@terreno/ai 0.29.0 → 0.31.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Flourish Health, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # @terreno/ai
2
2
 
3
- AI service layer for Terreno apps providing GPT chat, request logging, and admin tools. Provider-agnostic via the Vercel AI SDK.
3
+ AI service layer for Terreno backends — provider-agnostic chat, request logging, GPT history, projects, file uploads, MCP tools, and optional Langfuse integration.
4
4
 
5
- See the [full documentation](../.claude/rules/ai/00-ai.md) for usage, architecture, and integration details.
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add @terreno/ai @terreno/api mongoose
9
+ ```
10
+
11
+ Also install a Vercel AI SDK provider in your app (e.g. `bun add @ai-sdk/google`).
12
+
13
+ ## Quick start
14
+
15
+ ```typescript
16
+ import {TerrenoApp} from "@terreno/api";
17
+ import {AiApp, AIService} from "@terreno/ai";
18
+ import {google} from "@ai-sdk/google";
19
+ import {User} from "./models/user";
20
+
21
+ const aiService = new AIService({model: google("gemini-2.5-flash")});
22
+
23
+ new TerrenoApp({userModel: User})
24
+ .register(new AiApp({aiService}))
25
+ .start();
26
+ ```
27
+
28
+ This mounts GPT chat (`POST /gpt/prompt`), history CRUD (`/gpt/histories`), projects, and the admin AI request explorer. Add `LangfuseApp`, `FileStorageService`, and `MCPService` when you need those features.
29
+
30
+ ## What's included
31
+
32
+ - `AIService` — text, streaming, structured JSON, remix, summary, and translation helpers
33
+ - `AiApp` — TerrenoPlugin that registers all AI routes in one call
34
+ - Mongoose models: `AIRequest`, `GptHistory`, `Project`, `FileAttachment`
35
+ - Route registrars: `addGptRoutes`, `addGptHistoryRoutes`, `addProjectRoutes`, `addFileRoutes`, `addMcpRoutes`, `addAiRequestsExplorerRoutes`
36
+ - `LangfuseApp` — optional Langfuse tracing and admin UI routes
37
+ - `FileStorageService` — GCS uploads with signed URLs
38
+ - `MCPService` — SSE MCP client for tool calling
39
+ - Gemini and Vertex helpers: `listGeminiApiModels`, `createVertexProvider`
40
+
41
+ ## Documentation
42
+
43
+ Full API reference: [docs/reference/ai.md](https://github.com/flourishhealth/terreno/blob/master/docs/reference/ai.md)
44
+
45
+ ## License and Contributing
46
+
47
+ Licensed under the [MIT License](https://github.com/flourishhealth/terreno/blob/master/LICENSE). See [CONTRIBUTING.md](https://github.com/flourishhealth/terreno/blob/master/CONTRIBUTING.md) for contribution guidelines.
package/package.json CHANGED
@@ -18,15 +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.29.0",
21
+ "@terreno/test": "0.31.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
- "@types/passport-local-mongoose": "^6.1.5",
27
26
  "@types/supertest": "^7.2.0",
28
- "@terreno/api": "0.29.0",
29
- "mongoose": "8.23.0",
27
+ "@terreno/api": "0.31.0",
28
+ "mongoose": "9.7.4",
30
29
  "passport-local-mongoose": "^9.0.1",
31
30
  "supertest": "^7.2.2",
32
31
  "typescript": "~5.9.2",
@@ -65,15 +64,15 @@
65
64
  "mongoose",
66
65
  "express"
67
66
  ],
68
- "license": "Apache-2.0",
67
+ "license": "MIT",
69
68
  "main": "dist/index.js",
70
69
  "name": "@terreno/ai",
71
70
  "publishConfig": {
72
71
  "access": "public"
73
72
  },
74
73
  "peerDependencies": {
75
- "@terreno/api": "0.29.0",
76
- "mongoose": "^8.0.0"
74
+ "@terreno/api": "0.31.0",
75
+ "mongoose": "^8.0.0 || ^9.0.0"
77
76
  },
78
77
  "repository": {
79
78
  "type": "git",
@@ -91,5 +90,5 @@
91
90
  "test:coverage": "bun run ../scripts/check-coverage.ts"
92
91
  },
93
92
  "types": "dist/index.d.ts",
94
- "version": "0.29.0"
93
+ "version": "0.31.0"
95
94
  }
@@ -0,0 +1,102 @@
1
+ import {describe, expect, it} from "bun:test";
2
+
3
+ import * as terrenoAi from "./index";
4
+
5
+ const exported: Record<string, unknown> = terrenoAi;
6
+
7
+ /**
8
+ * Guards the public entrypoint of @terreno/ai: a missing or renamed export here is a
9
+ * breaking change for consumers, and the barrel itself is never exercised by the
10
+ * per-module tests.
11
+ */
12
+ describe("@terreno/ai public exports", () => {
13
+ const expectedFunctions = [
14
+ "addAiRequestsExplorerRoutes",
15
+ "addFileRoutes",
16
+ "addGptHistoryRoutes",
17
+ "addGptRoutes",
18
+ "addMcpRoutes",
19
+ "addProjectRoutes",
20
+ "assertVertexModelsEnabled",
21
+ "compilePrompt",
22
+ "createPrompt",
23
+ "createTelemetryConfig",
24
+ "createVertexProvider",
25
+ "getCached",
26
+ "getLangfuseClient",
27
+ "getPrompt",
28
+ "initLangfuseClient",
29
+ "initTracing",
30
+ "invalidateCache",
31
+ "invalidatePromptCache",
32
+ "isLangfuseInitialized",
33
+ "isVertexModelAllowed",
34
+ "jsonSchema",
35
+ "listEnabledVertexModels",
36
+ "listGeminiApiModels",
37
+ "normalizeGeminiModelId",
38
+ "normalizeLlmJsonTextForStructuredOutput",
39
+ "normalizeVertexModelId",
40
+ "parseAiJson",
41
+ "preparePromptForAI",
42
+ "setCached",
43
+ "shutdownLangfuseClient",
44
+ "shutdownTracing",
45
+ "verifyVertexModelsEnabled",
46
+ ] as const;
47
+
48
+ const expectedClasses = [
49
+ "AIRequest",
50
+ "AIService",
51
+ "AiApp",
52
+ "FileAttachment",
53
+ "FileStorageService",
54
+ "GptHistory",
55
+ "LangfuseApp",
56
+ "LangfuseCache",
57
+ "MCPService",
58
+ "Project",
59
+ ] as const;
60
+
61
+ const expectedConstants = [
62
+ "CONTENT_SUMMARY_PROMPT",
63
+ "DEFAULT_GPT_MEMORY",
64
+ "DEFAULT_VERTEX_LOCATION",
65
+ "GEMINI_API_BASE_URL",
66
+ "JSON_VALUE_SYSTEM_PROMPT",
67
+ "Output",
68
+ "REMIX_PROMPT",
69
+ "TITLE_GENERATION_PROMPT",
70
+ "TRANSLATION_PROMPT",
71
+ "TemperaturePresets",
72
+ ] as const;
73
+
74
+ it.each(expectedFunctions)("exports %s as a function", (name) => {
75
+ expect(typeof exported[name]).toBe("function");
76
+ });
77
+
78
+ it.each(expectedClasses)("exports %s as a constructable value", (name) => {
79
+ expect(typeof exported[name]).toBe("function");
80
+ });
81
+
82
+ it.each(expectedConstants)("exports the %s constant", (name) => {
83
+ expect(exported[name]).toBeDefined();
84
+ });
85
+
86
+ it("re-exports the default AI request types", () => {
87
+ expect(terrenoAi.DEFAULT_AI_REQUEST_TYPES).toContain("general");
88
+ expect(terrenoAi.DEFAULT_AI_REQUEST_TYPES).toContain("translation");
89
+
90
+ // The tuple is frozen at the type level via `as const`; keep the runtime list stable
91
+ // because request types are persisted on AIRequest documents.
92
+ expect([...terrenoAi.DEFAULT_AI_REQUEST_TYPES]).toEqual([
93
+ "general",
94
+ "json_array",
95
+ "json_object",
96
+ "json_value",
97
+ "remix",
98
+ "summarization",
99
+ "translation",
100
+ ]);
101
+ });
102
+ });