@jini-ai/core 0.7.2 → 0.7.3-next.2

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 (343) hide show
  1. package/README.md +40 -12
  2. package/dist/admin-runtime/admin-api-error.d.ts +68 -0
  3. package/dist/admin-runtime/admin-api-error.js +72 -0
  4. package/dist/admin-runtime/admin-config-error.d.ts +8 -0
  5. package/dist/admin-runtime/admin-config-error.js +11 -0
  6. package/dist/admin-runtime/controller-store.d.ts +20 -0
  7. package/dist/admin-runtime/controller-store.js +32 -0
  8. package/dist/admin-runtime/index.d.ts +13 -0
  9. package/dist/admin-runtime/index.js +12 -0
  10. package/dist/admin-runtime/panel-access.d.ts +88 -0
  11. package/dist/admin-runtime/panel-access.js +76 -0
  12. package/dist/admin-runtime/query-suffix.d.ts +5 -0
  13. package/dist/admin-runtime/query-suffix.js +5 -0
  14. package/dist/agent-handles/element-handles.d.ts +134 -0
  15. package/dist/agent-handles/element-handles.js +45 -0
  16. package/dist/agent-handles/field-descriptor.d.ts +28 -0
  17. package/dist/agent-handles/field-descriptor.js +3 -0
  18. package/dist/agent-handles/handle.d.ts +109 -0
  19. package/dist/agent-handles/handle.js +109 -0
  20. package/dist/agent-handles/index.d.ts +9 -0
  21. package/dist/agent-handles/index.js +6 -0
  22. package/dist/agent-handles/list-handles.d.ts +46 -0
  23. package/dist/agent-handles/list-handles.js +67 -0
  24. package/dist/agent-handles/secret-attrs.d.ts +14 -0
  25. package/dist/agent-handles/secret-attrs.js +13 -0
  26. package/dist/approval-batch-chain.d.ts +45 -0
  27. package/dist/approval-batch-chain.js +75 -0
  28. package/dist/approval.d.ts +33 -14
  29. package/dist/approval.js +57 -43
  30. package/dist/batch-tool-inputs.js +24 -20
  31. package/dist/contracts/admin-module.d.ts +166 -0
  32. package/dist/contracts/admin-module.js +14 -0
  33. package/dist/contracts/agents/definition.d.ts +459 -0
  34. package/dist/contracts/agents/definition.js +2 -0
  35. package/dist/contracts/agents/index.d.ts +7 -0
  36. package/dist/contracts/agents/index.js +2 -0
  37. package/dist/contracts/agents/launch.d.ts +64 -0
  38. package/dist/contracts/agents/launch.js +2 -0
  39. package/dist/contracts/agents/model-catalog.d.ts +213 -0
  40. package/dist/contracts/agents/model-catalog.js +4 -0
  41. package/dist/contracts/agents/native-tool-policy.d.ts +42 -0
  42. package/dist/contracts/agents/native-tool-policy.js +2 -0
  43. package/dist/contracts/ai-trace/capture.d.ts +17 -0
  44. package/dist/contracts/ai-trace/capture.js +43 -0
  45. package/dist/contracts/ai-trace/classify.d.ts +12 -0
  46. package/dist/contracts/ai-trace/classify.js +16 -0
  47. package/dist/contracts/ai-trace/index.d.ts +13 -0
  48. package/dist/contracts/ai-trace/index.js +6 -0
  49. package/dist/contracts/ai-trace/recorder.d.ts +64 -0
  50. package/dist/contracts/ai-trace/recorder.js +283 -0
  51. package/dist/contracts/ai-trace/sinks.d.ts +51 -0
  52. package/dist/contracts/ai-trace/sinks.js +153 -0
  53. package/dist/contracts/ai-trace/types.d.ts +123 -0
  54. package/dist/contracts/ai-trace/types.js +17 -0
  55. package/dist/contracts/ai-trace/usage.d.ts +16 -0
  56. package/dist/contracts/ai-trace/usage.js +45 -0
  57. package/dist/contracts/blob.d.ts +31 -0
  58. package/dist/contracts/blob.js +10 -0
  59. package/dist/contracts/capabilities.d.ts +95 -0
  60. package/dist/contracts/capabilities.js +111 -0
  61. package/dist/contracts/charts.d.ts +75 -0
  62. package/dist/contracts/charts.js +4 -0
  63. package/dist/contracts/env.d.ts +96 -0
  64. package/dist/contracts/env.js +6 -0
  65. package/dist/contracts/events/change-set.d.ts +106 -0
  66. package/dist/contracts/events/change-set.js +2 -0
  67. package/dist/contracts/events/command.d.ts +118 -0
  68. package/dist/contracts/events/command.js +2 -0
  69. package/dist/contracts/events/ports.d.ts +172 -0
  70. package/dist/contracts/events/ports.js +2 -0
  71. package/dist/contracts/events.d.ts +5 -0
  72. package/dist/contracts/events.js +2 -0
  73. package/dist/contracts/forms.d.ts +110 -0
  74. package/dist/contracts/forms.js +4 -0
  75. package/dist/contracts/hosted-mcp/config.d.ts +19 -0
  76. package/dist/contracts/hosted-mcp/record.d.ts +61 -4
  77. package/dist/contracts/mail/email-sender.d.ts +118 -0
  78. package/dist/contracts/mail/email-sender.js +20 -0
  79. package/dist/contracts/mail/smtp-payload.d.ts +32 -0
  80. package/dist/contracts/mail/smtp-payload.js +2 -0
  81. package/dist/contracts/mail.d.ts +2 -0
  82. package/dist/contracts/mail.js +1 -1
  83. package/dist/contracts/observability.d.ts +235 -0
  84. package/dist/contracts/observability.js +28 -0
  85. package/dist/contracts/plugin-sdk.d.ts +186 -0
  86. package/dist/contracts/plugin-sdk.js +39 -0
  87. package/dist/contracts/runtime/command.d.ts +41 -0
  88. package/dist/contracts/runtime/command.js +60 -0
  89. package/dist/contracts/runtime/environment.d.ts +18 -0
  90. package/dist/contracts/runtime/environment.js +26 -0
  91. package/dist/contracts/runtime/file-lock.d.ts +94 -0
  92. package/dist/contracts/runtime/file-lock.js +25 -0
  93. package/dist/contracts/runtime/fs.d.ts +33 -0
  94. package/dist/contracts/runtime/fs.js +2 -0
  95. package/dist/contracts/runtime/http.d.ts +89 -0
  96. package/dist/contracts/runtime/http.js +2 -0
  97. package/dist/contracts/runtime/platform.d.ts +3 -0
  98. package/dist/contracts/runtime/platform.js +2 -0
  99. package/dist/contracts/runtime/process.d.ts +40 -0
  100. package/dist/contracts/runtime/process.js +31 -0
  101. package/dist/contracts/runtime/reader.d.ts +11 -0
  102. package/dist/contracts/runtime/reader.js +2 -0
  103. package/dist/contracts/runtime/terminal.d.ts +99 -0
  104. package/dist/contracts/runtime/terminal.js +2 -0
  105. package/dist/contracts/runtime/testing.d.ts +84 -0
  106. package/dist/contracts/runtime/testing.js +116 -0
  107. package/dist/contracts/runtime.d.ts +10 -0
  108. package/dist/contracts/runtime.js +10 -0
  109. package/dist/contracts/server/api-error.d.ts +43 -0
  110. package/dist/contracts/server/api-error.js +49 -0
  111. package/dist/contracts/server/auth.d.ts +20 -0
  112. package/dist/contracts/server/auth.js +21 -0
  113. package/dist/contracts/server/conformance.d.ts +25 -0
  114. package/dist/contracts/server/conformance.js +50 -0
  115. package/dist/contracts/server/json-route.d.ts +176 -0
  116. package/dist/contracts/server/json-route.js +155 -0
  117. package/dist/contracts/server/middleware.d.ts +35 -0
  118. package/dist/contracts/server/middleware.js +56 -0
  119. package/dist/contracts/server/origin.d.ts +44 -0
  120. package/dist/contracts/server/origin.js +32 -0
  121. package/dist/contracts/server/query.d.ts +16 -0
  122. package/dist/contracts/server/query.js +69 -0
  123. package/dist/contracts/server/rate-limit.d.ts +20 -0
  124. package/dist/contracts/server/rate-limit.js +8 -0
  125. package/dist/contracts/server/request-body.d.ts +26 -0
  126. package/dist/contracts/server/request-body.js +82 -0
  127. package/dist/contracts/server/result.d.ts +17 -0
  128. package/dist/contracts/server/result.js +5 -0
  129. package/dist/contracts/server/route-table.d.ts +54 -0
  130. package/dist/contracts/server/route-table.js +119 -0
  131. package/dist/contracts/server/same-origin-write.d.ts +18 -0
  132. package/dist/contracts/server/same-origin-write.js +31 -0
  133. package/dist/contracts/server/security-headers.d.ts +30 -0
  134. package/dist/contracts/server/security-headers.js +35 -0
  135. package/dist/contracts/server/sse.d.ts +82 -0
  136. package/dist/contracts/server/sse.js +103 -0
  137. package/dist/contracts/server/testing.d.ts +59 -0
  138. package/dist/contracts/server/testing.js +68 -0
  139. package/dist/contracts/server/verified-origin/configured-origin.d.ts +37 -0
  140. package/dist/contracts/server/verified-origin/configured-origin.js +103 -0
  141. package/dist/contracts/server/verified-origin/index.d.ts +7 -0
  142. package/dist/contracts/server/verified-origin/index.js +6 -0
  143. package/dist/contracts/server/verified-origin/loopback-host.d.ts +9 -0
  144. package/dist/contracts/server/verified-origin/loopback-host.js +17 -0
  145. package/dist/contracts/server/verified-origin/origin.d.ts +64 -0
  146. package/dist/contracts/server/verified-origin/origin.js +162 -0
  147. package/dist/contracts/server/verified-origin/ports.d.ts +38 -0
  148. package/dist/contracts/server/verified-origin/ports.js +2 -0
  149. package/dist/contracts/server/verified-origin/repo.memory.d.ts +32 -0
  150. package/dist/contracts/server/verified-origin/repo.memory.js +34 -0
  151. package/dist/contracts/server/verified-origin/site-path.d.ts +113 -0
  152. package/dist/contracts/server/verified-origin/site-path.js +188 -0
  153. package/dist/contracts/server/verified-origin/types.d.ts +33 -0
  154. package/dist/contracts/server/verified-origin/types.js +30 -0
  155. package/dist/contracts/server.d.ts +46 -2
  156. package/dist/contracts/server.js +17 -3
  157. package/dist/contracts/storage/kernel.d.ts +86 -0
  158. package/dist/contracts/storage/kernel.js +38 -0
  159. package/dist/contracts/storage/migration.d.ts +32 -0
  160. package/dist/contracts/storage/migration.js +2 -0
  161. package/dist/contracts/storage/rows.d.ts +33 -0
  162. package/dist/contracts/storage/rows.js +42 -0
  163. package/dist/contracts/storage/sqlite.d.ts +113 -0
  164. package/dist/contracts/storage/sqlite.js +8 -0
  165. package/dist/contracts/storage/values.d.ts +25 -0
  166. package/dist/contracts/storage/values.js +25 -0
  167. package/dist/contracts/storage.d.ts +8 -0
  168. package/dist/contracts/storage.js +6 -0
  169. package/dist/contracts/vault/invariants.d.ts +26 -0
  170. package/dist/contracts/vault/invariants.js +49 -0
  171. package/dist/contracts/vault.d.ts +1 -0
  172. package/dist/contracts/vault.js +1 -1
  173. package/dist/env/coercers.d.ts +21 -0
  174. package/dist/env/coercers.js +68 -0
  175. package/dist/env/describe-env-for-diagnostics.d.ts +16 -0
  176. package/dist/env/describe-env-for-diagnostics.js +23 -0
  177. package/dist/env/format-env-issue.d.ts +13 -0
  178. package/dist/env/format-env-issue.js +22 -0
  179. package/dist/env/parse-env.d.ts +24 -0
  180. package/dist/env/parse-env.js +102 -0
  181. package/dist/env/value-echo.d.ts +17 -0
  182. package/dist/env/value-echo.js +42 -0
  183. package/dist/errors/approved-cause.d.ts +36 -0
  184. package/dist/errors/approved-cause.js +17 -0
  185. package/dist/errors/bindings.d.ts +61 -0
  186. package/dist/errors/bindings.js +57 -0
  187. package/dist/errors/catalog.d.ts +84 -0
  188. package/dist/errors/catalog.js +151 -0
  189. package/dist/errors/disclosure.d.ts +48 -0
  190. package/dist/errors/disclosure.js +27 -0
  191. package/dist/errors/error-id.d.ts +26 -0
  192. package/dist/errors/error-id.js +23 -0
  193. package/dist/errors/idioms.d.ts +73 -0
  194. package/dist/errors/idioms.js +85 -0
  195. package/dist/errors/incident-text.d.ts +16 -0
  196. package/dist/errors/incident-text.js +77 -0
  197. package/dist/errors/reporter.d.ts +94 -0
  198. package/dist/errors/reporter.js +152 -0
  199. package/dist/errors/sentences.d.ts +68 -0
  200. package/dist/errors/sentences.js +93 -0
  201. package/dist/errors/testing.d.ts +50 -0
  202. package/dist/errors/testing.js +44 -0
  203. package/dist/fetch/cache.d.ts +12 -5
  204. package/dist/fetch/cache.js +46 -47
  205. package/dist/fetch/index.d.ts +1 -1
  206. package/dist/fetch/loader-read.d.ts +6 -2
  207. package/dist/fetch/loader-read.js +4 -4
  208. package/dist/format-error-for-log.d.ts +15 -0
  209. package/dist/format-error-for-log.js +55 -0
  210. package/dist/gated-mutations/gateway.d.ts +2 -0
  211. package/dist/gated-mutations/gateway.js +4 -1
  212. package/dist/host-read-vocabulary.d.ts +47 -0
  213. package/dist/host-read-vocabulary.js +44 -0
  214. package/dist/index.d.ts +5 -1
  215. package/dist/index.js +4 -0
  216. package/dist/list-page.d.ts +93 -0
  217. package/dist/list-page.js +154 -0
  218. package/dist/model-facing-tool-errors.d.ts +67 -5
  219. package/dist/model-facing-tool-errors.js +155 -19
  220. package/dist/net/endpoint-policy.d.ts +39 -0
  221. package/dist/net/endpoint-policy.js +218 -0
  222. package/dist/net/fetch-timeouts.d.ts +38 -0
  223. package/dist/net/fetch-timeouts.js +31 -0
  224. package/dist/net/index.d.ts +4 -0
  225. package/dist/net/index.js +4 -0
  226. package/dist/net/loopback.d.ts +13 -0
  227. package/dist/net/loopback.js +39 -0
  228. package/dist/optimistic-concurrency.d.ts +183 -0
  229. package/dist/optimistic-concurrency.js +222 -0
  230. package/dist/primitives/errors.d.ts +9 -0
  231. package/dist/primitives/errors.js +12 -0
  232. package/dist/primitives/ids.d.ts +0 -2
  233. package/dist/primitives/ids.js +1 -4
  234. package/dist/primitives/index.d.ts +3 -0
  235. package/dist/primitives/index.js +2 -0
  236. package/dist/primitives/logger.d.ts +36 -1
  237. package/dist/primitives/logger.js +125 -9
  238. package/dist/primitives/node-shape.d.ts +24 -0
  239. package/dist/primitives/node-shape.js +21 -0
  240. package/dist/primitives/time.d.ts +9 -2
  241. package/dist/primitives/time.js +4 -3
  242. package/dist/provider-registry.js +26 -20
  243. package/dist/records.d.ts +40 -7
  244. package/dist/records.js +37 -3
  245. package/dist/redact.d.ts +1 -84
  246. package/dist/redact.js +2 -826
  247. package/dist/redaction-collectors.d.ts +7 -0
  248. package/dist/redaction-collectors.js +152 -0
  249. package/dist/redaction-exact-secrets.d.ts +14 -0
  250. package/dist/redaction-exact-secrets.js +115 -0
  251. package/dist/redaction-labels.d.ts +14 -0
  252. package/dist/redaction-labels.js +156 -0
  253. package/dist/redaction-patterns.d.ts +54 -0
  254. package/dist/redaction-patterns.js +178 -0
  255. package/dist/redaction-spans.d.ts +31 -0
  256. package/dist/redaction-spans.js +83 -0
  257. package/dist/registration-kit.d.ts +1 -1
  258. package/dist/revision-conflict-error.d.ts +18 -0
  259. package/dist/revision-conflict-error.js +20 -0
  260. package/dist/secret-shapes.d.ts +50 -0
  261. package/dist/secret-shapes.js +105 -0
  262. package/dist/settings/agent-tools.js +22 -8
  263. package/dist/settings/agent-value-write-tools.d.ts +4 -1
  264. package/dist/settings/agent-value-write-tools.js +7 -6
  265. package/dist/settings/agent-writable-preferences.d.ts +3 -1
  266. package/dist/settings/agent-writable-preferences.js +1 -1
  267. package/dist/settings/agent-write-denylist.d.ts +7 -4
  268. package/dist/settings/agent-write-denylist.js +1 -1
  269. package/dist/settings/{express/cms-adapter.d.ts → cms-adapter.d.ts} +3 -2
  270. package/dist/settings/{express/cms-adapter.js → cms-adapter.js} +21 -11
  271. package/dist/settings/definitions-dispatch.js +3 -1
  272. package/dist/settings/ensure-definitions.js +3 -1
  273. package/dist/settings/errors.d.ts +1 -13
  274. package/dist/settings/errors.js +2 -15
  275. package/dist/settings/index.d.ts +11 -2
  276. package/dist/settings/index.js +10 -2
  277. package/dist/settings/purge-service.js +63 -86
  278. package/dist/settings/{express/contracts.d.ts → route-policy.d.ts} +53 -47
  279. package/dist/settings/{express/shared.js → route-policy.js} +1 -16
  280. package/dist/settings/settings.d.ts +19 -11
  281. package/dist/settings/settings.js +9 -11
  282. package/dist/settings/tool-registrations.d.ts +3 -3
  283. package/dist/settings/tool-registrations.js +130 -125
  284. package/dist/settings/types.d.ts +1 -1
  285. package/dist/settings/write-definition-rename.d.ts +37 -0
  286. package/dist/settings/write-definition-rename.js +119 -0
  287. package/dist/settings/write-definition-retype.d.ts +61 -0
  288. package/dist/settings/write-definition-retype.js +109 -0
  289. package/dist/settings/write-definition-status.d.ts +81 -0
  290. package/dist/settings/write-definition-status.js +121 -0
  291. package/dist/settings/write-reset.d.ts +34 -0
  292. package/dist/settings/write-reset.js +73 -0
  293. package/dist/settings/write-service.d.ts +16 -287
  294. package/dist/settings/write-service.js +49 -681
  295. package/dist/settings/write-value-revisions.d.ts +68 -0
  296. package/dist/settings/write-value-revisions.js +124 -0
  297. package/dist/settings/write-values.d.ts +96 -0
  298. package/dist/settings/write-values.js +83 -0
  299. package/dist/surface-exchanges.d.ts +2 -2
  300. package/dist/text/dictionary-translator.d.ts +19 -0
  301. package/dist/text/dictionary-translator.js +14 -0
  302. package/dist/text/format-byte-size.d.ts +25 -0
  303. package/dist/text/format-byte-size.js +25 -0
  304. package/dist/text/format-timestamp.d.ts +22 -0
  305. package/dist/text/format-timestamp.js +57 -0
  306. package/dist/text/index.d.ts +12 -0
  307. package/dist/text/index.js +9 -0
  308. package/dist/text/is-abort-error.d.ts +5 -0
  309. package/dist/text/is-abort-error.js +5 -0
  310. package/dist/text/mime.d.ts +5 -0
  311. package/dist/text/mime.js +21 -0
  312. package/dist/text/redact-urls.d.ts +7 -0
  313. package/dist/text/redact-urls.js +5 -0
  314. package/dist/text/resolve-active-tab-id.d.ts +13 -0
  315. package/dist/text/resolve-active-tab-id.js +15 -0
  316. package/dist/text/sanitize-untrusted-text.d.ts +1 -1
  317. package/dist/text/sanitize-untrusted-text.js +2 -1
  318. package/dist/text/tagged-text-suppression.d.ts +103 -0
  319. package/dist/text/tagged-text-suppression.js +143 -0
  320. package/dist/text/template-i18n.d.ts +37 -0
  321. package/dist/text/template-i18n.js +48 -0
  322. package/dist/tool-call-text.d.ts +59 -0
  323. package/dist/tool-call-text.js +62 -0
  324. package/dist/tool-input-envelope.js +8 -4
  325. package/dist/tool-input-normalization.js +8 -1
  326. package/dist/tool-input-repairs.d.ts +58 -0
  327. package/dist/tool-input-repairs.js +154 -0
  328. package/dist/tool-tokens.js +1 -1
  329. package/dist/user-facing-error.d.ts +1 -1
  330. package/dist/user-facing-error.js +3 -1
  331. package/package.json +235 -14
  332. package/plugin-directory.d.ts +2 -2
  333. package/plugin-directory.js +16 -10
  334. package/dist/settings/express/contracts.js +0 -2
  335. package/dist/settings/express/http-request.d.ts +0 -33
  336. package/dist/settings/express/http-request.js +0 -50
  337. package/dist/settings/express/http.d.ts +0 -10
  338. package/dist/settings/express/http.js +0 -196
  339. package/dist/settings/express/index.d.ts +0 -5
  340. package/dist/settings/express/index.js +0 -4
  341. package/dist/settings/express/shared.d.ts +0 -68
  342. package/dist/settings/express/stream.d.ts +0 -24
  343. package/dist/settings/express/stream.js +0 -171
