@causyne/agent 1.20.7 → 1.20.9
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/acp/agentCatalog.js +9 -3
- package/src/acp/agentCatalog.ts +20 -4
- package/src/agentLoop.js +167 -34
- package/src/agentLoop.ts +188 -37
- package/src/commands.js +25 -10
- package/src/compiledSkills.js +7330 -319
- package/src/computerUse/types.js +8 -0
- package/src/computerUse/types.ts +121 -0
- package/src/computerUse/visionGrounding.js +87 -29
- package/src/computerUse/visionGrounding.ts +108 -36
- package/src/decisionPolicy.js +7 -9
- package/src/decisionPolicy.ts +7 -9
- package/src/documentEngine/antiSlopAuditor.js +13 -43
- package/src/documentEngine/antiSlopAuditor.ts +15 -47
- package/src/documentEngine/documentForge.js +3 -3
- package/src/documentEngine/documentForge.ts +3 -3
- package/src/dynamicCatalogue.js +568 -77
- package/src/dynamicCatalogue.ts +608 -79
- package/src/launchIntent.js +3 -3
- package/src/launchIntent.ts +3 -3
- package/src/planCache.js +4 -14
- package/src/planCache.ts +4 -14
- package/src/providers/acp.js +39 -4
- package/src/providers/acp.ts +42 -4
- package/src/providers/antigravity.d.ts +7 -1
- package/src/providers/antigravity.js +222 -34
- package/src/providers/antigravity.ts +220 -33
- package/src/providers/base.d.ts +2 -0
- package/src/providers/pi.js +3 -1
- package/src/providers/pi.ts +4 -2
- package/src/sandbox.js +7 -10
- package/src/smartToolsUse.js +203 -0
- package/src/smartToolsUse.ts +263 -0
- package/src/taskShape.js +7 -7
- package/src/taskShape.ts +7 -7
- package/src/toolPacks.js +5 -5
- package/src/tools/blenderAutomator.js +198 -11
- package/src/tools/documentForge.js +1 -1
- package/src/tools/documentForge.ts +1 -1
- package/src/tui/modelPicker.js +288 -69
- package/src/tui/modelPicker.ts +333 -72
|
@@ -28,11 +28,32 @@ export const ANTIGRAVITY_MODEL_IDS = {
|
|
|
28
28
|
};
|
|
29
29
|
export const ANTIGRAVITY_LABEL_BY_ID = Object.fromEntries(Object.entries(ANTIGRAVITY_MODEL_IDS).map(([label, id]) => [id, label]));
|
|
30
30
|
export const ANTIGRAVITY_MODELS = Object.keys(ANTIGRAVITY_MODEL_IDS);
|
|
31
|
+
export function synthesizeAgySlug(input) {
|
|
32
|
+
const trimmed = input.trim();
|
|
33
|
+
if (!trimmed)
|
|
34
|
+
return '';
|
|
35
|
+
if (!/[\s()]/.test(trimmed)) {
|
|
36
|
+
return trimmed;
|
|
37
|
+
}
|
|
38
|
+
let slug = trimmed
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.replace(/\(([^()]+)\)/g, ' $1 ')
|
|
41
|
+
.replace(/[^a-z0-9.]+/g, '-')
|
|
42
|
+
.replace(/^-+|-+$/g, '')
|
|
43
|
+
.replace(/-{2,}/g, '-');
|
|
44
|
+
if (slug.startsWith('claude-')) {
|
|
45
|
+
slug = slug.replace(/\./g, '-');
|
|
46
|
+
}
|
|
47
|
+
return slug;
|
|
48
|
+
}
|
|
31
49
|
export function registerAntigravityModel(slug, label) {
|
|
32
50
|
if (!slug || typeof slug !== 'string')
|
|
33
51
|
return;
|
|
34
|
-
const
|
|
35
|
-
const cleanLabel = (label && typeof label === 'string' && label.trim()) ||
|
|
52
|
+
const rawSlug = slug.trim();
|
|
53
|
+
const cleanLabel = (label && typeof label === 'string' && label.trim()) || rawSlug;
|
|
54
|
+
const cleanSlug = /[\s()]/.test(rawSlug)
|
|
55
|
+
? (ANTIGRAVITY_MODEL_IDS[rawSlug] || synthesizeAgySlug(rawSlug))
|
|
56
|
+
: rawSlug;
|
|
36
57
|
ANTIGRAVITY_MODEL_IDS[cleanLabel] = cleanSlug;
|
|
37
58
|
ANTIGRAVITY_MODEL_IDS[cleanSlug] = cleanSlug;
|
|
38
59
|
ANTIGRAVITY_LABEL_BY_ID[cleanSlug] = cleanLabel;
|
|
@@ -40,7 +61,40 @@ export function registerAntigravityModel(slug, label) {
|
|
|
40
61
|
ANTIGRAVITY_MODELS.push(cleanLabel);
|
|
41
62
|
}
|
|
42
63
|
}
|
|
43
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Authoritatively replace the active Antigravity model list with the live
|
|
66
|
+
* models returned by the user's current Antigravity account/tier, while
|
|
67
|
+
* preserving slug lookup mappings in ANTIGRAVITY_MODEL_IDS.
|
|
68
|
+
*/
|
|
69
|
+
export function replaceAntigravityModels(items) {
|
|
70
|
+
const nextLabels = [];
|
|
71
|
+
for (const item of items) {
|
|
72
|
+
if (typeof item === 'string') {
|
|
73
|
+
const trimmed = item.trim();
|
|
74
|
+
if (!trimmed)
|
|
75
|
+
continue;
|
|
76
|
+
const existingSlug = ANTIGRAVITY_MODEL_IDS[trimmed] || synthesizeAgySlug(trimmed);
|
|
77
|
+
const label = ANTIGRAVITY_LABEL_BY_ID[trimmed] || trimmed;
|
|
78
|
+
registerAntigravityModel(existingSlug, label);
|
|
79
|
+
if (!nextLabels.includes(label))
|
|
80
|
+
nextLabels.push(label);
|
|
81
|
+
}
|
|
82
|
+
else if (item && typeof item === 'object' && typeof item.id === 'string') {
|
|
83
|
+
const id = item.id.trim();
|
|
84
|
+
if (!id)
|
|
85
|
+
continue;
|
|
86
|
+
const label = (item.label && item.label.trim()) || ANTIGRAVITY_LABEL_BY_ID[id] || id;
|
|
87
|
+
registerAntigravityModel(id, label);
|
|
88
|
+
if (!nextLabels.includes(label))
|
|
89
|
+
nextLabels.push(label);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (nextLabels.length > 0) {
|
|
93
|
+
ANTIGRAVITY_MODELS.splice(0, ANTIGRAVITY_MODELS.length, ...nextLabels);
|
|
94
|
+
}
|
|
95
|
+
return [...ANTIGRAVITY_MODELS];
|
|
96
|
+
}
|
|
97
|
+
export function parseAgyModelsOutput(stdout, options = {}) {
|
|
44
98
|
const result = [];
|
|
45
99
|
if (!stdout || typeof stdout !== 'string')
|
|
46
100
|
return result;
|
|
@@ -49,7 +103,7 @@ export function parseAgyModelsOutput(stdout) {
|
|
|
49
103
|
const line = rawLine.replace(/\u001b\[[0-9;]*[A-Za-z]/g, '').trim();
|
|
50
104
|
if (!line)
|
|
51
105
|
continue;
|
|
52
|
-
if (/^(fetching|loading|no models|error)/i.test(line))
|
|
106
|
+
if (/^(fetching|loading|no models|error|warning|usage|available)/i.test(line))
|
|
53
107
|
continue;
|
|
54
108
|
if (line.endsWith('…') || line.endsWith('...'))
|
|
55
109
|
continue;
|
|
@@ -58,28 +112,59 @@ export function parseAgyModelsOutput(stdout) {
|
|
|
58
112
|
if (!match)
|
|
59
113
|
continue;
|
|
60
114
|
const id = match[1].trim();
|
|
61
|
-
const label = (match[2] && match[2].trim()) || id;
|
|
115
|
+
const label = ((match[2] && match[2].trim()) || id).replace(/\s+\(default\)$/i, '').trim();
|
|
62
116
|
result.push({ id, label });
|
|
63
117
|
registerAntigravityModel(id, label);
|
|
64
118
|
}
|
|
119
|
+
if (options.replaceActiveList && result.length > 0) {
|
|
120
|
+
replaceAntigravityModels(result);
|
|
121
|
+
}
|
|
65
122
|
return result;
|
|
66
123
|
}
|
|
67
|
-
function
|
|
124
|
+
export function isAntigravityOnboarded() {
|
|
68
125
|
try {
|
|
69
126
|
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
70
|
-
|
|
127
|
+
if (!home)
|
|
128
|
+
return false;
|
|
129
|
+
const onboardingFile = path.join(home, '.gemini', 'antigravity-cli', 'cache', 'onboarding.json');
|
|
130
|
+
if (fs.existsSync(onboardingFile)) {
|
|
131
|
+
const parsed = JSON.parse(fs.readFileSync(onboardingFile, 'utf8'));
|
|
132
|
+
if (parsed && parsed.onboardingComplete === true)
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
const oauthFile = path.join(home, '.gemini', 'oauth_creds.json');
|
|
136
|
+
if (fs.existsSync(oauthFile))
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// ignore read errors
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
function hydrateModelsFromDiskCache() {
|
|
145
|
+
try {
|
|
146
|
+
const causyneDir = process.env.CAUSYNE_HOME
|
|
147
|
+
|| path.join(process.env.HOME || process.env.USERPROFILE || '', '.causyne');
|
|
148
|
+
const cacheFile = path.join(causyneDir, 'models_cache.json');
|
|
71
149
|
if (!fs.existsSync(cacheFile))
|
|
72
150
|
return;
|
|
73
151
|
const content = fs.readFileSync(cacheFile, 'utf8');
|
|
74
152
|
const parsed = JSON.parse(content);
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
153
|
+
const agyEntry = parsed?.providers?.antigravity;
|
|
154
|
+
if (agyEntry?.modelIdMap && typeof agyEntry.modelIdMap === 'object') {
|
|
155
|
+
for (const [label, slug] of Object.entries(agyEntry.modelIdMap)) {
|
|
156
|
+
if (typeof slug === 'string' && slug.trim()) {
|
|
157
|
+
registerAntigravityModel(slug.trim(), label);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const agyModels = agyEntry?.models;
|
|
162
|
+
if (Array.isArray(agyModels) && agyModels.length > 0) {
|
|
77
163
|
for (const item of agyModels) {
|
|
78
164
|
if (typeof item === 'string' && item.trim()) {
|
|
79
165
|
const trimmed = item.trim();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
166
|
+
const slug = ANTIGRAVITY_MODEL_IDS[trimmed] || synthesizeAgySlug(trimmed);
|
|
167
|
+
registerAntigravityModel(slug, trimmed);
|
|
83
168
|
}
|
|
84
169
|
}
|
|
85
170
|
}
|
|
@@ -116,6 +201,9 @@ export function resolveAgyModelId(model) {
|
|
|
116
201
|
return slug;
|
|
117
202
|
}
|
|
118
203
|
}
|
|
204
|
+
if (/[\s()]/.test(trimmed)) {
|
|
205
|
+
return synthesizeAgySlug(trimmed);
|
|
206
|
+
}
|
|
119
207
|
return trimmed;
|
|
120
208
|
}
|
|
121
209
|
export function resolveAgyEffort(model) {
|
|
@@ -402,6 +490,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
402
490
|
printTimeout;
|
|
403
491
|
currentConversationId = null;
|
|
404
492
|
lastTaskId = null;
|
|
493
|
+
lastCumulativeUsage = null;
|
|
405
494
|
constructor(config = {}) {
|
|
406
495
|
super(config);
|
|
407
496
|
this.model = config.model || 'Gemini 3.8 Flash (Low)';
|
|
@@ -476,7 +565,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
476
565
|
'[Environment State & Idempotency Directive]\n' +
|
|
477
566
|
'Reuse relevant verified tool results from this session, and check uncertain prerequisites before relying on them.\n\n' +
|
|
478
567
|
'[Language & Communication Directive]\n' +
|
|
479
|
-
'Dynamically reflect and match the exact language used by the user in their prompt.
|
|
568
|
+
'Dynamically reflect and match the exact language used by the user in their prompt. Respond naturally in that same language. Never send conversational pleasantries or canned greetings.');
|
|
480
569
|
if (tools && tools.length > 0) {
|
|
481
570
|
const toolSummaries = tools.map(t => {
|
|
482
571
|
const name = t.name || t.function?.name || 'unknown';
|
|
@@ -646,15 +735,19 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
646
735
|
const currentSessionKey = options.conversationId || options.taskId || null;
|
|
647
736
|
if (currentSessionKey && currentSessionKey !== this.lastTaskId) {
|
|
648
737
|
this.currentConversationId = null;
|
|
738
|
+
this.lastCumulativeUsage = null;
|
|
649
739
|
this.lastTaskId = currentSessionKey;
|
|
650
740
|
}
|
|
651
741
|
if (messages.length <= 1) {
|
|
652
742
|
this.currentConversationId = null;
|
|
743
|
+
this.lastCumulativeUsage = null;
|
|
653
744
|
}
|
|
654
745
|
const useConversation = Boolean(this.currentConversationId);
|
|
746
|
+
const resumedConversationId = this.currentConversationId;
|
|
655
747
|
const latestUserMessage = [...messages].reverse().find(message => message.role === 'user');
|
|
656
748
|
const latestPrompt = typeof latestUserMessage?.content === 'string' ? latestUserMessage.content : '';
|
|
657
749
|
const launchOnly = options.taskIntent === 'launch' || isLaunchOnlyPrompt(latestPrompt);
|
|
750
|
+
const desktopTask = options.taskArchetype === 'desktop_personalization';
|
|
658
751
|
let promptText;
|
|
659
752
|
if (useConversation) {
|
|
660
753
|
let lastAssistantIndex = -1;
|
|
@@ -678,6 +771,13 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
678
771
|
'Do not create, edit, delete, install, or regenerate files. Do not claim the app opened unless a tool confirmed it. ' +
|
|
679
772
|
'Use Causyne tool calls for commands and desktop opening.\n\n' + promptText;
|
|
680
773
|
}
|
|
774
|
+
if (desktopTask) {
|
|
775
|
+
promptText = '[Current desktop task: finish and verify the requested change]\n' +
|
|
776
|
+
'Use only the tools needed. Search and download alone are not completion. ' +
|
|
777
|
+
'After setting the desktop picture, read back the actual system wallpaper and compare it with the intended image. ' +
|
|
778
|
+
'If a command is denied or the readback does not confirm the change, report the blocker honestly. ' +
|
|
779
|
+
'Keep native tool actions within 12; use Causyne tool calls when a native action is blocked.\n\n' + promptText;
|
|
780
|
+
}
|
|
681
781
|
const modelSlug = resolveAgyModelId(this.model);
|
|
682
782
|
const effort = resolveAgyEffort(this.model);
|
|
683
783
|
// Standard high-performance non-blocking CLI invocation:
|
|
@@ -729,7 +829,41 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
729
829
|
const nativeActions = [];
|
|
730
830
|
const attemptedNativeTools = [];
|
|
731
831
|
let childClosed = false;
|
|
832
|
+
const terminateChild = () => {
|
|
833
|
+
try {
|
|
834
|
+
child.kill('SIGTERM');
|
|
835
|
+
setTimeout(() => {
|
|
836
|
+
if (!childClosed)
|
|
837
|
+
child.kill('SIGKILL');
|
|
838
|
+
}, 1000).unref();
|
|
839
|
+
}
|
|
840
|
+
catch {
|
|
841
|
+
// A process that already exited needs no further action.
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
const maxNativeActions = desktopTask ? 12 : Infinity;
|
|
845
|
+
let nativeActionStarts = 0;
|
|
846
|
+
const seenNativeActionSteps = new Set();
|
|
847
|
+
// Antigravity's result usage is cumulative across the conversation, but
|
|
848
|
+
// DONE step updates carry usage for that step. Keep a turn-local subtotal
|
|
849
|
+
// so a single headless run cannot consume an entire task budget unseen.
|
|
850
|
+
const completedUsageSteps = new Set();
|
|
851
|
+
const partialUsage = {
|
|
852
|
+
promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0,
|
|
853
|
+
thinkingTokens: 0, measurement: 'provider_reported', cacheMeasurement: 'provider_reported'
|
|
854
|
+
};
|
|
855
|
+
const tokenLimit = Number(options.maxTokensThisCall);
|
|
856
|
+
const enforceTokenLimit = Number.isFinite(tokenLimit) && tokenLimit > 0;
|
|
857
|
+
const wallTimer = desktopTask ? setTimeout(() => {
|
|
858
|
+
const error = new Error('Antigravity exceeded the 180-second desktop task limit. Outcome is unverified.');
|
|
859
|
+
error.code = 'AGY_DESKTOP_TASK_LIMIT';
|
|
860
|
+
safeReject(error);
|
|
861
|
+
terminateChild();
|
|
862
|
+
}, 180_000) : null;
|
|
863
|
+
wallTimer?.unref();
|
|
732
864
|
const cleanup = () => {
|
|
865
|
+
if (wallTimer)
|
|
866
|
+
clearTimeout(wallTimer);
|
|
733
867
|
if (options.signal) {
|
|
734
868
|
options.signal.removeEventListener('abort', onAbort);
|
|
735
869
|
}
|
|
@@ -749,16 +883,7 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
749
883
|
resolve(res);
|
|
750
884
|
};
|
|
751
885
|
const onAbort = () => {
|
|
752
|
-
|
|
753
|
-
child.kill('SIGTERM');
|
|
754
|
-
setTimeout(() => {
|
|
755
|
-
if (!childClosed)
|
|
756
|
-
child.kill('SIGKILL');
|
|
757
|
-
}, 1000).unref();
|
|
758
|
-
}
|
|
759
|
-
catch {
|
|
760
|
-
// ignore kill errors
|
|
761
|
-
}
|
|
886
|
+
terminateChild();
|
|
762
887
|
const abortErr = new Error('Turn aborted by user or timeout.');
|
|
763
888
|
abortErr.name = 'AbortError';
|
|
764
889
|
safeReject(abortErr);
|
|
@@ -799,15 +924,50 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
799
924
|
}
|
|
800
925
|
else if (event.event === 'step_update') {
|
|
801
926
|
const stepUpdate = event.step_update;
|
|
927
|
+
const usage = stepUpdate?.usage;
|
|
928
|
+
const usageStepIndex = Number(stepUpdate?.step_index ?? event?.step_index);
|
|
929
|
+
if (stepUpdate?.state === 'DONE' && usage && Number.isFinite(usageStepIndex)
|
|
930
|
+
&& !completedUsageSteps.has(usageStepIndex)) {
|
|
931
|
+
const input = Number(usage.input_tokens);
|
|
932
|
+
const output = Number(usage.output_tokens);
|
|
933
|
+
if (Number.isFinite(input) && input >= 0 && Number.isFinite(output) && output >= 0) {
|
|
934
|
+
completedUsageSteps.add(usageStepIndex);
|
|
935
|
+
partialUsage.promptTokens += input;
|
|
936
|
+
partialUsage.completionTokens += output;
|
|
937
|
+
partialUsage.cachedPromptTokens = (partialUsage.cachedPromptTokens || 0)
|
|
938
|
+
+ (Number(usage.cache_read_tokens) || 0);
|
|
939
|
+
partialUsage.thinkingTokens = (partialUsage.thinkingTokens || 0)
|
|
940
|
+
+ (Number(usage.thinking_tokens) || 0);
|
|
941
|
+
if (enforceTokenLimit && partialUsage.promptTokens + partialUsage.completionTokens >= tokenLimit) {
|
|
942
|
+
this.currentConversationId = null;
|
|
943
|
+
const error = Object.assign(new Error(`Antigravity token budget reached during this turn: at least ${partialUsage.promptTokens + partialUsage.completionTokens} tokens reported for a ${tokenLimit}-token remaining budget. The task outcome is unverified.`), { code: 'AGY_TOKEN_BUDGET', partialUsage: { ...partialUsage } });
|
|
944
|
+
safeReject(error);
|
|
945
|
+
terminateChild();
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
802
950
|
const delta = stepUpdate?.text_delta;
|
|
803
951
|
const stepType = stepUpdate?.step_type;
|
|
804
952
|
if (stepType === 'tool') {
|
|
805
953
|
const state = stepUpdate?.state;
|
|
954
|
+
const stepIndex = Number(stepUpdate?.step_index ?? event?.step_index);
|
|
955
|
+
const newNativeAction = (state === 'ACTIVE' || (state === 'DONE' && Number.isFinite(stepIndex)))
|
|
956
|
+
&& (!Number.isFinite(stepIndex) || !seenNativeActionSteps.has(stepIndex));
|
|
957
|
+
if (newNativeAction && Number.isFinite(stepIndex))
|
|
958
|
+
seenNativeActionSteps.add(stepIndex);
|
|
959
|
+
if (desktopTask && newNativeAction && ++nativeActionStarts > maxNativeActions) {
|
|
960
|
+
const error = new Error(`Antigravity exceeded ${maxNativeActions} native actions for this desktop task. Outcome is unverified.`);
|
|
961
|
+
error.code = 'AGY_NATIVE_ACTION_BUDGET';
|
|
962
|
+
safeReject(error);
|
|
963
|
+
terminateChild();
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
806
966
|
const toolInfo = stepUpdate?.tool_info || {};
|
|
807
967
|
const name = stepUpdate?.tool_name || toolInfo?.name;
|
|
808
|
-
const status = state === 'DONE'
|
|
809
|
-
? 'completed'
|
|
810
|
-
:
|
|
968
|
+
const status = state === 'DONE' || state === 'ERROR'
|
|
969
|
+
? (state === 'ERROR' || toolInfo?.error ? 'failed' : 'completed')
|
|
970
|
+
: 'running';
|
|
811
971
|
const rawParams = (toolInfo && typeof toolInfo === 'object' && toolInfo.parameters) ||
|
|
812
972
|
(stepUpdate && typeof stepUpdate === 'object' && stepUpdate.parameters) ||
|
|
813
973
|
(toolInfo && typeof toolInfo === 'object' && toolInfo.input) ||
|
|
@@ -909,6 +1069,10 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
909
1069
|
});
|
|
910
1070
|
child.on('close', (code) => {
|
|
911
1071
|
childClosed = true;
|
|
1072
|
+
// A budget or user abort has already settled this call. Do not accept
|
|
1073
|
+
// a late result from the terminated process as a resumable session.
|
|
1074
|
+
if (isSettled)
|
|
1075
|
+
return;
|
|
912
1076
|
// Process any remaining bytes in stdoutBuffer
|
|
913
1077
|
if (stdoutBuffer.trim()) {
|
|
914
1078
|
try {
|
|
@@ -930,10 +1094,11 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
930
1094
|
// ignore
|
|
931
1095
|
}
|
|
932
1096
|
}
|
|
933
|
-
if (code !== 0 || finalResultObj?.status
|
|
1097
|
+
if (code !== 0 || (finalResultObj?.status && finalResultObj.status !== 'SUCCESS')) {
|
|
934
1098
|
if (useConversation)
|
|
935
1099
|
this.currentConversationId = null;
|
|
936
|
-
const errDetail = finalResultObj?.error || stderrBuffer.trim() ||
|
|
1100
|
+
const errDetail = finalResultObj?.error || stderrBuffer.trim() ||
|
|
1101
|
+
`terminal status ${finalResultObj?.status || 'unknown'}, exit code ${code}`;
|
|
937
1102
|
safeReject(new Error(`Antigravity Agent (agy) failed: ${errDetail}`));
|
|
938
1103
|
return;
|
|
939
1104
|
}
|
|
@@ -1008,15 +1173,33 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1008
1173
|
const finalResponseText = typeof finalResultObj?.response === 'string' ? finalResultObj.response.trim() : '';
|
|
1009
1174
|
const endedAfterToolWithoutFinalResponse = sawToolAfterLastText && !finalResponseText && deniedActions.length === 0 && toolCalls.length === 0;
|
|
1010
1175
|
const missingResultEvent = finalResultObj === null && deniedActions.length === 0 && toolCalls.length === 0;
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1176
|
+
const usageIsReported = finalResultObj?.usage?.input_tokens != null
|
|
1177
|
+
&& finalResultObj?.usage?.output_tokens != null
|
|
1178
|
+
&& Number.isFinite(Number(finalResultObj.usage.input_tokens))
|
|
1179
|
+
&& Number.isFinite(Number(finalResultObj.usage.output_tokens));
|
|
1180
|
+
const cumulative = {
|
|
1181
|
+
input: usageIsReported ? Number(finalResultObj.usage.input_tokens) : Math.ceil(promptText.length / 4),
|
|
1182
|
+
output: usageIsReported ? Number(finalResultObj.usage.output_tokens) : Math.ceil(rawContent.length / 4),
|
|
1183
|
+
thinking: Number(finalResultObj?.usage?.thinking_tokens) || 0,
|
|
1184
|
+
cacheRead: Number(finalResultObj?.usage?.cache_read_tokens) || 0
|
|
1185
|
+
};
|
|
1186
|
+
const prior = useConversation && resumedConversationId === this.lastCumulativeUsage?.conversationId
|
|
1187
|
+
? this.lastCumulativeUsage : null;
|
|
1188
|
+
const delta = (current, previous) => current >= previous ? current - previous : current;
|
|
1189
|
+
const promptTokens = prior && usageIsReported ? delta(cumulative.input, prior.input) : cumulative.input;
|
|
1190
|
+
const completionTokens = prior && usageIsReported ? delta(cumulative.output, prior.output) : cumulative.output;
|
|
1191
|
+
const thinkingTokens = prior && usageIsReported ? delta(cumulative.thinking, prior.thinking) : cumulative.thinking;
|
|
1192
|
+
const cachedPromptTokens = prior && usageIsReported ? delta(cumulative.cacheRead, prior.cacheRead) : cumulative.cacheRead;
|
|
1014
1193
|
const response = {
|
|
1015
1194
|
content,
|
|
1016
1195
|
usage: {
|
|
1017
1196
|
promptTokens,
|
|
1018
|
-
completionTokens
|
|
1019
|
-
|
|
1197
|
+
completionTokens,
|
|
1198
|
+
thinkingTokens,
|
|
1199
|
+
cachedPromptTokens,
|
|
1200
|
+
measurement: usageIsReported ? 'provider_reported' : 'text_estimate',
|
|
1201
|
+
cacheMeasurement: finalResultObj?.usage?.cache_read_tokens != null
|
|
1202
|
+
? 'provider_reported' : 'unavailable'
|
|
1020
1203
|
}
|
|
1021
1204
|
};
|
|
1022
1205
|
if (extractedReasoning) {
|
|
@@ -1031,6 +1214,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1031
1214
|
if (timedOutMidTurn || endedAfterToolWithoutFinalResponse || missingResultEvent) {
|
|
1032
1215
|
response.incompleteTurn = true;
|
|
1033
1216
|
}
|
|
1217
|
+
if (usageIsReported && this.currentConversationId) {
|
|
1218
|
+
this.lastCumulativeUsage = { conversationId: this.currentConversationId, ...cumulative };
|
|
1219
|
+
}
|
|
1034
1220
|
safeResolve(response);
|
|
1035
1221
|
});
|
|
1036
1222
|
});
|
|
@@ -1047,7 +1233,9 @@ export class AntigravityProvider extends LLMProvider {
|
|
|
1047
1233
|
if (options.signal?.aborted || err?.name === 'AbortError') {
|
|
1048
1234
|
throw err;
|
|
1049
1235
|
}
|
|
1050
|
-
const canRetryResetConversation = hadConversation && !this.currentConversationId
|
|
1236
|
+
const canRetryResetConversation = hadConversation && !this.currentConversationId
|
|
1237
|
+
&& err?.code !== 'AGY_NATIVE_ACTION_DENIED'
|
|
1238
|
+
&& err?.code !== 'AGY_TOKEN_BUDGET';
|
|
1051
1239
|
if (attempt < maxRetries && (this._isTransientError(err.message) || canRetryResetConversation)) {
|
|
1052
1240
|
attempt++;
|
|
1053
1241
|
const delay = attempt * 1200;
|