@terreno/ai 57.7.0 → 57.9.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/.cursorrules CHANGED
@@ -49,7 +49,7 @@ import {AIService} from "@terreno/ai";
49
49
  import {google} from "@ai-sdk/google";
50
50
 
51
51
  const aiService = new AIService({
52
- model: google("gemini-2.5-flash"),
52
+ model: google("gemini-3.8-flash"),
53
53
  defaultTemperature: 1.0, // optional
54
54
  });
55
55
  ```
@@ -165,7 +165,7 @@ Consuming apps wire up routes in their `setupServer` call:
165
165
  import {AIService, addGptRoutes, addGptHistoryRoutes, addAiRequestsExplorerRoutes} from "@terreno/ai";
166
166
  import {google} from "@ai-sdk/google";
167
167
 
168
- const aiService = new AIService({model: google("gemini-2.5-flash")});
168
+ const aiService = new AIService({model: google("gemini-3.8-flash")});
169
169
 
170
170
  setupServer({
171
171
  addRoutes: (router, options) => {
package/README.md CHANGED
@@ -20,7 +20,7 @@ import {AiApp, AIService} from "@terreno/ai";
20
20
  import {google} from "@ai-sdk/google";
21
21
  import {User} from "./models/user";
22
22
 
23
- const aiService = new AIService({model: google("gemini-2.5-flash")});
23
+ const aiService = new AIService({model: google("gemini-3.8-flash")});
24
24
 
25
25
  new TerrenoApp({userModel: User})
26
26
  .register(new AiApp({aiService}))
package/dist/aiApp.d.ts CHANGED
@@ -17,6 +17,11 @@ export interface AiAppOptions {
17
17
  fileStorageService?: FileStorageService;
18
18
  /** GCS bucket name for file uploads. Required alongside fileStorageService. */
19
19
  gcsBucket?: string;
20
+ /**
21
+ * When `false` or the function returns `false`, file uploads and chat attachments are rejected.
22
+ * Omit or pass `true` to leave uploads enabled whenever storage is configured.
23
+ */
24
+ fileUploadsEnabled?: import("./service/fileUploadsGate").FileUploadsEnabled;
20
25
  /** Maximum number of tool-calling steps per chat request. Defaults to 5 when tools are present. */
21
26
  maxSteps?: number;
22
27
  /** MCP service for connecting to external tool servers. */
@@ -25,7 +30,7 @@ export interface AiAppOptions {
25
30
  openApiOptions?: Record<string, unknown>;
26
31
  /** Tool choice strategy for chat requests. Defaults to "auto" when tools are present. */
27
32
  toolChoice?: "auto" | "none" | "required";
28
- /** Cheap model ID used for generating conversation titles (e.g. "gemini-2.0-flash-lite"). Falls back to the main model if not set. */
33
+ /** Cheap model ID used for generating conversation titles (e.g. "gemini-3.5-flash-lite"). Falls back to the main model if not set. */
29
34
  titleModelId?: string;
30
35
  /** Tool definitions available to the AI model during chat. */
31
36
  tools?: Record<string, Tool>;
@@ -43,7 +48,7 @@ export interface AiAppOptions {
43
48
  * import {AiApp, AIService} from "@terreno/ai";
44
49
  * import {google} from "@ai-sdk/google";
45
50
  *
46
- * const aiService = new AIService({model: google("gemini-2.5-flash")});
51
+ * const aiService = new AIService({model: google("gemini-3.8-flash")});
47
52
  * new AiApp({aiService, tools: myTools}).register(app);
48
53
  * ```
49
54
  *
