@tensorlakeai/tensorlake 0.5.151 → 0.5.152
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/README.md +8 -0
- package/dist/applications/index.cjs +7 -2
- package/dist/applications/index.cjs.map +1 -1
- package/dist/applications/index.js +7 -2
- package/dist/applications/index.js.map +1 -1
- package/dist/function-agent/main.cjs +1 -1
- package/dist/function-agent/main.cjs.map +1 -1
- package/dist/function-agent/main.js +1 -1
- package/dist/function-agent/main.js.map +1 -1
- package/dist/function-executor/main.cjs +2 -2
- package/dist/function-executor/main.cjs.map +1 -1
- package/dist/function-executor/main.js +2 -2
- package/dist/function-executor/main.js.map +1 -1
- package/dist/index.cjs +46 -189
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -6
- package/dist/index.d.ts +2 -6
- package/dist/index.js +45 -188
- package/dist/index.js.map +1 -1
- package/dist/sandbox-image.cjs +7 -2
- package/dist/sandbox-image.cjs.map +1 -1
- package/dist/sandbox-image.js +7 -2
- package/dist/sandbox-image.js.map +1 -1
- package/package.json +8 -7
- package/runtime/function-executor/manifest.json +7 -7
- package/runtime/function-executor/package/dist/function-executor/main.js +2 -2
- package/runtime/function-executor/package/dist/function-executor/main.js.map +1 -1
- package/runtime/function-executor/package/npm-shrinkwrap.json +2 -2
- package/runtime/function-executor/package/package.json +1 -1
- package/runtime/typescript-function-runner/manifest.json +7 -7
- package/runtime/typescript-function-runner/package/dist/function-agent/main.js +1 -1
- package/runtime/typescript-function-runner/package/dist/function-agent/main.js.map +1 -1
- package/runtime/typescript-function-runner/package/npm-shrinkwrap.json +26 -26
- package/runtime/typescript-function-runner/package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -49,7 +49,7 @@ var init_defaults = __esm({
|
|
|
49
49
|
"src/defaults.ts"() {
|
|
50
50
|
"use strict";
|
|
51
51
|
init_cjs_shims();
|
|
52
|
-
SDK_VERSION = "0.5.
|
|
52
|
+
SDK_VERSION = "0.5.152";
|
|
53
53
|
API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
|
|
54
54
|
API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
|
|
55
55
|
NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
|
|
@@ -314,6 +314,11 @@ function createWorkerBinding(runtime) {
|
|
|
314
314
|
return runtime.handle("NativeRepositoryClient", args);
|
|
315
315
|
}
|
|
316
316
|
},
|
|
317
|
+
NativeTcpTunnel: class {
|
|
318
|
+
constructor() {
|
|
319
|
+
return runtime.handle("NativeTcpTunnel", []);
|
|
320
|
+
}
|
|
321
|
+
},
|
|
317
322
|
validateManagedName: (name) => runtime.call(void 0, "validateManagedName", [name])
|
|
318
323
|
};
|
|
319
324
|
}
|
|
@@ -493,7 +498,7 @@ var init_native_worker_client = __esm({
|
|
|
493
498
|
}
|
|
494
499
|
};
|
|
495
500
|
runtimeKey = /* @__PURE__ */ Symbol.for(
|
|
496
|
-
`tensorlake.native.worker.${false ? "source" : "0.5.
|
|
501
|
+
`tensorlake.native.worker.${false ? "source" : "0.5.152"}.v1`
|
|
497
502
|
);
|
|
498
503
|
runtimes = globalThis;
|
|
499
504
|
}
|
|
@@ -941,116 +946,6 @@ function normalizeWebSocketData(message) {
|
|
|
941
946
|
}
|
|
942
947
|
return Buffer.from(message);
|
|
943
948
|
}
|
|
944
|
-
async function relaySocket(localSocket, websocket) {
|
|
945
|
-
return new Promise((resolve2) => {
|
|
946
|
-
let settled = false;
|
|
947
|
-
const keepAliveInterval = setInterval(() => {
|
|
948
|
-
if (websocket.readyState === import_ws.default.OPEN) {
|
|
949
|
-
websocket.ping();
|
|
950
|
-
}
|
|
951
|
-
}, WEBSOCKET_KEEPALIVE_INTERVAL_MS);
|
|
952
|
-
keepAliveInterval.unref?.();
|
|
953
|
-
const finish = () => {
|
|
954
|
-
if (settled) return;
|
|
955
|
-
settled = true;
|
|
956
|
-
clearInterval(keepAliveInterval);
|
|
957
|
-
cleanup();
|
|
958
|
-
resolve2();
|
|
959
|
-
};
|
|
960
|
-
const cleanup = () => {
|
|
961
|
-
localSocket.removeListener("data", onLocalData);
|
|
962
|
-
localSocket.removeListener("end", onLocalEnd);
|
|
963
|
-
localSocket.removeListener("close", onLocalClose);
|
|
964
|
-
localSocket.removeListener("error", onLocalError);
|
|
965
|
-
websocket.removeListener("message", onWsMessage);
|
|
966
|
-
websocket.removeListener("close", onWsClose);
|
|
967
|
-
websocket.removeListener("error", onWsError);
|
|
968
|
-
websocket.removeListener("ping", onWsPing);
|
|
969
|
-
};
|
|
970
|
-
const onLocalData = (chunk) => {
|
|
971
|
-
if (websocket.readyState !== import_ws.default.OPEN) {
|
|
972
|
-
localSocket.destroy();
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
975
|
-
websocket.send(chunk, { binary: true }, (error) => {
|
|
976
|
-
if (error) {
|
|
977
|
-
localSocket.destroy(error);
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
};
|
|
981
|
-
const onLocalEnd = () => {
|
|
982
|
-
if (websocket.readyState === import_ws.default.OPEN) {
|
|
983
|
-
websocket.close();
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
const onLocalClose = () => {
|
|
987
|
-
if (websocket.readyState === import_ws.default.OPEN || websocket.readyState === import_ws.default.CONNECTING) {
|
|
988
|
-
websocket.close();
|
|
989
|
-
}
|
|
990
|
-
finish();
|
|
991
|
-
};
|
|
992
|
-
const onLocalError = () => {
|
|
993
|
-
websocket.close();
|
|
994
|
-
finish();
|
|
995
|
-
};
|
|
996
|
-
const onWsMessage = (message, isBinary) => {
|
|
997
|
-
if (!isBinary) {
|
|
998
|
-
localSocket.destroy(
|
|
999
|
-
new SandboxError("received unexpected text frame from tunnel")
|
|
1000
|
-
);
|
|
1001
|
-
websocket.close();
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
const payload = normalizeWebSocketData(message);
|
|
1005
|
-
if (!localSocket.destroyed) {
|
|
1006
|
-
localSocket.write(payload);
|
|
1007
|
-
}
|
|
1008
|
-
};
|
|
1009
|
-
const onWsClose = () => {
|
|
1010
|
-
if (!localSocket.destroyed) {
|
|
1011
|
-
localSocket.end();
|
|
1012
|
-
}
|
|
1013
|
-
finish();
|
|
1014
|
-
};
|
|
1015
|
-
const onWsError = (error) => {
|
|
1016
|
-
localSocket.destroy(error);
|
|
1017
|
-
finish();
|
|
1018
|
-
};
|
|
1019
|
-
const onWsPing = (data) => {
|
|
1020
|
-
if (websocket.readyState === import_ws.default.OPEN) {
|
|
1021
|
-
websocket.pong(data, false, () => {
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
localSocket.on("data", onLocalData);
|
|
1026
|
-
localSocket.on("end", onLocalEnd);
|
|
1027
|
-
localSocket.on("close", onLocalClose);
|
|
1028
|
-
localSocket.on("error", onLocalError);
|
|
1029
|
-
websocket.on("message", onWsMessage);
|
|
1030
|
-
websocket.on("close", onWsClose);
|
|
1031
|
-
websocket.on("error", onWsError);
|
|
1032
|
-
websocket.on("ping", onWsPing);
|
|
1033
|
-
});
|
|
1034
|
-
}
|
|
1035
|
-
async function listenServer(server, localPort, localHost) {
|
|
1036
|
-
await new Promise((resolve2, reject) => {
|
|
1037
|
-
const onError = (error) => {
|
|
1038
|
-
server.removeListener("listening", onListening);
|
|
1039
|
-
reject(
|
|
1040
|
-
new SandboxError(
|
|
1041
|
-
`failed to bind local tunnel listener on ${localHost}:${localPort}: ${error.message}`
|
|
1042
|
-
)
|
|
1043
|
-
);
|
|
1044
|
-
};
|
|
1045
|
-
const onListening = () => {
|
|
1046
|
-
server.removeListener("error", onError);
|
|
1047
|
-
resolve2();
|
|
1048
|
-
};
|
|
1049
|
-
server.once("error", onError);
|
|
1050
|
-
server.once("listening", onListening);
|
|
1051
|
-
server.listen(localPort, localHost);
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
949
|
function validatePort(port, label, allowZero = false) {
|
|
1055
950
|
if (!Number.isInteger(port)) {
|
|
1056
951
|
throw new SandboxError(`${label} must be an integer, got ${port}`);
|
|
@@ -1083,14 +978,15 @@ async function withTimeout(timeoutMs, operation, timeoutMessage) {
|
|
|
1083
978
|
});
|
|
1084
979
|
});
|
|
1085
980
|
}
|
|
1086
|
-
var
|
|
981
|
+
var import_ws, DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS, WEBSOCKET_KEEPALIVE_INTERVAL_MS, TunnelByteStream, TcpTunnel;
|
|
1087
982
|
var init_tunnel = __esm({
|
|
1088
983
|
"src/tunnel.ts"() {
|
|
1089
984
|
"use strict";
|
|
1090
985
|
init_cjs_shims();
|
|
1091
|
-
net = __toESM(require("net"), 1);
|
|
1092
986
|
init_errors();
|
|
1093
987
|
import_ws = __toESM(require("ws"), 1);
|
|
988
|
+
init_native_sandbox();
|
|
989
|
+
init_native_worker_client();
|
|
1094
990
|
DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS = 1e4;
|
|
1095
991
|
WEBSOCKET_KEEPALIVE_INTERVAL_MS = 15e3;
|
|
1096
992
|
TunnelByteStream = class _TunnelByteStream {
|
|
@@ -1220,24 +1116,17 @@ var init_tunnel = __esm({
|
|
|
1220
1116
|
}
|
|
1221
1117
|
};
|
|
1222
1118
|
TcpTunnel = class _TcpTunnel {
|
|
1223
|
-
remotePort
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
closePromise = null;
|
|
1232
|
-
constructor(options) {
|
|
1233
|
-
this.baseUrl = options.baseUrl;
|
|
1234
|
-
this.wsHeaders = options.wsHeaders;
|
|
1235
|
-
this.remotePort = options.remotePort;
|
|
1236
|
-
this.localHost = options.localHost;
|
|
1237
|
-
this.localPort = options.localPort;
|
|
1238
|
-
this.server = options.server;
|
|
1239
|
-
this.connectTimeoutMs = options.connectTimeoutMs;
|
|
1119
|
+
constructor(native, remotePort, localHost, localPort) {
|
|
1120
|
+
this.native = native;
|
|
1121
|
+
this.remotePort = remotePort;
|
|
1122
|
+
this.localHost = localHost;
|
|
1123
|
+
this.localPort = localPort;
|
|
1124
|
+
this.lifetime = native.waitClosed();
|
|
1125
|
+
void this.lifetime.catch(() => {
|
|
1126
|
+
});
|
|
1240
1127
|
}
|
|
1128
|
+
closePromise = null;
|
|
1129
|
+
lifetime;
|
|
1241
1130
|
static async listen(options) {
|
|
1242
1131
|
const remotePort = validatePort(options.remotePort, "remote port");
|
|
1243
1132
|
const localHost = options.localHost ?? "127.0.0.1";
|
|
@@ -1246,69 +1135,37 @@ var init_tunnel = __esm({
|
|
|
1246
1135
|
"local port",
|
|
1247
1136
|
true
|
|
1248
1137
|
);
|
|
1249
|
-
const
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
void tunnel.handleConnection(localSocket);
|
|
1268
|
-
});
|
|
1269
|
-
return tunnel;
|
|
1138
|
+
const timeout = secondsToMillis(options.connectTimeout ?? 10) / 1e3;
|
|
1139
|
+
const native = new (loadNativeSandboxBinding()).NativeTcpTunnel();
|
|
1140
|
+
try {
|
|
1141
|
+
const port = await callNative(
|
|
1142
|
+
() => native.listen(
|
|
1143
|
+
options.baseUrl,
|
|
1144
|
+
options.wsHeaders,
|
|
1145
|
+
remotePort,
|
|
1146
|
+
localHost,
|
|
1147
|
+
localPort,
|
|
1148
|
+
timeout
|
|
1149
|
+
)
|
|
1150
|
+
);
|
|
1151
|
+
return new _TcpTunnel(native, remotePort, localHost, port);
|
|
1152
|
+
} catch (error) {
|
|
1153
|
+
releaseNativeHandle(native);
|
|
1154
|
+
throw error;
|
|
1155
|
+
}
|
|
1270
1156
|
}
|
|
1271
1157
|
address() {
|
|
1272
1158
|
return { host: this.localHost, port: this.localPort };
|
|
1273
1159
|
}
|
|
1274
1160
|
async close() {
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
this.server.close((error) => {
|
|
1284
|
-
if (error) {
|
|
1285
|
-
reject(new SandboxError(`failed to close tunnel listener: ${error.message}`));
|
|
1286
|
-
return;
|
|
1287
|
-
}
|
|
1288
|
-
resolve2();
|
|
1289
|
-
});
|
|
1290
|
-
});
|
|
1291
|
-
return this.closePromise;
|
|
1292
|
-
}
|
|
1293
|
-
async handleConnection(localSocket) {
|
|
1294
|
-
localSocket.setNoDelay(true);
|
|
1295
|
-
const relay = { localSocket, websocket: null };
|
|
1296
|
-
this.activeRelays.add(relay);
|
|
1297
|
-
try {
|
|
1298
|
-
relay.websocket = await openTunnelWebSocket({
|
|
1299
|
-
baseUrl: this.baseUrl,
|
|
1300
|
-
wsHeaders: this.wsHeaders,
|
|
1301
|
-
remotePort: this.remotePort,
|
|
1302
|
-
connectTimeoutMs: this.connectTimeoutMs
|
|
1303
|
-
});
|
|
1304
|
-
await relaySocket(localSocket, relay.websocket);
|
|
1305
|
-
} catch (error) {
|
|
1306
|
-
localSocket.destroy(
|
|
1307
|
-
error instanceof Error ? error : new Error(String(error))
|
|
1308
|
-
);
|
|
1309
|
-
} finally {
|
|
1310
|
-
this.activeRelays.delete(relay);
|
|
1311
|
-
}
|
|
1161
|
+
return this.closePromise ??= (async () => {
|
|
1162
|
+
try {
|
|
1163
|
+
await callNative(() => this.native.close());
|
|
1164
|
+
await this.lifetime;
|
|
1165
|
+
} finally {
|
|
1166
|
+
releaseNativeHandle(this.native);
|
|
1167
|
+
}
|
|
1168
|
+
})();
|
|
1312
1169
|
}
|
|
1313
1170
|
};
|
|
1314
1171
|
}
|