zeitlich 0.2.4 → 0.2.6
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 +70 -40
- package/dist/index.cjs +71 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +72 -37
- package/dist/index.js.map +1 -1
- package/dist/{workflow-PjeURKw4.d.cts → workflow-Dg5JMeOC.d.cts} +18 -4
- package/dist/{workflow-PjeURKw4.d.ts → workflow-Dg5JMeOC.d.ts} +18 -4
- package/dist/workflow.cjs +52 -35
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +1 -1
- package/dist/workflow.d.ts +1 -1
- package/dist/workflow.js +52 -35
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/activities.ts +11 -0
- package/src/index.ts +4 -4
- package/src/lib/model-invoker.ts +5 -4
- package/src/lib/session.ts +17 -4
- package/src/lib/thread-manager.ts +15 -3
- package/src/lib/tool-router.ts +40 -31
- package/src/lib/types.ts +10 -2
- package/src/tools/subagent/handler.ts +4 -5
- package/src/tools/subagent/tool.ts +3 -3
- package/src/workflow.ts +2 -2
package/dist/workflow.js
CHANGED
|
@@ -4,7 +4,7 @@ import z3, { z } from 'zod';
|
|
|
4
4
|
// src/lib/session.ts
|
|
5
5
|
var SUBAGENT_TOOL = "Subagent";
|
|
6
6
|
function buildSubagentDescription(subagents) {
|
|
7
|
-
const subagentList = subagents.map((s) => `- **${s.
|
|
7
|
+
const subagentList = subagents.map((s) => `- **${s.agentName}**: ${s.description}`).join("\n");
|
|
8
8
|
return `Launch a new agent to handle complex tasks autonomously.
|
|
9
9
|
|
|
10
10
|
The ${SUBAGENT_TOOL} tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
|
|
@@ -30,7 +30,7 @@ function createSubagentTool(subagents) {
|
|
|
30
30
|
if (subagents.length === 0) {
|
|
31
31
|
throw new Error("createTaskTool requires at least one subagent");
|
|
32
32
|
}
|
|
33
|
-
const names = subagents.map((s) => s.
|
|
33
|
+
const names = subagents.map((s) => s.agentName);
|
|
34
34
|
return {
|
|
35
35
|
name: SUBAGENT_TOOL,
|
|
36
36
|
description: buildSubagentDescription(subagents),
|
|
@@ -42,15 +42,15 @@ function createSubagentTool(subagents) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
function createSubagentHandler(subagents) {
|
|
45
|
-
const {
|
|
45
|
+
const { taskQueue: parentTaskQueue } = workflowInfo();
|
|
46
46
|
return async (args) => {
|
|
47
|
-
const config = subagents.find((s) => s.
|
|
47
|
+
const config = subagents.find((s) => s.agentName === args.subagent);
|
|
48
48
|
if (!config) {
|
|
49
49
|
throw new Error(
|
|
50
|
-
`Unknown subagent: ${args.subagent}. Available: ${subagents.map((s) => s.
|
|
50
|
+
`Unknown subagent: ${args.subagent}. Available: ${subagents.map((s) => s.agentName).join(", ")}`
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
|
-
const childWorkflowId = `${
|
|
53
|
+
const childWorkflowId = `${args.subagent}-${uuid4()}`;
|
|
54
54
|
const input = {
|
|
55
55
|
prompt: args.prompt,
|
|
56
56
|
...config.context && { context: config.context }
|
|
@@ -78,31 +78,36 @@ function createToolRouter(options) {
|
|
|
78
78
|
}
|
|
79
79
|
const isEnabled = (tool) => tool.enabled !== false;
|
|
80
80
|
if (options.subagents) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
81
|
+
const enabledSubagents = options.subagents.filter(
|
|
82
|
+
(s) => s.enabled !== false
|
|
83
|
+
);
|
|
84
|
+
if (enabledSubagents.length > 0) {
|
|
85
|
+
const subagentHooksMap = /* @__PURE__ */ new Map();
|
|
86
|
+
for (const s of enabledSubagents) {
|
|
87
|
+
if (s.hooks) subagentHooksMap.set(s.agentName, s.hooks);
|
|
88
|
+
}
|
|
89
|
+
const resolveSubagentName = (args) => args.subagent;
|
|
90
|
+
toolMap.set("Subagent", {
|
|
91
|
+
...createSubagentTool(enabledSubagents),
|
|
92
|
+
handler: createSubagentHandler(enabledSubagents),
|
|
93
|
+
...subagentHooksMap.size > 0 && {
|
|
94
|
+
hooks: {
|
|
95
|
+
onPreToolUse: async (ctx) => {
|
|
96
|
+
const hooks = subagentHooksMap.get(resolveSubagentName(ctx.args));
|
|
97
|
+
return hooks?.onPreExecution?.(ctx) ?? {};
|
|
98
|
+
},
|
|
99
|
+
onPostToolUse: async (ctx) => {
|
|
100
|
+
const hooks = subagentHooksMap.get(resolveSubagentName(ctx.args));
|
|
101
|
+
await hooks?.onPostExecution?.(ctx);
|
|
102
|
+
},
|
|
103
|
+
onPostToolUseFailure: async (ctx) => {
|
|
104
|
+
const hooks = subagentHooksMap.get(resolveSubagentName(ctx.args));
|
|
105
|
+
return hooks?.onExecutionFailure?.(ctx) ?? {};
|
|
106
|
+
}
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
106
111
|
}
|
|
107
112
|
async function processToolCall(toolCall, turn, handlerContext) {
|
|
108
113
|
const startTime = Date.now();
|
|
@@ -383,11 +388,19 @@ var createSession = async ({
|
|
|
383
388
|
subagents,
|
|
384
389
|
tools = {},
|
|
385
390
|
processToolsInParallel = true,
|
|
386
|
-
hooks = {}
|
|
391
|
+
hooks = {},
|
|
392
|
+
appendSystemPrompt = true,
|
|
393
|
+
systemPrompt
|
|
387
394
|
}) => {
|
|
395
|
+
const {
|
|
396
|
+
appendToolResult,
|
|
397
|
+
appendHumanMessage,
|
|
398
|
+
initializeThread,
|
|
399
|
+
appendSystemMessage
|
|
400
|
+
} = threadOps ?? proxyDefaultThreadOps();
|
|
388
401
|
const toolRouter = createToolRouter({
|
|
389
402
|
tools,
|
|
390
|
-
appendToolResult
|
|
403
|
+
appendToolResult,
|
|
391
404
|
threadId,
|
|
392
405
|
hooks,
|
|
393
406
|
subagents,
|
|
@@ -414,8 +427,11 @@ var createSession = async ({
|
|
|
414
427
|
});
|
|
415
428
|
}
|
|
416
429
|
stateManager.setTools(toolRouter.getToolDefinitions());
|
|
417
|
-
await
|
|
418
|
-
|
|
430
|
+
await initializeThread(threadId);
|
|
431
|
+
if (appendSystemPrompt && systemPrompt && systemPrompt.trim() !== "") {
|
|
432
|
+
await appendSystemMessage(threadId, systemPrompt);
|
|
433
|
+
}
|
|
434
|
+
await appendHumanMessage(threadId, await buildContextMessage());
|
|
419
435
|
let exitReason = "completed";
|
|
420
436
|
try {
|
|
421
437
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
@@ -436,7 +452,7 @@ var createSession = async ({
|
|
|
436
452
|
try {
|
|
437
453
|
parsedToolCalls.push(toolRouter.parseToolCall(tc));
|
|
438
454
|
} catch (error) {
|
|
439
|
-
await
|
|
455
|
+
await appendToolResult({
|
|
440
456
|
threadId,
|
|
441
457
|
toolCallId: tc.id ?? "",
|
|
442
458
|
toolName: tc.name,
|
|
@@ -483,7 +499,8 @@ function proxyDefaultThreadOps(options) {
|
|
|
483
499
|
return {
|
|
484
500
|
initializeThread: activities.initializeThread,
|
|
485
501
|
appendHumanMessage: activities.appendHumanMessage,
|
|
486
|
-
appendToolResult: activities.appendToolResult
|
|
502
|
+
appendToolResult: activities.appendToolResult,
|
|
503
|
+
appendSystemMessage: activities.appendSystemMessage
|
|
487
504
|
};
|
|
488
505
|
}
|
|
489
506
|
|