@screenreader-speech-capture/bridge 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +1056 -783
- package/dist/ui/adapter-node.js +1 -1
- package/dist/ui/client/ui/_app/immutable/chunks/BEImj5AP.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BEImj5AP.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BEImj5AP.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BLbj0ykL.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BLbj0ykL.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BLbj0ykL.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/B__KpOuX.js +3 -0
- package/dist/ui/client/ui/_app/immutable/chunks/B__KpOuX.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/B__KpOuX.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BkoDSEOx.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BkoDSEOx.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BkoDSEOx.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BlC5mir6.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BlC5mir6.js.br +2 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BlC5mir6.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BquQTeuV.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BquQTeuV.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BquQTeuV.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BtnuBvK5.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BtnuBvK5.js.br +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BtnuBvK5.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/{Dk73DTz3.js → BuwZGWCm.js} +21 -21
- package/dist/ui/client/ui/_app/immutable/chunks/BuwZGWCm.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/BuwZGWCm.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Bxh3K0TK.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Bxh3K0TK.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Bxh3K0TK.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/C06IiL6m.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/C06IiL6m.js.br +2 -0
- package/dist/ui/client/ui/_app/immutable/chunks/C06IiL6m.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/{hhZsYtkz.js → CAZ56n62.js} +3 -3
- package/dist/ui/client/ui/_app/immutable/chunks/CAZ56n62.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/CAZ56n62.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/CTnnxqUD.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/CTnnxqUD.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/CTnnxqUD.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DRNNJMYk.js +5 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DRNNJMYk.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DRNNJMYk.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/JsC3ASJq.js +3 -0
- package/dist/ui/client/ui/_app/immutable/chunks/JsC3ASJq.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/JsC3ASJq.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/{DU8ibkb0.js → OAsMjdHF.js} +13 -13
- package/dist/ui/client/ui/_app/immutable/chunks/OAsMjdHF.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/OAsMjdHF.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/R_4U_-zb.js +33 -0
- package/dist/ui/client/ui/_app/immutable/chunks/R_4U_-zb.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/R_4U_-zb.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/UKukklIc.js +1 -0
- package/dist/ui/client/ui/_app/immutable/chunks/UKukklIc.js.br +2 -0
- package/dist/ui/client/ui/_app/immutable/chunks/UKukklIc.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/{DoG5cwE3.js → VxDST09k.js} +1 -1
- package/dist/ui/client/ui/_app/immutable/chunks/VxDST09k.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/VxDST09k.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/{CEGGem4o.js → vPs9G1oN.js} +36 -36
- package/dist/ui/client/ui/_app/immutable/chunks/vPs9G1oN.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/vPs9G1oN.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/{Bq3k_s8n.js → w5i9ZoX_.js} +2 -2
- package/dist/ui/client/ui/_app/immutable/chunks/w5i9ZoX_.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/w5i9ZoX_.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/entry/app.CHExvln1.js +2 -0
- package/dist/ui/client/ui/_app/immutable/entry/app.CHExvln1.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/entry/app.CHExvln1.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/entry/start.4hiWLKwq.js +2 -0
- package/dist/ui/client/ui/_app/immutable/entry/start.4hiWLKwq.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/entry/start.4hiWLKwq.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/0.DENUQERM.js +1 -0
- package/dist/ui/client/ui/_app/immutable/nodes/0.DENUQERM.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/0.DENUQERM.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/1.BBl7b45u.js +1 -0
- package/dist/ui/client/ui/_app/immutable/nodes/1.BBl7b45u.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/1.BBl7b45u.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/2.4VpydhMh.js +1 -0
- package/dist/ui/client/ui/_app/immutable/nodes/2.4VpydhMh.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/2.4VpydhMh.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/3.D9AmPYb5.js +5 -0
- package/dist/ui/client/ui/_app/immutable/nodes/3.D9AmPYb5.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/3.D9AmPYb5.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/4.DxNIrNp_.js +180 -0
- package/dist/ui/client/ui/_app/immutable/nodes/4.DxNIrNp_.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/4.DxNIrNp_.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/5.Cm6I95kb.js +6 -0
- package/dist/ui/client/ui/_app/immutable/nodes/5.Cm6I95kb.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/5.Cm6I95kb.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/6.D9jpgBJB.js +6 -0
- package/dist/ui/client/ui/_app/immutable/nodes/6.D9jpgBJB.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/6.D9jpgBJB.js.gz +0 -0
- package/dist/ui/client/ui/_app/version.json +1 -1
- package/dist/ui/client/ui/_app/version.json.br +0 -0
- package/dist/ui/client/ui/_app/version.json.gz +0 -0
- package/dist/ui/server/.vite/manifest.json +68 -36
- package/dist/ui/server/chunks/{composition.js → app-context.js} +5 -965
- package/dist/ui/server/chunks/app-context.js.map +1 -0
- package/dist/ui/server/chunks/config2.js +106 -0
- package/dist/ui/server/chunks/config2.js.map +1 -0
- package/dist/ui/server/chunks/dialog.js +1 -1
- package/dist/ui/server/chunks/instance.js +3 -3
- package/dist/ui/server/chunks/internal.js +1 -1
- package/dist/ui/server/chunks/outlined-button.js +1 -1
- package/dist/ui/server/chunks/outlined-text-field.js +1 -1
- package/dist/ui/server/chunks/redispatch-event.js +1 -1
- package/dist/ui/server/chunks/rolldown-runtime.js +12 -0
- package/dist/ui/server/chunks/rules.js +178 -0
- package/dist/ui/server/chunks/rules.js.map +1 -0
- package/dist/ui/server/chunks/sessions.remote.js +1 -11
- package/dist/ui/server/chunks/sessions.remote.js.map +1 -1
- package/dist/ui/server/chunks/setup.js +86 -0
- package/dist/ui/server/chunks/setup.js.map +1 -0
- package/dist/ui/server/chunks/{icon-button.js → speech.js} +42 -3
- package/dist/ui/server/chunks/speech.js.map +1 -0
- package/dist/ui/server/chunks/src.js +20 -155
- package/dist/ui/server/chunks/src.js.map +1 -1
- package/dist/ui/server/chunks/static-html.js +1 -1
- package/dist/ui/server/chunks/text-button.js +1 -1
- package/dist/ui/server/chunks/vocabulary.js +19 -0
- package/dist/ui/server/chunks/vocabulary.js.map +1 -0
- package/dist/ui/server/entries/endpoints/api/config/_server.ts.js +3 -2
- package/dist/ui/server/entries/endpoints/api/config/_server.ts.js.map +1 -1
- package/dist/ui/server/entries/endpoints/api/input/keys/_server.ts.js +14 -5
- package/dist/ui/server/entries/endpoints/api/input/keys/_server.ts.js.map +1 -1
- package/dist/ui/server/entries/endpoints/api/markers/_server.ts.js +3 -2
- package/dist/ui/server/entries/endpoints/api/markers/_server.ts.js.map +1 -1
- package/dist/ui/server/entries/endpoints/api/sessions/_server.ts.js +2 -1
- package/dist/ui/server/entries/endpoints/api/sessions/_server.ts.js.map +1 -1
- package/dist/ui/server/entries/endpoints/api/speech/_server.ts.js +10 -13
- package/dist/ui/server/entries/endpoints/api/speech/_server.ts.js.map +1 -1
- package/dist/ui/server/entries/endpoints/api/status/_server.ts.js +2 -1
- package/dist/ui/server/entries/endpoints/api/status/_server.ts.js.map +1 -1
- package/dist/ui/server/entries/hooks.server.js +29 -25
- package/dist/ui/server/entries/hooks.server.js.map +1 -1
- package/dist/ui/server/entries/pages/_layout.svelte.js +749 -3
- package/dist/ui/server/entries/pages/_layout.svelte.js.map +1 -1
- package/dist/ui/server/entries/pages/_page.svelte.js +34 -25
- package/dist/ui/server/entries/pages/_page.svelte.js.map +1 -1
- package/dist/ui/server/entries/pages/settings/_page.svelte.js +5 -3
- package/dist/ui/server/entries/pages/settings/_page.svelte.js.map +1 -1
- package/dist/ui/server/entries/pages/setup/_page.svelte.js +2 -1
- package/dist/ui/server/entries/pages/setup/_page.svelte.js.map +1 -1
- package/dist/ui/server/entries/pages/setup/instructions/_page.svelte.js +3 -2
- package/dist/ui/server/entries/pages/setup/instructions/_page.svelte.js.map +1 -1
- package/dist/ui/server/manifest-full.js +1 -1
- package/dist/ui/server/manifest.js +1 -1
- package/dist/ui/server/nodes/0.js +1 -1
- package/dist/ui/server/nodes/1.js +1 -1
- package/dist/ui/server/nodes/2.js +1 -1
- package/dist/ui/server/nodes/3.js +1 -1
- package/dist/ui/server/nodes/4.js +1 -1
- package/dist/ui/server/nodes/5.js +1 -1
- package/dist/ui/server/nodes/6.js +1 -1
- package/dist/ui/server/server.js +1 -1
- package/package.json +1 -1
- package/dist/ui/client/ui/_app/immutable/chunks/0FroJ-XN.js +0 -3
- package/dist/ui/client/ui/_app/immutable/chunks/0FroJ-XN.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/0FroJ-XN.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/B_ZElYu_.js +0 -1
- package/dist/ui/client/ui/_app/immutable/chunks/B_ZElYu_.js.br +0 -2
- package/dist/ui/client/ui/_app/immutable/chunks/B_ZElYu_.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Bq3k_s8n.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Bq3k_s8n.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/CEGGem4o.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/CEGGem4o.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/CVpgcnu3.js +0 -1
- package/dist/ui/client/ui/_app/immutable/chunks/CVpgcnu3.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/CVpgcnu3.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Cwz551Q0.js +0 -5
- package/dist/ui/client/ui/_app/immutable/chunks/Cwz551Q0.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Cwz551Q0.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/D-2Nx62w.js +0 -1
- package/dist/ui/client/ui/_app/immutable/chunks/D-2Nx62w.js.br +0 -4
- package/dist/ui/client/ui/_app/immutable/chunks/D-2Nx62w.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DHsTyp2W.js +0 -1
- package/dist/ui/client/ui/_app/immutable/chunks/DHsTyp2W.js.br +0 -2
- package/dist/ui/client/ui/_app/immutable/chunks/DHsTyp2W.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DJvJc_zO.js +0 -33
- package/dist/ui/client/ui/_app/immutable/chunks/DJvJc_zO.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DJvJc_zO.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DU8ibkb0.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DU8ibkb0.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Dk73DTz3.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Dk73DTz3.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DoG5cwE3.js.br +0 -3
- package/dist/ui/client/ui/_app/immutable/chunks/DoG5cwE3.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Dvxhfd7j.js +0 -3
- package/dist/ui/client/ui/_app/immutable/chunks/Dvxhfd7j.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/Dvxhfd7j.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/DzInmTUe.js +0 -1
- package/dist/ui/client/ui/_app/immutable/chunks/DzInmTUe.js.br +0 -1
- package/dist/ui/client/ui/_app/immutable/chunks/DzInmTUe.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/hhZsYtkz.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/chunks/hhZsYtkz.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/entry/app.Bic9wlww.js +0 -2
- package/dist/ui/client/ui/_app/immutable/entry/app.Bic9wlww.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/entry/app.Bic9wlww.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/entry/start.DqIv9xYX.js +0 -2
- package/dist/ui/client/ui/_app/immutable/entry/start.DqIv9xYX.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/entry/start.DqIv9xYX.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/0.IqK6bsxB.js +0 -1
- package/dist/ui/client/ui/_app/immutable/nodes/0.IqK6bsxB.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/0.IqK6bsxB.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/1.C81neQJL.js +0 -1
- package/dist/ui/client/ui/_app/immutable/nodes/1.C81neQJL.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/1.C81neQJL.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/2.CmlyeAx_.js +0 -1
- package/dist/ui/client/ui/_app/immutable/nodes/2.CmlyeAx_.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/2.CmlyeAx_.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/3.DYZ3H5TS.js +0 -5
- package/dist/ui/client/ui/_app/immutable/nodes/3.DYZ3H5TS.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/3.DYZ3H5TS.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/4.Lwlmq1AY.js +0 -180
- package/dist/ui/client/ui/_app/immutable/nodes/4.Lwlmq1AY.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/4.Lwlmq1AY.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/5.rBMVkFpN.js +0 -6
- package/dist/ui/client/ui/_app/immutable/nodes/5.rBMVkFpN.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/5.rBMVkFpN.js.gz +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/6.nui9awM2.js +0 -6
- package/dist/ui/client/ui/_app/immutable/nodes/6.nui9awM2.js.br +0 -0
- package/dist/ui/client/ui/_app/immutable/nodes/6.nui9awM2.js.gz +0 -0
- package/dist/ui/server/chunks/composition.js.map +0 -1
- package/dist/ui/server/chunks/icon-button.js.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import os, { hostname } from "node:os";
|
|
|
5
5
|
import http from "node:http";
|
|
6
6
|
import net from "node:net";
|
|
7
7
|
import { finished, pipeline } from "node:stream";
|
|
8
|
-
import { setImmediate
|
|
8
|
+
import { setImmediate } from "node:timers/promises";
|
|
9
9
|
import fs, { existsSync, readFileSync } from "node:fs";
|
|
10
10
|
import { TextDecoder as TextDecoder$1, parseArgs } from "node:util";
|
|
11
11
|
import fs$1, { mkdir, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
@@ -15,7 +15,7 @@ import { execFile, spawn, spawnSync } from "node:child_process";
|
|
|
15
15
|
import readline from "node:readline";
|
|
16
16
|
import { createInterface } from "node:readline/promises";
|
|
17
17
|
// package.json
|
|
18
|
-
var version = "0.2.
|
|
18
|
+
var version = "0.2.1";
|
|
19
19
|
// ../shared/src/api-version.ts
|
|
20
20
|
/**
|
|
21
21
|
* `<major>.<minor>` of the HTTP API. Minor versions only add things, with the exceptions in
|
|
@@ -957,6 +957,33 @@ const FocusRequestSchema = /* @__PURE__ */ pipe(/* @__PURE__ */ strictObject({
|
|
|
957
957
|
* chords with this rule, and the CLI checks them before sending and lists the names in `--help`,
|
|
958
958
|
* so both use this one copy. Like `text-match.ts`, it belongs to the contract, not to either side.
|
|
959
959
|
*/
|
|
960
|
+
const DIGITS = [
|
|
961
|
+
"0",
|
|
962
|
+
"1",
|
|
963
|
+
"2",
|
|
964
|
+
"3",
|
|
965
|
+
"4",
|
|
966
|
+
"5",
|
|
967
|
+
"6",
|
|
968
|
+
"7",
|
|
969
|
+
"8",
|
|
970
|
+
"9"
|
|
971
|
+
];
|
|
972
|
+
const FUNCTION_KEYS = [
|
|
973
|
+
"f1",
|
|
974
|
+
"f2",
|
|
975
|
+
"f3",
|
|
976
|
+
"f4",
|
|
977
|
+
"f5",
|
|
978
|
+
"f6",
|
|
979
|
+
"f7",
|
|
980
|
+
"f8",
|
|
981
|
+
"f9",
|
|
982
|
+
"f10",
|
|
983
|
+
"f11",
|
|
984
|
+
"f12"
|
|
985
|
+
];
|
|
986
|
+
const LETTERS = "abcdefghijklmnopqrstuvwxyz".split("");
|
|
960
987
|
/** Keys that can be held down while another key is pressed. `Insert` and `CapsLock` are the screen reader keys. */
|
|
961
988
|
const MODIFIER_KEYS = [
|
|
962
989
|
"control",
|
|
@@ -971,7 +998,7 @@ const MODIFIER_KEYS = [
|
|
|
971
998
|
* reading commands. With NumLock off they are those commands, with NumLock on they type.
|
|
972
999
|
*/
|
|
973
1000
|
const NUMPAD_KEYS = [
|
|
974
|
-
...
|
|
1001
|
+
...DIGITS.map((digit) => `numpad${digit}`),
|
|
975
1002
|
"numpadplus",
|
|
976
1003
|
"numpadminus",
|
|
977
1004
|
"numpadmultiply",
|
|
@@ -995,7 +1022,7 @@ const NAMED_KEYS = [
|
|
|
995
1022
|
"end",
|
|
996
1023
|
"pageup",
|
|
997
1024
|
"pagedown",
|
|
998
|
-
...
|
|
1025
|
+
...FUNCTION_KEYS,
|
|
999
1026
|
...NUMPAD_KEYS
|
|
1000
1027
|
];
|
|
1001
1028
|
/** Aliases accepted in a chord, by their lower-case spelling. */
|
|
@@ -1014,8 +1041,10 @@ const KEY_ALIASES = {
|
|
|
1014
1041
|
const KEYS = /* @__PURE__ */ new Set([
|
|
1015
1042
|
...MODIFIER_KEYS,
|
|
1016
1043
|
...NAMED_KEYS,
|
|
1017
|
-
...
|
|
1044
|
+
...LETTERS,
|
|
1045
|
+
...DIGITS
|
|
1018
1046
|
]);
|
|
1047
|
+
const isKeyName = (name) => KEYS.has(name);
|
|
1019
1048
|
const MODIFIER_SET = new Set(MODIFIER_KEYS);
|
|
1020
1049
|
/**
|
|
1021
1050
|
* Parses `Insert+T` or `Control+Shift+Home`: modifiers and one last key, joined with `+`, names
|
|
@@ -1027,7 +1056,7 @@ function parseKeyChord$1(chord) {
|
|
|
1027
1056
|
for (const part of chord.split("+")) {
|
|
1028
1057
|
const lower = part.trim().toLowerCase();
|
|
1029
1058
|
const name = KEY_ALIASES[lower] ?? lower;
|
|
1030
|
-
if (!
|
|
1059
|
+
if (!isKeyName(name)) return {
|
|
1031
1060
|
ok: false,
|
|
1032
1061
|
message: `unknown key "${part.trim()}" in "${chord}"`
|
|
1033
1062
|
};
|
|
@@ -1051,6 +1080,14 @@ function parseKeyChord$1(chord) {
|
|
|
1051
1080
|
}
|
|
1052
1081
|
};
|
|
1053
1082
|
}
|
|
1083
|
+
// ../shared/src/rules/run-seq.ts
|
|
1084
|
+
/**
|
|
1085
|
+
* The first `seq` of a bridge run: its start time (`bridge.startedAt`) in milliseconds, so `seq`
|
|
1086
|
+
* keeps rising across restarts and a client can tell a position of an earlier run
|
|
1087
|
+
* (docs/implementation/decisions.md#seq-keeps-rising-across-restarts). The bridge numbers by it,
|
|
1088
|
+
* the client reads by it.
|
|
1089
|
+
*/
|
|
1090
|
+
const firstSeqOfRun = (startedAtMs) => startedAtMs;
|
|
1054
1091
|
// ../shared/src/rules/service-paths.ts
|
|
1055
1092
|
/** The Playwright server (`connectOptions.wsEndpoint`): `ws://<bridge>:5151/playwright`. */
|
|
1056
1093
|
const PLAYWRIGHT_PATH = "/playwright";
|
|
@@ -1110,6 +1147,20 @@ const StartSessionRequestSchema = /* @__PURE__ */ strictObject({
|
|
|
1110
1147
|
* one client ends or replaces another one's session. Optional. API 1.10.
|
|
1111
1148
|
*/
|
|
1112
1149
|
const CLIENT_HEADER = "x-sr-speech-client";
|
|
1150
|
+
// ../shared/src/ui-host.ts
|
|
1151
|
+
/** The environment variable the UI's BFF reads the bridge's address from. */
|
|
1152
|
+
const BRIDGE_API_URL_ENV = "SR_BRIDGE_API_URL";
|
|
1153
|
+
/**
|
|
1154
|
+
* The header that tells the UI its page is opened from the bridge's own machine, where the screen
|
|
1155
|
+
* reader would read the live log and feed it back (docs/usage/web-ui.md#accessibility-of-the-ui-itself).
|
|
1156
|
+
* The bridge sets (`1`) or removes it on every request, so a client can't send it.
|
|
1157
|
+
*/
|
|
1158
|
+
const LOCAL_HEADER = "x-sr-bridge-local";
|
|
1159
|
+
/**
|
|
1160
|
+
* Where the UI's server code finds the bridge log: a `Symbol.for` key on `globalThis`. Its lines
|
|
1161
|
+
* get the `[web-ui]` prefix, go to the log file and never block on the console.
|
|
1162
|
+
*/
|
|
1163
|
+
const UI_LOGGER_KEY = Symbol.for("screenreader-speech-capture.ui-logger");
|
|
1113
1164
|
// ../shared/src/validate.ts
|
|
1114
1165
|
/**
|
|
1115
1166
|
* Checks `value` against `schema`. Unknown keys of an answer don't fail it and are left out of the
|
|
@@ -1247,21 +1298,74 @@ var AppError = class extends Error {
|
|
|
1247
1298
|
function invalidField(field, message) {
|
|
1248
1299
|
return new AppError("INVALID_REQUEST", `${field}: ${message}`, { field });
|
|
1249
1300
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1301
|
+
// src/adapters/in/http/response.ts
|
|
1302
|
+
function sendJson(res, status, body) {
|
|
1303
|
+
const data = JSON.stringify(body);
|
|
1304
|
+
res.writeHead(status, {
|
|
1305
|
+
"content-type": "application/json; charset=utf-8",
|
|
1306
|
+
"content-length": Buffer.byteLength(data)
|
|
1307
|
+
});
|
|
1308
|
+
res.end(data);
|
|
1309
|
+
}
|
|
1310
|
+
function sendNoContent(res) {
|
|
1311
|
+
res.writeHead(204).end();
|
|
1312
|
+
}
|
|
1313
|
+
// src/adapters/in/http/errors.ts
|
|
1314
|
+
/** A request refused for where it comes from: `FORBIDDEN`. */
|
|
1315
|
+
var AccessDeniedError = class extends Error {
|
|
1316
|
+
details;
|
|
1317
|
+
name = "AccessDeniedError";
|
|
1318
|
+
code = "FORBIDDEN";
|
|
1319
|
+
constructor(message, details) {
|
|
1260
1320
|
super(message);
|
|
1261
|
-
this.
|
|
1262
|
-
this.reason = reason;
|
|
1321
|
+
this.details = details;
|
|
1263
1322
|
}
|
|
1264
1323
|
};
|
|
1324
|
+
/**
|
|
1325
|
+
* The error body every endpoint uses (docs/usage/http-api.md#errors) and its status. An `AppError`
|
|
1326
|
+
* or `AccessDeniedError` keeps its code. Anything else is `INTERNAL`, with the details in the bridge log only.
|
|
1327
|
+
*/
|
|
1328
|
+
function errorResponse(error, logger) {
|
|
1329
|
+
let body;
|
|
1330
|
+
if (error instanceof AppError || error instanceof AccessDeniedError) {
|
|
1331
|
+
body = { error: {
|
|
1332
|
+
code: error.code,
|
|
1333
|
+
message: error.message
|
|
1334
|
+
} };
|
|
1335
|
+
if (error.details !== void 0) body.error.details = error.details;
|
|
1336
|
+
} else {
|
|
1337
|
+
logger.error(`internal error: ${error instanceof Error ? error.stack ?? error.message : String(error)}`);
|
|
1338
|
+
body = { error: {
|
|
1339
|
+
code: "INTERNAL",
|
|
1340
|
+
message: "Internal error, see the bridge log"
|
|
1341
|
+
} };
|
|
1342
|
+
}
|
|
1343
|
+
return {
|
|
1344
|
+
status: ERROR_STATUS[body.error.code],
|
|
1345
|
+
body
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
/** Sends the error body every endpoint uses (docs/usage/http-api.md#errors). */
|
|
1349
|
+
function sendError(res, error, logger) {
|
|
1350
|
+
const { status, body } = errorResponse(error, logger);
|
|
1351
|
+
if (res.headersSent) {
|
|
1352
|
+
res.destroy();
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
sendJson(res, status, body);
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* The same answer on the raw socket of a WebSocket upgrade, which has no `ServerResponse`, then
|
|
1359
|
+
* closes it.
|
|
1360
|
+
*/
|
|
1361
|
+
function sendSocketError(socket, error, logger) {
|
|
1362
|
+
const { status, body } = errorResponse(error, logger);
|
|
1363
|
+
const data = JSON.stringify(body);
|
|
1364
|
+
socket.end(`HTTP/1.1 ${status} ${http.STATUS_CODES[status] ?? "Error"}\r\ncontent-type: application/json; charset=utf-8\r
|
|
1365
|
+
content-length: ${Buffer.byteLength(data)}\r\nconnection: close\r
|
|
1366
|
+
\r
|
|
1367
|
+
` + data);
|
|
1368
|
+
}
|
|
1265
1369
|
// src/adapters/in/http/access.ts
|
|
1266
1370
|
/** Methods that don't change anything. Other methods with a foreign `Origin` are refused. */
|
|
1267
1371
|
const SAFE_METHODS = /* @__PURE__ */ new Set([
|
|
@@ -1269,20 +1373,23 @@ const SAFE_METHODS = /* @__PURE__ */ new Set([
|
|
|
1269
1373
|
"HEAD",
|
|
1270
1374
|
"OPTIONS"
|
|
1271
1375
|
]);
|
|
1376
|
+
/** `Sec-Fetch-Site` values of a request the user made on the bridge's own page or address bar. */
|
|
1377
|
+
const OWN_FETCH_SITES = /* @__PURE__ */ new Set(["same-origin", "none"]);
|
|
1272
1378
|
/**
|
|
1273
|
-
* Throws `
|
|
1274
|
-
*
|
|
1275
|
-
* page could open a WebSocket or read an event stream (docs/usage/security.md#host-and-origin).
|
|
1379
|
+
* Throws an `AccessDeniedError` if the request comes through a foreign host name or from a foreign page
|
|
1380
|
+
* (docs/usage/security.md#host-and-origin).
|
|
1276
1381
|
*/
|
|
1277
|
-
function checkAccess(req, rules, { strictOrigin = false } = {}) {
|
|
1382
|
+
function checkAccess(req, rules, { strictOrigin = false, crossSite = "allow" } = {}) {
|
|
1278
1383
|
const host = (req.headers.host ?? "").toLowerCase();
|
|
1279
1384
|
const hostname = hostnameOf(host);
|
|
1280
|
-
if (hostname === void 0) throw new
|
|
1281
|
-
if (!hostAllowed(hostname, rules)) throw new
|
|
1385
|
+
if (hostname === void 0) throw new AccessDeniedError("The request has no valid Host header");
|
|
1386
|
+
if (!hostAllowed(hostname, rules)) throw new AccessDeniedError(`Host "${hostname}" is not allowed. Use the bridge's IP address, or add the name to http.allowedHosts (--allowed-hosts)`, { host: hostname });
|
|
1387
|
+
const fetchSite = req.headers["sec-fetch-site"];
|
|
1388
|
+
if (crossSite === "refuse" && fetchSite !== void 0 && !OWN_FETCH_SITES.has(fetchSite)) throw new AccessDeniedError("Requests from another site are not allowed", { fetchSite });
|
|
1282
1389
|
const origin = req.headers.origin;
|
|
1283
1390
|
if (origin === void 0) return;
|
|
1284
1391
|
if (!strictOrigin && SAFE_METHODS.has(req.method ?? "GET")) return;
|
|
1285
|
-
if (origin.toLowerCase() !== `http://${host}`) throw new
|
|
1392
|
+
if (origin.toLowerCase() !== `http://${host}`) throw new AccessDeniedError(`Requests from origin "${origin}" are not allowed`, { origin });
|
|
1286
1393
|
}
|
|
1287
1394
|
/** The host name in a `Host` header (`name:port`, `[::1]:port`), `undefined` if it isn't one. */
|
|
1288
1395
|
function hostnameOf(host) {
|
|
@@ -1306,6 +1413,22 @@ function hostAllowed(hostname, { allowedHosts, ownHostnames }) {
|
|
|
1306
1413
|
function ownNames(hostnames) {
|
|
1307
1414
|
return hostnames.flatMap((name) => [name, name.split(".")[0]]).filter((name) => name !== "");
|
|
1308
1415
|
}
|
|
1416
|
+
// src/application/ports/out/listener.ts
|
|
1417
|
+
/**
|
|
1418
|
+
* A listener can't use its port: something else listens on it (`EADDRINUSE`), or the system
|
|
1419
|
+
* doesn't allow it (`EACCES`, for example a port in a Windows excluded port range). Startup may
|
|
1420
|
+
* ask for another TCP port then (docs/implementation/tcp-capture.md#listening-and-connections).
|
|
1421
|
+
*/
|
|
1422
|
+
var PortUnavailableError = class extends Error {
|
|
1423
|
+
port;
|
|
1424
|
+
reason;
|
|
1425
|
+
name = "PortUnavailableError";
|
|
1426
|
+
constructor(message, port, reason) {
|
|
1427
|
+
super(message);
|
|
1428
|
+
this.port = port;
|
|
1429
|
+
this.reason = reason;
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1309
1432
|
// src/adapters/shared/net/listen.ts
|
|
1310
1433
|
/**
|
|
1311
1434
|
* Thrown when a listener can't start for another reason than its port being unavailable (for
|
|
@@ -1404,121 +1527,13 @@ function describeListener(scheme, host, port, path = "", interfaces = os.network
|
|
|
1404
1527
|
const urls = reachableUrls(scheme, host, port, interfaces).map((url) => `${url}${path}`).join(", ");
|
|
1405
1528
|
return isWildcard(host) ? `${hostPort(host, port)}, reachable at ${urls}` : urls;
|
|
1406
1529
|
}
|
|
1407
|
-
// src/adapters/
|
|
1408
|
-
function sendJson(res, status, body) {
|
|
1409
|
-
const data = JSON.stringify(body);
|
|
1410
|
-
res.writeHead(status, {
|
|
1411
|
-
"content-type": "application/json; charset=utf-8",
|
|
1412
|
-
"content-length": Buffer.byteLength(data)
|
|
1413
|
-
});
|
|
1414
|
-
res.end(data);
|
|
1415
|
-
}
|
|
1416
|
-
function sendNoContent(res) {
|
|
1417
|
-
res.writeHead(204).end();
|
|
1418
|
-
}
|
|
1419
|
-
// src/adapters/in/http/errors.ts
|
|
1420
|
-
/**
|
|
1421
|
-
* The error body every endpoint uses (docs/usage/http-api.md#errors) and its status. An `AppError`
|
|
1422
|
-
* keeps its code. Anything else is `INTERNAL`, with the details in the bridge log only.
|
|
1423
|
-
*/
|
|
1424
|
-
function errorResponse(error, logger) {
|
|
1425
|
-
let body;
|
|
1426
|
-
if (error instanceof AppError) {
|
|
1427
|
-
body = { error: {
|
|
1428
|
-
code: error.code,
|
|
1429
|
-
message: error.message
|
|
1430
|
-
} };
|
|
1431
|
-
if (error.details !== void 0) body.error.details = error.details;
|
|
1432
|
-
} else {
|
|
1433
|
-
logger.error(`internal error: ${error instanceof Error ? error.stack ?? error.message : String(error)}`);
|
|
1434
|
-
body = { error: {
|
|
1435
|
-
code: "INTERNAL",
|
|
1436
|
-
message: "Internal error, see the bridge log"
|
|
1437
|
-
} };
|
|
1438
|
-
}
|
|
1439
|
-
return {
|
|
1440
|
-
status: ERROR_STATUS[body.error.code],
|
|
1441
|
-
body
|
|
1442
|
-
};
|
|
1443
|
-
}
|
|
1444
|
-
/** Sends the error body every endpoint uses (docs/usage/http-api.md#errors). */
|
|
1445
|
-
function sendError(res, error, logger) {
|
|
1446
|
-
const { status, body } = errorResponse(error, logger);
|
|
1447
|
-
if (res.headersSent) {
|
|
1448
|
-
res.destroy();
|
|
1449
|
-
return;
|
|
1450
|
-
}
|
|
1451
|
-
sendJson(res, status, body);
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* The same answer on the raw socket of a WebSocket upgrade, which has no `ServerResponse`, then
|
|
1455
|
-
* closes it.
|
|
1456
|
-
*/
|
|
1457
|
-
function sendSocketError(socket, error, logger) {
|
|
1458
|
-
const { status, body } = errorResponse(error, logger);
|
|
1459
|
-
const data = JSON.stringify(body);
|
|
1460
|
-
socket.end(`HTTP/1.1 ${status} ${http.STATUS_CODES[status] ?? "Error"}\r\ncontent-type: application/json; charset=utf-8\r
|
|
1461
|
-
content-length: ${Buffer.byteLength(data)}\r\nconnection: close\r
|
|
1462
|
-
\r
|
|
1463
|
-
` + data);
|
|
1464
|
-
}
|
|
1465
|
-
// src/domain/child-service.ts
|
|
1466
|
-
const SERVICE_NAMES = ["playwright", "mcp"];
|
|
1467
|
-
/** How the services are named in log lines and errors. */
|
|
1468
|
-
const SERVICE_TITLES = {
|
|
1469
|
-
playwright: "Playwright server",
|
|
1470
|
-
mcp: "Playwright MCP"
|
|
1471
|
-
};
|
|
1530
|
+
// src/adapters/shared/net/child-host.ts
|
|
1472
1531
|
/**
|
|
1473
1532
|
* Where the child services listen: loopback only. Clients reach them through the bridge's HTTP
|
|
1474
1533
|
* port, which checks Host and Origin for them like for the API
|
|
1475
1534
|
* (docs/implementation/decisions.md#the-bridge-is-the-single-way-in).
|
|
1476
1535
|
*/
|
|
1477
1536
|
const CHILD_HOST = "127.0.0.1";
|
|
1478
|
-
/** A service's settings from the config: the Playwright server in the configured version, MCP in the bundled one. */
|
|
1479
|
-
function serviceSettings(name, config) {
|
|
1480
|
-
if (name === "playwright") {
|
|
1481
|
-
const { port, version } = config.playwright;
|
|
1482
|
-
return {
|
|
1483
|
-
host: CHILD_HOST,
|
|
1484
|
-
port,
|
|
1485
|
-
version
|
|
1486
|
-
};
|
|
1487
|
-
}
|
|
1488
|
-
return {
|
|
1489
|
-
host: CHILD_HOST,
|
|
1490
|
-
port: config.mcp.port,
|
|
1491
|
-
version: null
|
|
1492
|
-
};
|
|
1493
|
-
}
|
|
1494
|
-
function reachability(name, status, enabled) {
|
|
1495
|
-
if (status.state === "running") return { port: status.port };
|
|
1496
|
-
const title = SERVICE_TITLES[name];
|
|
1497
|
-
if (!enabled) return { unavailable: `${title} is disabled` };
|
|
1498
|
-
return { unavailable: `${title} is not running (state: ${status.state})` };
|
|
1499
|
-
}
|
|
1500
|
-
const RESTART_POLICY = {
|
|
1501
|
-
baseDelayMs: 1e3,
|
|
1502
|
-
maxDelayMs: 3e4,
|
|
1503
|
-
stableMs: 6e4,
|
|
1504
|
-
maxCrashesInRow: 5
|
|
1505
|
-
};
|
|
1506
|
-
/**
|
|
1507
|
-
* What to do after a crash. `crashesInRow` counts the crashes before this one, `ranForMs` is how
|
|
1508
|
-
* long the service ran before it crashed.
|
|
1509
|
-
*/
|
|
1510
|
-
function nextAfterCrash(crashesInRow, ranForMs, policy = RESTART_POLICY) {
|
|
1511
|
-
const streak = (ranForMs >= policy.stableMs ? 0 : crashesInRow) + 1;
|
|
1512
|
-
if (streak >= policy.maxCrashesInRow) return {
|
|
1513
|
-
action: "fail",
|
|
1514
|
-
crashesInRow: streak
|
|
1515
|
-
};
|
|
1516
|
-
return {
|
|
1517
|
-
action: "restart",
|
|
1518
|
-
crashesInRow: streak,
|
|
1519
|
-
delayMs: Math.min(policy.baseDelayMs * 2 ** (streak - 1), policy.maxDelayMs)
|
|
1520
|
-
};
|
|
1521
|
-
}
|
|
1522
1537
|
// src/adapters/in/http/proxy/service-proxy.ts
|
|
1523
1538
|
/** Headers that belong to one connection and are not passed on (RFC 9110, 7.6.1). */
|
|
1524
1539
|
const HOP_BY_HOP = /* @__PURE__ */ new Set([
|
|
@@ -1958,6 +1973,36 @@ function toWaitResultDto(result) {
|
|
|
1958
1973
|
};
|
|
1959
1974
|
}
|
|
1960
1975
|
// src/adapters/in/http/dto/input.ts
|
|
1976
|
+
function toFocusRequest({ target, title }) {
|
|
1977
|
+
return {
|
|
1978
|
+
target,
|
|
1979
|
+
title
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
function toClickRequest({ x, y, button }) {
|
|
1983
|
+
return {
|
|
1984
|
+
x,
|
|
1985
|
+
y,
|
|
1986
|
+
button
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
function toPressKeysRequest(dto) {
|
|
1990
|
+
const { keys, delayMs, expectedTarget } = dto;
|
|
1991
|
+
return {
|
|
1992
|
+
keys,
|
|
1993
|
+
delayMs,
|
|
1994
|
+
expectedTarget
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
function toCaptureOptions(dto) {
|
|
1998
|
+
const { quietForMs, firstWithinMs, timeoutMs, settleMs } = dto;
|
|
1999
|
+
return {
|
|
2000
|
+
quietForMs,
|
|
2001
|
+
firstWithinMs,
|
|
2002
|
+
timeoutMs,
|
|
2003
|
+
settleMs
|
|
2004
|
+
};
|
|
2005
|
+
}
|
|
1961
2006
|
function toInputResultDto({ window }) {
|
|
1962
2007
|
if (window === void 0) return {};
|
|
1963
2008
|
return { window: window && {
|
|
@@ -2031,7 +2076,7 @@ function answer(exchange, capture, send, record) {
|
|
|
2031
2076
|
function inputRoutes(router, deps) {
|
|
2032
2077
|
const { input, captures, focus, logger } = deps;
|
|
2033
2078
|
router.add("POST", "/input/focus", { body: FocusRequestSchema }, async ({ req, res, body }) => {
|
|
2034
|
-
const request = typedBody(FocusRequestSchema, body);
|
|
2079
|
+
const request = toFocusRequest(typedBody(FocusRequestSchema, body));
|
|
2035
2080
|
await whileConnected({
|
|
2036
2081
|
req,
|
|
2037
2082
|
res,
|
|
@@ -2041,23 +2086,25 @@ function inputRoutes(router, deps) {
|
|
|
2041
2086
|
signal
|
|
2042
2087
|
}), (focused) => sendJson(res, 200, toFocusedWindowDto(focused)));
|
|
2043
2088
|
}).add("POST", "/input/click", { body: ClickRequestSchema }, async ({ req, res, body }) => {
|
|
2044
|
-
const
|
|
2089
|
+
const dto = typedBody(ClickRequestSchema, body);
|
|
2090
|
+
const request = toClickRequest(dto);
|
|
2045
2091
|
await answer({
|
|
2046
2092
|
req,
|
|
2047
2093
|
res,
|
|
2048
2094
|
logger
|
|
2049
|
-
}, capture, (signal) => input.click(request, { signal }), (capture, signal) => captures.click({
|
|
2095
|
+
}, dto.capture && toCaptureOptions(dto.capture), (signal) => input.click(request, { signal }), (capture, signal) => captures.click({
|
|
2050
2096
|
...request,
|
|
2051
2097
|
capture,
|
|
2052
2098
|
signal
|
|
2053
2099
|
}));
|
|
2054
2100
|
}).add("POST", "/input/keys", { body: KeysRequestSchema }, async ({ req, res, body }) => {
|
|
2055
|
-
const
|
|
2101
|
+
const dto = typedBody(KeysRequestSchema, body);
|
|
2102
|
+
const request = toPressKeysRequest(dto);
|
|
2056
2103
|
await answer({
|
|
2057
2104
|
req,
|
|
2058
2105
|
res,
|
|
2059
2106
|
logger
|
|
2060
|
-
}, capture, (signal) => input.pressKeys(request, { signal }), (capture, signal) => captures.pressKeys({
|
|
2107
|
+
}, dto.capture && toCaptureOptions(dto.capture), (signal) => input.pressKeys(request, { signal }), (capture, signal) => captures.pressKeys({
|
|
2061
2108
|
...request,
|
|
2062
2109
|
capture,
|
|
2063
2110
|
signal
|
|
@@ -2121,6 +2168,14 @@ function sessionRoutes(router, { sessions }) {
|
|
|
2121
2168
|
sendJson(res, 200, toSessionListDto(sessions.list()));
|
|
2122
2169
|
});
|
|
2123
2170
|
}
|
|
2171
|
+
// src/adapters/in/http/dto/stream.ts
|
|
2172
|
+
function toPositionEventDto() {
|
|
2173
|
+
return {};
|
|
2174
|
+
}
|
|
2175
|
+
/** `sessionId` is left out when everything was cleared. */
|
|
2176
|
+
function toClearEventDto(sessionId) {
|
|
2177
|
+
return sessionId === void 0 ? {} : { sessionId };
|
|
2178
|
+
}
|
|
2124
2179
|
// src/adapters/in/http/sse/sse-frames.ts
|
|
2125
2180
|
/**
|
|
2126
2181
|
* Frames already built, by the entry or session they show. Every open stream gets the same
|
|
@@ -2143,9 +2198,9 @@ function sseFrame(event) {
|
|
|
2143
2198
|
const data = JSON.stringify(toSpeechEntryDto(event.entry));
|
|
2144
2199
|
return `id: ${event.entry.seq}\nevent: entry\ndata: ${data}\n\n`;
|
|
2145
2200
|
});
|
|
2146
|
-
case "position": return `id: ${event.seq}\nevent: position\ndata: {}\n\n`;
|
|
2201
|
+
case "position": return `id: ${event.seq}\nevent: position\ndata: ${JSON.stringify(toPositionEventDto())}\n\n`;
|
|
2147
2202
|
case "session": return cached(event.session, () => `event: session\ndata: ${JSON.stringify(toSessionDto(event.session))}\n\n`);
|
|
2148
|
-
case "clear": return
|
|
2203
|
+
case "clear": return `event: clear\ndata: ${JSON.stringify(toClearEventDto(event.sessionId))}\n\n`;
|
|
2149
2204
|
default: return `event: ${event.type}\ndata: {}\n\n`;
|
|
2150
2205
|
}
|
|
2151
2206
|
}
|
|
@@ -2180,11 +2235,9 @@ function speechRoutes(router, deps) {
|
|
|
2180
2235
|
const label = stringParam(url, "label");
|
|
2181
2236
|
if (label === void 0) throw invalidField("label", "is required");
|
|
2182
2237
|
sendJson(res, 200, toLatestMarkerDto(speech.latestMarker(label, sessionParam(url))));
|
|
2183
|
-
}).add("GET", "/speech/wait", { query: WAIT_QUERY }, async ({ res, url }) => {
|
|
2184
|
-
const
|
|
2185
|
-
|
|
2186
|
-
if (!res.writableEnded) controller.abort();
|
|
2187
|
-
});
|
|
2238
|
+
}).add("GET", "/speech/wait", { query: WAIT_QUERY }, async ({ req, res, url }) => {
|
|
2239
|
+
const signal = hangUpSignal(req, res);
|
|
2240
|
+
signal.addEventListener("abort", () => logger.debug("speech wait: the client hung up before the answer"), { once: true });
|
|
2188
2241
|
let result;
|
|
2189
2242
|
try {
|
|
2190
2243
|
result = await waits.wait({
|
|
@@ -2194,10 +2247,10 @@ function speechRoutes(router, deps) {
|
|
|
2194
2247
|
since: intParam(url, "since"),
|
|
2195
2248
|
timeoutMs: intParam(url, "timeoutMs"),
|
|
2196
2249
|
session: sessionParam(url),
|
|
2197
|
-
signal
|
|
2250
|
+
signal
|
|
2198
2251
|
});
|
|
2199
2252
|
} catch (error) {
|
|
2200
|
-
if (
|
|
2253
|
+
if (signal.aborted) return;
|
|
2201
2254
|
throw error;
|
|
2202
2255
|
}
|
|
2203
2256
|
sendJson(res, 200, toWaitResultDto(result));
|
|
@@ -2431,7 +2484,11 @@ var HttpServer = class {
|
|
|
2431
2484
|
path = url.pathname;
|
|
2432
2485
|
if (isApiPath(url.pathname)) res.setHeader(API_VERSION_HEADER, API_VERSION);
|
|
2433
2486
|
const route = this.proxy.match(url.pathname);
|
|
2434
|
-
|
|
2487
|
+
const api = route !== void 0 || isApiPath(url.pathname);
|
|
2488
|
+
this.checkAccess(req, {
|
|
2489
|
+
strictOrigin: route !== void 0,
|
|
2490
|
+
crossSite: api ? "refuse" : "allow"
|
|
2491
|
+
});
|
|
2435
2492
|
if (route) this.proxy.forward(route, req, res, url);
|
|
2436
2493
|
else if (this.deps.ui && !isApiPath(url.pathname)) await this.deps.ui(req, res);
|
|
2437
2494
|
else await this.router.find(method, url.pathname)({
|
|
@@ -2454,7 +2511,10 @@ var HttpServer = class {
|
|
|
2454
2511
|
const url = parseUrl(req.url);
|
|
2455
2512
|
const route = this.proxy.match(url.pathname);
|
|
2456
2513
|
if (route?.scheme !== "ws") throw new AppError("NOT_FOUND", `No WebSocket endpoint at ${url.pathname}`);
|
|
2457
|
-
this.checkAccess(req,
|
|
2514
|
+
this.checkAccess(req, {
|
|
2515
|
+
strictOrigin: true,
|
|
2516
|
+
crossSite: "refuse"
|
|
2517
|
+
});
|
|
2458
2518
|
this.deps.logger.debug(`upgrade ${url.pathname} → ${route.name}`);
|
|
2459
2519
|
this.proxy.upgrade(route, req, socket, head, url);
|
|
2460
2520
|
} catch (error) {
|
|
@@ -2463,13 +2523,14 @@ var HttpServer = class {
|
|
|
2463
2523
|
}
|
|
2464
2524
|
/**
|
|
2465
2525
|
* Host and origin rules (docs/usage/security.md#host-and-origin). The services refuse a foreign
|
|
2466
|
-
* origin for every method: a page could open a WebSocket or read an event stream.
|
|
2526
|
+
* origin for every method: a page could open a WebSocket or read an event stream. The API and
|
|
2527
|
+
* the services refuse what a browser sends for another site's page; the web UI doesn't.
|
|
2467
2528
|
*/
|
|
2468
|
-
checkAccess(req,
|
|
2529
|
+
checkAccess(req, options) {
|
|
2469
2530
|
checkAccess(req, {
|
|
2470
2531
|
allowedHosts: this.allowedHosts,
|
|
2471
2532
|
ownHostnames: this.deps.hostnames ?? []
|
|
2472
|
-
},
|
|
2533
|
+
}, options);
|
|
2473
2534
|
}
|
|
2474
2535
|
};
|
|
2475
2536
|
/** Whether `pathname` is the API's (`/api/v1`, `/api/v1/…`). An unknown one is an API 404. */
|
|
@@ -2485,22 +2546,13 @@ function parseUrl(target) {
|
|
|
2485
2546
|
}
|
|
2486
2547
|
}
|
|
2487
2548
|
// src/adapters/in/http/ui-mount.ts
|
|
2488
|
-
/** The environment variable the UI's BFF reads the bridge's address from. */
|
|
2489
|
-
const BRIDGE_API_URL_ENV = "SR_BRIDGE_API_URL";
|
|
2490
2549
|
/** The header adapter-node reads the request's protocol from (`PROTOCOL_HEADER`). */
|
|
2491
2550
|
const PROTOCOL_HEADER = "x-sr-bridge-protocol";
|
|
2492
2551
|
/**
|
|
2493
|
-
* The
|
|
2494
|
-
*
|
|
2495
|
-
* Set (`1`) or removed on every request, so a client can't send it.
|
|
2496
|
-
*/
|
|
2497
|
-
const LOCAL_HEADER = "x-sr-bridge-local";
|
|
2498
|
-
/**
|
|
2499
|
-
* Where the UI's server code finds the bridge log (`packages/ui/src/lib/server/log.ts` reads it):
|
|
2500
|
-
* a `Symbol.for` key on `globalThis`, because the bridge and the UI don't import each other. Its
|
|
2501
|
-
* lines then get the `[web-ui]` prefix, go to the log file and never block on the console.
|
|
2552
|
+
* The variables {@link UiMount.mount} sets for the UI. Child services don't inherit them
|
|
2553
|
+
* (`adapters/out/process`).
|
|
2502
2554
|
*/
|
|
2503
|
-
const
|
|
2555
|
+
const UI_ENV_NAMES = [BRIDGE_API_URL_ENV, "PROTOCOL_HEADER"];
|
|
2504
2556
|
/**
|
|
2505
2557
|
* The UI shipped in `dir` (`handler.js` of the `adapter-node` build). `undefined` when there is
|
|
2506
2558
|
* none: the bridge runs from source, or the package was built without the UI.
|
|
@@ -2705,7 +2757,8 @@ var TcpListener = class {
|
|
|
2705
2757
|
line: (text) => this.recordSpeech.record({
|
|
2706
2758
|
text,
|
|
2707
2759
|
voice,
|
|
2708
|
-
connectionId: id
|
|
2760
|
+
connectionId: id,
|
|
2761
|
+
source: "tcp"
|
|
2709
2762
|
}),
|
|
2710
2763
|
lineCut: (max) => this.logger.warn(`connection ${id}: line longer than ${max} bytes, cut it`)
|
|
2711
2764
|
});
|
|
@@ -3189,20 +3242,24 @@ function linkSignals(...signals) {
|
|
|
3189
3242
|
// src/application/services/bridge-lifecycle-service.ts
|
|
3190
3243
|
/**
|
|
3191
3244
|
* The bridge's state from `starting` over `ready` to `stopping`, and the order of startup and
|
|
3192
|
-
* shutdown.
|
|
3245
|
+
* shutdown. `GET /status` reads the state through {@link state}.
|
|
3193
3246
|
*/
|
|
3194
3247
|
var BridgeLifecycleService = class {
|
|
3195
3248
|
deps;
|
|
3196
3249
|
stopping;
|
|
3250
|
+
#state = "starting";
|
|
3197
3251
|
constructor(deps) {
|
|
3198
3252
|
this.deps = deps;
|
|
3199
3253
|
}
|
|
3254
|
+
state() {
|
|
3255
|
+
return this.#state;
|
|
3256
|
+
}
|
|
3200
3257
|
async start() {
|
|
3201
3258
|
const ports = await this.listen();
|
|
3202
3259
|
await this.deps.httpListening(ports.http);
|
|
3203
3260
|
this.deps.services.startEnabled().then(() => {
|
|
3204
3261
|
if (this.stopping !== void 0) return;
|
|
3205
|
-
this
|
|
3262
|
+
this.#state = "ready";
|
|
3206
3263
|
this.deps.logger.info(this.deps.readyMessage(ports));
|
|
3207
3264
|
});
|
|
3208
3265
|
return ports;
|
|
@@ -3226,8 +3283,8 @@ var BridgeLifecycleService = class {
|
|
|
3226
3283
|
}
|
|
3227
3284
|
}
|
|
3228
3285
|
async shutdown(reason) {
|
|
3229
|
-
const {
|
|
3230
|
-
state
|
|
3286
|
+
const { shutdown, tcp, http, services, logger } = this.deps;
|
|
3287
|
+
this.#state = "stopping";
|
|
3231
3288
|
logger.info(reason === void 0 ? "stopping" : `stopping (${reason})`);
|
|
3232
3289
|
shutdown.abort(shuttingDown());
|
|
3233
3290
|
const errors = [];
|
|
@@ -3246,27 +3303,62 @@ var BridgeLifecycleService = class {
|
|
|
3246
3303
|
logger.info("stopped");
|
|
3247
3304
|
}
|
|
3248
3305
|
};
|
|
3249
|
-
// src/
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
}
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3306
|
+
// src/domain/child-service.ts
|
|
3307
|
+
const SERVICE_NAMES = ["playwright", "mcp"];
|
|
3308
|
+
/** How the services are named in log lines and errors. */
|
|
3309
|
+
const SERVICE_TITLES = {
|
|
3310
|
+
playwright: "Playwright server",
|
|
3311
|
+
mcp: "Playwright MCP"
|
|
3312
|
+
};
|
|
3313
|
+
function reachability(name, status, enabled) {
|
|
3314
|
+
if (status.state === "running") return { port: status.port };
|
|
3315
|
+
const title = SERVICE_TITLES[name];
|
|
3316
|
+
if (!enabled) return { unavailable: `${title} is disabled` };
|
|
3317
|
+
return { unavailable: `${title} is not running (state: ${status.state})` };
|
|
3318
|
+
}
|
|
3319
|
+
const RESTART_POLICY = {
|
|
3320
|
+
baseDelayMs: 1e3,
|
|
3321
|
+
maxDelayMs: 3e4,
|
|
3322
|
+
stableMs: 6e4,
|
|
3323
|
+
maxCrashesInRow: 5
|
|
3324
|
+
};
|
|
3325
|
+
/**
|
|
3326
|
+
* What to do after a crash. `crashesInRow` counts the crashes before this one, `ranForMs` is how
|
|
3327
|
+
* long the service ran before it crashed.
|
|
3328
|
+
*/
|
|
3329
|
+
function nextAfterCrash(crashesInRow, ranForMs, policy = RESTART_POLICY) {
|
|
3330
|
+
const streak = (ranForMs >= policy.stableMs ? 0 : crashesInRow) + 1;
|
|
3331
|
+
if (streak >= policy.maxCrashesInRow) return {
|
|
3332
|
+
action: "fail",
|
|
3333
|
+
crashesInRow: streak
|
|
3334
|
+
};
|
|
3335
|
+
return {
|
|
3336
|
+
action: "restart",
|
|
3337
|
+
crashesInRow: streak,
|
|
3338
|
+
delayMs: Math.min(policy.baseDelayMs * 2 ** (streak - 1), policy.maxDelayMs)
|
|
3339
|
+
};
|
|
3340
|
+
}
|
|
3341
|
+
// src/application/services/child-services-service.ts
|
|
3342
|
+
/** Runs the Playwright server and Playwright MCP as the configuration says. */
|
|
3343
|
+
var ChildServicesService = class {
|
|
3344
|
+
deps;
|
|
3345
|
+
constructor(deps) {
|
|
3346
|
+
this.deps = deps;
|
|
3347
|
+
}
|
|
3348
|
+
async startEnabled() {
|
|
3349
|
+
const config = this.deps.config();
|
|
3350
|
+
const enabled = SERVICE_NAMES.filter((name) => config[name].enabled);
|
|
3351
|
+
await Promise.all(enabled.map((name) => this.supervisor(name).start()));
|
|
3352
|
+
}
|
|
3353
|
+
async stopAll() {
|
|
3354
|
+
const errors = (await Promise.allSettled(SERVICE_NAMES.map((name) => this.supervisor(name).stop()))).flatMap((result) => result.status === "rejected" ? [result.reason] : []);
|
|
3355
|
+
if (errors.length === 1) throw errors[0];
|
|
3356
|
+
if (errors.length > 1) throw new AggregateError(errors, "stopping the child services failed");
|
|
3357
|
+
}
|
|
3358
|
+
reachability(name) {
|
|
3359
|
+
return reachability(name, this.supervisor(name).status(), this.deps.config()[name].enabled);
|
|
3360
|
+
}
|
|
3361
|
+
supervisor(name) {
|
|
3270
3362
|
return this.deps.supervisors[name];
|
|
3271
3363
|
}
|
|
3272
3364
|
};
|
|
@@ -3430,9 +3522,57 @@ function withUnknownSettings(file, unknown) {
|
|
|
3430
3522
|
}
|
|
3431
3523
|
return Object.fromEntries(result);
|
|
3432
3524
|
}
|
|
3433
|
-
// src/application/
|
|
3525
|
+
// src/application/ports/in/load-config.ts
|
|
3526
|
+
/** A setting from flags, the environment or the config file is invalid. Nothing was started. */
|
|
3527
|
+
var ConfigError = class extends Error {
|
|
3528
|
+
name = "ConfigError";
|
|
3529
|
+
};
|
|
3530
|
+
// src/application/services/config-loader.ts
|
|
3434
3531
|
const show$1 = (value) => JSON.stringify(value);
|
|
3435
|
-
|
|
3532
|
+
/** `patch` checked, with an error that says where the bad setting came from. */
|
|
3533
|
+
function checked(patch, origin) {
|
|
3534
|
+
try {
|
|
3535
|
+
return validatePatch(patch);
|
|
3536
|
+
} catch (error) {
|
|
3537
|
+
throw new ConfigError(`${origin(error instanceof AppError ? error.details?.field : void 0)}: ${error.message}`, { cause: error });
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
/**
|
|
3541
|
+
* The configuration of a start (docs/usage/configuration.md): defaults, then the config file, then
|
|
3542
|
+
* flags and environment variables. `sources` names what sets each of those (`--tcp-port`).
|
|
3543
|
+
* Rejects with a {@link ConfigError}.
|
|
3544
|
+
*/
|
|
3545
|
+
async function loadConfig(store, overridesPatch, sources = /* @__PURE__ */ new Map()) {
|
|
3546
|
+
const sourceOf = (field) => sources.get(field) ?? "a flag or environment variable";
|
|
3547
|
+
let loaded;
|
|
3548
|
+
const warnings = [];
|
|
3549
|
+
try {
|
|
3550
|
+
loaded = await store.load((message) => warnings.push(message));
|
|
3551
|
+
} catch (error) {
|
|
3552
|
+
throw new ConfigError(error.message, { cause: error });
|
|
3553
|
+
}
|
|
3554
|
+
const { known, unknown, names } = splitUnknownSettings(loaded);
|
|
3555
|
+
const file = checked(known, () => `Invalid setting in the config file ${store.location}`);
|
|
3556
|
+
const overrides = checked(overridesPatch, (field) => field?.includes(".") ? `Invalid ${sourceOf(field)}` : "Invalid setting");
|
|
3557
|
+
const config = mergeConfig(mergeConfig(DEFAULT_CONFIG, file), overrides);
|
|
3558
|
+
try {
|
|
3559
|
+
assertDistinctPorts(config);
|
|
3560
|
+
} catch (error) {
|
|
3561
|
+
throw new ConfigError(`Invalid setting: ${error.message}`, { cause: error });
|
|
3562
|
+
}
|
|
3563
|
+
for (const name of names) warnings.push(`${name}: unknown setting in ${store.location}, ignored`);
|
|
3564
|
+
for (const { field, file: saved, override } of overriddenFields(file, overrides)) warnings.push(`${field}: the config file sets ${show$1(saved)}, but ${sourceOf(field)} sets ${show$1(override)}, which wins`);
|
|
3565
|
+
return {
|
|
3566
|
+
config,
|
|
3567
|
+
file,
|
|
3568
|
+
unknownSettings: unknown,
|
|
3569
|
+
pinned: new Map([...configFields(overrides).keys()].map((field) => [field, sourceOf(field)])),
|
|
3570
|
+
warnings
|
|
3571
|
+
};
|
|
3572
|
+
}
|
|
3573
|
+
// src/application/services/config-service.ts
|
|
3574
|
+
const show = (value) => JSON.stringify(value);
|
|
3575
|
+
const same = (a, b) => show(a) === show(b);
|
|
3436
3576
|
/**
|
|
3437
3577
|
* The configuration (`GET` / `PUT /api/v1/config`). The configuration in use never changes while
|
|
3438
3578
|
* the bridge runs: an update is saved to the config file and takes effect on the next start
|
|
@@ -3478,7 +3618,7 @@ var ConfigService = class {
|
|
|
3478
3618
|
this.active = mergeConfig(this.active, changes);
|
|
3479
3619
|
for (const [field, value] of configFields(changes)) {
|
|
3480
3620
|
if (same(value, before.get(field))) continue;
|
|
3481
|
-
this.deps.logger.info(`${field}: ${show
|
|
3621
|
+
this.deps.logger.info(`${field}: ${show(before.get(field))} → ${show(value)}, saved to ${this.deps.store.location}`);
|
|
3482
3622
|
}
|
|
3483
3623
|
return this.active;
|
|
3484
3624
|
});
|
|
@@ -3517,10 +3657,78 @@ var ConfigService = class {
|
|
|
3517
3657
|
for (const [field, value] of patched) {
|
|
3518
3658
|
const source = pinned?.get(field);
|
|
3519
3659
|
if (source !== void 0) logger.warn(`${field}: saved to ${store.location}, but ${source} overrides it on the next start`);
|
|
3520
|
-
else if (!same(value, running.get(field))) logger.info(`${field}: ${show
|
|
3660
|
+
else if (!same(value, running.get(field))) logger.info(`${field}: ${show(running.get(field))} → ${show(value)} on the next start`);
|
|
3521
3661
|
}
|
|
3522
3662
|
}
|
|
3523
3663
|
};
|
|
3664
|
+
// src/domain/capture-window.ts
|
|
3665
|
+
/** The speech an input caused, from when it was sent until it pauses, none comes or time runs out. */
|
|
3666
|
+
var CaptureWindow = class {
|
|
3667
|
+
sentAt;
|
|
3668
|
+
timing;
|
|
3669
|
+
maxEntries;
|
|
3670
|
+
#entries = [];
|
|
3671
|
+
#omitted = 0;
|
|
3672
|
+
/** When the newest speech was received. */
|
|
3673
|
+
#last;
|
|
3674
|
+
#end;
|
|
3675
|
+
/** @param maxEntries The first entries kept; later ones are only counted. */
|
|
3676
|
+
constructor(sentAt, timing, maxEntries) {
|
|
3677
|
+
this.sentAt = sentAt;
|
|
3678
|
+
this.timing = timing;
|
|
3679
|
+
this.maxEntries = maxEntries;
|
|
3680
|
+
this.#end = sentAt + timing.timeoutMs;
|
|
3681
|
+
}
|
|
3682
|
+
onSpeech(entry) {
|
|
3683
|
+
this.#last = entry.receivedAt.getTime();
|
|
3684
|
+
if (this.#entries.length < this.maxEntries) this.#entries.push(entry);
|
|
3685
|
+
else this.#omitted++;
|
|
3686
|
+
}
|
|
3687
|
+
/** When the capture ends unless more speech comes. */
|
|
3688
|
+
deadline() {
|
|
3689
|
+
const { firstWithinMs, quietForMs } = this.timing;
|
|
3690
|
+
const due = this.#last === void 0 ? this.sentAt + firstWithinMs : this.#last + quietForMs;
|
|
3691
|
+
return Math.min(due, this.#end);
|
|
3692
|
+
}
|
|
3693
|
+
/**
|
|
3694
|
+
* What the capture holds once its deadline has passed. The status comes from the entries' times,
|
|
3695
|
+
* not from the time now: timers may fire a little early.
|
|
3696
|
+
*/
|
|
3697
|
+
result() {
|
|
3698
|
+
return {
|
|
3699
|
+
status: this.#last === void 0 ? "no-speech" : this.#last + this.timing.quietForMs <= this.#end ? "silent" : "timeout",
|
|
3700
|
+
entries: this.#entries,
|
|
3701
|
+
omitted: this.#omitted
|
|
3702
|
+
};
|
|
3703
|
+
}
|
|
3704
|
+
};
|
|
3705
|
+
/**
|
|
3706
|
+
* The wait before an input until the newest speech is `settleMs` old, at most `timeoutMs`: after
|
|
3707
|
+
* that the input is sent anyway, and the trailing speech shows in the capture.
|
|
3708
|
+
*/
|
|
3709
|
+
var SettleWindow = class {
|
|
3710
|
+
start;
|
|
3711
|
+
timing;
|
|
3712
|
+
#last;
|
|
3713
|
+
/** @param lastSpeechAt When the newest speech so far was received, if there was any. */
|
|
3714
|
+
constructor(start, timing, lastSpeechAt) {
|
|
3715
|
+
this.start = start;
|
|
3716
|
+
this.timing = timing;
|
|
3717
|
+
this.#last = lastSpeechAt;
|
|
3718
|
+
}
|
|
3719
|
+
/** Whether the speech had already been quiet long enough at the start. */
|
|
3720
|
+
get settled() {
|
|
3721
|
+
return this.#last === void 0 || this.#last + this.timing.settleMs <= this.start;
|
|
3722
|
+
}
|
|
3723
|
+
onSpeech(at) {
|
|
3724
|
+
this.#last = at;
|
|
3725
|
+
}
|
|
3726
|
+
/** When the input may be sent unless more speech comes. */
|
|
3727
|
+
deadline() {
|
|
3728
|
+
if (this.#last === void 0) return this.start;
|
|
3729
|
+
return Math.min(this.#last + this.timing.settleMs, this.start + this.timing.timeoutMs);
|
|
3730
|
+
}
|
|
3731
|
+
};
|
|
3524
3732
|
// src/application/ports/in/capture-input.ts
|
|
3525
3733
|
/** Defaults and ranges of the capture options, in milliseconds. */
|
|
3526
3734
|
const CAPTURE_LIMITS = API_LIMITS.capture;
|
|
@@ -3637,6 +3845,64 @@ function followLog(deps, { since: requested, sessionId, staleSince = "wait" }, l
|
|
|
3637
3845
|
});
|
|
3638
3846
|
return stop;
|
|
3639
3847
|
}
|
|
3848
|
+
/**
|
|
3849
|
+
* {@link followLog} until `onEvent` says `done`, the time runs out (`timeout`) or the signal
|
|
3850
|
+
* aborts. Nothing is listening or running any more once it has settled.
|
|
3851
|
+
*/
|
|
3852
|
+
function followUntil(deps, { since, sessionId, signal, pace, timeLeft, startTimer }, onEvent) {
|
|
3853
|
+
if (signal.aborted) return Promise.reject(abortReason(signal));
|
|
3854
|
+
return new Promise((resolve, reject) => {
|
|
3855
|
+
let done = false;
|
|
3856
|
+
let timer;
|
|
3857
|
+
let stop;
|
|
3858
|
+
const finish = () => {
|
|
3859
|
+
done = true;
|
|
3860
|
+
stop?.();
|
|
3861
|
+
timer?.abort();
|
|
3862
|
+
signal.removeEventListener("abort", onAbort);
|
|
3863
|
+
};
|
|
3864
|
+
const succeed = (how) => {
|
|
3865
|
+
if (done) return;
|
|
3866
|
+
finish();
|
|
3867
|
+
resolve(how);
|
|
3868
|
+
};
|
|
3869
|
+
const fail = (error) => {
|
|
3870
|
+
if (done) return;
|
|
3871
|
+
finish();
|
|
3872
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
3873
|
+
};
|
|
3874
|
+
const onAbort = () => fail(abortReason(signal));
|
|
3875
|
+
const arm = () => {
|
|
3876
|
+
if (done) return;
|
|
3877
|
+
timer?.abort();
|
|
3878
|
+
const own = new AbortController();
|
|
3879
|
+
timer = own;
|
|
3880
|
+
deps.clock.sleep(Math.max(0, timeLeft()), own.signal).then(() => {
|
|
3881
|
+
if (timer === own) succeed("timeout");
|
|
3882
|
+
}, () => {});
|
|
3883
|
+
};
|
|
3884
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
3885
|
+
if (startTimer === "at once") arm();
|
|
3886
|
+
try {
|
|
3887
|
+
stop = followLog(deps, {
|
|
3888
|
+
since,
|
|
3889
|
+
sessionId
|
|
3890
|
+
}, (event) => {
|
|
3891
|
+
if (done) return;
|
|
3892
|
+
const step = onEvent(event);
|
|
3893
|
+
if (step === "done") succeed("done");
|
|
3894
|
+
else if (step === "rearm") arm();
|
|
3895
|
+
}, {
|
|
3896
|
+
pace,
|
|
3897
|
+
onCaughtUp: startTimer === "caught up" ? arm : void 0,
|
|
3898
|
+
onError: fail
|
|
3899
|
+
});
|
|
3900
|
+
if (done) stop();
|
|
3901
|
+
} catch (error) {
|
|
3902
|
+
fail(error);
|
|
3903
|
+
}
|
|
3904
|
+
});
|
|
3905
|
+
}
|
|
3640
3906
|
// src/application/shared/int-option.ts
|
|
3641
3907
|
/**
|
|
3642
3908
|
* A numeric use-case option: `fallback` if it is missing, otherwise checked to be an integer
|
|
@@ -3662,7 +3928,6 @@ function parseOptions(options) {
|
|
|
3662
3928
|
settleMs: ms("settleMs", settleMs)
|
|
3663
3929
|
};
|
|
3664
3930
|
}
|
|
3665
|
-
const toError = (error) => error instanceof Error ? error : new Error(String(error));
|
|
3666
3931
|
/**
|
|
3667
3932
|
* Native input that records the speech it causes (docs/usage/native-input.md#capturing-the-speech-an-input-causes).
|
|
3668
3933
|
* The start `seq` is read in the input queue right before the input is sent, so no other input
|
|
@@ -3703,36 +3968,31 @@ var InputCaptureService = class {
|
|
|
3703
3968
|
}
|
|
3704
3969
|
}
|
|
3705
3970
|
/**
|
|
3706
|
-
* Waits
|
|
3707
|
-
*
|
|
3708
|
-
* the wait: it goes by when speech was received, not by what the buffer holds.
|
|
3971
|
+
* Waits for the speech to settle ({@link SettleWindow}). Markers and clears don't shorten the
|
|
3972
|
+
* wait: it goes by when speech was received, not by what the buffer holds.
|
|
3709
3973
|
*/
|
|
3710
|
-
async settle(
|
|
3711
|
-
const
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3974
|
+
async settle(options, signal) {
|
|
3975
|
+
const window = new SettleWindow(this.now(), options, this.deps.log.lastSpeechAt?.getTime());
|
|
3976
|
+
if (window.settled) return;
|
|
3977
|
+
await this.follow(null, signal, () => window.deadline(), (event) => {
|
|
3978
|
+
if (event.type !== "entry" || event.entry.kind !== "speech") return void 0;
|
|
3979
|
+
window.onSpeech(event.entry.receivedAt.getTime());
|
|
3980
|
+
return "rearm";
|
|
3716
3981
|
});
|
|
3717
3982
|
}
|
|
3718
|
-
/** Follows the speech after `startSeq` until
|
|
3719
|
-
async record(startSeq,
|
|
3720
|
-
const
|
|
3721
|
-
const end = sentAt + timeoutMs;
|
|
3722
|
-
const entries = [];
|
|
3723
|
-
let omitted = 0;
|
|
3983
|
+
/** Follows the speech after `startSeq` until its {@link CaptureWindow} has passed. */
|
|
3984
|
+
async record(startSeq, options, signal) {
|
|
3985
|
+
const window = new CaptureWindow(this.now(), options, CAPTURE_LIMITS.entries);
|
|
3724
3986
|
let truncated = false;
|
|
3725
|
-
|
|
3726
|
-
const deadline = () => Math.min(last === void 0 ? sentAt + firstWithinMs : last + quietForMs, end);
|
|
3727
|
-
await this.follow(startSeq, signal, deadline, (event) => {
|
|
3987
|
+
await this.follow(startSeq, signal, () => window.deadline(), (event) => {
|
|
3728
3988
|
if (event.type === "truncated") truncated = true;
|
|
3729
|
-
if (event.type !== "entry" || event.entry.kind !== "speech") return;
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
else omitted++;
|
|
3989
|
+
if (event.type !== "entry" || event.entry.kind !== "speech") return void 0;
|
|
3990
|
+
window.onSpeech(event.entry);
|
|
3991
|
+
return "rearm";
|
|
3733
3992
|
});
|
|
3993
|
+
const { status, entries, omitted } = window.result();
|
|
3734
3994
|
return {
|
|
3735
|
-
status
|
|
3995
|
+
status,
|
|
3736
3996
|
startSeq,
|
|
3737
3997
|
entries,
|
|
3738
3998
|
omitted,
|
|
@@ -3741,60 +4001,34 @@ var InputCaptureService = class {
|
|
|
3741
4001
|
}
|
|
3742
4002
|
/**
|
|
3743
4003
|
* Hands `onEvent` the log's events after `since` (`null`: only new ones) until `deadline()`
|
|
3744
|
-
* (ms, read again
|
|
4004
|
+
* (ms, read again at each `rearm`) has passed. Rejects when `signal` aborts.
|
|
3745
4005
|
*/
|
|
3746
|
-
follow(since, signal, deadline, onEvent) {
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
timer?.abort();
|
|
3756
|
-
signal.removeEventListener("abort", onAbort);
|
|
3757
|
-
};
|
|
3758
|
-
const fail = (error) => {
|
|
3759
|
-
if (done) return;
|
|
3760
|
-
finish();
|
|
3761
|
-
reject(error);
|
|
3762
|
-
};
|
|
3763
|
-
const onAbort = () => fail(abortReason(signal));
|
|
3764
|
-
const arm = () => {
|
|
3765
|
-
timer?.abort();
|
|
3766
|
-
const own = new AbortController();
|
|
3767
|
-
timer = own;
|
|
3768
|
-
this.deps.clock.sleep(Math.max(0, deadline() - this.now()), own.signal).then(() => {
|
|
3769
|
-
if (done || timer !== own) return;
|
|
3770
|
-
finish();
|
|
3771
|
-
resolve();
|
|
3772
|
-
}, () => {});
|
|
3773
|
-
};
|
|
3774
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
3775
|
-
arm();
|
|
3776
|
-
try {
|
|
3777
|
-
stopFollow = followLog(this.deps, {
|
|
3778
|
-
since,
|
|
3779
|
-
sessionId: void 0
|
|
3780
|
-
}, (event) => {
|
|
3781
|
-
if (done) return;
|
|
3782
|
-
onEvent(event);
|
|
3783
|
-
if (event.type === "entry" && event.entry.kind === "speech") arm();
|
|
3784
|
-
}, {
|
|
3785
|
-
pace: this.deps.pace?.(),
|
|
3786
|
-
onError: (error) => fail(toError(error))
|
|
3787
|
-
});
|
|
3788
|
-
if (done) stopFollow();
|
|
3789
|
-
} catch (error) {
|
|
3790
|
-
fail(toError(error));
|
|
3791
|
-
}
|
|
3792
|
-
});
|
|
4006
|
+
async follow(since, signal, deadline, onEvent) {
|
|
4007
|
+
await followUntil(this.deps, {
|
|
4008
|
+
since,
|
|
4009
|
+
sessionId: void 0,
|
|
4010
|
+
signal,
|
|
4011
|
+
pace: this.deps.pace?.(),
|
|
4012
|
+
timeLeft: () => deadline() - this.now(),
|
|
4013
|
+
startTimer: "at once"
|
|
4014
|
+
}, onEvent);
|
|
3793
4015
|
}
|
|
3794
4016
|
now() {
|
|
3795
4017
|
return this.deps.clock.now().getTime();
|
|
3796
4018
|
}
|
|
3797
4019
|
};
|
|
4020
|
+
// src/domain/native-input.ts
|
|
4021
|
+
/** Whether the window belongs to the process tree of a target's browser. */
|
|
4022
|
+
function isWindowOfTarget(window, tree) {
|
|
4023
|
+
return tree.has(window.pid);
|
|
4024
|
+
}
|
|
4025
|
+
/**
|
|
4026
|
+
* The window to bring to the front: the first of `windows` (front to back) that belongs to the
|
|
4027
|
+
* target's process tree and has a title, with `title` one that contains it.
|
|
4028
|
+
*/
|
|
4029
|
+
function findTargetWindow(windows, tree, title) {
|
|
4030
|
+
return windows.find((window) => isWindowOfTarget(window, tree) && window.title !== "" && (title === void 0 || window.title.includes(title)));
|
|
4031
|
+
}
|
|
3798
4032
|
// src/application/shared/browser-targets.ts
|
|
3799
4033
|
/** The service whose process tree holds a target's browser windows, and its name in messages. */
|
|
3800
4034
|
const BROWSER_TARGETS = {
|
|
@@ -3853,7 +4087,7 @@ var WindowFocusService = class {
|
|
|
3853
4087
|
for (let attempt = 0; attempt < tries; attempt++) {
|
|
3854
4088
|
if (attempt > 0) await clock.sleep(TITLE_WAIT.pollMs, signal);
|
|
3855
4089
|
const tree = await windows.processTree(pid);
|
|
3856
|
-
const found = (await windows.topLevelWindows()
|
|
4090
|
+
const found = findTargetWindow(await windows.topLevelWindows(), tree, title);
|
|
3857
4091
|
if (found) return found;
|
|
3858
4092
|
}
|
|
3859
4093
|
}
|
|
@@ -3899,7 +4133,6 @@ function parseKeys(keys) {
|
|
|
3899
4133
|
*/
|
|
3900
4134
|
var NativeInputService = class {
|
|
3901
4135
|
deps;
|
|
3902
|
-
queue = Promise.resolve();
|
|
3903
4136
|
constructor(deps) {
|
|
3904
4137
|
this.deps = deps;
|
|
3905
4138
|
}
|
|
@@ -3908,7 +4141,7 @@ var NativeInputService = class {
|
|
|
3908
4141
|
checkCoordinate("y", y);
|
|
3909
4142
|
if (!MOUSE_BUTTONS.includes(button)) throw invalidField("button", "must be left, right or middle");
|
|
3910
4143
|
let sent = false;
|
|
3911
|
-
return this.
|
|
4144
|
+
return this.deps.queue.exclusive(async (signal) => {
|
|
3912
4145
|
await hooks.beforeInject?.();
|
|
3913
4146
|
const before = await this.sentTo();
|
|
3914
4147
|
signal.throwIfAborted();
|
|
@@ -3925,7 +4158,7 @@ var NativeInputService = class {
|
|
|
3925
4158
|
this.checkSupported(chords);
|
|
3926
4159
|
const text = `keys ${typeof keys === "string" ? keys : keys.join(" ")}`;
|
|
3927
4160
|
let sent = 0;
|
|
3928
|
-
return this.
|
|
4161
|
+
return this.deps.queue.exclusive(async (signal) => {
|
|
3929
4162
|
await hooks.beforeInject?.();
|
|
3930
4163
|
let before = expectedTarget === void 0 ? await this.sentTo() : {};
|
|
3931
4164
|
for (const [index, chord] of chords.entries()) {
|
|
@@ -3990,7 +4223,7 @@ var NativeInputService = class {
|
|
|
3990
4223
|
if (error instanceof AppError && error.code === "WRONG_WINDOW") throw error;
|
|
3991
4224
|
return refuse(`the window in front could not be checked (${error instanceof Error ? error.message : String(error)})`);
|
|
3992
4225
|
}
|
|
3993
|
-
if (!
|
|
4226
|
+
if (!isWindowOfTarget(window, tree)) return refuse(`the window in front ("${window.title}", pid ${window.pid}) does not belong to the browser of ${name}`, window);
|
|
3994
4227
|
return window;
|
|
3995
4228
|
}
|
|
3996
4229
|
checkSupported(chords) {
|
|
@@ -4031,32 +4264,18 @@ var NativeInputService = class {
|
|
|
4031
4264
|
}
|
|
4032
4265
|
return first;
|
|
4033
4266
|
}
|
|
4034
|
-
exclusive(task, signal) {
|
|
4035
|
-
return this.enqueue(task, signal);
|
|
4036
|
-
}
|
|
4037
|
-
/**
|
|
4038
|
-
* Runs `task` after the earlier ones; a failed task doesn't stop the later ones. `task` isn't
|
|
4039
|
-
* run if `signal` aborted or the bridge shut down by its turn. `unsent` says what a stopped
|
|
4040
|
-
* request leaves unsent, for the log.
|
|
4041
|
-
*/
|
|
4042
|
-
async enqueue(task, signal, unsent = () => void 0) {
|
|
4043
|
-
const stop = linkSignals(this.deps.shutdown, signal);
|
|
4044
|
-
const run = this.queue.then(() => {
|
|
4045
|
-
stop.signal.throwIfAborted();
|
|
4046
|
-
return task(stop.signal);
|
|
4047
|
-
});
|
|
4048
|
-
this.queue = run.catch(() => void 0);
|
|
4049
|
-
try {
|
|
4050
|
-
return await run;
|
|
4051
|
-
} catch (error) {
|
|
4052
|
-
const what = stop.signal.aborted ? unsent() : void 0;
|
|
4053
|
-
if (what !== void 0) this.deps.logger.warn(`${what} (${abortReason(stop.signal).message})`);
|
|
4054
|
-
throw error;
|
|
4055
|
-
} finally {
|
|
4056
|
-
stop.dispose();
|
|
4057
|
-
}
|
|
4058
|
-
}
|
|
4059
4267
|
};
|
|
4268
|
+
// src/domain/label.ts
|
|
4269
|
+
/**
|
|
4270
|
+
* A label as the API takes it: trimmed, not empty, at most `max` characters (`isTrimmedLabel`, the
|
|
4271
|
+
* rule the request schemas check too). `INVALID_REQUEST` naming `field` otherwise.
|
|
4272
|
+
*/
|
|
4273
|
+
function trimmedLabel(field, value, max) {
|
|
4274
|
+
if (isTrimmedLabel(value, max)) return value.trim();
|
|
4275
|
+
throw invalidField(field, value.trim() === "" ? "must not be empty" : `must be at most ${max} characters`);
|
|
4276
|
+
}
|
|
4277
|
+
/** A marker's text, which is also the label a marker is found by. */
|
|
4278
|
+
const markerLabel = (label) => trimmedLabel("label", label, API_LIMITS.markerLength);
|
|
4060
4279
|
// src/domain/session.ts
|
|
4061
4280
|
const EMPTY_SESSION_STATS = {
|
|
4062
4281
|
firstSeq: null,
|
|
@@ -4074,16 +4293,13 @@ function summarize(session, stats) {
|
|
|
4074
4293
|
}
|
|
4075
4294
|
/** `name` (required) or `run` (optional), trimmed. `INVALID_REQUEST` if empty or too long. */
|
|
4076
4295
|
function sessionLabel(field, value) {
|
|
4077
|
-
|
|
4078
|
-
if (text === "") throw invalidField(field, "must not be empty");
|
|
4079
|
-
if (text.length > MAX_SESSION_NAME_LENGTH) throw invalidField(field, `must be at most ${MAX_SESSION_NAME_LENGTH} characters`);
|
|
4080
|
-
return text;
|
|
4296
|
+
return trimmedLabel(field, value, MAX_SESSION_NAME_LENGTH);
|
|
4081
4297
|
}
|
|
4082
4298
|
// src/application/services/session-service.ts
|
|
4083
4299
|
const describe = (session) => `session ${session.id} "${session.name}" (client ${session.client ?? "unknown"})`;
|
|
4084
4300
|
/**
|
|
4085
|
-
* Starting, ending and listing sessions (docs/usage/speech-capture.md#sessions).
|
|
4086
|
-
*
|
|
4301
|
+
* Starting, ending and listing sessions (docs/usage/speech-capture.md#sessions). The speech log
|
|
4302
|
+
* gives entries their `sessionId` and reports each start and end as a `session` event. One screen
|
|
4087
4303
|
* reader means one current session: a client that ends or replaces another client's session is not
|
|
4088
4304
|
* refused, but warned about (docs/implementation/decisions.md#sessions-warn-instead-of-locking).
|
|
4089
4305
|
*/
|
|
@@ -4093,24 +4309,13 @@ var SessionService = class {
|
|
|
4093
4309
|
this.deps = deps;
|
|
4094
4310
|
}
|
|
4095
4311
|
start({ name, run, client }) {
|
|
4096
|
-
const label = sessionLabel("name", name);
|
|
4097
|
-
const group = run === void 0 || run === null ? null : sessionLabel("run", run);
|
|
4098
|
-
const owner = clientLabel(client);
|
|
4099
4312
|
const { ended, started } = this.deps.log.startSession({
|
|
4100
|
-
name
|
|
4101
|
-
run:
|
|
4102
|
-
client:
|
|
4313
|
+
name,
|
|
4314
|
+
run: run ?? null,
|
|
4315
|
+
client: client ?? null,
|
|
4103
4316
|
startedAt: this.deps.clock.now()
|
|
4104
4317
|
});
|
|
4105
|
-
|
|
4106
|
-
type: "session",
|
|
4107
|
-
session: ended
|
|
4108
|
-
});
|
|
4109
|
-
this.deps.events.publish({
|
|
4110
|
-
type: "session",
|
|
4111
|
-
session: started
|
|
4112
|
-
});
|
|
4113
|
-
const replaced = ended && ended.client !== owner ? ended : null;
|
|
4318
|
+
const replaced = ended && ended.client !== started.client ? ended : null;
|
|
4114
4319
|
if (replaced) this.deps.logger.warn(`${describe(started)} replaced ${describe(replaced)}`);
|
|
4115
4320
|
return {
|
|
4116
4321
|
session: started,
|
|
@@ -4121,10 +4326,6 @@ var SessionService = class {
|
|
|
4121
4326
|
const owner = clientLabel(client);
|
|
4122
4327
|
const ended = this.deps.log.endSession(this.deps.clock.now(), session);
|
|
4123
4328
|
if (!ended) return null;
|
|
4124
|
-
this.deps.events.publish({
|
|
4125
|
-
type: "session",
|
|
4126
|
-
session: ended
|
|
4127
|
-
});
|
|
4128
4329
|
if (ended.client !== owner) this.deps.logger.warn(`client ${owner ?? "unknown"} ended ${describe(ended)}`);
|
|
4129
4330
|
return ended;
|
|
4130
4331
|
}
|
|
@@ -4147,10 +4348,9 @@ function clientLabel(client) {
|
|
|
4147
4348
|
/** Page size of `list`: the default and the most a caller may ask for. */
|
|
4148
4349
|
const LIST_LIMIT = API_LIMITS.list;
|
|
4149
4350
|
// src/application/services/speech-service.ts
|
|
4150
|
-
const MAX_MARKER_LENGTH = API_LIMITS.markerLength;
|
|
4151
4351
|
/**
|
|
4152
4352
|
* Recording, reading, clearing and marking speech: every entry gets its `seq` and `sessionId`
|
|
4153
|
-
* from the speech log and `receivedAt` from the clock
|
|
4353
|
+
* from the speech log and `receivedAt` from the clock
|
|
4154
4354
|
* (docs/implementation/tcp-capture.md#from-line-to-speech-entry).
|
|
4155
4355
|
*/
|
|
4156
4356
|
var SpeechService = class {
|
|
@@ -4158,11 +4358,11 @@ var SpeechService = class {
|
|
|
4158
4358
|
constructor(deps) {
|
|
4159
4359
|
this.deps = deps;
|
|
4160
4360
|
}
|
|
4161
|
-
record({ text, voice, connectionId }) {
|
|
4361
|
+
record({ text, voice, source, connectionId }) {
|
|
4162
4362
|
this.add({
|
|
4163
4363
|
kind: "speech",
|
|
4164
4364
|
text,
|
|
4165
|
-
source
|
|
4365
|
+
source,
|
|
4166
4366
|
voice,
|
|
4167
4367
|
connectionId
|
|
4168
4368
|
});
|
|
@@ -4192,66 +4392,39 @@ var SpeechService = class {
|
|
|
4192
4392
|
/** Wipes the buffer and the ended sessions, or one scope. The current session stays current. */
|
|
4193
4393
|
clear(filter) {
|
|
4194
4394
|
const session = filter === "active" ? this.deps.log.resolveFilter(filter) ?? void 0 : filter;
|
|
4195
|
-
if (session === void 0)
|
|
4196
|
-
|
|
4197
|
-
this.deps.events.publish({ type: "clear" });
|
|
4198
|
-
return;
|
|
4199
|
-
}
|
|
4200
|
-
this.deps.events.publish({
|
|
4201
|
-
type: "clear",
|
|
4202
|
-
sessionId: this.deps.log.clearScope(session)
|
|
4203
|
-
});
|
|
4395
|
+
if (session === void 0) this.deps.log.clear();
|
|
4396
|
+
else this.deps.log.clearScope(session);
|
|
4204
4397
|
}
|
|
4398
|
+
/** The speech log trims the label and refuses an empty or too long one. */
|
|
4205
4399
|
addMarker(label) {
|
|
4206
|
-
const text = markerLabel(label);
|
|
4207
4400
|
return this.add({
|
|
4208
4401
|
kind: "marker",
|
|
4209
|
-
text,
|
|
4402
|
+
text: label,
|
|
4210
4403
|
source: "api",
|
|
4211
4404
|
voice: null,
|
|
4212
4405
|
connectionId: null
|
|
4213
4406
|
});
|
|
4214
4407
|
}
|
|
4215
4408
|
latestMarker(label, session) {
|
|
4216
|
-
const text = markerLabel(label);
|
|
4217
4409
|
const sessionId = this.deps.log.resolveFilter(session);
|
|
4218
|
-
return this.deps.log.latestMarker(
|
|
4410
|
+
return this.deps.log.latestMarker(label, sessionId) ?? null;
|
|
4219
4411
|
}
|
|
4220
4412
|
add(entry) {
|
|
4221
|
-
|
|
4413
|
+
return this.deps.log.append({
|
|
4222
4414
|
...entry,
|
|
4223
4415
|
receivedAt: this.deps.clock.now()
|
|
4224
4416
|
});
|
|
4225
|
-
this.deps.events.publish({
|
|
4226
|
-
type: "entry",
|
|
4227
|
-
entry: stored
|
|
4228
|
-
});
|
|
4229
|
-
return stored;
|
|
4230
4417
|
}
|
|
4231
4418
|
};
|
|
4232
|
-
/** A marker label: trimmed, not empty, at most `MAX_MARKER_LENGTH` characters. */
|
|
4233
|
-
function markerLabel(label) {
|
|
4234
|
-
const text = label.trim();
|
|
4235
|
-
if (text === "") throw invalidField("label", "must not be empty");
|
|
4236
|
-
if (text.length > MAX_MARKER_LENGTH) throw invalidField("label", `must be at most ${MAX_MARKER_LENGTH} characters`);
|
|
4237
|
-
return text;
|
|
4238
|
-
}
|
|
4239
4419
|
// src/application/services/status-service.ts
|
|
4240
|
-
/**
|
|
4241
|
-
* `GET /api/v1/status`. `BridgeLifecycleService` moves the state from `starting` to `ready` and
|
|
4242
|
-
* `stopping` through `BridgeStateControl`.
|
|
4243
|
-
*/
|
|
4420
|
+
/** `GET /api/v1/status`. */
|
|
4244
4421
|
var StatusService = class {
|
|
4245
4422
|
deps;
|
|
4246
|
-
state = "starting";
|
|
4247
4423
|
constructor(deps) {
|
|
4248
4424
|
this.deps = deps;
|
|
4249
4425
|
}
|
|
4250
|
-
setState(state) {
|
|
4251
|
-
this.state = state;
|
|
4252
|
-
}
|
|
4253
4426
|
status() {
|
|
4254
|
-
const { capture, log, supervisors, config, version, apiVersion, startedAt, injector, windows } = this.deps;
|
|
4427
|
+
const { state, capture, log, supervisors, config, version, apiVersion, startedAt, injector, windows } = this.deps;
|
|
4255
4428
|
const { listener, connections } = capture.captureStatus();
|
|
4256
4429
|
const { tcp } = config();
|
|
4257
4430
|
const listed = log.sessions();
|
|
@@ -4260,7 +4433,7 @@ var StatusService = class {
|
|
|
4260
4433
|
bridge: {
|
|
4261
4434
|
version,
|
|
4262
4435
|
apiVersion,
|
|
4263
|
-
state:
|
|
4436
|
+
state: state(),
|
|
4264
4437
|
startedAt
|
|
4265
4438
|
},
|
|
4266
4439
|
tcp: {
|
|
@@ -4284,14 +4457,33 @@ var StatusService = class {
|
|
|
4284
4457
|
};
|
|
4285
4458
|
}
|
|
4286
4459
|
};
|
|
4460
|
+
// src/application/shared/input-queue.ts
|
|
4461
|
+
/** One task at a time, in the order they came. A failed task doesn't stop the later ones. */
|
|
4462
|
+
var SerialInputQueue = class {
|
|
4463
|
+
deps;
|
|
4464
|
+
tail = Promise.resolve();
|
|
4465
|
+
constructor(deps) {
|
|
4466
|
+
this.deps = deps;
|
|
4467
|
+
}
|
|
4468
|
+
async exclusive(task, signal, unsent = () => void 0) {
|
|
4469
|
+
const stop = linkSignals(this.deps.shutdown, signal);
|
|
4470
|
+
const run = this.tail.then(() => {
|
|
4471
|
+
stop.signal.throwIfAborted();
|
|
4472
|
+
return task(stop.signal);
|
|
4473
|
+
});
|
|
4474
|
+
this.tail = run.catch(() => void 0);
|
|
4475
|
+
try {
|
|
4476
|
+
return await run;
|
|
4477
|
+
} catch (error) {
|
|
4478
|
+
const what = stop.signal.aborted ? unsent() : void 0;
|
|
4479
|
+
if (what !== void 0) this.deps.logger.warn(`${what} (${abortReason(stop.signal).message})`);
|
|
4480
|
+
throw error;
|
|
4481
|
+
} finally {
|
|
4482
|
+
stop.dispose();
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
};
|
|
4287
4486
|
// src/application/services/tcp-startup-service.ts
|
|
4288
|
-
const VOICE_DOCS = "docs/usage/vm-setup.md#more-voices--other-ports";
|
|
4289
|
-
const QUIT = /* @__PURE__ */ new Set([
|
|
4290
|
-
"",
|
|
4291
|
-
"q",
|
|
4292
|
-
"quit",
|
|
4293
|
-
"exit"
|
|
4294
|
-
]);
|
|
4295
4487
|
/**
|
|
4296
4488
|
* Starts the TCP listener on `tcp.port`. If that port is in use or not allowed, it asks the person
|
|
4297
4489
|
* at the console for another one, checks it, listens on it and saves it to the config file. It
|
|
@@ -4317,29 +4509,24 @@ var TcpStartupService = class {
|
|
|
4317
4509
|
return this.deps.listener.stop();
|
|
4318
4510
|
}
|
|
4319
4511
|
async choosePort(failure) {
|
|
4320
|
-
const {
|
|
4321
|
-
if (
|
|
4322
|
-
const giveUp = hinted(failure,
|
|
4512
|
+
const { hints, prompt, logger } = this.deps;
|
|
4513
|
+
if (hints.pinned !== void 0) throw hinted(failure, hints.pinned);
|
|
4514
|
+
const giveUp = hinted(failure, hints.choosePort);
|
|
4323
4515
|
if (prompt === void 0) throw giveUp;
|
|
4324
4516
|
logger.warn(failure.message);
|
|
4325
4517
|
for (;;) {
|
|
4326
|
-
const
|
|
4327
|
-
if (
|
|
4328
|
-
const port = await this.tryPort(
|
|
4518
|
+
const answer = await prompt.askForPort(failure.port);
|
|
4519
|
+
if (answer === void 0) throw giveUp;
|
|
4520
|
+
const port = await this.tryPort(answer);
|
|
4329
4521
|
if (port === void 0) continue;
|
|
4330
4522
|
await this.save(port);
|
|
4331
|
-
logger.warn(`speech capture listens on port ${port} instead of ${failure.port}:
|
|
4523
|
+
logger.warn(`speech capture listens on port ${port} instead of ${failure.port}: ${hints.pointVoice}`);
|
|
4332
4524
|
return port;
|
|
4333
4525
|
}
|
|
4334
4526
|
}
|
|
4335
|
-
/** Listens on
|
|
4336
|
-
async tryPort(
|
|
4527
|
+
/** Listens on `port`, or warns why not and resolves with `undefined`. */
|
|
4528
|
+
async tryPort(port) {
|
|
4337
4529
|
const { listener, config, logger } = this.deps;
|
|
4338
|
-
if (!/^\d+$/.test(answer)) {
|
|
4339
|
-
logger.warn(`${JSON.stringify(answer)} is not a port number`);
|
|
4340
|
-
return;
|
|
4341
|
-
}
|
|
4342
|
-
const port = Number(answer);
|
|
4343
4530
|
if (port === 0) {
|
|
4344
4531
|
logger.warn("port 0 picks another port on every start, but the voice needs a fixed one");
|
|
4345
4532
|
return;
|
|
@@ -4355,10 +4542,11 @@ var TcpStartupService = class {
|
|
|
4355
4542
|
}
|
|
4356
4543
|
/** Saves `port` as `tcp.port`. The bridge uses it anyway if the file can't be written. */
|
|
4357
4544
|
async save(port) {
|
|
4545
|
+
const { config, configLocation, hints, logger } = this.deps;
|
|
4358
4546
|
try {
|
|
4359
|
-
await
|
|
4547
|
+
await config.adopt({ tcp: { port } });
|
|
4360
4548
|
} catch (error) {
|
|
4361
|
-
|
|
4549
|
+
logger.warn(`tcp.port ${port} could not be saved to ${configLocation} (${error instanceof Error ? error.message : String(error)}): ${hints.keepPort(port)}`);
|
|
4362
4550
|
}
|
|
4363
4551
|
}
|
|
4364
4552
|
};
|
|
@@ -4387,6 +4575,36 @@ var TranscriptService = class {
|
|
|
4387
4575
|
});
|
|
4388
4576
|
}
|
|
4389
4577
|
};
|
|
4578
|
+
// src/domain/last-seen.ts
|
|
4579
|
+
/**
|
|
4580
|
+
* The last `limit` entries pushed, and how many came before them: what a wait that timed out
|
|
4581
|
+
* answers with (docs/usage/http-api.md).
|
|
4582
|
+
*/
|
|
4583
|
+
var LastSeen = class {
|
|
4584
|
+
limit;
|
|
4585
|
+
#entries = [];
|
|
4586
|
+
#dropped = 0;
|
|
4587
|
+
constructor(limit) {
|
|
4588
|
+
this.limit = limit;
|
|
4589
|
+
}
|
|
4590
|
+
push(entry) {
|
|
4591
|
+
this.#entries.push(entry);
|
|
4592
|
+
if (this.#entries.length >= 2 * this.limit) this.#trim();
|
|
4593
|
+
}
|
|
4594
|
+
result() {
|
|
4595
|
+
this.#trim();
|
|
4596
|
+
return {
|
|
4597
|
+
seen: this.#entries,
|
|
4598
|
+
omitted: this.#dropped
|
|
4599
|
+
};
|
|
4600
|
+
}
|
|
4601
|
+
#trim() {
|
|
4602
|
+
const over = this.#entries.length - this.limit;
|
|
4603
|
+
if (over <= 0) return;
|
|
4604
|
+
this.#entries.splice(0, over);
|
|
4605
|
+
this.#dropped += over;
|
|
4606
|
+
}
|
|
4607
|
+
};
|
|
4390
4608
|
// src/domain/text-match.ts
|
|
4391
4609
|
/** Longest `regex` a wait accepts. */
|
|
4392
4610
|
const MAX_REGEX_LENGTH = API_LIMITS.wait.regexLength;
|
|
@@ -4427,28 +4645,6 @@ const WAIT_TIMEOUT_MS = API_LIMITS.wait.timeoutMs;
|
|
|
4427
4645
|
/** How many of the entries a wait saw its timeout answer holds at most: the last ones. */
|
|
4428
4646
|
const WAIT_SEEN_LIMIT = API_LIMITS.wait.seen;
|
|
4429
4647
|
// src/application/services/wait-for-speech-service.ts
|
|
4430
|
-
/** The last {@link WAIT_SEEN_LIMIT} entries pushed, and how many came before them. */
|
|
4431
|
-
var LastSeen = class {
|
|
4432
|
-
#entries = [];
|
|
4433
|
-
#dropped = 0;
|
|
4434
|
-
push(entry) {
|
|
4435
|
-
this.#entries.push(entry);
|
|
4436
|
-
if (this.#entries.length >= 2 * WAIT_SEEN_LIMIT) this.#trim();
|
|
4437
|
-
}
|
|
4438
|
-
result() {
|
|
4439
|
-
this.#trim();
|
|
4440
|
-
return {
|
|
4441
|
-
seen: this.#entries,
|
|
4442
|
-
omitted: this.#dropped
|
|
4443
|
-
};
|
|
4444
|
-
}
|
|
4445
|
-
#trim() {
|
|
4446
|
-
const over = this.#entries.length - WAIT_SEEN_LIMIT;
|
|
4447
|
-
if (over <= 0) return;
|
|
4448
|
-
this.#entries.splice(0, over);
|
|
4449
|
-
this.#dropped += over;
|
|
4450
|
-
}
|
|
4451
|
-
};
|
|
4452
4648
|
/**
|
|
4453
4649
|
* Long-poll for a speech entry (`GET /api/v1/speech/wait`): looks through the buffer after
|
|
4454
4650
|
* `since`, then follows the new entries, with nothing missed or seen twice in between.
|
|
@@ -4474,127 +4670,66 @@ var WaitForSpeechService = class {
|
|
|
4474
4670
|
const matches = createSpeechMatcher(options);
|
|
4475
4671
|
const sessionId = this.deps.log.resolveFilter(options.session);
|
|
4476
4672
|
if (signal?.aborted) throw abortReason(signal);
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
const failed = (error) => fail(error instanceof Error ? error : new Error(String(error)));
|
|
4507
|
-
try {
|
|
4508
|
-
stop = followLog(this.deps, {
|
|
4509
|
-
since,
|
|
4510
|
-
sessionId
|
|
4511
|
-
}, (event) => {
|
|
4512
|
-
if (done || event.type !== "entry") return;
|
|
4513
|
-
seen.push(event.entry);
|
|
4514
|
-
if (!matches(event.entry)) return;
|
|
4515
|
-
finish();
|
|
4516
|
-
resolve({
|
|
4517
|
-
status: "matched",
|
|
4518
|
-
entry: event.entry
|
|
4519
|
-
});
|
|
4520
|
-
}, {
|
|
4521
|
-
pace: this.deps.pace?.(),
|
|
4522
|
-
onCaughtUp: startTimer,
|
|
4523
|
-
onError: failed
|
|
4524
|
-
});
|
|
4525
|
-
if (done) stop();
|
|
4526
|
-
} catch (error) {
|
|
4527
|
-
failed(error);
|
|
4528
|
-
}
|
|
4529
|
-
});
|
|
4673
|
+
const seen = new LastSeen(WAIT_SEEN_LIMIT);
|
|
4674
|
+
let match;
|
|
4675
|
+
/** The client's signal and the shutdown's. */
|
|
4676
|
+
const ended = linkSignals(this.deps.shutdown, signal);
|
|
4677
|
+
try {
|
|
4678
|
+
await followUntil(this.deps, {
|
|
4679
|
+
since,
|
|
4680
|
+
sessionId,
|
|
4681
|
+
signal: ended.signal,
|
|
4682
|
+
pace: this.deps.pace?.(),
|
|
4683
|
+
timeLeft: () => timeoutMs,
|
|
4684
|
+
startTimer: "caught up"
|
|
4685
|
+
}, (event) => {
|
|
4686
|
+
if (event.type !== "entry") return void 0;
|
|
4687
|
+
seen.push(event.entry);
|
|
4688
|
+
if (!matches(event.entry)) return void 0;
|
|
4689
|
+
match = event.entry;
|
|
4690
|
+
return "done";
|
|
4691
|
+
});
|
|
4692
|
+
} finally {
|
|
4693
|
+
ended.dispose();
|
|
4694
|
+
}
|
|
4695
|
+
return match ? {
|
|
4696
|
+
status: "matched",
|
|
4697
|
+
entry: match
|
|
4698
|
+
} : {
|
|
4699
|
+
status: "timeout",
|
|
4700
|
+
...seen.result()
|
|
4701
|
+
};
|
|
4530
4702
|
}
|
|
4531
4703
|
};
|
|
4532
|
-
// src/composition/
|
|
4533
|
-
/** A setting from flags, the environment or the config file is invalid. Nothing was started. */
|
|
4534
|
-
var ConfigError = class extends Error {
|
|
4535
|
-
name = "ConfigError";
|
|
4536
|
-
};
|
|
4537
|
-
/** `patch` checked, with an error that says where the bad setting came from. */
|
|
4538
|
-
function checked(patch, origin) {
|
|
4539
|
-
try {
|
|
4540
|
-
return validatePatch(patch);
|
|
4541
|
-
} catch (error) {
|
|
4542
|
-
throw new ConfigError(`${origin(error instanceof AppError ? error.details?.field : void 0)}: ${error.message}`, { cause: error });
|
|
4543
|
-
}
|
|
4544
|
-
}
|
|
4704
|
+
// src/composition/service-routes.ts
|
|
4545
4705
|
/**
|
|
4546
|
-
*
|
|
4547
|
-
*
|
|
4548
|
-
* `warnings` are returned too: there is no log yet, it is built from the result.
|
|
4706
|
+
* The child services' paths on the bridge's HTTP port (docs/usage/playwright-mcp.md): the
|
|
4707
|
+
* Playwright server's WebSocket at `/`, MCP's streamable HTTP at `/mcp`.
|
|
4549
4708
|
*/
|
|
4550
|
-
|
|
4551
|
-
let saved;
|
|
4552
|
-
const warnings = [];
|
|
4553
|
-
try {
|
|
4554
|
-
saved = await store.load((message) => warnings.push(message));
|
|
4555
|
-
} catch (error) {
|
|
4556
|
-
throw new ConfigError(error.message, { cause: error });
|
|
4557
|
-
}
|
|
4558
|
-
const { known, unknown, names: ignored } = splitUnknownSettings(saved);
|
|
4559
|
-
const file = checked(known, () => `Invalid setting in the config file ${store.location}`);
|
|
4560
|
-
const overrides = checked(overridesPatch, (field) => field?.includes(".") ? `Invalid ${sourceOf(field)}` : "Invalid setting");
|
|
4561
|
-
const config = mergeConfig(mergeConfig(DEFAULT_CONFIG, file), overrides);
|
|
4562
|
-
try {
|
|
4563
|
-
assertDistinctPorts(config);
|
|
4564
|
-
} catch (error) {
|
|
4565
|
-
throw new ConfigError(`Invalid setting: ${error.message}`, { cause: error });
|
|
4566
|
-
}
|
|
4567
|
-
return {
|
|
4568
|
-
config,
|
|
4569
|
-
file,
|
|
4570
|
-
overrides,
|
|
4571
|
-
unknown,
|
|
4572
|
-
ignored,
|
|
4573
|
-
warnings
|
|
4574
|
-
};
|
|
4575
|
-
}
|
|
4576
|
-
// src/composition/summary.ts
|
|
4577
|
-
const PATHS = {
|
|
4709
|
+
const SERVICE_ROUTES = {
|
|
4578
4710
|
playwright: {
|
|
4579
4711
|
path: PLAYWRIGHT_PATH,
|
|
4712
|
+
upstreamPath: "/",
|
|
4580
4713
|
scheme: "ws"
|
|
4581
4714
|
},
|
|
4582
4715
|
mcp: {
|
|
4583
4716
|
path: PLAYWRIGHT_MCP_PATH,
|
|
4717
|
+
upstreamPath: "/mcp",
|
|
4584
4718
|
scheme: "http"
|
|
4585
4719
|
}
|
|
4586
4720
|
};
|
|
4721
|
+
// src/composition/summary.ts
|
|
4587
4722
|
/**
|
|
4588
4723
|
* The block logged when the bridge is ready: what listens where, and which child services run.
|
|
4589
4724
|
* It is the one place to look for the URLs to use and for a component that did not start
|
|
4590
4725
|
* (docs/usage/operations.md#line-format).
|
|
4591
4726
|
*/
|
|
4592
4727
|
function readySummary(input) {
|
|
4593
|
-
const { config, ports,
|
|
4728
|
+
const { config, ports, services } = input;
|
|
4594
4729
|
const rows = [["speech capture", `${describeAddress(config.tcp.host, ports.tcp)} (${config.tcp.encoding})`], [input.webUi ? "HTTP API + web UI" : "HTTP API", reachableUrls("http", config.http.host, ports.http).join(", ")]];
|
|
4595
|
-
for (const name of
|
|
4596
|
-
const { path, scheme } =
|
|
4597
|
-
const { state, version } =
|
|
4730
|
+
for (const name of SERVICE_NAMES) {
|
|
4731
|
+
const { path, scheme } = SERVICE_ROUTES[name];
|
|
4732
|
+
const { state, version } = services[name];
|
|
4598
4733
|
const urls = reachableUrls(scheme, config.http.host, ports.http).map((url) => `${url}${path}`).join(", ");
|
|
4599
4734
|
let value;
|
|
4600
4735
|
if (!config[name].enabled) value = "off (disabled in the config)";
|
|
@@ -4746,6 +4881,12 @@ function bindExtendedKeyboard(koffi) {
|
|
|
4746
4881
|
keyUp: (key) => send(key, KEYEVENTF_KEYUP$1)
|
|
4747
4882
|
};
|
|
4748
4883
|
}
|
|
4884
|
+
// src/composition/koffi.ts
|
|
4885
|
+
/** Loads `koffi`, an optional dependency: rejects where it is not installed or can't run. */
|
|
4886
|
+
async function loadKoffi() {
|
|
4887
|
+
const module = await import("koffi");
|
|
4888
|
+
return module.default ?? module;
|
|
4889
|
+
}
|
|
4749
4890
|
// src/composition/input.ts
|
|
4750
4891
|
/**
|
|
4751
4892
|
* Loads `@jitsi/robotjs`, an optional dependency. When it can't be loaded (no prebuilt binary for
|
|
@@ -4771,8 +4912,7 @@ async function createInputInjector(logger) {
|
|
|
4771
4912
|
async function createExtendedKeyboard(logger) {
|
|
4772
4913
|
if (process.platform !== "win32") return void 0;
|
|
4773
4914
|
try {
|
|
4774
|
-
|
|
4775
|
-
return bindExtendedKeyboard(module.default ?? module);
|
|
4915
|
+
return bindExtendedKeyboard(await loadKoffi());
|
|
4776
4916
|
} catch (error) {
|
|
4777
4917
|
const reason = `koffi could not be loaded (${error instanceof Error ? error.message : String(error)})`;
|
|
4778
4918
|
logger.warn(`the keys numpadenter and numpaddivide are off: ${reason}`);
|
|
@@ -4854,7 +4994,6 @@ function bindWin32(koffi) {
|
|
|
4854
4994
|
const IsWindowVisible = user32.func("int __stdcall IsWindowVisible(intptr_t hWnd)");
|
|
4855
4995
|
const GetWindow = user32.func("intptr_t __stdcall GetWindow(intptr_t hWnd, uint32_t uCmd)");
|
|
4856
4996
|
const GetWindowTextW = user32.func("int __stdcall GetWindowTextW(intptr_t hWnd, _Out_ void *lpString, int nMaxCount)");
|
|
4857
|
-
const GetClassNameW = user32.func("int __stdcall GetClassNameW(intptr_t hWnd, _Out_ void *lpClassName, int nMaxCount)");
|
|
4858
4997
|
const IsIconic = user32.func("int __stdcall IsIconic(intptr_t hWnd)");
|
|
4859
4998
|
const ShowWindow = user32.func("int __stdcall ShowWindow(intptr_t hWnd, int nCmdShow)");
|
|
4860
4999
|
const keybd_event = user32.func("void __stdcall keybd_event(uint8_t bVk, uint8_t bScan, uint32_t dwFlags, uintptr_t dwExtraInfo)");
|
|
@@ -4903,7 +5042,6 @@ function bindWin32(koffi) {
|
|
|
4903
5042
|
isVisible: (hwnd) => IsWindowVisible(hwnd) !== 0,
|
|
4904
5043
|
ownerWindow: (hwnd) => Number(GetWindow(hwnd, GW_OWNER)),
|
|
4905
5044
|
title: (hwnd) => text(GetWindowTextW, hwnd),
|
|
4906
|
-
className: (hwnd) => text(GetClassNameW, hwnd),
|
|
4907
5045
|
isMinimized: (hwnd) => IsIconic(hwnd) !== 0,
|
|
4908
5046
|
restore: (hwnd) => void ShowWindow(hwnd, SW_RESTORE),
|
|
4909
5047
|
tapAlt() {
|
|
@@ -4970,8 +5108,7 @@ var Win32WindowSystem = class {
|
|
|
4970
5108
|
windows.push({
|
|
4971
5109
|
handle: hwnd,
|
|
4972
5110
|
pid: win32.owner(hwnd).pid,
|
|
4973
|
-
title: win32.title(hwnd)
|
|
4974
|
-
className: win32.className(hwnd)
|
|
5111
|
+
title: win32.title(hwnd)
|
|
4975
5112
|
});
|
|
4976
5113
|
}
|
|
4977
5114
|
return Promise.resolve(windows);
|
|
@@ -5015,8 +5152,7 @@ async function createWindowSystem(logger) {
|
|
|
5015
5152
|
return new DisabledWindowSystem("only on Windows");
|
|
5016
5153
|
}
|
|
5017
5154
|
try {
|
|
5018
|
-
const
|
|
5019
|
-
const windows = new Win32WindowSystem(bindWin32(module.default ?? module));
|
|
5155
|
+
const windows = new Win32WindowSystem(bindWin32(await loadKoffi()));
|
|
5020
5156
|
logger.info("bringing windows to the front is available (koffi)");
|
|
5021
5157
|
return windows;
|
|
5022
5158
|
} catch (error) {
|
|
@@ -5025,6 +5161,18 @@ async function createWindowSystem(logger) {
|
|
|
5025
5161
|
return new DisabledWindowSystem(reason);
|
|
5026
5162
|
}
|
|
5027
5163
|
}
|
|
5164
|
+
// src/adapters/out/log/terminal-text.ts
|
|
5165
|
+
/**
|
|
5166
|
+
* Escape sequences (CSI such as colours, OSC such as a window title, and the short ones) and the
|
|
5167
|
+
* other control characters, except tab. Text in log lines comes from outside: speech, session and
|
|
5168
|
+
* client names, the voice header, child process output. A terminal would act on what this removes
|
|
5169
|
+
* (docs/usage/operations.md#line-format).
|
|
5170
|
+
*/
|
|
5171
|
+
const CONTROL = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?|\u001b[@-_]?|\u009b[0-?]*[ -/]*[@-~]|[\u0000-\u0008\u000a-\u001f\u007f-\u009f]/g;
|
|
5172
|
+
/** `text` without escape sequences and control characters other than tab (one line). */
|
|
5173
|
+
function stripControlChars(text) {
|
|
5174
|
+
return text.replace(CONTROL, "");
|
|
5175
|
+
}
|
|
5028
5176
|
// src/adapters/out/log/format.ts
|
|
5029
5177
|
const ESC = "\x1B[";
|
|
5030
5178
|
const RESET = `${ESC}0m`;
|
|
@@ -5052,12 +5200,13 @@ function paint(text, colour, enabled) {
|
|
|
5052
5200
|
/**
|
|
5053
5201
|
* Formats one message as one or more log lines (without line breaks). Every line of a
|
|
5054
5202
|
* multi-line message gets the full prefix, timestamp and level. Padding is counted without
|
|
5055
|
-
* colour codes.
|
|
5203
|
+
* colour codes. Escape sequences and control characters in the message are removed: only the
|
|
5204
|
+
* bridge's own colours reach the terminal.
|
|
5056
5205
|
*/
|
|
5057
5206
|
function formatLogLines(prefix, level, time, message, colour) {
|
|
5058
5207
|
const tag = `[${prefix}]`;
|
|
5059
5208
|
const head = paint(tag, PREFIX_COLOURS[prefix], colour) + " ".repeat(PREFIX_WIDTH - tag.length) + `${time.toISOString()} ` + paint(level.toUpperCase(), LEVEL_COLOURS[level], colour) + " ".repeat(6 - level.length);
|
|
5060
|
-
return message.split(/\r?\n/).map((line) => head + line);
|
|
5209
|
+
return message.split(/\r?\n/).map((line) => head + stripControlChars(line));
|
|
5061
5210
|
}
|
|
5062
5211
|
// src/adapters/out/log/bridge-log.ts
|
|
5063
5212
|
const LEVEL_RANK = {
|
|
@@ -5240,6 +5389,13 @@ function createLogging(config, options) {
|
|
|
5240
5389
|
return log;
|
|
5241
5390
|
}
|
|
5242
5391
|
// src/adapters/out/terminal/terminal-prompt.ts
|
|
5392
|
+
/** Answers that quit instead of naming a port. */
|
|
5393
|
+
const QUIT = /* @__PURE__ */ new Set([
|
|
5394
|
+
"",
|
|
5395
|
+
"q",
|
|
5396
|
+
"quit",
|
|
5397
|
+
"exit"
|
|
5398
|
+
]);
|
|
5243
5399
|
/**
|
|
5244
5400
|
* Driven adapter: asks a question on the console and reads one line. Ctrl+C, end of input (Ctrl+D,
|
|
5245
5401
|
* Ctrl+Z on Windows) and the `signal` cancel it. It lets go of the input after each question, so
|
|
@@ -5250,6 +5406,18 @@ var TerminalPrompt = class {
|
|
|
5250
5406
|
constructor(options) {
|
|
5251
5407
|
this.options = options;
|
|
5252
5408
|
}
|
|
5409
|
+
async askForPort(failedPort) {
|
|
5410
|
+
for (;;) {
|
|
5411
|
+
const answer = await this.ask(`TCP port ${failedPort} can't be used. TCP port for the socket voice (Enter to quit): `);
|
|
5412
|
+
if (answer === void 0 || QUIT.has(answer.toLowerCase())) return void 0;
|
|
5413
|
+
if (/^\d+$/.test(answer)) return Number(answer);
|
|
5414
|
+
this.options.warn(`${JSON.stringify(answer)} is not a port number`);
|
|
5415
|
+
}
|
|
5416
|
+
}
|
|
5417
|
+
/**
|
|
5418
|
+
* Shows `question` and resolves with the trimmed answer, or with `undefined` if the person
|
|
5419
|
+
* cancels (Ctrl+C, end of input) or the start is cancelled.
|
|
5420
|
+
*/
|
|
5253
5421
|
async ask(question) {
|
|
5254
5422
|
const { input, output, flush, terminal, signal } = this.options;
|
|
5255
5423
|
if (signal?.aborted === true) return void 0;
|
|
@@ -5290,12 +5458,13 @@ var TerminalPrompt = class {
|
|
|
5290
5458
|
* The console prompt, or `undefined` when nobody can answer: stdin or stdout is not a terminal
|
|
5291
5459
|
* (a service, CI, a test, output piped to a file). `cancel` ends a pending question.
|
|
5292
5460
|
*/
|
|
5293
|
-
function createOperatorPrompt(cancel) {
|
|
5461
|
+
function createOperatorPrompt(warn, cancel) {
|
|
5294
5462
|
if (process.stdin.isTTY !== true || process.stdout.isTTY !== true) return void 0;
|
|
5295
5463
|
return new TerminalPrompt({
|
|
5296
5464
|
input: process.stdin,
|
|
5297
5465
|
output: process.stdout,
|
|
5298
5466
|
flush: flushTerminal,
|
|
5467
|
+
warn,
|
|
5299
5468
|
terminal: true,
|
|
5300
5469
|
...cancel === void 0 ? {} : { signal: cancel }
|
|
5301
5470
|
});
|
|
@@ -5309,25 +5478,28 @@ function yieldEvery(n) {
|
|
|
5309
5478
|
let count = 0;
|
|
5310
5479
|
return () => ++count % n === 0 ? setImmediate() : void 0;
|
|
5311
5480
|
}
|
|
5312
|
-
// src/composition/
|
|
5481
|
+
// src/composition/tcp-startup-hints.ts
|
|
5482
|
+
const VOICE_DOCS = "docs/usage/vm-setup.md#more-voices--other-ports";
|
|
5313
5483
|
/**
|
|
5314
|
-
* The
|
|
5315
|
-
*
|
|
5484
|
+
* The ways to set the TCP port by hand, as startup names them. `pinnedBy`: what sets `tcp.port`
|
|
5485
|
+
* if a flag or an environment variable does, for example `--tcp-port`.
|
|
5316
5486
|
*/
|
|
5487
|
+
function tcpStartupHints(configLocation, pinnedBy) {
|
|
5488
|
+
return {
|
|
5489
|
+
...pinnedBy === void 0 ? {} : { pinned: `${pinnedBy} sets this port: choose a free one there` },
|
|
5490
|
+
choosePort: `Start with --tcp-port <port>, or set tcp.port in ${configLocation}`,
|
|
5491
|
+
pointVoice: `point the socket voice to it (${VOICE_DOCS})`,
|
|
5492
|
+
keepPort: (port) => `start with --tcp-port ${port} next time`
|
|
5493
|
+
};
|
|
5494
|
+
}
|
|
5495
|
+
// src/composition/proxies.ts
|
|
5496
|
+
/** The pass-through of each child service on the bridge's HTTP port. */
|
|
5317
5497
|
function proxyRoutes(services) {
|
|
5318
|
-
return
|
|
5319
|
-
name: SERVICE_TITLES
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
target: () => services.reachability("playwright")
|
|
5324
|
-
}, {
|
|
5325
|
-
name: SERVICE_TITLES.mcp,
|
|
5326
|
-
path: PLAYWRIGHT_MCP_PATH,
|
|
5327
|
-
upstreamPath: "/mcp",
|
|
5328
|
-
scheme: "http",
|
|
5329
|
-
target: () => services.reachability("mcp")
|
|
5330
|
-
}];
|
|
5498
|
+
return SERVICE_NAMES.map((name) => ({
|
|
5499
|
+
name: SERVICE_TITLES[name],
|
|
5500
|
+
...SERVICE_ROUTES[name],
|
|
5501
|
+
target: () => services.reachability(name)
|
|
5502
|
+
}));
|
|
5331
5503
|
}
|
|
5332
5504
|
// src/adapters/shared/net/port-probe.ts
|
|
5333
5505
|
/** Where to probe a listener on a wildcard host: the loopback address of that family. */
|
|
@@ -5351,196 +5523,50 @@ function portOpen(host, port, timeoutMs = 1e3) {
|
|
|
5351
5523
|
socket.once("error", () => done(false));
|
|
5352
5524
|
});
|
|
5353
5525
|
}
|
|
5354
|
-
// src/adapters/out/process/child-process-
|
|
5355
|
-
|
|
5356
|
-
const
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
constructor(options) {
|
|
5382
|
-
this.options = options;
|
|
5383
|
-
this.settings = options.settings;
|
|
5384
|
-
}
|
|
5385
|
-
pid() {
|
|
5386
|
-
return this.state === "running" ? this.child?.pid ?? null : null;
|
|
5387
|
-
}
|
|
5388
|
-
status() {
|
|
5389
|
-
const { version, port } = this.active ?? this.resolved();
|
|
5390
|
-
return {
|
|
5391
|
-
state: this.state,
|
|
5392
|
-
version,
|
|
5393
|
-
port,
|
|
5394
|
-
restarts: this.restarts,
|
|
5395
|
-
exitCode: this.exitCode,
|
|
5396
|
-
lastError: this.lastError
|
|
5397
|
-
};
|
|
5398
|
-
}
|
|
5399
|
-
start() {
|
|
5400
|
-
if (this.state === "running") return Promise.resolve();
|
|
5401
|
-
const settled = new Promise((resolve) => this.waiters.push(resolve));
|
|
5402
|
-
if (this.state === "stopped" || this.state === "failed") {
|
|
5403
|
-
this.restarts = 0;
|
|
5404
|
-
this.crashesInRow = 0;
|
|
5405
|
-
this.exitCode = null;
|
|
5406
|
-
this.lastError = null;
|
|
5407
|
-
this.launch();
|
|
5408
|
-
}
|
|
5409
|
-
return settled;
|
|
5410
|
-
}
|
|
5411
|
-
async stop() {
|
|
5412
|
-
this.generation++;
|
|
5413
|
-
clearTimeout(this.restartTimer);
|
|
5414
|
-
this.abort?.abort();
|
|
5415
|
-
this.abort = null;
|
|
5416
|
-
const child = this.child;
|
|
5417
|
-
this.child = null;
|
|
5418
|
-
this.runningSince = null;
|
|
5419
|
-
this.active = null;
|
|
5420
|
-
const wasStopped = this.state === "stopped";
|
|
5421
|
-
this.setState("stopped");
|
|
5422
|
-
if (!wasStopped) this.options.logger.info(`${this.options.name} stopped`);
|
|
5423
|
-
if (child) await killTree(child);
|
|
5424
|
-
}
|
|
5425
|
-
resolved() {
|
|
5426
|
-
const { host, port, version } = this.settings;
|
|
5427
|
-
return {
|
|
5428
|
-
host,
|
|
5429
|
-
port,
|
|
5430
|
-
version: version ?? this.options.defaultVersion
|
|
5431
|
-
};
|
|
5432
|
-
}
|
|
5433
|
-
setState(state) {
|
|
5434
|
-
this.state = state;
|
|
5435
|
-
if (state === "running" || state === "failed" || state === "stopped") for (const resolve of this.waiters.splice(0)) resolve();
|
|
5436
|
-
}
|
|
5437
|
-
launch() {
|
|
5438
|
-
const generation = ++this.generation;
|
|
5439
|
-
const current = () => generation === this.generation;
|
|
5440
|
-
const settings = this.resolved();
|
|
5441
|
-
this.active = settings;
|
|
5442
|
-
const abort = new AbortController();
|
|
5443
|
-
this.abort = abort;
|
|
5444
|
-
this.setState("starting");
|
|
5445
|
-
this.launchedAt = Date.now();
|
|
5446
|
-
this.options.logger.info(`starting ${this.options.name} ${settings.version}`);
|
|
5447
|
-
const failed = (how, error) => {
|
|
5448
|
-
if (!current()) return;
|
|
5449
|
-
const cause = `${how}: ${error instanceof Error ? error.message : String(error)}`;
|
|
5450
|
-
this.options.logger.error(`${this.options.name} ${cause}`);
|
|
5451
|
-
this.crashed(null, "failed to start", cause);
|
|
5452
|
-
};
|
|
5453
|
-
this.options.prepare(settings, abort.signal).then(async (command) => {
|
|
5454
|
-
if (!current()) return;
|
|
5455
|
-
if (await portOpen(settings.host, settings.port)) {
|
|
5456
|
-
if (!current()) return;
|
|
5457
|
-
const cause = `port ${settings.port} is already in use (a leftover process of an earlier run, or another program)`;
|
|
5458
|
-
this.options.logger.error(`${this.options.name}: ${cause}`);
|
|
5459
|
-
this.crashed(null, "could not start", cause);
|
|
5460
|
-
return;
|
|
5461
|
-
}
|
|
5462
|
-
if (current()) this.spawn(command, settings, generation);
|
|
5463
|
-
}, (error) => failed("could not be prepared", error)).catch((error) => failed("could not be started", error));
|
|
5464
|
-
}
|
|
5465
|
-
spawn(command, settings, generation) {
|
|
5466
|
-
const current = () => generation === this.generation;
|
|
5467
|
-
const child = spawn(command.command, [...command.args], {
|
|
5468
|
-
...treeSpawnOptions,
|
|
5469
|
-
stdio: [
|
|
5470
|
-
"ignore",
|
|
5471
|
-
"pipe",
|
|
5472
|
-
"pipe"
|
|
5473
|
-
]
|
|
5474
|
-
});
|
|
5475
|
-
this.child = child;
|
|
5476
|
-
trackTree(child);
|
|
5477
|
-
pipeLines(child, this.options.output);
|
|
5478
|
-
let exited = false;
|
|
5479
|
-
let cause;
|
|
5480
|
-
const onExit = (code, signal) => {
|
|
5481
|
-
if (exited) return;
|
|
5482
|
-
exited = true;
|
|
5483
|
-
if (!current()) return;
|
|
5484
|
-
this.child = null;
|
|
5485
|
-
killTree(child);
|
|
5486
|
-
const what = code !== null ? `exited with code ${code}` : signal !== null ? `was killed (${signal})` : "failed to start";
|
|
5487
|
-
this.crashed(code, what, cause);
|
|
5488
|
-
};
|
|
5489
|
-
child.once("exit", onExit);
|
|
5490
|
-
child.once("error", (error) => {
|
|
5491
|
-
const failure = `could not be started: ${error.message}`;
|
|
5492
|
-
this.options.logger.error(`${this.options.name} ${failure}`);
|
|
5493
|
-
if (child.pid === void 0) {
|
|
5494
|
-
cause = failure;
|
|
5495
|
-
onExit(null, null);
|
|
5496
|
-
}
|
|
5497
|
-
});
|
|
5498
|
-
this.waitForPort(settings, generation, () => exited).then((open) => {
|
|
5499
|
-
if (!current() || exited) return;
|
|
5500
|
-
if (open) {
|
|
5501
|
-
this.runningSince = Date.now();
|
|
5502
|
-
this.setState("running");
|
|
5503
|
-
const seconds = ((Date.now() - this.launchedAt) / 1e3).toFixed(1);
|
|
5504
|
-
this.options.logger.info(`${this.options.name} running (${seconds}s)`);
|
|
5505
|
-
} else {
|
|
5506
|
-
cause = `did not open port ${settings.port} in time`;
|
|
5507
|
-
this.options.logger.error(`${this.options.name} ${cause}, killing it`);
|
|
5508
|
-
killTree(child);
|
|
5509
|
-
}
|
|
5526
|
+
// src/adapters/out/process/child-process-runner.ts
|
|
5527
|
+
function run(command, { output, hiddenEnv }) {
|
|
5528
|
+
const env = { ...process.env };
|
|
5529
|
+
for (const name of hiddenEnv ?? []) delete env[name];
|
|
5530
|
+
const child = spawn(command.command, [...command.args], {
|
|
5531
|
+
...treeSpawnOptions,
|
|
5532
|
+
env,
|
|
5533
|
+
stdio: [
|
|
5534
|
+
"ignore",
|
|
5535
|
+
"pipe",
|
|
5536
|
+
"pipe"
|
|
5537
|
+
]
|
|
5538
|
+
});
|
|
5539
|
+
trackTree(child);
|
|
5540
|
+
pipeLines(child, output);
|
|
5541
|
+
const exited = new Promise((resolve) => {
|
|
5542
|
+
child.once("exit", (code, signal) => resolve({
|
|
5543
|
+
code,
|
|
5544
|
+
signal
|
|
5545
|
+
}));
|
|
5546
|
+
child.on("error", (error) => {
|
|
5547
|
+
if (child.pid === void 0) resolve({
|
|
5548
|
+
code: null,
|
|
5549
|
+
signal: null,
|
|
5550
|
+
failure: error.message
|
|
5551
|
+
});
|
|
5552
|
+
else output.warn(`process error: ${error.message}`);
|
|
5510
5553
|
});
|
|
5511
|
-
}
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
const decision = nextAfterCrash(this.crashesInRow, ranForMs, this.options.policy);
|
|
5528
|
-
this.crashesInRow = decision.crashesInRow;
|
|
5529
|
-
if (decision.action === "fail") {
|
|
5530
|
-
logger.error(`${name} ${what}, ${decision.crashesInRow} crashes in a row: giving up. Restart the bridge to try again`);
|
|
5531
|
-
this.setState("failed");
|
|
5532
|
-
return;
|
|
5533
|
-
}
|
|
5534
|
-
logger.error(`${name} ${what}, restart ${this.restarts + 1} in ${formatDelay(decision.delayMs)}`);
|
|
5535
|
-
this.setState("crashed");
|
|
5536
|
-
this.restartTimer = setTimeout(() => {
|
|
5537
|
-
this.restarts++;
|
|
5538
|
-
this.launch();
|
|
5539
|
-
}, decision.delayMs);
|
|
5540
|
-
}
|
|
5541
|
-
};
|
|
5542
|
-
function formatDelay(ms) {
|
|
5543
|
-
return ms >= 1e3 ? `${ms / 1e3} s` : `${ms} ms`;
|
|
5554
|
+
});
|
|
5555
|
+
return {
|
|
5556
|
+
pid: child.pid ?? null,
|
|
5557
|
+
exited,
|
|
5558
|
+
kill: () => killTree(child)
|
|
5559
|
+
};
|
|
5560
|
+
}
|
|
5561
|
+
/** A child service as processes without a shell, whose whole tree `kill` ends. */
|
|
5562
|
+
function childProcessRunner(options) {
|
|
5563
|
+
return {
|
|
5564
|
+
prepare: async (settings, signal) => {
|
|
5565
|
+
const command = await options.prepare(settings, signal);
|
|
5566
|
+
return () => run(command, options);
|
|
5567
|
+
},
|
|
5568
|
+
portOpen
|
|
5569
|
+
};
|
|
5544
5570
|
}
|
|
5545
5571
|
// src/adapters/out/process/quiet-output.ts
|
|
5546
5572
|
/**
|
|
@@ -5635,7 +5661,7 @@ function bundledMcp() {
|
|
|
5635
5661
|
};
|
|
5636
5662
|
}
|
|
5637
5663
|
/**
|
|
5638
|
-
*
|
|
5664
|
+
* Playwright MCP in HTTP mode, the bundled version, as a child service. Each start first runs
|
|
5639
5665
|
* `cli.js install-browser --no-shell chromium`, which installs the Chromium of MCP's own
|
|
5640
5666
|
* Playwright and skips a build that is already there. It listens on loopback, and clients reach
|
|
5641
5667
|
* it through the bridge, which sends a loopback `Host`: MCP's own host check (by default
|
|
@@ -5667,17 +5693,16 @@ function playwrightMcp(options) {
|
|
|
5667
5693
|
]
|
|
5668
5694
|
};
|
|
5669
5695
|
};
|
|
5670
|
-
return
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
});
|
|
5696
|
+
return {
|
|
5697
|
+
runner: childProcessRunner({
|
|
5698
|
+
prepare: options.launch ?? prepare,
|
|
5699
|
+
output,
|
|
5700
|
+
hiddenEnv: options.hiddenEnv
|
|
5701
|
+
}),
|
|
5702
|
+
defaultVersion: version
|
|
5703
|
+
};
|
|
5679
5704
|
}
|
|
5680
|
-
// src/
|
|
5705
|
+
// src/adapters/out/npm/exact-version.ts
|
|
5681
5706
|
/**
|
|
5682
5707
|
* An exact npm version (`1.56.1`, `1.57.0-beta-1`). Versions end up on an `npm install` command
|
|
5683
5708
|
* line (`playwright.version`, `adapters/out/npm`), so nothing else may get through.
|
|
@@ -5793,7 +5818,7 @@ async function ensurePlaywright(options) {
|
|
|
5793
5818
|
* version (docs/usage/playwright-mcp.md#playwright-server).
|
|
5794
5819
|
*/
|
|
5795
5820
|
const DEFAULT_PLAYWRIGHT_VERSION = "1.65.1";
|
|
5796
|
-
/**
|
|
5821
|
+
/** `playwright run-server` in the configured version, as a child service. */
|
|
5797
5822
|
function playwrightServer(options) {
|
|
5798
5823
|
const { cacheRoot } = options;
|
|
5799
5824
|
const output = quietOutput(options.output, listeningLine);
|
|
@@ -5817,34 +5842,236 @@ function playwrightServer(options) {
|
|
|
5817
5842
|
]
|
|
5818
5843
|
};
|
|
5819
5844
|
};
|
|
5820
|
-
return
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5845
|
+
return {
|
|
5846
|
+
runner: childProcessRunner({
|
|
5847
|
+
prepare: options.launch ?? prepare,
|
|
5848
|
+
output,
|
|
5849
|
+
hiddenEnv: options.hiddenEnv
|
|
5850
|
+
}),
|
|
5851
|
+
defaultVersion: DEFAULT_PLAYWRIGHT_VERSION
|
|
5852
|
+
};
|
|
5853
|
+
}
|
|
5854
|
+
// src/application/services/supervised-service.ts
|
|
5855
|
+
/** How long the port may take to open after the start, before it counts as a crash. */
|
|
5856
|
+
const READY_TIMEOUT_MS = 6e4;
|
|
5857
|
+
/**
|
|
5858
|
+
* Runs one child service (docs/usage/operations.md#child-service-crashes): prepare, spawn, wait for
|
|
5859
|
+
* its port, restart after a crash with a growing delay, give up after too many crashes in a row,
|
|
5860
|
+
* and end the whole process tree on stop.
|
|
5861
|
+
*/
|
|
5862
|
+
var SupervisedService = class {
|
|
5863
|
+
deps;
|
|
5864
|
+
/** Settings of the current run, until it is stopped. `status()` reports these. */
|
|
5865
|
+
active = null;
|
|
5866
|
+
state = "stopped";
|
|
5867
|
+
restarts = 0;
|
|
5868
|
+
exitCode = null;
|
|
5869
|
+
lastError = null;
|
|
5870
|
+
crashesInRow = 0;
|
|
5871
|
+
child = null;
|
|
5872
|
+
runningSince = null;
|
|
5873
|
+
/** When the current launch began, for the time to `running` in the log. */
|
|
5874
|
+
launchedAt = 0;
|
|
5875
|
+
/** Of the current launch: aborting it ends its preparation and its waits. */
|
|
5876
|
+
abort = null;
|
|
5877
|
+
/** Bumped by every launch and stop, so callbacks of an older run do nothing. */
|
|
5878
|
+
generation = 0;
|
|
5879
|
+
waiters = [];
|
|
5880
|
+
constructor(deps) {
|
|
5881
|
+
this.deps = deps;
|
|
5882
|
+
}
|
|
5883
|
+
pid() {
|
|
5884
|
+
return this.state === "running" ? this.child?.pid ?? null : null;
|
|
5885
|
+
}
|
|
5886
|
+
status() {
|
|
5887
|
+
const { version, port } = this.active ?? this.resolved();
|
|
5888
|
+
return {
|
|
5889
|
+
state: this.state,
|
|
5890
|
+
version,
|
|
5891
|
+
port,
|
|
5892
|
+
restarts: this.restarts,
|
|
5893
|
+
exitCode: this.exitCode,
|
|
5894
|
+
lastError: this.lastError
|
|
5895
|
+
};
|
|
5896
|
+
}
|
|
5897
|
+
start() {
|
|
5898
|
+
if (this.state === "running") return Promise.resolve();
|
|
5899
|
+
const settled = new Promise((resolve) => this.waiters.push(resolve));
|
|
5900
|
+
if (this.state === "stopped" || this.state === "failed") {
|
|
5901
|
+
this.restarts = 0;
|
|
5902
|
+
this.crashesInRow = 0;
|
|
5903
|
+
this.exitCode = null;
|
|
5904
|
+
this.lastError = null;
|
|
5905
|
+
this.launch();
|
|
5906
|
+
}
|
|
5907
|
+
return settled;
|
|
5908
|
+
}
|
|
5909
|
+
async stop() {
|
|
5910
|
+
this.generation++;
|
|
5911
|
+
this.abort?.abort();
|
|
5912
|
+
this.abort = null;
|
|
5913
|
+
const child = this.child;
|
|
5914
|
+
this.child = null;
|
|
5915
|
+
this.runningSince = null;
|
|
5916
|
+
this.active = null;
|
|
5917
|
+
const wasStopped = this.state === "stopped";
|
|
5918
|
+
this.setState("stopped");
|
|
5919
|
+
if (!wasStopped) this.deps.logger.info(`${this.deps.name} stopped`);
|
|
5920
|
+
if (child) await child.kill();
|
|
5921
|
+
}
|
|
5922
|
+
resolved() {
|
|
5923
|
+
const { host, port, version } = this.deps.settings;
|
|
5924
|
+
return {
|
|
5925
|
+
host,
|
|
5926
|
+
port,
|
|
5927
|
+
version: version ?? this.deps.defaultVersion
|
|
5928
|
+
};
|
|
5929
|
+
}
|
|
5930
|
+
setState(state) {
|
|
5931
|
+
this.state = state;
|
|
5932
|
+
if (state === "running" || state === "failed" || state === "stopped") for (const resolve of this.waiters.splice(0)) resolve();
|
|
5933
|
+
}
|
|
5934
|
+
launch() {
|
|
5935
|
+
const generation = ++this.generation;
|
|
5936
|
+
const current = () => generation === this.generation;
|
|
5937
|
+
const { name, runner, logger } = this.deps;
|
|
5938
|
+
const settings = this.resolved();
|
|
5939
|
+
this.active = settings;
|
|
5940
|
+
const abort = new AbortController();
|
|
5941
|
+
this.abort = abort;
|
|
5942
|
+
this.setState("starting");
|
|
5943
|
+
this.launchedAt = this.now();
|
|
5944
|
+
logger.info(`starting ${name} ${settings.version}`);
|
|
5945
|
+
const failed = (how, error) => {
|
|
5946
|
+
if (!current()) return;
|
|
5947
|
+
const cause = `${how}: ${error instanceof Error ? error.message : String(error)}`;
|
|
5948
|
+
logger.error(`${name} ${cause}`);
|
|
5949
|
+
this.crashed(null, "failed to start", cause);
|
|
5950
|
+
};
|
|
5951
|
+
runner.prepare(settings, abort.signal).then(async (spawn) => {
|
|
5952
|
+
if (!current()) return;
|
|
5953
|
+
if (await runner.portOpen(settings.host, settings.port)) {
|
|
5954
|
+
if (!current()) return;
|
|
5955
|
+
const cause = `port ${settings.port} is already in use (a leftover process of an earlier run, or another program)`;
|
|
5956
|
+
logger.error(`${name}: ${cause}`);
|
|
5957
|
+
this.crashed(null, "could not start", cause);
|
|
5958
|
+
return;
|
|
5959
|
+
}
|
|
5960
|
+
if (current()) this.watch(spawn(), settings, generation, abort.signal);
|
|
5961
|
+
}, (error) => failed("could not be prepared", error)).catch((error) => failed("could not be started", error));
|
|
5962
|
+
}
|
|
5963
|
+
/** Follows a spawned child: until its port opens, and until it ends. */
|
|
5964
|
+
watch(child, settings, generation, signal) {
|
|
5965
|
+
const current = () => generation === this.generation;
|
|
5966
|
+
const { name, logger } = this.deps;
|
|
5967
|
+
this.child = child;
|
|
5968
|
+
let exited = false;
|
|
5969
|
+
let cause;
|
|
5970
|
+
child.exited.then(({ code, signal, failure }) => {
|
|
5971
|
+
exited = true;
|
|
5972
|
+
if (!current()) return;
|
|
5973
|
+
this.child = null;
|
|
5974
|
+
child.kill();
|
|
5975
|
+
if (failure !== void 0) {
|
|
5976
|
+
cause = `could not be started: ${failure}`;
|
|
5977
|
+
logger.error(`${name} ${cause}`);
|
|
5978
|
+
}
|
|
5979
|
+
const what = code !== null ? `exited with code ${code}` : signal !== null ? `was killed (${signal})` : "failed to start";
|
|
5980
|
+
this.crashed(code, what, cause);
|
|
5981
|
+
});
|
|
5982
|
+
this.waitForPort(settings, signal, () => exited).then((open) => {
|
|
5983
|
+
if (!current() || exited) return;
|
|
5984
|
+
if (open) {
|
|
5985
|
+
this.runningSince = this.now();
|
|
5986
|
+
this.setState("running");
|
|
5987
|
+
const seconds = ((this.now() - this.launchedAt) / 1e3).toFixed(1);
|
|
5988
|
+
logger.info(`${name} running (${seconds}s)`);
|
|
5989
|
+
} else {
|
|
5990
|
+
cause = `did not open port ${settings.port} in time`;
|
|
5991
|
+
logger.error(`${name} ${cause}, killing it`);
|
|
5992
|
+
child.kill();
|
|
5993
|
+
}
|
|
5994
|
+
});
|
|
5995
|
+
}
|
|
5996
|
+
async waitForPort(settings, signal, exited) {
|
|
5997
|
+
const { runner, clock, probeIntervalMs = 200 } = this.deps;
|
|
5998
|
+
const deadline = this.now() + READY_TIMEOUT_MS;
|
|
5999
|
+
while (!signal.aborted && !exited() && this.now() < deadline) {
|
|
6000
|
+
if (await runner.portOpen(settings.host, settings.port)) return true;
|
|
6001
|
+
await clock.sleep(probeIntervalMs, signal).catch(() => void 0);
|
|
6002
|
+
}
|
|
6003
|
+
return false;
|
|
6004
|
+
}
|
|
6005
|
+
/** `what` goes to the log, `cause` to the status. */
|
|
6006
|
+
crashed(code, what, cause = what) {
|
|
6007
|
+
const { name, logger, clock, policy } = this.deps;
|
|
6008
|
+
const ranForMs = this.runningSince === null ? 0 : this.now() - this.runningSince;
|
|
6009
|
+
this.runningSince = null;
|
|
6010
|
+
this.exitCode = code;
|
|
6011
|
+
this.lastError = cause;
|
|
6012
|
+
const decision = nextAfterCrash(this.crashesInRow, ranForMs, policy);
|
|
6013
|
+
this.crashesInRow = decision.crashesInRow;
|
|
6014
|
+
if (decision.action === "fail") {
|
|
6015
|
+
logger.error(`${name} ${what}, ${decision.crashesInRow} crashes in a row: giving up. Restart the bridge to try again`);
|
|
6016
|
+
this.setState("failed");
|
|
6017
|
+
return;
|
|
6018
|
+
}
|
|
6019
|
+
logger.error(`${name} ${what}, restart ${this.restarts + 1} in ${formatDelay(decision.delayMs)}`);
|
|
6020
|
+
this.setState("crashed");
|
|
6021
|
+
clock.sleep(decision.delayMs, this.abort?.signal).then(() => {
|
|
6022
|
+
this.restarts++;
|
|
6023
|
+
this.launch();
|
|
6024
|
+
}, () => void 0);
|
|
6025
|
+
}
|
|
6026
|
+
now() {
|
|
6027
|
+
return this.deps.clock.now().getTime();
|
|
6028
|
+
}
|
|
6029
|
+
};
|
|
6030
|
+
function formatDelay(ms) {
|
|
6031
|
+
return ms >= 1e3 ? `${ms / 1e3} s` : `${ms} ms`;
|
|
6032
|
+
}
|
|
6033
|
+
// src/composition/service-settings.ts
|
|
6034
|
+
/** A service's settings from the config: the Playwright server in the configured version, MCP in the bundled one. */
|
|
6035
|
+
function serviceSettings(name, config) {
|
|
6036
|
+
if (name === "playwright") {
|
|
6037
|
+
const { port, version } = config.playwright;
|
|
6038
|
+
return {
|
|
6039
|
+
host: CHILD_HOST,
|
|
6040
|
+
port,
|
|
6041
|
+
version
|
|
6042
|
+
};
|
|
6043
|
+
}
|
|
6044
|
+
return {
|
|
6045
|
+
host: CHILD_HOST,
|
|
6046
|
+
port: config.mcp.port,
|
|
6047
|
+
version: null
|
|
6048
|
+
};
|
|
5829
6049
|
}
|
|
5830
6050
|
// src/composition/services.ts
|
|
5831
6051
|
/** One supervisor per child service, not started yet (`ChildServicesService` runs them). */
|
|
5832
|
-
function createSupervisors(config, options, log) {
|
|
6052
|
+
function createSupervisors(config, options, log, clock) {
|
|
5833
6053
|
const logger = log.for("bridge");
|
|
6054
|
+
const supervise = (name, program) => new SupervisedService({
|
|
6055
|
+
name,
|
|
6056
|
+
settings: serviceSettings(name, config),
|
|
6057
|
+
...program,
|
|
6058
|
+
clock,
|
|
6059
|
+
logger
|
|
6060
|
+
});
|
|
6061
|
+
const playwright = playwrightServer({
|
|
6062
|
+
cacheRoot: options.playwrightDir ?? defaultPlaywrightDir(),
|
|
6063
|
+
output: log.for("playwright-server"),
|
|
6064
|
+
hiddenEnv: UI_ENV_NAMES,
|
|
6065
|
+
...options.playwrightLaunch ? { launch: options.playwrightLaunch } : {}
|
|
6066
|
+
});
|
|
6067
|
+
const mcp = playwrightMcp({
|
|
6068
|
+
output: log.for("playwright-mcp"),
|
|
6069
|
+
hiddenEnv: UI_ENV_NAMES,
|
|
6070
|
+
...options.mcpLaunch ? { launch: options.mcpLaunch } : {}
|
|
6071
|
+
});
|
|
5834
6072
|
return {
|
|
5835
|
-
playwright:
|
|
5836
|
-
|
|
5837
|
-
cacheRoot: options.playwrightDir ?? defaultPlaywrightDir(),
|
|
5838
|
-
logger,
|
|
5839
|
-
output: log.for("playwright-server"),
|
|
5840
|
-
...options.playwrightLaunch ? { launch: options.playwrightLaunch } : {}
|
|
5841
|
-
}),
|
|
5842
|
-
mcp: playwrightMcp({
|
|
5843
|
-
settings: serviceSettings("mcp", config),
|
|
5844
|
-
logger,
|
|
5845
|
-
output: log.for("playwright-mcp"),
|
|
5846
|
-
...options.mcpLaunch ? { launch: options.mcpLaunch } : {}
|
|
5847
|
-
})
|
|
6073
|
+
playwright: supervise("playwright", playwright),
|
|
6074
|
+
mcp: supervise("mcp", mcp)
|
|
5848
6075
|
};
|
|
5849
6076
|
}
|
|
5850
6077
|
// src/domain/capture.ts
|
|
@@ -5986,6 +6213,9 @@ var SeqQueue = class {
|
|
|
5986
6213
|
* - At most one session is current. The log keeps the current session and the ended ones with
|
|
5987
6214
|
* entries still in the buffer; an ended session is forgotten once its last entry is dropped or
|
|
5988
6215
|
* cleared, and `id`s are never given out twice.
|
|
6216
|
+
* - Every change is reported to `onEvent`, once the log is in its new state, so no caller can
|
|
6217
|
+
* forget it. Deleting a session reports nothing
|
|
6218
|
+
* (docs/implementation/decisions.md#deleting-a-session-is-a-400-for-the-current-one-and-sends-no-event).
|
|
5989
6219
|
*
|
|
5990
6220
|
* Adding, dropping and the session statistics are O(1), reading after a `seq` is O(log n).
|
|
5991
6221
|
*/
|
|
@@ -6007,7 +6237,10 @@ var SpeechLog = class {
|
|
|
6007
6237
|
#currentId = null;
|
|
6008
6238
|
/** The newest session id given out, `runStart - 1` before the first session. */
|
|
6009
6239
|
#lastSessionId;
|
|
6010
|
-
|
|
6240
|
+
#onEvent;
|
|
6241
|
+
/** @param onEvent Gets every change (the composition root publishes it on the event bus). */
|
|
6242
|
+
constructor(maxEntries, runStart = 1, onEvent = () => {}) {
|
|
6243
|
+
this.#onEvent = onEvent;
|
|
6011
6244
|
this.#maxEntries = maxEntries;
|
|
6012
6245
|
this.#runStart = runStart;
|
|
6013
6246
|
this.#nextSeq = runStart;
|
|
@@ -6027,10 +6260,15 @@ var SpeechLog = class {
|
|
|
6027
6260
|
get lastSpeechAt() {
|
|
6028
6261
|
return this.#lastSpeechAt;
|
|
6029
6262
|
}
|
|
6030
|
-
/**
|
|
6263
|
+
/**
|
|
6264
|
+
* Stores an entry in the current session (if any) and returns it with its `seq`. A marker's text
|
|
6265
|
+
* is a label (`markerLabel`): trimmed, `INVALID_REQUEST` if empty or too long.
|
|
6266
|
+
*/
|
|
6031
6267
|
append(draft) {
|
|
6268
|
+
const text = draft.kind === "marker" ? markerLabel(draft.text) : draft.text;
|
|
6032
6269
|
const entry = {
|
|
6033
6270
|
...draft,
|
|
6271
|
+
text,
|
|
6034
6272
|
seq: this.#nextSeq++,
|
|
6035
6273
|
sessionId: this.#currentId
|
|
6036
6274
|
};
|
|
@@ -6043,6 +6281,10 @@ var SpeechLog = class {
|
|
|
6043
6281
|
own.push(entry);
|
|
6044
6282
|
if (entry.kind === "speech") this.#lastSpeechAt = entry.receivedAt;
|
|
6045
6283
|
this.#trim();
|
|
6284
|
+
this.#onEvent({
|
|
6285
|
+
type: "entry",
|
|
6286
|
+
entry
|
|
6287
|
+
});
|
|
6046
6288
|
return entry;
|
|
6047
6289
|
}
|
|
6048
6290
|
/**
|
|
@@ -6069,7 +6311,8 @@ var SpeechLog = class {
|
|
|
6069
6311
|
* session (`null`: outside sessions). `undefined` if there is none (also when it was dropped).
|
|
6070
6312
|
*/
|
|
6071
6313
|
latestMarker(label, sessionId) {
|
|
6072
|
-
|
|
6314
|
+
const text = markerLabel(label);
|
|
6315
|
+
return (sessionId === void 0 ? this.#entries : this.#bySession.get(sessionId))?.findLast((entry) => entry.kind === "marker" && entry.text === text);
|
|
6073
6316
|
}
|
|
6074
6317
|
/**
|
|
6075
6318
|
* Removes the entries (and markers) of the current session or of the entries outside sessions
|
|
@@ -6084,6 +6327,10 @@ var SpeechLog = class {
|
|
|
6084
6327
|
this.#entries.removeWhere((entry) => entry.sessionId === scope);
|
|
6085
6328
|
this.#bySession.delete(scope);
|
|
6086
6329
|
this.#droppedBySession.delete(scope);
|
|
6330
|
+
this.#onEvent({
|
|
6331
|
+
type: "clear",
|
|
6332
|
+
sessionId: scope
|
|
6333
|
+
});
|
|
6087
6334
|
return scope;
|
|
6088
6335
|
}
|
|
6089
6336
|
/** Removes all entries and the ended sessions. The current session stays current. */
|
|
@@ -6093,6 +6340,7 @@ var SpeechLog = class {
|
|
|
6093
6340
|
this.#droppedUpToSeq = 0;
|
|
6094
6341
|
this.#droppedBySession.clear();
|
|
6095
6342
|
for (const session of this.#sessions.values()) if (session.endedAt !== null) this.#sessions.delete(session.id);
|
|
6343
|
+
this.#onEvent({ type: "clear" });
|
|
6096
6344
|
}
|
|
6097
6345
|
stats() {
|
|
6098
6346
|
return {
|
|
@@ -6102,20 +6350,38 @@ var SpeechLog = class {
|
|
|
6102
6350
|
lastSeq: this.#entries.last()?.seq ?? null
|
|
6103
6351
|
};
|
|
6104
6352
|
}
|
|
6105
|
-
/**
|
|
6353
|
+
/**
|
|
6354
|
+
* Ends the current session, if any, and starts a new current one. Its `name`, `run` and `client`
|
|
6355
|
+
* are labels (`sessionLabel`): trimmed, `INVALID_REQUEST` if empty or too long.
|
|
6356
|
+
*/
|
|
6106
6357
|
startSession(session) {
|
|
6107
|
-
const
|
|
6358
|
+
const name = sessionLabel("name", session.name);
|
|
6359
|
+
const run = session.run === null ? null : sessionLabel("run", session.run);
|
|
6360
|
+
const client = session.client === null ? null : sessionLabel("client", session.client);
|
|
6361
|
+
const ended = this.#end(session.startedAt);
|
|
6108
6362
|
const started = {
|
|
6109
6363
|
...session,
|
|
6364
|
+
name,
|
|
6365
|
+
run,
|
|
6366
|
+
client,
|
|
6110
6367
|
id: ++this.#lastSessionId,
|
|
6111
6368
|
endedAt: null,
|
|
6112
6369
|
startSeq: this.headSeq
|
|
6113
6370
|
};
|
|
6114
6371
|
this.#sessions.set(started.id, started);
|
|
6115
6372
|
this.#currentId = started.id;
|
|
6373
|
+
const summary = summarize(started, EMPTY_SESSION_STATS);
|
|
6374
|
+
if (ended) this.#onEvent({
|
|
6375
|
+
type: "session",
|
|
6376
|
+
session: ended
|
|
6377
|
+
});
|
|
6378
|
+
this.#onEvent({
|
|
6379
|
+
type: "session",
|
|
6380
|
+
session: summary
|
|
6381
|
+
});
|
|
6116
6382
|
return {
|
|
6117
6383
|
ended,
|
|
6118
|
-
started:
|
|
6384
|
+
started: summary
|
|
6119
6385
|
};
|
|
6120
6386
|
}
|
|
6121
6387
|
/**
|
|
@@ -6124,6 +6390,15 @@ var SpeechLog = class {
|
|
|
6124
6390
|
* never gave out.
|
|
6125
6391
|
*/
|
|
6126
6392
|
endSession(endedAt, id) {
|
|
6393
|
+
const ended = this.#end(endedAt, id);
|
|
6394
|
+
if (ended) this.#onEvent({
|
|
6395
|
+
type: "session",
|
|
6396
|
+
session: ended
|
|
6397
|
+
});
|
|
6398
|
+
return ended;
|
|
6399
|
+
}
|
|
6400
|
+
/** {@link endSession} without reporting it, for a change that isn't complete yet. */
|
|
6401
|
+
#end(endedAt, id) {
|
|
6127
6402
|
if (id !== void 0) this.#requireIssued(id);
|
|
6128
6403
|
const current = this.currentSession();
|
|
6129
6404
|
if (!current || id !== void 0 && current.id !== id) return null;
|
|
@@ -6224,7 +6499,6 @@ async function flushOutput() {
|
|
|
6224
6499
|
await flushTerminal();
|
|
6225
6500
|
await flushConsole();
|
|
6226
6501
|
}
|
|
6227
|
-
const show = (value) => JSON.stringify(value);
|
|
6228
6502
|
/** A busy port needs no stack: the message says what to do. Anything else is unexpected. */
|
|
6229
6503
|
function describeStartFailure(error) {
|
|
6230
6504
|
if (error instanceof ListenError || error instanceof PortUnavailableError) return error.message;
|
|
@@ -6239,8 +6513,7 @@ async function startBridge(options) {
|
|
|
6239
6513
|
const { version } = options;
|
|
6240
6514
|
const seams = options.testSeams ?? {};
|
|
6241
6515
|
const store = seams.configStore ?? new FsConfigStore(options.configFile ?? defaultConfigFile());
|
|
6242
|
-
const
|
|
6243
|
-
const { config, file: savedFile, overrides, unknown: unknownSettings, ignored, warnings } = await loadConfig(store, options.overrides, sourceOf);
|
|
6516
|
+
const { config, file: savedFile, unknownSettings, pinned, warnings } = await loadConfig(store, options.overrides, options.overrideSources);
|
|
6244
6517
|
const log = createLogging(config, {
|
|
6245
6518
|
version,
|
|
6246
6519
|
configLocation: store.location,
|
|
@@ -6249,13 +6522,11 @@ async function startBridge(options) {
|
|
|
6249
6522
|
const bridgeLogger = log.for("bridge");
|
|
6250
6523
|
const configLogger = log.for("config");
|
|
6251
6524
|
for (const warning of warnings) configLogger.warn(warning);
|
|
6252
|
-
for (const name of ignored) configLogger.warn(`${name}: unknown setting in ${store.location}, ignored`);
|
|
6253
|
-
for (const { field, file: saved, override } of overriddenFields(savedFile, overrides)) configLogger.warn(`${field}: the config file sets ${show(saved)}, but ${sourceOf(field)} sets ${show(override)}, which wins`);
|
|
6254
6525
|
try {
|
|
6255
6526
|
const clock = seams.clock ?? new SystemClock();
|
|
6256
6527
|
const startedAt = clock.now();
|
|
6257
|
-
const speechLog = new SpeechLog(config.buffer.maxEntries, startedAt.getTime());
|
|
6258
6528
|
const events = new InProcessEventBus((error) => bridgeLogger.error(`event listener failed: ${String(error)}`));
|
|
6529
|
+
const speechLog = new SpeechLog(config.buffer.maxEntries, firstSeqOfRun(startedAt.getTime()), (event) => events.publish(event));
|
|
6259
6530
|
new TranscriptService({
|
|
6260
6531
|
events,
|
|
6261
6532
|
transcript: log.for("speech-capture", { channel: "speech" })
|
|
@@ -6276,20 +6547,23 @@ async function startBridge(options) {
|
|
|
6276
6547
|
});
|
|
6277
6548
|
const sessions = new SessionService({
|
|
6278
6549
|
log: speechLog,
|
|
6279
|
-
events,
|
|
6280
6550
|
clock,
|
|
6281
6551
|
logger: log.for("bridge")
|
|
6282
6552
|
});
|
|
6283
6553
|
const injector = seams.inputInjector ?? await createInputInjector(log.for("native-input"));
|
|
6284
6554
|
const windows = seams.windowSystem ?? await createWindowSystem(log.for("native-input"));
|
|
6285
|
-
const supervisors = createSupervisors(config, seams, log);
|
|
6555
|
+
const supervisors = createSupervisors(config, seams, log, clock);
|
|
6556
|
+
const inputQueue = new SerialInputQueue({
|
|
6557
|
+
shutdown: shutdown.signal,
|
|
6558
|
+
logger: log.for("native-input")
|
|
6559
|
+
});
|
|
6286
6560
|
const input = new NativeInputService({
|
|
6561
|
+
queue: inputQueue,
|
|
6287
6562
|
injector,
|
|
6288
6563
|
windows,
|
|
6289
6564
|
services: supervisors,
|
|
6290
6565
|
clock,
|
|
6291
|
-
logger: log.for("native-input")
|
|
6292
|
-
shutdown: shutdown.signal
|
|
6566
|
+
logger: log.for("native-input")
|
|
6293
6567
|
});
|
|
6294
6568
|
const captures = new InputCaptureService({
|
|
6295
6569
|
input,
|
|
@@ -6305,23 +6579,22 @@ async function startBridge(options) {
|
|
|
6305
6579
|
active: config,
|
|
6306
6580
|
file: savedFile,
|
|
6307
6581
|
unknownSettings,
|
|
6308
|
-
pinned
|
|
6582
|
+
pinned
|
|
6309
6583
|
});
|
|
6310
6584
|
const focus = new WindowFocusService({
|
|
6311
6585
|
windows,
|
|
6312
|
-
queue:
|
|
6586
|
+
queue: inputQueue,
|
|
6313
6587
|
services: supervisors,
|
|
6314
6588
|
clock,
|
|
6315
6589
|
logger: log.for("native-input")
|
|
6316
6590
|
});
|
|
6317
6591
|
const childServices = new ChildServicesService({
|
|
6318
6592
|
supervisors,
|
|
6319
|
-
config: () => configService.get()
|
|
6320
|
-
logger: bridgeLogger
|
|
6593
|
+
config: () => configService.get()
|
|
6321
6594
|
});
|
|
6322
6595
|
const captureState = new CaptureState(() => clock.now());
|
|
6323
6596
|
const tcp = new TcpListener(speech, captureState, log.for("speech-capture"));
|
|
6324
|
-
const prompt = seams.prompt === void 0 ? createOperatorPrompt(options.cancelStart) : seams.prompt;
|
|
6597
|
+
const prompt = seams.prompt === void 0 ? createOperatorPrompt((message) => configLogger.warn(message), options.cancelStart) : seams.prompt;
|
|
6325
6598
|
const tcpStartup = new TcpStartupService({
|
|
6326
6599
|
listener: {
|
|
6327
6600
|
start: (port) => tcp.start({
|
|
@@ -6331,12 +6604,13 @@ async function startBridge(options) {
|
|
|
6331
6604
|
stop: () => tcp.stop()
|
|
6332
6605
|
},
|
|
6333
6606
|
config: configService,
|
|
6334
|
-
|
|
6607
|
+
hints: tcpStartupHints(store.location, pinned.get("tcp.port")),
|
|
6335
6608
|
...prompt === null || prompt === void 0 ? {} : { prompt },
|
|
6336
6609
|
configLocation: store.location,
|
|
6337
6610
|
logger: configLogger
|
|
6338
6611
|
});
|
|
6339
6612
|
const status = new StatusService({
|
|
6613
|
+
state: () => lifecycle.state(),
|
|
6340
6614
|
capture: captureState,
|
|
6341
6615
|
log: speechLog,
|
|
6342
6616
|
supervisors,
|
|
@@ -6364,7 +6638,6 @@ async function startBridge(options) {
|
|
|
6364
6638
|
...seams.ssePingMs === void 0 ? {} : { pingMs: seams.ssePingMs }
|
|
6365
6639
|
});
|
|
6366
6640
|
const lifecycle = new BridgeLifecycleService({
|
|
6367
|
-
state: status,
|
|
6368
6641
|
tcp: tcpStartup,
|
|
6369
6642
|
http: {
|
|
6370
6643
|
start: () => http.start(config.http),
|
|
@@ -6376,7 +6649,7 @@ async function startBridge(options) {
|
|
|
6376
6649
|
readyMessage: (ports) => readySummary({
|
|
6377
6650
|
config: configService.get(),
|
|
6378
6651
|
ports,
|
|
6379
|
-
|
|
6652
|
+
services: status.status().services,
|
|
6380
6653
|
webUi: ui !== void 0,
|
|
6381
6654
|
nativeInput: injector.availability,
|
|
6382
6655
|
tookMs: clock.now().getTime() - startedAt.getTime()
|