tokenslim 0.2.8 → 0.3.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.
package/README.md CHANGED
@@ -24,7 +24,7 @@ You also need the TokenSlim server running. Two easy options:
24
24
  ```bash
25
25
  # Option A — install the Rust CLI globally
26
26
  cargo install tokenslim
27
- tokenslim serve --port 10086
27
+ TOKENSLIM_PORT=10086 tokenslim-server
28
28
 
29
29
  # Option B — Docker
30
30
  docker run -d -p 10086:10086 ghcr.io/nuoyazhizhou/tokenslim:latest
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenslim",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "Node.js / TypeScript SDK for TokenSlim — REST client for compressing LLM inputs (also ships the `tokenslim` / `tokenslim-server` binaries for one-stop install).",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,6 +21,7 @@
21
21
  "clean": "rimraf dist",
22
22
  "prepublishOnly": "npm run clean && npm run build",
23
23
  "postinstall": "node scripts/postinstall.js",
24
+ "preuninstall": "node scripts/preuninstall.js",
24
25
  "test": "node --test dist/__tests__/*.test.js"
25
26
  },
26
27
  "keywords": [
@@ -47,12 +48,12 @@
47
48
  "node": ">=18.0.0"
48
49
  },
49
50
  "optionalDependencies": {
50
- "@tokenslim/cli-binary-linux-x64-gnu": "0.2.8",
51
- "@tokenslim/cli-binary-linux-arm64-gnu": "0.2.8",
52
- "@tokenslim/cli-binary-darwin-x64": "0.2.8",
53
- "@tokenslim/cli-binary-darwin-arm64": "0.2.8",
54
- "@tokenslim/cli-binary-windows-x64": "0.2.8",
55
- "@tokenslim/cli-binary-windows-arm64": "0.2.8"
51
+ "@tokenslim/cli-binary-linux-x64-gnu": "0.3.0",
52
+ "@tokenslim/cli-binary-linux-arm64-gnu": "0.3.0",
53
+ "@tokenslim/cli-binary-darwin-x64": "0.3.0",
54
+ "@tokenslim/cli-binary-darwin-arm64": "0.3.0",
55
+ "@tokenslim/cli-binary-windows-x64": "0.3.0",
56
+ "@tokenslim/cli-binary-windows-arm64": "0.3.0"
56
57
  },
57
58
  "devDependencies": {
58
59
  "typescript": "^5.4.0",
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ // packages/sdk-nodejs/scripts/preuninstall.js
3
+ //
4
+ // npm `preuninstall` hook. Runs before `npm uninstall -g tokenslim`.
5
+ // Removes the shell hook block from PowerShell/Bash profile so that
6
+ // the `function npm { tokenslim run npm @args }` wrapper doesn't
7
+ // break after the binary is gone.
8
+ //
9
+ // Best-effort: never fails npm uninstall. If hook removal fails, we
10
+ // print a hint for the user to clean up manually.
11
+
12
+ const { execFileSync } = require("node:child_process");
13
+ const path = require("node:path");
14
+
15
+ function info(msg) {
16
+ process.stdout.write(`[tokenslim/preuninstall] ${msg}\n`);
17
+ }
18
+
19
+ function warn(msg) {
20
+ process.stderr.write(`[tokenslim/preuninstall] WARN: ${msg}\n`);
21
+ }
22
+
23
+ try {
24
+ // 调用 bin/tokenslim.js 包装器,它会找到原生二进制并转发
25
+ const wrapper = path.join(__dirname, "..", "bin", "tokenslim.js");
26
+ info("removing shell hooks from profile...");
27
+ execFileSync(process.execPath, [wrapper, "hooks", "uninstall"], {
28
+ stdio: "inherit",
29
+ timeout: 15000,
30
+ });
31
+ info("shell hooks removed.");
32
+ } catch (e) {
33
+ warn(`failed to remove shell hooks: ${e.message}`);
34
+ warn(
35
+ `please manually remove the "# >>> tokenslim hook >>>" block from your shell profile.`,
36
+ );
37
+ // 永不因 hook 清理失败而中断 npm uninstall
38
+ process.exit(0);
39
+ }