@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/image.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { type AwaitOptions, type Reason, type Status } from "./generation.js";
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
4
|
import { MediaModel } from "./media-model.js";
|
|
5
5
|
import { MediaRoute } from "./route/media.js";
|
|
@@ -9,10 +9,13 @@ export type ImageOptions = MediaModel.Options;
|
|
|
9
9
|
export type ImageRoute = MediaRoute.AnyRoute<ImageRequest, ImageEvent, ImageResponse>;
|
|
10
10
|
export declare class ImageModel<Options extends ImageOptions = ImageOptions> extends MediaModel<ImageRoute, Options> {
|
|
11
11
|
protected readonly _ImageModel: void;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The number of type arguments selects the kind: `<Options>` for inline or queued, `<Options, Frame, State>` for
|
|
14
|
+
* stream. A queued route's token is the provider's job ID, so `ImageJob.id` is exactly what `status` and `result` take.
|
|
15
|
+
*/
|
|
13
16
|
static fromRoute<Options extends ImageOptions>(route: MediaModel.InlineRouteInput<ImageRequest<ImageModel<Options>>, ImageResponse>, input: MediaRoute.ModelInput): ImageModel<Options>;
|
|
14
17
|
static fromRoute<Options extends ImageOptions, Frame, State>(route: MediaModel.StreamRouteInput<ImageRequest<ImageModel<Options>>, ImageEvent, Frame, State>, input: MediaRoute.ModelInput): ImageModel<Options>;
|
|
15
|
-
static fromRoute<Options extends ImageOptions
|
|
18
|
+
static fromRoute<Options extends ImageOptions>(route: MediaModel.QueuedRouteInput<ImageRequest<ImageModel<Options>>, ImageResponse, string>, input: MediaRoute.ModelInput): ImageModel<Options>;
|
|
16
19
|
}
|
|
17
20
|
export declare const ImageModelSchema: Schema.declare<ImageModel<{
|
|
18
21
|
readonly [x: string]: unknown;
|
|
@@ -39,6 +42,18 @@ export type ImageRequestInput<Model extends ImageModel = ImageModel> = Omit<Imag
|
|
|
39
42
|
readonly images?: ReadonlyArray<Media.Input>;
|
|
40
43
|
readonly providerOptions?: NoInfer<ImageModelOptions<Model>>;
|
|
41
44
|
};
|
|
45
|
+
/** A submitted generation on a queued route. Store `id` with the model to read the job later, from any process. */
|
|
46
|
+
export interface ImageJob {
|
|
47
|
+
/** The provider's job ID. */
|
|
48
|
+
readonly id: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ImageStatus {
|
|
51
|
+
readonly status: Status;
|
|
52
|
+
/** Set when `status` is `error`. */
|
|
53
|
+
readonly reason?: Reason;
|
|
54
|
+
/** 0..1, only when the provider reports progress. */
|
|
55
|
+
readonly progress?: number;
|
|
56
|
+
}
|
|
42
57
|
declare const ImageResponse_base: Schema.Class<ImageResponse, Schema.Struct<{
|
|
43
58
|
readonly images: Schema.$Array<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
44
59
|
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
@@ -189,10 +204,6 @@ export declare const ImageFinishEvent: Schema.Struct<{
|
|
|
189
204
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
190
205
|
}>;
|
|
191
206
|
declare const imageEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
192
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
193
|
-
readonly id: Schema.String;
|
|
194
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
195
|
-
}>, Schema.Struct<{
|
|
196
207
|
readonly type: Schema.tag<"generation-progress">;
|
|
197
208
|
readonly id: Schema.String;
|
|
198
209
|
readonly progress: Schema.optional<Schema.Number>;
|
|
@@ -288,10 +299,6 @@ declare const imageEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.St
|
|
|
288
299
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
289
300
|
}>]>;
|
|
290
301
|
export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
291
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
292
|
-
readonly id: Schema.String;
|
|
293
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
294
|
-
}>, Schema.Struct<{
|
|
295
302
|
readonly type: Schema.tag<"generation-progress">;
|
|
296
303
|
readonly id: Schema.String;
|
|
297
304
|
readonly progress: Schema.optional<Schema.Number>;
|
|
@@ -387,7 +394,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
387
394
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
388
395
|
}>]> & {
|
|
389
396
|
readonly tag: "type";
|
|
390
|
-
readonly discriminants: readonly ["generation-
|
|
397
|
+
readonly discriminants: readonly ["generation-progress", "image-partial", "image", "finish"];
|
|
391
398
|
readonly cases: {
|
|
392
399
|
finish: Schema.Struct<{
|
|
393
400
|
readonly type: Schema.tag<"finish">;
|
|
@@ -417,11 +424,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
417
424
|
readonly id: Schema.String;
|
|
418
425
|
readonly progress: Schema.optional<Schema.Number>;
|
|
419
426
|
}>;
|
|
420
|
-
"generation-queued": Schema.Struct<{
|
|
421
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
422
|
-
readonly id: Schema.String;
|
|
423
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
424
|
-
}>;
|
|
425
427
|
image: Schema.Struct<{
|
|
426
428
|
readonly type: Schema.tag<"image">;
|
|
427
429
|
readonly index: Schema.Number;
|
|
@@ -501,10 +503,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
501
503
|
readonly type: "image";
|
|
502
504
|
readonly index: number;
|
|
503
505
|
readonly image: Media.Asset;
|
|
504
|
-
} | {
|
|
505
|
-
readonly type: "generation-queued";
|
|
506
|
-
readonly id: string;
|
|
507
|
-
readonly position?: number | undefined;
|
|
508
506
|
} | {
|
|
509
507
|
readonly type: "generation-progress";
|
|
510
508
|
readonly id: string;
|
|
@@ -549,12 +547,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
549
547
|
readonly image: Media.Asset;
|
|
550
548
|
}, {
|
|
551
549
|
readonly type: Keys;
|
|
552
|
-
}> | Extract<{
|
|
553
|
-
readonly type: "generation-queued";
|
|
554
|
-
readonly id: string;
|
|
555
|
-
readonly position?: number | undefined;
|
|
556
|
-
}, {
|
|
557
|
-
readonly type: Keys;
|
|
558
550
|
}> | Extract<{
|
|
559
551
|
readonly type: "generation-progress";
|
|
560
552
|
readonly id: string;
|
|
@@ -627,11 +619,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
627
619
|
readonly id: string;
|
|
628
620
|
readonly progress?: number | undefined;
|
|
629
621
|
};
|
|
630
|
-
"generation-queued": (u: unknown) => u is {
|
|
631
|
-
readonly type: "generation-queued";
|
|
632
|
-
readonly id: string;
|
|
633
|
-
readonly position?: number | undefined;
|
|
634
|
-
};
|
|
635
622
|
image: (u: unknown) => u is {
|
|
636
623
|
readonly type: "image";
|
|
637
624
|
readonly index: number;
|
|
@@ -644,7 +631,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
644
631
|
};
|
|
645
632
|
};
|
|
646
633
|
readonly match: {
|
|
647
|
-
<Handlers extends { [K in "finish" | "generation-progress" | "
|
|
634
|
+
<Handlers extends { [K in "finish" | "generation-progress" | "image" | "image-partial"]: (value: {
|
|
648
635
|
readonly finish: Schema.Struct<{
|
|
649
636
|
readonly type: Schema.tag<"finish">;
|
|
650
637
|
readonly usage: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
@@ -673,11 +660,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
673
660
|
readonly id: Schema.String;
|
|
674
661
|
readonly progress: Schema.optional<Schema.Number>;
|
|
675
662
|
}>;
|
|
676
|
-
readonly "generation-queued": Schema.Struct<{
|
|
677
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
678
|
-
readonly id: Schema.String;
|
|
679
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
680
|
-
}>;
|
|
681
663
|
readonly image: Schema.Struct<{
|
|
682
664
|
readonly type: Schema.tag<"image">;
|
|
683
665
|
readonly index: Schema.Number;
|
|
@@ -756,10 +738,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
756
738
|
readonly type: "image";
|
|
757
739
|
readonly index: number;
|
|
758
740
|
readonly image: Media.Asset;
|
|
759
|
-
} | {
|
|
760
|
-
readonly type: "generation-queued";
|
|
761
|
-
readonly id: string;
|
|
762
|
-
readonly position?: number | undefined;
|
|
763
741
|
} | {
|
|
764
742
|
readonly type: "generation-progress";
|
|
765
743
|
readonly id: string;
|
|
@@ -792,8 +770,8 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
792
770
|
readonly [x: string]: unknown;
|
|
793
771
|
};
|
|
794
772
|
} | undefined;
|
|
795
|
-
}, cases: Handlers): import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "
|
|
796
|
-
<Handlers extends { [K in "finish" | "generation-progress" | "
|
|
773
|
+
}, cases: Handlers): import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "image" | "image-partial"]>>;
|
|
774
|
+
<Handlers extends { [K in "finish" | "generation-progress" | "image" | "image-partial"]: (value: {
|
|
797
775
|
readonly finish: Schema.Struct<{
|
|
798
776
|
readonly type: Schema.tag<"finish">;
|
|
799
777
|
readonly usage: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
@@ -822,11 +800,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
822
800
|
readonly id: Schema.String;
|
|
823
801
|
readonly progress: Schema.optional<Schema.Number>;
|
|
824
802
|
}>;
|
|
825
|
-
readonly "generation-queued": Schema.Struct<{
|
|
826
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
827
|
-
readonly id: Schema.String;
|
|
828
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
829
|
-
}>;
|
|
830
803
|
readonly image: Schema.Struct<{
|
|
831
804
|
readonly type: Schema.tag<"image">;
|
|
832
805
|
readonly index: Schema.Number;
|
|
@@ -905,10 +878,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
905
878
|
readonly type: "image";
|
|
906
879
|
readonly index: number;
|
|
907
880
|
readonly image: Media.Asset;
|
|
908
|
-
} | {
|
|
909
|
-
readonly type: "generation-queued";
|
|
910
|
-
readonly id: string;
|
|
911
|
-
readonly position?: number | undefined;
|
|
912
881
|
} | {
|
|
913
882
|
readonly type: "generation-progress";
|
|
914
883
|
readonly id: string;
|
|
@@ -941,7 +910,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
941
910
|
readonly [x: string]: unknown;
|
|
942
911
|
};
|
|
943
912
|
} | undefined;
|
|
944
|
-
}) => import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "
|
|
913
|
+
}) => import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "image" | "image-partial"]>>;
|
|
945
914
|
};
|
|
946
915
|
readonly matchOrElse: {
|
|
947
916
|
<Handlers, OrElse>(value: {
|
|
@@ -952,10 +921,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
952
921
|
readonly type: "image";
|
|
953
922
|
readonly index: number;
|
|
954
923
|
readonly image: Media.Asset;
|
|
955
|
-
} | {
|
|
956
|
-
readonly type: "generation-queued";
|
|
957
|
-
readonly id: string;
|
|
958
|
-
readonly position?: number | undefined;
|
|
959
924
|
} | {
|
|
960
925
|
readonly type: "generation-progress";
|
|
961
926
|
readonly id: string;
|
|
@@ -1023,11 +988,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1023
988
|
readonly id: string;
|
|
1024
989
|
readonly progress?: number | undefined;
|
|
1025
990
|
}) => any) | undefined;
|
|
1026
|
-
readonly "generation-queued"?: ((value: {
|
|
1027
|
-
readonly type: "generation-queued";
|
|
1028
|
-
readonly id: string;
|
|
1029
|
-
readonly position?: number | undefined;
|
|
1030
|
-
}) => any) | undefined;
|
|
1031
991
|
readonly image?: ((value: {
|
|
1032
992
|
readonly type: "image";
|
|
1033
993
|
readonly index: number;
|
|
@@ -1038,7 +998,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1038
998
|
readonly index: number;
|
|
1039
999
|
readonly image: Media.Asset;
|
|
1040
1000
|
}) => any) | undefined;
|
|
1041
|
-
} & (Exclude<keyof Handlers, "finish" | "generation-progress" | "
|
|
1001
|
+
} & (Exclude<keyof Handlers, "finish" | "generation-progress" | "image" | "image-partial"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
|
|
1042
1002
|
readonly type: "image-partial";
|
|
1043
1003
|
readonly index: number;
|
|
1044
1004
|
readonly image: Media.Asset;
|
|
@@ -1050,12 +1010,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1050
1010
|
readonly image: Media.Asset;
|
|
1051
1011
|
}, {
|
|
1052
1012
|
readonly type: keyof Handlers;
|
|
1053
|
-
}> | Exclude<{
|
|
1054
|
-
readonly type: "generation-queued";
|
|
1055
|
-
readonly id: string;
|
|
1056
|
-
readonly position?: number | undefined;
|
|
1057
|
-
}, {
|
|
1058
|
-
readonly type: keyof Handlers;
|
|
1059
1013
|
}> | Exclude<{
|
|
1060
1014
|
readonly type: "generation-progress";
|
|
1061
1015
|
readonly id: string;
|
|
@@ -1128,11 +1082,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1128
1082
|
readonly id: string;
|
|
1129
1083
|
readonly progress?: number | undefined;
|
|
1130
1084
|
}) => any) | undefined;
|
|
1131
|
-
readonly "generation-queued"?: ((value: {
|
|
1132
|
-
readonly type: "generation-queued";
|
|
1133
|
-
readonly id: string;
|
|
1134
|
-
readonly position?: number | undefined;
|
|
1135
|
-
}) => any) | undefined;
|
|
1136
1085
|
readonly image?: ((value: {
|
|
1137
1086
|
readonly type: "image";
|
|
1138
1087
|
readonly index: number;
|
|
@@ -1143,7 +1092,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1143
1092
|
readonly index: number;
|
|
1144
1093
|
readonly image: Media.Asset;
|
|
1145
1094
|
}) => any) | undefined;
|
|
1146
|
-
} & (Exclude<keyof Handlers, "finish" | "generation-progress" | "
|
|
1095
|
+
} & (Exclude<keyof Handlers, "finish" | "generation-progress" | "image" | "image-partial"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
|
|
1147
1096
|
readonly type: "image-partial";
|
|
1148
1097
|
readonly index: number;
|
|
1149
1098
|
readonly image: Media.Asset;
|
|
@@ -1155,12 +1104,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1155
1104
|
readonly image: Media.Asset;
|
|
1156
1105
|
}, {
|
|
1157
1106
|
readonly type: keyof Handlers;
|
|
1158
|
-
}> | Exclude<{
|
|
1159
|
-
readonly type: "generation-queued";
|
|
1160
|
-
readonly id: string;
|
|
1161
|
-
readonly position?: number | undefined;
|
|
1162
|
-
}, {
|
|
1163
|
-
readonly type: keyof Handlers;
|
|
1164
1107
|
}> | Exclude<{
|
|
1165
1108
|
readonly type: "generation-progress";
|
|
1166
1109
|
readonly id: string;
|
|
@@ -1205,10 +1148,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1205
1148
|
readonly type: "image";
|
|
1206
1149
|
readonly index: number;
|
|
1207
1150
|
readonly image: Media.Asset;
|
|
1208
|
-
} | {
|
|
1209
|
-
readonly type: "generation-queued";
|
|
1210
|
-
readonly id: string;
|
|
1211
|
-
readonly position?: number | undefined;
|
|
1212
1151
|
} | {
|
|
1213
1152
|
readonly type: "generation-progress";
|
|
1214
1153
|
readonly id: string;
|
|
@@ -1245,11 +1184,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1245
1184
|
};
|
|
1246
1185
|
} & {
|
|
1247
1186
|
is: {
|
|
1248
|
-
generationQueued: (u: unknown) => u is {
|
|
1249
|
-
readonly type: "generation-queued";
|
|
1250
|
-
readonly id: string;
|
|
1251
|
-
readonly position?: number | undefined;
|
|
1252
|
-
};
|
|
1253
1187
|
generationProgress: (u: unknown) => u is {
|
|
1254
1188
|
readonly type: "generation-progress";
|
|
1255
1189
|
readonly id: string;
|
|
@@ -1301,14 +1235,21 @@ export type ImageEvent = Schema.Schema.Type<typeof imageEventTagged>;
|
|
|
1301
1235
|
export declare const request: <const Model extends ImageModel>(input: ImageRequestInput<Model>) => ImageRequest<Model>;
|
|
1302
1236
|
export declare function generate<const Model extends ImageModel>(input: ImageRequestInput<Model>, options?: AwaitOptions): Effect.Effect<ImageResponse, AIError, Service>;
|
|
1303
1237
|
export declare function stream<const Model extends ImageModel>(input: ImageRequestInput<Model>, options?: AwaitOptions): Stream.Stream<ImageEvent, AIError, Service>;
|
|
1304
|
-
/** Inline and
|
|
1305
|
-
export declare function start<const Model extends ImageModel>(input: ImageRequestInput<Model>): Effect.Effect<
|
|
1306
|
-
|
|
1238
|
+
/** Submit a generation and return at once; nothing polls. Inline and stream routes fail with `UnsupportedOperation`. */
|
|
1239
|
+
export declare function start<const Model extends ImageModel>(input: ImageRequestInput<Model>): Effect.Effect<ImageJob, AIError, Service>;
|
|
1240
|
+
/** One status read for a job ID. */
|
|
1241
|
+
export declare const status: (model: ImageModel, id: string) => Effect.Effect<ImageStatus, AIError, Service>;
|
|
1242
|
+
/** The finished images; fails while the job is still running, or with the provider's reason when it failed. */
|
|
1243
|
+
export declare const result: (model: ImageModel, id: string) => Effect.Effect<ImageResponse, AIError, Service>;
|
|
1244
|
+
/** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */
|
|
1245
|
+
export declare const cancel: (model: ImageModel, id: string) => Effect.Effect<void, AIError, Service>;
|
|
1307
1246
|
export declare const Image: {
|
|
1308
1247
|
readonly request: typeof request;
|
|
1309
1248
|
readonly generate: typeof generate;
|
|
1310
1249
|
readonly stream: typeof stream;
|
|
1311
1250
|
readonly start: typeof start;
|
|
1312
|
-
readonly
|
|
1251
|
+
readonly status: typeof status;
|
|
1252
|
+
readonly result: typeof result;
|
|
1253
|
+
readonly cancel: typeof cancel;
|
|
1313
1254
|
};
|
|
1314
1255
|
export {};
|
package/dist/image.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
|
-
import {
|
|
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";
|
|
@@ -29,9 +29,6 @@ const ImageRequestSchema = Schema.Struct({
|
|
|
29
29
|
resolution: Schema.optional(Schema.String),
|
|
30
30
|
providerOptions: Schema.optional(ProviderOptions),
|
|
31
31
|
});
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
// Response and events
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
32
|
export class ImageResponse extends Schema.Class("Image.Response")({
|
|
36
33
|
images: Schema.Array(Media.AssetSchema),
|
|
37
34
|
usage: Schema.optional(MediaUsage),
|
|
@@ -54,16 +51,9 @@ export const ImageFinishEvent = Schema.Struct({
|
|
|
54
51
|
usage: Schema.optional(MediaUsage),
|
|
55
52
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
56
53
|
}).annotate({ identifier: "Image.Event.Finish" });
|
|
57
|
-
const imageEventTagged = Schema.Union([
|
|
58
|
-
QueuedEvent,
|
|
59
|
-
ProgressEvent,
|
|
60
|
-
ImagePartialEvent,
|
|
61
|
-
ImageOutputEvent,
|
|
62
|
-
ImageFinishEvent,
|
|
63
|
-
]).pipe(Schema.toTaggedUnion("type"));
|
|
54
|
+
const imageEventTagged = Schema.Union([ProgressEvent, ImagePartialEvent, ImageOutputEvent, ImageFinishEvent]).pipe(Schema.toTaggedUnion("type"));
|
|
64
55
|
export const ImageEvent = Object.assign(imageEventTagged, {
|
|
65
56
|
is: {
|
|
66
|
-
generationQueued: imageEventTagged.guards["generation-queued"],
|
|
67
57
|
generationProgress: imageEventTagged.guards["generation-progress"],
|
|
68
58
|
imagePartial: imageEventTagged.guards["image-partial"],
|
|
69
59
|
image: imageEventTagged.guards.image,
|
|
@@ -104,11 +94,18 @@ export function stream(input, options) {
|
|
|
104
94
|
export function start(input) {
|
|
105
95
|
return requestEffect(input).pipe(Effect.flatMap((request) => ImageClient.start(request)));
|
|
106
96
|
}
|
|
107
|
-
|
|
97
|
+
/** One status read for a job ID. */
|
|
98
|
+
export const status = (model, id) => ImageClient.status(model, id);
|
|
99
|
+
/** The finished images; fails while the job is still running, or with the provider's reason when it failed. */
|
|
100
|
+
export const result = (model, id) => ImageClient.result(model, id);
|
|
101
|
+
/** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */
|
|
102
|
+
export const cancel = (model, id) => ImageClient.cancel(model, id);
|
|
108
103
|
export const Image = {
|
|
109
104
|
request,
|
|
110
105
|
generate,
|
|
111
106
|
stream,
|
|
112
107
|
start,
|
|
113
|
-
|
|
108
|
+
status,
|
|
109
|
+
result,
|
|
110
|
+
cancel,
|
|
114
111
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { type ImageModel, type ImageRequest, type ImageRequestInput } from "./im
|
|
|
7
7
|
import { LLM } from "./llm.js";
|
|
8
8
|
import { Media } from "./media.js";
|
|
9
9
|
import { type CheckpointRequest, type CompactionRequest, type EndpointCompactOptions, type StreamOptions, type TriggerCompactOptions } from "./route/client.js";
|
|
10
|
-
import { RequestExecutor } from "./route/executor.js";
|
|
10
|
+
import { RequestExecutor, type HttpMiddleware } from "./route/executor.js";
|
|
11
11
|
import { LanguageModel, type CompactionCheckpointResponse, type CompactionResponse, type LLMEvent, type LLMResponse } from "./schema/index.js";
|
|
12
12
|
import type { LoopObjectEvent, ObjectEvent, ObjectResponse, OutputSchema, OutputType, LLMLoopInput, LLMRequestInput } from "./llm.js";
|
|
13
13
|
import { type SpeechModel, type SpeechRequest, type SpeechRequestInput } from "./speech.js";
|
|
@@ -25,7 +25,14 @@ export interface Options {
|
|
|
25
25
|
}
|
|
26
26
|
export interface RunOptions {
|
|
27
27
|
readonly signal?: AbortSignal;
|
|
28
|
+
/**
|
|
29
|
+
* Runs on every provider request the call makes, like `RequestExecutor.withMiddleware`: submits, polls, results and
|
|
30
|
+
* cancels included. A handle the call returns keeps it for its own calls.
|
|
31
|
+
*/
|
|
32
|
+
readonly http?: HttpMiddleware;
|
|
28
33
|
}
|
|
34
|
+
/** Options for reading or writing an asset. Downloads use the asset's own `middleware`, never a caller's `http`. */
|
|
35
|
+
export type AssetRunOptions = Omit<RunOptions, "http">;
|
|
29
36
|
export type Services = AIClient.Services;
|
|
30
37
|
/**
|
|
31
38
|
* Promise view of a `Generation`. Its fields are a snapshot taken when the handle was created; `refresh()` resolves to a
|
|
@@ -47,14 +54,14 @@ export type GenerationHandle<Response> = Snapshot & {
|
|
|
47
54
|
export declare const make: (options?: Options) => {
|
|
48
55
|
run: <A, E>(effect: Effect.Effect<A, E, Services>, options?: RunOptions) => Promise<A>;
|
|
49
56
|
/** Decoded asset bytes, downloading `url` sources through the executor. */
|
|
50
|
-
bytes: (asset: Media.Asset, options?:
|
|
51
|
-
base64: (asset: Media.Asset, options?:
|
|
57
|
+
bytes: (asset: Media.Asset, options?: AssetRunOptions) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
58
|
+
base64: (asset: Media.Asset, options?: AssetRunOptions) => Promise<string>;
|
|
52
59
|
/** Pull a `url` asset into owned bytes before the provider URL expires. */
|
|
53
|
-
materialize: (asset: Media.Asset, options?:
|
|
60
|
+
materialize: (asset: Media.Asset, options?: AssetRunOptions) => Promise<Media.Asset>;
|
|
54
61
|
/** Read a file into an asset like `Media.file`: sniffed media type, then the extension's. */
|
|
55
|
-
file: (path: string, options?: Media.AssetOptions &
|
|
62
|
+
file: (path: string, options?: Media.AssetOptions & AssetRunOptions) => Promise<Media.Asset>;
|
|
56
63
|
/** Write an asset's bytes like `Media.write`: streamed through a temporary file that replaces `path` on success. */
|
|
57
|
-
write: (asset: Media.Asset, path: string, options?:
|
|
64
|
+
write: (asset: Media.Asset, path: string, options?: AssetRunOptions) => Promise<void>;
|
|
58
65
|
request: typeof LLM.request;
|
|
59
66
|
generate: {
|
|
60
67
|
<const Model extends LanguageModel, S extends OutputSchema>(input: LLMRequestInput<Model> & {
|
|
@@ -93,10 +100,6 @@ export declare const make: (options?: Options) => {
|
|
|
93
100
|
readonly type: "image";
|
|
94
101
|
readonly index: number;
|
|
95
102
|
readonly image: Media.Asset;
|
|
96
|
-
} | {
|
|
97
|
-
readonly type: "generation-queued";
|
|
98
|
-
readonly id: string;
|
|
99
|
-
readonly position?: number | undefined;
|
|
100
103
|
} | {
|
|
101
104
|
readonly type: "generation-progress";
|
|
102
105
|
readonly id: string;
|
|
@@ -130,8 +133,13 @@ export declare const make: (options?: Options) => {
|
|
|
130
133
|
};
|
|
131
134
|
} | undefined;
|
|
132
135
|
}>;
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
/** Submit a generation on a queued route and return its `{ id }` at once; nothing polls. */
|
|
137
|
+
start: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: RunOptions) => Promise<import("./image.js").ImageJob>;
|
|
138
|
+
/** One status read for a job ID. */
|
|
139
|
+
status: (model: ImageModel, id: string, options?: RunOptions) => Promise<import("./image.js").ImageStatus>;
|
|
140
|
+
/** The finished images; fails while the job is still running. */
|
|
141
|
+
result: (model: ImageModel, id: string, options?: RunOptions) => Promise<import("./image.js").ImageResponse>;
|
|
142
|
+
cancel: (model: ImageModel, id: string, options?: RunOptions) => Promise<void>;
|
|
135
143
|
};
|
|
136
144
|
decision: {
|
|
137
145
|
request: typeof import("./decision.js").request;
|
|
@@ -143,13 +151,13 @@ export declare const make: (options?: Options) => {
|
|
|
143
151
|
};
|
|
144
152
|
video: {
|
|
145
153
|
request: typeof import("./video.js").request;
|
|
146
|
-
/** Submit a generation and return its `{ id
|
|
154
|
+
/** Submit a generation and return its `{ id }` at once; nothing polls. */
|
|
147
155
|
start: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: RunOptions) => Promise<import("./video.js").VideoJob>;
|
|
148
|
-
/** One status read for a
|
|
149
|
-
status: (model: VideoModel,
|
|
156
|
+
/** One status read for a job ID. */
|
|
157
|
+
status: (model: VideoModel, id: string, options?: RunOptions) => Promise<import("./video.js").VideoStatus>;
|
|
150
158
|
/** The finished videos; fails while the job is still running. */
|
|
151
|
-
result: (model: VideoModel,
|
|
152
|
-
cancel: (model: VideoModel,
|
|
159
|
+
result: (model: VideoModel, id: string, options?: RunOptions) => Promise<import("./video.js").VideoResponse>;
|
|
160
|
+
cancel: (model: VideoModel, id: string, options?: RunOptions) => Promise<void>;
|
|
153
161
|
};
|
|
154
162
|
/** Experimental: may change without compatibility guarantees. */
|
|
155
163
|
experimental: {
|
|
@@ -166,10 +174,6 @@ export declare const make: (options?: Options) => {
|
|
|
166
174
|
readonly startSeconds: number;
|
|
167
175
|
readonly endSeconds: number;
|
|
168
176
|
}[];
|
|
169
|
-
} | {
|
|
170
|
-
readonly type: "generation-queued";
|
|
171
|
-
readonly id: string;
|
|
172
|
-
readonly position?: number | undefined;
|
|
173
177
|
} | {
|
|
174
178
|
readonly type: "generation-progress";
|
|
175
179
|
readonly id: string;
|
|
@@ -219,10 +223,6 @@ export declare const make: (options?: Options) => {
|
|
|
219
223
|
readonly endSeconds: number;
|
|
220
224
|
readonly speaker?: string | undefined;
|
|
221
225
|
};
|
|
222
|
-
} | {
|
|
223
|
-
readonly type: "generation-queued";
|
|
224
|
-
readonly id: string;
|
|
225
|
-
readonly position?: number | undefined;
|
|
226
226
|
} | {
|
|
227
227
|
readonly type: "generation-progress";
|
|
228
228
|
readonly id: string;
|
package/dist/index.js
CHANGED
|
@@ -28,35 +28,36 @@ const abortEffect = (signal) => signal === undefined
|
|
|
28
28
|
export const make = (options = {}) => {
|
|
29
29
|
const runtime = ManagedRuntime.make(AIClient.layerWith(options.layer ?? RequestExecutor.fetchLayer));
|
|
30
30
|
/** Run any package Effect (for example `ai.compact(...)` from `@opencode/ai/effect`) inside this runtime. */
|
|
31
|
-
const run = (effect, options) => runtime.runPromise(Effect.raceFirst(effect, abortEffect(options?.signal)));
|
|
32
|
-
const iterate = (stream, options) => Stream.toAsyncIterable(Stream.unwrap(runtime.contextEffect.pipe(Effect.map((context) => stream.pipe(Stream.interruptWhen(abortEffect(options?.signal)), Stream.provideContext(context))))));
|
|
31
|
+
const run = (effect, options) => runtime.runPromise(Effect.raceFirst(scoped(effect, options?.http), abortEffect(options?.signal)));
|
|
32
|
+
const iterate = (stream, options) => Stream.toAsyncIterable(Stream.unwrap(runtime.contextEffect.pipe(Effect.map((context) => scoped(stream, options?.http).pipe(Stream.interruptWhen(abortEffect(options?.signal)), Stream.provideContext(context))))));
|
|
33
|
+
// `run` and `iterate` apply `http` around the whole call, so the LLM call gets none of its own.
|
|
33
34
|
function generate(input, options) {
|
|
34
|
-
return run(LLM.generate(input, options), options);
|
|
35
|
+
return run(LLM.generate(input, { ...options, http: undefined }), options);
|
|
35
36
|
}
|
|
36
37
|
function stream(input, options) {
|
|
37
|
-
return iterate(LLM.stream(input, options), options);
|
|
38
|
+
return iterate(LLM.stream(input, { ...options, http: undefined }), options);
|
|
38
39
|
}
|
|
39
40
|
function loop(input, options) {
|
|
40
|
-
return iterate(LLM.loop(input, options), options);
|
|
41
|
+
return iterate(LLM.loop(input, { ...options, http: undefined }), options);
|
|
41
42
|
}
|
|
42
43
|
/** Read `events` from `stream` or `loop` to the end and fold them into the final result. */
|
|
43
44
|
const collect = (events, options) => run(LLM.collect(Stream.fromAsyncIterable(events, (error) => error)), options);
|
|
44
45
|
// The overloads pair each request type with its mechanism; `LLM.compact` checks the route's capability at runtime.
|
|
45
46
|
function compact(request, options) {
|
|
46
47
|
return options?.mechanism === "trigger"
|
|
47
|
-
? run(LLM.compact(request, options), options)
|
|
48
|
-
: run(LLM.compact(request, options), options);
|
|
48
|
+
? run(LLM.compact(request, { ...options, http: undefined }), options)
|
|
49
|
+
: run(LLM.compact(request, { ...options, http: undefined }), options);
|
|
49
50
|
}
|
|
50
|
-
const handle = (generation) => ({
|
|
51
|
+
const handle = (http) => (generation) => ({
|
|
51
52
|
...generation.snapshot,
|
|
52
53
|
snapshot: generation.snapshot,
|
|
53
54
|
terminal: generation.terminal,
|
|
54
55
|
token: generation.token,
|
|
55
|
-
await: (options) => run(generation.await(options), options),
|
|
56
|
-
events: (options) => iterate(generation.events(options), options),
|
|
57
|
-
result: (options) => run(generation.result(), options),
|
|
58
|
-
refresh: (options) => run(generation.refresh(), options).then(handle),
|
|
59
|
-
cancel: (options) => run(generation.cancel(), options),
|
|
56
|
+
await: (options) => run(generation.await(options), { http, ...options }),
|
|
57
|
+
events: (options) => iterate(generation.events(options), { http, ...options }),
|
|
58
|
+
result: (options) => run(generation.result(), { http, ...options }),
|
|
59
|
+
refresh: (options) => run(generation.refresh(), { http, ...options }).then(handle(options?.http ?? http)),
|
|
60
|
+
cancel: (options) => run(generation.cancel(), { http, ...options }),
|
|
60
61
|
});
|
|
61
62
|
return {
|
|
62
63
|
run,
|
|
@@ -111,8 +112,13 @@ export const make = (options = {}) => {
|
|
|
111
112
|
request: Image.request,
|
|
112
113
|
generate: (input, options) => run(Image.generate(input, options), options),
|
|
113
114
|
stream: (input, options) => iterate(Image.stream(input, options), options),
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
/** Submit a generation on a queued route and return its `{ id }` at once; nothing polls. */
|
|
116
|
+
start: (input, options) => run(Image.start(input), options),
|
|
117
|
+
/** One status read for a job ID. */
|
|
118
|
+
status: (model, id, options) => run(Image.status(model, id), options),
|
|
119
|
+
/** The finished images; fails while the job is still running. */
|
|
120
|
+
result: (model, id, options) => run(Image.result(model, id), options),
|
|
121
|
+
cancel: (model, id, options) => run(Image.cancel(model, id), options),
|
|
116
122
|
},
|
|
117
123
|
decision: {
|
|
118
124
|
request: Decision.request,
|
|
@@ -124,13 +130,13 @@ export const make = (options = {}) => {
|
|
|
124
130
|
},
|
|
125
131
|
video: {
|
|
126
132
|
request: Video.request,
|
|
127
|
-
/** Submit a generation and return its `{ id
|
|
133
|
+
/** Submit a generation and return its `{ id }` at once; nothing polls. */
|
|
128
134
|
start: (input, options) => run(Video.start(input), options),
|
|
129
|
-
/** One status read for a
|
|
130
|
-
status: (model,
|
|
135
|
+
/** One status read for a job ID. */
|
|
136
|
+
status: (model, id, options) => run(Video.status(model, id), options),
|
|
131
137
|
/** The finished videos; fails while the job is still running. */
|
|
132
|
-
result: (model,
|
|
133
|
-
cancel: (model,
|
|
138
|
+
result: (model, id, options) => run(Video.result(model, id), options),
|
|
139
|
+
cancel: (model, id, options) => run(Video.cancel(model, id), options),
|
|
134
140
|
},
|
|
135
141
|
/** Experimental: may change without compatibility guarantees. */
|
|
136
142
|
experimental: {
|
|
@@ -143,13 +149,14 @@ export const make = (options = {}) => {
|
|
|
143
149
|
request: Transcription.request,
|
|
144
150
|
generate: (input, options) => run(Transcription.generate(input, { poll: options?.poll }), options),
|
|
145
151
|
stream: (input, options) => iterate(Transcription.stream(input, { poll: options?.poll }), options),
|
|
146
|
-
start: (input, options) => run(Transcription.start(input), options).then(handle),
|
|
147
|
-
resume: (model, token, options) => run(Transcription.resume(model, token), options).then(handle),
|
|
152
|
+
start: (input, options) => run(Transcription.start(input), options).then(handle(options?.http)),
|
|
153
|
+
resume: (model, token, options) => run(Transcription.resume(model, token), options).then(handle(options?.http)),
|
|
148
154
|
},
|
|
149
155
|
},
|
|
150
156
|
dispose: () => runtime.dispose(),
|
|
151
157
|
};
|
|
152
158
|
};
|
|
159
|
+
const scoped = (self, http) => (http === undefined ? self : RequestExecutor.withMiddleware(http)(self));
|
|
153
160
|
const fileError = (message, cause) => new AIError({ reason: new InvalidRequestError({ message, cause }) });
|
|
154
161
|
/** `tool` from `@opencode/ai/effect`, with an `execute` that returns a value or a Promise and throws to fail. */
|
|
155
162
|
export const tool = (config) => {
|
package/dist/llm.d.ts
CHANGED
|
@@ -15,7 +15,10 @@ export type PromptOrMessages = {
|
|
|
15
15
|
interface TextRequestFields<Model extends LanguageModel> extends BaseRequest<Model, NoInfer<LanguageModelProviderOptions<Model>>>, GenerationOptionsFields {
|
|
16
16
|
readonly id?: string;
|
|
17
17
|
readonly system?: string | SystemPart | ReadonlyArray<SystemPart>;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Sent in array order. Pass `tool(...)` values or wire entries such as hosted provider tools. The same as a
|
|
20
|
+
* `Message.tools({ add: tools })` leading the history.
|
|
21
|
+
*/
|
|
19
22
|
readonly tools?: ReadonlyArray<Tool | ToolEntryInput>;
|
|
20
23
|
readonly toolChoice?: ToolChoice.Input;
|
|
21
24
|
readonly cache?: CachePolicy;
|
package/dist/llm.js
CHANGED
|
@@ -5,6 +5,7 @@ import { InvalidProviderOutputError, InvalidRequestError, mergeGeneration, AIErr
|
|
|
5
5
|
import { tool } from "./tool.js";
|
|
6
6
|
import { runTools } from "./tool-runtime.js";
|
|
7
7
|
import { addUsage, nextRequest, pendingCalls } from "./loop.js";
|
|
8
|
+
import { foldTools } from "./tool-updates.js";
|
|
8
9
|
export function generate(input, options) {
|
|
9
10
|
return prepare(input).pipe(Effect.flatMap(({ request, output }) => LLMClient.generate(request, options).pipe(Effect.flatMap((response) => output === undefined
|
|
10
11
|
? Effect.succeed(response)
|
|
@@ -15,8 +16,16 @@ export function stream(input, options) {
|
|
|
15
16
|
}
|
|
16
17
|
export function loop(input, options) {
|
|
17
18
|
const { tools, until, ...rest } = input;
|
|
18
|
-
return Stream.unwrap(prepare({ ...rest, tools }).pipe(
|
|
19
|
+
return Stream.unwrap(prepare({ ...rest, tools }).pipe(
|
|
20
|
+
// Untyped callers may omit `tools`.
|
|
21
|
+
Effect.map(({ request, output }) => driveLoop({ tools: runnableTools(tools ?? [], input.messages ?? []), until, output, options }, request, [], undefined))));
|
|
19
22
|
}
|
|
23
|
+
// Tools that `Message.tools(...)` adds run like top-level ones; a later change with the same name replaces or removes them.
|
|
24
|
+
const runnableTools = (tools, messages) => messages
|
|
25
|
+
.reduce((current, message) => message.role === "system" && message.tools !== undefined
|
|
26
|
+
? foldTools(current, message.tools.add ?? [], (message.tools.remove ?? []).map((item) => (typeof item === "string" ? item : item.name)))
|
|
27
|
+
: current, tools)
|
|
28
|
+
.filter((item) => "_definition" in item);
|
|
20
29
|
export { collect } from "./loop.js";
|
|
21
30
|
/**
|
|
22
31
|
* Stream one model call. Its `finish` is held back: `after` gets the completed step and streams what follows it.
|