agent-yes 1.303.1 → 1.304.0

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 (184) hide show
  1. package/README.md +54 -0
  2. package/default.config.yaml +5 -5
  3. package/dist/{JsonlStore-BpYZZTap.js → JsonlStore-CB_0sfdT.js} +5 -4
  4. package/dist/{SUPPORTED_CLIS-Dq9Lq9WJ.js → SUPPORTED_CLIS-C_1IiOj3.js} +2 -2
  5. package/dist/SUPPORTED_CLIS-Do3GHAY1.js +12 -0
  6. package/dist/{agentShare-suB6yPgO.js → agentShare-BvpEm-Fr.js} +10 -9
  7. package/dist/{askCli-BU3CNCLU.js → askCli-KmMf-3wA.js} +6 -6
  8. package/dist/{browser-BmxN1Ur9.js → browser-BAFPmEvN.js} +2 -2
  9. package/dist/{callback-Ctj3_Wxp.js → callback-BiSUhjw7.js} +6 -6
  10. package/dist/callback-SqLD2mMX.js +17 -0
  11. package/dist/{callbackCore-DSJWhqAe.js → callbackCore-BZ_10zyc.js} +1 -1
  12. package/dist/{callbackCore-BesbQ6-Z.js → callbackCore-Deve5pv3.js} +1 -1
  13. package/dist/{channels-j5nWuzlQ.js → channels-Y36S0ccW.js} +2 -2
  14. package/dist/cli.js +118 -13
  15. package/dist/{cmdDsh-2LP0grim.js → cmdDsh-DZ8bLsH7.js} +1 -1
  16. package/dist/cmdKill-CzSBfWmx.js +116 -0
  17. package/dist/{cmdPs-wc1j85fi.js → cmdPs-DBt23Qz0.js} +11 -10
  18. package/dist/{cwdConflictWarn-skQSMwEh.js → cwdConflictWarn-y-epQyOj.js} +21 -5
  19. package/dist/{cwdPassthroughHint-BUbWMoz0.js → cwdPassthroughHint-CzWh0hrw.js} +1 -1
  20. package/dist/{expose-Dawq1LxC.js → expose-Bhsn5yUz.js} +2 -2
  21. package/dist/forceKill-BDqxx4uQ.js +44 -0
  22. package/dist/{forkNested-CavHyWzA.js → forkNested-3heLs5XC.js} +45 -5
  23. package/dist/{globalPidIndex-CRB5KtyL.js → globalPidIndex-BsjlId-h.js} +6 -5
  24. package/dist/{globalPidIndex-BftWlg2V.js → globalPidIndex-uoz8Esqz.js} +2 -2
  25. package/dist/{hist-Cs0KFSUW.js → hist-DY16wm7g.js} +1 -1
  26. package/dist/{identity-DA7YI9km.js → identity-C0MxfwI2.js} +1 -1
  27. package/dist/{identity-Bk-aG_xl.js → identity-Ckav3-Up.js} +1 -1
  28. package/dist/index.js +7 -7
  29. package/dist/{initMsg-CcTqFtsp.js → initMsg-BEVDWYnv.js} +1 -1
  30. package/dist/{initMsg-D9KJnfgC.js → initMsg-GPU52N-j.js} +1 -1
  31. package/dist/liagent/box-BSIrRRc_.js +2320 -0
  32. package/dist/liagent/box-DloywR57.d.ts +409 -0
  33. package/dist/liagent/box.d.ts +3 -0
  34. package/dist/liagent/box.js +3 -0
  35. package/dist/liagent/cli.d.ts +1 -0
  36. package/dist/liagent/cli.js +908 -0
  37. package/dist/liagent/client.d.ts +28 -0
  38. package/dist/liagent/client.js +240 -0
  39. package/dist/liagent/echo-BvzPSI0x.js +86 -0
  40. package/dist/liagent/echo-W2RcMEny.d.ts +38 -0
  41. package/dist/liagent/hub.d.ts +405 -0
  42. package/dist/liagent/hub.js +1831 -0
  43. package/dist/liagent/index.d.ts +14 -0
  44. package/dist/liagent/index.js +10 -0
  45. package/dist/liagent/liagent.js +339 -0
  46. package/dist/liagent/mic-audio-C3Shud_F.js +754 -0
  47. package/dist/liagent/mic-audio-DMCWtEI-.d.ts +317 -0
  48. package/dist/liagent/mic-button-CtZHFBSG.js +651 -0
  49. package/dist/liagent/mic-button-Y0ioPetQ.d.ts +248 -0
  50. package/dist/liagent/mic.d.ts +3 -0
  51. package/dist/liagent/mic.js +4 -0
  52. package/dist/liagent/progress-CJs08bXb.js +473 -0
  53. package/dist/liagent/progress-CfE-meHr.d.ts +205 -0
  54. package/dist/liagent/progress.d.ts +2 -0
  55. package/dist/liagent/progress.js +3 -0
  56. package/dist/liagent/protocol.d.ts +324 -0
  57. package/dist/liagent/protocol.js +504 -0
  58. package/dist/liagent/speech-rate-DXeJjRTc.js +42 -0
  59. package/dist/liagent/state-tree-BZCmAknI.js +353 -0
  60. package/dist/liagent/tree-BrR7NwMf.js +710 -0
  61. package/dist/liagent/tree-HB9RhX_H.d.ts +295 -0
  62. package/dist/liagent/tree.d.ts +2 -0
  63. package/dist/liagent/tree.js +4 -0
  64. package/dist/liagent/ui-strings-B03le3fh.d.ts +27 -0
  65. package/dist/liagent/ui-strings-CJIwW5Gf.js +794 -0
  66. package/dist/liagent/ui.d.ts +394 -0
  67. package/dist/liagent/ui.js +5 -0
  68. package/dist/liagent/voice-D7yeS9VM.js +802 -0
  69. package/dist/liagent/voice-Qo7SCgi8.d.ts +308 -0
  70. package/dist/liagent/voice.d.ts +3 -0
  71. package/dist/liagent/voice.js +4 -0
  72. package/dist/{notifyDaemon-C7GlfJ1E.js → notifyDaemon-DkUB7GV2.js} +10 -9
  73. package/dist/{openBrowser-1cIo4dJL.js → openBrowser-CQAOIrD6.js} +1 -1
  74. package/dist/oxmgrService-DlYHmqyI.js +37 -0
  75. package/dist/oxmgrService-o9L3I6FX.js +3 -0
  76. package/dist/{parentLink-DoEWVGld.js → parentLink-BcAYcO9L.js} +2 -2
  77. package/dist/{parentLink-B58V1RVd.js → parentLink-MBUD3oY2.js} +2 -2
  78. package/dist/{parentPingLoop-C73bbmCE.js → parentPingLoop-DDO592Wh.js} +5 -5
  79. package/dist/{pidStore-433kvh9D.js → pidStore-C50VPk3E.js} +3 -3
  80. package/dist/pidStore-COkPjpW8.js +6 -0
  81. package/dist/{procStats-BvmrBrOs.js → procStats-DwTxj3rs.js} +1 -1
  82. package/dist/{remotes-MfdV9M8u.js → remotes-BqLoB5GR.js} +2 -2
  83. package/dist/{remotes-DevcBeLl.js → remotes-BsMGvAay.js} +3 -3
  84. package/dist/{roomReplyAlias-DFqg_6IU.js → roomReplyAlias-B-v76TA8.js} +3 -3
  85. package/dist/roomReplyAlias-BzWUBkQy.js +6 -0
  86. package/dist/{rustBinary-7VK7oLlW.js → rustBinary-BrJ2p8wy.js} +2 -2
  87. package/dist/{rustBinary-BV4LxMMn.js → rustBinary-vpfpWj1q.js} +2 -2
  88. package/dist/{schedule-Dp0qkNO1.js → schedule-Bzjhl6-h.js} +15 -44
  89. package/dist/schedulesCli-CLqieyQZ.js +784 -0
  90. package/dist/senderAncestry-CVHeKk1Y.js +173 -0
  91. package/dist/senderAncestry-KhAUPCQs.js +3 -0
  92. package/dist/{serve-BpOIIOVc.js → serve-XwFYE0cE.js} +67 -69
  93. package/dist/{serveRust-CbBrcUrg.js → serveRust-BfWkeL6T.js} +31 -4
  94. package/dist/{setup-DdIBk6Iv.js → setup-D4-s2VZw.js} +5 -5
  95. package/dist/{share-w5oRbvlj.js → share-CbFetL5H.js} +1 -1
  96. package/dist/{share-DrS3LYqf.js → share-_TPYAGWC.js} +1 -1
  97. package/dist/{shareCmd-DDENkBW2.js → shareCmd-DUBsVI3e.js} +10 -10
  98. package/dist/spawnGate-Dfj9V76w.js +5 -0
  99. package/dist/{spawnGate-lr3tvA6U.js → spawnGate-Dj_WaS29.js} +3 -3
  100. package/dist/{subcommands-DxgvDmZX.js → subcommands-B7YZJL8n.js} +471 -307
  101. package/dist/subcommands-BZPxFgkT.js +15 -0
  102. package/dist/{systemPathLink-SjUzgSiq.js → systemPathLink-Y3iC7bYV.js} +1 -1
  103. package/dist/{terminal-C2h7tpe0.js → terminal-13cGj3h6.js} +2 -2
  104. package/dist/terminal.js +1 -1
  105. package/dist/{todoAutomation-TTp_Qz9G.js → todoAutomation-CKlrxuZv.js} +2 -2
  106. package/dist/{todoCli-BWm5nZE0.js → todoCli-CU9vSJSJ.js} +6 -6
  107. package/dist/{todoIdentity-BvXZKWJI.js → todoIdentity-CzS1e7VL.js} +2 -2
  108. package/dist/{todoStore-C9RTz0Vs.js → todoStore-msRCEUi1.js} +2 -2
  109. package/dist/{tray-BeRSozJz.js → tray-CLktEN3G.js} +1 -1
  110. package/dist/{trayApp-QQjqhDv1.js → trayApp-5_OlvQcz.js} +2 -2
  111. package/dist/trayApp-DkAPo0m6.js +5 -0
  112. package/dist/{ts-6LF7f4fx.js → ts-njuddXQz.js} +126 -57
  113. package/dist/{versionChecker-Bc62HNf6.js → versionChecker-BJycAanp.js} +2 -2
  114. package/dist/{webrtcLink-va_gAR77.js → webrtcLink-DcvacEci.js} +1 -1
  115. package/dist/{webrtcLink-SsInrVHU.js → webrtcLink-WxS1nTIs.js} +1 -1
  116. package/dist/{webrtcRemote-BlGyNZDC.js → webrtcRemote-C3xQyf3u.js} +2 -2
  117. package/dist/{widget-Crb5zeHL.js → widget-DmRwOlco.js} +3 -3
  118. package/dist/widgets.js +1 -1
  119. package/dist/{workspaceConfig-BLWB5Wu9.js → workspaceConfig-DBgsu81B.js} +1 -1
  120. package/dist/{ws-DIbwNz8Z.js → ws-ByO6JO6m.js} +3 -3
  121. package/dist/{ws-BRhPG1Vy.js → ws-D0-Jg88z.js} +9 -8
  122. package/lab/ui/index.html +1 -1
  123. package/lab/ui/lab/posts/2026-08-11-slack-term-safe-writes.md +1 -1
  124. package/package.json +73 -8
  125. package/ts/JsonlStore.ts +10 -3
  126. package/ts/cli-idle.bun.spec.ts +1 -1
  127. package/ts/cli-idle.spec.ts +1 -1
  128. package/ts/cli.ts +35 -0
  129. package/ts/cmdKill.bun.spec.ts +155 -0
  130. package/ts/cmdKill.spec.ts +155 -0
  131. package/ts/cmdKill.ts +183 -0
  132. package/ts/composerGuard.edges.spec.ts +91 -0
  133. package/ts/composerGuard.spec.ts +53 -6
  134. package/ts/composerGuard.ts +42 -13
  135. package/ts/conptyModeFilter.spec.ts +30 -0
  136. package/ts/conptyModeFilter.ts +53 -0
  137. package/ts/copyLiagent.ts +42 -0
  138. package/ts/cwdConflictWarn.io.spec.ts +50 -0
  139. package/ts/cwdConflictWarn.spec.ts +34 -1
  140. package/ts/cwdConflictWarn.ts +43 -5
  141. package/ts/cwdGuard.spec.ts +110 -0
  142. package/ts/cwdGuard.ts +118 -0
  143. package/ts/forceKill.ts +52 -0
  144. package/ts/forkNested.bun.spec.ts +41 -0
  145. package/ts/forkNested.spec.ts +41 -0
  146. package/ts/forkNested.ts +48 -1
  147. package/ts/globalPidIndex.edges.spec.ts +125 -0
  148. package/ts/globalPidIndex.ts +6 -2
  149. package/ts/index.ts +13 -1
  150. package/ts/interruptSend.bun.spec.ts +99 -0
  151. package/ts/interruptSend.spec.ts +99 -0
  152. package/ts/interruptSend.ts +51 -0
  153. package/ts/lockRegistry.spec.ts +49 -0
  154. package/ts/lsRenderCache.spec.ts +58 -0
  155. package/ts/needsInput.edges.spec.ts +23 -0
  156. package/ts/parseCliArgs.ts +7 -0
  157. package/ts/pushGatePlan.spec.ts +147 -0
  158. package/ts/roomReplyAlias.io.spec.ts +81 -0
  159. package/ts/schedule.ts +5 -1
  160. package/ts/schedules.bun.spec.ts +397 -0
  161. package/ts/schedules.spec.ts +397 -0
  162. package/ts/schedules.ts +517 -0
  163. package/ts/schedulesCli.ts +386 -0
  164. package/ts/sendControl.bun.spec.ts +12 -0
  165. package/ts/senderAncestry.ts +1 -3
  166. package/ts/serve.ts +22 -33
  167. package/ts/serveRust.spec.ts +29 -2
  168. package/ts/serveRust.ts +27 -2
  169. package/ts/sizeNego.bun.spec.ts +9 -2
  170. package/ts/sizeNego.spec.ts +9 -2
  171. package/ts/sizeNego.ts +10 -5
  172. package/ts/subcommands.spec.ts +348 -9
  173. package/ts/subcommands.ts +513 -93
  174. package/ts/suggestAgents.spec.ts +33 -0
  175. package/ts/terminal/browser.ts +1 -1
  176. package/ts/todoParse.spec.ts +22 -1
  177. package/ts/todoParse.ts +19 -0
  178. package/dist/SUPPORTED_CLIS-ByO5twge.js +0 -12
  179. package/dist/callback-D7qfh_7p.js +0 -16
  180. package/dist/pidStore-BRlKRHXY.js +0 -6
  181. package/dist/roomReplyAlias-DuEkSSDI.js +0 -6
  182. package/dist/spawnGate-DeQBTX-o.js +0 -5
  183. package/dist/subcommands-DmiswRy4.js +0 -14
  184. package/dist/trayApp-C4TAvRvU.js +0 -5
