@causyne/agent 1.20.7 → 1.20.8

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.
@@ -1,5 +1,6 @@
1
1
  import { canonicalModelId } from '../modelIds.js';
2
2
  import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
3
+ import { saveCachedModels } from '../dynamicCatalogue.js';
3
4
  import { LLMProvider } from './base.js';
4
5
  import { AcpClient } from '../acp/client.js';
5
6
  import { getPeerProfile } from '../acp/peerProfiles.js';
@@ -376,10 +377,31 @@ export class AcpProvider extends LLMProvider {
376
377
  });
377
378
  await client.start(signal);
378
379
  const sessionId = await client.newSession(process.cwd(), [], signal);
380
+ const sessionModels = client.getSessionModels(sessionId);
381
+ const liveModels = sessionModels.availableModels;
382
+ if (liveModels.length > 0 && !process.env.NODE_TEST_CONTEXT) {
383
+ saveCachedModels(`acp/${this.peerId}`, liveModels, {
384
+ ...(sessionModels.currentModelId ? { currentModel: sessionModels.currentModelId } : {})
385
+ });
386
+ }
379
387
  let targetModel = this.model;
380
- if (this.peerId === 'opencode' && targetModel !== this.peerId && !targetModel.startsWith('opencode/')) {
388
+ if (this.peerId === 'opencode' && targetModel !== this.peerId && !targetModel.includes('/')) {
381
389
  targetModel = `opencode/${targetModel}`;
382
390
  }
391
+ if (liveModels.length > 0 && targetModel && !liveModels.includes(targetModel)) {
392
+ const matched = liveModels.find((m) => m.toLowerCase() === targetModel.toLowerCase() || m.endsWith(`/${targetModel}`));
393
+ if (matched) {
394
+ targetModel = matched;
395
+ this.model = matched;
396
+ }
397
+ else {
398
+ const staticDefault = DEFAULT_MODEL_BY_PROVIDER[`acp/${this.peerId}`];
399
+ if (targetModel === staticDefault || targetModel === this.peerId || targetModel === 'acp') {
400
+ targetModel = sessionModels.currentModelId || liveModels[0];
401
+ this.model = targetModel;
402
+ }
403
+ }
404
+ }
383
405
  if (targetModel && targetModel !== 'acp' && targetModel !== this.peerId) {
384
406
  try {
385
407
  await client.setSessionModel(sessionId, targetModel, signal);
@@ -389,7 +411,18 @@ export class AcpProvider extends LLMProvider {
389
411
  await client.close();
390
412
  throw err;
391
413
  }
392
- // peer does not support setSessionModel
414
+ // If the requested model is unavailable on the user's current account/tier,
415
+ // gracefully fall back to the peer's active or first advertised live model.
416
+ const fallbackModel = sessionModels.currentModelId || liveModels[0];
417
+ if (fallbackModel && fallbackModel !== targetModel) {
418
+ this.model = fallbackModel;
419
+ try {
420
+ await client.setSessionModel(sessionId, fallbackModel, signal);
421
+ }
422
+ catch {
423
+ // Peer already defaults to its own active session model
424
+ }
425
+ }
393
426
  }
394
427
  }
395
428
  this.activeClient = client;
@@ -1,5 +1,6 @@
1
1
  import { canonicalModelId } from '../modelIds.js';
2
2
  import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
3
+ import { saveCachedModels } from '../dynamicCatalogue.js';
3
4
  import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseToolCall, type ChatResponseAction } from './base.js';
4
5
  import { AcpClient } from '../acp/client.js';
5
6
  import { getPeerProfile } from '../acp/peerProfiles.js';
