@tensorlakeai/tensorlake 0.0.0-bootstrap.0 → 0.5.145
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 +166 -2
- package/bin/function-executor.js +8 -0
- package/bin/tensorlake-create-sandbox-image.js +9 -0
- package/bin/tensorlake-deploy.cjs +8 -0
- package/bin/tensorlake-import-sandbox-image.js +9 -0
- package/bin/tensorlake-typescript-function-runner.js +8 -0
- package/dist/applications/index.cjs +4821 -0
- package/dist/applications/index.cjs.map +1 -0
- package/dist/applications/index.d.cts +130 -0
- package/dist/applications/index.d.ts +130 -0
- package/dist/applications/index.js +4782 -0
- package/dist/applications/index.js.map +1 -0
- package/dist/function-agent/main.cjs +1838 -0
- package/dist/function-agent/main.cjs.map +1 -0
- package/dist/function-agent/main.d.cts +3 -0
- package/dist/function-agent/main.d.ts +3 -0
- package/dist/function-agent/main.js +1825 -0
- package/dist/function-agent/main.js.map +1 -0
- package/dist/function-executor/main.cjs +4944 -0
- package/dist/function-executor/main.cjs.map +1 -0
- package/dist/function-executor/main.d.cts +4 -0
- package/dist/function-executor/main.d.ts +4 -0
- package/dist/function-executor/main.js +4902 -0
- package/dist/function-executor/main.js.map +1 -0
- package/dist/index.cjs +10184 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2431 -0
- package/dist/index.d.ts +2431 -0
- package/dist/index.js +10108 -0
- package/dist/index.js.map +1 -0
- package/dist/native-worker.cjs +278 -0
- package/dist/native-worker.cjs.map +1 -0
- package/dist/native-worker.d.cts +2 -0
- package/dist/native-worker.d.ts +2 -0
- package/dist/native-worker.js +276 -0
- package/dist/native-worker.js.map +1 -0
- package/dist/remote-CNJ9TmcQ.d.cts +283 -0
- package/dist/remote-dblFxKug.d.ts +283 -0
- package/dist/sandbox-image-ChzWDeZy.d.cts +357 -0
- package/dist/sandbox-image-ChzWDeZy.d.ts +357 -0
- package/dist/sandbox-image.cjs +1992 -0
- package/dist/sandbox-image.cjs.map +1 -0
- package/dist/sandbox-image.d.cts +1 -0
- package/dist/sandbox-image.d.ts +1 -0
- package/dist/sandbox-image.js +1987 -0
- package/dist/sandbox-image.js.map +1 -0
- package/lib/libc.cjs +61 -0
- package/lib/libc.d.cts +1 -0
- package/lib/runtime.cjs +155 -0
- package/package.json +104 -4
- package/runtime/function-executor/manifest.json +59 -0
- package/runtime/function-executor/package/bin/function-executor.js +8 -0
- package/runtime/function-executor/package/dist/function-executor/main.js +4902 -0
- package/runtime/function-executor/package/dist/function-executor/main.js.map +1 -0
- package/runtime/function-executor/package/dist/native-worker.cjs +278 -0
- package/runtime/function-executor/package/dist/native-worker.cjs.map +1 -0
- package/runtime/function-executor/package/npm-shrinkwrap.json +475 -0
- package/runtime/function-executor/package/package.json +22 -0
- package/runtime/function-executor/package/proto/README.md +18 -0
- package/runtime/function-executor/package/proto/tensorlake/function_executor/proto/function_executor.proto +613 -0
- package/runtime/function-executor/package/proto/tensorlake/function_executor/proto/status.proto +42 -0
- package/runtime/typescript-function-runner/manifest.json +44 -0
- package/runtime/typescript-function-runner/package/bin/tensorlake-typescript-function-runner.js +8 -0
- package/runtime/typescript-function-runner/package/dist/function-agent/main.js +1825 -0
- package/runtime/typescript-function-runner/package/dist/function-agent/main.js.map +1 -0
- package/runtime/typescript-function-runner/package/dist/native-worker.cjs +278 -0
- package/runtime/typescript-function-runner/package/dist/native-worker.cjs.map +1 -0
- package/runtime/typescript-function-runner/package/npm-shrinkwrap.json +586 -0
- package/runtime/typescript-function-runner/package/package.json +25 -0
package/README.md
CHANGED
|
@@ -1,3 +1,167 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Tensorlake TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The TypeScript SDK supports Tensorlake sandboxes on Node.js 22 or newer. Deploying and running durable TypeScript applications requires Node.js 24 or newer. Application handlers are async-only and values crossing a function boundary must be JSON values or a direct `File`. Application entrypoints can also receive an exact raw request body with `HttpBody`.
|
|
4
|
+
|
|
5
|
+
Sandbox, repository and filesystem handles retain configuration on the calling thread.
|
|
6
|
+
The first native operation starts a persistent Node worker that loads the addon and
|
|
7
|
+
owns the native clients. Concurrent calls use the same worker; sandbox proxies share
|
|
8
|
+
their lifecycle client's connection pool. Addon loading and TLS initialization keep
|
|
9
|
+
the application's event loop responsive, including on the first call. Initialization
|
|
10
|
+
failures reject the operation. A later operation can retry transport initialization;
|
|
11
|
+
creating a new client picks up changes to the system's trusted certificates.
|
|
12
|
+
|
|
13
|
+
Streaming consumers acknowledge each event before Rust reads the next one. Breaking
|
|
14
|
+
iteration, aborting its signal, or closing the sandbox connection cancels the native
|
|
15
|
+
HTTP stream. Closing one handle leaves sibling handles usable. Garbage collection
|
|
16
|
+
also releases native handles, and an idle worker does not keep Node running. If a
|
|
17
|
+
worker fails, outstanding calls reject without automatic replay; subsequent calls
|
|
18
|
+
can start a fresh worker. Byte arguments are copied across the worker boundary;
|
|
19
|
+
caller-owned buffers are never detached. File-path upload APIs avoid that copy.
|
|
20
|
+
|
|
21
|
+
Both ESM and CommonJS packages include the worker entrypoint. Applications using a
|
|
22
|
+
bundler should keep `@tensorlakeai/tensorlake` external so its worker and optional native packages
|
|
23
|
+
remain available at runtime. Tensorlake's function runtime capsules carry the worker
|
|
24
|
+
for deployed application bundles. Image-building and Function Agent runtime bindings
|
|
25
|
+
have their own native entrypoints and are outside this sandbox worker boundary.
|
|
26
|
+
|
|
27
|
+
On Linux, native binding selection reads the Node executable's ELF interpreter
|
|
28
|
+
without generating diagnostic reports. For a nonstandard or statically linked Node
|
|
29
|
+
executable, set `TENSORLAKE_NODE_LIBC=gnu` or `TENSORLAKE_NODE_LIBC=musl` before using
|
|
30
|
+
the SDK.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { registerApplication, registerFunction } from "@tensorlakeai/tensorlake/applications";
|
|
34
|
+
|
|
35
|
+
const square = registerFunction(
|
|
36
|
+
"square",
|
|
37
|
+
async (value: number) => value * value,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const squares = registerApplication(
|
|
41
|
+
"squares",
|
|
42
|
+
async (values: number[]) => square.map(values),
|
|
43
|
+
);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This concise form infers the TypeScript call signature and uses permissive JSON
|
|
47
|
+
schemas. JavaScript default parameters are inferred as optional, and the
|
|
48
|
+
explicit name is stable across bundling. Use the schema-rich form when you need
|
|
49
|
+
runtime validation, API metadata, optional parameters without a JavaScript
|
|
50
|
+
default, rest parameters, `File` inputs and outputs, or an `HttpBody` input:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { registerApplication, schema } from "@tensorlakeai/tensorlake/applications";
|
|
54
|
+
|
|
55
|
+
export const validatedSquare = registerApplication(
|
|
56
|
+
async (value: number) => value * value,
|
|
57
|
+
{
|
|
58
|
+
name: "validated_square",
|
|
59
|
+
parameters: [schema.parameter("value", schema.number())] as const,
|
|
60
|
+
returns: schema.number(),
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Run locally or deploy the same file:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { runLocal } from "@tensorlakeai/tensorlake/applications";
|
|
69
|
+
|
|
70
|
+
const request = await runLocal(squares, [1, 2, 3]);
|
|
71
|
+
console.log(await request.output());
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Use `runRemote` for a deployed application. Plain client options remain the
|
|
75
|
+
last argument when every application argument is supplied. Wrap options with
|
|
76
|
+
`remoteOptions` when omitting JavaScript default arguments so an object input
|
|
77
|
+
can never be mistaken for client configuration:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { registerApplication, remoteOptions, runRemote } from "@tensorlakeai/tensorlake/applications";
|
|
81
|
+
|
|
82
|
+
const greeting = registerApplication(
|
|
83
|
+
"greeting",
|
|
84
|
+
async (name = "world") => `Hello, ${name}!`,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const request = await runRemote(
|
|
88
|
+
greeting,
|
|
89
|
+
remoteOptions({ apiKey: process.env.TENSORLAKE_API_KEY }),
|
|
90
|
+
);
|
|
91
|
+
console.log(await request.output());
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm install @tensorlakeai/tensorlake
|
|
96
|
+
tl deploy app.ts
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`tl` recognizes ESM `.ts`, `.mts`, `.js`, and `.mjs` entrypoints. The Rust CLI bundles the application for Node 24 with Rolldown, initializes the resulting ESM bundle once with Node to discover its registered functions, builds the function images, and uploads the deployment. CommonJS application modules and bundler configuration files are not supported.
|
|
100
|
+
|
|
101
|
+
The SDK build also produces a hashed executor capsule containing the Node 24 ESM executor, its protobufs, and an npm shrinkwrap derived from the checked-in SDK lockfile. During deployment, `tl` uses the capsule from the exact SDK package Rolldown resolved and adds it directly to the image-build context. This supports local dependencies such as `"@tensorlakeai/tensorlake": "file:../tensorlake/typescript"`; build that SDK checkout with `npm run build:sdk` before deploying. The local Tensorlake package does not need to be published.
|
|
102
|
+
|
|
103
|
+
Functions expose `future`, `map`, `reduce`, and `tailCall`. `map` and `reduce`
|
|
104
|
+
accept either an iterable or a Promise/Future that produces one, and their
|
|
105
|
+
iterables may contain Promise/Future values. A reduce initial value is optional;
|
|
106
|
+
without one, the first item becomes the accumulator and an empty collection is
|
|
107
|
+
an error. Awaiting a registered function inside a running application creates a
|
|
108
|
+
durable remote function call. `RequestContext.get()` provides async request
|
|
109
|
+
state, metrics, progress, and an abort signal. Local requests expose `cancel()`,
|
|
110
|
+
which aborts that signal and rejects `output()`.
|
|
111
|
+
|
|
112
|
+
TypeScript and Python definitions cannot be mixed in one deployed application bundle. Class-based function semantics are not supported in the TypeScript runtime.
|
|
113
|
+
|
|
114
|
+
For a raw request body, declare a direct application parameter with
|
|
115
|
+
`schema.httpBody()`. `HttpBody.content` contains the unchanged bytes,
|
|
116
|
+
`contentType` preserves the request MIME type, and `text()` / `json()` provide
|
|
117
|
+
explicit decoding helpers. `RequestContext.get().headers` exposes sanitized,
|
|
118
|
+
case-insensitive invocation headers and preserves duplicate values through
|
|
119
|
+
`getAll()`. `HttpBody` is not supported in nested schemas, durable function
|
|
120
|
+
parameters, or return values. See the
|
|
121
|
+
[raw webhook example](examples/http-body/README.md).
|
|
122
|
+
|
|
123
|
+
Applications that accept public HTTP requests can set
|
|
124
|
+
`allow: ["unauthenticated_requests"]` in their registration options. The
|
|
125
|
+
capability is emitted in the deployment manifest, and deployments preserve the
|
|
126
|
+
application's stable public endpoint identifier across updates.
|
|
127
|
+
|
|
128
|
+
## Function executor correctness
|
|
129
|
+
|
|
130
|
+
Run the executor transport and protocol-state regression suites with:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm run test:function-executor
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
These tests use bounded fake-server event sequences to cover terminal-result cardinality, retry exhaustion, deterministic concurrent fan-out and strict replay, function-call reduce chains, malformed user input, non-advancing event pages, tail calls, cross-bundle request errors, state reconciliation, and ranged BLOB transport. `npm run build:sdk` additionally builds the exact executor capsule used during deployment.
|
|
137
|
+
|
|
138
|
+
## Live server verification
|
|
139
|
+
|
|
140
|
+
The [server-verification example](examples/server-verification/README.md) uses the normal `tl deploy <PATH>` workflow to deploy eight reference applications and verify durable calls, retries and retry exhaustion, concurrent fan-out, server-orchestrated reduce, nested calls, request context, tail calls, files, and request errors against an already-running server.
|
|
141
|
+
|
|
142
|
+
## Native transport and application preloads
|
|
143
|
+
|
|
144
|
+
Cloud, sandbox, repository, and filesystem HTTP operations use the Rust SDK
|
|
145
|
+
through an internal worker. Keep the platform-specific optional native package
|
|
146
|
+
installed. Importing Tensorlake does not replace the application's HTTP dispatcher.
|
|
147
|
+
|
|
148
|
+
The worker starts with an empty `execArgv` and a copied environment with
|
|
149
|
+
`NODE_OPTIONS` cleared, so application `--require`, `--import`, and loader hooks
|
|
150
|
+
do not run inside it. Other environment variables are copied when it starts.
|
|
151
|
+
The application's own startup flags and environment remain intact. Native HTTPS
|
|
152
|
+
uses the Rust SDK's bundled Mozilla certificate roots.
|
|
153
|
+
|
|
154
|
+
`CloudClient.close()` cancels its active requests and streams and prevents further
|
|
155
|
+
requests. Buffered cloud requests have a 300-second deadline covering retries and
|
|
156
|
+
body reads. Progress and build-log streams have a connection deadline and can
|
|
157
|
+
remain open until completion or cancellation. `maxRetries` and `retryBackoffMs`
|
|
158
|
+
control transient retries for safe reads; mutations are replayed only when the
|
|
159
|
+
Rust retry policy establishes that they were not delivered, within its 30-second
|
|
160
|
+
replay budget. A lost response after delivery does not replay an application invocation.
|
|
161
|
+
Mutation redirects are returned as errors instead of being followed, because a
|
|
162
|
+
failure fetching the redirected result cannot prove that the mutation was not
|
|
163
|
+
delivered. Safe reads still follow redirects and retry failed response transfers.
|
|
164
|
+
Cloud requests advertise gzip support and decode gzip responses, including live SSE.
|
|
165
|
+
|
|
166
|
+
After building the SDK and native addon, run `npm run test:native-cloud` to check
|
|
167
|
+
the cloud transport against a local HTTP server.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { runCreateSandboxImageCli } from "../dist/sandbox-image.js";
|
|
4
|
+
|
|
5
|
+
runCreateSandboxImageCli().catch((error) => {
|
|
6
|
+
const message = error instanceof Error ? error.stack : String(error);
|
|
7
|
+
process.stderr.write(`${message}\n`);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { runImportSandboxImageCli } from "../dist/sandbox-image.js";
|
|
4
|
+
|
|
5
|
+
runImportSandboxImageCli().catch((error) => {
|
|
6
|
+
const message = error instanceof Error ? error.stack : String(error);
|
|
7
|
+
process.stderr.write(`${message}\n`);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
});
|