agentfootprint 6.43.0 → 6.45.0

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 (397) hide show
  1. package/ai-instructions/setup.sh +0 -0
  2. package/dist/core/RunnerBase.js +7 -0
  3. package/dist/core/RunnerBase.js.map +1 -1
  4. package/dist/core/agent/buildAgentChart.js +2 -1
  5. package/dist/core/agent/buildAgentChart.js.map +1 -1
  6. package/dist/core/agent/buildDynamicAgentChart.js +3 -1
  7. package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
  8. package/dist/core/agent/stages/pickEntry.js +3 -1
  9. package/dist/core/agent/stages/pickEntry.js.map +1 -1
  10. package/dist/esm/adapters/identity/agentcore.d.ts +100 -0
  11. package/dist/esm/adapters/llm/AnthropicProvider.d.ts +130 -0
  12. package/dist/esm/adapters/llm/BedrockProvider.d.ts +100 -0
  13. package/dist/esm/adapters/llm/BrowserAnthropicProvider.d.ts +41 -0
  14. package/dist/esm/adapters/llm/BrowserOpenAIProvider.d.ts +95 -0
  15. package/dist/esm/adapters/llm/MockProvider.d.ts +153 -0
  16. package/dist/esm/adapters/llm/OpenAIProvider.d.ts +220 -0
  17. package/dist/esm/adapters/llm/createProvider.d.ts +85 -0
  18. package/dist/esm/adapters/memory/agentcore.d.ts +146 -0
  19. package/dist/esm/adapters/memory/bedrockAgentMemory.d.ts +95 -0
  20. package/dist/esm/adapters/memory/redis.d.ts +127 -0
  21. package/dist/esm/adapters/observability/agentcore.d.ts +67 -0
  22. package/dist/esm/adapters/observability/audit.d.ts +254 -0
  23. package/dist/esm/adapters/observability/cloudwatch.d.ts +96 -0
  24. package/dist/esm/adapters/observability/otel.d.ts +237 -0
  25. package/dist/esm/adapters/observability/xray.d.ts +88 -0
  26. package/dist/esm/adapters/types.d.ts +378 -0
  27. package/dist/esm/bridge/eventMeta.d.ts +59 -0
  28. package/dist/esm/cache/CacheDecisionSubflow.d.ts +85 -0
  29. package/dist/esm/cache/CacheGateDecider.d.ts +127 -0
  30. package/dist/esm/cache/applyCachePolicy.d.ts +37 -0
  31. package/dist/esm/cache/cacheRecorder.d.ts +85 -0
  32. package/dist/esm/cache/index.d.ts +33 -0
  33. package/dist/esm/cache/strategies/AnthropicCacheStrategy.d.ts +38 -0
  34. package/dist/esm/cache/strategies/BedrockCacheStrategy.d.ts +33 -0
  35. package/dist/esm/cache/strategies/NoOpCacheStrategy.d.ts +29 -0
  36. package/dist/esm/cache/strategies/OpenAICacheStrategy.d.ts +36 -0
  37. package/dist/esm/cache/strategyRegistry.d.ts +45 -0
  38. package/dist/esm/cache/types.d.ts +243 -0
  39. package/dist/esm/conventions.d.ts +203 -0
  40. package/dist/esm/core/Agent.d.ts +355 -0
  41. package/dist/esm/core/LLMCall.d.ts +139 -0
  42. package/dist/esm/core/RunnerBase.d.ts +267 -0
  43. package/dist/esm/core/RunnerBase.js +7 -0
  44. package/dist/esm/core/RunnerBase.js.map +1 -1
  45. package/dist/esm/core/agent/AgentBuilder.d.ts +565 -0
  46. package/dist/esm/core/agent/buildAgentChart.d.ts +109 -0
  47. package/dist/esm/core/agent/buildAgentChart.js +2 -1
  48. package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
  49. package/dist/esm/core/agent/buildAgentMessageApiChart.d.ts +40 -0
  50. package/dist/esm/core/agent/buildCacheSubflow.d.ts +35 -0
  51. package/dist/esm/core/agent/buildDynamicAgentChart.d.ts +56 -0
  52. package/dist/esm/core/agent/buildDynamicAgentChart.js +3 -1
  53. package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
  54. package/dist/esm/core/agent/buildMessageApiChart.d.ts +47 -0
  55. package/dist/esm/core/agent/buildToolRegistry.d.ts +61 -0
  56. package/dist/esm/core/agent/memoryRecallInjections.d.ts +8 -0
  57. package/dist/esm/core/agent/stages/breakFinal.d.ts +22 -0
  58. package/dist/esm/core/agent/stages/callLLM.d.ts +74 -0
  59. package/dist/esm/core/agent/stages/pickEntry.d.ts +19 -0
  60. package/dist/esm/core/agent/stages/pickEntry.js +3 -1
  61. package/dist/esm/core/agent/stages/pickEntry.js.map +1 -1
  62. package/dist/esm/core/agent/stages/prepareFinal.d.ts +19 -0
  63. package/dist/esm/core/agent/stages/reliabilityExecution.d.ts +135 -0
  64. package/dist/esm/core/agent/stages/route.d.ts +18 -0
  65. package/dist/esm/core/agent/stages/seed.d.ts +53 -0
  66. package/dist/esm/core/agent/stages/toolCalls.d.ts +76 -0
  67. package/dist/esm/core/agent/toolArgsValidation.d.ts +62 -0
  68. package/dist/esm/core/agent/types.d.ts +382 -0
  69. package/dist/esm/core/agent/validators.d.ts +52 -0
  70. package/dist/esm/core/cost.d.ts +38 -0
  71. package/dist/esm/core/flowchartAsTool.d.ts +200 -0
  72. package/dist/esm/core/humanizeLLMError.d.ts +23 -0
  73. package/dist/esm/core/outputFallback.d.ts +139 -0
  74. package/dist/esm/core/outputSchema.d.ts +127 -0
  75. package/dist/esm/core/pause.d.ts +74 -0
  76. package/dist/esm/core/runCheckpoint.d.ts +179 -0
  77. package/dist/esm/core/runner.d.ts +203 -0
  78. package/dist/esm/core/slots/buildMessagesSlot.d.ts +40 -0
  79. package/dist/esm/core/slots/buildSystemPromptSlot.d.ts +41 -0
  80. package/dist/esm/core/slots/buildThinkingSubflow.d.ts +40 -0
  81. package/dist/esm/core/slots/buildToolsSlot.d.ts +60 -0
  82. package/dist/esm/core/slots/helpers.d.ts +27 -0
  83. package/dist/esm/core/toolContract.d.ts +43 -0
  84. package/dist/esm/core/tools.d.ts +90 -0
  85. package/dist/esm/core/translator.d.ts +94 -0
  86. package/dist/esm/core-flow/Conditional.d.ts +119 -0
  87. package/dist/esm/core-flow/Loop.d.ts +160 -0
  88. package/dist/esm/core-flow/Parallel.d.ts +360 -0
  89. package/dist/esm/core-flow/Sequence.d.ts +133 -0
  90. package/dist/esm/events/dispatcher.d.ts +134 -0
  91. package/dist/esm/events/payloads.d.ts +761 -0
  92. package/dist/esm/events/registry.d.ts +198 -0
  93. package/dist/esm/events/types.d.ts +70 -0
  94. package/dist/esm/identity/kinds.d.ts +36 -0
  95. package/dist/esm/identity/staticTokens.d.ts +28 -0
  96. package/dist/esm/identity/types.d.ts +113 -0
  97. package/dist/esm/identity/withCredentialRetry.d.ts +64 -0
  98. package/dist/esm/identity.d.ts +31 -0
  99. package/dist/esm/index.d.ts +64 -0
  100. package/dist/esm/index.js +2 -0
  101. package/dist/esm/index.js.map +1 -1
  102. package/dist/esm/injection-engine.d.ts +4 -0
  103. package/dist/esm/lib/canonicalJson.d.ts +56 -0
  104. package/dist/esm/lib/context-bisect/ablation.d.ts +109 -0
  105. package/dist/esm/lib/context-bisect/bisect.d.ts +75 -0
  106. package/dist/esm/lib/context-bisect/cost.d.ts +37 -0
  107. package/dist/esm/lib/context-bisect/index.d.ts +31 -0
  108. package/dist/esm/lib/context-bisect/index.js +3 -0
  109. package/dist/esm/lib/context-bisect/index.js.map +1 -1
  110. package/dist/esm/lib/context-bisect/llmEdgeWeigher.d.ts +124 -0
  111. package/dist/esm/lib/context-bisect/localize.d.ts +152 -0
  112. package/dist/esm/lib/context-bisect/localize.js +2 -0
  113. package/dist/esm/lib/context-bisect/localize.js.map +1 -1
  114. package/dist/esm/lib/context-bisect/loop-recall.d.ts +97 -0
  115. package/dist/esm/lib/context-bisect/missingContext.d.ts +71 -0
  116. package/dist/esm/lib/context-bisect/restoration.d.ts +39 -0
  117. package/dist/esm/lib/context-bisect/toBacktrackTrace.d.ts +138 -0
  118. package/dist/esm/lib/context-bisect/trajectory.d.ts +168 -0
  119. package/dist/esm/lib/context-bisect/types.d.ts +448 -0
  120. package/dist/esm/lib/context-bisect/walk-to-root.d.ts +103 -0
  121. package/dist/esm/lib/influence-core/attributability.d.ts +72 -0
  122. package/dist/esm/lib/influence-core/cache.d.ts +94 -0
  123. package/dist/esm/lib/influence-core/contrastive.d.ts +26 -0
  124. package/dist/esm/lib/influence-core/index.d.ts +34 -0
  125. package/dist/esm/lib/influence-core/margin.d.ts +33 -0
  126. package/dist/esm/lib/influence-core/signals.d.ts +128 -0
  127. package/dist/esm/lib/influence-core/similarity.d.ts +25 -0
  128. package/dist/esm/lib/influence-core/types.d.ts +252 -0
  129. package/dist/esm/lib/injection-engine/SkillRegistry.d.ts +147 -0
  130. package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.d.ts +110 -0
  131. package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
  132. package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
  133. package/dist/esm/lib/injection-engine/entryScorer.d.ts +93 -0
  134. package/dist/esm/lib/injection-engine/entryScorer.js +172 -0
  135. package/dist/esm/lib/injection-engine/entryScorer.js.map +1 -0
  136. package/dist/esm/lib/injection-engine/evaluator.d.ts +24 -0
  137. package/dist/esm/lib/injection-engine/factories/defineFact.d.ts +60 -0
  138. package/dist/esm/lib/injection-engine/factories/defineInjection.d.ts +41 -0
  139. package/dist/esm/lib/injection-engine/factories/defineInstruction.d.ts +78 -0
  140. package/dist/esm/lib/injection-engine/factories/defineRelevanceHint.d.ts +26 -0
  141. package/dist/esm/lib/injection-engine/factories/defineSkill.d.ts +160 -0
  142. package/dist/esm/lib/injection-engine/factories/defineSteering.d.ts +39 -0
  143. package/dist/esm/lib/injection-engine/index.d.ts +22 -0
  144. package/dist/esm/lib/injection-engine/index.js +1 -0
  145. package/dist/esm/lib/injection-engine/index.js.map +1 -1
  146. package/dist/esm/lib/injection-engine/skillContract.d.ts +29 -0
  147. package/dist/esm/lib/injection-engine/skillGraph.d.ts +289 -0
  148. package/dist/esm/lib/injection-engine/skillGraph.js +35 -41
  149. package/dist/esm/lib/injection-engine/skillGraph.js.map +1 -1
  150. package/dist/esm/lib/injection-engine/skillGraphCheckup.d.ts +49 -0
  151. package/dist/esm/lib/injection-engine/skillTools.d.ts +72 -0
  152. package/dist/esm/lib/injection-engine/softmax.d.ts +11 -0
  153. package/dist/esm/lib/injection-engine/types.d.ts +229 -0
  154. package/dist/esm/lib/injection-engine/types.js.map +1 -1
  155. package/dist/esm/lib/lazyRequire.d.ts +29 -0
  156. package/dist/esm/lib/mcp/index.d.ts +9 -0
  157. package/dist/esm/lib/mcp/mcpClient.d.ts +46 -0
  158. package/dist/esm/lib/mcp/mockMcpClient.d.ts +65 -0
  159. package/dist/esm/lib/mcp/types.d.ts +133 -0
  160. package/dist/esm/lib/rag/defineRAG.d.ts +139 -0
  161. package/dist/esm/lib/rag/index.d.ts +7 -0
  162. package/dist/esm/lib/rag/indexDocuments.d.ts +105 -0
  163. package/dist/esm/lib/tool-lint/analyze.d.ts +83 -0
  164. package/dist/esm/lib/tool-lint/cli.d.ts +43 -0
  165. package/dist/esm/lib/tool-lint/format.d.ts +18 -0
  166. package/dist/esm/lib/tool-lint/index.d.ts +23 -0
  167. package/dist/esm/lib/tool-lint/rules.d.ts +85 -0
  168. package/dist/esm/lib/tool-lint/types.d.ts +155 -0
  169. package/dist/esm/lib/trace-toolpack/bounded.d.ts +47 -0
  170. package/dist/esm/lib/trace-toolpack/debugPrompt.d.ts +19 -0
  171. package/dist/esm/lib/trace-toolpack/index.d.ts +20 -0
  172. package/dist/esm/lib/trace-toolpack/lazyToolpack.d.ts +35 -0
  173. package/dist/esm/lib/trace-toolpack/selfExplain.d.ts +100 -0
  174. package/dist/esm/lib/trace-toolpack/traceDebugAgent.d.ts +42 -0
  175. package/dist/esm/lib/trace-toolpack/traceToolpack.d.ts +69 -0
  176. package/dist/esm/lib/trace-toolpack/types.d.ts +59 -0
  177. package/dist/esm/llm-providers.d.ts +26 -0
  178. package/dist/esm/locales/index.d.ts +132 -0
  179. package/dist/esm/memory/beats/extractBeats.d.ts +61 -0
  180. package/dist/esm/memory/beats/extractor.d.ts +47 -0
  181. package/dist/esm/memory/beats/formatAsNarrative.d.ts +62 -0
  182. package/dist/esm/memory/beats/heuristicExtractor.d.ts +37 -0
  183. package/dist/esm/memory/beats/index.d.ts +12 -0
  184. package/dist/esm/memory/beats/llmExtractor.d.ts +56 -0
  185. package/dist/esm/memory/beats/types.d.ts +60 -0
  186. package/dist/esm/memory/beats/writeBeats.d.ts +22 -0
  187. package/dist/esm/memory/causal/evidenceRecorder.d.ts +66 -0
  188. package/dist/esm/memory/causal/index.d.ts +6 -0
  189. package/dist/esm/memory/causal/loadSnapshot.d.ts +51 -0
  190. package/dist/esm/memory/causal/snapshotPipeline.d.ts +35 -0
  191. package/dist/esm/memory/causal/types.d.ts +130 -0
  192. package/dist/esm/memory/causal/writeSnapshot.d.ts +73 -0
  193. package/dist/esm/memory/define.d.ts +63 -0
  194. package/dist/esm/memory/define.types.d.ts +276 -0
  195. package/dist/esm/memory/define.types.js +1 -1
  196. package/dist/esm/memory/embedding/cosine.d.ts +18 -0
  197. package/dist/esm/memory/embedding/embedMessages.d.ts +58 -0
  198. package/dist/esm/memory/embedding/index.d.ts +8 -0
  199. package/dist/esm/memory/embedding/loadRelevant.d.ts +51 -0
  200. package/dist/esm/memory/embedding/mockEmbedder.d.ts +22 -0
  201. package/dist/esm/memory/embedding/types.d.ts +46 -0
  202. package/dist/esm/memory/entry/decay.d.ts +36 -0
  203. package/dist/esm/memory/entry/index.d.ts +2 -0
  204. package/dist/esm/memory/entry/types.d.ts +140 -0
  205. package/dist/esm/memory/facts/extractFacts.d.ts +50 -0
  206. package/dist/esm/memory/facts/extractor.d.ts +33 -0
  207. package/dist/esm/memory/facts/formatFacts.d.ts +60 -0
  208. package/dist/esm/memory/facts/index.d.ts +14 -0
  209. package/dist/esm/memory/facts/llmFactExtractor.d.ts +64 -0
  210. package/dist/esm/memory/facts/loadFacts.d.ts +43 -0
  211. package/dist/esm/memory/facts/patternFactExtractor.d.ts +2 -0
  212. package/dist/esm/memory/facts/types.d.ts +68 -0
  213. package/dist/esm/memory/facts/writeFacts.d.ts +19 -0
  214. package/dist/esm/memory/identity/index.d.ts +2 -0
  215. package/dist/esm/memory/identity/types.d.ts +49 -0
  216. package/dist/esm/memory/index.d.ts +19 -0
  217. package/dist/esm/memory/pipeline/auto.d.ts +59 -0
  218. package/dist/esm/memory/pipeline/default.d.ts +49 -0
  219. package/dist/esm/memory/pipeline/ephemeral.d.ts +28 -0
  220. package/dist/esm/memory/pipeline/fact.d.ts +26 -0
  221. package/dist/esm/memory/pipeline/index.d.ts +13 -0
  222. package/dist/esm/memory/pipeline/narrative.d.ts +35 -0
  223. package/dist/esm/memory/pipeline/semantic.d.ts +37 -0
  224. package/dist/esm/memory/pipeline/types.d.ts +31 -0
  225. package/dist/esm/memory/stages/formatDefault.d.ts +64 -0
  226. package/dist/esm/memory/stages/index.d.ts +13 -0
  227. package/dist/esm/memory/stages/loadRecent.d.ts +49 -0
  228. package/dist/esm/memory/stages/pickByBudget.d.ts +63 -0
  229. package/dist/esm/memory/stages/summarize.d.ts +87 -0
  230. package/dist/esm/memory/stages/tokenize.d.ts +43 -0
  231. package/dist/esm/memory/stages/types.d.ts +75 -0
  232. package/dist/esm/memory/stages/writeMessages.d.ts +71 -0
  233. package/dist/esm/memory/store/InMemoryStore.d.ts +62 -0
  234. package/dist/esm/memory/store/index.d.ts +2 -0
  235. package/dist/esm/memory/store/types.d.ts +223 -0
  236. package/dist/esm/memory/wire/index.d.ts +2 -0
  237. package/dist/esm/memory/wire/mountMemoryPipeline.d.ts +108 -0
  238. package/dist/esm/memory-providers.d.ts +37 -0
  239. package/dist/esm/observability/contextError/finders/compareFinders.d.ts +19 -0
  240. package/dist/esm/observability/contextError/finders/index.d.ts +22 -0
  241. package/dist/esm/observability/contextError/finders/rankSuspects.d.ts +2 -0
  242. package/dist/esm/observability/contextError/finders/removeAndRetry.d.ts +11 -0
  243. package/dist/esm/observability/contextError/finders/shrinkToCause.d.ts +11 -0
  244. package/dist/esm/observability/contextError/finders/testManyCombos.d.ts +11 -0
  245. package/dist/esm/observability/contextError/finders/traceSteps.d.ts +2 -0
  246. package/dist/esm/observability/contextError/finders/types.d.ts +88 -0
  247. package/dist/esm/observability-providers.d.ts +46 -0
  248. package/dist/esm/observe.d.ts +62 -0
  249. package/dist/esm/observe.js +7 -1
  250. package/dist/esm/observe.js.map +1 -1
  251. package/dist/esm/patterns/Debate.d.ts +39 -0
  252. package/dist/esm/patterns/MapReduce.d.ts +66 -0
  253. package/dist/esm/patterns/Reflection.d.ts +51 -0
  254. package/dist/esm/patterns/SelfConsistency.d.ts +43 -0
  255. package/dist/esm/patterns/Swarm.d.ts +60 -0
  256. package/dist/esm/patterns/ToT.d.ts +53 -0
  257. package/dist/esm/patterns/index.d.ts +22 -0
  258. package/dist/esm/providers.d.ts +33 -0
  259. package/dist/esm/recorders/core/AgentRecorder.d.ts +15 -0
  260. package/dist/esm/recorders/core/CompositionRecorder.d.ts +17 -0
  261. package/dist/esm/recorders/core/ContextEvaluatedRecorder.d.ts +23 -0
  262. package/dist/esm/recorders/core/ContextRecorder.d.ts +47 -0
  263. package/dist/esm/recorders/core/CostRecorder.d.ts +14 -0
  264. package/dist/esm/recorders/core/EmitBridge.d.ts +30 -0
  265. package/dist/esm/recorders/core/ErrorBridge.d.ts +38 -0
  266. package/dist/esm/recorders/core/EvalRecorder.d.ts +16 -0
  267. package/dist/esm/recorders/core/MemoryRecorder.d.ts +17 -0
  268. package/dist/esm/recorders/core/PermissionRecorder.d.ts +16 -0
  269. package/dist/esm/recorders/core/ReliabilityRecorder.d.ts +24 -0
  270. package/dist/esm/recorders/core/SkillRecorder.d.ts +14 -0
  271. package/dist/esm/recorders/core/StreamRecorder.d.ts +15 -0
  272. package/dist/esm/recorders/core/ToolsRecorder.d.ts +18 -0
  273. package/dist/esm/recorders/core/ValidationRecorder.d.ts +16 -0
  274. package/dist/esm/recorders/core/contextEngineering.d.ts +136 -0
  275. package/dist/esm/recorders/core/typedEmit.d.ts +34 -0
  276. package/dist/esm/recorders/core/types.d.ts +97 -0
  277. package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.d.ts +117 -0
  278. package/dist/esm/recorders/observability/BoundaryRecorder.d.ts +546 -0
  279. package/dist/esm/recorders/observability/FlowchartRecorder.d.ts +220 -0
  280. package/dist/esm/recorders/observability/FlowchartRecorder.js +10 -2
  281. package/dist/esm/recorders/observability/FlowchartRecorder.js.map +1 -1
  282. package/dist/esm/recorders/observability/LiveStateRecorder.d.ts +250 -0
  283. package/dist/esm/recorders/observability/LoggingRecorder.d.ts +91 -0
  284. package/dist/esm/recorders/observability/RouteRecorder.d.ts +83 -0
  285. package/dist/esm/recorders/observability/RunStepRecorder.d.ts +231 -0
  286. package/dist/esm/recorders/observability/StatusRecorder.d.ts +36 -0
  287. package/dist/esm/recorders/observability/ToolChoiceRecorder.d.ts +164 -0
  288. package/dist/esm/recorders/observability/ToolLineageRecorder.d.ts +71 -0
  289. package/dist/esm/recorders/observability/commentary/commentaryTemplates.d.ts +105 -0
  290. package/dist/esm/recorders/observability/internal/ActorArrowClassifier.d.ts +25 -0
  291. package/dist/esm/recorders/observability/internal/CandidateAnswerBuffer.d.ts +28 -0
  292. package/dist/esm/recorders/observability/internal/ForkTracker.d.ts +60 -0
  293. package/dist/esm/recorders/observability/internal/RootInferrer.d.ts +51 -0
  294. package/dist/esm/recorders/observability/internal/SequenceSiblingTracker.d.ts +24 -0
  295. package/dist/esm/recorders/observability/localObservability.d.ts +48 -0
  296. package/dist/esm/recorders/observability/localObservability.js +54 -0
  297. package/dist/esm/recorders/observability/localObservability.js.map +1 -0
  298. package/dist/esm/recorders/observability/observeRunId.d.ts +36 -0
  299. package/dist/esm/recorders/observability/status/statusTemplates.d.ts +106 -0
  300. package/dist/esm/recorders/observability/trace.d.ts +119 -0
  301. package/dist/esm/recorders/observability/trace.js +99 -0
  302. package/dist/esm/recorders/observability/trace.js.map +1 -0
  303. package/dist/esm/reliability/CircuitBreaker.d.ts +75 -0
  304. package/dist/esm/reliability/buildReliabilityGateChart.d.ts +53 -0
  305. package/dist/esm/reliability/classifyError.d.ts +28 -0
  306. package/dist/esm/reliability/index.d.ts +35 -0
  307. package/dist/esm/reliability/types.d.ts +327 -0
  308. package/dist/esm/resilience/fallbackProvider.d.ts +33 -0
  309. package/dist/esm/resilience/index.d.ts +21 -0
  310. package/dist/esm/resilience/withCircuitBreaker.d.ts +129 -0
  311. package/dist/esm/resilience/withFallback.d.ts +45 -0
  312. package/dist/esm/resilience/withRetry.d.ts +71 -0
  313. package/dist/esm/security/PermissionPolicy.d.ts +124 -0
  314. package/dist/esm/security/PolicyHaltError.d.ts +72 -0
  315. package/dist/esm/security/extractSequence.d.ts +46 -0
  316. package/dist/esm/security/index.d.ts +44 -0
  317. package/dist/esm/security/thinkingRedaction.d.ts +50 -0
  318. package/dist/esm/status.d.ts +48 -0
  319. package/dist/esm/strategies/attach.d.ts +47 -0
  320. package/dist/esm/strategies/compose.d.ts +48 -0
  321. package/dist/esm/strategies/defaults/chatBubbleLiveStatus.d.ts +36 -0
  322. package/dist/esm/strategies/defaults/consoleObservability.d.ts +42 -0
  323. package/dist/esm/strategies/defaults/inMemorySinkCost.d.ts +50 -0
  324. package/dist/esm/strategies/defaults/index.d.ts +30 -0
  325. package/dist/esm/strategies/defaults/noopLens.d.ts +28 -0
  326. package/dist/esm/strategies/index.d.ts +36 -0
  327. package/dist/esm/strategies/registry.d.ts +70 -0
  328. package/dist/esm/strategies/types.d.ts +303 -0
  329. package/dist/esm/stream.d.ts +82 -0
  330. package/dist/esm/thinking/AnthropicThinkingHandler.d.ts +42 -0
  331. package/dist/esm/thinking/MockThinkingHandler.d.ts +50 -0
  332. package/dist/esm/thinking/OpenAIThinkingHandler.d.ts +37 -0
  333. package/dist/esm/thinking/index.d.ts +51 -0
  334. package/dist/esm/thinking/registry.d.ts +33 -0
  335. package/dist/esm/thinking/types.d.ts +162 -0
  336. package/dist/esm/tool-providers/gatedTools.d.ts +36 -0
  337. package/dist/esm/tool-providers/index.d.ts +41 -0
  338. package/dist/esm/tool-providers/skillScopedTools.d.ts +45 -0
  339. package/dist/esm/tool-providers/staticTools.d.ts +21 -0
  340. package/dist/esm/tool-providers/types.d.ts +138 -0
  341. package/dist/index.js +6 -2
  342. package/dist/index.js.map +1 -1
  343. package/dist/lib/context-bisect/index.js +3 -0
  344. package/dist/lib/context-bisect/index.js.map +1 -1
  345. package/dist/lib/context-bisect/localize.js +2 -0
  346. package/dist/lib/context-bisect/localize.js.map +1 -1
  347. package/dist/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
  348. package/dist/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
  349. package/dist/lib/injection-engine/entryScorer.js +178 -0
  350. package/dist/lib/injection-engine/entryScorer.js.map +1 -0
  351. package/dist/lib/injection-engine/index.js +5 -1
  352. package/dist/lib/injection-engine/index.js.map +1 -1
  353. package/dist/lib/injection-engine/skillGraph.js +35 -41
  354. package/dist/lib/injection-engine/skillGraph.js.map +1 -1
  355. package/dist/lib/injection-engine/types.js.map +1 -1
  356. package/dist/memory/define.types.js +1 -1
  357. package/dist/observe.js +14 -3
  358. package/dist/observe.js.map +1 -1
  359. package/dist/recorders/observability/FlowchartRecorder.js +12 -3
  360. package/dist/recorders/observability/FlowchartRecorder.js.map +1 -1
  361. package/dist/recorders/observability/localObservability.js +58 -0
  362. package/dist/recorders/observability/localObservability.js.map +1 -0
  363. package/dist/recorders/observability/trace.js +105 -0
  364. package/dist/recorders/observability/trace.js.map +1 -0
  365. package/dist/types/core/RunnerBase.d.ts.map +1 -1
  366. package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
  367. package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
  368. package/dist/types/core/agent/stages/pickEntry.d.ts.map +1 -1
  369. package/dist/types/core/agent/types.d.ts +8 -4
  370. package/dist/types/core/agent/types.d.ts.map +1 -1
  371. package/dist/types/core/runner.d.ts +12 -0
  372. package/dist/types/core/runner.d.ts.map +1 -1
  373. package/dist/types/index.d.ts +1 -1
  374. package/dist/types/index.d.ts.map +1 -1
  375. package/dist/types/lib/context-bisect/index.d.ts +3 -0
  376. package/dist/types/lib/context-bisect/index.d.ts.map +1 -1
  377. package/dist/types/lib/context-bisect/localize.d.ts +2 -0
  378. package/dist/types/lib/context-bisect/localize.d.ts.map +1 -1
  379. package/dist/types/lib/injection-engine/buildInjectionEngineSubflow.d.ts.map +1 -1
  380. package/dist/types/lib/injection-engine/entryScorer.d.ts +94 -0
  381. package/dist/types/lib/injection-engine/entryScorer.d.ts.map +1 -0
  382. package/dist/types/lib/injection-engine/index.d.ts +1 -0
  383. package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
  384. package/dist/types/lib/injection-engine/skillGraph.d.ts +21 -24
  385. package/dist/types/lib/injection-engine/skillGraph.d.ts.map +1 -1
  386. package/dist/types/lib/injection-engine/types.d.ts +9 -4
  387. package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
  388. package/dist/types/memory/define.types.d.ts +1 -1
  389. package/dist/types/observe.d.ts +3 -1
  390. package/dist/types/observe.d.ts.map +1 -1
  391. package/dist/types/recorders/observability/FlowchartRecorder.d.ts +8 -1
  392. package/dist/types/recorders/observability/FlowchartRecorder.d.ts.map +1 -1
  393. package/dist/types/recorders/observability/localObservability.d.ts +49 -0
  394. package/dist/types/recorders/observability/localObservability.d.ts.map +1 -0
  395. package/dist/types/recorders/observability/trace.d.ts +120 -0
  396. package/dist/types/recorders/observability/trace.d.ts.map +1 -0
  397. package/package.json +203 -56
