@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,36 @@
1
+ /**
2
+ * @file The one way an error's own text reaches a caller. Redaction removes known secret shapes; it
3
+ * does not decide who may read a fact: a message can quote a draft, a customer note or a URL with a
4
+ * query string, and no redactor sees that. So the owner of an operation approves a cause explicitly,
5
+ * and the reporter shows it only to a caller authorised for that same step. Redaction still runs on
6
+ * an approved cause, as a second layer.
7
+ *
8
+ * The callers of {@link approveCause} are a reviewed list held by
9
+ * `scripts/check-error-disclosure-callers.ts` (run by `pnpm guard`), so adding one is a reviewed
10
+ * diff with the operation owner's reason beside it. A host keeps its own list for its own callers.
11
+ */
12
+ declare const approvedCauseBrand: unique symbol;
13
+ /** "A caller authorised for `step` may read this failure's redacted cause." Built only by {@link approveCause}. */
14
+ export interface ApprovedCause {
15
+ readonly step: string;
16
+ readonly cause: unknown;
17
+ readonly [approvedCauseBrand]: true;
18
+ }
19
+ /** Options of {@link approveCause} and {@link isApprovedCause}. None yet; named so one can be added without changing the signature. */
20
+ export interface ApproveCauseOptions {
21
+ }
22
+ /**
23
+ * Called by the feature that owns `step`. Means: a caller authorised for this step may read this
24
+ * failure's redacted cause.
25
+ * @complexity O(1).
26
+ */
27
+ export declare function approveCause(required: {
28
+ step: string;
29
+ cause: unknown;
30
+ }, _optional?: ApproveCauseOptions): ApprovedCause;
31
+ /** True only for a value {@link approveCause} returned. */
32
+ export declare function isApprovedCause(required: {
33
+ value: unknown;
34
+ }, _optional?: ApproveCauseOptions): boolean;
35
+ export {};
36
+ //# sourceMappingURL=approved-cause.d.ts.map
@@ -0,0 +1,17 @@
1
+ /** Every approval this module issued. An object of the same shape built elsewhere (a cast, parsed JSON) is not in it. */
2
+ const issued = new WeakSet();
3
+ /**
4
+ * Called by the feature that owns `step`. Means: a caller authorised for this step may read this
5
+ * failure's redacted cause.
6
+ * @complexity O(1).
7
+ */
8
+ export function approveCause(required, _optional = {}) {
9
+ const approval = Object.freeze({ step: required.step, cause: required.cause });
10
+ issued.add(approval);
11
+ return approval;
12
+ }
13
+ /** True only for a value {@link approveCause} returned. */
14
+ export function isApprovedCause(required, _optional = {}) {
15
+ return typeof required.value === 'object' && required.value !== null && issued.has(required.value);
16
+ }
17
+ //# sourceMappingURL=approved-cause.js.map
@@ -0,0 +1,61 @@
1
+ /** Any error class, whatever its constructor takes. */
2
+ export type ErrorClass = abstract new (...args: never[]) => Error;
3
+ /**
4
+ * Which words a binding publishes:
5
+ * - `own-message`: the error's own message. Correct only when every construction site builds that
6
+ * message from fixed text and the caller's own input.
7
+ * - `fixed`: this text instead, for a class whose kind is safe to name but whose message is not.
8
+ * - `sentence`: the catalog sentence for the code, with optional values for its placeholders.
9
+ */
10
+ export type ErrorText = {
11
+ readonly mode: 'own-message';
12
+ } | {
13
+ readonly mode: 'fixed';
14
+ readonly text: string;
15
+ } | {
16
+ readonly mode: 'sentence';
17
+ readonly params?: (required: {
18
+ error: Error;
19
+ }) => Readonly<Record<string, string | number>>;
20
+ };
21
+ /** One class means one code. */
22
+ export interface ClassErrorBinding {
23
+ readonly error: ErrorClass;
24
+ readonly code: string;
25
+ readonly text: ErrorText;
26
+ /** Recovery guidance for the model, appended after the message. */
27
+ readonly guidance?: string;
28
+ /** The fixed label this class is logged as. Never read from the value: a class name is text. */
29
+ readonly label?: string;
30
+ }
31
+ /** One class carries several codes; `codeOf` picks one, and only a value in `codes` is accepted. */
32
+ export interface DiscriminantErrorBinding {
33
+ readonly error: ErrorClass;
34
+ readonly codes: readonly string[];
35
+ readonly text: ErrorText;
36
+ readonly label?: string;
37
+ readonly codeOf: (required: {
38
+ error: Error;
39
+ }) => string | undefined;
40
+ }
41
+ export type ErrorBinding = ClassErrorBinding | DiscriminantErrorBinding;
42
+ /** The bindings of one scope, in the order they are tried. First `instanceof` match wins. */
43
+ export interface ErrorScope {
44
+ readonly scope: string;
45
+ readonly bindings: readonly ErrorBinding[];
46
+ }
47
+ /** Options of {@link defineErrorScope}. None yet; named so one can be added without changing the signature. */
48
+ export interface ErrorScopeOptions {
49
+ }
50
+ /**
51
+ * Declares the bindings of one scope. Order matters: list a subclass before its superclass (the
52
+ * catalog rejects the reverse, because the later binding could never match).
53
+ * @throws TypeError for a scope name, code, label or text of the wrong shape (a programming error, found at load).
54
+ * @example defineErrorScope({ scope: 'members', bindings: [{ error: MemberNotFoundError, code: 'MEMBERS_NOT_FOUND', text: { mode: 'own-message' } }] })
55
+ * @complexity O(bindings).
56
+ */
57
+ export declare function defineErrorScope(required: {
58
+ scope: string;
59
+ bindings: readonly ErrorBinding[];
60
+ }, _optional?: ErrorScopeOptions): ErrorScope;
61
+ //# sourceMappingURL=bindings.d.ts.map
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @file Relation 2 of the error catalog: "in this scope, this error class means this code".
3
+ * Bindings are grouped by scope, ordered, and many-to-many on purpose: one class can mean different
4
+ * codes in different scopes, two classes can share a code, and one class can carry several codes
5
+ * through a discriminant. Server-side: a bindings file imports the feature's error classes, so the
6
+ * browser never imports it (the words live in `sentences.ts`).
7
+ */
8
+ import { isErrorCodeToken } from './sentences.js';
9
+ const SCOPE_NAME = /^[a-z][a-z0-9-]{0,63}$/;
10
+ const CLASS_LABEL = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
11
+ const TEXT_MODES = new Set(['own-message', 'fixed', 'sentence']);
12
+ function textProblem({ text }) {
13
+ if (typeof text !== 'object' || text === null || !TEXT_MODES.has(text.mode))
14
+ return 'text.mode must be "own-message", "fixed" or "sentence"';
15
+ if (text.mode === 'fixed' && (typeof text.text !== 'string' || !text.text.trim()))
16
+ return 'a "fixed" text needs the words to publish';
17
+ if (text.mode === 'sentence' && text.params !== undefined && typeof text.params !== 'function')
18
+ return 'text.params must be a function';
19
+ return undefined;
20
+ }
21
+ function codesProblem({ binding }) {
22
+ if (!('codes' in binding)) {
23
+ return isErrorCodeToken({ code: binding.code }) ? undefined : `the code "${String(binding.code)}" must be a constant token like MEMBERS_NOT_FOUND`;
24
+ }
25
+ if (typeof binding.codeOf !== 'function')
26
+ return 'a binding with "codes" needs a codeOf function';
27
+ if (!Array.isArray(binding.codes) || binding.codes.length === 0)
28
+ return 'a binding with codeOf needs a non-empty "codes" list';
29
+ const bad = binding.codes.find(code => !isErrorCodeToken({ code }));
30
+ return bad === undefined ? undefined : `the code "${String(bad)}" must be a constant token like FORM_DELIVERY_RATE_LIMITED`;
31
+ }
32
+ function bindingProblem({ binding }) {
33
+ if (typeof binding !== 'object' || binding === null || typeof binding.error !== 'function')
34
+ return 'each binding needs an error class';
35
+ if (binding.label !== undefined && !CLASS_LABEL.test(binding.label))
36
+ return 'a label must be an identifier like MemberNotFoundError';
37
+ return codesProblem({ binding }) ?? textProblem({ text: binding.text });
38
+ }
39
+ /**
40
+ * Declares the bindings of one scope. Order matters: list a subclass before its superclass (the
41
+ * catalog rejects the reverse, because the later binding could never match).
42
+ * @throws TypeError for a scope name, code, label or text of the wrong shape (a programming error, found at load).
43
+ * @example defineErrorScope({ scope: 'members', bindings: [{ error: MemberNotFoundError, code: 'MEMBERS_NOT_FOUND', text: { mode: 'own-message' } }] })
44
+ * @complexity O(bindings).
45
+ */
46
+ export function defineErrorScope(required, _optional = {}) {
47
+ const { scope, bindings } = required;
48
+ if (typeof scope !== 'string' || !SCOPE_NAME.test(scope))
49
+ throw new TypeError(`Error scope: the name "${String(scope)}" must be lower-case words joined by hyphens, like "content-post".`);
50
+ bindings.forEach((binding, index) => {
51
+ const problem = bindingProblem({ binding });
52
+ if (problem !== undefined)
53
+ throw new TypeError(`Error scope "${scope}", binding ${index + 1}: ${problem}.`);
54
+ });
55
+ return Object.freeze({ scope, bindings: Object.freeze(bindings.map(binding => Object.freeze({ ...binding }))) });
56
+ }
57
+ //# sourceMappingURL=bindings.js.map
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @file The error catalog: sentences keyed by code, bindings grouped by scope, and scoped lookup.
3
+ * It feeds the three existing consumers of "this class is safe and its code is X" (model-facing
4
+ * rules, caller-safe rules, the log describer) from one registration instead of adding a fourth.
5
+ * Immutable after creation; matching runs on the failure path only.
6
+ */
7
+ import type { CallerSafeErrorRule, ErrorDescriberVocabulary, ModelFacingErrorRule } from '../model-facing-tool-errors.js';
8
+ import type { Logger } from '../primitives/logger.js';
9
+ import type { ErrorScope, ErrorText } from './bindings.js';
10
+ import type { ErrorSentence, ErrorSentenceSet } from './sentences.js';
11
+ /** What one error means in one scope. */
12
+ export interface ErrorMatch {
13
+ readonly scope: string;
14
+ readonly code: string;
15
+ readonly mode: ErrorText['mode'];
16
+ /** The words the binding publishes. `own-message`: the error's own message, which the binding's
17
+ * owner listed as built from fixed text and the caller's own input. `fixed`: the binding's text.
18
+ * Absent in `sentence` mode. */
19
+ readonly message?: string;
20
+ /** `sentence` mode: values for the sentence's placeholders (strings and numbers, at most 16). */
21
+ readonly params?: Readonly<Record<string, string | number>>;
22
+ /** The sentence for the code, when a set defines one. */
23
+ readonly sentence?: ErrorSentence;
24
+ readonly guidance?: string;
25
+ readonly label?: string;
26
+ }
27
+ export interface ErrorCatalog {
28
+ /** Bindings of ONE scope, in order, first match wins. Never searches another scope. No match means incident. */
29
+ match(required: {
30
+ error: unknown;
31
+ scope: string;
32
+ }): ErrorMatch | undefined;
33
+ sentence(required: {
34
+ code: string;
35
+ }): ErrorSentence | undefined;
36
+ /** The sentence's status; `undefined` means "use the caller's own table" (a status is never `0`). */
37
+ statusFor(required: {
38
+ error: {
39
+ readonly code: string;
40
+ };
41
+ }): number | undefined;
42
+ modelFacingRules(required: {
43
+ scope: string;
44
+ }): readonly ModelFacingErrorRule[];
45
+ callerSafeRules(required: {
46
+ scope: string;
47
+ }): readonly CallerSafeErrorRule[];
48
+ /** Input for the unchanged `createErrorDescriber`: every catalog code, and each labelled class. */
49
+ describerVocabulary(): ErrorDescriberVocabulary;
50
+ /** Every source string a translation must cover (each message and action, once). */
51
+ sourceSentences(): readonly string[];
52
+ }
53
+ /**
54
+ * What to do when two sets define the same code, or two scopes share a name. `'throw'` (the
55
+ * default) is for a conformance test that builds the full host catalog. `'warn'` is for production,
56
+ * which keeps the first definition and never refuses to boot; it needs somewhere to write the warning.
57
+ */
58
+ export type ErrorCatalogOptions = {
59
+ readonly onDuplicate?: 'throw';
60
+ } | {
61
+ readonly onDuplicate: 'warn';
62
+ readonly logger: Pick<Logger, 'warn'>;
63
+ };
64
+ /**
65
+ * Builds the catalog from every feature's sentence sets and scopes.
66
+ *
67
+ * Lookup rules: the caller always names the scope and no other scope is searched; inside a scope the
68
+ * first `instanceof` match wins (subclass before superclass); two bindings may share a code; a
69
+ * discriminant's result counts only if it is in the binding's own list; an arbitrary error is never
70
+ * matched by its own `code` property, which is caller-writable.
71
+ *
72
+ * Rules returned for the model and for returned results are field-for-field today's rule shapes:
73
+ * `own-message` gives no `message` (the error's own message is published), `fixed` gives
74
+ * `message: text`. `sentence`-mode and discriminant bindings are not in them, so such a class stays
75
+ * unlisted for the model, which is the redacting default.
76
+ *
77
+ * @throws TypeError when a scope lists a superclass before its subclass, and (unless `onDuplicate: 'warn'`) for a duplicate sentence or scope.
78
+ * @complexity O(codes + bindings²) to build; O(bindings in the scope) per match.
79
+ */
80
+ export declare function createErrorCatalog(required: {
81
+ sentences: readonly ErrorSentenceSet[];
82
+ scopes: readonly ErrorScope[];
83
+ }, optional?: ErrorCatalogOptions): ErrorCatalog;
84
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1,151 @@
1
+ const MAX_PARAMS = 16;
2
+ function reportDuplicate({ what, optional }) {
3
+ if (optional.onDuplicate !== 'warn')
4
+ throw new TypeError(`Error catalog: ${what}. Remove one definition.`);
5
+ optional.logger.warn({ message: `[error-catalog] ${what}; keeping the first definition` });
6
+ }
7
+ function indexSentences({ sets, optional }) {
8
+ const byCode = new Map();
9
+ const owner = new Map();
10
+ for (const set of sets) {
11
+ for (const [code, sentence] of Object.entries(set.codes)) {
12
+ if (byCode.has(code))
13
+ reportDuplicate({ what: `the code "${code}" has a sentence in both "${owner.get(code)}" and "${set.domain}"`, optional });
14
+ else {
15
+ byCode.set(code, sentence);
16
+ owner.set(code, set.domain);
17
+ }
18
+ }
19
+ }
20
+ return byCode;
21
+ }
22
+ /** An earlier binding of the same class or a superclass matches first, so the later one is dead. */
23
+ function assertReachable({ scope }) {
24
+ scope.bindings.forEach((later, index) => {
25
+ const shadow = scope.bindings.slice(0, index).findIndex(earlier => later.error === earlier.error || later.error.prototype instanceof earlier.error);
26
+ if (shadow !== -1) {
27
+ throw new TypeError(`Error catalog: in scope "${scope.scope}", binding ${index + 1} can never match because binding ${shadow + 1} lists the same class or its superclass first. List the subclass first.`);
28
+ }
29
+ });
30
+ }
31
+ function indexScopes({ scopes, optional }) {
32
+ const byName = new Map();
33
+ for (const scope of scopes) {
34
+ assertReachable({ scope });
35
+ if (byName.has(scope.scope))
36
+ reportDuplicate({ what: `the scope "${scope.scope}" is defined twice`, optional });
37
+ else
38
+ byName.set(scope.scope, scope.bindings);
39
+ }
40
+ return byName;
41
+ }
42
+ /** The binding's code. A discriminant's `codeOf` is feature code: a throw, or a value outside its own list, is no match. */
43
+ function resolveCode({ binding, error }) {
44
+ if (!('codes' in binding))
45
+ return binding.code;
46
+ try {
47
+ const code = binding.codeOf({ error });
48
+ return typeof code === 'string' && binding.codes.includes(code) ? code : undefined;
49
+ }
50
+ catch {
51
+ // Rule: a throwing discriminant means "not classified". The caller then treats the original
52
+ // failure as an incident, which records that original error; nothing is lost.
53
+ return undefined;
54
+ }
55
+ }
56
+ function safeParams({ values }) {
57
+ if (typeof values !== 'object' || values === null)
58
+ return {};
59
+ const entries = Object.entries(values).filter((entry) => typeof entry[1] === 'string' || typeof entry[1] === 'number');
60
+ return Object.fromEntries(entries.slice(0, MAX_PARAMS));
61
+ }
62
+ /** The words a matched binding publishes. A throwing `params` is no match, for the same reason as {@link resolveCode}. */
63
+ function resolveText({ text, error }) {
64
+ try {
65
+ if (text.mode === 'fixed')
66
+ return { mode: text.mode, message: text.text };
67
+ if (text.mode === 'own-message')
68
+ return { mode: text.mode, message: String(error.message) };
69
+ return text.params === undefined ? { mode: text.mode } : { mode: text.mode, params: safeParams({ values: text.params({ error }) }) };
70
+ }
71
+ catch {
72
+ return undefined;
73
+ }
74
+ }
75
+ function matchBinding(required) {
76
+ const { error, scope, bindings, sentences } = required;
77
+ if (!(error instanceof Error))
78
+ return undefined;
79
+ const binding = bindings.find(candidate => error instanceof candidate.error);
80
+ if (binding === undefined)
81
+ return undefined;
82
+ const code = resolveCode({ binding, error });
83
+ const text = code === undefined ? undefined : resolveText({ text: binding.text, error });
84
+ if (code === undefined || text === undefined)
85
+ return undefined;
86
+ const sentence = sentences.get(code);
87
+ return {
88
+ scope, code, ...text,
89
+ ...(sentence === undefined ? {} : { sentence }),
90
+ ...('guidance' in binding && binding.guidance !== undefined ? { guidance: binding.guidance } : {}),
91
+ ...(binding.label === undefined ? {} : { label: binding.label }),
92
+ };
93
+ }
94
+ /** Class-to-code bindings that publish the error's own message or a fixed text: today's rule shapes. */
95
+ function ruleBindings({ bindings }) {
96
+ return bindings.filter((binding) => !('codes' in binding) && binding.text.mode !== 'sentence');
97
+ }
98
+ function vocabulary({ scopes, sentences }) {
99
+ const codes = new Set(sentences.keys());
100
+ const labels = new Map();
101
+ // The describer checks classes newest first; a scope lists subclasses first, so walk it backwards.
102
+ const bindings = [...scopes.values()].flatMap(scope => [...scope].reverse());
103
+ for (const binding of bindings) {
104
+ for (const code of 'codes' in binding ? binding.codes : [binding.code])
105
+ codes.add(code);
106
+ if (binding.label !== undefined && !labels.has(binding.error))
107
+ labels.set(binding.error, binding.label);
108
+ }
109
+ return { codes: [...codes], classes: [...labels].map(([error, label]) => ({ error, label })) };
110
+ }
111
+ /**
112
+ * Builds the catalog from every feature's sentence sets and scopes.
113
+ *
114
+ * Lookup rules: the caller always names the scope and no other scope is searched; inside a scope the
115
+ * first `instanceof` match wins (subclass before superclass); two bindings may share a code; a
116
+ * discriminant's result counts only if it is in the binding's own list; an arbitrary error is never
117
+ * matched by its own `code` property, which is caller-writable.
118
+ *
119
+ * Rules returned for the model and for returned results are field-for-field today's rule shapes:
120
+ * `own-message` gives no `message` (the error's own message is published), `fixed` gives
121
+ * `message: text`. `sentence`-mode and discriminant bindings are not in them, so such a class stays
122
+ * unlisted for the model, which is the redacting default.
123
+ *
124
+ * @throws TypeError when a scope lists a superclass before its subclass, and (unless `onDuplicate: 'warn'`) for a duplicate sentence or scope.
125
+ * @complexity O(codes + bindings²) to build; O(bindings in the scope) per match.
126
+ */
127
+ export function createErrorCatalog(required, optional = {}) {
128
+ const sentences = indexSentences({ sets: required.sentences, optional });
129
+ const scopes = indexScopes({ scopes: required.scopes, optional });
130
+ const describer = vocabulary({ scopes, sentences });
131
+ const source = [...new Set([...sentences.values()].flatMap(sentence => [sentence.message, sentence.action]))];
132
+ return {
133
+ match: ({ error, scope }) => {
134
+ const bindings = scopes.get(scope);
135
+ return bindings === undefined ? undefined : matchBinding({ error, scope, bindings, sentences });
136
+ },
137
+ sentence: ({ code }) => sentences.get(code),
138
+ statusFor: ({ error }) => sentences.get(error.code)?.status,
139
+ modelFacingRules: ({ scope }) => ruleBindings({ bindings: scopes.get(scope) ?? [] }).map(binding => ({
140
+ error: binding.error, code: binding.code,
141
+ ...(binding.text.mode === 'fixed' ? { message: binding.text.text } : {}),
142
+ ...(binding.guidance === undefined ? {} : { guidance: binding.guidance }),
143
+ })),
144
+ callerSafeRules: ({ scope }) => ruleBindings({ bindings: scopes.get(scope) ?? [] }).map(binding => ({
145
+ error: binding.error, ...(binding.text.mode === 'fixed' ? { message: binding.text.text } : {}),
146
+ })),
147
+ describerVocabulary: () => describer,
148
+ sourceSentences: () => source,
149
+ };
150
+ }
151
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @file Who may read what about an incident. The rule, stated once: redaction removes known secret
3
+ * shapes; it does not decide who may read a fact. No error text is shown to a caller because it was
4
+ * redacted. It is shown only when the owner of that operation approved it (`approveCause`) for a
5
+ * caller authorised for that same operation.
6
+ *
7
+ * | Audience | Gets |
8
+ * |---|---|
9
+ * | `anonymous` | the fallback words and the error ID. No details block |
10
+ * | `signed-in` | Copy details: ID, step, versions, time, and a fixed cause sentence |
11
+ * | `authorized` | the same, plus the listed class/code label; or the approved cause, redacted |
12
+ */
13
+ import type { SecretRedactionOptions } from '../redaction-patterns.js';
14
+ import { type UserFacingError } from '../user-facing-error.js';
15
+ import { type ApprovedCause } from './approved-cause.js';
16
+ /**
17
+ * `anonymous`: nobody is signed in. `signed-in`: an authenticated principal. `authorized`: the
18
+ * boundary's permission check for THIS operation has also passed.
19
+ */
20
+ export type ErrorAudience = 'anonymous' | 'signed-in' | 'authorized';
21
+ /** The cause every signed-in caller sees. It names where the facts are without stating any. */
22
+ export declare const INCIDENT_CAUSE_SENTENCE = "The error ID identifies the server report.";
23
+ /** Options of {@link discloseIncident}. */
24
+ export interface DiscloseIncidentOptions {
25
+ readonly approvedCause?: ApprovedCause;
26
+ readonly time?: string;
27
+ readonly redaction?: SecretRedactionOptions;
28
+ }
29
+ /**
30
+ * The Copy-details block an incident's caller may read, or `undefined` for an anonymous caller.
31
+ * `label` is a class label and listed code (`Error(SQLITE_BUSY)`), both approved by listing.
32
+ * @complexity O(length of the approved cause) for redaction; O(1) otherwise.
33
+ */
34
+ export declare function discloseIncident(required: {
35
+ audience: ErrorAudience;
36
+ step: string;
37
+ label: string;
38
+ errorId: string;
39
+ fallback: {
40
+ readonly message: string;
41
+ readonly action: string;
42
+ };
43
+ versions: {
44
+ readonly app: string;
45
+ readonly jini: string;
46
+ };
47
+ }, optional?: DiscloseIncidentOptions): UserFacingError | undefined;
48
+ //# sourceMappingURL=disclosure.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { formatUserFacingError } from '../user-facing-error.js';
2
+ import { isApprovedCause } from './approved-cause.js';
3
+ /** The cause every signed-in caller sees. It names where the facts are without stating any. */
4
+ export const INCIDENT_CAUSE_SENTENCE = 'The error ID identifies the server report.';
5
+ function disclosedCause(required, optional) {
6
+ if (required.audience !== 'authorized')
7
+ return INCIDENT_CAUSE_SENTENCE;
8
+ const approved = optional.approvedCause;
9
+ // An approval is for one step: a cause approved for the export is not shown for a later save.
10
+ if (approved !== undefined && isApprovedCause({ value: approved }) && approved.step === required.step)
11
+ return approved.cause;
12
+ return `${INCIDENT_CAUSE_SENTENCE} Failure class: ${required.label}.`;
13
+ }
14
+ /**
15
+ * The Copy-details block an incident's caller may read, or `undefined` for an anonymous caller.
16
+ * `label` is a class label and listed code (`Error(SQLITE_BUSY)`), both approved by listing.
17
+ * @complexity O(length of the approved cause) for redaction; O(1) otherwise.
18
+ */
19
+ export function discloseIncident(required, optional = {}) {
20
+ if (required.audience !== 'signed-in' && required.audience !== 'authorized')
21
+ return undefined;
22
+ return formatUserFacingError({ message: required.fallback.message, action: required.fallback.action, step: required.step, cause: disclosedCause(required, optional) }, {
23
+ ...optional.redaction, errorId: required.errorId, appVersion: required.versions.app, jiniVersion: required.versions.jini,
24
+ ...(optional.time === undefined ? {} : { time: optional.time }),
25
+ });
26
+ }
27
+ //# sourceMappingURL=disclosure.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file The one error ID format every incident uses: `ERR-XXXX-XXXX-XXXX-XXXX`.
3
+ *
4
+ * Why one format, and why this one: `formatUserFacingError` recovers exactly this shape from a
5
+ * cause's plain text. A chat consumer that rebuilds `new Error(message)` and an Electron renderer
6
+ * that only receives a rejection's message both lose every typed field, so the ID has to survive as
7
+ * words. Hosts pass this function's result through their `ids` port; the daemon's tool-failure
8
+ * decorator mints its IDs the same way, so a tool failure and a route incident look alike.
9
+ */
10
+ /** Options of {@link mintToolErrorId}. None yet; named so one can be added without changing the signature. */
11
+ export interface MintErrorIdOptions {
12
+ }
13
+ /**
14
+ * Mints one error ID: 64 bits from the host's random source (`crypto.randomBytes` in a Node host),
15
+ * formatted `ERR-XXXX-XXXX-XXXX-XXXX` in upper-case hex. Randomness is a port, so this stays pure.
16
+ *
17
+ * @param required.randomHex - Returns `bytes` random bytes as hex (16 characters for the 8 asked for).
18
+ * @returns The ID. It has the four-group shape whenever the source returns the 16 characters asked for.
19
+ * @complexity O(1).
20
+ */
21
+ export declare function mintToolErrorId(required: {
22
+ randomHex: (required: {
23
+ bytes: number;
24
+ }) => string;
25
+ }, _optional?: MintErrorIdOptions): string;
26
+ //# sourceMappingURL=error-id.d.ts.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @file The one error ID format every incident uses: `ERR-XXXX-XXXX-XXXX-XXXX`.
3
+ *
4
+ * Why one format, and why this one: `formatUserFacingError` recovers exactly this shape from a
5
+ * cause's plain text. A chat consumer that rebuilds `new Error(message)` and an Electron renderer
6
+ * that only receives a rejection's message both lose every typed field, so the ID has to survive as
7
+ * words. Hosts pass this function's result through their `ids` port; the daemon's tool-failure
8
+ * decorator mints its IDs the same way, so a tool failure and a route incident look alike.
9
+ */
10
+ /**
11
+ * Mints one error ID: 64 bits from the host's random source (`crypto.randomBytes` in a Node host),
12
+ * formatted `ERR-XXXX-XXXX-XXXX-XXXX` in upper-case hex. Randomness is a port, so this stays pure.
13
+ *
14
+ * @param required.randomHex - Returns `bytes` random bytes as hex (16 characters for the 8 asked for).
15
+ * @returns The ID. It has the four-group shape whenever the source returns the 16 characters asked for.
16
+ * @complexity O(1).
17
+ */
18
+ export function mintToolErrorId(required, _optional = {}) {
19
+ const hex = required.randomHex({ bytes: 8 }).toUpperCase();
20
+ const groups = hex.match(/.{4}/g) ?? [];
21
+ return `ERR-${groups.join('-')}`;
22
+ }
23
+ //# sourceMappingURL=error-id.js.map
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @file Named ways to let a failure go, each saying which kind it is. They replace anonymous
3
+ * `.catch(() => {})` handlers so the error gate can tell an intended choice from a swallowed error,
4
+ * and so every use can be listed. None of these is a way back to silent swallowing: a site where a
5
+ * failure should be visible reports it instead.
6
+ */
7
+ import type { Logger } from '../primitives/logger.js';
8
+ import type { ErrorClass } from './bindings.js';
9
+ /** Options of the idioms that take none yet; named so one can be added without changing a signature. */
10
+ export interface IdiomOptions {
11
+ }
12
+ /** Options of {@link orFallback} and {@link orFallbackSync}. */
13
+ export interface FallbackOptions {
14
+ /** Receives the failure, for a caller that wants it counted or logged. A throw from it is ignored. */
15
+ readonly observe?: (required: {
16
+ error: unknown;
17
+ step: string;
18
+ }) => void;
19
+ }
20
+ /**
21
+ * Marks a promise handled: no unhandled-rejection report for it. Every awaiter of the original
22
+ * promise still gets the rejection. For a promise whose failure its own owner already shows.
23
+ * @complexity O(1).
24
+ */
25
+ export declare function observed(required: {
26
+ promise: PromiseLike<unknown>;
27
+ }, _optional?: IdiomOptions): void;
28
+ /**
29
+ * Resolves when the promise settles and never rejects. Only for a promise whose rejection another
30
+ * named owner already receives (a queue tail waiting for the previous job).
31
+ * @complexity O(1).
32
+ */
33
+ export declare function afterSettled(required: {
34
+ promise: PromiseLike<unknown>;
35
+ }, _optional?: IdiomOptions): Promise<void>;
36
+ /**
37
+ * Runs `work`; on ANY failure returns `fallback`. For an optional probe or a documented fallback,
38
+ * where every failure means "no answer". `step` is a fixed label naming the probe; the gate lists it.
39
+ * Where a real failure must not look like "absent", use {@link absentWhen} instead.
40
+ * @complexity O(1) beyond `work`.
41
+ */
42
+ export declare function orFallback<Value>(required: {
43
+ work: () => Value | PromiseLike<Value>;
44
+ fallback: Value;
45
+ step: string;
46
+ }, optional?: FallbackOptions): Promise<Value>;
47
+ /** {@link orFallback} for a synchronous `work` (browser storage that may throw). */
48
+ export declare function orFallbackSync<Value>(required: {
49
+ work: () => Value;
50
+ fallback: Value;
51
+ step: string;
52
+ }, optional?: FallbackOptions): Value;
53
+ /**
54
+ * Runs cleanup. A failure is logged with its step (the log line carries the class and listed code,
55
+ * a host sink the original) and is never thrown, so cleanup cannot replace the result it follows.
56
+ * @complexity O(1) beyond `work`.
57
+ */
58
+ export declare function bestEffort(required: {
59
+ work: () => unknown;
60
+ step: string;
61
+ logger: Pick<Logger, 'warn'>;
62
+ }, _optional?: IdiomOptions): Promise<void>;
63
+ /**
64
+ * Runs `work`; returns `undefined` only for the listed codes (`ENOENT`) or classes and RETHROWS
65
+ * everything else, so a storage failure never reads as "not there".
66
+ * @complexity O(codes + kinds) on the failure path.
67
+ */
68
+ export declare function absentWhen<Value>(required: {
69
+ work: () => Value | PromiseLike<Value>;
70
+ codes: readonly string[];
71
+ kinds: readonly ErrorClass[];
72
+ }, _optional?: IdiomOptions): Promise<Value | undefined>;
73
+ //# sourceMappingURL=idioms.d.ts.map