@agentuity/cli 0.0.65 → 0.0.66

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.
Files changed (119) hide show
  1. package/dist/api.d.ts +1 -0
  2. package/dist/api.d.ts.map +1 -1
  3. package/dist/api.js +12 -2
  4. package/dist/api.js.map +1 -1
  5. package/dist/cli.d.ts.map +1 -1
  6. package/dist/cli.js +5 -1
  7. package/dist/cli.js.map +1 -1
  8. package/dist/cmd/auth/signup.js +1 -1
  9. package/dist/cmd/auth/signup.js.map +1 -1
  10. package/dist/cmd/build/index.d.ts.map +1 -1
  11. package/dist/cmd/build/index.js +10 -19
  12. package/dist/cmd/build/index.js.map +1 -1
  13. package/dist/cmd/build/plugin.d.ts.map +1 -1
  14. package/dist/cmd/build/plugin.js +8 -6
  15. package/dist/cmd/build/plugin.js.map +1 -1
  16. package/dist/cmd/cloud/db/create.js +1 -1
  17. package/dist/cmd/cloud/db/create.js.map +1 -1
  18. package/dist/cmd/cloud/db/delete.js +1 -1
  19. package/dist/cmd/cloud/db/delete.js.map +1 -1
  20. package/dist/cmd/cloud/db/get.js +1 -1
  21. package/dist/cmd/cloud/db/get.js.map +1 -1
  22. package/dist/cmd/cloud/db/list.js +1 -1
  23. package/dist/cmd/cloud/db/list.js.map +1 -1
  24. package/dist/cmd/cloud/db/logs.js +1 -1
  25. package/dist/cmd/cloud/db/logs.js.map +1 -1
  26. package/dist/cmd/cloud/db/sql.js +1 -1
  27. package/dist/cmd/cloud/db/sql.js.map +1 -1
  28. package/dist/cmd/cloud/keyvalue/util.d.ts +3 -0
  29. package/dist/cmd/cloud/keyvalue/util.d.ts.map +1 -1
  30. package/dist/cmd/cloud/keyvalue/util.js +3 -2
  31. package/dist/cmd/cloud/keyvalue/util.js.map +1 -1
  32. package/dist/cmd/cloud/objectstore/util.d.ts +3 -0
  33. package/dist/cmd/cloud/objectstore/util.d.ts.map +1 -1
  34. package/dist/cmd/cloud/objectstore/util.js +2 -2
  35. package/dist/cmd/cloud/objectstore/util.js.map +1 -1
  36. package/dist/cmd/cloud/session/get.js +3 -3
  37. package/dist/cmd/cloud/session/get.js.map +1 -1
  38. package/dist/cmd/cloud/session/list.js +3 -3
  39. package/dist/cmd/cloud/session/list.js.map +1 -1
  40. package/dist/cmd/cloud/storage/create.js +1 -1
  41. package/dist/cmd/cloud/storage/create.js.map +1 -1
  42. package/dist/cmd/cloud/storage/delete.js +1 -1
  43. package/dist/cmd/cloud/storage/delete.js.map +1 -1
  44. package/dist/cmd/cloud/storage/download.js +1 -1
  45. package/dist/cmd/cloud/storage/download.js.map +1 -1
  46. package/dist/cmd/cloud/storage/get.js +1 -1
  47. package/dist/cmd/cloud/storage/get.js.map +1 -1
  48. package/dist/cmd/cloud/storage/list.js +1 -1
  49. package/dist/cmd/cloud/storage/list.js.map +1 -1
  50. package/dist/cmd/cloud/storage/upload.js +1 -1
  51. package/dist/cmd/cloud/storage/upload.js.map +1 -1
  52. package/dist/cmd/cloud/stream/util.d.ts +3 -0
  53. package/dist/cmd/cloud/stream/util.d.ts.map +1 -1
  54. package/dist/cmd/cloud/stream/util.js +2 -2
  55. package/dist/cmd/cloud/stream/util.js.map +1 -1
  56. package/dist/cmd/cloud/thread/delete.js +3 -3
  57. package/dist/cmd/cloud/thread/delete.js.map +1 -1
  58. package/dist/cmd/cloud/thread/get.js +3 -3
  59. package/dist/cmd/cloud/thread/get.js.map +1 -1
  60. package/dist/cmd/cloud/thread/list.js +3 -3
  61. package/dist/cmd/cloud/thread/list.js.map +1 -1
  62. package/dist/cmd/cloud/vector/util.d.ts +3 -0
  63. package/dist/cmd/cloud/vector/util.d.ts.map +1 -1
  64. package/dist/cmd/cloud/vector/util.js +3 -2
  65. package/dist/cmd/cloud/vector/util.js.map +1 -1
  66. package/dist/cmd/dev/index.d.ts.map +1 -1
  67. package/dist/cmd/dev/index.js +14 -20
  68. package/dist/cmd/dev/index.js.map +1 -1
  69. package/dist/cmd/project/download.d.ts.map +1 -1
  70. package/dist/cmd/project/download.js +15 -16
  71. package/dist/cmd/project/download.js.map +1 -1
  72. package/dist/cmd/project/template-flow.d.ts.map +1 -1
  73. package/dist/cmd/project/template-flow.js +5 -4
  74. package/dist/cmd/project/template-flow.js.map +1 -1
  75. package/dist/cmd/project/templates.d.ts +2 -1
  76. package/dist/cmd/project/templates.d.ts.map +1 -1
  77. package/dist/cmd/project/templates.js +4 -9
  78. package/dist/cmd/project/templates.js.map +1 -1
  79. package/dist/config.d.ts +1 -1
  80. package/dist/config.d.ts.map +1 -1
  81. package/dist/config.js +109 -19
  82. package/dist/config.js.map +1 -1
  83. package/dist/types.d.ts +12 -12
  84. package/dist/types.d.ts.map +1 -1
  85. package/dist/types.js +11 -35
  86. package/dist/types.js.map +1 -1
  87. package/package.json +3 -3
  88. package/src/api.ts +13 -2
  89. package/src/cli.ts +6 -1
  90. package/src/cmd/auth/signup.ts +1 -1
  91. package/src/cmd/build/index.ts +10 -19
  92. package/src/cmd/build/plugin.ts +8 -6
  93. package/src/cmd/cloud/db/create.ts +1 -1
  94. package/src/cmd/cloud/db/delete.ts +1 -1
  95. package/src/cmd/cloud/db/get.ts +1 -1
  96. package/src/cmd/cloud/db/list.ts +1 -1
  97. package/src/cmd/cloud/db/logs.ts +1 -1
  98. package/src/cmd/cloud/db/sql.ts +1 -1
  99. package/src/cmd/cloud/keyvalue/util.ts +4 -2
  100. package/src/cmd/cloud/objectstore/util.ts +3 -2
  101. package/src/cmd/cloud/session/get.ts +3 -3
  102. package/src/cmd/cloud/session/list.ts +3 -3
  103. package/src/cmd/cloud/storage/create.ts +1 -1
  104. package/src/cmd/cloud/storage/delete.ts +1 -1
  105. package/src/cmd/cloud/storage/download.ts +1 -1
  106. package/src/cmd/cloud/storage/get.ts +1 -1
  107. package/src/cmd/cloud/storage/list.ts +1 -1
  108. package/src/cmd/cloud/storage/upload.ts +1 -1
  109. package/src/cmd/cloud/stream/util.ts +3 -2
  110. package/src/cmd/cloud/thread/delete.ts +3 -3
  111. package/src/cmd/cloud/thread/get.ts +3 -3
  112. package/src/cmd/cloud/thread/list.ts +3 -3
  113. package/src/cmd/cloud/vector/util.ts +4 -2
  114. package/src/cmd/dev/index.ts +14 -20
  115. package/src/cmd/project/download.ts +15 -16
  116. package/src/cmd/project/template-flow.ts +6 -4
  117. package/src/cmd/project/templates.ts +9 -11
  118. package/src/config.ts +130 -19
  119. package/src/types.ts +11 -35
