@sampleapp.ai/sdk 1.0.31 → 1.0.33
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/components/ModalSearchAndChat.js +1 -1
- package/dist/components/sandbox/Sandbox.js +6 -0
- package/dist/components/sandbox/api.js +10 -6
- package/dist/components/sandbox/guardian/context/vm-context.js +10 -1
- package/dist/components/sandbox/guardian/demo/guardian-demo.js +4 -4
- package/dist/components/sandbox/guardian/demo/left-view.js +2 -2
- package/dist/components/sandbox/guardian/guardian-component.js +44 -26
- package/dist/components/sandbox/guardian/hooks/use-sandbox-url-loader.js +57 -18
- package/dist/components/sandbox/guardian/ide/browser.js +28 -4
- package/dist/components/sandbox/guardian/right-view/right-panel-view.js +9 -4
- package/dist/components/sandbox/guardian/right-view/right-top-down-view.js +111 -38
- package/dist/components/sandbox/guardian/right-view/right-view.js +3 -3
- package/dist/components/sandbox/guardian/ui/download-and-open-buttons.js +13 -43
- package/dist/components/sandbox/guardian/ui/markdown.js +4 -2
- package/dist/components/sandbox/guardian/ui/theme-color-context.d.ts +6 -0
- package/dist/components/sandbox/guardian/utils.js +30 -1
- package/dist/index.d.ts +456 -32
- package/dist/index.es.js +18814 -18583
- package/dist/lib/api-client.js +128 -14
- package/package.json +1 -1
package/dist/lib/api-client.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SDK API Client for interacting with the SampleApp backend API
|
|
3
|
+
*
|
|
4
|
+
* Authentication: API keys are sent via Bearer token in the Authorization header.
|
|
5
|
+
* Set the apiKey in ApiClientConfig when creating the client.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const client = createApiClient({
|
|
10
|
+
* apiKey: "your-api-key-here"
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* // API key is automatically sent as "Authorization: Bearer your-api-key-here"
|
|
14
|
+
* const response = await client.sdk.startSandbox({
|
|
15
|
+
* env: { KEY: "value" }, // required when published_url is not available
|
|
16
|
+
* chatUid: "chat-uid"
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
3
19
|
*/
|
|
4
20
|
/**
|
|
5
21
|
* Extract container ID from a browser URL
|
|
@@ -66,31 +82,110 @@ class ApiClient {
|
|
|
66
82
|
this.sdk = {
|
|
67
83
|
/**
|
|
68
84
|
* Start a sandbox
|
|
69
|
-
*
|
|
85
|
+
*
|
|
86
|
+
* Authentication: API key is sent as Bearer token in Authorization header.
|
|
87
|
+
* The apiKey must be set in ApiClientConfig when creating the client.
|
|
88
|
+
*
|
|
89
|
+
* @param request - The start sandbox request (env and chatUid)
|
|
70
90
|
* @returns The sandbox response with container URL
|
|
91
|
+
* @throws Error if apiKey is not set in client config
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const client = createApiClient({ apiKey: "your-api-key" });
|
|
96
|
+
* const response = await client.sdk.startSandbox({
|
|
97
|
+
* env: { ENV_VAR: "value" }, // required when published_url is not available
|
|
98
|
+
* chatUid: "chat-uid-123"
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
71
101
|
*/
|
|
72
102
|
startSandbox: async (request) => {
|
|
103
|
+
if (!this.apiKey) {
|
|
104
|
+
throw new Error("API key is required. Set apiKey in ApiClientConfig when creating the client.");
|
|
105
|
+
}
|
|
73
106
|
return this.request(["sdk", "start-sandbox"], {
|
|
74
107
|
method: "POST",
|
|
75
108
|
body: JSON.stringify(request),
|
|
76
109
|
});
|
|
77
110
|
},
|
|
78
111
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
112
|
+
* Download code as zip file from GitHub repository
|
|
113
|
+
*
|
|
114
|
+
* Authentication: API key is sent as Bearer token in Authorization header.
|
|
115
|
+
* The apiKey must be set in ApiClientConfig when creating the client.
|
|
116
|
+
*
|
|
117
|
+
* @param sandboxId - The sandbox content UID
|
|
118
|
+
* @returns Promise that resolves when download is initiated
|
|
119
|
+
* @throws Error if apiKey is not set in client config
|
|
82
120
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
121
|
+
downloadCode: async (sandboxId) => {
|
|
122
|
+
if (!this.apiKey) {
|
|
123
|
+
throw new Error("API key is required. Set apiKey in ApiClientConfig when creating the client.");
|
|
124
|
+
}
|
|
125
|
+
const url = `${this.baseUrl}/api/v1/sdk/download-code?sandbox_id=${encodeURIComponent(sandboxId)}`;
|
|
126
|
+
// Make authenticated fetch request with Authorization header
|
|
127
|
+
const response = await fetch(url, {
|
|
128
|
+
method: "GET",
|
|
129
|
+
headers: {
|
|
130
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
if (!response.ok) {
|
|
134
|
+
const errorText = await response.text();
|
|
135
|
+
throw new Error(`Download failed: ${response.status} ${response.statusText}. ${errorText}`);
|
|
136
|
+
}
|
|
137
|
+
// Get the blob from the response
|
|
138
|
+
const blob = await response.blob();
|
|
139
|
+
// Create a download link and trigger it
|
|
140
|
+
const downloadUrl = window.URL.createObjectURL(blob);
|
|
141
|
+
const link = document.createElement("a");
|
|
142
|
+
link.href = downloadUrl;
|
|
143
|
+
link.download = `sandbox-${sandboxId}.zip`;
|
|
144
|
+
document.body.appendChild(link);
|
|
145
|
+
link.click();
|
|
146
|
+
document.body.removeChild(link);
|
|
147
|
+
window.URL.revokeObjectURL(downloadUrl);
|
|
85
148
|
},
|
|
86
149
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
150
|
+
* Start VM endpoint that starts a desktop sandbox, launches Chrome,
|
|
151
|
+
* navigates to the target URL, and returns a VNC viewer URL
|
|
152
|
+
*
|
|
153
|
+
* Authentication: API key is sent as Bearer token in Authorization header.
|
|
154
|
+
* The apiKey must be set in ApiClientConfig when creating the client.
|
|
155
|
+
*
|
|
156
|
+
* @param request - The start VM request with url, optional mode, and optional resolution
|
|
157
|
+
* @returns The sandbox response with sandboxId and vncUrl (if mode=json)
|
|
158
|
+
* @throws Error if apiKey is not set in client config
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const client = createApiClient({ apiKey: "your-api-key" });
|
|
163
|
+
* const response = await client.sdk.startVm({
|
|
164
|
+
* url: "https://example.com",
|
|
165
|
+
* mode: "json",
|
|
166
|
+
* resolution: [1920, 1080]
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
90
169
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
170
|
+
startVm: async (request) => {
|
|
171
|
+
if (!this.apiKey) {
|
|
172
|
+
throw new Error("API key is required. Set apiKey in ApiClientConfig when creating the client.");
|
|
173
|
+
}
|
|
174
|
+
const queryParams = {
|
|
175
|
+
url: request.url,
|
|
176
|
+
mode: request.mode || "json",
|
|
177
|
+
};
|
|
178
|
+
// Add resolution if provided
|
|
179
|
+
if (request.resolution &&
|
|
180
|
+
Array.isArray(request.resolution) &&
|
|
181
|
+
request.resolution.length >= 2) {
|
|
182
|
+
queryParams.width = request.resolution[0];
|
|
183
|
+
queryParams.height = request.resolution[1];
|
|
184
|
+
}
|
|
185
|
+
return this.request(["sdk", "start-vm"], {
|
|
186
|
+
method: "GET",
|
|
187
|
+
}, false, // API key is sent as Bearer token in Authorization header
|
|
188
|
+
queryParams);
|
|
94
189
|
},
|
|
95
190
|
};
|
|
96
191
|
const defaultBaseUrl = getBaseUrl();
|
|
@@ -99,15 +194,22 @@ class ApiClient {
|
|
|
99
194
|
}
|
|
100
195
|
/**
|
|
101
196
|
* Makes a request to the API
|
|
197
|
+
* Automatically includes Authorization: Bearer {apiKey} header if apiKey is set in config
|
|
102
198
|
*/
|
|
103
199
|
async request(endpoint, options = {}, useApiKeyHeader = false, queryParams) {
|
|
104
200
|
let url = `${this.baseUrl}/api/v1/${endpoint.join("/")}`;
|
|
105
201
|
if (queryParams) {
|
|
106
202
|
const params = new URLSearchParams();
|
|
107
203
|
Object.entries(queryParams).forEach(([key, value]) => {
|
|
108
|
-
|
|
204
|
+
// Skip undefined/null values
|
|
205
|
+
if (value !== undefined && value !== null) {
|
|
206
|
+
params.append(key, value.toString());
|
|
207
|
+
}
|
|
109
208
|
});
|
|
110
|
-
|
|
209
|
+
const queryString = params.toString();
|
|
210
|
+
if (queryString) {
|
|
211
|
+
url += `?${queryString}`;
|
|
212
|
+
}
|
|
111
213
|
}
|
|
112
214
|
const headers = Object.assign({ "Content-Type": "application/json" }, options.headers);
|
|
113
215
|
if (this.apiKey) {
|
|
@@ -128,8 +230,20 @@ class ApiClient {
|
|
|
128
230
|
}
|
|
129
231
|
/**
|
|
130
232
|
* Create an API client instance
|
|
233
|
+
*
|
|
131
234
|
* @param config - Configuration for the API client
|
|
235
|
+
* @param config.apiKey - API key for authentication (sent as Bearer token in Authorization header)
|
|
132
236
|
* @returns An API client instance
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* // Create client with API key
|
|
241
|
+
* const client = createApiClient({
|
|
242
|
+
* apiKey: process.env.NEXT_PUBLIC_SAMPLEAPP_API_KEY
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* // All requests will automatically include: Authorization: Bearer {apiKey}
|
|
246
|
+
* ```
|
|
133
247
|
*/
|
|
134
248
|
export function createApiClient(config) {
|
|
135
249
|
return new ApiClient(config);
|