@@ -0,0 +1,118 @@
1
+ import type { Clock, IdGenerator, JsonObject, UUID } from "../../primitives/index.js";
2
+ import type { ChangeSetOperation, ChangeSetRepoPort } from "./change-set.js";
3
+ import type { OutboxPort } from "./ports.js";
4
+ /** Principal executing a command. Agents act on behalf of a user. */
5
+ export interface CommandActor {
6
+ id: UUID;
7
+ kind: "user" | "agent";
8
+ /** User the agent is acting for; unset for direct human commands. */
9
+ onBehalfOfId?: UUID | undefined;
10
+ }
11
+ /** Cross-cutting command metadata; the mutation itself lives in `CommandMutation`. */
12
+ export interface CommandEnvelope {
13
+ workspaceId: UUID;
14
+ actor: CommandActor;
15
+ /** Human-readable description recorded on the change set. */
16
+ summary: string;
17
+ /** Supplied by retry-capable callers (agents must always send one). */
18
+ idempotencyKey?: string | undefined;
19
+ /** Chat message / plan step that motivated this command. */
20
+ intentRef?: string | undefined;
21
+ /**
22
+ * The permission this mutation requires, e.g.
23
+ * `"content.write"`. Must be supplied together with `ExecuteCommandDeps.authorize`
24
+ * — see that field's doc for the migration story. Optional only so gateway
25
+ * callers not yet migrated to real identity/authorize wiring keep compiling.
26
+ */
27
+ permission?: string | undefined;
28
+ }
29
+ /** The entity write a command performs, with its inverse capture. */
30
+ export interface CommandMutation<TResult> {
31
+ entityType: string;
32
+ entityId: UUID;
33
+ operation: ChangeSetOperation;
34
+ /**
35
+ * Snapshot whatever is needed to undo this mutation, read *before* execute.
36
+ * Return null when no inverse exists — the change set is then recorded but
37
+ * cannot be reverted (and agents must not be offered this mutation).
38
+ */
39
+ captureInverse(): Promise<JsonObject | null>;
40
+ /** The actual feature call. Runs only after inverse capture succeeds. */
41
+ execute(): Promise<TResult>;
42
+ /**
43
+ * Read the entity's version from the execute result (the version *after* the
44
+ * mutation). Stamped onto the item as the revert guard input.
45
+ * Omit for entity types without a version.
46
+ * See docs/decisions/DR-006-mutation-audit-atomicity.md.
47
+ */
48
+ captureEntityVersion?(required: {
49
+ result: TResult;
50
+ }, optional?: Record<string, never>): number | null;
51
+ /**
52
+ * Compensating rollback for the memory adapter's all-or-nothing guarantee
53
+ * If version capture, record preparation or persistence fails
54
+ * *after* `execute` has applied the feature mutation, the gateway calls this
55
+ * to undo the mutation — restoring the entity to its exact pre-`execute` state
56
+ * (verbatim, including `version`) so no "mutation without a record" survives
57
+ * On the SQLite adapter a real transaction replaces this and
58
+ * `rollback` may be a no-op/omitted only when a caller-owned transaction covers
59
+ * the feature write AND all subsequent record preparation/persistence. The gateway
60
+ * opens no such transaction itself. Without rollback or that outer transaction, a
61
+ * post-mutation failure rejects but leaves the feature mutation applied (
62
+ * is not guaranteed). A rollback rejection takes precedence over the original error.
63
+ * See docs/decisions/DR-006-mutation-audit-atomicity.md.
64
+ */
65
+ rollback?(): Promise<void>;
66
+ }
67
+ /**
68
+ * The shape of the `authorize()` gate, kept generic here so
69
+ * `core/commands` never imports the `identity` library (that would invert the
70
+ * dependency direction — `features`/libraries depend on `core`, not the
71
+ * reverse; see `packages/user-management/src/server/authorize.ts`'s file header). Composition roots
72
+ * (the host's composition root) bind a closure over the real
73
+ * `identity.authorize()` and its repos, and pass that closure as
74
+ * `ExecuteCommandDeps.authorize`.
75
+ */
76
+ export type AuthorizeFn = (params: {
77
+ principalId: UUID;
78
+ permission: string;
79
+ workspaceId: UUID;
80
+ entityType?: string | undefined;
81
+ entityId?: UUID | undefined;
82
+ }) => Promise<{
83
+ allowed: boolean;
84
+ reason: string;
85
+ }>;
86
+ /** Dependencies for executeCommand. */
87
+ export interface ExecuteCommandDeps {
88
+ clock: Clock;
89
+ idGen: IdGenerator;
90
+ changeSets: ChangeSetRepoPort;
91
+ /** When provided, `change-set.applied` is enqueued for async consumers. */
92
+ outbox?: OutboxPort | undefined;
93
+ /**
94
+ * Authorization gate. Must be supplied together with
95
+ * `CommandEnvelope.permission` — omitting one while supplying the other is a
96
+ * wiring bug (see `executeCommand`'s guard) rather than something that
97
+ * should silently allow or silently skip. Omitting BOTH is the legacy
98
+ * pre-identity path, kept so gateway callers not yet migrated to real
99
+ * identity/authorize wiring keep compiling and passing (see the Programmer
100
+ * handoff for which routes remain unconverted this pass).
101
+ */
102
+ authorize?: AuthorizeFn | undefined;
103
+ }
104
+ /** Required parameters for executeCommand. */
105
+ export interface ExecuteCommandRequired<TResult> {
106
+ deps: ExecuteCommandDeps;
107
+ command: CommandEnvelope;
108
+ mutation: CommandMutation<TResult>;
109
+ }
110
+ /** Optional parameters for executeCommand. Reserved for future use. */
111
+ export interface ExecuteCommandOptional {
112
+ }
113
+ /** The audited write gateway's shape; cms implements it (`executeCommand`), consumers take it injected. */
114
+ export type ExecuteCommandFn = <TResult>(required: ExecuteCommandRequired<TResult>, optional?: ExecuteCommandOptional) => Promise<{
115
+ result: TResult;
116
+ changeSetId: UUID;
117
+ }>;
118
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1,172 @@
1
+ /**
2
+ * @file Event, outbox and transaction-boundary port contracts.
3
+ *
4
+ * Purpose:
5
+ * Defines the stable interfaces that domain/application code depends on to publish events and deliver them reliably.
6
+ *
7
+ * Architectural role:
8
+ * This file is the dependency inversion seam. Hosts provide in-memory or durable implementations and compose them in
9
+ * their composition root. Concrete infrastructure can change without changing feature logic as long as implementations
10
+ * satisfy these types.
11
+ *
12
+ * Design goal:
13
+ * Core/domain code depends on interfaces from this file only, never on concrete infrastructure SDKs or
14
+ * framework-specific implementations.
15
+ */
16
+ import type { UUID, ISODateTime } from "../../primitives/index.js";
17
+ /**
18
+ * Immutable domain event emitted by synchronous command handlers and delivered
19
+ * asynchronously via the outbox pipeline.
20
+ */
21
+ export interface DomainEvent<TPayload = Record<string, unknown>> {
22
+ /** Unique identifier for the event record. */
23
+ id: UUID;
24
+ /** Stable event name, e.g. `workspace.created`. */
25
+ name: string;
26
+ /** ISO timestamp describing when the event was produced. */
27
+ occurredAt: ISODateTime;
28
+ /** Optional aggregate root identifier related to this event. */
29
+ aggregateId?: UUID;
30
+ /**
31
+ * Tenant/workspace boundary. Required: every domain event belongs to a
32
+ * workspace. Platform-level events must be a deliberate future
33
+ * decision, not an omission.
34
+ */
35
+ workspaceId: UUID;
36
+ /**
37
+ * Principal (user or AI agent) that caused this event. Reserved change-set
38
+ * vocabulary; optional until the identity library lands.
39
+ */
40
+ actorId?: UUID;
41
+ /**
42
+ * Change set this event belongs to, enabling propose/preview/apply/revert
43
+ * grouping. Reserved change-set vocabulary.
44
+ */
45
+ changeSetId?: UUID;
46
+ /** Event-specific payload. */
47
+ payload: TPayload;
48
+ /** Free-form metadata (trace IDs, source, etc.). */
49
+ metadata?: Record<string, unknown>;
50
+ }
51
+ /**
52
+ * Event bus abstraction used by the application layer.
53
+ *
54
+ * This is intentionally generic so implementations can be in-memory, queue-based,
55
+ * broker-based, or provider-managed without changing domain logic.
56
+ */
57
+ export interface EventBusPort {
58
+ /** Publish a single event to subscribers. */
59
+ publish<TPayload>(event: DomainEvent<TPayload>): Promise<void>;
60
+ /** Publish multiple events in order. */
61
+ publishBatch<TPayload>(required: {
62
+ events: Array<DomainEvent<TPayload>>;
63
+ }, optional?: Record<string, never>): Promise<void>;
64
+ /**
65
+ * Subscribe a handler to an event name.
66
+ * Returns an async unsubscriber function.
67
+ */
68
+ subscribe<TPayload>(required: {
69
+ eventName: string;
70
+ handler: (event: DomainEvent<TPayload>) => Promise<void>;
71
+ }, optional?: Record<string, never>): Promise<() => Promise<void>>;
72
+ /**
73
+ * Subscribe a handler to every event published on this bus, regardless of name. Additive to
74
+ * `subscribe` — existing per-name callers are unaffected.
75
+ * The Integrations fan-out (`registerWebhookFanout`) is the first real consumer: it narrows
76
+ * by topic itself rather than requiring a fixed list of event names up front.
77
+ */
78
+ subscribeAll(required: {
79
+ handler: (event: DomainEvent) => Promise<void>;
80
+ }, optional?: Record<string, never>): Promise<() => Promise<void>>;
81
+ }
82
+ /**
83
+ * Persisted outbox row used for reliable async event delivery.
84
+ */
85
+ export interface OutboxRecord {
86
+ /** Primary key for the outbox row (same as `event.id`). */
87
+ id: UUID;
88
+ /**
89
+ * The full event envelope. The outbox must preserve everything the producer
90
+ * emitted (workspaceId, aggregateId, actorId, occurredAt, metadata) so
91
+ * delivery replays the original event, not a reconstruction.
92
+ */
93
+ event: DomainEvent;
94
+ /** Delivery lifecycle state. */
95
+ status: "pending" | "processing" | "delivered" | "failed";
96
+ /** Number of delivery attempts so far. */
97
+ attempts: number;
98
+ /** Retry eligibility timestamp. */
99
+ nextAttemptAt: ISODateTime;
100
+ /** Most recent delivery failure reason. */
101
+ lastError?: string | undefined;
102
+ /** Row creation timestamp. */
103
+ createdAt: ISODateTime;
104
+ }
105
+ /**
106
+ * Reliable outbox contract.
107
+ *
108
+ * Command handlers enqueue events here in the same unit of work as the write.
109
+ * A worker later claims and delivers rows to the event bus.
110
+ */
111
+ export interface OutboxPort {
112
+ /** Append an event for later delivery. */
113
+ enqueue(event: DomainEvent): Promise<void>;
114
+ /** Claim pending rows for processing. */
115
+ claimPending(required: {
116
+ batchSize: number;
117
+ nowIso: ISODateTime;
118
+ }, optional?: Record<string, never>): Promise<OutboxRecord[]>;
119
+ /** Mark a row as delivered. */
120
+ markDelivered(required: {
121
+ id: UUID;
122
+ }, optional?: Record<string, never>): Promise<void>;
123
+ /**
124
+ * Mark a row as failed and set its next retry time.
125
+ *
126
+ * `nextStatus` is decided by the CALLER (the retry-policy owner, e.g. a worker that tracks an
127
+ * attempt cap) — an implementation must persist exactly what it is told, not re-derive the
128
+ * decision from the row's own stored `attempts` (2026-09-06: this parameter replaced that
129
+ * adapter-side re-derivation, mirroring `WebhookDeliveryRepoPort.markFailed`'s `nextStatus`
130
+ * shape in the host). `"pending"` re-enters the retry queue at `nextAttemptAt`; `"failed"`
131
+ * is terminal — `claimPending` only ever selects `"pending"` rows, so a `"failed"` row is
132
+ * permanently excluded from retry regardless of `nextAttemptAt`.
133
+ */
134
+ markFailed(required: {
135
+ id: UUID;
136
+ error: string;
137
+ nextAttemptAt: ISODateTime;
138
+ nextStatus: Extract<OutboxRecord["status"], "pending" | "failed">;
139
+ }, optional?: Record<string, never>): Promise<void>;
140
+ }
141
+ /** Clock and ID generator contracts are owned by the shared kernel primitives. */
142
+ /**
143
+ * Opens/commits/rolls back one transaction around `fn` — the same shape and contract as this
144
+ * codebase's other write chokepoints that need one (`RedirectsWriteDeps.transaction`,
145
+ * `SqliteSettingsRepo.transaction`).
146
+ *
147
+ * `deleteTerm`/`deleteTaxonomy` run their ENTIRE body — every guard read (`findById`,
148
+ * `countChildren`, `countByTerm`) AND every write (`delete`, `revisions.insert`, `outbox.enqueue`)
149
+ * — inside one call to this. Two failure modes this closes that a guard-then-transaction split
150
+ * would not:
151
+ *
152
+ * 1. **TOCTOU on the guard.** A guard read taken BEFORE the transaction opens can go stale the
153
+ * instant it returns — content can be assigned to the term in the gap between the read and the
154
+ * delete, and the delete would proceed having checked a now-wrong count. Putting the read
155
+ * inside the same transaction as the delete is what makes the guard's answer still true at the
156
+ * moment the delete actually runs.
157
+ * 2. **Partial cascade.** `deleteTaxonomy` deletes N member terms then the taxonomy row itself,
158
+ * with no FK/CASCADE at the schema level (the host schema — `taxonomies`/`terms`/`entry_terms`/
159
+ * `taxonomy_revisions` are plain columns, no foreign keys) to undo a mid-cascade failure. A
160
+ * real transaction is the only thing that can.
161
+ *
162
+ * A caller-supplied identity/no-op implementation is a valid choice for a backend that has no
163
+ * separate transaction primitive to offer (see `repo.memory.ts`'s `InMemoryTaxonomyRepo` for the
164
+ * disclosed rationale) — the port exists so `deleteTerm`/`deleteTaxonomy` never have to know which
165
+ * kind of backend they're running against.
166
+ */
167
+ export interface TransactionalRepoPort {
168
+ transaction<T>({ fn }: {
169
+ fn: () => Promise<T>;
170
+ }): Promise<T>;
171
+ }
172
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1,5 @@
1
+ /** @agent-note Types only: the generic command/event/outbox vocabulary. The gateway (`executeCommand`) lives in `@jini-ai/cms/core`. */
2
+ export type * from "./events/ports.js";
3
+ export type * from "./events/change-set.js";
4
+ export type * from "./events/command.js";
5
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1,110 @@
1
+ /** @agent-note Types and one constant. What form-collection providers and form-submission records share. */
2
+ /** Contract name under which form-collection providers register. */
3
+ export declare const FORM_COLLECTION_CONTRACT = "form_collection";
4
+ export interface FormProviderSelection {
5
+ readonly id: string;
6
+ readonly config: Readonly<Record<string, string>>;
7
+ }
8
+ export interface FormCollectionCapabilities {
9
+ readonly answers: string;
10
+ readonly validation: string;
11
+ readonly spamProtection: string;
12
+ }
13
+ /** Public settings only; secrets and provider credentials never belong in form definitions. */
14
+ export interface FormProviderDescription {
15
+ readonly id: string;
16
+ readonly label: string;
17
+ readonly fields: readonly {
18
+ readonly key: string;
19
+ readonly label: string;
20
+ readonly type: 'text' | 'url';
21
+ readonly helpText?: string;
22
+ }[];
23
+ readonly helpText?: string;
24
+ readonly answers: string;
25
+ readonly validation: string;
26
+ readonly frameOrigins: readonly string[];
27
+ readonly available: boolean;
28
+ readonly message?: string;
29
+ }
30
+ export type FormCollectionPlan = {
31
+ readonly kind: 'post';
32
+ readonly action: string;
33
+ readonly external: boolean;
34
+ readonly capabilities: FormCollectionCapabilities;
35
+ } | {
36
+ readonly kind: 'embed';
37
+ readonly url: string;
38
+ readonly title: string;
39
+ readonly capabilities: FormCollectionCapabilities;
40
+ readonly consent?: readonly ('necessary' | 'functional' | 'analytics' | 'marketing')[];
41
+ readonly publicUrl?: string;
42
+ readonly fallbackMessage?: string;
43
+ } | {
44
+ readonly kind: 'unavailable';
45
+ readonly code: 'provider_unavailable' | 'invalid_configuration';
46
+ readonly message: string;
47
+ };
48
+ export interface FormCollectionProvider {
49
+ describe?(): Omit<FormProviderDescription, 'id' | 'available'>;
50
+ plan(required: {
51
+ readonly slug: string;
52
+ readonly config: Readonly<Record<string, string>>;
53
+ }, optional?: Record<string, never>): FormCollectionPlan;
54
+ }
55
+ export interface FormFileReference {
56
+ mediaId: string;
57
+ filename: string;
58
+ contentType: string;
59
+ byteSize: number;
60
+ }
61
+ export type FormAnswer = string | boolean | number | string[] | FormFileReference;
62
+ /** A declared form field. `T` names the host's field-type vocabulary; the vocabulary itself is host policy. */
63
+ export interface FormFieldDescriptor<T extends string = string> {
64
+ id: string;
65
+ label: string;
66
+ type: T;
67
+ required: boolean;
68
+ /** Optional HTML name; must equal the stable id so historic submission keys remain valid. */
69
+ name?: string;
70
+ placeholder?: string;
71
+ helpText?: string;
72
+ default?: string | number | boolean | string[];
73
+ options?: Array<{
74
+ value: string;
75
+ label: string;
76
+ }>;
77
+ minLength?: number;
78
+ maxLength?: number | null;
79
+ /** Full-match, bounded safe regular expression; groups/alternation/backreferences are refused. */
80
+ pattern?: string;
81
+ min?: number | string;
82
+ max?: number | string;
83
+ step?: number;
84
+ /** Omitted accept means every recognized safe type, never executable/markup/archive formats. */
85
+ accept?: string[];
86
+ maxFileSize?: number;
87
+ /** Presence distinguishes an authored checkbox value (even "") from the native boolean default. */
88
+ checkboxValue?: string;
89
+ /** Length-bounded and HTML-escaped at rendering; class names are inert after escaping. */
90
+ className?: string;
91
+ /** Attribute names require a closed allowlist: escaping a name cannot make it safe.
92
+ * Values remain plain strings and must be HTML-escaped by the renderer. */
93
+ attributes?: Record<string, string>;
94
+ }
95
+ /** Immutable form-owned context; answers remain in the existing answer map, never in evidence. */
96
+ export interface FormSubmissionEvidence<T extends string = string> {
97
+ readonly version: 1;
98
+ readonly fields: FormFieldDescriptor<T>[];
99
+ readonly consent: Array<{
100
+ fieldId: string;
101
+ wording: string;
102
+ helpText?: string;
103
+ }>;
104
+ readonly schemaHash: string;
105
+ readonly capturedAt: string;
106
+ readonly source: 'native' | 'cloudflare';
107
+ /** Complete authored body retains consent prose outside checkbox labels without guessing. */
108
+ readonly html?: string;
109
+ }
110
+ //# sourceMappingURL=forms.d.ts.map
@@ -0,0 +1,4 @@
1
+ /** @agent-note Types and one constant. What form-collection providers and form-submission records share. */
2
+ /** Contract name under which form-collection providers register. */
3
+ export const FORM_COLLECTION_CONTRACT = 'form_collection';
4
+ //# sourceMappingURL=forms.js.map
@@ -112,6 +112,8 @@ export interface ExternalMcpServerView<TokenHint = never> {
112
112
  /** For `stdio` + `static_env`: the child env variable that receives that token. A NAME, so plaintext. */
113
113
  accessTokenEnvName: string | null;
114
114
  oauth: ExternalMcpOAuthView;
115
+ /** Edit revision; send it back as `expectedVersion` on the next save so an edit from an old screen is refused. */
116
+ version: number;
115
117
  }
