@mastra/langfuse 0.0.0-stream-vnext-usage-20250908171242 → 0.0.0-testing-cloud-studios-20260114234039

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.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Langfuse Exporter for Mastra Observability
3
+ *
4
+ * This exporter sends observability data to Langfuse.
5
+ * Root spans start traces in Langfuse.
6
+ * MODEL_GENERATION spans become Langfuse generations, all others become spans.
7
+ */
8
+ import type { TracingEvent, UsageStats } from '@mastra/core/observability';
9
+ import { BaseExporter } from '@mastra/observability';
10
+ import type { BaseExporterConfig } from '@mastra/observability';
11
+ export interface LangfuseExporterConfig extends BaseExporterConfig {
12
+ /** Langfuse API key */
13
+ publicKey?: string;
14
+ /** Langfuse secret key */
15
+ secretKey?: string;
16
+ /** Langfuse host URL */
17
+ baseUrl?: string;
18
+ /** Enable realtime mode - flushes after each event for immediate visibility */
19
+ realtime?: boolean;
20
+ /** Additional options to pass to the Langfuse client */
21
+ options?: any;
22
+ }
23
+ /**
24
+ * Token usage format compatible with Langfuse.
25
+ */
26
+ export interface LangfuseUsageMetrics {
27
+ input?: number;
28
+ output?: number;
29
+ total?: number;
30
+ reasoning?: number;
31
+ cache_read_input_tokens?: number;
32
+ cache_write_input_tokens?: number;
33
+ }
34
+ /**
35
+ * Formats UsageStats to Langfuse's expected format.
36
+ */
37
+ export declare function formatUsageMetrics(usage?: UsageStats): LangfuseUsageMetrics;
38
+ export declare class LangfuseExporter extends BaseExporter {
39
+ name: string;
40
+ private client;
41
+ private realtime;
42
+ private traceMap;
43
+ constructor(config?: LangfuseExporterConfig);
44
+ protected _exportTracingEvent(event: TracingEvent): Promise<void>;
45
+ private handleSpanStarted;
46
+ private handleSpanUpdateOrEnd;
47
+ private handleEventSpan;
48
+ private initTrace;
49
+ private getTraceData;
50
+ private getLangfuseParent;
51
+ private buildTracePayload;
52
+ /**
53
+ * Look up the Langfuse prompt from the closest parent span that has one.
54
+ * This enables prompt inheritance for MODEL_GENERATION spans when the prompt
55
+ * is set on a parent span (e.g., AGENT_RUN) rather than directly on the generation.
56
+ */
57
+ private findParentLangfusePrompt;
58
+ private buildSpanPayload;
59
+ addScoreToTrace({ traceId, spanId, score, reason, scorerName, metadata, }: {
60
+ traceId: string;
61
+ spanId?: string;
62
+ score: number;
63
+ reason?: string;
64
+ scorerName: string;
65
+ metadata?: Record<string, any>;
66
+ }): Promise<void>;
67
+ shutdown(): Promise<void>;
68
+ }
69
+ //# sourceMappingURL=tracing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAA8C,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGvH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAIhE,MAAM,WAAW,sBAAuB,SAAQ,kBAAkB;IAChE,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wDAAwD;IACxD,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAoBD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,oBAAoB,CAkC3E;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,IAAI,SAAc;IAClB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,QAAQ,CAAgC;gBAEpC,MAAM,GAAE,sBAA2B;cAsC/B,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;YAwBzD,iBAAiB;YAkCjB,qBAAqB;YAmDrB,eAAe;IAkC7B,OAAO,CAAC,SAAS;IAwCjB,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,iBAAiB;IA4BzB,OAAO,CAAC,iBAAiB;IAuBzB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAchC,OAAO,CAAC,gBAAgB;IAkGlB,eAAe,CAAC,EACpB,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChC,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBX,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAOhC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mastra/langfuse",
3
- "version": "0.0.0-stream-vnext-usage-20250908171242",
4
- "description": "Langfuse observability provider for Mastra - includes AI tracing and future observability features",
3
+ "version": "0.0.0-testing-cloud-studios-20260114234039",
4
+ "description": "Langfuse observability provider for Mastra - includes tracing and future observability features",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -24,21 +24,23 @@
24
24
  },
25
25
  "license": "Apache-2.0",
26
26
  "dependencies": {
27
- "langfuse": "^3.38.4"
27
+ "langfuse": "^3.38.6",
28
+ "@mastra/observability": "0.0.0-testing-cloud-studios-20260114234039"
28
29
  },
