oh-langfuse 0.1.24 → 0.1.25

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 (3) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +46 -19
  3. package/package.json +6 -3
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  `oh-langfuse` 是用于给 Claude Code、OpenCode 和 Codex 配置 Langfuse 追踪的命令行工具。它提供交互式安装向导,也支持 `setup` / `check` 直接命令,方便在用户机器上安装、修复和校验配置。
4
4
 
5
- 当前 npm 版本:`0.1.24`
5
+ 当前 npm 版本:`0.1.25`
6
6
 
7
7
  ## 能做什么
8
8
 
package/bin/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import fs from "node:fs";
3
- import path from "node:path";
4
- import { createInterface } from "node:readline/promises";
5
- import { fileURLToPath } from "node:url";
6
- import { spawnSync } from "node:child_process";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import readline from "readline";
5
+ import { fileURLToPath } from "url";
6
+ import { spawnSync } from "child_process";
7
7
 
8
8
  const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
9
9
  const scriptsDir = path.join(rootDir, "scripts");
@@ -13,6 +13,31 @@ const DEFAULT_LANGFUSE_PUBLIC_KEY = "pk-lf-da0c90a7-6e93-4eb7-bb86-c1047c8d187d"
13
13
  const DEFAULT_LANGFUSE_SECRET_KEY = "sk-lf-0269b85d-bfdc-442c-bfa3-e737954e3315";
14
14
  const USER_ID_PATTERN = /^[a-z](?:\d{8}|wx\d{7})$/;
15
15
  const USER_ID_PATTERN_TEXT = "^[a-z](?:\\d{8}|wx\\d{7})$";
16
+
17
+ function nodeMajorVersion() {
18
+ const raw = process.versions && process.versions.node ? process.versions.node : "0.0.0";
19
+ return Number.parseInt(raw.split(".")[0], 10) || 0;
20
+ }
21
+
22
+ function assertSupportedNode() {
23
+ if (nodeMajorVersion() >= 16) return;
24
+ console.error("oh-langfuse requires Node.js >= 16.");
25
+ console.error(`Current Node.js: ${process.version}`);
26
+ console.error("Please upgrade Node.js, then run: npx oh-langfuse@latest");
27
+ process.exit(1);
28
+ }
29
+
30
+ function createPromptInterface(options) {
31
+ const rl = readline.createInterface(options);
32
+ return {
33
+ question(query) {
34
+ return new Promise((resolve) => rl.question(query, resolve));
35
+ },
36
+ close() {
37
+ rl.close();
38
+ },
39
+ };
40
+ }
16
41
 
17
42
  const colorEnabled = process.stdout.isTTY && process.env.NO_COLOR !== "1";
18
43
  const ansi = (code) => (colorEnabled ? `\x1b[${code}m` : "");
@@ -260,7 +285,7 @@ function runNodeScript(name, args = [], { dryRun = false } = {}) {
260
285
  console.log(paint("Running installer...", t.bold, t.teal));
261
286
  console.log(paint("─".repeat(Math.min(terminalWidth(), 64)), t.panel));
262
287
  const r = spawnSync(process.execPath, [target, ...args], { stdio: "inherit" });
263
- return r.status ?? (r.error ? 1 : 0);
288
+ return r.status != null ? r.status : r.error ? 1 : 0;
264
289
  }
265
290
 
266
291
  async function askText(rl, label, { defaultValue = "", required = false, validate = null, invalidMessage = "" } = {}) {
@@ -294,7 +319,7 @@ async function askYesNo(rl, label, { defaultValue = false } = {}) {
294
319
 
295
320
  function rawKeySeq(raw) {
296
321
  if (Buffer.isBuffer(raw)) return raw.toString("latin1");
297
- return String(raw ?? "");
322
+ return String(raw == null ? "" : raw);
298
323
  }
299
324
 
300
325
  function parseRawKey(raw) {
@@ -680,8 +705,8 @@ async function checkMenu(rl, options) {
680
705
  return claude || opencode || codex;
681
706
  }
682
707
 
683
- async function interactiveMain(options) {
684
- const rl = createInterface({ input: process.stdin, output: process.stdout });
708
+ async function interactiveMain(options) {
709
+ const rl = createPromptInterface({ input: process.stdin, output: process.stdout });
685
710
  try {
686
711
  const action = await askChoice(
687
712
  rl,
@@ -727,9 +752,9 @@ async function setupLangfuseMenu(rl, options) {
727
752
  if (!targets.length) return 0;
728
753
  const config = await collectSharedConfig(rl, options);
729
754
  let code = 0;
730
- if (targets.includes("claude")) code ||= await setupClaude(rl, { ...options, config });
731
- if (targets.includes("opencode")) code ||= await setupOpenCode(rl, { ...options, config });
732
- if (targets.includes("codex")) code ||= await setupCodex(rl, { ...options, config });
755
+ if (targets.includes("claude")) code = code || await setupClaude(rl, { ...options, config });
756
+ if (targets.includes("opencode")) code = code || await setupOpenCode(rl, { ...options, config });
757
+ if (targets.includes("codex")) code = code || await setupCodex(rl, { ...options, config });
733
758
  return code;
734
759
  }
735
760
 
@@ -791,7 +816,7 @@ async function main() {
791
816
 
792
817
  if (!cmd) return await interactiveMain(options);
793
818
 
794
- const rl = createInterface({ input: process.stdin, output: process.stdout });
819
+ const rl = createPromptInterface({ input: process.stdin, output: process.stdout });
795
820
  try {
796
821
  if (cmd === "setup" && target === "claude") return await setupClaude(rl, options);
797
822
  if (cmd === "setup" && target === "opencode") return await setupOpenCode(rl, options);
@@ -815,9 +840,11 @@ async function main() {
815
840
  return 1;
816
841
  }
817
842
 
818
- main()
819
- .then((code) => process.exit(code))
820
- .catch((err) => {
821
- console.error(paint(err?.message || String(err), t.red));
822
- process.exit(1);
823
- });
843
+ assertSupportedNode();
844
+
845
+ main()
846
+ .then((code) => process.exit(code))
847
+ .catch((err) => {
848
+ console.error(paint((err && err.message) || String(err), t.red));
849
+ process.exit(1);
850
+ });
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "oh-langfuse",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "private": false,
5
5
  "type": "module",
6
- "description": "Use npm scripts to configure Claude Code / OpenCode / Codex with Langfuse tracing.",
7
- "bin": {
6
+ "description": "Use npm scripts to configure Claude Code / OpenCode / Codex with Langfuse tracing.",
7
+ "engines": {
8
+ "node": ">=16"
9
+ },
10
+ "bin": {
8
11
  "oh-langfuse": "bin/cli.js",
9
12
  "code-tool-langfuse": "bin/cli.js"
10
13
  },