@standardagents/builder 0.8.1 → 0.8.3
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/dist/built-in-routes.js.map +1 -1
- package/dist/index.js +13 -78
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +1 -1
- package/dist/mcp.js.map +1 -1
- package/dist/plugin.js +13 -42
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -456,7 +456,6 @@ var init_OpenAIProvider = __esm({
|
|
|
456
456
|
let usage;
|
|
457
457
|
for await (const chunk of stream) {
|
|
458
458
|
if (signal?.aborted || await state.thread.instance.shouldStop()) {
|
|
459
|
-
console.log("[openai] Stop detected during streaming - breaking out of loop");
|
|
460
459
|
break;
|
|
461
460
|
}
|
|
462
461
|
responseId = chunk.id;
|
|
@@ -550,7 +549,6 @@ var init_OpenRouterProvider = __esm({
|
|
|
550
549
|
request.provider = {
|
|
551
550
|
only: providers
|
|
552
551
|
};
|
|
553
|
-
console.log(`[OpenRouter] Using provider routing: only ${providers.join(", ")}`);
|
|
554
552
|
}
|
|
555
553
|
} catch (error) {
|
|
556
554
|
console.error("[OpenRouter] Failed to parse included_providers:", error);
|
|
@@ -594,7 +592,6 @@ var init_OpenRouterProvider = __esm({
|
|
|
594
592
|
try {
|
|
595
593
|
for await (const chunk of stream) {
|
|
596
594
|
if (signal?.aborted || await state.thread.instance.shouldStop()) {
|
|
597
|
-
console.log("[openrouter] Stop detected during streaming - breaking out of loop");
|
|
598
595
|
break;
|
|
599
596
|
}
|
|
600
597
|
allChunks.push(chunk);
|
|
@@ -612,7 +609,6 @@ var init_OpenRouterProvider = __esm({
|
|
|
612
609
|
}
|
|
613
610
|
if (choice.delta?.reasoning_details) {
|
|
614
611
|
const details = choice.delta.reasoning_details;
|
|
615
|
-
console.log(`[OpenRouter] Received reasoning_details chunk:`, JSON.stringify(details).substring(0, 200));
|
|
616
612
|
if (Array.isArray(details)) {
|
|
617
613
|
for (const item of details) {
|
|
618
614
|
if (item.type === "reasoning.text") {
|
|
@@ -1430,13 +1426,11 @@ var init_ToolExecutor = __esm({
|
|
|
1430
1426
|
state.sequence.isHandling = true;
|
|
1431
1427
|
while (state.sequence.queue.length > 0) {
|
|
1432
1428
|
if (await state.thread.instance.shouldStop() || state.abortController?.signal.aborted) {
|
|
1433
|
-
console.log("[ToolExecutor] Stop detected - aborting tool execution");
|
|
1434
1429
|
state.sequence.queue = [];
|
|
1435
1430
|
state.sequence.isHandling = false;
|
|
1436
1431
|
throw new Error("aborted");
|
|
1437
1432
|
}
|
|
1438
1433
|
const call = state.sequence.queue.shift();
|
|
1439
|
-
console.log("[\u{1F47E} ToolExecutor] call", call);
|
|
1440
1434
|
const toolMessageId = crypto.randomUUID();
|
|
1441
1435
|
try {
|
|
1442
1436
|
state.stream.sendTelemetry({
|
|
@@ -1446,7 +1440,6 @@ var init_ToolExecutor = __esm({
|
|
|
1446
1440
|
});
|
|
1447
1441
|
const validationError = this.validateToolCall(call, state);
|
|
1448
1442
|
if (validationError) {
|
|
1449
|
-
console.log("[\u{1F47E} ToolExecutor] validationError", validationError);
|
|
1450
1443
|
const result2 = {
|
|
1451
1444
|
status: "error",
|
|
1452
1445
|
error: validationError
|
|
@@ -1459,8 +1452,6 @@ var init_ToolExecutor = __esm({
|
|
|
1459
1452
|
timestamp: Date.now()
|
|
1460
1453
|
});
|
|
1461
1454
|
continue;
|
|
1462
|
-
} else {
|
|
1463
|
-
console.log("[\u{1F47E} ToolExecutor] tool is allowed");
|
|
1464
1455
|
}
|
|
1465
1456
|
const result = await this.executeToolCall(call, state, toolMessageId);
|
|
1466
1457
|
if (result.status === "error") {
|
|
@@ -1473,7 +1464,6 @@ var init_ToolExecutor = __esm({
|
|
|
1473
1464
|
const { FlowEngine: FlowEngine2 } = await Promise.resolve().then(() => (init_FlowEngine(), FlowEngine_exports));
|
|
1474
1465
|
const hookResult = result.status === "success" ? await FlowEngine2.runAfterToolCallSuccessHook(state, call, result) : await FlowEngine2.runAfterToolCallFailureHook(state, call, result);
|
|
1475
1466
|
if (hookResult === null) {
|
|
1476
|
-
console.log(`[ToolExecutor] Hook returned null for tool ${call.function.name} - removing from history`);
|
|
1477
1467
|
await this.removeToolCallFromHistory(call, state);
|
|
1478
1468
|
continue;
|
|
1479
1469
|
}
|
|
@@ -1494,7 +1484,6 @@ var init_ToolExecutor = __esm({
|
|
|
1494
1484
|
const { FlowEngine: FlowEngine2 } = await Promise.resolve().then(() => (init_FlowEngine(), FlowEngine_exports));
|
|
1495
1485
|
const hookResult = await FlowEngine2.runAfterToolCallFailureHook(state, call, errorResult);
|
|
1496
1486
|
if (hookResult === null) {
|
|
1497
|
-
console.log(`[ToolExecutor] Hook returned null for failed tool ${call.function.name} - removing from history`);
|
|
1498
1487
|
await this.removeToolCallFromHistory(call, state);
|
|
1499
1488
|
continue;
|
|
1500
1489
|
}
|
|
@@ -2269,7 +2258,6 @@ ${errorStack}` : ""}`;
|
|
|
2269
2258
|
`DELETE FROM messages WHERE id = ?`,
|
|
2270
2259
|
message.id
|
|
2271
2260
|
);
|
|
2272
|
-
console.log(`[ToolExecutor] Deleted message ${message.id} containing single tool call ${call.id}`);
|
|
2273
2261
|
} else {
|
|
2274
2262
|
const updatedToolCalls = toolCalls.filter((tc) => tc.id !== call.id);
|
|
2275
2263
|
message.tool_calls = JSON.stringify(updatedToolCalls);
|
|
@@ -2278,7 +2266,6 @@ ${errorStack}` : ""}`;
|
|
|
2278
2266
|
message.tool_calls,
|
|
2279
2267
|
message.id
|
|
2280
2268
|
);
|
|
2281
|
-
console.log(`[ToolExecutor] Removed tool call ${call.id} from message ${message.id}`);
|
|
2282
2269
|
}
|
|
2283
2270
|
} catch (error) {
|
|
2284
2271
|
console.error(`[ToolExecutor] Error removing tool call from history:`, error);
|
|
@@ -2343,7 +2330,6 @@ var init_FlowEngine = __esm({
|
|
|
2343
2330
|
while (state.turnCount < MAX_TURNS && !state.stopped && !state.abortController?.signal.aborted) {
|
|
2344
2331
|
try {
|
|
2345
2332
|
if (state.abortController?.signal.aborted) {
|
|
2346
|
-
console.log(`[FlowEngine.executeAsync] Thread ${threadId} execution aborted by user`);
|
|
2347
2333
|
const interruptionMessageId = crypto.randomUUID();
|
|
2348
2334
|
const timestamp = Date.now() * TIMESTAMP_MULTIPLIER;
|
|
2349
2335
|
let interruptionMessage = {
|
|
@@ -2382,14 +2368,12 @@ var init_FlowEngine = __esm({
|
|
|
2382
2368
|
await this.executeTurn(state);
|
|
2383
2369
|
state.turnCount++;
|
|
2384
2370
|
if (state.parentMessageId !== void 0) {
|
|
2385
|
-
console.log(`[FlowEngine.executeAsync] Sub-prompt completed turn 0 - breaking loop`);
|
|
2386
2371
|
state.stopped = true;
|
|
2387
2372
|
break;
|
|
2388
2373
|
}
|
|
2389
2374
|
} catch (error) {
|
|
2390
2375
|
const isAbortError = error instanceof Error && (error.name === "AbortError" || error.message.includes("aborted"));
|
|
2391
2376
|
if (isAbortError) {
|
|
2392
|
-
console.log(`Thread ${threadId} execution aborted by user during turn ${state.turnCount}`);
|
|
2393
2377
|
state.stopped = true;
|
|
2394
2378
|
break;
|
|
2395
2379
|
}
|
|
@@ -2497,7 +2481,6 @@ var init_FlowEngine = __esm({
|
|
|
2497
2481
|
* Merges provided fields with defaults and loaded data
|
|
2498
2482
|
*/
|
|
2499
2483
|
static async initializeState(stateInput) {
|
|
2500
|
-
console.log(`[FlowEngine.initializeState] Message history: ${JSON.stringify(stateInput.messageHistory)}`);
|
|
2501
2484
|
const { sideAPrompt, sideBPrompt } = await this.loadAgentAndPrompts(
|
|
2502
2485
|
stateInput.agentConfig,
|
|
2503
2486
|
stateInput.thread
|
|
@@ -2564,11 +2547,9 @@ var init_FlowEngine = __esm({
|
|
|
2564
2547
|
*/
|
|
2565
2548
|
static async executeTurn(state) {
|
|
2566
2549
|
if (await state.thread.instance.shouldStop()) {
|
|
2567
|
-
console.log("[FlowEngine.executeTurn] shouldStop flag is true, aborting turn");
|
|
2568
2550
|
throw new Error("aborted");
|
|
2569
2551
|
}
|
|
2570
2552
|
if (state.abortController?.signal.aborted) {
|
|
2571
|
-
console.log("[FlowEngine.executeTurn] abort signal detected, aborting turn");
|
|
2572
2553
|
throw new Error("aborted");
|
|
2573
2554
|
}
|
|
2574
2555
|
const maxTurns = state.currentSide === "a" ? state.agentConfig.side_a_max_turns : state.agentConfig.side_b_max_turns;
|
|
@@ -2628,7 +2609,6 @@ var init_FlowEngine = __esm({
|
|
|
2628
2609
|
throw error;
|
|
2629
2610
|
}
|
|
2630
2611
|
if (await state.thread.instance.shouldStop() || state.abortController?.signal.aborted) {
|
|
2631
|
-
console.log("[FlowEngine.executeTurn] Stop detected after LLM request - discarding response");
|
|
2632
2612
|
await state.storage.sql.exec(
|
|
2633
2613
|
`DELETE FROM messages WHERE id = ?`,
|
|
2634
2614
|
pendingMessageId
|
|
@@ -2648,7 +2628,6 @@ var init_FlowEngine = __esm({
|
|
|
2648
2628
|
await ToolExecutor.executeSequence(state, response.tool_calls);
|
|
2649
2629
|
}
|
|
2650
2630
|
if (await state.thread.instance.shouldStop() || state.abortController?.signal.aborted) {
|
|
2651
|
-
console.log("[FlowEngine.executeTurn] Stop detected after tool execution");
|
|
2652
2631
|
throw new Error("aborted");
|
|
2653
2632
|
}
|
|
2654
2633
|
this.checkStopCondition(state, response);
|
|
@@ -2753,7 +2732,6 @@ var init_FlowEngine = __esm({
|
|
|
2753
2732
|
new_agent_title: state.agentConfig.title,
|
|
2754
2733
|
timestamp: Date.now()
|
|
2755
2734
|
});
|
|
2756
|
-
console.log(`[FlowEngine] Handoff complete: switched to agent ${state.agentConfig.title}`);
|
|
2757
2735
|
} catch (error) {
|
|
2758
2736
|
console.error("Error executing handoff:", error);
|
|
2759
2737
|
await this.logError(state, error, "handoff_execution_error", `Handoff to agent ${newAgentName}`);
|
|
@@ -2784,7 +2762,6 @@ var init_FlowEngine = __esm({
|
|
|
2784
2762
|
role: "system",
|
|
2785
2763
|
content: promptContent
|
|
2786
2764
|
});
|
|
2787
|
-
console.log(`[FlowEngine] Reasoning config - includeReasoning: ${includeReasoning}, effort: ${reasoningEffort}, maxTokens: ${reasoningMaxTokens}, exclude: ${reasoningExclude}`);
|
|
2788
2765
|
const completedMessages = state.messageHistory.filter(
|
|
2789
2766
|
(msg) => msg.status !== "pending"
|
|
2790
2767
|
);
|
|
@@ -2838,21 +2815,17 @@ var init_FlowEngine = __esm({
|
|
|
2838
2815
|
type: "reasoning.text",
|
|
2839
2816
|
text: msg.reasoning_content
|
|
2840
2817
|
});
|
|
2841
|
-
console.log(`[FlowEngine] Added reasoning_content as text detail to message ${msg.id}`);
|
|
2842
2818
|
}
|
|
2843
2819
|
if (msg.reasoning_details) {
|
|
2844
2820
|
try {
|
|
2845
2821
|
const parsedDetails = JSON.parse(msg.reasoning_details);
|
|
2846
2822
|
reasoningDetailsArray.push(...parsedDetails);
|
|
2847
|
-
console.log(`[FlowEngine] Added ${parsedDetails.length} structured reasoning_details to message ${msg.id}`);
|
|
2848
2823
|
} catch (e) {
|
|
2849
2824
|
console.error(`[FlowEngine] Failed to parse reasoning_details for message ${msg.id}:`, e);
|
|
2850
2825
|
}
|
|
2851
2826
|
}
|
|
2852
2827
|
if (reasoningDetailsArray.length > 0) {
|
|
2853
2828
|
messageToAdd.reasoning_details = reasoningDetailsArray;
|
|
2854
|
-
} else {
|
|
2855
|
-
console.log(`[FlowEngine] includeReasoning is true but message ${msg.id} has no reasoning data`);
|
|
2856
2829
|
}
|
|
2857
2830
|
}
|
|
2858
2831
|
if (includePastTools && msg.role === "assistant" && msg.tool_calls) {
|
|
@@ -3787,7 +3760,6 @@ var init_FlowEngine = __esm({
|
|
|
3787
3760
|
const thread = state.thread;
|
|
3788
3761
|
const includeParentHistory = state.prompt.include_chat ?? true;
|
|
3789
3762
|
const includeToolCalls = state.prompt.include_past_tools ?? true;
|
|
3790
|
-
console.log("loadMessageHistory", includeParentHistory, includeToolCalls);
|
|
3791
3763
|
try {
|
|
3792
3764
|
let rows = [];
|
|
3793
3765
|
if (includeParentHistory) {
|
|
@@ -5685,6 +5657,9 @@ async function scanHooksDirectory(dir) {
|
|
|
5685
5657
|
for (const entry of entries) {
|
|
5686
5658
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
5687
5659
|
const fileName = entry.name.replace(".ts", "");
|
|
5660
|
+
if (fileName === "index") {
|
|
5661
|
+
continue;
|
|
5662
|
+
}
|
|
5688
5663
|
const filePath = path3.join(dir, entry.name);
|
|
5689
5664
|
const importPath = "./" + path3.relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
5690
5665
|
hooks.push({ name: fileName, importPath });
|
|
@@ -5783,9 +5758,7 @@ function agentbuilder(options = {}) {
|
|
|
5783
5758
|
};
|
|
5784
5759
|
function regenerateTypes() {
|
|
5785
5760
|
if (needsRegeneration(typeGenConfig)) {
|
|
5786
|
-
console.log("[vite-plugin-agent] Regenerating types...");
|
|
5787
5761
|
generateTypes(typeGenConfig);
|
|
5788
|
-
console.log("[vite-plugin-agent] Types regenerated at .agents/types.d.ts");
|
|
5789
5762
|
}
|
|
5790
5763
|
}
|
|
5791
5764
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -5922,7 +5895,7 @@ function agentbuilder(options = {}) {
|
|
|
5922
5895
|
}
|
|
5923
5896
|
return false;
|
|
5924
5897
|
}
|
|
5925
|
-
function handleFileChange(file, server
|
|
5898
|
+
function handleFileChange(file, server) {
|
|
5926
5899
|
const isToolFile = file.startsWith(toolsDir) && file.endsWith(".ts");
|
|
5927
5900
|
const isThreadApiFile = file.startsWith(threadApiDir) && file.endsWith(".ts");
|
|
5928
5901
|
const isHookFile = file.startsWith(hooksDir) && file.endsWith(".ts");
|
|
@@ -5931,13 +5904,6 @@ function agentbuilder(options = {}) {
|
|
|
5931
5904
|
const isAgentFile = file.startsWith(agentsDir) && file.endsWith(".ts");
|
|
5932
5905
|
const isConfigFile = isModelFile || isPromptFile || isAgentFile;
|
|
5933
5906
|
if (!isToolFile && !isThreadApiFile && !isHookFile && !isConfigFile) return;
|
|
5934
|
-
const fileType = isToolFile ? "tool" : isThreadApiFile ? "thread-api" : isHookFile ? "hook" : isModelFile ? "model" : isPromptFile ? "prompt" : "agent";
|
|
5935
|
-
console.log(
|
|
5936
|
-
`[vite-plugin-agent] ${action} ${fileType}: ${path3.relative(
|
|
5937
|
-
process.cwd(),
|
|
5938
|
-
file
|
|
5939
|
-
)}`
|
|
5940
|
-
);
|
|
5941
5907
|
if (isConfigFile || isToolFile) {
|
|
5942
5908
|
regenerateTypes();
|
|
5943
5909
|
}
|
|
@@ -5965,6 +5931,8 @@ function agentbuilder(options = {}) {
|
|
|
5965
5931
|
config() {
|
|
5966
5932
|
return {
|
|
5967
5933
|
optimizeDeps: {
|
|
5934
|
+
// Pre-bundle these deps to prevent reload during startup
|
|
5935
|
+
include: ["openai", "zod"],
|
|
5968
5936
|
// Exclude @standardagents/builder/mcp from pre-bundling (used for MCP server, not needed in worker)
|
|
5969
5937
|
exclude: [
|
|
5970
5938
|
"@standardagents/builder/mcp"
|
|
@@ -5991,50 +5959,35 @@ function agentbuilder(options = {}) {
|
|
|
5991
5959
|
};
|
|
5992
5960
|
},
|
|
5993
5961
|
resolveId(id) {
|
|
5994
|
-
if (id.includes("virtual:") || id.includes("agent")) {
|
|
5995
|
-
console.log("[plugin.resolveId]", id);
|
|
5996
|
-
}
|
|
5997
5962
|
if (id === VIRTUAL_TOOLS_ID) {
|
|
5998
|
-
console.log("[plugin.resolveId] \u2713 Resolving tools");
|
|
5999
5963
|
return RESOLVED_VIRTUAL_TOOLS_ID;
|
|
6000
5964
|
}
|
|
6001
5965
|
if (id === VIRTUAL_ROUTES_ID || id === VIRTUAL_ROUTER_ID) {
|
|
6002
|
-
console.log("[plugin.resolveId] \u2713 Resolving routes");
|
|
6003
5966
|
return RESOLVED_VIRTUAL_ROUTES_ID;
|
|
6004
5967
|
}
|
|
6005
5968
|
if (id === VIRTUAL_HOOKS_ID) {
|
|
6006
|
-
console.log("[plugin.resolveId] \u2713 Resolving hooks");
|
|
6007
5969
|
return RESOLVED_VIRTUAL_HOOKS_ID;
|
|
6008
5970
|
}
|
|
6009
5971
|
if (id === VIRTUAL_CONFIG_ID) {
|
|
6010
|
-
console.log("[plugin.resolveId] \u2713 Resolving config");
|
|
6011
5972
|
return RESOLVED_VIRTUAL_CONFIG_ID;
|
|
6012
5973
|
}
|
|
6013
5974
|
if (id === VIRTUAL_THREAD_API_ID) {
|
|
6014
|
-
console.log("[plugin.resolveId] \u2713 Resolving thread API");
|
|
6015
5975
|
return RESOLVED_VIRTUAL_THREAD_API_ID;
|
|
6016
5976
|
}
|
|
6017
5977
|
if (id === VIRTUAL_MODELS_ID) {
|
|
6018
|
-
console.log("[plugin.resolveId] \u2713 Resolving models");
|
|
6019
5978
|
return RESOLVED_VIRTUAL_MODELS_ID;
|
|
6020
5979
|
}
|
|
6021
5980
|
if (id === VIRTUAL_PROMPTS_ID) {
|
|
6022
|
-
console.log("[plugin.resolveId] \u2713 Resolving prompts");
|
|
6023
5981
|
return RESOLVED_VIRTUAL_PROMPTS_ID;
|
|
6024
5982
|
}
|
|
6025
5983
|
if (id === VIRTUAL_AGENTS_ID) {
|
|
6026
|
-
console.log("[plugin.resolveId] \u2713 Resolving agents");
|
|
6027
5984
|
return RESOLVED_VIRTUAL_AGENTS_ID;
|
|
6028
5985
|
}
|
|
6029
5986
|
if (id === VIRTUAL_BUILDER_ID) {
|
|
6030
|
-
console.log("[plugin.resolveId] \u2713 Resolving consolidated builder module");
|
|
6031
5987
|
return RESOLVED_VIRTUAL_BUILDER_ID;
|
|
6032
5988
|
}
|
|
6033
5989
|
},
|
|
6034
5990
|
async load(id) {
|
|
6035
|
-
if (id.includes("\0virtual:") || id.includes("agent")) {
|
|
6036
|
-
console.log("[plugin.load]", id);
|
|
6037
|
-
}
|
|
6038
5991
|
if (id === RESOLVED_VIRTUAL_TOOLS_ID) {
|
|
6039
5992
|
const tools = await scanToolsDirectory(toolsDir);
|
|
6040
5993
|
const toolsCode = tools.map(({ name, importPath, error }) => {
|
|
@@ -6079,11 +6032,8 @@ import { hooks } from "virtual:@standardagents-hooks";
|
|
|
6079
6032
|
import { models, modelNames } from "virtual:@standardagents-models";
|
|
6080
6033
|
import { prompts, promptNames } from "virtual:@standardagents-prompts";
|
|
6081
6034
|
import { agents, agentNames } from "virtual:@standardagents-agents";
|
|
6082
|
-
import { DurableThread as _DurableThread } from "@standardagents/builder/runtime";
|
|
6083
6035
|
import { requireAuth } from "@standardagents/builder/runtime";
|
|
6084
6036
|
|
|
6085
|
-
console.log('[Router] Virtual modules loaded - tools:', Object.keys(tools || {}), 'hooks:', Object.keys(hooks || {}), 'models:', modelNames, 'prompts:', promptNames, 'agents:', agentNames);
|
|
6086
|
-
|
|
6087
6037
|
const MOUNT_POINT = "${mountPoint}";
|
|
6088
6038
|
|
|
6089
6039
|
// Routes that don't require authentication
|
|
@@ -6208,8 +6158,8 @@ async function serveUI(pathname, env) {
|
|
|
6208
6158
|
// Transform HTML to use configured mount point
|
|
6209
6159
|
if (response.status === 200) {
|
|
6210
6160
|
const html = await response.text();
|
|
6211
|
-
// Replace default /
|
|
6212
|
-
const modifiedHtml = html.replace(/\\/
|
|
6161
|
+
// Replace default /agents/ paths with configured mount point
|
|
6162
|
+
const modifiedHtml = html.replace(/\\/agents\\//g, \`\${MOUNT_POINT}/\`);
|
|
6213
6163
|
return new Response(modifiedHtml, {
|
|
6214
6164
|
headers: {
|
|
6215
6165
|
"Content-Type": "text/html; charset=utf-8",
|
|
@@ -6240,15 +6190,10 @@ async function serveUI(pathname, env) {
|
|
|
6240
6190
|
}
|
|
6241
6191
|
}
|
|
6242
6192
|
|
|
6243
|
-
// Export DurableThread so users can re-export it from virtual module
|
|
6244
|
-
export { _DurableThread as DurableThread };
|
|
6245
6193
|
`;
|
|
6246
6194
|
}
|
|
6247
6195
|
if (id === RESOLVED_VIRTUAL_HOOKS_ID) {
|
|
6248
|
-
console.log("[plugin.load] \u2713 Loading HOOKS virtual module");
|
|
6249
|
-
console.log("[plugin.load] hooksDir:", hooksDir);
|
|
6250
6196
|
const hooks = await scanHooksDirectory(hooksDir);
|
|
6251
|
-
console.log(`[plugin.load] Scanned hooks directory, found ${hooks.length} hooks:`, hooks.map((h) => h.name));
|
|
6252
6197
|
const hooksCode = hooks.map(({ name, importPath }) => {
|
|
6253
6198
|
return ` "${name}": async () => {
|
|
6254
6199
|
try {
|
|
@@ -6260,7 +6205,6 @@ export { _DurableThread as DurableThread };
|
|
|
6260
6205
|
},`;
|
|
6261
6206
|
}).join("\n");
|
|
6262
6207
|
return `// Virtual agent hooks module
|
|
6263
|
-
console.log('[virtual:agent-hooks] Module loaded with hooks:', Object.keys({${hooks.map((h) => `'${h.name}': null`).join(", ")}}));
|
|
6264
6208
|
export const hooks = {
|
|
6265
6209
|
${hooksCode}
|
|
6266
6210
|
};`;
|
|
@@ -6539,10 +6483,10 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
6539
6483
|
},
|
|
6540
6484
|
configureServer(server) {
|
|
6541
6485
|
server.watcher.on("add", async (file) => {
|
|
6542
|
-
handleFileChange(file, server
|
|
6486
|
+
handleFileChange(file, server);
|
|
6543
6487
|
});
|
|
6544
6488
|
server.watcher.on("unlink", (file) => {
|
|
6545
|
-
handleFileChange(file, server
|
|
6489
|
+
handleFileChange(file, server);
|
|
6546
6490
|
});
|
|
6547
6491
|
server.middlewares.use(async (req, res, next) => {
|
|
6548
6492
|
const url = req.url;
|
|
@@ -7010,7 +6954,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
7010
6954
|
const configScript = `<script>window.__AGENTBUILDER_CONFIG__ = { mountPoint: "${mountPoint}" };</script>`;
|
|
7011
6955
|
let htmlContent = content.toString();
|
|
7012
6956
|
const assetPrefix = mountPoint === "/" ? "/" : `${mountPoint}/`;
|
|
7013
|
-
htmlContent = htmlContent.replace(/\/
|
|
6957
|
+
htmlContent = htmlContent.replace(/\/agents\//g, assetPrefix);
|
|
7014
6958
|
htmlContent = htmlContent.replace("</head>", `${configScript}</head>`);
|
|
7015
6959
|
content = Buffer.from(htmlContent);
|
|
7016
6960
|
}
|
|
@@ -7038,7 +6982,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
7038
6982
|
});
|
|
7039
6983
|
},
|
|
7040
6984
|
handleHotUpdate({ file, server }) {
|
|
7041
|
-
handleFileChange(file, server
|
|
6985
|
+
handleFileChange(file, server);
|
|
7042
6986
|
},
|
|
7043
6987
|
writeBundle(options2, bundle) {
|
|
7044
6988
|
const outDir = options2.dir || "dist";
|
|
@@ -7069,7 +7013,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
7069
7013
|
const configScript = `<script>window.__AGENTBUILDER_CONFIG__ = { mountPoint: "${mountPoint}" };</script>`;
|
|
7070
7014
|
let htmlContent = content.toString();
|
|
7071
7015
|
const assetPrefix = mountPoint === "/" ? "/" : `${mountPoint}/`;
|
|
7072
|
-
htmlContent = htmlContent.replace(/\/
|
|
7016
|
+
htmlContent = htmlContent.replace(/\/agents\//g, assetPrefix);
|
|
7073
7017
|
htmlContent = htmlContent.replace("</head>", `${configScript}</head>`);
|
|
7074
7018
|
content = Buffer.from(htmlContent);
|
|
7075
7019
|
}
|
|
@@ -7078,7 +7022,6 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
7078
7022
|
}
|
|
7079
7023
|
}
|
|
7080
7024
|
copyRecursive(clientDir, mountDir);
|
|
7081
|
-
console.log(`[agentbuilder] Copied client files to ${mountDir}`);
|
|
7082
7025
|
}
|
|
7083
7026
|
};
|
|
7084
7027
|
}
|
|
@@ -8247,23 +8190,18 @@ var DurableThread = class extends DurableObject {
|
|
|
8247
8190
|
*/
|
|
8248
8191
|
async stop() {
|
|
8249
8192
|
await this.ensureMigrated();
|
|
8250
|
-
console.log("[DurableThread.stop] Stop method called");
|
|
8251
8193
|
try {
|
|
8252
8194
|
await this.ctx.storage.sql.exec(
|
|
8253
8195
|
`UPDATE execution_state SET value = 'true' WHERE key = 'stopped'`
|
|
8254
8196
|
);
|
|
8255
|
-
console.log("[DurableThread.stop] Set stopped flag to true in SQLite");
|
|
8256
8197
|
if (this.currentAbortController) {
|
|
8257
|
-
console.log("[DurableThread.stop] Calling abort() on controller");
|
|
8258
8198
|
this.currentAbortController.abort();
|
|
8259
|
-
console.log("[DurableThread.stop] Abort signal set");
|
|
8260
8199
|
}
|
|
8261
8200
|
const now = Date.now() * TIMESTAMP_MULTIPLIER;
|
|
8262
8201
|
const updateCursor = await this.ctx.storage.sql.exec(
|
|
8263
8202
|
`UPDATE messages SET status = 'failed', response_completed_at = ? WHERE status = 'pending'`,
|
|
8264
8203
|
now
|
|
8265
8204
|
);
|
|
8266
|
-
console.log("[DurableThread.stop] Marked pending messages as failed");
|
|
8267
8205
|
const cursor = await this.ctx.storage.sql.exec(
|
|
8268
8206
|
`SELECT id, role, content, tool_calls, tool_call_id, tool_status, created_at, log_id, status, request_sent_at, response_completed_at FROM messages WHERE response_completed_at = ?`,
|
|
8269
8207
|
now
|
|
@@ -8317,7 +8255,6 @@ var DurableThread = class extends DurableObject {
|
|
|
8317
8255
|
created_at: now,
|
|
8318
8256
|
status: "completed"
|
|
8319
8257
|
});
|
|
8320
|
-
console.log(`[DurableThread.stop] Created error response for tool call ${tc.id}`);
|
|
8321
8258
|
}
|
|
8322
8259
|
}
|
|
8323
8260
|
}
|
|
@@ -8345,7 +8282,6 @@ var DurableThread = class extends DurableObject {
|
|
|
8345
8282
|
await this.ctx.storage.sql.exec(
|
|
8346
8283
|
`UPDATE logs SET is_complete = 1 WHERE is_complete = 0`
|
|
8347
8284
|
);
|
|
8348
|
-
console.log("[DurableThread.stop] Marked incomplete logs as complete");
|
|
8349
8285
|
const logsCursor = await this.ctx.storage.sql.exec(
|
|
8350
8286
|
`SELECT id, message_id, provider, model, model_name, prompt_name, tools_called,
|
|
8351
8287
|
parent_log_id, retry_of_log_id, error, cost_total, is_complete, created_at
|
|
@@ -9044,7 +8980,6 @@ var DurableThread = class extends DurableObject {
|
|
|
9044
8980
|
await this.ctx.storage.sql.exec(
|
|
9045
8981
|
`UPDATE execution_state SET value = 'false' WHERE key = 'stopped'`
|
|
9046
8982
|
);
|
|
9047
|
-
console.log("[DurableThread.processMessage] User message - cleared stopped flag in SQLite");
|
|
9048
8983
|
}
|
|
9049
8984
|
this.isExecuting = true;
|
|
9050
8985
|
this.currentAbortController = new AbortController();
|