@kabmo-labs/kabmo 0.53.0 → 0.53.2
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/client/index.html +1 -1
- package/dist/client/index.js +384 -384
- package/dist/client/static/js/{Body-sdq2yhmp.js → Body-vaa10tcd.js} +3 -3
- package/dist/client/static/js/{CsvGrid-afz6vr3m.js → CsvGrid-wabx4e6w.js} +1 -1
- package/dist/client/static/js/{DocxView-xwjgt7qq.js → DocxView-22b3mhh5.js} +1 -1
- package/dist/client/static/js/{DrawioView-7m4e8zcm.js → DrawioView-e02qhkp2.js} +1 -1
- package/dist/client/static/js/{HtmlPreview-tad0dezn.js → HtmlPreview-q7hwcf4s.js} +1 -1
- package/dist/client/static/js/{ImageView-7bpm4xhb.js → ImageView-fxb60ge7.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-ehxhj6t3.js → LayoutWrapper-cey5agsf.js} +2 -2
- package/dist/client/static/js/MergeDiffView-1z9mwf73.js +1 -0
- package/dist/client/static/js/{Modal-5qt3v5gn.js → Modal-e4yq7p5f.js} +9 -9
- package/dist/client/static/js/{PdfView-hbgnnana.js → PdfView-pf3angsq.js} +1 -1
- package/dist/client/static/js/{SessionsView-rv9jmr2e.js → SessionsView-mcvhpx0b.js} +1 -1
- package/dist/client/static/js/{SheetView-55e0a8as.js → SheetView-5ha5vvsr.js} +1 -1
- package/dist/client/static/js/{SvgPreview-10fa6mj1.js → SvgPreview-45wqjw0b.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-9w4p3dhe.js → abnfDiagram-O67JEVCF-gnf6krbs.js} +1 -1
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-5x6sb253.js → architectureDiagram-NJMV4G6O-00fd0wsg.js} +2 -2
- package/dist/client/static/js/{astro-m3fcq2sa.js → astro-asmathwv.js} +1 -1
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-2c6y4pkn.js → blockDiagram-BEXU5L5S-9c2sm96a.js} +2 -2
- package/dist/client/static/js/c-20y64hcp.js +1 -0
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-45rtm401.js → c4Diagram-YGBWAQC7-pemygn0s.js} +2 -2
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-rksw3aw9.js → classDiagram-v2-NBCMYWYE-h7r3sx3s.js} +2 -2
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-4hxtttt5.js → cose-bilkent-JH36ORCC-krx9crwv.js} +1 -1
- package/dist/client/static/js/cpp-ty6n0dg9.js +1 -0
- package/dist/client/static/js/css-ncvxaxt0.js +1 -0
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-5dhexpf2.js → cynefinDiagram-VND7K2PF-5rp2btew.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-1k3w4qm9.js → dagre-6A5THRUB-q57cnz52.js} +2 -2
- package/dist/client/static/js/{diagram-22UHCM2B-fw76k272.js → diagram-22UHCM2B-0bptn06k.js} +2 -2
- package/dist/client/static/js/{diagram-3UASUU5V-qnb2gn31.js → diagram-3UASUU5V-60snxawz.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-cavnxzpf.js → diagram-ATOU4E4O-bb0kewfp.js} +2 -2
- package/dist/client/static/js/{diagram-CDSNMT55-6dxaj054.js → diagram-CDSNMT55-3cdkns0z.js} +2 -2
- package/dist/client/static/js/{diagram-MLGK6HIB-f16fv9ay.js → diagram-MLGK6HIB-03mbhzeq.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-zsryj72g.js → diagram-MPIPVDR6-bcvzqqf4.js} +1 -1
- package/dist/client/static/js/{dockerfile-frznktsa.js → dockerfile-7kqkk4tz.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-1zz5h7sw.js → ebnfDiagram-ZINNZB2B-sg6kwnbx.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-25pehy1p.js → elk-276RUBZZ-5b8v0sdv.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-ezpjhgzw.js → erDiagram-OPXOYQCR-xbs156j5.js} +2 -2
- package/dist/client/static/js/flowDiagram-KWPJA3E3-sasgvf55.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-n11hq4ag.js → ganttDiagram-FUAMR5RP-4p7pfk6c.js} +1 -1
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-3znkxh7y.js → gitGraphDiagram-X574FWY7-3xqwr9pf.js} +1 -1
- package/dist/client/static/js/{index-10cxm9ty.js → index-0btbxkxf.js} +2 -2
- package/dist/client/static/js/{index-5pbf6dcz.js → index-1d8ff4t7.js} +3 -3
- package/dist/client/static/js/{index-9n1cg95f.js → index-1regq9wd.js} +1 -1
- package/dist/client/static/js/{index-4nvcwtvr.js → index-25zpywv7.js} +1 -1
- package/dist/client/static/js/{index-qj6b15r4.js → index-26a4afcr.js} +2 -2
- package/dist/client/static/js/{index-scmtzcv1.js → index-396g4zz4.js} +2 -2
- package/dist/client/static/js/{index-m1hd7ska.js → index-3amzzsdk.js} +25 -25
- package/dist/client/static/js/{index-vjmy9r20.js → index-3bmn5cc5.js} +1 -1
- package/dist/client/static/js/{index-qrpx4sk1.js → index-3x88t8g9.js} +2 -2
- package/dist/client/static/js/{index-e0h6xkpv.js → index-45vcpqp9.js} +1 -1
- package/dist/client/static/js/{index-7ag37ghj.js → index-4kchzh9y.js} +8 -8
- package/dist/client/static/js/{index-5hqjscys.js → index-5qtnmn76.js} +2 -2
- package/dist/client/static/js/{index-wvw70pgd.js → index-668fc1df.js} +2 -2
- package/dist/client/static/js/{index-b039ef9w.js → index-ayx3q8t9.js} +2 -2
- package/dist/client/static/js/{index-dzp9rwy0.js → index-c8ta3k4g.js} +161 -161
- package/dist/client/static/js/{index-ey0ckd66.js → index-cj8v7b50.js} +2 -2
- package/dist/client/static/js/{index-dkz8d77n.js → index-cy6ceab8.js} +1 -1
- package/dist/client/static/js/index-cysdvwqw.js +1 -0
- package/dist/client/static/js/{index-y79ebmam.js → index-e2esj214.js} +1 -1
- package/dist/client/static/js/{index-32gh2645.js → index-gzz6snng.js} +1 -1
- package/dist/client/static/js/{index-kyarw08m.js → index-hp3s5r3g.js} +2 -2
- package/dist/client/static/js/{index-5z7f6bq4.js → index-hwq7zgqd.js} +1 -1
- package/dist/client/static/js/{index-1qjxg7mh.js → index-j9t5xc3y.js} +1 -1
- package/dist/client/static/js/{index-58kgkwxt.js → index-jf8zcg99.js} +4 -4
- package/dist/client/static/js/{index-2k6wyyds.js → index-jg6ecfc7.js} +4 -4
- package/dist/client/static/js/{index-er7pj5k6.js → index-m6eh5g1q.js} +1 -1
- package/dist/client/static/js/{index-4faphth3.js → index-mgs5nscx.js} +1 -1
- package/dist/client/static/js/{index-me7ag6sy.js → index-mtjbp5ga.js} +1 -1
- package/dist/client/static/js/{index-dzsjyzht.js → index-ng3e6k6x.js} +2 -2
- package/dist/client/static/js/{index-z9msykm1.js → index-nmhwjwmt.js} +1 -1
- package/dist/client/static/js/{index-s78f7j47.js → index-nnhs52db.js} +1 -1
- package/dist/client/static/js/{index-8972fxm9.js → index-p75b7phb.js} +1 -1
- package/dist/client/static/js/{index-5j0wejvq.js → index-pak6t03c.js} +2 -2
- package/dist/client/static/js/{index-zkkttvtx.js → index-pdkt3r4r.js} +2 -2
- package/dist/client/static/js/{index-gmea6fjd.js → index-qj9tcz44.js} +5 -5
- package/dist/client/static/js/{index-ej1va073.js → index-rsyqf691.js} +2 -2
- package/dist/client/static/js/{index-tnhnysj1.js → index-rtpg4t84.js} +1 -1
- package/dist/client/static/js/{index-1e7fek0v.js → index-ryww3xxj.js} +1 -1
- package/dist/client/static/js/index-trrmbq0h.js +2 -0
- package/dist/client/static/js/{index-02skcm4d.js → index-vwxt5ss9.js} +1 -1
- package/dist/client/static/js/{index-acpn178r.js → index-x0y2c61e.js} +1 -1
- package/dist/client/static/js/{index-899yw6fh.js → index-x3g8fwkc.js} +2 -2
- package/dist/client/static/js/{index-j97qmbbv.js → index-xqkcx4az.js} +1 -1
- package/dist/client/static/js/{index-hqc2cazc.js → index-yf5a6t3p.js} +4 -4
- package/dist/client/static/js/{index-ht164kw9.js → index-z7gd7nvb.js} +1 -1
- package/dist/client/static/js/{index-1w92sjkm.js → index-zc3snsr9.js} +2 -2
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-kmv3jtrd.js → infoDiagram-VRGFBTTK-c362sv3t.js} +1 -1
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-5kp6geeh.js → ishikawaDiagram-OU5B5YK6-yc8ts8wj.js} +1 -1
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-6w5f1ddc.js → journeyDiagram-ZHPQQLJL-178c75fy.js} +2 -2
- package/dist/client/static/js/json-xha2drny.js +1 -0
- package/dist/client/static/js/{julia-nwh5w343.js → julia-d18zhpyp.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-6esn6xqn.js → kanban-definition-PNTS6WVX-w6g3n001.js} +2 -2
- package/dist/client/static/js/lua-njwwdj4s.js +1 -0
- package/dist/client/static/js/{mermaid.core-z83pf8ch.js → mermaid.core-vcdgn378.js} +7 -7
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-0h1nhw66.js → mindmap-definition-NLK3R4M7-t9e8arca.js} +1 -1
- package/dist/client/static/js/one-dark-pro-17hh3q12.js +1 -0
- package/dist/client/static/js/one-light-cntgvscy.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-xdcpr8my.js → pegDiagram-GJSIUBJH-nehn0x9n.js} +1 -1
- package/dist/client/static/js/{perl-wb4wtc9x.js → perl-sns2qvmf.js} +1 -1
- package/dist/client/static/js/{php-9g594k9f.js → php-3q6v9eey.js} +1 -1
- package/dist/client/static/js/{pieDiagram-5QR66LMP-0210zd5b.js → pieDiagram-5QR66LMP-p1t3ctd4.js} +1 -1
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-j0rtvvcm.js → quadrantDiagram-O4NWA36T-614rtbfe.js} +1 -1
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-mzxat5g5.js → railroadDiagram-XR7U4H2S-2vpr6pw8.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-zq5b9ts2.js → requirementDiagram-PLB6GJNP-b91s5q3p.js} +2 -2
- package/dist/client/static/js/{ruby-c4hxsegh.js → ruby-f9k99tfq.js} +1 -1
- package/dist/client/static/js/{rust-vmn352hx.js → rust-jj206pb7.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-06s3r7bv.js → sankeyDiagram-IPEJSGJF-4101kt9r.js} +2 -2
- package/dist/client/static/js/{sass-6yxywx7t.js → sass-2syegq28.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-7s4gz4t5.js → sequenceDiagram-PO4LG4MO-yq0cxg8c.js} +3 -3
- package/dist/client/static/js/{sizeCapture-INFHLROL-yensh9k2.js → sizeCapture-INFHLROL-jkvq39vz.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-1q8p06fk.js → stateDiagram-v2-GCMORJYK-y0h7w5rw.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-2mfxddzf.js → swimlanes-2SLR337P-1y073wzx.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-k2xf0gby.js → swimlanesDiagram-TC7HE7FX-8ahz3c68.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-xrk07evk.js → timeline-definition-EJHVYXUP-yjb0g0ys.js} +2 -2
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-ca9h5skn.js → usecaseDiagram-POWQR4AR-8xjkxrkv.js} +1 -1
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-c0y47znt.js → vennDiagram-UO4OBE2U-18wjbwtg.js} +1 -1
- package/dist/client/static/js/{vue-rcdqpz7q.js → vue-e8e3q3hj.js} +1 -1
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-mfk1ck3n.js → wardleyDiagram-VNRHLVJA-xqrfsrwp.js} +1 -1
- package/dist/client/static/js/xml-8516fzfp.js +1 -0
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-6f8xt89k.js → xychartDiagram-PMCCYNJV-azygghkz.js} +2 -2
- package/package.json +2 -2
- package/src/client/components/workspace/git-panel/index.test.ts +56 -7
- package/src/client/components/workspace/git-panel/index.tsx +9 -4
- package/src/client/components/workspace/repo-picker/index.test.tsx +29 -2
- package/src/client/hooks/chat/timeline/new-chat-open.ts +5 -3
- package/src/client/hooks/chat/timeline/new-chat.test.ts +18 -2
- package/src/client/hooks/chat/timeline/new-chat.ts +13 -12
- package/src/client/hooks/chat/timeline/scope.test.ts +100 -0
- package/src/client/hooks/chat/timeline/scope.ts +9 -9
- package/src/client/hooks/workspace/commit-box.ts +6 -1
- package/src/client/lib/tts/gapless.ts +205 -0
- package/src/client/lib/tts/player.test.ts +83 -64
- package/src/client/lib/tts/player.ts +48 -98
- package/src/server/lib/fs/fs-write-git.test.ts +15 -47
- package/src/server/lib/fs/git-ignore.test.ts +101 -0
- package/src/server/lib/fs/git-ignore.ts +38 -1
- package/src/server/lib/fs/git-repos.ts +32 -11
- package/src/server/lib/fs/listing.test.ts +19 -0
- package/src/shared/lib/workspace/active-project.test.ts +45 -0
- package/src/shared/lib/workspace/active-project.ts +21 -0
- package/dist/client/static/js/MergeDiffView-28xkyts9.js +0 -1
- package/dist/client/static/js/c-ypdp030b.js +0 -1
- package/dist/client/static/js/cpp-cxwev3gs.js +0 -1
- package/dist/client/static/js/css-6mxcqf8c.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-zh6hmn6g.js +0 -1
- package/dist/client/static/js/index-qva2vqbh.js +0 -2
- package/dist/client/static/js/index-xvh25zer.js +0 -1
- package/dist/client/static/js/json-mb8k0b1n.js +0 -1
- package/dist/client/static/js/lua-nxnqww9z.js +0 -1
- package/dist/client/static/js/one-dark-pro-wsgaqq27.js +0 -1
- package/dist/client/static/js/one-light-w8zdrvyc.js +0 -1
- package/dist/client/static/js/xml-vtrdnrn6.js +0 -1
|
@@ -27,6 +27,8 @@ import { GitPanel } from '@/client/components/workspace/git-panel';
|
|
|
27
27
|
import { ToastStack } from '@/client/components/common/ToastStack';
|
|
28
28
|
import { resetToasts } from '@/client/hooks/ui/toasts';
|
|
29
29
|
import { SessionStateProvider } from '@/client/components/common/session-state-provider/index';
|
|
30
|
+
import { REPO_SCOPE_STATE_KEY } from '@/client/hooks/workspace/repo-scope';
|
|
31
|
+
import { getSessionValue, resetSessionStateStore } from '@/shared/lib/workspace/session-state/store';
|
|
30
32
|
import { resetRealtimeClient } from '@/shared/lib/realtime/client';
|
|
31
33
|
import { gitTopic, reposTopic } from '@/shared/lib/realtime/protocol';
|
|
32
34
|
import { startRealtimeTestServer, type RealtimeTestServer } from '@/test-support/realtime-server';
|
|
@@ -75,6 +77,9 @@ afterEach(() => {
|
|
|
75
77
|
reads = [];
|
|
76
78
|
resetRealtimeClient();
|
|
77
79
|
resetToasts();
|
|
80
|
+
// A pick written by one case must not move the next case's panel: the slot
|
|
81
|
+
// is process state, keyed by session id, and every case here uses one id.
|
|
82
|
+
resetSessionStateStore();
|
|
78
83
|
server?.stop();
|
|
79
84
|
});
|
|
80
85
|
|
|
@@ -89,11 +94,30 @@ async function mount(options: {
|
|
|
89
94
|
httpSync?: { ahead: number; behind: number };
|
|
90
95
|
/** What a POST to `/api/fs/git` answers — the action channel. */
|
|
91
96
|
action?: unknown;
|
|
97
|
+
/** Discovered repos. A list without `'.'` makes the first entry the fallback. */
|
|
98
|
+
repos?: string[];
|
|
99
|
+
/**
|
|
100
|
+
* Workspace root. A case that WRITES a pick needs its own: the repo discovery
|
|
101
|
+
* store is process state keyed by root, so a snapshot left under one root
|
|
102
|
+
* would answer the next case's mount.
|
|
103
|
+
*/
|
|
104
|
+
root?: string;
|
|
92
105
|
} = {}): Promise<void> {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
const root = options.root ?? ROOT;
|
|
107
|
+
const repos = options.repos ?? ['.'];
|
|
108
|
+
// The panel resolves `'.'` when the list holds it, else the first repo — the
|
|
109
|
+
// same rule as `resolveRepoForPanel` — and subscribes to THAT scope's topic.
|
|
110
|
+
const fallback = repos.includes('.') ? '.' : (repos[0] ?? '.');
|
|
111
|
+
const rootTopic = gitTopic(`${root}\u0000.`);
|
|
112
|
+
const topics = new Map<string, TopicResolver>([
|
|
113
|
+
[rootTopic, async () => statusOf(1, options.topicSync)],
|
|
114
|
+
[reposTopic(root), async () => ({ repos, reposPending: false })],
|
|
115
|
+
]);
|
|
116
|
+
for (const repo of repos) {
|
|
117
|
+
const topic = gitTopic(`${root}\u0000${repo}`);
|
|
118
|
+
if (!topics.has(topic)) topics.set(topic, async () => statusOf(0));
|
|
119
|
+
}
|
|
120
|
+
server = await startRealtimeTestServer(topics);
|
|
97
121
|
const win = new Window({ url: `http://127.0.0.1:${server.port}` });
|
|
98
122
|
installDomGlobals(win);
|
|
99
123
|
const target = globalThis as unknown as Record<string, unknown>;
|
|
@@ -102,7 +126,7 @@ async function mount(options: {
|
|
|
102
126
|
const url = String(input);
|
|
103
127
|
const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
|
|
104
128
|
if (url.includes('/state')) return json({ sessionId: SESSION, state: {} });
|
|
105
|
-
if (url.includes('reposOnly')) return json({ repos
|
|
129
|
+
if (url.includes('reposOnly')) return json({ repos, reposPending: false });
|
|
106
130
|
// The action channel, before the status read: a mutation and a read share
|
|
107
131
|
// `/api/fs/git` and differ only by method.
|
|
108
132
|
if (init?.method === 'POST' && options.action !== undefined) return json(options.action);
|
|
@@ -122,7 +146,7 @@ async function mount(options: {
|
|
|
122
146
|
null,
|
|
123
147
|
// The panel raises into the page's ONE queue; the host is mounted
|
|
124
148
|
// beside it, so the assertion covers the assembled path.
|
|
125
|
-
h(GitPanel, { rootPath:
|
|
149
|
+
h(GitPanel, { rootPath: root, enabled: true }),
|
|
126
150
|
h(ToastStack, {}),
|
|
127
151
|
),
|
|
128
152
|
}),
|
|
@@ -131,7 +155,7 @@ async function mount(options: {
|
|
|
131
155
|
});
|
|
132
156
|
// Both reads must land before the assertion: with `fetched` still undefined
|
|
133
157
|
// the old precedence would accidentally pass.
|
|
134
|
-
await server.waitForTopic(
|
|
158
|
+
await server.waitForTopic(gitTopic(`${root}\u0000${fallback}`), (value) => value !== null);
|
|
135
159
|
for (let i = 0; i < 20; i += 1) await act(async () => {});
|
|
136
160
|
}
|
|
137
161
|
|
|
@@ -158,6 +182,31 @@ describe('GitPanel change list', () => {
|
|
|
158
182
|
for (let i = 0; i < 20; i += 1) await act(async () => {});
|
|
159
183
|
expect(container.textContent).toContain('file-1.txt');
|
|
160
184
|
});
|
|
185
|
+
|
|
186
|
+
test('choosing the repo the panel already resolved to pins the pick', async () => {
|
|
187
|
+
// With no stored pick and a root that is not a repository, the panel shows
|
|
188
|
+
// discovery's FIRST repo. Clicking that row used to be dropped as a no-op
|
|
189
|
+
// (`r !== activeRepo`), so the choice was never stored: the next list change
|
|
190
|
+
// resolved to whichever repo came first and the panel moved to a different
|
|
191
|
+
// working tree — the reported "it falls back to another workspace".
|
|
192
|
+
await mount({ repos: ['projects/alpha'], root: '/ws-pick' });
|
|
193
|
+
expect(getSessionValue(SESSION, REPO_SCOPE_STATE_KEY)).toBeUndefined();
|
|
194
|
+
|
|
195
|
+
const trigger = container.querySelector('button[title="Switch git project"]') as HTMLButtonElement;
|
|
196
|
+
expect(trigger.textContent).toContain('alpha');
|
|
197
|
+
await act(async () => {
|
|
198
|
+
trigger.click();
|
|
199
|
+
});
|
|
200
|
+
const row = [...document.querySelectorAll('button[role="option"]')].find((b) =>
|
|
201
|
+
b.textContent?.includes('projects/alpha'),
|
|
202
|
+
) as HTMLButtonElement | undefined;
|
|
203
|
+
expect(row).toBeDefined();
|
|
204
|
+
await act(async () => {
|
|
205
|
+
row?.click();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(getSessionValue(SESSION, REPO_SCOPE_STATE_KEY)).toEqual({ root: '/ws-pick', repo: 'projects/alpha' });
|
|
209
|
+
});
|
|
161
210
|
});
|
|
162
211
|
|
|
163
212
|
/**
|
|
@@ -239,10 +239,15 @@ export function GitPanel({ className = '', enabled = true, rootPath, refreshKey
|
|
|
239
239
|
rootPath={rootPath}
|
|
240
240
|
reposScanning={reposScanning}
|
|
241
241
|
onSelectRepo={(r) => {
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
|
|
242
|
+
// ALWAYS store the choice, even when it equals the repo the panel
|
|
243
|
+
// already resolved to. A repo shown because it is the first of an
|
|
244
|
+
// empty/fallback list is NOT a pick, so skipping the write left the
|
|
245
|
+
// selection unpinned and the next list change (a walk finishing, a
|
|
246
|
+
// rescan) moved the panel to whichever repo came first — the
|
|
247
|
+
// reported "it fell back to another workspace". The reload stays the
|
|
248
|
+
// scope effect's job: the resolved value does not change here, so
|
|
249
|
+
// nothing is fetched twice.
|
|
250
|
+
setActiveRepo(r);
|
|
246
251
|
}}
|
|
247
252
|
onRefresh={() => {
|
|
248
253
|
// The list comes from the TOPIC, so refreshing it is what updates the
|
|
@@ -51,7 +51,7 @@ afterAll(() => {
|
|
|
51
51
|
restoreDomGlobals();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
async function mount(repos: string[]): Promise<void> {
|
|
54
|
+
async function mount(repos: string[], activeRepo = '.'): Promise<void> {
|
|
55
55
|
(globalThis as unknown as Record<string, unknown>).fetch = async () =>
|
|
56
56
|
new Response(JSON.stringify({ success: true, details: [] }), {
|
|
57
57
|
status: 200,
|
|
@@ -64,7 +64,7 @@ async function mount(repos: string[]): Promise<void> {
|
|
|
64
64
|
render(
|
|
65
65
|
h(GitRepoPicker, {
|
|
66
66
|
rootPath: ROOT,
|
|
67
|
-
activeRepo
|
|
67
|
+
activeRepo,
|
|
68
68
|
onSelectRepo: (repo: string) => selections.push(repo),
|
|
69
69
|
repos,
|
|
70
70
|
scanning: false,
|
|
@@ -95,6 +95,33 @@ describe('GitRepoPicker', () => {
|
|
|
95
95
|
expect(trigger().textContent).toContain('Workspace');
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
test('names the selected repo before discovery has listed it', async () => {
|
|
99
|
+
// A reload starts discovery from scratch: the topic answers `['.']` until
|
|
100
|
+
// the walk finishes, while the session still holds the nested pick. Looking
|
|
101
|
+
// the selection up from the rows alone drew the workspace root — the PARENT
|
|
102
|
+
// folder, labelled with the workspace's own name — as if that were the
|
|
103
|
+
// chosen repository, and the repo the panel was reading was not even listed.
|
|
104
|
+
await mount(['.'], 'projects/a/token');
|
|
105
|
+
expect(trigger().textContent).toContain('token');
|
|
106
|
+
expect(trigger().textContent).not.toContain('Workspace');
|
|
107
|
+
|
|
108
|
+
await act(async () => {
|
|
109
|
+
trigger().click();
|
|
110
|
+
});
|
|
111
|
+
const active = menu().querySelector('button[aria-selected="true"]') as HTMLButtonElement | null;
|
|
112
|
+
expect(active?.textContent).toContain('projects/a/token');
|
|
113
|
+
// The root row is still a real choice beside it.
|
|
114
|
+
const rootRow = [...document.querySelectorAll('button[role="option"]')].find(
|
|
115
|
+
(b) => b.textContent?.trim() === 'Workspace',
|
|
116
|
+
);
|
|
117
|
+
expect(rootRow).toBeDefined();
|
|
118
|
+
|
|
119
|
+
await act(async () => {
|
|
120
|
+
active?.click();
|
|
121
|
+
});
|
|
122
|
+
expect(selections).toEqual(['projects/a/token']);
|
|
123
|
+
});
|
|
124
|
+
|
|
98
125
|
test('offers the root row when discovery found only nested repos', async () => {
|
|
99
126
|
// A workspace root that is a folder of nested repos is not itself a repo,
|
|
100
127
|
// so discovery omits `'.'`. The root is still a legitimate scope, and the
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
import { useCallback, useState } from 'preact/hooks';
|
|
23
23
|
import type { Attachment, WorkspaceFolderData } from '@/shared/types';
|
|
24
|
-
import {
|
|
24
|
+
import { newChatFolderId } from '@/shared/lib/workspace/active-project';
|
|
25
25
|
import { spawnCwdForNewSession, triggerSessionPrewarm } from '@/shared/lib/omp/session/prewarm';
|
|
26
26
|
|
|
27
27
|
export interface NewChatOpen {
|
|
@@ -57,8 +57,10 @@ export function useNewChatOpen({ folders, sessionId, selectedFolderId, harness }
|
|
|
57
57
|
const [openedHarness, setOpenedHarness] = useState<string | undefined>(undefined);
|
|
58
58
|
|
|
59
59
|
const open = useCallback((next: string, rows?: Attachment[]) => {
|
|
60
|
-
const folderId =
|
|
61
|
-
|
|
60
|
+
const folderId = newChatFolderId(folders, sessionId, selectedFolderId);
|
|
61
|
+
// The send's cwd, resolved the same way — not `spawnCwdForNewSession`'s
|
|
62
|
+
// fallback chain, which would warm a folder the pending chat never names.
|
|
63
|
+
const cwd = folderId === null ? null : spawnCwdForNewSession(folders, sessionId, folderId);
|
|
62
64
|
// Warm the agent the card will spawn on. A card opened from an ACP chat now
|
|
63
65
|
// warms THAT agent — it used to be skipped entirely, because the only pool
|
|
64
66
|
// was omp's and warming omp for a `claude` chat started a child the send
|
|
@@ -186,14 +186,30 @@ describe('useNewChatSubmit', () => {
|
|
|
186
186
|
expect(opened.searchParams.get('folderId')).toBe('3');
|
|
187
187
|
});
|
|
188
188
|
|
|
189
|
-
test('a folder already in the URL
|
|
189
|
+
test('a folder already in the URL does not veto the workspace the chat was started from', async () => {
|
|
190
|
+
// The URL's `folderId` is the RIGHT PANEL's scope, not this chat's target.
|
|
191
|
+
// Keeping it spawned the prompt in the previous workspace while the warm
|
|
192
|
+
// child waited in the one the chat was started from (the sidebar row and
|
|
193
|
+
// the prewarm both name folder 7).
|
|
190
194
|
const opened = makeDeps({ sessionId: 'sess-aaa', folders: folderOwning('sess-aaa') });
|
|
191
195
|
opened.searchParams.set('folderId', '9');
|
|
192
196
|
await mount(opened.deps);
|
|
193
197
|
|
|
194
198
|
await act(async () => { submit?.('halo', []); });
|
|
195
199
|
|
|
196
|
-
expect(opened.searchParams.get('folderId')).toBe('
|
|
200
|
+
expect(opened.searchParams.get('folderId')).toBe('7');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('a stale folderId is dropped when no workspace resolves', async () => {
|
|
204
|
+
// No owning folder and no pick: the chat has no target, and leaving the old
|
|
205
|
+
// scope in place would spawn it in that other workspace on the first send.
|
|
206
|
+
const opened = makeDeps({ sessionId: 'sess-unknown', selectedFolderId: null });
|
|
207
|
+
opened.searchParams.set('folderId', '9');
|
|
208
|
+
await mount(opened.deps);
|
|
209
|
+
|
|
210
|
+
await act(async () => { submit?.('halo', []); });
|
|
211
|
+
|
|
212
|
+
expect(opened.searchParams.get('folderId')).toBeNull();
|
|
197
213
|
});
|
|
198
214
|
|
|
199
215
|
test('the composer is cleared for the pending view it opens', async () => {
|
|
@@ -26,7 +26,7 @@ import type { Dispatch, SetStateAction } from 'preact/compat';
|
|
|
26
26
|
import type { Attachment, ChatMessageData, PromptDispatchResult, WorkspaceFolderData } from '@/shared/types';
|
|
27
27
|
import type { SetSearchParams } from '@/client/lib/router/search-params';
|
|
28
28
|
import { clearBranchParams } from '@/client/lib/router/branch-params';
|
|
29
|
-
import {
|
|
29
|
+
import { newChatFolderId } from '@/shared/lib/workspace/active-project';
|
|
30
30
|
import { startPendingSession, patchPendingEntry } from '@/client/hooks/chat/omp/pending-sessions';
|
|
31
31
|
import { setHarnessPick } from '@/client/hooks/chat/timeline/session-harness';
|
|
32
32
|
|
|
@@ -69,10 +69,14 @@ export function useNewChatSubmit(
|
|
|
69
69
|
}, [sessionId, executeSend]);
|
|
70
70
|
|
|
71
71
|
return useCallback((text, attachments, harness) => {
|
|
72
|
+
// The workspace this chat will RUN in: the folder owning the chat the card
|
|
73
|
+
// was opened from, else the composer's pick. Resolved ONCE here — the
|
|
74
|
+
// pending row, the prewarm (`useNewChatOpen`) and the spawn all read it.
|
|
75
|
+
const folderId = newChatFolderId(folders, sessionId, selectedFolderId);
|
|
72
76
|
// The store mints the pending id and owns the row it stands for: the
|
|
73
77
|
// sidebar/navbar show a default title immediately, and the row survives the
|
|
74
78
|
// `new-…` → omp-UUID switch when the first send spawns.
|
|
75
|
-
const pendingId = startPendingSession(
|
|
79
|
+
const pendingId = startPendingSession(folderId);
|
|
76
80
|
// The card's agent becomes the PENDING chat's agent now, not at the send:
|
|
77
81
|
// the composer's mode surface and the prewarm both read the pick, and a
|
|
78
82
|
// harness that only appears when the prompt lands showed omp's toggles over
|
|
@@ -87,16 +91,13 @@ export function useNewChatSubmit(
|
|
|
87
91
|
// `forkFrom`/`forkAt` in the URL, and this chat would be drawn as it.
|
|
88
92
|
const next = clearBranchParams(prev);
|
|
89
93
|
next.set('sessionId', pendingId);
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const folderId = activeProjectForSession(folders, sessionId).folder?.id ?? selectedFolderId;
|
|
98
|
-
if (folderId !== null && folderId !== undefined) next.set('folderId', String(folderId));
|
|
99
|
-
}
|
|
94
|
+
// The chat runs in `folderId` — that is where the prewarm fired and where
|
|
95
|
+
// the first send spawns. A `folderId` the URL already carried is the
|
|
96
|
+
// right panel's scope, not this chat's target, and it must not veto the
|
|
97
|
+
// workspace the chat was started from: keeping it spawned the prompt in
|
|
98
|
+
// the previous workspace while the warm child sat in this one.
|
|
99
|
+
if (folderId !== null && folderId !== undefined) next.set('folderId', String(folderId));
|
|
100
|
+
else next.delete('folderId');
|
|
100
101
|
return next;
|
|
101
102
|
}, { replace: true });
|
|
102
103
|
setLocalMessages([]);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The chat's folder scope IS the URL's `folderId` — read, never mirrored.
|
|
8
|
+
*
|
|
9
|
+
* The New Chat dialog's first send is dispatched in the SAME commit that writes
|
|
10
|
+
* `?folderId=` for the pending chat (`useNewChatSubmit` → the parked send). A
|
|
11
|
+
* copy kept in `useState` and synced by an effect is one render behind there,
|
|
12
|
+
* so the spawn read the PREVIOUS folder and the prompt landed in another
|
|
13
|
+
* workspace than the prewarmed one. These cases pin the value's freshness, not
|
|
14
|
+
* the mirror's mechanism.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
18
|
+
import { Window } from 'happy-dom';
|
|
19
|
+
import { h, render } from 'preact';
|
|
20
|
+
import { act } from 'preact/test-utils';
|
|
21
|
+
|
|
22
|
+
import { useTimelineScope, type TimelineScope } from '@/client/hooks/chat/timeline/scope';
|
|
23
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
24
|
+
|
|
25
|
+
const BASE = 'http://localhost/?sessionId=omp-a&folderId=9';
|
|
26
|
+
|
|
27
|
+
let container: HTMLElement | undefined;
|
|
28
|
+
let scope: TimelineScope | null = null;
|
|
29
|
+
/** `selectedFolderId` of every render, in order. */
|
|
30
|
+
const renders: Array<number | null> = [];
|
|
31
|
+
|
|
32
|
+
function Probe() {
|
|
33
|
+
const current = useTimelineScope();
|
|
34
|
+
scope = current;
|
|
35
|
+
renders.push(current.selectedFolderId);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function mount() {
|
|
40
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
41
|
+
await act(async () => { render(h(Probe, {}), container as HTMLElement); });
|
|
42
|
+
await act(async () => {});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
beforeAll(() => {
|
|
46
|
+
installDomGlobals(new Window({ url: BASE }));
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterAll(() => {
|
|
50
|
+
restoreDomGlobals();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
window.history.replaceState(null, '', BASE);
|
|
55
|
+
renders.length = 0;
|
|
56
|
+
scope = null;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
if (container) render(null, container);
|
|
61
|
+
container?.remove();
|
|
62
|
+
container = undefined;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('useTimelineScope', () => {
|
|
66
|
+
test('the URL folder is on the FIRST render a URL write produces', async () => {
|
|
67
|
+
await mount();
|
|
68
|
+
expect(renders).toEqual([9]);
|
|
69
|
+
|
|
70
|
+
const before = renders.length;
|
|
71
|
+
await act(async () => {
|
|
72
|
+
// Exactly what the New Chat dialog does: the pending chat's id and the
|
|
73
|
+
// workspace it was started from, in one write.
|
|
74
|
+
scope?.setSearchParams((prev) => {
|
|
75
|
+
prev.set('sessionId', 'new-1');
|
|
76
|
+
prev.set('folderId', '7');
|
|
77
|
+
return prev;
|
|
78
|
+
}, { replace: true });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// A mirrored copy answered `9` here and only caught up on the next render —
|
|
82
|
+
// which is the commit the parked send already used.
|
|
83
|
+
expect(renders[before]).toBe(7);
|
|
84
|
+
expect(scope?.sessionId).toBe('new-1');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('the picker writes the param and reads back the number', async () => {
|
|
88
|
+
await mount();
|
|
89
|
+
|
|
90
|
+
await act(async () => { scope?.selectContextFolder(11); });
|
|
91
|
+
|
|
92
|
+
expect(window.location.search).toContain('folderId=11');
|
|
93
|
+
expect(scope?.selectedFolderId).toBe(11);
|
|
94
|
+
|
|
95
|
+
await act(async () => { scope?.selectContextFolder(null); });
|
|
96
|
+
|
|
97
|
+
expect(window.location.search).not.toContain('folderId');
|
|
98
|
+
expect(scope?.selectedFolderId).toBeNull();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* so both readers move together.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { useCallback
|
|
17
|
-
import { useSearchParams } from '@/client/lib/router/search-params';
|
|
16
|
+
import { useCallback } from 'preact/hooks';
|
|
17
|
+
import { useSearchParams, type SetSearchParams } from '@/client/lib/router/search-params';
|
|
18
18
|
|
|
19
19
|
export interface TimelineScope {
|
|
20
20
|
sessionId: string | null;
|
|
@@ -23,22 +23,22 @@ export interface TimelineScope {
|
|
|
23
23
|
selectContextFolder: (id: number | null) => void;
|
|
24
24
|
/** The raw URL setter, for the send path: adopting a freshly spawned session
|
|
25
25
|
* rewrites `sessionId` in place, and the layout reads the same params. */
|
|
26
|
-
setSearchParams:
|
|
26
|
+
setSearchParams: SetSearchParams;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function useTimelineScope(): TimelineScope {
|
|
30
30
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
31
31
|
const sessionId = searchParams.get('sessionId');
|
|
32
32
|
const folderId = searchParams.get('folderId');
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
// DERIVED, never mirrored into state. The URL is the one value the picker,
|
|
34
|
+
// the prewarm and the send all read; a copy in `useState` synced by an effect
|
|
35
|
+
// lagged it by one render — and the New Chat dialog's first send is
|
|
36
|
+
// dispatched in the very commit that writes `?folderId=`, so it read the
|
|
37
|
+
// PREVIOUS folder and spawned the prompt in another workspace.
|
|
38
|
+
const selectedFolderId = folderId ? parseInt(folderId, 10) : null;
|
|
38
39
|
|
|
39
40
|
const selectContextFolder = useCallback(
|
|
40
41
|
(id: number | null) => {
|
|
41
|
-
setSelectedFolderId(id);
|
|
42
42
|
setSearchParams(
|
|
43
43
|
(prev) => {
|
|
44
44
|
if (id) prev.set('folderId', String(id));
|
|
@@ -153,7 +153,12 @@ export function useCommitBox({ rootPath, repo, execute }: UseCommitBoxOptions):
|
|
|
153
153
|
|
|
154
154
|
const params = new URLSearchParams({ headMessage: '1' });
|
|
155
155
|
if (rootPath) params.set('root', rootPath);
|
|
156
|
-
|
|
156
|
+
// ALWAYS send the repo, including `'.'`. The route's implicit-repo
|
|
157
|
+
// fallback (`repos.includes('.') ? '.' : repos[0]`) exists for a request
|
|
158
|
+
// that names none, so omitting the root pick made amend read the FIRST
|
|
159
|
+
// nested repo's HEAD message while the panel was on the workspace root —
|
|
160
|
+
// a different repository's commit seeded into the draft.
|
|
161
|
+
if (repo) params.set('repo', repo);
|
|
157
162
|
|
|
158
163
|
let cancelled = false;
|
|
159
164
|
void fetch(`/api/fs/git?${params.toString()}`)
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gapless synthesis playback.
|
|
8
|
+
*
|
|
9
|
+
* The player used to start one `<audio>` element per chunk. Even when the next
|
|
10
|
+
* blob was already in memory, swapping `src` tore down the decoder and called
|
|
11
|
+
* `play()` again, so every paragraph boundary carried an audible pause. This
|
|
12
|
+
* module decodes each chunk to an `AudioBuffer` and starts it at the previous
|
|
13
|
+
* buffer's exact end, on the browser's own continuous timeline.
|
|
14
|
+
*
|
|
15
|
+
* Pause suspends the context instead of the element: `currentTime` freezes,
|
|
16
|
+
* the scheduled sources keep their sample offsets, and resume continues from
|
|
17
|
+
* the same sample. Stop closes the context; the next read opens a fresh one.
|
|
18
|
+
*
|
|
19
|
+
* The context is created on the first scheduled read, so the module can be
|
|
20
|
+
* imported where no `AudioContext` exists (the server bundle, tests) and the
|
|
21
|
+
* refusal arrives on the click that needs it.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const START_LEAD_SECONDS = 0.05;
|
|
25
|
+
/**
|
|
26
|
+
* Decoded audio kept ahead of the playhead. Three chunks is enough for the
|
|
27
|
+
* next request to land while two are still queued, without holding a
|
|
28
|
+
* ten-minute answer in memory.
|
|
29
|
+
*/
|
|
30
|
+
const MAX_SCHEDULED_CHUNKS = 3;
|
|
31
|
+
const RESUME_TIMEOUT_MS = 750;
|
|
32
|
+
const BLOCKED_MESSAGE = 'The browser blocked autoplay. Press the speaker button to hear this answer.';
|
|
33
|
+
|
|
34
|
+
interface AudioGlobals {
|
|
35
|
+
AudioContext?: typeof AudioContext;
|
|
36
|
+
webkitAudioContext?: typeof AudioContext;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class GaplessAudio {
|
|
40
|
+
private context: AudioContext | null = null;
|
|
41
|
+
private nextStart = 0;
|
|
42
|
+
private readonly active = new Set<AudioBufferSourceNode>();
|
|
43
|
+
private readonly roomWaiters = new Set<() => void>();
|
|
44
|
+
private readonly idleWaiters = new Set<() => void>();
|
|
45
|
+
private paused = false;
|
|
46
|
+
private generation = 0;
|
|
47
|
+
|
|
48
|
+
constructor(private readonly createContext: () => AudioContext) {}
|
|
49
|
+
|
|
50
|
+
static create(): GaplessAudio | null {
|
|
51
|
+
const scope = globalThis as unknown as AudioGlobals;
|
|
52
|
+
const Ctor = scope.AudioContext ?? scope.webkitAudioContext;
|
|
53
|
+
return Ctor ? new GaplessAudio(() => new Ctor()) : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get hasAudio(): boolean {
|
|
57
|
+
return this.active.size > 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Open the context and make sure the browser will let it start. */
|
|
61
|
+
async ensure(): Promise<void> {
|
|
62
|
+
const existing = this.context?.state === 'closed' ? null : this.context;
|
|
63
|
+
const context = existing ?? this.open();
|
|
64
|
+
this.context = context;
|
|
65
|
+
if (this.paused) {
|
|
66
|
+
if (context.state === 'running') await context.suspend().catch(() => undefined);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
await this.resumeContext(context);
|
|
70
|
+
if (this.paused && context.state === 'running') await context.suspend().catch(() => undefined);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Decode one chunk and put it on the queue; resolves once it is scheduled. */
|
|
74
|
+
async schedule(blob: Blob): Promise<void> {
|
|
75
|
+
const generation = this.generation;
|
|
76
|
+
const context = this.context;
|
|
77
|
+
if (!context) throw new Error('Speech playback has not started.');
|
|
78
|
+
|
|
79
|
+
const bytes = await blob.arrayBuffer();
|
|
80
|
+
if (generation !== this.generation) return;
|
|
81
|
+
|
|
82
|
+
let buffer: AudioBuffer;
|
|
83
|
+
try {
|
|
84
|
+
buffer = await context.decodeAudioData(bytes);
|
|
85
|
+
} catch {
|
|
86
|
+
throw new Error('The audio could not be decoded.');
|
|
87
|
+
}
|
|
88
|
+
if (generation !== this.generation) return;
|
|
89
|
+
|
|
90
|
+
while (this.active.size >= MAX_SCHEDULED_CHUNKS && generation === this.generation) {
|
|
91
|
+
const room = Promise.withResolvers<void>();
|
|
92
|
+
this.roomWaiters.add(room.resolve);
|
|
93
|
+
await room.promise;
|
|
94
|
+
}
|
|
95
|
+
if (generation !== this.generation) return;
|
|
96
|
+
this.startBuffer(context, buffer);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Resolve when every scheduled buffer has finished playing. */
|
|
100
|
+
finish(): Promise<void> {
|
|
101
|
+
if (this.active.size === 0) return Promise.resolve();
|
|
102
|
+
const idle = Promise.withResolvers<void>();
|
|
103
|
+
this.idleWaiters.add(idle.resolve);
|
|
104
|
+
return idle.promise;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pause(): void {
|
|
108
|
+
this.paused = true;
|
|
109
|
+
const context = this.context;
|
|
110
|
+
if (context && context.state === 'running') void context.suspend().catch(() => undefined);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Continue a paused read at the sample where the context froze. */
|
|
114
|
+
async resume(): Promise<void> {
|
|
115
|
+
this.paused = false;
|
|
116
|
+
const context = this.context;
|
|
117
|
+
if (!context) return;
|
|
118
|
+
await this.resumeContext(context);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Silence the context after a natural end without closing it. */
|
|
122
|
+
idle(): void {
|
|
123
|
+
const context = this.context;
|
|
124
|
+
if (context && context.state === 'running') void context.suspend().catch(() => undefined);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
stop(): void {
|
|
128
|
+
this.generation += 1;
|
|
129
|
+
for (const source of this.active) {
|
|
130
|
+
source.onended = null;
|
|
131
|
+
try {
|
|
132
|
+
source.stop();
|
|
133
|
+
} catch {
|
|
134
|
+
// The source already ended; there is nothing left to stop.
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
source.disconnect();
|
|
138
|
+
} catch {
|
|
139
|
+
// The node was never connected, or was already disconnected.
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
this.active.clear();
|
|
143
|
+
this.nextStart = 0;
|
|
144
|
+
this.paused = false;
|
|
145
|
+
this.notifyRoom();
|
|
146
|
+
this.notifyIdle();
|
|
147
|
+
const context = this.context;
|
|
148
|
+
this.context = null;
|
|
149
|
+
if (context) void context.close().catch(() => undefined);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private open(): AudioContext {
|
|
153
|
+
try {
|
|
154
|
+
return this.createContext();
|
|
155
|
+
} catch (error) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
error instanceof Error && error.name === 'NotAllowedError'
|
|
158
|
+
? BLOCKED_MESSAGE
|
|
159
|
+
: 'This browser cannot play synthesized speech.',
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private async resumeContext(context: AudioContext): Promise<void> {
|
|
165
|
+
if (context.state === 'closed') throw new Error('Speech playback was closed.');
|
|
166
|
+
if (context.state === 'suspended') {
|
|
167
|
+
const timeout = Promise.withResolvers<void>();
|
|
168
|
+
const timer = setTimeout(() => timeout.resolve(), RESUME_TIMEOUT_MS);
|
|
169
|
+
const resume = context.resume().catch(() => undefined);
|
|
170
|
+
try {
|
|
171
|
+
await Promise.race([resume, timeout.promise]);
|
|
172
|
+
} finally {
|
|
173
|
+
clearTimeout(timer);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (context.state !== 'running' && !this.paused) throw new Error(BLOCKED_MESSAGE);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private startBuffer(context: AudioContext, buffer: AudioBuffer): void {
|
|
180
|
+
const source = context.createBufferSource();
|
|
181
|
+
source.buffer = buffer;
|
|
182
|
+
source.connect(context.destination);
|
|
183
|
+
source.onended = () => {
|
|
184
|
+
this.active.delete(source);
|
|
185
|
+
this.notifyRoom();
|
|
186
|
+
this.notifyIdle();
|
|
187
|
+
};
|
|
188
|
+
this.active.add(source);
|
|
189
|
+
|
|
190
|
+
const startAt = Math.max(context.currentTime + START_LEAD_SECONDS, this.nextStart);
|
|
191
|
+
this.nextStart = startAt + buffer.duration;
|
|
192
|
+
source.start(startAt);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private notifyRoom(): void {
|
|
196
|
+
for (const resolve of this.roomWaiters) resolve();
|
|
197
|
+
this.roomWaiters.clear();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private notifyIdle(): void {
|
|
201
|
+
if (this.active.size > 0) return;
|
|
202
|
+
for (const resolve of this.idleWaiters) resolve();
|
|
203
|
+
this.idleWaiters.clear();
|
|
204
|
+
}
|
|
205
|
+
}
|