@castari/sdk 0.1.4 → 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.
package/README.md CHANGED
@@ -1,151 +1,139 @@
1
1
  # @castari/sdk
2
2
 
3
- The SDK for building and connecting to Castari agents.
3
+ Official Castari SDK for TypeScript and Node.js.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
8
  npm install @castari/sdk
9
- # or
10
- bun add @castari/sdk
11
9
  ```
12
10
 
13
- ## Building Agents
14
-
15
- ### `serve(options)`
16
-
17
- Starts the agent server. This should be the entrypoint of your agent.
11
+ ## Quick Start
18
12
 
19
13
  ```typescript
20
- import { serve, tool } from '@castari/sdk'
14
+ import { CastariClient } from '@castari/sdk';
21
15
 
22
- serve({
23
- tools: [myTool],
24
- systemPrompt: 'You are a helpful assistant.'
25
- })
26
- ```
16
+ // Using API key
17
+ const client = new CastariClient({
18
+ apiKey: process.env.CASTARI_API_KEY,
19
+ });
27
20
 
28
- #### Options
21
+ // Or let it load from ~/.castari/credentials.yaml
22
+ const client = new CastariClient();
23
+ await client.ensureAuthenticated();
29
24
 
30
- | Property | Type | Description |
31
- |----------|------|-------------|
32
- | `tools` | `Tool[]` | Array of tools exposed by the agent |
33
- | `systemPrompt` | `string` | The system prompt defining the agent's behavior |
34
- | `allowedTools` | `string[]` | (Optional) Restrict which tools the agent can use |
35
- | `port` | `number` | (Optional) Port to listen on. Defaults to `3000` |
25
+ // List agents
26
+ const agents = await client.agents.list();
36
27
 
37
- By default, agents have access to all system tools (Bash, File Editing, etc.) plus any custom tools you define. Use `allowedTools` to restrict access:
28
+ // Deploy an agent
29
+ await client.agents.deploy('my-agent');
38
30
 
39
- ```typescript
40
- serve({
41
- tools: [myCustomTool],
42
- allowedTools: ['my_custom_tool', 'Bash'] // Only these tools available
43
- })
31
+ // Invoke an agent
32
+ const result = await client.agents.invoke('my-agent', {
33
+ prompt: 'Hello, world!',
34
+ });
35
+
36
+ console.log(result.response_content);
44
37
  ```
45
38
 
46
- ### `tool(definition)`
39
+ ## API Reference
47
40
 
48
- Defines a custom tool for the agent.
41
+ ### CastariClient
49
42
 
50
43
  ```typescript
51
- import { tool } from '@castari/sdk'
52
-
53
- const weatherTool = tool({
54
- name: 'get_weather',
55
- description: 'Get the weather for a location',
56
- inputSchema: {
57
- type: 'object',
58
- properties: {
59
- location: { type: 'string' }
60
- },
61
- required: ['location']
62
- },
63
- handler: async ({ location }) => {
64
- return `The weather in ${location} is sunny.`
65
- }
66
- })
44
+ const client = new CastariClient({
45
+ apiKey?: string, // API key (cast_...)
46
+ token?: string, // OAuth token
47
+ baseUrl?: string, // API base URL
48
+ });
67
49
  ```
68
50
 
69
- ## Connecting to Agents
70
-
71
- ### `CastariClient`
72
-
73
- A client for connecting to Castari agents.
51
+ ### Agents
74
52
 
75
53
  ```typescript
76
- import { CastariClient } from '@castari/sdk/client'
54
+ // List all agents
55
+ const agents = await client.agents.list();
77
56
 
78
- const client = new CastariClient({
79
- snapshot: 'my-agent',
80
- clientId: process.env.CASTARI_CLIENT_ID,
81
- platformApiKey: process.env.CASTARI_API_KEY,
82
- anthropicApiKey: process.env.ANTHROPIC_API_KEY,
83
- })
57
+ // Create an agent
58
+ const agent = await client.agents.create({
59
+ name: 'My Agent',
60
+ gitRepoUrl: 'https://github.com/user/repo',
61
+ slug: 'my-agent',
62
+ });
84
63
 
