@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.
Files changed (70) hide show
  1. package/README.md +55 -55
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/decision-client.d.ts +21 -0
  5. package/dist/decision-client.js +55 -0
  6. package/dist/decision.d.ts +452 -0
  7. package/dist/decision.js +143 -0
  8. package/dist/experimental.d.ts +0 -3
  9. package/dist/experimental.js +0 -2
  10. package/dist/index.d.ts +5 -0
  11. package/dist/index.js +4 -0
  12. package/dist/promise.d.ts +10 -1
  13. package/dist/promise.js +5 -0
  14. package/dist/protocols/alibaba-messages.d.ts +34 -0
  15. package/dist/protocols/anthropic-messages.d.ts +102 -0
  16. package/dist/protocols/anthropic-messages.js +32 -8
  17. package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
  18. package/dist/protocols/cloudflare-run-decisions.js +36 -0
  19. package/dist/protocols/index.d.ts +3 -0
  20. package/dist/protocols/index.js +3 -0
  21. package/dist/protocols/meta-messages.d.ts +34 -0
  22. package/dist/protocols/meta-messages.js +12 -0
  23. package/dist/protocols/openai-decisions.d.ts +22 -0
  24. package/dist/protocols/openai-decisions.js +108 -0
  25. package/dist/protocols/shared.d.ts +1 -1
  26. package/dist/protocols/shared.js +2 -2
  27. package/dist/protocols/system-one.d.ts +99 -0
  28. package/dist/protocols/system-one.js +228 -0
  29. package/dist/protocols/zai-messages.d.ts +34 -0
  30. package/dist/providers/alibaba.d.ts +34 -0
  31. package/dist/providers/amazon-bedrock-mantle.d.ts +34 -0
  32. package/dist/providers/anthropic-compatible.d.ts +34 -0
  33. package/dist/providers/anthropic.d.ts +34 -0
  34. package/dist/providers/baseten.d.ts +4 -10
  35. package/dist/providers/baseten.js +21 -8
  36. package/dist/providers/cloudflare-ai-gateway.d.ts +69 -3
  37. package/dist/providers/cloudflare-ai-gateway.js +10 -10
  38. package/dist/providers/cloudflare-workers-ai.d.ts +1 -3
  39. package/dist/providers/cloudflare-workers-ai.js +11 -12
  40. package/dist/providers/digitalocean.d.ts +3 -9
  41. package/dist/providers/digitalocean.js +10 -10
  42. package/dist/providers/google-vertex-messages.d.ts +34 -0
  43. package/dist/providers/meta.d.ts +34 -0
  44. package/dist/providers/minimax.d.ts +34 -0
  45. package/dist/providers/moonshot.d.ts +34 -0
  46. package/dist/providers/openai.d.ts +5 -10
  47. package/dist/providers/openai.js +11 -7
  48. package/dist/providers/opencode.d.ts +3 -9
  49. package/dist/providers/opencode.js +9 -9
  50. package/dist/providers/openrouter.d.ts +4 -10
  51. package/dist/providers/openrouter.js +8 -9
  52. package/dist/providers/typesafe-ai.d.ts +3 -9
  53. package/dist/providers/typesafe-ai.js +9 -9
  54. package/dist/providers/vercel-ai-gateway.d.ts +4 -15
  55. package/dist/providers/vercel-ai-gateway.js +13 -80
  56. package/dist/providers/zai-coding-plan.d.ts +34 -0
  57. package/dist/route/client.js +11 -0
  58. package/dist/route/decision.d.ts +57 -0
  59. package/dist/route/decision.js +74 -0
  60. package/package.json +3 -3
  61. package/dist/experimental/cloudflare-run-evaluation.d.ts +0 -15
  62. package/dist/experimental/cloudflare-run-evaluation.js +0 -43
  63. package/dist/experimental/evaluation-client.d.ts +0 -21
  64. package/dist/experimental/evaluation-client.js +0 -64
  65. package/dist/experimental/evaluation.d.ts +0 -242
  66. package/dist/experimental/evaluation.js +0 -108
  67. package/dist/experimental/openai-decisions.d.ts +0 -23
  68. package/dist/experimental/openai-decisions.js +0 -115
  69. package/dist/experimental/system-one.d.ts +0 -114
  70. package/dist/experimental/system-one.js +0 -140
