@opencode/ai 0.0.0-dev-21717 → 0.0.0-dev-21733

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 CHANGED
@@ -186,14 +186,19 @@ console.log(response.answers.refund.probability)
186
186
  `OPENCODE_API_KEY`. OpenRouter, Vercel AI Gateway, and OpenAI use the same provider shape:
187
187
 
188
188
  ```ts
189
- import { OpenAI, OpenRouter, VercelAIGateway } from "@opencode/ai/providers"
189
+ import { Baseten, DigitalOcean, OpenAI, OpenRouter, VercelAIGateway } from "@opencode/ai/providers"
190
190
 
191
191
  OpenRouter.configure().experimental.evaluation("typesafe/jev-1.13")
192
192
  VercelAIGateway.configure().experimental.evaluation("typesafe-ai/jev")
193
+ Baseten.configure().experimental.evaluation("decision-models/baseten-elephant-9b-latest")
194
+ DigitalOcean.configure().experimental.evaluation("typesafe-jev-1.13.0")
193
195
  OpenAI.configure().experimental.evaluation("gpt-6-luna")
194
196
  ```
195
197
 
196
198
  OpenRouter reads `OPENROUTER_API_KEY`. Vercel reads `AI_GATEWAY_API_KEY`, then `VERCEL_OIDC_TOKEN`.
199
+ Baseten reads `BASETEN_API_KEY`, accepts `max_len` in `options`, and returns unrounded values, so
200
+ `response.rounding` is unset. DigitalOcean reads
201
+ `DIGITALOCEAN_ACCESS_TOKEN`, `DIGITALOCEAN_API_KEY`, then `DO_INFERENCE_API_KEY`.
197
202
  OpenAI reads `OPENAI_API_KEY` and calls `/v1/decisions`.
198
203
  The common API uses `boolean`; System One routes lower it to native `noul`, and OpenAI lowers it to
199
204
  `predicate`. OpenAI predicates take no criteria, so boolean criteria fail before the request, and a
