@terreno/ai 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/langfuseCache.d.ts +5 -6
- package/dist/langfuseCache.js +11 -2
- package/dist/langfuseClient.js +5 -1
- package/dist/models/fileAttachment.js +17 -6
- package/dist/models/gptHistory.js +36 -17
- package/dist/routes/aiRequestsExplorer.d.ts +2 -1
- package/dist/routes/aiRequestsExplorer.js +18 -4
- package/dist/routes/files.d.ts +2 -1
- package/dist/routes/files.js +2 -2
- package/dist/routes/gpt.d.ts +2 -1
- package/dist/routes/gptHistories.d.ts +2 -1
- package/dist/routes/mcp.d.ts +2 -1
- package/dist/routes/mcp.js +2 -5
- package/dist/routes/projects.d.ts +2 -1
- package/dist/service/aiService.d.ts +3 -3
- package/dist/service/fileStorage.js +3 -2
- package/package.json +4 -3
- package/src/langfuseCache.ts +19 -5
- package/src/langfuseClient.test.ts +29 -52
- package/src/langfuseClient.ts +5 -1
- package/src/langfusePrompts.test.ts +11 -10
- package/src/langfuseRoutes.test.ts +27 -19
- package/src/langfuseVercelAi.test.ts +8 -12
- package/src/models/aiRequest.ts +2 -2
- package/src/models/fileAttachment.ts +17 -6
- package/src/models/gptHistory.ts +36 -17
- package/src/routes/aiRequestsExplorer.ts +20 -6
- package/src/routes/files.ts +8 -6
- package/src/routes/gpt.ts +21 -16
- package/src/routes/gptHistories.ts +2 -1
- package/src/routes/mcp.ts +7 -8
- package/src/routes/projects.ts +1 -1
- package/src/routes/routes.test.ts +64 -1
- package/src/service/aiService.test.ts +1 -0
- package/src/service/aiService.ts +4 -4
- package/src/service/fileStorage.ts +3 -2
- package/src/tests/bunSetup.ts +60 -0
- package/src/types/index.ts +2 -0
package/src/tests/bunSetup.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
2
|
import {afterAll, afterEach, beforeAll, beforeEach, mock} from "bun:test";
|
|
2
3
|
import {Writable} from "node:stream";
|
|
3
4
|
import {setupEnvironment, winstonLogger} from "@terreno/api";
|
|
@@ -99,6 +100,65 @@ afterEach(() => {
|
|
|
99
100
|
logs = [];
|
|
100
101
|
});
|
|
101
102
|
|
|
103
|
+
// Mock @langfuse/client globally so the real `./langfuseClient` module runs
|
|
104
|
+
// without making network calls. Each `new LangfuseClient(...)` gets its own
|
|
105
|
+
// mock functions so tests can customize per-instance behavior (via
|
|
106
|
+
// `getLangfuseClient()` after `initLangfuseClient(...)`). Mocking the SDK
|
|
107
|
+
// here, rather than mocking `./langfuseClient` per-test-file, prevents the
|
|
108
|
+
// `mock.module()` global cache from leaking different shapes across files.
|
|
109
|
+
mock.module("@langfuse/client", () => {
|
|
110
|
+
return {
|
|
111
|
+
LangfuseClient: class FakeLangfuseClient {
|
|
112
|
+
baseUrl: string;
|
|
113
|
+
publicKey: string;
|
|
114
|
+
secretKey: string;
|
|
115
|
+
api = {
|
|
116
|
+
prompts: {
|
|
117
|
+
list: mock(async () => ({
|
|
118
|
+
data: [],
|
|
119
|
+
meta: {limit: 20, page: 1, total: 0, totalPages: 0},
|
|
120
|
+
})),
|
|
121
|
+
},
|
|
122
|
+
trace: {
|
|
123
|
+
get: mock(async (id: string) => ({id, name: "Trace"})),
|
|
124
|
+
list: mock(async () => ({
|
|
125
|
+
data: [],
|
|
126
|
+
meta: {limit: 20, page: 1, total: 0, totalPages: 0},
|
|
127
|
+
})),
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
prompt = {
|
|
131
|
+
create: mock(async (_params: Record<string, unknown>) => undefined),
|
|
132
|
+
get: mock(async (name: string) => ({
|
|
133
|
+
config: {},
|
|
134
|
+
labels: [],
|
|
135
|
+
name,
|
|
136
|
+
prompt: "",
|
|
137
|
+
tags: [],
|
|
138
|
+
type: "text" as const,
|
|
139
|
+
version: 1,
|
|
140
|
+
})),
|
|
141
|
+
};
|
|
142
|
+
score = {create: mock(() => {})};
|
|
143
|
+
flush = mock(async () => {});
|
|
144
|
+
shutdown = mock(async () => {});
|
|
145
|
+
|
|
146
|
+
constructor(opts: {baseUrl: string; publicKey: string; secretKey: string}) {
|
|
147
|
+
this.baseUrl = opts.baseUrl;
|
|
148
|
+
this.publicKey = opts.publicKey;
|
|
149
|
+
this.secretKey = opts.secretKey;
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Ensure no langfuse client instance leaks across tests in different files.
|
|
156
|
+
// The real langfuseInstance module variable is reset to null between tests.
|
|
157
|
+
beforeEach(async () => {
|
|
158
|
+
const {shutdownLangfuseClient} = await import("../langfuseClient");
|
|
159
|
+
await shutdownLangfuseClient();
|
|
160
|
+
});
|
|
161
|
+
|
|
102
162
|
// Mock @sentry/bun module
|
|
103
163
|
mock.module("@sentry/bun", () => {
|
|
104
164
|
const mockFn = (): ReturnType<typeof mock> => mock(() => {});
|
package/src/types/index.ts
CHANGED
|
@@ -161,6 +161,7 @@ export interface AIServiceOptions {
|
|
|
161
161
|
export interface GenerateTextOptions {
|
|
162
162
|
maxOutputTokens?: number;
|
|
163
163
|
prompt: string;
|
|
164
|
+
// biome-ignore lint/suspicious/noExplicitAny: Vercel AI SDK's StopCondition is generic over the tool set; consumers may pass any tool shape.
|
|
164
165
|
stopWhen?: import("ai").StopCondition<any>;
|
|
165
166
|
systemPrompt?: string;
|
|
166
167
|
temperature?: number;
|
|
@@ -179,6 +180,7 @@ export interface GenerateStreamOptions {
|
|
|
179
180
|
|
|
180
181
|
export interface GenerateChatStreamOptions {
|
|
181
182
|
messages: Array<{content: string; role: "user" | "assistant" | "system"}>;
|
|
183
|
+
// biome-ignore lint/suspicious/noExplicitAny: Vercel AI SDK's StopCondition is generic over the tool set; consumers may pass any tool shape.
|
|
182
184
|
stopWhen?: import("ai").StopCondition<any>;
|
|
183
185
|
systemPrompt?: string;
|
|
184
186
|
toolChoice?: "auto" | "none" | "required";
|