zeitlich 0.2.27 → 0.2.29
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/README.md +121 -13
- package/dist/{activities-DE3_q9yq.d.ts → activities-1xrWRrGJ.d.cts} +2 -3
- package/dist/{activities-p8PDlRIK.d.cts → activities-DOViDCTE.d.ts} +2 -3
- package/dist/adapters/sandbox/e2b/index.cjs +230 -0
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -0
- package/dist/adapters/sandbox/e2b/index.d.cts +77 -0
- package/dist/adapters/sandbox/e2b/index.d.ts +77 -0
- package/dist/adapters/sandbox/e2b/index.js +227 -0
- package/dist/adapters/sandbox/e2b/index.js.map +1 -0
- package/dist/adapters/sandbox/{virtual → e2b}/workflow.cjs +8 -8
- package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -0
- package/dist/adapters/sandbox/e2b/workflow.d.cts +27 -0
- package/dist/adapters/sandbox/e2b/workflow.d.ts +27 -0
- package/dist/adapters/sandbox/{virtual → e2b}/workflow.js +8 -8
- package/dist/adapters/sandbox/e2b/workflow.js.map +1 -0
- package/dist/adapters/thread/anthropic/index.d.cts +5 -6
- package/dist/adapters/thread/anthropic/index.d.ts +5 -6
- package/dist/adapters/thread/anthropic/workflow.d.cts +4 -5
- package/dist/adapters/thread/anthropic/workflow.d.ts +4 -5
- package/dist/adapters/thread/google-genai/index.d.cts +5 -6
- package/dist/adapters/thread/google-genai/index.d.ts +5 -6
- package/dist/adapters/thread/google-genai/workflow.d.cts +4 -5
- package/dist/adapters/thread/google-genai/workflow.d.ts +4 -5
- package/dist/adapters/thread/langchain/index.cjs +22 -10
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +12 -10
- package/dist/adapters/thread/langchain/index.d.ts +12 -10
- package/dist/adapters/thread/langchain/index.js +22 -10
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +4 -5
- package/dist/adapters/thread/langchain/workflow.d.ts +4 -5
- package/dist/index.cjs +526 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -15
- package/dist/index.d.ts +66 -15
- package/dist/index.js +522 -26
- package/dist/index.js.map +1 -1
- package/dist/{proxy-BK1ydQt0.d.ts → proxy-78nc985d.d.ts} +1 -1
- package/dist/{proxy-BMAsMHdp.d.cts → proxy-Bm2UTiO_.d.cts} +1 -1
- package/dist/{thread-manager-dzaJHQEA.d.ts → thread-manager-07BaYu_z.d.ts} +1 -1
- package/dist/{thread-manager-Bz8txKKj.d.cts → thread-manager-BRE5KkHB.d.cts} +1 -1
- package/dist/{thread-manager-BlHua5_v.d.cts → thread-manager-CatBkarc.d.cts} +1 -1
- package/dist/{thread-manager-Bh9x847n.d.ts → thread-manager-CxbWo7q_.d.ts} +1 -1
- package/dist/types-BkVoEyiH.d.ts +1211 -0
- package/dist/{types-CIkYBoF8.d.ts → types-DAv_SLN8.d.ts} +1 -1
- package/dist/{types-BfIQABzu.d.cts → types-Dpz2gXLk.d.cts} +1 -1
- package/dist/types-seDYom4M.d.cts +1211 -0
- package/dist/workflow-B4T3la0p.d.cts +750 -0
- package/dist/workflow-DCmaXLZ_.d.ts +750 -0
- package/dist/workflow.cjs +198 -21
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +5 -579
- package/dist/workflow.d.ts +5 -579
- package/dist/workflow.js +197 -23
- package/dist/workflow.js.map +1 -1
- package/package.json +23 -23
- package/src/adapters/sandbox/{virtual → e2b}/proxy.ts +16 -13
- package/src/adapters/thread/langchain/hooks.test.ts +195 -0
- package/src/adapters/thread/langchain/hooks.ts +29 -12
- package/src/index.ts +7 -0
- package/src/lib/observability/hooks.ts +117 -0
- package/src/lib/observability/index.ts +13 -0
- package/src/lib/observability/sinks.ts +88 -0
- package/src/lib/sandbox/manager.ts +3 -3
- package/src/lib/session/session-edge-cases.integration.test.ts +1 -0
- package/src/lib/session/session.integration.test.ts +1 -0
- package/src/lib/session/session.ts +79 -5
- package/src/lib/session/types.ts +21 -0
- package/src/lib/state/manager.integration.test.ts +1 -0
- package/src/lib/subagent/handler.ts +22 -2
- package/src/lib/subagent/register.ts +7 -2
- package/src/lib/subagent/subagent.integration.test.ts +1 -0
- package/src/lib/tool-router/router-edge-cases.integration.test.ts +2 -0
- package/src/lib/tool-router/router.integration.test.ts +2 -0
- package/src/lib/tool-router/router.ts +26 -7
- package/src/lib/tool-router/types.ts +0 -4
- package/src/{adapters/sandbox/virtual → lib/virtual-fs}/filesystem.ts +4 -4
- package/src/lib/virtual-fs/index.ts +18 -0
- package/src/lib/virtual-fs/manager.ts +48 -0
- package/src/lib/virtual-fs/proxy.ts +45 -0
- package/src/{adapters/sandbox/virtual → lib/virtual-fs}/types.ts +43 -33
- package/src/{adapters/sandbox/virtual/virtual-sandbox.test.ts → lib/virtual-fs/virtual-fs.test.ts} +15 -130
- package/src/lib/virtual-fs/with-virtual-fs.ts +94 -0
- package/src/workflow.ts +25 -8
- package/tsup.config.ts +3 -2
- package/dist/adapters/sandbox/virtual/index.cjs +0 -487
- package/dist/adapters/sandbox/virtual/index.cjs.map +0 -1
- package/dist/adapters/sandbox/virtual/index.d.cts +0 -90
- package/dist/adapters/sandbox/virtual/index.d.ts +0 -90
- package/dist/adapters/sandbox/virtual/index.js +0 -479
- package/dist/adapters/sandbox/virtual/index.js.map +0 -1
- package/dist/adapters/sandbox/virtual/workflow.cjs.map +0 -1
- package/dist/adapters/sandbox/virtual/workflow.d.cts +0 -28
- package/dist/adapters/sandbox/virtual/workflow.d.ts +0 -28
- package/dist/adapters/sandbox/virtual/workflow.js.map +0 -1
- package/dist/queries-BCgJ9Sr5.d.ts +0 -44
- package/dist/queries-DwnE2bu3.d.cts +0 -44
- package/dist/types-CvJyXDYt.d.ts +0 -490
- package/dist/types-DFUNSYbj.d.ts +0 -125
- package/dist/types-DRnz-OZp.d.cts +0 -125
- package/dist/types-DSOefLpY.d.cts +0 -490
- package/dist/types-mCVxKIZb.d.cts +0 -585
- package/dist/types-mCVxKIZb.d.ts +0 -585
- package/src/adapters/sandbox/virtual/index.ts +0 -92
- package/src/adapters/sandbox/virtual/provider.ts +0 -121
- package/src/adapters/sandbox/virtual/with-virtual-sandbox.ts +0 -97
- /package/src/{adapters/sandbox/virtual → lib/virtual-fs}/mutations.ts +0 -0
- /package/src/{adapters/sandbox/virtual → lib/virtual-fs}/queries.ts +0 -0
- /package/src/{adapters/sandbox/virtual → lib/virtual-fs}/tree.ts +0 -0
package/dist/workflow.cjs
CHANGED
|
@@ -113,7 +113,7 @@ function createToolRouter(options) {
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
async function processToolCall(toolCall, turn, sandboxId
|
|
116
|
+
async function processToolCall(toolCall, turn, sandboxId) {
|
|
117
117
|
const startTime = Date.now();
|
|
118
118
|
const tool = toolMap.get(toolCall.name);
|
|
119
119
|
const preResult = await runPreHooks(toolCall, tool, turn);
|
|
@@ -131,6 +131,11 @@ function createToolRouter(options) {
|
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
const effectiveArgs = preResult.args;
|
|
134
|
+
workflow.log.debug("tool call dispatched", {
|
|
135
|
+
toolName: toolCall.name,
|
|
136
|
+
toolCallId: toolCall.id,
|
|
137
|
+
turn
|
|
138
|
+
});
|
|
134
139
|
let result;
|
|
135
140
|
let content;
|
|
136
141
|
let resultAppended = false;
|
|
@@ -142,8 +147,7 @@ function createToolRouter(options) {
|
|
|
142
147
|
...options.threadKey && { threadKey: options.threadKey },
|
|
143
148
|
toolCallId: toolCall.id,
|
|
144
149
|
toolName: toolCall.name,
|
|
145
|
-
...sandboxId !== void 0 && { sandboxId }
|
|
146
|
-
...sandboxStateUpdate && { sandboxStateUpdate }
|
|
150
|
+
...sandboxId !== void 0 && { sandboxId }
|
|
147
151
|
};
|
|
148
152
|
const response = await tool.handler(
|
|
149
153
|
effectiveArgs,
|
|
@@ -158,6 +162,13 @@ function createToolRouter(options) {
|
|
|
158
162
|
content = JSON.stringify(result, null, 2);
|
|
159
163
|
}
|
|
160
164
|
} catch (error) {
|
|
165
|
+
workflow.log.warn("tool call failed", {
|
|
166
|
+
toolName: toolCall.name,
|
|
167
|
+
toolCallId: toolCall.id,
|
|
168
|
+
turn,
|
|
169
|
+
durationMs: Date.now() - startTime,
|
|
170
|
+
error: error instanceof Error ? error.message : String(error)
|
|
171
|
+
});
|
|
161
172
|
const recovery = await runFailureHooks(
|
|
162
173
|
toolCall,
|
|
163
174
|
tool,
|
|
@@ -183,19 +194,26 @@ function createToolRouter(options) {
|
|
|
183
194
|
[workflow.uuid4(), config]
|
|
184
195
|
);
|
|
185
196
|
}
|
|
197
|
+
const durationMs = Date.now() - startTime;
|
|
186
198
|
const toolResult = {
|
|
187
199
|
toolCallId: toolCall.id,
|
|
188
200
|
name: toolCall.name,
|
|
189
201
|
data: result,
|
|
190
202
|
...metadata && { metadata }
|
|
191
203
|
};
|
|
204
|
+
workflow.log.debug("tool call completed", {
|
|
205
|
+
toolName: toolCall.name,
|
|
206
|
+
toolCallId: toolCall.id,
|
|
207
|
+
turn,
|
|
208
|
+
durationMs
|
|
209
|
+
});
|
|
192
210
|
await runPostHooks(
|
|
193
211
|
toolCall,
|
|
194
212
|
tool,
|
|
195
213
|
toolResult,
|
|
196
214
|
effectiveArgs,
|
|
197
215
|
turn,
|
|
198
|
-
|
|
216
|
+
durationMs
|
|
199
217
|
);
|
|
200
218
|
return toolResult;
|
|
201
219
|
}
|
|
@@ -237,10 +255,9 @@ function createToolRouter(options) {
|
|
|
237
255
|
}
|
|
238
256
|
const turn = context?.turn ?? 0;
|
|
239
257
|
const sandboxId = context?.sandboxId;
|
|
240
|
-
const sandboxStateUpdate = context?.sandboxStateUpdate;
|
|
241
258
|
if (options.parallel) {
|
|
242
259
|
const results2 = await Promise.all(
|
|
243
|
-
toolCalls.map((tc) => processToolCall(tc, turn, sandboxId
|
|
260
|
+
toolCalls.map((tc) => processToolCall(tc, turn, sandboxId))
|
|
244
261
|
);
|
|
245
262
|
return results2.filter(
|
|
246
263
|
(r) => r !== null
|
|
@@ -248,7 +265,7 @@ function createToolRouter(options) {
|
|
|
248
265
|
}
|
|
249
266
|
const results = [];
|
|
250
267
|
for (const toolCall of toolCalls) {
|
|
251
|
-
const result = await processToolCall(toolCall, turn, sandboxId
|
|
268
|
+
const result = await processToolCall(toolCall, turn, sandboxId);
|
|
252
269
|
if (result !== null) {
|
|
253
270
|
results.push(result);
|
|
254
271
|
}
|
|
@@ -384,7 +401,7 @@ function resolveSandboxConfig(config) {
|
|
|
384
401
|
if (config === "own") return { source: "own" };
|
|
385
402
|
return { source: "own", shutdown: config.shutdown };
|
|
386
403
|
}
|
|
387
|
-
function createSubagentHandler(subagents) {
|
|
404
|
+
function createSubagentHandler(subagents, options) {
|
|
388
405
|
const { taskQueue: parentTaskQueue } = workflow.workflowInfo();
|
|
389
406
|
const childResults = /* @__PURE__ */ new Map();
|
|
390
407
|
const pendingDestroys = /* @__PURE__ */ new Map();
|
|
@@ -416,10 +433,11 @@ function createSubagentHandler(subagents) {
|
|
|
416
433
|
}
|
|
417
434
|
let sandbox;
|
|
418
435
|
if (sandboxCfg.source === "inherit" && parentSandboxId) {
|
|
436
|
+
const stateUpdate = options?.getSandboxStateForInheritance?.();
|
|
419
437
|
sandbox = {
|
|
420
438
|
mode: "inherit",
|
|
421
439
|
sandboxId: parentSandboxId,
|
|
422
|
-
...
|
|
440
|
+
...stateUpdate && { stateUpdate }
|
|
423
441
|
};
|
|
424
442
|
} else if (sandboxCfg.source === "own") {
|
|
425
443
|
const prevSbId = continuationThreadId ? threadSandboxes.get(continuationThreadId) : void 0;
|
|
@@ -438,6 +456,12 @@ function createSubagentHandler(subagents) {
|
|
|
438
456
|
args: resolvedContext === void 0 ? [args.prompt, workflowInput] : [args.prompt, workflowInput, resolvedContext],
|
|
439
457
|
taskQueue: config.taskQueue ?? parentTaskQueue
|
|
440
458
|
};
|
|
459
|
+
workflow.log.info("subagent spawned", {
|
|
460
|
+
subagent: config.agentName,
|
|
461
|
+
childWorkflowId,
|
|
462
|
+
threadMode,
|
|
463
|
+
sandboxSource: sandboxCfg.source
|
|
464
|
+
});
|
|
441
465
|
const childHandle = await workflow.startChild(config.workflow, childOpts);
|
|
442
466
|
const effectiveShutdown = sandboxCfg.shutdown ?? "destroy";
|
|
443
467
|
const shouldDeferDestroy = effectiveShutdown === "pause-until-parent-close" && (sandboxCfg.source === "own" || allowsContinuation && sandboxCfg.source !== "inherit");
|
|
@@ -454,11 +478,20 @@ function createSubagentHandler(subagents) {
|
|
|
454
478
|
const childResult = childResults.get(childWorkflowId);
|
|
455
479
|
childResults.delete(childWorkflowId);
|
|
456
480
|
if (!childResult) {
|
|
481
|
+
workflow.log.warn("subagent returned no result", {
|
|
482
|
+
subagent: config.agentName,
|
|
483
|
+
childWorkflowId
|
|
484
|
+
});
|
|
457
485
|
return {
|
|
458
486
|
toolResponse: "Subagent workflow did not signal a result",
|
|
459
487
|
data: null
|
|
460
488
|
};
|
|
461
489
|
}
|
|
490
|
+
workflow.log.info("subagent completed", {
|
|
491
|
+
subagent: config.agentName,
|
|
492
|
+
childWorkflowId,
|
|
493
|
+
...childResult.usage && { usage: childResult.usage }
|
|
494
|
+
});
|
|
462
495
|
const {
|
|
463
496
|
toolResponse,
|
|
464
497
|
data,
|
|
@@ -524,7 +557,7 @@ function createSubagentHandler(subagents) {
|
|
|
524
557
|
}
|
|
525
558
|
|
|
526
559
|
// src/lib/subagent/register.ts
|
|
527
|
-
function buildSubagentRegistration(subagents) {
|
|
560
|
+
function buildSubagentRegistration(subagents, options) {
|
|
528
561
|
if (subagents.length === 0) return null;
|
|
529
562
|
const getEnabled = () => subagents.filter(
|
|
530
563
|
(s) => typeof s.enabled === "function" ? s.enabled() : s.enabled ?? true
|
|
@@ -534,7 +567,9 @@ function buildSubagentRegistration(subagents) {
|
|
|
534
567
|
if (s.hooks) subagentHooksMap.set(s.agentName, s.hooks);
|
|
535
568
|
}
|
|
536
569
|
const resolveSubagentName = (args) => args.subagent;
|
|
537
|
-
const { handler, destroySubagentSandboxes } = createSubagentHandler(subagents
|
|
570
|
+
const { handler, destroySubagentSandboxes } = createSubagentHandler(subagents, {
|
|
571
|
+
getSandboxStateForInheritance: options?.getSandboxStateForInheritance
|
|
572
|
+
});
|
|
538
573
|
const registration = {
|
|
539
574
|
name: SUBAGENT_TOOL_NAME,
|
|
540
575
|
enabled: () => getEnabled().length > 0,
|
|
@@ -673,7 +708,8 @@ async function createSession({
|
|
|
673
708
|
sandboxOps,
|
|
674
709
|
thread: threadInit,
|
|
675
710
|
sandbox: sandboxInit,
|
|
676
|
-
sandboxShutdown = "destroy"
|
|
711
|
+
sandboxShutdown = "destroy",
|
|
712
|
+
virtualFs: virtualFsConfig
|
|
677
713
|
}) {
|
|
678
714
|
const threadMode = threadInit?.mode ?? "new";
|
|
679
715
|
let threadId;
|
|
@@ -699,8 +735,11 @@ async function createSession({
|
|
|
699
735
|
} = threadOps;
|
|
700
736
|
const plugins = [];
|
|
701
737
|
let destroySubagentSandboxes;
|
|
738
|
+
let sandboxStateGetter;
|
|
702
739
|
if (subagents) {
|
|
703
|
-
const result = buildSubagentRegistration(subagents
|
|
740
|
+
const result = buildSubagentRegistration(subagents, {
|
|
741
|
+
getSandboxStateForInheritance: () => sandboxStateGetter?.()
|
|
742
|
+
});
|
|
704
743
|
if (result) {
|
|
705
744
|
plugins.push(result.registration);
|
|
706
745
|
destroySubagentSandboxes = result.destroySubagentSandboxes;
|
|
@@ -756,12 +795,21 @@ async function createSession({
|
|
|
756
795
|
const sandboxMode = sandboxInit?.mode;
|
|
757
796
|
let sandboxId;
|
|
758
797
|
let sandboxOwned = false;
|
|
759
|
-
|
|
798
|
+
sandboxStateGetter = () => {
|
|
799
|
+
const fileTree = stateManager.get("fileTree");
|
|
800
|
+
const resolverContext = stateManager.get("resolverContext");
|
|
801
|
+
const workspaceBase = stateManager.get("workspaceBase");
|
|
802
|
+
if (!fileTree && !resolverContext && !workspaceBase) return void 0;
|
|
803
|
+
return {
|
|
804
|
+
...fileTree !== void 0 && { fileTree },
|
|
805
|
+
...resolverContext !== void 0 && { resolverContext },
|
|
806
|
+
...workspaceBase !== void 0 && { workspaceBase }
|
|
807
|
+
};
|
|
808
|
+
};
|
|
760
809
|
if (sandboxMode === "inherit") {
|
|
761
810
|
const inheritInit = sandboxInit;
|
|
762
811
|
sandboxId = inheritInit.sandboxId;
|
|
763
812
|
if (inheritInit.stateUpdate) {
|
|
764
|
-
sandboxStateUpdate = inheritInit.stateUpdate;
|
|
765
813
|
stateManager.mergeUpdate(inheritInit.stateUpdate);
|
|
766
814
|
}
|
|
767
815
|
if (!sandboxOps) {
|
|
@@ -798,10 +846,20 @@ async function createSession({
|
|
|
798
846
|
sandboxId = result.sandboxId;
|
|
799
847
|
sandboxOwned = true;
|
|
800
848
|
if (result.stateUpdate) {
|
|
801
|
-
sandboxStateUpdate = result.stateUpdate;
|
|
802
849
|
stateManager.mergeUpdate(result.stateUpdate);
|
|
803
850
|
}
|
|
804
851
|
}
|
|
852
|
+
if (virtualFsConfig) {
|
|
853
|
+
const result = await virtualFsConfig.ops.resolveFileTree(
|
|
854
|
+
virtualFsConfig.resolverContext
|
|
855
|
+
);
|
|
856
|
+
stateManager.mergeUpdate({
|
|
857
|
+
fileTree: result.fileTree,
|
|
858
|
+
resolverContext: virtualFsConfig.resolverContext,
|
|
859
|
+
workspaceBase: virtualFsConfig.workspaceBase ?? "/",
|
|
860
|
+
...result.stateUpdate
|
|
861
|
+
});
|
|
862
|
+
}
|
|
805
863
|
if (hooks.onSessionStart) {
|
|
806
864
|
await hooks.onSessionStart({
|
|
807
865
|
threadId,
|
|
@@ -809,6 +867,14 @@ async function createSession({
|
|
|
809
867
|
metadata
|
|
810
868
|
});
|
|
811
869
|
}
|
|
870
|
+
workflow.log.info("session started", {
|
|
871
|
+
agentName,
|
|
872
|
+
threadId,
|
|
873
|
+
threadMode,
|
|
874
|
+
maxTurns,
|
|
875
|
+
...sandboxId && { sandboxId }
|
|
876
|
+
});
|
|
877
|
+
const sessionStartMs = Date.now();
|
|
812
878
|
const systemPrompt = stateManager.getSystemPrompt();
|
|
813
879
|
if (threadMode === "fork" && sourceThreadId) {
|
|
814
880
|
await forkThread(sourceThreadId, threadId, threadKey);
|
|
@@ -831,6 +897,7 @@ async function createSession({
|
|
|
831
897
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
832
898
|
stateManager.incrementTurns();
|
|
833
899
|
const currentTurn = stateManager.getTurns();
|
|
900
|
+
workflow.log.debug("turn started", { agentName, threadId, turn: currentTurn });
|
|
834
901
|
stateManager.setTools(toolRouter.getToolDefinitions());
|
|
835
902
|
const { message, rawToolCalls, usage } = await runAgent({
|
|
836
903
|
threadId,
|
|
@@ -841,9 +908,24 @@ async function createSession({
|
|
|
841
908
|
if (usage) {
|
|
842
909
|
stateManager.updateUsage(usage);
|
|
843
910
|
}
|
|
911
|
+
workflow.log.debug("model response received", {
|
|
912
|
+
agentName,
|
|
913
|
+
threadId,
|
|
914
|
+
turn: currentTurn,
|
|
915
|
+
toolCallCount: rawToolCalls.length,
|
|
916
|
+
...usage && { usage }
|
|
917
|
+
});
|
|
844
918
|
if (!toolRouter.hasTools() || rawToolCalls.length === 0) {
|
|
845
919
|
stateManager.complete();
|
|
846
920
|
exitReason = "completed";
|
|
921
|
+
workflow.log.info("session ended", {
|
|
922
|
+
agentName,
|
|
923
|
+
threadId,
|
|
924
|
+
exitReason,
|
|
925
|
+
turns: currentTurn,
|
|
926
|
+
durationMs: Date.now() - sessionStartMs,
|
|
927
|
+
usage: stateManager.getTotalUsage()
|
|
928
|
+
});
|
|
847
929
|
return {
|
|
848
930
|
threadId,
|
|
849
931
|
finalMessage: message,
|
|
@@ -872,8 +954,7 @@ async function createSession({
|
|
|
872
954
|
parsedToolCalls,
|
|
873
955
|
{
|
|
874
956
|
turn: currentTurn,
|
|
875
|
-
...sandboxId !== void 0 && { sandboxId }
|
|
876
|
-
...sandboxStateUpdate && { sandboxStateUpdate }
|
|
957
|
+
...sandboxId !== void 0 && { sandboxId }
|
|
877
958
|
}
|
|
878
959
|
);
|
|
879
960
|
for (const result of toolCallResults) {
|
|
@@ -896,9 +977,21 @@ async function createSession({
|
|
|
896
977
|
}
|
|
897
978
|
if (stateManager.getTurns() >= maxTurns && stateManager.isRunning()) {
|
|
898
979
|
exitReason = "max_turns";
|
|
980
|
+
workflow.log.warn("session hit max turns", {
|
|
981
|
+
agentName,
|
|
982
|
+
threadId,
|
|
983
|
+
maxTurns
|
|
984
|
+
});
|
|
899
985
|
}
|
|
900
986
|
} catch (error) {
|
|
901
987
|
exitReason = "failed";
|
|
988
|
+
workflow.log.error("session failed", {
|
|
989
|
+
agentName,
|
|
990
|
+
threadId,
|
|
991
|
+
turns: stateManager.getTurns(),
|
|
992
|
+
durationMs: Date.now() - sessionStartMs,
|
|
993
|
+
error: error instanceof Error ? error.message : String(error)
|
|
994
|
+
});
|
|
902
995
|
throw workflow.ApplicationFailure.fromError(error);
|
|
903
996
|
} finally {
|
|
904
997
|
await callSessionEnd(exitReason, stateManager.getTurns());
|
|
@@ -917,6 +1010,14 @@ async function createSession({
|
|
|
917
1010
|
await destroySubagentSandboxes();
|
|
918
1011
|
}
|
|
919
1012
|
}
|
|
1013
|
+
workflow.log.info("session ended", {
|
|
1014
|
+
agentName,
|
|
1015
|
+
threadId,
|
|
1016
|
+
exitReason,
|
|
1017
|
+
turns: stateManager.getTurns(),
|
|
1018
|
+
durationMs: Date.now() - sessionStartMs,
|
|
1019
|
+
usage: stateManager.getTotalUsage()
|
|
1020
|
+
});
|
|
920
1021
|
return {
|
|
921
1022
|
threadId,
|
|
922
1023
|
finalMessage: null,
|
|
@@ -1176,6 +1277,60 @@ function defineSubagentWorkflow(config, fn) {
|
|
|
1176
1277
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1177
1278
|
});
|
|
1178
1279
|
}
|
|
1280
|
+
function createObservabilityHooks(agentName) {
|
|
1281
|
+
const { zeitlichMetrics } = workflow.proxySinks();
|
|
1282
|
+
let sessionStartMs = Date.now();
|
|
1283
|
+
return {
|
|
1284
|
+
onSessionStart: (ctx) => {
|
|
1285
|
+
sessionStartMs = Date.now();
|
|
1286
|
+
zeitlichMetrics.sessionStarted({
|
|
1287
|
+
agentName,
|
|
1288
|
+
threadId: ctx.threadId,
|
|
1289
|
+
metadata: ctx.metadata
|
|
1290
|
+
});
|
|
1291
|
+
},
|
|
1292
|
+
onSessionEnd: (ctx) => {
|
|
1293
|
+
zeitlichMetrics.sessionEnded({
|
|
1294
|
+
agentName,
|
|
1295
|
+
threadId: ctx.threadId,
|
|
1296
|
+
exitReason: ctx.exitReason,
|
|
1297
|
+
turns: ctx.turns,
|
|
1298
|
+
usage: {},
|
|
1299
|
+
durationMs: Date.now() - sessionStartMs
|
|
1300
|
+
});
|
|
1301
|
+
},
|
|
1302
|
+
onPostToolUse: (ctx) => {
|
|
1303
|
+
zeitlichMetrics.toolExecuted({
|
|
1304
|
+
agentName,
|
|
1305
|
+
toolName: ctx.toolCall.name,
|
|
1306
|
+
durationMs: ctx.durationMs,
|
|
1307
|
+
success: true,
|
|
1308
|
+
threadId: ctx.threadId,
|
|
1309
|
+
turn: ctx.turn
|
|
1310
|
+
});
|
|
1311
|
+
},
|
|
1312
|
+
onPostToolUseFailure: (ctx) => {
|
|
1313
|
+
zeitlichMetrics.toolExecuted({
|
|
1314
|
+
agentName,
|
|
1315
|
+
toolName: ctx.toolCall.name,
|
|
1316
|
+
durationMs: 0,
|
|
1317
|
+
success: false,
|
|
1318
|
+
threadId: ctx.threadId,
|
|
1319
|
+
turn: ctx.turn
|
|
1320
|
+
});
|
|
1321
|
+
return {};
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
function composeHooks(...fns) {
|
|
1326
|
+
return async (...args) => {
|
|
1327
|
+
let lastResult;
|
|
1328
|
+
for (const fn of fns) {
|
|
1329
|
+
lastResult = await fn(...args);
|
|
1330
|
+
}
|
|
1331
|
+
return lastResult;
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1179
1334
|
var SandboxNotSupportedError = class extends common.ApplicationFailure {
|
|
1180
1335
|
constructor(operation) {
|
|
1181
1336
|
super(
|
|
@@ -1191,7 +1346,7 @@ var SandboxNotFoundError = class extends common.ApplicationFailure {
|
|
|
1191
1346
|
}
|
|
1192
1347
|
};
|
|
1193
1348
|
|
|
1194
|
-
// src/
|
|
1349
|
+
// src/lib/virtual-fs/mutations.ts
|
|
1195
1350
|
function applyVirtualTreeMutations(stateManager, mutations) {
|
|
1196
1351
|
let tree = [...stateManager.get("fileTree")];
|
|
1197
1352
|
for (const m of mutations) {
|
|
@@ -1213,7 +1368,7 @@ function applyVirtualTreeMutations(stateManager, mutations) {
|
|
|
1213
1368
|
return tree;
|
|
1214
1369
|
}
|
|
1215
1370
|
|
|
1216
|
-
// src/
|
|
1371
|
+
// src/lib/virtual-fs/tree.ts
|
|
1217
1372
|
var buildTree = (entries) => {
|
|
1218
1373
|
const root = { name: "/", children: /* @__PURE__ */ new Map(), isFile: false };
|
|
1219
1374
|
for (const entry of entries) {
|
|
@@ -1261,7 +1416,7 @@ function formatVirtualFileTree(entries, opts = {}) {
|
|
|
1261
1416
|
return "/" + printNode(root, "", sort);
|
|
1262
1417
|
}
|
|
1263
1418
|
|
|
1264
|
-
// src/
|
|
1419
|
+
// src/lib/virtual-fs/queries.ts
|
|
1265
1420
|
function hasFileWithMimeType(stateManager, pattern) {
|
|
1266
1421
|
const tree = stateManager.get("fileTree");
|
|
1267
1422
|
const matchers = (Array.isArray(pattern) ? pattern : [pattern]).map(buildMatcher);
|
|
@@ -1302,6 +1457,25 @@ function buildGlobMatcher(pattern) {
|
|
|
1302
1457
|
);
|
|
1303
1458
|
return (v) => re.test(v);
|
|
1304
1459
|
}
|
|
1460
|
+
function proxyVirtualFsOps(scope, options) {
|
|
1461
|
+
const resolvedScope = scope ?? workflow.workflowInfo().workflowType;
|
|
1462
|
+
const acts = workflow.proxyActivities(
|
|
1463
|
+
options ?? {
|
|
1464
|
+
startToCloseTimeout: "30s",
|
|
1465
|
+
retry: {
|
|
1466
|
+
maximumAttempts: 3,
|
|
1467
|
+
initialInterval: "2s",
|
|
1468
|
+
maximumInterval: "30s",
|
|
1469
|
+
backoffCoefficient: 2
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
);
|
|
1473
|
+
const prefix = resolvedScope;
|
|
1474
|
+
const p = (key) => `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;
|
|
1475
|
+
return {
|
|
1476
|
+
resolveFileTree: acts[p("resolveFileTree")]
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1305
1479
|
|
|
1306
1480
|
// src/lib/skills/parse.ts
|
|
1307
1481
|
function parseSkillFile(raw) {
|
|
@@ -1732,9 +1906,11 @@ exports.SandboxNotSupportedError = SandboxNotSupportedError;
|
|
|
1732
1906
|
exports.applyVirtualTreeMutations = applyVirtualTreeMutations;
|
|
1733
1907
|
exports.askUserQuestionTool = askUserQuestionTool;
|
|
1734
1908
|
exports.bashTool = bashTool;
|
|
1909
|
+
exports.composeHooks = composeHooks;
|
|
1735
1910
|
exports.createAgentStateManager = createAgentStateManager;
|
|
1736
1911
|
exports.createAskUserQuestionHandler = createAskUserQuestionHandler;
|
|
1737
1912
|
exports.createBashToolDescription = createBashToolDescription;
|
|
1913
|
+
exports.createObservabilityHooks = createObservabilityHooks;
|
|
1738
1914
|
exports.createReadSkillHandler = createReadSkillHandler;
|
|
1739
1915
|
exports.createReadSkillTool = createReadSkillTool;
|
|
1740
1916
|
exports.createSession = createSession;
|
|
@@ -1758,6 +1934,7 @@ exports.hasFileWithMimeType = hasFileWithMimeType;
|
|
|
1758
1934
|
exports.hasNoOtherToolCalls = hasNoOtherToolCalls;
|
|
1759
1935
|
exports.isTerminalStatus = isTerminalStatus;
|
|
1760
1936
|
exports.parseSkillFile = parseSkillFile;
|
|
1937
|
+
exports.proxyVirtualFsOps = proxyVirtualFsOps;
|
|
1761
1938
|
exports.readFileTool = readFileTool;
|
|
1762
1939
|
exports.taskCreateTool = taskCreateTool;
|
|
1763
1940
|
exports.taskGetTool = taskGetTool;
|