@agentuity/cli 0.0.65 → 0.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +12 -2
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +5 -1
- package/dist/cli.js.map +1 -1
- package/dist/cmd/auth/signup.js +1 -1
- package/dist/cmd/auth/signup.js.map +1 -1
- package/dist/cmd/build/index.d.ts.map +1 -1
- package/dist/cmd/build/index.js +10 -19
- package/dist/cmd/build/index.js.map +1 -1
- package/dist/cmd/build/plugin.d.ts.map +1 -1
- package/dist/cmd/build/plugin.js +8 -6
- package/dist/cmd/build/plugin.js.map +1 -1
- package/dist/cmd/cloud/db/create.js +1 -1
- package/dist/cmd/cloud/db/create.js.map +1 -1
- package/dist/cmd/cloud/db/delete.js +1 -1
- package/dist/cmd/cloud/db/delete.js.map +1 -1
- package/dist/cmd/cloud/db/get.js +1 -1
- package/dist/cmd/cloud/db/get.js.map +1 -1
- package/dist/cmd/cloud/db/list.js +1 -1
- package/dist/cmd/cloud/db/list.js.map +1 -1
- package/dist/cmd/cloud/db/logs.js +1 -1
- package/dist/cmd/cloud/db/logs.js.map +1 -1
- package/dist/cmd/cloud/db/sql.js +1 -1
- package/dist/cmd/cloud/db/sql.js.map +1 -1
- package/dist/cmd/cloud/keyvalue/util.d.ts +3 -0
- package/dist/cmd/cloud/keyvalue/util.d.ts.map +1 -1
- package/dist/cmd/cloud/keyvalue/util.js +3 -2
- package/dist/cmd/cloud/keyvalue/util.js.map +1 -1
- package/dist/cmd/cloud/objectstore/util.d.ts +3 -0
- package/dist/cmd/cloud/objectstore/util.d.ts.map +1 -1
- package/dist/cmd/cloud/objectstore/util.js +2 -2
- package/dist/cmd/cloud/objectstore/util.js.map +1 -1
- package/dist/cmd/cloud/session/get.js +3 -3
- package/dist/cmd/cloud/session/get.js.map +1 -1
- package/dist/cmd/cloud/session/list.js +3 -3
- package/dist/cmd/cloud/session/list.js.map +1 -1
- package/dist/cmd/cloud/storage/create.js +1 -1
- package/dist/cmd/cloud/storage/create.js.map +1 -1
- package/dist/cmd/cloud/storage/delete.js +1 -1
- package/dist/cmd/cloud/storage/delete.js.map +1 -1
- package/dist/cmd/cloud/storage/download.js +1 -1
- package/dist/cmd/cloud/storage/download.js.map +1 -1
- package/dist/cmd/cloud/storage/get.js +1 -1
- package/dist/cmd/cloud/storage/get.js.map +1 -1
- package/dist/cmd/cloud/storage/list.js +1 -1
- package/dist/cmd/cloud/storage/list.js.map +1 -1
- package/dist/cmd/cloud/storage/upload.js +1 -1
- package/dist/cmd/cloud/storage/upload.js.map +1 -1
- package/dist/cmd/cloud/stream/util.d.ts +3 -0
- package/dist/cmd/cloud/stream/util.d.ts.map +1 -1
- package/dist/cmd/cloud/stream/util.js +2 -2
- package/dist/cmd/cloud/stream/util.js.map +1 -1
- package/dist/cmd/cloud/thread/delete.js +3 -3
- package/dist/cmd/cloud/thread/delete.js.map +1 -1
- package/dist/cmd/cloud/thread/get.js +3 -3
- package/dist/cmd/cloud/thread/get.js.map +1 -1
- package/dist/cmd/cloud/thread/list.js +3 -3
- package/dist/cmd/cloud/thread/list.js.map +1 -1
- package/dist/cmd/cloud/vector/util.d.ts +3 -0
- package/dist/cmd/cloud/vector/util.d.ts.map +1 -1
- package/dist/cmd/cloud/vector/util.js +3 -2
- package/dist/cmd/cloud/vector/util.js.map +1 -1
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/dev/index.js +14 -20
- package/dist/cmd/dev/index.js.map +1 -1
- package/dist/cmd/project/download.d.ts.map +1 -1
- package/dist/cmd/project/download.js +16 -17
- package/dist/cmd/project/download.js.map +1 -1
- package/dist/cmd/project/template-flow.d.ts.map +1 -1
- package/dist/cmd/project/template-flow.js +5 -4
- package/dist/cmd/project/template-flow.js.map +1 -1
- package/dist/cmd/project/templates.d.ts +2 -1
- package/dist/cmd/project/templates.d.ts.map +1 -1
- package/dist/cmd/project/templates.js +4 -9
- package/dist/cmd/project/templates.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +109 -19
- package/dist/config.js.map +1 -1
- package/dist/types.d.ts +12 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +11 -35
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
- package/src/api.ts +13 -2
- package/src/cli.ts +6 -1
- package/src/cmd/auth/signup.ts +1 -1
- package/src/cmd/build/index.ts +10 -19
- package/src/cmd/build/plugin.ts +8 -6
- package/src/cmd/cloud/db/create.ts +1 -1
- package/src/cmd/cloud/db/delete.ts +1 -1
- package/src/cmd/cloud/db/get.ts +1 -1
- package/src/cmd/cloud/db/list.ts +1 -1
- package/src/cmd/cloud/db/logs.ts +1 -1
- package/src/cmd/cloud/db/sql.ts +1 -1
- package/src/cmd/cloud/keyvalue/util.ts +4 -2
- package/src/cmd/cloud/objectstore/util.ts +3 -2
- package/src/cmd/cloud/session/get.ts +3 -3
- package/src/cmd/cloud/session/list.ts +3 -3
- package/src/cmd/cloud/storage/create.ts +1 -1
- package/src/cmd/cloud/storage/delete.ts +1 -1
- package/src/cmd/cloud/storage/download.ts +1 -1
- package/src/cmd/cloud/storage/get.ts +1 -1
- package/src/cmd/cloud/storage/list.ts +1 -1
- package/src/cmd/cloud/storage/upload.ts +1 -1
- package/src/cmd/cloud/stream/util.ts +3 -2
- package/src/cmd/cloud/thread/delete.ts +3 -3
- package/src/cmd/cloud/thread/get.ts +3 -3
- package/src/cmd/cloud/thread/list.ts +3 -3
- package/src/cmd/cloud/vector/util.ts +4 -2
- package/src/cmd/dev/index.ts +14 -20
- package/src/cmd/project/download.ts +16 -17
- package/src/cmd/project/template-flow.ts +6 -4
- package/src/cmd/project/templates.ts +9 -11
- package/src/config.ts +130 -19
- package/src/types.ts +11 -35
|
@@ -22,7 +22,6 @@ import { generateLLMPrompt as generateWebPrompt } from '../ai/prompt/web';
|
|
|
22
22
|
import { generateLLMPrompt as generateAPIPrompt } from '../ai/prompt/api';
|
|
23
23
|
import type { TemplateInfo } from './templates';
|
|
24
24
|
|
|
25
|
-
const GITHUB_REPO = 'agentuity/sdk';
|
|
26
25
|
const GITHUB_BRANCH = 'main';
|
|
27
26
|
|
|
28
27
|
interface DownloadOptions {
|
|
@@ -54,7 +53,7 @@ async function cleanup(sourceDir: string, dest: string) {
|
|
|
54
53
|
});
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
tui.spinner(`📦 Copying template files...`, async () => {
|
|
56
|
+
await tui.spinner(`📦 Copying template files...`, async () => {
|
|
58
57
|
// Copy all files from source to dest
|
|
59
58
|
const files = readdirSync(sourceDir);
|
|
60
59
|
for (const file of files) {
|
|
@@ -91,14 +90,14 @@ export async function downloadTemplate(options: DownloadOptions): Promise<void>
|
|
|
91
90
|
// Download from GitHub
|
|
92
91
|
const branch = templateBranch || GITHUB_BRANCH;
|
|
93
92
|
const templatePath = `templates/${template.directory}`;
|
|
94
|
-
const url = `https://
|
|
93
|
+
const url = `https://agentuity.sh/template/sdk/${branch}/tar.gz`;
|
|
95
94
|
const tempDir = mkdtempSync(join(tmpdir(), 'agentuity-'));
|
|
96
95
|
const tarballPath = join(tempDir, 'download.tar.gz');
|
|
97
96
|
|
|
98
|
-
logger.debug('[download] URL:', url);
|
|
99
|
-
logger.debug('[download] Branch:', branch);
|
|
100
|
-
logger.debug('[download] Template path:', templatePath);
|
|
101
|
-
logger.debug('[download] Temp dir:', tempDir);
|
|
97
|
+
logger.debug('[download] URL: %s', url);
|
|
98
|
+
logger.debug('[download] Branch: %s', branch);
|
|
99
|
+
logger.debug('[download] Template path: %s', templatePath);
|
|
100
|
+
logger.debug('[download] Temp dir: %s', tempDir);
|
|
102
101
|
|
|
103
102
|
try {
|
|
104
103
|
// Step 1: Download tarball to temp file
|
|
@@ -120,8 +119,8 @@ export async function downloadTemplate(options: DownloadOptions): Promise<void>
|
|
|
120
119
|
const buffer = Buffer.concat(chunks);
|
|
121
120
|
await Bun.write(tarballPath, buffer);
|
|
122
121
|
|
|
123
|
-
logger.debug('[download] Downloaded bytes:', buffer.length);
|
|
124
|
-
logger.debug('[download] Tarball path:', tarballPath);
|
|
122
|
+
logger.debug('[download] Downloaded bytes: %dbytes', buffer.length);
|
|
123
|
+
logger.debug('[download] Tarball path: %s', tarballPath);
|
|
125
124
|
}
|
|
126
125
|
);
|
|
127
126
|
|
|
@@ -132,8 +131,8 @@ export async function downloadTemplate(options: DownloadOptions): Promise<void>
|
|
|
132
131
|
mkdirSync(extractDir, { recursive: true });
|
|
133
132
|
|
|
134
133
|
const prefix = `sdk-${branch}/${templatePath}/`;
|
|
135
|
-
logger.debug('[extract] Extract dir:', extractDir);
|
|
136
|
-
logger.debug('[extract] Filter prefix:', prefix);
|
|
134
|
+
logger.debug('[extract] Extract dir: %s', extractDir);
|
|
135
|
+
logger.debug('[extract] Filter prefix: %s', prefix);
|
|
137
136
|
|
|
138
137
|
// Track extraction stats for debugging
|
|
139
138
|
let ignoredCount = 0;
|
|
@@ -152,8 +151,8 @@ export async function downloadTemplate(options: DownloadOptions): Promise<void>
|
|
|
152
151
|
// This is a file/dir we want to extract - strip the prefix
|
|
153
152
|
header.name = header.name.substring(prefix.length);
|
|
154
153
|
mappedEntries.add(header.name); // Track that we mapped this
|
|
155
|
-
logger.debug('[extract] MAP:', originalName,
|
|
156
|
-
logger.debug('[extract] EXTRACT:', originalName);
|
|
154
|
+
logger.debug('[extract] MAP: %s -> %s', originalName, header.name);
|
|
155
|
+
logger.debug('[extract] EXTRACT: %s', originalName);
|
|
157
156
|
extractedCount++;
|
|
158
157
|
}
|
|
159
158
|
return header;
|
|
@@ -172,7 +171,7 @@ export async function downloadTemplate(options: DownloadOptions): Promise<void>
|
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
// Otherwise, ignore it
|
|
175
|
-
logger.debug('[extract] IGNORE:', header.name);
|
|
174
|
+
logger.debug('[extract] IGNORE: %s', header.name);
|
|
176
175
|
ignoredCount++;
|
|
177
176
|
return true;
|
|
178
177
|
},
|
|
@@ -183,14 +182,14 @@ export async function downloadTemplate(options: DownloadOptions): Promise<void>
|
|
|
183
182
|
await finished(extractor);
|
|
184
183
|
|
|
185
184
|
logger.debug('[extract] Extraction complete');
|
|
186
|
-
logger.debug('[extract] Ignored entries:', ignoredCount);
|
|
187
|
-
logger.debug('[extract] Extracted entries:', extractedCount);
|
|
185
|
+
logger.debug('[extract] Ignored entries: %d', ignoredCount);
|
|
186
|
+
logger.debug('[extract] Extracted entries: %d', extractedCount);
|
|
188
187
|
|
|
189
188
|
// Step 3: Copy extracted files to destination
|
|
190
189
|
await cleanup(extractDir, dest);
|
|
191
190
|
} finally {
|
|
192
191
|
// Clean up temp directory
|
|
193
|
-
logger.debug('[cleanup] Removing temp dir:', tempDir);
|
|
192
|
+
logger.debug('[cleanup] Removing temp dir: %s', tempDir);
|
|
194
193
|
rmSync(tempDir, { recursive: true, force: true });
|
|
195
194
|
}
|
|
196
195
|
}
|
|
@@ -74,7 +74,7 @@ export async function runCreateFlow(options: CreateFlowOptions): Promise<void> {
|
|
|
74
74
|
message: 'Fetching templates',
|
|
75
75
|
clearOnSuccess: true,
|
|
76
76
|
callback: async () => {
|
|
77
|
-
return fetchTemplates(templateDir, templateBranch);
|
|
77
|
+
return fetchTemplates(logger, templateDir, templateBranch);
|
|
78
78
|
},
|
|
79
79
|
});
|
|
80
80
|
|
|
@@ -90,7 +90,7 @@ export async function runCreateFlow(options: CreateFlowOptions): Promise<void> {
|
|
|
90
90
|
let catalystClient: ServerAPIClient | undefined;
|
|
91
91
|
|
|
92
92
|
if (auth) {
|
|
93
|
-
const serviceUrls = getServiceUrls();
|
|
93
|
+
const serviceUrls = getServiceUrls(region!);
|
|
94
94
|
const catalystUrl = config?.overrides?.catalyst_url ?? serviceUrls.catalyst;
|
|
95
95
|
catalystClient = new ServerAPIClient(catalystUrl, logger, auth.apiKey);
|
|
96
96
|
}
|
|
@@ -308,6 +308,8 @@ export async function runCreateFlow(options: CreateFlowOptions): Promise<void> {
|
|
|
308
308
|
if (auth && apiClient && orgId) {
|
|
309
309
|
let projectId: string | undefined;
|
|
310
310
|
|
|
311
|
+
const cloudRegion = region ?? process.env.AGENTUITY_REGION ?? 'usc';
|
|
312
|
+
|
|
311
313
|
await tui.spinner({
|
|
312
314
|
message: 'Registering your project',
|
|
313
315
|
clearOnSuccess: true,
|
|
@@ -315,7 +317,7 @@ export async function runCreateFlow(options: CreateFlowOptions): Promise<void> {
|
|
|
315
317
|
const project = await projectCreate(apiClient, {
|
|
316
318
|
name: projectName,
|
|
317
319
|
orgId,
|
|
318
|
-
cloudRegion
|
|
320
|
+
cloudRegion,
|
|
319
321
|
});
|
|
320
322
|
projectId = project.id;
|
|
321
323
|
return createProjectConfig(dest, {
|
|
@@ -325,7 +327,7 @@ export async function runCreateFlow(options: CreateFlowOptions): Promise<void> {
|
|
|
325
327
|
deployment: {
|
|
326
328
|
resources: resourceConfig,
|
|
327
329
|
},
|
|
328
|
-
region:
|
|
330
|
+
region: cloudRegion,
|
|
329
331
|
});
|
|
330
332
|
},
|
|
331
333
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { StructuredError } from '@agentuity/core';
|
|
1
|
+
import { StructuredError, Logger } from '@agentuity/core';
|
|
2
2
|
|
|
3
|
-
const GITHUB_REPO = 'agentuity/sdk';
|
|
4
3
|
const GITHUB_BRANCH = 'main';
|
|
5
|
-
const TEMPLATES_JSON_PATH = 'templates/templates.json';
|
|
6
4
|
|
|
7
5
|
export interface TemplateInfo {
|
|
8
6
|
id: string;
|
|
@@ -18,7 +16,11 @@ interface TemplatesManifest {
|
|
|
18
16
|
const TemplateMissingConfigurationError = StructuredError('TemplateMissingConfigurationError');
|
|
19
17
|
const TemplateDownloadError = StructuredError('TemplateDownloadError')<{ status: number }>();
|
|
20
18
|
|
|
21
|
-
export async function fetchTemplates(
|
|
19
|
+
export async function fetchTemplates(
|
|
20
|
+
logger: Logger,
|
|
21
|
+
localDir?: string,
|
|
22
|
+
branch?: string
|
|
23
|
+
): Promise<TemplateInfo[]> {
|
|
22
24
|
// Load from local directory if provided
|
|
23
25
|
if (localDir) {
|
|
24
26
|
const { join } = await import('node:path');
|
|
@@ -38,15 +40,11 @@ export async function fetchTemplates(localDir?: string, branch?: string): Promis
|
|
|
38
40
|
|
|
39
41
|
// Fetch from GitHub
|
|
40
42
|
const branchToUse = branch || GITHUB_BRANCH;
|
|
41
|
-
const url = `https://
|
|
43
|
+
const url = `https://agentuity.sh/template/sdk/${branchToUse}`;
|
|
42
44
|
|
|
43
|
-
const
|
|
44
|
-
if (process.env.GITHUB_TOKEN) {
|
|
45
|
-
headers['Authorization'] = `token ${process.env.GITHUB_TOKEN}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const response = await fetch(url, { headers });
|
|
45
|
+
const response = await fetch(url);
|
|
49
46
|
if (!response.ok) {
|
|
47
|
+
logger.trace('error fetching template from %s. %s', url, await response.text());
|
|
50
48
|
throw new TemplateDownloadError({
|
|
51
49
|
status: response.status,
|
|
52
50
|
message: `Failed to fetch templates: ${response.statusText}`,
|
package/src/config.ts
CHANGED
|
@@ -233,7 +233,11 @@ export async function saveConfig(config: Config, customPath?: string): Promise<v
|
|
|
233
233
|
const configPath = customPath || (await getProfile());
|
|
234
234
|
await ensureConfigDir();
|
|
235
235
|
|
|
236
|
-
|
|
236
|
+
// Strip auth from config before saving (never store auth in config file)
|
|
237
|
+
const configToSave = { ...config };
|
|
238
|
+
delete configToSave.auth;
|
|
239
|
+
|
|
240
|
+
const content = formatYAML(configToSave);
|
|
237
241
|
await writeFile(configPath, content + '\n', { mode: 0o600 });
|
|
238
242
|
// Ensure existing files get correct permissions on upgrade
|
|
239
243
|
await chmod(configPath, 0o600);
|
|
@@ -252,26 +256,61 @@ async function getOrInitConfig(): Promise<Config> {
|
|
|
252
256
|
|
|
253
257
|
export async function saveAuth(auth: AuthData): Promise<void> {
|
|
254
258
|
const config = await getOrInitConfig();
|
|
255
|
-
config.
|
|
259
|
+
const profileName = config.name || defaultProfileName;
|
|
260
|
+
|
|
261
|
+
const authData = {
|
|
256
262
|
api_key: auth.apiKey,
|
|
257
263
|
user_id: auth.userId,
|
|
258
264
|
expires: auth.expires.getTime(),
|
|
259
265
|
};
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
266
|
+
|
|
267
|
+
// Try to store in Bun secrets API
|
|
268
|
+
try {
|
|
269
|
+
await Bun.secrets.set({
|
|
270
|
+
service: `agentuity.cli.${profileName}`,
|
|
271
|
+
name: 'auth',
|
|
272
|
+
value: JSON.stringify(authData),
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Successfully stored in secrets, ensure auth is removed from config file
|
|
276
|
+
if (config.auth) {
|
|
277
|
+
delete config.auth;
|
|
278
|
+
await saveConfig(config);
|
|
279
|
+
}
|
|
280
|
+
} catch {
|
|
281
|
+
// Bun.secrets API not available or failed, fallback to config file
|
|
282
|
+
config.auth = authData;
|
|
283
|
+
config.preferences = config.preferences || {};
|
|
284
|
+
(config.preferences as Record<string, unknown>).orgId = '';
|
|
285
|
+
|
|
286
|
+
// Save with auth in config as fallback (saveConfig will try to strip it but we're setting it here)
|
|
287
|
+
const configPath = await getProfile();
|
|
288
|
+
await ensureConfigDir();
|
|
289
|
+
const content = formatYAML(config);
|
|
290
|
+
await writeFile(configPath, content + '\n', { mode: 0o600 });
|
|
291
|
+
await chmod(configPath, 0o600);
|
|
292
|
+
cachedConfig = config;
|
|
293
|
+
}
|
|
263
294
|
}
|
|
264
295
|
|
|
265
296
|
export async function clearAuth(): Promise<void> {
|
|
266
297
|
const config = await getOrInitConfig();
|
|
267
|
-
config.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
298
|
+
const profileName = config.name || defaultProfileName;
|
|
299
|
+
|
|
300
|
+
// Try to delete from Bun secrets API
|
|
301
|
+
try {
|
|
302
|
+
await Bun.secrets.delete({ service: `agentuity.cli.${profileName}`, name: 'auth' });
|
|
303
|
+
} catch {
|
|
304
|
+
// Bun.secrets API not available or failed
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Clear auth from config file (for backwards compatibility)
|
|
308
|
+
if (config.auth) {
|
|
309
|
+
delete config.auth;
|
|
310
|
+
config.preferences = config.preferences || {};
|
|
311
|
+
(config.preferences as Record<string, unknown>).orgId = '';
|
|
312
|
+
await saveConfig(config);
|
|
313
|
+
}
|
|
275
314
|
}
|
|
276
315
|
|
|
277
316
|
export async function saveProjectDir(projectDir: string): Promise<void> {
|
|
@@ -289,8 +328,59 @@ export async function saveOrgId(orgId: string): Promise<void> {
|
|
|
289
328
|
await saveConfig(config);
|
|
290
329
|
}
|
|
291
330
|
|
|
331
|
+
async function migrateAuthToSecrets(
|
|
332
|
+
config: Config,
|
|
333
|
+
profileName: string,
|
|
334
|
+
auth: { api_key: string; user_id: string; expires: number }
|
|
335
|
+
): Promise<boolean> {
|
|
336
|
+
try {
|
|
337
|
+
const authData = {
|
|
338
|
+
api_key: auth.api_key,
|
|
339
|
+
user_id: auth.user_id,
|
|
340
|
+
expires: auth.expires,
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
await Bun.secrets.set({
|
|
344
|
+
service: `agentuity.cli.${profileName}`,
|
|
345
|
+
name: 'auth',
|
|
346
|
+
value: JSON.stringify(authData),
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Successfully migrated, remove from config file
|
|
350
|
+
delete config.auth;
|
|
351
|
+
await saveConfig(config);
|
|
352
|
+
|
|
353
|
+
return true;
|
|
354
|
+
} catch {
|
|
355
|
+
// Migration failed, leave in config file
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
292
360
|
export async function getAuth(): Promise<AuthData | null> {
|
|
293
|
-
|
|
361
|
+
const config = await loadConfig();
|
|
362
|
+
const profileName = config?.name || defaultProfileName;
|
|
363
|
+
|
|
364
|
+
// Priority 1: Try Bun secrets API first (most secure)
|
|
365
|
+
try {
|
|
366
|
+
const authJson = await Bun.secrets.get({
|
|
367
|
+
service: `agentuity.cli.${profileName}`,
|
|
368
|
+
name: 'auth',
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
if (authJson) {
|
|
372
|
+
const auth = JSON.parse(authJson) as { api_key: string; user_id: string; expires: number };
|
|
373
|
+
return {
|
|
374
|
+
apiKey: auth.api_key,
|
|
375
|
+
userId: auth.user_id,
|
|
376
|
+
expires: new Date(auth.expires),
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
} catch {
|
|
380
|
+
// Bun.secrets API not available or failed, fallback to other methods
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Priority 2: Allow automated login from environment variables
|
|
294
384
|
if (process.env.AGENTUITY_CLI_API_KEY && process.env.AGENTUITY_USER_ID) {
|
|
295
385
|
return {
|
|
296
386
|
apiKey: process.env.AGENTUITY_CLI_API_KEY,
|
|
@@ -299,7 +389,7 @@ export async function getAuth(): Promise<AuthData | null> {
|
|
|
299
389
|
};
|
|
300
390
|
}
|
|
301
391
|
|
|
302
|
-
|
|
392
|
+
// Priority 3: Fallback to config file (backwards compatibility + migration)
|
|
303
393
|
if (!config) return null;
|
|
304
394
|
const auth = config.auth as { api_key?: string; user_id?: string; expires?: number } | undefined;
|
|
305
395
|
|
|
@@ -307,10 +397,23 @@ export async function getAuth(): Promise<AuthData | null> {
|
|
|
307
397
|
return null;
|
|
308
398
|
}
|
|
309
399
|
|
|
400
|
+
// Check if token is unexpired
|
|
401
|
+
const expiresDate = new Date(auth.expires || 0);
|
|
402
|
+
const isExpired = expiresDate.getTime() <= Date.now();
|
|
403
|
+
|
|
404
|
+
// If unexpired, attempt to migrate to Bun.secrets
|
|
405
|
+
if (!isExpired) {
|
|
406
|
+
await migrateAuthToSecrets(config, profileName, {
|
|
407
|
+
api_key: auth.api_key,
|
|
408
|
+
user_id: auth.user_id,
|
|
409
|
+
expires: auth.expires || 0,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
310
413
|
return {
|
|
311
414
|
apiKey: auth.api_key,
|
|
312
415
|
userId: auth.user_id,
|
|
313
|
-
expires:
|
|
416
|
+
expires: expiresDate,
|
|
314
417
|
};
|
|
315
418
|
}
|
|
316
419
|
|
|
@@ -670,13 +773,21 @@ export async function loadProjectSDKKey(
|
|
|
670
773
|
logger.trace(`[SDK_KEY] AGENTUITY_SDK_KEY not found in any file`);
|
|
671
774
|
}
|
|
672
775
|
|
|
673
|
-
export function getCatalystAPIClient(
|
|
674
|
-
|
|
675
|
-
|
|
776
|
+
export function getCatalystAPIClient(
|
|
777
|
+
config: Config | null,
|
|
778
|
+
logger: Logger,
|
|
779
|
+
auth: AuthData,
|
|
780
|
+
region: string
|
|
781
|
+
) {
|
|
782
|
+
const serviceUrls = getServiceUrls(region);
|
|
783
|
+
const catalystUrl = serviceUrls.catalyst;
|
|
676
784
|
return new ServerAPIClient(catalystUrl, logger, auth.apiKey);
|
|
677
785
|
}
|
|
678
786
|
|
|
679
787
|
export function getIONHost(config: Config | null) {
|
|
788
|
+
if (config?.name === 'local') {
|
|
789
|
+
return 'ion.agentuity.io';
|
|
790
|
+
}
|
|
680
791
|
const url = new URL(config?.overrides?.ion_url ?? 'https://ion.agentuity.cloud');
|
|
681
792
|
return url.hostname;
|
|
682
793
|
}
|
package/src/types.ts
CHANGED
|
@@ -26,44 +26,20 @@ export const ConfigSchema = zod.object({
|
|
|
26
26
|
.describe('Development mode configuration'),
|
|
27
27
|
overrides: zod
|
|
28
28
|
.object({
|
|
29
|
-
api_url: zod.url().
|
|
30
|
-
app_url: zod.url().
|
|
31
|
-
transport_url: zod
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
kv_url: zod
|
|
40
|
-
.url()
|
|
41
|
-
.default('https://catalyst.agentuity.cloud')
|
|
42
|
-
.describe('Override keyvalue URL'),
|
|
43
|
-
object_url: zod
|
|
44
|
-
.url()
|
|
45
|
-
.default('https://catalyst.agentuity.cloud')
|
|
46
|
-
.describe('Override object store URL'),
|
|
47
|
-
vector_url: zod
|
|
48
|
-
.url()
|
|
49
|
-
.default('https://catalyst.agentuity.cloud')
|
|
50
|
-
.describe('Override vector store URL'),
|
|
51
|
-
catalyst_url: zod
|
|
52
|
-
.url()
|
|
53
|
-
.default('https://catalyst.agentuity.cloud')
|
|
54
|
-
.describe('Override catalyst URL'),
|
|
55
|
-
ion_url: zod
|
|
56
|
-
.url()
|
|
57
|
-
.optional()
|
|
58
|
-
.default('https://ion.agentuity.cloud')
|
|
59
|
-
.describe('Override ion URL'),
|
|
60
|
-
gravity_url: zod
|
|
61
|
-
.url()
|
|
62
|
-
.default('grpc://devmode.agentuity.com')
|
|
63
|
-
.describe('Override gravity URL'),
|
|
29
|
+
api_url: zod.url().optional().describe('Override API base URL'),
|
|
30
|
+
app_url: zod.url().optional().describe('Override app base URL'),
|
|
31
|
+
transport_url: zod.url().optional().describe('Override transport URL'),
|
|
32
|
+
stream_url: zod.url().optional().describe('Override stream URL'),
|
|
33
|
+
kv_url: zod.url().optional().describe('Override keyvalue URL'),
|
|
34
|
+
object_url: zod.url().optional().describe('Override object store URL'),
|
|
35
|
+
vector_url: zod.url().optional().describe('Override vector store URL'),
|
|
36
|
+
catalyst_url: zod.url().optional().describe('Override catalyst URL'),
|
|
37
|
+
ion_url: zod.url().optional().describe('Override ion URL'),
|
|
38
|
+
gravity_url: zod.url().optional().describe('Override gravity URL'),
|
|
64
39
|
skip_version_check: zod.boolean().optional().describe('Skip CLI version check on startup'),
|
|
65
40
|
})
|
|
66
41
|
.optional()
|
|
42
|
+
.nullable()
|
|
67
43
|
.describe('URL and behavior overrides'),
|
|
68
44
|
preferences: zod
|
|
69
45
|
.object({
|