@scotthuang/agent-knock-knock 0.13.2 → 0.13.4

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 (278) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +27 -6
  3. package/dist/src/callback-outbox-policy.js +27 -6
  4. package/dist/src/callback-outbox-policy.js.map +1 -1
  5. package/dist/src/callback-outbox-service.d.ts +4 -30
  6. package/dist/src/callback-outbox-service.js +21 -154
  7. package/dist/src/callback-outbox-service.js.map +1 -1
  8. package/dist/src/callback-outbox-settlement.js +13 -8
  9. package/dist/src/callback-outbox-settlement.js.map +1 -1
  10. package/dist/src/callback-route-service.d.ts +46 -0
  11. package/dist/src/callback-route-service.js +155 -0
  12. package/dist/src/callback-route-service.js.map +1 -0
  13. package/dist/src/claude-terminal-agent-adapter.js +4 -0
  14. package/dist/src/claude-terminal-agent-adapter.js.map +1 -1
  15. package/dist/src/cli-core.js +9 -1
  16. package/dist/src/cli-core.js.map +1 -1
  17. package/dist/src/codex-process-incarnation.d.ts +8 -0
  18. package/dist/src/codex-process-incarnation.js +36 -0
  19. package/dist/src/codex-process-incarnation.js.map +1 -0
  20. package/dist/src/codex-terminal-agent-adapter.js +4 -0
  21. package/dist/src/codex-terminal-agent-adapter.js.map +1 -1
  22. package/dist/src/deferred-foreground-conflict-policy.d.ts +22 -0
  23. package/dist/src/deferred-foreground-conflict-policy.js +52 -0
  24. package/dist/src/deferred-foreground-conflict-policy.js.map +1 -0
  25. package/dist/src/durable-notification-kernel.d.ts +94 -0
  26. package/dist/src/durable-notification-kernel.js +68 -0
  27. package/dist/src/durable-notification-kernel.js.map +1 -0
  28. package/dist/src/herdr-socket-transport.d.ts +43 -0
  29. package/dist/src/herdr-socket-transport.js +170 -0
  30. package/dist/src/herdr-socket-transport.js.map +1 -0
  31. package/dist/src/herdr-terminal-control-provider.d.ts +2 -45
  32. package/dist/src/herdr-terminal-control-provider.js +8 -173
  33. package/dist/src/herdr-terminal-control-provider.js.map +1 -1
  34. package/dist/src/host-adapter-capabilities.d.ts +35 -0
  35. package/dist/src/host-adapter-capabilities.js +146 -0
  36. package/dist/src/host-adapter-capabilities.js.map +1 -0
  37. package/dist/src/host-adapter.d.ts +9 -3
  38. package/dist/src/host-adapter.js +33 -9
  39. package/dist/src/host-adapter.js.map +1 -1
  40. package/dist/src/host-bridge-tools.d.ts +3 -4
  41. package/dist/src/host-bridge-tools.js +49 -92
  42. package/dist/src/host-bridge-tools.js.map +1 -1
  43. package/dist/src/host-bridge.js +5 -5
  44. package/dist/src/host-bridge.js.map +1 -1
  45. package/dist/src/host-monitor-reconciliation.d.ts +6 -0
  46. package/dist/src/host-monitor-reconciliation.js +96 -0
  47. package/dist/src/host-monitor-reconciliation.js.map +1 -0
  48. package/dist/src/managed-session.js +2 -18
  49. package/dist/src/managed-session.js.map +1 -1
  50. package/dist/src/native-thread-lifecycle-cli-adapter.d.ts +13 -0
  51. package/dist/src/native-thread-lifecycle-cli-adapter.js +635 -3
  52. package/dist/src/native-thread-lifecycle-cli-adapter.js.map +1 -1
  53. package/dist/src/openclaw-list-projection.d.ts +2 -0
  54. package/dist/src/openclaw-list-projection.js +3 -0
  55. package/dist/src/openclaw-list-projection.js.map +1 -0
  56. package/dist/src/openclaw-model-facing-field-policy.d.ts +2 -0
  57. package/dist/src/openclaw-model-facing-field-policy.js +3 -0
  58. package/dist/src/openclaw-model-facing-field-policy.js.map +1 -0
  59. package/dist/src/openclaw-plugin-command-adapter.d.ts +6 -29
  60. package/dist/src/openclaw-plugin-command-adapter.js +7 -2370
  61. package/dist/src/openclaw-plugin-command-adapter.js.map +1 -1
  62. package/dist/src/openclaw-plugin-helpers.d.ts +2 -121
  63. package/dist/src/openclaw-plugin-helpers.js +2 -1164
  64. package/dist/src/openclaw-plugin-helpers.js.map +1 -1
  65. package/dist/src/openclaw-plugin-schemas.d.ts +2 -510
  66. package/dist/src/openclaw-plugin-schemas.js +2 -519
  67. package/dist/src/openclaw-plugin-schemas.js.map +1 -1
  68. package/dist/src/openclaw-plugin-supervisor.d.ts +4 -5
  69. package/dist/src/openclaw-plugin-supervisor.js +5 -94
  70. package/dist/src/openclaw-plugin-supervisor.js.map +1 -1
  71. package/dist/src/openclaw-plugin-value-helpers.d.ts +2 -0
  72. package/dist/src/openclaw-plugin-value-helpers.js +3 -0
  73. package/dist/src/openclaw-plugin-value-helpers.js.map +1 -0
  74. package/dist/src/openclaw-private-authority-offers.d.ts +4 -39
  75. package/dist/src/openclaw-private-authority-offers.js +3 -258
  76. package/dist/src/openclaw-private-authority-offers.js.map +1 -1
  77. package/dist/src/semantic-private-authority-offers.d.ts +41 -0
  78. package/dist/src/semantic-private-authority-offers.js +261 -0
  79. package/dist/src/semantic-private-authority-offers.js.map +1 -0
  80. package/dist/src/semantic-tool-arguments.d.ts +9 -0
  81. package/dist/src/semantic-tool-arguments.js +64 -0
  82. package/dist/src/semantic-tool-arguments.js.map +1 -0
  83. package/dist/src/semantic-tool-catalog.d.ts +48 -0
  84. package/dist/src/semantic-tool-catalog.js +105 -0
  85. package/dist/src/semantic-tool-catalog.js.map +1 -0
  86. package/dist/src/semantic-tool-command-helpers.d.ts +145 -0
  87. package/dist/src/semantic-tool-command-helpers.js +1272 -0
  88. package/dist/src/semantic-tool-command-helpers.js.map +1 -0
  89. package/dist/src/semantic-tool-list-projection.d.ts +10 -0
  90. package/dist/src/semantic-tool-list-projection.js +497 -0
  91. package/dist/src/semantic-tool-list-projection.js.map +1 -0
  92. package/dist/src/semantic-tool-model-facing-field-policy.d.ts +3 -0
  93. package/dist/src/semantic-tool-model-facing-field-policy.js +66 -0
  94. package/dist/src/semantic-tool-model-facing-field-policy.js.map +1 -0
  95. package/dist/src/semantic-tool-presentation.d.ts +37 -0
  96. package/dist/src/semantic-tool-presentation.js +680 -0
  97. package/dist/src/semantic-tool-presentation.js.map +1 -0
  98. package/dist/src/semantic-tool-private-authority.d.ts +39 -0
  99. package/dist/src/semantic-tool-private-authority.js +602 -0
  100. package/dist/src/semantic-tool-private-authority.js.map +1 -0
  101. package/dist/src/semantic-tool-relay.d.ts +16 -0
  102. package/dist/src/semantic-tool-relay.js +175 -0
  103. package/dist/src/semantic-tool-relay.js.map +1 -0
  104. package/dist/src/semantic-tool-runtime.d.ts +10 -0
  105. package/dist/src/semantic-tool-runtime.js +1157 -0
  106. package/dist/src/semantic-tool-runtime.js.map +1 -0
  107. package/dist/src/semantic-tool-schemas.d.ts +563 -0
  108. package/dist/src/semantic-tool-schemas.js +573 -0
  109. package/dist/src/semantic-tool-schemas.js.map +1 -0
  110. package/dist/src/semantic-tool-value-helpers.d.ts +5 -0
  111. package/dist/src/semantic-tool-value-helpers.js +27 -0
  112. package/dist/src/semantic-tool-value-helpers.js.map +1 -0
  113. package/dist/src/store-event-presentation.d.ts +17 -0
  114. package/dist/src/store-event-presentation.js +33 -0
  115. package/dist/src/store-event-presentation.js.map +1 -0
  116. package/dist/src/store.d.ts +3 -16
  117. package/dist/src/store.js +2 -30
  118. package/dist/src/store.js.map +1 -1
  119. package/dist/src/terminal-action-projection.d.ts +3 -17
  120. package/dist/src/terminal-action-projection.js +13 -41
  121. package/dist/src/terminal-action-projection.js.map +1 -1
  122. package/dist/src/terminal-agent-adapter.d.ts +7 -0
  123. package/dist/src/terminal-agent-adapter.js +8 -0
  124. package/dist/src/terminal-agent-adapter.js.map +1 -1
  125. package/dist/src/terminal-agent-bridge.d.ts +35 -332
  126. package/dist/src/terminal-agent-bridge.js +293 -2798
  127. package/dist/src/terminal-agent-bridge.js.map +1 -1
  128. package/dist/src/terminal-approval-cli-adapter.d.ts +17 -0
  129. package/dist/src/terminal-approval-cli-adapter.js +921 -0
  130. package/dist/src/terminal-approval-cli-adapter.js.map +1 -0
  131. package/dist/src/terminal-command-cli-adapter.d.ts +2 -429
  132. package/dist/src/terminal-command-cli-adapter.js +344 -6061
  133. package/dist/src/terminal-command-cli-adapter.js.map +1 -1
  134. package/dist/src/terminal-command-cli-ports.d.ts +443 -0
  135. package/dist/src/terminal-command-cli-ports.js +2 -0
  136. package/dist/src/terminal-command-cli-ports.js.map +1 -0
  137. package/dist/src/terminal-command-dispatch-preparation.d.ts +81 -0
  138. package/dist/src/terminal-command-dispatch-preparation.js +209 -0
  139. package/dist/src/terminal-command-dispatch-preparation.js.map +1 -0
  140. package/dist/src/terminal-command-dispatch-transport.d.ts +35 -0
  141. package/dist/src/terminal-command-dispatch-transport.js +859 -0
  142. package/dist/src/terminal-command-dispatch-transport.js.map +1 -0
  143. package/dist/src/terminal-command-foreground-proof.d.ts +32 -0
  144. package/dist/src/terminal-command-foreground-proof.js +72 -0
  145. package/dist/src/terminal-command-foreground-proof.js.map +1 -0
  146. package/dist/src/terminal-command-send-preflight.d.ts +41 -0
  147. package/dist/src/terminal-command-send-preflight.js +86 -0
  148. package/dist/src/terminal-command-send-preflight.js.map +1 -0
  149. package/dist/src/terminal-composer-classifier.d.ts +55 -0
  150. package/dist/src/terminal-composer-classifier.js +638 -0
  151. package/dist/src/terminal-composer-classifier.js.map +1 -0
  152. package/dist/src/terminal-control-ref.d.ts +23 -0
  153. package/dist/src/terminal-control-ref.js +32 -0
  154. package/dist/src/terminal-control-ref.js.map +1 -1
  155. package/dist/src/terminal-dispatch-recovery-authority.d.ts +56 -0
  156. package/dist/src/terminal-dispatch-recovery-authority.js +251 -0
  157. package/dist/src/terminal-dispatch-recovery-authority.js.map +1 -0
  158. package/dist/src/terminal-dispatch-recovery-cli-adapter.d.ts +1 -9
  159. package/dist/src/terminal-dispatch-recovery-cli-adapter.js +5 -240
  160. package/dist/src/terminal-dispatch-recovery-cli-adapter.js.map +1 -1
  161. package/dist/src/terminal-handoff-cli-adapter.d.ts +1 -11
  162. package/dist/src/terminal-handoff-cli-adapter.js +2 -39
  163. package/dist/src/terminal-handoff-cli-adapter.js.map +1 -1
  164. package/dist/src/terminal-human-explicit-send-cli-adapter.d.ts +25 -0
  165. package/dist/src/terminal-human-explicit-send-cli-adapter.js +903 -0
  166. package/dist/src/terminal-human-explicit-send-cli-adapter.js.map +1 -0
  167. package/dist/src/terminal-identity-authority-cli-adapter.d.ts +1 -6
  168. package/dist/src/terminal-identity-authority-cli-adapter.js +3 -33
  169. package/dist/src/terminal-identity-authority-cli-adapter.js.map +1 -1
  170. package/dist/src/terminal-interaction-cli-adapter.js +209 -210
  171. package/dist/src/terminal-interaction-cli-adapter.js.map +1 -1
  172. package/dist/src/terminal-interaction-core.d.ts +0 -2
  173. package/dist/src/terminal-interaction-core.js +4 -3
  174. package/dist/src/terminal-interaction-core.js.map +1 -1
  175. package/dist/src/terminal-interaction-protocol.d.ts +21 -0
  176. package/dist/src/terminal-interaction-protocol.js +74 -0
  177. package/dist/src/terminal-interaction-protocol.js.map +1 -1
  178. package/dist/src/terminal-interaction-response-bridge.d.ts +126 -0
  179. package/dist/src/terminal-interaction-response-bridge.js +579 -0
  180. package/dist/src/terminal-interaction-response-bridge.js.map +1 -0
  181. package/dist/src/terminal-interaction-response-transaction.d.ts +44 -0
  182. package/dist/src/terminal-interaction-response-transaction.js +56 -0
  183. package/dist/src/terminal-interaction-response-transaction.js.map +1 -0
  184. package/dist/src/terminal-list-action-policy.d.ts +43 -0
  185. package/dist/src/terminal-list-action-policy.js +164 -0
  186. package/dist/src/terminal-list-action-policy.js.map +1 -0
  187. package/dist/src/terminal-list-cli-adapter.d.ts +6 -36
  188. package/dist/src/terminal-list-cli-adapter.js +314 -1711
  189. package/dist/src/terminal-list-cli-adapter.js.map +1 -1
  190. package/dist/src/terminal-list-facts.d.ts +129 -0
  191. package/dist/src/terminal-list-facts.js +179 -0
  192. package/dist/src/terminal-list-facts.js.map +1 -0
  193. package/dist/src/terminal-list-inventory.d.ts +59 -0
  194. package/dist/src/terminal-list-inventory.js +194 -0
  195. package/dist/src/terminal-list-inventory.js.map +1 -0
  196. package/dist/src/terminal-list-ownership-service.d.ts +118 -0
  197. package/dist/src/terminal-list-ownership-service.js +1003 -0
  198. package/dist/src/terminal-list-ownership-service.js.map +1 -0
  199. package/dist/src/terminal-list-projection-service.d.ts +49 -0
  200. package/dist/src/terminal-list-projection-service.js +407 -0
  201. package/dist/src/terminal-list-projection-service.js.map +1 -0
  202. package/dist/src/terminal-list-renderer.d.ts +12 -11
  203. package/dist/src/terminal-list-renderer.js +237 -104
  204. package/dist/src/terminal-list-renderer.js.map +1 -1
  205. package/dist/src/terminal-managed-send-cli-adapter.d.ts +33 -0
  206. package/dist/src/terminal-managed-send-cli-adapter.js +994 -0
  207. package/dist/src/terminal-managed-send-cli-adapter.js.map +1 -0
  208. package/dist/src/terminal-managed-turn-list-action-policy.d.ts +47 -0
  209. package/dist/src/terminal-managed-turn-list-action-policy.js +64 -0
  210. package/dist/src/terminal-managed-turn-list-action-policy.js.map +1 -0
  211. package/dist/src/terminal-model-control-action-policy.d.ts +60 -0
  212. package/dist/src/terminal-model-control-action-policy.js +96 -0
  213. package/dist/src/terminal-model-control-action-policy.js.map +1 -0
  214. package/dist/src/terminal-model-control-availability.d.ts +68 -0
  215. package/dist/src/terminal-model-control-availability.js +157 -0
  216. package/dist/src/terminal-model-control-availability.js.map +1 -0
  217. package/dist/src/terminal-model-control-bridge.d.ts +48 -0
  218. package/dist/src/terminal-model-control-bridge.js +259 -0
  219. package/dist/src/terminal-model-control-bridge.js.map +1 -0
  220. package/dist/src/terminal-model-control-profile.d.ts +55 -0
  221. package/dist/src/terminal-model-control-profile.js +137 -0
  222. package/dist/src/terminal-model-control-profile.js.map +1 -0
  223. package/dist/src/terminal-model-control-subject.d.ts +34 -0
  224. package/dist/src/terminal-model-control-subject.js +58 -0
  225. package/dist/src/terminal-model-control-subject.js.map +1 -0
  226. package/dist/src/terminal-model-control-transaction.d.ts +19 -0
  227. package/dist/src/terminal-model-control-transaction.js +39 -0
  228. package/dist/src/terminal-model-control-transaction.js.map +1 -0
  229. package/dist/src/terminal-model-control.d.ts +331 -0
  230. package/dist/src/terminal-model-control.js +1686 -0
  231. package/dist/src/terminal-model-control.js.map +1 -0
  232. package/dist/src/terminal-monitor-application-service.js +50 -17
  233. package/dist/src/terminal-monitor-application-service.js.map +1 -1
  234. package/dist/src/terminal-native-inspection-bridge.d.ts +211 -0
  235. package/dist/src/terminal-native-inspection-bridge.js +1127 -0
  236. package/dist/src/terminal-native-inspection-bridge.js.map +1 -0
  237. package/dist/src/terminal-runtime-cli-adapter.d.ts +2 -0
  238. package/dist/src/terminal-runtime-cli-adapter.js +59 -17
  239. package/dist/src/terminal-runtime-cli-adapter.js.map +1 -1
  240. package/dist/src/terminal-submission-retry-application.d.ts +24 -0
  241. package/dist/src/terminal-submission-retry-application.js +402 -0
  242. package/dist/src/terminal-submission-retry-application.js.map +1 -0
  243. package/dist/src/terminal-submission-retry-ports.d.ts +30 -0
  244. package/dist/src/terminal-submission-retry-ports.js +2 -0
  245. package/dist/src/terminal-submission-retry-ports.js.map +1 -0
  246. package/dist/src/terminal-submission-retry-reconciliation.d.ts +236 -0
  247. package/dist/src/terminal-submission-retry-reconciliation.js +1130 -0
  248. package/dist/src/terminal-submission-retry-reconciliation.js.map +1 -0
  249. package/dist/src/terminal-submission-retry-transport.d.ts +58 -0
  250. package/dist/src/terminal-submission-retry-transport.js +675 -0
  251. package/dist/src/terminal-submission-retry-transport.js.map +1 -0
  252. package/dist/src/terminal-text-submission-bridge.d.ts +200 -0
  253. package/dist/src/terminal-text-submission-bridge.js +632 -0
  254. package/dist/src/terminal-text-submission-bridge.js.map +1 -0
  255. package/dist/src/terminal-user-explicit-send-policy.d.ts +29 -0
  256. package/dist/src/terminal-user-explicit-send-policy.js +46 -0
  257. package/dist/src/terminal-user-explicit-send-policy.js.map +1 -0
  258. package/dist/src/terminal-watch-cli-adapter.js +91 -143
  259. package/dist/src/terminal-watch-cli-adapter.js.map +1 -1
  260. package/dist/src/terminal-watch-codec.d.ts +9 -0
  261. package/dist/src/terminal-watch-codec.js +1051 -0
  262. package/dist/src/terminal-watch-codec.js.map +1 -0
  263. package/dist/src/terminal-watch-interaction-response-store.d.ts +19 -0
  264. package/dist/src/terminal-watch-interaction-response-store.js +87 -0
  265. package/dist/src/terminal-watch-interaction-response-store.js.map +1 -0
  266. package/dist/src/terminal-watch-record.d.ts +319 -0
  267. package/dist/src/terminal-watch-record.js +742 -0
  268. package/dist/src/terminal-watch-record.js.map +1 -0
  269. package/dist/src/terminal-watch-service.js +48 -27
  270. package/dist/src/terminal-watch-service.js.map +1 -1
  271. package/dist/src/terminal-watch-store.d.ts +3 -279
  272. package/dist/src/terminal-watch-store.js +5 -1779
  273. package/dist/src/terminal-watch-store.js.map +1 -1
  274. package/docs/quickstart-herdr.md +1 -1
  275. package/docs/quickstart-tmux.md +27 -2
  276. package/openclaw.plugin.json +13 -1
  277. package/package.json +7 -2
  278. package/templates/openclaw-skills/agent-knock-knock/SKILL.md +54 -11
