@kibotos/sdk 0.1.0 → 0.2.0

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/index.cjs CHANGED
@@ -139,7 +139,7 @@ function createAPIError(status, headers, body, fallbackMessage) {
139
139
  var DEFAULT_BASE_URL = "https://api.kibo.to/v1";
140
140
  var DEFAULT_MAX_RETRIES = 3;
141
141
  var DEFAULT_TIMEOUT_MS = 3e4;
142
- var SDK_VERSION = "0.1.0";
142
+ var SDK_VERSION = "0.2.0";
143
143
  var INITIAL_RETRY_DELAY_MS = 500;
144
144
  var MAX_RETRY_DELAY_MS = 8e3;
145
145
  var RETRYABLE_HTTP_STATUSES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
@@ -244,6 +244,21 @@ function combineSignals(userSignal, timeoutMs) {
244
244
  }
245
245
  };
246
246
  }
247
+ function combineResponseSignals(userSignal, timeoutMs) {
248
+ const hasTimeout = Number.isFinite(timeoutMs) && timeoutMs > 0;
249
+ if (userSignal && hasTimeout && typeof AbortSignal.any !== "function") {
250
+ const combined = combineSignals(userSignal, timeoutMs);
251
+ combined.signal?.addEventListener("abort", combined.cleanup, { once: true });
252
+ return combined;
253
+ }
254
+ const timeoutSignal = hasTimeout ? AbortSignal.timeout(timeoutMs) : void 0;
255
+ return {
256
+ signal: userSignal && timeoutSignal ? AbortSignal.any([userSignal, timeoutSignal]) : userSignal ?? timeoutSignal,
257
+ isTimeout: () => timeoutSignal?.aborted === true,
258
+ cleanup: () => {
259
+ }
260
+ };
261
+ }
247
262
  function sleep(ms, signal) {
248
263
  if (signal?.aborted) {
249
264
  return Promise.reject(createAbortError(signal));
@@ -301,31 +316,43 @@ var HttpClient = class {
301
316
  }
302
317
  return url.toString();
303
318
  }
304
- async request(config) {
305
- const { method, path, query, body, opts, disableWaitTimeoutRetry } = config;
306
- const url = this.buildUrl(path, query);
307
- const effectiveTimeoutMs = opts?.timeoutMs ?? this.timeoutMs;
308
- const userSignal = opts?.signal;
319
+ buildHeaders(overrides) {
309
320
  const headers = new Headers();
310
- headers.set("Accept", "application/json");
311
- headers.set("User-Agent", `@kibotos/sdk/${SDK_VERSION}`);
312
321
  if (this.apiKey) {
313
322
  headers.set("Authorization", `Bearer ${this.apiKey}`);
314
323
  }
315
324
  for (const [k, v] of Object.entries(this.defaultHeaders)) {
316
325
  headers.set(k, v);
317
326
  }
318
- if (opts?.headers) {
319
- for (const [k, v] of Object.entries(opts.headers)) {
320
- headers.set(k, v);
321
- }
327
+ for (const [k, v] of Object.entries(overrides ?? {})) {
328
+ headers.set(k, v);
329
+ }
330
+ return headers;
331
+ }
332
+ async request(config) {
333
+ return await this.perform(config, false);
334
+ }
335
+ requestResponse(config) {
336
+ return this.perform(config, true);
337
+ }
338
+ async perform(config, rawResponse) {
339
+ const { method, path, query, body, rawBody, opts, disableWaitTimeoutRetry } = config;
340
+ const url = this.buildUrl(path, query);
341
+ const effectiveTimeoutMs = opts?.timeoutMs ?? this.timeoutMs;
342
+ const userSignal = opts?.signal;
343
+ const maxRetries = config.nonReplayable ? 0 : this.maxRetries;
344
+ const headers = this.buildHeaders(opts?.headers);
345
+ headers.set("Accept", config.accept ?? headers.get("Accept") ?? "application/json");
346
+ if (!headers.has("User-Agent")) {
347
+ headers.set("User-Agent", `@kibotos/sdk/${SDK_VERSION}`);
322
348
  }
323
- const hasBody = body !== void 0;
324
- const serializedBody = hasBody ? JSON.stringify(body) : void 0;
325
- if (hasBody && !headers.has("Content-Type")) {
326
- headers.set("Content-Type", "application/json");
349
+ const requestBody = rawBody ?? (body === void 0 ? void 0 : JSON.stringify(body));
350
+ if (requestBody !== void 0 && !headers.has("Content-Type")) {
351
+ headers.set("Content-Type", rawBody === void 0 ? "application/json" : "application/octet-stream");
327
352
  }
328
- if (opts?.idempotencyKey) {
353
+ if (config.disableIdempotency) {
354
+ headers.delete("Idempotency-Key");
355
+ } else if (opts?.idempotencyKey) {
329
356
  headers.set("Idempotency-Key", opts.idempotencyKey);
330
357
  } else if (method === "POST" && !headers.has("Idempotency-Key")) {
331
358
  headers.set("Idempotency-Key", generateUuid());
@@ -335,15 +362,17 @@ var HttpClient = class {
335
362
  if (userSignal?.aborted) {
336
363
  throw createAbortError(userSignal);
337
364
  }
338
- const { signal, isTimeout, cleanup } = combineSignals(userSignal, effectiveTimeoutMs);
365
+ const { signal, isTimeout, cleanup } = rawResponse ? combineResponseSignals(userSignal, effectiveTimeoutMs) : combineSignals(userSignal, effectiveTimeoutMs);
339
366
  let response;
340
367
  try {
341
- response = await this.fetchImpl(url, {
368
+ const init = {
342
369
  method,
343
370
  headers,
344
- body: serializedBody,
371
+ body: requestBody,
345
372
  signal
346
- });
373
+ };
374
+ if (config.duplex) init.duplex = config.duplex;
375
+ response = await this.fetchImpl(url, init);
347
376
  } catch (err) {
348
377
  cleanup();
349
378
  if (userSignal?.aborted) {
@@ -353,7 +382,7 @@ var HttpClient = class {
353
382
  err instanceof Error && err.message ? `Network error: ${err.message}` : "Network error while contacting the Kibotos API",
354
383
  { cause: err }
355
384
  );
356
- if (attempt < this.maxRetries) {
385
+ if (attempt < maxRetries) {
357
386
  const delayMs = calculateBackoffMs(attempt);
358
387
  attempt += 1;
359
388
  await sleep(delayMs, userSignal);
@@ -361,6 +390,9 @@ var HttpClient = class {
361
390
  }
362
391
  throw connectionError;
363
392
  }
393
+ if (rawResponse && (response.ok || config.successStatuses?.includes(response.status))) {
394
+ return response;
395
+ }
364
396
  let parsedBody;
365
397
  try {
366
398
  const text = await response.text();
@@ -377,7 +409,7 @@ var HttpClient = class {
377
409
  throw createAbortError(userSignal);
378
410
  }
379
411
  const readError = isTimeout() ? new APIConnectionError(`Request timed out after ${effectiveTimeoutMs}ms`, { cause: err }) : new APIConnectionError("Failed to read response body from the Kibotos API", { cause: err });
380
- if (attempt < this.maxRetries) {
412
+ if (attempt < maxRetries) {
381
413
  const delayMs = calculateBackoffMs(attempt);
382
414
  attempt += 1;
383
415
  await sleep(delayMs, userSignal);
@@ -396,7 +428,7 @@ var HttpClient = class {
396
428
  parsedBody,
397
429
  response.statusText || void 0
398
430
  );
399
- if (this.shouldRetryAPIError(apiError, disableWaitTimeoutRetry) && attempt < this.maxRetries) {
431
+ if (this.shouldRetryAPIError(apiError, disableWaitTimeoutRetry) && attempt < maxRetries) {
400
432
  const retryAfterMs = apiError instanceof RateLimitError ? apiError.retryAfterMs : parseRetryAfterMs(response.headers.get("Retry-After"));
401
433
  const delayMs = calculateBackoffMs(attempt, retryAfterMs);
402
434
  attempt += 1;
@@ -771,7 +803,185 @@ var VolumesResource = class {
771
803
  }
772
804
  };
773
805
 
806
+ // src/sse.ts
807
+ var EXEC_EVENTS = /* @__PURE__ */ new Set([
808
+ "started",
809
+ "stdout",
810
+ "stderr",
811
+ "heartbeat",
812
+ "exited",
813
+ "error"
814
+ ]);
815
+ async function* parseExecEvents(response) {
816
+ if (!response.body) throw new Error("Kibotos exec stream has no response body");
817
+ const reader = response.body.getReader();
818
+ const decoder = new TextDecoder();
819
+ let pending = "";
820
+ let event = "";
821
+ let data = [];
822
+ let skipLF = false;
823
+ try {
824
+ while (true) {
825
+ const { value, done } = await reader.read();
826
+ const chunk = decoder.decode(value, { stream: !done });
827
+ if (chunk.length > 0) {
828
+ pending += skipLF && chunk.startsWith("\n") ? chunk.slice(1) : chunk;
829
+ skipLF = false;
830
+ }
831
+ let offset = 0;
832
+ const lineEnd = /\r\n|[\r\n]/g;
833
+ for (let match = lineEnd.exec(pending); match; match = lineEnd.exec(pending)) {
834
+ const line = pending.slice(offset, match.index);
835
+ offset = lineEnd.lastIndex;
836
+ skipLF = match[0] === "\r" && offset === pending.length;
837
+ if (line === "") {
838
+ const name = event;
839
+ const payload = data.join("\n");
840
+ const hasData = data.length > 0;
841
+ event = "";
842
+ data = [];
843
+ if (hasData && EXEC_EVENTS.has(name)) {
844
+ let decoded = payload;
845
+ try {
846
+ decoded = JSON.parse(payload);
847
+ } catch {
848
+ }
849
+ yield { event: name, data: decoded };
850
+ }
851
+ continue;
852
+ }
853
+ const colon = line.indexOf(":");
854
+ const field = colon === -1 ? line : line.slice(0, colon);
855
+ let fieldValue = colon === -1 ? "" : line.slice(colon + 1);
856
+ if (fieldValue.startsWith(" ")) fieldValue = fieldValue.slice(1);
857
+ if (field === "event") event = fieldValue;
858
+ if (field === "data") data.push(fieldValue);
859
+ }
860
+ pending = pending.slice(offset);
861
+ if (done) break;
862
+ }
863
+ } finally {
864
+ try {
865
+ await reader.cancel();
866
+ } catch {
867
+ } finally {
868
+ reader.releaseLock();
869
+ }
870
+ }
871
+ }
872
+
873
+ // src/websocket.ts
874
+ var FRAME_VERSION = 1;
875
+ var HEADER_BYTES = 6;
876
+ var WorkspaceChannel = {
877
+ stdin: 0,
878
+ stdout: 1,
879
+ stderr: 2,
880
+ pty: 3,
881
+ tunnel: 4
882
+ };
883
+ function encodeBinaryFrame(streamId, channel, payload) {
884
+ validateStreamId(streamId);
885
+ validateChannel(channel);
886
+ const frame = new Uint8Array(HEADER_BYTES + payload.byteLength);
887
+ const header = new DataView(frame.buffer);
888
+ header.setUint8(0, FRAME_VERSION);
889
+ header.setUint32(1, streamId, false);
890
+ header.setUint8(5, channel);
891
+ frame.set(payload, HEADER_BYTES);
892
+ return frame;
893
+ }
894
+ function decodeBinaryFrame(input) {
895
+ const bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
896
+ if (bytes.byteLength < HEADER_BYTES) throw new RangeError("Workspace frame is shorter than 6 bytes");
897
+ const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
898
+ if (header.getUint8(0) !== FRAME_VERSION) throw new RangeError("Unsupported workspace frame version");
899
+ const streamId = header.getUint32(1, false);
900
+ validateStreamId(streamId);
901
+ const channel = header.getUint8(5);
902
+ validateChannel(channel);
903
+ return {
904
+ stream_id: streamId,
905
+ channel,
906
+ payload: bytes.subarray(HEADER_BYTES)
907
+ };
908
+ }
909
+ function validateStreamId(streamId) {
910
+ if (!Number.isInteger(streamId) || streamId < 1 || streamId > 4294967295) {
911
+ throw new RangeError("stream_id must be a nonzero unsigned 32-bit integer");
912
+ }
913
+ }
914
+ function validateChannel(channel) {
915
+ if (!Number.isInteger(channel) || channel < 0 || channel > 4) {
916
+ throw new RangeError("Invalid workspace frame channel");
917
+ }
918
+ }
919
+ function decodeWorkspaceFrame(data) {
920
+ if (typeof data !== "string") return { type: "binary", frame: decodeBinaryFrame(data) };
921
+ const frame = JSON.parse(data);
922
+ if (!frame || typeof frame !== "object" || !("type" in frame) || typeof frame.type !== "string") {
923
+ throw new TypeError("Invalid workspace control frame");
924
+ }
925
+ return { type: "control", frame };
926
+ }
927
+ function webSocketUrl(url) {
928
+ const target = new URL(url);
929
+ if (target.protocol === "https:") target.protocol = "wss:";
930
+ if (target.protocol === "http:") target.protocol = "ws:";
931
+ if (target.protocol !== "ws:" && target.protocol !== "wss:") {
932
+ throw new TypeError("A WebSocket URL requires HTTP or HTTPS");
933
+ }
934
+ return target.toString();
935
+ }
936
+ function openWebSocket(url, headers, options) {
937
+ const handshake = { protocols: options?.protocols, headers: Object.fromEntries(headers) };
938
+ if (options?.factory) return options.factory(url, handshake);
939
+ const NativeWebSocket = globalThis.WebSocket;
940
+ if (typeof NativeWebSocket !== "function") {
941
+ throw new APIConnectionError("Global WebSocket is unavailable. Supply a WebSocket factory.");
942
+ }
943
+ if (Object.keys(handshake.headers).length === 0) {
944
+ return new NativeWebSocket(url, options?.protocols);
945
+ }
946
+ if (globalThis.process?.versions?.node) {
947
+ const NodeWebSocket = NativeWebSocket;
948
+ return new NodeWebSocket(url, handshake);
949
+ }
950
+ throw new APIConnectionError("This runtime requires a WebSocket factory to set handshake headers.");
951
+ }
952
+ var WorkspaceSocket = class {
953
+ constructor(socket) {
954
+ this.socket = socket;
955
+ socket.binaryType = "arraybuffer";
956
+ }
957
+ socket;
958
+ /** Subscribe to decoded frames. Returns an unsubscribe function. */
959
+ onFrame(listener) {
960
+ const onMessage = (event) => {
961
+ listener(decodeWorkspaceFrame(event.data));
962
+ };
963
+ this.socket.addEventListener("message", onMessage);
964
+ return () => this.socket.removeEventListener("message", onMessage);
965
+ }
966
+ sendControl(frame) {
967
+ this.socket.send(JSON.stringify(frame));
968
+ }
969
+ open(streamId, kind, params = {}) {
970
+ validateStreamId(streamId);
971
+ this.sendControl({ type: "open", stream_id: streamId, kind, params });
972
+ }
973
+ sendBinary(streamId, channel, payload) {
974
+ this.socket.send(encodeBinaryFrame(streamId, channel, payload));
975
+ }
976
+ close(code, reason) {
977
+ this.socket.close(code, reason);
978
+ }
979
+ };
980
+
774
981
  // src/resources/workspaces.ts
982
+ function workspacePath(id) {
983
+ return `/workspaces/${encodeURIComponent(id)}`;
984
+ }
775
985
  var WorkspacesResource = class {
776
986
  constructor(http) {
777
987
  this.http = http;
@@ -782,10 +992,15 @@ var WorkspacesResource = class {
782
992
  * `POST /v1/workspaces`
783
993
  */
784
994
  create(body, opts) {
995
+ const { noTimeout, ...rest } = body;
996
+ if (noTimeout && rest.timeout !== void 0) {
997
+ return Promise.reject(new TypeError("Cannot combine noTimeout with timeout"));
998
+ }
999
+ const payload = noTimeout ? { ...rest, timeout: { seconds: 0 } } : rest;
785
1000
  return this.http.request({
786
1001
  method: "POST",
787
1002
  path: "/workspaces",
788
- body,
1003
+ body: payload,
789
1004
  opts
790
1005
  });
791
1006
  }
@@ -834,7 +1049,7 @@ var WorkspacesResource = class {
834
1049
  });
835
1050
  }
836
1051
  /**
837
- * Updates workspace metadata (`name` and/or `labels`).
1052
+ * Updates workspace metadata and resizes eligible stopped or failed workspaces.
838
1053
  * `PATCH /v1/workspaces/{id}`
839
1054
  */
840
1055
  update(id, body, opts) {
@@ -861,10 +1076,18 @@ var WorkspacesResource = class {
861
1076
  * `POST /v1/workspaces/{id}/start`
862
1077
  */
863
1078
  start(id, body, opts) {
1079
+ let payload;
1080
+ if (body !== void 0) {
1081
+ const { noTimeout, ...rest } = body;
1082
+ if (noTimeout && rest.timeout !== void 0) {
1083
+ return Promise.reject(new TypeError("Cannot combine noTimeout with timeout"));
1084
+ }
1085
+ payload = noTimeout ? { ...rest, timeout: { seconds: 0 } } : rest;
1086
+ }
864
1087
  return this.http.request({
865
1088
  method: "POST",
866
1089
  path: `/workspaces/${encodeURIComponent(id)}/start`,
867
- body,
1090
+ body: payload,
868
1091
  opts
869
1092
  });
870
1093
  }
@@ -893,7 +1116,14 @@ var WorkspacesResource = class {
893
1116
  });
894
1117
  }
895
1118
  /**
896
- * Sets the network mode for a workspace.
1119
+ * Removes the auto-timeout policy so the workspace does not expire automatically.
1120
+ * `POST /v1/workspaces/{id}/timeout` with `{ seconds: 0 }`.
1121
+ */
1122
+ clearTimeout(id, opts) {
1123
+ return this.setTimeout(id, { seconds: 0 }, opts);
1124
+ }
1125
+ /**
1126
+ * Replaces the outbound network policy for a workspace.
897
1127
  * `PUT /v1/workspaces/{id}/network`
898
1128
  */
899
1129
  setNetwork(id, body, opts) {
@@ -904,6 +1134,161 @@ var WorkspacesResource = class {
904
1134
  opts
905
1135
  });
906
1136
  }
1137
+ setVolumes(id, body, opts) {
1138
+ return this.http.request({ method: "PUT", path: `${workspacePath(id)}/volumes`, body, opts });
1139
+ }
1140
+ setPacks(id, body, opts) {
1141
+ return this.http.request({ method: "PUT", path: `${workspacePath(id)}/packs`, body, opts });
1142
+ }
1143
+ getMetrics(id, params, opts) {
1144
+ return this.http.request({
1145
+ method: "GET",
1146
+ path: `${workspacePath(id)}/metrics`,
1147
+ query: buildQueryParams({
1148
+ start: params?.start instanceof Date ? params.start.toISOString() : params?.start,
1149
+ end: params?.end instanceof Date ? params.end.toISOString() : params?.end
1150
+ }),
1151
+ opts
1152
+ });
1153
+ }
1154
+ exec(id, body, opts) {
1155
+ return this.http.request({
1156
+ method: "POST",
1157
+ path: `${workspacePath(id)}/exec`,
1158
+ body,
1159
+ opts: { ...opts, timeoutMs: opts?.timeoutMs ?? ((body.timeout_seconds ?? 30) + 15) * 1e3 },
1160
+ accept: "application/json",
1161
+ nonReplayable: true,
1162
+ disableIdempotency: true
1163
+ });
1164
+ }
1165
+ async *execStream(id, body, opts) {
1166
+ const response = await this.http.requestResponse({
1167
+ method: "POST",
1168
+ path: `${workspacePath(id)}/exec`,
1169
+ body,
1170
+ opts: { ...opts, timeoutMs: opts?.timeoutMs ?? 0 },
1171
+ accept: "text/event-stream",
1172
+ nonReplayable: true,
1173
+ disableIdempotency: true
1174
+ });
1175
+ yield* parseExecEvents(response);
1176
+ }
1177
+ listFiles(id, path, opts) {
1178
+ return this.http.request({
1179
+ method: "GET",
1180
+ path: `${workspacePath(id)}/files`,
1181
+ query: buildQueryParams({ path, depth: opts?.depth, user: opts?.user }),
1182
+ opts
1183
+ });
1184
+ }
1185
+ statFile(id, path, opts) {
1186
+ return this.http.request({
1187
+ method: "GET",
1188
+ path: `${workspacePath(id)}/files/stat`,
1189
+ query: buildQueryParams({ path, user: opts?.user }),
1190
+ opts
1191
+ });
1192
+ }
1193
+ async readFile(id, path, opts) {
1194
+ const headers = new Headers(opts?.headers);
1195
+ if (opts?.range !== void 0) headers.set("Range", opts.range);
1196
+ if (opts?.ifNoneMatch !== void 0) headers.set("If-None-Match", opts.ifNoneMatch);
1197
+ const response = await this.http.requestResponse({
1198
+ method: "GET",
1199
+ path: `${workspacePath(id)}/files/content`,
1200
+ query: buildQueryParams({ path, user: opts?.user }),
1201
+ opts: { ...opts, headers: Object.fromEntries(headers), timeoutMs: opts?.timeoutMs ?? 0 },
1202
+ accept: "application/octet-stream",
1203
+ successStatuses: [304]
1204
+ });
1205
+ if (opts?.as === "bytes") return new Uint8Array(await response.arrayBuffer());
1206
+ if (opts?.as === "stream") return response.body;
1207
+ return response;
1208
+ }
1209
+ writeFile(id, path, content, opts) {
1210
+ const body = content instanceof Uint8Array ? content.buffer instanceof ArrayBuffer ? new Uint8Array(content.buffer, content.byteOffset, content.byteLength) : new Uint8Array(content) : content;
1211
+ return this.http.request({
1212
+ method: "PUT",
1213
+ path: `${workspacePath(id)}/files/content`,
1214
+ query: buildQueryParams({ path, mode: opts?.mode, create_only: opts?.createOnly, user: opts?.user }),
1215
+ opts: { ...opts, timeoutMs: opts?.timeoutMs ?? 0 },
1216
+ rawBody: body,
1217
+ duplex: body instanceof ReadableStream ? "half" : void 0,
1218
+ nonReplayable: true
1219
+ });
1220
+ }
1221
+ makeDir(id, body, opts) {
1222
+ return this.http.request({
1223
+ method: "POST",
1224
+ path: `${workspacePath(id)}/files/mkdir`,
1225
+ body,
1226
+ opts,
1227
+ nonReplayable: true,
1228
+ disableIdempotency: true
1229
+ });
1230
+ }
1231
+ moveFile(id, body, opts) {
1232
+ return this.http.request({
1233
+ method: "POST",
1234
+ path: `${workspacePath(id)}/files/move`,
1235
+ body,
1236
+ opts,
1237
+ nonReplayable: true,
1238
+ disableIdempotency: true
1239
+ });
1240
+ }
1241
+ deleteFile(id, path, opts) {
1242
+ return this.http.request({
1243
+ method: "DELETE",
1244
+ path: `${workspacePath(id)}/files`,
1245
+ query: buildQueryParams({ path, user: opts?.user }),
1246
+ opts,
1247
+ nonReplayable: true,
1248
+ disableIdempotency: true
1249
+ });
1250
+ }
1251
+ wsUrl(id) {
1252
+ return webSocketUrl(this.http.buildUrl(`${workspacePath(id)}/ws`));
1253
+ }
1254
+ tunnelWSUrl(id, target) {
1255
+ const url = this.http.buildUrl(`${workspacePath(id)}/tunnels/ws`, buildQueryParams({ ...target }));
1256
+ return webSocketUrl(url);
1257
+ }
1258
+ desktopVNCUrl(id) {
1259
+ return webSocketUrl(this.http.buildUrl(`${workspacePath(id)}/desktop/vnc`));
1260
+ }
1261
+ proxyUrl(id, port, path = "", query) {
1262
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
1263
+ throw new RangeError("port must be between 1 and 65535");
1264
+ }
1265
+ const segments = path.replace(/^\//, "").split("/");
1266
+ if (segments.some((segment) => segment === "." || segment === "..")) {
1267
+ throw new TypeError("Proxy path must not contain dot segments");
1268
+ }
1269
+ const suffix = path ? `/${segments.map(encodeURIComponent).join("/")}` : "";
1270
+ return this.http.buildUrl(`${workspacePath(id)}/proxy/${port}${suffix}`, query);
1271
+ }
1272
+ proxyWSUrl(id, port, path, query) {
1273
+ return webSocketUrl(this.proxyUrl(id, port, path, query));
1274
+ }
1275
+ /** Headers for a WebSocket upgrade or an authenticated proxy request. */
1276
+ wsHeaders(overrides) {
1277
+ return this.http.buildHeaders(overrides);
1278
+ }
1279
+ connectWS(id, opts) {
1280
+ return new WorkspaceSocket(openWebSocket(this.wsUrl(id), this.wsHeaders(opts?.headers), opts));
1281
+ }
1282
+ connectTunnel(id, target, opts) {
1283
+ return openWebSocket(this.tunnelWSUrl(id, target), this.wsHeaders(opts?.headers), opts);
1284
+ }
1285
+ connectDesktop(id, opts) {
1286
+ return openWebSocket(this.desktopVNCUrl(id), this.wsHeaders(opts?.headers), opts);
1287
+ }
1288
+ connectProxy(id, port, opts) {
1289
+ const url = this.proxyWSUrl(id, port, opts?.path, opts?.query);
1290
+ return openWebSocket(url, this.wsHeaders(opts?.headers), opts);
1291
+ }
907
1292
  /**
908
1293
  * Attaches a volume to a workspace.
909
1294
  * `PUT /v1/workspaces/{id}/volume`
@@ -980,6 +1365,89 @@ var ZonesResource = class {
980
1365
  }
981
1366
  };
982
1367
 
1368
+ // src/resources/egresses.ts
1369
+ var EgressesResource = class {
1370
+ constructor(http) {
1371
+ this.http = http;
1372
+ }
1373
+ http;
1374
+ create(body, opts) {
1375
+ return this.http.request({ method: "POST", path: "/egresses", body, opts });
1376
+ }
1377
+ list(params, opts) {
1378
+ return this.http.request({
1379
+ method: "GET",
1380
+ path: "/egresses",
1381
+ query: buildQueryParams({ ...params }),
1382
+ opts
1383
+ });
1384
+ }
1385
+ get(id, opts) {
1386
+ return this.http.request({ method: "GET", path: `/egresses/${encodeURIComponent(id)}`, opts });
1387
+ }
1388
+ replace(id, body, opts) {
1389
+ return this.http.request({ method: "PUT", path: `/egresses/${encodeURIComponent(id)}`, body, opts });
1390
+ }
1391
+ update(id, body, opts) {
1392
+ return this.http.request({ method: "PATCH", path: `/egresses/${encodeURIComponent(id)}`, body, opts });
1393
+ }
1394
+ delete(id, opts) {
1395
+ return this.http.request({ method: "DELETE", path: `/egresses/${encodeURIComponent(id)}`, opts });
1396
+ }
1397
+ };
1398
+
1399
+ // src/resources/packs.ts
1400
+ var PacksResource = class {
1401
+ constructor(http) {
1402
+ this.http = http;
1403
+ }
1404
+ http;
1405
+ list(params, opts) {
1406
+ return this.http.request({ method: "GET", path: "/packs", query: buildQueryParams({ ...params }), opts });
1407
+ }
1408
+ get(id, opts) {
1409
+ return this.http.request({ method: "GET", path: `/packs/${encodeURIComponent(id)}`, opts });
1410
+ }
1411
+ getRevision(id, revisionId, opts) {
1412
+ return this.http.request({
1413
+ method: "GET",
1414
+ path: `/packs/${encodeURIComponent(id)}/revisions/${encodeURIComponent(revisionId)}`,
1415
+ opts
1416
+ });
1417
+ }
1418
+ };
1419
+
1420
+ // src/resources/resolvers.ts
1421
+ var ResolversResource = class {
1422
+ constructor(http) {
1423
+ this.http = http;
1424
+ }
1425
+ http;
1426
+ create(body, opts) {
1427
+ return this.http.request({ method: "POST", path: "/resolvers", body, opts });
1428
+ }
1429
+ list(params, opts) {
1430
+ return this.http.request({
1431
+ method: "GET",
1432
+ path: "/resolvers",
1433
+ query: buildQueryParams({ ...params }),
1434
+ opts
1435
+ });
1436
+ }
1437
+ get(id, opts) {
1438
+ return this.http.request({ method: "GET", path: `/resolvers/${encodeURIComponent(id)}`, opts });
1439
+ }
1440
+ replace(id, body, opts) {
1441
+ return this.http.request({ method: "PUT", path: `/resolvers/${encodeURIComponent(id)}`, body, opts });
1442
+ }
1443
+ update(id, body, opts) {
1444
+ return this.http.request({ method: "PATCH", path: `/resolvers/${encodeURIComponent(id)}`, body, opts });
1445
+ }
1446
+ delete(id, opts) {
1447
+ return this.http.request({ method: "DELETE", path: `/resolvers/${encodeURIComponent(id)}`, opts });
1448
+ }
1449
+ };
1450
+
983
1451
  // src/client.ts
984
1452
  var Kibotos = class {
985
1453
  zones;
@@ -987,6 +1455,9 @@ var Kibotos = class {
987
1455
  workspaces;
988
1456
  volumes;
989
1457
  exposures;
1458
+ egresses;
1459
+ packs;
1460
+ resolvers;
990
1461
  http;
991
1462
  constructor(options = {}) {
992
1463
  this.http = new HttpClient(options);
@@ -994,6 +1465,9 @@ var Kibotos = class {
994
1465
  this.templates = new TemplatesResource(this.http);
995
1466
  this.workspaces = new WorkspacesResource(this.http);
996
1467
  this.volumes = new VolumesResource(this.http);
1468
+ this.egresses = new EgressesResource(this.http);
1469
+ this.packs = new PacksResource(this.http);
1470
+ this.resolvers = new ResolversResource(this.http);
997
1471
  this.exposures = new ExposuresResource(this.http);
998
1472
  }
999
1473
  /** Normalized base URL (always ending in `/v1`). */
@@ -1008,19 +1482,27 @@ exports.ConflictError = ConflictError;
1008
1482
  exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
1009
1483
  exports.DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES;
1010
1484
  exports.DEFAULT_TIMEOUT_MS = DEFAULT_TIMEOUT_MS;
1485
+ exports.EgressesResource = EgressesResource;
1011
1486
  exports.ExposuresResource = ExposuresResource;
1012
1487
  exports.Kibotos = Kibotos;
1013
1488
  exports.KibotosAPIError = KibotosAPIError;
1014
1489
  exports.KibotosError = KibotosError;
1015
1490
  exports.NotFoundError = NotFoundError;
1491
+ exports.PacksResource = PacksResource;
1016
1492
  exports.PermissionDeniedError = PermissionDeniedError;
1017
1493
  exports.RateLimitError = RateLimitError;
1494
+ exports.ResolversResource = ResolversResource;
1018
1495
  exports.SDK_VERSION = SDK_VERSION;
1019
1496
  exports.TemplatesResource = TemplatesResource;
1020
1497
  exports.UnexpectedStatusError = UnexpectedStatusError;
1021
1498
  exports.VolumesResource = VolumesResource;
1022
1499
  exports.WaitTimeoutError = WaitTimeoutError;
1500
+ exports.WorkspaceChannel = WorkspaceChannel;
1501
+ exports.WorkspaceSocket = WorkspaceSocket;
1023
1502
  exports.WorkspacesResource = WorkspacesResource;
1024
1503
  exports.ZonesResource = ZonesResource;
1504
+ exports.decodeBinaryFrame = decodeBinaryFrame;
1505
+ exports.decodeWorkspaceFrame = decodeWorkspaceFrame;
1506
+ exports.encodeBinaryFrame = encodeBinaryFrame;
1025
1507
  //# sourceMappingURL=index.cjs.map
1026
1508
  //# sourceMappingURL=index.cjs.map