@castari/sdk 0.1.2 → 0.1.4

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 CHANGED
@@ -24,6 +24,11 @@ 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
+ * Defaults to true for reliability. Set to false to connect directly to the sandbox.
30
+ */
31
+ useProxy?: boolean;
27
32
  }
28
33
  export declare class CastariClient {
29
34
  private ws?;
package/dist/client.js CHANGED
@@ -150,11 +150,31 @@ 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
+ // Default to proxy mode (true) unless explicitly disabled
156
+ const useProxy = this.options.useProxy ?? (process.env.CASTARI_USE_PROXY !== 'false');
155
157
  if (this.options.debug) {
156
158
  console.log(`✅ Sandbox started: ${id} at ${url}`);
159
+ if (useProxy && proxyUrl) {
160
+ console.log(`🔀 Using proxy mode via ${proxyUrl}`);
161
+ }
162
+ }
163
+ // If proxy mode is enabled and we have a proxy URL, use it
164
+ if (useProxy && proxyUrl) {
165
+ // Proxy mode: connect through platform API
166
+ const proxyConfigUrl = `${platformUrl}/proxy/${id}/config`;
167
+ const proxyWsUrl = proxyUrl;
168
+ return {
169
+ configUrl: proxyConfigUrl,
170
+ wsUrl: proxyWsUrl,
171
+ // No auth headers/params needed - proxy handles sandbox auth
172
+ cleanup: async () => {
173
+ await this.stop({ delete: true });
174
+ }
175
+ };
157
176
  }
177
+ // Direct mode: connect to sandbox directly
158
178
  const baseUrl = url.replace(/\/$/, '');
159
179
  const configUrl = `${baseUrl.replace('ws://', 'http://').replace('wss://', 'https://')}/config`;
160
180
  const wsUrlBase = `${baseUrl.replace('https://', 'wss://').replace('http://', 'ws://')}/ws`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@castari/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",