@opencode/ai 2.1.3 → 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 +13 -22
- package/dist/image-client.js +0 -1
- package/dist/image.d.ts +154 -324
- 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 +32 -12
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +62 -27
- package/dist/protocols/alibaba-responses.d.ts +41 -38
- package/dist/protocols/anthropic-messages.d.ts +196 -94
- package/dist/protocols/anthropic-messages.js +47 -16
- package/dist/protocols/bedrock-converse.d.ts +140 -47
- package/dist/protocols/bedrock-converse.js +114 -18
- 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 +32 -50
- 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/cohere-chat.d.ts +7 -8
- package/dist/protocols/deepgram-speech.d.ts +32 -50
- package/dist/protocols/elevenlabs-speech.d.ts +32 -50
- 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 +37 -34
- package/dist/protocols/gemini.js +13 -8
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-images.js +8 -37
- package/dist/protocols/google-interactions.d.ts +18 -14
- package/dist/protocols/google-interactions.js +14 -7
- package/dist/protocols/google-speech.d.ts +32 -50
- package/dist/protocols/google-speech.js +0 -1
- package/dist/protocols/google-transcription.d.ts +32 -50
- 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 +73 -38
- package/dist/protocols/meta-messages.js +14 -1
- package/dist/protocols/meta-responses.d.ts +84 -78
- package/dist/protocols/meta-responses.js +29 -1
- package/dist/protocols/mistral-chat.d.ts +81 -78
- package/dist/protocols/mistral-chat.js +2 -1
- package/dist/protocols/open-responses-channel.js +47 -46
- package/dist/protocols/open-responses-continuation.d.ts +8 -2
- package/dist/protocols/open-responses-continuation.js +3 -1
- package/dist/protocols/open-responses.d.ts +426 -396
- package/dist/protocols/open-responses.js +16 -25
- package/dist/protocols/openai-chat.d.ts +764 -52
- package/dist/protocols/openai-chat.js +38 -25
- package/dist/protocols/openai-compatible-chat.d.ts +35 -15
- package/dist/protocols/openai-compatible-responses.d.ts +44 -42
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +128 -0
- package/dist/protocols/openai-images.d.ts +53 -56
- package/dist/protocols/openai-images.js +100 -34
- package/dist/protocols/openai-responses.d.ts +322 -264
- package/dist/protocols/openai-responses.js +33 -3
- package/dist/protocols/openai-speech.d.ts +32 -50
- package/dist/protocols/openai-speech.js +15 -5
- package/dist/protocols/openai-transcription.d.ts +32 -50
- package/dist/protocols/openai-transcription.js +15 -11
- 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/partial-json-options.d.ts +0 -1
- package/dist/protocols/utils/partial-json-options.js +0 -1
- 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 +10 -1
- package/dist/protocols/venice-chat.d.ts +71 -53
- package/dist/protocols/venice-chat.js +7 -6
- package/dist/protocols/xai-images.d.ts +1 -2
- package/dist/protocols/xai-images.js +9 -2
- package/dist/protocols/xai-responses.d.ts +88 -78
- 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 +54 -30
- package/dist/protocols/zai-chat.js +8 -3
- package/dist/protocols/zai-images.d.ts +3 -1
- package/dist/protocols/zai-images.js +12 -11
- package/dist/protocols/zai-messages.d.ts +72 -35
- package/dist/protocols/zai-messages.js +3 -2
- package/dist/provider-error.js +24 -7
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +146 -85
- package/dist/providers/alibaba.js +16 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +277 -218
- package/dist/providers/amazon-bedrock.d.ts +48 -28
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +64 -29
- package/dist/providers/anthropic.d.ts +64 -29
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +156 -115
- 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 +75 -25
- package/dist/providers/baseten.js +41 -8
- package/dist/providers/cerebras.d.ts +66 -24
- 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 +409 -272
- package/dist/providers/cloudflare-ai-gateway.js +33 -6
- 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 +79 -25
- package/dist/providers/cloudflare-workers-ai.js +45 -9
- package/dist/providers/cohere.d.ts +117 -75
- package/dist/providers/deepinfra.d.ts +66 -24
- package/dist/providers/deepseek.d.ts +66 -24
- 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 +108 -37
- package/dist/providers/digitalocean.js +39 -8
- package/dist/providers/fireworks.d.ts +66 -24
- 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 +33 -12
- package/dist/providers/google-vertex-messages.d.ts +64 -29
- package/dist/providers/google-vertex-mistral.d.ts +17 -17
- package/dist/providers/google-vertex-responses.d.ts +38 -35
- package/dist/providers/google-vertex.d.ts +20 -18
- package/dist/providers/google-vertex.js +32 -15
- package/dist/providers/google.d.ts +22 -21
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +66 -28
- package/dist/providers/groq.js +0 -6
- package/dist/providers/meta.d.ts +144 -85
- package/dist/providers/minimax.d.ts +145 -86
- package/dist/providers/mistral.d.ts +28 -28
- package/dist/providers/moonshot.d.ts +277 -218
- package/dist/providers/open-responses-options.d.ts +0 -1
- package/dist/providers/open-responses-options.js +1 -1
- 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 +38 -35
- package/dist/providers/openai-compatible.d.ts +36 -13
- package/dist/providers/openai-compatible.js +22 -10
- package/dist/providers/openai-options.d.ts +3 -2
- package/dist/providers/openai-options.js +0 -1
- package/dist/providers/openai.d.ts +146 -109
- 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 +128 -47
- package/dist/providers/openrouter.js +38 -16
- package/dist/providers/togetherai.d.ts +66 -24
- 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 +214 -20
- 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 +40 -17
- 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 +224 -85
- package/dist/providers/zai.d.ts +110 -23
- package/dist/providers/zai.js +15 -8
- package/dist/route/auth-options.d.ts +0 -3
- package/dist/route/auth.d.ts +0 -2
- package/dist/route/auth.js +0 -2
- package/dist/route/client.d.ts +2 -4
- package/dist/route/client.js +29 -8
- package/dist/route/decision.d.ts +58 -0
- package/dist/route/decision.js +75 -0
- package/dist/route/executor-service.js +1 -1
- 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 +13 -22
- package/dist/speech-client.js +0 -1
- package/dist/speech.d.ts +148 -283
- 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 +13 -22
- package/dist/transcription.d.ts +148 -283
- package/dist/transcription.js +1 -1
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +13 -22
- package/dist/video-client.js +0 -1
- package/dist/video.d.ts +115 -250
- package/dist/video.js +3 -5
- package/package.json +516 -13
- 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 -115
- 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
|
@@ -16,14 +16,6 @@ export type DeepgramSpeechOptions = {
|
|
|
16
16
|
} & Record<string, unknown>;
|
|
17
17
|
export type Request = SpeechRequestFor<DeepgramSpeechOptions>;
|
|
18
18
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
19
|
-
readonly type: "generation-queued";
|
|
20
|
-
readonly id: string;
|
|
21
|
-
readonly position?: number | undefined;
|
|
22
|
-
} | {
|
|
23
|
-
readonly type: "generation-progress";
|
|
24
|
-
readonly id: string;
|
|
25
|
-
readonly progress?: number | undefined;
|
|
26
|
-
} | {
|
|
27
19
|
readonly type: "audio-delta";
|
|
28
20
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
29
21
|
} | {
|
|
@@ -33,18 +25,18 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
33
25
|
readonly startSeconds: number;
|
|
34
26
|
readonly endSeconds: number;
|
|
35
27
|
}[];
|
|
28
|
+
} | {
|
|
29
|
+
readonly type: "generation-queued";
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly position?: number | undefined;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "generation-progress";
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly progress?: number | undefined;
|
|
36
36
|
} | {
|
|
37
37
|
readonly type: "finish";
|
|
38
38
|
readonly audio: import("../media.js").Asset;
|
|
39
39
|
readonly usage?: {
|
|
40
|
-
readonly type: "tokens";
|
|
41
|
-
readonly input?: number | undefined;
|
|
42
|
-
readonly output?: number | undefined;
|
|
43
|
-
readonly total?: number | undefined;
|
|
44
|
-
readonly details?: {
|
|
45
|
-
readonly [x: string]: unknown;
|
|
46
|
-
} | undefined;
|
|
47
|
-
} | {
|
|
48
40
|
readonly type: "seconds";
|
|
49
41
|
readonly seconds: number;
|
|
50
42
|
} | {
|
|
@@ -56,16 +48,15 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
56
48
|
} | {
|
|
57
49
|
readonly type: "compute";
|
|
58
50
|
readonly seconds: number;
|
|
59
|
-
} |
|
|
60
|
-
|
|
61
|
-
readonly
|
|
62
|
-
readonly
|
|
63
|
-
readonly
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "tokens";
|
|
53
|
+
readonly input?: number | undefined;
|
|
54
|
+
readonly output?: number | undefined;
|
|
55
|
+
readonly total?: number | undefined;
|
|
56
|
+
readonly details?: {
|
|
57
|
+
readonly [x: string]: unknown;
|
|
67
58
|
} | undefined;
|
|
68
|
-
}
|
|
59
|
+
} | undefined;
|
|
69
60
|
readonly providerMetadata?: {
|
|
70
61
|
readonly [x: string]: {
|
|
71
62
|
readonly [x: string]: unknown;
|
|
@@ -75,14 +66,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
75
66
|
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<DeepgramSpeechOptions>;
|
|
76
67
|
export declare const DeepgramSpeech: {
|
|
77
68
|
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
78
|
-
readonly type: "generation-queued";
|
|
79
|
-
readonly id: string;
|
|
80
|
-
readonly position?: number | undefined;
|
|
81
|
-
} | {
|
|
82
|
-
readonly type: "generation-progress";
|
|
83
|
-
readonly id: string;
|
|
84
|
-
readonly progress?: number | undefined;
|
|
85
|
-
} | {
|
|
86
69
|
readonly type: "audio-delta";
|
|
87
70
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
88
71
|
} | {
|
|
@@ -92,18 +75,18 @@ export declare const DeepgramSpeech: {
|
|
|
92
75
|
readonly startSeconds: number;
|
|
93
76
|
readonly endSeconds: number;
|
|
94
77
|
}[];
|
|
78
|
+
} | {
|
|
79
|
+
readonly type: "generation-queued";
|
|
80
|
+
readonly id: string;
|
|
81
|
+
readonly position?: number | undefined;
|
|
82
|
+
} | {
|
|
83
|
+
readonly type: "generation-progress";
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly progress?: number | undefined;
|
|
95
86
|
} | {
|
|
96
87
|
readonly type: "finish";
|
|
97
88
|
readonly audio: import("../media.js").Asset;
|
|
98
89
|
readonly usage?: {
|
|
99
|
-
readonly type: "tokens";
|
|
100
|
-
readonly input?: number | undefined;
|
|
101
|
-
readonly output?: number | undefined;
|
|
102
|
-
readonly total?: number | undefined;
|
|
103
|
-
readonly details?: {
|
|
104
|
-
readonly [x: string]: unknown;
|
|
105
|
-
} | undefined;
|
|
106
|
-
} | {
|
|
107
90
|
readonly type: "seconds";
|
|
108
91
|
readonly seconds: number;
|
|
109
92
|
} | {
|
|
@@ -115,16 +98,15 @@ export declare const DeepgramSpeech: {
|
|
|
115
98
|
} | {
|
|
116
99
|
readonly type: "compute";
|
|
117
100
|
readonly seconds: number;
|
|
118
|
-
} |
|
|
119
|
-
|
|
120
|
-
readonly
|
|
121
|
-
readonly
|
|
122
|
-
readonly
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
};
|
|
101
|
+
} | {
|
|
102
|
+
readonly type: "tokens";
|
|
103
|
+
readonly input?: number | undefined;
|
|
104
|
+
readonly output?: number | undefined;
|
|
105
|
+
readonly total?: number | undefined;
|
|
106
|
+
readonly details?: {
|
|
107
|
+
readonly [x: string]: unknown;
|
|
126
108
|
} | undefined;
|
|
127
|
-
}
|
|
109
|
+
} | undefined;
|
|
128
110
|
readonly providerMetadata?: {
|
|
129
111
|
readonly [x: string]: {
|
|
130
112
|
readonly [x: string]: unknown;
|
|
@@ -19,14 +19,6 @@ export type ElevenLabsSpeechOptions = {
|
|
|
19
19
|
} & Record<string, unknown>;
|
|
20
20
|
export type Request = SpeechRequestFor<ElevenLabsSpeechOptions>;
|
|
21
21
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
22
|
-
readonly type: "generation-queued";
|
|
23
|
-
readonly id: string;
|
|
24
|
-
readonly position?: number | undefined;
|
|
25
|
-
} | {
|
|
26
|
-
readonly type: "generation-progress";
|
|
27
|
-
readonly id: string;
|
|
28
|
-
readonly progress?: number | undefined;
|
|
29
|
-
} | {
|
|
30
22
|
readonly type: "audio-delta";
|
|
31
23
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
32
24
|
} | {
|
|
@@ -36,18 +28,18 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
36
28
|
readonly startSeconds: number;
|
|
37
29
|
readonly endSeconds: number;
|
|
38
30
|
}[];
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "generation-queued";
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly position?: number | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "generation-progress";
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly progress?: number | undefined;
|
|
39
39
|
} | {
|
|
40
40
|
readonly type: "finish";
|
|
41
41
|
readonly audio: import("../media.js").Asset;
|
|
42
42
|
readonly usage?: {
|
|
43
|
-
readonly type: "tokens";
|
|
44
|
-
readonly input?: number | undefined;
|
|
45
|
-
readonly output?: number | undefined;
|
|
46
|
-
readonly total?: number | undefined;
|
|
47
|
-
readonly details?: {
|
|
48
|
-
readonly [x: string]: unknown;
|
|
49
|
-
} | undefined;
|
|
50
|
-
} | {
|
|
51
43
|
readonly type: "seconds";
|
|
52
44
|
readonly seconds: number;
|
|
53
45
|
} | {
|
|
@@ -59,16 +51,15 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
59
51
|
} | {
|
|
60
52
|
readonly type: "compute";
|
|
61
53
|
readonly seconds: number;
|
|
62
|
-
} |
|
|
63
|
-
|
|
64
|
-
readonly
|
|
65
|
-
readonly
|
|
66
|
-
readonly
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
54
|
+
} | {
|
|
55
|
+
readonly type: "tokens";
|
|
56
|
+
readonly input?: number | undefined;
|
|
57
|
+
readonly output?: number | undefined;
|
|
58
|
+
readonly total?: number | undefined;
|
|
59
|
+
readonly details?: {
|
|
60
|
+
readonly [x: string]: unknown;
|
|
70
61
|
} | undefined;
|
|
71
|
-
}
|
|
62
|
+
} | undefined;
|
|
72
63
|
readonly providerMetadata?: {
|
|
73
64
|
readonly [x: string]: {
|
|
74
65
|
readonly [x: string]: unknown;
|
|
@@ -78,14 +69,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
78
69
|
export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<ElevenLabsSpeechOptions>;
|
|
79
70
|
export declare const ElevenLabsSpeech: {
|
|
80
71
|
readonly protocol: MediaProtocol.Streamed<Request, {
|
|
81
|
-
readonly type: "generation-queued";
|
|
82
|
-
readonly id: string;
|
|
83
|
-
readonly position?: number | undefined;
|
|
84
|
-
} | {
|
|
85
|
-
readonly type: "generation-progress";
|
|
86
|
-
readonly id: string;
|
|
87
|
-
readonly progress?: number | undefined;
|
|
88
|
-
} | {
|
|
89
72
|
readonly type: "audio-delta";
|
|
90
73
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
91
74
|
} | {
|
|
@@ -95,18 +78,18 @@ export declare const ElevenLabsSpeech: {
|
|
|
95
78
|
readonly startSeconds: number;
|
|
96
79
|
readonly endSeconds: number;
|
|
97
80
|
}[];
|
|
81
|
+
} | {
|
|
82
|
+
readonly type: "generation-queued";
|
|
83
|
+
readonly id: string;
|
|
84
|
+
readonly position?: number | undefined;
|
|
85
|
+
} | {
|
|
86
|
+
readonly type: "generation-progress";
|
|
87
|
+
readonly id: string;
|
|
88
|
+
readonly progress?: number | undefined;
|
|
98
89
|
} | {
|
|
99
90
|
readonly type: "finish";
|
|
100
91
|
readonly audio: import("../media.js").Asset;
|
|
101
92
|
readonly usage?: {
|
|
102
|
-
readonly type: "tokens";
|
|
103
|
-
readonly input?: number | undefined;
|
|
104
|
-
readonly output?: number | undefined;
|
|
105
|
-
readonly total?: number | undefined;
|
|
106
|
-
readonly details?: {
|
|
107
|
-
readonly [x: string]: unknown;
|
|
108
|
-
} | undefined;
|
|
109
|
-
} | {
|
|
110
93
|
readonly type: "seconds";
|
|
111
94
|
readonly seconds: number;
|
|
112
95
|
} | {
|
|
@@ -118,16 +101,15 @@ export declare const ElevenLabsSpeech: {
|
|
|
118
101
|
} | {
|
|
119
102
|
readonly type: "compute";
|
|
120
103
|
readonly seconds: number;
|
|
121
|
-
} |
|
|
122
|
-
|
|
123
|
-
readonly
|
|
124
|
-
readonly
|
|
125
|
-
readonly
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
};
|
|
104
|
+
} | {
|
|
105
|
+
readonly type: "tokens";
|
|
106
|
+
readonly input?: number | undefined;
|
|
107
|
+
readonly output?: number | undefined;
|
|
108
|
+
readonly total?: number | undefined;
|
|
109
|
+
readonly details?: {
|
|
110
|
+
readonly [x: string]: unknown;
|
|
129
111
|
} | undefined;
|
|
130
|
-
}
|
|
112
|
+
} | undefined;
|
|
131
113
|
readonly providerMetadata?: {
|
|
132
114
|
readonly [x: string]: {
|
|
133
115
|
readonly [x: string]: unknown;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
|
|
2
|
+
import { Media } from "../media.js";
|
|
2
3
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
4
|
import { MediaRoute } from "../route/media.js";
|
|
4
5
|
import { type OpenString } from "../schema/index.js";
|
|
6
|
+
/** Model-defined `input` fields; `aspect` and `resolution` lower to `image_size` or `aspect_ratio` per model. */
|
|
5
7
|
export type FalImageOptions = {
|
|
6
|
-
readonly image_size?: OpenString<"square_hd" | "square" | "portrait_4_3" | "portrait_16_9" | "landscape_4_3" | "landscape_16_9"
|
|
8
|
+
readonly image_size?: OpenString<"square_hd" | "square" | "portrait_4_3" | "portrait_16_9" | "landscape_4_3" | "landscape_16_9"> | {
|
|
9
|
+
readonly width: number;
|
|
10
|
+
readonly height: number;
|
|
11
|
+
};
|
|
12
|
+
readonly seed?: number;
|
|
13
|
+
readonly output_format?: OpenString<"jpeg" | "png" | "webp">;
|
|
14
|
+
/** Inpainting mask, sent as `mask_url`. */
|
|
15
|
+
readonly mask?: Media.Asset;
|
|
7
16
|
readonly enable_safety_checker?: boolean;
|
|
8
17
|
} & Record<string, unknown>;
|
|
9
18
|
export type Request = ImageRequestFor<FalImageOptions>;
|
|
@@ -4,9 +4,9 @@ import { Media } from "../media.js";
|
|
|
4
4
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
5
|
import { MediaRoute } from "../route/media.js";
|
|
6
6
|
import { mergeJsonRecords } from "../schema/index.js";
|
|
7
|
-
import {
|
|
7
|
+
import { optionalNull } from "./shared.js";
|
|
8
8
|
import { FalQueue } from "./utils/fal-queue.js";
|
|
9
|
-
import {
|
|
9
|
+
import { ImageSizing } from "./utils/image-sizing.js";
|
|
10
10
|
const route = MediaProtocol.identity({ id: "fal-images", name: "fal Images", provider: "fal" });
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// 2. Response schema
|
|
@@ -24,8 +24,11 @@ const QueueResult = Schema.StructWithRest(Schema.Struct({
|
|
|
24
24
|
// ---------------------------------------------------------------------------
|
|
25
25
|
// 5. Request body construction
|
|
26
26
|
// ---------------------------------------------------------------------------
|
|
27
|
+
/** Nano Banana takes `aspect_ratio` and `resolution` tiers, FLUX Ultra and Kontext only `aspect_ratio`, FLUX `image_size`. */
|
|
27
28
|
const sizing = (model) => {
|
|
28
|
-
if (
|
|
29
|
+
if (model.startsWith("fal-ai/nano-banana"))
|
|
30
|
+
return "tiers";
|
|
31
|
+
if (/^fal-ai\/flux-pro\/(v1\.1-ultra|kontext)/.test(model))
|
|
29
32
|
return "aspect_ratio";
|
|
30
33
|
if (model.startsWith("fal-ai/flux"))
|
|
31
34
|
return "image_size";
|
|
@@ -33,13 +36,8 @@ const sizing = (model) => {
|
|
|
33
36
|
};
|
|
34
37
|
const validate = (request) => {
|
|
35
38
|
const id = request.model.id;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return Effect.fail(ProviderShared.invalidRequest(`${route.name} accepts either size or aspectRatio, not both`));
|
|
39
|
-
if (request.size !== undefined && field === "aspect_ratio")
|
|
40
|
-
return Effect.fail(route.unsupported("media.size", `${id} sizes by aspectRatio`));
|
|
41
|
-
if (request.aspectRatio !== undefined && field === "image_size")
|
|
42
|
-
return Effect.fail(route.unsupported("media.aspectRatio", `${id} sizes by size (image_size)`));
|
|
39
|
+
if (request.resolution !== undefined && sizing(id) === "aspect_ratio")
|
|
40
|
+
return Effect.fail(route.unsupported("media.resolution", `${id} sizes by aspect only`));
|
|
43
41
|
if ((request.images?.length ?? 0) > 1 && !takesImageList(id))
|
|
44
42
|
return Effect.fail(route.unsupported("media.images", `${id} takes one image_url; use an /edit or /multi endpoint for several images`));
|
|
45
43
|
return Effect.void;
|
|
@@ -51,17 +49,18 @@ const fromRequest = Effect.fn("FalImages.fromRequest")(function* (request) {
|
|
|
51
49
|
yield* validate(request);
|
|
52
50
|
const images = yield* Effect.forEach(request.images ?? [], (image) => FalQueue.mediaUrl(image, route.name));
|
|
53
51
|
const list = takesImageList(request.model.id);
|
|
52
|
+
const { mask, ...native } = request.providerOptions ?? {};
|
|
53
|
+
const field = sizing(request.model.id);
|
|
54
54
|
return MediaProtocol.json(mergeJsonRecords({
|
|
55
55
|
prompt: request.prompt,
|
|
56
56
|
num_images: request.n,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
output_format: request.format,
|
|
57
|
+
...(field === "image_size"
|
|
58
|
+
? { image_size: yield* ImageSizing.exact(route, request, { multiple: 16 }) }
|
|
59
|
+
: { aspect_ratio: request.aspect, resolution: request.resolution }),
|
|
61
60
|
image_urls: list && images.length > 0 ? images : undefined,
|
|
62
61
|
image_url: list ? undefined : images[0],
|
|
63
|
-
mask_url:
|
|
64
|
-
},
|
|
62
|
+
mask_url: mask === undefined ? undefined : yield* FalQueue.mediaUrl(mask, route.name),
|
|
63
|
+
}, native, request.http?.body) ?? {});
|
|
65
64
|
});
|
|
66
65
|
// ---------------------------------------------------------------------------
|
|
67
66
|
// 6. Response decoding
|
|
@@ -69,11 +68,9 @@ const fromRequest = Effect.fn("FalImages.fromRequest")(function* (request) {
|
|
|
69
68
|
const decodeQueueResult = route.decodeJson(QueueResult);
|
|
70
69
|
const decodeResult = Effect.fn("FalImages.decodeResult")(function* (response, context) {
|
|
71
70
|
const output = yield* decodeQueueResult(response);
|
|
72
|
-
const { images, seed,
|
|
71
|
+
const { images, seed, ...rest } = output.value;
|
|
73
72
|
if (images.length === 0)
|
|
74
73
|
return yield* output.invalid(`${route.name} returned no images`);
|
|
75
|
-
// With the safety checker on, flagged images come back blacked out rather than omitted.
|
|
76
|
-
const flagged = (has_nsfw_concepts ?? []).flatMap((value, index) => (value ? [index] : []));
|
|
77
74
|
return new ImageResponse({
|
|
78
75
|
images: images.map((image) => {
|
|
79
76
|
const info = { width: image.width ?? undefined, height: image.height ?? undefined };
|
|
@@ -81,12 +78,6 @@ const decodeResult = Effect.fn("FalImages.decodeResult")(function* (response, co
|
|
|
81
78
|
return (Media.parseDataUrl(image.url, { info }) ??
|
|
82
79
|
Media.url(image.url, { mediaType: image.content_type ?? undefined, info }));
|
|
83
80
|
}),
|
|
84
|
-
notices: flagged.length === 0
|
|
85
|
-
? undefined
|
|
86
|
-
: flagged.map((index) => ({
|
|
87
|
-
type: "moderated",
|
|
88
|
-
message: `${route.name} flagged image ${index} as NSFW`,
|
|
89
|
-
})),
|
|
90
81
|
providerMetadata: { fal: { requestId: context.token.requestID, seed: seed ?? undefined, ...rest } },
|
|
91
82
|
});
|
|
92
83
|
});
|
|
@@ -31,7 +31,7 @@ const fromRequest = Effect.fn("FalVideo.fromRequest")(function* (request) {
|
|
|
31
31
|
prompt: request.prompt,
|
|
32
32
|
negative_prompt: request.negativePrompt,
|
|
33
33
|
seed: request.seed,
|
|
34
|
-
aspect_ratio: request.
|
|
34
|
+
aspect_ratio: request.aspect,
|
|
35
35
|
resolution: request.resolution,
|
|
36
36
|
generate_audio: request.audio,
|
|
37
37
|
image_url: imageUrl,
|
|
@@ -105,6 +105,7 @@ declare const GeminiBody: Schema.Struct<{
|
|
|
105
105
|
}>;
|
|
106
106
|
export type GeminiBody = Schema.Schema.Type<typeof GeminiBody>;
|
|
107
107
|
declare const GeminiUsage: Schema.Struct<{
|
|
108
|
+
readonly cost: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Finite>, never>>;
|
|
108
109
|
readonly cachedContentTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
109
110
|
readonly thoughtsTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
110
111
|
readonly promptTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
@@ -158,27 +159,10 @@ export declare const protocol: Protocol<{
|
|
|
158
159
|
readonly contents: readonly {
|
|
159
160
|
readonly role?: "model" | "user" | null | undefined;
|
|
160
161
|
readonly parts?: readonly ({
|
|
161
|
-
readonly inlineData: {
|
|
162
|
-
readonly mimeType: string;
|
|
163
|
-
readonly data: string;
|
|
164
|
-
};
|
|
165
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
166
|
-
} | {
|
|
167
|
-
readonly text: string;
|
|
168
|
-
readonly thought?: boolean | null | undefined;
|
|
169
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
170
|
-
} | {
|
|
171
162
|
readonly fileData: {
|
|
172
163
|
readonly mimeType: string;
|
|
173
164
|
readonly fileUri: string;
|
|
174
165
|
};
|
|
175
|
-
} | {
|
|
176
|
-
readonly functionCall: {
|
|
177
|
-
readonly id?: string | null | undefined;
|
|
178
|
-
readonly name: string;
|
|
179
|
-
readonly args?: unknown;
|
|
180
|
-
};
|
|
181
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
182
166
|
} | {
|
|
183
167
|
readonly functionResponse: {
|
|
184
168
|
readonly id?: string | undefined;
|
|
@@ -192,6 +176,23 @@ export declare const protocol: Protocol<{
|
|
|
192
176
|
readonly thoughtSignature?: string | null | undefined;
|
|
193
177
|
}[] | undefined;
|
|
194
178
|
};
|
|
179
|
+
} | {
|
|
180
|
+
readonly text: string;
|
|
181
|
+
readonly thought?: boolean | null | undefined;
|
|
182
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
183
|
+
} | {
|
|
184
|
+
readonly inlineData: {
|
|
185
|
+
readonly mimeType: string;
|
|
186
|
+
readonly data: string;
|
|
187
|
+
};
|
|
188
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
189
|
+
} | {
|
|
190
|
+
readonly functionCall: {
|
|
191
|
+
readonly id?: string | null | undefined;
|
|
192
|
+
readonly name: string;
|
|
193
|
+
readonly args?: unknown;
|
|
194
|
+
};
|
|
195
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
195
196
|
})[] | null | undefined;
|
|
196
197
|
}[];
|
|
197
198
|
readonly labels?: {
|
|
@@ -259,6 +260,7 @@ export declare const protocol: Protocol<{
|
|
|
259
260
|
readonly safetyRatings?: unknown;
|
|
260
261
|
} | null | undefined;
|
|
261
262
|
readonly usageMetadata?: {
|
|
263
|
+
readonly cost?: number | undefined;
|
|
262
264
|
readonly cachedContentTokenCount?: number | null | undefined;
|
|
263
265
|
readonly thoughtsTokenCount?: number | null | undefined;
|
|
264
266
|
readonly promptTokenCount?: number | null | undefined;
|
|
@@ -286,6 +288,7 @@ export declare const protocol: Protocol<{
|
|
|
286
288
|
readonly safetyRatings?: unknown;
|
|
287
289
|
} | null | undefined;
|
|
288
290
|
readonly usageMetadata?: {
|
|
291
|
+
readonly cost?: number | undefined;
|
|
289
292
|
readonly cachedContentTokenCount?: number | null | undefined;
|
|
290
293
|
readonly thoughtsTokenCount?: number | null | undefined;
|
|
291
294
|
readonly promptTokenCount?: number | null | undefined;
|
|
@@ -298,27 +301,10 @@ export declare const route: Route<{
|
|
|
298
301
|
readonly contents: readonly {
|
|
299
302
|
readonly role?: "model" | "user" | null | undefined;
|
|
300
303
|
readonly parts?: readonly ({
|
|
301
|
-
readonly inlineData: {
|
|
302
|
-
readonly mimeType: string;
|
|
303
|
-
readonly data: string;
|
|
304
|
-
};
|
|
305
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
306
|
-
} | {
|
|
307
|
-
readonly text: string;
|
|
308
|
-
readonly thought?: boolean | null | undefined;
|
|
309
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
310
|
-
} | {
|
|
311
304
|
readonly fileData: {
|
|
312
305
|
readonly mimeType: string;
|
|
313
306
|
readonly fileUri: string;
|
|
314
307
|
};
|
|
315
|
-
} | {
|
|
316
|
-
readonly functionCall: {
|
|
317
|
-
readonly id?: string | null | undefined;
|
|
318
|
-
readonly name: string;
|
|
319
|
-
readonly args?: unknown;
|
|
320
|
-
};
|
|
321
|
-
readonly thoughtSignature?: string | null | undefined;
|
|
322
308
|
} | {
|
|
323
309
|
readonly functionResponse: {
|
|
324
310
|
readonly id?: string | undefined;
|
|
@@ -332,6 +318,23 @@ export declare const route: Route<{
|
|
|
332
318
|
readonly thoughtSignature?: string | null | undefined;
|
|
333
319
|
}[] | undefined;
|
|
334
320
|
};
|
|
321
|
+
} | {
|
|
322
|
+
readonly text: string;
|
|
323
|
+
readonly thought?: boolean | null | undefined;
|
|
324
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
325
|
+
} | {
|
|
326
|
+
readonly inlineData: {
|
|
327
|
+
readonly mimeType: string;
|
|
328
|
+
readonly data: string;
|
|
329
|
+
};
|
|
330
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
331
|
+
} | {
|
|
332
|
+
readonly functionCall: {
|
|
333
|
+
readonly id?: string | null | undefined;
|
|
334
|
+
readonly name: string;
|
|
335
|
+
readonly args?: unknown;
|
|
336
|
+
};
|
|
337
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
335
338
|
})[] | null | undefined;
|
|
336
339
|
}[];
|
|
337
340
|
readonly labels?: {
|
package/dist/protocols/gemini.js
CHANGED
|
@@ -59,7 +59,6 @@ const GeminiInlineDataPart = Schema.Struct({
|
|
|
59
59
|
}),
|
|
60
60
|
thoughtSignature: optionalNull(Schema.String),
|
|
61
61
|
});
|
|
62
|
-
/** Gemini Files API reference; the only remote input Gemini accepts. */
|
|
63
62
|
const GeminiFileDataPart = Schema.Struct({
|
|
64
63
|
fileData: Schema.Struct({
|
|
65
64
|
mimeType: Schema.String,
|
|
@@ -172,6 +171,7 @@ const GeminiUsage = Schema.Struct({
|
|
|
172
171
|
promptTokenCount: optionalNull(Schema.Number),
|
|
173
172
|
candidatesTokenCount: optionalNull(Schema.Number),
|
|
174
173
|
totalTokenCount: optionalNull(Schema.Number),
|
|
174
|
+
...ProviderShared.ReportedBilling.fields,
|
|
175
175
|
});
|
|
176
176
|
const GeminiCandidate = Schema.Struct({
|
|
177
177
|
content: optionalNull(GeminiResponseContent),
|
|
@@ -224,7 +224,7 @@ const lowerToolCall = (part, omitIds, metadataKey) => ({
|
|
|
224
224
|
});
|
|
225
225
|
const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
226
226
|
const contents = [];
|
|
227
|
-
const metadataKey = request.model.route.providerMetadataKey ??
|
|
227
|
+
const metadataKey = request.model.route.providerMetadataKey ?? request.model.provider;
|
|
228
228
|
const omitCallIds = omitsFunctionCallIds(request.model.id);
|
|
229
229
|
const legacyToolMedia = routesLegacyToolMedia(request.model.id);
|
|
230
230
|
let pendingMedia;
|
|
@@ -329,11 +329,13 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
|
329
329
|
for (const item of content) {
|
|
330
330
|
if (item.type === "text")
|
|
331
331
|
continue;
|
|
332
|
-
const value = yield*
|
|
333
|
-
|
|
332
|
+
const value = yield* GeminiGenerateContent.mediaPart("Gemini", GeminiGenerateContent.toolMedia(item));
|
|
333
|
+
// Nested fileData can be accepted without the model seeing the video, even on newer Gemini models.
|
|
334
|
+
if (legacyToolMedia || "fileData" in value)
|
|
335
|
+
(pendingMedia ??= []).push(value);
|
|
336
|
+
else
|
|
337
|
+
media.push(value);
|
|
334
338
|
}
|
|
335
|
-
if (legacyToolMedia && media.length > 0)
|
|
336
|
-
(pendingMedia ??= []).push(...media);
|
|
337
339
|
parts.push({
|
|
338
340
|
functionResponse: {
|
|
339
341
|
...(omitCallIds ? {} : { id: part.id }),
|
|
@@ -342,7 +344,7 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
|
342
344
|
name: part.name,
|
|
343
345
|
content: text.join("\n"),
|
|
344
346
|
},
|
|
345
|
-
parts:
|
|
347
|
+
parts: media.length === 0 ? undefined : media,
|
|
346
348
|
},
|
|
347
349
|
});
|
|
348
350
|
}
|
|
@@ -430,6 +432,7 @@ const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
|
|
|
430
432
|
cacheReadInputTokens: cached,
|
|
431
433
|
reasoningTokens: thoughts,
|
|
432
434
|
totalTokens: ProviderShared.totalTokens(promptTokens, outputTokens, usage.totalTokenCount ?? undefined),
|
|
435
|
+
cost: usage.cost,
|
|
433
436
|
providerMetadata: providerMetadata(metadataKey, metadata),
|
|
434
437
|
});
|
|
435
438
|
};
|
|
@@ -443,6 +446,8 @@ const mapContinuedUsage = (requests, metadataKey) => {
|
|
|
443
446
|
cachedContentTokenCount: requests[0].cachedContentTokenCount,
|
|
444
447
|
candidatesTokenCount: sum("candidatesTokenCount"),
|
|
445
448
|
thoughtsTokenCount: sum("thoughtsTokenCount"),
|
|
449
|
+
// Every continued request is billed on its own.
|
|
450
|
+
cost: sum("cost"),
|
|
446
451
|
}, metadataKey, {
|
|
447
452
|
promptTokenCount: sum("promptTokenCount"),
|
|
448
453
|
cachedContentTokenCount: sum("cachedContentTokenCount"),
|
|
@@ -750,7 +755,7 @@ export const protocol = Protocol.make({
|
|
|
750
755
|
event: Schema.Union([Schema.instanceOf(NextRequest), GeminiEvent]),
|
|
751
756
|
initial: (request) => ({
|
|
752
757
|
route: `${request.model.provider}/${request.model.route.id}`,
|
|
753
|
-
providerMetadataKey: request.model.route.providerMetadataKey ??
|
|
758
|
+
providerMetadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
|
|
754
759
|
hasToolCalls: false,
|
|
755
760
|
lifecycle: Lifecycle.initial(),
|
|
756
761
|
nextReasoningId: 0,
|
|
@@ -3,9 +3,9 @@ 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://generativelanguage.googleapis.com/v1beta";
|
|
6
|
-
/** Provider-native
|
|
6
|
+
/** Provider-native `generationConfig` fields. Common fields (`aspect`, `resolution`, `images`) live on the request. */
|
|
7
7
|
export type GoogleImageOptions = {
|
|
8
|
-
readonly
|
|
8
|
+
readonly seed?: number;
|
|
9
9
|
readonly thinkingLevel?: OpenString<"MINIMAL" | "LOW" | "MEDIUM" | "HIGH">;
|
|
10
10
|
readonly includeThoughts?: boolean;
|
|
11
11
|
} & Record<string, unknown>;
|