@opencode/ai 2.2.6 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +208 -98
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/decision.d.ts +10 -0
  5. package/dist/decision.js +2 -0
  6. package/dist/effect.d.ts +14 -7
  7. package/dist/effect.js +6 -1
  8. package/dist/embedding-client.d.ts +21 -0
  9. package/dist/embedding-client.js +30 -0
  10. package/dist/embedding.d.ts +111 -0
  11. package/dist/embedding.js +75 -0
  12. package/dist/experimental.d.ts +0 -4
  13. package/dist/experimental.js +0 -3
  14. package/dist/image-client.d.ts +1 -1
  15. package/dist/image-client.js +2 -6
  16. package/dist/image.d.ts +0 -1
  17. package/dist/image.js +0 -3
  18. package/dist/index.d.ts +18 -50
  19. package/dist/index.js +35 -13
  20. package/dist/media-model.d.ts +2 -0
  21. package/dist/media-model.js +3 -1
  22. package/dist/media.d.ts +9 -3
  23. package/dist/media.js +27 -7
  24. package/dist/protocols/alibaba-chat.d.ts +4 -0
  25. package/dist/protocols/anthropic-messages.js +3 -3
  26. package/dist/protocols/google-decisions.d.ts +13 -0
  27. package/dist/protocols/google-decisions.js +133 -0
  28. package/dist/protocols/google-embed-content.d.ts +34 -0
  29. package/dist/protocols/google-embed-content.js +110 -0
  30. package/dist/protocols/google-interactions-video.d.ts +43 -0
  31. package/dist/protocols/google-interactions-video.js +186 -0
  32. package/dist/protocols/google-interactions.d.ts +14 -1
  33. package/dist/protocols/google-interactions.js +1 -1
  34. package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
  35. package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
  36. package/dist/protocols/index.d.ts +4 -0
  37. package/dist/protocols/index.js +4 -0
  38. package/dist/protocols/minimax-video.d.ts +54 -0
  39. package/dist/protocols/minimax-video.js +292 -0
  40. package/dist/protocols/open-responses.d.ts +1 -1
  41. package/dist/protocols/open-responses.js +31 -8
  42. package/dist/protocols/openai-chat.d.ts +24 -0
  43. package/dist/protocols/openai-chat.js +37 -11
  44. package/dist/protocols/openai-compatible-chat.d.ts +1 -0
  45. package/dist/protocols/openai-decisions.js +14 -1
  46. package/dist/protocols/openai-embeddings.d.ts +16 -0
  47. package/dist/protocols/openai-embeddings.js +76 -0
  48. package/dist/protocols/openrouter-video.d.ts +41 -0
  49. package/dist/protocols/openrouter-video.js +138 -0
  50. package/dist/protocols/seedance-video.d.ts +50 -0
  51. package/dist/protocols/seedance-video.js +216 -0
  52. package/dist/protocols/shared.d.ts +13 -3
  53. package/dist/protocols/shared.js +27 -4
  54. package/dist/protocols/system-one.d.ts +45 -1
  55. package/dist/protocols/system-one.js +50 -8
  56. package/dist/protocols/utils/responses-compaction.js +1 -1
  57. package/dist/protocols/venice-chat.d.ts +4 -0
  58. package/dist/protocols/xai-video.d.ts +8 -2
  59. package/dist/protocols/xai-video.js +20 -15
  60. package/dist/protocols/zai-chat.d.ts +4 -0
  61. package/dist/provider-error.js +7 -1
  62. package/dist/providers/alibaba/embeddings.d.ts +2 -0
  63. package/dist/providers/alibaba/embeddings.js +1 -0
  64. package/dist/providers/alibaba.d.ts +3 -0
  65. package/dist/providers/alibaba.js +14 -1
  66. package/dist/providers/amazon-bedrock-mantle.d.ts +1 -0
  67. package/dist/providers/azure/embeddings.d.ts +2 -0
  68. package/dist/providers/azure/embeddings.js +1 -0
  69. package/dist/providers/azure.d.ts +3 -0
  70. package/dist/providers/azure.js +15 -0
  71. package/dist/providers/baseten.d.ts +2 -0
  72. package/dist/providers/byteplus/videos.d.ts +2 -0
  73. package/dist/providers/byteplus/videos.js +1 -0
  74. package/dist/providers/byteplus.d.ts +26 -0
  75. package/dist/providers/byteplus.js +21 -0
  76. package/dist/providers/cerebras.d.ts +2 -0
  77. package/dist/providers/cloudflare-ai-gateway.d.ts +2 -0
  78. package/dist/providers/cloudflare-workers-ai.d.ts +2 -0
  79. package/dist/providers/cohere/embeddings.d.ts +2 -0
  80. package/dist/providers/cohere/embeddings.js +1 -0
  81. package/dist/providers/cohere.d.ts +8 -0
  82. package/dist/providers/cohere.js +17 -1
  83. package/dist/providers/deepinfra/embeddings.d.ts +2 -0
  84. package/dist/providers/deepinfra/embeddings.js +1 -0
  85. package/dist/providers/deepinfra.d.ts +6 -1
  86. package/dist/providers/deepinfra.js +15 -1
  87. package/dist/providers/deepseek.d.ts +2 -0
  88. package/dist/providers/digitalocean/embeddings.d.ts +2 -0
  89. package/dist/providers/digitalocean/embeddings.js +1 -0
  90. package/dist/providers/digitalocean.d.ts +10 -0
  91. package/dist/providers/digitalocean.js +15 -0
  92. package/dist/providers/fireworks/embeddings.d.ts +2 -0
  93. package/dist/providers/fireworks/embeddings.js +1 -0
  94. package/dist/providers/fireworks.d.ts +6 -1
  95. package/dist/providers/fireworks.js +15 -1
  96. package/dist/providers/google/decisions.d.ts +2 -0
  97. package/dist/providers/google/decisions.js +1 -0
  98. package/dist/providers/google/embeddings.d.ts +2 -0
  99. package/dist/providers/google/embeddings.js +1 -0
  100. package/dist/providers/google/videos.d.ts +2 -0
  101. package/dist/providers/google/videos.js +1 -0
  102. package/dist/providers/google-vertex/embeddings.d.ts +2 -0
  103. package/dist/providers/google-vertex/embeddings.js +1 -0
  104. package/dist/providers/google-vertex-chat.d.ts +1 -0
  105. package/dist/providers/google-vertex.d.ts +7 -0
  106. package/dist/providers/google-vertex.js +52 -0
  107. package/dist/providers/google.d.ts +17 -4
  108. package/dist/providers/google.js +27 -3
  109. package/dist/providers/groq.d.ts +5 -0
  110. package/dist/providers/index.d.ts +2 -1
  111. package/dist/providers/index.js +2 -1
  112. package/dist/providers/meta.d.ts +1 -0
  113. package/dist/providers/minimax/videos.d.ts +3 -0
  114. package/dist/providers/minimax/videos.js +1 -0
  115. package/dist/providers/minimax.d.ts +7 -1
  116. package/dist/providers/minimax.js +10 -1
  117. package/dist/providers/moonshot.d.ts +1 -0
  118. package/dist/providers/openai/embeddings.d.ts +2 -0
  119. package/dist/providers/openai/embeddings.js +1 -0
  120. package/dist/providers/openai-compatible/decisions.d.ts +2 -0
  121. package/dist/providers/openai-compatible/decisions.js +1 -0
  122. package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
  123. package/dist/providers/openai-compatible/embeddings.js +1 -0
  124. package/dist/providers/openai-compatible.d.ts +6 -0
  125. package/dist/providers/openai-compatible.js +27 -0
  126. package/dist/providers/openai.d.ts +7 -0
  127. package/dist/providers/openai.js +14 -0
  128. package/dist/providers/openrouter/embeddings.d.ts +2 -0
  129. package/dist/providers/openrouter/embeddings.js +1 -0
  130. package/dist/providers/openrouter/videos.d.ts +2 -0
  131. package/dist/providers/openrouter/videos.js +1 -0
  132. package/dist/providers/openrouter.d.ts +21 -0
  133. package/dist/providers/openrouter.js +23 -0
  134. package/dist/providers/togetherai.d.ts +2 -0
  135. package/dist/providers/venice.d.ts +1 -0
  136. package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
  137. package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
  138. package/dist/providers/vercel-ai-gateway.d.ts +4 -0
  139. package/dist/providers/vercel-ai-gateway.js +15 -1
  140. package/dist/providers/volcengine/videos.d.ts +2 -0
  141. package/dist/providers/volcengine/videos.js +1 -0
  142. package/dist/providers/volcengine.d.ts +26 -0
  143. package/dist/providers/volcengine.js +21 -0
  144. package/dist/providers/xai.d.ts +1 -0
  145. package/dist/providers/zai-coding-plan.d.ts +1 -0
  146. package/dist/providers/zai.d.ts +1 -0
  147. package/dist/public.d.ts +4 -0
  148. package/dist/public.js +2 -0
  149. package/dist/route/embedding.d.ts +61 -0
  150. package/dist/route/embedding.js +88 -0
  151. package/dist/route/executor-service.d.ts +6 -0
  152. package/dist/route/executor-service.js +7 -0
  153. package/dist/route/executor.d.ts +7 -1
  154. package/dist/route/executor.js +7 -2
  155. package/dist/route/media-protocol.d.ts +12 -11
  156. package/dist/route/media.d.ts +2 -0
  157. package/dist/route/media.js +31 -22
  158. package/dist/route/transport/http.js +1 -1
  159. package/dist/schema/messages.d.ts +1 -1
  160. package/dist/schema/messages.js +1 -5
  161. package/dist/schema/options.d.ts +8 -0
  162. package/dist/schema/options.js +1 -0
  163. package/dist/speech-client.d.ts +1 -1
  164. package/dist/speech-client.js +4 -4
  165. package/dist/transcription-client.d.ts +1 -1
  166. package/dist/transcription-client.js +1 -2
  167. package/dist/video-client.d.ts +16 -84
  168. package/dist/video-client.js +28 -13
  169. package/dist/video.d.ts +56 -1072
  170. package/dist/video.js +28 -65
  171. package/package.json +355 -255
  172. package/dist/protocols/google-video.d.ts +0 -26
  173. package/dist/protocols/google-video.js +0 -146
  174. package/dist/protocols/runway-video.d.ts +0 -38
  175. package/dist/protocols/runway-video.js +0 -141
  176. package/dist/providers/runway.d.ts +0 -20
  177. package/dist/providers/runway.js +0 -17
