@firstlovecenter/ai-chat 0.2.3 → 0.6.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.
@@ -1,4 +1,5 @@
1
1
  import { GoogleAuth } from 'google-auth-library';
2
+ import { ZodType } from 'zod';
2
3
 
3
4
  /**
4
5
  * Tool typing for the agent loop.
@@ -39,8 +40,16 @@ type ToolResult = {
39
40
  message: string;
40
41
  };
41
42
  };
43
+
42
44
  type ToolDefinition<I = unknown, S = unknown> = {
43
45
  schema: ToolSchema;
46
+ /**
47
+ * Optional Zod schema for the same input. Required by the Vercel AI SDK
48
+ * route (which needs Zod to feed `tool({ parameters })`); the custom
49
+ * SSE route ignores it. Tools registered without a `zodSchema` will
50
+ * cause `buildVercelTools` to throw at config time.
51
+ */
52
+ zodSchema?: ZodType<I>;
44
53
  execute(input: I, ctx: ToolContext<S>): Promise<ToolResult>;
45
54
  };
46
55
  /** The terminal tool that closes the agent loop. The host's tool registry MUST include it. */
@@ -130,16 +139,26 @@ type ChatMessage = {
130
139
  createdAt: Date;
131
140
  };
132
141
  /**
133
- * Singleton row controlling the active tool-calling provider, the Vertex
134
- * region, and which chat UI (Custom vs. Vercel) renders globally. All three
142
+ * Singleton row controlling global AI runtime settings. All open-string
135
143
  * fields are validated at runtime against the registries the host configures
136
144
  * — they are not enums in the package's types so consumers can register
137
145
  * additional providers / interfaces without a schema change.
146
+ *
147
+ * `maxOutputTokens` caps both the agent loop's per-turn output AND each
148
+ * narrator's prose pass. Reasoning models (e.g. `xai/grok-4.1-fast-reasoning`)
149
+ * charge internal thinking against this budget — set it generously when
150
+ * those are in use.
151
+ *
152
+ * `rolePrompt` is the persona the assistant adopts. When non-null, it
153
+ * takes precedence over the host's static `rolePrompt` configureAiChat
154
+ * option, so admins can edit live in the settings UI.
138
155
  */
139
156
  type AiSettings = {
140
157
  toolProvider: string;
141
158
  gcpLocation: string;
142
159
  chatInterface: string;
160
+ maxOutputTokens: number;
161
+ rolePrompt: string | null;
143
162
  updatedAt: Date | null;
144
163
  updatedByUserId: number | null;
145
164
  };
@@ -233,6 +252,9 @@ type AiSettingsPatch = {
233
252
  toolProvider?: string;
234
253
  gcpLocation?: string;
235
254
  chatInterface?: string;
255
+ maxOutputTokens?: number;
256
+ /** Pass `null` to clear back to the host's static fallback. */
257
+ rolePrompt?: string | null;
236
258
  };
237
259
  /**
238
260
  * The whole reason this package is ORM-agnostic. Implemented by:
@@ -1,4 +1,5 @@
1
1
  import { GoogleAuth } from 'google-auth-library';
2
+ import { ZodType } from 'zod';
2
3
 
3
4
  /**
4
5
  * Tool typing for the agent loop.
@@ -39,8 +40,16 @@ type ToolResult = {
39
40
  message: string;
40
41
  };
41
42
  };
43
+
42
44
  type ToolDefinition<I = unknown, S = unknown> = {
43
45
  schema: ToolSchema;
46
+ /**
47
+ * Optional Zod schema for the same input. Required by the Vercel AI SDK
48
+ * route (which needs Zod to feed `tool({ parameters })`); the custom
49
+ * SSE route ignores it. Tools registered without a `zodSchema` will
50
+ * cause `buildVercelTools` to throw at config time.
51
+ */
52
+ zodSchema?: ZodType<I>;
44
53
  execute(input: I, ctx: ToolContext<S>): Promise<ToolResult>;
45
54
  };
46
55
  /** The terminal tool that closes the agent loop. The host's tool registry MUST include it. */
@@ -130,16 +139,26 @@ type ChatMessage = {
130
139
  createdAt: Date;
131
140
  };
132
141
  /**
133
- * Singleton row controlling the active tool-calling provider, the Vertex
134
- * region, and which chat UI (Custom vs. Vercel) renders globally. All three
142
+ * Singleton row controlling global AI runtime settings. All open-string
135
143
  * fields are validated at runtime against the registries the host configures
136
144
  * — they are not enums in the package's types so consumers can register
137
145
  * additional providers / interfaces without a schema change.
146
+ *
147
+ * `maxOutputTokens` caps both the agent loop's per-turn output AND each
148
+ * narrator's prose pass. Reasoning models (e.g. `xai/grok-4.1-fast-reasoning`)
149
+ * charge internal thinking against this budget — set it generously when
150
+ * those are in use.
151
+ *
152
+ * `rolePrompt` is the persona the assistant adopts. When non-null, it
153
+ * takes precedence over the host's static `rolePrompt` configureAiChat
154
+ * option, so admins can edit live in the settings UI.
138
155
  */
139
156
  type AiSettings = {
140
157
  toolProvider: string;
141
158
  gcpLocation: string;
142
159
  chatInterface: string;
160
+ maxOutputTokens: number;
161
+ rolePrompt: string | null;
143
162
  updatedAt: Date | null;
144
163
  updatedByUserId: number | null;
145
164
  };
@@ -233,6 +252,9 @@ type AiSettingsPatch = {
233
252
  toolProvider?: string;
234
253
  gcpLocation?: string;
235
254
  chatInterface?: string;
255
+ maxOutputTokens?: number;
256
+ /** Pass `null` to clear back to the host's static fallback. */
257
+ rolePrompt?: string | null;
236
258
  };
237
259
  /**
238
260
  * The whole reason this package is ORM-agnostic. Implemented by: