@genesislcap/foundation-ai 14.420.0 → 14.421.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,6 +1,6 @@
1
1
  import { InterfaceSymbol } from '@microsoft/fast-foundation';
2
2
 
3
- /** Feature flag name for AI functionality (beta). Enable via ?feature.ai in URL. */
3
+ /** Feature flag name for AI functionality (beta). Enable via ?feature.ai in URL or GENX_ENABLE_AI env var. */
4
4
  export declare const AI_FEATURE_FLAG = "ai";
5
5
 
6
6
  /**
@@ -31,6 +31,14 @@ export declare interface AIProvider {
31
31
  * Must be called from a user gesture (e.g. click).
32
32
  */
33
33
  triggerDownload?(): Promise<void>;
34
+ /**
35
+ * Stateless one-off prompt. No conversation history is maintained.
36
+ * Returns the plain text response.
37
+ * Use this for side-calls (suggestions, summarisation, classification) that
38
+ * should not interact with any ongoing conversation context.
39
+ * Providers that support chat implement this.
40
+ */
41
+ prompt?(message: string, options?: ChatRequestOptions): Promise<string>;
34
42
  /**
35
43
  * Multi-turn chat (non-streaming). Returns the assistant's response message.
36
44
  * Providers that support chat (Gemini, OpenAI) implement this.
@@ -101,6 +109,27 @@ declare interface AITransport {
101
109
  isAvailable?(): Promise<boolean>;
102
110
  }
103
111
 
112
+ /**
113
+ * Agent engine configuration for the chat assistant.
114
+ *
115
+ * @beta
116
+ */
117
+ export declare interface ChatAgentConfig {
118
+ /** Maximum number of tool call iterations within one agent's loop. Default: 50. */
119
+ maxToolIterations?: number;
120
+ /** Maximum number of agent-to-agent handoffs per user turn. Default: 3. */
121
+ maxHandoffs?: number;
122
+ /** Number of recent messages passed to the classifier for context. Default: 4. */
123
+ classifierHistoryLength?: number;
124
+ /** Number of retries on classifier failure before erroring. Default: 2. */
125
+ classifierRetries?: number;
126
+ /**
127
+ * Maximum number of consecutive fold open/close operations without a real tool call before
128
+ * the driver injects a guidance message. Default: 5.
129
+ */
130
+ maxFoldOperations?: number;
131
+ }
132
+
104
133
  /**
105
134
  * Configuration for the animations feature.
106
135
  *
@@ -131,35 +160,32 @@ export declare interface ChatAttachment {
131
160
  }
132
161
 
133
162
  /**
134
- * Display and behaviour configuration for the chat assistant.
135
- *
136
- * For toggle flags (`showToolCalls`, `showThinkingSteps`):
137
- * - `true` — default on, user can toggle off
138
- * - `false` — default off, user can toggle on
139
- * - `null` / `undefined` — completely disabled, no UI control shown
163
+ * Display and engine configuration for the chat assistant.
140
164
  *
141
165
  * @beta
142
166
  */
143
167
  export declare interface ChatConfig {
144
- /** Show tool call details in the chat UI. */
145
- showToolCalls?: boolean | null;
146
- /** Show model thinking/reasoning steps. */
147
- showThinkingSteps?: boolean | null;
148
- /** Show a button to download the full chat history as JSON. */
149
- allowDebugDownload?: boolean;
150
- /** Comma-separated list of accepted file extensions for upload, e.g., ".txt,.md,.csv". If undefined or empty, file uploads are disabled. */
151
- acceptedFiles?: string;
152
- /**
153
- * Seconds to wait before showing the loading spinner. Default: 5.
154
- * Set to 0 to show the spinner immediately when a request is in flight.
155
- */
156
- loadingDelay?: number;
157
- /** Animations feature configuration. */
158
- animations?: ChatAnimationsConfig;
159
- /** Maximum number of tool call iterations per turn. Default: 50. */
160
- maxToolIterations?: number;
168
+ /** UI display settings toggles, file upload, animations, etc. */
169
+ ui?: ChatUiConfig;
170
+ /** Agent engine settings — iteration limits, handoff caps, classifier tuning. */
171
+ agent?: ChatAgentConfig;
172
+ /** Query suggestions feature configuration. */
173
+ suggestions?: ChatSuggestionsConfig;
161
174
  }
162
175
 
