@terreno/ai 0.23.1 → 0.24.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/package.json +4 -4
- package/src/routes/routes.test.ts +46 -0
package/package.json
CHANGED
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"description": "AI service layer for Terreno apps - GPT chat, request logging, and admin tools.",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@biomejs/biome": "^2.3.6",
|
|
21
|
-
"@terreno/test": "0.
|
|
21
|
+
"@terreno/test": "0.24.0",
|
|
22
22
|
"@types/bun": "^1.3.8",
|
|
23
23
|
"@types/express": "^5.0.6",
|
|
24
24
|
"@types/luxon": "^3.7.1",
|
|
25
25
|
"@types/multer": "^1.4.12",
|
|
26
26
|
"@types/passport-local-mongoose": "^6.1.5",
|
|
27
27
|
"@types/supertest": "^7.2.0",
|
|
28
|
-
"@terreno/api": "0.
|
|
28
|
+
"@terreno/api": "0.24.0",
|
|
29
29
|
"mongoose": "8.23.0",
|
|
30
30
|
"passport-local-mongoose": "^9.0.1",
|
|
31
31
|
"supertest": "^7.2.2",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"@terreno/api": "0.
|
|
75
|
+
"@terreno/api": "0.24.0",
|
|
76
76
|
"mongoose": "^8.0.0"
|
|
77
77
|
},
|
|
78
78
|
"repository": {
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"test:coverage": "bun run ../scripts/check-coverage.ts"
|
|
92
92
|
},
|
|
93
93
|
"types": "dist/index.d.ts",
|
|
94
|
-
"version": "0.
|
|
94
|
+
"version": "0.24.0"
|
|
95
95
|
}
|
|
@@ -89,6 +89,30 @@ const createImageModel = () => ({
|
|
|
89
89
|
supportedUrls: {},
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
+
// Mock model that emits text without a finish event (no finish-step → post-loop flush)
|
|
93
|
+
const createNoFinishModel = () => ({
|
|
94
|
+
doGenerate: mock(async () => ({
|
|
95
|
+
content: [{text: "unflushed", type: "text" as const}],
|
|
96
|
+
finishReason: "stop" as const,
|
|
97
|
+
usage: {inputTokens: 1, outputTokens: 1},
|
|
98
|
+
})),
|
|
99
|
+
doStream: mock(async () => ({
|
|
100
|
+
stream: new ReadableStream({
|
|
101
|
+
start(controller) {
|
|
102
|
+
controller.enqueue({id: "t1", type: "text-start" as const});
|
|
103
|
+
controller.enqueue({delta: "buffered text", id: "t1", type: "text-delta" as const});
|
|
104
|
+
controller.enqueue({id: "t1", type: "text-end" as const});
|
|
105
|
+
// Deliberately omit finish event so the SDK does not emit finish-step
|
|
106
|
+
controller.close();
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
})),
|
|
110
|
+
modelId: "no-finish-model",
|
|
111
|
+
provider: "mock-provider",
|
|
112
|
+
specificationVersion: "v2" as const,
|
|
113
|
+
supportedUrls: {},
|
|
114
|
+
});
|
|
115
|
+
|
|
92
116
|
// Mock model that throws during doStream to exercise the inner catch
|
|
93
117
|
const createErrorModel = () => ({
|
|
94
118
|
doGenerate: mock(async () => ({
|
|
@@ -392,6 +416,28 @@ describe("AI Routes", () => {
|
|
|
392
416
|
expect(res.status).toBe(200);
|
|
393
417
|
});
|
|
394
418
|
|
|
419
|
+
it("flushes remaining buffered text when the stream ends without finish-step", async () => {
|
|
420
|
+
const noFinishService = new AIService({
|
|
421
|
+
model: createNoFinishModel() as unknown as LanguageModel,
|
|
422
|
+
});
|
|
423
|
+
const noFinishApp = new TerrenoApp({
|
|
424
|
+
configureApp: (router, options) => {
|
|
425
|
+
addGptRoutes(router, {aiService: noFinishService, openApiOptions: options});
|
|
426
|
+
},
|
|
427
|
+
skipListen: true,
|
|
428
|
+
userModel: UserModel,
|
|
429
|
+
}).build();
|
|
430
|
+
const agent = await authAsUser(noFinishApp, "notAdmin");
|
|
431
|
+
const res = await agent
|
|
432
|
+
.post("/gpt/prompt")
|
|
433
|
+
.send({prompt: "Hi"})
|
|
434
|
+
.buffer(true)
|
|
435
|
+
.parse(sseCollect);
|
|
436
|
+
expect(res.status).toBe(200);
|
|
437
|
+
const body = (res as SseResponse).body;
|
|
438
|
+
expect(body).toContain("buffered text");
|
|
439
|
+
});
|
|
440
|
+
|
|
395
441
|
it("streams inline image events from the model", async () => {
|
|
396
442
|
const imageService = new AIService({
|
|
397
443
|
model: createImageModel() as unknown as LanguageModel,
|