@opencode/ai 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -62
- package/dist/effect.d.ts +1 -1
- package/dist/effect.js +1 -1
- package/dist/image-client.d.ts +45 -0
- package/dist/index.d.ts +38 -20
- package/dist/index.js +14 -2
- package/dist/media-client.d.ts +1 -0
- package/dist/media-client.js +1 -0
- package/dist/protocols/alibaba-chat.d.ts +39 -4
- package/dist/protocols/alibaba-responses.d.ts +20 -3
- package/dist/protocols/google-images.js +3 -1
- package/dist/protocols/meta-responses.d.ts +40 -6
- package/dist/protocols/meta-responses.js +1 -1
- package/dist/protocols/minimax-images.d.ts +25 -0
- package/dist/protocols/minimax-images.js +150 -0
- package/dist/protocols/open-responses.d.ts +182 -27
- package/dist/protocols/open-responses.js +108 -36
- package/dist/protocols/openai-chat.d.ts +438 -46
- package/dist/protocols/openai-chat.js +121 -39
- package/dist/protocols/openai-compatible-chat.d.ts +35 -4
- package/dist/protocols/openai-compatible-responses.d.ts +20 -3
- package/dist/protocols/openai-freeform.d.ts +47 -0
- package/dist/protocols/openai-freeform.js +54 -0
- package/dist/protocols/openai-images.d.ts +16 -1
- package/dist/protocols/openai-images.js +49 -17
- package/dist/protocols/openai-responses.d.ts +120 -18
- package/dist/protocols/openai-responses.js +17 -8
- package/dist/protocols/venice-chat.d.ts +39 -4
- package/dist/protocols/venice-chat.js +1 -1
- package/dist/protocols/xai-images.d.ts +6 -0
- package/dist/protocols/xai-images.js +4 -5
- package/dist/protocols/xai-responses.d.ts +20 -3
- package/dist/protocols/xai-responses.js +2 -1
- package/dist/protocols/zai-chat.d.ts +39 -4
- package/dist/provider-error.js +5 -4
- package/dist/provider-package.d.ts +2 -0
- package/dist/providers/alibaba.d.ts +58 -10
- package/dist/providers/amazon-bedrock-mantle.d.ts +66 -11
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.d.ts +1 -1
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/azure.d.ts +79 -15
- package/dist/providers/baseten.d.ts +74 -12
- package/dist/providers/baseten.js +1 -1
- package/dist/providers/cerebras.d.ts +73 -11
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts +113 -17
- package/dist/providers/cloudflare-workers-ai.d.ts +73 -11
- package/dist/providers/cohere/chat.d.ts +1 -1
- package/dist/providers/cohere/chat.js +1 -1
- package/dist/providers/cohere.d.ts +73 -11
- package/dist/providers/cohere.js +1 -1
- package/dist/providers/deepinfra.d.ts +73 -11
- package/dist/providers/deepinfra.js +1 -1
- package/dist/providers/deepseek.d.ts +73 -11
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean/responses.d.ts +4 -0
- package/dist/providers/digitalocean/responses.js +1 -0
- package/dist/providers/digitalocean.d.ts +320 -21
- package/dist/providers/digitalocean.js +18 -7
- package/dist/providers/fireworks.d.ts +73 -11
- package/dist/providers/fireworks.js +1 -1
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +1 -1
- package/dist/providers/google-vertex-chat.d.ts +36 -5
- package/dist/providers/google-vertex-chat.js +1 -1
- package/dist/providers/google-vertex-interactions.d.ts +1 -1
- package/dist/providers/google-vertex-interactions.js +1 -1
- package/dist/providers/google-vertex-messages.d.ts +1 -1
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/google-vertex-mistral.d.ts +1 -1
- package/dist/providers/google-vertex-mistral.js +1 -1
- package/dist/providers/google-vertex-responses.d.ts +21 -4
- package/dist/providers/google-vertex-responses.js +1 -1
- package/dist/providers/google-vertex.d.ts +2 -2
- package/dist/providers/google-vertex.js +1 -1
- package/dist/providers/google.d.ts +2 -2
- package/dist/providers/google.js +1 -1
- package/dist/providers/groq.d.ts +77 -11
- package/dist/providers/groq.js +1 -1
- package/dist/providers/index.d.ts +0 -4
- package/dist/providers/index.js +0 -4
- package/dist/providers/meta/images.d.ts +2 -0
- package/dist/providers/meta/images.js +1 -0
- package/dist/providers/meta.d.ts +61 -12
- package/dist/providers/meta.js +2 -1
- package/dist/providers/minimax/chat.d.ts +1 -1
- package/dist/providers/minimax/chat.js +1 -1
- package/dist/providers/minimax/images.d.ts +3 -0
- package/dist/providers/minimax/images.js +1 -0
- package/dist/providers/minimax/responses.d.ts +1 -1
- package/dist/providers/minimax/responses.js +1 -1
- package/dist/providers/minimax.d.ts +63 -9
- package/dist/providers/minimax.js +22 -9
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/moonshot/messages.d.ts +1 -1
- package/dist/providers/moonshot/messages.js +1 -1
- package/dist/providers/moonshot/responses.d.ts +1 -1
- package/dist/providers/moonshot/responses.js +1 -1
- package/dist/providers/moonshot.d.ts +56 -8
- package/dist/providers/moonshot.js +1 -1
- package/dist/providers/openai-compatible-responses.d.ts +21 -4
- package/dist/providers/openai-compatible.d.ts +38 -7
- package/dist/providers/openai-compatible.js +9 -2
- package/dist/providers/openai.d.ts +59 -11
- package/dist/providers/openai.js +4 -2
- package/dist/providers/opencode.d.ts +3 -3
- package/dist/providers/opencode.js +1 -1
- package/dist/providers/openrouter/responses.d.ts +4 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter.d.ts +356 -26
- package/dist/providers/openrouter.js +42 -13
- package/dist/providers/togetherai.d.ts +73 -11
- package/dist/providers/togetherai.js +1 -1
- package/dist/providers/typesafe-ai.d.ts +3 -3
- package/dist/providers/typesafe-ai.js +1 -1
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +242 -9
- package/dist/providers/venice.js +33 -17
- package/dist/providers/vercel-ai-gateway.d.ts +8 -8
- package/dist/providers/vercel-ai-gateway.js +12 -2
- package/dist/providers/xai.d.ts +39 -8
- package/dist/providers/xai.js +1 -1
- package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
- package/dist/providers/zai-coding-plan/messages.js +1 -1
- package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
- package/dist/providers/zai-coding-plan/responses.js +1 -1
- package/dist/providers/zai-coding-plan.d.ts +56 -8
- package/dist/providers/zai-coding-plan.js +1 -1
- package/dist/providers/zai.d.ts +37 -6
- package/dist/providers/zai.js +1 -1
- package/dist/route/auth.d.ts +1 -1
- package/dist/route/media-protocol.d.ts +2 -4
- package/dist/route/media.d.ts +1 -1
- package/dist/route/media.js +2 -4
- package/dist/schema/messages.d.ts +35 -1
- package/dist/schema/messages.js +20 -0
- package/dist/speech-client.d.ts +48 -0
- package/dist/testing/decision.d.ts +16 -0
- package/dist/testing/decision.js +20 -0
- package/dist/testing/image.d.ts +14 -0
- package/dist/testing/image.js +12 -0
- package/dist/testing/media.d.ts +18 -0
- package/dist/testing/media.js +36 -0
- package/dist/testing/script.d.ts +28 -0
- package/dist/testing/script.js +60 -0
- package/dist/testing/speech.d.ts +14 -0
- package/dist/testing/speech.js +12 -0
- package/dist/testing/transcription.d.ts +14 -0
- package/dist/testing/transcription.js +12 -0
- package/dist/testing/video.d.ts +14 -0
- package/dist/testing/video.js +12 -0
- package/dist/testing.d.ts +10 -21
- package/dist/testing.js +11 -54
- package/dist/tool.d.ts +12 -1
- package/dist/tool.js +10 -2
- package/dist/transcription-client.d.ts +64 -0
- package/dist/video-client.d.ts +41 -0
- package/package.json +22 -38
- package/dist/protocols/bfl-images.d.ts +0 -47
- package/dist/protocols/bfl-images.js +0 -155
- package/dist/protocols/fal-images.d.ts +0 -34
- package/dist/protocols/fal-images.js +0 -95
- package/dist/protocols/fal-video.d.ts +0 -29
- package/dist/protocols/fal-video.js +0 -73
- package/dist/protocols/replicate-images.d.ts +0 -28
- package/dist/protocols/replicate-images.js +0 -127
- package/dist/protocols/stability-images.d.ts +0 -44
- package/dist/protocols/stability-images.js +0 -131
- package/dist/protocols/utils/fal-queue.d.ts +0 -26
- package/dist/protocols/utils/fal-queue.js +0 -67
- package/dist/providers/black-forest-labs.d.ts +0 -21
- package/dist/providers/black-forest-labs.js +0 -23
- package/dist/providers/fal.d.ts +0 -24
- package/dist/providers/fal.js +0 -26
- package/dist/providers/replicate.d.ts +0 -21
- package/dist/providers/replicate.js +0 -17
- package/dist/providers/stability.d.ts +0 -23
- package/dist/providers/stability.js +0 -18
|
@@ -109,7 +109,14 @@ export declare const protocol: Protocol<{
|
|
|
109
109
|
readonly ttl?: string | undefined;
|
|
110
110
|
} | undefined;
|
|
111
111
|
}[] | null;
|
|
112
|
-
readonly tool_calls?: readonly {
|
|
112
|
+
readonly tool_calls?: readonly ({
|
|
113
|
+
readonly id: string;
|
|
114
|
+
readonly type: "custom";
|
|
115
|
+
readonly custom: {
|
|
116
|
+
readonly name: string;
|
|
117
|
+
readonly input: string;
|
|
118
|
+
};
|
|
119
|
+
} | {
|
|
113
120
|
readonly id: string;
|
|
114
121
|
readonly type: "function";
|
|
115
122
|
readonly function: {
|
|
@@ -121,13 +128,13 @@ export declare const protocol: Protocol<{
|
|
|
121
128
|
readonly thought_signature: string;
|
|
122
129
|
};
|
|
123
130
|
} | undefined;
|
|
124
|
-
}[] | undefined;
|
|
131
|
+
})[] | undefined;
|
|
125
132
|
readonly reasoning_content?: string | undefined;
|
|
126
133
|
readonly reasoning?: string | undefined;
|
|
127
134
|
readonly reasoning_text?: string | undefined;
|
|
128
135
|
readonly reasoning_details?: unknown;
|
|
129
136
|
})[];
|
|
130
|
-
readonly tools?: readonly {
|
|
137
|
+
readonly tools?: readonly ({
|
|
131
138
|
readonly type: "function";
|
|
132
139
|
readonly function: {
|
|
133
140
|
readonly name: string;
|
|
@@ -141,12 +148,36 @@ export declare const protocol: Protocol<{
|
|
|
141
148
|
readonly type: "ephemeral";
|
|
142
149
|
readonly ttl?: string | undefined;
|
|
143
150
|
} | undefined;
|
|
144
|
-
}
|
|
151
|
+
} | {
|
|
152
|
+
readonly type: "custom";
|
|
153
|
+
readonly custom: {
|
|
154
|
+
readonly name: string;
|
|
155
|
+
readonly description: string;
|
|
156
|
+
readonly format: {
|
|
157
|
+
readonly type: "text";
|
|
158
|
+
} | {
|
|
159
|
+
readonly type: "grammar";
|
|
160
|
+
readonly grammar: {
|
|
161
|
+
readonly syntax: "lark" | "regex";
|
|
162
|
+
readonly definition: string;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
readonly cache_control?: {
|
|
167
|
+
readonly type: "ephemeral";
|
|
168
|
+
readonly ttl?: string | undefined;
|
|
169
|
+
} | undefined;
|
|
170
|
+
})[] | undefined;
|
|
145
171
|
readonly tool_choice?: "auto" | "none" | "required" | {
|
|
146
172
|
readonly type: "function";
|
|
147
173
|
readonly function: {
|
|
148
174
|
readonly name: string;
|
|
149
175
|
};
|
|
176
|
+
} | {
|
|
177
|
+
readonly type: "custom";
|
|
178
|
+
readonly custom: {
|
|
179
|
+
readonly name: string;
|
|
180
|
+
};
|
|
150
181
|
} | undefined;
|
|
151
182
|
readonly stream: true;
|
|
152
183
|
readonly stream_options?: {
|
|
@@ -215,6 +246,10 @@ export declare const protocol: Protocol<{
|
|
|
215
246
|
readonly name?: string | null | undefined;
|
|
216
247
|
readonly arguments?: string | null | undefined;
|
|
217
248
|
} | null | undefined;
|
|
249
|
+
readonly custom?: {
|
|
250
|
+
readonly name?: string | null | undefined;
|
|
251
|
+
readonly input?: string | null | undefined;
|
|
252
|
+
} | null | undefined;
|
|
218
253
|
readonly extra_content?: unknown;
|
|
219
254
|
}[] | null | undefined;
|
|
220
255
|
} | null | undefined;
|
|
@@ -26,7 +26,7 @@ export declare const protocol: Protocol<{
|
|
|
26
26
|
readonly role: "developer";
|
|
27
27
|
readonly content: string;
|
|
28
28
|
} | {
|
|
29
|
-
readonly type: "function_call_output";
|
|
29
|
+
readonly type: "custom_tool_call_output" | "function_call_output";
|
|
30
30
|
readonly call_id: string;
|
|
31
31
|
readonly output: string | readonly ({
|
|
32
32
|
readonly type: "input_text";
|
|
@@ -96,6 +96,12 @@ export declare const protocol: Protocol<{
|
|
|
96
96
|
readonly name: string;
|
|
97
97
|
readonly namespace?: string | undefined;
|
|
98
98
|
readonly arguments: string;
|
|
99
|
+
} | {
|
|
100
|
+
readonly type: "custom_tool_call";
|
|
101
|
+
readonly id?: string | undefined;
|
|
102
|
+
readonly call_id: string;
|
|
103
|
+
readonly name: string;
|
|
104
|
+
readonly input: string;
|
|
99
105
|
} | {
|
|
100
106
|
readonly [x: string]: unknown;
|
|
101
107
|
readonly type: "web_search_call";
|
|
@@ -140,6 +146,17 @@ export declare const protocol: Protocol<{
|
|
|
140
146
|
})[];
|
|
141
147
|
readonly instructions?: string | undefined;
|
|
142
148
|
readonly tools?: readonly ({
|
|
149
|
+
readonly type: "custom";
|
|
150
|
+
readonly name: string;
|
|
151
|
+
readonly description: string;
|
|
152
|
+
readonly format: {
|
|
153
|
+
readonly type: "text";
|
|
154
|
+
} | {
|
|
155
|
+
readonly type: "grammar";
|
|
156
|
+
readonly syntax: "lark" | "regex";
|
|
157
|
+
readonly definition: string;
|
|
158
|
+
};
|
|
159
|
+
} | {
|
|
143
160
|
readonly type: "function";
|
|
144
161
|
readonly name: string;
|
|
145
162
|
readonly description: string;
|
|
@@ -152,13 +169,13 @@ export declare const protocol: Protocol<{
|
|
|
152
169
|
readonly type: string;
|
|
153
170
|
})[] | undefined;
|
|
154
171
|
readonly tool_choice?: "auto" | "none" | "required" | {
|
|
155
|
-
readonly type: "function";
|
|
172
|
+
readonly type: "custom" | "function";
|
|
156
173
|
readonly name: string;
|
|
157
174
|
} | {
|
|
158
175
|
readonly type: "allowed_tools";
|
|
159
176
|
readonly mode: "auto" | "none" | "required";
|
|
160
177
|
readonly tools: readonly {
|
|
161
|
-
readonly type: "function";
|
|
178
|
+
readonly type: "custom" | "function";
|
|
162
179
|
readonly name: string;
|
|
163
180
|
}[];
|
|
164
181
|
} | undefined;
|
|
@@ -50,7 +50,9 @@ const GoogleImageResponse = Schema.Struct({
|
|
|
50
50
|
// ---------------------------------------------------------------------------
|
|
51
51
|
const generationConfig = (request) => {
|
|
52
52
|
const { thinkingLevel, includeThoughts, ...native } = request.providerOptions ?? {};
|
|
53
|
-
|
|
53
|
+
// Google names the half tier `512` and rejects `0.5K`.
|
|
54
|
+
const imageSize = request.resolution?.toUpperCase() === "0.5K" ? "512" : request.resolution?.toUpperCase();
|
|
55
|
+
const imageConfig = { aspectRatio: request.aspect, imageSize };
|
|
54
56
|
const thinkingConfig = { thinkingLevel, includeThoughts };
|
|
55
57
|
return (mergeJsonRecords({
|
|
56
58
|
responseModalities: ["IMAGE"],
|
|
@@ -40,7 +40,7 @@ export declare const protocol: Protocol<{
|
|
|
40
40
|
readonly role: "developer";
|
|
41
41
|
readonly content: string;
|
|
42
42
|
} | {
|
|
43
|
-
readonly type: "function_call_output";
|
|
43
|
+
readonly type: "custom_tool_call_output" | "function_call_output";
|
|
44
44
|
readonly call_id: string;
|
|
45
45
|
readonly output: string | readonly ({
|
|
46
46
|
readonly type: "input_text";
|
|
@@ -110,6 +110,12 @@ export declare const protocol: Protocol<{
|
|
|
110
110
|
readonly name: string;
|
|
111
111
|
readonly namespace?: string | undefined;
|
|
112
112
|
readonly arguments: string;
|
|
113
|
+
} | {
|
|
114
|
+
readonly type: "custom_tool_call";
|
|
115
|
+
readonly id?: string | undefined;
|
|
116
|
+
readonly call_id: string;
|
|
117
|
+
readonly name: string;
|
|
118
|
+
readonly input: string;
|
|
113
119
|
} | {
|
|
114
120
|
readonly [x: string]: unknown;
|
|
115
121
|
readonly type: "web_search_call";
|
|
@@ -154,6 +160,17 @@ export declare const protocol: Protocol<{
|
|
|
154
160
|
})[];
|
|
155
161
|
readonly instructions?: string | undefined;
|
|
156
162
|
readonly tools?: readonly ({
|
|
163
|
+
readonly type: "custom";
|
|
164
|
+
readonly name: string;
|
|
165
|
+
readonly description: string;
|
|
166
|
+
readonly format: {
|
|
167
|
+
readonly type: "text";
|
|
168
|
+
} | {
|
|
169
|
+
readonly type: "grammar";
|
|
170
|
+
readonly syntax: "lark" | "regex";
|
|
171
|
+
readonly definition: string;
|
|
172
|
+
};
|
|
173
|
+
} | {
|
|
157
174
|
readonly type: "function";
|
|
158
175
|
readonly name: string;
|
|
159
176
|
readonly description: string;
|
|
@@ -166,13 +183,13 @@ export declare const protocol: Protocol<{
|
|
|
166
183
|
readonly type: string;
|
|
167
184
|
})[] | undefined;
|
|
168
185
|
readonly tool_choice?: "auto" | "none" | "required" | {
|
|
169
|
-
readonly type: "function";
|
|
186
|
+
readonly type: "custom" | "function";
|
|
170
187
|
readonly name: string;
|
|
171
188
|
} | {
|
|
172
189
|
readonly type: "allowed_tools";
|
|
173
190
|
readonly mode: "auto" | "none" | "required";
|
|
174
191
|
readonly tools: readonly {
|
|
175
|
-
readonly type: "function";
|
|
192
|
+
readonly type: "custom" | "function";
|
|
176
193
|
readonly name: string;
|
|
177
194
|
}[];
|
|
178
195
|
} | undefined;
|
|
@@ -279,7 +296,7 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
|
|
|
279
296
|
readonly role: "developer";
|
|
280
297
|
readonly content: string;
|
|
281
298
|
} | {
|
|
282
|
-
readonly type: "function_call_output";
|
|
299
|
+
readonly type: "custom_tool_call_output" | "function_call_output";
|
|
283
300
|
readonly call_id: string;
|
|
284
301
|
readonly output: string | readonly ({
|
|
285
302
|
readonly type: "input_text";
|
|
@@ -349,6 +366,12 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
|
|
|
349
366
|
readonly name: string;
|
|
350
367
|
readonly namespace?: string | undefined;
|
|
351
368
|
readonly arguments: string;
|
|
369
|
+
} | {
|
|
370
|
+
readonly type: "custom_tool_call";
|
|
371
|
+
readonly id?: string | undefined;
|
|
372
|
+
readonly call_id: string;
|
|
373
|
+
readonly name: string;
|
|
374
|
+
readonly input: string;
|
|
352
375
|
} | {
|
|
353
376
|
readonly [x: string]: unknown;
|
|
354
377
|
readonly type: "web_search_call";
|
|
@@ -393,6 +416,17 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
|
|
|
393
416
|
})[];
|
|
394
417
|
readonly instructions?: string | undefined;
|
|
395
418
|
readonly tools?: readonly ({
|
|
419
|
+
readonly type: "custom";
|
|
420
|
+
readonly name: string;
|
|
421
|
+
readonly description: string;
|
|
422
|
+
readonly format: {
|
|
423
|
+
readonly type: "text";
|
|
424
|
+
} | {
|
|
425
|
+
readonly type: "grammar";
|
|
426
|
+
readonly syntax: "lark" | "regex";
|
|
427
|
+
readonly definition: string;
|
|
428
|
+
};
|
|
429
|
+
} | {
|
|
396
430
|
readonly type: "function";
|
|
397
431
|
readonly name: string;
|
|
398
432
|
readonly description: string;
|
|
@@ -405,13 +439,13 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
|
|
|
405
439
|
readonly type: string;
|
|
406
440
|
})[] | undefined;
|
|
407
441
|
readonly tool_choice?: "auto" | "none" | "required" | {
|
|
408
|
-
readonly type: "function";
|
|
442
|
+
readonly type: "custom" | "function";
|
|
409
443
|
readonly name: string;
|
|
410
444
|
} | {
|
|
411
445
|
readonly type: "allowed_tools";
|
|
412
446
|
readonly mode: "auto" | "none" | "required";
|
|
413
447
|
readonly tools: readonly {
|
|
414
|
-
readonly type: "function";
|
|
448
|
+
readonly type: "custom" | "function";
|
|
415
449
|
readonly name: string;
|
|
416
450
|
}[];
|
|
417
451
|
} | undefined;
|
|
@@ -97,7 +97,7 @@ const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
|
97
97
|
return { ...body, input };
|
|
98
98
|
});
|
|
99
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";
|
|
100
|
+
const isFunctionCallOutput = (item) => item.type === "function_call_output" || item.type === "custom_tool_call_output";
|
|
101
101
|
const HOSTED_TOOLS = {
|
|
102
102
|
web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
|
|
103
103
|
image_generation_call: {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { type OpenString } from "../schema/index.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://api.minimax.io/v1";
|
|
6
|
+
export declare const PATH = "/image_generation";
|
|
7
|
+
/** Provider-native options. Common `aspect` and `resolution` lower to `aspect_ratio` or `width` and `height`. */
|
|
8
|
+
export type MiniMaxImageOptions = {
|
|
9
|
+
/** Defaults to `base64`, which returns the bytes inline; `url` links expire after 24 hours. */
|
|
10
|
+
readonly responseFormat?: OpenString<"url" | "base64">;
|
|
11
|
+
readonly seed?: number;
|
|
12
|
+
readonly promptOptimizer?: boolean;
|
|
13
|
+
/** Native preset; it replaces `aspect` and `resolution`. */
|
|
14
|
+
readonly aspect_ratio?: string;
|
|
15
|
+
/** Native size, 512 to 2048 in steps of 8 (`image-01` only); it replaces `aspect` and `resolution`. */
|
|
16
|
+
readonly width?: number;
|
|
17
|
+
readonly height?: number;
|
|
18
|
+
} & Record<string, unknown>;
|
|
19
|
+
export type Request = ImageRequestFor<MiniMaxImageOptions>;
|
|
20
|
+
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
21
|
+
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<MiniMaxImageOptions>;
|
|
22
|
+
export declare const MiniMaxImages: {
|
|
23
|
+
readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
24
|
+
readonly model: typeof model;
|
|
25
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Duration, Effect, Schema } from "effect";
|
|
2
|
+
import { ImageModel, ImageResponse } from "../image.js";
|
|
3
|
+
import { Media } from "../media.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { MediaRoute } from "../route/media.js";
|
|
6
|
+
import { AIError, QuotaExceededError, mergeJsonRecords } from "../schema/index.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
import { ImageSizing } from "./utils/image-sizing.js";
|
|
9
|
+
import { MediaInput } from "./utils/media-input.js";
|
|
10
|
+
const route = MediaProtocol.identity({ id: "minimax-images", name: "MiniMax Images", provider: "minimax" });
|
|
11
|
+
export const DEFAULT_BASE_URL = "https://api.minimax.io/v1";
|
|
12
|
+
export const PATH = "/image_generation";
|
|
13
|
+
const OUTPUT_RETENTION = Duration.hours(24);
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// 2. Response schema
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
const MiniMaxImageResponse = Schema.Struct({
|
|
18
|
+
id: optionalNull(Schema.String),
|
|
19
|
+
data: optionalNull(Schema.Struct({
|
|
20
|
+
image_urls: optionalNull(Schema.Array(Schema.String)),
|
|
21
|
+
image_base64: optionalNull(Schema.Array(Schema.String)),
|
|
22
|
+
})),
|
|
23
|
+
metadata: optionalNull(Schema.Struct({
|
|
24
|
+
success_count: optionalNull(Schema.Union([Schema.Number, Schema.String])),
|
|
25
|
+
failed_count: optionalNull(Schema.Union([Schema.Number, Schema.String])),
|
|
26
|
+
})),
|
|
27
|
+
base_resp: optionalNull(Schema.Struct({
|
|
28
|
+
status_code: Schema.Number,
|
|
29
|
+
status_msg: optionalNull(Schema.String),
|
|
30
|
+
})),
|
|
31
|
+
});
|
|
32
|
+
const FAILURE = {
|
|
33
|
+
1002: "RateLimit",
|
|
34
|
+
1004: "Authentication",
|
|
35
|
+
2013: "InvalidRequest",
|
|
36
|
+
2049: "Authentication",
|
|
37
|
+
};
|
|
38
|
+
const INSUFFICIENT_BALANCE = 1008;
|
|
39
|
+
const CONTENT_POLICY = 1026;
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// 5. Request body construction
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
/** MiniMax's `aspect_ratio` presets and the sizes it renders them at. */
|
|
44
|
+
const PRESETS = {
|
|
45
|
+
"1:1": { width: 1024, height: 1024 },
|
|
46
|
+
"16:9": { width: 1280, height: 720 },
|
|
47
|
+
"4:3": { width: 1152, height: 864 },
|
|
48
|
+
"3:2": { width: 1248, height: 832 },
|
|
49
|
+
"2:3": { width: 832, height: 1248 },
|
|
50
|
+
"3:4": { width: 864, height: 1152 },
|
|
51
|
+
"9:16": { width: 720, height: 1280 },
|
|
52
|
+
"21:9": { width: 1344, height: 576 },
|
|
53
|
+
};
|
|
54
|
+
const LIMITS = { multiple: 8, minEdge: 512, maxEdge: 2048 };
|
|
55
|
+
const nativeOptions = (options = {}) => {
|
|
56
|
+
const { responseFormat, promptOptimizer, ...native } = options;
|
|
57
|
+
return { response_format: responseFormat ?? "base64", prompt_optimizer: promptOptimizer, ...native };
|
|
58
|
+
};
|
|
59
|
+
/** `image-01-live` rejects `21:9`. */
|
|
60
|
+
const presets = (model) => model === "image-01" ? PRESETS : Object.fromEntries(Object.entries(PRESETS).filter(([key]) => key !== "21:9"));
|
|
61
|
+
/** Presets render at about 1K, so they serve a preset aspect with no resolution or `1K`. */
|
|
62
|
+
const preset = (request) => {
|
|
63
|
+
const aspect = request.aspect ?? "1:1";
|
|
64
|
+
if (!Object.hasOwn(presets(request.model.id), aspect))
|
|
65
|
+
return undefined;
|
|
66
|
+
if (request.resolution !== undefined && ImageSizing.tier(request.resolution) !== 1)
|
|
67
|
+
return undefined;
|
|
68
|
+
return aspect;
|
|
69
|
+
};
|
|
70
|
+
/** Only `image-01` takes free `width` and `height`; other models render the presets alone. */
|
|
71
|
+
const sizing = (request) => {
|
|
72
|
+
if (!ImageSizing.isRequested(request))
|
|
73
|
+
return Effect.succeed({});
|
|
74
|
+
const aspect = preset(request);
|
|
75
|
+
if (aspect !== undefined)
|
|
76
|
+
return Effect.succeed({ aspect_ratio: aspect });
|
|
77
|
+
if (request.model.id === "image-01")
|
|
78
|
+
return ImageSizing.exact(route, request, LIMITS);
|
|
79
|
+
const available = presets(request.model.id);
|
|
80
|
+
const closest = ImageSizing.nearest(request, Object.values(available));
|
|
81
|
+
const name = Object.keys(available).find((key) => available[key] === closest);
|
|
82
|
+
return Effect.fail(route.unsupported(request.resolution === undefined ? "media.aspect" : "media.resolution", `${request.model.id} can't render ${[request.aspect, request.resolution].filter((value) => value !== undefined).join(" at ")}; the closest size it takes is ${closest.width}x${closest.height} (${name}). Change aspect or resolution, or set aspect_ratio in providerOptions`));
|
|
83
|
+
};
|
|
84
|
+
const isNativeSize = (options) => options?.aspect_ratio !== undefined || options?.width !== undefined || options?.height !== undefined;
|
|
85
|
+
// The API only takes a `character` (portrait) subject, one per request.
|
|
86
|
+
const subject = (asset) => ProviderShared.mediaReference(asset, undefined, `${route.name} input`).pipe(Effect.map((item) => ({ type: "character", image_file: item.value })));
|
|
87
|
+
const fromRequest = Effect.fn("MiniMaxImages.fromRequest")(function* (request) {
|
|
88
|
+
if ((request.images?.length ?? 0) > 1)
|
|
89
|
+
return yield* route.unsupported("media.images", `${route.name} takes one subject reference image`);
|
|
90
|
+
if (isNativeSize(request.providerOptions) && ImageSizing.isRequested(request))
|
|
91
|
+
return yield* ProviderShared.invalidRequest("MiniMax providerOptions aspect_ratio, width and height replace aspect and resolution; set one or the other");
|
|
92
|
+
const references = yield* Effect.forEach(request.images ?? [], subject);
|
|
93
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
94
|
+
model: request.model.id,
|
|
95
|
+
prompt: request.prompt,
|
|
96
|
+
subject_reference: references.length === 0 ? undefined : references,
|
|
97
|
+
n: request.n,
|
|
98
|
+
...(yield* sizing(request)),
|
|
99
|
+
}, nativeOptions(request.providerOptions), request.http?.body) ?? {});
|
|
100
|
+
});
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// 6. Response decoding
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
const decodeDocument = route.decodeJson(MiniMaxImageResponse);
|
|
105
|
+
const decodeResponse = Effect.fn("MiniMaxImages.decodeResponse")(function* (response) {
|
|
106
|
+
const output = yield* decodeDocument(response);
|
|
107
|
+
const decoded = output.value;
|
|
108
|
+
// MiniMax answers errors with HTTP 200 and a non-zero `base_resp.status_code`.
|
|
109
|
+
const status = decoded.base_resp;
|
|
110
|
+
if (status && status.status_code !== 0) {
|
|
111
|
+
const message = `${route.name} failed (${status.status_code}): ${status.status_msg ?? "unknown error"}`;
|
|
112
|
+
if (status.status_code === CONTENT_POLICY)
|
|
113
|
+
return yield* output.contentPolicy(message);
|
|
114
|
+
if (status.status_code === INSUFFICIENT_BALANCE)
|
|
115
|
+
return yield* new AIError({ reason: new QuotaExceededError({ message, body: output.body, http: output.http }) });
|
|
116
|
+
return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, status.status_code));
|
|
117
|
+
}
|
|
118
|
+
const images = [
|
|
119
|
+
...(yield* Effect.forEach(decoded.data?.image_base64 ?? [], (data, index) => MediaInput.decodedAsset(output.invalid, `${route.name} result ${index}`, data, undefined))),
|
|
120
|
+
// MiniMax returns no content type for URLs; the media type resolves when the asset is materialized.
|
|
121
|
+
...(yield* Effect.forEach(decoded.data?.image_urls ?? [], (url) => MediaProtocol.expiringUrl(url, OUTPUT_RETENTION))),
|
|
122
|
+
];
|
|
123
|
+
const failed = Number(decoded.metadata?.failed_count ?? 0);
|
|
124
|
+
if (images.length === 0 && failed > 0)
|
|
125
|
+
return yield* output.contentPolicy(`${route.name} blocked ${failed} image(s) for content safety`);
|
|
126
|
+
if (images.length === 0)
|
|
127
|
+
return yield* output.invalid(`${route.name} returned no images`);
|
|
128
|
+
return new ImageResponse({
|
|
129
|
+
images,
|
|
130
|
+
providerMetadata: {
|
|
131
|
+
minimax: {
|
|
132
|
+
id: decoded.id ?? undefined,
|
|
133
|
+
successCount: decoded.metadata?.success_count ?? undefined,
|
|
134
|
+
failedCount: decoded.metadata?.failed_count ?? undefined,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// 7. Protocol and route
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
export const protocol = MediaProtocol.inline(route, {
|
|
143
|
+
body: { from: fromRequest },
|
|
144
|
+
response: { decode: decodeResponse },
|
|
145
|
+
});
|
|
146
|
+
export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
147
|
+
export const MiniMaxImages = {
|
|
148
|
+
protocol,
|
|
149
|
+
model,
|
|
150
|
+
};
|