openclaw-openagent 1.0.12 → 1.0.14
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/index.js +2 -0
- package/dist/src/config/config-schema.d.ts +9 -0
- package/dist/src/config/config-schema.js +6 -0
- package/dist/src/messaging/executor.d.ts +2 -3
- package/dist/src/messaging/executor.js +4 -31
- package/dist/src/plugin-ui/assets/openagent-override.js +124 -18
- package/dist/src/proxy/auth-proxy.js +5 -0
- package/dist/src/runtime/update-checker.d.ts +18 -0
- package/dist/src/runtime/update-checker.js +216 -0
- package/index.ts +3 -0
- package/package.json +1 -3
- package/src/app/channel-tools.ts +0 -249
- package/src/app/discovery-tools.ts +0 -273
- package/src/app/download-file-tool.ts +0 -133
- package/src/app/hooks.ts +0 -144
- package/src/app/index.ts +0 -84
- package/src/app/messaging-tools.ts +0 -79
- package/src/app/ops-tools.ts +0 -155
- package/src/app/remote-agent-tool.ts +0 -762
- package/src/app/types.ts +0 -68
- package/src/app/upload-file-tool.ts +0 -411
- package/src/app/verbose-preflight.ts +0 -190
- package/src/auth/config.ts +0 -266
- package/src/auth/credential-manager.ts +0 -146
- package/src/auth/index.ts +0 -24
- package/src/auth/verify.ts +0 -99
- package/src/channel.ts +0 -566
- package/src/compat.ts +0 -94
- package/src/config/config-schema.ts +0 -39
- package/src/messaging/aggregator.ts +0 -120
- package/src/messaging/collector.ts +0 -89
- package/src/messaging/executor.ts +0 -72
- package/src/messaging/inbound.ts +0 -150
- package/src/messaging/index.ts +0 -11
- package/src/messaging/mention-protocol.ts +0 -94
- package/src/messaging/process-c2c-request.ts +0 -564
- package/src/messaging/process-message.ts +0 -373
- package/src/messaging/scheduler.ts +0 -55
- package/src/messaging/types.ts +0 -38
- package/src/plugin-ui/adapters/oc-2026-04.js +0 -103
- package/src/plugin-ui/adapters/oc-2026-05.js +0 -125
- package/src/plugin-ui/adapters/oc-2026-06.js +0 -125
- package/src/plugin-ui/adapters/oc-unknown.js +0 -48
- package/src/plugin-ui/assets/agentbook-icon.svg +0 -5
- package/src/plugin-ui/assets/bg.png +0 -0
- package/src/plugin-ui/assets/icon.png +0 -0
- package/src/plugin-ui/assets/magic.svg +0 -5
- package/src/plugin-ui/assets/openagent-override.js +0 -11156
- package/src/plugin-ui/build.cjs +0 -463
- package/src/plugin-ui/index.ts +0 -18
- package/src/plugin-ui/modules/agent-book/panel/agent-book.js +0 -570
- package/src/plugin-ui/modules/agent-book/panel/agent-card.js +0 -170
- package/src/plugin-ui/modules/agent-book/panel/agent-data.js +0 -643
- package/src/plugin-ui/modules/agent-book/panel/inject-ui.js +0 -665
- package/src/plugin-ui/modules/agent-book/panel/mention-state.js +0 -206
- package/src/plugin-ui/modules/agent-book/panel/styles.js +0 -833
- package/src/plugin-ui/modules/agent-book/panel/theme-adapter.js +0 -86
- package/src/plugin-ui/modules/agent-book/remote-agent-tool/components-core.js +0 -295
- package/src/plugin-ui/modules/agent-book/remote-agent-tool/thought-chain-card.js +0 -211
- package/src/plugin-ui/modules/agent-book/scanner.js +0 -131
- package/src/plugin-ui/modules/agent-book/travelcard/travel-cards.js +0 -500
- package/src/plugin-ui/modules/agent-book/travelcard/travel-engine.js +0 -652
- package/src/plugin-ui/modules/agent-book/travelcard/travel-styles.js +0 -256
- package/src/plugin-ui/modules/loader/bootstrap.js +0 -38
- package/src/plugin-ui/modules/loader/shared-state.js +0 -838
- package/src/plugin-ui/modules/loader/ws-intercept.js +0 -199
- package/src/plugin-ui/modules/remote-agent/chunk-parser.js +0 -161
- package/src/plugin-ui/modules/remote-agent/execution-card.js +0 -530
- package/src/plugin-ui/modules/remote-agent/markdown-renderer.js +0 -256
- package/src/plugin-ui/modules/remote-agent/media-links.js +0 -151
- package/src/plugin-ui/modules/remote-agent/native-style-adapter.js +0 -134
- package/src/plugin-ui/modules/remote-agent/output-card.js +0 -342
- package/src/plugin-ui/modules/remote-agent/progress-store.js +0 -363
- package/src/plugin-ui/modules/remote-agent/render-hooks.js +0 -1700
- package/src/plugin-ui/modules/remote-agent/styles.js +0 -896
- package/src/plugin-ui/modules/remote-agent/tool-card-model.js +0 -130
- package/src/plugin-ui/postinstall-deploy.cjs +0 -52
- package/src/plugin-ui/ui-extension-loader/backup.ts +0 -92
- package/src/plugin-ui/ui-extension-loader/index.ts +0 -276
- package/src/plugin-ui/ui-extension-loader/locator.ts +0 -152
- package/src/plugin-ui/ui-extension-loader/manifest.ts +0 -57
- package/src/plugin-ui/ui-extension-loader/registry-regex.ts +0 -944
- package/src/plugin-ui/ui-extension-loader/removed-extensions.ts +0 -70
- package/src/plugin-ui/ui-extension-loader/types.ts +0 -72
- package/src/proxy/auth-proxy.ts +0 -409
- package/src/runtime/account.ts +0 -549
- package/src/runtime/index.ts +0 -7
- package/src/runtime/plugin-runtime.ts +0 -94
- package/src/runtime/registry.ts +0 -71
- package/src/sdk/CLASS_MAP.md +0 -143
- package/src/sdk/index.d.ts +0 -126
- package/src/sdk/index.js +0 -23990
- package/src/sdk/modules/cloud-search-module.js +0 -1117
- package/src/sdk/modules/follow-module.js +0 -1069
- package/src/sdk/modules/group-module.js +0 -7397
- package/src/sdk/modules/relationship-module.js +0 -2269
- package/src/sdk/modules/signaling-module.js +0 -1468
- package/src/sdk/modules/tim-upload-plugin.js +0 -730
- package/src/sdk/node-env/http-request.js +0 -90
- package/src/sdk/node-env/index.js +0 -57
- package/src/sdk/node-env/storage.js +0 -114
- package/src/sdk/package.json +0 -10
- package/src/sdk/tsconfig.json +0 -16
- package/src/state/pending-invocation-store.ts +0 -43
- package/src/state/store.ts +0 -756
- package/src/tim/c2c.ts +0 -451
- package/src/tim/channels.ts +0 -364
- package/src/tim/client.ts +0 -330
- package/src/tim/index.ts +0 -18
- package/src/tim/messages.ts +0 -166
- package/src/tim/sdk-logger-init.ts +0 -50
- package/src/tools.ts +0 -10
- package/src/transport/factory.ts +0 -95
- package/src/transport/oasn/index.ts +0 -17
- package/src/transport/oasn/oasn-agent-card.ts +0 -111
- package/src/transport/oasn/oasn-discovery.ts +0 -108
- package/src/transport/oasn/oasn-files.ts +0 -210
- package/src/transport/oasn/oasn-http.ts +0 -529
- package/src/transport/oasn/oasn-invocation.ts +0 -604
- package/src/transport/oasn/oasn-normalize.ts +0 -133
- package/src/transport/oasn/oasn-register.ts +0 -33
- package/src/transport/oasn/oasn-transport.ts +0 -318
- package/src/transport/oasn/oasn-types.ts +0 -404
- package/src/transport/tim/index.ts +0 -8
- package/src/transport/tim/tim-transport.ts +0 -515
- package/src/transport/types.ts +0 -538
- package/src/types/openclaw-plugin-sdk-media-store.d.ts +0 -9
- package/src/types/openclaw.d.ts +0 -97
- package/src/types/tencentcloud-chat.d.ts +0 -15
- package/src/util/http.ts +0 -113
- package/src/util/logger.ts +0 -131
- package/src/util/url-resolver.ts +0 -77
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
// ══════════════════════════════════════════════════════════════
|
|
2
|
-
// 方案 A: WebSocket 构造函数拦截(主力)
|
|
3
|
-
// 直接给每个 WS 实例加 message listener,不依赖 JSON.parse
|
|
4
|
-
// ══════════════════════════════════════════════════════════════
|
|
5
|
-
const _OrigWebSocket = window.WebSocket;
|
|
6
|
-
window.WebSocket = function(url, protocols) {
|
|
7
|
-
const ws = protocols !== undefined
|
|
8
|
-
? new _OrigWebSocket(url, protocols)
|
|
9
|
-
: new _OrigWebSocket(url);
|
|
10
|
-
|
|
11
|
-
ws.addEventListener('message', function(event) {
|
|
12
|
-
try {
|
|
13
|
-
const raw = String(event.data || '');
|
|
14
|
-
const msg = JSON.parse(raw);
|
|
15
|
-
if (!msg || typeof msg !== 'object') return;
|
|
16
|
-
|
|
17
|
-
const p = _extractToolStreamPayload(msg);
|
|
18
|
-
if (p) {
|
|
19
|
-
if (_isRawToolStreamDebugEnabled()) {
|
|
20
|
-
_logRawToolStreamPayload(p, msg);
|
|
21
|
-
}
|
|
22
|
-
if (typeof CL.handleDelegateWsEvent === 'function') {
|
|
23
|
-
CL.handleDelegateWsEvent(p);
|
|
24
|
-
}
|
|
25
|
-
_interceptTripData(p);
|
|
26
|
-
}
|
|
27
|
-
} catch (err) {
|
|
28
|
-
// silent — non-JSON messages or parsing errors
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
return ws;
|
|
33
|
-
};
|
|
34
|
-
// 保留静态属性和原型链
|
|
35
|
-
window.WebSocket.prototype = _OrigWebSocket.prototype;
|
|
36
|
-
window.WebSocket.CONNECTING = _OrigWebSocket.CONNECTING;
|
|
37
|
-
window.WebSocket.OPEN = _OrigWebSocket.OPEN;
|
|
38
|
-
window.WebSocket.CLOSING = _OrigWebSocket.CLOSING;
|
|
39
|
-
window.WebSocket.CLOSED = _OrigWebSocket.CLOSED;
|
|
40
|
-
|
|
41
|
-
/* muted */ void 0;
|
|
42
|
-
|
|
43
|
-
function _extractToolStreamPayload(msg) {
|
|
44
|
-
if (!msg || msg.type !== 'event') return null;
|
|
45
|
-
|
|
46
|
-
// Current OpenClaw gateway frames use:
|
|
47
|
-
// { type: "event", event: "agent", payload: { stream: "tool", data: ... } }
|
|
48
|
-
if (msg.event === 'agent' && msg.payload && msg.payload.stream === 'tool') {
|
|
49
|
-
return msg.payload;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Keep compatibility with older/local frames that already put the tool
|
|
53
|
-
// stream payload directly under payload, or one level deeper.
|
|
54
|
-
if (msg.payload && msg.payload.stream === 'tool') return msg.payload;
|
|
55
|
-
if (msg.payload && msg.payload.payload && msg.payload.payload.stream === 'tool') {
|
|
56
|
-
return msg.payload.payload;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function _logRawToolStreamPayload(payload, frame) {
|
|
63
|
-
try {
|
|
64
|
-
const data = payload && payload.data || {};
|
|
65
|
-
const entry = {
|
|
66
|
-
ts: new Date().toISOString(),
|
|
67
|
-
phase: data.phase || '',
|
|
68
|
-
toolCallId: data.toolCallId || '',
|
|
69
|
-
payload,
|
|
70
|
-
frame
|
|
71
|
-
};
|
|
72
|
-
window.__openagentRawToolStreamLog = window.__openagentRawToolStreamLog || [];
|
|
73
|
-
window.__openagentRawToolStreamLog.push(entry);
|
|
74
|
-
if (window.__openagentRawToolStreamLog.length > 200) {
|
|
75
|
-
window.__openagentRawToolStreamLog.splice(0, window.__openagentRawToolStreamLog.length - 200);
|
|
76
|
-
}
|
|
77
|
-
_persistRawToolStreamDebugLog(window.__openagentRawToolStreamLog);
|
|
78
|
-
console.log('[cl-raw-tool-stream] tcid=' + String(entry.toolCallId || '').substring(0, 8)
|
|
79
|
-
+ ' phase=' + entry.phase
|
|
80
|
-
+ ' payload=' + JSON.stringify(payload));
|
|
81
|
-
} catch (err) {
|
|
82
|
-
// debug logging must never affect the stream path
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function _isRawToolStreamDebugEnabled() {
|
|
87
|
-
try {
|
|
88
|
-
return window.localStorage && window.localStorage.getItem('openagent.debug.rawSse') === '1';
|
|
89
|
-
} catch (err) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function _persistRawToolStreamDebugLog(entries) {
|
|
95
|
-
try {
|
|
96
|
-
const json = JSON.stringify(entries || []);
|
|
97
|
-
try {
|
|
98
|
-
window.localStorage && window.localStorage.setItem('openagent.rawToolStream.v1', json);
|
|
99
|
-
} catch (storageErr) {}
|
|
100
|
-
|
|
101
|
-
const doc = window.document;
|
|
102
|
-
if (!doc || !doc.body) return;
|
|
103
|
-
let node = doc.getElementById('openagent-raw-tool-stream-log');
|
|
104
|
-
if (!node) {
|
|
105
|
-
node = doc.createElement('pre');
|
|
106
|
-
node.id = 'openagent-raw-tool-stream-log';
|
|
107
|
-
node.style.display = 'none';
|
|
108
|
-
doc.body.appendChild(node);
|
|
109
|
-
}
|
|
110
|
-
node.textContent = json;
|
|
111
|
-
} catch (err) {}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function _interceptTripData(payload) {
|
|
115
|
-
try {
|
|
116
|
-
const data = payload?.data;
|
|
117
|
-
|
|
118
|
-
// 深度检查 payload 结构
|
|
119
|
-
if (data) {
|
|
120
|
-
const keys = Object.keys(data);
|
|
121
|
-
const strFields = keys.filter(k => typeof data[k] === 'string' && data[k].length > 50);
|
|
122
|
-
const hasTripInAny = keys.some(k => typeof data[k] === 'string' && data[k].includes('TRIP_DATA'));
|
|
123
|
-
/* muted */ void 0;
|
|
124
|
-
|
|
125
|
-
// 深入一层
|
|
126
|
-
if (data.data && typeof data.data === 'object') {
|
|
127
|
-
const dk = Object.keys(data.data);
|
|
128
|
-
const dHas = dk.some(k => typeof data.data[k] === 'string' && data.data[k].includes('TRIP_DATA'));
|
|
129
|
-
/* muted */ void 0;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (!data) return;
|
|
133
|
-
|
|
134
|
-
// 检测 [TRIP_CARDS_READY] 信号标记,然后 fetch 卡片数据文件
|
|
135
|
-
const textFields = ['text', 'content', 'result', 'output'];
|
|
136
|
-
|
|
137
|
-
function tryDetectSignal(obj, field) {
|
|
138
|
-
if (typeof obj[field] !== 'string') return false;
|
|
139
|
-
const val = obj[field];
|
|
140
|
-
if (!val.includes('[TRIP_CARDS_READY]')) return false;
|
|
141
|
-
// 移除信号标记
|
|
142
|
-
obj[field] = val.replace(/\n*\[TRIP_CARDS_READY\]/, '');
|
|
143
|
-
CL.fetchTripCardDataOnce('ws-ready-marker');
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
for (const field of textFields) {
|
|
148
|
-
if (tryDetectSignal(data, field)) return;
|
|
149
|
-
}
|
|
150
|
-
if (data.data && typeof data.data === 'object') {
|
|
151
|
-
for (const field of textFields) {
|
|
152
|
-
if (tryDetectSignal(data.data, field)) return;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
} catch (err) {
|
|
156
|
-
// silent
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
CL.fetchTripCardDataOnce = function(source, options) {
|
|
162
|
-
const force = !!(options && options.force);
|
|
163
|
-
const scope = options && options.scope;
|
|
164
|
-
if (scope && typeof CL.getScopedTripCardData === 'function') {
|
|
165
|
-
const scoped = CL.getScopedTripCardData(scope);
|
|
166
|
-
if (scoped && !force) return Promise.resolve(scoped);
|
|
167
|
-
}
|
|
168
|
-
if (CL.tripCardData && !force && (!scope || (typeof CL.tripCardDataMatchesScope === 'function' && CL.tripCardDataMatchesScope(CL.tripCardData, scope)))) {
|
|
169
|
-
return Promise.resolve(CL.tripCardData);
|
|
170
|
-
}
|
|
171
|
-
if (CL.tripCardDataFetchPromise) return CL.tripCardDataFetchPromise;
|
|
172
|
-
if (CL.tripCardDataFetchFailed) return Promise.resolve(null);
|
|
173
|
-
|
|
174
|
-
CL.tripCardDataFetchPromise = fetch('./trip-card-data.json?t=' + Date.now())
|
|
175
|
-
.then(r => {
|
|
176
|
-
if (!r.ok) throw new Error('HTTP ' + r.status);
|
|
177
|
-
return r.json();
|
|
178
|
-
})
|
|
179
|
-
.then(cardData => {
|
|
180
|
-
if (typeof CL.mergeTripCardData === 'function') {
|
|
181
|
-
CL.mergeTripCardData(cardData, { replaceDayList: true, scope: scope });
|
|
182
|
-
} else {
|
|
183
|
-
CL.tripCardData = cardData;
|
|
184
|
-
}
|
|
185
|
-
CL.tripCardDataFetchFailed = false;
|
|
186
|
-
/* muted */ void 0;
|
|
187
|
-
return cardData;
|
|
188
|
-
})
|
|
189
|
-
.catch(e => {
|
|
190
|
-
CL.tripCardDataFetchFailed = true;
|
|
191
|
-
console.warn('[trip-cards] File fetch failed:', e.message, 'via', source || 'unknown');
|
|
192
|
-
return null;
|
|
193
|
-
})
|
|
194
|
-
.finally(() => {
|
|
195
|
-
CL.tripCardDataFetchPromise = null;
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
return CL.tripCardDataFetchPromise;
|
|
199
|
-
};
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// ── OpenAgent Chunk Parser — card.text → Chunk[] ──
|
|
2
|
-
//
|
|
3
|
-
// 解析 ToolCard.text 中的 JSON 数据块。
|
|
4
|
-
// 数据格式来自远端 Agent 的 SSE 流:
|
|
5
|
-
// {"msgType":2,"dataType":"think","thinkType":"title|content","text":"..."}
|
|
6
|
-
//
|
|
7
|
-
// 输出 Chunk 类型:
|
|
8
|
-
// { type: 'step', title: string } — 仅 dataType=think + thinkType=title
|
|
9
|
-
// { type: 'result', text: string } — 最终结果
|
|
10
|
-
// { type: 'error', text: string } — 错误信息
|
|
11
|
-
// { type: 'data', raw: object } — 结构化数据(tripCard 等)
|
|
12
|
-
// { type: 'text', text: string } — 纯文本 fallback
|
|
13
|
-
|
|
14
|
-
function _clParseChunks(text, scope) {
|
|
15
|
-
if (!text) return [];
|
|
16
|
-
var chunks = [];
|
|
17
|
-
|
|
18
|
-
// text 通常是多行 JSON,但历史/不同版本里也可能是连续 JSON 或
|
|
19
|
-
// 带换行的完整 JSON。先按平衡大括号切出 record,避免 data event 退化成正文。
|
|
20
|
-
var parts = _clSplitJsonRecords(text);
|
|
21
|
-
for (var pi = 0; pi < parts.length; pi++) {
|
|
22
|
-
var part = parts[pi];
|
|
23
|
-
if (part.type === 'json') {
|
|
24
|
-
chunks.push(_clNormalizeChunk(part.raw, scope));
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var lines = String(part.text || '').split('\n');
|
|
29
|
-
for (var i = 0; i < lines.length; i++) {
|
|
30
|
-
var line = lines[i].trim();
|
|
31
|
-
if (!line) continue;
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
var obj = JSON.parse(line);
|
|
35
|
-
if (obj && typeof obj === 'object') {
|
|
36
|
-
chunks.push(_clNormalizeChunk(obj, scope));
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
} catch (e) {
|
|
40
|
-
// not JSON — treat as plain text fallback
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 纯文本 fallback
|
|
44
|
-
chunks.push({ type: 'text', text: line });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return chunks;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function _clReadJsonRecordAt(text, start) {
|
|
52
|
-
if (!text || text.charAt(start) !== '{') return null;
|
|
53
|
-
var depth = 0;
|
|
54
|
-
var inString = false;
|
|
55
|
-
var escaping = false;
|
|
56
|
-
|
|
57
|
-
for (var i = start; i < text.length; i++) {
|
|
58
|
-
var ch = text.charAt(i);
|
|
59
|
-
|
|
60
|
-
if (inString) {
|
|
61
|
-
if (escaping) {
|
|
62
|
-
escaping = false;
|
|
63
|
-
} else if (ch === '\\') {
|
|
64
|
-
escaping = true;
|
|
65
|
-
} else if (ch === '"') {
|
|
66
|
-
inString = false;
|
|
67
|
-
}
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (ch === '"') {
|
|
72
|
-
inString = true;
|
|
73
|
-
} else if (ch === '{') {
|
|
74
|
-
depth++;
|
|
75
|
-
} else if (ch === '}') {
|
|
76
|
-
depth--;
|
|
77
|
-
if (depth === 0) {
|
|
78
|
-
var rawText = text.slice(start, i + 1);
|
|
79
|
-
try {
|
|
80
|
-
var parsed = JSON.parse(rawText);
|
|
81
|
-
if (parsed && typeof parsed === 'object') {
|
|
82
|
-
return { raw: parsed, end: i + 1 };
|
|
83
|
-
}
|
|
84
|
-
} catch (e) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function _clSplitJsonRecords(text) {
|
|
95
|
-
var parts = [];
|
|
96
|
-
var last = 0;
|
|
97
|
-
|
|
98
|
-
for (var i = 0; i < text.length; i++) {
|
|
99
|
-
if (text.charAt(i) !== '{') continue;
|
|
100
|
-
var record = _clReadJsonRecordAt(text, i);
|
|
101
|
-
if (!record) continue;
|
|
102
|
-
|
|
103
|
-
if (i > last) {
|
|
104
|
-
parts.push({ type: 'text', text: text.slice(last, i) });
|
|
105
|
-
}
|
|
106
|
-
parts.push({ type: 'json', raw: record.raw });
|
|
107
|
-
i = record.end - 1;
|
|
108
|
-
last = record.end;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (last < text.length) {
|
|
112
|
-
parts.push({ type: 'text', text: text.slice(last) });
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return parts.length ? parts : [{ type: 'text', text: text }];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function _clNormalizeChunk(obj, scope) {
|
|
119
|
-
if (typeof _cl_ingestTripCardData === 'function') {
|
|
120
|
-
try { _cl_ingestTripCardData(obj, scope); } catch (e) {}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// 远端 Agent SSE 格式: {msgType, dataType, thinkType, text, ...}
|
|
124
|
-
if (obj.dataType === 'think') {
|
|
125
|
-
if (obj.thinkType === 'title') {
|
|
126
|
-
return { type: 'step', title: obj.text || '' };
|
|
127
|
-
}
|
|
128
|
-
return { type: 'data', raw: obj };
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (obj.dataType === 'data') {
|
|
132
|
-
return { type: 'data', raw: obj };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// 结构化数据(tripCardData, unitContext 等)
|
|
136
|
-
if (obj.fullJson || obj.unitContext || obj.unitContexts || obj.dayList
|
|
137
|
-
|| obj.foodData || obj.budgetData || obj.budget || obj.tripCardData
|
|
138
|
-
|| obj.itineraryVersionInfo || obj.itinerary) {
|
|
139
|
-
return { type: 'data', raw: obj };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// 错误:只接受显式错误事件。不能把普通业务 JSON 里的 error 字段直接当成
|
|
143
|
-
// OpenClaw tool error,否则刷新历史卡片时会把 output 外壳染成错误态。
|
|
144
|
-
if (obj.type === 'error' || obj.dataType === 'error' || obj.isError === true) {
|
|
145
|
-
return { type: 'error', text: obj.message || obj.error || obj.text || '' };
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// 结果
|
|
149
|
-
if (obj.type === 'result' || obj.dataType === 'result') {
|
|
150
|
-
return { type: 'result', text: obj.content || obj.text || '' };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// 通用 thinking/step/progress 不再生成过程 UI;只保留为数据。
|
|
154
|
-
if (obj.type === 'thinking' || obj.type === 'thought'
|
|
155
|
-
|| obj.type === 'step' || obj.type === 'progress') {
|
|
156
|
-
return { type: 'data', raw: obj };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// fallback: 整个对象当数据
|
|
160
|
-
return { type: 'data', raw: obj };
|
|
161
|
-
}
|