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