@opencode/ai 2.2.7 → 2.3.1

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 (158) hide show
  1. package/README.md +164 -99
  2. package/dist/cache-policy.js +4 -2
  3. package/dist/effect.d.ts +11 -8
  4. package/dist/effect.js +2 -1
  5. package/dist/experimental.d.ts +0 -4
  6. package/dist/experimental.js +0 -3
  7. package/dist/generation.d.ts +10 -10
  8. package/dist/generation.js +8 -14
  9. package/dist/image-client.d.ts +56 -59
  10. package/dist/image-client.js +47 -12
  11. package/dist/image.d.ts +36 -95
  12. package/dist/image.js +11 -14
  13. package/dist/index.d.ts +31 -68
  14. package/dist/index.js +54 -30
  15. package/dist/llm.d.ts +4 -1
  16. package/dist/llm.js +10 -1
  17. package/dist/media-client.d.ts +18 -6
  18. package/dist/media-client.js +42 -37
  19. package/dist/media-model.d.ts +2 -0
  20. package/dist/media-model.js +3 -1
  21. package/dist/media.d.ts +26 -4
  22. package/dist/media.js +52 -11
  23. package/dist/protocols/alibaba-messages.d.ts +24 -2
  24. package/dist/protocols/alibaba-responses.d.ts +26 -0
  25. package/dist/protocols/anthropic-messages.d.ts +70 -6
  26. package/dist/protocols/anthropic-messages.js +74 -9
  27. package/dist/protocols/assemblyai-transcription.js +7 -6
  28. package/dist/protocols/cartesia-speech.d.ts +0 -8
  29. package/dist/protocols/deepgram-speech.d.ts +0 -8
  30. package/dist/protocols/elevenlabs-speech.d.ts +0 -8
  31. package/dist/protocols/google-decisions.d.ts +13 -0
  32. package/dist/protocols/google-decisions.js +133 -0
  33. package/dist/protocols/google-interactions-video.d.ts +38 -0
  34. package/dist/protocols/google-interactions-video.js +185 -0
  35. package/dist/protocols/google-interactions.d.ts +14 -1
  36. package/dist/protocols/google-interactions.js +1 -1
  37. package/dist/protocols/google-speech.d.ts +0 -8
  38. package/dist/protocols/google-transcription.d.ts +0 -8
  39. package/dist/protocols/index.d.ts +1 -0
  40. package/dist/protocols/index.js +1 -0
  41. package/dist/protocols/meta-messages.d.ts +24 -2
  42. package/dist/protocols/meta-responses.d.ts +52 -0
  43. package/dist/protocols/minimax-video.d.ts +45 -0
  44. package/dist/protocols/minimax-video.js +290 -0
  45. package/dist/protocols/open-responses.d.ts +250 -24
  46. package/dist/protocols/open-responses.js +40 -24
  47. package/dist/protocols/openai-chat.js +7 -3
  48. package/dist/protocols/openai-compatible-responses.d.ts +26 -0
  49. package/dist/protocols/openai-freeform.d.ts +1 -1
  50. package/dist/protocols/openai-freeform.js +9 -5
  51. package/dist/protocols/openai-images.d.ts +0 -8
  52. package/dist/protocols/openai-responses.d.ts +153 -0
  53. package/dist/protocols/openai-responses.js +68 -7
  54. package/dist/protocols/openai-speech.d.ts +0 -8
  55. package/dist/protocols/openai-transcription.d.ts +0 -8
  56. package/dist/protocols/openrouter-video.d.ts +36 -0
  57. package/dist/protocols/openrouter-video.js +139 -0
  58. package/dist/protocols/seedance-video.d.ts +45 -0
  59. package/dist/protocols/seedance-video.js +217 -0
  60. package/dist/protocols/system-one.d.ts +45 -1
  61. package/dist/protocols/system-one.js +42 -7
  62. package/dist/protocols/utils/gateway-protocol.js +1 -0
  63. package/dist/protocols/utils/responses-compaction.js +8 -4
  64. package/dist/protocols/xai-responses.d.ts +26 -0
  65. package/dist/protocols/xai-video.d.ts +12 -11
  66. package/dist/protocols/xai-video.js +33 -24
  67. package/dist/protocols/zai-messages.d.ts +24 -2
  68. package/dist/provider-error.js +7 -1
  69. package/dist/providers/alibaba.d.ts +50 -2
  70. package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
  71. package/dist/providers/anthropic-compatible.d.ts +24 -2
  72. package/dist/providers/anthropic.d.ts +24 -2
  73. package/dist/providers/azure.d.ts +76 -2
  74. package/dist/providers/byteplus/videos.d.ts +2 -0
  75. package/dist/providers/byteplus/videos.js +1 -0
  76. package/dist/providers/byteplus.d.ts +26 -0
  77. package/dist/providers/byteplus.js +21 -0
  78. package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
  79. package/dist/providers/digitalocean.d.ts +26 -0
  80. package/dist/providers/google/decisions.d.ts +2 -0
  81. package/dist/providers/google/decisions.js +1 -0
  82. package/dist/providers/google/videos.d.ts +2 -0
  83. package/dist/providers/google/videos.js +1 -0
  84. package/dist/providers/google-vertex-messages.d.ts +24 -2
  85. package/dist/providers/google-vertex-messages.js +1 -0
  86. package/dist/providers/google-vertex-responses.d.ts +26 -0
  87. package/dist/providers/google.d.ts +11 -4
  88. package/dist/providers/google.js +16 -3
  89. package/dist/providers/index.d.ts +2 -1
  90. package/dist/providers/index.js +2 -1
  91. package/dist/providers/meta.d.ts +50 -2
  92. package/dist/providers/minimax/videos.d.ts +3 -0
  93. package/dist/providers/minimax/videos.js +1 -0
  94. package/dist/providers/minimax.d.ts +56 -3
  95. package/dist/providers/minimax.js +10 -1
  96. package/dist/providers/moonshot.d.ts +50 -2
  97. package/dist/providers/openai-compatible/decisions.d.ts +2 -0
  98. package/dist/providers/openai-compatible/decisions.js +1 -0
  99. package/dist/providers/openai-compatible-responses.d.ts +26 -0
  100. package/dist/providers/openai-compatible.d.ts +2 -0
  101. package/dist/providers/openai-compatible.js +14 -0
  102. package/dist/providers/openai.d.ts +26 -0
  103. package/dist/providers/openrouter/videos.d.ts +2 -0
  104. package/dist/providers/openrouter/videos.js +1 -0
  105. package/dist/providers/openrouter.d.ts +31 -0
  106. package/dist/providers/openrouter.js +8 -0
  107. package/dist/providers/venice.d.ts +26 -0
  108. package/dist/providers/volcengine/videos.d.ts +2 -0
  109. package/dist/providers/volcengine/videos.js +1 -0
  110. package/dist/providers/volcengine.d.ts +26 -0
  111. package/dist/providers/volcengine.js +21 -0
  112. package/dist/providers/xai/videos.d.ts +2 -0
  113. package/dist/providers/xai/videos.js +1 -0
  114. package/dist/providers/xai.d.ts +4 -3
  115. package/dist/providers/xai.js +5 -1
  116. package/dist/providers/zai-coding-plan.d.ts +50 -2
  117. package/dist/public.d.ts +7 -4
  118. package/dist/public.js +2 -1
  119. package/dist/route/client.d.ts +2 -0
  120. package/dist/route/client.js +5 -1
  121. package/dist/route/executor-service.d.ts +20 -1
  122. package/dist/route/executor-service.js +35 -1
  123. package/dist/route/executor.d.ts +11 -2
  124. package/dist/route/executor.js +25 -5
  125. package/dist/route/media-protocol.d.ts +21 -15
  126. package/dist/route/media-protocol.js +11 -4
  127. package/dist/route/media.d.ts +2 -0
  128. package/dist/route/media.js +40 -22
  129. package/dist/route/protocol.d.ts +3 -0
  130. package/dist/route/transport/http.js +1 -1
  131. package/dist/schema/events.d.ts +5 -0
  132. package/dist/schema/messages.d.ts +25 -2
  133. package/dist/schema/messages.js +27 -7
  134. package/dist/schema/options.d.ts +18 -2
  135. package/dist/schema/options.js +1 -0
  136. package/dist/speech-client.d.ts +6 -6
  137. package/dist/speech-client.js +4 -4
  138. package/dist/speech.d.ts +7 -88
  139. package/dist/speech.js +1 -3
  140. package/dist/tool-updates.d.ts +34 -0
  141. package/dist/tool-updates.js +93 -0
  142. package/dist/tool.d.ts +6 -1
  143. package/dist/tool.js +1 -1
  144. package/dist/transcription-client.d.ts +6 -6
  145. package/dist/transcription-client.js +1 -2
  146. package/dist/transcription.d.ts +7 -88
  147. package/dist/transcription.js +1 -3
  148. package/dist/video-client.d.ts +16 -84
  149. package/dist/video-client.js +30 -13
  150. package/dist/video.d.ts +54 -1126
  151. package/dist/video.js +29 -65
  152. package/package.json +59 -7
  153. package/dist/protocols/google-video.d.ts +0 -26
  154. package/dist/protocols/google-video.js +0 -146
  155. package/dist/protocols/runway-video.d.ts +0 -38
  156. package/dist/protocols/runway-video.js +0 -141
  157. package/dist/providers/runway.d.ts +0 -20
  158. package/dist/providers/runway.js +0 -17