116
118
  /**
117
119
  * The OAuth half of a save. Every field follows the same three-state rule `env` established:
@@ -174,6 +176,12 @@ export interface SaveExternalMcpServerInput {
174
176
  * keeps the stored name. */
175
177
  accessTokenEnvName?: string;
176
178
  oauth?: SaveExternalMcpOAuthInput;
179
+ /**
180
+ * The `version` the person (or tool) loaded this row at. Present: an edit from an older screen is refused with a
181
+ * `RecordVersionConflictError`. Absent: the save is compared against the version read in the same request, which does
182
+ * not protect against a stale screen (kept only until every caller sends it).
183
+ */
184
+ expectedVersion?: number;
177
185
  /**
178
186
  * Set ONLY by the host's trusted plugin provisioner, on the ONE save that creates a brand-new
179
187
  * plugin-provisioned row. Every other caller (including administrative routes and assistant
@@ -250,4 +258,15 @@ export interface ExternalMcpDeviceStart {
250
258
  }
251
259
  /** @agent-note Discriminated by `kind`; hosts render each arm, packages never build host links here. */
252
260
  export type ExternalMcpConnectStart = ExternalMcpAuthorizationStart | ExternalMcpDeviceStart;
261
+ /** Machine-readable reason a saved, enabled server could not become a usable config. Only reauthorization is
262
+ * distinguished today; callers branch on this, never on `reason` wording. */
263
+ export type ExternalMcpConfigFailureCategory = "reauth_required";
264
+ /** @agent-note One saved, enabled server the hosted store could not resolve. `reason` is operator-facing prose
265
+ * (the host's settings link interpolated; never a secret or provider text). `category` is absent for an
266
+ * ordinary resolution failure (unreadable credentials, misconfigured row, token endpoint unreachable). */
267
+ export interface ExternalMcpConfigFailure {
268
+ readonly serverId: string;
269
+ readonly reason: string;
270
+ readonly category?: ExternalMcpConfigFailureCategory;
271
+ }
253
272
  //# sourceMappingURL=config.d.ts.map
