openclaw-openagent 1.0.11 → 1.0.12
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 +1 -1
- package/dist/src/app/remote-agent-tool.js +110 -14
- package/dist/src/app/types.d.ts +2 -2
- package/dist/src/plugin-ui/adapters/adapters/oc-2026-04.js +103 -0
- package/dist/src/plugin-ui/adapters/adapters/oc-2026-05.js +125 -0
- package/dist/src/plugin-ui/adapters/adapters/oc-2026-06.js +125 -0
- package/dist/src/plugin-ui/adapters/adapters/oc-unknown.js +48 -0
- package/dist/src/plugin-ui/adapters/oc-2026-04.js +103 -0
- package/dist/src/plugin-ui/adapters/oc-2026-05.js +125 -0
- package/dist/src/plugin-ui/adapters/oc-2026-06.js +125 -0
- package/dist/src/plugin-ui/adapters/oc-unknown.js +48 -0
- package/dist/src/plugin-ui/assets/openagent-override.js +1007 -258
- package/dist/src/plugin-ui/index.d.ts +1 -1
- package/dist/src/plugin-ui/index.js +2 -2
- package/dist/src/plugin-ui/ui-extension-loader/index.d.ts +2 -1
- package/dist/src/plugin-ui/ui-extension-loader/index.js +5 -5
- package/dist/src/plugin-ui/ui-extension-loader/registry-regex.js +75 -8
- package/dist/src/plugin-ui/ui-extension-loader/types.d.ts +4 -1
- package/dist/src/state/store.d.ts +21 -0
- package/dist/src/state/store.js +54 -0
- package/dist/src/transport/oasn/oasn-invocation.d.ts +3 -0
- package/dist/src/transport/oasn/oasn-invocation.js +28 -12
- package/dist/src/transport/oasn/oasn-types.d.ts +8 -4
- package/index.ts +1 -1
- package/package.json +4 -3
- package/src/app/remote-agent-tool.ts +131 -16
- package/src/app/types.ts +2 -2
- package/src/plugin-ui/adapters/oc-2026-04.js +103 -0
- package/src/plugin-ui/adapters/oc-2026-05.js +125 -0
- package/src/plugin-ui/adapters/oc-2026-06.js +125 -0
- package/src/plugin-ui/adapters/oc-unknown.js +48 -0
- package/src/plugin-ui/assets/openagent-override.js +1007 -258
- package/src/plugin-ui/build.cjs +249 -38
- package/src/plugin-ui/index.ts +2 -2
- package/src/plugin-ui/modules/agent-book/panel/agent-book.js +102 -12
- package/src/plugin-ui/modules/agent-book/panel/inject-ui.js +105 -3
- package/src/plugin-ui/modules/agent-book/panel/styles.js +42 -35
- package/src/plugin-ui/modules/agent-book/remote-agent-tool/components-core.js +4 -2
- package/src/plugin-ui/modules/agent-book/remote-agent-tool/thought-chain-card.js +4 -1
- package/src/plugin-ui/modules/agent-book/scanner.js +17 -5
- package/src/plugin-ui/modules/agent-book/travelcard/travel-styles.js +5 -0
- package/src/plugin-ui/modules/loader/shared-state.js +244 -20
- package/src/plugin-ui/modules/remote-agent/execution-card.js +54 -16
- package/src/plugin-ui/modules/remote-agent/native-style-adapter.js +5 -23
- package/src/plugin-ui/modules/remote-agent/output-card.js +13 -7
- package/src/plugin-ui/modules/remote-agent/render-hooks.js +53 -41
- package/src/plugin-ui/modules/remote-agent/styles.js +230 -88
- package/src/plugin-ui/modules/remote-agent/tool-card-model.js +72 -4
- package/src/plugin-ui/postinstall-deploy.cjs +52 -0
- package/src/plugin-ui/ui-extension-loader/index.ts +6 -6
- package/src/plugin-ui/ui-extension-loader/registry-regex.ts +81 -9
- package/src/plugin-ui/ui-extension-loader/types.ts +5 -1
- package/src/state/store.ts +80 -0
- package/src/transport/oasn/oasn-invocation.ts +47 -12
- package/src/transport/oasn/oasn-types.ts +6 -2
- package/src/types/openclaw-plugin-sdk-media-store.d.ts +9 -0
|
@@ -17,7 +17,7 @@ import { restoreFile } from './backup.js';
|
|
|
17
17
|
import { UI_EXTENSIONS } from './registry-regex.js';
|
|
18
18
|
import { REMOVED_UI_EXTENSIONS } from './removed-extensions.js';
|
|
19
19
|
import type { ManifestData } from './manifest.js';
|
|
20
|
-
import type { UIExtension } from './types.js';
|
|
20
|
+
import type { UIExtension, UIExtensionContext } from './types.js';
|
|
21
21
|
import type { RemovedUIExtension, RemovedRevertResult } from './removed-extensions.js';
|
|
22
22
|
|
|
23
23
|
// ── 注入策略:正则模式链(无需 .map,21 版本全仿真验证通过)──────────────────
|
|
@@ -53,7 +53,7 @@ function needsChange(
|
|
|
53
53
|
* 4. 共享文件扩展按组处理:任何一个变更 → 恢复 backup → 重新 apply 全组
|
|
54
54
|
* 5. 写入新 manifest
|
|
55
55
|
*/
|
|
56
|
-
export async function loadUIExtensions(): Promise<void> {
|
|
56
|
+
export async function loadUIExtensions(context: UIExtensionContext = {}): Promise<void> {
|
|
57
57
|
const controlUiDir = resolveControlUiDir();
|
|
58
58
|
|
|
59
59
|
if (!controlUiDir) {
|
|
@@ -134,7 +134,7 @@ export async function loadUIExtensions(): Promise<void> {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
logger.debug(`[ui-ext] ${ext.id}: apply v${ext.version}`);
|
|
137
|
-
if (safeApply(ext, controlUiDir)) {
|
|
137
|
+
if (safeApply(ext, controlUiDir, context)) {
|
|
138
138
|
newExtensions[ext.id] = { version: ext.version };
|
|
139
139
|
applied++;
|
|
140
140
|
}
|
|
@@ -200,7 +200,7 @@ export async function loadUIExtensions(): Promise<void> {
|
|
|
200
200
|
// 重新 apply 全组中所有应保留的扩展
|
|
201
201
|
for (const ext of group) {
|
|
202
202
|
logger.debug(`[ui-ext] ${ext.id}: apply v${ext.version} (group rebuild)`);
|
|
203
|
-
if (safeApply(ext, controlUiDir)) {
|
|
203
|
+
if (safeApply(ext, controlUiDir, context)) {
|
|
204
204
|
newExtensions[ext.id] = { version: ext.version };
|
|
205
205
|
applied++;
|
|
206
206
|
}
|
|
@@ -249,9 +249,9 @@ export async function unloadUIExtensions(): Promise<void> {
|
|
|
249
249
|
|
|
250
250
|
// ── Helpers ──────────────────────────────────────────────────────────────
|
|
251
251
|
|
|
252
|
-
function safeApply(ext: UIExtension, controlUiDir: string): boolean {
|
|
252
|
+
function safeApply(ext: UIExtension, controlUiDir: string, context: UIExtensionContext): boolean {
|
|
253
253
|
try {
|
|
254
|
-
return ext.apply(controlUiDir);
|
|
254
|
+
return ext.apply(controlUiDir, context);
|
|
255
255
|
} catch (err) {
|
|
256
256
|
logger.error(`[ui-ext] Failed to apply '${ext.id}': ${(err as Error).message}`);
|
|
257
257
|
return false;
|
|
@@ -13,17 +13,87 @@ import { logger } from '../../util/logger.js';
|
|
|
13
13
|
import { findFileByPrefix } from './locator.js';
|
|
14
14
|
import { backupFile, restoreFile } from './backup.js';
|
|
15
15
|
import { makeMarker, hasMarker } from './types.js';
|
|
16
|
-
import type { UIExtension } from './types.js';
|
|
16
|
+
import type { UIExtension, UIExtensionContext } from './types.js';
|
|
17
17
|
|
|
18
18
|
// ── 常量 ──────────────────────────────────────────────────────────────────
|
|
19
19
|
|
|
20
20
|
const OVERRIDE_ASSET_URL = new URL('../assets/openagent-override.js', import.meta.url);
|
|
21
21
|
const ICON_ASSET_URL = new URL('../assets/icon.png', import.meta.url);
|
|
22
22
|
const BG_ASSET_URL = new URL('../assets/bg.png', import.meta.url);
|
|
23
|
+
const HOST_ADAPTER_URLS: Record<string, URL> = {
|
|
24
|
+
'oc-2026-04': new URL('../adapters/oc-2026-04.js', import.meta.url),
|
|
25
|
+
'oc-2026-05': new URL('../adapters/oc-2026-05.js', import.meta.url),
|
|
26
|
+
'oc-2026-06': new URL('../adapters/oc-2026-06.js', import.meta.url),
|
|
27
|
+
'oc-unknown': new URL('../adapters/oc-unknown.js', import.meta.url),
|
|
28
|
+
};
|
|
29
|
+
const HOST_ADAPTER_START = '/*__OPENAGENT_HOST_ADAPTER_START__*/';
|
|
30
|
+
const HOST_ADAPTER_END = '/*__OPENAGENT_HOST_ADAPTER_END__*/';
|
|
31
|
+
const HOST_ADAPTER_BLOCK_RE = /\/\*__OPENAGENT_HOST_ADAPTER_START__\*\/[\s\S]*?\/\*__OPENAGENT_HOST_ADAPTER_END__\*\//;
|
|
32
|
+
const BUILD_ID_TOKEN = "buildId: '__OPENAGENT_BUILD_ID__'";
|
|
33
|
+
const BUILD_ID_ASSIGNMENT_RE = /buildId:\s*(?:"[^"]*"|'[^']*')/;
|
|
34
|
+
|
|
35
|
+
function normalizeHostVersion(hostVersion: string | undefined): string {
|
|
36
|
+
const value = String(hostVersion || '').trim();
|
|
37
|
+
if (!value || value === 'unknown') return '';
|
|
38
|
+
const match = value.match(/20\d{2}\.\d{1,2}\.\d{1,2}(?:-[A-Za-z0-9._-]+)?/);
|
|
39
|
+
return match ? match[0] : '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function resolveHostAdapterId(hostVersion: string | undefined): string {
|
|
43
|
+
const version = normalizeHostVersion(hostVersion);
|
|
44
|
+
const parts = version.split('.');
|
|
45
|
+
const year = Number.parseInt(parts[0], 10);
|
|
46
|
+
const month = Number.parseInt(parts[1], 10);
|
|
47
|
+
if (year === 2026 && month === 4) return 'oc-2026-04';
|
|
48
|
+
if (year === 2026 && month === 5) return 'oc-2026-05';
|
|
49
|
+
if (year === 2026 && month === 6) return 'oc-2026-06';
|
|
50
|
+
return 'oc-unknown';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getHostAdapterBlock(hostVersion: string | undefined): string {
|
|
54
|
+
let adapterId = resolveHostAdapterId(hostVersion);
|
|
55
|
+
let adapterUrl = HOST_ADAPTER_URLS[adapterId];
|
|
56
|
+
if (!adapterUrl || !existsSync(adapterUrl)) {
|
|
57
|
+
adapterId = 'oc-unknown';
|
|
58
|
+
adapterUrl = HOST_ADAPTER_URLS[adapterId];
|
|
59
|
+
}
|
|
60
|
+
const adapterSource = readFileSync(adapterUrl, 'utf-8').trimEnd();
|
|
61
|
+
return [
|
|
62
|
+
HOST_ADAPTER_START,
|
|
63
|
+
`// HOST ADAPTER: ${adapterId}`,
|
|
64
|
+
adapterSource,
|
|
65
|
+
HOST_ADAPTER_END,
|
|
66
|
+
].join('\n');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function injectHostAdapter(source: string, hostVersion: string | undefined): string {
|
|
70
|
+
const block = getHostAdapterBlock(hostVersion);
|
|
71
|
+
return HOST_ADAPTER_BLOCK_RE.test(source)
|
|
72
|
+
? source.replace(HOST_ADAPTER_BLOCK_RE, block)
|
|
73
|
+
: source;
|
|
74
|
+
}
|
|
23
75
|
|
|
24
|
-
function
|
|
76
|
+
function injectBuildId(source: string): string {
|
|
77
|
+
const normalized = source.replace(BUILD_ID_ASSIGNMENT_RE, BUILD_ID_TOKEN);
|
|
78
|
+
const buildId = createHash('sha256').update(normalized).digest('hex').slice(0, 12);
|
|
79
|
+
return normalized.replace(BUILD_ID_TOKEN, `buildId: ${JSON.stringify(buildId)}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getOverrideAssetContent(context?: UIExtensionContext): string {
|
|
83
|
+
let source = readFileSync(OVERRIDE_ASSET_URL, 'utf-8');
|
|
84
|
+
const hostVersion = normalizeHostVersion(context?.hostVersion);
|
|
85
|
+
if (hostVersion) {
|
|
86
|
+
source = source.replace(
|
|
87
|
+
"hostVersion: '__OPENCLAW_HOST_VERSION__'",
|
|
88
|
+
`hostVersion: ${JSON.stringify(hostVersion)}`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return injectBuildId(injectHostAdapter(source, hostVersion));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function getOverrideAssetHash(context?: UIExtensionContext): string {
|
|
25
95
|
return createHash('sha256')
|
|
26
|
-
.update(
|
|
96
|
+
.update(getOverrideAssetContent(context))
|
|
27
97
|
.digest('hex')
|
|
28
98
|
.slice(0, 12);
|
|
29
99
|
}
|
|
@@ -109,21 +179,21 @@ const overrideScript: UIExtension = {
|
|
|
109
179
|
version: 1,
|
|
110
180
|
alwaysApply: true,
|
|
111
181
|
|
|
112
|
-
apply(controlUiDir: string): boolean {
|
|
182
|
+
apply(controlUiDir: string, context?: UIExtensionContext): boolean {
|
|
113
183
|
if (!existsSync(OVERRIDE_ASSET_URL)) {
|
|
114
184
|
logger.warn('[ui-ext:regex] override-script: asset missing');
|
|
115
185
|
return false;
|
|
116
186
|
}
|
|
117
187
|
const dest = join(controlUiDir, 'openagent-override.js');
|
|
188
|
+
const srcContent = getOverrideAssetContent(context);
|
|
118
189
|
if (existsSync(dest)) {
|
|
119
|
-
const srcContent = readFileSync(OVERRIDE_ASSET_URL, 'utf-8');
|
|
120
190
|
const destContent = readFileSync(dest, 'utf-8');
|
|
121
191
|
if (srcContent === destContent) {
|
|
122
192
|
logger.debug('[ui-ext:regex] override-script: content unchanged, skip');
|
|
123
193
|
return true;
|
|
124
194
|
}
|
|
125
195
|
}
|
|
126
|
-
|
|
196
|
+
writeFileSync(dest, srcContent, 'utf-8');
|
|
127
197
|
logger.info('[ui-ext:regex] override-script: deployed openagent-override.js');
|
|
128
198
|
|
|
129
199
|
// Deploy icon.png alongside
|
|
@@ -179,7 +249,7 @@ const htmlScriptTag: UIExtension = {
|
|
|
179
249
|
version: 5,
|
|
180
250
|
alwaysApply: true,
|
|
181
251
|
|
|
182
|
-
apply(controlUiDir: string): boolean {
|
|
252
|
+
apply(controlUiDir: string, context?: UIExtensionContext): boolean {
|
|
183
253
|
const indexPath = join(controlUiDir, 'index.html');
|
|
184
254
|
if (!existsSync(indexPath)) {
|
|
185
255
|
logger.warn('[ui-ext:regex] html-script-tag: index.html not found');
|
|
@@ -188,8 +258,10 @@ const htmlScriptTag: UIExtension = {
|
|
|
188
258
|
let html = readFileSync(indexPath, 'utf-8');
|
|
189
259
|
const htmlMarker = `<!--openagent:${this.id}-->`;
|
|
190
260
|
const markerPattern = /(?:\/\*openagent:html-script-tag\*\/|<!--openagent:html-script-tag-->)/;
|
|
191
|
-
const overrideHash = getOverrideAssetHash();
|
|
192
|
-
const
|
|
261
|
+
const overrideHash = getOverrideAssetHash(context);
|
|
262
|
+
const hostVersion = normalizeHostVersion(context?.hostVersion);
|
|
263
|
+
const hostVersionAttr = hostVersion ? ` data-openagent-host-version="${hostVersion}"` : '';
|
|
264
|
+
const scriptTag = `${htmlMarker}<script src="./openagent-override.js?v=${overrideHash}"${hostVersionAttr}></script>`;
|
|
193
265
|
const markedScriptPattern = /(?:\/\*openagent:html-script-tag\*\/|<!--openagent:html-script-tag-->)<script[^>]*openagent-override[^>]*><\/script>\n?\s*/g;
|
|
194
266
|
const oldScriptPattern = /<script[^>]*openagent-override[^>]*><\/script>\n?\s*/g;
|
|
195
267
|
|
|
@@ -37,7 +37,7 @@ export interface UIExtension {
|
|
|
37
37
|
* 接收 control-ui 目录路径,内部自行决定改什么文件、怎么改。
|
|
38
38
|
* 返回 true 表示成功,false 表示失败(不写入 manifest,下次重试)。
|
|
39
39
|
*/
|
|
40
|
-
apply: (controlUiDir: string) => boolean;
|
|
40
|
+
apply: (controlUiDir: string, context?: UIExtensionContext) => boolean;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* 卸载扩展。
|
|
@@ -47,6 +47,10 @@ export interface UIExtension {
|
|
|
47
47
|
revert: (controlUiDir: string) => void;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
export interface UIExtensionContext {
|
|
51
|
+
hostVersion?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
50
54
|
/**
|
|
51
55
|
* OpenAgent 标记前缀,注入的代码旁加此注释以标识修改来源。
|
|
52
56
|
* 格式:/*openagent:<extension-id>* /
|
package/src/state/store.ts
CHANGED
|
@@ -67,6 +67,22 @@ export interface PendingInvocationRecord {
|
|
|
67
67
|
updated_at: number;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* 远程 ServiceAgent 会话续传记录。
|
|
72
|
+
*
|
|
73
|
+
* 一个 OpenClaw 本地会话里,同一个远程 Agent 的第一次 invocation 会返回
|
|
74
|
+
* session_id;后续 mode='session' 的调用应带回这个 session_id,才能保留
|
|
75
|
+
* 远端上下文。account_id + openclaw_session_key + target_agent_id 共同隔离,
|
|
76
|
+
* 避免不同账号、不同本地聊天、不同远程 Agent 之间串 session。
|
|
77
|
+
*/
|
|
78
|
+
export interface RemoteAgentSessionRecord {
|
|
79
|
+
openclaw_session_key: string;
|
|
80
|
+
target_agent_id: string;
|
|
81
|
+
session_id: string;
|
|
82
|
+
created_at: number;
|
|
83
|
+
updated_at: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
70
86
|
interface SqlJsDatabase {
|
|
71
87
|
run(sql: string, params?: unknown[]): void;
|
|
72
88
|
prepare(sql: string): SqlJsStatement;
|
|
@@ -291,6 +307,21 @@ export class StateStore {
|
|
|
291
307
|
CREATE INDEX IF NOT EXISTS idx_pending_invocations_invocation
|
|
292
308
|
ON pending_invocations (account_id, invocation_id)
|
|
293
309
|
`);
|
|
310
|
+
this.db.run(`
|
|
311
|
+
CREATE TABLE IF NOT EXISTS remote_agent_sessions (
|
|
312
|
+
account_id TEXT NOT NULL,
|
|
313
|
+
openclaw_session_key TEXT NOT NULL,
|
|
314
|
+
target_agent_id TEXT NOT NULL,
|
|
315
|
+
session_id TEXT NOT NULL,
|
|
316
|
+
created_at INTEGER NOT NULL DEFAULT 0,
|
|
317
|
+
updated_at INTEGER NOT NULL DEFAULT 0,
|
|
318
|
+
PRIMARY KEY (account_id, openclaw_session_key, target_agent_id)
|
|
319
|
+
)
|
|
320
|
+
`);
|
|
321
|
+
this.db.run(`
|
|
322
|
+
CREATE INDEX IF NOT EXISTS idx_remote_agent_sessions_updated
|
|
323
|
+
ON remote_agent_sessions (account_id, updated_at)
|
|
324
|
+
`);
|
|
294
325
|
}
|
|
295
326
|
|
|
296
327
|
// ── Write to disk ──
|
|
@@ -533,6 +564,55 @@ export class StateStore {
|
|
|
533
564
|
}
|
|
534
565
|
}
|
|
535
566
|
|
|
567
|
+
// ═════════════════════════════════════════════════════════════════
|
|
568
|
+
// OASN remote_agent_sessions CRUD
|
|
569
|
+
//
|
|
570
|
+
// 保存远端 ServiceAgent 返回的 session_id,用于同一 OpenClaw 会话内后续
|
|
571
|
+
// mode='session' 调用续传。run 模式不读写这张表。
|
|
572
|
+
// ═════════════════════════════════════════════════════════════════
|
|
573
|
+
|
|
574
|
+
getRemoteAgentSession(openclawSessionKey: string, targetAgentId: string): string | null {
|
|
575
|
+
if (!this.db) return null;
|
|
576
|
+
const scopeKey = openclawSessionKey.trim();
|
|
577
|
+
const agentId = targetAgentId.trim();
|
|
578
|
+
if (!scopeKey || !agentId) return null;
|
|
579
|
+
|
|
580
|
+
const stmt = this.db.prepare(
|
|
581
|
+
`SELECT session_id
|
|
582
|
+
FROM remote_agent_sessions
|
|
583
|
+
WHERE account_id = ? AND openclaw_session_key = ? AND target_agent_id = ?`,
|
|
584
|
+
);
|
|
585
|
+
stmt.bind([this.accountId, scopeKey, agentId]);
|
|
586
|
+
const row = stmt.step() ? stmt.getAsObject() : null;
|
|
587
|
+
stmt.free();
|
|
588
|
+
const sessionId = row?.['session_id'];
|
|
589
|
+
return typeof sessionId === 'string' && sessionId.trim() ? sessionId : null;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
upsertRemoteAgentSession(record: {
|
|
593
|
+
openclaw_session_key: string;
|
|
594
|
+
target_agent_id: string;
|
|
595
|
+
session_id: string;
|
|
596
|
+
}): void {
|
|
597
|
+
if (!this.db) return;
|
|
598
|
+
const scopeKey = record.openclaw_session_key.trim();
|
|
599
|
+
const agentId = record.target_agent_id.trim();
|
|
600
|
+
const sessionId = record.session_id.trim();
|
|
601
|
+
if (!scopeKey || !agentId || !sessionId) return;
|
|
602
|
+
|
|
603
|
+
const now = Date.now();
|
|
604
|
+
this.db.run(
|
|
605
|
+
`INSERT INTO remote_agent_sessions
|
|
606
|
+
(account_id, openclaw_session_key, target_agent_id, session_id, created_at, updated_at)
|
|
607
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
608
|
+
ON CONFLICT(account_id, openclaw_session_key, target_agent_id) DO UPDATE SET
|
|
609
|
+
session_id = excluded.session_id,
|
|
610
|
+
updated_at = excluded.updated_at`,
|
|
611
|
+
[this.accountId, scopeKey, agentId, sessionId, now, now],
|
|
612
|
+
);
|
|
613
|
+
this.persist();
|
|
614
|
+
}
|
|
615
|
+
|
|
536
616
|
// ═════════════════════════════════════════════════════════════════
|
|
537
617
|
// §11.1 OASN pending_invocations CRUD(OasnInvocation.PendingInvocationStore 适配)
|
|
538
618
|
//
|
|
@@ -407,15 +407,10 @@ export class OasnInvocation {
|
|
|
407
407
|
};
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const message = userError?.message
|
|
415
|
-
?? inlineResult?.summary
|
|
416
|
-
?? visible?.inlineResultSummary
|
|
417
|
-
?? visible?.inline_result_summary
|
|
418
|
-
?? `Invocation ended with status=${final.status}`;
|
|
410
|
+
const message = this._invocationFailureMessage(
|
|
411
|
+
final,
|
|
412
|
+
`Invocation ended with status=${final.status}`,
|
|
413
|
+
);
|
|
419
414
|
return {
|
|
420
415
|
requestId: invocationId,
|
|
421
416
|
status: 'error',
|
|
@@ -450,15 +445,55 @@ export class OasnInvocation {
|
|
|
450
445
|
|
|
451
446
|
/** 终态错误专用 TransportError,便于上层 catch */
|
|
452
447
|
private _terminalError(final: GetInvocationResponse, handle: TaskHandle): TransportError {
|
|
453
|
-
const
|
|
454
|
-
const
|
|
455
|
-
const msg = userError?.message ?? `Invocation ${final.status}`;
|
|
448
|
+
const code = this._invocationFailureCode(final) ?? `INVOCATION_${final.status.toUpperCase()}`;
|
|
449
|
+
const msg = this._invocationFailureMessage(final, `Invocation ${final.status}`);
|
|
456
450
|
return makeTransportError(code, msg, {
|
|
457
451
|
invocationId: handle.invocationId,
|
|
458
452
|
sessionId: handle.sessionId,
|
|
459
453
|
});
|
|
460
454
|
}
|
|
461
455
|
|
|
456
|
+
private _invocationFailureCode(final: GetInvocationResponse): string | undefined {
|
|
457
|
+
return this._firstText(
|
|
458
|
+
final.userError?.code,
|
|
459
|
+
final.user_error?.code,
|
|
460
|
+
final.userErrorCode,
|
|
461
|
+
final.user_error_code,
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
private _invocationFailureMessage(final: GetInvocationResponse, fallback: string): string {
|
|
466
|
+
const userMessage = this._firstText(
|
|
467
|
+
final.userError?.message,
|
|
468
|
+
final.user_error?.message,
|
|
469
|
+
final.userErrorMessage,
|
|
470
|
+
final.user_error_message,
|
|
471
|
+
);
|
|
472
|
+
if (userMessage) return userMessage;
|
|
473
|
+
|
|
474
|
+
const inlineResult = final.inlineResult ?? final.inline_result;
|
|
475
|
+
const visible = final.visibleResult ?? final.visible_result;
|
|
476
|
+
const fallbackMessage = this._firstText(
|
|
477
|
+
inlineResult?.summary,
|
|
478
|
+
visible?.inlineResultSummary,
|
|
479
|
+
visible?.inline_result_summary,
|
|
480
|
+
final.progress?.safeStatusMessage,
|
|
481
|
+
final.progress?.safe_status_message,
|
|
482
|
+
);
|
|
483
|
+
const code = this._invocationFailureCode(final);
|
|
484
|
+
if (fallbackMessage && code && !fallbackMessage.includes(code)) return `${fallbackMessage} (${code})`;
|
|
485
|
+
return fallbackMessage ?? code ?? fallback;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
private _firstText(...values: Array<unknown>): string | undefined {
|
|
489
|
+
for (const value of values) {
|
|
490
|
+
if (typeof value !== 'string') continue;
|
|
491
|
+
const trimmed = value.trim();
|
|
492
|
+
if (trimmed) return trimmed;
|
|
493
|
+
}
|
|
494
|
+
return undefined;
|
|
495
|
+
}
|
|
496
|
+
|
|
462
497
|
private _toArtifactRef(art: ArtifactResponse): ArtifactRef {
|
|
463
498
|
return {
|
|
464
499
|
id: art.artifactId ?? art.artifact_id ?? '',
|
|
@@ -316,8 +316,12 @@ export interface GetInvocationResponse {
|
|
|
316
316
|
nextPollAfterMs?: number | null;
|
|
317
317
|
next_poll_after_ms?: number | null;
|
|
318
318
|
warnings?: string[];
|
|
319
|
-
userError?: { code
|
|
320
|
-
user_error?: { code
|
|
319
|
+
userError?: { code?: string; message?: string | null };
|
|
320
|
+
user_error?: { code?: string; message?: string | null };
|
|
321
|
+
userErrorCode?: string;
|
|
322
|
+
user_error_code?: string;
|
|
323
|
+
userErrorMessage?: string | null;
|
|
324
|
+
user_error_message?: string | null;
|
|
321
325
|
createdAt?: string;
|
|
322
326
|
created_at?: string;
|
|
323
327
|
updatedAt?: string;
|