@@ -378,10 +379,35 @@ export class AcpProvider extends LLMProvider {
378
379
  await client.start(signal);
379
380
  const sessionId = await client.newSession(process.cwd(), [], signal);
380
381
 
382
+ const sessionModels = client.getSessionModels(sessionId);
383
+ const liveModels = sessionModels.availableModels;
384
+ if (liveModels.length > 0 && !process.env.NODE_TEST_CONTEXT) {
385
+ saveCachedModels(`acp/${this.peerId}`, liveModels, {
386
+ ...(sessionModels.currentModelId ? { currentModel: sessionModels.currentModelId } : {})
387
+ });
388
+ }
389
+
381
390
  let targetModel = this.model;
382
- if (this.peerId === 'opencode' && targetModel !== this.peerId && !targetModel.startsWith('opencode/')) {
391
+ if (this.peerId === 'opencode' && targetModel !== this.peerId && !targetModel.includes('/')) {
383
392
  targetModel = `opencode/${targetModel}`;
384
393
  }
394
+
395
+ if (liveModels.length > 0 && targetModel && !liveModels.includes(targetModel)) {
396
+ const matched = liveModels.find(
397
+ (m) => m.toLowerCase() === targetModel.toLowerCase() || m.endsWith(`/${targetModel}`)
398
+ );
399
+ if (matched) {
400
+ targetModel = matched;
401
+ this.model = matched;
402
+ } else {
403
+ const staticDefault = (DEFAULT_MODEL_BY_PROVIDER as Record<string, string>)[`acp/${this.peerId}`];
404
+ if (targetModel === staticDefault || targetModel === this.peerId || targetModel === 'acp') {
405
+ targetModel = sessionModels.currentModelId || liveModels[0]!;
406
+ this.model = targetModel;
407
+ }
408
+ }
409
+ }
410
+
385
411
  if (targetModel && targetModel !== 'acp' && targetModel !== this.peerId) {
386
412
  try {
387
413
  await client.setSessionModel(sessionId, targetModel, signal);
@@ -390,7 +416,17 @@ export class AcpProvider extends LLMProvider {
390
416
  await client.close();
391
417
  throw err;
392
418
  }
393
- // peer does not support setSessionModel
419
+ // If the requested model is unavailable on the user's current account/tier,
420
+ // gracefully fall back to the peer's active or first advertised live model.
421
+ const fallbackModel = sessionModels.currentModelId || liveModels[0];
422
+ if (fallbackModel && fallbackModel !== targetModel) {
423
+ this.model = fallbackModel;
424
+ try {
425
+ await client.setSessionModel(sessionId, fallbackModel, signal);
426
+ } catch {
427
+ // Peer already defaults to its own active session model
428
+ }
429
+ }
394
430
  }
395
431
  }
396
432
 
@@ -2,8 +2,14 @@ export const BASELINE_ANTIGRAVITY_MODELS: Record<string, string>;
2
2
  export const ANTIGRAVITY_MODELS: string[];
3
3
  export const ANTIGRAVITY_MODEL_IDS: Record<string, string>;
4
4
  export const ANTIGRAVITY_LABEL_BY_ID: Record<string, string>;
5
+ export function synthesizeAgySlug(input: string): string;
5
6
  export function registerAntigravityModel(slug: string, label?: string): void;
6
- export function parseAgyModelsOutput(stdout: string): Array<{ id: string; label: string }>;
7
+ export function replaceAntigravityModels(items: Array<{ id: string; label?: string } | string>): string[];
8
+ export function parseAgyModelsOutput(
9
+ stdout: string,
10
+ options?: { replaceActiveList?: boolean }
11
+ ): Array<{ id: string; label: string }>;
12
+ export function isAntigravityOnboarded(): boolean;
7
13
  export function resolveAgyModelId(model: string | null | undefined): string;
8
14
  export function resolveAgyEffort(model: string | null | undefined): string;
9
15
  export function isAntigravityProvider(provider: string | null | undefined): boolean;
@@ -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 cleanSlug = slug.trim();
35
- const cleanLabel = (label && typeof label === 'string' && label.trim()) || cleanSlug;
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
- export function parseAgyModelsOutput(stdout) {
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 hydrateModelsFromDiskCache() {
124
+ export function isAntigravityOnboarded() {
68
125
  try {
69
126
  const home = process.env.HOME || process.env.USERPROFILE || '';
70
- const cacheFile = path.join(home, '.causyne', 'models_cache.json');
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 agyModels = parsed?.providers?.antigravity?.models;
76
- if (Array.isArray(agyModels)) {
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
- if (!ANTIGRAVITY_MODEL_IDS[trimmed]) {
81
- registerAntigravityModel(trimmed, trimmed);
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) {
@@ -35,10 +35,31 @@ export const ANTIGRAVITY_LABEL_BY_ID: Record<string, string> = Object.fromEntrie
35
35
 
36
36
  export const ANTIGRAVITY_MODELS: string[] = Object.keys(ANTIGRAVITY_MODEL_IDS);
37
37
 
38
+ export function synthesizeAgySlug(input: string): string {
39
+ const trimmed = input.trim();
40
+ if (!trimmed) return '';
41
+ if (!/[\s()]/.test(trimmed)) {
42
+ return trimmed;
43
+ }
44
+ let slug = trimmed
45
+ .toLowerCase()
46
+ .replace(/\(([^()]+)\)/g, ' $1 ')
47
+ .replace(/[^a-z0-9.]+/g, '-')
48
+ .replace(/^-+|-+$/g, '')
49
+ .replace(/-{2,}/g, '-');
50
+ if (slug.startsWith('claude-')) {
51
+ slug = slug.replace(/\./g, '-');
52
+ }
53
+ return slug;
54
+ }
55
+
38
56
  export function registerAntigravityModel(slug: string, label?: string): void {
39
57
  if (!slug || typeof slug !== 'string') return;
40
- const cleanSlug = slug.trim();
41
- const cleanLabel = (label && typeof label === 'string' && label.trim()) || cleanSlug;
58
+ const rawSlug = slug.trim();
59
+ const cleanLabel = (label && typeof label === 'string' && label.trim()) || rawSlug;
60
+ const cleanSlug = /[\s()]/.test(rawSlug)
61
+ ? (ANTIGRAVITY_MODEL_IDS[rawSlug] || synthesizeAgySlug(rawSlug))
62
+ : rawSlug;
42
63
 
43
64
  ANTIGRAVITY_MODEL_IDS[cleanLabel] = cleanSlug;
44
65
  ANTIGRAVITY_MODEL_IDS[cleanSlug] = cleanSlug;
@@ -48,7 +69,41 @@ export function registerAntigravityModel(slug: string, label?: string): void {
48
69
  }
49
70
  }
50
71
 
51
- export function parseAgyModelsOutput(stdout: string): Array<{ id: string; label: string }> {
72
+ /**
73
+ * Authoritatively replace the active Antigravity model list with the live
74
+ * models returned by the user's current Antigravity account/tier, while
75
+ * preserving slug lookup mappings in ANTIGRAVITY_MODEL_IDS.
76
+ */
77
+ export function replaceAntigravityModels(
78
+ items: Array<{ id: string; label?: string } | string>
79
+ ): string[] {
80
+ const nextLabels: string[] = [];
81
+ for (const item of items) {
82
+ if (typeof item === 'string') {
83
+ const trimmed = item.trim();
84
+ if (!trimmed) continue;
85
+ const existingSlug = ANTIGRAVITY_MODEL_IDS[trimmed] || synthesizeAgySlug(trimmed);
86
+ const label = ANTIGRAVITY_LABEL_BY_ID[trimmed] || trimmed;
87
+ registerAntigravityModel(existingSlug, label);
88
+ if (!nextLabels.includes(label)) nextLabels.push(label);
89
+ } else if (item && typeof item === 'object' && typeof item.id === 'string') {
90
+ const id = item.id.trim();
91
+ if (!id) continue;
92
+ const label = (item.label && item.label.trim()) || ANTIGRAVITY_LABEL_BY_ID[id] || id;
93
+ registerAntigravityModel(id, label);
94
+ if (!nextLabels.includes(label)) nextLabels.push(label);
95
+ }
96
+ }
97
+ if (nextLabels.length > 0) {
98
+ ANTIGRAVITY_MODELS.splice(0, ANTIGRAVITY_MODELS.length, ...nextLabels);
99
+ }
100
+ return [...ANTIGRAVITY_MODELS];
101
+ }
102
+
103
+ export function parseAgyModelsOutput(
104
+ stdout: string,
105
+ options: { replaceActiveList?: boolean } = {}
106
+ ): Array<{ id: string; label: string }> {
52
107
  const result: Array<{ id: string; label: string }> = [];
53
108
  if (!stdout || typeof stdout !== 'string') return result;
54
109
 
@@ -56,7 +111,7 @@ export function parseAgyModelsOutput(stdout: string): Array<{ id: string; label:
56
111
  for (const rawLine of lines) {
57
112
  const line = rawLine.replace(/\u001b\[[0-9;]*[A-Za-z]/g, '').trim();
58
113
  if (!line) continue;
59
- if (/^(fetching|loading|no models|error)/i.test(line)) continue;
114
+ if (/^(fetching|loading|no models|error|warning|usage|available)/i.test(line)) continue;
60
115
  if (line.endsWith('…') || line.endsWith('...')) continue;
61
116
 
62
117
  const cleanLine = line.replace(/^[^a-zA-Z0-9_-]+/, '');
@@ -64,28 +119,56 @@ export function parseAgyModelsOutput(stdout: string): Array<{ id: string; label:
64
119
  if (!match) continue;
65
120
 
66
121
  const id = match[1]!.trim();
67
- const label = (match[2] && match[2].trim()) || id;
122
+ const label = ((match[2] && match[2].trim()) || id).replace(/\s+\(default\)$/i, '').trim();
68
123
  result.push({ id, label });
69
124
  registerAntigravityModel(id, label);
70
125
  }
126
+ if (options.replaceActiveList && result.length > 0) {
127
+ replaceAntigravityModels(result);
128
+ }
71
129
  return result;
72
130
  }
73
131
 
74
- function hydrateModelsFromDiskCache(): void {
132
+ export function isAntigravityOnboarded(): boolean {
75
133
  try {
76
134
  const home = process.env.HOME || process.env.USERPROFILE || '';
77
- const cacheFile = path.join(home, '.causyne', 'models_cache.json');
135
+ if (!home) return false;
136
+ const onboardingFile = path.join(home, '.gemini', 'antigravity-cli', 'cache', 'onboarding.json');
137
+ if (fs.existsSync(onboardingFile)) {
138
+ const parsed = JSON.parse(fs.readFileSync(onboardingFile, 'utf8'));
139
+ if (parsed && parsed.onboardingComplete === true) return true;
140
+ }
141
+ const oauthFile = path.join(home, '.gemini', 'oauth_creds.json');
142
+ if (fs.existsSync(oauthFile)) return true;
143
+ } catch {
144
+ // ignore read errors
145
+ }
146
+ return false;
147
+ }
148
+
149
+ function hydrateModelsFromDiskCache(): void {
150
+ try {
151
+ const causyneDir = process.env.CAUSYNE_HOME
152
+ || path.join(process.env.HOME || process.env.USERPROFILE || '', '.causyne');
153
+ const cacheFile = path.join(causyneDir, 'models_cache.json');
78
154
  if (!fs.existsSync(cacheFile)) return;
79
155
  const content = fs.readFileSync(cacheFile, 'utf8');
80
156
  const parsed = JSON.parse(content);
81
- const agyModels = parsed?.providers?.antigravity?.models;
82
- if (Array.isArray(agyModels)) {
157
+ const agyEntry = parsed?.providers?.antigravity;
158
+ if (agyEntry?.modelIdMap && typeof agyEntry.modelIdMap === 'object') {
159
+ for (const [label, slug] of Object.entries(agyEntry.modelIdMap)) {
160
+ if (typeof slug === 'string' && slug.trim()) {
161
+ registerAntigravityModel(slug.trim(), label);
162
+ }
163
+ }
164
+ }
165
+ const agyModels = agyEntry?.models;
166
+ if (Array.isArray(agyModels) && agyModels.length > 0) {
83
167
  for (const item of agyModels) {
84
168
  if (typeof item === 'string' && item.trim()) {
85
169
  const trimmed = item.trim();
86
- if (!ANTIGRAVITY_MODEL_IDS[trimmed]) {
87
- registerAntigravityModel(trimmed, trimmed);
88
- }
170
+ const slug = ANTIGRAVITY_MODEL_IDS[trimmed] || synthesizeAgySlug(trimmed);
171
+ registerAntigravityModel(slug, trimmed);
89
172
  }
90
173
  }
91
174
  }
@@ -125,6 +208,10 @@ export function resolveAgyModelId(model?: string | null): string {
125
208
  }
126
209
  }
127
210
 
211
+ if (/[\s()]/.test(trimmed)) {
212
+ return synthesizeAgySlug(trimmed);
213
+ }
214
+
128
215
  return trimmed;
129
216
  }
130
217