@sentisec/sdk 1.0.0 → 1.1.1
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/CHANGELOG.md +95 -0
- package/README.md +102 -5
- package/bin/sentisec.js +40 -54
- package/dist/index.cjs +589 -48
- package/dist/index.d.cts +364 -16
- package/dist/index.d.ts +364 -16
- package/dist/index.js +569 -49
- package/package.json +2 -5
- package/scripts/install-binary.js +130 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentisec/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Sentisec TypeScript SDK — cognitive integrity monitoring for autonomous agents. Monitor + wrap(...) for OpenAI / Anthropic agent loops with SSE streaming support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -50,8 +50,6 @@
|
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsup",
|
|
53
|
-
"test": "vitest run",
|
|
54
|
-
"test:watch": "vitest",
|
|
55
53
|
"typecheck": "tsc --noEmit",
|
|
56
54
|
"clean": "rimraf dist",
|
|
57
55
|
"postinstall": "node scripts/install-binary.js",
|
|
@@ -61,7 +59,6 @@
|
|
|
61
59
|
"@types/node": "^20.12.12",
|
|
62
60
|
"rimraf": "^5.0.7",
|
|
63
61
|
"tsup": "^8.3.5",
|
|
64
|
-
"typescript": "^5.6.3"
|
|
65
|
-
"vitest": "^2.1.8"
|
|
62
|
+
"typescript": "^5.6.3"
|
|
66
63
|
}
|
|
67
64
|
}
|
|
@@ -2,20 +2,23 @@
|
|
|
2
2
|
// @sentisec/sdk → scripts/install-binary.js
|
|
3
3
|
// npm postinstall fetcher for the Sentisec CLI native binary.
|
|
4
4
|
//
|
|
5
|
-
// Behavior contract
|
|
6
|
-
// *
|
|
7
|
-
//
|
|
8
|
-
//
|
|
5
|
+
// Behavior contract:
|
|
6
|
+
// * Chooses a Python the CLI is built for, in the one-line installer's
|
|
7
|
+
// order: SENTISEC_PYTHON when set; python3 when its version is
|
|
8
|
+
// supported; else the newest supported python3.<minor> on PATH; else a
|
|
9
|
+
// refusal naming what was found and what is supported.
|
|
10
|
+
// * Downloads the right tarball for the host (platform, arch, python-minor)
|
|
11
|
+
// triple and verifies sha256 against sha256sums.txt (mandatory).
|
|
9
12
|
// * Extracts to node_modules/@sentisec/sdk/native/<platform>/<arch>/<pyminor>/
|
|
10
|
-
// and writes
|
|
13
|
+
// and writes native/<platform>/<arch>/interpreter.json: the chosen
|
|
14
|
+
// interpreter, which bin/sentisec.js runs the CLI with.
|
|
11
15
|
// * Zero external runtime deps. Uses node:https + node:crypto + spawned tar.
|
|
12
16
|
//
|
|
13
17
|
// Soft-fail policy (exit 0, npm install succeeds, library still usable):
|
|
14
18
|
// * SENTISEC_SKIP_POSTINSTALL truthy → dev override
|
|
15
19
|
// * CI && !SENTISEC_NPM_FETCH_IN_CI truthy → CI caches stay clean
|
|
16
20
|
// * unsupported platform / arch → leave SDK as library-only
|
|
17
|
-
// *
|
|
18
|
-
// * python minor not in {3.11, 3.12, 3.13, 3.14} → no binary for their python
|
|
21
|
+
// * no supported Python found → user can install one later
|
|
19
22
|
// * network failure (DNS / timeout / 5xx) → try again next install
|
|
20
23
|
// * tuple missing from latest-versions.json → that cell didn't build
|
|
21
24
|
//
|
|
@@ -25,16 +28,19 @@
|
|
|
25
28
|
import { spawnSync } from "node:child_process";
|
|
26
29
|
import { createHash } from "node:crypto";
|
|
27
30
|
import {
|
|
31
|
+
accessSync,
|
|
28
32
|
chmodSync,
|
|
33
|
+
constants as fsConstants,
|
|
29
34
|
createWriteStream,
|
|
30
35
|
existsSync,
|
|
31
36
|
mkdirSync,
|
|
32
37
|
readFileSync,
|
|
33
38
|
rmSync,
|
|
39
|
+
statSync,
|
|
34
40
|
writeFileSync,
|
|
35
41
|
} from "node:fs";
|
|
36
42
|
import { tmpdir } from "node:os";
|
|
37
|
-
import { dirname, join } from "node:path";
|
|
43
|
+
import { delimiter, dirname, join } from "node:path";
|
|
38
44
|
import { pipeline } from "node:stream/promises";
|
|
39
45
|
import { fileURLToPath, URL } from "node:url";
|
|
40
46
|
import https from "node:https";
|
|
@@ -56,7 +62,19 @@ const SUPPORTED_ARCHES = {
|
|
|
56
62
|
arm64: "arm64",
|
|
57
63
|
x64: "x64",
|
|
58
64
|
};
|
|
59
|
-
|
|
65
|
+
// The Python minors the CLI is built for, newest first. The only place they
|
|
66
|
+
// are written in this package.
|
|
67
|
+
const SUPPORTED_PY_MINORS = ["3.14", "3.13", "3.12", "3.11"];
|
|
68
|
+
const NEWEST_PY = SUPPORTED_PY_MINORS[0];
|
|
69
|
+
const SUPPORTED_RANGE = `${SUPPORTED_PY_MINORS.at(-1)} to ${NEWEST_PY}`;
|
|
70
|
+
|
|
71
|
+
// Read by bin/sentisec.js: { "python": <interpreter path>, "minor": "3.13" }.
|
|
72
|
+
const INTERPRETER_MARKER = "interpreter.json";
|
|
73
|
+
|
|
74
|
+
// The command that re-runs this script, for a global or a project install.
|
|
75
|
+
const REBUILD = `npm rebuild${
|
|
76
|
+
process.env.npm_config_global === "true" ? " -g" : ""
|
|
77
|
+
} @sentisec/sdk`;
|
|
60
78
|
|
|
61
79
|
// Public release mirror. Cloudflare R2 (sentisec-releases bucket, public,
|
|
62
80
|
// served by Pages at https://releases.sentisec.ch). The release-cli.yml
|
|
@@ -77,12 +95,14 @@ const SOFT_FAIL_RECOVERY = [
|
|
|
77
95
|
`${LOG_PREFIX} pipx install sentisec-sdk`,
|
|
78
96
|
].join("\n");
|
|
79
97
|
|
|
98
|
+
/** @param {string} reason @returns {never} */
|
|
80
99
|
function softFail(reason) {
|
|
81
100
|
warn(reason);
|
|
82
101
|
process.stderr.write(SOFT_FAIL_RECOVERY + "\n");
|
|
83
102
|
process.exit(0);
|
|
84
103
|
}
|
|
85
104
|
|
|
105
|
+
/** @param {string} reason @returns {never} */
|
|
86
106
|
function hardFail(reason) {
|
|
87
107
|
warn(`FATAL: ${reason}`);
|
|
88
108
|
process.exit(1);
|
|
@@ -120,38 +140,111 @@ if (!platformName || !archName) {
|
|
|
120
140
|
}
|
|
121
141
|
const platformKey = `${platformName}-${archName}`;
|
|
122
142
|
|
|
123
|
-
// ---
|
|
143
|
+
// --- choose a python -----------------------------------------------------
|
|
144
|
+
|
|
145
|
+
// The first executable file called `name` on PATH, or null.
|
|
146
|
+
function findOnPath(name) {
|
|
147
|
+
for (const dir of (process.env.PATH || "").split(delimiter)) {
|
|
148
|
+
if (!dir) continue;
|
|
149
|
+
const candidate = join(dir, name);
|
|
150
|
+
try {
|
|
151
|
+
if (!statSync(candidate).isFile()) continue;
|
|
152
|
+
accessSync(candidate, fsConstants.X_OK);
|
|
153
|
+
return candidate;
|
|
154
|
+
} catch {
|
|
155
|
+
// not here
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
124
160
|
|
|
125
|
-
|
|
161
|
+
// { minor: "3.13", executable } for an interpreter that answers, else null.
|
|
162
|
+
// `executable` is the interpreter's own sys.executable: the path that keeps
|
|
163
|
+
// naming this version when `python3` later names another one.
|
|
164
|
+
function askPython(path) {
|
|
126
165
|
const result = spawnSync(
|
|
127
|
-
|
|
128
|
-
[
|
|
129
|
-
"-c",
|
|
130
|
-
"import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')",
|
|
131
|
-
],
|
|
166
|
+
path,
|
|
167
|
+
["-c", "import sys; print('%d.%d' % sys.version_info[:2]); print(sys.executable)"],
|
|
132
168
|
{ encoding: "utf8" }
|
|
133
169
|
);
|
|
134
170
|
if (result.error || result.status !== 0) return null;
|
|
135
|
-
|
|
171
|
+
const [minor = "", executable = ""] = result.stdout.trim().split(/\r?\n/);
|
|
172
|
+
if (!/^\d+\.\d+$/.test(minor)) return null;
|
|
173
|
+
return { minor, executable: executable || path };
|
|
136
174
|
}
|
|
137
175
|
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
);
|
|
176
|
+
function pythonInstallHint() {
|
|
177
|
+
if (process.platform === "darwin") return `brew install python@${NEWEST_PY}`;
|
|
178
|
+
if (findOnPath("apt")) return `sudo apt install python${NEWEST_PY}`;
|
|
179
|
+
if (findOnPath("dnf")) return `sudo dnf install python${NEWEST_PY}`;
|
|
180
|
+
if (findOnPath("pacman")) return "sudo pacman -S python";
|
|
181
|
+
return "your distro's package manager";
|
|
145
182
|
}
|
|
146
183
|
|
|
147
|
-
|
|
184
|
+
// { path, minor, executable, why }: `why` is set when the choice is not
|
|
185
|
+
// python3, and says why.
|
|
186
|
+
function choosePython() {
|
|
187
|
+
const override = process.env.SENTISEC_PYTHON;
|
|
188
|
+
if (override) {
|
|
189
|
+
const path = override.includes("/") ? override : findOnPath(override);
|
|
190
|
+
const answer = path ? askPython(path) : null;
|
|
191
|
+
if (!answer) {
|
|
192
|
+
softFail(
|
|
193
|
+
`SENTISEC_PYTHON='${override}' is not a Python that runs. ` +
|
|
194
|
+
`Point it at a Python from ${SUPPORTED_RANGE}, or unset it, then run '${REBUILD}'.`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (!SUPPORTED_PY_MINORS.includes(answer.minor)) {
|
|
198
|
+
softFail(
|
|
199
|
+
`SENTISEC_PYTHON='${override}' is Python ${answer.minor}; the Sentisec CLI ` +
|
|
200
|
+
`is built for Python ${SUPPORTED_RANGE}. Point it at one of those, or unset it, ` +
|
|
201
|
+
`then run '${REBUILD}'.`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return { path, ...answer, why: "set by SENTISEC_PYTHON" };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let found;
|
|
208
|
+
const python3 = findOnPath("python3");
|
|
209
|
+
if (python3) {
|
|
210
|
+
const answer = askPython(python3);
|
|
211
|
+
if (answer && SUPPORTED_PY_MINORS.includes(answer.minor)) {
|
|
212
|
+
return { path: python3, ...answer, why: null };
|
|
213
|
+
}
|
|
214
|
+
found = answer
|
|
215
|
+
? `python3 (${python3}) is Python ${answer.minor}`
|
|
216
|
+
: `python3 (${python3}) did not report its version`;
|
|
217
|
+
} else {
|
|
218
|
+
found = "there is no python3 on PATH";
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
for (const minor of SUPPORTED_PY_MINORS) {
|
|
222
|
+
const path = findOnPath(`python${minor}`);
|
|
223
|
+
if (!path) continue;
|
|
224
|
+
// A shim can carry the name of a version it does not run: ask it.
|
|
225
|
+
const answer = askPython(path);
|
|
226
|
+
if (!answer || answer.minor !== minor) continue;
|
|
227
|
+
return {
|
|
228
|
+
path,
|
|
229
|
+
...answer,
|
|
230
|
+
why: `${found}; the Sentisec CLI is built for Python ${SUPPORTED_RANGE}`,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const tried = SUPPORTED_PY_MINORS.map((minor) => `python${minor}`).join(", ");
|
|
148
235
|
softFail(
|
|
149
|
-
`
|
|
150
|
-
`
|
|
151
|
-
`and
|
|
236
|
+
`No Python the Sentisec CLI can run on: ${found}, and none of ${tried} is on PATH. ` +
|
|
237
|
+
`Supported: Python ${SUPPORTED_RANGE}. Install one ('${pythonInstallHint()}') ` +
|
|
238
|
+
`and run '${REBUILD}', or set SENTISEC_PYTHON=/path/to/python${NEWEST_PY}.`
|
|
152
239
|
);
|
|
153
240
|
}
|
|
154
241
|
|
|
242
|
+
const python = choosePython();
|
|
243
|
+
const pyMinor = python.minor;
|
|
244
|
+
log(
|
|
245
|
+
`Using python: ${python.path} (${pyMinor})${python.why ? ` — ${python.why}` : ""}`
|
|
246
|
+
);
|
|
247
|
+
|
|
155
248
|
// --- resolve CLI release version -----------------------------------------
|
|
156
249
|
//
|
|
157
250
|
// The npm SDK version (e.g., 0.1.0-rc.2) and the CLI release version
|
|
@@ -469,16 +562,22 @@ try {
|
|
|
469
562
|
softFail(`Failed to chmod ${binaryPath}: ${err.message}. CLI not installed.`);
|
|
470
563
|
}
|
|
471
564
|
|
|
472
|
-
//
|
|
565
|
+
// Record the interpreter for bin/sentisec.js, which runs the CLI with it
|
|
566
|
+
// rather than with whatever python3 is at run time.
|
|
473
567
|
try {
|
|
474
|
-
writeFileSync(
|
|
568
|
+
writeFileSync(
|
|
569
|
+
join(installRoot, INTERPRETER_MARKER),
|
|
570
|
+
JSON.stringify({ python: python.executable, minor: pyMinor }) + "\n",
|
|
571
|
+
"utf8"
|
|
572
|
+
);
|
|
475
573
|
} catch (err) {
|
|
476
574
|
cleanupStaging();
|
|
477
|
-
softFail(`Failed to write
|
|
575
|
+
softFail(`Failed to write ${INTERPRETER_MARKER}: ${err.message}. CLI not installed.`);
|
|
478
576
|
}
|
|
479
577
|
|
|
480
578
|
cleanupStaging();
|
|
481
579
|
log(
|
|
482
580
|
`CLI binary installed: native/${platformName}/${archName}/${pyMinor}/sentisec (py${pyMinor})`
|
|
483
581
|
);
|
|
582
|
+
log(`sentisec will run on ${python.executable}`);
|
|
484
583
|
process.exit(0);
|