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,28 @@
1
+ import { r as ChatBox } from "./box-DloywR57.js";
2
+
3
+ //#region src/client.d.ts
4
+ /** Hidden this long before the socket is dropped. */
5
+ declare const IDLE_MS = 30000;
6
+ type HubOptions = {
7
+ /** The hub's page-socket URL (ws:// or wss://, or a path on this origin). */url: string;
8
+ /**
9
+ * This page's label, shown to agents; default: path + (pwa) + user agent.
10
+ * A function is asked again after each client-side navigation.
11
+ */
12
+ label?: string | (() => string); /** Report client-side navigation to the hub ({type:"page"}). Default true. */
13
+ trackPages?: boolean; /** Run code approved agents send (eval scope). Default false. */
14
+ evalCode?: boolean; /** Whether the socket should be up at all (beyond visibility). Default always. */
15
+ wanted?: () => boolean; /** Each eval result, for the site's own logging. */
16
+ onEval?: (r: {
17
+ id: string;
18
+ ok: boolean;
19
+ } & Record<string, unknown>) => void;
20
+ };
21
+ type HubConnection = {
22
+ /** Re-check visibility and wanted() now (call it when wanted() may have changed). */update(): void;
23
+ close(): void;
24
+ };
25
+ declare function connectHub(box: ChatBox, opts: HubOptions): HubConnection;
26
+ //#endregion
27
+ export { HubConnection, HubOptions, IDLE_MS, connectHub };
28
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,240 @@
1
+ import { PAGE_DEBOUNCE_MS, compile, summarize, trimHistory } from "./protocol.js";
2
+
3
+ //#region src/client.ts
4
+ /** Hidden this long before the socket is dropped. */
5
+ const IDLE_MS = 3e4;
6
+ /** How long the eval icon pulses after code ran. */
7
+ const RAN_MS = 4e3;
8
+ /** This tab's page id, kept for the tab's life so a reconnect keeps its grants. */
9
+ const PAGE_KEY = "liagent:page";
10
+ const readPageId = () => {
11
+ try {
12
+ return sessionStorage.getItem(PAGE_KEY) ?? "";
13
+ } catch {
14
+ return "";
15
+ }
16
+ };
17
+ const savePageId = (id) => {
18
+ try {
19
+ if (id) sessionStorage.setItem(PAGE_KEY, id);
20
+ } catch {}
21
+ };
22
+ function socketUrl(url, label) {
23
+ const u = new URL(url, location.href);
24
+ if (u.protocol === "http:") u.protocol = "ws:";
25
+ if (u.protocol === "https:") u.protocol = "wss:";
26
+ u.searchParams.set("label", label);
27
+ const page = readPageId();
28
+ if (page) u.searchParams.set("page", page);
29
+ return u.toString();
30
+ }
31
+ function connectHub(box, opts) {
32
+ let ws = null;
33
+ let idle;
34
+ let ran;
35
+ let nav;
36
+ const pageLabel = () => {
37
+ if (typeof opts.label === "function") return opts.label();
38
+ if (opts.label) return opts.label;
39
+ const standalone = matchMedia?.("(display-mode: standalone)").matches ? "pwa " : "";
40
+ return `${location.pathname} ${standalone}${navigator.userAgent}`;
41
+ };
42
+ let sentLabel = "";
43
+ let closed = false;
44
+ const opened = /* @__PURE__ */ new WeakSet();
45
+ const wanted = () => !closed && document.visibilityState === "visible" && (opts.wanted?.() ?? true);
46
+ const send = (sock, msg) => {
47
+ if (!sock || sock.readyState !== WebSocket.OPEN) return false;
48
+ try {
49
+ sock.send(JSON.stringify(msg));
50
+ return true;
51
+ } catch {
52
+ return false;
53
+ }
54
+ };
55
+ const run = async (sock, id, to, code) => {
56
+ clearTimeout(ran);
57
+ box.evalRan = true;
58
+ ran = setTimeout(() => box.evalRan = false, RAN_MS);
59
+ const t0 = performance.now();
60
+ let result;
61
+ try {
62
+ const value = await compile(code)();
63
+ result = {
64
+ ok: true,
65
+ ms: Math.round(performance.now() - t0),
66
+ value: summarize(value)
67
+ };
68
+ } catch (e) {
69
+ const err = e instanceof Error ? e : new Error(String(e));
70
+ result = {
71
+ ok: false,
72
+ error: `${err.name}: ${err.message}`.slice(0, 1e3),
73
+ stack: (err.stack ?? "").slice(0, 2e3)
74
+ };
75
+ }
76
+ opts.onEval?.({
77
+ id,
78
+ ...result
79
+ });
80
+ send(sock, {
81
+ type: "result",
82
+ id,
83
+ to,
84
+ ...result
85
+ });
86
+ };
87
+ const reset = () => {
88
+ box.live = false;
89
+ box.pending = null;
90
+ box.sessions = [];
91
+ box.pages = [];
92
+ box.busy = false;
93
+ };
94
+ const connect = () => {
95
+ if (ws) return;
96
+ const label = sentLabel = pageLabel();
97
+ const sock = new WebSocket(socketUrl(opts.url, label));
98
+ ws = sock;
99
+ sock.onopen = () => {
100
+ opened.add(sock);
101
+ box.live = true;
102
+ };
103
+ sock.onmessage = (e) => {
104
+ let msg;
105
+ try {
106
+ msg = JSON.parse(String(e.data));
107
+ } catch {
108
+ return;
109
+ }
110
+ switch (msg.type) {
111
+ case "friend-status":
112
+ box.friend = true;
113
+ box.notice = msg.status === "blocked" ? "Chat is not available for this account." : "";
114
+ return;
115
+ case "rate-limited":
116
+ box.warning = `Too many messages: that one was not sent. Try again in ${Math.max(1, Math.ceil(Number(msg.retryIn) / 6e4) || 1)} min.`;
117
+ return;
118
+ case "state": {
119
+ const s = msg;
120
+ box.pending = s.pending ?? null;
121
+ box.sessions = Array.isArray(s.sessions) ? s.sessions : [];
122
+ box.listeners = s.listeners ?? box.sessions.length;
123
+ box.nodes = Array.isArray(s.nodes) ? s.nodes : [];
124
+ box.pages = Array.isArray(s.pages) ? s.pages : [];
125
+ const self = typeof s.self === "string" ? s.self : "";
126
+ box.self = self;
127
+ savePageId(self);
128
+ return;
129
+ }
130
+ case "busy":
131
+ box.beat();
132
+ return;
133
+ case "history":
134
+ if (Array.isArray(msg.messages)) box.messages = trimHistory(msg.messages);
135
+ return;
136
+ case "chat": {
137
+ const m = msg.message;
138
+ if (!m || typeof m !== "object") return;
139
+ box.push(m);
140
+ if (m.from !== "agent") box.warning = "";
141
+ return;
142
+ }
143
+ case "edited":
144
+ box.edit(msg);
145
+ return;
146
+ case "eval":
147
+ if (!opts.evalCode) return;
148
+ if (typeof msg.id !== "string" || typeof msg.to !== "string") return;
149
+ if (typeof msg.code !== "string") return;
150
+ run(sock, msg.id, msg.to, msg.code);
151
+ return;
152
+ }
153
+ };
154
+ sock.onclose = (e) => {
155
+ if (ws !== sock) return;
156
+ ws = null;
157
+ reset();
158
+ if (opened.has(sock) && e.code < 4e3 && wanted()) connect();
159
+ };
160
+ };
161
+ const disconnect = () => {
162
+ clearTimeout(idle);
163
+ const sock = ws;
164
+ ws = null;
165
+ reset();
166
+ sock?.close();
167
+ };
168
+ const update = () => {
169
+ clearTimeout(idle);
170
+ if (wanted()) connect();
171
+ else if (closed || !(opts.wanted?.() ?? true)) disconnect();
172
+ else if (ws) idle = setTimeout(disconnect, IDLE_MS);
173
+ };
174
+ box.onSend = (text, to, opts) => send(ws, {
175
+ type: "chat",
176
+ id: crypto.randomUUID().slice(0, 12),
177
+ text,
178
+ ...to ? { to } : {},
179
+ ...opts?.source ? { source: opts.source } : {}
180
+ });
181
+ box.onAnswer = (type, p, answer) => void send(ws, type === "deny" ? {
182
+ type,
183
+ pair: p.pair
184
+ } : {
185
+ type,
186
+ pair: p.pair,
187
+ ...answer.pages ? { pages: answer.pages } : {},
188
+ ...answer.scope ? { scope: answer.scope } : {}
189
+ });
190
+ box.onEnd = (p) => void send(ws, {
191
+ type: "revoke",
192
+ pair: p.pair
193
+ });
194
+ box.onEndPage = (id) => void send(ws, {
195
+ type: "end-page",
196
+ id
197
+ });
198
+ const navigated = () => {
199
+ clearTimeout(nav);
200
+ nav = setTimeout(() => {
201
+ const label = pageLabel();
202
+ if (label === sentLabel) return;
203
+ if (send(ws, {
204
+ type: "page",
205
+ label
206
+ })) sentLabel = label;
207
+ }, PAGE_DEBOUNCE_MS);
208
+ };
209
+ const unhook = [];
210
+ if (opts.trackPages !== false) {
211
+ for (const k of ["pushState", "replaceState"]) {
212
+ const orig = history[k];
213
+ history[k] = function(...a) {
214
+ const r = orig.apply(this, a);
215
+ navigated();
216
+ return r;
217
+ };
218
+ unhook.push(() => history[k] = orig);
219
+ }
220
+ addEventListener("popstate", navigated);
221
+ unhook.push(() => removeEventListener("popstate", navigated));
222
+ }
223
+ document.addEventListener("visibilitychange", update);
224
+ update();
225
+ return {
226
+ update,
227
+ close() {
228
+ closed = true;
229
+ document.removeEventListener("visibilitychange", update);
230
+ clearTimeout(ran);
231
+ clearTimeout(nav);
232
+ for (const u of unhook) u();
233
+ disconnect();
234
+ }
235
+ };
236
+ }
237
+
238
+ //#endregion
239
+ export { IDLE_MS, connectHub };
240
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,86 @@
1
+ //#region src/echo.ts
2
+ /**
3
+ * The text-level echo guard: with the
4
+ * mic left open while the agent speaks, what leaks past the browser's echo
5
+ * canceller comes back from STT as the agent's own words. A transcript that
6
+ * closely matches a sentence the agent spoke in the last ECHO_WINDOW_MS is
7
+ * dropped. Pure functions, tested in test/echo-guard.test.ts.
8
+ */
9
+ /** Dropped from this similarity (Dice over character n-grams) to one recent agent sentence. */
10
+ const ECHO_SIMILARITY = .6;
11
+ /** Agent sentences still playing, or ended at most this long before the utterance, count. */
12
+ const ECHO_WINDOW_MS = 1e4;
13
+ /**
14
+ * Shorter transcripts (normalized) are dropped only when they equal a whole
15
+ * sentence: "OK" or "はい" said by the user must not vanish because the
16
+ * agent's sentence contained it.
17
+ */
18
+ const ECHO_MIN_CHARS = 4;
19
+ const CJK = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u;
20
+ /** Case, width, punctuation, symbols and spaces gone: "Hello, World!" → "helloworld". */
21
+ function normalizeEcho(s) {
22
+ return s.normalize("NFKC").toLowerCase().replace(/[\p{P}\p{S}\s]/gu, "");
23
+ }
24
+ /** Character n-grams with counts (the whole string when it is shorter than n). */
25
+ function grams(s, n) {
26
+ const out = /* @__PURE__ */ new Map();
27
+ const chars = [...s];
28
+ if (chars.length && chars.length < n) out.set(s, 1);
29
+ for (let i = 0; i + n <= chars.length; i++) {
30
+ const g = chars.slice(i, i + n).join("");
31
+ out.set(g, (out.get(g) ?? 0) + 1);
32
+ }
33
+ return out;
34
+ }
35
+ /** Dice coefficient of two n-gram bags: 2·|A∩B| / (|A|+|B|), in [0, 1]. */
36
+ function dice(a, b) {
37
+ let na = 0;
38
+ let nb = 0;
39
+ let both = 0;
40
+ for (const c of a.values()) na += c;
41
+ for (const c of b.values()) nb += c;
42
+ for (const [g, c] of a) both += Math.min(c, b.get(g) ?? 0);
43
+ return na + nb ? 2 * both / (na + nb) : 0;
44
+ }
45
+ /**
46
+ * How much `transcript` looks like the agent's own speech: compared with each
47
+ * recent sentence, and each pair of consecutive ones (a transcript can span
48
+ * a sentence break). Bigrams for CJK, trigrams otherwise, after normalizeEcho.
49
+ */
50
+ function echoScore(transcript, spoken) {
51
+ const t = normalizeEcho(transcript);
52
+ const none = {
53
+ score: 0,
54
+ against: null,
55
+ drop: false
56
+ };
57
+ if (!t || !spoken.length) return none;
58
+ const n = CJK.test(t) ? 2 : 3;
59
+ const short = [...t].length < ECHO_MIN_CHARS;
60
+ const cands = [...spoken];
61
+ for (let i = 0; i + 1 < spoken.length; i++) cands.push(`${spoken[i]} ${spoken[i + 1]}`);
62
+ const tg = grams(t, n);
63
+ let best = none;
64
+ for (const c of cands) {
65
+ const nc = normalizeEcho(c);
66
+ if (!nc) continue;
67
+ let score;
68
+ if (nc === t || !short && nc.includes(t)) score = 1;
69
+ else if (short) score = 0;
70
+ else score = dice(tg, grams(nc, n));
71
+ if (score > best.score) best = {
72
+ score,
73
+ against: c,
74
+ drop: false
75
+ };
76
+ }
77
+ return {
78
+ ...best,
79
+ score: Math.round(best.score * 1e3) / 1e3,
80
+ drop: best.score >= ECHO_SIMILARITY
81
+ };
82
+ }
83
+
84
+ //#endregion
85
+ export { echoScore as a, dice as i, ECHO_SIMILARITY as n, grams as o, ECHO_WINDOW_MS as r, normalizeEcho as s, ECHO_MIN_CHARS as t };
86
+ //# sourceMappingURL=echo-BvzPSI0x.js.map
@@ -0,0 +1,38 @@
1
+ //#region src/echo.d.ts
2
+ /**
3
+ * The text-level echo guard: with the
4
+ * mic left open while the agent speaks, what leaks past the browser's echo
5
+ * canceller comes back from STT as the agent's own words. A transcript that
6
+ * closely matches a sentence the agent spoke in the last ECHO_WINDOW_MS is
7
+ * dropped. Pure functions, tested in test/echo-guard.test.ts.
8
+ */
9
+ /** Dropped from this similarity (Dice over character n-grams) to one recent agent sentence. */
10
+ declare const ECHO_SIMILARITY = 0.6;
11
+ /** Agent sentences still playing, or ended at most this long before the utterance, count. */
12
+ declare const ECHO_WINDOW_MS = 10000;
13
+ /**
14
+ * Shorter transcripts (normalized) are dropped only when they equal a whole
15
+ * sentence: "OK" or "はい" said by the user must not vanish because the
16
+ * agent's sentence contained it.
17
+ */
18
+ declare const ECHO_MIN_CHARS = 4;
19
+ /** Case, width, punctuation, symbols and spaces gone: "Hello, World!" → "helloworld". */
20
+ declare function normalizeEcho(s: string): string;
21
+ /** Character n-grams with counts (the whole string when it is shorter than n). */
22
+ declare function grams(s: string, n: number): Map<string, number>;
23
+ /** Dice coefficient of two n-gram bags: 2·|A∩B| / (|A|+|B|), in [0, 1]. */
24
+ declare function dice(a: Map<string, number>, b: Map<string, number>): number;
25
+ type EchoScore = {
26
+ /** 0 … 1: 1 for a substring, else the best Dice similarity. */score: number; /** The agent text it matched best (null when nothing did). */
27
+ against: string | null; /** score ≥ ECHO_SIMILARITY. */
28
+ drop: boolean;
29
+ };
30
+ /**
31
+ * How much `transcript` looks like the agent's own speech: compared with each
32
+ * recent sentence, and each pair of consecutive ones (a transcript can span
33
+ * a sentence break). Bigrams for CJK, trigrams otherwise, after normalizeEcho.
34
+ */
35
+ declare function echoScore(transcript: string, spoken: readonly string[]): EchoScore;
36
+ //#endregion
37
+ export { dice as a, normalizeEcho as c, EchoScore as i, ECHO_SIMILARITY as n, echoScore as o, ECHO_WINDOW_MS as r, grams as s, ECHO_MIN_CHARS as t };
38
+ //# sourceMappingURL=echo-W2RcMEny.d.ts.map