@@ -0,0 +1,133 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { DecisionResponse, DecisionUsage } from "../decision.js";
3
+ import { DecisionRoute } from "../route/decision.js";
4
+ import { Endpoint } from "../route/endpoint.js";
5
+ import { MediaProtocol } from "../route/media-protocol.js";
6
+ import { AIError, ProviderID, UnsupportedOperationError, mergeJsonRecords, } from "../schema/index.js";
7
+ import { encodeJson } from "../utils/json.js";
8
+ import { JsonObject, knownString, ProviderShared } from "./shared.js";
9
+ import { SystemOne } from "./system-one.js";
10
+ import { MediaInput } from "./utils/media-input.js";
11
+ const ID = "google-decisions";
12
+ const NAME = "Google Decisions";
13
+ export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
14
+ const Options = Schema.Struct({
15
+ /** Token budget for every image and video input; `ultra_high` applies to images only. */
16
+ mediaResolution: Schema.optional(knownString()),
17
+ });
18
+ const Usage = Schema.StructWithRest(Schema.Struct({
19
+ total_input_tokens: Schema.optional(Schema.Number),
20
+ total_output_tokens: Schema.optional(Schema.Number),
21
+ total_tokens: Schema.optional(Schema.Number),
22
+ }), [JsonObject]);
23
+ const Response = Schema.Struct({
24
+ answers: Schema.Record(Schema.String, SystemOne.Answer),
25
+ usage: Schema.optional(Usage),
26
+ });
27
+ const decodeOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(Options));
28
+ const fromRequest = Effect.fn("GoogleDecisions.fromRequest")(function* (request) {
29
+ const options = yield* decodeOptions(request.providerOptions ?? {});
30
+ const { mediaResolution: _, ...native } = request.providerOptions ?? {};
31
+ return {
32
+ ...mergeJsonRecords(native, request.http?.body),
33
+ model: request.model.id,
34
+ input: separateText(yield* Effect.forEach(request.input, (part) => inputPart(request, part, options.mediaResolution))),
35
+ questions: {
36
+ ...(yield* SystemOne.encodeQuestions(request.questions)),
37
+ // Google names System One's predicate criteria `true_description` and `false_description`.
38
+ ...Object.fromEntries(request.questions.flatMap((question) => question.type === "predicate" && question.criteria !== undefined
39
+ ? [
40
+ [
41
+ question.name,
42
+ {
43
+ type: "noul",
44
+ instructions: question.instructions,
45
+ criteria: {
46
+ ...(question.criteria.true === undefined ? {} : { true_description: question.criteria.true }),
47
+ ...(question.criteria.false === undefined ? {} : { false_description: question.criteria.false }),
48
+ },
49
+ },
50
+ ],
51
+ ]
52
+ : [])),
53
+ },
54
+ };
55
+ });
56
+ const inputPart = (request, part, resolution) => {
57
+ if (part.type === "text")
58
+ return Effect.succeed({ type: "text", text: part.text });
59
+ // Google reads every text block as text; JSON is serialized so its keys are never parsed as content blocks.
60
+ if (part.type === "json")
61
+ return Effect.succeed({ type: "text", text: encodeJson(part.value) });
62
+ return mediaPart(request, part.media, resolution);
63
+ };
64
+ // Google joins adjacent text blocks with no separator, so each one after another starts on a new line.
65
+ const separateText = (blocks) => blocks.map((block, index) => block.type === "text" && blocks[index - 1]?.type === "text" ? { ...block, text: `\n${block.text}` } : block);
66
+ const mediaPart = (request, asset, resolution) => {
67
+ const type = asset.kind === "image" || asset.kind === "audio" || asset.kind === "video"
68
+ ? asset.kind
69
+ : asset.mediaType.toLowerCase() === "application/pdf"
70
+ ? "document"
71
+ : undefined;
72
+ if (type === undefined)
73
+ return Effect.fail(new AIError({
74
+ reason: new UnsupportedOperationError({
75
+ operation: "decision.media",
76
+ provider: request.model.provider,
77
+ route: request.model.route.id,
78
+ message: `${NAME} takes images, audio, video and PDFs; got ${asset.mediaType}`,
79
+ }),
80
+ }));
81
+ const block = {
82
+ type,
83
+ mime_type: asset.mediaType.toLowerCase(),
84
+ // `ultra_high` is image-only, so video keeps Google's default for it.
85
+ ...(resolution !== undefined && (type === "image" || (type === "video" && resolution !== "ultra_high"))
86
+ ? { resolution }
87
+ : {}),
88
+ };
89
+ const inline = asset.inline();
90
+ if (inline)
91
+ return Effect.succeed({ ...block, data: inline.base64 });
92
+ // Google fetches URLs itself, so one that needs our download credentials can't be forwarded.
93
+ if (asset.source.type === "url" && /^https:\/\//i.test(asset.source.url) && asset.headers === undefined)
94
+ return Effect.succeed({ ...block, uri: asset.source.url });
95
+ const file = MediaInput.refID(asset, ProviderID.make("google"));
96
+ if (file !== undefined)
97
+ return Effect.succeed({ ...block, uri: file });
98
+ return Effect.fail(ProviderShared.invalidRequest(`${NAME} accepts inline media, public HTTPS URLs and Google Files API URIs; materialize ${asset.source.type} media first`));
99
+ };
100
+ const decodeDocument = MediaProtocol.identity({ id: ID, name: NAME, provider: "google" }).decodeJson(Response);
101
+ export const protocol = DecisionRoute.protocol({
102
+ id: ID,
103
+ name: NAME,
104
+ body: { from: fromRequest },
105
+ response: {
106
+ decode: Effect.fn("GoogleDecisions.decodeResponse")(function* (response, context) {
107
+ const output = yield* decodeDocument(response);
108
+ const data = output.value;
109
+ const answers = data.answers;
110
+ const names = context.request.questions.map((question) => question.name);
111
+ if (Object.keys(answers).length !== names.length || !names.every((name) => Object.hasOwn(answers, name)))
112
+ return yield* output.invalid(`${NAME} answers do not match the requested questions`);
113
+ return new DecisionResponse({
114
+ answers: context.request.questions.map((question) => SystemOne.toAnswer(question, answers[question.name])),
115
+ usage: data.usage === undefined
116
+ ? undefined
117
+ : new DecisionUsage({
118
+ inputTokens: data.usage.total_input_tokens,
119
+ outputTokens: data.usage.total_output_tokens,
120
+ totalTokens: ProviderShared.totalTokens(data.usage.total_input_tokens, data.usage.total_output_tokens, data.usage.total_tokens),
121
+ }),
122
+ providerMetadata: data.usage === undefined ? undefined : { [context.providerMetadataKey]: { usage: data.usage } },
123
+ });
124
+ }),
125
+ },
126
+ });
127
+ export const route = DecisionRoute.make({
128
+ id: ID,
129
+ provider: "google",
130
+ protocol,
131
+ endpoint: Endpoint.path("/decisions", { baseURL: DEFAULT_BASE_URL }),
132
+ });
133
+ export * as GoogleDecisions from "./google-decisions.js";
@@ -0,0 +1,38 @@
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
+ export declare const PATH = "/interactions";
8
+ /**
9
+ * Provider-native Interactions fields, merged into the body. Common fields (`start`, `end`, `references`,
10
+ * `duration`, `aspect`, `resolution`) live on the request. Edit or extend a video by passing it as a reference with
11
+ * `generation_config.video_config.task`, or continue a generated one with `previous_interaction_id`.
12
+ */
13
+ export type GoogleVideoOptions = {
14
+ readonly previous_interaction_id?: string;
15
+ readonly generation_config?: {
16
+ readonly video_config?: {
17
+ readonly task?: OpenString<"text_to_video" | "image_to_video" | "reference_to_video" | "edit" | "extend">;
18
+ } & Record<string, unknown>;
19
+ } & Record<string, unknown>;
20
+ readonly response_format?: {
21
+ readonly delivery?: OpenString<"inline" | "uri">;
22
+ } & Record<string, unknown>;
23
+ readonly service_tier?: OpenString<"flex" | "standard" | "priority">;
24
+ readonly webhook_config?: {
25
+ readonly uris?: ReadonlyArray<string>;
26
+ readonly user_metadata?: Record<string, unknown>;
27
+ };
28
+ } & Record<string, unknown>;
29
+ export type Request = VideoRequest<VideoModel<GoogleVideoOptions>>;
30
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
31
+ export declare const Token: Schema.String;
32
+ export type Token = Schema.Schema.Type<typeof Token>;
33
+ export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
34
+ export declare const model: (input: MediaRoute.ModelInput) => VideoModel<GoogleVideoOptions>;
35
+ export declare const GoogleInteractionsVideo: {
36
+ readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
37
+ readonly model: typeof model;
38
+ };
@@ -0,0 +1,185 @@
1
+ import { 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, tokenUsage } from "../schema/index.js";
6
+ import { VideoModel, VideoResponse, seconds } from "../video.js";
7
+ import { GoogleInteractions } from "./google-interactions.js";
8
+ import { optionalNull } from "./shared.js";
9
+ import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
10
+ import { MediaInput } from "./utils/media-input.js";
11
+ const route = MediaProtocol.identity({
12
+ id: "google-interactions-video",
13
+ name: "Google Interactions Video",
14
+ provider: "google",
15
+ });
16
+ export const DEFAULT_BASE_URL = GoogleInteractions.DEFAULT_BASE_URL;
17
+ export const PATH = "/interactions";
18
+ // ---------------------------------------------------------------------------
19
+ // 2. Token and response schemas
20
+ // ---------------------------------------------------------------------------
21
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
22
+ export const Token = Schema.String;
23
+ const Content = Schema.Struct({
24
+ type: Schema.String,
25
+ data: optionalNull(Schema.String),
26
+ uri: optionalNull(Schema.String),
27
+ mime_type: optionalNull(Schema.String),
28
+ text: optionalNull(Schema.String),
29
+ });
30
+ const Usage = Schema.StructWithRest(Schema.Struct({
31
+ total_input_tokens: optionalNull(Schema.Number),
32
+ total_output_tokens: optionalNull(Schema.Number),
33
+ total_thought_tokens: optionalNull(Schema.Number),
34
+ total_tokens: optionalNull(Schema.Number),
35
+ }), [Schema.Record(Schema.String, Schema.Unknown)]);
36
+ const Interaction = Schema.Struct({
37
+ id: Schema.String,
38
+ status: Schema.String,
39
+ model: optionalNull(Schema.String),
40
+ steps: optionalNull(Schema.Array(Schema.Struct({ type: Schema.String, content: optionalNull(Schema.Array(Content)) }))),
41
+ usage: optionalNull(Usage),
42
+ errors: optionalNull(Schema.Array(Schema.Struct({ code: optionalNull(Schema.String), message: optionalNull(Schema.String) }))),
43
+ });
44
+ // `incomplete` is terminal ("completed, but contains incomplete results"); the result read decides whether a video
45
+ // came back. `requires_action` and `requires_continuation` are not documented for video and stay running.
46
+ const STATUS = {
47
+ in_progress: "running",
48
+ completed: "completed",
49
+ incomplete: "completed",
50
+ failed: "failed",
51
+ cancelled: "cancelled",
52
+ };
53
+ // ---------------------------------------------------------------------------
54
+ // 3. Failures
55
+ // ---------------------------------------------------------------------------
56
+ // Interaction error codes are documented only as "a URI that identifies the error type"; the last segment carries the
57
+ // canonical Google status name.
58
+ const FAILURE = {
59
+ INVALID_ARGUMENT: "InvalidRequest",
60
+ FAILED_PRECONDITION: "InvalidRequest",
61
+ OUT_OF_RANGE: "InvalidRequest",
62
+ PERMISSION_DENIED: "Authentication",
63
+ UNAUTHENTICATED: "Authentication",
64
+ RESOURCE_EXHAUSTED: "RateLimit",
65
+ };
66
+ const errorCode = (code) => code?.split("/").at(-1)?.trim().toUpperCase().replaceAll("-", "_") || undefined;
67
+ // ---------------------------------------------------------------------------
68
+ // 5. Request body construction
69
+ // ---------------------------------------------------------------------------
70
+ // Omni has no role field for media: it reads one image as the start frame and two as start and end. The task hint
71
+ // pins that reading when only frames, or only references, are sent; with both, the prompt decides.
72
+ const task = (request) => {
73
+ const frames = request.start !== undefined || request.end !== undefined;
74
+ const references = (request.references ?? []).length > 0;
75
+ if (frames && !references)
76
+ return "image_to_video";
77
+ if (references && !frames)
78
+ return "reference_to_video";
79
+ return undefined;
80
+ };
81
+ const fromRequest = Effect.fn("GoogleInteractionsVideo.fromRequest")(function* (request) {
82
+ if (request.end !== undefined && request.start === undefined)
83
+ return yield* route.unsupported("video.end", `${route.name} reads a lone image as the start frame; send start too`);
84
+ const media = yield* Effect.forEach([request.start, request.end, ...(request.references ?? [])].filter((asset) => asset !== undefined), GoogleInteractions.mediaContent);
85
+ const responseFormat = {
86
+ // `auto` follows the input image, which Omni expresses by leaving the ratio out.
87
+ aspect_ratio: request.aspect === "auto" ? undefined : request.aspect,
88
+ resolution: request.resolution?.toLowerCase(),
89
+ duration: request.duration === undefined ? undefined : `${seconds(request.duration)}s`,
90
+ };
91
+ const videoTask = task(request);
92
+ return MediaProtocol.json(mergeJsonRecords({
93
+ model: request.model.id,
94
+ input: [...media, { type: "text", text: request.prompt }],
95
+ background: true,
96
+ response_format: Object.values(responseFormat).some((value) => value !== undefined)
97
+ ? { type: "video", ...responseFormat }
98
+ : undefined,
99
+ generation_config: videoTask === undefined ? undefined : { video_config: { task: videoTask } },
100
+ }, request.providerOptions, request.http?.body) ?? {});
101
+ });
102
+ // ---------------------------------------------------------------------------
103
+ // 6. Response decoding
104
+ // ---------------------------------------------------------------------------
105
+ const decodeStart = route.decodeStarted(Interaction, (value) => ({
106
+ token: value.id,
107
+ snapshot: { id: value.id, ...MediaProtocol.status(STATUS, value.status) },
108
+ }));
109
+ const decodeInteraction = route.decodeJson(Interaction);
110
+ const decodeStatus = Effect.fn("GoogleInteractionsVideo.decodeStatus")(function* (response, context) {
111
+ const output = yield* decodeInteraction(response);
112
+ return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
113
+ });
114
+ const decodeResult = Effect.fn("GoogleInteractionsVideo.decodeResult")(function* (response, context) {
115
+ const output = yield* decodeInteraction(response);
116
+ const decoded = output.value;
117
+ const status = MediaProtocol.state(STATUS, decoded.status);
118
+ if (status === "running")
119
+ return yield* output.pending(context.token);
120
+ const errors = decoded.errors ?? [];
121
+ const codes = errors.flatMap((error) => {
122
+ const code = errorCode(error.code);
123
+ return code === undefined ? [] : [code];
124
+ });
125
+ const messages = errors.flatMap((error) => (error.message?.trim() ? [error.message.trim()] : []));
126
+ if (status === "cancelled")
127
+ return yield* output.ended("cancelled", `${route.name} interaction ${context.token} was cancelled`);
128
+ if (status === "failed") {
129
+ const message = `${route.name} generation failed${codes.length === 0 ? "" : ` (${codes.join(", ")})`}${messages.length === 0 ? "" : `: ${messages.join("\n")}`}`;
130
+ if (codes.some((code) => code === "CONTENT_BLOCKED" || GeminiGenerateContent.contentFiltered(code)))
131
+ return yield* output.contentPolicy(message);
132
+ return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, codes[0]));
133
+ }
134
+ const contents = (decoded.steps ?? []).flatMap((step) => (step.type === "model_output" ? (step.content ?? []) : []));
135
+ const videos = yield* Effect.forEach(contents.filter((content) => content.type === "video"), (content, index) => {
136
+ const mediaType = content.mime_type ?? undefined;
137
+ if (content.data)
138
+ return MediaInput.decodedAsset(output.invalid, `${route.name} video ${index}`, content.data, mediaType);
139
+ // `GET /interactions/{id}` documents inline data even for `delivery: "uri"`; a Files API URI needs the API key
140
+ // to download, so it stays a Google reference that can be passed back as input.
141
+ if (content.uri)
142
+ return Effect.succeed(Media.ref(route.provider, content.uri, mediaType));
143
+ return Effect.fail(output.invalid(`${route.name} returned a video without data or a URI`));
144
+ });
145
+ if (videos.length === 0) {
146
+ if (codes.some((code) => code === "CONTENT_BLOCKED" || GeminiGenerateContent.contentFiltered(code)))
147
+ return yield* output.contentPolicy(`${route.name} withheld the video${messages.length === 0 ? "" : `: ${messages.join("\n")}`}`);
148
+ return yield* output.invalid(`${route.name} ${decoded.status} without a video`);
149
+ }
150
+ const usage = decoded.usage ?? undefined;
151
+ return new VideoResponse({
152
+ videos,
153
+ usage: usage === undefined
154
+ ? undefined
155
+ : tokenUsage({
156
+ input: usage.total_input_tokens ?? undefined,
157
+ output: usage.total_output_tokens ?? undefined,
158
+ total: usage.total_tokens ?? undefined,
159
+ details: { reasoningTokens: usage.total_thought_tokens ?? undefined, google: usage },
160
+ }),
161
+ providerMetadata: {
162
+ google: {
163
+ interactionId: decoded.id,
164
+ model: decoded.model ?? undefined,
165
+ status: decoded.status,
166
+ },
167
+ },
168
+ });
169
+ });
170
+ // ---------------------------------------------------------------------------
171
+ // 7. Protocol and route
172
+ // ---------------------------------------------------------------------------
173
+ const interactionPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
174
+ export const protocol = MediaProtocol.queued(route, {
175
+ token: Token,
176
+ start: { body: { from: fromRequest }, decode: decodeStart },
177
+ status: { path: interactionPath, decode: decodeStatus },
178
+ result: { path: interactionPath, decode: decodeResult },
179
+ cancel: { method: "POST", path: (token) => `${interactionPath(token)}/cancel` },
180
+ });
181
+ export const model = (input) => VideoModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
182
+ export const GoogleInteractionsVideo = {
183
+ protocol,
184
+ model,
185
+ };
@@ -1,6 +1,8 @@
1
- import { Schema } from "effect";
1
+ import { Effect, Schema } from "effect";
2
2
  import { Route } from "../route/client.js";
