@terreno/ai 0.20.2 → 0.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.
@@ -9,7 +9,7 @@ A monorepo containing shared packages for building full-stack applications with
9
9
  - **rtk/** - Redux Toolkit Query utilities for API backends (`@terreno/rtk`)
10
10
  - **admin-backend/** - Admin panel backend plugin for @terreno/api (`@terreno/admin-backend`)
11
11
  - **admin-frontend/** - Admin panel frontend screens for @terreno/api backends (`@terreno/admin-frontend`)
12
- - **mcp-server/** - MCP server for AI assistant integration (`@terreno/mcp-server`)
12
+ - **mcp-server/** - MCP server for AI assistant integration (`@terreno/mcp`, bins `terreno-mcp` / `terreno-mcp-local`)
13
13
  - **demo/** - Demo app for showcasing and testing UI components
14
14
  - **example-frontend/** - Example Expo app demonstrating full stack usage
15
15
  - **example-backend/** - Example Express backend using @terreno/api
package/AGENTS.md CHANGED
@@ -9,7 +9,7 @@ A monorepo containing shared packages for building full-stack applications with
9
9
  - **rtk/** - Redux Toolkit Query utilities for API backends (`@terreno/rtk`)
10
10
  - **admin-backend/** - Admin panel backend plugin for @terreno/api (`@terreno/admin-backend`)
11
11
  - **admin-frontend/** - Admin panel frontend screens for @terreno/api backends (`@terreno/admin-frontend`)
12
- - **mcp-server/** - MCP server for AI assistant integration (`@terreno/mcp-server`)
12
+ - **mcp-server/** - MCP server for AI assistant integration (`@terreno/mcp`, bins `terreno-mcp` / `terreno-mcp-local`)
13
13
  - **demo/** - Demo app for showcasing and testing UI components
14
14
  - **example-frontend/** - Example Expo app demonstrating full stack usage
15
15
  - **example-backend/** - Example Express backend using @terreno/api
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "ai": "^6.0.97",
14
14
  "google-auth-library": "^10.5.0",
15
15
  "luxon": "^3.7.2",
16
- "multer": "^1.4.5-lts.1"
16
+ "multer": "2.2.0"
17
17
  },
18
18
  "description": "AI service layer for Terreno apps - GPT chat, request logging, and admin tools.",
19
19
  "devDependencies": {
@@ -24,7 +24,7 @@
24
24
  "@types/multer": "^1.4.12",
25
25
  "@types/passport-local-mongoose": "^6.1.5",
26
26
  "@types/supertest": "^6.0.2",
27
- "@terreno/api": "0.20.2",
27
+ "@terreno/api": "0.21.0",
28
28
  "mongoose": "8.23.0",
29
29
  "passport-local-mongoose": "^9.0.1",
30
30
  "supertest": "^7.0.0",
@@ -71,7 +71,7 @@
71
71
  "access": "public"
72
72
  },
73
73
  "peerDependencies": {
74
- "@terreno/api": "0.20.2",
74
+ "@terreno/api": "0.21.0",
75
75
  "mongoose": "^8.0.0"
76
76
  },
77
77
  "repository": {
@@ -90,5 +90,5 @@
90
90
  "test:coverage": "bun run ../scripts/check-coverage.ts"
91
91
  },
92
92
  "types": "dist/index.d.ts",
93
- "version": "0.20.2"
93
+ "version": "0.21.0"
94
94
  }
package/src/aiApp.test.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import {beforeAll, describe, expect, it, mock} from "bun:test";
2
- import {createdUpdatedPlugin, setupServer} from "@terreno/api";
2
+ import {createdUpdatedPlugin, TerrenoApp} from "@terreno/api";
3
3
  import type {LanguageModel} from "ai";
4
4
  import type express from "express";
5
5
  import mongoose from "mongoose";
@@ -73,11 +73,11 @@ describe("AiApp", () => {
73
73
  const {AIService} = await import("./service/aiService");
74
74
  const aiService = new AIService({model: createMockModel() as unknown as LanguageModel});
75
75
  const plugin = new AiApp({aiService});
76
- const app = setupServer({
77
- addRoutes: (router) => plugin.register(router as unknown as express.Application),
76
+ const app = new TerrenoApp({
77
+ configureApp: (router) => plugin.register(router as unknown as express.Application),
78
78
  skipListen: true,
79
79
  userModel: UserModel,
80
- });
80
+ }).build();
81
81
 
82
82
  const agent = await authAsUser(app);
83
83
  const tools = await agent.get("/gpt/tools");
@@ -101,11 +101,11 @@ describe("AiApp", () => {
101
101
  })),
102
102
  } as unknown as FileStorageService;
103
103
  const plugin = new AiApp({fileStorageService, gcsBucket: "test-bucket"});
104
- const app = setupServer({
105
- addRoutes: (router) => plugin.register(router as unknown as express.Application),
104
+ const app = new TerrenoApp({
105
+ configureApp: (router) => plugin.register(router as unknown as express.Application),
106
106
  skipListen: true,
107
107
  userModel: UserModel,
108
- });
108
+ }).build();
109
109
  // Unauthenticated access to upload route: ensure it exists (returns 401, not 404).
110
110
  const upload = await supertest(app).post("/files/upload");
111
111
  expect(upload.status).not.toBe(404);
@@ -122,11 +122,11 @@ describe("AiApp", () => {
122
122
  })),
123
123
  } as unknown as FileStorageService;
124
124
  const plugin = new AiApp({fileStorageService});
125
- const app = setupServer({
126
- addRoutes: (router) => plugin.register(router as unknown as express.Application),
125
+ const app = new TerrenoApp({
126
+ configureApp: (router) => plugin.register(router as unknown as express.Application),
127
127
  skipListen: true,
128
128
  userModel: UserModel,
129
- });
129
+ }).build();
130
130
  const upload = await supertest(app).post("/files/upload");
131
131
  expect(upload.status).toBe(404);
132
132
  });
@@ -138,11 +138,11 @@ describe("AiApp", () => {
138
138
  reconnectServer: mock(async () => {}),
139
139
  } as unknown as MCPService;
140
140
  const plugin = new AiApp({mcpService});
141
- const app = setupServer({
142
- addRoutes: (router) => plugin.register(router as unknown as express.Application),
141
+ const app = new TerrenoApp({
142
+ configureApp: (router) => plugin.register(router as unknown as express.Application),
143
143
  skipListen: true,
144
144
  userModel: UserModel,
145
- });
145
+ }).build();
146
146
  const agent = await authAsUser(app);
147
147
  const servers = await agent.get("/mcp/servers");
148
148
  expect(servers.status).not.toBe(404);
@@ -1,5 +1,5 @@
1
1
  import {beforeAll, beforeEach, describe, expect, it} from "bun:test";
2
- import {createdUpdatedPlugin, setupServer} from "@terreno/api";
2
+ import {createdUpdatedPlugin, TerrenoApp} from "@terreno/api";
3
3
  import type express from "express";
4
4
  import mongoose from "mongoose";
5
5
  import passportLocalMongoose from "passport-local-mongoose";
@@ -25,11 +25,11 @@ userSchema.plugin(createdUpdatedPlugin);
25
25
  const UserModel = mongoose.models.User || mongoose.model("User", userSchema);
26
26
 
27
27
  const buildApp = (plugin: LangfuseApp) =>
28
- setupServer({
29
- addRoutes: (router) => plugin.register(router as unknown as express.Application),
28
+ new TerrenoApp({
29
+ configureApp: (router) => plugin.register(router as unknown as express.Application),
30
30
  skipListen: true,
31
31
  userModel: UserModel,
32
- });
32
+ }).build();
33
33
 
34
34
  describe("LangfuseApp", () => {
35
35
  beforeAll(async () => {
@@ -1,5 +1,6 @@
1
1
  import {beforeAll, beforeEach, describe, expect, it, mock} from "bun:test";
2
- import {createdUpdatedPlugin, setupServer} from "@terreno/api";
2
+ import {createdUpdatedPlugin, TerrenoApp, type TerrenoAppOptions} from "@terreno/api";
3
+ import type express from "express";
3
4
  import mongoose from "mongoose";
4
5
  import passportLocalMongoose from "passport-local-mongoose";
5
6
  import supertest from "supertest";
@@ -56,7 +57,7 @@ const authAsUser = async (
56
57
  return agent;
57
58
  };
58
59
 
59
- let app: ReturnType<typeof setupServer>;
60
+ let app: express.Application;
60
61
 
61
62
  describe("Langfuse routes", () => {
62
63
  beforeAll(async () => {
@@ -97,16 +98,16 @@ describe("Langfuse routes", () => {
97
98
  client.prompt.get = promptGet;
98
99
  client.score.create = scoreCreate;
99
100
 
100
- app = setupServer({
101
- addRoutes: (router) => {
101
+ app = new TerrenoApp({
102
+ configureApp: (router) => {
102
103
  addPromptRoutes(router, "/admin/langfuse");
103
104
  addTraceRoutes(router, "/admin/langfuse");
104
105
  addPlaygroundRoutes(router, "/admin/langfuse");
105
106
  addEvaluationRoutes(router, "/admin/langfuse", []);
106
107
  },
107
108
  skipListen: true,
108
- userModel: UserModel as Parameters<typeof setupServer>[0]["userModel"],
109
- });
109
+ userModel: UserModel as unknown as TerrenoAppOptions["userModel"],
110
+ }).build();
110
111
  });
111
112
 
112
113
  describe("prompt routes", () => {
@@ -1,5 +1,5 @@
1
1
  import {beforeAll, beforeEach, describe, expect, it, mock} from "bun:test";
2
- import {createdUpdatedPlugin, setupServer} from "@terreno/api";
2
+ import {createdUpdatedPlugin, TerrenoApp} from "@terreno/api";
3
3
  import type express from "express";
4
4
  import mongoose from "mongoose";
5
5
  import passportLocalMongoose from "passport-local-mongoose";
@@ -69,8 +69,8 @@ describe("File Routes", () => {
69
69
  })
70
70
  ),
71
71
  };
72
- app = setupServer({
73
- addRoutes: (router, options) => {
72
+ app = new TerrenoApp({
73
+ configureApp: (router, options) => {
74
74
  addFileRoutes(router, {
75
75
  fileStorageService: fileStorageService as FileStorageService,
76
76
  openApiOptions: options,
@@ -78,7 +78,7 @@ describe("File Routes", () => {
78
78
  },
79
79
  skipListen: true,
80
80
  userModel: UserModel,
81
- });
81
+ }).build();
82
82
  });
83
83
 
84
84
  describe("POST /files/upload", () => {
@@ -1,5 +1,5 @@
1
1
  import {beforeAll, beforeEach, describe, expect, it, mock} from "bun:test";
2
- import {createdUpdatedPlugin, setupServer} from "@terreno/api";
2
+ import {createdUpdatedPlugin, TerrenoApp} from "@terreno/api";
3
3
  import type express from "express";
4
4
  import mongoose from "mongoose";
5
5
  import passportLocalMongoose from "passport-local-mongoose";
@@ -57,13 +57,13 @@ describe("MCP Routes", () => {
57
57
  })),
58
58
  reconnectServer: mock(async () => true),
59
59
  } as unknown as MockMcpService;
60
- app = setupServer({
61
- addRoutes: (router, options) => {
60
+ app = new TerrenoApp({
61
+ configureApp: (router, options) => {
62
62
  addMcpRoutes(router, {mcpService: mcpService as MCPService, openApiOptions: options});
63
63
  },
64
64
  skipListen: true,
65
65
  userModel: UserModel,
66
- });
66
+ }).build();
67
67
  });
68
68
 
69
69
  describe("GET /mcp/servers", () => {
@@ -116,13 +116,13 @@ describe("MCP Routes", () => {
116
116
 
117
117
  it("returns connected=false when reconnect fails", async () => {
118
118
  mcpService.reconnectServer = mock(async () => false);
119
- const customApp = setupServer({
120
- addRoutes: (router, options) => {
119
+ const customApp = new TerrenoApp({
120
+ configureApp: (router, options) => {
121
121
  addMcpRoutes(router, {mcpService: mcpService as MCPService, openApiOptions: options});
122
122
  },
123
123
  skipListen: true,
124
124
  userModel: UserModel,
125
- });
125
+ }).build();
126
126
  const agent = await authAsUser(customApp, "admin");
127
127
  const res = await agent.post("/mcp/servers/unknown/reconnect");
128
128
  expect(res.status).toBe(200);
@@ -1,5 +1,5 @@
1
1
  import {beforeAll, beforeEach, describe, expect, it} from "bun:test";
2
- import {createdUpdatedPlugin, setupServer} from "@terreno/api";
2
+ import {createdUpdatedPlugin, TerrenoApp} from "@terreno/api";
3
3
  import type express from "express";
4
4
  import mongoose from "mongoose";
5
5
  import passportLocalMongoose from "passport-local-mongoose";
@@ -51,13 +51,13 @@ describe("Project Routes", () => {
51
51
 
52
52
  beforeEach(async () => {
53
53
  await Project.deleteMany({});
54
- app = setupServer({
55
- addRoutes: (router, options) => {
54
+ app = new TerrenoApp({
55
+ configureApp: (router, options) => {
56
56
  addProjectRoutes(router, {openApiOptions: options});
57
57
  },
58
58
  skipListen: true,
59
59
  userModel: UserModel,
60
- });
60
+ }).build();
61
61
  });
62
62
 
63
63
  describe("project memories (subdoc)", () => {
@@ -1,5 +1,5 @@
1
1
  import {afterEach, beforeAll, beforeEach, describe, expect, it, mock} from "bun:test";
2
- import {createdUpdatedPlugin, setupServer} from "@terreno/api";
2
+ import {createdUpdatedPlugin, TerrenoApp} from "@terreno/api";
3
3
  import {jsonSchema, type LanguageModel, type Tool, tool} from "ai";
4
4
  import type express from "express";
5
5
  import mongoose from "mongoose";
@@ -155,15 +155,15 @@ describe("AI Routes", () => {
155
155
  const mockModel = createMockModel();
156
156
  aiService = new AIService({model: mockModel as unknown as LanguageModel});
157
157
 
158
- app = setupServer({
159
- addRoutes: (router, options) => {
158
+ app = new TerrenoApp({
159
+ configureApp: (router, options) => {
160
160
  addGptHistoryRoutes(router, options);
161
161
  addGptRoutes(router, {aiService, openApiOptions: options});
162
162
  addAiRequestsExplorerRoutes(router, {openApiOptions: options});
163
163
  },
164
164
  skipListen: true,
165
165
  userModel: UserModel,
166
- });
166
+ }).build();
167
167
  });
168
168
 
169
169
  afterEach(async () => {
@@ -209,13 +209,13 @@ describe("AI Routes", () => {
209
209
  });
210
210
 
211
211
  it("returns demo response when no aiService configured", async () => {
212
- const demoApp = setupServer({
213
- addRoutes: (router, options) => {
212
+ const demoApp = new TerrenoApp({
213
+ configureApp: (router, options) => {
214
214
  addGptRoutes(router, {openApiOptions: options});
215
215
  },
216
216
  skipListen: true,
217
217
  userModel: UserModel,
218
- });
218
+ }).build();
219
219
  const agent = await authAsUser(demoApp, "notAdmin");
220
220
  const res = await agent.post("/gpt/remix").send({text: "Hello"});
221
221
  expect(res.status).toBe(200);
@@ -260,13 +260,13 @@ describe("AI Routes", () => {
260
260
  });
261
261
 
262
262
  it("sends demo response when no ai service configured", async () => {
263
- const demoApp = setupServer({
264
- addRoutes: (router, options) => {
263
+ const demoApp = new TerrenoApp({
264
+ configureApp: (router, options) => {
265
265
  addGptRoutes(router, {openApiOptions: options});
266
266
  },
267
267
  skipListen: true,
268
268
  userModel: UserModel,
269
- });
269
+ }).build();
270
270
  const agent = await authAsUser(demoApp, "notAdmin");
271
271
  const res = await agent
272
272
  .post("/gpt/prompt")
@@ -282,13 +282,13 @@ describe("AI Routes", () => {
282
282
  const createModelFn = mock((_apiKey: string, _modelId?: string) => {
283
283
  return createMockModel() as unknown as LanguageModel;
284
284
  });
285
- const customApp = setupServer({
286
- addRoutes: (router, options) => {
285
+ const customApp = new TerrenoApp({
286
+ configureApp: (router, options) => {
287
287
  addGptRoutes(router, {createModelFn, openApiOptions: options});
288
288
  },
289
289
  skipListen: true,
290
290
  userModel: UserModel,
291
- });
291
+ }).build();
292
292
  const agent = await authAsUser(customApp, "notAdmin");
293
293
  const res = await agent
294
294
  .post("/gpt/prompt")
@@ -304,13 +304,13 @@ describe("AI Routes", () => {
304
304
  const createServerModelFn = mock(
305
305
  (_modelId?: string) => createMockModel() as unknown as LanguageModel
306
306
  );
307
- const customApp = setupServer({
308
- addRoutes: (router, options) => {
307
+ const customApp = new TerrenoApp({
308
+ configureApp: (router, options) => {
309
309
  addGptRoutes(router, {createServerModelFn, openApiOptions: options});
310
310
  },
311
311
  skipListen: true,
312
312
  userModel: UserModel,
313
- });
313
+ }).build();
314
314
  const agent = await authAsUser(customApp, "notAdmin");
315
315
  const res = await agent
316
316
  .post("/gpt/prompt")
@@ -323,13 +323,13 @@ describe("AI Routes", () => {
323
323
 
324
324
  it("falls back to default aiService when createServerModelFn returns null", async () => {
325
325
  const createServerModelFn = mock((_modelId?: string) => null);
326
- const customApp = setupServer({
327
- addRoutes: (router, options) => {
326
+ const customApp = new TerrenoApp({
327
+ configureApp: (router, options) => {
328
328
  addGptRoutes(router, {aiService, createServerModelFn, openApiOptions: options});
329
329
  },
330
330
  skipListen: true,
331
331
  userModel: UserModel,
332
- });
332
+ }).build();
333
333
  const agent = await authAsUser(customApp, "notAdmin");
334
334
  const res = await agent
335
335
  .post("/gpt/prompt")
@@ -432,13 +432,13 @@ describe("AI Routes", () => {
432
432
  const imageService = new AIService({
433
433
  model: createImageModel() as unknown as LanguageModel,
434
434
  });
435
- const imgApp = setupServer({
436
- addRoutes: (router, options) => {
435
+ const imgApp = new TerrenoApp({
436
+ configureApp: (router, options) => {
437
437
  addGptRoutes(router, {aiService: imageService, openApiOptions: options});
438
438
  },
439
439
  skipListen: true,
440
440
  userModel: UserModel,
441
- });
441
+ }).build();
442
442
  const agent = await authAsUser(imgApp, "notAdmin");
443
443
  const res = await agent
444
444
  .post("/gpt/prompt")
@@ -454,13 +454,13 @@ describe("AI Routes", () => {
454
454
  const errService = new AIService({
455
455
  model: createErrorModel() as unknown as LanguageModel,
456
456
  });
457
- const errApp = setupServer({
458
- addRoutes: (router, options) => {
457
+ const errApp = new TerrenoApp({
458
+ configureApp: (router, options) => {
459
459
  addGptRoutes(router, {aiService: errService, openApiOptions: options});
460
460
  },
461
461
  skipListen: true,
462
462
  userModel: UserModel,
463
- });
463
+ }).build();
464
464
  const agent = await authAsUser(errApp, "notAdmin");
465
465
  const res = await agent
466
466
  .post("/gpt/prompt")
@@ -478,13 +478,13 @@ describe("AI Routes", () => {
478
478
  throw new Error("mcp unavailable");
479
479
  }),
480
480
  } as unknown as MCPService;
481
- const customApp = setupServer({
482
- addRoutes: (router, options) => {
481
+ const customApp = new TerrenoApp({
482
+ configureApp: (router, options) => {
483
483
  addGptRoutes(router, {aiService, mcpService, openApiOptions: options});
484
484
  },
485
485
  skipListen: true,
486
486
  userModel: UserModel,
487
- });
487
+ }).build();
488
488
  const agent = await authAsUser(customApp, "notAdmin");
489
489
  const res = await agent
490
490
  .post("/gpt/prompt")
@@ -501,13 +501,13 @@ describe("AI Routes", () => {
501
501
  search: {description: "web search"},
502
502
  })),
503
503
  } as unknown as MCPService;
504
- const customApp = setupServer({
505
- addRoutes: (router, options) => {
504
+ const customApp = new TerrenoApp({
505
+ configureApp: (router, options) => {
506
506
  addGptRoutes(router, {aiService, mcpService, openApiOptions: options});
507
507
  },
508
508
  skipListen: true,
509
509
  userModel: UserModel,
510
- });
510
+ }).build();
511
511
  const agent = await authAsUser(customApp, "notAdmin");
512
512
  const res = await agent
513
513
  .post("/gpt/prompt")
@@ -527,8 +527,8 @@ describe("AI Routes", () => {
527
527
  }
528
528
  return mainFn();
529
529
  });
530
- const customApp = setupServer({
531
- addRoutes: (router, options) => {
530
+ const customApp = new TerrenoApp({
531
+ configureApp: (router, options) => {
532
532
  addGptRoutes(router, {
533
533
  createServerModelFn,
534
534
  openApiOptions: options,
@@ -537,7 +537,7 @@ describe("AI Routes", () => {
537
537
  },
538
538
  skipListen: true,
539
539
  userModel: UserModel,
540
- });
540
+ }).build();
541
541
  const agent = await authAsUser(customApp, "notAdmin");
542
542
  const res = await agent
543
543
  .post("/gpt/prompt")
@@ -552,8 +552,8 @@ describe("AI Routes", () => {
552
552
  const createModelFn = mock((_apiKey: string, _modelId?: string) => {
553
553
  return createMockModel() as unknown as LanguageModel;
554
554
  });
555
- const customApp = setupServer({
556
- addRoutes: (router, options) => {
555
+ const customApp = new TerrenoApp({
556
+ configureApp: (router, options) => {
557
557
  addGptRoutes(router, {
558
558
  createModelFn,
559
559
  openApiOptions: options,
@@ -562,7 +562,7 @@ describe("AI Routes", () => {
562
562
  },
563
563
  skipListen: true,
564
564
  userModel: UserModel,
565
- });
565
+ }).build();
566
566
  const agent = await authAsUser(customApp, "notAdmin");
567
567
  const res = await agent
568
568
  .post("/gpt/prompt")
@@ -583,8 +583,8 @@ describe("AI Routes", () => {
583
583
  const imageService = new AIService({
584
584
  model: createImageModel() as unknown as LanguageModel,
585
585
  });
586
- const imgApp = setupServer({
587
- addRoutes: (router, options) => {
586
+ const imgApp = new TerrenoApp({
587
+ configureApp: (router, options) => {
588
588
  addGptRoutes(router, {
589
589
  aiService: imageService,
590
590
  openApiOptions: options,
@@ -595,7 +595,7 @@ describe("AI Routes", () => {
595
595
  },
596
596
  skipListen: true,
597
597
  userModel: UserModel,
598
- });
598
+ }).build();
599
599
  const agent = await authAsUser(imgApp, "notAdmin");
600
600
  const res = await agent
601
601
  .post("/gpt/prompt")
@@ -606,8 +606,8 @@ describe("AI Routes", () => {
606
606
  });
607
607
 
608
608
  it("uses the langfuse system prompt when configured", async () => {
609
- const customApp = setupServer({
610
- addRoutes: (router, options) => {
609
+ const customApp = new TerrenoApp({
610
+ configureApp: (router, options) => {
611
611
  addGptRoutes(router, {
612
612
  aiService,
613
613
  langfuseSystemPromptName: "missing-prompt-name",
@@ -616,7 +616,7 @@ describe("AI Routes", () => {
616
616
  },
617
617
  skipListen: true,
618
618
  userModel: UserModel,
619
- });
619
+ }).build();
620
620
  const agent = await authAsUser(customApp, "notAdmin");
621
621
  const res = await agent
622
622
  .post("/gpt/prompt")
@@ -676,8 +676,8 @@ describe("AI Routes", () => {
676
676
  specificationVersion: "v2" as const,
677
677
  supportedUrls: {},
678
678
  };
679
- const toolApp = setupServer({
680
- addRoutes: (router, options) => {
679
+ const toolApp = new TerrenoApp({
680
+ configureApp: (router, options) => {
681
681
  addGptRoutes(router, {
682
682
  aiService: new AIService({model: toolModel as unknown as LanguageModel}),
683
683
  openApiOptions: options,
@@ -688,7 +688,7 @@ describe("AI Routes", () => {
688
688
  },
689
689
  skipListen: true,
690
690
  userModel: UserModel,
691
- });
691
+ }).build();
692
692
  const agent = await authAsUser(toolApp, "notAdmin");
693
693
  const res = await agent
694
694
  .post("/gpt/prompt")
@@ -761,8 +761,8 @@ describe("AI Routes", () => {
761
761
  }),
762
762
  inputSchema: jsonSchema({properties: {}, type: "object"}),
763
763
  });
764
- const fileToolApp = setupServer({
765
- addRoutes: (router, options) => {
764
+ const fileToolApp = new TerrenoApp({
765
+ configureApp: (router, options) => {
766
766
  addGptRoutes(router, {
767
767
  aiService: new AIService({model: fileToolModel as unknown as LanguageModel}),
768
768
  openApiOptions: options,
@@ -771,7 +771,7 @@ describe("AI Routes", () => {
771
771
  },
772
772
  skipListen: true,
773
773
  userModel: UserModel,
774
- });
774
+ }).build();
775
775
  const agent = await authAsUser(fileToolApp, "notAdmin");
776
776
  const res = await agent
777
777
  .post("/gpt/prompt")
@@ -816,8 +816,8 @@ describe("AI Routes", () => {
816
816
  specificationVersion: "v2" as const,
817
817
  supportedUrls: {},
818
818
  };
819
- const errApp = setupServer({
820
- addRoutes: (router, options) => {
819
+ const errApp = new TerrenoApp({
820
+ configureApp: (router, options) => {
821
821
  addGptRoutes(router, {
822
822
  aiService: new AIService({
823
823
  model: errEventModel as unknown as LanguageModel,
@@ -827,7 +827,7 @@ describe("AI Routes", () => {
827
827
  },
828
828
  skipListen: true,
829
829
  userModel: UserModel,
830
- });
830
+ }).build();
831
831
  const agent = await authAsUser(errApp, "notAdmin");
832
832
  const res = await agent
833
833
  .post("/gpt/prompt")
@@ -870,8 +870,8 @@ describe("AI Routes", () => {
870
870
  }
871
871
  return createMockModel() as unknown as LanguageModel;
872
872
  });
873
- const customApp = setupServer({
874
- addRoutes: (router, options) => {
873
+ const customApp = new TerrenoApp({
874
+ configureApp: (router, options) => {
875
875
  addGptRoutes(router, {
876
876
  createServerModelFn,
877
877
  openApiOptions: options,
@@ -880,7 +880,7 @@ describe("AI Routes", () => {
880
880
  },
881
881
  skipListen: true,
882
882
  userModel: UserModel,
883
- });
883
+ }).build();
884
884
  const agent = await authAsUser(customApp, "notAdmin");
885
885
  const res = await agent
886
886
  .post("/gpt/prompt")
@@ -943,8 +943,8 @@ describe("AI Routes", () => {
943
943
  specificationVersion: "v2" as const,
944
944
  supportedUrls: {},
945
945
  };
946
- const customApp = setupServer({
947
- addRoutes: (router, options) => {
946
+ const customApp = new TerrenoApp({
947
+ configureApp: (router, options) => {
948
948
  addGptRoutes(router, {
949
949
  aiService: new AIService({model: noStepModel as unknown as LanguageModel}),
950
950
  openApiOptions: options,
@@ -952,7 +952,7 @@ describe("AI Routes", () => {
952
952
  },
953
953
  skipListen: true,
954
954
  userModel: UserModel,
955
- });
955
+ }).build();
956
956
  const agent = await authAsUser(customApp, "notAdmin");
957
957
  const res = await agent
958
958
  .post("/gpt/prompt")
@@ -968,8 +968,8 @@ describe("AI Routes", () => {
968
968
  const createRequestTools = mock(() => ({
969
969
  localLookup: {description: "Per-request tool"} as unknown as Tool,
970
970
  }));
971
- const customApp = setupServer({
972
- addRoutes: (router, options) => {
971
+ const customApp = new TerrenoApp({
972
+ configureApp: (router, options) => {
973
973
  addGptRoutes(router, {
974
974
  aiService,
975
975
  createRequestTools,
@@ -978,7 +978,7 @@ describe("AI Routes", () => {
978
978
  },
979
979
  skipListen: true,
980
980
  userModel: UserModel,
981
- });
981
+ }).build();
982
982
  const agent = await authAsUser(customApp, "notAdmin");
983
983
  const res = await agent
984
984
  .post("/gpt/prompt")
@@ -1021,8 +1021,8 @@ describe("AI Routes", () => {
1021
1021
  specificationVersion: "v2" as const,
1022
1022
  supportedUrls: {},
1023
1023
  };
1024
- const fileApp = setupServer({
1025
- addRoutes: (router, options) => {
1024
+ const fileApp = new TerrenoApp({
1025
+ configureApp: (router, options) => {
1026
1026
  addGptRoutes(router, {
1027
1027
  aiService: new AIService({model: nonImageFileModel as unknown as LanguageModel}),
1028
1028
  openApiOptions: options,
@@ -1030,7 +1030,7 @@ describe("AI Routes", () => {
1030
1030
  },
1031
1031
  skipListen: true,
1032
1032
  userModel: UserModel,
1033
- });
1033
+ }).build();
1034
1034
  const agent = await authAsUser(fileApp, "notAdmin");
1035
1035
  const res = await agent
1036
1036
  .post("/gpt/prompt")
@@ -1179,8 +1179,8 @@ describe("AI Routes", () => {
1179
1179
  specificationVersion: "v2" as const,
1180
1180
  supportedUrls: {},
1181
1181
  };
1182
- const errApp = setupServer({
1183
- addRoutes: (router, options) => {
1182
+ const errApp = new TerrenoApp({
1183
+ configureApp: (router, options) => {
1184
1184
  addGptRoutes(router, {
1185
1185
  aiService: new AIService({
1186
1186
  model: streamIterationErrorModel as unknown as LanguageModel,
@@ -1190,7 +1190,7 @@ describe("AI Routes", () => {
1190
1190
  },
1191
1191
  skipListen: true,
1192
1192
  userModel: UserModel,
1193
- });
1193
+ }).build();
1194
1194
  const agent = await authAsUser(errApp, "notAdmin");
1195
1195
  const res = await agent
1196
1196
  .post("/gpt/prompt")
@@ -1233,8 +1233,8 @@ describe("AI Routes", () => {
1233
1233
  },
1234
1234
  }));
1235
1235
  try {
1236
- const customApp = setupServer({
1237
- addRoutes: (router, options) => {
1236
+ const customApp = new TerrenoApp({
1237
+ configureApp: (router, options) => {
1238
1238
  addGptRoutes(router, {
1239
1239
  aiService,
1240
1240
  langfuseSystemPromptName: "broken-prompt",
@@ -1243,7 +1243,7 @@ describe("AI Routes", () => {
1243
1243
  },
1244
1244
  skipListen: true,
1245
1245
  userModel: UserModel,
1246
- });
1246
+ }).build();
1247
1247
  const agent = await authAsUser(customApp, "notAdmin");
1248
1248
  const res = await agent
1249
1249
  .post("/gpt/prompt")
@@ -1296,8 +1296,8 @@ describe("AI Routes", () => {
1296
1296
  specificationVersion: "v2" as const,
1297
1297
  supportedUrls: {},
1298
1298
  };
1299
- const errApp = setupServer({
1300
- addRoutes: (router, options) => {
1299
+ const errApp = new TerrenoApp({
1300
+ configureApp: (router, options) => {
1301
1301
  addGptRoutes(router, {
1302
1302
  aiService: new AIService({
1303
1303
  model: streamIterationErrorModel as unknown as LanguageModel,
@@ -1307,7 +1307,7 @@ describe("AI Routes", () => {
1307
1307
  },
1308
1308
  skipListen: true,
1309
1309
  userModel: UserModel,
1310
- });
1310
+ }).build();
1311
1311
  const originalLogRequest = AIRequest.logRequest;
1312
1312
  AIRequest.logRequest = mock(async () => {
1313
1313
  throw new Error("log write failed");
@@ -1331,8 +1331,8 @@ describe("AI Routes", () => {
1331
1331
 
1332
1332
  describe("GPT tools route", () => {
1333
1333
  it("lists built-in tools from route config", async () => {
1334
- const customApp = setupServer({
1335
- addRoutes: (router, options) => {
1334
+ const customApp = new TerrenoApp({
1335
+ configureApp: (router, options) => {
1336
1336
  addGptRoutes(router, {
1337
1337
  aiService,
1338
1338
  openApiOptions: options,
@@ -1341,7 +1341,7 @@ describe("AI Routes", () => {
1341
1341
  },
1342
1342
  skipListen: true,
1343
1343
  userModel: UserModel,
1344
- });
1344
+ }).build();
1345
1345
  const agent = await authAsUser(customApp, "notAdmin");
1346
1346
  const res = await agent.get("/gpt/tools");
1347
1347
  expect(res.status).toBe(200);
@@ -1352,13 +1352,13 @@ describe("AI Routes", () => {
1352
1352
  const createRequestTools = mock(() => ({
1353
1353
  now: {description: "Current time"} as unknown as Tool,
1354
1354
  }));
1355
- const customApp = setupServer({
1356
- addRoutes: (router, options) => {
1355
+ const customApp = new TerrenoApp({
1356
+ configureApp: (router, options) => {
1357
1357
  addGptRoutes(router, {aiService, createRequestTools, openApiOptions: options});
1358
1358
  },
1359
1359
  skipListen: true,
1360
1360
  userModel: UserModel,
1361
- });
1361
+ }).build();
1362
1362
  const agent = await authAsUser(customApp, "notAdmin");
1363
1363
  const res = await agent.get("/gpt/tools");
1364
1364
  expect(res.status).toBe(200);
@@ -1369,13 +1369,13 @@ describe("AI Routes", () => {
1369
1369
  const mcpService = {
1370
1370
  getTools: mock(async () => ({search: {description: "web search"}})),
1371
1371
  } as unknown as MCPService;
1372
- const customApp = setupServer({
1373
- addRoutes: (router, options) => {
1372
+ const customApp = new TerrenoApp({
1373
+ configureApp: (router, options) => {
1374
1374
  addGptRoutes(router, {aiService, mcpService, openApiOptions: options});
1375
1375
  },
1376
1376
  skipListen: true,
1377
1377
  userModel: UserModel,
1378
- });
1378
+ }).build();
1379
1379
  const agent = await authAsUser(customApp, "notAdmin");
1380
1380
  const res = await agent.get("/gpt/tools");
1381
1381
  expect(res.status).toBe(200);
@@ -1388,13 +1388,13 @@ describe("AI Routes", () => {
1388
1388
  throw new Error("boom");
1389
1389
  }),
1390
1390
  } as unknown as MCPService;
1391
- const customApp = setupServer({
1392
- addRoutes: (router, options) => {
1391
+ const customApp = new TerrenoApp({
1392
+ configureApp: (router, options) => {
1393
1393
  addGptRoutes(router, {aiService, mcpService, openApiOptions: options});
1394
1394
  },
1395
1395
  skipListen: true,
1396
1396
  userModel: UserModel,
1397
- });
1397
+ }).build();
1398
1398
  const agent = await authAsUser(customApp, "notAdmin");
1399
1399
  const res = await agent.get("/gpt/tools");
1400
1400
  expect(res.status).toBe(200);
@@ -1567,8 +1567,8 @@ describe("AI Routes", () => {
1567
1567
  specificationVersion: "v2" as const,
1568
1568
  supportedUrls: {},
1569
1569
  };
1570
- const fileApp = setupServer({
1571
- addRoutes: (router, options) => {
1570
+ const fileApp = new TerrenoApp({
1571
+ configureApp: (router, options) => {
1572
1572
  addGptRoutes(router, {
1573
1573
  aiService: new AIService({model: nonImageFileModel as unknown as LanguageModel}),
1574
1574
  openApiOptions: options,
@@ -1576,7 +1576,7 @@ describe("AI Routes", () => {
1576
1576
  },
1577
1577
  skipListen: true,
1578
1578
  userModel: UserModel,
1579
- });
1579
+ }).build();
1580
1580
  const agent = await authAsUser(fileApp, "notAdmin");
1581
1581
  const res = await agent
1582
1582
  .post("/gpt/prompt")
@@ -92,5 +92,65 @@ describe("gemini model listing helpers", () => {
92
92
  const result = await listGeminiApiModels({apiKey: "key", fetchImpl});
93
93
  expect(result).toBeUndefined();
94
94
  });
95
+
96
+ it("returns undefined when fetchImpl is not available", async () => {
97
+ // Pass a falsy non-nullish value so the `??` operator keeps it (instead of
98
+ // falling through to globalThis.fetch), and `!fetchImpl` evaluates to true.
99
+ const result = await listGeminiApiModels({
100
+ apiKey: "key",
101
+ fetchImpl: 0 as unknown as typeof fetch,
102
+ });
103
+ expect(result).toBeUndefined();
104
+ });
105
+
106
+ it("returns a partial list when pagination exceeds the maximum page limit", async () => {
107
+ let callCount = 0;
108
+ const fetchImpl = mock(async () => {
109
+ callCount += 1;
110
+ return jsonResponse({
111
+ models: [
112
+ {
113
+ name: `models/gemini-page-${callCount}`,
114
+ supportedGenerationMethods: ["generateContent"],
115
+ },
116
+ ],
117
+ nextPageToken: `page-${callCount + 1}`,
118
+ });
119
+ }) as unknown as typeof fetch;
120
+
121
+ const result = await listGeminiApiModels({apiKey: "key", fetchImpl});
122
+ expect(result).toBeDefined();
123
+ expect(result?.length).toBe(10);
124
+ expect(callCount).toBe(10);
125
+ });
126
+
127
+ it("skips models with missing name", async () => {
128
+ const fetchImpl = mock(async () =>
129
+ jsonResponse({
130
+ models: [
131
+ {name: "models/gemini-valid", supportedGenerationMethods: ["generateContent"]},
132
+ {supportedGenerationMethods: ["generateContent"]},
133
+ {name: undefined, supportedGenerationMethods: ["generateContent"]},
134
+ ],
135
+ })
136
+ ) as unknown as typeof fetch;
137
+
138
+ const result = await listGeminiApiModels({apiKey: "key", fetchImpl});
139
+ expect(result).toEqual(["gemini-valid"]);
140
+ });
141
+
142
+ it("skips models with no supportedGenerationMethods when chatOnly is true", async () => {
143
+ const fetchImpl = mock(async () =>
144
+ jsonResponse({
145
+ models: [
146
+ {name: "models/gemini-chat", supportedGenerationMethods: ["generateContent"]},
147
+ {name: "models/gemini-no-methods"},
148
+ ],
149
+ })
150
+ ) as unknown as typeof fetch;
151
+
152
+ const result = await listGeminiApiModels({apiKey: "key", chatOnly: true, fetchImpl});
153
+ expect(result).toEqual(["gemini-chat"]);
154
+ });
95
155
  });
96
156
  });
@@ -63,6 +63,159 @@ describe("parseAiJson", () => {
63
63
  expect(r.raw).toBe("not json at all");
64
64
  }
65
65
  });
66
+
67
+ it("returns failure for empty string", () => {
68
+ const r = parseAiJson("");
69
+ expect(r.success).toBe(false);
70
+ if (!r.success) {
71
+ expect(r.error).toBe("Empty or non-string input");
72
+ }
73
+ });
74
+
75
+ it("returns failure for whitespace-only string", () => {
76
+ const r = parseAiJson(" ");
77
+ expect(r.success).toBe(false);
78
+ if (!r.success) {
79
+ expect(r.error).toBe("Empty or non-string input");
80
+ }
81
+ });
82
+
83
+ it("handles escaped characters inside JSON strings during balanced extraction", () => {
84
+ const r = parseAiJson(`preamble {"msg":"line1\\nline2","path":"C:\\\\dir"} tail`);
85
+ expect(r.success).toBe(true);
86
+ if (r.success) {
87
+ expect(r.data).toEqual({msg: "line1\nline2", path: "C:\\dir"});
88
+ }
89
+ });
90
+
91
+ it("handles escaped quotes inside JSON strings during balanced extraction", () => {
92
+ const r = parseAiJson(`noise {"key":"value with \\"quotes\\""} done`);
93
+ expect(r.success).toBe(true);
94
+ if (r.success) {
95
+ expect(r.data).toEqual({key: 'value with "quotes"'});
96
+ }
97
+ });
98
+
99
+ it("returns failure for mismatched brackets", () => {
100
+ const r = parseAiJson("{]");
101
+ expect(r.success).toBe(false);
102
+ });
103
+
104
+ it("returns failure for unclosed JSON (unbalanced brackets)", () => {
105
+ const r = parseAiJson(`{"a": {"b": 1}`);
106
+ expect(r.success).toBe(false);
107
+ });
108
+
109
+ it("repairs trailing comma inside a balanced extraction that otherwise fails parse", () => {
110
+ const r = parseAiJson(`Sure! {"items": [1, 2, 3,],} enjoy!`);
111
+ expect(r.success).toBe(true);
112
+ if (r.success) {
113
+ expect(r.repaired).toBe(true);
114
+ expect(r.data).toEqual({items: [1, 2, 3]});
115
+ }
116
+ });
117
+
118
+ it("repairs trailing commas inside balanced extraction with backslash content", () => {
119
+ const input = `here {"a": "x\\\\y", "b": 1,}`;
120
+ const r = parseAiJson(input);
121
+ expect(r.success).toBe(true);
122
+ if (r.success) {
123
+ expect(r.repaired).toBe(true);
124
+ expect(r.data).toEqual({a: "x\\y", b: 1});
125
+ }
126
+ });
127
+
128
+ it("repairs smart quotes via whole-string repair when balanced extraction fails", () => {
129
+ const r = parseAiJson(`\u201Ckey\u201D: \u201Cvalue\u201D`);
130
+ expect(r.success).toBe(false);
131
+ });
132
+
133
+ it("repairs smart quotes on a full JSON object", () => {
134
+ const r = parseAiJson(`{\u201Ckey\u201D: \u201Cvalue\u201D}`);
135
+ expect(r.success).toBe(true);
136
+ if (r.success) {
137
+ expect(r.repaired).toBe(true);
138
+ expect(r.data).toEqual({key: "value"});
139
+ }
140
+ });
141
+
142
+ it("repairs escaped characters in repair path outside strings", () => {
143
+ const r = parseAiJson(`{"escaped": "a\\b", "trailing": true,}`);
144
+ expect(r.success).toBe(true);
145
+ if (r.success) {
146
+ expect(r.repaired).toBe(true);
147
+ }
148
+ });
149
+
150
+ it("strips partial opening fence and trailing fence", () => {
151
+ const r = parseAiJson('```json\n{"x": 1}\n```');
152
+ expect(r.success).toBe(true);
153
+ if (r.success) {
154
+ expect(r.data).toEqual({x: 1});
155
+ }
156
+ });
157
+
158
+ it("strips partial opening fence without full closure", () => {
159
+ const r = parseAiJson('```json\n{"a":1}');
160
+ expect(r.success).toBe(true);
161
+ if (r.success) {
162
+ expect(r.data).toEqual({a: 1});
163
+ }
164
+ });
165
+
166
+ it("strips opening fence with colon separator", () => {
167
+ const r = parseAiJson('```json:\n{"y": 2}\n```');
168
+ expect(r.success).toBe(true);
169
+ if (r.success) {
170
+ expect(r.data).toEqual({y: 2});
171
+ }
172
+ });
173
+
174
+ it("parses arrays at top level", () => {
175
+ const r = parseAiJson("[1, 2, 3]");
176
+ expect(r.success).toBe(true);
177
+ if (r.success) {
178
+ expect(r.data).toEqual([1, 2, 3]);
179
+ expect(r.repaired).toBe(false);
180
+ }
181
+ });
182
+
183
+ it("extracts a JSON array from prose", () => {
184
+ const r = parseAiJson("Here are the items: [1, 2, 3] — done.");
185
+ expect(r.success).toBe(true);
186
+ if (r.success) {
187
+ expect(r.data).toEqual([1, 2, 3]);
188
+ expect(r.repaired).toBe(true);
189
+ }
190
+ });
191
+
192
+ it("returns failure when no brackets are present at all", () => {
193
+ const r = parseAiJson("just plain text with no JSON");
194
+ expect(r.success).toBe(false);
195
+ });
196
+
197
+ it("returns failure for unterminated JSON", () => {
198
+ const r = parseAiJson('{"a": 1');
199
+ expect(r.success).toBe(false);
200
+ });
201
+
202
+ it("repairs smart quotes inside a balanced extraction (repairedSlice path)", () => {
203
+ const r = parseAiJson(`prefix {\u201Ckey\u201D: 1} suffix`);
204
+ expect(r.success).toBe(true);
205
+ if (r.success) {
206
+ expect(r.repaired).toBe(true);
207
+ expect(r.data).toEqual({key: 1});
208
+ }
209
+ });
210
+
211
+ it("repairs whole cleaned text when balanced extraction is not possible", () => {
212
+ const r = parseAiJson(`\u201Chello\u201D`);
213
+ expect(r.success).toBe(true);
214
+ if (r.success) {
215
+ expect(r.repaired).toBe(true);
216
+ expect(r.data).toBe("hello");
217
+ }
218
+ });
66
219
  });
67
220
 
68
221
  describe("normalizeLlmJsonTextForStructuredOutput", () => {
@@ -325,5 +325,118 @@ describe("vertex helpers", () => {
325
325
  });
326
326
  expect(models).toBeUndefined();
327
327
  });
328
+ it("skips models without a name in the response", async () => {
329
+ const fetchImpl = mock(async () => ({
330
+ json: async () => ({
331
+ publisherModels: [
332
+ {name: "publishers/google/models/gemini-2.5-flash"},
333
+ {},
334
+ {name: undefined},
335
+ {name: "publishers/google/models/gemini-2.5-pro"},
336
+ ],
337
+ }),
338
+ ok: true,
339
+ status: 200,
340
+ })) as unknown as typeof fetch;
341
+ const models = await listEnabledVertexModels({
342
+ fetchImpl,
343
+ getAccessToken: async () => "fake-token",
344
+ project: "demo-project",
345
+ });
346
+ expect(models).toEqual(["gemini-2.5-flash", "gemini-2.5-pro"]);
347
+ });
348
+
349
+ it("uses global location when GOOGLE_VERTEX_LOCATION env is set", async () => {
350
+ process.env.GOOGLE_VERTEX_LOCATION = "europe-west4";
351
+ const fetchImpl = mock(async (input: string | URL) => {
352
+ const url = input.toString();
353
+ expect(url).toContain("europe-west4-aiplatform.googleapis.com");
354
+ return {
355
+ json: async () => ({
356
+ publisherModels: [{name: "publishers/google/models/gemini-2.5-flash"}],
357
+ }),
358
+ ok: true,
359
+ status: 200,
360
+ } as unknown as Response;
361
+ });
362
+ const models = await listEnabledVertexModels({
363
+ fetchImpl: fetchImpl as unknown as typeof fetch,
364
+ getAccessToken: async () => "fake-token",
365
+ project: "demo-project",
366
+ });
367
+ expect(models).toEqual(["gemini-2.5-flash"]);
368
+ });
369
+ });
370
+
371
+ describe("createVertexProvider", () => {
372
+ it("returns undefined and logs a warning when factory is not available and module is not installed", () => {
373
+ const provider = createVertexProvider({
374
+ project: "demo-project",
375
+ vertexFactory: undefined,
376
+ });
377
+ // loadVertexModule returns undefined because @ai-sdk/google-vertex is not installed in test env
378
+ expect(provider).toBeUndefined();
379
+ });
380
+
381
+ it("uses GOOGLE_VERTEX_LOCATION env for location resolution", () => {
382
+ process.env.GOOGLE_VERTEX_LOCATION = "asia-east1";
383
+ const provider = createVertexProvider({
384
+ project: "demo-project",
385
+ vertexFactory: makeVertexFactory(),
386
+ });
387
+ expect(provider?.location).toBe("asia-east1");
388
+ });
389
+
390
+ it("uses GOOGLE_VERTEX_PROJECT env when project option is omitted", () => {
391
+ process.env.GOOGLE_VERTEX_PROJECT = "env-project";
392
+ const provider = createVertexProvider({
393
+ vertexFactory: makeVertexFactory(),
394
+ });
395
+ expect(provider).toBeDefined();
396
+ expect(provider?.project).toBe("env-project");
397
+ });
398
+
399
+ it("exposes the raw provider", () => {
400
+ const provider = createVertexProvider({
401
+ project: "demo-project",
402
+ vertexFactory: makeVertexFactory(),
403
+ });
404
+ expect(provider?.raw).toBeDefined();
405
+ });
406
+
407
+ it("resolves image models through the allow-list", () => {
408
+ const provider = createVertexProvider({
409
+ project: "demo-project",
410
+ vertexFactory: makeVertexFactory(),
411
+ });
412
+ const img = provider?.imageModel("imagen-4.0-fast-generate-001");
413
+ expect(img).toBeDefined();
414
+ });
415
+ });
416
+
417
+ describe("verifyVertexModelsEnabled", () => {
418
+ it("deduplicates requested models before checking", async () => {
419
+ const result = await verifyVertexModelsEnabled({
420
+ listModelsFn: mock(async () => ["gemini-2.5-flash"]),
421
+ models: ["gemini-2.5-flash", "gemini-2.5-flash@001"],
422
+ project: "demo-project",
423
+ });
424
+ expect(result.checked).toBe(true);
425
+ expect(result.available).toEqual(["gemini-2.5-flash"]);
426
+ expect(result.unavailable).toEqual([]);
427
+ });
428
+ });
429
+
430
+ describe("assertVertexModelsEnabled", () => {
431
+ it("returns the result when all models are available", async () => {
432
+ const result = await assertVertexModelsEnabled({
433
+ listModelsFn: mock(async () => ["gemini-2.5-flash", "gemini-2.5-pro"]),
434
+ models: ["gemini-2.5-flash"],
435
+ project: "demo-project",
436
+ });
437
+ expect(result.checked).toBe(true);
438
+ expect(result.available).toEqual(["gemini-2.5-flash"]);
439
+ expect(result.unavailable).toEqual([]);
440
+ });
328
441
  });
329
442
  });