@nyte-ai/plugin 0.0.0-stage → 0.0.18
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 +800 -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-6z2kgtyt.js +51 -0
- package/dist/chunks/billing-8rjk35gr.js +444 -0
- package/dist/chunks/billing-9mfedmsh.js +373 -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-j643d12p.js +197 -0
- package/dist/chunks/billing-k2p1t25n.js +109 -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-tzr3cebf.js +20 -0
- package/dist/chunks/billing-wmcbg6fw.js +52 -0
- package/dist/chunks/billing-wmkxkypm.js +527 -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 +1004 -0
- package/dist/src/acp/registry.d.ts +18 -0
- package/dist/src/acp/registry.js +8 -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 +368 -0
- package/dist/src/claude-code-sdk/session.d.ts +48 -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 +35 -0
- package/dist/src/client/notifications.js +26 -0
- package/dist/src/client/presentation.d.ts +336 -0
- package/dist/src/client/presentation.js +373 -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/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 +78 -0
- package/dist/src/rename.js +78 -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,109 @@
|
|
|
1
|
+
// src/acp/registry.ts
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { access, readFile, realpath } from "node:fs/promises";
|
|
4
|
+
import { basename, delimiter, dirname, join } from "node:path";
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
import { Value } from "typebox/value";
|
|
7
|
+
var launch = {
|
|
8
|
+
args: Type.Optional(Type.Array(Type.String())),
|
|
9
|
+
env: Type.Optional(Type.Record(Type.String(), Type.String()))
|
|
10
|
+
};
|
|
11
|
+
var registryAgent = Type.Object({
|
|
12
|
+
id: Type.String({ minLength: 1 }),
|
|
13
|
+
name: Type.String({ minLength: 1 }),
|
|
14
|
+
distribution: Type.Object({
|
|
15
|
+
binary: Type.Optional(Type.Record(Type.String(), Type.Object({ cmd: Type.String({ minLength: 1 }), ...launch }))),
|
|
16
|
+
npx: Type.Optional(Type.Object({ package: Type.String({ minLength: 1 }), ...launch }))
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
var registry = Type.Object({ agents: Type.Array(Type.Unknown()) });
|
|
20
|
+
var packageBin = Type.Object({
|
|
21
|
+
bin: Type.Union([Type.String(), Type.Record(Type.String(), Type.String())])
|
|
22
|
+
});
|
|
23
|
+
var PACKAGE = /^(@?[^@]+)@[^@]+$/;
|
|
24
|
+
function registryEntries2(document) {
|
|
25
|
+
return Value.Check(registry, document) ? document.agents : [];
|
|
26
|
+
}
|
|
27
|
+
function platformTarget() {
|
|
28
|
+
const os = process.platform === "win32" ? "windows" : process.platform;
|
|
29
|
+
const arch = process.arch === "arm64" ? "aarch64" : process.arch === "x64" ? "x86_64" : process.arch;
|
|
30
|
+
return `${os}-${arch}`;
|
|
31
|
+
}
|
|
32
|
+
async function executable(path) {
|
|
33
|
+
try {
|
|
34
|
+
await access(path, constants.X_OK);
|
|
35
|
+
return true;
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function findOnPath(name, path) {
|
|
41
|
+
const names = process.platform === "win32" ? [`${name}.exe`, `${name}.cmd`, name] : [name];
|
|
42
|
+
for (const dir of path.split(delimiter))
|
|
43
|
+
for (const candidate of names)
|
|
44
|
+
if (dir !== "" && await executable(join(dir, candidate)))
|
|
45
|
+
return join(dir, candidate);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
async function resolved(path) {
|
|
49
|
+
try {
|
|
50
|
+
return await realpath(path);
|
|
51
|
+
} catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function globalBin(spec, path) {
|
|
56
|
+
const name = PACKAGE.exec(spec)?.[1] ?? spec;
|
|
57
|
+
const npx = await findOnPath("npx", path);
|
|
58
|
+
if (npx === undefined)
|
|
59
|
+
return;
|
|
60
|
+
const bin = dirname(npx);
|
|
61
|
+
const windows = process.platform === "win32";
|
|
62
|
+
const modules = windows ? join(bin, "node_modules") : join(dirname(bin), "lib", "node_modules");
|
|
63
|
+
const root = join(modules, name);
|
|
64
|
+
let manifest;
|
|
65
|
+
try {
|
|
66
|
+
manifest = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
67
|
+
} catch {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!Value.Check(packageBin, manifest))
|
|
71
|
+
return;
|
|
72
|
+
const [command, target] = typeof manifest.bin === "string" ? [basename(name), manifest.bin] : Object.entries(manifest.bin).find(([key]) => key !== "") ?? [];
|
|
73
|
+
if (command === undefined || target === undefined)
|
|
74
|
+
return;
|
|
75
|
+
if (windows) {
|
|
76
|
+
const shim = join(bin, `${command}.cmd`);
|
|
77
|
+
const text = await readFile(shim, "utf8").catch(() => "");
|
|
78
|
+
return text.includes(`node_modules\\${name.replaceAll("/", "\\")}\\`) ? shim : undefined;
|
|
79
|
+
}
|
|
80
|
+
const linked = join(bin, command);
|
|
81
|
+
const [from, to] = await Promise.all([resolved(linked), resolved(join(root, target))]);
|
|
82
|
+
return from !== undefined && from === to && await executable(linked) ? linked : undefined;
|
|
83
|
+
}
|
|
84
|
+
async function installed(agent, path) {
|
|
85
|
+
const binary = agent.distribution.binary?.[platformTarget()];
|
|
86
|
+
if (binary !== undefined) {
|
|
87
|
+
const command = await findOnPath(basename(binary.cmd).replace(/\.exe$/, ""), path);
|
|
88
|
+
if (command !== undefined)
|
|
89
|
+
return {
|
|
90
|
+
id: agent.id,
|
|
91
|
+
name: agent.name,
|
|
92
|
+
command,
|
|
93
|
+
args: binary.args ?? [],
|
|
94
|
+
env: binary.env ?? {}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const npx = agent.distribution.npx;
|
|
98
|
+
if (npx === undefined)
|
|
99
|
+
return;
|
|
100
|
+
const command = await globalBin(npx.package, path);
|
|
101
|
+
return command === undefined ? undefined : { id: agent.id, name: agent.name, command, args: npx.args ?? [], env: npx.env ?? {} };
|
|
102
|
+
}
|
|
103
|
+
async function installedAgents2(entries, path) {
|
|
104
|
+
const agents = entries.filter((entry) => Value.Check(registryAgent, entry));
|
|
105
|
+
const found = await Promise.all(agents.map((agent) => installed(agent, path)));
|
|
106
|
+
return found.filter((agent) => agent !== undefined);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { registryEntries2, installedAgents2 };
|
|
@@ -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 };
|