@causyne/agent 1.20.0 → 1.20.7
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 +13 -9
- package/SECURITY.md +1 -4
- package/package.json +1 -1
- package/src/acp/client.js +176 -26
- package/src/acp/client.ts +167 -25
- package/src/acp/protocol.js +116 -0
- package/src/acp/protocol.ts +163 -0
- package/src/acp/server.js +5 -6
- package/src/acp/server.ts +4 -6
- package/src/agentLoop.d.ts +1 -0
- package/src/agentLoop.js +681 -245
- package/src/agentLoop.ts +708 -262
- package/src/agentPolicy.js +9 -0
- package/src/agentPolicy.ts +9 -0
- package/src/approvalPolicy.js +55 -0
- package/src/approvalPolicy.ts +66 -0
- package/src/browser/browserRuntime.js +217 -14
- package/src/browser/browserRuntime.ts +255 -14
- package/src/browser/causyneBrowser.js +1215 -68
- package/src/browser/causyneBrowser.ts +1340 -72
- package/src/cliMode.js +52 -29
- package/src/commands.js +141 -17
- package/src/config.js +22 -12
- package/src/continuum/ui/continuumPicker.js +18 -1
- package/src/continuum/ui/continuumPicker.ts +19 -1
- package/src/dynamicCatalogue.js +87 -20
- package/src/dynamicCatalogue.ts +85 -15
- package/src/launchIntent.js +40 -0
- package/src/launchIntent.ts +49 -0
- package/src/memoryManager.js +26 -2
- package/src/modelCatalogue.js +2 -0
- package/src/planCache.js +320 -11
- package/src/planCache.ts +402 -13
- package/src/providers/acp.js +173 -18
- package/src/providers/acp.ts +169 -19
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +674 -34
- package/src/providers/antigravity.ts +707 -35
- package/src/providers/base.d.ts +10 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +161 -0
- package/src/providers/pi.ts +148 -0
- package/src/provisioning/capabilityProvisioner.js +17 -0
- package/src/provisioning/capabilityTools.js +1 -1
- package/src/sandbox.js +30 -39
- package/src/sessionJournal.js +53 -10
- package/src/sessionJournal.ts +64 -10
- package/src/taskShape.js +9 -9
- package/src/taskShape.ts +9 -9
- package/src/timeMachine.js +124 -0
- package/src/timeMachine.ts +141 -0
- package/src/toolPacks.js +4 -10
- package/src/tools/archive.js +196 -59
- package/src/tools/archive.ts +220 -0
- package/src/tools/browserAutomator.js +78 -9
- package/src/tools/browserAutomator.ts +90 -9
- package/src/tools/desktopOpen.js +114 -31
- package/src/tools/desktopOpen.ts +144 -0
- package/src/tools/gitExec.js +5 -3
- package/src/tools/nativeEngine.js +4 -3
- package/src/tools/nativeEngine.ts +5 -3
- package/src/tools/openSourceToolProvisioner.js +5 -4
- package/src/tools/openSourceToolProvisioner.ts +5 -4
- package/src/tools/registry.js +3 -0
- package/src/tools/screenshot.js +55 -71
- package/src/tools/screenshot.ts +70 -0
- package/src/tools/sysRun.js +284 -117
- package/src/tools/sysRun.ts +347 -0
- package/src/tools/toolSelfRepair.js +109 -2
- package/src/tools/toolSelfRepair.ts +100 -2
- package/src/tools/updatePlan.js +49 -1
- package/src/tools/updatePlan.ts +43 -1
- package/src/tools/viewImage.js +93 -78
- package/src/tools/viewImage.ts +116 -0
- package/src/tools/webFetch.js +20 -6
- package/src/tools/webFetch.ts +26 -6
- package/src/tui/activityLayout.js +9 -0
- package/src/tui/activityLayout.ts +10 -0
- package/src/tui/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +23 -0
- package/src/tui/chatRenderer.js +49 -49
- package/src/tui/clipboardSync.js +28 -1
- package/src/tui/clipboardSync.ts +26 -1
- package/src/tui/codeProgress.js +299 -0
- package/src/tui/codeProgress.ts +304 -0
- package/src/tui/codeStreamRenderer.js +132 -0
- package/src/tui/codeStreamRenderer.ts +141 -0
- package/src/tui/commandPresentation.js +11 -0
- package/src/tui/commandPresentation.ts +18 -0
- package/src/tui/completion.js +45 -13
- package/src/tui/composerControls.js +131 -0
- package/src/tui/composerControls.ts +184 -0
- package/src/tui/diff.d.ts +2 -0
- package/src/tui/home.js +4 -2
- package/src/tui/homeTransition.js +21 -0
- package/src/tui/homeTransition.ts +27 -0
- package/src/tui/homeView.js +62 -0
- package/src/tui/homeView.ts +91 -0
- package/src/tui/layout.js +46 -0
- package/src/tui/layout.ts +52 -0
- package/src/tui/messageActionPlacement.js +16 -0
- package/src/tui/messageActionPlacement.ts +25 -0
- package/src/tui/messageInteraction.js +221 -0
- package/src/tui/messageInteraction.ts +275 -0
- package/src/tui/modelPicker.js +4 -24
- package/src/tui/modelPicker.ts +4 -20
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +175 -101
- package/src/tui/resizeRecovery.js +15 -0
- package/src/tui/resizeRecovery.ts +27 -0
- package/src/tui/scrollInteraction.js +97 -0
- package/src/tui/scrollInteraction.ts +189 -0
- package/src/tui/sessionLayout.js +12 -0
- package/src/tui/sessionLayout.ts +12 -0
- package/src/tui/sessionPicker.js +111 -16
- package/src/tui/sessionPicker.ts +121 -16
- package/src/tui/sessionSidebar.js +78 -0
- package/src/tui/sessionSidebar.ts +95 -0
- package/src/tui/setup.js +1 -1
- package/src/tui/setup.ts +1 -1
- package/src/tui/stageSurface.js +120 -58
- package/src/tui/text.d.ts +6 -0
- package/src/tui/textLayout.js +23 -0
- package/src/tui/textLayout.ts +28 -0
- package/src/tui/viewport.js +204 -279
- package/src/tui/viewport.ts +326 -0
- package/src/types/contracts.ts +54 -0
- package/src/utils/paths.js +5 -4
- package/src/utils/paths.ts +5 -5
package/src/providers/acp.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { canonicalModelId } from '../modelIds.js';
|
|
2
2
|
import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
|
|
3
|
-
import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseToolCall } from './base.js';
|
|
3
|
+
import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseToolCall, type ChatResponseAction } from './base.js';
|
|
4
4
|
import { AcpClient } from '../acp/client.js';
|
|
5
5
|
import { getPeerProfile } from '../acp/peerProfiles.js';
|
|
6
6
|
import { BUILTIN_PEER_PRESETS } from '../acp/agentCatalog.js';
|
|
@@ -19,8 +19,11 @@ export class AcpProvider extends LLMProvider {
|
|
|
19
19
|
args: string[];
|
|
20
20
|
private activeClient: AcpClient | null = null;
|
|
21
21
|
private activeSessionId: string | null = null;
|
|
22
|
+
private currentTurnAborted = false;
|
|
22
23
|
private currentTurnChunkHandler: ((chunk: string) => void) | null = null;
|
|
23
24
|
private currentTurnReasoningHandler: ((chunk: string) => void) | null = null;
|
|
25
|
+
private currentTurnNativeActionHandler: ((action: ChatResponseAction) => void) | null = null;
|
|
26
|
+
private readonly liveFileActions = new Map<string, ChatResponseAction>();
|
|
24
27
|
|
|
25
28
|
constructor(config: ProviderConfig = {}) {
|
|
26
29
|
super(config);
|
|
@@ -46,7 +49,10 @@ export class AcpProvider extends LLMProvider {
|
|
|
46
49
|
this.model = canonicalModelId(modelIsPeerName ? peerDefault : configuredModel);
|
|
47
50
|
|
|
48
51
|
const profile = getPeerProfile(this.peerId);
|
|
49
|
-
if (
|
|
52
|
+
if (config.command) {
|
|
53
|
+
this.command = config.command;
|
|
54
|
+
this.args = config.args || ['acp'];
|
|
55
|
+
} else if (profile) {
|
|
50
56
|
this.command = profile.command;
|
|
51
57
|
this.args = profile.args || [];
|
|
52
58
|
} else {
|
|
@@ -55,7 +61,7 @@ export class AcpProvider extends LLMProvider {
|
|
|
55
61
|
this.command = preset.command;
|
|
56
62
|
this.args = preset.args || [];
|
|
57
63
|
} else {
|
|
58
|
-
this.command =
|
|
64
|
+
this.command = this.peerId;
|
|
59
65
|
this.args = config.args || ['acp'];
|
|
60
66
|
}
|
|
61
67
|
}
|
|
@@ -66,7 +72,7 @@ export class AcpProvider extends LLMProvider {
|
|
|
66
72
|
|
|
67
73
|
formatConversation(messages: any[], tools: any[] = []): string {
|
|
68
74
|
const lines: string[] = [];
|
|
69
|
-
lines.push('[System Instructions]\nYou are acting as an AI reasoning engine for Causyne Agent over ACP. Do NOT invoke your own internal host CLI tools or execute commands directly. When an action or tool is required, output an explicit tool call in this exact format:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\nCausyne Agent will execute the tool in its secure environment and return the results back to you.');
|
|
75
|
+
lines.push('[System Instructions]\nYou are acting as an AI reasoning engine for Causyne Agent over ACP. Do NOT invoke your own internal host CLI tools or execute commands directly. When an action or tool is required, output an explicit tool call in this exact format:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\nCausyne Agent will execute the tool in its secure environment and return the results back to you.\n\n[Language & Communication Directive]\nDynamically reflect and match the exact language used by the user in their prompt. If the user writes in English, you must respond strictly in English. Default to English for all responses and reasoning. Never default to Indonesian.');
|
|
70
76
|
|
|
71
77
|
if (tools && tools.length > 0) {
|
|
72
78
|
const toolSummaries = tools.map(t => {
|
|
@@ -78,6 +84,8 @@ export class AcpProvider extends LLMProvider {
|
|
|
78
84
|
}).join('\n');
|
|
79
85
|
lines.push(`[Available Tools]\nYou may invoke tools when needed by outputting:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\n\n${toolSummaries}`);
|
|
80
86
|
}
|
|
87
|
+
const seenToolOutputs = new Set<string>();
|
|
88
|
+
const seenAssistantCalls = new Set<string>();
|
|
81
89
|
for (const msg of messages) {
|
|
82
90
|
const role = msg.role === 'user'
|
|
83
91
|
? 'User'
|
|
@@ -96,10 +104,23 @@ export class AcpProvider extends LLMProvider {
|
|
|
96
104
|
text = msg.content.map((c: any) => typeof c === 'string' ? c : (c?.text || '')).filter(Boolean).join('\n');
|
|
97
105
|
}
|
|
98
106
|
|
|
107
|
+
if (msg.role === 'tool' && text.trim()) {
|
|
108
|
+
const normalized = text.trim();
|
|
109
|
+
if (seenToolOutputs.has(normalized)) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
seenToolOutputs.add(normalized);
|
|
113
|
+
}
|
|
114
|
+
|
|
99
115
|
if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
|
|
100
116
|
for (const tc of msg.tool_calls) {
|
|
101
117
|
const fn = tc.function || {};
|
|
102
118
|
const fnArgs = typeof fn.arguments === 'string' ? fn.arguments : JSON.stringify(fn.arguments || {});
|
|
119
|
+
const callSig = `${fn.name}:${fnArgs}`;
|
|
120
|
+
if (seenAssistantCalls.has(callSig)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
seenAssistantCalls.add(callSig);
|
|
103
124
|
text += `\n<tool_call>{"name": "${fn.name}", "arguments": ${fnArgs}}</tool_call>`;
|
|
104
125
|
}
|
|
105
126
|
}
|
|
@@ -133,6 +154,8 @@ export class AcpProvider extends LLMProvider {
|
|
|
133
154
|
pending.push(`[Available Tools]\nYou may invoke tools when needed by outputting:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\n\n${toolSummaries}`);
|
|
134
155
|
}
|
|
135
156
|
|
|
157
|
+
const seenToolOutputs = new Set<string>();
|
|
158
|
+
const seenAssistantCalls = new Set<string>();
|
|
136
159
|
for (const msg of messages) {
|
|
137
160
|
const role = this._roleLabel(msg);
|
|
138
161
|
let text = '';
|
|
@@ -142,10 +165,23 @@ export class AcpProvider extends LLMProvider {
|
|
|
142
165
|
text = msg.content.map((c: any) => typeof c === 'string' ? c : (c?.text || '')).filter(Boolean).join('\n');
|
|
143
166
|
}
|
|
144
167
|
|
|
168
|
+
if (msg.role === 'tool' && text.trim()) {
|
|
169
|
+
const normalized = text.trim();
|
|
170
|
+
if (seenToolOutputs.has(normalized)) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
seenToolOutputs.add(normalized);
|
|
174
|
+
}
|
|
175
|
+
|
|
145
176
|
if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
|
|
146
177
|
for (const tc of msg.tool_calls) {
|
|
147
178
|
const fn = tc.function || {};
|
|
148
179
|
const fnArgs = typeof fn.arguments === 'string' ? fn.arguments : JSON.stringify(fn.arguments || {});
|
|
180
|
+
const callSig = `${fn.name}:${fnArgs}`;
|
|
181
|
+
if (seenAssistantCalls.has(callSig)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
seenAssistantCalls.add(callSig);
|
|
149
185
|
text += `\n<tool_call>{"name": "${fn.name}", "arguments": ${fnArgs}}</tool_call>`;
|
|
150
186
|
}
|
|
151
187
|
}
|
|
@@ -243,10 +279,42 @@ export class AcpProvider extends LLMProvider {
|
|
|
243
279
|
}
|
|
244
280
|
}
|
|
245
281
|
|
|
282
|
+
if (calls.length === 0) {
|
|
283
|
+
const openIndex = text.lastIndexOf('<tool_call>');
|
|
284
|
+
if (openIndex !== -1 && text.indexOf('</tool_call>', openIndex) === -1) {
|
|
285
|
+
const partial = text.slice(openIndex + '<tool_call>'.length).trim();
|
|
286
|
+
for (const suffix of ['', '}', '}}', '}}}', '"}', '"}}', '"}}}', '"}]}}', '"]}}', '"]}}}']) {
|
|
287
|
+
try {
|
|
288
|
+
const parsed = JSON.parse(partial + suffix);
|
|
289
|
+
const name = parsed.name || parsed.tool || parsed.function?.name;
|
|
290
|
+
if (name) {
|
|
291
|
+
const rawArgs = parsed.arguments !== undefined ? parsed.arguments : (parsed.parameters !== undefined ? parsed.parameters : (parsed.input !== undefined ? parsed.input : (parsed.function?.arguments || {})));
|
|
292
|
+
calls.push({
|
|
293
|
+
id: `acp_call_${Date.now()}_0`,
|
|
294
|
+
type: 'function',
|
|
295
|
+
function: {
|
|
296
|
+
name,
|
|
297
|
+
arguments: typeof rawArgs === 'string' ? rawArgs : JSON.stringify(rawArgs || {})
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
} catch {
|
|
303
|
+
// try next candidate
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
246
309
|
return calls;
|
|
247
310
|
}
|
|
248
311
|
|
|
249
|
-
private async getOrCreateClient(): Promise<{ client: AcpClient; sessionId: string }> {
|
|
312
|
+
private async getOrCreateClient(signal?: AbortSignal): Promise<{ client: AcpClient; sessionId: string }> {
|
|
313
|
+
if (signal?.aborted) {
|
|
314
|
+
const abortErr = new Error('ACP request aborted by user');
|
|
315
|
+
abortErr.name = 'AbortError';
|
|
316
|
+
throw abortErr;
|
|
317
|
+
}
|
|
250
318
|
if (this.activeClient && this.activeSessionId) {
|
|
251
319
|
return { client: this.activeClient, sessionId: this.activeSessionId };
|
|
252
320
|
}
|
|
@@ -255,13 +323,15 @@ export class AcpProvider extends LLMProvider {
|
|
|
255
323
|
command: this.command,
|
|
256
324
|
args: this.args,
|
|
257
325
|
cwd: process.cwd(),
|
|
258
|
-
promptTimeoutMs:
|
|
326
|
+
promptTimeoutMs: 900_000,
|
|
259
327
|
permissionHandler: async (req: RequestPermissionRequest) => {
|
|
328
|
+
if (this.currentTurnAborted || signal?.aborted) return { outcome: 'cancelled' };
|
|
260
329
|
const allowOpt = req.options?.find(o => o.kind === 'allow_once' || o.kind === 'allow_always' || o.optionId === 'allow');
|
|
261
330
|
if (allowOpt) return { outcome: 'selected', optionId: allowOpt.optionId };
|
|
262
331
|
return { outcome: 'cancelled' };
|
|
263
332
|
},
|
|
264
333
|
onUpdate: (_sessionId: string, update: SessionUpdate) => {
|
|
334
|
+
if (this.currentTurnAborted) return;
|
|
265
335
|
if (update && typeof update === 'object') {
|
|
266
336
|
const updateObj = update as any;
|
|
267
337
|
if (updateObj.sessionUpdate === 'agent_thought_chunk') {
|
|
@@ -269,6 +339,32 @@ export class AcpProvider extends LLMProvider {
|
|
|
269
339
|
if (thought && this.currentTurnReasoningHandler) {
|
|
270
340
|
this.currentTurnReasoningHandler(thought);
|
|
271
341
|
}
|
|
342
|
+
} else if (updateObj.sessionUpdate === 'agent_message_chunk') {
|
|
343
|
+
const text = updateObj.content?.type === 'text' ? updateObj.content.text : '';
|
|
344
|
+
if (text && this.currentTurnChunkHandler) this.currentTurnChunkHandler(text);
|
|
345
|
+
} else if (updateObj.sessionUpdate === 'tool_call' || updateObj.sessionUpdate === 'tool_call_update') {
|
|
346
|
+
const id = String(updateObj.toolCallId || '');
|
|
347
|
+
const earlier = this.liveFileActions.get(id);
|
|
348
|
+
const kind = updateObj.kind || (earlier?.name === 'fs_edit' ? 'edit' : earlier?.name === 'fs_delete' ? 'delete' : earlier?.name === 'fs_move' ? 'move' : '');
|
|
349
|
+
const name = kind === 'edit' ? 'fs_edit' : kind === 'delete' ? 'fs_delete' : kind === 'move' ? 'fs_move' : '';
|
|
350
|
+
if (name && id) {
|
|
351
|
+
const diff = Array.isArray(updateObj.content)
|
|
352
|
+
? updateObj.content.find((item: any) => item?.type === 'diff')
|
|
353
|
+
: null;
|
|
354
|
+
const input = updateObj.rawInput && typeof updateObj.rawInput === 'object' ? updateObj.rawInput : {};
|
|
355
|
+
const parameters: Record<string, unknown> = {
|
|
356
|
+
...(earlier?.parameters || {}), ...input,
|
|
357
|
+
...(diff?.path ? { path: diff.path } : {}),
|
|
358
|
+
...(diff?.newText ? { content: diff.newText } : {}),
|
|
359
|
+
...(updateObj.locations?.[0]?.path ? { path: updateObj.locations[0].path } : {})
|
|
360
|
+
};
|
|
361
|
+
const status = updateObj.status === 'completed' ? 'completed' : updateObj.status === 'failed' ? 'failed' : 'running';
|
|
362
|
+
const action: ChatResponseAction = { name, status, parameters,
|
|
363
|
+
detail: String(parameters.path || updateObj.title || '') };
|
|
364
|
+
if (status === 'running') this.liveFileActions.set(id, action);
|
|
365
|
+
else this.liveFileActions.delete(id);
|
|
366
|
+
this.currentTurnNativeActionHandler?.(action);
|
|
367
|
+
}
|
|
272
368
|
} else if ('textDelta' in updateObj) {
|
|
273
369
|
const delta = updateObj.textDelta;
|
|
274
370
|
if (delta && typeof delta === 'string' && this.currentTurnChunkHandler) {
|
|
@@ -279,8 +375,8 @@ export class AcpProvider extends LLMProvider {
|
|
|
279
375
|
}
|
|
280
376
|
});
|
|
281
377
|
|
|
282
|
-
await client.start();
|
|
283
|
-
const sessionId = await client.newSession(process.cwd());
|
|
378
|
+
await client.start(signal);
|
|
379
|
+
const sessionId = await client.newSession(process.cwd(), [], signal);
|
|
284
380
|
|
|
285
381
|
let targetModel = this.model;
|
|
286
382
|
if (this.peerId === 'opencode' && targetModel !== this.peerId && !targetModel.startsWith('opencode/')) {
|
|
@@ -288,8 +384,12 @@ export class AcpProvider extends LLMProvider {
|
|
|
288
384
|
}
|
|
289
385
|
if (targetModel && targetModel !== 'acp' && targetModel !== this.peerId) {
|
|
290
386
|
try {
|
|
291
|
-
await client.setSessionModel(sessionId, targetModel);
|
|
292
|
-
} catch {
|
|
387
|
+
await client.setSessionModel(sessionId, targetModel, signal);
|
|
388
|
+
} catch (err: any) {
|
|
389
|
+
if (this.currentTurnAborted || signal?.aborted || err?.name === 'AbortError') {
|
|
390
|
+
await client.close();
|
|
391
|
+
throw err;
|
|
392
|
+
}
|
|
293
393
|
// peer does not support setSessionModel
|
|
294
394
|
}
|
|
295
395
|
}
|
|
@@ -299,23 +399,52 @@ export class AcpProvider extends LLMProvider {
|
|
|
299
399
|
return { client, sessionId };
|
|
300
400
|
}
|
|
301
401
|
|
|
402
|
+
abort(): void {
|
|
403
|
+
this.currentTurnAborted = true;
|
|
404
|
+
this.currentTurnChunkHandler = null;
|
|
405
|
+
this.currentTurnReasoningHandler = null;
|
|
406
|
+
this.currentTurnNativeActionHandler = null;
|
|
407
|
+
this.liveFileActions.clear();
|
|
408
|
+
if (this.activeClient && this.activeSessionId) {
|
|
409
|
+
try {
|
|
410
|
+
this.activeClient.notifyCancel(this.activeSessionId);
|
|
411
|
+
} catch {
|
|
412
|
+
// ignore cancel write error
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
void this.close();
|
|
416
|
+
}
|
|
417
|
+
|
|
302
418
|
async close(): Promise<void> {
|
|
303
|
-
|
|
419
|
+
const client = this.activeClient;
|
|
420
|
+
this.activeClient = null;
|
|
421
|
+
this.activeSessionId = null;
|
|
422
|
+
if (client) {
|
|
304
423
|
try {
|
|
305
|
-
await
|
|
424
|
+
await client.close();
|
|
306
425
|
} catch {
|
|
307
426
|
// ignore close error
|
|
308
427
|
}
|
|
309
|
-
this.activeClient = null;
|
|
310
|
-
this.activeSessionId = null;
|
|
311
428
|
}
|
|
312
429
|
}
|
|
313
430
|
|
|
314
431
|
override async chat(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
|
|
432
|
+
this.currentTurnAborted = Boolean(options.signal?.aborted);
|
|
433
|
+
if (this.currentTurnAborted) {
|
|
434
|
+
const abortErr = new Error('ACP request aborted by user');
|
|
435
|
+
abortErr.name = 'AbortError';
|
|
436
|
+
throw abortErr;
|
|
437
|
+
}
|
|
315
438
|
this.currentTurnChunkHandler = options.onChunk || null;
|
|
316
439
|
this.currentTurnReasoningHandler = options.onReasoningChunk || null;
|
|
440
|
+
this.currentTurnNativeActionHandler = options.onNativeAction || null;
|
|
441
|
+
this.liveFileActions.clear();
|
|
442
|
+
const onAbort = (): void => {
|
|
443
|
+
this.abort();
|
|
444
|
+
};
|
|
445
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
317
446
|
try {
|
|
318
|
-
const { client, sessionId } = await this.getOrCreateClient();
|
|
447
|
+
const { client, sessionId } = await this.getOrCreateClient(options.signal);
|
|
319
448
|
|
|
320
449
|
const supportsImages = client.agentCapabilities?.promptCapabilities?.image === true;
|
|
321
450
|
const promptBlocks = this.formatPromptBlocks(messages, options.tools, supportsImages);
|
|
@@ -323,12 +452,21 @@ export class AcpProvider extends LLMProvider {
|
|
|
323
452
|
|
|
324
453
|
let result;
|
|
325
454
|
try {
|
|
326
|
-
result = await client.prompt(sessionId, promptBlocks);
|
|
455
|
+
result = await client.prompt(sessionId, promptBlocks, options.signal);
|
|
327
456
|
} catch (promptErr: any) {
|
|
328
|
-
|
|
457
|
+
if (this.currentTurnAborted || options.signal?.aborted || promptErr?.name === 'AbortError') {
|
|
458
|
+
throw promptErr;
|
|
459
|
+
}
|
|
460
|
+
// If peer failed before any user abort, try recreating client once in case connection dropped
|
|
329
461
|
await this.close();
|
|
330
|
-
const fresh = await this.getOrCreateClient();
|
|
331
|
-
result = await fresh.client.prompt(fresh.sessionId, promptBlocks);
|
|
462
|
+
const fresh = await this.getOrCreateClient(options.signal);
|
|
463
|
+
result = await fresh.client.prompt(fresh.sessionId, promptBlocks, options.signal);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (this.currentTurnAborted || options.signal?.aborted) {
|
|
467
|
+
const abortErr = new Error('ACP request aborted by user');
|
|
468
|
+
abortErr.name = 'AbortError';
|
|
469
|
+
throw abortErr;
|
|
332
470
|
}
|
|
333
471
|
|
|
334
472
|
let rawContent = (result?.text || '').trim();
|
|
@@ -348,13 +486,25 @@ export class AcpProvider extends LLMProvider {
|
|
|
348
486
|
if (toolCalls.length > 0) {
|
|
349
487
|
response.toolCalls = toolCalls;
|
|
350
488
|
}
|
|
489
|
+
if (result?.stopReason === 'max_tokens' || result?.stopReason === 'max_turn_requests') {
|
|
490
|
+
response.incompleteTurn = true;
|
|
491
|
+
}
|
|
351
492
|
return response;
|
|
352
493
|
} catch (err: any) {
|
|
353
494
|
await this.close();
|
|
495
|
+
if (this.currentTurnAborted || options.signal?.aborted || err?.name === 'AbortError') {
|
|
496
|
+
const abortErr = new Error('ACP request aborted by user');
|
|
497
|
+
abortErr.name = 'AbortError';
|
|
498
|
+
throw abortErr;
|
|
499
|
+
}
|
|
354
500
|
const msg = err instanceof Error ? err.message : String(err);
|
|
355
501
|
throw new Error(`ACP Peer Agent (${this.peerId}) Error: ${msg}. Make sure "${this.command}" is installed and running.`);
|
|
356
502
|
} finally {
|
|
503
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
357
504
|
this.currentTurnChunkHandler = null;
|
|
505
|
+
this.currentTurnReasoningHandler = null;
|
|
506
|
+
this.currentTurnNativeActionHandler = null;
|
|
507
|
+
this.liveFileActions.clear();
|
|
358
508
|
}
|
|
359
509
|
}
|
|
360
510
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
export const BASELINE_ANTIGRAVITY_MODELS: Record<string, string>;
|
|
1
2
|
export const ANTIGRAVITY_MODELS: string[];
|
|
2
3
|
export const ANTIGRAVITY_MODEL_IDS: Record<string, string>;
|
|
3
4
|
export const ANTIGRAVITY_LABEL_BY_ID: Record<string, string>;
|
|
4
|
-
export function
|
|
5
|
+
export function registerAntigravityModel(slug: string, label?: string): void;
|
|
6
|
+
export function parseAgyModelsOutput(stdout: string): Array<{ id: string; label: string }>;
|
|
7
|
+
export function resolveAgyModelId(model: string | null | undefined): string;
|
|
8
|
+
export function resolveAgyEffort(model: string | null | undefined): string;
|
|
5
9
|
export function isAntigravityProvider(provider: string | null | undefined): boolean;
|
|
6
10
|
export function resolveAgyBinary(): string;
|
|
7
11
|
export class AntigravityProvider {
|