dsh-watch-together 0.2.0 → 0.2.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/CHANGELOG.md +57 -0
- package/README.md +10 -2
- package/docs/INTERFACES.zh.md +73 -0
- package/dsh.plugin.json +1 -1
- package/examples/floating-chat/glass_window.py +7 -0
- package/examples/floating-chat/glass_window_gpu.py +502 -0
- package/examples/floating-chat/mic-dsh.png +0 -0
- package/examples/floating-chat/requirements-glass.txt +8 -9
- package/examples/floating-chat/window.py +1454 -3372
- package/examples/floating-chat/window_protocol.py +167 -0
- package/lib/client.js +306 -0
- package/package.json +24 -2
- package/src/chat-server.js +201 -198
- package/src/chat-store.js +10 -0
- package/src/handler.js +266 -261
- package/src/index.js +156 -130
- package/src/input-surface.js +156 -154
- package/src/interfaces.js +43 -0
- package/src/public-api.js +24 -0
- package/src/recognition-interface.js +43 -0
- package/src/register.js +7 -2
- package/src/settings/config.js +146 -0
- package/src/settings/deps.js +163 -0
- package/src/settings/page.html +233 -0
- package/src/settings/page.js +11 -0
- package/src/settings/server.js +195 -0
- package/src/tts-interface.js +59 -0
- package/src/wake-failure.js +67 -0
- package/src/watch-loop.js +37 -11
- package/src/watch-run.js +1007 -1002
- package/src/window-interface.js +81 -0
- package/src/window-protocol.js +122 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* window-interface.js — the plugin-facing floating-window contract.
|
|
3
|
+
*
|
|
4
|
+
* A window implementation can be the bundled Python process, a future web
|
|
5
|
+
* window, or a test double. The watch plugin only calls this object:
|
|
6
|
+
*
|
|
7
|
+
* open() / hide() / show() / alive() / hidden()
|
|
8
|
+
* message(entry) / meta(text) / control(action, value) / tts(event)
|
|
9
|
+
*
|
|
10
|
+
* Messages are written to the protocol file; process/config details stay in
|
|
11
|
+
* the transport, not in the watch loop.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
appendWindowAction, appendWindowEvent, readWindowActions,
|
|
16
|
+
} from './window-protocol.js';
|
|
17
|
+
import {
|
|
18
|
+
floatingWindowAlive, floatingWindowHidden, openFloatingWindow, setWindowHidden,
|
|
19
|
+
} from './floating-window.js';
|
|
20
|
+
|
|
21
|
+
export const WINDOW_INTERFACE_VERSION = 1;
|
|
22
|
+
|
|
23
|
+
export function createWindowInterface({ transport = null } = {}) {
|
|
24
|
+
const t = transport ?? {
|
|
25
|
+
open(options = {}) {
|
|
26
|
+
return openFloatingWindow(options);
|
|
27
|
+
},
|
|
28
|
+
hide() {
|
|
29
|
+
return setWindowHidden(true);
|
|
30
|
+
},
|
|
31
|
+
show() {
|
|
32
|
+
return setWindowHidden(false);
|
|
33
|
+
},
|
|
34
|
+
alive() {
|
|
35
|
+
return floatingWindowAlive();
|
|
36
|
+
},
|
|
37
|
+
hidden() {
|
|
38
|
+
return floatingWindowHidden();
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
return Object.freeze({
|
|
42
|
+
kind: 'window',
|
|
43
|
+
version: WINDOW_INTERFACE_VERSION,
|
|
44
|
+
open(options) {
|
|
45
|
+
return t.open(options);
|
|
46
|
+
},
|
|
47
|
+
hide() {
|
|
48
|
+
return t.hide();
|
|
49
|
+
},
|
|
50
|
+
show() {
|
|
51
|
+
return t.show();
|
|
52
|
+
},
|
|
53
|
+
alive() {
|
|
54
|
+
return t.alive();
|
|
55
|
+
},
|
|
56
|
+
hidden() {
|
|
57
|
+
return t.hidden();
|
|
58
|
+
},
|
|
59
|
+
message(entry) {
|
|
60
|
+
return appendWindowEvent({ type: 'message', ...entry });
|
|
61
|
+
},
|
|
62
|
+
meta(text, extra = {}) {
|
|
63
|
+
return appendWindowEvent({ type: 'meta', text, ...extra });
|
|
64
|
+
},
|
|
65
|
+
control(action, value = null) {
|
|
66
|
+
return appendWindowEvent({ type: 'control', action, value });
|
|
67
|
+
},
|
|
68
|
+
tts(event) {
|
|
69
|
+
return appendWindowEvent({ type: 'tts', ...event });
|
|
70
|
+
},
|
|
71
|
+
actions(env = process.env) {
|
|
72
|
+
return readWindowActions(env);
|
|
73
|
+
},
|
|
74
|
+
accept(action, env = process.env) {
|
|
75
|
+
return appendWindowAction(action, env);
|
|
76
|
+
},
|
|
77
|
+
status() {
|
|
78
|
+
return { alive: Boolean(t.alive()), hidden: Boolean(t.hidden()) };
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* window-protocol.js — the wire between the plugin and any floating window.
|
|
3
|
+
*
|
|
4
|
+
* The plugin writes **window-events.jsonl**; a window process reads it. The
|
|
5
|
+
* window may write **window-outbox.jsonl** for user actions. This is the only
|
|
6
|
+
* place that knows the on-disk schema. The window does not import Node, and
|
|
7
|
+
* the plugin does not import Python.
|
|
8
|
+
*
|
|
9
|
+
* Message events intentionally carry the same role/text/at fields as chat.jsonl
|
|
10
|
+
* so existing renderers can consume them unchanged. The window may read both
|
|
11
|
+
* files during the migration; duplicate events are harmless because the
|
|
12
|
+
* renderer de-duplicates by (role, text, at).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { appendFileSync, mkdirSync, readFileSync } from 'node:fs';
|
|
16
|
+
import { dirname, join } from 'node:path';
|
|
17
|
+
|
|
18
|
+
import { cacheDir } from 'dsh-video-storyboard/cache';
|
|
19
|
+
|
|
20
|
+
export const WINDOW_PROTOCOL_VERSION = 1;
|
|
21
|
+
export const WINDOW_EVENT_FILE = 'window-events.jsonl';
|
|
22
|
+
export const WINDOW_OUTBOX_FILE = 'window-outbox.jsonl';
|
|
23
|
+
|
|
24
|
+
export const WINDOW_EVENT_TYPES = Object.freeze([
|
|
25
|
+
'message', 'meta', 'control', 'tts', 'ping',
|
|
26
|
+
]);
|
|
27
|
+
export const WINDOW_ACTION_TYPES = Object.freeze([
|
|
28
|
+
'say', 'close', 'hide', 'show', 'rename', 'collapse', 'expand',
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
export function windowEventFile(env = process.env) {
|
|
32
|
+
return join(cacheDir(env), WINDOW_EVENT_FILE);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function windowOutboxFile(env = process.env) {
|
|
36
|
+
return join(cacheDir(env), WINDOW_OUTBOX_FILE);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function readJsonLines(file) {
|
|
40
|
+
try {
|
|
41
|
+
return readFileSync(file, 'utf8').split('\n').filter((line) => line.trim())
|
|
42
|
+
.map((line) => {
|
|
43
|
+
try { return JSON.parse(line); } catch { return null; }
|
|
44
|
+
})
|
|
45
|
+
.filter(Boolean);
|
|
46
|
+
} catch { return []; }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function appendJsonLine(file, value) {
|
|
50
|
+
try {
|
|
51
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
52
|
+
} catch { /* directory already exists */ }
|
|
53
|
+
appendFileSync(file, `${JSON.stringify(value)}\n`, 'utf8');
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Validate/normalize an event. Unknown event types are dropped, not thrown. */
|
|
58
|
+
export function normalizeWindowEvent(event = {}) {
|
|
59
|
+
const type = WINDOW_EVENT_TYPES.includes(event.type) ? event.type : null;
|
|
60
|
+
if (!type) return null;
|
|
61
|
+
const out = {
|
|
62
|
+
v: WINDOW_PROTOCOL_VERSION,
|
|
63
|
+
type,
|
|
64
|
+
at: Number.isFinite(Number(event.at)) ? Number(event.at) : Date.now(),
|
|
65
|
+
};
|
|
66
|
+
if (type === 'message' || type === 'meta') {
|
|
67
|
+
const role = String(event.role ?? (type === 'meta' ? 'meta' : 'assistant'));
|
|
68
|
+
const text = String(event.text ?? '').slice(0, 4000);
|
|
69
|
+
if (!text) return null;
|
|
70
|
+
return {
|
|
71
|
+
...out, role, text,
|
|
72
|
+
...(Number.isFinite(Number(event.t)) ? { t: +Number(event.t).toFixed(2) } : {}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (type === 'control') {
|
|
76
|
+
const action = String(event.action ?? '').trim();
|
|
77
|
+
if (!action) return null;
|
|
78
|
+
return { ...out, action, value: event.value ?? null };
|
|
79
|
+
}
|
|
80
|
+
if (type === 'tts') {
|
|
81
|
+
const text = String(event.text ?? '').slice(0, 4000);
|
|
82
|
+
if (!text) return null;
|
|
83
|
+
return { ...out, state: String(event.state ?? 'due'), text };
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Append a plugin → window event. Returns the normalized event (or null). */
|
|
89
|
+
export function appendWindowEvent(event, env = process.env) {
|
|
90
|
+
const normalized = normalizeWindowEvent(event);
|
|
91
|
+
if (!normalized) return null;
|
|
92
|
+
appendJsonLine(windowEventFile(env), normalized);
|
|
93
|
+
return normalized;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Read plugin → window events (tests/diagnostics). */
|
|
97
|
+
export function readWindowEvents(env = process.env) {
|
|
98
|
+
return readJsonLines(windowEventFile(env));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Append a user → plugin action from a window process. */
|
|
102
|
+
export function appendWindowAction(action, env = process.env) {
|
|
103
|
+
const type = String(action?.type ?? '').trim();
|
|
104
|
+
if (!WINDOW_ACTION_TYPES.includes(type)) return null;
|
|
105
|
+
const out = {
|
|
106
|
+
v: WINDOW_PROTOCOL_VERSION,
|
|
107
|
+
type,
|
|
108
|
+
at: Number.isFinite(Number(action.at)) ? Number(action.at) : Date.now(),
|
|
109
|
+
};
|
|
110
|
+
if (type === 'say') {
|
|
111
|
+
const text = String(action.text ?? '').trim().slice(0, 500);
|
|
112
|
+
if (!text) return null;
|
|
113
|
+
out.text = text;
|
|
114
|
+
}
|
|
115
|
+
if (action.value !== undefined) out.value = action.value;
|
|
116
|
+
return appendJsonLine(windowOutboxFile(env), out);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Read user → plugin actions (polled by the window service). */
|
|
120
|
+
export function readWindowActions(env = process.env) {
|
|
121
|
+
return readJsonLines(windowOutboxFile(env));
|
|
122
|
+
}
|