@@ -0,0 +1,2 @@
1
+ /** @deprecated OpenClaw compatibility facade; use semantic-tool-value-helpers. */
2
+ export * from "./semantic-tool-value-helpers.js";
@@ -0,0 +1,3 @@
1
+ /** @deprecated OpenClaw compatibility facade; use semantic-tool-value-helpers. */
2
+ export * from "./semantic-tool-value-helpers.js";
3
+ //# sourceMappingURL=openclaw-plugin-value-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openclaw-plugin-value-helpers.js","sourceRoot":"","sources":["../../src/openclaw-plugin-value-helpers.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,cAAc,kCAAkC,CAAC"}
@@ -1,41 +1,6 @@
1
- export declare const OPENCLAW_PRIVATE_AUTHORITY_OFFER_TTL_MS: number;
2
- export declare const OPENCLAW_PRIVATE_AUTHORITY_OFFER_LIMIT = 512;
3
- export declare const OPENCLAW_APPROVAL_AUTHORITY_KIND = "approval";
4
- export declare const OPENCLAW_INTERACTION_AUTHORITY_KIND = "interaction";
5
- export declare const OPENCLAW_INTERACTION_AUTHORITY_SUBJECT_KINDS: readonly ["managed_turn", "terminal_watch"];
6
- export type OpenClawInteractionAuthoritySubjectKind = typeof OPENCLAW_INTERACTION_AUTHORITY_SUBJECT_KINDS[number];
7
- export interface OpenClawPrivateAuthorityTarget {
8
- type: string;
9
- id: string;
10
- }
11
- export interface OpenClawPrivateAuthorityOfferKey {
12
- sessionKey: string;
13
- sessionId: string;
14
- kind: string;
15
- target: OpenClawPrivateAuthorityTarget;
16
- }
17
- export interface OpenClawPrivateAuthorityOfferPayload extends Readonly<Record<string, unknown>> {
18
- readonly args?: Readonly<Record<string, unknown>>;
19
- readonly fingerprint?: string;
20
- readonly invalidated?: boolean;
21
- }
22
- export declare function openClawApprovalAuthorityOfferKey(sessionKey: string, sessionId: string, target: OpenClawPrivateAuthorityTarget): OpenClawPrivateAuthorityOfferKey;
23
1
  /**
24
- * Legacy managed-Turn overload retained while callers migrate to the explicit
25
- * subject-aware form below.
2
+ * OpenClaw compatibility names for the Host-neutral private authority store.
3
+ * New core code must import semantic-private-authority-offers directly.
26
4
  */
