@castari/sdk 0.0.5 → 0.0.6
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/client.d.ts +7 -1
- package/dist/client.js +26 -5
- package/dist/const.js +1 -1
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -8,13 +8,17 @@ export interface ClientOptions extends Partial<QueryConfig> {
|
|
|
8
8
|
connectionUrl?: string;
|
|
9
9
|
/** Anthropic API key (required unless present in process.env.ANTHROPIC_API_KEY) */
|
|
10
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;
|
|
11
15
|
/** Enable debug logging */
|
|
12
16
|
debug?: boolean;
|
|
13
17
|
/** Snapshot name to deploy/start */
|
|
14
18
|
snapshot?: string;
|
|
15
19
|
/** Optional labels to apply to the sandbox (and filter by for reuse) */
|
|
16
20
|
labels?: Record<string, string>;
|
|
17
|
-
/** Optional volume name to mount at /home/
|
|
21
|
+
/** Optional volume name to mount at /home/castari/agent-workspace */
|
|
18
22
|
volume?: string;
|
|
19
23
|
/** Castari Platform API URL. Defaults to https://api.castari.com (or localhost in dev) */
|
|
20
24
|
platformUrl?: string;
|
|
@@ -26,6 +30,8 @@ export declare class CastariClient {
|
|
|
26
30
|
private options;
|
|
27
31
|
private messageHandlers;
|
|
28
32
|
private sandboxId?;
|
|
33
|
+
private resolvedClientId?;
|
|
34
|
+
private resolvedPlatformApiKey?;
|
|
29
35
|
constructor(options?: ClientOptions);
|
|
30
36
|
start(): Promise<void>;
|
|
31
37
|
private setupLocalConnection;
|
package/dist/client.js
CHANGED
|
@@ -5,6 +5,8 @@ export class CastariClient {
|
|
|
5
5
|
options;
|
|
6
6
|
messageHandlers = [];
|
|
7
7
|
sandboxId;
|
|
8
|
+
resolvedClientId;
|
|
9
|
+
resolvedPlatformApiKey;
|
|
8
10
|
constructor(options = {}) {
|
|
9
11
|
this.options = {
|
|
10
12
|
...options,
|
|
@@ -15,6 +17,10 @@ export class CastariClient {
|
|
|
15
17
|
if (!anthropicApiKey) {
|
|
16
18
|
throw new Error('ANTHROPIC_API_KEY is required');
|
|
17
19
|
}
|
|
20
|
+
this.resolvedClientId =
|
|
21
|
+
this.options.clientId || process.env.CASTARI_CLIENT_ID || undefined;
|
|
22
|
+
this.resolvedPlatformApiKey =
|
|
23
|
+
this.options.platformApiKey || process.env.CASTARI_API_KEY || undefined;
|
|
18
24
|
const connection = this.options.connectionUrl
|
|
19
25
|
? await this.setupLocalConnection()
|
|
20
26
|
: await this.setupPlatformConnection();
|
|
@@ -39,7 +45,7 @@ export class CastariClient {
|
|
|
39
45
|
configHeaders['x-daytona-preview-token'] = connection.previewToken;
|
|
40
46
|
}
|
|
41
47
|
let configResponse = null;
|
|
42
|
-
const maxConfigAttempts =
|
|
48
|
+
const maxConfigAttempts = 5;
|
|
43
49
|
for (let attempt = 1; attempt <= maxConfigAttempts; attempt++) {
|
|
44
50
|
configResponse = await fetch(connection.configUrl, {
|
|
45
51
|
method: 'POST',
|
|
@@ -116,17 +122,26 @@ export class CastariClient {
|
|
|
116
122
|
};
|
|
117
123
|
}
|
|
118
124
|
async setupPlatformConnection() {
|
|
125
|
+
if (!this.resolvedClientId) {
|
|
126
|
+
throw new Error('CASTARI_CLIENT_ID is required when connecting via the Castari Platform');
|
|
127
|
+
}
|
|
119
128
|
const platformUrl = this.options.platformUrl || process.env.CASTARI_PLATFORM_URL || 'http://localhost:3000';
|
|
120
129
|
if (this.options.debug) {
|
|
121
130
|
console.log(`🚀 Requesting sandbox from ${platformUrl}...`);
|
|
122
131
|
}
|
|
123
132
|
const response = await fetch(`${platformUrl}/sandbox/start`, {
|
|
124
133
|
method: 'POST',
|
|
125
|
-
headers: {
|
|
134
|
+
headers: {
|
|
135
|
+
'Content-Type': 'application/json',
|
|
136
|
+
...(this.resolvedPlatformApiKey
|
|
137
|
+
? { Authorization: `Bearer ${this.resolvedPlatformApiKey}` }
|
|
138
|
+
: {}),
|
|
139
|
+
},
|
|
126
140
|
body: JSON.stringify({
|
|
127
141
|
snapshot: this.options.snapshot,
|
|
128
142
|
labels: this.options.labels,
|
|
129
|
-
volume: this.options.volume
|
|
143
|
+
volume: this.options.volume,
|
|
144
|
+
clientId: this.resolvedClientId
|
|
130
145
|
})
|
|
131
146
|
});
|
|
132
147
|
if (!response.ok) {
|
|
@@ -175,12 +190,18 @@ export class CastariClient {
|
|
|
175
190
|
if (this.sandboxId) {
|
|
176
191
|
const platformUrl = this.options.platformUrl || process.env.CASTARI_PLATFORM_URL || 'http://localhost:3000';
|
|
177
192
|
try {
|
|
193
|
+
const clientId = this.resolvedClientId || this.options.clientId || process.env.CASTARI_CLIENT_ID;
|
|
194
|
+
const apiKey = this.resolvedPlatformApiKey || this.options.platformApiKey || process.env.CASTARI_API_KEY;
|
|
178
195
|
const response = await fetch(`${platformUrl}/sandbox/stop`, {
|
|
179
196
|
method: 'POST',
|
|
180
|
-
headers: {
|
|
197
|
+
headers: {
|
|
198
|
+
'Content-Type': 'application/json',
|
|
199
|
+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
200
|
+
},
|
|
181
201
|
body: JSON.stringify({
|
|
182
202
|
sandboxId: this.sandboxId,
|
|
183
|
-
delete: options.delete
|
|
203
|
+
delete: options.delete,
|
|
204
|
+
clientId
|
|
184
205
|
})
|
|
185
206
|
});
|
|
186
207
|
if (!response.ok) {
|
package/dist/const.js
CHANGED
|
@@ -6,4 +6,4 @@ export const SERVER_PORT = 3000;
|
|
|
6
6
|
// Workspace configuration
|
|
7
7
|
export const WORKSPACE_DIR_NAME = 'agent-workspace';
|
|
8
8
|
// Connection token (one-time) configuration
|
|
9
|
-
export const CONNECTION_TOKEN_TTL_MS = 5 * 60 *
|
|
9
|
+
export const CONNECTION_TOKEN_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
package/package.json
CHANGED