@@ -1,26 +0,0 @@
1
- import { Schema } from "effect";
2
- import { MediaProtocol } from "../route/media-protocol.js";
3
- import { MediaRoute } from "../route/media.js";
4
- import { type OpenString } from "../schema/index.js";
5
- import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
6
- export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
7
- /** Provider-native `parameters`. Common fields (`aspect`, `resolution`, `durationSeconds`, `seed`) live on the request. */
8
- export type GoogleVideoOptions = {
9
- readonly personGeneration?: OpenString<"allow_all" | "allow_adult" | "dont_allow">;
10
- } & Record<string, unknown>;
11
- export type Request = VideoRequest<VideoModel<GoogleVideoOptions>>;
12
- /** The long-running operation name, e.g. `models/veo-3.1-generate-preview/operations/abc123`. */
13
- export declare const Token: Schema.Struct<{
14
- readonly operation: Schema.String;
15
- }>;
16
- export type Token = Schema.Schema.Type<typeof Token>;
17
- export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, {
18
- readonly operation: string;
19
- }>;
20
- export declare const model: (input: MediaRoute.ModelInput) => VideoModel<GoogleVideoOptions>;
21
- export declare const GoogleVideo: {
22
- readonly protocol: MediaProtocol.Queued<Request, VideoResponse, {
23
- readonly operation: string;
24
- }>;
25
- readonly model: typeof model;
26
- };
@@ -1,146 +0,0 @@
1
- import { Duration, Effect, Schema } from "effect";
2
- import { Media } from "../media.js";
3
- import { MediaProtocol } from "../route/media-protocol.js";
4
- import { MediaRoute } from "../route/media.js";
5
- import { mergeJsonRecords } from "../schema/index.js";
6
- import { VideoModel, VideoResponse } from "../video.js";
7
- import { ProviderShared, optionalArray } from "./shared.js";
8
- const route = MediaProtocol.identity({ id: "google-video", name: "Google Veo", provider: "google" });
9
- export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
10
- /** Veo keeps generated files for two days; the asset carries that deadline so callers materialize in time. */
11
- const FILE_RETENTION = Duration.days(2);
12
- // ---------------------------------------------------------------------------
13
- // 2. Token and response schemas
14
- // ---------------------------------------------------------------------------
15
- /** The long-running operation name, e.g. `models/veo-3.1-generate-preview/operations/abc123`. */
16
- export const Token = Schema.Struct({ operation: Schema.String });
17
- const StartResponse = Schema.Struct({ name: Schema.String });
18
- const Operation = Schema.Struct({
19
- done: Schema.optional(Schema.Boolean),
20
- error: Schema.optional(Schema.Struct({ code: Schema.optional(Schema.Number), message: Schema.optional(Schema.String) })),
21
- response: Schema.optional(Schema.Struct({
22
- generateVideoResponse: Schema.optional(Schema.Struct({
23
- generatedSamples: optionalArray(Schema.Struct({
24
- video: Schema.optional(Schema.Struct({
25
- uri: Schema.optional(Schema.String),
26
- mimeType: Schema.optional(Schema.String),
27
- })),
28
- })),
29
- raiMediaFilteredCount: Schema.optional(Schema.Number),
30
- raiMediaFilteredReasons: optionalArray(Schema.String),
31
- })),
32
- })),
33
- metadata: Schema.optional(Schema.Unknown),
34
- });
35
- // Operation errors are `google.rpc.Status`; unlisted codes (INTERNAL, UNAVAILABLE, ...) are provider-side.
36
- const FAILURE = {
37
- 3: "InvalidRequest", // INVALID_ARGUMENT
38
- 7: "Authentication", // PERMISSION_DENIED
39
- 8: "RateLimit", // RESOURCE_EXHAUSTED
40
- 9: "InvalidRequest", // FAILED_PRECONDITION
41
- 11: "InvalidRequest", // OUT_OF_RANGE
42
- 16: "Authentication", // UNAUTHENTICATED
43
- };
44
- // ---------------------------------------------------------------------------
45
- // 5. Request body construction
46
- // ---------------------------------------------------------------------------
47
- // Veo takes inline media only; a prior Veo output is `Media.url` with transient auth, so materialize it first.
48
- const inlineMedia = (asset) => ProviderShared.requireInlineMedia(route.name, asset).pipe(Effect.map((inline) => ({ inlineData: { mimeType: inline.mime, data: inline.base64 } })));
49
- const fromRequest = Effect.fn("GoogleVideo.fromRequest")(function* (request) {
50
- if (request.n !== undefined && request.n > 1)
51
- return yield* route.unsupported("video.n", `${route.name} generates one video per request; call it once per video instead of n=${request.n}`);
52
- if (request.audio === false)
53
- return yield* route.unsupported("video.audio", `${route.name} always generates audio; audio: false cannot be honored`);
54
- if (request.frames?.last !== undefined && request.frames.first === undefined)
55
- return yield* ProviderShared.invalidRequest(`${route.name} requires frames.first when frames.last is set`);
56
- const image = request.frames?.first === undefined ? undefined : yield* inlineMedia(request.frames.first);
57
- const lastFrame = request.frames?.last === undefined ? undefined : yield* inlineMedia(request.frames.last);
58
- const video = request.video === undefined ? undefined : yield* inlineMedia(request.video);
59
- const referenceImages = yield* Effect.forEach(request.references ?? [], (asset) => inlineMedia(asset).pipe(Effect.map((image) => ({ image, referenceType: "asset" }))));
60
- return MediaProtocol.json(mergeJsonRecords({
61
- instances: [
62
- {
63
- prompt: request.prompt,
64
- image,
65
- lastFrame,
66
- referenceImages: referenceImages.length === 0 ? undefined : referenceImages,
67
- video,
68
- },
69
- ],
70
- parameters: mergeJsonRecords({
71
- aspectRatio: request.aspect,
72
- resolution: request.resolution,
73
- durationSeconds: request.durationSeconds,
74
- negativePrompt: request.negativePrompt,
75
- seed: request.seed,
76
- }, request.providerOptions),
77
- }, request.http?.body) ?? {});
78
- });
79
- // ---------------------------------------------------------------------------
80
- // 6. Response decoding
81
- // ---------------------------------------------------------------------------
82
- const decodeStart = route.decodeStarted(StartResponse, (value) => ({
83
- token: { operation: value.name },
84
- snapshot: { id: value.name, status: "running" },
85
- }));
86
- // Operations carry no status string: not done is running, done with `error` failed, otherwise completed.
87
- const statusOf = (operation) => {
88
- if (operation.done !== true)
89
- return "running";
90
- return operation.error === undefined ? "completed" : "failed";
91
- };
92
- const decodeOperation = route.decodeJson(Operation);
93
- const decodeStatus = Effect.fn("GoogleVideo.decodeStatus")(function* (response, context) {
94
- const output = yield* decodeOperation(response);
95
- return { id: context.token.operation, status: statusOf(output.value) };
96
- });
97
- const decodeResult = Effect.fn("GoogleVideo.decodeResult")(function* (response, context) {
98
- const output = yield* decodeOperation(response);
99
- const operation = output.value;
100
- const status = statusOf(operation);
101
- if (status === "running")
102
- return yield* output.pending(context.token.operation);
103
- if (status === "failed")
104
- return yield* output.ended("failed", `${route.name} operation failed${operation.error?.message === undefined ? "" : `: ${operation.error.message}`}`, MediaProtocol.failure(FAILURE, operation.error?.code));
105
- const generated = operation.response?.generateVideoResponse;
106
- // Downloads require the same API key as the poll; the asset carries it transiently and follows the redirect.
107
- const videos = yield* Effect.forEach((generated?.generatedSamples ?? []).flatMap((sample) => sample.video?.uri === undefined ? [] : [{ uri: sample.video.uri, mimeType: sample.video.mimeType }]), (video) => MediaProtocol.expiringUrl(video.uri, FILE_RETENTION, {
108
- mediaType: video.mimeType ?? "video/mp4",
109
- headers: context.auth,
110
- }));
111
- const reasons = generated?.raiMediaFilteredReasons ?? [];
112
- if (videos.length === 0 && (reasons.length > 0 || (generated?.raiMediaFilteredCount ?? 0) > 0))
113
- return yield* output.contentPolicy(`${route.name} filtered every video${reasons.length === 0 ? "" : `: ${reasons.join("; ")}`}`);
114
- if (videos.length === 0)
115
- return yield* output.invalid(`${route.name} operation completed without any video`);
116
- return new VideoResponse({
117
- videos,
118
- providerMetadata: {
119
- google: {
120
- operation: context.token.operation,
121
- raiMediaFilteredCount: generated?.raiMediaFilteredCount,
122
- raiMediaFilteredReasons: generated?.raiMediaFilteredReasons,
123
- metadata: operation.metadata,
124
- },
125
- },
126
- });
127
- });
128
- // ---------------------------------------------------------------------------
129
- // 7. Protocol and route
130
- // ---------------------------------------------------------------------------
131
- const operationPath = (token) => `/${token.operation}`;
132
- export const protocol = MediaProtocol.queued(route, {
133
- token: Token,
134
- start: { body: { from: fromRequest }, decode: decodeStart },
135
- status: { path: operationPath, decode: decodeStatus },
136
- result: { path: operationPath, decode: decodeResult },
137
- });
138
- export const model = (input) => VideoModel.fromRoute({
139
- protocol,
140
- baseURL: DEFAULT_BASE_URL,
141
- path: ({ request }) => `/models/${request.model.id}:predictLongRunning`,
142
- }, input);
143
- export const GoogleVideo = {
144
- protocol,
145
- model,
146
- };
@@ -1,38 +0,0 @@
1
- import { Schema } from "effect";
2
- import { MediaProtocol } from "../route/media-protocol.js";
3
- import { MediaRoute } from "../route/media.js";
4
- import { type OpenString } from "../schema/index.js";
5
- import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
6
- export declare const DEFAULT_BASE_URL = "https://api.dev.runwayml.com/v1";
7
- /** Every Runway request must pin the API version. */
8
- export declare const API_VERSION = "2024-11-06";
9
- export declare const TEXT_TO_VIDEO_PATH = "/text_to_video";
10
- export declare const IMAGE_TO_VIDEO_PATH = "/image_to_video";
11
- export declare const VIDEO_TO_VIDEO_PATH = "/video_to_video";
12
- export declare const TASKS_PATH = "/tasks";
13
- /**
14
- * Provider-native options. Common fields lower to Runway's names: `aspect` → `ratio` (Runway expects pixel
15
- * ratios such as `1280:720` for most models), `durationSeconds` → `duration`, `audio`, `negativePrompt`,
16
- * `resolution`, `references`, and `frames` → `promptImage`.
17
- */
18
- export type RunwayVideoOptions = {
19
- readonly contentModeration?: {
20
- readonly publicFigureThreshold?: OpenString<"auto" | "low">;
21
- };
22
- readonly outputFormat?: OpenString<"mp4" | "prores" | "png_sequence">;
23
- } & Record<string, unknown>;
24
- export type Request = VideoRequest<VideoModel<RunwayVideoOptions>>;
25
- export declare const Token: Schema.Struct<{
26
- readonly taskID: Schema.String;
27
- }>;
28
- export type Token = Schema.Schema.Type<typeof Token>;
29
- export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, {
30
- readonly taskID: string;
31
- }>;
32
- export declare const model: (input: MediaRoute.ModelInput) => VideoModel<RunwayVideoOptions>;
33
- export declare const RunwayVideo: {
34
- readonly protocol: MediaProtocol.Queued<Request, VideoResponse, {
35
- readonly taskID: string;
36
- }>;
37
- readonly model: typeof model;
38
- };
@@ -1,141 +0,0 @@
1
- import { Duration, Effect, Schema } from "effect";
2
- import { Media } from "../media.js";
3
- import { MediaProtocol } from "../route/media-protocol.js";
4
- import { MediaRoute } from "../route/media.js";
5
- import { mergeJsonRecords } from "../schema/index.js";
6
- import { VideoModel, VideoResponse } from "../video.js";
7
- import { ProviderShared, optionalArray, optionalNull } from "./shared.js";
8
- const route = MediaProtocol.identity({ id: "runway-video", name: "Runway", provider: "runway" });
9
- export const DEFAULT_BASE_URL = "https://api.dev.runwayml.com/v1";
10
- /** Every Runway request must pin the API version. */
11
- export const API_VERSION = "2024-11-06";
12
- export const TEXT_TO_VIDEO_PATH = "/text_to_video";
13
- export const IMAGE_TO_VIDEO_PATH = "/image_to_video";
14
- export const VIDEO_TO_VIDEO_PATH = "/video_to_video";
15
- export const TASKS_PATH = "/tasks";
16
- /** Output URLs are valid for 24–48 hours; the asset carries the conservative bound. */
17
- const OUTPUT_RETENTION = Duration.hours(24);
18
- // ---------------------------------------------------------------------------
19
- // 2. Token and response schemas
20
- // ---------------------------------------------------------------------------
21
- export const Token = Schema.Struct({ taskID: Schema.String });
22
- const Cost = Schema.Struct({ credits: Schema.Number });
23
- const StartResponse = Schema.Struct({ id: Schema.String });
24
- const Task = Schema.Struct({
25
- status: Schema.String,
26
- progress: optionalNull(Schema.Number),
27
- output: optionalArray(Schema.String),
28
- failure: optionalNull(Schema.String),
29
- failureCode: optionalNull(Schema.String),
30
- cost: Schema.optional(Cost),
31
- estimatedCost: Schema.optional(Cost),
32
- });
33
- const STATUS = {
34
- PENDING: "queued",
35
- THROTTLED: "queued",
36
- RUNNING: "running",
37
- SUCCEEDED: "completed",
38
- FAILED: "failed",
39
- CANCELLED: "cancelled",
40
- };
41
- // ---------------------------------------------------------------------------
42
- // 5. Request body construction
43
- // ---------------------------------------------------------------------------
44
- // Runway accepts HTTPS URLs, `runway://` upload URIs, and data URIs, all as one string.
45
- const mediaUri = (asset) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((reference) => reference.value));
46
- const fromRequest = Effect.fn("RunwayVideo.fromRequest")(function* (request) {
47
- const first = request.frames?.first === undefined ? undefined : yield* mediaUri(request.frames.first);
48
- const last = request.frames?.last === undefined ? undefined : yield* mediaUri(request.frames.last);
49
- const promptImage = [
50
- ...(first === undefined ? [] : [{ uri: first, position: "first" }]),
51
- ...(last === undefined ? [] : [{ uri: last, position: "last" }]),
52
- ];
53
- const videoUri = request.video === undefined ? undefined : yield* mediaUri(request.video);
54
- const references = yield* Effect.forEach(request.references ?? [], (asset) => mediaUri(asset).pipe(Effect.map((uri) => ({ uri }))));
55
- return MediaProtocol.json(mergeJsonRecords({
56
- model: request.model.id,
57
- promptText: request.prompt,
58
- promptImage: promptImage.length === 0 ? undefined : promptImage,
59
- videoUri,
60
- references: references.length === 0 ? undefined : references,
61
- ratio: request.aspect,
62
- duration: request.durationSeconds,
63
- resolution: request.resolution,
64
- audio: request.audio,
65
- negativePrompt: request.negativePrompt,
66
- seed: request.seed,
67
- }, request.providerOptions, request.http?.body) ?? {});
68
- });
69
- // ---------------------------------------------------------------------------
70
- // 6. Response decoding
71
- // ---------------------------------------------------------------------------
72
- const decodeStart = route.decodeStarted(StartResponse, (value) => ({
73
- token: { taskID: value.id },
74
- snapshot: { id: value.id, status: "queued" },
75
- }));
76
- const decodeTask = route.decodeJson(Task);
77
- const decodeStatus = Effect.fn("RunwayVideo.decodeStatus")(function* (response, context) {
78
- const output = yield* decodeTask(response);
79
- const status = MediaProtocol.status(STATUS, output.value.status);
80
- return { id: context.token.taskID, status, progress: output.value.progress ?? undefined };
81
- });
82
- const decodeResult = Effect.fn("RunwayVideo.decodeResult")(function* (response, context) {
83
- const output = yield* decodeTask(response);
84
- const task = output.value;
85
- const status = MediaProtocol.status(STATUS, task.status);
86
- if (status === "failed") {
87
- const code = task.failureCode ?? undefined;
88
- const message = `${route.name} task failed${code === undefined ? "" : ` (${code})`}${task.failure ? `: ${task.failure}` : ""}`;
89
- // Runway failure codes are dotted paths; every moderation outcome carries a SAFETY segment.
90
- if (code !== undefined && /(^|\.)SAFETY(\.|$)/.test(code))
91
- return yield* output.contentPolicy(message);
92
- // ASSET.INVALID rejects the caller's input media; Runway documents it as not retryable.
93
- return yield* output.ended("failed", message, code !== undefined && /^ASSET\.INVALID(\.|$)/.test(code) ? "InvalidRequest" : "ProviderInternal");
94
- }
95
- if (status === "cancelled")
96
- return yield* output.ended("cancelled", `${route.name} task ${context.token.taskID} was cancelled`);
97
- if (status !== "completed")
98
- return yield* output.pending(context.token.taskID);
99
- const urls = task.output ?? [];
100
- if (urls.length === 0)
101
- return yield* output.invalid(`${route.name} task succeeded without any output`);
102
- return new VideoResponse({
103
- videos: yield* Effect.forEach(urls, (url) => MediaProtocol.expiringUrl(url, OUTPUT_RETENTION, { mediaType: "video/mp4" })),
104
- usage: task.cost === undefined ? undefined : { type: "credits", credits: task.cost.credits },
105
- providerMetadata: {
106
- runway: {
107
- taskId: context.token.taskID,
108
- estimatedCredits: task.estimatedCost?.credits,
109
- },
110
- },
111
- });
112
- });
113
- // ---------------------------------------------------------------------------
114
- // 7. Protocol and route
115
- // ---------------------------------------------------------------------------
116
- const taskPath = (token) => `${TASKS_PATH}/${token.taskID}`;
117
- export const protocol = MediaProtocol.queued(route, {
118
- token: Token,
119
- unsupported: ["n"],
120
- start: { body: { from: fromRequest }, decode: decodeStart },
121
- status: { path: taskPath, decode: decodeStatus },
122
- result: { path: taskPath, decode: decodeResult },
123
- cancel: { method: "DELETE", path: taskPath, activeOnly: true },
124
- });
125
- const startPath = (request) => {
126
- if (request.video !== undefined)
127
- return VIDEO_TO_VIDEO_PATH;
128
- if (request.frames?.first !== undefined || request.frames?.last !== undefined)
129
- return IMAGE_TO_VIDEO_PATH;
130
- return TEXT_TO_VIDEO_PATH;
131
- };
132
- export const model = (input) => VideoModel.fromRoute({
133
- protocol,
134
- baseURL: DEFAULT_BASE_URL,
135
- headers: { "X-Runway-Version": API_VERSION },
136
- path: ({ request }) => startPath(request),
137
- }, input);
138
- export const RunwayVideo = {
139
- protocol,
140
- model,
141
- };
@@ -1,20 +0,0 @@
1
- import { type ProviderAuthOption } from "../route/auth-options.js";
2
- import { type HttpOptions, type ModelID } from "../schema/index.js";
3
- export type { RunwayVideoOptions } from "../protocols/runway-video.js";
4
- export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
5
- export type Config = ProviderAuthOption<"optional"> & {
6
- readonly baseURL?: string;
7
- readonly headers?: Record<string, string>;
8
- readonly http?: HttpOptions;
9
- };
10
- export declare const configure: (input?: Config) => {
11
- id: string & import("effect/Brand").Brand<"AI.ProviderID">;
12
- video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/runway-video.js").RunwayVideoOptions>;
13
- configure: typeof configure;
14
- };
15
- export declare const provider: {
16
- id: string & import("effect/Brand").Brand<"AI.ProviderID">;
17
- video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/runway-video.js").RunwayVideoOptions>;
18
- configure: typeof configure;
19
- };
20
- export declare const video: (modelID: string | ModelID) => import("../video.js").VideoModel<import("../protocols/runway-video.js").RunwayVideoOptions>;
@@ -1,17 +0,0 @@
1
- import { AuthOptions } from "../route/auth-options.js";
2
- import { MediaRoute } from "../route/media.js";
3
- import { ProviderID } from "../schema/index.js";
4
- import { RunwayVideo } from "../protocols/runway-video.js";
5
- export const id = ProviderID.make("runway");
6
- const auth = (options) => AuthOptions.bearer(options, "RUNWAYML_API_SECRET");
7
- export const configure = (input = {}) => {
8
- const media = MediaRoute.deployment(input, auth(input));
9
- const video = (modelID) => RunwayVideo.model({ ...media, id: modelID });
10
- return {
11
- id,
12
- video,
13
- configure,
14
- };
15
- };
16
- export const provider = configure();
17
- export const video = provider.video;