@terreno/ai 57.19.2 → 57.21.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/.claude/CLAUDE.local.md +1 -1
- package/.cursor/rules/00-root.mdc +1 -1
- package/.github/copilot-instructions.md +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +443 -0
- package/biome.jsonc +1 -0
- package/dist/harness/agentLoop.js +1 -0
- package/dist/observability/local/experimentRunner.d.ts +2 -5
- package/dist/types/harness.d.ts +5 -2
- package/e2e/smoke.ts +227 -0
- package/package.json +14 -12
- package/src/aiApp.test.ts +22 -17
- package/src/harness/agentLoop.test.ts +1 -1
- package/src/harness/agentLoop.ts +2 -1
- package/src/harness/agentRecovery.test.ts +31 -28
- package/src/harness/approvals.test.ts +11 -9
- package/src/harness/events.test.ts +10 -6
- package/src/harness/extensions.test.ts +7 -6
- package/src/harness/ownership.test.ts +20 -9
- package/src/harness/retries.test.ts +6 -3
- package/src/harness/routes/conversations.test.ts +2 -2
- package/src/harness/routes/tasks.test.ts +2 -2
- package/src/harness/runners/jobsRunner.test.ts +1 -1
- package/src/harness/subagent.test.ts +3 -2
- package/src/harness/waits.test.ts +6 -4
- package/src/index.test.ts +3 -3
- package/src/isolated/gptStream.isolated.ts +33 -28
- package/src/isolated/langfuseClient.isolated.ts +9 -3
- package/src/isolated/lazyProjectModel.isolated.ts +2 -2
- package/src/langfuseApp.test.ts +4 -20
- package/src/langfuseRoutes.test.ts +20 -15
- package/src/langfuseTracing.test.ts +6 -2
- package/src/langfuseVercelAi.test.ts +12 -9
- package/src/models/gptHistory.test.ts +10 -6
- package/src/observability/evaluate.test.ts +12 -10
- package/src/observability/local/experimentRunner.test.ts +9 -12
- package/src/observability/local/experimentRunner.ts +2 -2
- package/src/observability/local/promptStore.test.ts +4 -3
- package/src/observability/routes/datasets.test.ts +2 -2
- package/src/observability/routes/evaluators.test.ts +2 -2
- package/src/observability/routes/experiments.test.ts +2 -2
- package/src/observability/routes/prompts.test.ts +3 -3
- package/src/observability/routes/review.test.ts +2 -2
- package/src/observability/routes/status.test.ts +4 -4
- package/src/observability/routes/testMultiStage.test.ts +6 -6
- package/src/observability/routes/traces.test.ts +2 -2
- package/src/routes/files.test.ts +5 -3
- package/src/routes/gpt.test.ts +21 -14
- package/src/routes/gptActions.test.ts +7 -8
- package/src/routes/gptDatasets.test.ts +1 -1
- package/src/routes/gptFiles.test.ts +1 -1
- package/src/routes/gptHistories.test.ts +15 -9
- package/src/routes/mcp.test.ts +3 -3
- package/src/routes/projects.test.ts +5 -3
- package/src/routes/routes.test.ts +58 -42
- package/src/service/aiService.test.ts +1 -1
- package/src/service/asks.test.ts +14 -6
- package/src/service/fileStorage.test.ts +5 -2
- package/src/service/getMCPTools.test.ts +9 -5
- package/src/service/mcpService.test.ts +6 -3
- package/src/tests/bunSetup.ts +1 -1
- package/src/tests/chatHarness.ts +4 -4
- package/src/tests/fakeJudge.ts +8 -0
- package/src/tests/fakeLangfusePrompt.ts +10 -0
- package/src/tests/helpers.ts +26 -4
- package/src/types/harness.ts +6 -2
- package/tsconfig.typecheck.json +18 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {afterEach, describe, expect, it} from "bun:test";
|
|
2
2
|
import {z} from "@terreno/api";
|
|
3
|
-
import type mongoose from "mongoose";
|
|
4
3
|
|
|
5
4
|
import {AIRequest} from "../models/aiRequest";
|
|
6
5
|
import {GptHistory} from "../models/gptHistory";
|
|
@@ -47,7 +46,7 @@ describe("POST /gpt/actions", () => {
|
|
|
47
46
|
|
|
48
47
|
it("rejects an unknown name, a bad payload, and a non-owner", async () => {
|
|
49
48
|
const created = await ensureTestUsers();
|
|
50
|
-
const userId =
|
|
49
|
+
const userId = created[1]._id;
|
|
51
50
|
const history = await GptHistory.create({
|
|
52
51
|
prompts: [{text: "Hello", type: "user"}],
|
|
53
52
|
userId,
|
|
@@ -89,7 +88,7 @@ describe("POST /gpt/actions", () => {
|
|
|
89
88
|
|
|
90
89
|
it("returns the handler document and logs ui_action", async () => {
|
|
91
90
|
const created = await ensureTestUsers();
|
|
92
|
-
const userId =
|
|
91
|
+
const userId = created[1]._id;
|
|
93
92
|
const history = await GptHistory.create({
|
|
94
93
|
prompts: [{text: "Hello", type: "user"}],
|
|
95
94
|
userId,
|
|
@@ -135,7 +134,7 @@ describe("POST /gpt/actions", () => {
|
|
|
135
134
|
|
|
136
135
|
it("returns 504 and logs the timeout", async () => {
|
|
137
136
|
const created = await ensureTestUsers();
|
|
138
|
-
const userId =
|
|
137
|
+
const userId = created[1]._id;
|
|
139
138
|
const history = await GptHistory.create({
|
|
140
139
|
prompts: [{text: "Hello", type: "user"}],
|
|
141
140
|
userId,
|
|
@@ -166,7 +165,7 @@ describe("POST /gpt/actions", () => {
|
|
|
166
165
|
|
|
167
166
|
it("returns 500 when the handler's document is invalid", async () => {
|
|
168
167
|
const created = await ensureTestUsers();
|
|
169
|
-
const userId =
|
|
168
|
+
const userId = created[1]._id;
|
|
170
169
|
const history = await GptHistory.create({
|
|
171
170
|
prompts: [{text: "Hello", type: "user"}],
|
|
172
171
|
userId,
|
|
@@ -230,7 +229,7 @@ describe("POST /gpt/actions", () => {
|
|
|
230
229
|
|
|
231
230
|
it("rejects a replace value the client does not understand", async () => {
|
|
232
231
|
const created = await ensureTestUsers();
|
|
233
|
-
const userId =
|
|
232
|
+
const userId = created[1]._id;
|
|
234
233
|
const history = await GptHistory.create({
|
|
235
234
|
prompts: [{text: "Hello", type: "user"}],
|
|
236
235
|
userId,
|
|
@@ -291,7 +290,7 @@ describe("POST /gpt/actions with scaleStepperHostAction", () => {
|
|
|
291
290
|
assistantPrompts: string[]
|
|
292
291
|
): Promise<{agent: Awaited<ReturnType<typeof authAsUser>>; historyId: string}> => {
|
|
293
292
|
const created = await ensureTestUsers();
|
|
294
|
-
const userId =
|
|
293
|
+
const userId = created[1]._id;
|
|
295
294
|
const history = await GptHistory.create({
|
|
296
295
|
prompts: [
|
|
297
296
|
{text: "Plan a roast", type: "user"},
|
|
@@ -403,7 +402,7 @@ describe("POST /gpt/actions with toggleChecklistHostAction", () => {
|
|
|
403
402
|
assistantPrompts: string[]
|
|
404
403
|
): Promise<{agent: Awaited<ReturnType<typeof authAsUser>>; historyId: string}> => {
|
|
405
404
|
const created = await ensureTestUsers();
|
|
406
|
-
const userId =
|
|
405
|
+
const userId = created[1]._id;
|
|
407
406
|
const history = await GptHistory.create({
|
|
408
407
|
prompts: [
|
|
409
408
|
{text: "Plan a roast", type: "user"},
|
|
@@ -39,7 +39,7 @@ describe("GET /gpt/datasets/:id", () => {
|
|
|
39
39
|
it("buckets by week, downsamples with LTTB, and paginates tables", async () => {
|
|
40
40
|
await ensureTestUsers();
|
|
41
41
|
const created = await ensureTestUsers();
|
|
42
|
-
const userId =
|
|
42
|
+
const userId = created[1]._id;
|
|
43
43
|
const rows = hourlyRows(12_480);
|
|
44
44
|
const registered = await registerAiDataset({
|
|
45
45
|
columns,
|
|
@@ -279,7 +279,7 @@ describe("/gpt/prompt files asks", () => {
|
|
|
279
279
|
},
|
|
280
280
|
]);
|
|
281
281
|
|
|
282
|
-
const output = receiptResultOf(model, 1) as {value: {text?: string}[]};
|
|
282
|
+
const output = receiptResultOf(model, 1) as {value: {text?: string; type?: string}[]};
|
|
283
283
|
expect(output.value.slice(1)).toEqual([
|
|
284
284
|
{text: "File 1 of 1: ledger.csv (text/csv, 100051 bytes)", type: "text"},
|
|
285
285
|
{text: "a".repeat(99_999), type: "text"},
|
|
@@ -38,7 +38,13 @@ import {
|
|
|
38
38
|
toolNamesOf,
|
|
39
39
|
USER_PROMPT,
|
|
40
40
|
} from "../tests/chatHarness";
|
|
41
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
authAsUser,
|
|
43
|
+
authAsUserWithCredentials,
|
|
44
|
+
ensureTestUsers,
|
|
45
|
+
historyRouterOptions,
|
|
46
|
+
terrenoUserModel,
|
|
47
|
+
} from "../tests/helpers";
|
|
42
48
|
import type {GptHistoryDocument} from "../types";
|
|
43
49
|
import {addGptHistoryRoutes} from "./gptHistories";
|
|
44
50
|
|
|
@@ -799,10 +805,10 @@ describe("/gpt/histories headless turns", () => {
|
|
|
799
805
|
const historyApp = (validation?: ModelRouterOptions<GptHistoryDocument>["validation"]) =>
|
|
800
806
|
new TerrenoApp({
|
|
801
807
|
configureApp: (router, options) => {
|
|
802
|
-
addGptHistoryRoutes(router, {...options, validation});
|
|
808
|
+
addGptHistoryRoutes(router, {...historyRouterOptions(options), validation});
|
|
803
809
|
},
|
|
804
810
|
skipListen: true,
|
|
805
|
-
userModel:
|
|
811
|
+
userModel: terrenoUserModel,
|
|
806
812
|
}).build();
|
|
807
813
|
|
|
808
814
|
afterEach(() => {
|
|
@@ -845,10 +851,10 @@ describe("/gpt/histories headless turns", () => {
|
|
|
845
851
|
it("adds no headless actions without chat options", async () => {
|
|
846
852
|
const app = new TerrenoApp({
|
|
847
853
|
configureApp: (router, options) => {
|
|
848
|
-
addGptHistoryRoutes(router, options);
|
|
854
|
+
addGptHistoryRoutes(router, historyRouterOptions(options));
|
|
849
855
|
},
|
|
850
856
|
skipListen: true,
|
|
851
|
-
userModel:
|
|
857
|
+
userModel: terrenoUserModel,
|
|
852
858
|
}).build();
|
|
853
859
|
const agent = await authAsUser(app, "notAdmin");
|
|
854
860
|
|
|
@@ -865,12 +871,12 @@ describe("/gpt/histories headless turns", () => {
|
|
|
865
871
|
const app = new TerrenoApp({
|
|
866
872
|
configureApp: (router, options) => {
|
|
867
873
|
addGptHistoryRoutes(router, {
|
|
868
|
-
...options,
|
|
874
|
+
...historyRouterOptions(options),
|
|
869
875
|
chat: {aiService: new AIService({model: model as unknown as LanguageModel})},
|
|
870
876
|
});
|
|
871
877
|
},
|
|
872
878
|
skipListen: true,
|
|
873
|
-
userModel:
|
|
879
|
+
userModel: terrenoUserModel,
|
|
874
880
|
}).build();
|
|
875
881
|
const agent = await authAsUser(app, "notAdmin");
|
|
876
882
|
const historyId = await createHistory(agent);
|
|
@@ -892,7 +898,7 @@ describe("/gpt/histories headless turns", () => {
|
|
|
892
898
|
const app = new TerrenoApp({
|
|
893
899
|
configureApp: (router, options) => {
|
|
894
900
|
addGptHistoryRoutes(router, {
|
|
895
|
-
...options,
|
|
901
|
+
...historyRouterOptions(options),
|
|
896
902
|
chat: {
|
|
897
903
|
aiService: new AIService({model: model as unknown as LanguageModel}),
|
|
898
904
|
asks: true,
|
|
@@ -914,7 +920,7 @@ describe("/gpt/histories headless turns", () => {
|
|
|
914
920
|
});
|
|
915
921
|
},
|
|
916
922
|
skipListen: true,
|
|
917
|
-
userModel:
|
|
923
|
+
userModel: terrenoUserModel,
|
|
918
924
|
}).build();
|
|
919
925
|
const agent = await authAsUser(app, "notAdmin");
|
|
920
926
|
const historyId = await createHistory(agent);
|
package/src/routes/mcp.test.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type express from "express";
|
|
|
4
4
|
import supertest from "supertest";
|
|
5
5
|
|
|
6
6
|
import type {MCPService} from "../service/mcpService";
|
|
7
|
-
import {authAsUser, ensureTestUsers,
|
|
7
|
+
import {authAsUser, ensureTestUsers, terrenoUserModel} from "../tests/helpers";
|
|
8
8
|
import {addMcpRoutes} from "./mcp";
|
|
9
9
|
|
|
10
10
|
type MockMcpService = Pick<MCPService, "getServerStatus" | "getTools" | "reconnectServer">;
|
|
@@ -30,7 +30,7 @@ describe("MCP Routes", () => {
|
|
|
30
30
|
addMcpRoutes(router, {mcpService: mcpService as MCPService, openApiOptions: options});
|
|
31
31
|
},
|
|
32
32
|
skipListen: true,
|
|
33
|
-
userModel:
|
|
33
|
+
userModel: terrenoUserModel,
|
|
34
34
|
}).build();
|
|
35
35
|
});
|
|
36
36
|
|
|
@@ -89,7 +89,7 @@ describe("MCP Routes", () => {
|
|
|
89
89
|
addMcpRoutes(router, {mcpService: mcpService as MCPService, openApiOptions: options});
|
|
90
90
|
},
|
|
91
91
|
skipListen: true,
|
|
92
|
-
userModel:
|
|
92
|
+
userModel: terrenoUserModel,
|
|
93
93
|
}).build();
|
|
94
94
|
const agent = await authAsUser(customApp, "admin");
|
|
95
95
|
const res = await agent.post("/mcp/servers/unknown/reconnect");
|
|
@@ -4,7 +4,7 @@ import type express from "express";
|
|
|
4
4
|
import mongoose from "mongoose";
|
|
5
5
|
|
|
6
6
|
import {Project} from "../models/project";
|
|
7
|
-
import {authAsUser, ensureTestUsers, UserModel} from "../tests/helpers";
|
|
7
|
+
import {authAsUser, ensureTestUsers, terrenoUserModel, UserModel} from "../tests/helpers";
|
|
8
8
|
import {addProjectRoutes} from "./projects";
|
|
9
9
|
|
|
10
10
|
describe("Project Routes", () => {
|
|
@@ -24,7 +24,7 @@ describe("Project Routes", () => {
|
|
|
24
24
|
addProjectRoutes(router, {openApiOptions: options});
|
|
25
25
|
},
|
|
26
26
|
skipListen: true,
|
|
27
|
-
userModel:
|
|
27
|
+
userModel: terrenoUserModel,
|
|
28
28
|
}).build();
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -77,7 +77,9 @@ describe("Project Routes", () => {
|
|
|
77
77
|
|
|
78
78
|
it("exposes ownerId virtual aliased to userId", async () => {
|
|
79
79
|
const project = await Project.create({name: "With Owner", userId: notAdminId});
|
|
80
|
-
expect(
|
|
80
|
+
expect(
|
|
81
|
+
project.toObject<{ownerId: mongoose.Types.ObjectId}>({virtuals: true}).ownerId.toString()
|
|
82
|
+
).toBe(notAdminId.toString());
|
|
81
83
|
});
|
|
82
84
|
});
|
|
83
85
|
|
|
@@ -17,7 +17,14 @@ import type {ObservabilityPlugin} from "../observability/types";
|
|
|
17
17
|
import {AIService} from "../service/aiService";
|
|
18
18
|
import type {FileStorageService} from "../service/fileStorage";
|
|
19
19
|
import type {MCPService} from "../service/mcpService";
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
authAsUser,
|
|
22
|
+
ensureTestUsers,
|
|
23
|
+
historyRouterOptions,
|
|
24
|
+
terrenoUserModel,
|
|
25
|
+
UserModel,
|
|
26
|
+
} from "../tests/helpers";
|
|
27
|
+
import type {FileContentPart, ImageContentPart} from "../types/index";
|
|
21
28
|
import {addAiRequestsExplorerRoutes} from "./aiRequestsExplorer";
|
|
22
29
|
import {addGptHistoryRoutes} from "./gptHistories";
|
|
23
30
|
|
|
@@ -25,14 +32,15 @@ type SseResponse = supertest.Response & {body: string};
|
|
|
25
32
|
|
|
26
33
|
// Mock langfuseVercelAi to avoid transitive langfuse SDK import in tests.
|
|
27
34
|
// Spread the real module so later-loaded test files still see the real exports.
|
|
28
|
-
|
|
35
|
+
// The package compiles as CommonJS, so modules load with require instead of top-level await.
|
|
36
|
+
const realLangfuseVercelAi: typeof import("../langfuseVercelAi.js") = require("../langfuseVercelAi");
|
|
29
37
|
mock.module("../langfuseVercelAi", () => ({
|
|
30
38
|
...realLangfuseVercelAi,
|
|
31
39
|
createTelemetryConfig: () => ({functionId: "test", isEnabled: false}),
|
|
32
40
|
preparePromptForAI: async () => ({config: {}, prompt: "test", telemetry: {isEnabled: false}}),
|
|
33
41
|
}));
|
|
34
42
|
|
|
35
|
-
const realAi
|
|
43
|
+
const realAi: typeof import("ai") = require("ai");
|
|
36
44
|
type StreamTextOptions = Parameters<typeof realAi.streamText>[0];
|
|
37
45
|
type StreamTextResult = ReturnType<typeof realAi.streamText>;
|
|
38
46
|
const realStreamText = realAi.streamText;
|
|
@@ -43,7 +51,7 @@ mock.module("ai", () => ({
|
|
|
43
51
|
streamTextOverride ? streamTextOverride(options) : realStreamText(options),
|
|
44
52
|
}));
|
|
45
53
|
|
|
46
|
-
const {addGptRoutes}
|
|
54
|
+
const {addGptRoutes}: typeof import("./gpt.js") = require("./gpt");
|
|
47
55
|
|
|
48
56
|
// Create mock AI model (LanguageModelV2)
|
|
49
57
|
const createMockModel = (modelId = "mock-model") => ({
|
|
@@ -193,12 +201,12 @@ describe("AI Routes", () => {
|
|
|
193
201
|
|
|
194
202
|
app = new TerrenoApp({
|
|
195
203
|
configureApp: (router, options) => {
|
|
196
|
-
addGptHistoryRoutes(router, options);
|
|
204
|
+
addGptHistoryRoutes(router, historyRouterOptions(options));
|
|
197
205
|
addGptRoutes(router, {aiService, openApiOptions: options});
|
|
198
206
|
addAiRequestsExplorerRoutes(router, {openApiOptions: options});
|
|
199
207
|
},
|
|
200
208
|
skipListen: true,
|
|
201
|
-
userModel:
|
|
209
|
+
userModel: terrenoUserModel,
|
|
202
210
|
}).build();
|
|
203
211
|
});
|
|
204
212
|
|
|
@@ -262,7 +270,7 @@ describe("AI Routes", () => {
|
|
|
262
270
|
addGptRoutes(router, {openApiOptions: options});
|
|
263
271
|
},
|
|
264
272
|
skipListen: true,
|
|
265
|
-
userModel:
|
|
273
|
+
userModel: terrenoUserModel,
|
|
266
274
|
}).build();
|
|
267
275
|
const agent = await authAsUser(demoApp, "notAdmin");
|
|
268
276
|
const res = await agent.post("/gpt/remix").send({text: "Hello"});
|
|
@@ -397,7 +405,7 @@ describe("AI Routes", () => {
|
|
|
397
405
|
addGptRoutes(router, {openApiOptions: options});
|
|
398
406
|
},
|
|
399
407
|
skipListen: true,
|
|
400
|
-
userModel:
|
|
408
|
+
userModel: terrenoUserModel,
|
|
401
409
|
}).build();
|
|
402
410
|
const agent = await authAsUser(demoApp, "notAdmin");
|
|
403
411
|
const res = await agent
|
|
@@ -419,7 +427,7 @@ describe("AI Routes", () => {
|
|
|
419
427
|
addGptRoutes(router, {createModelFn, openApiOptions: options});
|
|
420
428
|
},
|
|
421
429
|
skipListen: true,
|
|
422
|
-
userModel:
|
|
430
|
+
userModel: terrenoUserModel,
|
|
423
431
|
}).build();
|
|
424
432
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
425
433
|
const res = await agent
|
|
@@ -441,7 +449,7 @@ describe("AI Routes", () => {
|
|
|
441
449
|
addGptRoutes(router, {createServerModelFn, openApiOptions: options});
|
|
442
450
|
},
|
|
443
451
|
skipListen: true,
|
|
444
|
-
userModel:
|
|
452
|
+
userModel: terrenoUserModel,
|
|
445
453
|
}).build();
|
|
446
454
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
447
455
|
const res = await agent
|
|
@@ -454,13 +462,16 @@ describe("AI Routes", () => {
|
|
|
454
462
|
});
|
|
455
463
|
|
|
456
464
|
it("falls back to default aiService when createServerModelFn returns null", async () => {
|
|
457
|
-
|
|
465
|
+
// A JavaScript host may return null even though the option's type says undefined.
|
|
466
|
+
const createServerModelFn = mock(
|
|
467
|
+
(_modelId?: string) => null as unknown as LanguageModel | undefined
|
|
468
|
+
);
|
|
458
469
|
const customApp = new TerrenoApp({
|
|
459
470
|
configureApp: (router, options) => {
|
|
460
471
|
addGptRoutes(router, {aiService, createServerModelFn, openApiOptions: options});
|
|
461
472
|
},
|
|
462
473
|
skipListen: true,
|
|
463
|
-
userModel:
|
|
474
|
+
userModel: terrenoUserModel,
|
|
464
475
|
}).build();
|
|
465
476
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
466
477
|
const res = await agent
|
|
@@ -576,7 +587,7 @@ describe("AI Routes", () => {
|
|
|
576
587
|
addGptRoutes(router, {aiService: noFinishService, openApiOptions: options});
|
|
577
588
|
},
|
|
578
589
|
skipListen: true,
|
|
579
|
-
userModel:
|
|
590
|
+
userModel: terrenoUserModel,
|
|
580
591
|
}).build();
|
|
581
592
|
const agent = await authAsUser(noFinishApp, "notAdmin");
|
|
582
593
|
const res = await agent
|
|
@@ -598,7 +609,7 @@ describe("AI Routes", () => {
|
|
|
598
609
|
addGptRoutes(router, {aiService: imageService, openApiOptions: options});
|
|
599
610
|
},
|
|
600
611
|
skipListen: true,
|
|
601
|
-
userModel:
|
|
612
|
+
userModel: terrenoUserModel,
|
|
602
613
|
}).build();
|
|
603
614
|
const agent = await authAsUser(imgApp, "notAdmin");
|
|
604
615
|
const res = await agent
|
|
@@ -622,7 +633,7 @@ describe("AI Routes", () => {
|
|
|
622
633
|
addGptRoutes(router, {aiService: imageService, openApiOptions: options});
|
|
623
634
|
},
|
|
624
635
|
skipListen: true,
|
|
625
|
-
userModel:
|
|
636
|
+
userModel: terrenoUserModel,
|
|
626
637
|
}).build();
|
|
627
638
|
const agent = await authAsUser(imgApp, "notAdmin");
|
|
628
639
|
const res = await agent
|
|
@@ -638,7 +649,9 @@ describe("AI Routes", () => {
|
|
|
638
649
|
const assistant = history.prompts.find((p) => p.type === "assistant");
|
|
639
650
|
expect(assistant?.text).toBe("");
|
|
640
651
|
expect(assistant?.content).toHaveLength(1);
|
|
641
|
-
expect(assistant?.content?.[0]?.url).toBe(
|
|
652
|
+
expect((assistant?.content?.[0] as ImageContentPart | undefined)?.url).toBe(
|
|
653
|
+
"data:image/png;base64,aGVsbG8="
|
|
654
|
+
);
|
|
642
655
|
});
|
|
643
656
|
|
|
644
657
|
it("writes an SSE error event when the model stream throws", async () => {
|
|
@@ -650,7 +663,7 @@ describe("AI Routes", () => {
|
|
|
650
663
|
addGptRoutes(router, {aiService: errService, openApiOptions: options});
|
|
651
664
|
},
|
|
652
665
|
skipListen: true,
|
|
653
|
-
userModel:
|
|
666
|
+
userModel: terrenoUserModel,
|
|
654
667
|
}).build();
|
|
655
668
|
const agent = await authAsUser(errApp, "notAdmin");
|
|
656
669
|
const res = await agent
|
|
@@ -674,7 +687,7 @@ describe("AI Routes", () => {
|
|
|
674
687
|
addGptRoutes(router, {aiService, mcpService, openApiOptions: options});
|
|
675
688
|
},
|
|
676
689
|
skipListen: true,
|
|
677
|
-
userModel:
|
|
690
|
+
userModel: terrenoUserModel,
|
|
678
691
|
}).build();
|
|
679
692
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
680
693
|
const res = await agent
|
|
@@ -697,7 +710,7 @@ describe("AI Routes", () => {
|
|
|
697
710
|
addGptRoutes(router, {aiService, mcpService, openApiOptions: options});
|
|
698
711
|
},
|
|
699
712
|
skipListen: true,
|
|
700
|
-
userModel:
|
|
713
|
+
userModel: terrenoUserModel,
|
|
701
714
|
}).build();
|
|
702
715
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
703
716
|
const res = await agent
|
|
@@ -727,7 +740,7 @@ describe("AI Routes", () => {
|
|
|
727
740
|
});
|
|
728
741
|
},
|
|
729
742
|
skipListen: true,
|
|
730
|
-
userModel:
|
|
743
|
+
userModel: terrenoUserModel,
|
|
731
744
|
}).build();
|
|
732
745
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
733
746
|
const res = await agent
|
|
@@ -752,7 +765,7 @@ describe("AI Routes", () => {
|
|
|
752
765
|
});
|
|
753
766
|
},
|
|
754
767
|
skipListen: true,
|
|
755
|
-
userModel:
|
|
768
|
+
userModel: terrenoUserModel,
|
|
756
769
|
}).build();
|
|
757
770
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
758
771
|
const res = await agent
|
|
@@ -785,7 +798,7 @@ describe("AI Routes", () => {
|
|
|
785
798
|
});
|
|
786
799
|
},
|
|
787
800
|
skipListen: true,
|
|
788
|
-
userModel:
|
|
801
|
+
userModel: terrenoUserModel,
|
|
789
802
|
}).build();
|
|
790
803
|
const agent = await authAsUser(imgApp, "notAdmin");
|
|
791
804
|
const res = await agent
|
|
@@ -806,7 +819,7 @@ describe("AI Routes", () => {
|
|
|
806
819
|
});
|
|
807
820
|
},
|
|
808
821
|
skipListen: true,
|
|
809
|
-
userModel:
|
|
822
|
+
userModel: terrenoUserModel,
|
|
810
823
|
}).build();
|
|
811
824
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
812
825
|
const res = await agent
|
|
@@ -912,7 +925,7 @@ describe("AI Routes", () => {
|
|
|
912
925
|
});
|
|
913
926
|
},
|
|
914
927
|
skipListen: true,
|
|
915
|
-
userModel:
|
|
928
|
+
userModel: terrenoUserModel,
|
|
916
929
|
}).build();
|
|
917
930
|
const agent = await authAsUser(toolApp, "notAdmin");
|
|
918
931
|
const res = await agent
|
|
@@ -1018,7 +1031,7 @@ describe("AI Routes", () => {
|
|
|
1018
1031
|
});
|
|
1019
1032
|
},
|
|
1020
1033
|
skipListen: true,
|
|
1021
|
-
userModel:
|
|
1034
|
+
userModel: terrenoUserModel,
|
|
1022
1035
|
}).build();
|
|
1023
1036
|
const agent = await authAsUser(fileToolApp, "notAdmin");
|
|
1024
1037
|
const res = await agent
|
|
@@ -1074,7 +1087,7 @@ describe("AI Routes", () => {
|
|
|
1074
1087
|
});
|
|
1075
1088
|
},
|
|
1076
1089
|
skipListen: true,
|
|
1077
|
-
userModel:
|
|
1090
|
+
userModel: terrenoUserModel,
|
|
1078
1091
|
}).build();
|
|
1079
1092
|
const agent = await authAsUser(errApp, "notAdmin");
|
|
1080
1093
|
const res = await agent
|
|
@@ -1127,7 +1140,7 @@ describe("AI Routes", () => {
|
|
|
1127
1140
|
});
|
|
1128
1141
|
},
|
|
1129
1142
|
skipListen: true,
|
|
1130
|
-
userModel:
|
|
1143
|
+
userModel: terrenoUserModel,
|
|
1131
1144
|
}).build();
|
|
1132
1145
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
1133
1146
|
const res = await agent
|
|
@@ -1199,7 +1212,7 @@ describe("AI Routes", () => {
|
|
|
1199
1212
|
});
|
|
1200
1213
|
},
|
|
1201
1214
|
skipListen: true,
|
|
1202
|
-
userModel:
|
|
1215
|
+
userModel: terrenoUserModel,
|
|
1203
1216
|
}).build();
|
|
1204
1217
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
1205
1218
|
const res = await agent
|
|
@@ -1225,7 +1238,7 @@ describe("AI Routes", () => {
|
|
|
1225
1238
|
});
|
|
1226
1239
|
},
|
|
1227
1240
|
skipListen: true,
|
|
1228
|
-
userModel:
|
|
1241
|
+
userModel: terrenoUserModel,
|
|
1229
1242
|
}).build();
|
|
1230
1243
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
1231
1244
|
const res = await agent
|
|
@@ -1277,7 +1290,7 @@ describe("AI Routes", () => {
|
|
|
1277
1290
|
});
|
|
1278
1291
|
},
|
|
1279
1292
|
skipListen: true,
|
|
1280
|
-
userModel:
|
|
1293
|
+
userModel: terrenoUserModel,
|
|
1281
1294
|
}).build();
|
|
1282
1295
|
const agent = await authAsUser(fileApp, "notAdmin");
|
|
1283
1296
|
const res = await agent
|
|
@@ -1446,7 +1459,7 @@ describe("AI Routes", () => {
|
|
|
1446
1459
|
addGptRoutes(router, {aiService, openApiOptions: options, ...extra});
|
|
1447
1460
|
},
|
|
1448
1461
|
skipListen: true,
|
|
1449
|
-
userModel:
|
|
1462
|
+
userModel: terrenoUserModel,
|
|
1450
1463
|
}).build();
|
|
1451
1464
|
|
|
1452
1465
|
it("rejects attachments when file uploads are disabled", async () => {
|
|
@@ -1684,7 +1697,10 @@ describe("AI Routes", () => {
|
|
|
1684
1697
|
.patch(`/gpt/histories/${historyId}`)
|
|
1685
1698
|
.send({prompts: stored.body.data.prompts});
|
|
1686
1699
|
expect(roundTripped.status).toBe(200);
|
|
1687
|
-
|
|
1700
|
+
const filePart = (await GptHistory.findById(historyId))?.prompts[0].content?.[1] as
|
|
1701
|
+
| FileContentPart
|
|
1702
|
+
| ImageContentPart;
|
|
1703
|
+
expect(filePart.gcsKey).toBe(ownKey);
|
|
1688
1704
|
|
|
1689
1705
|
const patched = await agent.patch(`/gpt/histories/${historyId}`).send({
|
|
1690
1706
|
prompts: [{content: [{text: "f", type: "text"}, plantedPart], text: "f", type: "user"}],
|
|
@@ -1999,7 +2015,7 @@ describe("AI Routes", () => {
|
|
|
1999
2015
|
});
|
|
2000
2016
|
},
|
|
2001
2017
|
skipListen: true,
|
|
2002
|
-
userModel:
|
|
2018
|
+
userModel: terrenoUserModel,
|
|
2003
2019
|
}).build();
|
|
2004
2020
|
const agent = await authAsUser(errApp, "notAdmin");
|
|
2005
2021
|
|
|
@@ -2047,7 +2063,7 @@ describe("AI Routes", () => {
|
|
|
2047
2063
|
addGptRoutes(router, {aiService, openApiOptions: options});
|
|
2048
2064
|
},
|
|
2049
2065
|
skipListen: true,
|
|
2050
|
-
userModel:
|
|
2066
|
+
userModel: terrenoUserModel,
|
|
2051
2067
|
}).build();
|
|
2052
2068
|
const agent = await authAsUser(errApp, "notAdmin");
|
|
2053
2069
|
|
|
@@ -2097,7 +2113,7 @@ describe("AI Routes", () => {
|
|
|
2097
2113
|
});
|
|
2098
2114
|
},
|
|
2099
2115
|
skipListen: true,
|
|
2100
|
-
userModel:
|
|
2116
|
+
userModel: terrenoUserModel,
|
|
2101
2117
|
}).build();
|
|
2102
2118
|
const agent = await authAsUser(errApp, "notAdmin");
|
|
2103
2119
|
const res = await agent
|
|
@@ -2150,7 +2166,7 @@ describe("AI Routes", () => {
|
|
|
2150
2166
|
});
|
|
2151
2167
|
},
|
|
2152
2168
|
skipListen: true,
|
|
2153
|
-
userModel:
|
|
2169
|
+
userModel: terrenoUserModel,
|
|
2154
2170
|
}).build();
|
|
2155
2171
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
2156
2172
|
const res = await agent
|
|
@@ -2214,7 +2230,7 @@ describe("AI Routes", () => {
|
|
|
2214
2230
|
});
|
|
2215
2231
|
},
|
|
2216
2232
|
skipListen: true,
|
|
2217
|
-
userModel:
|
|
2233
|
+
userModel: terrenoUserModel,
|
|
2218
2234
|
}).build();
|
|
2219
2235
|
const originalLogRequest = AIRequest.logRequest;
|
|
2220
2236
|
AIRequest.logRequest = mock(async () => {
|
|
@@ -2248,7 +2264,7 @@ describe("AI Routes", () => {
|
|
|
2248
2264
|
});
|
|
2249
2265
|
},
|
|
2250
2266
|
skipListen: true,
|
|
2251
|
-
userModel:
|
|
2267
|
+
userModel: terrenoUserModel,
|
|
2252
2268
|
}).build();
|
|
2253
2269
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
2254
2270
|
const res = await agent.get("/gpt/tools");
|
|
@@ -2265,7 +2281,7 @@ describe("AI Routes", () => {
|
|
|
2265
2281
|
addGptRoutes(router, {aiService, createRequestTools, openApiOptions: options});
|
|
2266
2282
|
},
|
|
2267
2283
|
skipListen: true,
|
|
2268
|
-
userModel:
|
|
2284
|
+
userModel: terrenoUserModel,
|
|
2269
2285
|
}).build();
|
|
2270
2286
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
2271
2287
|
const res = await agent.get("/gpt/tools");
|
|
@@ -2282,7 +2298,7 @@ describe("AI Routes", () => {
|
|
|
2282
2298
|
addGptRoutes(router, {aiService, mcpService, openApiOptions: options});
|
|
2283
2299
|
},
|
|
2284
2300
|
skipListen: true,
|
|
2285
|
-
userModel:
|
|
2301
|
+
userModel: terrenoUserModel,
|
|
2286
2302
|
}).build();
|
|
2287
2303
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
2288
2304
|
const res = await agent.get("/gpt/tools");
|
|
@@ -2301,7 +2317,7 @@ describe("AI Routes", () => {
|
|
|
2301
2317
|
addGptRoutes(router, {aiService, mcpService, openApiOptions: options});
|
|
2302
2318
|
},
|
|
2303
2319
|
skipListen: true,
|
|
2304
|
-
userModel:
|
|
2320
|
+
userModel: terrenoUserModel,
|
|
2305
2321
|
}).build();
|
|
2306
2322
|
const agent = await authAsUser(customApp, "notAdmin");
|
|
2307
2323
|
const res = await agent.get("/gpt/tools");
|
|
@@ -2556,7 +2572,7 @@ describe("AI Routes", () => {
|
|
|
2556
2572
|
});
|
|
2557
2573
|
},
|
|
2558
2574
|
skipListen: true,
|
|
2559
|
-
userModel:
|
|
2575
|
+
userModel: terrenoUserModel,
|
|
2560
2576
|
}).build();
|
|
2561
2577
|
const agent = await authAsUser(fileApp, "notAdmin");
|
|
2562
2578
|
const res = await agent
|
|
@@ -13,7 +13,7 @@ import {AIService, TemperaturePresets} from "./aiService";
|
|
|
13
13
|
// Create a mock LanguageModelV2
|
|
14
14
|
const createMockModel = (responseText = "Mock response") => {
|
|
15
15
|
return {
|
|
16
|
-
doGenerate: mock(async () => ({
|
|
16
|
+
doGenerate: mock(async (_options: unknown) => ({
|
|
17
17
|
content: [{text: responseText, type: "text" as const}],
|
|
18
18
|
finishReason: "stop" as const,
|
|
19
19
|
usage: {inputTokens: 5, outputTokens: 10},
|
package/src/service/asks.test.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
2
|
import {ASK_LIMITS, type AskKind, type AskResponse, askPromptSection} from "@terreno/blocks";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
asSchema,
|
|
5
|
+
type JSONValue,
|
|
6
|
+
jsonSchema,
|
|
7
|
+
type ModelMessage,
|
|
8
|
+
type Tool,
|
|
9
|
+
type ToolResultPart,
|
|
10
|
+
tool,
|
|
11
|
+
} from "ai";
|
|
4
12
|
|
|
5
13
|
import {
|
|
6
14
|
approvalAskInput,
|
|
@@ -24,7 +32,7 @@ const PLAN_ASK_INPUT = {
|
|
|
24
32
|
{id: "team", label: "Team"},
|
|
25
33
|
],
|
|
26
34
|
prompt: "Which plan should I set up?",
|
|
27
|
-
select: "one",
|
|
35
|
+
select: "one" as const,
|
|
28
36
|
};
|
|
29
37
|
|
|
30
38
|
const TEAM_ANSWER = {action: "accept" as const, content: {selected: ["team"]}};
|
|
@@ -57,8 +65,8 @@ const lookupResult = {
|
|
|
57
65
|
type: "tool-result" as const,
|
|
58
66
|
};
|
|
59
67
|
|
|
60
|
-
const answerResult = (toolCallId: string, value: unknown) => ({
|
|
61
|
-
output: {type: "json", value},
|
|
68
|
+
const answerResult = (toolCallId: string, value: unknown): ToolResultPart => ({
|
|
69
|
+
output: {type: "json", value: value as JSONValue},
|
|
62
70
|
toolCallId,
|
|
63
71
|
toolName: "ask_choice",
|
|
64
72
|
type: "tool-result",
|
|
@@ -76,14 +84,14 @@ describe("asks", () => {
|
|
|
76
84
|
expected: ["confirm"],
|
|
77
85
|
label: '{kinds: ["confirm"]}',
|
|
78
86
|
},
|
|
79
|
-
{asks: {kinds: []}, expected: [], label: "{kinds: []}"},
|
|
87
|
+
{asks: {kinds: [] as AskKind[]}, expected: [], label: "{kinds: []}"},
|
|
80
88
|
{
|
|
81
89
|
asks: {kinds: ["choice", "choice"] as AskKind[]},
|
|
82
90
|
expected: ["choice"],
|
|
83
91
|
label: '{kinds: ["choice", "choice"]}',
|
|
84
92
|
},
|
|
85
93
|
])("resolves $label", ({asks, expected}) => {
|
|
86
|
-
expect(resolveAskKinds(asks)).toEqual(expected);
|
|
94
|
+
expect(resolveAskKinds(asks)).toEqual([...expected]);
|
|
87
95
|
});
|
|
88
96
|
|
|
89
97
|
it("throws on an unknown kind and names the known kinds", () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {afterEach, beforeEach, describe, expect, it} from "bun:test";
|
|
1
|
+
import {afterEach, beforeAll, beforeEach, describe, expect, it} from "bun:test";
|
|
2
2
|
import {registerGcsMock} from "@terreno/test";
|
|
3
3
|
import mongoose from "mongoose";
|
|
4
4
|
|
|
@@ -7,7 +7,10 @@ import {FileAttachment} from "../models/fileAttachment";
|
|
|
7
7
|
// In-memory @google-cloud/storage so the service doesn't try to authenticate
|
|
8
8
|
const gcs = registerGcsMock();
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
let FileStorageService: typeof import("./fileStorage.js").FileStorageService;
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
({FileStorageService} = await import("./fileStorage.js"));
|
|
13
|
+
});
|
|
11
14
|
|
|
12
15
|
describe("FileStorageService", () => {
|
|
13
16
|
beforeEach(async () => {
|