@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,113 @@
1
+ /**
2
+ * @file The slice of an embedded SQLite driver connection this package uses, written structurally so the
3
+ * package needs neither that driver nor its types: a consumer's own `Database` instance satisfies
4
+ * it as-is. Keeping the driver out of the type graph also keeps two installed copies (the consumer's
5
+ * and a linked dev copy of this package's) from becoming two incompatible nominal types.
6
+ */
7
+ /** A prepared statement, as much of one as the query-builder binding shim and the ops call. */
8
+ export interface SqliteStatement {
9
+ readonly reader: boolean;
10
+ all(...parameters: unknown[]): unknown[];
11
+ run(...parameters: unknown[]): {
12
+ changes: number | bigint;
13
+ lastInsertRowid: number | bigint;
14
+ };
15
+ iterate(...parameters: unknown[]): IterableIterator<unknown>;
16
+ }
17
+ /** An embedded SQLite driver `Database`. */
18
+ export interface SqliteClient {
19
+ /** True for `:memory:` and other private in-memory databases. */
20
+ readonly memory: boolean;
21
+ /** The path it was opened with. */
22
+ readonly name: string;
23
+ readonly inTransaction: boolean;
24
+ exec(source: string): unknown;
25
+ prepare(source: string): SqliteStatement;
26
+ pragma(source: string): unknown;
27
+ backup(destinationFile: string): Promise<unknown>;
28
+ close(): unknown;
29
+ }
30
+ /** embedded SQLite driver's constructor options this package passes. */
31
+ export interface SqliteOpenOptions {
32
+ readonly?: boolean;
33
+ fileMustExist?: boolean;
34
+ }
35
+ /** The consumer's way to open a connection with ITS copy of embedded SQLite driver: `(p, o) => new Database(p, o)`. */
36
+ export type SqliteOpener<Connection extends SqliteClient = SqliteClient> = (filePath: string, options: SqliteOpenOptions) => Connection;
37
+ /** Structural synchronous SQLite contract for legacy CRUD; the host owns the driver. */
38
+ /** Prepared query preserving typed positional bindings and rows. */
39
+ export interface SqliteSyncStatement<Parameters extends unknown[] = unknown[], Result = unknown> {
40
+ readonly reader: boolean;
41
+ run(...parameters: Parameters): {
42
+ changes: number | bigint;
43
+ lastInsertRowid: number | bigint;
44
+ };
45
+ get(...parameters: Parameters): Result | undefined;
46
+ all(...parameters: Parameters): Result[];
47
+ iterate(...parameters: Parameters): IterableIterator<Result>;
48
+ }
49
+ /** Callable transaction with the driver's explicit lock modes. */
50
+ export interface SqliteSyncTransaction<Args extends unknown[], Result> {
51
+ (...args: Args): Result;
52
+ deferred(...args: Args): Result;
53
+ immediate(...args: Args): Result;
54
+ exclusive(...args: Args): Result;
55
+ }
56
+ /** Separate sync API; the kernel's minimal SqliteClient remains unchanged. */
57
+ export interface SqliteSyncClient extends SqliteClient {
58
+ readonly open: boolean;
59
+ prepare<Parameters extends unknown[] | object = unknown[], Result = unknown>(source: string): Parameters extends unknown[] ? SqliteSyncStatement<Parameters, Result> : SqliteSyncStatement<[Parameters], Result>;
60
+ pragma(source: string, options?: {
61
+ simple?: boolean;
62
+ }): unknown;
63
+ transaction<Args extends unknown[], Result>(body: (...args: Args) => Result): SqliteSyncTransaction<Args, Result>;
64
+ }
65
+ /** Published 0.3.x alias, now structural rather than tied to a driver installation. */
66
+ export type SqliteDb = SqliteSyncClient;
67
+ /** Host acquisition seam, also preserving an actual driver's richer handle type. */
68
+ export type SqliteSyncOpener<Connection extends SqliteSyncClient = SqliteSyncClient> = (file: string, options: SqliteOpenOptions) => Connection;
69
+ /**
70
+ * @file SQLite driver type surface. Types only — no runtime declarations, so this module erases
71
+ * entirely at compile time.
72
+ *
73
+ * Nothing here references an ORM. That is the point: a type on this package's public surface must
74
+ * be a plain structural shape, which crosses a
75
+ * package boundary cleanly. See `@jini-ai/db/sqlite` `open.ts`'s module doc for the measured failure that made this a
76
+ * rule rather than a preference.
77
+ */
78
+ /**
79
+ * A caller-injected hook run against `filePath` BEFORE the connection is opened.
80
+ *
81
+ * Dependency inversion on purpose: recovery policy (replaying a half-applied migration,
82
+ * quarantining a corrupt file) is host knowledge, and a persistence package reaching up into host
83
+ * feature code to fetch it would be a layer-direction violation. The hook is optional, but when
84
+ * supplied it runs for every path, including `:memory:`. A host with file-only recovery must make
85
+ * its hook a no-op for ephemeral connections and hermetic tests, where there is nothing to recover.
86
+ */
87
+ export type SqliteRecoveryHook = (required: {
88
+ filePath: string;
89
+ }, options?: Record<string, never>) => void;
90
+ export interface OpenSqliteConnectionOptions<Connection extends SqliteClient = SqliteClient> {
91
+ /** The consumer opens with its own driver copy. */
92
+ readonly open: (required: {
93
+ filePath: string;
94
+ }, options: Record<string, never>) => Connection;
95
+ /** Filesystem path, or `':memory:'` for an ephemeral connection. */
96
+ readonly filePath: string;
97
+ /**
98
+ * Pragma statements applied immediately after open, **replacing** (not extending) the defaults.
99
+ * Pass the full list you want; see `DEFAULT_PRAGMAS` for what you are replacing and why each
100
+ * default is there.
101
+ */
102
+ readonly pragmas?: readonly string[];
103
+ readonly recover?: SqliteRecoveryHook;
104
+ }
105
+ /**
106
+ * The minimum a caller must supply for restore-point capture: the raw driver's online-backup
107
+ * method and nothing else. Structurally minimal so a host can pass a real connection or a narrow
108
+ * test double, and so this package never needs to name the host's ORM handle type.
109
+ */
110
+ export type SqliteBackupSource = {
111
+ backup(destination: string): Promise<unknown>;
112
+ };
113
+ //# sourceMappingURL=sqlite.d.ts.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @file The slice of an embedded SQLite driver connection this package uses, written structurally so the
3
+ * package needs neither that driver nor its types: a consumer's own `Database` instance satisfies
4
+ * it as-is. Keeping the driver out of the type graph also keeps two installed copies (the consumer's
5
+ * and a linked dev copy of this package's) from becoming two incompatible nominal types.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=sqlite.js.map
@@ -0,0 +1,25 @@
1
+ /** @file Pure value helpers for rows read through a {@link StorageKernel}; no driver or query library. */
2
+ /** A boolean column as read: `true`/`false` on Postgres, `1`/`0` on SQLite. NULL stays null. */
3
+ export declare function toBool({ value }: {
4
+ value: boolean | number | null | undefined;
5
+ }, _optional?: Record<string, never>): boolean | null;
6
+ /**
7
+ * True iff `err` is a UNIQUE violation, from any driver: SQLite's `SQLITE_CONSTRAINT_UNIQUE` /
8
+ * "UNIQUE constraint failed", Postgres SQLSTATE `23505` (the Postgres drivers both set `code`).
9
+ * The message check also covers the in-memory test doubles, which throw SQLite's wording.
10
+ */
11
+ export declare function isUniqueViolation({ err }: {
12
+ err: unknown;
13
+ }, _optional?: Record<string, never>): boolean;
14
+ /** A blob/bytea value as bytes, whichever shape the driver returned (Buffer, Uint8Array). */
15
+ export declare function toBytes({ value }: {
16
+ value: unknown;
17
+ }, _optional?: Record<string, never>): Uint8Array;
18
+ export interface ColumnInfo {
19
+ name: string;
20
+ /** The declared type, lower-case, in the dialect's own spelling (`text`, `integer`, `bigint`…). */
21
+ type: string;
22
+ notNull: boolean;
23
+ primaryKey: boolean;
24
+ }
25
+ //# sourceMappingURL=values.d.ts.map
@@ -0,0 +1,25 @@
1
+ /** @file Pure value helpers for rows read through a {@link StorageKernel}; no driver or query library. */
2
+ /** A boolean column as read: `true`/`false` on Postgres, `1`/`0` on SQLite. NULL stays null. */
3
+ export function toBool({ value }, _optional = {}) {
4
+ if (value === null || value === undefined)
5
+ return null;
6
+ return value === true || value === 1;
7
+ }
8
+ /**
9
+ * True iff `err` is a UNIQUE violation, from any driver: SQLite's `SQLITE_CONSTRAINT_UNIQUE` /
10
+ * "UNIQUE constraint failed", Postgres SQLSTATE `23505` (the Postgres drivers both set `code`).
11
+ * The message check also covers the in-memory test doubles, which throw SQLite's wording.
12
+ */
13
+ export function isUniqueViolation({ err }, _optional = {}) {
14
+ if (!(err instanceof Error))
15
+ return false;
16
+ const code = err.code;
17
+ return code === "SQLITE_CONSTRAINT_UNIQUE" || code === "23505" || err.message.includes("UNIQUE constraint failed");
18
+ }
19
+ /** A blob/bytea value as bytes, whichever shape the driver returned (Buffer, Uint8Array). */
20
+ export function toBytes({ value }, _optional = {}) {
21
+ if (value instanceof Uint8Array)
22
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
23
+ throw new Error(`expected a binary column value, got ${typeof value}`);
24
+ }
25
+ //# sourceMappingURL=values.js.map
@@ -0,0 +1,8 @@
1
+ /** @agent-note Library-neutral types and pure row/value helpers only. Kernels, drivers, `sql`-built helpers and the
2
+ * migration runner live in the host's storage package (`@jini-ai/db`). Never import a query library or driver here. */
3
+ export * from "./storage/kernel.js";
4
+ export * from "./storage/values.js";
5
+ export * from "./storage/rows.js";
6
+ export type * from "./storage/sqlite.js";
7
+ export type * from "./storage/migration.js";
8
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1,6 @@
1
+ /** @agent-note Library-neutral types and pure row/value helpers only. Kernels, drivers, `sql`-built helpers and the
2
+ * migration runner live in the host's storage package (`@jini-ai/db`). Never import a query library or driver here. */
3
+ export * from "./storage/kernel.js";
4
+ export * from "./storage/values.js";
5
+ export * from "./storage/rows.js";
6
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1,26 @@
1
+ import type { VaultErrorCode, VaultOptions, VaultRecord, VaultQuery, VaultDefaultQuery, VaultPutRecord } from "./records.js";
2
+ export declare const VAULT_KINDS: readonly ["site-assistant", "personal-execution", "media-provider", "publish-peer", "database-destination", "vendor", "source-control", "mcp-env", "mcp-auth", "api-connection"];
3
+ /** Safe error codes never contain submitted values or encrypted material. */
4
+ export declare class VaultError extends Error {
5
+ readonly code: VaultErrorCode;
6
+ constructor({ code }: {
7
+ code: VaultError["code"];
8
+ }, _options?: VaultOptions);
9
+ }
10
+ /** The record belongs to the query's exact workspace, kind, owner and principal; an omitted provider
11
+ * matches every provider. @complexity O(1). */
12
+ export declare function isInVaultQueryScope({ record, query }: {
13
+ record: Pick<VaultRecord, keyof VaultQuery>;
14
+ query: VaultQuery;
15
+ }, _options?: VaultOptions): boolean;
16
+ /** Unambiguous scope encoding keeps adapter default/identity checks on the same contract. */
17
+ export declare function vaultGroupKey({ record }: {
18
+ record: VaultDefaultQuery;
19
+ }, _options?: VaultOptions): string;
20
+ /** Adapters guard CAS and immutable identity even for callers below the service. */
21
+ export declare function assertVaultReplacement({ record, existing, expectedRevision }: {
22
+ record: VaultPutRecord;
23
+ existing: VaultRecord | null;
24
+ expectedRevision: number | null;
25
+ }, _options?: VaultOptions): void;
26
+ //# sourceMappingURL=invariants.d.ts.map
@@ -0,0 +1,49 @@
1
+ export const VAULT_KINDS = ["site-assistant", "personal-execution", "media-provider", "publish-peer",
2
+ "database-destination", "vendor", "source-control", "mcp-env", "mcp-auth", "api-connection"];
3
+ /** Safe error codes never contain submitted values or encrypted material. */
4
+ export class VaultError extends Error {
5
+ code;
6
+ constructor({ code }, _options = {}) {
7
+ super(`Secrets vault: ${code}`);
8
+ this.code = code;
9
+ this.name = "VaultError";
10
+ }
11
+ }
12
+ /** The record belongs to the query's exact workspace, kind, owner and principal; an omitted provider
13
+ * matches every provider. @complexity O(1). */
14
+ export function isInVaultQueryScope({ record, query }, _options = {}) {
15
+ const sameOwner = record.workspaceId === query.workspaceId && record.kind === query.kind && record.ownerKey === query.ownerKey;
16
+ const sameProvider = query.provider === undefined || record.provider === query.provider;
17
+ return sameOwner && record.principalId === query.principalId && sameProvider;
18
+ }
19
+ /** Unambiguous scope encoding keeps adapter default/identity checks on the same contract. */
20
+ export function vaultGroupKey({ record }, _options = {}) {
21
+ return JSON.stringify([record.workspaceId, record.kind, record.ownerKey, record.principalId, record.provider]);
22
+ }
23
+ /** Fields fixed at create and checked on every replacement. */
24
+ // Provider groups defaults, but is not authenticated identity (see buildVaultAad).
25
+ const IMMUTABLE_FIELDS = ["workspaceId", "kind", "ownerKey", "principalId", "id", "binding", "createdAt"];
26
+ function assertRevision({ record, existing, expectedRevision }) {
27
+ if (expectedRevision === null ? existing !== null : existing?.revision !== expectedRevision)
28
+ throw new VaultError({ code: "conflict" });
29
+ if (!Number.isSafeInteger(record.revision) || record.revision !== (expectedRevision ?? 0) + 1)
30
+ throw new VaultError({ code: "invalid-record" });
31
+ }
32
+ function assertSameIdentity({ record, existing }) {
33
+ if (IMMUTABLE_FIELDS.some(field => record[field] !== existing[field]))
34
+ throw new VaultError({ code: "context" });
35
+ if (existing.kind === "vendor") {
36
+ // Missing subtype identifies a pre-unification vendor; an explicit null is not a default.
37
+ const previousType = existing.meta.credentialType === undefined ? "vendor" : existing.meta.credentialType;
38
+ const nextType = record.meta.credentialType === undefined ? "vendor" : record.meta.credentialType;
39
+ if (nextType !== previousType)
40
+ throw new VaultError({ code: "context" });
41
+ }
42
+ }
43
+ /** Adapters guard CAS and immutable identity even for callers below the service. */
44
+ export function assertVaultReplacement({ record, existing, expectedRevision }, _options = {}) {
45
+ assertRevision({ record, existing, expectedRevision });
46
+ if (existing)
47
+ assertSameIdentity({ record, existing });
48
+ }
49
+ //# sourceMappingURL=invariants.js.map
@@ -11,4 +11,5 @@ export interface SealedSecret {
11
11
  export type * from './vault/ports.js';
12
12
  export type * from './vault/vendor-credential-sets.js';
13
13
  export type * from './vault/records.js';
14
+ export * from "./vault/invariants.js";
14
15
  //# sourceMappingURL=vault.d.ts.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export * from "./vault/invariants.js";
2
2
  //# sourceMappingURL=vault.js.map
@@ -0,0 +1,21 @@
1
+ /** One coercer and one plain-words description per value type. A lookup table, not a switch,
2
+ * so adding a type cannot grow one function past the complexity limit. Pure; no I/O.
3
+ */
4
+ import type { EnvValueType, EnvVarSpec } from '../contracts/env.js';
5
+ export type Coerced = {
6
+ readonly ok: true;
7
+ readonly value: unknown;
8
+ } | {
9
+ readonly ok: false;
10
+ };
11
+ type Coercer = (input: {
12
+ readonly raw: string;
13
+ readonly spec: EnvVarSpec;
14
+ }) => Coerced;
15
+ export declare const COERCERS: Readonly<Record<EnvValueType, Coercer>>;
16
+ /** What the variable accepts, in words an operator can act on. */
17
+ export declare function describeExpected({ spec }: {
18
+ spec: EnvVarSpec;
19
+ }, _optional?: Record<string, never>): string;
20
+ export {};
21
+ //# sourceMappingURL=coercers.d.ts.map
@@ -0,0 +1,68 @@
1
+ const REJECTED = { ok: false };
2
+ const DEFAULT_ON = ['1', 'true'];
3
+ const DEFAULT_OFF = ['0', 'false'];
4
+ function wholeNumber({ raw, spec, floor }) {
5
+ const text = raw.trim();
6
+ if (!/^-?\d+$/.test(text))
7
+ return REJECTED;
8
+ const value = Number(text);
9
+ const min = spec.accepts?.min ?? floor;
10
+ const max = spec.accepts?.max ?? Number.MAX_SAFE_INTEGER;
11
+ return Number.isSafeInteger(value) && value >= min && value <= max ? { ok: true, value } : REJECTED;
12
+ }
13
+ /** Flag and enum words are compared with the raw text: today's readers do not trim or fold case. */
14
+ const flag = ({ raw, spec }) => {
15
+ if ((spec.accepts?.on ?? DEFAULT_ON).includes(raw))
16
+ return { ok: true, value: true };
17
+ return (spec.accepts?.off ?? DEFAULT_OFF).includes(raw) ? { ok: true, value: false } : REJECTED;
18
+ };
19
+ const origin = ({ raw }) => {
20
+ const text = raw.trim();
21
+ return URL.canParse(text) && new URL(text).origin === text ? { ok: true, value: text } : REJECTED;
22
+ };
23
+ /** A parse failure is reported as an invalid value by the caller; nothing is swallowed. */
24
+ const json = ({ raw }) => {
25
+ try {
26
+ return { ok: true, value: JSON.parse(raw) };
27
+ }
28
+ catch {
29
+ return REJECTED;
30
+ }
31
+ };
32
+ export const COERCERS = {
33
+ string: ({ raw }) => ({ ok: true, value: raw }),
34
+ path: ({ raw }) => ({ ok: true, value: raw }),
35
+ int: ({ raw, spec }) => wholeNumber({ raw, spec, floor: Number.MIN_SAFE_INTEGER }),
36
+ 'duration-ms': ({ raw, spec }) => wholeNumber({ raw, spec, floor: 0 }),
37
+ flag,
38
+ enum: ({ raw, spec }) => (spec.accepts?.values?.includes(raw) ? { ok: true, value: raw } : REJECTED),
39
+ url: ({ raw }) => (URL.canParse(raw.trim()) ? { ok: true, value: raw.trim() } : REJECTED),
40
+ origin,
41
+ list: ({ raw }) => ({ ok: true, value: raw.split(',').map(item => item.trim()).filter(item => item !== '') }),
42
+ json,
43
+ };
44
+ function range({ spec, unit }) {
45
+ const { min, max } = spec.accepts ?? {};
46
+ if (min !== undefined && max !== undefined)
47
+ return `${unit} from ${min} to ${max}`;
48
+ if (min !== undefined)
49
+ return `${unit} of ${min} or more`;
50
+ return max !== undefined ? `${unit} of ${max} or less` : unit;
51
+ }
52
+ const EXPECTED = {
53
+ string: () => 'text',
54
+ path: () => 'a file or folder path',
55
+ int: ({ spec }) => range({ spec, unit: 'a whole number' }),
56
+ 'duration-ms': ({ spec }) => range({ spec, unit: 'a whole number of milliseconds' }),
57
+ flag: ({ spec }) => `${(spec.accepts?.on ?? DEFAULT_ON).join(' or ')} to turn it on, or ${(spec.accepts?.off ?? DEFAULT_OFF).join(' or ')} to turn it off`,
58
+ enum: ({ spec }) => `one of: ${(spec.accepts?.values ?? []).join(', ')}`,
59
+ url: () => 'a full web address such as https://example.com/path',
60
+ origin: () => 'a web address with no path, such as https://example.com',
61
+ list: () => 'a comma-separated list',
62
+ json: () => 'valid JSON',
63
+ };
64
+ /** What the variable accepts, in words an operator can act on. */
65
+ export function describeExpected({ spec }, _optional = {}) {
66
+ return EXPECTED[spec.type]({ spec });
67
+ }
68
+ //# sourceMappingURL=coercers.js.map
@@ -0,0 +1,16 @@
1
+ /** Pure environment descriptions for host-owned diagnostics. */
2
+ import type { EnvSchema, HostEnvironment } from '../contracts/env.js';
3
+ /** Describe every schema name and every supplied env name without applying defaults or coercion.
4
+ * Values require an explicit non-secret value display; unknown names always show presence only.
5
+ * Pure: no I/O, ambient reads or input mutation; bad values do not throw.
6
+ * @param required The host's schema and environment snapshot.
7
+ * @returns Env names mapped to sanitized values, `set (N characters)` or `not set`.
8
+ * @complexity O(s + e) lookups for s specs and e env entries, plus shown-value redaction;
9
+ * O(s + e) map entries and bounded text per entry.
10
+ * @example describeEnvForDiagnostics({ schema, env: hostEnv });
11
+ */
12
+ export declare function describeEnvForDiagnostics<Config>(required: {
13
+ readonly schema: EnvSchema<Config>;
14
+ readonly env: HostEnvironment;
15
+ }, _optional?: Record<string, never>): Readonly<Record<string, string>>;
16
+ //# sourceMappingURL=describe-env-for-diagnostics.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { echoEnvValue } from './value-echo.js';
2
+ /** Render only the disclosure-safe echo, never the raw environment value. */
3
+ function describeEcho({ echo }) {
4
+ if (echo.kind === 'shown')
5
+ return echo.text;
6
+ return echo.kind === 'hidden' ? `set (${echo.length} characters)` : 'not set';
7
+ }
8
+ /** Describe every schema name and every supplied env name without applying defaults or coercion.
9
+ * Values require an explicit non-secret value display; unknown names always show presence only.
10
+ * Pure: no I/O, ambient reads or input mutation; bad values do not throw.
11
+ * @param required The host's schema and environment snapshot.
12
+ * @returns Env names mapped to sanitized values, `set (N characters)` or `not set`.
13
+ * @complexity O(s + e) lookups for s specs and e env entries, plus shown-value redaction;
14
+ * O(s + e) map entries and bounded text per entry.
15
+ * @example describeEnvForDiagnostics({ schema, env: hostEnv });
16
+ */
17
+ export function describeEnvForDiagnostics(required, _optional = {}) {
18
+ const { schema, env } = required;
19
+ const byName = new Map(schema.specs.map(spec => [spec.name, spec]));
20
+ const names = new Set([...byName.keys(), ...Object.keys(env)]);
21
+ return Object.fromEntries([...names].map(name => [name, describeEcho({ echo: echoEnvValue({ spec: byName.get(name), raw: env[name] }) })]));
22
+ }
23
+ //# sourceMappingURL=describe-env-for-diagnostics.js.map
@@ -0,0 +1,13 @@
1
+ /** Plain words for one environment issue: the variable, what was expected, what happens now, the fix.
2
+ * The text is built only from the issue, which never holds a raw secret, so it is safe to print.
3
+ */
4
+ import type { EnvIssue } from '../contracts/env.js';
5
+ /** @param required The issue and the host's product name, as its operator knows it.
6
+ * @returns Three lines for a rejected value, two for an unknown name. Pure; O(length of the text).
7
+ * @example formatEnvIssue({ issue, product: 'Host' });
8
+ */
9
+ export declare function formatEnvIssue(required: {
10
+ readonly issue: EnvIssue;
11
+ readonly product: string;
12
+ }, _optional?: Record<string, never>): string;
13
+ //# sourceMappingURL=format-env-issue.d.ts.map
@@ -0,0 +1,22 @@
1
+ function received({ echo }) {
2
+ if (echo.kind === 'shown')
3
+ return `is set to "${echo.text}"`;
4
+ return echo.kind === 'hidden' ? `is set (${echo.length} characters, not shown)` : 'is not set';
5
+ }
6
+ function unknownName({ issue, product }) {
7
+ const hint = issue.suggestion === undefined ? '' : ` Did you mean ${issue.suggestion}?`;
8
+ return `${issue.name} is set, but ${product} has no setting with that name.${hint}\nNothing was changed. To fix: ${issue.fix}.`;
9
+ }
10
+ /** @param required The issue and the host's product name, as its operator knows it.
11
+ * @returns Three lines for a rejected value, two for an unknown name. Pure; O(length of the text).
12
+ * @example formatEnvIssue({ issue, product: 'Host' });
13
+ */
14
+ export function formatEnvIssue(required, _optional = {}) {
15
+ const { issue, product } = required;
16
+ if (issue.problem === 'unknown-name')
17
+ return unknownName({ issue, product });
18
+ // No default to name: either there is none, or it is a secret's default and may not be shown.
19
+ const now = issue.usedInstead === undefined ? `${product} is not using this value.` : `${product} is using ${issue.usedInstead} instead.`;
20
+ return `${issue.name} ${received({ echo: issue.received })}. ${product} expected ${issue.expected}.\n${now}\nTo fix: ${issue.fix}`;
21
+ }
22
+ //# sourceMappingURL=format-env-issue.js.map
@@ -0,0 +1,24 @@
1
+ /** Turn a schema and an environment map into a frozen config plus plain-words issues.
2
+ *
3
+ * The parser never stops a boot: a bad value becomes an issue and the default is used. A value
4
+ * with its own validator (`validation: 'owner'`) is handed on as raw text, unjudged, so the code
5
+ * that refuses it today keeps refusing it with its own error at its own time. Values that are
6
+ * not delivered through the environment are never read here and never enter the config.
7
+ */
8
+ import type { EnvSchema, EnvVarSpec, HostEnvironment, ParsedEnv } from '../contracts/env.js';
9
+ /** Pure: no I/O, never logs, never throws on a bad value. Every issue is returned, not the first.
10
+ * @param required The host's schema and the map to read (the ambient environment, a child's
11
+ * launch map or a per-scope snapshot: the parser treats them alike).
12
+ * @param optional `declared`: names another list already owns (allow-lists, vendor names), so
13
+ * they are not reported as unknown.
14
+ * @returns A deep-frozen config, the variable that set each field, and every issue found.
15
+ * @complexity O(s + e) for s specs and e entries; each unknown name adds one pass over the names.
16
+ * @example parseEnv({ schema, env: hostEnv }).issues.map(issue => formatEnvIssue({ issue, product: 'Host' }));
17
+ */
18
+ export declare function parseEnv<Config>(required: {
19
+ readonly schema: EnvSchema<Config>;
20
+ readonly env: HostEnvironment;
21
+ }, optional?: {
22
+ readonly declared?: readonly EnvVarSpec[];
23
+ }): ParsedEnv<Config>;
24
+ //# sourceMappingURL=parse-env.d.ts.map
@@ -0,0 +1,102 @@
1
+ import { COERCERS, describeExpected } from './coercers.js';
2
+ import { echoEnvValue, isSet } from './value-echo.js';
3
+ /** The controlling variable's raw text when set, otherwise its own default. */
4
+ function isActive({ spec, env, byName }) {
5
+ const gate = spec.activeWhen;
6
+ if (!gate)
7
+ return true;
8
+ const raw = env[gate.name];
9
+ const controlling = isSet({ value: raw }) ? raw : byName.get(gate.name)?.default;
10
+ return controlling !== undefined && gate.in.includes(controlling);
11
+ }
12
+ function defaultValue({ spec }) {
13
+ if (spec.default === undefined)
14
+ return undefined;
15
+ const coerced = COERCERS[spec.type]({ raw: spec.default, spec });
16
+ return coerced.ok ? coerced.value : undefined;
17
+ }
18
+ function invalid({ spec, raw }) {
19
+ const usedInstead = spec.secret ? undefined : spec.default;
20
+ return { name: spec.name, problem: 'invalid', received: echoEnvValue({ spec, raw }), expected: describeExpected({ spec }),
21
+ ...(usedInstead === undefined ? {} : { usedInstead }), fix: spec.doc.fix };
22
+ }
23
+ function readOne({ spec, env, byName }) {
24
+ const raw = env[spec.name];
25
+ if (spec.validation === 'owner')
26
+ return raw === undefined ? { value: undefined } : { value: raw, source: spec.name };
27
+ if (!isActive({ spec, env, byName }))
28
+ return { value: undefined };
29
+ if (!isSet({ value: raw }) || raw === undefined)
30
+ return { value: defaultValue({ spec }) };
31
+ const coerced = COERCERS[spec.type]({ raw, spec });
32
+ if (coerced.ok)
33
+ return { value: coerced.value, source: spec.name };
34
+ return { value: defaultValue({ spec }), issue: invalid({ spec, raw }) };
35
+ }
36
+ function editDistance({ a, b }) {
37
+ let row = Array.from({ length: b.length + 1 }, (_, index) => index);
38
+ for (let i = 1; i <= a.length; i++) {
39
+ const next = [i];
40
+ for (let j = 1; j <= b.length; j++)
41
+ next[j] = Math.min(row[j] + 1, next[j - 1] + 1, row[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
42
+ row = next;
43
+ }
44
+ return row[b.length];
45
+ }
46
+ /** The closest known name within two edits; ties go to the first in sorted order. */
47
+ function nearestName({ name, known }) {
48
+ const scored = known.map(candidate => ({ candidate, distance: editDistance({ a: name, b: candidate }) }))
49
+ .filter(({ distance }) => distance <= 2).sort((left, right) => left.distance - right.distance || left.candidate.localeCompare(right.candidate));
50
+ return scored[0]?.candidate;
51
+ }
52
+ /** O(e) over the map, plus one name comparison per known name for each unknown name found. */
53
+ function checkUnknownNames({ env, ownedPrefixes, known }) {
54
+ const names = new Set(known);
55
+ return Object.keys(env).sort()
56
+ .filter(name => isSet({ value: env[name] }) && !names.has(name) && ownedPrefixes.some(prefix => name.startsWith(prefix)))
57
+ .map((name) => {
58
+ const suggestion = nearestName({ name, known });
59
+ return { name, problem: 'unknown-name', received: echoEnvValue({ spec: undefined, raw: env[name] }), expected: 'a setting name this program knows',
60
+ ...(suggestion === undefined ? {} : { suggestion }), fix: suggestion === undefined ? 'check the spelling where you set it, or remove it' : 'rename it where you set it' };
61
+ });
62
+ }
63
+ function deepFreeze({ value }) {
64
+ if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
65
+ for (const child of Object.values(value))
66
+ deepFreeze({ value: child });
67
+ Object.freeze(value);
68
+ }
69
+ return value;
70
+ }
71
+ function assemble({ fields, unknown }) {
72
+ const config = {};
73
+ const sources = {};
74
+ const issues = [];
75
+ for (const { spec, result } of fields) {
76
+ config[spec.field] = result.value;
77
+ if (result.source !== undefined)
78
+ sources[spec.field] = result.source;
79
+ if (result.issue)
80
+ issues.push(result.issue);
81
+ }
82
+ // The host's schema type says which fields exist; this is the one place that shape is asserted.
83
+ return deepFreeze({ value: { config: config, sources, issues: [...issues, ...unknown] } });
84
+ }
85
+ /** Pure: no I/O, never logs, never throws on a bad value. Every issue is returned, not the first.
86
+ * @param required The host's schema and the map to read (the ambient environment, a child's
87
+ * launch map or a per-scope snapshot: the parser treats them alike).
88
+ * @param optional `declared`: names another list already owns (allow-lists, vendor names), so
89
+ * they are not reported as unknown.
90
+ * @returns A deep-frozen config, the variable that set each field, and every issue found.
91
+ * @complexity O(s + e) for s specs and e entries; each unknown name adds one pass over the names.
92
+ * @example parseEnv({ schema, env: hostEnv }).issues.map(issue => formatEnvIssue({ issue, product: 'Host' }));
93
+ */
94
+ export function parseEnv(required, optional = {}) {
95
+ const { schema, env } = required;
96
+ const specs = schema.specs;
97
+ const byName = new Map(specs.map(spec => [spec.name, spec]));
98
+ const fields = specs.filter(spec => (spec.delivery ?? 'env') === 'env').map(spec => ({ spec, result: readOne({ spec, env, byName }) }));
99
+ const known = [...specs, ...(optional.declared ?? [])].map(spec => spec.name);
100
+ return assemble({ fields, unknown: checkUnknownNames({ env, ownedPrefixes: schema.ownedPrefixes, known }) });
101
+ }
102
+ //# sourceMappingURL=parse-env.js.map
@@ -0,0 +1,17 @@
1
+ /** Shared disclosure policy for parser issues and environment diagnostics. */
2
+ import type { EnvValueEcho, EnvVarSpec } from '../contracts/env.js';
3
+ /** The one definition of "is it set". Never a truthiness check: `0`, `false` and `""` are real values. */
4
+ export declare function isSet({ value }: {
5
+ value: string | undefined;
6
+ }, _optional?: Record<string, never>): boolean;
7
+ /** Allow-list display: a value is shown only when its spec says it is not secret and may be shown.
8
+ * A name with no spec can therefore never leak a value. No I/O or input mutation.
9
+ * @param required The spec, if listed, and the raw environment value.
10
+ * @returns Presence or sanitized text; malformed URLs are hidden, never thrown.
11
+ * @complexity One value's URL parsing and existing lexical redaction; at most 121 output characters.
12
+ */
13
+ export declare function echoEnvValue({ spec, raw }: {
14
+ spec: EnvVarSpec | undefined;
15
+ raw: string | undefined;
16
+ }, _optional?: Record<string, never>): EnvValueEcho;
17
+ //# sourceMappingURL=value-echo.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { redactSecrets } from '../redact.js';
2
+ const SHOWN_LIMIT = 120;
3
+ /** The one definition of "is it set". Never a truthiness check: `0`, `false` and `""` are real values. */
4
+ export function isSet({ value }, _optional = {}) {
5
+ return value !== undefined && value.trim() !== '';
6
+ }
7
+ /** A URL setting can carry credentials although the setting itself is not a secret. */
8
+ function withoutCredentials({ raw }) {
9
+ if (!URL.canParse(raw.trim()))
10
+ return undefined;
11
+ const url = new URL(raw.trim());
12
+ url.username = '';
13
+ url.password = '';
14
+ url.search = '';
15
+ url.hash = '';
16
+ return url.toString();
17
+ }
18
+ /** Sanitize an allow-listed value, hiding malformed URLs and redacting before truncation.
19
+ * URL parsing and lexical redaction retain only bounded text; no I/O or input mutation.
20
+ */
21
+ function shownEcho({ spec, raw }) {
22
+ const text = spec.type === 'url' || spec.type === 'origin' ? withoutCredentials({ raw }) : raw;
23
+ if (text === undefined)
24
+ return { kind: 'hidden', length: raw.length };
25
+ // Redact before truncation so a partial credential cannot evade its shape rule.
26
+ const redacted = redactSecrets({ input: text }, { redactPii: false });
27
+ return { kind: 'shown', text: redacted.length > SHOWN_LIMIT ? `${redacted.slice(0, SHOWN_LIMIT)}…` : redacted };
28
+ }
29
+ /** Allow-list display: a value is shown only when its spec says it is not secret and may be shown.
30
+ * A name with no spec can therefore never leak a value. No I/O or input mutation.
31
+ * @param required The spec, if listed, and the raw environment value.
32
+ * @returns Presence or sanitized text; malformed URLs are hidden, never thrown.
33
+ * @complexity One value's URL parsing and existing lexical redaction; at most 121 output characters.
34
+ */
35
+ export function echoEnvValue({ spec, raw }, _optional = {}) {
36
+ if (!isSet({ value: raw }) || raw === undefined)
37
+ return { kind: 'unset' };
38
+ if (!spec || spec.secret || spec.display !== 'value')
39
+ return { kind: 'hidden', length: raw.length };
40
+ return shownEcho({ spec, raw });
41
+ }
42
+ //# sourceMappingURL=value-echo.js.map