@xiaoqiong0v0/opencode-browser-tool 1.7.0 → 1.9.0
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 +15 -9
- package/dist/binary.js +15 -9
- package/dist/client.js +448 -170
- package/dist/config/index.js +22 -10
- package/dist/i18n/en.js +123 -19
- package/dist/i18n/index.js +17 -0
- package/dist/i18n/zh.js +123 -19
- package/dist/index.js +189 -154
- package/dist/notify-server.js +16 -5
- package/package.json +1 -1
package/dist/notify-server.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
// 插件侧通知监听:shell 发送记录后主动 POST /notify 到这里(推送式投递,替代轮询)。
|
|
1
|
+
// 插件侧通知监听:shell 发送记录后主动 POST /notify[/<sid>] 到这里(推送式投递,替代轮询)。
|
|
2
2
|
// 仅绑定 127.0.0.1 + 随机空闲端口;端点只接收最小信息(count),大内容仍由插件走
|
|
3
3
|
// /api/annotate/consume-sent 拉取(drain)。
|
|
4
|
+
//
|
|
5
|
+
// 1.9.0 会话隔离:每个 shell 实例注册自己的 `/notify/<sid>`,通知按 URL 里的 sid 路由到
|
|
6
|
+
// 对应会话的 drain —— 彻底取代旧的「最后活跃会话」(last-writer-wins)投递。
|
|
4
7
|
import { createServer } from "node:http";
|
|
5
8
|
let server = null;
|
|
6
9
|
let port = 0;
|
|
10
|
+
/** 收到通知时的回调:参数为通知 URL 里的 sid(空串 = 未带 sid 的旧格式 /notify) */
|
|
7
11
|
let onNotify = null;
|
|
8
|
-
/** 启动监听(幂等);返回实际端口。onNotify 在收到 shell 通知时被调用 */
|
|
12
|
+
/** 启动监听(幂等);返回实际端口。onNotify 在收到 shell 通知时被调用(带 sid) */
|
|
9
13
|
export async function startNotifyServer(handler) {
|
|
10
14
|
onNotify = handler;
|
|
11
15
|
if (server && port)
|
|
12
16
|
return port;
|
|
13
17
|
return new Promise((resolvePort, reject) => {
|
|
14
18
|
const srv = createServer((req, res) => {
|
|
15
|
-
|
|
19
|
+
const url = req.url || "";
|
|
20
|
+
if (req.method !== "POST" || !url.startsWith("/notify")) {
|
|
16
21
|
res.writeHead(404, { "content-type": "application/json" });
|
|
17
22
|
res.end('{"ok":false}');
|
|
18
23
|
return;
|
|
19
24
|
}
|
|
25
|
+
// 从路径提取 sid:/notify/<sid>;裸 /notify(旧格式)→ sid = ""
|
|
26
|
+
const sid = url.startsWith("/notify/") ? decodeURIComponent(url.slice("/notify/".length)) : "";
|
|
20
27
|
// 只读取/丢弃最小 payload,避免大内容经此通道
|
|
21
28
|
let bytes = 0;
|
|
22
29
|
req.on("data", (c) => {
|
|
@@ -28,7 +35,7 @@ export async function startNotifyServer(handler) {
|
|
|
28
35
|
res.writeHead(200, { "content-type": "application/json" });
|
|
29
36
|
res.end('{"ok":true}');
|
|
30
37
|
try {
|
|
31
|
-
onNotify?.();
|
|
38
|
+
onNotify?.(sid);
|
|
32
39
|
}
|
|
33
40
|
catch {
|
|
34
41
|
// 忽略回调异常,不影响响应
|
|
@@ -47,7 +54,11 @@ export async function startNotifyServer(handler) {
|
|
|
47
54
|
});
|
|
48
55
|
});
|
|
49
56
|
}
|
|
50
|
-
/**
|
|
57
|
+
/** 未带 sid 的基础通知地址(仅兼容旧用法;新代码请用 getNotifyUrlForSession) */
|
|
51
58
|
export function getNotifyUrl() {
|
|
52
59
|
return server && port ? `http://127.0.0.1:${port}/notify` : null;
|
|
53
60
|
}
|
|
61
|
+
/** 某会话的通知地址:每个 shell 实例注册各自这条 → 通知可按 sid 归属 */
|
|
62
|
+
export function getNotifyUrlForSession(sid) {
|
|
63
|
+
return server && port ? `http://127.0.0.1:${port}/notify/${encodeURIComponent(sid)}` : null;
|
|
64
|
+
}
|