85
- await client.start()
64
+ // Get agent by slug
65
+ const agent = await client.agents.get('my-agent');
86
66
 
87
- client.onMessage((msg) => {
88
- console.log('Agent:', msg)
89
- })
67
+ // Delete an agent
68
+ await client.agents.delete('my-agent');
90
69
 
91
- client.send({
92
- type: 'user_message',
93
- data: { message: 'Hello!' }
94
- })
70
+ // Deploy an agent
71
+ const agent = await client.agents.deploy('my-agent');
95
72
 
96
- // When done
97
- await client.stop()
73
+ // Invoke an agent
74
+ const result = await client.agents.invoke('my-agent', {
75
+ prompt: 'Your prompt here',
76
+ });
98
77
  ```
99
78
 
100
- #### Constructor Options
79
+ ### Secrets
101
80
 
102
- | Property | Type | Description |
103
- |----------|------|-------------|
104
- | `snapshot` | `string` | Name of the snapshot to use |
105
- | `clientId` | `string` | Your Castari client ID |
106
- | `platformApiKey` | `string` | Your Castari API key |
107
- | `anthropicApiKey` | `string` | Your Anthropic API key |
108
- | `volume` | `string` | (Optional) Volume name for persistent storage |
109
- | `labels` | `Record<string, string>` | (Optional) Labels for sandbox reuse |
110
- | `connectionUrl` | `string` | (Optional) Direct URL for local development |
111
- | `platformUrl` | `string` | (Optional) Override the platform URL (advanced) |
81
+ ```typescript
82
+ // List secrets (keys only, values are never returned)
83
+ const secrets = await client.agents.listSecrets('my-agent');
84
+
85
+ // Set a secret
86
+ await client.agents.setSecret('my-agent', 'API_KEY', 'secret-value');
87
+
88
+ // Delete a secret
89
+ await client.agents.deleteSecret('my-agent', 'API_KEY');
90
+ ```
112
91
 
113
- #### Methods
92
+ ### Usage
114
93
 
115
- - `start()` - Creates a sandbox and connects to the agent
116
- - `stop(options?)` - Disconnects and cleans up
117
- - `{ delete: false }` - Stop but preserve sandbox for reuse
118
- - `send(message)` - Send a message to the agent
119
- - `onMessage(callback)` - Register a callback for incoming messages
94
+ ```typescript
95
+ // Get usage summary
96
+ const summary = await client.usage.summary({ days: 30 });
120
97
 
121
- ### Sandbox Reuse
98
+ // Get daily breakdown
99
+ const daily = await client.usage.daily({ days: 7 });
100
+ ```
122
101
 
123
- Use labels to reuse sandboxes across sessions:
102
+ ### Auth
124
103
 
125
104
  ```typescript
126
- const client = new CastariClient({
127
- snapshot: 'my-agent',
128
- volume: `user-${userId}`,
129
- labels: {
130
- userId,
131
- app: 'my-app'
132
- }
133
- })
105
+ // Get current user
106
+ const user = await client.auth.me();
134
107
 
135
- // First call creates, subsequent calls reuse
136
- await client.start()
108
+ // Create API key
109
+ const { api_key, prefix } = await client.auth.createApiKey();
137
110
 
