sunpeak 0.16.27 → 0.16.28
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/bin/commands/build.mjs +0 -1
- package/dist/chatgpt/globals.css +10 -9
- package/dist/chatgpt/index.cjs +55 -24
- package/dist/chatgpt/index.cjs.map +1 -1
- package/dist/chatgpt/index.js +31 -25
- package/dist/chatgpt/index.js.map +1 -1
- package/dist/chunk-9hOWP6kD.cjs +64 -0
- package/dist/chunk-D6g4UhsZ.js +35 -0
- package/dist/claude/index.cjs +4 -4
- package/dist/claude/index.js +3 -5
- package/dist/discovery-BxKCIgG5.cjs +332 -0
- package/dist/discovery-BxKCIgG5.cjs.map +1 -0
- package/dist/discovery-Du4LHrih.js +261 -0
- package/dist/discovery-Du4LHrih.js.map +1 -0
- package/dist/host/chatgpt/index.cjs +171 -65
- package/dist/host/chatgpt/index.cjs.map +1 -1
- package/dist/host/chatgpt/index.js +170 -70
- package/dist/host/chatgpt/index.js.map +1 -1
- package/dist/host/index.cjs +47 -19
- package/dist/host/index.cjs.map +1 -1
- package/dist/host/index.js +47 -24
- package/dist/host/index.js.map +1 -1
- package/dist/index.cjs +3103 -3725
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3026 -3746
- package/dist/index.js.map +1 -1
- package/dist/lib/discovery-cli.cjs +117 -131
- package/dist/lib/discovery-cli.cjs.map +1 -1
- package/dist/lib/discovery-cli.js +107 -111
- package/dist/lib/discovery-cli.js.map +1 -1
- package/dist/mcp/index.cjs +9818 -10283
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +9799 -10282
- package/dist/mcp/index.js.map +1 -1
- package/dist/protocol-DJmRaBzO.js +11080 -0
- package/dist/{protocol-DkDHRwOW.cjs.map → protocol-DJmRaBzO.js.map} +1 -1
- package/dist/protocol-jbxhzcnS.cjs +11493 -0
- package/dist/protocol-jbxhzcnS.cjs.map +1 -0
- package/dist/simulator/index.cjs +79 -36
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.js +43 -37
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator-BYIH-xqQ.cjs +3701 -0
- package/dist/{simulator-Gc6n_fT4.cjs.map → simulator-BYIH-xqQ.cjs.map} +1 -1
- package/dist/simulator-CmgNnWBO.js +3575 -0
- package/dist/simulator-CmgNnWBO.js.map +1 -0
- package/dist/simulator-url-BDGD4vZD.cjs +69 -0
- package/dist/simulator-url-BDGD4vZD.cjs.map +1 -0
- package/dist/simulator-url-Bkxj43yT.js +64 -0
- package/dist/simulator-url-Bkxj43yT.js.map +1 -0
- package/dist/style.css +10 -9
- package/dist/use-app-D2h-aiyr.cjs +940 -0
- package/dist/use-app-D2h-aiyr.cjs.map +1 -0
- package/dist/use-app-X7JbGskk.js +598 -0
- package/dist/use-app-X7JbGskk.js.map +1 -0
- package/package.json +8 -8
- package/template/node_modules/.bin/vite +2 -2
- package/template/node_modules/.bin/vitest +2 -2
- package/template/package.json +5 -5
- package/dist/claude/index.cjs.map +0 -1
- package/dist/claude/index.js.map +0 -1
- package/dist/discovery-BVqD-JsT.js +0 -224
- package/dist/discovery-BVqD-JsT.js.map +0 -1
- package/dist/discovery-D1gpaVz4.cjs +0 -223
- package/dist/discovery-D1gpaVz4.cjs.map +0 -1
- package/dist/index-BEWVLFfB.cjs +0 -28
- package/dist/index-BEWVLFfB.cjs.map +0 -1
- package/dist/index-C6XYFOmh.js +0 -29
- package/dist/index-C6XYFOmh.js.map +0 -1
- package/dist/index-D0FsXP3Y.cjs +0 -40
- package/dist/index-D0FsXP3Y.cjs.map +0 -1
- package/dist/index-Rg7SWjvl.js +0 -41
- package/dist/index-Rg7SWjvl.js.map +0 -1
- package/dist/protocol-DkDHRwOW.cjs +0 -12221
- package/dist/protocol-uge7qFev.js +0 -12223
- package/dist/protocol-uge7qFev.js.map +0 -1
- package/dist/simulator-B-CrMHVs.js +0 -3534
- package/dist/simulator-B-CrMHVs.js.map +0 -1
- package/dist/simulator-Gc6n_fT4.cjs +0 -3549
- package/dist/simulator-url-DcSYRl-P.cjs +0 -53
- package/dist/simulator-url-DcSYRl-P.cjs.map +0 -1
- package/dist/simulator-url-j_XV3EoP.js +0 -54
- package/dist/simulator-url-j_XV3EoP.js.map +0 -1
- package/dist/use-app-C9gpzIQO.js +0 -349
- package/dist/use-app-C9gpzIQO.js.map +0 -1
- package/dist/use-app-D09O2swh.cjs +0 -348
- package/dist/use-app-D09O2swh.cjs.map +0 -1
|
@@ -1,138 +1,124 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
|
-
const
|
|
26
|
-
const
|
|
2
|
+
const require_chunk = require("../chunk-9hOWP6kD.cjs");
|
|
3
|
+
const require_discovery = require("../discovery-BxKCIgG5.cjs");
|
|
4
|
+
let path = require("path");
|
|
5
|
+
path = require_chunk.__toESM(path);
|
|
6
|
+
//#region src/lib/extract-resource.ts
|
|
7
|
+
/**
|
|
8
|
+
* Extract the `resource` named export from a resource .tsx file.
|
|
9
|
+
*
|
|
10
|
+
* Uses esbuild to bundle only the `resource` export, stubbing all of the
|
|
11
|
+
* resource file's own imports (React, components, etc.) so only the static
|
|
12
|
+
* config object is evaluated.
|
|
13
|
+
*/
|
|
27
14
|
async function extractResourceExport(tsxPath) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`No "resource" export found in ${tsxPath}. Add: export const resource: ResourceConfig = { title: '...', ... };`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
return resource;
|
|
15
|
+
const esbuild = await import("esbuild");
|
|
16
|
+
const absolutePath = path.default.resolve(tsxPath);
|
|
17
|
+
const dir = path.default.dirname(absolutePath);
|
|
18
|
+
const base = path.default.basename(absolutePath);
|
|
19
|
+
const result = await esbuild.build({
|
|
20
|
+
stdin: {
|
|
21
|
+
contents: `export { resource } from './${base}';`,
|
|
22
|
+
resolveDir: dir,
|
|
23
|
+
loader: "ts"
|
|
24
|
+
},
|
|
25
|
+
bundle: true,
|
|
26
|
+
write: false,
|
|
27
|
+
format: "cjs",
|
|
28
|
+
treeShaking: true,
|
|
29
|
+
loader: {
|
|
30
|
+
".tsx": "tsx",
|
|
31
|
+
".ts": "ts",
|
|
32
|
+
".jsx": "jsx"
|
|
33
|
+
},
|
|
34
|
+
logLevel: "silent",
|
|
35
|
+
plugins: [{
|
|
36
|
+
name: "externalize-deps",
|
|
37
|
+
setup(build) {
|
|
38
|
+
let entryResolved = false;
|
|
39
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
40
|
+
if (args.kind !== "import-statement") return;
|
|
41
|
+
if (!entryResolved) {
|
|
42
|
+
entryResolved = true;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
return { external: true };
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}]
|
|
49
|
+
});
|
|
50
|
+
if (!result.outputFiles?.length) throw new Error(`Failed to extract resource from ${tsxPath}`);
|
|
51
|
+
const code = result.outputFiles[0].text;
|
|
52
|
+
const mod = { exports: {} };
|
|
53
|
+
new Function("module", "exports", "require", code)(mod, mod.exports, () => ({}));
|
|
54
|
+
const resource = mod.exports.resource;
|
|
55
|
+
if (!resource) throw new Error(`No "resource" export found in ${tsxPath}. Add: export const resource: ResourceConfig = { title: '...', ... };`);
|
|
56
|
+
return resource;
|
|
74
57
|
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/lib/extract-tool.ts
|
|
60
|
+
/**
|
|
61
|
+
* Extract the `tool` named export from a tool .ts file.
|
|
62
|
+
*
|
|
63
|
+
* Uses esbuild in ESM mode to compile TypeScript and tree-shake to just the
|
|
64
|
+
* `tool` export. ESM tree-shaking drops unused exports (schema, handler) so
|
|
65
|
+
* their dependencies (zod, etc.) are never evaluated.
|
|
66
|
+
*
|
|
67
|
+
* `schema` and `default` handler are loaded at runtime via Vite SSR.
|
|
68
|
+
*/
|
|
75
69
|
async function extractToolExport(tsPath) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (toolMatch) {
|
|
118
|
-
tool = new Function("return " + toolMatch[1])();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (!tool) {
|
|
122
|
-
throw new Error(
|
|
123
|
-
`No "tool" export found in ${tsPath}. Add: export const tool: AppToolConfig = { ... };`
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
return { tool };
|
|
70
|
+
const esbuild = await import("esbuild");
|
|
71
|
+
const absolutePath = path.default.resolve(tsPath);
|
|
72
|
+
const dir = path.default.dirname(absolutePath);
|
|
73
|
+
const base = path.default.basename(absolutePath);
|
|
74
|
+
const result = await esbuild.build({
|
|
75
|
+
stdin: {
|
|
76
|
+
contents: `export { tool } from './${base}';`,
|
|
77
|
+
resolveDir: dir,
|
|
78
|
+
loader: "ts"
|
|
79
|
+
},
|
|
80
|
+
bundle: true,
|
|
81
|
+
write: false,
|
|
82
|
+
format: "esm",
|
|
83
|
+
treeShaking: true,
|
|
84
|
+
loader: {
|
|
85
|
+
".tsx": "tsx",
|
|
86
|
+
".ts": "ts",
|
|
87
|
+
".jsx": "jsx"
|
|
88
|
+
},
|
|
89
|
+
logLevel: "silent",
|
|
90
|
+
plugins: [{
|
|
91
|
+
name: "externalize-node-modules",
|
|
92
|
+
setup(build) {
|
|
93
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
94
|
+
if (args.kind !== "import-statement") return;
|
|
95
|
+
if (!args.path.startsWith(".") && !args.path.startsWith("/")) return { external: true };
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}]
|
|
99
|
+
});
|
|
100
|
+
if (!result.outputFiles?.length) throw new Error(`Failed to extract tool from ${tsPath}`);
|
|
101
|
+
const code = result.outputFiles[0].text.replace(/^import\s+.*$/gm, "").replace(/^export\s*\{[^}]*\}\s*;?\s*$/m, "");
|
|
102
|
+
let tool;
|
|
103
|
+
try {
|
|
104
|
+
tool = new Function(code + "\nreturn tool;")();
|
|
105
|
+
} catch {
|
|
106
|
+
const toolMatch = result.outputFiles[0].text.match(/var tool\s*=\s*(\{[\s\S]*?\n\});/);
|
|
107
|
+
if (toolMatch) tool = new Function("return " + toolMatch[1])();
|
|
108
|
+
}
|
|
109
|
+
if (!tool) throw new Error(`No "tool" export found in ${tsPath}. Add: export const tool: AppToolConfig = { ... };`);
|
|
110
|
+
return { tool };
|
|
127
111
|
}
|
|
128
|
-
|
|
129
|
-
exports.extractSimulationKey = discovery.extractSimulationKey;
|
|
130
|
-
exports.findResourceDirs = discovery.findResourceDirs;
|
|
131
|
-
exports.findResourceKey = discovery.findResourceKey;
|
|
132
|
-
exports.findSimulationFilesFlat = discovery.findSimulationFilesFlat;
|
|
133
|
-
exports.findToolFiles = discovery.findToolFiles;
|
|
134
|
-
exports.getComponentName = discovery.getComponentName;
|
|
135
|
-
exports.toPascalCase = discovery.toPascalCase;
|
|
112
|
+
//#endregion
|
|
136
113
|
exports.extractResourceExport = extractResourceExport;
|
|
114
|
+
exports.extractResourceKey = require_discovery.extractResourceKey;
|
|
115
|
+
exports.extractSimulationKey = require_discovery.extractSimulationKey;
|
|
137
116
|
exports.extractToolExport = extractToolExport;
|
|
138
|
-
|
|
117
|
+
exports.findResourceDirs = require_discovery.findResourceDirs;
|
|
118
|
+
exports.findResourceKey = require_discovery.findResourceKey;
|
|
119
|
+
exports.findSimulationFilesFlat = require_discovery.findSimulationFilesFlat;
|
|
120
|
+
exports.findToolFiles = require_discovery.findToolFiles;
|
|
121
|
+
exports.getComponentName = require_discovery.getComponentName;
|
|
122
|
+
exports.toPascalCase = require_discovery.toPascalCase;
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=discovery-cli.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery-cli.cjs","sources":["../../src/lib/extract-resource.ts","../../src/lib/extract-tool.ts"],"sourcesContent":["import path from 'path';\n\n/**\n * Extract the `resource` named export from a resource .tsx file.\n *\n * Uses esbuild to bundle only the `resource` export, stubbing all of the\n * resource file's own imports (React, components, etc.) so only the static\n * config object is evaluated.\n */\nexport async function extractResourceExport(tsxPath: string): Promise<Record<string, unknown>> {\n const esbuild = await import('esbuild');\n const absolutePath = path.resolve(tsxPath);\n const dir = path.dirname(absolutePath);\n const base = path.basename(absolutePath);\n\n const result = await esbuild.build({\n stdin: {\n contents: `export { resource } from './${base}';`,\n resolveDir: dir,\n loader: 'ts',\n },\n bundle: true,\n write: false,\n format: 'cjs',\n treeShaking: true,\n loader: { '.tsx': 'tsx', '.ts': 'ts', '.jsx': 'jsx' },\n logLevel: 'silent',\n plugins: [\n {\n name: 'externalize-deps',\n setup(build) {\n let entryResolved = false;\n // Let stdin's import of the resource file resolve normally,\n // but externalize everything the resource file itself imports.\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind !== 'import-statement') return;\n if (!entryResolved) {\n entryResolved = true;\n return;\n }\n return { external: true };\n });\n },\n },\n ],\n });\n\n if (!result.outputFiles?.length) {\n throw new Error(`Failed to extract resource from ${tsxPath}`);\n }\n\n const code = result.outputFiles[0].text;\n const mod: { exports: Record<string, unknown> } = { exports: {} };\n new Function('module', 'exports', 'require', code)(mod, mod.exports, () => ({}));\n\n const resource = mod.exports.resource as Record<string, unknown> | undefined;\n if (!resource) {\n throw new Error(\n `No \"resource\" export found in ${tsxPath}. ` +\n `Add: export const resource: ResourceConfig = { title: '...', ... };`\n );\n }\n\n return resource;\n}\n","import path from 'path';\n\n/**\n * Extract the `tool` named export from a tool .ts file.\n *\n * Uses esbuild in ESM mode to compile TypeScript and tree-shake to just the\n * `tool` export. ESM tree-shaking drops unused exports (schema, handler) so\n * their dependencies (zod, etc.) are never evaluated.\n *\n * `schema` and `default` handler are loaded at runtime via Vite SSR.\n */\nexport async function extractToolExport(\n tsPath: string\n): Promise<{ tool: Record<string, unknown> }> {\n const esbuild = await import('esbuild');\n const absolutePath = path.resolve(tsPath);\n const dir = path.dirname(absolutePath);\n const base = path.basename(absolutePath);\n\n const result = await esbuild.build({\n stdin: {\n contents: `export { tool } from './${base}';`,\n resolveDir: dir,\n loader: 'ts',\n },\n bundle: true,\n write: false,\n format: 'esm',\n treeShaking: true,\n loader: { '.tsx': 'tsx', '.ts': 'ts', '.jsx': 'jsx' },\n logLevel: 'silent',\n plugins: [\n {\n name: 'externalize-node-modules',\n setup(build) {\n // Resolve relative imports normally (resource files, local modules)\n // but externalize everything from node_modules\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind !== 'import-statement') return;\n // Bare specifiers (not starting with . or /) are node_modules\n if (!args.path.startsWith('.') && !args.path.startsWith('/')) {\n return { external: true };\n }\n return undefined;\n });\n },\n },\n ],\n });\n\n if (!result.outputFiles?.length) {\n throw new Error(`Failed to extract tool from ${tsPath}`);\n }\n\n // Strip import statements and export block so we can eval as plain JS.\n // `tool` is pure data (no dependencies), so stripping imports is safe.\n // Other top-level code (schema, etc.) may reference stripped imports but\n // we only need the `tool` variable — errors in other code are caught and ignored.\n const code = result.outputFiles[0].text\n .replace(/^import\\s+.*$/gm, '')\n .replace(/^export\\s*\\{[^}]*\\}\\s*;?\\s*$/m, '');\n let tool: Record<string, unknown> | undefined;\n try {\n const fn = new Function(code + '\\nreturn tool;');\n tool = fn() as Record<string, unknown> | undefined;\n } catch {\n // If other top-level code crashes (e.g. schema using stripped zod),\n // extract just the tool variable declaration and eval that alone.\n const toolMatch = result.outputFiles[0].text.match(/var tool\\s*=\\s*(\\{[\\s\\S]*?\\n\\});/);\n if (toolMatch) {\n tool = new Function('return ' + toolMatch[1])() as Record<string, unknown>;\n }\n }\n if (!tool) {\n throw new Error(\n `No \"tool\" export found in ${tsPath}. ` + `Add: export const tool: AppToolConfig = { ... };`\n );\n }\n\n return { tool };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"discovery-cli.cjs","names":[],"sources":["../../src/lib/extract-resource.ts","../../src/lib/extract-tool.ts"],"sourcesContent":["import path from 'path';\n\n/**\n * Extract the `resource` named export from a resource .tsx file.\n *\n * Uses esbuild to bundle only the `resource` export, stubbing all of the\n * resource file's own imports (React, components, etc.) so only the static\n * config object is evaluated.\n */\nexport async function extractResourceExport(tsxPath: string): Promise<Record<string, unknown>> {\n const esbuild = await import('esbuild');\n const absolutePath = path.resolve(tsxPath);\n const dir = path.dirname(absolutePath);\n const base = path.basename(absolutePath);\n\n const result = await esbuild.build({\n stdin: {\n contents: `export { resource } from './${base}';`,\n resolveDir: dir,\n loader: 'ts',\n },\n bundle: true,\n write: false,\n format: 'cjs',\n treeShaking: true,\n loader: { '.tsx': 'tsx', '.ts': 'ts', '.jsx': 'jsx' },\n logLevel: 'silent',\n plugins: [\n {\n name: 'externalize-deps',\n setup(build) {\n let entryResolved = false;\n // Let stdin's import of the resource file resolve normally,\n // but externalize everything the resource file itself imports.\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind !== 'import-statement') return;\n if (!entryResolved) {\n entryResolved = true;\n return;\n }\n return { external: true };\n });\n },\n },\n ],\n });\n\n if (!result.outputFiles?.length) {\n throw new Error(`Failed to extract resource from ${tsxPath}`);\n }\n\n const code = result.outputFiles[0].text;\n const mod: { exports: Record<string, unknown> } = { exports: {} };\n new Function('module', 'exports', 'require', code)(mod, mod.exports, () => ({}));\n\n const resource = mod.exports.resource as Record<string, unknown> | undefined;\n if (!resource) {\n throw new Error(\n `No \"resource\" export found in ${tsxPath}. ` +\n `Add: export const resource: ResourceConfig = { title: '...', ... };`\n );\n }\n\n return resource;\n}\n","import path from 'path';\n\n/**\n * Extract the `tool` named export from a tool .ts file.\n *\n * Uses esbuild in ESM mode to compile TypeScript and tree-shake to just the\n * `tool` export. ESM tree-shaking drops unused exports (schema, handler) so\n * their dependencies (zod, etc.) are never evaluated.\n *\n * `schema` and `default` handler are loaded at runtime via Vite SSR.\n */\nexport async function extractToolExport(\n tsPath: string\n): Promise<{ tool: Record<string, unknown> }> {\n const esbuild = await import('esbuild');\n const absolutePath = path.resolve(tsPath);\n const dir = path.dirname(absolutePath);\n const base = path.basename(absolutePath);\n\n const result = await esbuild.build({\n stdin: {\n contents: `export { tool } from './${base}';`,\n resolveDir: dir,\n loader: 'ts',\n },\n bundle: true,\n write: false,\n format: 'esm',\n treeShaking: true,\n loader: { '.tsx': 'tsx', '.ts': 'ts', '.jsx': 'jsx' },\n logLevel: 'silent',\n plugins: [\n {\n name: 'externalize-node-modules',\n setup(build) {\n // Resolve relative imports normally (resource files, local modules)\n // but externalize everything from node_modules\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind !== 'import-statement') return;\n // Bare specifiers (not starting with . or /) are node_modules\n if (!args.path.startsWith('.') && !args.path.startsWith('/')) {\n return { external: true };\n }\n return undefined;\n });\n },\n },\n ],\n });\n\n if (!result.outputFiles?.length) {\n throw new Error(`Failed to extract tool from ${tsPath}`);\n }\n\n // Strip import statements and export block so we can eval as plain JS.\n // `tool` is pure data (no dependencies), so stripping imports is safe.\n // Other top-level code (schema, etc.) may reference stripped imports but\n // we only need the `tool` variable — errors in other code are caught and ignored.\n const code = result.outputFiles[0].text\n .replace(/^import\\s+.*$/gm, '')\n .replace(/^export\\s*\\{[^}]*\\}\\s*;?\\s*$/m, '');\n let tool: Record<string, unknown> | undefined;\n try {\n const fn = new Function(code + '\\nreturn tool;');\n tool = fn() as Record<string, unknown> | undefined;\n } catch {\n // If other top-level code crashes (e.g. schema using stripped zod),\n // extract just the tool variable declaration and eval that alone.\n const toolMatch = result.outputFiles[0].text.match(/var tool\\s*=\\s*(\\{[\\s\\S]*?\\n\\});/);\n if (toolMatch) {\n tool = new Function('return ' + toolMatch[1])() as Record<string, unknown>;\n }\n }\n if (!tool) {\n throw new Error(\n `No \"tool\" export found in ${tsPath}. ` + `Add: export const tool: AppToolConfig = { ... };`\n );\n }\n\n return { tool };\n}\n"],"mappings":";;;;;;;;;;;;;AASA,eAAsB,sBAAsB,SAAmD;CAC7F,MAAM,UAAU,MAAM,OAAO;CAC7B,MAAM,eAAe,KAAA,QAAK,QAAQ,QAAQ;CAC1C,MAAM,MAAM,KAAA,QAAK,QAAQ,aAAa;CACtC,MAAM,OAAO,KAAA,QAAK,SAAS,aAAa;CAExC,MAAM,SAAS,MAAM,QAAQ,MAAM;EACjC,OAAO;GACL,UAAU,+BAA+B,KAAK;GAC9C,YAAY;GACZ,QAAQ;GACT;EACD,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,aAAa;EACb,QAAQ;GAAE,QAAQ;GAAO,OAAO;GAAM,QAAQ;GAAO;EACrD,UAAU;EACV,SAAS,CACP;GACE,MAAM;GACN,MAAM,OAAO;IACX,IAAI,gBAAgB;AAGpB,UAAM,UAAU,EAAE,QAAQ,MAAM,GAAG,SAAS;AAC1C,SAAI,KAAK,SAAS,mBAAoB;AACtC,SAAI,CAAC,eAAe;AAClB,sBAAgB;AAChB;;AAEF,YAAO,EAAE,UAAU,MAAM;MACzB;;GAEL,CACF;EACF,CAAC;AAEF,KAAI,CAAC,OAAO,aAAa,OACvB,OAAM,IAAI,MAAM,mCAAmC,UAAU;CAG/D,MAAM,OAAO,OAAO,YAAY,GAAG;CACnC,MAAM,MAA4C,EAAE,SAAS,EAAE,EAAE;AACjE,KAAI,SAAS,UAAU,WAAW,WAAW,KAAK,CAAC,KAAK,IAAI,gBAAgB,EAAE,EAAE;CAEhF,MAAM,WAAW,IAAI,QAAQ;AAC7B,KAAI,CAAC,SACH,OAAM,IAAI,MACR,iCAAiC,QAAQ,uEAE1C;AAGH,QAAO;;;;;;;;;;;;;ACpDT,eAAsB,kBACpB,QAC4C;CAC5C,MAAM,UAAU,MAAM,OAAO;CAC7B,MAAM,eAAe,KAAA,QAAK,QAAQ,OAAO;CACzC,MAAM,MAAM,KAAA,QAAK,QAAQ,aAAa;CACtC,MAAM,OAAO,KAAA,QAAK,SAAS,aAAa;CAExC,MAAM,SAAS,MAAM,QAAQ,MAAM;EACjC,OAAO;GACL,UAAU,2BAA2B,KAAK;GAC1C,YAAY;GACZ,QAAQ;GACT;EACD,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,aAAa;EACb,QAAQ;GAAE,QAAQ;GAAO,OAAO;GAAM,QAAQ;GAAO;EACrD,UAAU;EACV,SAAS,CACP;GACE,MAAM;GACN,MAAM,OAAO;AAGX,UAAM,UAAU,EAAE,QAAQ,MAAM,GAAG,SAAS;AAC1C,SAAI,KAAK,SAAS,mBAAoB;AAEtC,SAAI,CAAC,KAAK,KAAK,WAAW,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,IAAI,CAC1D,QAAO,EAAE,UAAU,MAAM;MAG3B;;GAEL,CACF;EACF,CAAC;AAEF,KAAI,CAAC,OAAO,aAAa,OACvB,OAAM,IAAI,MAAM,+BAA+B,SAAS;CAO1D,MAAM,OAAO,OAAO,YAAY,GAAG,KAChC,QAAQ,mBAAmB,GAAG,CAC9B,QAAQ,iCAAiC,GAAG;CAC/C,IAAI;AACJ,KAAI;AAEF,SADW,IAAI,SAAS,OAAO,iBAAiB,EACrC;SACL;EAGN,MAAM,YAAY,OAAO,YAAY,GAAG,KAAK,MAAM,mCAAmC;AACtF,MAAI,UACF,QAAO,IAAI,SAAS,YAAY,UAAU,GAAG,EAAE;;AAGnD,KAAI,CAAC,KACH,OAAM,IAAI,MACR,6BAA6B,OAAO,oDACrC;AAGH,QAAO,EAAE,MAAM"}
|
|
@@ -1,116 +1,112 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as extractResourceKey, c as findResourceKey, d as getComponentName, f as toPascalCase, l as findSimulationFilesFlat, o as extractSimulationKey, s as findResourceDirs, u as findToolFiles } from "../discovery-Du4LHrih.js";
|
|
2
2
|
import path from "path";
|
|
3
|
+
//#region src/lib/extract-resource.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extract the `resource` named export from a resource .tsx file.
|
|
6
|
+
*
|
|
7
|
+
* Uses esbuild to bundle only the `resource` export, stubbing all of the
|
|
8
|
+
* resource file's own imports (React, components, etc.) so only the static
|
|
9
|
+
* config object is evaluated.
|
|
10
|
+
*/
|
|
3
11
|
async function extractResourceExport(tsxPath) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
`No "resource" export found in ${tsxPath}. Add: export const resource: ResourceConfig = { title: '...', ... };`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return resource;
|
|
12
|
+
const esbuild = await import("esbuild");
|
|
13
|
+
const absolutePath = path.resolve(tsxPath);
|
|
14
|
+
const dir = path.dirname(absolutePath);
|
|
15
|
+
const base = path.basename(absolutePath);
|
|
16
|
+
const result = await esbuild.build({
|
|
17
|
+
stdin: {
|
|
18
|
+
contents: `export { resource } from './${base}';`,
|
|
19
|
+
resolveDir: dir,
|
|
20
|
+
loader: "ts"
|
|
21
|
+
},
|
|
22
|
+
bundle: true,
|
|
23
|
+
write: false,
|
|
24
|
+
format: "cjs",
|
|
25
|
+
treeShaking: true,
|
|
26
|
+
loader: {
|
|
27
|
+
".tsx": "tsx",
|
|
28
|
+
".ts": "ts",
|
|
29
|
+
".jsx": "jsx"
|
|
30
|
+
},
|
|
31
|
+
logLevel: "silent",
|
|
32
|
+
plugins: [{
|
|
33
|
+
name: "externalize-deps",
|
|
34
|
+
setup(build) {
|
|
35
|
+
let entryResolved = false;
|
|
36
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
37
|
+
if (args.kind !== "import-statement") return;
|
|
38
|
+
if (!entryResolved) {
|
|
39
|
+
entryResolved = true;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return { external: true };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}]
|
|
46
|
+
});
|
|
47
|
+
if (!result.outputFiles?.length) throw new Error(`Failed to extract resource from ${tsxPath}`);
|
|
48
|
+
const code = result.outputFiles[0].text;
|
|
49
|
+
const mod = { exports: {} };
|
|
50
|
+
new Function("module", "exports", "require", code)(mod, mod.exports, () => ({}));
|
|
51
|
+
const resource = mod.exports.resource;
|
|
52
|
+
if (!resource) throw new Error(`No "resource" export found in ${tsxPath}. Add: export const resource: ResourceConfig = { title: '...', ... };`);
|
|
53
|
+
return resource;
|
|
50
54
|
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/lib/extract-tool.ts
|
|
57
|
+
/**
|
|
58
|
+
* Extract the `tool` named export from a tool .ts file.
|
|
59
|
+
*
|
|
60
|
+
* Uses esbuild in ESM mode to compile TypeScript and tree-shake to just the
|
|
61
|
+
* `tool` export. ESM tree-shaking drops unused exports (schema, handler) so
|
|
62
|
+
* their dependencies (zod, etc.) are never evaluated.
|
|
63
|
+
*
|
|
64
|
+
* `schema` and `default` handler are loaded at runtime via Vite SSR.
|
|
65
|
+
*/
|
|
51
66
|
async function extractToolExport(tsPath) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (toolMatch) {
|
|
94
|
-
tool = new Function("return " + toolMatch[1])();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (!tool) {
|
|
98
|
-
throw new Error(
|
|
99
|
-
`No "tool" export found in ${tsPath}. Add: export const tool: AppToolConfig = { ... };`
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
return { tool };
|
|
67
|
+
const esbuild = await import("esbuild");
|
|
68
|
+
const absolutePath = path.resolve(tsPath);
|
|
69
|
+
const dir = path.dirname(absolutePath);
|
|
70
|
+
const base = path.basename(absolutePath);
|
|
71
|
+
const result = await esbuild.build({
|
|
72
|
+
stdin: {
|
|
73
|
+
contents: `export { tool } from './${base}';`,
|
|
74
|
+
resolveDir: dir,
|
|
75
|
+
loader: "ts"
|
|
76
|
+
},
|
|
77
|
+
bundle: true,
|
|
78
|
+
write: false,
|
|
79
|
+
format: "esm",
|
|
80
|
+
treeShaking: true,
|
|
81
|
+
loader: {
|
|
82
|
+
".tsx": "tsx",
|
|
83
|
+
".ts": "ts",
|
|
84
|
+
".jsx": "jsx"
|
|
85
|
+
},
|
|
86
|
+
logLevel: "silent",
|
|
87
|
+
plugins: [{
|
|
88
|
+
name: "externalize-node-modules",
|
|
89
|
+
setup(build) {
|
|
90
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
91
|
+
if (args.kind !== "import-statement") return;
|
|
92
|
+
if (!args.path.startsWith(".") && !args.path.startsWith("/")) return { external: true };
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}]
|
|
96
|
+
});
|
|
97
|
+
if (!result.outputFiles?.length) throw new Error(`Failed to extract tool from ${tsPath}`);
|
|
98
|
+
const code = result.outputFiles[0].text.replace(/^import\s+.*$/gm, "").replace(/^export\s*\{[^}]*\}\s*;?\s*$/m, "");
|
|
99
|
+
let tool;
|
|
100
|
+
try {
|
|
101
|
+
tool = new Function(code + "\nreturn tool;")();
|
|
102
|
+
} catch {
|
|
103
|
+
const toolMatch = result.outputFiles[0].text.match(/var tool\s*=\s*(\{[\s\S]*?\n\});/);
|
|
104
|
+
if (toolMatch) tool = new Function("return " + toolMatch[1])();
|
|
105
|
+
}
|
|
106
|
+
if (!tool) throw new Error(`No "tool" export found in ${tsPath}. Add: export const tool: AppToolConfig = { ... };`);
|
|
107
|
+
return { tool };
|
|
103
108
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
extractToolExport,
|
|
109
|
-
g as findResourceDirs,
|
|
110
|
-
h as findResourceKey,
|
|
111
|
-
j as findSimulationFilesFlat,
|
|
112
|
-
k as findToolFiles,
|
|
113
|
-
i as getComponentName,
|
|
114
|
-
t as toPascalCase
|
|
115
|
-
};
|
|
116
|
-
//# sourceMappingURL=discovery-cli.js.map
|
|
109
|
+
//#endregion
|
|
110
|
+
export { extractResourceExport, extractResourceKey, extractSimulationKey, extractToolExport, findResourceDirs, findResourceKey, findSimulationFilesFlat, findToolFiles, getComponentName, toPascalCase };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=discovery-cli.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery-cli.js","sources":["../../src/lib/extract-resource.ts","../../src/lib/extract-tool.ts"],"sourcesContent":["import path from 'path';\n\n/**\n * Extract the `resource` named export from a resource .tsx file.\n *\n * Uses esbuild to bundle only the `resource` export, stubbing all of the\n * resource file's own imports (React, components, etc.) so only the static\n * config object is evaluated.\n */\nexport async function extractResourceExport(tsxPath: string): Promise<Record<string, unknown>> {\n const esbuild = await import('esbuild');\n const absolutePath = path.resolve(tsxPath);\n const dir = path.dirname(absolutePath);\n const base = path.basename(absolutePath);\n\n const result = await esbuild.build({\n stdin: {\n contents: `export { resource } from './${base}';`,\n resolveDir: dir,\n loader: 'ts',\n },\n bundle: true,\n write: false,\n format: 'cjs',\n treeShaking: true,\n loader: { '.tsx': 'tsx', '.ts': 'ts', '.jsx': 'jsx' },\n logLevel: 'silent',\n plugins: [\n {\n name: 'externalize-deps',\n setup(build) {\n let entryResolved = false;\n // Let stdin's import of the resource file resolve normally,\n // but externalize everything the resource file itself imports.\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind !== 'import-statement') return;\n if (!entryResolved) {\n entryResolved = true;\n return;\n }\n return { external: true };\n });\n },\n },\n ],\n });\n\n if (!result.outputFiles?.length) {\n throw new Error(`Failed to extract resource from ${tsxPath}`);\n }\n\n const code = result.outputFiles[0].text;\n const mod: { exports: Record<string, unknown> } = { exports: {} };\n new Function('module', 'exports', 'require', code)(mod, mod.exports, () => ({}));\n\n const resource = mod.exports.resource as Record<string, unknown> | undefined;\n if (!resource) {\n throw new Error(\n `No \"resource\" export found in ${tsxPath}. ` +\n `Add: export const resource: ResourceConfig = { title: '...', ... };`\n );\n }\n\n return resource;\n}\n","import path from 'path';\n\n/**\n * Extract the `tool` named export from a tool .ts file.\n *\n * Uses esbuild in ESM mode to compile TypeScript and tree-shake to just the\n * `tool` export. ESM tree-shaking drops unused exports (schema, handler) so\n * their dependencies (zod, etc.) are never evaluated.\n *\n * `schema` and `default` handler are loaded at runtime via Vite SSR.\n */\nexport async function extractToolExport(\n tsPath: string\n): Promise<{ tool: Record<string, unknown> }> {\n const esbuild = await import('esbuild');\n const absolutePath = path.resolve(tsPath);\n const dir = path.dirname(absolutePath);\n const base = path.basename(absolutePath);\n\n const result = await esbuild.build({\n stdin: {\n contents: `export { tool } from './${base}';`,\n resolveDir: dir,\n loader: 'ts',\n },\n bundle: true,\n write: false,\n format: 'esm',\n treeShaking: true,\n loader: { '.tsx': 'tsx', '.ts': 'ts', '.jsx': 'jsx' },\n logLevel: 'silent',\n plugins: [\n {\n name: 'externalize-node-modules',\n setup(build) {\n // Resolve relative imports normally (resource files, local modules)\n // but externalize everything from node_modules\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind !== 'import-statement') return;\n // Bare specifiers (not starting with . or /) are node_modules\n if (!args.path.startsWith('.') && !args.path.startsWith('/')) {\n return { external: true };\n }\n return undefined;\n });\n },\n },\n ],\n });\n\n if (!result.outputFiles?.length) {\n throw new Error(`Failed to extract tool from ${tsPath}`);\n }\n\n // Strip import statements and export block so we can eval as plain JS.\n // `tool` is pure data (no dependencies), so stripping imports is safe.\n // Other top-level code (schema, etc.) may reference stripped imports but\n // we only need the `tool` variable — errors in other code are caught and ignored.\n const code = result.outputFiles[0].text\n .replace(/^import\\s+.*$/gm, '')\n .replace(/^export\\s*\\{[^}]*\\}\\s*;?\\s*$/m, '');\n let tool: Record<string, unknown> | undefined;\n try {\n const fn = new Function(code + '\\nreturn tool;');\n tool = fn() as Record<string, unknown> | undefined;\n } catch {\n // If other top-level code crashes (e.g. schema using stripped zod),\n // extract just the tool variable declaration and eval that alone.\n const toolMatch = result.outputFiles[0].text.match(/var tool\\s*=\\s*(\\{[\\s\\S]*?\\n\\});/);\n if (toolMatch) {\n tool = new Function('return ' + toolMatch[1])() as Record<string, unknown>;\n }\n }\n if (!tool) {\n throw new Error(\n `No \"tool\" export found in ${tsPath}. ` + `Add: export const tool: AppToolConfig = { ... };`\n );\n }\n\n return { tool };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"discovery-cli.js","names":[],"sources":["../../src/lib/extract-resource.ts","../../src/lib/extract-tool.ts"],"sourcesContent":["import path from 'path';\n\n/**\n * Extract the `resource` named export from a resource .tsx file.\n *\n * Uses esbuild to bundle only the `resource` export, stubbing all of the\n * resource file's own imports (React, components, etc.) so only the static\n * config object is evaluated.\n */\nexport async function extractResourceExport(tsxPath: string): Promise<Record<string, unknown>> {\n const esbuild = await import('esbuild');\n const absolutePath = path.resolve(tsxPath);\n const dir = path.dirname(absolutePath);\n const base = path.basename(absolutePath);\n\n const result = await esbuild.build({\n stdin: {\n contents: `export { resource } from './${base}';`,\n resolveDir: dir,\n loader: 'ts',\n },\n bundle: true,\n write: false,\n format: 'cjs',\n treeShaking: true,\n loader: { '.tsx': 'tsx', '.ts': 'ts', '.jsx': 'jsx' },\n logLevel: 'silent',\n plugins: [\n {\n name: 'externalize-deps',\n setup(build) {\n let entryResolved = false;\n // Let stdin's import of the resource file resolve normally,\n // but externalize everything the resource file itself imports.\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind !== 'import-statement') return;\n if (!entryResolved) {\n entryResolved = true;\n return;\n }\n return { external: true };\n });\n },\n },\n ],\n });\n\n if (!result.outputFiles?.length) {\n throw new Error(`Failed to extract resource from ${tsxPath}`);\n }\n\n const code = result.outputFiles[0].text;\n const mod: { exports: Record<string, unknown> } = { exports: {} };\n new Function('module', 'exports', 'require', code)(mod, mod.exports, () => ({}));\n\n const resource = mod.exports.resource as Record<string, unknown> | undefined;\n if (!resource) {\n throw new Error(\n `No \"resource\" export found in ${tsxPath}. ` +\n `Add: export const resource: ResourceConfig = { title: '...', ... };`\n );\n }\n\n return resource;\n}\n","import path from 'path';\n\n/**\n * Extract the `tool` named export from a tool .ts file.\n *\n * Uses esbuild in ESM mode to compile TypeScript and tree-shake to just the\n * `tool` export. ESM tree-shaking drops unused exports (schema, handler) so\n * their dependencies (zod, etc.) are never evaluated.\n *\n * `schema` and `default` handler are loaded at runtime via Vite SSR.\n */\nexport async function extractToolExport(\n tsPath: string\n): Promise<{ tool: Record<string, unknown> }> {\n const esbuild = await import('esbuild');\n const absolutePath = path.resolve(tsPath);\n const dir = path.dirname(absolutePath);\n const base = path.basename(absolutePath);\n\n const result = await esbuild.build({\n stdin: {\n contents: `export { tool } from './${base}';`,\n resolveDir: dir,\n loader: 'ts',\n },\n bundle: true,\n write: false,\n format: 'esm',\n treeShaking: true,\n loader: { '.tsx': 'tsx', '.ts': 'ts', '.jsx': 'jsx' },\n logLevel: 'silent',\n plugins: [\n {\n name: 'externalize-node-modules',\n setup(build) {\n // Resolve relative imports normally (resource files, local modules)\n // but externalize everything from node_modules\n build.onResolve({ filter: /.*/ }, (args) => {\n if (args.kind !== 'import-statement') return;\n // Bare specifiers (not starting with . or /) are node_modules\n if (!args.path.startsWith('.') && !args.path.startsWith('/')) {\n return { external: true };\n }\n return undefined;\n });\n },\n },\n ],\n });\n\n if (!result.outputFiles?.length) {\n throw new Error(`Failed to extract tool from ${tsPath}`);\n }\n\n // Strip import statements and export block so we can eval as plain JS.\n // `tool` is pure data (no dependencies), so stripping imports is safe.\n // Other top-level code (schema, etc.) may reference stripped imports but\n // we only need the `tool` variable — errors in other code are caught and ignored.\n const code = result.outputFiles[0].text\n .replace(/^import\\s+.*$/gm, '')\n .replace(/^export\\s*\\{[^}]*\\}\\s*;?\\s*$/m, '');\n let tool: Record<string, unknown> | undefined;\n try {\n const fn = new Function(code + '\\nreturn tool;');\n tool = fn() as Record<string, unknown> | undefined;\n } catch {\n // If other top-level code crashes (e.g. schema using stripped zod),\n // extract just the tool variable declaration and eval that alone.\n const toolMatch = result.outputFiles[0].text.match(/var tool\\s*=\\s*(\\{[\\s\\S]*?\\n\\});/);\n if (toolMatch) {\n tool = new Function('return ' + toolMatch[1])() as Record<string, unknown>;\n }\n }\n if (!tool) {\n throw new Error(\n `No \"tool\" export found in ${tsPath}. ` + `Add: export const tool: AppToolConfig = { ... };`\n );\n }\n\n return { tool };\n}\n"],"mappings":";;;;;;;;;;AASA,eAAsB,sBAAsB,SAAmD;CAC7F,MAAM,UAAU,MAAM,OAAO;CAC7B,MAAM,eAAe,KAAK,QAAQ,QAAQ;CAC1C,MAAM,MAAM,KAAK,QAAQ,aAAa;CACtC,MAAM,OAAO,KAAK,SAAS,aAAa;CAExC,MAAM,SAAS,MAAM,QAAQ,MAAM;EACjC,OAAO;GACL,UAAU,+BAA+B,KAAK;GAC9C,YAAY;GACZ,QAAQ;GACT;EACD,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,aAAa;EACb,QAAQ;GAAE,QAAQ;GAAO,OAAO;GAAM,QAAQ;GAAO;EACrD,UAAU;EACV,SAAS,CACP;GACE,MAAM;GACN,MAAM,OAAO;IACX,IAAI,gBAAgB;AAGpB,UAAM,UAAU,EAAE,QAAQ,MAAM,GAAG,SAAS;AAC1C,SAAI,KAAK,SAAS,mBAAoB;AACtC,SAAI,CAAC,eAAe;AAClB,sBAAgB;AAChB;;AAEF,YAAO,EAAE,UAAU,MAAM;MACzB;;GAEL,CACF;EACF,CAAC;AAEF,KAAI,CAAC,OAAO,aAAa,OACvB,OAAM,IAAI,MAAM,mCAAmC,UAAU;CAG/D,MAAM,OAAO,OAAO,YAAY,GAAG;CACnC,MAAM,MAA4C,EAAE,SAAS,EAAE,EAAE;AACjE,KAAI,SAAS,UAAU,WAAW,WAAW,KAAK,CAAC,KAAK,IAAI,gBAAgB,EAAE,EAAE;CAEhF,MAAM,WAAW,IAAI,QAAQ;AAC7B,KAAI,CAAC,SACH,OAAM,IAAI,MACR,iCAAiC,QAAQ,uEAE1C;AAGH,QAAO;;;;;;;;;;;;;ACpDT,eAAsB,kBACpB,QAC4C;CAC5C,MAAM,UAAU,MAAM,OAAO;CAC7B,MAAM,eAAe,KAAK,QAAQ,OAAO;CACzC,MAAM,MAAM,KAAK,QAAQ,aAAa;CACtC,MAAM,OAAO,KAAK,SAAS,aAAa;CAExC,MAAM,SAAS,MAAM,QAAQ,MAAM;EACjC,OAAO;GACL,UAAU,2BAA2B,KAAK;GAC1C,YAAY;GACZ,QAAQ;GACT;EACD,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,aAAa;EACb,QAAQ;GAAE,QAAQ;GAAO,OAAO;GAAM,QAAQ;GAAO;EACrD,UAAU;EACV,SAAS,CACP;GACE,MAAM;GACN,MAAM,OAAO;AAGX,UAAM,UAAU,EAAE,QAAQ,MAAM,GAAG,SAAS;AAC1C,SAAI,KAAK,SAAS,mBAAoB;AAEtC,SAAI,CAAC,KAAK,KAAK,WAAW,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,IAAI,CAC1D,QAAO,EAAE,UAAU,MAAM;MAG3B;;GAEL,CACF;EACF,CAAC;AAEF,KAAI,CAAC,OAAO,aAAa,OACvB,OAAM,IAAI,MAAM,+BAA+B,SAAS;CAO1D,MAAM,OAAO,OAAO,YAAY,GAAG,KAChC,QAAQ,mBAAmB,GAAG,CAC9B,QAAQ,iCAAiC,GAAG;CAC/C,IAAI;AACJ,KAAI;AAEF,SADW,IAAI,SAAS,OAAO,iBAAiB,EACrC;SACL;EAGN,MAAM,YAAY,OAAO,YAAY,GAAG,KAAK,MAAM,mCAAmC;AACtF,MAAI,UACF,QAAO,IAAI,SAAS,YAAY,UAAU,GAAG,EAAE;;AAGnD,KAAI,CAAC,KACH,OAAM,IAAI,MACR,6BAA6B,OAAO,oDACrC;AAGH,QAAO,EAAE,MAAM"}
|