176
+ /**
177
+ * The result returned by a driver after processing a user turn.
178
+ *
179
+ * @beta
180
+ */
181
+ export declare type ChatDriverResult = {
182
+ reason: 'done';
183
+ } | {
184
+ reason: 'agent-handoff';
185
+ summary: string;
186
+ remainingTask: string;
187
+ };
188
+
163
189
  /**
164
190
  * A user interaction component request.
165
191
  *
@@ -169,8 +195,8 @@ export declare interface ChatInteraction {
169
195
  interactionId: string;
170
196
  componentName: string;
171
197
  data: any;
172
- /** Set to true once the interaction has been resolved. Used to render a read-only state on re-render. */
173
- resolved?: boolean;
198
+ /** The result when the interaction has been resolved. Truthy check indicates resolved state; value is available for widgets to display. */
199
+ resolved?: InteractionResult<unknown>;
174
200
  }
175
201
 
176
202
  /**
@@ -186,6 +212,14 @@ export declare interface ChatMessage {
186
212
  attachments?: ChatAttachment[];
187
213
  interaction?: ChatInteraction;
188
214
  thinking?: boolean;
215
+ /** Name of the agent that produced this message. Set by OrchestratingDriver. */
216
+ agentName?: string;
217
+ /**
218
+ * Total prompt tokens consumed for the request that produced this message.
219
+ * Set by transports that return usage metadata (e.g. Gemini). Used to display
220
+ * context window utilisation in the UI.
221
+ */
222
+ inputTokens?: number;
189
223
  }
190
224
 
191
225
  /**
@@ -205,7 +239,7 @@ export declare interface ChatRequestOptions {
205
239
  *
206
240
  * @beta
207
241
  */
208
- export declare type ChatRole = 'user' | 'assistant' | 'system' | 'tool';
242
+ export declare type ChatRole = 'user' | 'assistant' | 'system' | 'tool' | 'system-event';
209
243
 
210
244
  /**
211
245
  * A streaming chunk from a chat response.
@@ -218,16 +252,77 @@ export declare interface ChatStreamChunk {
218
252
  toolCalls?: ChatToolCall[];
219
253
  }
220
254
 
255
+ /**
256
+ * Configuration for the chat suggestions feature.
257
+ *
258
+ * @beta
259
+ */
260
+ export declare type ChatSuggestionsConfig = {
261
+ /** Suggestions are disabled. */
262
+ behavior: 'never';
263
+ /** Not applicable when behavior is 'never'. */
264
+ count?: never;
265
+ /** Not applicable when behavior is 'never'. */
266
+ prompt?: never;
267
+ } | {
268
+ /**
269
+ * 'initial': Show suggestions on first load before any messages are sent.
270
+ * 'always': Show suggestions after every assistant response.
271
+ */
272
+ behavior: 'initial' | 'always';
273
+ /**
274
+ * Number of suggestions to generate.
275
+ * @default 3
276
+ */
277
+ count?: number;
278
+ /**
279
+ * Custom prompt to steer the suggestion generation. If omitted, a
280
+ * default prompt is used.
281
+ */
282
+ prompt?: string;
283
+ };
284
+
221
285
  /**
222
286
  * A tool call requested by the assistant.
223
287
  *
224
288
  * @beta
225
289
  */
226
- export declare interface ChatToolCall {
290
+ export declare type ChatToolCall = ChatToolCallBase | ChatToolCallUnknown;
291
+
292
+ /**
293
+ * A tool call requested by the assistant.
294
+ *
295
+ * @beta
296
+ */
297
+ declare type ChatToolCallBase = {
227
298
  id: string;
228
299
  name: string;
229
300
  args: Record<string, unknown>;
230
- }
301
+ /**
302
+ * Set by the driver when this tool call is a fold lifecycle event.
303
+ * Used by the template to render fold opens/closes distinctly.
304
+ * Not sent to the AI provider.
305
+ */
306
+ foldEvent?: 'open' | 'close';
307
+ /**
308
+ * UI-only breadcrumb path of fold names the tool lives inside, e.g. ['trading_tools'].
309
+ * Set by the driver from the active fold stack when a tool call is appended.
310
+ * Not sent to the AI provider.
311
+ */
312
+ foldPath?: string[];
313
+ };
314
+
315
+ /**
316
+ * A tool call for a tool name the driver could not resolve to any handler.
317
+ * `availableTools` lists every tool name registered at the time of the call.
318
+ * Not sent to the AI provider.
319
+ *
320
+ * @beta
321
+ */
322
+ export declare type ChatToolCallUnknown = ChatToolCallBase & {
323
+ unknown: true;
324
+ availableTools: string[];
325
+ };
231
326
 
