@terreno/ai 0.31.0 → 56.0.0-beta.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/README.md +2 -44
- package/dist/service/vertex.d.ts +12 -0
- package/dist/service/vertex.js +3 -2
- package/package.json +9 -8
- package/src/service/vertex.test.ts +3 -3
- package/src/service/vertex.ts +7 -1
- package/tsconfig.json +4 -2
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,47 +1,5 @@
|
|
|
1
1
|
# @terreno/ai
|
|
2
2
|
|
|
3
|
-
AI service layer for Terreno
|
|
3
|
+
AI service layer for Terreno apps providing GPT chat, request logging, and admin tools. Provider-agnostic via the Vercel AI SDK.
|
|
4
4
|
|
|
5
|
-
|
|
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.
|
|
5
|
+
See the [full documentation](../.claude/rules/ai/00-ai.md) for usage, architecture, and integration details.
|
package/dist/service/vertex.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ export interface VertexLanguageModelProvider {
|
|
|
19
19
|
(modelId: string): LanguageModel;
|
|
20
20
|
image: (modelId: string) => ImageModel;
|
|
21
21
|
}
|
|
22
|
+
interface VertexModule {
|
|
23
|
+
createVertex: (opts: {
|
|
24
|
+
location: string;
|
|
25
|
+
project: string;
|
|
26
|
+
}) => VertexLanguageModelProvider;
|
|
27
|
+
}
|
|
22
28
|
export interface CreateVertexProviderOptions {
|
|
23
29
|
/**
|
|
24
30
|
* Optional allow-list of model ids consumers may use. When omitted or empty (the default), ALL
|
|
@@ -29,6 +35,11 @@ export interface CreateVertexProviderOptions {
|
|
|
29
35
|
location?: string;
|
|
30
36
|
/** GCP project id. Falls back to the GOOGLE_VERTEX_PROJECT env var. */
|
|
31
37
|
project?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Injectable loader for the `@ai-sdk/google-vertex` module, primarily for testing the
|
|
40
|
+
* "module not installed" fallback deterministically. Defaults to a `require`-based loader.
|
|
41
|
+
*/
|
|
42
|
+
loadModule?: () => VertexModule | undefined;
|
|
32
43
|
/**
|
|
33
44
|
* Injectable factory for the `@ai-sdk/google-vertex` provider, primarily for testing. When
|
|
34
45
|
* omitted, the provider is loaded dynamically from `@ai-sdk/google-vertex`.
|
|
@@ -113,3 +124,4 @@ export declare const verifyVertexModelsEnabled: (options: VerifyVertexModelsOpti
|
|
|
113
124
|
* do not throw so local development and offline environments keep working.
|
|
114
125
|
*/
|
|
115
126
|
export declare const assertVertexModelsEnabled: (options: VerifyVertexModelsOptions) => Promise<VertexModelAvailability>;
|
|
127
|
+
export {};
|
package/dist/service/vertex.js
CHANGED
|
@@ -168,7 +168,7 @@ var aiPlatformHost = function (location) {
|
|
|
168
168
|
* installed, so callers can fall back to another provider or demo mode.
|
|
169
169
|
*/
|
|
170
170
|
var createVertexProvider = function (options) {
|
|
171
|
-
var _a, _b, _c;
|
|
171
|
+
var _a, _b, _c, _d;
|
|
172
172
|
if (options === void 0) { options = {}; }
|
|
173
173
|
var project = (_a = options.project) !== null && _a !== void 0 ? _a : process.env.GOOGLE_VERTEX_PROJECT;
|
|
174
174
|
if (!project) {
|
|
@@ -176,7 +176,8 @@ var createVertexProvider = function (options) {
|
|
|
176
176
|
}
|
|
177
177
|
var location = resolveLocation(options.location);
|
|
178
178
|
var allowedModels = options.allowedModels && options.allowedModels.length > 0 ? options.allowedModels : undefined;
|
|
179
|
-
var
|
|
179
|
+
var loadModule = (_b = options.loadModule) !== null && _b !== void 0 ? _b : loadVertexModule;
|
|
180
|
+
var factory = (_c = options.vertexFactory) !== null && _c !== void 0 ? _c : (_d = loadModule()) === null || _d === void 0 ? void 0 : _d.createVertex;
|
|
180
181
|
if (!factory) {
|
|
181
182
|
api_1.logger.warn("Vertex AI (Gemini Enterprise Agent Platform) provider requested but @ai-sdk/google-vertex is not installed.");
|
|
182
183
|
return undefined;
|
package/package.json
CHANGED
|
@@ -18,17 +18,18 @@
|
|
|
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/
|
|
21
|
+
"@terreno/api": "56.0.0-beta.0",
|
|
22
|
+
"@terreno/test": "56.0.0-beta.0",
|
|
22
23
|
"@types/bun": "^1.3.8",
|
|
23
24
|
"@types/express": "^5.0.6",
|
|
24
25
|
"@types/luxon": "^3.7.1",
|
|
25
26
|
"@types/multer": "^1.4.12",
|
|
27
|
+
"@types/passport-local-mongoose": "^6.1.5",
|
|
26
28
|
"@types/supertest": "^7.2.0",
|
|
27
|
-
"
|
|
28
|
-
"mongoose": "9.7.4",
|
|
29
|
+
"mongoose": "8.23.0",
|
|
29
30
|
"passport-local-mongoose": "^9.0.1",
|
|
30
31
|
"supertest": "^7.2.2",
|
|
31
|
-
"typescript": "~
|
|
32
|
+
"typescript": "~6.0.3",
|
|
32
33
|
"winston": "^3.18.3"
|
|
33
34
|
},
|
|
34
35
|
"exports": {
|
|
@@ -64,15 +65,15 @@
|
|
|
64
65
|
"mongoose",
|
|
65
66
|
"express"
|
|
66
67
|
],
|
|
67
|
-
"license": "
|
|
68
|
+
"license": "Apache-2.0",
|
|
68
69
|
"main": "dist/index.js",
|
|
69
70
|
"name": "@terreno/ai",
|
|
70
71
|
"publishConfig": {
|
|
71
72
|
"access": "public"
|
|
72
73
|
},
|
|
73
74
|
"peerDependencies": {
|
|
74
|
-
"@terreno/api": "0.
|
|
75
|
-
"mongoose": "^8.0.0
|
|
75
|
+
"@terreno/api": "56.0.0-beta.0",
|
|
76
|
+
"mongoose": "^8.0.0"
|
|
76
77
|
},
|
|
77
78
|
"repository": {
|
|
78
79
|
"type": "git",
|
|
@@ -90,5 +91,5 @@
|
|
|
90
91
|
"test:coverage": "bun run ../scripts/check-coverage.ts"
|
|
91
92
|
},
|
|
92
93
|
"types": "dist/index.d.ts",
|
|
93
|
-
"version": "0.
|
|
94
|
+
"version": "56.0.0-beta.0"
|
|
94
95
|
}
|
|
@@ -190,9 +190,9 @@ describe("vertex helpers", () => {
|
|
|
190
190
|
|
|
191
191
|
describe("createVertexProvider without vertexFactory", () => {
|
|
192
192
|
it("returns undefined when @ai-sdk/google-vertex is not installed (no factory)", () => {
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
const provider = createVertexProvider({project: "demo-project"});
|
|
193
|
+
// Inject a loader that simulates the module being unavailable so the fallback is
|
|
194
|
+
// deterministic even when @ai-sdk/google-vertex is hoisted into the monorepo.
|
|
195
|
+
const provider = createVertexProvider({loadModule: () => undefined, project: "demo-project"});
|
|
196
196
|
expect(provider).toBeUndefined();
|
|
197
197
|
});
|
|
198
198
|
});
|
package/src/service/vertex.ts
CHANGED
|
@@ -42,6 +42,11 @@ export interface CreateVertexProviderOptions {
|
|
|
42
42
|
location?: string;
|
|
43
43
|
/** GCP project id. Falls back to the GOOGLE_VERTEX_PROJECT env var. */
|
|
44
44
|
project?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Injectable loader for the `@ai-sdk/google-vertex` module, primarily for testing the
|
|
47
|
+
* "module not installed" fallback deterministically. Defaults to a `require`-based loader.
|
|
48
|
+
*/
|
|
49
|
+
loadModule?: () => VertexModule | undefined;
|
|
45
50
|
/**
|
|
46
51
|
* Injectable factory for the `@ai-sdk/google-vertex` provider, primarily for testing. When
|
|
47
52
|
* omitted, the provider is loaded dynamically from `@ai-sdk/google-vertex`.
|
|
@@ -170,7 +175,8 @@ export const createVertexProvider = (
|
|
|
170
175
|
const allowedModels =
|
|
171
176
|
options.allowedModels && options.allowedModels.length > 0 ? options.allowedModels : undefined;
|
|
172
177
|
|
|
173
|
-
const
|
|
178
|
+
const loadModule = options.loadModule ?? loadVertexModule;
|
|
179
|
+
const factory = options.vertexFactory ?? loadModule()?.createVertex;
|
|
174
180
|
if (!factory) {
|
|
175
181
|
logger.warn(
|
|
176
182
|
"Vertex AI (Gemini Enterprise Agent Platform) provider requested but @ai-sdk/google-vertex is not installed."
|
package/tsconfig.json
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
"downlevelIteration": true,
|
|
8
8
|
"esModuleInterop": true,
|
|
9
9
|
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"ignoreDeprecations": "6.0",
|
|
10
11
|
"jsx": "react",
|
|
11
|
-
"lib": ["
|
|
12
|
+
"lib": ["es2022", "dom"],
|
|
12
13
|
"module": "commonjs",
|
|
13
14
|
"moduleResolution": "node",
|
|
14
15
|
"noEmit": false,
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
"noUnusedLocals": false,
|
|
19
20
|
"noUnusedParameters": false,
|
|
20
21
|
"outDir": "./dist",
|
|
22
|
+
"rootDir": "./src",
|
|
21
23
|
"preserveConstEnums": true,
|
|
22
24
|
"removeComments": false,
|
|
23
25
|
"skipLibCheck": true,
|
|
@@ -34,5 +36,5 @@
|
|
|
34
36
|
"src/**/*.isolated.tsx",
|
|
35
37
|
"src/tests"
|
|
36
38
|
],
|
|
37
|
-
"include": ["src/**/*.ts*", "src/*.ts", "
|
|
39
|
+
"include": ["src/**/*.ts*", "src/*.ts", "src/**/*.d.ts"]
|
|
38
40
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|