@blade-hq/agent-client 2610.0.0-beta.36 → 2610.0.0-beta.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -4
- package/dist/auth.d.ts +0 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +73 -72
- package/dist/index.js.map +1 -1
- package/dist/resources/computers.d.ts +24 -2
- package/dist/schemas/session.d.ts +4 -0
- package/dist/shared/type-guards.d.ts +2 -0
- package/package.json +1 -1
- package/public-api.md +29 -1
package/README.md
CHANGED
|
@@ -316,13 +316,30 @@ await client.computers.setEnabled(sessionId, computer.id, false) // 停用
|
|
|
316
316
|
做电脑选择器时用这几个纯函数,别自己重算状态:
|
|
317
317
|
|
|
318
318
|
```ts
|
|
319
|
-
import {
|
|
319
|
+
import {
|
|
320
|
+
canToggleComputer, computerState, sortComputers,
|
|
321
|
+
computerOS, computerPlatformLabel, computerDaemonVersion,
|
|
322
|
+
} from "@blade-hq/agent-client"
|
|
323
|
+
|
|
324
|
+
sortComputers(computers) // 按接入时间,顺序稳定不随状态变化
|
|
325
|
+
computerState(computer) // ComputerState: "primary" | "enabled" | "offline" | "idle"
|
|
326
|
+
canToggleComputer(computer) // 主运行时返回 false
|
|
320
327
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
328
|
+
computerOS(computer) // ComputerOS: "macos" | "windows" | "linux" | "unknown"
|
|
329
|
+
computerPlatformLabel(computer) // "darwin/arm64"
|
|
330
|
+
computerDaemonVersion(computer) // "dev (bc3ad71d1)",未知时是空串
|
|
324
331
|
```
|
|
325
332
|
|
|
333
|
+
`sortComputers` **刻意不按在线/可用排序**:那样排看着"手边的在前面",代价是电脑
|
|
334
|
+
上下线、勾选状态一变整个列表就重排,用户正要点的那一项会在手指底下跑掉。改名也
|
|
335
|
+
不会挪位置,新接入的稳定排在末尾。
|
|
336
|
+
|
|
337
|
+
`computerOS` 判定的是 daemon 上报的 `runtime.GOOS`,各处自己 `startsWith` 一遍必然会分叉;
|
|
338
|
+
图标怎么画交给界面,这里只回答"是哪一类系统"。
|
|
339
|
+
|
|
340
|
+
`computerDaemonVersion` 返回的是服务端存的完整串——dev 构建带 commit,
|
|
341
|
+
因为 dev 的版本号全都是 `dev`,光看它分不出是哪次构建的二进制。**不要在前端另拼一套格式。**
|
|
342
|
+
|
|
326
343
|
`ComputersResource` 是 `client.computers` 的类型。
|
|
327
344
|
|
|
328
345
|
## AgentSession
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export interface AuthOptions {
|
|
2
2
|
token?: string | (() => string | null | undefined);
|
|
3
3
|
}
|
|
4
|
-
export declare function buildAuthHeaders(options: AuthOptions): Record<string, string>;
|
|
5
4
|
export declare function buildSocketAuth(options: AuthOptions): {
|
|
6
5
|
token: string;
|
|
7
6
|
} | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -22,8 +22,8 @@ export { isCommandEnvelope, isInboundEnvelope } from "./commands/protocol";
|
|
|
22
22
|
export type { AuthResource, ExchangeCodeParams, ExchangeCodeResult, ProvidersResponse, UserInfo, } from "./resources/auth";
|
|
23
23
|
export type { HeadlessResource } from "./resources/headless";
|
|
24
24
|
export { ComputersResource } from "./resources/computers";
|
|
25
|
-
export { canToggleComputer, computerState, sortComputers, } from "./resources/computers";
|
|
26
|
-
export type { ComputerState, SessionComputer, SessionComputerList, } from "./resources/computers";
|
|
25
|
+
export { canToggleComputer, computerDaemonVersion, computerOS, computerPlatformLabel, computerState, sortComputers, } from "./resources/computers";
|
|
26
|
+
export type { ComputerOS, ComputerState, SessionComputer, SessionComputerList, } from "./resources/computers";
|
|
27
27
|
export { ModelsResource } from "./resources/models";
|
|
28
28
|
export type { ModelCatalog, ModelOption } from "./resources/models";
|
|
29
29
|
export type { SessionsResource } from "./resources/sessions";
|
package/dist/index.js
CHANGED
|
@@ -214,6 +214,11 @@ var AuthResource = class {
|
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
216
|
|
|
217
|
+
// src/shared/type-guards.ts
|
|
218
|
+
function isRecord(value) {
|
|
219
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
220
|
+
}
|
|
221
|
+
|
|
217
222
|
// src/resources/headless.ts
|
|
218
223
|
var HeadlessError = class extends Error {
|
|
219
224
|
constructor(message, detail) {
|
|
@@ -394,9 +399,6 @@ function errorMessageFromResult(result) {
|
|
|
394
399
|
}
|
|
395
400
|
return null;
|
|
396
401
|
}
|
|
397
|
-
function isRecord(value) {
|
|
398
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
399
|
-
}
|
|
400
402
|
function ensureSocketConnected(socket, timeoutMs, detail) {
|
|
401
403
|
if (socket.connected) {
|
|
402
404
|
return Promise.resolve();
|
|
@@ -430,13 +432,29 @@ function computerState(computer) {
|
|
|
430
432
|
if (computer.enabled) return "enabled";
|
|
431
433
|
return computer.online ? "idle" : "offline";
|
|
432
434
|
}
|
|
435
|
+
function computerOS(computer) {
|
|
436
|
+
const os = (computer.os ?? "").toLowerCase();
|
|
437
|
+
if (os.startsWith("darwin") || os.startsWith("mac")) return "macos";
|
|
438
|
+
if (os.startsWith("windows")) return "windows";
|
|
439
|
+
if (os.startsWith("linux")) return "linux";
|
|
440
|
+
return "unknown";
|
|
441
|
+
}
|
|
442
|
+
function computerPlatformLabel(computer) {
|
|
443
|
+
const os = (computer.os ?? "").trim();
|
|
444
|
+
const arch = (computer.arch ?? "").trim();
|
|
445
|
+
if (os && arch) return `${os}/${arch}`;
|
|
446
|
+
return os || arch || "";
|
|
447
|
+
}
|
|
448
|
+
function computerDaemonVersion(computer) {
|
|
449
|
+
return (computer.daemon_version ?? "").trim();
|
|
450
|
+
}
|
|
433
451
|
function canToggleComputer(computer) {
|
|
434
452
|
return !computer.is_primary;
|
|
435
453
|
}
|
|
436
454
|
function sortComputers(computers) {
|
|
437
455
|
return [...computers].sort((a, b) => {
|
|
438
|
-
|
|
439
|
-
if (
|
|
456
|
+
const byCreated = (a.created_at ?? "").localeCompare(b.created_at ?? "");
|
|
457
|
+
if (byCreated !== 0) return byCreated;
|
|
440
458
|
return a.label.localeCompare(b.label);
|
|
441
459
|
});
|
|
442
460
|
}
|
|
@@ -518,6 +536,8 @@ var SessionInfo = type({
|
|
|
518
536
|
"daemon_id?": "string | null",
|
|
519
537
|
"agent_runtime_id?": "string | null",
|
|
520
538
|
"workspace_path?": "string | null",
|
|
539
|
+
"ba_version?": "string | null",
|
|
540
|
+
"sandbox_version?": "string | null",
|
|
521
541
|
"match?": "unknown"
|
|
522
542
|
});
|
|
523
543
|
|
|
@@ -1160,15 +1180,12 @@ function getContextGroupDisplayState(contexts) {
|
|
|
1160
1180
|
}
|
|
1161
1181
|
|
|
1162
1182
|
// src/shared/projection/context.ts
|
|
1163
|
-
function isRecord2(value) {
|
|
1164
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1165
|
-
}
|
|
1166
1183
|
function buildContextTurn(entry, sequence) {
|
|
1167
|
-
if (entry.kind !== "context" || !
|
|
1184
|
+
if (entry.kind !== "context" || !isRecord(entry.source) || !isRecord(entry.data)) {
|
|
1168
1185
|
return null;
|
|
1169
1186
|
}
|
|
1170
|
-
const display =
|
|
1171
|
-
const message =
|
|
1187
|
+
const display = isRecord(entry.data.display) ? entry.data.display : {};
|
|
1188
|
+
const message = isRecord(entry.message) ? entry.message : {};
|
|
1172
1189
|
const context = contextProjectionData({
|
|
1173
1190
|
context_kind: typeof entry.source.kind === "string" ? entry.source.kind : null,
|
|
1174
1191
|
context_key: typeof entry.source.key === "string" ? entry.source.key : null,
|
|
@@ -1178,7 +1195,7 @@ function buildContextTurn(entry, sequence) {
|
|
|
1178
1195
|
context_revision: typeof entry.data.revision === "string" ? entry.data.revision : null,
|
|
1179
1196
|
display_title: typeof display.title === "string" ? display.title : null,
|
|
1180
1197
|
display_summary: typeof display.summary === "string" ? display.summary : null,
|
|
1181
|
-
sources: Array.isArray(display.sources) ? display.sources.filter(
|
|
1198
|
+
sources: Array.isArray(display.sources) ? display.sources.filter(isRecord) : []
|
|
1182
1199
|
});
|
|
1183
1200
|
if (!context) return null;
|
|
1184
1201
|
const turnId = typeof entry.id === "string" && entry.id ? entry.id : `context-${sequence}`;
|
|
@@ -1477,7 +1494,7 @@ var ClientProjectionBuilder = class {
|
|
|
1477
1494
|
return null;
|
|
1478
1495
|
}
|
|
1479
1496
|
onContextEntry(payload) {
|
|
1480
|
-
if (!
|
|
1497
|
+
if (!isRecord(payload.entry)) return null;
|
|
1481
1498
|
const turn = buildContextTurn(payload.entry, this.nextSeq());
|
|
1482
1499
|
return turn ? [{ kind: "upsert", turn }] : null;
|
|
1483
1500
|
}
|
|
@@ -1538,11 +1555,11 @@ var ClientProjectionBuilder = class {
|
|
|
1538
1555
|
loopId,
|
|
1539
1556
|
toolCallId: optStr(payload.tool_call_id) ?? void 0,
|
|
1540
1557
|
toolName: toolNameFromPayload(payload) ?? void 0,
|
|
1541
|
-
workspacePath:
|
|
1558
|
+
workspacePath: isRecord(payload.workspace_change) ? optStr(payload.workspace_change.to) ?? void 0 : void 0
|
|
1542
1559
|
}
|
|
1543
1560
|
];
|
|
1544
1561
|
const change = payload.workspace_change;
|
|
1545
|
-
if (
|
|
1562
|
+
if (isRecord(change)) {
|
|
1546
1563
|
const source = optStr(change.source) ?? "";
|
|
1547
1564
|
const projectName = optStr(change.project_name) ?? "";
|
|
1548
1565
|
const fromPath = optStr(change.from) ?? "";
|
|
@@ -1638,7 +1655,7 @@ var ClientProjectionBuilder = class {
|
|
|
1638
1655
|
const updates = this.collectLoopUpdates(loopId, parentLoopId);
|
|
1639
1656
|
const entryId = typeof payload.entry_id === "string" ? payload.entry_id : "";
|
|
1640
1657
|
if (!entryId) return updates;
|
|
1641
|
-
const answerData =
|
|
1658
|
+
const answerData = isRecord(payload.answer_data) ? payload.answer_data : {};
|
|
1642
1659
|
const answerTurn = {
|
|
1643
1660
|
id: entryId,
|
|
1644
1661
|
sequence: this.nextSeq(),
|
|
@@ -2065,9 +2082,6 @@ var ClientProjectionBuilder = class {
|
|
|
2065
2082
|
return `${prefix}:${this.syntheticCounter}:${hex}`;
|
|
2066
2083
|
}
|
|
2067
2084
|
};
|
|
2068
|
-
function isRecord3(value) {
|
|
2069
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2070
|
-
}
|
|
2071
2085
|
function optStr(value) {
|
|
2072
2086
|
if (value == null || value === "") return null;
|
|
2073
2087
|
return String(value);
|
|
@@ -2103,14 +2117,14 @@ function projectHistory(entries) {
|
|
|
2103
2117
|
const kind = String(entry.kind ?? "");
|
|
2104
2118
|
const loopId = String(entry.loop_name ?? "root");
|
|
2105
2119
|
const id = String(entry.id ?? `history-${sequence + 1}`);
|
|
2106
|
-
if (kind === "turn_timing" &&
|
|
2120
|
+
if (kind === "turn_timing" && isRecord(entry.data)) {
|
|
2107
2121
|
const turnId = typeof entry.data.turn_id === "string" ? entry.data.turn_id : "";
|
|
2108
2122
|
const duration = numberOrNull(entry.data.first_token_delivery_ms);
|
|
2109
2123
|
const target = turnEntryAliases.get(turnId);
|
|
2110
2124
|
if (target && duration !== null) target.first_token_delivery_ms = duration;
|
|
2111
2125
|
continue;
|
|
2112
2126
|
}
|
|
2113
|
-
if (kind === "post_chat_followup" &&
|
|
2127
|
+
if (kind === "post_chat_followup" && isRecord(entry.data)) {
|
|
2114
2128
|
const assistantEntryId = String(entry.data.assistant_entry_id ?? "");
|
|
2115
2129
|
if (latestRootMessage?.role === "assistant" && latestRootMessage.turn_id === assistantEntryId) {
|
|
2116
2130
|
const followup = normalizePostChatFollowup(entry.data, assistantEntryId);
|
|
@@ -2126,7 +2140,7 @@ function projectHistory(entries) {
|
|
|
2126
2140
|
}
|
|
2127
2141
|
continue;
|
|
2128
2142
|
}
|
|
2129
|
-
if (kind === "message" &&
|
|
2143
|
+
if (kind === "message" && isRecord(entry.message)) {
|
|
2130
2144
|
const message = entry.message;
|
|
2131
2145
|
const role = String(message.role ?? "");
|
|
2132
2146
|
if (role === "tool") {
|
|
@@ -2161,7 +2175,7 @@ function projectHistory(entries) {
|
|
|
2161
2175
|
blocks,
|
|
2162
2176
|
tool_calls: toolCalls,
|
|
2163
2177
|
model: stringOrNull(message.model),
|
|
2164
|
-
usage:
|
|
2178
|
+
usage: isRecord(message._usage) ? { ...message._usage } : null,
|
|
2165
2179
|
duration_ms: numberOrZero(message._duration_ms),
|
|
2166
2180
|
first_token_ms: numberOrNull(message._first_token_ms),
|
|
2167
2181
|
stream_duration_ms: numberOrNull(message._stream_duration_ms),
|
|
@@ -2172,7 +2186,7 @@ function projectHistory(entries) {
|
|
|
2172
2186
|
parent_fork_tool_call_id: stringOrNull(message._parent_fork_tool_call_id)
|
|
2173
2187
|
};
|
|
2174
2188
|
const isNativeToolEntry = role === "assistant" && Array.isArray(message.tool_calls) && message.tool_calls.some(
|
|
2175
|
-
(toolCall) =>
|
|
2189
|
+
(toolCall) => isRecord(toolCall) && typeof toolCall.provider === "string"
|
|
2176
2190
|
);
|
|
2177
2191
|
const previousTurn = turns[turns.length - 1];
|
|
2178
2192
|
if (role === "assistant" && previousTurn?.role === "assistant" && previousTurn.loop_id === loopId && nativeToolTurns.has(previousTurn)) {
|
|
@@ -2226,7 +2240,7 @@ function projectHistory(entries) {
|
|
|
2226
2240
|
if (kind === "mode_change") {
|
|
2227
2241
|
turns.push(markerTurn(id, ++sequence, loopId, "mode_change", entry.data ?? {}));
|
|
2228
2242
|
} else if (kind === "workspace_change") {
|
|
2229
|
-
const change =
|
|
2243
|
+
const change = isRecord(entry.data) ? entry.data : {};
|
|
2230
2244
|
const source = stringOrNull(change.source) ?? "";
|
|
2231
2245
|
const projectName = stringOrNull(change.project_name) ?? "";
|
|
2232
2246
|
const fromPath = stringOrNull(change.from) ?? "";
|
|
@@ -2268,7 +2282,7 @@ function projectHistory(entries) {
|
|
|
2268
2282
|
} else if (kind === "compaction" || kind === "tool_result_archive") {
|
|
2269
2283
|
const data = entry.data ?? {};
|
|
2270
2284
|
const compactionId = String(data.compaction_id ?? entry.id ?? `history-${sequence + 1}`);
|
|
2271
|
-
let content =
|
|
2285
|
+
let content = isRecord(entry.message) ? entry.message.content : void 0;
|
|
2272
2286
|
if (kind === "tool_result_archive") {
|
|
2273
2287
|
const archivedCount = Array.isArray(data.archived_files) ? data.archived_files.length : 0;
|
|
2274
2288
|
content = `<compaction-summary>
|
|
@@ -2283,11 +2297,11 @@ function projectHistory(entries) {
|
|
|
2283
2297
|
);
|
|
2284
2298
|
} else if (kind === "child_pause") {
|
|
2285
2299
|
const data = entry.data ?? {};
|
|
2286
|
-
const sourceLoop =
|
|
2300
|
+
const sourceLoop = isRecord(data.source_loop) ? data.source_loop : {};
|
|
2287
2301
|
const childLoopId = String(data.child_loop_name ?? sourceLoop.name ?? "");
|
|
2288
2302
|
const childToolCallId = String(data.child_pause_tool_call_id ?? "");
|
|
2289
2303
|
const parentToolCallId = String(data.parent_fork_tool_call_id ?? "");
|
|
2290
|
-
const pauseToolData =
|
|
2304
|
+
const pauseToolData = isRecord(data.pause_tool_data) ? data.pause_tool_data : {};
|
|
2291
2305
|
const description = String(sourceLoop.description ?? "");
|
|
2292
2306
|
applyAskUserPauseToTurn(
|
|
2293
2307
|
latestAssistantByLoop.get(childLoopId),
|
|
@@ -2375,15 +2389,15 @@ function parseToolArguments(value) {
|
|
|
2375
2389
|
if (!value) return {};
|
|
2376
2390
|
try {
|
|
2377
2391
|
const parsed = JSON.parse(value);
|
|
2378
|
-
return
|
|
2392
|
+
return isRecord(parsed) ? parsed : {};
|
|
2379
2393
|
} catch {
|
|
2380
2394
|
return {};
|
|
2381
2395
|
}
|
|
2382
2396
|
}
|
|
2383
2397
|
function buildToolCalls(value) {
|
|
2384
2398
|
if (!Array.isArray(value)) return [];
|
|
2385
|
-
return value.filter(
|
|
2386
|
-
const fn =
|
|
2399
|
+
return value.filter(isRecord).map((raw) => {
|
|
2400
|
+
const fn = isRecord(raw.function) ? raw.function : {};
|
|
2387
2401
|
const name = String(fn.name ?? "");
|
|
2388
2402
|
return {
|
|
2389
2403
|
id: String(raw.id ?? ""),
|
|
@@ -2404,7 +2418,7 @@ function buildBlocks(message, toolCalls) {
|
|
|
2404
2418
|
blocks.push({ type: "text", content: displayContent });
|
|
2405
2419
|
} else if (Array.isArray(stored)) {
|
|
2406
2420
|
for (const raw of stored) {
|
|
2407
|
-
if (!
|
|
2421
|
+
if (!isRecord(raw)) continue;
|
|
2408
2422
|
const type3 = String(raw.type ?? "");
|
|
2409
2423
|
if (type3 === "thinking") blocks.push({ type: type3, content: raw.thinking ?? raw.content ?? "" });
|
|
2410
2424
|
if (type3 === "text") blocks.push({ type: type3, content: raw.text ?? raw.content ?? "" });
|
|
@@ -2453,9 +2467,6 @@ function markerTurn(id, sequence, loopId, type3, content, toolCallId = null) {
|
|
|
2453
2467
|
duration_ms: 0
|
|
2454
2468
|
};
|
|
2455
2469
|
}
|
|
2456
|
-
function isRecord4(value) {
|
|
2457
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2458
|
-
}
|
|
2459
2470
|
function stringOrNull(value) {
|
|
2460
2471
|
return typeof value === "string" ? value : null;
|
|
2461
2472
|
}
|
|
@@ -2499,7 +2510,6 @@ function toCreateSessionPayload(request) {
|
|
|
2499
2510
|
var builtinSolutionIds = /* @__PURE__ */ new Set([
|
|
2500
2511
|
"app-dev",
|
|
2501
2512
|
"general_chat",
|
|
2502
|
-
"multica",
|
|
2503
2513
|
"night_build",
|
|
2504
2514
|
"skill_editor",
|
|
2505
2515
|
"smart_bid",
|
|
@@ -3385,10 +3395,10 @@ function inferLoopStatusFromMessages(messages) {
|
|
|
3385
3395
|
}
|
|
3386
3396
|
function inferLoopStatusFromTurns(turns, messages) {
|
|
3387
3397
|
const latestAgentNotification = [...turns].reverse().flatMap((turn) => turn.blocks).find((block) => {
|
|
3388
|
-
if (block.type !== "system_notification" || !
|
|
3398
|
+
if (block.type !== "system_notification" || !isRecord(block.content)) return false;
|
|
3389
3399
|
return block.content.notification_type === "agent:start" || block.content.notification_type === "agent:end";
|
|
3390
3400
|
});
|
|
3391
|
-
if (latestAgentNotification?.type === "system_notification" &&
|
|
3401
|
+
if (latestAgentNotification?.type === "system_notification" && isRecord(latestAgentNotification.content)) {
|
|
3392
3402
|
const notificationType = latestAgentNotification.content.notification_type;
|
|
3393
3403
|
const status = latestAgentNotification.content.status;
|
|
3394
3404
|
if (notificationType === "agent:start" || status === "running") return "running";
|
|
@@ -3397,11 +3407,8 @@ function inferLoopStatusFromTurns(turns, messages) {
|
|
|
3397
3407
|
}
|
|
3398
3408
|
return inferLoopStatusFromMessages(messages);
|
|
3399
3409
|
}
|
|
3400
|
-
function isRecord5(value) {
|
|
3401
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3402
|
-
}
|
|
3403
3410
|
function toSelectionMap(value) {
|
|
3404
|
-
if (!
|
|
3411
|
+
if (!isRecord(value)) return {};
|
|
3405
3412
|
const entries = Object.entries(value).map(([questionKey, optionIndexes]) => {
|
|
3406
3413
|
if (!Array.isArray(optionIndexes)) return null;
|
|
3407
3414
|
const parsedIndexes = optionIndexes.map((item) => typeof item === "number" ? item : Number(item)).filter((item) => Number.isInteger(item));
|
|
@@ -3410,7 +3417,7 @@ function toSelectionMap(value) {
|
|
|
3410
3417
|
return Object.fromEntries(entries);
|
|
3411
3418
|
}
|
|
3412
3419
|
function toCustomMap(value) {
|
|
3413
|
-
if (!
|
|
3420
|
+
if (!isRecord(value)) return {};
|
|
3414
3421
|
const entries = Object.entries(value).filter(([, text]) => typeof text === "string").map(([questionKey, text]) => [Number(questionKey), text]);
|
|
3415
3422
|
return Object.fromEntries(entries);
|
|
3416
3423
|
}
|
|
@@ -3419,7 +3426,7 @@ function extractAskAnswers(turns) {
|
|
|
3419
3426
|
for (const turn of turns) {
|
|
3420
3427
|
for (const block of turn.blocks) {
|
|
3421
3428
|
if (block.type !== "ask_user_answer" || typeof block.tool_call_id !== "string") continue;
|
|
3422
|
-
if (!
|
|
3429
|
+
if (!isRecord(block.content)) continue;
|
|
3423
3430
|
const note = typeof block.content.note === "string" ? block.content.note.trim() : "";
|
|
3424
3431
|
answers[block.tool_call_id] = {
|
|
3425
3432
|
selections: toSelectionMap(block.content.selections),
|
|
@@ -3435,9 +3442,9 @@ function parentForkToolCallIdFromTurn(turn) {
|
|
|
3435
3442
|
return turn.parent_fork_tool_call_id;
|
|
3436
3443
|
}
|
|
3437
3444
|
for (const block of turn.blocks) {
|
|
3438
|
-
if (block.type !== "system_notification" || !
|
|
3445
|
+
if (block.type !== "system_notification" || !isRecord(block.content)) continue;
|
|
3439
3446
|
const metadata = block.content.metadata;
|
|
3440
|
-
if (!
|
|
3447
|
+
if (!isRecord(metadata)) continue;
|
|
3441
3448
|
const parentId = metadata.parent_fork_tool_call_id;
|
|
3442
3449
|
if (typeof parentId === "string" && parentId.length > 0) return parentId;
|
|
3443
3450
|
}
|
|
@@ -3454,16 +3461,16 @@ function buildMessageContent2(turn) {
|
|
|
3454
3461
|
}
|
|
3455
3462
|
function workspaceNotificationContent(turn) {
|
|
3456
3463
|
const block = turn.blocks.find(
|
|
3457
|
-
(candidate) => candidate.type === "system_notification" &&
|
|
3464
|
+
(candidate) => candidate.type === "system_notification" && isRecord(candidate.content) && candidate.content.notification_type === "workspace_change"
|
|
3458
3465
|
);
|
|
3459
|
-
if (!block || !
|
|
3466
|
+
if (!block || !isRecord(block.content)) return "";
|
|
3460
3467
|
const title = typeof block.content.title === "string" ? block.content.title.trim() : "";
|
|
3461
3468
|
const detail = typeof block.content.detail === "string" ? block.content.detail.trim() : "";
|
|
3462
3469
|
return [title ? `**${title}**` : "", detail].filter(Boolean).join("\n\n");
|
|
3463
3470
|
}
|
|
3464
3471
|
function askUserAnswerContent(turn) {
|
|
3465
3472
|
const answerBlock = turn.blocks.find((block) => block.type === "ask_user_answer");
|
|
3466
|
-
if (!answerBlock || !
|
|
3473
|
+
if (!answerBlock || !isRecord(answerBlock.content)) return null;
|
|
3467
3474
|
const answer = answerBlock.content.answer;
|
|
3468
3475
|
return typeof answer === "string" && answer.trim().length > 0 ? answer : null;
|
|
3469
3476
|
}
|
|
@@ -3853,18 +3860,15 @@ function createClientRequestId() {
|
|
|
3853
3860
|
return `${Date.now()}-${Math.random().toString(36).slice(2)}-${fallbackRequestCounter}`;
|
|
3854
3861
|
}
|
|
3855
3862
|
var OOM_KEYWORDS_RE = /(?:\b(?:exit_code|ExitedWith|exited with)|退出码)\D*(?<!\d)137(?!\d)/i;
|
|
3856
|
-
function isRecord6(value) {
|
|
3857
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3858
|
-
}
|
|
3859
3863
|
function isOomText(value) {
|
|
3860
3864
|
return typeof value === "string" && OOM_KEYWORDS_RE.test(value);
|
|
3861
3865
|
}
|
|
3862
3866
|
function parseJsonRecord(value) {
|
|
3863
|
-
if (
|
|
3867
|
+
if (isRecord(value)) return value;
|
|
3864
3868
|
if (typeof value !== "string") return null;
|
|
3865
3869
|
try {
|
|
3866
3870
|
const parsed = JSON.parse(value);
|
|
3867
|
-
return
|
|
3871
|
+
return isRecord(parsed) ? parsed : null;
|
|
3868
3872
|
} catch {
|
|
3869
3873
|
return null;
|
|
3870
3874
|
}
|
|
@@ -3912,7 +3916,7 @@ function extractTerminalChatEndStatus(events) {
|
|
|
3912
3916
|
return null;
|
|
3913
3917
|
}
|
|
3914
3918
|
function isUiMetaLike(value) {
|
|
3915
|
-
return
|
|
3919
|
+
return isRecord(value) && ("resourceHTML" in value || "resourceUri" in value || "resourceURI" in value);
|
|
3916
3920
|
}
|
|
3917
3921
|
var AgentSession = class _AgentSession {
|
|
3918
3922
|
sessionId;
|
|
@@ -4140,7 +4144,7 @@ var AgentSession = class _AgentSession {
|
|
|
4140
4144
|
if (this.getAppContext) {
|
|
4141
4145
|
try {
|
|
4142
4146
|
const rawContext = await this.getAppContext();
|
|
4143
|
-
if (!
|
|
4147
|
+
if (!isRecord(rawContext)) {
|
|
4144
4148
|
throw new Error("getContext \u5FC5\u987B\u8FD4\u56DE JSON \u5BF9\u8C61");
|
|
4145
4149
|
}
|
|
4146
4150
|
const serialized = JSON.stringify(rawContext);
|
|
@@ -4148,7 +4152,7 @@ var AgentSession = class _AgentSession {
|
|
|
4148
4152
|
throw new Error("getContext \u5FC5\u987B\u8FD4\u56DE\u53EF\u5E8F\u5217\u5316\u7684 JSON \u5BF9\u8C61");
|
|
4149
4153
|
}
|
|
4150
4154
|
const normalized = JSON.parse(serialized);
|
|
4151
|
-
if (!
|
|
4155
|
+
if (!isRecord(normalized)) {
|
|
4152
4156
|
throw new Error("getContext \u5FC5\u987B\u8FD4\u56DE JSON \u5BF9\u8C61");
|
|
4153
4157
|
}
|
|
4154
4158
|
appContext = normalized;
|
|
@@ -4619,9 +4623,9 @@ ${text}` } : block
|
|
|
4619
4623
|
detail,
|
|
4620
4624
|
status,
|
|
4621
4625
|
loopId,
|
|
4622
|
-
metadata:
|
|
4626
|
+
metadata: isRecord(notification.metadata) ? notification.metadata : void 0
|
|
4623
4627
|
});
|
|
4624
|
-
if (notificationType === "bg:started" &&
|
|
4628
|
+
if (notificationType === "bg:started" && isRecord(notification.metadata)) {
|
|
4625
4629
|
const taskId = typeof notification.metadata.task_id === "string" ? notification.metadata.task_id : "";
|
|
4626
4630
|
if (taskId) {
|
|
4627
4631
|
this.emitter.emit("backgroundTask", {
|
|
@@ -4777,7 +4781,7 @@ ${text}` } : block
|
|
|
4777
4781
|
title: ui.title ?? "\u5DE5\u5177\u9884\u89C8"
|
|
4778
4782
|
});
|
|
4779
4783
|
}
|
|
4780
|
-
if (block.type === "system_notification" &&
|
|
4784
|
+
if (block.type === "system_notification" && isRecord(block.content)) {
|
|
4781
4785
|
this._handleSystemNotification(turn.loop_id, block.content);
|
|
4782
4786
|
}
|
|
4783
4787
|
}
|
|
@@ -5402,21 +5406,14 @@ function resolveAuthToken(options) {
|
|
|
5402
5406
|
return token ? token : null;
|
|
5403
5407
|
}
|
|
5404
5408
|
|
|
5405
|
-
// src/version.ts
|
|
5406
|
-
var SDK_NAME = "agent-client";
|
|
5407
|
-
var SDK_VERSION = true ? "2610.0.0-beta.36" : "1.1.1";
|
|
5408
|
-
|
|
5409
5409
|
// src/socket.ts
|
|
5410
|
-
function withSdkIdentity(auth) {
|
|
5411
|
-
return { ...auth ?? {}, sdk: SDK_NAME, sdk_version: SDK_VERSION };
|
|
5412
|
-
}
|
|
5413
5410
|
function createSocket(options) {
|
|
5414
5411
|
const token = resolveAuthToken(options);
|
|
5415
5412
|
return io(options.baseUrl, {
|
|
5416
5413
|
path: options.path ?? "/socket.io",
|
|
5417
5414
|
withCredentials: true,
|
|
5418
5415
|
query: token ? { token } : void 0,
|
|
5419
|
-
auth: typeof options.token === "function" ? (cb) => cb(
|
|
5416
|
+
auth: typeof options.token === "function" ? (cb) => cb(buildSocketAuth(options) ?? {}) : buildSocketAuth(options) ?? {},
|
|
5420
5417
|
autoConnect: false
|
|
5421
5418
|
});
|
|
5422
5419
|
}
|
|
@@ -5818,9 +5815,6 @@ function defaultDocumentBaseUrl() {
|
|
|
5818
5815
|
if (typeof location !== "undefined" && location.origin) return `${location.origin}/`;
|
|
5819
5816
|
return document.baseURI;
|
|
5820
5817
|
}
|
|
5821
|
-
function isRecord7(value) {
|
|
5822
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5823
|
-
}
|
|
5824
5818
|
function normalizeServiceUrl(value) {
|
|
5825
5819
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
5826
5820
|
if (value.includes("?") || value.includes("#")) return null;
|
|
@@ -5834,7 +5828,7 @@ function normalizeServiceUrl(value) {
|
|
|
5834
5828
|
}
|
|
5835
5829
|
}
|
|
5836
5830
|
function parsePlatformEndpoints(value) {
|
|
5837
|
-
if (!
|
|
5831
|
+
if (!isRecord(value) || !isRecord(value.services)) return null;
|
|
5838
5832
|
const services = {};
|
|
5839
5833
|
for (const name of PLATFORM_SERVICE_NAMES) {
|
|
5840
5834
|
if (!(name in value.services)) continue;
|
|
@@ -5882,6 +5876,10 @@ function resolveServiceUrl(endpoints, name, path = "") {
|
|
|
5882
5876
|
return target.toString();
|
|
5883
5877
|
}
|
|
5884
5878
|
|
|
5879
|
+
// src/version.ts
|
|
5880
|
+
var SDK_NAME = "agent-client";
|
|
5881
|
+
var SDK_VERSION = true ? "2610.0.0-beta.38" : "1.1.1";
|
|
5882
|
+
|
|
5885
5883
|
// src/commands/protocol.ts
|
|
5886
5884
|
function isCommandEnvelope(value) {
|
|
5887
5885
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -6003,6 +6001,9 @@ export {
|
|
|
6003
6001
|
buildMessageContent,
|
|
6004
6002
|
canToggleComputer,
|
|
6005
6003
|
chatErrorForDisplay,
|
|
6004
|
+
computerDaemonVersion,
|
|
6005
|
+
computerOS,
|
|
6006
|
+
computerPlatformLabel,
|
|
6006
6007
|
computerState,
|
|
6007
6008
|
connectEmbedded,
|
|
6008
6009
|
contentPreview,
|