@namzu/sdk 0.1.4 → 0.1.5-rc.1
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/advisory/executor.d.ts +2 -2
- package/dist/advisory/executor.d.ts.map +1 -1
- package/dist/advisory/executor.js.map +1 -1
- package/dist/agents/AbstractAgent.d.ts +20 -2
- package/dist/agents/AbstractAgent.d.ts.map +1 -1
- package/dist/agents/AbstractAgent.js +23 -1
- package/dist/agents/AbstractAgent.js.map +1 -1
- package/dist/agents/PipelineAgent.d.ts.map +1 -1
- package/dist/agents/PipelineAgent.js +1 -1
- package/dist/agents/PipelineAgent.js.map +1 -1
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +1 -0
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/RouterAgent.d.ts.map +1 -1
- package/dist/agents/RouterAgent.js +4 -2
- package/dist/agents/RouterAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +4 -1
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/agents/__tests__/lock.test.d.ts +2 -0
- package/dist/agents/__tests__/lock.test.d.ts.map +1 -0
- package/dist/agents/__tests__/lock.test.js +131 -0
- package/dist/agents/__tests__/lock.test.js.map +1 -0
- package/dist/agents/index.d.ts +2 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +1 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/lock.d.ts +42 -0
- package/dist/agents/lock.d.ts.map +1 -0
- package/dist/agents/lock.js +54 -0
- package/dist/agents/lock.js.map +1 -0
- package/dist/bridge/a2a/message.d.ts.map +1 -1
- package/dist/bridge/a2a/message.js.map +1 -1
- package/dist/bridge/tools/connector/router.d.ts +4 -5
- package/dist/bridge/tools/connector/router.d.ts.map +1 -1
- package/dist/bridge/tools/connector/router.js.map +1 -1
- package/dist/compaction/__tests__/SlidingWindowManager.test.d.ts +2 -0
- package/dist/compaction/__tests__/SlidingWindowManager.test.d.ts.map +1 -0
- package/dist/compaction/__tests__/SlidingWindowManager.test.js +113 -0
- package/dist/compaction/__tests__/SlidingWindowManager.test.js.map +1 -0
- package/dist/compaction/__tests__/dangling.test.d.ts +2 -0
- package/dist/compaction/__tests__/dangling.test.d.ts.map +1 -0
- package/dist/compaction/__tests__/dangling.test.js +356 -0
- package/dist/compaction/__tests__/dangling.test.js.map +1 -0
- package/dist/compaction/__tests__/factory.test.d.ts +2 -0
- package/dist/compaction/__tests__/factory.test.d.ts.map +1 -0
- package/dist/compaction/__tests__/factory.test.js +43 -0
- package/dist/compaction/__tests__/factory.test.js.map +1 -0
- package/dist/compaction/dangling.d.ts +96 -0
- package/dist/compaction/dangling.d.ts.map +1 -0
- package/dist/compaction/dangling.js +274 -0
- package/dist/compaction/dangling.js.map +1 -0
- package/dist/compaction/factory.d.ts +20 -0
- package/dist/compaction/factory.d.ts.map +1 -0
- package/dist/compaction/factory.js +35 -0
- package/dist/compaction/factory.js.map +1 -0
- package/dist/compaction/index.d.ts +5 -0
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +3 -0
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/interface.d.ts +33 -0
- package/dist/compaction/interface.d.ts.map +1 -0
- package/dist/compaction/interface.js +2 -0
- package/dist/compaction/interface.js.map +1 -0
- package/dist/compaction/managers/index.d.ts +4 -0
- package/dist/compaction/managers/index.d.ts.map +1 -0
- package/dist/compaction/managers/index.js +4 -0
- package/dist/compaction/managers/index.js.map +1 -0
- package/dist/compaction/managers/null.d.ts +12 -0
- package/dist/compaction/managers/null.d.ts.map +1 -0
- package/dist/compaction/managers/null.js +15 -0
- package/dist/compaction/managers/null.js.map +1 -0
- package/dist/compaction/managers/slidingWindow.d.ts +27 -0
- package/dist/compaction/managers/slidingWindow.d.ts.map +1 -0
- package/dist/compaction/managers/slidingWindow.js +41 -0
- package/dist/compaction/managers/slidingWindow.js.map +1 -0
- package/dist/compaction/managers/structured.d.ts +23 -0
- package/dist/compaction/managers/structured.d.ts.map +1 -0
- package/dist/compaction/managers/structured.js +144 -0
- package/dist/compaction/managers/structured.js.map +1 -0
- package/dist/compaction/types.d.ts +1 -1
- package/dist/compaction/types.d.ts.map +1 -1
- package/dist/config/runtime.d.ts +16 -16
- package/dist/config/runtime.js +1 -1
- package/dist/config/runtime.js.map +1 -1
- package/dist/constants/agent/index.d.ts +1 -1
- package/dist/constants/agent/index.d.ts.map +1 -1
- package/dist/gateway/local.d.ts +2 -2
- package/dist/gateway/local.d.ts.map +1 -1
- package/dist/gateway/local.js +10 -1
- package/dist/gateway/local.js.map +1 -1
- package/dist/index.d.ts +18 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +3 -2
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/run/persistence.d.ts +1 -2
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +2 -1
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/plugin/__tests__/lifecycle.test.d.ts +2 -0
- package/dist/plugin/__tests__/lifecycle.test.d.ts.map +1 -0
- package/dist/plugin/__tests__/lifecycle.test.js +332 -0
- package/dist/plugin/__tests__/lifecycle.test.js.map +1 -0
- package/dist/plugin/lifecycle.d.ts +2 -2
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +28 -2
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/resolver.d.ts +2 -2
- package/dist/plugin/resolver.d.ts.map +1 -1
- package/dist/plugin/resolver.js.map +1 -1
- package/dist/registry/agent/definitions.d.ts +3 -2
- package/dist/registry/agent/definitions.d.ts.map +1 -1
- package/dist/registry/agent/definitions.js.map +1 -1
- package/dist/registry/tool/execute.d.ts +2 -5
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/runtime/decision/parser.d.ts.map +1 -1
- package/dist/runtime/decision/parser.js +15 -40
- package/dist/runtime/decision/parser.js.map +1 -1
- package/dist/runtime/query/context-cache.d.ts +3 -3
- package/dist/runtime/query/context-cache.d.ts.map +1 -1
- package/dist/runtime/query/context-cache.js.map +1 -1
- package/dist/runtime/query/context.d.ts +1 -1
- package/dist/runtime/query/context.d.ts.map +1 -1
- package/dist/runtime/query/context.js.map +1 -1
- package/dist/runtime/query/events.js +11 -11
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +4 -2
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +1 -0
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +5 -3
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +2 -1
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +2 -2
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/advisory.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
- package/dist/runtime/query/iteration/phases/checkpoint.d.ts +1 -1
- package/dist/runtime/query/iteration/phases/checkpoint.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/checkpoint.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +2 -2
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/plan.d.ts +1 -1
- package/dist/runtime/query/iteration/phases/plan.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/plan.js.map +1 -1
- package/dist/runtime/query/prompt.d.ts +2 -2
- package/dist/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/runtime/query/result.d.ts +1 -1
- package/dist/runtime/query/result.d.ts.map +1 -1
- package/dist/runtime/query/result.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +4 -2
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +1 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/store/conversation/memory.d.ts +1 -1
- package/dist/store/conversation/memory.d.ts.map +1 -1
- package/dist/store/conversation/memory.js +15 -3
- package/dist/store/conversation/memory.js.map +1 -1
- package/dist/store/run/disk.d.ts +1 -2
- package/dist/store/run/disk.d.ts.map +1 -1
- package/dist/store/run/disk.js +21 -13
- package/dist/store/run/disk.js.map +1 -1
- package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts +140 -0
- package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts.map +1 -0
- package/dist/tools/builtins/__tests__/structuredOutput.example.js +183 -0
- package/dist/tools/builtins/__tests__/structuredOutput.example.js.map +1 -0
- package/dist/tools/builtins/__tests__/structuredOutput.test.d.ts +2 -0
- package/dist/tools/builtins/__tests__/structuredOutput.test.d.ts.map +1 -0
- package/dist/tools/builtins/__tests__/structuredOutput.test.js +224 -0
- package/dist/tools/builtins/__tests__/structuredOutput.test.js.map +1 -0
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +1 -2
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +1 -0
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +3 -0
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/ls.d.ts +1 -1
- package/dist/tools/builtins/structuredOutput.d.ts +27 -0
- package/dist/tools/builtins/structuredOutput.d.ts.map +1 -0
- package/dist/tools/builtins/structuredOutput.js +46 -0
- package/dist/tools/builtins/structuredOutput.js.map +1 -0
- package/dist/tools/task/list.d.ts +1 -1
- package/dist/tools/task/list.d.ts.map +1 -1
- package/dist/tools/task/list.js.map +1 -1
- package/dist/types/agent/base.d.ts +4 -1
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/index.d.ts +1 -0
- package/dist/types/agent/index.d.ts.map +1 -1
- package/dist/types/agent/index.js +1 -0
- package/dist/types/agent/index.js.map +1 -1
- package/dist/types/agent/manager.d.ts +27 -0
- package/dist/types/agent/manager.d.ts.map +1 -0
- package/dist/types/agent/manager.js +2 -0
- package/dist/types/agent/manager.js.map +1 -0
- package/dist/types/agent/reactive.d.ts +2 -2
- package/dist/types/agent/reactive.d.ts.map +1 -1
- package/dist/types/agent/supervisor.d.ts +2 -2
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +0 -2
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js +0 -2
- package/dist/types/agent/task.js.map +1 -1
- package/dist/types/common/index.d.ts +0 -1
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/common/index.js +0 -1
- package/dist/types/common/index.js.map +1 -1
- package/dist/types/hitl/index.d.ts +1 -2
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/invocation/__tests__/state.test.d.ts +2 -0
- package/dist/types/invocation/__tests__/state.test.d.ts.map +1 -0
- package/dist/types/invocation/__tests__/state.test.js +167 -0
- package/dist/types/invocation/__tests__/state.test.js.map +1 -0
- package/dist/types/invocation/index.d.ts +37 -0
- package/dist/types/invocation/index.d.ts.map +1 -0
- package/dist/types/invocation/index.js +23 -0
- package/dist/types/invocation/index.js.map +1 -0
- package/dist/types/plugin/index.d.ts +6 -0
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +16 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/run/events.d.ts +1 -1
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/index.d.ts +1 -0
- package/dist/types/run/index.d.ts.map +1 -1
- package/dist/types/run/index.js +1 -0
- package/dist/types/run/index.js.map +1 -1
- package/dist/types/run/metadata.d.ts +1 -1
- package/dist/types/run/metadata.d.ts.map +1 -1
- package/dist/types/run/state.d.ts +1 -1
- package/dist/types/run/state.d.ts.map +1 -1
- package/dist/types/run/stop-reason.d.ts +2 -0
- package/dist/types/run/stop-reason.d.ts.map +1 -0
- package/dist/types/run/stop-reason.js +2 -0
- package/dist/types/run/stop-reason.js.map +1 -0
- package/dist/types/structured-output/index.d.ts +51 -0
- package/dist/types/structured-output/index.d.ts.map +1 -0
- package/dist/types/structured-output/index.js +2 -0
- package/dist/types/structured-output/index.js.map +1 -0
- package/dist/types/tool/index.d.ts +36 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/advisory/executor.ts +2 -4
- package/src/agents/AbstractAgent.ts +26 -3
- package/src/agents/PipelineAgent.ts +1 -1
- package/src/agents/ReactiveAgent.ts +1 -0
- package/src/agents/RouterAgent.ts +8 -2
- package/src/agents/SupervisorAgent.ts +5 -1
- package/src/agents/__tests__/lock.test.ts +158 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/lock.ts +66 -0
- package/src/bridge/a2a/message.ts +1 -2
- package/src/bridge/tools/connector/router.ts +4 -5
- package/src/compaction/__tests__/SlidingWindowManager.test.ts +139 -0
- package/src/compaction/__tests__/dangling.test.ts +447 -0
- package/src/compaction/__tests__/factory.test.ts +53 -0
- package/src/compaction/dangling.ts +321 -0
- package/src/compaction/factory.ts +41 -0
- package/src/compaction/index.ts +14 -0
- package/src/compaction/interface.ts +35 -0
- package/src/compaction/managers/index.ts +3 -0
- package/src/compaction/managers/null.ts +19 -0
- package/src/compaction/managers/slidingWindow.ts +57 -0
- package/src/compaction/managers/structured.ts +169 -0
- package/src/compaction/types.ts +1 -1
- package/src/config/runtime.ts +1 -1
- package/src/constants/agent/index.ts +1 -1
- package/src/gateway/local.ts +13 -4
- package/src/index.ts +38 -1
- package/src/manager/agent/lifecycle.ts +3 -2
- package/src/manager/run/persistence.ts +3 -8
- package/src/plugin/__tests__/lifecycle.test.ts +430 -0
- package/src/plugin/lifecycle.ts +32 -6
- package/src/plugin/resolver.ts +3 -3
- package/src/registry/agent/definitions.ts +3 -2
- package/src/registry/tool/execute.ts +2 -5
- package/src/runtime/decision/parser.ts +15 -40
- package/src/runtime/query/context-cache.ts +3 -4
- package/src/runtime/query/context.ts +1 -2
- package/src/runtime/query/events.ts +11 -11
- package/src/runtime/query/executor.ts +5 -3
- package/src/runtime/query/index.ts +11 -4
- package/src/runtime/query/iteration/index.ts +2 -2
- package/src/runtime/query/iteration/phases/advisory.ts +1 -2
- package/src/runtime/query/iteration/phases/checkpoint.ts +1 -2
- package/src/runtime/query/iteration/phases/context.ts +2 -2
- package/src/runtime/query/iteration/phases/plan.ts +1 -2
- package/src/runtime/query/prompt.ts +3 -3
- package/src/runtime/query/result.ts +1 -2
- package/src/runtime/query/tooling.ts +5 -2
- package/src/store/conversation/memory.ts +21 -5
- package/src/store/run/disk.ts +18 -16
- package/src/tools/builtins/__tests__/structuredOutput.example.ts +221 -0
- package/src/tools/builtins/__tests__/structuredOutput.test.ts +275 -0
- package/src/tools/builtins/grep.ts +1 -2
- package/src/tools/builtins/index.ts +3 -0
- package/src/tools/builtins/structuredOutput.ts +55 -0
- package/src/tools/task/list.ts +1 -2
- package/src/types/agent/base.ts +5 -1
- package/src/types/agent/index.ts +1 -0
- package/src/types/agent/manager.ts +36 -0
- package/src/types/agent/reactive.ts +2 -2
- package/src/types/agent/supervisor.ts +2 -2
- package/src/types/agent/task.ts +0 -4
- package/src/types/common/index.ts +0 -2
- package/src/types/hitl/index.ts +1 -2
- package/src/types/invocation/__tests__/state.test.ts +210 -0
- package/src/types/invocation/index.ts +55 -0
- package/src/types/plugin/index.ts +19 -0
- package/src/types/run/events.ts +1 -10
- package/src/types/run/index.ts +1 -0
- package/src/types/run/metadata.ts +1 -1
- package/src/types/run/state.ts +1 -1
- package/src/types/run/stop-reason.ts +10 -0
- package/src/types/structured-output/index.ts +56 -0
- package/src/types/tool/index.ts +45 -0
package/src/types/agent/task.ts
CHANGED
|
@@ -66,8 +66,6 @@ export interface AgentTaskProgress {
|
|
|
66
66
|
recentActivities: string[]
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export { MAX_RECENT_ACTIVITIES } from '../../constants/agent/index.js'
|
|
70
|
-
|
|
71
69
|
export interface SendMessageOptions {
|
|
72
70
|
agentId: string
|
|
73
71
|
|
|
@@ -88,5 +86,3 @@ export interface AgentManagerConfig {
|
|
|
88
86
|
|
|
89
87
|
maxBudgetFraction: number
|
|
90
88
|
}
|
|
91
|
-
|
|
92
|
-
export { AGENT_MANAGER_DEFAULTS } from '../../constants/agent/index.js'
|
|
@@ -12,8 +12,6 @@ export interface TokenUsage {
|
|
|
12
12
|
cacheWriteTokens: number
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export { EMPTY_TOKEN_USAGE } from '../../constants/limits.js'
|
|
16
|
-
|
|
17
15
|
export function accumulateTokenUsage(current: TokenUsage, addition: TokenUsage): TokenUsage {
|
|
18
16
|
return {
|
|
19
17
|
promptTokens: current.promptTokens + addition.promptTokens,
|
package/src/types/hitl/index.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { CostInfo, TokenUsage } from '../common/index.js'
|
|
2
|
-
import type { PlanId, RunId } from '../ids/index.js'
|
|
2
|
+
import type { CheckpointId, PlanId, RunId } from '../ids/index.js'
|
|
3
3
|
import type { Message } from '../message/index.js'
|
|
4
4
|
import type { PlanStatus } from '../plan/index.js'
|
|
5
5
|
|
|
6
|
-
import type { CheckpointId } from '../ids/index.js'
|
|
7
6
|
export type { CheckpointId }
|
|
8
7
|
|
|
9
8
|
export type HITLResumeDecision =
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import type { TenantId } from '../../ids/index.js'
|
|
3
|
+
import { deriveChildState } from '../index.js'
|
|
4
|
+
import type { InvocationState } from '../index.js'
|
|
5
|
+
|
|
6
|
+
describe('InvocationState', () => {
|
|
7
|
+
describe('deriveChildState', () => {
|
|
8
|
+
it('should create child state with single agent in parentChain when parent is undefined', () => {
|
|
9
|
+
const childState = deriveChildState(undefined, 'agent-123')
|
|
10
|
+
|
|
11
|
+
expect(childState.parentChain).toEqual(['agent-123'])
|
|
12
|
+
expect(childState.tenantId).toBeUndefined()
|
|
13
|
+
expect(childState.metadata).toBeUndefined()
|
|
14
|
+
expect(childState.services).toBeUndefined()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('should create child state with single agent in parentChain when parent has no parentChain', () => {
|
|
18
|
+
const parent: InvocationState = {
|
|
19
|
+
tenantId: 'ten_abc' as TenantId,
|
|
20
|
+
metadata: { userId: 'user-123' },
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const childState = deriveChildState(parent, 'agent-456')
|
|
24
|
+
|
|
25
|
+
expect(childState.parentChain).toEqual(['agent-456'])
|
|
26
|
+
expect(childState.tenantId).toBe(parent.tenantId)
|
|
27
|
+
expect(childState.metadata).toBe(parent.metadata)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should extend parentChain with current agent', () => {
|
|
31
|
+
const parent: InvocationState = {
|
|
32
|
+
parentChain: ['supervisor', 'router'],
|
|
33
|
+
tenantId: 'ten_xyz' as TenantId,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const childState = deriveChildState(parent, 'worker-agent')
|
|
37
|
+
|
|
38
|
+
expect(childState.parentChain).toEqual(['supervisor', 'router', 'worker-agent'])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should preserve tenantId through derivation', () => {
|
|
42
|
+
const tenantId = 'ten_tenant123' as TenantId
|
|
43
|
+
const parent: InvocationState = {
|
|
44
|
+
tenantId,
|
|
45
|
+
parentChain: ['agent-1'],
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const childState = deriveChildState(parent, 'agent-2')
|
|
49
|
+
|
|
50
|
+
expect(childState.tenantId).toBe(tenantId)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should preserve metadata through derivation', () => {
|
|
54
|
+
const metadata = {
|
|
55
|
+
userId: 'user-456',
|
|
56
|
+
sessionId: 'sess_789',
|
|
57
|
+
correlationId: 'corr_abc',
|
|
58
|
+
}
|
|
59
|
+
const parent: InvocationState = {
|
|
60
|
+
metadata,
|
|
61
|
+
parentChain: ['agent-1'],
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const childState = deriveChildState(parent, 'agent-2')
|
|
65
|
+
|
|
66
|
+
expect(childState.metadata).toBe(metadata)
|
|
67
|
+
expect(childState.metadata?.userId).toBe('user-456')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('should preserve services through derivation', () => {
|
|
71
|
+
const services = {
|
|
72
|
+
db: { pool: 'mock-pool' },
|
|
73
|
+
cache: { client: 'mock-redis' },
|
|
74
|
+
}
|
|
75
|
+
const parent: InvocationState = {
|
|
76
|
+
services,
|
|
77
|
+
parentChain: ['agent-1'],
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const childState = deriveChildState(parent, 'agent-2')
|
|
81
|
+
|
|
82
|
+
expect(childState.services).toBe(services)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('should preserve all fields through multi-level derivation', () => {
|
|
86
|
+
const tenantId = 'ten_multi' as TenantId
|
|
87
|
+
const metadata = { userId: 'user-multi' }
|
|
88
|
+
const services = { db: 'postgres' }
|
|
89
|
+
|
|
90
|
+
const level1 = deriveChildState(undefined, 'supervisor')
|
|
91
|
+
expect(level1.parentChain).toEqual(['supervisor'])
|
|
92
|
+
|
|
93
|
+
const parent: InvocationState = {
|
|
94
|
+
tenantId,
|
|
95
|
+
metadata,
|
|
96
|
+
services,
|
|
97
|
+
parentChain: level1.parentChain,
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const level2 = deriveChildState(parent, 'router')
|
|
101
|
+
expect(level2.parentChain).toEqual(['supervisor', 'router'])
|
|
102
|
+
expect(level2.tenantId).toBe(tenantId)
|
|
103
|
+
expect(level2.metadata).toBe(metadata)
|
|
104
|
+
expect(level2.services).toBe(services)
|
|
105
|
+
|
|
106
|
+
const level3 = deriveChildState(level2, 'worker')
|
|
107
|
+
expect(level3.parentChain).toEqual(['supervisor', 'router', 'worker'])
|
|
108
|
+
expect(level3.tenantId).toBe(tenantId)
|
|
109
|
+
expect(level3.metadata).toBe(metadata)
|
|
110
|
+
expect(level3.services).toBe(services)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('should create immutable parentChain', () => {
|
|
114
|
+
const parent: InvocationState = {
|
|
115
|
+
parentChain: ['agent-1'],
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const childState = deriveChildState(parent, 'agent-2')
|
|
119
|
+
|
|
120
|
+
// Ensure the parentChain is a new array, not mutated
|
|
121
|
+
expect(parent.parentChain).toEqual(['agent-1'])
|
|
122
|
+
expect(childState.parentChain).toEqual(['agent-1', 'agent-2'])
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('should handle empty parentChain in parent', () => {
|
|
126
|
+
const parent: InvocationState = {
|
|
127
|
+
parentChain: [],
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const childState = deriveChildState(parent, 'agent-first')
|
|
131
|
+
|
|
132
|
+
expect(childState.parentChain).toEqual(['agent-first'])
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('should allow complex agent IDs in parentChain', () => {
|
|
136
|
+
const agentIds = ['supervisor-agent-123', 'router-multi-path', 'worker-task-handler']
|
|
137
|
+
|
|
138
|
+
let state: InvocationState | undefined
|
|
139
|
+
for (const agentId of agentIds) {
|
|
140
|
+
state = deriveChildState(state, agentId)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
expect(state?.parentChain).toEqual(agentIds)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('should not mutate parent state', () => {
|
|
147
|
+
const parent: InvocationState = {
|
|
148
|
+
parentChain: ['original'],
|
|
149
|
+
tenantId: 'ten_orig' as TenantId,
|
|
150
|
+
metadata: { key: 'value' },
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const originalParentChain = [...parent.parentChain!]
|
|
154
|
+
|
|
155
|
+
deriveChildState(parent, 'child')
|
|
156
|
+
|
|
157
|
+
// Parent state should remain unchanged
|
|
158
|
+
expect(parent.parentChain).toEqual(originalParentChain)
|
|
159
|
+
expect(parent.parentChain).toEqual(['original'])
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
describe('InvocationState immutability', () => {
|
|
164
|
+
it('should have readonly fields', () => {
|
|
165
|
+
const state: InvocationState = {
|
|
166
|
+
tenantId: 'ten_test' as TenantId,
|
|
167
|
+
metadata: { key: 'value' },
|
|
168
|
+
services: { db: 'postgres' },
|
|
169
|
+
parentChain: ['agent-1'],
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Type system enforces immutability, so these assertions verify the type definitions
|
|
173
|
+
expect(state.tenantId).toBe('ten_test')
|
|
174
|
+
expect(state.metadata).toBeDefined()
|
|
175
|
+
expect(state.services).toBeDefined()
|
|
176
|
+
expect(state.parentChain).toBeDefined()
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('should support undefined optional fields', () => {
|
|
180
|
+
const minimalState: InvocationState = {
|
|
181
|
+
parentChain: ['agent-1'],
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
expect(minimalState.tenantId).toBeUndefined()
|
|
185
|
+
expect(minimalState.metadata).toBeUndefined()
|
|
186
|
+
expect(minimalState.services).toBeUndefined()
|
|
187
|
+
expect(minimalState.parentChain).toEqual(['agent-1'])
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('should handle metadata with various types', () => {
|
|
191
|
+
const metadata = {
|
|
192
|
+
userId: 'user-123',
|
|
193
|
+
count: 42,
|
|
194
|
+
enabled: true,
|
|
195
|
+
nested: { key: 'value' },
|
|
196
|
+
array: [1, 2, 3],
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const state: InvocationState = {
|
|
200
|
+
metadata,
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
expect(state.metadata?.userId).toBe('user-123')
|
|
204
|
+
expect(state.metadata?.count).toBe(42)
|
|
205
|
+
expect(state.metadata?.enabled).toBe(true)
|
|
206
|
+
expect(state.metadata?.nested).toEqual({ key: 'value' })
|
|
207
|
+
expect(state.metadata?.array).toEqual([1, 2, 3])
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { TenantId } from '../ids/index.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared state passed through agent hierarchies.
|
|
5
|
+
*
|
|
6
|
+
* This state is NOT visible to the LLM — it carries runtime context
|
|
7
|
+
* like DB clients, tenant info, session metadata, etc. that sub-agents
|
|
8
|
+
* need to access but should not expose to the LLM.
|
|
9
|
+
*
|
|
10
|
+
* The invocation state flows through the entire agent call chain:
|
|
11
|
+
* - Top-level caller creates or provides initial state
|
|
12
|
+
* - SupervisorAgent/RouterAgent derives child state with extended parentChain
|
|
13
|
+
* - Child agents receive the state in their config
|
|
14
|
+
* - Tools can access state via ToolContext.invocationState
|
|
15
|
+
*/
|
|
16
|
+
export interface InvocationState {
|
|
17
|
+
/** Tenant context for multi-tenant isolation (if applicable) */
|
|
18
|
+
readonly tenantId?: TenantId
|
|
19
|
+
|
|
20
|
+
/** Request-scoped metadata (user info, session, correlation IDs, etc.) */
|
|
21
|
+
readonly metadata?: Readonly<Record<string, unknown>>
|
|
22
|
+
|
|
23
|
+
/** Shared services (DB clients, external APIs, cache, etc.) */
|
|
24
|
+
readonly services?: Readonly<Record<string, unknown>>
|
|
25
|
+
|
|
26
|
+
/** Parent agent chain for debugging/tracing (agent IDs in order) */
|
|
27
|
+
readonly parentChain?: readonly string[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a child invocation state with the current agent appended to parentChain.
|
|
32
|
+
*
|
|
33
|
+
* This function is called by SupervisorAgent and RouterAgent when delegating
|
|
34
|
+
* to sub-agents. It ensures the full agent hierarchy is tracked for debugging,
|
|
35
|
+
* logging, and tenant isolation validation.
|
|
36
|
+
*
|
|
37
|
+
* @param parent The parent invocation state (may be undefined for top-level agents)
|
|
38
|
+
* @param currentAgentId The ID of the agent making the delegation
|
|
39
|
+
* @returns A new InvocationState with currentAgentId appended to parentChain
|
|
40
|
+
*/
|
|
41
|
+
export function deriveChildState(
|
|
42
|
+
parent: InvocationState | undefined,
|
|
43
|
+
currentAgentId: string,
|
|
44
|
+
): InvocationState {
|
|
45
|
+
const parentChain = parent?.parentChain
|
|
46
|
+
? [...parent.parentChain, currentAgentId]
|
|
47
|
+
: [currentAgentId]
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
tenantId: parent?.tenantId,
|
|
51
|
+
metadata: parent?.metadata,
|
|
52
|
+
services: parent?.services,
|
|
53
|
+
parentChain,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -125,6 +125,25 @@ export type PluginHookResult =
|
|
|
125
125
|
| { action: 'skip'; reason: string }
|
|
126
126
|
| { action: 'modify'; input: unknown }
|
|
127
127
|
| { action: 'error'; message: string }
|
|
128
|
+
| { action: 'resume'; input: string }
|
|
129
|
+
| { action: 'retry' }
|
|
130
|
+
|
|
131
|
+
export function assertPluginHookResult(result: PluginHookResult): asserts result {
|
|
132
|
+
const action = result.action
|
|
133
|
+
switch (action) {
|
|
134
|
+
case 'continue':
|
|
135
|
+
case 'skip':
|
|
136
|
+
case 'modify':
|
|
137
|
+
case 'error':
|
|
138
|
+
case 'resume':
|
|
139
|
+
case 'retry':
|
|
140
|
+
break
|
|
141
|
+
default: {
|
|
142
|
+
const _exhaustive: never = action
|
|
143
|
+
throw new Error(`Unknown PluginHookResult action: ${_exhaustive}`)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
128
147
|
|
|
129
148
|
export interface PluginHookDefinition {
|
|
130
149
|
readonly event: PluginHookEvent
|
package/src/types/run/events.ts
CHANGED
|
@@ -7,16 +7,7 @@ import type { PlanStep } from '../plan/index.js'
|
|
|
7
7
|
import type { PluginHookEvent, PluginHookResult } from '../plugin/index.js'
|
|
8
8
|
import type { TaskStatus } from '../task/index.js'
|
|
9
9
|
|
|
10
|
-
export type StopReason
|
|
11
|
-
| 'end_turn'
|
|
12
|
-
| 'token_budget'
|
|
13
|
-
| 'cost_limit'
|
|
14
|
-
| 'timeout'
|
|
15
|
-
| 'max_iterations'
|
|
16
|
-
| 'cancelled'
|
|
17
|
-
| 'plan_rejected'
|
|
18
|
-
| 'paused'
|
|
19
|
-
| 'error'
|
|
10
|
+
export type { StopReason } from './stop-reason.js'
|
|
20
11
|
|
|
21
12
|
export type RunEvent =
|
|
22
13
|
| { type: 'run_started'; runId: RunId; systemPrompt?: string }
|
package/src/types/run/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentStatus, CostInfo, TokenUsage } from '../common/index.js'
|
|
2
2
|
import type { RunId, TaskId, ThreadId } from '../ids/index.js'
|
|
3
|
-
import type { StopReason } from './
|
|
3
|
+
import type { StopReason } from './stop-reason.js'
|
|
4
4
|
|
|
5
5
|
export interface RunMetadata {
|
|
6
6
|
id: RunId
|
package/src/types/run/state.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AgentStatus, CostInfo, TokenUsage } from '../common/index.js'
|
|
|
2
2
|
import type { RunId } from '../ids/index.js'
|
|
3
3
|
import type { Message } from '../message/index.js'
|
|
4
4
|
import type { AgentRunConfig } from './config.js'
|
|
5
|
-
import type { StopReason } from './
|
|
5
|
+
import type { StopReason } from './stop-reason.js'
|
|
6
6
|
|
|
7
7
|
export interface RunStateMetadata {
|
|
8
8
|
agentId: string
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for structured output via tool constraint.
|
|
5
|
+
*
|
|
6
|
+
* This configuration allows an agent to produce validated, typed output by
|
|
7
|
+
* presenting the output schema as a special tool that the model must call.
|
|
8
|
+
*/
|
|
9
|
+
export interface StructuredOutputConfig<TSchema extends z.ZodType = z.ZodType> {
|
|
10
|
+
/**
|
|
11
|
+
* The Zod schema that defines the output structure.
|
|
12
|
+
* Used for both validation and LLM tool schema generation.
|
|
13
|
+
*/
|
|
14
|
+
schema: TSchema
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether to force the model to use the structured_output tool.
|
|
18
|
+
* When true, sets tool_choice to force the tool.
|
|
19
|
+
* When false, the model may choose to call it or not.
|
|
20
|
+
* Default: true
|
|
21
|
+
*/
|
|
22
|
+
enforceToolChoice?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Result from structured output tool execution.
|
|
27
|
+
*
|
|
28
|
+
* The structured_output tool returns this result after validating
|
|
29
|
+
* the input against the provided schema.
|
|
30
|
+
*/
|
|
31
|
+
export interface StructuredOutputResult<T = unknown> {
|
|
32
|
+
/**
|
|
33
|
+
* Whether the structured output was successfully produced.
|
|
34
|
+
* Always true for successful tool execution (validation happens at schema level).
|
|
35
|
+
*/
|
|
36
|
+
success: boolean
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The parsed and validated output data.
|
|
40
|
+
* Type is inferred from the Zod schema.
|
|
41
|
+
*/
|
|
42
|
+
data?: T
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Error message if structured output failed.
|
|
46
|
+
* This would typically come from schema validation errors
|
|
47
|
+
* that occur before tool execution.
|
|
48
|
+
*/
|
|
49
|
+
error?: string
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The raw JSON string representation of the output.
|
|
53
|
+
* Useful for logging or debugging.
|
|
54
|
+
*/
|
|
55
|
+
rawOutput?: string
|
|
56
|
+
}
|
package/src/types/tool/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { z } from 'zod'
|
|
2
2
|
import type { Logger } from '../../utils/logger.js'
|
|
3
3
|
import type { RunId } from '../ids/index.js'
|
|
4
|
+
import type { InvocationState } from '../invocation/index.js'
|
|
4
5
|
import type { PermissionMode } from '../permission/index.js'
|
|
5
6
|
import type { Sandbox } from '../sandbox/index.js'
|
|
6
7
|
|
|
@@ -22,6 +23,8 @@ export interface ToolContext {
|
|
|
22
23
|
workingDirectory: string
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
invocationState?: InvocationState
|
|
27
|
+
|
|
25
28
|
toolRegistry?: ToolRegistryRef
|
|
26
29
|
sandbox?: Sandbox
|
|
27
30
|
}
|
|
@@ -84,3 +87,45 @@ export interface ToolRegistryConfig {
|
|
|
84
87
|
logger?: Logger
|
|
85
88
|
tierConfig?: ToolTierConfig
|
|
86
89
|
}
|
|
90
|
+
|
|
91
|
+
export interface ToolExecutionResult extends ToolResult {
|
|
92
|
+
permissionDenied?: boolean
|
|
93
|
+
permissionMessage?: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Full tool registry contract — registration, lookup, execution, prompt generation.
|
|
98
|
+
* Concrete implementation: `ToolRegistry` in `registry/tool/execute.ts`.
|
|
99
|
+
*/
|
|
100
|
+
export interface ToolRegistryContract {
|
|
101
|
+
register(id: string, tool: ToolDefinition): void
|
|
102
|
+
register(tool: ToolDefinition, initialState?: ToolAvailability): void
|
|
103
|
+
register(tools: ToolDefinition[], initialState?: ToolAvailability): void
|
|
104
|
+
|
|
105
|
+
unregister(id: string): boolean
|
|
106
|
+
clear(): void
|
|
107
|
+
|
|
108
|
+
get(name: string): ToolDefinition | undefined
|
|
109
|
+
getOrThrow(name: string): ToolDefinition
|
|
110
|
+
has(name: string): boolean
|
|
111
|
+
getAll(): ToolDefinition[]
|
|
112
|
+
listIds(): string[]
|
|
113
|
+
listNames(): string[]
|
|
114
|
+
|
|
115
|
+
getAvailability(name: string): ToolAvailability
|
|
116
|
+
activate(names: string[]): void
|
|
117
|
+
defer(names: string[]): void
|
|
118
|
+
suspendAll(): void
|
|
119
|
+
hasSuspended(): boolean
|
|
120
|
+
searchDeferred(query: string): ToolDefinition[]
|
|
121
|
+
getCallableTools(toolNames?: string[]): ToolDefinition[]
|
|
122
|
+
|
|
123
|
+
execute(toolName: string, rawInput: unknown, context: ToolContext): Promise<ToolExecutionResult>
|
|
124
|
+
|
|
125
|
+
size(): number
|
|
126
|
+
|
|
127
|
+
toLLMTools(toolNames?: string[]): LLMToolSchema[]
|
|
128
|
+
toPromptSection(toolNames?: string[]): string
|
|
129
|
+
toTierGuidance(): string | null
|
|
130
|
+
assignTiers(mapping: Record<string, string>): void
|
|
131
|
+
}
|