@opencode/ai 2.2.5 → 2.2.6
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 +133 -69
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +20 -125
- package/dist/decision.js +25 -15
- package/dist/effect.d.ts +4 -15
- package/dist/effect.js +2 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -464
- package/dist/image.js +17 -15
- package/dist/index.d.ts +28 -465
- package/dist/index.js +18 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +5 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +54 -173
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +10 -16
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +54 -72
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +44 -30
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +7 -10
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/open-responses.js +10 -15
- package/dist/protocols/openai-chat.d.ts +3 -23
- package/dist/protocols/openai-chat.js +26 -47
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +1 -4
- package/dist/protocols/shared.js +13 -11
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +3 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +5 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +7 -80
- package/dist/providers/alibaba.d.ts +67 -4
- package/dist/providers/alibaba.js +6 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +322 -7
- package/dist/providers/azure.js +25 -9
- package/dist/providers/baseten.d.ts +5 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +5 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere.d.ts +6 -5
- package/dist/providers/cohere.js +7 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra.d.ts +5 -5
- package/dist/providers/deepinfra.js +5 -13
- package/dist/providers/deepseek.d.ts +5 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean.d.ts +8 -5
- package/dist/providers/digitalocean.js +13 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks.d.ts +5 -5
- package/dist/providers/fireworks.js +4 -15
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex-chat.d.ts +3 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +3 -3
- package/dist/providers/google.d.ts +15 -13
- package/dist/providers/google.js +9 -19
- package/dist/providers/groq.d.ts +5 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +5 -5
- package/dist/providers/meta.js +10 -23
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +5 -5
- package/dist/providers/minimax.js +7 -22
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +5 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +6 -7
- package/dist/providers/openai-compatible.js +4 -10
- package/dist/providers/openai.d.ts +4 -4
- package/dist/providers/openai.js +3 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter.d.ts +8 -5
- package/dist/providers/openrouter.js +16 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +5 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +4 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway.d.ts +5 -5
- package/dist/providers/vercel-ai-gateway.js +15 -28
- package/dist/providers/xai.d.ts +4 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +5 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +5 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +12 -0
- package/dist/public.js +5 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +9 -9
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
package/dist/protocols/gemini.js
CHANGED
|
@@ -157,6 +157,7 @@ const GeminiUsage = Schema.Struct({
|
|
|
157
157
|
cachedContentTokenCount: optionalNull(Schema.Number),
|
|
158
158
|
thoughtsTokenCount: optionalNull(Schema.Number),
|
|
159
159
|
promptTokenCount: optionalNull(Schema.Number),
|
|
160
|
+
toolUsePromptTokenCount: optionalNull(Schema.Number),
|
|
160
161
|
candidatesTokenCount: optionalNull(Schema.Number),
|
|
161
162
|
totalTokenCount: optionalNull(Schema.Number),
|
|
162
163
|
...ProviderShared.ReportedBilling.fields,
|
|
@@ -202,6 +203,7 @@ const lowerContentPart = Effect.fnUntraced(function* (part) {
|
|
|
202
203
|
return yield* GeminiGenerateContent.mediaPart("Gemini", part.media);
|
|
203
204
|
});
|
|
204
205
|
const providerMetadata = (key, metadata) => ({ [key]: metadata });
|
|
206
|
+
const signatureMetadata = (key, signature) => signature ? providerMetadata(key, { thoughtSignature: signature }) : undefined;
|
|
205
207
|
const thoughtSignature = (metadata, key) => {
|
|
206
208
|
const value = metadata?.[key];
|
|
207
209
|
return typeof value?.thoughtSignature === "string" ? value.thoughtSignature : undefined;
|
|
@@ -239,8 +241,6 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
|
239
241
|
if (message.role === "user") {
|
|
240
242
|
const parts = [];
|
|
241
243
|
for (const part of message.content) {
|
|
242
|
-
if (!ProviderShared.supportsContent(part, ["text", "media"]))
|
|
243
|
-
return yield* ProviderShared.unsupportedContent("Gemini", "user", ["text", "media"]);
|
|
244
244
|
parts.push(yield* lowerContentPart(part));
|
|
245
245
|
}
|
|
246
246
|
contents.push({ role: "user", parts });
|
|
@@ -293,8 +293,6 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
|
293
293
|
}
|
|
294
294
|
const parts = [];
|
|
295
295
|
for (const part of message.content) {
|
|
296
|
-
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
297
|
-
return yield* ProviderShared.unsupportedContent("Gemini", "tool", ["tool-result"]);
|
|
298
296
|
if (part.result.type !== "content") {
|
|
299
297
|
parts.push({
|
|
300
298
|
functionResponse: {
|
|
@@ -347,17 +345,16 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
|
347
345
|
const fromRequest = Effect.fn("Gemini.fromRequest")(function* (request) {
|
|
348
346
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
349
347
|
const hasTools = flattened.tools.length > 0;
|
|
350
|
-
const generation = request.generation;
|
|
351
348
|
const options = yield* decodeOptions(request.providerOptions ?? {});
|
|
352
349
|
const generationConfig = {
|
|
353
|
-
maxOutputTokens:
|
|
354
|
-
temperature:
|
|
355
|
-
topP:
|
|
356
|
-
topK:
|
|
357
|
-
frequencyPenalty:
|
|
358
|
-
presencePenalty:
|
|
359
|
-
seed:
|
|
360
|
-
stopSequences:
|
|
350
|
+
maxOutputTokens: request.maxTokens,
|
|
351
|
+
temperature: request.temperature,
|
|
352
|
+
topP: request.topP,
|
|
353
|
+
topK: request.topK,
|
|
354
|
+
frequencyPenalty: request.frequencyPenalty,
|
|
355
|
+
presencePenalty: request.presencePenalty,
|
|
356
|
+
seed: request.seed,
|
|
357
|
+
stopSequences: request.stop,
|
|
361
358
|
// Gemini accepts a budget above `maxOutputTokens`, but thinking then leaves the answer empty.
|
|
362
359
|
thinkingConfig: options.thinkingConfig === undefined
|
|
363
360
|
? undefined
|
|
@@ -366,7 +363,7 @@ const fromRequest = Effect.fn("Gemini.fromRequest")(function* (request) {
|
|
|
366
363
|
includeThoughts: options.thinkingConfig.includeThoughts ?? true,
|
|
367
364
|
thinkingBudget: options.thinkingConfig.thinkingBudget === undefined
|
|
368
365
|
? undefined
|
|
369
|
-
: ProviderShared.fitThinkingBudget(options.thinkingConfig.thinkingBudget,
|
|
366
|
+
: ProviderShared.fitThinkingBudget(options.thinkingConfig.thinkingBudget, request.maxTokens, MIN_THINKING_BUDGET),
|
|
370
367
|
},
|
|
371
368
|
};
|
|
372
369
|
return {
|
|
@@ -391,8 +388,8 @@ const fromRequest = Effect.fn("Gemini.fromRequest")(function* (request) {
|
|
|
391
388
|
// =============================================================================
|
|
392
389
|
// Stream Parsing
|
|
393
390
|
// =============================================================================
|
|
394
|
-
// Gemini reports `promptTokenCount`
|
|
395
|
-
// `
|
|
391
|
+
// Gemini reports `promptTokenCount` with a `cachedContentTokenCount` subset;
|
|
392
|
+
// `toolUsePromptTokenCount` is additional billed input. `candidatesTokenCount` is *exclusive*
|
|
396
393
|
// of `thoughtsTokenCount` — visible-only, not a total — so we sum the two
|
|
397
394
|
// to produce the inclusive `outputTokens` the rest of the contract expects.
|
|
398
395
|
const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
|
|
@@ -400,7 +397,7 @@ const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
|
|
|
400
397
|
return undefined;
|
|
401
398
|
// Explicit provider nulls decode as `null`; normalize to `undefined` so the
|
|
402
399
|
// token arithmetic below treats them like absent counts.
|
|
403
|
-
const promptTokens = usage.promptTokenCount ?? undefined;
|
|
400
|
+
const promptTokens = ProviderShared.sumTokens(usage.promptTokenCount ?? undefined, usage.toolUsePromptTokenCount ?? undefined);
|
|
404
401
|
const cached = usage.cachedContentTokenCount ?? undefined;
|
|
405
402
|
const thoughts = usage.thoughtsTokenCount ?? undefined;
|
|
406
403
|
const visible = usage.candidatesTokenCount ?? undefined;
|
|
@@ -421,13 +418,13 @@ const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
|
|
|
421
418
|
providerMetadata: providerMetadata(metadataKey, metadata),
|
|
422
419
|
});
|
|
423
420
|
};
|
|
424
|
-
//
|
|
425
|
-
//
|
|
426
|
-
// remain in provider metadata.
|
|
421
|
+
// Continued requests retain the first request's input instead of summing re-billed prompts.
|
|
422
|
+
// Complete billed counts, including tool-use prompts from later requests, remain in provider metadata.
|
|
427
423
|
const mapContinuedUsage = (requests, metadataKey) => {
|
|
428
424
|
const sum = (field) => ProviderShared.sumTokens(...requests.map((usage) => usage[field] ?? undefined));
|
|
429
425
|
return mapUsage({
|
|
430
426
|
promptTokenCount: requests[0].promptTokenCount,
|
|
427
|
+
toolUsePromptTokenCount: requests[0].toolUsePromptTokenCount,
|
|
431
428
|
cachedContentTokenCount: requests[0].cachedContentTokenCount,
|
|
432
429
|
candidatesTokenCount: sum("candidatesTokenCount"),
|
|
433
430
|
thoughtsTokenCount: sum("thoughtsTokenCount"),
|
|
@@ -435,6 +432,7 @@ const mapContinuedUsage = (requests, metadataKey) => {
|
|
|
435
432
|
cost: sum("cost"),
|
|
436
433
|
}, metadataKey, {
|
|
437
434
|
promptTokenCount: sum("promptTokenCount"),
|
|
435
|
+
toolUsePromptTokenCount: sum("toolUsePromptTokenCount"),
|
|
438
436
|
cachedContentTokenCount: sum("cachedContentTokenCount"),
|
|
439
437
|
candidatesTokenCount: sum("candidatesTokenCount"),
|
|
440
438
|
thoughtsTokenCount: sum("thoughtsTokenCount"),
|
|
@@ -442,6 +440,8 @@ const mapContinuedUsage = (requests, metadataKey) => {
|
|
|
442
440
|
requests: requests.length,
|
|
443
441
|
});
|
|
444
442
|
};
|
|
443
|
+
const terminalFinishReason = (finishReason) => finishReason && finishReason !== "FINISH_REASON_UNSPECIFIED" ? finishReason : undefined;
|
|
444
|
+
const RECOVERABLE_FINISH_REASONS = new Set(["MALFORMED_RESPONSE", "MALFORMED_FUNCTION_CALL", "UNEXPECTED_TOOL_CALL"]);
|
|
445
445
|
const mapFinishReason = (finishReason, hasToolCalls) => {
|
|
446
446
|
if (finishReason === undefined)
|
|
447
447
|
return hasToolCalls ? "tool-calls" : "unknown";
|
|
@@ -470,13 +470,9 @@ const finish = (state) => {
|
|
|
470
470
|
const events = [];
|
|
471
471
|
let lifecycle = state.lifecycle;
|
|
472
472
|
if (state.reasoningId !== undefined)
|
|
473
|
-
lifecycle = Lifecycle.reasoningEnd(lifecycle, events, state.reasoningId, state.reasoningSignature
|
|
474
|
-
? undefined
|
|
475
|
-
: providerMetadata(state.providerMetadataKey, { thoughtSignature: state.reasoningSignature }));
|
|
473
|
+
lifecycle = Lifecycle.reasoningEnd(lifecycle, events, state.reasoningId, signatureMetadata(state.providerMetadataKey, state.reasoningSignature));
|
|
476
474
|
if (state.textId !== undefined)
|
|
477
|
-
lifecycle = Lifecycle.textEnd(lifecycle, events, state.textId, state.textSignature
|
|
478
|
-
? undefined
|
|
479
|
-
: providerMetadata(state.providerMetadataKey, { thoughtSignature: state.textSignature }));
|
|
475
|
+
lifecycle = Lifecycle.textEnd(lifecycle, events, state.textId, signatureMetadata(state.providerMetadataKey, state.textSignature));
|
|
480
476
|
Lifecycle.finish(lifecycle, events, {
|
|
481
477
|
reason: {
|
|
482
478
|
normalized: promptBlockReason === undefined ? mapFinishReason(finishReason, state.hasToolCalls) : "content-filter",
|
|
@@ -515,24 +511,22 @@ const step = (state, event) => {
|
|
|
515
511
|
}));
|
|
516
512
|
}
|
|
517
513
|
const candidate = event.candidates?.[0];
|
|
514
|
+
const finishReason = terminalFinishReason(candidate?.finishReason);
|
|
518
515
|
const nextState = {
|
|
519
516
|
...state,
|
|
520
517
|
promptFeedback: event.promptFeedback ?? state.promptFeedback,
|
|
521
518
|
usage: event.usageMetadata ?? state.usage,
|
|
522
|
-
finishReason:
|
|
519
|
+
finishReason: finishReason ?? state.finishReason,
|
|
523
520
|
};
|
|
524
|
-
|
|
525
|
-
if (candidate?.finishReason === "MALFORMED_RESPONSE")
|
|
521
|
+
if (finishReason && mapFinishReason(finishReason, state.hasToolCalls) === "error")
|
|
526
522
|
return Effect.fail(new AIError({
|
|
527
523
|
reason: new InvalidProviderOutputError({
|
|
528
524
|
route: state.route,
|
|
529
|
-
message: `Gemini stopped with ${
|
|
525
|
+
message: `Gemini stopped with ${finishReason}`,
|
|
530
526
|
body: ProviderShared.encodeJson(event),
|
|
531
|
-
classification: "incomplete-stream",
|
|
527
|
+
classification: RECOVERABLE_FINISH_REASONS.has(finishReason) ? "incomplete-stream" : undefined,
|
|
532
528
|
}),
|
|
533
529
|
}));
|
|
534
|
-
if (candidate?.finishReason && mapFinishReason(candidate.finishReason, state.hasToolCalls) === "error")
|
|
535
|
-
return Effect.fail(ProviderShared.eventError(state.route, `Gemini stopped with ${candidate.finishReason}`, ProviderShared.encodeJson(event)));
|
|
536
530
|
if (!candidate?.content)
|
|
537
531
|
return Effect.succeed([nextState, []]);
|
|
538
532
|
const events = [];
|
|
@@ -546,6 +540,21 @@ const step = (state, event) => {
|
|
|
546
540
|
let nextTextId = nextState.nextTextId;
|
|
547
541
|
// Supplier ids must be tracked across chunks of the same response, not just within one event's parts.
|
|
548
542
|
const seenCallIds = new Set(nextState.seenCallIds);
|
|
543
|
+
const signed = (signature) => signatureMetadata(state.providerMetadataKey, signature);
|
|
544
|
+
const endReasoning = () => {
|
|
545
|
+
if (reasoningId === undefined)
|
|
546
|
+
return;
|
|
547
|
+
lifecycle = Lifecycle.reasoningEnd(lifecycle, events, reasoningId, signed(reasoningSignature));
|
|
548
|
+
reasoningId = undefined;
|
|
549
|
+
reasoningSignature = undefined;
|
|
550
|
+
};
|
|
551
|
+
const endText = () => {
|
|
552
|
+
if (textId === undefined)
|
|
553
|
+
return;
|
|
554
|
+
lifecycle = Lifecycle.textEnd(lifecycle, events, textId, signed(textSignature));
|
|
555
|
+
textId = undefined;
|
|
556
|
+
textSignature = undefined;
|
|
557
|
+
};
|
|
549
558
|
for (const input of candidate.content.parts ?? []) {
|
|
550
559
|
if (ProviderShared.isRecord(input) &&
|
|
551
560
|
!("text" in input) &&
|
|
@@ -569,40 +578,26 @@ const step = (state, event) => {
|
|
|
569
578
|
lifecycle = Lifecycle.stepStart(lifecycle, events);
|
|
570
579
|
events.push(LLMEvent.media({
|
|
571
580
|
media: Media.base64(part.inlineData.data, part.inlineData.mimeType),
|
|
572
|
-
providerMetadata: signature
|
|
573
|
-
? providerMetadata(state.providerMetadataKey, { thoughtSignature: signature })
|
|
574
|
-
: undefined,
|
|
581
|
+
providerMetadata: signed(signature),
|
|
575
582
|
}));
|
|
576
583
|
continue;
|
|
577
584
|
}
|
|
578
585
|
if ("text" in part && part.text.length > 0) {
|
|
579
586
|
if (part.thought) {
|
|
580
|
-
|
|
581
|
-
lifecycle = Lifecycle.textEnd(lifecycle, events, textId, textSignature
|
|
582
|
-
? providerMetadata(state.providerMetadataKey, { thoughtSignature: textSignature })
|
|
583
|
-
: undefined);
|
|
584
|
-
textId = undefined;
|
|
585
|
-
textSignature = undefined;
|
|
586
|
-
}
|
|
587
|
+
endText();
|
|
587
588
|
if (reasoningId === undefined) {
|
|
588
589
|
reasoningId = `reasoning-${nextReasoningId}`;
|
|
589
590
|
nextReasoningId += 1;
|
|
590
591
|
}
|
|
591
|
-
lifecycle = Lifecycle.reasoningDelta(lifecycle, events, reasoningId, part.text,
|
|
592
|
+
lifecycle = Lifecycle.reasoningDelta(lifecycle, events, reasoningId, part.text, signed(signature));
|
|
592
593
|
continue;
|
|
593
594
|
}
|
|
594
|
-
|
|
595
|
-
lifecycle = Lifecycle.reasoningEnd(lifecycle, events, reasoningId, reasoningSignature
|
|
596
|
-
? providerMetadata(state.providerMetadataKey, { thoughtSignature: reasoningSignature })
|
|
597
|
-
: undefined);
|
|
598
|
-
reasoningId = undefined;
|
|
599
|
-
reasoningSignature = undefined;
|
|
600
|
-
}
|
|
595
|
+
endReasoning();
|
|
601
596
|
if (textId === undefined) {
|
|
602
597
|
textId = `text-${nextTextId}`;
|
|
603
598
|
nextTextId += 1;
|
|
604
599
|
}
|
|
605
|
-
lifecycle = Lifecycle.textDelta(lifecycle, events, textId, part.text,
|
|
600
|
+
lifecycle = Lifecycle.textDelta(lifecycle, events, textId, part.text, signed(textSignature));
|
|
606
601
|
textSignature = undefined;
|
|
607
602
|
continue;
|
|
608
603
|
}
|
|
@@ -617,26 +612,14 @@ const step = (state, event) => {
|
|
|
617
612
|
if (supplied !== undefined)
|
|
618
613
|
seenCallIds.add(supplied);
|
|
619
614
|
const id = supplied !== undefined && !duplicate ? supplied : `tool_${crypto.randomUUID().replaceAll("-", "")}`;
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
? providerMetadata(state.providerMetadataKey, { thoughtSignature: reasoningSignature })
|
|
623
|
-
: undefined);
|
|
624
|
-
reasoningId = undefined;
|
|
625
|
-
reasoningSignature = undefined;
|
|
626
|
-
}
|
|
627
|
-
if (textId !== undefined) {
|
|
628
|
-
lifecycle = Lifecycle.textEnd(lifecycle, events, textId, textSignature ? providerMetadata(state.providerMetadataKey, { thoughtSignature: textSignature }) : undefined);
|
|
629
|
-
textId = undefined;
|
|
630
|
-
textSignature = undefined;
|
|
631
|
-
}
|
|
615
|
+
endReasoning();
|
|
616
|
+
endText();
|
|
632
617
|
lifecycle = Lifecycle.stepStart(lifecycle, events);
|
|
633
618
|
events.push(LLMEvent.toolCall({
|
|
634
619
|
id,
|
|
635
620
|
name: part.functionCall.name,
|
|
636
621
|
input,
|
|
637
|
-
providerMetadata:
|
|
638
|
-
? providerMetadata(state.providerMetadataKey, { thoughtSignature: part.thoughtSignature })
|
|
639
|
-
: undefined,
|
|
622
|
+
providerMetadata: signed(signature),
|
|
640
623
|
}));
|
|
641
624
|
hasToolCalls = true;
|
|
642
625
|
}
|
|
@@ -692,8 +675,9 @@ export const transport = {
|
|
|
692
675
|
if (typeof event === "object" && event !== null)
|
|
693
676
|
raw.set(event, frame);
|
|
694
677
|
const candidate = Option.getOrUndefined(decodeCheckpoint(event))?.candidates?.[0];
|
|
695
|
-
|
|
696
|
-
|
|
678
|
+
const candidateFinishReason = terminalFinishReason(candidate?.finishReason);
|
|
679
|
+
token = candidate?.continuationToken ?? (candidateFinishReason ? undefined : token);
|
|
680
|
+
finishReason = candidateFinishReason ?? finishReason;
|
|
697
681
|
return event;
|
|
698
682
|
}))), Stream.catchIf(
|
|
699
683
|
// A connection failure may resume; a timeout keeps its meaning and ends the response.
|
|
@@ -710,9 +694,7 @@ export const transport = {
|
|
|
710
694
|
return Stream.empty;
|
|
711
695
|
})));
|
|
712
696
|
});
|
|
713
|
-
const next = (continuationToken) => Stream.unwrap(sse
|
|
714
|
-
.prepare({ ...prepared.input, body: { ...prepared.input.body, continuationToken } })
|
|
715
|
-
.pipe(Effect.flatMap((continued) => sse.execute(continued, request, runtime)), Effect.map(respond)));
|
|
697
|
+
const next = (continuationToken) => Stream.unwrap(sse.prepare({ ...prepared.input, body: { ...prepared.input.body, continuationToken } }).pipe(Effect.flatMap((continued) => sse.execute(continued, request, runtime)), Effect.map(respond)));
|
|
716
698
|
const first = yield* sse.execute(prepared.http, request, runtime);
|
|
717
699
|
return {
|
|
718
700
|
frames: respond(first),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
@@ -9,7 +9,7 @@ export type GoogleImageOptions = {
|
|
|
9
9
|
readonly thinkingLevel?: OpenString<"MINIMAL" | "LOW" | "MEDIUM" | "HIGH">;
|
|
10
10
|
readonly includeThoughts?: boolean;
|
|
11
11
|
} & Record<string, unknown>;
|
|
12
|
-
export type Request =
|
|
12
|
+
export type Request = ImageRequest<ImageModel<GoogleImageOptions>>;
|
|
13
13
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
14
14
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<GoogleImageOptions>;
|
|
15
15
|
export declare const GoogleImages: {
|
|
@@ -35,7 +35,6 @@ interface ParserState {
|
|
|
35
35
|
readonly lifecycle: Lifecycle.State;
|
|
36
36
|
readonly steps: Partial<Record<number, OutputStep>>;
|
|
37
37
|
readonly tools: ToolStream.State<number>;
|
|
38
|
-
readonly completed: boolean;
|
|
39
38
|
}
|
|
40
39
|
export declare const protocol: Protocol<{
|
|
41
40
|
readonly model: string;
|
|
@@ -170,13 +169,13 @@ export declare const protocol: Protocol<{
|
|
|
170
169
|
readonly message?: string | undefined;
|
|
171
170
|
}[] | undefined;
|
|
172
171
|
};
|
|
173
|
-
} | {
|
|
174
|
-
readonly event_type: "error";
|
|
175
|
-
readonly error: unknown;
|
|
176
172
|
} | {
|
|
177
173
|
readonly event_type: "interaction.status_update";
|
|
178
174
|
readonly interaction_id?: string | undefined;
|
|
179
175
|
readonly status: string;
|
|
176
|
+
} | {
|
|
177
|
+
readonly event_type: "error";
|
|
178
|
+
readonly error?: unknown;
|
|
180
179
|
}, ParserState>;
|
|
181
180
|
export declare const route: Route<{
|
|
182
181
|
readonly model: string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Effect, Schema, SchemaGetter } from "effect";
|
|
1
|
+
import { Effect, Option, Schema, SchemaGetter } from "effect";
|
|
2
2
|
import { Route } from "../route/client.js";
|
|
3
3
|
import { Auth } from "../route/auth.js";
|
|
4
4
|
import { Endpoint } from "../route/endpoint.js";
|
|
5
5
|
import { Framing } from "../route/framing.js";
|
|
6
6
|
import { Protocol } from "../route/protocol.js";
|
|
7
|
-
import { AIError, LLMEvent, ProviderID, Usage, } from "../schema/index.js";
|
|
7
|
+
import { AIError, ContentPolicyError, InvalidProviderOutputError, LLMEvent, ProviderID, Usage, } from "../schema/index.js";
|
|
8
8
|
import { Media } from "../media.js";
|
|
9
9
|
import { classifyProviderFailure, providerErrorMessage } from "../provider-error.js";
|
|
10
10
|
import { encodeJson } from "../utils/json.js";
|
|
@@ -147,6 +147,11 @@ const UnknownEvent = Schema.Struct({
|
|
|
147
147
|
decode: SchemaGetter.transform(() => ({ event_type: "unknown" })),
|
|
148
148
|
encode: SchemaGetter.forbidden(() => "Unknown Google Interactions stream events are decode-only"),
|
|
149
149
|
}));
|
|
150
|
+
const ErrorDetail = Schema.StructWithRest(Schema.Struct({
|
|
151
|
+
code: lenient(Schema.String),
|
|
152
|
+
error_type: lenient(Schema.String),
|
|
153
|
+
message: lenient(Schema.String),
|
|
154
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
150
155
|
const Event = Schema.Union([
|
|
151
156
|
Schema.Struct({ event_type: Schema.Literal("step.start"), index: Schema.Number, step: OutputStep }),
|
|
152
157
|
Schema.Struct({ event_type: Schema.Literal("step.delta"), index: Schema.Number, delta: Delta }),
|
|
@@ -161,7 +166,7 @@ const Event = Schema.Union([
|
|
|
161
166
|
status: Schema.String,
|
|
162
167
|
}),
|
|
163
168
|
Schema.Struct({ event_type: Schema.Literal("interaction.completed"), interaction: Interaction }),
|
|
164
|
-
Schema.Struct({ event_type: Schema.Literal("error"), error: Schema.Unknown }),
|
|
169
|
+
Schema.Struct({ event_type: Schema.Literal("error"), error: Schema.optionalKey(Schema.Unknown) }),
|
|
165
170
|
UnknownEvent,
|
|
166
171
|
]);
|
|
167
172
|
// =============================================================================
|
|
@@ -273,9 +278,7 @@ const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (reque
|
|
|
273
278
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
274
279
|
if (flattened.tools.some((tool) => tool.native !== undefined))
|
|
275
280
|
return yield* ProviderShared.invalidRequest("Google Interactions hosted tools are not supported");
|
|
276
|
-
if (request.
|
|
277
|
-
request.generation?.frequencyPenalty !== undefined ||
|
|
278
|
-
request.generation?.presencePenalty !== undefined)
|
|
281
|
+
if (request.topK !== undefined || request.frequencyPenalty !== undefined || request.presencePenalty !== undefined)
|
|
279
282
|
return yield* ProviderShared.invalidRequest("Google Interactions does not support topK, frequencyPenalty, or presencePenalty");
|
|
280
283
|
const choice = request.toolChoice === undefined
|
|
281
284
|
? undefined
|
|
@@ -303,11 +306,11 @@ const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (reque
|
|
|
303
306
|
}))
|
|
304
307
|
: undefined,
|
|
305
308
|
generation_config: {
|
|
306
|
-
max_output_tokens: request.
|
|
307
|
-
temperature: request.
|
|
308
|
-
top_p: request.
|
|
309
|
-
seed: request.
|
|
310
|
-
stop_sequences: request.
|
|
309
|
+
max_output_tokens: request.maxTokens,
|
|
310
|
+
temperature: request.temperature,
|
|
311
|
+
top_p: request.topP,
|
|
312
|
+
seed: request.seed,
|
|
313
|
+
stop_sequences: request.stop,
|
|
311
314
|
thinking_level: options.thinkingLevel,
|
|
312
315
|
thinking_summaries: options.thinkingSummaries,
|
|
313
316
|
tool_choice: choice,
|
|
@@ -427,6 +430,23 @@ const onStop = Effect.fnUntraced(function* (state, index) {
|
|
|
427
430
|
const result = yield* ToolStream.finish(ADAPTER, state.tools, index);
|
|
428
431
|
return [{ ...state, tools: result.tools }, result.events ?? []];
|
|
429
432
|
});
|
|
433
|
+
const RECOVERABLE_CODES = new Set([
|
|
434
|
+
"MALFORMED_FUNCTION_CALL",
|
|
435
|
+
"MALFORMED_TOOL_CALL",
|
|
436
|
+
"UNEXPECTED_TOOL_CALL",
|
|
437
|
+
"MALFORMED_RESPONSE",
|
|
438
|
+
]);
|
|
439
|
+
const INVALID_OUTPUT_CODES = new Set(["MISSING_THOUGHT_SIGNATURE", "TOO_MANY_TOOL_CALLS", "NO_IMAGE"]);
|
|
440
|
+
const failureReason = (route, code, message, data, rawBody) => {
|
|
441
|
+
const normalized = code?.trim().toUpperCase().replaceAll("-", "_");
|
|
442
|
+
if (normalized && RECOVERABLE_CODES.has(normalized))
|
|
443
|
+
return new InvalidProviderOutputError({ route, message, body: rawBody, classification: "incomplete-stream" });
|
|
444
|
+
if (normalized && INVALID_OUTPUT_CODES.has(normalized))
|
|
445
|
+
return new InvalidProviderOutputError({ route, message, body: rawBody });
|
|
446
|
+
if (normalized && (normalized === "CONTENT_BLOCKED" || GeminiGenerateContent.contentFiltered(normalized)))
|
|
447
|
+
return new ContentPolicyError({ message, body: rawBody });
|
|
448
|
+
return classifyProviderFailure({ message, data, rawBody });
|
|
449
|
+
};
|
|
430
450
|
const step = Effect.fnUntraced(function* (state, event) {
|
|
431
451
|
switch (event.event_type) {
|
|
432
452
|
case "step.start":
|
|
@@ -439,34 +459,32 @@ const step = Effect.fnUntraced(function* (state, event) {
|
|
|
439
459
|
case "interaction.status_update":
|
|
440
460
|
case "unknown":
|
|
441
461
|
return [state, []];
|
|
442
|
-
case "error":
|
|
462
|
+
case "error": {
|
|
463
|
+
const rawBody = encodeJson(event);
|
|
464
|
+
const detail = Option.getOrUndefined(Schema.decodeUnknownOption(ErrorDetail)(event.error));
|
|
443
465
|
return yield* new AIError({
|
|
444
|
-
reason:
|
|
445
|
-
message: providerErrorMessage(encodeJson(event)) ?? "Google Interactions stream error",
|
|
446
|
-
data: event.error,
|
|
447
|
-
rawBody: encodeJson(event),
|
|
448
|
-
}),
|
|
466
|
+
reason: failureReason(state.route, detail?.code ?? detail?.error_type, detail?.message?.trim() || providerErrorMessage(rawBody) || "Google Interactions stream error", event.error, rawBody),
|
|
449
467
|
});
|
|
468
|
+
}
|
|
450
469
|
case "interaction.completed": {
|
|
451
470
|
const interaction = event.interaction;
|
|
452
471
|
if (interaction.status === "failed" || interaction.status === "cancelled") {
|
|
453
472
|
const messages = (interaction.errors ?? []).flatMap((error) => (error.message?.trim() ? [error.message] : []));
|
|
473
|
+
const coded = interaction.errors?.find((error) => error.code);
|
|
454
474
|
return yield* new AIError({
|
|
455
|
-
reason:
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
data: interaction.errors?.find((error) => error.code) ?? interaction,
|
|
459
|
-
rawBody: encodeJson(event),
|
|
460
|
-
}),
|
|
475
|
+
reason: failureReason(state.route, coded?.code, messages.length > 0 ? messages.join("\n") : `Google Interactions ${interaction.status}`,
|
|
476
|
+
// The first coded error decides the classification; every message stays visible.
|
|
477
|
+
coded ?? interaction, encodeJson(event)),
|
|
461
478
|
});
|
|
462
479
|
}
|
|
463
480
|
if (!["completed", "requires_action", "incomplete"].includes(interaction.status))
|
|
464
481
|
return yield* ProviderShared.eventError(ADAPTER, `Unexpected terminal Interactions status: ${interaction.status}`, encodeJson(event));
|
|
465
482
|
const pending = yield* ToolStream.finishAll(ADAPTER, state.tools);
|
|
466
483
|
const events = [...pending.events];
|
|
484
|
+
const hasToolCalls = Object.values(state.steps).some((item) => item?.type === "function_call");
|
|
467
485
|
const lifecycle = Lifecycle.finish(state.lifecycle, events, {
|
|
468
486
|
reason: {
|
|
469
|
-
normalized: interaction.status === "requires_action"
|
|
487
|
+
normalized: interaction.status === "requires_action" || (interaction.status === "completed" && hasToolCalls)
|
|
470
488
|
? "tool-calls"
|
|
471
489
|
: interaction.status === "incomplete"
|
|
472
490
|
? "length"
|
|
@@ -476,7 +494,7 @@ const step = Effect.fnUntraced(function* (state, event) {
|
|
|
476
494
|
usage: mapUsage(interaction.usage, state.metadataKey),
|
|
477
495
|
providerMetadata: { [state.metadataKey]: { interactionId: interaction.id } },
|
|
478
496
|
});
|
|
479
|
-
return [{ ...state, lifecycle, tools: pending.tools
|
|
497
|
+
return [{ ...state, lifecycle, tools: pending.tools }, events];
|
|
480
498
|
}
|
|
481
499
|
}
|
|
482
500
|
});
|
|
@@ -490,18 +508,14 @@ export const protocol = Protocol.make({
|
|
|
490
508
|
stream: {
|
|
491
509
|
event: Protocol.jsonEvent(Event),
|
|
492
510
|
initial: (request) => ({
|
|
493
|
-
route: `${request.model.provider}/${
|
|
511
|
+
route: `${request.model.provider}/${request.model.route.id}`,
|
|
494
512
|
metadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
|
|
495
513
|
lifecycle: Lifecycle.initial(),
|
|
496
514
|
steps: {},
|
|
497
515
|
tools: ToolStream.empty(),
|
|
498
|
-
completed: false,
|
|
499
516
|
}),
|
|
500
517
|
step,
|
|
501
518
|
terminal: (event) => event.event_type === "interaction.completed",
|
|
502
|
-
onHalt: (state) => state.completed
|
|
503
|
-
? Effect.succeed([])
|
|
504
|
-
: Effect.fail(ProviderShared.eventError(ADAPTER, "Google Interactions stream ended before interaction.completed")),
|
|
505
519
|
},
|
|
506
520
|
});
|
|
507
521
|
export const route = Route.make({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
|
-
import { SpeechModel, type
|
|
3
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
4
4
|
import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
|
|
5
5
|
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
@@ -21,7 +21,7 @@ export type GoogleSpeechOptions = {
|
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
} & Record<string, unknown>;
|
|
24
|
-
export type Request =
|
|
24
|
+
export type Request = SpeechRequest<SpeechModel<GoogleSpeechOptions>>;
|
|
25
25
|
interface State extends SpeechStream.Audio, GeminiGenerateContent.Metadata {
|
|
26
26
|
readonly mimeType?: string;
|
|
27
27
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { TranscriptionModel, type
|
|
4
|
+
import { TranscriptionModel, type TranscriptionRequest, type TranscriptionSegment, type TranscriptionWord } from "../transcription.js";
|
|
5
5
|
import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
7
7
|
/**
|
|
@@ -15,7 +15,7 @@ export type GoogleTranscriptionOptions = {
|
|
|
15
15
|
readonly languageCodes?: ReadonlyArray<string>;
|
|
16
16
|
};
|
|
17
17
|
} & Record<string, unknown>;
|
|
18
|
-
export type Request =
|
|
18
|
+
export type Request = TranscriptionRequest<TranscriptionModel<GoogleTranscriptionOptions>>;
|
|
19
19
|
interface State extends GeminiGenerateContent.Metadata {
|
|
20
20
|
readonly text: string;
|
|
21
21
|
readonly segments: Array<TranscriptionSegment>;
|
|
@@ -2,13 +2,13 @@ import { Schema } from "effect";
|
|
|
2
2
|
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
|
-
import { VideoModel, VideoResponse, type
|
|
5
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
7
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>;
|
|
11
|
-
export type Request =
|
|
11
|
+
export type Request = VideoRequest<VideoModel<GoogleVideoOptions>>;
|
|
12
12
|
/** The long-running operation name, e.g. `models/veo-3.1-generate-preview/operations/abc123`. */
|
|
13
13
|
export declare const Token: Schema.Struct<{
|
|
14
14
|
readonly operation: Schema.String;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
@@ -20,7 +20,7 @@ export type ImageOptions = {
|
|
|
20
20
|
};
|
|
21
21
|
readonly [key: string]: unknown;
|
|
22
22
|
};
|
|
23
|
-
export type Request =
|
|
23
|
+
export type Request = ImageRequest<ImageModel<ImageOptions>>;
|
|
24
24
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
25
25
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<ImageOptions>;
|
|
26
26
|
export * as MetaImages from "./meta-images.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { Base64 } from "effect/encoding";
|
|
3
3
|
import { Protocol } from "../route/protocol.js";
|
|
4
|
-
import {
|
|
4
|
+
import { AssistantMessage, LLMEvent, ToolResultPart } from "../schema/index.js";
|
|
5
5
|
import { OpenResponses } from "./open-responses.js";
|
|
6
6
|
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
7
7
|
import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
|
|
@@ -48,27 +48,30 @@ 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
|
-
const body = yield* OpenResponses.fromRequestWithAdapter(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
part.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
const body = yield* OpenResponses.fromRequestWithAdapter({
|
|
52
|
+
...request,
|
|
53
|
+
messages: request.messages.map((message) => message.role !== "assistant"
|
|
54
|
+
? message
|
|
55
|
+
: new AssistantMessage({
|
|
56
|
+
...message,
|
|
57
|
+
content: message.content.map((part) => {
|
|
58
|
+
if (part.type !== "tool-result" ||
|
|
59
|
+
!part.providerExecuted ||
|
|
60
|
+
part.name !== "image_generation" ||
|
|
61
|
+
part.result.type !== "content" ||
|
|
62
|
+
part.providerMetadata?.[key]?.itemId !== part.id)
|
|
63
|
+
return part;
|
|
64
|
+
// Meta's signed image ID carries edit state; replay the handle, not the image bytes as a user message.
|
|
65
|
+
return ToolResultPart.make({
|
|
66
|
+
...part,
|
|
67
|
+
result: {
|
|
68
|
+
type: "json",
|
|
69
|
+
value: { type: "image_generation_call", id: part.id, status: "completed", result: null },
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}),
|
|
73
|
+
})),
|
|
74
|
+
}, adapter);
|
|
72
75
|
// Meta cannot see video nested in tool results; attach it after the complete result batch.
|
|
73
76
|
const input = [];
|
|
74
77
|
const videos = [];
|
|
@@ -99,7 +102,7 @@ const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
|
99
102
|
// Hosted replay items have an open `type`, so a plain tag check does not narrow the union.
|
|
100
103
|
const isFunctionCallOutput = (item) => item.type === "function_call_output" || item.type === "custom_tool_call_output";
|
|
101
104
|
const HOSTED_TOOLS = {
|
|
102
|
-
web_search_call:
|
|
105
|
+
web_search_call: ResponsesHostedTools.common.web_search_call,
|
|
103
106
|
image_generation_call: {
|
|
104
107
|
name: "image_generation",
|
|
105
108
|
input: () => ({}),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
@@ -16,7 +16,7 @@ export type MiniMaxImageOptions = {
|
|
|
16
16
|
readonly width?: number;
|
|
17
17
|
readonly height?: number;
|
|
18
18
|
} & Record<string, unknown>;
|
|
19
|
-
export type Request =
|
|
19
|
+
export type Request = ImageRequest<ImageModel<MiniMaxImageOptions>>;
|
|
20
20
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
21
21
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<MiniMaxImageOptions>;
|
|
22
22
|
export declare const MiniMaxImages: {
|