@nyte-ai/plugin 0.0.0-stage → 0.0.19
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/LICENSE +21 -0
- package/THIRD-PARTY-NOTICES.md +866 -0
- package/dist/chunks/billing-0y7dfkp2.js +146 -0
- package/dist/chunks/billing-2v3g7rd9.js +190 -0
- package/dist/chunks/billing-3j77ss7y.js +86 -0
- package/dist/chunks/billing-3scqmkzb.js +559 -0
- package/dist/chunks/billing-4vz9pxyx.js +22 -0
- package/dist/chunks/billing-6z2kgtyt.js +51 -0
- package/dist/chunks/billing-8rjk35gr.js +444 -0
- package/dist/chunks/billing-9nn3yp18.js +176 -0
- package/dist/chunks/billing-9qc0eqh4.js +174 -0
- package/dist/chunks/billing-a9vqn66p.js +351 -0
- package/dist/chunks/billing-bv5zr32b.js +369 -0
- package/dist/chunks/billing-cy1rg619.js +302 -0
- package/dist/chunks/billing-ejx2hv52.js +323 -0
- package/dist/chunks/billing-h13r0byk.js +80 -0
- package/dist/chunks/billing-hg64tqf1.js +97 -0
- package/dist/chunks/billing-j643d12p.js +197 -0
- package/dist/chunks/billing-kn3d30b4.js +276 -0
- package/dist/chunks/billing-mvc33pv6.js +36 -0
- package/dist/chunks/billing-s4rrspsk.js +7 -0
- package/dist/chunks/billing-svrhh5a5.js +307 -0
- package/dist/chunks/billing-sxc70w72.js +161 -0
- package/dist/chunks/billing-t1qrxe16.js +41 -0
- package/dist/chunks/billing-tm34gm2p.js +528 -0
- package/dist/chunks/billing-tzr3cebf.js +20 -0
- package/dist/chunks/billing-v3hg5rc7.js +373 -0
- package/dist/chunks/billing-wmcbg6fw.js +52 -0
- package/dist/chunks/billing-ye3wk5r3.js +205 -0
- package/dist/chunks/billing-zfpm2rt0.js +29 -0
- package/dist/examples/claude-code/LICENSE +21 -0
- package/dist/examples/claude-code/billing.d.ts +7 -0
- package/dist/examples/claude-code/billing.js +11 -0
- package/dist/examples/claude-code/claude-cli.d.ts +35 -0
- package/dist/examples/claude-code/claude-cli.js +15 -0
- package/dist/examples/claude-code/env.d.ts +1 -0
- package/dist/examples/claude-code/env.js +6 -0
- package/dist/examples/claude-code/index.d.ts +24 -0
- package/dist/examples/claude-code/index.js +149 -0
- package/dist/examples/claude-code/inert-mcp.d.ts +1 -0
- package/dist/examples/claude-code/inert-mcp.js +6 -0
- package/dist/examples/claude-code/model-catalog.d.ts +27 -0
- package/dist/examples/claude-code/model-catalog.js +12 -0
- package/dist/examples/claude-code/process.d.ts +22 -0
- package/dist/examples/claude-code/process.js +25 -0
- package/dist/examples/claude-code/replay.d.ts +4 -0
- package/dist/examples/claude-code/replay.js +11 -0
- package/dist/examples/claude-code/stream.d.ts +3 -0
- package/dist/examples/claude-code/stream.js +16 -0
- package/dist/examples/claude-code/transcript.d.ts +83 -0
- package/dist/examples/claude-code/transcript.js +23 -0
- package/dist/examples/claude-code/turn-relay.d.ts +48 -0
- package/dist/examples/claude-code/turn-relay.js +9 -0
- package/dist/examples/claude-code/wire.d.ts +372 -0
- package/dist/examples/claude-code/wire.js +18 -0
- package/dist/src/acp/connection.d.ts +24 -0
- package/dist/src/acp/connection.js +8 -0
- package/dist/src/acp/index.d.ts +54 -0
- package/dist/src/acp/index.js +1005 -0
- package/dist/src/acp/registry.d.ts +18 -0
- package/dist/src/acp/registry.js +9 -0
- package/dist/src/acp/thread.d.ts +46 -0
- package/dist/src/acp/thread.js +7 -0
- package/dist/src/acp/transcript.d.ts +8 -0
- package/dist/src/acp/transcript.js +11 -0
- package/dist/src/acp/translate.d.ts +33 -0
- package/dist/src/acp/translate.js +20 -0
- package/dist/src/approvals/approvals.d.ts +189 -0
- package/dist/src/approvals/approvals.js +143 -0
- package/dist/src/approvals/schema.d.ts +169 -0
- package/dist/src/approvals/schema.js +18 -0
- package/dist/src/bash-description.d.ts +30 -0
- package/dist/src/bash-description.js +18 -0
- package/dist/src/browser-tools.d.ts +25 -0
- package/dist/src/browser-tools.js +246 -0
- package/dist/src/canvas/canvas-compile.d.ts +48 -0
- package/dist/src/canvas/canvas-compile.js +8 -0
- package/dist/src/canvas/canvas-libraries.d.ts +32 -0
- package/dist/src/canvas/canvas-libraries.js +6 -0
- package/dist/src/canvas/canvas-preview.d.ts +107 -0
- package/dist/src/canvas/canvas-preview.js +12 -0
- package/dist/src/canvas/canvas-protocol.d.ts +184 -0
- package/dist/src/canvas/canvas-protocol.js +75 -0
- package/dist/src/canvas/canvas.d.ts +50 -0
- package/dist/src/canvas/canvas.js +221 -0
- package/dist/src/canvas/schema.d.ts +47 -0
- package/dist/src/canvas/schema.js +8 -0
- package/dist/src/claude-code-sdk/index.d.ts +35 -0
- package/dist/src/claude-code-sdk/index.js +379 -0
- package/dist/src/claude-code-sdk/session.d.ts +50 -0
- package/dist/src/claude-code-sdk/session.js +7 -0
- package/dist/src/claude-code-sdk/transcript.d.ts +19 -0
- package/dist/src/claude-code-sdk/transcript.js +15 -0
- package/dist/src/claude-code-sdk/translate.d.ts +18 -0
- package/dist/src/claude-code-sdk/translate.js +20 -0
- package/dist/src/client/mount.d.ts +44 -0
- package/dist/src/client/mount.js +252 -0
- package/dist/src/client/notifications.d.ts +36 -0
- package/dist/src/client/notifications.js +24 -0
- package/dist/src/client/presentation.d.ts +362 -0
- package/dist/src/client/presentation.js +391 -0
- package/dist/src/client/transcript-tui.d.ts +23 -0
- package/dist/src/client/transcript-tui.js +20 -0
- package/dist/src/client/transcript.d.ts +23 -0
- package/dist/src/client/transcript.js +51 -0
- package/dist/src/client.d.ts +53 -0
- package/dist/src/client.js +22 -0
- package/dist/src/codemode-runtime.d.ts +11 -0
- package/dist/src/codemode-runtime.js +10 -0
- package/dist/src/codemode-worker.d.ts +1 -0
- package/dist/src/codemode-worker.js +2 -0
- package/dist/src/codemode.d.ts +21 -0
- package/dist/src/codemode.js +170 -0
- package/dist/src/core.d.ts +43 -0
- package/dist/src/core.js +11 -0
- package/dist/src/find-on-path.d.ts +4 -0
- package/dist/src/find-on-path.js +8 -0
- package/dist/src/openai-astra-context.d.ts +23 -0
- package/dist/src/openai-astra-context.js +14 -0
- package/dist/src/openai-compaction.d.ts +15 -0
- package/dist/src/openai-compaction.js +55 -0
- package/dist/src/question/client/questions-tui.d.ts +9 -0
- package/dist/src/question/client/questions-tui.js +19 -0
- package/dist/src/question/client/questions.d.ts +9 -0
- package/dist/src/question/client/questions.js +160 -0
- package/dist/src/question/question.d.ts +63 -0
- package/dist/src/question/question.js +9 -0
- package/dist/src/question/schema.d.ts +101 -0
- package/dist/src/question/schema.js +14 -0
- package/dist/src/rename.d.ts +79 -0
- package/dist/src/rename.js +91 -0
- package/dist/src/telemetry.d.ts +36 -0
- package/dist/src/telemetry.js +84 -0
- package/dist/src/web-search.d.ts +78 -0
- package/dist/src/web-search.js +219 -0
- package/package.json +190 -3
- package/README.md +0 -3
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CANVAS_GLOBAL2,
|
|
3
|
+
KIT_SPECIFIER2,
|
|
4
|
+
CANVAS_ENTRY2,
|
|
5
|
+
CANVAS_SOURCE_LIMIT2,
|
|
6
|
+
CANVAS_CODE_LIMIT2,
|
|
7
|
+
REACT_EXPORTS2,
|
|
8
|
+
JSX_RUNTIME_EXPORTS2,
|
|
9
|
+
REACT_DOM_EXPORTS2,
|
|
10
|
+
LIBRARY_EXPORTS2,
|
|
11
|
+
canvasFilesComment2,
|
|
12
|
+
KIT_EXPORTS2
|
|
13
|
+
} from "./billing-bv5zr32b.js";
|
|
14
|
+
|
|
15
|
+
// src/canvas/canvas-compile.ts
|
|
16
|
+
import { init, parse } from "es-module-lexer";
|
|
17
|
+
import { transform } from "sucrase";
|
|
18
|
+
var EXTERNAL = new Map([
|
|
19
|
+
["react", { value: `globalThis.${CANVAS_GLOBAL2}.react`, names: REACT_EXPORTS2 }],
|
|
20
|
+
[
|
|
21
|
+
"react/jsx-runtime",
|
|
22
|
+
{ value: `globalThis.${CANVAS_GLOBAL2}.jsxRuntime`, names: JSX_RUNTIME_EXPORTS2 }
|
|
23
|
+
],
|
|
24
|
+
["react-dom", { value: `globalThis.${CANVAS_GLOBAL2}.reactDom`, names: REACT_DOM_EXPORTS2 }],
|
|
25
|
+
[KIT_SPECIFIER2, { value: `globalThis.${CANVAS_GLOBAL2}.kit`, names: KIT_EXPORTS2 }],
|
|
26
|
+
...Object.entries(LIBRARY_EXPORTS2).map(([name, names]) => [
|
|
27
|
+
name,
|
|
28
|
+
{ value: `await globalThis.${CANVAS_GLOBAL2}.library(${JSON.stringify(name)})`, names }
|
|
29
|
+
])
|
|
30
|
+
]);
|
|
31
|
+
var RUNTIME_2 = new Set(["react-dom", ...Object.keys(LIBRARY_EXPORTS2)]);
|
|
32
|
+
var IMPORTABLE = [...EXTERNAL.keys()].filter((name) => name !== "react/jsx-runtime").map((name) => `"${name}"`).join(", ");
|
|
33
|
+
var FILE_NAME = /^(?:[\w-][\w.-]*\/)*[\w-][\w.-]*\.tsx?$/u;
|
|
34
|
+
var encoder = new TextEncoder;
|
|
35
|
+
var POSITION = /\((\d+):(\d+)\)\s*$/;
|
|
36
|
+
function at(file, line, column, text) {
|
|
37
|
+
return { file, line, column, text };
|
|
38
|
+
}
|
|
39
|
+
function locate(output, offset, prefix) {
|
|
40
|
+
const before = output.slice(0, offset);
|
|
41
|
+
const line = before.split(`
|
|
42
|
+
`).length;
|
|
43
|
+
const column = offset - (before.lastIndexOf(`
|
|
44
|
+
`) + 1) - (line === 1 ? Math.min(prefix, offset) : 0);
|
|
45
|
+
return { line, column };
|
|
46
|
+
}
|
|
47
|
+
function bindings(clause) {
|
|
48
|
+
const text = clause.trim();
|
|
49
|
+
if (text === "")
|
|
50
|
+
return [];
|
|
51
|
+
const match = /^(?:([A-Za-z_$][\w$]*)\s*(?:,\s*)?)?(?:\*\s*as\s+([A-Za-z_$][\w$]*)|\{([^}]*)\})?$/u.exec(text);
|
|
52
|
+
if (match === null)
|
|
53
|
+
return;
|
|
54
|
+
const [, defaultName, namespace, named] = match;
|
|
55
|
+
const found = [];
|
|
56
|
+
if (defaultName !== undefined)
|
|
57
|
+
found.push({ imported: "default", local: defaultName });
|
|
58
|
+
if (namespace !== undefined)
|
|
59
|
+
found.push({ imported: "*", local: namespace });
|
|
60
|
+
for (const entry of (named ?? "").split(",")) {
|
|
61
|
+
const piece = entry.trim();
|
|
62
|
+
if (piece === "")
|
|
63
|
+
continue;
|
|
64
|
+
const pair = /^([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/u.exec(piece);
|
|
65
|
+
if (pair === null)
|
|
66
|
+
return;
|
|
67
|
+
found.push({ imported: pair[1] ?? "", local: pair[2] ?? pair[1] ?? "" });
|
|
68
|
+
}
|
|
69
|
+
return found;
|
|
70
|
+
}
|
|
71
|
+
function resolveFile(importer, specifier, names) {
|
|
72
|
+
const segments = importer.split("/").slice(0, -1);
|
|
73
|
+
for (const segment of specifier.split("/")) {
|
|
74
|
+
if (segment === "" || segment === ".")
|
|
75
|
+
continue;
|
|
76
|
+
if (segment !== "..") {
|
|
77
|
+
segments.push(segment);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (segments.pop() === undefined)
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const path = segments.join("/");
|
|
84
|
+
const bare = path.replace(/\.jsx?$/u, "");
|
|
85
|
+
return [path, `${bare}.tsx`, `${bare}.ts`, `${path}/index.tsx`, `${path}/index.ts`].find((candidate) => names.has(candidate));
|
|
86
|
+
}
|
|
87
|
+
function checkFile(file, source, names, errors, externals) {
|
|
88
|
+
let output;
|
|
89
|
+
try {
|
|
90
|
+
output = transform(source, {
|
|
91
|
+
transforms: file.endsWith(".tsx") ? ["typescript", "jsx"] : ["typescript"],
|
|
92
|
+
jsxRuntime: "automatic",
|
|
93
|
+
production: true,
|
|
94
|
+
filePath: file
|
|
95
|
+
}).code;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
const message = error instanceof Error ? error.message.replace(`Error transforming ${file}: `, "") : String(error);
|
|
98
|
+
const position = POSITION.exec(message);
|
|
99
|
+
errors.push(at(file, position === null ? null : Number(position[1]), position === null ? null : Number(position[2]), message.replace(POSITION, "").trim()));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const [imports, exports] = parse(output, file);
|
|
103
|
+
const injected = imports[0];
|
|
104
|
+
const prefix = injected !== undefined && injected.ss === 0 && injected.n === "react/jsx-runtime" && !source.startsWith(output.slice(0, injected.se)) ? injected.se + (output[injected.se] === ";" ? 1 : 0) : 0;
|
|
105
|
+
const unit = {
|
|
106
|
+
file,
|
|
107
|
+
output,
|
|
108
|
+
exports: exports.map((entry) => entry.n),
|
|
109
|
+
edits: [],
|
|
110
|
+
wants: []
|
|
111
|
+
};
|
|
112
|
+
for (const entry of imports)
|
|
113
|
+
checkImport(unit, entry, prefix, names, errors, externals);
|
|
114
|
+
for (const found of findLinkerNames(output)) {
|
|
115
|
+
const { line, column } = locate(output, found.offset, prefix);
|
|
116
|
+
errors.push(at(file, line, column, `Rename \`${found.name}\`: the module linker owns that name in a canvas file.`));
|
|
117
|
+
}
|
|
118
|
+
return unit;
|
|
119
|
+
}
|
|
120
|
+
function findLinkerNames(code) {
|
|
121
|
+
const found = [];
|
|
122
|
+
const scan = /\/\/[^\n]*|\/\*[\s\S]*?\*\/|"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|`(?:\\.|[^`\\])*`|(?<!\.\s*)(?<![\w$])(exports|require)(?![\w$])(?!\s*:)/gu;
|
|
123
|
+
for (const match of code.matchAll(scan))
|
|
124
|
+
if (match[1] !== undefined)
|
|
125
|
+
found.push({ name: match[1], offset: match.index });
|
|
126
|
+
return found;
|
|
127
|
+
}
|
|
128
|
+
function checkImport(unit, entry, prefix, names, errors, externals) {
|
|
129
|
+
if (entry.d === -2)
|
|
130
|
+
return;
|
|
131
|
+
const { file, output } = unit;
|
|
132
|
+
const { line, column } = locate(output, entry.ss, prefix);
|
|
133
|
+
const statement = output.slice(entry.ss, entry.se);
|
|
134
|
+
const fail = (text) => {
|
|
135
|
+
errors.push(at(file, line, column, text));
|
|
136
|
+
};
|
|
137
|
+
if (statement.startsWith("export")) {
|
|
138
|
+
fail("A canvas cannot re-export from a module; import, then export your own names.");
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const specifier = entry.n;
|
|
142
|
+
if (specifier === undefined) {
|
|
143
|
+
fail(`A computed import() is not available; import ${IMPORTABLE} or a canvas file by a literal name.`);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const relative = specifier.startsWith("./") || specifier.startsWith("../");
|
|
147
|
+
const target = relative ? resolveFile(file, specifier, names) : undefined;
|
|
148
|
+
const external = relative ? undefined : EXTERNAL.get(specifier);
|
|
149
|
+
if (relative && target === undefined) {
|
|
150
|
+
fail(`"${specifier}" is not one of this canvas's files; pass it in \`files\`.`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (external === undefined && target === undefined) {
|
|
154
|
+
fail(`"${specifier}" is not available. A canvas can import ${IMPORTABLE} and its own files by relative path.`);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (external !== undefined)
|
|
158
|
+
externals.add(specifier);
|
|
159
|
+
if (target !== undefined) {
|
|
160
|
+
const quoted = output[entry.s] === '"' || output[entry.s] === "'";
|
|
161
|
+
unit.edits.push({
|
|
162
|
+
start: quoted ? entry.s + 1 : entry.s,
|
|
163
|
+
end: quoted ? entry.e - 1 : entry.e,
|
|
164
|
+
text: target
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (entry.d >= 0)
|
|
168
|
+
return;
|
|
169
|
+
const from = statement.lastIndexOf("from");
|
|
170
|
+
const bound = bindings(from === -1 ? "" : statement.slice("import".length, from));
|
|
171
|
+
if (bound === undefined) {
|
|
172
|
+
fail("This import could not be read; write it as `import X from`, `import * as X from` or `import { a, b as c } from`.");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const named = bound.filter((binding) => binding.imported !== "default" && binding.imported !== "*").map((binding) => binding.imported);
|
|
176
|
+
if (target !== undefined) {
|
|
177
|
+
unit.wants.push({
|
|
178
|
+
target,
|
|
179
|
+
specifier,
|
|
180
|
+
names: bound.some((binding) => binding.imported === "default") ? [...named, "default"] : named,
|
|
181
|
+
line,
|
|
182
|
+
column
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
for (const name of named)
|
|
187
|
+
if (!(external?.names ?? []).includes(name))
|
|
188
|
+
fail(`"${specifier}" has no export named "${name}".`);
|
|
189
|
+
}
|
|
190
|
+
function link(unit) {
|
|
191
|
+
let code = unit.output;
|
|
192
|
+
for (const edit of unit.edits.toSorted((left, right) => right.start - left.start))
|
|
193
|
+
code = `${code.slice(0, edit.start)}${edit.text}${code.slice(edit.end)}`;
|
|
194
|
+
return transform(code, { transforms: ["imports"], production: true, filePath: unit.file }).code;
|
|
195
|
+
}
|
|
196
|
+
async function compileCanvas2(source, files = {}, limits = {}) {
|
|
197
|
+
const sourceLimit = limits.source ?? CANVAS_SOURCE_LIMIT2;
|
|
198
|
+
const codeLimit = limits.code ?? CANVAS_CODE_LIMIT2;
|
|
199
|
+
const sources = [
|
|
200
|
+
[CANVAS_ENTRY2, source],
|
|
201
|
+
...Object.entries(files).map(([name, text]) => [name.replace(/^\.\//u, ""), text])
|
|
202
|
+
];
|
|
203
|
+
const bytes = sources.reduce((sum, [, text]) => sum + encoder.encode(text).byteLength, 0);
|
|
204
|
+
if (bytes > sourceLimit)
|
|
205
|
+
return failed([
|
|
206
|
+
at(null, null, null, `The source is over ${kb(sourceLimit)}; render less at once.`)
|
|
207
|
+
]);
|
|
208
|
+
const errors = [];
|
|
209
|
+
const names = new Set;
|
|
210
|
+
for (const [name = ""] of sources) {
|
|
211
|
+
if (names.has(name))
|
|
212
|
+
errors.push(at(name, null, null, name === CANVAS_ENTRY2 ? `\`files\` cannot hold ${CANVAS_ENTRY2}; that is \`source\`.` : "This file is named twice."));
|
|
213
|
+
else if (!FILE_NAME.test(name))
|
|
214
|
+
errors.push(at(name, null, null, "A canvas file is a path inside the canvas, such as `chart.tsx` or `lib/scale.ts`."));
|
|
215
|
+
names.add(name);
|
|
216
|
+
}
|
|
217
|
+
if (errors.length > 0)
|
|
218
|
+
return failed(errors);
|
|
219
|
+
await init;
|
|
220
|
+
const externals = new Set;
|
|
221
|
+
const units = sources.flatMap(([name = "", text = ""]) => {
|
|
222
|
+
const unit = checkFile(name, text, names, errors, externals);
|
|
223
|
+
return unit === undefined ? [] : [unit];
|
|
224
|
+
});
|
|
225
|
+
const exported = new Map(units.map((unit) => [unit.file, unit.exports]));
|
|
226
|
+
for (const unit of units)
|
|
227
|
+
for (const want of unit.wants)
|
|
228
|
+
for (const name of want.names)
|
|
229
|
+
if (exported.get(want.target)?.includes(name) === false)
|
|
230
|
+
errors.push(at(unit.file, want.line, want.column, name === "default" ? `"${want.specifier}" has no default export.` : `"${want.specifier}" has no export named "${name}".`));
|
|
231
|
+
if (exported.get(CANVAS_ENTRY2)?.includes("default") === false)
|
|
232
|
+
errors.push(at(CANVAS_ENTRY2, null, null, "The module must `export default` a component."));
|
|
233
|
+
if (errors.length > 0)
|
|
234
|
+
return failed(errors);
|
|
235
|
+
const code = bundle(units, externals);
|
|
236
|
+
if (encoder.encode(code).byteLength > codeLimit)
|
|
237
|
+
return failed([
|
|
238
|
+
at(null, null, null, `The compiled canvas is over ${kb(codeLimit)}; render less at once.`)
|
|
239
|
+
]);
|
|
240
|
+
return {
|
|
241
|
+
kind: "compiled",
|
|
242
|
+
code,
|
|
243
|
+
runtime: [...externals].some((name) => RUNTIME_2.has(name)) ? 2 : 1
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function bundle(units, imported) {
|
|
247
|
+
const externals = [...EXTERNAL].filter(([name]) => imported.has(name)).map(([name, external]) => `${JSON.stringify(name)}: ${external.value}`);
|
|
248
|
+
const spans = [];
|
|
249
|
+
const body = [];
|
|
250
|
+
let line = 2;
|
|
251
|
+
for (const unit of units) {
|
|
252
|
+
const code = link(unit);
|
|
253
|
+
const lines = code.split(`
|
|
254
|
+
`).length;
|
|
255
|
+
spans.push([unit.file, line + 1, lines]);
|
|
256
|
+
body.push(`${JSON.stringify(unit.file)}: function (exports, require) {`, code, "},");
|
|
257
|
+
line += lines + 2;
|
|
258
|
+
}
|
|
259
|
+
return [
|
|
260
|
+
`${canvasFilesComment2(spans)}const __external = { ${externals.join(", ")} }; const __files = {`,
|
|
261
|
+
...body,
|
|
262
|
+
"}; const __modules = new Map();",
|
|
263
|
+
"function __require(name) { if (Object.hasOwn(__external, name)) return __external[name]; let found = __modules.get(name); if (found === undefined) { found = {}; __modules.set(name, found); __files[name](found, __require); } return found; }",
|
|
264
|
+
`export default __require(${JSON.stringify(CANVAS_ENTRY2)}).default;`,
|
|
265
|
+
""
|
|
266
|
+
].join(`
|
|
267
|
+
`);
|
|
268
|
+
}
|
|
269
|
+
function kb(bytes) {
|
|
270
|
+
return `${Math.round(bytes / 1024)} KB`;
|
|
271
|
+
}
|
|
272
|
+
function failed(errors) {
|
|
273
|
+
return { kind: "failed", errors };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export { compileCanvas2 };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CANVAS_CODE_LIMIT2
|
|
3
|
+
} from "./billing-bv5zr32b.js";
|
|
4
|
+
|
|
5
|
+
// src/canvas/schema.ts
|
|
6
|
+
import { definePart } from "@nyte-ai/core";
|
|
7
|
+
import { standard } from "@nyte-ai/schema";
|
|
8
|
+
import { Type } from "typebox";
|
|
9
|
+
var state = standard(Type.Object({
|
|
10
|
+
runtime: Type.Integer({ minimum: 1 }),
|
|
11
|
+
title: Type.String({ minLength: 1, maxLength: 120 }),
|
|
12
|
+
code: Type.String({ maxLength: CANVAS_CODE_LIMIT2 }),
|
|
13
|
+
height: Type.Union([Type.Number(), Type.Null()]),
|
|
14
|
+
error: Type.Union([Type.String(), Type.Null()])
|
|
15
|
+
}));
|
|
16
|
+
var actions = {
|
|
17
|
+
replace: {
|
|
18
|
+
input: standard(Type.Object({
|
|
19
|
+
runtime: Type.Integer({ minimum: 1 }),
|
|
20
|
+
title: Type.String({ minLength: 1, maxLength: 120 }),
|
|
21
|
+
code: Type.String({ maxLength: CANVAS_CODE_LIMIT2 }),
|
|
22
|
+
height: Type.Union([Type.Number(), Type.Null()])
|
|
23
|
+
}))
|
|
24
|
+
},
|
|
25
|
+
report: {
|
|
26
|
+
input: standard(Type.Object({ message: Type.String({ minLength: 1, maxLength: 2000 }) }))
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var canvas2 = definePart({
|
|
30
|
+
kind: "canvas",
|
|
31
|
+
state,
|
|
32
|
+
actions,
|
|
33
|
+
fallback: (current, { id }) => `Canvas ${id}: ${current.title}.${current.error === null ? "" : ` It failed to render: ${current.error}. Fix it by calling canvas_render with canvas "${id}".`}`
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export { canvas2 };
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MIRROR_TOOL2,
|
|
3
|
+
emptyMessage2,
|
|
4
|
+
mirrorClass2,
|
|
5
|
+
toolText2,
|
|
6
|
+
Translator2
|
|
7
|
+
} from "./billing-9nn3yp18.js";
|
|
8
|
+
|
|
9
|
+
// src/acp/thread.ts
|
|
10
|
+
import { posix } from "node:path";
|
|
11
|
+
import { createAssistantMessageEventStream } from "@nyte-ai/ai";
|
|
12
|
+
import { Type } from "typebox";
|
|
13
|
+
import { Value } from "typebox/value";
|
|
14
|
+
class Inbox {
|
|
15
|
+
#items = [];
|
|
16
|
+
#waiter;
|
|
17
|
+
#ended = false;
|
|
18
|
+
push(item) {
|
|
19
|
+
this.#items.push(item);
|
|
20
|
+
this.#wake();
|
|
21
|
+
}
|
|
22
|
+
end() {
|
|
23
|
+
this.#ended = true;
|
|
24
|
+
this.#wake();
|
|
25
|
+
}
|
|
26
|
+
async next() {
|
|
27
|
+
while (this.#items.length === 0 && !this.#ended)
|
|
28
|
+
await new Promise((resolve) => this.#waiter = resolve);
|
|
29
|
+
return this.#items.shift();
|
|
30
|
+
}
|
|
31
|
+
#wake() {
|
|
32
|
+
const waiter = this.#waiter;
|
|
33
|
+
this.#waiter = undefined;
|
|
34
|
+
waiter?.();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
var input = Type.Record(Type.String(), Type.Unknown());
|
|
38
|
+
function answer(choice, options) {
|
|
39
|
+
const kinds = choice === "allow" ? ["allow_once"] : choice === "reject" ? ["reject_once", "reject_always"] : [];
|
|
40
|
+
const option = kinds.flatMap((kind) => options.filter((entry) => entry.kind === kind))[0];
|
|
41
|
+
return option === undefined ? { outcome: { outcome: "cancelled" } } : { outcome: { outcome: "selected", optionId: option.optionId } };
|
|
42
|
+
}
|
|
43
|
+
function guardedFirst(cwd, paths) {
|
|
44
|
+
const root = posix.resolve(cwd);
|
|
45
|
+
const inside = (path) => {
|
|
46
|
+
const target = posix.resolve(root, path);
|
|
47
|
+
return target === root || target.startsWith(`${root}/`);
|
|
48
|
+
};
|
|
49
|
+
return [...paths.filter((path) => !inside(path)), ...paths.filter(inside)];
|
|
50
|
+
}
|
|
51
|
+
function stopReason(response) {
|
|
52
|
+
switch (response.stopReason) {
|
|
53
|
+
case "max_tokens":
|
|
54
|
+
case "max_turn_requests":
|
|
55
|
+
return "length";
|
|
56
|
+
case "refusal":
|
|
57
|
+
return "error";
|
|
58
|
+
case "cancelled":
|
|
59
|
+
return "aborted";
|
|
60
|
+
default:
|
|
61
|
+
return "stop";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class AcpThread2 {
|
|
66
|
+
prefix;
|
|
67
|
+
#channel;
|
|
68
|
+
#events = new Inbox;
|
|
69
|
+
#tools = new Map;
|
|
70
|
+
#permissions = new Map;
|
|
71
|
+
#recordings = new Map;
|
|
72
|
+
#changes = new Set;
|
|
73
|
+
#queue = [];
|
|
74
|
+
#running = false;
|
|
75
|
+
#failure;
|
|
76
|
+
constructor(prefix, channel) {
|
|
77
|
+
this.prefix = prefix;
|
|
78
|
+
this.#channel = channel;
|
|
79
|
+
}
|
|
80
|
+
get closed() {
|
|
81
|
+
return this.#failure !== undefined;
|
|
82
|
+
}
|
|
83
|
+
send(blocks) {
|
|
84
|
+
if (this.#running)
|
|
85
|
+
this.#queue.push(blocks);
|
|
86
|
+
else
|
|
87
|
+
this.#start(blocks);
|
|
88
|
+
}
|
|
89
|
+
update(update) {
|
|
90
|
+
switch (update.sessionUpdate) {
|
|
91
|
+
case "agent_message_chunk":
|
|
92
|
+
if (update.content.type === "text")
|
|
93
|
+
this.#events.push({ kind: "text", text: update.content.text });
|
|
94
|
+
break;
|
|
95
|
+
case "agent_thought_chunk":
|
|
96
|
+
if (update.content.type === "text")
|
|
97
|
+
this.#events.push({ kind: "thinking", text: update.content.text });
|
|
98
|
+
break;
|
|
99
|
+
case "tool_call":
|
|
100
|
+
case "tool_call_update":
|
|
101
|
+
this.#see(update);
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
this.#changed();
|
|
107
|
+
}
|
|
108
|
+
async permission(request) {
|
|
109
|
+
const id = request.toolCall.toolCallId;
|
|
110
|
+
this.#see(request.toolCall);
|
|
111
|
+
if (this.#failure !== undefined)
|
|
112
|
+
return answer("cancelled", request.options);
|
|
113
|
+
const asking = new AbortController;
|
|
114
|
+
this.#permissions.set(id, asking);
|
|
115
|
+
this.#changed();
|
|
116
|
+
try {
|
|
117
|
+
const recorded = await Promise.race([
|
|
118
|
+
this.#recording(id).promise,
|
|
119
|
+
new Promise((resolve) => asking.signal.addEventListener("abort", () => resolve("cancelled"), { once: true }))
|
|
120
|
+
]);
|
|
121
|
+
if (recorded !== "recording")
|
|
122
|
+
return answer(recorded === "skipped" ? "reject" : "cancelled", request.options);
|
|
123
|
+
const args = this.#arguments(id);
|
|
124
|
+
const name = args.kind === "other" ? args.title : args.kind;
|
|
125
|
+
const verdict = await this.#channel.approve({ name, class: mirrorClass2(args) }, asking.signal);
|
|
126
|
+
if (asking.signal.aborted)
|
|
127
|
+
return answer("cancelled", request.options);
|
|
128
|
+
return answer(verdict.kind === "allow" ? "allow" : "reject", request.options);
|
|
129
|
+
} finally {
|
|
130
|
+
this.#permissions.delete(id);
|
|
131
|
+
this.#changed();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
recording(id) {
|
|
135
|
+
this.#recording(id).resolve("recording");
|
|
136
|
+
}
|
|
137
|
+
skip(id) {
|
|
138
|
+
if (this.#tools.has(id))
|
|
139
|
+
this.#recording(id).resolve("skipped");
|
|
140
|
+
}
|
|
141
|
+
respond(model, signal, tools = true) {
|
|
142
|
+
const stream = createAssistantMessageEventStream();
|
|
143
|
+
const output = emptyMessage2(model);
|
|
144
|
+
const translator = new Translator2(model, output, stream);
|
|
145
|
+
const abort = () => {
|
|
146
|
+
this.cancel();
|
|
147
|
+
this.#events.push({ kind: "aborted" });
|
|
148
|
+
};
|
|
149
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
150
|
+
(async () => {
|
|
151
|
+
try {
|
|
152
|
+
stream.push({ type: "start", partial: output });
|
|
153
|
+
let reason;
|
|
154
|
+
while (reason === undefined) {
|
|
155
|
+
const event = await this.#events.next();
|
|
156
|
+
if (event === undefined)
|
|
157
|
+
throw this.#failure ?? new Error("The agent stopped.");
|
|
158
|
+
if (event.kind === "aborted")
|
|
159
|
+
throw new Error("Request was aborted");
|
|
160
|
+
if (event.kind === "text")
|
|
161
|
+
translator.text(event.text);
|
|
162
|
+
else if (event.kind === "thinking")
|
|
163
|
+
translator.thinking(event.text);
|
|
164
|
+
else if (event.kind === "tool" && !tools)
|
|
165
|
+
this.skip(event.id);
|
|
166
|
+
else if (event.kind === "tool") {
|
|
167
|
+
translator.call(this.#mirror(event.id));
|
|
168
|
+
reason = "toolUse";
|
|
169
|
+
} else {
|
|
170
|
+
translator.end();
|
|
171
|
+
if (event.response.usage !== undefined && event.response.usage !== null)
|
|
172
|
+
translator.usage(event.response.usage);
|
|
173
|
+
output.rawStopReason = event.response.stopReason;
|
|
174
|
+
const mapped = stopReason(event.response);
|
|
175
|
+
if (mapped === "aborted")
|
|
176
|
+
throw new Error("Request was aborted");
|
|
177
|
+
if (mapped === "error")
|
|
178
|
+
throw new Error("The agent refused to complete the request.");
|
|
179
|
+
reason = mapped;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
output.stopReason = reason;
|
|
183
|
+
stream.push({ type: "done", reason, message: output });
|
|
184
|
+
} catch (error) {
|
|
185
|
+
output.stopReason = signal?.aborted === true ? "aborted" : "error";
|
|
186
|
+
output.errorMessage = error instanceof Error ? error.message : String(error);
|
|
187
|
+
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
188
|
+
} finally {
|
|
189
|
+
signal?.removeEventListener("abort", abort);
|
|
190
|
+
stream.end();
|
|
191
|
+
}
|
|
192
|
+
})();
|
|
193
|
+
return stream;
|
|
194
|
+
}
|
|
195
|
+
async result(id, signal) {
|
|
196
|
+
const settled = () => {
|
|
197
|
+
const status = this.#tools.get(id)?.status;
|
|
198
|
+
return status === "completed" || status === "failed" || !this.#running || [...this.#permissions.keys()].some((other) => other !== id);
|
|
199
|
+
};
|
|
200
|
+
while (!settled() && this.#failure === undefined) {
|
|
201
|
+
if (signal.aborted) {
|
|
202
|
+
this.cancel();
|
|
203
|
+
signal.throwIfAborted();
|
|
204
|
+
}
|
|
205
|
+
await new Promise((resolve) => {
|
|
206
|
+
const done = () => {
|
|
207
|
+
this.#changes.delete(done);
|
|
208
|
+
signal.removeEventListener("abort", done);
|
|
209
|
+
resolve();
|
|
210
|
+
};
|
|
211
|
+
this.#changes.add(done);
|
|
212
|
+
signal.addEventListener("abort", done, { once: true });
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const tool = this.#tools.get(id);
|
|
216
|
+
if (tool === undefined)
|
|
217
|
+
throw this.#failure ?? new Error("The agent did not report this call.");
|
|
218
|
+
return { text: toolText2(tool.content, tool.rawOutput), failed: tool.status === "failed" };
|
|
219
|
+
}
|
|
220
|
+
cancel() {
|
|
221
|
+
this.#queue.length = 0;
|
|
222
|
+
for (const asking of this.#permissions.values())
|
|
223
|
+
asking.abort();
|
|
224
|
+
if (this.#running)
|
|
225
|
+
this.#channel.cancel();
|
|
226
|
+
}
|
|
227
|
+
close(reason = new Error("The agent's session closed.")) {
|
|
228
|
+
if (this.#failure !== undefined)
|
|
229
|
+
return;
|
|
230
|
+
this.cancel();
|
|
231
|
+
this.#failure = reason;
|
|
232
|
+
this.#events.end();
|
|
233
|
+
this.#changed();
|
|
234
|
+
}
|
|
235
|
+
#start(blocks) {
|
|
236
|
+
this.#running = true;
|
|
237
|
+
this.#channel.prompt(blocks).then((response) => {
|
|
238
|
+
const next = response.stopReason === "cancelled" ? undefined : this.#queue.shift();
|
|
239
|
+
if (next !== undefined) {
|
|
240
|
+
this.#start(next);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
this.#running = false;
|
|
244
|
+
this.#events.push({ kind: "stop", response });
|
|
245
|
+
this.#changed();
|
|
246
|
+
}, (error) => {
|
|
247
|
+
this.#running = false;
|
|
248
|
+
this.close(error instanceof Error ? error : new Error(String(error)));
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
#see(update) {
|
|
252
|
+
const known = this.#tools.get(update.toolCallId);
|
|
253
|
+
const tool = known ?? {
|
|
254
|
+
title: "Tool",
|
|
255
|
+
kind: "other",
|
|
256
|
+
status: "pending",
|
|
257
|
+
input: {},
|
|
258
|
+
paths: [],
|
|
259
|
+
content: [],
|
|
260
|
+
rawOutput: undefined
|
|
261
|
+
};
|
|
262
|
+
tool.title = update.title ?? tool.title;
|
|
263
|
+
tool.kind = update.kind ?? tool.kind;
|
|
264
|
+
tool.status = update.status ?? tool.status;
|
|
265
|
+
tool.input = Value.Check(input, update.rawInput) ? update.rawInput : tool.input;
|
|
266
|
+
tool.paths = update.locations?.map((location) => location.path) ?? tool.paths;
|
|
267
|
+
tool.content = update.content ?? tool.content;
|
|
268
|
+
tool.rawOutput = update.rawOutput ?? tool.rawOutput;
|
|
269
|
+
if (known !== undefined)
|
|
270
|
+
return;
|
|
271
|
+
this.#tools.set(update.toolCallId, tool);
|
|
272
|
+
this.#events.push({ kind: "tool", id: update.toolCallId });
|
|
273
|
+
}
|
|
274
|
+
#arguments(id) {
|
|
275
|
+
const tool = this.#tools.get(id);
|
|
276
|
+
return {
|
|
277
|
+
thread: this.prefix,
|
|
278
|
+
id,
|
|
279
|
+
title: tool?.title ?? "Tool",
|
|
280
|
+
kind: tool?.kind ?? "other",
|
|
281
|
+
input: tool?.input ?? {},
|
|
282
|
+
paths: guardedFirst(this.#channel.cwd, tool?.paths ?? [])
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
#mirror(id) {
|
|
286
|
+
return {
|
|
287
|
+
type: "toolCall",
|
|
288
|
+
id: `${this.prefix}${id}`,
|
|
289
|
+
name: MIRROR_TOOL2,
|
|
290
|
+
arguments: this.#arguments(id)
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
#recording(id) {
|
|
294
|
+
const known = this.#recordings.get(id);
|
|
295
|
+
if (known !== undefined)
|
|
296
|
+
return known;
|
|
297
|
+
const created = Promise.withResolvers();
|
|
298
|
+
this.#recordings.set(id, created);
|
|
299
|
+
return created;
|
|
300
|
+
}
|
|
301
|
+
#changed() {
|
|
302
|
+
for (const change of this.#changes)
|
|
303
|
+
change();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export { AcpThread2 };
|