@theokit/sdk 1.5.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 (369) hide show
  1. package/CHANGELOG.md +1571 -0
  2. package/LICENSE +201 -0
  3. package/README.md +80 -0
  4. package/bin/theokit-migrate-config.mjs +269 -0
  5. package/bin/theokit-migrate-memory.mjs +116 -0
  6. package/dist/agent-builder.d.ts +52 -0
  7. package/dist/agent-factory.d.ts +39 -0
  8. package/dist/agent.d.ts +175 -0
  9. package/dist/batch.d.ts +11 -0
  10. package/dist/budget.d.ts +48 -0
  11. package/dist/cache.d.ts +74 -0
  12. package/dist/cron-1yxL3K2S.d.cts +221 -0
  13. package/dist/cron-BYVdYzob.d.ts +221 -0
  14. package/dist/cron.cjs +14655 -0
  15. package/dist/cron.cjs.map +1 -0
  16. package/dist/cron.d.cts +3 -0
  17. package/dist/cron.d.ts +71 -0
  18. package/dist/cron.js +14652 -0
  19. package/dist/cron.js.map +1 -0
  20. package/dist/define-tool.d.ts +35 -0
  21. package/dist/errors-CK8brCJ1.d.cts +448 -0
  22. package/dist/errors-CvAeEWgE.d.ts +448 -0
  23. package/dist/errors.cjs +255 -0
  24. package/dist/errors.cjs.map +1 -0
  25. package/dist/errors.d.cts +3 -0
  26. package/dist/errors.d.ts +356 -0
  27. package/dist/errors.js +238 -0
  28. package/dist/errors.js.map +1 -0
  29. package/dist/eval.cjs +14826 -0
  30. package/dist/eval.cjs.map +1 -0
  31. package/dist/eval.d.cts +35 -0
  32. package/dist/eval.d.ts +35 -0
  33. package/dist/eval.js +14821 -0
  34. package/dist/eval.js.map +1 -0
  35. package/dist/generate-object.d.ts +67 -0
  36. package/dist/handoff.d.ts +55 -0
  37. package/dist/index.cjs +17127 -0
  38. package/dist/index.cjs.map +1 -0
  39. package/dist/index.d.cts +1878 -0
  40. package/dist/index.d.ts +24 -0
  41. package/dist/index.js +17095 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/internal/agent-loop/loop-types.d.ts +29 -0
  44. package/dist/internal/agent-loop/loop.d.ts +2 -0
  45. package/dist/internal/agent-loop/message-builders.d.ts +6 -0
  46. package/dist/internal/agent-loop/tool-dispatch.d.ts +4 -0
  47. package/dist/internal/agent-loop/usage-and-cost.d.ts +25 -0
  48. package/dist/internal/budget/calendar-window.d.ts +19 -0
  49. package/dist/internal/budget/compute-cost.d.ts +28 -0
  50. package/dist/internal/budget/enforcement.d.ts +32 -0
  51. package/dist/internal/budget/ledger.d.ts +25 -0
  52. package/dist/internal/budget/normalize-usage.d.ts +27 -0
  53. package/dist/internal/budget/pricing-registry.d.ts +36 -0
  54. package/dist/internal/budget/registry.d.ts +16 -0
  55. package/dist/internal/budget/usage-accumulator.d.ts +31 -0
  56. package/dist/internal/cache/cosine.d.ts +14 -0
  57. package/dist/internal/cache/embed-helper.d.ts +15 -0
  58. package/dist/internal/cache/key.d.ts +15 -0
  59. package/dist/internal/cache/lookup.d.ts +28 -0
  60. package/dist/internal/cache/store-handler.d.ts +24 -0
  61. package/dist/internal/cache/store-json.d.ts +48 -0
  62. package/dist/internal/cache/store.d.ts +54 -0
  63. package/dist/internal/cache/telemetry.d.ts +20 -0
  64. package/dist/internal/cache/ttl.d.ts +11 -0
  65. package/dist/internal/catalog/fixtures.d.ts +16 -0
  66. package/dist/internal/catalog/local-models.d.ts +24 -0
  67. package/dist/internal/cron/run-job.d.ts +1 -0
  68. package/dist/internal/cron/scheduler.d.ts +1 -0
  69. package/dist/internal/cron/store.d.ts +1 -0
  70. package/dist/internal/cron/validate.d.ts +1 -0
  71. package/dist/internal/env.d.ts +1 -0
  72. package/dist/internal/errors/mappers/anthropic.d.ts +30 -0
  73. package/dist/internal/errors/mappers/bedrock.d.ts +16 -0
  74. package/dist/internal/errors/mappers/ollama.d.ts +41 -0
  75. package/dist/internal/errors/mappers/openai-compatible.d.ts +25 -0
  76. package/dist/internal/errors/mappers/shared.d.ts +10 -0
  77. package/dist/internal/errors/mappers/vertex.d.ts +15 -0
  78. package/dist/internal/eval/aggregate.d.ts +9 -0
  79. package/dist/internal/eval/dataset-iter.d.ts +9 -0
  80. package/dist/internal/eval/runner.d.ts +9 -0
  81. package/dist/internal/eval/single-flight.d.ts +16 -0
  82. package/dist/internal/eval/telemetry.d.ts +23 -0
  83. package/dist/internal/fixture-mode.d.ts +16 -0
  84. package/dist/internal/handoff/dispatcher.d.ts +29 -0
  85. package/dist/internal/handoff/registry.d.ts +23 -0
  86. package/dist/internal/handoff/telemetry.d.ts +18 -0
  87. package/dist/internal/handoff/tool-injector.d.ts +34 -0
  88. package/dist/internal/http.d.ts +1 -0
  89. package/dist/internal/ids.d.ts +1 -0
  90. package/dist/internal/judge/judge-call.d.ts +35 -0
  91. package/dist/internal/judge/parse-verdict.d.ts +11 -0
  92. package/dist/internal/judge/types.d.ts +17 -0
  93. package/dist/internal/llm/anthropic-shared.d.ts +89 -0
  94. package/dist/internal/llm/anthropic.d.ts +9 -0
  95. package/dist/internal/llm/bedrock-anthropic.d.ts +36 -0
  96. package/dist/internal/llm/bedrock-token-cache.d.ts +18 -0
  97. package/dist/internal/llm/credential-pool-context.d.ts +11 -0
  98. package/dist/internal/llm/credential-pool-types.d.ts +22 -0
  99. package/dist/internal/llm/credential-pool.d.ts +18 -0
  100. package/dist/internal/llm/fallback-client.d.ts +1 -0
  101. package/dist/internal/llm/fault-injection.d.ts +50 -0
  102. package/dist/internal/llm/finish.d.ts +1 -0
  103. package/dist/internal/llm/model-identifier.d.ts +24 -0
  104. package/dist/internal/llm/ollama-native.d.ts +27 -0
  105. package/dist/internal/llm/openai.d.ts +9 -0
  106. package/dist/internal/llm/pool-aware-client.d.ts +16 -0
  107. package/dist/internal/llm/router.d.ts +17 -0
  108. package/dist/internal/llm/sse.d.ts +9 -0
  109. package/dist/internal/llm/stream-relay.d.ts +17 -0
  110. package/dist/internal/llm/types.d.ts +70 -0
  111. package/dist/internal/llm/vertex-anthropic.d.ts +40 -0
  112. package/dist/internal/llm/vertex-auth.d.ts +30 -0
  113. package/dist/internal/llm/vertex-gemini.d.ts +28 -0
  114. package/dist/internal/llm/vertex-router.d.ts +21 -0
  115. package/dist/internal/mcp/client.d.ts +16 -0
  116. package/dist/internal/memory/active-memory-cache.d.ts +10 -0
  117. package/dist/internal/memory/active-memory.d.ts +45 -0
  118. package/dist/internal/memory/adapters/catalog.d.ts +1 -0
  119. package/dist/internal/memory/adapters/deepinfra-embedding.d.ts +2 -0
  120. package/dist/internal/memory/adapters/mistral-embedding.d.ts +2 -0
  121. package/dist/internal/memory/adapters/ollama-embedding.d.ts +34 -0
  122. package/dist/internal/memory/adapters/openai-compatible.d.ts +23 -0
  123. package/dist/internal/memory/adapters/openai-embedding.d.ts +2 -0
  124. package/dist/internal/memory/adapters/openrouter-embedding.d.ts +2 -0
  125. package/dist/internal/memory/adapters/voyage-embedding.d.ts +2 -0
  126. package/dist/internal/memory/atomic-write.d.ts +7 -0
  127. package/dist/internal/memory/chunk-markdown.d.ts +2 -0
  128. package/dist/internal/memory/circuit-breaker.d.ts +22 -0
  129. package/dist/internal/memory/cwd-mutex.d.ts +1 -0
  130. package/dist/internal/memory/dreaming/diary.d.ts +4 -0
  131. package/dist/internal/memory/dreaming/phases.d.ts +15 -0
  132. package/dist/internal/memory/dreaming/run.d.ts +10 -0
  133. package/dist/internal/memory/embedding-adapter.d.ts +42 -0
  134. package/dist/internal/memory/embedding-cache.d.ts +1 -0
  135. package/dist/internal/memory/index-db.d.ts +10 -0
  136. package/dist/internal/memory/index-manager-dispatch.d.ts +23 -0
  137. package/dist/internal/memory/index-manager.d.ts +68 -0
  138. package/dist/internal/memory/index-schema.d.ts +21 -0
  139. package/dist/internal/memory/lance-index.d.ts +32 -0
  140. package/dist/internal/memory/lance-memory-adapter.d.ts +43 -0
  141. package/dist/internal/memory/markdown-store.d.ts +16 -0
  142. package/dist/internal/memory/memory-index.d.ts +52 -0
  143. package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +15 -0
  144. package/dist/internal/memory/migration.d.ts +9 -0
  145. package/dist/internal/memory/reader.d.ts +8 -0
  146. package/dist/internal/memory/session-loader.d.ts +1 -0
  147. package/dist/internal/memory/session-summary-writer.d.ts +2 -0
  148. package/dist/internal/memory/sqlite-vec-loader.d.ts +3 -0
  149. package/dist/internal/memory/tools.d.ts +14 -0
  150. package/dist/internal/memory/transcript-store.d.ts +1 -0
  151. package/dist/internal/memory/types.d.ts +17 -0
  152. package/dist/internal/memory/vec-index.d.ts +28 -0
  153. package/dist/internal/memory/wiki-loader.d.ts +2 -0
  154. package/dist/internal/observability/tracer-loader.d.ts +20 -0
  155. package/dist/internal/persistence/atomic-write.d.ts +1 -0
  156. package/dist/internal/persistence/conversation-storage-fs.d.ts +37 -0
  157. package/dist/internal/persistence/conversation-storage-memory.d.ts +24 -0
  158. package/dist/internal/persistence/cwd-mutex.d.ts +1 -0
  159. package/dist/internal/persistence/file-lock.d.ts +14 -0
  160. package/dist/internal/persistence/fts5-sanitize.d.ts +16 -0
  161. package/dist/internal/persistence/markdown-config-loader.d.ts +35 -0
  162. package/dist/internal/persistence/paths.d.ts +19 -0
  163. package/dist/internal/persistence/persistence-schema.d.ts +17 -0
  164. package/dist/internal/persistence/schema-version.d.ts +13 -0
  165. package/dist/internal/persistence/sqlite-wal.d.ts +10 -0
  166. package/dist/internal/personality/context.d.ts +17 -0
  167. package/dist/internal/personality/registry.d.ts +17 -0
  168. package/dist/internal/personality/store.d.ts +27 -0
  169. package/dist/internal/personality/switch.d.ts +36 -0
  170. package/dist/internal/personality/types.d.ts +18 -0
  171. package/dist/internal/plugins/context.d.ts +31 -0
  172. package/dist/internal/plugins/manager.d.ts +37 -0
  173. package/dist/internal/plugins/types.d.ts +102 -0
  174. package/dist/internal/providers/builtin/anthropic.d.ts +2 -0
  175. package/dist/internal/providers/builtin/bedrock.d.ts +25 -0
  176. package/dist/internal/providers/builtin/gemini.d.ts +10 -0
  177. package/dist/internal/providers/builtin/index.d.ts +19 -0
  178. package/dist/internal/providers/builtin/llamacpp.d.ts +1 -0
  179. package/dist/internal/providers/builtin/lmstudio.d.ts +1 -0
  180. package/dist/internal/providers/builtin/ollama.d.ts +17 -0
  181. package/dist/internal/providers/builtin/openai.d.ts +2 -0
  182. package/dist/internal/providers/builtin/openrouter.d.ts +2 -0
  183. package/dist/internal/providers/builtin/vertex.d.ts +27 -0
  184. package/dist/internal/providers/discovery.d.ts +14 -0
  185. package/dist/internal/providers/index.d.ts +8 -0
  186. package/dist/internal/providers/registry.d.ts +12 -0
  187. package/dist/internal/providers/types.d.ts +27 -0
  188. package/dist/internal/runtime/abort-utils.d.ts +21 -0
  189. package/dist/internal/runtime/agent-factory-registry.d.ts +16 -0
  190. package/dist/internal/runtime/agent-registry-store.d.ts +61 -0
  191. package/dist/internal/runtime/agent-registry.d.ts +34 -0
  192. package/dist/internal/runtime/agent-session-store.d.ts +3 -0
  193. package/dist/internal/runtime/agent-session.d.ts +2 -0
  194. package/dist/internal/runtime/async-local-storage.d.ts +20 -0
  195. package/dist/internal/runtime/async-semaphore.d.ts +24 -0
  196. package/dist/internal/runtime/budget.d.ts +36 -0
  197. package/dist/internal/runtime/cloud-agent.d.ts +1 -0
  198. package/dist/internal/runtime/cloud-config-serializer.d.ts +3 -0
  199. package/dist/internal/runtime/cloud-payload-types.d.ts +56 -0
  200. package/dist/internal/runtime/cloud-run.d.ts +1 -0
  201. package/dist/internal/runtime/cloud-tool-parity.d.ts +1 -0
  202. package/dist/internal/runtime/context-aggregator.d.ts +26 -0
  203. package/dist/internal/runtime/context-discovery-runner.d.ts +27 -0
  204. package/dist/internal/runtime/context-discovery.d.ts +21 -0
  205. package/dist/internal/runtime/context-frontmatter.d.ts +16 -0
  206. package/dist/internal/runtime/context-import-resolver.d.ts +24 -0
  207. package/dist/internal/runtime/context-loaders.d.ts +42 -0
  208. package/dist/internal/runtime/context-manager.d.ts +11 -0
  209. package/dist/internal/runtime/context-mdc-parser.d.ts +24 -0
  210. package/dist/internal/runtime/default-model.d.ts +1 -0
  211. package/dist/internal/runtime/fixture-events.d.ts +12 -0
  212. package/dist/internal/runtime/fixture-responder.d.ts +1 -0
  213. package/dist/internal/runtime/fixture-run-base.d.ts +45 -0
  214. package/dist/internal/runtime/fixture-scripts.d.ts +21 -0
  215. package/dist/internal/runtime/fixture-types.d.ts +1 -0
  216. package/dist/internal/runtime/fork-agent.d.ts +15 -0
  217. package/dist/internal/runtime/hooks-executor.d.ts +35 -0
  218. package/dist/internal/runtime/hooks-frontmatter.d.ts +26 -0
  219. package/dist/internal/runtime/hooks-source.d.ts +22 -0
  220. package/dist/internal/runtime/live-agent-registry.d.ts +87 -0
  221. package/dist/internal/runtime/local-agent-bootstrap.d.ts +37 -0
  222. package/dist/internal/runtime/local-agent-dispatch.d.ts +57 -0
  223. package/dist/internal/runtime/local-agent-invalidate.d.ts +8 -0
  224. package/dist/internal/runtime/local-agent-memory-direct.d.ts +12 -0
  225. package/dist/internal/runtime/local-agent-memory-hooks.d.ts +41 -0
  226. package/dist/internal/runtime/local-agent-memory.d.ts +1 -0
  227. package/dist/internal/runtime/local-agent-personality-extensions.d.ts +19 -0
  228. package/dist/internal/runtime/local-agent-plugins.d.ts +13 -0
  229. package/dist/internal/runtime/local-agent-runtime-extensions.d.ts +13 -0
  230. package/dist/internal/runtime/local-agent-task-wrap.d.ts +11 -0
  231. package/dist/internal/runtime/local-agent.d.ts +1 -0
  232. package/dist/internal/runtime/local-run.d.ts +1 -0
  233. package/dist/internal/runtime/memory-store.d.ts +4 -0
  234. package/dist/internal/runtime/plugin-frontmatter.d.ts +17 -0
  235. package/dist/internal/runtime/plugins-manager.d.ts +1 -0
  236. package/dist/internal/runtime/post-run-lifecycle.d.ts +1 -0
  237. package/dist/internal/runtime/providers-manager.d.ts +1 -0
  238. package/dist/internal/runtime/real-cloud-run.d.ts +2 -0
  239. package/dist/internal/runtime/real-local-run.d.ts +2 -0
  240. package/dist/internal/runtime/run-registry.d.ts +5 -0
  241. package/dist/internal/runtime/run-until.d.ts +22 -0
  242. package/dist/internal/runtime/shell-tool.d.ts +7 -0
  243. package/dist/internal/runtime/skill-frontmatter.d.ts +1 -0
  244. package/dist/internal/runtime/skills-manager.d.ts +1 -0
  245. package/dist/internal/runtime/spawn-collect.d.ts +8 -0
  246. package/dist/internal/runtime/subagents-loader.d.ts +1 -0
  247. package/dist/internal/runtime/system-prompt/escape.d.ts +1 -0
  248. package/dist/internal/runtime/system-prompt/local-assembly.d.ts +1 -0
  249. package/dist/internal/runtime/system-prompt/pipeline.d.ts +1 -0
  250. package/dist/internal/runtime/system-prompt/providers/active-memory-provider.d.ts +1 -0
  251. package/dist/internal/runtime/system-prompt/providers/base-provider.d.ts +1 -0
  252. package/dist/internal/runtime/system-prompt/providers/context-provider.d.ts +1 -0
  253. package/dist/internal/runtime/system-prompt/providers/memory-provider.d.ts +1 -0
  254. package/dist/internal/runtime/system-prompt/providers/skills-provider.d.ts +1 -0
  255. package/dist/internal/runtime/system-prompt/safe-call.d.ts +1 -0
  256. package/dist/internal/runtime/system-prompt/types.d.ts +5 -0
  257. package/dist/internal/runtime/system-prompt.d.ts +1 -0
  258. package/dist/internal/runtime/validate-agent-options.d.ts +1 -0
  259. package/dist/internal/runtime/workspace-dir.d.ts +9 -0
  260. package/dist/internal/runtime/yaml-frontmatter.d.ts +20 -0
  261. package/dist/internal/scorers/llm-judge.d.ts +24 -0
  262. package/dist/internal/security/index.d.ts +11 -0
  263. package/dist/internal/security/path-guard.d.ts +56 -0
  264. package/dist/internal/security/redact.d.ts +21 -0
  265. package/dist/internal/structured-output-helpers.d.ts +54 -0
  266. package/dist/internal/task/registry.d.ts +61 -0
  267. package/dist/internal/task/ring-buffer.d.ts +10 -0
  268. package/dist/internal/task/store.d.ts +59 -0
  269. package/dist/internal/task/subscribe.d.ts +15 -0
  270. package/dist/internal/task/telemetry.d.ts +27 -0
  271. package/dist/internal/telemetry/adapter-registry.d.ts +2 -0
  272. package/dist/internal/telemetry/adapters/langfuse.d.ts +2 -0
  273. package/dist/internal/telemetry/adapters/posthog.d.ts +2 -0
  274. package/dist/internal/telemetry/adapters/sentry.d.ts +2 -0
  275. package/dist/internal/telemetry/safe-require.d.ts +1 -0
  276. package/dist/internal/telemetry/tracer.d.ts +18 -0
  277. package/dist/internal/tool-dispatch/repair-middleware.d.ts +34 -0
  278. package/dist/internal/tool-dispatch/strip-think.d.ts +22 -0
  279. package/dist/internal/tool-registry/personality-filter.d.ts +37 -0
  280. package/dist/internal/workflow/ctx.d.ts +19 -0
  281. package/dist/internal/workflow/error-shape.d.ts +7 -0
  282. package/dist/internal/workflow/executor.d.ts +15 -0
  283. package/dist/internal/workflow/index.d.ts +12 -0
  284. package/dist/internal/workflow/retry-policy.d.ts +14 -0
  285. package/dist/internal/workflow/run-id.d.ts +9 -0
  286. package/dist/internal/workflow/single-flight.d.ts +18 -0
  287. package/dist/internal/workflow/snapshot-store.d.ts +23 -0
  288. package/dist/internal/workflow/step-agent.d.ts +12 -0
  289. package/dist/internal/workflow/step-branch.d.ts +10 -0
  290. package/dist/internal/workflow/step-dowhile.d.ts +8 -0
  291. package/dist/internal/workflow/step-fn.d.ts +10 -0
  292. package/dist/internal/workflow/step-foreach.d.ts +11 -0
  293. package/dist/internal/workflow/step-parallel.d.ts +17 -0
  294. package/dist/internal/workflow/step-sleep.d.ts +7 -0
  295. package/dist/internal/workflow/telemetry.d.ts +23 -0
  296. package/dist/internal/zod/to-json-schema.d.ts +21 -0
  297. package/dist/memory-adapter-helpers.d.ts +28 -0
  298. package/dist/memory.d.ts +123 -0
  299. package/dist/migrate.d.ts +33 -0
  300. package/dist/path-safety.cjs +126 -0
  301. package/dist/path-safety.cjs.map +1 -0
  302. package/dist/path-safety.d.cts +15 -0
  303. package/dist/path-safety.d.ts +15 -0
  304. package/dist/path-safety.js +120 -0
  305. package/dist/path-safety.js.map +1 -0
  306. package/dist/run-DkCD5DeO.d.cts +2181 -0
  307. package/dist/run-DkCD5DeO.d.ts +2181 -0
  308. package/dist/scorers.d.ts +75 -0
  309. package/dist/security.d.ts +67 -0
  310. package/dist/stream-object.d.ts +74 -0
  311. package/dist/task-store.cjs +237 -0
  312. package/dist/task-store.cjs.map +1 -0
  313. package/dist/task-store.d.cts +8 -0
  314. package/dist/task-store.d.ts +8 -0
  315. package/dist/task-store.js +233 -0
  316. package/dist/task-store.js.map +1 -0
  317. package/dist/task.d.ts +87 -0
  318. package/dist/theokit.d.ts +84 -0
  319. package/dist/tools/_path-scope.d.cts +8 -0
  320. package/dist/tools/_path-scope.d.ts +8 -0
  321. package/dist/tools/_subprocess.d.cts +28 -0
  322. package/dist/tools/_subprocess.d.ts +28 -0
  323. package/dist/tools/git-diff.d.cts +22 -0
  324. package/dist/tools/git-diff.d.ts +22 -0
  325. package/dist/tools/index.d.cts +29 -0
  326. package/dist/tools/index.d.ts +29 -0
  327. package/dist/tools/list-dir.d.cts +26 -0
  328. package/dist/tools/list-dir.d.ts +26 -0
  329. package/dist/tools/read-file.d.cts +31 -0
  330. package/dist/tools/read-file.d.ts +31 -0
  331. package/dist/tools/run-vitest.d.cts +46 -0
  332. package/dist/tools/run-vitest.d.ts +46 -0
  333. package/dist/tools/search-text.d.cts +32 -0
  334. package/dist/tools/search-text.d.ts +32 -0
  335. package/dist/tools.cjs +690 -0
  336. package/dist/tools.cjs.map +1 -0
  337. package/dist/tools.js +683 -0
  338. package/dist/tools.js.map +1 -0
  339. package/dist/trajectory-helpers.d.ts +31 -0
  340. package/dist/types/agent.d.ts +771 -0
  341. package/dist/types/batch.d.ts +112 -0
  342. package/dist/types/budget.d.ts +88 -0
  343. package/dist/types/cache.d.ts +76 -0
  344. package/dist/types/context.d.ts +93 -0
  345. package/dist/types/conversation-storage.d.ts +76 -0
  346. package/dist/types/conversation.d.ts +90 -0
  347. package/dist/types/cron.d.ts +150 -0
  348. package/dist/types/eval.d.ts +132 -0
  349. package/dist/types/goal-events.d.ts +95 -0
  350. package/dist/types/handoff.d.ts +135 -0
  351. package/dist/types/index.d.ts +20 -0
  352. package/dist/types/mcp.d.ts +64 -0
  353. package/dist/types/memory-adapter.d.ts +175 -0
  354. package/dist/types/messages.d.ts +154 -0
  355. package/dist/types/providers.d.ts +102 -0
  356. package/dist/types/run.d.ts +215 -0
  357. package/dist/types/task.d.ts +131 -0
  358. package/dist/types/theokit.d.ts +61 -0
  359. package/dist/types/trajectory.d.ts +49 -0
  360. package/dist/types/updates.d.ts +148 -0
  361. package/dist/types/usage.d.ts +61 -0
  362. package/dist/types/workflow.d.ts +217 -0
  363. package/dist/workflow.cjs +2405 -0
  364. package/dist/workflow.cjs.map +1 -0
  365. package/dist/workflow.d.cts +97 -0
  366. package/dist/workflow.d.ts +97 -0
  367. package/dist/workflow.js +2398 -0
  368. package/dist/workflow.js.map +1 -0
  369. package/package.json +183 -0