@@ -575,9 +580,13 @@ call rather than being dropped, so check this table before swapping only the `mo
575
580
  | Replicate | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ (use `providerOptions`) | ✗ |
576
581
  | Stability `image` | 1 | ✗ | ✓ | ✓ | ✓ | 1 (not on `core`) | ✗ |
577
582
  | Stability `upscale()` | ✗ | ✗ | ✗ | ✓ | ✓ | exactly 1 (required) | ✗ |
583
+ | Vercel AI Gateway | ✓ | per model | ✗ | ✗ | ignored | per model | per model |
584
+ | Cloudflare Workers AI | 1 | ✓² | ✗ | ✓² | ✗ | ✗ | ✗ |
578
585
 
579
586
  ✓ lowers natively; ✗ fails whenever the field is set (including `n: 1`); `1` means `n > 1` fails. ¹ `Image.stream` on OpenAI generates one image. fal
580
- rejects `size` and `aspectRatio` together; which one a fal or BFL model takes depends on the model.
587
+ rejects `size` and `aspectRatio` together; which one a fal or BFL model takes depends on the model. Vercel AI Gateway
588
+ forwards `format` but does not apply it, so the returned bytes keep the upstream model's own format. ² Workers AI
589
+ `@cf/black-forest-labs/flux-1-schnell` takes neither `size` nor `seed`, and the provider rejects them.
581
590
 
582
591
  `Media.Asset` is the one asset type shared by image requests, image responses, LLM messages, and tool results.
583
592
  `asset.source` is the serializable `Media.Source` (`bytes`, `base64`, `url`, or `ref`); `asset.bytes()`,
@@ -1,4 +1,4 @@
1
- import { EvaluationModel } from "./evaluation.js";
1
+ import { EvaluationModel, type EvaluationRounding } from "./evaluation.js";
2
2
  import { MediaRoute } from "../route/media.js";
3
3
  import type { ProviderID } from "../schema/index.js";
4
4
  export interface ModelInput extends MediaRoute.ModelInput {
@@ -6,6 +6,7 @@ export interface ModelInput extends MediaRoute.ModelInput {
6
6
  readonly provider: ProviderID;
7
7
  /** The Run API base, `.../client/v4/accounts/{account}/ai/run`. */
8
8
  readonly baseURL: string;
9
+ readonly rounding?: EvaluationRounding;
9
10
  }
10
11
  /** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One request body as `input`. */
11
12
  export declare const model: (input: ModelInput) => EvaluationModel<import("./evaluation.js").EvaluationOptions>;
@@ -1,5 +1,5 @@
1
1
  import { Effect, Schema } from "effect";
2
- import { EvaluationModel } from "./evaluation.js";
2
+ import { EvaluationModel, } from "./evaluation.js";
3
3
  import { SystemOne } from "./system-one.js";
4
4
  import { Endpoint } from "../route/endpoint.js";
5
5
  import { MediaProtocol } from "../route/media-protocol.js";
@@ -26,7 +26,7 @@ export const model = (input) => {
26
26
  from: (request) => SystemOne.encodeInput(request).pipe(Effect.map((body) => MediaProtocol.json({ model: request.model.id, input: body }))),
27
27
  },
28
28
  response: {
29
- decode: (response) => decodeEnvelope(response).pipe(Effect.map((output) => SystemOne.toResponse("answers" in output.value.result ? output.value.result : output.value.result.result, input.provider))),
29
+ decode: (response) => decodeEnvelope(response).pipe(Effect.map((output) => SystemOne.toResponse("answers" in output.value.result ? output.value.result : output.value.result.result, input.provider, input.rounding))),
30
30
  },
31
31
  }),
32
32
  endpoint: Endpoint.path("", { baseURL: input.baseURL }),
@@ -1,5 +1,5 @@
1
1
  import { Effect, Schema } from "effect";
2
- import { EvaluationModel, EvaluationResponse, type EvaluationOptions, type EvaluationRequestFor } from "./evaluation.js";
2
+ import { EvaluationModel, EvaluationResponse, EvaluationRounding, type EvaluationOptions, type EvaluationRequestFor } from "./evaluation.js";
3
3
  import { type Definition as AuthDefinition } from "../route/auth.js";
4
4
  import { AIError, HttpOptions, ModelID } from "../schema/index.js";
5
5
  export declare const Response: Schema.Struct<{
@@ -35,7 +35,9 @@ export interface ModelInput {
35
35
  readonly baseURL: string;
36
36
  readonly headers?: Record<string, string>;
37
37
  readonly http?: HttpOptions;
38
+ readonly rounding?: EvaluationRounding;
38
39
  }
40
+ export declare const jevRounding: EvaluationRounding;
39
41
  /** The System One request body without `model`, with `boolean` questions lowered to native `noul`. */
40
42
  export declare const encodeInput: (req: EvaluationRequestFor) => Effect.Effect<{
41
43
  readonly [x: string]: unknown;
@@ -77,7 +79,7 @@ export declare const encodeInput: (req: EvaluationRequestFor) => Effect.Effect<{
77
79
  };
78
80
  };
79
81
  }, AIError, never>;
80
- export declare const toResponse: (data: typeof Response.Type, providerMetadataKey: string) => EvaluationResponse;
82
+ export declare const toResponse: (data: typeof Response.Type, providerMetadataKey: string, rounding?: EvaluationRounding) => EvaluationResponse;
81
83
  export declare const model: <Options extends EvaluationOptions = EvaluationOptions>(cfg: ModelInput) => EvaluationModel<Options>;
82
84
  export declare const SystemOne: {
83
85
  readonly Response: Schema.Struct<{
@@ -108,4 +110,5 @@ export declare const SystemOne: {
108
110
  readonly encodeInput: typeof encodeInput;
109
111
  readonly toResponse: typeof toResponse;
110
112
  readonly model: typeof model;
113
+ readonly jevRounding: EvaluationRounding;
111
114
  };
@@ -55,13 +55,14 @@ export const Response = Schema.Struct({
55
55
  provider: Schema.optional(Schema.String),
56
56
  provider_metadata: Schema.optional(ProviderMetadata),
57
57
  });
58
+ export const jevRounding = new EvaluationRounding({ probabilityDecimals: 2, scoreDecimals: 2 });
58
59
  /** The System One request body without `model`, with `boolean` questions lowered to native `noul`. */
59
60
  export const encodeInput = (req) => Schema.encodeUnknownEffect(Input)({
60
61
  ...mergeJsonRecords(req.options, req.http?.body),
61
62
  state: req.state,
62
63
  questions: Object.fromEntries(Object.entries(req.questions).map(([id, x]) => [id, x.type === "boolean" ? { ...x, type: "noul" } : x])),
63
64
  }).pipe(Effect.mapError((cause) => new AIError({ reason: new InvalidRequestError({ message: cause.message, cause }) })));
64
- export const toResponse = (data, providerMetadataKey) => {
65
+ export const toResponse = (data, providerMetadataKey, rounding) => {
65
66
  const legend = {};
66
67
  const answers = Object.fromEntries(Object.entries(data.answers).map(([id, answer]) => {
67
68
  if (answer.type === "noul")
@@ -106,7 +107,7 @@ export const toResponse = (data, providerMetadataKey) => {
106
107
  providerMetadata: { [providerMetadataKey]: data.usage },
107
108
  })
108
109
  : undefined,
109
- rounding: new EvaluationRounding({ probabilityDecimals: 2, scoreDecimals: 2 }),
110
+ rounding,
110
111
  providerMetadata: Object.keys(meta).length === 0 ? undefined : { [providerMetadataKey]: meta },
111
112
  });
112
113
  };
@@ -132,8 +133,8 @@ export const model = (cfg) => EvaluationModel.make({
132
133
  const fail = (message, cause, body) => new AIError({ reason: new InvalidProviderOutputError({ route: "system-one", message, body, http, cause }) });
133
134
  const text = yield* res.text.pipe(Effect.mapError((cause) => fail("Failed to read the System One response", cause)));
134
135
  const data = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Response))(text).pipe(Effect.mapError((cause) => fail("System One returned an invalid response", cause, text)));
135
- return toResponse(data, cfg.providerMetadataKey);
136
+ return toResponse(data, cfg.providerMetadataKey, cfg.rounding);
136
137
  }),
137
138
  },
138
139
  });
139
- export const SystemOne = { Response, encodeInput, toResponse, model };
140
+ export const SystemOne = { Response, encodeInput, toResponse, model, jevRounding };
@@ -0,0 +1,17 @@
1
+ import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
2
+ import { MediaProtocol } from "../route/media-protocol.js";
3
+ import type { MediaRoute } from "../route/media.js";
4
+ /** Native Run API inputs. Step counts are `steps` on FLUX and Lucid Origin and `num_steps` on the other models. */
5
+ export type CloudflareWorkersAIImageOptions = {
6
+ readonly steps?: number;
7
+ readonly num_steps?: number;
8
+ readonly guidance?: number;
9
+ readonly negative_prompt?: string;
10
+ } & Record<string, unknown>;
11
+ export type Request = ImageRequestFor<CloudflareWorkersAIImageOptions>;
12
+ export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
13
+ export declare const model: (input: MediaRoute.ModelInput) => ImageModel<CloudflareWorkersAIImageOptions>;
14
+ export declare const CloudflareWorkersAIImages: {
15
+ readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
16
+ readonly model: typeof model;
17
+ };
@@ -0,0 +1,72 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { ImageModel, ImageResponse } from "../image.js";
3
+ import { Media } from "../media.js";
4
+ import { MediaProtocol } from "../route/media-protocol.js";
5
+ import { mergeJsonRecords } from "../schema/index.js";
6
+ import { MediaInput } from "./utils/media-input.js";
7
+ const route = MediaProtocol.identity({
8
+ id: "cloudflare-workers-ai-images",
9
+ name: "Cloudflare Workers AI",
10
+ provider: "cloudflare-workers-ai",
11
+ });
12
+ /** FLUX.2 models only accept multipart form fields, even for a prompt alone. */
13
+ const MULTIPART_MODEL_PREFIX = "@cf/black-forest-labs/flux-2-";
14
+ const RESERVED_FORM_FIELDS = new Set(["prompt"]);
15
+ // ---------------------------------------------------------------------------
16
+ // 2. Response schema
17
+ // ---------------------------------------------------------------------------
18
+ const RunResponse = Schema.Struct({
19
+ result: Schema.Struct({
20
+ image: Schema.optional(Schema.String),
21
+ usage: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
22
+ }),
23
+ });
24
+ // ---------------------------------------------------------------------------
25
+ // 5. Request body construction
26
+ // ---------------------------------------------------------------------------
27
+ const fromRequest = Effect.fn("CloudflareWorkersAIImages.fromRequest")(function* (request) {
28
+ if (request.n !== undefined && request.n > 1)
29
+ return yield* route.unsupported("media.n", `${route.name} generates one image per request; call it once per image`);
30
+ const fields = {
31
+ prompt: request.prompt,
32
+ ...(request.size === undefined ? {} : MediaInput.dimensions(request.size)),
33
+ seed: request.seed,
34
+ };
35
+ const native = mergeJsonRecords(request.providerOptions, request.http?.body);
36
+ if (!request.model.id.startsWith(MULTIPART_MODEL_PREFIX))
37
+ return MediaProtocol.json(mergeJsonRecords(fields, native) ?? {});
38
+ const body = new FormData();
39
+ MediaInput.appendFields(body, fields, { overlay: native, reserved: RESERVED_FORM_FIELDS });
40
+ return MediaProtocol.multipart(body);
41
+ });
42
+ // ---------------------------------------------------------------------------
43
+ // 6. Response decoding
44
+ // ---------------------------------------------------------------------------
45
+ const decodeDocument = route.decodeJson(RunResponse);
46
+ // FLUX and Lucid Origin wrap base64 in the Run API envelope; the Stable Diffusion family, DreamShaper, and Phoenix
47
+ // answer with the raw image, whose declared content type does not always match the bytes.
48
+ const decodeResponse = Effect.fn("CloudflareWorkersAIImages.decodeResponse")(function* (response) {
49
+ if (!response.headers["content-type"]?.startsWith("application/json"))
50
+ return new ImageResponse({ images: [Media.bytes(yield* route.bytes(response))] });
51
+ const output = yield* decodeDocument(response);
52
+ const result = output.value.result;
53
+ if (result.image === undefined)
54
+ return yield* output.invalid(`${route.name} returned no image`);
55
+ return new ImageResponse({
56
+ images: [yield* MediaInput.decodedAsset(output.invalid, `${route.name} result`, result.image, undefined)],
57
+ providerMetadata: result.usage === undefined ? undefined : { "cloudflare-workers-ai": { usage: result.usage } },
58
+ });
59
+ });
60
+ // ---------------------------------------------------------------------------
61
+ // 7. Protocol and route
62
+ // ---------------------------------------------------------------------------
63
+ export const protocol = MediaProtocol.inline(route, {
64
+ unsupported: ["images", "mask", "aspectRatio", "format"],
65
+ body: { from: fromRequest },
66
+ response: { decode: decodeResponse },
67
+ });
68
+ export const model = (input) => ImageModel.fromRoute({ protocol, path: ({ request }) => `/${request.model.id}` }, input);
69
+ export const CloudflareWorkersAIImages = {
70
+ protocol,
71
+ model,
72
+ };
@@ -1,8 +1,9 @@
1
+ import { Schema } from "effect";
1
2
  import { ImageModel, type ImageRequestFor } from "../image.js";
2
3
  import { Media } from "../media.js";
3
4
  import { MediaProtocol } from "../route/media-protocol.js";
4
5
  import { MediaRoute } from "../route/media.js";
5
- import { type MediaUsage, type OpenString } from "../schema/index.js";
6
+ import { type OpenString } from "../schema/index.js";
6
7
  export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
7
8
  export declare const PATH = "/images/generations";
8
9
  export declare const EDIT_PATH = "/images/edits";
@@ -16,6 +17,13 @@ export type OpenAIImageOptions = {
16
17
  readonly partialImages?: number;
17
18
  } & Record<string, unknown>;
18
19
  export type Request = ImageRequestFor<OpenAIImageOptions>;
20
+ declare const Usage: Schema.Struct<{
21
+ readonly input_tokens: Schema.optional<Schema.Number>;
22
+ readonly output_tokens: Schema.optional<Schema.Number>;
23
+ readonly total_tokens: Schema.optional<Schema.Number>;
24
+ readonly input_tokens_details: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
25
+ readonly output_tokens_details: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
26
+ }>;
19
27
  /** `generate` reads the whole JSON response as one frame. */
20
28
  type Frame = string | {
21
29
  readonly document: string;
@@ -26,7 +34,7 @@ interface State {
26
34
  readonly size?: string;
27
35
  readonly quality?: string;
28
36
  readonly background?: string;
29
- readonly usage?: MediaUsage;
37
+ readonly usage?: Schema.Schema.Type<typeof Usage>;
30
38
  }
31
39
  export declare const protocol: MediaProtocol.Streamed<Request, {
32
40
  readonly type: "image-partial";
@@ -82,7 +90,10 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
82
90
  };
83
91
  } | undefined;
84
92
  }, Frame, State>;
85
- export declare const model: (input: MediaRoute.ModelInput) => ImageModel<OpenAIImageOptions>;
93
+ /** `provider` attributes models, refs, and metadata to an OpenAI-compatible host; it defaults to `openai`. */
94
+ export declare const model: (input: MediaRoute.ModelInput & {
95
+ readonly provider?: string;
96
+ }) => ImageModel<OpenAIImageOptions>;
86
97
  export declare const OpenAIImages: {
87
98
  readonly protocol: MediaProtocol.Streamed<Request, {
88
99
  readonly type: "image-partial";
@@ -4,7 +4,7 @@ import { Media } from "../media.js";
4
4
  import { Framing } from "../route/framing.js";
5
5
  import { MediaProtocol } from "../route/media-protocol.js";
6
6
  import { MediaRoute } from "../route/media.js";
7
- import { mergeJsonRecords } from "../schema/index.js";
7
+ import { mergeJsonRecords, ProviderID } from "../schema/index.js";
8
8
  import { ProviderShared } from "./shared.js";
9
9
  import { MediaInput } from "./utils/media-input.js";
10
10
  const route = MediaProtocol.identity({ id: "openai-images", name: "OpenAI Images", provider: "openai" });
@@ -74,7 +74,7 @@ const streamOptions = (request) => {
74
74
  };
75
75
  const isEdit = (request) => (request.images?.length ?? 0) > 0;
76
76
  const isInline = (asset) => asset.source.type === "bytes" || asset.source.type === "base64";
77
- const reference = (asset) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((item) => (item.type === "ref" ? { file_id: item.value } : { image_url: item.value })));
77
+ const reference = (asset, provider) => ProviderShared.mediaReference(asset, provider, route.name).pipe(Effect.map((item) => (item.type === "ref" ? { file_id: item.value } : { image_url: item.value })));
78
78
  const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request) {
79
79
  const images = request.images ?? [];
80
80
  const mask = request.mask;
@@ -91,8 +91,8 @@ const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request) {
91
91
  form.append("mask", MediaInput.blob(yield* MediaInput.inlineBytes(route.id, mask), mask.mediaType), "mask");
92
92
  return MediaProtocol.multipart(form);
93
93
  }
94
- const references = yield* Effect.forEach(images, reference);
95
- const maskReference = mask === undefined ? undefined : yield* reference(mask);
94
+ const references = yield* Effect.forEach(images, (image) => reference(image, request.model.provider));
95
+ const maskReference = mask === undefined ? undefined : yield* reference(mask, request.model.provider);
96
96
  return MediaProtocol.json(mergeJsonRecords({
97
97
  model: request.model.id,
98
98
  prompt: request.prompt,
@@ -103,14 +103,14 @@ const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request) {
103
103
  // ---------------------------------------------------------------------------
104
104
  // 6. Stream parsing
105
105
  // ---------------------------------------------------------------------------
106
- const usage = (value) => value === undefined
106
+ const usage = (value, provider) => value === undefined
107
107
  ? undefined
108
108
  : {
109
109
  type: "tokens",
110
110
  input: value.input_tokens,
111
111
  output: value.output_tokens,
112
112
  total: value.total_tokens,
113
- details: { openai: value },
113
+ details: { [provider]: value },
114
114
  };
115
115
  /** `size` echoes the rendered `WIDTHxHEIGHT`; `auto` or any other value leaves the dimensions unknown. */
116
116
  const info = (format, size) => {
@@ -135,7 +135,7 @@ const onEvent = Effect.fnUntraced(function* (state, frame) {
135
135
  size: event.size,
136
136
  quality: event.quality,
137
137
  background: event.background,
138
- usage: usage(event.usage),
138
+ usage: event.usage,
139
139
  },
140
140
  [ImageOutputEvent.make({ index: state.completed, image })],
141
141
  ];
@@ -157,19 +157,20 @@ const onDocument = Effect.fnUntraced(function* (frame) {
157
157
  size: decoded.size,
158
158
  quality: decoded.quality,
159
159
  background: decoded.background,
160
- usage: usage(decoded.usage),
160
+ usage: decoded.usage,
161
161
  };
162
162
  return [state, images.map((image, index) => ImageOutputEvent.make({ index, image }))];
163
163
  });
164
164
  const step = (state, frame) => (typeof frame === "string" ? onEvent(state, frame) : onDocument(frame));
165
- const finish = (state) => {
165
+ const finish = (state, context) => {
166
166
  if (state.completed === 0)
167
167
  return Effect.fail(route.incomplete());
168
+ const provider = context.request.model.provider;
168
169
  return Effect.succeed([
169
170
  ImageFinishEvent.make({
170
- usage: state.usage,
171
+ usage: usage(state.usage, provider),
171
172
  providerMetadata: {
172
- openai: {
173
+ [provider]: {
173
174
  outputFormat: state.format,
174
175
  size: state.size,
175
176
  quality: state.quality,
@@ -192,7 +193,12 @@ export const protocol = MediaProtocol.stream(route, {
192
193
  step,
193
194
  finish,
194
195
  });
195
- export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: ({ request }) => (isEdit(request) ? EDIT_PATH : PATH) }, input);
196
+ /** `provider` attributes models, refs, and metadata to an OpenAI-compatible host; it defaults to `openai`. */
197
+ export const model = (input) => ImageModel.fromRoute({
198
+ protocol: input.provider === undefined ? protocol : { ...protocol, provider: ProviderID.make(input.provider) },
199
+ baseURL: DEFAULT_BASE_URL,
200
+ path: ({ request }) => (isEdit(request) ? EDIT_PATH : PATH),
201
+ }, input);
196
202
  export const OpenAIImages = {
197
203
  protocol,
198
204
  model,
@@ -8,6 +8,10 @@ export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> &
8
8
  readonly baseURL?: string;
9
9
  readonly providerOptions?: OpenAIProviderOptionsInput;
10
10
  };
11
+ export interface BasetenEvaluationOptions {
12
+ readonly [key: string]: unknown;
13
+ readonly max_len?: number;
14
+ }
11
15
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & {
12
16
  readonly apiKey?: string;
13
17
  readonly baseURL?: string;
@@ -259,12 +263,21 @@ export declare const routes: Route<{
259
263
  export declare const configure: (input?: LanguageModelOptions) => {
260
264
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
261
265
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
266
+ experimental: {
267
+ evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<BasetenEvaluationOptions>;
268
+ };
262
269
  configure: typeof configure;
263
270
  };
264
271
  export declare const provider: {
265
272
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
266
273
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
274
+ experimental: {
275
+ evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<BasetenEvaluationOptions>;
276
+ };
267
277
  configure: typeof configure;
268
278
  };
279
+ export declare const experimental: {
280
+ evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<BasetenEvaluationOptions>;
281
+ };
269
282
  export declare const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
270
283
  export * as Baseten from "./baseten.js";
@@ -2,7 +2,8 @@ import { OpenAIChat } from "../protocols/openai-chat.js";
2
2
  import { AuthOptions } from "../route/auth-options.js";
3
3
  import { Route } from "../route/client.js";
4
4
  import { Endpoint } from "../route/endpoint.js";
5
- import { ProviderID } from "../schema/index.js";
5
+ import { HttpOptions, ProviderID } from "../schema/index.js";
6
+ import { SystemOne } from "../experimental/system-one.js";
6
7
  export const id = ProviderID.make("baseten");
7
8
  const baseURL = "https://inference.baseten.co/v1";
8
9
  export const route = Route.make({
@@ -16,18 +17,30 @@ export const route = Route.make({
16
17
  export const routes = [route];
17
18
  export const configure = (input = {}) => {
18
19
  const { apiKey: _apiKey, auth: _auth, baseURL: endpoint, ...defaults } = input;
20
+ const auth = AuthOptions.bearer(input, "BASETEN_API_KEY");
19
21
  const configured = route.with({
20
22
  ...defaults,
21
23
  endpoint: { baseURL: endpoint ?? baseURL },
22
- auth: AuthOptions.bearer(input, "BASETEN_API_KEY"),
24
+ auth,
25
+ });
26
+ const evaluation = (modelID) => SystemOne.model({
27
+ id: modelID,
28
+ provider: id,
29
+ providerMetadataKey: "baseten",
30
+ auth,
31
+ baseURL: endpoint ?? baseURL,
32
+ headers: input.headers,
33
+ http: HttpOptions.make(input.http),
23
34
  });
24
35
  return {
25
36
  id,
26
37
  model: (modelID) => configured.model({ id: modelID }),
38
+ experimental: { evaluation },
27
39
  configure,
28
40
  };
29
41
  };
30
42
  export const provider = configure();
43
+ export const experimental = provider.experimental;
31
44
  export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => configure({
32
45
  apiKey,
33
46
  baseURL,
@@ -1,4 +1,5 @@
1
1
  import { CloudflareRunEvaluation } from "../experimental/cloudflare-run-evaluation.js";
2
+ import { SystemOne } from "../experimental/system-one.js";
2
3
  import { AnthropicMessages, OpenAIChat, OpenAIResponses } from "../protocols/index.js";
3
4
  import { Auth } from "../route/auth.js";
4
5
  import { Endpoint } from "../route/endpoint.js";
@@ -89,6 +90,7 @@ export const configure = (input) => {
89
90
  baseURL: runBaseURL(input),
90
91
  headers: rest.headers,
91
92
  http: HttpOptions.make(input.http),
93
+ rounding: SystemOne.jevRounding,
92
94
  });
93
95
  return {
94
96
  id,
@@ -15,6 +15,7 @@ export type LanguageModelOptions = WorkersAIURL & Omit<RouteDefaultsInput, "prov
15
15
  export type Settings = ProviderPackage.Settings & OpenAIProviderOptionsInput & WorkersAIURL & {
16
16
  readonly apiKey?: string;
17
17
  };
18
+ export type { CloudflareWorkersAIImageOptions } from "../protocols/cloudflare-workers-ai-images.js";
18
19
  export declare const baseURL: (input: WorkersAIURL) => string;
19
20
  /** The Run API (`/ai/run`) next to the OpenAI-compatible `/ai/v1` base. */
20
21
  export declare const runBaseURL: (input: WorkersAIURL) => string;
@@ -266,8 +267,9 @@ export declare const configure: (input: LanguageModelOptions) => {
266
267
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
267
268
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
268
269
  experimental: {
269
- evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<import("../experimental.js").EvaluationOptions>;
270
+ evaluation: (modelID: string | ModelID) => import("../experimental/evaluation.js").EvaluationModel<import("../experimental/evaluation.js").EvaluationOptions>;
270
271
  };
272
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./cloudflare-workers-ai.js").CloudflareWorkersAIImageOptions>;
271
273
  configure: typeof configure;
272
274
  };
273
275
  export declare const provider: {
@@ -1,8 +1,11 @@
1
1
  import { CloudflareRunEvaluation } from "../experimental/cloudflare-run-evaluation.js";
2
+ import { EvaluationRounding } from "../experimental/evaluation.js";
3
+ import { CloudflareWorkersAIImages } from "../protocols/cloudflare-workers-ai-images.js";
2
4
  import { OpenAIChat } from "../protocols/openai-chat.js";
3
5
  import { AuthOptions } from "../route/auth-options.js";
4
6
  import { Route } from "../route/client.js";
5
7
  import { Endpoint } from "../route/endpoint.js";
8
+ import { MediaRoute } from "../route/media.js";
6
9
  import { HttpOptions, ProviderConfigurationError, ProviderID } from "../schema/index.js";
7
10
  export const id = ProviderID.make("cloudflare-workers-ai");
8
11
  export const authEnvVars = ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN", "CLOUDFLARE_API_TOKEN"];
@@ -35,6 +38,7 @@ export const route = Route.make({
35
38
  framing: OpenAIChat.framing,
36
39
  });
37
40
  export const routes = [route];
41
+ const clefRounding = new EvaluationRounding({ probabilityDecimals: 4, scoreDecimals: 4 });
38
42
  export const configure = (input) => {
39
43
  const { accountId: _accountId, apiKey: _apiKey, auth: _auth, baseURL: _baseURL, ...defaults } = input;
40
44
  const auth = AuthOptions.bearer(input, authEnvVars);
@@ -46,11 +50,16 @@ export const configure = (input) => {
46
50
  baseURL: runBaseURL(input),
47
51
  headers: input.headers,
48
52
  http: HttpOptions.make(input.http),
53
+ rounding: clefRounding,
49
54
  });
50
55
  return {
51
56
  id,
52
57
  model: (modelID) => configured.model({ id: modelID }),
53
58
  experimental: { evaluation },
59
+ image: (modelID) => CloudflareWorkersAIImages.model({
60
+ ...MediaRoute.deployment({ ...input, baseURL: runBaseURL(input) }, auth),
61
+ id: modelID,
62
+ }),
54
63
  configure,
55
64
  };
56
65
  };
@@ -454,12 +454,21 @@ export declare const routes: Route<{
454
454
  export declare const configure: (input?: LanguageModelOptions) => {
455
455
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
456
456
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
457
+ experimental: {
458
+ evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<import("../experimental.js").EvaluationOptions>;
459
+ };
457
460
  configure: typeof configure;
458
461
  };
459
462
  export declare const provider: {
460
463
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
461
464
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
465
+ experimental: {
466
+ evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<import("../experimental.js").EvaluationOptions>;
467
+ };
462
468
  configure: typeof configure;
463
469
  };
470
+ export declare const experimental: {
471
+ evaluation: (modelID: string | ModelID) => import("../experimental.js").EvaluationModel<import("../experimental.js").EvaluationOptions>;
472
+ };
464
473
  export declare const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
465
474
  export * as DigitalOcean from "./digitalocean.js";
@@ -4,7 +4,8 @@ import { AuthOptions } from "../route/auth-options.js";
4
4
  import { Route } from "../route/client.js";
5
5
  import { Endpoint } from "../route/endpoint.js";
6
6
  import { Protocol } from "../route/protocol.js";
7
- import { ProviderID } from "../schema/index.js";
7
+ import { HttpOptions, ProviderID } from "../schema/index.js";
8
+ import { SystemOne } from "../experimental/system-one.js";
8
9
  export const id = ProviderID.make("digitalocean");
9
10
  const baseURL = "https://inference.do-ai.run/v1";
10
11
  export const protocol = Protocol.make({
@@ -26,10 +27,21 @@ export const route = Route.make({
26
27
  export const routes = [route];
27
28
  export const configure = (input = {}) => {
28
29
  const { apiKey: _apiKey, auth: _auth, baseURL: endpoint, ...defaults } = input;
30
+ const auth = AuthOptions.bearer(input, ["DIGITALOCEAN_ACCESS_TOKEN", "DIGITALOCEAN_API_KEY", "DO_INFERENCE_API_KEY"]);
29
31
  const configured = route.with({
30
32
  ...defaults,
31
33
  endpoint: { baseURL: endpoint ?? baseURL },
32
- auth: AuthOptions.bearer(input, ["DIGITALOCEAN_ACCESS_TOKEN", "DIGITALOCEAN_API_KEY", "DO_INFERENCE_API_KEY"]),
34
+ auth,
35
+ });
36
+ const evaluation = (modelID) => SystemOne.model({
37
+ id: modelID,
38
+ provider: id,
39
+ providerMetadataKey: "digitalocean",
40
+ auth,
41
+ baseURL: endpoint ?? baseURL,
42
+ headers: input.headers,
43
+ http: HttpOptions.make(input.http),
44
+ rounding: SystemOne.jevRounding,
33
45
  });
34
46
  return {
35
47
  id,
@@ -39,10 +51,12 @@ export const configure = (input = {}) => {
39
51
  supportsPromptCacheKey: true,
40
52
  },
41
53
  }),
54
+ experimental: { evaluation },
42
55
  configure,
43
56
  };
44
57
  };
45
58
  export const provider = configure();
59
+ export const experimental = provider.experimental;
46
60
  export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => configure({
47
61
  apiKey,
48
62
  baseURL,
@@ -12,6 +12,7 @@ export const configure = (input = {}) => {
12
12
  baseURL: input.baseURL ?? baseURL,
13
13
  headers: input.headers,
14
14
  http: HttpOptions.make(input.http),
15
+ rounding: SystemOne.jevRounding,
15
16
  });
16
17
  return { id, experimental: { evaluation }, configure };
17
18
  };
@@ -107,6 +107,7 @@ export const configure = (input = {}) => {
107
107
  baseURL: input.baseURL ?? baseURL,
108
108
  headers: input.headers,
109
109
  http: HttpOptions.make(input.http),
110
+ rounding: SystemOne.jevRounding,
110
111
  });
111
112
  return {
112
113
  id,
@@ -12,6 +12,7 @@ export const configure = (input = {}) => {
12
12
  baseURL: input.baseURL ?? baseURL,
13
13
  headers: input.headers,
14
14
  http: HttpOptions.make(input.http),
15
+ rounding: SystemOne.jevRounding,
15
16
  });
16
17
  return { id, experimental: { evaluation }, configure };
17
18
  };
@@ -84,6 +84,7 @@ export declare const configure: (input?: Options) => {
84
84
  messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
85
85
  responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
86
86
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
87
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
87
88
  experimental: {
88
89
  evaluation: (modelID: string | ModelID) => EvaluationModel<EvaluationOptions>;
89
90
  };
@@ -95,6 +96,7 @@ export declare const provider: {
95
96
  messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
96
97
  responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
97
98
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
99
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
98
100
  experimental: {
99
101
  evaluation: (modelID: string | ModelID) => EvaluationModel<EvaluationOptions>;
100
102
  };
@@ -106,6 +108,7 @@ export declare const experimental: {
106
108
  export declare const messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
107
109
  export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
108
110
  export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
111
+ export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
109
112
  export declare const model: ProviderPackage.Definition<Settings, ProviderOptionsInput>["model"];
110
113
  export declare const messagesModel: ProviderPackage.Definition<Settings, ProviderOptionsInput>["model"];
111
114
  export declare const responsesModel: ProviderPackage.Definition<Settings, ProviderOptionsInput>["model"];
@@ -4,6 +4,7 @@ import { EvaluationAnswer, EvaluationInput, EvaluationModel, EvaluationQuestion,
4
4
  import { AnthropicMessages } from "../protocols/anthropic-messages.js";
5
5
  import { OpenAIChat } from "../protocols/openai-chat.js";
6
6
  import { OpenResponses } from "../protocols/open-responses.js";
7
+ import { OpenAIImages } from "../protocols/openai-images.js";
7
8
  import { JsonObject, optionalNull, ProviderShared } from "../protocols/shared.js";
8
9
  import { gatewayProtocol } from "../protocols/utils/gateway-protocol.js";
9
10
  import { Auth } from "../route/auth.js";
@@ -12,6 +13,7 @@ import { Route } from "../route/client.js";
12
13
  import { Endpoint } from "../route/endpoint.js";
13
14
  import { RequestExecutor } from "../route/executor.js";
14
15
  import { Framing } from "../route/framing.js";
16
+ import { MediaRoute } from "../route/media.js";
15
17
  import { AIError, HttpOptions, InvalidProviderOutputError, InvalidRequestError, LLMRequest, ModelID, ProviderID, ProviderMetadata, ProviderOptions, ReasoningEffort, Usage, } from "../schema/index.js";
16
18
  export const id = ProviderID.make("vercel-ai-gateway");
17
19
  const baseURL = "https://ai-gateway.vercel.sh/v1";
@@ -203,13 +205,16 @@ export const configure = (input = {}) => {
203
205
  }),
204
206
  },
205
207
  });
206
- return { id, model, messages, responses, chat, experimental: { evaluation }, configure };
208
+ const media = MediaRoute.deployment({ ...input, baseURL: configured.endpoint.baseURL }, configured.auth);
209
+ const image = (modelID) => OpenAIImages.model({ ...media, id: modelID, provider: id });
210
+ return { id, model, messages, responses, chat, image, experimental: { evaluation }, configure };
207
211
  };
208
212
  export const provider = configure();
209
213
  export const experimental = provider.experimental;
210
214
  export const messages = provider.messages;
211
215
  export const responses = provider.responses;
212
216
  export const chat = provider.chat;
217
+ export const image = provider.image;
213
218
  export const model = (modelID, settings) => fromSettings(settings).model(modelID);
214
219
  export const messagesModel = (modelID, settings) => fromSettings(settings).messages(modelID);
215
220
  export const responsesModel = (modelID, settings) => fromSettings(settings).responses(modelID);
@@ -153,6 +153,7 @@ export declare const identity: (input: {
153
153
  pending: (id: string) => AIError;
154
154
  contentPolicy: (message: string) => AIError;
155
155
  }, AIError, never>;
156
+ bytes: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<Uint8Array<ArrayBuffer>, AIError, never>;
156
157
  decodeJson: <A>(schema: Schema.Codec<A, unknown>) => (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<{
157
158
  body: string;
158
159
  http: HttpContext;
@@ -32,6 +32,14 @@ const FAILURES = {
32
32
  export const identity = (input) => {
33
33
  const provider = ProviderID.make(input.provider);
34
34
  const frameError = (message, body, cause) => new AIError({ reason: new InvalidProviderOutputError({ route: input.id, message, body, cause }) });
35
+ const readError = (http) => (cause) => new AIError({
36
+ reason: new InvalidProviderOutputError({
37
+ route: input.id,
38
+ message: `Failed to read the ${input.name} response`,
39
+ http,
40
+ cause,
41
+ }),
42
+ });
35
43
  /**
36
44
  * Read a text body while retaining the original payload and HTTP context on every downstream error. `invalid` is a
37
45
  * malformed provider document; `ended` is a generation that reached a terminal status without output (`failed`
@@ -41,14 +49,7 @@ export const identity = (input) => {
41
49
  */
42
50
  const text = Effect.fn("MediaProtocol.text")(function* (response) {
43
51
  const http = RequestExecutor.responseHttp(response);
44
- const body = yield* response.text.pipe(Effect.mapError((cause) => new AIError({
45
- reason: new InvalidProviderOutputError({
46
- route: input.id,
47
- message: `Failed to read the ${input.name} response`,
48
- http,
49
- cause,
50
- }),
51
- })));
52
+ const body = yield* response.text.pipe(Effect.mapError(readError(http)));
52
53
  return {
53
54
  body,
54
55
  http,
@@ -77,11 +78,14 @@ export const identity = (input) => {
77
78
  return { ...output, value };
78
79
  });
79
80
  };
81
+ /** Read a raw binary body, for providers that answer with the media bytes themselves. */
82
+ const bytes = (response) => response.arrayBuffer.pipe(Effect.map((buffer) => new Uint8Array(buffer)), Effect.mapError(readError(RequestExecutor.responseHttp(response))));
80
83
  return {
81
84
  id: input.id,
82
85
  name: input.name,
83
86
  provider,
84
87
  text,
88
+ bytes,
85
89
  decodeJson,
86
90
  /** Decode a submission response into the token and first snapshot. */
87
91
  decodeStarted: (schema, started) => {
@@ -20,8 +20,25 @@ export const detectMediaType = (bytes) => {
20
20
  }
21
21
  if (startsWith(bytes, [0x25, 0x50, 0x44, 0x46]))
22
22
  return "application/pdf";
23
- if (bytes.length >= 12 && ascii(bytes, 4, 8) === "ftyp")
23
+ if (bytes.length >= 12 && ascii(bytes, 4, 8) === "ftyp") {
24
+ // AVIF, HEIC, QuickTime and M4A share MP4's container; the major brand tells them apart, and generic HEIF brands
25
+ // list `avif`/`avis` among the compatible brands that follow the minor version.
26
+ const brand = ascii(bytes, 8, 12);
27
+ const boxEnd = Math.min(new DataView(bytes.buffer, bytes.byteOffset).getUint32(0), bytes.length);
28
+ const compatible = Array.from({ length: Math.floor((boxEnd - 16) / 4) }, (_, index) => ascii(bytes, 16 + index * 4, 20 + index * 4));
29
+ const generic = brand === "mif1" || brand === "msf1";
30
+ if (brand === "avif" ||
31
+ brand === "avis" ||
32
+ (generic && (compatible.includes("avif") || compatible.includes("avis"))))
33
+ return "image/avif";
34
+ if (generic || ["heic", "heix", "hevc", "hevx"].includes(brand))
35
+ return "image/heic";
36
+ if (brand === "qt ")
37
+ return "video/quicktime";
38
+ if (brand === "M4A ")
39
+ return "audio/mp4";
24
40
  return "video/mp4";
41
+ }
25
42
  if (startsWith(bytes, [0x1a, 0x45, 0xdf, 0xa3]))
26
43
  return "video/webm";
27
44
  if (startsWith(bytes, [0x49, 0x44, 0x33]))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-21717",
3
+ "version": "0.0.0-dev-21733",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "devDependencies": {
36
36
  "@clack/prompts": "1.0.0-alpha.1",
37
37
  "@effect/platform-node": "4.0.1",
38
- "@opencode/http-recorder": "0.0.0-dev-21717",
38
+ "@opencode/http-recorder": "0.0.0-dev-21733",
39
39
  "@tsconfig/bun": "1.0.9",
40
40
  "@types/bun": "1.4.3",
41
41
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -45,7 +45,7 @@
45
45
  "@aws-sdk/credential-providers": "3.1057.0",
46
46
  "@smithy/eventstream-codec": "4.2.14",
47
47
  "@smithy/util-utf8": "4.2.2",
48
- "@opencode/schema": "0.0.0-dev-21717",
48
+ "@opencode/schema": "0.0.0-dev-21733",
49
49
  "aws4fetch": "1.0.20",
50
50
  "effect": "4.0.1",
51
51
  "google-auth-library": "10.5.0"