@genesislcap/foundation-ai 14.438.0 → 14.439.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/dist/dts/ai-provider.d.ts +9 -3
- package/dist/dts/ai-provider.d.ts.map +1 -1
- package/dist/dts/index.d.ts +5 -2
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/providers/anthropic-provider.d.ts +26 -0
- package/dist/dts/providers/anthropic-provider.d.ts.map +1 -0
- package/dist/dts/transports/anthropic-transport.d.ts +93 -0
- package/dist/dts/transports/anthropic-transport.d.ts.map +1 -0
- package/dist/dts/transports/gemini-transport.d.ts +19 -2
- package/dist/dts/transports/gemini-transport.d.ts.map +1 -1
- package/dist/dts/transports/server-openai-transport.d.ts +1 -0
- package/dist/dts/transports/server-openai-transport.d.ts.map +1 -1
- package/dist/dts/types/chat.types.d.ts +25 -0
- package/dist/dts/types/chat.types.d.ts.map +1 -1
- package/dist/dts/types/config.types.d.ts +33 -2
- package/dist/dts/types/config.types.d.ts.map +1 -1
- package/dist/dts/types/status.types.d.ts +7 -0
- package/dist/dts/types/status.types.d.ts.map +1 -1
- package/dist/dts/types/transports.types.d.ts +22 -0
- package/dist/dts/types/transports.types.d.ts.map +1 -1
- package/dist/esm/ai-provider.js +24 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/providers/anthropic-provider.js +64 -0
- package/dist/esm/providers/gemini-provider.js +1 -1
- package/dist/esm/providers/openai-provider.js +2 -2
- package/dist/esm/transports/anthropic-transport.js +367 -0
- package/dist/esm/transports/gemini-transport.js +50 -3
- package/dist/esm/transports/server-openai-transport.js +16 -1
- package/dist/esm/types/config.types.js +6 -0
- package/dist/foundation-ai.api.json +1351 -7
- package/dist/foundation-ai.d.ts +230 -6
- package/package.json +11 -11
|
@@ -56,9 +56,15 @@ export declare function createAIProvider(config?: AIConfig | null): AIProvider;
|
|
|
56
56
|
* @beta
|
|
57
57
|
*/
|
|
58
58
|
export interface ResolveAIConfigOptions {
|
|
59
|
-
/** Cloud provider (openai, gemini). Default: openai */
|
|
60
|
-
provider?: 'openai' | 'gemini';
|
|
61
|
-
/**
|
|
59
|
+
/** Cloud provider (openai, gemini, anthropic). Default: openai */
|
|
60
|
+
provider?: 'openai' | 'gemini' | 'anthropic';
|
|
61
|
+
/**
|
|
62
|
+
* Model name.
|
|
63
|
+
*
|
|
64
|
+
* - OpenAI default: `gpt-4o-mini`.
|
|
65
|
+
* - Gemini: only {@link SUPPORTED_GEMINI_MODEL_IDS} (default `gemini-2.5-flash-lite`).
|
|
66
|
+
* - Anthropic: only {@link SUPPORTED_ANTHROPIC_MODEL_IDS} (default `claude-haiku-4-5-20251001`).
|
|
67
|
+
*/
|
|
62
68
|
model?: string;
|
|
63
69
|
/** Prefer Chrome built-in AI when available */
|
|
64
70
|
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;
|
|
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;AAU/D,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,QAAQ,EAIb,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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
|
2
|
+
export { AnthropicProvider } from './providers/anthropic-provider';
|
|
2
3
|
export { GeminiProvider } from './providers/gemini-provider';
|
|
4
|
+
export { AnthropicTransport } from './transports/anthropic-transport';
|
|
3
5
|
export { GeminiTransport, MalformedFunctionCallError } from './transports/gemini-transport';
|
|
4
6
|
export { AI_FEATURE_FLAG, isAIFeatureEnabled } from './utils/feature-flags';
|
|
5
|
-
export { SUPPORTED_GEMINI_MODEL_IDS } from './types';
|
|
6
|
-
export type { AIConfig, AIStatus, AIProviderType, ChromeAIConfig, ChromeAvailability, GeminiAIConfig, GeminiModelId, ServerAIConfig, } from './types';
|
|
7
|
+
export { SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS } from './types';
|
|
8
|
+
export type { AIConfig, AIStatus, AIProviderType, AnthropicAIConfig, AnthropicModelId, ChromeAIConfig, ChromeAvailability, GeminiAIConfig, GeminiModelId, ServerAIConfig, } from './types';
|
|
7
9
|
export type { AgentPickerMode, ChatAgentConfig, ChatAgentPickerConfig, ChatAnimationsConfig, ChatAttachment, ChatConfig, ChatDriverResult, ChatInputDuringExecutionMode, ChatMessage, ChatInteraction, ChatRequestOptions, ChatRole, ChatStreamChunk, ChatToolCall, ChatToolCallUnknown, ChatToolDefinition, ChatToolHandlers, ChatToolResult, ChatUiConfig, ChatSuggestionsConfig, InteractionRequestOptions, InteractionResult, SubAgentRequestOptions, } from './types/chat.types';
|
|
8
10
|
export { isChatToolCallUnknown } from './types/chat.types';
|
|
9
11
|
export type { ChatTransport } from './types/chat-transport.types';
|
|
12
|
+
export type { CostReportingTransport } from './types/transports.types';
|
|
10
13
|
export type { ResolveAIConfigOptions } from './ai-provider';
|
|
11
14
|
export type { CriteriaInterpretContext, FieldLike } from './interactions';
|
|
12
15
|
export type { CriteriaClauseResult, CriteriaGroupResult, CriteriaInterpretationResult, } from './types/criteria-types';
|
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,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,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,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AACpF,YAAY,EACV,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,4BAA4B,EAC5B,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,sBAAsB,GACvB,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,0BAA0B,CAAC;AACvE,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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AIProvider } from '../ai-provider';
|
|
2
|
+
import type { CriteriaInterpretContext } from '../interactions';
|
|
3
|
+
import { AnthropicTransport } from '../transports/anthropic-transport';
|
|
4
|
+
import type { AIStatus } from '../types';
|
|
5
|
+
import type { ChatMessage, ChatRequestOptions, ChatStreamChunk } from '../types/chat.types';
|
|
6
|
+
import type { CriteriaInterpretationResult } from '../types/criteria-types';
|
|
7
|
+
export interface AnthropicProviderConfig {
|
|
8
|
+
criteriaInstructions?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Anthropic Claude AI provider. Uses {@link AnthropicTransport} to handle requests.
|
|
12
|
+
* Implements criteria interpretation and multi-turn chat.
|
|
13
|
+
*
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export declare class AnthropicProvider implements AIProvider {
|
|
17
|
+
private readonly transport;
|
|
18
|
+
private readonly criteriaInstructions?;
|
|
19
|
+
constructor(config: AnthropicProviderConfig, transport: AnthropicTransport);
|
|
20
|
+
getStatus(): Promise<AIStatus>;
|
|
21
|
+
interpretCriteria(input: string, context: CriteriaInterpretContext): Promise<CriteriaInterpretationResult | null>;
|
|
22
|
+
prompt(message: string, options?: ChatRequestOptions): Promise<string>;
|
|
23
|
+
chat(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
|
|
24
|
+
streamChat(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): AsyncIterable<ChatStreamChunk>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=anthropic-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-provider.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic-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,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,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,uBAAuB;IACtC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;GAKG;AACH,qBAAa,iBAAkB,YAAW,UAAU;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAS;gBAEnC,MAAM,EAAE,uBAAuB,EAAE,SAAS,EAAE,kBAAkB;IAKpE,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC;IAK9B,iBAAiB,CACrB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC;IAkBzC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,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;CAmBlC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type AITransport, type AnthropicModelId, type CostReportingTransport, type StructuredPromptOptions } from '../types';
|
|
2
|
+
import type { ChatTransport } from '../types/chat-transport.types';
|
|
3
|
+
import type { ChatMessage, ChatRequestOptions } from '../types/chat.types';
|
|
4
|
+
export interface AnthropicTransportConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Defaults to `claude-haiku-4-5-20251001`. Only {@link SUPPORTED_ANTHROPIC_MODEL_IDS}
|
|
7
|
+
* are accepted.
|
|
8
|
+
*/
|
|
9
|
+
model?: AnthropicModelId;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
/**
|
|
12
|
+
* API key for direct calls to the Anthropic API.
|
|
13
|
+
* Must be provided explicitly; callers are responsible for reading it from
|
|
14
|
+
* their environment (e.g. a build-time injected global). When set, requests
|
|
15
|
+
* include `anthropic-dangerous-direct-browser-access: true` so the API
|
|
16
|
+
* accepts the call from a browser origin.
|
|
17
|
+
*/
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Server-proxy endpoint (e.g. `/gwf/ai-service/anthropic/chat`).
|
|
21
|
+
* Only used when no API key is available. When omitted and no API key
|
|
22
|
+
* is found, requests will fail.
|
|
23
|
+
*/
|
|
24
|
+
serverEndpoint?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Hard cap on tokens generated per response. Defaults to 4096.
|
|
27
|
+
*/
|
|
28
|
+
maxTokens?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Transport for Anthropic Claude. Calls the Messages API directly when `apiKey`
|
|
32
|
+
* is provided, otherwise falls back to a server-proxy endpoint (if `serverEndpoint`
|
|
33
|
+
* is configured).
|
|
34
|
+
*
|
|
35
|
+
* Implements `AITransport` (structured prompt via tool-forcing) and `ChatTransport`
|
|
36
|
+
* (multi-turn chat).
|
|
37
|
+
*
|
|
38
|
+
* @beta
|
|
39
|
+
*/
|
|
40
|
+
export declare class AnthropicTransport implements AITransport, ChatTransport, CostReportingTransport {
|
|
41
|
+
private readonly model;
|
|
42
|
+
private readonly timeout;
|
|
43
|
+
private readonly apiKey;
|
|
44
|
+
private readonly serverEndpoint;
|
|
45
|
+
private readonly maxTokens;
|
|
46
|
+
/**
|
|
47
|
+
* Estimated USD cost accumulated across every successful request on this
|
|
48
|
+
* transport instance. Convenience accessor for non-chat consumers
|
|
49
|
+
* (telemetry, debug overlays). The main chat UI sums per-message `cost`
|
|
50
|
+
* fields instead so its session total stays attributed to chat turns only.
|
|
51
|
+
*/
|
|
52
|
+
private lifetimeCostUsd;
|
|
53
|
+
constructor(config?: AnthropicTransportConfig);
|
|
54
|
+
getConfig(): {
|
|
55
|
+
provider: 'anthropic';
|
|
56
|
+
model: AnthropicModelId;
|
|
57
|
+
contextLimit: number;
|
|
58
|
+
};
|
|
59
|
+
/** Estimated USD cost accumulated across every successful request on this transport instance. */
|
|
60
|
+
getLifetimeCost(): number;
|
|
61
|
+
/** Reset the lifetime cost counter. Intended for chat-clear / new-session flows. */
|
|
62
|
+
resetLifetimeCost(): void;
|
|
63
|
+
sendStructuredPrompt(options: StructuredPromptOptions): Promise<string>;
|
|
64
|
+
sendChatMessage(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
|
|
65
|
+
private static readonly TOKENS_PER_MILLION;
|
|
66
|
+
private static readonly COST_DECIMAL_PLACES;
|
|
67
|
+
/**
|
|
68
|
+
* Logs the per-call cost breakdown, accumulates the lifetime running total,
|
|
69
|
+
* and returns the per-call total so the caller can attach it to the response
|
|
70
|
+
* message.
|
|
71
|
+
*/
|
|
72
|
+
private logTokenUsage;
|
|
73
|
+
/**
|
|
74
|
+
* Convert the internal `ChatMessage[]` history into Anthropic's message format.
|
|
75
|
+
*
|
|
76
|
+
* Anthropic alternates strictly `user` / `assistant`. Tool calls are emitted by
|
|
77
|
+
* the assistant as `tool_use` blocks; the corresponding `tool_result` blocks
|
|
78
|
+
* must appear in the *next* user message and reference the tool by `tool_use_id`.
|
|
79
|
+
* Consecutive same-role turns are merged by the API but we merge here to keep
|
|
80
|
+
* the payload tidy.
|
|
81
|
+
*/
|
|
82
|
+
private toAnthropicMessages;
|
|
83
|
+
private fromAnthropicResponse;
|
|
84
|
+
private buildEndpoint;
|
|
85
|
+
private static readonly MAX_RETRIES;
|
|
86
|
+
private static readonly RATE_LIMIT_STATUS;
|
|
87
|
+
private static readonly SERVICE_UNAVAILABLE_STATUS;
|
|
88
|
+
private static readonly OVERLOADED_STATUS;
|
|
89
|
+
private static readonly RETRYABLE_STATUSES;
|
|
90
|
+
private static readonly BACKOFF_BASE_MS;
|
|
91
|
+
private post;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=anthropic-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/anthropic-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,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,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;;;;;;OAQG;IACH,OAAO,CAAC,mBAAmB;IAkE3B,OAAO,CAAC,qBAAqB;IAkD7B,OAAO,CAAC,aAAa;IAgCrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAK;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAO;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,0BAA0B,CAAO;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAO;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAIxC;IACF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAQ;YAEjC,IAAI;CA+CnB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AITransport, type GeminiModelId, type StructuredPromptOptions } from '../types';
|
|
1
|
+
import { type AITransport, type CostReportingTransport, 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 {
|
|
@@ -40,20 +40,37 @@ export declare class MalformedFunctionCallError extends Error {
|
|
|
40
40
|
*
|
|
41
41
|
* @beta
|
|
42
42
|
*/
|
|
43
|
-
export declare class GeminiTransport implements AITransport, ChatTransport {
|
|
43
|
+
export declare class GeminiTransport implements AITransport, ChatTransport, CostReportingTransport {
|
|
44
44
|
private readonly model;
|
|
45
45
|
private readonly timeout;
|
|
46
46
|
private readonly apiKey;
|
|
47
47
|
private readonly serverEndpoint;
|
|
48
|
+
/**
|
|
49
|
+
* Estimated USD cost accumulated across every successful request on this
|
|
50
|
+
* transport instance. Convenience accessor for non-chat consumers
|
|
51
|
+
* (telemetry, debug overlays). The main chat UI sums per-message `cost`
|
|
52
|
+
* fields instead so its session total stays attributed to chat turns only.
|
|
53
|
+
*/
|
|
54
|
+
private lifetimeCostUsd;
|
|
48
55
|
constructor(config?: GeminiTransportConfig);
|
|
49
56
|
getConfig(): {
|
|
50
57
|
provider: 'gemini';
|
|
51
58
|
model: GeminiModelId;
|
|
59
|
+
contextLimit: number;
|
|
52
60
|
};
|
|
61
|
+
/** Estimated USD cost accumulated across every successful request on this transport instance. */
|
|
62
|
+
getLifetimeCost(): number;
|
|
63
|
+
/** Reset the lifetime cost counter. Intended for chat-clear / new-session flows. */
|
|
64
|
+
resetLifetimeCost(): void;
|
|
53
65
|
sendStructuredPrompt(options: StructuredPromptOptions): Promise<string>;
|
|
54
66
|
sendChatMessage(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
|
|
55
67
|
private static readonly TOKENS_PER_MILLION;
|
|
56
68
|
private static readonly COST_DECIMAL_PLACES;
|
|
69
|
+
/**
|
|
70
|
+
* Logs the per-call cost breakdown, accumulates the lifetime running total,
|
|
71
|
+
* and returns the per-call total so the caller can attach it to the response
|
|
72
|
+
* message.
|
|
73
|
+
*/
|
|
57
74
|
private logTokenUsage;
|
|
58
75
|
private toGeminiContents;
|
|
59
76
|
private fromGeminiResponse;
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"file":"gemini-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/gemini-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC7B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CAAC;IA4BvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAa;IACvD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAK;IAEhD;;;;OAIG;IACH,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,gBAAgB;IAwDxB,OAAO,CAAC,kBAAkB;IA0E1B,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,0BAA0B,CAAO;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAGxC;IACF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAQ;YAEjC,IAAI;IAgDlB,OAAO,CAAC,eAAe;CAexB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-openai-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/server-openai-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"server-openai-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/server-openai-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAkBrE,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,qBAAa,qBAAsB,YAAW,WAAW;IACvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,GAAE,2BAAgC;IAKpD,SAAS,IAAI;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE;IAQnE,oBAAoB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC;CAgC9E"}
|
|
@@ -124,6 +124,18 @@ export interface ChatMessage {
|
|
|
124
124
|
* context window utilisation in the UI.
|
|
125
125
|
*/
|
|
126
126
|
inputTokens?: number;
|
|
127
|
+
/**
|
|
128
|
+
* Total output (generated) tokens for the request that produced this message.
|
|
129
|
+
* Set by transports that return usage metadata. Used alongside `cost`.
|
|
130
|
+
*/
|
|
131
|
+
outputTokens?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Estimated USD cost for the single request that produced this message,
|
|
134
|
+
* derived from the active model's input/output rates. Set by transports.
|
|
135
|
+
* Hosts can sum this across the message list to display a running session
|
|
136
|
+
* cost without re-deriving rates.
|
|
137
|
+
*/
|
|
138
|
+
cost?: number;
|
|
127
139
|
}
|
|
128
140
|
/**
|
|
129
141
|
* JSON Schema-based tool definition for function calling.
|
|
@@ -328,6 +340,19 @@ export interface ChatUiConfig {
|
|
|
328
340
|
* - `false` — hidden
|
|
329
341
|
*/
|
|
330
342
|
showContextUsage?: boolean;
|
|
343
|
+
/**
|
|
344
|
+
* Show the running session cost (aggregated USD across all chat turns) in
|
|
345
|
+
* the settings panel.
|
|
346
|
+
* - `true` or `undefined` (default) — shown when cost data is available
|
|
347
|
+
* - `false` — hidden
|
|
348
|
+
*/
|
|
349
|
+
showSessionCost?: boolean;
|
|
350
|
+
/**
|
|
351
|
+
* Show the active model id in the settings panel.
|
|
352
|
+
* - `true` or `undefined` (default) — shown when the provider exposes a model
|
|
353
|
+
* - `false` — hidden
|
|
354
|
+
*/
|
|
355
|
+
showActiveModel?: boolean;
|
|
331
356
|
}
|
|
332
357
|
/**
|
|
333
358
|
* Agent engine configuration for the chat assistant.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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IG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;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;IACpC,gEAAgE;IAChE,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC;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"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @beta
|
|
5
5
|
*/
|
|
6
|
-
export type AIProviderType = 'openai' | 'chrome' | 'gemini' | 'none';
|
|
6
|
+
export type AIProviderType = 'openai' | 'chrome' | 'gemini' | 'anthropic' | 'none';
|
|
7
7
|
/**
|
|
8
8
|
* Gemini REST model ids supported by {@link GeminiTransport}.
|
|
9
9
|
*
|
|
@@ -12,6 +12,14 @@ export type AIProviderType = 'openai' | 'chrome' | 'gemini' | 'none';
|
|
|
12
12
|
export type GeminiModelId = 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-lite';
|
|
13
13
|
/** @beta */
|
|
14
14
|
export declare const SUPPORTED_GEMINI_MODEL_IDS: readonly GeminiModelId[];
|
|
15
|
+
/**
|
|
16
|
+
* Anthropic Messages API model ids supported by {@link AnthropicTransport}.
|
|
17
|
+
*
|
|
18
|
+
* @beta
|
|
19
|
+
*/
|
|
20
|
+
export type AnthropicModelId = 'claude-opus-4-7' | 'claude-sonnet-4-6' | 'claude-haiku-4-5-20251001';
|
|
21
|
+
/** @beta */
|
|
22
|
+
export declare const SUPPORTED_ANTHROPIC_MODEL_IDS: readonly AnthropicModelId[];
|
|
15
23
|
/**
|
|
16
24
|
* Base provider-level configuration.
|
|
17
25
|
*
|
|
@@ -69,11 +77,34 @@ export interface GeminiAIConfig extends AIProviderConfig {
|
|
|
69
77
|
serverEndpoint?: string;
|
|
70
78
|
apiKey?: string;
|
|
71
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Anthropic server-proxy AI configuration (client calls your server; server calls Anthropic).
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* API key stays on the server. URL defaults to `/gwf/ai-service/anthropic/chat`.
|
|
85
|
+
* When `apiKey` is provided, the transport calls `api.anthropic.com/v1/messages` directly
|
|
86
|
+
* (browser direct calls require `anthropic-dangerous-direct-browser-access: true`, which the
|
|
87
|
+
* transport sends automatically — only use this in trusted contexts).
|
|
88
|
+
*
|
|
89
|
+
* @beta
|
|
90
|
+
*/
|
|
91
|
+
export interface AnthropicAIConfig extends AIProviderConfig {
|
|
92
|
+
providerType: 'anthropic';
|
|
93
|
+
/** Defaults to `claude-haiku-4-5-20251001`. Only {@link SUPPORTED_ANTHROPIC_MODEL_IDS} are accepted at runtime. */
|
|
94
|
+
model?: AnthropicModelId;
|
|
95
|
+
serverEndpoint?: string;
|
|
96
|
+
apiKey?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Hard cap on tokens generated per response. Anthropic's `max_tokens` is a required
|
|
99
|
+
* field on every request. Defaults to 4096.
|
|
100
|
+
*/
|
|
101
|
+
maxTokens?: number;
|
|
102
|
+
}
|
|
72
103
|
/**
|
|
73
104
|
* Union type for provider-specific configs.
|
|
74
105
|
* Extend when adding new providers.
|
|
75
106
|
*
|
|
76
107
|
* @beta
|
|
77
108
|
*/
|
|
78
|
-
export type AIConfig = ServerAIConfig | ChromeAIConfig | GeminiAIConfig;
|
|
109
|
+
export type AIConfig = ServerAIConfig | ChromeAIConfig | GeminiAIConfig | AnthropicAIConfig;
|
|
79
110
|
//# sourceMappingURL=config.types.d.ts.map
|
|
@@ -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;
|
|
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,WAAW,GAAG,MAAM,CAAC;AAEnF;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,uBAAuB,CAAC;AAE5F,YAAY;AACZ,eAAO,MAAM,0BAA0B,EAAE,SAAS,aAAa,EAIrD,CAAC;AAEX;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GACxB,iBAAiB,GACjB,mBAAmB,GACnB,2BAA2B,CAAC;AAEhC,YAAY;AACZ,eAAO,MAAM,6BAA6B,EAAE,SAAS,gBAAgB,EAI3D,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;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,YAAY,EAAE,WAAW,CAAC;IAC1B,mHAAmH;IACnH,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,cAAc,GAAG,cAAc,GAAG,iBAAiB,CAAC"}
|
|
@@ -14,5 +14,12 @@ export interface AIStatus {
|
|
|
14
14
|
provider: AIProviderType;
|
|
15
15
|
model: string;
|
|
16
16
|
chromeAvailability?: ChromeAvailability;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum input context window for the active model, in tokens. Used by the
|
|
19
|
+
* chat UI to render context utilisation. Optional — providers without a
|
|
20
|
+
* well-defined limit (e.g. Chrome on-device) leave it undefined and the UI
|
|
21
|
+
* hides the indicator.
|
|
22
|
+
*/
|
|
23
|
+
contextLimit?: number;
|
|
17
24
|
}
|
|
18
25
|
//# sourceMappingURL=status.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.types.d.ts","sourceRoot":"","sources":["../../../src/types/status.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,aAAa,GAAG,cAAc,GAAG,aAAa,CAAC;AAE9F;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"status.types.d.ts","sourceRoot":"","sources":["../../../src/types/status.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,aAAa,GAAG,cAAc,GAAG,aAAa,CAAC;AAE9F;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -18,4 +18,26 @@ export interface AITransport {
|
|
|
18
18
|
sendStructuredPrompt(options: StructuredPromptOptions): Promise<string>;
|
|
19
19
|
isAvailable?(): Promise<boolean>;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Optional capability implemented by transports that can report the estimated
|
|
23
|
+
* USD cost they have incurred over their lifetime.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Surfaces a transport-lifetime running total for non-chat consumers such as
|
|
27
|
+
* telemetry, debug overlays, or admin dashboards. The chat UI deliberately
|
|
28
|
+
* does not depend on this — it sums per-message `cost` fields instead so the
|
|
29
|
+
* session total stays scoped to chat turns and excludes other call sites
|
|
30
|
+
* (suggestions, criteria interpretation, etc.) that share the same transport.
|
|
31
|
+
*
|
|
32
|
+
* Consumers can either accept a `CostReportingTransport` directly or duck-type
|
|
33
|
+
* with `'getLifetimeCost' in transport`.
|
|
34
|
+
*
|
|
35
|
+
* @beta
|
|
36
|
+
*/
|
|
37
|
+
export interface CostReportingTransport {
|
|
38
|
+
/** Estimated USD cost accumulated across every successful request on this transport instance. */
|
|
39
|
+
getLifetimeCost(): number;
|
|
40
|
+
/** Reset the lifetime cost counter. Intended for chat-clear / new-session flows. */
|
|
41
|
+
resetLifetimeCost(): void;
|
|
42
|
+
}
|
|
21
43
|
//# sourceMappingURL=transports.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transports.types.d.ts","sourceRoot":"","sources":["../../../src/types/transports.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,oBAAoB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxE,WAAW,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAClC"}
|
|
1
|
+
{"version":3,"file":"transports.types.d.ts","sourceRoot":"","sources":["../../../src/types/transports.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,oBAAoB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxE,WAAW,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAClC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,sBAAsB;IACrC,iGAAiG;IACjG,eAAe,IAAI,MAAM,CAAC;IAC1B,oFAAoF;IACpF,iBAAiB,IAAI,IAAI,CAAC;CAC3B"}
|
package/dist/esm/ai-provider.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { DI } from '@microsoft/fast-foundation';
|
|
3
|
+
import { AnthropicProvider } from './providers/anthropic-provider';
|
|
3
4
|
import { ChromeProvider } from './providers/chrome-provider';
|
|
4
5
|
import { DefaultAIProvider } from './providers/default-provider';
|
|
5
6
|
import { GeminiProvider } from './providers/gemini-provider';
|
|
6
7
|
import { OpenAIProvider } from './providers/openai-provider';
|
|
8
|
+
import { AnthropicTransport } from './transports/anthropic-transport';
|
|
7
9
|
import { ChromePromptTransport } from './transports/chrome-prompt-transport';
|
|
8
10
|
import { GeminiTransport } from './transports/gemini-transport';
|
|
9
11
|
import { ServerOpenAITransport } from './transports/server-openai-transport';
|
|
10
|
-
import { SUPPORTED_GEMINI_MODEL_IDS, } from './types';
|
|
12
|
+
import { SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS, } from './types';
|
|
11
13
|
import { logger } from './utils';
|
|
12
14
|
import { isAIFeatureEnabled } from './utils/feature-flags';
|
|
13
15
|
function isChromeConfig(config) {
|
|
@@ -16,6 +18,9 @@ function isChromeConfig(config) {
|
|
|
16
18
|
function isGeminiConfig(config) {
|
|
17
19
|
return 'providerType' in config && config.providerType === 'gemini';
|
|
18
20
|
}
|
|
21
|
+
function isAnthropicConfig(config) {
|
|
22
|
+
return 'providerType' in config && config.providerType === 'anthropic';
|
|
23
|
+
}
|
|
19
24
|
function isServerAIConfig(config) {
|
|
20
25
|
return !!config.provider;
|
|
21
26
|
}
|
|
@@ -47,6 +52,17 @@ export function createAIProvider(config) {
|
|
|
47
52
|
});
|
|
48
53
|
return new GeminiProvider({ criteriaInstructions: config.criteriaInstructions }, transport);
|
|
49
54
|
}
|
|
55
|
+
if (config && isAnthropicConfig(config)) {
|
|
56
|
+
logger.debug('createAIProvider: using AnthropicProvider');
|
|
57
|
+
const transport = new AnthropicTransport({
|
|
58
|
+
model: config.model,
|
|
59
|
+
timeout: config.timeout,
|
|
60
|
+
serverEndpoint: config.serverEndpoint,
|
|
61
|
+
apiKey: config.apiKey,
|
|
62
|
+
maxTokens: config.maxTokens,
|
|
63
|
+
});
|
|
64
|
+
return new AnthropicProvider({ criteriaInstructions: config.criteriaInstructions }, transport);
|
|
65
|
+
}
|
|
50
66
|
if (config && isServerAIConfig(config)) {
|
|
51
67
|
if (config.provider !== 'openai') {
|
|
52
68
|
logger.warn('createAIProvider: only openai server provider supported for now, using default');
|
|
@@ -93,6 +109,13 @@ export function resolveAIConfig() {
|
|
|
93
109
|
}
|
|
94
110
|
return { providerType: 'gemini', model: geminiModel };
|
|
95
111
|
}
|
|
112
|
+
if (provider === 'anthropic') {
|
|
113
|
+
const anthropicModel = model !== null && model !== void 0 ? model : 'claude-haiku-4-5-20251001';
|
|
114
|
+
if (!SUPPORTED_ANTHROPIC_MODEL_IDS.includes(anthropicModel)) {
|
|
115
|
+
throw new Error(`resolveAIConfig: unsupported Anthropic model "${anthropicModel}". Use one of: ${SUPPORTED_ANTHROPIC_MODEL_IDS.join(', ')}.`);
|
|
116
|
+
}
|
|
117
|
+
return { providerType: 'anthropic', model: anthropicModel };
|
|
118
|
+
}
|
|
96
119
|
return { provider, model: model !== null && model !== void 0 ? model : 'gpt-4o-mini' };
|
|
97
120
|
});
|
|
98
121
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { AIProvider, createAIProvider, getAIProvider, resolveAIConfig } from './ai-provider';
|
|
2
|
+
export { AnthropicProvider } from './providers/anthropic-provider';
|
|
2
3
|
export { GeminiProvider } from './providers/gemini-provider';
|
|
4
|
+
export { AnthropicTransport } from './transports/anthropic-transport';
|
|
3
5
|
export { GeminiTransport, MalformedFunctionCallError } from './transports/gemini-transport';
|
|
4
6
|
export { AI_FEATURE_FLAG, isAIFeatureEnabled } from './utils/feature-flags';
|
|
5
|
-
export { SUPPORTED_GEMINI_MODEL_IDS } from './types';
|
|
7
|
+
export { SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS } from './types';
|
|
6
8
|
export { isChatToolCallUnknown } from './types/chat.types';
|
|
7
9
|
export { isSpeechRecognitionAvailable, startSpeechRecognition } from './utils/speech-to-text';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { __asyncDelegator, __asyncGenerator, __asyncValues, __await, __awaiter } from "tslib";
|
|
2
|
+
import { buildCriteriaSystemPrompt, buildCriteriaUserPrompt, CRITERIA_JSON_SCHEMA, parseCriteriaResponse, } from '../interactions';
|
|
3
|
+
import { logger } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Anthropic Claude AI provider. Uses {@link AnthropicTransport} to handle requests.
|
|
6
|
+
* Implements criteria interpretation and multi-turn chat.
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export class AnthropicProvider {
|
|
11
|
+
constructor(config, transport) {
|
|
12
|
+
this.transport = transport;
|
|
13
|
+
this.criteriaInstructions = config.criteriaInstructions;
|
|
14
|
+
}
|
|
15
|
+
getStatus() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const config = this.transport.getConfig();
|
|
18
|
+
return { provider: 'anthropic', model: config.model, contextLimit: config.contextLimit };
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
interpretCriteria(input, context) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
24
|
+
const fields = (_a = context === null || context === void 0 ? void 0 : context.fields) !== null && _a !== void 0 ? _a : [];
|
|
25
|
+
const systemPrompt = buildCriteriaSystemPrompt(fields, this.criteriaInstructions);
|
|
26
|
+
const userPrompt = buildCriteriaUserPrompt(input);
|
|
27
|
+
try {
|
|
28
|
+
const raw = yield this.transport.sendStructuredPrompt({
|
|
29
|
+
systemPrompt,
|
|
30
|
+
userPrompt,
|
|
31
|
+
responseSchema: CRITERIA_JSON_SCHEMA,
|
|
32
|
+
});
|
|
33
|
+
return parseCriteriaResponse(raw);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
logger.error('AnthropicProvider interpretCriteria failed:', e);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
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
|
+
}
|
|
47
|
+
chat(history, userMessage, options) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return this.transport.sendChatMessage(history, userMessage, options);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
streamChat(history, userMessage, options) {
|
|
53
|
+
return __asyncGenerator(this, arguments, function* streamChat_1() {
|
|
54
|
+
if ('streamChatMessage' in this.transport &&
|
|
55
|
+
typeof this.transport.streamChatMessage === 'function') {
|
|
56
|
+
yield __await(yield* __asyncDelegator(__asyncValues(this.transport.streamChatMessage(history, userMessage, options))));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const msg = yield __await(this.transport.sendChatMessage(history, userMessage, options));
|
|
60
|
+
yield yield __await({ delta: msg.content, done: true, toolCalls: msg.toolCalls });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -15,7 +15,7 @@ export class GeminiProvider {
|
|
|
15
15
|
getStatus() {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
17
|
const config = this.transport.getConfig();
|
|
18
|
-
return { provider: 'gemini', model: config.model };
|
|
18
|
+
return { provider: 'gemini', model: config.model, contextLimit: config.contextLimit };
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
interpretCriteria(input, context) {
|
|
@@ -20,8 +20,8 @@ export class OpenAIProvider {
|
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
const config = this.transport instanceof ServerOpenAITransport
|
|
22
22
|
? this.transport.getConfig()
|
|
23
|
-
: { provider: 'openai', model: 'gpt-4o-mini' };
|
|
24
|
-
return { provider: 'openai', model: config.model };
|
|
23
|
+
: { provider: 'openai', model: 'gpt-4o-mini', contextLimit: undefined };
|
|
24
|
+
return { provider: 'openai', model: config.model, contextLimit: config.contextLimit };
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
interpretCriteria(input, context) {
|