@standardagents/builder 0.10.1-next.bbd142a → 0.11.0-next.0fa8695
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +48 -0
- package/dist/built-in-routes.js +6069 -90
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/assets/index.css +1 -1
- package/dist/client/index.js +25 -19
- package/dist/client/vendor.js +1 -1
- package/dist/client/vue.js +1 -1
- package/dist/image-processing.d.ts +10 -6
- package/dist/image-processing.js +11 -138
- package/dist/image-processing.js.map +1 -1
- package/dist/index.d.ts +456 -802
- package/dist/index.js +4944 -3977
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.js +127 -76
- package/dist/plugin.js.map +1 -1
- package/package.json +21 -22
package/dist/plugin.d.ts
CHANGED
package/dist/plugin.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import fs2 from 'fs';
|
|
2
2
|
import path3 from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
|
-
import { createRequire } from 'module';
|
|
5
4
|
|
|
6
5
|
// src/plugin.ts
|
|
7
6
|
var TSCONFIG_CONTENT = `{
|
|
@@ -813,16 +812,6 @@ function generatePromptFile(data) {
|
|
|
813
812
|
const toolsCode = formatToolsArray(data.tools);
|
|
814
813
|
lines.push(` tools: ${toolsCode},`);
|
|
815
814
|
}
|
|
816
|
-
if (data.handoffAgents && data.handoffAgents.length > 0) {
|
|
817
|
-
const agentsStr = data.handoffAgents.map((a) => `'${escapeString2(a)}'`).join(", ");
|
|
818
|
-
lines.push(` handoffAgents: [${agentsStr}],`);
|
|
819
|
-
}
|
|
820
|
-
if (data.beforeTool) {
|
|
821
|
-
lines.push(` beforeTool: '${escapeString2(data.beforeTool)}',`);
|
|
822
|
-
}
|
|
823
|
-
if (data.afterTool) {
|
|
824
|
-
lines.push(` afterTool: '${escapeString2(data.afterTool)}',`);
|
|
825
|
-
}
|
|
826
815
|
if (data.reasoning && hasNonNullProperties(data.reasoning)) {
|
|
827
816
|
const reasoningCode = formatReasoningConfig(data.reasoning);
|
|
828
817
|
lines.push(` reasoning: ${reasoningCode},`);
|
|
@@ -987,7 +976,7 @@ function generateAgentFile(data) {
|
|
|
987
976
|
if (data.type && data.type !== "ai_human") {
|
|
988
977
|
lines.push(` type: '${data.type}',`);
|
|
989
978
|
}
|
|
990
|
-
if (data.maxSessionTurns !== void 0) {
|
|
979
|
+
if (data.maxSessionTurns !== void 0 && data.maxSessionTurns !== null) {
|
|
991
980
|
lines.push(` maxSessionTurns: ${data.maxSessionTurns},`);
|
|
992
981
|
}
|
|
993
982
|
lines.push(` sideA: ${formatSideConfig(data.sideA)},`);
|
|
@@ -1000,9 +989,6 @@ function generateAgentFile(data) {
|
|
|
1000
989
|
if (data.toolDescription) {
|
|
1001
990
|
lines.push(` toolDescription: '${escapeString3(data.toolDescription)}',`);
|
|
1002
991
|
}
|
|
1003
|
-
if (data.tags && data.tags.length > 0) {
|
|
1004
|
-
lines.push(` tags: ${JSON.stringify(data.tags)},`);
|
|
1005
|
-
}
|
|
1006
992
|
lines.push(`});`);
|
|
1007
993
|
lines.push("");
|
|
1008
994
|
return lines.join("\n");
|
|
@@ -1022,11 +1008,11 @@ function formatSideConfig(config) {
|
|
|
1022
1008
|
if (config.stopToolResponseProperty) {
|
|
1023
1009
|
parts.push(` stopToolResponseProperty: '${escapeString3(config.stopToolResponseProperty)}',`);
|
|
1024
1010
|
}
|
|
1025
|
-
if (config.
|
|
1026
|
-
parts.push(`
|
|
1011
|
+
if (config.maxSteps !== void 0) {
|
|
1012
|
+
parts.push(` maxSteps: ${config.maxSteps},`);
|
|
1027
1013
|
}
|
|
1028
|
-
if (config.
|
|
1029
|
-
parts.push(`
|
|
1014
|
+
if (config.endSessionTool) {
|
|
1015
|
+
parts.push(` endSessionTool: '${escapeString3(config.endSessionTool)}',`);
|
|
1030
1016
|
}
|
|
1031
1017
|
if (config.manualStopCondition !== void 0) {
|
|
1032
1018
|
parts.push(` manualStopCondition: ${config.manualStopCondition},`);
|
|
@@ -1126,7 +1112,7 @@ function validateModelData(data) {
|
|
|
1126
1112
|
if (!data.provider || typeof data.provider !== "string") {
|
|
1127
1113
|
return "Model provider is required and must be a string";
|
|
1128
1114
|
}
|
|
1129
|
-
const validProviders = ["openai", "openrouter", "anthropic", "google"];
|
|
1115
|
+
const validProviders = ["openai", "openrouter", "anthropic", "google", "test"];
|
|
1130
1116
|
if (!validProviders.includes(data.provider)) {
|
|
1131
1117
|
return `Invalid provider '${data.provider}'. Must be one of: ${validProviders.join(", ")}`;
|
|
1132
1118
|
}
|
|
@@ -1173,11 +1159,8 @@ function transformPromptData(data) {
|
|
|
1173
1159
|
required_schema: "requiredSchema",
|
|
1174
1160
|
include_chat: "includeChat",
|
|
1175
1161
|
include_past_tools: "includePastTools",
|
|
1176
|
-
before_tool: "beforeTool",
|
|
1177
|
-
after_tool: "afterTool",
|
|
1178
1162
|
parallel_tool_calls: "parallelToolCalls",
|
|
1179
1163
|
tool_choice: "toolChoice",
|
|
1180
|
-
handoff_agents: "handoffAgents",
|
|
1181
1164
|
reasoning_effort: "reasoningEffort",
|
|
1182
1165
|
reasoning_max_tokens: "reasoningMaxTokens",
|
|
1183
1166
|
reasoning_exclude: "reasoningExclude",
|
|
@@ -1328,9 +1311,6 @@ function validatePromptData(data) {
|
|
|
1328
1311
|
if (data.tools !== void 0 && !Array.isArray(data.tools)) {
|
|
1329
1312
|
return "tools must be an array";
|
|
1330
1313
|
}
|
|
1331
|
-
if (data.handoffAgents !== void 0 && !Array.isArray(data.handoffAgents)) {
|
|
1332
|
-
return "handoffAgents must be an array";
|
|
1333
|
-
}
|
|
1334
1314
|
if (data.reasoning !== void 0) {
|
|
1335
1315
|
if (typeof data.reasoning !== "object") {
|
|
1336
1316
|
return "reasoning must be an object";
|
|
@@ -1375,11 +1355,11 @@ function transformAgentData(data) {
|
|
|
1375
1355
|
if (data.side_a_stop_tool_response_property) {
|
|
1376
1356
|
transformed.sideA.stopToolResponseProperty = data.side_a_stop_tool_response_property;
|
|
1377
1357
|
}
|
|
1378
|
-
if (data.
|
|
1379
|
-
transformed.sideA.
|
|
1358
|
+
if (data.side_a_max_steps !== void 0) {
|
|
1359
|
+
transformed.sideA.maxSteps = data.side_a_max_steps;
|
|
1380
1360
|
}
|
|
1381
|
-
if (data.
|
|
1382
|
-
transformed.sideA.
|
|
1361
|
+
if (data.side_a_end_session_tool) {
|
|
1362
|
+
transformed.sideA.endSessionTool = data.side_a_end_session_tool;
|
|
1383
1363
|
}
|
|
1384
1364
|
if (data.side_a_manual_stop_condition !== void 0) {
|
|
1385
1365
|
transformed.sideA.manualStopCondition = data.side_a_manual_stop_condition;
|
|
@@ -1400,11 +1380,11 @@ function transformAgentData(data) {
|
|
|
1400
1380
|
if (data.side_b_stop_tool_response_property) {
|
|
1401
1381
|
transformed.sideB.stopToolResponseProperty = data.side_b_stop_tool_response_property;
|
|
1402
1382
|
}
|
|
1403
|
-
if (data.
|
|
1404
|
-
transformed.sideB.
|
|
1383
|
+
if (data.side_b_max_steps !== void 0) {
|
|
1384
|
+
transformed.sideB.maxSteps = data.side_b_max_steps;
|
|
1405
1385
|
}
|
|
1406
|
-
if (data.
|
|
1407
|
-
transformed.sideB.
|
|
1386
|
+
if (data.side_b_end_session_tool) {
|
|
1387
|
+
transformed.sideB.endSessionTool = data.side_b_end_session_tool;
|
|
1408
1388
|
}
|
|
1409
1389
|
if (data.side_b_manual_stop_condition !== void 0) {
|
|
1410
1390
|
transformed.sideB.manualStopCondition = data.side_b_manual_stop_condition;
|
|
@@ -1416,9 +1396,6 @@ function transformAgentData(data) {
|
|
|
1416
1396
|
if (data.tool_description) {
|
|
1417
1397
|
transformed.toolDescription = data.tool_description;
|
|
1418
1398
|
}
|
|
1419
|
-
if (data.tags) {
|
|
1420
|
-
transformed.tags = data.tags;
|
|
1421
|
-
}
|
|
1422
1399
|
return transformed;
|
|
1423
1400
|
}
|
|
1424
1401
|
function getAgentFilePath(agentsDir, name) {
|
|
@@ -1606,9 +1583,9 @@ function validateAgentData(data) {
|
|
|
1606
1583
|
if (data.sideA.stopTool && !data.sideA.stopToolResponseProperty) {
|
|
1607
1584
|
return "sideA.stopToolResponseProperty is required when sideA.stopTool is set";
|
|
1608
1585
|
}
|
|
1609
|
-
if (data.sideA.
|
|
1610
|
-
if (typeof data.sideA.
|
|
1611
|
-
return "sideA.
|
|
1586
|
+
if (data.sideA.maxSteps !== void 0) {
|
|
1587
|
+
if (typeof data.sideA.maxSteps !== "number" || data.sideA.maxSteps <= 0) {
|
|
1588
|
+
return "sideA.maxSteps must be a positive number";
|
|
1612
1589
|
}
|
|
1613
1590
|
}
|
|
1614
1591
|
if (data.type === "dual_ai") {
|
|
@@ -1621,35 +1598,24 @@ function validateAgentData(data) {
|
|
|
1621
1598
|
if (data.sideB.stopTool && !data.sideB.stopToolResponseProperty) {
|
|
1622
1599
|
return "sideB.stopToolResponseProperty is required when sideB.stopTool is set";
|
|
1623
1600
|
}
|
|
1624
|
-
if (data.sideB.
|
|
1625
|
-
if (typeof data.sideB.
|
|
1626
|
-
return "sideB.
|
|
1601
|
+
if (data.sideB.maxSteps !== void 0) {
|
|
1602
|
+
if (typeof data.sideB.maxSteps !== "number" || data.sideB.maxSteps <= 0) {
|
|
1603
|
+
return "sideB.maxSteps must be a positive number";
|
|
1627
1604
|
}
|
|
1628
1605
|
}
|
|
1629
1606
|
}
|
|
1630
1607
|
if (data.exposeAsTool && !data.toolDescription) {
|
|
1631
1608
|
return "toolDescription is required when exposeAsTool is true";
|
|
1632
1609
|
}
|
|
1633
|
-
if (data.maxSessionTurns !== void 0) {
|
|
1610
|
+
if (data.maxSessionTurns !== void 0 && data.maxSessionTurns !== null) {
|
|
1634
1611
|
if (typeof data.maxSessionTurns !== "number" || data.maxSessionTurns <= 0) {
|
|
1635
1612
|
return "maxSessionTurns must be a positive number";
|
|
1636
1613
|
}
|
|
1637
1614
|
}
|
|
1638
|
-
if (data.tags !== void 0) {
|
|
1639
|
-
if (!Array.isArray(data.tags)) {
|
|
1640
|
-
return "tags must be an array";
|
|
1641
|
-
}
|
|
1642
|
-
for (const tag of data.tags) {
|
|
1643
|
-
if (typeof tag !== "string") {
|
|
1644
|
-
return "Each tag must be a string";
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
1615
|
return null;
|
|
1649
1616
|
}
|
|
1650
1617
|
|
|
1651
1618
|
// src/plugin.ts
|
|
1652
|
-
createRequire(import.meta.url);
|
|
1653
1619
|
var VIRTUAL_TOOLS_ID = "virtual:@standardagents-tools";
|
|
1654
1620
|
var RESOLVED_VIRTUAL_TOOLS_ID = "\0" + VIRTUAL_TOOLS_ID;
|
|
1655
1621
|
var VIRTUAL_ROUTES_ID = "virtual:@standardagents-routes";
|
|
@@ -1668,6 +1634,8 @@ var VIRTUAL_PROMPTS_ID = "virtual:@standardagents-prompts";
|
|
|
1668
1634
|
var RESOLVED_VIRTUAL_PROMPTS_ID = "\0" + VIRTUAL_PROMPTS_ID;
|
|
1669
1635
|
var VIRTUAL_AGENTS_ID = "virtual:@standardagents-agents";
|
|
1670
1636
|
var RESOLVED_VIRTUAL_AGENTS_ID = "\0" + VIRTUAL_AGENTS_ID;
|
|
1637
|
+
var VIRTUAL_EFFECTS_ID = "virtual:@standardagents-effects";
|
|
1638
|
+
var RESOLVED_VIRTUAL_EFFECTS_ID = "\0" + VIRTUAL_EFFECTS_ID;
|
|
1671
1639
|
var VIRTUAL_BUILDER_ID = "virtual:@standardagents/builder";
|
|
1672
1640
|
var RESOLVED_VIRTUAL_BUILDER_ID = "\0" + VIRTUAL_BUILDER_ID;
|
|
1673
1641
|
function scanApiDirectory(dir, baseRoute = "") {
|
|
@@ -1843,6 +1811,33 @@ async function scanPromptsDirectory(dir) {
|
|
|
1843
1811
|
async function scanAgentsDirectory(dir) {
|
|
1844
1812
|
return scanConfigDirectory(dir, /export\s+default\s+defineAgent/);
|
|
1845
1813
|
}
|
|
1814
|
+
async function scanEffectsDirectory(dir) {
|
|
1815
|
+
const effects = [];
|
|
1816
|
+
if (!fs2.existsSync(dir)) {
|
|
1817
|
+
return effects;
|
|
1818
|
+
}
|
|
1819
|
+
const entries = await fs2.promises.readdir(dir, { withFileTypes: true });
|
|
1820
|
+
for (const entry of entries) {
|
|
1821
|
+
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
1822
|
+
const fileName = entry.name.replace(".ts", "");
|
|
1823
|
+
const filePath = path3.join(dir, entry.name);
|
|
1824
|
+
const importPath = "./" + path3.relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
1825
|
+
if (fileName === "CLAUDE" || fileName.startsWith("_")) {
|
|
1826
|
+
continue;
|
|
1827
|
+
}
|
|
1828
|
+
try {
|
|
1829
|
+
const content = fs2.readFileSync(filePath, "utf-8");
|
|
1830
|
+
if (!content.includes("defineEffect")) {
|
|
1831
|
+
continue;
|
|
1832
|
+
}
|
|
1833
|
+
} catch {
|
|
1834
|
+
continue;
|
|
1835
|
+
}
|
|
1836
|
+
effects.push({ name: fileName, importPath });
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
return effects;
|
|
1840
|
+
}
|
|
1846
1841
|
function parseRequestBody(req) {
|
|
1847
1842
|
return new Promise((resolve, reject) => {
|
|
1848
1843
|
let body = "";
|
|
@@ -1873,6 +1868,7 @@ function agentbuilder(options = {}) {
|
|
|
1873
1868
|
const modelsDir = options.modelsDir ? path3.resolve(process.cwd(), options.modelsDir) : path3.resolve(process.cwd(), "agents/models");
|
|
1874
1869
|
const promptsDir = options.promptsDir ? path3.resolve(process.cwd(), options.promptsDir) : path3.resolve(process.cwd(), "agents/prompts");
|
|
1875
1870
|
const agentsDir = options.agentsDir ? path3.resolve(process.cwd(), options.agentsDir) : path3.resolve(process.cwd(), "agents/agents");
|
|
1871
|
+
const effectsDir = options.effectsDir ? path3.resolve(process.cwd(), options.effectsDir) : path3.resolve(process.cwd(), "agents/effects");
|
|
1876
1872
|
const outputDir = path3.resolve(process.cwd(), ".agents");
|
|
1877
1873
|
const typeGenConfig = {
|
|
1878
1874
|
modelsDir,
|
|
@@ -2063,17 +2059,24 @@ function agentbuilder(options = {}) {
|
|
|
2063
2059
|
// WASM image processing deps - must be excluded to avoid pre-bundle cache issues
|
|
2064
2060
|
"@cf-wasm/photon",
|
|
2065
2061
|
"@cf-wasm/photon/workerd",
|
|
2062
|
+
"@standardagents/sip",
|
|
2063
|
+
// sip's jsquash dependencies (WASM-based decoders)
|
|
2066
2064
|
"@jsquash/avif",
|
|
2067
|
-
"@jsquash/
|
|
2068
|
-
"@jsquash/png",
|
|
2069
|
-
"@jsquash/webp",
|
|
2070
|
-
"@standardagents/sip"
|
|
2065
|
+
"@jsquash/webp"
|
|
2071
2066
|
];
|
|
2072
2067
|
const depsToInclude = [
|
|
2073
2068
|
"zod",
|
|
2074
2069
|
"openai"
|
|
2075
2070
|
];
|
|
2071
|
+
const currentDir = path3.dirname(fileURLToPath(import.meta.url));
|
|
2072
|
+
const isInDist = currentDir.endsWith("dist");
|
|
2073
|
+
const builderClientDir = path3.resolve(
|
|
2074
|
+
currentDir,
|
|
2075
|
+
isInDist ? "./client" : "../dist/client"
|
|
2076
|
+
);
|
|
2076
2077
|
return {
|
|
2078
|
+
// Set publicDir to builder's client assets so Cloudflare plugin preserves assets config
|
|
2079
|
+
publicDir: fs2.existsSync(builderClientDir) ? builderClientDir : void 0,
|
|
2077
2080
|
optimizeDeps: {
|
|
2078
2081
|
// Exclude our packages from pre-bundling - they contain cloudflare:workers imports
|
|
2079
2082
|
// that cannot be resolved during dependency optimization
|
|
@@ -2102,11 +2105,10 @@ function agentbuilder(options = {}) {
|
|
|
2102
2105
|
// WASM image processing deps
|
|
2103
2106
|
"@cf-wasm/photon",
|
|
2104
2107
|
"@cf-wasm/photon/workerd",
|
|
2108
|
+
"@standardagents/sip",
|
|
2109
|
+
// sip's jsquash dependencies (WASM-based decoders)
|
|
2105
2110
|
"@jsquash/avif",
|
|
2106
|
-
"@jsquash/
|
|
2107
|
-
"@jsquash/png",
|
|
2108
|
-
"@jsquash/webp",
|
|
2109
|
-
"@standardagents/sip"
|
|
2111
|
+
"@jsquash/webp"
|
|
2110
2112
|
];
|
|
2111
2113
|
const depsToInclude = [
|
|
2112
2114
|
"zod",
|
|
@@ -2147,6 +2149,9 @@ function agentbuilder(options = {}) {
|
|
|
2147
2149
|
if (id === VIRTUAL_AGENTS_ID) {
|
|
2148
2150
|
return RESOLVED_VIRTUAL_AGENTS_ID;
|
|
2149
2151
|
}
|
|
2152
|
+
if (id === VIRTUAL_EFFECTS_ID) {
|
|
2153
|
+
return RESOLVED_VIRTUAL_EFFECTS_ID;
|
|
2154
|
+
}
|
|
2150
2155
|
if (id === VIRTUAL_BUILDER_ID) {
|
|
2151
2156
|
return RESOLVED_VIRTUAL_BUILDER_ID;
|
|
2152
2157
|
}
|
|
@@ -2311,13 +2316,15 @@ async function serveUI(pathname, env) {
|
|
|
2311
2316
|
// Create a proper request for the asset path
|
|
2312
2317
|
// Use a dummy origin since we only care about the path
|
|
2313
2318
|
// Re-add mount point since pathname was stripped by router
|
|
2314
|
-
|
|
2319
|
+
// Handle root mountPoint "/" specially to avoid double slashes
|
|
2320
|
+
const mountPrefix = MOUNT_POINT === "/" ? "" : MOUNT_POINT;
|
|
2321
|
+
const assetUrl = \`http://localhost\${mountPrefix}\${pathname}\`;
|
|
2315
2322
|
let response = await env.ASSETS.fetch(assetUrl);
|
|
2316
2323
|
|
|
2317
2324
|
// If not found, fall back to index.html for SPA routing
|
|
2318
2325
|
const isIndexHtml = response.status === 404 || pathname === "/" || !pathname.includes(".");
|
|
2319
2326
|
if (isIndexHtml) {
|
|
2320
|
-
response = await env.ASSETS.fetch(\`http://localhost\${
|
|
2327
|
+
response = await env.ASSETS.fetch(\`http://localhost\${mountPrefix}/index.html\`);
|
|
2321
2328
|
|
|
2322
2329
|
// Transform HTML to use configured mount point
|
|
2323
2330
|
if (response.status === 200) {
|
|
@@ -2464,6 +2471,31 @@ ${agentsCode}
|
|
|
2464
2471
|
};
|
|
2465
2472
|
|
|
2466
2473
|
export const agentNames = ${JSON.stringify(agents.filter((a) => !a.error).map((a) => a.name))};
|
|
2474
|
+
`;
|
|
2475
|
+
}
|
|
2476
|
+
if (id === RESOLVED_VIRTUAL_EFFECTS_ID) {
|
|
2477
|
+
const effects = await scanEffectsDirectory(effectsDir);
|
|
2478
|
+
const effectsCode = effects.map(({ name, importPath, error }) => {
|
|
2479
|
+
if (error) {
|
|
2480
|
+
const escapedError = error.replace(/"/g, '\\"').replace(/\n/g, "\\n");
|
|
2481
|
+
return ` "${name}": async () => { throw new Error("${escapedError}"); },`;
|
|
2482
|
+
} else {
|
|
2483
|
+
return ` "${name}": async () => {
|
|
2484
|
+
try {
|
|
2485
|
+
return (await import("${importPath}")).default;
|
|
2486
|
+
} catch (error) {
|
|
2487
|
+
console.error('Failed to import effect ${name}:', error);
|
|
2488
|
+
throw error;
|
|
2489
|
+
}
|
|
2490
|
+
},`;
|
|
2491
|
+
}
|
|
2492
|
+
}).join("\n");
|
|
2493
|
+
return `// Virtual agent effects module
|
|
2494
|
+
export const effects = {
|
|
2495
|
+
${effectsCode}
|
|
2496
|
+
};
|
|
2497
|
+
|
|
2498
|
+
export const effectNames = ${JSON.stringify(effects.filter((e) => !e.error).map((e) => e.name))};
|
|
2467
2499
|
`;
|
|
2468
2500
|
}
|
|
2469
2501
|
if (id === RESOLVED_VIRTUAL_BUILDER_ID) {
|
|
@@ -2472,6 +2504,7 @@ export const agentNames = ${JSON.stringify(agents.filter((a) => !a.error).map((a
|
|
|
2472
2504
|
const models = await scanModelsDirectory(modelsDir);
|
|
2473
2505
|
const prompts = await scanPromptsDirectory(promptsDir);
|
|
2474
2506
|
const agents = await scanAgentsDirectory(agentsDir);
|
|
2507
|
+
const effects = await scanEffectsDirectory(effectsDir);
|
|
2475
2508
|
const toAbsolutePath = (relativePath) => {
|
|
2476
2509
|
if (relativePath.startsWith("./")) {
|
|
2477
2510
|
return path3.resolve(process.cwd(), relativePath).replace(/\\/g, "/");
|
|
@@ -2550,6 +2583,22 @@ export const agentNames = ${JSON.stringify(agents.filter((a) => !a.error).map((a
|
|
|
2550
2583
|
console.error('Failed to import agent ${name}:', error);
|
|
2551
2584
|
throw error;
|
|
2552
2585
|
}
|
|
2586
|
+
},`;
|
|
2587
|
+
}
|
|
2588
|
+
}).join("\n");
|
|
2589
|
+
const effectsCode = effects.map(({ name, importPath, error }) => {
|
|
2590
|
+
const absPath = toAbsolutePath(importPath);
|
|
2591
|
+
if (error) {
|
|
2592
|
+
const escapedError = error.replace(/"/g, '\\"').replace(/\n/g, "\\n");
|
|
2593
|
+
return ` "${name}": async () => { throw new Error("${escapedError}"); },`;
|
|
2594
|
+
} else {
|
|
2595
|
+
return ` "${name}": async () => {
|
|
2596
|
+
try {
|
|
2597
|
+
return (await import("${absPath}")).default;
|
|
2598
|
+
} catch (error) {
|
|
2599
|
+
console.error('Failed to import effect ${name}:', error);
|
|
2600
|
+
throw error;
|
|
2601
|
+
}
|
|
2553
2602
|
},`;
|
|
2554
2603
|
}
|
|
2555
2604
|
}).join("\n");
|
|
@@ -2587,6 +2636,10 @@ const _agents = {
|
|
|
2587
2636
|
${agentsCode}
|
|
2588
2637
|
};
|
|
2589
2638
|
|
|
2639
|
+
const _effects = {
|
|
2640
|
+
${effectsCode}
|
|
2641
|
+
};
|
|
2642
|
+
|
|
2590
2643
|
/**
|
|
2591
2644
|
* DurableThread with all virtual module methods already implemented.
|
|
2592
2645
|
* Simply extend this class in your agents/Thread.ts file.
|
|
@@ -2621,6 +2674,10 @@ export class DurableThread extends _BaseDurableThread {
|
|
|
2621
2674
|
agents() {
|
|
2622
2675
|
return _agents;
|
|
2623
2676
|
}
|
|
2677
|
+
|
|
2678
|
+
effects() {
|
|
2679
|
+
return _effects;
|
|
2680
|
+
}
|
|
2624
2681
|
}
|
|
2625
2682
|
|
|
2626
2683
|
/**
|
|
@@ -2647,6 +2704,10 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
2647
2704
|
agents() {
|
|
2648
2705
|
return _agents;
|
|
2649
2706
|
}
|
|
2707
|
+
|
|
2708
|
+
effects() {
|
|
2709
|
+
return _effects;
|
|
2710
|
+
}
|
|
2650
2711
|
}
|
|
2651
2712
|
`;
|
|
2652
2713
|
}
|
|
@@ -2659,6 +2720,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
2659
2720
|
this.addWatchFile(modelsDir);
|
|
2660
2721
|
this.addWatchFile(promptsDir);
|
|
2661
2722
|
this.addWatchFile(agentsDir);
|
|
2723
|
+
this.addWatchFile(effectsDir);
|
|
2662
2724
|
},
|
|
2663
2725
|
configureServer(server) {
|
|
2664
2726
|
server.watcher.on("add", async (file) => {
|
|
@@ -2903,20 +2965,12 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
2903
2965
|
const getIncludePastTools = (c) => c.match(/includePastTools:\s*(true|false)/)?.[1] === "true";
|
|
2904
2966
|
const getParallelToolCalls = (c) => c.match(/parallelToolCalls:\s*(true|false)/)?.[1] === "true";
|
|
2905
2967
|
const getToolChoice = (c) => c.match(/toolChoice:\s*['"]([^'"]+)['"]/)?.[1];
|
|
2906
|
-
const getBeforeTool = (c) => c.match(/beforeTool:\s*['"]([^'"]+)['"]/)?.[1];
|
|
2907
|
-
const getAfterTool = (c) => c.match(/afterTool:\s*['"]([^'"]+)['"]/)?.[1];
|
|
2908
2968
|
const getTools = (c) => {
|
|
2909
2969
|
const match = c.match(/tools:\s*\[([^\]]*)\]/);
|
|
2910
2970
|
if (!match) return [];
|
|
2911
2971
|
const items = match[1].match(/['"]([^'"]+)['"]/g);
|
|
2912
2972
|
return items ? items.map((s) => s.replace(/['"]/g, "")) : [];
|
|
2913
2973
|
};
|
|
2914
|
-
const getHandoffAgents = (c) => {
|
|
2915
|
-
const match = c.match(/handoffAgents:\s*\[([^\]]*)\]/);
|
|
2916
|
-
if (!match) return [];
|
|
2917
|
-
const items = match[1].match(/['"]([^'"]+)['"]/g);
|
|
2918
|
-
return items ? items.map((s) => s.replace(/['"]/g, "")) : [];
|
|
2919
|
-
};
|
|
2920
2974
|
const getPrompt = (c) => {
|
|
2921
2975
|
const backtickMatch = c.match(/prompt:\s*`([\s\S]*?)`/);
|
|
2922
2976
|
if (backtickMatch) return backtickMatch[1];
|
|
@@ -2944,10 +2998,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
2944
2998
|
include_past_tools: getIncludePastTools(content),
|
|
2945
2999
|
parallel_tool_calls: getParallelToolCalls(content),
|
|
2946
3000
|
tool_choice: getToolChoice(content) || "auto",
|
|
2947
|
-
before_tool: getBeforeTool(content) || null,
|
|
2948
|
-
after_tool: getAfterTool(content) || null,
|
|
2949
3001
|
tools: getTools(content),
|
|
2950
|
-
prompts: getHandoffAgents(content),
|
|
2951
3002
|
reasoning: null,
|
|
2952
3003
|
// Complex to parse
|
|
2953
3004
|
created_at: Math.floor(Date.now() / 1e3)
|