138
- // Stop but preserve for later
139
- await client.stop({ delete: false })
111
+ // Revoke API key
112
+ await client.auth.revokeApiKey();
140
113
  ```
141
114
 
142
- ## Environment Variables
115
+ ## Error Handling
143
116
 
144
- | Variable | Description |
145
- |----------|-------------|
146
- | `ANTHROPIC_API_KEY` | Your Anthropic API key |
147
- | `CASTARI_CLIENT_ID` | Your Castari client ID |
148
- | `CASTARI_API_KEY` | Your Castari API key |
117
+ ```typescript
118
+ import {
119
+ CastariError,
120
+ AuthenticationError,
121
+ NotFoundError,
122
+ RateLimitError,
123
+ } from '@castari/sdk';
124
+
125
+ try {
126
+ await client.agents.get('non-existent');
127
+ } catch (error) {
128
+ if (error instanceof NotFoundError) {
129
+ console.log('Agent not found');
130
+ } else if (error instanceof AuthenticationError) {
131
+ console.log('Not authenticated');
132
+ } else if (error instanceof RateLimitError) {
133
+ console.log(`Rate limited, retry in ${error.retryAfter}s`);
134
+ }
135
+ }
136
+ ```
149
137
 
150
138
  ## License
151
139
 
@@ -0,0 +1,76 @@
1
+ import type { HttpClient } from './http.js';
2
+ import type { Agent, CreateAgentOptions, InvocationResponse, InvokeOptions, Secret } from './types.js';
3
+ /**
4
+ * API for managing agents
5
+ */
6
+ export declare class AgentsAPI {
7
+ private client;
8
+ constructor(client: HttpClient);
9
+ /**
10
+ * List all agents for the authenticated user
11
+ * @returns Array of agents
12
+ */
13
+ list(): Promise<Agent[]>;
14
+ /**
15
+ * Create a new agent
16
+ * @param options - Agent creation options
17
+ * @returns The created agent
18
+ */
19
+ create(options: CreateAgentOptions): Promise<Agent>;
20
+ /**
21
+ * Get an agent by slug
22
+ * @param slug - The agent's unique slug
23
+ * @returns The agent
24
+ * @throws NotFoundError if agent doesn't exist
25
+ */
26
+ get(slug: string): Promise<Agent>;
27
+ /**
28
+ * Delete an agent
29
+ * @param slug - The agent's unique slug
30
+ * @throws NotFoundError if agent doesn't exist
31
+ */
32
+ delete(slug: string): Promise<void>;
33
+ /**
34
+ * Deploy an agent (create sandbox, clone repo, install deps)
35
+ * @param slug - The agent's unique slug
36
+ * @returns The updated agent with status 'active'
37
+ * @throws NotFoundError if agent doesn't exist
38
+ */
39
+ deploy(slug: string): Promise<Agent>;
40
+ /**
41
+ * Stop a running agent
42
+ * @param slug - The agent's unique slug
43
+ * @returns The updated agent with status 'stopped'
44
+ * @throws NotFoundError if agent doesn't exist
45
+ */
46
+ stop(slug: string): Promise<Agent>;
47
+ /**
48
+ * Invoke an agent with a prompt
49
+ * @param slug - The agent's unique slug
50
+ * @param options - Invocation options including prompt
51
+ * @returns The invocation response with result and usage stats
52
+ * @throws NotFoundError if agent doesn't exist
53
+ * @throws BadRequestError if agent is not deployed
54
+ */
55
+ invoke(slug: string, options: InvokeOptions): Promise<InvocationResponse>;
56
+ /**
57
+ * List secret keys for an agent (values are never returned)
58
+ * @param slug - The agent's unique slug
59
+ * @returns Array of secret key names
60
+ */
61
+ listSecrets(slug: string): Promise<Secret[]>;
62
+ /**
63
+ * Set a secret for an agent
64
+ * @param slug - The agent's unique slug
65
+ * @param key - The secret key
66
+ * @param value - The secret value
67
+ */
68
+ setSecret(slug: string, key: string, value: string): Promise<void>;
69
+ /**
70
+ * Delete a secret from an agent
71
+ * @param slug - The agent's unique slug
72
+ * @param key - The secret key to delete
73
+ */
74
+ deleteSecret(slug: string, key: string): Promise<void>;
75
+ }
76
+ //# sourceMappingURL=agents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EACV,KAAK,EAEL,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,MAAM,EACP,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,SAAS;IACR,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAK9B;;;;OAIG;IACG,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC;IAUzD;;;;;OAKG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAIvC;;;;OAIG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC;;;;;OAKG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAM1C;;;;;OAKG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAIxC;;;;;;;OAOG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAW/E;;;;OAIG;IACG,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAKlD;;;;;OAKG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxE;;;;OAIG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAM7D"}
package/dist/agents.js ADDED
@@ -0,0 +1,111 @@
1
+ /**
2
+ * API for managing agents
3
+ */
4
+ export class AgentsAPI {
5
+ client;
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ /**
10
+ * List all agents for the authenticated user
11
+ * @returns Array of agents
12
+ */
13
+ async list() {
14
+ const response = await this.client.request('GET', '/agents');
15
+ return response.agents;
16
+ }
17
+ /**
18
+ * Create a new agent
19
+ * @param options - Agent creation options
20
+ * @returns The created agent
21
+ */
22
+ async create(options) {
23
+ return this.client.request('POST', '/agents', {
24
+ body: {
25
+ name: options.name,
26
+ git_repo_url: options.gitRepoUrl,
27
+ slug: options.slug,
28
+ },
29
+ });
30
+ }
31
+ /**
32
+ * Get an agent by slug
33
+ * @param slug - The agent's unique slug
34
+ * @returns The agent
35
+ * @throws NotFoundError if agent doesn't exist
36
+ */
37
+ async get(slug) {
38
+ return this.client.request('GET', `/agents/${encodeURIComponent(slug)}`);
39
+ }
40
+ /**
41
+ * Delete an agent
42
+ * @param slug - The agent's unique slug
43
+ * @throws NotFoundError if agent doesn't exist
44
+ */
45
+ async delete(slug) {
46
+ return this.client.request('DELETE', `/agents/${encodeURIComponent(slug)}`);
47
+ }
48
+ /**
49
+ * Deploy an agent (create sandbox, clone repo, install deps)
50
+ * @param slug - The agent's unique slug
51
+ * @returns The updated agent with status 'active'
52
+ * @throws NotFoundError if agent doesn't exist
53
+ */
54
+ async deploy(slug) {
55
+ return this.client.request('POST', `/agents/${encodeURIComponent(slug)}/deploy`, {
56
+ timeout: 120000, // 2 minutes for deployment
57
+ });
58
+ }
59
+ /**
60
+ * Stop a running agent
61
+ * @param slug - The agent's unique slug
62
+ * @returns The updated agent with status 'stopped'
63
+ * @throws NotFoundError if agent doesn't exist
64
+ */
65
+ async stop(slug) {
66
+ return this.client.request('POST', `/agents/${encodeURIComponent(slug)}/stop`);
67
+ }
68
+ /**
69
+ * Invoke an agent with a prompt
70
+ * @param slug - The agent's unique slug
71
+ * @param options - Invocation options including prompt
72
+ * @returns The invocation response with result and usage stats
73
+ * @throws NotFoundError if agent doesn't exist
74
+ * @throws BadRequestError if agent is not deployed
75
+ */
76
+ async invoke(slug, options) {
77
+ return this.client.request('POST', `/agents/${encodeURIComponent(slug)}/invoke`, {
78
+ body: { prompt: options.prompt },
79
+ timeout: 180000, // 3 minutes for invocation
80
+ });
81
+ }
82
+ /**
83
+ * List secret keys for an agent (values are never returned)
84
+ * @param slug - The agent's unique slug
85
+ * @returns Array of secret key names
86
+ */
87
+ async listSecrets(slug) {
88
+ const response = await this.client.request('GET', `/agents/${encodeURIComponent(slug)}/secrets`);
89
+ return response.secrets;
90
+ }
91
+ /**
92
+ * Set a secret for an agent
93
+ * @param slug - The agent's unique slug
94
+ * @param key - The secret key
95
+ * @param value - The secret value
96
+ */
97
+ async setSecret(slug, key, value) {
98
+ return this.client.request('POST', `/agents/${encodeURIComponent(slug)}/secrets`, {
99
+ body: { key, value },
100
+ });
101
+ }
102
+ /**
103
+ * Delete a secret from an agent
104
+ * @param slug - The agent's unique slug
105
+ * @param key - The secret key to delete
106
+ */
107
+ async deleteSecret(slug, key) {
108
+ return this.client.request('DELETE', `/agents/${encodeURIComponent(slug)}/secrets/${encodeURIComponent(key)}`);
109
+ }
110
+ }
111
+ //# sourceMappingURL=agents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents.js","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,MAAM,OAAO,SAAS;IACA;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAqB,KAAK,EAAE,SAAS,CAAC,CAAC;QACjF,OAAO,QAAQ,CAAC,MAAM,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,OAA2B;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAQ,MAAM,EAAE,SAAS,EAAE;YACnD,IAAI,EAAE;gBACJ,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,YAAY,EAAE,OAAO,CAAC,UAAU;gBAChC,IAAI,EAAE,OAAO,CAAC,IAAI;aACnB;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAQ,KAAK,EAAE,WAAW,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClF,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAO,QAAQ,EAAE,WAAW,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpF,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAQ,MAAM,EAAE,WAAW,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE;YACtF,OAAO,EAAE,MAAM,EAAE,2BAA2B;SAC7C,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAQ,MAAM,EAAE,WAAW,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxF,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,OAAsB;QAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,MAAM,EACN,WAAW,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAC5C;YACE,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;YAChC,OAAO,EAAE,MAAM,EAAE,2BAA2B;SAC7C,CACF,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,IAAY;QAC5B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAwB,KAAK,EAAE,WAAW,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxH,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,GAAW,EAAE,KAAa;QACtD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAO,MAAM,EAAE,WAAW,kBAAkB,CAAC,IAAI,CAAC,UAAU,EAAE;YACtF,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;SACrB,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,IAAY,EAAE,GAAW;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,QAAQ,EACR,WAAW,kBAAkB,CAAC,IAAI,CAAC,YAAY,kBAAkB,CAAC,GAAG,CAAC,EAAE,CACzE,CAAC;IACJ,CAAC;CACF"}
package/dist/auth.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { HttpClient } from './http.js';
2
+ import type { User, ApiKeyResponse } from './types.js';
3
+ /**
4
+ * API for authentication operations
5
+ */
6
+ export declare class AuthAPI {
7
+ private client;
8
+ constructor(client: HttpClient);
9
+ /**
10
+ * Get the currently authenticated user
11
+ * @returns The authenticated user
12
+ * @throws AuthenticationError if not authenticated
13
+ */
14
+ me(): Promise<User>;
15
+ /**
16
+ * Create a new API key for the authenticated user
17
+ * @returns The new API key (only shown once)
18
+ * @throws BadRequestError if user already has an API key
19
+ */
20
+ createApiKey(): Promise<ApiKeyResponse>;
21
+ /**
22
+ * Revoke the user's API key
23
+ * @throws BadRequestError if user has no API key
24
+ */
25
+ revokeApiKey(): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEvD;;GAEG;AACH,qBAAa,OAAO;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;;;OAIG;IACG,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,cAAc,CAAC;IAI7C;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
package/dist/auth.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * API for authentication operations
3
+ */
4
+ export class AuthAPI {
5
+ client;
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ /**
10
+ * Get the currently authenticated user
11
+ * @returns The authenticated user
12
+ * @throws AuthenticationError if not authenticated
13
+ */
14
+ async me() {
15
+ return this.client.request('GET', '/auth/me');
16
+ }
17
+ /**
18
+ * Create a new API key for the authenticated user
19
+ * @returns The new API key (only shown once)
20
+ * @throws BadRequestError if user already has an API key
21
+ */
22
+ async createApiKey() {
23
+ return this.client.request('POST', '/auth/api-key');
24
+ }
25
+ /**
26
+ * Revoke the user's API key
27
+ * @throws BadRequestError if user has no API key
28
+ */
29
+ async revokeApiKey() {
30
+ return this.client.request('DELETE', '/auth/api-key');
31
+ }
32
+ }
33
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,OAAO;IACE;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C;;;;OAIG;IACH,KAAK,CAAC,EAAE;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAO,KAAK,EAAE,UAAU,CAAC,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAiB,MAAM,EAAE,eAAe,CAAC,CAAC;IACtE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAO,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC9D,CAAC;CACF"}
package/dist/client.d.ts CHANGED
@@ -1,50 +1,56 @@
1
- import type { QueryConfig, WSInputMessage, WSOutputMessage } from './types';
2
- export * from './types';
1
+ import { AgentsAPI } from './agents.js';
2
+ import { UsageAPI } from './usage.js';
3
+ import { AuthAPI } from './auth.js';
4
+ import type { CastariClientOptions } from './types.js';
3
5
  /**
4
- * Configuration options for the Castari Client.
6
+ * Main client for interacting with the Castari API
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { CastariClient } from '@castari/sdk';
11
+ *
12
+ * // Uses credentials from ~/.castari or CASTARI_API_KEY env var
13
+ * const client = new CastariClient();
14
+ *
15
+ * // Or provide credentials explicitly
16
+ * const client = new CastariClient({ apiKey: 'cap_xxxxx' });
17
+ *
18
+ * // List agents
19
+ * const agents = await client.agents.list();
20
+ *
21
+ * // Deploy an agent
22
+ * await client.agents.deploy('my-agent');
23
+ *
24
+ * // Invoke an agent
25
+ * const result = await client.agents.invoke('my-agent', { prompt: 'Hello!' });
26
+ * ```
5
27
  */