@@ -100,6 +100,13 @@ export interface ExternalMcpServerRecord {
100
100
  oauthAadVersion: number;
101
101
  createdAt: ISODateTime;
102
102
  updatedAt: ISODateTime;
103
+ /**
104
+ * Edit revision, starting at 1. Advanced by every write an editor can see: a form save, an access
105
+ * approval or revocation, a credential removed by recovery. NOT advanced by runtime writes (token
106
+ * refresh, OAuth status, lease), so background activity never makes a person's save conflict.
107
+ * @agent-note Compared in the write statement (`updateIfVersion`), never in application code alone. A caller that holds a `version` read earlier and sends it back as the basis is protected against a save from an old screen; a lock or a same-request read is not that protection.
108
+ */
109
+ version: number;
103
110
  }
104
111
  /** A conditional access-only write. Credential and connection configuration are never replaced. */
105
112
  /** @agent-note Built by the host from an `ExternalMcpApprovedAccess`; the repository applies it atomically or returns `false`. Credential and connection columns are never part of it. */
@@ -115,7 +122,29 @@ export interface ExternalMcpAccessUpdate {
115
122
  readonly principalId: string;
116
123
  readonly nowIso: ISODateTime;
117
124
  }
118
- /** Workspace-scoped persistence. Multi-row per workspace, so list/upsert/delete rather
125
+ /** Which server row a runtime write addresses. */
126
+ export interface ExternalMcpServerKey {
127
+ readonly workspaceId: UUID;
128
+ readonly serverId: string;
129
+ }
130
+ /** The credential envelopes an edit was built from, exactly as the writer read them from the stored row. */
131
+ /** @agent-note The repository compares these against the row's current vault pointers inside its write. A miss with an unchanged `version` means a runtime write (token refresh) moved a credential between the writer's read and its write: the writer re-reads and rebuilds once. Never re-sealed or edited by the caller. */
132
+ export interface ExternalMcpReplacedSecrets {
133
+ readonly sealedEnv: SealedSecret | null;
134
+ readonly sealedOAuth: SealedSecret | null;
135
+ }
136
+ /** The only columns a runtime (non-edit) OAuth write may change. */
137
+ /** @agent-note Deliberately has no label, enabled flag, grants, url or version: a token refresh must not restore the values it read before it called the provider. */
138
+ export interface ExternalMcpOAuthRuntimePatch {
139
+ readonly oauthStatus: string | null;
140
+ readonly oauthExpiresAt: ISODateTime | null;
141
+ readonly oauthRefreshLeaseUntil: ISODateTime | null;
142
+ /** The new staged envelope, or `null` to drop the stored one (a cleared token with no client secret to keep). */
143
+ readonly sealedOAuth: SealedSecret | null;
144
+ readonly oauthAadVersion: number;
145
+ readonly updatedAt: ISODateTime;
146
+ }
147
+ /** Workspace-scoped persistence. Multi-row per workspace, so list/insert/update/delete rather
119
148
  * than a single-row find/upsert. */
