@opencode/ai 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -18
- package/dist/cache-policy.js +4 -2
- package/dist/effect.d.ts +3 -1
- package/dist/generation.d.ts +10 -10
- package/dist/generation.js +8 -14
- package/dist/image-client.d.ts +56 -59
- package/dist/image-client.js +47 -8
- package/dist/image.d.ts +36 -95
- package/dist/image.js +11 -14
- package/dist/index.d.ts +25 -25
- package/dist/index.js +29 -22
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +10 -1
- package/dist/media-client.d.ts +18 -6
- package/dist/media-client.js +42 -37
- package/dist/media.d.ts +17 -1
- package/dist/media.js +28 -7
- package/dist/protocols/alibaba-messages.d.ts +24 -2
- package/dist/protocols/alibaba-responses.d.ts +26 -0
- package/dist/protocols/anthropic-messages.d.ts +70 -6
- package/dist/protocols/anthropic-messages.js +74 -9
- package/dist/protocols/assemblyai-transcription.js +7 -6
- package/dist/protocols/cartesia-speech.d.ts +0 -8
- package/dist/protocols/deepgram-speech.d.ts +0 -8
- package/dist/protocols/elevenlabs-speech.d.ts +0 -8
- package/dist/protocols/google-interactions-video.d.ts +4 -9
- package/dist/protocols/google-interactions-video.js +9 -10
- package/dist/protocols/google-speech.d.ts +0 -8
- package/dist/protocols/google-transcription.d.ts +0 -8
- package/dist/protocols/meta-messages.d.ts +24 -2
- package/dist/protocols/meta-responses.d.ts +52 -0
- package/dist/protocols/minimax-video.d.ts +6 -15
- package/dist/protocols/minimax-video.js +25 -27
- package/dist/protocols/open-responses.d.ts +250 -24
- package/dist/protocols/open-responses.js +40 -24
- package/dist/protocols/openai-chat.js +7 -3
- package/dist/protocols/openai-compatible-responses.d.ts +26 -0
- package/dist/protocols/openai-freeform.d.ts +1 -1
- package/dist/protocols/openai-freeform.js +9 -5
- package/dist/protocols/openai-images.d.ts +0 -8
- package/dist/protocols/openai-responses.d.ts +153 -0
- package/dist/protocols/openai-responses.js +68 -7
- package/dist/protocols/openai-speech.d.ts +0 -8
- package/dist/protocols/openai-transcription.d.ts +0 -8
- package/dist/protocols/openrouter-video.d.ts +4 -9
- package/dist/protocols/openrouter-video.js +14 -13
- package/dist/protocols/seedance-video.d.ts +4 -9
- package/dist/protocols/seedance-video.js +13 -12
- package/dist/protocols/utils/gateway-protocol.js +1 -0
- package/dist/protocols/utils/responses-compaction.js +7 -3
- package/dist/protocols/xai-responses.d.ts +26 -0
- package/dist/protocols/xai-video.d.ts +4 -9
- package/dist/protocols/xai-video.js +13 -9
- package/dist/protocols/zai-messages.d.ts +24 -2
- package/dist/providers/alibaba.d.ts +50 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
- package/dist/providers/anthropic-compatible.d.ts +24 -2
- package/dist/providers/anthropic.d.ts +24 -2
- package/dist/providers/azure.d.ts +76 -2
- package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
- package/dist/providers/digitalocean.d.ts +26 -0
- package/dist/providers/google-vertex-messages.d.ts +24 -2
- package/dist/providers/google-vertex-messages.js +1 -0
- package/dist/providers/google-vertex-responses.d.ts +26 -0
- package/dist/providers/google.d.ts +3 -3
- package/dist/providers/google.js +5 -2
- package/dist/providers/meta.d.ts +50 -2
- package/dist/providers/minimax.d.ts +50 -2
- package/dist/providers/moonshot.d.ts +50 -2
- package/dist/providers/openai-compatible-responses.d.ts +26 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openrouter.d.ts +26 -0
- package/dist/providers/venice.d.ts +26 -0
- package/dist/providers/xai/videos.d.ts +2 -0
- package/dist/providers/xai/videos.js +1 -0
- package/dist/providers/xai.d.ts +4 -3
- package/dist/providers/xai.js +5 -1
- package/dist/providers/zai-coding-plan.d.ts +50 -2
- package/dist/public.d.ts +5 -4
- package/dist/public.js +1 -1
- package/dist/route/client.d.ts +2 -0
- package/dist/route/client.js +5 -1
- package/dist/route/executor-service.d.ts +14 -1
- package/dist/route/executor-service.js +28 -1
- package/dist/route/executor.d.ts +5 -2
- package/dist/route/executor.js +20 -5
- package/dist/route/media-protocol.d.ts +12 -7
- package/dist/route/media-protocol.js +11 -4
- package/dist/route/media.js +12 -3
- package/dist/route/protocol.d.ts +3 -0
- package/dist/schema/events.d.ts +5 -0
- package/dist/schema/messages.d.ts +24 -1
- package/dist/schema/messages.js +26 -2
- package/dist/schema/options.d.ts +10 -2
- package/dist/speech-client.d.ts +5 -5
- package/dist/speech.d.ts +7 -88
- package/dist/speech.js +1 -3
- package/dist/tool-updates.d.ts +34 -0
- package/dist/tool-updates.js +93 -0
- package/dist/tool.d.ts +6 -1
- package/dist/tool.js +1 -1
- package/dist/transcription-client.d.ts +5 -5
- package/dist/transcription.d.ts +7 -88
- package/dist/transcription.js +1 -3
- package/dist/video-client.d.ts +6 -6
- package/dist/video-client.js +13 -11
- package/dist/video.d.ts +17 -73
- package/dist/video.js +9 -8
- package/package.json +7 -3
package/dist/speech.d.ts
CHANGED
|
@@ -186,10 +186,6 @@ export declare const SpeechFinishEvent: Schema.Struct<{
|
|
|
186
186
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
187
187
|
}>;
|
|
188
188
|
declare const speechEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
189
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
190
|
-
readonly id: Schema.String;
|
|
191
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
192
|
-
}>, Schema.Struct<{
|
|
193
189
|
readonly type: Schema.tag<"generation-progress">;
|
|
194
190
|
readonly id: Schema.String;
|
|
195
191
|
readonly progress: Schema.optional<Schema.Number>;
|
|
@@ -258,10 +254,6 @@ declare const speechEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.S
|
|
|
258
254
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
259
255
|
}>]>;
|
|
260
256
|
export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
261
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
262
|
-
readonly id: Schema.String;
|
|
263
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
264
|
-
}>, Schema.Struct<{
|
|
265
257
|
readonly type: Schema.tag<"generation-progress">;
|
|
266
258
|
readonly id: Schema.String;
|
|
267
259
|
readonly progress: Schema.optional<Schema.Number>;
|
|
@@ -330,7 +322,7 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
330
322
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
331
323
|
}>]> & {
|
|
332
324
|
readonly tag: "type";
|
|
333
|
-
readonly discriminants: readonly ["generation-
|
|
325
|
+
readonly discriminants: readonly ["generation-progress", "audio-delta", "timestamps", "finish"];
|
|
334
326
|
readonly cases: {
|
|
335
327
|
"audio-delta": Schema.Struct<{
|
|
336
328
|
readonly type: Schema.tag<"audio-delta">;
|
|
@@ -395,11 +387,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
395
387
|
readonly id: Schema.String;
|
|
396
388
|
readonly progress: Schema.optional<Schema.Number>;
|
|
397
389
|
}>;
|
|
398
|
-
"generation-queued": Schema.Struct<{
|
|
399
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
400
|
-
readonly id: Schema.String;
|
|
401
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
402
|
-
}>;
|
|
403
390
|
timestamps: Schema.Struct<{
|
|
404
391
|
readonly type: Schema.tag<"timestamps">;
|
|
405
392
|
readonly items: Schema.$Array<Schema.Struct<{
|
|
@@ -419,10 +406,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
419
406
|
readonly startSeconds: number;
|
|
420
407
|
readonly endSeconds: number;
|
|
421
408
|
}[];
|
|
422
|
-
} | {
|
|
423
|
-
readonly type: "generation-queued";
|
|
424
|
-
readonly id: string;
|
|
425
|
-
readonly position?: number | undefined;
|
|
426
409
|
} | {
|
|
427
410
|
readonly type: "generation-progress";
|
|
428
411
|
readonly id: string;
|
|
@@ -470,12 +453,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
470
453
|
}[];
|
|
471
454
|
}, {
|
|
472
455
|
readonly type: Keys;
|
|
473
|
-
}> | Extract<{
|
|
474
|
-
readonly type: "generation-queued";
|
|
475
|
-
readonly id: string;
|
|
476
|
-
readonly position?: number | undefined;
|
|
477
|
-
}, {
|
|
478
|
-
readonly type: Keys;
|
|
479
456
|
}> | Extract<{
|
|
480
457
|
readonly type: "generation-progress";
|
|
481
458
|
readonly id: string;
|
|
@@ -554,11 +531,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
554
531
|
readonly id: string;
|
|
555
532
|
readonly progress?: number | undefined;
|
|
556
533
|
};
|
|
557
|
-
"generation-queued": (u: unknown) => u is {
|
|
558
|
-
readonly type: "generation-queued";
|
|
559
|
-
readonly id: string;
|
|
560
|
-
readonly position?: number | undefined;
|
|
561
|
-
};
|
|
562
534
|
timestamps: (u: unknown) => u is {
|
|
563
535
|
readonly type: "timestamps";
|
|
564
536
|
readonly items: readonly {
|
|
@@ -569,7 +541,7 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
569
541
|
};
|
|
570
542
|
};
|
|
571
543
|
readonly match: {
|
|
572
|
-
<Handlers extends { [K in "audio-delta" | "finish" | "generation-progress" | "
|
|
544
|
+
<Handlers extends { [K in "audio-delta" | "finish" | "generation-progress" | "timestamps"]: (value: {
|
|
573
545
|
readonly "audio-delta": Schema.Struct<{
|
|
574
546
|
readonly type: Schema.tag<"audio-delta">;
|
|
575
547
|
readonly chunk: Schema.Uint8Array;
|
|
@@ -633,11 +605,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
633
605
|
readonly id: Schema.String;
|
|
634
606
|
readonly progress: Schema.optional<Schema.Number>;
|
|
635
607
|
}>;
|
|
636
|
-
readonly "generation-queued": Schema.Struct<{
|
|
637
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
638
|
-
readonly id: Schema.String;
|
|
639
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
640
|
-
}>;
|
|
641
608
|
readonly timestamps: Schema.Struct<{
|
|
642
609
|
readonly type: Schema.tag<"timestamps">;
|
|
643
610
|
readonly items: Schema.$Array<Schema.Struct<{
|
|
@@ -656,10 +623,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
656
623
|
readonly startSeconds: number;
|
|
657
624
|
readonly endSeconds: number;
|
|
658
625
|
}[];
|
|
659
|
-
} | {
|
|
660
|
-
readonly type: "generation-queued";
|
|
661
|
-
readonly id: string;
|
|
662
|
-
readonly position?: number | undefined;
|
|
663
626
|
} | {
|
|
664
627
|
readonly type: "generation-progress";
|
|
665
628
|
readonly id: string;
|
|
@@ -693,8 +656,8 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
693
656
|
readonly [x: string]: unknown;
|
|
694
657
|
};
|
|
695
658
|
} | undefined;
|
|
696
|
-
}, cases: Handlers): import("effect/Unify").Unify<ReturnType<Handlers["audio-delta" | "finish" | "generation-progress" | "
|
|
697
|
-
<Handlers extends { [K in "audio-delta" | "finish" | "generation-progress" | "
|
|
659
|
+
}, cases: Handlers): import("effect/Unify").Unify<ReturnType<Handlers["audio-delta" | "finish" | "generation-progress" | "timestamps"]>>;
|
|
660
|
+
<Handlers extends { [K in "audio-delta" | "finish" | "generation-progress" | "timestamps"]: (value: {
|
|
698
661
|
readonly "audio-delta": Schema.Struct<{
|
|
699
662
|
readonly type: Schema.tag<"audio-delta">;
|
|
700
663
|
readonly chunk: Schema.Uint8Array;
|
|
@@ -758,11 +721,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
758
721
|
readonly id: Schema.String;
|
|
759
722
|
readonly progress: Schema.optional<Schema.Number>;
|
|
760
723
|
}>;
|
|
761
|
-
readonly "generation-queued": Schema.Struct<{
|
|
762
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
763
|
-
readonly id: Schema.String;
|
|
764
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
765
|
-
}>;
|
|
766
724
|
readonly timestamps: Schema.Struct<{
|
|
767
725
|
readonly type: Schema.tag<"timestamps">;
|
|
768
726
|
readonly items: Schema.$Array<Schema.Struct<{
|
|
@@ -781,10 +739,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
781
739
|
readonly startSeconds: number;
|
|
782
740
|
readonly endSeconds: number;
|
|
783
741
|
}[];
|
|
784
|
-
} | {
|
|
785
|
-
readonly type: "generation-queued";
|
|
786
|
-
readonly id: string;
|
|
787
|
-
readonly position?: number | undefined;
|
|
788
742
|
} | {
|
|
789
743
|
readonly type: "generation-progress";
|
|
790
744
|
readonly id: string;
|
|
@@ -818,7 +772,7 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
818
772
|
readonly [x: string]: unknown;
|
|
819
773
|
};
|
|
820
774
|
} | undefined;
|
|
821
|
-
}) => import("effect/Unify").Unify<ReturnType<Handlers["audio-delta" | "finish" | "generation-progress" | "
|
|
775
|
+
}) => import("effect/Unify").Unify<ReturnType<Handlers["audio-delta" | "finish" | "generation-progress" | "timestamps"]>>;
|
|
822
776
|
};
|
|
823
777
|
readonly matchOrElse: {
|
|
824
778
|
<Handlers, OrElse>(value: {
|
|
@@ -831,10 +785,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
831
785
|
readonly startSeconds: number;
|
|
832
786
|
readonly endSeconds: number;
|
|
833
787
|
}[];
|
|
834
|
-
} | {
|
|
835
|
-
readonly type: "generation-queued";
|
|
836
|
-
readonly id: string;
|
|
837
|
-
readonly position?: number | undefined;
|
|
838
788
|
} | {
|
|
839
789
|
readonly type: "generation-progress";
|
|
840
790
|
readonly id: string;
|
|
@@ -908,11 +858,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
908
858
|
readonly id: string;
|
|
909
859
|
readonly progress?: number | undefined;
|
|
910
860
|
}) => any) | undefined;
|
|
911
|
-
readonly "generation-queued"?: ((value: {
|
|
912
|
-
readonly type: "generation-queued";
|
|
913
|
-
readonly id: string;
|
|
914
|
-
readonly position?: number | undefined;
|
|
915
|
-
}) => any) | undefined;
|
|
916
861
|
readonly timestamps?: ((value: {
|
|
917
862
|
readonly type: "timestamps";
|
|
918
863
|
readonly items: readonly {
|
|
@@ -921,7 +866,7 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
921
866
|
readonly endSeconds: number;
|
|
922
867
|
}[];
|
|
923
868
|
}) => any) | undefined;
|
|
924
|
-
} & (Exclude<keyof Handlers, "audio-delta" | "finish" | "generation-progress" | "
|
|
869
|
+
} & (Exclude<keyof Handlers, "audio-delta" | "finish" | "generation-progress" | "timestamps"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
|
|
925
870
|
readonly type: "audio-delta";
|
|
926
871
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
927
872
|
}, {
|
|
@@ -935,12 +880,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
935
880
|
}[];
|
|
936
881
|
}, {
|
|
937
882
|
readonly type: keyof Handlers;
|
|
938
|
-
}> | Exclude<{
|
|
939
|
-
readonly type: "generation-queued";
|
|
940
|
-
readonly id: string;
|
|
941
|
-
readonly position?: number | undefined;
|
|
942
|
-
}, {
|
|
943
|
-
readonly type: keyof Handlers;
|
|
944
883
|
}> | Exclude<{
|
|
945
884
|
readonly type: "generation-progress";
|
|
946
885
|
readonly id: string;
|
|
@@ -1019,11 +958,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1019
958
|
readonly id: string;
|
|
1020
959
|
readonly progress?: number | undefined;
|
|
1021
960
|
}) => any) | undefined;
|
|
1022
|
-
readonly "generation-queued"?: ((value: {
|
|
1023
|
-
readonly type: "generation-queued";
|
|
1024
|
-
readonly id: string;
|
|
1025
|
-
readonly position?: number | undefined;
|
|
1026
|
-
}) => any) | undefined;
|
|
1027
961
|
readonly timestamps?: ((value: {
|
|
1028
962
|
readonly type: "timestamps";
|
|
1029
963
|
readonly items: readonly {
|
|
@@ -1032,7 +966,7 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1032
966
|
readonly endSeconds: number;
|
|
1033
967
|
}[];
|
|
1034
968
|
}) => any) | undefined;
|
|
1035
|
-
} & (Exclude<keyof Handlers, "audio-delta" | "finish" | "generation-progress" | "
|
|
969
|
+
} & (Exclude<keyof Handlers, "audio-delta" | "finish" | "generation-progress" | "timestamps"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
|
|
1036
970
|
readonly type: "audio-delta";
|
|
1037
971
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
1038
972
|
}, {
|
|
@@ -1046,12 +980,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1046
980
|
}[];
|
|
1047
981
|
}, {
|
|
1048
982
|
readonly type: keyof Handlers;
|
|
1049
|
-
}> | Exclude<{
|
|
1050
|
-
readonly type: "generation-queued";
|
|
1051
|
-
readonly id: string;
|
|
1052
|
-
readonly position?: number | undefined;
|
|
1053
|
-
}, {
|
|
1054
|
-
readonly type: keyof Handlers;
|
|
1055
983
|
}> | Exclude<{
|
|
1056
984
|
readonly type: "generation-progress";
|
|
1057
985
|
readonly id: string;
|
|
@@ -1099,10 +1027,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1099
1027
|
readonly startSeconds: number;
|
|
1100
1028
|
readonly endSeconds: number;
|
|
1101
1029
|
}[];
|
|
1102
|
-
} | {
|
|
1103
|
-
readonly type: "generation-queued";
|
|
1104
|
-
readonly id: string;
|
|
1105
|
-
readonly position?: number | undefined;
|
|
1106
1030
|
} | {
|
|
1107
1031
|
readonly type: "generation-progress";
|
|
1108
1032
|
readonly id: string;
|
|
@@ -1140,11 +1064,6 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1140
1064
|
};
|
|
1141
1065
|
} & {
|
|
1142
1066
|
is: {
|
|
1143
|
-
generationQueued: (u: unknown) => u is {
|
|
1144
|
-
readonly type: "generation-queued";
|
|
1145
|
-
readonly id: string;
|
|
1146
|
-
readonly position?: number | undefined;
|
|
1147
|
-
};
|
|
1148
1067
|
generationProgress: (u: unknown) => u is {
|
|
1149
1068
|
readonly type: "generation-progress";
|
|
1150
1069
|
readonly id: string;
|
package/dist/speech.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
|
-
import { ProgressEvent
|
|
2
|
+
import { ProgressEvent } from "./generation.js";
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
4
|
import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
|
|
5
5
|
import { MediaRoute } from "./route/media.js";
|
|
@@ -70,7 +70,6 @@ export const SpeechFinishEvent = Schema.Struct({
|
|
|
70
70
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
71
71
|
}).annotate({ identifier: "Speech.Event.Finish" });
|
|
72
72
|
const speechEventTagged = Schema.Union([
|
|
73
|
-
QueuedEvent,
|
|
74
73
|
ProgressEvent,
|
|
75
74
|
SpeechAudioDeltaEvent,
|
|
76
75
|
SpeechTimestampsEvent,
|
|
@@ -78,7 +77,6 @@ const speechEventTagged = Schema.Union([
|
|
|
78
77
|
]).pipe(Schema.toTaggedUnion("type"));
|
|
79
78
|
export const SpeechEvent = Object.assign(speechEventTagged, {
|
|
80
79
|
is: {
|
|
81
|
-
generationQueued: speechEventTagged.guards["generation-queued"],
|
|
82
80
|
generationProgress: speechEventTagged.guards["generation-progress"],
|
|
83
81
|
audioDelta: speechEventTagged.guards["audio-delta"],
|
|
84
82
|
timestamps: speechEventTagged.guards.timestamps,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Message, type LLMRequest, type ToolChanges, type ToolEntry } from "./schema/messages.js";
|
|
2
|
+
import type { Capabilities } from "./schema/options.js";
|
|
3
|
+
export type ToolUpdate = NonNullable<NonNullable<Capabilities["tools"]>["updates"]>[number];
|
|
4
|
+
/** What a protocol can send in place of a `Message.tools(...)` marker; the model's `tools.updates` narrows it. */
|
|
5
|
+
export interface ToolUpdateEncoding {
|
|
6
|
+
readonly kinds: ReadonlyArray<ToolUpdate>;
|
|
7
|
+
/** Whether the marker at this message index can be sent where it is. Defaults to anywhere. */
|
|
8
|
+
readonly placeable?: (request: LLMRequest, index: number) => boolean;
|
|
9
|
+
/** Whether a tool can be added or removed in place. Defaults to every tool. */
|
|
10
|
+
readonly declarable?: (tool: ToolEntry) => boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const toolsUpdate: (message: Message) => ToolChanges | undefined;
|
|
13
|
+
/** Whether any marker adds a tool, so a request without top-level tools still declares some. */
|
|
14
|
+
export declare const addsTools: (request: LLMRequest) => boolean;
|
|
15
|
+
/** The changes this route sends in place: the model's `tools.updates` that the protocol's encoding covers. */
|
|
16
|
+
export declare const toolUpdateKinds: (request: LLMRequest) => ("add" | "remove" | "replace")[];
|
|
17
|
+
/** Apply one change: removals first, then additions replace a same-named tool in place or append. */
|
|
18
|
+
export declare const foldTools: <Item extends {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
}>(tools: ReadonlyArray<Item>, add: ReadonlyArray<Item>, remove: ReadonlyArray<string>) => ReadonlyArray<Item>;
|
|
21
|
+
/**
|
|
22
|
+
* Fold the declarations up to the last one this route can't send in place into the leading one (the request's
|
|
23
|
+
* `tools`), and keep later markers in place, trimmed to their effective changes. Protocols send kept markers in
|
|
24
|
+
* message order and track what they need along the way. A marker is sent in place only after the conversation starts, when the model's
|
|
25
|
+
* `tools.updates` and the protocol's encoding both cover what it does: `add` a new name, `replace` a name declared
|
|
26
|
+
* before (even if removed since), `remove` a current tool. Removing a name that matches no current tool does nothing.
|
|
27
|
+
*/
|
|
28
|
+
export declare const planToolUpdates: (request: LLMRequest) => LLMRequest;
|
|
29
|
+
/** Fold every marker into the top-level tools, as a route without in-place tool changes sends them. */
|
|
30
|
+
export declare const foldToolUpdates: (request: LLMRequest) => LLMRequest;
|
|
31
|
+
/** Flattened names of the tools in `before` that `after` no longer has, including tools a redefined namespace drops. */
|
|
32
|
+
export declare const withdrawnTools: (before: ReadonlyArray<ToolEntry>, after: ReadonlyArray<ToolEntry>) => string[];
|
|
33
|
+
/** Rewrite the tools each marker adds, keeping the request identity when there are no markers. */
|
|
34
|
+
export declare const mapToolUpdates: (request: LLMRequest, f: (tools: ReadonlyArray<ToolEntry>) => ReadonlyArray<ToolEntry>) => LLMRequest;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// A request's top-level `tools` is shorthand for a leading `Message.tools({ add: tools })`: tool state is one
|
|
2
|
+
// ordered list of declarations, that leading one and then each marker in message order. Folding the whole list
|
|
3
|
+
// gives the tools a route without in-place changes sends. A protocol that can send some changes in place keeps
|
|
4
|
+
// them where they are, so the leading declaration, and the prompt cache behind it, stays fixed.
|
|
5
|
+
import { Message, SystemMessage } from "./schema/messages.js";
|
|
6
|
+
import { flattenTools } from "./protocols/shared.js";
|
|
7
|
+
export const toolsUpdate = (message) => message.role === "system" ? message.tools : undefined;
|
|
8
|
+
/** Whether any marker adds a tool, so a request without top-level tools still declares some. */
|
|
9
|
+
export const addsTools = (request) => request.messages.some((message) => (toolsUpdate(message)?.add.length ?? 0) > 0);
|
|
10
|
+
/** The changes this route sends in place: the model's `tools.updates` that the protocol's encoding covers. */
|
|
11
|
+
export const toolUpdateKinds = (request) => {
|
|
12
|
+
const encoding = request.model.route.toolUpdates;
|
|
13
|
+
return (request.model.capabilities?.tools?.updates ?? []).filter((kind) => encoding?.kinds.includes(kind));
|
|
14
|
+
};
|
|
15
|
+
/** Apply one change: removals first, then additions replace a same-named tool in place or append. */
|
|
16
|
+
export const foldTools = (tools, add, remove) => {
|
|
17
|
+
const added = new Map(add.map((tool) => [tool.name, tool]));
|
|
18
|
+
const kept = tools.filter((tool) => !remove.includes(tool.name)).map((tool) => added.get(tool.name) ?? tool);
|
|
19
|
+
const names = new Set(kept.map((tool) => tool.name));
|
|
20
|
+
return [...kept, ...[...added.values()].filter((tool) => !names.has(tool.name))];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Fold the declarations up to the last one this route can't send in place into the leading one (the request's
|
|
24
|
+
* `tools`), and keep later markers in place, trimmed to their effective changes. Protocols send kept markers in
|
|
25
|
+
* message order and track what they need along the way. A marker is sent in place only after the conversation starts, when the model's
|
|
26
|
+
* `tools.updates` and the protocol's encoding both cover what it does: `add` a new name, `replace` a name declared
|
|
27
|
+
* before (even if removed since), `remove` a current tool. Removing a name that matches no current tool does nothing.
|
|
28
|
+
*/
|
|
29
|
+
export const planToolUpdates = (request) => plan(request, toolUpdateKinds(request));
|
|
30
|
+
/** Fold every marker into the top-level tools, as a route without in-place tool changes sends them. */
|
|
31
|
+
export const foldToolUpdates = (request) => plan(request, []);
|
|
32
|
+
const plan = (request, supported) => {
|
|
33
|
+
const changes = request.messages.flatMap((message, index) => message.role === "system" && message.tools !== undefined ? [{ index, ...message.tools }] : []);
|
|
34
|
+
if (changes.length === 0)
|
|
35
|
+
return request;
|
|
36
|
+
const encoding = request.model.route.toolUpdates;
|
|
37
|
+
const declarable = (tool) => encoding?.declarable?.(tool) ?? true;
|
|
38
|
+
const firstTurn = request.messages.findIndex((message) => message.role !== "system");
|
|
39
|
+
const steps = changes.reduce((state, change) => {
|
|
40
|
+
const added = change.add.map((tool) => tool.name);
|
|
41
|
+
const removed = state.tools.filter((tool) => change.remove.includes(tool.name) && !added.includes(tool.name));
|
|
42
|
+
const tools = foldTools(state.tools, change.add, change.remove);
|
|
43
|
+
const kinds = [
|
|
44
|
+
...(removed.length > 0 || withdrawnTools(state.tools, tools).length > 0 ? ["remove"] : []),
|
|
45
|
+
...added.map((name) => (state.declared.has(name) ? "replace" : "add")),
|
|
46
|
+
];
|
|
47
|
+
const native = firstTurn !== -1 &&
|
|
48
|
+
change.index > firstTurn &&
|
|
49
|
+
kinds.every((kind) => supported.includes(kind)) &&
|
|
50
|
+
[...change.add, ...removed].every(declarable) &&
|
|
51
|
+
(encoding?.placeable?.(request, change.index) ?? true);
|
|
52
|
+
const step = {
|
|
53
|
+
index: change.index,
|
|
54
|
+
native,
|
|
55
|
+
tools,
|
|
56
|
+
changes: { add: change.add, remove: removed.map((tool) => tool.name) },
|
|
57
|
+
};
|
|
58
|
+
return { tools, declared: new Set([...state.declared, ...added]), steps: [...state.steps, step] };
|
|
59
|
+
}, { tools: request.tools, declared: new Set(request.tools.map((tool) => tool.name)), steps: [] }).steps;
|
|
60
|
+
const cut = steps.findLastIndex((step) => !step.native);
|
|
61
|
+
const kept = new Map(steps.slice(cut + 1).map((step) => [step.index, step.changes]));
|
|
62
|
+
return {
|
|
63
|
+
...request,
|
|
64
|
+
tools: cut === -1 ? request.tools : steps[cut].tools,
|
|
65
|
+
messages: request.messages.flatMap((message, index) => {
|
|
66
|
+
if (message.role !== "system" || message.tools === undefined)
|
|
67
|
+
return [message];
|
|
68
|
+
const tools = kept.get(index);
|
|
69
|
+
if (tools !== undefined && (tools.add.length > 0 || tools.remove.length > 0))
|
|
70
|
+
return [new SystemMessage({ ...message, tools })];
|
|
71
|
+
if (message.content.length === 0)
|
|
72
|
+
return [];
|
|
73
|
+
return [new SystemMessage({ id: message.id, role: "system", content: message.content })];
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/** Flattened names of the tools in `before` that `after` no longer has, including tools a redefined namespace drops. */
|
|
78
|
+
export const withdrawnTools = (before, after) => {
|
|
79
|
+
const kept = new Set(toolNames(after));
|
|
80
|
+
return toolNames(before).filter((name) => !kept.has(name));
|
|
81
|
+
};
|
|
82
|
+
const toolNames = (tools) => flattenTools(tools).map((tool) => tool.name);
|
|
83
|
+
/** Rewrite the tools each marker adds, keeping the request identity when there are no markers. */
|
|
84
|
+
export const mapToolUpdates = (request, f) => {
|
|
85
|
+
if (!request.messages.some((message) => toolsUpdate(message) !== undefined))
|
|
86
|
+
return request;
|
|
87
|
+
return {
|
|
88
|
+
...request,
|
|
89
|
+
messages: request.messages.map((message) => message.role === "system" && message.tools !== undefined
|
|
90
|
+
? new SystemMessage({ ...message, tools: { ...message.tools, add: f(message.tools.add) } })
|
|
91
|
+
: message),
|
|
92
|
+
};
|
|
93
|
+
};
|
package/dist/tool.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, JsonSchema, Schema } from "effect";
|
|
2
2
|
import type { Content } from "@opencode/schema/tool";
|
|
3
3
|
import type { Freeform, ToolCallPart, ToolDefinition as ToolDefinitionClass, ToolOutput as ToolOutputType } from "./schema/index.js";
|
|
4
|
-
import { ToolFailure } from "./schema/index.js";
|
|
4
|
+
import { ToolFailure, type ToolEntryInput } from "./schema/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* Schema constraint for tool input / success values: no decoding or
|
|
7
7
|
* encoding services are allowed. Tools should be self-contained — anything
|
|
@@ -61,6 +61,11 @@ export interface Tool<Input extends ToolInput = any, Success extends ToolSchema<
|
|
|
61
61
|
/** @internal */
|
|
62
62
|
readonly _definition: ToolDefinitionClass;
|
|
63
63
|
}
|
|
64
|
+
/** Tool changes for `Message.tools`: `add` takes what a request's `tools` takes, `remove` the same tools or their names. */
|
|
65
|
+
export interface ToolChangesInput {
|
|
66
|
+
readonly add?: ReadonlyArray<Tool | ToolEntryInput>;
|
|
67
|
+
readonly remove?: ReadonlyArray<Tool | ToolEntryInput | string>;
|
|
68
|
+
}
|
|
64
69
|
/** A tool with an `execute` handler, which `LLM.loop` and `ToolRuntime.dispatch` can run. */
|
|
65
70
|
export type ExecutableTool<Input extends ToolInput = any, Success extends ToolSchema<any> = any> = Tool<Input, Success> & {
|
|
66
71
|
readonly execute: ToolExecute<Input, Success>;
|
package/dist/tool.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, JsonSchema, Schema } from "effect";
|
|
2
|
-
import { ToolDefinition, ToolFailure, ToolOutput } from "./schema/index.js";
|
|
2
|
+
import { ToolDefinition, ToolFailure, ToolOutput, } from "./schema/index.js";
|
|
3
3
|
import { isRecord } from "./utils/record.js";
|
|
4
4
|
/**
|
|
5
5
|
* Constructs a tool whose `execute` returns an Effect that fails with `ToolFailure`.
|
|
@@ -19,10 +19,6 @@ export declare const TranscriptionClient: {
|
|
|
19
19
|
readonly endSeconds: number;
|
|
20
20
|
readonly speaker?: string | undefined;
|
|
21
21
|
};
|
|
22
|
-
} | {
|
|
23
|
-
readonly type: "generation-queued";
|
|
24
|
-
readonly id: string;
|
|
25
|
-
readonly position?: number | undefined;
|
|
26
22
|
} | {
|
|
27
23
|
readonly type: "generation-progress";
|
|
28
24
|
readonly id: string;
|
|
@@ -85,6 +81,10 @@ export declare const TranscriptionClient: {
|
|
|
85
81
|
readonly endSeconds: number;
|
|
86
82
|
readonly speaker?: string | undefined;
|
|
87
83
|
};
|
|
84
|
+
} | {
|
|
85
|
+
readonly type: "generation-progress";
|
|
86
|
+
readonly id: string;
|
|
87
|
+
readonly progress?: number | undefined;
|
|
88
88
|
} | {
|
|
89
89
|
readonly text: string;
|
|
90
90
|
readonly segments?: readonly {
|
|
@@ -129,7 +129,7 @@ export declare const TranscriptionClient: {
|
|
|
129
129
|
};
|
|
130
130
|
} | undefined;
|
|
131
131
|
readonly type: "finish";
|
|
132
|
-
}
|
|
132
|
+
}, import("./public.js").AIError, TranscriptionClientService>;
|
|
133
133
|
readonly start: (request: TranscriptionRequest) => import("effect/Effect").Effect<import("./generation.js").Generation<TranscriptionResponse>, import("./public.js").AIError, TranscriptionClientService>;
|
|
134
134
|
readonly resume: (model: import("./transcription.js").TranscriptionModel<{
|
|
135
135
|
readonly [x: string]: unknown;
|