dia-bridge 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,18 @@
11
11
  - 「用 `dia-bridge_dia_ask` 问 Dia:……」(等待约 15~30 秒拿回完整回答)
12
12
  - 「用 `dia-bridge_dia_get_chat_history` 看最近回答」(直读本地日志,秒返回)
13
13
 
14
+ ### 可选:一键装 `/dia` 快捷指令(不用每次打长句子)
15
+
16
+ 想直接在对话里输入 `/dia 你的问题`、`/dia status`、`/dia history`,把本仓库自带的 [`skills/dia/SKILL.md`](skills/dia/SKILL.md) 复制到你的客户端技能目录即可:
17
+
18
+ ```bash
19
+ # DeepSeek Harness (DSH)
20
+ mkdir -p ~/.dsh/skills/dia && curl -fsSL https://raw.githubusercontent.com/DaBinBinah/dia-bridge/main/skills/dia/SKILL.md -o ~/.dsh/skills/dia/SKILL.md
21
+
22
+ # Claude Code / Codex / OpenCode(如使用 ~/.claude/skills 或 ~/.agents/skills)
23
+ mkdir -p ~/.claude/skills/dia && curl -fsSL https://raw.githubusercontent.com/DaBinBinah/dia-bridge/main/skills/dia/SKILL.md -o ~/.claude/skills/dia/SKILL.md
24
+ ```
25
+
14
26
  A Magpie (`kind: "tools"`) / OpenCode plugin that exposes the locally running **Dia** browser AI assistant (macOS `company.thebrowser.dia` / Windows `Dia`) to Claude Code, Codex, OpenCode, and other MCP-capable agents via a single `dia_ask(prompt)` tool.
15
27
 
16
28
  > **Terms of Service & Account Risk Warning / 风险提示**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dia-bridge",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "把 Dia 浏览器内置 AI 变成 MCP 工具,给 Claude Code / Magpie 用(支持 macOS / Windows,Linux 可远程连)| Bridge Dia browser AI into MCP tools for Claude Code & Magpie",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",
@@ -11,6 +11,7 @@
11
11
  "index.mjs",
12
12
  "bin/",
13
13
  "src/",
14
+ "skills/",
14
15
  "README.md",
15
16
  "LICENSE"
16
17
  ],
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: dia
3
+ description: 直接调用本地 Dia 浏览器内置 AI(dia_ask)回答用户问题。输入 /dia <问题> 即可一键提问 Dia,也可查历史回复(dia_get_chat_history)或自检状态(dia_status)。
4
+ ---
5
+
6
+ # /dia — 向 Dia 浏览器 AI 提问
7
+
8
+ 当用户使用 `/dia <问题>` 或要求向 Dia 提问时,按以下步骤执行:
9
+
10
+ 1. 直接调用 `dia_ask`(若带命名空间则为 `dia-bridge_dia_ask`),把用户 `/dia` 后面的完整问题作为 `prompt` 原样传入,不要擅自改写或截断用户问题。
11
+ 2. 等待工具返回后,直接把 Dia 的回复清晰呈现给用户(无需额外啰嗦说明,也不要自行编造回答)。
12
+ 3. 如果用户只输入了 `/dia status` 或询问连接状态,调用 `dia_status`。
13
+ 4. 如果用户输入了 `/dia history` 或想看最近回答,调用 `dia_get_chat_history`。
14
+ 5. 若调用报权限或未运行错误,先调用一次 `dia_status` 并将具体原因与修复提示简洁告诉用户。
15
+ 6. 若 `dia_ask` 返回超时(TIMEOUT),说明 Dia 可能仍在生成长回答或交互式内容,不要反复重复提问;直接告知用户 Dia 仍在生成中,或稍等片刻后调用 `dia_get_chat_history` 读取结果。
package/src/bridge.mjs CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  export const DEFAULT_TIMEOUT_MS = 50000
24
24
  export const MIN_TIMEOUT_MS = 1000
25
25
  export const MAX_TIMEOUT_MS = 300000
26
+ export const DEFAULT_DEDUP_WINDOW_MS = 180000
26
27
 
