@blade-hq/agent-client 2610.0.0-beta.37 → 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/dist/auth.d.ts +0 -1
- package/dist/index.js +52 -69
- package/dist/index.js.map +1 -1
- 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 +4 -0
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.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();
|
|
@@ -534,6 +536,8 @@ var SessionInfo = type({
|
|
|
534
536
|
"daemon_id?": "string | null",
|
|
535
537
|
"agent_runtime_id?": "string | null",
|
|
536
538
|
"workspace_path?": "string | null",
|
|
539
|
+
"ba_version?": "string | null",
|
|
540
|
+
"sandbox_version?": "string | null",
|
|
537
541
|
"match?": "unknown"
|
|
538
542
|
});
|
|
539
543
|
|
|
@@ -1176,15 +1180,12 @@ function getContextGroupDisplayState(contexts) {
|
|
|
1176
1180
|
}
|
|
1177
1181
|
|
|
1178
1182
|
// src/shared/projection/context.ts
|
|
1179
|
-
function isRecord2(value) {
|
|
1180
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1181
|
-
}
|
|
1182
1183
|
function buildContextTurn(entry, sequence) {
|
|
1183
|
-
if (entry.kind !== "context" || !
|
|
1184
|
+
if (entry.kind !== "context" || !isRecord(entry.source) || !isRecord(entry.data)) {
|
|
1184
1185
|
return null;
|
|
1185
1186
|
}
|
|
1186
|
-
const display =
|
|
1187
|
-
const message =
|
|
1187
|
+
const display = isRecord(entry.data.display) ? entry.data.display : {};
|
|
1188
|
+
const message = isRecord(entry.message) ? entry.message : {};
|
|
1188
1189
|
const context = contextProjectionData({
|
|
1189
1190
|
context_kind: typeof entry.source.kind === "string" ? entry.source.kind : null,
|
|
1190
1191
|
context_key: typeof entry.source.key === "string" ? entry.source.key : null,
|
|
@@ -1194,7 +1195,7 @@ function buildContextTurn(entry, sequence) {
|
|
|
1194
1195
|
context_revision: typeof entry.data.revision === "string" ? entry.data.revision : null,
|
|
1195
1196
|
display_title: typeof display.title === "string" ? display.title : null,
|
|
1196
1197
|
display_summary: typeof display.summary === "string" ? display.summary : null,
|
|
1197
|
-
sources: Array.isArray(display.sources) ? display.sources.filter(
|
|
1198
|
+
sources: Array.isArray(display.sources) ? display.sources.filter(isRecord) : []
|
|
1198
1199
|
});
|
|
1199
1200
|
if (!context) return null;
|
|
1200
1201
|
const turnId = typeof entry.id === "string" && entry.id ? entry.id : `context-${sequence}`;
|
|
@@ -1493,7 +1494,7 @@ var ClientProjectionBuilder = class {
|
|
|
1493
1494
|
return null;
|
|
1494
1495
|
}
|
|
1495
1496
|
onContextEntry(payload) {
|
|
1496
|
-
if (!
|
|
1497
|
+
if (!isRecord(payload.entry)) return null;
|
|
1497
1498
|
const turn = buildContextTurn(payload.entry, this.nextSeq());
|
|
1498
1499
|
return turn ? [{ kind: "upsert", turn }] : null;
|
|
1499
1500
|
}
|
|
@@ -1554,11 +1555,11 @@ var ClientProjectionBuilder = class {
|
|
|
1554
1555
|
loopId,
|
|
1555
1556
|
toolCallId: optStr(payload.tool_call_id) ?? void 0,
|
|
1556
1557
|
toolName: toolNameFromPayload(payload) ?? void 0,
|
|
1557
|
-
workspacePath:
|
|
1558
|
+
workspacePath: isRecord(payload.workspace_change) ? optStr(payload.workspace_change.to) ?? void 0 : void 0
|
|
1558
1559
|
}
|
|
1559
1560
|
];
|
|
1560
1561
|
const change = payload.workspace_change;
|
|
1561
|
-
if (
|
|
1562
|
+
if (isRecord(change)) {
|
|
1562
1563
|
const source = optStr(change.source) ?? "";
|
|
1563
1564
|
const projectName = optStr(change.project_name) ?? "";
|
|
1564
1565
|
const fromPath = optStr(change.from) ?? "";
|
|
@@ -1654,7 +1655,7 @@ var ClientProjectionBuilder = class {
|
|
|
1654
1655
|
const updates = this.collectLoopUpdates(loopId, parentLoopId);
|
|
1655
1656
|
const entryId = typeof payload.entry_id === "string" ? payload.entry_id : "";
|
|
1656
1657
|
if (!entryId) return updates;
|
|
1657
|
-
const answerData =
|
|
1658
|
+
const answerData = isRecord(payload.answer_data) ? payload.answer_data : {};
|
|
1658
1659
|
const answerTurn = {
|
|
1659
1660
|
id: entryId,
|
|
1660
1661
|
sequence: this.nextSeq(),
|
|
@@ -2081,9 +2082,6 @@ var ClientProjectionBuilder = class {
|
|
|
2081
2082
|
return `${prefix}:${this.syntheticCounter}:${hex}`;
|
|
2082
2083
|
}
|
|
2083
2084
|
};
|
|
2084
|
-
function isRecord3(value) {
|
|
2085
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2086
|
-
}
|
|
2087
2085
|
function optStr(value) {
|
|
2088
2086
|
if (value == null || value === "") return null;
|
|
2089
2087
|
return String(value);
|
|
@@ -2119,14 +2117,14 @@ function projectHistory(entries) {
|
|
|
2119
2117
|
const kind = String(entry.kind ?? "");
|
|
2120
2118
|
const loopId = String(entry.loop_name ?? "root");
|
|
2121
2119
|
const id = String(entry.id ?? `history-${sequence + 1}`);
|
|
2122
|
-
if (kind === "turn_timing" &&
|
|
2120
|
+
if (kind === "turn_timing" && isRecord(entry.data)) {
|
|
2123
2121
|
const turnId = typeof entry.data.turn_id === "string" ? entry.data.turn_id : "";
|
|
2124
2122
|
const duration = numberOrNull(entry.data.first_token_delivery_ms);
|
|
2125
2123
|
const target = turnEntryAliases.get(turnId);
|
|
2126
2124
|
if (target && duration !== null) target.first_token_delivery_ms = duration;
|
|
2127
2125
|
continue;
|
|
2128
2126
|
}
|
|
2129
|
-
if (kind === "post_chat_followup" &&
|
|
2127
|
+
if (kind === "post_chat_followup" && isRecord(entry.data)) {
|
|
2130
2128
|
const assistantEntryId = String(entry.data.assistant_entry_id ?? "");
|
|
2131
2129
|
if (latestRootMessage?.role === "assistant" && latestRootMessage.turn_id === assistantEntryId) {
|
|
2132
2130
|
const followup = normalizePostChatFollowup(entry.data, assistantEntryId);
|
|
@@ -2142,7 +2140,7 @@ function projectHistory(entries) {
|
|
|
2142
2140
|
}
|
|
2143
2141
|
continue;
|
|
2144
2142
|
}
|
|
2145
|
-
if (kind === "message" &&
|
|
2143
|
+
if (kind === "message" && isRecord(entry.message)) {
|
|
2146
2144
|
const message = entry.message;
|
|
2147
2145
|
const role = String(message.role ?? "");
|
|
2148
2146
|
if (role === "tool") {
|
|
@@ -2177,7 +2175,7 @@ function projectHistory(entries) {
|
|
|
2177
2175
|
blocks,
|
|
2178
2176
|
tool_calls: toolCalls,
|
|
2179
2177
|
model: stringOrNull(message.model),
|
|
2180
|
-
usage:
|
|
2178
|
+
usage: isRecord(message._usage) ? { ...message._usage } : null,
|
|
2181
2179
|
duration_ms: numberOrZero(message._duration_ms),
|
|
2182
2180
|
first_token_ms: numberOrNull(message._first_token_ms),
|
|
2183
2181
|
stream_duration_ms: numberOrNull(message._stream_duration_ms),
|
|
@@ -2188,7 +2186,7 @@ function projectHistory(entries) {
|
|
|
2188
2186
|
parent_fork_tool_call_id: stringOrNull(message._parent_fork_tool_call_id)
|
|
2189
2187
|
};
|
|
2190
2188
|
const isNativeToolEntry = role === "assistant" && Array.isArray(message.tool_calls) && message.tool_calls.some(
|
|
2191
|
-
(toolCall) =>
|
|
2189
|
+
(toolCall) => isRecord(toolCall) && typeof toolCall.provider === "string"
|
|
2192
2190
|
);
|
|
2193
2191
|
const previousTurn = turns[turns.length - 1];
|
|
2194
2192
|
if (role === "assistant" && previousTurn?.role === "assistant" && previousTurn.loop_id === loopId && nativeToolTurns.has(previousTurn)) {
|
|
@@ -2242,7 +2240,7 @@ function projectHistory(entries) {
|
|
|
2242
2240
|
if (kind === "mode_change") {
|
|
2243
2241
|
turns.push(markerTurn(id, ++sequence, loopId, "mode_change", entry.data ?? {}));
|
|
2244
2242
|
} else if (kind === "workspace_change") {
|
|
2245
|
-
const change =
|
|
2243
|
+
const change = isRecord(entry.data) ? entry.data : {};
|
|
2246
2244
|
const source = stringOrNull(change.source) ?? "";
|
|
2247
2245
|
const projectName = stringOrNull(change.project_name) ?? "";
|
|
2248
2246
|
const fromPath = stringOrNull(change.from) ?? "";
|
|
@@ -2284,7 +2282,7 @@ function projectHistory(entries) {
|
|
|
2284
2282
|
} else if (kind === "compaction" || kind === "tool_result_archive") {
|
|
2285
2283
|
const data = entry.data ?? {};
|
|
2286
2284
|
const compactionId = String(data.compaction_id ?? entry.id ?? `history-${sequence + 1}`);
|
|
2287
|
-
let content =
|
|
2285
|
+
let content = isRecord(entry.message) ? entry.message.content : void 0;
|
|
2288
2286
|
if (kind === "tool_result_archive") {
|
|
2289
2287
|
const archivedCount = Array.isArray(data.archived_files) ? data.archived_files.length : 0;
|
|
2290
2288
|
content = `<compaction-summary>
|
|
@@ -2299,11 +2297,11 @@ function projectHistory(entries) {
|
|
|
2299
2297
|
);
|
|
2300
2298
|
} else if (kind === "child_pause") {
|
|
2301
2299
|
const data = entry.data ?? {};
|
|
2302
|
-
const sourceLoop =
|
|
2300
|
+
const sourceLoop = isRecord(data.source_loop) ? data.source_loop : {};
|
|
2303
2301
|
const childLoopId = String(data.child_loop_name ?? sourceLoop.name ?? "");
|
|
2304
2302
|
const childToolCallId = String(data.child_pause_tool_call_id ?? "");
|
|
2305
2303
|
const parentToolCallId = String(data.parent_fork_tool_call_id ?? "");
|
|
2306
|
-
const pauseToolData =
|
|
2304
|
+
const pauseToolData = isRecord(data.pause_tool_data) ? data.pause_tool_data : {};
|
|
2307
2305
|
const description = String(sourceLoop.description ?? "");
|
|
2308
2306
|
applyAskUserPauseToTurn(
|
|
2309
2307
|
latestAssistantByLoop.get(childLoopId),
|
|
@@ -2391,15 +2389,15 @@ function parseToolArguments(value) {
|
|
|
2391
2389
|
if (!value) return {};
|
|
2392
2390
|
try {
|
|
2393
2391
|
const parsed = JSON.parse(value);
|
|
2394
|
-
return
|
|
2392
|
+
return isRecord(parsed) ? parsed : {};
|
|
2395
2393
|
} catch {
|
|
2396
2394
|
return {};
|
|
2397
2395
|
}
|
|
2398
2396
|
}
|
|
2399
2397
|
function buildToolCalls(value) {
|
|
2400
2398
|
if (!Array.isArray(value)) return [];
|
|
2401
|
-
return value.filter(
|
|
2402
|
-
const fn =
|
|
2399
|
+
return value.filter(isRecord).map((raw) => {
|
|
2400
|
+
const fn = isRecord(raw.function) ? raw.function : {};
|
|
2403
2401
|
const name = String(fn.name ?? "");
|
|
2404
2402
|
return {
|
|
2405
2403
|
id: String(raw.id ?? ""),
|
|
@@ -2420,7 +2418,7 @@ function buildBlocks(message, toolCalls) {
|
|
|
2420
2418
|
blocks.push({ type: "text", content: displayContent });
|
|
2421
2419
|
} else if (Array.isArray(stored)) {
|
|
2422
2420
|
for (const raw of stored) {
|
|
2423
|
-
if (!
|
|
2421
|
+
if (!isRecord(raw)) continue;
|
|
2424
2422
|
const type3 = String(raw.type ?? "");
|
|
2425
2423
|
if (type3 === "thinking") blocks.push({ type: type3, content: raw.thinking ?? raw.content ?? "" });
|
|
2426
2424
|
if (type3 === "text") blocks.push({ type: type3, content: raw.text ?? raw.content ?? "" });
|
|
@@ -2469,9 +2467,6 @@ function markerTurn(id, sequence, loopId, type3, content, toolCallId = null) {
|
|
|
2469
2467
|
duration_ms: 0
|
|
2470
2468
|
};
|
|
2471
2469
|
}
|
|
2472
|
-
function isRecord4(value) {
|
|
2473
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2474
|
-
}
|
|
2475
2470
|
function stringOrNull(value) {
|
|
2476
2471
|
return typeof value === "string" ? value : null;
|
|
2477
2472
|
}
|
|
@@ -3400,10 +3395,10 @@ function inferLoopStatusFromMessages(messages) {
|
|
|
3400
3395
|
}
|
|
3401
3396
|
function inferLoopStatusFromTurns(turns, messages) {
|
|
3402
3397
|
const latestAgentNotification = [...turns].reverse().flatMap((turn) => turn.blocks).find((block) => {
|
|
3403
|
-
if (block.type !== "system_notification" || !
|
|
3398
|
+
if (block.type !== "system_notification" || !isRecord(block.content)) return false;
|
|
3404
3399
|
return block.content.notification_type === "agent:start" || block.content.notification_type === "agent:end";
|
|
3405
3400
|
});
|
|
3406
|
-
if (latestAgentNotification?.type === "system_notification" &&
|
|
3401
|
+
if (latestAgentNotification?.type === "system_notification" && isRecord(latestAgentNotification.content)) {
|
|
3407
3402
|
const notificationType = latestAgentNotification.content.notification_type;
|
|
3408
3403
|
const status = latestAgentNotification.content.status;
|
|
3409
3404
|
if (notificationType === "agent:start" || status === "running") return "running";
|
|
@@ -3412,11 +3407,8 @@ function inferLoopStatusFromTurns(turns, messages) {
|
|
|
3412
3407
|
}
|
|
3413
3408
|
return inferLoopStatusFromMessages(messages);
|
|
3414
3409
|
}
|
|
3415
|
-
function isRecord5(value) {
|
|
3416
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3417
|
-
}
|
|
3418
3410
|
function toSelectionMap(value) {
|
|
3419
|
-
if (!
|
|
3411
|
+
if (!isRecord(value)) return {};
|
|
3420
3412
|
const entries = Object.entries(value).map(([questionKey, optionIndexes]) => {
|
|
3421
3413
|
if (!Array.isArray(optionIndexes)) return null;
|
|
3422
3414
|
const parsedIndexes = optionIndexes.map((item) => typeof item === "number" ? item : Number(item)).filter((item) => Number.isInteger(item));
|
|
@@ -3425,7 +3417,7 @@ function toSelectionMap(value) {
|
|
|
3425
3417
|
return Object.fromEntries(entries);
|
|
3426
3418
|
}
|
|
3427
3419
|
function toCustomMap(value) {
|
|
3428
|
-
if (!
|
|
3420
|
+
if (!isRecord(value)) return {};
|
|
3429
3421
|
const entries = Object.entries(value).filter(([, text]) => typeof text === "string").map(([questionKey, text]) => [Number(questionKey), text]);
|
|
3430
3422
|
return Object.fromEntries(entries);
|
|
3431
3423
|
}
|
|
@@ -3434,7 +3426,7 @@ function extractAskAnswers(turns) {
|
|
|
3434
3426
|
for (const turn of turns) {
|
|
3435
3427
|
for (const block of turn.blocks) {
|
|
3436
3428
|
if (block.type !== "ask_user_answer" || typeof block.tool_call_id !== "string") continue;
|
|
3437
|
-
if (!
|
|
3429
|
+
if (!isRecord(block.content)) continue;
|
|
3438
3430
|
const note = typeof block.content.note === "string" ? block.content.note.trim() : "";
|
|
3439
3431
|
answers[block.tool_call_id] = {
|
|
3440
3432
|
selections: toSelectionMap(block.content.selections),
|
|
@@ -3450,9 +3442,9 @@ function parentForkToolCallIdFromTurn(turn) {
|
|
|
3450
3442
|
return turn.parent_fork_tool_call_id;
|
|
3451
3443
|
}
|
|
3452
3444
|
for (const block of turn.blocks) {
|
|
3453
|
-
if (block.type !== "system_notification" || !
|
|
3445
|
+
if (block.type !== "system_notification" || !isRecord(block.content)) continue;
|
|
3454
3446
|
const metadata = block.content.metadata;
|
|
3455
|
-
if (!
|
|
3447
|
+
if (!isRecord(metadata)) continue;
|
|
3456
3448
|
const parentId = metadata.parent_fork_tool_call_id;
|
|
3457
3449
|
if (typeof parentId === "string" && parentId.length > 0) return parentId;
|
|
3458
3450
|
}
|
|
@@ -3469,16 +3461,16 @@ function buildMessageContent2(turn) {
|
|
|
3469
3461
|
}
|
|
3470
3462
|
function workspaceNotificationContent(turn) {
|
|
3471
3463
|
const block = turn.blocks.find(
|
|
3472
|
-
(candidate) => candidate.type === "system_notification" &&
|
|
3464
|
+
(candidate) => candidate.type === "system_notification" && isRecord(candidate.content) && candidate.content.notification_type === "workspace_change"
|
|
3473
3465
|
);
|
|
3474
|
-
if (!block || !
|
|
3466
|
+
if (!block || !isRecord(block.content)) return "";
|
|
3475
3467
|
const title = typeof block.content.title === "string" ? block.content.title.trim() : "";
|
|
3476
3468
|
const detail = typeof block.content.detail === "string" ? block.content.detail.trim() : "";
|
|
3477
3469
|
return [title ? `**${title}**` : "", detail].filter(Boolean).join("\n\n");
|
|
3478
3470
|
}
|
|
3479
3471
|
function askUserAnswerContent(turn) {
|
|
3480
3472
|
const answerBlock = turn.blocks.find((block) => block.type === "ask_user_answer");
|
|
3481
|
-
if (!answerBlock || !
|
|
3473
|
+
if (!answerBlock || !isRecord(answerBlock.content)) return null;
|
|
3482
3474
|
const answer = answerBlock.content.answer;
|
|
3483
3475
|
return typeof answer === "string" && answer.trim().length > 0 ? answer : null;
|
|
3484
3476
|
}
|
|
@@ -3868,18 +3860,15 @@ function createClientRequestId() {
|
|
|
3868
3860
|
return `${Date.now()}-${Math.random().toString(36).slice(2)}-${fallbackRequestCounter}`;
|
|
3869
3861
|
}
|
|
3870
3862
|
var OOM_KEYWORDS_RE = /(?:\b(?:exit_code|ExitedWith|exited with)|退出码)\D*(?<!\d)137(?!\d)/i;
|
|
3871
|
-
function isRecord6(value) {
|
|
3872
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3873
|
-
}
|
|
3874
3863
|
function isOomText(value) {
|
|
3875
3864
|
return typeof value === "string" && OOM_KEYWORDS_RE.test(value);
|
|
3876
3865
|
}
|
|
3877
3866
|
function parseJsonRecord(value) {
|
|
3878
|
-
if (
|
|
3867
|
+
if (isRecord(value)) return value;
|
|
3879
3868
|
if (typeof value !== "string") return null;
|
|
3880
3869
|
try {
|
|
3881
3870
|
const parsed = JSON.parse(value);
|
|
3882
|
-
return
|
|
3871
|
+
return isRecord(parsed) ? parsed : null;
|
|
3883
3872
|
} catch {
|
|
3884
3873
|
return null;
|
|
3885
3874
|
}
|
|
@@ -3927,7 +3916,7 @@ function extractTerminalChatEndStatus(events) {
|
|
|
3927
3916
|
return null;
|
|
3928
3917
|
}
|
|
3929
3918
|
function isUiMetaLike(value) {
|
|
3930
|
-
return
|
|
3919
|
+
return isRecord(value) && ("resourceHTML" in value || "resourceUri" in value || "resourceURI" in value);
|
|
3931
3920
|
}
|
|
3932
3921
|
var AgentSession = class _AgentSession {
|
|
3933
3922
|
sessionId;
|
|
@@ -4155,7 +4144,7 @@ var AgentSession = class _AgentSession {
|
|
|
4155
4144
|
if (this.getAppContext) {
|
|
4156
4145
|
try {
|
|
4157
4146
|
const rawContext = await this.getAppContext();
|
|
4158
|
-
if (!
|
|
4147
|
+
if (!isRecord(rawContext)) {
|
|
4159
4148
|
throw new Error("getContext \u5FC5\u987B\u8FD4\u56DE JSON \u5BF9\u8C61");
|
|
4160
4149
|
}
|
|
4161
4150
|
const serialized = JSON.stringify(rawContext);
|
|
@@ -4163,7 +4152,7 @@ var AgentSession = class _AgentSession {
|
|
|
4163
4152
|
throw new Error("getContext \u5FC5\u987B\u8FD4\u56DE\u53EF\u5E8F\u5217\u5316\u7684 JSON \u5BF9\u8C61");
|
|
4164
4153
|
}
|
|
4165
4154
|
const normalized = JSON.parse(serialized);
|
|
4166
|
-
if (!
|
|
4155
|
+
if (!isRecord(normalized)) {
|
|
4167
4156
|
throw new Error("getContext \u5FC5\u987B\u8FD4\u56DE JSON \u5BF9\u8C61");
|
|
4168
4157
|
}
|
|
4169
4158
|
appContext = normalized;
|
|
@@ -4634,9 +4623,9 @@ ${text}` } : block
|
|
|
4634
4623
|
detail,
|
|
4635
4624
|
status,
|
|
4636
4625
|
loopId,
|
|
4637
|
-
metadata:
|
|
4626
|
+
metadata: isRecord(notification.metadata) ? notification.metadata : void 0
|
|
4638
4627
|
});
|
|
4639
|
-
if (notificationType === "bg:started" &&
|
|
4628
|
+
if (notificationType === "bg:started" && isRecord(notification.metadata)) {
|
|
4640
4629
|
const taskId = typeof notification.metadata.task_id === "string" ? notification.metadata.task_id : "";
|
|
4641
4630
|
if (taskId) {
|
|
4642
4631
|
this.emitter.emit("backgroundTask", {
|
|
@@ -4792,7 +4781,7 @@ ${text}` } : block
|
|
|
4792
4781
|
title: ui.title ?? "\u5DE5\u5177\u9884\u89C8"
|
|
4793
4782
|
});
|
|
4794
4783
|
}
|
|
4795
|
-
if (block.type === "system_notification" &&
|
|
4784
|
+
if (block.type === "system_notification" && isRecord(block.content)) {
|
|
4796
4785
|
this._handleSystemNotification(turn.loop_id, block.content);
|
|
4797
4786
|
}
|
|
4798
4787
|
}
|
|
@@ -5417,21 +5406,14 @@ function resolveAuthToken(options) {
|
|
|
5417
5406
|
return token ? token : null;
|
|
5418
5407
|
}
|
|
5419
5408
|
|
|
5420
|
-
// src/version.ts
|
|
5421
|
-
var SDK_NAME = "agent-client";
|
|
5422
|
-
var SDK_VERSION = true ? "2610.0.0-beta.37" : "1.1.1";
|
|
5423
|
-
|
|
5424
5409
|
// src/socket.ts
|
|
5425
|
-
function withSdkIdentity(auth) {
|
|
5426
|
-
return { ...auth ?? {}, sdk: SDK_NAME, sdk_version: SDK_VERSION };
|
|
5427
|
-
}
|
|
5428
5410
|
function createSocket(options) {
|
|
5429
5411
|
const token = resolveAuthToken(options);
|
|
5430
5412
|
return io(options.baseUrl, {
|
|
5431
5413
|
path: options.path ?? "/socket.io",
|
|
5432
5414
|
withCredentials: true,
|
|
5433
5415
|
query: token ? { token } : void 0,
|
|
5434
|
-
auth: typeof options.token === "function" ? (cb) => cb(
|
|
5416
|
+
auth: typeof options.token === "function" ? (cb) => cb(buildSocketAuth(options) ?? {}) : buildSocketAuth(options) ?? {},
|
|
5435
5417
|
autoConnect: false
|
|
5436
5418
|
});
|
|
5437
5419
|
}
|
|
@@ -5833,9 +5815,6 @@ function defaultDocumentBaseUrl() {
|
|
|
5833
5815
|
if (typeof location !== "undefined" && location.origin) return `${location.origin}/`;
|
|
5834
5816
|
return document.baseURI;
|
|
5835
5817
|
}
|
|
5836
|
-
function isRecord7(value) {
|
|
5837
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5838
|
-
}
|
|
5839
5818
|
function normalizeServiceUrl(value) {
|
|
5840
5819
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
5841
5820
|
if (value.includes("?") || value.includes("#")) return null;
|
|
@@ -5849,7 +5828,7 @@ function normalizeServiceUrl(value) {
|
|
|
5849
5828
|
}
|
|
5850
5829
|
}
|
|
5851
5830
|
function parsePlatformEndpoints(value) {
|
|
5852
|
-
if (!
|
|
5831
|
+
if (!isRecord(value) || !isRecord(value.services)) return null;
|
|
5853
5832
|
const services = {};
|
|
5854
5833
|
for (const name of PLATFORM_SERVICE_NAMES) {
|
|
5855
5834
|
if (!(name in value.services)) continue;
|
|
@@ -5897,6 +5876,10 @@ function resolveServiceUrl(endpoints, name, path = "") {
|
|
|
5897
5876
|
return target.toString();
|
|
5898
5877
|
}
|
|
5899
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
|
+
|
|
5900
5883
|
// src/commands/protocol.ts
|
|
5901
5884
|
function isCommandEnvelope(value) {
|
|
5902
5885
|
if (typeof value !== "object" || value === null) return false;
|