@buda-ai/connector 0.1.4 → 0.1.6
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/cli.js +52 -23
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1081,6 +1081,7 @@ var BASE_CONNECTOR_CAPABILITIES = [
|
|
|
1081
1081
|
"git"
|
|
1082
1082
|
];
|
|
1083
1083
|
var browserAvailabilityWarningLogged = false;
|
|
1084
|
+
var getBrowserAvailabilityWarning = (browserAvailability) => browserAvailability.available ? null : `${browserAvailability.error} Browser automation is disabled, but shell, filesystem, Git, and coding capabilities remain available.`;
|
|
1084
1085
|
var getAdvertisedCapabilities = (browserAvailability = resolveBrowserAvailability(), deviceToken) => [
|
|
1085
1086
|
...BASE_CONNECTOR_CAPABILITIES,
|
|
1086
1087
|
...browserAvailability.available ? ["browser"] : [],
|
|
@@ -1089,9 +1090,10 @@ var getAdvertisedCapabilities = (browserAvailability = resolveBrowserAvailabilit
|
|
|
1089
1090
|
async function buildPayload(config, extra) {
|
|
1090
1091
|
const bundle = await readBundledManifest();
|
|
1091
1092
|
const browserAvailability = resolveBrowserAvailability();
|
|
1092
|
-
|
|
1093
|
+
const browserWarning = getBrowserAvailabilityWarning(browserAvailability);
|
|
1094
|
+
if (browserWarning && !browserAvailabilityWarningLogged) {
|
|
1093
1095
|
browserAvailabilityWarningLogged = true;
|
|
1094
|
-
await writeLog("warn",
|
|
1096
|
+
await writeLog("warn", browserWarning);
|
|
1095
1097
|
}
|
|
1096
1098
|
return {
|
|
1097
1099
|
connectorId: config.connectorId,
|
|
@@ -2113,6 +2115,7 @@ var isAlreadyExists3 = (error) => error instanceof Error && "code" in error && e
|
|
|
2113
2115
|
// src/relay.ts
|
|
2114
2116
|
var RELAY_PING_INTERVAL_MS = 2e4;
|
|
2115
2117
|
var RELAY_PONG_TIMEOUT_MS = 1e4;
|
|
2118
|
+
var RELAY_HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
2116
2119
|
var RELAY_RECONNECT_MAX_MS = 3e4;
|
|
2117
2120
|
var RELAY_RECONNECT_JITTER = 0.2;
|
|
2118
2121
|
var RELAY_FAST_RECONNECT_MS = 500;
|
|
@@ -2120,12 +2123,29 @@ var CONNECTOR_SOCKET_REPLACED_CLOSE_CODE = 4001;
|
|
|
2120
2123
|
var CONNECTOR_SOCKET_REVOKED_CLOSE_CODE = 4003;
|
|
2121
2124
|
var shouldReconnectConnectorRelay = (closeCode) => closeCode !== CONNECTOR_SOCKET_REPLACED_CLOSE_CODE && closeCode !== CONNECTOR_SOCKET_REVOKED_CLOSE_CODE;
|
|
2122
2125
|
var getConnectorRelayReconnectBaseDelay = (hadOpenConnection, backoffMs) => hadOpenConnection ? RELAY_FAST_RECONNECT_MS : backoffMs;
|
|
2126
|
+
var formatConnectorRelayError = (error, depth = 0) => {
|
|
2127
|
+
if (depth >= 3) return String(error);
|
|
2128
|
+
const details = [String(error)];
|
|
2129
|
+
if (error && typeof error === "object") {
|
|
2130
|
+
const candidate = error;
|
|
2131
|
+
if (candidate.cause !== void 0) {
|
|
2132
|
+
details.push(`cause=${formatConnectorRelayError(candidate.cause, depth + 1)}`);
|
|
2133
|
+
}
|
|
2134
|
+
if (Array.isArray(candidate.errors) && candidate.errors.length > 0) {
|
|
2135
|
+
details.push(
|
|
2136
|
+
`errors=[${candidate.errors.map((nestedError) => formatConnectorRelayError(nestedError, depth + 1)).join(", ")}]`
|
|
2137
|
+
);
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
return [...new Set(details.filter(Boolean))].join(" ") || "Unknown relay error";
|
|
2141
|
+
};
|
|
2123
2142
|
function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegistry, launchConfig) {
|
|
2124
2143
|
let socket = null;
|
|
2125
2144
|
let reconnectTimer = null;
|
|
2126
2145
|
let pingTimer = null;
|
|
2127
2146
|
let pongTimer = null;
|
|
2128
2147
|
let stopped = false;
|
|
2148
|
+
let suspendedForAccessRevocation = false;
|
|
2129
2149
|
let reconnectDelayMs = RELAY_RECONNECT_INTERVAL_MS;
|
|
2130
2150
|
let hadOpenConnection = false;
|
|
2131
2151
|
let activeRelayProtocol = relayProtocol;
|
|
@@ -2152,7 +2172,7 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
|
|
|
2152
2172
|
return Math.max(reconnectingEstablishedSocket ? 250 : 500, Math.round(base + jitter));
|
|
2153
2173
|
};
|
|
2154
2174
|
const scheduleReconnect = (reason) => {
|
|
2155
|
-
if (stopped || reconnectTimer) return;
|
|
2175
|
+
if (stopped || suspendedForAccessRevocation || reconnectTimer) return;
|
|
2156
2176
|
const delay = nextReconnectDelay();
|
|
2157
2177
|
void writeLog("info", `relay reconnecting in ${delay}ms (${reason})`);
|
|
2158
2178
|
clearTimers();
|
|
@@ -2161,16 +2181,13 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
|
|
|
2161
2181
|
try {
|
|
2162
2182
|
connect();
|
|
2163
2183
|
} catch (error) {
|
|
2164
|
-
void writeLog(
|
|
2165
|
-
"warn",
|
|
2166
|
-
`relay reconnect threw: ${error instanceof Error ? error.message : error}`
|
|
2167
|
-
);
|
|
2184
|
+
void writeLog("warn", `relay reconnect threw: ${formatConnectorRelayError(error)}`);
|
|
2168
2185
|
scheduleReconnect("connect-throw");
|
|
2169
2186
|
}
|
|
2170
2187
|
}, delay);
|
|
2171
2188
|
};
|
|
2172
2189
|
const connect = () => {
|
|
2173
|
-
if (stopped) return;
|
|
2190
|
+
if (stopped || suspendedForAccessRevocation) return;
|
|
2174
2191
|
const relayUrl = getConnectorRelayUrl(config.serverUrl, config.connectorId);
|
|
2175
2192
|
const oauthToken = launchConfig?.oauthToken?.trim();
|
|
2176
2193
|
const token = config.token?.trim() || getConnectorToken(launchConfig);
|
|
@@ -2180,7 +2197,8 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
|
|
|
2180
2197
|
headers["X-Buda-Connector-Id"] = config.connectorId;
|
|
2181
2198
|
if (config.deviceToken) headers["X-Buda-Connector-Device-Token"] = config.deviceToken;
|
|
2182
2199
|
const ws = new WebSocket(relayUrl, {
|
|
2183
|
-
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
2200
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0,
|
|
2201
|
+
handshakeTimeout: RELAY_HANDSHAKE_TIMEOUT_MS
|
|
2184
2202
|
});
|
|
2185
2203
|
socket = ws;
|
|
2186
2204
|
const inflight = /* @__PURE__ */ new Map();
|
|
@@ -2201,10 +2219,7 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
|
|
|
2201
2219
|
try {
|
|
2202
2220
|
ws.ping();
|
|
2203
2221
|
} catch (error) {
|
|
2204
|
-
void writeLog(
|
|
2205
|
-
"warn",
|
|
2206
|
-
`relay ping failed: ${error instanceof Error ? error.message : error}`
|
|
2207
|
-
);
|
|
2222
|
+
void writeLog("warn", `relay ping failed: ${formatConnectorRelayError(error)}`);
|
|
2208
2223
|
ws.terminate();
|
|
2209
2224
|
return;
|
|
2210
2225
|
}
|
|
@@ -2236,18 +2251,21 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
|
|
|
2236
2251
|
ws.on("close", (code) => {
|
|
2237
2252
|
detach();
|
|
2238
2253
|
if (!shouldReconnectConnectorRelay(code)) {
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2254
|
+
clearTimers();
|
|
2255
|
+
if (code === CONNECTOR_SOCKET_REPLACED_CLOSE_CODE) {
|
|
2256
|
+
stopped = true;
|
|
2257
|
+
void writeLog("warn", "relay replaced by another process for this connector");
|
|
2258
|
+
} else {
|
|
2259
|
+
suspendedForAccessRevocation = true;
|
|
2260
|
+
void writeLog("warn", "relay access revoked; waiting for access to be restored");
|
|
2261
|
+
}
|
|
2244
2262
|
return;
|
|
2245
2263
|
}
|
|
2246
2264
|
void writeLog("warn", "relay disconnected");
|
|
2247
2265
|
scheduleReconnect("close");
|
|
2248
2266
|
});
|
|
2249
2267
|
ws.on("error", (error) => {
|
|
2250
|
-
void writeLog("warn", `relay error: ${error
|
|
2268
|
+
void writeLog("warn", `relay error: ${formatConnectorRelayError(error)}`);
|
|
2251
2269
|
detach();
|
|
2252
2270
|
scheduleReconnect("error");
|
|
2253
2271
|
});
|
|
@@ -2255,10 +2273,7 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
|
|
|
2255
2273
|
try {
|
|
2256
2274
|
connect();
|
|
2257
2275
|
} catch (error) {
|
|
2258
|
-
void writeLog(
|
|
2259
|
-
"warn",
|
|
2260
|
-
`relay initial connect threw: ${error instanceof Error ? error.message : error}`
|
|
2261
|
-
);
|
|
2276
|
+
void writeLog("warn", `relay initial connect threw: ${formatConnectorRelayError(error)}`);
|
|
2262
2277
|
scheduleReconnect("connect-throw");
|
|
2263
2278
|
}
|
|
2264
2279
|
return {
|
|
@@ -2269,6 +2284,19 @@ function startConnectorRelay(config, bunnyDaemon, relayProtocol, workspaceRegist
|
|
|
2269
2284
|
void writeLog("info", `relay protocol key updated ${nextRelayProtocol.keyId}`);
|
|
2270
2285
|
}
|
|
2271
2286
|
},
|
|
2287
|
+
resumeAfterAccessRestore() {
|
|
2288
|
+
if (stopped || !suspendedForAccessRevocation) return;
|
|
2289
|
+
suspendedForAccessRevocation = false;
|
|
2290
|
+
reconnectDelayMs = RELAY_RECONNECT_INTERVAL_MS;
|
|
2291
|
+
hadOpenConnection = false;
|
|
2292
|
+
void writeLog("info", "relay access restored; reconnecting");
|
|
2293
|
+
try {
|
|
2294
|
+
connect();
|
|
2295
|
+
} catch (error) {
|
|
2296
|
+
void writeLog("warn", `relay reconnect threw: ${formatConnectorRelayError(error)}`);
|
|
2297
|
+
scheduleReconnect("access-restored");
|
|
2298
|
+
}
|
|
2299
|
+
},
|
|
2272
2300
|
stop() {
|
|
2273
2301
|
stopped = true;
|
|
2274
2302
|
if (reconnectTimer) {
|
|
@@ -3034,6 +3062,7 @@ async function runConnectorDaemon(launchConfig) {
|
|
|
3034
3062
|
const interval = setInterval(() => {
|
|
3035
3063
|
heartbeatConnector(config, launchConfig, activeBunnyDaemon).then(({ relayProtocol: nextRelayProtocol }) => {
|
|
3036
3064
|
relay.updateRelayProtocol(nextRelayProtocol);
|
|
3065
|
+
relay.resumeAfterAccessRestore();
|
|
3037
3066
|
}).catch((error) => {
|
|
3038
3067
|
void writeLog(
|
|
3039
3068
|
"warn",
|