dsh-watch-together 0.2.14 → 0.2.15

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/dsh.plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-watch-together",
3
3
  "description": "Watch a video together, in sync with the user's real playback: each segment arrives as one storyboard image plus its subtitle lines just before it ends, and the floating window carries spoken replies and live room audio.",
4
- "version": "0.2.14",
4
+ "version": "0.2.15",
5
5
  "entry": {
6
6
  "name": "dsh-watch-together",
7
7
  "inject": [
@@ -58,7 +58,15 @@ except ImportError:
58
58
  sys.stderr.write("缺 numpy:pip install numpy\n")
59
59
  raise SystemExit(2)
60
60
 
61
- from aec import FdafAec, find_loopback_device # 回声消除:把电脑放出来的声音从麦克风里减掉
61
+ # 回声消除:把电脑放出来的声音从麦克风里减掉。
62
+ # **不是硬依赖**:打包漏了 aec.py 时(issue #36:0.0.2–0.1.3 的 see-now 包都没带)
63
+ # 麦克风仍要能起来,只是不做回声消除 —— 而模块级 import 失败会让整个进程当场退出,
64
+ # 悬浮窗那边 stderr 又被丢进 DEVNULL,用户只看到"录音中"三个字。
65
+ try:
66
+ from aec import FdafAec, find_loopback_device
67
+ except ImportError:
68
+ FdafAec = None
69
+ find_loopback_device = None
62
70
 
63
71
  # ---------------------------------------------------------------- 与悬浮窗共享的那份流
64
72
 
@@ -273,14 +281,17 @@ def run(args):
273
281
  aec = None
274
282
  lb_dev, lb_name = None, None
275
283
  if not args.no_aec:
276
- lb_dev = args.loopback
277
- if lb_dev is None:
278
- lb_dev, lb_name = find_loopback_device()
279
- if lb_dev is not None:
280
- aec = FdafAec(frame=512, taps=args.taps, mu=0.35, dt_ratio=args.dt_ratio)
281
- log(f"回声消除开:参考设备 [{lb_dev}] {lb_name or ''}")
284
+ if FdafAec is None or find_loopback_device is None:
285
+ log("缺 aec.py,回声消除关 —— 麦克风照常可用,但扬声器的声音会被一起收进来")
282
286
  else:
283
- log("没找到回环设备(扬声器/立体声混音),回声消除关 —— 可用 --loopback 指定设备号")
287
+ lb_dev = args.loopback
288
+ if lb_dev is None:
289
+ lb_dev, lb_name = find_loopback_device()
290
+ if lb_dev is not None:
291
+ aec = FdafAec(frame=512, taps=args.taps, mu=0.35, dt_ratio=args.dt_ratio)
292
+ log(f"回声消除开:参考设备 [{lb_dev}] {lb_name or ''}")
293
+ else:
294
+ log("没找到回环设备(扬声器/立体声混音),回声消除关 —— 可用 --loopback 指定设备号")
284
295
  ring = Ring()
285
296
 
286
297
  def feed(block, ref_block=None):
@@ -36,22 +36,31 @@ import queue
36
36
  import subprocess
37
37
  import threading
38
38
  import time
39
- from ctypes import wintypes
40
39
  from pathlib import Path
41
40
 
41
+ # 是不是 Windows。**所有 ctypes.windll / wintypes / WDA 都必须先问它**:
42
+ # `ctypes.windll` 在 macOS/Linux 上根本不存在,模块顶层摸一下就是
43
+ # `AttributeError: module 'ctypes' has no attribute 'windll'`,而且死在依赖预检
44
+ # 之前,用户看到的是"启动后 700ms 退出,code=1"(issue #40)。
45
+ IS_WIN = os.name == "nt"
46
+
47
+ if IS_WIN:
48
+ from ctypes import wintypes
49
+
42
50
  # 必须在 import tkinter / 创建任何窗口之前声明 per-monitor v2 DPI 感知。
43
- _u = ctypes.windll.user32
44
- try:
45
- _u.SetProcessDpiAwarenessContext.argtypes = [ctypes.c_void_p]
46
- _u.SetProcessDpiAwarenessContext.restype = ctypes.c_bool
47
- _u.SetProcessDpiAwarenessContext(ctypes.c_void_p(-4))
48
- except Exception:
49
- pass
51
+ if IS_WIN:
52
+ _u = ctypes.windll.user32
53
+ try:
54
+ _u.SetProcessDpiAwarenessContext.argtypes = [ctypes.c_void_p]
55
+ _u.SetProcessDpiAwarenessContext.restype = ctypes.c_bool
56
+ _u.SetProcessDpiAwarenessContext(ctypes.c_void_p(-4))
57
+ except Exception:
58
+ pass
50
59
 
51
- try:
52
- ctypes.windll.winmm.timeBeginPeriod(1)
53
- except Exception:
54
- pass
60
+ try:
61
+ ctypes.windll.winmm.timeBeginPeriod(1)
62
+ except Exception:
63
+ pass
55
64
 
56
65
  # ---------------------------------------------------------------- 依赖预检
57
66
  #
@@ -80,8 +89,10 @@ def _die_missing(missing: list) -> None:
80
89
  log_path.write_text(text + "\n", encoding="utf-8")
81
90
  except Exception:
82
91
  pass
92
+ # 弹窗标题跟着"谁拉起的这个窗"走:see-now 的用户看到 dsh-watch-together 会以为装错了包
83
93
  try:
84
- ctypes.windll.user32.MessageBoxW(None, text, "dsh-watch-together", 0x10)
94
+ ctypes.windll.user32.MessageBoxW(None, text,
95
+ os.environ.get("DSH_WINDOW_BRAND") or "dsh-watch-together", 0x10)
85
96
  except Exception:
86
97
  print(text, flush=True)
87
98
  raise SystemExit(2)
@@ -226,6 +237,8 @@ REMOTE_MARKS = (
226
237
 
227
238
  def remote_capture_likely() -> bool:
228
239
  """当前是不是远程/捕获环境:RDP 标志位 + 常见远程软件窗口。"""
240
+ if not IS_WIN:
241
+ return False
229
242
  try:
230
243
  if ctypes.windll.user32.GetSystemMetrics(0x1000): # SM_REMOTESESSION
231
244
  return True
@@ -420,7 +433,8 @@ class LiveGlass:
420
433
  self._excluded = False
421
434
  # 录屏模式(capturable)下 mss 会抓到窗口自己,必须每帧挖掉,见 fill_own_rect。
422
435
  # 缓存起来:读配置是磁盘 IO,不能每帧做。
423
- self._cappable = capturable()
436
+ # **非 Windows 一律按"能抓到自己"处理**:那边没有 WDA,不挖就是"透过自己看自己"。
437
+ self._cappable = capturable() or not IS_WIN
424
438
  # 样式:live / frost / solid。静态样式不抓屏、不设 WDA、不起渲染线程。
425
439
  self._style = glass_style(cfg)
426
440
  self._static = self._style in STATIC_STYLES
@@ -1530,11 +1544,22 @@ class LiveGlass:
1530
1544
  # ---- 窗口句柄 ----
1531
1545
 
1532
1546
  def _hwnd_root(self):
1547
+ if not IS_WIN:
1548
+ return None
1533
1549
  if self._hwnd is None:
1534
1550
  self._hwnd = ctypes.windll.user32.GetAncestor(self.root.winfo_id(), 2)
1535
1551
  return self._hwnd
1536
1552
 
1537
1553
  def _set_exclude(self, on: bool) -> None:
1554
+ """WDA:让窗口从屏幕捕获里消失,抓自己所在区域时抓到的是背后的桌面。
1555
+
1556
+ macOS/Linux 没有这个 API,**不能抓、也不能设**:硬调就是 AttributeError。
1557
+ 返回 False 之后 `_cappable` 会被打开,改走"抓到了就把自己那块填掉"那条路
1558
+ (见 `glass_capture.fill_own_rect`),否则会递归地拍到自己。
1559
+ """
1560
+ if not IS_WIN:
1561
+ self._excluded = False
1562
+ return
1538
1563
  hwnd = self._hwnd_root()
1539
1564
  fn = ctypes.windll.user32.SetWindowDisplayAffinity
1540
1565
  fn.argtypes = [wintypes.HWND, wintypes.DWORD]
@@ -1545,6 +1570,15 @@ class LiveGlass:
1545
1570
  print("WDA failed", ctypes.GetLastError(), flush=True)
1546
1571
 
1547
1572
  def _bbox(self):
1573
+ if not IS_WIN:
1574
+ # 非 Windows 没有 GetWindowRect;用 Tk 自己的屏幕坐标顶上。
1575
+ # Retina 上是逻辑像素,和 mss 的物理像素可能差一个缩放倍数 ——
1576
+ # 已知的遗留问题,那类机器上建议用 frost/solid(都不抓屏)。
1577
+ try:
1578
+ x, y = int(self.root.winfo_rootx()), int(self.root.winfo_rooty())
1579
+ return (x, y, x + int(self.root.winfo_width()), y + int(self.root.winfo_height()))
1580
+ except Exception:
1581
+ return (0, 0, 0, 0)
1548
1582
  rc = _RECT()
1549
1583
  ctypes.windll.user32.GetWindowRect(self._hwnd_root(), ctypes.byref(rc))
1550
1584
  return (rc.left, rc.top, rc.right, rc.bottom)
@@ -1580,7 +1614,8 @@ class LiveGlass:
1580
1614
  self._renderer.close()
1581
1615
  except Exception:
1582
1616
  pass
1583
- ctypes.windll.winmm.timeEndPeriod(1)
1617
+ if IS_WIN:
1618
+ ctypes.windll.winmm.timeEndPeriod(1)
1584
1619
  finally:
1585
1620
  self.root.destroy()
1586
1621
  return "break"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-watch-together",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "Watch a video together, in sync with the user's real playback: every segment arrives as one storyboard image plus its subtitle lines just before it ends, while the floating window carries spoken replies and live room audio — picture and voice, not a transcript.",
5
5
  "keywords": [
6
6
  "dsh",
@@ -0,0 +1,144 @@
1
+ /**
2
+ * define-tool.js — `@deepseek-ai/dsh-tools` 的**离线兜底**。
3
+ *
4
+ * ## 为什么需要它(2026-11-06 社区实报)
5
+ *
6
+ * 插件的工具定义要用宿主的 `defineTool()`:它把 author spec 编译成 JSON Schema、
7
+ * 给 execute 包一层参数校验。但 `@deepseek-ai/dsh-tools` **被打包进宿主的 `app.asar`**,
8
+ * 插件从自己的 `node_modules` 往上解析时**找不到这个包** →
9
+ * `import()` 抛 → `apply()` 被 catch 吞掉 → **整个插件静默不注册任何工具**。
10
+ *
11
+ * 社区原话:「根源没变:它 `import('@deepseek-ai/dsh-tools')`,宿主的这份被打进 `app.asar`,
12
+ * plugins 侧解析不到,加载时就在注册工具之前抛了」。
13
+ *
14
+ * ## 兜底做什么、不做什么
15
+ *
16
+ * **做**:把 author spec 编译成宿主 `register()` 认的 JSON Schema。规则逐条照抄
17
+ * `dsh-tools/lib/index.js` 的 `runSchemaCompiler`:
18
+ * - `property-map`:每个属性的 `required: true` 提升到父级 `required` 数组,并从属性里删掉;
19
+ * 没写 `required: true` 的属性 = 可选(宿主的参数**默认全是可选**)。
20
+ * - `type: 'json'` 是 author-only 节点 → 退化成 `{}`(任意 JSON,只保留 description 等注解)。
21
+ * - `properties` / `items` 递归;其余键(`description` / `enum` / `additionalProperties`)原样透传。
22
+ *
23
+ * **不做**:运行时参数校验(宿主那层 `validateJsonSchemaValue` 拿不到)。
24
+ * 代价是模型传错参数时不再抛 `ToolArgsError`,而是走各 handler 自己的默认值分支 ——
25
+ * 真出问题时表现为"参数没生效",所以 `schema-audit.test.mjs` 那套静态审计更要守住。
26
+ *
27
+ * **首选仍然是宿主的版本**:`loadDefineTool()` 先 import、再 `DSH_TOOLS_PATH`,
28
+ * 两个都不行才落到这里,并打一条 warn 让用户知道降级了。
29
+ */
30
+
31
+ const AUTHOR_ONLY_JSON = 'json';
32
+
33
+ /**
34
+ * 编译一个属性表(`parameters` 或某个 object 节点的 `properties`)。
35
+ * @param {object} map - 属性名 → author value spec
36
+ * @param {string} path - 报错用的路径前缀
37
+ * @returns {{properties: object, required?: string[]}}
38
+ */
39
+ function compilePropertyMap(map, path) {
40
+ if (!map || typeof map !== 'object' || Array.isArray(map)) {
41
+ throw new Error(`${path} 必须是对象(属性名 → 值 schema)`);
42
+ }
43
+ const properties = {};
44
+ const required = [];
45
+ for (const [key, spec] of Object.entries(map)) {
46
+ if (!spec || typeof spec !== 'object' || Array.isArray(spec)) {
47
+ throw new Error(`${path}.${key} 必须是值 schema 对象`);
48
+ }
49
+ const { required: mark, ...rest } = spec;
50
+ if (mark !== undefined && mark !== true) throw new Error(`${path}.${key}.required 写了就只能是 true`);
51
+ if (mark === true) required.push(key);
52
+ properties[key] = compileValue(rest, `${path}.${key}`);
53
+ }
54
+ return required.length > 0 ? { properties, required } : { properties };
55
+ }
56
+
57
+ /**
58
+ * 编译一个值 schema。`type: 'json'` 退化成注解(不写 `type`)。
59
+ * @param {object} spec
60
+ * @param {string} path
61
+ * @returns {object}
62
+ */
63
+ function compileValue(spec, path) {
64
+ if (!spec || typeof spec !== 'object' || Array.isArray(spec)) {
65
+ throw new Error(`${path} 必须是值 schema 对象`);
66
+ }
67
+ const out = {};
68
+ for (const [key, value] of Object.entries(spec)) {
69
+ if (key === 'required') continue; // 由 compilePropertyMap 提走
70
+ if (key === 'properties') {
71
+ const compiled = compilePropertyMap(value, `${path}.properties`);
72
+ out.properties = compiled.properties;
73
+ if (compiled.required) out.required = compiled.required;
74
+ continue;
75
+ }
76
+ if (key === 'items') {
77
+ out.items = compileValue(value, `${path}.items`);
78
+ continue;
79
+ }
80
+ // author-only:任意 JSON。宿主把它变成"只有注解、没有 type"的 schema
81
+ if (key === 'type' && value === AUTHOR_ONLY_JSON) continue;
82
+ out[key] = value;
83
+ }
84
+ return out;
85
+ }
86
+
87
+ /**
88
+ * 编译 `parameters`:隐式开放对象,根上不写 `required`(除非属性显式标了)。
89
+ * @param {object} spec
90
+ * @returns {object}
91
+ */
92
+ export function parametersToJsonSchema(spec) {
93
+ const { properties, required } = compilePropertyMap(spec, 'parameters');
94
+ return { type: 'object', properties, ...(required ? { required } : {}) };
95
+ }
96
+
97
+ /**
98
+ * 编译 `output.schema`。
99
+ * @param {object} spec
100
+ * @returns {object}
101
+ */
102
+ export function outputSchemaToJsonSchema(spec) {
103
+ return compileValue(spec, 'schema');
104
+ }
105
+
106
+ /**
107
+ * `defineTool` 的兜底实现:**签名和返回值与宿主一致,只是不做运行时参数校验**。
108
+ * @param {object} options - 与宿主 `defineTool` 相同的入参
109
+ * @returns {object} registry-ready definition
110
+ */
111
+ export function defineToolCompat(options) {
112
+ if (!options || typeof options !== 'object') throw new Error('defineTool: options 必须是对象');
113
+ const { name, description, parameters, output, execute } = options;
114
+ if (typeof name !== 'string' || !name) throw new Error('defineTool: name 必须是非空字符串');
115
+ if (!output || typeof output !== 'object') throw new Error(`defineTool(${name}): 缺 output`);
116
+ if (typeof output.render !== 'function') throw new Error(`defineTool(${name}): output.render 必须是函数`);
117
+ if (typeof execute !== 'function') throw new Error(`defineTool(${name}): execute 必须是函数`);
118
+ if (options.timeoutMs !== undefined
119
+ && (!Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0)) {
120
+ throw new Error(`defineTool(${name}): timeoutMs 必须是正数`);
121
+ }
122
+
123
+ const tool = {
124
+ name,
125
+ description,
126
+ parameters: parametersToJsonSchema(parameters ?? {}),
127
+ output: {
128
+ schema: outputSchemaToJsonSchema(output.schema ?? {}),
129
+ render: output.render,
130
+ ...(typeof output.presentationMeta === 'function' ? { presentationMeta: output.presentationMeta } : {}),
131
+ },
132
+ ...(options.deferLoading === true ? { deferLoading: true } : {}),
133
+ ...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
134
+ async execute(args, exec) {
135
+ return execute(args, exec);
136
+ },
137
+ };
138
+ if (typeof options.projectContent === 'function') tool.projectContent = options.projectContent;
139
+ if (typeof options.finalizeContent === 'function') tool.finalizeContent = options.finalizeContent;
140
+ if (typeof options.presentCall === 'function') tool.presentCall = options.presentCall;
141
+ if (typeof options.presentResult === 'function') tool.presentResult = options.presentResult;
142
+ if (typeof options.isConcurrencySafe === 'function') tool.isConcurrencySafe = options.isConcurrencySafe;
143
+ return tool;
144
+ }