Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 166 to 318

Compare

+43 −4 in 2 places
Lines 1–27 at 318 (were 1–7 at 166)
1+/** Internal values may expose an exact streaming representation without changing public toJSON. */
2+const streamingValues = new WeakMap<object, () => unknown>();
3+export function registerJsonChunkValue(value: object, representation: () => unknown): void {
4+ streamingValues.set(value, representation);
5+}
6+
7+/** A JSON string backed by bounded, replayable UTF-16 chunks. */
8+export class JsonStringChunks {
9+ readonly chunks: () => Iterable<string>;
10+ constructor(chunks: () => Iterable<string>) {
11+ this.chunks = chunks;
12+ }
13+ toJSON(): string {
14+ return [...this.chunks()].join("");
15+ }
16+}
118/** JSON.stringify-compatible chunks for canonical data, without a whole-value string.
219 * Individual input strings and object key lists still belong to the caller.
320 */
4−export function* jsonValueChunks(input: unknown): IterableIterator<string> {
21+export function* jsonValueChunks(
22+ input: unknown,
23+ options: { maxDepth?: number; unboxPrimitives?: boolean } = {},
24+): IterableIterator<string> {
525 const active = new Set<object>();
626 function* string(value: string): IterableIterator<string> {
727 yield '"';
Lines 36–74 at 318 (were 16–35 at 166)
1636 yield '"';
1737 }
1838 const normalize = (value: unknown, key: string): unknown => {
39+ if (value instanceof JsonStringChunks) return value;
1940 if (value !== null && typeof value === "object") {
41+ const streaming = streamingValues.get(value);
42+ if (streaming) return streaming();
2043 const toJSON = (value as { toJSON?: unknown }).toJSON;
21− if (typeof toJSON === "function") return toJSON.call(value, key);
44+ if (typeof toJSON === "function") value = toJSON.call(value, key);
2245 }
46+ if (options.unboxPrimitives && (value instanceof String || value instanceof Number || value instanceof Boolean))
47+ return value.valueOf();
2348 return value;
2449 };
2550 const omitted = (value: unknown) => value === undefined || typeof value === "function" || typeof value === "symbol";
2651 function* encode(value: unknown): IterableIterator<string> {
27− if (typeof value === "string") yield* string(value);
52+ if (value instanceof JsonStringChunks) {
53+ yield '"';
54+ let pending = "";
55+ for (const chunk of value.chunks()) {
56+ if (typeof chunk !== "string" || chunk.length > 16384) throw Error("JSON string chunk exceeds bound");
57+ const text = pending + chunk;
58+ let end = text.length;
59+ const last = text.charCodeAt(end - 1);
60+ if (last >= 0xd800 && last <= 0xdbff) end--;
61+ pending = text.slice(end);
62+ if (end) yield JSON.stringify(text.slice(0, end)).slice(1, -1);
63+ }
64+ if (pending) yield JSON.stringify(pending).slice(1, -1);
65+ yield '"';
66+ } else if (typeof value === "string") yield* string(value);
2867 else if (value === null || typeof value === "boolean" || typeof value === "number") yield JSON.stringify(value);
2968 else if (typeof value !== "object" || value === null) throw Error("unsupported canonical JSON value");
3069 else {
3170 if (active.has(value)) throw Error("cyclic canonical JSON value");
32− if (active.size >= 128) throw Error("canonical JSON depth exceeds bound");
71+ if (active.size >= (options.maxDepth ?? 128)) throw Error("canonical JSON depth exceeds bound");
3372 active.add(value);
3473 try {
3574 if (Array.isArray(value)) {
MCP
compare on this site's /mcp
CLI
abso diff 166 318 src/engine/json-value-chunks.ts --json
JSON
/christopher/abso-core/compare/166..318?file=src%2Fengine%2Fjson-value-chunks.ts&format=json