@@ -0,0 +1,29 @@
1
+ import type { ConversationTurn } from "../../types/conversation.js";
2
+ import type { SDKMessage } from "../../types/messages.js";
3
+ import type { RunStatus } from "../../types/run.js";
4
+ export interface AgentLoopOutput {
5
+ events: SDKMessage[];
6
+ finalStatus: RunStatus;
7
+ result: string;
8
+ conversation: ConversationTurn[];
9
+ /**
10
+ * Aggregated token usage across every LLM call in this loop (ADR D376).
11
+ * Populated whenever ≥1 LLM call completed — including partial-failure
12
+ * runs (EC-5). Undefined when zero LLM calls fired (e.g., abort before
13
+ * first send, or fixture-mode path that bypasses this loop).
14
+ */
15
+ usage?: import("../../types/usage.js").TokenUsage;
16
+ /**
17
+ * Inferred pricing-based cost matching `usage` (ADR D377). Set when the
18
+ * model has a pricing entry in the registry; `cost.status` is
19
+ * `"estimated"` / `"unknown"` / `"included"` per D377.
20
+ */
21
+ cost?: import("../../types/usage.js").CostBreakdown;
22
+ /**
23
+ * Structured error from transport / provider failure (Finding B fix).
24
+ * When set, `finalStatus === "error"`. Downstream surfaces (runtime,
25
+ * `RunResult.error`) copy this verbatim. NEVER leaks as an assistant
26
+ * message (the previous bug — sdk-error-packaging-fix-plan).
27
+ */
28
+ error?: AgentLoopErrorDetail;
29
+ }
@@ -0,0 +1,2 @@
1
+ import type { AgentLoopInputs, AgentLoopOutput } from "./loop-types.js";
2
+ export declare function runAgentLoop(inputs: AgentLoopInputs): Promise<AgentLoopOutput>;
@@ -0,0 +1,6 @@
1
+ import type { SDKAssistantMessage, SDKUserMessageEvent } from "../../types/messages.js";
2
+ import type { LlmMessage, LlmToolCallPart } from "../llm/types.js";
3
+ import type { AgentLoopInputs } from "./loop-types.js";
4
+ export declare function buildUserEvent(inputs: AgentLoopInputs): SDKUserMessageEvent;
5
+ export declare function buildAssistantEvent(inputs: AgentLoopInputs, text: string): SDKAssistantMessage;
6
+ export declare function buildAssistantTurn(text: string, toolCalls: LlmToolCallPart[]): LlmMessage;
@@ -0,0 +1,4 @@
1
+ import type { SDKMessage } from "../../types/messages.js";
2
+ import type { LlmContentPart, LlmToolCallPart } from "../llm/types.js";
3
+ import type { AgentLoopInputs } from "./loop-types.js";
4
+ export declare function dispatchTools(inputs: AgentLoopInputs, tools: ResolvedTool[], toolCalls: LlmToolCallPart[], events: SDKMessage[]): Promise<LlmContentPart[]>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Usage + cost helpers extracted from `loop.ts` (ADRs D376/D377).
3
+ *
4
+ * - `accumulateUsage(usage, llmOutput)` — merge a single LLM turn's 5-bucket
5
+ * token counts into the per-loop {@link UsageAccumulator}. Early-returns
6
+ * when no bucket was populated (avoids spurious zero-step entries on
7
+ * pure-error turns).
8
+ * - `computeUsageCost(inputs, usage)` — resolve provider+model from the
9
+ * `model.id` prefix (with LlmClient.name fallback) and run the pricing
10
+ * registry lookup to produce the matching `CostBreakdown`. Returns
11
+ * `undefined` for the `auto` sentinel model.
12
+ *
13
+ * @internal
14
+ */
15
+ import type { UsageAccumulator } from "../budget/usage-accumulator.js";
16
+ import type { AgentLoopInputs } from "./loop-types.js";
17
+ export interface LlmTurnUsage {
18
+ inputTokens?: number;
19
+ outputTokens?: number;
20
+ cacheReadTokens?: number;
21
+ cacheWriteTokens?: number;
22
+ reasoningTokens?: number;
23
+ }
24
+ export declare function accumulateUsage(usage: UsageAccumulator, turn: LlmTurnUsage): void;
25
+ export declare function computeUsageCost(inputs: AgentLoopInputs, usage: TokenUsage): CostBreakdown | undefined;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * UTC-aligned calendar window helpers (ADR D382).
3
+ *
4
+ * - `1h` — relative (now - 1 hour).
5
+ * - `1d` — UTC midnight (current UTC day).
6
+ * - `1w` — UTC monday 00:00:00 (current UTC week, Monday is week start).
7
+ * - `30d` — relative 30 days.
8
+ * - `365d` — relative 365 days.
9
+ *
10
+ * `1d` and `1w` are calendar-aligned because users expect "1 USD per day"
11
+ * = "since midnight UTC", not a rolling 24h.
12
+ * `30d`/`365d` are relative because nobody expects "since the 1st".
13
+ *
14
+ * @internal
15
+ */
16
+ export declare function startOfDayUtc(now?: Date): Date;
17
+ export declare function startOfWeekUtc(now?: Date): Date;
18
+ /** Returns the inclusive start timestamp (ms) for the given window relative to `now`. */
19
+ export declare function windowStartMs(window: BudgetWindow, now?: Date): number;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * computeCost — apply pricing entries to a TokenUsage and produce a
3
+ * CostBreakdown (ADRs D377, D378).
4
+ *
5
+ * Edge cases absorbed:
6
+ * - EC-13: negative pricing → status="unknown" + note.
7
+ * - EC-14: reasoning tokens fall back to outputCostPerMillion when
8
+ * dedicated reasoning rate is undefined.
9
+ * - EC-12: money precision via microcent normalization (× 1e6).
10
+ * - "subscription_included" routes (Codex CLI, future Claude Pro) →
11
+ * return $0 with status="included".
12
+ * - Provider unknown / pricing missing → status="unknown" with
13
+ * undefined amountUsd (NÃO retorna 0 falso).
14
+ *
15
+ * @internal
16
+ */
17
+ interface ComputeArgs {
18
+ readonly usage: TokenUsage;
19
+ readonly provider: string;
20
+ readonly model: string;
21
+ readonly baseUrl?: string;
22
+ }
23
+ /**
24
+ * Returns CostBreakdown with `status="estimated"`, `"unknown"`, or
25
+ * `"included"`. Never throws; never returns 0 when pricing is missing.
26
+ */
27
+ export declare function computeCost(args: ComputeArgs): CostBreakdown;
28
+ export {};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Budget enforcement (ADRs D383, D386, EC-7/8/9).
3
+ *
4
+ * - `preflightCheck(name, estimatedUsd)` — em `block` mode, throw
5
+ * `BudgetExceededError` antes da LLM call se qualquer limit seria
6
+ * excedido (EC-9 — caller chama dentro do mutex section).
7
+ * - `chargeAndCheckThresholds(name, actualUsd)` — apply charge ao
8
+ * ledger + invoca onThreshold/onExceed callbacks isolated em
9
+ * try/catch (EC-8).
10
+ *
11
+ * @internal
12
+ */
13
+ /**
14
+ * Throws BudgetExceededError if `mode === "block"` and any limit
15
+ * would be exceeded. No-op for audit/warn modes (post-charge checks
16
+ * handle those).
17
+ *
18
+ * Caller invokes this BEFORE the LLM call.
19
+ */
20
+ export declare function preflightCheck(name: string, estimatedUsd: number): void;
21
+ /**
22
+ * Charge the budget + dispatch threshold/exceed callbacks (EC-8 isolated).
23
+ *
24
+ * - In `audit` mode: charge only, no callbacks.
25
+ * - In `warn` mode: charge + onThreshold (80/95) + onExceed (100). No throw.
26
+ * - In `block` mode: charge + onThreshold + onExceed. No throw post-call
27
+ * (preflightCheck already prevented exceed for the upcoming call;
28
+ * this protects against simultaneous-call races where multiple sends
29
+ * each pass preflight independently — last one to charge may still
30
+ * tip a limit. We document the case rather than retroactively throw).
31
+ */
32
+ export declare function chargeAndCheckThresholds(name: string, actualUsd: number): Promise<void>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * In-process Budget ledger (ADR D385).
3
+ *
4
+ * Singleton mutex-protected. Stores per-budget ChargeLog[] arrays;
5
+ * `spentIn(window)` filters by timestamp.
6
+ *
7
+ * EC-6: GC eviction runs DENTRO do mesmo mutex que charge — sem race.
8
+ * EC-9: charge() é called inside same critical section as preflight
9
+ * check by Budget enforcement.
10
+ *
11
+ * Persistence cross-restart: deferred to v0.2 (JsonFile pattern).
12
+ *
13
+ * @internal
14
+ */
15
+ /** Charge a budget. Idempotent across concurrent calls via withCwdMutex. */
16
+ export declare function charge(name: string, amountUsd: number): Promise<void>;
17
+ /** Return total spend in the given window for `name`. Snapshot read (no mutex needed). */
18
+ export declare function spentIn(name: string, window: BudgetWindow, now?: Date): number;
19
+ /** Diagnostic — total logs across all budgets. */
20
+ export declare function __getLogCountForTests(name?: string): number;
21
+ export declare function __resetLedgerForTests(): void;
22
+ /** Force GC manually (tests only). */
23
+ export declare function __evictNowForTests(): Promise<void>;
24
+ /** Force-insert a log at a specific timestamp (tests only). */
25
+ export declare function __injectLogForTests(name: string, timestamp: number, amountUsd: number): void;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * normalizeUsage — convert provider-shaped raw `usage` object to
3
+ * canonical `TokenUsage`. Ports Hermes Agent's `normalize_usage`
4
+ * (referencia/hermes-agent/agent/usage_pricing.py:672-742).
5
+ *
6
+ * Handles 3 API shapes:
7
+ * - Anthropic Messages: 4 explicit buckets (input/output/cache_read/cache_creation).
8
+ * - OpenAI Chat Completions: prompt_tokens INCLUDES cache; subtract cached_tokens.
9
+ * - OpenAI Responses (Codex): input_tokens INCLUDES cache; same subtraction.
10
+ *
11
+ * Edge cases:
12
+ * - cline#10266 — OpenAI-compat proxies (OpenRouter, Vercel AI Gateway,
13
+ * Cline) routing Claude expose Anthropic-style top-level fields
14
+ * (cache_read_input_tokens / cache_creation_input_tokens). Both
15
+ * locations are checked with top-level fallback.
16
+ * - Null/undefined fields → 0 via `int()` coerce.
17
+ * - String token counts → parsed via int.
18
+ * - Negative values → clamped to 0 (defensive against proxy bugs).
19
+ *
20
+ * @internal
21
+ */
22
+ export type ApiMode = "anthropic_messages" | "openai_chat_completions" | "openai_responses";
23
+ export declare function inferApiMode(provider: string): ApiMode;
24
+ export declare function normalizeUsage(rawUsage: unknown, opts: {
25
+ provider: string;
26
+ apiMode?: ApiMode;
27
+ }): TokenUsage;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Pricing registry — bundled snapshot of LiteLLM JSON (ADR D379) with
3
+ * lazy load + alias normalization (EC-2).
4
+ *
5
+ * Snapshot lives in `pricing-data.json` (hand-curated 2026-05; refresh
6
+ * via `scripts/refresh-pricing.mjs`). All rates in USD per 1_000_000
7
+ * tokens (D378).
8
+ *
9
+ * Lookup precedence (EC-2):
10
+ * 1. Direct `provider/model` key
11
+ * 2. Strip date suffix (-YYYYMMDD or -YYYY-MM-DD)
12
+ * 3. Anthropic dot-to-dash normalization (claude-opus-4.7 → claude-opus-4-7)
13
+ * 4. Strip `openrouter/` prefix
14
+ *
15
+ * @internal
16
+ */
17
+ export interface PricingEntry {
18
+ readonly provider: string;
19
+ readonly model: string;
20
+ readonly inputCostPerMillion: number;
21
+ readonly outputCostPerMillion: number;
22
+ readonly cacheReadCostPerMillion?: number;
23
+ readonly cacheWriteCostPerMillion?: number;
24
+ readonly reasoningCostPerMillion?: number;
25
+ readonly pricingVersion: string;
26
+ }
27
+ /**
28
+ * Returns the pricing entry for a given `{provider, model}` route.
29
+ * Tries direct lookup, then 3 alias normalizations (EC-2).
30
+ */
31
+ export declare function getPricingEntry(opts: {
32
+ provider: string;
33
+ model: string;
34
+ baseUrl?: string;
35
+ }): PricingEntry | undefined;
36
+ export declare function pricingVersion(): string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Internal Budget registry — keeps live `BudgetOptions` per name.
3
+ * Singleton; no persistence (D385).
4
+ *
5
+ * @internal
6
+ */
7
+ import type { BudgetHandle, BudgetMode, BudgetOptions, BudgetSnapshot } from "../../types/budget.js";
8
+ export declare function __resetRegistryForTests(): void;
9
+ export declare function validateBudgetName(name: string): void;
10
+ export declare function createBudget(opts: BudgetOptions): BudgetHandle;
11
+ export declare function getBudget(name: string): BudgetHandle | undefined;
12
+ export declare function listBudgets(): readonly BudgetHandle[];
13
+ export declare function deleteBudget(name: string): boolean;
14
+ export declare function snapshotAll(): readonly BudgetSnapshot[];
15
+ export declare function getBudgetOptionsRaw(name: string): BudgetOptions | undefined;
16
+ export declare function defaultMode(opts: BudgetOptions): BudgetMode;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * UsageAccumulator — aggregate multi-step `LlmFinish` token counts
3
+ * into a canonical `TokenUsage` (ADR D376, mirror openai-agents-python
4
+ * `Usage.add`).
5
+ *
6
+ * Each `add(step)` merges in a per-step finish; `toTokenUsage()`
7
+ * produces the aggregated public shape with `requests[]` populated
8
+ * when there were ≥2 steps.
9
+ *
10
+ * @internal
11
+ */
12
+ interface StepUsage {
13
+ inputTokens?: number;
14
+ outputTokens?: number;
15
+ cacheReadTokens?: number;
16
+ cacheWriteTokens?: number;
17
+ reasoningTokens?: number;
18
+ }
19
+ export declare class UsageAccumulator {
20
+ private input;
21
+ private output;
22
+ private cacheRead;
23
+ private cacheWrite;
24
+ private reasoning;
25
+ private readonly requests;
26
+ add(step: StepUsage): void;
27
+ /** Did we observe any usage at all? */
28
+ hasAny(): boolean;
29
+ toTokenUsage(): TokenUsage;
30
+ }
31
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Cosine distance between two equal-length vectors.
3
+ *
4
+ * Returns `1 - cos(a, b)`. Range:
5
+ * - 0.0 = identical direction
6
+ * - 1.0 = orthogonal
7
+ * - 2.0 = opposite (rare in normalized embeddings)
8
+ *
9
+ * Throws on dim mismatch. (Callers MUST filter by dim before calling
10
+ * — EC-2 absorbed at the store level.)
11
+ *
12
+ * @internal
13
+ */
14
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Shared embed-with-graceful-degradation helper — used by both `lookup.ts`
3
+ * and `store-handler.ts`. Extracted to remove the embed-failure boilerplate
4
+ * clone flagged by jscpd. EC-1 absorbed: embedder failure is silent (caller
5
+ * decides what to do via the boolean return).
6
+ *
7
+ * @internal
8
+ */
9
+ import type { InMemoryCacheStore } from "./store.js";
10
+ import type { JsonFileCacheStore } from "./store-json.js";
11
+ interface SpanLike {
12
+ setAttribute(key: string, value: string | number | boolean): SpanLike;
13
+ }
14
+ export declare function embedOrDegrade(embedder: CacheEmbedderRuntime, prompt: string, store: InMemoryCacheStore | JsonFileCacheStore, span: SpanLike, context: "lookup" | "store"): Promise<number[] | undefined>;
15
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Composite cache key (ADR D253).
3
+ *
4
+ * Format: `${namespace}:${embedderId}:${modelId}:${hash(normalizedPrompt)}`.
5
+ * Normalizes whitespace + lowercases. Hash = first 16 hex chars of SHA-256.
6
+ *
7
+ * @internal
8
+ */
9
+ export interface CacheKeyParams {
10
+ namespace: string;
11
+ embedderId: string;
12
+ modelId: string;
13
+ prompt: string;
14
+ }
15
+ export declare function computeCacheKey(p: CacheKeyParams): string;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Cache lookup handler — wired to `pre_user_send` hook (ADRs D259, D260).
3
+ *
4
+ * EC-1: embedder failure degrades to miss (cache is transparent).
5
+ * EC-3: empty / whitespace prompt bypasses cache (avoids hash collision).
6
+ * EC-5: telemetry span ends in finally even on early-return.
7
+ *
8
+ * @internal
9
+ */
10
+ import type { InMemoryCacheStore } from "./store.js";
11
+ import type { JsonFileCacheStore } from "./store-json.js";
12
+ export type LookupableStore = InMemoryCacheStore | JsonFileCacheStore;
13
+ export interface LookupParams {
14
+ prompt: string;
15
+ store: LookupableStore;
16
+ embedder: CacheEmbedderRuntime;
17
+ threshold: number;
18
+ ttl: CacheTTLConfig;
19
+ namespace: string;
20
+ modelId: string;
21
+ }
22
+ export interface LookupResult {
23
+ cached: boolean;
24
+ response?: string;
25
+ source?: "kv" | "semantic";
26
+ distance?: number;
27
+ }
28
+ export declare function performLookup(p: LookupParams): Promise<LookupResult>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Cache store handler — wired to `post_assistant_reply` hook (ADRs D260, D266).
3
+ *
4
+ * EC-1: embedder failure during store is silent (LLM call already succeeded;
5
+ * no cache entry written).
6
+ * EC-3: empty prompt bypass.
7
+ * EC-10 / D266: skip storage when the run invoked tools (replay loses
8
+ * side-effects).
9
+ *
10
+ * @internal
11
+ */
12
+ import type { LookupableStore } from "./lookup.js";
13
+ export interface StoreParams {
14
+ prompt: string;
15
+ response: string;
16
+ /** D266: skip cache when tools were used. */
17
+ usedTools?: boolean;
18
+ store: LookupableStore;
19
+ embedder: CacheEmbedderRuntime;
20
+ ttl: CacheTTLConfig;
21
+ namespace: string;
22
+ modelId: string;
23
+ }
24
+ export declare function performStore(p: StoreParams): Promise<void>;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * JSON disk-backed cache store (ADR D265).
3
+ *
4
+ * One file per namespace at `<dir>/<namespace>.json`. Uses
5
+ * `atomicWriteText` (D60) for crash-safe writes. Debounced flush (200ms)
6
+ * to coalesce bursts.
7
+ *
8
+ * EC-7: corrupt JSON load → log warn + treat as empty cache. Never
9
+ * propagates parse errors that would block `Agent.create`.
10
+ *
11
+ * Layered behind `InMemoryCacheStore` — disk is just persistence; all
12
+ * lookups still hit the in-memory Map for O(1) KV / O(N) vector scan.
13
+ *
14
+ * @internal
15
+ */
16
+ import type { CacheEntry, CacheStats } from "../../types/cache.js";
17
+ import { type CacheStore } from "./store.js";
18
+ export declare class JsonFileCacheStore implements CacheStore {
19
+ private readonly dir;
20
+ private readonly namespace;
21
+ private readonly inner;
22
+ private flushTimer;
23
+ private dirty;
24
+ constructor(dir: string, namespace: string, maxEntries: number);
25
+ /** Hydrate from disk. EC-7: corrupt file → empty cache. */
26
+ hydrate(): Promise<void>;
27
+ kvGet(key: string, now: number): CacheEntry | undefined;
28
+ semanticSearch(vector: ReadonlyArray<number>, threshold: number, embedderId: string, namespace: string, now: number): {
29
+ entry: CacheEntry;
30
+ distance: number;
31
+ } | undefined;
32
+ set(entry: CacheEntry): void;
33
+ delete(key: string): void;
34
+ clear(): Promise<void>;
35
+ stats(): CacheStats;
36
+ evictExpired(now: number): number;
37
+ /** Force write the current snapshot. Called on shutdown / clear. */
38
+ flush(): Promise<void>;
39
+ /** Counters proxied to inner. */
40
+ incrementKvHits(): void;
41
+ incrementSemanticHits(): void;
42
+ incrementMisses(): void;
43
+ incrementExcluded(): void;
44
+ incrementEmbedderFailures(): void;
45
+ private filePath;
46
+ private markDirty;
47
+ private writeSnapshot;
48
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Cache store interface + in-memory implementation (ADRs D252, D259, D261).
3
+ *
4
+ * INVARIANT (EC-9, EC-13): KV map and vector view are the SAME Map.
5
+ * `semanticSearch` iterates `Map.values()`. No parallel list. `set` replaces
6
+ * by key (Map semantics) — no duplicate-on-race possible.
7
+ *
8
+ * EC-2: `semanticSearch` filters by `embedderId === currentEmbedderId &&
9
+ * vector.length === currentDim` before cosine compare. Protects against
10
+ * dim mismatch when disk-loaded entries used a different embedder.
11
+ *
12
+ * @internal
13
+ */
14
+ export interface CacheStore {
15
+ kvGet(key: string, now: number): CacheEntry | undefined;
16
+ semanticSearch(vector: ReadonlyArray<number>, threshold: number, embedderId: string, namespace: string, now: number): {
17
+ entry: CacheEntry;
18
+ distance: number;
19
+ } | undefined;
20
+ set(entry: CacheEntry): void;
21
+ delete(key: string): void;
22
+ clear(): Promise<void>;
23
+ stats(): CacheStats;
24
+ evictExpired(now: number): number;
25
+ /** For persistence backends — bulk import. */
26
+ loadAll?(entries: ReadonlyArray<CacheEntry>): void;
27
+ /** For persistence backends — snapshot for serialization. */
28
+ dump?(): ReadonlyArray<CacheEntry>;
29
+ }
30
+ export declare class InMemoryCacheStore implements CacheStore {
31
+ private readonly maxEntries;
32
+ private readonly map;
33
+ private readonly counters;
34
+ constructor(maxEntries: number);
35
+ kvGet(key: string, now: number): CacheEntry | undefined;
36
+ private isEligibleForSearch;
37
+ semanticSearch(vector: ReadonlyArray<number>, threshold: number, embedderId: string, namespace: string, now: number): {
38
+ entry: CacheEntry;
39
+ distance: number;
40
+ } | undefined;
41
+ set(entry: CacheEntry): void;
42
+ delete(key: string): void;
43
+ clear(): Promise<void>;
44
+ stats(): CacheStats;
45
+ evictExpired(now: number): number;
46
+ loadAll(entries: ReadonlyArray<CacheEntry>): void;
47
+ dump(): ReadonlyArray<CacheEntry>;
48
+ /** Internal helpers for counters (used by lookup/store handlers). */
49
+ incrementKvHits(): void;
50
+ incrementSemanticHits(): void;
51
+ incrementMisses(): void;
52
+ incrementExcluded(): void;
53
+ incrementEmbedderFailures(): void;
54
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * OTel telemetry for semantic cache (ADR D262).
3
+ *
4
+ * Spans:
5
+ * - `cache.lookup` — per `pre_user_send`. Attributes: namespace, embedder.id,
6
+ * hit (kv|semantic|miss), distance, ttl_remaining_s, bypass_reason.
7
+ * - `cache.store` — per `post_assistant_reply`. Attributes: bypass_reason, stored.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare function startCacheLookupSpan(info: {
12
+ namespace: string;
13
+ embedderId: string;
14
+ }): SpanLike;
15
+ export declare function startCacheStoreSpan(info: {
16
+ namespace: string;
17
+ embedderId: string;
18
+ }): SpanLike;
19
+ /** Test seam — reset tracer cache so a fresh require attempt happens. */
20
+ export declare function __resetCacheTelemetryForTests(): void;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * TTL string parser. Accepts:
3
+ * - number → treated as SECONDS
4
+ * - string `"\d+(s|m|h|d|w)"` → seconds/minutes/hours/days/weeks
5
+ *
6
+ * EC-8: `"0s"` / `0` returns 0 (effectively disables cache for that entry).
7
+ * Negative numbers throw `CacheInvalidTtlError`.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare function parseTtlMs(input: string | number): number;
@@ -0,0 +1,16 @@
1
+ import type { SDKProvider } from "../../types/providers.js";
2
+ import type { SDKModel, SDKRepository, SDKUser } from "../../types/theokit.js";
3
+ /** Fixture user identity (matches `tests/golden/theokit/me.json`). */
4
+ export declare const FIXTURE_USER: SDKUser;
5
+ /** Fixture model catalog (matches `tests/golden/theokit/models.json`). */
6
+ export declare const FIXTURE_MODELS: SDKModel[];
7
+ /** Fixture connected repos (matches `tests/golden/theokit/repositories.json`). */
8
+ export declare const FIXTURE_REPOSITORIES: SDKRepository[];
9
+ /**
10
+ * Fixture provider catalog. Covers chat, web_search, image, and embedding
11
+ * capabilities. The `setupSchema` is intentionally generic JSON Schema —
12
+ * consumers drive UI from these definitions.
13
+ *
14
+ * Public and secret-free by design — no tokens or API key examples.
15
+ */
16
+ export declare const FIXTURE_PROVIDERS: SDKProvider[];
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Local model discovery via OpenAI-compatible `/v1/models` endpoint
3
+ * (T2.1, ADR D184).
4
+ *
5
+ * Used by `Theokit.models.list({ provider: "ollama" })` (and any other
6
+ * future provider with `authType: "none"` exposing the OpenAI-shape
7
+ * models endpoint — LM Studio, llama.cpp `./server`, vLLM, etc.) to
8
+ * enumerate locally-installed models without a cloud round-trip.
9
+ *
10
+ * Aligned with OpenClaw `extensions/ollama/src/provider-models.ts` which
11
+ * targets the same endpoint shape. Mirrors the relevant Hermes
12
+ * `models.dev` catalog behavior for local providers.
13
+ *
14
+ * @internal
15
+ */
16
+ import type { SDKModel } from "../../types/theokit.js";
17
+ /**
18
+ * Fetch and map `<baseUrl>/v1/models` → `SDKModel[]`. Throws a typed
19
+ * `ConfigurationError` on connection failures (ECONNREFUSED → "Run
20
+ * `ollama serve`"). Returns `[]` when the body is unparseable —
21
+ * defensive choice over crashing on malformed responses from
22
+ * non-standard local runtimes.
23
+ */
24
+ export declare function listLocalModelsViaOpenAiCompat(baseUrl: string): Promise<SDKModel[]>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Anthropic HTTP error mapper (ADR D67).
3
+ *
4
+ * Translates an Anthropic API error response into a typed
5
+ * `TheokitAgentError` subclass with full `ErrorMetadata`. Mapping rules:
6
+ *
7
+ * 401/403 → `AuthenticationError` (`code: "auth_failed"`)
8
+ * 429 → `RateLimitError` (`code: "rate_limit"`)
9
+ * 400 → `ConfigurationError` (`code: "context_too_long"` if body
10
+ * mentions context length, else
11
+ * `"invalid_request"`; or
12
+ * `"content_filtered"` for policy.)
13
+ * 408 → `NetworkError` (`code: "timeout"`)
14
+ * 5xx → `NetworkError` (`code: "server_error"` — covers 529
15
+ * overloaded_error common em horário
16
+ * de pico)
17
+ * other → `UnknownAgentError` (`code: "unknown"`)
18
+ *
19
+ * Never throws — caller is already in an error path.
20
+ *
21
+ * @internal
22
+ */
23
+ interface MapAnthropicErrorArgs {
24
+ status: number;
25
+ body: unknown;
26
+ headers: Headers | undefined;
27
+ endpoint: string;
28
+ }
29
+ export declare function mapAnthropicError(args: MapAnthropicErrorArgs): TheokitAgentError;
30
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * AWS Bedrock HTTP error mapper (ADRs D67, D300).
3
+ *
4
+ * Bedrock returns either AWS-style `{ message, __type: "ThrottlingException" }`
5
+ * or sometimes `{ Message }` (capitalized) depending on the model dialect.
6
+ * We accept both shapes and map to canonical `TheokitAgentError` subclasses.
7
+ *
8
+ * @internal
9
+ */
10
+ export interface MapBedrockErrorArgs {
11
+ status: number;
12
+ body: unknown;
13
+ headers: Headers | undefined;
14
+ endpoint: string;
15
+ }
16
+ export declare function mapBedrockError(args: MapBedrockErrorArgs): TheokitAgentError;