zeitlich 0.2.6 → 0.2.8
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/index.cjs +200 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -11
- package/dist/index.d.ts +4 -11
- package/dist/index.js +179 -97
- package/dist/index.js.map +1 -1
- package/dist/{workflow-Dg5JMeOC.d.cts → workflow-BdAuMMjY.d.cts} +129 -37
- package/dist/{workflow-Dg5JMeOC.d.ts → workflow-BdAuMMjY.d.ts} +129 -37
- package/dist/workflow.cjs +195 -101
- 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 +172 -79
- package/dist/workflow.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +0 -2
- package/src/lib/model-invoker.ts +9 -6
- package/src/lib/session.ts +86 -15
- package/src/lib/state-manager.ts +84 -7
- package/src/lib/tool-router.ts +12 -10
- package/src/lib/types.ts +74 -11
- package/src/tools/ask-user-question/handler.ts +19 -20
- package/src/tools/subagent/handler.ts +2 -1
- package/src/workflow.ts +5 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { A as AgentResponse, a as ActivityToolHandler,
|
|
2
|
-
export {
|
|
1
|
+
import { A as AgentResponse, a as ActivityToolHandler, G as GlobArgs, F as FileEditArgs, B as BashArgs } from './workflow-BdAuMMjY.cjs';
|
|
2
|
+
export { b as AGENT_HANDLER_NAMES, c as AgentConfig, d as AgentFile, e as AgentState, f as AgentStateManager, g as AgentStatus, h as AppendToolResultFn, i as AskUserQuestionArgs, j as BaseAgentState, k as BaseThreadManager, l as FileReadArgs, m as FileWriteArgs, n as GrepArgs, I as InferToolResults, J as JsonPrimitive, o as JsonSerializable, p as JsonValue, P as ParsedToolCall, q as ParsedToolCallUnion, r as PostToolUseFailureHook, s as PostToolUseFailureHookContext, t as PostToolUseFailureHookResult, u as PostToolUseHook, v as PostToolUseHookContext, w as PreToolUseHook, x as PreToolUseHookContext, y as PreToolUseHookResult, z as ProcessToolCallsContext, R as RawToolCall, C as RunAgentActivity, D as RunAgentConfig, S as SessionEndHook, E as SessionEndHookContext, H as SessionExitReason, K as SessionLifecycleHooks, L as SessionStartHook, M as SessionStartHookContext, N as SubagentArgs, O as SubagentConfig, Q as SubagentHooks, T as SubagentInput, U as TaskCreateArgs, V as TaskGetArgs, W as TaskListArgs, X as TaskStatus, Y as TaskUpdateArgs, Z as ThreadManager, _ as ThreadManagerConfig, $ as ThreadOps, a0 as ToolArgs, a1 as ToolCallResult, a2 as ToolCallResultUnion, a3 as ToolDefinition, a4 as ToolHandler, a5 as ToolHandlerContext, a6 as ToolHandlerResponse, a7 as ToolHooks, a8 as ToolMap, a9 as ToolMessageContent, aa as ToolNames, ab as ToolResult, ac as ToolResultConfig, ad as ToolRouter, ae as ToolWithHandler, af as WorkflowTask, ag as ZeitlichSession, ah as ZeitlichSharedActivities, ai as askUserQuestionTool, aj as bashTool, ak as createAgentStateManager, al as createAskUserQuestionHandler, am as createBashToolDescription, an as createSession, ao as createSharedActivities, ap as createSubagentTool, aq as createTaskCreateHandler, ar as createTaskGetHandler, as as createTaskListHandler, at as createTaskUpdateHandler, au as createThreadManager, av as createToolRouter, aw as defineSubagent, ax as defineTool, ay as editTool, az as globTool, aA as grepTool, aB as hasNoOtherToolCalls, aC as isTerminalStatus, aD as proxyDefaultThreadOps, aE as readTool, aF as taskCreateTool, aG as taskGetTool, aH as taskListTool, aI as taskUpdateTool, aJ as withAutoAppend, aK as writeTool } from './workflow-BdAuMMjY.cjs';
|
|
3
3
|
import { SimplePlugin } from '@temporalio/plugin';
|
|
4
4
|
import Redis from 'ioredis';
|
|
5
5
|
import { WorkflowClient } from '@temporalio/client';
|
|
6
6
|
import { BaseChatModel, BaseChatModelCallOptions, BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
7
|
-
import { StoredMessage } from '@langchain/core/messages';
|
|
8
7
|
import { IFileSystem, BashOptions } from 'just-bash';
|
|
9
8
|
import '@temporalio/workflow';
|
|
9
|
+
import '@langchain/core/messages';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import '@temporalio/common';
|
|
12
12
|
|
|
@@ -55,13 +55,6 @@ declare function invokeModel({ redis, model, client, config: { threadId, agentNa
|
|
|
55
55
|
}>;
|
|
56
56
|
}): Promise<AgentResponse>;
|
|
57
57
|
|
|
58
|
-
/**
|
|
59
|
-
* Creates handler for user interaction tool - creates AI messages for display.
|
|
60
|
-
*/
|
|
61
|
-
declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQuestionArgs, {
|
|
62
|
-
chatMessages: StoredMessage[];
|
|
63
|
-
}>;
|
|
64
|
-
|
|
65
58
|
/**
|
|
66
59
|
* Result of a glob operation
|
|
67
60
|
*/
|
|
@@ -109,4 +102,4 @@ declare const toTree: (fs: IFileSystem, opts?: {
|
|
|
109
102
|
sort?: boolean;
|
|
110
103
|
}) => Promise<string>;
|
|
111
104
|
|
|
112
|
-
export { ActivityToolHandler, AgentResponse,
|
|
105
|
+
export { ActivityToolHandler, AgentResponse, BashArgs, FileEditArgs, GlobArgs, type InvokeModelConfig, ZeitlichPlugin, type ZeitlichPluginOptions, createBashHandler, createEditHandler, createGlobHandler, invokeModel, toTree };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { A as AgentResponse, a as ActivityToolHandler,
|
|
2
|
-
export {
|
|
1
|
+
import { A as AgentResponse, a as ActivityToolHandler, G as GlobArgs, F as FileEditArgs, B as BashArgs } from './workflow-BdAuMMjY.js';
|
|
2
|
+
export { b as AGENT_HANDLER_NAMES, c as AgentConfig, d as AgentFile, e as AgentState, f as AgentStateManager, g as AgentStatus, h as AppendToolResultFn, i as AskUserQuestionArgs, j as BaseAgentState, k as BaseThreadManager, l as FileReadArgs, m as FileWriteArgs, n as GrepArgs, I as InferToolResults, J as JsonPrimitive, o as JsonSerializable, p as JsonValue, P as ParsedToolCall, q as ParsedToolCallUnion, r as PostToolUseFailureHook, s as PostToolUseFailureHookContext, t as PostToolUseFailureHookResult, u as PostToolUseHook, v as PostToolUseHookContext, w as PreToolUseHook, x as PreToolUseHookContext, y as PreToolUseHookResult, z as ProcessToolCallsContext, R as RawToolCall, C as RunAgentActivity, D as RunAgentConfig, S as SessionEndHook, E as SessionEndHookContext, H as SessionExitReason, K as SessionLifecycleHooks, L as SessionStartHook, M as SessionStartHookContext, N as SubagentArgs, O as SubagentConfig, Q as SubagentHooks, T as SubagentInput, U as TaskCreateArgs, V as TaskGetArgs, W as TaskListArgs, X as TaskStatus, Y as TaskUpdateArgs, Z as ThreadManager, _ as ThreadManagerConfig, $ as ThreadOps, a0 as ToolArgs, a1 as ToolCallResult, a2 as ToolCallResultUnion, a3 as ToolDefinition, a4 as ToolHandler, a5 as ToolHandlerContext, a6 as ToolHandlerResponse, a7 as ToolHooks, a8 as ToolMap, a9 as ToolMessageContent, aa as ToolNames, ab as ToolResult, ac as ToolResultConfig, ad as ToolRouter, ae as ToolWithHandler, af as WorkflowTask, ag as ZeitlichSession, ah as ZeitlichSharedActivities, ai as askUserQuestionTool, aj as bashTool, ak as createAgentStateManager, al as createAskUserQuestionHandler, am as createBashToolDescription, an as createSession, ao as createSharedActivities, ap as createSubagentTool, aq as createTaskCreateHandler, ar as createTaskGetHandler, as as createTaskListHandler, at as createTaskUpdateHandler, au as createThreadManager, av as createToolRouter, aw as defineSubagent, ax as defineTool, ay as editTool, az as globTool, aA as grepTool, aB as hasNoOtherToolCalls, aC as isTerminalStatus, aD as proxyDefaultThreadOps, aE as readTool, aF as taskCreateTool, aG as taskGetTool, aH as taskListTool, aI as taskUpdateTool, aJ as withAutoAppend, aK as writeTool } from './workflow-BdAuMMjY.js';
|
|
3
3
|
import { SimplePlugin } from '@temporalio/plugin';
|
|
4
4
|
import Redis from 'ioredis';
|
|
5
5
|
import { WorkflowClient } from '@temporalio/client';
|
|
6
6
|
import { BaseChatModel, BaseChatModelCallOptions, BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
7
|
-
import { StoredMessage } from '@langchain/core/messages';
|
|
8
7
|
import { IFileSystem, BashOptions } from 'just-bash';
|
|
9
8
|
import '@temporalio/workflow';
|
|
9
|
+
import '@langchain/core/messages';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import '@temporalio/common';
|
|
12
12
|
|
|
@@ -55,13 +55,6 @@ declare function invokeModel({ redis, model, client, config: { threadId, agentNa
|
|
|
55
55
|
}>;
|
|
56
56
|
}): Promise<AgentResponse>;
|
|
57
57
|
|
|
58
|
-
/**
|
|
59
|
-
* Creates handler for user interaction tool - creates AI messages for display.
|
|
60
|
-
*/
|
|
61
|
-
declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQuestionArgs, {
|
|
62
|
-
chatMessages: StoredMessage[];
|
|
63
|
-
}>;
|
|
64
|
-
|
|
65
58
|
/**
|
|
66
59
|
* Result of a glob operation
|
|
67
60
|
*/
|
|
@@ -109,4 +102,4 @@ declare const toTree: (fs: IFileSystem, opts?: {
|
|
|
109
102
|
sort?: boolean;
|
|
110
103
|
}) => Promise<string>;
|
|
111
104
|
|
|
112
|
-
export { ActivityToolHandler, AgentResponse,
|
|
105
|
+
export { ActivityToolHandler, AgentResponse, BashArgs, FileEditArgs, GlobArgs, type InvokeModelConfig, ZeitlichPlugin, type ZeitlichPluginOptions, createBashHandler, createEditHandler, createGlobHandler, invokeModel, toTree };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { setHandler, defineUpdate, condition, proxyActivities, defineQuery, uuid4, workflowInfo, executeChild } from '@temporalio/workflow';
|
|
2
|
+
import z13, { z } from 'zod';
|
|
3
3
|
import { SimplePlugin } from '@temporalio/plugin';
|
|
4
|
-
import { mapStoredMessagesToChatMessages,
|
|
4
|
+
import { mapStoredMessagesToChatMessages, ToolMessage, AIMessage, SystemMessage, HumanMessage } from '@langchain/core/messages';
|
|
5
5
|
import crypto from 'crypto';
|
|
6
6
|
import { Context } from '@temporalio/activity';
|
|
7
7
|
import { Bash } from 'just-bash';
|
|
@@ -39,10 +39,10 @@ function createSubagentTool(subagents) {
|
|
|
39
39
|
return {
|
|
40
40
|
name: SUBAGENT_TOOL,
|
|
41
41
|
description: buildSubagentDescription(subagents),
|
|
42
|
-
schema:
|
|
43
|
-
subagent:
|
|
44
|
-
description:
|
|
45
|
-
prompt:
|
|
42
|
+
schema: z13.object({
|
|
43
|
+
subagent: z13.enum(names).describe("The type of subagent to launch"),
|
|
44
|
+
description: z13.string().describe("A short (3-5 word) description of the task"),
|
|
45
|
+
prompt: z13.string().describe("The task for the agent to perform")
|
|
46
46
|
})
|
|
47
47
|
};
|
|
48
48
|
}
|
|
@@ -65,11 +65,12 @@ function createSubagentHandler(subagents) {
|
|
|
65
65
|
args: [input],
|
|
66
66
|
taskQueue: config.taskQueue ?? parentTaskQueue
|
|
67
67
|
};
|
|
68
|
-
const { toolResponse, data } = typeof config.workflow === "string" ? await executeChild(config.workflow, childOpts) : await executeChild(config.workflow, childOpts);
|
|
68
|
+
const { toolResponse, data, usage } = typeof config.workflow === "string" ? await executeChild(config.workflow, childOpts) : await executeChild(config.workflow, childOpts);
|
|
69
69
|
const validated = config.resultSchema ? config.resultSchema.parse(data) : null;
|
|
70
70
|
return {
|
|
71
71
|
toolResponse,
|
|
72
|
-
data: validated
|
|
72
|
+
data: validated,
|
|
73
|
+
...usage && { usage }
|
|
73
74
|
};
|
|
74
75
|
};
|
|
75
76
|
}
|
|
@@ -81,20 +82,17 @@ function createToolRouter(options) {
|
|
|
81
82
|
for (const [_key, tool] of Object.entries(options.tools)) {
|
|
82
83
|
toolMap.set(tool.name, tool);
|
|
83
84
|
}
|
|
84
|
-
const isEnabled = (tool) => tool.enabled
|
|
85
|
+
const isEnabled = (tool) => tool.enabled?.() ?? true;
|
|
85
86
|
if (options.subagents) {
|
|
86
|
-
|
|
87
|
-
(s) => s.enabled !== false
|
|
88
|
-
);
|
|
89
|
-
if (enabledSubagents.length > 0) {
|
|
87
|
+
if (options.subagents.length > 0) {
|
|
90
88
|
const subagentHooksMap = /* @__PURE__ */ new Map();
|
|
91
|
-
for (const s of
|
|
89
|
+
for (const s of options.subagents) {
|
|
92
90
|
if (s.hooks) subagentHooksMap.set(s.agentName, s.hooks);
|
|
93
91
|
}
|
|
94
92
|
const resolveSubagentName = (args) => args.subagent;
|
|
95
93
|
toolMap.set("Subagent", {
|
|
96
|
-
...createSubagentTool(
|
|
97
|
-
handler: createSubagentHandler(
|
|
94
|
+
...createSubagentTool(options.subagents),
|
|
95
|
+
handler: createSubagentHandler(options.subagents),
|
|
98
96
|
...subagentHooksMap.size > 0 && {
|
|
99
97
|
hooks: {
|
|
100
98
|
onPreToolUse: async (ctx) => {
|
|
@@ -404,6 +402,7 @@ function hasNoOtherToolCalls(toolCalls, excludeName) {
|
|
|
404
402
|
var createSession = async ({
|
|
405
403
|
threadId,
|
|
406
404
|
agentName,
|
|
405
|
+
description,
|
|
407
406
|
maxTurns = 50,
|
|
408
407
|
metadata = {},
|
|
409
408
|
runAgent,
|
|
@@ -414,7 +413,8 @@ var createSession = async ({
|
|
|
414
413
|
processToolsInParallel = true,
|
|
415
414
|
hooks = {},
|
|
416
415
|
appendSystemPrompt = true,
|
|
417
|
-
systemPrompt
|
|
416
|
+
systemPrompt,
|
|
417
|
+
waitForInputTimeout = "48h"
|
|
418
418
|
}) => {
|
|
419
419
|
const {
|
|
420
420
|
appendToolResult,
|
|
@@ -442,7 +442,28 @@ var createSession = async ({
|
|
|
442
442
|
}
|
|
443
443
|
};
|
|
444
444
|
return {
|
|
445
|
-
runSession: async ({
|
|
445
|
+
runSession: async ({
|
|
446
|
+
stateManager
|
|
447
|
+
}) => {
|
|
448
|
+
setHandler(
|
|
449
|
+
defineUpdate(`add${agentName}Message`),
|
|
450
|
+
async (message) => {
|
|
451
|
+
if (hooks.onPreHumanMessageAppend) {
|
|
452
|
+
await hooks.onPreHumanMessageAppend({
|
|
453
|
+
message,
|
|
454
|
+
threadId
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
await appendHumanMessage(threadId, message);
|
|
458
|
+
if (hooks.onPostHumanMessageAppend) {
|
|
459
|
+
await hooks.onPostHumanMessageAppend({
|
|
460
|
+
message,
|
|
461
|
+
threadId
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
stateManager.run();
|
|
465
|
+
}
|
|
466
|
+
);
|
|
446
467
|
if (hooks.onSessionStart) {
|
|
447
468
|
await hooks.onSessionStart({
|
|
448
469
|
threadId,
|
|
@@ -450,7 +471,6 @@ var createSession = async ({
|
|
|
450
471
|
metadata
|
|
451
472
|
});
|
|
452
473
|
}
|
|
453
|
-
stateManager.setTools(toolRouter.getToolDefinitions());
|
|
454
474
|
await initializeThread(threadId);
|
|
455
475
|
if (appendSystemPrompt && systemPrompt && systemPrompt.trim() !== "") {
|
|
456
476
|
await appendSystemMessage(threadId, systemPrompt);
|
|
@@ -461,15 +481,25 @@ var createSession = async ({
|
|
|
461
481
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
462
482
|
stateManager.incrementTurns();
|
|
463
483
|
const currentTurn = stateManager.getTurns();
|
|
464
|
-
|
|
484
|
+
stateManager.setTools(toolRouter.getToolDefinitions());
|
|
485
|
+
const { message, rawToolCalls, usage } = await runAgent({
|
|
465
486
|
threadId,
|
|
466
487
|
agentName,
|
|
467
|
-
metadata
|
|
488
|
+
metadata,
|
|
489
|
+
systemPrompt,
|
|
490
|
+
description
|
|
468
491
|
});
|
|
492
|
+
if (usage) {
|
|
493
|
+
stateManager.updateUsage(usage);
|
|
494
|
+
}
|
|
469
495
|
if (!toolRouter.hasTools() || rawToolCalls.length === 0) {
|
|
470
496
|
stateManager.complete();
|
|
471
497
|
exitReason = "completed";
|
|
472
|
-
return
|
|
498
|
+
return {
|
|
499
|
+
finalMessage: message,
|
|
500
|
+
exitReason,
|
|
501
|
+
usage: stateManager.getTotalUsage()
|
|
502
|
+
};
|
|
473
503
|
}
|
|
474
504
|
const parsedToolCalls = [];
|
|
475
505
|
for (const tc of rawToolCalls) {
|
|
@@ -486,12 +516,27 @@ var createSession = async ({
|
|
|
486
516
|
});
|
|
487
517
|
}
|
|
488
518
|
}
|
|
489
|
-
await toolRouter.processToolCalls(
|
|
490
|
-
|
|
491
|
-
|
|
519
|
+
const toolCallResults = await toolRouter.processToolCalls(
|
|
520
|
+
parsedToolCalls,
|
|
521
|
+
{
|
|
522
|
+
turn: currentTurn
|
|
523
|
+
}
|
|
524
|
+
);
|
|
525
|
+
for (const result of toolCallResults) {
|
|
526
|
+
if (result.usage) {
|
|
527
|
+
stateManager.updateUsage(result.usage);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
492
530
|
if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
|
|
493
|
-
|
|
494
|
-
|
|
531
|
+
const conditionMet = await condition(
|
|
532
|
+
() => stateManager.getStatus() === "RUNNING",
|
|
533
|
+
waitForInputTimeout
|
|
534
|
+
);
|
|
535
|
+
if (!conditionMet) {
|
|
536
|
+
stateManager.cancel();
|
|
537
|
+
await condition(() => false, "2s");
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
495
540
|
}
|
|
496
541
|
}
|
|
497
542
|
if (stateManager.getTurns() >= maxTurns && stateManager.isRunning()) {
|
|
@@ -503,7 +548,11 @@ var createSession = async ({
|
|
|
503
548
|
} finally {
|
|
504
549
|
await callSessionEnd(exitReason, stateManager.getTurns());
|
|
505
550
|
}
|
|
506
|
-
return
|
|
551
|
+
return {
|
|
552
|
+
finalMessage: null,
|
|
553
|
+
exitReason,
|
|
554
|
+
usage: stateManager.getTotalUsage()
|
|
555
|
+
};
|
|
507
556
|
}
|
|
508
557
|
};
|
|
509
558
|
};
|
|
@@ -532,12 +581,19 @@ function proxyDefaultThreadOps(options) {
|
|
|
532
581
|
function isTerminalStatus(status) {
|
|
533
582
|
return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
|
|
534
583
|
}
|
|
535
|
-
|
|
536
|
-
|
|
584
|
+
function createAgentStateManager({
|
|
585
|
+
initialState,
|
|
586
|
+
agentConfig
|
|
587
|
+
}) {
|
|
537
588
|
let status = initialState?.status ?? "RUNNING";
|
|
538
589
|
let version = initialState?.version ?? 0;
|
|
539
590
|
let turns = initialState?.turns ?? 0;
|
|
540
591
|
let tools = initialState?.tools ?? [];
|
|
592
|
+
let totalInputTokens = 0;
|
|
593
|
+
let totalOutputTokens = 0;
|
|
594
|
+
let totalCachedWriteTokens = 0;
|
|
595
|
+
let totalCachedReadTokens = 0;
|
|
596
|
+
let totalReasonTokens = 0;
|
|
541
597
|
const tasks = new Map(initialState?.tasks);
|
|
542
598
|
const {
|
|
543
599
|
status: _,
|
|
@@ -557,9 +613,21 @@ function createAgentStateManager(initialState) {
|
|
|
557
613
|
...customState
|
|
558
614
|
};
|
|
559
615
|
}
|
|
560
|
-
setHandler(
|
|
616
|
+
setHandler(defineQuery(`get${agentConfig.agentName}State`), () => {
|
|
561
617
|
return buildState();
|
|
562
618
|
});
|
|
619
|
+
setHandler(
|
|
620
|
+
defineUpdate(
|
|
621
|
+
`waitFor${agentConfig.agentName}StateChange`
|
|
622
|
+
),
|
|
623
|
+
async (lastKnownVersion) => {
|
|
624
|
+
await condition(
|
|
625
|
+
() => version > lastKnownVersion || isTerminalStatus(status),
|
|
626
|
+
"55s"
|
|
627
|
+
);
|
|
628
|
+
return buildState();
|
|
629
|
+
}
|
|
630
|
+
);
|
|
563
631
|
return {
|
|
564
632
|
getStatus() {
|
|
565
633
|
return status;
|
|
@@ -640,6 +708,23 @@ function createAgentStateManager(initialState) {
|
|
|
640
708
|
version++;
|
|
641
709
|
}
|
|
642
710
|
return deleted;
|
|
711
|
+
},
|
|
712
|
+
updateUsage(usage) {
|
|
713
|
+
totalInputTokens += usage.inputTokens ?? 0;
|
|
714
|
+
totalOutputTokens += usage.outputTokens ?? 0;
|
|
715
|
+
totalCachedWriteTokens += usage.cachedWriteTokens ?? 0;
|
|
716
|
+
totalCachedReadTokens += usage.cachedReadTokens ?? 0;
|
|
717
|
+
totalReasonTokens += usage.reasonTokens ?? 0;
|
|
718
|
+
},
|
|
719
|
+
getTotalUsage() {
|
|
720
|
+
return {
|
|
721
|
+
totalInputTokens,
|
|
722
|
+
totalOutputTokens,
|
|
723
|
+
totalCachedWriteTokens,
|
|
724
|
+
totalCachedReadTokens,
|
|
725
|
+
totalReasonTokens,
|
|
726
|
+
turns
|
|
727
|
+
};
|
|
643
728
|
}
|
|
644
729
|
};
|
|
645
730
|
}
|
|
@@ -648,38 +733,6 @@ var AGENT_HANDLER_NAMES = {
|
|
|
648
733
|
waitForStateChange: "waitForStateChange",
|
|
649
734
|
addMessage: "addMessage"
|
|
650
735
|
};
|
|
651
|
-
var askUserQuestionTool = {
|
|
652
|
-
name: "AskUserQuestion",
|
|
653
|
-
description: `Use this tool when you need to ask the user questions during execution. This allows you to:
|
|
654
|
-
|
|
655
|
-
1. Gather user preferences or requirements
|
|
656
|
-
2. Clarify ambiguous instructions
|
|
657
|
-
3. Get decisions on implementation choices as you work
|
|
658
|
-
4. Offer choices to the user about what direction to take.
|
|
659
|
-
|
|
660
|
-
Usage notes:
|
|
661
|
-
|
|
662
|
-
* Users will always be able to select "Other" to provide custom text input
|
|
663
|
-
* Use multiSelect: true to allow multiple answers to be selected for a question
|
|
664
|
-
* If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
|
|
665
|
-
`,
|
|
666
|
-
schema: z3.object({
|
|
667
|
-
questions: z3.array(
|
|
668
|
-
z3.object({
|
|
669
|
-
question: z3.string().describe("The full question text to display"),
|
|
670
|
-
header: z3.string().describe("Short label for the question (max 12 characters)"),
|
|
671
|
-
options: z3.array(
|
|
672
|
-
z3.object({
|
|
673
|
-
label: z3.string(),
|
|
674
|
-
description: z3.string()
|
|
675
|
-
})
|
|
676
|
-
).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
|
|
677
|
-
multiSelect: z3.boolean().describe("If true, users can select multiple options")
|
|
678
|
-
})
|
|
679
|
-
)
|
|
680
|
-
}),
|
|
681
|
-
strict: true
|
|
682
|
-
};
|
|
683
736
|
var globTool = {
|
|
684
737
|
name: "Glob",
|
|
685
738
|
description: `Search for files matching a glob pattern within the available file system.
|
|
@@ -836,17 +889,17 @@ var taskCreateTool = {
|
|
|
836
889
|
- Include enough detail in the description for another agent to understand and complete the task
|
|
837
890
|
- After creating tasks, use TaskUpdate to set up dependencies (blocks/blockedBy) if needed
|
|
838
891
|
- Check TaskList first to avoid creating duplicate tasks`,
|
|
839
|
-
schema:
|
|
840
|
-
subject:
|
|
892
|
+
schema: z13.object({
|
|
893
|
+
subject: z13.string().describe(
|
|
841
894
|
'A brief, actionable title in imperative form (e.g., "Fix authentication bug in login flow")'
|
|
842
895
|
),
|
|
843
|
-
description:
|
|
896
|
+
description: z13.string().describe(
|
|
844
897
|
"Detailed description of what needs to be done, including context and acceptance criteria"
|
|
845
898
|
),
|
|
846
|
-
activeForm:
|
|
899
|
+
activeForm: z13.string().describe(
|
|
847
900
|
'Present continuous form shown in spinner when task is in_progress (e.g., "Fixing authentication bug"). This is displayed to the user while you work on the task.'
|
|
848
901
|
),
|
|
849
|
-
metadata:
|
|
902
|
+
metadata: z13.record(z13.string(), z13.string()).describe("Arbitrary key-value pairs for tracking")
|
|
850
903
|
})
|
|
851
904
|
};
|
|
852
905
|
function createTaskCreateHandler(stateManager) {
|
|
@@ -871,8 +924,8 @@ function createTaskCreateHandler(stateManager) {
|
|
|
871
924
|
var taskGetTool = {
|
|
872
925
|
name: "TaskGet",
|
|
873
926
|
description: `Retrieve full task details including dependencies.`,
|
|
874
|
-
schema:
|
|
875
|
-
taskId:
|
|
927
|
+
schema: z13.object({
|
|
928
|
+
taskId: z13.string().describe("The ID of the task to get")
|
|
876
929
|
})
|
|
877
930
|
};
|
|
878
931
|
|
|
@@ -895,7 +948,7 @@ function createTaskGetHandler(stateManager) {
|
|
|
895
948
|
var taskListTool = {
|
|
896
949
|
name: "TaskList",
|
|
897
950
|
description: `List all tasks with current state.`,
|
|
898
|
-
schema:
|
|
951
|
+
schema: z13.object({})
|
|
899
952
|
};
|
|
900
953
|
|
|
901
954
|
// src/tools/task-list/handler.ts
|
|
@@ -911,11 +964,11 @@ function createTaskListHandler(stateManager) {
|
|
|
911
964
|
var taskUpdateTool = {
|
|
912
965
|
name: "TaskUpdate",
|
|
913
966
|
description: `Update status, add blockers, modify details.`,
|
|
914
|
-
schema:
|
|
915
|
-
taskId:
|
|
916
|
-
status:
|
|
917
|
-
addBlockedBy:
|
|
918
|
-
addBlocks:
|
|
967
|
+
schema: z13.object({
|
|
968
|
+
taskId: z13.string().describe("The ID of the task to get"),
|
|
969
|
+
status: z13.enum(["pending", "in_progress", "completed"]).describe("The status of the task"),
|
|
970
|
+
addBlockedBy: z13.array(z13.string()).describe("The IDs of the tasks that are blocking this task"),
|
|
971
|
+
addBlocks: z13.array(z13.string()).describe("The IDs of the tasks that this task is blocking")
|
|
919
972
|
})
|
|
920
973
|
};
|
|
921
974
|
|
|
@@ -983,13 +1036,53 @@ Use this tool to:
|
|
|
983
1036
|
- Execute scripts and chain commands with pipes (|) or logical operators (&&, ||)
|
|
984
1037
|
- Inspect files and directories
|
|
985
1038
|
`,
|
|
986
|
-
schema:
|
|
987
|
-
command:
|
|
1039
|
+
schema: z13.object({
|
|
1040
|
+
command: z13.string().describe(
|
|
988
1041
|
"The bash command to execute. Can include pipes (|), redirects (>, >>), logical operators (&&, ||), and shell features like command substitution $(...)."
|
|
989
1042
|
)
|
|
990
1043
|
}),
|
|
991
1044
|
strict: true
|
|
992
1045
|
};
|
|
1046
|
+
var askUserQuestionTool = {
|
|
1047
|
+
name: "AskUserQuestion",
|
|
1048
|
+
description: `Use this tool when you need to ask the user questions during execution. This allows you to:
|
|
1049
|
+
|
|
1050
|
+
1. Gather user preferences or requirements
|
|
1051
|
+
2. Clarify ambiguous instructions
|
|
1052
|
+
3. Get decisions on implementation choices as you work
|
|
1053
|
+
4. Offer choices to the user about what direction to take.
|
|
1054
|
+
|
|
1055
|
+
Usage notes:
|
|
1056
|
+
|
|
1057
|
+
* Users will always be able to select "Other" to provide custom text input
|
|
1058
|
+
* Use multiSelect: true to allow multiple answers to be selected for a question
|
|
1059
|
+
* If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
|
|
1060
|
+
`,
|
|
1061
|
+
schema: z13.object({
|
|
1062
|
+
questions: z13.array(
|
|
1063
|
+
z13.object({
|
|
1064
|
+
question: z13.string().describe("The full question text to display"),
|
|
1065
|
+
header: z13.string().describe("Short label for the question (max 12 characters)"),
|
|
1066
|
+
options: z13.array(
|
|
1067
|
+
z13.object({
|
|
1068
|
+
label: z13.string(),
|
|
1069
|
+
description: z13.string()
|
|
1070
|
+
})
|
|
1071
|
+
).min(0).max(4).describe("Array of 0-4 choices, each with label and description"),
|
|
1072
|
+
multiSelect: z13.boolean().describe("If true, users can select multiple options")
|
|
1073
|
+
})
|
|
1074
|
+
)
|
|
1075
|
+
}),
|
|
1076
|
+
strict: true
|
|
1077
|
+
};
|
|
1078
|
+
|
|
1079
|
+
// src/tools/ask-user-question/handler.ts
|
|
1080
|
+
var createAskUserQuestionHandler = () => (args) => {
|
|
1081
|
+
return {
|
|
1082
|
+
toolResponse: "Question submitted",
|
|
1083
|
+
data: { questions: args.questions }
|
|
1084
|
+
};
|
|
1085
|
+
};
|
|
993
1086
|
|
|
994
1087
|
// node_modules/uuid/dist/esm-node/stringify.js
|
|
995
1088
|
var byteToHex = [];
|
|
@@ -1162,7 +1255,7 @@ async function invokeModel({
|
|
|
1162
1255
|
const parentWorkflowId = info.workflowExecution.workflowId;
|
|
1163
1256
|
const parentRunId = info.workflowExecution.runId;
|
|
1164
1257
|
const handle = client.getHandle(parentWorkflowId, parentRunId);
|
|
1165
|
-
const { tools } = await handle.query(
|
|
1258
|
+
const { tools } = await handle.query(`get${agentName}State`);
|
|
1166
1259
|
const messages = await thread.load();
|
|
1167
1260
|
const response = await model.invoke(
|
|
1168
1261
|
[...mapStoredMessagesToChatMessages(messages)],
|
|
@@ -1183,25 +1276,14 @@ async function invokeModel({
|
|
|
1183
1276
|
args: tc.args
|
|
1184
1277
|
})),
|
|
1185
1278
|
usage: {
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1279
|
+
inputTokens: response.usage_metadata?.input_tokens,
|
|
1280
|
+
outputTokens: response.usage_metadata?.output_tokens,
|
|
1281
|
+
reasonTokens: response.usage_metadata?.output_token_details?.reasoning,
|
|
1282
|
+
cachedWriteTokens: response.usage_metadata?.input_token_details?.cache_creation,
|
|
1283
|
+
cachedReadTokens: response.usage_metadata?.input_token_details?.cache_read
|
|
1189
1284
|
}
|
|
1190
1285
|
};
|
|
1191
1286
|
}
|
|
1192
|
-
var createAskUserQuestionHandler = () => async (args) => {
|
|
1193
|
-
const messages = args.questions.map(
|
|
1194
|
-
({ question, header, options, multiSelect }) => new AIMessage({
|
|
1195
|
-
content: question,
|
|
1196
|
-
additional_kwargs: {
|
|
1197
|
-
header,
|
|
1198
|
-
options,
|
|
1199
|
-
multiSelect
|
|
1200
|
-
}
|
|
1201
|
-
}).toDict()
|
|
1202
|
-
);
|
|
1203
|
-
return { toolResponse: "Question submitted", data: { chatMessages: messages } };
|
|
1204
|
-
};
|
|
1205
1287
|
function createGlobHandler(fs) {
|
|
1206
1288
|
return async (_args) => {
|
|
1207
1289
|
new Bash({ fs });
|
|
@@ -1371,6 +1453,6 @@ var toTree = async (fs, opts = {}) => {
|
|
|
1371
1453
|
return base + subtree;
|
|
1372
1454
|
};
|
|
1373
1455
|
|
|
1374
|
-
export { AGENT_HANDLER_NAMES, ZeitlichPlugin, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashHandler, createBashToolDescription, createEditHandler, createGlobHandler, createSession, createSharedActivities, createSubagentTool, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createThreadManager, createToolRouter, defineSubagent, defineTool, editTool,
|
|
1456
|
+
export { AGENT_HANDLER_NAMES, ZeitlichPlugin, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashHandler, createBashToolDescription, createEditHandler, createGlobHandler, createSession, createSharedActivities, createSubagentTool, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createThreadManager, createToolRouter, defineSubagent, defineTool, editTool, globTool, grepTool, hasNoOtherToolCalls, invokeModel, isTerminalStatus, proxyDefaultThreadOps, readTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, toTree, withAutoAppend, writeTool };
|
|
1375
1457
|
//# sourceMappingURL=index.js.map
|
|
1376
1458
|
//# sourceMappingURL=index.js.map
|