27
- export declare function openClawInteractionAuthorityOfferKey(sessionKey: string, sessionId: string, turnId: string, interactionId: string): OpenClawPrivateAuthorityOfferKey;
28
- export declare function openClawInteractionAuthorityOfferKey(sessionKey: string, sessionId: string, subjectKind: OpenClawInteractionAuthoritySubjectKind, subjectId: string, interactionId: string): OpenClawPrivateAuthorityOfferKey;
29
- export declare function openClawManagedTurnInteractionAuthorityOfferKey(sessionKey: string, sessionId: string, turnId: string, interactionId: string): OpenClawPrivateAuthorityOfferKey;
30
- export declare function openClawTerminalWatchInteractionAuthorityOfferKey(sessionKey: string, sessionId: string, watchId: string, interactionId: string): OpenClawPrivateAuthorityOfferKey;
31
- /**
32
- * Invalidates every interaction response offer previously displayed for one
33
- * exact subject in one exact controller conversation. Status uses this as a
34
- * refresh boundary before it publishes at most one offer from the new
35
- * snapshot, so an old interaction id cannot remain actionable for the rest of
36
- * its TTL after the terminal UI disappears or changes.
37
- */
38
- export declare function invalidateOpenClawInteractionAuthorityOffersForSubject(api: object, sessionKey: string, sessionId: string, subjectKind: OpenClawInteractionAuthoritySubjectKind, subjectId: string, nowMs?: number): number;
39
- export declare function rememberOpenClawPrivateAuthorityOffer(api: object, key: OpenClawPrivateAuthorityOfferKey, payload: Record<string, unknown>, nowMs?: number): void;
40
- export declare function peekOpenClawPrivateAuthorityOffer<Payload extends OpenClawPrivateAuthorityOfferPayload = OpenClawPrivateAuthorityOfferPayload>(api: object, key: OpenClawPrivateAuthorityOfferKey, nowMs?: number): Payload | undefined;
41
- export declare function consumeOpenClawPrivateAuthorityOffer<Payload extends OpenClawPrivateAuthorityOfferPayload = OpenClawPrivateAuthorityOfferPayload>(api: object, key: OpenClawPrivateAuthorityOfferKey, nowMs?: number): Payload | undefined;
5
+ export { SEMANTIC_APPROVAL_AUTHORITY_KIND as OPENCLAW_APPROVAL_AUTHORITY_KIND, SEMANTIC_INTERACTION_AUTHORITY_KIND as OPENCLAW_INTERACTION_AUTHORITY_KIND, SEMANTIC_INTERACTION_AUTHORITY_SUBJECT_KINDS as OPENCLAW_INTERACTION_AUTHORITY_SUBJECT_KINDS, SEMANTIC_PRIVATE_AUTHORITY_OFFER_LIMIT as OPENCLAW_PRIVATE_AUTHORITY_OFFER_LIMIT, SEMANTIC_PRIVATE_AUTHORITY_OFFER_TTL_MS as OPENCLAW_PRIVATE_AUTHORITY_OFFER_TTL_MS, consumeSemanticPrivateAuthorityOffer as consumeOpenClawPrivateAuthorityOffer, invalidateSemanticInteractionAuthorityOffersForSubject as invalidateOpenClawInteractionAuthorityOffersForSubject, peekSemanticPrivateAuthorityOffer as peekOpenClawPrivateAuthorityOffer, rememberSemanticPrivateAuthorityOffer as rememberOpenClawPrivateAuthorityOffer, semanticApprovalAuthorityOfferKey as openClawApprovalAuthorityOfferKey, semanticInteractionAuthorityOfferKey as openClawInteractionAuthorityOfferKey, semanticManagedTurnInteractionAuthorityOfferKey as openClawManagedTurnInteractionAuthorityOfferKey, semanticTerminalWatchInteractionAuthorityOfferKey as openClawTerminalWatchInteractionAuthorityOfferKey } from "./semantic-private-authority-offers.js";
6
+ export type { SemanticInteractionAuthoritySubjectKind as OpenClawInteractionAuthoritySubjectKind, SemanticPrivateAuthorityOfferKey as OpenClawPrivateAuthorityOfferKey, SemanticPrivateAuthorityOfferPayload as OpenClawPrivateAuthorityOfferPayload, SemanticPrivateAuthorityTarget as OpenClawPrivateAuthorityTarget } from "./semantic-private-authority-offers.js";
@@ -1,261 +1,6 @@
1
- export const OPENCLAW_PRIVATE_AUTHORITY_OFFER_TTL_MS = 10 * 60 * 1000;
2
- export const OPENCLAW_PRIVATE_AUTHORITY_OFFER_LIMIT = 512;
3
- export const OPENCLAW_APPROVAL_AUTHORITY_KIND = "approval";
4
- export const OPENCLAW_INTERACTION_AUTHORITY_KIND = "interaction";
5
- export const OPENCLAW_INTERACTION_AUTHORITY_SUBJECT_KINDS = [
6
- "managed_turn",
7
- "terminal_watch"
8
- ];
9
- const storesByApi = new WeakMap();
10
- export function openClawApprovalAuthorityOfferKey(sessionKey, sessionId, target) {
11
- return {
12
- sessionKey,
13
- sessionId,
14
- kind: OPENCLAW_APPROVAL_AUTHORITY_KIND,
15
- target
16
- };
17
- }
18
- export function openClawInteractionAuthorityOfferKey(sessionKey, sessionId, subjectKindOrTurnId, subjectIdOrInteractionId, explicitInteractionId) {
19
- const legacyManagedTurn = explicitInteractionId === undefined;
20
- const subjectKind = legacyManagedTurn
21
- ? "managed_turn"
22
- : interactionAuthoritySubjectKind(subjectKindOrTurnId);
23
- const subjectId = exactNonBlank(legacyManagedTurn ? subjectKindOrTurnId : subjectIdOrInteractionId, "interaction subject id");
24
- const interactionId = exactNonBlank(legacyManagedTurn ? subjectIdOrInteractionId : explicitInteractionId, "interaction id");
25
- return {
26
- sessionKey,
27
- sessionId,
28
- kind: OPENCLAW_INTERACTION_AUTHORITY_KIND,
29
- target: {
30
- type: "interaction_subject",
31
- id: JSON.stringify([subjectKind, subjectId, interactionId])
32
- }
33
- };
34
- }
35
- export function openClawManagedTurnInteractionAuthorityOfferKey(sessionKey, sessionId, turnId, interactionId) {
36
- return openClawInteractionAuthorityOfferKey(sessionKey, sessionId, "managed_turn", turnId, interactionId);
37
- }
38
- export function openClawTerminalWatchInteractionAuthorityOfferKey(sessionKey, sessionId, watchId, interactionId) {
39
- return openClawInteractionAuthorityOfferKey(sessionKey, sessionId, "terminal_watch", watchId, interactionId);
40
- }
41
1
  /**
42
- * Invalidates every interaction response offer previously displayed for one
43
- * exact subject in one exact controller conversation. Status uses this as a
44
- * refresh boundary before it publishes at most one offer from the new
45
- * snapshot, so an old interaction id cannot remain actionable for the rest of
46
- * its TTL after the terminal UI disappears or changes.
2
+ * OpenClaw compatibility names for the Host-neutral private authority store.
3
+ * New core code must import semantic-private-authority-offers directly.
47
4
  */