27
28
  export function normalizeTimeoutMs(value, fallback = DEFAULT_TIMEOUT_MS) {
28
29
  if (value === undefined || value === null) return fallback
@@ -72,6 +73,10 @@ export function createDiaBridge(config = {}) {
72
73
  const pollIntervalMs = config.pollIntervalMs ?? 350
73
74
  const settleMs = config.settleMs ?? 400
74
75
  const workFallbackSettleMs = config.workFallbackSettleMs ?? 2000
76
+ const dedupWindowMs =
77
+ typeof config.dedupWindowMs === "number" && config.dedupWindowMs >= 0
78
+ ? config.dedupWindowMs
79
+ : DEFAULT_DEDUP_WINDOW_MS
75
80
 
76
81
  const deps = {
77
82
  checkEnv: config.deps?.checkEnv ?? backend.checkEnv,
@@ -84,6 +89,7 @@ export function createDiaBridge(config = {}) {
84
89
  (() => config.contextsDir ?? getDefaultContextsDir({ platform })),
85
90
  }
86
91
  const log = createLogger("dia-bridge")
92
+ let pendingSubmission = null
87
93
 
88
94
  async function ask(prompt, options = {}) {
89
95
  if (typeof prompt !== "string" || prompt.trim().length === 0) {
@@ -120,17 +126,39 @@ export function createDiaBridge(config = {}) {
120
126
  platform,
121
127
  })
122
128
 
129
+ const promptKey = prompt.trim()
123
130
  const contextsDir = deps.getContextsDir()
124
- const snapshot = await deps.captureSnapshot(contextsDir)
125
- log.debug("captured snapshot", { contexts: snapshot.contexts.size })
126
-
127
- const submitRes = await deps.submitPrompt(prompt, {
128
- signal,
129
- timeoutMs: Math.min(25000, remainingMs(backend.submitStage)),
130
- bundleId,
131
- processName,
132
- })
133
- log.debug("submitted prompt", { method: submitRes?.method, length: prompt.length })
131
+ const canReusePending =
132
+ dedupWindowMs > 0 &&
133
+ pendingSubmission !== null &&
134
+ pendingSubmission.promptKey === promptKey &&
135
+ pendingSubmission.contextsDir === contextsDir &&
136
+ Date.now() - pendingSubmission.submittedAt < dedupWindowMs
137
+
138
+ let snapshot
139
+ if (canReusePending) {
140
+ snapshot = pendingSubmission.snapshot
141
+ log.debug("reusing pending submission after prior timeout/abort; skipping duplicate submit", {
142
+ length: prompt.length,
143
+ })
144
+ } else {
145
+ snapshot = await deps.captureSnapshot(contextsDir)
146
+ log.debug("captured snapshot", { contexts: snapshot.contexts.size })
147
+
148
+ const submitRes = await deps.submitPrompt(prompt, {
149
+ signal,
150
+ timeoutMs: Math.min(25000, remainingMs(backend.submitStage)),
151
+ bundleId,
152
+ processName,
153
+ })
154
+ pendingSubmission = {
155
+ promptKey,
156
+ snapshot,
157
+ contextsDir,
158
+ submittedAt: Date.now(),
159
+ }
160
+ log.debug("submitted prompt", { method: submitRes?.method, length: prompt.length })
161
+ }
134
162
 
135
163
  const result = await deps.pollForNewAnswer(contextsDir, snapshot, {
136
164
  signal,
@@ -141,6 +169,7 @@ export function createDiaBridge(config = {}) {
141
169
  workFallbackSettleMs,
142
170
  })
143
171
 
172
+ pendingSubmission = null
144
173
  log.debug("received answer", { contextId: result.contextId, source: result.source })
145
174
  return result.answer
146
175
  } finally {
package/src/errors.mjs CHANGED
@@ -57,7 +57,7 @@ export class DiaTimeoutError extends DiaBridgeError {
57
57
  constructor(timeoutMs, stage = "waiting for Dia response") {
58
58
  super(
59
59
  "TIMEOUT",
60
- `dia_ask timed out after ${timeoutMs}ms while ${stage}. Note: Dia responses typically take 15-50s and Magpie enforces a 55s tool call limit.`,
60
+ `dia_ask timed out after ${timeoutMs}ms while ${stage}. Dia may still be generating the reply — do not spam duplicate retries (use dia_get_chat_history after a short wait; retrying the exact same prompt within 3 minutes resumes waiting without re-submitting).`,
61
61
  )
62
62
  this.timeoutMs = timeoutMs
63
63
  this.stage = stage