@genesislcap/foundation-ai 14.419.2 → 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.
- package/README.md +7 -1
- package/dist/dts/ai-provider.d.ts +10 -2
- package/dist/dts/ai-provider.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -2
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/providers/gemini-provider.d.ts +1 -0
- package/dist/dts/providers/gemini-provider.d.ts.map +1 -1
- package/dist/dts/transports/gemini-transport.d.ts +6 -5
- package/dist/dts/transports/gemini-transport.d.ts.map +1 -1
- package/dist/dts/types/chat.types.d.ts +145 -8
- package/dist/dts/types/chat.types.d.ts.map +1 -1
- package/dist/dts/types/config.types.d.ts +10 -1
- package/dist/dts/types/config.types.d.ts.map +1 -1
- package/dist/dts/utils/feature-flags.d.ts +2 -2
- package/dist/dts/utils/feature-flags.d.ts.map +1 -1
- package/dist/esm/ai-provider.js +8 -3
- package/dist/esm/index.js +2 -0
- package/dist/esm/providers/gemini-provider.js +6 -0
- package/dist/esm/transports/gemini-transport.js +40 -12
- package/dist/esm/types/chat.types.js +8 -1
- package/dist/esm/types/config.types.js +5 -1
- package/dist/esm/utils/feature-flags.js +10 -3
- package/dist/foundation-ai.api.json +890 -246
- package/dist/foundation-ai.d.ts +200 -36
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -21,12 +21,18 @@ Each provider exposes capabilities such as `interpretCriteria` (natural language
|
|
|
21
21
|
|
|
22
22
|
## Feature flag
|
|
23
23
|
|
|
24
|
-
AI features are **disabled by default
|
|
24
|
+
AI features are **disabled by default**. Enable them via URL parameter or environment variable:
|
|
25
25
|
|
|
26
|
+
**URL parameter** — append `?feature.ai` to any URL (useful for testing without rebuilding):
|
|
26
27
|
```
|
|
27
28
|
https://your-app.com/?feature.ai
|
|
28
29
|
```
|
|
29
30
|
|
|
31
|
+
**Environment variable** — set `GENX_ENABLE_AI=true` in your app's `.env` file to enable permanently without a URL parameter:
|
|
32
|
+
```
|
|
33
|
+
GENX_ENABLE_AI=true
|
|
34
|
+
```
|
|
35
|
+
|
|
30
36
|
When the flag is off:
|
|
31
37
|
|
|
32
38
|
- `createAIProvider()` and `getAIProvider()` return a no-op provider
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CriteriaInterpretContext } from './interactions';
|
|
2
|
-
import type
|
|
2
|
+
import { type AIConfig, type AIStatus, type CriteriaInterpretationResult } from './types';
|
|
3
3
|
import type { ChatMessage, ChatRequestOptions, ChatStreamChunk } from './types/chat.types';
|
|
4
4
|
/**
|
|
5
5
|
* AI Provider interface for foundation-ai.
|
|
@@ -21,6 +21,14 @@ export interface AIProvider {
|
|
|
21
21
|
* Must be called from a user gesture (e.g. click).
|
|
22
22
|
*/
|
|
23
23
|
triggerDownload?(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Stateless one-off prompt. No conversation history is maintained.
|
|
26
|
+
* Returns the plain text response.
|
|
27
|
+
* Use this for side-calls (suggestions, summarisation, classification) that
|
|
28
|
+
* should not interact with any ongoing conversation context.
|
|
29
|
+
* Providers that support chat implement this.
|
|
30
|
+
*/
|
|
31
|
+
prompt?(message: string, options?: ChatRequestOptions): Promise<string>;
|
|
24
32
|
/**
|
|
25
33
|
* Multi-turn chat (non-streaming). Returns the assistant's response message.
|
|
26
34
|
* Providers that support chat (Gemini, OpenAI) implement this.
|
|
@@ -50,7 +58,7 @@ export declare function createAIProvider(config?: AIConfig | null): AIProvider;
|
|
|
50
58
|
export interface ResolveAIConfigOptions {
|
|
51
59
|
/** Cloud provider (openai, gemini). Default: openai */
|
|
52
60
|
provider?: 'openai' | 'gemini';
|
|
53
|
-
/** Model name
|
|
61
|
+
/** Model name. OpenAI default: gpt-4o-mini. Gemini: only {@link SUPPORTED_GEMINI_MODEL_IDS} (default flash-lite). */
|
|
54
62
|
model?: string;
|
|
55
63
|
/** Prefer Chrome built-in AI when available */
|
|
56
64
|
preferChrome?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-provider.d.ts","sourceRoot":"","sources":["../../src/ai-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAQ/D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ai-provider.d.ts","sourceRoot":"","sources":["../../src/ai-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAQ/D,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,QAAQ,EAEb,KAAK,4BAA4B,EAIlC,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAI3F;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,iBAAiB,CAAC,CAChB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC,CAAC;IAEhD;;OAEG;IACH,SAAS,CAAC,IAAI,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAEvC;;;OAGG;IACH,eAAe,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAExE;;;OAGG;IACH,IAAI,CAAC,CACH,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC,CAAC;IAExB;;;OAGG;IACH,UAAU,CAAC,CACT,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,aAAa,CAAC,eAAe,CAAC,CAAC;CACnC;AAcD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU,CAmCrE;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,uDAAuD;IACvD,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC/B,qHAAqH;IACrH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAgC1B;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,kEAAwE,CAAC;AAEhG;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAM1C"}
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ export { AIProvider, createAIProvider, getAIProvider, resolveAIConfig } from './
|
|
|
2
2
|
export { GeminiProvider } from './providers/gemini-provider';
|
|
3
3
|
export { GeminiTransport, MalformedFunctionCallError } from './transports/gemini-transport';
|
|
4
4
|
export { AI_FEATURE_FLAG, isAIFeatureEnabled } from './utils/feature-flags';
|
|
5
|
-
export
|
|
6
|
-
export type {
|
|
5
|
+
export { SUPPORTED_GEMINI_MODEL_IDS } from './types';
|
|
6
|
+
export type { AIConfig, AIStatus, AIProviderType, ChromeAIConfig, ChromeAvailability, GeminiAIConfig, GeminiModelId, ServerAIConfig, } from './types';
|
|
7
|
+
export type { ChatAgentConfig, ChatAnimationsConfig, ChatAttachment, ChatConfig, ChatDriverResult, ChatMessage, ChatInteraction, ChatRequestOptions, ChatRole, ChatStreamChunk, ChatToolCall, ChatToolCallUnknown, ChatToolDefinition, ChatToolHandlers, ChatToolResult, ChatUiConfig, ChatSuggestionsConfig, InteractionResult, } from './types/chat.types';
|
|
8
|
+
export { isChatToolCallUnknown } from './types/chat.types';
|
|
7
9
|
export type { ChatTransport } from './types/chat-transport.types';
|
|
8
10
|
export type { ResolveAIConfigOptions } from './ai-provider';
|
|
9
11
|
export type { CriteriaInterpretContext, FieldLike } from './interactions';
|
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,YAAY,EACV,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,YAAY,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1E,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AACrD,YAAY,EACV,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,YAAY,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1E,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -19,6 +19,7 @@ export declare class GeminiProvider implements AIProvider {
|
|
|
19
19
|
constructor(config: GeminiProviderConfig, transport: GeminiTransport);
|
|
20
20
|
getStatus(): Promise<AIStatus>;
|
|
21
21
|
interpretCriteria(input: string, context: CriteriaInterpretContext): Promise<CriteriaInterpretationResult | null>;
|
|
22
|
+
prompt(message: string, options?: ChatRequestOptions): Promise<string>;
|
|
22
23
|
chat(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
|
|
23
24
|
streamChat(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): AsyncIterable<ChatStreamChunk>;
|
|
24
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini-provider.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAOhE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAG5E,MAAM,WAAW,oBAAoB;IACnC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;GAKG;AACH,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;IAC5C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAS;gBAEnC,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,eAAe;IAK9D,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC;IAK9B,iBAAiB,CACrB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC;I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,CAAC,MAAM,CAAC;IAKtE,IAAI,CACR,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC;IAIhB,UAAU,CACf,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,aAAa,CAAC,eAAe,CAAC;CAYlC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AITransport, type GeminiModelId, type StructuredPromptOptions } from '../types';
|
|
2
2
|
import type { ChatTransport } from '../types/chat-transport.types';
|
|
3
3
|
import type { ChatMessage, ChatRequestOptions } from '../types/chat.types';
|
|
4
4
|
export interface GeminiTransportConfig {
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Defaults to `gemini-2.5-flash-lite`. Only {@link SUPPORTED_GEMINI_MODEL_IDS} are accepted.
|
|
7
|
+
*/
|
|
8
|
+
model?: GeminiModelId;
|
|
6
9
|
timeout?: number;
|
|
7
10
|
/**
|
|
8
11
|
* API key for direct calls to the Gemini API.
|
|
@@ -45,13 +48,11 @@ export declare class GeminiTransport implements AITransport, ChatTransport {
|
|
|
45
48
|
constructor(config?: GeminiTransportConfig);
|
|
46
49
|
getConfig(): {
|
|
47
50
|
provider: 'gemini';
|
|
48
|
-
model:
|
|
51
|
+
model: GeminiModelId;
|
|
49
52
|
};
|
|
50
53
|
sendStructuredPrompt(options: StructuredPromptOptions): Promise<string>;
|
|
51
54
|
sendChatMessage(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
|
|
52
55
|
private static readonly TOKENS_PER_MILLION;
|
|
53
|
-
private static readonly PROMPT_COST_PER_MILLION;
|
|
54
|
-
private static readonly CANDIDATE_COST_PER_MILLION;
|
|
55
56
|
private static readonly COST_DECIMAL_PLACES;
|
|
56
57
|
private logTokenUsage;
|
|
57
58
|
private toGeminiContents;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/gemini-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"gemini-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/gemini-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC7B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAEV,WAAW,EACX,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AA6B7B,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAUD;;;;;;GAMG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACvC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM;gBAAtB,aAAa,CAAC,EAAE,MAAM;CAI5C;AAED;;;;;;;;GAQG;AACH,qBAAa,eAAgB,YAAW,WAAW,EAAE,aAAa;IAChE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAqB;gBAExC,MAAM,GAAE,qBAA0B;IAe9C,SAAS,IAAI;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,aAAa,CAAA;KAAE;IAMnD,oBAAoB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBvE,eAAe,CACnB,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC;IA4BvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAa;IACvD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAK;IAEhD,OAAO,CAAC,aAAa;IAoBrB,OAAO,CAAC,gBAAgB;IAgDxB,OAAO,CAAC,kBAAkB;IAkE1B,OAAO,CAAC,aAAa;IAyBrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAK;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAO;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAQ;YAEjC,IAAI;IAgDlB,OAAO,CAAC,eAAe;CAexB"}
|
|
@@ -3,17 +3,52 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @beta
|
|
5
5
|
*/
|
|
6
|
-
export type ChatRole = 'user' | 'assistant' | 'system' | 'tool';
|
|
6
|
+
export type ChatRole = 'user' | 'assistant' | 'system' | 'tool' | 'system-event';
|
|
7
7
|
/**
|
|
8
8
|
* A tool call requested by the assistant.
|
|
9
9
|
*
|
|
10
10
|
* @beta
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
type ChatToolCallBase = {
|
|
13
13
|
id: string;
|
|
14
14
|
name: string;
|
|
15
15
|
args: Record<string, unknown>;
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Set by the driver when this tool call is a fold lifecycle event.
|
|
18
|
+
* Used by the template to render fold opens/closes distinctly.
|
|
19
|
+
* Not sent to the AI provider.
|
|
20
|
+
*/
|
|
21
|
+
foldEvent?: 'open' | 'close';
|
|
22
|
+
/**
|
|
23
|
+
* UI-only breadcrumb path of fold names the tool lives inside, e.g. ['trading_tools'].
|
|
24
|
+
* Set by the driver from the active fold stack when a tool call is appended.
|
|
25
|
+
* Not sent to the AI provider.
|
|
26
|
+
*/
|
|
27
|
+
foldPath?: string[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A tool call for a tool name the driver could not resolve to any handler.
|
|
31
|
+
* `availableTools` lists every tool name registered at the time of the call.
|
|
32
|
+
* Not sent to the AI provider.
|
|
33
|
+
*
|
|
34
|
+
* @beta
|
|
35
|
+
*/
|
|
36
|
+
export type ChatToolCallUnknown = ChatToolCallBase & {
|
|
37
|
+
unknown: true;
|
|
38
|
+
availableTools: string[];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A tool call requested by the assistant.
|
|
42
|
+
*
|
|
43
|
+
* @beta
|
|
44
|
+
*/
|
|
45
|
+
export type ChatToolCall = ChatToolCallBase | ChatToolCallUnknown;
|
|
46
|
+
/**
|
|
47
|
+
* Type guard that narrows a `ChatToolCall` to `ChatToolCallUnknown`.
|
|
48
|
+
*
|
|
49
|
+
* @beta
|
|
50
|
+
*/
|
|
51
|
+
export declare function isChatToolCallUnknown(tc: ChatToolCall): tc is ChatToolCallUnknown;
|
|
17
52
|
/**
|
|
18
53
|
* The result of executing a tool call.
|
|
19
54
|
*
|
|
@@ -42,8 +77,8 @@ export interface ChatInteraction {
|
|
|
42
77
|
interactionId: string;
|
|
43
78
|
componentName: string;
|
|
44
79
|
data: any;
|
|
45
|
-
/**
|
|
46
|
-
resolved?:
|
|
80
|
+
/** The result when the interaction has been resolved. Truthy check indicates resolved state; value is available for widgets to display. */
|
|
81
|
+
resolved?: InteractionResult<unknown>;
|
|
47
82
|
}
|
|
48
83
|
/**
|
|
49
84
|
* A file attachment included with a user message.
|
|
@@ -68,6 +103,14 @@ export interface ChatMessage {
|
|
|
68
103
|
attachments?: ChatAttachment[];
|
|
69
104
|
interaction?: ChatInteraction;
|
|
70
105
|
thinking?: boolean;
|
|
106
|
+
/** Name of the agent that produced this message. Set by OrchestratingDriver. */
|
|
107
|
+
agentName?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Total prompt tokens consumed for the request that produced this message.
|
|
110
|
+
* Set by transports that return usage metadata (e.g. Gemini). Used to display
|
|
111
|
+
* context window utilisation in the UI.
|
|
112
|
+
*/
|
|
113
|
+
inputTokens?: number;
|
|
71
114
|
}
|
|
72
115
|
/**
|
|
73
116
|
* JSON Schema-based tool definition for function calling.
|
|
@@ -98,6 +141,18 @@ export interface ChatRequestOptions {
|
|
|
98
141
|
attachments?: ChatAttachment[];
|
|
99
142
|
signal?: AbortSignal;
|
|
100
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* The result returned by a driver after processing a user turn.
|
|
146
|
+
*
|
|
147
|
+
* @beta
|
|
148
|
+
*/
|
|
149
|
+
export type ChatDriverResult = {
|
|
150
|
+
reason: 'done';
|
|
151
|
+
} | {
|
|
152
|
+
reason: 'agent-handoff';
|
|
153
|
+
summary: string;
|
|
154
|
+
remainingTask: string;
|
|
155
|
+
};
|
|
101
156
|
/**
|
|
102
157
|
* A streaming chunk from a chat response.
|
|
103
158
|
*
|
|
@@ -126,7 +181,7 @@ export interface ChatAnimationsConfig {
|
|
|
126
181
|
enabled?: string[];
|
|
127
182
|
}
|
|
128
183
|
/**
|
|
129
|
-
*
|
|
184
|
+
* UI display configuration for the chat assistant.
|
|
130
185
|
*
|
|
131
186
|
* For toggle flags (`showToolCalls`, `showThinkingSteps`):
|
|
132
187
|
* - `true` — default on, user can toggle off
|
|
@@ -135,7 +190,7 @@ export interface ChatAnimationsConfig {
|
|
|
135
190
|
*
|
|
136
191
|
* @beta
|
|
137
192
|
*/
|
|
138
|
-
export interface
|
|
193
|
+
export interface ChatUiConfig {
|
|
139
194
|
/** Show tool call details in the chat UI. */
|
|
140
195
|
showToolCalls?: boolean | null;
|
|
141
196
|
/** Show model thinking/reasoning steps. */
|
|
@@ -151,7 +206,89 @@ export interface ChatConfig {
|
|
|
151
206
|
loadingDelay?: number;
|
|
152
207
|
/** Animations feature configuration. */
|
|
153
208
|
animations?: ChatAnimationsConfig;
|
|
154
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* When `true`, shows the `slot="splash"` content when there are no messages.
|
|
211
|
+
* The host element reflects a `showing-splash` boolean attribute that consumers
|
|
212
|
+
* can use as a CSS hook to animate the splash in and out. Default: `false`.
|
|
213
|
+
*/
|
|
214
|
+
showSplash?: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Show an inline divider in the message list when the active specialist changes.
|
|
217
|
+
* Also shown automatically when showToolCalls is true.
|
|
218
|
+
* - `true` — default on, user can toggle off
|
|
219
|
+
* - `false` — default off, user can toggle on
|
|
220
|
+
* - `null` / `undefined` — completely disabled, no UI control shown
|
|
221
|
+
*/
|
|
222
|
+
showAgentSwitchIndicator?: boolean | null;
|
|
223
|
+
/**
|
|
224
|
+
* Show a context window usage indicator in the settings panel.
|
|
225
|
+
* Visible when the settings panel is open and token usage data is available.
|
|
226
|
+
* - `true` or `undefined` (default) — shown when data is available
|
|
227
|
+
* - `false` — hidden
|
|
228
|
+
*/
|
|
229
|
+
showContextUsage?: boolean;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Agent engine configuration for the chat assistant.
|
|
233
|
+
*
|
|
234
|
+
* @beta
|
|
235
|
+
*/
|
|
236
|
+
export interface ChatAgentConfig {
|
|
237
|
+
/** Maximum number of tool call iterations within one agent's loop. Default: 50. */
|
|
155
238
|
maxToolIterations?: number;
|
|
239
|
+
/** Maximum number of agent-to-agent handoffs per user turn. Default: 3. */
|
|
240
|
+
maxHandoffs?: number;
|
|
241
|
+
/** Number of recent messages passed to the classifier for context. Default: 4. */
|
|
242
|
+
classifierHistoryLength?: number;
|
|
243
|
+
/** Number of retries on classifier failure before erroring. Default: 2. */
|
|
244
|
+
classifierRetries?: number;
|
|
245
|
+
/**
|
|
246
|
+
* Maximum number of consecutive fold open/close operations without a real tool call before
|
|
247
|
+
* the driver injects a guidance message. Default: 5.
|
|
248
|
+
*/
|
|
249
|
+
maxFoldOperations?: number;
|
|
156
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Display and engine configuration for the chat assistant.
|
|
253
|
+
*
|
|
254
|
+
* @beta
|
|
255
|
+
*/
|
|
256
|
+
export interface ChatConfig {
|
|
257
|
+
/** UI display settings — toggles, file upload, animations, etc. */
|
|
258
|
+
ui?: ChatUiConfig;
|
|
259
|
+
/** Agent engine settings — iteration limits, handoff caps, classifier tuning. */
|
|
260
|
+
agent?: ChatAgentConfig;
|
|
261
|
+
/** Query suggestions feature configuration. */
|
|
262
|
+
suggestions?: ChatSuggestionsConfig;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Configuration for the chat suggestions feature.
|
|
266
|
+
*
|
|
267
|
+
* @beta
|
|
268
|
+
*/
|
|
269
|
+
export type ChatSuggestionsConfig = {
|
|
270
|
+
/** Suggestions are disabled. */
|
|
271
|
+
behavior: 'never';
|
|
272
|
+
/** Not applicable when behavior is 'never'. */
|
|
273
|
+
count?: never;
|
|
274
|
+
/** Not applicable when behavior is 'never'. */
|
|
275
|
+
prompt?: never;
|
|
276
|
+
} | {
|
|
277
|
+
/**
|
|
278
|
+
* 'initial': Show suggestions on first load before any messages are sent.
|
|
279
|
+
* 'always': Show suggestions after every assistant response.
|
|
280
|
+
*/
|
|
281
|
+
behavior: 'initial' | 'always';
|
|
282
|
+
/**
|
|
283
|
+
* Number of suggestions to generate.
|
|
284
|
+
* @default 3
|
|
285
|
+
*/
|
|
286
|
+
count?: number;
|
|
287
|
+
/**
|
|
288
|
+
* Custom prompt to steer the suggestion generation. If omitted, a
|
|
289
|
+
* default prompt is used.
|
|
290
|
+
*/
|
|
291
|
+
prompt?: string;
|
|
292
|
+
};
|
|
293
|
+
export {};
|
|
157
294
|
//# sourceMappingURL=chat.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.types.d.ts","sourceRoot":"","sources":["../../../src/types/chat.types.ts"],"names":[],"mappings":"AAAA;;;;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M,WAAW,eAAe;IAC9B,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kFAAkF;IAClF,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,2EAA2E;IAC3E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,mEAAmE;IACnE,EAAE,CAAC,EAAE,YAAY,CAAC;IAClB,iFAAiF;IACjF,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,qBAAqB,CAAC;CACrC;AAED;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAC7B;IACE,gCAAgC;IAChC,QAAQ,EAAE,OAAO,CAAC;IAClB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,+CAA+C;IAC/C,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,GACD;IACE;;;OAGG;IACH,QAAQ,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
* @beta
|
|
5
5
|
*/
|
|
6
6
|
export type AIProviderType = 'openai' | 'chrome' | 'gemini' | 'none';
|
|
7
|
+
/**
|
|
8
|
+
* Gemini REST model ids supported by {@link GeminiTransport}.
|
|
9
|
+
*
|
|
10
|
+
* @beta
|
|
11
|
+
*/
|
|
12
|
+
export type GeminiModelId = 'gemini-2.5-flash' | 'gemini-2.5-flash-lite';
|
|
13
|
+
/** @beta */
|
|
14
|
+
export declare const SUPPORTED_GEMINI_MODEL_IDS: readonly GeminiModelId[];
|
|
7
15
|
/**
|
|
8
16
|
* Base provider-level configuration.
|
|
9
17
|
*
|
|
@@ -56,7 +64,8 @@ export interface ChromeAIConfig extends AIProviderConfig {
|
|
|
56
64
|
*/
|
|
57
65
|
export interface GeminiAIConfig extends AIProviderConfig {
|
|
58
66
|
providerType: 'gemini';
|
|
59
|
-
|
|
67
|
+
/** Defaults to `gemini-2.5-flash-lite`. Only {@link SUPPORTED_GEMINI_MODEL_IDS} are accepted at runtime. */
|
|
68
|
+
model?: GeminiModelId;
|
|
60
69
|
serverEndpoint?: string;
|
|
61
70
|
apiKey?: string;
|
|
62
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.types.d.ts","sourceRoot":"","sources":["../../../src/types/config.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAErE;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,6DAA6D;AAC7D,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AAErE;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,QAAQ,EAAE,oBAAoB,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,YAAY,CAAC,EAAE,QAAQ,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,YAAY,EAAE,QAAQ,CAAC;IACvB,KAAK,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"config.types.d.ts","sourceRoot":"","sources":["../../../src/types/config.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAErE;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,kBAAkB,GAAG,uBAAuB,CAAC;AAEzE,YAAY;AACZ,eAAO,MAAM,0BAA0B,EAAE,SAAS,aAAa,EAGrD,CAAC;AAEX;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,6DAA6D;AAC7D,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AAErE;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,QAAQ,EAAE,oBAAoB,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,YAAY,CAAC,EAAE,QAAQ,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,YAAY,EAAE,QAAQ,CAAC;IACvB,4GAA4G;IAC5G,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,cAAc,GAAG,cAAc,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/** Feature flag name for AI functionality (beta). Enable via ?feature.ai in URL. */
|
|
1
|
+
/** Feature flag name for AI functionality (beta). Enable via ?feature.ai in URL or GENX_ENABLE_AI env var. */
|
|
2
2
|
export declare const AI_FEATURE_FLAG = "ai";
|
|
3
|
-
/** Returns true when AI features (beta) are enabled
|
|
3
|
+
/** Returns true when AI features (beta) are enabled via ?feature.ai URL param or GENX_ENABLE_AI=true env var. */
|
|
4
4
|
export declare const isAIFeatureEnabled: () => boolean;
|
|
5
5
|
//# sourceMappingURL=feature-flags.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags.d.ts","sourceRoot":"","sources":["../../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"feature-flags.d.ts","sourceRoot":"","sources":["../../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAEA,8GAA8G;AAC9G,eAAO,MAAM,eAAe,OAAO,CAAC;AAUpC,iHAAiH;AACjH,eAAO,MAAM,kBAAkB,QAAO,OAA6D,CAAC"}
|
package/dist/esm/ai-provider.js
CHANGED
|
@@ -7,6 +7,7 @@ import { OpenAIProvider } from './providers/openai-provider';
|
|
|
7
7
|
import { ChromePromptTransport } from './transports/chrome-prompt-transport';
|
|
8
8
|
import { GeminiTransport } from './transports/gemini-transport';
|
|
9
9
|
import { ServerOpenAITransport } from './transports/server-openai-transport';
|
|
10
|
+
import { SUPPORTED_GEMINI_MODEL_IDS, } from './types';
|
|
10
11
|
import { logger } from './utils';
|
|
11
12
|
import { isAIFeatureEnabled } from './utils/feature-flags';
|
|
12
13
|
function isChromeConfig(config) {
|
|
@@ -74,7 +75,7 @@ export function resolveAIConfig() {
|
|
|
74
75
|
logger.warn('resolveAIConfig: AI feature flag disabled');
|
|
75
76
|
return null;
|
|
76
77
|
}
|
|
77
|
-
const { provider = 'openai', model
|
|
78
|
+
const { provider = 'openai', model, preferChrome = true } = options;
|
|
78
79
|
if (preferChrome) {
|
|
79
80
|
const transport = new ChromePromptTransport();
|
|
80
81
|
const availability = yield transport.getAvailability();
|
|
@@ -86,9 +87,13 @@ export function resolveAIConfig() {
|
|
|
86
87
|
logger.warn('resolveAIConfig: Chrome not available', availability);
|
|
87
88
|
}
|
|
88
89
|
if (provider === 'gemini') {
|
|
89
|
-
|
|
90
|
+
const geminiModel = model !== null && model !== void 0 ? model : 'gemini-2.5-flash-lite';
|
|
91
|
+
if (!SUPPORTED_GEMINI_MODEL_IDS.includes(geminiModel)) {
|
|
92
|
+
throw new Error(`resolveAIConfig: unsupported Gemini model "${geminiModel}". Use one of: ${SUPPORTED_GEMINI_MODEL_IDS.join(', ')}.`);
|
|
93
|
+
}
|
|
94
|
+
return { providerType: 'gemini', model: geminiModel };
|
|
90
95
|
}
|
|
91
|
-
return { provider, model };
|
|
96
|
+
return { provider, model: model !== null && model !== void 0 ? model : 'gpt-4o-mini' };
|
|
92
97
|
});
|
|
93
98
|
}
|
|
94
99
|
/**
|
package/dist/esm/index.js
CHANGED
|
@@ -2,4 +2,6 @@ export { AIProvider, createAIProvider, getAIProvider, resolveAIConfig } from './
|
|
|
2
2
|
export { GeminiProvider } from './providers/gemini-provider';
|
|
3
3
|
export { GeminiTransport, MalformedFunctionCallError } from './transports/gemini-transport';
|
|
4
4
|
export { AI_FEATURE_FLAG, isAIFeatureEnabled } from './utils/feature-flags';
|
|
5
|
+
export { SUPPORTED_GEMINI_MODEL_IDS } from './types';
|
|
6
|
+
export { isChatToolCallUnknown } from './types/chat.types';
|
|
5
7
|
export { isSpeechRecognitionAvailable, startSpeechRecognition } from './utils/speech-to-text';
|
|
@@ -38,6 +38,12 @@ export class GeminiProvider {
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
+
prompt(message, options) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const response = yield this.transport.sendChatMessage([], message, options);
|
|
44
|
+
return response.content;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
41
47
|
chat(history, userMessage, options) {
|
|
42
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
49
|
return this.transport.sendChatMessage(history, userMessage, options);
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
+
import { SUPPORTED_GEMINI_MODEL_IDS, } from '../types';
|
|
3
|
+
import { logger } from '../utils/logger';
|
|
2
4
|
const GEMINI_DIRECT_URL = (model) => `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`;
|
|
3
|
-
const DEFAULT_MODEL = 'gemini-2.
|
|
5
|
+
const DEFAULT_MODEL = 'gemini-2.5-flash-lite';
|
|
4
6
|
const DEFAULT_TIMEOUT = 180000; // 3 minutes
|
|
7
|
+
function assertSupportedGeminiModel(model) {
|
|
8
|
+
if (!SUPPORTED_GEMINI_MODEL_IDS.includes(model)) {
|
|
9
|
+
throw new Error(`GeminiTransport: unsupported model "${model}". Use one of: ${SUPPORTED_GEMINI_MODEL_IDS.join(', ')}.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Paid Standard tier for supported models — https://ai.google.dev/gemini-api/docs/pricing
|
|
14
|
+
*/
|
|
15
|
+
function estimatedGeminiPaidRatesUsdPerMillion(model) {
|
|
16
|
+
if (model === 'gemini-2.5-flash-lite') {
|
|
17
|
+
return { promptPerMillion: 0.1, candidatePerMillion: 0.4 };
|
|
18
|
+
}
|
|
19
|
+
return { promptPerMillion: 0.3, candidatePerMillion: 2.5 };
|
|
20
|
+
}
|
|
5
21
|
/**
|
|
6
22
|
* Thrown when Gemini returns a `MALFORMED_FUNCTION_CALL` finish reason,
|
|
7
23
|
* typically because the model tried to batch multiple tool calls using
|
|
@@ -28,7 +44,12 @@ export class MalformedFunctionCallError extends Error {
|
|
|
28
44
|
export class GeminiTransport {
|
|
29
45
|
constructor(config = {}) {
|
|
30
46
|
var _a, _b;
|
|
31
|
-
|
|
47
|
+
const model = (_a = config.model) !== null && _a !== void 0 ? _a : DEFAULT_MODEL;
|
|
48
|
+
assertSupportedGeminiModel(model);
|
|
49
|
+
this.model = model;
|
|
50
|
+
if (model === 'gemini-2.5-flash') {
|
|
51
|
+
logger.warn('GeminiTransport: using gemini-2.5-flash — higher cost than flash-lite; use for harder reasoning or agent tasks.');
|
|
52
|
+
}
|
|
32
53
|
this.timeout = (_b = config.timeout) !== null && _b !== void 0 ? _b : DEFAULT_TIMEOUT;
|
|
33
54
|
this.apiKey = config.apiKey;
|
|
34
55
|
this.serverEndpoint = config.serverEndpoint;
|
|
@@ -75,11 +96,11 @@ export class GeminiTransport {
|
|
|
75
96
|
});
|
|
76
97
|
}
|
|
77
98
|
logTokenUsage(promptTokens, candidateTokens) {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
99
|
+
const { promptPerMillion, candidatePerMillion } = estimatedGeminiPaidRatesUsdPerMillion(this.model);
|
|
100
|
+
const promptCost = (promptTokens / GeminiTransport.TOKENS_PER_MILLION) * promptPerMillion;
|
|
101
|
+
const candidateCost = (candidateTokens / GeminiTransport.TOKENS_PER_MILLION) * candidatePerMillion;
|
|
81
102
|
const totalCost = promptCost + candidateCost;
|
|
82
|
-
console.log(
|
|
103
|
+
console.log(`--- Gemini Token Usage (${this.model}) ---`);
|
|
83
104
|
console.log(`Prompt Tokens: ${promptTokens} ($${promptCost.toFixed(GeminiTransport.COST_DECIMAL_PLACES)})`);
|
|
84
105
|
console.log(`Candidate Tokens: ${candidateTokens} ($${candidateCost.toFixed(GeminiTransport.COST_DECIMAL_PLACES)})`);
|
|
85
106
|
console.log(`Total Cost: $${totalCost.toFixed(GeminiTransport.COST_DECIMAL_PLACES)}`);
|
|
@@ -89,7 +110,7 @@ export class GeminiTransport {
|
|
|
89
110
|
var _a, _b;
|
|
90
111
|
const contents = [];
|
|
91
112
|
for (const msg of history) {
|
|
92
|
-
if (msg.role === 'system' || msg.thinking)
|
|
113
|
+
if (msg.role === 'system' || msg.role === 'system-event' || msg.thinking)
|
|
93
114
|
continue;
|
|
94
115
|
const role = msg.role === 'user' ? 'user' : 'model';
|
|
95
116
|
if (msg.toolResult) {
|
|
@@ -133,9 +154,13 @@ export class GeminiTransport {
|
|
|
133
154
|
}
|
|
134
155
|
fromGeminiResponse(response) {
|
|
135
156
|
var _a, _b, _c, _d, _e;
|
|
157
|
+
let inputTokens;
|
|
136
158
|
if (response.usageMetadata) {
|
|
137
159
|
const usage = response.usageMetadata;
|
|
138
160
|
this.logTokenUsage((_a = usage.promptTokenCount) !== null && _a !== void 0 ? _a : 0, (_b = usage.candidatesTokenCount) !== null && _b !== void 0 ? _b : 0);
|
|
161
|
+
if (usage.promptTokenCount != null) {
|
|
162
|
+
inputTokens = usage.promptTokenCount;
|
|
163
|
+
}
|
|
139
164
|
}
|
|
140
165
|
const candidates = response === null || response === void 0 ? void 0 : response.candidates;
|
|
141
166
|
const firstCandidate = candidates === null || candidates === void 0 ? void 0 : candidates[0];
|
|
@@ -163,12 +188,17 @@ export class GeminiTransport {
|
|
|
163
188
|
}
|
|
164
189
|
// For tool-call responses, surface thought parts as `content` so the UI can
|
|
165
190
|
// render them as a collapsible thinking block. Fall back to text narration
|
|
166
|
-
// (textParts) for models that don't emit native thought parts (e.g.
|
|
191
|
+
// (textParts) for models that don't emit native thought parts (e.g. some Flash models)
|
|
167
192
|
// but do narrate alongside tool calls when prompted to do so.
|
|
168
193
|
// For final answers, surface only the response text.
|
|
169
|
-
|
|
170
|
-
? {
|
|
194
|
+
const base = toolCalls.length > 0
|
|
195
|
+
? {
|
|
196
|
+
role: 'assistant',
|
|
197
|
+
content: thoughtParts.join('') || textParts.join(''),
|
|
198
|
+
toolCalls,
|
|
199
|
+
}
|
|
171
200
|
: { role: 'assistant', content: textParts.join('') };
|
|
201
|
+
return inputTokens != null ? Object.assign(Object.assign({}, base), { inputTokens }) : base;
|
|
172
202
|
}
|
|
173
203
|
buildEndpoint(body) {
|
|
174
204
|
if (this.apiKey) {
|
|
@@ -241,8 +271,6 @@ export class GeminiTransport {
|
|
|
241
271
|
}
|
|
242
272
|
// ── Private helpers ────────────────────────────────────────────────────
|
|
243
273
|
GeminiTransport.TOKENS_PER_MILLION = 1000000;
|
|
244
|
-
GeminiTransport.PROMPT_COST_PER_MILLION = 0.1;
|
|
245
|
-
GeminiTransport.CANDIDATE_COST_PER_MILLION = 0.4;
|
|
246
274
|
GeminiTransport.COST_DECIMAL_PLACES = 6;
|
|
247
275
|
GeminiTransport.MAX_RETRIES = 5;
|
|
248
276
|
GeminiTransport.RATE_LIMIT_STATUS = 429;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { isFeatureActivated } from '@genesislcap/foundation-utils';
|
|
2
|
-
/** Feature flag name for AI functionality (beta). Enable via ?feature.ai in URL. */
|
|
2
|
+
/** Feature flag name for AI functionality (beta). Enable via ?feature.ai in URL or GENX_ENABLE_AI env var. */
|
|
3
3
|
export const AI_FEATURE_FLAG = 'ai';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
let _envEnabled = false;
|
|
5
|
+
try {
|
|
6
|
+
if (typeof GENX_ENABLE_AI !== 'undefined') {
|
|
7
|
+
_envEnabled = GENX_ENABLE_AI === 'true';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
catch (_a) { }
|
|
11
|
+
/** Returns true when AI features (beta) are enabled via ?feature.ai URL param or GENX_ENABLE_AI=true env var. */
|
|
12
|
+
export const isAIFeatureEnabled = () => _envEnabled || isFeatureActivated(AI_FEATURE_FLAG);
|