@narumitw/pi-langfuse 0.26.0 → 0.31.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
@@ -168,6 +168,7 @@ The built-in mask specifically protects Langfuse credentials; it is not a genera
168
168
  ```txt
169
169
  extensions/pi-langfuse/
170
170
  ├── src/
171
+ │ ├── index.ts # Pi package entrypoint
171
172
  │ ├── langfuse.ts # Pi lifecycle integration and slash command
172
173
  │ ├── tracing.ts # Observation lifecycle, outcomes, and bounded metadata
173
174
  │ ├── sanitizer.ts # Content bounding and opaque-signature removal
@@ -180,7 +181,7 @@ extensions/pi-langfuse/
180
181
  └── package.json
181
182
  ```
182
183
 
183
- Only `langfuse.ts` is a Pi entrypoint; the other source modules are internal.
184
+ `index.ts` is the Pi entrypoint and forwards to `langfuse.ts`; the other source modules are internal.
184
185
 
185
186
  ## 🔎 Keywords
186
187
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-langfuse",
3
- "version": "0.26.0",
3
+ "version": "0.31.0",
4
4
  "description": "Pi extension that traces LLM generations and tool activity to Langfuse.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "pi": {
22
22
  "extensions": [
23
- "./src/langfuse.ts"
23
+ "./src/index.ts"
24
24
  ]
25
25
  },
26
26
  "scripts": {
@@ -30,15 +30,15 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@langfuse/otel": "^5.9.1",
33
- "@langfuse/tracing": "^4.0.0",
33
+ "@langfuse/tracing": "^5.9.1",
34
34
  "@opentelemetry/api": "^1.9.1",
35
- "@opentelemetry/exporter-trace-otlp-http": "^0.220.0",
36
- "@opentelemetry/sdk-trace-base": "^2.9.0",
37
- "@opentelemetry/sdk-trace-node": "^2.9.0"
35
+ "@opentelemetry/exporter-trace-otlp-http": "^0.221.0",
36
+ "@opentelemetry/sdk-trace-base": "^2.10.0",
37
+ "@opentelemetry/sdk-trace-node": "^2.10.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@biomejs/biome": "2.5.3",
41
- "@earendil-works/pi-coding-agent": "0.80.10",
40
+ "@biomejs/biome": "2.5.5",
41
+ "@earendil-works/pi-coding-agent": "0.82.1",
42
42
  "@types/node": "26.1.1",
43
43
  "typescript": "7.0.2"
44
44
  },
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from "./langfuse.js";
package/src/runtime.ts CHANGED
@@ -3,7 +3,7 @@ import { LangfuseSpanProcessor } from "@langfuse/otel";
3
3
  import {
4
4
  type LangfuseObservation,
5
5
  type LangfuseObservationAttributes,
6
- type LangfuseTraceAttributes,
6
+ LangfuseOtelSpanAttributes,
7
7
  setLangfuseTracerProvider,
8
8
  startObservation,
9
9
  } from "@langfuse/tracing";
@@ -44,7 +44,28 @@ class ProductionObservation implements Observation {
44
44
  }
45
45
 
46
46
  updateTrace(attributes: ObservationAttributes): Observation {
47
- this.native.updateTrace(attributes as LangfuseTraceAttributes);
47
+ const { input, output, metadata, name, sessionId, tags, version } = attributes;
48
+ if (input !== undefined || output !== undefined) {
49
+ this.native.setTraceIO({ input, output });
50
+ }
51
+ if (name !== undefined) {
52
+ this.native.otelSpan.setAttribute(LangfuseOtelSpanAttributes.TRACE_NAME, name);
53
+ }
54
+ if (sessionId !== undefined) {
55
+ this.native.otelSpan.setAttribute(LangfuseOtelSpanAttributes.TRACE_SESSION_ID, sessionId);
56
+ }
57
+ if (tags !== undefined) {
58
+ this.native.otelSpan.setAttribute(LangfuseOtelSpanAttributes.TRACE_TAGS, tags);
59
+ }
60
+ if (version !== undefined) {
61
+ this.native.otelSpan.setAttribute(LangfuseOtelSpanAttributes.VERSION, version);
62
+ }
63
+ for (const [key, value] of Object.entries(metadata ?? {})) {
64
+ this.native.otelSpan.setAttribute(
65
+ `${LangfuseOtelSpanAttributes.TRACE_METADATA}.${key}`,
66
+ String(value),
67
+ );
68
+ }
48
69
  return this;
49
70
  }
50
71
 
@@ -67,9 +88,7 @@ class ProductionTraceBackend implements TraceBackend {
67
88
  ): Observation {
68
89
  const parent = options.parent;
69
90
  if (parent instanceof ProductionObservation) {
70
- return new ProductionObservation(
71
- startChild(parent.native, name, attributes, options.asType),
72
- );
91
+ return new ProductionObservation(startChild(parent.native, name, attributes, options.asType));
73
92
  }
74
93
  return new ProductionObservation(startRoot(name, attributes, options.asType));
75
94
  }
@@ -236,10 +255,7 @@ function maskSecretValue(
236
255
  return data.map((item) => maskSecretValue(item, secrets, active));
237
256
  }
238
257
  return Object.fromEntries(
239
- Object.entries(data).map(([key, value]) => [
240
- key,
241
- maskSecretValue(value, secrets, active),
242
- ]),
258
+ Object.entries(data).map(([key, value]) => [key, maskSecretValue(value, secrets, active)]),
243
259
  );
244
260
  } finally {
245
261
  active.delete(data);
package/src/tracing.ts CHANGED
@@ -243,8 +243,7 @@ export class TraceRecorder {
243
243
  }
244
244
 
245
245
  beginAgent(input: BeginAgentInput): void {
246
- if (this.root)
247
- this.closeActiveTrace("Interrupted by a new Pi run.", undefined, "interrupted");
246
+ if (this.root) this.closeActiveTrace("Interrupted by a new Pi run.", undefined, "interrupted");
248
247
 
249
248
  this.lastOutput = undefined;
250
249
  this.lastAssistant = undefined;