@terreno/ai 0.11.1 → 0.11.2
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/dist/langfuseTypes.d.ts +37 -37
- package/package.json +11 -3
- package/src/langfuseClient.test.ts +72 -0
- package/src/langfuseTypes.ts +36 -36
package/dist/langfuseTypes.d.ts
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
1
|
export interface ScoringFunction {
|
|
2
|
-
name: string;
|
|
3
|
-
description: string;
|
|
4
|
-
scoreType: "numeric" | "categorical" | "boolean";
|
|
5
2
|
categories?: string[];
|
|
3
|
+
description: string;
|
|
4
|
+
name: string;
|
|
6
5
|
range?: {
|
|
7
|
-
min: number;
|
|
8
6
|
max: number;
|
|
7
|
+
min: number;
|
|
9
8
|
};
|
|
9
|
+
scoreType: "numeric" | "categorical" | "boolean";
|
|
10
10
|
}
|
|
11
11
|
export interface LangfuseAppOptions {
|
|
12
|
-
secretKey: string;
|
|
13
|
-
publicKey: string;
|
|
14
|
-
/** Organization slug in Langfuse (default: "flourish-health") */
|
|
15
|
-
organization?: string;
|
|
16
|
-
/** Project name/slug in Langfuse (default: "terreno") */
|
|
17
|
-
project?: string;
|
|
18
|
-
/** Langfuse project ID (UUID) for trace URLs; optional, keys usually imply project */
|
|
19
|
-
projectId?: string;
|
|
20
|
-
baseUrl?: string;
|
|
21
12
|
adminPath?: string;
|
|
22
|
-
|
|
23
|
-
enableTracing?: boolean;
|
|
24
|
-
serviceName?: string;
|
|
13
|
+
baseUrl?: string;
|
|
25
14
|
cache?: {
|
|
26
15
|
promptTtlSeconds?: number;
|
|
27
16
|
traceTtlSeconds?: number;
|
|
28
17
|
};
|
|
18
|
+
enableAdminUI?: boolean;
|
|
19
|
+
enableTracing?: boolean;
|
|
29
20
|
evaluation?: {
|
|
30
21
|
enabled?: boolean;
|
|
31
22
|
scoringFunctions?: ScoringFunction[];
|
|
32
23
|
};
|
|
24
|
+
/** Organization slug in Langfuse (default: "flourish-health") */
|
|
25
|
+
organization?: string;
|
|
26
|
+
/** Project name/slug in Langfuse (default: "terreno") */
|
|
27
|
+
project?: string;
|
|
28
|
+
/** Langfuse project ID (UUID) for trace URLs; optional, keys usually imply project */
|
|
29
|
+
projectId?: string;
|
|
30
|
+
publicKey: string;
|
|
31
|
+
secretKey: string;
|
|
32
|
+
serviceName?: string;
|
|
33
33
|
}
|
|
34
34
|
export interface ChatMessage {
|
|
35
|
-
role: string;
|
|
36
35
|
content: string;
|
|
36
|
+
role: string;
|
|
37
37
|
}
|
|
38
38
|
export interface LangfuseCachedPrompt {
|
|
39
|
-
name: string;
|
|
40
|
-
version: number;
|
|
41
|
-
type: "text" | "chat";
|
|
42
|
-
prompt: string | ChatMessage[];
|
|
43
39
|
config: Record<string, unknown>;
|
|
44
40
|
labels: string[];
|
|
41
|
+
name: string;
|
|
42
|
+
prompt: string | ChatMessage[];
|
|
45
43
|
tags: string[];
|
|
44
|
+
type: "text" | "chat";
|
|
45
|
+
version: number;
|
|
46
46
|
}
|
|
47
47
|
export interface TelemetrySettings {
|
|
48
|
-
isEnabled?: boolean;
|
|
49
48
|
functionId?: string;
|
|
49
|
+
isEnabled?: boolean;
|
|
50
50
|
metadata?: Record<string, string | number | boolean>;
|
|
51
51
|
}
|
|
52
52
|
export interface PreparePromptResult {
|
|
53
|
-
prompt?: string;
|
|
54
|
-
messages?: ChatMessage[];
|
|
55
53
|
config: Record<string, unknown>;
|
|
54
|
+
messages?: ChatMessage[];
|
|
55
|
+
prompt?: string;
|
|
56
56
|
telemetry: TelemetrySettings;
|
|
57
57
|
}
|
|
58
58
|
export interface GetPromptOptions {
|
|
59
59
|
label?: string;
|
|
60
|
-
variables?: Record<string, string>;
|
|
61
60
|
userId?: string;
|
|
61
|
+
variables?: Record<string, string>;
|
|
62
62
|
}
|
|
63
63
|
export interface PromptListItem {
|
|
64
|
-
|
|
65
|
-
version: number;
|
|
66
|
-
type: "text" | "chat";
|
|
64
|
+
createdAt: string;
|
|
67
65
|
labels: string[];
|
|
66
|
+
name: string;
|
|
68
67
|
tags: string[];
|
|
69
|
-
|
|
68
|
+
type: "text" | "chat";
|
|
69
|
+
version: number;
|
|
70
70
|
}
|
|
71
71
|
export interface TraceListItem {
|
|
72
72
|
id: string;
|
|
73
|
+
input?: unknown;
|
|
74
|
+
metadata?: Record<string, unknown>;
|
|
73
75
|
name: string;
|
|
74
|
-
|
|
76
|
+
output?: unknown;
|
|
75
77
|
sessionId?: string;
|
|
76
78
|
timestamp: string;
|
|
77
|
-
|
|
78
|
-
output?: unknown;
|
|
79
|
-
metadata?: Record<string, unknown>;
|
|
79
|
+
userId?: string;
|
|
80
80
|
}
|
|
81
81
|
export interface PaginatedResult<T> {
|
|
82
82
|
data: T[];
|
|
83
83
|
meta: {
|
|
84
|
-
page: number;
|
|
85
84
|
limit: number;
|
|
85
|
+
page: number;
|
|
86
86
|
total: number;
|
|
87
87
|
totalPages: number;
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
export interface ScoreSubmission {
|
|
91
|
-
traceId: string;
|
|
92
|
-
name: string;
|
|
93
|
-
value: number | string;
|
|
94
91
|
comment?: string;
|
|
95
92
|
dataType?: "NUMERIC" | "CATEGORICAL" | "BOOLEAN";
|
|
93
|
+
name: string;
|
|
94
|
+
traceId: string;
|
|
95
|
+
value: number | string;
|
|
96
96
|
}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@langfuse/otel": "^5.0.1",
|
|
11
11
|
"@opentelemetry/api": "^1.9.0",
|
|
12
12
|
"@opentelemetry/sdk-node": "^0.213.0",
|
|
13
|
-
"@terreno/api": "0.11.
|
|
13
|
+
"@terreno/api": "0.11.2",
|
|
14
14
|
"ai": "^6.0.97",
|
|
15
15
|
"multer": "^1.4.5-lts.1"
|
|
16
16
|
},
|
|
@@ -32,6 +32,14 @@
|
|
|
32
32
|
".": {
|
|
33
33
|
"default": "./dist/index.js",
|
|
34
34
|
"types": "./dist/index.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./langfuseClient": {
|
|
37
|
+
"default": "./dist/langfuseClient.js",
|
|
38
|
+
"types": "./dist/langfuseClient.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./langfuseApp": {
|
|
41
|
+
"default": "./dist/langfuseApp.js",
|
|
42
|
+
"types": "./dist/langfuseApp.d.ts"
|
|
35
43
|
}
|
|
36
44
|
},
|
|
37
45
|
"homepage": "https://github.com/FlourishHealth/terreno#readme",
|
|
@@ -48,7 +56,7 @@
|
|
|
48
56
|
"access": "public"
|
|
49
57
|
},
|
|
50
58
|
"peerDependencies": {
|
|
51
|
-
"@terreno/api": "0.11.
|
|
59
|
+
"@terreno/api": "0.11.2",
|
|
52
60
|
"mongoose": "^8.0.0"
|
|
53
61
|
},
|
|
54
62
|
"repository": {
|
|
@@ -67,5 +75,5 @@
|
|
|
67
75
|
"test:coverage": "bun run ../scripts/check-coverage.ts"
|
|
68
76
|
},
|
|
69
77
|
"types": "dist/index.d.ts",
|
|
70
|
-
"version": "0.11.
|
|
78
|
+
"version": "0.11.2"
|
|
71
79
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getLangfuseClient,
|
|
5
|
+
initLangfuseClient,
|
|
6
|
+
isLangfuseInitialized,
|
|
7
|
+
shutdownLangfuseClient,
|
|
8
|
+
} from "./langfuseClient";
|
|
9
|
+
|
|
10
|
+
describe("langfuseClient", () => {
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
await shutdownLangfuseClient();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(async () => {
|
|
16
|
+
await shutdownLangfuseClient();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("throws when getLangfuseClient is called before initialization", () => {
|
|
20
|
+
expect(() => getLangfuseClient()).toThrow(
|
|
21
|
+
"Langfuse client not initialized. Call initLangfuseClient first."
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("isLangfuseInitialized returns false before initialization", () => {
|
|
26
|
+
expect(isLangfuseInitialized()).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("initLangfuseClient creates and returns a client", () => {
|
|
30
|
+
const client = initLangfuseClient({
|
|
31
|
+
publicKey: "pk-test",
|
|
32
|
+
secretKey: "sk-test",
|
|
33
|
+
});
|
|
34
|
+
expect(client).toBeDefined();
|
|
35
|
+
expect(isLangfuseInitialized()).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("getLangfuseClient returns the initialized client", () => {
|
|
39
|
+
const initialized = initLangfuseClient({
|
|
40
|
+
publicKey: "pk-test",
|
|
41
|
+
secretKey: "sk-test",
|
|
42
|
+
});
|
|
43
|
+
const retrieved = getLangfuseClient();
|
|
44
|
+
expect(retrieved).toBe(initialized);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("initLangfuseClient accepts a custom baseUrl", () => {
|
|
48
|
+
const client = initLangfuseClient({
|
|
49
|
+
baseUrl: "https://custom.langfuse.com",
|
|
50
|
+
publicKey: "pk-test",
|
|
51
|
+
secretKey: "sk-test",
|
|
52
|
+
});
|
|
53
|
+
expect(client).toBeDefined();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("shutdownLangfuseClient resets the instance", async () => {
|
|
57
|
+
initLangfuseClient({
|
|
58
|
+
publicKey: "pk-test",
|
|
59
|
+
secretKey: "sk-test",
|
|
60
|
+
});
|
|
61
|
+
expect(isLangfuseInitialized()).toBe(true);
|
|
62
|
+
await shutdownLangfuseClient();
|
|
63
|
+
expect(isLangfuseInitialized()).toBe(false);
|
|
64
|
+
expect(() => getLangfuseClient()).toThrow();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("shutdownLangfuseClient is a no-op when not initialized", async () => {
|
|
68
|
+
expect(isLangfuseInitialized()).toBe(false);
|
|
69
|
+
await shutdownLangfuseClient();
|
|
70
|
+
expect(isLangfuseInitialized()).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
});
|
package/src/langfuseTypes.ts
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
1
|
export interface ScoringFunction {
|
|
2
|
-
|
|
2
|
+
categories?: string[];
|
|
3
3
|
description: string;
|
|
4
|
+
name: string;
|
|
5
|
+
range?: {max: number; min: number};
|
|
4
6
|
scoreType: "numeric" | "categorical" | "boolean";
|
|
5
|
-
categories?: string[];
|
|
6
|
-
range?: {min: number; max: number};
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface LangfuseAppOptions {
|
|
10
|
-
secretKey: string;
|
|
11
|
-
publicKey: string;
|
|
12
|
-
/** Organization slug in Langfuse (default: "flourish-health") */
|
|
13
|
-
organization?: string;
|
|
14
|
-
/** Project name/slug in Langfuse (default: "terreno") */
|
|
15
|
-
project?: string;
|
|
16
|
-
/** Langfuse project ID (UUID) for trace URLs; optional, keys usually imply project */
|
|
17
|
-
projectId?: string;
|
|
18
|
-
baseUrl?: string;
|
|
19
10
|
adminPath?: string;
|
|
20
|
-
|
|
21
|
-
enableTracing?: boolean;
|
|
22
|
-
serviceName?: string;
|
|
11
|
+
baseUrl?: string;
|
|
23
12
|
cache?: {
|
|
24
13
|
promptTtlSeconds?: number;
|
|
25
14
|
traceTtlSeconds?: number;
|
|
26
15
|
};
|
|
16
|
+
enableAdminUI?: boolean;
|
|
17
|
+
enableTracing?: boolean;
|
|
27
18
|
evaluation?: {
|
|
28
19
|
enabled?: boolean;
|
|
29
20
|
scoringFunctions?: ScoringFunction[];
|
|
30
21
|
};
|
|
22
|
+
/** Organization slug in Langfuse (default: "flourish-health") */
|
|
23
|
+
organization?: string;
|
|
24
|
+
/** Project name/slug in Langfuse (default: "terreno") */
|
|
25
|
+
project?: string;
|
|
26
|
+
/** Langfuse project ID (UUID) for trace URLs; optional, keys usually imply project */
|
|
27
|
+
projectId?: string;
|
|
28
|
+
publicKey: string;
|
|
29
|
+
secretKey: string;
|
|
30
|
+
serviceName?: string;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface ChatMessage {
|
|
34
|
-
role: string;
|
|
35
34
|
content: string;
|
|
35
|
+
role: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface LangfuseCachedPrompt {
|
|
39
|
-
name: string;
|
|
40
|
-
version: number;
|
|
41
|
-
type: "text" | "chat";
|
|
42
|
-
prompt: string | ChatMessage[];
|
|
43
39
|
config: Record<string, unknown>;
|
|
44
40
|
labels: string[];
|
|
41
|
+
name: string;
|
|
42
|
+
prompt: string | ChatMessage[];
|
|
45
43
|
tags: string[];
|
|
44
|
+
type: "text" | "chat";
|
|
45
|
+
version: number;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export interface TelemetrySettings {
|
|
49
|
-
isEnabled?: boolean;
|
|
50
49
|
functionId?: string;
|
|
50
|
+
isEnabled?: boolean;
|
|
51
51
|
metadata?: Record<string, string | number | boolean>;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
export interface PreparePromptResult {
|
|
55
|
-
prompt?: string;
|
|
56
|
-
messages?: ChatMessage[];
|
|
57
55
|
config: Record<string, unknown>;
|
|
56
|
+
messages?: ChatMessage[];
|
|
57
|
+
prompt?: string;
|
|
58
58
|
telemetry: TelemetrySettings;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export interface GetPromptOptions {
|
|
62
62
|
label?: string;
|
|
63
|
-
variables?: Record<string, string>;
|
|
64
63
|
userId?: string;
|
|
64
|
+
variables?: Record<string, string>;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export interface PromptListItem {
|
|
68
|
-
|
|
69
|
-
version: number;
|
|
70
|
-
type: "text" | "chat";
|
|
68
|
+
createdAt: string;
|
|
71
69
|
labels: string[];
|
|
70
|
+
name: string;
|
|
72
71
|
tags: string[];
|
|
73
|
-
|
|
72
|
+
type: "text" | "chat";
|
|
73
|
+
version: number;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
export interface TraceListItem {
|
|
77
77
|
id: string;
|
|
78
|
+
input?: unknown;
|
|
79
|
+
metadata?: Record<string, unknown>;
|
|
78
80
|
name: string;
|
|
79
|
-
|
|
81
|
+
output?: unknown;
|
|
80
82
|
sessionId?: string;
|
|
81
83
|
timestamp: string;
|
|
82
|
-
|
|
83
|
-
output?: unknown;
|
|
84
|
-
metadata?: Record<string, unknown>;
|
|
84
|
+
userId?: string;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export interface PaginatedResult<T> {
|
|
88
88
|
data: T[];
|
|
89
89
|
meta: {
|
|
90
|
-
page: number;
|
|
91
90
|
limit: number;
|
|
91
|
+
page: number;
|
|
92
92
|
total: number;
|
|
93
93
|
totalPages: number;
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export interface ScoreSubmission {
|
|
98
|
-
traceId: string;
|
|
99
|
-
name: string;
|
|
100
|
-
value: number | string;
|
|
101
98
|
comment?: string;
|
|
102
99
|
dataType?: "NUMERIC" | "CATEGORICAL" | "BOOLEAN";
|
|
100
|
+
name: string;
|
|
101
|
+
traceId: string;
|
|
102
|
+
value: number | string;
|
|
103
103
|
}
|