@castari/cli 0.1.11 → 0.2.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.
Files changed (70) hide show
  1. package/bin/cast.js +2 -0
  2. package/dist/commands/agents.d.ts +6 -0
  3. package/dist/commands/agents.d.ts.map +1 -0
  4. package/dist/commands/agents.js +174 -0
  5. package/dist/commands/agents.js.map +1 -0
  6. package/dist/commands/apikey.d.ts +6 -0
  7. package/dist/commands/apikey.d.ts.map +1 -0
  8. package/dist/commands/apikey.js +57 -0
  9. package/dist/commands/apikey.js.map +1 -0
  10. package/dist/commands/deploy.d.ts +3 -3
  11. package/dist/commands/deploy.d.ts.map +1 -0
  12. package/dist/commands/deploy.js +24 -64
  13. package/dist/commands/deploy.js.map +1 -0
  14. package/dist/commands/invoke.d.ts +3 -0
  15. package/dist/commands/invoke.d.ts.map +1 -0
  16. package/dist/commands/invoke.js +50 -0
  17. package/dist/commands/invoke.js.map +1 -0
  18. package/dist/commands/login.d.ts +3 -0
  19. package/dist/commands/login.d.ts.map +1 -0
  20. package/dist/commands/login.js +123 -0
  21. package/dist/commands/login.js.map +1 -0
  22. package/dist/commands/logout.d.ts +3 -0
  23. package/dist/commands/logout.d.ts.map +1 -0
  24. package/dist/commands/logout.js +16 -0
  25. package/dist/commands/logout.js.map +1 -0
  26. package/dist/commands/secrets.d.ts +6 -0
  27. package/dist/commands/secrets.d.ts.map +1 -0
  28. package/dist/commands/secrets.js +90 -0
  29. package/dist/commands/secrets.js.map +1 -0
  30. package/dist/commands/stop.d.ts +3 -0
  31. package/dist/commands/stop.d.ts.map +1 -0
  32. package/dist/commands/stop.js +25 -0
  33. package/dist/commands/stop.js.map +1 -0
  34. package/dist/commands/usage.d.ts +3 -0
  35. package/dist/commands/usage.d.ts.map +1 -0
  36. package/dist/commands/usage.js +76 -0
  37. package/dist/commands/usage.js.map +1 -0
  38. package/dist/commands/whoami.d.ts +3 -0
  39. package/dist/commands/whoami.d.ts.map +1 -0
  40. package/dist/commands/whoami.js +27 -0
  41. package/dist/commands/whoami.js.map +1 -0
  42. package/dist/index.d.ts +2 -1
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +36 -34
  45. package/dist/index.js.map +1 -0
  46. package/dist/utils/errors.d.ts +6 -0
  47. package/dist/utils/errors.d.ts.map +1 -0
  48. package/dist/utils/errors.js +42 -0
  49. package/dist/utils/errors.js.map +1 -0
  50. package/dist/utils/output.d.ts +45 -0
  51. package/dist/utils/output.d.ts.map +1 -0
  52. package/dist/utils/output.js +75 -0
  53. package/dist/utils/output.js.map +1 -0
  54. package/package.json +55 -35
  55. package/LICENSE +0 -21
  56. package/README.md +0 -151
  57. package/dist/commands/client-id.d.ts +0 -1
  58. package/dist/commands/client-id.js +0 -25
  59. package/dist/commands/dev.d.ts +0 -1
  60. package/dist/commands/dev.js +0 -17
  61. package/dist/commands/generate-secrets.d.ts +0 -1
  62. package/dist/commands/generate-secrets.js +0 -60
  63. package/dist/commands/init.d.ts +0 -5
  64. package/dist/commands/init.js +0 -899
  65. package/dist/commands/start.d.ts +0 -5
  66. package/dist/commands/start.js +0 -100
  67. package/dist/utils/client-auth.d.ts +0 -11
  68. package/dist/utils/client-auth.js +0 -21
  69. package/dist/utils/client-id.d.ts +0 -10
  70. package/dist/utils/client-id.js +0 -36
