@allbluecn/web-app 0.28.11 → 0.28.13
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/package.json +5 -5
- package/public/dev-gallery.html +19 -0
- package/src/__tests__/bench/baselines/format-timestamp.json +44 -0
- package/src/__typeprobe__.d.ts +4 -0
- package/src/components/harness/extension-panel/panels/terminal/__tests__/terminal-instance.test.tsx +93 -4
- package/src/components/harness/extension-panel/panels/terminal/sse-transport.ts +28 -5
- package/src/components/harness/extension-panel/panels/terminal/terminal-instance.tsx +53 -10
- package/src/components/harness/extension-panel/panels/terminal/transport.ts +10 -3
- package/src/components/harness/extension-panel/panels/terminal/ws-transport.ts +13 -2
- package/src/components/settings/harness/connectors-card.tsx +5 -0
- package/src/components/story/detail/story-detail-toolbar/associated-attachments-panel.tsx +2 -1
- package/src/dev/gallery-entry.tsx +38 -0
- package/src/dev/gallery.tsx +610 -0
- package/src/lib/changelog/sdk-versions.ts +4 -4
- package/src/lib/session.ts +10 -0
- package/src/paraglide/README.md +1 -1
- package/src/paraglide/messages/_index.d.ts +9 -0
- package/src/paraglide/messages/_index.js +9 -0
- package/src/paraglide/messages/capabilities_webhook.d.ts +16 -0
- package/src/paraglide/messages/capabilities_webhook.js +29 -0
- package/src/paraglide/messages/capabilities_workflow.d.ts +16 -0
- package/src/paraglide/messages/capabilities_workflow.js +29 -0
- package/src/paraglide/messages/harness_panel_terminal_exitedrecycled1.d.ts +17 -0
- package/src/paraglide/messages/harness_panel_terminal_exitedrecycled1.js +30 -0
- package/src/paraglide/messages/harness_panel_terminal_restarted.d.ts +16 -0
- package/src/paraglide/messages/harness_panel_terminal_restarted.js +29 -0
- package/src/paraglide/messages/settings_harness_connectors_needsauth1.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_connectors_needsauth1.js +30 -0
- package/src/paraglide/messages/settings_harness_ralphenabled1.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_ralphenabled1.js +30 -0
- package/src/paraglide/messages/settings_harness_ralphenabled_description1.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_ralphenabled_description1.js +30 -0
- package/src/paraglide/messages/settings_harness_ralphmaxrounds2.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_ralphmaxrounds2.js +30 -0
- package/src/paraglide/messages/settings_harness_ralphmaxrounds_description2.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_ralphmaxrounds_description2.js +30 -0
- package/src/routeTree.gen.ts +21 -0
- package/src/routes/api/auth/desktop-callback.ts +9 -0
- package/src/routes/api/chat.ts +8 -1
- package/src/routes/api/harness/browser/proxy.ts +41 -12
- package/src/routes/api/harness/terminal/$.ts +32 -13
- package/src/routes/api/harness/terminal/__tests__/route.test.ts +41 -0
- package/src/routes/api/harness/webhook/$token.ts +23 -0
- package/src/routes/api/sync/__tests__/bootstrap.test.ts +32 -1
- package/src/routes/api/sync/bootstrap.ts +11 -0
- package/src/server/ai-gateway/adapter.ts +7 -3
- package/src/server/ai-gateway/connectivity-check.ts +3 -2
- package/src/server/ai-gateway/durability/__tests__/sse-resume-frames.test.ts +123 -0
- package/src/server/ai-gateway/embedding.ts +3 -2
- package/src/server/ai-gateway/model-fetch.ts +3 -2
- package/src/server/ai-gateway/sandbox/__tests__/provider.test.ts +12 -1
- package/src/server/ai-gateway/sandbox/policy.ts +27 -1
- package/src/server/ai-gateway/sandbox/provider.ts +10 -0
- package/src/server/ai-gateway/tools/definitions.ts +1 -1
- package/src/server/ai-gateway/tools/server.ts +4 -2
- package/src/server/harness/__tests__/agent-terminal-sandbox.test.ts +23 -4
- package/src/server/harness/__tests__/agent-terminal.server.test.ts +118 -2
- package/src/server/harness/__tests__/credentials.server.test.ts +25 -2
- package/src/server/harness/__tests__/host-schedule-worker.test.ts +43 -0
- package/src/server/harness/__tests__/runtime-without-providers.test.ts +11 -0
- package/src/server/harness/__tests__/sticky-route.test.ts +86 -0
- package/src/server/harness/__tests__/terminal-foreground.server.test.ts +80 -0
- package/src/server/harness/__tests__/terminal-manager.server.test.ts +75 -1
- package/src/server/harness/__tests__/tool-entitlements.test.ts +6 -2
- package/src/server/harness/agent-terminal.server.ts +25 -4
- package/src/server/harness/agents/__tests__/agent-control.test.ts +1 -0
- package/src/server/harness/agents/run-view.server.ts +55 -2
- package/src/server/harness/capabilities/__tests__/__snapshots__/matrix.test.ts.snap +92 -0
- package/src/server/harness/capabilities/__tests__/execution-plane-denials.test.ts +3 -1
- package/src/server/harness/capabilities/__tests__/p3-matrix.test.ts +3 -3
- package/src/server/harness/capabilities/__tests__/p5-matrix.test.ts +293 -0
- package/src/server/harness/capabilities/__tests__/validate.test.ts +8 -2
- package/src/server/harness/capabilities/execution-plane-denials.ts +9 -3
- package/src/server/harness/capabilities/manifests/agent-terminal.ts +3 -2
- package/src/server/harness/capabilities/manifests/webhook.ts +45 -0
- package/src/server/harness/capabilities/manifests/workflow.ts +40 -0
- package/src/server/harness/capabilities/registry.ts +4 -0
- package/src/server/harness/connectors/__tests__/connector-accounts.test.ts +22 -1
- package/src/server/harness/connectors/connector-accounts.server.ts +7 -0
- package/src/server/harness/credentials.server.ts +3 -1
- package/src/server/harness/define.server.ts +11 -0
- package/src/server/harness/mcp/mcp-config.server.ts +3 -1
- package/src/server/harness/outbox/outbox-dispatcher.server.ts +9 -0
- package/src/server/harness/outbox/outbox-store.server.ts +7 -0
- package/src/server/harness/persistence/__tests__/log-store.server.test.ts +4 -1
- package/src/server/harness/plugins/__tests__/tool-risk-audit.test.ts +5 -1
- package/src/server/harness/plugins/builtin/agent-terminal.plugin.ts +12 -2
- package/src/server/harness/providers/contracts.ts +16 -0
- package/src/server/harness/schedule/schedule-dispatcher.server.ts +3 -0
- package/src/server/harness/search/__tests__/indexer.test.ts +4 -1
- package/src/server/harness/search/__tests__/lifecycle.test.ts +4 -1
- package/src/server/harness/search/__tests__/search.test.ts +4 -1
- package/src/server/harness/sticky-route.server.ts +72 -0
- package/src/server/harness/terminal-foreground.server.ts +90 -0
- package/src/server/harness/terminal-manager.server.ts +78 -3
- package/src/server/harness/tool-entitlements.server.ts +5 -0
- package/src/server/harness/webhook/__tests__/body.test.ts +73 -0
- package/src/server/harness/webhook/__tests__/payload.test.ts +215 -0
- package/src/server/harness/webhook/__tests__/signature.test.ts +170 -0
- package/src/server/harness/webhook/__tests__/webhook-dispatcher.test.ts +212 -0
- package/src/server/harness/webhook/__tests__/webhook.plugin.test.ts +195 -0
- package/src/server/harness/webhook/__tests__/webhook.service.test.ts +354 -0
- package/src/server/harness/webhook/body.server.ts +56 -0
- package/src/server/harness/webhook/payload.server.ts +169 -0
- package/src/server/harness/webhook/signature.server.ts +118 -0
- package/src/server/harness/webhook/types.ts +57 -0
- package/src/server/harness/webhook/webhook-dispatcher.server.ts +495 -0
- package/src/server/harness/webhook/webhook-store.server.ts +115 -0
- package/src/server/harness/webhook/webhook.plugin.ts +273 -0
- package/src/server/harness/webhook/webhook.service.server.ts +577 -0
- package/src/server/harness/worker/__tests__/worker-http.test.ts +8 -1
- package/src/server/harness/worker/worker-health.server.ts +4 -1
- package/src/server/harness/worker/worker-runtime.server.ts +43 -1
- package/src/server/harness/workflow/__tests__/engine.test.ts +195 -0
- package/src/server/harness/workflow/__tests__/settings.test.ts +125 -0
- package/src/server/harness/workflow/__tests__/validate.test.ts +151 -0
- package/src/server/harness/workflow/engine.server.ts +155 -0
- package/src/server/harness/workflow/settings.ts +84 -0
- package/src/server/harness/workflow/store.server.ts +147 -0
- package/src/server/harness/workflow/types.ts +80 -0
- package/src/server/harness/workflow/validate.ts +130 -0
- package/src/server/harness/workflow/workflow.plugin.ts +261 -0
- package/src/server/knowledge/search-scope.ts +8 -1
- package/src/server/middlewares/security-headers.ts +1 -0
- package/src/server/serverFns/__tests__/link-preview.test.ts +2 -2
- package/src/server/serverFns/collab.ts +4 -0
- package/src/server/serverFns/design/versions.ts +6 -0
- package/src/server/serverFns/harness/__tests__/fork-thread.test.ts +14 -1
- package/src/server/serverFns/harness/fork-thread.ts +17 -0
- package/src/server/serverFns/story/link-preview.ts +3 -2
- package/src/server-entry.ts +13 -1
- package/src/start.ts +15 -1
- package/vite.shared.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbluecn/web-app",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.13",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@ag-ui/core": "1.0.0",
|
|
66
66
|
"@allbluecn/collab-core": "0.2.1",
|
|
67
|
-
"@allbluecn/collab-server": "0.1.
|
|
68
|
-
"@allbluecn/database": "0.14.
|
|
67
|
+
"@allbluecn/collab-server": "0.1.8",
|
|
68
|
+
"@allbluecn/database": "0.14.12",
|
|
69
69
|
"@allbluecn/dsh-compat": "0.0.3",
|
|
70
|
-
"@allbluecn/kernel": "0.12.
|
|
71
|
-
"@allbluecn/sync-core": "0.7.
|
|
70
|
+
"@allbluecn/kernel": "0.12.4",
|
|
71
|
+
"@allbluecn/sync-core": "0.7.4",
|
|
72
72
|
"@ariakit/react": "^0.4.28",
|
|
73
73
|
"@auth/core": "^0.41.2",
|
|
74
74
|
"@auth/prisma-adapter": "^2.11.2",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>组件形态画廊(本地验收)</title>
|
|
7
|
+
<!-- 本地专用页面:不入 git,不参与生产构建,仅供浏览器自动化验收。
|
|
8
|
+
打开方式:http://localhost:3000/dev-gallery.html -->
|
|
9
|
+
<style>
|
|
10
|
+
html, body, #root { height: 100%; }
|
|
11
|
+
body { margin: 0; background: hsl(0 0% 100%); color: hsl(240 10% 3.9%); font-family: system-ui, -apple-system, sans-serif; }
|
|
12
|
+
.dark body { background: hsl(240 10% 3.9%); color: hsl(0 0% 98%); }
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<div id="root"></div>
|
|
17
|
+
<script type="module" src="/src/dev/gallery-entry.tsx"></script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"latency": {
|
|
3
|
+
"aad": 0.048410276139197045,
|
|
4
|
+
"critical": 1.96,
|
|
5
|
+
"df": 1059,
|
|
6
|
+
"mad": 0.022145999999793275,
|
|
7
|
+
"max": 3.373666999999841,
|
|
8
|
+
"mean": 0.94407134433964,
|
|
9
|
+
"min": 0.8770409999997355,
|
|
10
|
+
"moe": 0.007457128456580703,
|
|
11
|
+
"p50": 0.9219379999999546,
|
|
12
|
+
"p75": 0.9482297500001096,
|
|
13
|
+
"p99": 1.549765560000042,
|
|
14
|
+
"p995": 1.6288096400004497,
|
|
15
|
+
"p999": 1.8190369999991707,
|
|
16
|
+
"rme": 0.7898903511150234,
|
|
17
|
+
"samplesCount": 1060,
|
|
18
|
+
"sd": 0.12387066970076242,
|
|
19
|
+
"sem": 0.0038046573758064813,
|
|
20
|
+
"variance": 0.015343942812115383
|
|
21
|
+
},
|
|
22
|
+
"throughput": {
|
|
23
|
+
"aad": 43.792207103583756,
|
|
24
|
+
"critical": 1.96,
|
|
25
|
+
"df": 1059,
|
|
26
|
+
"mad": 25.941182125708224,
|
|
27
|
+
"max": 1140.1975506279657,
|
|
28
|
+
"mean": 1068.8147818211185,
|
|
29
|
+
"min": 296.4133685986338,
|
|
30
|
+
"moe": 4.749020957923807,
|
|
31
|
+
"p50": 1084.6716379180502,
|
|
32
|
+
"p75": 1108.6600489500372,
|
|
33
|
+
"p99": 1137.598277984184,
|
|
34
|
+
"p995": 1138.8284369378687,
|
|
35
|
+
"p999": 1140.1930292151646,
|
|
36
|
+
"rme": 0.4443259055448416,
|
|
37
|
+
"samplesCount": 1060,
|
|
38
|
+
"sd": 78.88618385832574,
|
|
39
|
+
"sem": 2.422969876491738,
|
|
40
|
+
"variance": 6223.030003729573
|
|
41
|
+
},
|
|
42
|
+
"period": 0.9440713443396405,
|
|
43
|
+
"totalTime": 1000.7156250000189
|
|
44
|
+
}
|
package/src/components/harness/extension-panel/panels/terminal/__tests__/terminal-instance.test.tsx
CHANGED
|
@@ -166,8 +166,10 @@ function storedBindingId(threadId = "th1", tabId = "terminal-1"): string | null
|
|
|
166
166
|
|
|
167
167
|
/** 装配 fetch 替身:create/input/ack 路由 + 记录 input 载荷 + create 调用数。
|
|
168
168
|
* notFoundTermIds:命中 id 的 events 探测返回 404(服务端已无此终端——dev/host 重启或
|
|
169
|
-
* idle 回收后 binding 存活死 id),驱动 attach 的 notFound→create 重建路径。
|
|
170
|
-
|
|
169
|
+
* idle 回收后 binding 存活死 id),驱动 attach 的 notFound→create 重建路径。
|
|
170
|
+
* createInstanceId / notFoundInstanceId:P5 任务 8 多实例 sticky——create 响应与 404 body
|
|
171
|
+
* 各带实例标识,客户端据「binding 记的实例 ≠ 404 报的实例」判定为换实例(静默重建)。 */
|
|
172
|
+
function stubFetch(opts: { createShell?: string; failCreate?: boolean; envUnavailable?: boolean; notFoundTermIds?: string[]; notFoundEpoch?: string; createInstanceId?: string; notFoundInstanceId?: string } = {}) {
|
|
171
173
|
const inputBodies: Array<{ writes?: Array<{ seq: number, data: string, typed?: boolean }>; resize?: { cols: number, rows: number } }> = []
|
|
172
174
|
let createCalls = 0
|
|
173
175
|
const fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
@@ -178,7 +180,12 @@ function stubFetch(opts: { createShell?: string; failCreate?: boolean; envUnavai
|
|
|
178
180
|
return jsonResponse({ error: "terminal_env_unavailable", message: "env down" }, 503)
|
|
179
181
|
}
|
|
180
182
|
if (opts.failCreate) return jsonResponse({ error: "terminal_limit", message: "上限" }, 409)
|
|
181
|
-
return jsonResponse({
|
|
183
|
+
return jsonResponse({
|
|
184
|
+
terminalId: `term_${createCalls}`,
|
|
185
|
+
shell: opts.createShell ?? "/bin/zsh",
|
|
186
|
+
serverEpoch: "epoch_test",
|
|
187
|
+
...(opts.createInstanceId ? { instanceId: opts.createInstanceId } : {}),
|
|
188
|
+
})
|
|
182
189
|
}
|
|
183
190
|
if (url.includes("/input")) {
|
|
184
191
|
inputBodies.push(JSON.parse(String(init?.body ?? "{}")))
|
|
@@ -188,7 +195,18 @@ function stubFetch(opts: { createShell?: string; failCreate?: boolean; envUnavai
|
|
|
188
195
|
// events 探测(SSE connect 前置):命中的死 id → 404 terminal_not_found
|
|
189
196
|
if (url.includes("/events")) {
|
|
190
197
|
const dead = opts.notFoundTermIds?.some((id) => url.includes(`/${id}/events`))
|
|
191
|
-
if (dead)
|
|
198
|
+
if (dead) {
|
|
199
|
+
// 404 body 按方案 C 带服务端代际(P5 任务 4)+ 实例标识(P5 任务 8)。
|
|
200
|
+
return jsonResponse(
|
|
201
|
+
{
|
|
202
|
+
error: "terminal_not_found",
|
|
203
|
+
message: "终端不存在",
|
|
204
|
+
...(opts.notFoundEpoch ? { serverEpoch: opts.notFoundEpoch } : {}),
|
|
205
|
+
...(opts.notFoundInstanceId ? { instanceId: opts.notFoundInstanceId } : {}),
|
|
206
|
+
},
|
|
207
|
+
404,
|
|
208
|
+
)
|
|
209
|
+
}
|
|
192
210
|
}
|
|
193
211
|
return jsonResponse({})
|
|
194
212
|
})
|
|
@@ -299,6 +317,77 @@ describe("死 terminalId 自动重建(dev/host 重启或 idle 回收后 bindin
|
|
|
299
317
|
expect(storedBindingId()).toBe("term_1")
|
|
300
318
|
})
|
|
301
319
|
|
|
320
|
+
it("404 代际变了 → 提示「服务端已重启」并自动重建(P5 任务 4:epoch 分流 UI)", async () => {
|
|
321
|
+
// binding 记 epoch_old;404 body 带 epoch_new → 服务端换了实例(重启/重新部署)
|
|
322
|
+
window.localStorage.setItem(
|
|
323
|
+
"allblue.harness.terminal-binding.v1.th1.terminal-1",
|
|
324
|
+
JSON.stringify({ terminalId: "term_dead", serverEpoch: "epoch_old" }),
|
|
325
|
+
)
|
|
326
|
+
const infoSpy = vi.spyOn(toast, "info")
|
|
327
|
+
const { getCreateCalls } = stubFetch({ notFoundTermIds: ["term_dead"], notFoundEpoch: "epoch_new" })
|
|
328
|
+
render(<TerminalInstance threadId="th1" tabId="terminal-1" />)
|
|
329
|
+
await waitFor(() => expect(getCreateCalls()).toBe(1))
|
|
330
|
+
expect(infoSpy).toHaveBeenCalledWith(m.harness_panel_terminal_restarted())
|
|
331
|
+
expect(storedBindingId()).toBe("term_1") // 重建行为不变(提示不改变恢复链)
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
it("404 代际未变 → 提示「终端已退出/被回收」并自动重建", async () => {
|
|
335
|
+
window.localStorage.setItem(
|
|
336
|
+
"allblue.harness.terminal-binding.v1.th1.terminal-1",
|
|
337
|
+
JSON.stringify({ terminalId: "term_dead", serverEpoch: "epoch_same" }),
|
|
338
|
+
)
|
|
339
|
+
const infoSpy = vi.spyOn(toast, "info")
|
|
340
|
+
const { getCreateCalls } = stubFetch({ notFoundTermIds: ["term_dead"], notFoundEpoch: "epoch_same" })
|
|
341
|
+
render(<TerminalInstance threadId="th1" tabId="terminal-1" />)
|
|
342
|
+
await waitFor(() => expect(getCreateCalls()).toBe(1))
|
|
343
|
+
expect(infoSpy).toHaveBeenCalledWith(m.harness_panel_terminal_exitedRecycled())
|
|
344
|
+
expect(infoSpy).not.toHaveBeenCalledWith(m.harness_panel_terminal_restarted())
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
it("换实例(404 报的 instanceId ≠ binding 记的)→ 不提示,静默重建(P5 任务 8 三态分流)", async () => {
|
|
348
|
+
// 多实例 sticky 未命中:请求落到没有这个 PTY 的机器,必 404。这**不是故障**,
|
|
349
|
+
// 即使 epoch 未变也不能弹「终端已退出/被回收」——那会让用户以为终端炸了。
|
|
350
|
+
window.localStorage.setItem(
|
|
351
|
+
"allblue.harness.terminal-binding.v1.th1.terminal-1",
|
|
352
|
+
JSON.stringify({ terminalId: "term_dead", serverEpoch: "epoch_same", instanceId: "host-a:1" }),
|
|
353
|
+
)
|
|
354
|
+
const infoSpy = vi.spyOn(toast, "info")
|
|
355
|
+
const { getCreateCalls } = stubFetch({
|
|
356
|
+
notFoundTermIds: ["term_dead"],
|
|
357
|
+
notFoundEpoch: "epoch_same", // 同代际:单看 epoch 会被误判成「终端回收」
|
|
358
|
+
notFoundInstanceId: "host-b:2", // 但实例不同 → 就是粘性漂移
|
|
359
|
+
})
|
|
360
|
+
render(<TerminalInstance threadId="th1" tabId="terminal-1" />)
|
|
361
|
+
await waitFor(() => expect(getCreateCalls()).toBe(1))
|
|
362
|
+
expect(infoSpy).not.toHaveBeenCalledWith(m.harness_panel_terminal_exitedRecycled())
|
|
363
|
+
expect(infoSpy).not.toHaveBeenCalledWith(m.harness_panel_terminal_restarted())
|
|
364
|
+
expect(storedBindingId()).toBe("term_1") // 重建照旧:不提示不等于不恢复
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
it("create 响应的 instanceId 写入 binding(供后续 404 三态分流比对)", async () => {
|
|
368
|
+
stubFetch({ createInstanceId: "host-a:1" })
|
|
369
|
+
await renderTerminal()
|
|
370
|
+
act(() => FakeEventSource.last().emit({ type: "snapshot", connectionId: "c1", sequence: 0, screen: "$ ", info: { cols: 80, rows: 24, shell: "/bin/zsh" }, writable: true }))
|
|
371
|
+
await waitFor(() => expect(screen.getByTestId("dock-terminal-instance").getAttribute("data-terminal-phase")).toBe("connected"))
|
|
372
|
+
const raw = window.localStorage.getItem("allblue.harness.terminal-binding.v1.th1.terminal-1")
|
|
373
|
+
expect(raw).toBeTruthy()
|
|
374
|
+
expect(JSON.parse(raw!)).toEqual({
|
|
375
|
+
terminalId: "term_1",
|
|
376
|
+
serverEpoch: "epoch_test",
|
|
377
|
+
instanceId: "host-a:1",
|
|
378
|
+
})
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
it("代际未知(旧纯 id binding / 404 不带 epoch)→ 不提示,维持静默重建(不猜)", async () => {
|
|
382
|
+
window.localStorage.setItem("allblue.harness.terminal-binding.v1.th1.terminal-1", "term_dead")
|
|
383
|
+
const infoSpy = vi.spyOn(toast, "info")
|
|
384
|
+
const { getCreateCalls } = stubFetch({ notFoundTermIds: ["term_dead"] })
|
|
385
|
+
render(<TerminalInstance threadId="th1" tabId="terminal-1" />)
|
|
386
|
+
await waitFor(() => expect(getCreateCalls()).toBe(1))
|
|
387
|
+
expect(infoSpy).not.toHaveBeenCalledWith(m.harness_panel_terminal_restarted())
|
|
388
|
+
expect(infoSpy).not.toHaveBeenCalledWith(m.harness_panel_terminal_exitedRecycled())
|
|
389
|
+
})
|
|
390
|
+
|
|
302
391
|
it("重建后服务端仍 404(持续不可用)→ 守卫生效,不无限 create 循环", async () => {
|
|
303
392
|
window.localStorage.setItem("allblue.harness.terminal-binding.v1.th1.terminal-1", "term_dead")
|
|
304
393
|
// 仅 binding 的死 id 探测 404;重建的新终端探测通过但 EventSource 层 404(模拟真实浏览器
|
|
@@ -69,14 +69,30 @@ export function createSseTransport(options: TerminalTransportOptions): TerminalT
|
|
|
69
69
|
| null
|
|
70
70
|
return { ok: false, error: errBody?.message ?? null, errorCode: errBody?.error }
|
|
71
71
|
}
|
|
72
|
-
const data = (await res.json()) as {
|
|
73
|
-
|
|
72
|
+
const data = (await res.json()) as {
|
|
73
|
+
terminalId: string
|
|
74
|
+
shell: string
|
|
75
|
+
serverEpoch?: string
|
|
76
|
+
instanceId?: string
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
ok: true,
|
|
80
|
+
terminalId: data.terminalId,
|
|
81
|
+
shell: data.shell,
|
|
82
|
+
serverEpoch: data.serverEpoch,
|
|
83
|
+
instanceId: data.instanceId,
|
|
84
|
+
}
|
|
74
85
|
} catch {
|
|
75
86
|
return { ok: false, error: null }
|
|
76
87
|
}
|
|
77
88
|
},
|
|
78
89
|
|
|
79
|
-
async connect(termId): Promise<{
|
|
90
|
+
async connect(termId): Promise<{
|
|
91
|
+
ok: boolean
|
|
92
|
+
notFound?: boolean
|
|
93
|
+
serverEpoch?: string
|
|
94
|
+
instanceId?: string
|
|
95
|
+
}> {
|
|
80
96
|
terminalId = termId
|
|
81
97
|
const eventUrl = apiBase(`${termId}/events?threadId=${encodeURIComponent(threadId)}`)
|
|
82
98
|
// EventSource 读不到 HTTP 状态码(404/503 一律 onerror)——先探测一次区分
|
|
@@ -87,8 +103,15 @@ export function createSseTransport(options: TerminalTransportOptions): TerminalT
|
|
|
87
103
|
const probe = await fetch(eventUrl)
|
|
88
104
|
if (probe.status === 404) {
|
|
89
105
|
terminalId = null
|
|
90
|
-
const body = (await probe.json().catch(() => null)) as
|
|
91
|
-
|
|
106
|
+
const body = (await probe.json().catch(() => null)) as
|
|
107
|
+
| { serverEpoch?: string; instanceId?: string }
|
|
108
|
+
| null
|
|
109
|
+
return {
|
|
110
|
+
ok: false,
|
|
111
|
+
notFound: true,
|
|
112
|
+
serverEpoch: body?.serverEpoch,
|
|
113
|
+
instanceId: body?.instanceId,
|
|
114
|
+
}
|
|
92
115
|
}
|
|
93
116
|
// 非 404(200 SSE 流 / 401 / 429 等)→ 交由 EventSource 处理;探测响应体不消费,
|
|
94
117
|
// 直接取消(EventSource 会重新发起真正的流连接)。
|
|
@@ -69,12 +69,14 @@ const FOCUS_REPORTS = ["\x1b[I", "\x1b[O"]
|
|
|
69
69
|
function bindingKey(threadId: string, tabId: string): string {
|
|
70
70
|
return `${BINDING_PREFIX}.${threadId}.${tabId}`
|
|
71
71
|
}
|
|
72
|
-
/** binding 存 {terminalId, serverEpoch}(方案 C)。serverEpoch
|
|
73
|
-
*
|
|
74
|
-
*
|
|
72
|
+
/** binding 存 {terminalId, serverEpoch, instanceId}(方案 C + P5 任务 8)。serverEpoch 供重连
|
|
73
|
+
* 比对区分「服务端重启」(epoch 变)与「终端退出/idle 回收」(epoch 不变);instanceId 再
|
|
74
|
+
* 区分「本次请求落到别的实例」(多实例 sticky 未命中——PTY 只活在一个进程里,跨实例必 404,
|
|
75
|
+
* 这不是故障,不该弹「服务重启」)。兼容旧纯 id 值:读到非 JSON/缺字段视为未知,走 404 兜底。 */
|
|
75
76
|
interface TerminalBinding {
|
|
76
77
|
terminalId: string
|
|
77
78
|
serverEpoch?: string
|
|
79
|
+
instanceId?: string
|
|
78
80
|
}
|
|
79
81
|
function readBinding(threadId: string, tabId: string): TerminalBinding | null {
|
|
80
82
|
try {
|
|
@@ -92,9 +94,19 @@ function readBinding(threadId: string, tabId: string): TerminalBinding | null {
|
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
|
-
function writeBinding(
|
|
97
|
+
function writeBinding(
|
|
98
|
+
threadId: string,
|
|
99
|
+
tabId: string,
|
|
100
|
+
terminalId: string,
|
|
101
|
+
serverEpoch?: string,
|
|
102
|
+
instanceId?: string,
|
|
103
|
+
): void {
|
|
96
104
|
try {
|
|
97
|
-
const payload: TerminalBinding = {
|
|
105
|
+
const payload: TerminalBinding = {
|
|
106
|
+
terminalId,
|
|
107
|
+
...(serverEpoch ? { serverEpoch } : {}),
|
|
108
|
+
...(instanceId ? { instanceId } : {}),
|
|
109
|
+
}
|
|
98
110
|
window.localStorage.setItem(bindingKey(threadId, tabId), JSON.stringify(payload))
|
|
99
111
|
} catch {
|
|
100
112
|
/* localStorage 不可用(隐私模式)→ 忽略,仅本次会话内有效 */
|
|
@@ -164,6 +176,15 @@ export function TerminalInstance({
|
|
|
164
176
|
const clientSeqRef = useRef(0)
|
|
165
177
|
const connectedRef = useRef(false)
|
|
166
178
|
const didInitBindingRef = useRef(false)
|
|
179
|
+
/**
|
|
180
|
+
* binding 记的服务端代际(方案 C,P5 任务 4 UI 收口):404 时与响应带的 serverEpoch
|
|
181
|
+
* 比对——变了=服务端换了实例(重启/重新部署),不变=该终端已退出或被 idle 回收。
|
|
182
|
+
* 跨 attach 保留(重连时不再读 binding,但代际仍有效);未知则维持静默重建。
|
|
183
|
+
*/
|
|
184
|
+
const boundEpochRef = useRef<string | undefined>(undefined)
|
|
185
|
+
// 绑定时的服务端实例(P5 任务 8):404 时与响应里的 instanceId 比对——不同 = 请求落到了
|
|
186
|
+
// 别的实例(sticky 未命中),静默重建即可;相同 = 真在本实例上失效,再按 epoch 分重启/回收。
|
|
187
|
+
const boundInstanceRef = useRef<string | undefined>(undefined)
|
|
167
188
|
const transportRef = useRef<TerminalTransport | null>(null)
|
|
168
189
|
/** 批处理缓冲(每笔记 typed 手势判定,flush 时合并)。 */
|
|
169
190
|
const writeBufRef = useRef<Array<{ data: string; typed: boolean }>>([])
|
|
@@ -357,16 +378,15 @@ export function TerminalInstance({
|
|
|
357
378
|
// binding/create)→ binding(仅首次)→ create(下方步骤 2)。binding 路径与
|
|
358
379
|
// create 路径保持原序不动;agent tab 不写 binding(create 路径专属,语义不变)。
|
|
359
380
|
// binding 存的 serverEpoch 记入 boundEpochRef,供 notFound 时比对区分重启/回收。
|
|
360
|
-
let boundEpochRef: string | undefined
|
|
361
381
|
if (initialTerminalIdRef.current) {
|
|
362
382
|
terminalIdRef.current = initialTerminalIdRef.current
|
|
363
383
|
} else if (!terminalIdRef.current && !didInitBindingRef.current) {
|
|
364
384
|
didInitBindingRef.current = true
|
|
365
385
|
const binding = readBinding(threadId, tabId)
|
|
366
386
|
terminalIdRef.current = binding?.terminalId ?? null
|
|
367
|
-
boundEpochRef = binding?.serverEpoch
|
|
368
|
-
|
|
369
|
-
// 死 id 守卫:notFound 重建每代只走一次,防服务端持续 404 时 create↔connect 死循环
|
|
387
|
+
boundEpochRef.current = binding?.serverEpoch
|
|
388
|
+
boundInstanceRef.current = binding?.instanceId
|
|
389
|
+
} // 死 id 守卫:notFound 重建每代只走一次,防服务端持续 404 时 create↔connect 死循环
|
|
370
390
|
let recreatedAfterNotFound = false
|
|
371
391
|
|
|
372
392
|
// 决定传输形态:WS 优先(desktop/harness client 且未失败),否则 SSE
|
|
@@ -417,7 +437,10 @@ export function TerminalInstance({
|
|
|
417
437
|
}
|
|
418
438
|
terminalIdRef.current = result.terminalId
|
|
419
439
|
setShellName(result.shell)
|
|
420
|
-
writeBinding(threadId, tabId, result.terminalId, result.serverEpoch)
|
|
440
|
+
writeBinding(threadId, tabId, result.terminalId, result.serverEpoch, result.instanceId)
|
|
441
|
+
// 新终端的代际与实例:后续 404 用它区分「换实例」「服务重启」与「本终端退出/回收」。
|
|
442
|
+
boundEpochRef.current = result.serverEpoch
|
|
443
|
+
boundInstanceRef.current = result.instanceId
|
|
421
444
|
}
|
|
422
445
|
if (cancelled) return
|
|
423
446
|
|
|
@@ -425,6 +448,26 @@ export function TerminalInstance({
|
|
|
425
448
|
const conn = await transport.connect(terminalIdRef.current)
|
|
426
449
|
if (cancelled) return
|
|
427
450
|
if (conn.notFound && !recreatedAfterNotFound) {
|
|
451
|
+
// 方案 C 的 UI 收口(P5 任务 4 / §6.5):404 是两类失效的同一签名,靠代际区分——
|
|
452
|
+
// serverEpoch 与 binding 记的不同 → 服务端换了实例(重启/重新部署);相同 → 该
|
|
453
|
+
// 终端已退出或被 2h idle 回收。代际未知(旧 binding / agent tab 全覆盖)时不提示,
|
|
454
|
+
// 维持既有静默重建兜底(不猜)。
|
|
455
|
+
const boundEpoch = boundEpochRef.current
|
|
456
|
+
const boundInstance = boundInstanceRef.current
|
|
457
|
+
// 三态分流:换实例(sticky 未命中)→ 不提示,静默重建;同实例 epoch 变 → 服务端
|
|
458
|
+
// 重启;同实例 epoch 未变 → 该终端已退出或被 idle 回收。实例未知(WS 回落前的旧
|
|
459
|
+
// binding / agent tab)时不猜,维持既有 epoch 比对。
|
|
460
|
+
const switchedInstance =
|
|
461
|
+
conn.instanceId !== undefined &&
|
|
462
|
+
boundInstance !== undefined &&
|
|
463
|
+
conn.instanceId !== boundInstance
|
|
464
|
+
if (!switchedInstance && conn.serverEpoch && boundEpoch) {
|
|
465
|
+
toast.info(
|
|
466
|
+
conn.serverEpoch === boundEpoch
|
|
467
|
+
? m.harness_panel_terminal_exitedRecycled()
|
|
468
|
+
: m.harness_panel_terminal_restarted(),
|
|
469
|
+
)
|
|
470
|
+
}
|
|
428
471
|
recreatedAfterNotFound = true
|
|
429
472
|
terminalIdRef.current = null
|
|
430
473
|
clearBinding(threadId, tabId)
|
|
@@ -62,9 +62,10 @@ export interface TerminalTransportCmd {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/** create 端点结果:成功返回 terminalId + shell + serverEpoch(方案 C 写入 binding 供重连
|
|
65
|
-
*
|
|
65
|
+
* 比对)+ instanceId(P5 任务 8:多实例下区分「换了实例」与「同实例终端没了」),
|
|
66
|
+
* 失败返回 error(null = 无服务端消息)+ 可选错误码(P6e-1 降级态判定用)。 */
|
|
66
67
|
export type TerminalCreateResult =
|
|
67
|
-
| { ok: true; terminalId: string; shell: string; serverEpoch?: string }
|
|
68
|
+
| { ok: true; terminalId: string; shell: string; serverEpoch?: string; instanceId?: string }
|
|
68
69
|
| { ok: false; error: string | null; errorCode?: string }
|
|
69
70
|
|
|
70
71
|
/** 传输层接口(P6d-1 SSE 实现 + P6d-2 WS 实现共用契约)。 */
|
|
@@ -77,7 +78,13 @@ export interface TerminalTransport {
|
|
|
77
78
|
* notFound=true 表示服务端已无此终端(dev/host 重启、idle 回收后 binding 存活死 id),
|
|
78
79
|
* 调用方应清 terminalId 并走 create 重建(DSH missingTerminal 语义),而非永久 404 循环。
|
|
79
80
|
* WS 实现同步 connect(非 101 走 onFallback),返回恒 ok。 */
|
|
80
|
-
connect(termId: string): Promise<{
|
|
81
|
+
connect(termId: string): Promise<{
|
|
82
|
+
ok: boolean
|
|
83
|
+
notFound?: boolean
|
|
84
|
+
serverEpoch?: string
|
|
85
|
+
/** 404 时服务端实例标识(P5 任务 8;WS 握手读不到 body,故可能缺省)。 */
|
|
86
|
+
instanceId?: string
|
|
87
|
+
}>
|
|
81
88
|
/** 注册下行帧回调(snapshot/output/state/slow/exit)。 */
|
|
82
89
|
onFrame(cb: (f: DownFrame) => void): void
|
|
83
90
|
/** 注册连接错误回调(EventSource onerror)。 */
|
|
@@ -126,8 +126,19 @@ export function createWsTransport(options: TerminalTransportOptions): TerminalTr
|
|
|
126
126
|
const errBody = (await res.json().catch(() => null)) as { message?: string } | null
|
|
127
127
|
return { ok: false, error: errBody?.message ?? null }
|
|
128
128
|
}
|
|
129
|
-
const data = (await res.json()) as {
|
|
130
|
-
|
|
129
|
+
const data = (await res.json()) as {
|
|
130
|
+
terminalId: string
|
|
131
|
+
shell: string
|
|
132
|
+
serverEpoch?: string
|
|
133
|
+
instanceId?: string
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
ok: true,
|
|
137
|
+
terminalId: data.terminalId,
|
|
138
|
+
shell: data.shell,
|
|
139
|
+
serverEpoch: data.serverEpoch,
|
|
140
|
+
instanceId: data.instanceId,
|
|
141
|
+
}
|
|
131
142
|
} catch {
|
|
132
143
|
return { ok: false, error: null }
|
|
133
144
|
}
|
|
@@ -193,6 +193,11 @@ function ConnectorsCardInner() {
|
|
|
193
193
|
{m.settings_harness_connectors_expiredBadge()}
|
|
194
194
|
</Badge>
|
|
195
195
|
) : null}
|
|
196
|
+
{row.hasCredential ? null : (
|
|
197
|
+
<Badge variant="outline" data-testid="connector-account-needs-auth">
|
|
198
|
+
{m.settings_harness_connectors_needsAuth()}
|
|
199
|
+
</Badge>
|
|
200
|
+
)}
|
|
196
201
|
<span className="text-xs text-muted-foreground">{formatExpiry(row)}</span>
|
|
197
202
|
<span className="ms-auto flex items-center gap-2">
|
|
198
203
|
<Button
|
|
@@ -248,11 +248,12 @@ function LinkPreview({ url }: { url: string }) {
|
|
|
248
248
|
}
|
|
249
249
|
return (
|
|
250
250
|
<div className="h-48 w-full overflow-hidden rounded-md border bg-background">
|
|
251
|
+
{/* linkpreview-001:去 allow-same-origin(同源+allow-scripts 组合=沙箱逃逸面) */}
|
|
251
252
|
<iframe
|
|
252
253
|
src={url}
|
|
253
254
|
className="size-full border-0"
|
|
254
255
|
title="链接预览"
|
|
255
|
-
sandbox="allow-scripts allow-
|
|
256
|
+
sandbox="allow-scripts allow-popups allow-forms"
|
|
256
257
|
/>
|
|
257
258
|
</div>
|
|
258
259
|
);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// 组件形态画廊的 dev-only 入口(本地专用,不入 git)。
|
|
2
|
+
//
|
|
3
|
+
// 为什么不放进 src/routes/:文件路由生成器会把它扫进 routeTree.gen.ts,导致生成物
|
|
4
|
+
// 永远脏、且新增页面时无法干净提交。
|
|
5
|
+
// 为什么不用主 router:主 router 若要挂一个未入库的模块,只能靠 import.meta.glob,
|
|
6
|
+
// 那会把本文件的内容打进生产主 chunk(实测 client 168K / server 300K)。
|
|
7
|
+
// 这里用独立的内联路由 + memory history:URL 是 /dev-gallery.html,路由内部仍是
|
|
8
|
+
// createRoute('/dev/gallery'),与主应用完全隔离。
|
|
9
|
+
|
|
10
|
+
import { StrictMode } from 'react'
|
|
11
|
+
import { createRoot } from 'react-dom/client'
|
|
12
|
+
import {
|
|
13
|
+
RouterProvider,
|
|
14
|
+
createMemoryHistory,
|
|
15
|
+
createRootRoute,
|
|
16
|
+
createRoute,
|
|
17
|
+
createRouter,
|
|
18
|
+
} from '@tanstack/react-router'
|
|
19
|
+
|
|
20
|
+
import '@/styles/globals.css'
|
|
21
|
+
import { GalleryPage } from './gallery'
|
|
22
|
+
|
|
23
|
+
const rootRoute = createRootRoute()
|
|
24
|
+
const galleryRoute = createRoute({
|
|
25
|
+
getParentRoute: () => rootRoute,
|
|
26
|
+
path: '/dev/gallery',
|
|
27
|
+
component: GalleryPage,
|
|
28
|
+
})
|
|
29
|
+
const router = createRouter({
|
|
30
|
+
routeTree: rootRoute.addChildren([galleryRoute]),
|
|
31
|
+
history: createMemoryHistory({ initialEntries: ['/dev/gallery'] }),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
createRoot(document.getElementById('root')!).render(
|
|
35
|
+
<StrictMode>
|
|
36
|
+
<RouterProvider router={router} />
|
|
37
|
+
</StrictMode>,
|
|
38
|
+
)
|