@@ -51,7 +56,7 @@ export interface AiAppOptions {
51
56
  * ```typescript
52
57
  * // Demo mode with per-request key support (no server-side API key needed)
53
58
  * new AiApp({
54
- * createModelFn: (key) => google("gemini-2.5-flash", {apiKey: key}),
59
+ * createModelFn: (key) => google("gemini-3.8-flash", {apiKey: key}),
55
60
  * demoMode: true,
56
61
  * }).register(app);
57
62
  * ```
package/dist/aiApp.js CHANGED
@@ -20,7 +20,7 @@ const projects_1 = require("./routes/projects");
20
20
  * import {AiApp, AIService} from "@terreno/ai";
21
21
  * import {google} from "@ai-sdk/google";
22
22
  *
23
- * const aiService = new AIService({model: google("gemini-2.5-flash")});
23
+ * const aiService = new AIService({model: google("gemini-3.8-flash")});
24
24
  * new AiApp({aiService, tools: myTools}).register(app);
25
25
  * ```
26
26
  *
@@ -28,7 +28,7 @@ const projects_1 = require("./routes/projects");
28
28
  * ```typescript
29
29
  * // Demo mode with per-request key support (no server-side API key needed)
30
30
  * new AiApp({
31
- * createModelFn: (key) => google("gemini-2.5-flash", {apiKey: key}),
31
+ * createModelFn: (key) => google("gemini-3.8-flash", {apiKey: key}),
32
32
  * demoMode: true,
33
33
  * }).register(app);
34
34
  * ```
@@ -40,13 +40,16 @@ class AiApp {
40
40
  }
41
41
  register(app) {
42
42
  const router = app;
43
- const { aiService, createModelFn, createServerModelFn, demoMode, fileStorageService, gcsBucket, maxSteps, mcpService, openApiOptions, titleModelId, toolChoice, tools, } = this.options;
43
+ const { aiService, createModelFn, createServerModelFn, demoMode, fileStorageService, fileUploadsEnabled, gcsBucket, maxSteps, mcpService, openApiOptions, titleModelId, toolChoice, tools, } = this.options;
44
44
  (0, gptHistories_1.addGptHistoryRoutes)(router, { openApiOptions });
45
45
  (0, gpt_1.addGptRoutes)(router, {
46
46
  aiService,
47
47
  createModelFn,
48
48
  createServerModelFn,
49
49
  demoMode,
50
+ // Attachments are only uploaded when the file routes are mounted too
51
+ fileStorageService: fileStorageService && gcsBucket ? fileStorageService : undefined,
52
+ fileUploadsEnabled,
50
53
  maxSteps,
51
54
  mcpService,
52
55
  openApiOptions,
@@ -59,6 +62,7 @@ class AiApp {
59
62
  if (fileStorageService && gcsBucket) {
60
63
  (0, files_1.addFileRoutes)(router, {
61
64
  fileStorageService,
65
+ fileUploadsEnabled,
62
66
  gcsBucket,
63
67
  openApiOptions,
64
68
  });
@@ -8,6 +8,10 @@ const api_1 = require("@terreno/api");
8
8
  const mongoose_1 = __importDefault(require("mongoose"));
9
9
  const contentPartSchema = new mongoose_1.default.Schema({
10
10
  filename: { description: "Original filename of the attached file", type: String },
11
+ gcsKey: {
12
+ description: "Durable storage key for an attachment uploaded through FileStorageService",
13
+ type: String,
14
+ },
11
15
  mimeType: { description: "MIME type of the content part", type: String },
12
16
  text: { description: "Text content of this part", type: String },
13
17
  type: {
@@ -28,7 +32,24 @@ const gptHistoryPromptSchema = new mongoose_1.default.Schema({
28
32
  type: String,
29
33
  },
30
34
  result: { description: "Result returned from a tool call", type: mongoose_1.default.Schema.Types.Mixed },
31
- text: { description: "Text content of the prompt or response", required: true, type: String },
35
+ status: {
36
+ description: "Lifecycle of an assistant reply: streaming while partial text is persisted, then complete or error",
37
+ enum: ["streaming", "complete", "error"],
38
+ type: String,
39
+ },
40
+ streamId: {
41
+ description: "Identifier of the /gpt/prompt reply, used to resume an in-flight stream",
42
+ type: String,
43
+ },
44
+ text: {
45
+ default: "",
46
+ description: "Text content of the prompt or response",
47
+ // Image-only responses carry their payload in content, and streaming replies start empty
48
+ required: function () {
49
+ return !this.content?.length && !this.status;
50
+ },
51
+ type: String,
52
+ },
32
53
  toolCallId: {
33
54
  description: "Identifier linking a tool result to its originating call",
34
55
  type: String,
@@ -7,6 +7,7 @@ exports.addFileRoutes = void 0;
7
7
  const api_1 = require("@terreno/api");
8
8
  const multer_1 = __importDefault(require("multer"));
9
9
  const fileAttachment_1 = require("../models/fileAttachment");
10
+ const fileUploadsGate_1 = require("../service/fileUploadsGate");
10
11
  const ALLOWED_MIME_TYPES = new Set([
11
12
  "image/jpeg",
12
13
  "image/png",
@@ -47,6 +48,7 @@ const addFileRoutes = (router, options) => {
47
48
  })
48
49
  .build(),
49
50
  ], (0, api_1.asyncHandler)(async (req, res) => {
51
+ await (0, fileUploadsGate_1.assertFileUploadsEnabled)(req, options.fileUploadsEnabled);
50
52
  const file = req.file;
51
53
  const userId = req.user
52
54
  ?._id;