toolsplice 0.0.1 → 0.0.2
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 +62 -330
- package/dist/abortable.d.ts +6 -0
- package/dist/abortable.js +50 -0
- package/dist/adaptive-read.d.ts +50 -0
- package/dist/adaptive-read.js +780 -0
- package/dist/answer-wait.d.ts +7 -0
- package/dist/answer-wait.js +45 -0
- package/dist/cache-reads.d.ts +18 -0
- package/dist/cache-reads.js +89 -0
- package/dist/calibration-ledger.d.ts +37 -0
- package/dist/calibration-ledger.js +148 -0
- package/dist/calibration-marker.d.ts +4 -0
- package/dist/calibration-marker.js +77 -0
- package/dist/catalog-setup.d.ts +33 -0
- package/dist/catalog-setup.js +89 -0
- package/dist/catalog.d.ts +10 -0
- package/dist/catalog.js +42 -0
- package/dist/checkpoint-files.d.ts +15 -0
- package/dist/checkpoint-files.js +99 -0
- package/dist/cli.js +545 -14
- package/dist/coalesce-reads.d.ts +6 -0
- package/dist/coalesce-reads.js +33 -0
- package/dist/contract-caller.d.ts +2 -1
- package/dist/contract-caller.js +35 -16
- package/dist/contract-schema.d.ts +3 -1
- package/dist/contract-schema.js +34 -4
- package/dist/contracts.d.ts +1 -0
- package/dist/contracts.js +5 -1
- package/dist/core.d.ts +31 -1
- package/dist/core.js +27 -0
- package/dist/db-final-answer.d.ts +9 -0
- package/dist/db-final-answer.js +62 -0
- package/dist/define.d.ts +78 -0
- package/dist/define.js +14 -0
- package/dist/final-answer-stores.d.ts +71 -0
- package/dist/final-answer-stores.js +72 -0
- package/dist/final-answer.d.ts +32 -0
- package/dist/final-answer.js +104 -0
- package/dist/impact.d.ts +48 -0
- package/dist/impact.js +71 -0
- package/dist/index.d.ts +32 -1
- package/dist/index.js +28 -0
- package/dist/local-tool.d.ts +18 -0
- package/dist/local-tool.js +32 -0
- package/dist/mcp-apps.d.ts +53 -0
- package/dist/mcp-apps.js +32 -0
- package/dist/mcp-event-delivery.d.ts +98 -0
- package/dist/mcp-event-delivery.js +211 -0
- package/dist/mcp-extensions.d.ts +46 -0
- package/dist/mcp-extensions.js +200 -0
- package/dist/mcp-peer.d.ts +45 -0
- package/dist/mcp-peer.js +207 -0
- package/dist/mcp-server-card.d.ts +21 -0
- package/dist/mcp-server-card.js +54 -0
- package/dist/page-checkpoint.d.ts +71 -0
- package/dist/page-checkpoint.js +286 -0
- package/dist/page-read-gate.d.ts +15 -0
- package/dist/page-read-gate.js +48 -0
- package/dist/pattern.d.ts +1 -0
- package/dist/pattern.js +27 -5
- package/dist/probe.js +6 -19
- package/dist/read-pages.d.ts +25 -0
- package/dist/read-pages.js +85 -0
- package/dist/read-policy.d.ts +6 -0
- package/dist/read-policy.js +16 -0
- package/dist/read-steps.d.ts +12 -0
- package/dist/read-steps.js +36 -0
- package/dist/result-session.d.ts +109 -0
- package/dist/result-session.js +620 -0
- package/dist/route-checkpoint.d.ts +3 -0
- package/dist/route-checkpoint.js +80 -0
- package/dist/route-driver-cli.d.ts +3 -0
- package/dist/route-driver-cli.js +43 -0
- package/dist/route-evaluation.d.ts +141 -0
- package/dist/route-evaluation.js +329 -0
- package/dist/row-groups.d.ts +17 -0
- package/dist/row-groups.js +79 -0
- package/dist/row-query.d.ts +62 -0
- package/dist/row-query.js +172 -0
- package/dist/rules.d.ts +30 -0
- package/dist/rules.js +72 -0
- package/dist/run-diagnostics.d.ts +75 -0
- package/dist/run-diagnostics.js +212 -0
- package/dist/search-fetch.d.ts +50 -0
- package/dist/search-fetch.js +264 -0
- package/dist/skill-files.d.ts +9 -0
- package/dist/skill-files.js +49 -0
- package/dist/splice-diagnostics.d.ts +4 -0
- package/dist/splice-diagnostics.js +24 -16
- package/dist/splice-measure.d.ts +33 -0
- package/dist/splice-measure.js +55 -0
- package/dist/splice-project.d.ts +12 -6
- package/dist/splice-project.js +72 -20
- package/dist/splice-recording.d.ts +29 -2
- package/dist/splice-recording.js +22 -5
- package/dist/splice.d.ts +98 -1
- package/dist/splice.js +225 -27
- package/dist/sqlite-checkpoint-store.d.ts +5 -0
- package/dist/sqlite-checkpoint-store.js +91 -0
- package/dist/sqlite-checkpoint-worker.d.ts +1 -0
- package/dist/sqlite-checkpoint-worker.js +115 -0
- package/dist/test-difference.d.ts +13 -0
- package/dist/test-difference.js +42 -0
- package/dist/testing.d.ts +122 -0
- package/dist/testing.js +261 -0
- package/dist/text-pages.d.ts +24 -0
- package/dist/text-pages.js +36 -0
- package/dist/tool-discovery.d.ts +59 -0
- package/dist/tool-discovery.js +136 -0
- package/dist/unevaluated.d.ts +7 -0
- package/dist/unevaluated.js +156 -0
- package/dist/v2.js +25 -8
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workflow-json.js +1 -1
- package/docs/AGENT-FRAMEWORKS.md +431 -0
- package/docs/BENCHMARKS.md +43 -0
- package/docs/INTEGRATION-QUICKSTART.md +859 -0
- package/docs/LEARNING-AND-STORAGE.md +393 -0
- package/docs/MCP.md +204 -0
- package/docs/PROJECTS-AND-UPGRADES.md +67 -9
- package/docs/PYTHON-REFERENCE.md +348 -0
- package/docs/PYTHON.md +120 -0
- package/docs/RECORDING-AND-CORRECTIONS.md +30 -1
- package/docs/TESTING.md +259 -0
- package/examples/mcp-app/build.mjs +11 -0
- package/examples/mcp-app/view.mjs +22 -0
- package/examples/quickstart.mjs +43 -0
- package/examples/route-driver.mjs +67 -0
- package/integrations/ai.d.mts +36 -0
- package/integrations/ai.mjs +178 -0
- package/integrations/call-options.mjs +9 -0
- package/integrations/langchain.d.mts +31 -0
- package/integrations/langchain.mjs +114 -0
- package/integrations/managed.mjs +154 -0
- package/integrations/types.d.mts +13 -0
- package/package.json +47 -3
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createGuardCompiler } from "./contract-caller.js";
|
|
2
|
+
import { copyJson, jsonObject, parseWorkflowJson } from "./workflow-json.js";
|
|
3
|
+
const tokens = (text) => new Set(text
|
|
4
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
5
|
+
.toLowerCase()
|
|
6
|
+
.match(/[a-z0-9]+/g) ?? []);
|
|
7
|
+
const properties = (fields) => ({
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: fields,
|
|
10
|
+
required: Object.keys(fields),
|
|
11
|
+
additionalProperties: false,
|
|
12
|
+
});
|
|
13
|
+
export class CatalogSearch {
|
|
14
|
+
limit;
|
|
15
|
+
definition = {
|
|
16
|
+
name: "discover_tools",
|
|
17
|
+
description: "Find authorized tools by exact name or keywords. Returns matching names, descriptions and full input schemas for call_discovered_tool.",
|
|
18
|
+
inputSchema: properties({
|
|
19
|
+
query: { type: "string", minLength: 1, maxLength: 512 },
|
|
20
|
+
}),
|
|
21
|
+
};
|
|
22
|
+
#index;
|
|
23
|
+
constructor(tools, limit) {
|
|
24
|
+
this.limit = limit;
|
|
25
|
+
this.#index = tools.map((t) => ({
|
|
26
|
+
tool: t,
|
|
27
|
+
definition: copyJson(t.definition),
|
|
28
|
+
name: tokens(t.definition.name),
|
|
29
|
+
body: tokens((t.definition.description ?? "").slice(0, 2048)),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
matches(q) {
|
|
33
|
+
const words = tokens(q);
|
|
34
|
+
return this.#index
|
|
35
|
+
.map((entry) => {
|
|
36
|
+
let score = entry.definition.name.toLowerCase() === q.trim().toLowerCase()
|
|
37
|
+
? 10000
|
|
38
|
+
: 0;
|
|
39
|
+
for (const word of words)
|
|
40
|
+
score +=
|
|
41
|
+
(entry.name.has(word) ? 8 : 0) + (entry.body.has(word) ? 1 : 0);
|
|
42
|
+
return { entry, score };
|
|
43
|
+
})
|
|
44
|
+
.filter((r) => r.score > 0)
|
|
45
|
+
.sort((a, b) => b.score - a.score);
|
|
46
|
+
}
|
|
47
|
+
initial(question) {
|
|
48
|
+
if (typeof question !== "string" ||
|
|
49
|
+
!question.trim() ||
|
|
50
|
+
Buffer.byteLength(question) > 32768)
|
|
51
|
+
throw new Error("Expected a question of 1 to 32768 UTF-8 bytes.");
|
|
52
|
+
return this.matches(question)
|
|
53
|
+
.slice(0, this.limit)
|
|
54
|
+
.map((row) => row.entry.tool);
|
|
55
|
+
}
|
|
56
|
+
async execute(args) {
|
|
57
|
+
const q = args.query;
|
|
58
|
+
if (typeof q !== "string" || !q.trim() || q.length > 512)
|
|
59
|
+
throw new Error("Enter a bounded tool name or search query.");
|
|
60
|
+
return {
|
|
61
|
+
tools: this.matches(q)
|
|
62
|
+
.slice(0, this.limit)
|
|
63
|
+
.map(({ entry: { definition: d } }) => copyJson({
|
|
64
|
+
name: d.name,
|
|
65
|
+
description: d.description ?? "",
|
|
66
|
+
inputSchema: d.inputSchema,
|
|
67
|
+
})),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class CatalogCall {
|
|
72
|
+
definition = {
|
|
73
|
+
name: "call_discovered_tool",
|
|
74
|
+
description: "Call an authorized tool by its exact name. Encode its arguments as a JSON object string matching its discovered input schema.",
|
|
75
|
+
inputSchema: properties({
|
|
76
|
+
name: { type: "string" },
|
|
77
|
+
arguments: { type: "string" },
|
|
78
|
+
}),
|
|
79
|
+
};
|
|
80
|
+
#tools;
|
|
81
|
+
#compile;
|
|
82
|
+
#guards = new Map();
|
|
83
|
+
constructor(tools) {
|
|
84
|
+
this.#tools = new Map(tools.map((t) => [t.definition.name, t]));
|
|
85
|
+
}
|
|
86
|
+
resolve(args) {
|
|
87
|
+
const tool = typeof args.name === "string" && this.#tools.get(args.name);
|
|
88
|
+
if (!tool)
|
|
89
|
+
throw new Error("Unknown catalog tool.");
|
|
90
|
+
if (typeof args.arguments !== "string")
|
|
91
|
+
throw new Error("Pass a JSON object string for arguments.");
|
|
92
|
+
const input = parseWorkflowJson(args.arguments);
|
|
93
|
+
if (!jsonObject(input))
|
|
94
|
+
throw new Error("Tool arguments must be a JSON object.");
|
|
95
|
+
const name = tool.definition.name;
|
|
96
|
+
let guard = this.#guards.get(name);
|
|
97
|
+
if (!guard) {
|
|
98
|
+
guard = (this.#compile ??= createGuardCompiler())(tool.definition.inputSchema, name, "input");
|
|
99
|
+
this.#guards.set(name, guard);
|
|
100
|
+
}
|
|
101
|
+
if (!guard(input))
|
|
102
|
+
throw new Error("Arguments do not match the selected tool schema.");
|
|
103
|
+
return { tool, input };
|
|
104
|
+
}
|
|
105
|
+
async execute(args, options) {
|
|
106
|
+
const { tool, input } = this.resolve(args);
|
|
107
|
+
return tool.execute(input, options);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Limit model-visible schemas to requested matches. Pass only executables authorized for this run. */
|
|
111
|
+
export function discoverTools(tools, { threshold = 16, limit = 2, question, } = {}) {
|
|
112
|
+
if (!Number.isSafeInteger(threshold) ||
|
|
113
|
+
threshold < 1 ||
|
|
114
|
+
!Number.isSafeInteger(limit) ||
|
|
115
|
+
limit < 1 ||
|
|
116
|
+
limit > 8)
|
|
117
|
+
throw new RangeError("Invalid catalog threshold or result limit.");
|
|
118
|
+
const names = tools.map((t) => t.definition.name);
|
|
119
|
+
if (new Set(names).size !== names.length)
|
|
120
|
+
throw new Error("Duplicate catalog tool name.");
|
|
121
|
+
if (tools.length < threshold)
|
|
122
|
+
return [...tools];
|
|
123
|
+
if (names.some((n) => [
|
|
124
|
+
"discover_tools",
|
|
125
|
+
"call_discovered_tool",
|
|
126
|
+
"inspect_result",
|
|
127
|
+
"call_with_result",
|
|
128
|
+
].includes(n)))
|
|
129
|
+
throw new Error("Reserved catalog tool name.");
|
|
130
|
+
const search = new CatalogSearch(tools, limit);
|
|
131
|
+
return [
|
|
132
|
+
...(question === undefined ? [] : search.initial(question)),
|
|
133
|
+
search,
|
|
134
|
+
new CatalogCall(tools),
|
|
135
|
+
];
|
|
136
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Options, ValidateFunction } from "ajv";
|
|
2
|
+
type Schema = boolean | Record<string, unknown>;
|
|
3
|
+
/** Used only for modern schemas that explicitly request unevaluated-location checks.
|
|
4
|
+
* Ajv still compiles each assertion. Only the collection of successful locations is local.
|
|
5
|
+
* Every subvalidator resolves against the same detached, already-guarded schema. */
|
|
6
|
+
export declare function compileUnevaluated(root: Schema, options: Options): ValidateFunction;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// JSON Schema 2020-12 records the individual indices matched by contains and the
|
|
2
|
+
// properties evaluated by successful branches. Ajv alone tracks only an array prefix.
|
|
3
|
+
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
4
|
+
import { escapePointer, jsonObject } from "./workflow-json.js";
|
|
5
|
+
const maps = ["properties", "$defs", "definitions", "dependentSchemas"];
|
|
6
|
+
const lists = ["prefixItems", "allOf", "anyOf", "oneOf"];
|
|
7
|
+
const children = ["items", "contains", "not", "if", "then", "else", "propertyNames",
|
|
8
|
+
"additionalProperties", "unevaluatedItems", "unevaluatedProperties"];
|
|
9
|
+
/** Used only for modern schemas that explicitly request unevaluated-location checks.
|
|
10
|
+
* Ajv still compiles each assertion. Only the collection of successful locations is local.
|
|
11
|
+
* Every subvalidator resolves against the same detached, already-guarded schema. */
|
|
12
|
+
export function compileUnevaluated(root, options) {
|
|
13
|
+
const ajv = new Ajv2020(options);
|
|
14
|
+
const id = "urn:toolsplice:local-guard";
|
|
15
|
+
const paths = new WeakMap();
|
|
16
|
+
const schemas = new Map();
|
|
17
|
+
const validators = new Map();
|
|
18
|
+
const required = new Set();
|
|
19
|
+
const references = new Set();
|
|
20
|
+
function index(schema, path) {
|
|
21
|
+
schemas.set(path, schema);
|
|
22
|
+
if (typeof schema === "boolean")
|
|
23
|
+
return;
|
|
24
|
+
paths.set(schema, path);
|
|
25
|
+
if (typeof schema.$ref === "string")
|
|
26
|
+
references.add(decodeURIComponent(schema.$ref.slice(1)));
|
|
27
|
+
for (const key of maps) {
|
|
28
|
+
const entries = schema[key];
|
|
29
|
+
if (jsonObject(entries))
|
|
30
|
+
for (const [name, child] of Object.entries(entries))
|
|
31
|
+
index(child, path + "/" + key + "/" + escapePointer(name));
|
|
32
|
+
}
|
|
33
|
+
for (const key of lists) {
|
|
34
|
+
const subs = schema[key];
|
|
35
|
+
if (Array.isArray(subs))
|
|
36
|
+
subs.forEach((child, i) => {
|
|
37
|
+
const pointer = path + "/" + key + "/" + i;
|
|
38
|
+
index(child, pointer);
|
|
39
|
+
if (key === "oneOf" || key === "anyOf")
|
|
40
|
+
required.add(pointer);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
for (const key of children) {
|
|
44
|
+
if (!Object.hasOwn(schema, key))
|
|
45
|
+
continue;
|
|
46
|
+
const pointer = path + "/" + key;
|
|
47
|
+
index(schema[key], pointer);
|
|
48
|
+
if (["if", "contains", "unevaluatedItems", "unevaluatedProperties"].includes(key))
|
|
49
|
+
required.add(pointer);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
index(root, "");
|
|
53
|
+
for (const ref of references)
|
|
54
|
+
if (!schemas.has(ref))
|
|
55
|
+
throw new Error("Reference must identify a local schema.");
|
|
56
|
+
function valid(path, value) {
|
|
57
|
+
const schema = schemas.get(path);
|
|
58
|
+
if (typeof schema === "boolean")
|
|
59
|
+
return schema;
|
|
60
|
+
const check = validators.get(path);
|
|
61
|
+
if (!check)
|
|
62
|
+
throw new Error("Missing compiled schema condition.");
|
|
63
|
+
return !!check(value);
|
|
64
|
+
}
|
|
65
|
+
for (const [keyword, type] of [["unevaluatedItems", "array"], ["unevaluatedProperties", "object"]]) {
|
|
66
|
+
ajv.removeKeyword(keyword);
|
|
67
|
+
ajv.addKeyword({
|
|
68
|
+
keyword, type, schemaType: ["boolean", "object"], errors: false,
|
|
69
|
+
compile(_subschema, parent) {
|
|
70
|
+
const location = paths.get(parent);
|
|
71
|
+
if (location === undefined)
|
|
72
|
+
throw new Error("Unknown schema location.");
|
|
73
|
+
return (value) => {
|
|
74
|
+
const covered = new Set();
|
|
75
|
+
const visited = new Set();
|
|
76
|
+
const array = Array.isArray(value);
|
|
77
|
+
// Return true when a successful branch evaluated every location.
|
|
78
|
+
function collect(path, includeOwn) {
|
|
79
|
+
if (visited.has(path))
|
|
80
|
+
return false;
|
|
81
|
+
visited.add(path);
|
|
82
|
+
const schema = schemas.get(path);
|
|
83
|
+
if (schema === undefined)
|
|
84
|
+
throw new Error("Missing referenced schema.");
|
|
85
|
+
if (typeof schema === "boolean")
|
|
86
|
+
return false;
|
|
87
|
+
if (includeOwn && Object.hasOwn(schema, keyword))
|
|
88
|
+
return true;
|
|
89
|
+
if (array) {
|
|
90
|
+
if (Object.hasOwn(schema, "items"))
|
|
91
|
+
return true;
|
|
92
|
+
if (Array.isArray(schema.prefixItems))
|
|
93
|
+
for (let i = 0; i < Math.min(value.length, schema.prefixItems.length); i++)
|
|
94
|
+
covered.add(String(i));
|
|
95
|
+
if (Object.hasOwn(schema, "contains"))
|
|
96
|
+
for (const [i, item] of value.entries())
|
|
97
|
+
if (valid(path + "/contains", item))
|
|
98
|
+
covered.add(String(i));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (Object.hasOwn(schema, "additionalProperties"))
|
|
102
|
+
return true;
|
|
103
|
+
if (jsonObject(schema.properties))
|
|
104
|
+
for (const name of Object.keys(schema.properties))
|
|
105
|
+
covered.add(name);
|
|
106
|
+
if (jsonObject(schema.dependentSchemas))
|
|
107
|
+
for (const name of Object.keys(schema.dependentSchemas))
|
|
108
|
+
if (Object.hasOwn(value, name) && collect(path + "/dependentSchemas/" + escapePointer(name), true))
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if (typeof schema.$ref === "string" && collect(decodeURIComponent(schema.$ref.slice(1)), true))
|
|
112
|
+
return true;
|
|
113
|
+
for (const key of ["allOf", "anyOf", "oneOf"]) {
|
|
114
|
+
const subs = schema[key];
|
|
115
|
+
if (!Array.isArray(subs))
|
|
116
|
+
continue;
|
|
117
|
+
for (let i = 0; i < subs.length; i++) {
|
|
118
|
+
const branch = path + "/" + key + "/" + i;
|
|
119
|
+
if ((key === "allOf" || valid(branch, value)) && collect(branch, true))
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (Object.hasOwn(schema, "if")) {
|
|
124
|
+
const condition = valid(path + "/if", value);
|
|
125
|
+
if (condition && collect(path + "/if", true))
|
|
126
|
+
return true;
|
|
127
|
+
const branch = condition ? "then" : "else";
|
|
128
|
+
if (Object.hasOwn(schema, branch))
|
|
129
|
+
return collect(path + "/" + branch, true);
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
if (collect(location, false))
|
|
134
|
+
return true;
|
|
135
|
+
for (const [name, item] of Object.entries(value))
|
|
136
|
+
if (!covered.has(name) && !valid(location + "/" + keyword, item))
|
|
137
|
+
return false;
|
|
138
|
+
return true;
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
ajv.addSchema(root, id);
|
|
144
|
+
const result = ajv.getSchema(id);
|
|
145
|
+
if (!result)
|
|
146
|
+
throw new Error("Could not compile schema.");
|
|
147
|
+
for (const path of required) {
|
|
148
|
+
if (typeof schemas.get(path) === "boolean")
|
|
149
|
+
continue;
|
|
150
|
+
const check = ajv.getSchema(id + "#" + path.split("/").map(encodeURIComponent).join("/"));
|
|
151
|
+
if (!check)
|
|
152
|
+
throw new Error("Could not compile schema condition.");
|
|
153
|
+
validators.set(path, check);
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
package/dist/v2.js
CHANGED
|
@@ -327,6 +327,27 @@ export function createV2Adapter(options) {
|
|
|
327
327
|
frameBytes = 0;
|
|
328
328
|
controller.enqueue(await frame(bytes));
|
|
329
329
|
}
|
|
330
|
+
// A long incomplete event can contain thousands of tiny upstream fragments.
|
|
331
|
+
// Forward bounded blocks so a single flush cannot queue one task per fragment.
|
|
332
|
+
async function forwardBuffered(controller) {
|
|
333
|
+
let first = 0;
|
|
334
|
+
while (first < parts.length) {
|
|
335
|
+
let end = first + 1, size = parts[first].byteLength;
|
|
336
|
+
while (end < parts.length && size + parts[end].byteLength <= 64 * 1024) {
|
|
337
|
+
size += parts[end++].byteLength;
|
|
338
|
+
}
|
|
339
|
+
if (end === first + 1)
|
|
340
|
+
controller.enqueue(parts[first]);
|
|
341
|
+
else
|
|
342
|
+
controller.enqueue(Buffer.concat(parts.slice(first, end), size));
|
|
343
|
+
first = end;
|
|
344
|
+
const pause = workBudget();
|
|
345
|
+
if (pause)
|
|
346
|
+
await pause;
|
|
347
|
+
}
|
|
348
|
+
parts = [];
|
|
349
|
+
frameBytes = 0;
|
|
350
|
+
}
|
|
330
351
|
const stream = response.body.pipeThrough(new TransformStream({
|
|
331
352
|
async transform(chunk, controller) {
|
|
332
353
|
const yieldChunk = workBudget();
|
|
@@ -344,11 +365,8 @@ export function createV2Adapter(options) {
|
|
|
344
365
|
await yieldBlock;
|
|
345
366
|
}
|
|
346
367
|
if (frameBytes + i - start + 1 > maxResponseBytes) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
controller.enqueue(chunk.subarray(start));
|
|
350
|
-
parts = [];
|
|
351
|
-
frameBytes = 0;
|
|
368
|
+
await forwardBuffered(controller);
|
|
369
|
+
controller.enqueue(start ? chunk.subarray(start) : chunk);
|
|
352
370
|
bypass = true;
|
|
353
371
|
log("v2 oversized SSE stream left unobserved.");
|
|
354
372
|
return;
|
|
@@ -382,13 +400,12 @@ export function createV2Adapter(options) {
|
|
|
382
400
|
await emitFrame(controller);
|
|
383
401
|
}
|
|
384
402
|
if (start < chunk.byteLength) {
|
|
385
|
-
const part = chunk.subarray(start);
|
|
403
|
+
const part = start ? chunk.subarray(start) : chunk;
|
|
386
404
|
parts.push(part);
|
|
387
405
|
frameBytes += part.byteLength;
|
|
388
406
|
}
|
|
389
407
|
},
|
|
390
|
-
flush
|
|
391
|
-
controller.enqueue(part); parts = []; },
|
|
408
|
+
flush: forwardBuffered,
|
|
392
409
|
}));
|
|
393
410
|
return responseWith(response, stream);
|
|
394
411
|
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.
|
|
1
|
+
export declare const VERSION = "0.0.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.0.
|
|
1
|
+
export const VERSION = "0.0.2";
|
package/dist/workflow-json.js
CHANGED
|
@@ -4,7 +4,7 @@ import { stableHash } from "./drift.js";
|
|
|
4
4
|
export const JSON_LIMIT = 5 * 1024 * 1024;
|
|
5
5
|
export const jsonObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
6
6
|
export function copyJson(value, maxBytes = JSON_LIMIT) {
|
|
7
|
-
assertContractJson(value);
|
|
7
|
+
assertContractJson(value, undefined, undefined, maxBytes);
|
|
8
8
|
const encoded = JSON.stringify(value);
|
|
9
9
|
if (Buffer.byteLength(encoded) > maxBytes)
|
|
10
10
|
throw new Error("Workflow JSON exceeds its byte limit.");
|