Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cli/Runway.Cli/GeneratedApi/Commands/ApiCommand.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public static Command Create()
command.Options.Add(CliOptions.OutputDirectory);
command.Subcommands.Add(AvatarVideosApiGroupCommand.Create());
command.Subcommands.Add(AvatarsApiGroupCommand.Create());
command.Subcommands.Add(GenerateApiGroupCommand.Create());
command.Subcommands.Add(KnowledgeApiGroupCommand.Create());
command.Subcommands.Add(ModelRouterApiGroupCommand.Create());
command.Subcommands.Add(OrganizationApiGroupCommand.Create());
command.Subcommands.Add(RealtimeSessionsApiGroupCommand.Create());
command.Subcommands.Add(RecipesApiGroupCommand.Create());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#nullable enable

using System.CommandLine;

namespace Runway.Cli.GeneratedApi.Commands;

internal static class GenerateApiGroupCommand
{
public static Command Create()
{
var command = new Command(@"generate", @"Generate endpoint commands.");
command.Subcommands.Add(GenerateCreateGenerateVideoCommandApiCommand.Create());
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#nullable enable
#pragma warning disable CS0618

using System.CommandLine;

namespace Runway.Cli.GeneratedApi.Commands;

internal static partial class GenerateCreateGenerateVideoCommandApiCommand
{
private static Option<string> XRunwayVersion { get; } = new(
name: @"--x-runway-version")
{
Description = @"The version of the RunwayML API being used. You can read more about versioning [here](/api-details/versioning).",
DefaultValueFactory = _ => "2024-11-06",
};

private static Option<string> ConfigId { get; } = new(
name: @"--config-id")
{
Description = @"The slug of a saved Model Router config to route this request with.",
Required = true,
};

private static Option<bool?> DryRun { get; } = CliRuntime.CreateNullableBoolOption(
name: @"--dry-run",
description: @"When true, run the full routing pipeline and return the decision and estimated cost without generating. No task is created, nothing is billed, and no asset is produced.");

private static Option<global::Runway.CreateGenerateVideoRequestInput> InputOption { get; } = new(
name: @"--input")
{
Description = @"Model-agnostic video generation input. Fields are optional; the router selects a model and maps these options to it.",
Required = true,
};
private static Option<string?> RequestInput { get; } = new(@"--request-input")
{
Description = "Load request JSON from a file path, '-' for stdin, or an inline JSON object/array string.",
};

private static Option<string?> RequestJson { get; } = new(@"--request-json")
{
Description = "Request body as JSON.",
Hidden = true,
};

private static Option<string?> RequestFile { get; } = new(@"--request-file")
{
Description = "Path to a JSON request file, or '-' for stdin.",
Hidden = true,
};

private static string FormatResponse(ParseResult parseResult, global::Runway.CreateGenerateVideoResponse value, global::System.Text.Json.Serialization.JsonSerializerContext context, bool truncateLongStrings)
{
string? text = null;
CustomizeResponseText(parseResult, value, ref text);
if (!string.IsNullOrWhiteSpace(text))
{
return text;
}

var hints = new Dictionary<string, CliFormatHint>(StringComparer.OrdinalIgnoreCase)
{
};
CustomizeResponseFormatHints(hints);
return CliRuntime.FormatHumanReadable(value, context, truncateLongStrings, hints);
}

static partial void CustomizeResponseText(ParseResult parseResult, global::Runway.CreateGenerateVideoResponse value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);


public static Command Create()
{
var command = new Command(@"create-generate-video", @"Routed video generation
Start a video generation task using a saved Model Router config instead of naming a model.");
command.Options.Add(XRunwayVersion);
command.Options.Add(ConfigId);
command.Options.Add(DryRun);
command.Options.Add(InputOption);
command.Options.Add(RequestInput);
command.Options.Add(RequestJson);
command.Options.Add(RequestFile);
command.Validators.Add(result =>
{
var hasInput = result.GetResult(RequestInput) is not null;
var hasRequestJson = result.GetResult(RequestJson) is not null;
var hasRequestFile = result.GetResult(RequestFile) is not null;
var specifiedCount = (hasInput ? 1 : 0) + (hasRequestJson ? 1 : 0) + (hasRequestFile ? 1 : 0);
if (specifiedCount > 1)
{
result.AddError(@"Specify at most one of --request-input, --request-json, or --request-file.");
}
});

command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var __requestBase = await CliRuntime.ReadRequestOrDefaultAsync<global::Runway.CreateGenerateVideoRequest>(
parseResult,
RequestInput,
RequestJson,
RequestFile,
global::Runway.SourceGenerationContext.Default,
cancellationToken).ConfigureAwait(false);
var xRunwayVersion = parseResult.GetRequiredValue(XRunwayVersion);
var configId = parseResult.GetRequiredValue(ConfigId);
var dryRun = CliRuntime.WasSpecified(parseResult, DryRun) ? parseResult.GetValue(DryRun) : (__requestBase is { } __DryRunBaseValue ? __DryRunBaseValue.DryRun : default);
var input = parseResult.GetRequiredValue(InputOption);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


var response = await client.Generate.CreateGenerateVideoAsync(
xRunwayVersion: xRunwayVersion,
configId: configId,
dryRun: dryRun,
input: input,
cancellationToken: cancellationToken).ConfigureAwait(false);


await CliRuntime.WriteResponseAsync(
parseResult,
response,
global::Runway.SourceGenerationContext.Default,
FormatResponse,
cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false));
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#nullable enable

using System.CommandLine;

namespace Runway.Cli.GeneratedApi.Commands;

internal static class ModelRouterApiGroupCommand
{
public static Command Create()
{
var command = new Command(@"model-router", @"Model Router endpoint commands.");
command.Subcommands.Add(ModelRouterCreateRoutersCommandApiCommand.Create());
command.Subcommands.Add(ModelRouterDeleteRoutersByIdCommandApiCommand.Create());
command.Subcommands.Add(ModelRouterEditRoutersByIdCommandApiCommand.Create());
command.Subcommands.Add(ModelRouterGetRoutersCommandApiCommand.Create());
command.Subcommands.Add(ModelRouterGetRoutersByIdCommandApiCommand.Create());
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#nullable enable
#pragma warning disable CS0618

using System.CommandLine;

namespace Runway.Cli.GeneratedApi.Commands;

internal static partial class ModelRouterCreateRoutersCommandApiCommand
{
private static Argument<string> Slug { get; } = new(
name: @"slug")
{
Description = @"Immutable slug used to reference this Model Router in generation requests (for example, production-video). Unique within the API project. The UUID id remains the canonical management identifier.",
};

private static Option<string> XRunwayVersion { get; } = new(
name: @"--x-runway-version")
{
Description = @"The version of the RunwayML API being used. You can read more about versioning [here](/api-details/versioning).",
DefaultValueFactory = _ => "2024-11-06",
};

private static Option<string?> NameOption { get; } = new(
name: @"--name")
{
Description = @"Optional human-readable display name for this router. Defaults to the slug when omitted.",
};

private static Option<string?> DescriptionOption { get; } = new(
name: @"--description")
{
Description = @"An optional Model Router description.",
};

private static Option<global::Runway.CreateRoutersRequestSettings?> Settings { get; } = new(
name: @"--settings")
{
Description = @"Model Router routing preferences. Defaults to cost-optimized allow-all when omitted. Modality is implied by the generate endpoint used with this Model Router.",
};
private static Option<string?> Input { get; } = new(@"--input")
{
Description = "Load request JSON from a file path, '-' for stdin, or an inline JSON object/array string.",
};

private static Option<string?> RequestJson { get; } = new(@"--request-json")
{
Description = "Request body as JSON.",
Hidden = true,
};

private static Option<string?> RequestFile { get; } = new(@"--request-file")
{
Description = "Path to a JSON request file, or '-' for stdin.",
Hidden = true,
};

private static string FormatResponse(ParseResult parseResult, global::Runway.CreateRoutersResponse value, global::System.Text.Json.Serialization.JsonSerializerContext context, bool truncateLongStrings)
{
string? text = null;
CustomizeResponseText(parseResult, value, ref text);
if (!string.IsNullOrWhiteSpace(text))
{
return text;
}

var hints = new Dictionary<string, CliFormatHint>(StringComparer.OrdinalIgnoreCase)
{
};
CustomizeResponseFormatHints(hints);
return CliRuntime.FormatHumanReadable(value, context, truncateLongStrings, hints);
}

static partial void CustomizeResponseText(ParseResult parseResult, global::Runway.CreateRoutersResponse value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);


public static Command Create()
{
var command = new Command(@"create-routers", @"Create Model Router
Create a Model Router configuration.");
command.Arguments.Add(Slug);
command.Options.Add(XRunwayVersion);
command.Options.Add(NameOption);
command.Options.Add(DescriptionOption);
command.Options.Add(Settings);
command.Options.Add(Input);
command.Options.Add(RequestJson);
command.Options.Add(RequestFile);
command.Validators.Add(result =>
{
var hasInput = result.GetResult(Input) is not null;
var hasRequestJson = result.GetResult(RequestJson) is not null;
var hasRequestFile = result.GetResult(RequestFile) is not null;
var specifiedCount = (hasInput ? 1 : 0) + (hasRequestJson ? 1 : 0) + (hasRequestFile ? 1 : 0);
if (specifiedCount > 1)
{
result.AddError(@"Specify at most one of --input, --request-json, or --request-file.");
}
});

command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var __requestBase = await CliRuntime.ReadRequestOrDefaultAsync<global::Runway.CreateRoutersRequest>(
parseResult,
Input,
RequestJson,
RequestFile,
global::Runway.SourceGenerationContext.Default,
cancellationToken).ConfigureAwait(false);
var slug = parseResult.GetRequiredValue(Slug);
var xRunwayVersion = parseResult.GetRequiredValue(XRunwayVersion);
var name = CliRuntime.WasSpecified(parseResult, NameOption) ? parseResult.GetValue(NameOption) : (__requestBase is { } __NameBaseValue ? __NameBaseValue.Name : default);
var description = CliRuntime.WasSpecified(parseResult, DescriptionOption) ? parseResult.GetValue(DescriptionOption) : (__requestBase is { } __DescriptionBaseValue ? __DescriptionBaseValue.Description : default);
var settings = CliRuntime.WasSpecified(parseResult, Settings) ? parseResult.GetValue(Settings) : (__requestBase is { } __SettingsBaseValue ? __SettingsBaseValue.Settings : default);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


var response = await client.ModelRouter.CreateRoutersAsync(
slug: slug,
xRunwayVersion: xRunwayVersion,
name: name,
description: description,
settings: settings,
cancellationToken: cancellationToken).ConfigureAwait(false);


await CliRuntime.WriteResponseAsync(
parseResult,
response,
global::Runway.SourceGenerationContext.Default,
FormatResponse,
cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false));
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#nullable enable
#pragma warning disable CS0618

using System.CommandLine;

namespace Runway.Cli.GeneratedApi.Commands;

internal static partial class ModelRouterDeleteRoutersByIdCommandApiCommand
{
private static Argument<global::System.Guid> Id { get; } = new(
name: @"id")
{
Description = @"The Model Router's primary key ID (UUID).",
};

private static Option<string> XRunwayVersion { get; } = new(
name: @"--x-runway-version")
{
Description = @"The version of the RunwayML API being used. You can read more about versioning [here](/api-details/versioning).",
DefaultValueFactory = _ => "2024-11-06",
};

public static Command Create()
{
var command = new Command(@"delete-routers-by-id", @"Delete Model Router
Delete a Model Router configuration. Deleted Model Routers cannot be used for generation.");
command.Arguments.Add(Id);
command.Options.Add(XRunwayVersion);


command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var id = parseResult.GetRequiredValue(Id);
var xRunwayVersion = parseResult.GetRequiredValue(XRunwayVersion);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


await client.ModelRouter.DeleteRoutersByIdAsync(
id: id,
xRunwayVersion: xRunwayVersion,
cancellationToken: cancellationToken).ConfigureAwait(false);

await CliRuntime.WriteSuccessAsync(parseResult, cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false));
return command;
}
}
Loading
Loading