@opencode/ai 0.0.0-dev-21266 → 0.0.0-dev-21268

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 +1,5 @@
1
+ /**
2
+ * Replace lone UTF-16 surrogates in every string, key and nested value. Unchanged
3
+ * subtrees are returned by reference so requests with large histories are not copied.
4
+ */
1
5
  export declare const sanitizeSurrogates: <T>(value: T) => T;
@@ -1,14 +1,31 @@
1
+ import { Schema } from "effect";
1
2
  import { Media } from "../media.js";
2
3
  import { isRecord } from "./record.js";
4
+ /**
5
+ * Replace lone UTF-16 surrogates in every string, key and nested value. Unchanged
6
+ * subtrees are returned by reference so requests with large histories are not copied.
7
+ */
3
8
  export const sanitizeSurrogates = (value) => {
4
9
  if (typeof value === "string")
5
- return value.toWellFormed();
6
- if (Array.isArray(value))
7
- return value.map(sanitizeSurrogates);
10
+ return (value.isWellFormed() ? value : value.toWellFormed());
11
+ if (Array.isArray(value)) {
12
+ const items = value.map(sanitizeSurrogates);
13
+ return (Object.getPrototypeOf(value) === Array.prototype && items.every((item, index) => item === value[index])
14
+ ? value
15
+ : items);
16
+ }
8
17
  // Media assets carry binary or base64 payloads and a lazy byte cache; flattening them into a record would drop both.
9
18
  if (value instanceof Uint8Array || value instanceof Error || value instanceof Media.Asset)
10
19
  return value;
11
- if (isRecord(value))
12
- return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key.toWellFormed(), sanitizeSurrogates(entry)]));
13
- return value;
20
+ if (!isRecord(value))
21
+ return value;
22
+ const entries = Object.entries(value);
23
+ const sanitized = entries.map(([key, entry]) => [sanitizeSurrogates(key), sanitizeSurrogates(entry)]);
24
+ // Changed nodes and other objects (such as Date) are copied into plain records as before. Unchanged plain
25
+ // records and Schema class instances are kept: a copy would hold the same fields, and Schema constructors
26
+ // decode such a copy back into an equal instance.
27
+ if (sanitized.every(([key, entry], index) => key === entries[index][0] && entry === entries[index][1]) &&
28
+ (Object.getPrototypeOf(value) === Object.prototype || Schema.isSchema(value.constructor)))
29
+ return value;
30
+ return Object.fromEntries(sanitized);
14
31
  };
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-21266",
3
+ "version": "0.0.0-dev-21268",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@clack/prompts": "1.0.0-alpha.1",
36
36
  "@effect/platform-node": "4.0.1",
37
- "@opencode/http-recorder": "0.0.0-dev-21266",
37
+ "@opencode/http-recorder": "0.0.0-dev-21268",
38
38
  "@tsconfig/bun": "1.0.9",
39
39
  "@types/bun": "1.4.0",
40
40
  "@typescript/native": "npm:typescript@7.0.2",
@@ -44,7 +44,7 @@
44
44
  "@aws-sdk/credential-providers": "3.1057.0",
45
45
  "@smithy/eventstream-codec": "4.2.14",
46
46
  "@smithy/util-utf8": "4.2.2",
47
- "@opencode/schema": "0.0.0-dev-21266",
47
+ "@opencode/schema": "0.0.0-dev-21268",
48
48
  "aws4fetch": "1.0.20",
49
49
  "effect": "4.0.1",
50
50
  "google-auth-library": "10.5.0"