232
327
  /**
233
328
  * JSON Schema-based tool definition for function calling.
@@ -274,6 +369,55 @@ export declare interface ChatTransport {
274
369
  streamChatMessage?(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): AsyncIterable<ChatStreamChunk>;
275
370
  }
276
371
 
372
+ /**
373
+ * UI display configuration for the chat assistant.
374
+ *
375
+ * For toggle flags (`showToolCalls`, `showThinkingSteps`):
376
+ * - `true` — default on, user can toggle off
377
+ * - `false` — default off, user can toggle on
378
+ * - `null` / `undefined` — completely disabled, no UI control shown
379
+ *
380
+ * @beta
381
+ */
382
+ export declare interface ChatUiConfig {
383
+ /** Show tool call details in the chat UI. */
384
+ showToolCalls?: boolean | null;
385
+ /** Show model thinking/reasoning steps. */
386
+ showThinkingSteps?: boolean | null;
387
+ /** Show a button to download the full chat history as JSON. */
388
+ allowDebugDownload?: boolean;
389
+ /** Comma-separated list of accepted file extensions for upload, e.g., ".txt,.md,.csv". If undefined or empty, file uploads are disabled. */
390
+ acceptedFiles?: string;
391
+ /**
392
+ * Seconds to wait before showing the loading spinner. Default: 5.
393
+ * Set to 0 to show the spinner immediately when a request is in flight.
394
+ */
395
+ loadingDelay?: number;
396
+ /** Animations feature configuration. */
397
+ animations?: ChatAnimationsConfig;
398
+ /**
399
+ * When `true`, shows the `slot="splash"` content when there are no messages.
400
+ * The host element reflects a `showing-splash` boolean attribute that consumers
401
+ * can use as a CSS hook to animate the splash in and out. Default: `false`.
402
+ */
403
+ showSplash?: boolean;
404
+ /**
405
+ * Show an inline divider in the message list when the active specialist changes.
406
+ * Also shown automatically when showToolCalls is true.
407
+ * - `true` — default on, user can toggle off
408
+ * - `false` — default off, user can toggle on
409
+ * - `null` / `undefined` — completely disabled, no UI control shown
410
+ */
411
+ showAgentSwitchIndicator?: boolean | null;
412
+ /**
413
+ * Show a context window usage indicator in the settings panel.
414
+ * Visible when the settings panel is open and token usage data is available.
415
+ * - `true` or `undefined` (default) — shown when data is available
416
+ * - `false` — hidden
417
+ */
418
+ showContextUsage?: boolean;
419
+ }
420
+
277
421
  /**
278
422
  * Chrome built-in AI (Prompt API / Gemini Nano) configuration.
279
423
  *
@@ -370,11 +514,19 @@ export declare type FieldLike = string | {
370
514
  */
371
515
  export declare interface GeminiAIConfig extends AIProviderConfig {
372
516
  providerType: 'gemini';
373
- model?: string;
517
+ /** Defaults to `gemini-2.5-flash-lite`. Only {@link SUPPORTED_GEMINI_MODEL_IDS} are accepted at runtime. */
518
+ model?: GeminiModelId;
374
519
  serverEndpoint?: string;
375
520
  apiKey?: string;
376
521
  }
377
522
 
523
+ /**
524
+ * Gemini REST model ids supported by {@link GeminiTransport}.
525
+ *
526
+ * @beta
527
+ */
528
+ export declare type GeminiModelId = 'gemini-2.5-flash' | 'gemini-2.5-flash-lite';
529
+
378
530
  /**
379
531
  * Gemini AI provider. Uses {@link GeminiTransport} to handle requests.
380
532
  * Implements criteria interpretation and multi-turn chat.
@@ -387,6 +539,7 @@ export declare class GeminiProvider implements AIProvider {
387
539
  constructor(config: GeminiProviderConfig, transport: GeminiTransport);
388
540
  getStatus(): Promise<AIStatus>;
389
541
  interpretCriteria(input: string, context: CriteriaInterpretContext): Promise<CriteriaInterpretationResult | null>;
542
+ prompt(message: string, options?: ChatRequestOptions): Promise<string>;
390
543
  chat(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
391
544
  streamChat(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): AsyncIterable<ChatStreamChunk>;
392
545
  }
@@ -412,13 +565,11 @@ export declare class GeminiTransport implements AITransport, ChatTransport {
412
565
  constructor(config?: GeminiTransportConfig);
413
566
  getConfig(): {
414
567
  provider: 'gemini';
415
- model: string;
568
+ model: GeminiModelId;
416
569
  };
417
570
  sendStructuredPrompt(options: StructuredPromptOptions): Promise<string>;
418
571
  sendChatMessage(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
419
572
  private static readonly TOKENS_PER_MILLION;
420
- private static readonly PROMPT_COST_PER_MILLION;
421
- private static readonly CANDIDATE_COST_PER_MILLION;
422
573
  private static readonly COST_DECIMAL_PLACES;
423
574
  private logTokenUsage;
424
575
  private toGeminiContents;
@@ -432,7 +583,10 @@ export declare class GeminiTransport implements AITransport, ChatTransport {
432
583
  }
433
584
 
434
585
  declare interface GeminiTransportConfig {
435
- model?: string;
586
+ /**
587
+ * Defaults to `gemini-2.5-flash-lite`. Only {@link SUPPORTED_GEMINI_MODEL_IDS} are accepted.
588
+ */
589
+ model?: GeminiModelId;
436
590
  timeout?: number;
