pi-langfuse 1.3.2 → 1.3.3
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 +6 -7
- package/README_CN.md +6 -7
- package/index.ts +2 -2
- package/package.json +1 -1
- package/src/config.ts +10 -5
- package/src/constants.ts +4 -7
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ Run any `pi` command with the extension loaded. On first run without configurati
|
|
|
78
78
|
2. **Langfuse secret key** — starts with `sk-lf-...`
|
|
79
79
|
3. **Langfuse host** — defaults to `https://cloud.langfuse.com`
|
|
80
80
|
|
|
81
|
-
The extension saves these to
|
|
81
|
+
The extension saves these to `~/.pi/agent/pi-langfuse/config.json`, so package updates and reinstalls do not overwrite your Langfuse credentials.
|
|
82
82
|
|
|
83
83
|
To re-run setup at any time:
|
|
84
84
|
|
|
@@ -86,7 +86,7 @@ To re-run setup at any time:
|
|
|
86
86
|
/langfuse-setup
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
### Method 2: Environment variables
|
|
89
|
+
### Method 2: Environment variables (fallback)
|
|
90
90
|
|
|
91
91
|
Set these before starting Pi:
|
|
92
92
|
|
|
@@ -96,11 +96,11 @@ export LANGFUSE_SECRET_KEY="sk-lf-xxxx"
|
|
|
96
96
|
export LANGFUSE_BASE_URL="https://cloud.langfuse.com" # optional; LANGFUSE_HOST is also supported
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
The
|
|
99
|
+
The saved config file takes precedence. Environment variables are used only when `~/.pi/agent/pi-langfuse/config.json` does not exist or is incomplete, which avoids drift after re-running `/langfuse-setup`.
|
|
100
100
|
|
|
101
|
-
### Method 3:
|
|
101
|
+
### Method 3: Persistent config.json
|
|
102
102
|
|
|
103
|
-
For local
|
|
103
|
+
For persistent local configuration, create or update `~/.pi/agent/pi-langfuse/config.json`:
|
|
104
104
|
|
|
105
105
|
```json
|
|
106
106
|
{
|
|
@@ -110,7 +110,7 @@ For local development, create a `config.json` in the project root:
|
|
|
110
110
|
}
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
> **⚠️ Security**:
|
|
113
|
+
> **⚠️ Security**: Keep `~/.pi/agent/pi-langfuse/config.json` private. Never commit API keys to version control.
|
|
114
114
|
|
|
115
115
|
## Usage
|
|
116
116
|
|
|
@@ -160,7 +160,6 @@ pi-langfuse/
|
|
|
160
160
|
├── index.ts # Extension entrypoint and core logic
|
|
161
161
|
├── package.json # Package metadata
|
|
162
162
|
├── tsconfig.json # TypeScript configuration
|
|
163
|
-
├── config.json # Local credentials (git-ignored)
|
|
164
163
|
├── types/
|
|
165
164
|
│ ├── pi-coding-agent.d.ts # Pi extension API types
|
|
166
165
|
│ └── node-shims.d.ts # Node.js module shims
|
package/README_CN.md
CHANGED
|
@@ -78,7 +78,7 @@ pi link /path/to/pi-langfuse
|
|
|
78
78
|
2. **Langfuse 密钥** — 以 `sk-lf-...` 开头
|
|
79
79
|
3. **Langfuse 主机地址** — 默认为 `https://cloud.langfuse.com`
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
扩展会将这些保存到 `~/.pi/agent/pi-langfuse/config.json`,这样 Pi 更新、重装扩展时不会覆盖你的 Langfuse 凭据。
|
|
82
82
|
|
|
83
83
|
随时重新运行设置:
|
|
84
84
|
|
|
@@ -86,7 +86,7 @@ pi link /path/to/pi-langfuse
|
|
|
86
86
|
/langfuse-setup
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
### 方式 2
|
|
89
|
+
### 方式 2:环境变量(兜底)
|
|
90
90
|
|
|
91
91
|
在启动 Pi 前设置:
|
|
92
92
|
|
|
@@ -96,11 +96,11 @@ export LANGFUSE_SECRET_KEY="sk-lf-xxxx"
|
|
|
96
96
|
export LANGFUSE_BASE_URL="https://cloud.langfuse.com" # 可选;也支持 LANGFUSE_HOST
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
保存的配置文件优先级更高。只有当 `~/.pi/agent/pi-langfuse/config.json` 不存在或不完整时,扩展才会使用环境变量,这样重新运行 `/langfuse-setup` 后不会出现配置漂移。
|
|
100
100
|
|
|
101
|
-
### 方式 3
|
|
101
|
+
### 方式 3:持久化 config.json
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
如需使用持久化本地配置,创建或更新 `~/.pi/agent/pi-langfuse/config.json`:
|
|
104
104
|
|
|
105
105
|
```json
|
|
106
106
|
{
|
|
@@ -110,7 +110,7 @@ export LANGFUSE_BASE_URL="https://cloud.langfuse.com" # 可选;也支持 LANG
|
|
|
110
110
|
}
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
> **⚠️
|
|
113
|
+
> **⚠️ 安全提醒**:请保护好 `~/.pi/agent/pi-langfuse/config.json`。切勿将 API 密钥提交到版本控制。
|
|
114
114
|
|
|
115
115
|
## 使用
|
|
116
116
|
|
|
@@ -160,7 +160,6 @@ pi-langfuse/
|
|
|
160
160
|
├── index.ts # 扩展入口和核心逻辑
|
|
161
161
|
├── package.json # 包元数据
|
|
162
162
|
├── tsconfig.json # TypeScript 配置
|
|
163
|
-
├── config.json # 本地凭据(git 忽略)
|
|
164
163
|
├── types/
|
|
165
164
|
│ ├── pi-coding-agent.d.ts # Pi 扩展 API 类型
|
|
166
165
|
│ └── node-shims.d.ts # Node.js 模块 shims
|
package/index.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { basename } from "node:path";
|
|
|
11
11
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
12
12
|
|
|
13
13
|
import { state, resetRunState } from "./src/state.js";
|
|
14
|
-
import { ensureConfig, promptForConfig,
|
|
14
|
+
import { ensureConfig, promptForConfig, loadConfig } from "./src/config.js";
|
|
15
15
|
import { shutdownRuntime } from "./src/langfuse.js";
|
|
16
16
|
import { getMessageFromEvent, extractAssistantOutput } from "./src/utils.js";
|
|
17
17
|
import { startAgentRun, finishAgentRun } from "./src/handlers/agent.js";
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
|
|
36
36
|
export default async function (pi: ExtensionAPI) {
|
|
37
37
|
if (!state.config) {
|
|
38
|
-
state.config =
|
|
38
|
+
state.config = loadConfig();
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
if (state.config) {
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readFileSync, existsSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { mkdirSync, readFileSync, existsSync, writeFileSync } from "node:fs";
|
|
2
2
|
import type { Config } from "./types.js";
|
|
3
|
-
import { CONFIG_PATH, DEFAULT_LANGFUSE_HOST } from "./constants.js";
|
|
3
|
+
import { CONFIG_DIR, CONFIG_PATH, DEFAULT_LANGFUSE_HOST } from "./constants.js";
|
|
4
4
|
import { state } from "./state.js";
|
|
5
5
|
import { shutdownRuntime } from "./langfuse.js";
|
|
6
6
|
|
|
@@ -38,7 +38,12 @@ export function loadConfigFromEnv(): Config | null {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
export function loadConfig(): Config | null {
|
|
42
|
+
return loadConfigFromFile() || loadConfigFromEnv();
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
export function saveConfig(config: Config) {
|
|
46
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
42
47
|
writeFileSync(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`, "utf-8");
|
|
43
48
|
}
|
|
44
49
|
|
|
@@ -79,7 +84,7 @@ async function saveConfigFromUI(ctx: any, config: Config): Promise<boolean> {
|
|
|
79
84
|
return true;
|
|
80
85
|
} catch (error) {
|
|
81
86
|
console.warn("📊 Langfuse: Failed to save config.json", error);
|
|
82
|
-
ctx.ui.notify(
|
|
87
|
+
ctx.ui.notify(`Failed to save Langfuse config.json to ${CONFIG_PATH}. Check Pi config directory permissions.`, "error");
|
|
83
88
|
state.config = null;
|
|
84
89
|
return false;
|
|
85
90
|
}
|
|
@@ -87,7 +92,7 @@ async function saveConfigFromUI(ctx: any, config: Config): Promise<boolean> {
|
|
|
87
92
|
|
|
88
93
|
export async function ensureConfig(ctx: any): Promise<boolean> {
|
|
89
94
|
if (!state.config) {
|
|
90
|
-
state.config =
|
|
95
|
+
state.config = loadConfig();
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
if (state.config) {
|
|
@@ -114,7 +119,7 @@ export async function promptForConfig(ctx: any): Promise<boolean> {
|
|
|
114
119
|
|
|
115
120
|
const config = await collectConfigFromUI(ctx, "Manual setup requested");
|
|
116
121
|
if (!config) {
|
|
117
|
-
state.config =
|
|
122
|
+
state.config = loadConfig();
|
|
118
123
|
return false;
|
|
119
124
|
}
|
|
120
125
|
|
package/src/constants.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// `dirname` gives us `src/`, and `resolve(..., '..')` gives us the root.
|
|
7
|
-
export const EXT_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
-
export const CONFIG_PATH = resolve(EXT_DIR, "config.json");
|
|
4
|
+
export const CONFIG_DIR = resolve(homedir(), ".pi", "agent", "pi-langfuse");
|
|
5
|
+
export const CONFIG_PATH = resolve(CONFIG_DIR, "config.json");
|
|
9
6
|
export const DEFAULT_LANGFUSE_HOST = "https://cloud.langfuse.com";
|
|
10
7
|
|
|
11
8
|
export const MAX_STRING_LENGTH = 12_000;
|