48
- export function invalidateOpenClawInteractionAuthorityOffersForSubject(api, sessionKey, sessionId, subjectKind, subjectId, nowMs = Date.now()) {
49
- const exactApi = assertApi(api);
50
- const exactSessionKey = exactNonBlank(sessionKey, "sessionKey");
51
- const exactSessionId = exactNonBlank(sessionId, "sessionId");
52
- const exactSubjectKind = interactionAuthoritySubjectKind(subjectKind);
53
- const exactSubjectId = exactNonBlank(subjectId, "interaction subject id");
54
- assertNow(nowMs);
55
- const store = storesByApi.get(exactApi);
56
- if (!store)
57
- return 0;
58
- pruneExpiredOffers(store, nowMs);
59
- let invalidated = 0;
60
- for (const normalizedKey of store.entries.keys()) {
61
- if (normalizedInteractionOfferMatchesSubject(normalizedKey, exactSessionKey, exactSessionId, exactSubjectKind, exactSubjectId)) {
62
- store.entries.delete(normalizedKey);
63
- invalidated += 1;
64
- }
65
- }
66
- return invalidated;
67
- }
68
- export function rememberOpenClawPrivateAuthorityOffer(api, key, payload, nowMs = Date.now()) {
69
- const normalizedKey = privateAuthorityOfferKey(key);
70
- const store = privateAuthorityOfferStore(api);
71
- assertNow(nowMs);
72
- pruneExpiredOffers(store, nowMs);
73
- const previous = store.entries.get(normalizedKey)?.payload;
74
- const authorityChanged = privateAuthorityPayloadChanged(previous, payload);
75
- const merged = mergePrivateAuthorityPayload(previous, payload);
76
- const invalidated = authorityChanged || (previous?.invalidated === true);
77
- const storedPayload = {
78
- ...merged,
79
- ...(invalidated ? { invalidated: true } : {})
80
- };
81
- if (!invalidated)
82
- delete storedPayload.invalidated;
83
- store.entries.delete(normalizedKey);
84
- while (store.entries.size >= OPENCLAW_PRIVATE_AUTHORITY_OFFER_LIMIT) {
85
- const oldest = store.entries.keys().next().value;
86
- if (typeof oldest !== "string")
87
- break;
88
- store.entries.delete(oldest);
89
- }
90
- store.entries.set(normalizedKey, {
91
- expiresAtMs: nowMs + OPENCLAW_PRIVATE_AUTHORITY_OFFER_TTL_MS,
92
- payload: cloneAndFreezePayload(storedPayload)
93
- });
94
- }
95
- export function peekOpenClawPrivateAuthorityOffer(api, key, nowMs = Date.now()) {
96
- return readPrivateAuthorityOffer(api, key, false, nowMs);
97
- }
98
- export function consumeOpenClawPrivateAuthorityOffer(api, key, nowMs = Date.now()) {
99
- return readPrivateAuthorityOffer(api, key, true, nowMs);
100
- }
101
- function readPrivateAuthorityOffer(api, key, consume, nowMs) {
102
- assertNow(nowMs);
103
- const store = storesByApi.get(assertApi(api));
104
- if (!store)
105
- return undefined;
106
- const normalizedKey = privateAuthorityOfferKey(key);
107
- const offer = store.entries.get(normalizedKey);
108
- if (!offer) {
109
- pruneExpiredOffers(store, nowMs);
110
- return undefined;
111
- }
112
- if (offer.expiresAtMs <= nowMs) {
113
- store.entries.delete(normalizedKey);
114
- pruneExpiredOffers(store, nowMs);
115
- return undefined;
116
- }
117
- if (offer.payload.invalidated === true) {
118
- if (consume)
119
- store.entries.delete(normalizedKey);
120
- return undefined;
121
- }
122
- if (consume)
123
- store.entries.delete(normalizedKey);
124
- return offer.payload;
125
- }
126
- function privateAuthorityOfferStore(api) {
127
- const exactApi = assertApi(api);
128
- const existing = storesByApi.get(exactApi);
129
- if (existing)
130
- return existing;
131
- const created = { entries: new Map() };
132
- storesByApi.set(exactApi, created);
133
- return created;
134
- }
135
- function privateAuthorityOfferKey(key) {
136
- const sessionKey = exactNonBlank(key?.sessionKey, "sessionKey");
137
- const sessionId = exactNonBlank(key?.sessionId, "sessionId");
138
- const kind = exactIdentifier(key?.kind, "kind");
139
- const targetType = exactIdentifier(key?.target?.type, "target.type");
140
- const targetId = exactNonBlank(key?.target?.id, "target.id");
141
- return JSON.stringify([sessionKey, sessionId, kind, targetType, targetId]);
142
- }
143
- function normalizedInteractionOfferMatchesSubject(normalizedKey, sessionKey, sessionId, subjectKind, subjectId) {
144
- try {
145
- const key = JSON.parse(normalizedKey);
146
- if (!Array.isArray(key) ||
147
- key.length !== 5 ||
148
- key[0] !== sessionKey ||
149
- key[1] !== sessionId ||
150
- key[2] !== OPENCLAW_INTERACTION_AUTHORITY_KIND ||
151
- key[3] !== "interaction_subject" ||
152
- typeof key[4] !== "string") {
153
- return false;
154
- }
155
- const target = JSON.parse(key[4]);
156
- return Array.isArray(target) &&
157
- target.length === 3 &&
158
- target[0] === subjectKind &&
159
- target[1] === subjectId &&
160
- typeof target[2] === "string";
161
- }
162
- catch {
163
- return false;
164
- }
165
- }
166
- function exactIdentifier(value, label) {
167
- const text = exactNonBlank(value, label);
168
- if (!/^[a-z][a-z0-9_.-]{0,63}$/u.test(text)) {
169
- throw new Error(`private authority offer ${label} is invalid`);
170
- }
171
- return text;
172
- }
173
- function interactionAuthoritySubjectKind(value) {
174
- if (!OPENCLAW_INTERACTION_AUTHORITY_SUBJECT_KINDS.includes(value)) {
175
- throw new Error("private authority offer interaction subject kind is invalid");
176
- }
177
- return value;
178
- }
179
- function exactNonBlank(value, label) {
180
- if (typeof value !== "string" ||
181
- value.length === 0 ||
182
- value.trim() !== value) {
183
- throw new Error(`private authority offer ${label} must be exact and non-empty`);
184
- }
185
- return value;
186
- }
187
- function assertApi(api) {
188
- if ((typeof api !== "object" || api === null) && typeof api !== "function") {
189
- throw new Error("private authority offer api must be an object");
190
- }
191
- return api;
192
- }
193
- function assertNow(nowMs) {
194
- if (!Number.isFinite(nowMs)) {
195
- throw new Error("private authority offer clock must be finite");
196
- }
197
- }
198
- function pruneExpiredOffers(store, nowMs) {
199
- for (const [key, offer] of store.entries) {
200
- if (offer.expiresAtMs <= nowMs)
201
- store.entries.delete(key);
202
- }
203
- }
204
- function cloneAndFreezePayload(payload) {
205
- if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
206
- throw new Error("private authority offer payload must be an object");
207
- }
208
- let cloned;
209
- try {
210
- cloned = structuredClone(payload);
211
- }
212
- catch {
213
- throw new Error("private authority offer payload must be structured-cloneable");
214
- }
215
- return deepFreeze(cloned, new WeakSet());
216
- }
217
- function mergePrivateAuthorityPayload(previous, update) {
218
- const definedUpdate = Object.fromEntries(Object.entries(update).filter(([, value]) => value !== undefined));
219
- const previousArgs = isPlainRecord(previous?.args) ? previous.args : {};
220
- const updateArgs = isPlainRecord(definedUpdate.args)
221
- ? definedUpdate.args
222
- : undefined;
223
- return {
224
- ...(previous ?? {}),
225
- ...definedUpdate,
226
- ...(updateArgs
227
- ? { args: { ...previousArgs, ...updateArgs } }
228
- : Object.keys(previousArgs).length > 0
229
- ? { args: previousArgs }
230
- : {})
231
- };
232
- }
233
- function privateAuthorityPayloadChanged(previous, update) {
234
- if (!previous)
235
- return false;
236
- const nextFingerprint = update.fingerprint;
237
- if (nextFingerprint !== undefined &&
238
- previous.fingerprint !== undefined &&
239
- nextFingerprint !== previous.fingerprint) {
240
- return true;
241
- }
242
- const previousArgs = isPlainRecord(previous.args) ? previous.args : {};
243
- const updateArgs = isPlainRecord(update.args) ? update.args : undefined;
244
- if (!updateArgs)
245
- return false;
246
- return Object.keys(previousArgs).length > 0 &&
247
- JSON.stringify(previousArgs) !== JSON.stringify(updateArgs);
248
- }
249
- function isPlainRecord(value) {
250
- return typeof value === "object" && value !== null && !Array.isArray(value);
251
- }
252
- function deepFreeze(value, seen) {
253
- if (typeof value !== "object" || value === null || seen.has(value)) {
254
- return value;
255
- }
256
- seen.add(value);
257
- for (const nested of Object.values(value))
258
- deepFreeze(nested, seen);
259
- return Object.freeze(value);
260
- }
5
+ export { SEMANTIC_APPROVAL_AUTHORITY_KIND as OPENCLAW_APPROVAL_AUTHORITY_KIND, SEMANTIC_INTERACTION_AUTHORITY_KIND as OPENCLAW_INTERACTION_AUTHORITY_KIND, SEMANTIC_INTERACTION_AUTHORITY_SUBJECT_KINDS as OPENCLAW_INTERACTION_AUTHORITY_SUBJECT_KINDS, SEMANTIC_PRIVATE_AUTHORITY_OFFER_LIMIT as OPENCLAW_PRIVATE_AUTHORITY_OFFER_LIMIT, SEMANTIC_PRIVATE_AUTHORITY_OFFER_TTL_MS as OPENCLAW_PRIVATE_AUTHORITY_OFFER_TTL_MS, consumeSemanticPrivateAuthorityOffer as consumeOpenClawPrivateAuthorityOffer, invalidateSemanticInteractionAuthorityOffersForSubject as invalidateOpenClawInteractionAuthorityOffersForSubject, peekSemanticPrivateAuthorityOffer as peekOpenClawPrivateAuthorityOffer, rememberSemanticPrivateAuthorityOffer as rememberOpenClawPrivateAuthorityOffer, semanticApprovalAuthorityOfferKey as openClawApprovalAuthorityOfferKey, semanticInteractionAuthorityOfferKey as openClawInteractionAuthorityOfferKey, semanticManagedTurnInteractionAuthorityOfferKey as openClawManagedTurnInteractionAuthorityOfferKey, semanticTerminalWatchInteractionAuthorityOfferKey as openClawTerminalWatchInteractionAuthorityOfferKey } from "./semantic-private-authority-offers.js";
261
6
  //# sourceMappingURL=openclaw-private-authority-offers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"openclaw-private-authority-offers.js","sourceRoot":"","sources":["../../src/openclaw-private-authority-offers.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uCAAuC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACtE,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,CAAC;AAC1D,MAAM,CAAC,MAAM,gCAAgC,GAAG,UAAU,CAAC;AAC3D,MAAM,CAAC,MAAM,mCAAmC,GAAG,aAAa,CAAC;AACjE,MAAM,CAAC,MAAM,4CAA4C,GAAG;IAC1D,cAAc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-private-authority-offers.js","sourceRoot":"","sources":["../../src/openclaw-private-authority-offers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,gCAAgC,IAAI,gCAAgC,EACpE,mCAAmC,IAAI,mCAAmC,EAC1E,4CAA4C,IAAI,4CAA4C,EAC5F,sCAAsC,IAAI,sCAAsC,EAChF,uCAAuC,IAAI,uCAAuC,EAClF,oCAAoC,IAAI,oCAAoC,EAC5E,sDAAsD,IAAI,sDAAsD,EAChH,iCAAiC,IAAI,iCAAiC,EACtE,qCAAqC,IAAI,qCAAqC,EAC9E,iCAAiC,IAAI,iCAAiC,EACtE,oCAAoC,IAAI,oCAAoC,EAC5E,+CAA+C,IAAI,+CAA+C,EAClG,iDAAiD,IAAI,iDAAiD,EACvG,MAAM,wCAAwC,CAAC"}