120
149
  /** @agent-note Fulfilled by the host (SQL or memory adapter). The store, the sign-in service and the plugin connect seam must receive the SAME repository instance, because sealed envelopes carry private repository context only that repository rebuilds. */
121
150
  export interface ExternalMcpServerRepoPort {
@@ -126,11 +155,39 @@ export interface ExternalMcpServerRepoPort {
126
155
  workspaceId: UUID;
127
156
  serverId: string;
128
157
  }): Promise<ExternalMcpServerRecord | null>;
129
- /** @agent-note Writes the whole row in one transaction (row, vault pointer, status and expiry together). */
158
+ /** @agent-note Writes the whole row in one transaction (row, vault pointer, status and expiry together). Replaces any stored row blindly, so it is not allowed for an edit: use `insert` / `updateIfVersion` / `updateOAuthRuntime`. */
130
159
  upsert(record: ExternalMcpServerRecord): Promise<void>;
160
+ /**
161
+ * Creates the row at `version` 1. `false` when a row with this key already exists; nothing is written.
162
+ * @agent-note One transaction (row + staged envelopes). Never overwrites: a create that lost a race to another create reports `false`.
163
+ */
164
+ insert(required: {
165
+ readonly record: ExternalMcpServerRecord;
166
+ }): Promise<boolean>;
167
+ /**
168
+ * The edit write: replaces the editable columns and both credential pointers iff the stored
169
+ * `version` equals `expectedVersion` AND both stored envelopes are the ones in `replaces`; sets
170
+ * `version` to `expectedVersion + 1`. `false` when nothing was written (the row is gone, moved on, or a credential was replaced since the read).
171
+ * @agent-note Compare-and-set in the write statement under the same writer lock the credential writers take. `record.version` is ignored; the repository assigns the next version.
172
+ */
173
+ updateIfVersion(required: {
174
+ readonly record: ExternalMcpServerRecord;
175
+ readonly expectedVersion: number;
176
+ readonly replaces: ExternalMcpReplacedSecrets;
177
+ }): Promise<boolean>;
178
+ /**
179
+ * The runtime write: sets only the sealed-OAuth pointer, `oauthStatus`, `oauthExpiresAt`,
180
+ * `oauthRefreshLeaseUntil`, `oauthAadVersion` and `updatedAt`, iff the stored sealed-OAuth envelope is `expectedSealedOAuth`. Leaves `version` and every other column alone. `false` when the credential was replaced or removed, or the row is gone.
181
+ * @agent-note A late token set for a credential that no longer exists is dropped, never written onto its replacement. The caller reports it as "reauthorization required".
182
+ */
183
+ updateOAuthRuntime(required: {
184
+ readonly key: ExternalMcpServerKey;
185
+ readonly expectedSealedOAuth: SealedSecret | null;
186
+ readonly patch: ExternalMcpOAuthRuntimePatch;
187
+ }): Promise<boolean>;
131
188
  /** Compare the approved snapshot and update access atomically, preserving credential columns. */
