@causyne/agent 1.17.0 → 1.19.0
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/package.json +1 -1
- package/src/agentLoop.js +2348 -2518
- package/src/agentLoop.ts +2865 -0
- package/src/checkpoints.d.ts +4 -0
- package/src/cliMode.js +10 -3
- package/src/commands.js +274 -25
- package/src/config.js +22 -0
- package/src/contextManager.d.ts +10 -0
- package/src/continuum/adapters/antigravity.js +193 -0
- package/src/continuum/adapters/antigravity.ts +204 -0
- package/src/continuum/adapters/base.js +48 -0
- package/src/continuum/adapters/base.ts +57 -0
- package/src/continuum/adapters/causyne.js +66 -0
- package/src/continuum/adapters/causyne.ts +72 -0
- package/src/continuum/adapters/claudeCode.js +171 -0
- package/src/continuum/adapters/claudeCode.ts +179 -0
- package/src/continuum/adapters/codex.js +181 -0
- package/src/continuum/adapters/codex.ts +193 -0
- package/src/continuum/adapters/opencode.js +134 -0
- package/src/continuum/adapters/opencode.ts +153 -0
- package/src/continuum/compactor.js +54 -0
- package/src/continuum/compactor.ts +83 -0
- package/src/continuum/index.js +8 -0
- package/src/continuum/index.ts +9 -0
- package/src/continuum/ingest.js +63 -0
- package/src/continuum/ingest.ts +89 -0
- package/src/continuum/sanitizer.js +55 -0
- package/src/continuum/sanitizer.ts +59 -0
- package/src/continuum/scanner.js +86 -0
- package/src/continuum/scanner.ts +106 -0
- package/src/continuum/types.js +3 -0
- package/src/continuum/types.ts +51 -0
- package/src/continuum/ui/continuumPicker.js +111 -0
- package/src/continuum/ui/continuumPicker.ts +145 -0
- package/src/cortex/autoCondenser.d.ts +2 -0
- package/src/cortex/vectorDb.d.ts +1 -0
- package/src/designPalettes.d.ts +2 -0
- package/src/devMode.d.ts +1 -0
- package/src/dynamicCatalogue.js +140 -1
- package/src/dynamicCatalogue.ts +179 -1
- package/src/embodimentSession.d.ts +2 -0
- package/src/entrypoint.js +12 -0
- package/src/memory.d.ts +1 -0
- package/src/memoryManager.d.ts +1 -0
- package/src/modelIds.d.ts +2 -0
- package/src/outputStore.d.ts +4 -0
- package/src/providers/acp.js +321 -267
- package/src/providers/acp.ts +360 -0
- package/src/providers/antigravity.js +389 -239
- package/src/providers/antigravity.ts +450 -0
- package/src/providers/base.d.ts +68 -0
- package/src/providers/factory.d.ts +1 -0
- package/src/provisioning/capabilityProvisioner.d.ts +2 -0
- package/src/sandbox.d.ts +1 -0
- package/src/skillsManager.d.ts +3 -0
- package/src/slopDetector.d.ts +3 -0
- package/src/taskBuffer.d.ts +1 -0
- package/src/tokenTracker.d.ts +1 -0
- package/src/toolPacks.d.ts +8 -0
- package/src/tools/registry.d.ts +4 -0
- package/src/tui/chatRenderer.js +71 -12
- package/src/tui/clipboardSync.js +36 -0
- package/src/tui/clipboardSync.ts +36 -0
- package/src/tui/dialogs.js +15 -2
- package/src/tui/home.js +27 -25
- package/src/tui/modelPicker.js +221 -0
- package/src/tui/modelPicker.ts +290 -0
- package/src/tui/prompt.js +17 -6
- package/src/tui/selectList.js +20 -0
- package/src/tui/theme.js +4 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseToolCall } from './base.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Display label → the id `agy --model` actually accepts, exactly as reported
|
|
8
|
+
* by `agy models`. The CLI exposes slugs; the picker shows the readable label.
|
|
9
|
+
* Passing the label through unchanged is what a user would try, so both forms
|
|
10
|
+
* resolve here rather than failing at the provider.
|
|
11
|
+
*/
|
|
12
|
+
export const ANTIGRAVITY_MODEL_IDS: Record<string, string> = {
|
|
13
|
+
'Gemini 3.8 Flash (Low)': 'gemini-3.8-flash-low',
|
|
14
|
+
'Gemini 3.8 Flash (Medium)': 'gemini-3.8-flash-medium',
|
|
15
|
+
'Gemini 3.8 Flash (High)': 'gemini-3.8-flash-high',
|
|
16
|
+
'Gemini 4 Argon (Low)': 'gemini-4-argon-low',
|
|
17
|
+
'Gemini 4 Argon (Medium)': 'gemini-4-argon-medium',
|
|
18
|
+
'Gemini 4 Argon (High)': 'gemini-4-argon-high',
|
|
19
|
+
'Claude Sonnet 5.5 (Low)': 'claude-sonnet-5-5-low',
|
|
20
|
+
'Claude Sonnet 5.5 (Medium)': 'claude-sonnet-5-5-medium',
|
|
21
|
+
'Claude Sonnet 5.5 (High)': 'claude-sonnet-5-5-high',
|
|
22
|
+
'Claude Opus 5.5 (Low)': 'claude-opus-5-5-low',
|
|
23
|
+
'Claude Opus 5.5 (Medium)': 'claude-opus-5-5-medium',
|
|
24
|
+
'Claude Opus 5.5 (High)': 'claude-opus-5-5-high',
|
|
25
|
+
'GPT-OSS 120B (Medium)': 'gpt-oss-120b-medium'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const ANTIGRAVITY_LABEL_BY_ID: Record<string, string> = Object.fromEntries(
|
|
29
|
+
Object.entries(ANTIGRAVITY_MODEL_IDS).map(([label, id]) => [id, label])
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const ANTIGRAVITY_MODELS: string[] = Object.keys(ANTIGRAVITY_MODEL_IDS);
|
|
33
|
+
|
|
34
|
+
export function resolveAgyModelId(model?: string | null): string {
|
|
35
|
+
if (typeof model !== 'string') return '';
|
|
36
|
+
const trimmed = model.trim();
|
|
37
|
+
return ANTIGRAVITY_MODEL_IDS[trimmed] || trimmed;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function resolveAgyEffort(model?: string | null): string {
|
|
41
|
+
if (typeof model !== 'string') return 'low';
|
|
42
|
+
const m = model.toLowerCase();
|
|
43
|
+
if (m.includes('(low)') || m.includes('-low')) return 'low';
|
|
44
|
+
if (m.includes('(medium)') || m.includes('-medium')) return 'medium';
|
|
45
|
+
if (m.includes('(high)') || m.includes('-high')) return 'high';
|
|
46
|
+
if (m.includes('(xhigh)') || m.includes('-xhigh')) return 'xhigh';
|
|
47
|
+
if (m.includes('(max)') || m.includes('-max')) return 'max';
|
|
48
|
+
return 'low';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isAntigravityProvider(provider?: string | null): boolean {
|
|
52
|
+
if (!provider) return false;
|
|
53
|
+
const p = String(provider).toLowerCase();
|
|
54
|
+
return p === 'antigravity' || p === 'agy' || p.startsWith('antigravity/') || p.startsWith('agy/');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function resolveAgyBinary(): string {
|
|
58
|
+
const envPath = process.env.PATH || '';
|
|
59
|
+
const searchDirs = [
|
|
60
|
+
...envPath.split(path.delimiter),
|
|
61
|
+
path.join(process.env.HOME || '', '.local/bin'),
|
|
62
|
+
path.join(process.env.HOME || '', '.antigravity/antigravity/bin'),
|
|
63
|
+
path.join(process.env.HOME || '', '.gemini/antigravity-ide/bin'),
|
|
64
|
+
'/Applications/Antigravity.app/Contents/Resources/app/bin',
|
|
65
|
+
'/Applications/Antigravity IDE.app/Contents/Resources/app/bin'
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const binNames = ['agy', 'antigravity'];
|
|
69
|
+
for (const dir of searchDirs) {
|
|
70
|
+
if (!dir) continue;
|
|
71
|
+
for (const name of binNames) {
|
|
72
|
+
const full = path.join(dir, name);
|
|
73
|
+
try {
|
|
74
|
+
if (fs.existsSync(full) && fs.statSync(full).isFile()) {
|
|
75
|
+
return full;
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
// ignore inaccessible path
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return 'agy';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class AntigravityProvider extends LLMProvider {
|
|
86
|
+
command: string;
|
|
87
|
+
|
|
88
|
+
constructor(config: ProviderConfig = {}) {
|
|
89
|
+
super(config);
|
|
90
|
+
this.model = config.model || 'Gemini 3.8 Flash (Low)';
|
|
91
|
+
this.command = config.command || resolveAgyBinary();
|
|
92
|
+
this.visionModels = [];
|
|
93
|
+
this.audioModels = [];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
formatConversation(messages: any[], tools: any[] = []): string {
|
|
97
|
+
const lines: string[] = [];
|
|
98
|
+
|
|
99
|
+
// Core System boundary instructions
|
|
100
|
+
lines.push(
|
|
101
|
+
'[System Instructions]\n' +
|
|
102
|
+
'You are acting as an AI reasoning engine for Causyne Agent. Do NOT invoke your own internal host CLI tools or execute commands directly. ' +
|
|
103
|
+
'When an action or tool is required, output an explicit tool call in this exact format:\n' +
|
|
104
|
+
'<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\n' +
|
|
105
|
+
'Causyne Agent will execute the tool in its secure environment and return the results back to you.'
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
if (tools && tools.length > 0) {
|
|
109
|
+
const toolSummaries = tools.map(t => {
|
|
110
|
+
const name = t.name || t.function?.name || 'unknown';
|
|
111
|
+
const desc = t.description || t.function?.description || '';
|
|
112
|
+
const params = t.parameters || t.input_schema || t.function?.parameters || {};
|
|
113
|
+
const paramKeys = Object.keys(params.properties || {}).join(', ');
|
|
114
|
+
return `- ${name}(${paramKeys}): ${desc}`;
|
|
115
|
+
}).join('\n');
|
|
116
|
+
lines.push(
|
|
117
|
+
`[Available Tools]\nYou may invoke tools when needed by outputting:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\n\n${toolSummaries}`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (const msg of messages) {
|
|
122
|
+
const role = msg.role === 'user'
|
|
123
|
+
? 'User'
|
|
124
|
+
: (msg.role === 'assistant'
|
|
125
|
+
? 'Assistant'
|
|
126
|
+
: (msg.role === 'system'
|
|
127
|
+
? 'System Instructions'
|
|
128
|
+
: (msg.role === 'tool'
|
|
129
|
+
? `Tool Result (${msg.name || 'tool'})`
|
|
130
|
+
: 'Context')));
|
|
131
|
+
|
|
132
|
+
let text = '';
|
|
133
|
+
if (typeof msg.content === 'string') {
|
|
134
|
+
text = msg.content;
|
|
135
|
+
} else if (Array.isArray(msg.content)) {
|
|
136
|
+
text = msg.content.map((c: any) => typeof c === 'string' ? c : (c?.text || '')).filter(Boolean).join('\n');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
|
|
140
|
+
for (const tc of msg.tool_calls) {
|
|
141
|
+
const fn = tc.function || {};
|
|
142
|
+
const fnArgs = typeof fn.arguments === 'string' ? fn.arguments : JSON.stringify(fn.arguments || {});
|
|
143
|
+
text += `\n<tool_call>{"name": "${fn.name}", "arguments": ${fnArgs}}</tool_call>`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (text.trim()) {
|
|
148
|
+
lines.push(`[${role}]\n${text.trim()}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return lines.join('\n\n');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
extractToolCalls(text: string): ChatResponseToolCall[] {
|
|
155
|
+
const calls: ChatResponseToolCall[] = [];
|
|
156
|
+
if (!text || typeof text !== 'string') return calls;
|
|
157
|
+
const regex = /<tool_call>([\s\S]*?)<\/tool_call>/g;
|
|
158
|
+
let match: RegExpExecArray | null;
|
|
159
|
+
let index = 0;
|
|
160
|
+
while ((match = regex.exec(text)) !== null) {
|
|
161
|
+
try {
|
|
162
|
+
const raw = match[1]?.trim() || '';
|
|
163
|
+
const parsed = JSON.parse(raw);
|
|
164
|
+
const name = parsed.name || parsed.tool || parsed.function?.name;
|
|
165
|
+
if (name) {
|
|
166
|
+
const rawArgs = parsed.arguments !== undefined ? parsed.arguments : (parsed.parameters !== undefined ? parsed.parameters : (parsed.input !== undefined ? parsed.input : (parsed.function?.arguments || {})));
|
|
167
|
+
calls.push({
|
|
168
|
+
id: `agy_call_${Date.now()}_${index++}`,
|
|
169
|
+
type: 'function',
|
|
170
|
+
function: {
|
|
171
|
+
name,
|
|
172
|
+
arguments: typeof rawArgs === 'string' ? rawArgs : JSON.stringify(rawArgs || {})
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
} catch {
|
|
177
|
+
// ignore malformed tool_call blocks
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (calls.length === 0) {
|
|
182
|
+
const fenceRegex = /```(?:tool_call|json)?\s*(\{[\s\S]*?"name"\s*:\s*[\s\S]*?\})\s*```/g;
|
|
183
|
+
while ((match = fenceRegex.exec(text)) !== null) {
|
|
184
|
+
try {
|
|
185
|
+
const raw = match[1]?.trim() || '';
|
|
186
|
+
const parsed = JSON.parse(raw);
|
|
187
|
+
const name = parsed.name || parsed.tool || parsed.function?.name;
|
|
188
|
+
if (name) {
|
|
189
|
+
const rawArgs = parsed.arguments !== undefined ? parsed.arguments : (parsed.parameters !== undefined ? parsed.parameters : (parsed.input !== undefined ? parsed.input : (parsed.function?.arguments || {})));
|
|
190
|
+
calls.push({
|
|
191
|
+
id: `agy_call_${Date.now()}_${index++}`,
|
|
192
|
+
type: 'function',
|
|
193
|
+
function: {
|
|
194
|
+
name,
|
|
195
|
+
arguments: typeof rawArgs === 'string' ? rawArgs : JSON.stringify(rawArgs || {})
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
} catch {
|
|
200
|
+
// ignore
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return calls;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
_isTransientError(errMessage: string): boolean {
|
|
209
|
+
if (!errMessage) return false;
|
|
210
|
+
const msg = String(errMessage).toLowerCase();
|
|
211
|
+
return msg.includes('connection reset') ||
|
|
212
|
+
msg.includes('econnreset') ||
|
|
213
|
+
msg.includes('etimedout') ||
|
|
214
|
+
msg.includes('streamgeneratecontent') ||
|
|
215
|
+
msg.includes('socket hang up') ||
|
|
216
|
+
msg.includes('network error') ||
|
|
217
|
+
msg.includes('temporarily unavailable') ||
|
|
218
|
+
msg.includes('status 503') ||
|
|
219
|
+
msg.includes('status 504') ||
|
|
220
|
+
msg.includes('status 429');
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async _executeOnce(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
|
|
224
|
+
const promptText = this.formatConversation(messages, options.tools);
|
|
225
|
+
const modelSlug = resolveAgyModelId(this.model);
|
|
226
|
+
const effort = resolveAgyEffort(this.model);
|
|
227
|
+
|
|
228
|
+
// Standard high-performance non-blocking CLI invocation:
|
|
229
|
+
// 1. stream-json output for real-time responsiveness and non-buffering progress.
|
|
230
|
+
// 2. --disable-slash-commands prevents sluggish filesystem and customization scans.
|
|
231
|
+
// 3. -p - pipes prompt from stdin to avoid OS argument length bottlenecks.
|
|
232
|
+
// 4. --print-timeout 120s protects against unhandled deadlocks.
|
|
233
|
+
const args = [
|
|
234
|
+
'--output-format',
|
|
235
|
+
'stream-json',
|
|
236
|
+
'--disable-slash-commands',
|
|
237
|
+
'--print-timeout',
|
|
238
|
+
'120s',
|
|
239
|
+
'--dangerously-skip-permissions',
|
|
240
|
+
'--model',
|
|
241
|
+
modelSlug,
|
|
242
|
+
'--effort',
|
|
243
|
+
effort,
|
|
244
|
+
'-p',
|
|
245
|
+
'-'
|
|
246
|
+
];
|
|
247
|
+
|
|
248
|
+
return new Promise<ChatResponse>((resolve, reject) => {
|
|
249
|
+
let isSettled = false;
|
|
250
|
+
const child = spawn(this.command, args, {
|
|
251
|
+
cwd: process.cwd(),
|
|
252
|
+
env: process.env,
|
|
253
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
254
|
+
windowsHide: true
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
let stdoutBuffer = '';
|
|
258
|
+
let stderrBuffer = '';
|
|
259
|
+
let streamedResponse = '';
|
|
260
|
+
let finalResultObj: any = null;
|
|
261
|
+
|
|
262
|
+
const cleanup = () => {
|
|
263
|
+
if (options.signal) {
|
|
264
|
+
options.signal.removeEventListener('abort', onAbort);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const safeReject = (err: Error) => {
|
|
269
|
+
if (isSettled) return;
|
|
270
|
+
isSettled = true;
|
|
271
|
+
cleanup();
|
|
272
|
+
reject(err);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const safeResolve = (res: ChatResponse) => {
|
|
276
|
+
if (isSettled) return;
|
|
277
|
+
isSettled = true;
|
|
278
|
+
cleanup();
|
|
279
|
+
resolve(res);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const onAbort = () => {
|
|
283
|
+
try {
|
|
284
|
+
child.kill('SIGTERM');
|
|
285
|
+
setTimeout(() => {
|
|
286
|
+
if (!child.killed) child.kill('SIGKILL');
|
|
287
|
+
}, 1000).unref();
|
|
288
|
+
} catch {
|
|
289
|
+
// ignore kill errors
|
|
290
|
+
}
|
|
291
|
+
safeReject(new Error('Turn aborted by user or timeout.'));
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
if (options.signal) {
|
|
295
|
+
if (options.signal.aborted) {
|
|
296
|
+
onAbort();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
options.signal.addEventListener('abort', onAbort, { once: true });
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Feed prompt directly into child process stdin, then close stdin
|
|
303
|
+
try {
|
|
304
|
+
child.stdin.write(promptText, 'utf8');
|
|
305
|
+
child.stdin.end();
|
|
306
|
+
} catch (err: any) {
|
|
307
|
+
safeReject(new Error(`Failed to pipe prompt to Antigravity CLI: ${err.message}`));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
child.stdout.setEncoding('utf8');
|
|
312
|
+
child.stdout.on('data', (chunk: string) => {
|
|
313
|
+
stdoutBuffer += chunk;
|
|
314
|
+
|
|
315
|
+
// Process line-delimited stream-json events
|
|
316
|
+
const lines = stdoutBuffer.split('\n');
|
|
317
|
+
stdoutBuffer = lines.pop() || ''; // Keep incomplete trailing fragment in buffer
|
|
318
|
+
|
|
319
|
+
for (const line of lines) {
|
|
320
|
+
const trimmed = line.trim();
|
|
321
|
+
if (!trimmed) continue;
|
|
322
|
+
try {
|
|
323
|
+
const event = JSON.parse(trimmed);
|
|
324
|
+
if (event.event === 'step_update') {
|
|
325
|
+
const stepUpdate = event.step_update;
|
|
326
|
+
const delta = stepUpdate?.text_delta;
|
|
327
|
+
const stepType = stepUpdate?.step_type;
|
|
328
|
+
if (delta && typeof delta === 'string') {
|
|
329
|
+
if (stepType === 'thought' || stepType === 'agent_thought') {
|
|
330
|
+
if (typeof options.onReasoningChunk === 'function') {
|
|
331
|
+
options.onReasoningChunk(delta);
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
streamedResponse += delta;
|
|
335
|
+
if (typeof options.onChunk === 'function') {
|
|
336
|
+
options.onChunk(delta);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
} else if (event.event === 'result') {
|
|
341
|
+
finalResultObj = event.result;
|
|
342
|
+
} else if (event.status === 'ERROR') {
|
|
343
|
+
safeReject(new Error(`Antigravity Agent returned error: ${event.error || 'Unknown error'}`));
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
} catch {
|
|
347
|
+
// Non-JSON line (fallback log)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
child.stderr.setEncoding('utf8');
|
|
353
|
+
child.stderr.on('data', (chunk: string) => {
|
|
354
|
+
stderrBuffer += chunk;
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
child.on('error', (err: Error) => {
|
|
358
|
+
safeReject(new Error(`Antigravity Agent (agy) spawn error: ${err.message}. Make sure Antigravity CLI is installed.`));
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
child.on('close', (code: number | null) => {
|
|
362
|
+
// Process any remaining bytes in stdoutBuffer
|
|
363
|
+
if (stdoutBuffer.trim()) {
|
|
364
|
+
try {
|
|
365
|
+
const event = JSON.parse(stdoutBuffer.trim());
|
|
366
|
+
if (event.event === 'result') {
|
|
367
|
+
finalResultObj = event.result;
|
|
368
|
+
} else if (event.status === 'ERROR') {
|
|
369
|
+
safeReject(new Error(`Antigravity Agent returned error: ${event.error || 'Unknown error'}`));
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
} catch {
|
|
373
|
+
// ignore
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (code !== 0 && !streamedResponse && !finalResultObj) {
|
|
378
|
+
const errDetail = stderrBuffer.trim() || `exit code ${code}`;
|
|
379
|
+
safeReject(new Error(`Antigravity Agent (agy) failed: ${errDetail}`));
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
let rawContent = (finalResultObj?.response || streamedResponse || '').trim();
|
|
384
|
+
let extractedReasoning = finalResultObj?.reasoning || finalResultObj?.thought || '';
|
|
385
|
+
|
|
386
|
+
// Extract <thought> or <thinking> blocks if present in rawContent
|
|
387
|
+
const thoughtMatch = /<(?:thought|thinking)>([\s\S]*?)<\/(?:thought|thinking)>/i.exec(rawContent);
|
|
388
|
+
if (thoughtMatch && thoughtMatch[1]) {
|
|
389
|
+
extractedReasoning = (extractedReasoning ? extractedReasoning + '\n' : '') + thoughtMatch[1].trim();
|
|
390
|
+
rawContent = rawContent.replace(/<(?:thought|thinking)>[\s\S]*?<\/(?:thought|thinking)>/gi, '').trim();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const toolCalls = this.extractToolCalls(rawContent);
|
|
394
|
+
|
|
395
|
+
// Strip tool call tags from prose so raw XML does not leak into chat display
|
|
396
|
+
let content = rawContent.replace(/<tool_call>[\s\S]*?<\/tool_call>/g, '').trim();
|
|
397
|
+
|
|
398
|
+
if (!content && Array.isArray(finalResultObj?.denied_actions) && finalResultObj.denied_actions.length > 0) {
|
|
399
|
+
content = `Antigravity attempted action: ${finalResultObj.denied_actions.map((a: any) => a.display_name || a.action).join(', ')}`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (!content && toolCalls.length === 0) {
|
|
403
|
+
content = 'Turn completed by Antigravity Agent.';
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const promptTokens = Number(finalResultObj?.usage?.input_tokens) || Math.ceil(promptText.length / 4);
|
|
407
|
+
const completionTokens = Number(finalResultObj?.usage?.output_tokens) || Math.ceil(rawContent.length / 4);
|
|
408
|
+
const thinkingTokens = Number(finalResultObj?.usage?.thinking_tokens) || 0;
|
|
409
|
+
|
|
410
|
+
const response: ChatResponse = {
|
|
411
|
+
content: content || (toolCalls.length > 0 ? '' : 'Turn completed by Antigravity Agent.'),
|
|
412
|
+
usage: {
|
|
413
|
+
promptTokens,
|
|
414
|
+
completionTokens: completionTokens + thinkingTokens,
|
|
415
|
+
cachedPromptTokens: Number(finalResultObj?.usage?.cache_read_tokens) || 0
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
if (extractedReasoning) {
|
|
420
|
+
response.reasoningContent = extractedReasoning;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (toolCalls.length > 0) {
|
|
424
|
+
response.toolCalls = toolCalls;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
safeResolve(response);
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
override async chat(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
|
|
433
|
+
const maxRetries = options.maxRetries ?? 2;
|
|
434
|
+
let attempt = 0;
|
|
435
|
+
while (attempt <= maxRetries) {
|
|
436
|
+
try {
|
|
437
|
+
return await this._executeOnce(messages, options);
|
|
438
|
+
} catch (err: any) {
|
|
439
|
+
if (attempt < maxRetries && this._isTransientError(err.message)) {
|
|
440
|
+
attempt++;
|
|
441
|
+
const delay = attempt * 1200;
|
|
442
|
+
await new Promise(r => setTimeout(r, delay));
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
throw err;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
throw new Error('Antigravity execution failed after maximum retries.');
|
|
449
|
+
}
|
|
450
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export interface ProviderConfig {
|
|
2
|
+
apiKey?: string | undefined;
|
|
3
|
+
model?: string | undefined;
|
|
4
|
+
baseUrl?: string | undefined;
|
|
5
|
+
provider?: string | undefined;
|
|
6
|
+
command?: string | undefined;
|
|
7
|
+
args?: string[] | undefined;
|
|
8
|
+
peer?: string | undefined;
|
|
9
|
+
supportsVision?: boolean | undefined;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ChatResponseUsage {
|
|
14
|
+
promptTokens: number;
|
|
15
|
+
completionTokens: number;
|
|
16
|
+
cachedPromptTokens?: number | undefined;
|
|
17
|
+
totalTokens?: number | undefined;
|
|
18
|
+
thinkingTokens?: number | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ChatResponseToolCall {
|
|
22
|
+
id: string;
|
|
23
|
+
type: string;
|
|
24
|
+
function: {
|
|
25
|
+
name: string;
|
|
26
|
+
arguments: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ChatResponse {
|
|
31
|
+
content: string;
|
|
32
|
+
usage: ChatResponseUsage;
|
|
33
|
+
toolCalls?: ChatResponseToolCall[] | undefined;
|
|
34
|
+
reasoningContent?: string | undefined;
|
|
35
|
+
thinkingBlocks?: any[] | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ChatOptions {
|
|
39
|
+
tools?: any[] | undefined;
|
|
40
|
+
temperature?: number | undefined;
|
|
41
|
+
maxRetries?: number | undefined;
|
|
42
|
+
signal?: AbortSignal | undefined;
|
|
43
|
+
onChunk?: ((chunk: string) => void) | undefined;
|
|
44
|
+
onReasoningChunk?: ((chunk: string) => void) | undefined;
|
|
45
|
+
coreToolCount?: number | undefined;
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class LLMProvider {
|
|
50
|
+
apiKey?: string;
|
|
51
|
+
model: string;
|
|
52
|
+
baseUrl?: string;
|
|
53
|
+
visionModels: string[];
|
|
54
|
+
imagePayloadFormat: string;
|
|
55
|
+
visionOverride: boolean | null;
|
|
56
|
+
audioModels: string[];
|
|
57
|
+
audioPayloadFormat: string;
|
|
58
|
+
|
|
59
|
+
constructor(config?: ProviderConfig);
|
|
60
|
+
get supportsVision(): boolean;
|
|
61
|
+
get supportsAudio(): boolean;
|
|
62
|
+
supportsToolSearch?(): boolean;
|
|
63
|
+
chat(messages: any[], options?: ChatOptions): Promise<ChatResponse>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function mimeTypeForAudioFormat(format: string): string;
|
|
67
|
+
export function audioFormatForMimeType(mimeType: string): string;
|
|
68
|
+
export function isAudioBlock(block: any): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function createProvider(...args: any[]): any;
|
|
@@ -8,3 +8,5 @@ export interface CapabilityVerdict {
|
|
|
8
8
|
export function ensureCapability(group: string): Promise<CapabilityVerdict>;
|
|
9
9
|
export function loadCapabilityPackage(packageName: string): Promise<unknown>;
|
|
10
10
|
export function capabilityDirectory(): string;
|
|
11
|
+
export function groupStatus(group: string): { state: string };
|
|
12
|
+
export function isGroupDeclined(group: string): boolean;
|
package/src/sandbox.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const Sandbox: any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const TaskBuffer: any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const TokenTracker: any;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function routePacks(...args: any[]): any;
|
|
2
|
+
export function packForTool(...args: any[]): any;
|
|
3
|
+
export function isCoreTool(...args: any[]): any;
|
|
4
|
+
export function isGameIntent(...args: any[]): any;
|
|
5
|
+
export function isWebIntent(...args: any[]): any;
|
|
6
|
+
export function getPackCatalogue(...args: any[]): any;
|
|
7
|
+
export const PACK_PLAYBOOKS: any;
|
|
8
|
+
export const PACKS: any;
|