@@ -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: region ?? 'usc',
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: region ?? 'usc',
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(localDir?: string, branch?: string): Promise<TemplateInfo[]> {
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://raw.githubusercontent.com/${GITHUB_REPO}/${branchToUse}/${TEMPLATES_JSON_PATH}`;
43
+ const url = `https://agentuity.sh/template/sdk/${branchToUse}`;
42
44
 
43
- const headers: Record<string, string> = {};
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
- const content = formatYAML(config);
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.auth = {
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
- config.preferences = config.preferences || {};
261
- (config.preferences as Record<string, unknown>).orgId = '';
262
- await saveConfig(config);
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.auth = {
268
- api_key: '',
269
- user_id: '',
270
- expires: Date.now(),
271
- };
272
- config.preferences = config.preferences || {};
273
- (config.preferences as Record<string, unknown>).orgId = '';
274
- await saveConfig(config);
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
- // allow automated login from environment variables if present
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
- const config = await loadConfig();
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: new Date(auth.expires || 0),
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(config: Config | null, logger: Logger, auth: AuthData) {
674
- const serviceUrls = getServiceUrls();
675
- const catalystUrl = config?.overrides?.catalyst_url ?? serviceUrls.catalyst;
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().default('https://api.agentuity.com').describe('Override API base URL'),
30
- app_url: zod.url().default('https://app.agentuity.com').describe('Override app base URL'),
31
- transport_url: zod
32
- .url()
33
- .default('https://catalyst.agentuity.cloud')
34
- .describe('Override transport URL'),
35
- stream_url: zod
36
- .url()
37
- .default('https://stream.agentuity.cloud')
38
- .describe('Override stream URL'),
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({