@rawdash/connector-langfuse 0.0.1
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 +122 -0
- package/dist/index.d.ts +422 -0
- package/dist/index.js +593 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
<!-- This file is generated from connector metadata by scripts/generate-connector-docs.ts. Do not edit by hand. -->
|
|
2
|
+
|
|
3
|
+
# @rawdash/connector-langfuse
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@rawdash/connector-langfuse)
|
|
6
|
+
[](https://github.com/rawdash/rawdash/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Sync LLM traces, daily observation volume and cost by model, and feedback scores from a Langfuse project.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @rawdash/connector-langfuse
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Authentication
|
|
17
|
+
|
|
18
|
+
A Langfuse public + secret API key pair scoped to one project is required. The connector authenticates over HTTP Basic auth (`publicKey:secretKey`).
|
|
19
|
+
|
|
20
|
+
1. Open Langfuse -> Settings -> API Keys and create a new key pair for the project you want to sync.
|
|
21
|
+
2. Copy both the public key (`pk-lf-...`) and the secret key (`sk-lf-...`). The secret is shown once.
|
|
22
|
+
3. Set `host` to your instance base URL - `https://cloud.langfuse.com` (or the US/EU regional variants) for Langfuse Cloud, or your self-hosted origin (no trailing slash).
|
|
23
|
+
4. Store the secret as a secret and reference it from config as `secretKey: secret("LANGFUSE_SECRET_KEY")`, alongside the plaintext `publicKey`.
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
| Field | Type | Required | Description |
|
|
28
|
+
| -------------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
29
|
+
| `publicKey` | string | Yes | Langfuse public API key for the project (starts with `pk-lf-`). Created in Langfuse -> Settings -> API Keys. |
|
|
30
|
+
| `secretKey` | secret | Yes | Langfuse secret API key for the project (starts with `sk-lf-`). Issued alongside the public key in Langfuse -> Settings -> API Keys. |
|
|
31
|
+
| `host` | string | No | Langfuse instance base URL. Use https://cloud.langfuse.com (US) or https://us.cloud.langfuse.com / https://eu.cloud.langfuse.com for Langfuse Cloud, or your self-hosted origin. No trailing slash. |
|
|
32
|
+
| `lookbackDays` | number | No | How many calendar days of history to backfill on a full sync. Defaults to 30. |
|
|
33
|
+
| `resources` | array | No | Which Langfuse resources to sync. Omit to sync all of them. |
|
|
34
|
+
|
|
35
|
+
## Resources
|
|
36
|
+
|
|
37
|
+
- **`langfuse_trace`** _(entity)_ - LLM traces in the project, keyed by id, with name, owning user/session, optional release/version, aggregate cost in USD, aggregate latency in milliseconds, and the createdAt timestamp.
|
|
38
|
+
- Endpoint: `GET /api/public/traces`
|
|
39
|
+
- Traces upsert by id on every run. Trace input/output payloads are not stored.
|
|
40
|
+
- `name`: Trace name set by the SDK.
|
|
41
|
+
- `projectId`: Langfuse project id the trace belongs to.
|
|
42
|
+
- `userId`: Attached userId, if any.
|
|
43
|
+
- `sessionId`: Attached sessionId, if any.
|
|
44
|
+
- `release`: Release identifier from the SDK, if set.
|
|
45
|
+
- `version`: Version identifier from the SDK, if set.
|
|
46
|
+
- `totalCost`: Aggregate trace cost in USD across all observations.
|
|
47
|
+
- `latencyMs`: End-to-end trace latency in milliseconds.
|
|
48
|
+
- `createdAt`: ISO timestamp of trace creation.
|
|
49
|
+
- **`langfuse_observations_per_day`** _(metric)_ - Daily LLM observation volume, total tokens, and total cost rolled up by model from the Langfuse daily metrics endpoint. One sample per (day, model) over the lookback window.
|
|
50
|
+
- Endpoint: `GET /api/public/metrics/daily`
|
|
51
|
+
- Unit: observations
|
|
52
|
+
- Granularity: Daily (UTC)
|
|
53
|
+
- Dimensions: `model`, `countObservations`, `inputTokens`, `outputTokens`, `totalTokens`, `costUsd`
|
|
54
|
+
- Rollup metrics are stamped at UTC midnight of the day they cover.
|
|
55
|
+
- **`langfuse_scores`** _(metric)_ - Daily Langfuse score rollups by score name. One sample per (day, name): the mean numeric value across that day and the count of scores written.
|
|
56
|
+
- Endpoint: `GET /api/public/scores`
|
|
57
|
+
- Unit: scores
|
|
58
|
+
- Granularity: Daily (UTC)
|
|
59
|
+
- Dimensions: `name`, `average`, `count`
|
|
60
|
+
- Only numeric scores contribute to the average; non-numeric scores still increment the count.
|
|
61
|
+
|
|
62
|
+
## Example
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import {
|
|
66
|
+
defineConfig,
|
|
67
|
+
defineDashboard,
|
|
68
|
+
defineMetric,
|
|
69
|
+
secret,
|
|
70
|
+
} from '@rawdash/core';
|
|
71
|
+
|
|
72
|
+
const langfuse = {
|
|
73
|
+
name: 'langfuse',
|
|
74
|
+
connectorId: 'langfuse',
|
|
75
|
+
config: {
|
|
76
|
+
publicKey: 'pk-lf-...',
|
|
77
|
+
secretKey: secret('LANGFUSE_SECRET_KEY'),
|
|
78
|
+
host: 'https://cloud.langfuse.com',
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default defineConfig({
|
|
83
|
+
connectors: [langfuse],
|
|
84
|
+
dashboards: {
|
|
85
|
+
llm: defineDashboard({
|
|
86
|
+
widgets: {
|
|
87
|
+
daily_observations: {
|
|
88
|
+
kind: 'timeseries',
|
|
89
|
+
title: 'LLM observations per day',
|
|
90
|
+
window: '30d',
|
|
91
|
+
metric: defineMetric({
|
|
92
|
+
connector: langfuse,
|
|
93
|
+
shape: 'metric',
|
|
94
|
+
name: 'langfuse_observations_per_day',
|
|
95
|
+
fn: 'sum',
|
|
96
|
+
}),
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Rate limits
|
|
105
|
+
|
|
106
|
+
Langfuse Cloud applies per-project rate limits (around 1000 requests/min on paid plans); 429 responses with Retry-After are honored.
|
|
107
|
+
|
|
108
|
+
## Limitations
|
|
109
|
+
|
|
110
|
+
- One key pair scopes the sync to a single Langfuse project; sync multiple projects by adding one connector instance per project.
|
|
111
|
+
- Trace bodies (input/output payloads) are not synced - only the trace envelope plus aggregated cost / token / latency.
|
|
112
|
+
- Session and dataset endpoints are out of scope for the initial release.
|
|
113
|
+
|
|
114
|
+
## Links
|
|
115
|
+
|
|
116
|
+
- [Rawdash docs](https://rawdash.dev/docs/connectors/)
|
|
117
|
+
- [Langfuse API docs](https://api.reference.langfuse.com)
|
|
118
|
+
- [GitHub](https://github.com/rawdash/rawdash)
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { BaseConnector, ConnectorContext, SyncOptions, StorageHandle, SyncResult, ConnectorDoc } from '@rawdash/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const configFields: z.ZodObject<{
|
|
5
|
+
publicKey: z.ZodString;
|
|
6
|
+
secretKey: z.ZodObject<{
|
|
7
|
+
$secret: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
host: z.ZodDefault<z.ZodString>;
|
|
10
|
+
lookbackDays: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
12
|
+
traces: "traces";
|
|
13
|
+
observations_per_day: "observations_per_day";
|
|
14
|
+
scores: "scores";
|
|
15
|
+
}>>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
declare const doc: ConnectorDoc;
|
|
18
|
+
interface LangfuseSettings {
|
|
19
|
+
publicKey: string;
|
|
20
|
+
host: string;
|
|
21
|
+
lookbackDays?: number;
|
|
22
|
+
resources?: readonly LangfuseResource[];
|
|
23
|
+
}
|
|
24
|
+
declare const langfuseCredentials: {
|
|
25
|
+
secretKey: {
|
|
26
|
+
description: string;
|
|
27
|
+
auth: "required";
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
type LangfuseCredentials = typeof langfuseCredentials;
|
|
31
|
+
declare const PHASE_ORDER: readonly ["traces", "observations_per_day", "scores"];
|
|
32
|
+
type LangfusePhase = (typeof PHASE_ORDER)[number];
|
|
33
|
+
type LangfuseResource = LangfusePhase;
|
|
34
|
+
declare const langfuseResources: {
|
|
35
|
+
readonly langfuse_trace: {
|
|
36
|
+
readonly shape: "entity";
|
|
37
|
+
readonly filterable: [];
|
|
38
|
+
readonly description: "LLM traces in the project, keyed by id, with name, owning user/session, optional release/version, aggregate cost in USD, aggregate latency in milliseconds, and the createdAt timestamp.";
|
|
39
|
+
readonly endpoint: "GET /api/public/traces";
|
|
40
|
+
readonly notes: "Traces upsert by id on every run. Trace input/output payloads are not stored.";
|
|
41
|
+
readonly fields: [{
|
|
42
|
+
readonly name: "name";
|
|
43
|
+
readonly description: "Trace name set by the SDK.";
|
|
44
|
+
}, {
|
|
45
|
+
readonly name: "projectId";
|
|
46
|
+
readonly description: "Langfuse project id the trace belongs to.";
|
|
47
|
+
}, {
|
|
48
|
+
readonly name: "userId";
|
|
49
|
+
readonly description: "Attached userId, if any.";
|
|
50
|
+
}, {
|
|
51
|
+
readonly name: "sessionId";
|
|
52
|
+
readonly description: "Attached sessionId, if any.";
|
|
53
|
+
}, {
|
|
54
|
+
readonly name: "release";
|
|
55
|
+
readonly description: "Release identifier from the SDK, if set.";
|
|
56
|
+
}, {
|
|
57
|
+
readonly name: "version";
|
|
58
|
+
readonly description: "Version identifier from the SDK, if set.";
|
|
59
|
+
}, {
|
|
60
|
+
readonly name: "totalCost";
|
|
61
|
+
readonly description: "Aggregate trace cost in USD across all observations.";
|
|
62
|
+
}, {
|
|
63
|
+
readonly name: "latencyMs";
|
|
64
|
+
readonly description: "End-to-end trace latency in milliseconds.";
|
|
65
|
+
}, {
|
|
66
|
+
readonly name: "createdAt";
|
|
67
|
+
readonly description: "ISO timestamp of trace creation.";
|
|
68
|
+
}];
|
|
69
|
+
readonly responses: {
|
|
70
|
+
readonly traces: z.ZodObject<{
|
|
71
|
+
data: z.ZodArray<z.ZodObject<{
|
|
72
|
+
id: z.ZodString;
|
|
73
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
74
|
+
projectId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
75
|
+
userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
76
|
+
sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
77
|
+
release: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
78
|
+
version: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
79
|
+
totalCost: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
80
|
+
latency: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
81
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
82
|
+
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
83
|
+
}, z.core.$strip>>;
|
|
84
|
+
meta: z.ZodObject<{
|
|
85
|
+
page: z.ZodNumber;
|
|
86
|
+
limit: z.ZodNumber;
|
|
87
|
+
totalItems: z.ZodNumber;
|
|
88
|
+
totalPages: z.ZodNumber;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
readonly langfuse_observations_per_day: {
|
|
94
|
+
readonly shape: "metric";
|
|
95
|
+
readonly description: "Daily LLM observation volume, total tokens, and total cost rolled up by model from the Langfuse daily metrics endpoint. One sample per (day, model) over the lookback window.";
|
|
96
|
+
readonly endpoint: "GET /api/public/metrics/daily";
|
|
97
|
+
readonly unit: "observations";
|
|
98
|
+
readonly granularity: "Daily (UTC)";
|
|
99
|
+
readonly notes: "Rollup metrics are stamped at UTC midnight of the day they cover.";
|
|
100
|
+
readonly dimensions: [{
|
|
101
|
+
readonly name: "model";
|
|
102
|
+
readonly description: "The model id the observations ran against.";
|
|
103
|
+
}, {
|
|
104
|
+
readonly name: "countObservations";
|
|
105
|
+
readonly description: "Observations recorded that day for this model.";
|
|
106
|
+
}, {
|
|
107
|
+
readonly name: "inputTokens";
|
|
108
|
+
readonly description: "Input tokens consumed that day for this model.";
|
|
109
|
+
}, {
|
|
110
|
+
readonly name: "outputTokens";
|
|
111
|
+
readonly description: "Output tokens produced that day for this model.";
|
|
112
|
+
}, {
|
|
113
|
+
readonly name: "totalTokens";
|
|
114
|
+
readonly description: "Total tokens (input + output) for the day and model.";
|
|
115
|
+
}, {
|
|
116
|
+
readonly name: "costUsd";
|
|
117
|
+
readonly description: "Aggregate cost in USD for the day and model.";
|
|
118
|
+
}];
|
|
119
|
+
readonly responses: {
|
|
120
|
+
readonly observations_per_day: z.ZodObject<{
|
|
121
|
+
data: z.ZodArray<z.ZodObject<{
|
|
122
|
+
date: z.ZodString;
|
|
123
|
+
countTraces: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
124
|
+
countObservations: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
125
|
+
totalCost: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
126
|
+
usage: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
127
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
128
|
+
inputUsage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
129
|
+
outputUsage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
130
|
+
totalUsage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
131
|
+
countObservations: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
132
|
+
totalCost: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
133
|
+
}, z.core.$strip>>>>;
|
|
134
|
+
}, z.core.$strip>>;
|
|
135
|
+
meta: z.ZodObject<{
|
|
136
|
+
page: z.ZodNumber;
|
|
137
|
+
limit: z.ZodNumber;
|
|
138
|
+
totalItems: z.ZodNumber;
|
|
139
|
+
totalPages: z.ZodNumber;
|
|
140
|
+
}, z.core.$strip>;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
readonly langfuse_scores: {
|
|
145
|
+
readonly shape: "metric";
|
|
146
|
+
readonly description: "Daily Langfuse score rollups by score name. One sample per (day, name): the mean numeric value across that day and the count of scores written.";
|
|
147
|
+
readonly endpoint: "GET /api/public/scores";
|
|
148
|
+
readonly unit: "scores";
|
|
149
|
+
readonly granularity: "Daily (UTC)";
|
|
150
|
+
readonly notes: "Only numeric scores contribute to the average; non-numeric scores still increment the count.";
|
|
151
|
+
readonly dimensions: [{
|
|
152
|
+
readonly name: "name";
|
|
153
|
+
readonly description: "Score name as set by the SDK.";
|
|
154
|
+
}, {
|
|
155
|
+
readonly name: "average";
|
|
156
|
+
readonly description: "Mean numeric score value for the day (zero if no numeric values).";
|
|
157
|
+
}, {
|
|
158
|
+
readonly name: "count";
|
|
159
|
+
readonly description: "Number of scores written that day.";
|
|
160
|
+
}];
|
|
161
|
+
readonly responses: {
|
|
162
|
+
readonly scores: z.ZodObject<{
|
|
163
|
+
data: z.ZodArray<z.ZodObject<{
|
|
164
|
+
id: z.ZodString;
|
|
165
|
+
name: z.ZodString;
|
|
166
|
+
value: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
167
|
+
stringValue: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
168
|
+
dataType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
169
|
+
source: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
170
|
+
timestamp: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
171
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
172
|
+
}, z.core.$strip>>;
|
|
173
|
+
meta: z.ZodObject<{
|
|
174
|
+
page: z.ZodNumber;
|
|
175
|
+
limit: z.ZodNumber;
|
|
176
|
+
totalItems: z.ZodNumber;
|
|
177
|
+
totalPages: z.ZodNumber;
|
|
178
|
+
}, z.core.$strip>;
|
|
179
|
+
}, z.core.$strip>;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
declare const id = "langfuse";
|
|
184
|
+
declare class LangfuseConnector extends BaseConnector<LangfuseSettings, LangfuseCredentials> {
|
|
185
|
+
static readonly id = "langfuse";
|
|
186
|
+
static readonly resources: {
|
|
187
|
+
readonly langfuse_trace: {
|
|
188
|
+
readonly shape: "entity";
|
|
189
|
+
readonly filterable: [];
|
|
190
|
+
readonly description: "LLM traces in the project, keyed by id, with name, owning user/session, optional release/version, aggregate cost in USD, aggregate latency in milliseconds, and the createdAt timestamp.";
|
|
191
|
+
readonly endpoint: "GET /api/public/traces";
|
|
192
|
+
readonly notes: "Traces upsert by id on every run. Trace input/output payloads are not stored.";
|
|
193
|
+
readonly fields: [{
|
|
194
|
+
readonly name: "name";
|
|
195
|
+
readonly description: "Trace name set by the SDK.";
|
|
196
|
+
}, {
|
|
197
|
+
readonly name: "projectId";
|
|
198
|
+
readonly description: "Langfuse project id the trace belongs to.";
|
|
199
|
+
}, {
|
|
200
|
+
readonly name: "userId";
|
|
201
|
+
readonly description: "Attached userId, if any.";
|
|
202
|
+
}, {
|
|
203
|
+
readonly name: "sessionId";
|
|
204
|
+
readonly description: "Attached sessionId, if any.";
|
|
205
|
+
}, {
|
|
206
|
+
readonly name: "release";
|
|
207
|
+
readonly description: "Release identifier from the SDK, if set.";
|
|
208
|
+
}, {
|
|
209
|
+
readonly name: "version";
|
|
210
|
+
readonly description: "Version identifier from the SDK, if set.";
|
|
211
|
+
}, {
|
|
212
|
+
readonly name: "totalCost";
|
|
213
|
+
readonly description: "Aggregate trace cost in USD across all observations.";
|
|
214
|
+
}, {
|
|
215
|
+
readonly name: "latencyMs";
|
|
216
|
+
readonly description: "End-to-end trace latency in milliseconds.";
|
|
217
|
+
}, {
|
|
218
|
+
readonly name: "createdAt";
|
|
219
|
+
readonly description: "ISO timestamp of trace creation.";
|
|
220
|
+
}];
|
|
221
|
+
readonly responses: {
|
|
222
|
+
readonly traces: z.ZodObject<{
|
|
223
|
+
data: z.ZodArray<z.ZodObject<{
|
|
224
|
+
id: z.ZodString;
|
|
225
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
226
|
+
projectId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
227
|
+
userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
228
|
+
sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
229
|
+
release: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
230
|
+
version: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
231
|
+
totalCost: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
232
|
+
latency: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
233
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
234
|
+
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
235
|
+
}, z.core.$strip>>;
|
|
236
|
+
meta: z.ZodObject<{
|
|
237
|
+
page: z.ZodNumber;
|
|
238
|
+
limit: z.ZodNumber;
|
|
239
|
+
totalItems: z.ZodNumber;
|
|
240
|
+
totalPages: z.ZodNumber;
|
|
241
|
+
}, z.core.$strip>;
|
|
242
|
+
}, z.core.$strip>;
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
readonly langfuse_observations_per_day: {
|
|
246
|
+
readonly shape: "metric";
|
|
247
|
+
readonly description: "Daily LLM observation volume, total tokens, and total cost rolled up by model from the Langfuse daily metrics endpoint. One sample per (day, model) over the lookback window.";
|
|
248
|
+
readonly endpoint: "GET /api/public/metrics/daily";
|
|
249
|
+
readonly unit: "observations";
|
|
250
|
+
readonly granularity: "Daily (UTC)";
|
|
251
|
+
readonly notes: "Rollup metrics are stamped at UTC midnight of the day they cover.";
|
|
252
|
+
readonly dimensions: [{
|
|
253
|
+
readonly name: "model";
|
|
254
|
+
readonly description: "The model id the observations ran against.";
|
|
255
|
+
}, {
|
|
256
|
+
readonly name: "countObservations";
|
|
257
|
+
readonly description: "Observations recorded that day for this model.";
|
|
258
|
+
}, {
|
|
259
|
+
readonly name: "inputTokens";
|
|
260
|
+
readonly description: "Input tokens consumed that day for this model.";
|
|
261
|
+
}, {
|
|
262
|
+
readonly name: "outputTokens";
|
|
263
|
+
readonly description: "Output tokens produced that day for this model.";
|
|
264
|
+
}, {
|
|
265
|
+
readonly name: "totalTokens";
|
|
266
|
+
readonly description: "Total tokens (input + output) for the day and model.";
|
|
267
|
+
}, {
|
|
268
|
+
readonly name: "costUsd";
|
|
269
|
+
readonly description: "Aggregate cost in USD for the day and model.";
|
|
270
|
+
}];
|
|
271
|
+
readonly responses: {
|
|
272
|
+
readonly observations_per_day: z.ZodObject<{
|
|
273
|
+
data: z.ZodArray<z.ZodObject<{
|
|
274
|
+
date: z.ZodString;
|
|
275
|
+
countTraces: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
276
|
+
countObservations: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
277
|
+
totalCost: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
278
|
+
usage: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
279
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
280
|
+
inputUsage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
281
|
+
outputUsage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
282
|
+
totalUsage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
283
|
+
countObservations: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
284
|
+
totalCost: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
285
|
+
}, z.core.$strip>>>>;
|
|
286
|
+
}, z.core.$strip>>;
|
|
287
|
+
meta: z.ZodObject<{
|
|
288
|
+
page: z.ZodNumber;
|
|
289
|
+
limit: z.ZodNumber;
|
|
290
|
+
totalItems: z.ZodNumber;
|
|
291
|
+
totalPages: z.ZodNumber;
|
|
292
|
+
}, z.core.$strip>;
|
|
293
|
+
}, z.core.$strip>;
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
readonly langfuse_scores: {
|
|
297
|
+
readonly shape: "metric";
|
|
298
|
+
readonly description: "Daily Langfuse score rollups by score name. One sample per (day, name): the mean numeric value across that day and the count of scores written.";
|
|
299
|
+
readonly endpoint: "GET /api/public/scores";
|
|
300
|
+
readonly unit: "scores";
|
|
301
|
+
readonly granularity: "Daily (UTC)";
|
|
302
|
+
readonly notes: "Only numeric scores contribute to the average; non-numeric scores still increment the count.";
|
|
303
|
+
readonly dimensions: [{
|
|
304
|
+
readonly name: "name";
|
|
305
|
+
readonly description: "Score name as set by the SDK.";
|
|
306
|
+
}, {
|
|
307
|
+
readonly name: "average";
|
|
308
|
+
readonly description: "Mean numeric score value for the day (zero if no numeric values).";
|
|
309
|
+
}, {
|
|
310
|
+
readonly name: "count";
|
|
311
|
+
readonly description: "Number of scores written that day.";
|
|
312
|
+
}];
|
|
313
|
+
readonly responses: {
|
|
314
|
+
readonly scores: z.ZodObject<{
|
|
315
|
+
data: z.ZodArray<z.ZodObject<{
|
|
316
|
+
id: z.ZodString;
|
|
317
|
+
name: z.ZodString;
|
|
318
|
+
value: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
319
|
+
stringValue: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
320
|
+
dataType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
321
|
+
source: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
322
|
+
timestamp: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
323
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
324
|
+
}, z.core.$strip>>;
|
|
325
|
+
meta: z.ZodObject<{
|
|
326
|
+
page: z.ZodNumber;
|
|
327
|
+
limit: z.ZodNumber;
|
|
328
|
+
totalItems: z.ZodNumber;
|
|
329
|
+
totalPages: z.ZodNumber;
|
|
330
|
+
}, z.core.$strip>;
|
|
331
|
+
}, z.core.$strip>;
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
static readonly schemas: {
|
|
336
|
+
readonly traces: z.ZodObject<{
|
|
337
|
+
data: z.ZodArray<z.ZodObject<{
|
|
338
|
+
id: z.ZodString;
|
|
339
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
340
|
+
projectId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
341
|
+
userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
342
|
+
sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
343
|
+
release: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
344
|
+
version: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
345
|
+
totalCost: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
346
|
+
latency: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
347
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
348
|
+
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
349
|
+
}, z.core.$strip>>;
|
|
350
|
+
meta: z.ZodObject<{
|
|
351
|
+
page: z.ZodNumber;
|
|
352
|
+
limit: z.ZodNumber;
|
|
353
|
+
totalItems: z.ZodNumber;
|
|
354
|
+
totalPages: z.ZodNumber;
|
|
355
|
+
}, z.core.$strip>;
|
|
356
|
+
}, z.core.$strip>;
|
|
357
|
+
} & {
|
|
358
|
+
readonly observations_per_day: z.ZodObject<{
|
|
359
|
+
data: z.ZodArray<z.ZodObject<{
|
|
360
|
+
date: z.ZodString;
|
|
361
|
+
countTraces: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
362
|
+
countObservations: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
363
|
+
totalCost: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
364
|
+
usage: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
365
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
366
|
+
inputUsage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
367
|
+
outputUsage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
368
|
+
totalUsage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
369
|
+
countObservations: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
370
|
+
totalCost: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
371
|
+
}, z.core.$strip>>>>;
|
|
372
|
+
}, z.core.$strip>>;
|
|
373
|
+
meta: z.ZodObject<{
|
|
374
|
+
page: z.ZodNumber;
|
|
375
|
+
limit: z.ZodNumber;
|
|
376
|
+
totalItems: z.ZodNumber;
|
|
377
|
+
totalPages: z.ZodNumber;
|
|
378
|
+
}, z.core.$strip>;
|
|
379
|
+
}, z.core.$strip>;
|
|
380
|
+
} & {
|
|
381
|
+
readonly scores: z.ZodObject<{
|
|
382
|
+
data: z.ZodArray<z.ZodObject<{
|
|
383
|
+
id: z.ZodString;
|
|
384
|
+
name: z.ZodString;
|
|
385
|
+
value: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
386
|
+
stringValue: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
387
|
+
dataType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
388
|
+
source: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
389
|
+
timestamp: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
390
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
391
|
+
}, z.core.$strip>>;
|
|
392
|
+
meta: z.ZodObject<{
|
|
393
|
+
page: z.ZodNumber;
|
|
394
|
+
limit: z.ZodNumber;
|
|
395
|
+
totalItems: z.ZodNumber;
|
|
396
|
+
totalPages: z.ZodNumber;
|
|
397
|
+
}, z.core.$strip>;
|
|
398
|
+
}, z.core.$strip>;
|
|
399
|
+
} & Readonly<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
400
|
+
static create(input: unknown, ctx?: ConnectorContext): LangfuseConnector;
|
|
401
|
+
readonly id = "langfuse";
|
|
402
|
+
readonly credentials: {
|
|
403
|
+
secretKey: {
|
|
404
|
+
description: string;
|
|
405
|
+
auth: "required";
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
private get baseUrl();
|
|
409
|
+
private buildHeaders;
|
|
410
|
+
private windowStart;
|
|
411
|
+
private fetchTracesPage;
|
|
412
|
+
private writeTraces;
|
|
413
|
+
private fetchDailyMetricsPage;
|
|
414
|
+
private writeDailyMetrics;
|
|
415
|
+
private fetchScoresPage;
|
|
416
|
+
private writeScores;
|
|
417
|
+
private clearScopeOnFirstPage;
|
|
418
|
+
private writePhase;
|
|
419
|
+
sync(options: SyncOptions, storage: StorageHandle, signal?: AbortSignal): Promise<SyncResult>;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export { LangfuseConnector, type LangfuseResource, type LangfuseSettings, configFields, LangfuseConnector as default, doc, id, langfuseResources as resources };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
// ../../connector-shared/dist/index.js
|
|
2
|
+
var HTTP_CLIENT_VERSION = "0.0.0";
|
|
3
|
+
var DEFAULT_USER_AGENT = `rawdash-connector/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;
|
|
4
|
+
function connectorUserAgent(connectorId) {
|
|
5
|
+
return `rawdash-connector-${connectorId}/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;
|
|
6
|
+
}
|
|
7
|
+
function parseEpoch(value, unit) {
|
|
8
|
+
if (value === null || value === void 0) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (unit === "iso") {
|
|
12
|
+
if (typeof value !== "string") {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const ms = new Date(value).getTime();
|
|
16
|
+
return Number.isFinite(ms) ? ms : null;
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
22
|
+
if (!Number.isFinite(n)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const result = unit === "s" ? n * 1e3 : n;
|
|
26
|
+
return Number.isFinite(result) ? result : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/langfuse.ts
|
|
30
|
+
import {
|
|
31
|
+
BaseConnector,
|
|
32
|
+
defineConfigFields,
|
|
33
|
+
defineConnectorDoc,
|
|
34
|
+
defineResources,
|
|
35
|
+
makeChunkedCursorGuard,
|
|
36
|
+
paginateChunked,
|
|
37
|
+
schemasFromResources,
|
|
38
|
+
selectActivePhases
|
|
39
|
+
} from "@rawdash/core";
|
|
40
|
+
import { z } from "zod";
|
|
41
|
+
var configFields = defineConfigFields(
|
|
42
|
+
z.object({
|
|
43
|
+
publicKey: z.string().trim().min(1).meta({
|
|
44
|
+
label: "Public key",
|
|
45
|
+
description: "Langfuse public API key for the project (starts with `pk-lf-`). Created in Langfuse -> Settings -> API Keys.",
|
|
46
|
+
placeholder: "pk-lf-..."
|
|
47
|
+
}),
|
|
48
|
+
secretKey: z.object({ $secret: z.string() }).meta({
|
|
49
|
+
label: "Secret key",
|
|
50
|
+
description: "Langfuse secret API key for the project (starts with `sk-lf-`). Issued alongside the public key in Langfuse -> Settings -> API Keys.",
|
|
51
|
+
placeholder: "sk-lf-...",
|
|
52
|
+
secret: true
|
|
53
|
+
}),
|
|
54
|
+
host: z.string().trim().regex(
|
|
55
|
+
/^https?:\/\/[^\s/]+$/,
|
|
56
|
+
"Use a base URL with protocol and no trailing slash, e.g. https://cloud.langfuse.com"
|
|
57
|
+
).default("https://cloud.langfuse.com").meta({
|
|
58
|
+
label: "Host",
|
|
59
|
+
description: "Langfuse instance base URL. Use https://cloud.langfuse.com (US) or https://us.cloud.langfuse.com / https://eu.cloud.langfuse.com for Langfuse Cloud, or your self-hosted origin. No trailing slash.",
|
|
60
|
+
placeholder: "https://cloud.langfuse.com"
|
|
61
|
+
}),
|
|
62
|
+
lookbackDays: z.number().int().positive().optional().meta({
|
|
63
|
+
label: "Lookback days (full sync)",
|
|
64
|
+
description: "How many calendar days of history to backfill on a full sync. Defaults to 30.",
|
|
65
|
+
placeholder: "30"
|
|
66
|
+
}),
|
|
67
|
+
resources: z.array(z.enum(["traces", "observations_per_day", "scores"])).nonempty().optional().meta({
|
|
68
|
+
label: "Resources",
|
|
69
|
+
description: "Which Langfuse resources to sync. Omit to sync all of them."
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
var doc = defineConnectorDoc({
|
|
74
|
+
displayName: "Langfuse",
|
|
75
|
+
category: "engineering",
|
|
76
|
+
brandColor: "#1F2937",
|
|
77
|
+
tagline: "Sync LLM traces, daily observation volume and cost by model, and feedback scores from a Langfuse project.",
|
|
78
|
+
vendor: {
|
|
79
|
+
name: "Langfuse",
|
|
80
|
+
domain: "langfuse.com",
|
|
81
|
+
apiDocs: "https://api.reference.langfuse.com",
|
|
82
|
+
website: "https://langfuse.com"
|
|
83
|
+
},
|
|
84
|
+
auth: {
|
|
85
|
+
summary: "A Langfuse public + secret API key pair scoped to one project is required. The connector authenticates over HTTP Basic auth (`publicKey:secretKey`).",
|
|
86
|
+
setup: [
|
|
87
|
+
"Open Langfuse -> Settings -> API Keys and create a new key pair for the project you want to sync.",
|
|
88
|
+
"Copy both the public key (`pk-lf-...`) and the secret key (`sk-lf-...`). The secret is shown once.",
|
|
89
|
+
"Set `host` to your instance base URL - `https://cloud.langfuse.com` (or the US/EU regional variants) for Langfuse Cloud, or your self-hosted origin (no trailing slash).",
|
|
90
|
+
'Store the secret as a secret and reference it from config as `secretKey: secret("LANGFUSE_SECRET_KEY")`, alongside the plaintext `publicKey`.'
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
rateLimit: "Langfuse Cloud applies per-project rate limits (around 1000 requests/min on paid plans); 429 responses with Retry-After are honored.",
|
|
94
|
+
limitations: [
|
|
95
|
+
"One key pair scopes the sync to a single Langfuse project; sync multiple projects by adding one connector instance per project.",
|
|
96
|
+
"Trace bodies (input/output payloads) are not synced - only the trace envelope plus aggregated cost / token / latency.",
|
|
97
|
+
"Session and dataset endpoints are out of scope for the initial release."
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
var langfuseCredentials = {
|
|
101
|
+
secretKey: {
|
|
102
|
+
description: "Langfuse secret API key",
|
|
103
|
+
auth: "required"
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var PHASE_ORDER = ["traces", "observations_per_day", "scores"];
|
|
107
|
+
var isLangfuseSyncCursor = makeChunkedCursorGuard(PHASE_ORDER);
|
|
108
|
+
var TRACES_PAGE_SIZE = 50;
|
|
109
|
+
var METRICS_PAGE_SIZE = 50;
|
|
110
|
+
var SCORES_PAGE_SIZE = 50;
|
|
111
|
+
var CHUNK_BUDGET_MS = 25e3;
|
|
112
|
+
var DEFAULT_LOOKBACK_DAYS = 30;
|
|
113
|
+
var MS_PER_DAY = 24 * 60 * 60 * 1e3;
|
|
114
|
+
var TRACE_ENTITY = "langfuse_trace";
|
|
115
|
+
var OBSERVATIONS_METRIC = "langfuse_observations_per_day";
|
|
116
|
+
var SCORES_METRIC = "langfuse_scores";
|
|
117
|
+
var traceSchema = z.object({
|
|
118
|
+
id: z.string().min(1),
|
|
119
|
+
name: z.string().nullish(),
|
|
120
|
+
projectId: z.string().nullish(),
|
|
121
|
+
userId: z.string().nullish(),
|
|
122
|
+
sessionId: z.string().nullish(),
|
|
123
|
+
release: z.string().nullish(),
|
|
124
|
+
version: z.string().nullish(),
|
|
125
|
+
totalCost: z.number().nullish(),
|
|
126
|
+
latency: z.number().nullish(),
|
|
127
|
+
createdAt: z.string().nullish(),
|
|
128
|
+
updatedAt: z.string().nullish()
|
|
129
|
+
});
|
|
130
|
+
var tracesResponseSchema = z.object({
|
|
131
|
+
data: z.array(traceSchema),
|
|
132
|
+
meta: z.object({
|
|
133
|
+
page: z.number(),
|
|
134
|
+
limit: z.number(),
|
|
135
|
+
totalItems: z.number(),
|
|
136
|
+
totalPages: z.number()
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
var dailyUsageSchema = z.object({
|
|
140
|
+
model: z.string().nullish(),
|
|
141
|
+
inputUsage: z.number().nullish(),
|
|
142
|
+
outputUsage: z.number().nullish(),
|
|
143
|
+
totalUsage: z.number().nullish(),
|
|
144
|
+
countObservations: z.number().nullish(),
|
|
145
|
+
totalCost: z.number().nullish()
|
|
146
|
+
});
|
|
147
|
+
var dailyMetricSchema = z.object({
|
|
148
|
+
date: z.string(),
|
|
149
|
+
countTraces: z.number().nullish(),
|
|
150
|
+
countObservations: z.number().nullish(),
|
|
151
|
+
totalCost: z.number().nullish(),
|
|
152
|
+
usage: z.array(dailyUsageSchema).nullish()
|
|
153
|
+
});
|
|
154
|
+
var dailyMetricsResponseSchema = z.object({
|
|
155
|
+
data: z.array(dailyMetricSchema),
|
|
156
|
+
meta: z.object({
|
|
157
|
+
page: z.number(),
|
|
158
|
+
limit: z.number(),
|
|
159
|
+
totalItems: z.number(),
|
|
160
|
+
totalPages: z.number()
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
var scoreSchema = z.object({
|
|
164
|
+
id: z.string().min(1),
|
|
165
|
+
name: z.string().min(1),
|
|
166
|
+
value: z.number().nullish(),
|
|
167
|
+
stringValue: z.string().nullish(),
|
|
168
|
+
dataType: z.string().nullish(),
|
|
169
|
+
source: z.string().nullish(),
|
|
170
|
+
timestamp: z.string().nullish(),
|
|
171
|
+
createdAt: z.string().nullish()
|
|
172
|
+
});
|
|
173
|
+
var scoresResponseSchema = z.object({
|
|
174
|
+
data: z.array(scoreSchema),
|
|
175
|
+
meta: z.object({
|
|
176
|
+
page: z.number(),
|
|
177
|
+
limit: z.number(),
|
|
178
|
+
totalItems: z.number(),
|
|
179
|
+
totalPages: z.number()
|
|
180
|
+
})
|
|
181
|
+
});
|
|
182
|
+
var langfuseResources = defineResources({
|
|
183
|
+
langfuse_trace: {
|
|
184
|
+
shape: "entity",
|
|
185
|
+
filterable: [],
|
|
186
|
+
description: "LLM traces in the project, keyed by id, with name, owning user/session, optional release/version, aggregate cost in USD, aggregate latency in milliseconds, and the createdAt timestamp.",
|
|
187
|
+
endpoint: "GET /api/public/traces",
|
|
188
|
+
notes: "Traces upsert by id on every run. Trace input/output payloads are not stored.",
|
|
189
|
+
fields: [
|
|
190
|
+
{ name: "name", description: "Trace name set by the SDK." },
|
|
191
|
+
{
|
|
192
|
+
name: "projectId",
|
|
193
|
+
description: "Langfuse project id the trace belongs to."
|
|
194
|
+
},
|
|
195
|
+
{ name: "userId", description: "Attached userId, if any." },
|
|
196
|
+
{ name: "sessionId", description: "Attached sessionId, if any." },
|
|
197
|
+
{
|
|
198
|
+
name: "release",
|
|
199
|
+
description: "Release identifier from the SDK, if set."
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "version",
|
|
203
|
+
description: "Version identifier from the SDK, if set."
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: "totalCost",
|
|
207
|
+
description: "Aggregate trace cost in USD across all observations."
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: "latencyMs",
|
|
211
|
+
description: "End-to-end trace latency in milliseconds."
|
|
212
|
+
},
|
|
213
|
+
{ name: "createdAt", description: "ISO timestamp of trace creation." }
|
|
214
|
+
],
|
|
215
|
+
responses: { traces: tracesResponseSchema }
|
|
216
|
+
},
|
|
217
|
+
langfuse_observations_per_day: {
|
|
218
|
+
shape: "metric",
|
|
219
|
+
description: "Daily LLM observation volume, total tokens, and total cost rolled up by model from the Langfuse daily metrics endpoint. One sample per (day, model) over the lookback window.",
|
|
220
|
+
endpoint: "GET /api/public/metrics/daily",
|
|
221
|
+
unit: "observations",
|
|
222
|
+
granularity: "Daily (UTC)",
|
|
223
|
+
notes: "Rollup metrics are stamped at UTC midnight of the day they cover.",
|
|
224
|
+
dimensions: [
|
|
225
|
+
{
|
|
226
|
+
name: "model",
|
|
227
|
+
description: "The model id the observations ran against."
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: "countObservations",
|
|
231
|
+
description: "Observations recorded that day for this model."
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
name: "inputTokens",
|
|
235
|
+
description: "Input tokens consumed that day for this model."
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: "outputTokens",
|
|
239
|
+
description: "Output tokens produced that day for this model."
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: "totalTokens",
|
|
243
|
+
description: "Total tokens (input + output) for the day and model."
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: "costUsd",
|
|
247
|
+
description: "Aggregate cost in USD for the day and model."
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
responses: { observations_per_day: dailyMetricsResponseSchema }
|
|
251
|
+
},
|
|
252
|
+
langfuse_scores: {
|
|
253
|
+
shape: "metric",
|
|
254
|
+
description: "Daily Langfuse score rollups by score name. One sample per (day, name): the mean numeric value across that day and the count of scores written.",
|
|
255
|
+
endpoint: "GET /api/public/scores",
|
|
256
|
+
unit: "scores",
|
|
257
|
+
granularity: "Daily (UTC)",
|
|
258
|
+
notes: "Only numeric scores contribute to the average; non-numeric scores still increment the count.",
|
|
259
|
+
dimensions: [
|
|
260
|
+
{ name: "name", description: "Score name as set by the SDK." },
|
|
261
|
+
{
|
|
262
|
+
name: "average",
|
|
263
|
+
description: "Mean numeric score value for the day (zero if no numeric values)."
|
|
264
|
+
},
|
|
265
|
+
{ name: "count", description: "Number of scores written that day." }
|
|
266
|
+
],
|
|
267
|
+
responses: { scores: scoresResponseSchema }
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
var id = "langfuse";
|
|
271
|
+
var LangfuseConnector = class _LangfuseConnector extends BaseConnector {
|
|
272
|
+
static id = id;
|
|
273
|
+
static resources = langfuseResources;
|
|
274
|
+
static schemas = schemasFromResources(langfuseResources);
|
|
275
|
+
static create(input, ctx) {
|
|
276
|
+
const parsed = configFields.parse(input);
|
|
277
|
+
return new _LangfuseConnector(
|
|
278
|
+
{
|
|
279
|
+
publicKey: parsed.publicKey,
|
|
280
|
+
host: parsed.host,
|
|
281
|
+
lookbackDays: parsed.lookbackDays,
|
|
282
|
+
resources: parsed.resources
|
|
283
|
+
},
|
|
284
|
+
{ secretKey: parsed.secretKey },
|
|
285
|
+
ctx
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
id = id;
|
|
289
|
+
credentials = langfuseCredentials;
|
|
290
|
+
get baseUrl() {
|
|
291
|
+
return this.settings.host.replace(/\/+$/, "");
|
|
292
|
+
}
|
|
293
|
+
buildHeaders() {
|
|
294
|
+
const raw = `${this.settings.publicKey}:${this.creds.secretKey}`;
|
|
295
|
+
const basic = encodeBasicAuth(raw);
|
|
296
|
+
return {
|
|
297
|
+
Authorization: `Basic ${basic}`,
|
|
298
|
+
Accept: "application/json",
|
|
299
|
+
"User-Agent": connectorUserAgent("langfuse")
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
windowStart(options) {
|
|
303
|
+
const lookbackDays = this.settings.lookbackDays ?? DEFAULT_LOOKBACK_DAYS;
|
|
304
|
+
const now = Date.now();
|
|
305
|
+
let startMs = now - lookbackDays * MS_PER_DAY;
|
|
306
|
+
if (options.since) {
|
|
307
|
+
const sinceMs = new Date(options.since).getTime();
|
|
308
|
+
if (Number.isFinite(sinceMs) && sinceMs < startMs) {
|
|
309
|
+
startMs = sinceMs;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return new Date(startMs);
|
|
313
|
+
}
|
|
314
|
+
async fetchTracesPage(options, page, signal) {
|
|
315
|
+
const pageNum = parsePage(page);
|
|
316
|
+
const url = new URL(`${this.baseUrl}/api/public/traces`);
|
|
317
|
+
url.searchParams.set("page", String(pageNum));
|
|
318
|
+
url.searchParams.set("limit", String(TRACES_PAGE_SIZE));
|
|
319
|
+
const start = this.windowStart(options);
|
|
320
|
+
url.searchParams.set("fromTimestamp", start.toISOString());
|
|
321
|
+
const res = await this.get(url.toString(), {
|
|
322
|
+
resource: "traces",
|
|
323
|
+
headers: this.buildHeaders(),
|
|
324
|
+
signal
|
|
325
|
+
});
|
|
326
|
+
const data = res.body.data;
|
|
327
|
+
const sinceMs = options.since ? new Date(options.since).getTime() : null;
|
|
328
|
+
const allBeforeSince = sinceMs !== null && data.length > 0 && data.every((t) => {
|
|
329
|
+
const ts = parseEpoch(t.createdAt ?? null, "iso");
|
|
330
|
+
return ts !== null && ts < sinceMs;
|
|
331
|
+
});
|
|
332
|
+
const totalPages = res.body.meta?.totalPages ?? 0;
|
|
333
|
+
const next = !allBeforeSince && data.length > 0 && pageNum < totalPages ? String(pageNum + 1) : null;
|
|
334
|
+
return { items: data, next };
|
|
335
|
+
}
|
|
336
|
+
async writeTraces(storage, items) {
|
|
337
|
+
for (const trace of items) {
|
|
338
|
+
const createdAt = parseEpoch(trace.createdAt ?? null, "iso") ?? 0;
|
|
339
|
+
const updatedAt = parseEpoch(trace.updatedAt ?? null, "iso") ?? createdAt;
|
|
340
|
+
await storage.entity({
|
|
341
|
+
type: TRACE_ENTITY,
|
|
342
|
+
id: trace.id,
|
|
343
|
+
attributes: {
|
|
344
|
+
name: trace.name ?? null,
|
|
345
|
+
projectId: trace.projectId ?? null,
|
|
346
|
+
userId: trace.userId ?? null,
|
|
347
|
+
sessionId: trace.sessionId ?? null,
|
|
348
|
+
release: trace.release ?? null,
|
|
349
|
+
version: trace.version ?? null,
|
|
350
|
+
totalCost: finiteNumberOrNull(trace.totalCost),
|
|
351
|
+
latencyMs: finiteNumberOrNull(trace.latency),
|
|
352
|
+
createdAt: trace.createdAt ?? null
|
|
353
|
+
},
|
|
354
|
+
updated_at: updatedAt
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async fetchDailyMetricsPage(options, page, signal) {
|
|
359
|
+
const pageNum = parsePage(page);
|
|
360
|
+
const url = new URL(`${this.baseUrl}/api/public/metrics/daily`);
|
|
361
|
+
url.searchParams.set("page", String(pageNum));
|
|
362
|
+
url.searchParams.set("limit", String(METRICS_PAGE_SIZE));
|
|
363
|
+
const start = this.windowStart(options);
|
|
364
|
+
url.searchParams.set("fromTimestamp", start.toISOString());
|
|
365
|
+
const res = await this.get(url.toString(), {
|
|
366
|
+
resource: "observations_per_day",
|
|
367
|
+
headers: this.buildHeaders(),
|
|
368
|
+
signal
|
|
369
|
+
});
|
|
370
|
+
const data = res.body.data;
|
|
371
|
+
const totalPages = res.body.meta?.totalPages ?? 0;
|
|
372
|
+
const next = data.length > 0 && pageNum < totalPages ? String(pageNum + 1) : null;
|
|
373
|
+
return { items: data, next };
|
|
374
|
+
}
|
|
375
|
+
async writeDailyMetrics(storage, items) {
|
|
376
|
+
for (const row of items) {
|
|
377
|
+
const ts = dateStringToMs(row.date);
|
|
378
|
+
if (ts === null) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const usage = row.usage ?? [];
|
|
382
|
+
if (usage.length === 0) {
|
|
383
|
+
const count = finiteNumber(row.countObservations);
|
|
384
|
+
await storage.metric({
|
|
385
|
+
name: OBSERVATIONS_METRIC,
|
|
386
|
+
ts,
|
|
387
|
+
value: count,
|
|
388
|
+
attributes: {
|
|
389
|
+
model: null,
|
|
390
|
+
countObservations: count,
|
|
391
|
+
inputTokens: 0,
|
|
392
|
+
outputTokens: 0,
|
|
393
|
+
totalTokens: 0,
|
|
394
|
+
costUsd: finiteNumber(row.totalCost)
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
for (const entry of usage) {
|
|
400
|
+
const count = finiteNumber(entry.countObservations);
|
|
401
|
+
const input = finiteNumber(entry.inputUsage);
|
|
402
|
+
const output = finiteNumber(entry.outputUsage);
|
|
403
|
+
const totalTokens = entry.totalUsage !== null && entry.totalUsage !== void 0 ? finiteNumber(entry.totalUsage) : input + output;
|
|
404
|
+
await storage.metric({
|
|
405
|
+
name: OBSERVATIONS_METRIC,
|
|
406
|
+
ts,
|
|
407
|
+
value: count,
|
|
408
|
+
attributes: {
|
|
409
|
+
model: entry.model ?? null,
|
|
410
|
+
countObservations: count,
|
|
411
|
+
inputTokens: input,
|
|
412
|
+
outputTokens: output,
|
|
413
|
+
totalTokens,
|
|
414
|
+
costUsd: finiteNumber(entry.totalCost)
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async fetchScoresPage(options, page, signal) {
|
|
421
|
+
const pageNum = parsePage(page);
|
|
422
|
+
const url = new URL(`${this.baseUrl}/api/public/scores`);
|
|
423
|
+
url.searchParams.set("page", String(pageNum));
|
|
424
|
+
url.searchParams.set("limit", String(SCORES_PAGE_SIZE));
|
|
425
|
+
const start = this.windowStart(options);
|
|
426
|
+
url.searchParams.set("fromTimestamp", start.toISOString());
|
|
427
|
+
const res = await this.get(url.toString(), {
|
|
428
|
+
resource: "scores",
|
|
429
|
+
headers: this.buildHeaders(),
|
|
430
|
+
signal
|
|
431
|
+
});
|
|
432
|
+
const data = res.body.data;
|
|
433
|
+
const sinceMs = options.since ? new Date(options.since).getTime() : null;
|
|
434
|
+
const allBeforeSince = sinceMs !== null && data.length > 0 && data.every((s) => {
|
|
435
|
+
const ts = parseEpoch(s.timestamp ?? null, "iso") ?? parseEpoch(s.createdAt ?? null, "iso");
|
|
436
|
+
return ts !== null && ts < sinceMs;
|
|
437
|
+
});
|
|
438
|
+
const totalPages = res.body.meta?.totalPages ?? 0;
|
|
439
|
+
const next = !allBeforeSince && data.length > 0 && pageNum < totalPages ? String(pageNum + 1) : null;
|
|
440
|
+
return { items: data, next };
|
|
441
|
+
}
|
|
442
|
+
async writeScores(storage, items) {
|
|
443
|
+
const byDayName = /* @__PURE__ */ new Map();
|
|
444
|
+
for (const score of items) {
|
|
445
|
+
const ts = parseEpoch(score.timestamp ?? null, "iso") ?? parseEpoch(score.createdAt ?? null, "iso");
|
|
446
|
+
if (ts === null) {
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const day = startOfUtcDay(ts);
|
|
450
|
+
const key = `${day}|${score.name}`;
|
|
451
|
+
const prev = byDayName.get(key) ?? { count: 0, sum: 0, numericCount: 0 };
|
|
452
|
+
prev.count += 1;
|
|
453
|
+
if (typeof score.value === "number" && Number.isFinite(score.value)) {
|
|
454
|
+
prev.sum += score.value;
|
|
455
|
+
prev.numericCount += 1;
|
|
456
|
+
}
|
|
457
|
+
byDayName.set(key, prev);
|
|
458
|
+
}
|
|
459
|
+
for (const [key, acc] of byDayName) {
|
|
460
|
+
const sep = key.indexOf("|");
|
|
461
|
+
const dayMs = Number(key.slice(0, sep));
|
|
462
|
+
const name = key.slice(sep + 1);
|
|
463
|
+
const average = acc.numericCount > 0 ? acc.sum / acc.numericCount : 0;
|
|
464
|
+
await storage.metric({
|
|
465
|
+
name: SCORES_METRIC,
|
|
466
|
+
ts: dayMs,
|
|
467
|
+
value: average,
|
|
468
|
+
attributes: {
|
|
469
|
+
name,
|
|
470
|
+
average,
|
|
471
|
+
count: acc.count
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
async clearScopeOnFirstPage(storage, phase, isFull) {
|
|
477
|
+
switch (phase) {
|
|
478
|
+
case "traces":
|
|
479
|
+
if (isFull) {
|
|
480
|
+
await storage.entities([], { types: [TRACE_ENTITY] });
|
|
481
|
+
}
|
|
482
|
+
return;
|
|
483
|
+
case "observations_per_day":
|
|
484
|
+
await storage.metrics([], { names: [OBSERVATIONS_METRIC] });
|
|
485
|
+
return;
|
|
486
|
+
case "scores":
|
|
487
|
+
await storage.metrics([], { names: [SCORES_METRIC] });
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
async writePhase(storage, phase, items) {
|
|
492
|
+
switch (phase) {
|
|
493
|
+
case "traces":
|
|
494
|
+
await this.writeTraces(storage, items);
|
|
495
|
+
return;
|
|
496
|
+
case "observations_per_day":
|
|
497
|
+
await this.writeDailyMetrics(storage, items);
|
|
498
|
+
return;
|
|
499
|
+
case "scores":
|
|
500
|
+
await this.writeScores(storage, items);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
async sync(options, storage, signal) {
|
|
505
|
+
const cursor = isLangfuseSyncCursor(options.cursor) ? options.cursor : void 0;
|
|
506
|
+
const isFull = options.mode === "full";
|
|
507
|
+
const phases = selectActivePhases(
|
|
508
|
+
(r) => r,
|
|
509
|
+
PHASE_ORDER,
|
|
510
|
+
this.settings.resources
|
|
511
|
+
);
|
|
512
|
+
return paginateChunked({
|
|
513
|
+
phases,
|
|
514
|
+
cursor,
|
|
515
|
+
signal,
|
|
516
|
+
logger: this.logger,
|
|
517
|
+
maxChunkMs: CHUNK_BUDGET_MS,
|
|
518
|
+
fetchPage: async (phase, page, sig) => {
|
|
519
|
+
switch (phase) {
|
|
520
|
+
case "traces":
|
|
521
|
+
return this.fetchTracesPage(options, page, sig);
|
|
522
|
+
case "observations_per_day":
|
|
523
|
+
return this.fetchDailyMetricsPage(options, page, sig);
|
|
524
|
+
case "scores":
|
|
525
|
+
return this.fetchScoresPage(options, page, sig);
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
writeBatch: async (phase, items, page) => {
|
|
529
|
+
if (page === null) {
|
|
530
|
+
await this.clearScopeOnFirstPage(storage, phase, isFull);
|
|
531
|
+
}
|
|
532
|
+
await this.writePhase(storage, phase, items);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
function parsePage(page) {
|
|
538
|
+
if (page === null) {
|
|
539
|
+
return 1;
|
|
540
|
+
}
|
|
541
|
+
const n = Number(page);
|
|
542
|
+
return Number.isFinite(n) && n >= 1 ? Math.floor(n) : 1;
|
|
543
|
+
}
|
|
544
|
+
function finiteNumber(value, fallback = 0) {
|
|
545
|
+
if (value === null || value === void 0) {
|
|
546
|
+
return fallback;
|
|
547
|
+
}
|
|
548
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
549
|
+
return Number.isFinite(n) ? n : fallback;
|
|
550
|
+
}
|
|
551
|
+
function finiteNumberOrNull(value) {
|
|
552
|
+
if (value === null || value === void 0 || value === "") {
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
556
|
+
return Number.isFinite(n) ? n : null;
|
|
557
|
+
}
|
|
558
|
+
function dateStringToMs(value) {
|
|
559
|
+
if (typeof value !== "string") {
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
const trimmed = value.trim();
|
|
563
|
+
if (trimmed === "") {
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
const isoLike = /^\d{4}-\d{2}-\d{2}$/.test(trimmed) ? `${trimmed}T00:00:00.000Z` : trimmed;
|
|
567
|
+
return parseEpoch(isoLike, "iso");
|
|
568
|
+
}
|
|
569
|
+
function startOfUtcDay(ms) {
|
|
570
|
+
return Math.floor(ms / MS_PER_DAY) * MS_PER_DAY;
|
|
571
|
+
}
|
|
572
|
+
function encodeBasicAuth(raw) {
|
|
573
|
+
if (typeof btoa === "function") {
|
|
574
|
+
return btoa(raw);
|
|
575
|
+
}
|
|
576
|
+
const bufferCtor = globalThis.Buffer;
|
|
577
|
+
if (bufferCtor) {
|
|
578
|
+
return bufferCtor.from(raw).toString("base64");
|
|
579
|
+
}
|
|
580
|
+
throw new Error("No base64 encoder available in this runtime");
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// src/index.ts
|
|
584
|
+
var index_default = LangfuseConnector;
|
|
585
|
+
export {
|
|
586
|
+
LangfuseConnector,
|
|
587
|
+
configFields,
|
|
588
|
+
index_default as default,
|
|
589
|
+
doc,
|
|
590
|
+
id,
|
|
591
|
+
langfuseResources as resources
|
|
592
|
+
};
|
|
593
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../connector-shared/src/errors.ts","../../../connector-shared/src/retry.ts","../../../connector-shared/src/version.ts","../../../connector-shared/src/request.ts","../../../connector-shared/src/rate-limit.ts","../../../connector-shared/src/map-concurrent.ts","../../../connector-shared/src/sanitize.ts","../../../connector-shared/src/epoch.ts","../../../connector-shared/src/pagination.ts","../../../connector-shared/src/logger.ts","../src/langfuse.ts","../src/index.ts"],"sourcesContent":["import type { HttpResponse } from './types';\n\nexport type HttpErrorKind =\n | 'transient'\n | 'rate_limit'\n | 'auth'\n | 'upstream_bug'\n | 'client_bug';\n\nexport abstract class HttpClientError extends Error {\n abstract readonly kind: HttpErrorKind;\n readonly response?: HttpResponse;\n\n constructor(message: string, response?: HttpResponse) {\n super(message);\n this.name = new.target.name;\n this.response = response;\n }\n}\n\nexport class TransientError extends HttpClientError {\n readonly kind = 'transient' as const;\n}\n\nexport class RateLimitError extends HttpClientError {\n readonly kind = 'rate_limit' as const;\n readonly retryAfter?: Date;\n\n constructor(message: string, response?: HttpResponse, retryAfter?: Date) {\n super(message, response);\n this.retryAfter = retryAfter;\n }\n}\n\nexport class AuthError extends HttpClientError {\n readonly kind = 'auth' as const;\n}\n\nexport class UpstreamBugError extends HttpClientError {\n readonly kind = 'upstream_bug' as const;\n}\n\nexport class ClientBugError extends HttpClientError {\n readonly kind = 'client_bug' as const;\n}\n\nexport function classifyStatus(status: number): HttpErrorKind {\n if (status === 429) {\n return 'rate_limit';\n }\n if (status === 401 || status === 403) {\n return 'auth';\n }\n if (status === 408) {\n return 'transient';\n }\n if (status >= 500) {\n return 'upstream_bug';\n }\n if (status >= 400) {\n return 'client_bug';\n }\n return 'client_bug';\n}\n\nexport function errorForStatus(\n message: string,\n response: HttpResponse,\n retryAfter?: Date,\n): HttpClientError {\n const kind = classifyStatus(response.status);\n switch (kind) {\n case 'rate_limit':\n return new RateLimitError(message, response, retryAfter);\n case 'auth':\n return new AuthError(message, response);\n case 'transient':\n return new TransientError(message, response);\n case 'upstream_bug':\n return new UpstreamBugError(message, response);\n case 'client_bug':\n return new ClientBugError(message, response);\n }\n}\n","import { HttpClientError, RateLimitError, TransientError } from './errors';\n\nexport interface RetryPolicy {\n maxAttempts?: number;\n initialDelayMs?: number;\n maxDelayMs?: number;\n retryOn?: (status: number | null, err?: Error) => boolean;\n}\n\nexport const defaultRetryOn = (status: number | null, err?: Error): boolean => {\n if (err instanceof RateLimitError) {\n return true;\n }\n if (err instanceof TransientError) {\n return true;\n }\n if (status === null) {\n return err instanceof Error && !(err instanceof HttpClientError);\n }\n if (status === 408 || status === 429) {\n return true;\n }\n if (status >= 500) {\n return true;\n }\n return false;\n};\n\nexport function backoffDelayMs(\n attempt: number,\n policy: Required<Pick<RetryPolicy, 'initialDelayMs' | 'maxDelayMs'>>,\n): number {\n const base = policy.initialDelayMs * 2 ** attempt;\n const jitter = base * 0.25 * Math.random();\n return Math.min(base + jitter, policy.maxDelayMs);\n}\n\nexport function parseRetryAfter(\n headerValue: string | null,\n now: Date = new Date(),\n): Date | undefined {\n if (!headerValue) {\n return undefined;\n }\n const trimmed = headerValue.trim();\n if (/^\\d+$/.test(trimmed)) {\n return new Date(now.getTime() + Number(trimmed) * 1000);\n }\n const parsed = Date.parse(trimmed);\n if (Number.isNaN(parsed)) {\n return undefined;\n }\n return new Date(parsed);\n}\n\nexport function sleep(ms: number, signal?: AbortSignal): Promise<void> {\n if (signal?.aborted) {\n return Promise.reject(signal.reason ?? new Error('Aborted'));\n }\n return new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal!.reason ?? new Error('Aborted'));\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","export const HTTP_CLIENT_VERSION = '0.0.0';\n\nexport const DEFAULT_USER_AGENT = `rawdash-connector/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;\n\nexport function connectorUserAgent(connectorId: string): string {\n return `rawdash-connector-${connectorId}/${HTTP_CLIENT_VERSION} (+https://rawdash.dev)`;\n}\n","import {\n AuthError,\n ClientBugError,\n HttpClientError,\n RateLimitError,\n TransientError,\n UpstreamBugError,\n errorForStatus,\n} from './errors';\nimport { defaultRetryOn, parseRetryAfter, sleep } from './retry';\nimport type { FetchLike, HttpMethod, HttpRequest, HttpResponse } from './types';\nimport { DEFAULT_USER_AGENT } from './version';\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\nconst DEFAULT_MAX_ATTEMPTS = 3;\nconst DEFAULT_INITIAL_DELAY_MS = 1000;\nconst DEFAULT_MAX_DELAY_MS = 60_000;\nconst OBSERVER_TIMEOUT_MS = 250;\n\nexport interface RequestObservation {\n url: string;\n method: HttpMethod;\n status: number;\n resource: string;\n requestId: string;\n body: unknown;\n}\n\nexport type RequestObserver = (\n event: RequestObservation,\n) => void | Promise<void>;\n\nexport interface RequestOptions {\n fetch?: FetchLike;\n observer?: RequestObserver;\n resource: string;\n requestId?: string;\n}\n\nasync function notifyObserver(\n observer: RequestObserver,\n event: RequestObservation,\n): Promise<void> {\n let result: void | Promise<void>;\n try {\n result = observer(event);\n } catch (err) {\n console.warn('[connector-shared] request observer threw:', err);\n return;\n }\n if (!(result instanceof Promise)) {\n return;\n }\n const guarded = result.catch((err) => {\n console.warn('[connector-shared] request observer rejected:', err);\n });\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<void>((resolve) => {\n timer = setTimeout(resolve, OBSERVER_TIMEOUT_MS);\n });\n try {\n await Promise.race([guarded, timeout]);\n } finally {\n if (timer) {\n clearTimeout(timer);\n }\n }\n}\n\nfunction newRequestId(): string {\n const c = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto;\n if (c?.randomUUID) {\n return c.randomUUID();\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n}\n\nfunction mergeHeaders(\n defaults: Record<string, string>,\n overrides: Record<string, string> | undefined,\n): Record<string, string> {\n const merged: Record<string, string> = {};\n for (const [k, v] of Object.entries(defaults)) {\n merged[k.toLowerCase()] = v;\n }\n if (overrides) {\n for (const [k, v] of Object.entries(overrides)) {\n merged[k.toLowerCase()] = v;\n }\n }\n return merged;\n}\n\nfunction linkTimeoutSignal(\n parent: AbortSignal | undefined,\n timeoutMs: number,\n): { signal: AbortSignal; cancel: () => void } {\n const controller = new AbortController();\n const onParentAbort = () => {\n controller.abort(parent?.reason);\n };\n if (parent) {\n if (parent.aborted) {\n controller.abort(parent.reason);\n } else {\n parent.addEventListener('abort', onParentAbort, { once: true });\n }\n }\n const timer = setTimeout(() => {\n controller.abort(new Error(`Request timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n return {\n signal: controller.signal,\n cancel: () => {\n clearTimeout(timer);\n if (parent) {\n parent.removeEventListener('abort', onParentAbort);\n }\n },\n };\n}\n\nasync function readBody(res: Response, parseJson: boolean): Promise<unknown> {\n if (res.status === 204 || res.status === 205) {\n return null;\n }\n const contentType = res.headers.get('content-type') ?? '';\n if (parseJson && contentType.includes('application/json')) {\n const text = await res.text();\n if (text.length === 0) {\n return null;\n }\n return JSON.parse(text);\n }\n return res.text();\n}\n\nexport async function request<T = unknown>(\n req: HttpRequest,\n options: RequestOptions,\n): Promise<HttpResponse<T>> {\n const fetchImpl: FetchLike = options.fetch ?? (globalThis.fetch as FetchLike);\n const retry = req.retry ?? {};\n const maxAttempts = retry.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;\n const initialDelayMs = retry.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;\n const maxDelayMs = retry.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;\n const retryOn = retry.retryOn ?? defaultRetryOn;\n const timeoutMs = req.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const parseJson = req.parseJson ?? true;\n\n const headers = mergeHeaders(\n {\n 'User-Agent': DEFAULT_USER_AGENT,\n Accept: 'application/json',\n },\n req.headers,\n );\n\n let lastErr: Error | undefined;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n req.signal?.throwIfAborted();\n\n const { signal, cancel } = linkTimeoutSignal(req.signal, timeoutMs);\n let res: Response;\n try {\n res = await fetchImpl(req.url, {\n method: req.method ?? 'GET',\n headers,\n body: req.body as RequestInit['body'],\n signal,\n });\n } catch (err) {\n cancel();\n if (req.signal?.aborted) {\n throw req.signal.reason ?? err;\n }\n const error = err instanceof Error ? err : new Error(String(err));\n lastErr = error;\n if (attempt < maxAttempts - 1 && retryOn(null, error)) {\n const delay = computeDelay(attempt, initialDelayMs, maxDelayMs);\n await sleep(delay, req.signal);\n continue;\n }\n throw new TransientError(error.message);\n }\n cancel();\n\n const body = await readBody(res, parseJson);\n const httpResponse: HttpResponse<T> = {\n status: res.status,\n headers: res.headers,\n body: body as T,\n };\n if (req.rateLimit) {\n const state = req.rateLimit.parse(res.headers);\n if (state) {\n httpResponse.rateLimitState = state;\n }\n }\n\n if (options.observer) {\n await notifyObserver(options.observer, {\n url: req.url,\n method: req.method ?? 'GET',\n status: res.status,\n resource: options.resource,\n requestId: options.requestId ?? newRequestId(),\n body,\n });\n }\n\n if (res.ok) {\n return httpResponse;\n }\n\n const retryAfter = parseRetryAfter(res.headers.get('retry-after'));\n const message = `HTTP ${res.status} ${res.statusText} for ${req.method ?? 'GET'} ${req.url}`;\n const err = errorForStatus(message, httpResponse, retryAfter);\n\n if (\n attempt < maxAttempts - 1 &&\n retryOn(res.status, err) &&\n !(err instanceof AuthError) &&\n !(err instanceof ClientBugError)\n ) {\n lastErr = err;\n let delay = computeDelay(attempt, initialDelayMs, maxDelayMs);\n if (err instanceof RateLimitError && retryAfter) {\n const wait = retryAfter.getTime() - Date.now();\n if (wait > 0) {\n delay = Math.min(wait, maxDelayMs);\n }\n }\n await sleep(delay, req.signal);\n continue;\n }\n\n throw err;\n }\n\n throw lastErr ?? new UpstreamBugError('Exhausted retry attempts');\n}\n\nfunction computeDelay(\n attempt: number,\n initialDelayMs: number,\n maxDelayMs: number,\n): number {\n const base = initialDelayMs * 2 ** attempt;\n const jitter = base * 0.25 * Math.random();\n return Math.min(base + jitter, maxDelayMs);\n}\n\nexport { HttpClientError };\n","export interface RateLimitState {\n remaining: number;\n resetAt: Date;\n}\n\nexport interface RateLimitPolicy {\n parse(headers: Headers): RateLimitState | null;\n}\n\nexport interface StandardRateLimitPolicyConfig {\n remainingHeader: string;\n resetHeader: string;\n resetUnit: 's' | 'ms';\n resetFallbackMs?: number;\n}\n\nexport function standardRateLimitPolicy(\n config: StandardRateLimitPolicyConfig,\n): RateLimitPolicy {\n const { remainingHeader, resetHeader, resetUnit, resetFallbackMs } = config;\n const multiplier = resetUnit === 's' ? 1000 : 1;\n return {\n parse(h) {\n const remainingRaw = h.get(remainingHeader);\n if (remainingRaw === null || remainingRaw.trim() === '') {\n return null;\n }\n const remaining = Number(remainingRaw);\n if (!Number.isFinite(remaining)) {\n return null;\n }\n const resetRaw = h.get(resetHeader);\n if (resetRaw === null) {\n if (resetFallbackMs === undefined) {\n return null;\n }\n return {\n remaining,\n resetAt: new Date(Date.now() + resetFallbackMs),\n };\n }\n if (resetRaw.trim() === '') {\n return null;\n }\n const reset = Number(resetRaw);\n if (!Number.isFinite(reset) || reset < 0) {\n return null;\n }\n const resetMs = reset * multiplier;\n if (!Number.isFinite(resetMs)) {\n return null;\n }\n return { remaining, resetAt: new Date(resetMs) };\n },\n };\n}\n","export async function mapWithConcurrency<T, R>(\n items: readonly T[],\n concurrency: number,\n fn: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const results = new Array<R>(items.length);\n if (items.length === 0) {\n return results;\n }\n const normalized = Number.isFinite(concurrency) ? Math.floor(concurrency) : 1;\n const limit = Math.max(1, Math.min(normalized, items.length));\n let next = 0;\n let failed = false;\n\n async function worker(): Promise<void> {\n while (!failed) {\n const i = next++;\n if (i >= items.length) {\n return;\n }\n try {\n results[i] = await fn(items[i]!, i);\n } catch (err) {\n failed = true;\n throw err;\n }\n }\n }\n\n const workers: Promise<void>[] = [];\n for (let w = 0; w < limit; w++) {\n workers.push(worker());\n }\n await Promise.all(workers);\n return results;\n}\n","export interface SanitizeAllowedUrlOptions {\n url: string | null;\n host: string;\n pathname: string;\n protocol?: 'https:' | 'http:';\n}\n\nexport function sanitizeAllowedUrl(\n options: SanitizeAllowedUrlOptions,\n): string | null {\n const { url, host, pathname, protocol = 'https:' } = options;\n if (url === null) {\n return null;\n }\n try {\n const u = new URL(url);\n if (u.protocol !== protocol || u.host !== host || u.pathname !== pathname) {\n return null;\n }\n return u.toString();\n } catch {\n return null;\n }\n}\n","export type EpochUnit = 'ms' | 's' | 'iso';\n\nexport function parseEpoch(\n value: number | string | null | undefined,\n unit: EpochUnit,\n): number | null {\n if (value === null || value === undefined) {\n return null;\n }\n if (unit === 'iso') {\n if (typeof value !== 'string') {\n return null;\n }\n const ms = new Date(value).getTime();\n return Number.isFinite(ms) ? ms : null;\n }\n if (typeof value === 'string' && value.trim() === '') {\n return null;\n }\n const n = typeof value === 'number' ? value : Number(value);\n if (!Number.isFinite(n)) {\n return null;\n }\n const result = unit === 's' ? n * 1000 : n;\n return Number.isFinite(result) ? result : null;\n}\n","import { request } from './request';\nimport type { HttpRequest } from './types';\n\nexport function parseLinkHeader(header: string | null): Record<string, string> {\n if (!header) {\n return {};\n }\n const result: Record<string, string> = {};\n for (const part of header.split(',')) {\n const match = part.match(/<([^>]+)>\\s*;\\s*rel=\"([^\"]+)\"/);\n if (match) {\n result[match[2]!] = match[1]!;\n }\n }\n return result;\n}\n\nexport async function* paginateLink<T>(\n initial: HttpRequest,\n parse: (body: unknown) => T[],\n options: { resource: string },\n): AsyncIterable<T> {\n let next: string | null = initial.url;\n while (next) {\n const res: Awaited<ReturnType<typeof request>> = await request(\n {\n ...initial,\n url: next,\n },\n { resource: options.resource },\n );\n for (const item of parse(res.body)) {\n yield item;\n }\n const links = parseLinkHeader(res.headers.get('link'));\n next = links['next'] ?? null;\n }\n}\n\nexport async function* paginateCursor<T>(\n initial: HttpRequest,\n parse: (body: unknown) => { items: T[]; nextCursor: string | null },\n buildNext: (req: HttpRequest, cursor: string) => HttpRequest,\n options: { resource: string },\n): AsyncIterable<T> {\n let req: HttpRequest = initial;\n while (true) {\n const res = await request(req, { resource: options.resource });\n const { items, nextCursor } = parse(res.body);\n for (const item of items) {\n yield item;\n }\n if (!nextCursor) {\n return;\n }\n req = buildNext(req, nextCursor);\n }\n}\n\nexport async function* paginatePage<T>(\n initial: HttpRequest,\n parse: (body: unknown) => { items: T[]; hasMore: boolean },\n buildPage: (req: HttpRequest, page: number) => HttpRequest,\n options: { resource: string },\n): AsyncIterable<T> {\n let page = 1;\n while (true) {\n const req = page === 1 ? initial : buildPage(initial, page);\n const res = await request(req, { resource: options.resource });\n const { items, hasMore } = parse(res.body);\n for (const item of items) {\n yield item;\n }\n if (!hasMore || items.length === 0) {\n return;\n }\n page++;\n }\n}\n","export type LogFields = Record<string, unknown>;\n\nexport interface ConnectorLogger {\n info(event: string, fields?: LogFields): void;\n warn(event: string, fields?: LogFields): void;\n}\n\nexport interface ConnectorLoggerOptions {\n scope: string;\n}\n\nconst MAX_VALUE_LEN = 120;\n\nfunction truncate(s: string, max = MAX_VALUE_LEN): string {\n if (s.length <= max) {\n return s;\n }\n return `${s.slice(0, max - 1)}…`;\n}\n\nfunction formatValue(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return '';\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (typeof value === 'string') {\n const t = truncate(value);\n if (/[\\s\"=]/.test(t)) {\n return JSON.stringify(t);\n }\n return t;\n }\n if (typeof value === 'bigint') {\n return value.toString();\n }\n let json: string | undefined;\n try {\n json = JSON.stringify(value);\n } catch {\n json = undefined;\n }\n return truncate(json ?? String(value));\n}\n\nexport function formatLogFields(fields?: LogFields): string {\n if (!fields) {\n return '';\n }\n const parts: string[] = [];\n for (const [k, v] of Object.entries(fields)) {\n if (v === undefined) {\n continue;\n }\n parts.push(`${k}=${formatValue(v)}`);\n }\n return parts.length > 0 ? ` ${parts.join(' ')}` : '';\n}\n\nexport function formatLogLine(\n scope: string,\n event: string,\n fields?: LogFields,\n): string {\n return `[${scope}] ${event}${formatLogFields(fields)}`;\n}\n\nexport function createDefaultConnectorLogger(\n opts: ConnectorLoggerOptions,\n): ConnectorLogger {\n return {\n info(event, fields) {\n console.info(formatLogLine(opts.scope, event, fields));\n },\n warn(event, fields) {\n console.warn(formatLogLine(opts.scope, event, fields));\n },\n };\n}\n\nconst NOOP_LOGGER: ConnectorLogger = {\n info() {},\n warn() {},\n};\n\nexport function noopConnectorLogger(): ConnectorLogger {\n return NOOP_LOGGER;\n}\n","import { connectorUserAgent, parseEpoch } from '@rawdash/connector-shared';\nimport {\n BaseConnector,\n type ConnectorContext,\n type ConnectorDoc,\n type CredentialsSchema,\n type StorageHandle,\n type SyncOptions,\n type SyncResult,\n defineConfigFields,\n defineConnectorDoc,\n defineResources,\n makeChunkedCursorGuard,\n paginateChunked,\n schemasFromResources,\n selectActivePhases,\n} from '@rawdash/core';\nimport { z } from 'zod';\n\nexport const configFields = defineConfigFields(\n z.object({\n publicKey: z.string().trim().min(1).meta({\n label: 'Public key',\n description:\n 'Langfuse public API key for the project (starts with `pk-lf-`). Created in Langfuse -> Settings -> API Keys.',\n placeholder: 'pk-lf-...',\n }),\n secretKey: z.object({ $secret: z.string() }).meta({\n label: 'Secret key',\n description:\n 'Langfuse secret API key for the project (starts with `sk-lf-`). Issued alongside the public key in Langfuse -> Settings -> API Keys.',\n placeholder: 'sk-lf-...',\n secret: true,\n }),\n host: z\n .string()\n .trim()\n .regex(\n /^https?:\\/\\/[^\\s/]+$/,\n 'Use a base URL with protocol and no trailing slash, e.g. https://cloud.langfuse.com',\n )\n .default('https://cloud.langfuse.com')\n .meta({\n label: 'Host',\n description:\n 'Langfuse instance base URL. Use https://cloud.langfuse.com (US) or https://us.cloud.langfuse.com / https://eu.cloud.langfuse.com for Langfuse Cloud, or your self-hosted origin. No trailing slash.',\n placeholder: 'https://cloud.langfuse.com',\n }),\n lookbackDays: z.number().int().positive().optional().meta({\n label: 'Lookback days (full sync)',\n description:\n 'How many calendar days of history to backfill on a full sync. Defaults to 30.',\n placeholder: '30',\n }),\n resources: z\n .array(z.enum(['traces', 'observations_per_day', 'scores']))\n .nonempty()\n .optional()\n .meta({\n label: 'Resources',\n description:\n 'Which Langfuse resources to sync. Omit to sync all of them.',\n }),\n }),\n);\n\nexport const doc: ConnectorDoc = defineConnectorDoc({\n displayName: 'Langfuse',\n category: 'engineering',\n brandColor: '#1F2937',\n tagline:\n 'Sync LLM traces, daily observation volume and cost by model, and feedback scores from a Langfuse project.',\n vendor: {\n name: 'Langfuse',\n domain: 'langfuse.com',\n apiDocs: 'https://api.reference.langfuse.com',\n website: 'https://langfuse.com',\n },\n auth: {\n summary:\n 'A Langfuse public + secret API key pair scoped to one project is required. The connector authenticates over HTTP Basic auth (`publicKey:secretKey`).',\n setup: [\n 'Open Langfuse -> Settings -> API Keys and create a new key pair for the project you want to sync.',\n 'Copy both the public key (`pk-lf-...`) and the secret key (`sk-lf-...`). The secret is shown once.',\n 'Set `host` to your instance base URL - `https://cloud.langfuse.com` (or the US/EU regional variants) for Langfuse Cloud, or your self-hosted origin (no trailing slash).',\n 'Store the secret as a secret and reference it from config as `secretKey: secret(\"LANGFUSE_SECRET_KEY\")`, alongside the plaintext `publicKey`.',\n ],\n },\n rateLimit:\n 'Langfuse Cloud applies per-project rate limits (around 1000 requests/min on paid plans); 429 responses with Retry-After are honored.',\n limitations: [\n 'One key pair scopes the sync to a single Langfuse project; sync multiple projects by adding one connector instance per project.',\n 'Trace bodies (input/output payloads) are not synced - only the trace envelope plus aggregated cost / token / latency.',\n 'Session and dataset endpoints are out of scope for the initial release.',\n ],\n});\n\nexport interface LangfuseSettings {\n publicKey: string;\n host: string;\n lookbackDays?: number;\n resources?: readonly LangfuseResource[];\n}\n\nconst langfuseCredentials = {\n secretKey: {\n description: 'Langfuse secret API key',\n auth: 'required' as const,\n },\n} satisfies CredentialsSchema;\n\ntype LangfuseCredentials = typeof langfuseCredentials;\n\nconst PHASE_ORDER = ['traces', 'observations_per_day', 'scores'] as const;\n\ntype LangfusePhase = (typeof PHASE_ORDER)[number];\n\nexport type LangfuseResource = LangfusePhase;\n\nconst isLangfuseSyncCursor = makeChunkedCursorGuard(PHASE_ORDER);\n\nconst TRACES_PAGE_SIZE = 50;\nconst METRICS_PAGE_SIZE = 50;\nconst SCORES_PAGE_SIZE = 50;\nconst CHUNK_BUDGET_MS = 25_000;\nconst DEFAULT_LOOKBACK_DAYS = 30;\nconst MS_PER_DAY = 24 * 60 * 60 * 1000;\n\nconst TRACE_ENTITY = 'langfuse_trace';\nconst OBSERVATIONS_METRIC = 'langfuse_observations_per_day';\nconst SCORES_METRIC = 'langfuse_scores';\n\ninterface TraceRecord {\n id: string;\n name?: string | null;\n projectId?: string | null;\n userId?: string | null;\n sessionId?: string | null;\n release?: string | null;\n version?: string | null;\n totalCost?: number | null;\n latency?: number | null;\n createdAt?: string | null;\n updatedAt?: string | null;\n}\n\ninterface TracesListResponse {\n data: TraceRecord[];\n meta: { page: number; limit: number; totalItems: number; totalPages: number };\n}\n\ninterface DailyUsage {\n model?: string | null;\n inputUsage?: number | null;\n outputUsage?: number | null;\n totalUsage?: number | null;\n countObservations?: number | null;\n totalCost?: number | null;\n}\n\ninterface DailyMetricRecord {\n date: string;\n countTraces?: number | null;\n countObservations?: number | null;\n totalCost?: number | null;\n usage?: DailyUsage[] | null;\n}\n\ninterface DailyMetricsResponse {\n data: DailyMetricRecord[];\n meta: { page: number; limit: number; totalItems: number; totalPages: number };\n}\n\ninterface ScoreRecord {\n id: string;\n name: string;\n value?: number | null;\n stringValue?: string | null;\n dataType?: string | null;\n source?: string | null;\n timestamp?: string | null;\n createdAt?: string | null;\n}\n\ninterface ScoresListResponse {\n data: ScoreRecord[];\n meta: { page: number; limit: number; totalItems: number; totalPages: number };\n}\n\nconst traceSchema = z.object({\n id: z.string().min(1),\n name: z.string().nullish(),\n projectId: z.string().nullish(),\n userId: z.string().nullish(),\n sessionId: z.string().nullish(),\n release: z.string().nullish(),\n version: z.string().nullish(),\n totalCost: z.number().nullish(),\n latency: z.number().nullish(),\n createdAt: z.string().nullish(),\n updatedAt: z.string().nullish(),\n});\n\nconst tracesResponseSchema = z.object({\n data: z.array(traceSchema),\n meta: z.object({\n page: z.number(),\n limit: z.number(),\n totalItems: z.number(),\n totalPages: z.number(),\n }),\n});\n\nconst dailyUsageSchema = z.object({\n model: z.string().nullish(),\n inputUsage: z.number().nullish(),\n outputUsage: z.number().nullish(),\n totalUsage: z.number().nullish(),\n countObservations: z.number().nullish(),\n totalCost: z.number().nullish(),\n});\n\nconst dailyMetricSchema = z.object({\n date: z.string(),\n countTraces: z.number().nullish(),\n countObservations: z.number().nullish(),\n totalCost: z.number().nullish(),\n usage: z.array(dailyUsageSchema).nullish(),\n});\n\nconst dailyMetricsResponseSchema = z.object({\n data: z.array(dailyMetricSchema),\n meta: z.object({\n page: z.number(),\n limit: z.number(),\n totalItems: z.number(),\n totalPages: z.number(),\n }),\n});\n\nconst scoreSchema = z.object({\n id: z.string().min(1),\n name: z.string().min(1),\n value: z.number().nullish(),\n stringValue: z.string().nullish(),\n dataType: z.string().nullish(),\n source: z.string().nullish(),\n timestamp: z.string().nullish(),\n createdAt: z.string().nullish(),\n});\n\nconst scoresResponseSchema = z.object({\n data: z.array(scoreSchema),\n meta: z.object({\n page: z.number(),\n limit: z.number(),\n totalItems: z.number(),\n totalPages: z.number(),\n }),\n});\n\nexport const langfuseResources = defineResources({\n langfuse_trace: {\n shape: 'entity',\n filterable: [],\n description:\n 'LLM traces in the project, keyed by id, with name, owning user/session, optional release/version, aggregate cost in USD, aggregate latency in milliseconds, and the createdAt timestamp.',\n endpoint: 'GET /api/public/traces',\n notes:\n 'Traces upsert by id on every run. Trace input/output payloads are not stored.',\n fields: [\n { name: 'name', description: 'Trace name set by the SDK.' },\n {\n name: 'projectId',\n description: 'Langfuse project id the trace belongs to.',\n },\n { name: 'userId', description: 'Attached userId, if any.' },\n { name: 'sessionId', description: 'Attached sessionId, if any.' },\n {\n name: 'release',\n description: 'Release identifier from the SDK, if set.',\n },\n {\n name: 'version',\n description: 'Version identifier from the SDK, if set.',\n },\n {\n name: 'totalCost',\n description: 'Aggregate trace cost in USD across all observations.',\n },\n {\n name: 'latencyMs',\n description: 'End-to-end trace latency in milliseconds.',\n },\n { name: 'createdAt', description: 'ISO timestamp of trace creation.' },\n ],\n responses: { traces: tracesResponseSchema },\n },\n langfuse_observations_per_day: {\n shape: 'metric',\n description:\n 'Daily LLM observation volume, total tokens, and total cost rolled up by model from the Langfuse daily metrics endpoint. One sample per (day, model) over the lookback window.',\n endpoint: 'GET /api/public/metrics/daily',\n unit: 'observations',\n granularity: 'Daily (UTC)',\n notes: 'Rollup metrics are stamped at UTC midnight of the day they cover.',\n dimensions: [\n {\n name: 'model',\n description: 'The model id the observations ran against.',\n },\n {\n name: 'countObservations',\n description: 'Observations recorded that day for this model.',\n },\n {\n name: 'inputTokens',\n description: 'Input tokens consumed that day for this model.',\n },\n {\n name: 'outputTokens',\n description: 'Output tokens produced that day for this model.',\n },\n {\n name: 'totalTokens',\n description: 'Total tokens (input + output) for the day and model.',\n },\n {\n name: 'costUsd',\n description: 'Aggregate cost in USD for the day and model.',\n },\n ],\n responses: { observations_per_day: dailyMetricsResponseSchema },\n },\n langfuse_scores: {\n shape: 'metric',\n description:\n 'Daily Langfuse score rollups by score name. One sample per (day, name): the mean numeric value across that day and the count of scores written.',\n endpoint: 'GET /api/public/scores',\n unit: 'scores',\n granularity: 'Daily (UTC)',\n notes:\n 'Only numeric scores contribute to the average; non-numeric scores still increment the count.',\n dimensions: [\n { name: 'name', description: 'Score name as set by the SDK.' },\n {\n name: 'average',\n description:\n 'Mean numeric score value for the day (zero if no numeric values).',\n },\n { name: 'count', description: 'Number of scores written that day.' },\n ],\n responses: { scores: scoresResponseSchema },\n },\n});\n\nexport const id = 'langfuse';\n\nexport class LangfuseConnector extends BaseConnector<\n LangfuseSettings,\n LangfuseCredentials\n> {\n static readonly id = id;\n\n static readonly resources = langfuseResources;\n\n static readonly schemas = schemasFromResources(langfuseResources);\n\n static create(input: unknown, ctx?: ConnectorContext): LangfuseConnector {\n const parsed = configFields.parse(input);\n return new LangfuseConnector(\n {\n publicKey: parsed.publicKey,\n host: parsed.host,\n lookbackDays: parsed.lookbackDays,\n resources: parsed.resources,\n },\n { secretKey: parsed.secretKey },\n ctx,\n );\n }\n\n readonly id = id;\n override readonly credentials = langfuseCredentials;\n\n private get baseUrl(): string {\n return this.settings.host.replace(/\\/+$/, '');\n }\n\n private buildHeaders(): Record<string, string> {\n const raw = `${this.settings.publicKey}:${this.creds.secretKey}`;\n const basic = encodeBasicAuth(raw);\n return {\n Authorization: `Basic ${basic}`,\n Accept: 'application/json',\n 'User-Agent': connectorUserAgent('langfuse'),\n };\n }\n\n private windowStart(options: SyncOptions): Date {\n const lookbackDays = this.settings.lookbackDays ?? DEFAULT_LOOKBACK_DAYS;\n const now = Date.now();\n let startMs = now - lookbackDays * MS_PER_DAY;\n if (options.since) {\n const sinceMs = new Date(options.since).getTime();\n if (Number.isFinite(sinceMs) && sinceMs < startMs) {\n startMs = sinceMs;\n }\n }\n return new Date(startMs);\n }\n\n private async fetchTracesPage(\n options: SyncOptions,\n page: string | null,\n signal?: AbortSignal,\n ): Promise<{ items: TraceRecord[]; next: string | null }> {\n const pageNum = parsePage(page);\n const url = new URL(`${this.baseUrl}/api/public/traces`);\n url.searchParams.set('page', String(pageNum));\n url.searchParams.set('limit', String(TRACES_PAGE_SIZE));\n const start = this.windowStart(options);\n url.searchParams.set('fromTimestamp', start.toISOString());\n const res = await this.get<TracesListResponse>(url.toString(), {\n resource: 'traces',\n headers: this.buildHeaders(),\n signal,\n });\n const data = res.body.data;\n const sinceMs = options.since ? new Date(options.since).getTime() : null;\n const allBeforeSince =\n sinceMs !== null &&\n data.length > 0 &&\n data.every((t) => {\n const ts = parseEpoch(t.createdAt ?? null, 'iso');\n return ts !== null && ts < sinceMs;\n });\n const totalPages = res.body.meta?.totalPages ?? 0;\n const next =\n !allBeforeSince && data.length > 0 && pageNum < totalPages\n ? String(pageNum + 1)\n : null;\n return { items: data, next };\n }\n\n private async writeTraces(\n storage: StorageHandle,\n items: TraceRecord[],\n ): Promise<void> {\n for (const trace of items) {\n const createdAt = parseEpoch(trace.createdAt ?? null, 'iso') ?? 0;\n const updatedAt = parseEpoch(trace.updatedAt ?? null, 'iso') ?? createdAt;\n await storage.entity({\n type: TRACE_ENTITY,\n id: trace.id,\n attributes: {\n name: trace.name ?? null,\n projectId: trace.projectId ?? null,\n userId: trace.userId ?? null,\n sessionId: trace.sessionId ?? null,\n release: trace.release ?? null,\n version: trace.version ?? null,\n totalCost: finiteNumberOrNull(trace.totalCost),\n latencyMs: finiteNumberOrNull(trace.latency),\n createdAt: trace.createdAt ?? null,\n },\n updated_at: updatedAt,\n });\n }\n }\n\n private async fetchDailyMetricsPage(\n options: SyncOptions,\n page: string | null,\n signal?: AbortSignal,\n ): Promise<{ items: DailyMetricRecord[]; next: string | null }> {\n const pageNum = parsePage(page);\n const url = new URL(`${this.baseUrl}/api/public/metrics/daily`);\n url.searchParams.set('page', String(pageNum));\n url.searchParams.set('limit', String(METRICS_PAGE_SIZE));\n const start = this.windowStart(options);\n url.searchParams.set('fromTimestamp', start.toISOString());\n const res = await this.get<DailyMetricsResponse>(url.toString(), {\n resource: 'observations_per_day',\n headers: this.buildHeaders(),\n signal,\n });\n const data = res.body.data;\n const totalPages = res.body.meta?.totalPages ?? 0;\n const next =\n data.length > 0 && pageNum < totalPages ? String(pageNum + 1) : null;\n return { items: data, next };\n }\n\n private async writeDailyMetrics(\n storage: StorageHandle,\n items: DailyMetricRecord[],\n ): Promise<void> {\n for (const row of items) {\n const ts = dateStringToMs(row.date);\n if (ts === null) {\n continue;\n }\n const usage = row.usage ?? [];\n if (usage.length === 0) {\n const count = finiteNumber(row.countObservations);\n await storage.metric({\n name: OBSERVATIONS_METRIC,\n ts,\n value: count,\n attributes: {\n model: null,\n countObservations: count,\n inputTokens: 0,\n outputTokens: 0,\n totalTokens: 0,\n costUsd: finiteNumber(row.totalCost),\n },\n });\n continue;\n }\n for (const entry of usage) {\n const count = finiteNumber(entry.countObservations);\n const input = finiteNumber(entry.inputUsage);\n const output = finiteNumber(entry.outputUsage);\n const totalTokens =\n entry.totalUsage !== null && entry.totalUsage !== undefined\n ? finiteNumber(entry.totalUsage)\n : input + output;\n await storage.metric({\n name: OBSERVATIONS_METRIC,\n ts,\n value: count,\n attributes: {\n model: entry.model ?? null,\n countObservations: count,\n inputTokens: input,\n outputTokens: output,\n totalTokens,\n costUsd: finiteNumber(entry.totalCost),\n },\n });\n }\n }\n }\n\n private async fetchScoresPage(\n options: SyncOptions,\n page: string | null,\n signal?: AbortSignal,\n ): Promise<{ items: ScoreRecord[]; next: string | null }> {\n const pageNum = parsePage(page);\n const url = new URL(`${this.baseUrl}/api/public/scores`);\n url.searchParams.set('page', String(pageNum));\n url.searchParams.set('limit', String(SCORES_PAGE_SIZE));\n const start = this.windowStart(options);\n url.searchParams.set('fromTimestamp', start.toISOString());\n const res = await this.get<ScoresListResponse>(url.toString(), {\n resource: 'scores',\n headers: this.buildHeaders(),\n signal,\n });\n const data = res.body.data;\n const sinceMs = options.since ? new Date(options.since).getTime() : null;\n const allBeforeSince =\n sinceMs !== null &&\n data.length > 0 &&\n data.every((s) => {\n const ts =\n parseEpoch(s.timestamp ?? null, 'iso') ??\n parseEpoch(s.createdAt ?? null, 'iso');\n return ts !== null && ts < sinceMs;\n });\n const totalPages = res.body.meta?.totalPages ?? 0;\n const next =\n !allBeforeSince && data.length > 0 && pageNum < totalPages\n ? String(pageNum + 1)\n : null;\n return { items: data, next };\n }\n\n private async writeScores(\n storage: StorageHandle,\n items: ScoreRecord[],\n ): Promise<void> {\n type Acc = { count: number; sum: number; numericCount: number };\n const byDayName = new Map<string, Acc>();\n for (const score of items) {\n const ts =\n parseEpoch(score.timestamp ?? null, 'iso') ??\n parseEpoch(score.createdAt ?? null, 'iso');\n if (ts === null) {\n continue;\n }\n const day = startOfUtcDay(ts);\n const key = `${day}|${score.name}`;\n const prev = byDayName.get(key) ?? { count: 0, sum: 0, numericCount: 0 };\n prev.count += 1;\n if (typeof score.value === 'number' && Number.isFinite(score.value)) {\n prev.sum += score.value;\n prev.numericCount += 1;\n }\n byDayName.set(key, prev);\n }\n for (const [key, acc] of byDayName) {\n const sep = key.indexOf('|');\n const dayMs = Number(key.slice(0, sep));\n const name = key.slice(sep + 1);\n const average = acc.numericCount > 0 ? acc.sum / acc.numericCount : 0;\n await storage.metric({\n name: SCORES_METRIC,\n ts: dayMs,\n value: average,\n attributes: {\n name,\n average,\n count: acc.count,\n },\n });\n }\n }\n\n private async clearScopeOnFirstPage(\n storage: StorageHandle,\n phase: LangfusePhase,\n isFull: boolean,\n ): Promise<void> {\n switch (phase) {\n case 'traces':\n if (isFull) {\n await storage.entities([], { types: [TRACE_ENTITY] });\n }\n return;\n case 'observations_per_day':\n await storage.metrics([], { names: [OBSERVATIONS_METRIC] });\n return;\n case 'scores':\n await storage.metrics([], { names: [SCORES_METRIC] });\n return;\n }\n }\n\n private async writePhase(\n storage: StorageHandle,\n phase: LangfusePhase,\n items: unknown[],\n ): Promise<void> {\n switch (phase) {\n case 'traces':\n await this.writeTraces(storage, items as TraceRecord[]);\n return;\n case 'observations_per_day':\n await this.writeDailyMetrics(storage, items as DailyMetricRecord[]);\n return;\n case 'scores':\n await this.writeScores(storage, items as ScoreRecord[]);\n return;\n }\n }\n\n async sync(\n options: SyncOptions,\n storage: StorageHandle,\n signal?: AbortSignal,\n ): Promise<SyncResult> {\n const cursor = isLangfuseSyncCursor(options.cursor)\n ? options.cursor\n : undefined;\n const isFull = options.mode === 'full';\n\n const phases = selectActivePhases<LangfuseResource, LangfusePhase>(\n (r) => r,\n PHASE_ORDER,\n this.settings.resources,\n );\n\n return paginateChunked<LangfusePhase, string>({\n phases,\n cursor,\n signal,\n logger: this.logger,\n maxChunkMs: CHUNK_BUDGET_MS,\n fetchPage: async (phase, page, sig) => {\n switch (phase) {\n case 'traces':\n return this.fetchTracesPage(options, page, sig);\n case 'observations_per_day':\n return this.fetchDailyMetricsPage(options, page, sig);\n case 'scores':\n return this.fetchScoresPage(options, page, sig);\n }\n },\n writeBatch: async (phase, items, page) => {\n if (page === null) {\n await this.clearScopeOnFirstPage(storage, phase, isFull);\n }\n await this.writePhase(storage, phase, items);\n },\n });\n }\n}\n\nfunction parsePage(page: string | null): number {\n if (page === null) {\n return 1;\n }\n const n = Number(page);\n return Number.isFinite(n) && n >= 1 ? Math.floor(n) : 1;\n}\n\nfunction finiteNumber(value: unknown, fallback = 0): number {\n if (value === null || value === undefined) {\n return fallback;\n }\n const n = typeof value === 'number' ? value : Number(value);\n return Number.isFinite(n) ? n : fallback;\n}\n\nfunction finiteNumberOrNull(value: unknown): number | null {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n const n = typeof value === 'number' ? value : Number(value);\n return Number.isFinite(n) ? n : null;\n}\n\nfunction dateStringToMs(value: unknown): number | null {\n if (typeof value !== 'string') {\n return null;\n }\n const trimmed = value.trim();\n if (trimmed === '') {\n return null;\n }\n const isoLike = /^\\d{4}-\\d{2}-\\d{2}$/.test(trimmed)\n ? `${trimmed}T00:00:00.000Z`\n : trimmed;\n return parseEpoch(isoLike, 'iso');\n}\n\nfunction startOfUtcDay(ms: number): number {\n return Math.floor(ms / MS_PER_DAY) * MS_PER_DAY;\n}\n\nfunction encodeBasicAuth(raw: string): string {\n if (typeof btoa === 'function') {\n return btoa(raw);\n }\n const bufferCtor = (\n globalThis as {\n Buffer?: { from: (s: string) => { toString: (enc: string) => string } };\n }\n ).Buffer;\n if (bufferCtor) {\n return bufferCtor.from(raw).toString('base64');\n }\n throw new Error('No base64 encoder available in this runtime');\n}\n","import { LangfuseConnector } from './langfuse';\n\nexport {\n configFields,\n doc,\n LangfuseConnector,\n langfuseResources as resources,\n id,\n} from './langfuse';\nexport type { LangfuseSettings, LangfuseResource } from './langfuse';\nexport default LangfuseConnector;\n"],"mappings":";AEAO,IAAM,sBAAsB;AAE5B,IAAM,qBAAqB,qBAAqB,mBAAmB;AAEnE,SAAS,mBAAmB,aAA6B;AAC9D,SAAO,qBAAqB,WAAW,IAAI,mBAAmB;AAChE;AKJO,SAAS,WACd,OACA,MACe;AACf,MAAI,UAAU,QAAQ,UAAU,QAAW;AACzC,WAAO;EACT;AACA,MAAI,SAAS,OAAO;AAClB,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO;IACT;AACA,UAAM,KAAK,IAAI,KAAK,KAAK,EAAE,QAAQ;AACnC,WAAO,OAAO,SAAS,EAAE,IAAI,KAAK;EACpC;AACA,MAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAAI;AACpD,WAAO;EACT;AACA,QAAM,IAAI,OAAO,UAAU,WAAW,QAAQ,OAAO,KAAK;AAC1D,MAAI,CAAC,OAAO,SAAS,CAAC,GAAG;AACvB,WAAO;EACT;AACA,QAAM,SAAS,SAAS,MAAM,IAAI,MAAO;AACzC,SAAO,OAAO,SAAS,MAAM,IAAI,SAAS;AAC5C;;;AGxBA;AAAA,EACE;AAAA,EAOA;AAA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,SAAS,CAAC,IAAI,IAAI;AAClC;AAEA,SAAS,mBAAmB,OAA+B;AACzD,MAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,IAAI;AACzD,WAAO;AAAA,EACT;AACA,QAAM,IAAI,OAAO,UAAU,WAAW,QAAQ,OAAO,KAAK;AAC1D,SAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAClC;AAEA,SAAS,eAAe,OAA+B;AACrD,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AACA,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,YAAY,IAAI;AAClB,WAAO;AAAA,EACT;AACA,QAAM,UAAU,sBAAsB,KAAK,OAAO,IAC9C,GAAG,OAAO,mBACV;AACJ,SAAO,WAAW,SAAS,KAAK;AAClC;AAEA,SAAS,cAAc,IAAoB;AACzC,SAAO,KAAK,MAAM,KAAK,UAAU,IAAI;AACvC;AAEA,SAAS,gBAAgB,KAAqB;AAC5C,MAAI,OAAO,SAAS,YAAY;AAC9B,WAAO,KAAK,GAAG;AAAA,EACjB;AACA,QAAM,aACJ,WAGA;AACF,MAAI,YAAY;AACd,WAAO,WAAW,KAAK,GAAG,EAAE,SAAS,QAAQ;AAAA,EAC/C;AACA,QAAM,IAAI,MAAM,6CAA6C;AAC/D;;;AC3uBA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rawdash/connector-langfuse",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Rawdash connector for Langfuse — LLM traces, daily observation volume and cost, and feedback scores",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/rawdash/rawdash.git",
|
|
11
|
+
"directory": "packages/connectors/langfuse"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"@rawdash/source": "./src/index.ts",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"lint": "eslint src",
|
|
29
|
+
"test": "vitest run"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@rawdash/core": "workspace:*",
|
|
33
|
+
"zod": "^4.4.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@rawdash/connector-shared": "workspace:*",
|
|
37
|
+
"@rawdash/connector-test-utils": "workspace:*",
|
|
38
|
+
"fast-check": "^4.8.0",
|
|
39
|
+
"tsup": "^8.0.0",
|
|
40
|
+
"typescript": "^5.7.2",
|
|
41
|
+
"vitest": "^4.1.4"
|
|
42
|
+
}
|
|
43
|
+
}
|