@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,134 @@
1
+ /**
2
+ * @module element-handles
3
+ *
4
+ * The `data-agent-*` markup convention: how a page names the things an agent may act on.
5
+ *
6
+ * Handles are an **allowlist**, not a query language. A caller names a handle the page
7
+ * already published; it never supplies a selector. That is the whole security property —
8
+ * `resolveHandleSelector` can only ever build `[data-agent-element="<validated-handle>"]`,
9
+ * so there is no path from caller input to an arbitrary `querySelector`.
10
+ */
11
+ import type { FieldDescriptor } from './field-descriptor.js';
12
+ export declare const AGENT_ELEMENT_ATTRIBUTE = "data-agent-element";
13
+ export declare const AGENT_ROLE_ATTRIBUTE = "data-agent-role";
14
+ export declare const AGENT_LABEL_ATTRIBUTE = "data-agent-label";
15
+ export declare const AGENT_PAGE_ATTRIBUTE = "data-agent-page";
16
+ /**
17
+ * Marks a subtree the page driver must treat as absent: nothing inside it is published, adopted
18
+ * as a wrapper's control, or counted in any ancestor's text. For a secret the page shows a human
19
+ * (a revealed key), since a published ancestor's state otherwise reports its whole text content.
20
+ */
21
+ export declare const AGENT_PRIVATE_ATTRIBUTE = "data-agent-private";
22
+ /** What verb applies to a tagged element. Mirrors the convention documented in the sample markup. */
23
+ export type AgentElementRole = 'button' | 'checkbox' | 'field' | 'form' | 'list' | 'status' | 'region' | 'link';
24
+ export declare const AGENT_ELEMENT_ROLES: readonly AgentElementRole[];
25
+ /**
26
+ * Whether `handle` is a syntactically valid agent element handle.
27
+ *
28
+ * @param handle - Candidate handle, typically caller-supplied.
29
+ * @returns True when it is safe to interpolate into an attribute selector.
30
+ */
31
+ export declare function isValidElementHandle({ handle }: {
32
+ handle: string;
33
+ }, _optional?: Record<string, never>): boolean;
34
+ /**
35
+ * Builds the one selector shape this system will ever resolve.
36
+ *
37
+ * @param handle - A handle published by the page.
38
+ * @returns The attribute selector for that handle.
39
+ * @throws If the handle is not valid — never fall back to treating it as a raw selector.
40
+ */
41
+ export declare function resolveHandleSelector({ handle }: {
42
+ handle: string;
43
+ }, _optional?: Record<string, never>): string;
44
+ /** A tagged element as described back to a caller. `label` is page-authored, so it is untrusted. */
45
+ export interface AgentElementDescriptor {
46
+ readonly handle: string;
47
+ readonly role: AgentElementRole | undefined;
48
+ readonly label: string;
49
+ readonly labelTruncated: boolean;
50
+ readonly page: string | undefined;
51
+ }
52
+ /**
53
+ * What an element currently *is*, as opposed to what it is *for*.
54
+ *
55
+ * `label` answers "what is this control" and is stable page ontology — it stays `"Full name"`
56
+ * whether the box is empty or holds `"Ada Lovelace"`. That stability is the reason a caller can
57
+ * address the same element across a whole session, and the reason a driver must never overwrite a
58
+ * label with live text. But it leaves a caller unable to check its own work: after typing a name,
59
+ * after ticking a box, after navigating, the reply named the element and said nothing about
60
+ * whether anything had actually happened.
61
+ *
62
+ * This is the missing half — a separate channel, so observation is added rather than ontology
63
+ * traded away.
64
+ *
65
+ * `text` and any `value` are page-authored and therefore untrusted, exactly like `label`.
66
+ */
67
+ export interface AgentElementState {
68
+ /**
69
+ * Live text rendered inside the element, normalized and bounded. Empty for a bare input, and
70
+ * empty when withheld — see {@link AgentElementState.textWithheld}.
71
+ */
72
+ readonly text: string;
73
+ readonly textTruncated: boolean;
74
+ /**
75
+ * Why `text` is empty on an element that has some — so a caller reads "withheld", not "blank".
76
+ *
77
+ * Only ever set for an editable region (a `contenteditable`), whose text is the field's own
78
+ * contents rather than page-authored chrome. Every other element's text is what the page already
79
+ * renders openly to anyone looking at it.
80
+ */
81
+ readonly textWithheld?: string;
82
+ /** The field's current contents. Absent when the element is not a field, or when withheld. */
83
+ readonly value?: string;
84
+ readonly valueTruncated?: boolean;
85
+ /** Why `value` is absent on a field that has one — so a caller reads "withheld", not "empty". */
86
+ readonly valueWithheld?: string;
87
+ /** Checkbox/radio state. Absent when the element is neither. */
88
+ readonly checked?: boolean;
89
+ /** Disclosure state from aria-expanded or a native details element; absent for other controls. */
90
+ readonly expanded?: boolean;
91
+ readonly disabled?: boolean;
92
+ /** False when the element is present in the DOM but not rendered. */
93
+ readonly visible?: boolean;
94
+ /**
95
+ * A dropdown's available option texts — what `page.select_option` will accept. Absent for
96
+ * everything else. Reported even when the current `value` is withheld: which options exist is
97
+ * page-authored ontology, not the user's data.
98
+ */
99
+ readonly options?: readonly string[];
100
+ }
101
+ /**
102
+ * What a driver reports for one element, before policy runs.
103
+ *
104
+ * Drivers stay mechanical: this carries the raw `value` and the `field` descriptor, and the
105
+ * executor decides whether the value may be reported at all (see `findFieldReadRefusal`). Putting
106
+ * that decision in the driver would place a secrecy rule in the one layer this design says must
107
+ * not hold policy — and would have to be re-derived correctly by every future driver.
108
+ */
109
+ export interface AgentElementRawState {
110
+ /** Raw text content. The executor normalizes and bounds it. */
111
+ readonly text: string;
112
+ /**
113
+ * True when this element's `text` IS the field's contents rather than page-authored chrome —
114
+ * i.e. it is an editable region (`contenteditable`), which has no `value` of its own.
115
+ *
116
+ * A mechanical fact about the element, which is why a driver reports it: only the driver can
117
+ * tell. What follows from it is policy and stays in `projectElementState`, which gates such text
118
+ * with the same read guard it applies to `value`. Without this, a `<div contenteditable
119
+ * name="password">` had no `value` to withhold and handed the secret back as `text` instead.
120
+ */
121
+ readonly textIsValue?: boolean | undefined;
122
+ /** Raw field contents, reported unconditionally; the executor applies the read guard. */
123
+ readonly value?: string | undefined;
124
+ readonly checked?: boolean | undefined;
125
+ /** Raw disclosure state; the executor preserves it for action verification. */
126
+ readonly expanded?: boolean | undefined;
127
+ readonly disabled?: boolean | undefined;
128
+ readonly visible?: boolean | undefined;
129
+ /** Present when the element resolves to a field, so the executor can apply the read guard. */
130
+ readonly field?: FieldDescriptor | undefined;
131
+ /** A dropdown's option texts. Page-authored, so it is bounded but never withheld. */
132
+ readonly options?: readonly string[] | undefined;
133
+ }
134
+ //# sourceMappingURL=element-handles.d.ts.map
@@ -0,0 +1,45 @@
1
+ export const AGENT_ELEMENT_ATTRIBUTE = 'data-agent-element';
2
+ export const AGENT_ROLE_ATTRIBUTE = 'data-agent-role';
3
+ export const AGENT_LABEL_ATTRIBUTE = 'data-agent-label';
4
+ export const AGENT_PAGE_ATTRIBUTE = 'data-agent-page';
5
+ /**
6
+ * Marks a subtree the page driver must treat as absent: nothing inside it is published, adopted
7
+ * as a wrapper's control, or counted in any ancestor's text. For a secret the page shows a human
8
+ * (a revealed key), since a published ancestor's state otherwise reports its whole text content.
9
+ */
10
+ export const AGENT_PRIVATE_ATTRIBUTE = 'data-agent-private';
11
+ export const AGENT_ELEMENT_ROLES = [
12
+ 'button', 'checkbox', 'field', 'form', 'list', 'status', 'region', 'link',
13
+ ];
14
+ /**
15
+ * Lowercase, digits and single hyphens. Deliberately narrower than CSS allows: a handle that
16
+ * cannot contain a quote, bracket, backslash or whitespace cannot break out of the attribute
17
+ * selector it is interpolated into.
18
+ */
19
+ const HANDLE_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
20
+ /** Upper bound on a handle, so a hostile page cannot publish a megabyte-long name. */
21
+ const MAX_HANDLE_LENGTH = 128;
22
+ /**
23
+ * Whether `handle` is a syntactically valid agent element handle.
24
+ *
25
+ * @param handle - Candidate handle, typically caller-supplied.
26
+ * @returns True when it is safe to interpolate into an attribute selector.
27
+ */
28
+ export function isValidElementHandle({ handle }, _optional = {}) {
29
+ return handle.length > 0 && handle.length <= MAX_HANDLE_LENGTH && HANDLE_PATTERN.test(handle);
30
+ }
31
+ /**
32
+ * Builds the one selector shape this system will ever resolve.
33
+ *
34
+ * @param handle - A handle published by the page.
35
+ * @returns The attribute selector for that handle.
36
+ * @throws If the handle is not valid — never fall back to treating it as a raw selector.
37
+ */
38
+ export function resolveHandleSelector({ handle }, _optional = {}) {
39
+ if (!isValidElementHandle({ handle })) {
40
+ throw new Error(`invalid element handle "${handle.slice(0, MAX_HANDLE_LENGTH)}": `
41
+ + 'handles are lowercase words joined by single hyphens, and are never CSS selectors');
42
+ }
43
+ return `[${AGENT_ELEMENT_ATTRIBUTE}="${handle}"]`;
44
+ }
45
+ //# sourceMappingURL=element-handles.js.map
@@ -0,0 +1,28 @@
1
+ /** @file The input-field descriptor shared by the element-handle state and the agentic field guards. */
2
+ /** The subset of an input element these guards need. Framework- and DOM-free by design. */
3
+ export interface FieldDescriptor {
4
+ /** The `type` attribute, lowercased. */
5
+ readonly type?: string | undefined;
6
+ /** The `autocomplete` attribute, lowercased. */
7
+ readonly autocomplete?: string | undefined;
8
+ readonly name?: string | undefined;
9
+ readonly id?: string | undefined;
10
+ /**
11
+ * **Every** human-visible naming of the field the driver could resolve — `aria-label`,
12
+ * `placeholder`, and the text of each associated `<label>`.
13
+ *
14
+ * Carried because `name`/`id` are the *machine* names, and a form builder or CMS that emits
15
+ * `name="field_47"` leaves the guard nothing to judge while the page still plainly reads
16
+ * "Card number" to the user. A field whose sensitivity is stated only in its label was
17
+ * invisible to every refusal here until this existed.
18
+ *
19
+ * Plural, and required to be exhaustive, because the singular form this replaced took whichever
20
+ * source resolved *first*: a page could then mask a sensitive field behind a benign one —
21
+ * `<label for=f>Card number</label><input id=f name=field_47 placeholder="Enter value">` reached
22
+ * the guard as the single label "Enter value", and its value was reported back in full.
23
+ */
24
+ readonly accessibleLabels?: readonly string[] | undefined;
25
+ readonly readOnly?: boolean | undefined;
26
+ readonly disabled?: boolean | undefined;
27
+ }
28
+ //# sourceMappingURL=field-descriptor.d.ts.map
@@ -0,0 +1,3 @@
1
+ /** @file The input-field descriptor shared by the element-handle state and the agentic field guards. */
2
+ export {};
3
+ //# sourceMappingURL=field-descriptor.js.map
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @module handle
3
+ *
4
+ * `agentHandle({ handle: 'save' })` — the attribute props a component spreads onto its root element to
5
+ * publish itself under this package's `data-agent-*` markup convention (see
6
+ * `element-handles.ts`), without the caller having to know the attribute names or re-derive the
7
+ * handle-validity rule itself.
8
+ *
9
+ * Deliberately pure data, no DOM: this returns a plain object of string attributes, spreadable by
10
+ * React (`<button {...agentHandle({ handle: 'save' })}>`), Vue, Svelte, or any renderer that accepts arbitrary
11
+ * attribute props on an element. That is what lets it live in this package's universal root
12
+ * rather than `./dom` — nothing here touches `document` or any browser global.
13
+ */
14
+ import { AGENT_ELEMENT_ATTRIBUTE, AGENT_LABEL_ATTRIBUTE, AGENT_PAGE_ATTRIBUTE, AGENT_ROLE_ATTRIBUTE, type AgentElementRole } from './element-handles.js';
15
+ /** Optional markup to attach alongside the handle itself. */
16
+ export interface AgentHandleOptions {
17
+ /** What verb applies to this element — see {@link AgentElementRole}. */
18
+ readonly role?: AgentElementRole;
19
+ /** Stable, page-authored ontology for this element (e.g. `"Full name"`). Never live text. */
20
+ readonly label?: string;
21
+ /** Which published page this element belongs to, for a multi-page host. */
22
+ readonly page?: string;
23
+ }
24
+ /** The attribute props {@link agentHandle} returns, ready to spread onto an element. */
25
+ export type AgentHandleProps = {
26
+ readonly [AGENT_ELEMENT_ATTRIBUTE]: string;
27
+ } & Partial<Record<typeof AGENT_ROLE_ATTRIBUTE | typeof AGENT_LABEL_ATTRIBUTE | typeof AGENT_PAGE_ATTRIBUTE, string>>;
28
+ /**
29
+ * Builds the attribute props that publish `handle` as an agent-addressable element.
30
+ *
31
+ * @param handle - The handle to publish. Must satisfy {@link isValidElementHandle} — this
32
+ * function reuses that exact rule rather than a second, possibly-diverging check, since an
33
+ * adversarial probe already confirmed it rejects quotes, brackets, backslashes, unicode and
34
+ * overlong handles (see `element-handles.ts`).
35
+ * @param options - Optional role/label/page markup.
36
+ * @returns Attribute props to spread onto the element that should carry this handle.
37
+ * @throws If `handle` is not a valid element handle — never publishes a handle a caller (`page.*`
38
+ * capabilities, `resolveHandleSelector`) could not later resolve.
39
+ */
40
+ export declare function agentHandle({ handle }: {
41
+ handle: string;
42
+ }, options?: AgentHandleOptions): AgentHandleProps;
43
+ /**
44
+ * Derives a bounded handle segment from an opaque id without rewriting that id.
45
+ * Short valid ids keep their spelling; other ids use a stable 64-bit FNV-1a fingerprint
46
+ * of their UTF-16 code units. The `h-<16 hex digits>` namespace is reserved for fingerprints.
47
+ * Unlike list collision suffixes, this segment does not depend on filtering or row order.
48
+ * This is display identity, not a cryptographic or authorization primitive.
49
+ * @param required - The original id; arbitrary characters, empty and long strings are accepted.
50
+ * @returns A valid segment of at most 40 characters; callers reserve space for their fixed prefix.
51
+ * @complexity O(n) time in id characters, O(1) auxiliary space. No effects or errors.
52
+ */
53
+ export declare function agentHandleSegment({ value }: {
54
+ value: string;
55
+ }, _optional?: Record<string, never>): string;
56
+ /**
57
+ * The handle for one sub-element published under `base` — `<base>-<action>`.
58
+ *
59
+ * The one join rule every multi-control component under a single host-supplied base handle needs
60
+ * (a settings tab, a card, a form), extracted here so each such component imports it rather than
61
+ * re-deriving the same template literal. First established as `sourceConfigActionHandle` in
62
+ * `../../features/source-config-list/agent-handles.ts` before this package had a generic version —
63
+ * that feature's own doc comment explains the naming split this generalizes ("a host names a
64
+ * component; the component names its own parts").
65
+ *
66
+ * @param base - The component's own handle, as published by the host. Must already be a valid
67
+ * element handle — callers own that, same as every other `agentHandle()` base.
68
+ * @param action - The sub-element's name. Always a literal chosen by the component, never host data.
69
+ * @returns `<base>-<action>`.
70
+ * @complexity O(1).
71
+ */
72
+ export declare function agentSubHandle({ base, action }: {
73
+ base: string;
74
+ action: string;
75
+ }, _optional?: Record<string, never>): string;
76
+ /** What to publish about one sub-element — see {@link agentHandleProps}. */
77
+ export interface AgentHandlePropsOptions extends AgentHandleOptions {
78
+ /** Host-published base handle. Omit to leave the element unpublished. */
79
+ readonly base?: string | undefined;
80
+ /**
81
+ * The sub-element's name, appended to `base` via {@link agentSubHandle}. Omit when the element
82
+ * IS `base` — the component's own root.
83
+ */
84
+ readonly action?: string;
85
+ }
86
+ /**
87
+ * Builds the `data-agent-*` attribute props for one element of a component that takes a single
88
+ * OPTIONAL base handle from its host, or nothing at all when the host published no base.
89
+ *
90
+ * This is the seam a component with more than one agent-addressable element should use: the host
91
+ * hands the component ONE base handle (`agentHandle?: string` in that component's own props, named
92
+ * identically to this function's own `handle.ts` sibling so a caller cannot mistake which handle a
93
+ * component wants), and the component derives every sub-element's handle from it via `action`,
94
+ * exactly the "host names a component, the component names its own parts" split
95
+ * `source-config-list/agent-handles.ts` established first. Returning `{}` rather than throwing on
96
+ * an `undefined` base is what keeps the host prop opt-in: a host that never passes `agentHandle`
97
+ * renders exactly the markup it did before this existed — additive, never a behavior change.
98
+ *
99
+ * @param base - The component's own handle from the host, or `undefined` when it published none.
100
+ * @param options - Role, stable label, optional page, and the optional `action` naming this
101
+ * sub-element (see {@link AgentHandlePropsOptions}).
102
+ * @returns Spreadable attribute props, or `{}` when `base` is `undefined`.
103
+ * @throws If `base` is defined but not a valid element handle — via `agentHandle()`, deliberately
104
+ * unguarded so a bad host-supplied base fails loudly at first render rather than silently
105
+ * answering to a handle the host never wrote.
106
+ * @complexity O(1).
107
+ */
108
+ export declare function agentHandleProps(_required: Record<string, never>, options?: AgentHandlePropsOptions): AgentHandleProps | Record<string, never>;
109
+ //# sourceMappingURL=handle.d.ts.map
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @module handle
3
+ *
4
+ * `agentHandle({ handle: 'save' })` — the attribute props a component spreads onto its root element to
5
+ * publish itself under this package's `data-agent-*` markup convention (see
6
+ * `element-handles.ts`), without the caller having to know the attribute names or re-derive the
7
+ * handle-validity rule itself.
8
+ *
9
+ * Deliberately pure data, no DOM: this returns a plain object of string attributes, spreadable by
10
+ * React (`<button {...agentHandle({ handle: 'save' })}>`), Vue, Svelte, or any renderer that accepts arbitrary
11
+ * attribute props on an element. That is what lets it live in this package's universal root
12
+ * rather than `./dom` — nothing here touches `document` or any browser global.
13
+ */
14
+ import { AGENT_ELEMENT_ATTRIBUTE, AGENT_LABEL_ATTRIBUTE, AGENT_PAGE_ATTRIBUTE, AGENT_ROLE_ATTRIBUTE, isValidElementHandle, } from './element-handles.js';
15
+ import { omitKeys } from '../records.js';
16
+ /**
17
+ * Builds the attribute props that publish `handle` as an agent-addressable element.
18
+ *
19
+ * @param handle - The handle to publish. Must satisfy {@link isValidElementHandle} — this
20
+ * function reuses that exact rule rather than a second, possibly-diverging check, since an
21
+ * adversarial probe already confirmed it rejects quotes, brackets, backslashes, unicode and
22
+ * overlong handles (see `element-handles.ts`).
23
+ * @param options - Optional role/label/page markup.
24
+ * @returns Attribute props to spread onto the element that should carry this handle.
25
+ * @throws If `handle` is not a valid element handle — never publishes a handle a caller (`page.*`
26
+ * capabilities, `resolveHandleSelector`) could not later resolve.
27
+ */
28
+ export function agentHandle({ handle }, options = {}) {
29
+ if (!isValidElementHandle({ handle })) {
30
+ throw new Error(`invalid element handle "${handle.slice(0, 128)}": `
31
+ + 'handles are lowercase words joined by single hyphens, and are never CSS selectors');
32
+ }
33
+ const props = { [AGENT_ELEMENT_ATTRIBUTE]: handle };
34
+ if (options.role !== undefined)
35
+ props[AGENT_ROLE_ATTRIBUTE] = options.role;
36
+ if (options.label !== undefined)
37
+ props[AGENT_LABEL_ATTRIBUTE] = options.label;
38
+ if (options.page !== undefined)
39
+ props[AGENT_PAGE_ATTRIBUTE] = options.page;
40
+ return props;
41
+ }
42
+ /**
43
+ * Derives a bounded handle segment from an opaque id without rewriting that id.
44
+ * Short valid ids keep their spelling; other ids use a stable 64-bit FNV-1a fingerprint
45
+ * of their UTF-16 code units. The `h-<16 hex digits>` namespace is reserved for fingerprints.
46
+ * Unlike list collision suffixes, this segment does not depend on filtering or row order.
47
+ * This is display identity, not a cryptographic or authorization primitive.
48
+ * @param required - The original id; arbitrary characters, empty and long strings are accepted.
49
+ * @returns A valid segment of at most 40 characters; callers reserve space for their fixed prefix.
50
+ * @complexity O(n) time in id characters, O(1) auxiliary space. No effects or errors.
51
+ */
52
+ export function agentHandleSegment({ value }, _optional = {}) {
53
+ if (value.length <= 40 && isValidElementHandle({ handle: value }) && !/^h-[0-9a-f]{16}$/.test(value))
54
+ return value;
55
+ let hash = 0xcbf29ce484222325n;
56
+ for (let index = 0; index < value.length; index += 1) {
57
+ hash = BigInt.asUintN(64, (hash ^ BigInt(value.charCodeAt(index))) * 0x100000001b3n);
58
+ }
59
+ return `h-${hash.toString(16).padStart(16, '0')}`;
60
+ }
61
+ /**
62
+ * The handle for one sub-element published under `base` — `<base>-<action>`.
63
+ *
64
+ * The one join rule every multi-control component under a single host-supplied base handle needs
65
+ * (a settings tab, a card, a form), extracted here so each such component imports it rather than
66
+ * re-deriving the same template literal. First established as `sourceConfigActionHandle` in
67
+ * `../../features/source-config-list/agent-handles.ts` before this package had a generic version —
68
+ * that feature's own doc comment explains the naming split this generalizes ("a host names a
69
+ * component; the component names its own parts").
70
+ *
71
+ * @param base - The component's own handle, as published by the host. Must already be a valid
72
+ * element handle — callers own that, same as every other `agentHandle()` base.
73
+ * @param action - The sub-element's name. Always a literal chosen by the component, never host data.
74
+ * @returns `<base>-<action>`.
75
+ * @complexity O(1).
76
+ */
77
+ export function agentSubHandle({ base, action }, _optional = {}) {
78
+ return `${base}-${action}`;
79
+ }
80
+ /**
81
+ * Builds the `data-agent-*` attribute props for one element of a component that takes a single
82
+ * OPTIONAL base handle from its host, or nothing at all when the host published no base.
83
+ *
84
+ * This is the seam a component with more than one agent-addressable element should use: the host
85
+ * hands the component ONE base handle (`agentHandle?: string` in that component's own props, named
86
+ * identically to this function's own `handle.ts` sibling so a caller cannot mistake which handle a
87
+ * component wants), and the component derives every sub-element's handle from it via `action`,
88
+ * exactly the "host names a component, the component names its own parts" split
89
+ * `source-config-list/agent-handles.ts` established first. Returning `{}` rather than throwing on
90
+ * an `undefined` base is what keeps the host prop opt-in: a host that never passes `agentHandle`
91
+ * renders exactly the markup it did before this existed — additive, never a behavior change.
92
+ *
93
+ * @param base - The component's own handle from the host, or `undefined` when it published none.
94
+ * @param options - Role, stable label, optional page, and the optional `action` naming this
95
+ * sub-element (see {@link AgentHandlePropsOptions}).
96
+ * @returns Spreadable attribute props, or `{}` when `base` is `undefined`.
97
+ * @throws If `base` is defined but not a valid element handle — via `agentHandle()`, deliberately
98
+ * unguarded so a bad host-supplied base fails loudly at first render rather than silently
99
+ * answering to a handle the host never wrote.
100
+ * @complexity O(1).
101
+ */
102
+ export function agentHandleProps(_required, options = {}) {
103
+ const { base } = options;
104
+ if (base === undefined)
105
+ return {};
106
+ const { action, ...rest } = omitKeys({ source: options, keys: ['base'] });
107
+ return agentHandle({ handle: action === undefined ? base : agentSubHandle({ base, action }) }, rest);
108
+ }
109
+ //# sourceMappingURL=handle.js.map
@@ -0,0 +1,9 @@
1
+ /** @file Agent handles: the `data-agent-*` markup convention and the handle grammar. Pure data, no DOM. */
2
+ export { agentHandle, agentHandleSegment, agentSubHandle, agentHandleProps } from './handle.js';
3
+ export type { AgentHandleOptions, AgentHandleProps, AgentHandlePropsOptions } from './handle.js';
4
+ export { buildAgentListHandles } from './list-handles.js';
5
+ export { AGENT_ELEMENT_ATTRIBUTE, AGENT_ROLE_ATTRIBUTE, AGENT_LABEL_ATTRIBUTE, AGENT_PAGE_ATTRIBUTE, AGENT_PRIVATE_ATTRIBUTE, AGENT_ELEMENT_ROLES, isValidElementHandle, resolveHandleSelector } from './element-handles.js';
6
+ export type { AgentElementRole, AgentElementDescriptor, AgentElementState, AgentElementRawState } from './element-handles.js';
7
+ export type { FieldDescriptor } from './field-descriptor.js';
8
+ export { secretControlAttrs } from './secret-attrs.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,6 @@
1
+ /** @file Agent handles: the `data-agent-*` markup convention and the handle grammar. Pure data, no DOM. */
2
+ export { agentHandle, agentHandleSegment, agentSubHandle, agentHandleProps } from './handle.js';
3
+ export { buildAgentListHandles } from './list-handles.js';
4
+ export { AGENT_ELEMENT_ATTRIBUTE, AGENT_ROLE_ATTRIBUTE, AGENT_LABEL_ATTRIBUTE, AGENT_PAGE_ATTRIBUTE, AGENT_PRIVATE_ATTRIBUTE, AGENT_ELEMENT_ROLES, isValidElementHandle, resolveHandleSelector } from './element-handles.js';
5
+ export { secretControlAttrs } from './secret-attrs.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @module list-handles
3
+ *
4
+ * How a host turns one namespace prefix (its own `agentHandle` base, e.g. `"mcp-server"`) plus a
5
+ * list of items' own stable ids into a distinct, stable base handle per item — the shape every
6
+ * repeated-row/repeated-card list needs, and that a per-host reimplementation risks getting
7
+ * subtly wrong (see {@link buildAgentListHandles}'s own doc for the exact failure mode).
8
+ *
9
+ * The core problem: a `data-agent-element` handle is `[a-z0-9]+(-[a-z0-9]+)*` only (see
10
+ * `element-handles.ts`), but the ids driving a real list (a form field's `id`, a content type's
11
+ * `key`, a database row's numeric id, a configured source's own id, ...) are arbitrary strings.
12
+ * Two different ids can also slugify to the SAME handle. Both are resolved here, once, so every
13
+ * list surface in every host derives its handles the same way instead of each re-deriving (and
14
+ * possibly getting wrong) the same two rules. Lives at this package's universal root — like
15
+ * `handle.ts` and `element-handles.ts` — because it is pure data with no DOM or framework
16
+ * involved, so any host (React, Vue, a server-rendered list) can use it identically.
17
+ */
18
+ /**
19
+ * Builds one distinct, stable base handle per id, positionally aligned with `ids`.
20
+ *
21
+ * Handles are derived from each id's own slug, not its position in the list — an agent reading
22
+ * `page.find_elements` should see `<prefix>-about-us`, not `<prefix>-3`, so the same control keeps
23
+ * the same handle even if rows are later reordered or filtered. An id with nothing sluggable left
24
+ * in it (e.g. `"***"`) falls back to its 1-based position instead, so it still produces a
25
+ * resolvable handle rather than an empty one.
26
+ *
27
+ * Uniqueness is enforced with a suffix SEARCH, not a single `-<index>` append: appending the index
28
+ * alone is not collision-proof (`["x", "x-3", "x"]` would give the third entry the fallback
29
+ * `<prefix>-x-3`, which the second entry already holds). A duplicate handle does not fail loudly —
30
+ * it makes `page.click`/`page.fill` silently resolve to whichever element the DOM reaches first —
31
+ * so this loop is the load-bearing part of the function, not a stylistic choice.
32
+ *
33
+ * @param prefix - The list's own handle namespace (e.g. `"mcp-server"`, `"form-field"`). Must
34
+ * already be a valid, non-empty handle segment — callers own that, same as every other
35
+ * `agentHandle()` base.
36
+ * @param ids - The list items' own stable ids, in the order they are rendered.
37
+ * @returns One base handle per id, positionally aligned with `ids`, all distinct.
38
+ * @complexity Time O(n) typical, O(n²) worst case when every id slugifies identically (the suffix
39
+ * search then walks the full used-set for each collision); n is a list's row/card count, which is
40
+ * operator- or user-authored content and stays small in practice. Space O(n).
41
+ */
42
+ export declare function buildAgentListHandles({ prefix, ids }: {
43
+ prefix: string;
44
+ ids: readonly string[];
45
+ }, _optional?: Record<string, never>): string[];
46
+ //# sourceMappingURL=list-handles.d.ts.map
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @module list-handles
3
+ *
4
+ * How a host turns one namespace prefix (its own `agentHandle` base, e.g. `"mcp-server"`) plus a
5
+ * list of items' own stable ids into a distinct, stable base handle per item — the shape every
6
+ * repeated-row/repeated-card list needs, and that a per-host reimplementation risks getting
7
+ * subtly wrong (see {@link buildAgentListHandles}'s own doc for the exact failure mode).
8
+ *
9
+ * The core problem: a `data-agent-element` handle is `[a-z0-9]+(-[a-z0-9]+)*` only (see
10
+ * `element-handles.ts`), but the ids driving a real list (a form field's `id`, a content type's
11
+ * `key`, a database row's numeric id, a configured source's own id, ...) are arbitrary strings.
12
+ * Two different ids can also slugify to the SAME handle. Both are resolved here, once, so every
13
+ * list surface in every host derives its handles the same way instead of each re-deriving (and
14
+ * possibly getting wrong) the same two rules. Lives at this package's universal root — like
15
+ * `handle.ts` and `element-handles.ts` — because it is pure data with no DOM or framework
16
+ * involved, so any host (React, Vue, a server-rendered list) can use it identically.
17
+ */
18
+ /** Strips leading and trailing `-` in one linear pass (the `/^-+|-+$/g` spelling backtracks). */
19
+ function trimDashes(text) {
20
+ let start = 0;
21
+ let end = text.length;
22
+ while (start < end && text[start] === '-')
23
+ start += 1;
24
+ while (end > start && text[end - 1] === '-')
25
+ end -= 1;
26
+ return text.slice(start, end);
27
+ }
28
+ /**
29
+ * Builds one distinct, stable base handle per id, positionally aligned with `ids`.
30
+ *
31
+ * Handles are derived from each id's own slug, not its position in the list — an agent reading
32
+ * `page.find_elements` should see `<prefix>-about-us`, not `<prefix>-3`, so the same control keeps
33
+ * the same handle even if rows are later reordered or filtered. An id with nothing sluggable left
34
+ * in it (e.g. `"***"`) falls back to its 1-based position instead, so it still produces a
35
+ * resolvable handle rather than an empty one.
36
+ *
37
+ * Uniqueness is enforced with a suffix SEARCH, not a single `-<index>` append: appending the index
38
+ * alone is not collision-proof (`["x", "x-3", "x"]` would give the third entry the fallback
39
+ * `<prefix>-x-3`, which the second entry already holds). A duplicate handle does not fail loudly —
40
+ * it makes `page.click`/`page.fill` silently resolve to whichever element the DOM reaches first —
41
+ * so this loop is the load-bearing part of the function, not a stylistic choice.
42
+ *
43
+ * @param prefix - The list's own handle namespace (e.g. `"mcp-server"`, `"form-field"`). Must
44
+ * already be a valid, non-empty handle segment — callers own that, same as every other
45
+ * `agentHandle()` base.
46
+ * @param ids - The list items' own stable ids, in the order they are rendered.
47
+ * @returns One base handle per id, positionally aligned with `ids`, all distinct.
48
+ * @complexity Time O(n) typical, O(n²) worst case when every id slugifies identically (the suffix
49
+ * search then walks the full used-set for each collision); n is a list's row/card count, which is
50
+ * operator- or user-authored content and stays small in practice. Space O(n).
51
+ */
52
+ export function buildAgentListHandles({ prefix, ids }, _optional = {}) {
53
+ const used = new Set();
54
+ return ids.map((id, index) => {
55
+ const slug = trimDashes(id.toLowerCase().replace(/[^a-z0-9]+/g, '-'));
56
+ const preferred = `${prefix}-${slug === '' ? index + 1 : slug}`;
57
+ let handle = preferred;
58
+ let suffix = 2;
59
+ while (used.has(handle)) {
60
+ handle = `${preferred}-${suffix}`;
61
+ suffix += 1;
62
+ }
63
+ used.add(handle);
64
+ return handle;
65
+ });
66
+ }
67
+ //# sourceMappingURL=list-handles.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Keeps ordinary control props while excluding agent addressing from a semantic secret, including
3
+ * after reveal changes its native input type. Caller metadata cannot override the private marker.
4
+ * @param required.attrs - Input or reveal-control props; never mutated.
5
+ * @returns A fresh props object with only the enforced agent privacy marker.
6
+ * @complexity O(n) time and space in the number of supplied props; no I/O or effects.
7
+ * @overallScore 100
8
+ */
9
+ export declare function secretControlAttrs<T extends object>({ attrs }: {
10
+ attrs: T;
11
+ }): Omit<T, `data-agent-${string}`> & {
12
+ 'data-agent-private': '';
13
+ };
14
+ //# sourceMappingURL=secret-attrs.d.ts.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Keeps ordinary control props while excluding agent addressing from a semantic secret, including
3
+ * after reveal changes its native input type. Caller metadata cannot override the private marker.
4
+ * @param required.attrs - Input or reveal-control props; never mutated.
5
+ * @returns A fresh props object with only the enforced agent privacy marker.
6
+ * @complexity O(n) time and space in the number of supplied props; no I/O or effects.
7
+ * @overallScore 100
8
+ */
9
+ export function secretControlAttrs({ attrs }) {
10
+ const ordinary = Object.entries(attrs).filter(([name]) => !name.toLowerCase().startsWith('data-agent-'));
11
+ return { ...Object.fromEntries(ordinary), 'data-agent-private': '' };
12
+ }
13
+ //# sourceMappingURL=secret-attrs.js.map
@@ -0,0 +1,45 @@
1
+ import { type ApprovalSteps } from './approval.js';
2
+ import type { ToolExecutionContext, ToolExecutionOptions, ToolHandler } from './tool-registry.js';
3
+ /** Prepares one item and takes whatever pin the host needs to refuse a stale change. */
4
+ export type PrepareStep<TPrepared> = ApprovalSteps<TPrepared, undefined>['prepare'];
5
+ /** What a host supplies to chain batch items that write the same target.
6
+ * - `run` applies one prepared item and reports `committed`, the version that write itself produced
7
+ * (`undefined` when it wrote nothing, for example a byte-identical write).
8
+ * - `targetKey` names the target an item writes; items with the same key chain, others never do.
9
+ * - `successor` pins the next item for a key to what the previous write committed. It is synchronous
10
+ * and must not do I/O: a read here would adopt whatever a foreign writer left behind as the baseline,
11
+ * so the only trusted value is the one the batch's own write reported. */
12
+ export interface ChainedBatchSteps<TPrepared, TCommitted> {
13
+ prepare: PrepareStep<TPrepared>;
14
+ run(required: {
15
+ ctx: ToolExecutionContext;
16
+ prepared: TPrepared;
17
+ }, optional?: ToolExecutionOptions): Promise<{
18
+ output: unknown;
19
+ committed: TCommitted | undefined;
20
+ }>;
21
+ targetKey(required: {
22
+ prepared: TPrepared;
23
+ }): string;
24
+ successor(required: {
25
+ prepared: TPrepared;
26
+ committed: TCommitted | undefined;
27
+ previous: TPrepared;
28
+ }): TPrepared;
29
+ }
30
+ /** A direct (never asking) batch whose items for the same target apply in order, each pinned to the
31
+ * version the batch's own previous write committed. Reuses the approval owner's input snapshot, item
32
+ * cap, duplicate detection and cancellation checks. A single call returns `run`'s output unchanged;
33
+ * a batch returns `{ batch: true, total, results }` so `batchOutcomeFor` reports partial failures.
34
+ * `createBatchApprovalHandler` is untouched: a person approved a description computed from the first bytes.
35
+ * @param optional.targetNoun What the target is called in the "Skipped" sentence. Default `target`.
36
+ * @throws ToolInputError for malformed, duplicate or over-cap batches and for cancellation; `prepare`
37
+ * failures propagate; a single call's `run` failure propagates; a batch item's failure is its result.
38
+ * @complexity O(input bytes) plus bounded host effects; no reads by core.
39
+ * @example createChainedBatchHandler({ prepare, run, targetKey, successor }, { targetNoun: 'file' });
40
+ */
41
+ export declare function createChainedBatchHandler<TPrepared, TCommitted>(required: ChainedBatchSteps<TPrepared, TCommitted>, { maxItems, targetNoun }?: {
42
+ maxItems?: number;
43
+ targetNoun?: string;
44
+ }): ToolHandler;
45
+ //# sourceMappingURL=approval-batch-chain.d.ts.map