@buda-ai/connector 0.1.11 → 0.1.12

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.
Files changed (2) hide show
  1. package/dist/cli.js +37 -12
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -517,7 +517,7 @@ import path2 from "path";
517
517
  // package.json
518
518
  var package_default = {
519
519
  name: "@buda-ai/connector",
520
- version: "0.1.11",
520
+ version: "0.1.12",
521
521
  private: false,
522
522
  type: "module",
523
523
  publishConfig: {
@@ -3196,17 +3196,13 @@ var proxyConnectorTerminalTunnel = async (input) => {
3196
3196
  headers: { "X-Buda-Local-Terminal-Token": input.localToken },
3197
3197
  handshakeTimeout: TERMINAL_HANDSHAKE_TIMEOUT_MS
3198
3198
  });
3199
- try {
3200
- await Promise.all([connectSocket(cloud), connectSocket(local)]);
3201
- } catch (error) {
3202
- cloud.terminate();
3203
- local.terminate();
3204
- throw error;
3205
- }
3206
3199
  let bridgeAccepted = false;
3200
+ let activityStarted = false;
3207
3201
  let activityEnded = false;
3202
+ let cloudCloseAfterOpen = null;
3203
+ let localCloseAfterOpen = null;
3208
3204
  const endActivity = () => {
3209
- if (activityEnded) return;
3205
+ if (!activityStarted || activityEnded) return;
3210
3206
  activityEnded = true;
3211
3207
  input.onActivityEnd?.();
3212
3208
  };
@@ -3254,24 +3250,53 @@ var proxyConnectorTerminalTunnel = async (input) => {
3254
3250
  });
3255
3251
  cloud.once("close", (code, reason) => {
3256
3252
  endActivity();
3253
+ const normalizedCode = normalizeTerminalCloseCode(code);
3254
+ const normalizedReason = truncateTerminalCloseReason(reason.toString());
3257
3255
  if (!bridgeAccepted) {
3258
3256
  void writeLog(
3259
3257
  "warn",
3260
- `terminal cloud tunnel closed before readiness session=${input.sessionId} code=${code} reason=${truncateTerminalCloseReason(reason.toString())}`
3258
+ `terminal cloud tunnel closed before readiness session=${input.sessionId} code=${code} reason=${normalizedReason}`
3261
3259
  );
3262
3260
  }
3263
3261
  if (local.readyState === WebSocket.OPEN) {
3264
- local.close(normalizeTerminalCloseCode(code), truncateTerminalCloseReason(reason.toString()));
3262
+ local.close(normalizedCode, normalizedReason);
3263
+ } else if (local.readyState === WebSocket.CONNECTING) {
3264
+ localCloseAfterOpen = { code: normalizedCode, reason: normalizedReason };
3265
3265
  }
3266
3266
  });
3267
3267
  local.once("close", (code, reason) => {
3268
3268
  endActivity();
3269
+ const normalizedClose = {
3270
+ code: normalizeTerminalCloseCode(code),
3271
+ reason: truncateTerminalCloseReason(reason.toString())
3272
+ };
3269
3273
  if (cloud.readyState === WebSocket.OPEN) {
3270
- cloud.close(normalizeTerminalCloseCode(code), truncateTerminalCloseReason(reason.toString()));
3274
+ cloud.close(normalizedClose.code, normalizedClose.reason);
3275
+ } else if (cloud.readyState === WebSocket.CONNECTING) {
3276
+ cloudCloseAfterOpen = normalizedClose;
3277
+ }
3278
+ });
3279
+ cloud.once("open", () => {
3280
+ if (cloudCloseAfterOpen && cloud.readyState === WebSocket.OPEN) {
3281
+ cloud.close(cloudCloseAfterOpen.code, cloudCloseAfterOpen.reason);
3282
+ }
3283
+ });
3284
+ local.once("open", () => {
3285
+ if (localCloseAfterOpen && local.readyState === WebSocket.OPEN) {
3286
+ local.close(localCloseAfterOpen.code, localCloseAfterOpen.reason);
3271
3287
  }
3272
3288
  });
3273
3289
  cloud.once("error", () => local.terminate());
3274
3290
  local.once("error", () => cloud.terminate());
3291
+ try {
3292
+ await Promise.all([connectSocket(cloud), connectSocket(local)]);
3293
+ } catch (error) {
3294
+ cloud.terminate();
3295
+ local.terminate();
3296
+ throw error;
3297
+ }
3298
+ if (cloud.readyState !== WebSocket.OPEN || local.readyState !== WebSocket.OPEN) return;
3299
+ activityStarted = true;
3275
3300
  input.onActivityStart?.();
3276
3301
  cloud.send(JSON.stringify({ type: "bridge-ready" }));
3277
3302
  await writeLog(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buda-ai/connector",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "publishConfig": {