@opencode-ai/ai 0.0.0-next-16210 → 0.0.0-next-16214
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/open-responses.d.ts +326 -34
- package/dist/protocols/open-responses.js +111 -24
- package/dist/protocols/openai-compatible-responses.d.ts +6 -5
- package/dist/protocols/openai-responses.d.ts +117 -60
- package/dist/protocols/openai-responses.js +17 -3
- package/dist/providers/azure.d.ts +14 -6
- package/dist/providers/github-copilot.d.ts +14 -6
- package/dist/providers/google-vertex-responses.d.ts +6 -5
- package/dist/providers/openai-compatible-responses.d.ts +6 -5
- package/dist/providers/openai.d.ts +28 -12
- package/dist/providers/xai.d.ts +14 -6
- package/package.json +3 -3
|
@@ -35,6 +35,7 @@ const OpenResponsesOutputText = Schema.Struct({
|
|
|
35
35
|
type: Schema.tag("output_text"),
|
|
36
36
|
text: Schema.String,
|
|
37
37
|
});
|
|
38
|
+
export const MessagePhase = Schema.Literals(["commentary", "final_answer"]);
|
|
38
39
|
const OpenResponsesReasoningSummaryText = Schema.Struct({
|
|
39
40
|
type: Schema.tag("summary_text"),
|
|
40
41
|
text: Schema.String,
|
|
@@ -61,10 +62,14 @@ const OpenResponsesFunctionCallOutput = Schema.Union([
|
|
|
61
62
|
Schema.String,
|
|
62
63
|
Schema.Array(OpenResponsesFunctionCallOutputContent),
|
|
63
64
|
]);
|
|
64
|
-
const
|
|
65
|
+
export const InputItem = Schema.Union([
|
|
65
66
|
Schema.Struct({ role: Schema.tag("system"), content: Schema.String }),
|
|
66
67
|
Schema.Struct({ role: Schema.tag("user"), content: Schema.Array(OpenResponsesInputContent) }),
|
|
67
|
-
Schema.Struct({
|
|
68
|
+
Schema.Struct({
|
|
69
|
+
role: Schema.tag("assistant"),
|
|
70
|
+
content: Schema.Array(OpenResponsesOutputText),
|
|
71
|
+
phase: Schema.optionalKey(MessagePhase),
|
|
72
|
+
}),
|
|
68
73
|
OpenResponsesReasoningItem,
|
|
69
74
|
OpenResponsesItemReference,
|
|
70
75
|
Schema.Struct({
|
|
@@ -96,7 +101,7 @@ export const ToolChoice = Schema.Union([
|
|
|
96
101
|
// transports in sync without a destructure-and-strip dance.
|
|
97
102
|
export const coreFields = {
|
|
98
103
|
model: Schema.String,
|
|
99
|
-
input: Schema.Array(
|
|
104
|
+
input: Schema.Array(InputItem),
|
|
100
105
|
instructions: Schema.optional(Schema.String),
|
|
101
106
|
tools: optionalArray(Tool),
|
|
102
107
|
tool_choice: Schema.optional(ToolChoice),
|
|
@@ -149,6 +154,7 @@ const OpenResponsesErrorPayload = Schema.Struct({
|
|
|
149
154
|
export const Event = Schema.StructWithRest(Schema.Struct({
|
|
150
155
|
type: Schema.String,
|
|
151
156
|
delta: Schema.optional(Schema.String),
|
|
157
|
+
text: Schema.optional(Schema.String),
|
|
152
158
|
item_id: Schema.optional(Schema.String),
|
|
153
159
|
summary_index: Schema.optional(Schema.Number),
|
|
154
160
|
item: Schema.optional(StreamItem),
|
|
@@ -282,7 +288,23 @@ const lowerMessages = Effect.fn("OpenResponses.lowerMessages")(function* (reques
|
|
|
282
288
|
const flushText = () => {
|
|
283
289
|
if (content.length === 0)
|
|
284
290
|
return;
|
|
285
|
-
|
|
291
|
+
const groups = content.reduce((groups, part) => {
|
|
292
|
+
const metadata = part.providerMetadata?.[providerMetadataKey];
|
|
293
|
+
const phase = ProviderShared.isRecord(metadata)
|
|
294
|
+
? messagePhase(metadata.phase, extension)
|
|
295
|
+
: undefined;
|
|
296
|
+
const group = groups.at(-1);
|
|
297
|
+
if (group && group.phase === phase)
|
|
298
|
+
group.parts.push(part);
|
|
299
|
+
else
|
|
300
|
+
groups.push({ phase, parts: [part] });
|
|
301
|
+
return groups;
|
|
302
|
+
}, []);
|
|
303
|
+
input.push(...groups.map((group) => ({
|
|
304
|
+
role: "assistant",
|
|
305
|
+
content: group.parts.map((part) => ({ type: "output_text", text: part.text })),
|
|
306
|
+
...(group.phase === undefined ? {} : { phase: group.phase }),
|
|
307
|
+
})));
|
|
286
308
|
content.splice(0, content.length);
|
|
287
309
|
};
|
|
288
310
|
for (const part of message.content) {
|
|
@@ -381,7 +403,7 @@ const lowerOptions = (request) => {
|
|
|
381
403
|
...(options.serviceTier ? { service_tier: options.serviceTier } : {}),
|
|
382
404
|
};
|
|
383
405
|
};
|
|
384
|
-
export const
|
|
406
|
+
export const fromRequestWithExtension = Effect.fn("OpenResponses.fromRequestWithExtension")(function* (request, extension) {
|
|
385
407
|
const generation = request.generation;
|
|
386
408
|
const toolSchemaCompatibility = request.model.compatibility?.toolSchema;
|
|
387
409
|
return {
|
|
@@ -398,6 +420,10 @@ export const fromRequest = Effect.fn("OpenResponses.fromRequest")(function* (req
|
|
|
398
420
|
...lowerOptions(request),
|
|
399
421
|
};
|
|
400
422
|
});
|
|
423
|
+
const decodeBody = ProviderShared.validateWith(Schema.decodeUnknownEffect(OpenResponsesBody));
|
|
424
|
+
export const fromRequest = Effect.fn("OpenResponses.fromRequest")(function* (request) {
|
|
425
|
+
return yield* decodeBody(yield* fromRequestWithExtension(request, BASE));
|
|
426
|
+
});
|
|
401
427
|
// =============================================================================
|
|
402
428
|
// Stream Parsing
|
|
403
429
|
// =============================================================================
|
|
@@ -448,24 +474,31 @@ const NO_EVENTS = [];
|
|
|
448
474
|
// so keep this set aligned with `step` and the protocol's terminal predicate.
|
|
449
475
|
const TERMINAL_TYPES = new Set(["response.completed", "response.incomplete", "response.failed"]);
|
|
450
476
|
export const terminal = (event) => TERMINAL_TYPES.has(event.type);
|
|
451
|
-
const onOutputTextDelta = (state, event) => {
|
|
477
|
+
const onOutputTextDelta = (state, event, id) => {
|
|
452
478
|
if (!event.delta)
|
|
453
479
|
return [state, NO_EVENTS];
|
|
454
480
|
const events = [];
|
|
481
|
+
const phase = state.messagePhases[id];
|
|
482
|
+
const metadata = phase === undefined ? undefined : providerMetadata(state, { phase });
|
|
483
|
+
const lifecycle = Lifecycle.textStart(state.lifecycle, events, id, metadata);
|
|
455
484
|
return [
|
|
456
|
-
{ ...state, lifecycle: Lifecycle.textDelta(
|
|
485
|
+
{ ...state, lifecycle: Lifecycle.textDelta(lifecycle, events, id, event.delta) },
|
|
457
486
|
events,
|
|
458
487
|
];
|
|
459
488
|
};
|
|
460
|
-
const onOutputTextDone = (state, event) => {
|
|
489
|
+
const onOutputTextDone = (state, event, id) => {
|
|
490
|
+
if (state.messageItems.has(id)) {
|
|
491
|
+
if (state.lifecycle.text.has(id) || event.text === undefined)
|
|
492
|
+
return [state, NO_EVENTS];
|
|
493
|
+
return onOutputTextDelta(state, { ...event, delta: event.text }, id);
|
|
494
|
+
}
|
|
461
495
|
const events = [];
|
|
462
|
-
return [{ ...state, lifecycle: Lifecycle.textEnd(state.lifecycle, events,
|
|
496
|
+
return [{ ...state, lifecycle: Lifecycle.textEnd(state.lifecycle, events, id) }, events];
|
|
463
497
|
};
|
|
464
|
-
export const onReasoningDelta = (state, event) => {
|
|
498
|
+
export const onReasoningDelta = (state, event, itemID) => {
|
|
465
499
|
if (!event.delta)
|
|
466
500
|
return [state, NO_EVENTS];
|
|
467
501
|
const events = [];
|
|
468
|
-
const itemID = event.item_id ?? "reasoning-0";
|
|
469
502
|
const id = event.summary_index !== undefined || state.reasoningItems[itemID] ? `${itemID}:${event.summary_index ?? 0}` : itemID;
|
|
470
503
|
return [
|
|
471
504
|
{
|
|
@@ -491,6 +524,18 @@ const reasoningMetadata = (state, item) => providerMetadata(state, { itemId: ite
|
|
|
491
524
|
// best-effort, not guaranteed.
|
|
492
525
|
const onOutputItemAdded = (state, event) => {
|
|
493
526
|
const item = event.item;
|
|
527
|
+
if (item?.type === "message" && item.id)
|
|
528
|
+
return [
|
|
529
|
+
{
|
|
530
|
+
...state,
|
|
531
|
+
messageItems: new Set([...state.messageItems, item.id]),
|
|
532
|
+
messagePhases: (() => {
|
|
533
|
+
const phase = state.messagePhase(item.phase);
|
|
534
|
+
return phase === undefined ? state.messagePhases : { ...state.messagePhases, [item.id]: phase };
|
|
535
|
+
})(),
|
|
536
|
+
},
|
|
537
|
+
NO_EVENTS,
|
|
538
|
+
];
|
|
494
539
|
if (item && isReasoningItem(item)) {
|
|
495
540
|
const events = [];
|
|
496
541
|
return [
|
|
@@ -611,8 +656,23 @@ const onOutputItemDone = Effect.fn("OpenResponses.onOutputItemDone")(function* (
|
|
|
611
656
|
const item = event.item;
|
|
612
657
|
if (!item)
|
|
613
658
|
return [state, NO_EVENTS];
|
|
614
|
-
if (item.type === "message" && item.id)
|
|
615
|
-
|
|
659
|
+
if (item.type === "message" && item.id) {
|
|
660
|
+
const itemPhase = state.messagePhase(item.phase);
|
|
661
|
+
const phase = itemPhase === undefined ? state.messagePhases[item.id] : itemPhase;
|
|
662
|
+
const events = [];
|
|
663
|
+
const messageItems = new Set(state.messageItems);
|
|
664
|
+
messageItems.delete(item.id);
|
|
665
|
+
const { [item.id]: _phase, ...messagePhases } = state.messagePhases;
|
|
666
|
+
return [
|
|
667
|
+
{
|
|
668
|
+
...state,
|
|
669
|
+
lifecycle: Lifecycle.textEnd(state.lifecycle, events, item.id, phase === undefined ? undefined : providerMetadata(state, { phase })),
|
|
670
|
+
messageItems,
|
|
671
|
+
messagePhases,
|
|
672
|
+
},
|
|
673
|
+
events,
|
|
674
|
+
];
|
|
675
|
+
}
|
|
616
676
|
if (item.type === "function_call") {
|
|
617
677
|
if (!item.id || !item.call_id || !item.name)
|
|
618
678
|
return [state, NO_EVENTS];
|
|
@@ -701,24 +761,43 @@ const providerError = (state, event, fallback) => {
|
|
|
701
761
|
});
|
|
702
762
|
};
|
|
703
763
|
export const step = (state, event) => {
|
|
704
|
-
if (event.type === "response.output_text.delta")
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
return Effect.succeed(
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
764
|
+
if (event.type === "response.output_text.delta" || event.type === "response.output_text.done") {
|
|
765
|
+
if (!event.item_id)
|
|
766
|
+
return ProviderShared.eventError(state.id, `${event.type} is missing item_id`);
|
|
767
|
+
return Effect.succeed(event.type === "response.output_text.delta"
|
|
768
|
+
? onOutputTextDelta(state, event, event.item_id)
|
|
769
|
+
: onOutputTextDone(state, event, event.item_id));
|
|
770
|
+
}
|
|
771
|
+
if (event.type === "response.reasoning.delta" || event.type === "response.reasoning_summary_text.delta") {
|
|
772
|
+
if (!event.item_id)
|
|
773
|
+
return ProviderShared.eventError(state.id, `${event.type} is missing item_id`);
|
|
774
|
+
return Effect.succeed(onReasoningDelta(state, event, event.item_id));
|
|
775
|
+
}
|
|
776
|
+
if (event.type === "response.reasoning.done" || event.type === "response.reasoning_summary_text.done") {
|
|
777
|
+
if (!event.item_id)
|
|
778
|
+
return ProviderShared.eventError(state.id, `${event.type} is missing item_id`);
|
|
711
779
|
return Effect.succeed(onReasoningDone(state, event));
|
|
780
|
+
}
|
|
712
781
|
if (event.type === "response.reasoning_summary_part.added")
|
|
713
|
-
return
|
|
782
|
+
return event.item_id
|
|
783
|
+
? Effect.succeed(onReasoningSummaryPartAdded(state, event))
|
|
784
|
+
: ProviderShared.eventError(state.id, `${event.type} is missing item_id`);
|
|
714
785
|
if (event.type === "response.reasoning_summary_part.done")
|
|
715
|
-
return
|
|
716
|
-
|
|
786
|
+
return event.item_id
|
|
787
|
+
? Effect.succeed(onReasoningSummaryPartDone(state, event))
|
|
788
|
+
: ProviderShared.eventError(state.id, `${event.type} is missing item_id`);
|
|
789
|
+
if (event.type === "response.output_item.added") {
|
|
790
|
+
if (event.item?.type === "message" && !event.item.id)
|
|
791
|
+
return ProviderShared.eventError(state.id, `${event.type} message is missing id`);
|
|
717
792
|
return Effect.succeed(onOutputItemAdded(state, event));
|
|
793
|
+
}
|
|
718
794
|
if (event.type === "response.function_call_arguments.delta")
|
|
719
795
|
return onFunctionCallArgumentsDelta(state, event);
|
|
720
|
-
if (event.type === "response.output_item.done")
|
|
796
|
+
if (event.type === "response.output_item.done") {
|
|
797
|
+
if (event.item?.type === "message" && !event.item.id)
|
|
798
|
+
return ProviderShared.eventError(state.id, `${event.type} message is missing id`);
|
|
721
799
|
return onOutputItemDone(state, event);
|
|
800
|
+
}
|
|
722
801
|
if (event.type === "response.completed" || event.type === "response.incomplete")
|
|
723
802
|
return Effect.succeed(onResponseFinish(state, event));
|
|
724
803
|
if (event.type === "response.failed")
|
|
@@ -741,9 +820,17 @@ export const initial = (request, extension = BASE) => ({
|
|
|
741
820
|
hasFunctionCall: false,
|
|
742
821
|
tools: ToolStream.empty(),
|
|
743
822
|
lifecycle: Lifecycle.initial(),
|
|
823
|
+
messageItems: new Set(),
|
|
824
|
+
messagePhase: (value) => messagePhase(value, extension),
|
|
825
|
+
messagePhases: {},
|
|
744
826
|
reasoningItems: {},
|
|
745
827
|
store: OpenResponsesOptions.resolve(request).store,
|
|
746
828
|
});
|
|
829
|
+
const messagePhase = (value, extension) => {
|
|
830
|
+
if (value === "commentary" || value === "final_answer")
|
|
831
|
+
return value;
|
|
832
|
+
return extension.messagePhase?.(value);
|
|
833
|
+
};
|
|
747
834
|
export const protocol = Protocol.make({
|
|
748
835
|
id: ADAPTER,
|
|
749
836
|
body: {
|
|
@@ -34,13 +34,14 @@ export declare const route: Route<{
|
|
|
34
34
|
readonly file_data: import("effect/Schema").String;
|
|
35
35
|
readonly mime_type: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
36
36
|
}>]>]>>;
|
|
37
|
-
}, "Type"> |
|
|
38
|
-
readonly
|
|
39
|
-
readonly content: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
37
|
+
}, "Type"> | {
|
|
38
|
+
readonly content: readonly import("effect/Schema").Struct.ReadonlySide<{
|
|
40
39
|
readonly type: import("effect/Schema").tag<"output_text">;
|
|
41
40
|
readonly text: import("effect/Schema").String;
|
|
42
|
-
}
|
|
43
|
-
|
|
41
|
+
}, "Type">[];
|
|
42
|
+
readonly role: "assistant";
|
|
43
|
+
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
44
|
+
} | import("effect/Schema").Struct.ReadonlySide<{
|
|
44
45
|
readonly type: import("effect/Schema").tag<"function_call">;
|
|
45
46
|
readonly call_id: import("effect/Schema").String;
|
|
46
47
|
readonly name: import("effect/Schema").String;
|
|
@@ -7,31 +7,14 @@ export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
|
7
7
|
export declare const PATH = "/responses";
|
|
8
8
|
declare const OpenAIResponsesBody: Schema.Struct<{
|
|
9
9
|
readonly stream: Schema.Literal<true>;
|
|
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<"image_generation">;
|
|
32
|
-
}>]>>;
|
|
33
|
-
readonly model: Schema.String;
|
|
34
10
|
readonly input: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
11
|
+
readonly role: Schema.tag<"assistant">;
|
|
12
|
+
readonly content: Schema.$Array<Schema.Struct<{
|
|
13
|
+
readonly type: Schema.tag<"output_text">;
|
|
14
|
+
readonly text: Schema.String;
|
|
15
|
+
}>>;
|
|
16
|
+
readonly phase: Schema.optionalKey<Schema.NullOr<Schema.Literals<readonly ["commentary", "final_answer"]>>>;
|
|
17
|
+
}>, Schema.Union<readonly [Schema.Struct<{
|
|
35
18
|
readonly role: Schema.tag<"system">;
|
|
36
19
|
readonly content: Schema.String;
|
|
37
20
|
}>, Schema.Struct<{
|
|
@@ -54,6 +37,7 @@ declare const OpenAIResponsesBody: Schema.Struct<{
|
|
|
54
37
|
readonly type: Schema.tag<"output_text">;
|
|
55
38
|
readonly text: Schema.String;
|
|
56
39
|
}>>;
|
|
40
|
+
readonly phase: Schema.optionalKey<Schema.Literals<readonly ["commentary", "final_answer"]>>;
|
|
57
41
|
}>, Schema.Struct<{
|
|
58
42
|
readonly type: Schema.tag<"reasoning">;
|
|
59
43
|
readonly id: Schema.optionalKey<Schema.String>;
|
|
@@ -85,7 +69,31 @@ declare const OpenAIResponsesBody: Schema.Struct<{
|
|
|
85
69
|
readonly file_data: Schema.String;
|
|
86
70
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
87
71
|
}>]>>]>;
|
|
72
|
+
}>]>]>>;
|
|
73
|
+
readonly tools: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
74
|
+
readonly type: Schema.tag<"function">;
|
|
75
|
+
readonly name: Schema.String;
|
|
76
|
+
readonly description: Schema.String;
|
|
77
|
+
readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
78
|
+
readonly strict: Schema.optional<Schema.Boolean>;
|
|
79
|
+
}>, Schema.Struct<{
|
|
80
|
+
readonly type: Schema.tag<"image_generation">;
|
|
81
|
+
readonly action: Schema.optional<Schema.Literals<readonly ["auto", "generate", "edit"]>>;
|
|
82
|
+
readonly background: Schema.optional<Schema.Literals<readonly ["auto", "opaque", "transparent"]>>;
|
|
83
|
+
readonly input_fidelity: Schema.optional<Schema.Literals<readonly ["low", "high"]>>;
|
|
84
|
+
readonly output_compression: Schema.optional<Schema.Int>;
|
|
85
|
+
readonly output_format: Schema.optional<Schema.Literals<readonly ["png", "jpeg", "webp"]>>;
|
|
86
|
+
readonly partial_images: Schema.optional<Schema.Int>;
|
|
87
|
+
readonly quality: Schema.optional<Schema.Literals<readonly ["auto", "low", "medium", "high"]>>;
|
|
88
|
+
readonly size: Schema.optional<Schema.String>;
|
|
89
|
+
}>]>>>;
|
|
90
|
+
readonly tool_choice: Schema.optional<Schema.Union<readonly [Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
|
|
91
|
+
readonly type: Schema.tag<"function">;
|
|
92
|
+
readonly name: Schema.String;
|
|
93
|
+
}>]>, Schema.Struct<{
|
|
94
|
+
readonly type: Schema.tag<"image_generation">;
|
|
88
95
|
}>]>>;
|
|
96
|
+
readonly model: Schema.String;
|
|
89
97
|
readonly instructions: Schema.optional<Schema.String>;
|
|
90
98
|
readonly store: Schema.optional<Schema.Boolean>;
|
|
91
99
|
readonly service_tier: Schema.optional<Schema.Literals<readonly ["auto", "default", "flex", "priority"]>>;
|
|
@@ -132,13 +140,14 @@ export declare const protocol: Protocol<{
|
|
|
132
140
|
readonly file_data: Schema.String;
|
|
133
141
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
134
142
|
}>]>]>>;
|
|
135
|
-
}, "Type"> |
|
|
136
|
-
readonly
|
|
137
|
-
readonly content: Schema.$Array<Schema.Struct<{
|
|
143
|
+
}, "Type"> | {
|
|
144
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
138
145
|
readonly type: Schema.tag<"output_text">;
|
|
139
146
|
readonly text: Schema.String;
|
|
140
|
-
}
|
|
141
|
-
|
|
147
|
+
}, "Type">[];
|
|
148
|
+
readonly role: "assistant";
|
|
149
|
+
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
150
|
+
} | Schema.Struct.ReadonlySide<{
|
|
142
151
|
readonly type: Schema.tag<"function_call">;
|
|
143
152
|
readonly call_id: Schema.String;
|
|
144
153
|
readonly name: Schema.String;
|
|
@@ -158,7 +167,14 @@ export declare const protocol: Protocol<{
|
|
|
158
167
|
readonly file_data: Schema.String;
|
|
159
168
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
160
169
|
}>]>>]>;
|
|
161
|
-
}, "Type">
|
|
170
|
+
}, "Type"> | {
|
|
171
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
172
|
+
readonly type: Schema.tag<"output_text">;
|
|
173
|
+
readonly text: Schema.String;
|
|
174
|
+
}, "Type">[];
|
|
175
|
+
readonly role: "assistant";
|
|
176
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
177
|
+
})[];
|
|
162
178
|
readonly model: string;
|
|
163
179
|
readonly stream: true;
|
|
164
180
|
readonly text?: {
|
|
@@ -209,6 +225,7 @@ export declare const protocol: Protocol<{
|
|
|
209
225
|
readonly code?: string | null | undefined;
|
|
210
226
|
readonly param?: string | null | undefined;
|
|
211
227
|
} | null | undefined;
|
|
228
|
+
readonly text?: string | undefined;
|
|
212
229
|
readonly response?: {
|
|
213
230
|
readonly [x: string]: unknown;
|
|
214
231
|
readonly error?: {
|
|
@@ -279,13 +296,14 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
279
296
|
readonly file_data: Schema.String;
|
|
280
297
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
281
298
|
}>]>]>>;
|
|
282
|
-
}, "Type"> |
|
|
283
|
-
readonly
|
|
284
|
-
readonly content: Schema.$Array<Schema.Struct<{
|
|
299
|
+
}, "Type"> | {
|
|
300
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
285
301
|
readonly type: Schema.tag<"output_text">;
|
|
286
302
|
readonly text: Schema.String;
|
|
287
|
-
}
|
|
288
|
-
|
|
303
|
+
}, "Type">[];
|
|
304
|
+
readonly role: "assistant";
|
|
305
|
+
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
306
|
+
} | Schema.Struct.ReadonlySide<{
|
|
289
307
|
readonly type: Schema.tag<"function_call">;
|
|
290
308
|
readonly call_id: Schema.String;
|
|
291
309
|
readonly name: Schema.String;
|
|
@@ -305,7 +323,14 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
305
323
|
readonly file_data: Schema.String;
|
|
306
324
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
307
325
|
}>]>>]>;
|
|
308
|
-
}, "Type">
|
|
326
|
+
}, "Type"> | {
|
|
327
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
328
|
+
readonly type: Schema.tag<"output_text">;
|
|
329
|
+
readonly text: Schema.String;
|
|
330
|
+
}, "Type">[];
|
|
331
|
+
readonly role: "assistant";
|
|
332
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
333
|
+
})[];
|
|
309
334
|
readonly model: string;
|
|
310
335
|
readonly stream: true;
|
|
311
336
|
readonly text?: {
|
|
@@ -378,13 +403,14 @@ export declare const route: Route<{
|
|
|
378
403
|
readonly file_data: Schema.String;
|
|
379
404
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
380
405
|
}>]>]>>;
|
|
381
|
-
}, "Type"> |
|
|
382
|
-
readonly
|
|
383
|
-
readonly content: Schema.$Array<Schema.Struct<{
|
|
406
|
+
}, "Type"> | {
|
|
407
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
384
408
|
readonly type: Schema.tag<"output_text">;
|
|
385
409
|
readonly text: Schema.String;
|
|
386
|
-
}
|
|
387
|
-
|
|
410
|
+
}, "Type">[];
|
|
411
|
+
readonly role: "assistant";
|
|
412
|
+
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
413
|
+
} | Schema.Struct.ReadonlySide<{
|
|
388
414
|
readonly type: Schema.tag<"function_call">;
|
|
389
415
|
readonly call_id: Schema.String;
|
|
390
416
|
readonly name: Schema.String;
|
|
@@ -404,7 +430,14 @@ export declare const route: Route<{
|
|
|
404
430
|
readonly file_data: Schema.String;
|
|
405
431
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
406
432
|
}>]>>]>;
|
|
407
|
-
}, "Type">
|
|
433
|
+
}, "Type"> | {
|
|
434
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
435
|
+
readonly type: Schema.tag<"output_text">;
|
|
436
|
+
readonly text: Schema.String;
|
|
437
|
+
}, "Type">[];
|
|
438
|
+
readonly role: "assistant";
|
|
439
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
440
|
+
})[];
|
|
408
441
|
readonly model: string;
|
|
409
442
|
readonly stream: true;
|
|
410
443
|
readonly text?: {
|
|
@@ -477,13 +510,14 @@ export declare const webSocketTransport: import("../route/transport/websocket").
|
|
|
477
510
|
readonly file_data: Schema.String;
|
|
478
511
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
479
512
|
}>]>]>>;
|
|
480
|
-
}, "Type"> |
|
|
481
|
-
readonly
|
|
482
|
-
readonly content: Schema.$Array<Schema.Struct<{
|
|
513
|
+
}, "Type"> | {
|
|
514
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
483
515
|
readonly type: Schema.tag<"output_text">;
|
|
484
516
|
readonly text: Schema.String;
|
|
485
|
-
}
|
|
486
|
-
|
|
517
|
+
}, "Type">[];
|
|
518
|
+
readonly role: "assistant";
|
|
519
|
+
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
520
|
+
} | Schema.Struct.ReadonlySide<{
|
|
487
521
|
readonly type: Schema.tag<"function_call">;
|
|
488
522
|
readonly call_id: Schema.String;
|
|
489
523
|
readonly name: Schema.String;
|
|
@@ -503,7 +537,14 @@ export declare const webSocketTransport: import("../route/transport/websocket").
|
|
|
503
537
|
readonly file_data: Schema.String;
|
|
504
538
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
505
539
|
}>]>>]>;
|
|
506
|
-
}, "Type">
|
|
540
|
+
}, "Type"> | {
|
|
541
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
542
|
+
readonly type: Schema.tag<"output_text">;
|
|
543
|
+
readonly text: Schema.String;
|
|
544
|
+
}, "Type">[];
|
|
545
|
+
readonly role: "assistant";
|
|
546
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
547
|
+
})[];
|
|
507
548
|
readonly model: string;
|
|
508
549
|
readonly stream: true;
|
|
509
550
|
readonly text?: {
|
|
@@ -577,13 +618,14 @@ export declare const webSocketTransport: import("../route/transport/websocket").
|
|
|
577
618
|
readonly file_data: Schema.String;
|
|
578
619
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
579
620
|
}>]>]>>;
|
|
580
|
-
}, "Type"> |
|
|
581
|
-
readonly
|
|
582
|
-
readonly content: Schema.$Array<Schema.Struct<{
|
|
621
|
+
}, "Type"> | {
|
|
622
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
583
623
|
readonly type: Schema.tag<"output_text">;
|
|
584
624
|
readonly text: Schema.String;
|
|
585
|
-
}
|
|
586
|
-
|
|
625
|
+
}, "Type">[];
|
|
626
|
+
readonly role: "assistant";
|
|
627
|
+
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
628
|
+
} | Schema.Struct.ReadonlySide<{
|
|
587
629
|
readonly type: Schema.tag<"function_call">;
|
|
588
630
|
readonly call_id: Schema.String;
|
|
589
631
|
readonly name: Schema.String;
|
|
@@ -603,7 +645,14 @@ export declare const webSocketTransport: import("../route/transport/websocket").
|
|
|
603
645
|
readonly file_data: Schema.String;
|
|
604
646
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
605
647
|
}>]>>]>;
|
|
606
|
-
}, "Type">
|
|
648
|
+
}, "Type"> | {
|
|
649
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
650
|
+
readonly type: Schema.tag<"output_text">;
|
|
651
|
+
readonly text: Schema.String;
|
|
652
|
+
}, "Type">[];
|
|
653
|
+
readonly role: "assistant";
|
|
654
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
655
|
+
})[];
|
|
607
656
|
readonly model: string;
|
|
608
657
|
readonly text?: {
|
|
609
658
|
readonly verbosity?: "low" | "medium" | "high" | undefined;
|
|
@@ -675,13 +724,14 @@ export declare const webSocketRoute: Route<{
|
|
|
675
724
|
readonly file_data: Schema.String;
|
|
676
725
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
677
726
|
}>]>]>>;
|
|
678
|
-
}, "Type"> |
|
|
679
|
-
readonly
|
|
680
|
-
readonly content: Schema.$Array<Schema.Struct<{
|
|
727
|
+
}, "Type"> | {
|
|
728
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
681
729
|
readonly type: Schema.tag<"output_text">;
|
|
682
730
|
readonly text: Schema.String;
|
|
683
|
-
}
|
|
684
|
-
|
|
731
|
+
}, "Type">[];
|
|
732
|
+
readonly role: "assistant";
|
|
733
|
+
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
734
|
+
} | Schema.Struct.ReadonlySide<{
|
|
685
735
|
readonly type: Schema.tag<"function_call">;
|
|
686
736
|
readonly call_id: Schema.String;
|
|
687
737
|
readonly name: Schema.String;
|
|
@@ -701,7 +751,14 @@ export declare const webSocketRoute: Route<{
|
|
|
701
751
|
readonly file_data: Schema.String;
|
|
702
752
|
readonly mime_type: Schema.optional<Schema.String>;
|
|
703
753
|
}>]>>]>;
|
|
704
|
-
}, "Type">
|
|
754
|
+
}, "Type"> | {
|
|
755
|
+
readonly content: readonly Schema.Struct.ReadonlySide<{
|
|
756
|
+
readonly type: Schema.tag<"output_text">;
|
|
757
|
+
readonly text: Schema.String;
|
|
758
|
+
}, "Type">[];
|
|
759
|
+
readonly role: "assistant";
|
|
760
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
761
|
+
})[];
|
|
705
762
|
readonly model: string;
|
|
706
763
|
readonly stream: true;
|
|
707
764
|
readonly text?: {
|
|
@@ -30,8 +30,17 @@ const OpenAIResponsesToolChoice = Schema.Union([
|
|
|
30
30
|
OpenResponses.ToolChoice,
|
|
31
31
|
Schema.Struct({ type: Schema.tag("image_generation") }),
|
|
32
32
|
]);
|
|
33
|
+
const OpenAIResponsesInputItem = Schema.Union([
|
|
34
|
+
Schema.Struct({
|
|
35
|
+
role: Schema.tag("assistant"),
|
|
36
|
+
content: Schema.Array(Schema.Struct({ type: Schema.tag("output_text"), text: Schema.String })),
|
|
37
|
+
phase: Schema.optionalKey(Schema.NullOr(OpenResponses.MessagePhase)),
|
|
38
|
+
}),
|
|
39
|
+
OpenResponses.InputItem,
|
|
40
|
+
]);
|
|
33
41
|
const OpenAIResponsesCoreFields = {
|
|
34
42
|
...OpenResponses.coreFields,
|
|
43
|
+
input: Schema.Array(OpenAIResponsesInputItem),
|
|
35
44
|
tools: optionalArray(OpenAIResponsesTools),
|
|
36
45
|
tool_choice: Schema.optional(OpenAIResponsesToolChoice),
|
|
37
46
|
};
|
|
@@ -47,6 +56,7 @@ const encodeWebSocketMessage = Schema.encodeSync(Schema.fromJsonString(OpenAIRes
|
|
|
47
56
|
const extension = {
|
|
48
57
|
id: ADAPTER,
|
|
49
58
|
name: NAME,
|
|
59
|
+
messagePhase: (value) => (value === null ? null : undefined),
|
|
50
60
|
lowerMedia: ({ part, media, request }) => {
|
|
51
61
|
if (request.model.provider !== "xai" || media.mime !== "application/pdf")
|
|
52
62
|
return undefined;
|
|
@@ -84,7 +94,7 @@ const lowerToolChoice = (toolChoice, tools) => ProviderShared.matchToolChoice(NA
|
|
|
84
94
|
: { type: "function", name },
|
|
85
95
|
});
|
|
86
96
|
const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request) {
|
|
87
|
-
const body = yield* OpenResponses.
|
|
97
|
+
const body = yield* OpenResponses.fromRequestWithExtension(LLMRequest.update(request, { tools: [], toolChoice: undefined }), extension);
|
|
88
98
|
const toolSchemaCompatibility = request.model.compatibility?.toolSchema;
|
|
89
99
|
return {
|
|
90
100
|
...body,
|
|
@@ -151,9 +161,13 @@ const onHostedToolDone = Effect.fn("OpenAIResponses.onHostedToolDone")(function*
|
|
|
151
161
|
});
|
|
152
162
|
const step = (state, event) => {
|
|
153
163
|
if (event.type === "response.reasoning_text.delta" || event.type === "response.reasoning_summary.delta")
|
|
154
|
-
return
|
|
164
|
+
return event.item_id
|
|
165
|
+
? Effect.succeed(OpenResponses.onReasoningDelta(state, event, event.item_id))
|
|
166
|
+
: ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`);
|
|
155
167
|
if (event.type === "response.reasoning_text.done" || event.type === "response.reasoning_summary.done")
|
|
156
|
-
return
|
|
168
|
+
return event.item_id
|
|
169
|
+
? Effect.succeed(OpenResponses.onReasoningDone(state, event))
|
|
170
|
+
: ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`);
|
|
157
171
|
if (event.type === "response.output_item.done" && event.item && isHostedToolItem(event.item))
|
|
158
172
|
return onHostedToolDone(state, event.item);
|
|
159
173
|
return OpenResponses.step(state, event);
|
|
@@ -114,13 +114,14 @@ export declare const routes: (RouteDef<{
|
|
|
114
114
|
readonly file_data: import("effect/Schema").String;
|
|
115
115
|
readonly mime_type: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
116
116
|
}>]>]>>;
|
|
117
|
-
}, "Type"> |
|
|
118
|
-
readonly
|
|
119
|
-
readonly content: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
117
|
+
}, "Type"> | {
|
|
118
|
+
readonly content: readonly import("effect/Schema").Struct.ReadonlySide<{
|
|
120
119
|
readonly type: import("effect/Schema").tag<"output_text">;
|
|
121
120
|
readonly text: import("effect/Schema").String;
|
|
122
|
-
}
|
|
123
|
-
|
|
121
|
+
}, "Type">[];
|
|
122
|
+
readonly role: "assistant";
|
|
123
|
+
readonly phase?: "commentary" | "final_answer" | undefined;
|
|
124
|
+
} | import("effect/Schema").Struct.ReadonlySide<{
|
|
124
125
|
readonly type: import("effect/Schema").tag<"function_call">;
|
|
125
126
|
readonly call_id: import("effect/Schema").String;
|
|
126
127
|
readonly name: import("effect/Schema").String;
|
|
@@ -140,7 +141,14 @@ export declare const routes: (RouteDef<{
|
|
|
140
141
|
readonly file_data: import("effect/Schema").String;
|
|
141
142
|
readonly mime_type: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
142
143
|
}>]>>]>;
|
|
143
|
-
}, "Type">
|
|
144
|
+
}, "Type"> | {
|
|
145
|
+
readonly content: readonly import("effect/Schema").Struct.ReadonlySide<{
|
|
146
|
+
readonly type: import("effect/Schema").tag<"output_text">;
|
|
147
|
+
readonly text: import("effect/Schema").String;
|
|
148
|
+
}, "Type">[];
|
|
149
|
+
readonly role: "assistant";
|
|
150
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
151
|
+
})[];
|
|
144
152
|
readonly model: string;
|
|
145
153
|
readonly stream: true;
|
|
146
154
|
readonly text?: {
|