3
3
  import { Protocol } from "../route/protocol.js";
4
+ import { AIError } from "../schema/index.js";
5
+ import { Media } from "../media.js";
4
6
  import { Lifecycle } from "./utils/lifecycle.js";
5
7
  import { ToolStream } from "./utils/tool-stream.js";
6
8
  export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
@@ -36,6 +38,17 @@ interface ParserState {
36
38
  readonly steps: Partial<Record<number, OutputStep>>;
37
39
  readonly tools: ToolStream.State<number>;
38
40
  }
41
+ export declare const mediaContent: (asset: Media.Asset) => Effect.Effect<{
42
+ type: "audio" | "document" | "image" | "video";
43
+ uri: string;
44
+ mime_type: string;
45
+ data?: undefined;
46
+ } | {
47
+ uri?: undefined;
48
+ type: "audio" | "document" | "image" | "video";
49
+ data: string;
50
+ mime_type: string;
51
+ }, AIError, never>;
39
52
  export declare const protocol: Protocol<{
40
53
  readonly model: string;
41
54
  readonly input: readonly ({
@@ -172,7 +172,7 @@ const Event = Schema.Union([
172
172
  // =============================================================================
173
173
  // Request Body Construction
174
174
  // =============================================================================
175
- const mediaContent = Effect.fnUntraced(function* (asset) {
175
+ export const mediaContent = Effect.fnUntraced(function* (asset) {
176
176
  if (asset.kind !== "image" &&
177
177
  asset.kind !== "audio" &&
178
178
  asset.kind !== "video" &&
@@ -35,10 +35,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
35
35
  readonly startSeconds: number;
36
36
  readonly endSeconds: number;
37
37
  }[];
38
- } | {
39
- readonly type: "generation-queued";
40
- readonly id: string;
41
- readonly position?: number | undefined;
42
38
  } | {
43
39
  readonly type: "generation-progress";
44
40
  readonly id: string;
@@ -85,10 +81,6 @@ export declare const GoogleSpeech: {
85
81
  readonly startSeconds: number;
86
82
  readonly endSeconds: number;
87
83
  }[];
88
- } | {
89
- readonly type: "generation-queued";
90
- readonly id: string;
91
- readonly position?: number | undefined;
92
84
  } | {
93
85
  readonly type: "generation-progress";
94
86
  readonly id: string;
@@ -32,10 +32,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
32
32
  readonly endSeconds: number;
33
33
  readonly speaker?: string | undefined;
34
34
  };
35
- } | {
36
- readonly type: "generation-queued";
37
- readonly id: string;
38
- readonly position?: number | undefined;
39
35
  } | {
40
36
  readonly type: "generation-progress";
41
37
  readonly id: string;
@@ -98,10 +94,6 @@ export declare const GoogleTranscription: {
98
94
  readonly endSeconds: number;
99
95
  readonly speaker?: string | undefined;
100
96
  };
101
- } | {
102
- readonly type: "generation-queued";
103
- readonly id: string;
104
- readonly position?: number | undefined;
105
97
  } | {
106
98
  readonly type: "generation-progress";
107
99
  readonly id: string;
@@ -3,6 +3,7 @@ export * as BedrockConverse from "./bedrock-converse.js";
3
3
  export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
4
4
  export * as CohereChat from "./cohere-chat.js";
5
5
  export * as Gemini from "./gemini.js";
6
+ export * as GoogleDecisions from "./google-decisions.js";
6
7
  export * as GoogleEmbedContent from "./google-embed-content.js";
7
8
  export * as GoogleInteractions from "./google-interactions.js";
8
9
  export * as GoogleVertexPredictEmbeddings from "./google-vertex-predict-embeddings.js";
@@ -3,6 +3,7 @@ export * as BedrockConverse from "./bedrock-converse.js";
3
3
  export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
4
4
  export * as CohereChat from "./cohere-chat.js";
5
5
  export * as Gemini from "./gemini.js";
6
+ export * as GoogleDecisions from "./google-decisions.js";
6
7
  export * as GoogleEmbedContent from "./google-embed-content.js";
7
8
  export * as GoogleInteractions from "./google-interactions.js";
8
9
  export * as GoogleVertexPredictEmbeddings from "./google-vertex-predict-embeddings.js";
@@ -228,14 +228,36 @@ export declare const protocol: Protocol<{
228
228
  })[];
229
229
  } | {
230
230
  readonly role: "system";
231
- readonly content: readonly {
231
+ readonly content: readonly ({
232
+ readonly type: "tool_addition";
233
+ readonly tool: {
234
+ readonly type: "tool_definition";
235
+ readonly definition: {
236
+ readonly name: string;
237
+ readonly description: string;
238
+ readonly input_schema: {
239
+ readonly [x: string]: unknown;
240
+ };
241
+ readonly cache_control?: {
242
+ readonly type: "ephemeral";
243
+ readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
244
+ } | undefined;
245
+ };
246
+ };
247
+ } | {
248
+ readonly type: "tool_removal";
249
+ readonly tool: {
250
+ readonly type: "tool_reference";
251
+ readonly name: string;
252
+ };
253
+ } | {
232
254
  readonly type: "text";
233
255
  readonly text: string;
234
256
  readonly cache_control?: {
235
257
  readonly type: "ephemeral";
236
258
  readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
237
259
  } | undefined;
238
- }[];
260
+ })[];
239
261
  readonly output_config?: {
240
262
  readonly effort: string;
241
263
  } | undefined;
@@ -31,6 +31,32 @@ export declare const protocol: Protocol<{
31
31
  readonly reasoning: {
32
32
  readonly effort: import("../schema/options.js").ReasoningEffort;
33
33
  };
34
+ } | {
35
+ readonly type: "additional_tools";
36
+ readonly role: "developer";
37
+ readonly tools: readonly ({
38
+ readonly type: "custom";
39
+ readonly name: string;
40
+ readonly description: string;
41
+ readonly format: {
42
+ readonly type: "text";
43
+ } | {
44
+ readonly type: "grammar";
45
+ readonly syntax: "lark" | "regex";
46
+ readonly definition: string;
47
+ };
48
+ } | {
49
+ readonly type: "function";
50
+ readonly name: string;
51
+ readonly description: string;
52
+ readonly parameters: {
53
+ readonly [x: string]: unknown;
54
+ };
55
+ readonly strict?: boolean | undefined;
56
+ } | {
57
+ readonly [x: string]: unknown;
58
+ readonly type: string;
59
+ })[];
34
60
  } | {
35
61
  readonly type: "message";
36
62
  readonly role: "system";
@@ -287,6 +313,32 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
287
313
  readonly reasoning: {
288
314
  readonly effort: import("../schema/options.js").ReasoningEffort;
289
315
  };
316
+ } | {
317
+ readonly type: "additional_tools";
318
+ readonly role: "developer";
319
+ readonly tools: readonly ({
320
+ readonly type: "custom";
321
+ readonly name: string;
322
+ readonly description: string;
323
+ readonly format: {
324
+ readonly type: "text";
325
+ } | {
326
+ readonly type: "grammar";
327
+ readonly syntax: "lark" | "regex";
328
+ readonly definition: string;
329
+ };
330
+ } | {
331
+ readonly type: "function";
332
+ readonly name: string;
333
+ readonly description: string;
334
+ readonly parameters: {
335
+ readonly [x: string]: unknown;
336
+ };
337
+ readonly strict?: boolean | undefined;
338
+ } | {
339
+ readonly [x: string]: unknown;
340
+ readonly type: string;
341
+ })[];
290
342
  } | {
291
343
  readonly type: "message";
292
344
  readonly role: "system";
@@ -0,0 +1,45 @@
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
+ /** The API host without a version: H3 is served under `/v2` and Hailuo under `/v1`. */
7
+ export declare const DEFAULT_BASE_URL = "https://api.minimax.io";
8
+ export declare const PATH = "/v2/video_generation";
9
+ export declare const STATUS_PATH = "/v2/query/video_generation";
10
+ export declare const HAILUO_PATH = "/v1/video_generation";
11
+ export declare const HAILUO_STATUS_PATH = "/v1/query/video_generation";
12
+ export declare const FILE_PATH = "/v1/files/retrieve";
13
+ /**
14
+ * Provider-native options, merged into the body. Common fields (`start`, `end`, `references`, `duration`, `aspect`,
15
+ * `resolution`, `sound`) live on the request. `extra` and `response_format` are H3 (v2) fields; `prompt_optimizer`
16
+ * and `fast_pretreatment` are Hailuo (v1) fields; both APIs take `callback_url`.
17
+ */
18
+ export type MiniMaxVideoOptions = {
19
+ readonly extra?: {
20
+ readonly prompt_expansion_mode?: OpenString<"disabled" | "balanced" | "quality">;
21
+ };
22
+ readonly response_format?: OpenString<"task" | "flat">;
23
+ readonly prompt_optimizer?: boolean;
24
+ readonly fast_pretreatment?: boolean;
25
+ readonly callback_url?: string;
26
+ } & Record<string, unknown>;
27
+ export type Request = VideoRequest<VideoModel<MiniMaxVideoOptions>>;
28
+ /** The provider's job ID; it is all a later status, result or cancel call needs. */
29
+ export declare const Token: Schema.String;
30
+ export type Token = Schema.Schema.Type<typeof Token>;
31
+ export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
32
+ export declare const hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, string>;
33
+ /** H3 and later models on the v2 API. */
34
+ export declare const h3Model: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
35
+ /** Hailuo and the `*-01` models on the v1 API. */
36
+ export declare const hailuoModel: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
37
+ /** Picks the API by model family: Hailuo and `*-01` models use v1, everything else v2. */
38
+ export declare const model: (input: MediaRoute.ModelInput) => VideoModel<MiniMaxVideoOptions>;
39
+ export declare const MiniMaxVideo: {
40
+ readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
41
+ readonly hailuoProtocol: MediaProtocol.Queued<Request, VideoResponse, string>;
42
+ readonly model: typeof model;
43
+ readonly h3Model: typeof h3Model;
44
+ readonly hailuoModel: typeof hailuoModel;
45
+ };