@@ -0,0 +1,41 @@
1
+ export declare const SEMANTIC_PRIVATE_AUTHORITY_OFFER_TTL_MS: number;
2
+ export declare const SEMANTIC_PRIVATE_AUTHORITY_OFFER_LIMIT = 512;
3
+ export declare const SEMANTIC_APPROVAL_AUTHORITY_KIND = "approval";
4
+ export declare const SEMANTIC_INTERACTION_AUTHORITY_KIND = "interaction";
5
+ export declare const SEMANTIC_INTERACTION_AUTHORITY_SUBJECT_KINDS: readonly ["managed_turn", "terminal_watch"];
6
+ export type SemanticInteractionAuthoritySubjectKind = typeof SEMANTIC_INTERACTION_AUTHORITY_SUBJECT_KINDS[number];
7
+ export interface SemanticPrivateAuthorityTarget {
8
+ type: string;
9
+ id: string;
10
+ }
11
+ export interface SemanticPrivateAuthorityOfferKey {
12
+ sessionKey: string;
13
+ sessionId: string;
14
+ kind: string;
15
+ target: SemanticPrivateAuthorityTarget;
16
+ }
17
+ export interface SemanticPrivateAuthorityOfferPayload extends Readonly<Record<string, unknown>> {
18
+ readonly args?: Readonly<Record<string, unknown>>;
19
+ readonly fingerprint?: string;
20
+ readonly invalidated?: boolean;
21
+ }
22
+ export declare function semanticApprovalAuthorityOfferKey(sessionKey: string, sessionId: string, target: SemanticPrivateAuthorityTarget): SemanticPrivateAuthorityOfferKey;
23
+ /**
24
+ * Legacy managed-Turn overload retained while callers migrate to the explicit
25
+ * subject-aware form below.
26
+ */
27
+ export declare function semanticInteractionAuthorityOfferKey(sessionKey: string, sessionId: string, turnId: string, interactionId: string): SemanticPrivateAuthorityOfferKey;
28
+ export declare function semanticInteractionAuthorityOfferKey(sessionKey: string, sessionId: string, subjectKind: SemanticInteractionAuthoritySubjectKind, subjectId: string, interactionId: string): SemanticPrivateAuthorityOfferKey;
29
+ export declare function semanticManagedTurnInteractionAuthorityOfferKey(sessionKey: string, sessionId: string, turnId: string, interactionId: string): SemanticPrivateAuthorityOfferKey;
30
+ export declare function semanticTerminalWatchInteractionAuthorityOfferKey(sessionKey: string, sessionId: string, watchId: string, interactionId: string): SemanticPrivateAuthorityOfferKey;
31
+ /**
32
+ * Invalidates every interaction response offer previously displayed for one
33
+ * exact subject in one exact controller conversation. Status uses this as a
34
+ * refresh boundary before it publishes at most one offer from the new
35
+ * snapshot, so an old interaction id cannot remain actionable for the rest of
36
+ * its TTL after the terminal UI disappears or changes.
37
+ */
38
+ export declare function invalidateSemanticInteractionAuthorityOffersForSubject(api: object, sessionKey: string, sessionId: string, subjectKind: SemanticInteractionAuthoritySubjectKind, subjectId: string, nowMs?: number): number;
39
+ export declare function rememberSemanticPrivateAuthorityOffer(api: object, key: SemanticPrivateAuthorityOfferKey, payload: Record<string, unknown>, nowMs?: number): void;
40
+ export declare function peekSemanticPrivateAuthorityOffer<Payload extends SemanticPrivateAuthorityOfferPayload = SemanticPrivateAuthorityOfferPayload>(api: object, key: SemanticPrivateAuthorityOfferKey, nowMs?: number): Payload | undefined;
41
+ export declare function consumeSemanticPrivateAuthorityOffer<Payload extends SemanticPrivateAuthorityOfferPayload = SemanticPrivateAuthorityOfferPayload>(api: object, key: SemanticPrivateAuthorityOfferKey, nowMs?: number): Payload | undefined;
@@ -0,0 +1,261 @@
1
+ export const SEMANTIC_PRIVATE_AUTHORITY_OFFER_TTL_MS = 10 * 60 * 1000;
2
+ export const SEMANTIC_PRIVATE_AUTHORITY_OFFER_LIMIT = 512;
3
+ export const SEMANTIC_APPROVAL_AUTHORITY_KIND = "approval";
4
+ export const SEMANTIC_INTERACTION_AUTHORITY_KIND = "interaction";
5
+ export const SEMANTIC_INTERACTION_AUTHORITY_SUBJECT_KINDS = [
6
+ "managed_turn",
7
+ "terminal_watch"
8
+ ];
9
+ const storesByApi = new WeakMap();
10
+ export function semanticApprovalAuthorityOfferKey(sessionKey, sessionId, target) {
11
+ return {
12
+ sessionKey,
13
+ sessionId,
14
+ kind: SEMANTIC_APPROVAL_AUTHORITY_KIND,
15
+ target
16
+ };
17
+ }
18
+ export function semanticInteractionAuthorityOfferKey(sessionKey, sessionId, subjectKindOrTurnId, subjectIdOrInteractionId, explicitInteractionId) {
19
+ const legacyManagedTurn = explicitInteractionId === undefined;
20
+ const subjectKind = legacyManagedTurn
21
+ ? "managed_turn"
22
+ : interactionAuthoritySubjectKind(subjectKindOrTurnId);
23
+ const subjectId = exactNonBlank(legacyManagedTurn ? subjectKindOrTurnId : subjectIdOrInteractionId, "interaction subject id");
24
+ const interactionId = exactNonBlank(legacyManagedTurn ? subjectIdOrInteractionId : explicitInteractionId, "interaction id");
25
+ return {
26
+ sessionKey,
27
+ sessionId,
28
+ kind: SEMANTIC_INTERACTION_AUTHORITY_KIND,
29
+ target: {
30
+ type: "interaction_subject",
31
+ id: JSON.stringify([subjectKind, subjectId, interactionId])
32
+ }
33
+ };
34
+ }
35
+ export function semanticManagedTurnInteractionAuthorityOfferKey(sessionKey, sessionId, turnId, interactionId) {
36
+ return semanticInteractionAuthorityOfferKey(sessionKey, sessionId, "managed_turn", turnId, interactionId);
37
+ }
38
+ export function semanticTerminalWatchInteractionAuthorityOfferKey(sessionKey, sessionId, watchId, interactionId) {
39
+ return semanticInteractionAuthorityOfferKey(sessionKey, sessionId, "terminal_watch", watchId, interactionId);
40
+ }
41
+ /**
42
+ * Invalidates every interaction response offer previously displayed for one
43
+ * exact subject in one exact controller conversation. Status uses this as a
44
+ * refresh boundary before it publishes at most one offer from the new
45
+ * snapshot, so an old interaction id cannot remain actionable for the rest of
46
+ * its TTL after the terminal UI disappears or changes.
47
+ */
48
+ export function invalidateSemanticInteractionAuthorityOffersForSubject(api, sessionKey, sessionId, subjectKind, subjectId, nowMs = Date.now()) {
49
+ const exactApi = assertApi(api);
50
+ const exactSessionKey = exactNonBlank(sessionKey, "sessionKey");
51
+ const exactSessionId = exactNonBlank(sessionId, "sessionId");
52
+ const exactSubjectKind = interactionAuthoritySubjectKind(subjectKind);
53
+ const exactSubjectId = exactNonBlank(subjectId, "interaction subject id");
54
+ assertNow(nowMs);
55
+ const store = storesByApi.get(exactApi);
56
+ if (!store)
57
+ return 0;
58
+ pruneExpiredOffers(store, nowMs);
59
+ let invalidated = 0;
60
+ for (const normalizedKey of store.entries.keys()) {
61
+ if (normalizedInteractionOfferMatchesSubject(normalizedKey, exactSessionKey, exactSessionId, exactSubjectKind, exactSubjectId)) {
62
+ store.entries.delete(normalizedKey);
63
+ invalidated += 1;
64
+ }
65
+ }
66
+ return invalidated;
67
+ }
68
+ export function rememberSemanticPrivateAuthorityOffer(api, key, payload, nowMs = Date.now()) {
69
+ const normalizedKey = privateAuthorityOfferKey(key);
70
+ const store = privateAuthorityOfferStore(api);
71
+ assertNow(nowMs);
72
+ pruneExpiredOffers(store, nowMs);
73
+ const previous = store.entries.get(normalizedKey)?.payload;
74
+ const authorityChanged = privateAuthorityPayloadChanged(previous, payload);
75
+ const merged = mergePrivateAuthorityPayload(previous, payload);
76
+ const invalidated = authorityChanged || (previous?.invalidated === true);
77
+ const storedPayload = {
78
+ ...merged,
79
+ ...(invalidated ? { invalidated: true } : {})
80
+ };
81
+ if (!invalidated)
82
+ delete storedPayload.invalidated;
83
+ store.entries.delete(normalizedKey);
84
+ while (store.entries.size >= SEMANTIC_PRIVATE_AUTHORITY_OFFER_LIMIT) {
85
+ const oldest = store.entries.keys().next().value;
86
+ if (typeof oldest !== "string")
87
+ break;
88
+ store.entries.delete(oldest);
89
+ }
90
+ store.entries.set(normalizedKey, {
91
+ expiresAtMs: nowMs + SEMANTIC_PRIVATE_AUTHORITY_OFFER_TTL_MS,
92
+ payload: cloneAndFreezePayload(storedPayload)
93
+ });
94
+ }
95
+ export function peekSemanticPrivateAuthorityOffer(api, key, nowMs = Date.now()) {
96
+ return readPrivateAuthorityOffer(api, key, false, nowMs);
97
+ }
98
+ export function consumeSemanticPrivateAuthorityOffer(api, key, nowMs = Date.now()) {
99
+ return readPrivateAuthorityOffer(api, key, true, nowMs);
100
+ }
101
+ function readPrivateAuthorityOffer(api, key, consume, nowMs) {
102
+ assertNow(nowMs);
103
+ const store = storesByApi.get(assertApi(api));
104
+ if (!store)
105
+ return undefined;
106
+ const normalizedKey = privateAuthorityOfferKey(key);
107
+ const offer = store.entries.get(normalizedKey);
108
+ if (!offer) {
109
+ pruneExpiredOffers(store, nowMs);
110
+ return undefined;
111
+ }
112
+ if (offer.expiresAtMs <= nowMs) {
113
+ store.entries.delete(normalizedKey);
114
+ pruneExpiredOffers(store, nowMs);
115
+ return undefined;
116
+ }
117
+ if (offer.payload.invalidated === true) {
118
+ if (consume)
119
+ store.entries.delete(normalizedKey);
120
+ return undefined;
121
+ }
122
+ if (consume)
123
+ store.entries.delete(normalizedKey);
124
+ return offer.payload;
125
+ }
126
+ function privateAuthorityOfferStore(api) {
127
+ const exactApi = assertApi(api);
128
+ const existing = storesByApi.get(exactApi);
129
+ if (existing)
130
+ return existing;
131
+ const created = { entries: new Map() };
132
+ storesByApi.set(exactApi, created);
133
+ return created;
134
+ }
135
+ function privateAuthorityOfferKey(key) {
136
+ const sessionKey = exactNonBlank(key?.sessionKey, "sessionKey");
137
+ const sessionId = exactNonBlank(key?.sessionId, "sessionId");
138
+ const kind = exactIdentifier(key?.kind, "kind");
139
+ const targetType = exactIdentifier(key?.target?.type, "target.type");
140
+ const targetId = exactNonBlank(key?.target?.id, "target.id");
141
+ return JSON.stringify([sessionKey, sessionId, kind, targetType, targetId]);
142
+ }
143
+ function normalizedInteractionOfferMatchesSubject(normalizedKey, sessionKey, sessionId, subjectKind, subjectId) {
144
+ try {
145
+ const key = JSON.parse(normalizedKey);
146
+ if (!Array.isArray(key) ||
147
+ key.length !== 5 ||
148
+ key[0] !== sessionKey ||
149
+ key[1] !== sessionId ||
150
+ key[2] !== SEMANTIC_INTERACTION_AUTHORITY_KIND ||
151
+ key[3] !== "interaction_subject" ||
152
+ typeof key[4] !== "string") {
153
+ return false;
154
+ }
155
+ const target = JSON.parse(key[4]);
156
+ return Array.isArray(target) &&
157
+ target.length === 3 &&
158
+ target[0] === subjectKind &&
159
+ target[1] === subjectId &&
160
+ typeof target[2] === "string";
161
+ }
162
+ catch {
163
+ return false;
164
+ }
165
+ }
166
+ function exactIdentifier(value, label) {
167
+ const text = exactNonBlank(value, label);
168
+ if (!/^[a-z][a-z0-9_.-]{0,63}$/u.test(text)) {
169
+ throw new Error(`private authority offer ${label} is invalid`);
170
+ }
171
+ return text;
172
+ }
173
+ function interactionAuthoritySubjectKind(value) {
174
+ if (!SEMANTIC_INTERACTION_AUTHORITY_SUBJECT_KINDS.includes(value)) {
175
+ throw new Error("private authority offer interaction subject kind is invalid");
176
+ }
177
+ return value;
178
+ }
179
+ function exactNonBlank(value, label) {
180
+ if (typeof value !== "string" ||
181
+ value.length === 0 ||
182
+ value.trim() !== value) {
183
+ throw new Error(`private authority offer ${label} must be exact and non-empty`);
184
+ }
185
+ return value;
186
+ }
187
+ function assertApi(api) {
188
+ if ((typeof api !== "object" || api === null) && typeof api !== "function") {
189
+ throw new Error("private authority offer api must be an object");
190
+ }
191
+ return api;
192
+ }
193
+ function assertNow(nowMs) {
194
+ if (!Number.isFinite(nowMs)) {
195
+ throw new Error("private authority offer clock must be finite");
196
+ }
197
+ }
198
+ function pruneExpiredOffers(store, nowMs) {
199
+ for (const [key, offer] of store.entries) {
200
+ if (offer.expiresAtMs <= nowMs)
201
+ store.entries.delete(key);
202
+ }
203
+ }
204
+ function cloneAndFreezePayload(payload) {
205
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
206
+ throw new Error("private authority offer payload must be an object");
207
+ }
208
+ let cloned;
209
+ try {
210
+ cloned = structuredClone(payload);
211
+ }
212
+ catch {
213
+ throw new Error("private authority offer payload must be structured-cloneable");
214
+ }
215
+ return deepFreeze(cloned, new WeakSet());
216
+ }
217
+ function mergePrivateAuthorityPayload(previous, update) {
218
+ const definedUpdate = Object.fromEntries(Object.entries(update).filter(([, value]) => value !== undefined));
219
+ const previousArgs = isPlainRecord(previous?.args) ? previous.args : {};
220
+ const updateArgs = isPlainRecord(definedUpdate.args)
221
+ ? definedUpdate.args
222
+ : undefined;
223
+ return {
224
+ ...(previous ?? {}),
225
+ ...definedUpdate,
226
+ ...(updateArgs
227
+ ? { args: { ...previousArgs, ...updateArgs } }
228
+ : Object.keys(previousArgs).length > 0
229
+ ? { args: previousArgs }
230
+ : {})
231
+ };
232
+ }
233
+ function privateAuthorityPayloadChanged(previous, update) {
234
+ if (!previous)
235
+ return false;
236
+ const nextFingerprint = update.fingerprint;
237
+ if (nextFingerprint !== undefined &&
238
+ previous.fingerprint !== undefined &&
239
+ nextFingerprint !== previous.fingerprint) {
240
+ return true;
241
+ }
242
+ const previousArgs = isPlainRecord(previous.args) ? previous.args : {};
243
+ const updateArgs = isPlainRecord(update.args) ? update.args : undefined;
244
+ if (!updateArgs)
245
+ return false;
246
+ return Object.keys(previousArgs).length > 0 &&
247
+ JSON.stringify(previousArgs) !== JSON.stringify(updateArgs);
248
+ }
249
+ function isPlainRecord(value) {
250
+ return typeof value === "object" && value !== null && !Array.isArray(value);
251
+ }
252
+ function deepFreeze(value, seen) {
253
+ if (typeof value !== "object" || value === null || seen.has(value)) {
254
+ return value;
255
+ }
256
+ seen.add(value);
257
+ for (const nested of Object.values(value))
258
+ deepFreeze(nested, seen);
259
+ return Object.freeze(value);
260
+ }
261
+ //# sourceMappingURL=semantic-private-authority-offers.js.map