@toolpal/builder 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,85 @@
1
+ Toolpal License
2
+
3
+ Copyright (c) 2026 the Toolpal authors. All rights reserved.
4
+
5
+ This license covers the Toolpal client packages: toolpal, @toolpal/sdk,
6
+ @toolpal/tool, @toolpal/runtime, @toolpal/sandbox, @toolpal/manifest,
7
+ @toolpal/analyzer and @toolpal/builder (together, the "Software"). It does not
8
+ cover any other Toolpal software or service, such as the Toolpal registry or
9
+ website. The Toolpal authors are the "licensor"; "you" means the person or
10
+ organization using the Software.
11
+
12
+ 1. Use
13
+
14
+ The licensor grants you a free, worldwide, non-exclusive, non-transferable
15
+ license to install, run and use the Software for any purpose, including
16
+ commercial purposes, subject to the terms below.
17
+
18
+ 2. Tools you build
19
+
20
+ You may include @toolpal/tool, and any other code the Software adds to a
21
+ tool when it builds one, in tools you create. You may publish and
22
+ distribute those tools, through the Toolpal registry or otherwise, under
23
+ terms you choose for your own code. The parts of a tool that come from the
24
+ Software remain under this license.
25
+
26
+ 3. Copies
27
+
28
+ You may make the copies of the Software you need to use it, including in
29
+ your own applications, container images, caches and deployments, as long
30
+ as each copy keeps this license and is unmodified apart from automated
31
+ bundling, compilation or minification.
32
+
33
+ 4. Restrictions
34
+
35
+ You may not:
36
+
37
+ a. modify the Software or make derivative works of it, except as
38
+ sections 2 and 3 allow;
39
+ b. sell, rent, lease or sublicense the Software, or distribute it on its
40
+ own, except as sections 2 and 3 allow;
41
+ c. use the Software to offer a product or service that competes with
42
+ Toolpal, such as a tool registry or marketplace, without the
43
+ licensor's written permission;
44
+ d. remove or change any copyright, license or other notice in the
45
+ Software.
46
+
47
+ 5. Third-party software
48
+
49
+ The Software uses open-source components that are licensed to you under
50
+ their own licenses. Nothing in this license limits your rights under
51
+ those licenses.
52
+
53
+ 6. Ownership
54
+
55
+ The licensor keeps all rights in the Software that this license does not
56
+ expressly grant you. This license grants no rights to the Toolpal name or
57
+ logo.
58
+
59
+ 7. Termination
60
+
61
+ This license ends automatically if you break any of its terms. You must
62
+ then stop using the Software and delete your copies of it. Tools you
63
+ distributed before then stay licensed under section 2 for the people who
64
+ received them.
65
+
66
+ 8. No warranty
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
69
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
70
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
71
+
72
+ 9. Limitation of liability
73
+
74
+ IN NO EVENT SHALL THE LICENSOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
75
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
76
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
77
+ DEALINGS IN THE SOFTWARE. THIS INCLUDES HARM CAUSED BY TOOLS YOU RUN WITH
78
+ THE SOFTWARE: ITS ISOLATION REDUCES RISK BUT IS NOT A GUARANTEE (SEE THE
79
+ SECURITY MODEL IN THE TOOLPAL DOCUMENTATION).
80
+
81
+ 10. Future versions
82
+
83
+ The licensor may release future versions of the Software under different
84
+ terms. Each version of the Software is governed by the license included
85
+ with it.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @toolpal/builder
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Bundles, analyzes, captures verified sandbox examples, and packs [Toolpal](https://toolpal.dev) workflows for publishing.
4
+
5
+ Most users should install the [`toolpal`](https://www.npmjs.com/package/toolpal) CLI/SDK instead.
@@ -0,0 +1,43 @@
1
+ import { type AnalysisReport, type ToolManifest } from "@toolpal/manifest";
2
+ import { Supervisor } from "@toolpal/sandbox";
3
+ import * as esbuild from "esbuild";
4
+ export declare const BUILDER_VERSION = "0.1.1";
5
+ /**
6
+ * Prepended to every bundle so CommonJS dependencies can `require()` Node
7
+ * built-ins from ESM. The analyzer recognises this exact createRequire import.
8
+ */
9
+ export declare const BANNER = "import { createRequire as __toolpalCreateRequire } from \"node:module\";\nconst require = __toolpalCreateRequire(import.meta.url);";
10
+ export interface BuildOptions {
11
+ projectDir: string;
12
+ /** Extra package.json export conditions (the monorepo uses "toolpal-source"). */
13
+ conditions?: string[] | undefined;
14
+ /** Reuse a supervisor (tests, long-running CLIs); a temporary one is created otherwise. */
15
+ supervisor?: Supervisor | undefined;
16
+ /**
17
+ * For source that is not trusted (written by a model): the project's own files
18
+ * may import only these packages and Node's built-in modules, never another
19
+ * file. Without it an import can pull any readable file on this machine into
20
+ * the bundle.
21
+ */
22
+ onlyPackages?: string[] | undefined;
23
+ /** Env vars passed when executing `defineTool({ examples })` (only declared vars are passed). */
24
+ exampleEnv?: Record<string, string | undefined> | undefined;
25
+ /** Set false to skip executing declared examples during build (keeps declared inputs only). */
26
+ runExamples?: boolean | undefined;
27
+ }
28
+ export interface BuildResult {
29
+ manifest: ToolManifest;
30
+ report: AnalysisReport;
31
+ flags: string[];
32
+ bundle: Buffer;
33
+ entryIntegrity: string;
34
+ bundlePath: string;
35
+ manifestPath: string;
36
+ }
37
+ /** The esbuild options that determine output bytes; hashed into `manifest.build.options`. */
38
+ export declare function bundleOptions(entry: string, conditions?: string[]): esbuild.BuildOptions;
39
+ export declare function bundleOptionsHash(options: esbuild.BuildOptions): string;
40
+ /** Runs esbuild and returns the single output bundle (not written to disk). */
41
+ export declare function bundle(projectDir: string, entry: string, conditions?: string[], onlyPackages?: string[]): Promise<Buffer>;
42
+ export declare function buildTool(opts: BuildOptions): Promise<BuildResult>;
43
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,cAAc,EAcnB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AY,CAAC,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,MAAM,CAAC,CA0BjB;AAmBD,wBAAsB,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAoHxE"}
package/dist/build.js ADDED
@@ -0,0 +1,218 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
3
+ import { isBuiltin } from "node:module";
4
+ import { join, resolve, sep } from "node:path";
5
+ import { analyzeBundle } from "@toolpal/analyzer";
6
+ import { canonicalJson, checkDeclared, computeFlags, ENTRY_PATH, fileFields, integrityOf, lintManifest, MANIFEST_VERSION, MAX_BUNDLE_BYTES, MIN_NODE_VERSION, mergePermissions, parseManifest, permissionsFromReport, UNPUBLISHED_VERSION, } from "@toolpal/manifest";
7
+ import { Supervisor } from "@toolpal/sandbox";
8
+ import * as esbuild from "esbuild";
9
+ import { BuildError } from "./errors.js";
10
+ import { captureExamples } from "./examples.js";
11
+ import { readProjectPackage } from "./project.js";
12
+ export const BUILDER_VERSION = "0.1.1";
13
+ /**
14
+ * Prepended to every bundle so CommonJS dependencies can `require()` Node
15
+ * built-ins from ESM. The analyzer recognises this exact createRequire import.
16
+ */
17
+ export const BANNER = 'import { createRequire as __toolpalCreateRequire } from "node:module";\nconst require = __toolpalCreateRequire(import.meta.url);';
18
+ /** The esbuild options that determine output bytes; hashed into `manifest.build.options`. */
19
+ export function bundleOptions(entry, conditions = []) {
20
+ return {
21
+ entryPoints: [entry],
22
+ outfile: ENTRY_PATH,
23
+ bundle: true,
24
+ platform: "node",
25
+ format: "esm",
26
+ target: "node22",
27
+ mainFields: ["module", "main"],
28
+ minify: false,
29
+ sourcemap: false,
30
+ legalComments: "inline",
31
+ charset: "utf8",
32
+ banner: { js: BANNER },
33
+ define: { "process.env.NODE_ENV": '"production"' },
34
+ conditions: ["module", ...conditions],
35
+ write: false,
36
+ logLevel: "silent",
37
+ };
38
+ }
39
+ export function bundleOptionsHash(options) {
40
+ return integrityOf(canonicalJson(options), "sha256");
41
+ }
42
+ /** Refuses every import from the project's own files except `allowed` packages and built-ins. */
43
+ function onlyPackagesPlugin(projectDir, allowed) {
44
+ const own = resolve(projectDir) + sep;
45
+ const packages = join(own, "node_modules") + sep;
46
+ return {
47
+ name: "toolpal-only-packages",
48
+ setup(build) {
49
+ build.onResolve({ filter: /.*/ }, (args) => {
50
+ if (args.kind === "entry-point")
51
+ return undefined;
52
+ const importer = resolve(args.importer);
53
+ if (!importer.startsWith(own) || importer.startsWith(packages))
54
+ return undefined;
55
+ if (isBuiltin(args.path))
56
+ return undefined;
57
+ const [first = "", second = ""] = args.path.split("/");
58
+ if (allowed.includes(first.startsWith("@") ? `${first}/${second}` : first)) {
59
+ return undefined;
60
+ }
61
+ const from = allowed.map((name) => `"${name}"`).join(", ");
62
+ return {
63
+ errors: [
64
+ {
65
+ text: `cannot import "${args.path}": a tool built this way is a single file that imports only from ${from} and Node's built-in modules. Use the Toolpal CLI for a tool that needs npm packages or more files.`,
66
+ },
67
+ ],
68
+ };
69
+ });
70
+ },
71
+ };
72
+ }
73
+ /** Runs esbuild and returns the single output bundle (not written to disk). */
74
+ export async function bundle(projectDir, entry, conditions, onlyPackages) {
75
+ const options = bundleOptions(entry, conditions);
76
+ let result;
77
+ try {
78
+ result = await esbuild.build({
79
+ ...options,
80
+ absWorkingDir: projectDir,
81
+ // A tsconfig.json in some parent directory must not shape such a build either.
82
+ ...(onlyPackages
83
+ ? { plugins: [onlyPackagesPlugin(projectDir, onlyPackages)], tsconfigRaw: "{}" }
84
+ : {}),
85
+ });
86
+ }
87
+ catch (err) {
88
+ const failure = err;
89
+ const details = (failure.errors ?? []).map((e) => `${e.location ? `${e.location.file}:${e.location.line}: ` : ""}${e.text}`);
90
+ throw new BuildError("bundling failed", details.length > 0 ? details : [String(err)]);
91
+ }
92
+ const out = result.outputFiles?.[0];
93
+ if (!out)
94
+ throw new BuildError("esbuild produced no output");
95
+ const bytes = Buffer.from(out.contents);
96
+ if (bytes.length > MAX_BUNDLE_BYTES) {
97
+ throw new BuildError(`bundle is ${bytes.length} bytes; the limit is ${MAX_BUNDLE_BYTES}`);
98
+ }
99
+ return bytes;
100
+ }
101
+ /**
102
+ * `toolpal build`: bundle → analyze (permissions) → describe in a no-permission
103
+ * sandbox (schemas) → manifest → lint. Writes dist/tool.mjs and dist/manifest.json.
104
+ */
105
+ /**
106
+ * Builds are deterministic, so an unchanged output is left alone and a changed
107
+ * one is replaced atomically. Either way a concurrent reader (a running tool, a
108
+ * parallel build of the same project) never sees a half-written file.
109
+ */
110
+ async function writeIfChanged(path, data) {
111
+ const current = await readFile(path).catch(() => null);
112
+ if (current?.equals(data))
113
+ return;
114
+ const tmp = `${path}.${randomBytes(6).toString("hex")}.tmp`;
115
+ await writeFile(tmp, data);
116
+ await rename(tmp, path);
117
+ }
118
+ export async function buildTool(opts) {
119
+ const { projectDir } = opts;
120
+ const pkg = await readProjectPackage(projectDir);
121
+ const options = bundleOptions(pkg.toolpal.entry, opts.conditions);
122
+ const code = await bundle(projectDir, pkg.toolpal.entry, opts.conditions, opts.onlyPackages);
123
+ const report = analyzeBundle(code.toString("utf8"));
124
+ const bundlePath = join(projectDir, ENTRY_PATH);
125
+ await mkdir(join(projectDir, "dist"), { recursive: true });
126
+ await writeIfChanged(bundlePath, code);
127
+ const entryIntegrity = integrityOf(code, "sha256");
128
+ const supervisor = opts.supervisor ?? new Supervisor();
129
+ let described;
130
+ let capturedExamples;
131
+ let permissions;
132
+ try {
133
+ try {
134
+ described = await supervisor.describe({
135
+ toolDir: projectDir,
136
+ entryPath: bundlePath,
137
+ entryIntegrity,
138
+ memoryMb: pkg.toolpal.limits.memoryMb,
139
+ });
140
+ }
141
+ catch (err) {
142
+ throw new BuildError("the bundle failed to load in the sandbox (top-level code runs with no permissions)", [err.message]);
143
+ }
144
+ // Files are handed over inside the tool's private temp dir, so a tool with a file field has one.
145
+ const usesFiles = fileFields(described.inputSchema).length + fileFields(described.outputSchema).length > 0;
146
+ permissions = mergePermissions(mergePermissions(permissionsFromReport(report), pkg.toolpal.permissions), { tmp: usesFiles });
147
+ if (described.examples?.length) {
148
+ capturedExamples = await captureExamples({
149
+ projectDir,
150
+ entryPath: bundlePath,
151
+ entryIntegrity,
152
+ inputSchema: described.inputSchema,
153
+ outputSchema: described.outputSchema,
154
+ permissions,
155
+ limits: pkg.toolpal.limits,
156
+ examples: described.examples,
157
+ supervisor,
158
+ env: opts.exampleEnv,
159
+ run: opts.runExamples,
160
+ untrustedSource: Boolean(opts.onlyPackages),
161
+ });
162
+ }
163
+ }
164
+ finally {
165
+ if (!opts.supervisor)
166
+ await supervisor.close();
167
+ }
168
+ let manifest;
169
+ try {
170
+ manifest = parseManifest({
171
+ manifestVersion: MANIFEST_VERSION,
172
+ name: pkg.name,
173
+ // A build has no version of its own; `packTool` stamps the one the registry assigns.
174
+ version: UNPUBLISHED_VERSION,
175
+ description: described.description,
176
+ license: pkg.license,
177
+ repository: pkg.repository,
178
+ keywords: pkg.keywords,
179
+ entry: ENTRY_PATH,
180
+ sdk: described.sdkVersion ?? "unknown",
181
+ engines: { node: `>=${MIN_NODE_VERSION}` },
182
+ inputSchema: described.inputSchema,
183
+ outputSchema: described.outputSchema,
184
+ ...(capturedExamples?.length ? { examples: capturedExamples } : {}),
185
+ permissions,
186
+ limits: pkg.toolpal.limits,
187
+ build: {
188
+ toolpal: BUILDER_VERSION,
189
+ esbuild: esbuild.version,
190
+ options: bundleOptionsHash(options),
191
+ },
192
+ });
193
+ }
194
+ catch (err) {
195
+ throw new BuildError("generated manifest is invalid", [err.message]);
196
+ }
197
+ const lint = lintManifest(manifest);
198
+ if (lint.length > 0) {
199
+ throw new BuildError("tool description or schemas failed lint", lint.map((i) => `${i.path}: ${i.message}`));
200
+ }
201
+ // Auto-filled permissions always cover what was detected; this guards the merge itself.
202
+ const violations = checkDeclared(report, manifest.permissions);
203
+ if (violations.length > 0) {
204
+ throw new BuildError("permissions do not cover detected usage", violations.map((v) => v.message));
205
+ }
206
+ const manifestPath = join(projectDir, "dist", "manifest.json");
207
+ await writeIfChanged(manifestPath, Buffer.from(`${JSON.stringify(manifest, null, 2)}\n`));
208
+ return {
209
+ manifest,
210
+ report,
211
+ flags: computeFlags(report, manifest.permissions),
212
+ bundle: code,
213
+ entryIntegrity,
214
+ bundlePath,
215
+ manifestPath,
216
+ };
217
+ }
218
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAEL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EAErB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GACjB,kIAAkI,CAAC;AA+Br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AC,EAAE,CAAC;QACpB,MAAM,IAAI,UAAU,CAClB,yCAAyC,EACzC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAC3C,CAAC;IACJ,CAAC;IACD,wFAAwF;IACxF,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC/D,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,UAAU,CAClB,yCAAyC,EACzC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CACjC,CAAC;IACJ,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;IAC/D,MAAM,cAAc,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1F,OAAO;QACL,QAAQ;QACR,MAAM;QACN,KAAK,EAAE,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC;QACjD,MAAM,EAAE,IAAI;QACZ,cAAc;QACd,UAAU;QACV,YAAY;KACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare class BuildError extends Error {
2
+ readonly details: string[];
3
+ constructor(message: string, details?: string[]);
4
+ }
5
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,EAAO,EAIlD;CACF"}
package/dist/errors.js ADDED
@@ -0,0 +1,9 @@
1
+ export class BuildError extends Error {
2
+ details;
3
+ constructor(message, details = []) {
4
+ super(details.length > 0 ? `${message}\n ${details.join("\n ")}` : message);
5
+ this.name = "BuildError";
6
+ this.details = details;
7
+ }
8
+ }
9
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC1B,OAAO,CAAW;IAC3B,YAAY,OAAe,EAAE,OAAO,GAAa,EAAE;QACjD,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import { type Limits, type ManifestExample, type Permissions } from "@toolpal/manifest";
2
+ import type { Supervisor, ToolExampleInput } from "@toolpal/sandbox";
3
+ export interface CaptureExamplesOptions {
4
+ projectDir: string;
5
+ entryPath: string;
6
+ entryIntegrity: string;
7
+ inputSchema: Record<string, unknown>;
8
+ outputSchema: Record<string, unknown>;
9
+ permissions: Permissions;
10
+ limits: Limits;
11
+ examples: readonly ToolExampleInput[];
12
+ supervisor: Supervisor;
13
+ /** Env vars supplied by the author for capturing examples (filtered to declared permissions.env). */
14
+ env?: Record<string, string | undefined> | undefined;
15
+ /** When false, skip running examples and keep declared inputs only. */
16
+ run?: boolean | undefined;
17
+ /** Untrusted source builds only execute pure offline examples (no net, no env, no input files). */
18
+ untrustedSource?: boolean | undefined;
19
+ }
20
+ /**
21
+ * Executes each declared `defineTool({ examples })` input inside the sandbox
22
+ * and captures its real output (plus clean metadata for returned `FilePath()`
23
+ * files) into `manifest.examples`.
24
+ */
25
+ export declare function captureExamples(opts: CaptureExamplesOptions): Promise<ManifestExample[]>;
26
+ //# sourceMappingURL=examples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examples.d.ts","sourceRoot":"","sources":["../src/examples.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,MAAM,EAKX,KAAK,eAAe,EACpB,KAAK,WAAW,EAEjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAsB,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAkFzF,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACtC,UAAU,EAAE,UAAU,CAAC;IACvB,qGAAqG;IACrG,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IACrD,uEAAuE;IACvE,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,mGAAmG;IACnG,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACvC;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CA4K9F"}
@@ -0,0 +1,220 @@
1
+ import { copyFile, lstat, mkdir, realpath, stat } from "node:fs/promises";
2
+ import { basename, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
+ import { canonicalJson, fileFields, MAX_EXAMPLE_BYTES, MAX_EXAMPLES, MAX_FILE_BYTES, MAX_FILES_PER_CALL, sha256Hex, } from "@toolpal/manifest";
4
+ import { BuildError } from "./errors.js";
5
+ const MEDIA_TYPES = {
6
+ ".png": "image/png",
7
+ ".jpg": "image/jpeg",
8
+ ".jpeg": "image/jpeg",
9
+ ".webp": "image/webp",
10
+ ".gif": "image/gif",
11
+ ".svg": "image/svg+xml",
12
+ ".pdf": "application/pdf",
13
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
14
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
15
+ ".csv": "text/csv",
16
+ ".tsv": "text/tab-separated-values",
17
+ ".txt": "text/plain",
18
+ ".md": "text/markdown",
19
+ ".json": "application/json",
20
+ ".ics": "text/calendar",
21
+ ".srt": "application/x-subrip",
22
+ ".vtt": "text/vtt",
23
+ ".zip": "application/zip",
24
+ };
25
+ function isInside(path, dir) {
26
+ const rel = relative(dir, path);
27
+ return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
28
+ }
29
+ function mediaTypeOf(filename) {
30
+ return MEDIA_TYPES[extname(filename).toLowerCase()];
31
+ }
32
+ async function resolveExampleInputFile(projectDir, field, given, exampleIdx) {
33
+ const projectReal = await realpath(projectDir);
34
+ const named = resolve(projectDir, given);
35
+ const real = await realpath(named).catch(() => undefined);
36
+ if (real === undefined || !isInside(real, projectReal)) {
37
+ throw new BuildError(`examples[${exampleIdx}].input.${field} must reference a file inside the tool project directory (${given})`);
38
+ }
39
+ const info = await stat(real).catch(() => undefined);
40
+ if (!info?.isFile()) {
41
+ throw new BuildError(`examples[${exampleIdx}].input.${field} is not a regular file (${given})`);
42
+ }
43
+ if (info.size > MAX_FILE_BYTES) {
44
+ throw new BuildError(`examples[${exampleIdx}].input.${field} exceeds the file size limit (${info.size} bytes)`);
45
+ }
46
+ return { source: real, name: basename(named) };
47
+ }
48
+ async function collectExampleOutputFile(field, returned, outputDir, exampleIdx) {
49
+ const named = resolve(outputDir, returned);
50
+ const info = await lstat(named).catch(() => undefined);
51
+ const real = info?.isFile() ? await realpath(named).catch(() => undefined) : undefined;
52
+ if (real === undefined || !isInside(real, outputDir)) {
53
+ throw new BuildError(`examples[${exampleIdx}] returned an invalid output file path for "${field}" (must be a file written inside ctx.outputDir)`);
54
+ }
55
+ const name = basename(real);
56
+ const mediaType = mediaTypeOf(name);
57
+ return {
58
+ name,
59
+ size: info?.size ?? 0,
60
+ ...(mediaType ? { mediaType } : {}),
61
+ };
62
+ }
63
+ /**
64
+ * Executes each declared `defineTool({ examples })` input inside the sandbox
65
+ * and captures its real output (plus clean metadata for returned `FilePath()`
66
+ * files) into `manifest.examples`.
67
+ */
68
+ export async function captureExamples(opts) {
69
+ if (opts.examples.length === 0)
70
+ return [];
71
+ if (opts.examples.length > MAX_EXAMPLES) {
72
+ throw new BuildError(`at most ${MAX_EXAMPLES} examples are allowed; found ${opts.examples.length}`);
73
+ }
74
+ const inFiles = fileFields(opts.inputSchema);
75
+ const outFiles = fileFields(opts.outputSchema);
76
+ const needsFiles = inFiles.length + outFiles.length > 0;
77
+ // Filter author-supplied env vars to only what the tool declares.
78
+ const childEnv = {};
79
+ for (const key of opts.permissions.env) {
80
+ const val = opts.env?.[key];
81
+ if (typeof val === "string")
82
+ childEnv[key] = val;
83
+ }
84
+ // Untrusted source builds (`publish_tool`) may only run examples that require
85
+ // no network, no env vars, and no input files from disk.
86
+ const canRunUntrusted = !opts.permissions.net && opts.permissions.env.length === 0 && inFiles.length === 0;
87
+ const shouldRun = opts.run !== false && (!opts.untrustedSource || canRunUntrusted);
88
+ if (!shouldRun) {
89
+ return opts.examples.map((ex) => ({
90
+ ...(ex.title ? { title: ex.title } : {}),
91
+ ...(ex.prompt ? { prompt: ex.prompt } : {}),
92
+ input: ex.input,
93
+ }));
94
+ }
95
+ const spec = {
96
+ key: `example|${opts.entryIntegrity}|${canonicalJson(opts.permissions)}|${opts.limits.memoryMb}|${sha256Hex(canonicalJson(childEnv))}`,
97
+ toolDir: opts.projectDir,
98
+ entryPath: opts.entryPath,
99
+ entryIntegrity: opts.entryIntegrity,
100
+ permissions: opts.permissions,
101
+ memoryMb: opts.limits.memoryMb,
102
+ env: childEnv,
103
+ };
104
+ const timeoutMs = opts.untrustedSource
105
+ ? Math.min(opts.limits.timeoutMs, 10_000)
106
+ : opts.limits.timeoutMs;
107
+ const captured = [];
108
+ for (const [idx, ex] of opts.examples.entries()) {
109
+ const rawInput = ex.input;
110
+ const displayInput = { ...rawInput };
111
+ const stagedFiles = [];
112
+ if (inFiles.length > 0) {
113
+ let count = 0;
114
+ for (const field of inFiles) {
115
+ const value = rawInput[field.name];
116
+ if (value === undefined)
117
+ continue;
118
+ const paths = field.many ? value : [value];
119
+ if (!Array.isArray(paths) || paths.some((p) => typeof p !== "string")) {
120
+ throw new BuildError(`examples[${idx}].input.${field.name} must be a file path string`);
121
+ }
122
+ count += paths.length;
123
+ if (count > MAX_FILES_PER_CALL) {
124
+ throw new BuildError(`examples[${idx}] references more than ${MAX_FILES_PER_CALL} files`);
125
+ }
126
+ const resolved = await Promise.all(paths.map((p) => resolveExampleInputFile(opts.projectDir, field.name, p, idx)));
127
+ stagedFiles.push({ field, files: resolved });
128
+ const displayNames = resolved.map((f) => f.name);
129
+ displayInput[field.name] = field.many ? displayNames : displayNames[0];
130
+ }
131
+ }
132
+ let outputFiles;
133
+ const callFiles = needsFiles
134
+ ? {
135
+ async stage(dirs) {
136
+ const sent = { ...rawInput };
137
+ let n = 0;
138
+ for (const { field, files } of stagedFiles) {
139
+ const copied = [];
140
+ for (const f of files) {
141
+ const slot = join(dirs.inputDir, String(n++));
142
+ await mkdir(slot);
143
+ await copyFile(f.source, join(slot, f.name));
144
+ copied.push(join(slot, f.name));
145
+ }
146
+ sent[field.name] = field.many ? copied : copied[0];
147
+ }
148
+ return sent;
149
+ },
150
+ async collect(returned, dirs) {
151
+ if (returned === null || typeof returned !== "object" || Array.isArray(returned)) {
152
+ throw new BuildError(`examples[${idx}] did not return a JSON object`);
153
+ }
154
+ const outObj = { ...returned };
155
+ if (outFiles.length === 0)
156
+ return outObj;
157
+ const outDir = await realpath(dirs.outputDir);
158
+ const meta = {};
159
+ let count = 0;
160
+ for (const field of outFiles) {
161
+ const value = outObj[field.name];
162
+ if (value === undefined)
163
+ continue;
164
+ const paths = field.many ? value : [value];
165
+ if (!Array.isArray(paths) || paths.some((p) => typeof p !== "string")) {
166
+ throw new BuildError(`examples[${idx}] output.${field.name} must be a file path string`);
167
+ }
168
+ count += paths.length;
169
+ if (count > MAX_FILES_PER_CALL) {
170
+ throw new BuildError(`examples[${idx}] returned more than ${MAX_FILES_PER_CALL} files`);
171
+ }
172
+ const collected = await Promise.all(paths.map((p) => collectExampleOutputFile(field.name, p, outDir, idx)));
173
+ if (field.many) {
174
+ meta[field.name] = collected;
175
+ outObj[field.name] = collected.map((f) => f.name);
176
+ }
177
+ else if (collected[0]) {
178
+ meta[field.name] = collected[0];
179
+ outObj[field.name] = collected[0].name;
180
+ }
181
+ }
182
+ if (Object.keys(meta).length > 0)
183
+ outputFiles = meta;
184
+ return outObj;
185
+ },
186
+ }
187
+ : undefined;
188
+ let rawOutput;
189
+ try {
190
+ const result = await opts.supervisor.run(spec, rawInput, {
191
+ timeoutMs,
192
+ isolation: "per-call",
193
+ files: callFiles,
194
+ });
195
+ rawOutput = result.output;
196
+ }
197
+ catch (err) {
198
+ if (err instanceof BuildError)
199
+ throw err;
200
+ throw new BuildError(`examples[${idx}]${ex.title ? ` (${ex.title})` : ""} failed while capturing output`, [err.message]);
201
+ }
202
+ if (rawOutput === null || typeof rawOutput !== "object" || Array.isArray(rawOutput)) {
203
+ throw new BuildError(`examples[${idx}] handler must return a JSON object`);
204
+ }
205
+ const entry = {
206
+ ...(ex.title ? { title: ex.title } : {}),
207
+ ...(ex.prompt ? { prompt: ex.prompt } : {}),
208
+ input: displayInput,
209
+ output: rawOutput,
210
+ ...(outputFiles ? { outputFiles } : {}),
211
+ };
212
+ const bytes = Buffer.byteLength(JSON.stringify(entry));
213
+ if (bytes > MAX_EXAMPLE_BYTES) {
214
+ throw new BuildError(`examples[${idx}] captured output is ${bytes} bytes (limit is ${MAX_EXAMPLE_BYTES} bytes); use a smaller example input`);
215
+ }
216
+ captured.push(entry);
217
+ }
218
+ return captured;
219
+ }
220
+ //# sourceMappingURL=examples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examples.js","sourceRoot":"","sources":["../src/examples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACxF,OAAO,EACL,aAAa,EAGb,UAAU,EAEV,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,kBAAkB,EAGlB,SAAS,GACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,iBAAiB;IACzB,OAAO,EAAE,yEAAyE;IAClF,OAAO,EAAE,mEAAmE;IAC5E,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,2BAA2B;IACnC,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,eAAe;IACtB,OAAO,EAAE,kBAAkB;IAC3B,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,sBAAsB;IAC9B,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,iBAAi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,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YACpF,MAAM,IAAI,UAAU,CAAC,YAAY,GAAG,qCAAqC,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,KAAK,GAAoB;YAC7B,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3C,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,SAAoC;YAC5C,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxC,CAAC;QACF,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACvD,IAAI,KAAK,GAAG,iBAAiB,EAAE,CAAC;YAC9B,MAAM,IAAI,UAAU,CAClB,YAAY,GAAG,wBAAwB,KAAK,oBAAoB,iBAAiB,sCAAsC,CACxH,CAAC;QACJ,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { version as ESBUILD_VERSION } from "esbuild";
2
+ export { BANNER, BUILDER_VERSION, type BuildOptions, type BuildResult, buildTool, bundle, bundleOptions, bundleOptionsHash, } from "./build.js";
3
+ export { BuildError } from "./errors.js";
4
+ export { type CaptureExamplesOptions, captureExamples } from "./examples.js";
5
+ export { type PackOptions, type PackResult, packTool } from "./pack.js";
6
+ export { type ProjectPackage, readProjectPackage } from "./project.js";
7
+ export { buildFromSource, MAX_SOURCE_BYTES, type PublishTarget, publishBuilt, removeSourceBuild, SOURCE_TOOL_PACKAGE, type SourceBuild, type SourceBuildOptions, } from "./source.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EACL,MAAM,EACN,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,SAAS,EACT,MAAM,EACN,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,sBAAsB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,KAAK,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,KAAK,aAAa,EAClB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { version as ESBUILD_VERSION } from "esbuild";
2
+ export { BANNER, BUILDER_VERSION, buildTool, bundle, bundleOptions, bundleOptionsHash, } from "./build.js";
3
+ export { BuildError } from "./errors.js";
4
+ export { captureExamples } from "./examples.js";
5
+ export { packTool } from "./pack.js";
6
+ export { readProjectPackage } from "./project.js";
7
+ export { buildFromSource, MAX_SOURCE_BYTES, publishBuilt, removeSourceBuild, SOURCE_TOOL_PACKAGE, } from "./source.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EACL,MAAM,EACN,eAAe,EAGf,SAAS,EACT,MAAM,EACN,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAA+B,eAAe,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAqC,QAAQ,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAuB,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EACL,eAAe,EACf,gBAAgB,EAEhB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,GAGpB,MAAM,aAAa,CAAC"}
package/dist/pack.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { type ToolManifest } from "@toolpal/manifest";
2
+ export interface PackResult {
3
+ tarball: Buffer;
4
+ integrity: string;
5
+ entryIntegrity: string;
6
+ manifest: ToolManifest;
7
+ files: Array<{
8
+ path: string;
9
+ size: number;
10
+ }>;
11
+ }
12
+ export interface PackOptions {
13
+ /**
14
+ * The version this package is published as: the one the registry assigns next
15
+ * (`nextVersion`). Without it the package keeps the build's unpublished version,
16
+ * which no registry accepts.
17
+ */
18
+ version?: string | undefined;
19
+ }
20
+ /**
21
+ * Packs a built project: manifest + the exact bundle + package.json + docs +
22
+ * `src/` (for reading only) + the dependency lockfile (for verify-build). The
23
+ * version is stamped here, into the packed manifest only; the build on disk
24
+ * stays unversioned.
25
+ */
26
+ export declare function packTool(projectDir: string, opts?: PackOptions): Promise<PackResult>;
27
+ //# sourceMappingURL=pack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAEA,OAAO,EAQL,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC9C;AAeD,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAuD9F"}
package/dist/pack.js ADDED
@@ -0,0 +1,82 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { createTarball, ENTRY_PATH, integrityOf, MAX_TARBALL_BYTES, MAX_TARBALL_FILES, parseManifest, TARBALL_MANIFEST_PATH, } from "@toolpal/manifest";
4
+ import { BuildError } from "./errors.js";
5
+ const ROOT_DOCS = /^(readme|license|licence|changelog)(\.[a-z]+)?$/i;
6
+ const LOCKFILES = ["package-lock.json", "pnpm-lock.yaml", "yarn.lock", "bun.lock"];
7
+ async function collectDir(base, rel, out) {
8
+ for (const entry of await readdir(join(base, rel), { withFileTypes: true })) {
9
+ if (entry.name.startsWith(".") || entry.name === "node_modules")
10
+ continue;
11
+ const childRel = `${rel}/${entry.name}`;
12
+ if (entry.isDirectory())
13
+ await collectDir(base, childRel, out);
14
+ else if (entry.isFile())
15
+ out.set(childRel, await readFile(join(base, childRel)));
16
+ // Symlinks and other special files are skipped: they never go into a tarball.
17
+ }
18
+ }
19
+ /**
20
+ * Packs a built project: manifest + the exact bundle + package.json + docs +
21
+ * `src/` (for reading only) + the dependency lockfile (for verify-build). The
22
+ * version is stamped here, into the packed manifest only; the build on disk
23
+ * stays unversioned.
24
+ */
25
+ export async function packTool(projectDir, opts = {}) {
26
+ let manifestText;
27
+ let bundle;
28
+ try {
29
+ manifestText = await readFile(join(projectDir, "dist", "manifest.json"), "utf8");
30
+ bundle = await readFile(join(projectDir, ENTRY_PATH));
31
+ }
32
+ catch {
33
+ throw new BuildError("dist/ is missing; run `toolpal build` first");
34
+ }
35
+ let manifest = parseManifest(JSON.parse(manifestText));
36
+ if (opts.version !== undefined && opts.version !== manifest.version) {
37
+ try {
38
+ manifest = parseManifest({ ...manifest, version: opts.version });
39
+ }
40
+ catch (err) {
41
+ throw new BuildError(`cannot pack as version "${opts.version}"`, [err.message]);
42
+ }
43
+ manifestText = `${JSON.stringify(manifest, null, 2)}\n`;
44
+ }
45
+ const files = new Map();
46
+ files.set(TARBALL_MANIFEST_PATH, Buffer.from(manifestText));
47
+ files.set(ENTRY_PATH, bundle);
48
+ files.set("package.json", await readFile(join(projectDir, "package.json")));
49
+ for (const entry of await readdir(projectDir, { withFileTypes: true })) {
50
+ if (entry.isFile() && ROOT_DOCS.test(entry.name)) {
51
+ files.set(entry.name, await readFile(join(projectDir, entry.name)));
52
+ }
53
+ }
54
+ for (const lockfile of LOCKFILES) {
55
+ const contents = await readFile(join(projectDir, lockfile)).catch(() => null);
56
+ if (contents) {
57
+ files.set(lockfile, contents);
58
+ break;
59
+ }
60
+ }
61
+ await collectDir(projectDir, "src", files).catch((err) => {
62
+ if (err.code !== "ENOENT")
63
+ throw err;
64
+ });
65
+ if (files.size > MAX_TARBALL_FILES) {
66
+ throw new BuildError(`package has ${files.size} files; the limit is ${MAX_TARBALL_FILES}`);
67
+ }
68
+ const tarball = createTarball(files);
69
+ if (tarball.length > MAX_TARBALL_BYTES) {
70
+ throw new BuildError(`tarball is ${tarball.length} bytes; the limit is ${MAX_TARBALL_BYTES}`);
71
+ }
72
+ return {
73
+ tarball,
74
+ integrity: integrityOf(tarball),
75
+ entryIntegrity: integrityOf(bundle, "sha256"),
76
+ manifest,
77
+ files: [...files]
78
+ .map(([path, data]) => ({ path, size: data.length }))
79
+ .sort((a, b) => a.path.localeCompare(b.path)),
80
+ };
81
+ }
82
+ //# sourceMappingURL=pack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.js","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,GAEtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAUzC,MAAM,SAAS,GAAG,kDAAkD,CAAC;AACrE,MAAM,SAAS,GAAG,CAAC,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAEnF,KAAK,UAAU,UAAU,CAAC,IAAY,EAAE,GAAW,EAAE,GAAwB;IAC3E,KAAK,MAAM,KAAK,IAAI,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAC5E,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc;YAAE,SAAS;QAC1E,MAAM,QAAQ,GAAG,GAAG,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,KAAK,CAAC,WAAW,EAAE;YAAE,MAAM,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;aAC1D,IAAI,KAAK,CAAC,MAAM,EAAE;YAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,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,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;QACvC,MAAM,IAAI,UAAU,CAAC,cAAc,OAAO,CAAC,MAAM,wBAAwB,iBAAiB,EAAE,CAAC,CAAC;IAChG,CAAC;IACD,OAAO;QACL,OAAO;QACP,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC;QAC/B,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC;QAC7C,QAAQ;QACR,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC;aACd,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;aACpD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;KAChD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type Limits, type Permissions } from "@toolpal/manifest";
2
+ /**
3
+ * The parts of an author's package.json that toolpal reads. Its "version" is not
4
+ * one of them: the registry numbers each publish, so authors never choose versions.
5
+ */
6
+ export interface ProjectPackage {
7
+ name: string;
8
+ description?: string | undefined;
9
+ license?: string | undefined;
10
+ repository?: string | undefined;
11
+ keywords?: string[] | undefined;
12
+ toolpal: {
13
+ entry: string;
14
+ /** Extra grants the analyzer cannot see (e.g. env vars read via computed keys). */
15
+ permissions: Partial<Permissions>;
16
+ limits: Limits;
17
+ };
18
+ }
19
+ export declare function readProjectPackage(projectDir: string): Promise<ProjectPackage>;
20
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,MAAM,EAEX,KAAK,WAAW,EAEjB,MAAM,mBAAmB,CAAC;AAG3B;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAChC,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,mFAAmF;QACnF,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QAClC,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,wBAAsB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAwCpF"}
@@ -0,0 +1,44 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { isValidToolName, limitsSchema, permissionsSchema, } from "@toolpal/manifest";
4
+ import { BuildError } from "./errors.js";
5
+ export async function readProjectPackage(projectDir) {
6
+ let raw;
7
+ try {
8
+ raw = JSON.parse(await readFile(join(projectDir, "package.json"), "utf8"));
9
+ }
10
+ catch (err) {
11
+ throw new BuildError(`cannot read package.json in ${projectDir}: ${err.message}`);
12
+ }
13
+ const name = String(raw.name ?? "");
14
+ if (!isValidToolName(name)) {
15
+ throw new BuildError(`package.json "name" must be @scope/name (lowercase), got "${name}"`);
16
+ }
17
+ const cfg = (raw.toolpal ?? {});
18
+ const permissions = permissionsSchema.partial().safeParse(cfg.permissions ?? {});
19
+ if (!permissions.success) {
20
+ throw new BuildError(`package.json toolpal.permissions: ${permissions.error.issues[0]?.message}`);
21
+ }
22
+ const limits = limitsSchema.safeParse(cfg.limits ?? {});
23
+ if (!limits.success) {
24
+ throw new BuildError(`package.json toolpal.limits: ${limits.error.issues[0]?.message}`);
25
+ }
26
+ const repository = typeof raw.repository === "string"
27
+ ? raw.repository
28
+ : typeof raw.repository?.url === "string"
29
+ ? raw.repository.url
30
+ : undefined;
31
+ return {
32
+ name,
33
+ description: typeof raw.description === "string" ? raw.description : undefined,
34
+ license: typeof raw.license === "string" ? raw.license : undefined,
35
+ repository,
36
+ keywords: Array.isArray(raw.keywords) ? raw.keywords.map(String).slice(0, 20) : undefined,
37
+ toolpal: {
38
+ entry: typeof cfg.entry === "string" ? cfg.entry : "src/index.ts",
39
+ permissions: permissions.data,
40
+ limits: limits.data,
41
+ },
42
+ };
43
+ }
44
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,eAAe,EAEf,YAAY,EAEZ,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAoBzC,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,UAAkB;IACzD,IAAI,GAA4B,CAAC;IACjC,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,UAAU,CAAC,+BAA+B,UAAU,KAAM,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/F,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IACpC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,UAAU,CAAC,6DAA6D,IAAI,GAAG,CAAC,CAAC;IAC7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AC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;QACzF,OAAO,EAAE;YACP,KAAK,EAAE,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc;YACjE,WAAW,EAAE,WAAW,CAAC,IAAI;YAC7B,MAAM,EAAE,MAAM,CAAC,IAAI;SACpB;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { Visibility } from "@toolpal/manifest";
2
+ import type { Supervisor } from "@toolpal/sandbox";
3
+ import { type BuildResult } from "./build.js";
4
+ import { type PackResult } from "./pack.js";
5
+ /** The one package a tool built from source may import; it brings the schema builder with it. */
6
+ export declare const SOURCE_TOOL_PACKAGE = "@toolpal/tool";
7
+ export declare const MAX_SOURCE_BYTES: number;
8
+ export interface SourceBuildOptions {
9
+ /** `@scope/name`. */
10
+ name: string;
11
+ /** The whole tool: one TypeScript module whose default export is `defineTool({...})`. */
12
+ code: string;
13
+ /**
14
+ * A directory this may fill. The authoring packages are copied into it once,
15
+ * and each build gets a subdirectory of its own.
16
+ */
17
+ workDir: string;
18
+ supervisor?: Supervisor | undefined;
19
+ }
20
+ export interface SourceBuild extends BuildResult {
21
+ /** The throwaway project that was built: pack or publish it, then remove it. */
22
+ projectDir: string;
23
+ }
24
+ /**
25
+ * Builds a tool from one source file, as `toolpal build` would build a project
26
+ * holding just that file. The source is not trusted: it may import
27
+ * `@toolpal/tool` and Node's built-in modules and nothing else, so no other
28
+ * file on this machine can end up in the bundle.
29
+ */
30
+ export declare function buildFromSource(opts: SourceBuildOptions): Promise<SourceBuild>;
31
+ /**
32
+ * Removes a build's throwaway project. On Windows the directory stays locked for
33
+ * a moment after the sandbox process that loaded the bundle exits, so this
34
+ * retries, and a directory that still cannot be removed is left behind rather
35
+ * than failing the caller.
36
+ */
37
+ export declare function removeSourceBuild(projectDir: string): Promise<void>;
38
+ /** The part of a registry client that publishing needs. */
39
+ export interface PublishTarget<Response> {
40
+ nextVersion(name: string): Promise<string>;
41
+ publish(name: string, version: string, tarball: Uint8Array, integrity: string, opts?: {
42
+ visibility?: Visibility | undefined;
43
+ }): Promise<Response>;
44
+ }
45
+ /**
46
+ * Packs a built project as its tool's next version and uploads it. The registry
47
+ * numbers versions, so when another publish takes the number first this one is
48
+ * repacked as the one after.
49
+ */
50
+ export declare function publishBuilt<Response>(target: PublishTarget<Response>, projectDir: string, visibility?: Visibility): Promise<{
51
+ pack: PackResult;
52
+ response: Response;
53
+ }>;
54
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,KAAK,WAAW,EAAa,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,WAAW,CAAC;AAGtD,iGAAiG;AACjG,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,gBAAgB,QAAa,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAC;CACpB;AAmFD;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CA0BpF;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIzE;AAED,2DAA2D;AAC3D,MAAM,WAAW,aAAa,CAAC,QAAQ;IACrC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,OAAO,CACL,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;KAAE,GAC7C,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EACzC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,EAC/B,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,CAkBnD"}
package/dist/source.js ADDED
@@ -0,0 +1,151 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { cp, mkdir, readdir, readFile, realpath, rename, rm, stat, writeFile, } from "node:fs/promises";
3
+ import { createRequire } from "node:module";
4
+ import { dirname, join, relative } from "node:path";
5
+ import { buildTool } from "./build.js";
6
+ import { BuildError } from "./errors.js";
7
+ import { packTool } from "./pack.js";
8
+ import { readProjectPackage } from "./project.js";
9
+ /** The one package a tool built from source may import; it brings the schema builder with it. */
10
+ export const SOURCE_TOOL_PACKAGE = "@toolpal/tool";
11
+ export const MAX_SOURCE_BYTES = 256 * 1024;
12
+ async function exists(path) {
13
+ return stat(path).then(() => true, () => false);
14
+ }
15
+ async function versionOf(packageRoot) {
16
+ return String(JSON.parse(await readFile(join(packageRoot, "package.json"), "utf8")).version);
17
+ }
18
+ /**
19
+ * A short digest of the files a kit copies from `@toolpal/tool`. A rebuilt
20
+ * package gets a kit of its own even when its version is unchanged; otherwise a
21
+ * kit copied before, say, a new export was added would be reused for good.
22
+ */
23
+ async function digestOf(toolRoot) {
24
+ const dist = join(toolRoot, "dist");
25
+ const files = (await readdir(dist, { recursive: true, withFileTypes: true }))
26
+ .filter((entry) => entry.isFile())
27
+ .map((entry) => join(entry.parentPath, entry.name))
28
+ .sort();
29
+ const hash = createHash("sha256");
30
+ for (const file of [join(toolRoot, "package.json"), ...files]) {
31
+ hash
32
+ .update(relative(toolRoot, file))
33
+ .update("\0")
34
+ .update(await readFile(file))
35
+ .update("\0");
36
+ }
37
+ return hash.digest("hex").slice(0, 12);
38
+ }
39
+ /**
40
+ * Copies `@toolpal/tool` and its schema library to
41
+ * `<workDir>/<versions>-<digest>/node_modules`, once per build of them. Builds
42
+ * happen below that directory, so they resolve exactly what an installed project
43
+ * would, without npm running and without the bundle naming any path outside it.
44
+ */
45
+ async function ensureKit(workDir) {
46
+ let toolRoot;
47
+ let typeboxRoot;
48
+ try {
49
+ const entry = createRequire(import.meta.url).resolve(SOURCE_TOOL_PACKAGE);
50
+ toolRoot = dirname(dirname(await realpath(entry)));
51
+ for (let dir = toolRoot; typeboxRoot === undefined; dir = dirname(dir)) {
52
+ const candidate = join(dir, "node_modules", "typebox");
53
+ if (await exists(join(candidate, "package.json")))
54
+ typeboxRoot = await realpath(candidate);
55
+ else if (dirname(dir) === dir)
56
+ throw new Error("typebox is not installed");
57
+ }
58
+ }
59
+ catch (err) {
60
+ throw new BuildError(`${SOURCE_TOOL_PACKAGE} is not installed alongside toolpal, so a tool cannot be built from source here`, [err.message]);
61
+ }
62
+ const toolVersion = await versionOf(toolRoot);
63
+ const versions = `${toolVersion}-${await versionOf(typeboxRoot)}`;
64
+ const dir = join(workDir, `${versions}-${await digestOf(toolRoot)}`);
65
+ if (await exists(join(dir, "node_modules")))
66
+ return { dir, toolVersion };
67
+ // Filled under another name and renamed, so a build never sees half a copy.
68
+ const staging = `${dir}.${randomBytes(6).toString("hex")}.tmp`;
69
+ const tool = join(staging, "node_modules", "@toolpal", "tool");
70
+ await mkdir(tool, { recursive: true });
71
+ await cp(join(toolRoot, "package.json"), join(tool, "package.json"));
72
+ await cp(join(toolRoot, "dist"), join(tool, "dist"), { recursive: true });
73
+ await cp(typeboxRoot, join(staging, "node_modules", "typebox"), {
74
+ recursive: true,
75
+ dereference: true,
76
+ });
77
+ try {
78
+ await rename(staging, dir);
79
+ }
80
+ catch (err) {
81
+ await rm(staging, { recursive: true, force: true });
82
+ // Another process finished the same copy first.
83
+ if (!(await exists(join(dir, "node_modules"))))
84
+ throw err;
85
+ }
86
+ return { dir, toolVersion };
87
+ }
88
+ /**
89
+ * Builds a tool from one source file, as `toolpal build` would build a project
90
+ * holding just that file. The source is not trusted: it may import
91
+ * `@toolpal/tool` and Node's built-in modules and nothing else, so no other
92
+ * file on this machine can end up in the bundle.
93
+ */
94
+ export async function buildFromSource(opts) {
95
+ if (Buffer.byteLength(opts.code) > MAX_SOURCE_BYTES) {
96
+ throw new BuildError(`the source is larger than ${MAX_SOURCE_BYTES} bytes`);
97
+ }
98
+ const kit = await ensureKit(opts.workDir);
99
+ const projectDir = join(kit.dir, "build", randomBytes(6).toString("hex"));
100
+ try {
101
+ await mkdir(join(projectDir, "src"), { recursive: true });
102
+ const pkg = {
103
+ name: opts.name,
104
+ type: "module",
105
+ toolpal: { entry: "src/index.ts" },
106
+ dependencies: { [SOURCE_TOOL_PACKAGE]: `^${kit.toolVersion}` },
107
+ };
108
+ await writeFile(join(projectDir, "package.json"), `${JSON.stringify(pkg, null, 2)}\n`);
109
+ await writeFile(join(projectDir, "src", "index.ts"), opts.code);
110
+ const built = await buildTool({
111
+ projectDir,
112
+ supervisor: opts.supervisor,
113
+ onlyPackages: [SOURCE_TOOL_PACKAGE],
114
+ });
115
+ return { ...built, projectDir };
116
+ }
117
+ catch (err) {
118
+ await removeSourceBuild(projectDir);
119
+ throw err;
120
+ }
121
+ }
122
+ /**
123
+ * Removes a build's throwaway project. On Windows the directory stays locked for
124
+ * a moment after the sandbox process that loaded the bundle exits, so this
125
+ * retries, and a directory that still cannot be removed is left behind rather
126
+ * than failing the caller.
127
+ */
128
+ export async function removeSourceBuild(projectDir) {
129
+ await rm(projectDir, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }).catch(() => undefined);
130
+ }
131
+ /**
132
+ * Packs a built project as its tool's next version and uploads it. The registry
133
+ * numbers versions, so when another publish takes the number first this one is
134
+ * repacked as the one after.
135
+ */
136
+ export async function publishBuilt(target, projectDir, visibility) {
137
+ const { name } = await readProjectPackage(projectDir);
138
+ for (let attempt = 1;; attempt++) {
139
+ const pack = await packTool(projectDir, { version: await target.nextVersion(name) });
140
+ try {
141
+ const response = await target.publish(name, pack.manifest.version, pack.tarball, pack.integrity, { visibility });
142
+ return { pack, response };
143
+ }
144
+ catch (err) {
145
+ const code = err.details?.registryCode;
146
+ if (attempt >= 3 || (code !== "VERSION_NOT_NEXT" && code !== "VERSION_EXISTS"))
147
+ throw err;
148
+ }
149
+ }
150
+ }
151
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,EAAE,EACF,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,EAAE,EACF,IAAI,EACJ,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGpD,OAAO,EAAoB,SAAS,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,E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ACd,EAAE,UAAU,EAAE,CACf,CAAC;YACF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC5B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,GAAI,GAAgD,CAAC,OAAO,EAAE,YAAY,CAAC;YACrF,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB,IAAI,IAAI,KAAK,gBAAgB,CAAC;gBAAE,MAAM,GAAG,CAAC;QAC5F,CAAC;IACH,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@toolpal/builder",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Builds, analyzes and packs Toolpal workflows",
5
+ "homepage": "https://toolpal.dev",
6
+ "type": "module",
7
+ "license": "SEE LICENSE IN LICENSE",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "LICENSE",
20
+ "README.md"
21
+ ],
22
+ "engines": {
23
+ "node": ">=22.15.0"
24
+ },
25
+ "dependencies": {
26
+ "esbuild": "^0.28.2",
27
+ "semver": "^7.8.5",
28
+ "@toolpal/analyzer": "0.1.1",
29
+ "@toolpal/sandbox": "0.1.1",
30
+ "@toolpal/manifest": "0.1.1",
31
+ "@toolpal/tool": "0.1.1"
32
+ },
33
+ "devDependencies": {
34
+ "@types/semver": "^7.8.0"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc -b"
38
+ }
6
39
  }