29
30
  "devDependencies": {
30
- "@microsoft/api-extractor": "^7.52.8",
31
- "@types/node": "^20.19.0",
32
- "eslint": "^9.30.1",
31
+ "@types/node": "22.13.17",
32
+ "@vitest/coverage-v8": "4.0.12",
33
+ "@vitest/ui": "4.0.12",
34
+ "eslint": "^9.37.0",
33
35
  "tsup": "^8.5.0",
34
- "typescript": "^5.8.3",
35
- "vitest": "^3.2.4",
36
- "@internal/types-builder": "0.0.0-stream-vnext-usage-20250908171242",
37
- "@internal/lint": "0.0.0-stream-vnext-usage-20250908171242",
38
- "@mastra/core": "0.0.0-stream-vnext-usage-20250908171242"
36
+ "typescript": "^5.9.3",
37
+ "vitest": "4.0.16",
38
+ "@internal/lint": "0.0.0-testing-cloud-studios-20260114234039",
39
+ "@internal/types-builder": "0.0.0-testing-cloud-studios-20260114234039",
40
+ "@mastra/core": "0.0.0-testing-cloud-studios-20260114234039"
39
41
  },
40
42
  "peerDependencies": {
41
- "@mastra/core": "0.0.0-stream-vnext-usage-20250908171242"
43
+ "@mastra/core": "0.0.0-testing-cloud-studios-20260114234039"
42
44
  },
43
45
  "homepage": "https://mastra.ai",
44
46
  "repository": {
@@ -49,6 +51,9 @@
49
51
  "bugs": {
50
52
  "url": "https://github.com/mastra-ai/mastra/issues"
51
53
  },
54
+ "engines": {
55
+ "node": ">=22.13.0"
56
+ },
52
57
  "scripts": {
53
58
  "build": "tsup --silent --config tsup.config.ts",
54
59
  "build:watch": "pnpm build --watch",
@@ -1,41 +0,0 @@
1
- /**
2
- * Langfuse Exporter for Mastra AI Tracing
3
- *
4
- * This exporter sends tracing data to Langfuse for AI observability.
5
- * Root spans start traces in Langfuse.
6
- * LLM_GENERATION spans become Langfuse generations, all others become spans.
7
- */
8
- import type { AITracingExporter, AITracingEvent } from '@mastra/core/ai-tracing';
9
- export interface LangfuseExporterConfig {
10
- /** Langfuse API key */
11
- publicKey?: string;
12
- /** Langfuse secret key */
13
- secretKey?: string;
14
- /** Langfuse host URL */
15
- baseUrl?: string;
16
- /** Enable realtime mode - flushes after each event for immediate visibility */
17
- realtime?: boolean;
18
- /** Logger level for diagnostic messages (default: 'warn') */
19
- logLevel?: 'debug' | 'info' | 'warn' | 'error';
20
- /** Additional options to pass to the Langfuse client */
21
- options?: any;
22
- }
23
- export declare class LangfuseExporter implements AITracingExporter {
24
- name: string;
25
- private client;
26
- private realtime;
27
- private traceMap;
28
- private logger;
29
- constructor(config: LangfuseExporterConfig);
30
- exportEvent(event: AITracingEvent): Promise<void>;
31
- private handleSpanStarted;
32
- private handleSpanUpdateOrEnd;
33
- private handleEventSpan;
34
- private initTrace;
35
- private getTraceData;
36
- private getLangfuseParent;
37
- private buildTracePayload;
38
- private buildSpanPayload;
39
- shutdown(): Promise<void>;
40
- }
41
- //# sourceMappingURL=ai-tracing.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai-tracing.d.ts","sourceRoot":"","sources":["../src/ai-tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAsC,MAAM,yBAAyB,CAAC;AAMrH,MAAM,WAAW,sBAAsB;IACrC,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/C,wDAAwD;IACxD,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAUD,qBAAa,gBAAiB,YAAW,iBAAiB;IACxD,IAAI,SAAc;IAClB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,sBAAsB;IAsBpC,WAAW,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;YA6BzC,iBAAiB;YAwBjB,qBAAqB;YAgCrB,eAAe;IA6B7B,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,iBAAiB;IA4BzB,OAAO,CAAC,iBAAiB;IAqBzB,OAAO,CAAC,gBAAgB;IAmDlB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAMhC"}