@opencode/ai 0.0.0-dev-21798 → 0.0.0-dev-21800
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 +55 -55
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +452 -0
- package/dist/decision.js +143 -0
- package/dist/experimental.d.ts +0 -3
- package/dist/experimental.js +0 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/promise.d.ts +10 -1
- package/dist/promise.js +5 -0
- package/dist/protocols/alibaba-messages.d.ts +34 -0
- package/dist/protocols/anthropic-messages.d.ts +102 -0
- package/dist/protocols/anthropic-messages.js +32 -8
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-messages.d.ts +34 -0
- package/dist/protocols/meta-messages.js +12 -0
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +108 -0
- package/dist/protocols/shared.d.ts +1 -1
- package/dist/protocols/shared.js +2 -2
- package/dist/protocols/system-one.d.ts +99 -0
- package/dist/protocols/system-one.js +228 -0
- package/dist/protocols/zai-messages.d.ts +34 -0
- package/dist/providers/alibaba.d.ts +34 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +34 -0
- package/dist/providers/anthropic-compatible.d.ts +34 -0
- package/dist/providers/anthropic.d.ts +34 -0
- package/dist/providers/baseten.d.ts +4 -10
- package/dist/providers/baseten.js +21 -8
- package/dist/providers/cloudflare-ai-gateway.d.ts +69 -3
- package/dist/providers/cloudflare-ai-gateway.js +10 -10
- package/dist/providers/cloudflare-workers-ai.d.ts +1 -3
- package/dist/providers/cloudflare-workers-ai.js +11 -12
- package/dist/providers/digitalocean.d.ts +3 -9
- package/dist/providers/digitalocean.js +10 -10
- package/dist/providers/google-vertex-messages.d.ts +34 -0
- package/dist/providers/meta.d.ts +34 -0
- package/dist/providers/minimax.d.ts +34 -0
- package/dist/providers/moonshot.d.ts +34 -0
- package/dist/providers/openai.d.ts +5 -10
- package/dist/providers/openai.js +11 -7
- package/dist/providers/opencode.d.ts +3 -9
- package/dist/providers/opencode.js +9 -9
- package/dist/providers/openrouter.d.ts +4 -10
- package/dist/providers/openrouter.js +8 -9
- package/dist/providers/typesafe-ai.d.ts +3 -9
- package/dist/providers/typesafe-ai.js +9 -9
- package/dist/providers/vercel-ai-gateway.d.ts +4 -15
- package/dist/providers/vercel-ai-gateway.js +13 -80
- package/dist/providers/zai-coding-plan.d.ts +34 -0
- package/dist/route/client.js +11 -0
- package/dist/route/decision.d.ts +57 -0
- package/dist/route/decision.js +74 -0
- package/package.json +3 -3
- package/dist/experimental/cloudflare-run-evaluation.d.ts +0 -15
- package/dist/experimental/cloudflare-run-evaluation.js +0 -43
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/openai-decisions.d.ts +0 -23
- package/dist/experimental/openai-decisions.js +0 -115
- package/dist/experimental/system-one.d.ts +0 -114
- package/dist/experimental/system-one.js +0 -140
package/dist/promise.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect, Layer } from "effect";
|
|
2
2
|
import { AIClient } from "./ai-client.js";
|
|
3
|
+
import { type DecisionModel, type DecisionQuestions, type DecisionRequestInput } from "./decision.js";
|
|
3
4
|
import type { AwaitOptions, Event, Snapshot } from "./generation.js";
|
|
4
5
|
import { type ImageModel, type ImageRequest, type ImageRequestInput } from "./image.js";
|
|
5
6
|
import { LLM } from "./index.js";
|
|
@@ -12,7 +13,7 @@ import { type TranscriptionModel, type TranscriptionRequest, type TranscriptionR
|
|
|
12
13
|
import { type VideoModel, type VideoRequest, type VideoRequestInput } from "./video.js";
|
|
13
14
|
/**
|
|
14
15
|
* Promise-first entrypoint for scripts and non-Effect callers. One `ManagedRuntime` hosts the LLM, image, video, speech,
|
|
15
|
-
* and
|
|
16
|
+
* transcription and decision clients over a request executor; every method runs the corresponding Effect API and rethrows
|
|
16
17
|
* `AIError` unchanged. `file` and `write` load `node:fs/promises` on first use, so importing this module does not.
|
|
17
18
|
*/
|
|
18
19
|
export interface Options {
|
|
@@ -525,6 +526,10 @@ export declare const make: (options?: Options) => {
|
|
|
525
526
|
start: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
|
|
526
527
|
resume: (model: TranscriptionModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
|
|
527
528
|
};
|
|
529
|
+
decision: {
|
|
530
|
+
request: typeof import("./decision.js").request;
|
|
531
|
+
generate: <const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>, options?: RunOptions) => Promise<import("./decision.js").DecisionResponseFor<Questions>>;
|
|
532
|
+
};
|
|
528
533
|
dispose: () => Promise<void>;
|
|
529
534
|
};
|
|
530
535
|
export type Client = ReturnType<typeof make>;
|
|
@@ -1016,6 +1021,10 @@ export declare const ai: {
|
|
|
1016
1021
|
start: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
|
|
1017
1022
|
resume: (model: TranscriptionModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
|
|
1018
1023
|
};
|
|
1024
|
+
decision: {
|
|
1025
|
+
request: typeof import("./decision.js").request;
|
|
1026
|
+
generate: <const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>, options?: RunOptions) => Promise<import("./decision.js").DecisionResponseFor<Questions>>;
|
|
1027
|
+
};
|
|
1019
1028
|
dispose: () => Promise<void>;
|
|
1020
1029
|
};
|
|
1021
1030
|
export * as AI from "./promise.js";
|
package/dist/promise.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect, Layer, ManagedRuntime, Stream } from "effect";
|
|
2
2
|
import { AIClient } from "./ai-client.js";
|
|
3
|
+
import { Decision } from "./decision.js";
|
|
3
4
|
import { Image } from "./image.js";
|
|
4
5
|
import { LLM } from "./index.js";
|
|
5
6
|
import { Media } from "./media.js";
|
|
@@ -92,6 +93,10 @@ export const make = (options = {}) => {
|
|
|
92
93
|
start: (input, options) => run(Transcription.start(input), options).then(handle),
|
|
93
94
|
resume: (model, token, options) => run(Transcription.resume(model, token), options).then(handle),
|
|
94
95
|
},
|
|
96
|
+
decision: {
|
|
97
|
+
request: Decision.request,
|
|
98
|
+
generate: (input, options) => run(Decision.generate(input), options),
|
|
99
|
+
},
|
|
95
100
|
dispose: () => runtime.dispose(),
|
|
96
101
|
};
|
|
97
102
|
};
|
|
@@ -61,6 +61,23 @@ export declare const protocol: Protocol<{
|
|
|
61
61
|
readonly transformations?: {
|
|
62
62
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
63
63
|
} | undefined;
|
|
64
|
+
} | {
|
|
65
|
+
readonly type: "video";
|
|
66
|
+
readonly source: {
|
|
67
|
+
readonly type: "base64";
|
|
68
|
+
readonly media_type: string;
|
|
69
|
+
readonly data: string;
|
|
70
|
+
} | {
|
|
71
|
+
readonly type: "url";
|
|
72
|
+
readonly url: string;
|
|
73
|
+
} | {
|
|
74
|
+
readonly type: "file";
|
|
75
|
+
readonly file_id: string;
|
|
76
|
+
};
|
|
77
|
+
readonly cache_control?: {
|
|
78
|
+
readonly type: "ephemeral";
|
|
79
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
80
|
+
} | undefined;
|
|
64
81
|
} | {
|
|
65
82
|
readonly type: "document";
|
|
66
83
|
readonly source: {
|
|
@@ -117,6 +134,23 @@ export declare const protocol: Protocol<{
|
|
|
117
134
|
readonly transformations?: {
|
|
118
135
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
119
136
|
} | undefined;
|
|
137
|
+
} | {
|
|
138
|
+
readonly type: "video";
|
|
139
|
+
readonly source: {
|
|
140
|
+
readonly type: "base64";
|
|
141
|
+
readonly media_type: string;
|
|
142
|
+
readonly data: string;
|
|
143
|
+
} | {
|
|
144
|
+
readonly type: "url";
|
|
145
|
+
readonly url: string;
|
|
146
|
+
} | {
|
|
147
|
+
readonly type: "file";
|
|
148
|
+
readonly file_id: string;
|
|
149
|
+
};
|
|
150
|
+
readonly cache_control?: {
|
|
151
|
+
readonly type: "ephemeral";
|
|
152
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
153
|
+
} | undefined;
|
|
120
154
|
} | {
|
|
121
155
|
readonly type: "document";
|
|
122
156
|
readonly source: {
|
|
@@ -210,6 +210,23 @@ export declare const AnthropicMessagesBody: Schema.Struct<{
|
|
|
210
210
|
readonly citations: Schema.optional<Schema.Struct<{
|
|
211
211
|
readonly enabled: Schema.Boolean;
|
|
212
212
|
}>>;
|
|
213
|
+
}>, Schema.Struct<{
|
|
214
|
+
readonly type: Schema.tag<"video">;
|
|
215
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
216
|
+
readonly type: Schema.tag<"base64">;
|
|
217
|
+
readonly media_type: Schema.String;
|
|
218
|
+
readonly data: Schema.String;
|
|
219
|
+
}>, Schema.Struct<{
|
|
220
|
+
readonly type: Schema.tag<"url">;
|
|
221
|
+
readonly url: Schema.String;
|
|
222
|
+
}>, Schema.Struct<{
|
|
223
|
+
readonly type: Schema.tag<"file">;
|
|
224
|
+
readonly file_id: Schema.String;
|
|
225
|
+
}>]>;
|
|
226
|
+
readonly cache_control: Schema.optional<Schema.Struct<{
|
|
227
|
+
readonly type: Schema.tag<"ephemeral">;
|
|
228
|
+
readonly ttl: Schema.optional<Schema.Literals<readonly ["5m", "1h"]>>;
|
|
229
|
+
}>>;
|
|
213
230
|
}>, Schema.Struct<{
|
|
214
231
|
readonly type: Schema.tag<"tool_result">;
|
|
215
232
|
readonly tool_use_id: Schema.String;
|
|
@@ -266,6 +283,23 @@ export declare const AnthropicMessagesBody: Schema.Struct<{
|
|
|
266
283
|
readonly citations: Schema.optional<Schema.Struct<{
|
|
267
284
|
readonly enabled: Schema.Boolean;
|
|
268
285
|
}>>;
|
|
286
|
+
}>, Schema.Struct<{
|
|
287
|
+
readonly type: Schema.tag<"video">;
|
|
288
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
289
|
+
readonly type: Schema.tag<"base64">;
|
|
290
|
+
readonly media_type: Schema.String;
|
|
291
|
+
readonly data: Schema.String;
|
|
292
|
+
}>, Schema.Struct<{
|
|
293
|
+
readonly type: Schema.tag<"url">;
|
|
294
|
+
readonly url: Schema.String;
|
|
295
|
+
}>, Schema.Struct<{
|
|
296
|
+
readonly type: Schema.tag<"file">;
|
|
297
|
+
readonly file_id: Schema.String;
|
|
298
|
+
}>]>;
|
|
299
|
+
readonly cache_control: Schema.optional<Schema.Struct<{
|
|
300
|
+
readonly type: Schema.tag<"ephemeral">;
|
|
301
|
+
readonly ttl: Schema.optional<Schema.Literals<readonly ["5m", "1h"]>>;
|
|
302
|
+
}>>;
|
|
269
303
|
}>]>>]>;
|
|
270
304
|
readonly is_error: Schema.optional<Schema.Boolean>;
|
|
271
305
|
readonly cache_control: Schema.optional<Schema.Struct<{
|
|
@@ -457,6 +491,23 @@ export declare const protocol: Protocol<{
|
|
|
457
491
|
readonly transformations?: {
|
|
458
492
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
459
493
|
} | undefined;
|
|
494
|
+
} | {
|
|
495
|
+
readonly type: "video";
|
|
496
|
+
readonly source: {
|
|
497
|
+
readonly type: "base64";
|
|
498
|
+
readonly media_type: string;
|
|
499
|
+
readonly data: string;
|
|
500
|
+
} | {
|
|
501
|
+
readonly type: "url";
|
|
502
|
+
readonly url: string;
|
|
503
|
+
} | {
|
|
504
|
+
readonly type: "file";
|
|
505
|
+
readonly file_id: string;
|
|
506
|
+
};
|
|
507
|
+
readonly cache_control?: {
|
|
508
|
+
readonly type: "ephemeral";
|
|
509
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
510
|
+
} | undefined;
|
|
460
511
|
} | {
|
|
461
512
|
readonly type: "document";
|
|
462
513
|
readonly source: {
|
|
@@ -513,6 +564,23 @@ export declare const protocol: Protocol<{
|
|
|
513
564
|
readonly transformations?: {
|
|
514
565
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
515
566
|
} | undefined;
|
|
567
|
+
} | {
|
|
568
|
+
readonly type: "video";
|
|
569
|
+
readonly source: {
|
|
570
|
+
readonly type: "base64";
|
|
571
|
+
readonly media_type: string;
|
|
572
|
+
readonly data: string;
|
|
573
|
+
} | {
|
|
574
|
+
readonly type: "url";
|
|
575
|
+
readonly url: string;
|
|
576
|
+
} | {
|
|
577
|
+
readonly type: "file";
|
|
578
|
+
readonly file_id: string;
|
|
579
|
+
};
|
|
580
|
+
readonly cache_control?: {
|
|
581
|
+
readonly type: "ephemeral";
|
|
582
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
583
|
+
} | undefined;
|
|
516
584
|
} | {
|
|
517
585
|
readonly type: "document";
|
|
518
586
|
readonly source: {
|
|
@@ -817,6 +885,23 @@ export declare const route: Route<{
|
|
|
817
885
|
readonly transformations?: {
|
|
818
886
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
819
887
|
} | undefined;
|
|
888
|
+
} | {
|
|
889
|
+
readonly type: "video";
|
|
890
|
+
readonly source: {
|
|
891
|
+
readonly type: "base64";
|
|
892
|
+
readonly media_type: string;
|
|
893
|
+
readonly data: string;
|
|
894
|
+
} | {
|
|
895
|
+
readonly type: "url";
|
|
896
|
+
readonly url: string;
|
|
897
|
+
} | {
|
|
898
|
+
readonly type: "file";
|
|
899
|
+
readonly file_id: string;
|
|
900
|
+
};
|
|
901
|
+
readonly cache_control?: {
|
|
902
|
+
readonly type: "ephemeral";
|
|
903
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
904
|
+
} | undefined;
|
|
820
905
|
} | {
|
|
821
906
|
readonly type: "document";
|
|
822
907
|
readonly source: {
|
|
@@ -873,6 +958,23 @@ export declare const route: Route<{
|
|
|
873
958
|
readonly transformations?: {
|
|
874
959
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
875
960
|
} | undefined;
|
|
961
|
+
} | {
|
|
962
|
+
readonly type: "video";
|
|
963
|
+
readonly source: {
|
|
964
|
+
readonly type: "base64";
|
|
965
|
+
readonly media_type: string;
|
|
966
|
+
readonly data: string;
|
|
967
|
+
} | {
|
|
968
|
+
readonly type: "url";
|
|
969
|
+
readonly url: string;
|
|
970
|
+
} | {
|
|
971
|
+
readonly type: "file";
|
|
972
|
+
readonly file_id: string;
|
|
973
|
+
};
|
|
974
|
+
readonly cache_control?: {
|
|
975
|
+
readonly type: "ephemeral";
|
|
976
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
977
|
+
} | undefined;
|
|
876
978
|
} | {
|
|
877
979
|
readonly type: "document";
|
|
878
980
|
readonly source: {
|
|
@@ -81,6 +81,11 @@ const AnthropicImageBlock = Schema.Struct({
|
|
|
81
81
|
cache_control: Schema.optional(AnthropicCacheControl),
|
|
82
82
|
transformations: Schema.optional(AnthropicImageTransformations),
|
|
83
83
|
});
|
|
84
|
+
const AnthropicVideoBlock = Schema.Struct({
|
|
85
|
+
type: Schema.tag("video"),
|
|
86
|
+
source: AnthropicImageSource,
|
|
87
|
+
cache_control: Schema.optional(AnthropicCacheControl),
|
|
88
|
+
});
|
|
84
89
|
// SDK: Base64PDFSource:209 {type:"base64", media_type:"application/pdf", data}, PlainTextSource:2716 {type:"text", media_type:"text/plain", data},
|
|
85
90
|
// SDK: URLPDFSource:3823 {type:"url", url}, FileDocumentSource:2344 {type:"file", file_id}, ContentBlockSource:2266 {type:"content", content}
|
|
86
91
|
// SDK: DocumentBlockParam:2297 {source: 5-way union, cache_control, citations, context, title}
|
|
@@ -157,7 +162,12 @@ const AnthropicServerToolResultBlock = Schema.Struct({
|
|
|
157
162
|
// Anthropic accepts either a plain string or an ordered array of text, image, and
|
|
158
163
|
// document blocks inside `tool_result.content`. The array form keeps media as native
|
|
159
164
|
// model input instead of JSON-stringifying base64 into prompt text.
|
|
160
|
-
const AnthropicToolResultContent = Schema.Union([
|
|
165
|
+
const AnthropicToolResultContent = Schema.Union([
|
|
166
|
+
AnthropicTextBlock,
|
|
167
|
+
AnthropicImageBlock,
|
|
168
|
+
AnthropicDocumentBlock,
|
|
169
|
+
AnthropicVideoBlock,
|
|
170
|
+
]);
|
|
161
171
|
const AnthropicToolResultBlock = Schema.Struct({
|
|
162
172
|
type: Schema.tag("tool_result"),
|
|
163
173
|
tool_use_id: Schema.String,
|
|
@@ -169,6 +179,7 @@ const AnthropicUserBlock = Schema.Union([
|
|
|
169
179
|
AnthropicTextBlock,
|
|
170
180
|
AnthropicImageBlock,
|
|
171
181
|
AnthropicDocumentBlock,
|
|
182
|
+
AnthropicVideoBlock,
|
|
172
183
|
AnthropicToolResultBlock,
|
|
173
184
|
]);
|
|
174
185
|
const AnthropicCompactionBlock = Schema.Struct({
|
|
@@ -539,9 +550,22 @@ const citationsFromMetadata = (metadata) => {
|
|
|
539
550
|
return undefined;
|
|
540
551
|
};
|
|
541
552
|
const isHttpUrl = (value) => /^https?:\/\//i.test(value.trim());
|
|
542
|
-
const lowerMedia = Effect.fnUntraced(function* (part, breakpoints) {
|
|
553
|
+
const lowerMedia = Effect.fnUntraced(function* (part, request, breakpoints) {
|
|
543
554
|
const mime = part.media.mediaType.toLowerCase();
|
|
544
555
|
const cacheControlValue = breakpoints ? cacheControl(breakpoints, part.cache) : undefined;
|
|
556
|
+
if (mime.startsWith("video/")) {
|
|
557
|
+
const inline = part.media.inline();
|
|
558
|
+
const source = inline
|
|
559
|
+
? { type: "base64", media_type: mime, data: inline.base64 }
|
|
560
|
+
: yield* ProviderShared.mediaReference(part.media, request.model.provider, "Messages video").pipe(Effect.map((reference) => reference.type === "ref" && !reference.value.includes("://")
|
|
561
|
+
? { type: "file", file_id: reference.value }
|
|
562
|
+
: { type: "url", url: reference.value }));
|
|
563
|
+
return {
|
|
564
|
+
type: "video",
|
|
565
|
+
source,
|
|
566
|
+
...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
|
|
567
|
+
};
|
|
568
|
+
}
|
|
545
569
|
const fileId = fileIdFromMetadata(part.metadata);
|
|
546
570
|
// SDK file sources: FileImageSource:2350 / FileDocumentSource:2344 {type:"file", file_id}
|
|
547
571
|
if (fileId) {
|
|
@@ -644,19 +668,19 @@ const lowerMedia = Effect.fnUntraced(function* (part, breakpoints) {
|
|
|
644
668
|
});
|
|
645
669
|
// Tool results may carry structured text, images, and documents. Keep media as provider-native
|
|
646
670
|
// content instead of JSON-stringifying base64 into a prompt string.
|
|
647
|
-
const lowerToolResultContentItem = Effect.fnUntraced(function* (item) {
|
|
671
|
+
const lowerToolResultContentItem = Effect.fnUntraced(function* (item, request) {
|
|
648
672
|
if (item.type === "text")
|
|
649
673
|
return { type: "text", text: item.text };
|
|
650
|
-
return yield* lowerMedia(ProviderShared.toolFileMedia(item));
|
|
674
|
+
return yield* lowerMedia(ProviderShared.toolFileMedia(item), request);
|
|
651
675
|
});
|
|
652
|
-
const lowerToolResultContent = Effect.fnUntraced(function* (part) {
|
|
676
|
+
const lowerToolResultContent = Effect.fnUntraced(function* (part, request) {
|
|
653
677
|
// Text / json / error results stay as a string for backward compatibility
|
|
654
678
|
// with existing cassettes and provider expectations.
|
|
655
679
|
if (part.result.type !== "content")
|
|
656
680
|
return ProviderShared.toolResultText(part);
|
|
657
681
|
// Preserve the narrowed array element type when compiled through a consumer package.
|
|
658
682
|
const content = part.result.value;
|
|
659
|
-
return yield* Effect.forEach(content, lowerToolResultContentItem);
|
|
683
|
+
return yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request));
|
|
660
684
|
});
|
|
661
685
|
const requireThinkingSignature = (request) => {
|
|
662
686
|
if (request.model.compatibility?.requireSignature !== undefined)
|
|
@@ -763,7 +787,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
763
787
|
continue;
|
|
764
788
|
}
|
|
765
789
|
if (part.type === "media") {
|
|
766
|
-
content.push(yield* lowerMedia(part, breakpoints));
|
|
790
|
+
content.push(yield* lowerMedia(part, request, breakpoints));
|
|
767
791
|
continue;
|
|
768
792
|
}
|
|
769
793
|
return yield* ProviderShared.unsupportedContent("Anthropic Messages", "user", ["text", "media"]);
|
|
@@ -839,7 +863,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
839
863
|
content.push({
|
|
840
864
|
type: "tool_result",
|
|
841
865
|
tool_use_id: scrubToolCallID(part.id),
|
|
842
|
-
content: yield* lowerToolResultContent(part),
|
|
866
|
+
content: yield* lowerToolResultContent(part, request),
|
|
843
867
|
is_error: part.result.type === "error" ? true : undefined,
|
|
844
868
|
cache_control: cacheControl(breakpoints, part.cache),
|
|
845
869
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
2
|
+
/** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One body as `input`; media defaults to Clef's top-level lists. */
|
|
3
|
+
export declare const protocol: DecisionRoute.Protocol;
|
|
4
|
+
/** Providers set the Run API base, `.../client/v4/accounts/{account}/ai/run`, with `route.with(...)`. */
|
|
5
|
+
export declare const route: DecisionRoute.Route;
|
|
6
|
+
export declare const CloudflareRunDecisions: {
|
|
7
|
+
readonly protocol: DecisionRoute.Protocol;
|
|
8
|
+
readonly route: DecisionRoute.Route;
|
|
9
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
3
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
4
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
5
|
+
import { SystemOne } from "./system-one.js";
|
|
6
|
+
const ID = "cloudflare-run-decisions";
|
|
7
|
+
const NAME = "Cloudflare Run";
|
|
8
|
+
// Workers AI models answer with the System One response; third-party models such as TypeSafe Jev wrap it in a
|
|
9
|
+
// completed run record.
|
|
10
|
+
const Envelope = Schema.Struct({
|
|
11
|
+
result: Schema.Union([
|
|
12
|
+
SystemOne.Response,
|
|
13
|
+
Schema.Struct({ state: Schema.Literal("Completed"), result: SystemOne.Response }),
|
|
14
|
+
]),
|
|
15
|
+
});
|
|
16
|
+
const decodeEnvelope = MediaProtocol.identity({ id: ID, name: NAME, provider: "cloudflare-workers-ai" }).decodeJson(Envelope);
|
|
17
|
+
/** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One body as `input`; media defaults to Clef's top-level lists. */
|
|
18
|
+
export const protocol = DecisionRoute.protocol({
|
|
19
|
+
id: ID,
|
|
20
|
+
name: NAME,
|
|
21
|
+
inlineMedia: true,
|
|
22
|
+
body: {
|
|
23
|
+
from: (request) => SystemOne.encodeBody(request, "images").pipe(Effect.map((input) => ({ model: request.model.id, input }))),
|
|
24
|
+
},
|
|
25
|
+
response: {
|
|
26
|
+
decode: (response, context) => decodeEnvelope(response).pipe(Effect.flatMap((output) => SystemOne.toResponse("answers" in output.value.result ? output.value.result : output.value.result.result, context.request, context.providerMetadataKey, output.invalid))),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
/** Providers set the Run API base, `.../client/v4/accounts/{account}/ai/run`, with `route.with(...)`. */
|
|
30
|
+
export const route = DecisionRoute.make({
|
|
31
|
+
id: ID,
|
|
32
|
+
provider: "cloudflare-workers-ai",
|
|
33
|
+
protocol,
|
|
34
|
+
endpoint: Endpoint.path(""),
|
|
35
|
+
});
|
|
36
|
+
export const CloudflareRunDecisions = { protocol, route };
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export * as AnthropicMessages from "./anthropic-messages.js";
|
|
2
2
|
export * as BedrockConverse from "./bedrock-converse.js";
|
|
3
|
+
export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
|
|
3
4
|
export * as CohereChat from "./cohere-chat.js";
|
|
4
5
|
export * as Gemini from "./gemini.js";
|
|
5
6
|
export * as GoogleInteractions from "./google-interactions.js";
|
|
6
7
|
export * as MistralChat from "./mistral-chat.js";
|
|
7
8
|
export * as OpenAIChat from "./openai-chat.js";
|
|
9
|
+
export * as OpenAIDecisions from "./openai-decisions.js";
|
|
8
10
|
export * as OpenAIImages from "./openai-images.js";
|
|
9
11
|
export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
|
|
10
12
|
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
|
|
11
13
|
export * as OpenAIResponses from "./openai-responses.js";
|
|
12
14
|
export * as OpenResponses from "./open-responses.js";
|
|
13
15
|
export * as OpenResponsesChannel from "./open-responses-channel.js";
|
|
16
|
+
export * as SystemOne from "./system-one.js";
|
|
14
17
|
export * as XAIResponses from "./xai-responses.js";
|
package/dist/protocols/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export * as AnthropicMessages from "./anthropic-messages.js";
|
|
2
2
|
export * as BedrockConverse from "./bedrock-converse.js";
|
|
3
|
+
export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
|
|
3
4
|
export * as CohereChat from "./cohere-chat.js";
|
|
4
5
|
export * as Gemini from "./gemini.js";
|
|
5
6
|
export * as GoogleInteractions from "./google-interactions.js";
|
|
6
7
|
export * as MistralChat from "./mistral-chat.js";
|
|
7
8
|
export * as OpenAIChat from "./openai-chat.js";
|
|
9
|
+
export * as OpenAIDecisions from "./openai-decisions.js";
|
|
8
10
|
export * as OpenAIImages from "./openai-images.js";
|
|
9
11
|
export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
|
|
10
12
|
export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
|
|
11
13
|
export * as OpenAIResponses from "./openai-responses.js";
|
|
12
14
|
export * as OpenResponses from "./open-responses.js";
|
|
13
15
|
export * as OpenResponsesChannel from "./open-responses-channel.js";
|
|
16
|
+
export * as SystemOne from "./system-one.js";
|
|
14
17
|
export * as XAIResponses from "./xai-responses.js";
|
|
@@ -49,6 +49,23 @@ export declare const protocol: Protocol<{
|
|
|
49
49
|
readonly transformations?: {
|
|
50
50
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
51
51
|
} | undefined;
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "video";
|
|
54
|
+
readonly source: {
|
|
55
|
+
readonly type: "base64";
|
|
56
|
+
readonly media_type: string;
|
|
57
|
+
readonly data: string;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: "url";
|
|
60
|
+
readonly url: string;
|
|
61
|
+
} | {
|
|
62
|
+
readonly type: "file";
|
|
63
|
+
readonly file_id: string;
|
|
64
|
+
};
|
|
65
|
+
readonly cache_control?: {
|
|
66
|
+
readonly type: "ephemeral";
|
|
67
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
68
|
+
} | undefined;
|
|
52
69
|
} | {
|
|
53
70
|
readonly type: "document";
|
|
54
71
|
readonly source: {
|
|
@@ -105,6 +122,23 @@ export declare const protocol: Protocol<{
|
|
|
105
122
|
readonly transformations?: {
|
|
106
123
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
107
124
|
} | undefined;
|
|
125
|
+
} | {
|
|
126
|
+
readonly type: "video";
|
|
127
|
+
readonly source: {
|
|
128
|
+
readonly type: "base64";
|
|
129
|
+
readonly media_type: string;
|
|
130
|
+
readonly data: string;
|
|
131
|
+
} | {
|
|
132
|
+
readonly type: "url";
|
|
133
|
+
readonly url: string;
|
|
134
|
+
} | {
|
|
135
|
+
readonly type: "file";
|
|
136
|
+
readonly file_id: string;
|
|
137
|
+
};
|
|
138
|
+
readonly cache_control?: {
|
|
139
|
+
readonly type: "ephemeral";
|
|
140
|
+
readonly ttl?: "1h" | "5m" | undefined;
|
|
141
|
+
} | undefined;
|
|
108
142
|
} | {
|
|
109
143
|
readonly type: "document";
|
|
110
144
|
readonly source: {
|
|
@@ -27,6 +27,18 @@ const fromRequest = Effect.fn("MetaMessages.fromRequest")(function* (request) {
|
|
|
27
27
|
const body = yield* AnthropicMessages.protocol.body.from(projected.request);
|
|
28
28
|
return {
|
|
29
29
|
...body,
|
|
30
|
+
messages: body.messages.map((message) => {
|
|
31
|
+
if (message.role !== "user")
|
|
32
|
+
return message;
|
|
33
|
+
const videos = [];
|
|
34
|
+
const content = message.content.map((block) => {
|
|
35
|
+
if (block.type !== "tool_result" || typeof block.content === "string")
|
|
36
|
+
return block;
|
|
37
|
+
videos.push(...block.content.filter((item) => item.type === "video"));
|
|
38
|
+
return { ...block, content: block.content.filter((item) => item.type !== "video") };
|
|
39
|
+
});
|
|
40
|
+
return videos.length === 0 ? message : { ...message, content: [...content, ...videos] };
|
|
41
|
+
}),
|
|
30
42
|
tools: body.tools === undefined
|
|
31
43
|
? undefined
|
|
32
44
|
: yield* Effect.forEach(body.tools, (tool, index) => Effect.gen(function* () {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
3
|
+
import { type ProviderOptions } from "../schema/index.js";
|
|
4
|
+
export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
5
|
+
export declare const PATH = "/decisions";
|
|
6
|
+
declare const Options: Schema.Struct<{
|
|
7
|
+
readonly promptCacheKey: Schema.optional<Schema.String>;
|
|
8
|
+
readonly promptCacheOptions: Schema.optional<Schema.Struct<{
|
|
9
|
+
readonly mode: Schema.optional<Schema.String>;
|
|
10
|
+
readonly ttl: Schema.optional<Schema.String>;
|
|
11
|
+
}>>;
|
|
12
|
+
readonly safetyIdentifier: Schema.optional<Schema.String>;
|
|
13
|
+
}>;
|
|
14
|
+
/** Known fields map to their wire names; anything else is sent as given. */
|
|
15
|
+
export type OptionsInput = ProviderOptions & typeof Options.Encoded;
|
|
16
|
+
export declare const protocol: DecisionRoute.Protocol;
|
|
17
|
+
export declare const route: DecisionRoute.Route;
|
|
18
|
+
export declare const OpenAIDecisions: {
|
|
19
|
+
readonly protocol: DecisionRoute.Protocol;
|
|
20
|
+
readonly route: DecisionRoute.Route;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { DecisionResponse } from "../decision.js";
|
|
3
|
+
import { DecisionRoute } from "../route/decision.js";
|
|
4
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
6
|
+
import { AIError, UnsupportedOperationError, mergeJsonRecords } from "../schema/index.js";
|
|
7
|
+
import { encodeJson } from "../utils/json.js";
|
|
8
|
+
import { OpenResponses } from "./open-responses.js";
|
|
9
|
+
import { ProviderShared } from "./shared.js";
|
|
10
|
+
const ID = "openai-decisions";
|
|
11
|
+
const NAME = "OpenAI Decisions";
|
|
12
|
+
export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
13
|
+
export const PATH = "/decisions";
|
|
14
|
+
const Options = Schema.Struct({
|
|
15
|
+
promptCacheKey: Schema.optional(Schema.String),
|
|
16
|
+
promptCacheOptions: Schema.optional(Schema.Struct({ mode: Schema.optional(Schema.String), ttl: Schema.optional(Schema.String) })),
|
|
17
|
+
safetyIdentifier: Schema.optional(Schema.String),
|
|
18
|
+
});
|
|
19
|
+
const Probability = Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 1 }));
|
|
20
|
+
const ChoiceValue = Schema.Union([Schema.String, Schema.Boolean]);
|
|
21
|
+
const Answer = Schema.Union([
|
|
22
|
+
Schema.Struct({ type: Schema.Literal("predicate"), name: Schema.String, probability: Probability }),
|
|
23
|
+
Schema.Struct({
|
|
24
|
+
type: Schema.Literal("choice"),
|
|
25
|
+
name: Schema.String,
|
|
26
|
+
choice: ChoiceValue,
|
|
27
|
+
probabilities: Schema.Array(Schema.Struct({ value: ChoiceValue, probability: Probability })),
|
|
28
|
+
confidence: Probability,
|
|
29
|
+
}),
|
|
30
|
+
Schema.Struct({
|
|
31
|
+
type: Schema.Literal("score"),
|
|
32
|
+
name: Schema.String,
|
|
33
|
+
score: Schema.Number,
|
|
34
|
+
probabilities: Schema.Array(Schema.Struct({ value: Schema.Int, label: Schema.String, probability: Probability })),
|
|
35
|
+
confidence: Probability,
|
|
36
|
+
}),
|
|
37
|
+
Schema.Struct({ type: Schema.Literal("refusal"), name: Schema.String }),
|
|
38
|
+
]);
|
|
39
|
+
const Response = Schema.Struct({
|
|
40
|
+
model: Schema.String,
|
|
41
|
+
answers: Schema.Array(Answer),
|
|
42
|
+
usage: Schema.optional(OpenResponses.OpenResponsesUsage),
|
|
43
|
+
});
|
|
44
|
+
const decodeOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(Options));
|
|
45
|
+
const fromRequest = Effect.fn("OpenAIDecisions.fromRequest")(function* (request) {
|
|
46
|
+
const options = yield* decodeOptions(request.providerOptions ?? {});
|
|
47
|
+
const { promptCacheKey: _, promptCacheOptions: __, safetyIdentifier: ___, ...native } = request.providerOptions ?? {};
|
|
48
|
+
return {
|
|
49
|
+
...mergeJsonRecords({
|
|
50
|
+
prompt_cache_key: options.promptCacheKey,
|
|
51
|
+
prompt_cache_options: options.promptCacheOptions,
|
|
52
|
+
safety_identifier: options.safetyIdentifier,
|
|
53
|
+
...native,
|
|
54
|
+
}, request.http?.body),
|
|
55
|
+
model: request.model.id,
|
|
56
|
+
input: [{ role: "user", content: yield* Effect.forEach(request.input, (part) => inputPart(request, part)) }],
|
|
57
|
+
questions: request.questions,
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
// `input_json` takes an object or a list of objects; other JSON values go as text.
|
|
61
|
+
const inputPart = (request, part) => {
|
|
62
|
+
if (part.type === "text")
|
|
63
|
+
return Effect.succeed({ type: "input_text", text: part.text });
|
|
64
|
+
if (part.type === "json")
|
|
65
|
+
return Effect.succeed(isObject(part.value) || (Array.isArray(part.value) && part.value.every(isObject))
|
|
66
|
+
? { type: "input_json", data: part.value }
|
|
67
|
+
: { type: "input_text", text: encodeJson(part.value) });
|
|
68
|
+
if (part.media.kind !== "image")
|
|
69
|
+
return Effect.fail(new AIError({
|
|
70
|
+
reason: new UnsupportedOperationError({
|
|
71
|
+
operation: "decision.media",
|
|
72
|
+
provider: request.model.provider,
|
|
73
|
+
route: request.model.route.id,
|
|
74
|
+
message: `${NAME} takes images only; got ${part.media.kind} media`,
|
|
75
|
+
}),
|
|
76
|
+
}));
|
|
77
|
+
return ProviderShared.mediaReference(part.media, undefined, `${NAME} image input`).pipe(Effect.map((reference) => ({ type: "input_image", image_url: reference.value })));
|
|
78
|
+
};
|
|
79
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
80
|
+
const decodeDocument = MediaProtocol.identity({ id: ID, name: NAME, provider: "openai" }).decodeJson(Response);
|
|
81
|
+
export const protocol = DecisionRoute.protocol({
|
|
82
|
+
id: ID,
|
|
83
|
+
name: NAME,
|
|
84
|
+
body: { from: fromRequest },
|
|
85
|
+
response: {
|
|
86
|
+
decode: Effect.fn("OpenAIDecisions.decodeResponse")(function* (response, context) {
|
|
87
|
+
const output = yield* decodeDocument(response);
|
|
88
|
+
const answers = output.value.answers.map((answer) => answer.type === "refusal" ? { name: answer.name, type: "error", reason: "refusal" } : answer);
|
|
89
|
+
const byName = new Map(answers.map((answer) => [answer.name, answer]));
|
|
90
|
+
const ordered = context.request.questions.flatMap((question) => byName.get(question.name) ?? []);
|
|
91
|
+
return new DecisionResponse({
|
|
92
|
+
answers: ordered.length === answers.length ? ordered : answers,
|
|
93
|
+
usage: OpenResponses.mapUsage(output.value.usage, context.providerMetadataKey),
|
|
94
|
+
providerMetadata: { [context.providerMetadataKey]: { model: output.value.model } },
|
|
95
|
+
});
|
|
96
|
+
}),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
export const route = DecisionRoute.make({
|
|
100
|
+
id: ID,
|
|
101
|
+
provider: "openai",
|
|
102
|
+
protocol,
|
|
103
|
+
endpoint: Endpoint.path(PATH, { baseURL: DEFAULT_BASE_URL }),
|
|
104
|
+
});
|
|
105
|
+
export const OpenAIDecisions = {
|
|
106
|
+
protocol,
|
|
107
|
+
route,
|
|
108
|
+
};
|
|
@@ -151,7 +151,7 @@ export type MediaReference = {
|
|
|
151
151
|
*/
|
|
152
152
|
export declare const mediaReference: (asset: Media.Asset, provider: ProviderID | undefined, label: string) => Effect.Effect<MediaReference, AIError>;
|
|
153
153
|
/**
|
|
154
|
-
* Lift a tool-result file into a `MediaPart`. Tool files carry either a data URL,
|
|
154
|
+
* Lift a tool-result file into a `MediaPart`. Tool files carry either a data URL, a URI, or raw base64 in
|
|
155
155
|
* `uri`; the declared `mime` wins over any data-URL prefix so tool authors control the type the model sees.
|
|
156
156
|
*/
|
|
157
157
|
export declare const toolFileMedia: (item: Tool.FileContent) => MediaPart;
|
package/dist/protocols/shared.js
CHANGED
|
@@ -186,14 +186,14 @@ export const mediaReference = (asset, provider, label) => {
|
|
|
186
186
|
return Effect.fail(invalidRequest(`${label} accepts inline bytes, data URLs, http(s) URLs${accepted}${got}`));
|
|
187
187
|
};
|
|
188
188
|
/**
|
|
189
|
-
* Lift a tool-result file into a `MediaPart`. Tool files carry either a data URL,
|
|
189
|
+
* Lift a tool-result file into a `MediaPart`. Tool files carry either a data URL, a URI, or raw base64 in
|
|
190
190
|
* `uri`; the declared `mime` wins over any data-URL prefix so tool authors control the type the model sees.
|
|
191
191
|
*/
|
|
192
192
|
export const toolFileMedia = (item) => {
|
|
193
193
|
const parsed = Media.parseDataUrl(item.uri);
|
|
194
194
|
const asset = parsed
|
|
195
195
|
? Media.from({ ...parsed.source, mediaType: item.mime })
|
|
196
|
-
:
|
|
196
|
+
: item.uri.includes("://")
|
|
197
197
|
? Media.url(item.uri, { mediaType: item.mime })
|
|
198
198
|
: Media.base64(item.uri, item.mime);
|
|
199
199
|
return Message.media(asset, { filename: item.name });
|