@jini-ai/core 0.7.1 → 0.7.3-next.1

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 (339) 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 +232 -0
  84. package/dist/contracts/observability.js +27 -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/host-read-vocabulary.d.ts +47 -0
  211. package/dist/host-read-vocabulary.js +44 -0
  212. package/dist/index.d.ts +5 -1
  213. package/dist/index.js +4 -0
  214. package/dist/list-page.d.ts +93 -0
  215. package/dist/list-page.js +154 -0
  216. package/dist/model-facing-tool-errors.d.ts +67 -5
  217. package/dist/model-facing-tool-errors.js +155 -19
  218. package/dist/net/endpoint-policy.d.ts +39 -0
  219. package/dist/net/endpoint-policy.js +218 -0
  220. package/dist/net/fetch-timeouts.d.ts +38 -0
  221. package/dist/net/fetch-timeouts.js +31 -0
  222. package/dist/net/index.d.ts +4 -0
  223. package/dist/net/index.js +4 -0
  224. package/dist/net/loopback.d.ts +13 -0
  225. package/dist/net/loopback.js +39 -0
  226. package/dist/optimistic-concurrency.d.ts +183 -0
  227. package/dist/optimistic-concurrency.js +222 -0
  228. package/dist/primitives/errors.d.ts +9 -0
  229. package/dist/primitives/errors.js +12 -0
  230. package/dist/primitives/ids.d.ts +0 -2
  231. package/dist/primitives/ids.js +1 -4
  232. package/dist/primitives/index.d.ts +3 -0
  233. package/dist/primitives/index.js +2 -0
  234. package/dist/primitives/logger.d.ts +36 -1
  235. package/dist/primitives/logger.js +125 -9
  236. package/dist/primitives/node-shape.d.ts +24 -0
  237. package/dist/primitives/node-shape.js +21 -0
  238. package/dist/primitives/time.d.ts +9 -2
  239. package/dist/primitives/time.js +4 -3
  240. package/dist/provider-registry.js +26 -20
  241. package/dist/records.d.ts +40 -7
  242. package/dist/records.js +37 -3
  243. package/dist/redact.d.ts +1 -84
  244. package/dist/redact.js +2 -826
  245. package/dist/redaction-collectors.d.ts +7 -0
  246. package/dist/redaction-collectors.js +152 -0
  247. package/dist/redaction-exact-secrets.d.ts +14 -0
  248. package/dist/redaction-exact-secrets.js +115 -0
  249. package/dist/redaction-labels.d.ts +14 -0
  250. package/dist/redaction-labels.js +156 -0
  251. package/dist/redaction-patterns.d.ts +54 -0
  252. package/dist/redaction-patterns.js +178 -0
  253. package/dist/redaction-spans.d.ts +31 -0
  254. package/dist/redaction-spans.js +83 -0
  255. package/dist/registration-kit.d.ts +1 -1
  256. package/dist/revision-conflict-error.d.ts +18 -0
  257. package/dist/revision-conflict-error.js +20 -0
  258. package/dist/secret-shapes.d.ts +50 -0
  259. package/dist/secret-shapes.js +105 -0
  260. package/dist/settings/agent-tools.js +22 -8
  261. package/dist/settings/agent-value-write-tools.d.ts +4 -1
  262. package/dist/settings/agent-value-write-tools.js +7 -6
  263. package/dist/settings/agent-writable-preferences.d.ts +3 -1
  264. package/dist/settings/agent-writable-preferences.js +1 -1
  265. package/dist/settings/agent-write-denylist.d.ts +7 -4
  266. package/dist/settings/agent-write-denylist.js +1 -1
  267. package/dist/settings/{express/cms-adapter.d.ts → cms-adapter.d.ts} +3 -2
  268. package/dist/settings/{express/cms-adapter.js → cms-adapter.js} +21 -11
  269. package/dist/settings/definitions-dispatch.js +3 -1
  270. package/dist/settings/ensure-definitions.js +3 -1
  271. package/dist/settings/errors.d.ts +1 -13
  272. package/dist/settings/errors.js +2 -15
  273. package/dist/settings/index.d.ts +11 -2
  274. package/dist/settings/index.js +10 -2
  275. package/dist/settings/purge-service.js +63 -86
  276. package/dist/settings/{express/contracts.d.ts → route-policy.d.ts} +53 -47
  277. package/dist/settings/{express/shared.js → route-policy.js} +1 -16
  278. package/dist/settings/settings.d.ts +19 -11
  279. package/dist/settings/settings.js +9 -11
  280. package/dist/settings/tool-registrations.d.ts +3 -3
  281. package/dist/settings/tool-registrations.js +130 -125
  282. package/dist/settings/types.d.ts +1 -1
  283. package/dist/settings/write-definition-rename.d.ts +37 -0
  284. package/dist/settings/write-definition-rename.js +119 -0
  285. package/dist/settings/write-definition-retype.d.ts +61 -0
  286. package/dist/settings/write-definition-retype.js +109 -0
  287. package/dist/settings/write-definition-status.d.ts +81 -0
  288. package/dist/settings/write-definition-status.js +121 -0
  289. package/dist/settings/write-reset.d.ts +34 -0
  290. package/dist/settings/write-reset.js +73 -0
  291. package/dist/settings/write-service.d.ts +16 -287
  292. package/dist/settings/write-service.js +49 -681
  293. package/dist/settings/write-value-revisions.d.ts +68 -0
  294. package/dist/settings/write-value-revisions.js +124 -0
  295. package/dist/settings/write-values.d.ts +96 -0
  296. package/dist/settings/write-values.js +83 -0
  297. package/dist/surface-exchanges.d.ts +2 -2
  298. package/dist/text/dictionary-translator.d.ts +19 -0
  299. package/dist/text/dictionary-translator.js +14 -0
  300. package/dist/text/format-byte-size.d.ts +25 -0
  301. package/dist/text/format-byte-size.js +25 -0
  302. package/dist/text/format-timestamp.d.ts +22 -0
  303. package/dist/text/format-timestamp.js +57 -0
  304. package/dist/text/index.d.ts +12 -0
  305. package/dist/text/index.js +9 -0
  306. package/dist/text/is-abort-error.d.ts +5 -0
  307. package/dist/text/is-abort-error.js +5 -0
  308. package/dist/text/mime.d.ts +5 -0
  309. package/dist/text/mime.js +21 -0
  310. package/dist/text/redact-urls.d.ts +7 -0
  311. package/dist/text/redact-urls.js +5 -0
  312. package/dist/text/resolve-active-tab-id.d.ts +13 -0
  313. package/dist/text/resolve-active-tab-id.js +15 -0
  314. package/dist/text/sanitize-untrusted-text.d.ts +1 -1
  315. package/dist/text/sanitize-untrusted-text.js +2 -1
  316. package/dist/text/tagged-text-suppression.d.ts +103 -0
  317. package/dist/text/tagged-text-suppression.js +143 -0
  318. package/dist/text/template-i18n.d.ts +37 -0
  319. package/dist/text/template-i18n.js +48 -0
  320. package/dist/tool-call-text.d.ts +59 -0
  321. package/dist/tool-call-text.js +62 -0
  322. package/dist/tool-input-envelope.js +8 -4
  323. package/dist/tool-input-normalization.js +8 -1
  324. package/dist/tool-input-repairs.d.ts +58 -0
  325. package/dist/tool-input-repairs.js +154 -0
  326. package/dist/tool-tokens.js +1 -1
  327. package/dist/user-facing-error.d.ts +1 -1
  328. package/dist/user-facing-error.js +3 -1
  329. package/package.json +234 -13
  330. package/dist/settings/express/contracts.js +0 -2
  331. package/dist/settings/express/http-request.d.ts +0 -33
  332. package/dist/settings/express/http-request.js +0 -50
  333. package/dist/settings/express/http.d.ts +0 -10
  334. package/dist/settings/express/http.js +0 -196
  335. package/dist/settings/express/index.d.ts +0 -5
  336. package/dist/settings/express/index.js +0 -4
  337. package/dist/settings/express/shared.d.ts +0 -68
  338. package/dist/settings/express/stream.d.ts +0 -24
  339. package/dist/settings/express/stream.js +0 -171
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Browser-safe literal endpoint hostname policy. No Node imports or DNS effects:
3
+ * operator-configured local model servers deliberately keep their loopback
4
+ * exception. Resolved-peer validation and strict IP parsing belong to the Node
5
+ * adapters, whose different trust boundaries must not be collapsed into this.
6
+ * SSRF peer classification is distinct from core's browser-development LAN origin allow-list.
7
+ */
8
+ function normalizeBracketedIpv6(hostname) {
9
+ const stripped = hostname.startsWith('[') && hostname.endsWith(']')
10
+ ? hostname.slice(1, -1)
11
+ : hostname;
12
+ // FQDN trailing-dot form (RFC 1034) resolves identically to the dotless
13
+ // form, so `localhost.` must normalize to `localhost` before the equality
14
+ // check below — and `0.0.0.0.`, `10.0.0.1.`, etc. must normalize before
15
+ // the IPv4 classifier parses them. Strips one or more trailing dots.
16
+ // A scan rather than /\.+$/, which backtracks quadratically on long interior dot runs. This module
17
+ // stays import-free (see its contract test), so it does not use core's trimCharsEnd.
18
+ const lowered = stripped.toLowerCase();
19
+ let end = lowered.length;
20
+ while (end > 0 && lowered[end - 1] === '.')
21
+ end -= 1;
22
+ return lowered.slice(0, end);
23
+ }
24
+ function parseIpv4(hostname) {
25
+ const parts = hostname.split('.');
26
+ if (parts.length !== 4)
27
+ return null;
28
+ const parsed = parts.map((part) => {
29
+ if (!/^\d{1,3}$/.test(part))
30
+ return null;
31
+ const value = Number(part);
32
+ return value >= 0 && value <= 255 ? value : null;
33
+ });
34
+ if (parsed.some((part) => part === null))
35
+ return null;
36
+ return [parsed[0], parsed[1], parsed[2], parsed[3]];
37
+ }
38
+ /** Expand an IPv6 literal (with `::` compression and/or an embedded dotted
39
+ * IPv4 tail) into its eight 16-bit groups, or null if it does not parse.
40
+ * Node's URL parser normalizes mapped literals to hex (`::ffff:127.0.0.1` →
41
+ * `::ffff:7f00:1`), so a string regex can't reliably spot the mapped range —
42
+ * we have to canonicalize.
43
+ *
44
+ * Exported (previously module-private) so its parse-failure guards are
45
+ * directly unit-testable: the IP classifier and guarded client gate
46
+ * calls behind `net.isIP(addr) === 6`, and Node's `isIP` already fully
47
+ * validates IPv6 syntax (including embedded-IPv4-tail octet ranges) before
48
+ * returning 6 — empirically verified in the original extraction by fuzzing ~10k
49
+ * `isIP`-accepted v6 literals through this function's guards with zero
50
+ * hits — so none of these guards are reachable through that path. They stay
51
+ * as real defense-in-depth (fail closed with `null` rather than trust a
52
+ * platform primitive never changing behavior), matching the asset cache's
53
+ * exported-for-direct-testing precedent (`readBodyCapped`'s abort parameter). */
54
+ export function expandIpv6({ address: addr }) {
55
+ // `String#split` always returns a non-empty array, so index 0 is never
56
+ // `undefined` — the `!` narrows a `noUncheckedIndexedAccess` false
57
+ // positive, not a real fallback path.
58
+ const literal = addr.toLowerCase().split('%')[0];
59
+ if (!literal.includes(':'))
60
+ return null;
61
+ const s = foldIpv4Tail(literal);
62
+ if (s === null)
63
+ return null;
64
+ const halves = s.split('::');
65
+ if (halves.length > 2)
66
+ return null;
67
+ const parse = (p) => p === '' ? [] : p.split(':').map((g) => (/^[0-9a-f]{1,4}$/.test(g) ? parseInt(g, 16) : Number.NaN));
68
+ // `halves` always has at least one element (split guarantee).
69
+ const left = parse(halves[0]);
70
+ let groups;
71
+ if (halves.length === 1) {
72
+ groups = left;
73
+ }
74
+ else {
75
+ // `halves.length === 2` here (the `> 2` case already returned above).
76
+ const right = parse(halves[1]);
77
+ const fill = 8 - left.length - right.length;
78
+ if (fill < 1)
79
+ return null;
80
+ groups = [...left, ...Array.from({ length: fill }, () => 0), ...right];
81
+ }
82
+ if (!validIpv6Groups(groups))
83
+ return null;
84
+ return groups;
85
+ }
86
+ /** Fold a dotted tail while retaining the parser's defense-in-depth octet validation. */
87
+ function foldIpv4Tail(s) {
88
+ // Fold a trailing dotted IPv4 (`…:1.2.3.4`) into two hex groups.
89
+ const v4 = /^(.*:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(s);
90
+ if (v4) {
91
+ // `v4[2]` is the regex's second (mandatory, non-optional) capture group
92
+ // of a successful match — always defined.
93
+ const o = v4[2].split('.').map((n) => Number(n));
94
+ if (o.length !== 4 || o.some((n) => !Number.isInteger(n) || n < 0 || n > 255))
95
+ return null;
96
+ // `o` is now a validated 4-element array — indices 0-3 always defined.
97
+ const hi = ((o[0] << 8) | o[1]).toString(16);
98
+ const lo = ((o[2] << 8) | o[3]).toString(16);
99
+ s = `${v4[1]}${hi}:${lo}`;
100
+ }
101
+ return s;
102
+ }
103
+ function validIpv6Groups(groups) {
104
+ return groups.length === 8 && groups.every(g => Number.isInteger(g) && g >= 0 && g <= 0xffff);
105
+ }
106
+ /** Classifies validated IPv4 bytes; shared by native and embedded-v4 literals. */
107
+ function classifyIpv4Bytes(bytes) {
108
+ const [a, b] = bytes;
109
+ if (a === 127)
110
+ return 'loopback';
111
+ // This range includes the cloud metadata address 169.254.169.254.
112
+ if (a === 169 && b === 254)
113
+ return 'link-local';
114
+ if (a === 0 || a >= 224)
115
+ return 'reserved'; // "this" network / unspecified; multicast + reserved
116
+ // The remaining blocked IPv4 ranges include RFC 6598 shared carrier space (100.64.0.0/10):
117
+ // it is not globally routable and belongs with RFC 1918 private ranges for egress decisions.
118
+ if (isPrivateIpv4Bytes(bytes))
119
+ return 'private';
120
+ return 'public';
121
+ }
122
+ function isPrivateIpv4Bytes([a, b]) {
123
+ if (a === 100)
124
+ return b >= 64 && b <= 127;
125
+ if (a === 172)
126
+ return b >= 16 && b <= 31;
127
+ if (a === 192)
128
+ return b === 168;
129
+ return a === 10;
130
+ }
131
+ // Each /96 prefix carries IPv4 in the final four bytes. Matching canonical
132
+ // bytes also handles expanded IPv6 and WHATWG URL's dotted-to-hex normalization.
133
+ const EMBEDDED_IPV4_PREFIXES = [
134
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // compatible ::/96 (except native ::/::1)
135
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255], // mapped ::ffff:0:0/96
136
+ [0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0], // translated ::ffff:0:0:0/96
137
+ [0, 100, 255, 155, 0, 0, 0, 0, 0, 0, 0, 0], // well-known NAT64 64:ff9b::/96
138
+ ];
139
+ function hasEmbeddedIpv4(bytes) {
140
+ return EMBEDDED_IPV4_PREFIXES.some(prefix => hasPrefix(bytes, prefix));
141
+ }
142
+ function hasPrefix(bytes, prefix) {
143
+ return prefix.every((byte, index) => bytes[index] === byte);
144
+ }
145
+ // Teredo 2001::/32 obfuscates its client IPv4, and local-use NAT64 64:ff9b:1::/48 may embed
146
+ // IPv4 at any prefix length, so neither can be classified by position: both are refused.
147
+ const UNCLASSIFIABLE_TUNNEL_PREFIXES = [
148
+ [0x20, 0x01, 0, 0], // Teredo 2001::/32
149
+ [0, 0x64, 0xff, 0x9b, 0, 1], // local-use NAT64 64:ff9b:1::/48
150
+ ];
151
+ /** Tunnel prefixes that reach IPv4 without a fixed /96 tail; null means not a tunnel prefix. */
152
+ function classifyTunnelIpv6(bytes) {
153
+ // 6to4 2002::/16 carries its IPv4 in bytes 2-5; a host with a 6to4 route encapsulates to it.
154
+ if (hasPrefix(bytes, [0x20, 0x02]))
155
+ return classifyIpv4Bytes(bytes.slice(2, 6));
156
+ if (UNCLASSIFIABLE_TUNNEL_PREFIXES.some(prefix => hasPrefix(bytes, prefix)))
157
+ return 'reserved';
158
+ return null;
159
+ }
160
+ /** Classifies 16 IPv6 bytes, independent of compression or dotted/hex tail spelling. */
161
+ function classifyIpv6Bytes(bytes) {
162
+ // Native :: and ::1 retain their own meaning before the deprecated compatible-v4 range.
163
+ if (bytes.every(n => n === 0))
164
+ return 'reserved'; // :: (unspecified)
165
+ if (bytes.slice(0, 15).every(n => n === 0) && bytes[15] === 1)
166
+ return 'loopback';
167
+ // IPv4-mapped (::ffff:0:0/96) and deprecated IPv4-compatible (::/96)
168
+ // carry an embedded IPv4: classify its real range so ::ffff:7f00:1 is caught.
169
+ if (hasEmbeddedIpv4(bytes))
170
+ return classifyIpv4Bytes(bytes.slice(12));
171
+ const tunnel = classifyTunnelIpv6(bytes);
172
+ if (tunnel)
173
+ return tunnel;
174
+ if (bytes[0] === 255)
175
+ return 'reserved'; // multicast ff00::/8
176
+ const first = (bytes[0] << 8) | bytes[1];
177
+ if ((first & 0xffc0) === 0xfe80)
178
+ return 'link-local'; // fe80::/10 (fe80–febf)
179
+ if ((first & 0xfe00) === 0xfc00)
180
+ return 'private'; // unique-local fc00::/7
181
+ return 'public';
182
+ }
183
+ /** Pure literal classifier; null means malformed input or a hostname requiring DNS. */
184
+ export function classifyAddressLiteral({ address }, _options = {}) {
185
+ if (!address.includes(':')) {
186
+ const ipv4 = parseIpv4(address);
187
+ return ipv4 ? classifyIpv4Bytes(ipv4) : null;
188
+ }
189
+ const groups = expandIpv6({ address });
190
+ if (!groups)
191
+ return null;
192
+ // The parser's length/regex checks guarantee complete groups and bytes here;
193
+ // non-null assertions in byte classification narrow index types, not a runtime fallback.
194
+ // Parse once, then all range decisions operate on the same 16 canonical bytes.
195
+ const bytes = groups.flatMap(group => [group >> 8, group & 255]);
196
+ return classifyIpv6Bytes(bytes);
197
+ }
198
+ /** True for localhost and literal loopback, including embedded IPv4 forms. */
199
+ export function isLoopbackApiHost({ hostname }) {
200
+ const host = normalizeBracketedIpv6(hostname);
201
+ return host === 'localhost' || classifyAddressLiteral({ address: host }) === 'loopback';
202
+ }
203
+ /** Private/reserved literal hosts are blocked; configured local servers keep their loopback exception. */
204
+ export function isBlockedExternalApiHostname({ hostname }) {
205
+ const host = normalizeBracketedIpv6(hostname);
206
+ const addressClass = classifyAddressLiteral({ address: host });
207
+ return addressClass !== null && addressClass !== 'public' && addressClass !== 'loopback';
208
+ }
209
+ /** Literal policy for a hostname from a deployed endpoint URL: local names and reserved
210
+ * addresses are excluded. DNS reachability remains the deployment host's responsibility.
211
+ * @complexity O(hostname length), no DNS or other I/O. */
212
+ export function isDeployedApiHostname({ hostname }, _optional = {}) {
213
+ const host = normalizeBracketedIpv6(hostname);
214
+ if (isLoopbackApiHost({ hostname: host }) || isBlockedExternalApiHostname({ hostname: host }))
215
+ return false;
216
+ return !host.endsWith('.localhost') && !host.endsWith('.local');
217
+ }
218
+ //# sourceMappingURL=endpoint-policy.js.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Shared vocabulary for outbound-fetch timeout classes. `FETCH_TIMEOUT_MS` gives call sites a small,
3
+ * documented set of named ceilings instead of an invented number each time: a deploy-provider API
4
+ * call, an image byte-fetch, and a large asset upload genuinely have different reasonable limits.
5
+ * Callers still name the timeout explicitly (usually one of these constants), because a reader of the
6
+ * call site should see the number rather than hunt for a hidden default.
7
+ */
8
+ /**
9
+ * Shared, documented timeout classes for outbound `fetch()` calls. Every call site names one
10
+ * explicitly (or its own justified number) rather than relying on an unstated default.
11
+ */
12
+ export declare const FETCH_TIMEOUT_MS: {
13
+ /** A single metadata/status/API-read call expected to return quickly: a model catalog listing, a
14
+ * connection test, a GitHub API read, an LLM provider's non-streaming completion call. */
15
+ readonly QUICK: 15000;
16
+ /** A deploy-provider API call that may involve real backend work on the provider's side — site
17
+ * creation, DNS record lookups, deployment status polling. */
18
+ readonly DEPLOY: 30000;
19
+ /** A large-payload transfer: an asset/blob upload, a generated-media byte fetch. */
20
+ readonly UPLOAD: 120000;
21
+ /** A media-generation API call whose response only arrives once the vendor has actually finished
22
+ * generating the image/video/audio server-side — routinely minutes, not seconds. Matches the
23
+ * value OpenAI's and OpenRouter's own image providers already hardcode locally
24
+ * (`OPENAI_IMAGE_*_TIMEOUT_MS`/`OPENROUTER_IMAGE_TIMEOUT_MS`); used as the shared dispatch-level
25
+ * backstop in `@jini-ai/integrations`' `dispatchVendorRequest` for every OTHER vendor that (as of
26
+ * 2026-08-16) sets no timeout of its own at all. Deliberately NOT the same as `UPLOAD`: a backstop
27
+ * shorter than a vendor's own already-correct 10-minute generation timeout would abort a
28
+ * legitimately still-generating request early. */
29
+ readonly GENERATE: number;
30
+ };
31
+ /** Opt-in byte and decoding guards; defaults remain unlimited and replacement-decoded. */
32
+ export type TextReadOptions = {
33
+ /** Nonnegative safe integer. Actual streamed bytes, independent of Content-Length. */
34
+ maxResponseBytes?: number;
35
+ /** Reject malformed UTF-8, including an incomplete trailing character. */
36
+ strictUtf8?: boolean;
37
+ };
38
+ //# sourceMappingURL=fetch-timeouts.d.ts.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Shared vocabulary for outbound-fetch timeout classes. `FETCH_TIMEOUT_MS` gives call sites a small,
3
+ * documented set of named ceilings instead of an invented number each time: a deploy-provider API
4
+ * call, an image byte-fetch, and a large asset upload genuinely have different reasonable limits.
5
+ * Callers still name the timeout explicitly (usually one of these constants), because a reader of the
6
+ * call site should see the number rather than hunt for a hidden default.
7
+ */
8
+ /**
9
+ * Shared, documented timeout classes for outbound `fetch()` calls. Every call site names one
10
+ * explicitly (or its own justified number) rather than relying on an unstated default.
11
+ */
12
+ export const FETCH_TIMEOUT_MS = {
13
+ /** A single metadata/status/API-read call expected to return quickly: a model catalog listing, a
14
+ * connection test, a GitHub API read, an LLM provider's non-streaming completion call. */
15
+ QUICK: 15_000,
16
+ /** A deploy-provider API call that may involve real backend work on the provider's side — site
17
+ * creation, DNS record lookups, deployment status polling. */
18
+ DEPLOY: 30_000,
19
+ /** A large-payload transfer: an asset/blob upload, a generated-media byte fetch. */
20
+ UPLOAD: 120_000,
21
+ /** A media-generation API call whose response only arrives once the vendor has actually finished
22
+ * generating the image/video/audio server-side — routinely minutes, not seconds. Matches the
23
+ * value OpenAI's and OpenRouter's own image providers already hardcode locally
24
+ * (`OPENAI_IMAGE_*_TIMEOUT_MS`/`OPENROUTER_IMAGE_TIMEOUT_MS`); used as the shared dispatch-level
25
+ * backstop in `@jini-ai/integrations`' `dispatchVendorRequest` for every OTHER vendor that (as of
26
+ * 2026-08-16) sets no timeout of its own at all. Deliberately NOT the same as `UPLOAD`: a backstop
27
+ * shorter than a vendor's own already-correct 10-minute generation timeout would abort a
28
+ * legitimately still-generating request early. */
29
+ GENERATE: 10 * 60_000,
30
+ };
31
+ //# sourceMappingURL=fetch-timeouts.js.map
@@ -0,0 +1,4 @@
1
+ export * from './endpoint-policy.js';
2
+ export * from './loopback.js';
3
+ export * from './fetch-timeouts.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ export * from './endpoint-policy.js';
2
+ export * from './loopback.js';
3
+ export * from './fetch-timeouts.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,13 @@
1
+ /** True when `hostname` is `localhost`, an IPv6 loopback literal, or a `127.0.0.0/8` IPv4 literal. */
2
+ export declare function isLoopbackHostname({ hostname }: {
3
+ readonly hostname: unknown;
4
+ }, _optional?: Record<string, never>): boolean;
5
+ /**
6
+ * True when `address` (typically `req.socket.remoteAddress`) is a loopback peer, unwrapping an IPv4-mapped
7
+ * IPv6 prefix first. IPv4 is judged by the same strict dotted-quad pattern `isLoopbackHostname` uses, which
8
+ * rejects leading-zero octets and trailing text exactly as the runtime's own IPv4 check does.
9
+ */
10
+ export declare function isLoopbackPeerAddress({ address }: {
11
+ readonly address: unknown;
12
+ }, _optional?: Record<string, never>): boolean;
13
+ //# sourceMappingURL=loopback.d.ts.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Node's own strict dotted-quad IPv4 pattern (lib/internal/net.js). Core carries no Node imports,
3
+ * so this regex stands in for the runtime's own IPv4 check; a parity test in platform proves they agree.
4
+ */
5
+ const STRICT_IPV4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
6
+ /** True when `hostname` is `localhost`, an IPv6 loopback literal, or a `127.0.0.0/8` IPv4 literal. */
7
+ export function isLoopbackHostname({ hostname }, _optional = {}) {
8
+ const normalized = String(hostname || '')
9
+ .toLowerCase()
10
+ .replace(/^\[|\]$/g, '')
11
+ .replace(/\.$/, '');
12
+ if (normalized === 'localhost')
13
+ return true;
14
+ if (normalized === '::1' || normalized === '0:0:0:0:0:0:0:1')
15
+ return true;
16
+ if (STRICT_IPV4.test(normalized))
17
+ return normalized === '127.0.0.1' || normalized.startsWith('127.');
18
+ return false;
19
+ }
20
+ /**
21
+ * True when `address` (typically `req.socket.remoteAddress`) is a loopback peer, unwrapping an IPv4-mapped
22
+ * IPv6 prefix first. IPv4 is judged by the same strict dotted-quad pattern `isLoopbackHostname` uses, which
23
+ * rejects leading-zero octets and trailing text exactly as the runtime's own IPv4 check does.
24
+ */
25
+ export function isLoopbackPeerAddress({ address }, _optional = {}) {
26
+ if (typeof address !== 'string')
27
+ return false;
28
+ const normalized = address.trim().toLowerCase().replace(/^\[|\]$/g, '');
29
+ if (!normalized)
30
+ return false;
31
+ if (normalized.startsWith('::ffff:'))
32
+ return isLoopbackPeerAddress({ address: normalized.slice('::ffff:'.length) });
33
+ if (normalized === '::1' || normalized === '0:0:0:0:0:0:0:1')
34
+ return true;
35
+ if (STRICT_IPV4.test(normalized))
36
+ return normalized === '127.0.0.1' || normalized.startsWith('127.');
37
+ return false;
38
+ }
39
+ //# sourceMappingURL=loopback.js.map
@@ -0,0 +1,183 @@
1
+ import type { ModelFacingErrorRule } from './model-facing-tool-errors.js';
2
+ /** The machine-readable code every arm publishes for a superseded basis — the same string posts,
3
+ * entries, menus and content types already send, so existing admin classifiers keep working. */
4
+ export declare const VERSION_CONFLICT_CODE = "VERSION_CONFLICT";
5
+ /**
6
+ * A compare-and-set write lost: the record moved on (or was deleted) after the caller read it.
7
+ * Nothing was written. Resending the same request cannot succeed; re-reading can.
8
+ */
9
+ export declare class RecordVersionConflictError extends Error {
10
+ readonly code = "VERSION_CONFLICT";
11
+ /** Plain-words noun for the record, e.g. `webhook`, `MCP server`. */
12
+ readonly recordKind: string;
13
+ readonly recordId: string;
14
+ /** The version the caller read. */
15
+ readonly expectedVersion: number;
16
+ /** The version stored now, or `null` when the record no longer exists. */
17
+ readonly currentVersion: number | null;
18
+ constructor(required: {
19
+ recordKind: string;
20
+ recordId: string;
21
+ expectedVersion: number;
22
+ currentVersion: number | null;
23
+ }, optional?: ErrorOptions);
24
+ }
25
+ /**
26
+ * The basis off an untrusted input. `undefined` means the caller did not send one (legacy
27
+ * last-write-wins callers); anything present must be a non-negative integer.
28
+ *
29
+ * Throws instead of coercing: a mistyped `"3"` read as "no basis" would turn a client that believes
30
+ * it is protected into an unguarded overwrite — the exact bug this closes.
31
+ *
32
+ * @throws {ToolInputError} `'<field>' must be a non-negative integer when present`.
33
+ * @complexity O(1).
34
+ */
35
+ export declare function parseExpectedVersion(required: {
36
+ value: unknown;
37
+ }, optional?: {
38
+ field?: string;
39
+ }): number | undefined;
40
+ /**
41
+ * Like {@link parseExpectedVersion} but the basis is mandatory — for assistant write tools, where
42
+ * the model always reads a record before replacing it, so a missing basis is a caller mistake.
43
+ *
44
+ * @throws {ToolInputError} with plain recovery words when missing or malformed.
45
+ * @complexity O(1).
46
+ */
47
+ export declare function requireExpectedVersion(required: {
48
+ value: unknown;
49
+ readToolId: string;
50
+ }, optional?: {
51
+ field?: string;
52
+ }): number;
53
+ /**
54
+ * Finishes a conditional write (`UPDATE … WHERE version = :expectedVersion`). Changed rows ⇒ done;
55
+ * none ⇒ re-read the live version (for the message) and throw.
56
+ *
57
+ * @param required.changedRows - What the driver reported (`numUpdatedRows`, `changes`, `rowCount`).
58
+ * @param required.readCurrentVersion - Reads the stored version, `null` when the row is gone.
59
+ * @throws {RecordVersionConflictError} when no row changed.
60
+ * @complexity O(1) plus one read on a miss.
61
+ */
62
+ export declare function assertVersionedWrite(required: {
63
+ changedRows: number | bigint;
64
+ recordKind: string;
65
+ recordId: string;
66
+ expectedVersion: number;
67
+ readCurrentVersion: () => Promise<number | null>;
68
+ }, _optional?: Record<string, never>): Promise<void>;
69
+ /**
70
+ * A settings-ledger conflict (`settings` `set(…, { expectedRevisionSeq })` / `clear`) as the shared
71
+ * conflict, so a route or tool that writes settings maps ONE error class to 409 / model guidance.
72
+ * Why a bridge, not a second check: the ledger already compares the value row's `seq` inside its
73
+ * revision-stream lock; only its error spelling differs. Any other error comes back unchanged, so
74
+ * callers can `throw fromSettingsRevisionConflict({ error, setting })` in a catch.
75
+ *
76
+ * @param required.setting - `<namespace>.<key>` of the value that was written.
77
+ * @complexity O(1).
78
+ */
79
+ export declare function fromSettingsRevisionConflict(required: {
80
+ error: unknown;
81
+ setting: string;
82
+ }, _optional?: Record<string, never>): unknown;
83
+ /** The JSON body an HTTP route answers a conflict with, under status 409. */
84
+ export interface VersionConflictBody {
85
+ readonly error: string;
86
+ readonly code: typeof VERSION_CONFLICT_CODE;
87
+ readonly details: {
88
+ readonly recordKind: string;
89
+ readonly recordId: string;
90
+ readonly expectedVersion: number;
91
+ readonly currentVersion: number | null;
92
+ };
93
+ }
94
+ /**
95
+ * The 409 body. `details` carries the versions as fields so the admin "Copy details" text and any
96
+ * client can show "yours N, theirs M" without parsing prose. Same `{ error, code, details }` shape
97
+ * `features/post/expected-version.ts` in a host already sends.
98
+ *
99
+ * @complexity O(1).
100
+ */
101
+ export declare function versionConflictBody(required: {
102
+ error: RecordVersionConflictError;
103
+ }, _optional?: Record<string, never>): VersionConflictBody;
104
+ /** The machine-readable code for a save that named no version (HTTP status 428). */
105
+ export declare const VERSION_REQUIRED_CODE = "VERSION_REQUIRED";
106
+ /** The one plain-words answer for a save that named no version, shared by the error and its 428 body. */
107
+ export declare const VERSION_REQUIRED_MESSAGE = "This save did not say which version you were editing, so nothing was saved (it could have overwritten someone else's change). Reload, make your change again, and save.";
108
+ /**
109
+ * A save for an editable record arrived without saying which version the person was editing, so it
110
+ * could have overwritten someone else's change. Nothing was written. Re-reading and saving again can
111
+ * succeed.
112
+ */
113
+ export declare class RecordVersionRequiredError extends Error {
114
+ readonly code = "VERSION_REQUIRED";
115
+ /** The input field that should have carried the version. */
116
+ readonly field: string;
117
+ constructor(required: {
118
+ field: string;
119
+ }, optional?: ErrorOptions);
120
+ }
121
+ /**
122
+ * Like {@link parseExpectedVersion} but the basis is mandatory for an editor save (a person's form),
123
+ * and a missing one is its own error so a route can answer 428 instead of a generic 400.
124
+ *
125
+ * @throws {ToolInputError} when present but malformed.
126
+ * @throws {RecordVersionRequiredError} when missing.
127
+ * @complexity O(1).
128
+ */
129
+ export declare function requireEditorVersion(required: {
130
+ value: unknown;
131
+ }, optional?: {
132
+ field?: string;
133
+ }): number;
134
+ /**
135
+ * The 428 body for a save that named no version. HTTP status 428.
136
+ *
137
+ * @complexity O(1).
138
+ */
139
+ export declare function versionRequiredBody(required: {
140
+ error: RecordVersionRequiredError;
141
+ }, _optional?: Record<string, never>): {
142
+ error: string;
143
+ code: typeof VERSION_REQUIRED_CODE;
144
+ details: {
145
+ field: string;
146
+ };
147
+ };
148
+ /**
149
+ * The model-facing rule for a domain's allowlist: publishes the plain message plus what to do next,
150
+ * so the assistant re-reads instead of resending the same stale call (or giving up).
151
+ *
152
+ * @complexity O(1).
153
+ */
154
+ export declare function versionConflictRule(required: {
155
+ readToolId: string;
156
+ }, _optional?: Record<string, never>): ModelFacingErrorRule;
157
+ /**
158
+ * An internal, single-purpose change (a status flip, an adoption, a rename) applied to a versioned
159
+ * record: read it, derive the next state from what was read, write it conditionally on the version
160
+ * that was read. If the write misses, read again and re-apply the same change once (rule M4), then
161
+ * report the conflict. A person's or an agent's edit never goes through here: it carries its own
162
+ * basis and is never retried for them.
163
+ *
164
+ * @param required.read - Reads the record, `null` when it does not exist.
165
+ * @param required.build - Derives the next record from the one just read; `null` means nothing to write.
166
+ * @param required.write - The conditional write (`WHERE version = current.version`); `true` when it applied.
167
+ * @returns the record as written, or `null` when it does not exist or `build` had nothing to write.
168
+ * @throws {RecordVersionConflictError} when the write missed twice.
169
+ * @complexity O(1) writes; at most two reads, two builds and one extra read for the message.
170
+ */
171
+ export declare function applyInternalChange<TRecord extends {
172
+ readonly version: number;
173
+ }>(required: {
174
+ recordKind: string;
175
+ recordId: string;
176
+ read: () => Promise<TRecord | null>;
177
+ build: (current: TRecord) => Promise<TRecord | null>;
178
+ write: (required: {
179
+ current: TRecord;
180
+ next: TRecord;
181
+ }) => Promise<boolean>;
182
+ }, _optional?: Record<string, never>): Promise<TRecord | null>;
183
+ //# sourceMappingURL=optimistic-concurrency.d.ts.map