6
- export interface ClientOptions extends Partial<QueryConfig> {
7
- /** Local/custom connection URL (e.g., 'http://localhost:3000'). If omitted, Platform mode is used. */
8
- connectionUrl?: string;
9
- /** Anthropic API key (required unless present in process.env.ANTHROPIC_API_KEY) */
10
- anthropicApiKey?: string;
11
- /** Castari client ID (required for platform mode; otherwise read from env) */
12
- clientId?: string;
13
- /** Castari platform API key (used for auth when contacting the platform) */
14
- platformApiKey?: string;
15
- /** Enable debug logging */
16
- debug?: boolean;
17
- /** Snapshot name to deploy/start */
18
- snapshot?: string;
19
- /** Optional labels to apply to the sandbox (and filter by for reuse) */
20
- labels?: Record<string, string>;
21
- /** Optional volume name to mount at /home/castari/agent-workspace */
22
- volume?: string;
23
- /** Castari Platform API URL. Defaults to https://api.castari.com (or localhost in dev) */
24
- platformUrl?: string;
25
- /** Optional sessionId to resume */
26
- resume?: string;
27
- /**
28
- * Use the platform API as a WebSocket proxy instead of connecting directly to the sandbox.
29
- * Defaults to true for reliability. Set to false to connect directly to the sandbox.
30
- */
31
- useProxy?: boolean;
32
- }
33
28
  export declare class CastariClient {
34
- private ws?;
35
29
  private options;
36
- private messageHandlers;
37
- private sandboxId?;
38
- private resolvedClientId?;
39
- private resolvedPlatformApiKey?;
40
- constructor(options?: ClientOptions);
41
- start(): Promise<void>;
42
- private setupLocalConnection;
43
- private setupPlatformConnection;
44
- private handleMessage;
45
- onMessage(handler: (message: WSOutputMessage) => void): () => void;
46
- send(message: WSInputMessage): void;
47
- stop(options?: {
48
- delete?: boolean;
49
- }): Promise<void>;
30
+ private httpClient;
31
+ private initialized;
32
+ private initPromise;
33
+ /** API for managing agents */
34
+ readonly agents: AgentsAPI;
35
+ /** API for accessing usage statistics */
36
+ readonly usage: UsageAPI;
37
+ /** API for authentication operations */
38
+ readonly auth: AuthAPI;
39
+ /**
40
+ * Create a new Castari client
41
+ * @param options - Client configuration options
42
+ */
43
+ constructor(options?: CastariClientOptions);
44
+ /**
45
+ * Initialize the client by loading credentials from config
46
+ * This is called automatically before the first API request
47
+ */
48
+ private initialize;
49
+ private doInitialize;
50
+ /**
51
+ * Ensure the client is initialized before making requests
52
+ * @throws AuthenticationError if no credentials are available
53
+ */
54
+ ensureAuthenticated(): Promise<void>;
50
55
  }
56
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAa;IAkBZ,OAAO,CAAC,OAAO;IAjB3B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAA8B;IAEjD,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAE3B,yCAAyC;IACzC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAEzB,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB;;;OAGG;gBACiB,OAAO,GAAE,oBAAyB;IAqBtD;;;OAGG;YACW,UAAU;YAaV,YAAY;IAY1B;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ3C"}