twin3-sdk 0.2.11-pre-alpha → 0.2.12-pre-alpha
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 +7 -7
- package/js/local-memory.js +64 -0
- package/local-memory.d.ts +22 -0
- package/package.json +8 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Twin3 SDK (`twin3-sdk`)
|
|
2
2
|
> **The Universal Capability Motherboard for Autonomous AI Agents & Self-Sovereign Humans**
|
|
3
3
|
|
|
4
|
-
[English](README.md) | [
|
|
4
|
+
[English](README.md) | [Traditional Chinese](README_ZH.md) | [GitHub: twin3-team/twin3-sdk](https://github.com/twin3-team/twin3-sdk)
|
|
5
5
|
|
|
6
6
|
[](https://python.org)
|
|
7
7
|
[](#the-seven-layer-symbiotic-architecture)
|
|
@@ -103,22 +103,22 @@ pip install -e /path/to/twin3-sdk
|
|
|
103
103
|
* Any protocol or algorithm improvement in `twin3-sdk` is reflected in both applications in **0 milliseconds**.
|
|
104
104
|
|
|
105
105
|
#### 2. Production Distribution
|
|
106
|
-
|
|
106
|
+
`v0.2.12-pre-alpha` is the current release candidate: `0.2.12-pre-alpha` for npm and `0.2.12a0` for PyPI. Publication is pending. Consumers must pin the exact released version and lock its registry integrity; never use a mutable range for a cryptographic protocol dependency. This release stays pre-alpha. Marketplace or sales copy may offer it for evaluation; it is not a stable release, and the npm dist-tag is `next`, not `latest`.
|
|
107
107
|
|
|
108
108
|
`package.json` `engines` sets Node.js to `>=18` and does not set an npm engine. Any npm that can install a tarball can consume the package. Packing this repository was checked with npm 10 or newer; the stricter npm version in the release runbook applies only to Trusted Publishing.
|
|
109
109
|
|
|
110
|
-
After
|
|
110
|
+
After publication, install the exact released version from the registry:
|
|
111
111
|
|
|
112
112
|
```bash
|
|
113
|
-
npm install twin3-sdk@0.2.
|
|
114
|
-
pip install twin3-sdk==0.2.
|
|
113
|
+
npm install twin3-sdk@0.2.12-pre-alpha
|
|
114
|
+
pip install twin3-sdk==0.2.12a0
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
For local evaluation, you can also use the packed npm tarball. Do not install from a git URL or a version range:
|
|
118
118
|
|
|
119
119
|
```bash
|
|
120
120
|
npm pack --ignore-scripts
|
|
121
|
-
npm install ./twin3-sdk-0.2.
|
|
121
|
+
npm install ./twin3-sdk-0.2.12-pre-alpha.tgz
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
---
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { spawn } = require("node:child_process");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const fs = require("node:fs");
|
|
6
|
+
|
|
7
|
+
function requiredText(value, limit = 1000) {
|
|
8
|
+
if (typeof value !== "string" || !value.trim() || value.length > limit || value.includes("\0")) throw new TypeError("local_memory_option_invalid");
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function startLocalMemory(options) {
|
|
13
|
+
if (!options || typeof options !== "object") throw new TypeError("local_memory_options_required");
|
|
14
|
+
const executable = requiredText(options.pythonExecutable);
|
|
15
|
+
const databasePath = requiredText(options.databasePath);
|
|
16
|
+
const directory = path.dirname(databasePath);
|
|
17
|
+
if (!path.isAbsolute(executable) || !path.isAbsolute(databasePath)) throw new TypeError("local_memory_absolute_path_required");
|
|
18
|
+
if (!["human", "enterprise"].includes(options.namespace)) throw new TypeError("local_memory_namespace_invalid");
|
|
19
|
+
const subject = requiredText(options.subject, 200);
|
|
20
|
+
const ontology = requiredText(options.ontology, 200);
|
|
21
|
+
if (!Array.isArray(options.dimensions) || !options.dimensions.length || options.dimensions.some(value => typeof value !== "string" || !value || value.includes(","))) throw new TypeError("local_memory_dimensions_invalid");
|
|
22
|
+
const port = options.port ?? 0;
|
|
23
|
+
if (!Number.isSafeInteger(port) || port < 0 || port > 65535) throw new TypeError("local_memory_port_invalid");
|
|
24
|
+
const args = ["-I", "-m", "twin3.memory.runtime", "--database", databasePath, "--subject", subject, "--namespace", options.namespace, "--ontology", ontology, "--dimensions", options.dimensions.join(","), "--port", String(port)];
|
|
25
|
+
if (options.model) args.push("--model", requiredText(options.model, 200));
|
|
26
|
+
if (options.embeddingModel) args.push("--embedding-model", requiredText(options.embeddingModel, 200));
|
|
27
|
+
if (options.modelEndpoint) args.push("--model-endpoint", requiredText(options.modelEndpoint, 200));
|
|
28
|
+
const child = spawn(executable, args, { shell: false, stdio: ["ignore", "pipe", "pipe"] });
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
let stdout = "";
|
|
31
|
+
let settled = false;
|
|
32
|
+
const timer = setTimeout(() => fail("local_memory_start_timeout"), 15000);
|
|
33
|
+
function fail(code) {
|
|
34
|
+
if (settled) return;
|
|
35
|
+
settled = true;
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
child.kill("SIGINT");
|
|
38
|
+
reject(new Error(code));
|
|
39
|
+
}
|
|
40
|
+
child.stderr.on("data", () => {});
|
|
41
|
+
child.on("error", () => fail("local_memory_runtime_unavailable"));
|
|
42
|
+
child.on("exit", () => fail("local_memory_runtime_unavailable"));
|
|
43
|
+
child.stdout.on("data", chunk => {
|
|
44
|
+
if (settled) return;
|
|
45
|
+
stdout += chunk.toString("utf8");
|
|
46
|
+
if (stdout.length > 16384) return fail("local_memory_start_invalid");
|
|
47
|
+
if (!stdout.includes("\n")) return;
|
|
48
|
+
try {
|
|
49
|
+
const result = JSON.parse(stdout.split("\n")[0]);
|
|
50
|
+
const url = new URL(result.url);
|
|
51
|
+
if (result.capability !== "memory.local-v1" || result.identity_assurance !== "local_workspace_only" || url.protocol !== "http:" || url.hostname !== "127.0.0.1" || !url.port || url.pathname !== "/" || url.search || url.hash || url.username || url.password || typeof result.token_file !== "string" || path.dirname(fs.realpathSync(result.token_file)) !== fs.realpathSync(directory) || path.basename(result.token_file) !== `session-${url.port}.token`) return fail("local_memory_start_invalid");
|
|
52
|
+
settled = true;
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
child.stdout.removeAllListeners("data");
|
|
55
|
+
child.stdout.resume();
|
|
56
|
+
resolve({ url: result.url, tokenFile: result.token_file, identityAssurance: result.identity_assurance, process: child, stop: () => child.kill("SIGINT") });
|
|
57
|
+
} catch {
|
|
58
|
+
fail("local_memory_start_invalid");
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { startLocalMemory };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface LocalMemoryOptions {
|
|
2
|
+
pythonExecutable: string;
|
|
3
|
+
databasePath: string;
|
|
4
|
+
namespace: "enterprise" | "human";
|
|
5
|
+
subject: string;
|
|
6
|
+
ontology: string;
|
|
7
|
+
dimensions: string[];
|
|
8
|
+
port?: number;
|
|
9
|
+
model?: string;
|
|
10
|
+
embeddingModel?: string;
|
|
11
|
+
modelEndpoint?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface LocalMemoryProcess {
|
|
15
|
+
url: string;
|
|
16
|
+
tokenFile: string;
|
|
17
|
+
identityAssurance: "local_workspace_only";
|
|
18
|
+
process: import("node:child_process").ChildProcess;
|
|
19
|
+
stop(): boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function startLocalMemory(options: LocalMemoryOptions): Promise<LocalMemoryProcess>;
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twin3-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12-pre-alpha",
|
|
4
4
|
"description": "Universal Capability Motherboard for Autonomous AI Agents and Self-Sovereign Humans (JS/Node runtime)",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./js/index.js",
|
|
7
7
|
"types": "./index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
+
"./local-memory": {
|
|
10
|
+
"types": "./local-memory.d.ts",
|
|
11
|
+
"require": "./js/local-memory.js",
|
|
12
|
+
"default": "./js/local-memory.js"
|
|
13
|
+
},
|
|
9
14
|
".": {
|
|
10
15
|
"types": "./index.d.ts",
|
|
11
16
|
"require": "./js/index.js",
|
|
@@ -19,6 +24,8 @@
|
|
|
19
24
|
"./package.json": "./package.json"
|
|
20
25
|
},
|
|
21
26
|
"files": [
|
|
27
|
+
"js/local-memory.js",
|
|
28
|
+
"local-memory.d.ts",
|
|
22
29
|
"js/index.js",
|
|
23
30
|
"js/comm/counterparty.js",
|
|
24
31
|
"js/state.js",
|