@theokit/sdk 1.6.2 → 1.8.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 (371) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/bin/init-claude.mjs +34 -0
  3. package/claude-template/AGENTS.md +139 -0
  4. package/claude-template/CLAUDE.md +51 -0
  5. package/claude-template/dot-claude/rules/theokit-conventions.md +33 -0
  6. package/claude-template/dot-claude/settings.json +16 -0
  7. package/claude-template/dot-claude/skills/theokit-agent-core/SKILL.md +209 -0
  8. package/claude-template/dot-claude/skills/theokit-budget/SKILL.md +176 -0
  9. package/claude-template/dot-claude/skills/theokit-config/SKILL.md +139 -0
  10. package/claude-template/dot-claude/skills/theokit-cron/SKILL.md +148 -0
  11. package/claude-template/dot-claude/skills/theokit-di/SKILL.md +233 -0
  12. package/claude-template/dot-claude/skills/theokit-di-agent/SKILL.md +294 -0
  13. package/claude-template/dot-claude/skills/theokit-errors/SKILL.md +172 -0
  14. package/claude-template/dot-claude/skills/theokit-eval/SKILL.md +144 -0
  15. package/claude-template/dot-claude/skills/theokit-gateways/SKILL.md +209 -0
  16. package/claude-template/dot-claude/skills/theokit-memory/SKILL.md +176 -0
  17. package/claude-template/dot-claude/skills/theokit-rag/SKILL.md +226 -0
  18. package/claude-template/dot-claude/skills/theokit-streaming/SKILL.md +156 -0
  19. package/claude-template/dot-claude/skills/theokit-subscriptions/SKILL.md +148 -0
  20. package/claude-template/dot-claude/skills/theokit-tools/SKILL.md +170 -0
  21. package/claude-template/dot-claude/skills/theokit-workflows/SKILL.md +218 -0
  22. package/dist/a2a/agent-mailbox.d.cts +27 -0
  23. package/dist/a2a/agent-mailbox.d.ts +27 -0
  24. package/dist/a2a/index.cjs +16850 -0
  25. package/dist/a2a/index.cjs.map +1 -0
  26. package/dist/a2a/index.d.cts +9 -0
  27. package/dist/a2a/index.d.ts +9 -0
  28. package/dist/a2a/index.js +16844 -0
  29. package/dist/a2a/index.js.map +1 -0
  30. package/dist/a2a/message-bus.d.cts +27 -0
  31. package/dist/a2a/message-bus.d.ts +27 -0
  32. package/dist/a2a/subagent.d.cts +25 -0
  33. package/dist/a2a/subagent.d.ts +25 -0
  34. package/dist/a2a/types.d.cts +12 -0
  35. package/dist/a2a/types.d.ts +12 -0
  36. package/dist/agent.d.ts +1 -1
  37. package/dist/client/index.cjs +73 -0
  38. package/dist/client/index.cjs.map +1 -0
  39. package/dist/client/index.d.cts +7 -0
  40. package/dist/client/index.d.ts +7 -0
  41. package/dist/client/index.js +71 -0
  42. package/dist/client/index.js.map +1 -0
  43. package/dist/client/theokit-client.d.cts +18 -0
  44. package/dist/client/theokit-client.d.ts +18 -0
  45. package/dist/client/types.d.cts +19 -0
  46. package/dist/client/types.d.ts +19 -0
  47. package/dist/{run-DkCD5DeO.d.cts → cron-BnywDYLq.d.cts} +496 -910
  48. package/dist/{run-DkCD5DeO.d.ts → cron-CtZvJD9J.d.ts} +496 -910
  49. package/dist/cron.cjs +4285 -2893
  50. package/dist/cron.cjs.map +1 -1
  51. package/dist/cron.d.cts +2 -3
  52. package/dist/cron.d.ts +2 -71
  53. package/dist/cron.js +4289 -2897
  54. package/dist/cron.js.map +1 -1
  55. package/dist/{errors-CvAeEWgE.d.ts → errors-ChqOmFH1.d.cts} +52 -6
  56. package/dist/{errors-CK8brCJ1.d.cts → errors-DV9e0rcp.d.ts} +52 -6
  57. package/dist/errors.cjs +218 -3
  58. package/dist/errors.cjs.map +1 -1
  59. package/dist/errors.d.cts +2 -3
  60. package/dist/errors.d.ts +50 -4
  61. package/dist/errors.js +217 -4
  62. package/dist/errors.js.map +1 -1
  63. package/dist/eval.cjs +4285 -2893
  64. package/dist/eval.cjs.map +1 -1
  65. package/dist/eval.d.cts +35 -0
  66. package/dist/eval.js +4289 -2897
  67. package/dist/eval.js.map +1 -1
  68. package/dist/event-bus.d.ts +23 -0
  69. package/dist/index.cjs +5132 -4200
  70. package/dist/index.cjs.map +1 -1
  71. package/dist/index.d.cts +298 -278
  72. package/dist/index.d.ts +1898 -24
  73. package/dist/index.js +6441 -5509
  74. package/dist/index.js.map +1 -1
  75. package/dist/internal/agent-loop/loop-context-init.d.ts +2 -0
  76. package/dist/internal/agent-loop/tool-dispatch.d.ts +22 -1
  77. package/dist/internal/auth/api-key-validator.d.ts +46 -0
  78. package/dist/internal/llm/anthropic-shared.d.ts +8 -1
  79. package/dist/internal/llm/retry.d.ts +22 -0
  80. package/dist/internal/llm/types.d.ts +47 -1
  81. package/dist/internal/memory/active-memory-cache.d.ts +3 -3
  82. package/dist/internal/memory/active-memory-types.d.ts +8 -0
  83. package/dist/internal/memory/active-memory.d.ts +24 -20
  84. package/dist/internal/memory/adapters/azure-openai-embedding.d.ts +2 -0
  85. package/dist/internal/memory/adapters/cohere-embedding.d.ts +2 -0
  86. package/dist/internal/memory/adapters/gemini-embedding.d.ts +2 -0
  87. package/dist/internal/memory/adapters/jina-embedding.d.ts +2 -0
  88. package/dist/internal/memory/index-manager-contract.d.ts +26 -0
  89. package/dist/internal/memory/index-manager-dispatch.d.ts +1 -1
  90. package/dist/internal/memory/index-manager.d.ts +8 -26
  91. package/dist/internal/memory/{chunk-markdown.d.ts → storage/chunk-markdown.d.ts} +1 -1
  92. package/dist/internal/memory/{markdown-store.d.ts → storage/markdown-store.d.ts} +1 -1
  93. package/dist/internal/memory/{reader.d.ts → storage/reader.d.ts} +1 -1
  94. package/dist/internal/observability/context.d.cts +23 -0
  95. package/dist/internal/observability/context.d.ts +23 -0
  96. package/dist/internal/observability/index.cjs +38 -0
  97. package/dist/internal/observability/index.cjs.map +1 -0
  98. package/dist/internal/observability/index.d.cts +8 -0
  99. package/dist/internal/observability/index.d.ts +8 -0
  100. package/dist/internal/observability/index.js +33 -0
  101. package/dist/internal/observability/index.js.map +1 -0
  102. package/dist/internal/observability/tracer-loader.d.cts +20 -0
  103. package/dist/internal/persistence/conversation-storage-fs.d.cts +37 -0
  104. package/dist/internal/persistence/conversation-storage-memory.d.cts +24 -0
  105. package/dist/internal/persistence/credential-pool-store.d.cts +32 -0
  106. package/dist/internal/persistence/credential-pool-store.d.ts +32 -0
  107. package/dist/internal/persistence/cwd-mutex.d.cts +1 -0
  108. package/dist/internal/persistence/exclusive-create.d.cts +22 -0
  109. package/dist/internal/persistence/exclusive-create.d.ts +22 -0
  110. package/dist/internal/persistence/file-lock.d.cts +14 -0
  111. package/dist/internal/persistence/fts5-sanitize.d.cts +16 -0
  112. package/dist/internal/persistence/index.cjs +359 -0
  113. package/dist/internal/persistence/index.cjs.map +1 -0
  114. package/dist/internal/persistence/index.d.cts +20 -0
  115. package/dist/internal/persistence/index.d.ts +20 -0
  116. package/dist/internal/persistence/index.js +341 -0
  117. package/dist/internal/persistence/index.js.map +1 -0
  118. package/dist/internal/persistence/markdown-config-loader.d.cts +35 -0
  119. package/dist/internal/persistence/paths.d.cts +19 -0
  120. package/dist/internal/persistence/persistence-schema.d.cts +21 -0
  121. package/dist/internal/persistence/persistence-schema.d.ts +4 -0
  122. package/dist/internal/persistence/schema-version.d.cts +13 -0
  123. package/dist/internal/persistence/sqlite-cas.d.cts +25 -0
  124. package/dist/internal/persistence/sqlite-cas.d.ts +25 -0
  125. package/dist/internal/persistence/sqlite-wal.d.cts +10 -0
  126. package/dist/internal/plugins/context.d.cts +31 -0
  127. package/dist/internal/plugins/index.cjs +228 -0
  128. package/dist/internal/plugins/index.cjs.map +1 -0
  129. package/dist/internal/plugins/index.d.cts +8 -0
  130. package/dist/internal/plugins/index.d.ts +8 -0
  131. package/dist/internal/plugins/index.js +222 -0
  132. package/dist/internal/plugins/index.js.map +1 -0
  133. package/dist/internal/plugins/lifecycle.d.cts +14 -0
  134. package/dist/internal/plugins/lifecycle.d.ts +14 -0
  135. package/dist/internal/plugins/manager.d.cts +37 -0
  136. package/dist/internal/plugins/types.d.cts +102 -0
  137. package/dist/internal/providers/catalog-loader.d.ts +39 -0
  138. package/dist/internal/runtime/agent-session-store.d.ts +1 -1
  139. package/dist/internal/runtime/agent-session.d.ts +1 -0
  140. package/dist/internal/runtime/budget-tracker.d.ts +73 -0
  141. package/dist/internal/runtime/{context-manager.d.ts → context/context-manager.d.ts} +1 -1
  142. package/dist/internal/runtime/{fixture-events.d.ts → fixtures/fixture-events.d.ts} +1 -1
  143. package/dist/internal/runtime/{fixture-run-base.d.ts → fixtures/fixture-run-base.d.ts} +4 -4
  144. package/dist/internal/runtime/{fixture-scripts.d.ts → fixtures/fixture-scripts.d.ts} +1 -1
  145. package/dist/internal/runtime/local-agent-bootstrap.d.ts +2 -2
  146. package/dist/internal/runtime/local-agent-memory-provider.d.ts +57 -0
  147. package/dist/internal/runtime/memory-path-selector.d.ts +73 -0
  148. package/dist/internal/runtime/memory-provider.d.ts +165 -0
  149. package/dist/internal/runtime/{agent-registry.d.ts → registry/agent-registry-contract.d.ts} +15 -9
  150. package/dist/internal/runtime/registry/agent-registry.d.ts +7 -0
  151. package/dist/internal/runtime/{live-agent-registry.d.ts → registry/live-agent-registry.d.ts} +1 -1
  152. package/dist/internal/runtime/{run-registry.d.ts → registry/run-registry.d.ts} +1 -1
  153. package/dist/internal/runtime/session-types.d.ts +35 -0
  154. package/dist/internal/runtime/system-prompt/sources/skills-provider.d.ts +1 -0
  155. package/dist/internal/runtime/validate-response.d.ts +18 -0
  156. package/dist/internal/security/index.cjs +361 -0
  157. package/dist/internal/security/index.cjs.map +1 -0
  158. package/dist/internal/security/index.d.cts +11 -0
  159. package/dist/internal/security/index.js +350 -0
  160. package/dist/internal/security/index.js.map +1 -0
  161. package/dist/internal/security/path-guard.d.cts +59 -0
  162. package/dist/internal/security/path-guard.d.ts +3 -0
  163. package/dist/internal/security/redact.d.cts +21 -0
  164. package/dist/internal/security/secret-redactor.d.cts +1 -0
  165. package/dist/internal/security/secret-redactor.d.ts +1 -0
  166. package/dist/internal/security/test-reset.d.cts +10 -0
  167. package/dist/internal/security/test-reset.d.ts +10 -0
  168. package/dist/internal/telemetry/adapters/arize.d.ts +2 -0
  169. package/dist/internal/telemetry/adapters/braintrust.d.ts +2 -0
  170. package/dist/internal/telemetry/adapters/datadog.d.ts +2 -0
  171. package/dist/internal/telemetry/adapters/langsmith.d.ts +2 -0
  172. package/dist/internal/telemetry/span-names.d.ts +6 -0
  173. package/dist/internal/telemetry/tracer.d.ts +1 -0
  174. package/dist/internal/workflow/evented-executor.d.ts +42 -0
  175. package/dist/internal/workflow/scheduler.d.ts +23 -0
  176. package/dist/internal/zod/to-json-schema.d.ts +5 -15
  177. package/dist/job-queue.d.ts +28 -0
  178. package/dist/path-safety.cjs +67 -6
  179. package/dist/path-safety.cjs.map +1 -1
  180. package/dist/path-safety.d.cts +15 -0
  181. package/dist/path-safety.d.ts +1 -1
  182. package/dist/path-safety.js +67 -7
  183. package/dist/path-safety.js.map +1 -1
  184. package/dist/permission-engine.d.ts +21 -0
  185. package/dist/provider-catalog.json +702 -0
  186. package/dist/rag/index.cjs +136 -0
  187. package/dist/rag/index.cjs.map +1 -0
  188. package/dist/rag/index.d.cts +11 -0
  189. package/dist/rag/index.d.ts +11 -0
  190. package/dist/rag/index.js +129 -0
  191. package/dist/rag/index.js.map +1 -0
  192. package/dist/rag/reranker.d.cts +26 -0
  193. package/dist/rag/reranker.d.ts +26 -0
  194. package/dist/rag/retriever.d.cts +25 -0
  195. package/dist/rag/retriever.d.ts +25 -0
  196. package/dist/rag/text-splitter.d.cts +12 -0
  197. package/dist/rag/text-splitter.d.ts +12 -0
  198. package/dist/rag/types.d.cts +37 -0
  199. package/dist/rag/types.d.ts +37 -0
  200. package/dist/run-DrwUpFxZ.d.cts +823 -0
  201. package/dist/run-DrwUpFxZ.d.ts +823 -0
  202. package/dist/sandbox/index.cjs +133 -0
  203. package/dist/sandbox/index.cjs.map +1 -0
  204. package/dist/sandbox/index.d.cts +2 -0
  205. package/dist/sandbox/index.d.ts +2 -0
  206. package/dist/sandbox/index.js +128 -0
  207. package/dist/sandbox/index.js.map +1 -0
  208. package/dist/sandbox/local-sandbox.d.cts +17 -0
  209. package/dist/sandbox/local-sandbox.d.ts +17 -0
  210. package/dist/sandbox/types.d.cts +44 -0
  211. package/dist/sandbox/types.d.ts +44 -0
  212. package/dist/server/adapter/express.d.cts +9 -0
  213. package/dist/server/adapter/express.d.ts +9 -0
  214. package/dist/server/adapter/fastify.d.cts +9 -0
  215. package/dist/server/adapter/fastify.d.ts +9 -0
  216. package/dist/server/adapter/hono.d.cts +9 -0
  217. package/dist/server/adapter/hono.d.ts +9 -0
  218. package/dist/server/adapter/index.d.cts +8 -0
  219. package/dist/server/adapter/index.d.ts +8 -0
  220. package/dist/server/adapter/shared-handler.d.cts +9 -0
  221. package/dist/server/adapter/shared-handler.d.ts +9 -0
  222. package/dist/server/adapter/types.d.cts +33 -0
  223. package/dist/server/adapter/types.d.ts +33 -0
  224. package/dist/server/auth/errors.d.cts +53 -0
  225. package/dist/server/auth/errors.d.ts +53 -0
  226. package/dist/server/auth/index.cjs +38 -41
  227. package/dist/server/auth/index.cjs.map +1 -1
  228. package/dist/server/auth/index.d.cts +11 -172
  229. package/dist/server/auth/index.d.ts +11 -172
  230. package/dist/server/auth/index.js +39 -42
  231. package/dist/server/auth/index.js.map +1 -1
  232. package/dist/server/auth/oauth-transaction-store.d.cts +39 -0
  233. package/dist/server/auth/oauth-transaction-store.d.ts +39 -0
  234. package/dist/server/auth/orchestrator.d.cts +8 -0
  235. package/dist/server/auth/orchestrator.d.ts +8 -0
  236. package/dist/server/auth/types.d.cts +91 -0
  237. package/dist/server/auth/types.d.ts +91 -0
  238. package/dist/server/auth/validate-return-to.d.cts +17 -0
  239. package/dist/server/auth/validate-return-to.d.ts +17 -0
  240. package/dist/server/errors-envelope.cjs +409 -0
  241. package/dist/server/errors-envelope.cjs.map +1 -0
  242. package/dist/server/errors-envelope.d.cts +61 -0
  243. package/dist/server/errors-envelope.d.ts +61 -0
  244. package/dist/server/errors-envelope.js +405 -0
  245. package/dist/server/errors-envelope.js.map +1 -0
  246. package/dist/subscription/define-subscription.d.cts +63 -0
  247. package/dist/subscription/define-subscription.d.ts +63 -0
  248. package/dist/subscription/index.cjs +402 -0
  249. package/dist/subscription/index.cjs.map +1 -0
  250. package/dist/subscription/index.d.cts +18 -0
  251. package/dist/subscription/index.d.ts +18 -0
  252. package/dist/subscription/index.js +394 -0
  253. package/dist/subscription/index.js.map +1 -0
  254. package/dist/subscription/internal/adapter-types.d.cts +11 -0
  255. package/dist/subscription/internal/adapter-types.d.ts +11 -0
  256. package/dist/subscription/internal/backpressure.d.cts +24 -0
  257. package/dist/subscription/internal/backpressure.d.ts +24 -0
  258. package/dist/subscription/internal/server-integration.d.cts +17 -0
  259. package/dist/subscription/internal/server-integration.d.ts +17 -0
  260. package/dist/subscription/internal/sse-encoder.d.cts +13 -0
  261. package/dist/subscription/internal/sse-encoder.d.ts +13 -0
  262. package/dist/subscription/internal/sse-parser.d.cts +15 -0
  263. package/dist/subscription/internal/sse-parser.d.ts +15 -0
  264. package/dist/subscription/internal/subscription-runtime.d.cts +9 -0
  265. package/dist/subscription/internal/subscription-runtime.d.ts +9 -0
  266. package/dist/subscription/internal/ws-adapter-node.d.cts +10 -0
  267. package/dist/subscription/internal/ws-adapter-node.d.ts +10 -0
  268. package/dist/subscription/theokit-subscribe.d.cts +41 -0
  269. package/dist/subscription/theokit-subscribe.d.ts +41 -0
  270. package/dist/subscription/types.d.cts +140 -0
  271. package/dist/subscription/types.d.ts +140 -0
  272. package/dist/task-store.cjs +30 -2
  273. package/dist/task-store.cjs.map +1 -1
  274. package/dist/task-store.d.cts +8 -0
  275. package/dist/task-store.js +31 -3
  276. package/dist/task-store.js.map +1 -1
  277. package/dist/types/agent-prims.d.ts +61 -0
  278. package/dist/types/agent.d.ts +48 -53
  279. package/dist/types/conversation.d.ts +20 -8
  280. package/dist/types/index.d.ts +0 -2
  281. package/dist/types/messages-base.d.ts +20 -0
  282. package/dist/types/messages.d.ts +1 -1
  283. package/dist/types/run.d.ts +1 -1
  284. package/dist/types/updates.d.ts +1 -1
  285. package/dist/voice/index.d.ts +7 -0
  286. package/dist/voice/openai-realtime.d.ts +21 -0
  287. package/dist/voice/types.d.ts +35 -0
  288. package/dist/workflow.cjs +179 -88
  289. package/dist/workflow.cjs.map +1 -1
  290. package/dist/workflow.d.cts +97 -0
  291. package/dist/workflow.js +180 -89
  292. package/dist/workflow.js.map +1 -1
  293. package/package.json +128 -25
  294. package/dist/budget.d.ts +0 -48
  295. package/dist/cache.d.ts +0 -74
  296. package/dist/cron-1yxL3K2S.d.cts +0 -221
  297. package/dist/cron-BYVdYzob.d.ts +0 -221
  298. package/dist/handoff.d.ts +0 -55
  299. package/dist/internal/budget/calendar-window.d.ts +0 -19
  300. package/dist/internal/budget/enforcement.d.ts +0 -32
  301. package/dist/internal/budget/ledger.d.ts +0 -25
  302. package/dist/internal/budget/normalize-usage.d.ts +0 -27
  303. package/dist/internal/budget/registry.d.ts +0 -16
  304. package/dist/internal/cache/cosine.d.ts +0 -14
  305. package/dist/internal/cache/embed-helper.d.ts +0 -15
  306. package/dist/internal/cache/key.d.ts +0 -15
  307. package/dist/internal/cache/lookup.d.ts +0 -28
  308. package/dist/internal/cache/store-handler.d.ts +0 -24
  309. package/dist/internal/cache/store-json.d.ts +0 -48
  310. package/dist/internal/cache/store.d.ts +0 -54
  311. package/dist/internal/cache/telemetry.d.ts +0 -20
  312. package/dist/internal/cache/ttl.d.ts +0 -11
  313. package/dist/internal/catalog/fixtures.d.ts +0 -16
  314. package/dist/internal/catalog/local-models.d.ts +0 -24
  315. package/dist/internal/handoff/dispatcher.d.ts +0 -29
  316. package/dist/internal/handoff/registry.d.ts +0 -23
  317. package/dist/internal/handoff/telemetry.d.ts +0 -18
  318. package/dist/internal/handoff/tool-injector.d.ts +0 -34
  319. package/dist/internal/memory/atomic-write.d.ts +0 -7
  320. package/dist/internal/memory/dreaming/diary.d.ts +0 -4
  321. package/dist/internal/memory/dreaming/phases.d.ts +0 -15
  322. package/dist/internal/memory/dreaming/run.d.ts +0 -10
  323. package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +0 -15
  324. package/dist/memory-adapter-helpers.d.ts +0 -28
  325. package/dist/memory.d.ts +0 -123
  326. package/dist/migrate.d.ts +0 -33
  327. package/dist/security.d.ts +0 -67
  328. package/dist/task.d.ts +0 -87
  329. package/dist/theokit.d.ts +0 -84
  330. package/dist/tools/_path-scope.d.ts +0 -8
  331. package/dist/tools/_subprocess.d.ts +0 -28
  332. package/dist/tools/git-diff.d.ts +0 -22
  333. package/dist/tools/index.d.ts +0 -29
  334. package/dist/tools/list-dir.d.ts +0 -26
  335. package/dist/tools/read-file.d.ts +0 -31
  336. package/dist/tools/run-vitest.d.ts +0 -46
  337. package/dist/tools/search-text.d.ts +0 -32
  338. package/dist/tools.cjs +0 -690
  339. package/dist/tools.cjs.map +0 -1
  340. package/dist/tools.js +0 -683
  341. package/dist/tools.js.map +0 -1
  342. package/dist/trajectory-helpers.d.ts +0 -31
  343. package/dist/types/cache.d.ts +0 -76
  344. package/dist/types/handoff.d.ts +0 -135
  345. /package/dist/{internal/cron/run-job.d.ts → agent-helpers.d.ts} +0 -0
  346. /package/dist/internal/{cron/scheduler.d.ts → agent-loop/loop-llm-stream.d.ts} +0 -0
  347. /package/dist/internal/{cron/store.d.ts → agent-loop/tool-executors.d.ts} +0 -0
  348. /package/dist/internal/{cron/validate.d.ts → memory/index-manager-helpers.d.ts} +0 -0
  349. /package/dist/internal/memory/{session-loader.d.ts → storage/session-loader.d.ts} +0 -0
  350. /package/dist/internal/memory/{session-summary-writer.d.ts → storage/session-summary-writer.d.ts} +0 -0
  351. /package/dist/internal/memory/{transcript-store.d.ts → storage/transcript-store.d.ts} +0 -0
  352. /package/dist/internal/memory/{wiki-loader.d.ts → storage/wiki-loader.d.ts} +0 -0
  353. /package/dist/internal/{memory/cwd-mutex.d.ts → persistence/atomic-write.d.cts} +0 -0
  354. /package/dist/internal/runtime/{context-aggregator.d.ts → context/context-aggregator.d.ts} +0 -0
  355. /package/dist/internal/runtime/{context-discovery-runner.d.ts → context/context-discovery-runner.d.ts} +0 -0
  356. /package/dist/internal/runtime/{context-discovery.d.ts → context/context-discovery.d.ts} +0 -0
  357. /package/dist/internal/runtime/{context-frontmatter.d.ts → context/context-frontmatter.d.ts} +0 -0
  358. /package/dist/internal/runtime/{context-import-resolver.d.ts → context/context-import-resolver.d.ts} +0 -0
  359. /package/dist/internal/runtime/{context-loaders.d.ts → context/context-loaders.d.ts} +0 -0
  360. /package/dist/internal/runtime/{context-mdc-parser.d.ts → context/context-mdc-parser.d.ts} +0 -0
  361. /package/dist/internal/runtime/{fixture-responder.d.ts → fixtures/fixture-responder.d.ts} +0 -0
  362. /package/dist/internal/runtime/{fixture-types.d.ts → fixtures/fixture-types.d.ts} +0 -0
  363. /package/dist/internal/runtime/{plugins-manager.d.ts → local-agent-send.d.ts} +0 -0
  364. /package/dist/internal/runtime/{plugin-frontmatter.d.ts → plugins/plugin-frontmatter.d.ts} +0 -0
  365. /package/dist/internal/runtime/{system-prompt/providers/active-memory-provider.d.ts → plugins/plugins-manager.d.ts} +0 -0
  366. /package/dist/internal/runtime/{agent-factory-registry.d.ts → registry/agent-factory-registry.d.ts} +0 -0
  367. /package/dist/internal/runtime/{agent-registry-store.d.ts → registry/agent-registry-store.d.ts} +0 -0
  368. /package/dist/internal/runtime/system-prompt/{providers/base-provider.d.ts → sources/active-memory-provider.d.ts} +0 -0
  369. /package/dist/internal/runtime/system-prompt/{providers/context-provider.d.ts → sources/base-provider.d.ts} +0 -0
  370. /package/dist/internal/runtime/system-prompt/{providers/memory-provider.d.ts → sources/context-provider.d.ts} +0 -0
  371. /package/dist/internal/runtime/system-prompt/{providers/skills-provider.d.ts → sources/memory-provider.d.ts} +0 -0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @theokit/sdk/server/auth — orchestrator types (Caminho C Hybrid per G11)
