shennian 0.2.4 → 0.2.5
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/dist/bin/shennian.d.ts +0 -1
- package/dist/bin/shennian.js +0 -1
- package/dist/src/agents/adapter.d.ts +0 -1
- package/dist/src/agents/adapter.js +0 -1
- package/dist/src/agents/claude.d.ts +1 -1
- package/dist/src/agents/claude.js +12 -6
- package/dist/src/agents/codex.d.ts +0 -1
- package/dist/src/agents/codex.js +13 -4
- package/dist/src/agents/command-spec.d.ts +28 -3
- package/dist/src/agents/command-spec.js +251 -10
- package/dist/src/agents/cursor.d.ts +0 -1
- package/dist/src/agents/cursor.js +2 -4
- package/dist/src/agents/custom.d.ts +0 -6
- package/dist/src/agents/custom.js +4 -40
- package/dist/src/agents/detect.d.ts +0 -1
- package/dist/src/agents/detect.js +0 -1
- package/dist/src/agents/gemini.d.ts +0 -1
- package/dist/src/agents/gemini.js +7 -3
- package/dist/src/agents/model-registry/cache.d.ts +0 -1
- package/dist/src/agents/model-registry/cache.js +0 -1
- package/dist/src/agents/model-registry/discovery.d.ts +0 -1
- package/dist/src/agents/model-registry/discovery.js +13 -54
- package/dist/src/agents/model-registry/parsers.d.ts +3 -1
- package/dist/src/agents/model-registry/parsers.js +92 -2
- package/dist/src/agents/model-registry/runner.d.ts +2 -7
- package/dist/src/agents/model-registry/runner.js +3 -134
- package/dist/src/agents/model-registry/service.d.ts +0 -1
- package/dist/src/agents/model-registry/service.js +12 -10
- package/dist/src/agents/model-registry/types.d.ts +0 -1
- package/dist/src/agents/model-registry/types.js +0 -1
- package/dist/src/agents/model-registry.d.ts +2 -2
- package/dist/src/agents/model-registry.js +2 -2
- package/dist/src/agents/openclaw.d.ts +0 -1
- package/dist/src/agents/openclaw.js +13 -4
- package/dist/src/agents/pi.d.ts +0 -1
- package/dist/src/agents/pi.js +0 -1
- package/dist/src/commands/agent.d.ts +0 -1
- package/dist/src/commands/agent.js +2 -33
- package/dist/src/commands/daemon.d.ts +6 -1
- package/dist/src/commands/daemon.js +153 -18
- package/dist/src/commands/pair-qr.d.ts +0 -1
- package/dist/src/commands/pair-qr.js +0 -1
- package/dist/src/commands/pair.d.ts +0 -1
- package/dist/src/commands/pair.js +0 -1
- package/dist/src/commands/upgrade.d.ts +0 -1
- package/dist/src/commands/upgrade.js +0 -1
- package/dist/src/config/index.d.ts +0 -1
- package/dist/src/config/index.js +0 -1
- package/dist/src/fs/handler.d.ts +0 -1
- package/dist/src/fs/handler.js +0 -1
- package/dist/src/fs/security.d.ts +0 -1
- package/dist/src/fs/security.js +5 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +33 -7
- package/dist/src/log-reporter.d.ts +0 -1
- package/dist/src/log-reporter.js +2 -20
- package/dist/src/native-fusion/parsers.d.ts +0 -1
- package/dist/src/native-fusion/parsers.js +356 -40
- package/dist/src/native-fusion/service.d.ts +0 -1
- package/dist/src/native-fusion/service.js +14 -5
- package/dist/src/native-fusion/state.d.ts +0 -1
- package/dist/src/native-fusion/state.js +0 -1
- package/dist/src/native-fusion/types.d.ts +0 -1
- package/dist/src/native-fusion/types.js +0 -1
- package/dist/src/region.d.ts +0 -1
- package/dist/src/region.js +0 -1
- package/dist/src/relay/client.d.ts +11 -2
- package/dist/src/relay/client.js +22 -4
- package/dist/src/session/handlers/agents.d.ts +0 -1
- package/dist/src/session/handlers/agents.js +0 -1
- package/dist/src/session/handlers/chat.d.ts +0 -1
- package/dist/src/session/handlers/chat.js +0 -1
- package/dist/src/session/handlers/control.d.ts +0 -1
- package/dist/src/session/handlers/control.js +0 -1
- package/dist/src/session/handlers/fs.d.ts +0 -1
- package/dist/src/session/handlers/fs.js +5 -2
- package/dist/src/session/manager.d.ts +1 -1
- package/dist/src/session/manager.js +23 -4
- package/dist/src/session/store.d.ts +0 -1
- package/dist/src/session/store.js +0 -1
- package/dist/src/session/types.d.ts +0 -1
- package/dist/src/session/types.js +0 -1
- package/dist/src/upgrade/engine.d.ts +0 -1
- package/dist/src/upgrade/engine.js +0 -1
- package/package.json +3 -2
- package/dist/bin/shennian.d.ts.map +0 -1
- package/dist/bin/shennian.js.map +0 -1
- package/dist/src/__experiments__/probe-debug.d.ts +0 -2
- package/dist/src/__experiments__/probe-debug.d.ts.map +0 -1
- package/dist/src/__experiments__/probe-debug.js +0 -66
- package/dist/src/__experiments__/probe-debug.js.map +0 -1
- package/dist/src/__experiments__/probe-final-benchmark.d.ts +0 -3
- package/dist/src/__experiments__/probe-final-benchmark.d.ts.map +0 -1
- package/dist/src/__experiments__/probe-final-benchmark.js +0 -234
- package/dist/src/__experiments__/probe-final-benchmark.js.map +0 -1
- package/dist/src/__experiments__/probe-models-final.d.ts +0 -19
- package/dist/src/__experiments__/probe-models-final.d.ts.map +0 -1
- package/dist/src/__experiments__/probe-models-final.js +0 -250
- package/dist/src/__experiments__/probe-models-final.js.map +0 -1
- package/dist/src/__experiments__/probe-models.d.ts +0 -7
- package/dist/src/__experiments__/probe-models.d.ts.map +0 -1
- package/dist/src/__experiments__/probe-models.js +0 -251
- package/dist/src/__experiments__/probe-models.js.map +0 -1
- package/dist/src/__tests__/agents-e2e.d.ts +0 -21
- package/dist/src/__tests__/agents-e2e.d.ts.map +0 -1
- package/dist/src/__tests__/agents-e2e.js +0 -155
- package/dist/src/__tests__/agents-e2e.js.map +0 -1
- package/dist/src/__tests__/claude-adapter.test.d.ts +0 -2
- package/dist/src/__tests__/claude-adapter.test.d.ts.map +0 -1
- package/dist/src/__tests__/claude-adapter.test.js +0 -75
- package/dist/src/__tests__/claude-adapter.test.js.map +0 -1
- package/dist/src/__tests__/codex-adapter.test.d.ts +0 -2
- package/dist/src/__tests__/codex-adapter.test.d.ts.map +0 -1
- package/dist/src/__tests__/codex-adapter.test.js +0 -281
- package/dist/src/__tests__/codex-adapter.test.js.map +0 -1
- package/dist/src/__tests__/config.test.d.ts +0 -2
- package/dist/src/__tests__/config.test.d.ts.map +0 -1
- package/dist/src/__tests__/config.test.js +0 -60
- package/dist/src/__tests__/config.test.js.map +0 -1
- package/dist/src/__tests__/cursor-adapter.test.d.ts +0 -2
- package/dist/src/__tests__/cursor-adapter.test.d.ts.map +0 -1
- package/dist/src/__tests__/cursor-adapter.test.js +0 -69
- package/dist/src/__tests__/cursor-adapter.test.js.map +0 -1
- package/dist/src/__tests__/custom-agent-flow.test.d.ts +0 -2
- package/dist/src/__tests__/custom-agent-flow.test.d.ts.map +0 -1
- package/dist/src/__tests__/custom-agent-flow.test.js +0 -244
- package/dist/src/__tests__/custom-agent-flow.test.js.map +0 -1
- package/dist/src/__tests__/daemon-autostart.test.d.ts +0 -2
- package/dist/src/__tests__/daemon-autostart.test.d.ts.map +0 -1
- package/dist/src/__tests__/daemon-autostart.test.js +0 -60
- package/dist/src/__tests__/daemon-autostart.test.js.map +0 -1
- package/dist/src/__tests__/e2e-relay.d.ts +0 -19
- package/dist/src/__tests__/e2e-relay.d.ts.map +0 -1
- package/dist/src/__tests__/e2e-relay.js +0 -400
- package/dist/src/__tests__/e2e-relay.js.map +0 -1
- package/dist/src/__tests__/fs-handler.test.d.ts +0 -2
- package/dist/src/__tests__/fs-handler.test.d.ts.map +0 -1
- package/dist/src/__tests__/fs-handler.test.js +0 -19
- package/dist/src/__tests__/fs-handler.test.js.map +0 -1
- package/dist/src/__tests__/model-discovery.test.d.ts +0 -2
- package/dist/src/__tests__/model-discovery.test.d.ts.map +0 -1
- package/dist/src/__tests__/model-discovery.test.js +0 -47
- package/dist/src/__tests__/model-discovery.test.js.map +0 -1
- package/dist/src/__tests__/model-switching.test.d.ts +0 -2
- package/dist/src/__tests__/model-switching.test.d.ts.map +0 -1
- package/dist/src/__tests__/model-switching.test.js +0 -292
- package/dist/src/__tests__/model-switching.test.js.map +0 -1
- package/dist/src/__tests__/native-fusion-parsers.test.d.ts +0 -2
- package/dist/src/__tests__/native-fusion-parsers.test.d.ts.map +0 -1
- package/dist/src/__tests__/native-fusion-parsers.test.js +0 -253
- package/dist/src/__tests__/native-fusion-parsers.test.js.map +0 -1
- package/dist/src/__tests__/native-fusion-service.test.d.ts +0 -2
- package/dist/src/__tests__/native-fusion-service.test.d.ts.map +0 -1
- package/dist/src/__tests__/native-fusion-service.test.js +0 -157
- package/dist/src/__tests__/native-fusion-service.test.js.map +0 -1
- package/dist/src/__tests__/native-session-sync.test.d.ts +0 -2
- package/dist/src/__tests__/native-session-sync.test.d.ts.map +0 -1
- package/dist/src/__tests__/native-session-sync.test.js +0 -198
- package/dist/src/__tests__/native-session-sync.test.js.map +0 -1
- package/dist/src/__tests__/pair-qr.test.d.ts +0 -2
- package/dist/src/__tests__/pair-qr.test.d.ts.map +0 -1
- package/dist/src/__tests__/pair-qr.test.js +0 -13
- package/dist/src/__tests__/pair-qr.test.js.map +0 -1
- package/dist/src/__tests__/pi-context.test.d.ts +0 -2
- package/dist/src/__tests__/pi-context.test.d.ts.map +0 -1
- package/dist/src/__tests__/pi-context.test.js +0 -261
- package/dist/src/__tests__/pi-context.test.js.map +0 -1
- package/dist/src/__tests__/session-manager.test.d.ts +0 -2
- package/dist/src/__tests__/session-manager.test.d.ts.map +0 -1
- package/dist/src/__tests__/session-manager.test.js +0 -685
- package/dist/src/__tests__/session-manager.test.js.map +0 -1
- package/dist/src/__tests__/session-store.test.d.ts +0 -2
- package/dist/src/__tests__/session-store.test.d.ts.map +0 -1
- package/dist/src/__tests__/session-store.test.js +0 -106
- package/dist/src/__tests__/session-store.test.js.map +0 -1
- package/dist/src/agents/adapter.d.ts.map +0 -1
- package/dist/src/agents/adapter.js.map +0 -1
- package/dist/src/agents/claude.d.ts.map +0 -1
- package/dist/src/agents/claude.js.map +0 -1
- package/dist/src/agents/codex.d.ts.map +0 -1
- package/dist/src/agents/codex.js.map +0 -1
- package/dist/src/agents/command-spec.d.ts.map +0 -1
- package/dist/src/agents/command-spec.js.map +0 -1
- package/dist/src/agents/cursor.d.ts.map +0 -1
- package/dist/src/agents/cursor.js.map +0 -1
- package/dist/src/agents/custom.d.ts.map +0 -1
- package/dist/src/agents/custom.js.map +0 -1
- package/dist/src/agents/detect.d.ts.map +0 -1
- package/dist/src/agents/detect.js.map +0 -1
- package/dist/src/agents/gemini.d.ts.map +0 -1
- package/dist/src/agents/gemini.js.map +0 -1
- package/dist/src/agents/model-registry/cache.d.ts.map +0 -1
- package/dist/src/agents/model-registry/cache.js.map +0 -1
- package/dist/src/agents/model-registry/discovery.d.ts.map +0 -1
- package/dist/src/agents/model-registry/discovery.js.map +0 -1
- package/dist/src/agents/model-registry/parsers.d.ts.map +0 -1
- package/dist/src/agents/model-registry/parsers.js.map +0 -1
- package/dist/src/agents/model-registry/runner.d.ts.map +0 -1
- package/dist/src/agents/model-registry/runner.js.map +0 -1
- package/dist/src/agents/model-registry/service.d.ts.map +0 -1
- package/dist/src/agents/model-registry/service.js.map +0 -1
- package/dist/src/agents/model-registry/types.d.ts.map +0 -1
- package/dist/src/agents/model-registry/types.js.map +0 -1
- package/dist/src/agents/model-registry.d.ts.map +0 -1
- package/dist/src/agents/model-registry.js.map +0 -1
- package/dist/src/agents/openclaw.d.ts.map +0 -1
- package/dist/src/agents/openclaw.js.map +0 -1
- package/dist/src/agents/pi.d.ts.map +0 -1
- package/dist/src/agents/pi.js.map +0 -1
- package/dist/src/commands/agent.d.ts.map +0 -1
- package/dist/src/commands/agent.js.map +0 -1
- package/dist/src/commands/daemon.d.ts.map +0 -1
- package/dist/src/commands/daemon.js.map +0 -1
- package/dist/src/commands/pair-qr.d.ts.map +0 -1
- package/dist/src/commands/pair-qr.js.map +0 -1
- package/dist/src/commands/pair.d.ts.map +0 -1
- package/dist/src/commands/pair.js.map +0 -1
- package/dist/src/commands/upgrade.d.ts.map +0 -1
- package/dist/src/commands/upgrade.js.map +0 -1
- package/dist/src/config/index.d.ts.map +0 -1
- package/dist/src/config/index.js.map +0 -1
- package/dist/src/fs/handler.d.ts.map +0 -1
- package/dist/src/fs/handler.js.map +0 -1
- package/dist/src/fs/multimodal.d.ts +0 -5
- package/dist/src/fs/multimodal.d.ts.map +0 -1
- package/dist/src/fs/multimodal.js +0 -39
- package/dist/src/fs/multimodal.js.map +0 -1
- package/dist/src/fs/security.d.ts.map +0 -1
- package/dist/src/fs/security.js.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/log-reporter.d.ts.map +0 -1
- package/dist/src/log-reporter.js.map +0 -1
- package/dist/src/native-fusion/parsers.d.ts.map +0 -1
- package/dist/src/native-fusion/parsers.js.map +0 -1
- package/dist/src/native-fusion/service.d.ts.map +0 -1
- package/dist/src/native-fusion/service.js.map +0 -1
- package/dist/src/native-fusion/state.d.ts.map +0 -1
- package/dist/src/native-fusion/state.js.map +0 -1
- package/dist/src/native-fusion/types.d.ts.map +0 -1
- package/dist/src/native-fusion/types.js.map +0 -1
- package/dist/src/native-sync/discover.d.ts +0 -6
- package/dist/src/native-sync/discover.d.ts.map +0 -1
- package/dist/src/native-sync/discover.js +0 -69
- package/dist/src/native-sync/discover.js.map +0 -1
- package/dist/src/native-sync/parsers.d.ts +0 -3
- package/dist/src/native-sync/parsers.d.ts.map +0 -1
- package/dist/src/native-sync/parsers.js +0 -373
- package/dist/src/native-sync/parsers.js.map +0 -1
- package/dist/src/native-sync/service.d.ts +0 -16
- package/dist/src/native-sync/service.d.ts.map +0 -1
- package/dist/src/native-sync/service.js +0 -95
- package/dist/src/native-sync/service.js.map +0 -1
- package/dist/src/native-sync/state.d.ts +0 -6
- package/dist/src/native-sync/state.d.ts.map +0 -1
- package/dist/src/native-sync/state.js +0 -34
- package/dist/src/native-sync/state.js.map +0 -1
- package/dist/src/native-sync/types.d.ts +0 -23
- package/dist/src/native-sync/types.d.ts.map +0 -1
- package/dist/src/native-sync/types.js +0 -4
- package/dist/src/native-sync/types.js.map +0 -1
- package/dist/src/region.d.ts.map +0 -1
- package/dist/src/region.js.map +0 -1
- package/dist/src/relay/client.d.ts.map +0 -1
- package/dist/src/relay/client.js.map +0 -1
- package/dist/src/session/handlers/agents.d.ts.map +0 -1
- package/dist/src/session/handlers/agents.js.map +0 -1
- package/dist/src/session/handlers/chat.d.ts.map +0 -1
- package/dist/src/session/handlers/chat.js.map +0 -1
- package/dist/src/session/handlers/control.d.ts.map +0 -1
- package/dist/src/session/handlers/control.js.map +0 -1
- package/dist/src/session/handlers/fs.d.ts.map +0 -1
- package/dist/src/session/handlers/fs.js.map +0 -1
- package/dist/src/session/handlers/queue.d.ts +0 -4
- package/dist/src/session/handlers/queue.d.ts.map +0 -1
- package/dist/src/session/handlers/queue.js +0 -66
- package/dist/src/session/handlers/queue.js.map +0 -1
- package/dist/src/session/manager.d.ts.map +0 -1
- package/dist/src/session/manager.js.map +0 -1
- package/dist/src/session/store.d.ts.map +0 -1
- package/dist/src/session/store.js.map +0 -1
- package/dist/src/session/types.d.ts.map +0 -1
- package/dist/src/session/types.js.map +0 -1
- package/dist/src/upgrade/engine.d.ts.map +0 -1
- package/dist/src/upgrade/engine.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import os from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
import { buildUserMessagePayload } from '@shennian/wire';
|
|
7
8
|
function normalizeText(text) {
|
|
8
9
|
return stripGitDirectiveArtifacts(text.replace(/\r\n/g, '\n').trim());
|
|
9
10
|
}
|
|
@@ -46,6 +47,346 @@ function makeEventKey(filePath, offset, kind) {
|
|
|
46
47
|
const fingerprint = createHash('sha1').update(filePath).digest('hex').slice(0, 16);
|
|
47
48
|
return `${fingerprint}:${offset}:${kind}`;
|
|
48
49
|
}
|
|
50
|
+
function safeStringify(value) {
|
|
51
|
+
if (value == null)
|
|
52
|
+
return '';
|
|
53
|
+
if (typeof value === 'string')
|
|
54
|
+
return value;
|
|
55
|
+
try {
|
|
56
|
+
return JSON.stringify(value);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return String(value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function normalizeToolText(text) {
|
|
63
|
+
return text.replace(/\r\n/g, '\n').trim();
|
|
64
|
+
}
|
|
65
|
+
function parseStructuredString(value) {
|
|
66
|
+
if (typeof value !== 'string')
|
|
67
|
+
return value;
|
|
68
|
+
const trimmed = value.trim();
|
|
69
|
+
if (!trimmed)
|
|
70
|
+
return '';
|
|
71
|
+
try {
|
|
72
|
+
return JSON.parse(trimmed);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function summarizeToolResult(value) {
|
|
79
|
+
if (value == null)
|
|
80
|
+
return '';
|
|
81
|
+
if (typeof value === 'string')
|
|
82
|
+
return normalizeToolText(value);
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
const textParts = value
|
|
85
|
+
.map((item) => extractTextContent(item))
|
|
86
|
+
.filter(Boolean);
|
|
87
|
+
if (textParts.length > 0)
|
|
88
|
+
return normalizeToolText(textParts.join('\n\n'));
|
|
89
|
+
}
|
|
90
|
+
if (typeof value === 'object') {
|
|
91
|
+
const text = extractTextContent(value);
|
|
92
|
+
if (text)
|
|
93
|
+
return normalizeToolText(text);
|
|
94
|
+
}
|
|
95
|
+
return normalizeToolText(safeStringify(value));
|
|
96
|
+
}
|
|
97
|
+
function extractTextContent(value) {
|
|
98
|
+
if (value == null)
|
|
99
|
+
return '';
|
|
100
|
+
if (typeof value === 'string')
|
|
101
|
+
return value;
|
|
102
|
+
if (Array.isArray(value)) {
|
|
103
|
+
return value
|
|
104
|
+
.map((item) => extractTextContent(item))
|
|
105
|
+
.filter(Boolean)
|
|
106
|
+
.join('\n\n');
|
|
107
|
+
}
|
|
108
|
+
if (typeof value !== 'object')
|
|
109
|
+
return '';
|
|
110
|
+
const record = value;
|
|
111
|
+
if (typeof record.text === 'string')
|
|
112
|
+
return record.text;
|
|
113
|
+
if (typeof record.output === 'string')
|
|
114
|
+
return record.output;
|
|
115
|
+
if (typeof record.message === 'string')
|
|
116
|
+
return record.message;
|
|
117
|
+
if ('Ok' in record)
|
|
118
|
+
return extractTextContent(record.Ok);
|
|
119
|
+
if ('Err' in record)
|
|
120
|
+
return extractTextContent(record.Err);
|
|
121
|
+
if ('content' in record)
|
|
122
|
+
return extractTextContent(record.content);
|
|
123
|
+
if ('contentItems' in record)
|
|
124
|
+
return extractTextContent(record.contentItems);
|
|
125
|
+
if ('result' in record)
|
|
126
|
+
return extractTextContent(record.result);
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
129
|
+
function buildToolPayload(name, args, result) {
|
|
130
|
+
const payload = {
|
|
131
|
+
v: 1,
|
|
132
|
+
type: 'tool',
|
|
133
|
+
name,
|
|
134
|
+
};
|
|
135
|
+
if (args !== undefined)
|
|
136
|
+
payload.args = args;
|
|
137
|
+
if (result !== undefined)
|
|
138
|
+
payload.result = summarizeToolResult(result);
|
|
139
|
+
return JSON.stringify(payload);
|
|
140
|
+
}
|
|
141
|
+
function escapeMarkdownLabel(label) {
|
|
142
|
+
return label.replace(/[[\]\\]/g, '\\$&');
|
|
143
|
+
}
|
|
144
|
+
function buildMarkdownImageRef(filePath, label = 'Generated image') {
|
|
145
|
+
return ``;
|
|
146
|
+
}
|
|
147
|
+
function buildImagePayload(filePath) {
|
|
148
|
+
const name = path.basename(filePath) || 'generated-image.png';
|
|
149
|
+
return JSON.stringify({
|
|
150
|
+
v: 1,
|
|
151
|
+
type: 'image',
|
|
152
|
+
content: buildMarkdownImageRef(filePath, name),
|
|
153
|
+
attachments: [
|
|
154
|
+
{
|
|
155
|
+
path: filePath,
|
|
156
|
+
name,
|
|
157
|
+
mimeType: 'image/png',
|
|
158
|
+
kind: 'image',
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function inferMimeType(filePath) {
|
|
164
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
165
|
+
if (ext === '.png')
|
|
166
|
+
return 'image/png';
|
|
167
|
+
if (ext === '.jpg' || ext === '.jpeg')
|
|
168
|
+
return 'image/jpeg';
|
|
169
|
+
if (ext === '.webp')
|
|
170
|
+
return 'image/webp';
|
|
171
|
+
if (ext === '.gif')
|
|
172
|
+
return 'image/gif';
|
|
173
|
+
return 'application/octet-stream';
|
|
174
|
+
}
|
|
175
|
+
function parseCodexLocalImageAttachment(value) {
|
|
176
|
+
if (typeof value === 'string') {
|
|
177
|
+
const imagePath = value.trim();
|
|
178
|
+
if (!imagePath)
|
|
179
|
+
return null;
|
|
180
|
+
return {
|
|
181
|
+
path: imagePath,
|
|
182
|
+
name: path.basename(imagePath) || 'image.png',
|
|
183
|
+
mimeType: inferMimeType(imagePath),
|
|
184
|
+
kind: 'image',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
if (typeof value !== 'object' || value === null)
|
|
188
|
+
return null;
|
|
189
|
+
const entry = value;
|
|
190
|
+
const imagePath = typeof entry.path === 'string' ? entry.path
|
|
191
|
+
: typeof entry.file_path === 'string' ? entry.file_path
|
|
192
|
+
: typeof entry.saved_path === 'string' ? entry.saved_path
|
|
193
|
+
: '';
|
|
194
|
+
if (!imagePath.trim())
|
|
195
|
+
return null;
|
|
196
|
+
const name = typeof entry.name === 'string' && entry.name.trim()
|
|
197
|
+
? entry.name
|
|
198
|
+
: path.basename(imagePath) || 'image.png';
|
|
199
|
+
const mimeType = typeof entry.mimeType === 'string' && entry.mimeType.trim()
|
|
200
|
+
? entry.mimeType
|
|
201
|
+
: inferMimeType(imagePath);
|
|
202
|
+
return {
|
|
203
|
+
path: imagePath,
|
|
204
|
+
name,
|
|
205
|
+
mimeType,
|
|
206
|
+
kind: 'image',
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function parseCodexTextElements(value) {
|
|
210
|
+
if (!Array.isArray(value))
|
|
211
|
+
return '';
|
|
212
|
+
const parts = value
|
|
213
|
+
.map((item) => {
|
|
214
|
+
if (typeof item === 'string')
|
|
215
|
+
return item;
|
|
216
|
+
if (typeof item === 'object' && item !== null) {
|
|
217
|
+
const record = item;
|
|
218
|
+
return typeof record.text === 'string' ? record.text : '';
|
|
219
|
+
}
|
|
220
|
+
return '';
|
|
221
|
+
})
|
|
222
|
+
.map((text) => normalizeText(text))
|
|
223
|
+
.filter(Boolean);
|
|
224
|
+
return parts.join('\n\n');
|
|
225
|
+
}
|
|
226
|
+
function stripCodexUserMessageWrapper(text) {
|
|
227
|
+
const normalized = normalizeText(text);
|
|
228
|
+
if (!normalized)
|
|
229
|
+
return '';
|
|
230
|
+
const requestMatch = normalized.match(/My request for Codex:\s*([\s\S]*)$/i);
|
|
231
|
+
if (requestMatch && requestMatch[1])
|
|
232
|
+
return normalizeText(requestMatch[1]);
|
|
233
|
+
return normalized;
|
|
234
|
+
}
|
|
235
|
+
function parseCodexUserMessage(payload) {
|
|
236
|
+
const textFromElements = parseCodexTextElements(payload.text_elements);
|
|
237
|
+
const textFromInput = Array.isArray(payload.input)
|
|
238
|
+
? parseCodexTextElements(payload.input)
|
|
239
|
+
: '';
|
|
240
|
+
const textFromMessage = typeof payload.message === 'string'
|
|
241
|
+
? stripCodexUserMessageWrapper(payload.message)
|
|
242
|
+
: '';
|
|
243
|
+
const text = textFromElements || textFromInput || textFromMessage;
|
|
244
|
+
const attachments = Array.isArray(payload.local_images)
|
|
245
|
+
? payload.local_images
|
|
246
|
+
.map(parseCodexLocalImageAttachment)
|
|
247
|
+
.filter((item) => item != null)
|
|
248
|
+
: [];
|
|
249
|
+
if (!text && attachments.length === 0)
|
|
250
|
+
return null;
|
|
251
|
+
if (attachments.length > 0) {
|
|
252
|
+
return {
|
|
253
|
+
payload: buildUserMessagePayload(text, attachments),
|
|
254
|
+
titleText: text,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return { payload: text, titleText: text };
|
|
258
|
+
}
|
|
259
|
+
function pushCodexEvent(events, filePath, lineOffset, kind, sourceSessionKey, ts, payload, title, modelId, workDir, role = 'agent') {
|
|
260
|
+
if (!payload)
|
|
261
|
+
return;
|
|
262
|
+
events.push({
|
|
263
|
+
agentType: 'codex',
|
|
264
|
+
sourceMode: 'codex_rollout_import',
|
|
265
|
+
sourceSessionKey,
|
|
266
|
+
sourceEventKey: makeEventKey(filePath, lineOffset, kind),
|
|
267
|
+
cursor: makeCursor(filePath, lineOffset),
|
|
268
|
+
role,
|
|
269
|
+
ts,
|
|
270
|
+
payload,
|
|
271
|
+
title,
|
|
272
|
+
modelId,
|
|
273
|
+
workDir,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function pushCodexToolEvent(events, filePath, lineOffset, kind, sourceSessionKey, ts, toolName, title, modelId, workDir, args, result) {
|
|
277
|
+
pushCodexEvent(events, filePath, lineOffset, kind, sourceSessionKey, ts, buildToolPayload(toolName, args, result), title, modelId, workDir);
|
|
278
|
+
}
|
|
279
|
+
function parseCodexResponseItem(events, filePath, lineOffset, payload, sourceSessionKey, ts, title, modelId, workDir) {
|
|
280
|
+
const itemType = typeof payload.type === 'string' ? payload.type : '';
|
|
281
|
+
if (!itemType)
|
|
282
|
+
return;
|
|
283
|
+
if (itemType === 'function_call') {
|
|
284
|
+
const name = typeof payload.name === 'string' ? payload.name : 'function_call';
|
|
285
|
+
pushCodexToolEvent(events, filePath, lineOffset, itemType, sourceSessionKey, ts, name, title, modelId, workDir, parseStructuredString(payload.arguments));
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (itemType === 'function_call_output') {
|
|
289
|
+
pushCodexToolEvent(events, filePath, lineOffset, itemType, sourceSessionKey, ts, 'function_call_output', title, modelId, workDir, payload.call_id, payload.output);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (itemType === 'custom_tool_call') {
|
|
293
|
+
const name = typeof payload.name === 'string' ? payload.name : 'custom_tool_call';
|
|
294
|
+
const args = payload.input !== undefined ? { input: payload.input } : undefined;
|
|
295
|
+
pushCodexToolEvent(events, filePath, lineOffset, itemType, sourceSessionKey, ts, name, title, modelId, workDir, args);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (itemType === 'custom_tool_call_output') {
|
|
299
|
+
const name = typeof payload.name === 'string' ? payload.name : 'custom_tool_call_output';
|
|
300
|
+
const result = payload.output ?? payload.result ?? payload.content;
|
|
301
|
+
pushCodexToolEvent(events, filePath, lineOffset, itemType, sourceSessionKey, ts, name, title, modelId, workDir, payload.call_id, result);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (itemType === 'web_search_call') {
|
|
305
|
+
const action = typeof payload.action === 'object' && payload.action !== null
|
|
306
|
+
? payload.action
|
|
307
|
+
: null;
|
|
308
|
+
pushCodexToolEvent(events, filePath, lineOffset, itemType, sourceSessionKey, ts, 'web_search', title, modelId, workDir, action ?? payload.query);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function parseCodexEventMessage(events, filePath, lineOffset, payload, sourceSessionKey, ts, title, modelId, workDir) {
|
|
313
|
+
const eventType = typeof payload.type === 'string' ? payload.type : '';
|
|
314
|
+
if (!eventType)
|
|
315
|
+
return;
|
|
316
|
+
if (eventType === 'user_message') {
|
|
317
|
+
const parsedUser = parseCodexUserMessage(payload);
|
|
318
|
+
if (!parsedUser)
|
|
319
|
+
return;
|
|
320
|
+
pushCodexEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, parsedUser.payload, title, modelId, workDir, 'user');
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (eventType === 'agent_message') {
|
|
324
|
+
const text = typeof payload.message === 'string' ? normalizeText(payload.message) : '';
|
|
325
|
+
if (!text)
|
|
326
|
+
return;
|
|
327
|
+
pushCodexEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, text, title, modelId, workDir);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (eventType === 'exec_command_end') {
|
|
331
|
+
const command = Array.isArray(payload.command) ? payload.command : payload.parsed_cmd ?? payload.command;
|
|
332
|
+
const exitCode = payload.exit_code ?? payload.exitCode;
|
|
333
|
+
const output = [
|
|
334
|
+
typeof payload.aggregated_output === 'string' ? payload.aggregated_output : '',
|
|
335
|
+
exitCode != null ? `\n(exit ${String(exitCode)})` : '',
|
|
336
|
+
].join('');
|
|
337
|
+
pushCodexToolEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, 'command_execution', title, modelId, workDir, { command }, output);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (eventType === 'patch_apply_end') {
|
|
341
|
+
pushCodexToolEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, 'apply_patch', title, modelId, workDir, payload.changes, {
|
|
342
|
+
success: payload.success,
|
|
343
|
+
stdout: payload.stdout,
|
|
344
|
+
stderr: payload.stderr,
|
|
345
|
+
});
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (eventType === 'mcp_tool_call_end') {
|
|
349
|
+
const invocation = typeof payload.invocation === 'object' && payload.invocation !== null
|
|
350
|
+
? payload.invocation
|
|
351
|
+
: null;
|
|
352
|
+
const tool = typeof invocation?.tool === 'string' ? invocation.tool : 'mcp_tool_call';
|
|
353
|
+
const args = {
|
|
354
|
+
server: invocation?.server,
|
|
355
|
+
...(typeof invocation?.arguments === 'object' && invocation.arguments !== null
|
|
356
|
+
? invocation.arguments
|
|
357
|
+
: {}),
|
|
358
|
+
};
|
|
359
|
+
pushCodexToolEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, tool, title, modelId, workDir, args, payload.result);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (eventType === 'dynamic_tool_call_request') {
|
|
363
|
+
const tool = typeof payload.tool === 'string' ? payload.tool : 'dynamic_tool_call';
|
|
364
|
+
pushCodexToolEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, tool, title, modelId, workDir, payload.arguments);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (eventType === 'dynamic_tool_call_response') {
|
|
368
|
+
const tool = typeof payload.tool === 'string' ? payload.tool : 'dynamic_tool_call';
|
|
369
|
+
pushCodexToolEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, tool, title, modelId, workDir, payload.callId ?? payload.call_id, payload.result ?? payload.output);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (eventType === 'web_search_end') {
|
|
373
|
+
const action = typeof payload.action === 'object' && payload.action !== null
|
|
374
|
+
? payload.action
|
|
375
|
+
: null;
|
|
376
|
+
pushCodexToolEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, 'web_search', title, modelId, workDir, action ?? payload.query, payload.query);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (eventType === 'image_generation_end') {
|
|
380
|
+
const savedPath = typeof payload.saved_path === 'string' ? payload.saved_path.trim() : '';
|
|
381
|
+
if (!savedPath)
|
|
382
|
+
return;
|
|
383
|
+
pushCodexEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, buildImagePayload(savedPath), title, modelId, workDir);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (eventType === 'view_image_tool_call') {
|
|
387
|
+
pushCodexToolEvent(events, filePath, lineOffset, eventType, sourceSessionKey, ts, 'view_image', title, modelId, workDir, payload.path ?? payload.image_path ?? payload);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
49
390
|
function relativeProjectDir(cwd) {
|
|
50
391
|
const home = os.homedir();
|
|
51
392
|
if (cwd.startsWith(home))
|
|
@@ -143,7 +484,9 @@ function lookupCodexThreadName(sourceSessionKey) {
|
|
|
143
484
|
if (!fs.existsSync(indexPath))
|
|
144
485
|
return null;
|
|
145
486
|
const content = fs.readFileSync(indexPath, 'utf8');
|
|
146
|
-
|
|
487
|
+
const lines = content.split('\n');
|
|
488
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
489
|
+
const line = lines[index];
|
|
147
490
|
if (!line.trim())
|
|
148
491
|
continue;
|
|
149
492
|
const parsed = safeParse(line);
|
|
@@ -244,46 +587,20 @@ export function parseCodexRolloutChunk(filePath, startOffset) {
|
|
|
244
587
|
title = lookupCodexThreadName(sourceSessionKey) ?? '';
|
|
245
588
|
continue;
|
|
246
589
|
}
|
|
247
|
-
if (
|
|
590
|
+
if (!sourceSessionKey)
|
|
591
|
+
continue;
|
|
592
|
+
if (type === 'response_item') {
|
|
593
|
+
parseCodexResponseItem(events, filePath, lineOffset, payload, sourceSessionKey, ts, title, modelId, workDir);
|
|
248
594
|
continue;
|
|
249
|
-
const eventType = typeof payload.type === 'string' ? payload.type : '';
|
|
250
|
-
if (eventType === 'user_message') {
|
|
251
|
-
const text = typeof payload.message === 'string' ? normalizeText(payload.message) : '';
|
|
252
|
-
if (!text)
|
|
253
|
-
continue;
|
|
254
|
-
if (!title)
|
|
255
|
-
title = text.slice(0, 80);
|
|
256
|
-
events.push({
|
|
257
|
-
agentType: 'codex',
|
|
258
|
-
sourceMode: 'codex_rollout_import',
|
|
259
|
-
sourceSessionKey,
|
|
260
|
-
sourceEventKey: makeEventKey(filePath, lineOffset, 'user_message'),
|
|
261
|
-
cursor: makeCursor(filePath, lineOffset),
|
|
262
|
-
role: 'user',
|
|
263
|
-
ts,
|
|
264
|
-
payload: text,
|
|
265
|
-
title,
|
|
266
|
-
modelId,
|
|
267
|
-
workDir,
|
|
268
|
-
});
|
|
269
595
|
}
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
sourceEventKey: makeEventKey(filePath, lineOffset, 'agent_message'),
|
|
279
|
-
cursor: makeCursor(filePath, lineOffset),
|
|
280
|
-
role: 'agent',
|
|
281
|
-
ts,
|
|
282
|
-
payload: text,
|
|
283
|
-
title,
|
|
284
|
-
modelId,
|
|
285
|
-
workDir,
|
|
286
|
-
});
|
|
596
|
+
if (type === 'event_msg') {
|
|
597
|
+
const eventType = typeof payload.type === 'string' ? payload.type : '';
|
|
598
|
+
if (eventType === 'user_message') {
|
|
599
|
+
const parsedUser = parseCodexUserMessage(payload);
|
|
600
|
+
if (parsedUser?.titleText && !title)
|
|
601
|
+
title = parsedUser.titleText.slice(0, 80);
|
|
602
|
+
}
|
|
603
|
+
parseCodexEventMessage(events, filePath, lineOffset, payload, sourceSessionKey, ts, title, modelId, workDir);
|
|
287
604
|
}
|
|
288
605
|
}
|
|
289
606
|
return { nextOffset, events };
|
|
@@ -368,4 +685,3 @@ export function parseClaudeTranscriptChunk(filePath, startOffset) {
|
|
|
368
685
|
}
|
|
369
686
|
return { nextOffset, events };
|
|
370
687
|
}
|
|
371
|
-
//# sourceMappingURL=parsers.js.map
|
|
@@ -5,8 +5,8 @@ import fs from 'node:fs';
|
|
|
5
5
|
import { listClaudeTranscriptFiles, listCodexRolloutFiles, parseClaudeTranscriptChunk, parseCodexRolloutChunk, } from './parsers.js';
|
|
6
6
|
import { loadNativeScannerState, saveNativeScannerState } from './state.js';
|
|
7
7
|
const SCAN_INTERVAL_MS = 60_000;
|
|
8
|
-
const CLAIM_TTL_MS =
|
|
9
|
-
const
|
|
8
|
+
const CLAIM_TTL_MS = SCAN_INTERVAL_MS * 2;
|
|
9
|
+
const MANAGED_RUN_SUPPRESSION_TTL_MS = 30 * 60_000;
|
|
10
10
|
const MAX_BATCH_SIZE = 20;
|
|
11
11
|
function normalizeText(text) {
|
|
12
12
|
return text.replace(/\r\n/g, '\n').trim();
|
|
@@ -146,7 +146,7 @@ export class NativeSessionFusionService {
|
|
|
146
146
|
agentType: event.agentType,
|
|
147
147
|
sourceSessionKey: event.sourceSessionKey,
|
|
148
148
|
startedAt: event.ts,
|
|
149
|
-
endsAt: Math.max(now, event.ts) +
|
|
149
|
+
endsAt: Math.max(now, event.ts) + MANAGED_RUN_SUPPRESSION_TTL_MS,
|
|
150
150
|
});
|
|
151
151
|
return {
|
|
152
152
|
...event,
|
|
@@ -161,7 +161,16 @@ export class NativeSessionFusionService {
|
|
|
161
161
|
const window = this.suppressionWindows.get(key);
|
|
162
162
|
if (!window)
|
|
163
163
|
return false;
|
|
164
|
-
|
|
164
|
+
if (event.ts < window.startedAt)
|
|
165
|
+
return false;
|
|
166
|
+
if (event.ts > window.endsAt) {
|
|
167
|
+
this.suppressionWindows.delete(key);
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (event.role === 'user') {
|
|
171
|
+
this.suppressionWindows.delete(key);
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
165
175
|
}
|
|
166
176
|
}
|
|
167
|
-
//# sourceMappingURL=service.js.map
|
package/dist/src/region.d.ts
CHANGED
|
@@ -13,4 +13,3 @@ export declare const SERVERS: Record<Region, {
|
|
|
13
13
|
export declare function detectAndChooseServer(): Promise<string>;
|
|
14
14
|
export declare function urlToRegion(url: string): Region;
|
|
15
15
|
export declare function regionToUrl(region: Region): string;
|
|
16
|
-
//# sourceMappingURL=region.d.ts.map
|
package/dist/src/region.js
CHANGED
|
@@ -6,9 +6,17 @@ export type CliRelayOptions = {
|
|
|
6
6
|
agentList?: string[];
|
|
7
7
|
onReq?: (req: ReqFrame) => void;
|
|
8
8
|
onConnected?: () => void;
|
|
9
|
-
onDisconnected?: () => void;
|
|
9
|
+
onDisconnected?: (info: CliRelayDisconnectInfo) => void;
|
|
10
10
|
};
|
|
11
11
|
export type CliRelayState = 'connecting' | 'connected' | 'disconnected';
|
|
12
|
+
export type CliRelayDisconnectInfo = {
|
|
13
|
+
code?: number;
|
|
14
|
+
reason?: string;
|
|
15
|
+
error?: string;
|
|
16
|
+
phase: 'connecting' | 'connected' | 'disconnected';
|
|
17
|
+
trigger?: 'connect-timeout' | 'pong-timeout' | 'heartbeat-timeout' | 'socket-error' | 'socket-close';
|
|
18
|
+
reconnectAttempt: number;
|
|
19
|
+
};
|
|
12
20
|
export declare class CliRelayClient {
|
|
13
21
|
private options;
|
|
14
22
|
private ws;
|
|
@@ -20,6 +28,8 @@ export declare class CliRelayClient {
|
|
|
20
28
|
private pingTimer;
|
|
21
29
|
private pongTimer;
|
|
22
30
|
private disposed;
|
|
31
|
+
private closeTrigger;
|
|
32
|
+
private lastSocketError;
|
|
23
33
|
/** Buffered agent events awaiting server ack, keyed by event id */
|
|
24
34
|
private sendBuffer;
|
|
25
35
|
private pendingAcks;
|
|
@@ -50,4 +60,3 @@ export declare class CliRelayClient {
|
|
|
50
60
|
private scheduleReconnect;
|
|
51
61
|
private cleanup;
|
|
52
62
|
}
|
|
53
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/src/relay/client.js
CHANGED
|
@@ -21,6 +21,8 @@ export class CliRelayClient {
|
|
|
21
21
|
pingTimer = null;
|
|
22
22
|
pongTimer = null;
|
|
23
23
|
disposed = false;
|
|
24
|
+
closeTrigger;
|
|
25
|
+
lastSocketError;
|
|
24
26
|
/** Buffered agent events awaiting server ack, keyed by event id */
|
|
25
27
|
sendBuffer = new Map();
|
|
26
28
|
pendingAcks = new Map();
|
|
@@ -46,6 +48,7 @@ export class CliRelayClient {
|
|
|
46
48
|
// Guard against connections that never open (DNS hang, TCP timeout, etc.)
|
|
47
49
|
this.connectTimer = setTimeout(() => {
|
|
48
50
|
if (this.ws === ws && this.state === 'connecting') {
|
|
51
|
+
this.closeTrigger = 'connect-timeout';
|
|
49
52
|
ws.terminate();
|
|
50
53
|
}
|
|
51
54
|
}, CONNECT_TIMEOUT);
|
|
@@ -78,14 +81,25 @@ export class CliRelayClient {
|
|
|
78
81
|
}
|
|
79
82
|
this.handleFrame(frame);
|
|
80
83
|
});
|
|
81
|
-
ws.on('close', () => {
|
|
84
|
+
ws.on('close', (code, reason) => {
|
|
82
85
|
if (this.ws !== ws)
|
|
83
86
|
return;
|
|
87
|
+
const phase = this.state;
|
|
88
|
+
const info = {
|
|
89
|
+
code,
|
|
90
|
+
reason: reason.toString(),
|
|
91
|
+
error: this.lastSocketError,
|
|
92
|
+
phase,
|
|
93
|
+
trigger: this.closeTrigger ?? 'socket-close',
|
|
94
|
+
reconnectAttempt: this.reconnectAttempts + 1,
|
|
95
|
+
};
|
|
84
96
|
this.cleanup(false);
|
|
85
|
-
this.options.onDisconnected?.();
|
|
97
|
+
this.options.onDisconnected?.(info);
|
|
86
98
|
this.scheduleReconnect();
|
|
87
99
|
});
|
|
88
|
-
ws.on('error', () => {
|
|
100
|
+
ws.on('error', (error) => {
|
|
101
|
+
this.lastSocketError = error.message;
|
|
102
|
+
this.closeTrigger = 'socket-error';
|
|
89
103
|
ws.close();
|
|
90
104
|
});
|
|
91
105
|
}
|
|
@@ -210,6 +224,7 @@ export class CliRelayClient {
|
|
|
210
224
|
// Set pong timeout before sending ping
|
|
211
225
|
this.pongTimer = setTimeout(() => {
|
|
212
226
|
// No pong received — connection is dead, force close
|
|
227
|
+
this.closeTrigger = 'pong-timeout';
|
|
213
228
|
ws.close();
|
|
214
229
|
}, PONG_TIMEOUT);
|
|
215
230
|
try {
|
|
@@ -217,6 +232,7 @@ export class CliRelayClient {
|
|
|
217
232
|
}
|
|
218
233
|
catch {
|
|
219
234
|
this.clearPongTimer();
|
|
235
|
+
this.closeTrigger = 'socket-error';
|
|
220
236
|
ws.close();
|
|
221
237
|
}
|
|
222
238
|
}, PING_INTERVAL);
|
|
@@ -237,6 +253,7 @@ export class CliRelayClient {
|
|
|
237
253
|
startHeartbeat() {
|
|
238
254
|
this.clearHeartbeat();
|
|
239
255
|
this.heartbeatTimer = setTimeout(() => {
|
|
256
|
+
this.closeTrigger = 'heartbeat-timeout';
|
|
240
257
|
this.ws?.close();
|
|
241
258
|
}, HEARTBEAT_TIMEOUT);
|
|
242
259
|
}
|
|
@@ -263,6 +280,8 @@ export class CliRelayClient {
|
|
|
263
280
|
}
|
|
264
281
|
cleanup(rejectAll) {
|
|
265
282
|
this.state = 'disconnected';
|
|
283
|
+
this.closeTrigger = undefined;
|
|
284
|
+
this.lastSocketError = undefined;
|
|
266
285
|
this.clearConnectTimer();
|
|
267
286
|
this.clearHeartbeat();
|
|
268
287
|
this.clearPing();
|
|
@@ -290,4 +309,3 @@ export class CliRelayClient {
|
|
|
290
309
|
}
|
|
291
310
|
}
|
|
292
311
|
}
|
|
293
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -2,4 +2,3 @@ import type { ReqFrame } from '@shennian/wire';
|
|
|
2
2
|
import type { SessionManagerRuntime } from '../types.js';
|
|
3
3
|
export declare function handleModelsRefresh(runtime: SessionManagerRuntime, req: ReqFrame): Promise<void>;
|
|
4
4
|
export declare function handleAgentsRefresh(runtime: SessionManagerRuntime, req: ReqFrame): Promise<void>;
|
|
5
|
-
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -2,4 +2,3 @@ import type { ReqFrame } from '@shennian/wire';
|
|
|
2
2
|
import type { SessionManagerRuntime } from '../types.js';
|
|
3
3
|
export declare function handleChatSend(runtime: SessionManagerRuntime, req: ReqFrame): Promise<void>;
|
|
4
4
|
export declare function handleChatAbort(runtime: SessionManagerRuntime, req: ReqFrame): Promise<void>;
|
|
5
|
-
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -3,4 +3,3 @@ import type { SessionManagerRuntime } from '../types.js';
|
|
|
3
3
|
export declare function handleRegionProbe(runtime: SessionManagerRuntime, req: ReqFrame): Promise<void>;
|
|
4
4
|
export declare function handleRegionSwitch(runtime: SessionManagerRuntime, req: ReqFrame): Promise<void>;
|
|
5
5
|
export declare function handleUpgradeSetPolicy(runtime: SessionManagerRuntime, req: ReqFrame): Promise<void>;
|
|
6
|
-
//# sourceMappingURL=control.d.ts.map
|
|
@@ -8,4 +8,3 @@ export declare function handleFsTransferChunk(runtime: SessionManagerRuntime, re
|
|
|
8
8
|
export declare function handleFsTransferFinish(runtime: SessionManagerRuntime, req: ReqFrame): Promise<void>;
|
|
9
9
|
export declare function handleFsTransferAbort(runtime: SessionManagerRuntime, req: ReqFrame): Promise<void>;
|
|
10
10
|
export declare function cleanupPendingTransfers(runtime: SessionManagerRuntime): void;
|
|
11
|
-
//# sourceMappingURL=fs.d.ts.map
|