132
- /** @agent-note Compare-and-set against `expected`; `false` means the row changed since approval and nothing was written. */
133
- updateAccessIfCurrent(required: ExternalMcpAccessUpdate, optional?: Record<string, never>): Promise<boolean>;
189
+ /** @agent-note Compare-and-set against `expected`; `false` means the row changed since approval and nothing was written. A successful write advances `version`, so a form saved from before the approval or revocation conflicts instead of restoring the old grants. */
190
+ updateAccessIfCurrent(required: ExternalMcpAccessUpdate): Promise<boolean>;
134
191
  /** @agent-note Returns whether a row existed. */
135
192
  deleteByServerId(input: {
136
193
  workspaceId: UUID;
@@ -0,0 +1,118 @@
1
+ /**
2
+ * MOVE: Event data and recipient authority belong to the originating feature, independently of
3
+ * delivery providers. Hosts bind authorization, templates and persistence; this surface sends nothing.
4
+ */
5
+ import type { EmailAddress, MailerSendOptions } from "../mail.js";
6
+ /** Explicit caller scope, including for background jobs running as a host service principal. */
7
+ export interface EmailSenderContext {
8
+ readonly workspaceId: string;
9
+ readonly principalId: string;
10
+ }
11
+ /** A concrete event source; the same event name may occur for several sources or senders. */
12
+ export interface EmailSourceRef {
13
+ readonly senderId: string;
14
+ readonly sourceId: string;
15
+ }
16
+ export interface EmailSourceSummary extends EmailSourceRef {
17
+ readonly label: string;
18
+ readonly eventName: string;
19
+ }
20
+ /** Token is the exact placeholder name, without braces. Labels are presentation only. */
21
+ export interface EmailSourceField {
22
+ readonly token: string;
23
+ readonly label: string;
24
+ readonly required: boolean;
25
+ }
26
+ /** Recipient ids are source-owned choices, never caller-supplied addresses or expressions. */
27
+ export interface EmailRecipientChoice {
28
+ readonly id: string;
29
+ readonly label: string;
30
+ }
31
+ export interface EmailReadiness {
32
+ readonly ready: boolean;
33
+ readonly blockers: readonly string[];
34
+ }
35
+ /** Persisted by the sender's existing write owner, never by a template-side relationship. */
36
+ export interface EmailBindingInput {
37
+ readonly bindingId: string;
38
+ readonly enabled: boolean;
39
+ readonly templateId: string;
40
+ readonly recipientId: string;
41
+ readonly replyTo: string;
42
+ }
43
+ export interface EmailBinding extends EmailBindingInput {
44
+ readonly activatedAt: string | null;
45
+ }
46
+ export interface EmailSourceDescription extends EmailSourceSummary {
47
+ readonly fields: readonly EmailSourceField[];
48
+ readonly permittedRecipients: readonly EmailRecipientChoice[];
49
+ readonly purpose: NonNullable<MailerSendOptions["purpose"]>;
50
+ readonly lane: NonNullable<MailerSendOptions["lane"]>;
51
+ readonly binding: EmailBinding | null;
52
+ readonly readiness: EmailReadiness;
53
+ }
54
+ /** Only allowlisted event values and recipients cross this boundary; no stored event row. */
55
+ export interface ResolvedEmailEvent {
56
+ /** Authoritative ISO event time, compared with the binding's latest activation to prevent backfill. */
57
+ readonly occurredAt: string;
58
+ readonly values: Readonly<Record<string, string>>;
59
+ readonly recipients: readonly {
60
+ readonly id: string;
61
+ readonly address: EmailAddress;
62
+ }[];
63
+ }
64
+ export type EmailSourceRequest = EmailSenderContext & {
65
+ readonly sourceId: string;
66
+ };
67
+ /** Every operation must authorize its own scope. Resolution also verifies event/source ownership.
68
+ * No example-listing API: hosts may offer an authorized latest submission or a labeled sample. */
69
+ export interface EmailSender {
70
+ readonly id: string;
71
+ readonly label: string;
72
+ listSources(required: EmailSenderContext, optional?: Record<string, never>): Promise<readonly EmailSourceSummary[]>;
73
+ describeSource(required: EmailSourceRequest, optional?: Record<string, never>): Promise<EmailSourceDescription>;
74
+ resolveEvent(required: EmailSourceRequest & {
75
+ readonly eventId: string;
76
+ }, optional?: Record<string, never>): Promise<ResolvedEmailEvent>;
77
+ configureEmail(required: EmailSourceRequest & {
78
+ readonly binding: EmailBindingInput;
79
+ }, optional?: Record<string, never>): Promise<EmailBinding>;
80
+ }
81
+ /** Describe must report all placeholders, including those absent from the template declarations.
82
+ * Render must use send-safe rendering, supplied values only, and refuse a changed version. */
83
+ export interface EmailTemplatePort {
84
+ describe(required: EmailSenderContext & {
85
+ readonly templateId: string;
86
+ }, optional?: Record<string, never>): Promise<{
87
+ readonly version: string;
88
+ readonly fields: readonly string[];
89
+ readonly placeholders: readonly string[];
90
+ }>;
91
+ render(required: EmailSenderContext & {
92
+ readonly templateId: string;
93
+ readonly version: string;
94
+ readonly values: Readonly<Record<string, string>>;
95
+ }, optional?: Record<string, never>): Promise<{
96
+ readonly subject: string;
97
+ readonly html: string;
98
+ readonly text: string;
99
+ readonly missingFields: readonly string[];
100
+ }>;
101
+ }
102
+ /** Caller-safe failures never include event values, recipients or credentials. */
103
+ export declare class EmailSenderError extends Error {
104
+ readonly code: "forbidden" | "not_found" | "ownership" | "configuration" | "not_ready" | "incompatible" | "missing_value";
105
+ constructor(required: {
106
+ readonly code: EmailSenderError["code"];
107
+ }, _optional?: Record<string, never>);
108
+ }
109
+ /** Refuses unsupported declarations and undeclared placeholders before activation or rendering.
110
+ * @complexity O(f + d + p) source fields, declarations and placeholders; no I/O. */
111
+ export declare function validateEmailSourceTemplate(required: {
112
+ readonly fields: readonly EmailSourceField[];
113
+ readonly template: {
114
+ readonly fields: readonly string[];
115
+ readonly placeholders: readonly string[];
116
+ };
117
+ }, _optional?: Record<string, never>): void;
118
+ //# sourceMappingURL=email-sender.d.ts.map