@agent-assembly/sdk 0.0.1-alpha.3 → 0.0.1-alpha.4
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/package.json +9 -8
- package/scripts/postinstall.mjs +137 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-assembly/sdk",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.4",
|
|
4
4
|
"description": "TypeScript SDK for Agent Assembly",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/ai-agent-assembly/node-sdk.git"
|
|
14
14
|
},
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/ai-agent-assembly/node-sdk/issues"
|
|
17
17
|
},
|
|
18
|
-
"homepage": "https://github.com/
|
|
18
|
+
"homepage": "https://github.com/ai-agent-assembly/node-sdk#readme",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
21
|
"import": "./dist/esm/index.js",
|
|
@@ -59,13 +59,14 @@
|
|
|
59
59
|
"nodejs"
|
|
60
60
|
],
|
|
61
61
|
"optionalDependencies": {
|
|
62
|
-
"@agent-assembly/runtime-darwin-arm64": "0.0.1-alpha.
|
|
63
|
-
"@agent-assembly/runtime-darwin-x64": "0.0.1-alpha.
|
|
64
|
-
"@agent-assembly/runtime-linux-
|
|
65
|
-
"@agent-assembly/runtime-linux-
|
|
62
|
+
"@agent-assembly/runtime-darwin-arm64": "0.0.1-alpha.4",
|
|
63
|
+
"@agent-assembly/runtime-darwin-x64": "0.0.1-alpha.4",
|
|
64
|
+
"@agent-assembly/runtime-linux-arm64": "0.0.1-alpha.4",
|
|
65
|
+
"@agent-assembly/runtime-linux-x64": "0.0.1-alpha.4"
|
|
66
66
|
},
|
|
67
67
|
"files": [
|
|
68
68
|
"dist/",
|
|
69
|
+
"scripts/postinstall.mjs",
|
|
69
70
|
"native/aa-ffi-node/*.node",
|
|
70
71
|
"native/aa-ffi-node/index.cjs",
|
|
71
72
|
"native/aa-ffi-node/index.d.ts",
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
|
|
6
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
7
|
+
|
|
8
|
+
const SUPPORTED_PLATFORM_KEYS = {
|
|
9
|
+
"darwin-arm64": "darwin-arm64",
|
|
10
|
+
"darwin-x64": "darwin-x64",
|
|
11
|
+
"linux-x64": "linux-x64-gnu",
|
|
12
|
+
"win32-x64": "win32-x64-msvc"
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function detectPlatformKey(platform = process.platform, arch = process.arch) {
|
|
16
|
+
return SUPPORTED_PLATFORM_KEYS[`${platform}-${arch}`] ?? null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function resolveBinaryPackageName(platform = process.platform, arch = process.arch) {
|
|
20
|
+
const platformKey = detectPlatformKey(platform, arch);
|
|
21
|
+
|
|
22
|
+
if (!platformKey) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return `@agent-assembly/${platformKey}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function findFirstNodeBinary(dirPath) {
|
|
30
|
+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
31
|
+
|
|
32
|
+
for (const entry of entries) {
|
|
33
|
+
const entryPath = path.join(dirPath, entry.name);
|
|
34
|
+
|
|
35
|
+
if (entry.isDirectory()) {
|
|
36
|
+
const nested = findFirstNodeBinary(entryPath);
|
|
37
|
+
if (nested) {
|
|
38
|
+
return nested;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (entry.isFile() && entry.name.endsWith(".node")) {
|
|
43
|
+
return entryPath;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function resolveBinaryFromPackage(
|
|
51
|
+
packageName,
|
|
52
|
+
options = {}
|
|
53
|
+
) {
|
|
54
|
+
const { cwd = process.cwd() } = options;
|
|
55
|
+
|
|
56
|
+
const packageJsonPath = requireFromHere.resolve(`${packageName}/package.json`, {
|
|
57
|
+
paths: [cwd]
|
|
58
|
+
});
|
|
59
|
+
const packageDir = path.dirname(packageJsonPath);
|
|
60
|
+
const binaryPath = findFirstNodeBinary(packageDir);
|
|
61
|
+
|
|
62
|
+
if (!binaryPath) {
|
|
63
|
+
throw new Error(`No .node file found in ${packageName}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return binaryPath;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function selectBinaryForCurrentPlatform(options = {}) {
|
|
70
|
+
const {
|
|
71
|
+
platform = process.platform,
|
|
72
|
+
arch = process.arch,
|
|
73
|
+
cwd = process.cwd(),
|
|
74
|
+
targetNativeDir = path.resolve(cwd, "native/aa-ffi-node"),
|
|
75
|
+
logger = console
|
|
76
|
+
} = options;
|
|
77
|
+
|
|
78
|
+
const packageName = resolveBinaryPackageName(platform, arch);
|
|
79
|
+
|
|
80
|
+
if (!packageName) {
|
|
81
|
+
logger.warn(
|
|
82
|
+
`[agent-assembly] Unsupported platform: ${platform}-${arch}; skipping binary selection.`
|
|
83
|
+
);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const sourceBinaryPath = resolveBinaryFromPackage(packageName, { cwd });
|
|
88
|
+
const targetBinaryPath = path.join(targetNativeDir, "index.node");
|
|
89
|
+
|
|
90
|
+
fs.mkdirSync(targetNativeDir, { recursive: true });
|
|
91
|
+
fs.copyFileSync(sourceBinaryPath, targetBinaryPath);
|
|
92
|
+
|
|
93
|
+
logger.info(`[agent-assembly] Selected binary package ${packageName}`);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
packageName,
|
|
97
|
+
sourceBinaryPath,
|
|
98
|
+
targetBinaryPath
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function runPostinstall(options = {}) {
|
|
103
|
+
const { logger = console } = options;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
selectBinaryForCurrentPlatform(options);
|
|
107
|
+
return true;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
logger.warn(
|
|
110
|
+
`[agent-assembly] Failed to select native binary: ${error instanceof Error ? error.message : String(error)}`
|
|
111
|
+
);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function isExecutedDirectly(
|
|
117
|
+
moduleUrl = import.meta.url,
|
|
118
|
+
entryPath = process.argv[1]
|
|
119
|
+
) {
|
|
120
|
+
return Boolean(entryPath) && moduleUrl === pathToFileURL(entryPath).href;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function runPostinstallEntrypoint(options = {}) {
|
|
124
|
+
const {
|
|
125
|
+
moduleUrl = import.meta.url,
|
|
126
|
+
entryPath = process.argv[1],
|
|
127
|
+
run = () => runPostinstall(options)
|
|
128
|
+
} = options;
|
|
129
|
+
|
|
130
|
+
if (isExecutedDirectly(moduleUrl, entryPath)) {
|
|
131
|
+
return run();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
runPostinstallEntrypoint();
|