@theokit/sdk 1.6.1 → 1.7.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 (351) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/dist/a2a/agent-mailbox.d.cts +27 -0
  3. package/dist/a2a/agent-mailbox.d.ts +27 -0
  4. package/dist/a2a/index.cjs +16850 -0
  5. package/dist/a2a/index.cjs.map +1 -0
  6. package/dist/a2a/index.d.cts +9 -0
  7. package/dist/a2a/index.d.ts +9 -0
  8. package/dist/a2a/index.js +16844 -0
  9. package/dist/a2a/index.js.map +1 -0
  10. package/dist/a2a/message-bus.d.cts +27 -0
  11. package/dist/a2a/message-bus.d.ts +27 -0
  12. package/dist/a2a/subagent.d.cts +25 -0
  13. package/dist/a2a/subagent.d.ts +25 -0
  14. package/dist/a2a/types.d.cts +12 -0
  15. package/dist/a2a/types.d.ts +12 -0
  16. package/dist/agent.d.ts +1 -1
  17. package/dist/client/index.cjs +73 -0
  18. package/dist/client/index.cjs.map +1 -0
  19. package/dist/client/index.d.cts +7 -0
  20. package/dist/client/index.d.ts +7 -0
  21. package/dist/client/index.js +71 -0
  22. package/dist/client/index.js.map +1 -0
  23. package/dist/client/theokit-client.d.cts +18 -0
  24. package/dist/client/theokit-client.d.ts +18 -0
  25. package/dist/client/types.d.cts +19 -0
  26. package/dist/client/types.d.ts +19 -0
  27. package/dist/{run-DkCD5DeO.d.cts → cron-BnywDYLq.d.cts} +496 -910
  28. package/dist/{run-DkCD5DeO.d.ts → cron-CtZvJD9J.d.ts} +496 -910
  29. package/dist/cron.cjs +4285 -2893
  30. package/dist/cron.cjs.map +1 -1
  31. package/dist/cron.d.cts +2 -3
  32. package/dist/cron.d.ts +2 -71
  33. package/dist/cron.js +4289 -2897
  34. package/dist/cron.js.map +1 -1
  35. package/dist/{errors-CvAeEWgE.d.ts → errors-ChqOmFH1.d.cts} +52 -6
  36. package/dist/{errors-CK8brCJ1.d.cts → errors-DV9e0rcp.d.ts} +52 -6
  37. package/dist/errors.cjs +218 -3
  38. package/dist/errors.cjs.map +1 -1
  39. package/dist/errors.d.cts +2 -3
  40. package/dist/errors.d.ts +50 -4
  41. package/dist/errors.js +217 -4
  42. package/dist/errors.js.map +1 -1
  43. package/dist/eval.cjs +4285 -2893
  44. package/dist/eval.cjs.map +1 -1
  45. package/dist/eval.d.cts +35 -0
  46. package/dist/eval.js +4289 -2897
  47. package/dist/eval.js.map +1 -1
  48. package/dist/event-bus.d.ts +23 -0
  49. package/dist/index.cjs +5132 -4200
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.cts +298 -278
  52. package/dist/index.d.ts +1898 -24
  53. package/dist/index.js +6441 -5509
  54. package/dist/index.js.map +1 -1
  55. package/dist/internal/agent-loop/loop-context-init.d.ts +2 -0
  56. package/dist/internal/agent-loop/tool-dispatch.d.ts +22 -1
  57. package/dist/internal/auth/api-key-validator.d.ts +46 -0
  58. package/dist/internal/llm/anthropic-shared.d.ts +8 -1
  59. package/dist/internal/llm/retry.d.ts +22 -0
  60. package/dist/internal/llm/types.d.ts +47 -1
  61. package/dist/internal/memory/active-memory-cache.d.ts +3 -3
  62. package/dist/internal/memory/active-memory-types.d.ts +8 -0
  63. package/dist/internal/memory/active-memory.d.ts +24 -20
  64. package/dist/internal/memory/adapters/azure-openai-embedding.d.ts +2 -0
  65. package/dist/internal/memory/adapters/cohere-embedding.d.ts +2 -0
  66. package/dist/internal/memory/adapters/gemini-embedding.d.ts +2 -0
  67. package/dist/internal/memory/adapters/jina-embedding.d.ts +2 -0
  68. package/dist/internal/memory/index-manager-contract.d.ts +26 -0
  69. package/dist/internal/memory/index-manager-dispatch.d.ts +1 -1
  70. package/dist/internal/memory/index-manager.d.ts +8 -26
  71. package/dist/internal/memory/{chunk-markdown.d.ts → storage/chunk-markdown.d.ts} +1 -1
  72. package/dist/internal/memory/{markdown-store.d.ts → storage/markdown-store.d.ts} +1 -1
  73. package/dist/internal/memory/{reader.d.ts → storage/reader.d.ts} +1 -1
  74. package/dist/internal/observability/context.d.cts +23 -0
  75. package/dist/internal/observability/context.d.ts +23 -0
  76. package/dist/internal/observability/index.cjs +38 -0
  77. package/dist/internal/observability/index.cjs.map +1 -0
  78. package/dist/internal/observability/index.d.cts +8 -0
  79. package/dist/internal/observability/index.d.ts +8 -0
  80. package/dist/internal/observability/index.js +33 -0
  81. package/dist/internal/observability/index.js.map +1 -0
  82. package/dist/internal/observability/tracer-loader.d.cts +20 -0
  83. package/dist/internal/persistence/conversation-storage-fs.d.cts +37 -0
  84. package/dist/internal/persistence/conversation-storage-memory.d.cts +24 -0
  85. package/dist/internal/persistence/credential-pool-store.d.cts +32 -0
  86. package/dist/internal/persistence/credential-pool-store.d.ts +32 -0
  87. package/dist/internal/persistence/cwd-mutex.d.cts +1 -0
  88. package/dist/internal/persistence/exclusive-create.d.cts +22 -0
  89. package/dist/internal/persistence/exclusive-create.d.ts +22 -0
  90. package/dist/internal/persistence/file-lock.d.cts +14 -0
  91. package/dist/internal/persistence/fts5-sanitize.d.cts +16 -0
  92. package/dist/internal/persistence/index.cjs +359 -0
  93. package/dist/internal/persistence/index.cjs.map +1 -0
  94. package/dist/internal/persistence/index.d.cts +20 -0
  95. package/dist/internal/persistence/index.d.ts +20 -0
  96. package/dist/internal/persistence/index.js +341 -0
  97. package/dist/internal/persistence/index.js.map +1 -0
  98. package/dist/internal/persistence/markdown-config-loader.d.cts +35 -0
  99. package/dist/internal/persistence/paths.d.cts +19 -0
  100. package/dist/internal/persistence/persistence-schema.d.cts +21 -0
  101. package/dist/internal/persistence/persistence-schema.d.ts +4 -0
  102. package/dist/internal/persistence/schema-version.d.cts +13 -0
  103. package/dist/internal/persistence/sqlite-cas.d.cts +25 -0
  104. package/dist/internal/persistence/sqlite-cas.d.ts +25 -0
  105. package/dist/internal/persistence/sqlite-wal.d.cts +10 -0
  106. package/dist/internal/plugins/context.d.cts +31 -0
  107. package/dist/internal/plugins/index.cjs +228 -0
  108. package/dist/internal/plugins/index.cjs.map +1 -0
  109. package/dist/internal/plugins/index.d.cts +8 -0
  110. package/dist/internal/plugins/index.d.ts +8 -0
  111. package/dist/internal/plugins/index.js +222 -0
  112. package/dist/internal/plugins/index.js.map +1 -0
  113. package/dist/internal/plugins/lifecycle.d.cts +14 -0
  114. package/dist/internal/plugins/lifecycle.d.ts +14 -0
  115. package/dist/internal/plugins/manager.d.cts +37 -0
  116. package/dist/internal/plugins/types.d.cts +102 -0
  117. package/dist/internal/providers/catalog-loader.d.ts +39 -0
  118. package/dist/internal/runtime/agent-session-store.d.ts +1 -1
  119. package/dist/internal/runtime/agent-session.d.ts +1 -0
  120. package/dist/internal/runtime/budget-tracker.d.ts +73 -0
  121. package/dist/internal/runtime/{context-manager.d.ts → context/context-manager.d.ts} +1 -1
  122. package/dist/internal/runtime/{fixture-events.d.ts → fixtures/fixture-events.d.ts} +1 -1
  123. package/dist/internal/runtime/{fixture-run-base.d.ts → fixtures/fixture-run-base.d.ts} +4 -4
  124. package/dist/internal/runtime/{fixture-scripts.d.ts → fixtures/fixture-scripts.d.ts} +1 -1
  125. package/dist/internal/runtime/local-agent-bootstrap.d.ts +2 -2
  126. package/dist/internal/runtime/local-agent-memory-provider.d.ts +57 -0
  127. package/dist/internal/runtime/memory-path-selector.d.ts +73 -0
  128. package/dist/internal/runtime/memory-provider.d.ts +165 -0
  129. package/dist/internal/runtime/{agent-registry.d.ts → registry/agent-registry-contract.d.ts} +15 -9
  130. package/dist/internal/runtime/registry/agent-registry.d.ts +7 -0
  131. package/dist/internal/runtime/{live-agent-registry.d.ts → registry/live-agent-registry.d.ts} +1 -1
  132. package/dist/internal/runtime/{run-registry.d.ts → registry/run-registry.d.ts} +1 -1
  133. package/dist/internal/runtime/session-types.d.ts +35 -0
  134. package/dist/internal/runtime/system-prompt/sources/skills-provider.d.ts +1 -0
  135. package/dist/internal/runtime/validate-response.d.ts +18 -0
  136. package/dist/internal/security/index.cjs +361 -0
  137. package/dist/internal/security/index.cjs.map +1 -0
  138. package/dist/internal/security/index.d.cts +11 -0
  139. package/dist/internal/security/index.js +350 -0
  140. package/dist/internal/security/index.js.map +1 -0
  141. package/dist/internal/security/path-guard.d.cts +59 -0
  142. package/dist/internal/security/path-guard.d.ts +3 -0
  143. package/dist/internal/security/redact.d.cts +21 -0
  144. package/dist/internal/security/secret-redactor.d.cts +1 -0
  145. package/dist/internal/security/secret-redactor.d.ts +1 -0
  146. package/dist/internal/security/test-reset.d.cts +10 -0
  147. package/dist/internal/security/test-reset.d.ts +10 -0
  148. package/dist/internal/telemetry/adapters/arize.d.ts +2 -0
  149. package/dist/internal/telemetry/adapters/braintrust.d.ts +2 -0
  150. package/dist/internal/telemetry/adapters/datadog.d.ts +2 -0
  151. package/dist/internal/telemetry/adapters/langsmith.d.ts +2 -0
  152. package/dist/internal/telemetry/span-names.d.ts +6 -0
  153. package/dist/internal/telemetry/tracer.d.ts +1 -0
  154. package/dist/internal/workflow/evented-executor.d.ts +42 -0
  155. package/dist/internal/workflow/scheduler.d.ts +23 -0
  156. package/dist/internal/zod/to-json-schema.d.ts +5 -15
  157. package/dist/job-queue.d.ts +28 -0
  158. package/dist/path-safety.cjs +67 -6
  159. package/dist/path-safety.cjs.map +1 -1
  160. package/dist/path-safety.d.cts +15 -0
  161. package/dist/path-safety.d.ts +1 -1
  162. package/dist/path-safety.js +67 -7
  163. package/dist/path-safety.js.map +1 -1
  164. package/dist/permission-engine.d.ts +21 -0
  165. package/dist/provider-catalog.json +702 -0
  166. package/dist/rag/index.cjs +136 -0
  167. package/dist/rag/index.cjs.map +1 -0
  168. package/dist/rag/index.d.cts +11 -0
  169. package/dist/rag/index.d.ts +11 -0
  170. package/dist/rag/index.js +129 -0
  171. package/dist/rag/index.js.map +1 -0
  172. package/dist/rag/reranker.d.cts +26 -0
  173. package/dist/rag/reranker.d.ts +26 -0
  174. package/dist/rag/retriever.d.cts +25 -0
  175. package/dist/rag/retriever.d.ts +25 -0
  176. package/dist/rag/text-splitter.d.cts +12 -0
  177. package/dist/rag/text-splitter.d.ts +12 -0
  178. package/dist/rag/types.d.cts +37 -0
  179. package/dist/rag/types.d.ts +37 -0
  180. package/dist/run-DrwUpFxZ.d.cts +823 -0
  181. package/dist/run-DrwUpFxZ.d.ts +823 -0
  182. package/dist/sandbox/index.cjs +133 -0
  183. package/dist/sandbox/index.cjs.map +1 -0
  184. package/dist/sandbox/index.d.cts +2 -0
  185. package/dist/sandbox/index.d.ts +2 -0
  186. package/dist/sandbox/index.js +128 -0
  187. package/dist/sandbox/index.js.map +1 -0
  188. package/dist/sandbox/local-sandbox.d.cts +17 -0
  189. package/dist/sandbox/local-sandbox.d.ts +17 -0
  190. package/dist/sandbox/types.d.cts +44 -0
  191. package/dist/sandbox/types.d.ts +44 -0
  192. package/dist/server/adapter/express.d.cts +9 -0
  193. package/dist/server/adapter/express.d.ts +9 -0
  194. package/dist/server/adapter/fastify.d.cts +9 -0
  195. package/dist/server/adapter/fastify.d.ts +9 -0
  196. package/dist/server/adapter/hono.d.cts +9 -0
  197. package/dist/server/adapter/hono.d.ts +9 -0
  198. package/dist/server/adapter/index.d.cts +8 -0
  199. package/dist/server/adapter/index.d.ts +8 -0
  200. package/dist/server/adapter/shared-handler.d.cts +9 -0
  201. package/dist/server/adapter/shared-handler.d.ts +9 -0
  202. package/dist/server/adapter/types.d.cts +33 -0
  203. package/dist/server/adapter/types.d.ts +33 -0
  204. package/dist/server/auth/errors.d.cts +53 -0
  205. package/dist/server/auth/errors.d.ts +53 -0
  206. package/dist/server/auth/index.cjs +48 -42
  207. package/dist/server/auth/index.cjs.map +1 -1
  208. package/dist/server/auth/index.d.cts +11 -172
  209. package/dist/server/auth/index.d.ts +11 -172
  210. package/dist/server/auth/index.js +49 -43
  211. package/dist/server/auth/index.js.map +1 -1
  212. package/dist/server/auth/oauth-transaction-store.d.cts +39 -0
  213. package/dist/server/auth/oauth-transaction-store.d.ts +39 -0
  214. package/dist/server/auth/orchestrator.d.cts +8 -0
  215. package/dist/server/auth/orchestrator.d.ts +8 -0
  216. package/dist/server/auth/types.d.cts +91 -0
  217. package/dist/server/auth/types.d.ts +91 -0
  218. package/dist/server/auth/validate-return-to.d.cts +17 -0
  219. package/dist/server/auth/validate-return-to.d.ts +17 -0
  220. package/dist/server/errors-envelope.cjs +409 -0
  221. package/dist/server/errors-envelope.cjs.map +1 -0
  222. package/dist/server/errors-envelope.d.cts +61 -0
  223. package/dist/server/errors-envelope.d.ts +61 -0
  224. package/dist/server/errors-envelope.js +405 -0
  225. package/dist/server/errors-envelope.js.map +1 -0
  226. package/dist/subscription/define-subscription.d.cts +63 -0
  227. package/dist/subscription/define-subscription.d.ts +63 -0
  228. package/dist/subscription/index.cjs +402 -0
  229. package/dist/subscription/index.cjs.map +1 -0
  230. package/dist/subscription/index.d.cts +18 -0
  231. package/dist/subscription/index.d.ts +18 -0
  232. package/dist/subscription/index.js +394 -0
  233. package/dist/subscription/index.js.map +1 -0
  234. package/dist/subscription/internal/adapter-types.d.cts +11 -0
  235. package/dist/subscription/internal/adapter-types.d.ts +11 -0
  236. package/dist/subscription/internal/backpressure.d.cts +24 -0
  237. package/dist/subscription/internal/backpressure.d.ts +24 -0
  238. package/dist/subscription/internal/server-integration.d.cts +17 -0
  239. package/dist/subscription/internal/server-integration.d.ts +17 -0
  240. package/dist/subscription/internal/sse-encoder.d.cts +13 -0
  241. package/dist/subscription/internal/sse-encoder.d.ts +13 -0
  242. package/dist/subscription/internal/sse-parser.d.cts +15 -0
  243. package/dist/subscription/internal/sse-parser.d.ts +15 -0
  244. package/dist/subscription/internal/subscription-runtime.d.cts +9 -0
  245. package/dist/subscription/internal/subscription-runtime.d.ts +9 -0
  246. package/dist/subscription/internal/ws-adapter-node.d.cts +10 -0
  247. package/dist/subscription/internal/ws-adapter-node.d.ts +10 -0
  248. package/dist/subscription/theokit-subscribe.d.cts +41 -0
  249. package/dist/subscription/theokit-subscribe.d.ts +41 -0
  250. package/dist/subscription/types.d.cts +140 -0
  251. package/dist/subscription/types.d.ts +140 -0
  252. package/dist/task-store.cjs +30 -2
  253. package/dist/task-store.cjs.map +1 -1
  254. package/dist/task-store.d.cts +8 -0
  255. package/dist/task-store.js +31 -3
  256. package/dist/task-store.js.map +1 -1
  257. package/dist/types/agent-prims.d.ts +61 -0
  258. package/dist/types/agent.d.ts +48 -53
  259. package/dist/types/conversation.d.ts +20 -8
  260. package/dist/types/index.d.ts +0 -2
  261. package/dist/types/messages-base.d.ts +20 -0
  262. package/dist/types/messages.d.ts +1 -1
  263. package/dist/types/run.d.ts +1 -1
  264. package/dist/types/updates.d.ts +1 -1
  265. package/dist/voice/index.d.ts +7 -0
  266. package/dist/voice/openai-realtime.d.ts +21 -0
  267. package/dist/voice/types.d.ts +35 -0
  268. package/dist/workflow.cjs +179 -88
  269. package/dist/workflow.cjs.map +1 -1
  270. package/dist/workflow.d.cts +97 -0
  271. package/dist/workflow.js +180 -89
  272. package/dist/workflow.js.map +1 -1
  273. package/package.json +126 -25
  274. package/dist/budget.d.ts +0 -48
  275. package/dist/cache.d.ts +0 -74
  276. package/dist/cron-1yxL3K2S.d.cts +0 -221
  277. package/dist/cron-BYVdYzob.d.ts +0 -221
  278. package/dist/handoff.d.ts +0 -55
  279. package/dist/internal/budget/calendar-window.d.ts +0 -19
  280. package/dist/internal/budget/enforcement.d.ts +0 -32
  281. package/dist/internal/budget/ledger.d.ts +0 -25
  282. package/dist/internal/budget/normalize-usage.d.ts +0 -27
  283. package/dist/internal/budget/registry.d.ts +0 -16
  284. package/dist/internal/cache/cosine.d.ts +0 -14
  285. package/dist/internal/cache/embed-helper.d.ts +0 -15
  286. package/dist/internal/cache/key.d.ts +0 -15
  287. package/dist/internal/cache/lookup.d.ts +0 -28
  288. package/dist/internal/cache/store-handler.d.ts +0 -24
  289. package/dist/internal/cache/store-json.d.ts +0 -48
  290. package/dist/internal/cache/store.d.ts +0 -54
  291. package/dist/internal/cache/telemetry.d.ts +0 -20
  292. package/dist/internal/cache/ttl.d.ts +0 -11
  293. package/dist/internal/catalog/fixtures.d.ts +0 -16
  294. package/dist/internal/catalog/local-models.d.ts +0 -24
  295. package/dist/internal/handoff/dispatcher.d.ts +0 -29
  296. package/dist/internal/handoff/registry.d.ts +0 -23
  297. package/dist/internal/handoff/telemetry.d.ts +0 -18
  298. package/dist/internal/handoff/tool-injector.d.ts +0 -34
  299. package/dist/internal/memory/atomic-write.d.ts +0 -7
  300. package/dist/internal/memory/dreaming/diary.d.ts +0 -4
  301. package/dist/internal/memory/dreaming/phases.d.ts +0 -15
  302. package/dist/internal/memory/dreaming/run.d.ts +0 -10
  303. package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +0 -15
  304. package/dist/memory-adapter-helpers.d.ts +0 -28
  305. package/dist/memory.d.ts +0 -123
  306. package/dist/migrate.d.ts +0 -33
  307. package/dist/security.d.ts +0 -67
  308. package/dist/task.d.ts +0 -87
  309. package/dist/theokit.d.ts +0 -84
  310. package/dist/tools/_path-scope.d.ts +0 -8
  311. package/dist/tools/_subprocess.d.ts +0 -28
  312. package/dist/tools/git-diff.d.ts +0 -22
  313. package/dist/tools/index.d.ts +0 -29
  314. package/dist/tools/list-dir.d.ts +0 -26
  315. package/dist/tools/read-file.d.ts +0 -31
  316. package/dist/tools/run-vitest.d.ts +0 -46
  317. package/dist/tools/search-text.d.ts +0 -32
  318. package/dist/tools.cjs +0 -690
  319. package/dist/tools.cjs.map +0 -1
  320. package/dist/tools.js +0 -683
  321. package/dist/tools.js.map +0 -1
  322. package/dist/trajectory-helpers.d.ts +0 -31
  323. package/dist/types/cache.d.ts +0 -76
  324. package/dist/types/handoff.d.ts +0 -135
  325. /package/dist/{internal/cron/run-job.d.ts → agent-helpers.d.ts} +0 -0
  326. /package/dist/internal/{cron/scheduler.d.ts → agent-loop/loop-llm-stream.d.ts} +0 -0
  327. /package/dist/internal/{cron/store.d.ts → agent-loop/tool-executors.d.ts} +0 -0
  328. /package/dist/internal/{cron/validate.d.ts → memory/index-manager-helpers.d.ts} +0 -0
  329. /package/dist/internal/memory/{session-loader.d.ts → storage/session-loader.d.ts} +0 -0
  330. /package/dist/internal/memory/{session-summary-writer.d.ts → storage/session-summary-writer.d.ts} +0 -0
  331. /package/dist/internal/memory/{transcript-store.d.ts → storage/transcript-store.d.ts} +0 -0
  332. /package/dist/internal/memory/{wiki-loader.d.ts → storage/wiki-loader.d.ts} +0 -0
  333. /package/dist/internal/{memory/cwd-mutex.d.ts → persistence/atomic-write.d.cts} +0 -0
  334. /package/dist/internal/runtime/{context-aggregator.d.ts → context/context-aggregator.d.ts} +0 -0
  335. /package/dist/internal/runtime/{context-discovery-runner.d.ts → context/context-discovery-runner.d.ts} +0 -0
  336. /package/dist/internal/runtime/{context-discovery.d.ts → context/context-discovery.d.ts} +0 -0
  337. /package/dist/internal/runtime/{context-frontmatter.d.ts → context/context-frontmatter.d.ts} +0 -0
  338. /package/dist/internal/runtime/{context-import-resolver.d.ts → context/context-import-resolver.d.ts} +0 -0
  339. /package/dist/internal/runtime/{context-loaders.d.ts → context/context-loaders.d.ts} +0 -0
  340. /package/dist/internal/runtime/{context-mdc-parser.d.ts → context/context-mdc-parser.d.ts} +0 -0
  341. /package/dist/internal/runtime/{fixture-responder.d.ts → fixtures/fixture-responder.d.ts} +0 -0
  342. /package/dist/internal/runtime/{fixture-types.d.ts → fixtures/fixture-types.d.ts} +0 -0
  343. /package/dist/internal/runtime/{plugins-manager.d.ts → local-agent-send.d.ts} +0 -0
  344. /package/dist/internal/runtime/{plugin-frontmatter.d.ts → plugins/plugin-frontmatter.d.ts} +0 -0
  345. /package/dist/internal/runtime/{system-prompt/providers/active-memory-provider.d.ts → plugins/plugins-manager.d.ts} +0 -0
  346. /package/dist/internal/runtime/{agent-factory-registry.d.ts → registry/agent-factory-registry.d.ts} +0 -0
  347. /package/dist/internal/runtime/{agent-registry-store.d.ts → registry/agent-registry-store.d.ts} +0 -0
  348. /package/dist/internal/runtime/system-prompt/{providers/base-provider.d.ts → sources/active-memory-provider.d.ts} +0 -0
  349. /package/dist/internal/runtime/system-prompt/{providers/context-provider.d.ts → sources/base-provider.d.ts} +0 -0
  350. /package/dist/internal/runtime/system-prompt/{providers/memory-provider.d.ts → sources/context-provider.d.ts} +0 -0
  351. /package/dist/internal/runtime/system-prompt/{providers/skills-provider.d.ts → sources/memory-provider.d.ts} +0 -0
