@finalai/agent-definition 0.1.0
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.
Potentially problematic release.
This version of @finalai/agent-definition might be problematic. Click here for more details.
- package/README.md +16 -0
- package/THIRD_PARTY_NOTICES.md +303 -0
- package/dist/compiler-assets/chunk-2CZRHOLL.ts +10 -0
- package/dist/compiler-assets/chunk-32O3ODZE.ts +39 -0
- package/dist/compiler-assets/chunk-5BK6FVRE.ts +75 -0
- package/dist/compiler-assets/chunk-6WR3PGNF.ts +0 -0
- package/dist/compiler-assets/chunk-7QP2CKPI.ts +30 -0
- package/dist/compiler-assets/chunk-7VSSVZM4.ts +55 -0
- package/dist/compiler-assets/chunk-7WGYG73V.ts +42 -0
- package/dist/compiler-assets/chunk-BLB6JGLO.ts +481 -0
- package/dist/compiler-assets/chunk-CWWRTRWW.ts +76 -0
- package/dist/compiler-assets/chunk-EVQIK62B.ts +188 -0
- package/dist/compiler-assets/chunk-GNR7XBPN.ts +3364 -0
- package/dist/compiler-assets/chunk-GTUZOATD.ts +10 -0
- package/dist/compiler-assets/chunk-HFS4KLEL.ts +10 -0
- package/dist/compiler-assets/chunk-HGW4YHAY.ts +6865 -0
- package/dist/compiler-assets/chunk-HNPUTP35.ts +172 -0
- package/dist/compiler-assets/chunk-JIPNTA56.ts +59 -0
- package/dist/compiler-assets/chunk-JNJE72EH.ts +10 -0
- package/dist/compiler-assets/chunk-JPY4L2UJ.ts +349 -0
- package/dist/compiler-assets/chunk-JTGTLYDT.ts +0 -0
- package/dist/compiler-assets/chunk-LUSAAV4L.ts +33 -0
- package/dist/compiler-assets/chunk-MZMSKIKU.ts +472 -0
- package/dist/compiler-assets/chunk-NMYHO2QN.ts +25 -0
- package/dist/compiler-assets/chunk-NYTOYKKF.ts +28 -0
- package/dist/compiler-assets/chunk-OWC6SFFF.ts +295 -0
- package/dist/compiler-assets/chunk-QMKWAFVZ.ts +59 -0
- package/dist/compiler-assets/chunk-QMWTDPNT.ts +79 -0
- package/dist/compiler-assets/chunk-RWUIMTBI.ts +13 -0
- package/dist/compiler-assets/chunk-SKTNMUO7.ts +64 -0
- package/dist/compiler-assets/chunk-T6WG4L4M.ts +19 -0
- package/dist/compiler-assets/chunk-TATN3PYK.ts +81 -0
- package/dist/compiler-assets/chunk-VHXHUU7L.ts +16 -0
- package/dist/compiler-assets/chunk-WMXMVFHM.ts +121 -0
- package/dist/compiler-assets/chunk-XHKPWT3G.ts +55 -0
- package/dist/compiler-assets/chunk-ZDLVA6XF.ts +476 -0
- package/dist/compiler-assets/src/authoring/agent.ts +10 -0
- package/dist/compiler-assets/src/authoring/approval.ts +19 -0
- package/dist/compiler-assets/src/authoring/brand.ts +23 -0
- package/dist/compiler-assets/src/authoring/channels.ts +26 -0
- package/dist/compiler-assets/src/authoring/connections.ts +10 -0
- package/dist/compiler-assets/src/authoring/context.ts +7 -0
- package/dist/compiler-assets/src/authoring/credentials.ts +21 -0
- package/dist/compiler-assets/src/authoring/dynamic.ts +10 -0
- package/dist/compiler-assets/src/authoring/harness.ts +17 -0
- package/dist/compiler-assets/src/authoring/hooks.ts +28 -0
- package/dist/compiler-assets/src/authoring/index.ts +110 -0
- package/dist/compiler-assets/src/authoring/instructions.ts +14 -0
- package/dist/compiler-assets/src/authoring/sandbox.ts +25 -0
- package/dist/compiler-assets/src/authoring/schedules.ts +10 -0
- package/dist/compiler-assets/src/authoring/skills.ts +10 -0
- package/dist/compiler-assets/src/authoring/tools.ts +23 -0
- package/dist/compiler-assets/src/compatibility.ts +14810 -0
- package/dist/compiler-assets/src/compiler/evaluate-child.mjs +77 -0
- package/dist/compiler-assets/src/index.ts +195 -0
- package/dist/compiler-assets/src/manifest.ts +72 -0
- package/dist/compiler-assets/src/resolve.ts +19 -0
- package/dist/compiler-assets/src/runtime/bundle.ts +72 -0
- package/dist/compiler-assets/src/runtime/describe.ts +31 -0
- package/dist/compiler-assets/src/runtime/described.ts +142 -0
- package/dist/compiler-assets/src/runtime/isolate.ts +28 -0
- package/dist/compiler-assets/src/runtime/layout.ts +15 -0
- package/dist/compiler-assets/src/runtime/lower.ts +52 -0
- package/dist/compiler-assets/src/runtime/schema-validation.ts +21 -0
- package/dist/compiler-assets/src/runtime/values.ts +38 -0
- package/dist/modules/authoring/agent.d.mts +22 -0
- package/dist/modules/authoring/agent.mjs +6 -0
- package/dist/modules/authoring/agent.mjs.map +7 -0
- package/dist/modules/authoring/approval.d.mts +17 -0
- package/dist/modules/authoring/approval.mjs +42 -0
- package/dist/modules/authoring/approval.mjs.map +7 -0
- package/dist/modules/authoring/brand.d.mts +27 -0
- package/dist/modules/authoring/brand.mjs +51 -0
- package/dist/modules/authoring/brand.mjs.map +7 -0
- package/dist/modules/authoring/channels.d.mts +41 -0
- package/dist/modules/authoring/channels.mjs +65 -0
- package/dist/modules/authoring/channels.mjs.map +7 -0
- package/dist/modules/authoring/connections.d.mts +23 -0
- package/dist/modules/authoring/connections.mjs +6 -0
- package/dist/modules/authoring/connections.mjs.map +7 -0
- package/dist/modules/authoring/context.d.mts +83 -0
- package/dist/modules/authoring/context.mjs +12 -0
- package/dist/modules/authoring/context.mjs.map +7 -0
- package/dist/modules/authoring/credentials.d.mts +10 -0
- package/dist/modules/authoring/credentials.mjs +31 -0
- package/dist/modules/authoring/credentials.mjs.map +7 -0
- package/dist/modules/authoring/dynamic.d.mts +30 -0
- package/dist/modules/authoring/dynamic.mjs +15 -0
- package/dist/modules/authoring/dynamic.mjs.map +7 -0
- package/dist/modules/authoring/harness.d.mts +85 -0
- package/dist/modules/authoring/harness.mjs +55 -0
- package/dist/modules/authoring/harness.mjs.map +7 -0
- package/dist/modules/authoring/hooks.d.mts +120 -0
- package/dist/modules/authoring/hooks.mjs +72 -0
- package/dist/modules/authoring/hooks.mjs.map +7 -0
- package/dist/modules/authoring/index.d.mts +27 -0
- package/dist/modules/authoring/index.mjs +63 -0
- package/dist/modules/authoring/index.mjs.map +7 -0
- package/dist/modules/authoring/instructions.d.mts +13 -0
- package/dist/modules/authoring/instructions.mjs +15 -0
- package/dist/modules/authoring/instructions.mjs.map +7 -0
- package/dist/modules/authoring/sandbox.d.mts +21 -0
- package/dist/modules/authoring/sandbox.mjs +13 -0
- package/dist/modules/authoring/sandbox.mjs.map +7 -0
- package/dist/modules/authoring/schedules.d.mts +8 -0
- package/dist/modules/authoring/schedules.mjs +6 -0
- package/dist/modules/authoring/schedules.mjs.map +7 -0
- package/dist/modules/authoring/skills.d.mts +8 -0
- package/dist/modules/authoring/skills.mjs +6 -0
- package/dist/modules/authoring/skills.mjs.map +7 -0
- package/dist/modules/authoring/tools.d.mts +80 -0
- package/dist/modules/authoring/tools.mjs +70 -0
- package/dist/modules/authoring/tools.mjs.map +7 -0
- package/dist/modules/compatibility.d.mts +36 -0
- package/dist/modules/compatibility.mjs +536 -0
- package/dist/modules/compatibility.mjs.map +7 -0
- package/dist/modules/compiler/assemble.d.mts +30 -0
- package/dist/modules/compiler/assemble.mjs +923 -0
- package/dist/modules/compiler/assemble.mjs.map +7 -0
- package/dist/modules/compiler/bundle.d.mts +22 -0
- package/dist/modules/compiler/bundle.mjs +385 -0
- package/dist/modules/compiler/bundle.mjs.map +7 -0
- package/dist/modules/compiler/diagnostics.d.mts +40 -0
- package/dist/modules/compiler/diagnostics.mjs +38 -0
- package/dist/modules/compiler/diagnostics.mjs.map +7 -0
- package/dist/modules/compiler/discovery.d.mts +36 -0
- package/dist/modules/compiler/discovery.mjs +158 -0
- package/dist/modules/compiler/discovery.mjs.map +7 -0
- package/dist/modules/compiler/evaluate.d.mts +13 -0
- package/dist/modules/compiler/evaluate.mjs +194 -0
- package/dist/modules/compiler/evaluate.mjs.map +7 -0
- package/dist/modules/compiler/files.d.mts +19 -0
- package/dist/modules/compiler/files.mjs +90 -0
- package/dist/modules/compiler/files.mjs.map +7 -0
- package/dist/modules/compiler/frontmatter.d.mts +9 -0
- package/dist/modules/compiler/frontmatter.mjs +34 -0
- package/dist/modules/compiler/frontmatter.mjs.map +7 -0
- package/dist/modules/compiler/index.d.mts +49 -0
- package/dist/modules/compiler/index.mjs +244 -0
- package/dist/modules/compiler/index.mjs.map +7 -0
- package/dist/modules/compiler/load.d.mts +8 -0
- package/dist/modules/compiler/load.mjs +45 -0
- package/dist/modules/compiler/load.mjs.map +7 -0
- package/dist/modules/compiler/local-isolate.d.mts +20 -0
- package/dist/modules/compiler/local-isolate.mjs +93 -0
- package/dist/modules/compiler/local-isolate.mjs.map +7 -0
- package/dist/modules/compiler/packages.d.mts +66 -0
- package/dist/modules/compiler/packages.mjs +307 -0
- package/dist/modules/compiler/packages.mjs.map +7 -0
- package/dist/modules/index.d.mts +7 -0
- package/dist/modules/index.mjs +25 -0
- package/dist/modules/index.mjs.map +7 -0
- package/dist/modules/manifest.d.mts +2 -0
- package/dist/modules/manifest.mjs +67 -0
- package/dist/modules/manifest.mjs.map +7 -0
- package/dist/modules/resolve.d.mts +24 -0
- package/dist/modules/resolve.mjs +176 -0
- package/dist/modules/resolve.mjs.map +7 -0
- package/dist/modules/runtime/bundle.d.mts +12 -0
- package/dist/modules/runtime/bundle.mjs +48 -0
- package/dist/modules/runtime/bundle.mjs.map +7 -0
- package/dist/modules/runtime/describe.d.mts +19 -0
- package/dist/modules/runtime/describe.mjs +471 -0
- package/dist/modules/runtime/describe.mjs.map +7 -0
- package/dist/modules/runtime/described.d.mts +376 -0
- package/dist/modules/runtime/described.mjs +116 -0
- package/dist/modules/runtime/described.mjs.map +7 -0
- package/dist/modules/runtime/isolate.d.mts +70 -0
- package/dist/modules/runtime/isolate.mjs +454 -0
- package/dist/modules/runtime/isolate.mjs.map +7 -0
- package/dist/modules/runtime/layout.d.mts +21 -0
- package/dist/modules/runtime/layout.mjs +24 -0
- package/dist/modules/runtime/layout.mjs.map +7 -0
- package/dist/modules/runtime/lower.d.mts +73 -0
- package/dist/modules/runtime/lower.mjs +463 -0
- package/dist/modules/runtime/lower.mjs.map +7 -0
- package/dist/modules/runtime/schema-validation.d.mts +21 -0
- package/dist/modules/runtime/schema-validation.mjs +238 -0
- package/dist/modules/runtime/schema-validation.mjs.map +7 -0
- package/dist/modules/runtime/values.d.mts +20 -0
- package/dist/modules/runtime/values.mjs +48 -0
- package/dist/modules/runtime/values.mjs.map +7 -0
- package/fixtures/acme-fleet/agent/agent.ts +74 -0
- package/fixtures/acme-fleet/agent/instructions.md +1 -0
- package/fixtures/assistant/agent/agent.ts +16 -0
- package/fixtures/assistant/agent/instructions.md +1 -0
- package/fixtures/assistant/agent/tools/current_time.ts +9 -0
- package/fixtures/assistant-with-tools/agent/agent.ts +16 -0
- package/fixtures/assistant-with-tools/agent/instructions.md +1 -0
- package/fixtures/assistant-with-tools/agent/tools/current_time.ts +9 -0
- package/fixtures/final-connection/agent/agent.ts +15 -0
- package/fixtures/final-connection/agent/connections/final.ts +9 -0
- package/fixtures/release-scout/agent/agent.ts +22 -0
- package/fixtures/release-scout/agent/channels/github-signature.ts +27 -0
- package/fixtures/release-scout/agent/channels/github.ts +38 -0
- package/fixtures/release-scout/agent/connections/linear.ts +9 -0
- package/fixtures/release-scout/agent/hooks/audit.ts +24 -0
- package/fixtures/release-scout/agent/instructions/org-context.ts +26 -0
- package/fixtures/release-scout/agent/instructions.md +2 -0
- package/fixtures/release-scout/agent/sandbox.ts +20 -0
- package/fixtures/release-scout/agent/schedules/daily-digest.md +7 -0
- package/fixtures/release-scout/agent/skills/triage/SKILL.md +8 -0
- package/fixtures/release-scout/agent/skills/triage/checklist.md +3 -0
- package/fixtures/release-scout/agent/tools/lookup_release_notes.ts +24 -0
- package/fixtures/tsconfig.json +5 -0
- package/package.json +94 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readdir, readFile, realpath } from "node:fs/promises";
|
|
2
|
+
import { join, posix, sep } from "node:path";
|
|
3
|
+
const MAX_FILES = 400;
|
|
4
|
+
const MAX_DEPTH = 10;
|
|
5
|
+
const MAX_FILE_BYTES = 512e3;
|
|
6
|
+
const IGNORED_NAME = (name) => name.startsWith(".") || name === "node_modules" || name === "__tests__" || /\.(test|spec)\.[cm]?[jt]sx?$/.test(name);
|
|
7
|
+
const isResourcePath = (path) => path.startsWith("workspace/") || path.startsWith("skills/");
|
|
8
|
+
const ignoredResourceName = (name) => name === ".git" || name === "node_modules" || name === ".DS_Store" || name.startsWith("._") || name === ".env" || name.startsWith(".env.") && ![".env.example", ".env.template"].includes(name);
|
|
9
|
+
const readAgentDirectory = async (directory) => {
|
|
10
|
+
const root = await realpath(directory);
|
|
11
|
+
const files = {};
|
|
12
|
+
let count = 0;
|
|
13
|
+
const walk = async (relative, depth) => {
|
|
14
|
+
if (depth > MAX_DEPTH) throw new Error("Agent directory nesting is too deep");
|
|
15
|
+
const absolute = relative.length === 0 ? root : join(root, ...relative.split("/"));
|
|
16
|
+
const children = await readdir(absolute, { withFileTypes: true });
|
|
17
|
+
for (const child of children.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
18
|
+
const path = relative.length === 0 ? child.name : `${relative}/${child.name}`;
|
|
19
|
+
if (isResourcePath(path) ? ignoredResourceName(child.name) : IGNORED_NAME(child.name))
|
|
20
|
+
continue;
|
|
21
|
+
const target = await realpath(join(absolute, child.name));
|
|
22
|
+
if (target !== root && !target.startsWith(`${root}${sep}`)) {
|
|
23
|
+
throw new Error(`${path} leaves the agent directory`);
|
|
24
|
+
}
|
|
25
|
+
if (child.isDirectory() || child.isSymbolicLink() && await readdir(target).then(
|
|
26
|
+
() => true,
|
|
27
|
+
() => false
|
|
28
|
+
)) {
|
|
29
|
+
await walk(path, depth + 1);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
count += 1;
|
|
33
|
+
if (count > MAX_FILES) throw new Error(`Agent directory has more than ${MAX_FILES} files`);
|
|
34
|
+
const bytes = await readFile(target);
|
|
35
|
+
if (bytes.byteLength > MAX_FILE_BYTES)
|
|
36
|
+
throw new Error(`${path} is larger than ${MAX_FILE_BYTES} bytes`);
|
|
37
|
+
let text;
|
|
38
|
+
try {
|
|
39
|
+
text = new TextDecoder("utf-8", { fatal: isResourcePath(path), ignoreBOM: true }).decode(
|
|
40
|
+
bytes
|
|
41
|
+
);
|
|
42
|
+
} catch {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`${path} must contain valid UTF-8 text; binary workspace and skill resources are unsupported`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
files[path] = text;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
await walk("", 0);
|
|
51
|
+
return { root, files };
|
|
52
|
+
};
|
|
53
|
+
const normalizeFiles = (input, options = {}) => {
|
|
54
|
+
const files = {};
|
|
55
|
+
const problems = [];
|
|
56
|
+
for (const [rawPath, content] of Object.entries(input)) {
|
|
57
|
+
const path = posix.normalize(rawPath.replaceAll("\\", "/")).replace(/^\.\//, "");
|
|
58
|
+
if (path.startsWith("/") || path === ".." || path.startsWith("../") || path.length === 0) {
|
|
59
|
+
problems.push({
|
|
60
|
+
path: rawPath,
|
|
61
|
+
message: "file paths must be relative and stay inside the agent directory"
|
|
62
|
+
});
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (path.split("/").some(isResourcePath(path) ? ignoredResourceName : IGNORED_NAME)) continue;
|
|
66
|
+
if (options.enforceSizeLimits !== false && Buffer.byteLength(content) > MAX_FILE_BYTES) {
|
|
67
|
+
problems.push({ path, message: `larger than ${MAX_FILE_BYTES} bytes` });
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
files[path] = content;
|
|
71
|
+
}
|
|
72
|
+
if (options.enforceSizeLimits !== false && Object.keys(files).length > MAX_FILES) {
|
|
73
|
+
problems.push({ path: ".", message: `more than ${MAX_FILES} files` });
|
|
74
|
+
}
|
|
75
|
+
return { files, problems };
|
|
76
|
+
};
|
|
77
|
+
const preparationFiles = (files) => Object.fromEntries(
|
|
78
|
+
Object.entries(files).filter(
|
|
79
|
+
([path]) => path.startsWith("workspace/") || path.startsWith("skills/")
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
export {
|
|
83
|
+
MAX_DEPTH,
|
|
84
|
+
MAX_FILES,
|
|
85
|
+
MAX_FILE_BYTES,
|
|
86
|
+
normalizeFiles,
|
|
87
|
+
preparationFiles,
|
|
88
|
+
readAgentDirectory
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=files.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/compiler/files.ts"],
|
|
4
|
+
"sourcesContent": ["import { readdir, readFile, realpath } from 'node:fs/promises';\nimport { join, posix, sep } from 'node:path';\n\nexport const MAX_FILES = 400;\nexport const MAX_DEPTH = 10;\nexport const MAX_FILE_BYTES = 512_000;\n\nconst IGNORED_NAME = (name: string): boolean =>\n name.startsWith('.') ||\n name === 'node_modules' ||\n name === '__tests__' ||\n /\\.(test|spec)\\.[cm]?[jt]sx?$/.test(name);\nconst isResourcePath = (path: string): boolean =>\n path.startsWith('workspace/') || path.startsWith('skills/');\nconst ignoredResourceName = (name: string): boolean =>\n name === '.git' ||\n name === 'node_modules' ||\n name === '.DS_Store' ||\n name.startsWith('._') ||\n name === '.env' ||\n (name.startsWith('.env.') && !['.env.example', '.env.template'].includes(name));\n\nexport interface DirectoryFilesIface {\n root: string;\n files: Record<string, string>;\n}\n\n// Reads an agent directory into a path \u2192 text map (directory-relative,\n// forward slashes). Symlinks that leave the directory are rejected.\nexport const readAgentDirectory = async (directory: string): Promise<DirectoryFilesIface> => {\n const root = await realpath(directory);\n const files: Record<string, string> = {};\n let count = 0;\n const walk = async (relative: string, depth: number): Promise<void> => {\n if (depth > MAX_DEPTH) throw new Error('Agent directory nesting is too deep');\n const absolute = relative.length === 0 ? root : join(root, ...relative.split('/'));\n const children = await readdir(absolute, { withFileTypes: true });\n for (const child of children.toSorted((a, b) => a.name.localeCompare(b.name))) {\n const path = relative.length === 0 ? child.name : `${relative}/${child.name}`;\n if (isResourcePath(path) ? ignoredResourceName(child.name) : IGNORED_NAME(child.name))\n continue;\n const target = await realpath(join(absolute, child.name));\n if (target !== root && !target.startsWith(`${root}${sep}`)) {\n throw new Error(`${path} leaves the agent directory`);\n }\n if (\n child.isDirectory() ||\n (child.isSymbolicLink() &&\n (await readdir(target).then(\n () => true,\n () => false,\n )))\n ) {\n await walk(path, depth + 1);\n continue;\n }\n count += 1;\n if (count > MAX_FILES) throw new Error(`Agent directory has more than ${MAX_FILES} files`);\n const bytes = await readFile(target);\n if (bytes.byteLength > MAX_FILE_BYTES)\n throw new Error(`${path} is larger than ${MAX_FILE_BYTES} bytes`);\n let text: string;\n try {\n text = new TextDecoder('utf-8', { fatal: isResourcePath(path), ignoreBOM: true }).decode(\n bytes,\n );\n } catch {\n throw new Error(\n `${path} must contain valid UTF-8 text; binary workspace and skill resources are unsupported`,\n );\n }\n files[path] = text;\n }\n };\n await walk('', 0);\n return { root, files };\n};\n\nexport interface NormalizedFilesIface {\n files: Record<string, string>;\n problems: { path: string; message: string }[];\n}\n\n// Normalizes a caller-supplied file map: forward slashes, no leading './',\n// nothing outside the directory, ignored names dropped.\nexport const normalizeFiles = (\n input: Record<string, string>,\n options: { enforceSizeLimits?: boolean } = {},\n): NormalizedFilesIface => {\n const files: Record<string, string> = {};\n const problems: { path: string; message: string }[] = [];\n for (const [rawPath, content] of Object.entries(input)) {\n const path = posix.normalize(rawPath.replaceAll('\\\\', '/')).replace(/^\\.\\//, '');\n if (path.startsWith('/') || path === '..' || path.startsWith('../') || path.length === 0) {\n problems.push({\n path: rawPath,\n message: 'file paths must be relative and stay inside the agent directory',\n });\n continue;\n }\n if (path.split('/').some(isResourcePath(path) ? ignoredResourceName : IGNORED_NAME)) continue;\n if (options.enforceSizeLimits !== false && Buffer.byteLength(content) > MAX_FILE_BYTES) {\n problems.push({ path, message: `larger than ${MAX_FILE_BYTES} bytes` });\n continue;\n }\n files[path] = content;\n }\n if (options.enforceSizeLimits !== false && Object.keys(files).length > MAX_FILES) {\n problems.push({ path: '.', message: `more than ${MAX_FILES} files` });\n }\n return { files, problems };\n};\n\nexport const preparationFiles = (files: Record<string, string>): Record<string, string> =>\n Object.fromEntries(\n Object.entries(files).filter(\n ([path]) => path.startsWith('workspace/') || path.startsWith('skills/'),\n ),\n );\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,UAAU,gBAAgB;AAC5C,SAAS,MAAM,OAAO,WAAW;AAE1B,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,iBAAiB;AAE9B,MAAM,eAAe,CAAC,SACpB,KAAK,WAAW,GAAG,KACnB,SAAS,kBACT,SAAS,eACT,+BAA+B,KAAK,IAAI;AAC1C,MAAM,iBAAiB,CAAC,SACtB,KAAK,WAAW,YAAY,KAAK,KAAK,WAAW,SAAS;AAC5D,MAAM,sBAAsB,CAAC,SAC3B,SAAS,UACT,SAAS,kBACT,SAAS,eACT,KAAK,WAAW,IAAI,KACpB,SAAS,UACR,KAAK,WAAW,OAAO,KAAK,CAAC,CAAC,gBAAgB,eAAe,EAAE,SAAS,IAAI;AASxE,MAAM,qBAAqB,OAAO,cAAoD;AAC3F,QAAM,OAAO,MAAM,SAAS,SAAS;AACrC,QAAM,QAAgC,CAAC;AACvC,MAAI,QAAQ;AACZ,QAAM,OAAO,OAAO,UAAkB,UAAiC;AACrE,QAAI,QAAQ,UAAW,OAAM,IAAI,MAAM,qCAAqC;AAC5E,UAAM,WAAW,SAAS,WAAW,IAAI,OAAO,KAAK,MAAM,GAAG,SAAS,MAAM,GAAG,CAAC;AACjF,UAAM,WAAW,MAAM,QAAQ,UAAU,EAAE,eAAe,KAAK,CAAC;AAChE,eAAW,SAAS,SAAS,SAAS,CAAC,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC,GAAG;AAC7E,YAAM,OAAO,SAAS,WAAW,IAAI,MAAM,OAAO,GAAG,QAAQ,IAAI,MAAM,IAAI;AAC3E,UAAI,eAAe,IAAI,IAAI,oBAAoB,MAAM,IAAI,IAAI,aAAa,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,WAAW,GAAG;AACxF,eAAS,KAAK;AAAA,QACZ,MAAM;AAAA,QACN,SAAS;AAAA,MACX,CAAC;AACD;AAAA,IACF;AACA,QAAI,KAAK,MAAM,GAAG,EAAE,KAAK,eAAe,IAAI,IAAI,sBAAsB,YAAY,EAAG;AACrF,QAAI,QAAQ,sBAAsB,SAAS,OAAO,WAAW,OAAO,IAAI,gBAAgB;AACtF,eAAS,KAAK,EAAE,MAAM,SAAS,eAAe,cAAc,SAAS,CAAC;AACtE;AAAA,IACF;AACA,UAAM,IAAI,IAAI;AAAA,EAChB;AACA,MAAI,QAAQ,sBAAsB,SAAS,OAAO,KAAK,KAAK,EAAE,SAAS,WAAW;AAChF,aAAS,KAAK,EAAE,MAAM,KAAK,SAAS,aAAa,SAAS,SAAS,CAAC;AAAA,EACtE;AACA,SAAO,EAAE,OAAO,SAAS;AAC3B;AAEO,MAAM,mBAAmB,CAAC,UAC/B,OAAO;AAAA,EACL,OAAO,QAAQ,KAAK,EAAE;AAAA,IACpB,CAAC,CAAC,IAAI,MAAM,KAAK,WAAW,YAAY,KAAK,KAAK,WAAW,SAAS;AAAA,EACxE;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type JsonObject } from '@finalai/agent-provider';
|
|
2
|
+
export interface FrontMatterIface {
|
|
3
|
+
data: JsonObject;
|
|
4
|
+
body: string;
|
|
5
|
+
error: string | null;
|
|
6
|
+
}
|
|
7
|
+
export declare const parseFrontMatter: (text: string) => FrontMatterIface;
|
|
8
|
+
export declare const frontMatterString: (data: JsonObject, key: string) => string | null;
|
|
9
|
+
export declare const firstParagraphLine: (markdown: string) => string | null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsonObjectSchema } from "@finalai/agent-provider";
|
|
2
|
+
import { parse } from "yaml";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
const parseFrontMatter = (text) => {
|
|
5
|
+
const normalized = text.replace(/^/, "").replaceAll("\r\n", "\n");
|
|
6
|
+
if (!normalized.startsWith("---\n")) return { data: {}, body: normalized, error: null };
|
|
7
|
+
const end = normalized.indexOf("\n---", 4);
|
|
8
|
+
if (end < 0) return { data: {}, body: normalized, error: "front matter is not closed with ---" };
|
|
9
|
+
const yamlText = normalized.slice(4, end);
|
|
10
|
+
const rest = normalized.slice(end + 4).replace(/^[^\n]*\n?/, "");
|
|
11
|
+
let data;
|
|
12
|
+
try {
|
|
13
|
+
data = parse(yamlText);
|
|
14
|
+
} catch (cause) {
|
|
15
|
+
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
16
|
+
return { data: {}, body: rest, error: `front matter is not valid YAML: ${detail}` };
|
|
17
|
+
}
|
|
18
|
+
if (data == null) return { data: {}, body: rest, error: null };
|
|
19
|
+
const parsed = jsonObjectSchema.safeParse(data);
|
|
20
|
+
if (!parsed.success)
|
|
21
|
+
return { data: {}, body: rest, error: "front matter must be a YAML mapping" };
|
|
22
|
+
return { data: parsed.data, body: rest, error: null };
|
|
23
|
+
};
|
|
24
|
+
const frontMatterString = (data, key) => {
|
|
25
|
+
const parsed = z.string().safeParse(data[key]);
|
|
26
|
+
return parsed.success ? parsed.data : null;
|
|
27
|
+
};
|
|
28
|
+
const firstParagraphLine = (markdown) => markdown.split("\n").map((line) => line.trim()).find((line) => line.length > 0 && !line.startsWith("```"))?.replace(/^[#>*-]+\s*/, "") ?? null;
|
|
29
|
+
export {
|
|
30
|
+
firstParagraphLine,
|
|
31
|
+
frontMatterString,
|
|
32
|
+
parseFrontMatter
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=frontmatter.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/compiler/frontmatter.ts"],
|
|
4
|
+
"sourcesContent": ["import { jsonObjectSchema, type JsonObject } from '@finalai/agent-provider';\nimport { parse } from 'yaml';\nimport * as z from 'zod';\n\nexport interface FrontMatterIface {\n data: JsonObject;\n body: string;\n error: string | null;\n}\n\n// `---\\n<yaml>\\n---\\n<body>`; text without front matter is all body.\nexport const parseFrontMatter = (text: string): FrontMatterIface => {\n const normalized = text.replace(/^\uFEFF/, '').replaceAll('\\r\\n', '\\n');\n if (!normalized.startsWith('---\\n')) return { data: {}, body: normalized, error: null };\n const end = normalized.indexOf('\\n---', 4);\n if (end < 0) return { data: {}, body: normalized, error: 'front matter is not closed with ---' };\n const yamlText = normalized.slice(4, end);\n const rest = normalized.slice(end + 4).replace(/^[^\\n]*\\n?/, '');\n let data;\n try {\n data = parse(yamlText);\n } catch (cause) {\n const detail = cause instanceof Error ? cause.message : String(cause);\n return { data: {}, body: rest, error: `front matter is not valid YAML: ${detail}` };\n }\n if (data == null) return { data: {}, body: rest, error: null };\n const parsed = jsonObjectSchema.safeParse(data);\n if (!parsed.success)\n return { data: {}, body: rest, error: 'front matter must be a YAML mapping' };\n return { data: parsed.data, body: rest, error: null };\n};\n\nexport const frontMatterString = (data: JsonObject, key: string): string | null => {\n const parsed = z.string().safeParse(data[key]);\n return parsed.success ? parsed.data : null;\n};\n\nexport const firstParagraphLine = (markdown: string): string | null =>\n markdown\n .split('\\n')\n .map((line) => line.trim())\n .find((line) => line.length > 0 && !line.startsWith('```'))\n ?.replace(/^[#>*-]+\\s*/, '') ?? null;\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,wBAAyC;AAClD,SAAS,aAAa;AACtB,YAAY,OAAO;AASZ,MAAM,mBAAmB,CAAC,SAAmC;AAClE,QAAM,aAAa,KAAK,QAAQ,MAAM,EAAE,EAAE,WAAW,QAAQ,IAAI;AACjE,MAAI,CAAC,WAAW,WAAW,OAAO,EAAG,QAAO,EAAE,MAAM,CAAC,GAAG,MAAM,YAAY,OAAO,KAAK;AACtF,QAAM,MAAM,WAAW,QAAQ,SAAS,CAAC;AACzC,MAAI,MAAM,EAAG,QAAO,EAAE,MAAM,CAAC,GAAG,MAAM,YAAY,OAAO,sCAAsC;AAC/F,QAAM,WAAW,WAAW,MAAM,GAAG,GAAG;AACxC,QAAM,OAAO,WAAW,MAAM,MAAM,CAAC,EAAE,QAAQ,cAAc,EAAE;AAC/D,MAAI;AACJ,MAAI;AACF,WAAO,MAAM,QAAQ;AAAA,EACvB,SAAS,OAAO;AACd,UAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACpE,WAAO,EAAE,MAAM,CAAC,GAAG,MAAM,MAAM,OAAO,mCAAmC,MAAM,GAAG;AAAA,EACpF;AACA,MAAI,QAAQ,KAAM,QAAO,EAAE,MAAM,CAAC,GAAG,MAAM,MAAM,OAAO,KAAK;AAC7D,QAAM,SAAS,iBAAiB,UAAU,IAAI;AAC9C,MAAI,CAAC,OAAO;AACV,WAAO,EAAE,MAAM,CAAC,GAAG,MAAM,MAAM,OAAO,sCAAsC;AAC9E,SAAO,EAAE,MAAM,OAAO,MAAM,MAAM,MAAM,OAAO,KAAK;AACtD;AAEO,MAAM,oBAAoB,CAAC,MAAkB,QAA+B;AACjF,QAAM,SAAS,EAAE,OAAO,EAAE,UAAU,KAAK,GAAG,CAAC;AAC7C,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;AAEO,MAAM,qBAAqB,CAAC,aACjC,SACG,MAAM,IAAI,EACV,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,EACzB,KAAK,CAAC,SAAS,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,KAAK,CAAC,GACxD,QAAQ,eAAe,EAAE,KAAK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type AgentManifestIface, type HarnessDescriptionIface, type ProviderRef } from '@finalai/agent-provider';
|
|
2
|
+
import { type CompatibilityReportIface } from "../compatibility.mjs";
|
|
3
|
+
import { type DiagnosticIface } from "./diagnostics.mjs";
|
|
4
|
+
import { type VendoredPackageIface } from "./packages.mjs";
|
|
5
|
+
export type { CompatibilityReportIface } from "../compatibility.mjs";
|
|
6
|
+
export { DiagnosticCode, DiagnosticSeverity, hasErrors } from "./diagnostics.mjs";
|
|
7
|
+
export type { DiagnosticIface } from "./diagnostics.mjs";
|
|
8
|
+
export { discover } from "./discovery.mjs";
|
|
9
|
+
export { loadBundle } from "./load.mjs";
|
|
10
|
+
export type { LoadedBundleIface } from "./load.mjs";
|
|
11
|
+
export { loadBundleInLocalIsolate } from "./local-isolate.mjs";
|
|
12
|
+
export type { LocalIsolateOptionsIface } from "./local-isolate.mjs";
|
|
13
|
+
export { parsePackageJson, PLATFORM_PACKAGES, splitSpecifier, workspaceDependencies, WorkspaceDependencyKind, workspacePackageCandidates, workspacePackageGlobs, } from "./packages.mjs";
|
|
14
|
+
export type { VendoredPackageIface, WorkspaceDependencyIface } from "./packages.mjs";
|
|
15
|
+
export interface CompileOptionsIface {
|
|
16
|
+
dir?: string;
|
|
17
|
+
files?: Record<string, string>;
|
|
18
|
+
defaultFiles?: Readonly<Record<string, string>>;
|
|
19
|
+
name?: string;
|
|
20
|
+
harnessDescriptions?: (ref: ProviderRef, context: HarnessDescriptionContextIface) => Promise<HarnessDescriptionIface | null>;
|
|
21
|
+
packageRoot?: string;
|
|
22
|
+
packages?: Record<string, VendoredPackageIface>;
|
|
23
|
+
providerModules?: Readonly<Record<string, string>>;
|
|
24
|
+
installedSandboxProviders?: Readonly<Record<string, string>>;
|
|
25
|
+
}
|
|
26
|
+
export interface HarnessDescriptionContextIface {
|
|
27
|
+
bundle: {
|
|
28
|
+
hash: string;
|
|
29
|
+
code: string;
|
|
30
|
+
} | null;
|
|
31
|
+
}
|
|
32
|
+
export interface CompiledBundleIface {
|
|
33
|
+
files?: Record<string, string>;
|
|
34
|
+
hash: string;
|
|
35
|
+
code: string;
|
|
36
|
+
modules: Record<string, string>;
|
|
37
|
+
sandboxOpeners: Record<string, string>;
|
|
38
|
+
channelRoutes: Record<string, {
|
|
39
|
+
method: string;
|
|
40
|
+
path: string;
|
|
41
|
+
}[]>;
|
|
42
|
+
}
|
|
43
|
+
export interface CompileResultIface {
|
|
44
|
+
manifest: AgentManifestIface | null;
|
|
45
|
+
bundle: CompiledBundleIface | null;
|
|
46
|
+
diagnostics: DiagnosticIface[];
|
|
47
|
+
report: CompatibilityReportIface | null;
|
|
48
|
+
}
|
|
49
|
+
export declare const compile: (options: CompileOptionsIface) => Promise<CompileResultIface>;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import {
|
|
2
|
+
jsonValueSchema
|
|
3
|
+
} from "@finalai/agent-provider";
|
|
4
|
+
import { sandboxPreparationInputs, sandboxSeedFiles } from "@finalai/agent-provider/sandbox";
|
|
5
|
+
import { basename, dirname } from "node:path";
|
|
6
|
+
import * as z from "zod";
|
|
7
|
+
import { compatibilityReport } from "../compatibility.mjs";
|
|
8
|
+
import { assemble } from "./assemble.mjs";
|
|
9
|
+
import { bundleAgent } from "./bundle.mjs";
|
|
10
|
+
import {
|
|
11
|
+
diagnostic,
|
|
12
|
+
DiagnosticCode,
|
|
13
|
+
DiagnosticSeverity,
|
|
14
|
+
hasErrors
|
|
15
|
+
} from "./diagnostics.mjs";
|
|
16
|
+
import { discover } from "./discovery.mjs";
|
|
17
|
+
import { evaluateBundle } from "./evaluate.mjs";
|
|
18
|
+
import { normalizeFiles, preparationFiles, readAgentDirectory } from "./files.mjs";
|
|
19
|
+
import { declaredDependencyDiagnostics } from "./packages.mjs";
|
|
20
|
+
import { DiagnosticCode as DiagnosticCode2, DiagnosticSeverity as DiagnosticSeverity2, hasErrors as hasErrors2 } from "./diagnostics.mjs";
|
|
21
|
+
import { discover as discover2 } from "./discovery.mjs";
|
|
22
|
+
import { loadBundle } from "./load.mjs";
|
|
23
|
+
import { loadBundleInLocalIsolate } from "./local-isolate.mjs";
|
|
24
|
+
import {
|
|
25
|
+
parsePackageJson,
|
|
26
|
+
PLATFORM_PACKAGES,
|
|
27
|
+
splitSpecifier,
|
|
28
|
+
workspaceDependencies,
|
|
29
|
+
WorkspaceDependencyKind,
|
|
30
|
+
workspacePackageCandidates,
|
|
31
|
+
workspacePackageGlobs
|
|
32
|
+
} from "./packages.mjs";
|
|
33
|
+
const directoryName = (dir) => {
|
|
34
|
+
const name = basename(dir);
|
|
35
|
+
return name === "agent" ? basename(dirname(dir)) : name;
|
|
36
|
+
};
|
|
37
|
+
const configObjectSchema = z.record(z.string(), jsonValueSchema);
|
|
38
|
+
const schemaPropertiesSchema = z.object({ properties: z.record(z.string(), jsonValueSchema) });
|
|
39
|
+
const withoutUndeclaredDirectoryFields = (args) => {
|
|
40
|
+
const config = configObjectSchema.safeParse(args.manifest.harness.config);
|
|
41
|
+
if (!config.success) return args.manifest;
|
|
42
|
+
const declared = schemaPropertiesSchema.safeParse(args.configSchema);
|
|
43
|
+
const properties = declared.success ? declared.data.properties : {};
|
|
44
|
+
const next = { ...config.data };
|
|
45
|
+
const fields = [
|
|
46
|
+
["instructions", args.directoryFields.instructions],
|
|
47
|
+
["skills", args.directoryFields.skills]
|
|
48
|
+
];
|
|
49
|
+
for (const [field, sources] of fields) {
|
|
50
|
+
if (sources.length === 0 || field in properties || !(field in next)) continue;
|
|
51
|
+
delete next[field];
|
|
52
|
+
args.diagnostics.push(
|
|
53
|
+
diagnostic({
|
|
54
|
+
severity: DiagnosticSeverity.Warning,
|
|
55
|
+
code: DiagnosticCode.Compatibility,
|
|
56
|
+
message: `the harness has no ${field} field, so ${sources.join(", ")} ${sources.length === 1 ? "is" : "are"} unused`
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return { ...args.manifest, harness: { ...args.manifest.harness, config: next } };
|
|
61
|
+
};
|
|
62
|
+
const compile = async (options) => {
|
|
63
|
+
const diagnostics = [];
|
|
64
|
+
const fail = (message) => ({
|
|
65
|
+
manifest: null,
|
|
66
|
+
bundle: null,
|
|
67
|
+
diagnostics: [
|
|
68
|
+
...diagnostics,
|
|
69
|
+
diagnostic({ severity: DiagnosticSeverity.Error, code: DiagnosticCode.Input, message })
|
|
70
|
+
],
|
|
71
|
+
report: null
|
|
72
|
+
});
|
|
73
|
+
let root = null;
|
|
74
|
+
let rawFiles;
|
|
75
|
+
if (options.dir != null) {
|
|
76
|
+
if (options.files != null) return fail("pass either dir or files, not both");
|
|
77
|
+
try {
|
|
78
|
+
const read = await readAgentDirectory(options.dir);
|
|
79
|
+
root = read.root;
|
|
80
|
+
rawFiles = read.files;
|
|
81
|
+
} catch (cause) {
|
|
82
|
+
return fail(cause instanceof Error ? cause.message : String(cause));
|
|
83
|
+
}
|
|
84
|
+
} else if (options.files != null) rawFiles = options.files;
|
|
85
|
+
else return fail("pass dir or files");
|
|
86
|
+
const normalized = normalizeFiles(rawFiles);
|
|
87
|
+
for (const problem of normalized.problems) {
|
|
88
|
+
diagnostics.push(
|
|
89
|
+
diagnostic({
|
|
90
|
+
severity: DiagnosticSeverity.Error,
|
|
91
|
+
code: DiagnosticCode.Input,
|
|
92
|
+
message: problem.message,
|
|
93
|
+
path: problem.path
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
const { files } = normalized;
|
|
98
|
+
const defaultModuleKeys = /* @__PURE__ */ new Set();
|
|
99
|
+
for (const [path, source] of Object.entries(options.defaultFiles ?? {})) {
|
|
100
|
+
const stem = path.replace(/\.(ts|mts|js|mjs)$/, "");
|
|
101
|
+
if (!Object.keys(files).some((file) => file.replace(/\.(ts|mts|js|mjs)$/, "") === stem)) {
|
|
102
|
+
files[path] = source;
|
|
103
|
+
defaultModuleKeys.add(stem.replace(/^channels\//, ""));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
sandboxSeedFiles(sandboxPreparationInputs(files));
|
|
108
|
+
} catch (cause) {
|
|
109
|
+
return fail(cause instanceof Error ? cause.message : String(cause));
|
|
110
|
+
}
|
|
111
|
+
const packages = {};
|
|
112
|
+
for (const [name, pkg] of Object.entries(options.packages ?? {})) {
|
|
113
|
+
const vendored = normalizeFiles(pkg.files, { enforceSizeLimits: false });
|
|
114
|
+
for (const problem of vendored.problems) {
|
|
115
|
+
diagnostics.push(
|
|
116
|
+
diagnostic({
|
|
117
|
+
severity: DiagnosticSeverity.Error,
|
|
118
|
+
code: DiagnosticCode.Input,
|
|
119
|
+
message: `${name}: ${problem.message}`,
|
|
120
|
+
path: problem.path
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
Object.defineProperty(packages, name, {
|
|
125
|
+
value: { ...pkg, files: vendored.files },
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true,
|
|
128
|
+
writable: true
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
diagnostics.push(
|
|
132
|
+
...declaredDependencyDiagnostics({
|
|
133
|
+
packageJson: files["package.json"],
|
|
134
|
+
vendored: new Set(Object.keys(packages)),
|
|
135
|
+
local: root != null
|
|
136
|
+
})
|
|
137
|
+
);
|
|
138
|
+
const discovery = discover(Object.keys(files));
|
|
139
|
+
let bundle = null;
|
|
140
|
+
let described = null;
|
|
141
|
+
if (discovery.modules.length > 0) {
|
|
142
|
+
const bundled = await bundleAgent({
|
|
143
|
+
files,
|
|
144
|
+
layout: discovery.modules,
|
|
145
|
+
root,
|
|
146
|
+
packageRoot: options.packageRoot,
|
|
147
|
+
packages,
|
|
148
|
+
providerModules: options.providerModules
|
|
149
|
+
});
|
|
150
|
+
for (const problem of bundled.problems) {
|
|
151
|
+
diagnostics.push(
|
|
152
|
+
diagnostic({
|
|
153
|
+
severity: DiagnosticSeverity.Error,
|
|
154
|
+
code: problem.builtin ? DiagnosticCode.NodeBuiltin : DiagnosticCode.Bundle,
|
|
155
|
+
message: problem.message,
|
|
156
|
+
path: problem.path
|
|
157
|
+
})
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
if (bundled.code != null && bundled.hash != null) {
|
|
161
|
+
bundle = { hash: bundled.hash, code: bundled.code };
|
|
162
|
+
const evaluated = await evaluateBundle(bundled.code, { packageRoot: options.packageRoot });
|
|
163
|
+
if (evaluated.ok) described = evaluated.described;
|
|
164
|
+
else
|
|
165
|
+
diagnostics.push(
|
|
166
|
+
diagnostic({
|
|
167
|
+
severity: DiagnosticSeverity.Error,
|
|
168
|
+
code: DiagnosticCode.Evaluation,
|
|
169
|
+
message: evaluated.message
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (hasErrors(diagnostics)) return { manifest: null, bundle: null, diagnostics, report: null };
|
|
175
|
+
const assembled = assemble({
|
|
176
|
+
files,
|
|
177
|
+
discovery,
|
|
178
|
+
described,
|
|
179
|
+
fallbackName: options.name ?? (options.dir == null ? "agent" : directoryName(root ?? options.dir)),
|
|
180
|
+
bundle,
|
|
181
|
+
installedSandboxProviders: options.installedSandboxProviders
|
|
182
|
+
});
|
|
183
|
+
if (assembled.manifest != null) {
|
|
184
|
+
for (const key of defaultModuleKeys) {
|
|
185
|
+
const source = assembled.manifest.channelSources?.[key];
|
|
186
|
+
if (source != null) source.source = "default";
|
|
187
|
+
for (const channel of assembled.manifest.channels)
|
|
188
|
+
if (channel.key === key) channel.source = "default";
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
diagnostics.push(...assembled.diagnostics);
|
|
192
|
+
const manifest = assembled.manifest;
|
|
193
|
+
const compiledBundle = manifest?.bundle == null || bundle == null ? null : {
|
|
194
|
+
...bundle,
|
|
195
|
+
files: preparationFiles(files),
|
|
196
|
+
modules: assembled.modules,
|
|
197
|
+
sandboxOpeners: assembled.sandboxOpeners,
|
|
198
|
+
channelRoutes: assembled.channelRoutes
|
|
199
|
+
};
|
|
200
|
+
let report = null;
|
|
201
|
+
let finalManifest = manifest;
|
|
202
|
+
if (manifest != null && options.harnessDescriptions != null) {
|
|
203
|
+
const description = await options.harnessDescriptions(manifest.harness.harness, { bundle });
|
|
204
|
+
if (description == null) {
|
|
205
|
+
diagnostics.push(
|
|
206
|
+
diagnostic({
|
|
207
|
+
severity: DiagnosticSeverity.Warning,
|
|
208
|
+
code: DiagnosticCode.Compatibility,
|
|
209
|
+
message: "the harness description is unavailable, so there is no compatibility report"
|
|
210
|
+
})
|
|
211
|
+
);
|
|
212
|
+
} else {
|
|
213
|
+
report = compatibilityReport({
|
|
214
|
+
manifest,
|
|
215
|
+
description,
|
|
216
|
+
directoryFiles: assembled.directoryFields
|
|
217
|
+
});
|
|
218
|
+
finalManifest = withoutUndeclaredDirectoryFields({
|
|
219
|
+
manifest,
|
|
220
|
+
configSchema: description.configSchema,
|
|
221
|
+
directoryFields: assembled.directoryFields,
|
|
222
|
+
diagnostics
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return { manifest: finalManifest, bundle: compiledBundle, diagnostics, report };
|
|
227
|
+
};
|
|
228
|
+
export {
|
|
229
|
+
DiagnosticCode2 as DiagnosticCode,
|
|
230
|
+
DiagnosticSeverity2 as DiagnosticSeverity,
|
|
231
|
+
PLATFORM_PACKAGES,
|
|
232
|
+
WorkspaceDependencyKind,
|
|
233
|
+
compile,
|
|
234
|
+
discover2 as discover,
|
|
235
|
+
hasErrors2 as hasErrors,
|
|
236
|
+
loadBundle,
|
|
237
|
+
loadBundleInLocalIsolate,
|
|
238
|
+
parsePackageJson,
|
|
239
|
+
splitSpecifier,
|
|
240
|
+
workspaceDependencies,
|
|
241
|
+
workspacePackageCandidates,
|
|
242
|
+
workspacePackageGlobs
|
|
243
|
+
};
|
|
244
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/compiler/index.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n jsonValueSchema,\n type AgentManifestIface,\n type HarnessDescriptionIface,\n type JsonSchema,\n type ProviderRef,\n} from '@finalai/agent-provider';\nimport { sandboxPreparationInputs, sandboxSeedFiles } from '@finalai/agent-provider/sandbox';\nimport { basename, dirname } from 'node:path';\nimport * as z from 'zod';\nimport { compatibilityReport, type CompatibilityReportIface } from \"../compatibility.mjs\";\nimport { assemble } from \"./assemble.mjs\";\nimport { bundleAgent } from \"./bundle.mjs\";\nimport {\n diagnostic,\n DiagnosticCode,\n DiagnosticSeverity,\n hasErrors,\n type DiagnosticIface,\n} from \"./diagnostics.mjs\";\nimport { discover } from \"./discovery.mjs\";\nimport { evaluateBundle } from \"./evaluate.mjs\";\nimport { normalizeFiles, preparationFiles, readAgentDirectory } from \"./files.mjs\";\nimport { declaredDependencyDiagnostics, type VendoredPackageIface } from \"./packages.mjs\";\n\nexport type { CompatibilityReportIface } from \"../compatibility.mjs\";\nexport { DiagnosticCode, DiagnosticSeverity, hasErrors } from \"./diagnostics.mjs\";\nexport type { DiagnosticIface } from \"./diagnostics.mjs\";\nexport { discover } from \"./discovery.mjs\";\nexport { loadBundle } from \"./load.mjs\";\nexport type { LoadedBundleIface } from \"./load.mjs\";\nexport { loadBundleInLocalIsolate } from \"./local-isolate.mjs\";\nexport type { LocalIsolateOptionsIface } from \"./local-isolate.mjs\";\nexport {\n parsePackageJson,\n PLATFORM_PACKAGES,\n splitSpecifier,\n workspaceDependencies,\n WorkspaceDependencyKind,\n workspacePackageCandidates,\n workspacePackageGlobs,\n} from \"./packages.mjs\";\nexport type { VendoredPackageIface, WorkspaceDependencyIface } from \"./packages.mjs\";\n\nexport interface CompileOptionsIface {\n // An agent directory on disk (the repository's `agent/` directory)...\n dir?: string;\n // ...or its files, directory-relative (what Build reads from git).\n files?: Record<string, string>;\n // Optional modules supplied by the host when the author did not provide them.\n defaultFiles?: Readonly<Record<string, string>>;\n // Identity name when agent.ts sets none; defaults to the directory name.\n name?: string;\n // Looks up the chosen harness's description for the compatibility report.\n // A bundle harness is described from the bundle being compiled.\n harnessDescriptions?: (\n ref: ProviderRef,\n context: HarnessDescriptionContextIface,\n ) => Promise<HarnessDescriptionIface | null>;\n // This package's installed root, when the compiler runs from a bundle.\n packageRoot?: string;\n // Workspace packages from the agent's repository it imports, by name\n // (packages.ts); the platform passes them since it compiles without installing.\n packages?: Record<string, VendoredPackageIface>;\n // Authoring modules of the provider packages the host installed, by import\n // specifier \u2192 source file (`@finalai/daytona-agent-provider/sandboxes`), which\n // authored code may import though this package does not depend on them. A\n // compile of files without a checkout resolves packages from this package's\n // dependencies only.\n providerModules?: Readonly<Record<string, string>>;\n // Explicit provider defaults used to infer a dynamic sandbox target by name.\n installedSandboxProviders?: Readonly<Record<string, string>>;\n}\n\nexport interface HarnessDescriptionContextIface {\n // The compiled bundle; null when the definition has no authored modules.\n bundle: { hash: string; code: string } | null;\n}\n\nexport interface CompiledBundleIface {\n // Pinned workspace and skill files used by sandbox provider preparation.\n files?: Record<string, string>;\n hash: string;\n // One ESM module for the Worker isolate; exports `modules` and `runtime`.\n code: string;\n // Bundle export \u2192 directory-relative source path, for everything the\n // runtime calls (tools, channels, hooks, resolvers, selectors, providers).\n modules: Record<string, string>;\n // Target \u2192 bundle export of the sandbox.ts selector that opens it.\n sandboxOpeners: Record<string, string>;\n // Bundle channel export ('channels/github') \u2192 its routes, so the platform\n // shows route URLs without running the bundle.\n channelRoutes: Record<string, { method: string; path: string }[]>;\n}\n\nexport interface CompileResultIface {\n // Null when there are errors.\n manifest: AgentManifestIface | null;\n bundle: CompiledBundleIface | null;\n diagnostics: DiagnosticIface[];\n report: CompatibilityReportIface | null;\n}\n\nconst directoryName = (dir: string): string => {\n const name = basename(dir);\n return name === 'agent' ? basename(dirname(dir)) : name;\n};\n\nconst configObjectSchema = z.record(z.string(), jsonValueSchema);\nconst schemaPropertiesSchema = z.object({ properties: z.record(z.string(), jsonValueSchema) });\n\nconst withoutUndeclaredDirectoryFields = (args: {\n manifest: AgentManifestIface;\n configSchema: JsonSchema;\n directoryFields: { instructions: string[]; skills: string[] };\n diagnostics: DiagnosticIface[];\n}): AgentManifestIface => {\n const config = configObjectSchema.safeParse(args.manifest.harness.config);\n if (!config.success) return args.manifest;\n const declared = schemaPropertiesSchema.safeParse(args.configSchema);\n const properties = declared.success ? declared.data.properties : {};\n const next = { ...config.data };\n const fields: ['instructions' | 'skills', string[]][] = [\n ['instructions', args.directoryFields.instructions],\n ['skills', args.directoryFields.skills],\n ];\n for (const [field, sources] of fields) {\n if (sources.length === 0 || field in properties || !(field in next)) continue;\n delete next[field];\n args.diagnostics.push(\n diagnostic({\n severity: DiagnosticSeverity.Warning,\n code: DiagnosticCode.Compatibility,\n message: `the harness has no ${field} field, so ${sources.join(', ')} ${sources.length === 1 ? 'is' : 'are'} unused`,\n }),\n );\n }\n return { ...args.manifest, harness: { ...args.manifest.harness, config: next } };\n};\n\nexport const compile = async (options: CompileOptionsIface): Promise<CompileResultIface> => {\n const diagnostics: DiagnosticIface[] = [];\n const fail = (message: string): CompileResultIface => ({\n manifest: null,\n bundle: null,\n diagnostics: [\n ...diagnostics,\n diagnostic({ severity: DiagnosticSeverity.Error, code: DiagnosticCode.Input, message }),\n ],\n report: null,\n });\n let root: string | null = null;\n let rawFiles: Record<string, string>;\n if (options.dir != null) {\n if (options.files != null) return fail('pass either dir or files, not both');\n try {\n const read = await readAgentDirectory(options.dir);\n root = read.root;\n rawFiles = read.files;\n } catch (cause) {\n return fail(cause instanceof Error ? cause.message : String(cause));\n }\n } else if (options.files != null) rawFiles = options.files;\n else return fail('pass dir or files');\n const normalized = normalizeFiles(rawFiles);\n for (const problem of normalized.problems) {\n diagnostics.push(\n diagnostic({\n severity: DiagnosticSeverity.Error,\n code: DiagnosticCode.Input,\n message: problem.message,\n path: problem.path,\n }),\n );\n }\n const { files } = normalized;\n const defaultModuleKeys = new Set<string>();\n for (const [path, source] of Object.entries(options.defaultFiles ?? {})) {\n const stem = path.replace(/\\.(ts|mts|js|mjs)$/, '');\n if (!Object.keys(files).some((file) => file.replace(/\\.(ts|mts|js|mjs)$/, '') === stem)) {\n files[path] = source;\n defaultModuleKeys.add(stem.replace(/^channels\\//, ''));\n }\n }\n try {\n sandboxSeedFiles(sandboxPreparationInputs(files));\n } catch (cause) {\n return fail(cause instanceof Error ? cause.message : String(cause));\n }\n const packages: Record<string, VendoredPackageIface> = {};\n for (const [name, pkg] of Object.entries(options.packages ?? {})) {\n const vendored = normalizeFiles(pkg.files, { enforceSizeLimits: false });\n for (const problem of vendored.problems) {\n diagnostics.push(\n diagnostic({\n severity: DiagnosticSeverity.Error,\n code: DiagnosticCode.Input,\n message: `${name}: ${problem.message}`,\n path: problem.path,\n }),\n );\n }\n Object.defineProperty(packages, name, {\n value: { ...pkg, files: vendored.files },\n enumerable: true,\n configurable: true,\n writable: true,\n });\n }\n diagnostics.push(\n ...declaredDependencyDiagnostics({\n packageJson: files['package.json'],\n vendored: new Set(Object.keys(packages)),\n local: root != null,\n }),\n );\n const discovery = discover(Object.keys(files));\n\n let bundle: { hash: string; code: string } | null = null;\n let described = null;\n if (discovery.modules.length > 0) {\n const bundled = await bundleAgent({\n files,\n layout: discovery.modules,\n root,\n packageRoot: options.packageRoot,\n packages,\n providerModules: options.providerModules,\n });\n for (const problem of bundled.problems) {\n diagnostics.push(\n diagnostic({\n severity: DiagnosticSeverity.Error,\n code: problem.builtin ? DiagnosticCode.NodeBuiltin : DiagnosticCode.Bundle,\n message: problem.message,\n path: problem.path,\n }),\n );\n }\n if (bundled.code != null && bundled.hash != null) {\n bundle = { hash: bundled.hash, code: bundled.code };\n const evaluated = await evaluateBundle(bundled.code, { packageRoot: options.packageRoot });\n if (evaluated.ok) described = evaluated.described;\n else\n diagnostics.push(\n diagnostic({\n severity: DiagnosticSeverity.Error,\n code: DiagnosticCode.Evaluation,\n message: evaluated.message,\n }),\n );\n }\n }\n if (hasErrors(diagnostics)) return { manifest: null, bundle: null, diagnostics, report: null };\n\n const assembled = assemble({\n files,\n discovery,\n described,\n fallbackName:\n options.name ?? (options.dir == null ? 'agent' : directoryName(root ?? options.dir)),\n bundle,\n installedSandboxProviders: options.installedSandboxProviders,\n });\n if (assembled.manifest != null) {\n for (const key of defaultModuleKeys) {\n const source = assembled.manifest.channelSources?.[key];\n if (source != null) source.source = 'default';\n for (const channel of assembled.manifest.channels)\n if (channel.key === key) channel.source = 'default';\n }\n }\n diagnostics.push(...assembled.diagnostics);\n const manifest = assembled.manifest;\n const compiledBundle: CompiledBundleIface | null =\n manifest?.bundle == null || bundle == null\n ? null\n : {\n ...bundle,\n files: preparationFiles(files),\n modules: assembled.modules,\n sandboxOpeners: assembled.sandboxOpeners,\n channelRoutes: assembled.channelRoutes,\n };\n\n let report: CompatibilityReportIface | null = null;\n let finalManifest = manifest;\n if (manifest != null && options.harnessDescriptions != null) {\n const description = await options.harnessDescriptions(manifest.harness.harness, { bundle });\n if (description == null) {\n diagnostics.push(\n diagnostic({\n severity: DiagnosticSeverity.Warning,\n code: DiagnosticCode.Compatibility,\n message: 'the harness description is unavailable, so there is no compatibility report',\n }),\n );\n } else {\n report = compatibilityReport({\n manifest,\n description,\n directoryFiles: assembled.directoryFields,\n });\n // Directory instructions and skills fill harness config fields\n // only when the harness declares them; otherwise they are reported unused.\n finalManifest = withoutUndeclaredDirectoryFields({\n manifest,\n configSchema: description.configSchema,\n directoryFields: assembled.directoryFields,\n diagnostics,\n });\n }\n }\n return { manifest: finalManifest, bundle: compiledBundle, diagnostics, report };\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,OAKK;AACP,SAAS,0BAA0B,wBAAwB;AAC3D,SAAS,UAAU,eAAe;AAClC,YAAY,OAAO;AACnB,SAAS,2BAA0D;AACnE,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB,kBAAkB,0BAA0B;AACrE,SAAS,qCAAgE;AAGzE,SAAS,kBAAAA,iBAAgB,sBAAAC,qBAAoB,aAAAC,kBAAiB;AAE9D,SAAS,YAAAC,iBAAgB;AACzB,SAAS,kBAAkB;AAE3B,SAAS,gCAAgC;AAEzC;AAAA,EACE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ACH,OAAO,iBAAiB,KAAK;AAAA,IAC7B,SAAS,UAAU;AAAA,IACnB,gBAAgB,UAAU;AAAA,IAC1B,eAAe,UAAU;AAAA,EAC3B;AAEN,MAAI,SAA0C;AAC9C,MAAI,gBAAgB;AACpB,MAAI,YAAY,QAAQ,QAAQ,uBAAuB,MAAM;AAC3D,UAAM,cAAc,MAAM,QAAQ,oBAAoB,SAAS,QAAQ,SAAS,EAAE,OAAO,CAAC;AAC1F,QAAI,eAAe,MAAM;AACvB,kBAAY;AAAA,QACV,WAAW;AAAA,UACT,UAAU,mBAAmB;AAAA,UAC7B,MAAM,eAAe;AAAA,UACrB,SAAS;AAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF,OAAO;AACL,eAAS,oBAAoB;AAAA,QAC3B;AAAA,QACA;AAAA,QACA,gBAAgB,UAAU;AAAA,MAC5B,CAAC;AAGD,sBAAgB,iCAAiC;AAAA,QAC/C;AAAA,QACA,cAAc,YAAY;AAAA,QAC1B,iBAAiB,UAAU;AAAA,QAC3B;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO,EAAE,UAAU,eAAe,QAAQ,gBAAgB,aAAa,OAAO;AAChF;",
|
|
6
|
+
"names": ["DiagnosticCode", "DiagnosticSeverity", "hasErrors", "discover"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IsolateRuntimeIface } from "../runtime/isolate.mjs";
|
|
2
|
+
import { type AuthoredRecord, type AuthoredValue } from "../runtime/values.mjs";
|
|
3
|
+
export interface LoadedBundleIface {
|
|
4
|
+
modules: AuthoredRecord;
|
|
5
|
+
runtime: IsolateRuntimeIface;
|
|
6
|
+
}
|
|
7
|
+
export declare const parseLoadedBundle: (namespace: AuthoredValue) => LoadedBundleIface;
|
|
8
|
+
export declare const loadBundle: (code: string) => Promise<LoadedBundleIface>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
import {
|
|
7
|
+
authoredRecordSchema,
|
|
8
|
+
callableSchema
|
|
9
|
+
} from "../runtime/values.mjs";
|
|
10
|
+
const loadedBundleSchema = z.looseObject({
|
|
11
|
+
modules: authoredRecordSchema,
|
|
12
|
+
runtime: z.custom(
|
|
13
|
+
(value) => z.looseObject({
|
|
14
|
+
runTool: callableSchema,
|
|
15
|
+
evaluateApproval: callableSchema,
|
|
16
|
+
resolveDynamic: callableSchema,
|
|
17
|
+
dispatchHook: callableSchema,
|
|
18
|
+
handleChannelRoute: callableSchema,
|
|
19
|
+
handleChannelSocket: callableSchema
|
|
20
|
+
}).safeParse(value).success
|
|
21
|
+
)
|
|
22
|
+
});
|
|
23
|
+
const parseLoadedBundle = (namespace) => {
|
|
24
|
+
const parsed = loadedBundleSchema.safeParse(namespace);
|
|
25
|
+
if (!parsed.success) throw new Error("not an agent bundle");
|
|
26
|
+
return { modules: parsed.data.modules, runtime: parsed.data.runtime };
|
|
27
|
+
};
|
|
28
|
+
const loadBundle = async (code) => {
|
|
29
|
+
const directory = await mkdtemp(join(tmpdir(), "final-agent-bundle-"));
|
|
30
|
+
const file = join(directory, "bundle.mjs");
|
|
31
|
+
try {
|
|
32
|
+
await writeFile(file, code, { mode: 384 });
|
|
33
|
+
return parseLoadedBundle(await import(
|
|
34
|
+
/* @vite-ignore */
|
|
35
|
+
pathToFileURL(file).href
|
|
36
|
+
));
|
|
37
|
+
} finally {
|
|
38
|
+
await rm(directory, { recursive: true, force: true });
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
loadBundle,
|
|
43
|
+
parseLoadedBundle
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=load.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/compiler/load.ts"],
|
|
4
|
+
"sourcesContent": ["import { mkdtemp, rm, writeFile } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport * as z from 'zod';\nimport type { IsolateRuntimeIface } from \"../runtime/isolate.mjs\";\nimport {\n authoredRecordSchema,\n callableSchema,\n type AuthoredRecord,\n type AuthoredValue,\n} from \"../runtime/values.mjs\";\n\nexport interface LoadedBundleIface {\n modules: AuthoredRecord;\n runtime: IsolateRuntimeIface;\n}\n\nconst loadedBundleSchema = z.looseObject({\n modules: authoredRecordSchema,\n runtime: z.custom<IsolateRuntimeIface>(\n (value) =>\n z\n .looseObject({\n runTool: callableSchema,\n evaluateApproval: callableSchema,\n resolveDynamic: callableSchema,\n dispatchHook: callableSchema,\n handleChannelRoute: callableSchema,\n handleChannelSocket: callableSchema,\n })\n .safeParse(value).success,\n ),\n});\n\nexport const parseLoadedBundle = (namespace: AuthoredValue): LoadedBundleIface => {\n const parsed = loadedBundleSchema.safeParse(namespace);\n if (!parsed.success) throw new Error('not an agent bundle');\n return { modules: parsed.data.modules, runtime: parsed.data.runtime };\n};\n\n// Imports a compiled bundle in this Node process, for local development and\n// tests of the code that drives the isolate. Production runs bundles in the\n// Worker isolate (agent-harness-workers), never in a Node service.\nexport const loadBundle = async (code: string): Promise<LoadedBundleIface> => {\n const directory = await mkdtemp(join(tmpdir(), 'final-agent-bundle-'));\n const file = join(directory, 'bundle.mjs');\n try {\n await writeFile(file, code, { mode: 0o600 });\n return parseLoadedBundle(await import(/* @vite-ignore */ pathToFileURL(file).href));\n } finally {\n await rm(directory, { recursive: true, force: true });\n }\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,IAAI,iBAAiB;AACvC,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAC9B,YAAY,OAAO;AAEnB;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAOP,MAAM,qBAAqB,EAAE,YAAY;AAAA,EACvC,SAAS;AAAA,EACT,SAAS,EAAE;AAAA,IACT,CAAC,UACC,EACG,YAAY;AAAA,MACX,SAAS;AAAA,MACT,kBAAkB;AAAA,MAClB,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,oBAAoB;AAAA,MACpB,qBAAqB;AAAA,IACvB,CAAC,EACA,UAAU,KAAK,EAAE;AAAA,EACxB;AACF,CAAC;AAEM,MAAM,oBAAoB,CAAC,cAAgD;AAChF,QAAM,SAAS,mBAAmB,UAAU,SAAS;AACrD,MAAI,CAAC,OAAO,QAAS,OAAM,IAAI,MAAM,qBAAqB;AAC1D,SAAO,EAAE,SAAS,OAAO,KAAK,SAAS,SAAS,OAAO,KAAK,QAAQ;AACtE;AAKO,MAAM,aAAa,OAAO,SAA6C;AAC5E,QAAM,YAAY,MAAM,QAAQ,KAAK,OAAO,GAAG,qBAAqB,CAAC;AACrE,QAAM,OAAO,KAAK,WAAW,YAAY;AACzC,MAAI;AACF,UAAM,UAAU,MAAM,MAAM,EAAE,MAAM,IAAM,CAAC;AAC3C,WAAO,kBAAkB,MAAM;AAAA;AAAA,MAA0B,cAAc,IAAI,EAAE;AAAA,KAAK;AAAA,EACpF,UAAE;AACA,UAAM,GAAG,WAAW,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EACtD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type JsonValue, type SandboxOpener, type SecretReaderIface } from '@finalai/agent-provider';
|
|
2
|
+
import type { AgentSessionInfoIface } from "../authoring/context.mjs";
|
|
3
|
+
import { type LoadedBundleIface } from "./load.mjs";
|
|
4
|
+
export interface LocalIsolateOptionsIface {
|
|
5
|
+
fetch?: typeof fetch;
|
|
6
|
+
}
|
|
7
|
+
export interface LocalIsolateBundleIface extends LoadedBundleIface {
|
|
8
|
+
callExportMethod(args: {
|
|
9
|
+
exportName: string;
|
|
10
|
+
method: string;
|
|
11
|
+
args: JsonValue[];
|
|
12
|
+
}): Promise<JsonValue>;
|
|
13
|
+
runSandboxSelector(args: {
|
|
14
|
+
exportName: string;
|
|
15
|
+
session: AgentSessionInfoIface;
|
|
16
|
+
secrets: SecretReaderIface;
|
|
17
|
+
open: SandboxOpener;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare const loadBundleInLocalIsolate: (code: string, options?: LocalIsolateOptionsIface) => Promise<LocalIsolateBundleIface>;
|