@blade-hq/agent-client 1.2.1-beta.12 → 1.2.1-beta.13
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 +55 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -56,9 +56,14 @@ async function loginWithPopup(client, options = {}) {
|
|
|
56
56
|
return new Promise((resolve, reject) => {
|
|
57
57
|
const timeoutMs = options.timeoutMs ?? 5 * 60 * 1e3;
|
|
58
58
|
let settled = false;
|
|
59
|
+
let closeTimer;
|
|
60
|
+
const stopCloseWatch = () => {
|
|
61
|
+
globalThis.clearInterval(closeWatcher);
|
|
62
|
+
if (closeTimer !== void 0) globalThis.clearTimeout(closeTimer);
|
|
63
|
+
};
|
|
59
64
|
const cleanup = () => {
|
|
60
65
|
window.removeEventListener("message", onMessage);
|
|
61
|
-
|
|
66
|
+
stopCloseWatch();
|
|
62
67
|
globalThis.clearTimeout(timeoutHandle);
|
|
63
68
|
};
|
|
64
69
|
const settle = (fn) => {
|
|
@@ -73,6 +78,7 @@ async function loginWithPopup(client, options = {}) {
|
|
|
73
78
|
if (!isAuthCallbackMessage(event.data)) return;
|
|
74
79
|
if (event.data.state !== state) return;
|
|
75
80
|
const message = event.data;
|
|
81
|
+
stopCloseWatch();
|
|
76
82
|
try {
|
|
77
83
|
popup.close();
|
|
78
84
|
} catch {
|
|
@@ -98,11 +104,10 @@ async function loginWithPopup(client, options = {}) {
|
|
|
98
104
|
});
|
|
99
105
|
};
|
|
100
106
|
const closeWatcher = globalThis.setInterval(() => {
|
|
101
|
-
if (popup.closed
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
107
|
+
if (!popup.closed || settled || closeTimer !== void 0) return;
|
|
108
|
+
closeTimer = globalThis.setTimeout(() => {
|
|
109
|
+
settle(() => reject(new Error("\u767B\u5F55\u7A97\u53E3\u5DF2\u5173\u95ED\uFF0C\u672A\u5B8C\u6210\u6388\u6743\u3002")));
|
|
110
|
+
}, 400);
|
|
106
111
|
}, 500);
|
|
107
112
|
const timeoutHandle = globalThis.setTimeout(() => {
|
|
108
113
|
settle(() => reject(new Error("\u767B\u5F55\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5\u3002")));
|
|
@@ -1611,7 +1616,9 @@ function projectHistory(entries) {
|
|
|
1611
1616
|
const toolOwners = /* @__PURE__ */ new Map();
|
|
1612
1617
|
const latestAssistantByLoop = /* @__PURE__ */ new Map();
|
|
1613
1618
|
const pendingChildPauses = /* @__PURE__ */ new Map();
|
|
1619
|
+
const answeredToolCallIds = /* @__PURE__ */ new Set();
|
|
1614
1620
|
let latestRootMessage = null;
|
|
1621
|
+
let latestRootAssistant = null;
|
|
1615
1622
|
let sequence = 0;
|
|
1616
1623
|
for (const entry of entries) {
|
|
1617
1624
|
const kind = String(entry.kind ?? "");
|
|
@@ -1670,6 +1677,10 @@ function projectHistory(entries) {
|
|
|
1670
1677
|
}
|
|
1671
1678
|
turns.push(turn);
|
|
1672
1679
|
if (role === "assistant") latestAssistantByLoop.set(loopId, turn);
|
|
1680
|
+
if (loopId === "root") {
|
|
1681
|
+
if (role === "assistant") latestRootAssistant = turn;
|
|
1682
|
+
else if (role === "user") latestRootAssistant = null;
|
|
1683
|
+
}
|
|
1673
1684
|
for (const toolCall of toolCalls) toolOwners.set(toolCall.id, turn);
|
|
1674
1685
|
continue;
|
|
1675
1686
|
}
|
|
@@ -1764,6 +1775,7 @@ function projectHistory(entries) {
|
|
|
1764
1775
|
} else if (kind === "ask_user_answer") {
|
|
1765
1776
|
const data = entry.data ?? {};
|
|
1766
1777
|
const toolCallId = String(data.tool_call_id ?? "");
|
|
1778
|
+
if (toolCallId) answeredToolCallIds.add(toolCallId);
|
|
1767
1779
|
const pending = pendingChildPauses.get(toolCallId);
|
|
1768
1780
|
if (pending) {
|
|
1769
1781
|
setToolCallStatus(latestAssistantByLoop.get(pending.childLoopId), toolCallId, "done", null, null);
|
|
@@ -1790,8 +1802,44 @@ function projectHistory(entries) {
|
|
|
1790
1802
|
);
|
|
1791
1803
|
}
|
|
1792
1804
|
}
|
|
1805
|
+
const rootAssistant = latestRootAssistant;
|
|
1806
|
+
if (rootAssistant) {
|
|
1807
|
+
for (const toolCall of rootAssistant.tool_calls) {
|
|
1808
|
+
if (answeredToolCallIds.has(toolCall.id)) continue;
|
|
1809
|
+
if (toolCall.tool_name.split(":").pop() !== "AskUserQuestion") continue;
|
|
1810
|
+
if (toolCall.status === "error" || toolCall.status === "cancelled") continue;
|
|
1811
|
+
const pauseArguments = parseToolArguments(toolCall.arguments);
|
|
1812
|
+
if (typeof toolCall.result === "string") {
|
|
1813
|
+
const resultArguments = parseToolArguments(toolCall.result);
|
|
1814
|
+
if (Array.isArray(resultArguments.questions)) {
|
|
1815
|
+
pauseArguments.questions = resultArguments.questions;
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
applyAskUserPauseToTurn(
|
|
1819
|
+
rootAssistant,
|
|
1820
|
+
{
|
|
1821
|
+
name: toolCall.tool_name,
|
|
1822
|
+
tool_call_id: toolCall.id,
|
|
1823
|
+
arguments: pauseArguments
|
|
1824
|
+
},
|
|
1825
|
+
toolCall.id,
|
|
1826
|
+
"",
|
|
1827
|
+
"",
|
|
1828
|
+
(name) => name
|
|
1829
|
+
);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1793
1832
|
return turns;
|
|
1794
1833
|
}
|
|
1834
|
+
function parseToolArguments(value) {
|
|
1835
|
+
if (!value) return {};
|
|
1836
|
+
try {
|
|
1837
|
+
const parsed = JSON.parse(value);
|
|
1838
|
+
return isRecord3(parsed) ? parsed : {};
|
|
1839
|
+
} catch {
|
|
1840
|
+
return {};
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1795
1843
|
function buildToolCalls(value) {
|
|
1796
1844
|
if (!Array.isArray(value)) return [];
|
|
1797
1845
|
return value.filter(isRecord3).map((raw) => {
|
|
@@ -4131,7 +4179,7 @@ function resolveAuthToken(options) {
|
|
|
4131
4179
|
|
|
4132
4180
|
// src/version.ts
|
|
4133
4181
|
var SDK_NAME = "agent-client";
|
|
4134
|
-
var SDK_VERSION = true ? "1.2.1-beta.
|
|
4182
|
+
var SDK_VERSION = true ? "1.2.1-beta.13" : "1.1.1";
|
|
4135
4183
|
|
|
4136
4184
|
// src/socket.ts
|
|
4137
4185
|
function withSdkIdentity(auth) {
|