@@ -0,0 +1,405 @@
1
+ import { ChatMessage } from "./protocol.js";
2
+
3
+ //#region src/progress-hub.d.ts
4
+ /** Durable Object storage as the progress hub uses it: the key-value API and the alarm. */
5
+ type ProgressStorage = Storage & {
6
+ getAlarm(): Promise<number | null>;
7
+ setAlarm(at: number): Promise<void>;
8
+ };
9
+ type ProgressState = {
10
+ acceptWebSocket(ws: Socket): void;
11
+ getWebSockets(): Socket[];
12
+ storage: ProgressStorage;
13
+ };
14
+ /**
15
+ * Set to "1" by routeProgress() once the host's `reader(req)` said yes; any a
16
+ * client sent is dropped first. A host that routes to the hub itself must do
17
+ * the same.
18
+ */
19
+ declare const PROGRESS_READER_HEADER = "x-liagent-progress-reader";
20
+ /** Writes allowed per window: per name, and for everyone together. */
21
+ declare const RATE: {
22
+ readonly windowMs: 60000;
23
+ readonly perName: 30;
24
+ readonly total: 120;
25
+ };
26
+ /** A report is a few hundred bytes; anything much bigger is not one. */
27
+ declare const MAX_BODY = 4096;
28
+ /** The longest a minted token lives. */
29
+ declare const GRANT_MAX_MS: number;
30
+ declare const GRANT_DEFAULT = "8h";
31
+ /** The note a check-off writes. */
32
+ declare const RESOLVED_NOTE = "resolved by owner";
33
+ /**
34
+ * The checks routeProgress() makes before a token route reaches the hub. null = go
35
+ * on; otherwise the response. 403 from a browser (pages never use tokens),
36
+ * 503 while the secret is unset (so a writer sees why), 401 with no bearer.
37
+ */
38
+ declare function progressGate(req: Request, secret: string | undefined): Response | null;
39
+ type ProgressHubOptions = {
40
+ /** The env binding that holds the root secret. Default "PROGRESS_TOKEN". */secretVar?: string;
41
+ };
42
+ declare class ProgressHub {
43
+ private ctx;
44
+ private now;
45
+ private windows;
46
+ private seq;
47
+ private secret;
48
+ /**
49
+ * `env[secretVar]` (default PROGRESS_TOKEN) is the root secret: unset, every
50
+ * token route answers 401 (routeProgress answers 503 first).
51
+ */
52
+ constructor(ctx: ProgressState, env?: unknown, now?: () => number, opts?: ProgressHubOptions);
53
+ fetch(req: Request): Promise<Response>;
54
+ private body;
55
+ private all;
56
+ /** The tree (newest first) and the log (oldest first). */
57
+ private state;
58
+ sendSnapshot(to?: Socket[]): Promise<void>;
59
+ private send;
60
+ /** Counts one write; false = over the limit. */
61
+ private allow;
62
+ private tooMany;
63
+ /**
64
+ * Is `id` inside the subtree of `node`? Walks parents: a path's directory,
65
+ * otherwise the stored `parent` (`override` stands in for one node's).
66
+ */
67
+ private covers;
68
+ /** Would `parent` (through its own ancestors) lead back to `id`? */
69
+ private loops;
70
+ /** May this token write this report? A message for the 403, or null. */
71
+ private refuse;
72
+ private write;
73
+ /** Put nodes, making room past PROGRESS_MAX_ENTRIES; true if any were dropped. */
74
+ private store;
75
+ /** Append one event, dropping the oldest past PROGRESS_LOG_MAX. */
76
+ private append;
77
+ /**
78
+ * The owner checks off a node: done, `needs` cleared, the answer noted. An
79
+ * owner to-do also resolves the decision or approval it refs.
80
+ */
81
+ resolve(id: string, note?: string): Promise<Response>;
82
+ /** Mint a token for `node` (inside the asking token's scope), signed with the root. */
83
+ private grant;
84
+ /** Make sure the alarm goes off by `at` (one already due is the one running now). */
85
+ private schedule;
86
+ /** The Durable Object alarm: prune done nodes past their TTL and empty auto groups, then wait for the next. */
87
+ alarm(): Promise<void>;
88
+ /** The owner's page checks off a node: {type:"resolve", id, note?}. Nothing else is heard. */
89
+ webSocketMessage(_ws: Socket, raw: string | ArrayBuffer): Promise<void>;
90
+ webSocketClose(ws: Socket, code: number): void;
91
+ webSocketError(ws: Socket): void;
92
+ }
93
+ /**
94
+ * A ProgressHub class with these options baked in, to export from your Worker
95
+ * as the Durable Object: `export const ProgressHub = progressHub()`.
96
+ */
97
+ declare function progressHub(opts?: ProgressHubOptions): typeof ProgressHub;
98
+ type Stub$1 = {
99
+ fetch(req: Request): Promise<Response>;
100
+ };
101
+ type Namespace$1 = {
102
+ idFromName(name: string): unknown;
103
+ get(id: unknown): Stub$1;
104
+ };
105
+ type ProgressRouteOptions = {
106
+ /** The hub's root secret (the same the Durable Object reads); unset answers 503 to writers. */secret: string | undefined;
107
+ /**
108
+ * May this WebSocket request read the tree (and check nodes off)? The host's
109
+ * own session check — typically "is this the owner". Only called for a
110
+ * socket from an allowed Origin; a throw counts as no.
111
+ */
112
+ reader: (req: Request) => Promise<boolean> | boolean; /** The path (writers POST here and to /grant, /resolve below it; readers open a socket). Default /api/progress. */
113
+ path?: string; /** The Durable Object's name in the namespace. Default "progress". */
114
+ name?: string; /** Origins, besides the request's own, whose pages may open the reader socket (exact match). */
115
+ allowedOrigins?: string[];
116
+ };
117
+ /**
118
+ * Route a request to the progress hub if it is under `path`; null otherwise
119
+ * (so the site's own routes go on). A WebSocket is a reader: from an allowed
120
+ * Origin and only if `reader(req)` says so, marked with
121
+ * PROGRESS_READER_HEADER. Anything else is a writer (progressGate: no
122
+ * Origin, a secret set, a bearer token), forwarded without that header.
123
+ */
124
+ declare function routeProgress(req: Request, ns: Namespace$1, opts: ProgressRouteOptions): Promise<Response | null>;
125
+ //#endregion
126
+ //#region src/hub.d.ts
127
+ /** The owner's chat thread; every other thread is a friend's user id. */
128
+ declare const OWNER_THREAD = "owner";
129
+ /** Who a page belongs to, as the site says (routeChat's `identify`). */
130
+ type Identity = {
131
+ userId: string;
132
+ email: string;
133
+ owner: boolean;
134
+ };
135
+ /** A user id usable as a thread and a storage key: no separators, bounded. */
136
+ declare const isUserId: (v: unknown) => v is string;
137
+ /** A friend who has used the chat (`friend:<userId>`). */
138
+ type FriendRecord = {
139
+ email: string;
140
+ firstSeen: number;
141
+ lastAt: number;
142
+ count: number;
143
+ blocked?: boolean;
144
+ blockedAt?: number;
145
+ };
146
+ type HubOptions = {
147
+ /** Let an eval approval run code on the approved pages (8 hours). Default false. */eval?: boolean; /** Messages a friend may send per window. Default 30. */
148
+ friendChatMax?: number; /** That window. Default 10 minutes. */
149
+ friendWindowMs?: number;
150
+ /**
151
+ * Put the start of each message (80 chars) and of eval code (200) in the
152
+ * Worker logs. Default false: logs keep only lengths, since they hold what
153
+ * the user and their friends wrote.
154
+ */
155
+ logContent?: boolean;
156
+ };
157
+ type Socket = {
158
+ send(data: string): void;
159
+ close(code?: number, reason?: string): void;
160
+ readyState?: number;
161
+ serializeAttachment(v: unknown): void;
162
+ deserializeAttachment(): unknown;
163
+ };
164
+ type Storage = {
165
+ get<T>(key: string): Promise<T | undefined>;
166
+ put(key: string, value: unknown): Promise<void>;
167
+ delete(key: string): Promise<boolean>;
168
+ list<T>(opts: {
169
+ prefix: string;
170
+ reverse?: boolean;
171
+ limit?: number;
172
+ }): Promise<Map<string, T>>;
173
+ };
174
+ type DOState = {
175
+ acceptWebSocket(ws: Socket): void;
176
+ getWebSockets(): Socket[];
177
+ storage: Storage; /** Cloudflare's: holds every event until `fn` is done (used to load state on wake). */
178
+ blockConcurrencyWhile?<T>(fn: () => Promise<T>): Promise<T>;
179
+ };
180
+ /** Who a page is: set by routeChat() from the site's answer, never by the page. */
181
+ declare const IDENTITY_HEADERS: {
182
+ readonly user: "x-liagent-user";
183
+ readonly email: "x-liagent-email";
184
+ readonly owner: "x-liagent-owner";
185
+ };
186
+ /** The agent's client IP, set by routeChat from cf-connecting-ip (never by the client). */
187
+ declare const IP_HEADER = "x-liagent-ip";
188
+ /** The header an agent resumes its chat grant with. */
189
+ declare const TOKEN_HEADER = "x-liagent-token";
190
+ declare const hashToken: (token: string) => Promise<string>;
191
+ /** After the user denies a pairing, that audience takes no new request for this long. */
192
+ declare const PAIR_COOLDOWN_MS = 60000;
193
+ /**
194
+ * At most PAIR_MAX pairing requests per audience and client IP per
195
+ * PAIR_WINDOW_MS, and PAIR_AUDIENCE_MAX per audience from all IPs together
196
+ * (which bounds the prompts the user sees). Keyed by IP too, so a stranger
197
+ * using up their own quota cannot lock the user's agent out. A request waits
198
+ * up to PENDING_MS (2 min), so the window must be longer than PAIR_MAX of
199
+ * those, or re-knocking as each lapses would never hit the cap.
200
+ */
201
+ declare const PAIR_MAX = 3;
202
+ declare const PAIR_AUDIENCE_MAX = 10;
203
+ declare const PAIR_WINDOW_MS: number;
204
+ /** A friend's page may relabel at most once per this long; faster ones are dropped. */
205
+ declare const FRIEND_RELABEL_MS = 1000;
206
+ /** A friend may hold at most this many page sockets at once. */
207
+ declare const FRIEND_MAX_PAGES = 8;
208
+ declare class ChatHub {
209
+ private ctx;
210
+ private now;
211
+ protected opts: Required<HubOptions>;
212
+ /** `{head}` for a log line, only when the hub logs content. */
213
+ private head;
214
+ constructor(ctx: DOState, _env?: unknown, now?: () => number, opts?: HubOptions);
215
+ /**
216
+ * Every stored grant by hash: read once per instance (an evicted hub reads
217
+ * it again), then kept in step with each write. Only the listing of
218
+ * sleeping eval grants uses it; a resume always asks storage itself.
219
+ */
220
+ private grants?;
221
+ /**
222
+ * Pairing requests per (audience, IP) and per audience, to bound the
223
+ * prompts anyone can raise: the window's start and count, and when the
224
+ * user last denied one. Read synchronously from this map, written through
225
+ * to storage (`knock:<key>`), and loaded back when a hub wakes from
226
+ * hibernation (under blockConcurrencyWhile, before any event), so an
227
+ * evicted hub does not forget them. Where the host has no
228
+ * blockConcurrencyWhile they are kept in memory only.
229
+ */
230
+ private knocks;
231
+ private setKnock;
232
+ /** Load the stored counters; drop those whose window and cooldown have both passed. */
233
+ private loadKnocks;
234
+ /**
235
+ * Room for one more pairing request for audience `who` from client `ip`:
236
+ * false (and `ws` closed with 4429) if not. Per (audience, IP): a
237
+ * cooldown after the user denied that IP's request, and PAIR_MAX per
238
+ * window. Per audience: PAIR_AUDIENCE_MAX per window from all IPs. Without
239
+ * an IP (a hub not behind routeChat on Cloudflare), every request shares
240
+ * one key.
241
+ */
242
+ private knockAllowed;
243
+ private loadingGrants?;
244
+ private loadGrants;
245
+ private putGrant;
246
+ private dropGrant;
247
+ /** Open sockets of one role, optionally leaving one out (the one closing). */
248
+ private sockets;
249
+ private pages;
250
+ /**
251
+ * Owner-approved agents still in time. They hear every thread and may `say`
252
+ * to any. A pairing made for a friend is not one.
253
+ */
254
+ private listeners;
255
+ /** What one audience's pages see: its pairings, how many agents listen, its pages. */
256
+ private state;
257
+ /** Send every page its audience's state; `skip` is left out of the sending only. */
258
+ private broadcast;
259
+ private controller;
260
+ /** One thread's kept chat, oldest first. */
261
+ history(thread?: string): Promise<ChatMessage[]>;
262
+ /**
263
+ * Keep one message (dropping its thread's oldest past CHAT_HISTORY) and send
264
+ * it on. An agent's reply in the owner's thread goes live only to the pages
265
+ * of its grant (`only`); every page still gets it in its history.
266
+ */
267
+ private post;
268
+ /**
269
+ * The agent polishes the owner's latest voice line (see "Voice edits"
270
+ * above). Every refusal is an {type:"error"} naming the rule it broke.
271
+ */
272
+ private edit;
273
+ /** The live node grants (`ngrant:`), lapsed ones dropped as they are met. */
274
+ private nodeGrants;
275
+ /** Everyone who has used the chat, most recent first. */
276
+ friends(): Promise<({
277
+ userId: string;
278
+ } & FriendRecord)[]>;
279
+ /** A friend by user id or (any case) email. */
280
+ private findFriend;
281
+ fetch(req: Request): Promise<Response>;
282
+ /**
283
+ * The owner's friends API — route it only from an owner-only path of your
284
+ * own (routeChat never does):
285
+ * GET /internal/friends → {friends}
286
+ * GET /internal/friends/thread?user=id → {messages}
287
+ * POST /internal/friends {userId, action: "block" | "unblock"}
288
+ */
289
+ private friendsApi;
290
+ /** Block (or unblock) a friend: blocking closes their pages and every pairing made for them. */
291
+ block(userId: string, blocked: boolean): Promise<FriendRecord | null>;
292
+ /**
293
+ * A page joins: it gets its own thread's history and its audience's state.
294
+ * A blocked friend is told and closed. With no identity (tests) it is the owner's.
295
+ */
296
+ connectPage(ws: Socket, url: URL, who?: Identity): Promise<void>;
297
+ /**
298
+ * An agent knocks. `?for=<email>` asks a friend's pages for an eval pairing
299
+ * (owner grant and an eval hub only). With just a grant token it is back
300
+ * in chat scope at once. Otherwise it waits for the owner: one pending
301
+ * pairing per audience, and only with a page to ask.
302
+ */
303
+ connectController(ws: Socket, url: URL, token?: string | null, ip?: string): Promise<void>;
304
+ /** Make room for one audience's pairing: false (and `ws` closed) if one is still waiting. */
305
+ private clearPending;
306
+ private knock;
307
+ /** The owner's live grant behind a token, or null (and a lapsed one deleted). */
308
+ private liveGrant;
309
+ /** An eval pairing on one friend's pages: the owner's agent asks, the friend answers. */
310
+ private pairForFriend;
311
+ /** Reconnecting with a grant token: chat scope again, no prompt — or 4498 if it is not live. */
312
+ private resume;
313
+ webSocketMessage(ws: Socket, raw: string | ArrayBuffer): void | Promise<void>;
314
+ private fromPage;
315
+ /**
316
+ * A friend's message: no approval needed, but a blocked friend is closed
317
+ * and more than friendChatMax in a window is dropped (and the page told).
318
+ * Their first ever message tells the agents ({type:"friend-new"}).
319
+ */
320
+ private friendChat;
321
+ /** The pages an Allow names: live ones of the answering page's audience; by default that page. */
322
+ private choosePages;
323
+ /** Whether any live page of `thread` is covered by `pages`. */
324
+ private anyCovered;
325
+ /** Add pages to an approved agent's grant: every socket of it, and the stored grant. */
326
+ private addPages;
327
+ /** A page reports client-side navigation: relabel it, update the lists, tell the agents. */
328
+ private relabel;
329
+ /** A page went away: update the lists, and start the clock on grants it was the last page of. */
330
+ private pageClosed;
331
+ /**
332
+ * Grants whose pages are all closed: note when that began, forget it when
333
+ * a page of theirs is back, and after PAGES_GONE_MS tell the agent to pair
334
+ * again (4409) and drop the grant. Run on every event (no timers).
335
+ */
336
+ private sweep;
337
+ /** End (revoke) a sleeping eval grant, or add the answering page to it. */
338
+ private dormant;
339
+ /**
340
+ * Allow for code. The user's: eval and chat for EVAL_GRANT_MS, with a grant
341
+ * token the agent resumes with (pages and all). A friend's preview: eval
342
+ * only, for APPROVAL_MS, on this socket only — no token. On a hub without
343
+ * eval, an older agent's "8h" answer is an hour of chat on this socket.
344
+ */
345
+ private allowHour;
346
+ /** "Allow chat for 30 days": chat only, with a grant token the agent can resume with. */
347
+ private allowChat;
348
+ /** Deny a pairing, or End a session — and with it the grant behind it, on every socket using it. */
349
+ private end;
350
+ /** Where an agent's `say` goes: the owner's thread, or a friend's by user id or email. */
351
+ private sayTarget;
352
+ /**
353
+ * A node grant: senders within `from` may address nodes within `to`, for
354
+ * `ms` (EVAL_GRANT_MS by default). Only an agent whose node holds both may
355
+ * grant it or take it back; the root's always may.
356
+ */
357
+ private nodeGrant;
358
+ private fromController;
359
+ webSocketClose(ws: Socket, code: number): void | Promise<void>;
360
+ }
361
+ /**
362
+ * A ChatHub class with these options baked in, to export from your Worker as
363
+ * the Durable Object: `export const ChatHub = chatHub({ eval: true })`.
364
+ */
365
+ declare function chatHub(opts?: HubOptions): typeof ChatHub;
366
+ type Stub = {
367
+ fetch(req: Request): Promise<Response>;
368
+ };
369
+ type Namespace = {
370
+ idFromName(name: string): unknown;
371
+ get(id: unknown): Stub;
372
+ };
373
+ type RouteOptions = {
374
+ /** Who this page request is, from the site's own session; null refuses it. */identify: (req: Request) => Promise<Identity | null> | Identity | null; /** The page socket's path. Default /api/chat. */
375
+ pagePath?: string; /** The agent socket's path. Default <pagePath>/control. */
376
+ controlPath?: string; /** The Durable Object's name in the namespace (one hub per name). Default "chat". */
377
+ name?: string;
378
+ /**
379
+ * Origins, besides the request's own, whose pages may open the page socket
380
+ * (e.g. ["https://app.example.com"] when the hub is on api.example.com).
381
+ * Any other Origin is refused before `identify` runs, so a site the user
382
+ * visits cannot ride their cookie into the chat (cross-site WebSocket
383
+ * hijacking). Exact match: scheme, host and port.
384
+ */
385
+ allowedOrigins?: string[];
386
+ };
387
+ /**
388
+ * Whether a page socket's Origin may connect: the request's own origin, or
389
+ * one listed in `allowed`. A request with no Origin is not from a browser
390
+ * page (browsers always send one on a WebSocket), so it can only use
391
+ * credentials it already holds: it goes on to `identify` like any other.
392
+ */
393
+ declare function pageOriginAllowed(req: Request, allowed?: readonly string[]): boolean;
394
+ /**
395
+ * Route a request to the hub if it is one of its two sockets; null otherwise
396
+ * (so the site's own routes go on). Pages are identified by the site and
397
+ * their identity is passed in IDENTITY_HEADERS (any the client sent are
398
+ * dropped). A page socket from a foreign Origin is refused (see
399
+ * `allowedOrigins`); an agent socket is refused if it carries any Origin
400
+ * (a web page).
401
+ */
402
+ declare function routeChat(req: Request, ns: Namespace, opts: RouteOptions): Promise<Response | null>;
403
+ //#endregion
404
+ export { ChatHub, DOState, FRIEND_MAX_PAGES, FRIEND_RELABEL_MS, FriendRecord, GRANT_DEFAULT, GRANT_MAX_MS, HubOptions, IDENTITY_HEADERS, IP_HEADER, Identity, MAX_BODY, OWNER_THREAD, PAIR_AUDIENCE_MAX, PAIR_COOLDOWN_MS, PAIR_MAX, PAIR_WINDOW_MS, PROGRESS_READER_HEADER, ProgressHub, ProgressHubOptions, ProgressRouteOptions, ProgressState, ProgressStorage, RATE, RESOLVED_NOTE, RouteOptions, Socket, Storage, TOKEN_HEADER, chatHub, hashToken, isUserId, pageOriginAllowed, progressGate, progressHub, routeChat, routeProgress };
405
+ //# sourceMappingURL=hub.d.ts.map