oh-langfuse 0.1.13 → 0.1.14
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 +15 -0
- package/bin/cli.js +20 -8
- package/package.json +1 -1
- package/scripts/opencode-langfuse-check.mjs +16 -0
- package/scripts/opencode-langfuse-setup.mjs +23 -4
- package/scripts/wsl-utils.mjs +39 -0
package/README.md
CHANGED
|
@@ -104,6 +104,21 @@ npx oh-langfuse@latest check codex
|
|
|
104
104
|
`launch-opencode-langfuse.sh`,用于在 shell 环境变量未生效时显式带
|
|
105
105
|
Langfuse 配置启动 OpenCode。
|
|
106
106
|
|
|
107
|
+
如果你在 Windows 里执行安装命令、但实际在 WSL 里运行 OpenCode,请使用
|
|
108
|
+
`--wsl` 将配置写入 WSL 的 `$HOME/.config/opencode`,而不是 Windows 的
|
|
109
|
+
`C:\Users\<you>\.config\opencode`:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npx oh-langfuse@latest setup opencode --wsl --userId=h00613222
|
|
113
|
+
npx oh-langfuse@latest check opencode --wsl
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
指定发行版时可以使用:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npx oh-langfuse@latest setup opencode --wsl=Ubuntu --userId=h00613222
|
|
120
|
+
```
|
|
121
|
+
|
|
107
122
|
### Codex
|
|
108
123
|
|
|
109
124
|
安装 `codex_langfuse_notify.py`,创建 `~/.codex/langfuse-venv`,安装 Python
|
package/bin/cli.js
CHANGED
|
@@ -492,6 +492,13 @@ function commonLangfuseArgs(config) {
|
|
|
492
492
|
function optionalInstallerArgs(options) {
|
|
493
493
|
return [...(hasValue(options.pipIndexUrl) ? [`--pipIndexUrl=${options.pipIndexUrl}`] : [])];
|
|
494
494
|
}
|
|
495
|
+
|
|
496
|
+
function opencodePlatformArgs(options) {
|
|
497
|
+
return [
|
|
498
|
+
...(options.wsl ? [typeof options.wsl === "string" ? `--wsl=${options.wsl}` : "--wsl"] : []),
|
|
499
|
+
...(hasValue(options.wslDistro) ? [`--wslDistro=${options.wslDistro}`] : [])
|
|
500
|
+
];
|
|
501
|
+
}
|
|
495
502
|
|
|
496
503
|
async function confirmAction(rl, title, rows, options) {
|
|
497
504
|
clearScreen();
|
|
@@ -538,6 +545,7 @@ async function setupOpenCode(rl, options) {
|
|
|
538
545
|
const args = [
|
|
539
546
|
...commonLangfuseArgs(config),
|
|
540
547
|
...(hasValue(options.npmRegistry) ? [`--npmRegistry=${options.npmRegistry}`] : []),
|
|
548
|
+
...opencodePlatformArgs(options),
|
|
541
549
|
...(!setEnv ? ["--no-set-env"] : []),
|
|
542
550
|
...(!installPlugin ? ["--skip-plugin-install"] : []),
|
|
543
551
|
...(hasValue(cliPath) ? [`--cmd=${cliPath}`] : [])
|
|
@@ -548,9 +556,10 @@ async function setupOpenCode(rl, options) {
|
|
|
548
556
|
[
|
|
549
557
|
labelValue("User ID", config.userId || "<none>", config.userId ? t.teal : t.muted),
|
|
550
558
|
labelValue("User env vars", setEnv ? "write" : "skip", setEnv ? t.teal : t.gold),
|
|
551
|
-
labelValue("Plugin install", installPlugin ? "install/update" : "skip", installPlugin ? t.teal : t.gold),
|
|
552
|
-
labelValue("CLI path", cliPath || "auto-detect", t.blue),
|
|
553
|
-
labelValue("
|
|
559
|
+
labelValue("Plugin install", installPlugin ? "install/update" : "skip", installPlugin ? t.teal : t.gold),
|
|
560
|
+
labelValue("CLI path", cliPath || "auto-detect", t.blue),
|
|
561
|
+
labelValue("Target runtime", options.wsl ? `WSL${typeof options.wsl === "string" ? ` (${options.wsl})` : ""}` : "current OS", t.violet),
|
|
562
|
+
labelValue("Config file", "~/.config/opencode/opencode.json", t.violet)
|
|
554
563
|
],
|
|
555
564
|
options
|
|
556
565
|
);
|
|
@@ -588,11 +597,11 @@ function checkClaude(options, { clear = true } = {}) {
|
|
|
588
597
|
return runNodeScript("langfuse-check.mjs", [], options);
|
|
589
598
|
}
|
|
590
599
|
|
|
591
|
-
function checkOpenCode(options, { clear = true } = {}) {
|
|
592
|
-
if (clear) clearScreen();
|
|
593
|
-
renderBrand(options);
|
|
594
|
-
return runNodeScript("opencode-langfuse-check.mjs",
|
|
595
|
-
}
|
|
600
|
+
function checkOpenCode(options, { clear = true } = {}) {
|
|
601
|
+
if (clear) clearScreen();
|
|
602
|
+
renderBrand(options);
|
|
603
|
+
return runNodeScript("opencode-langfuse-check.mjs", opencodePlatformArgs(options), options);
|
|
604
|
+
}
|
|
596
605
|
|
|
597
606
|
function checkCodex(options, { clear = true } = {}) {
|
|
598
607
|
if (clear) clearScreen();
|
|
@@ -704,6 +713,7 @@ function printHelp() {
|
|
|
704
713
|
]);
|
|
705
714
|
renderSection("Options", [
|
|
706
715
|
`${paint("--dry-run", t.gold)} Preview actions without writing files or installing packages.`,
|
|
716
|
+
`${paint("--wsl[=DISTRO]", t.gold)} Configure/check OpenCode inside WSL from Windows.`,
|
|
707
717
|
`${paint("--npmRegistry=URL", t.gold)} Use a specific npm registry when installing the OpenCode plugin.`,
|
|
708
718
|
`${paint("--pipIndexUrl=URL", t.gold)} Use a specific pip index for Python Langfuse installs.`,
|
|
709
719
|
`${paint("--help", t.gold)} Show this help.`
|
|
@@ -714,6 +724,8 @@ async function main() {
|
|
|
714
724
|
const args = parseArgs(process.argv.slice(2));
|
|
715
725
|
const options = {
|
|
716
726
|
dryRun: !!args["dry-run"],
|
|
727
|
+
wsl: args.wsl || !!(args.wslDistro || args["wsl-distro"]),
|
|
728
|
+
wslDistro: args.wslDistro || args["wsl-distro"] || "",
|
|
717
729
|
npmRegistry: args.npmRegistry || "",
|
|
718
730
|
pipIndexUrl: args.pipIndexUrl || ""
|
|
719
731
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
|
+
import { runOhLangfuseInWsl, shouldRunInWsl } from "./wsl-utils.mjs";
|
|
5
|
+
|
|
6
|
+
function parseArgs(argv) {
|
|
7
|
+
const args = {};
|
|
8
|
+
for (const raw of argv) {
|
|
9
|
+
if (!raw.startsWith("--")) continue;
|
|
10
|
+
const eq = raw.indexOf("=");
|
|
11
|
+
if (eq === -1) args[raw.slice(2)] = true;
|
|
12
|
+
else args[raw.slice(2, eq)] = raw.slice(eq + 1);
|
|
13
|
+
}
|
|
14
|
+
return args;
|
|
15
|
+
}
|
|
4
16
|
|
|
5
17
|
function stripBom(s) {
|
|
6
18
|
if (typeof s !== "string" || s.length === 0) return s;
|
|
@@ -190,6 +202,10 @@ function main() {
|
|
|
190
202
|
}
|
|
191
203
|
|
|
192
204
|
try {
|
|
205
|
+
const args = parseArgs(process.argv.slice(2));
|
|
206
|
+
if (shouldRunInWsl(args)) {
|
|
207
|
+
process.exit(runOhLangfuseInWsl(args, ["npx", "-y", "oh-langfuse@latest", "check", "opencode"]));
|
|
208
|
+
}
|
|
193
209
|
main();
|
|
194
210
|
} catch (e) {
|
|
195
211
|
console.error(e?.message || String(e));
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
4
|
import { spawn, spawnSync } from "node:child_process";
|
|
5
|
+
import { runOhLangfuseInWsl, shouldRunInWsl } from "./wsl-utils.mjs";
|
|
5
6
|
|
|
6
7
|
function parseArgs(argv) {
|
|
7
8
|
const args = {};
|
|
@@ -420,8 +421,26 @@ function updateShellConfig({ publicKey, secretKey, baseUrl, userId }) {
|
|
|
420
421
|
}
|
|
421
422
|
|
|
422
423
|
async function main() {
|
|
423
|
-
const args = parseArgs(process.argv.slice(2));
|
|
424
|
-
|
|
424
|
+
const args = parseArgs(process.argv.slice(2));
|
|
425
|
+
if (shouldRunInWsl(args)) {
|
|
426
|
+
const forwarded = [
|
|
427
|
+
"npx",
|
|
428
|
+
"-y",
|
|
429
|
+
"oh-langfuse@latest",
|
|
430
|
+
"setup",
|
|
431
|
+
"opencode",
|
|
432
|
+
...(args.langfuseBaseUrl ? [`--langfuseBaseUrl=${args.langfuseBaseUrl}`] : []),
|
|
433
|
+
...(args.publicKey ? [`--publicKey=${args.publicKey}`] : []),
|
|
434
|
+
...(args.secretKey ? [`--secretKey=${args.secretKey}`] : []),
|
|
435
|
+
...(args.userId || args.userid ? [`--userId=${args.userId || args.userid}`] : []),
|
|
436
|
+
...(args.npmRegistry ? [`--npmRegistry=${args.npmRegistry}`] : []),
|
|
437
|
+
...(args["no-set-env"] ? ["--no-set-env"] : []),
|
|
438
|
+
...(args["skip-plugin-install"] ? ["--skip-plugin-install"] : [])
|
|
439
|
+
];
|
|
440
|
+
process.exit(runOhLangfuseInWsl(args, forwarded));
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const setEnv = !args["no-set-env"];
|
|
425
444
|
const skipPluginInstall =
|
|
426
445
|
!!(args["skip-plugin-install"] || args.skipNpmInstall || process.env.OPENCODE_SKIP_PLUGIN_INSTALL);
|
|
427
446
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
export function shouldRunInWsl(args) {
|
|
4
|
+
return process.platform === "win32" && !!(args.wsl || args.wslDistro || args["wsl-distro"]);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function wslDistro(args) {
|
|
8
|
+
if (typeof args.wsl === "string" && args.wsl.trim() && args.wsl.trim().toLowerCase() !== "true") {
|
|
9
|
+
return args.wsl.trim();
|
|
10
|
+
}
|
|
11
|
+
if (typeof args.wslDistro === "string" && args.wslDistro.trim()) return args.wslDistro.trim();
|
|
12
|
+
if (typeof args["wsl-distro"] === "string" && args["wsl-distro"].trim()) return args["wsl-distro"].trim();
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function shQuote(value) {
|
|
17
|
+
return `'${String(value).replace(/'/g, "'\"'\"'")}'`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function runOhLangfuseInWsl(args, ohLangfuseArgs) {
|
|
21
|
+
const distro = wslDistro(args);
|
|
22
|
+
const wslArgs = [];
|
|
23
|
+
if (distro) wslArgs.push("-d", distro);
|
|
24
|
+
wslArgs.push("--", "sh", "-lc", ohLangfuseArgs.map(shQuote).join(" "));
|
|
25
|
+
|
|
26
|
+
console.log(
|
|
27
|
+
distro
|
|
28
|
+
? `Forwarding OpenCode Langfuse command to WSL distro: ${distro}`
|
|
29
|
+
: "Forwarding OpenCode Langfuse command to the default WSL distro"
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const r = spawnSync("wsl.exe", wslArgs, { stdio: "inherit", windowsHide: true });
|
|
33
|
+
if (r.error) {
|
|
34
|
+
console.error(r.error.message);
|
|
35
|
+
console.error("WSL is not available from this Windows session. Run the same oh-langfuse command inside WSL instead.");
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
return r.status ?? 1;
|
|
39
|
+
}
|