@@ -0,0 +1,23 @@
1
+ /**
2
+ * humanizeLLMError — turn a raw provider/SDK error into a plain-language
3
+ * sentence a NON-developer can act on.
4
+ *
5
+ * agentfootprint targets vibe-coding / non-developer builders. A raw
6
+ * "[browser-anthropic] Failed to fetch" or "401 Unauthorized" means
7
+ * nothing to them. This maps the common failure shapes to a friendly,
8
+ * actionable message. The raw error is preserved on `.cause` (and via
9
+ * `wrapLLMError`) so developers can still dig in.
10
+ *
11
+ * Pure + dependency-light: string/shape matching only. Extend the cases
12
+ * as new provider failure modes surface — keep each message short and
13
+ * tell the user what to DO.
14
+ */
15
+ /** Map a thrown provider/SDK error to a friendly, actionable sentence. */
16
+ export declare function humanizeLLMError(err: unknown): string;
17
+ /**
18
+ * Wrap a raw provider error in a fresh Error whose `.message` is the
19
+ * humanized sentence, preserving the original on `.cause` for developers
20
+ * (and "Copy for LLM"). Re-throw this from the LLM call site so the
21
+ * friendly message flows through onError → onRunFailed → the monitor.
22
+ */
23
+ export declare function wrapLLMError(err: unknown): Error;
@@ -0,0 +1,139 @@
1
+ /**
2
+ * outputFallback — 3-tier degradation for structured-output validation
3
+ * failures.
4
+ *
5
+ * Pairs with `outputSchema(parser)`. When the LLM's final answer
6
+ * fails schema validation (after the agent loop has done what it
7
+ * could), instead of throwing `OutputSchemaError` to the caller,
8
+ * the agent falls through:
9
+ *
10
+ * 1. **Primary** — LLM emitted schema-valid JSON. Caller gets the
11
+ * parsed value.
12
+ * 2. **Fallback** — `OutputSchemaError` thrown by the parser. The
13
+ * consumer-supplied async `fallback(error, raw)` runs; its
14
+ * return value is parsed against the same schema. If valid →
15
+ * caller gets it. If `fallback` itself throws OR its return
16
+ * value fails schema → tier 3.
17
+ * 3. **Canned** — static `canned` value (validated against the
18
+ * schema at builder time so it's guaranteed to satisfy). The
19
+ * agent NEVER throws when `canned` is set.
20
+ *
21
+ * Pattern: chain-of-responsibility (GoF) over typed degradation tiers.
22
+ * Same shape as `withRetry` / `withFallback` for LLM
23
+ * providers, but at the SCHEMA layer instead of the network
24
+ * layer.
25
+ *
26
+ * Role: Layer-6 (Agent) — terminal contract failure handler.
27
+ * Composable with `outputSchema` (which it supplements;
28
+ * one without the other is incoherent).
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { z } from 'zod';
33
+ *
34
+ * const Refund = z.object({
35
+ * amount: z.number().nonnegative(),
36
+ * reason: z.string().min(1),
37
+ * });
38
+ *
39
+ * const agent = Agent.create({...})
40
+ * .system('You decide refund amounts.')
41
+ * .outputSchema(Refund)
42
+ * .outputFallback({
43
+ * // Tier 2: try a more permissive prompt; if it also fails,
44
+ * // escalate to a human.
45
+ * fallback: async (err, raw) => ({
46
+ * amount: 0,
47
+ * reason: `manual review required (LLM output: ${raw.slice(0, 200)})`,
48
+ * }),
49
+ * // Tier 3: guaranteed-valid safety net.
50
+ * canned: { amount: 0, reason: 'unable to process — please retry' },
51
+ * })
52
+ * .build();
53
+ *
54
+ * // Caller never sees OutputSchemaError; gets a typed Refund either way.
55
+ * const refund = await agent.runTyped({ message: '...' });
56
+ * ```
57
+ *
58
+ * Why this matters in production:
59
+ * - LLMs occasionally emit prose despite the system prompt asking
60
+ * for JSON ("Sure! Here's your refund: {...}").
61
+ * - Schema-violating outputs are bursty under model load (vendor
62
+ * A/B tests, model rollouts, content-filter trips).
63
+ * - A B2C agent that THROWS on every malformed output cascades
64
+ * into 5xx for the end user; the FAIL-OPEN pattern degrades
65
+ * gracefully and lets you triage offline.
66
+ *
67
+ * Two typed events fire so observability backends can alert on
68
+ * degradation:
69
+ * - `agentfootprint.resilience.output_fallback_triggered`
70
+ * (tier 2 fired)
71
+ * - `agentfootprint.resilience.output_canned_used`
72
+ * (tier 3 fired — fallback also failed; safety net engaged)
73
+ */
74
+ import type { OutputSchemaError, OutputSchemaParser } from './outputSchema.js';
75
+ /**
76
+ * Tier-2 fallback function. Receives the original validation error +
77
+ * the raw LLM output; returns a value that the agent will then try
78
+ * to validate against the same schema.
79
+ *
80
+ * If this function throws, OR its return value fails schema, the
81
+ * agent falls through to the `canned` value (tier 3).
82
+ */
83
+ export type OutputFallbackFn<T> = (error: OutputSchemaError, rawOutput: string) => Promise<T> | T;
84
+ export interface OutputFallbackOptions<T> {
85
+ /** Tier 2 — async function that produces a candidate value. May
86
+ * throw or return invalid data; the agent will fall through to
87
+ * `canned` if so. */
88
+ readonly fallback: OutputFallbackFn<T>;
89
+ /** Tier 3 — guaranteed-valid safety net. Validated against the
90
+ * schema at builder time (throws on mismatch — fail-fast on
91
+ * misconfig). When set, the agent NEVER throws on output-schema
92
+ * failure.
93
+ *
94
+ * When omitted, `fallback`-thrown errors propagate to the caller
95
+ * (consumer chooses fail-open vs fail-closed). */
96
+ readonly canned?: T;
97
+ }
98
+ /**
99
+ * Internal — the resolved fallback config stored on the Agent.
100
+ * Identical to public `OutputFallbackOptions` but with the parser
101
+ * + canned-validation results pre-computed.
102
+ *
103
+ * @internal
104
+ */
105
+ export interface ResolvedOutputFallback<T> {
106
+ readonly fallback: OutputFallbackFn<T>;
107
+ readonly canned?: T;
108
+ /** True when `canned` was provided. Used by `apply…` to decide
109
+ * whether tier 3 exists at all. */
110
+ readonly hasCanned: boolean;
111
+ }
112
+ /**
113
+ * Validate the consumer-supplied `canned` value against the schema
114
+ * at builder time. Fail-fast on misconfig — a `canned` value that
115
+ * doesn't satisfy the schema would cascade into runtime errors
116
+ * AFTER the agent loop has already failed, which defeats the
117
+ * fail-open guarantee.
118
+ *
119
+ * Throws `TypeError` with a hint if validation fails.
120
+ */
121
+ export declare function validateCannedAgainstSchema<T>(canned: T, parser: OutputSchemaParser<T>): void;
122
+ /**
123
+ * The 3-tier resolver. Called by `agent.parseOutput()` /
124
+ * `agent.runTyped()` when an `outputFallback` is configured. Replaces
125
+ * the bare-throw behavior of `applyOutputSchema()`.
126
+ *
127
+ * Returns the typed value from whichever tier wins. Emits typed
128
+ * events at every tier transition so observability backends can
129
+ * alert on degradation.
130
+ *
131
+ * @param raw — the LLM's original final-answer string
132
+ * @param parser — the outputSchema parser
133
+ * @param fallbackCfg — the resolved fallback configuration
134
+ * @param emit — agentfootprint dispatcher's `dispatch()` entry
135
+ * (typed via the runner; we accept a thin
136
+ * function so this module stays import-free of
137
+ * the dispatcher).
138
+ */
139
+ export declare function applyOutputFallback<T>(raw: string, parser: OutputSchemaParser<T>, fallbackCfg: ResolvedOutputFallback<T>, emit: (eventType: string, payload: Record<string, unknown>) => void, primaryError: OutputSchemaError): Promise<T>;
@@ -0,0 +1,127 @@
1
+ /**
2
+ * outputSchema — declarative terminal contract for an Agent's final answer.
3
+ *
4
+ * The Block A6 piece. Lets a consumer say:
5
+ *
6
+ * "Whatever this agent says at the end of a run, it MUST be JSON
7
+ * matching this Zod (or Zod-like) schema. Auto-instruct the LLM,
8
+ * parse + validate the final answer for me."
9
+ *
10
+ * Why a typed contract matters: agentic code that calls an LLM and
11
+ * then JSON.parses the string answer is brittle. The schema serves
12
+ * three jobs at once:
13
+ *
14
+ * 1. **Instruction**: a system-prompt sentence telling the LLM the
15
+ * output shape (auto-generated from `schema.description` /
16
+ * JSON-schema introspection where available, or from a consumer-
17
+ * supplied `instruction` override).
18
+ *
19
+ * 2. **Validation**: a `parser.parse(rawString)` step on the run's
20
+ * final answer, throwing `OutputSchemaError` on parse / shape
21
+ * failure rather than returning malformed data.
22
+ *
23
+ * 3. **Type narrowing**: `agent.runTyped({...})` returns the inferred
24
+ * shape `T` instead of `string`, so callers stop reaching for
25
+ * `as MyType` casts.
26
+ *
27
+ * Pattern: Strategy (GoF) over the parser interface; structural
28
+ * duck-typing (Zod / Valibot / ArkType / hand-written —
29
+ * anything with a `parse(unknown): T` method satisfies it).
30
+ *
31
+ * Role: Layer-6 (Agent) — terminal contract on the run output.
32
+ * NOT a context-engineering Injection per se, but composes
33
+ * with the InjectionEngine (auto-injects an Instruction).
34
+ *
35
+ * @example zod schema
36
+ * import { z } from 'zod';
37
+ * const Output = z.object({ status: z.enum(['ok', 'err']), items: z.array(z.string()) });
38
+ *
39
+ * const agent = Agent.create({ ... })
40
+ * .system('You answer support tickets.')
41
+ * .outputSchema(Output)
42
+ * .build();
43
+ *
44
+ * const typed = await agent.runTyped({ message: 'list pending tickets' });
45
+ * typed.status; // narrowed to 'ok' | 'err'
46
+ *
47
+ * @example valibot / arktype / hand-written parser
48
+ * const Output = { parse(v: unknown): MyType { ... } };
49
+ * const agent = Agent.create({...}).outputSchema(Output, { instruction: '...' }).build();
50
+ */
51
+ /**
52
+ * Minimum shape any validation library must expose to satisfy
53
+ * `outputSchema`. Covers Zod (`schema.parse`), Valibot
54
+ * (`v.parse(schema, value)` — pass `{ parse: v => v.parse(schema, v) }`),
55
+ * ArkType (`type.assert`), and hand-written parsers.
56
+ *
57
+ * Implementations MUST throw on validation failure (the runtime
58
+ * catches the throw, wraps it in `OutputSchemaError`, and emits the
59
+ * diagnostic event).
60
+ */
61
+ export interface OutputSchemaParser<T> {
62
+ parse(value: unknown): T;
63
+ /**
64
+ * Human-readable description of the output shape. Used by
65
+ * `outputSchema` to auto-build the system-prompt instruction when
66
+ * `opts.instruction` is not provided. Zod schemas expose this via
67
+ * `.describe('...')`; consumers can attach the field directly on
68
+ * hand-written parsers.
69
+ */
70
+ readonly description?: string;
71
+ }
72
+ /**
73
+ * Optional configuration for `outputSchema`.
74
+ */
75
+ export interface OutputSchemaOptions {
76
+ /**
77
+ * Injection id for the auto-generated "respond with this shape"
78
+ * instruction. Defaults to `'output-schema'`. Override when you
79
+ * have multiple agents with different schemas in one process and
80
+ * want the diagnostic events to disambiguate.
81
+ */
82
+ readonly name?: string;
83
+ /**
84
+ * Custom system-prompt instruction text. Defaults to a generic
85
+ * "Respond with valid JSON matching the output schema. Do not
86
+ * include prose." sentence (extended with `parser.description`
87
+ * when present). Override when the LLM benefits from a
88
+ * domain-specific framing.
89
+ */
90
+ readonly instruction?: string;
91
+ }
92
+ /**
93
+ * Thrown by `agent.parseOutput(...)` / `agent.runTyped(...)` when the
94
+ * agent's final answer fails JSON parsing OR schema validation.
95
+ *
96
+ * `cause` carries the underlying parse error (Zod's ZodError, etc.).
97
+ * `rawOutput` carries the agent's untyped string output so callers
98
+ * can log / persist the failed response for triage.
99
+ */
100
+ export declare class OutputSchemaError extends Error {
101
+ readonly rawOutput: string;
102
+ readonly stage: 'json-parse' | 'schema-validate';
103
+ readonly cause?: unknown;
104
+ constructor(message: string, opts: {
105
+ rawOutput: string;
106
+ stage: 'json-parse' | 'schema-validate';
107
+ cause?: unknown;
108
+ });
109
+ }
110
+ /**
111
+ * Default instruction template — used when `opts.instruction` is not
112
+ * provided. Concatenates the parser's `.description` (if present) so
113
+ * Zod schemas authored with `.describe('...')` propagate naturally.
114
+ */
115
+ export declare function buildDefaultInstruction(parser: OutputSchemaParser<unknown>): string;
116
+ /**
117
+ * Parse + validate a raw string answer against a parser. Used by
118
+ * `agent.parseOutput()` / `agent.runTyped()`. Centralized here so
119
+ * both call sites share identical error-mapping behavior.
120
+ *
121
+ * Two-stage error reporting:
122
+ * - JSON parse failure → `stage: 'json-parse'` (LLM emitted prose
123
+ * or malformed JSON)
124
+ * - Schema validation failure → `stage: 'schema-validate'` (JSON
125
+ * was valid but didn't match the contracted shape)
126
+ */
127
+ export declare function applyOutputSchema<T>(raw: string, parser: OutputSchemaParser<T>): T;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * pause — runner-level pause/resume primitives.
3
+ *
4
+ * Pattern: Control-flow exception (PauseRequest) + typed outcome (RunnerPauseOutcome).
5
+ * Role: core/ layer. Bridges footprintjs.s pause signal into the agentfootprint
6
+ * Runner contract: tools call `pauseHere(data)` to raise a pause
7
+ * intent; runners detect the paused executor result and return a
8
+ * `RunnerPauseOutcome` instead of `TOut`. Consumers call
9
+ * `runner.resume(checkpoint, input)` to continue.
10
+ * Emits: N/A (types + helpers only). Event emission happens in RunnerBase.
11
+ *
12
+ * Why a control-flow "throw": tool.execute(args, ctx) doesn't receive the
13
+ * typed scope, so it cannot call `scope.$pause()` directly. A thrown
14
+ * `PauseRequest` is caught inside the Agent's tool-call stage, which then
15
+ * forwards the pause into the flowchart via `scope.$pause()`. This keeps
16
+ * the tool API clean (tools are pure-ish) while still supporting pause.
17
+ */
18
+ import type { FlowchartCheckpoint } from 'footprintjs';
19
+ /**
20
+ * Outcome returned by `runner.run()` / `runner.resume()` when execution
21
+ * has paused mid-flow. The shape mirrors footprintjs's `PausedResult` but
22
+ * surfaces `pauseData` as a first-class field for consumers who don't
23
+ * want to reach into the checkpoint.
24
+ */
25
+ export interface RunnerPauseOutcome {
26
+ readonly paused: true;
27
+ /** Serializable checkpoint — store anywhere (Redis, Postgres, localStorage). */
28
+ readonly checkpoint: FlowchartCheckpoint;
29
+ /** Data passed to `scope.$pause()` / `pauseHere()`. Consumer-typed. */
30
+ readonly pauseData: unknown;
31
+ }
32
+ /** Type guard — discriminates `RunnerPauseOutcome` from a normal `TOut`. */
33
+ export declare function isPaused<T>(result: T | RunnerPauseOutcome): result is RunnerPauseOutcome;
34
+ /**
35
+ * Control-flow error raised by `pauseHere()` inside a tool's `execute()`.
36
+ * Caught by the Agent's tool-call stage, which forwards to `scope.$pause()`.
37
+ * Never propagates to the consumer.
38
+ */
39
+ export declare class PauseRequest extends Error {
40
+ readonly data: unknown;
41
+ constructor(data: unknown);
42
+ }
43
+ /**
44
+ * Called from inside a tool's `execute()` to request a pause. Throws a
45
+ * `PauseRequest` that the Agent catches and forwards to the flowchart.
46
+ *
47
+ * @example
48
+ * const approveTool: Tool<{ action: string }, string> = {
49
+ * schema: { name: 'approve', description: 'Ask human', inputSchema: {...} },
50
+ * execute: async (args) => {
51
+ * pauseHere({ question: `Approve ${args.action}?`, risk: 'high' });
52
+ * return ''; // unreachable — pauseHere always throws
53
+ * },
54
+ * };
55
+ */
56
+ export declare function pauseHere(data: unknown): never;
57
+ /** Type guard for a thrown `PauseRequest`. */
58
+ export declare function isPauseRequest(err: unknown): err is PauseRequest;
59
+ /**
60
+ * Ergonomic alias for `pauseHere(data)` — the human-in-the-loop name.
61
+ *
62
+ * `pauseHere` describes the mechanism (control-flow throw); `askHuman`
63
+ * describes the intent (ask a person to decide). Both work identically.
64
+ *
65
+ * @example
66
+ * const approveRefund: Tool<{ amount: number }, string> = {
67
+ * schema: { name: 'approve_refund', description: '...', inputSchema: {...} },
68
+ * execute: async ({ amount }) => {
69
+ * if (amount > 1000) askHuman({ question: `Approve $${amount}?` });
70
+ * return 'auto-approved';
71
+ * },
72
+ * };
73
+ */
74
+ export declare const askHuman: typeof pauseHere;
@@ -0,0 +1,179 @@
1
+ /**
2
+ * runCheckpoint — fault-tolerant resume primitives.
3
+ *
4
+ * Today's pause/resume only handles INTENTIONAL pauses (`askHuman`).
5
+ * Errors mid-run (LLM 500s, vendor outages, tool throws, container
6
+ * restarts) propagate all the way up and the consumer must restart
7
+ * from scratch — losing the prior iterations' work.
8
+ *
9
+ * This module adds the third piece of the Reliability subsystem:
10
+ *
11
+ * 1. **`AgentRunCheckpoint`** — JSON-serializable snapshot of an
12
+ * agent run's progress. Captured automatically at each
13
+ * iteration boundary (the natural commit points). Survives
14
+ * process restart — persist to Redis / Postgres / S3 / queue.
15
+ *
16
+ * 2. **`RunCheckpointError`** — wraps the underlying error with
17
+ * the last-known-good checkpoint. Throwing this instead of the
18
+ * raw error lets consumers catch + persist + resume later
19
+ * without losing context.
20
+ *
21
+ * 3. **`agent.resumeOnError(checkpoint)`** — replays the agent run
22
+ * with the checkpointed conversation history restored. The
23
+ * next iteration retries the call that originally failed (with
24
+ * the latest provider state — circuit breaker may have closed,
25
+ * vendor may have recovered, etc.).
26
+ *
27
+ * Design tradeoff: we use a CONVERSATION-HISTORY checkpoint shape
28
+ * rather than a full executor-state checkpoint (which would require
29
+ * footprintjs API surface changes for mid-run snapshotting). The
30
+ * tradeoff:
31
+ *
32
+ * ✅ Survives process restart (JSON-serializable, tiny payload)
33
+ * ✅ Works with any LLM provider — replay starts from history
34
+ * ✅ No footprintjs core changes
35
+ * ⚠️ Loses mid-iteration partial state (acceptable — iterations
36
+ * are atomic; we resume from the last completed boundary)
37
+ * ⚠️ TOOL RE-EXECUTION (idempotency requirement): anything the
38
+ * failed iteration did after the last completed boundary —
39
+ * including tool side effects — is NOT in the checkpoint. On
40
+ * resume the model re-decides from the restored history and may
41
+ * re-issue those tool calls; they WILL execute again. There is
42
+ * NO built-in toolCallId-based dedup. Mutating tools (payments,
43
+ * emails, DB writes) must be idempotent — derive an idempotency
44
+ * key from stable call content, not from `ctx.toolCallId` (fresh
45
+ * per issued call, so a re-issued call gets a NEW id). Note the
46
+ * same requirement exists WITHOUT resume: a tool that performs
47
+ * its side effect and then throws reports the error message back
48
+ * to the model as the tool result, and the model typically
49
+ * retries the call on the next iteration.
50
+ *
51
+ * Pattern: Memento (GoF) — snapshot of an object's internal state
52
+ * for later restoration. Same shape as `FlowchartCheckpoint`
53
+ * but at the agent layer (one logical iteration vs. one
54
+ * DFS stage).
55
+ */
56
+ import type { LLMMessage } from '../adapters/types.js';
57
+ /**
58
+ * JSON-serializable checkpoint of an in-progress agent run. Persist
59
+ * to ANY durable store (Redis / Postgres / S3 / disk / queue) and
60
+ * resume hours / days / deploys later via `agent.resumeOnError(...)`.
61
+ *
62
+ * **Stable shape** — the `version` field guards forward compat. v1
63
+ * → v2 transitions will be supported via a migration helper.
64
+ */
65
+ export interface AgentRunCheckpoint {
66
+ /** Schema version. v1 = conversation-history-based. */
67
+ readonly version: 1;
68
+ /** `runId` of the FAILING run — lets the consumer correlate a
69
+ * persisted checkpoint back to the original run's observability.
70
+ * NOT reused on resume: `resumeOnError` starts a fresh run with a
71
+ * fresh `runId` (only the conversation history is restored). */
72
+ readonly runId: string;
73
+ /** Conversation history at the LAST completed iteration boundary
74
+ * (LLM messages). The next iteration retries from here. */
75
+ readonly history: readonly LLMMessage[];
76
+ /** Index of the last completed iteration in the FAILING run
77
+ * (diagnostic — not consumed on resume). The resumed run restores
78
+ * this history but re-seeds its own iteration counter at 1 with a
79
+ * full `maxIterations` budget. */
80
+ readonly lastCompletedIteration: number;
81
+ /** Original input message. Surfaces in observability + lets the
82
+ * consumer correlate checkpoint to the user's request. */
83
+ readonly originalInput: {
84
+ readonly message: string;
85
+ };
86
+ /** Wall-clock when the checkpoint was captured. Diagnostic only. */
87
+ readonly checkpointedAt: number;
88
+ /** Where the failure happened. Diagnostic — surfaces in oncall
89
+ * triage so you can tell "LLM 500 mid-iteration" from "tool
90
+ * threw" from "validation kept failing". */
91
+ readonly failurePoint?: {
92
+ readonly iteration: number;
93
+ readonly phase: 'iteration' | 'tool' | 'llm' | 'unknown';
94
+ };
95
+ }
96
+ /**
97
+ * Thrown by `agent.run()` when a fault occurs mid-run. Carries the
98
+ * underlying error AND the last-known-good checkpoint. Catch this
99
+ * specifically to engage the resume-on-error path; let other errors
100
+ * propagate normally.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * import { Agent, RunCheckpointError } from 'agentfootprint';
105
+ *
106
+ * try {
107
+ * const result = await agent.run({ message: 'long task' });
108
+ * } catch (err) {
109
+ * if (err instanceof RunCheckpointError) {
110
+ * await checkpointStore.put(sessionId, err.checkpoint);
111
+ * // hours / restart later:
112
+ * const checkpoint = await checkpointStore.get(sessionId);
113
+ * const result = await agent.resumeOnError(checkpoint);
114
+ * } else {
115
+ * throw err; // not a recoverable error — propagate
116
+ * }
117
+ * }
118
+ * ```
119
+ */
120
+ export declare class RunCheckpointError extends Error {
121
+ readonly code: "ERR_RUN_CHECKPOINT";
122
+ /** The error that triggered the checkpoint. Inspect for retry
123
+ * decisions ("if cause is CircuitOpenError, wait for cooldown
124
+ * before resuming"). */
125
+ readonly cause: Error;
126
+ /** The last-known-good checkpoint. Persist + pass back to
127
+ * `agent.resumeOnError(checkpoint)` to continue from here. */
128
+ readonly checkpoint: AgentRunCheckpoint;
129
+ constructor(cause: Error, checkpoint: AgentRunCheckpoint);
130
+ }
131
+ /**
132
+ * Mutable state the Agent maintains during a run for checkpoint
133
+ * capture. Keyed by `runId` so multiple in-flight runs don't
134
+ * collide. Cleared on `turn_end` (success path).
135
+ *
136
+ * @internal
137
+ */
138
+ export interface RunCheckpointTracker {
139
+ readonly runId: string;
140
+ readonly originalInput: {
141
+ readonly message: string;
142
+ };
143
+ /** Updated on every `agentfootprint.agent.iteration_end`. */
144
+ history: readonly LLMMessage[];
145
+ /** Updated on every `agentfootprint.agent.iteration_end`. */
146
+ lastCompletedIteration: number;
147
+ /** Set when an iteration begins (used to attribute the failure
148
+ * phase if we throw before the next iteration_end). */
149
+ inFlightIteration?: number;
150
+ }
151
+ /**
152
+ * Build a JSON-serializable checkpoint from a tracker + failure
153
+ * info. Pure function — no side effects.
154
+ *
155
+ * @internal
156
+ */
157
+ export declare function buildCheckpoint(tracker: RunCheckpointTracker, failurePoint?: {
158
+ iteration: number;
159
+ phase: AgentRunCheckpoint['failurePoint'] extends infer F ? F extends {
160
+ phase: infer P;
161
+ } ? P : never : never;
162
+ }): AgentRunCheckpoint;
163
+ /**
164
+ * Validate a checkpoint at deserialization time. Catches forward-
165
+ * incompatible payloads (someone tries to resume a v3 checkpoint on
166
+ * a v1 runtime, or a corrupted JSON blob).
167
+ *
168
+ * Returns the checkpoint typed-narrowed; throws TypeError on
169
+ * unknown shape.
170
+ */
171
+ export declare function validateCheckpoint(value: unknown): AgentRunCheckpoint;
172
+ /**
173
+ * Classify a thrown error into one of the failure-point phase
174
+ * buckets. Heuristic — uses error name / code / message inspection.
175
+ * Fast path returns 'unknown' so unrecognized errors still produce
176
+ * a checkpoint (the cause itself is preserved in
177
+ * `RunCheckpointError.cause`).
178
+ */
179
+ export declare function classifyFailurePhase(err: Error): 'iteration' | 'tool' | 'llm' | 'unknown';