3
+ *
4
+ * Plan: g11-auth-architecture-implementation v1.4 (sha256 4d381020...)
5
+ * Blueprint: g11-auth-architecture-decision v1.1 (SHIPPABLE 97.9)
6
+ * AUTH-DELEGATION lock (theokit/CLAUDE.md:217-225) — these types are the
7
+ * orchestrator contract; concrete OAuth/email providers ship in opt-in
8
+ * @theokit/auth-* packages (adapters layer per ADR D11).
9
+ */
10
+ import type { IncomingMessage, ServerResponse } from "node:http";
11
+ /**
12
+ * SessionManager contract (matches theokit/packages/theo/src/server/auth/session.ts:49).
13
+ * Imported as type-only — runtime depends via peerDep `theokit@>=0.2.4`.
14
+ */
15
+ export interface SessionManager<TSession> {
16
+ getSession(req: IncomingMessage): Promise<TSession | null>;
17
+ createSession(res: ServerResponse, data: TSession): Promise<void>;
18
+ destroySession(res: ServerResponse): void;
19
+ rotateSession(req: IncomingMessage, res: ServerResponse): Promise<TSession | null>;
20
+ }
21
+ /**
22
+ * Per ADR D5 — OAuth transaction state stored in encrypted HttpOnly cookie
23
+ * (cookie-state pattern). Expires within 10 minutes per invariant.
24
+ */
25
+ export interface OAuthTransaction {
26
+ state: string;
27
+ pkceVerifier?: string;
28
+ returnTo?: string;
29
+ createdAt: number;
30
+ expiresAt: number;
31
+ }
32
+ /**
33
+ * Per ADR D9 — provider profile types are provider-specific (not unified).
34
+ * Each @theokit/auth-* package exports its own profile shape.
35
+ * Generic param TProfile lets consumers narrow via discriminated unions on providerName.
36
+ */
37
+ export interface AuthResult<TProfile, TName extends string = string> {
38
+ profile: TProfile;
39
+ providerName: TName;
40
+ rawTokens?: {
41
+ accessToken: string;
42
+ refreshToken?: string;
43
+ idToken?: string;
44
+ expiresAt?: number;
45
+ };
46
+ }
47
+ /**
48
+ * Provider contract — each @theokit/auth-* package implements this.
49
+ * Per blueprint Q5 + ADR D11 (adapters layer).
50
+ */
51
+ export interface AuthProvider<TProfile, TName extends string = string> {
52
+ name: TName;
53
+ createAuthorizationURL(tx: OAuthTransaction): URL | Promise<URL>;
54
+ handleCallback(req: IncomingMessage, tx: OAuthTransaction): Promise<AuthResult<TProfile, TName>>;
55
+ }
56
+ /**
57
+ * `defineAuth(opts)` configuration shape — Caminho C (Hybrid).
58
+ * `providers` optional: empty = Caminho A escape hatch (manual signIn only).
59
+ * `onSignIn` invoked after provider callback success; returns TSession to persist.
60
+ */
61
+ export interface DefineAuthOptions<TSession> {
62
+ session: SessionManager<TSession>;
63
+ providers?: AuthProvider<unknown, string>[];
64
+ onSignIn?: <TProfile>(args: {
65
+ profile: TProfile;
66
+ provider: string;
67
+ }) => Promise<TSession>;
68
+ onSignOut?: (session: TSession | null) => Promise<void> | void;
69
+ }
70
+ /**
71
+ * Returned by `defineAuth<TSession>(opts)` — 5-method orchestrator surface.
72
+ *
73
+ * - startSignIn: returns Response.redirect to provider authorization URL with state cookie
74
+ * - finishSignIn: handles provider callback; verifies state; calls onSignIn; rotates session ID
75
+ * (OWASP A07:2021 per EC-10); creates session cookie; clears transaction cookie
76
+ * - signIn: Caminho A escape hatch — skip OAuth flow; directly persist session from external profile
77
+ * - signOut: destroys session cookie + invokes onSignOut callback
78
+ * - getSession: read-only passthrough to session.getSession
79
+ */
80
+ export interface AuthOrchestrator<TSession> {
81
+ startSignIn(providerName: string, req: IncomingMessage, opts?: {
82
+ returnTo?: string;
83
+ }): Promise<Response>;
84
+ finishSignIn(providerName: string, req: IncomingMessage, res: ServerResponse): Promise<{
85
+ session: TSession;
86
+ returnTo?: string;
87
+ }>;
88
+ signIn<TProfile>(profile: TProfile, providerName: string, req: IncomingMessage, res: ServerResponse): Promise<TSession>;
89
+ signOut(res: ServerResponse): void | Promise<void>;
90
+ getSession(req: IncomingMessage): Promise<TSession | null>;
91
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @theokit/sdk/server/auth — orchestrator types (Caminho C Hybrid per G11)
3
+ *
4
+ * Plan: g11-auth-architecture-implementation v1.4 (sha256 4d381020...)
5
+ * Blueprint: g11-auth-architecture-decision v1.1 (SHIPPABLE 97.9)
6
+ * AUTH-DELEGATION lock (theokit/CLAUDE.md:217-225) — these types are the
7
+ * orchestrator contract; concrete OAuth/email providers ship in opt-in
8
+ * @theokit/auth-* packages (adapters layer per ADR D11).
9
+ */
10
+ import type { IncomingMessage, ServerResponse } from "node:http";
11
+ /**
12
+ * SessionManager contract (matches theokit/packages/theo/src/server/auth/session.ts:49).
13
+ * Imported as type-only — runtime depends via peerDep `theokit@>=0.2.4`.
14
+ */
15
+ export interface SessionManager<TSession> {
16
+ getSession(req: IncomingMessage): Promise<TSession | null>;
17
+ createSession(res: ServerResponse, data: TSession): Promise<void>;
18
+ destroySession(res: ServerResponse): void;
19
+ rotateSession(req: IncomingMessage, res: ServerResponse): Promise<TSession | null>;
20
+ }
21
+ /**
22
+ * Per ADR D5 — OAuth transaction state stored in encrypted HttpOnly cookie
23
+ * (cookie-state pattern). Expires within 10 minutes per invariant.
24
+ */
25
+ export interface OAuthTransaction {
26
+ state: string;
27
+ pkceVerifier?: string;
28
+ returnTo?: string;
29
+ createdAt: number;
30
+ expiresAt: number;
31
+ }
32
+ /**
33
+ * Per ADR D9 — provider profile types are provider-specific (not unified).
34
+ * Each @theokit/auth-* package exports its own profile shape.
35
+ * Generic param TProfile lets consumers narrow via discriminated unions on providerName.
36
+ */
37
+ export interface AuthResult<TProfile, TName extends string = string> {
38
+ profile: TProfile;
39
+ providerName: TName;
40
+ rawTokens?: {
41
+ accessToken: string;
42
+ refreshToken?: string;
43
+ idToken?: string;
44
+ expiresAt?: number;
45
+ };
46
+ }
47
+ /**
48
+ * Provider contract — each @theokit/auth-* package implements this.
49
+ * Per blueprint Q5 + ADR D11 (adapters layer).
50
+ */
51
+ export interface AuthProvider<TProfile, TName extends string = string> {
52
+ name: TName;
53
+ createAuthorizationURL(tx: OAuthTransaction): URL | Promise<URL>;
54
+ handleCallback(req: IncomingMessage, tx: OAuthTransaction): Promise<AuthResult<TProfile, TName>>;
55
+ }
56
+ /**
57
+ * `defineAuth(opts)` configuration shape — Caminho C (Hybrid).
58
+ * `providers` optional: empty = Caminho A escape hatch (manual signIn only).
59
+ * `onSignIn` invoked after provider callback success; returns TSession to persist.
60
+ */
61
+ export interface DefineAuthOptions<TSession> {
62
+ session: SessionManager<TSession>;
63
+ providers?: AuthProvider<unknown, string>[];
64
+ onSignIn?: <TProfile>(args: {
65
+ profile: TProfile;
66
+ provider: string;
67
+ }) => Promise<TSession>;
68
+ onSignOut?: (session: TSession | null) => Promise<void> | void;
69
+ }
70
+ /**
71
+ * Returned by `defineAuth<TSession>(opts)` — 5-method orchestrator surface.
72
+ *
73
+ * - startSignIn: returns Response.redirect to provider authorization URL with state cookie
74
+ * - finishSignIn: handles provider callback; verifies state; calls onSignIn; rotates session ID
75
+ * (OWASP A07:2021 per EC-10); creates session cookie; clears transaction cookie
76
+ * - signIn: Caminho A escape hatch — skip OAuth flow; directly persist session from external profile
77
+ * - signOut: destroys session cookie + invokes onSignOut callback
78
+ * - getSession: read-only passthrough to session.getSession
79
+ */
80
+ export interface AuthOrchestrator<TSession> {
81
+ startSignIn(providerName: string, req: IncomingMessage, opts?: {
82
+ returnTo?: string;
83
+ }): Promise<Response>;
84
+ finishSignIn(providerName: string, req: IncomingMessage, res: ServerResponse): Promise<{
85
+ session: TSession;
86
+ returnTo?: string;
87
+ }>;
88
+ signIn<TProfile>(profile: TProfile, providerName: string, req: IncomingMessage, res: ServerResponse): Promise<TSession>;
89
+ signOut(res: ServerResponse): void | Promise<void>;
90
+ getSession(req: IncomingMessage): Promise<TSession | null>;
91
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @theokit/sdk/server/auth — same-origin returnTo validator
3
+ *
4
+ * Per v1.1 EC-2 MUST FIX — OWASP A01:2021 open-redirect mitigation.
5
+ *
6
+ * Without this check, attacker craft `/login?returnTo=https://evil.com` would
7
+ * cause post-login redirect to attacker domain with authenticated session cookie.
8
+ *
9
+ * Rules:
10
+ * - undefined/empty returnTo → default '/'
11
+ * - protocol-relative `//evil.com` → default '/' (URL parser would resolve to baseUrl protocol)
12
+ * - absolute URL with origin ≠ baseUrl.origin → default '/' (cross-origin redirect)
13
+ * - absolute URL with origin === baseUrl.origin → keep (same-origin allowed)
14
+ * - relative path starting with '/' → keep (same-app navigation)
15
+ * - relative path not starting with '/' → default '/' (defensive)
16
+ */
17
+ export declare function validateReturnTo(returnTo: string | undefined, baseUrl: URL): string;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @theokit/sdk/server/auth — same-origin returnTo validator
3
+ *
4
+ * Per v1.1 EC-2 MUST FIX — OWASP A01:2021 open-redirect mitigation.
5
+ *
6
+ * Without this check, attacker craft `/login?returnTo=https://evil.com` would
7
+ * cause post-login redirect to attacker domain with authenticated session cookie.
8
+ *
9
+ * Rules:
10
+ * - undefined/empty returnTo → default '/'
11
+ * - protocol-relative `//evil.com` → default '/' (URL parser would resolve to baseUrl protocol)
12
+ * - absolute URL with origin ≠ baseUrl.origin → default '/' (cross-origin redirect)
13
+ * - absolute URL with origin === baseUrl.origin → keep (same-origin allowed)
14
+ * - relative path starting with '/' → keep (same-app navigation)
15
+ * - relative path not starting with '/' → default '/' (defensive)
16
+ */
17
+ export declare function validateReturnTo(returnTo: string | undefined, baseUrl: URL): string;
@@ -0,0 +1,409 @@
1
+ 'use strict';
2
+
3
+ // src/internal/security/redact.ts
4
+ var REDACT_ENABLED = readEnvOnce();
5
+ function readEnvOnce() {
6
+ const raw = process.env.THEOKIT_REDACT_SECRETS;
7
+ if (raw === void 0) return true;
8
+ return ["1", "true", "yes", "on"].includes(raw.toLowerCase());
9
+ }
10
+ var warnedOptOut = false;
11
+ if (!REDACT_ENABLED && !warnedOptOut) {
12
+ process.stderr.write(
13
+ "[theokit-sdk] Secret redaction is DISABLED via THEOKIT_REDACT_SECRETS. Credentials may leak into errors, telemetry, logs, transcripts.\n"
14
+ );
15
+ warnedOptOut = true;
16
+ }
17
+ var BUILTIN_PATTERNS = [
18
+ // T5.4: 30+ vendor prefixes (was 12 pre-T5.4). Order matters — more
19
+ // specific prefixes precede generic ones (e.g., sk-ant-admin01 before
20
+ // sk-ant-, sk-proj- before sk-). PEM block deliberately first so its
21
+ // multi-line span runs before any per-line patterns can fire.
22
+ /-----BEGIN[ ]+(?:RSA |EC |DSA |OPENSSH |ENCRYPTED |)PRIVATE KEY-----[\s\S]+?-----END[ ]+(?:RSA |EC |DSA |OPENSSH |ENCRYPTED |)PRIVATE KEY-----/g,
23
+ // JWT — exact 3-segment base64url. Dotted; the body floor of 4 chars per
24
+ // segment matches the minimum legal payload while skipping `a.b.c` noise.
25
+ /eyJ[A-Za-z0-9_-]{4,}\.eyJ[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}/g,
26
+ // Azure Storage SAS — match the sig= component (URL-encoded base64).
27
+ /(?<=[?&]sig=)[A-Za-z0-9%+/]{20,}/g,
28
+ // Anthropic
29
+ /sk-ant-admin01-[A-Za-z0-9_-]{10,}/g,
30
+ // Anthropic admin keys (must precede sk-ant-)
31
+ /sk-ant-[A-Za-z0-9_-]{10,}/g,
32
+ // Anthropic regular
33
+ // OpenAI family + clones (sk- generic must come AFTER all sk-foo- variants)
34
+ /sk-proj-[A-Za-z0-9_-]{10,}/g,
35
+ // OpenAI project key (must precede sk- generic)
36
+ /sk-[A-Za-z0-9_-]{10,}/g,
37
+ // OpenAI / OpenRouter / DeepInfra / Together / DeepSeek
38
+ // Provider prefixes (alphabetized for maintainability)
39
+ /AIza[A-Za-z0-9_-]{35}/g,
40
+ // Google API key
41
+ /AKIA[A-Z0-9]{16}/g,
42
+ // AWS access key
43
+ /fw_[A-Za-z0-9]{20,}/g,
44
+ // Fireworks
45
+ /glpat-[A-Za-z0-9_-]{20}/g,
46
+ // GitLab PAT
47
+ /ghp_[A-Za-z0-9]{36}/g,
48
+ // GitHub PAT classic
49
+ /github_pat_[A-Za-z0-9_]{82}/g,
50
+ // GitHub PAT fine-grained
51
+ /gsk_[A-Za-z0-9]{20,}/g,
52
+ // Groq
53
+ /hf_[A-Za-z0-9]{20,}/g,
54
+ // HuggingFace
55
+ /\bpa-[A-Za-z0-9_-]{20,}/g,
56
+ // Voyage AI (word-boundary to skip CSS / kebab IDs)
57
+ /pcsk_[A-Za-z0-9_-]{20,}/g,
58
+ // Pinecone
59
+ /pplx-[A-Za-z0-9_-]{20,}/g,
60
+ // Perplexity
61
+ /r8_[A-Za-z0-9_-]{20,}/g,
62
+ // Replicate
63
+ /rk_live_[A-Za-z0-9]{20,}/g,
64
+ // Stripe restricted
65
+ /sk_live_[A-Za-z0-9]{20,}/g,
66
+ // Stripe secret
67
+ /sntrys_[A-Za-z0-9]{40,}/g,
68
+ // Sentry user auth
69
+ /xai-[A-Za-z0-9_-]{20,}/g,
70
+ // xAI (Grok)
71
+ /xox[bpasr]-[A-Za-z0-9-]{10,}/g,
72
+ //Slack tokens
73
+ // Additional unique-prefix tokens with low false-positive risk
74
+ /npm_[A-Za-z0-9]{36}/g,
75
+ // npm access token
76
+ /SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}/g,
77
+ // SendGrid
78
+ /\bSK[A-Za-z0-9]{32}\b/g,
79
+ // Twilio API SID (word-boundary to skip CSS class noise)
80
+ /\bkey-[a-f0-9]{32}\b/g,
81
+ // Mailgun (hex-only narrows false positives)
82
+ /MT[A-Za-z0-9_-]{23}\.[A-Za-z0-9_-]{6}\.[A-Za-z0-9_-]{27}/g,
83
+ // Discord bot
84
+ /\b(?:sdk|mob)-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\b/g
85
+ // LaunchDarkly
86
+ ];
87
+ var BEARER_PATTERN = /\b(Bearer\s+)([A-Za-z0-9_\-.+/=]{8,})/g;
88
+ var PARAM_PATTERN = /(\b(?:access_token|api_key|api-key|client_secret|credential|credentials|id_token|jwt|password|private_key|refresh_token|secret|service_account|session_token|token|x-api-key)\b["']?\s*[:=]\s*["']?)([A-Za-z0-9_\-.+/]+)/gi;
89
+ var _extraPatterns = [];
90
+ function maskToken(token) {
91
+ if (token.length < 18) return "***";
92
+ return `${token.slice(0, 6)}...${token.slice(-4)}`;
93
+ }
94
+ function coerceToString(value) {
95
+ if (typeof value === "string") return value;
96
+ if (value === null || value === void 0) return null;
97
+ if (typeof value === "object") {
98
+ try {
99
+ const s = JSON.stringify(value);
100
+ return s === void 0 ? null : s;
101
+ } catch {
102
+ return "[unredactable: circular]";
103
+ }
104
+ }
105
+ return String(value);
106
+ }
107
+ function redactSecrets(text, opts) {
108
+ const coerced = coerceToString(text);
109
+ if (coerced === null) return "";
110
+ if (!REDACT_ENABLED) return coerced;
111
+ let s = coerced;
112
+ for (const re of BUILTIN_PATTERNS) {
113
+ s = s.replace(re, (m) => maskToken(m));
114
+ }
115
+ for (const re of _extraPatterns) {
116
+ s = s.replace(re, (m) => maskToken(m));
117
+ }
118
+ {
119
+ s = s.replace(BEARER_PATTERN, (_, prefix) => `${prefix}***`);
120
+ s = s.replace(PARAM_PATTERN, (whole, prefix, value) => {
121
+ if (value.includes("...")) return whole;
122
+ return `${prefix}***`;
123
+ });
124
+ }
125
+ return s;
126
+ }
127
+
128
+ // src/errors.ts
129
+ var TheokitAgentError = class extends Error {
130
+ name = "TheokitAgentError";
131
+ isRetryable;
132
+ code;
133
+ protoErrorCode;
134
+ metadata;
135
+ constructor(message, options = {}) {
136
+ super(message, options.cause !== void 0 ? { cause: options.cause } : void 0);
137
+ this.isRetryable = options.isRetryable ?? false;
138
+ if (options.code !== void 0) this.code = options.code;
139
+ if (options.protoErrorCode !== void 0) this.protoErrorCode = options.protoErrorCode;
140
+ if (options.metadata !== void 0) this.metadata = options.metadata;
141
+ }
142
+ };
143
+ var AuthenticationError = class extends TheokitAgentError {
144
+ name = "AuthenticationError";
145
+ constructor(message, options = {}) {
146
+ super(message, { ...options, isRetryable: false });
147
+ }
148
+ };
149
+ var RateLimitError = class extends TheokitAgentError {
150
+ name = "RateLimitError";
151
+ constructor(message, options = {}) {
152
+ super(message, { ...options, isRetryable: true });
153
+ }
154
+ };
155
+ var ConfigurationError = class extends TheokitAgentError {
156
+ name = "ConfigurationError";
157
+ constructor(message, options = {}) {
158
+ super(message, { ...options, isRetryable: false });
159
+ }
160
+ };
161
+ var NetworkError = class extends TheokitAgentError {
162
+ name = "NetworkError";
163
+ constructor(message, options = {}) {
164
+ super(message, { ...options, isRetryable: true });
165
+ }
166
+ };
167
+ var UnknownAgentError = class extends TheokitAgentError {
168
+ name = "UnknownAgentError";
169
+ constructor(message, options = {}) {
170
+ super(message, { ...options, isRetryable: false });
171
+ }
172
+ };
173
+ var AgentRunError = class extends TheokitAgentError {
174
+ name = "AgentRunError";
175
+ provider;
176
+ raw;
177
+ /** Provider's request id (`x-request-id` / `request-id` header). Useful for support tickets. */
178
+ requestId;
179
+ /** SDK conversation id this error was raised inside. */
180
+ conversationId;
181
+ constructor(message, options) {
182
+ super(message, {
183
+ code: options.code,
184
+ cause: options.cause,
185
+ metadata: options.metadata,
186
+ // D311: most AgentRunErrors are not retriable (auth, validation, abort).
187
+ // Provider mappers (D314) override per-status — explicit `retriable` wins
188
+ // over the implicit default when supplied.
189
+ isRetryable: options.retriable ?? defaultRetriableForCode(options.code)
190
+ });
191
+ if (options.provider !== void 0) this.provider = options.provider;
192
+ if (options.raw !== void 0) this.raw = options.raw;
193
+ if (options.requestId !== void 0) this.requestId = options.requestId;
194
+ if (options.conversationId !== void 0) this.conversationId = options.conversationId;
195
+ }
196
+ /**
197
+ * Production-Readiness #3 (ADR D311): alias for `isRetryable` exposed as
198
+ * `retriable` to match the handoff contract. Future v2 will deprecate
199
+ * `isRetryable` in favor of this.
200
+ */
201
+ get retriable() {
202
+ return this.isRetryable;
203
+ }
204
+ /**
205
+ * D312: provider's `Retry-After` header in **milliseconds**. Mappers store
206
+ * the header value (seconds) in `metadata.retryAfter`; this getter
207
+ * multiplies by 1000 so the result composes with `Date.now()`/`setTimeout`.
208
+ *
209
+ * Returns `undefined` when no hint was provided. `0` is a legitimate value
210
+ * — use `=== undefined` check rather than truthy check.
211
+ */
212
+ get retryAfterMs() {
213
+ if (this.metadata?.retryAfter === void 0) return void 0;
214
+ return this.metadata.retryAfter * 1e3;
215
+ }
216
+ /**
217
+ * D313 + T1.5: alias for `metadata.raw`. Provider response body for
218
+ * debugging. T1.5 wraps the value in `redactSecrets` at the getter
219
+ * boundary so secret-shaped substrings (`sk-...`, Bearer JWTs, etc.) are
220
+ * stripped before reaching the caller. Available but NEVER serialized
221
+ * into `.message` (anti-leak invariant).
222
+ */
223
+ get providerError() {
224
+ const raw = this.metadata?.raw;
225
+ if (raw === void 0) return void 0;
226
+ if (typeof raw === "string") return redactSecrets(raw);
227
+ try {
228
+ return redactSecrets(JSON.stringify(raw));
229
+ } catch {
230
+ return redactSecrets(String(raw));
231
+ }
232
+ }
233
+ /**
234
+ * T1.5 — sanitized JSON form. `metadata.raw` is OMITTED by default; opt
235
+ * in via `THEOKIT_DEBUG_RAW_ERRORS=1` to surface the (redacted) raw
236
+ * payload for diagnostics. Every other field stays accessible.
237
+ *
238
+ * The single env-var gate is read each call so operators can toggle at
239
+ * runtime without restarting the process.
240
+ */
241
+ toJSON() {
242
+ const json = {
243
+ name: this.name,
244
+ message: this.message,
245
+ isRetryable: this.isRetryable
246
+ };
247
+ addOptionalFields(json, this);
248
+ const safeMeta = sanitizeMetadata(this.metadata);
249
+ if (safeMeta !== void 0) json.metadata = safeMeta;
250
+ return json;
251
+ }
252
+ };
253
+ function addOptionalFields(json, err) {
254
+ if (err.code !== void 0) json.code = err.code;
255
+ if (err.provider !== void 0) json.provider = err.provider;
256
+ if (err.requestId !== void 0) json.requestId = err.requestId;
257
+ if (err.conversationId !== void 0) json.conversationId = err.conversationId;
258
+ if (err.raw !== void 0) json.raw = redactSecrets(err.raw);
259
+ }
260
+ function sanitizeMetadata(meta) {
261
+ if (meta === void 0) return void 0;
262
+ const { raw, ...rest } = meta;
263
+ const debugRaw = process.env.THEOKIT_DEBUG_RAW_ERRORS === "1";
264
+ if (debugRaw && raw !== void 0) {
265
+ const redactedRaw = typeof raw === "string" ? redactSecrets(raw) : redactSecrets(safeStringify(raw));
266
+ return { ...rest, raw: redactedRaw };
267
+ }
268
+ return rest;
269
+ }
270
+ function safeStringify(value) {
271
+ try {
272
+ return JSON.stringify(value);
273
+ } catch {
274
+ return String(value);
275
+ }
276
+ }
277
+ function defaultRetriableForCode(code) {
278
+ switch (code) {
279
+ case "rate_limit":
280
+ case "timeout":
281
+ case "server_error":
282
+ case "network":
283
+ case "provider_unreachable":
284
+ return true;
285
+ default:
286
+ return false;
287
+ }
288
+ }
289
+ var CredentialPoolExhaustedError = class extends TheokitAgentError {
290
+ name = "CredentialPoolExhaustedError";
291
+ provider;
292
+ nextRetryAt;
293
+ constructor(message, options) {
294
+ super(message, {
295
+ ...options,
296
+ isRetryable: true,
297
+ code: options.code ?? "credential_pool_exhausted"
298
+ });
299
+ this.provider = options.provider;
300
+ this.nextRetryAt = options.nextRetryAt;
301
+ }
302
+ };
303
+ var MemoryAdapterError = class extends TheokitAgentError {
304
+ name = "MemoryAdapterError";
305
+ adapterId;
306
+ constructor(message, options) {
307
+ super(message, {
308
+ isRetryable: options.code === "rate_limited" || options.code === "network",
309
+ code: options.code,
310
+ ...options.cause !== void 0 ? { cause: options.cause } : {},
311
+ ...options.metadata !== void 0 ? { metadata: options.metadata } : {}
312
+ });
313
+ this.adapterId = options.adapterId;
314
+ }
315
+ };
316
+
317
+ // src/server/errors-envelope.ts
318
+ var NAME_TO_CODE = /* @__PURE__ */ new Map([
319
+ ["AuthenticationError", "UNAUTHORIZED"],
320
+ ["RateLimitError", "RATE_LIMITED"],
321
+ ["ConfigurationError", "PROVIDER_KEY_MISSING"],
322
+ ["IntegrationNotConnectedError", "PROVIDER_KEY_MISSING"],
323
+ ["NetworkError", "SERVICE_UNAVAILABLE"],
324
+ ["AgentRunError", "AGENT_RUN_ERROR"],
325
+ ["BudgetExceededError", "BUDGET_EXCEEDED"],
326
+ ["CredentialPoolExhaustedError", "CREDENTIAL_POOL_EXHAUSTED"],
327
+ ["UnknownAgentError", "INTERNAL_SERVER_ERROR"],
328
+ ["MemoryAdapterError", "INTERNAL_SERVER_ERROR"]
329
+ ]);
330
+ function toEnvelope(value) {
331
+ if (!(value instanceof Error)) {
332
+ return {
333
+ code: "INTERNAL_SERVER_ERROR",
334
+ message: typeof value === "string" ? value : "Unknown error"
335
+ };
336
+ }
337
+ const name = value.name;
338
+ const code = NAME_TO_CODE.get(name) ?? "INTERNAL_SERVER_ERROR";
339
+ const meta = buildMeta(name, value);
340
+ const ext = buildExt(value);
341
+ return {
342
+ code,
343
+ message: value.message,
344
+ cause: value.cause,
345
+ meta,
346
+ ext
347
+ };
348
+ }
349
+ function buildMeta(name, err) {
350
+ const meta = { sdkErrorName: name };
351
+ if (err instanceof TheokitAgentError && err.metadata !== void 0) {
352
+ meta.provider = err.metadata.provider;
353
+ meta.endpoint = err.metadata.endpoint;
354
+ if (err.metadata.statusCode !== void 0) {
355
+ meta.statusCode = err.metadata.statusCode;
356
+ }
357
+ }
358
+ return meta;
359
+ }
360
+ function buildExt(err) {
361
+ if (err instanceof RateLimitError && err.metadata?.retryAfter !== void 0) {
362
+ return {
363
+ retryable: true,
364
+ retryAfterMs: err.metadata.retryAfter * 1e3
365
+ };
366
+ }
367
+ if (err instanceof CredentialPoolExhaustedError && err.nextRetryAt !== void 0) {
368
+ const delayMs = Math.max(0, err.nextRetryAt - Date.now());
369
+ return {
370
+ retryable: true,
371
+ retryAfterMs: delayMs
372
+ };
373
+ }
374
+ return void 0;
375
+ }
376
+ var CODE_TO_RECONSTRUCTOR = /* @__PURE__ */ new Map([
377
+ ["UNAUTHORIZED", (env) => new AuthenticationError(env.message)],
378
+ [
379
+ "RATE_LIMITED",
380
+ (env) => new RateLimitError(env.message, env.cause !== void 0 ? { cause: env.cause } : {})
381
+ ],
382
+ ["PROVIDER_KEY_MISSING", (env) => new ConfigurationError(env.message)],
383
+ ["SERVICE_UNAVAILABLE", (env) => new NetworkError(env.message)],
384
+ ["GATEWAY_TIMEOUT", (env) => new NetworkError(env.message)],
385
+ [
386
+ "AGENT_RUN_ERROR",
387
+ (env) => new AgentRunError(env.message, {
388
+ code: "unknown",
389
+ ...env.cause !== void 0 ? { cause: env.cause } : {}
390
+ })
391
+ ],
392
+ ["INTERNAL_SERVER_ERROR", (env) => new UnknownAgentError(env.message)]
393
+ // BUDGET_EXCEEDED + CREDENTIAL_POOL_EXHAUSTED reconstructors require
394
+ // domain-specific args (budgetName, provider) that the envelope doesn't
395
+ // always carry. Fall back to UnknownAgentError when those fields are
396
+ // missing; consumer code that needs the typed class should call the
397
+ // constructor directly.
398
+ ]);
399
+ function fromEnvelope(env) {
400
+ const reconstructor = CODE_TO_RECONSTRUCTOR.get(env.code);
401
+ if (reconstructor) return reconstructor(env);
402
+ return new UnknownAgentError(env.message);
403
+ }
404
+
405
+ exports.MemoryAdapterError = MemoryAdapterError;
406
+ exports.fromEnvelope = fromEnvelope;
407
+ exports.toEnvelope = toEnvelope;
408
+ //# sourceMappingURL=errors-envelope.cjs.map
409
+ //# sourceMappingURL=errors-envelope.cjs.map