@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,132 @@
1
+ /**
2
+ * Public type contract for `Eval.create / .run` and the `Scorers` namespace
3
+ * (Adoption Roadmap #2; ADRs D202-D213).
4
+ *
5
+ * Consumers import these types via `@theokit/sdk` — they're re-exported
6
+ * from the package barrel. Implementation lives in `eval.ts`, `scorers.ts`,
7
+ * and `internal/eval/**`.
8
+ *
9
+ * @public
10
+ */
11
+ import type { SDKAgent } from "./agent.js";
12
+ /** Inferred `Agent.create` options shape — avoid cycling through `AgentOptions` directly. */
13
+ export type EvalAgentOptions = Parameters<typeof import("../agent.js").Agent.create>[0];
14
+ /** A single dataset row — input prompt + optional reference + free-form metadata. */
15
+ export interface DatasetEntry {
16
+ readonly input: string;
17
+ readonly expected?: unknown;
18
+ readonly metadata?: Record<string, unknown>;
19
+ }
20
+ /**
21
+ * `Dataset` is either an array OR a factory returning a (sync or async)
22
+ * iterable (D210). The runner normalizes both shapes into an
23
+ * `AsyncIterable<DatasetEntry>` internally.
24
+ */
25
+ export type Dataset = ReadonlyArray<DatasetEntry> | (() => Iterable<DatasetEntry> | AsyncIterable<DatasetEntry>);
26
+ /** Outcome of a single scoring decision. `score` in [0, 1]; the runner clamps. */
27
+ export interface Score {
28
+ readonly score: number;
29
+ readonly reason?: string;
30
+ }
31
+ /**
32
+ * Scorer signature (D207). Returns `Score` synchronously OR via Promise —
33
+ * the runner always awaits.
34
+ */
35
+ export type Scorer = (output: string, expected?: unknown) => Score | Promise<Score>;
36
+ /** A named scorer — produced by every `Scorers.*` factory. */
37
+ export interface NamedScorer {
38
+ readonly name: string;
39
+ readonly score: Scorer;
40
+ }
41
+ /** Lifecycle hooks. Each fires inside a `safeHook` wrapper (EC-4); a throw never aborts the run. */
42
+ export interface EvalHooks {
43
+ readonly beforeRun?: (info: {
44
+ name: string;
45
+ totalEstimate: number | undefined;
46
+ }) => void;
47
+ readonly afterRow?: (row: EvalRowResult, index: number) => void;
48
+ readonly afterRun?: (run: EvalRun) => void;
49
+ }
50
+ /** Public options for `Eval.create`. */
51
+ export interface EvalOptions {
52
+ /**
53
+ * Unique-per-process name for telemetry correlation + report titles.
54
+ * Concurrent runs with the same name throw `EvalAlreadyRunningError` (D213).
55
+ */
56
+ readonly name: string;
57
+ /** The dataset to evaluate. See {@link Dataset}. */
58
+ readonly dataset: Dataset;
59
+ /** At least one scorer. Plain `Scorer` is wrapped with an auto-name. */
60
+ readonly scorers: ReadonlyArray<Scorer | NamedScorer>;
61
+ /**
62
+ * Agent to evaluate. Three accepted shapes:
63
+ * - `SDKAgent` instance — same agent used for every row (no state isolation).
64
+ * - `EvalAgentOptions` — a fresh agent is constructed per row (state isolation; default).
65
+ * - `(entry) => SDKAgent | Promise<SDKAgent>` — dynamic agent selection.
66
+ */
67
+ readonly agent: SDKAgent | EvalAgentOptions | ((entry: DatasetEntry) => SDKAgent | Promise<SDKAgent>);
68
+ /**
69
+ * Row concurrency. Default 4 (matches `Agent.batch` D136). MUST be in
70
+ * `[1, 64]` (EC-3 — 0 deadlocks the semaphore, Infinity DoSs the provider).
71
+ */
72
+ readonly concurrency?: number;
73
+ /** Optional metadata persisted to `EvalRun.metadata` (tags, env, version). */
74
+ readonly metadata?: Record<string, unknown>;
75
+ /** Optional progress / lifecycle hooks. */
76
+ readonly hooks?: EvalHooks;
77
+ }
78
+ /** Per-row outcome. */
79
+ export interface EvalRowResult {
80
+ readonly index: number;
81
+ readonly input: string;
82
+ readonly output: string;
83
+ readonly expected?: unknown;
84
+ readonly scores: ReadonlyArray<{
85
+ readonly name: string;
86
+ readonly score: number;
87
+ readonly reason?: string;
88
+ }>;
89
+ readonly meanScore: number;
90
+ readonly durationMs: number;
91
+ readonly tokensIn?: number;
92
+ readonly tokensOut?: number;
93
+ readonly error?: string;
94
+ readonly metadata?: Record<string, unknown>;
95
+ }
96
+ /** Per-scorer breakdown computed across all rows. */
97
+ export interface PerScorerStats {
98
+ readonly mean: number;
99
+ readonly median: number;
100
+ readonly min: number;
101
+ readonly max: number;
102
+ }
103
+ /** Aggregate stats — the production-decision dashboard data (D211). */
104
+ export interface EvalAggregate {
105
+ readonly meanScore: number;
106
+ readonly medianScore: number;
107
+ /** Ratio of rows where `meanScore >= 0.5`. */
108
+ readonly passRatio: number;
109
+ readonly perScorer: Record<string, PerScorerStats>;
110
+ readonly totalRows: number;
111
+ readonly errorRows: number;
112
+ readonly durationMsP50: number;
113
+ readonly durationMsP95: number;
114
+ readonly tokensInTotal: number;
115
+ readonly tokensOutTotal: number;
116
+ }
117
+ /** Final run result — plain serializable JSON (D209). */
118
+ export interface EvalRun {
119
+ readonly id: string;
120
+ readonly name: string;
121
+ readonly startedAt: number;
122
+ readonly endedAt: number;
123
+ readonly durationMs: number;
124
+ readonly aggregate: EvalAggregate;
125
+ readonly rows: ReadonlyArray<EvalRowResult>;
126
+ readonly metadata?: Record<string, unknown>;
127
+ }
128
+ /** Per-call options for `eval.run(...)`. */
129
+ export interface EvalRunOptions {
130
+ /** Cancels pending rows; in-flight rows complete (D140 pattern). */
131
+ readonly signal?: AbortSignal;
132
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Public event types emitted by {@link SDKAgent.runUntil} (ADRs D115-D117).
3
+ *
4
+ * Discriminated union by `type` field so consumers can `switch (event.type)`
5
+ * with full TypeScript exhaustiveness. Mirrors the
6
+ * {@link import("../stream-object.js").StreamObjectEvent} pattern (ADR D39).
7
+ *
8
+ * @public
9
+ */
10
+ /**
11
+ * Single event emitted while iterating a goal-driven loop. Five variants:
12
+ *
13
+ * - `turn_start` — the agent is about to invoke `send()`. Emitted once
14
+ * per turn.
15
+ * - `agent_response` — the agent's `send()` resolved; carries the text
16
+ * reply.
17
+ * - `judge_verdict` — the auxiliary judge model evaluated the response.
18
+ * `parseFailed: true` indicates the judge returned a malformed reply
19
+ * (fail-safe verdict = `continue`, see ADR D121).
20
+ * - `continuation` — the judge ruled `continue`; carries the prompt that
21
+ * was sent on THIS turn (i.e., the input that produced the agent
22
+ * response just yielded). Useful for consumers who want to audit the
23
+ * exact continuation message that drove each iteration. The prompt
24
+ * for the NEXT turn is composed lazily at the start of that turn
25
+ * from the latest `agent_response.content`.
26
+ * - `status_change` — transition of the overall goal state. Always
27
+ * emitted once at start (`active`) and once at end
28
+ * (`completed | failed | paused`).
29
+ *
30
+ * @public
31
+ */
32
+ export type GoalEvent = {
33
+ type: "turn_start";
34
+ turn: number;
35
+ goal: string;
36
+ } | {
37
+ type: "agent_response";
38
+ turn: number;
39
+ content: string;
40
+ } | {
41
+ type: "judge_verdict";
42
+ turn: number;
43
+ verdict: "done" | "continue" | "skipped";
44
+ reason: string;
45
+ parseFailed: boolean;
46
+ } | {
47
+ type: "continuation";
48
+ turn: number;
49
+ prompt: string;
50
+ } | {
51
+ type: "status_change";
52
+ status: "active" | "paused" | "completed" | "failed";
53
+ reason: string;
54
+ };
55
+ /**
56
+ * Return value of the `runUntil` async generator. Consumer reads via
57
+ * `const { value } = await gen.next()` (when `done: true`).
58
+ *
59
+ * @public
60
+ */
61
+ export interface GoalResult {
62
+ status: "completed" | "failed" | "paused";
63
+ turnsUsed: number;
64
+ finalResponse: string | undefined;
65
+ }
66
+ /**
67
+ * Return type of {@link import("../internal/runtime/local-agent.js").LocalAgent.runUntil}.
68
+ * Extracted so the LocalAgent method signature stays a single line (G8 LoC budget).
69
+ *
70
+ * @public
71
+ */
72
+ export type RunUntilIterator = AsyncGenerator<GoalEvent, GoalResult, void>;
73
+ /**
74
+ * Per-call configuration for `Agent.runUntil`.
75
+ *
76
+ * @public
77
+ */
78
+ export interface GoalOptions {
79
+ /** Hard cap on iterations. Default `20`. */
80
+ maxTurns?: number;
81
+ /** Bail after N consecutive judge parse failures. Default `3` (ADR D121). */
82
+ maxConsecutiveJudgeFailures?: number;
83
+ /** Judge model identifier. Default `"openai/gpt-4o-mini"` (ADR D119). */
84
+ judgeModel?: string;
85
+ /** Override env for the judge auxiliary agent. Default `OPENROUTER_API_KEY` (EC-A). */
86
+ judgeApiKey?: string;
87
+ /** Optional subgoals fed to the judge prompt. */
88
+ subgoals?: string[];
89
+ /**
90
+ * Cancel mid-loop via `AbortController.signal`. The generator yields
91
+ * a `status_change: paused` event and returns at the next turn
92
+ * boundary (ADR D117).
93
+ */
94
+ signal?: AbortSignal;
95
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Public types for `Agent.create({ handoffs })` + `Handoff.create()` +
3
+ * `Agent.handoffTo()` (Adoption Roadmap #4; ADRs D214-D229).
4
+ *
5
+ * Pattern: handoff-as-tool. Each handoff destination becomes a synthetic
6
+ * `transfer_to_<receiver>` function tool exposed to the LLM. Runtime
7
+ * intercepts the tool call and routes the next turn to the receiver.
8
+ *
9
+ * @public
10
+ */
11
+ import type { ZodType } from "zod";
12
+ import type { SDKAgent } from "./agent.js";
13
+ /**
14
+ * Context handed to `onHandoff` callbacks and `isEnabled` predicates.
15
+ * Read-only snapshot of the handoff dispatch state.
16
+ */
17
+ export interface HandoffContext {
18
+ readonly senderAgentId: string;
19
+ readonly receiverAgentId: string;
20
+ /** Depth counter AT dispatch time (post-increment; first handoff = 1). */
21
+ readonly currentDepth: number;
22
+ /** Chain of agentIds traversed so far in this send(). Always ends with sender. */
23
+ readonly chain: ReadonlyArray<string>;
24
+ }
25
+ /**
26
+ * The transcript wrapper passed to `inputFilter`. `messages` is widened to
27
+ * `unknown[]` so this type doesn't import from `messages.ts` (avoids cycle
28
+ * — implementations cast to `SDKMessage[]` internally).
29
+ */
30
+ export interface HandoffHistory {
31
+ readonly messages: ReadonlyArray<unknown>;
32
+ }
33
+ /**
34
+ * Options accepted by `Handoff.create(target, opts?)`.
35
+ *
36
+ * @public
37
+ */
38
+ export interface HandoffOptions<TInput extends ZodType = ZodType> {
39
+ /** Override the default tool name `transfer_to_<receiver.name>` (D215). */
40
+ readonly toolName?: string;
41
+ /** Override the default tool description. */
42
+ readonly toolDescription?: string;
43
+ /**
44
+ * Side-effect callback fired BEFORE the receiver takes over.
45
+ *
46
+ * **Semantics (D227):** throwing aborts the handoff — the synthetic tool
47
+ * returns `tool_error: onHandoff_failed: <message>` so the LLM sees the
48
+ * conflict. Logger-style consumers MUST wrap their own try/catch to
49
+ * swallow exceptions.
50
+ */
51
+ readonly onHandoff?: (ctx: HandoffContext, parsed: TInput extends ZodType ? unknown : undefined) => void | Promise<void>;
52
+ /**
53
+ * Zod schema for the handoff tool-call arguments (structured payload).
54
+ * When set, LLM-provided args are validated before `onHandoff` fires.
55
+ *
56
+ * **Edge case (D229):** empty/null `inputJson` parses as `{}` before
57
+ * Zod refinements fire — required-field schemas still throw normally.
58
+ */
59
+ readonly inputType?: TInput;
60
+ /**
61
+ * Filter the history passed to the receiver (D216 default = full; D219).
62
+ *
63
+ * **Resilience (D228):** if this callback throws, the runtime logs once
64
+ * to stderr and falls back to the un-filtered history. Use this for
65
+ * privacy redaction; if you need fatal-on-failure semantics, throw in
66
+ * `onHandoff` instead.
67
+ */
68
+ readonly inputFilter?: (history: HandoffHistory) => HandoffHistory | Promise<HandoffHistory>;
69
+ /**
70
+ * Restrict the receiver's tools for the post-handoff turn ONLY (D224).
71
+ * Subsequent receiver-internal turns use the receiver's full tool set.
72
+ */
73
+ readonly tools?: ReadonlyArray<string>;
74
+ /**
75
+ * Dynamically enable/disable this handoff. Bool = static; predicate =
76
+ * called per-`Agent.send()` to evaluate.
77
+ */
78
+ readonly isEnabled?: boolean | ((ctx: HandoffContext) => boolean | Promise<boolean>);
79
+ }
80
+ /**
81
+ * Result of a single handoff dispatch (for telemetry / observability).
82
+ *
83
+ * @public
84
+ */
85
+ export interface HandoffResult {
86
+ readonly from: string;
87
+ readonly to: string;
88
+ readonly depth: number;
89
+ readonly toolName: string;
90
+ readonly reasonFromLlm?: string;
91
+ }
92
+ /** Throw when handoff depth exceeds `maxHandoffDepth` (default 5; D218). */
93
+ export declare class HandoffLoopError extends Error {
94
+ readonly name = "HandoffLoopError";
95
+ readonly depth: number;
96
+ readonly chain: ReadonlyArray<string>;
97
+ constructor(depth: number, chain: ReadonlyArray<string>);
98
+ }
99
+ /** Throw when the same (sender, receiver) pair invoked twice in one send() (D221). */
100
+ export declare class HandoffPairLoopError extends Error {
101
+ readonly name = "HandoffPairLoopError";
102
+ readonly senderAgentId: string;
103
+ readonly receiverAgentId: string;
104
+ constructor(senderAgentId: string, receiverAgentId: string);
105
+ }
106
+ /** Throw when an agent's `handoffs[]` includes a self-reference (EC-6). */
107
+ export declare class HandoffSelfReferenceError extends Error {
108
+ readonly name = "HandoffSelfReferenceError";
109
+ readonly agentId: string;
110
+ constructor(agentId: string);
111
+ }
112
+ /** Throw when receiver is disposed at dispatch time (EC-5). */
113
+ export declare class HandoffReceiverDisposedError extends Error {
114
+ readonly name = "HandoffReceiverDisposedError";
115
+ readonly receiverAgentId: string;
116
+ constructor(receiverAgentId: string);
117
+ }
118
+ /** Throw when two handoffs in the same parent collide on tool name (D215). */
119
+ export declare class HandoffNameCollisionError extends Error {
120
+ readonly name = "HandoffNameCollisionError";
121
+ readonly conflictingName: string;
122
+ constructor(conflictingName: string);
123
+ }
124
+ /**
125
+ * Public `Handoff` shape — what `Handoff.create()` returns. Read-only
126
+ * accessors only; behavior lives in the engine.
127
+ *
128
+ * @public
129
+ */
130
+ export interface HandoffDescriptor<TInput extends ZodType = ZodType> {
131
+ readonly target: SDKAgent;
132
+ readonly options: HandoffOptions<TInput>;
133
+ /** Resolved tool name (after applying toolName override or default `transfer_to_<receiver>`). */
134
+ readonly resolvedToolName: string;
135
+ }
@@ -0,0 +1,20 @@
1
+ export type * from "./agent.js";
2
+ export type * from "./batch.js";
3
+ export type * from "./budget.js";
4
+ export type * from "./cache.js";
5
+ export type * from "./context.js";
6
+ export type * from "./conversation.js";
7
+ export type * from "./conversation-storage.js";
8
+ export type * from "./cron.js";
9
+ export type * from "./goal-events.js";
10
+ export type * from "./handoff.js";
11
+ export type * from "./mcp.js";
12
+ export type * from "./memory-adapter.js";
13
+ export type * from "./messages.js";
14
+ export type * from "./providers.js";
15
+ export type * from "./run.js";
16
+ export type * from "./task.js";
17
+ export type * from "./theokit.js";
18
+ export type * from "./trajectory.js";
19
+ export type * from "./updates.js";
20
+ export type * from "./usage.js";
@@ -0,0 +1,64 @@
1
+ /**
2
+ * MCP server configuration accepted by `Agent.create()` and `agent.send()`.
3
+ *
4
+ * @public
5
+ */
6
+ export type McpStdioServerConfig = {
7
+ type?: "stdio";
8
+ command: string;
9
+ args?: string[];
10
+ env?: Record<string, string>;
11
+ /** Local agents only. Cloud rejects this field. */
12
+ cwd?: string;
13
+ };
14
+ /**
15
+ * OAuth-style auth bundle for HTTP/SSE MCP servers.
16
+ *
17
+ * @public
18
+ */
19
+ export interface McpAuthConfig {
20
+ CLIENT_ID: string;
21
+ CLIENT_SECRET?: string;
22
+ scopes?: string[];
23
+ /**
24
+ * OAuth 2.1 PKCE flow configuration (ADR D41, v1.2+). When present, the
25
+ * SDK runs the PKCE flow on first use and stores tokens via keychain or
26
+ * file. Without this, the SDK relies on `CLIENT_SECRET` + manual headers.
27
+ */
28
+ oauth?: McpOAuthConfig;
29
+ }
30
+ /**
31
+ * OAuth 2.1 PKCE flow descriptor. See ADR D41.
32
+ *
33
+ * @public
34
+ */
35
+ export interface McpOAuthConfig {
36
+ /** Authorization endpoint (e.g. https://api.notion.com/v1/oauth/authorize). */
37
+ authorizationEndpoint: string;
38
+ /** Token endpoint (e.g. https://api.notion.com/v1/oauth/token). */
39
+ tokenEndpoint: string;
40
+ /** Where the OAuth `code` is received. */
41
+ redirectMode: "manual" | "localhost";
42
+ /** Localhost callback port (0 = random free port, default). */
43
+ localhostPort?: number;
44
+ /** Flow timeout in ms (default 300_000 = 5min). */
45
+ timeoutMs?: number;
46
+ }
47
+ /**
48
+ * HTTP or SSE MCP server.
49
+ *
50
+ * @public
51
+ */
52
+ export type McpHttpServerConfig = {
53
+ type?: "http" | "sse";
54
+ url: string;
55
+ /** Passed through. `Authorization` works here. */
56
+ headers?: Record<string, string>;
57
+ auth?: McpAuthConfig;
58
+ };
59
+ /**
60
+ * Union of MCP server configs. See `docs.md` for the full reference.
61
+ *
62
+ * @public
63
+ */
64
+ export type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Public `MemoryAdapter` contract (T1.1, ADRs D141 / D147).
3
+ *
4
+ * The plugin extension point `{ kind: "memory" }` (ADR D98) declares a
5
+ * `createProvider` factory; this file types its return value formally.
6
+ * Adapters implement `write` / `recall` / `delete` plus optional methods
7
+ * gated by `capabilities`. `MemoryId` is a branded string prefixed with
8
+ * the adapter id so cross-adapter use throws on `extractRawId` (EC-B).
9
+ *
10
+ * Each provider-specific package (`@theokit-memory-supermemory`, etc)
11
+ * exports a factory returning a `Plugin { kind: "memory" }` whose
12
+ * `createProvider` resolves to a `MemoryAdapter` instance.
13
+ *
14
+ * @public
15
+ */
16
+ /**
17
+ * Branded provider memory ID. Format: `${adapterId}:${rawProviderId}`.
18
+ * Use `mkMemoryId` / `extractRawId` from `../memory-adapter-helpers.js`
19
+ * to construct and unwrap with cross-adapter safety (EC-B).
20
+ *
21
+ * @public
22
+ */
23
+ export type MemoryId = string & {
24
+ readonly __brand: "MemoryId";
25
+ };
26
+ /**
27
+ * Portable identity context. `userId` is the only required field —
28
+ * the lowest common denominator across Supermemory / Honcho / Mem0.
29
+ * Adapter implementations translate the optional fields to their
30
+ * provider's native primitives (Honcho session, Mem0 run_id, etc).
31
+ *
32
+ * @public
33
+ */
34
+ export interface MemoryContext {
35
+ /** End-user identity. */
36
+ userId: string;
37
+ /** Agent / persona writing the memory. */
38
+ agentId?: string;
39
+ /** Logical conversation / run boundary. */
40
+ sessionId?: string;
41
+ /** Tenant / workspace partition. */
42
+ tenantId?: string;
43
+ /** Free-form tags for filtering / categorization. */
44
+ tags?: string[];
45
+ /** Provider-passthrough metadata. */
46
+ metadata?: Record<string, unknown>;
47
+ }
48
+ /**
49
+ * A single memory fact returned by `recall` or `get`.
50
+ *
51
+ * @public
52
+ */
53
+ export interface MemoryFact {
54
+ id: MemoryId;
55
+ content: string;
56
+ /** Semantic relevance score (provider-defined scale) when result of `recall`. */
57
+ score?: number;
58
+ /** ISO 8601 timestamp of creation. */
59
+ createdAt?: string;
60
+ metadata?: Record<string, unknown>;
61
+ }
62
+ /**
63
+ * Versioned snapshot of a memory's history. Only emitted by providers
64
+ * with `capabilities.history === true` (Mem0 today).
65
+ *
66
+ * @public
67
+ */
68
+ export interface MemoryRevision {
69
+ id: MemoryId;
70
+ content: string;
71
+ version: number;
72
+ changedAt: string;
73
+ }
74
+ /**
75
+ * Statically declared adapter feature flags. Consumers feature-detect
76
+ * at compile time via `if (adapter.capabilities.history)`.
77
+ *
78
+ * @public
79
+ */
80
+ export interface MemoryAdapterCapabilities {
81
+ /** Returns prior versions of a memory via `history(id)`. */
82
+ history: boolean;
83
+ /** First-class `sessionId` scoping. */
84
+ sessions: boolean;
85
+ /** First-class `tenantId` scoping. */
86
+ tenancy: boolean;
87
+ /** Provider performs reasoning over memory (e.g., Honcho dialectic). */
88
+ reasoning: boolean;
89
+ /** Exposes LLM-callable function-calling schemas. */
90
+ toolSchemas: boolean;
91
+ /** Supports background prefetch (currently informational). */
92
+ prefetch: boolean;
93
+ }
94
+ /**
95
+ * One assistant-turn message in the canonical `{role, content}` shape
96
+ * an adapter may receive instead of a flat string when writing a turn.
97
+ *
98
+ * @public
99
+ */
100
+ export interface MemoryTurnMessage {
101
+ role: "user" | "assistant" | "system";
102
+ content: string;
103
+ }
104
+ /**
105
+ * OpenAI-format function-calling schema exposed to the LLM.
106
+ *
107
+ * @public
108
+ */
109
+ export interface MemoryToolSchema {
110
+ name: string;
111
+ description: string;
112
+ parameters: Record<string, unknown>;
113
+ }
114
+ /**
115
+ * Portable third-party memory adapter contract. Implementations live
116
+ * in `@theokit-memory-*` packages; the SDK never imports them.
117
+ *
118
+ * @public
119
+ */
120
+ export interface MemoryAdapter {
121
+ /** Short identifier — matches the `${adapterId}` prefix in `MemoryId`. */
122
+ readonly id: string;
123
+ readonly capabilities: MemoryAdapterCapabilities;
124
+ /** Synchronous availability probe — no network, no I/O. */
125
+ isAvailable(): boolean;
126
+ /** One-shot initialization. Idempotent: safe to call multiple times. */
127
+ initialize?(): Promise<void>;
128
+ /**
129
+ * Persist a fact or full turn to memory. Returns the stored
130
+ * `MemoryId`. Throws `MemoryAdapterError(code: "invalid_input")` on
131
+ * empty content or invalid identifiers in `ctx`.
132
+ */
133
+ write(content: string | MemoryTurnMessage[], ctx: MemoryContext): Promise<MemoryId>;
134
+ /**
135
+ * Semantic recall — top-`k` facts ordered by relevance. Returns
136
+ * empty array when `k === 0` or no matches.
137
+ */
138
+ recall(query: string, ctx: MemoryContext, k?: number): Promise<MemoryFact[]>;
139
+ /**
140
+ * Delete a memory by id. Throws `MemoryAdapterError(code:
141
+ * "invalid_input")` when the id was minted by a different adapter
142
+ * (EC-B). Throws `code: "not_found"` when the id does not exist.
143
+ */
144
+ delete(id: MemoryId): Promise<void>;
145
+ list?(ctx: MemoryContext, opts?: {
146
+ cursor?: string;
147
+ limit?: number;
148
+ }): AsyncIterable<MemoryFact>;
149
+ get?(id: MemoryId): Promise<MemoryFact | null>;
150
+ history?(id: MemoryId): Promise<MemoryRevision[]>;
151
+ /** Empty array when `capabilities.toolSchemas === false`. */
152
+ getToolSchemas?(): MemoryToolSchema[];
153
+ handleToolCall?(name: string, args: Record<string, unknown>, ctx: MemoryContext): Promise<string>;
154
+ /** Graceful shutdown — flush queues, close connections. */
155
+ shutdown?(): Promise<void>;
156
+ }
157
+ /**
158
+ * Direct memory API exposed on `SDKAgent.memory`. Resolves to whichever
159
+ * memory adapter(s) are registered via `Agent.create({ plugins: [...] })`.
160
+ *
161
+ * @public
162
+ */
163
+ export interface AgentMemory {
164
+ /**
165
+ * Persist a fact. Returns the first adapter's id; in multi-adapter
166
+ * setups all adapters receive the write (fan-out).
167
+ */
168
+ write(content: string | MemoryTurnMessage[], ctx?: Partial<MemoryContext>): Promise<MemoryId>;
169
+ /** Semantic recall — merged + deduped across registered adapters. */
170
+ recall(query: string, ctx?: Partial<MemoryContext>, k?: number): Promise<MemoryFact[]>;
171
+ /** Delete a memory by id — routes to the owning adapter via prefix. */
172
+ delete(id: MemoryId): Promise<void>;
173
+ /** Returns the first registered adapter or `null` when none exists. */
174
+ adapter(): MemoryAdapter | null;
175
+ }