437
591
  /**
438
592
  * API key for direct calls to the Gemini API.
@@ -479,9 +633,16 @@ export declare type InteractionResult<T = unknown> = {
479
633
  message?: string;
480
634
  };
481
635
 
482
- /** Returns true when AI features (beta) are enabled. Requires ?feature.ai in URL. */
636
+ /** Returns true when AI features (beta) are enabled via ?feature.ai URL param or GENX_ENABLE_AI=true env var. */
483
637
  export declare const isAIFeatureEnabled: () => boolean;
484
638
 
639
+ /**
640
+ * Type guard that narrows a `ChatToolCall` to `ChatToolCallUnknown`.
641
+ *
642
+ * @beta
643
+ */
644
+ export declare function isChatToolCallUnknown(tc: ChatToolCall): tc is ChatToolCallUnknown;
645
+
485
646
  /**
486
647
  * Speech-to-text using Web Speech API.
487
648
  * Gracefully degrades when SpeechRecognition is unavailable.
@@ -524,7 +685,7 @@ export declare function resolveAIConfig(options?: ResolveAIConfigOptions): Promi
524
685
  export declare interface ResolveAIConfigOptions {
525
686
  /** Cloud provider (openai, gemini). Default: openai */
526
687
  provider?: 'openai' | 'gemini';
527
- /** Model name (e.g. gpt-4o-mini). Default: gpt-4o-mini */
688
+ /** Model name. OpenAI default: gpt-4o-mini. Gemini: only {@link SUPPORTED_GEMINI_MODEL_IDS} (default flash-lite). */
528
689
  model?: string;
529
690
  /** Prefer Chrome built-in AI when available */
530
691
  preferChrome?: boolean;
@@ -569,4 +730,7 @@ declare interface StructuredPromptOptions {
569
730
  responseSchema?: object;
570
731
  }
571
732
 
733
+ /** @beta */
734
+ export declare const SUPPORTED_GEMINI_MODEL_IDS: readonly GeminiModelId[];
735
+
572
736
  export { }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-ai",
3
3
  "description": "Genesis Foundation AI - Provider-agnostic AI configuration and shared utilities",
4
- "version": "14.420.0",
4
+ "version": "14.421.0",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -51,17 +51,17 @@
51
51
  }
52
52
  },
53
53
  "devDependencies": {
54
- "@genesislcap/foundation-testing": "14.420.0",
55
- "@genesislcap/genx": "14.420.0",
56
- "@genesislcap/rollup-builder": "14.420.0",
57
- "@genesislcap/ts-builder": "14.420.0",
58
- "@genesislcap/uvu-playwright-builder": "14.420.0",
59
- "@genesislcap/vite-builder": "14.420.0",
60
- "@genesislcap/webpack-builder": "14.420.0"
54
+ "@genesislcap/foundation-testing": "14.421.0",
55
+ "@genesislcap/genx": "14.421.0",
56
+ "@genesislcap/rollup-builder": "14.421.0",
57
+ "@genesislcap/ts-builder": "14.421.0",
58
+ "@genesislcap/uvu-playwright-builder": "14.421.0",
59
+ "@genesislcap/vite-builder": "14.421.0",
60
+ "@genesislcap/webpack-builder": "14.421.0"
61
61
  },
62
62
  "dependencies": {
63
- "@genesislcap/foundation-logger": "14.420.0",
64
- "@genesislcap/foundation-utils": "14.420.0",
63
+ "@genesislcap/foundation-logger": "14.421.0",
64
+ "@genesislcap/foundation-utils": "14.421.0",
65
65
  "@microsoft/fast-foundation": "2.50.0"
66
66
  },
67
67
  "repository": {
@@ -72,5 +72,5 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "52c9259f8fb7a203979c832b08388579ae728a38"
75
+ "gitHead": "d109b70edbd07af351ed8bf393ace74b42bb5356"
76
76
  }