@opencode-ai/ai 0.0.0-next-15825 → 0.0.0-next-15830
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 +43 -2
- package/dist/image-client.d.ts +19 -0
- package/dist/image-client.js +19 -0
- package/dist/image.d.ts +78 -0
- package/dist/image.js +77 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/index.js +1 -0
- package/dist/protocols/openai-compatible-responses.d.ts +14 -2
- package/dist/protocols/openai-images.d.ts +36 -0
- package/dist/protocols/openai-images.js +145 -0
- package/dist/protocols/openai-responses.d.ts +100 -14
- package/dist/protocols/openai-responses.js +73 -19
- package/dist/protocols/utils/openai-image.d.ts +5 -0
- package/dist/protocols/utils/openai-image.js +18 -0
- package/dist/providers/azure.d.ts +14 -2
- package/dist/providers/github-copilot.d.ts +14 -2
- package/dist/providers/google-vertex-responses.d.ts +14 -2
- package/dist/providers/openai-compatible-responses.d.ts +14 -2
- package/dist/providers/openai.d.ts +50 -5
- package/dist/providers/openai.js +33 -2
- package/dist/providers/xai.d.ts +14 -2
- package/dist/route/auth.d.ts +4 -2
- package/package.json +3 -3
|
@@ -55,16 +55,28 @@ declare const OpenAIResponsesBody: Schema.Struct<{
|
|
|
55
55
|
}>]>>]>;
|
|
56
56
|
}>]>>;
|
|
57
57
|
readonly instructions: Schema.optional<Schema.String>;
|
|
58
|
-
readonly tools: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
58
|
+
readonly tools: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
59
59
|
readonly type: Schema.tag<"function">;
|
|
60
60
|
readonly name: Schema.String;
|
|
61
61
|
readonly description: Schema.String;
|
|
62
62
|
readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
63
63
|
readonly strict: Schema.optional<Schema.Boolean>;
|
|
64
|
-
}
|
|
64
|
+
}>, Schema.Struct<{
|
|
65
|
+
readonly type: Schema.tag<"image_generation">;
|
|
66
|
+
readonly action: Schema.optional<Schema.Literals<readonly ["auto", "generate", "edit"]>>;
|
|
67
|
+
readonly background: Schema.optional<Schema.Literals<readonly ["auto", "opaque", "transparent"]>>;
|
|
68
|
+
readonly input_fidelity: Schema.optional<Schema.Literals<readonly ["low", "high"]>>;
|
|
69
|
+
readonly output_compression: Schema.optional<Schema.Int>;
|
|
70
|
+
readonly output_format: Schema.optional<Schema.Literals<readonly ["png", "jpeg", "webp"]>>;
|
|
71
|
+
readonly partial_images: Schema.optional<Schema.Int>;
|
|
72
|
+
readonly quality: Schema.optional<Schema.Literals<readonly ["auto", "low", "medium", "high"]>>;
|
|
73
|
+
readonly size: Schema.optional<Schema.String>;
|
|
74
|
+
}>]>>>;
|
|
65
75
|
readonly tool_choice: Schema.optional<Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
|
|
66
76
|
readonly type: Schema.tag<"function">;
|
|
67
77
|
readonly name: Schema.String;
|
|
78
|
+
}>, Schema.Struct<{
|
|
79
|
+
readonly type: Schema.tag<"image_generation">;
|
|
68
80
|
}>]>>;
|
|
69
81
|
readonly store: Schema.optional<Schema.Boolean>;
|
|
70
82
|
readonly service_tier: Schema.optional<Schema.Literals<readonly ["auto", "default", "flex", "priority"]>>;
|
|
@@ -142,7 +154,7 @@ export declare const protocol: Protocol<{
|
|
|
142
154
|
readonly effort?: string | undefined;
|
|
143
155
|
readonly summary?: "auto" | undefined;
|
|
144
156
|
} | undefined;
|
|
145
|
-
readonly tools?: readonly {
|
|
157
|
+
readonly tools?: readonly ({
|
|
146
158
|
readonly type: "function";
|
|
147
159
|
readonly name: string;
|
|
148
160
|
readonly description: string;
|
|
@@ -150,11 +162,23 @@ export declare const protocol: Protocol<{
|
|
|
150
162
|
readonly [x: string]: unknown;
|
|
151
163
|
};
|
|
152
164
|
readonly strict?: boolean | undefined;
|
|
153
|
-
}
|
|
165
|
+
} | {
|
|
166
|
+
readonly type: "image_generation";
|
|
167
|
+
readonly size?: string | undefined;
|
|
168
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
169
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
170
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
171
|
+
readonly output_compression?: number | undefined;
|
|
172
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
173
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
174
|
+
readonly partial_images?: number | undefined;
|
|
175
|
+
})[] | undefined;
|
|
154
176
|
readonly temperature?: number | undefined;
|
|
155
177
|
readonly tool_choice?: "required" | "none" | "auto" | Schema.Struct.ReadonlySide<{
|
|
156
178
|
readonly type: Schema.tag<"function">;
|
|
157
179
|
readonly name: Schema.String;
|
|
180
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
181
|
+
readonly type: Schema.tag<"image_generation">;
|
|
158
182
|
}, "Type"> | undefined;
|
|
159
183
|
readonly top_p?: number | undefined;
|
|
160
184
|
readonly store?: boolean | undefined;
|
|
@@ -201,10 +225,12 @@ export declare const protocol: Protocol<{
|
|
|
201
225
|
readonly error?: unknown;
|
|
202
226
|
readonly name?: string | undefined;
|
|
203
227
|
readonly id?: string | undefined;
|
|
228
|
+
readonly result?: string | undefined;
|
|
204
229
|
readonly status?: string | undefined;
|
|
205
230
|
readonly output?: unknown;
|
|
206
231
|
readonly code?: string | undefined;
|
|
207
232
|
readonly arguments?: string | undefined;
|
|
233
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
208
234
|
readonly encrypted_content?: string | null | undefined;
|
|
209
235
|
readonly call_id?: string | undefined;
|
|
210
236
|
readonly action?: unknown;
|
|
@@ -280,7 +306,7 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
280
306
|
readonly effort?: string | undefined;
|
|
281
307
|
readonly summary?: "auto" | undefined;
|
|
282
308
|
} | undefined;
|
|
283
|
-
readonly tools?: readonly {
|
|
309
|
+
readonly tools?: readonly ({
|
|
284
310
|
readonly type: "function";
|
|
285
311
|
readonly name: string;
|
|
286
312
|
readonly description: string;
|
|
@@ -288,11 +314,23 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
288
314
|
readonly [x: string]: unknown;
|
|
289
315
|
};
|
|
290
316
|
readonly strict?: boolean | undefined;
|
|
291
|
-
}
|
|
317
|
+
} | {
|
|
318
|
+
readonly type: "image_generation";
|
|
319
|
+
readonly size?: string | undefined;
|
|
320
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
321
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
322
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
323
|
+
readonly output_compression?: number | undefined;
|
|
324
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
325
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
326
|
+
readonly partial_images?: number | undefined;
|
|
327
|
+
})[] | undefined;
|
|
292
328
|
readonly temperature?: number | undefined;
|
|
293
329
|
readonly tool_choice?: "required" | "none" | "auto" | Schema.Struct.ReadonlySide<{
|
|
294
330
|
readonly type: Schema.tag<"function">;
|
|
295
331
|
readonly name: Schema.String;
|
|
332
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
333
|
+
readonly type: Schema.tag<"image_generation">;
|
|
296
334
|
}, "Type"> | undefined;
|
|
297
335
|
readonly top_p?: number | undefined;
|
|
298
336
|
readonly store?: boolean | undefined;
|
|
@@ -357,7 +395,7 @@ export declare const route: Route<{
|
|
|
357
395
|
readonly effort?: string | undefined;
|
|
358
396
|
readonly summary?: "auto" | undefined;
|
|
359
397
|
} | undefined;
|
|
360
|
-
readonly tools?: readonly {
|
|
398
|
+
readonly tools?: readonly ({
|
|
361
399
|
readonly type: "function";
|
|
362
400
|
readonly name: string;
|
|
363
401
|
readonly description: string;
|
|
@@ -365,11 +403,23 @@ export declare const route: Route<{
|
|
|
365
403
|
readonly [x: string]: unknown;
|
|
366
404
|
};
|
|
367
405
|
readonly strict?: boolean | undefined;
|
|
368
|
-
}
|
|
406
|
+
} | {
|
|
407
|
+
readonly type: "image_generation";
|
|
408
|
+
readonly size?: string | undefined;
|
|
409
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
410
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
411
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
412
|
+
readonly output_compression?: number | undefined;
|
|
413
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
414
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
415
|
+
readonly partial_images?: number | undefined;
|
|
416
|
+
})[] | undefined;
|
|
369
417
|
readonly temperature?: number | undefined;
|
|
370
418
|
readonly tool_choice?: "required" | "none" | "auto" | Schema.Struct.ReadonlySide<{
|
|
371
419
|
readonly type: Schema.tag<"function">;
|
|
372
420
|
readonly name: Schema.String;
|
|
421
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
422
|
+
readonly type: Schema.tag<"image_generation">;
|
|
373
423
|
}, "Type"> | undefined;
|
|
374
424
|
readonly top_p?: number | undefined;
|
|
375
425
|
readonly store?: boolean | undefined;
|
|
@@ -434,7 +484,7 @@ export declare const webSocketTransport: import("../route/transport/websocket").
|
|
|
434
484
|
readonly effort?: string | undefined;
|
|
435
485
|
readonly summary?: "auto" | undefined;
|
|
436
486
|
} | undefined;
|
|
437
|
-
readonly tools?: readonly {
|
|
487
|
+
readonly tools?: readonly ({
|
|
438
488
|
readonly type: "function";
|
|
439
489
|
readonly name: string;
|
|
440
490
|
readonly description: string;
|
|
@@ -442,11 +492,23 @@ export declare const webSocketTransport: import("../route/transport/websocket").
|
|
|
442
492
|
readonly [x: string]: unknown;
|
|
443
493
|
};
|
|
444
494
|
readonly strict?: boolean | undefined;
|
|
445
|
-
}
|
|
495
|
+
} | {
|
|
496
|
+
readonly type: "image_generation";
|
|
497
|
+
readonly size?: string | undefined;
|
|
498
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
499
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
500
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
501
|
+
readonly output_compression?: number | undefined;
|
|
502
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
503
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
504
|
+
readonly partial_images?: number | undefined;
|
|
505
|
+
})[] | undefined;
|
|
446
506
|
readonly temperature?: number | undefined;
|
|
447
507
|
readonly tool_choice?: "required" | "none" | "auto" | Schema.Struct.ReadonlySide<{
|
|
448
508
|
readonly type: Schema.tag<"function">;
|
|
449
509
|
readonly name: Schema.String;
|
|
510
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
511
|
+
readonly type: Schema.tag<"image_generation">;
|
|
450
512
|
}, "Type"> | undefined;
|
|
451
513
|
readonly top_p?: number | undefined;
|
|
452
514
|
readonly store?: boolean | undefined;
|
|
@@ -511,7 +573,7 @@ export declare const webSocketTransport: import("../route/transport/websocket").
|
|
|
511
573
|
readonly effort?: string | undefined;
|
|
512
574
|
readonly summary?: "auto" | undefined;
|
|
513
575
|
} | undefined;
|
|
514
|
-
readonly tools?: readonly {
|
|
576
|
+
readonly tools?: readonly ({
|
|
515
577
|
readonly type: "function";
|
|
516
578
|
readonly name: string;
|
|
517
579
|
readonly description: string;
|
|
@@ -519,11 +581,23 @@ export declare const webSocketTransport: import("../route/transport/websocket").
|
|
|
519
581
|
readonly [x: string]: unknown;
|
|
520
582
|
};
|
|
521
583
|
readonly strict?: boolean | undefined;
|
|
522
|
-
}
|
|
584
|
+
} | {
|
|
585
|
+
readonly type: "image_generation";
|
|
586
|
+
readonly size?: string | undefined;
|
|
587
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
588
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
589
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
590
|
+
readonly output_compression?: number | undefined;
|
|
591
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
592
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
593
|
+
readonly partial_images?: number | undefined;
|
|
594
|
+
})[] | undefined;
|
|
523
595
|
readonly temperature?: number | undefined;
|
|
524
596
|
readonly tool_choice?: "required" | "none" | "auto" | Schema.Struct.ReadonlySide<{
|
|
525
597
|
readonly type: Schema.tag<"function">;
|
|
526
598
|
readonly name: Schema.String;
|
|
599
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
600
|
+
readonly type: Schema.tag<"image_generation">;
|
|
527
601
|
}, "Type"> | undefined;
|
|
528
602
|
readonly top_p?: number | undefined;
|
|
529
603
|
readonly store?: boolean | undefined;
|
|
@@ -588,7 +662,7 @@ export declare const webSocketRoute: Route<{
|
|
|
588
662
|
readonly effort?: string | undefined;
|
|
589
663
|
readonly summary?: "auto" | undefined;
|
|
590
664
|
} | undefined;
|
|
591
|
-
readonly tools?: readonly {
|
|
665
|
+
readonly tools?: readonly ({
|
|
592
666
|
readonly type: "function";
|
|
593
667
|
readonly name: string;
|
|
594
668
|
readonly description: string;
|
|
@@ -596,11 +670,23 @@ export declare const webSocketRoute: Route<{
|
|
|
596
670
|
readonly [x: string]: unknown;
|
|
597
671
|
};
|
|
598
672
|
readonly strict?: boolean | undefined;
|
|
599
|
-
}
|
|
673
|
+
} | {
|
|
674
|
+
readonly type: "image_generation";
|
|
675
|
+
readonly size?: string | undefined;
|
|
676
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
677
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
678
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
679
|
+
readonly output_compression?: number | undefined;
|
|
680
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
681
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
682
|
+
readonly partial_images?: number | undefined;
|
|
683
|
+
})[] | undefined;
|
|
600
684
|
readonly temperature?: number | undefined;
|
|
601
685
|
readonly tool_choice?: "required" | "none" | "auto" | Schema.Struct.ReadonlySide<{
|
|
602
686
|
readonly type: Schema.tag<"function">;
|
|
603
687
|
readonly name: Schema.String;
|
|
688
|
+
}, "Type"> | Schema.Struct.ReadonlySide<{
|
|
689
|
+
readonly type: Schema.tag<"image_generation">;
|
|
604
690
|
}, "Type"> | undefined;
|
|
605
691
|
readonly top_p?: number | undefined;
|
|
606
692
|
readonly store?: boolean | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Effect, Encoding, Schema } from "effect";
|
|
2
2
|
import { Route } from "../route/client";
|
|
3
3
|
import { Auth } from "../route/auth";
|
|
4
4
|
import { Endpoint } from "../route/endpoint";
|
|
@@ -11,6 +11,7 @@ import { OpenAIOptions } from "./utils/openai-options";
|
|
|
11
11
|
import { Lifecycle } from "./utils/lifecycle";
|
|
12
12
|
import { ToolSchemaProjection } from "./utils/tool-schema";
|
|
13
13
|
import { ToolStream } from "./utils/tool-stream";
|
|
14
|
+
import { OpenAIImage } from "./utils/openai-image";
|
|
14
15
|
const ADAPTER = "openai-responses";
|
|
15
16
|
export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
16
17
|
export const PATH = "/responses";
|
|
@@ -77,9 +78,22 @@ const OpenAIResponsesTool = Schema.Struct({
|
|
|
77
78
|
parameters: JsonObject,
|
|
78
79
|
strict: Schema.optional(Schema.Boolean),
|
|
79
80
|
});
|
|
81
|
+
const OpenAIResponsesImageGenerationTool = Schema.Struct({
|
|
82
|
+
type: Schema.tag("image_generation"),
|
|
83
|
+
action: Schema.optional(Schema.Literals(["auto", "generate", "edit"])),
|
|
84
|
+
background: Schema.optional(Schema.Literals(["auto", "opaque", "transparent"])),
|
|
85
|
+
input_fidelity: Schema.optional(Schema.Literals(["low", "high"])),
|
|
86
|
+
output_compression: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 100 }))),
|
|
87
|
+
output_format: Schema.optional(Schema.Literals(["png", "jpeg", "webp"])),
|
|
88
|
+
partial_images: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
|
|
89
|
+
quality: Schema.optional(Schema.Literals(["auto", "low", "medium", "high"])),
|
|
90
|
+
size: Schema.optional(OpenAIImage.Size),
|
|
91
|
+
});
|
|
92
|
+
const OpenAIResponsesTools = Schema.Union([OpenAIResponsesTool, OpenAIResponsesImageGenerationTool]);
|
|
80
93
|
const OpenAIResponsesToolChoice = Schema.Union([
|
|
81
94
|
Schema.Literals(["auto", "none", "required"]),
|
|
82
95
|
Schema.Struct({ type: Schema.tag("function"), name: Schema.String }),
|
|
96
|
+
Schema.Struct({ type: Schema.tag("image_generation") }),
|
|
83
97
|
]);
|
|
84
98
|
// Fields shared between the HTTP body and the WebSocket `response.create`
|
|
85
99
|
// message. The HTTP body adds `stream: true`; the WebSocket message adds
|
|
@@ -89,7 +103,7 @@ const OpenAIResponsesCoreFields = {
|
|
|
89
103
|
model: Schema.String,
|
|
90
104
|
input: Schema.Array(OpenAIResponsesInputItem),
|
|
91
105
|
instructions: Schema.optional(Schema.String),
|
|
92
|
-
tools: optionalArray(
|
|
106
|
+
tools: optionalArray(OpenAIResponsesTools),
|
|
93
107
|
tool_choice: Schema.optional(OpenAIResponsesToolChoice),
|
|
94
108
|
store: Schema.optional(Schema.Boolean),
|
|
95
109
|
service_tier: Schema.optional(OpenAIOptions.OpenAIServiceTier),
|
|
@@ -141,6 +155,8 @@ const OpenAIResponsesStreamItem = Schema.Struct({
|
|
|
141
155
|
outputs: Schema.optional(Schema.Unknown),
|
|
142
156
|
server_label: Schema.optional(Schema.String),
|
|
143
157
|
output: Schema.optional(Schema.Unknown),
|
|
158
|
+
result: Schema.optional(Schema.String),
|
|
159
|
+
output_format: Schema.optional(Schema.Literals(["png", "jpeg", "webp"])),
|
|
144
160
|
error: Schema.optional(Schema.Unknown),
|
|
145
161
|
encrypted_content: optionalNull(Schema.String),
|
|
146
162
|
});
|
|
@@ -176,19 +192,37 @@ const invalid = ProviderShared.invalidRequest;
|
|
|
176
192
|
// =============================================================================
|
|
177
193
|
// Request Lowering
|
|
178
194
|
// =============================================================================
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
195
|
+
const nativeImageToolInput = (tool) => {
|
|
196
|
+
const native = tool.native?.openai;
|
|
197
|
+
return ProviderShared.isRecord(native) && native.type === "image_generation" ? native : undefined;
|
|
198
|
+
};
|
|
199
|
+
const nativeImageTool = (tool) => {
|
|
200
|
+
const native = nativeImageToolInput(tool);
|
|
201
|
+
return Schema.is(OpenAIResponsesImageGenerationTool)(native) ? native : undefined;
|
|
202
|
+
};
|
|
203
|
+
const lowerTool = Effect.fn("OpenAIResponses.lowerTool")(function* (tool, inputSchema) {
|
|
204
|
+
const native = nativeImageToolInput(tool);
|
|
205
|
+
if (native !== undefined) {
|
|
206
|
+
if (Schema.is(OpenAIResponsesImageGenerationTool)(native))
|
|
207
|
+
return native;
|
|
208
|
+
return yield* invalid("OpenAI Responses image generation tool options are invalid");
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
type: "function",
|
|
212
|
+
name: tool.name,
|
|
213
|
+
description: tool.description,
|
|
214
|
+
parameters: ToolSchemaProjection.openAI(inputSchema),
|
|
215
|
+
// TODO: Read this from OpenAI-specific tool options so direct LLM callers can opt into strict schemas.
|
|
216
|
+
strict: false,
|
|
217
|
+
};
|
|
186
218
|
});
|
|
187
|
-
const lowerToolChoice = (toolChoice) => ProviderShared.matchToolChoice("OpenAI Responses", toolChoice, {
|
|
219
|
+
const lowerToolChoice = (toolChoice, tools) => ProviderShared.matchToolChoice("OpenAI Responses", toolChoice, {
|
|
188
220
|
auto: () => "auto",
|
|
189
221
|
none: () => "none",
|
|
190
222
|
required: () => "required",
|
|
191
|
-
tool: (name) => (
|
|
223
|
+
tool: (name) => tools.some((tool) => tool.name === name && nativeImageTool(tool) !== undefined)
|
|
224
|
+
? { type: "image_generation" }
|
|
225
|
+
: { type: "function", name },
|
|
192
226
|
});
|
|
193
227
|
const lowerToolCall = (part) => ({
|
|
194
228
|
type: "function_call",
|
|
@@ -320,6 +354,13 @@ const lowerMessages = Effect.fn("OpenAIResponses.lowerMessages")(function* (requ
|
|
|
320
354
|
const itemID = hostedToolItemID(part);
|
|
321
355
|
if (store !== false && itemID && !hostedToolReferences.has(itemID))
|
|
322
356
|
input.push({ type: "item_reference", id: itemID });
|
|
357
|
+
if (store === false && part.name === "image_generation" && part.result.type === "content") {
|
|
358
|
+
const content = part.result.value;
|
|
359
|
+
input.push({
|
|
360
|
+
role: "user",
|
|
361
|
+
content: yield* Effect.forEach(content, lowerToolResultContentItem),
|
|
362
|
+
});
|
|
363
|
+
}
|
|
323
364
|
if (itemID)
|
|
324
365
|
hostedToolReferences.add(itemID);
|
|
325
366
|
continue;
|
|
@@ -379,8 +420,8 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
|
|
|
379
420
|
input: yield* lowerMessages(request),
|
|
380
421
|
tools: request.tools.length === 0
|
|
381
422
|
? undefined
|
|
382
|
-
: request.tools
|
|
383
|
-
tool_choice: request.toolChoice ? yield* lowerToolChoice(request.toolChoice) : undefined,
|
|
423
|
+
: yield* Effect.forEach(request.tools, (tool) => lowerTool(tool, ToolSchemaProjection.modelCompatibility(tool.inputSchema, toolSchemaCompatibility))),
|
|
424
|
+
tool_choice: request.toolChoice ? yield* lowerToolChoice(request.toolChoice, request.tools) : undefined,
|
|
384
425
|
stream: true,
|
|
385
426
|
max_output_tokens: generation?.maxTokens,
|
|
386
427
|
temperature: generation?.temperature,
|
|
@@ -452,11 +493,24 @@ const isHostedToolItem = (item) => item.type in HOSTED_TOOLS && typeof item.id =
|
|
|
452
493
|
const isReasoningItem = (item) => item.type === "reasoning" && typeof item.id === "string" && item.id.length > 0;
|
|
453
494
|
// Round-trip the full item as the structured result so consumers can extract
|
|
454
495
|
// outputs / sources / status without re-decoding.
|
|
455
|
-
const hostedToolResult = (item)
|
|
496
|
+
const hostedToolResult = Effect.fn("OpenAIResponses.hostedToolResult")(function* (item) {
|
|
456
497
|
const isError = typeof item.error !== "undefined" && item.error !== null;
|
|
498
|
+
if (item.type === "image_generation_call" && item.result) {
|
|
499
|
+
yield* Effect.fromResult(Encoding.decodeBase64(item.result)).pipe(Effect.mapError(() => ProviderShared.eventError(ADAPTER, "OpenAI Responses returned invalid image base64")));
|
|
500
|
+
return {
|
|
501
|
+
type: "content",
|
|
502
|
+
value: [
|
|
503
|
+
{
|
|
504
|
+
type: "file",
|
|
505
|
+
uri: `data:image/${item.output_format ?? "png"};base64,${item.result}`,
|
|
506
|
+
mime: `image/${item.output_format ?? "png"}`,
|
|
507
|
+
},
|
|
508
|
+
],
|
|
509
|
+
};
|
|
510
|
+
}
|
|
457
511
|
return isError ? { type: "error", value: item.error } : { type: "json", value: item };
|
|
458
|
-
};
|
|
459
|
-
const hostedToolEvents = (item)
|
|
512
|
+
});
|
|
513
|
+
const hostedToolEvents = Effect.fn("OpenAIResponses.hostedToolEvents")(function* (item) {
|
|
460
514
|
const tool = HOSTED_TOOLS[item.type];
|
|
461
515
|
const providerMetadata = openaiMetadata({ itemId: item.id });
|
|
462
516
|
return [
|
|
@@ -470,12 +524,12 @@ const hostedToolEvents = (item) => {
|
|
|
470
524
|
LLMEvent.toolResult({
|
|
471
525
|
id: item.id,
|
|
472
526
|
name: tool.name,
|
|
473
|
-
result: hostedToolResult(item),
|
|
527
|
+
result: yield* hostedToolResult(item),
|
|
474
528
|
providerExecuted: true,
|
|
475
529
|
providerMetadata,
|
|
476
530
|
}),
|
|
477
531
|
];
|
|
478
|
-
};
|
|
532
|
+
});
|
|
479
533
|
const NO_EVENTS = [];
|
|
480
534
|
// `response.completed` / `response.incomplete` are clean finishes that emit a
|
|
481
535
|
// `finish` event; `response.failed` is a hard failure. All three end the stream,
|
|
@@ -671,7 +725,7 @@ const onOutputItemDone = Effect.fn("OpenAIResponses.onOutputItemDone")(function*
|
|
|
671
725
|
if (isHostedToolItem(item)) {
|
|
672
726
|
const events = [];
|
|
673
727
|
const lifecycle = Lifecycle.stepStart(state.lifecycle, events);
|
|
674
|
-
events.push(...hostedToolEvents(item));
|
|
728
|
+
events.push(...(yield* hostedToolEvents(item)));
|
|
675
729
|
return [{ ...state, lifecycle }, events];
|
|
676
730
|
}
|
|
677
731
|
if (isReasoningItem(item)) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
const dimensions = (value) => {
|
|
3
|
+
const match = /^(\d+)x(\d+)$/.exec(value);
|
|
4
|
+
if (!match)
|
|
5
|
+
return undefined;
|
|
6
|
+
return { width: Number(match[1]), height: Number(match[2]) };
|
|
7
|
+
};
|
|
8
|
+
export const Size = Schema.String.check(Schema.makeFilter((value) => {
|
|
9
|
+
if (value === "auto")
|
|
10
|
+
return undefined;
|
|
11
|
+
const parsed = dimensions(value);
|
|
12
|
+
if (!parsed)
|
|
13
|
+
return "image size must be `auto` or `{width}x{height}`";
|
|
14
|
+
return parsed.width > 0 && parsed.height > 0 ? undefined : "image dimensions must be positive integers";
|
|
15
|
+
}));
|
|
16
|
+
export const OpenAIImage = {
|
|
17
|
+
Size,
|
|
18
|
+
};
|
|
@@ -138,7 +138,7 @@ export declare const routes: (RouteDef<{
|
|
|
138
138
|
readonly effort?: string | undefined;
|
|
139
139
|
readonly summary?: "auto" | undefined;
|
|
140
140
|
} | undefined;
|
|
141
|
-
readonly tools?: readonly {
|
|
141
|
+
readonly tools?: readonly ({
|
|
142
142
|
readonly type: "function";
|
|
143
143
|
readonly name: string;
|
|
144
144
|
readonly description: string;
|
|
@@ -146,11 +146,23 @@ export declare const routes: (RouteDef<{
|
|
|
146
146
|
readonly [x: string]: unknown;
|
|
147
147
|
};
|
|
148
148
|
readonly strict?: boolean | undefined;
|
|
149
|
-
}
|
|
149
|
+
} | {
|
|
150
|
+
readonly type: "image_generation";
|
|
151
|
+
readonly size?: string | undefined;
|
|
152
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
153
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
154
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
155
|
+
readonly output_compression?: number | undefined;
|
|
156
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
157
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
158
|
+
readonly partial_images?: number | undefined;
|
|
159
|
+
})[] | undefined;
|
|
150
160
|
readonly temperature?: number | undefined;
|
|
151
161
|
readonly tool_choice?: "required" | "none" | "auto" | import("effect/Schema").Struct.ReadonlySide<{
|
|
152
162
|
readonly type: import("effect/Schema").tag<"function">;
|
|
153
163
|
readonly name: import("effect/Schema").String;
|
|
164
|
+
}, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
|
|
165
|
+
readonly type: import("effect/Schema").tag<"image_generation">;
|
|
154
166
|
}, "Type"> | undefined;
|
|
155
167
|
readonly top_p?: number | undefined;
|
|
156
168
|
readonly store?: boolean | undefined;
|
|
@@ -126,7 +126,7 @@ export declare const routes: (import("../route").Route<{
|
|
|
126
126
|
readonly effort?: string | undefined;
|
|
127
127
|
readonly summary?: "auto" | undefined;
|
|
128
128
|
} | undefined;
|
|
129
|
-
readonly tools?: readonly {
|
|
129
|
+
readonly tools?: readonly ({
|
|
130
130
|
readonly type: "function";
|
|
131
131
|
readonly name: string;
|
|
132
132
|
readonly description: string;
|
|
@@ -134,11 +134,23 @@ export declare const routes: (import("../route").Route<{
|
|
|
134
134
|
readonly [x: string]: unknown;
|
|
135
135
|
};
|
|
136
136
|
readonly strict?: boolean | undefined;
|
|
137
|
-
}
|
|
137
|
+
} | {
|
|
138
|
+
readonly type: "image_generation";
|
|
139
|
+
readonly size?: string | undefined;
|
|
140
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
141
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
142
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
143
|
+
readonly output_compression?: number | undefined;
|
|
144
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
145
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
146
|
+
readonly partial_images?: number | undefined;
|
|
147
|
+
})[] | undefined;
|
|
138
148
|
readonly temperature?: number | undefined;
|
|
139
149
|
readonly tool_choice?: "required" | "none" | "auto" | import("effect/Schema").Struct.ReadonlySide<{
|
|
140
150
|
readonly type: import("effect/Schema").tag<"function">;
|
|
141
151
|
readonly name: import("effect/Schema").String;
|
|
152
|
+
}, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
|
|
153
|
+
readonly type: import("effect/Schema").tag<"image_generation">;
|
|
142
154
|
}, "Type"> | undefined;
|
|
143
155
|
readonly top_p?: number | undefined;
|
|
144
156
|
readonly store?: boolean | undefined;
|
|
@@ -71,7 +71,7 @@ export declare const routes: import("../route").Route<{
|
|
|
71
71
|
readonly effort?: string | undefined;
|
|
72
72
|
readonly summary?: "auto" | undefined;
|
|
73
73
|
} | undefined;
|
|
74
|
-
readonly tools?: readonly {
|
|
74
|
+
readonly tools?: readonly ({
|
|
75
75
|
readonly type: "function";
|
|
76
76
|
readonly name: string;
|
|
77
77
|
readonly description: string;
|
|
@@ -79,11 +79,23 @@ export declare const routes: import("../route").Route<{
|
|
|
79
79
|
readonly [x: string]: unknown;
|
|
80
80
|
};
|
|
81
81
|
readonly strict?: boolean | undefined;
|
|
82
|
-
}
|
|
82
|
+
} | {
|
|
83
|
+
readonly type: "image_generation";
|
|
84
|
+
readonly size?: string | undefined;
|
|
85
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
86
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
87
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
88
|
+
readonly output_compression?: number | undefined;
|
|
89
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
90
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
91
|
+
readonly partial_images?: number | undefined;
|
|
92
|
+
})[] | undefined;
|
|
83
93
|
readonly temperature?: number | undefined;
|
|
84
94
|
readonly tool_choice?: "required" | "none" | "auto" | import("effect/Schema").Struct.ReadonlySide<{
|
|
85
95
|
readonly type: import("effect/Schema").tag<"function">;
|
|
86
96
|
readonly name: import("effect/Schema").String;
|
|
97
|
+
}, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
|
|
98
|
+
readonly type: import("effect/Schema").tag<"image_generation">;
|
|
87
99
|
}, "Type"> | undefined;
|
|
88
100
|
readonly top_p?: number | undefined;
|
|
89
101
|
readonly store?: boolean | undefined;
|
|
@@ -69,7 +69,7 @@ export declare const routes: import("../route").Route<{
|
|
|
69
69
|
readonly effort?: string | undefined;
|
|
70
70
|
readonly summary?: "auto" | undefined;
|
|
71
71
|
} | undefined;
|
|
72
|
-
readonly tools?: readonly {
|
|
72
|
+
readonly tools?: readonly ({
|
|
73
73
|
readonly type: "function";
|
|
74
74
|
readonly name: string;
|
|
75
75
|
readonly description: string;
|
|
@@ -77,11 +77,23 @@ export declare const routes: import("../route").Route<{
|
|
|
77
77
|
readonly [x: string]: unknown;
|
|
78
78
|
};
|
|
79
79
|
readonly strict?: boolean | undefined;
|
|
80
|
-
}
|
|
80
|
+
} | {
|
|
81
|
+
readonly type: "image_generation";
|
|
82
|
+
readonly size?: string | undefined;
|
|
83
|
+
readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
84
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
85
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
86
|
+
readonly output_compression?: number | undefined;
|
|
87
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
88
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
89
|
+
readonly partial_images?: number | undefined;
|
|
90
|
+
})[] | undefined;
|
|
81
91
|
readonly temperature?: number | undefined;
|
|
82
92
|
readonly tool_choice?: "required" | "none" | "auto" | import("effect/Schema").Struct.ReadonlySide<{
|
|
83
93
|
readonly type: import("effect/Schema").tag<"function">;
|
|
84
94
|
readonly name: import("effect/Schema").String;
|
|
95
|
+
}, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
|
|
96
|
+
readonly type: import("effect/Schema").tag<"image_generation">;
|
|
85
97
|
}, "Type"> | undefined;
|
|
86
98
|
readonly top_p?: number | undefined;
|
|
87
99
|
readonly store?: boolean | undefined;
|