@opencode-ai/ai 0.0.0-dev-18195 → 0.0.0-dev-18198

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.
@@ -1,7 +1,7 @@
1
1
  import { Context, Effect, Layer } from "effect";
2
2
  import { RequestExecutor } from "./route/executor.js";
3
+ import { type AIError } from "./schema/index.js";
3
4
  import type { ImageOptions, ImageRequestFor, ImageResponse } from "./image.js";
4
- import type { AIError } from "./schema/index.js";
5
5
  export type Execute = RequestExecutor.Interface["execute"];
6
6
  export interface Interface {
7
7
  readonly generate: <Options extends ImageOptions>(request: ImageRequestFor<Options>) => Effect.Effect<ImageResponse, AIError>;
@@ -1,5 +1,7 @@
1
1
  import { Context, Effect, Layer } from "effect";
2
2
  import { RequestExecutor } from "./route/executor.js";
3
+ import { mergeHttpOptions } from "./schema/index.js";
4
+ import { sanitizeSurrogates } from "./utils/sanitize.js";
3
5
  export class Service extends Context.Service()("@opencode/ImageClient") {
4
6
  }
5
7
  export const generate = (request) => Effect.gen(function* () {
@@ -9,7 +11,14 @@ export const generate = (request) => Effect.gen(function* () {
9
11
  export const layer = Layer.effect(Service, Effect.gen(function* () {
10
12
  const executor = yield* RequestExecutor.Service;
11
13
  return Service.of({
12
- generate: (request) => request.model.route.generate(request, executor.execute),
14
+ generate: (request) => request.model.route.generate({
15
+ ...sanitizeSurrogates({
16
+ ...request,
17
+ model: undefined,
18
+ http: mergeHttpOptions(request.model.http, request.http),
19
+ }),
20
+ model: request.model,
21
+ }, executor.execute),
13
22
  });
14
23
  }));
15
24
  export const ImageClient = {
@@ -5,6 +5,7 @@ import { RequestExecutor } from "./executor.js";
5
5
  import { Framing } from "./framing.js";
6
6
  import { HttpTransport } from "./transport/index.js";
7
7
  import { applyCachePolicy } from "../cache-policy.js";
8
+ import { sanitizeSurrogates } from "../utils/sanitize.js";
8
9
  import * as ProviderShared from "../protocols/shared.js";
9
10
  import { AIError, GenerationOptions, HttpOptions, LLMRequest, LLMResponse, LanguageModel, LLMEvent, InvalidProviderOutputReason, ProviderID, mergeGenerationOptions, mergeHttpOptions, mergeProviderOptions, } from "../schema/index.js";
10
11
  const makeRouteLanguageModel = (route, mapped) => {
@@ -159,7 +160,8 @@ export function make(input) {
159
160
  });
160
161
  }
161
162
  const compile = Effect.fn("LLM.compile")(function* (request, options) {
162
- const resolved = applyCachePolicy(resolveRequestOptions(request));
163
+ const original = applyCachePolicy(resolveRequestOptions(request));
164
+ const resolved = LLMRequest.update(original, sanitizeSurrogates({ ...LLMRequest.input(original), model: undefined }));
163
165
  const route = resolved.model.route;
164
166
  const body = yield* route.body
165
167
  .from(resolved)
@@ -0,0 +1 @@
1
+ export declare const sanitizeSurrogates: <T>(value: T) => T;
@@ -0,0 +1,12 @@
1
+ import { isRecord } from "./record.js";
2
+ export const sanitizeSurrogates = (value) => {
3
+ if (typeof value === "string")
4
+ return value.toWellFormed();
5
+ if (Array.isArray(value))
6
+ return value.map(sanitizeSurrogates);
7
+ if (value instanceof Uint8Array || value instanceof Error)
8
+ return value;
9
+ if (isRecord(value))
10
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key.toWellFormed(), sanitizeSurrogates(entry)]));
11
+ return value;
12
+ };
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-18195",
3
+ "version": "0.0.0-dev-18198",
4
4
  "name": "@opencode-ai/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@clack/prompts": "1.0.0-alpha.1",
32
32
  "@effect/platform-node": "4.0.0-rc.111",
33
- "@opencode-ai/http-recorder": "0.0.0-dev-18195",
33
+ "@opencode-ai/http-recorder": "0.0.0-dev-18198",
34
34
  "@tsconfig/bun": "1.0.9",
35
35
  "@types/bun": "1.3.13",
36
36
  "@typescript/native-preview": "7.0.0-dev.20251207.1",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@smithy/eventstream-codec": "4.2.14",
41
41
  "@smithy/util-utf8": "4.2.2",
42
- "@opencode-ai/schema": "0.0.0-dev-18195",
42
+ "@opencode-ai/schema": "0.0.0-dev-18198",
43
43
  "aws4fetch": "1.0.20",
44
44
  "effect": "4.0.0-rc.111",
45
45
  "google-auth-library": "10.5.0"