@cofy-x/axern-sdk 0.2.0-bootstrap.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.
Files changed (92) hide show
  1. package/README.md +169 -0
  2. package/dist/client/index.d.ts +63 -0
  3. package/dist/client/index.js +213 -0
  4. package/dist/config/index.d.ts +15 -0
  5. package/dist/config/index.js +65 -0
  6. package/dist/errors/index.d.ts +46 -0
  7. package/dist/errors/index.js +123 -0
  8. package/dist/generated/proto.d.ts +10 -0
  9. package/dist/generated/proto.js +80 -0
  10. package/dist/index.d.ts +19 -0
  11. package/dist/index.js +13 -0
  12. package/dist/node/archive.d.ts +9 -0
  13. package/dist/node/archive.js +41 -0
  14. package/dist/node/attached_process.d.ts +10 -0
  15. package/dist/node/attached_process.js +60 -0
  16. package/dist/node/capabilities.d.ts +8 -0
  17. package/dist/node/capabilities.js +51 -0
  18. package/dist/node/client.d.ts +44 -0
  19. package/dist/node/client.js +96 -0
  20. package/dist/node/computer_use.d.ts +12 -0
  21. package/dist/node/computer_use.js +81 -0
  22. package/dist/node/context.d.ts +22 -0
  23. package/dist/node/context.js +37 -0
  24. package/dist/node/exec.d.ts +12 -0
  25. package/dist/node/exec.js +93 -0
  26. package/dist/node/files.d.ts +18 -0
  27. package/dist/node/files.js +101 -0
  28. package/dist/node/process.d.ts +36 -0
  29. package/dist/node/process.js +144 -0
  30. package/dist/node/streams.d.ts +8 -0
  31. package/dist/node/streams.js +70 -0
  32. package/dist/proto/axern/common/file/v1/file.proto +31 -0
  33. package/dist/proto/axern/control/admin/v1/allocation_lifecycle.proto +91 -0
  34. package/dist/proto/axern/control/admin/v1/audit.proto +53 -0
  35. package/dist/proto/axern/control/admin/v1/node.proto +49 -0
  36. package/dist/proto/axern/control/admin/v1/reliability.proto +184 -0
  37. package/dist/proto/axern/control/admin/v1/service.proto +18 -0
  38. package/dist/proto/axern/control/admin/v1/storage.proto +81 -0
  39. package/dist/proto/axern/control/agentprofile/v1/agent_profile.proto +169 -0
  40. package/dist/proto/axern/control/catalog/v1/catalog.proto +127 -0
  41. package/dist/proto/axern/control/common/v1/common.proto +171 -0
  42. package/dist/proto/axern/control/environment/v1/environment.proto +94 -0
  43. package/dist/proto/axern/control/function/v1/function.proto +130 -0
  44. package/dist/proto/axern/control/function/v1/function_types.proto +233 -0
  45. package/dist/proto/axern/control/gateway/v1/gateway.proto +60 -0
  46. package/dist/proto/axern/control/namespace/v1/namespace.proto +52 -0
  47. package/dist/proto/axern/control/node/v1/node_control.proto +302 -0
  48. package/dist/proto/axern/control/quota/v1/quota.proto +113 -0
  49. package/dist/proto/axern/control/rollout/v1/rollout.proto +344 -0
  50. package/dist/proto/axern/control/run/v1/run.proto +88 -0
  51. package/dist/proto/axern/control/secret/v1/secret.proto +75 -0
  52. package/dist/proto/axern/control/service/v1/service.proto +96 -0
  53. package/dist/proto/axern/control/service/v1/service_event.proto +47 -0
  54. package/dist/proto/axern/control/service/v1/service_replica.proto +74 -0
  55. package/dist/proto/axern/control/service/v1/service_types.proto +155 -0
  56. package/dist/proto/axern/control/storage/v1/storage.proto +107 -0
  57. package/dist/proto/axern/control/storage/v1/storage_types.proto +125 -0
  58. package/dist/proto/axern/control/tunnel/v1/tunnel.proto +195 -0
  59. package/dist/proto/axern/data/artifact/v1/artifact.proto +19 -0
  60. package/dist/proto/axern/node/sandbox/v1/node.proto +652 -0
  61. package/dist/proto/axern/tunnel/v1/tunnel.proto +50 -0
  62. package/dist/resources.d.ts +13 -0
  63. package/dist/resources.js +107 -0
  64. package/dist/sandbox/archive.d.ts +8 -0
  65. package/dist/sandbox/archive.js +228 -0
  66. package/dist/sandbox/index.d.ts +86 -0
  67. package/dist/sandbox/index.js +204 -0
  68. package/dist/sandbox/lifecycle.d.ts +11 -0
  69. package/dist/sandbox/lifecycle.js +57 -0
  70. package/dist/tunnel/connector.d.ts +34 -0
  71. package/dist/tunnel/connector.js +141 -0
  72. package/dist/tunnel/control.d.ts +22 -0
  73. package/dist/tunnel/control.js +91 -0
  74. package/dist/tunnel/debug.d.ts +6 -0
  75. package/dist/tunnel/debug.js +19 -0
  76. package/dist/tunnel/relay.d.ts +17 -0
  77. package/dist/tunnel/relay.js +41 -0
  78. package/dist/tunnel/runtime.d.ts +34 -0
  79. package/dist/tunnel/runtime.js +118 -0
  80. package/dist/tunnel/session.d.ts +25 -0
  81. package/dist/tunnel/session.js +95 -0
  82. package/dist/tunnel/target.d.ts +7 -0
  83. package/dist/tunnel/target.js +28 -0
  84. package/dist/tunnel/types.d.ts +25 -0
  85. package/dist/tunnel/types.js +6 -0
  86. package/dist/types.d.ts +219 -0
  87. package/dist/types.js +8 -0
  88. package/dist/validation.d.ts +10 -0
  89. package/dist/validation.js +37 -0
  90. package/dist/version.d.ts +7 -0
  91. package/dist/version.js +9 -0
  92. package/package.json +57 -0
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import net from "node:net";
7
+ import { debugFrame } from "./debug.js";
8
+ const defaultDialTimeoutMs = 5_000;
9
+ const defaultMaxStreams = 128;
10
+ export class TunnelRelaySession {
11
+ call;
12
+ options;
13
+ streams = new Map();
14
+ constructor(call, options) {
15
+ this.call = call;
16
+ this.options = options;
17
+ }
18
+ handleFrame(frame) {
19
+ if ("ping" in frame) {
20
+ const ping = frame.ping;
21
+ this.send({ pong: { id: String(ping.id ?? "") } });
22
+ return;
23
+ }
24
+ if ("stream_open" in frame) {
25
+ this.openLocal(streamIdOf(frame.stream_open));
26
+ return;
27
+ }
28
+ if ("stream_data" in frame) {
29
+ const data = frame.stream_data;
30
+ this.writeLocal(streamIdOf(data), Buffer.from(data.data ?? []));
31
+ return;
32
+ }
33
+ if ("stream_close" in frame) {
34
+ this.closeLocal(streamIdOf(frame.stream_close));
35
+ }
36
+ }
37
+ send(frame) {
38
+ debugFrame("send", frame);
39
+ this.call.write(frame);
40
+ }
41
+ closeAll() {
42
+ for (const socket of this.streams.values()) {
43
+ socket.destroy();
44
+ }
45
+ this.streams.clear();
46
+ }
47
+ openLocal(streamId) {
48
+ if (this.streams.size >= (this.options.maxStreams ?? defaultMaxStreams)) {
49
+ this.sendClose(streamId, "max local streams reached");
50
+ return;
51
+ }
52
+ const socket = net.connect(this.options.upstreamTarget);
53
+ const timeout = this.options.dialTimeoutMs ?? defaultDialTimeoutMs;
54
+ this.streams.set(streamId, socket);
55
+ socket.setTimeout(timeout, () => {
56
+ this.sendClose(streamId, `dial timeout after ${timeout}ms`);
57
+ this.closeLocal(streamId);
58
+ });
59
+ socket.on("connect", () => {
60
+ socket.setTimeout(0);
61
+ });
62
+ socket.on("data", (data) => this.send({ stream_data: { stream_id: streamId, data } }));
63
+ socket.on("error", (error) => {
64
+ this.sendClose(streamId, error.message);
65
+ this.closeLocal(streamId);
66
+ });
67
+ socket.on("close", () => {
68
+ this.sendClose(streamId, "");
69
+ this.streams.delete(streamId);
70
+ });
71
+ }
72
+ writeLocal(streamId, data) {
73
+ const socket = this.streams.get(streamId);
74
+ if (socket === undefined) {
75
+ this.sendClose(streamId, "local stream is not open");
76
+ return;
77
+ }
78
+ socket.write(data);
79
+ }
80
+ closeLocal(streamId) {
81
+ const socket = this.streams.get(streamId);
82
+ this.streams.delete(streamId);
83
+ socket?.destroy();
84
+ }
85
+ sendClose(streamId, message) {
86
+ this.send({ stream_close: { stream_id: streamId, error: message } });
87
+ }
88
+ }
89
+ function streamIdOf(value) {
90
+ const streamId = String(value?.stream_id ?? "");
91
+ if (streamId === "") {
92
+ throw new Error("tunnel stream frame is missing stream_id");
93
+ }
94
+ return streamId;
95
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type net from "node:net";
7
+ export declare function parseTcpTarget(target: string): net.NetConnectOpts;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { SandboxValidationError } from "../errors/index.js";
7
+ export function parseTcpTarget(target) {
8
+ if (target.startsWith("[")) {
9
+ const end = target.indexOf("]");
10
+ if (end === -1 || target[end + 1] !== ":") {
11
+ throw new SandboxValidationError(`invalid tunnel upstream target: ${target}`);
12
+ }
13
+ const port = Number(target.slice(end + 2));
14
+ if (!Number.isInteger(port) || port <= 0) {
15
+ throw new SandboxValidationError(`invalid tunnel upstream port: ${target}`);
16
+ }
17
+ return { host: target.slice(1, end), port };
18
+ }
19
+ const colon = target.lastIndexOf(":");
20
+ if (colon <= 0 || colon === target.length - 1) {
21
+ throw new SandboxValidationError(`invalid tunnel upstream target: ${target}`);
22
+ }
23
+ const port = Number(target.slice(colon + 1));
24
+ if (!Number.isInteger(port) || port <= 0) {
25
+ throw new SandboxValidationError(`invalid tunnel upstream port: ${target}`);
26
+ }
27
+ return { host: target.slice(0, colon), port };
28
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export interface TunnelSession {
7
+ session_id?: string;
8
+ allocation_id?: string;
9
+ edge_target?: string;
10
+ client_edge_target?: string;
11
+ bound_addr?: string;
12
+ remote_port?: number;
13
+ }
14
+ export interface CreateTunnelSessionResult {
15
+ session: TunnelSession;
16
+ clientToken: string;
17
+ }
18
+ export interface TunnelRuntime {
19
+ sessionId: string;
20
+ clientToken: string;
21
+ boundAddr: string;
22
+ upstream: string;
23
+ proxyPort: number;
24
+ stop(): Promise<void>;
25
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export {};
@@ -0,0 +1,219 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export type Dict<T = unknown> = Record<string, T>;
7
+ export type Command = string | readonly string[];
8
+ export interface ExecOptions {
9
+ env?: Record<string, string>;
10
+ cwd?: string;
11
+ timeoutSeconds?: number;
12
+ user?: string;
13
+ tty?: boolean;
14
+ check?: boolean;
15
+ leaseTtlSeconds?: number;
16
+ rpcTimeoutMs?: number;
17
+ }
18
+ export interface ExecResult {
19
+ exitCode: number;
20
+ stdout: Buffer;
21
+ stderr: Buffer;
22
+ stdoutTruncated: boolean;
23
+ stderrTruncated: boolean;
24
+ stdoutText(encoding?: BufferEncoding): string;
25
+ stderrText(encoding?: BufferEncoding): string;
26
+ }
27
+ export interface ImageProcessMount {
28
+ sandboxPath: string;
29
+ targetPath: string;
30
+ readonly?: boolean;
31
+ options?: readonly string[];
32
+ }
33
+ export interface VolumeMount {
34
+ name: string;
35
+ target: string;
36
+ readonly?: boolean;
37
+ options?: readonly string[];
38
+ }
39
+ export declare function workspaceMount(path?: string): ImageProcessMount;
40
+ export interface ImageExecOptions extends ExecOptions {
41
+ mounts?: readonly ImageProcessMount[];
42
+ }
43
+ export type ProcessEvent = {
44
+ kind: "ready";
45
+ } | {
46
+ kind: "stdout";
47
+ data: Buffer;
48
+ } | {
49
+ kind: "stderr";
50
+ data: Buffer;
51
+ } | {
52
+ kind: "exit";
53
+ exitCode: number;
54
+ message: string;
55
+ };
56
+ export interface ProcessOptions extends Omit<ExecOptions, "check"> {
57
+ }
58
+ export interface ImageProcessOptions extends ProcessOptions {
59
+ mounts?: readonly ImageProcessMount[];
60
+ }
61
+ export interface ProcessResult {
62
+ exitCode: number;
63
+ message: string;
64
+ }
65
+ export type SandboxFileKind = "file" | "directory" | "symlink" | "other" | "unspecified";
66
+ export interface SandboxFileInfo {
67
+ path: string;
68
+ kind: SandboxFileKind;
69
+ size: number;
70
+ mode: number;
71
+ mtimeNs: number;
72
+ }
73
+ export interface WriteFileOptions {
74
+ createParents?: boolean;
75
+ }
76
+ export interface MkdirOptions {
77
+ parents?: boolean;
78
+ }
79
+ export interface RemoveOptions {
80
+ recursive?: boolean;
81
+ force?: boolean;
82
+ }
83
+ export interface CopyOptions {
84
+ recursive?: boolean;
85
+ overwrite?: boolean;
86
+ }
87
+ export interface MoveOptions {
88
+ overwrite?: boolean;
89
+ }
90
+ export interface ChmodOptions {
91
+ recursive?: boolean;
92
+ }
93
+ export interface TouchOptions {
94
+ create?: boolean;
95
+ mtimeNs?: number;
96
+ }
97
+ export interface UploadDirOptions {
98
+ createParents?: boolean;
99
+ overwrite?: boolean;
100
+ chunkSize?: number;
101
+ rpcTimeoutMs?: number;
102
+ }
103
+ export interface DownloadDirOptions {
104
+ overwrite?: boolean;
105
+ chunkSize?: number;
106
+ rpcTimeoutMs?: number;
107
+ }
108
+ export interface UploadArchiveOptions {
109
+ createParents?: boolean;
110
+ overwrite?: boolean;
111
+ leaseTtlSeconds?: number;
112
+ rpcTimeoutMs?: number;
113
+ }
114
+ export interface DownloadArchiveOptions {
115
+ leaseTtlSeconds?: number;
116
+ rpcTimeoutMs?: number;
117
+ }
118
+ export interface TunnelOptions {
119
+ upstream: string;
120
+ proxyPort?: number;
121
+ ttlSeconds?: number;
122
+ readyTimeoutMs?: number;
123
+ renewEveryMs?: number;
124
+ connector?: TunnelConnectorOptions;
125
+ }
126
+ export interface TunnelConnectorOptions {
127
+ pingIntervalMs?: number;
128
+ dialTimeoutMs?: number;
129
+ maxStreams?: number;
130
+ }
131
+ export interface TunnelMetadata {
132
+ sessionId: string;
133
+ boundAddr: string;
134
+ upstream: string;
135
+ proxyPort: number;
136
+ }
137
+ export interface CapabilityDependencyStatus {
138
+ name: string;
139
+ available: boolean;
140
+ reason: string;
141
+ }
142
+ export interface CapabilityProviderStatus {
143
+ name: string;
144
+ state: string;
145
+ available: boolean;
146
+ capabilities: string[];
147
+ backend: string;
148
+ reason: string;
149
+ dependencies: CapabilityDependencyStatus[];
150
+ }
151
+ export interface CapabilityProviderSummary {
152
+ total: number;
153
+ available: number;
154
+ degraded: number;
155
+ unavailable: number;
156
+ }
157
+ export interface CapabilityStatus {
158
+ ready: boolean;
159
+ capabilities: string[];
160
+ providers: CapabilityProviderStatus[];
161
+ providerSummary: CapabilityProviderSummary;
162
+ }
163
+ export interface NodeCallOptions {
164
+ rpcTimeoutMs?: number;
165
+ }
166
+ export interface ComputerUseDependencyStatus {
167
+ name: string;
168
+ available: boolean;
169
+ reason: string;
170
+ }
171
+ export interface ComputerUseStatus {
172
+ available: boolean;
173
+ display: string;
174
+ backend: string;
175
+ reason: string;
176
+ dependencies: ComputerUseDependencyStatus[];
177
+ }
178
+ export interface ComputerUseRegion {
179
+ x: number;
180
+ y: number;
181
+ width: number;
182
+ height: number;
183
+ }
184
+ export interface ComputerUseScreenshot {
185
+ data: Buffer;
186
+ contentType: string;
187
+ }
188
+ export interface ComputerUseScreenshotOptions {
189
+ showCursor?: boolean;
190
+ region?: ComputerUseRegion;
191
+ format?: string;
192
+ quality?: number;
193
+ scale?: number;
194
+ rpcTimeoutMs?: number;
195
+ }
196
+ export interface ComputerUseDisplay {
197
+ display: string;
198
+ backend: string;
199
+ width: number;
200
+ height: number;
201
+ }
202
+ export interface ComputerUseMouseOptions {
203
+ action?: string;
204
+ x?: number;
205
+ y?: number;
206
+ toX?: number;
207
+ toY?: number;
208
+ button?: string;
209
+ direction?: string;
210
+ amount?: number;
211
+ rpcTimeoutMs?: number;
212
+ }
213
+ export interface ComputerUseKeyboardOptions {
214
+ text?: string;
215
+ key?: string;
216
+ keys?: readonly string[];
217
+ delayMs?: number;
218
+ rpcTimeoutMs?: number;
219
+ }
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export function workspaceMount(path = "/workspace") {
7
+ return { sandboxPath: path, targetPath: path };
8
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Command } from "./types.js";
7
+ export declare function required(name: string, value: string | undefined | null): string;
8
+ export declare function nonEmptyPath(path: string): string;
9
+ export declare function normalizeCommand(command: Command): string[];
10
+ export declare function positiveNumber(name: string, value: number | undefined): number | undefined;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { SandboxValidationError } from "./errors/index.js";
7
+ export function required(name, value) {
8
+ if (value === undefined || value === null || value.length === 0) {
9
+ throw new SandboxValidationError(`${name} is required`);
10
+ }
11
+ return value;
12
+ }
13
+ export function nonEmptyPath(path) {
14
+ if (path.length === 0) {
15
+ throw new SandboxValidationError("path is required");
16
+ }
17
+ return path;
18
+ }
19
+ export function normalizeCommand(command) {
20
+ if (typeof command === "string") {
21
+ if (command.length === 0) {
22
+ throw new SandboxValidationError("command is required");
23
+ }
24
+ return ["/bin/sh", "-lc", command];
25
+ }
26
+ const argv = [...command];
27
+ if (argv.length === 0 || argv.some((part) => part.length === 0)) {
28
+ throw new SandboxValidationError("command argv must contain non-empty strings");
29
+ }
30
+ return argv;
31
+ }
32
+ export function positiveNumber(name, value) {
33
+ if (value !== undefined && value < 0) {
34
+ throw new SandboxValidationError(`${name} must be non-negative`);
35
+ }
36
+ return value;
37
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export declare const AXERN_VERSION = "0.2.0";
7
+ export declare function platformName(): string;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 cofy-x
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export const AXERN_VERSION = "0.2.0-bootstrap.0";
7
+ export function platformName() {
8
+ return "axern";
9
+ }
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@cofy-x/axern-sdk",
3
+ "version": "0.2.0-bootstrap.0",
4
+ "description": "TypeScript SDK for Axern agentic infrastructure and isolated sandboxes",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/cofy-x/axern.git",
9
+ "directory": "sdk/typescript"
10
+ },
11
+ "homepage": "https://axern.cofy-x.space/sdk/typescript/",
12
+ "bugs": {
13
+ "url": "https://github.com/cofy-x/axern/issues"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "type": "module",
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "dist/*.d.ts",
23
+ "dist/*.js",
24
+ "dist/client",
25
+ "dist/config",
26
+ "dist/errors",
27
+ "dist/generated",
28
+ "dist/node",
29
+ "dist/proto",
30
+ "dist/sandbox",
31
+ "dist/tunnel",
32
+ "README.md"
33
+ ],
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js"
38
+ }
39
+ },
40
+ "scripts": {
41
+ "build": "tsc -p tsconfig.json && node scripts/copy-proto.mjs",
42
+ "test": "tsx --test tests/*.test.ts",
43
+ "lint": "tsc --noEmit -p tsconfig.json",
44
+ "pack:dry-run": "node scripts/clean-dist.mjs && pnpm run build && npm pack --dry-run --json",
45
+ "smoke:local": "pnpm run build && node dist/smoke/local.js",
46
+ "smoke:tunnel": "pnpm run build && node dist/smoke/tunnel.js"
47
+ },
48
+ "dependencies": {
49
+ "@grpc/grpc-js": "^1.14.4",
50
+ "@grpc/proto-loader": "^0.8.0",
51
+ "tar-stream": "^3.2.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^25.6.0",
55
+ "@types/tar-stream": "^3.1.4"
56
+ }
57
+ }