@opencode-ai/ai 0.0.0-dev-17929 → 0.0.0-dev-17944
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/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/index.js +1 -0
- package/dist/protocols/open-responses-channel.d.ts +0 -5
- package/dist/protocols/open-responses-channel.js +8 -1
- package/dist/protocols/{openai-responses-channel.d.ts → open-responses-continuation.d.ts} +1 -1
- package/dist/protocols/{openai-responses-channel.js → open-responses-continuation.js} +2 -2
- package/dist/protocols/open-responses.d.ts +51 -35
- package/dist/protocols/open-responses.js +62 -58
- package/dist/protocols/openai-compatible-responses.d.ts +8 -5
- package/dist/protocols/openai-responses.d.ts +80 -117
- package/dist/protocols/openai-responses.js +21 -68
- package/dist/protocols/utils/responses-hosted-tools.d.ts +27 -0
- package/dist/protocols/utils/responses-hosted-tools.js +32 -0
- package/dist/protocols/xai-responses.d.ts +174 -0
- package/dist/protocols/xai-responses.js +49 -0
- package/dist/provider-error.d.ts +1 -0
- package/dist/provider-error.js +4 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +8 -14
- package/dist/providers/azure.d.ts +8 -14
- package/dist/providers/google-vertex-responses.d.ts +8 -5
- package/dist/providers/openai-compatible-responses.d.ts +8 -5
- package/dist/providers/openai.d.ts +8 -14
- package/dist/providers/xai.d.ts +1 -135
- package/dist/providers/xai.js +4 -3
- package/dist/schema/errors.d.ts +1 -0
- package/dist/schema/errors.js +3 -0
- package/package.json +3 -3
|
@@ -3,21 +3,42 @@ import { Route } from "../route/client.js";
|
|
|
3
3
|
import { Protocol } from "../route/protocol.js";
|
|
4
4
|
import { HttpTransport } from "../route/transport/index.js";
|
|
5
5
|
import { OpenResponses } from "./open-responses.js";
|
|
6
|
-
import { type Options } from "./open-responses-channel.js";
|
|
7
6
|
export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
8
7
|
export declare const PATH = "/responses";
|
|
9
8
|
declare const OpenAIResponsesBody: Schema.Struct<{
|
|
10
9
|
readonly stream: Schema.Literal<true>;
|
|
11
|
-
readonly
|
|
12
|
-
readonly type: Schema.tag<"
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
readonly tools: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
11
|
+
readonly type: Schema.tag<"function">;
|
|
12
|
+
readonly name: Schema.String;
|
|
13
|
+
readonly description: Schema.String;
|
|
14
|
+
readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
15
|
+
readonly strict: Schema.optional<Schema.Boolean>;
|
|
16
|
+
}>, Schema.Struct<{
|
|
17
|
+
readonly type: Schema.tag<"image_generation">;
|
|
18
|
+
readonly action: Schema.optional<Schema.Literals<readonly ["auto", "generate", "edit"]>>;
|
|
19
|
+
readonly background: Schema.optional<Schema.Literals<readonly ["auto", "opaque", "transparent"]>>;
|
|
20
|
+
readonly input_fidelity: Schema.optional<Schema.Literals<readonly ["low", "high"]>>;
|
|
21
|
+
readonly output_compression: Schema.optional<Schema.Int>;
|
|
22
|
+
readonly output_format: Schema.optional<Schema.Literals<readonly ["png", "jpeg", "webp"]>>;
|
|
23
|
+
readonly partial_images: Schema.optional<Schema.Int>;
|
|
24
|
+
readonly quality: Schema.optional<Schema.Literals<readonly ["auto", "low", "medium", "high"]>>;
|
|
25
|
+
readonly size: Schema.optional<Schema.String>;
|
|
26
|
+
}>]>>>;
|
|
27
|
+
readonly tool_choice: Schema.optional<Schema.Union<readonly [Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
|
|
28
|
+
readonly type: Schema.tag<"function">;
|
|
29
|
+
readonly name: Schema.String;
|
|
30
|
+
}>, Schema.Struct<{
|
|
31
|
+
readonly type: Schema.tag<"allowed_tools">;
|
|
32
|
+
readonly mode: Schema.Literals<readonly ["auto", "none", "required"]>;
|
|
33
|
+
readonly tools: Schema.$Array<Schema.Struct<{
|
|
34
|
+
readonly type: Schema.tag<"function">;
|
|
35
|
+
readonly name: Schema.String;
|
|
18
36
|
}>>;
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
}>]>, Schema.Struct<{
|
|
38
|
+
readonly type: Schema.tag<"image_generation">;
|
|
39
|
+
}>]>>;
|
|
40
|
+
readonly model: Schema.String;
|
|
41
|
+
readonly input: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
21
42
|
readonly role: Schema.tag<"system">;
|
|
22
43
|
readonly content: Schema.String;
|
|
23
44
|
}>, Schema.Struct<{
|
|
@@ -34,8 +55,8 @@ declare const OpenAIResponsesBody: Schema.Struct<{
|
|
|
34
55
|
}>, Schema.Struct<{
|
|
35
56
|
readonly type: Schema.tag<"input_file">;
|
|
36
57
|
readonly filename: Schema.String;
|
|
37
|
-
readonly file_data: Schema.String
|
|
38
|
-
readonly
|
|
58
|
+
readonly file_data: Schema.optional<Schema.String>;
|
|
59
|
+
readonly file_url: Schema.optional<Schema.String>;
|
|
39
60
|
}>]>]>>;
|
|
40
61
|
}>, Schema.Struct<{
|
|
41
62
|
readonly type: Schema.tag<"message">;
|
|
@@ -45,7 +66,7 @@ declare const OpenAIResponsesBody: Schema.Struct<{
|
|
|
45
66
|
readonly type: Schema.tag<"output_text">;
|
|
46
67
|
readonly text: Schema.String;
|
|
47
68
|
}>>;
|
|
48
|
-
readonly phase: Schema.optionalKey<Schema.Literals<readonly ["commentary", "final_answer"]
|
|
69
|
+
readonly phase: Schema.optionalKey<Schema.NullOr<Schema.Literals<readonly ["commentary", "final_answer"]>>>;
|
|
49
70
|
}>, Schema.Struct<{
|
|
50
71
|
readonly type: Schema.tag<"reasoning">;
|
|
51
72
|
readonly id: Schema.optionalKey<Schema.String>;
|
|
@@ -75,41 +96,13 @@ declare const OpenAIResponsesBody: Schema.Struct<{
|
|
|
75
96
|
}>, Schema.Struct<{
|
|
76
97
|
readonly type: Schema.tag<"input_file">;
|
|
77
98
|
readonly filename: Schema.String;
|
|
78
|
-
readonly file_data: Schema.String
|
|
79
|
-
readonly
|
|
99
|
+
readonly file_data: Schema.optional<Schema.String>;
|
|
100
|
+
readonly file_url: Schema.optional<Schema.String>;
|
|
101
|
+
}>, Schema.Struct<{
|
|
102
|
+
readonly type: Schema.tag<"input_video">;
|
|
103
|
+
readonly video_url: Schema.String;
|
|
80
104
|
}>]>>]>;
|
|
81
|
-
}>]>]>>;
|
|
82
|
-
readonly tools: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
83
|
-
readonly type: Schema.tag<"function">;
|
|
84
|
-
readonly name: Schema.String;
|
|
85
|
-
readonly description: Schema.String;
|
|
86
|
-
readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
87
|
-
readonly strict: Schema.optional<Schema.Boolean>;
|
|
88
|
-
}>, Schema.Struct<{
|
|
89
|
-
readonly type: Schema.tag<"image_generation">;
|
|
90
|
-
readonly action: Schema.optional<Schema.Literals<readonly ["auto", "generate", "edit"]>>;
|
|
91
|
-
readonly background: Schema.optional<Schema.Literals<readonly ["auto", "opaque", "transparent"]>>;
|
|
92
|
-
readonly input_fidelity: Schema.optional<Schema.Literals<readonly ["low", "high"]>>;
|
|
93
|
-
readonly output_compression: Schema.optional<Schema.Int>;
|
|
94
|
-
readonly output_format: Schema.optional<Schema.Literals<readonly ["png", "jpeg", "webp"]>>;
|
|
95
|
-
readonly partial_images: Schema.optional<Schema.Int>;
|
|
96
|
-
readonly quality: Schema.optional<Schema.Literals<readonly ["auto", "low", "medium", "high"]>>;
|
|
97
|
-
readonly size: Schema.optional<Schema.String>;
|
|
98
|
-
}>]>>>;
|
|
99
|
-
readonly tool_choice: Schema.optional<Schema.Union<readonly [Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
|
|
100
|
-
readonly type: Schema.tag<"function">;
|
|
101
|
-
readonly name: Schema.String;
|
|
102
|
-
}>, Schema.Struct<{
|
|
103
|
-
readonly type: Schema.tag<"allowed_tools">;
|
|
104
|
-
readonly mode: Schema.Literals<readonly ["auto", "none", "required"]>;
|
|
105
|
-
readonly tools: Schema.$Array<Schema.Struct<{
|
|
106
|
-
readonly type: Schema.tag<"function">;
|
|
107
|
-
readonly name: Schema.String;
|
|
108
|
-
}>>;
|
|
109
|
-
}>]>, Schema.Struct<{
|
|
110
|
-
readonly type: Schema.tag<"image_generation">;
|
|
111
105
|
}>]>>;
|
|
112
|
-
readonly model: Schema.String;
|
|
113
106
|
readonly instructions: Schema.optional<Schema.String>;
|
|
114
107
|
readonly store: Schema.optional<Schema.Boolean>;
|
|
115
108
|
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
@@ -164,8 +157,8 @@ export declare const protocol: Protocol<{
|
|
|
164
157
|
} | {
|
|
165
158
|
readonly type: "input_file";
|
|
166
159
|
readonly filename: string;
|
|
167
|
-
readonly file_data
|
|
168
|
-
readonly
|
|
160
|
+
readonly file_data?: string | undefined;
|
|
161
|
+
readonly file_url?: string | undefined;
|
|
169
162
|
} | {
|
|
170
163
|
readonly type: "input_text";
|
|
171
164
|
readonly text: string;
|
|
@@ -178,7 +171,7 @@ export declare const protocol: Protocol<{
|
|
|
178
171
|
}[];
|
|
179
172
|
readonly role: "assistant";
|
|
180
173
|
readonly id?: string | undefined;
|
|
181
|
-
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
174
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
182
175
|
} | {
|
|
183
176
|
readonly type: "function_call";
|
|
184
177
|
readonly name: string;
|
|
@@ -194,21 +187,15 @@ export declare const protocol: Protocol<{
|
|
|
194
187
|
} | {
|
|
195
188
|
readonly type: "input_file";
|
|
196
189
|
readonly filename: string;
|
|
197
|
-
readonly file_data
|
|
198
|
-
readonly
|
|
190
|
+
readonly file_data?: string | undefined;
|
|
191
|
+
readonly file_url?: string | undefined;
|
|
199
192
|
} | {
|
|
200
193
|
readonly type: "input_text";
|
|
201
194
|
readonly text: string;
|
|
195
|
+
} | {
|
|
196
|
+
readonly type: "input_video";
|
|
197
|
+
readonly video_url: string;
|
|
202
198
|
})[];
|
|
203
|
-
} | {
|
|
204
|
-
readonly type: "message";
|
|
205
|
-
readonly content: readonly {
|
|
206
|
-
readonly type: "output_text";
|
|
207
|
-
readonly text: string;
|
|
208
|
-
}[];
|
|
209
|
-
readonly role: "assistant";
|
|
210
|
-
readonly id?: string | undefined;
|
|
211
|
-
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
212
199
|
})[];
|
|
213
200
|
readonly model: string;
|
|
214
201
|
readonly stream: true;
|
|
@@ -353,8 +340,8 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
353
340
|
} | {
|
|
354
341
|
readonly type: "input_file";
|
|
355
342
|
readonly filename: string;
|
|
356
|
-
readonly file_data
|
|
357
|
-
readonly
|
|
343
|
+
readonly file_data?: string | undefined;
|
|
344
|
+
readonly file_url?: string | undefined;
|
|
358
345
|
} | {
|
|
359
346
|
readonly type: "input_text";
|
|
360
347
|
readonly text: string;
|
|
@@ -367,7 +354,7 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
367
354
|
}[];
|
|
368
355
|
readonly role: "assistant";
|
|
369
356
|
readonly id?: string | undefined;
|
|
370
|
-
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
357
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
371
358
|
} | {
|
|
372
359
|
readonly type: "function_call";
|
|
373
360
|
readonly name: string;
|
|
@@ -383,21 +370,15 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
383
370
|
} | {
|
|
384
371
|
readonly type: "input_file";
|
|
385
372
|
readonly filename: string;
|
|
386
|
-
readonly file_data
|
|
387
|
-
readonly
|
|
373
|
+
readonly file_data?: string | undefined;
|
|
374
|
+
readonly file_url?: string | undefined;
|
|
388
375
|
} | {
|
|
389
376
|
readonly type: "input_text";
|
|
390
377
|
readonly text: string;
|
|
378
|
+
} | {
|
|
379
|
+
readonly type: "input_video";
|
|
380
|
+
readonly video_url: string;
|
|
391
381
|
})[];
|
|
392
|
-
} | {
|
|
393
|
-
readonly type: "message";
|
|
394
|
-
readonly content: readonly {
|
|
395
|
-
readonly type: "output_text";
|
|
396
|
-
readonly text: string;
|
|
397
|
-
}[];
|
|
398
|
-
readonly role: "assistant";
|
|
399
|
-
readonly id?: string | undefined;
|
|
400
|
-
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
401
382
|
})[];
|
|
402
383
|
readonly model: string;
|
|
403
384
|
readonly stream: true;
|
|
@@ -462,7 +443,7 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
462
443
|
readonly max_tool_calls?: number | undefined;
|
|
463
444
|
readonly parallel_tool_calls?: boolean | undefined;
|
|
464
445
|
}, string>;
|
|
465
|
-
export declare const channelTransport: (options:
|
|
446
|
+
export declare const channelTransport: (options: import("./open-responses-channel.js").Options) => import("../route/transport/index.js").Transport<{
|
|
466
447
|
readonly input: readonly ({
|
|
467
448
|
readonly type: "reasoning";
|
|
468
449
|
readonly summary: readonly {
|
|
@@ -488,8 +469,8 @@ export declare const channelTransport: (options: Omit<Options, "driver">) => imp
|
|
|
488
469
|
} | {
|
|
489
470
|
readonly type: "input_file";
|
|
490
471
|
readonly filename: string;
|
|
491
|
-
readonly file_data
|
|
492
|
-
readonly
|
|
472
|
+
readonly file_data?: string | undefined;
|
|
473
|
+
readonly file_url?: string | undefined;
|
|
493
474
|
} | {
|
|
494
475
|
readonly type: "input_text";
|
|
495
476
|
readonly text: string;
|
|
@@ -502,7 +483,7 @@ export declare const channelTransport: (options: Omit<Options, "driver">) => imp
|
|
|
502
483
|
}[];
|
|
503
484
|
readonly role: "assistant";
|
|
504
485
|
readonly id?: string | undefined;
|
|
505
|
-
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
486
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
506
487
|
} | {
|
|
507
488
|
readonly type: "function_call";
|
|
508
489
|
readonly name: string;
|
|
@@ -518,21 +499,15 @@ export declare const channelTransport: (options: Omit<Options, "driver">) => imp
|
|
|
518
499
|
} | {
|
|
519
500
|
readonly type: "input_file";
|
|
520
501
|
readonly filename: string;
|
|
521
|
-
readonly file_data
|
|
522
|
-
readonly
|
|
502
|
+
readonly file_data?: string | undefined;
|
|
503
|
+
readonly file_url?: string | undefined;
|
|
523
504
|
} | {
|
|
524
505
|
readonly type: "input_text";
|
|
525
506
|
readonly text: string;
|
|
507
|
+
} | {
|
|
508
|
+
readonly type: "input_video";
|
|
509
|
+
readonly video_url: string;
|
|
526
510
|
})[];
|
|
527
|
-
} | {
|
|
528
|
-
readonly type: "message";
|
|
529
|
-
readonly content: readonly {
|
|
530
|
-
readonly type: "output_text";
|
|
531
|
-
readonly text: string;
|
|
532
|
-
}[];
|
|
533
|
-
readonly role: "assistant";
|
|
534
|
-
readonly id?: string | undefined;
|
|
535
|
-
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
536
511
|
})[];
|
|
537
512
|
readonly model: string;
|
|
538
513
|
readonly stream: true;
|
|
@@ -623,8 +598,8 @@ export declare const transport: import("../route/transport/index.js").Transport<
|
|
|
623
598
|
} | {
|
|
624
599
|
readonly type: "input_file";
|
|
625
600
|
readonly filename: string;
|
|
626
|
-
readonly file_data
|
|
627
|
-
readonly
|
|
601
|
+
readonly file_data?: string | undefined;
|
|
602
|
+
readonly file_url?: string | undefined;
|
|
628
603
|
} | {
|
|
629
604
|
readonly type: "input_text";
|
|
630
605
|
readonly text: string;
|
|
@@ -637,7 +612,7 @@ export declare const transport: import("../route/transport/index.js").Transport<
|
|
|
637
612
|
}[];
|
|
638
613
|
readonly role: "assistant";
|
|
639
614
|
readonly id?: string | undefined;
|
|
640
|
-
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
615
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
641
616
|
} | {
|
|
642
617
|
readonly type: "function_call";
|
|
643
618
|
readonly name: string;
|
|
@@ -653,21 +628,15 @@ export declare const transport: import("../route/transport/index.js").Transport<
|
|
|
653
628
|
} | {
|
|
654
629
|
readonly type: "input_file";
|
|
655
630
|
readonly filename: string;
|
|
656
|
-
readonly file_data
|
|
657
|
-
readonly
|
|
631
|
+
readonly file_data?: string | undefined;
|
|
632
|
+
readonly file_url?: string | undefined;
|
|
658
633
|
} | {
|
|
659
634
|
readonly type: "input_text";
|
|
660
635
|
readonly text: string;
|
|
636
|
+
} | {
|
|
637
|
+
readonly type: "input_video";
|
|
638
|
+
readonly video_url: string;
|
|
661
639
|
})[];
|
|
662
|
-
} | {
|
|
663
|
-
readonly type: "message";
|
|
664
|
-
readonly content: readonly {
|
|
665
|
-
readonly type: "output_text";
|
|
666
|
-
readonly text: string;
|
|
667
|
-
}[];
|
|
668
|
-
readonly role: "assistant";
|
|
669
|
-
readonly id?: string | undefined;
|
|
670
|
-
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
671
640
|
})[];
|
|
672
641
|
readonly model: string;
|
|
673
642
|
readonly stream: true;
|
|
@@ -758,8 +727,8 @@ export declare const route: Route<{
|
|
|
758
727
|
} | {
|
|
759
728
|
readonly type: "input_file";
|
|
760
729
|
readonly filename: string;
|
|
761
|
-
readonly file_data
|
|
762
|
-
readonly
|
|
730
|
+
readonly file_data?: string | undefined;
|
|
731
|
+
readonly file_url?: string | undefined;
|
|
763
732
|
} | {
|
|
764
733
|
readonly type: "input_text";
|
|
765
734
|
readonly text: string;
|
|
@@ -772,7 +741,7 @@ export declare const route: Route<{
|
|
|
772
741
|
}[];
|
|
773
742
|
readonly role: "assistant";
|
|
774
743
|
readonly id?: string | undefined;
|
|
775
|
-
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
744
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
776
745
|
} | {
|
|
777
746
|
readonly type: "function_call";
|
|
778
747
|
readonly name: string;
|
|
@@ -788,21 +757,15 @@ export declare const route: Route<{
|
|
|
788
757
|
} | {
|
|
789
758
|
readonly type: "input_file";
|
|
790
759
|
readonly filename: string;
|
|
791
|
-
readonly file_data
|
|
792
|
-
readonly
|
|
760
|
+
readonly file_data?: string | undefined;
|
|
761
|
+
readonly file_url?: string | undefined;
|
|
793
762
|
} | {
|
|
794
763
|
readonly type: "input_text";
|
|
795
764
|
readonly text: string;
|
|
765
|
+
} | {
|
|
766
|
+
readonly type: "input_video";
|
|
767
|
+
readonly video_url: string;
|
|
796
768
|
})[];
|
|
797
|
-
} | {
|
|
798
|
-
readonly type: "message";
|
|
799
|
-
readonly content: readonly {
|
|
800
|
-
readonly type: "output_text";
|
|
801
|
-
readonly text: string;
|
|
802
|
-
}[];
|
|
803
|
-
readonly role: "assistant";
|
|
804
|
-
readonly id?: string | undefined;
|
|
805
|
-
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
806
769
|
})[];
|
|
807
770
|
readonly model: string;
|
|
808
771
|
readonly stream: true;
|
|
@@ -5,14 +5,13 @@ import { Auth } from "../route/auth.js";
|
|
|
5
5
|
import { Endpoint } from "../route/endpoint.js";
|
|
6
6
|
import { Protocol } from "../route/protocol.js";
|
|
7
7
|
import { HttpTransport } from "../route/transport/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { LLMRequest } from "../schema/index.js";
|
|
9
9
|
import { OpenResponses } from "./open-responses.js";
|
|
10
10
|
import { optionalArray, ProviderShared } from "./shared.js";
|
|
11
|
-
import { Lifecycle } from "./utils/lifecycle.js";
|
|
12
11
|
import { OpenAIImage } from "./utils/openai-image.js";
|
|
12
|
+
import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
|
|
13
13
|
import { ToolSchemaProjection } from "./utils/tool-schema.js";
|
|
14
14
|
import { OpenResponsesChannel } from "./open-responses-channel.js";
|
|
15
|
-
import { OpenAIResponsesChannel } from "./openai-responses-channel.js";
|
|
16
15
|
const ADAPTER = "openai-responses";
|
|
17
16
|
const NAME = "OpenAI Responses";
|
|
18
17
|
const WEBSOCKET_PROTOCOL_HEADER = "responses_websockets=2026-02-06";
|
|
@@ -35,19 +34,8 @@ const OpenAIResponsesToolChoice = Schema.Union([
|
|
|
35
34
|
OpenResponses.ToolChoice,
|
|
36
35
|
Schema.Struct({ type: Schema.tag("image_generation") }),
|
|
37
36
|
]);
|
|
38
|
-
const OpenAIResponsesInputItem = Schema.Union([
|
|
39
|
-
Schema.Struct({
|
|
40
|
-
type: Schema.tag("message"),
|
|
41
|
-
id: Schema.optionalKey(Schema.String),
|
|
42
|
-
role: Schema.tag("assistant"),
|
|
43
|
-
content: Schema.Array(Schema.Struct({ type: Schema.tag("output_text"), text: Schema.String })),
|
|
44
|
-
phase: Schema.optionalKey(Schema.NullOr(OpenResponses.MessagePhase)),
|
|
45
|
-
}),
|
|
46
|
-
OpenResponses.InputItem,
|
|
47
|
-
]);
|
|
48
37
|
const OpenAIResponsesCoreFields = {
|
|
49
38
|
...OpenResponses.coreFields,
|
|
50
|
-
input: Schema.Array(OpenAIResponsesInputItem),
|
|
51
39
|
tools: optionalArray(OpenAIResponsesTools),
|
|
52
40
|
tool_choice: Schema.optional(OpenAIResponsesToolChoice),
|
|
53
41
|
};
|
|
@@ -58,17 +46,6 @@ const OpenAIResponsesBody = Schema.Struct({
|
|
|
58
46
|
const extension = {
|
|
59
47
|
id: ADAPTER,
|
|
60
48
|
name: NAME,
|
|
61
|
-
messagePhase: (value) => (value === null ? null : undefined),
|
|
62
|
-
lowerMedia: ({ part, media, request }) => {
|
|
63
|
-
if (request.model.provider !== "xai" || media.mime !== "application/pdf")
|
|
64
|
-
return undefined;
|
|
65
|
-
return {
|
|
66
|
-
type: "input_file",
|
|
67
|
-
filename: part.filename ?? "document.pdf",
|
|
68
|
-
file_data: media.base64,
|
|
69
|
-
mime_type: media.mime,
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
49
|
};
|
|
73
50
|
const nativeImageToolInput = (tool) => {
|
|
74
51
|
const native = tool.native?.openai;
|
|
@@ -106,23 +83,6 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
|
|
|
106
83
|
tool_choice: body.tool_choice ?? (request.toolChoice ? yield* lowerToolChoice(request.toolChoice, request.tools) : undefined),
|
|
107
84
|
};
|
|
108
85
|
});
|
|
109
|
-
const HOSTED_TOOLS = {
|
|
110
|
-
web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
|
|
111
|
-
web_search_preview_call: { name: "web_search_preview", input: (item) => item.action ?? {} },
|
|
112
|
-
file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
|
|
113
|
-
code_interpreter_call: {
|
|
114
|
-
name: "code_interpreter",
|
|
115
|
-
input: (item) => ({ code: item.code, container_id: item.container_id }),
|
|
116
|
-
},
|
|
117
|
-
computer_use_call: { name: "computer_use", input: (item) => item.action ?? {} },
|
|
118
|
-
image_generation_call: { name: "image_generation", input: () => ({}) },
|
|
119
|
-
mcp_call: {
|
|
120
|
-
name: "mcp",
|
|
121
|
-
input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
|
|
122
|
-
},
|
|
123
|
-
local_shell_call: { name: "local_shell", input: (item) => item.action ?? {} },
|
|
124
|
-
};
|
|
125
|
-
const isHostedToolItem = (item) => item.type in HOSTED_TOOLS && typeof item.id === "string" && item.id.length > 0;
|
|
126
86
|
const hostedToolResult = Effect.fn("OpenAIResponses.hostedToolResult")(function* (item) {
|
|
127
87
|
const isError = item.error !== undefined && item.error !== null;
|
|
128
88
|
if (item.type === "image_generation_call" && item.result) {
|
|
@@ -141,26 +101,22 @@ const hostedToolResult = Effect.fn("OpenAIResponses.hostedToolResult")(function*
|
|
|
141
101
|
}
|
|
142
102
|
return isError ? { type: "error", value: item.error } : { type: "json", value: item };
|
|
143
103
|
});
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
providerMetadata,
|
|
161
|
-
}));
|
|
162
|
-
return [{ ...state, lifecycle }, events];
|
|
163
|
-
});
|
|
104
|
+
const HOSTED_TOOLS = {
|
|
105
|
+
web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
|
|
106
|
+
web_search_preview_call: { name: "web_search_preview", input: (item) => item.action ?? {} },
|
|
107
|
+
file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
|
|
108
|
+
code_interpreter_call: {
|
|
109
|
+
name: "code_interpreter",
|
|
110
|
+
input: (item) => ({ code: item.code, container_id: item.container_id }),
|
|
111
|
+
},
|
|
112
|
+
computer_use_call: { name: "computer_use", input: (item) => item.action ?? {} },
|
|
113
|
+
image_generation_call: { name: "image_generation", input: () => ({}), result: hostedToolResult },
|
|
114
|
+
mcp_call: {
|
|
115
|
+
name: "mcp",
|
|
116
|
+
input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
|
|
117
|
+
},
|
|
118
|
+
local_shell_call: { name: "local_shell", input: (item) => item.action ?? {} },
|
|
119
|
+
};
|
|
164
120
|
const step = (state, event) => {
|
|
165
121
|
if (event.type === "response.reasoning_text.delta" || event.type === "response.reasoning_summary.delta")
|
|
166
122
|
return event.item_id
|
|
@@ -170,8 +126,8 @@ const step = (state, event) => {
|
|
|
170
126
|
return event.item_id
|
|
171
127
|
? Effect.succeed(OpenResponses.onReasoningDone(state, event))
|
|
172
128
|
: ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`);
|
|
173
|
-
if (event.type === "response.output_item.done" && event.item &&
|
|
174
|
-
return
|
|
129
|
+
if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS))
|
|
130
|
+
return ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS);
|
|
175
131
|
return OpenResponses.step(state, event);
|
|
176
132
|
};
|
|
177
133
|
export const protocol = Protocol.make({
|
|
@@ -190,10 +146,7 @@ export const protocol = Protocol.make({
|
|
|
190
146
|
const endpoint = Endpoint.path(PATH, { baseURL: DEFAULT_BASE_URL });
|
|
191
147
|
const auth = Auth.none;
|
|
192
148
|
export const httpTransport = HttpTransport.sseJson.with();
|
|
193
|
-
export const channelTransport = (
|
|
194
|
-
...options,
|
|
195
|
-
driver: (input) => OpenAIResponsesChannel.driver({ id: options.id, name: options.name, ...input }),
|
|
196
|
-
});
|
|
149
|
+
export const channelTransport = (OpenResponsesChannel.transport);
|
|
197
150
|
export const transport = channelTransport({
|
|
198
151
|
id: ADAPTER,
|
|
199
152
|
name: NAME,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type AIError, type ToolResultPart } from "../../schema/index.js";
|
|
3
|
+
import { OpenResponses } from "../open-responses.js";
|
|
4
|
+
export type Item = OpenResponses.StreamItem & {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly status?: string;
|
|
7
|
+
readonly action?: unknown;
|
|
8
|
+
readonly queries?: unknown;
|
|
9
|
+
readonly results?: unknown;
|
|
10
|
+
readonly code?: string;
|
|
11
|
+
readonly container_id?: string;
|
|
12
|
+
readonly outputs?: unknown;
|
|
13
|
+
readonly server_label?: string;
|
|
14
|
+
readonly output?: unknown;
|
|
15
|
+
readonly result?: string;
|
|
16
|
+
readonly output_format?: "png" | "jpeg" | "webp";
|
|
17
|
+
readonly error?: unknown;
|
|
18
|
+
};
|
|
19
|
+
export interface Definition {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly input: (item: Item) => unknown;
|
|
22
|
+
readonly result?: (item: Item) => Effect.Effect<ToolResultPart["result"], AIError>;
|
|
23
|
+
}
|
|
24
|
+
export type Definitions = Readonly<Record<string, Definition>>;
|
|
25
|
+
export declare const isItem: <Tools extends Definitions>(item: OpenResponses.StreamItem, tools: Tools) => item is Item;
|
|
26
|
+
export declare const onDone: (state: OpenResponses.ParserState, item: Item, tools: Definitions) => Effect.Effect<OpenResponses.StepResult, AIError>;
|
|
27
|
+
export * as ResponsesHostedTools from "./responses-hosted-tools.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { LLMEvent } from "../../schema/index.js";
|
|
3
|
+
import { OpenResponses } from "../open-responses.js";
|
|
4
|
+
import { Lifecycle } from "./lifecycle.js";
|
|
5
|
+
export const isItem = (item, tools) => item.type in tools && typeof item.id === "string" && item.id.length > 0;
|
|
6
|
+
export const onDone = Effect.fn("ResponsesHostedTools.onDone")(function* (state, item, tools) {
|
|
7
|
+
const tool = tools[item.type];
|
|
8
|
+
if (!tool)
|
|
9
|
+
return [state, []];
|
|
10
|
+
const providerMetadata = OpenResponses.providerMetadata(state, { itemId: item.id });
|
|
11
|
+
const events = [];
|
|
12
|
+
const lifecycle = Lifecycle.stepStart(state.lifecycle, events);
|
|
13
|
+
events.push(LLMEvent.toolCall({
|
|
14
|
+
id: item.id,
|
|
15
|
+
name: tool.name,
|
|
16
|
+
input: tool.input(item),
|
|
17
|
+
providerExecuted: true,
|
|
18
|
+
providerMetadata,
|
|
19
|
+
}), LLMEvent.toolResult({
|
|
20
|
+
id: item.id,
|
|
21
|
+
name: tool.name,
|
|
22
|
+
result: tool.result
|
|
23
|
+
? yield* tool.result(item)
|
|
24
|
+
: item.error !== undefined && item.error !== null
|
|
25
|
+
? { type: "error", value: item.error }
|
|
26
|
+
: { type: "json", value: item },
|
|
27
|
+
providerExecuted: true,
|
|
28
|
+
providerMetadata,
|
|
29
|
+
}));
|
|
30
|
+
return [{ ...state, lifecycle }, events];
|
|
31
|
+
});
|
|
32
|
+
export * as ResponsesHostedTools from "./responses-hosted-tools.js";
|