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.
- package/README.md +54 -0
- package/default.config.yaml +5 -5
- package/dist/{JsonlStore-BpYZZTap.js → JsonlStore-CB_0sfdT.js} +5 -4
- package/dist/{SUPPORTED_CLIS-Dq9Lq9WJ.js → SUPPORTED_CLIS-C_1IiOj3.js} +2 -2
- package/dist/SUPPORTED_CLIS-Do3GHAY1.js +12 -0
- package/dist/{agentShare-suB6yPgO.js → agentShare-BvpEm-Fr.js} +10 -9
- package/dist/{askCli-BU3CNCLU.js → askCli-KmMf-3wA.js} +6 -6
- package/dist/{browser-BmxN1Ur9.js → browser-BAFPmEvN.js} +2 -2
- package/dist/{callback-Ctj3_Wxp.js → callback-BiSUhjw7.js} +6 -6
- package/dist/callback-SqLD2mMX.js +17 -0
- package/dist/{callbackCore-DSJWhqAe.js → callbackCore-BZ_10zyc.js} +1 -1
- package/dist/{callbackCore-BesbQ6-Z.js → callbackCore-Deve5pv3.js} +1 -1
- package/dist/{channels-j5nWuzlQ.js → channels-Y36S0ccW.js} +2 -2
- package/dist/cli.js +118 -13
- package/dist/{cmdDsh-2LP0grim.js → cmdDsh-DZ8bLsH7.js} +1 -1
- package/dist/cmdKill-CzSBfWmx.js +116 -0
- package/dist/{cmdPs-wc1j85fi.js → cmdPs-DBt23Qz0.js} +11 -10
- package/dist/{cwdConflictWarn-skQSMwEh.js → cwdConflictWarn-y-epQyOj.js} +21 -5
- package/dist/{cwdPassthroughHint-BUbWMoz0.js → cwdPassthroughHint-CzWh0hrw.js} +1 -1
- package/dist/{expose-Dawq1LxC.js → expose-Bhsn5yUz.js} +2 -2
- package/dist/forceKill-BDqxx4uQ.js +44 -0
- package/dist/{forkNested-CavHyWzA.js → forkNested-3heLs5XC.js} +45 -5
- package/dist/{globalPidIndex-CRB5KtyL.js → globalPidIndex-BsjlId-h.js} +6 -5
- package/dist/{globalPidIndex-BftWlg2V.js → globalPidIndex-uoz8Esqz.js} +2 -2
- package/dist/{hist-Cs0KFSUW.js → hist-DY16wm7g.js} +1 -1
- package/dist/{identity-DA7YI9km.js → identity-C0MxfwI2.js} +1 -1
- package/dist/{identity-Bk-aG_xl.js → identity-Ckav3-Up.js} +1 -1
- package/dist/index.js +7 -7
- package/dist/{initMsg-CcTqFtsp.js → initMsg-BEVDWYnv.js} +1 -1
- package/dist/{initMsg-D9KJnfgC.js → initMsg-GPU52N-j.js} +1 -1
- package/dist/liagent/box-BSIrRRc_.js +2320 -0
- package/dist/liagent/box-DloywR57.d.ts +409 -0
- package/dist/liagent/box.d.ts +3 -0
- package/dist/liagent/box.js +3 -0
- package/dist/liagent/cli.d.ts +1 -0
- package/dist/liagent/cli.js +908 -0
- package/dist/liagent/client.d.ts +28 -0
- package/dist/liagent/client.js +240 -0
- package/dist/liagent/echo-BvzPSI0x.js +86 -0
- package/dist/liagent/echo-W2RcMEny.d.ts +38 -0
- package/dist/liagent/hub.d.ts +405 -0
- package/dist/liagent/hub.js +1831 -0
- package/dist/liagent/index.d.ts +14 -0
- package/dist/liagent/index.js +10 -0
- package/dist/liagent/liagent.js +339 -0
- package/dist/liagent/mic-audio-C3Shud_F.js +754 -0
- package/dist/liagent/mic-audio-DMCWtEI-.d.ts +317 -0
- package/dist/liagent/mic-button-CtZHFBSG.js +651 -0
- package/dist/liagent/mic-button-Y0ioPetQ.d.ts +248 -0
- package/dist/liagent/mic.d.ts +3 -0
- package/dist/liagent/mic.js +4 -0
- package/dist/liagent/progress-CJs08bXb.js +473 -0
- package/dist/liagent/progress-CfE-meHr.d.ts +205 -0
- package/dist/liagent/progress.d.ts +2 -0
- package/dist/liagent/progress.js +3 -0
- package/dist/liagent/protocol.d.ts +324 -0
- package/dist/liagent/protocol.js +504 -0
- package/dist/liagent/speech-rate-DXeJjRTc.js +42 -0
- package/dist/liagent/state-tree-BZCmAknI.js +353 -0
- package/dist/liagent/tree-BrR7NwMf.js +710 -0
- package/dist/liagent/tree-HB9RhX_H.d.ts +295 -0
- package/dist/liagent/tree.d.ts +2 -0
- package/dist/liagent/tree.js +4 -0
- package/dist/liagent/ui-strings-B03le3fh.d.ts +27 -0
- package/dist/liagent/ui-strings-CJIwW5Gf.js +794 -0
- package/dist/liagent/ui.d.ts +394 -0
- package/dist/liagent/ui.js +5 -0
- package/dist/liagent/voice-D7yeS9VM.js +802 -0
- package/dist/liagent/voice-Qo7SCgi8.d.ts +308 -0
- package/dist/liagent/voice.d.ts +3 -0
- package/dist/liagent/voice.js +4 -0
- package/dist/{notifyDaemon-C7GlfJ1E.js → notifyDaemon-DkUB7GV2.js} +10 -9
- package/dist/{openBrowser-1cIo4dJL.js → openBrowser-CQAOIrD6.js} +1 -1
- package/dist/oxmgrService-DlYHmqyI.js +37 -0
- package/dist/oxmgrService-o9L3I6FX.js +3 -0
- package/dist/{parentLink-DoEWVGld.js → parentLink-BcAYcO9L.js} +2 -2
- package/dist/{parentLink-B58V1RVd.js → parentLink-MBUD3oY2.js} +2 -2
- package/dist/{parentPingLoop-C73bbmCE.js → parentPingLoop-DDO592Wh.js} +5 -5
- package/dist/{pidStore-433kvh9D.js → pidStore-C50VPk3E.js} +3 -3
- package/dist/pidStore-COkPjpW8.js +6 -0
- package/dist/{procStats-BvmrBrOs.js → procStats-DwTxj3rs.js} +1 -1
- package/dist/{remotes-MfdV9M8u.js → remotes-BqLoB5GR.js} +2 -2
- package/dist/{remotes-DevcBeLl.js → remotes-BsMGvAay.js} +3 -3
- package/dist/{roomReplyAlias-DFqg_6IU.js → roomReplyAlias-B-v76TA8.js} +3 -3
- package/dist/roomReplyAlias-BzWUBkQy.js +6 -0
- package/dist/{rustBinary-7VK7oLlW.js → rustBinary-BrJ2p8wy.js} +2 -2
- package/dist/{rustBinary-BV4LxMMn.js → rustBinary-vpfpWj1q.js} +2 -2
- package/dist/{schedule-Dp0qkNO1.js → schedule-Bzjhl6-h.js} +15 -44
- package/dist/schedulesCli-CLqieyQZ.js +784 -0
- package/dist/senderAncestry-CVHeKk1Y.js +173 -0
- package/dist/senderAncestry-KhAUPCQs.js +3 -0
- package/dist/{serve-BpOIIOVc.js → serve-XwFYE0cE.js} +67 -69
- package/dist/{serveRust-CbBrcUrg.js → serveRust-BfWkeL6T.js} +31 -4
- package/dist/{setup-DdIBk6Iv.js → setup-D4-s2VZw.js} +5 -5
- package/dist/{share-w5oRbvlj.js → share-CbFetL5H.js} +1 -1
- package/dist/{share-DrS3LYqf.js → share-_TPYAGWC.js} +1 -1
- package/dist/{shareCmd-DDENkBW2.js → shareCmd-DUBsVI3e.js} +10 -10
- package/dist/spawnGate-Dfj9V76w.js +5 -0
- package/dist/{spawnGate-lr3tvA6U.js → spawnGate-Dj_WaS29.js} +3 -3
- package/dist/{subcommands-DxgvDmZX.js → subcommands-B7YZJL8n.js} +471 -307
- package/dist/subcommands-BZPxFgkT.js +15 -0
- package/dist/{systemPathLink-SjUzgSiq.js → systemPathLink-Y3iC7bYV.js} +1 -1
- package/dist/{terminal-C2h7tpe0.js → terminal-13cGj3h6.js} +2 -2
- package/dist/terminal.js +1 -1
- package/dist/{todoAutomation-TTp_Qz9G.js → todoAutomation-CKlrxuZv.js} +2 -2
- package/dist/{todoCli-BWm5nZE0.js → todoCli-CU9vSJSJ.js} +6 -6
- package/dist/{todoIdentity-BvXZKWJI.js → todoIdentity-CzS1e7VL.js} +2 -2
- package/dist/{todoStore-C9RTz0Vs.js → todoStore-msRCEUi1.js} +2 -2
- package/dist/{tray-BeRSozJz.js → tray-CLktEN3G.js} +1 -1
- package/dist/{trayApp-QQjqhDv1.js → trayApp-5_OlvQcz.js} +2 -2
- package/dist/trayApp-DkAPo0m6.js +5 -0
- package/dist/{ts-6LF7f4fx.js → ts-njuddXQz.js} +126 -57
- package/dist/{versionChecker-Bc62HNf6.js → versionChecker-BJycAanp.js} +2 -2
- package/dist/{webrtcLink-va_gAR77.js → webrtcLink-DcvacEci.js} +1 -1
- package/dist/{webrtcLink-SsInrVHU.js → webrtcLink-WxS1nTIs.js} +1 -1
- package/dist/{webrtcRemote-BlGyNZDC.js → webrtcRemote-C3xQyf3u.js} +2 -2
- package/dist/{widget-Crb5zeHL.js → widget-DmRwOlco.js} +3 -3
- package/dist/widgets.js +1 -1
- package/dist/{workspaceConfig-BLWB5Wu9.js → workspaceConfig-DBgsu81B.js} +1 -1
- package/dist/{ws-DIbwNz8Z.js → ws-ByO6JO6m.js} +3 -3
- package/dist/{ws-BRhPG1Vy.js → ws-D0-Jg88z.js} +9 -8
- package/lab/ui/index.html +1 -1
- package/lab/ui/lab/posts/2026-08-11-slack-term-safe-writes.md +1 -1
- package/package.json +73 -8
- package/ts/JsonlStore.ts +10 -3
- package/ts/cli-idle.bun.spec.ts +1 -1
- package/ts/cli-idle.spec.ts +1 -1
- package/ts/cli.ts +35 -0
- package/ts/cmdKill.bun.spec.ts +155 -0
- package/ts/cmdKill.spec.ts +155 -0
- package/ts/cmdKill.ts +183 -0
- package/ts/composerGuard.edges.spec.ts +91 -0
- package/ts/composerGuard.spec.ts +53 -6
- package/ts/composerGuard.ts +42 -13
- package/ts/conptyModeFilter.spec.ts +30 -0
- package/ts/conptyModeFilter.ts +53 -0
- package/ts/copyLiagent.ts +42 -0
- package/ts/cwdConflictWarn.io.spec.ts +50 -0
- package/ts/cwdConflictWarn.spec.ts +34 -1
- package/ts/cwdConflictWarn.ts +43 -5
- package/ts/cwdGuard.spec.ts +110 -0
- package/ts/cwdGuard.ts +118 -0
- package/ts/forceKill.ts +52 -0
- package/ts/forkNested.bun.spec.ts +41 -0
- package/ts/forkNested.spec.ts +41 -0
- package/ts/forkNested.ts +48 -1
- package/ts/globalPidIndex.edges.spec.ts +125 -0
- package/ts/globalPidIndex.ts +6 -2
- package/ts/index.ts +13 -1
- package/ts/interruptSend.bun.spec.ts +99 -0
- package/ts/interruptSend.spec.ts +99 -0
- package/ts/interruptSend.ts +51 -0
- package/ts/lockRegistry.spec.ts +49 -0
- package/ts/lsRenderCache.spec.ts +58 -0
- package/ts/needsInput.edges.spec.ts +23 -0
- package/ts/parseCliArgs.ts +7 -0
- package/ts/pushGatePlan.spec.ts +147 -0
- package/ts/roomReplyAlias.io.spec.ts +81 -0
- package/ts/schedule.ts +5 -1
- package/ts/schedules.bun.spec.ts +397 -0
- package/ts/schedules.spec.ts +397 -0
- package/ts/schedules.ts +517 -0
- package/ts/schedulesCli.ts +386 -0
- package/ts/sendControl.bun.spec.ts +12 -0
- package/ts/senderAncestry.ts +1 -3
- package/ts/serve.ts +22 -33
- package/ts/serveRust.spec.ts +29 -2
- package/ts/serveRust.ts +27 -2
- package/ts/sizeNego.bun.spec.ts +9 -2
- package/ts/sizeNego.spec.ts +9 -2
- package/ts/sizeNego.ts +10 -5
- package/ts/subcommands.spec.ts +348 -9
- package/ts/subcommands.ts +513 -93
- package/ts/suggestAgents.spec.ts +33 -0
- package/ts/terminal/browser.ts +1 -1
- package/ts/todoParse.spec.ts +22 -1
- package/ts/todoParse.ts +19 -0
- package/dist/SUPPORTED_CLIS-ByO5twge.js +0 -12
- package/dist/callback-D7qfh_7p.js +0 -16
- package/dist/pidStore-BRlKRHXY.js +0 -6
- package/dist/roomReplyAlias-DuEkSSDI.js +0 -6
- package/dist/spawnGate-DeQBTX-o.js +0 -5
- package/dist/subcommands-DmiswRy4.js +0 -14
- package/dist/trayApp-C4TAvRvU.js +0 -5
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
//#region src/protocol.ts
|
|
2
|
+
/** Largest `code` accepted, in characters. */
|
|
3
|
+
const MAX_CODE = 16 * 1024;
|
|
4
|
+
/** Largest result summary a page sends back, in characters. */
|
|
5
|
+
const MAX_RESULT = 4e3;
|
|
6
|
+
/** Largest page or controller label, in characters. */
|
|
7
|
+
const MAX_LABEL = 300;
|
|
8
|
+
/** How long the owner has to answer a pairing prompt. */
|
|
9
|
+
const PENDING_MS = 2 * 6e4;
|
|
10
|
+
/** How long a friend's preview approval (eval on their pages, one socket) lasts. */
|
|
11
|
+
const APPROVAL_MS = 60 * 6e4;
|
|
12
|
+
/**
|
|
13
|
+
* How long the user's eval approval lasts — and its resumable grant token: the
|
|
14
|
+
* agent reconnects with it (x-liagent-token) without a new prompt until then,
|
|
15
|
+
* or until End revokes it.
|
|
16
|
+
*/
|
|
17
|
+
const EVAL_GRANT_MS = 480 * 6e4;
|
|
18
|
+
/** How long "Allow chat" lasts — and its resumable grant token. */
|
|
19
|
+
const CHAT_MS = 720 * 60 * 6e4;
|
|
20
|
+
/** Largest chat message (owner's or agent's), in characters. */
|
|
21
|
+
const MAX_CHAT = 4e3;
|
|
22
|
+
/** Chat messages the hub keeps (and sends a page on connect). */
|
|
23
|
+
const CHAT_HISTORY = 200;
|
|
24
|
+
/** A page shows the spinner while the agent's last busy beat is younger than this. */
|
|
25
|
+
const BUSY_MS = 12e3;
|
|
26
|
+
/** A beat this soon after a reply is the tail of the work just answered: ignored. */
|
|
27
|
+
const BUSY_AFTER_REPLY_MS = 1500;
|
|
28
|
+
/**
|
|
29
|
+
* How long an eval grant outlives its pages: if every page it covers stays
|
|
30
|
+
* closed this long, the agent is told to pair again (4409). Shorter gaps —
|
|
31
|
+
* a phone app switch, a reload — keep the grant, since a tab keeps its page id.
|
|
32
|
+
*/
|
|
33
|
+
const PAGES_GONE_MS = 5 * 6e4;
|
|
34
|
+
/** A page id: the tab's own, kept in sessionStorage and sent on reconnect (?page=). */
|
|
35
|
+
const isPageId = (v) => typeof v === "string" && /^[A-Za-z0-9_-]{6,64}$/.test(v);
|
|
36
|
+
/** How long a page waits after client-side navigation before reporting it. */
|
|
37
|
+
const PAGE_DEBOUNCE_MS = 300;
|
|
38
|
+
/** How many times the agent may polish one voice line. */
|
|
39
|
+
const MAX_EDITS = 3;
|
|
40
|
+
/** A message updated by an EditedEvent; any other message is returned as is. */
|
|
41
|
+
function applyEdit(m, e) {
|
|
42
|
+
if (m.id !== e.id || (m.thread ?? "owner") !== e.thread) return m;
|
|
43
|
+
return {
|
|
44
|
+
...m,
|
|
45
|
+
text: e.text,
|
|
46
|
+
raw: e.raw,
|
|
47
|
+
edited: e.edited
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The draft after a transcript landed in it, if the whole draft is still
|
|
52
|
+
* dictation (the draft was empty, or is exactly what dictation left there);
|
|
53
|
+
* null once anything typed is in it.
|
|
54
|
+
*/
|
|
55
|
+
function dictatedDraft(prev, pure, next) {
|
|
56
|
+
return !prev.trim() || prev === pure ? next : null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A line's source as it is sent: "stt" when the draft is exactly what the
|
|
60
|
+
* mic left there (sent as heard, or unchanged); undefined when anything was
|
|
61
|
+
* typed or edited in it.
|
|
62
|
+
*/
|
|
63
|
+
function draftSource(draft, pure) {
|
|
64
|
+
return pure !== null && draft === pure && !!draft.trim() ? "stt" : void 0;
|
|
65
|
+
}
|
|
66
|
+
const str = (v, max) => typeof v === "string" ? v.slice(0, max) : void 0;
|
|
67
|
+
function parse(raw) {
|
|
68
|
+
if (typeof raw !== "string" || raw.length > MAX_CODE + 2048) return null;
|
|
69
|
+
try {
|
|
70
|
+
const v = JSON.parse(raw);
|
|
71
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** A chat message's text: trimmed, non-empty, at most MAX_CHAT characters; else undefined. */
|
|
77
|
+
function chatText(raw) {
|
|
78
|
+
if (typeof raw !== "string") return void 0;
|
|
79
|
+
const t = raw.trim();
|
|
80
|
+
return t && t.length <= MAX_CHAT ? t : void 0;
|
|
81
|
+
}
|
|
82
|
+
/** Validate an agent's message; anything else is an error sent back to it. */
|
|
83
|
+
function parseControllerMessage(raw) {
|
|
84
|
+
const m = parse(raw);
|
|
85
|
+
if (m?.type === "say") {
|
|
86
|
+
const text = chatText(m.text);
|
|
87
|
+
if (!text) return {
|
|
88
|
+
ok: false,
|
|
89
|
+
error: `say needs text of 1–${MAX_CHAT} chars`
|
|
90
|
+
};
|
|
91
|
+
let to = str(m.to, 320)?.trim();
|
|
92
|
+
let node;
|
|
93
|
+
if (to?.startsWith("/") || typeof m.node === "string") {
|
|
94
|
+
node = nodePath(typeof m.node === "string" ? m.node : to);
|
|
95
|
+
if (!node) return {
|
|
96
|
+
ok: false,
|
|
97
|
+
error: `not a node path: ${String(m.node ?? to)}`
|
|
98
|
+
};
|
|
99
|
+
if (to?.startsWith("/")) to = void 0;
|
|
100
|
+
if (node === ROOT_NODE) node = void 0;
|
|
101
|
+
}
|
|
102
|
+
const taskPath = m.taskPath === void 0 ? void 0 : nodePath(m.taskPath);
|
|
103
|
+
if (m.taskPath !== void 0 && !taskPath) return {
|
|
104
|
+
ok: false,
|
|
105
|
+
error: `not a node path: ${String(m.taskPath)}`
|
|
106
|
+
};
|
|
107
|
+
const agentId = agentIdOf(m.agentId);
|
|
108
|
+
const value = {
|
|
109
|
+
type: "say",
|
|
110
|
+
text
|
|
111
|
+
};
|
|
112
|
+
if (to) value.to = to;
|
|
113
|
+
if (node) value.node = node;
|
|
114
|
+
if (taskPath && taskPath !== ROOT_NODE) value.taskPath = taskPath;
|
|
115
|
+
if (agentId) value.agentId = agentId;
|
|
116
|
+
return {
|
|
117
|
+
ok: true,
|
|
118
|
+
value
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (m?.type === "edit") {
|
|
122
|
+
const id = str(m.id, 64)?.trim();
|
|
123
|
+
if (!id) return {
|
|
124
|
+
ok: false,
|
|
125
|
+
error: "edit needs the id of the message to polish"
|
|
126
|
+
};
|
|
127
|
+
const text = chatText(m.text);
|
|
128
|
+
if (!text) return {
|
|
129
|
+
ok: false,
|
|
130
|
+
error: `edit needs text of 1–${MAX_CHAT} chars`
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
ok: true,
|
|
134
|
+
value: {
|
|
135
|
+
type: "edit",
|
|
136
|
+
id,
|
|
137
|
+
text
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (m?.type === "grant" || m?.type === "ungrant") {
|
|
142
|
+
const from = nodePath(m.from);
|
|
143
|
+
const to = nodePath(m.to);
|
|
144
|
+
if (!from || !to) return {
|
|
145
|
+
ok: false,
|
|
146
|
+
error: `${m.type} needs node paths "from" and "to"`
|
|
147
|
+
};
|
|
148
|
+
if (m.type === "ungrant") return {
|
|
149
|
+
ok: true,
|
|
150
|
+
value: {
|
|
151
|
+
type: "ungrant",
|
|
152
|
+
from,
|
|
153
|
+
to
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const ms = typeof m.ms === "number" && m.ms > 0 ? Math.min(m.ms, CHAT_MS) : void 0;
|
|
157
|
+
return {
|
|
158
|
+
ok: true,
|
|
159
|
+
value: ms ? {
|
|
160
|
+
type: "grant",
|
|
161
|
+
from,
|
|
162
|
+
to,
|
|
163
|
+
ms
|
|
164
|
+
} : {
|
|
165
|
+
type: "grant",
|
|
166
|
+
from,
|
|
167
|
+
to
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (m?.type === "busy") {
|
|
172
|
+
const to = str(m.to, 320);
|
|
173
|
+
const value = { type: "busy" };
|
|
174
|
+
if (to) value.to = to;
|
|
175
|
+
if (m.on === false) value.on = false;
|
|
176
|
+
return {
|
|
177
|
+
ok: true,
|
|
178
|
+
value
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (!m || m.type !== "eval") return {
|
|
182
|
+
ok: false,
|
|
183
|
+
error: "expected {\"type\":\"say\",\"text\":\"…\"}, {\"type\":\"eval\",\"code\":\"…\"}, {\"type\":\"edit\",\"id\",\"text\"} or {\"type\":\"grant\",\"from\",\"to\"}"
|
|
184
|
+
};
|
|
185
|
+
if (typeof m.code !== "string" || !m.code.trim()) return {
|
|
186
|
+
ok: false,
|
|
187
|
+
error: "empty code"
|
|
188
|
+
};
|
|
189
|
+
if (m.code.length > MAX_CODE) return {
|
|
190
|
+
ok: false,
|
|
191
|
+
error: `code over ${MAX_CODE} chars`
|
|
192
|
+
};
|
|
193
|
+
const target = str(m.target, MAX_LABEL);
|
|
194
|
+
return {
|
|
195
|
+
ok: true,
|
|
196
|
+
value: target ? {
|
|
197
|
+
type: "eval",
|
|
198
|
+
code: m.code,
|
|
199
|
+
target
|
|
200
|
+
} : {
|
|
201
|
+
type: "eval",
|
|
202
|
+
code: m.code
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/** Validate a page's message; anything else is dropped. */
|
|
207
|
+
function parsePageMessage(raw) {
|
|
208
|
+
const m = parse(raw);
|
|
209
|
+
if (!m) return null;
|
|
210
|
+
if (m.type === "allow") {
|
|
211
|
+
const pair = str(m.pair, 64);
|
|
212
|
+
if (!pair) return null;
|
|
213
|
+
const out = {
|
|
214
|
+
type: "allow",
|
|
215
|
+
pair
|
|
216
|
+
};
|
|
217
|
+
if (m.pages === "all") out.pages = "all";
|
|
218
|
+
else if (Array.isArray(m.pages)) out.pages = m.pages.filter((x) => typeof x === "string" && x.length > 0 && x.length <= 64).slice(0, 64);
|
|
219
|
+
if (m.scope === "chat") out.scope = "chat";
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
if (m.type === "page") {
|
|
223
|
+
const label = typeof m.label === "string" ? m.label.slice(0, MAX_LABEL) : void 0;
|
|
224
|
+
return label ? {
|
|
225
|
+
type: "page",
|
|
226
|
+
label
|
|
227
|
+
} : null;
|
|
228
|
+
}
|
|
229
|
+
if (m.type === "end-page") {
|
|
230
|
+
const id = str(m.id, 64);
|
|
231
|
+
return id ? {
|
|
232
|
+
type: "end-page",
|
|
233
|
+
id
|
|
234
|
+
} : null;
|
|
235
|
+
}
|
|
236
|
+
if (m.type === "deny" || m.type === "revoke") {
|
|
237
|
+
const pair = str(m.pair, 64);
|
|
238
|
+
return pair ? {
|
|
239
|
+
type: m.type,
|
|
240
|
+
pair
|
|
241
|
+
} : null;
|
|
242
|
+
}
|
|
243
|
+
if (m.type === "chat") {
|
|
244
|
+
const id = str(m.id, 64);
|
|
245
|
+
const text = chatText(m.text);
|
|
246
|
+
if (!id || !text) return null;
|
|
247
|
+
const to = nodePath(m.to);
|
|
248
|
+
const out = {
|
|
249
|
+
type: "chat",
|
|
250
|
+
id,
|
|
251
|
+
text
|
|
252
|
+
};
|
|
253
|
+
if (to && to !== ROOT_NODE) out.to = to;
|
|
254
|
+
if (m.source === "stt") out.source = "stt";
|
|
255
|
+
return out;
|
|
256
|
+
}
|
|
257
|
+
if (m.type === "result") {
|
|
258
|
+
const id = str(m.id, 64);
|
|
259
|
+
const to = str(m.to, 64);
|
|
260
|
+
if (!id || !to) return null;
|
|
261
|
+
return {
|
|
262
|
+
type: "result",
|
|
263
|
+
id,
|
|
264
|
+
to,
|
|
265
|
+
ok: m.ok === true,
|
|
266
|
+
value: str(m.value, MAX_RESULT + 64),
|
|
267
|
+
error: str(m.error, 1e3),
|
|
268
|
+
stack: str(m.stack, 2e3),
|
|
269
|
+
ms: typeof m.ms === "number" ? m.ms : void 0
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
/** The newest `max` messages, oldest first. */
|
|
275
|
+
function trimHistory(list, max = CHAT_HISTORY) {
|
|
276
|
+
return list.length > max ? list.slice(list.length - max) : list;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* The language to read a reply in, from its script alone: any kana is
|
|
280
|
+
* Japanese, Hangul Korean, other Han Chinese (zh-CN), and everything else
|
|
281
|
+
* English.
|
|
282
|
+
*/
|
|
283
|
+
function pickLang(text) {
|
|
284
|
+
if (/[\p{Script=Hiragana}\p{Script=Katakana}]/u.test(text)) return "ja-JP";
|
|
285
|
+
if (/\p{Script=Hangul}/u.test(text)) return "ko-KR";
|
|
286
|
+
if (/\p{Script=Han}/u.test(text)) return "zh-CN";
|
|
287
|
+
return "en-US";
|
|
288
|
+
}
|
|
289
|
+
/** An installed voice for `lang`: the exact locale first, then the same language. */
|
|
290
|
+
function pickVoice(voices, lang) {
|
|
291
|
+
const norm = (l) => l.replace(/_/g, "-").toLowerCase();
|
|
292
|
+
const want = norm(lang);
|
|
293
|
+
const base = want.split("-")[0];
|
|
294
|
+
const exact = voices.filter((v) => norm(v.lang) === want);
|
|
295
|
+
const same = voices.filter((v) => norm(v.lang).split("-")[0] === base);
|
|
296
|
+
const pool = exact.length ? exact : same;
|
|
297
|
+
return pool.find((v) => v.default) ?? pool[0];
|
|
298
|
+
}
|
|
299
|
+
/** A label shown to the user: one line, printable, bounded. */
|
|
300
|
+
function cleanLabel(raw, max = MAX_LABEL) {
|
|
301
|
+
return (raw ?? "").replace(/[\u0000-\u001f\u007f]+/g, " ").trim().slice(0, max);
|
|
302
|
+
}
|
|
303
|
+
/** The short code the CLI prints and the prompt shows, so the owner can match them. */
|
|
304
|
+
function shortCode(bytes) {
|
|
305
|
+
return Array.from(bytes.slice(0, 2), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
306
|
+
}
|
|
307
|
+
/** A page's label matches when there is no target, or it contains the target (any case). */
|
|
308
|
+
function matchesTarget(label, target) {
|
|
309
|
+
if (!target) return true;
|
|
310
|
+
return label.toLowerCase().includes(target.toLowerCase());
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* A JSON-serialisable summary of whatever the code returned, at most `max`
|
|
314
|
+
* characters: cycles, functions, DOM nodes, errors, Maps, Sets and BigInts
|
|
315
|
+
* become readable strings instead of throwing.
|
|
316
|
+
*/
|
|
317
|
+
function summarize(value, max = MAX_RESULT) {
|
|
318
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
319
|
+
let out;
|
|
320
|
+
try {
|
|
321
|
+
out = JSON.stringify(value, (_key, v) => {
|
|
322
|
+
if (typeof v === "bigint") return `${v}n`;
|
|
323
|
+
if (typeof v === "function") return `[function ${v.name || "anonymous"}]`;
|
|
324
|
+
if (typeof v === "symbol") return v.toString();
|
|
325
|
+
if (v === void 0) return "[undefined]";
|
|
326
|
+
if (v instanceof Error) return {
|
|
327
|
+
name: v.name,
|
|
328
|
+
message: v.message,
|
|
329
|
+
stack: v.stack
|
|
330
|
+
};
|
|
331
|
+
if (typeof v === "object" && v !== null) {
|
|
332
|
+
const node = v;
|
|
333
|
+
if (typeof node.nodeType === "number") return typeof node.outerHTML === "string" ? node.outerHTML.slice(0, 500) : `[node ${String(node.nodeName)}]`;
|
|
334
|
+
if (seen.has(v)) return "[circular]";
|
|
335
|
+
seen.add(v);
|
|
336
|
+
if (v instanceof Map) return { "[Map]": [...v.entries()] };
|
|
337
|
+
if (v instanceof Set) return { "[Set]": [...v.values()] };
|
|
338
|
+
}
|
|
339
|
+
return v;
|
|
340
|
+
});
|
|
341
|
+
} catch (e) {
|
|
342
|
+
out = `[unserialisable: ${e instanceof Error ? e.message : String(e)}]`;
|
|
343
|
+
}
|
|
344
|
+
out ??= "[undefined]";
|
|
345
|
+
return out.length > max ? `${out.slice(0, max)}…[${out.length - max} more]` : out;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Compile `code` as an async function. An expression (`document.title`) is
|
|
349
|
+
* returned as is; anything else is a function body, so `return x` works and
|
|
350
|
+
* `await` is allowed in both.
|
|
351
|
+
*/
|
|
352
|
+
function compile(code) {
|
|
353
|
+
try {
|
|
354
|
+
return new Function(`return (async () => (\n${code}\n))();`);
|
|
355
|
+
} catch (e) {
|
|
356
|
+
if (!(e instanceof SyntaxError)) throw e;
|
|
357
|
+
return new Function(`return (async () => {\n${code}\n})();`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/** Longest node path kept, in characters ("/words/prefetch"). */
|
|
361
|
+
const MAX_NODE_PATH = 80;
|
|
362
|
+
/** Longest assignee id kept (`agentId`), in characters. */
|
|
363
|
+
const MAX_AGENT_ID = 40;
|
|
364
|
+
/** The main thread's node: the root of the tree. */
|
|
365
|
+
const ROOT_NODE = "/";
|
|
366
|
+
/** One path segment: URL-safe characters only. */
|
|
367
|
+
const SEG = /^[A-Za-z0-9._~-]+$/;
|
|
368
|
+
/**
|
|
369
|
+
* A node path, normalised: trimmed, a leading "/", segments split on "/" or
|
|
370
|
+
* "›" (so "/words › prefetch" and "words/prefetch" are "/words/prefetch"),
|
|
371
|
+
* no empty, "." or ".." segment, at most MAX_NODE_PATH characters, path
|
|
372
|
+
* characters only. Anything else is undefined (never truncated: a cut path
|
|
373
|
+
* would name another node).
|
|
374
|
+
*/
|
|
375
|
+
function nodePath(raw) {
|
|
376
|
+
if (typeof raw !== "string") return void 0;
|
|
377
|
+
const s = raw.trim();
|
|
378
|
+
if (!s || s.length > MAX_NODE_PATH * 2) return void 0;
|
|
379
|
+
const segs = s.split(/\s*[/›]\s*/).filter(Boolean);
|
|
380
|
+
if (segs.some((x) => !SEG.test(x) || x === "." || x === "..")) return void 0;
|
|
381
|
+
const out = `/${segs.join("/")}`;
|
|
382
|
+
return out.length <= MAX_NODE_PATH ? out : void 0;
|
|
383
|
+
}
|
|
384
|
+
/** An assignee id: trimmed, cut to MAX_AGENT_ID, letters, digits and ._@:+- or spaces only. */
|
|
385
|
+
function agentIdOf(raw) {
|
|
386
|
+
if (typeof raw !== "string") return void 0;
|
|
387
|
+
const s = raw.trim().slice(0, MAX_AGENT_ID).trim();
|
|
388
|
+
return /^[\w.@:+ -]+$/.test(s) ? s : void 0;
|
|
389
|
+
}
|
|
390
|
+
/** `p` is `root` or below it. Both are normalised node paths. */
|
|
391
|
+
function isWithin(p, root) {
|
|
392
|
+
return root === ROOT_NODE || p === root || p.startsWith(`${root}/`);
|
|
393
|
+
}
|
|
394
|
+
/** The deepest node both paths are within. */
|
|
395
|
+
function commonAncestor(a, b) {
|
|
396
|
+
const x = a.split("/").filter(Boolean);
|
|
397
|
+
const y = b.split("/").filter(Boolean);
|
|
398
|
+
const out = [];
|
|
399
|
+
for (let i = 0; i < Math.min(x.length, y.length) && x[i] === y[i]; i++) out.push(x[i] ?? "");
|
|
400
|
+
return `/${out.join("/")}`;
|
|
401
|
+
}
|
|
402
|
+
/** How a node path reads in the chat: "/words › prefetch" ("/" stays "/"). */
|
|
403
|
+
function pathLabel(p) {
|
|
404
|
+
const segs = p.split("/").filter(Boolean);
|
|
405
|
+
return segs.length ? `/${segs.join(" › ")}` : ROOT_NODE;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Whether a listener at node `listener` gets a message addressed to `to`
|
|
409
|
+
* (both absent = the root, the main thread, as before node paths):
|
|
410
|
+
* "direct" when it is that node, "observed" when it is an ancestor (the
|
|
411
|
+
* root observes everything), null otherwise (a sibling or a descendant).
|
|
412
|
+
*/
|
|
413
|
+
function routeTo(listener, to) {
|
|
414
|
+
const l = listener ?? ROOT_NODE;
|
|
415
|
+
const p = to ?? ROOT_NODE;
|
|
416
|
+
if (l === p) return "direct";
|
|
417
|
+
return isWithin(p, l) ? "observed" : null;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* May a sender at node `from` address node `to`? Always into its own
|
|
421
|
+
* subtree, always upward (its parent, any ancestor, the root), else only
|
|
422
|
+
* under a live grant covering both. The error names the common ancestor,
|
|
423
|
+
* whose listener (or the root's) may grant it.
|
|
424
|
+
*/
|
|
425
|
+
function mayAddress(from, to, grants = [], now = Date.now()) {
|
|
426
|
+
if (isWithin(to, from)) return {
|
|
427
|
+
ok: true,
|
|
428
|
+
via: "subtree"
|
|
429
|
+
};
|
|
430
|
+
if (isWithin(from, to)) return {
|
|
431
|
+
ok: true,
|
|
432
|
+
via: "upward"
|
|
433
|
+
};
|
|
434
|
+
if (grants.some((g) => g.until > now && isWithin(from, g.from) && isWithin(to, g.to))) return {
|
|
435
|
+
ok: true,
|
|
436
|
+
via: "grant"
|
|
437
|
+
};
|
|
438
|
+
return {
|
|
439
|
+
ok: false,
|
|
440
|
+
error: `out of scope: needs a grant from ${commonAncestor(from, to)}`
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
/** A leading "@<node path> " in a draft: the node it addresses and the text after it. */
|
|
444
|
+
const ADDRESS = /^@(\/?(?:[A-Za-z0-9._~-]+(?:(?:\/|\s*›\s*)[A-Za-z0-9._~-]+)*)?\/?)(?:\s+([\s\S]*))?$/;
|
|
445
|
+
/**
|
|
446
|
+
* A draft that starts with "@/words › prefetch " (or "@/words/prefetch ")
|
|
447
|
+
* addresses that node: `to` and the rest of the text. `complete` is false
|
|
448
|
+
* while the address is still being typed (no space after it yet). Null when
|
|
449
|
+
* the draft is not an address.
|
|
450
|
+
*/
|
|
451
|
+
function parseAddress(draft) {
|
|
452
|
+
if (!draft.startsWith("@/")) return null;
|
|
453
|
+
const m = ADDRESS.exec(draft);
|
|
454
|
+
if (!m) return null;
|
|
455
|
+
const to = nodePath(m[1] || ROOT_NODE);
|
|
456
|
+
if (!to) return null;
|
|
457
|
+
if (m[2] === void 0 || m[2].startsWith("›")) return {
|
|
458
|
+
to,
|
|
459
|
+
text: "",
|
|
460
|
+
complete: false
|
|
461
|
+
};
|
|
462
|
+
return {
|
|
463
|
+
to,
|
|
464
|
+
text: m[2].trim(),
|
|
465
|
+
complete: true
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
/** The node paths offered while typing "@/…": those starting with what is typed, shortest first. */
|
|
469
|
+
function completeNode(partial, nodes) {
|
|
470
|
+
const typed = partial.replace(/^@/, "").replace(/\s*›\s*/g, "/").trim().toLowerCase();
|
|
471
|
+
return [...new Set(nodes)].filter((n) => n !== ROOT_NODE && n.toLowerCase().startsWith(typed || "/")).sort((a, b) => a.length - b.length || a.localeCompare(b)).slice(0, 8);
|
|
472
|
+
}
|
|
473
|
+
/** A node's hue (0–359), from its path: the log line's left border. */
|
|
474
|
+
function nodeHue(p) {
|
|
475
|
+
let h = 2166136261;
|
|
476
|
+
const s = `node:${p}`;
|
|
477
|
+
for (let i = 0; i < s.length; i++) {
|
|
478
|
+
h ^= s.charCodeAt(i);
|
|
479
|
+
h = Math.imul(h, 16777619);
|
|
480
|
+
}
|
|
481
|
+
return (h >>> 0) % 360;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* What a log line shows about nodes: the node it belongs to (an agent's
|
|
485
|
+
* `taskPath`, else the owner's target `to`), the muted subtitle ("/words ›
|
|
486
|
+
* prefetch", "→ /words › prefetch", or "/a › b → /c" for agent→agent), and
|
|
487
|
+
* its left-border colour. Nothing for a main-thread line without a node.
|
|
488
|
+
*/
|
|
489
|
+
function lineNode(m) {
|
|
490
|
+
const from = m.from === "agent" && m.taskPath && m.taskPath !== ROOT_NODE ? m.taskPath : "";
|
|
491
|
+
const to = m.to && m.to !== ROOT_NODE ? m.to : "";
|
|
492
|
+
if (!from && !to) return null;
|
|
493
|
+
const subtitle = from ? to ? `${pathLabel(from)} → ${pathLabel(to)}` : pathLabel(from) : `→ ${pathLabel(to)}`;
|
|
494
|
+
const node = from || to;
|
|
495
|
+
return {
|
|
496
|
+
node,
|
|
497
|
+
subtitle,
|
|
498
|
+
border: `oklch(0.7 0.09 ${nodeHue(node)})`
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
//#endregion
|
|
503
|
+
export { APPROVAL_MS, BUSY_AFTER_REPLY_MS, BUSY_MS, CHAT_HISTORY, CHAT_MS, EVAL_GRANT_MS, MAX_AGENT_ID, MAX_CHAT, MAX_CODE, MAX_EDITS, MAX_LABEL, MAX_NODE_PATH, MAX_RESULT, PAGES_GONE_MS, PAGE_DEBOUNCE_MS, PENDING_MS, ROOT_NODE, agentIdOf, applyEdit, chatText, cleanLabel, commonAncestor, compile, completeNode, dictatedDraft, draftSource, isPageId, isWithin, lineNode, matchesTarget, mayAddress, nodeHue, nodePath, parseAddress, parseControllerMessage, parsePageMessage, pathLabel, pickLang, pickVoice, routeTo, shortCode, summarize, trimHistory };
|
|
504
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/speech-rate.ts
|
|
2
|
+
/**
|
|
3
|
+
* How fast the agent's replies are read aloud: a per-device setting
|
|
4
|
+
* (localStorage `liagent:speech-rate`), picked in the chat's menu. Applied
|
|
5
|
+
* from the next utterance, on both outputs (the speech utterance's rate, or a cloud
|
|
6
|
+
* voice's playbackRate with the pitch kept).
|
|
7
|
+
*/
|
|
8
|
+
const SPEECH_RATE_KEY = "liagent:speech-rate";
|
|
9
|
+
const SPEECH_RATES = [
|
|
10
|
+
1,
|
|
11
|
+
1.25,
|
|
12
|
+
1.5,
|
|
13
|
+
2
|
|
14
|
+
];
|
|
15
|
+
const DEFAULT_SPEECH_RATE = 1.5;
|
|
16
|
+
const store = () => {
|
|
17
|
+
try {
|
|
18
|
+
return globalThis.localStorage ?? null;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/** The saved rate, if it is one of SPEECH_RATES; else the default. */
|
|
24
|
+
function speechRate(s = store()) {
|
|
25
|
+
let raw = null;
|
|
26
|
+
try {
|
|
27
|
+
raw = s?.getItem(SPEECH_RATE_KEY) ?? null;
|
|
28
|
+
} catch {}
|
|
29
|
+
const n = Number(raw);
|
|
30
|
+
return raw !== null && SPEECH_RATES.includes(n) ? n : DEFAULT_SPEECH_RATE;
|
|
31
|
+
}
|
|
32
|
+
/** Save a rate (one of SPEECH_RATES; anything else is ignored). */
|
|
33
|
+
function setSpeechRate(rate, s = store()) {
|
|
34
|
+
if (!SPEECH_RATES.includes(rate)) return;
|
|
35
|
+
try {
|
|
36
|
+
s?.setItem(SPEECH_RATE_KEY, String(rate));
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { speechRate as a, setSpeechRate as i, SPEECH_RATES as n, SPEECH_RATE_KEY as r, DEFAULT_SPEECH_RATE as t };
|
|
42
|
+
//# sourceMappingURL=speech-rate-DXeJjRTc.js.map
|