@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,116 @@
1
+ import { collectProcessTreePids } from "./process.js";
2
+ /** Runs each critical section immediately and records the lock path and options it was asked for. */
3
+ export function fakeFileLock(_required = {}, _optional = {}) {
4
+ const calls = [];
5
+ const held = new Set();
6
+ return {
7
+ calls,
8
+ held,
9
+ async withFileLock(required, optional) {
10
+ calls.push({ lockPath: required.lockPath, options: optional });
11
+ held.add(required.lockPath);
12
+ try {
13
+ return await required.run({ lockPath: required.lockPath, assertHeld: async () => undefined });
14
+ }
15
+ finally {
16
+ held.delete(required.lockPath);
17
+ }
18
+ },
19
+ };
20
+ }
21
+ /** Writes into a `Map`; `createParent`, `mode` and the other options are recorded, not honoured. */
22
+ export function fakeAtomicWriter(_required = {}, _optional = {}) {
23
+ const files = new Map();
24
+ const writes = [];
25
+ const backups = [];
26
+ return {
27
+ files,
28
+ writes,
29
+ backups,
30
+ async writeText({ filePath, content }, optional) {
31
+ writes.push({ method: "writeText", filePath, options: optional });
32
+ files.set(filePath, content);
33
+ },
34
+ async writeJson({ filePath, data }, optional) {
35
+ writes.push({ method: "writeJson", filePath, options: optional });
36
+ const text = JSON.stringify(data, null, 2);
37
+ if (text === undefined)
38
+ throw new TypeError("writeJson was given data JSON cannot represent");
39
+ files.set(filePath, optional?.trailingNewline ? `${text}\n` : text);
40
+ },
41
+ async backupOriginalOnce({ filePath }) {
42
+ backups.push(filePath);
43
+ },
44
+ };
45
+ }
46
+ /**
47
+ * A process table that `stopProcesses` empties: it stops the requested pids and their descendants
48
+ * (the same tree walk the real port uses) and reports them as stopped, none forced.
49
+ * `waitForProcessExit` answers true once the pid is no longer in the table.
50
+ */
51
+ export function fakeProcessControl(_required = {}, optional = {}) {
52
+ let table = [...(optional.processes ?? [])];
53
+ const stopRequests = [];
54
+ const waited = [];
55
+ return {
56
+ stopRequests,
57
+ waited,
58
+ async listProcessSnapshots() {
59
+ return table.map((snapshot) => ({ ...snapshot }));
60
+ },
61
+ async stopProcesses({ pids }) {
62
+ stopRequests.push(pids);
63
+ const matchedPids = collectProcessTreePids({ processes: table.map((snapshot) => ({ ...snapshot })), rootPids: [...pids] }).filter((pid) => table.some((snapshot) => snapshot.pid === pid));
64
+ table = table.filter((snapshot) => !matchedPids.includes(snapshot.pid));
65
+ return { alreadyStopped: matchedPids.length === 0, forcedPids: [], matchedPids, remainingPids: [], stoppedPids: matchedPids };
66
+ },
67
+ async waitForProcessExit({ pid }) {
68
+ waited.push(pid);
69
+ return typeof pid !== "number" || !table.some((snapshot) => snapshot.pid === pid);
70
+ },
71
+ };
72
+ }
73
+ /** Answers every request from `respond` (default: `200` with an empty body) and records it. */
74
+ export function fakeHttpFetch(_required = {}, optional = {}) {
75
+ const calls = [];
76
+ const respond = optional.respond ?? (() => new Response(""));
77
+ return {
78
+ calls,
79
+ async fetchWithTimeout({ url, timeoutMs }, optional) {
80
+ calls.push({ url: String(url), timeoutMs, init: optional?.init });
81
+ return respond({ url: String(url), init: optional?.init });
82
+ },
83
+ async readResponseText({ response }) {
84
+ return response.text();
85
+ },
86
+ };
87
+ }
88
+ /**
89
+ * Serves `routes` through clients that never open a socket. A request that matches no route gets
90
+ * a `404` so a test fails on the assertion about the answer, not on an exception inside the fake.
91
+ */
92
+ export function fakeGuardedHttp(required, _optional = {}) {
93
+ const requests = [];
94
+ const clients = [];
95
+ const send = async ({ request }) => {
96
+ requests.push(request);
97
+ const route = required.routes[`${request.method} ${request.url}`];
98
+ const answer = typeof route === "function" ? route(request) : route;
99
+ return { status: 404, headers: {}, bodyText: "", finalUrl: request.url, ...answer };
100
+ };
101
+ return {
102
+ requests,
103
+ clients,
104
+ createClient(input) {
105
+ clients.push(input);
106
+ return { send };
107
+ },
108
+ async fetch({ client, url }, optional) {
109
+ const response = await client.send({
110
+ request: { method: (optional?.method ?? "GET"), url, headers: optional?.headers ?? {}, ...(typeof optional?.body === "string" ? { body: optional.body } : {}), idleTimeoutMs: optional?.idleTimeoutMs ?? 1 },
111
+ });
112
+ return new Response(response.bodyText, { status: response.status, headers: { ...response.headers } });
113
+ },
114
+ };
115
+ }
116
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1,10 @@
1
+ export * from "./runtime/platform.js";
2
+ export * from "./runtime/environment.js";
3
+ export * from "./runtime/command.js";
4
+ export * from "./runtime/process.js";
5
+ export * from "./runtime/file-lock.js";
6
+ export * from "./runtime/fs.js";
7
+ export * from "./runtime/terminal.js";
8
+ export * from "./runtime/http.js";
9
+ export * from "./runtime/reader.js";
10
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,10 @@
1
+ export * from "./runtime/platform.js";
2
+ export * from "./runtime/environment.js";
3
+ export * from "./runtime/command.js";
4
+ export * from "./runtime/process.js";
5
+ export * from "./runtime/file-lock.js";
6
+ export * from "./runtime/fs.js";
7
+ export * from "./runtime/terminal.js";
8
+ export * from "./runtime/http.js";
9
+ export * from "./runtime/reader.js";
10
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @file The JSON error shape every Jini route answers with, the status each error code maps to,
3
+ * and the standard validation failure.
4
+ */
5
+ import type { JsonValue } from '../../primitives/json.js';
6
+ /**
7
+ * The wire error shape. Restated structurally because core has no dependencies, so it cannot
8
+ * import the protocol package's `ApiError`; the two are mutually assignable.
9
+ */
10
+ export interface ServerApiError {
11
+ code: string;
12
+ message: string;
13
+ details?: JsonValue;
14
+ retryable?: boolean;
15
+ requestId?: string;
16
+ }
17
+ /** The `{ error }` envelope a failed route answers with. */
18
+ export interface ServerApiErrorResponse {
19
+ error: ServerApiError;
20
+ }
21
+ /** Wraps an error in the standard `{ error }` envelope. */
22
+ export declare const apiErrorBody: ({ error }: {
23
+ readonly error: ServerApiError;
24
+ }, _optional?: Record<string, never>) => ServerApiErrorResponse;
25
+ /** Resolves the HTTP status to send for an `ApiError`, defaulting to 500 for unmapped codes. */
26
+ export declare function statusForError({ error }: {
27
+ readonly error: ServerApiError;
28
+ }, _optional?: Record<string, never>): number;
29
+ /** Issue shape attached to a validation failure so clients can render per-field errors. */
30
+ export interface ServerValidationIssue {
31
+ readonly path: string;
32
+ readonly message: string;
33
+ }
34
+ /**
35
+ * Builds a `BAD_REQUEST` error for a failed parse. When `issues` is non-empty, attaches
36
+ * them as structured validation details so clients can render per-field errors.
37
+ */
38
+ export declare function validationError({ message }: {
39
+ readonly message: string;
40
+ }, { issues }?: {
41
+ readonly issues?: readonly ServerValidationIssue[] | undefined;
42
+ }): ServerApiError;
43
+ //# sourceMappingURL=api-error.d.ts.map
@@ -0,0 +1,49 @@
1
+ /** Wraps an error in the standard `{ error }` envelope. */
2
+ export const apiErrorBody = ({ error }, _optional = {}) => ({ error });
3
+ /**
4
+ * @internal
5
+ * Default HTTP status per generic error code. Codes not listed here fall back to 500 in
6
+ * `statusForError` — deliberately conservative, since an unmapped code (including any
7
+ * product-specific code a consuming pack defines) is more likely a new server-side failure mode
8
+ * than a client error.
9
+ */
10
+ const ERROR_STATUS_BY_CODE = {
11
+ BAD_REQUEST: 400,
12
+ UNAUTHORIZED: 401,
13
+ FORBIDDEN: 403,
14
+ NOT_FOUND: 404,
15
+ CONFLICT: 409,
16
+ PAYLOAD_TOO_LARGE: 413,
17
+ UNSUPPORTED_MEDIA_TYPE: 415,
18
+ VALIDATION_FAILED: 422,
19
+ RATE_LIMITED: 429,
20
+ INTERNAL_ERROR: 500,
21
+ UPSTREAM_UNAVAILABLE: 502,
22
+ SERVICE_UNAVAILABLE: 503,
23
+ NOT_CONFIGURED: 503,
24
+ TOOL_TOKEN_MISSING: 401,
25
+ TOOL_TOKEN_INVALID: 401,
26
+ TOOL_TOKEN_EXPIRED: 401,
27
+ TOOL_ENDPOINT_DENIED: 403,
28
+ TOOL_OPERATION_DENIED: 403,
29
+ TOOL_NOT_AVAILABLE: 503,
30
+ UNKNOWN_TOOL: 404,
31
+ TOOL_EXECUTION_FAILED: 422,
32
+ REMOTE_TOOL_BRIDGE_NOT_CONFIGURED: 503,
33
+ REMOTE_TOOL_BRIDGE_TOKEN_REQUIRED: 401,
34
+ OAUTH_FLOW_IN_PROGRESS: 409,
35
+ };
36
+ /** Resolves the HTTP status to send for an `ApiError`, defaulting to 500 for unmapped codes. */
37
+ export function statusForError({ error }, _optional = {}) {
38
+ return ERROR_STATUS_BY_CODE[error.code] ?? 500;
39
+ }
40
+ /**
41
+ * Builds a `BAD_REQUEST` error for a failed parse. When `issues` is non-empty, attaches
42
+ * them as structured validation details so clients can render per-field errors.
43
+ */
44
+ export function validationError({ message }, { issues = [] } = {}) {
45
+ if (issues.length === 0)
46
+ return { code: 'BAD_REQUEST', message };
47
+ return { code: 'BAD_REQUEST', message, details: { kind: 'validation', issues } };
48
+ }
49
+ //# sourceMappingURL=api-error.js.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @file Bearer-token header grammar shared by every bearer gate, so the accepted `Authorization`
3
+ * header is defined exactly once.
4
+ */
5
+ /**
6
+ * Extracts the token from an `Authorization: Bearer <token>` header value. The scheme is
7
+ * case-insensitive per RFC 7235 §2.1; the token itself is not.
8
+ *
9
+ * Shared by every bearer gate so the accepted header grammar is defined exactly
10
+ * once — three separate copies of this regex is three chances for them to disagree about what
11
+ * counts as a well-formed header.
12
+ *
13
+ * @param header - The raw `Authorization` header value, or `undefined` when absent.
14
+ * @returns The token, or `null` when the header is absent or not a well-formed bearer header.
15
+ * @complexity O(n) in the header length.
16
+ */
17
+ export declare function bearerTokenFromHeader({ header }: {
18
+ readonly header: string | undefined;
19
+ }, _optional?: Record<string, never>): string | null;
20
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @file Bearer-token header grammar shared by every bearer gate, so the accepted `Authorization`
3
+ * header is defined exactly once.
4
+ */
5
+ const BEARER_TOKEN_PATTERN = /^Bearer\s+(\S+)\s*$/i;
6
+ /**
7
+ * Extracts the token from an `Authorization: Bearer <token>` header value. The scheme is
8
+ * case-insensitive per RFC 7235 §2.1; the token itself is not.
9
+ *
10
+ * Shared by every bearer gate so the accepted header grammar is defined exactly
11
+ * once — three separate copies of this regex is three chances for them to disagree about what
12
+ * counts as a well-formed header.
13
+ *
14
+ * @param header - The raw `Authorization` header value, or `undefined` when absent.
15
+ * @returns The token, or `null` when the header is absent or not a well-formed bearer header.
16
+ * @complexity O(n) in the header length.
17
+ */
18
+ export function bearerTokenFromHeader({ header }, _optional = {}) {
19
+ return BEARER_TOKEN_PATTERN.exec(header ?? '')?.[1] ?? null;
20
+ }
21
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @file Conformance checks any `Server` adapter must pass: the contract's path syntax, precedence,
3
+ * decoding and HEAD rules. The caller supplies its test runner, so core imports none.
4
+ */
5
+ import type { Server } from '../server.js';
6
+ /** The test-runner functions the suite needs (vitest, jest and node:test all fit). */
7
+ export interface ConformanceRunner {
8
+ describe(name: string, body: () => void): void;
9
+ it(name: string, body: () => void | Promise<void>): void;
10
+ expect(value: unknown): {
11
+ toBe(expected: unknown): void;
12
+ toEqual(expected: unknown): void;
13
+ toThrow(): void;
14
+ };
15
+ }
16
+ /** A fresh adapter under test: the `Server` to register on and a way to send it a request. */
17
+ export interface ConformanceTarget {
18
+ readonly server: Server;
19
+ fetch(request: Request): Promise<Response>;
20
+ }
21
+ /** Registers the conformance suite for the adapter `makeServer` builds (a fresh one per case). */
22
+ export declare function serverConformance({ describe, it, expect }: ConformanceRunner, { makeServer }: {
23
+ makeServer: () => ConformanceTarget;
24
+ }): void;
25
+ //# sourceMappingURL=conformance.d.ts.map
@@ -0,0 +1,50 @@
1
+ const get = (path) => new Request(`http://localhost${path}`);
2
+ const answer = (label) => () => new Response(label);
3
+ /** Registers the conformance suite for the adapter `makeServer` builds (a fresh one per case). */
4
+ export function serverConformance({ describe, it, expect }, { makeServer }) {
5
+ describe('Server contract conformance', () => {
6
+ it('prefers a literal segment over :param', async () => {
7
+ const t = makeServer();
8
+ t.server.route({ method: 'GET', path: '/x/:id', handler: answer('param') });
9
+ t.server.route({ method: 'GET', path: '/x/new', handler: answer('literal') });
10
+ expect(await (await t.fetch(get('/x/new'))).text()).toBe('literal');
11
+ expect(await (await t.fetch(get('/x/other'))).text()).toBe('param');
12
+ });
13
+ it('decides precedence segment by segment from the left', async () => {
14
+ const t = makeServer();
15
+ t.server.route({ method: 'GET', path: '/a/:p/c', handler: answer('late') });
16
+ t.server.route({ method: 'GET', path: '/a/b/:q', handler: answer('early') });
17
+ expect(await (await t.fetch(get('/a/b/c'))).text()).toBe('early');
18
+ });
19
+ it('decodes params and treats malformed encoding as no match', async () => {
20
+ const t = makeServer();
21
+ t.server.route({ method: 'GET', path: '/n/:id', handler: ({ params }) => new Response(params.id ?? '') });
22
+ expect(await (await t.fetch(get('/n/a%20b'))).text()).toBe('a b');
23
+ expect((await t.fetch(get('/n/%'))).status).toBe(404);
24
+ });
25
+ it('never matches an empty segment against :name', async () => {
26
+ const t = makeServer();
27
+ t.server.route({ method: 'GET', path: '/n/:id', handler: answer('hit') });
28
+ expect((await t.fetch(get('/n/'))).status).toBe(404);
29
+ });
30
+ it('answers HEAD from the GET route without a body', async () => {
31
+ const t = makeServer();
32
+ t.server.route({ method: 'GET', path: '/h', handler: answer('body') });
33
+ const response = await t.fetch(new Request('http://localhost/h', { method: 'HEAD' }));
34
+ expect(response.status).toBe(200);
35
+ expect(await response.text()).toBe('');
36
+ });
37
+ it('refuses a duplicate registration', () => {
38
+ const t = makeServer();
39
+ t.server.route({ method: 'GET', path: '/d/:a', handler: answer('1') });
40
+ expect(() => t.server.route({ method: 'GET', path: '/d/:b', handler: answer('2') })).toThrow();
41
+ });
42
+ it('answers an unmatched request with 404, or 405 when only the method differs', async () => {
43
+ const t = makeServer();
44
+ t.server.route({ method: 'POST', path: '/p', handler: answer('p') });
45
+ expect((await t.fetch(get('/missing'))).status).toBe(404);
46
+ expect((await t.fetch(get('/p'))).status).toBe(405);
47
+ });
48
+ });
49
+ }
50
+ //# sourceMappingURL=conformance.js.map
@@ -0,0 +1,176 @@
1
+ /**
2
+ * @file Declarative JSON routes for the `Server` contract: `jsonRoute` turns a spec (parse, handle,
3
+ * origin policy, host ports) into one `ServerRoute`, so route modules return `ServerRoute[]` and the
4
+ * host mounts them on whatever adapter it runs.
5
+ */
6
+ import type { ServerRoute } from '../server.js';
7
+ import { type ServerApiError } from './api-error.js';
8
+ import { type OriginContext } from './origin.js';
9
+ import type { Result } from './result.js';
10
+ /**
11
+ * The normalized shape of a raw HTTP request handed to a route's `parse` function: body, query,
12
+ * and params, decoupled from any framework `Request` type so parsers are unit-testable without
13
+ * a real server.
14
+ */
15
+ export interface RouteInputContext {
16
+ body: unknown;
17
+ query: Record<string, unknown>;
18
+ params: Record<string, string>;
19
+ }
20
+ /** Parses a `RouteInputContext` into a typed `Input`, or fails with an error. */
21
+ export type InputParser<Input> = (raw: RouteInputContext) => Result<Input>;
22
+ /** HTTP verbs a `JsonRouteSpec` can be mounted under. */
23
+ export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch';
24
+ /** Explicit authorization remains at the route's chosen point, preserving validation precedence. */
25
+ export type JsonRouteAuthorize = (requiredArgs: {
26
+ readonly permission: string;
27
+ readonly entityType: string;
28
+ }, optionalArgs?: Record<string, never>) => Promise<void>;
29
+ /**
30
+ * Handles a parsed `Input` (plus injected `Deps`) and produces a `Result<Output>`.
31
+ *
32
+ * `signal` is optional and additive: it aborts if the client's connection drops before a response
33
+ * is written; handlers read it from their optional arguments when they perform cancellable work.
34
+ */
35
+ export type Handler<Input, Output, Deps, Context = undefined> = (requiredArgs: {
36
+ readonly input: Input;
37
+ readonly deps: Deps;
38
+ readonly context?: Context | undefined;
39
+ readonly authorize?: JsonRouteAuthorize;
40
+ }, optionalArgs?: {
41
+ readonly signal?: AbortSignal | undefined;
42
+ }) => Promise<Result<Output>> | Result<Output>;
43
+ /** What a host's incident sink receives for an exception no route anticipated. */
44
+ export interface RouteHostInternalErrorContext {
45
+ /** HTTP method of the route whose handler threw. */
46
+ readonly method: string;
47
+ /** Registered path of the route whose handler threw. */
48
+ readonly path: string;
49
+ /** Echoed back to the caller as the response's `requestId`, so an operator can tie a user's report to this log line. */
50
+ readonly correlationId: string;
51
+ /** The exception exactly as thrown — never sent to the caller. */
52
+ readonly error: unknown;
53
+ }
54
+ /**
55
+ * Records an unanticipated exception (SEC-005) and returns the caller-safe error to answer with.
56
+ * Required on the host: generating the correlation id needs a runtime API core does not have.
57
+ */
58
+ export type ReportRouteInternalError = <E extends {
59
+ readonly error: unknown;
60
+ }>(required: {
61
+ readonly report: E;
62
+ readonly logSource: string;
63
+ readonly message: string;
64
+ }, optional?: {
65
+ readonly onInternalError?: ((context: E & {
66
+ readonly correlationId: string;
67
+ readonly logSource: string;
68
+ }) => void) | undefined;
69
+ }) => ServerApiError;
70
+ /** Server startup state a route needs to evaluate its same-origin guard and report incidents. */
71
+ export interface RouteHostContext extends OriginContext {
72
+ /**
73
+ * Host-owned sink for the real exception behind a generic `INTERNAL_ERROR` response (SEC-005).
74
+ * The catch-all for a route that throws outside its own guarded path.
75
+ */
76
+ readonly onInternalError?: (context: RouteHostInternalErrorContext) => void;
77
+ }
78
+ /**
79
+ * Host-owned workspace, authentication/authorization and exception policy.
80
+ * Guards throw on rejection; the error port owns the answer. Without an error port the
81
+ * route keeps its caller-safe-error and SEC-005 redaction policy. Authentication can await
82
+ * host readiness; it runs after workspace rejection and before parsing or handling.
83
+ */
84
+ export interface JsonRoutePorts<Deps, Context = undefined> {
85
+ readonly workspace?: (required: {
86
+ readonly raw: RouteInputContext;
87
+ readonly deps: Deps;
88
+ }) => void | Promise<void>;
89
+ readonly authenticate?: (required: {
90
+ readonly raw: RouteInputContext;
91
+ readonly request: Request;
92
+ readonly locals: Record<string, unknown>;
93
+ readonly deps: Deps;
94
+ }) => Context | Promise<Context>;
95
+ readonly authorize?: (required: {
96
+ readonly context: Context | undefined;
97
+ readonly deps: Deps;
98
+ readonly permission: string;
99
+ readonly entityType: string;
100
+ }) => void | Promise<void>;
101
+ /** Host error policy; returns the answer instead of writing it. */
102
+ readonly onError?: (required: {
103
+ readonly error: unknown;
104
+ readonly request: Request;
105
+ }) => Response | Promise<Response>;
106
+ }
107
+ /** Declarative description of one JSON route. Consumed by {@link jsonRoute}. */
108
+ export interface JsonRouteSpec<Input, Output, Deps, Context = undefined> {
109
+ method: HttpMethod;
110
+ path: string;
111
+ requireSameOrigin?: boolean;
112
+ /** Body ceiling for every method but GET. Defaults to the shared JSON body limit. */
113
+ maxBodyBytes?: number;
114
+ parse: InputParser<Input>;
115
+ handle: Handler<Input, Output, Deps, Context>;
116
+ successStatus?: number;
117
+ ports?: JsonRoutePorts<Deps, Context>;
118
+ }
119
+ /**
120
+ * Thrown by a route's `handle` — or by anything it calls, at any depth — to bypass the SEC-005
121
+ * redaction below with an error the throwing code has already decided is safe for the caller
122
+ * to see. Prefer returning `err(...)` from `handle` when the failure is anticipated at that point;
123
+ * this class is for the same kind of failure discovered a level deeper, inside an awaited call
124
+ * `handle` did not wrap in its own `try`.
125
+ *
126
+ * Not a way to defeat SEC-005: the only way to reach the branch that reads this class is for code to
127
+ * construct one itself, naming the exact error — code and message — it is choosing to disclose.
128
+ * Any thrown value that is not this class (including a plain `Error` with an actionable-looking
129
+ * message) still redacts; nothing here widens what a route can leak by accident.
130
+ */
131
+ export declare class ClientFacingError extends Error {
132
+ readonly apiError: ServerApiError;
133
+ constructor({ apiError }: {
134
+ readonly apiError: ServerApiError;
135
+ }, _optional?: Record<string, never>);
136
+ }
137
+ /**
138
+ * Combines required route fields and optional settings into a fresh spec while pinning its generic
139
+ * parameters at the definition site so callers do not have to repeat them. Optional settings take
140
+ * precedence. Never mutates either argument.
141
+ * @complexity O(1) time/space for the fixed spec fields.
142
+ */
143
+ export declare function defineJsonRoute<Input, Output, Deps, Context = undefined>(requiredArgs: Omit<JsonRouteSpec<Input, Output, Deps, Context>, 'requireSameOrigin' | 'successStatus' | 'ports' | 'maxBodyBytes'>, optionalArgs?: Pick<JsonRouteSpec<Input, Output, Deps, Context>, 'requireSameOrigin' | 'successStatus' | 'ports' | 'maxBodyBytes'>): JsonRouteSpec<Input, Output, Deps, Context>;
144
+ /**
145
+ * A JSON response with Express's `res.json` content type, so clients see the same header. A null-body
146
+ * status (204, 205, 304) gets no body and no content type.
147
+ */
148
+ export declare function jsonResponse({ status, body }: {
149
+ readonly status: number;
150
+ readonly body: unknown;
151
+ }, { headers }?: {
152
+ readonly headers?: Readonly<Record<string, string>>;
153
+ }): Response;
154
+ /**
155
+ * Builds the one `ServerRoute` for `spec`. The route's parse and handle functions operate on
156
+ * `RouteInputContext` and `Deps`, so they are unit testable without a server. A host context is
157
+ * required only for routes that opt into the same-origin guard or that can throw unanticipated errors.
158
+ */
159
+ export declare function jsonRoute<I, O, D, C = undefined>({ spec, deps, reportInternalError }: {
160
+ readonly spec: JsonRouteSpec<I, O, D, C>;
161
+ readonly deps: D;
162
+ readonly reportInternalError: ReportRouteInternalError;
163
+ }, { host }?: {
164
+ readonly host?: RouteHostContext;
165
+ }): ServerRoute;
166
+ /**
167
+ * The same-origin check for a hand-built route (an SSE stream, an upload) that is not a `jsonRoute` and so does not
168
+ * get `requireSameOrigin`: the host's origin policy is asked with the request's `host`, `origin` and `sec-fetch-site`
169
+ * headers, and a refusal is the standard 403 `Response`. Returns `undefined` when the request may proceed, so the
170
+ * route's first line is `const refused = sameOriginRefusal(...); if (refused) return refused;`.
171
+ */
172
+ export declare function sameOriginRefusal({ request, origin }: {
173
+ readonly request: Request;
174
+ readonly origin: OriginContext;
175
+ }, _optional?: Record<string, never>): Response | undefined;
176
+ //# sourceMappingURL=json-route.d.ts.map