@opencode/ai 2.1.4 → 2.2.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.
- package/README.md +283 -114
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +4 -0
- package/dist/cache-policy.js +20 -6
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +472 -0
- package/dist/decision.js +158 -0
- package/dist/effect.d.ts +38 -0
- package/dist/effect.js +27 -0
- package/dist/effort-updates.d.ts +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
- package/dist/experimental/cloudflare-run-extraction.js +83 -0
- package/dist/experimental/extraction.d.ts +183 -0
- package/dist/experimental/extraction.js +102 -0
- package/dist/experimental/realtime.d.ts +7 -2
- package/dist/experimental/realtime.js +5 -5
- package/dist/experimental.d.ts +2 -3
- package/dist/experimental.js +1 -2
- package/dist/image-client.d.ts +5 -14
- package/dist/image-client.js +0 -1
- package/dist/image.d.ts +6 -176
- package/dist/image.js +4 -11
- package/dist/index.d.ts +1426 -34
- package/dist/index.js +127 -24
- package/dist/llm.d.ts +16 -1
- package/dist/llm.js +34 -0
- package/dist/media-client.d.ts +2 -1
- package/dist/media-model.d.ts +3 -0
- package/dist/media-model.js +4 -1
- package/dist/media.d.ts +0 -7
- package/dist/media.js +0 -6
- package/dist/protocols/alibaba-chat.d.ts +20 -0
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +52 -17
- package/dist/protocols/alibaba-responses.d.ts +6 -3
- package/dist/protocols/anthropic-messages.d.ts +160 -54
- package/dist/protocols/anthropic-messages.js +44 -13
- package/dist/protocols/bedrock-converse.d.ts +110 -15
- package/dist/protocols/bedrock-converse.js +112 -15
- package/dist/protocols/bedrock-event-stream.js +1 -0
- package/dist/protocols/bfl-images.d.ts +9 -0
- package/dist/protocols/bfl-images.js +17 -15
- package/dist/protocols/cartesia-speech.d.ts +0 -18
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
- package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
- package/dist/protocols/deepgram-speech.d.ts +0 -18
- package/dist/protocols/elevenlabs-speech.d.ts +0 -18
- package/dist/protocols/fal-images.d.ts +10 -1
- package/dist/protocols/fal-images.js +16 -25
- package/dist/protocols/fal-video.js +1 -1
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +11 -6
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-images.js +8 -37
- package/dist/protocols/google-interactions.d.ts +4 -0
- package/dist/protocols/google-interactions.js +12 -5
- package/dist/protocols/google-speech.d.ts +0 -18
- package/dist/protocols/google-speech.js +0 -1
- package/dist/protocols/google-transcription.d.ts +0 -18
- package/dist/protocols/google-transcription.js +0 -1
- package/dist/protocols/google-video.d.ts +1 -1
- package/dist/protocols/google-video.js +2 -7
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +7 -1
- package/dist/protocols/meta-images.js +10 -8
- package/dist/protocols/meta-messages.d.ts +52 -17
- package/dist/protocols/meta-messages.js +14 -1
- package/dist/protocols/meta-responses.d.ts +6 -0
- package/dist/protocols/meta-responses.js +29 -1
- package/dist/protocols/open-responses.d.ts +30 -0
- package/dist/protocols/open-responses.js +8 -18
- package/dist/protocols/openai-chat.d.ts +713 -1
- package/dist/protocols/openai-chat.js +35 -22
- package/dist/protocols/openai-compatible-chat.d.ts +22 -1
- package/dist/protocols/openai-compatible-responses.d.ts +8 -5
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +128 -0
- package/dist/protocols/openai-images.d.ts +21 -24
- package/dist/protocols/openai-images.js +100 -34
- package/dist/protocols/openai-responses.d.ts +82 -24
- package/dist/protocols/openai-responses.js +32 -2
- package/dist/protocols/openai-speech.d.ts +0 -18
- package/dist/protocols/openai-speech.js +15 -5
- package/dist/protocols/openai-transcription.d.ts +0 -18
- package/dist/protocols/openai-transcription.js +3 -4
- package/dist/protocols/replicate-images.js +1 -1
- package/dist/protocols/runway-video.d.ts +1 -1
- package/dist/protocols/runway-video.js +1 -1
- package/dist/protocols/shared.d.ts +9 -1
- package/dist/protocols/shared.js +13 -2
- package/dist/protocols/stability-images.d.ts +5 -0
- package/dist/protocols/stability-images.js +4 -9
- package/dist/protocols/system-one.d.ts +101 -0
- package/dist/protocols/system-one.js +230 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
- package/dist/protocols/utils/bedrock-cache.js +7 -6
- package/dist/protocols/utils/cache.d.ts +14 -3
- package/dist/protocols/utils/cache.js +11 -4
- package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
- package/dist/protocols/utils/gemini-generate-content.js +10 -16
- package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
- package/dist/protocols/utils/gemini-json-schema.js +3 -3
- package/dist/protocols/utils/image-sizing.d.ts +31 -0
- package/dist/protocols/utils/image-sizing.js +73 -0
- package/dist/protocols/utils/media-input.d.ts +4 -5
- package/dist/protocols/utils/media-input.js +8 -5
- package/dist/protocols/utils/speech-stream.d.ts +0 -1
- package/dist/protocols/utils/speech-stream.js +0 -1
- package/dist/protocols/utils/tool-schema.js +15 -5
- package/dist/protocols/utils/tool-stream.d.ts +9 -0
- package/dist/protocols/venice-chat.d.ts +19 -0
- package/dist/protocols/venice-chat.js +1 -1
- package/dist/protocols/xai-images.d.ts +1 -2
- package/dist/protocols/xai-images.js +9 -2
- package/dist/protocols/xai-responses.d.ts +10 -0
- package/dist/protocols/xai-responses.js +28 -2
- package/dist/protocols/xai-video.d.ts +1 -1
- package/dist/protocols/xai-video.js +11 -8
- package/dist/protocols/zai-chat.d.ts +21 -0
- package/dist/protocols/zai-images.d.ts +3 -1
- package/dist/protocols/zai-images.js +12 -11
- package/dist/protocols/zai-messages.d.ts +52 -17
- package/dist/provider-error.js +19 -4
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +79 -18
- package/dist/providers/alibaba.js +16 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +197 -138
- package/dist/providers/amazon-bedrock.d.ts +34 -14
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +52 -17
- package/dist/providers/anthropic.d.ts +52 -17
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +50 -9
- package/dist/providers/azure.js +19 -1
- package/dist/providers/baseten/decisions.d.ts +2 -0
- package/dist/providers/baseten/decisions.js +1 -0
- package/dist/providers/baseten.d.ts +51 -1
- package/dist/providers/baseten.js +41 -8
- package/dist/providers/cerebras.d.ts +42 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +177 -43
- package/dist/providers/cloudflare-ai-gateway.js +32 -4
- package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
- package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/images.js +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +55 -1
- package/dist/providers/cloudflare-workers-ai.js +45 -9
- package/dist/providers/cohere.d.ts +42 -0
- package/dist/providers/deepinfra.d.ts +42 -0
- package/dist/providers/deepseek.d.ts +42 -0
- package/dist/providers/digitalocean/decisions.d.ts +2 -0
- package/dist/providers/digitalocean/decisions.js +1 -0
- package/dist/providers/digitalocean/images.d.ts +2 -0
- package/dist/providers/digitalocean/images.js +1 -0
- package/dist/providers/digitalocean.d.ts +72 -1
- package/dist/providers/digitalocean.js +39 -8
- package/dist/providers/fireworks.d.ts +42 -0
- package/dist/providers/google/images.d.ts +2 -0
- package/dist/providers/google/images.js +1 -0
- package/dist/providers/google-vertex/images.d.ts +2 -0
- package/dist/providers/google-vertex/images.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +21 -0
- package/dist/providers/google-vertex-messages.d.ts +52 -17
- package/dist/providers/google-vertex-responses.d.ts +3 -0
- package/dist/providers/google-vertex.d.ts +3 -1
- package/dist/providers/google-vertex.js +30 -13
- package/dist/providers/google.d.ts +5 -4
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +42 -4
- package/dist/providers/groq.js +0 -6
- package/dist/providers/meta.d.ts +197 -138
- package/dist/providers/minimax.d.ts +76 -17
- package/dist/providers/moonshot.d.ts +76 -17
- package/dist/providers/openai/images.d.ts +2 -0
- package/dist/providers/openai/images.js +1 -0
- package/dist/providers/openai-compatible/images.d.ts +2 -0
- package/dist/providers/openai-compatible/images.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +3 -0
- package/dist/providers/openai-compatible.d.ts +24 -1
- package/dist/providers/openai-compatible.js +21 -9
- package/dist/providers/openai-options.d.ts +3 -1
- package/dist/providers/openai.d.ts +46 -9
- package/dist/providers/openai.js +20 -4
- package/dist/providers/opencode/decisions.d.ts +2 -0
- package/dist/providers/opencode/decisions.js +1 -0
- package/dist/providers/opencode.d.ts +9 -10
- package/dist/providers/opencode.js +10 -8
- package/dist/providers/openrouter/decisions.d.ts +2 -0
- package/dist/providers/openrouter/decisions.js +1 -0
- package/dist/providers/openrouter/images.d.ts +2 -0
- package/dist/providers/openrouter/images.js +1 -0
- package/dist/providers/openrouter.d.ts +92 -11
- package/dist/providers/openrouter.js +38 -16
- package/dist/providers/togetherai.d.ts +42 -0
- package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
- package/dist/providers/typesafe-ai/decisions.js +1 -0
- package/dist/providers/typesafe-ai.d.ts +9 -10
- package/dist/providers/typesafe-ai.js +10 -8
- package/dist/providers/venice.d.ts +19 -0
- package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
- package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/images.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +10 -16
- package/dist/providers/vercel-ai-gateway.js +31 -85
- package/dist/providers/xai/images.d.ts +2 -0
- package/dist/providers/xai/images.js +1 -0
- package/dist/providers/xai.d.ts +28 -5
- package/dist/providers/xai.js +15 -8
- package/dist/providers/zai/images.d.ts +2 -0
- package/dist/providers/zai/images.js +1 -0
- package/dist/providers/zai-coding-plan.d.ts +76 -17
- package/dist/providers/zai.d.ts +26 -4
- package/dist/providers/zai.js +15 -8
- package/dist/route/client.d.ts +2 -2
- package/dist/route/client.js +26 -4
- package/dist/route/decision.d.ts +58 -0
- package/dist/route/decision.js +75 -0
- package/dist/route/executor.d.ts +1 -1
- package/dist/route/framing.d.ts +2 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.js +3 -0
- package/dist/route/media-protocol.d.ts +1 -0
- package/dist/route/media-protocol.js +12 -8
- package/dist/route/media.d.ts +5 -1
- package/dist/route/media.js +6 -2
- package/dist/route/transport/http.js +1 -0
- package/dist/route/transport/index.d.ts +1 -0
- package/dist/schema/events.d.ts +148 -6
- package/dist/schema/events.js +20 -0
- package/dist/schema/messages.d.ts +6 -2
- package/dist/schema/messages.js +3 -0
- package/dist/schema/options.d.ts +5 -3
- package/dist/schema/options.js +8 -3
- package/dist/speech-client.d.ts +5 -14
- package/dist/speech-client.js +0 -1
- package/dist/speech.d.ts +0 -135
- package/dist/speech.js +2 -4
- package/dist/testing.d.ts +25 -24
- package/dist/testing.js +3 -21
- package/dist/transcription-client.d.ts +5 -14
- package/dist/transcription.d.ts +0 -135
- package/dist/transcription.js +1 -1
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +5 -14
- package/dist/video-client.js +0 -1
- package/dist/video.d.ts +1 -136
- package/dist/video.js +3 -5
- package/package.json +513 -11
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/system-one.d.ts +0 -16
- package/dist/experimental/system-one.js +0 -135
- package/dist/promise.d.ts +0 -1021
- package/dist/promise.js +0 -101
- package/dist/provider.d.ts +0 -23
- package/dist/provider.js +0 -2
|
@@ -11,6 +11,7 @@ import { encodeJson } from "../utils/json.js";
|
|
|
11
11
|
import { JsonObject, knownString, lenient, optionalNull, ProviderShared } from "./shared.js";
|
|
12
12
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
13
13
|
import { MediaInput } from "./utils/media-input.js";
|
|
14
|
+
import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
|
|
14
15
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
15
16
|
const ADAPTER = "google-interactions";
|
|
16
17
|
export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
@@ -127,6 +128,7 @@ const Interaction = Schema.StructWithRest(Schema.Struct({
|
|
|
127
128
|
id: Schema.optional(Schema.String),
|
|
128
129
|
status: Schema.String,
|
|
129
130
|
usage: Schema.optional(RawUsage),
|
|
131
|
+
errors: Schema.optional(Schema.Array(Schema.Struct({ code: Schema.optional(Schema.String), message: Schema.optional(Schema.String) }))),
|
|
130
132
|
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
131
133
|
const KNOWN_EVENT_TYPES = new Set([
|
|
132
134
|
"step.start",
|
|
@@ -172,7 +174,9 @@ const mediaContent = Effect.fnUntraced(function* (asset) {
|
|
|
172
174
|
asset.mediaType !== "text/csv")
|
|
173
175
|
return yield* ProviderShared.invalidRequest(`Google Interactions does not support ${asset.mediaType} document input`);
|
|
174
176
|
const type = asset.kind === "image" || asset.kind === "audio" || asset.kind === "video" ? asset.kind : "document";
|
|
175
|
-
const uri =
|
|
177
|
+
const uri = asset.kind === "video" && asset.source.type === "url" && /^https?:\/\//i.test(asset.source.url)
|
|
178
|
+
? asset.source.url
|
|
179
|
+
: MediaInput.refID(asset, ProviderID.make("google"));
|
|
176
180
|
if (uri !== undefined)
|
|
177
181
|
return { type, uri, mime_type: asset.mediaType };
|
|
178
182
|
const inline = yield* ProviderShared.requireInlineMedia("Google Interactions", asset);
|
|
@@ -253,7 +257,7 @@ const lowerToolResult = Effect.fnUntraced(function* (part) {
|
|
|
253
257
|
return yield* Effect.forEach(part.result.value, (item) => {
|
|
254
258
|
if (item.type === "text")
|
|
255
259
|
return Effect.succeed({ type: "text", text: item.text });
|
|
256
|
-
return mediaContent(
|
|
260
|
+
return mediaContent(GeminiGenerateContent.toolMedia(item));
|
|
257
261
|
});
|
|
258
262
|
});
|
|
259
263
|
const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (request) {
|
|
@@ -437,14 +441,17 @@ const step = Effect.fnUntraced(function* (state, event) {
|
|
|
437
441
|
});
|
|
438
442
|
case "interaction.completed": {
|
|
439
443
|
const interaction = event.interaction;
|
|
440
|
-
if (interaction.status === "failed" || interaction.status === "cancelled")
|
|
444
|
+
if (interaction.status === "failed" || interaction.status === "cancelled") {
|
|
445
|
+
const messages = (interaction.errors ?? []).flatMap((error) => (error.message?.trim() ? [error.message] : []));
|
|
441
446
|
return yield* new AIError({
|
|
442
447
|
reason: classifyProviderFailure({
|
|
443
|
-
message: `Google Interactions ${interaction.status}`,
|
|
444
|
-
|
|
448
|
+
message: messages.length > 0 ? messages.join("\n") : `Google Interactions ${interaction.status}`,
|
|
449
|
+
// The first coded error decides the classification; every message stays visible.
|
|
450
|
+
data: interaction.errors?.find((error) => error.code) ?? interaction,
|
|
445
451
|
rawBody: encodeJson(event),
|
|
446
452
|
}),
|
|
447
453
|
});
|
|
454
|
+
}
|
|
448
455
|
if (!["completed", "requires_action", "incomplete"].includes(interaction.status))
|
|
449
456
|
return yield* ProviderShared.eventError(ADAPTER, `Unexpected terminal Interactions status: ${interaction.status}`, encodeJson(event));
|
|
450
457
|
const pending = yield* ToolStream.finishAll(ADAPTER, state.tools);
|
|
@@ -67,15 +67,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
67
67
|
readonly [x: string]: unknown;
|
|
68
68
|
} | undefined;
|
|
69
69
|
} | undefined;
|
|
70
|
-
readonly notices?: readonly {
|
|
71
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
72
|
-
readonly message: string;
|
|
73
|
-
readonly providerMetadata?: {
|
|
74
|
-
readonly [x: string]: {
|
|
75
|
-
readonly [x: string]: unknown;
|
|
76
|
-
};
|
|
77
|
-
} | undefined;
|
|
78
|
-
}[] | undefined;
|
|
79
70
|
readonly providerMetadata?: {
|
|
80
71
|
readonly [x: string]: {
|
|
81
72
|
readonly [x: string]: unknown;
|
|
@@ -126,15 +117,6 @@ export declare const GoogleSpeech: {
|
|
|
126
117
|
readonly [x: string]: unknown;
|
|
127
118
|
} | undefined;
|
|
128
119
|
} | undefined;
|
|
129
|
-
readonly notices?: readonly {
|
|
130
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
131
|
-
readonly message: string;
|
|
132
|
-
readonly providerMetadata?: {
|
|
133
|
-
readonly [x: string]: {
|
|
134
|
-
readonly [x: string]: unknown;
|
|
135
|
-
};
|
|
136
|
-
} | undefined;
|
|
137
|
-
}[] | undefined;
|
|
138
120
|
readonly providerMetadata?: {
|
|
139
121
|
readonly [x: string]: {
|
|
140
122
|
readonly [x: string]: unknown;
|
|
@@ -67,7 +67,6 @@ const finish = (state, context) => {
|
|
|
67
67
|
return SpeechStream.finish(route, state, {
|
|
68
68
|
...output,
|
|
69
69
|
usage: GeminiGenerateContent.usage(state.usage),
|
|
70
|
-
notices: GeminiGenerateContent.notices(route.name, state),
|
|
71
70
|
providerMetadata: GeminiGenerateContent.providerMetadata(state),
|
|
72
71
|
detail: `finish reason: ${state.finishReason}`,
|
|
73
72
|
});
|
|
@@ -78,15 +78,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
78
78
|
readonly [x: string]: unknown;
|
|
79
79
|
} | undefined;
|
|
80
80
|
} | undefined;
|
|
81
|
-
readonly notices?: readonly {
|
|
82
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
83
|
-
readonly message: string;
|
|
84
|
-
readonly providerMetadata?: {
|
|
85
|
-
readonly [x: string]: {
|
|
86
|
-
readonly [x: string]: unknown;
|
|
87
|
-
};
|
|
88
|
-
} | undefined;
|
|
89
|
-
}[] | undefined;
|
|
90
81
|
readonly providerMetadata?: {
|
|
91
82
|
readonly [x: string]: {
|
|
92
83
|
readonly [x: string]: unknown;
|
|
@@ -153,15 +144,6 @@ export declare const GoogleTranscription: {
|
|
|
153
144
|
readonly [x: string]: unknown;
|
|
154
145
|
} | undefined;
|
|
155
146
|
} | undefined;
|
|
156
|
-
readonly notices?: readonly {
|
|
157
|
-
readonly type: "filtered" | "moderated" | "other";
|
|
158
|
-
readonly message: string;
|
|
159
|
-
readonly providerMetadata?: {
|
|
160
|
-
readonly [x: string]: {
|
|
161
|
-
readonly [x: string]: unknown;
|
|
162
|
-
};
|
|
163
|
-
} | undefined;
|
|
164
|
-
}[] | undefined;
|
|
165
147
|
readonly providerMetadata?: {
|
|
166
148
|
readonly [x: string]: {
|
|
167
149
|
readonly [x: string]: unknown;
|
|
@@ -103,7 +103,6 @@ const finish = (state) => {
|
|
|
103
103
|
segments: state.segments.length === 0 ? undefined : state.segments,
|
|
104
104
|
words: state.words.length === 0 ? undefined : state.words,
|
|
105
105
|
usage: GeminiGenerateContent.usage(state.usage),
|
|
106
|
-
notices: GeminiGenerateContent.notices(route.name, state),
|
|
107
106
|
providerMetadata: GeminiGenerateContent.providerMetadata(state),
|
|
108
107
|
}),
|
|
109
108
|
]);
|
|
@@ -4,7 +4,7 @@ import { MediaRoute } from "../route/media.js";
|
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
5
5
|
import { VideoModel, VideoResponse, type VideoRequestFor } from "../video.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
7
|
-
/** Provider-native `parameters`. Common fields (`
|
|
7
|
+
/** Provider-native `parameters`. Common fields (`aspect`, `resolution`, `durationSeconds`, `seed`) live on the request. */
|
|
8
8
|
export type GoogleVideoOptions = {
|
|
9
9
|
readonly personGeneration?: OpenString<"allow_all" | "allow_adult" | "dont_allow">;
|
|
10
10
|
} & Record<string, unknown>;
|
|
@@ -68,7 +68,7 @@ const fromRequest = Effect.fn("GoogleVideo.fromRequest")(function* (request) {
|
|
|
68
68
|
},
|
|
69
69
|
],
|
|
70
70
|
parameters: mergeJsonRecords({
|
|
71
|
-
aspectRatio: request.
|
|
71
|
+
aspectRatio: request.aspect,
|
|
72
72
|
resolution: request.resolution,
|
|
73
73
|
durationSeconds: request.durationSeconds,
|
|
74
74
|
negativePrompt: request.negativePrompt,
|
|
@@ -109,22 +109,17 @@ const decodeResult = Effect.fn("GoogleVideo.decodeResult")(function* (response,
|
|
|
109
109
|
headers: context.auth,
|
|
110
110
|
}));
|
|
111
111
|
const reasons = generated?.raiMediaFilteredReasons ?? [];
|
|
112
|
-
const notices = reasons.map((reason) => ({
|
|
113
|
-
type: "filtered",
|
|
114
|
-
message: `${route.name} filtered media: ${reason}`,
|
|
115
|
-
providerMetadata: { google: { raiMediaFilteredReason: reason } },
|
|
116
|
-
}));
|
|
117
112
|
if (videos.length === 0 && (reasons.length > 0 || (generated?.raiMediaFilteredCount ?? 0) > 0))
|
|
118
113
|
return yield* output.contentPolicy(`${route.name} filtered every video${reasons.length === 0 ? "" : `: ${reasons.join("; ")}`}`);
|
|
119
114
|
if (videos.length === 0)
|
|
120
115
|
return yield* output.invalid(`${route.name} operation completed without any video`);
|
|
121
116
|
return new VideoResponse({
|
|
122
117
|
videos,
|
|
123
|
-
notices: notices.length === 0 ? undefined : notices,
|
|
124
118
|
providerMetadata: {
|
|
125
119
|
google: {
|
|
126
120
|
operation: context.token.operation,
|
|
127
121
|
raiMediaFilteredCount: generated?.raiMediaFilteredCount,
|
|
122
|
+
raiMediaFilteredReasons: generated?.raiMediaFilteredReasons,
|
|
128
123
|
metadata: operation.metadata,
|
|
129
124
|
},
|
|
130
125
|
},
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export * as AnthropicMessages from "./anthropic-messages.js";
|
|
2
2
|
export * as BedrockConverse from "./bedrock-converse.js";
|
|
3
|
+
export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
|
|
3
4
|
export * as CohereChat from "./cohere-chat.js";
|
|
4
5
|
export * as Gemini from "./gemini.js";
|
|
5
6
|
export * as GoogleInteractions from "./google-interactions.js";
|
|
6
7
|
export * as MistralChat from "./mistral-chat.js";
|
|
7
8
|
export * as OpenAIChat from "./openai-chat.js";
|
|
9
|
+
export * as OpenAIDecisions from "./openai-decisions.js";
|
|
8
10
|
export * as OpenAIImages from "./openai-images.js";
|
|
9
11
|
export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
|
|
10
12
|
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
|
|
11
13
|
export * as OpenAIResponses from "./openai-responses.js";
|
|
12
14
|
export * as OpenResponses from "./open-responses.js";
|
|
13
15
|
export * as OpenResponsesChannel from "./open-responses-channel.js";
|
|
16
|
+
export * as SystemOne from "./system-one.js";
|
|
14
17
|
export * as XAIResponses from "./xai-responses.js";
|
package/dist/protocols/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export * as AnthropicMessages from "./anthropic-messages.js";
|
|
2
2
|
export * as BedrockConverse from "./bedrock-converse.js";
|
|
3
|
+
export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
|
|
3
4
|
export * as CohereChat from "./cohere-chat.js";
|
|
4
5
|
export * as Gemini from "./gemini.js";
|
|
5
6
|
export * as GoogleInteractions from "./google-interactions.js";
|
|
6
7
|
export * as MistralChat from "./mistral-chat.js";
|
|
7
8
|
export * as OpenAIChat from "./openai-chat.js";
|
|
9
|
+
export * as OpenAIDecisions from "./openai-decisions.js";
|
|
8
10
|
export * as OpenAIImages from "./openai-images.js";
|
|
9
11
|
export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
|
|
10
12
|
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
|
|
11
13
|
export * as OpenAIResponses from "./openai-responses.js";
|
|
12
14
|
export * as OpenResponses from "./open-responses.js";
|
|
13
15
|
export * as OpenResponsesChannel from "./open-responses-channel.js";
|
|
16
|
+
export * as SystemOne from "./system-one.js";
|
|
14
17
|
export * as XAIResponses from "./xai-responses.js";
|
|
@@ -3,8 +3,14 @@ import { MediaProtocol } from "../route/media-protocol.js";
|
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
5
5
|
export declare const DEFAULT_BASE_URL = "https://api.meta.ai/v1";
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Provider-native options. Common fields (`n`, `aspect`, `images`) live on the request; Meta picks its own output
|
|
8
|
+
* resolution (about 2.5 megapixels), so `resolution` is ignored.
|
|
9
|
+
*/
|
|
7
10
|
export type ImageOptions = {
|
|
11
|
+
/** `WIDTHxHEIGHT` aspect ratio hint; it replaces `aspect`, so setting both fails. */
|
|
12
|
+
readonly size?: string;
|
|
13
|
+
readonly outputFormat?: OpenString<"webp" | "png" | "jpeg">;
|
|
8
14
|
readonly responseFormat?: OpenString<"b64_json" | "url">;
|
|
9
15
|
readonly reasoningStrength?: OpenString<"low" | "high">;
|
|
10
16
|
readonly toolEnablement?: {
|
|
@@ -3,8 +3,9 @@ import { ImageModel, ImageResponse } from "../image.js";
|
|
|
3
3
|
import { Media } from "../media.js";
|
|
4
4
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
5
|
import { MediaRoute } from "../route/media.js";
|
|
6
|
-
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { mergeJsonRecords, tokenUsage } from "../schema/index.js";
|
|
7
7
|
import { JsonObject, ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
import { ImageSizing } from "./utils/image-sizing.js";
|
|
8
9
|
import { MediaInput } from "./utils/media-input.js";
|
|
9
10
|
const route = MediaProtocol.identity({ id: "meta-images", name: "Meta Images", provider: "meta" });
|
|
10
11
|
export const DEFAULT_BASE_URL = "https://api.meta.ai/v1";
|
|
@@ -40,14 +41,17 @@ const isEdit = (request) => (request.images?.length ?? 0) > 0;
|
|
|
40
41
|
const reference = (asset) => ProviderShared.mediaReference(asset, undefined, route.name).pipe(Effect.map((item) => ({ image_url: item.value })));
|
|
41
42
|
const fromRequest = Effect.fn("MetaImages.fromRequest")(function* (request) {
|
|
42
43
|
const images = yield* Effect.forEach(request.images ?? [], reference);
|
|
43
|
-
const { responseFormat, reasoningStrength, toolEnablement, ...native } = request.providerOptions ?? {};
|
|
44
|
+
const { outputFormat, responseFormat, reasoningStrength, toolEnablement, ...native } = request.providerOptions ?? {};
|
|
45
|
+
if (native.size !== undefined && request.aspect !== undefined)
|
|
46
|
+
return yield* ProviderShared.invalidRequest("Meta providerOptions.size replaces aspect; set one or the other");
|
|
47
|
+
const hint = request.aspect === undefined ? undefined : ImageSizing.fit({ aspect: request.aspect }, { multiple: 16 });
|
|
44
48
|
const payload = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))(mergeJsonRecords({
|
|
45
49
|
model: request.model.id,
|
|
46
50
|
prompt: request.prompt,
|
|
47
51
|
images: images.length === 0 ? undefined : images,
|
|
48
52
|
n: request.n,
|
|
49
|
-
size:
|
|
50
|
-
output_format:
|
|
53
|
+
size: hint === undefined ? undefined : `${hint.width}x${hint.height}`,
|
|
54
|
+
output_format: outputFormat,
|
|
51
55
|
response_format: responseFormat,
|
|
52
56
|
reasoning_strength: reasoningStrength,
|
|
53
57
|
tool_enablement: toolEnablement,
|
|
@@ -73,13 +77,12 @@ const decodeResponse = Effect.fn("MetaImages.decodeResponse")(function* (respons
|
|
|
73
77
|
images,
|
|
74
78
|
usage: decoded.usage === undefined
|
|
75
79
|
? undefined
|
|
76
|
-
: {
|
|
77
|
-
type: "tokens",
|
|
80
|
+
: tokenUsage({
|
|
78
81
|
input: decoded.usage.input_tokens,
|
|
79
82
|
output: decoded.usage.output_tokens,
|
|
80
83
|
total: decoded.usage.total_tokens,
|
|
81
84
|
details: { meta: decoded.usage },
|
|
82
|
-
},
|
|
85
|
+
}),
|
|
83
86
|
providerMetadata: { meta: { outputFormat: format } },
|
|
84
87
|
});
|
|
85
88
|
});
|
|
@@ -87,7 +90,6 @@ const decodeResponse = Effect.fn("MetaImages.decodeResponse")(function* (respons
|
|
|
87
90
|
// 7. Protocol and route
|
|
88
91
|
// ---------------------------------------------------------------------------
|
|
89
92
|
export const protocol = MediaProtocol.inline(route, {
|
|
90
|
-
unsupported: ["mask", "aspectRatio", "seed"],
|
|
91
93
|
body: { from: fromRequest },
|
|
92
94
|
response: { decode: decodeResponse },
|
|
93
95
|
});
|
|
@@ -17,7 +17,7 @@ export declare const protocol: Protocol<{
|
|
|
17
17
|
readonly text: string;
|
|
18
18
|
readonly cache_control?: {
|
|
19
19
|
readonly type: "ephemeral";
|
|
20
|
-
readonly ttl?:
|
|
20
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
21
21
|
} | undefined;
|
|
22
22
|
}[] | undefined;
|
|
23
23
|
readonly messages: readonly ({
|
|
@@ -27,7 +27,7 @@ export declare const protocol: Protocol<{
|
|
|
27
27
|
readonly text: string;
|
|
28
28
|
readonly cache_control?: {
|
|
29
29
|
readonly type: "ephemeral";
|
|
30
|
-
readonly ttl?:
|
|
30
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
31
31
|
} | undefined;
|
|
32
32
|
} | {
|
|
33
33
|
readonly type: "image";
|
|
@@ -44,11 +44,28 @@ export declare const protocol: Protocol<{
|
|
|
44
44
|
};
|
|
45
45
|
readonly cache_control?: {
|
|
46
46
|
readonly type: "ephemeral";
|
|
47
|
-
readonly ttl?:
|
|
47
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
48
48
|
} | undefined;
|
|
49
49
|
readonly transformations?: {
|
|
50
50
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
51
51
|
} | undefined;
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "video";
|
|
54
|
+
readonly source: {
|
|
55
|
+
readonly type: "base64";
|
|
56
|
+
readonly media_type: string;
|
|
57
|
+
readonly data: string;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: "url";
|
|
60
|
+
readonly url: string;
|
|
61
|
+
} | {
|
|
62
|
+
readonly type: "file";
|
|
63
|
+
readonly file_id: string;
|
|
64
|
+
};
|
|
65
|
+
readonly cache_control?: {
|
|
66
|
+
readonly type: "ephemeral";
|
|
67
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
68
|
+
} | undefined;
|
|
52
69
|
} | {
|
|
53
70
|
readonly type: "document";
|
|
54
71
|
readonly source: {
|
|
@@ -68,7 +85,7 @@ export declare const protocol: Protocol<{
|
|
|
68
85
|
};
|
|
69
86
|
readonly cache_control?: {
|
|
70
87
|
readonly type: "ephemeral";
|
|
71
|
-
readonly ttl?:
|
|
88
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
72
89
|
} | undefined;
|
|
73
90
|
readonly title?: string | undefined;
|
|
74
91
|
readonly context?: string | undefined;
|
|
@@ -83,7 +100,7 @@ export declare const protocol: Protocol<{
|
|
|
83
100
|
readonly text: string;
|
|
84
101
|
readonly cache_control?: {
|
|
85
102
|
readonly type: "ephemeral";
|
|
86
|
-
readonly ttl?:
|
|
103
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
87
104
|
} | undefined;
|
|
88
105
|
} | {
|
|
89
106
|
readonly type: "image";
|
|
@@ -100,11 +117,28 @@ export declare const protocol: Protocol<{
|
|
|
100
117
|
};
|
|
101
118
|
readonly cache_control?: {
|
|
102
119
|
readonly type: "ephemeral";
|
|
103
|
-
readonly ttl?:
|
|
120
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
104
121
|
} | undefined;
|
|
105
122
|
readonly transformations?: {
|
|
106
123
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
107
124
|
} | undefined;
|
|
125
|
+
} | {
|
|
126
|
+
readonly type: "video";
|
|
127
|
+
readonly source: {
|
|
128
|
+
readonly type: "base64";
|
|
129
|
+
readonly media_type: string;
|
|
130
|
+
readonly data: string;
|
|
131
|
+
} | {
|
|
132
|
+
readonly type: "url";
|
|
133
|
+
readonly url: string;
|
|
134
|
+
} | {
|
|
135
|
+
readonly type: "file";
|
|
136
|
+
readonly file_id: string;
|
|
137
|
+
};
|
|
138
|
+
readonly cache_control?: {
|
|
139
|
+
readonly type: "ephemeral";
|
|
140
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
141
|
+
} | undefined;
|
|
108
142
|
} | {
|
|
109
143
|
readonly type: "document";
|
|
110
144
|
readonly source: {
|
|
@@ -124,7 +158,7 @@ export declare const protocol: Protocol<{
|
|
|
124
158
|
};
|
|
125
159
|
readonly cache_control?: {
|
|
126
160
|
readonly type: "ephemeral";
|
|
127
|
-
readonly ttl?:
|
|
161
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
128
162
|
} | undefined;
|
|
129
163
|
readonly title?: string | undefined;
|
|
130
164
|
readonly context?: string | undefined;
|
|
@@ -135,7 +169,7 @@ export declare const protocol: Protocol<{
|
|
|
135
169
|
readonly is_error?: boolean | undefined;
|
|
136
170
|
readonly cache_control?: {
|
|
137
171
|
readonly type: "ephemeral";
|
|
138
|
-
readonly ttl?:
|
|
172
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
139
173
|
} | undefined;
|
|
140
174
|
})[];
|
|
141
175
|
} | {
|
|
@@ -148,7 +182,7 @@ export declare const protocol: Protocol<{
|
|
|
148
182
|
readonly text: string;
|
|
149
183
|
readonly cache_control?: {
|
|
150
184
|
readonly type: "ephemeral";
|
|
151
|
-
readonly ttl?:
|
|
185
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
152
186
|
} | undefined;
|
|
153
187
|
} | {
|
|
154
188
|
readonly type: "thinking";
|
|
@@ -156,14 +190,14 @@ export declare const protocol: Protocol<{
|
|
|
156
190
|
readonly signature: string;
|
|
157
191
|
readonly cache_control?: {
|
|
158
192
|
readonly type: "ephemeral";
|
|
159
|
-
readonly ttl?:
|
|
193
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
160
194
|
} | undefined;
|
|
161
195
|
} | {
|
|
162
196
|
readonly type: "redacted_thinking";
|
|
163
197
|
readonly data: string;
|
|
164
198
|
readonly cache_control?: {
|
|
165
199
|
readonly type: "ephemeral";
|
|
166
|
-
readonly ttl?:
|
|
200
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
167
201
|
} | undefined;
|
|
168
202
|
} | {
|
|
169
203
|
readonly type: "tool_use";
|
|
@@ -172,7 +206,7 @@ export declare const protocol: Protocol<{
|
|
|
172
206
|
readonly input: unknown;
|
|
173
207
|
readonly cache_control?: {
|
|
174
208
|
readonly type: "ephemeral";
|
|
175
|
-
readonly ttl?:
|
|
209
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
176
210
|
} | undefined;
|
|
177
211
|
} | {
|
|
178
212
|
readonly type: "server_tool_use";
|
|
@@ -181,7 +215,7 @@ export declare const protocol: Protocol<{
|
|
|
181
215
|
readonly input: unknown;
|
|
182
216
|
readonly cache_control?: {
|
|
183
217
|
readonly type: "ephemeral";
|
|
184
|
-
readonly ttl?:
|
|
218
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
185
219
|
} | undefined;
|
|
186
220
|
} | {
|
|
187
221
|
readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
|
|
@@ -189,7 +223,7 @@ export declare const protocol: Protocol<{
|
|
|
189
223
|
readonly content: unknown;
|
|
190
224
|
readonly cache_control?: {
|
|
191
225
|
readonly type: "ephemeral";
|
|
192
|
-
readonly ttl?:
|
|
226
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
193
227
|
} | undefined;
|
|
194
228
|
})[];
|
|
195
229
|
} | {
|
|
@@ -199,7 +233,7 @@ export declare const protocol: Protocol<{
|
|
|
199
233
|
readonly text: string;
|
|
200
234
|
readonly cache_control?: {
|
|
201
235
|
readonly type: "ephemeral";
|
|
202
|
-
readonly ttl?:
|
|
236
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
203
237
|
} | undefined;
|
|
204
238
|
}[];
|
|
205
239
|
readonly output_config?: {
|
|
@@ -247,7 +281,7 @@ export declare const protocol: Protocol<{
|
|
|
247
281
|
} | undefined;
|
|
248
282
|
readonly cache_control?: {
|
|
249
283
|
readonly type: "ephemeral";
|
|
250
|
-
readonly ttl?:
|
|
284
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
251
285
|
} | undefined;
|
|
252
286
|
readonly container?: string | {
|
|
253
287
|
readonly id?: string | null | undefined;
|
|
@@ -260,6 +294,7 @@ export declare const protocol: Protocol<{
|
|
|
260
294
|
readonly user_id?: string | null | undefined;
|
|
261
295
|
} | undefined;
|
|
262
296
|
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
|
|
297
|
+
readonly speed?: import("../schema/options.js").OpenString<"fast" | "standard"> | undefined;
|
|
263
298
|
readonly tools?: readonly ({
|
|
264
299
|
readonly type: "web_search";
|
|
265
300
|
readonly name: "web_search";
|
|
@@ -278,7 +313,7 @@ export declare const protocol: Protocol<{
|
|
|
278
313
|
};
|
|
279
314
|
readonly cache_control?: {
|
|
280
315
|
readonly type: "ephemeral";
|
|
281
|
-
readonly ttl?:
|
|
316
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
282
317
|
} | undefined;
|
|
283
318
|
})[] | undefined;
|
|
284
319
|
}, string, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { Protocol } from "../route/protocol.js";
|
|
3
|
+
import { CacheTTL } from "../schema/index.js";
|
|
3
4
|
import { AnthropicMessages } from "./anthropic-messages.js";
|
|
4
5
|
import { MetaResponses } from "./meta-responses.js";
|
|
5
6
|
import { JsonObject, optionalArray, ProviderShared } from "./shared.js";
|
|
@@ -10,7 +11,7 @@ const WebSearch = Schema.Struct({
|
|
|
10
11
|
});
|
|
11
12
|
const MetaCacheControl = Schema.Struct({
|
|
12
13
|
type: Schema.tag("ephemeral"),
|
|
13
|
-
ttl: Schema.optional(
|
|
14
|
+
ttl: Schema.optional(CacheTTL),
|
|
14
15
|
});
|
|
15
16
|
const FunctionTool = Schema.Struct({
|
|
16
17
|
name: Schema.String,
|
|
@@ -27,6 +28,18 @@ const fromRequest = Effect.fn("MetaMessages.fromRequest")(function* (request) {
|
|
|
27
28
|
const body = yield* AnthropicMessages.protocol.body.from(projected.request);
|
|
28
29
|
return {
|
|
29
30
|
...body,
|
|
31
|
+
messages: body.messages.map((message) => {
|
|
32
|
+
if (message.role !== "user")
|
|
33
|
+
return message;
|
|
34
|
+
const videos = [];
|
|
35
|
+
const content = message.content.map((block) => {
|
|
36
|
+
if (block.type !== "tool_result" || typeof block.content === "string")
|
|
37
|
+
return block;
|
|
38
|
+
videos.push(...block.content.filter((item) => item.type === "video"));
|
|
39
|
+
return { ...block, content: block.content.filter((item) => item.type !== "video") };
|
|
40
|
+
});
|
|
41
|
+
return videos.length === 0 ? message : { ...message, content: [...content, ...videos] };
|
|
42
|
+
}),
|
|
30
43
|
tools: body.tools === undefined
|
|
31
44
|
? undefined
|
|
32
45
|
: yield* Effect.forEach(body.tools, (tool, index) => Effect.gen(function* () {
|
|
@@ -77,6 +77,9 @@ export declare const protocol: Protocol<{
|
|
|
77
77
|
readonly content: readonly ({
|
|
78
78
|
readonly type: "input_text";
|
|
79
79
|
readonly text: string;
|
|
80
|
+
} | {
|
|
81
|
+
readonly type: "input_video";
|
|
82
|
+
readonly video_url: string;
|
|
80
83
|
} | {
|
|
81
84
|
readonly type: "input_image";
|
|
82
85
|
readonly image_url: string;
|
|
@@ -313,6 +316,9 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
|
|
|
313
316
|
readonly content: readonly ({
|
|
314
317
|
readonly type: "input_text";
|
|
315
318
|
readonly text: string;
|
|
319
|
+
} | {
|
|
320
|
+
readonly type: "input_video";
|
|
321
|
+
readonly video_url: string;
|
|
316
322
|
} | {
|
|
317
323
|
readonly type: "input_image";
|
|
318
324
|
readonly image_url: string;
|
|
@@ -48,7 +48,7 @@ const adapter = {
|
|
|
48
48
|
};
|
|
49
49
|
const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
50
50
|
const key = request.model.route.providerMetadataKey ?? String(request.model.provider);
|
|
51
|
-
|
|
51
|
+
const body = yield* OpenResponses.fromRequestWithAdapter(LLMRequest.update(request, {
|
|
52
52
|
messages: request.messages.map((message) => Message.make({
|
|
53
53
|
...message,
|
|
54
54
|
content: message.content.map((part) => {
|
|
@@ -69,7 +69,35 @@ const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
|
69
69
|
}),
|
|
70
70
|
})),
|
|
71
71
|
}), adapter);
|
|
72
|
+
// Meta cannot see video nested in tool results; attach it after the complete result batch.
|
|
73
|
+
const input = [];
|
|
74
|
+
const videos = [];
|
|
75
|
+
const flushVideos = () => {
|
|
76
|
+
if (videos.length > 0)
|
|
77
|
+
input.push({ type: "message", role: "user", content: videos.splice(0) });
|
|
78
|
+
};
|
|
79
|
+
for (const item of body.input) {
|
|
80
|
+
if (!isFunctionCallOutput(item)) {
|
|
81
|
+
flushVideos();
|
|
82
|
+
input.push(item);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (typeof item.output === "string") {
|
|
86
|
+
input.push(item);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const content = item.output.filter((part) => part.type !== "input_video");
|
|
90
|
+
videos.push(...item.output.filter((part) => part.type === "input_video"));
|
|
91
|
+
input.push({
|
|
92
|
+
...item,
|
|
93
|
+
output: content.length === 0 && item.output.length > 0 ? "Video attached in the following user message." : content,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
flushVideos();
|
|
97
|
+
return { ...body, input };
|
|
72
98
|
});
|
|
99
|
+
// Hosted replay items have an open `type`, so a plain tag check does not narrow the union.
|
|
100
|
+
const isFunctionCallOutput = (item) => item.type === "function_call_output";
|
|
73
101
|
const HOSTED_TOOLS = {
|
|
74
102
|
web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
|
|
75
103
|
image_generation_call: {
|