@opencode/ai 2.0.9 → 2.0.11
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/alibaba-responses.d.ts +5 -17
- package/dist/protocols/meta-responses.d.ts +5 -17
- package/dist/protocols/open-responses-channel.js +0 -1
- package/dist/protocols/open-responses-continuation.js +1 -1
- package/dist/protocols/open-responses.d.ts +24 -175
- package/dist/protocols/open-responses.js +28 -71
- package/dist/protocols/openai-responses.d.ts +5 -17
- package/dist/protocols/xai-responses.d.ts +5 -17
- package/dist/route/transport/websocket.js +4 -10
- package/package.json +3 -3
|
@@ -190,16 +190,10 @@ export declare const protocol: Protocol<{
|
|
|
190
190
|
readonly [x: string]: unknown;
|
|
191
191
|
readonly type: string;
|
|
192
192
|
readonly status?: unknown;
|
|
193
|
-
readonly code?:
|
|
194
|
-
readonly message?:
|
|
195
|
-
readonly headers?: unknown;
|
|
193
|
+
readonly code?: unknown;
|
|
194
|
+
readonly message?: unknown;
|
|
196
195
|
readonly text?: string | undefined;
|
|
197
|
-
readonly error?:
|
|
198
|
-
readonly type?: string | null | undefined;
|
|
199
|
-
readonly code?: string | null | undefined;
|
|
200
|
-
readonly message?: string | null | undefined;
|
|
201
|
-
readonly param?: string | null | undefined;
|
|
202
|
-
} | null | undefined;
|
|
196
|
+
readonly error?: unknown;
|
|
203
197
|
readonly item?: {
|
|
204
198
|
readonly [x: string]: unknown;
|
|
205
199
|
readonly type: string;
|
|
@@ -224,12 +218,7 @@ export declare const protocol: Protocol<{
|
|
|
224
218
|
readonly encrypted_content?: string | null | undefined;
|
|
225
219
|
readonly call_id?: string | undefined;
|
|
226
220
|
}[] | undefined;
|
|
227
|
-
readonly error?:
|
|
228
|
-
readonly type?: string | null | undefined;
|
|
229
|
-
readonly code?: string | null | undefined;
|
|
230
|
-
readonly message?: string | null | undefined;
|
|
231
|
-
readonly param?: string | null | undefined;
|
|
232
|
-
} | null | undefined;
|
|
221
|
+
readonly error?: unknown;
|
|
233
222
|
readonly usage?: {
|
|
234
223
|
readonly input_tokens?: number | undefined;
|
|
235
224
|
readonly output_tokens?: number | undefined;
|
|
@@ -248,10 +237,9 @@ export declare const protocol: Protocol<{
|
|
|
248
237
|
} | null | undefined;
|
|
249
238
|
} | undefined;
|
|
250
239
|
readonly arguments?: string | undefined;
|
|
251
|
-
readonly param?: string | null | undefined;
|
|
252
|
-
readonly status_code?: unknown;
|
|
253
240
|
readonly item_id?: string | undefined;
|
|
254
241
|
readonly output_index?: number | undefined;
|
|
255
242
|
readonly summary_index?: number | undefined;
|
|
243
|
+
readonly status_code?: unknown;
|
|
256
244
|
}, OpenResponses.ParserState>;
|
|
257
245
|
export * as AlibabaResponses from "./alibaba-responses.js";
|
|
@@ -219,16 +219,10 @@ export declare const protocol: Protocol<{
|
|
|
219
219
|
readonly [x: string]: unknown;
|
|
220
220
|
readonly type: string;
|
|
221
221
|
readonly status?: unknown;
|
|
222
|
-
readonly code?:
|
|
223
|
-
readonly message?:
|
|
224
|
-
readonly headers?: unknown;
|
|
222
|
+
readonly code?: unknown;
|
|
223
|
+
readonly message?: unknown;
|
|
225
224
|
readonly text?: string | undefined;
|
|
226
|
-
readonly error?:
|
|
227
|
-
readonly type?: string | null | undefined;
|
|
228
|
-
readonly code?: string | null | undefined;
|
|
229
|
-
readonly message?: string | null | undefined;
|
|
230
|
-
readonly param?: string | null | undefined;
|
|
231
|
-
} | null | undefined;
|
|
225
|
+
readonly error?: unknown;
|
|
232
226
|
readonly item?: {
|
|
233
227
|
readonly [x: string]: unknown;
|
|
234
228
|
readonly type: string;
|
|
@@ -253,12 +247,7 @@ export declare const protocol: Protocol<{
|
|
|
253
247
|
readonly encrypted_content?: string | null | undefined;
|
|
254
248
|
readonly call_id?: string | undefined;
|
|
255
249
|
}[] | undefined;
|
|
256
|
-
readonly error?:
|
|
257
|
-
readonly type?: string | null | undefined;
|
|
258
|
-
readonly code?: string | null | undefined;
|
|
259
|
-
readonly message?: string | null | undefined;
|
|
260
|
-
readonly param?: string | null | undefined;
|
|
261
|
-
} | null | undefined;
|
|
250
|
+
readonly error?: unknown;
|
|
262
251
|
readonly usage?: {
|
|
263
252
|
readonly input_tokens?: number | undefined;
|
|
264
253
|
readonly output_tokens?: number | undefined;
|
|
@@ -277,11 +266,10 @@ export declare const protocol: Protocol<{
|
|
|
277
266
|
} | null | undefined;
|
|
278
267
|
} | undefined;
|
|
279
268
|
readonly arguments?: string | undefined;
|
|
280
|
-
readonly param?: string | null | undefined;
|
|
281
|
-
readonly status_code?: unknown;
|
|
282
269
|
readonly item_id?: string | undefined;
|
|
283
270
|
readonly output_index?: number | undefined;
|
|
284
271
|
readonly summary_index?: number | undefined;
|
|
272
|
+
readonly status_code?: unknown;
|
|
285
273
|
}, ParserState>;
|
|
286
274
|
export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
287
275
|
readonly input: readonly ({
|
|
@@ -32,7 +32,6 @@ const driver = (options, body) => {
|
|
|
32
32
|
return yield* ProviderShared.eventError(options.id, `${options.name} emitted ${event.type} after a terminal event`, frame);
|
|
33
33
|
if (event.type === "error") {
|
|
34
34
|
terminal = true;
|
|
35
|
-
yield* OpenResponses.decodeKnownErrorEvent(event).pipe(Effect.mapError((cause) => ProviderShared.eventError(options.id, `${options.name} returned a malformed error event`, frame, cause)));
|
|
36
35
|
return {
|
|
37
36
|
type: "provider-failure",
|
|
38
37
|
error: OpenResponses.providerFailure(event, `${options.name} stream error`, frame),
|
|
@@ -83,7 +83,7 @@ const incremental = (request, checkpoint) => {
|
|
|
83
83
|
return undefined;
|
|
84
84
|
return input.slice(baseline.length);
|
|
85
85
|
};
|
|
86
|
-
const code = (event) =>
|
|
86
|
+
const code = (event) => OpenResponses.errorDetail(event).code;
|
|
87
87
|
const rejected = (observation, recovery) => ({
|
|
88
88
|
type: "rejected",
|
|
89
89
|
recovery,
|
|
@@ -564,45 +564,7 @@ export type StreamItem = Schema.Schema.Type<typeof StreamItem>;
|
|
|
564
564
|
export type OutputItem = StreamItem & {
|
|
565
565
|
readonly id: string;
|
|
566
566
|
};
|
|
567
|
-
export declare const
|
|
568
|
-
readonly type: Schema.tag<"error">;
|
|
569
|
-
readonly status: Schema.optional<Schema.Number>;
|
|
570
|
-
readonly status_code: Schema.optional<Schema.Number>;
|
|
571
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
572
|
-
readonly message: Schema.optional<Schema.String>;
|
|
573
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
574
|
-
readonly error: Schema.optional<Schema.NullOr<Schema.decodeTo<Schema.Struct<{
|
|
575
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
576
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
577
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
578
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
579
|
-
}>, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
580
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
581
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
582
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
583
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
584
|
-
}>]>, never, never>>>;
|
|
585
|
-
readonly headers: Schema.optional<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>>;
|
|
586
|
-
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
|
|
587
|
-
export declare const decodeKnownErrorEvent: (event: Event) => Effect.Effect<{
|
|
588
|
-
readonly [x: string]: unknown;
|
|
589
|
-
readonly type: "error";
|
|
590
|
-
readonly status?: number | undefined;
|
|
591
|
-
readonly code?: string | null | undefined;
|
|
592
|
-
readonly message?: string | undefined;
|
|
593
|
-
readonly headers?: {
|
|
594
|
-
readonly [x: string]: string | number | boolean;
|
|
595
|
-
} | undefined;
|
|
596
|
-
readonly error?: {
|
|
597
|
-
readonly type?: string | null | undefined;
|
|
598
|
-
readonly code?: string | null | undefined;
|
|
599
|
-
readonly message?: string | null | undefined;
|
|
600
|
-
readonly param?: string | null | undefined;
|
|
601
|
-
} | null | undefined;
|
|
602
|
-
readonly param?: string | null | undefined;
|
|
603
|
-
readonly status_code?: number | undefined;
|
|
604
|
-
}, Schema.SchemaError, never>;
|
|
605
|
-
export declare const Event: Schema.decodeTo<Schema.toType<Schema.StructWithRest<Schema.Struct<{
|
|
567
|
+
export declare const Event: Schema.StructWithRest<Schema.Struct<{
|
|
606
568
|
readonly type: Schema.String;
|
|
607
569
|
readonly delta: Schema.optional<Schema.String>;
|
|
608
570
|
readonly arguments: Schema.optional<Schema.String>;
|
|
@@ -646,131 +608,31 @@ export declare const Event: Schema.decodeTo<Schema.toType<Schema.StructWithRest<
|
|
|
646
608
|
}>>>;
|
|
647
609
|
readonly total_tokens: Schema.optional<Schema.Number>;
|
|
648
610
|
}>>>;
|
|
649
|
-
readonly error: Schema.optional<Schema.
|
|
650
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
651
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
652
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
653
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
654
|
-
}>, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
655
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
656
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
657
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
658
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
659
|
-
}>]>, never, never>>>;
|
|
660
|
-
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
|
|
661
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
662
|
-
readonly message: Schema.optional<Schema.String>;
|
|
663
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
664
|
-
readonly error: Schema.optional<Schema.NullOr<Schema.decodeTo<Schema.Struct<{
|
|
665
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
666
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
667
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
668
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
669
|
-
}>, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
670
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
671
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
672
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
673
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
674
|
-
}>]>, never, never>>>;
|
|
675
|
-
readonly status: Schema.optional<Schema.Unknown>;
|
|
676
|
-
readonly status_code: Schema.optional<Schema.Unknown>;
|
|
677
|
-
readonly headers: Schema.optional<Schema.Unknown>;
|
|
678
|
-
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>, Schema.StructWithRest<Schema.Struct<{
|
|
679
|
-
readonly type: Schema.String;
|
|
680
|
-
readonly delta: Schema.optional<Schema.String>;
|
|
681
|
-
readonly arguments: Schema.optional<Schema.String>;
|
|
682
|
-
readonly text: Schema.optional<Schema.String>;
|
|
683
|
-
readonly item_id: Schema.optional<Schema.String>;
|
|
684
|
-
readonly output_index: Schema.optional<Schema.Number>;
|
|
685
|
-
readonly summary_index: Schema.optional<Schema.Number>;
|
|
686
|
-
readonly item: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
|
|
687
|
-
readonly type: Schema.String;
|
|
688
|
-
readonly id: Schema.optional<Schema.String>;
|
|
689
|
-
readonly call_id: Schema.optional<Schema.String>;
|
|
690
|
-
readonly name: Schema.optional<Schema.String>;
|
|
691
|
-
readonly namespace: Schema.optional<Schema.String>;
|
|
692
|
-
readonly arguments: Schema.optional<Schema.String>;
|
|
693
|
-
readonly encrypted_content: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
694
|
-
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
|
|
695
|
-
readonly response: Schema.optional<Schema.StructWithRest<Schema.Struct<{
|
|
696
|
-
readonly id: Schema.optional<Schema.String>;
|
|
697
|
-
readonly service_tier: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
698
|
-
readonly incomplete_details: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
699
|
-
readonly reason: Schema.optional<Schema.String>;
|
|
700
|
-
}>>>;
|
|
701
|
-
readonly output: Schema.optional<Schema.$Array<Schema.StructWithRest<Schema.Struct<{
|
|
702
|
-
readonly type: Schema.String;
|
|
703
|
-
readonly id: Schema.optional<Schema.String>;
|
|
704
|
-
readonly call_id: Schema.optional<Schema.String>;
|
|
705
|
-
readonly name: Schema.optional<Schema.String>;
|
|
706
|
-
readonly namespace: Schema.optional<Schema.String>;
|
|
707
|
-
readonly arguments: Schema.optional<Schema.String>;
|
|
708
|
-
readonly encrypted_content: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
709
|
-
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
|
|
710
|
-
readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
711
|
-
readonly input_tokens: Schema.optional<Schema.Number>;
|
|
712
|
-
readonly input_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
713
|
-
readonly cached_tokens: Schema.optional<Schema.Number>;
|
|
714
|
-
readonly cache_write_tokens: Schema.optional<Schema.Number>;
|
|
715
|
-
}>>>;
|
|
716
|
-
readonly output_tokens: Schema.optional<Schema.Number>;
|
|
717
|
-
readonly output_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
|
|
718
|
-
readonly reasoning_tokens: Schema.optional<Schema.Number>;
|
|
719
|
-
}>>>;
|
|
720
|
-
readonly total_tokens: Schema.optional<Schema.Number>;
|
|
721
|
-
}>>>;
|
|
722
|
-
readonly error: Schema.optional<Schema.NullOr<Schema.decodeTo<Schema.Struct<{
|
|
723
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
724
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
725
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
726
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
727
|
-
}>, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
728
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
729
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
730
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
731
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
732
|
-
}>]>, never, never>>>;
|
|
611
|
+
readonly error: Schema.optional<Schema.Unknown>;
|
|
733
612
|
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
|
|
734
|
-
readonly code: Schema.optional<Schema.
|
|
735
|
-
readonly message: Schema.optional<Schema.
|
|
736
|
-
readonly
|
|
737
|
-
readonly error: Schema.optional<Schema.NullOr<Schema.decodeTo<Schema.Struct<{
|
|
738
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
739
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
740
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
741
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
742
|
-
}>, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
743
|
-
readonly type: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
744
|
-
readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
745
|
-
readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
746
|
-
readonly param: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
747
|
-
}>]>, never, never>>>;
|
|
613
|
+
readonly code: Schema.optional<Schema.Unknown>;
|
|
614
|
+
readonly message: Schema.optional<Schema.Unknown>;
|
|
615
|
+
readonly error: Schema.optional<Schema.Unknown>;
|
|
748
616
|
readonly status: Schema.optional<Schema.Unknown>;
|
|
749
617
|
readonly status_code: Schema.optional<Schema.Unknown>;
|
|
750
|
-
|
|
751
|
-
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, never, never>;
|
|
618
|
+
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
|
|
752
619
|
export type Event = Schema.Schema.Type<typeof Event>;
|
|
753
620
|
export type NormalizedEvent = Event & {
|
|
754
621
|
readonly item?: OutputItem | null;
|
|
755
622
|
};
|
|
756
623
|
/**
|
|
757
|
-
* Decodes one WebSocket frame.
|
|
758
|
-
* event type; that
|
|
624
|
+
* Decodes one WebSocket frame. Some providers and gateways answer a rejected `response.create` with a bare
|
|
625
|
+
* `{ "error": ... }` envelope and no event type; that reads as an error event so it classifies instead of
|
|
626
|
+
* failing decoding.
|
|
759
627
|
*/
|
|
760
628
|
export declare const decodeChannelEvent: (frame: string) => Effect.Effect<{
|
|
761
629
|
readonly [x: string]: unknown;
|
|
762
630
|
readonly type: string;
|
|
763
631
|
readonly status?: unknown;
|
|
764
|
-
readonly code?:
|
|
765
|
-
readonly message?:
|
|
766
|
-
readonly headers?: unknown;
|
|
632
|
+
readonly code?: unknown;
|
|
633
|
+
readonly message?: unknown;
|
|
767
634
|
readonly text?: string | undefined;
|
|
768
|
-
readonly error?:
|
|
769
|
-
readonly type?: string | null | undefined;
|
|
770
|
-
readonly code?: string | null | undefined;
|
|
771
|
-
readonly message?: string | null | undefined;
|
|
772
|
-
readonly param?: string | null | undefined;
|
|
773
|
-
} | null | undefined;
|
|
635
|
+
readonly error?: unknown;
|
|
774
636
|
readonly item?: {
|
|
775
637
|
readonly [x: string]: unknown;
|
|
776
638
|
readonly type: string;
|
|
@@ -795,12 +657,7 @@ export declare const decodeChannelEvent: (frame: string) => Effect.Effect<{
|
|
|
795
657
|
readonly encrypted_content?: string | null | undefined;
|
|
796
658
|
readonly call_id?: string | undefined;
|
|
797
659
|
}[] | undefined;
|
|
798
|
-
readonly error?:
|
|
799
|
-
readonly type?: string | null | undefined;
|
|
800
|
-
readonly code?: string | null | undefined;
|
|
801
|
-
readonly message?: string | null | undefined;
|
|
802
|
-
readonly param?: string | null | undefined;
|
|
803
|
-
} | null | undefined;
|
|
660
|
+
readonly error?: unknown;
|
|
804
661
|
readonly usage?: {
|
|
805
662
|
readonly input_tokens?: number | undefined;
|
|
806
663
|
readonly output_tokens?: number | undefined;
|
|
@@ -819,11 +676,10 @@ export declare const decodeChannelEvent: (frame: string) => Effect.Effect<{
|
|
|
819
676
|
} | null | undefined;
|
|
820
677
|
} | undefined;
|
|
821
678
|
readonly arguments?: string | undefined;
|
|
822
|
-
readonly param?: string | null | undefined;
|
|
823
|
-
readonly status_code?: unknown;
|
|
824
679
|
readonly item_id?: string | undefined;
|
|
825
680
|
readonly output_index?: number | undefined;
|
|
826
681
|
readonly summary_index?: number | undefined;
|
|
682
|
+
readonly status_code?: unknown;
|
|
827
683
|
}, Schema.SchemaError, never>;
|
|
828
684
|
export interface ProviderAdapter {
|
|
829
685
|
readonly id: string;
|
|
@@ -1146,6 +1002,11 @@ export declare const terminal: (event: Event) => boolean;
|
|
|
1146
1002
|
export declare const normalize: (state: Pick<ParserState, "outputItems">, input: Event) => NormalizedEvent;
|
|
1147
1003
|
export declare const onReasoningDelta: (state: ParserState, event: Event, itemID: string) => StepResult;
|
|
1148
1004
|
export declare const onReasoningDone: (state: ParserState, event: Event, itemID: string) => StepResult;
|
|
1005
|
+
/** Error code and message from wherever the frame put them; top-level fields win over nested ones. */
|
|
1006
|
+
export declare const errorDetail: (event: Event) => {
|
|
1007
|
+
message: string | undefined;
|
|
1008
|
+
code: string | undefined;
|
|
1009
|
+
};
|
|
1149
1010
|
export declare const providerFailure: (event: Event, fallback: string, body?: string) => AIError;
|
|
1150
1011
|
export declare const step: (state: ParserState, event: NormalizedEvent) => AIError | Effect.Effect<[ParserState, readonly (({
|
|
1151
1012
|
readonly type: "compaction";
|
|
@@ -1525,16 +1386,10 @@ export declare const protocol: Protocol<{
|
|
|
1525
1386
|
readonly [x: string]: unknown;
|
|
1526
1387
|
readonly type: string;
|
|
1527
1388
|
readonly status?: unknown;
|
|
1528
|
-
readonly code?:
|
|
1529
|
-
readonly message?:
|
|
1530
|
-
readonly headers?: unknown;
|
|
1389
|
+
readonly code?: unknown;
|
|
1390
|
+
readonly message?: unknown;
|
|
1531
1391
|
readonly text?: string | undefined;
|
|
1532
|
-
readonly error?:
|
|
1533
|
-
readonly type?: string | null | undefined;
|
|
1534
|
-
readonly code?: string | null | undefined;
|
|
1535
|
-
readonly message?: string | null | undefined;
|
|
1536
|
-
readonly param?: string | null | undefined;
|
|
1537
|
-
} | null | undefined;
|
|
1392
|
+
readonly error?: unknown;
|
|
1538
1393
|
readonly item?: {
|
|
1539
1394
|
readonly [x: string]: unknown;
|
|
1540
1395
|
readonly type: string;
|
|
@@ -1559,12 +1414,7 @@ export declare const protocol: Protocol<{
|
|
|
1559
1414
|
readonly encrypted_content?: string | null | undefined;
|
|
1560
1415
|
readonly call_id?: string | undefined;
|
|
1561
1416
|
}[] | undefined;
|
|
1562
|
-
readonly error?:
|
|
1563
|
-
readonly type?: string | null | undefined;
|
|
1564
|
-
readonly code?: string | null | undefined;
|
|
1565
|
-
readonly message?: string | null | undefined;
|
|
1566
|
-
readonly param?: string | null | undefined;
|
|
1567
|
-
} | null | undefined;
|
|
1417
|
+
readonly error?: unknown;
|
|
1568
1418
|
readonly usage?: {
|
|
1569
1419
|
readonly input_tokens?: number | undefined;
|
|
1570
1420
|
readonly output_tokens?: number | undefined;
|
|
@@ -1583,11 +1433,10 @@ export declare const protocol: Protocol<{
|
|
|
1583
1433
|
} | null | undefined;
|
|
1584
1434
|
} | undefined;
|
|
1585
1435
|
readonly arguments?: string | undefined;
|
|
1586
|
-
readonly param?: string | null | undefined;
|
|
1587
|
-
readonly status_code?: unknown;
|
|
1588
1436
|
readonly item_id?: string | undefined;
|
|
1589
1437
|
readonly output_index?: number | undefined;
|
|
1590
1438
|
readonly summary_index?: number | undefined;
|
|
1439
|
+
readonly status_code?: unknown;
|
|
1591
1440
|
}, ParserState>;
|
|
1592
1441
|
export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
1593
1442
|
readonly input: readonly ({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Option, Schema
|
|
1
|
+
import { Effect, Option, Schema } from "effect";
|
|
2
2
|
import { HttpTransport } from "../route/transport/index.js";
|
|
3
3
|
import { Protocol } from "../route/protocol.js";
|
|
4
4
|
import { AIError, LLMEvent, ProviderInternalError, Usage, } from "../schema/index.js";
|
|
@@ -237,39 +237,12 @@ export const StreamItem = Schema.StructWithRest(Schema.Struct({
|
|
|
237
237
|
arguments: Schema.optional(Schema.String),
|
|
238
238
|
encrypted_content: optionalNull(Schema.String),
|
|
239
239
|
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
240
|
-
// Responses-compatible providers put
|
|
241
|
-
//
|
|
240
|
+
// Responses-compatible providers put error details at the top level, under `error`, or under
|
|
241
|
+
// `response.error`, and gateways reshape them freely: strings, numeric codes, extra fields. Those
|
|
242
|
+
// fields decode as opaque values and `errorDetail` reads them defensively, so an error frame can
|
|
243
|
+
// only fail on invalid JSON and otherwise always classifies with the raw body as the fallback.
|
|
242
244
|
// https://www.openresponses.org/specification
|
|
243
|
-
const
|
|
244
|
-
type: optionalNull(Schema.String),
|
|
245
|
-
code: optionalNull(Schema.String),
|
|
246
|
-
message: optionalNull(Schema.String),
|
|
247
|
-
param: optionalNull(Schema.String),
|
|
248
|
-
});
|
|
249
|
-
const OpenResponsesErrorPayload = Schema.Union([Schema.String, OpenResponsesErrorObject]).pipe(Schema.decodeTo(OpenResponsesErrorObject, {
|
|
250
|
-
decode: SchemaGetter.transform((error) => (typeof error === "string" ? { message: error } : error)),
|
|
251
|
-
encode: SchemaGetter.passthrough(),
|
|
252
|
-
}));
|
|
253
|
-
const WebSocketErrorHeader = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]);
|
|
254
|
-
export const WebSocketErrorEvent = Schema.StructWithRest(Schema.Struct({
|
|
255
|
-
type: Schema.tag("error"),
|
|
256
|
-
status: Schema.optional(Schema.Number),
|
|
257
|
-
status_code: Schema.optional(Schema.Number),
|
|
258
|
-
code: optionalNull(Schema.String),
|
|
259
|
-
message: Schema.optional(Schema.String),
|
|
260
|
-
param: optionalNull(Schema.String),
|
|
261
|
-
error: optionalNull(OpenResponsesErrorPayload),
|
|
262
|
-
headers: Schema.optional(Schema.Record(Schema.String, WebSocketErrorHeader)),
|
|
263
|
-
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
264
|
-
const decodeWebSocketErrorEvent = Schema.decodeUnknownEffect(WebSocketErrorEvent);
|
|
265
|
-
export const decodeKnownErrorEvent = (event) => decodeWebSocketErrorEvent({
|
|
266
|
-
...event,
|
|
267
|
-
status: typeof event.status === "number" ? event.status : undefined,
|
|
268
|
-
status_code: typeof event.status_code === "number" ? event.status_code : undefined,
|
|
269
|
-
headers: ProviderShared.isRecord(event.headers)
|
|
270
|
-
? Object.fromEntries(Object.entries(event.headers).filter((entry) => typeof entry[1] === "string" || typeof entry[1] === "number" || typeof entry[1] === "boolean"))
|
|
271
|
-
: undefined,
|
|
272
|
-
});
|
|
245
|
+
const asText = (value) => typeof value === "string" && value.length > 0 ? value : typeof value === "number" ? String(value) : undefined;
|
|
273
246
|
export const Event = Schema.StructWithRest(Schema.Struct({
|
|
274
247
|
type: Schema.String,
|
|
275
248
|
delta: Schema.optional(Schema.String),
|
|
@@ -286,36 +259,22 @@ export const Event = Schema.StructWithRest(Schema.Struct({
|
|
|
286
259
|
incomplete_details: optionalNull(Schema.Struct({ reason: Schema.optional(Schema.String) })),
|
|
287
260
|
output: Schema.optional(Schema.Array(StreamItem)),
|
|
288
261
|
usage: optionalNull(OpenResponsesUsage),
|
|
289
|
-
error:
|
|
262
|
+
error: Schema.optional(Schema.Unknown),
|
|
290
263
|
}), [Schema.Record(Schema.String, Schema.Unknown)])),
|
|
291
|
-
code:
|
|
292
|
-
message: Schema.optional(Schema.
|
|
293
|
-
|
|
294
|
-
error: optionalNull(OpenResponsesErrorPayload),
|
|
264
|
+
code: Schema.optional(Schema.Unknown),
|
|
265
|
+
message: Schema.optional(Schema.Unknown),
|
|
266
|
+
error: Schema.optional(Schema.Unknown),
|
|
295
267
|
status: Schema.optional(Schema.Unknown),
|
|
296
268
|
status_code: Schema.optional(Schema.Unknown),
|
|
297
|
-
|
|
298
|
-
}), [Schema.Record(Schema.String, Schema.Unknown)]).pipe(Schema.decode({
|
|
299
|
-
decode: SchemaGetter.transform((event) => {
|
|
300
|
-
if (event.type !== "error" || event.error != null)
|
|
301
|
-
return event;
|
|
302
|
-
const { code, message, param, ...rest } = event;
|
|
303
|
-
if (code === undefined && message === undefined && param === undefined)
|
|
304
|
-
return event;
|
|
305
|
-
// Flat errors (for example, Meta's) can also arrive through generic Responses endpoints.
|
|
306
|
-
return { ...rest, error: { code, message, param } };
|
|
307
|
-
}),
|
|
308
|
-
encode: SchemaGetter.passthrough(),
|
|
309
|
-
}));
|
|
269
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
310
270
|
const decodeEventValue = Schema.decodeUnknownEffect(Event);
|
|
311
271
|
const decodeFrame = Schema.decodeUnknownEffect(ProviderShared.Json);
|
|
312
272
|
/**
|
|
313
|
-
* Decodes one WebSocket frame.
|
|
314
|
-
* event type; that
|
|
273
|
+
* Decodes one WebSocket frame. Some providers and gateways answer a rejected `response.create` with a bare
|
|
274
|
+
* `{ "error": ... }` envelope and no event type; that reads as an error event so it classifies instead of
|
|
275
|
+
* failing decoding.
|
|
315
276
|
*/
|
|
316
|
-
export const decodeChannelEvent = (frame) => decodeFrame(frame).pipe(Effect.flatMap((value) => decodeEventValue(ProviderShared.isRecord(value) &&
|
|
317
|
-
value.type === undefined &&
|
|
318
|
-
(typeof value.error === "string" || ProviderShared.isRecord(value.error))
|
|
277
|
+
export const decodeChannelEvent = (frame) => decodeFrame(frame).pipe(Effect.flatMap((value) => decodeEventValue(ProviderShared.isRecord(value) && value.type === undefined && value.error != null
|
|
319
278
|
? { ...value, type: "error" }
|
|
320
279
|
: value)));
|
|
321
280
|
const BASE_ADAPTER = { id: ADAPTER, name: NAME };
|
|
@@ -1121,22 +1080,20 @@ const onResponseFinish = Effect.fn("OpenResponses.onResponseFinish")(function* (
|
|
|
1121
1080
|
});
|
|
1122
1081
|
return [{ ...current, lifecycle }, events];
|
|
1123
1082
|
});
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
const code = event.code || nested?.code || undefined;
|
|
1133
|
-
if (message && code)
|
|
1134
|
-
return `${code}: ${message}`;
|
|
1135
|
-
return message || code;
|
|
1083
|
+
/** Error code and message from wherever the frame put them; top-level fields win over nested ones. */
|
|
1084
|
+
export const errorDetail = (event) => {
|
|
1085
|
+
const raw = event.error ?? event.response?.error;
|
|
1086
|
+
const nested = typeof raw === "string" ? { message: raw } : ProviderShared.isRecord(raw) ? raw : undefined;
|
|
1087
|
+
return {
|
|
1088
|
+
message: asText(event.message) ?? asText(nested?.message),
|
|
1089
|
+
code: asText(event.code) ?? asText(nested?.code),
|
|
1090
|
+
};
|
|
1136
1091
|
};
|
|
1092
|
+
// Prefix the code when both are present (`rate_limit_exceeded: Slow down`) so the failure mode is
|
|
1093
|
+
// visible; fall back to the raw frame rather than a generic message when neither decodes.
|
|
1137
1094
|
export const providerFailure = (event, fallback, body = ProviderShared.encodeJson(event)) => {
|
|
1138
|
-
const
|
|
1139
|
-
const summary =
|
|
1095
|
+
const detail = errorDetail(event);
|
|
1096
|
+
const summary = detail.message && detail.code ? `${detail.code}: ${detail.message}` : (detail.message ?? detail.code);
|
|
1140
1097
|
const message = summary ?? (body === "{}" ? fallback : body);
|
|
1141
1098
|
const status = typeof event.status === "number"
|
|
1142
1099
|
? event.status
|
|
@@ -1210,7 +1167,7 @@ export const step = (state, event) => {
|
|
|
1210
1167
|
if (event.type === "response.failed")
|
|
1211
1168
|
return providerFailure(event, `${state.name} response failed`);
|
|
1212
1169
|
if (event.type === "error")
|
|
1213
|
-
return
|
|
1170
|
+
return providerFailure(event, `${state.name} stream error`);
|
|
1214
1171
|
return Effect.succeed([state, NO_EVENTS]);
|
|
1215
1172
|
};
|
|
1216
1173
|
// =============================================================================
|
|
@@ -450,16 +450,10 @@ export declare const protocol: Protocol<{
|
|
|
450
450
|
readonly [x: string]: unknown;
|
|
451
451
|
readonly type: string;
|
|
452
452
|
readonly status?: unknown;
|
|
453
|
-
readonly code?:
|
|
454
|
-
readonly message?:
|
|
455
|
-
readonly headers?: unknown;
|
|
453
|
+
readonly code?: unknown;
|
|
454
|
+
readonly message?: unknown;
|
|
456
455
|
readonly text?: string | undefined;
|
|
457
|
-
readonly error?:
|
|
458
|
-
readonly type?: string | null | undefined;
|
|
459
|
-
readonly code?: string | null | undefined;
|
|
460
|
-
readonly message?: string | null | undefined;
|
|
461
|
-
readonly param?: string | null | undefined;
|
|
462
|
-
} | null | undefined;
|
|
456
|
+
readonly error?: unknown;
|
|
463
457
|
readonly item?: {
|
|
464
458
|
readonly [x: string]: unknown;
|
|
465
459
|
readonly type: string;
|
|
@@ -484,12 +478,7 @@ export declare const protocol: Protocol<{
|
|
|
484
478
|
readonly encrypted_content?: string | null | undefined;
|
|
485
479
|
readonly call_id?: string | undefined;
|
|
486
480
|
}[] | undefined;
|
|
487
|
-
readonly error?:
|
|
488
|
-
readonly type?: string | null | undefined;
|
|
489
|
-
readonly code?: string | null | undefined;
|
|
490
|
-
readonly message?: string | null | undefined;
|
|
491
|
-
readonly param?: string | null | undefined;
|
|
492
|
-
} | null | undefined;
|
|
481
|
+
readonly error?: unknown;
|
|
493
482
|
readonly usage?: {
|
|
494
483
|
readonly input_tokens?: number | undefined;
|
|
495
484
|
readonly output_tokens?: number | undefined;
|
|
@@ -508,11 +497,10 @@ export declare const protocol: Protocol<{
|
|
|
508
497
|
} | null | undefined;
|
|
509
498
|
} | undefined;
|
|
510
499
|
readonly arguments?: string | undefined;
|
|
511
|
-
readonly param?: string | null | undefined;
|
|
512
|
-
readonly status_code?: unknown;
|
|
513
500
|
readonly item_id?: string | undefined;
|
|
514
501
|
readonly output_index?: number | undefined;
|
|
515
502
|
readonly summary_index?: number | undefined;
|
|
503
|
+
readonly status_code?: unknown;
|
|
516
504
|
}, OpenResponses.ParserState>;
|
|
517
505
|
export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
518
506
|
readonly input: readonly ({
|
|
@@ -184,16 +184,10 @@ export declare const protocol: Protocol<{
|
|
|
184
184
|
readonly [x: string]: unknown;
|
|
185
185
|
readonly type: string;
|
|
186
186
|
readonly status?: unknown;
|
|
187
|
-
readonly code?:
|
|
188
|
-
readonly message?:
|
|
189
|
-
readonly headers?: unknown;
|
|
187
|
+
readonly code?: unknown;
|
|
188
|
+
readonly message?: unknown;
|
|
190
189
|
readonly text?: string | undefined;
|
|
191
|
-
readonly error?:
|
|
192
|
-
readonly type?: string | null | undefined;
|
|
193
|
-
readonly code?: string | null | undefined;
|
|
194
|
-
readonly message?: string | null | undefined;
|
|
195
|
-
readonly param?: string | null | undefined;
|
|
196
|
-
} | null | undefined;
|
|
190
|
+
readonly error?: unknown;
|
|
197
191
|
readonly item?: {
|
|
198
192
|
readonly [x: string]: unknown;
|
|
199
193
|
readonly type: string;
|
|
@@ -218,12 +212,7 @@ export declare const protocol: Protocol<{
|
|
|
218
212
|
readonly encrypted_content?: string | null | undefined;
|
|
219
213
|
readonly call_id?: string | undefined;
|
|
220
214
|
}[] | undefined;
|
|
221
|
-
readonly error?:
|
|
222
|
-
readonly type?: string | null | undefined;
|
|
223
|
-
readonly code?: string | null | undefined;
|
|
224
|
-
readonly message?: string | null | undefined;
|
|
225
|
-
readonly param?: string | null | undefined;
|
|
226
|
-
} | null | undefined;
|
|
215
|
+
readonly error?: unknown;
|
|
227
216
|
readonly usage?: {
|
|
228
217
|
readonly input_tokens?: number | undefined;
|
|
229
218
|
readonly output_tokens?: number | undefined;
|
|
@@ -242,11 +231,10 @@ export declare const protocol: Protocol<{
|
|
|
242
231
|
} | null | undefined;
|
|
243
232
|
} | undefined;
|
|
244
233
|
readonly arguments?: string | undefined;
|
|
245
|
-
readonly param?: string | null | undefined;
|
|
246
|
-
readonly status_code?: unknown;
|
|
247
234
|
readonly item_id?: string | undefined;
|
|
248
235
|
readonly output_index?: number | undefined;
|
|
249
236
|
readonly summary_index?: number | undefined;
|
|
237
|
+
readonly status_code?: unknown;
|
|
250
238
|
}, OpenResponses.ParserState>;
|
|
251
239
|
export declare const compact: import("../route/client.js").CompactOperation;
|
|
252
240
|
export * as XAIResponses from "./xai-responses.js";
|
|
@@ -145,7 +145,9 @@ export const open = (input) => Effect.gen(function* () {
|
|
|
145
145
|
});
|
|
146
146
|
export const fromWebSocket = (ws, input) => Effect.gen(function* () {
|
|
147
147
|
yield* waitOpen(ws, input);
|
|
148
|
-
|
|
148
|
+
// The socket pushes frames synchronously and cannot be paused, so the hand-off to the consumer
|
|
149
|
+
// fiber must absorb whole read buffers. Bun delivers over a thousand small frames in one tick.
|
|
150
|
+
const messages = yield* Queue.unbounded();
|
|
149
151
|
const oversized = (message) => typeof message === "string" ? new Blob([message]).size > MAX_FRAME_BYTES : message.byteLength > MAX_FRAME_BYTES;
|
|
150
152
|
const rejectOversized = (message) => {
|
|
151
153
|
if (!oversized(message))
|
|
@@ -164,15 +166,7 @@ export const fromWebSocket = (ws, input) => Effect.gen(function* () {
|
|
|
164
166
|
const offer = (message) => {
|
|
165
167
|
if (rejectOversized(message))
|
|
166
168
|
return;
|
|
167
|
-
|
|
168
|
-
return;
|
|
169
|
-
Queue.failCauseUnsafe(messages, Cause.fail(transportError("WebSocket inbound queue overflow", {
|
|
170
|
-
body: typeof message === "string" ? message : new TextDecoder().decode(message),
|
|
171
|
-
url: input.url,
|
|
172
|
-
operation: "read",
|
|
173
|
-
code: "queue-overflow",
|
|
174
|
-
phase: "receive",
|
|
175
|
-
})));
|
|
169
|
+
Queue.offerUnsafe(messages, message);
|
|
176
170
|
};
|
|
177
171
|
const onMessage = (event) => {
|
|
178
172
|
if (typeof event.data === "string")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
32
32
|
"@effect/platform-node": "4.0.0-rc.112",
|
|
33
|
-
"@opencode/http-recorder": "2.0.
|
|
33
|
+
"@opencode/http-recorder": "2.0.11",
|
|
34
34
|
"@tsconfig/bun": "1.0.9",
|
|
35
35
|
"@types/bun": "1.4.0",
|
|
36
36
|
"@typescript/native-preview": "7.0.0-dev.20251207.1",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
41
41
|
"@smithy/eventstream-codec": "4.2.14",
|
|
42
42
|
"@smithy/util-utf8": "4.2.2",
|
|
43
|
-
"@opencode/schema": "2.0.
|
|
43
|
+
"@opencode/schema": "2.0.11",
|
|
44
44
|
"aws4fetch": "1.0.20",
|
|
45
45
|
"effect": "4.0.0-rc.112",
|
|
46
46
|
"google-auth-library": "10.5.0"
|