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,37 @@
1
+ /**
2
+ * applyCachePolicy — internal helper for injection factories.
3
+ *
4
+ * Each factory (`defineSkill`, `defineSteering`, `defineFact`,
5
+ * `defineInstruction`, `defineMemory`) calls this to merge the
6
+ * consumer-supplied `cache` option with the flavor-specific default.
7
+ * The merged policy lands in `Injection.metadata.cache` for the
8
+ * CacheDecision subflow (Phase 4) to read back.
9
+ *
10
+ * Why it lives in src/cache/ (not co-located with each factory):
11
+ * - Single source of truth for per-flavor defaults
12
+ * - Tests for the defaults live in one place (test/cache/)
13
+ * - Adding a new factory means adding one entry to the map below;
14
+ * not duplicating the default-resolution logic five times
15
+ */
16
+ import type { CachePolicy } from './types.js';
17
+ /**
18
+ * Per-flavor default `cache` values when consumer doesn't specify.
19
+ * These match the documentation in `CachePolicy`'s JSDoc — keep
20
+ * synchronized.
21
+ */
22
+ declare const FLAVOR_DEFAULTS: Readonly<Record<string, CachePolicy>>;
23
+ /**
24
+ * Resolve the effective `cache` policy for an injection.
25
+ *
26
+ * @param flavor - The injection flavor (drives the default if `consumerValue` undefined)
27
+ * @param consumerValue - What the consumer wrote in `cache:` (or undefined)
28
+ * @returns The effective CachePolicy. Always defined.
29
+ */
30
+ export declare function resolveCachePolicy(flavor: keyof typeof FLAVOR_DEFAULTS | string, consumerValue: CachePolicy | undefined): CachePolicy;
31
+ /**
32
+ * Read-only access to the per-flavor default table. Exported for
33
+ * tests asserting the documented defaults are wired correctly. Not
34
+ * intended for runtime use — callers should use `resolveCachePolicy`.
35
+ */
36
+ export declare function getFlavorDefault(flavor: string): CachePolicy;
37
+ export {};
@@ -0,0 +1,85 @@
1
+ /**
2
+ * cacheRecorder() — observability for the v2.6 cache layer.
3
+ *
4
+ * Subscribes to:
5
+ * - `FlowRecorder.onDecision` — captures CacheGate routing decisions
6
+ * (apply-markers / no-markers + the rule that fired + evidence
7
+ * from `decide()`). Read directly from `event.evidence.rules[matched]`
8
+ * since footprintjs already auto-captures predicate `inputs[]`.
9
+ * - `agentfootprint.stream.llm_end` events — read provider's `usage`
10
+ * and call the agent's CacheStrategy.extractMetrics() to normalize
11
+ * into CacheMetrics (cacheReadTokens / cacheWriteTokens / fresh).
12
+ *
13
+ * Produces:
14
+ * - per-iteration `agentfootprint.cache.applied` events (markers
15
+ * applied this iter or empty if skipped) — for Lens trace
16
+ * - per-iteration `agentfootprint.cache.metrics` events (hit/write
17
+ * token counts + estimated dollars via PricingTable) — for
18
+ * dashboards
19
+ * - a turn-end summary printable via `recorder.report()` —
20
+ * numeric tally plus dollars saved
21
+ *
22
+ * v2.6 LIMITATION: doesn't yet write `scope.recentHitRate` back into
23
+ * agent state. CacheGate's hit-rate-floor rule won't fire automatically;
24
+ * consumers can manually wire feedback via `Agent.create(...).attach(rec)`.
25
+ * Full feedback loop deferred to v2.7 (needs an agent-side accessor
26
+ * convention since recorders don't normally write to scope).
27
+ */
28
+ import type { CombinedRecorder } from 'footprintjs';
29
+ import type { CacheMetrics, CacheStrategy } from './types.js';
30
+ import type { PricingTable } from '../adapters/types.js';
31
+ interface PerIterEntry {
32
+ readonly iteration: number;
33
+ readonly branch: 'apply-markers' | 'no-markers';
34
+ readonly rule?: string;
35
+ readonly metrics?: CacheMetrics;
36
+ readonly dollarsSpent: number;
37
+ readonly dollarsSavedVsNoCache: number;
38
+ }
39
+ interface CacheReportSummary {
40
+ readonly totalIterations: number;
41
+ readonly applyMarkersIterations: number;
42
+ readonly noMarkersIterations: number;
43
+ readonly cacheReadTokensTotal: number;
44
+ readonly cacheWriteTokensTotal: number;
45
+ readonly freshInputTokensTotal: number;
46
+ readonly hitRate: number;
47
+ readonly estimatedDollarsSpent: number;
48
+ readonly estimatedDollarsSavedVsNoCache: number;
49
+ readonly perIter: readonly PerIterEntry[];
50
+ }
51
+ export interface CacheRecorderOptions {
52
+ /**
53
+ * The agent's CacheStrategy. Required for `extractMetrics` —
54
+ * normalizes provider-specific `usage` shapes into CacheMetrics.
55
+ * If not provided, recorder logs the raw usage and skips dollar math.
56
+ */
57
+ readonly strategy?: CacheStrategy;
58
+ /**
59
+ * PricingTable for dollar estimates. Falls back to token-count-only
60
+ * reporting when omitted. Looks up `'input'` / `'cacheRead'` /
61
+ * `'cacheWrite'` token kinds (PricingTable already supports these
62
+ * as of v2.5).
63
+ */
64
+ readonly pricing?: PricingTable;
65
+ /**
66
+ * Model id for pricing lookup. Defaults to a placeholder; set to
67
+ * the actual model the agent is using for accurate dollar math.
68
+ */
69
+ readonly model?: string;
70
+ }
71
+ export interface CacheRecorderHandle extends CombinedRecorder {
72
+ /**
73
+ * Build a per-turn report. Call after `agent.run()` completes.
74
+ * Returns a frozen snapshot — recorder keeps accumulating but the
75
+ * report you held is stable.
76
+ */
77
+ report(): CacheReportSummary;
78
+ /**
79
+ * Reset accumulated state. Call between turns if you want
80
+ * per-turn rather than per-session reporting.
81
+ */
82
+ reset(): void;
83
+ }
84
+ export declare function cacheRecorder(options?: CacheRecorderOptions): CacheRecorderHandle;
85
+ export {};
@@ -0,0 +1,33 @@
1
+ /**
2
+ * agentfootprint/cache — public surface for the cache layer (v2.6+).
3
+ *
4
+ * Importing this module side-effect-registers every built-in cache
5
+ * strategy in the registry. The agentfootprint main barrel imports
6
+ * from here so consumers get the registered strategies without
7
+ * needing to know they exist.
8
+ *
9
+ * Strategies registered as of v2.6:
10
+ * - NoOp (wildcard '*' fallback) — always available, registered by
11
+ * the registry module itself
12
+ * - AnthropicCacheStrategy ('anthropic', 'browser-anthropic')
13
+ *
14
+ * Future strategies (Phase 8+):
15
+ * - OpenAICacheStrategy
16
+ * - BedrockCacheStrategy
17
+ * - GeminiCacheStrategy (v2.7+, async handle-based)
18
+ *
19
+ * Public types (re-exported for consumers):
20
+ * - CachePolicy, CacheMarker, CacheStrategy, CacheCapabilities,
21
+ * CacheMetrics, CachePolicyContext, CacheStrategyContext
22
+ */
23
+ import './strategies/AnthropicCacheStrategy.js';
24
+ import './strategies/OpenAICacheStrategy.js';
25
+ import './strategies/BedrockCacheStrategy.js';
26
+ export type { CachePolicy, CachePolicyContext, CacheMarker, CacheStrategy, CacheStrategyContext, CacheCapabilities, CacheMetrics, } from './types.js';
27
+ export { getDefaultCacheStrategy, registerCacheStrategy, listRegisteredStrategies, } from './strategyRegistry.js';
28
+ export { NoOpCacheStrategy } from './strategies/NoOpCacheStrategy.js';
29
+ export { AnthropicCacheStrategy } from './strategies/AnthropicCacheStrategy.js';
30
+ export { OpenAICacheStrategy } from './strategies/OpenAICacheStrategy.js';
31
+ export { BedrockCacheStrategy } from './strategies/BedrockCacheStrategy.js';
32
+ export { cacheRecorder } from './cacheRecorder.js';
33
+ export type { CacheRecorderOptions, CacheRecorderHandle } from './cacheRecorder.js';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * AnthropicCacheStrategy — translates agnostic CacheMarker[] to
3
+ * Anthropic API's `cache_control: { type: 'ephemeral' }` markers.
4
+ *
5
+ * Anthropic-specific behaviors honored:
6
+ * - **4-marker limit**: Anthropic allows ≤4 cache breakpoints per
7
+ * request. Strategy clamps oversize candidate sets, keeping the
8
+ * first 4 in slot order.
9
+ * - **TTL mapping**: 'short' → default 5min ephemeral; 'long' →
10
+ * `ttl: '1h'` (1-hour beta).
11
+ * - **Provider-side hashing**: this strategy doesn't hash — Anthropic
12
+ * keys cache by exact byte prefix server-side. We don't need
13
+ * content hashes for the v2.6 surface; reserved for v2.7+ if a
14
+ * pre-flight cache-warm-check API ships.
15
+ *
16
+ * What this strategy DOES vs DOESN'T do:
17
+ * - DOES: clamp markers, attach to LLMRequest.cacheMarkers,
18
+ * extract metrics from response.usage
19
+ * - DOES NOT: rewrite the wire body. The provider
20
+ * (BrowserAnthropicProvider) reads `cacheMarkers` and applies
21
+ * `cache_control` blocks during body construction. Separation of
22
+ * concerns: strategy decides WHAT to cache; provider knows HOW
23
+ * to encode on its specific wire.
24
+ *
25
+ * Auto-registers in the strategy registry on module import for
26
+ * provider names: 'anthropic', 'browser-anthropic'.
27
+ */
28
+ import type { CacheCapabilities, CacheMarker, CacheMetrics, CacheStrategy, CacheStrategyContext } from '../types.js';
29
+ import type { LLMRequest } from '../../adapters/types.js';
30
+ export declare class AnthropicCacheStrategy implements CacheStrategy {
31
+ readonly providerName = "anthropic";
32
+ readonly capabilities: CacheCapabilities;
33
+ prepareRequest(req: LLMRequest, candidates: readonly CacheMarker[], ctx: CacheStrategyContext): Promise<{
34
+ readonly request: LLMRequest;
35
+ readonly markersApplied: readonly CacheMarker[];
36
+ }>;
37
+ extractMetrics(usage: unknown): CacheMetrics | undefined;
38
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * BedrockCacheStrategy — model-aware strategy for AWS Bedrock.
3
+ *
4
+ * Bedrock hosts multiple model families. Cache support varies:
5
+ * - Claude on Bedrock → identical mechanics to direct Anthropic
6
+ * (`cache_control: { type: 'ephemeral' }` markers, 4-marker
7
+ * limit). Strategy delegates to Anthropic-shaped behavior.
8
+ * - Llama / Mistral / Cohere on Bedrock → no cache support today
9
+ * (as of 2026-04-30). Strategy passes through, returns no metrics.
10
+ *
11
+ * Auto-detection: inspects `req.model` to decide. Claude model IDs
12
+ * start with `'anthropic.claude'` on Bedrock (e.g.,
13
+ * `anthropic.claude-3-5-sonnet-20240620-v1:0`).
14
+ *
15
+ * Auto-registers under provider name `'bedrock'`.
16
+ *
17
+ * Per the Phase 1 review (Reviewer 6 — Provider SDK expert): for
18
+ * non-Claude Bedrock models the strategy reports `enabled: false` in
19
+ * its capabilities so the CacheDecision subflow can short-circuit
20
+ * marker emission (potential v2.7 optimization). Today markers still
21
+ * emit and we drop them silently in prepareRequest.
22
+ */
23
+ import type { CacheCapabilities, CacheMarker, CacheMetrics, CacheStrategy, CacheStrategyContext } from '../types.js';
24
+ import type { LLMRequest } from '../../adapters/types.js';
25
+ export declare class BedrockCacheStrategy implements CacheStrategy {
26
+ readonly providerName = "bedrock";
27
+ readonly capabilities: CacheCapabilities;
28
+ prepareRequest(req: LLMRequest, candidates: readonly CacheMarker[], ctx: CacheStrategyContext): Promise<{
29
+ readonly request: LLMRequest;
30
+ readonly markersApplied: readonly CacheMarker[];
31
+ }>;
32
+ extractMetrics(usage: unknown): CacheMetrics | undefined;
33
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * NoOpCacheStrategy — fallback strategy for providers without cache
3
+ * support (Mock, unknown providers, intentional opt-out).
4
+ *
5
+ * Returns the request unchanged; reports no metrics. The
6
+ * `capabilities.enabled` flag is `false` so the CacheDecision subflow
7
+ * could choose to skip emitting markers entirely (potential v2.7
8
+ * optimization), though current Phase 4+5 always emit markers and
9
+ * let the strategy decide what to do with them.
10
+ *
11
+ * Always-available default. Registered against the special wildcard
12
+ * `'*'` so any unrecognized provider name falls back to NoOp.
13
+ */
14
+ import type { CacheCapabilities, CacheMarker, CacheMetrics, CacheStrategy, CacheStrategyContext } from '../types.js';
15
+ import type { LLMRequest } from '../../adapters/types.js';
16
+ export declare class NoOpCacheStrategy implements CacheStrategy {
17
+ /**
18
+ * Wildcard provider name. The strategy registry treats this as the
19
+ * fallback for any provider that doesn't have a specific strategy
20
+ * registered.
21
+ */
22
+ readonly providerName = "*";
23
+ readonly capabilities: CacheCapabilities;
24
+ prepareRequest(req: LLMRequest, _candidates: readonly CacheMarker[], _ctx: CacheStrategyContext): Promise<{
25
+ readonly request: LLMRequest;
26
+ readonly markersApplied: readonly CacheMarker[];
27
+ }>;
28
+ extractMetrics(_usage: unknown): CacheMetrics | undefined;
29
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * OpenAICacheStrategy — metrics-only strategy for OpenAI providers.
3
+ *
4
+ * OpenAI auto-caches request prefixes ≥1024 tokens at 50% off.
5
+ * No client-side opt-in markers needed (and no way to influence
6
+ * cache behavior from the client). The strategy:
7
+ *
8
+ * - **prepareRequest**: pass-through. We can't tell OpenAI what
9
+ * to cache; they decide automatically. Markers are silently
10
+ * dropped (the 80% case for OpenAI consumers is "I declared
11
+ * cache: 'always' for my injections" — that's still meaningful
12
+ * because (a) it's portable across providers, (b) for OpenAI
13
+ * the auto-cache may still hit on stable prefixes regardless).
14
+ * - **extractMetrics**: reads `prompt_tokens_details.cached_tokens`
15
+ * from OpenAI's usage response so cacheRecorder can surface
16
+ * hit rates / dollar savings.
17
+ *
18
+ * Auto-registers on module import for: 'openai', 'browser-openai'.
19
+ *
20
+ * Documentation note for consumers (Phase 12 docs): the `cache:`
21
+ * directive on injection definitions is portable but has NO LOCAL
22
+ * EFFECT on OpenAI runs — the provider auto-caches based on prefix
23
+ * length. The directive still ships correctly with the agent and
24
+ * lights up automatically when you swap to Anthropic / Bedrock.
25
+ */
26
+ import type { CacheCapabilities, CacheMarker, CacheMetrics, CacheStrategy, CacheStrategyContext } from '../types.js';
27
+ import type { LLMRequest } from '../../adapters/types.js';
28
+ export declare class OpenAICacheStrategy implements CacheStrategy {
29
+ readonly providerName = "openai";
30
+ readonly capabilities: CacheCapabilities;
31
+ prepareRequest(req: LLMRequest, _candidates: readonly CacheMarker[], _ctx: CacheStrategyContext): Promise<{
32
+ readonly request: LLMRequest;
33
+ readonly markersApplied: readonly CacheMarker[];
34
+ }>;
35
+ extractMetrics(usage: unknown): CacheMetrics | undefined;
36
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Strategy registry — maps provider name → CacheStrategy.
3
+ *
4
+ * Auto-resolution at agent build time: agentfootprint inspects
5
+ * `provider.name` and looks up the registered strategy for that
6
+ * name. Falls back to `NoOpCacheStrategy` (registered under wildcard
7
+ * `'*'`) when the provider isn't recognized.
8
+ *
9
+ * Phases shipping registered strategies:
10
+ * - v2.6 Phase 6 (this phase): NoOp
11
+ * - v2.6 Phase 7: AnthropicCacheStrategy ('anthropic',
12
+ * 'browser-anthropic')
13
+ * - v2.6 Phase 8: OpenAICacheStrategy ('openai', 'browser-openai'),
14
+ * BedrockCacheStrategy ('bedrock')
15
+ * - v2.7+ : GeminiCacheStrategy (handle-based, async, deferred)
16
+ *
17
+ * Consumers can register their own strategy via
18
+ * `registerCacheStrategy(strategy)`. Useful for in-house LLM proxies
19
+ * or test mocks.
20
+ */
21
+ import type { CacheStrategy } from './types.js';
22
+ /**
23
+ * Look up a CacheStrategy by provider name. Falls back to the
24
+ * wildcard NoOp strategy if no match.
25
+ *
26
+ * Lookup is case-insensitive on the provider name.
27
+ */
28
+ export declare function getDefaultCacheStrategy(providerName: string): CacheStrategy;
29
+ /**
30
+ * Register (or replace) a strategy for a provider name. Called by
31
+ * strategy modules (v2.6 Phase 7+) at module load OR by consumers
32
+ * needing a custom backend. Replacing an existing strategy is allowed
33
+ * — the most-recent registration wins.
34
+ */
35
+ export declare function registerCacheStrategy(strategy: CacheStrategy): void;
36
+ /**
37
+ * Read-only view of registered strategy names. Useful for diagnostics
38
+ * (e.g., logging "we have strategies for: anthropic, openai, *").
39
+ */
40
+ export declare function listRegisteredStrategies(): readonly string[];
41
+ /**
42
+ * Internal helper for tests: reset the registry to the default
43
+ * (wildcard → NoOp only). Not exported from the public barrel.
44
+ */
45
+ export declare function _resetRegistryForTests(): void;
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Cache layer — public types.
3
+ *
4
+ * Three layers, each with one responsibility:
5
+ *
6
+ * 1. CONSUMER DSL — `CachePolicy` field on every injection factory.
7
+ * Declarative, like GraphQL schema input. Says WHAT should be
8
+ * cacheable. Examples: `cache: 'always'`, `cache: 'while-active'`.
9
+ *
10
+ * 2. AGNOSTIC MARKERS — `CacheMarker[]` produced by the
11
+ * `CacheDecision` subflow at runtime. Provider-independent
12
+ * identification of "cacheable prefix in field X up to index Y".
13
+ *
14
+ * 3. PROVIDER STRATEGY — one `CacheStrategy` implementation per
15
+ * provider (Anthropic / OpenAI / Bedrock / NoOp). Translates
16
+ * agnostic markers to provider-specific wire format AND extracts
17
+ * cache metrics from the provider's response.
18
+ *
19
+ * The interfaces are read-only / immutable by convention. Strategies
20
+ * MUST be stateless across runs; per-run state lives in the
21
+ * `CacheStrategyContext` passed into `prepareRequest`.
22
+ */
23
+ import type { LLMRequest } from '../adapters/types.js';
24
+ /**
25
+ * `cache:` field shape on every injection factory.
26
+ *
27
+ * Defaults per factory (chosen so `cache:` is rarely written explicitly):
28
+ * - `defineSteering` → `'always'`
29
+ * - `defineFact` → `'always'`
30
+ * - `defineSkill` → `'while-active'`
31
+ * - `defineInstruction` → `'never'`
32
+ * - `defineMemory` → `'while-active'`
33
+ *
34
+ * Variants:
35
+ * - `'always'` — cache whenever this injection is in `activeInjections`.
36
+ * Sugar for `{ until: () => false }`. The most aggressive form.
37
+ * - `'never'` — never cache. Use for volatile content (rule predicates,
38
+ * on-tool-return injections, content with timestamps or per-request IDs).
39
+ * Sugar for `{ until: () => true }` — i.e., always-invalidated.
40
+ * - `'while-active'` — cache while this injection appears in
41
+ * `activeInjections[]` for the current iteration. The cache invalidates
42
+ * the moment the injection becomes inactive (predicate returns `false`,
43
+ * skill deactivates, fact gets removed). Skill default; intuitive
44
+ * meaning regardless of factory.
45
+ * - `{ until: ctx => ... }` — conditional invalidation; cached UNTIL
46
+ * the predicate returns `true`. The predicate runs every iteration;
47
+ * if it flips to `true`, the cache prefix is rebuilt.
48
+ *
49
+ * **Composition**: the four sentinel forms cover most cases. For
50
+ * complex composition (e.g., "cache always EXCEPT after iter 5"), use
51
+ * the `{ until: ... }` form directly:
52
+ *
53
+ * ```ts
54
+ * // Stable for the first 5 iters, then flush:
55
+ * cache: { until: ctx => ctx.iteration > 5 }
56
+ *
57
+ * // Cache while iter > 1 (skip caching on the very first call):
58
+ * cache: { until: ctx => ctx.iteration <= 1 }
59
+ *
60
+ * // Invalidate when cumulative spend exceeds budget:
61
+ * cache: { until: ctx => ctx.cumulativeInputTokens > 50_000 }
62
+ * ```
63
+ *
64
+ * The predicate is the DSL's escape hatch — Turing-complete by design.
65
+ * 80% of consumers stick with the three sentinel strings; power users
66
+ * compose freely via `{ until }`.
67
+ */
68
+ export type CachePolicy = 'always' | 'never' | 'while-active' | {
69
+ readonly until: (ctx: CachePolicyContext) => boolean;
70
+ };
71
+ /**
72
+ * Context passed to a `CachePolicy.until` predicate. Read-only
73
+ * snapshot; predicates must be pure.
74
+ *
75
+ * Mirrors `InjectionContext` but trimmed to the fields a cache
76
+ * predicate would meaningfully inspect.
77
+ */
78
+ export interface CachePolicyContext {
79
+ /** Current ReAct iteration (1-based). */
80
+ readonly iteration: number;
81
+ /** Number of iterations remaining (= maxIterations - iteration). */
82
+ readonly iterationsRemaining: number;
83
+ /** The current user message that started this turn. */
84
+ readonly userMessage: string;
85
+ /** Last tool that returned, if any. */
86
+ readonly lastToolName?: string;
87
+ /** Cumulative input tokens so far this run. */
88
+ readonly cumulativeInputTokens: number;
89
+ }
90
+ /**
91
+ * Provider-independent identification of a cacheable prefix.
92
+ *
93
+ * The CacheDecision subflow walks `activeInjections` and emits one
94
+ * marker per slot whose entries from index 0..boundaryIndex form a
95
+ * stable, contiguous, cacheable prefix.
96
+ *
97
+ * `field` is the request field this marker targets. Each provider
98
+ * strategy translates it differently:
99
+ * - `'system'` → Anthropic puts `cache_control` on a system block
100
+ * - `'tools'` → Anthropic puts `cache_control` on a tools array entry
101
+ * - `'messages'` → Anthropic puts `cache_control` on the LAST content
102
+ * block of the LAST message (Anthropic-specific positional rule)
103
+ */
104
+ export interface CacheMarker {
105
+ readonly field: 'system' | 'tools' | 'messages';
106
+ /**
107
+ * 0-based index of the LAST element in `field` to include in the
108
+ * cached prefix. Everything from index 0..boundaryIndex (inclusive)
109
+ * is cacheable.
110
+ *
111
+ * **Provider note for `field: 'messages'`**: Anthropic's `cache_control`
112
+ * on `messages` is positional — it only takes effect on the LAST
113
+ * content block of the LAST message in the cacheable prefix. The
114
+ * AnthropicCacheStrategy translates `boundaryIndex` to the right
115
+ * positional placement; consumers and CacheDecision subflow don't
116
+ * see this complexity.
117
+ */
118
+ readonly boundaryIndex: number;
119
+ /**
120
+ * Suggested TTL for this marker. Strategies map to provider-specific
121
+ * values (Anthropic: `'short'` → 5min ephemeral, `'long'` → 1h beta).
122
+ */
123
+ readonly ttl: 'short' | 'long';
124
+ /**
125
+ * Diagnostic string surfaced in cacheRecorder events. Helps consumers
126
+ * understand WHY this marker fired. Examples: `'always-on injections'`,
127
+ * `'skill body (port-error-triage)'`.
128
+ */
129
+ readonly reason: string;
130
+ }
131
+ /**
132
+ * Per-provider cache implementation. One strategy per provider name;
133
+ * registered in a default map keyed by `LLMProvider.name`.
134
+ *
135
+ * Strategies MUST be stateless across runs. Any per-run state (handle
136
+ * cache, hit-rate tracking) lives inside the strategy instance.
137
+ */
138
+ export interface CacheStrategy {
139
+ /** Provider name match. e.g. `'anthropic'`, `'openai'`, `'bedrock'`. */
140
+ readonly providerName: string;
141
+ /**
142
+ * Static description of what this strategy can do. Read by the
143
+ * CacheDecision subflow to know whether to bother emitting markers,
144
+ * and how many to emit before clamping to provider limits.
145
+ */
146
+ readonly capabilities: CacheCapabilities;
147
+ /**
148
+ * Translate agnostic markers to provider-specific wire format.
149
+ *
150
+ * Async to support handle-based caching (Gemini does
151
+ * `createCachedContent` and references handles; not in v2.6 but
152
+ * the interface is async-ready for v2.7+).
153
+ *
154
+ * Returns the modified request AND the markers actually applied
155
+ * (after capability-clamping). `markersApplied` flows into the
156
+ * cacheRecorder for diagnostic surfacing.
157
+ */
158
+ prepareRequest(req: LLMRequest, candidates: readonly CacheMarker[], ctx: CacheStrategyContext): Promise<{
159
+ readonly request: LLMRequest;
160
+ readonly markersApplied: readonly CacheMarker[];
161
+ }>;
162
+ /**
163
+ * Extract cache hit/miss metrics from the provider's `usage` field.
164
+ * Each provider names its cache fields differently:
165
+ * - Anthropic: `cache_creation_input_tokens` + `cache_read_input_tokens`
166
+ * - OpenAI: `prompt_tokens_details.cached_tokens`
167
+ *
168
+ * Returns `undefined` for providers without cache reporting (Mock, NoOp).
169
+ */
170
+ extractMetrics(usage: unknown): CacheMetrics | undefined;
171
+ }
172
+ /**
173
+ * Static description of a strategy's capabilities. The CacheDecision
174
+ * subflow reads this BEFORE calling `prepareRequest` so it can clamp
175
+ * candidates to a count the strategy can actually use.
176
+ */
177
+ export interface CacheCapabilities {
178
+ /**
179
+ * `true` if this strategy actually does anything. `false` for NoOp,
180
+ * Mock, or providers we haven't built yet. CacheDecision subflow
181
+ * skips entirely when `enabled` is `false`.
182
+ */
183
+ readonly enabled: boolean;
184
+ /**
185
+ * Maximum number of cache markers per request. Anthropic enforces 4
186
+ * cache breakpoints per request; OpenAI is automatic (∞); Gemini
187
+ * is per-handle (∞ effectively). Strategies clamp internally.
188
+ */
189
+ readonly maxMarkers: number;
190
+ /**
191
+ * TTL values this strategy can map to. Anthropic supports both;
192
+ * OpenAI is fixed (~5min); some providers may only support one.
193
+ */
194
+ readonly ttls: ReadonlyArray<'short' | 'long'>;
195
+ /**
196
+ * Which request fields this strategy can mark. Most providers support
197
+ * all three (system / tools / messages); some are field-restricted.
198
+ */
199
+ readonly fields: ReadonlyArray<'system' | 'tools' | 'messages'>;
200
+ /**
201
+ * `true` if the provider auto-caches without explicit markers (OpenAI).
202
+ * In that case `prepareRequest` is a pass-through; only
203
+ * `extractMetrics` does meaningful work. Surfaced for documentation
204
+ * (so consumers know `cache: 'never'` may not actually disable caching
205
+ * on auto-caching providers).
206
+ */
207
+ readonly automatic: boolean;
208
+ }
209
+ /**
210
+ * Per-run state passed into `prepareRequest`. Strategies use this to
211
+ * make per-iteration decisions (rate of cache invalidation, current
212
+ * iteration index, etc.) without leaking state into module scope.
213
+ */
214
+ export interface CacheStrategyContext {
215
+ readonly iteration: number;
216
+ readonly iterationsRemaining: number;
217
+ /**
218
+ * Hit rate across previous iterations of this run (0..1). Strategies
219
+ * use this for self-disable behaviors (e.g., AnthropicCacheStrategy
220
+ * auto-skips markers when hit rate < 30% to avoid the cache-write
221
+ * penalty without recoup).
222
+ */
223
+ readonly recentHitRate: number | undefined;
224
+ /**
225
+ * `true` when `Agent.create({ caching: 'off' })` is set OR a
226
+ * higher-level kill switch fires. Strategy MUST honor this and
227
+ * return the request unchanged.
228
+ */
229
+ readonly cachingDisabled: boolean;
230
+ }
231
+ /**
232
+ * Normalized cache metrics extracted from a provider's `usage`
233
+ * response. cacheRecorder consumes these for hit-rate tracking,
234
+ * cost estimation (via PricingTable), and diagnostic events.
235
+ */
236
+ export interface CacheMetrics {
237
+ /** Tokens served from cache (10% / 50% / 25% off depending on provider). */
238
+ readonly cacheReadTokens: number;
239
+ /** Tokens written to cache this call (premium varies by provider). */
240
+ readonly cacheWriteTokens: number;
241
+ /** New input tokens not from cache — full price. */
242
+ readonly freshInputTokens: number;
243
+ }