@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.
Files changed (324) hide show
  1. package/dist/advisory/executor.d.ts +2 -2
  2. package/dist/advisory/executor.d.ts.map +1 -1
  3. package/dist/advisory/executor.js.map +1 -1
  4. package/dist/agents/AbstractAgent.d.ts +20 -2
  5. package/dist/agents/AbstractAgent.d.ts.map +1 -1
  6. package/dist/agents/AbstractAgent.js +23 -1
  7. package/dist/agents/AbstractAgent.js.map +1 -1
  8. package/dist/agents/PipelineAgent.d.ts.map +1 -1
  9. package/dist/agents/PipelineAgent.js +1 -1
  10. package/dist/agents/PipelineAgent.js.map +1 -1
  11. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  12. package/dist/agents/ReactiveAgent.js +1 -0
  13. package/dist/agents/ReactiveAgent.js.map +1 -1
  14. package/dist/agents/RouterAgent.d.ts.map +1 -1
  15. package/dist/agents/RouterAgent.js +4 -2
  16. package/dist/agents/RouterAgent.js.map +1 -1
  17. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  18. package/dist/agents/SupervisorAgent.js +4 -1
  19. package/dist/agents/SupervisorAgent.js.map +1 -1
  20. package/dist/agents/__tests__/lock.test.d.ts +2 -0
  21. package/dist/agents/__tests__/lock.test.d.ts.map +1 -0
  22. package/dist/agents/__tests__/lock.test.js +131 -0
  23. package/dist/agents/__tests__/lock.test.js.map +1 -0
  24. package/dist/agents/index.d.ts +2 -0
  25. package/dist/agents/index.d.ts.map +1 -1
  26. package/dist/agents/index.js +1 -0
  27. package/dist/agents/index.js.map +1 -1
  28. package/dist/agents/lock.d.ts +42 -0
  29. package/dist/agents/lock.d.ts.map +1 -0
  30. package/dist/agents/lock.js +54 -0
  31. package/dist/agents/lock.js.map +1 -0
  32. package/dist/bridge/a2a/message.d.ts.map +1 -1
  33. package/dist/bridge/a2a/message.js.map +1 -1
  34. package/dist/bridge/tools/connector/router.d.ts +4 -5
  35. package/dist/bridge/tools/connector/router.d.ts.map +1 -1
  36. package/dist/bridge/tools/connector/router.js.map +1 -1
  37. package/dist/compaction/__tests__/SlidingWindowManager.test.d.ts +2 -0
  38. package/dist/compaction/__tests__/SlidingWindowManager.test.d.ts.map +1 -0
  39. package/dist/compaction/__tests__/SlidingWindowManager.test.js +113 -0
  40. package/dist/compaction/__tests__/SlidingWindowManager.test.js.map +1 -0
  41. package/dist/compaction/__tests__/dangling.test.d.ts +2 -0
  42. package/dist/compaction/__tests__/dangling.test.d.ts.map +1 -0
  43. package/dist/compaction/__tests__/dangling.test.js +356 -0
  44. package/dist/compaction/__tests__/dangling.test.js.map +1 -0
  45. package/dist/compaction/__tests__/factory.test.d.ts +2 -0
  46. package/dist/compaction/__tests__/factory.test.d.ts.map +1 -0
  47. package/dist/compaction/__tests__/factory.test.js +43 -0
  48. package/dist/compaction/__tests__/factory.test.js.map +1 -0
  49. package/dist/compaction/dangling.d.ts +96 -0
  50. package/dist/compaction/dangling.d.ts.map +1 -0
  51. package/dist/compaction/dangling.js +274 -0
  52. package/dist/compaction/dangling.js.map +1 -0
  53. package/dist/compaction/factory.d.ts +20 -0
  54. package/dist/compaction/factory.d.ts.map +1 -0
  55. package/dist/compaction/factory.js +35 -0
  56. package/dist/compaction/factory.js.map +1 -0
  57. package/dist/compaction/index.d.ts +5 -0
  58. package/dist/compaction/index.d.ts.map +1 -1
  59. package/dist/compaction/index.js +3 -0
  60. package/dist/compaction/index.js.map +1 -1
  61. package/dist/compaction/interface.d.ts +33 -0
  62. package/dist/compaction/interface.d.ts.map +1 -0
  63. package/dist/compaction/interface.js +2 -0
  64. package/dist/compaction/interface.js.map +1 -0
  65. package/dist/compaction/managers/index.d.ts +4 -0
  66. package/dist/compaction/managers/index.d.ts.map +1 -0
  67. package/dist/compaction/managers/index.js +4 -0
  68. package/dist/compaction/managers/index.js.map +1 -0
  69. package/dist/compaction/managers/null.d.ts +12 -0
  70. package/dist/compaction/managers/null.d.ts.map +1 -0
  71. package/dist/compaction/managers/null.js +15 -0
  72. package/dist/compaction/managers/null.js.map +1 -0
  73. package/dist/compaction/managers/slidingWindow.d.ts +27 -0
  74. package/dist/compaction/managers/slidingWindow.d.ts.map +1 -0
  75. package/dist/compaction/managers/slidingWindow.js +41 -0
  76. package/dist/compaction/managers/slidingWindow.js.map +1 -0
  77. package/dist/compaction/managers/structured.d.ts +23 -0
  78. package/dist/compaction/managers/structured.d.ts.map +1 -0
  79. package/dist/compaction/managers/structured.js +144 -0
  80. package/dist/compaction/managers/structured.js.map +1 -0
  81. package/dist/compaction/types.d.ts +1 -1
  82. package/dist/compaction/types.d.ts.map +1 -1
  83. package/dist/config/runtime.d.ts +16 -16
  84. package/dist/config/runtime.js +1 -1
  85. package/dist/config/runtime.js.map +1 -1
  86. package/dist/constants/agent/index.d.ts +1 -1
  87. package/dist/constants/agent/index.d.ts.map +1 -1
  88. package/dist/gateway/local.d.ts +2 -2
  89. package/dist/gateway/local.d.ts.map +1 -1
  90. package/dist/gateway/local.js +10 -1
  91. package/dist/gateway/local.js.map +1 -1
  92. package/dist/index.d.ts +18 -4
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +12 -2
  95. package/dist/index.js.map +1 -1
  96. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  97. package/dist/manager/agent/lifecycle.js +3 -2
  98. package/dist/manager/agent/lifecycle.js.map +1 -1
  99. package/dist/manager/run/persistence.d.ts +1 -2
  100. package/dist/manager/run/persistence.d.ts.map +1 -1
  101. package/dist/manager/run/persistence.js +2 -1
  102. package/dist/manager/run/persistence.js.map +1 -1
  103. package/dist/plugin/__tests__/lifecycle.test.d.ts +2 -0
  104. package/dist/plugin/__tests__/lifecycle.test.d.ts.map +1 -0
  105. package/dist/plugin/__tests__/lifecycle.test.js +332 -0
  106. package/dist/plugin/__tests__/lifecycle.test.js.map +1 -0
  107. package/dist/plugin/lifecycle.d.ts +2 -2
  108. package/dist/plugin/lifecycle.d.ts.map +1 -1
  109. package/dist/plugin/lifecycle.js +28 -2
  110. package/dist/plugin/lifecycle.js.map +1 -1
  111. package/dist/plugin/resolver.d.ts +2 -2
  112. package/dist/plugin/resolver.d.ts.map +1 -1
  113. package/dist/plugin/resolver.js.map +1 -1
  114. package/dist/registry/agent/definitions.d.ts +3 -2
  115. package/dist/registry/agent/definitions.d.ts.map +1 -1
  116. package/dist/registry/agent/definitions.js.map +1 -1
  117. package/dist/registry/tool/execute.d.ts +2 -5
  118. package/dist/registry/tool/execute.d.ts.map +1 -1
  119. package/dist/registry/tool/execute.js.map +1 -1
  120. package/dist/runtime/decision/parser.d.ts.map +1 -1
  121. package/dist/runtime/decision/parser.js +15 -40
  122. package/dist/runtime/decision/parser.js.map +1 -1
  123. package/dist/runtime/query/context-cache.d.ts +3 -3
  124. package/dist/runtime/query/context-cache.d.ts.map +1 -1
  125. package/dist/runtime/query/context-cache.js.map +1 -1
  126. package/dist/runtime/query/context.d.ts +1 -1
  127. package/dist/runtime/query/context.d.ts.map +1 -1
  128. package/dist/runtime/query/context.js.map +1 -1
  129. package/dist/runtime/query/events.js +11 -11
  130. package/dist/runtime/query/events.js.map +1 -1
  131. package/dist/runtime/query/executor.d.ts +4 -2
  132. package/dist/runtime/query/executor.d.ts.map +1 -1
  133. package/dist/runtime/query/executor.js +1 -0
  134. package/dist/runtime/query/executor.js.map +1 -1
  135. package/dist/runtime/query/index.d.ts +5 -3
  136. package/dist/runtime/query/index.d.ts.map +1 -1
  137. package/dist/runtime/query/index.js +2 -1
  138. package/dist/runtime/query/index.js.map +1 -1
  139. package/dist/runtime/query/iteration/index.d.ts +2 -2
  140. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  141. package/dist/runtime/query/iteration/index.js.map +1 -1
  142. package/dist/runtime/query/iteration/phases/advisory.d.ts.map +1 -1
  143. package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
  144. package/dist/runtime/query/iteration/phases/checkpoint.d.ts +1 -1
  145. package/dist/runtime/query/iteration/phases/checkpoint.d.ts.map +1 -1
  146. package/dist/runtime/query/iteration/phases/checkpoint.js.map +1 -1
  147. package/dist/runtime/query/iteration/phases/context.d.ts +2 -2
  148. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  149. package/dist/runtime/query/iteration/phases/plan.d.ts +1 -1
  150. package/dist/runtime/query/iteration/phases/plan.d.ts.map +1 -1
  151. package/dist/runtime/query/iteration/phases/plan.js.map +1 -1
  152. package/dist/runtime/query/prompt.d.ts +2 -2
  153. package/dist/runtime/query/prompt.d.ts.map +1 -1
  154. package/dist/runtime/query/prompt.js.map +1 -1
  155. package/dist/runtime/query/result.d.ts +1 -1
  156. package/dist/runtime/query/result.d.ts.map +1 -1
  157. package/dist/runtime/query/result.js.map +1 -1
  158. package/dist/runtime/query/tooling.d.ts +4 -2
  159. package/dist/runtime/query/tooling.d.ts.map +1 -1
  160. package/dist/runtime/query/tooling.js +1 -0
  161. package/dist/runtime/query/tooling.js.map +1 -1
  162. package/dist/store/conversation/memory.d.ts +1 -1
  163. package/dist/store/conversation/memory.d.ts.map +1 -1
  164. package/dist/store/conversation/memory.js +15 -3
  165. package/dist/store/conversation/memory.js.map +1 -1
  166. package/dist/store/run/disk.d.ts +1 -2
  167. package/dist/store/run/disk.d.ts.map +1 -1
  168. package/dist/store/run/disk.js +21 -13
  169. package/dist/store/run/disk.js.map +1 -1
  170. package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts +140 -0
  171. package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts.map +1 -0
  172. package/dist/tools/builtins/__tests__/structuredOutput.example.js +183 -0
  173. package/dist/tools/builtins/__tests__/structuredOutput.example.js.map +1 -0
  174. package/dist/tools/builtins/__tests__/structuredOutput.test.d.ts +2 -0
  175. package/dist/tools/builtins/__tests__/structuredOutput.test.d.ts.map +1 -0
  176. package/dist/tools/builtins/__tests__/structuredOutput.test.js +224 -0
  177. package/dist/tools/builtins/__tests__/structuredOutput.test.js.map +1 -0
  178. package/dist/tools/builtins/grep.d.ts.map +1 -1
  179. package/dist/tools/builtins/grep.js +1 -2
  180. package/dist/tools/builtins/grep.js.map +1 -1
  181. package/dist/tools/builtins/index.d.ts +1 -0
  182. package/dist/tools/builtins/index.d.ts.map +1 -1
  183. package/dist/tools/builtins/index.js +3 -0
  184. package/dist/tools/builtins/index.js.map +1 -1
  185. package/dist/tools/builtins/ls.d.ts +1 -1
  186. package/dist/tools/builtins/structuredOutput.d.ts +27 -0
  187. package/dist/tools/builtins/structuredOutput.d.ts.map +1 -0
  188. package/dist/tools/builtins/structuredOutput.js +46 -0
  189. package/dist/tools/builtins/structuredOutput.js.map +1 -0
  190. package/dist/tools/task/list.d.ts +1 -1
  191. package/dist/tools/task/list.d.ts.map +1 -1
  192. package/dist/tools/task/list.js.map +1 -1
  193. package/dist/types/agent/base.d.ts +4 -1
  194. package/dist/types/agent/base.d.ts.map +1 -1
  195. package/dist/types/agent/index.d.ts +1 -0
  196. package/dist/types/agent/index.d.ts.map +1 -1
  197. package/dist/types/agent/index.js +1 -0
  198. package/dist/types/agent/index.js.map +1 -1
  199. package/dist/types/agent/manager.d.ts +27 -0
  200. package/dist/types/agent/manager.d.ts.map +1 -0
  201. package/dist/types/agent/manager.js +2 -0
  202. package/dist/types/agent/manager.js.map +1 -0
  203. package/dist/types/agent/reactive.d.ts +2 -2
  204. package/dist/types/agent/reactive.d.ts.map +1 -1
  205. package/dist/types/agent/supervisor.d.ts +2 -2
  206. package/dist/types/agent/supervisor.d.ts.map +1 -1
  207. package/dist/types/agent/task.d.ts +0 -2
  208. package/dist/types/agent/task.d.ts.map +1 -1
  209. package/dist/types/agent/task.js +0 -2
  210. package/dist/types/agent/task.js.map +1 -1
  211. package/dist/types/common/index.d.ts +0 -1
  212. package/dist/types/common/index.d.ts.map +1 -1
  213. package/dist/types/common/index.js +0 -1
  214. package/dist/types/common/index.js.map +1 -1
  215. package/dist/types/hitl/index.d.ts +1 -2
  216. package/dist/types/hitl/index.d.ts.map +1 -1
  217. package/dist/types/hitl/index.js.map +1 -1
  218. package/dist/types/invocation/__tests__/state.test.d.ts +2 -0
  219. package/dist/types/invocation/__tests__/state.test.d.ts.map +1 -0
  220. package/dist/types/invocation/__tests__/state.test.js +167 -0
  221. package/dist/types/invocation/__tests__/state.test.js.map +1 -0
  222. package/dist/types/invocation/index.d.ts +37 -0
  223. package/dist/types/invocation/index.d.ts.map +1 -0
  224. package/dist/types/invocation/index.js +23 -0
  225. package/dist/types/invocation/index.js.map +1 -0
  226. package/dist/types/plugin/index.d.ts +6 -0
  227. package/dist/types/plugin/index.d.ts.map +1 -1
  228. package/dist/types/plugin/index.js +16 -0
  229. package/dist/types/plugin/index.js.map +1 -1
  230. package/dist/types/run/events.d.ts +1 -1
  231. package/dist/types/run/events.d.ts.map +1 -1
  232. package/dist/types/run/index.d.ts +1 -0
  233. package/dist/types/run/index.d.ts.map +1 -1
  234. package/dist/types/run/index.js +1 -0
  235. package/dist/types/run/index.js.map +1 -1
  236. package/dist/types/run/metadata.d.ts +1 -1
  237. package/dist/types/run/metadata.d.ts.map +1 -1
  238. package/dist/types/run/state.d.ts +1 -1
  239. package/dist/types/run/state.d.ts.map +1 -1
  240. package/dist/types/run/stop-reason.d.ts +2 -0
  241. package/dist/types/run/stop-reason.d.ts.map +1 -0
  242. package/dist/types/run/stop-reason.js +2 -0
  243. package/dist/types/run/stop-reason.js.map +1 -0
  244. package/dist/types/structured-output/index.d.ts +51 -0
  245. package/dist/types/structured-output/index.d.ts.map +1 -0
  246. package/dist/types/structured-output/index.js +2 -0
  247. package/dist/types/structured-output/index.js.map +1 -0
  248. package/dist/types/tool/index.d.ts +36 -0
  249. package/dist/types/tool/index.d.ts.map +1 -1
  250. package/package.json +1 -1
  251. package/src/advisory/executor.ts +2 -4
  252. package/src/agents/AbstractAgent.ts +26 -3
  253. package/src/agents/PipelineAgent.ts +1 -1
  254. package/src/agents/ReactiveAgent.ts +1 -0
  255. package/src/agents/RouterAgent.ts +8 -2
  256. package/src/agents/SupervisorAgent.ts +5 -1
  257. package/src/agents/__tests__/lock.test.ts +158 -0
  258. package/src/agents/index.ts +2 -0
  259. package/src/agents/lock.ts +66 -0
  260. package/src/bridge/a2a/message.ts +1 -2
  261. package/src/bridge/tools/connector/router.ts +4 -5
  262. package/src/compaction/__tests__/SlidingWindowManager.test.ts +139 -0
  263. package/src/compaction/__tests__/dangling.test.ts +447 -0
  264. package/src/compaction/__tests__/factory.test.ts +53 -0
  265. package/src/compaction/dangling.ts +321 -0
  266. package/src/compaction/factory.ts +41 -0
  267. package/src/compaction/index.ts +14 -0
  268. package/src/compaction/interface.ts +35 -0
  269. package/src/compaction/managers/index.ts +3 -0
  270. package/src/compaction/managers/null.ts +19 -0
  271. package/src/compaction/managers/slidingWindow.ts +57 -0
  272. package/src/compaction/managers/structured.ts +169 -0
  273. package/src/compaction/types.ts +1 -1
  274. package/src/config/runtime.ts +1 -1
  275. package/src/constants/agent/index.ts +1 -1
  276. package/src/gateway/local.ts +13 -4
  277. package/src/index.ts +38 -1
  278. package/src/manager/agent/lifecycle.ts +3 -2
  279. package/src/manager/run/persistence.ts +3 -8
  280. package/src/plugin/__tests__/lifecycle.test.ts +430 -0
  281. package/src/plugin/lifecycle.ts +32 -6
  282. package/src/plugin/resolver.ts +3 -3
  283. package/src/registry/agent/definitions.ts +3 -2
  284. package/src/registry/tool/execute.ts +2 -5
  285. package/src/runtime/decision/parser.ts +15 -40
  286. package/src/runtime/query/context-cache.ts +3 -4
  287. package/src/runtime/query/context.ts +1 -2
  288. package/src/runtime/query/events.ts +11 -11
  289. package/src/runtime/query/executor.ts +5 -3
  290. package/src/runtime/query/index.ts +11 -4
  291. package/src/runtime/query/iteration/index.ts +2 -2
  292. package/src/runtime/query/iteration/phases/advisory.ts +1 -2
  293. package/src/runtime/query/iteration/phases/checkpoint.ts +1 -2
  294. package/src/runtime/query/iteration/phases/context.ts +2 -2
  295. package/src/runtime/query/iteration/phases/plan.ts +1 -2
  296. package/src/runtime/query/prompt.ts +3 -3
  297. package/src/runtime/query/result.ts +1 -2
  298. package/src/runtime/query/tooling.ts +5 -2
  299. package/src/store/conversation/memory.ts +21 -5
  300. package/src/store/run/disk.ts +18 -16
  301. package/src/tools/builtins/__tests__/structuredOutput.example.ts +221 -0
  302. package/src/tools/builtins/__tests__/structuredOutput.test.ts +275 -0
  303. package/src/tools/builtins/grep.ts +1 -2
  304. package/src/tools/builtins/index.ts +3 -0
  305. package/src/tools/builtins/structuredOutput.ts +55 -0
  306. package/src/tools/task/list.ts +1 -2
  307. package/src/types/agent/base.ts +5 -1
  308. package/src/types/agent/index.ts +1 -0
  309. package/src/types/agent/manager.ts +36 -0
  310. package/src/types/agent/reactive.ts +2 -2
  311. package/src/types/agent/supervisor.ts +2 -2
  312. package/src/types/agent/task.ts +0 -4
  313. package/src/types/common/index.ts +0 -2
  314. package/src/types/hitl/index.ts +1 -2
  315. package/src/types/invocation/__tests__/state.test.ts +210 -0
  316. package/src/types/invocation/index.ts +55 -0
  317. package/src/types/plugin/index.ts +19 -0
  318. package/src/types/run/events.ts +1 -10
  319. package/src/types/run/index.ts +1 -0
  320. package/src/types/run/metadata.ts +1 -1
  321. package/src/types/run/state.ts +1 -1
  322. package/src/types/run/stop-reason.ts +10 -0
  323. package/src/types/structured-output/index.ts +56 -0
  324. package/src/types/tool/index.ts +45 -0
@@ -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,
@@ -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
@@ -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 }
@@ -1,3 +1,4 @@
1
+ export * from './stop-reason.js'
1
2
  export * from './config.js'
2
3
  export * from './state.js'
3
4
  export * from './events.js'
@@ -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 './events.js'
3
+ import type { StopReason } from './stop-reason.js'
4
4
 
5
5
  export interface RunMetadata {
6
6
  id: RunId
@@ -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 './events.js'
5
+ import type { StopReason } from './stop-reason.js'
6
6
 
7
7
  export interface RunStateMetadata {
8
8
  agentId: string
@@ -0,0 +1,10 @@
1
+ export type StopReason =
2
+ | 'end_turn'
3
+ | 'token_budget'
4
+ | 'cost_limit'
5
+ | 'timeout'
6
+ | 'max_iterations'
7
+ | 'cancelled'
8
+ | 'plan_rejected'
9
+ | 'paused'
10
+ | 'error'
@@ -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
+ }
@@ -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
+ }