@blade-hq/agent-client 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +82 -27
- package/dist/index.js.map +1 -1
- package/dist/resources/sessions.d.ts +4 -1
- package/dist/schemas/projection.d.ts +1 -0
- package/dist/schemas/session.d.ts +2 -0
- package/dist/shared/projection/builder.d.ts +1 -0
- package/dist/types/rest.d.ts +248 -411
- package/dist/types/socket-events.d.ts +4 -0
- package/package.json +1 -1
- package/public-api.md +4 -2
package/dist/index.js
CHANGED
|
@@ -1075,9 +1075,31 @@ var ClientProjectionBuilder = class {
|
|
|
1075
1075
|
kind: "workspace_changed",
|
|
1076
1076
|
loopId,
|
|
1077
1077
|
toolCallId: optStr(payload.tool_call_id) ?? void 0,
|
|
1078
|
-
toolName: toolNameFromPayload(payload) ?? void 0
|
|
1078
|
+
toolName: toolNameFromPayload(payload) ?? void 0,
|
|
1079
|
+
workspacePath: isRecord2(payload.workspace_change) ? optStr(payload.workspace_change.to) ?? void 0 : void 0
|
|
1079
1080
|
}
|
|
1080
1081
|
];
|
|
1082
|
+
const change = payload.workspace_change;
|
|
1083
|
+
if (isRecord2(change)) {
|
|
1084
|
+
const source = optStr(change.source) ?? "";
|
|
1085
|
+
const projectName = optStr(change.project_name) ?? "";
|
|
1086
|
+
const fromPath = optStr(change.from) ?? "";
|
|
1087
|
+
const toPath = optStr(change.to) ?? "";
|
|
1088
|
+
const filesCopied = typeof change.files_copied === "number" ? change.files_copied : 0;
|
|
1089
|
+
updates.unshift({
|
|
1090
|
+
kind: "upsert",
|
|
1091
|
+
turn: buildSystemNotificationTurn(
|
|
1092
|
+
this.nextSeq(),
|
|
1093
|
+
this.nextTurnId("workspace_change"),
|
|
1094
|
+
loopId,
|
|
1095
|
+
"workspace_change",
|
|
1096
|
+
"done",
|
|
1097
|
+
source === "cli:blade" && projectName ? `\u9879\u76EE\u300C${projectName}\u300D\u5DF2\u521B\u5EFA` : "\u5DE5\u4F5C\u76EE\u5F55\u5DF2\u5207\u6362",
|
|
1098
|
+
source === "cli:blade" && projectName ? `${filesCopied > 0 ? `\u5DF2\u590D\u5236 ${filesCopied} \u9879\u5F53\u524D\u6587\u4EF6\u3002` : "\u5DF2\u539F\u5730\u4F7F\u7528\u5F53\u524D\u6587\u4EF6\u5939\u3002"} \u540E\u7EED\u5DE5\u4F5C\u5C06\u5728 ${toPath} \u8FDB\u884C\u3002` : `\u5DE5\u4F5C\u76EE\u5F55\u5DF2\u4ECE ${fromPath} \u5207\u6362\u5230 ${toPath}\u3002\u540E\u7EED\u5DE5\u4F5C\u5C06\u5728\u65B0\u76EE\u5F55\u8FDB\u884C\u3002`,
|
|
1099
|
+
{ ...change }
|
|
1100
|
+
)
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1081
1103
|
const state = this.activeTurns.get(loopId);
|
|
1082
1104
|
if (state) {
|
|
1083
1105
|
const turn = snapshot(state, this.nextSeq(), "streaming");
|
|
@@ -1486,6 +1508,9 @@ var ClientProjectionBuilder = class {
|
|
|
1486
1508
|
return `${prefix}:${this.syntheticCounter}:${hex}`;
|
|
1487
1509
|
}
|
|
1488
1510
|
};
|
|
1511
|
+
function isRecord2(value) {
|
|
1512
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1513
|
+
}
|
|
1489
1514
|
function optStr(value) {
|
|
1490
1515
|
if (value == null || value === "") return null;
|
|
1491
1516
|
return String(value);
|
|
@@ -1516,7 +1541,7 @@ function projectHistory(entries) {
|
|
|
1516
1541
|
const kind = String(entry.kind ?? "");
|
|
1517
1542
|
const loopId = String(entry.loop_name ?? "root");
|
|
1518
1543
|
const id = String(entry.id ?? `history-${sequence + 1}`);
|
|
1519
|
-
if (kind === "message" &&
|
|
1544
|
+
if (kind === "message" && isRecord3(entry.message)) {
|
|
1520
1545
|
const message = entry.message;
|
|
1521
1546
|
const role = String(message.role ?? "");
|
|
1522
1547
|
if (role === "tool") {
|
|
@@ -1548,7 +1573,7 @@ function projectHistory(entries) {
|
|
|
1548
1573
|
blocks,
|
|
1549
1574
|
tool_calls: toolCalls,
|
|
1550
1575
|
model: stringOrNull(message.model),
|
|
1551
|
-
usage:
|
|
1576
|
+
usage: isRecord3(message._usage) ? { ...message._usage } : null,
|
|
1552
1577
|
duration_ms: numberOrZero(message._duration_ms),
|
|
1553
1578
|
started_at: typeof entry.timestamp === "string" ? entry.timestamp : void 0
|
|
1554
1579
|
};
|
|
@@ -1559,6 +1584,25 @@ function projectHistory(entries) {
|
|
|
1559
1584
|
}
|
|
1560
1585
|
if (kind === "mode_change") {
|
|
1561
1586
|
turns.push(markerTurn(id, ++sequence, loopId, "mode_change", entry.data ?? {}));
|
|
1587
|
+
} else if (kind === "workspace_change") {
|
|
1588
|
+
const change = isRecord3(entry.data) ? entry.data : {};
|
|
1589
|
+
const source = stringOrNull(change.source) ?? "";
|
|
1590
|
+
const projectName = stringOrNull(change.project_name) ?? "";
|
|
1591
|
+
const fromPath = stringOrNull(change.from) ?? "";
|
|
1592
|
+
const toPath = stringOrNull(change.to) ?? "";
|
|
1593
|
+
const filesCopied = typeof change.files_copied === "number" ? change.files_copied : 0;
|
|
1594
|
+
turns.push(
|
|
1595
|
+
buildSystemNotificationTurn(
|
|
1596
|
+
++sequence,
|
|
1597
|
+
id,
|
|
1598
|
+
loopId,
|
|
1599
|
+
"workspace_change",
|
|
1600
|
+
"done",
|
|
1601
|
+
source === "cli:blade" && projectName ? `\u9879\u76EE\u300C${projectName}\u300D\u5DF2\u521B\u5EFA` : "\u5DE5\u4F5C\u76EE\u5F55\u5DF2\u5207\u6362",
|
|
1602
|
+
source === "cli:blade" && projectName ? `${filesCopied > 0 ? `\u5DF2\u590D\u5236 ${filesCopied} \u9879\u5F53\u524D\u6587\u4EF6\u3002` : "\u5DF2\u539F\u5730\u4F7F\u7528\u5F53\u524D\u6587\u4EF6\u5939\u3002"} \u540E\u7EED\u5DE5\u4F5C\u5C06\u5728 ${toPath} \u8FDB\u884C\u3002` : `\u5DE5\u4F5C\u76EE\u5F55\u5DF2\u4ECE ${fromPath} \u5207\u6362\u5230 ${toPath}\u3002\u540E\u7EED\u5DE5\u4F5C\u5C06\u5728\u65B0\u76EE\u5F55\u8FDB\u884C\u3002`,
|
|
1603
|
+
{ ...change }
|
|
1604
|
+
)
|
|
1605
|
+
);
|
|
1562
1606
|
} else if (kind === "plan_status") {
|
|
1563
1607
|
const data = entry.data ?? {};
|
|
1564
1608
|
turns.push(
|
|
@@ -1582,7 +1626,7 @@ function projectHistory(entries) {
|
|
|
1582
1626
|
} else if (kind === "compaction" || kind === "tool_result_archive") {
|
|
1583
1627
|
const data = entry.data ?? {};
|
|
1584
1628
|
const compactionId = String(data.compaction_id ?? entry.id ?? `history-${sequence + 1}`);
|
|
1585
|
-
let content =
|
|
1629
|
+
let content = isRecord3(entry.message) ? entry.message.content : void 0;
|
|
1586
1630
|
if (kind === "tool_result_archive") {
|
|
1587
1631
|
const archivedCount = Array.isArray(data.archived_files) ? data.archived_files.length : 0;
|
|
1588
1632
|
content = `<compaction-summary>
|
|
@@ -1597,11 +1641,11 @@ function projectHistory(entries) {
|
|
|
1597
1641
|
);
|
|
1598
1642
|
} else if (kind === "child_pause") {
|
|
1599
1643
|
const data = entry.data ?? {};
|
|
1600
|
-
const sourceLoop =
|
|
1644
|
+
const sourceLoop = isRecord3(data.source_loop) ? data.source_loop : {};
|
|
1601
1645
|
const childLoopId = String(data.child_loop_name ?? sourceLoop.name ?? "");
|
|
1602
1646
|
const childToolCallId = String(data.child_pause_tool_call_id ?? "");
|
|
1603
1647
|
const parentToolCallId = String(data.parent_fork_tool_call_id ?? "");
|
|
1604
|
-
const pauseToolData =
|
|
1648
|
+
const pauseToolData = isRecord3(data.pause_tool_data) ? data.pause_tool_data : {};
|
|
1605
1649
|
const description = String(sourceLoop.description ?? "");
|
|
1606
1650
|
applyAskUserPauseToTurn(
|
|
1607
1651
|
latestAssistantByLoop.get(childLoopId),
|
|
@@ -1659,8 +1703,8 @@ function projectHistory(entries) {
|
|
|
1659
1703
|
}
|
|
1660
1704
|
function buildToolCalls(value) {
|
|
1661
1705
|
if (!Array.isArray(value)) return [];
|
|
1662
|
-
return value.filter(
|
|
1663
|
-
const fn =
|
|
1706
|
+
return value.filter(isRecord3).map((raw) => {
|
|
1707
|
+
const fn = isRecord3(raw.function) ? raw.function : {};
|
|
1664
1708
|
const name = String(fn.name ?? "");
|
|
1665
1709
|
return {
|
|
1666
1710
|
id: String(raw.id ?? ""),
|
|
@@ -1680,7 +1724,7 @@ function buildBlocks(message, toolCalls) {
|
|
|
1680
1724
|
blocks.push({ type: "text", content: displayContent });
|
|
1681
1725
|
} else if (Array.isArray(stored)) {
|
|
1682
1726
|
for (const raw of stored) {
|
|
1683
|
-
if (!
|
|
1727
|
+
if (!isRecord3(raw)) continue;
|
|
1684
1728
|
const type3 = String(raw.type ?? "");
|
|
1685
1729
|
if (type3 === "thinking") blocks.push({ type: type3, content: raw.thinking ?? raw.content ?? "" });
|
|
1686
1730
|
if (type3 === "text") blocks.push({ type: type3, content: raw.text ?? raw.content ?? "" });
|
|
@@ -1713,7 +1757,7 @@ function markerTurn(id, sequence, loopId, type3, content, toolCallId = null) {
|
|
|
1713
1757
|
duration_ms: 0
|
|
1714
1758
|
};
|
|
1715
1759
|
}
|
|
1716
|
-
function
|
|
1760
|
+
function isRecord3(value) {
|
|
1717
1761
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1718
1762
|
}
|
|
1719
1763
|
function stringOrNull(value) {
|
|
@@ -1984,8 +2028,9 @@ var SessionsResource = class {
|
|
|
1984
2028
|
checkpoint_id: checkpointId
|
|
1985
2029
|
});
|
|
1986
2030
|
}
|
|
1987
|
-
deleteSession(sessionId) {
|
|
1988
|
-
|
|
2031
|
+
deleteSession(sessionId, options) {
|
|
2032
|
+
const query = options?.deleteWorkspace ? "?delete_workspace=true" : "";
|
|
2033
|
+
return this.client.json("DELETE", `/api/sessions/${sessionId}${query}`);
|
|
1989
2034
|
}
|
|
1990
2035
|
listBackgroundTasks(sessionId, init) {
|
|
1991
2036
|
return this.client.jsonFromInit(`/api/sessions/${sessionId}/background-tasks`, init);
|
|
@@ -2453,10 +2498,10 @@ function inferLoopStatusFromMessages(messages) {
|
|
|
2453
2498
|
}
|
|
2454
2499
|
function inferLoopStatusFromTurns(turns, messages) {
|
|
2455
2500
|
const latestAgentNotification = [...turns].reverse().flatMap((turn) => turn.blocks).find((block) => {
|
|
2456
|
-
if (block.type !== "system_notification" || !
|
|
2501
|
+
if (block.type !== "system_notification" || !isRecord4(block.content)) return false;
|
|
2457
2502
|
return block.content.notification_type === "agent:start" || block.content.notification_type === "agent:end";
|
|
2458
2503
|
});
|
|
2459
|
-
if (latestAgentNotification?.type === "system_notification" &&
|
|
2504
|
+
if (latestAgentNotification?.type === "system_notification" && isRecord4(latestAgentNotification.content)) {
|
|
2460
2505
|
const notificationType = latestAgentNotification.content.notification_type;
|
|
2461
2506
|
const status = latestAgentNotification.content.status;
|
|
2462
2507
|
if (notificationType === "agent:start" || status === "running") return "running";
|
|
@@ -2465,7 +2510,7 @@ function inferLoopStatusFromTurns(turns, messages) {
|
|
|
2465
2510
|
}
|
|
2466
2511
|
return inferLoopStatusFromMessages(messages);
|
|
2467
2512
|
}
|
|
2468
|
-
function
|
|
2513
|
+
function isRecord4(value) {
|
|
2469
2514
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2470
2515
|
}
|
|
2471
2516
|
function parentForkToolCallIdFromTurn(turn) {
|
|
@@ -2473,9 +2518,9 @@ function parentForkToolCallIdFromTurn(turn) {
|
|
|
2473
2518
|
return turn.parent_fork_tool_call_id;
|
|
2474
2519
|
}
|
|
2475
2520
|
for (const block of turn.blocks) {
|
|
2476
|
-
if (block.type !== "system_notification" || !
|
|
2521
|
+
if (block.type !== "system_notification" || !isRecord4(block.content)) continue;
|
|
2477
2522
|
const metadata = block.content.metadata;
|
|
2478
|
-
if (!
|
|
2523
|
+
if (!isRecord4(metadata)) continue;
|
|
2479
2524
|
const parentId = metadata.parent_fork_tool_call_id;
|
|
2480
2525
|
if (typeof parentId === "string" && parentId.length > 0) return parentId;
|
|
2481
2526
|
}
|
|
@@ -2490,9 +2535,18 @@ function buildMessageContent2(turn) {
|
|
|
2490
2535
|
return JSON.stringify(block.content);
|
|
2491
2536
|
}).join("");
|
|
2492
2537
|
}
|
|
2538
|
+
function workspaceNotificationContent(turn) {
|
|
2539
|
+
const block = turn.blocks.find(
|
|
2540
|
+
(candidate) => candidate.type === "system_notification" && isRecord4(candidate.content) && candidate.content.notification_type === "workspace_change"
|
|
2541
|
+
);
|
|
2542
|
+
if (!block || !isRecord4(block.content)) return "";
|
|
2543
|
+
const title = typeof block.content.title === "string" ? block.content.title.trim() : "";
|
|
2544
|
+
const detail = typeof block.content.detail === "string" ? block.content.detail.trim() : "";
|
|
2545
|
+
return [title ? `**${title}**` : "", detail].filter(Boolean).join("\n\n");
|
|
2546
|
+
}
|
|
2493
2547
|
function askUserAnswerContent(turn) {
|
|
2494
2548
|
const answerBlock = turn.blocks.find((block) => block.type === "ask_user_answer");
|
|
2495
|
-
if (!answerBlock || !
|
|
2549
|
+
if (!answerBlock || !isRecord4(answerBlock.content)) return null;
|
|
2496
2550
|
const answer = answerBlock.content.answer;
|
|
2497
2551
|
return typeof answer === "string" && answer.trim().length > 0 ? answer : null;
|
|
2498
2552
|
}
|
|
@@ -2572,7 +2626,7 @@ function projectionToMessage(turn) {
|
|
|
2572
2626
|
...turn.started_at ? { timestamp: turn.started_at } : {}
|
|
2573
2627
|
};
|
|
2574
2628
|
}
|
|
2575
|
-
const content = buildMessageContent2(turn);
|
|
2629
|
+
const content = buildMessageContent2(turn) || workspaceNotificationContent(turn);
|
|
2576
2630
|
const reasoning = buildReasoning(turn);
|
|
2577
2631
|
const toolCalls = turn.tool_calls.length > 0 ? turn.tool_calls.map((toolCall) => ({
|
|
2578
2632
|
id: toolCall.id,
|
|
@@ -2796,18 +2850,18 @@ function markStreamingTurns(state, turnStatus, toolCallStatus) {
|
|
|
2796
2850
|
// src/session/agent-session.ts
|
|
2797
2851
|
var OOM_MESSAGE = "\u6C99\u76D2\u5185\u5B58\u4F7F\u7528\u8D85\u51FA\u9650\u5236\uFF0C\u5DF2\u81EA\u52A8\u91CD\u542F\u3002\u5982\u679C\u7ECF\u5E38\u89E6\u53D1\uFF0C\u53EF\u4EE5\u8054\u7CFB\u7BA1\u7406\u5458\u8C03\u6574\u989D\u5EA6\u3002";
|
|
2798
2852
|
var OOM_KEYWORDS_RE = /(?:\b(?:exit_code|ExitedWith|exited with)|退出码)\D*(?<!\d)137(?!\d)/i;
|
|
2799
|
-
function
|
|
2853
|
+
function isRecord5(value) {
|
|
2800
2854
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2801
2855
|
}
|
|
2802
2856
|
function isOomText(value) {
|
|
2803
2857
|
return typeof value === "string" && OOM_KEYWORDS_RE.test(value);
|
|
2804
2858
|
}
|
|
2805
2859
|
function parseJsonRecord(value) {
|
|
2806
|
-
if (
|
|
2860
|
+
if (isRecord5(value)) return value;
|
|
2807
2861
|
if (typeof value !== "string") return null;
|
|
2808
2862
|
try {
|
|
2809
2863
|
const parsed = JSON.parse(value);
|
|
2810
|
-
return
|
|
2864
|
+
return isRecord5(parsed) ? parsed : null;
|
|
2811
2865
|
} catch {
|
|
2812
2866
|
return null;
|
|
2813
2867
|
}
|
|
@@ -2849,7 +2903,7 @@ function extractTerminalChatEndStatus(events) {
|
|
|
2849
2903
|
return null;
|
|
2850
2904
|
}
|
|
2851
2905
|
function isUiMetaLike(value) {
|
|
2852
|
-
return
|
|
2906
|
+
return isRecord5(value) && ("resourceHTML" in value || "resourceUri" in value || "resourceURI" in value);
|
|
2853
2907
|
}
|
|
2854
2908
|
var AgentSession = class _AgentSession {
|
|
2855
2909
|
sessionId;
|
|
@@ -3203,9 +3257,9 @@ var AgentSession = class _AgentSession {
|
|
|
3203
3257
|
detail,
|
|
3204
3258
|
status,
|
|
3205
3259
|
loopId,
|
|
3206
|
-
metadata:
|
|
3260
|
+
metadata: isRecord5(notification.metadata) ? notification.metadata : void 0
|
|
3207
3261
|
});
|
|
3208
|
-
if (notificationType === "bg:started" &&
|
|
3262
|
+
if (notificationType === "bg:started" && isRecord5(notification.metadata)) {
|
|
3209
3263
|
const taskId = typeof notification.metadata.task_id === "string" ? notification.metadata.task_id : "";
|
|
3210
3264
|
if (taskId) {
|
|
3211
3265
|
this.emitter.emit("backgroundTask", {
|
|
@@ -3329,7 +3383,7 @@ var AgentSession = class _AgentSession {
|
|
|
3329
3383
|
title: ui.title ?? "\u5DE5\u5177\u9884\u89C8"
|
|
3330
3384
|
});
|
|
3331
3385
|
}
|
|
3332
|
-
if (block.type === "system_notification" &&
|
|
3386
|
+
if (block.type === "system_notification" && isRecord5(block.content)) {
|
|
3333
3387
|
this._handleSystemNotification(turn.loop_id, block.content);
|
|
3334
3388
|
}
|
|
3335
3389
|
}
|
|
@@ -3757,7 +3811,7 @@ function resolveAuthToken(options) {
|
|
|
3757
3811
|
|
|
3758
3812
|
// src/version.ts
|
|
3759
3813
|
var SDK_NAME = "agent-client";
|
|
3760
|
-
var SDK_VERSION = true ? "1.1.
|
|
3814
|
+
var SDK_VERSION = true ? "1.1.5" : "1.1.1";
|
|
3761
3815
|
|
|
3762
3816
|
// src/socket.ts
|
|
3763
3817
|
function withSdkIdentity(auth) {
|
|
@@ -4225,6 +4279,7 @@ var SessionInfo = type({
|
|
|
4225
4279
|
"disable_tools?": "string[]",
|
|
4226
4280
|
"runtime_type?": "string | null",
|
|
4227
4281
|
"daemon_id?": "string | null",
|
|
4282
|
+
"workspace_path?": "string | null",
|
|
4228
4283
|
"match?": "unknown"
|
|
4229
4284
|
});
|
|
4230
4285
|
|