@@ -0,0 +1,823 @@
1
+ /**
2
+ * Type-leaf — primitives shared between `agent.ts`, `run.ts`, and
3
+ * `messages.ts`. Extracted to break LOW type-only cycles #5 and #7
4
+ * (audit `architecture-output/final_report.md`) per plan
5
+ * arch-review-fixes-2026-06-06 § Phase 4 / T4.1 (D438).
6
+ *
7
+ * Public surface unchanged — `types/agent.ts` re-exports these from this
8
+ * leaf so `import type { ModelSelection, CustomTool } from "@theokit/sdk"`
9
+ * keeps resolving.
10
+ *
11
+ * @public
12
+ */
13
+ /**
14
+ * One slot in a {@link ModelSelection.params} array.
15
+ *
16
+ * @public
17
+ */
18
+ interface ModelParameterValue {
19
+ id: string;
20
+ value: string;
21
+ }
22
+ /**
23
+ * Identifies a model plus optional per-model parameters (e.g. reasoning effort).
24
+ *
25
+ * Use `Theokit.models.list()` to discover valid ids and parameter definitions.
26
+ *
27
+ * @public
28
+ */
29
+ interface ModelSelection {
30
+ id: string;
31
+ params?: ModelParameterValue[];
32
+ }
33
+ /**
34
+ * Local function tool declared per-agent via {@link AgentOptions.tools}. The
35
+ * handler runs in-process; no MCP server is involved. The SDK serializes
36
+ * `name`, `description`, and `inputSchema` into the model's tool catalog.
37
+ *
38
+ * Handlers MUST be re-passed on `Agent.resume()` because closures cannot be
39
+ * persisted. The tool catalog (name + description + schema) is NOT serialized.
40
+ *
41
+ * @public
42
+ */
43
+ interface CustomTool {
44
+ /**
45
+ * Tool name surfaced to the LLM. Must match `^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`
46
+ * and must not collide with `shell`, `memory_search`, `memory_get`, or any
47
+ * `mcp_*` prefix (reserved for the SDK's built-in tools).
48
+ */
49
+ name: string;
50
+ /** Description surfaced to the LLM. Required — drives tool-selection accuracy. */
51
+ description: string;
52
+ /** JSON Schema (Draft-7 subset) describing the `input` argument. Must be `type: "object"`. */
53
+ inputSchema: Record<string, unknown>;
54
+ /**
55
+ * Local handler invoked when the model emits `tool_use` for this tool.
56
+ * Returns a string (becomes the `tool_result.content` surfaced back to the
57
+ * model). Throws → SDK converts to `tool_result` with `isError: true` and
58
+ * the error `message` as content.
59
+ */
60
+ handler: (input: Record<string, unknown>) => string | Promise<string>;
61
+ }
62
+
63
+ /**
64
+ * Type-leaf — base message types shared between `conversation.ts` and
65
+ * `updates.ts`. Extracted to break LOW type-only cycle #6 (audit
66
+ * `architecture-output/final_report.md`) per plan arch-review-fixes-2026-06-06
67
+ * § Phase 4 / T4.1 (D438).
68
+ *
69
+ * Public surface unchanged — `types/conversation.ts` re-exports `UserMessage`
70
+ * from this leaf so `import type { UserMessage } from "@theokit/sdk"` keeps
71
+ * resolving.
72
+ *
73
+ * @public
74
+ */
75
+ /**
76
+ * User-authored message in a conversation history.
77
+ *
78
+ * @public
79
+ */
80
+ interface UserMessage {
81
+ text: string;
82
+ }
83
+
84
+ /**
85
+ * Single tool call event. The internal `args` and `result` shapes are NOT stable.
86
+ *
87
+ * @public
88
+ */
89
+ interface ToolCall {
90
+ callId: string;
91
+ name: string;
92
+ args?: unknown;
93
+ result?: unknown;
94
+ }
95
+ /**
96
+ * Incremental text token from the assistant.
97
+ *
98
+ * @public
99
+ */
100
+ interface TextDeltaUpdate {
101
+ type: "text-delta";
102
+ text: string;
103
+ }
104
+ /**
105
+ * Incremental reasoning token.
106
+ *
107
+ * @public
108
+ */
109
+ interface ThinkingDeltaUpdate {
110
+ type: "thinking-delta";
111
+ text: string;
112
+ }
113
+ /**
114
+ * Emitted when a reasoning block completes.
115
+ *
116
+ * @public
117
+ */
118
+ interface ThinkingCompletedUpdate {
119
+ type: "thinking-completed";
120
+ thinkingDurationMs: number;
121
+ }
122
+ /**
123
+ * Tool call started — args committed.
124
+ *
125
+ * @public
126
+ */
127
+ interface ToolCallStartedUpdate {
128
+ type: "tool-call-started";
129
+ callId: string;
130
+ toolCall: ToolCall;
131
+ modelCallId: string;
132
+ }
133
+ /**
134
+ * Tool call arguments streaming in incrementally.
135
+ *
136
+ * @public
137
+ */
138
+ interface PartialToolCallUpdate {
139
+ type: "partial-tool-call";
140
+ callId: string;
141
+ toolCall: ToolCall;
142
+ modelCallId: string;
143
+ }
144
+ /**
145
+ * Tool call completed.
146
+ *
147
+ * @public
148
+ */
149
+ interface ToolCallCompletedUpdate {
150
+ type: "tool-call-completed";
151
+ callId: string;
152
+ toolCall: ToolCall;
153
+ modelCallId: string;
154
+ }
155
+ /**
156
+ * Token count delta for usage tracking.
157
+ *
158
+ * @public
159
+ */
160
+ interface TokenDeltaUpdate {
161
+ type: "token-delta";
162
+ tokens: number;
163
+ }
164
+ /**
165
+ * Conversation step started.
166
+ *
167
+ * @public
168
+ */
169
+ interface StepStartedUpdate {
170
+ type: "step-started";
171
+ stepId: number;
172
+ }
173
+ /**
174
+ * Conversation step completed.
175
+ *
176
+ * @public
177
+ */
178
+ interface StepCompletedUpdate {
179
+ type: "step-completed";
180
+ stepId: number;
181
+ stepDurationMs: number;
182
+ }
183
+ /**
184
+ * Turn ended with usage summary.
185
+ *
186
+ * @public
187
+ */
188
+ interface TurnEndedUpdate {
189
+ type: "turn-ended";
190
+ usage?: {
191
+ inputTokens: number;
192
+ outputTokens: number;
193
+ cacheReadTokens: number;
194
+ cacheWriteTokens: number;
195
+ };
196
+ }
197
+ /**
198
+ * User message appended to the conversation.
199
+ *
200
+ * @public
201
+ */
202
+ interface UserMessageAppendedUpdate {
203
+ type: "user-message-appended";
204
+ userMessage: UserMessage;
205
+ }
206
+ /** @public */
207
+ interface SummaryUpdate {
208
+ type: "summary";
209
+ summary: string;
210
+ }
211
+ /** @public */
212
+ interface SummaryStartedUpdate {
213
+ type: "summary-started";
214
+ }
215
+ /** @public */
216
+ interface SummaryCompletedUpdate {
217
+ type: "summary-completed";
218
+ }
219
+ /** @public */
220
+ interface ShellOutputDeltaUpdate {
221
+ type: "shell-output-delta";
222
+ event: Record<string, unknown>;
223
+ }
224
+ /**
225
+ * Lowest-level raw update from a run. Pass `onDelta` to `agent.send()` to
226
+ * consume these. Finer-grained than `SDKMessage` events.
227
+ *
228
+ * @public
229
+ */
230
+ type InteractionUpdate = TextDeltaUpdate | ThinkingDeltaUpdate | ThinkingCompletedUpdate | ToolCallStartedUpdate | ToolCallCompletedUpdate | PartialToolCallUpdate | TokenDeltaUpdate | StepStartedUpdate | StepCompletedUpdate | TurnEndedUpdate | UserMessageAppendedUpdate | SummaryUpdate | SummaryStartedUpdate | SummaryCompletedUpdate | ShellOutputDeltaUpdate;
231
+
232
+ /**
233
+ * Plain assistant message in a conversation history.
234
+ *
235
+ * @public
236
+ */
237
+ interface AssistantMessage {
238
+ text: string;
239
+ }
240
+ /**
241
+ * Reasoning step in a conversation history.
242
+ *
243
+ * @public
244
+ */
245
+ interface ThinkingMessage {
246
+ text: string;
247
+ thinkingDurationMs?: number;
248
+ }
249
+ /**
250
+ * Shell command executed during a run.
251
+ *
252
+ * @public
253
+ */
254
+ interface ShellCommand {
255
+ command: string;
256
+ workingDirectory?: string;
257
+ }
258
+ /**
259
+ * Output of a shell command.
260
+ *
261
+ * @public
262
+ */
263
+ interface ShellOutput {
264
+ stdout: string;
265
+ stderr: string;
266
+ exitCode: number;
267
+ }
268
+ /**
269
+ * Single step inside an agent turn.
270
+ *
271
+ * @public
272
+ */
273
+ /**
274
+ * Result of a tool invocation. Pairs with the preceding `toolCall` step
275
+ * by `callId`. `isError: true` when the tool returned a failure result.
276
+ *
277
+ * T2.3 — added so `Run.conversation()` surfaces the full interaction
278
+ * including tool results (parity with OpenAI Agents `RunResult.new_items`).
279
+ *
280
+ * @public
281
+ */
282
+ interface ToolResult {
283
+ callId: string;
284
+ name: string;
285
+ result: string;
286
+ isError: boolean;
287
+ }
288
+ type ConversationStep = {
289
+ type: "assistantMessage";
290
+ message: AssistantMessage;
291
+ } | {
292
+ type: "toolCall";
293
+ message: ToolCall;
294
+ } | {
295
+ type: "toolResult";
296
+ message: ToolResult;
297
+ } | {
298
+ type: "thinkingMessage";
299
+ message: ThinkingMessage;
300
+ };
301
+ /**
302
+ * Agent turn: user message + assistant/tool/thinking steps.
303
+ *
304
+ * @public
305
+ */
306
+ interface AgentConversationTurn {
307
+ userMessage?: UserMessage;
308
+ steps: ConversationStep[];
309
+ }
310
+ /**
311
+ * Shell turn: a command and its output.
312
+ *
313
+ * @public
314
+ */
315
+ interface ShellConversationTurn {
316
+ shellCommand?: ShellCommand;
317
+ shellOutput?: ShellOutput;
318
+ }
319
+ /**
320
+ * Structured per-turn view of a run.
321
+ *
322
+ * @public
323
+ */
324
+ type ConversationTurn = {
325
+ type: "agentConversationTurn";
326
+ turn: AgentConversationTurn;
327
+ } | {
328
+ type: "shellConversationTurn";
329
+ turn: ShellConversationTurn;
330
+ };
331
+
332
+ /**
333
+ * MCP server configuration accepted by `Agent.create()` and `agent.send()`.
334
+ *
335
+ * @public
336
+ */
337
+ type McpStdioServerConfig = {
338
+ type?: "stdio";
339
+ command: string;
340
+ args?: string[];
341
+ env?: Record<string, string>;
342
+ /** Local agents only. Cloud rejects this field. */
343
+ cwd?: string;
344
+ };
345
+ /**
346
+ * OAuth-style auth bundle for HTTP/SSE MCP servers.
347
+ *
348
+ * @public
349
+ */
350
+ interface McpAuthConfig {
351
+ CLIENT_ID: string;
352
+ CLIENT_SECRET?: string;
353
+ scopes?: string[];
354
+ /**
355
+ * OAuth 2.1 PKCE flow configuration (ADR D41, v1.2+). When present, the
356
+ * SDK runs the PKCE flow on first use and stores tokens via keychain or
357
+ * file. Without this, the SDK relies on `CLIENT_SECRET` + manual headers.
358
+ */
359
+ oauth?: McpOAuthConfig;
360
+ }
361
+ /**
362
+ * OAuth 2.1 PKCE flow descriptor. See ADR D41.
363
+ *
364
+ * @public
365
+ */
366
+ interface McpOAuthConfig {
367
+ /** Authorization endpoint (e.g. https://api.notion.com/v1/oauth/authorize). */
368
+ authorizationEndpoint: string;
369
+ /** Token endpoint (e.g. https://api.notion.com/v1/oauth/token). */
370
+ tokenEndpoint: string;
371
+ /** Where the OAuth `code` is received. */
372
+ redirectMode: "manual" | "localhost";
373
+ /** Localhost callback port (0 = random free port, default). */
374
+ localhostPort?: number;
375
+ /** Flow timeout in ms (default 300_000 = 5min). */
376
+ timeoutMs?: number;
377
+ }
378
+ /**
379
+ * HTTP or SSE MCP server.
380
+ *
381
+ * @public
382
+ */
383
+ type McpHttpServerConfig = {
384
+ type?: "http" | "sse";
385
+ url: string;
386
+ /** Passed through. `Authorization` works here. */
387
+ headers?: Record<string, string>;
388
+ auth?: McpAuthConfig;
389
+ };
390
+ /**
391
+ * Union of MCP server configs. See `docs.md` for the full reference.
392
+ *
393
+ * @public
394
+ */
395
+ type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;
396
+
397
+ /**
398
+ * Plain text content block emitted by the assistant or user.
399
+ *
400
+ * @public
401
+ */
402
+ interface TextBlock {
403
+ type: "text";
404
+ text: string;
405
+ }
406
+ /**
407
+ * Tool invocation block emitted by the assistant.
408
+ *
409
+ * @public
410
+ */
411
+ interface ToolUseBlock {
412
+ type: "tool_use";
413
+ id: string;
414
+ name: string;
415
+ /** Tool args are not part of the stable schema. Treat as unknown and parse defensively. */
416
+ input: unknown;
417
+ }
418
+ /**
419
+ * Init metadata. Emitted once at the start of a run.
420
+ *
421
+ * @public
422
+ */
423
+ interface SDKSystemMessage {
424
+ type: "system";
425
+ subtype?: "init";
426
+ agent_id: string;
427
+ run_id: string;
428
+ model?: ModelSelection;
429
+ tools?: string[];
430
+ }
431
+ /**
432
+ * Echo of the user prompt for this run.
433
+ *
434
+ * @public
435
+ */
436
+ interface SDKUserMessageEvent {
437
+ type: "user";
438
+ agent_id: string;
439
+ run_id: string;
440
+ message: {
441
+ role: "user";
442
+ content: TextBlock[];
443
+ };
444
+ }
445
+ /**
446
+ * Model text output for this run.
447
+ *
448
+ * @public
449
+ */
450
+ interface SDKAssistantMessage {
451
+ type: "assistant";
452
+ agent_id: string;
453
+ run_id: string;
454
+ message: {
455
+ role: "assistant";
456
+ content: Array<TextBlock | ToolUseBlock>;
457
+ };
458
+ }
459
+ /**
460
+ * Reasoning content.
461
+ *
462
+ * @public
463
+ */
464
+ interface SDKThinkingMessage {
465
+ type: "thinking";
466
+ agent_id: string;
467
+ run_id: string;
468
+ text: string;
469
+ thinking_duration_ms?: number;
470
+ }
471
+ /**
472
+ * Tool invocation lifecycle event. Emitted at start with `args`, then again on
473
+ * completion with `result`.
474
+ *
475
+ * Tool `args` and `result` are NOT part of the stable schema — treat as unknown.
476
+ *
477
+ * @public
478
+ */
479
+ interface SDKToolUseMessage {
480
+ type: "tool_call";
481
+ agent_id: string;
482
+ run_id: string;
483
+ call_id: string;
484
+ name: string;
485
+ status: "running" | "completed" | "error";
486
+ args?: unknown;
487
+ result?: unknown;
488
+ truncated?: {
489
+ args?: boolean;
490
+ result?: boolean;
491
+ };
492
+ }
493
+ /**
494
+ * Cloud run lifecycle transitions.
495
+ *
496
+ * @public
497
+ */
498
+ interface SDKStatusMessage {
499
+ type: "status";
500
+ agent_id: string;
501
+ run_id: string;
502
+ status: "CREATING" | "RUNNING" | "FINISHED" | "ERROR" | "CANCELLED" | "EXPIRED";
503
+ message?: string;
504
+ }
505
+ /**
506
+ * Task-level milestones and summaries.
507
+ *
508
+ * @public
509
+ */
510
+ interface SDKTaskMessage {
511
+ type: "task";
512
+ agent_id: string;
513
+ run_id: string;
514
+ status?: string;
515
+ text?: string;
516
+ }
517
+ /**
518
+ * Awaiting user input or approval.
519
+ *
520
+ * @public
521
+ */
522
+ interface SDKRequestMessage {
523
+ type: "request";
524
+ agent_id: string;
525
+ run_id: string;
526
+ request_id: string;
527
+ }
528
+ /**
529
+ * Partial object emitted during `Agent.streamObject<T>` streaming (ADR D45).
530
+ * `partial` is `DeepPartial<z.infer<T>>` at the typed iterator level but
531
+ * erased to `unknown` here because SDKMessage union is non-generic.
532
+ *
533
+ * @public
534
+ */
535
+ interface SDKObjectDelta {
536
+ type: "object_delta";
537
+ agent_id: string;
538
+ run_id: string;
539
+ partial: unknown;
540
+ attempt: number;
541
+ }
542
+ /**
543
+ * Discriminated union of all stream events. Discriminate on `type`.
544
+ *
545
+ * All events include `agent_id` and `run_id`.
546
+ *
547
+ * @public
548
+ */
549
+ type SDKMessage = SDKSystemMessage | SDKUserMessageEvent | SDKAssistantMessage | SDKThinkingMessage | SDKToolUseMessage | SDKStatusMessage | SDKTaskMessage | SDKRequestMessage | SDKObjectDelta;
550
+
551
+ /**
552
+ * Public type contract for token usage + cost tracking (ADRs D376-D379).
553
+ *
554
+ * Surfaces via `RunResult.usage` + `RunResult.cost` after every Run.
555
+ * Re-exported through the package barrel; consumers import from
556
+ * `@theokit/sdk`.
557
+ *
558
+ * @public
559
+ */
560
+ /**
561
+ * Token usage observed during a Run. 5 closed buckets (D376) cover
562
+ * 100% of providers in 2026: OpenAI Chat / OpenAI Responses (o-series
563
+ * with reasoning) / Anthropic Messages (with prompt caching).
564
+ *
565
+ * `totalTokens` is derived (`inputTokens + outputTokens`); EC-10
566
+ * invariant: SDK must never emit `totalTokens !== inputTokens + outputTokens`.
567
+ *
568
+ * `requests[]` is the per-request breakdown (mirror openai-agents-python)
569
+ * — populated only when the run made > 1 LLM call.
570
+ */
571
+ interface TokenUsage {
572
+ readonly inputTokens: number;
573
+ readonly outputTokens: number;
574
+ readonly cacheReadTokens?: number;
575
+ readonly cacheWriteTokens?: number;
576
+ readonly reasoningTokens?: number;
577
+ readonly totalTokens: number;
578
+ /** Per-request breakdown; absent when the run made a single LLM call. */
579
+ readonly requests?: ReadonlyArray<Omit<TokenUsage, "requests">>;
580
+ }
581
+ /**
582
+ * Cost confidence level (D377).
583
+ * - `actual`: returned by a provider billing API (e.g. OpenRouter `/generation`).
584
+ * - `estimated`: computed from bundled pricing snapshot.
585
+ * - `included`: subscription-included route (Codex CLI, Claude Pro).
586
+ * - `unknown`: pricing data unavailable; `amountUsd` is undefined.
587
+ */
588
+ type CostStatus = "actual" | "estimated" | "included" | "unknown";
589
+ /** Source of the cost figure for caller-side audit. */
590
+ type CostSource = "openrouter_api" | "litellm_snapshot" | "user_override" | "subscription_included" | "unknown";
591
+ /**
592
+ * Cost breakdown attached to `RunResult.cost`. When `status === "unknown"`,
593
+ * `amountUsd` is `undefined` — DO NOT default to 0 (mentira). UI exibe
594
+ * `n/a` para unknown, `~$1.23` para estimated, `$1.23` para actual.
595
+ */
596
+ interface CostBreakdown {
597
+ readonly amountUsd: number | undefined;
598
+ readonly status: CostStatus;
599
+ readonly currency: "USD";
600
+ readonly source: CostSource;
601
+ readonly pricingVersion: string | undefined;
602
+ readonly notes?: ReadonlyArray<string>;
603
+ /** Per-bucket detail (in USD) for caller analytics. */
604
+ readonly detail?: {
605
+ readonly input?: number;
606
+ readonly output?: number;
607
+ readonly cacheRead?: number;
608
+ readonly cacheWrite?: number;
609
+ readonly reasoning?: number;
610
+ };
611
+ }
612
+
613
+ /**
614
+ * Lifecycle status of a {@link Run}.
615
+ *
616
+ * @public
617
+ */
618
+ type RunStatus = "running" | "finished" | "error" | "cancelled";
619
+ /**
620
+ * Operations that may or may not be supported on a given {@link Run}, or on
621
+ * its parent agent.
622
+ *
623
+ * Runtime-specific availability — query at runtime with `run.supports(op)` and
624
+ * read the human reason via `run.unsupportedReason(op)`.
625
+ *
626
+ * @public
627
+ */
628
+ type RunOperation = "stream" | "wait" | "cancel" | "conversation" | "listArtifacts" | "downloadArtifact" | "runUntil" | "fork" | "usePersonality" | "workflow";
629
+ /**
630
+ * Git metadata attached to cloud runs.
631
+ *
632
+ * @public
633
+ */
634
+ interface RunGitInfo {
635
+ branches: Array<{
636
+ repoUrl: string;
637
+ branch?: string;
638
+ prUrl?: string;
639
+ }>;
640
+ }
641
+ /**
642
+ * Terminal result of a {@link Run}.
643
+ *
644
+ * @public
645
+ */
646
+ interface RunResult {
647
+ id: string;
648
+ status: "finished" | "error" | "cancelled";
649
+ result?: string;
650
+ model?: ModelSelection;
651
+ durationMs?: number;
652
+ git?: RunGitInfo;
653
+ /**
654
+ * Structured error detail, populated when `status === "error"`. Surfaces
655
+ * the diagnostic that emit-error-event pushes into the stream so callers
656
+ * that don't drain `run.stream()` still get the cause via `run.wait()`.
657
+ *
658
+ * For successful runs (`status: "finished"`) this is undefined.
659
+ *
660
+ * @public
661
+ */
662
+ error?: RunErrorDetail;
663
+ /**
664
+ * Token usage observed for this run (ADR D376). Populated in every
665
+ * status where ≥1 LLM call completed — including partial-failure
666
+ * runs (EC-5). `undefined` only when zero LLM calls executed (e.g.,
667
+ * abort before send).
668
+ *
669
+ * @public
670
+ */
671
+ usage?: TokenUsage;
672
+ /**
673
+ * Estimated/actual USD cost for this run (ADR D377). Always paired
674
+ * with `usage` when populated. `cost.status` tells caller how to
675
+ * trust the figure.
676
+ *
677
+ * @public
678
+ */
679
+ cost?: CostBreakdown;
680
+ }
681
+ /**
682
+ * Structured error attached to a {@link RunResult} when the underlying run
683
+ * transitioned to `"error"` status. `message` is always present; `code` is
684
+ * a stable identifier suitable for branching (e.g. `"llm_4xx"`,
685
+ * `"tool_dispatch_failed"`, `"mcp_init_failed"`); `cause` is the raw error
686
+ * for further inspection when available.
687
+ *
688
+ * @public
689
+ */
690
+ interface RunErrorDetail {
691
+ message: string;
692
+ code?: string;
693
+ cause?: unknown;
694
+ }
695
+ /**
696
+ * Dimensions of an inline image attachment.
697
+ *
698
+ * @public
699
+ */
700
+ interface SDKImageDimension {
701
+ width: number;
702
+ height: number;
703
+ }
704
+ /**
705
+ * Either a remote URL or inline base64 payload.
706
+ *
707
+ * @public
708
+ */
709
+ type SDKImage = {
710
+ url: string;
711
+ dimension?: SDKImageDimension;
712
+ } | {
713
+ data: string;
714
+ mimeType: string;
715
+ dimension?: SDKImageDimension;
716
+ };
717
+ /**
718
+ * Structured form of `agent.send()`'s message argument. Use it to send images
719
+ * alongside text.
720
+ *
721
+ * @public
722
+ */
723
+ interface SDKUserMessage {
724
+ text: string;
725
+ images?: SDKImage[];
726
+ }
727
+ /**
728
+ * Per-send overrides and callbacks.
729
+ *
730
+ * @public
731
+ */
732
+ interface SendOptions {
733
+ model?: ModelSelection;
734
+ /**
735
+ * Per-call system prompt override. Wins over `AgentOptions.systemPrompt`.
736
+ * String only — for dynamic resolvers, configure on `AgentOptions`. An
737
+ * empty string is honoured (it explicitly clears the system context).
738
+ */
739
+ systemPrompt?: string;
740
+ /** Fully replaces creation-time servers for this run (not merged). */
741
+ mcpServers?: Record<string, McpServerConfig>;
742
+ /**
743
+ * Per-call inline custom tools. Fully replaces `AgentOptions.tools` for
744
+ * this run (not merged). Local runtime only — cloud agents reject any
745
+ * non-empty per-call tools array with the same error code as creation
746
+ * (`cloud_custom_tools_rejected`). Semantics:
747
+ * - `undefined` → fall back to `AgentOptions.tools`
748
+ * - `[]` → explicitly clear (no custom tools for this run)
749
+ * - `[t1, t2]` → use exactly these tools for this run
750
+ */
751
+ tools?: CustomTool[];
752
+ onStep?: (args: {
753
+ step: ConversationStep;
754
+ }) => void | Promise<void>;
755
+ onDelta?: (args: {
756
+ update: InteractionUpdate;
757
+ }) => void | Promise<void>;
758
+ /** Local agents only. Expire a stuck active run before starting this message. */
759
+ local?: {
760
+ force?: boolean;
761
+ };
762
+ /**
763
+ * Optional `AbortSignal` propagated to memory adapter `pre_user_send`
764
+ * hooks (EC-H). Note: the LLM HTTP call itself is NOT cancellable
765
+ * mid-stream — same constraint as `Agent.batch` (ADR D140).
766
+ *
767
+ * @public
768
+ */
769
+ signal?: AbortSignal;
770
+ /**
771
+ * Opt-in task wrapping (ADRs D363, D374). When truthy, the entire
772
+ * run is registered as a `Task` in the SDK's observable registry —
773
+ * caller can list / inspect / cancel / subscribe via the `Task`
774
+ * namespace. Default behavior (no `task` option) is byte-identical
775
+ * to v1.1 (no Task overhead).
776
+ *
777
+ * Accepts:
778
+ * - `true` — auto-generate task id; no extra metadata.
779
+ * - `{ id, meta }` — user-supplied id (D368 grammar enforced) and/or
780
+ * metadata attached to the handle's `meta` field.
781
+ *
782
+ * The work-fn `signal` is **merged** with `options.signal` (whichever
783
+ * aborts first wins). Local agents only — CloudAgent throws
784
+ * `UnsupportedTaskOperationError` (D370).
785
+ *
786
+ * @public
787
+ */
788
+ task?: true | {
789
+ id?: string;
790
+ meta?: Record<string, unknown>;
791
+ };
792
+ }
793
+ /**
794
+ * Handle to a single prompt submission.
795
+ *
796
+ * @public
797
+ */
798
+ interface Run {
799
+ readonly id: string;
800
+ readonly agentId: string;
801
+ readonly status: RunStatus;
802
+ readonly result?: string;
803
+ readonly model?: ModelSelection;
804
+ readonly durationMs?: number;
805
+ readonly git?: RunGitInfo;
806
+ readonly createdAt?: number;
807
+ /** AsyncGenerator of normalized stream events. Discriminate on `event.type`. */
808
+ stream(): AsyncGenerator<SDKMessage, void>;
809
+ /** Resolves to the terminal {@link RunResult}. */
810
+ wait(): Promise<RunResult>;
811
+ /** Move status to `"cancelled"`, abort the stream, stop in-flight tool calls. */
812
+ cancel(): Promise<void>;
813
+ /** Structured per-turn view of the conversation. */
814
+ conversation(): Promise<ConversationTurn[]>;
815
+ /** Whether the given operation is available on this run's runtime. */
816
+ supports(operation: RunOperation): boolean;
817
+ /** Human-readable reason that `supports(operation)` returned `false`. */
818
+ unsupportedReason(operation: RunOperation): string | undefined;
819
+ /** Subscribe to status changes. Returns an unsubscribe function. */
820
+ onDidChangeStatus(listener: (status: RunStatus) => void): () => void;
821
+ }
822
+
823
+ export type { ToolCall as $, AgentConversationTurn as A, SDKToolUseMessage as B, CustomTool as C, SDKUserMessage as D, SDKUserMessageEvent as E, SendOptions as F, ShellCommand as G, ShellConversationTurn as H, InteractionUpdate as I, ShellOutput as J, ShellOutputDeltaUpdate as K, StepCompletedUpdate as L, ModelSelection as M, StepStartedUpdate as N, SummaryCompletedUpdate as O, PartialToolCallUpdate as P, SummaryStartedUpdate as Q, RunResult as R, SDKMessage as S, SummaryUpdate as T, TextBlock as U, TextDeltaUpdate as V, ThinkingCompletedUpdate as W, ThinkingDeltaUpdate as X, ThinkingMessage as Y, TokenDeltaUpdate as Z, TokenUsage as _, McpServerConfig as a, ToolCallCompletedUpdate as a0, ToolCallStartedUpdate as a1, ToolResult as a2, ToolUseBlock as a3, TurnEndedUpdate as a4, UserMessage as a5, UserMessageAppendedUpdate as a6, Run as b, AssistantMessage as c, ConversationStep as d, ConversationTurn as e, CostBreakdown as f, CostSource as g, CostStatus as h, McpAuthConfig as i, McpHttpServerConfig as j, McpOAuthConfig as k, McpStdioServerConfig as l, ModelParameterValue as m, RunErrorDetail as n, RunGitInfo as o, RunOperation as p, RunStatus as q, SDKAssistantMessage as r, SDKImage as s, SDKImageDimension as t, SDKObjectDelta as u, SDKRequestMessage as v, SDKStatusMessage as w, SDKSystemMessage as x, SDKTaskMessage as y, SDKThinkingMessage as z };