@@ -1,5 +0,0 @@
1
- export declare function start(options: {
2
- snapshot?: string;
3
- volume?: string;
4
- id?: string;
5
- }): Promise<void>;
@@ -1,100 +0,0 @@
1
- import { CastariClient } from '@castari/sdk/client';
2
- import { readFile } from 'fs/promises';
3
- import chalk from 'chalk';
4
- import dotenv from 'dotenv';
5
- import { getClientAuthOrExit } from '../utils/client-auth';
6
- export async function start(options) {
7
- // Load .env from current directory
8
- dotenv.config();
9
- // Read package.json for defaults
10
- let snapshotName = options.snapshot;
11
- let volumeName = options.volume;
12
- try {
13
- const pkg = JSON.parse(await readFile('package.json', 'utf-8'));
14
- if (!snapshotName)
15
- snapshotName = pkg.name;
16
- if (!volumeName)
17
- volumeName = pkg.castari?.volume;
18
- }
19
- catch (e) {
20
- // Ignore if package.json missing
21
- }
22
- const { clientId, apiKey } = await getClientAuthOrExit();
23
- if (!snapshotName) {
24
- console.error(chalk.red('Error: Snapshot name is required.'));
25
- process.exit(1);
26
- }
27
- console.log(chalk.blue(`šŸš€ Starting agent "${snapshotName}"...`));
28
- if (volumeName) {
29
- console.log(chalk.blue(`šŸ“¦ Using volume: ${volumeName}`));
30
- }
31
- else {
32
- console.log(chalk.blue(`šŸ“¦ No volume specified (sandbox will be ephemeral)`));
33
- }
34
- const platformUrl = process.env.CASTARI_PLATFORM_URL;
35
- const clientOptions = {
36
- snapshot: snapshotName,
37
- ...(volumeName ? { volume: volumeName } : {}),
38
- platformUrl,
39
- debug: true, // Enable debug logs for CLI
40
- anthropicApiKey: process.env.ANTHROPIC_API_KEY,
41
- clientId,
42
- };
43
- if (apiKey)
44
- clientOptions.platformApiKey = apiKey;
45
- const client = new CastariClient(clientOptions);
46
- try {
47
- await client.start();
48
- console.log(chalk.green('āœ… Agent started!'));
49
- console.log(chalk.cyan('Type a message to chat with the agent (Ctrl+C to exit):'));
50
- const stdin = process.stdin;
51
- stdin.addListener('data', (d) => {
52
- const input = d.toString().trim();
53
- if (input) {
54
- client.send({
55
- type: 'user_message',
56
- data: {
57
- type: 'user',
58
- message: {
59
- role: 'user',
60
- content: input
61
- }
62
- }
63
- });
64
- }
65
- });
66
- client.onMessage((msg) => {
67
- if (msg.type === 'sdk_message') {
68
- const data = msg.data;
69
- if (data.type === 'assistant_message') {
70
- // Handle text content
71
- if (typeof data.message.content === 'string') {
72
- console.log(chalk.green('Agent:'), data.message.content);
73
- }
74
- else if (Array.isArray(data.message.content)) {
75
- data.message.content.forEach((block) => {
76
- if (block.type === 'text') {
77
- console.log(chalk.green('Agent:'), block.text);
78
- }
79
- });
80
- }
81
- }
82
- }
83
- else if (msg.type === 'error') {
84
- console.error(chalk.red('Error:'), msg.error);
85
- }
86
- });
87
- // Add signal handlers for graceful shutdown
88
- const cleanup = async () => {
89
- console.log(chalk.yellow('\nšŸ›‘ Shutting down...'));
90
- await client.stop({ delete: true });
91
- process.exit(0);
92
- };
93
- process.on('SIGINT', cleanup);
94
- process.on('SIGTERM', cleanup);
95
- }
96
- catch (err) {
97
- console.error(chalk.red('Failed to start agent:'), err.message || err);
98
- process.exit(1);
99
- }
100
- }
@@ -1,11 +0,0 @@
1
- export type ClientAuth = {
2
- clientId: string;
3
- apiKey?: string;
4
- };
5
- export declare function getClientAuthOrExit(): Promise<ClientAuth>;
6
- export declare function saveClientAuth(data: {
7
- clientId: string;
8
- apiKey?: string;
9
- source?: 'online' | 'offline';
10
- platformUrl?: string;
11
- }): Promise<void>;
@@ -1,21 +0,0 @@
1
- import { getClientIdOrExit, loadClientId, saveClientId } from './client-id';
2
- export async function getClientAuthOrExit() {
3
- const clientId = await getClientIdOrExit();
4
- const stored = await loadClientId();
5
- const apiKey = process.env.CASTARI_API_KEY ||
6
- stored?.apiKey;
7
- if (!apiKey) {
8
- // We allow missing apiKey for now (platform may allow unauthenticated in dev)
9
- return { clientId };
10
- }
11
- return { clientId, apiKey };
12
- }
13
- export async function saveClientAuth(data) {
14
- await saveClientId({
15
- clientId: data.clientId,
16
- apiKey: data.apiKey,
17
- source: data.source,
18
- createdAt: new Date().toISOString(),
19
- platformUrl: data.platformUrl,
20
- });
21
- }
@@ -1,10 +0,0 @@
1
- export type StoredClientId = {
2
- clientId: string;
3
- source?: 'online' | 'offline';
4
- createdAt?: string;
5
- platformUrl?: string;
6
- apiKey?: string;
7
- };
8
- export declare function loadClientId(): Promise<StoredClientId | null>;
9
- export declare function saveClientId(data: StoredClientId): Promise<void>;
10
- export declare function getClientIdOrExit(explicit?: string): Promise<string>;
@@ -1,36 +0,0 @@
1
- import { homedir } from 'os';
2
- import { join } from 'path';
3
- import { mkdir, readFile, writeFile } from 'fs/promises';
4
- import chalk from 'chalk';
5
- const CONFIG_DIR = join(homedir(), '.castari');
6
- const CONFIG_PATH = join(CONFIG_DIR, 'client.json');
7
- export async function loadClientId() {
8
- try {
9
- const raw = await readFile(CONFIG_PATH, 'utf-8');
10
- const parsed = JSON.parse(raw);
11
- if (parsed.clientId && typeof parsed.clientId === 'string') {
12
- return parsed;
13
- }
14
- return null;
15
- }
16
- catch {
17
- return null;
18
- }
19
- }
20
- export async function saveClientId(data) {
21
- await mkdir(CONFIG_DIR, { recursive: true });
22
- await writeFile(CONFIG_PATH, JSON.stringify(data, null, 2));
23
- }
24
- export async function getClientIdOrExit(explicit) {
25
- const envId = process.env.CASTARI_CLIENT_ID;
26
- if (explicit)
27
- return explicit;
28
- if (envId)
29
- return envId;
30
- const stored = await loadClientId();
31
- if (stored?.clientId)
32
- return stored.clientId;
33
- console.error(chalk.red('CASTARI_CLIENT_ID is required.'));
34
- console.error(chalk.white('Run `castari generate-secrets` to create one, or set CASTARI_CLIENT_ID in your environment.'));
35
- process.exit(1);
36
- }