@castari/sdk 0.0.4 → 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 +9 -1
- package/dist/client.js +30 -5
- package/dist/const.js +1 -1
- package/dist/server.js +6 -0
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -8,22 +8,30 @@ 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;
|
|
25
|
+
/** Optional sessionId to resume */
|
|
26
|
+
resume?: string;
|
|
21
27
|
}
|
|
22
28
|
export declare class CastariClient {
|
|
23
29
|
private ws?;
|
|
24
30
|
private options;
|
|
25
31
|
private messageHandlers;
|
|
26
32
|
private sandboxId?;
|
|
33
|
+
private resolvedClientId?;
|
|
34
|
+
private resolvedPlatformApiKey?;
|
|
27
35
|
constructor(options?: ClientOptions);
|
|
28
36
|
start(): Promise<void>;
|
|
29
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();
|
|
@@ -27,7 +33,11 @@ export class CastariClient {
|
|
|
27
33
|
allowedTools: this.options.allowedTools,
|
|
28
34
|
systemPrompt: this.options.systemPrompt,
|
|
29
35
|
model: this.options.model,
|
|
36
|
+
resume: this.options.resume,
|
|
30
37
|
};
|
|
38
|
+
if (this.options.debug) {
|
|
39
|
+
console.log(`📋 Config payload:`, JSON.stringify(configPayload, null, 2));
|
|
40
|
+
}
|
|
31
41
|
const configHeaders = {
|
|
32
42
|
'Content-Type': 'application/json',
|
|
33
43
|
};
|
|
@@ -35,7 +45,7 @@ export class CastariClient {
|
|
|
35
45
|
configHeaders['x-daytona-preview-token'] = connection.previewToken;
|
|
36
46
|
}
|
|
37
47
|
let configResponse = null;
|
|
38
|
-
const maxConfigAttempts =
|
|
48
|
+
const maxConfigAttempts = 5;
|
|
39
49
|
for (let attempt = 1; attempt <= maxConfigAttempts; attempt++) {
|
|
40
50
|
configResponse = await fetch(connection.configUrl, {
|
|
41
51
|
method: 'POST',
|
|
@@ -112,17 +122,26 @@ export class CastariClient {
|
|
|
112
122
|
};
|
|
113
123
|
}
|
|
114
124
|
async setupPlatformConnection() {
|
|
125
|
+
if (!this.resolvedClientId) {
|
|
126
|
+
throw new Error('CASTARI_CLIENT_ID is required when connecting via the Castari Platform');
|
|
127
|
+
}
|
|
115
128
|
const platformUrl = this.options.platformUrl || process.env.CASTARI_PLATFORM_URL || 'http://localhost:3000';
|
|
116
129
|
if (this.options.debug) {
|
|
117
130
|
console.log(`🚀 Requesting sandbox from ${platformUrl}...`);
|
|
118
131
|
}
|
|
119
132
|
const response = await fetch(`${platformUrl}/sandbox/start`, {
|
|
120
133
|
method: 'POST',
|
|
121
|
-
headers: {
|
|
134
|
+
headers: {
|
|
135
|
+
'Content-Type': 'application/json',
|
|
136
|
+
...(this.resolvedPlatformApiKey
|
|
137
|
+
? { Authorization: `Bearer ${this.resolvedPlatformApiKey}` }
|
|
138
|
+
: {}),
|
|
139
|
+
},
|
|
122
140
|
body: JSON.stringify({
|
|
123
141
|
snapshot: this.options.snapshot,
|
|
124
142
|
labels: this.options.labels,
|
|
125
|
-
volume: this.options.volume
|
|
143
|
+
volume: this.options.volume,
|
|
144
|
+
clientId: this.resolvedClientId
|
|
126
145
|
})
|
|
127
146
|
});
|
|
128
147
|
if (!response.ok) {
|
|
@@ -171,12 +190,18 @@ export class CastariClient {
|
|
|
171
190
|
if (this.sandboxId) {
|
|
172
191
|
const platformUrl = this.options.platformUrl || process.env.CASTARI_PLATFORM_URL || 'http://localhost:3000';
|
|
173
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;
|
|
174
195
|
const response = await fetch(`${platformUrl}/sandbox/stop`, {
|
|
175
196
|
method: 'POST',
|
|
176
|
-
headers: {
|
|
197
|
+
headers: {
|
|
198
|
+
'Content-Type': 'application/json',
|
|
199
|
+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
200
|
+
},
|
|
177
201
|
body: JSON.stringify({
|
|
178
202
|
sandboxId: this.sandboxId,
|
|
179
|
-
delete: options.delete
|
|
203
|
+
delete: options.delete,
|
|
204
|
+
clientId
|
|
180
205
|
})
|
|
181
206
|
});
|
|
182
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/dist/server.js
CHANGED
|
@@ -115,6 +115,12 @@ async function processMessages(initialOptions) {
|
|
|
115
115
|
...options,
|
|
116
116
|
prompt: '[generator]', // avoid logging generator internals
|
|
117
117
|
});
|
|
118
|
+
if (options.resume) {
|
|
119
|
+
console.info(`📋 Resuming session: ${options.resume}`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
console.info('📋 Starting new session');
|
|
123
|
+
}
|
|
118
124
|
activeStream = query({
|
|
119
125
|
prompt: generateMessages(),
|
|
120
126
|
options,
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED