@castari/sdk 0.1.1 → 0.1.3
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 +9 -4
- package/dist/client.d.ts +6 -0
- package/dist/client.js +22 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,7 +77,9 @@ import { CastariClient } from '@castari/sdk/client'
|
|
|
77
77
|
|
|
78
78
|
const client = new CastariClient({
|
|
79
79
|
snapshot: 'my-agent',
|
|
80
|
-
|
|
80
|
+
clientId: process.env.CASTARI_CLIENT_ID,
|
|
81
|
+
platformApiKey: process.env.CASTARI_API_KEY,
|
|
82
|
+
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
|
|
81
83
|
})
|
|
82
84
|
|
|
83
85
|
await client.start()
|
|
@@ -99,11 +101,14 @@ await client.stop()
|
|
|
99
101
|
|
|
100
102
|
| Property | Type | Description |
|
|
101
103
|
|----------|------|-------------|
|
|
102
|
-
| `platformUrl` | `string` | URL of the Castari Platform |
|
|
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 |
|
|
104
108
|
| `volume` | `string` | (Optional) Volume name for persistent storage |
|
|
105
|
-
| `connectionUrl` | `string` | (Optional) Direct URL for local development |
|
|
106
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) |
|
|
107
112
|
|
|
108
113
|
#### Methods
|
|
109
114
|
|
|
@@ -139,8 +144,8 @@ await client.stop({ delete: false })
|
|
|
139
144
|
| Variable | Description |
|
|
140
145
|
|----------|-------------|
|
|
141
146
|
| `ANTHROPIC_API_KEY` | Your Anthropic API key |
|
|
142
|
-
| `CASTARI_PLATFORM_URL` | URL of the Castari Platform |
|
|
143
147
|
| `CASTARI_CLIENT_ID` | Your Castari client ID |
|
|
148
|
+
| `CASTARI_API_KEY` | Your Castari API key |
|
|
144
149
|
|
|
145
150
|
## License
|
|
146
151
|
|
package/dist/client.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export interface ClientOptions extends Partial<QueryConfig> {
|
|
|
24
24
|
platformUrl?: string;
|
|
25
25
|
/** Optional sessionId to resume */
|
|
26
26
|
resume?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Use the platform API as a WebSocket proxy instead of connecting directly to the sandbox.
|
|
29
|
+
* Useful when your network blocks the sandbox preview domains.
|
|
30
|
+
* Defaults to false.
|
|
31
|
+
*/
|
|
32
|
+
useProxy?: boolean;
|
|
27
33
|
}
|
|
28
34
|
export declare class CastariClient {
|
|
29
35
|
private ws?;
|
package/dist/client.js
CHANGED
|
@@ -127,7 +127,7 @@ export class CastariClient {
|
|
|
127
127
|
if (!this.resolvedClientId) {
|
|
128
128
|
throw new Error('CASTARI_CLIENT_ID is required when connecting via the Castari Platform');
|
|
129
129
|
}
|
|
130
|
-
const platformUrl = this.options.platformUrl || process.env.CASTARI_PLATFORM_URL || DEFAULT_PLATFORM_URL;
|
|
130
|
+
const platformUrl = (this.options.platformUrl || process.env.CASTARI_PLATFORM_URL || DEFAULT_PLATFORM_URL).replace(/\/$/, '');
|
|
131
131
|
if (this.options.debug) {
|
|
132
132
|
console.log(`🚀 Requesting sandbox from ${platformUrl}...`);
|
|
133
133
|
}
|
|
@@ -150,11 +150,30 @@ export class CastariClient {
|
|
|
150
150
|
const errorText = await response.text();
|
|
151
151
|
throw new Error(`Failed to start sandbox: ${errorText}`);
|
|
152
152
|
}
|
|
153
|
-
const { id, url, authHeaders, authParams } = await response.json();
|
|
153
|
+
const { id, url, proxyUrl, authHeaders, authParams } = await response.json();
|
|
154
154
|
this.sandboxId = id;
|
|
155
|
+
const useProxy = this.options.useProxy ?? (process.env.CASTARI_USE_PROXY === 'true');
|
|
155
156
|
if (this.options.debug) {
|
|
156
157
|
console.log(`✅ Sandbox started: ${id} at ${url}`);
|
|
158
|
+
if (useProxy && proxyUrl) {
|
|
159
|
+
console.log(`🔀 Using proxy mode via ${proxyUrl}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// If proxy mode is enabled and we have a proxy URL, use it
|
|
163
|
+
if (useProxy && proxyUrl) {
|
|
164
|
+
// Proxy mode: connect through platform API
|
|
165
|
+
const proxyConfigUrl = `${platformUrl}/proxy/${id}/config`;
|
|
166
|
+
const proxyWsUrl = proxyUrl;
|
|
167
|
+
return {
|
|
168
|
+
configUrl: proxyConfigUrl,
|
|
169
|
+
wsUrl: proxyWsUrl,
|
|
170
|
+
// No auth headers/params needed - proxy handles sandbox auth
|
|
171
|
+
cleanup: async () => {
|
|
172
|
+
await this.stop({ delete: true });
|
|
173
|
+
}
|
|
174
|
+
};
|
|
157
175
|
}
|
|
176
|
+
// Direct mode: connect to sandbox directly
|
|
158
177
|
const baseUrl = url.replace(/\/$/, '');
|
|
159
178
|
const configUrl = `${baseUrl.replace('ws://', 'http://').replace('wss://', 'https://')}/config`;
|
|
160
179
|
const wsUrlBase = `${baseUrl.replace('https://', 'wss://').replace('http://', 'ws://')}/ws`;
|
|
@@ -191,7 +210,7 @@ export class CastariClient {
|
|
|
191
210
|
this.ws.close();
|
|
192
211
|
}
|
|
193
212
|
if (this.sandboxId) {
|
|
194
|
-
const platformUrl = this.options.platformUrl || process.env.CASTARI_PLATFORM_URL || DEFAULT_PLATFORM_URL;
|
|
213
|
+
const platformUrl = (this.options.platformUrl || process.env.CASTARI_PLATFORM_URL || DEFAULT_PLATFORM_URL).replace(/\/$/, '');
|
|
195
214
|
try {
|
|
196
215
|
const clientId = this.resolvedClientId || this.options.clientId || process.env.CASTARI_CLIENT_ID;
|
|
197
216
|
const apiKey = this.resolvedPlatformApiKey || this.options.platformApiKey || process.env.CASTARI_API_KEY;
|