@nextclaw/nextclaw-engine-claude-agent-sdk 0.2.0 → 0.2.2
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 +24 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -106,6 +106,15 @@ function readPermissionMode(input, key) {
|
|
|
106
106
|
}
|
|
107
107
|
return void 0;
|
|
108
108
|
}
|
|
109
|
+
function toAbortError(reason) {
|
|
110
|
+
if (reason instanceof Error) {
|
|
111
|
+
return reason;
|
|
112
|
+
}
|
|
113
|
+
const message = typeof reason === "string" && reason.trim() ? reason.trim() : "operation aborted";
|
|
114
|
+
const error = new Error(message);
|
|
115
|
+
error.name = "AbortError";
|
|
116
|
+
return error;
|
|
117
|
+
}
|
|
109
118
|
function readSettingSources(input, key) {
|
|
110
119
|
const list = readStringArray(input, key);
|
|
111
120
|
if (!list) {
|
|
@@ -149,6 +158,7 @@ class PluginClaudeAgentSdkEngine {
|
|
|
149
158
|
this.skillsLoader = new SkillsLoader(options.workspace);
|
|
150
159
|
}
|
|
151
160
|
kind = "claude-agent-sdk";
|
|
161
|
+
supportsAbort = true;
|
|
152
162
|
sdkModulePromise = null;
|
|
153
163
|
sessionIdsByKey = /* @__PURE__ */ new Map();
|
|
154
164
|
defaultModel;
|
|
@@ -192,6 +202,16 @@ class PluginClaudeAgentSdkEngine {
|
|
|
192
202
|
params.onSessionEvent?.(userEvent);
|
|
193
203
|
const sdk = await this.getSdkModule();
|
|
194
204
|
const abortController = new AbortController();
|
|
205
|
+
const onExternalAbort = () => {
|
|
206
|
+
if (!abortController.signal.aborted) {
|
|
207
|
+
abortController.abort(params.abortSignal?.reason);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
if (params.abortSignal?.aborted) {
|
|
211
|
+
onExternalAbort();
|
|
212
|
+
} else {
|
|
213
|
+
params.abortSignal?.addEventListener("abort", onExternalAbort, { once: true });
|
|
214
|
+
}
|
|
195
215
|
const timeout = this.createRequestTimeout(abortController);
|
|
196
216
|
const queryOptions = this.buildQueryOptions(sessionKey, model, abortController);
|
|
197
217
|
const requestedSkillsContent = this.skillsLoader.loadSkillsForContext(requestedSkills);
|
|
@@ -235,11 +255,15 @@ class PluginClaudeAgentSdkEngine {
|
|
|
235
255
|
resultReply = result.text;
|
|
236
256
|
}
|
|
237
257
|
} finally {
|
|
258
|
+
params.abortSignal?.removeEventListener("abort", onExternalAbort);
|
|
238
259
|
if (timeout !== null) {
|
|
239
260
|
clearTimeout(timeout);
|
|
240
261
|
}
|
|
241
262
|
query.close();
|
|
242
263
|
}
|
|
264
|
+
if (abortController.signal.aborted) {
|
|
265
|
+
throw toAbortError(abortController.signal.reason);
|
|
266
|
+
}
|
|
243
267
|
const assistantReply = assistantMessages.join("\n").trim();
|
|
244
268
|
const reply = assistantReply || resultReply.trim();
|
|
245
269
|
const assistantEvent = this.options.sessionManager.addMessage(session, "assistant", reply, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/nextclaw-engine-claude-agent-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "NextClaw Claude Agent SDK engine plugin backed by Anthropic official SDK.",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@anthropic-ai/claude-agent-sdk": "^0.2.63",
|
|
26
|
-
"@nextclaw/core": "^0.7.
|
|
26
|
+
"@nextclaw/core": "^0.7.5",
|
|
27
27
|
"zod": "^4.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|