@@ -0,0 +1,99 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { DecisionResponse, type DecisionModelCompatibility, type DecisionRequestFor } from "../decision.js";
3
+ import { DecisionRoute } from "../route/decision.js";
4
+ import { AIError } from "../schema/index.js";
5
+ export declare const DEFAULT_PATH = "/systemone";
6
+ export declare const DEFAULT_BASE_URL = "https://api.typesafe.ai/v1";
7
+ /** `messages` is Baseten's own placement (parts in a user message inside `state.messages`), set by its provider. */
8
+ type ImageInput = NonNullable<DecisionModelCompatibility["imageInput"]> | "messages";
9
+ export declare const Response: Schema.Struct<{
10
+ readonly model: Schema.String;
11
+ readonly answers: Schema.$Record<Schema.String, Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
12
+ readonly type: Schema.Literal<"noul">;
13
+ readonly noul: Schema.Number;
14
+ }>, Schema.Struct<{
15
+ readonly type: Schema.Literal<"choice">;
16
+ readonly choice: Schema.String;
17
+ readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
18
+ readonly confidence: Schema.Number;
19
+ }>, Schema.Struct<{
20
+ readonly type: Schema.Literal<"score">;
21
+ readonly score: Schema.Number;
22
+ readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
23
+ readonly confidence: Schema.Number;
24
+ }>]>>;
25
+ readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
26
+ readonly input_tokens: Schema.optional<Schema.Number>;
27
+ readonly output_tokens: Schema.optional<Schema.Number>;
28
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
29
+ readonly id: Schema.optional<Schema.String>;
30
+ readonly provider: Schema.optional<Schema.String>;
31
+ readonly provider_metadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
32
+ }>;
33
+ export type Response = Schema.Schema.Type<typeof Response>;
34
+ /** The System One body without `model`; media goes where the model's `imageInput` says, else `fallback`. */
35
+ export declare const encodeBody: (request: DecisionRequestFor, fallback: ImageInput) => Effect.Effect<{
36
+ questions: any;
37
+ state: unknown;
38
+ assets?: undefined;
39
+ } | {
40
+ questions: any;
41
+ state: readonly unknown[];
42
+ assets: {
43
+ [k: string]: {
44
+ type: string;
45
+ format: string;
46
+ data_base64: string;
47
+ };
48
+ };
49
+ }, AIError, never>;
50
+ /** Map System One's answers, keyed by question name, back to the request's question order. */
51
+ export declare const toResponse: (data: Response, request: DecisionRequestFor, providerMetadataKey: string, invalid: (message: string) => AIError) => Effect.Effect<never, AIError, never> | Effect.Effect<DecisionResponse, never, never>;
52
+ export declare const protocol: DecisionRoute.Protocol;
53
+ /** TypeSafe's API, the reference System One host; other hosts change the endpoint and auth with `route.with(...)`. */
54
+ export declare const route: DecisionRoute.Route;
55
+ export declare const SystemOne: {
56
+ readonly Response: Schema.Struct<{
57
+ readonly model: Schema.String;
58
+ readonly answers: Schema.$Record<Schema.String, Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
59
+ readonly type: Schema.Literal<"noul">;
60
+ readonly noul: Schema.Number;
61
+ }>, Schema.Struct<{
62
+ readonly type: Schema.Literal<"choice">;
63
+ readonly choice: Schema.String;
64
+ readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
65
+ readonly confidence: Schema.Number;
66
+ }>, Schema.Struct<{
67
+ readonly type: Schema.Literal<"score">;
68
+ readonly score: Schema.Number;
69
+ readonly probabilities: Schema.$Record<Schema.String, Schema.Number>;
70
+ readonly confidence: Schema.Number;
71
+ }>]>>;
72
+ readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
73
+ readonly input_tokens: Schema.optional<Schema.Number>;
74
+ readonly output_tokens: Schema.optional<Schema.Number>;
75
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
76
+ readonly id: Schema.optional<Schema.String>;
77
+ readonly provider: Schema.optional<Schema.String>;
78
+ readonly provider_metadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
79
+ }>;
80
+ readonly encodeBody: (request: DecisionRequestFor, fallback: ImageInput) => Effect.Effect<{
81
+ questions: any;
82
+ state: unknown;
83
+ assets?: undefined;
84
+ } | {
85
+ questions: any;
86
+ state: readonly unknown[];
87
+ assets: {
88
+ [k: string]: {
89
+ type: string;
90
+ format: string;
91
+ data_base64: string;
92
+ };
93
+ };
94
+ }, AIError, never>;
95
+ readonly toResponse: typeof toResponse;
96
+ readonly protocol: DecisionRoute.Protocol;
97
+ readonly route: DecisionRoute.Route;
98
+ };
99
+ export {};
@@ -0,0 +1,228 @@
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, Usage, mergeJsonRecords } from "../schema/index.js";
7
+ import { encodeJson } from "../utils/json.js";
8
+ import { JsonObject, ProviderShared } from "./shared.js";
9
+ export const DEFAULT_PATH = "/systemone";
10
+ export const DEFAULT_BASE_URL = "https://api.typesafe.ai/v1";
11
+ const Probability = Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 1 }));
12
+ const Answer = Schema.Union([
13
+ Schema.Struct({ type: Schema.Literal("noul"), noul: Probability }),
14
+ Schema.Struct({
15
+ type: Schema.Literal("choice"),
16
+ choice: Schema.String,
17
+ probabilities: Schema.Record(Schema.String, Probability),
18
+ confidence: Probability,
19
+ }),
20
+ Schema.Struct({
21
+ type: Schema.Literal("score"),
22
+ score: Schema.Number,
23
+ probabilities: Schema.Record(Schema.String, Probability),
24
+ confidence: Probability,
25
+ }),
26
+ ]).pipe(Schema.toTaggedUnion("type"));
27
+ const NativeUsage = Schema.StructWithRest(Schema.Struct({
28
+ input_tokens: Schema.optional(Schema.Number),
29
+ output_tokens: Schema.optional(Schema.Number),
30
+ }), [JsonObject]);
31
+ export const Response = Schema.Struct({
32
+ model: Schema.String,
33
+ answers: Schema.Record(Schema.String, Answer),
34
+ usage: Schema.optional(NativeUsage),
35
+ id: Schema.optional(Schema.String),
36
+ provider: Schema.optional(Schema.String),
37
+ provider_metadata: Schema.optional(Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Unknown))),
38
+ });
39
+ const ID = "system-one";
40
+ const NAME = "System One";
41
+ /** The System One body without `model`; media goes where the model's `imageInput` says, else `fallback`. */
42
+ export const encodeBody = Effect.fn("SystemOne.encodeBody")(function* (request, fallback) {
43
+ const questions = yield* encodeQuestions(request.questions);
44
+ const placed = yield* placeMedia(request, request.model.compatibility?.imageInput ?? fallback);
45
+ return { ...mergeJsonRecords(request.providerOptions, request.http?.body), ...placed, questions };
46
+ });
47
+ const encodeQuestions = (questions) => Effect.forEach(questions, (question) => {
48
+ if (question.type === "predicate")
49
+ return Effect.succeed([question.name, { type: "noul", instructions: question.instructions }]);
50
+ if (question.type === "score")
51
+ return Effect.succeed([
52
+ question.name,
53
+ {
54
+ type: "score",
55
+ instructions: question.instructions,
56
+ criteria: question.levels.map((level) => level.description === undefined ? level.label : `${level.label}: ${level.description}`),
57
+ },
58
+ ]);
59
+ // Options are map keys, so `true` is sent as "true" and mapped back by `choiceValue`.
60
+ const keys = question.choices.map((choice) => String(choice.value));
61
+ if (new Set(keys).size !== keys.length)
62
+ return Effect.fail(ProviderShared.invalidRequest(`System One choice options are strings; "${question.name}" has a boolean and a string with the same text`));
63
+ return Effect.succeed([
64
+ question.name,
65
+ {
66
+ type: "choice",
67
+ instructions: question.instructions,
68
+ criteria: Object.fromEntries(question.choices.map((choice) => [String(choice.value), choice.description ?? null])),
69
+ },
70
+ ]);
71
+ }).pipe(Effect.map(Object.fromEntries));
72
+ const placeMedia = Effect.fnUntraced(function* (request, imageInput) {
73
+ const parts = request.input;
74
+ const unsupported = (asset, accepted) => new AIError({
75
+ reason: new UnsupportedOperationError({
76
+ operation: "decision.media",
77
+ provider: request.model.provider,
78
+ route: request.model.route.id,
79
+ message: `${NAME} takes ${accepted} here; got ${asset.mediaType}`,
80
+ }),
81
+ });
82
+ const media = parts.flatMap((part) => (part.type === "media" ? [part.media] : []));
83
+ if (media.length === 0)
84
+ return { state: state(parts.map(plain)) };
85
+ if (imageInput === "state")
86
+ return { state: yield* Effect.forEach(parts, (part) => stateItem(part, unsupported)) };
87
+ // Chat-style content in one user message: text and JSON as text parts, media as in `state`.
88
+ if (imageInput === "messages")
89
+ return {
90
+ state: {
91
+ messages: [
92
+ {
93
+ role: "user",
94
+ content: yield* Effect.forEach(parts, (part) => part.type === "media"
95
+ ? stateItem(part, unsupported)
96
+ : Effect.succeed({ type: "text", text: part.type === "text" ? part.text : encodeJson(part.value) })),
97
+ },
98
+ ],
99
+ },
100
+ };
101
+ if (imageInput === "images") {
102
+ const lists = { image: "images", audio: "audio", video: "videos" };
103
+ const unplaced = media.find((asset) => !Object.hasOwn(lists, asset.kind));
104
+ if (unplaced !== undefined)
105
+ return yield* unsupported(unplaced, "images, audio and video");
106
+ const inline = yield* Effect.forEach(media, (asset) => ProviderShared.requireInlineMedia(NAME, asset));
107
+ const fields = Object.fromEntries(Object.entries(lists).flatMap(([kind, field]) => {
108
+ const items = inline.filter((_, index) => media[index].kind === kind).map((item) => item.dataUrl);
109
+ return items.length === 0 ? [] : [[field, items]];
110
+ }));
111
+ return { state: state(parts.filter((part) => part.type !== "media").map(plain)), ...fields };
112
+ }
113
+ const unplaced = media.find((asset) => asset.kind !== "image");
114
+ if (unplaced !== undefined)
115
+ return yield* unsupported(unplaced, "images");
116
+ const inline = yield* Effect.forEach(media, (asset) => ProviderShared.requireInlineMedia(NAME, asset));
117
+ // Every occurrence of a reference string in the body is replaced with its image, so it must not be ordinary text.
118
+ const reference = (index) => `<image-${index + 1}>`;
119
+ const items = parts.reduce((acc, part) => part.type === "media"
120
+ ? { next: acc.next + 1, values: [...acc.values, reference(acc.next)] }
121
+ : { next: acc.next, values: [...acc.values, plain(part)] }, { next: 0, values: [] }).values;
122
+ return {
123
+ state: items,
124
+ assets: Object.fromEntries(inline.map((item, index) => [
125
+ reference(index),
126
+ { type: "image", format: item.mime.slice("image/".length), data_base64: item.base64 },
127
+ ])),
128
+ };
129
+ });
130
+ /** A lone text or JSON part is the state itself; several are a list. */
131
+ const state = (items) => (items.length === 1 ? items[0] : items);
132
+ const plain = (part) => {
133
+ if (part.type === "text")
134
+ return part.text;
135
+ if (part.type === "json")
136
+ return part.value;
137
+ return undefined;
138
+ };
139
+ const stateItem = (part, unsupported) => {
140
+ if (part.type !== "media")
141
+ return Effect.succeed(plain(part));
142
+ const asset = part.media;
143
+ if (asset.kind !== "image" && asset.kind !== "audio" && asset.kind !== "video")
144
+ return Effect.fail(unsupported(asset, "images, audio and video"));
145
+ return ProviderShared.requireInlineMedia(NAME, asset).pipe(Effect.map((inline) => {
146
+ if (asset.kind === "image")
147
+ return { type: "image_url", image_url: { url: inline.dataUrl } };
148
+ if (asset.kind === "video")
149
+ return { type: "video_url", video_url: { url: inline.dataUrl } };
150
+ return { type: "input_audio", input_audio: { data: inline.base64, format: inline.mime.slice("audio/".length) } };
151
+ }));
152
+ };
153
+ /** Map System One's answers, keyed by question name, back to the request's question order. */
154
+ export const toResponse = (data, request, providerMetadataKey, invalid) => {
155
+ const names = request.questions.map((question) => question.name);
156
+ if (Object.keys(data.answers).length !== names.length || !names.every((name) => Object.hasOwn(data.answers, name)))
157
+ return Effect.fail(invalid("System One answers do not match the requested questions"));
158
+ return Effect.succeed(new DecisionResponse({
159
+ answers: request.questions.map((question) => toAnswer(question, data.answers[question.name])),
160
+ usage: data.usage === undefined
161
+ ? undefined
162
+ : new Usage({
163
+ inputTokens: data.usage.input_tokens,
164
+ outputTokens: data.usage.output_tokens,
165
+ totalTokens: ProviderShared.totalTokens(data.usage.input_tokens, data.usage.output_tokens, undefined),
166
+ providerMetadata: { [providerMetadataKey]: data.usage },
167
+ }),
168
+ providerMetadata: {
169
+ [providerMetadataKey]: {
170
+ model: data.model,
171
+ ...(data.id === undefined ? {} : { responseId: data.id }),
172
+ ...(data.provider === undefined ? {} : { provider: data.provider }),
173
+ ...data.provider_metadata?.[providerMetadataKey],
174
+ },
175
+ },
176
+ }));
177
+ };
178
+ const toAnswer = (question, answer) => {
179
+ if (answer.type === "noul")
180
+ return { name: question.name, type: "predicate", probability: answer.noul };
181
+ if (answer.type === "choice") {
182
+ const choices = question.type === "choice" ? question.choices : [];
183
+ const value = (key) => choices.find((choice) => String(choice.value) === key)?.value ?? key;
184
+ const rank = (key) => {
185
+ const index = choices.findIndex((choice) => String(choice.value) === key);
186
+ return index === -1 ? choices.length : index;
187
+ };
188
+ return {
189
+ name: question.name,
190
+ type: "choice",
191
+ choice: value(answer.choice),
192
+ probabilities: Object.entries(answer.probabilities)
193
+ .toSorted(([a], [b]) => rank(a) - rank(b))
194
+ .map(([key, probability]) => ({ value: value(key), probability })),
195
+ confidence: answer.confidence,
196
+ };
197
+ }
198
+ const levels = question.type === "score" ? question.levels : [];
199
+ return {
200
+ name: question.name,
201
+ type: "score",
202
+ score: answer.score,
203
+ probabilities: Object.entries(answer.probabilities)
204
+ .map(([key, probability]) => ({ value: Number(key), label: levels[Number(key)]?.label ?? key, probability }))
205
+ .toSorted((a, b) => a.value - b.value),
206
+ confidence: answer.confidence,
207
+ };
208
+ };
209
+ const decodeDocument = MediaProtocol.identity({ id: ID, name: NAME, provider: "typesafe-ai" }).decodeJson(Response);
210
+ export const protocol = DecisionRoute.protocol({
211
+ id: ID,
212
+ name: NAME,
213
+ inlineMedia: true,
214
+ body: {
215
+ from: (request) => encodeBody(request, "assets").pipe(Effect.map((body) => ({ ...body, model: request.model.id }))),
216
+ },
217
+ response: {
218
+ decode: (response, context) => decodeDocument(response).pipe(Effect.flatMap((output) => toResponse(output.value, context.request, context.providerMetadataKey, output.invalid))),
219
+ },
220
+ });
221
+ /** TypeSafe's API, the reference System One host; other hosts change the endpoint and auth with `route.with(...)`. */
222
+ export const route = DecisionRoute.make({
223
+ id: ID,
224
+ provider: "typesafe-ai",
225
+ protocol,
226
+ endpoint: Endpoint.path("/systemone", { baseURL: DEFAULT_BASE_URL }),
227
+ });
228
+ export const SystemOne = { Response, encodeBody, toResponse, protocol, route };
@@ -58,6 +58,23 @@ export declare const protocol: Protocol<{
58
58
  readonly transformations?: {
59
59
  readonly oversized_image?: "downsize" | "error" | undefined;
60
60
  } | undefined;
61
+ } | {
62
+ readonly type: "video";
63
+ readonly source: {
64
+ readonly type: "base64";
65
+ readonly media_type: string;
66
+ readonly data: string;
67
+ } | {
68
+ readonly type: "url";
69
+ readonly url: string;
70
+ } | {
71
+ readonly type: "file";
72
+ readonly file_id: string;
73
+ };
74
+ readonly cache_control?: {
75
+ readonly type: "ephemeral";
76
+ readonly ttl?: "1h" | "5m" | undefined;
77
+ } | undefined;
61
78
  } | {
62
79
  readonly type: "document";
63
80
  readonly source: {
@@ -114,6 +131,23 @@ export declare const protocol: Protocol<{
114
131
  readonly transformations?: {
115
132
  readonly oversized_image?: "downsize" | "error" | undefined;
116
133
  } | undefined;
134
+ } | {
135
+ readonly type: "video";
136
+ readonly source: {
137
+ readonly type: "base64";
138
+ readonly media_type: string;
139
+ readonly data: string;
140
+ } | {
141
+ readonly type: "url";
142
+ readonly url: string;
143
+ } | {
144
+ readonly type: "file";
145
+ readonly file_id: string;
146
+ };
147
+ readonly cache_control?: {
148
+ readonly type: "ephemeral";
149
+ readonly ttl?: "1h" | "5m" | undefined;
150
+ } | undefined;
117
151
  } | {
118
152
  readonly type: "document";
119
153
  readonly source: {
@@ -227,6 +227,23 @@ export declare const routes: (Route<{
227
227
  readonly transformations?: {
228
228
  readonly oversized_image?: "downsize" | "error" | undefined;
229
229
  } | undefined;
230
+ } | {
231
+ readonly type: "video";
232
+ readonly source: {
233
+ readonly type: "base64";
234
+ readonly media_type: string;
235
+ readonly data: string;
236
+ } | {
237
+ readonly type: "url";
238
+ readonly url: string;
239
+ } | {
240
+ readonly type: "file";
241
+ readonly file_id: string;
242
+ };
243
+ readonly cache_control?: {
244
+ readonly type: "ephemeral";
245
+ readonly ttl?: "1h" | "5m" | undefined;
246
+ } | undefined;
230
247
  } | {
231
248
  readonly type: "document";
232
249
  readonly source: {
@@ -283,6 +300,23 @@ export declare const routes: (Route<{
283
300
  readonly transformations?: {
284
301
  readonly oversized_image?: "downsize" | "error" | undefined;
285
302
  } | undefined;
303
+ } | {
304
+ readonly type: "video";
305
+ readonly source: {
306
+ readonly type: "base64";
307
+ readonly media_type: string;
308
+ readonly data: string;
309
+ } | {
310
+ readonly type: "url";
311
+ readonly url: string;
312
+ } | {
313
+ readonly type: "file";
314
+ readonly file_id: string;
315
+ };
316
+ readonly cache_control?: {
317
+ readonly type: "ephemeral";
318
+ readonly ttl?: "1h" | "5m" | undefined;
319
+ } | undefined;
286
320
  } | {
287
321
  readonly type: "document";
288
322
  readonly source: {
@@ -80,6 +80,23 @@ export declare const routes: (Route<{
80
80
  readonly transformations?: {
81
81
  readonly oversized_image?: "downsize" | "error" | undefined;
82
82
  } | undefined;
83
+ } | {
84
+ readonly type: "video";
85
+ readonly source: {
86
+ readonly type: "base64";
87
+ readonly media_type: string;
88
+ readonly data: string;
89
+ } | {
90
+ readonly type: "url";
91
+ readonly url: string;
92
+ } | {
93
+ readonly type: "file";
94
+ readonly file_id: string;
95
+ };
96
+ readonly cache_control?: {
97
+ readonly type: "ephemeral";
98
+ readonly ttl?: "1h" | "5m" | undefined;
99
+ } | undefined;
83
100
  } | {
84
101
  readonly type: "document";
85
102
  readonly source: {
@@ -136,6 +153,23 @@ export declare const routes: (Route<{
136
153
  readonly transformations?: {
137
154
  readonly oversized_image?: "downsize" | "error" | undefined;
138
155
  } | undefined;
156
+ } | {
157
+ readonly type: "video";
158
+ readonly source: {
159
+ readonly type: "base64";
160
+ readonly media_type: string;
161
+ readonly data: string;
162
+ } | {
163
+ readonly type: "url";
164
+ readonly url: string;
165
+ } | {
166
+ readonly type: "file";
167
+ readonly file_id: string;
168
+ };
169
+ readonly cache_control?: {
170
+ readonly type: "ephemeral";
171
+ readonly ttl?: "1h" | "5m" | undefined;
172
+ } | undefined;
139
173
  } | {
140
174
  readonly type: "document";
141
175
  readonly source: {
@@ -72,6 +72,23 @@ export declare const routes: import("../route/client.js").Route<{
72
72
  readonly transformations?: {
73
73
  readonly oversized_image?: "downsize" | "error" | undefined;
74
74
  } | undefined;
75
+ } | {
76
+ readonly type: "video";
77
+ readonly source: {
78
+ readonly type: "base64";
79
+ readonly media_type: string;
80
+ readonly data: string;
81
+ } | {
82
+ readonly type: "url";
83
+ readonly url: string;
84
+ } | {
85
+ readonly type: "file";
86
+ readonly file_id: string;
87
+ };
88
+ readonly cache_control?: {
89
+ readonly type: "ephemeral";
90
+ readonly ttl?: "1h" | "5m" | undefined;
91
+ } | undefined;
75
92
  } | {
76
93
  readonly type: "document";
77
94
  readonly source: {
@@ -128,6 +145,23 @@ export declare const routes: import("../route/client.js").Route<{
128
145
  readonly transformations?: {
129
146
  readonly oversized_image?: "downsize" | "error" | undefined;
130
147
  } | undefined;
148
+ } | {
149
+ readonly type: "video";
150
+ readonly source: {
151
+ readonly type: "base64";
152
+ readonly media_type: string;
153
+ readonly data: string;
154
+ } | {
155
+ readonly type: "url";
156
+ readonly url: string;
157
+ } | {
158
+ readonly type: "file";
159
+ readonly file_id: string;
160
+ };
161
+ readonly cache_control?: {
162
+ readonly type: "ephemeral";
163
+ readonly ttl?: "1h" | "5m" | undefined;
164
+ } | undefined;
131
165
  } | {
132
166
  readonly type: "document";
133
167
  readonly source: {
@@ -57,6 +57,23 @@ export declare const routes: import("../route/client.js").Route<{
57
57
  readonly transformations?: {
58
58
  readonly oversized_image?: "downsize" | "error" | undefined;
59
59
  } | undefined;
60
+ } | {
61
+ readonly type: "video";
62
+ readonly source: {
63
+ readonly type: "base64";
64
+ readonly media_type: string;
65
+ readonly data: string;
66
+ } | {
67
+ readonly type: "url";
68
+ readonly url: string;
69
+ } | {
70
+ readonly type: "file";
71
+ readonly file_id: string;
72
+ };
73
+ readonly cache_control?: {
74
+ readonly type: "ephemeral";
75
+ readonly ttl?: "1h" | "5m" | undefined;
76
+ } | undefined;
60
77
  } | {
61
78
  readonly type: "document";
62
79
  readonly source: {
@@ -113,6 +130,23 @@ export declare const routes: import("../route/client.js").Route<{
113
130
  readonly transformations?: {
114
131
  readonly oversized_image?: "downsize" | "error" | undefined;
115
132
  } | undefined;
133
+ } | {
134
+ readonly type: "video";
135
+ readonly source: {
136
+ readonly type: "base64";
137
+ readonly media_type: string;
138
+ readonly data: string;
139
+ } | {
140
+ readonly type: "url";
141
+ readonly url: string;
142
+ } | {
143
+ readonly type: "file";
144
+ readonly file_id: string;
145
+ };
146
+ readonly cache_control?: {
147
+ readonly type: "ephemeral";
148
+ readonly ttl?: "1h" | "5m" | undefined;
149
+ } | undefined;
116
150
  } | {
117
151
  readonly type: "document";
118
152
  readonly source: {
@@ -8,7 +8,7 @@ export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> &
8
8
  readonly baseURL?: string;
9
9
  readonly providerOptions?: OpenAIProviderOptionsInput;
10
10
  };
11
- export interface BasetenEvaluationOptions {
11
+ export interface BasetenDecisionOptions {
12
12
  readonly [key: string]: unknown;
13
13
  readonly max_len?: number;
14
14
  }
@@ -283,21 +283,15 @@ export declare const routes: Route<{
283
283
  export declare const configure: (input?: LanguageModelOptions) => {
284
284
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
285
285
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
286
- experimental: {
287
- evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<BasetenEvaluationOptions>;
288
- };
286
+ decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
289
287
  configure: typeof configure;
290
288
  };
291
289
  export declare const provider: {
292
290
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
293
291
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
294
- experimental: {
295
- evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<BasetenEvaluationOptions>;
296
- };
292
+ decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
297
293
  configure: typeof configure;
298
294
  };
299
- export declare const experimental: {
300
- evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<BasetenEvaluationOptions>;
301
- };
295
+ export declare const decision: (modelID: string | ModelID) => import("../decision.js").DecisionModel<BasetenDecisionOptions>;
302
296
  export declare const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
303
297
  export * as Baseten from "./baseten.js";
@@ -1,9 +1,11 @@
1
+ import { Effect } from "effect";
1
2
  import { OpenAIChat } from "../protocols/openai-chat.js";
3
+ import { SystemOne } from "../protocols/system-one.js";
2
4
  import { AuthOptions } from "../route/auth-options.js";
3
5
  import { Route } from "../route/client.js";
6
+ import { DecisionRoute } from "../route/decision.js";
4
7
  import { Endpoint } from "../route/endpoint.js";
5
- import { HttpOptions, ProviderID } from "../schema/index.js";
6
- import { SystemOne } from "../experimental/system-one.js";
8
+ import { ProviderID } from "../schema/index.js";
7
9
  export const id = ProviderID.make("baseten");
8
10
  const baseURL = "https://inference.baseten.co/v1";
9
11
  export const route = Route.make({
@@ -15,6 +17,15 @@ export const route = Route.make({
15
17
  framing: OpenAIChat.framing,
16
18
  });
17
19
  export const routes = [route];
20
+ // Baseten reads media only as parts in a user message inside `state.messages`, not in any of the System One
21
+ // placements models.dev describes, so its decision protocol fixes that placement.
22
+ const decisionProtocol = DecisionRoute.protocol({
23
+ ...SystemOne.protocol,
24
+ id: "baseten-system-one",
25
+ body: {
26
+ from: (request) => SystemOne.encodeBody(request, "messages").pipe(Effect.map((body) => ({ ...body, model: request.model.id }))),
27
+ },
28
+ });
18
29
  export const configure = (input = {}) => {
19
30
  const { apiKey: _apiKey, auth: _auth, baseURL: endpoint, ...defaults } = input;
20
31
  const auth = AuthOptions.bearer(input, "BASETEN_API_KEY");
@@ -23,24 +34,26 @@ export const configure = (input = {}) => {
23
34
  endpoint: { baseURL: endpoint ?? baseURL },
24
35
  auth,
25
36
  });
26
- const evaluation = (modelID) => SystemOne.model({
27
- id: modelID,
37
+ const decisionRoute = DecisionRoute.make({
38
+ id: decisionProtocol.id,
28
39
  provider: id,
29
40
  providerMetadataKey: "baseten",
41
+ protocol: decisionProtocol,
42
+ endpoint: Endpoint.path("/systemone", { baseURL: endpoint ?? baseURL }),
30
43
  auth,
31
- baseURL: endpoint ?? baseURL,
32
44
  headers: input.headers,
33
- http: HttpOptions.make(input.http),
45
+ http: input.http,
34
46
  });
47
+ const decision = (modelID) => decisionRoute.model({ id: modelID });
35
48
  return {
36
49
  id,
37
50
  model: (modelID) => configured.model({ id: modelID }),
38
- experimental: { evaluation },
51
+ decision,
39
52
  configure,
40
53
  };
41
54
  };
42
55
  export const provider = configure();
43
- export const experimental = provider.experimental;
56
+ export const decision = provider.decision;
44
57
  export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => configure({
45
58
  apiKey,
46
59
  baseURL,