@hiper2d/ai-agents 0.15.0 → 0.16.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 +3 -3
- package/dist/index.d.mts +26 -13
- package/dist/index.d.ts +26 -13
- package/dist/index.js +50 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -69,10 +69,10 @@ const { audio, costUSD } = await voice.speak({ text: 'Night falls.', voice: 'Kor
|
|
|
69
69
|
const { text } = await voice.transcribe({ audio: recording, mimeType: 'audio/webm' });
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
`openai` runs gpt-4o-mini-tts + Whisper, `google` runs Gemini 3.
|
|
72
|
+
`openai` runs gpt-4o-mini-tts + Whisper, `google` runs Gemini 3.8 Flash-Lite TTS + Gemini 3.5
|
|
73
73
|
Transcribe (`VOICE_MODEL_CONSTANTS`, prices in `VOICE_MODEL_PRICING`). The `voiceStyle`
|
|
74
|
-
direction works for both providers: OpenAI takes it as instructions, Gemini
|
|
75
|
-
|
|
74
|
+
direction works for both providers: OpenAI takes it as instructions, Gemini as the part's
|
|
75
|
+
`speechMetadata.style` (3.8 TTS reads the text verbatim, so no inline "Say X:" prefix).
|
|
76
76
|
|
|
77
77
|
### Images and portrait sheets (`@hiper2d/ai-agents/images`)
|
|
78
78
|
|
package/dist/index.d.mts
CHANGED
|
@@ -907,6 +907,8 @@ interface SpeechResult {
|
|
|
907
907
|
audio: ArrayBuffer;
|
|
908
908
|
costUSD: number;
|
|
909
909
|
usage: SpeechUsage;
|
|
910
|
+
/** Gemini only: the styled request was safety-blocked, so the line was read without its style. */
|
|
911
|
+
styleDropped?: boolean;
|
|
910
912
|
}
|
|
911
913
|
interface TranscriptionRequest {
|
|
912
914
|
audio: ArrayBuffer;
|
|
@@ -943,7 +945,7 @@ interface VoiceAgent {
|
|
|
943
945
|
declare const VOICE_MODEL_CONSTANTS: {
|
|
944
946
|
readonly OPENAI_TTS: "gpt-4o-mini-tts";
|
|
945
947
|
readonly OPENAI_STT: "whisper-1";
|
|
946
|
-
readonly GOOGLE_TTS: "gemini-3.
|
|
948
|
+
readonly GOOGLE_TTS: "gemini-3.8-flash-lite-tts";
|
|
947
949
|
readonly GOOGLE_STT: "gemini-3.5-transcribe";
|
|
948
950
|
};
|
|
949
951
|
declare const SUPPORTED_VOICE_PROVIDERS: readonly VoiceProvider[];
|
|
@@ -1006,7 +1008,7 @@ declare class OpenAiVoiceAgent implements VoiceAgent {
|
|
|
1006
1008
|
declare class GoogleVoiceAgent implements VoiceAgent {
|
|
1007
1009
|
private readonly apiKey;
|
|
1008
1010
|
readonly provider: "google";
|
|
1009
|
-
readonly ttsModel: "gemini-3.
|
|
1011
|
+
readonly ttsModel: "gemini-3.8-flash-lite-tts";
|
|
1010
1012
|
readonly sttModel: "gemini-3.5-transcribe";
|
|
1011
1013
|
constructor(apiKey: string);
|
|
1012
1014
|
speak(request: SpeechRequest): Promise<SpeechResult>;
|
|
@@ -1042,7 +1044,7 @@ declare function transcribeWithOpenAi(audioBuffer: ArrayBuffer, apiKey: string,
|
|
|
1042
1044
|
interface GoogleTtsAudioOptions {
|
|
1043
1045
|
/** e.g. "Kore", "Puck" */
|
|
1044
1046
|
voiceName: string;
|
|
1045
|
-
/** "mysteriously", "excitedly", or a longer direction */
|
|
1047
|
+
/** "mysteriously", "excitedly", or a longer direction; sent as speechMetadata.style */
|
|
1046
1048
|
voiceStyle?: string;
|
|
1047
1049
|
}
|
|
1048
1050
|
interface GoogleTtsResult {
|
|
@@ -1053,15 +1055,16 @@ interface GoogleTtsResult {
|
|
|
1053
1055
|
inputTokens: number;
|
|
1054
1056
|
outputTokens: number;
|
|
1055
1057
|
};
|
|
1058
|
+
/** True when the styled request was safety-blocked and the line was read without its style. */
|
|
1059
|
+
styleDropped?: boolean;
|
|
1056
1060
|
}
|
|
1057
1061
|
/**
|
|
1058
|
-
* Gemini TTS
|
|
1059
|
-
*
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
1062
|
-
* value feeds OpenAI's `instructions`, so one field serves both providers.
|
|
1062
|
+
* Gemini 3.8 TTS reads the part text as a verbatim transcript: an inline
|
|
1063
|
+
* "Say cheerfully:" prefix (the 3.1 convention) may be spoken aloud. Delivery
|
|
1064
|
+
* direction goes in the part's `speechMetadata.style` instead, short adverb or
|
|
1065
|
+
* longer sentence alike. Trailing punctuation is trimmed; blank means none.
|
|
1063
1066
|
*/
|
|
1064
|
-
declare function
|
|
1067
|
+
declare function normalizeTtsStyle(voiceStyle?: string): string | undefined;
|
|
1065
1068
|
/** Wraps raw 16-bit mono PCM in a WAV header. */
|
|
1066
1069
|
declare function pcmToWav(pcmData: Uint8Array, sampleRate?: number): ArrayBuffer;
|
|
1067
1070
|
/**
|
|
@@ -1071,12 +1074,22 @@ declare function pcmToWav(pcmData: Uint8Array, sampleRate?: number): ArrayBuffer
|
|
|
1071
1074
|
* difference between a diagnosable log line and "no audio data".
|
|
1072
1075
|
*/
|
|
1073
1076
|
declare function describeEmptyTtsResponse(response: any): string;
|
|
1077
|
+
/**
|
|
1078
|
+
* A safety block on the prompt or the candidate. The 3.1 preview model
|
|
1079
|
+
* false-positived on volume directions ("Say quietly: <harmless line>" blocked
|
|
1080
|
+
* 4 of 6 on 2026-09-24); 3.8 Flash-Lite with the style in speechMetadata passed
|
|
1081
|
+
* the same lines 9 of 9, but the fallback below stays as a net.
|
|
1082
|
+
*/
|
|
1083
|
+
declare function isSafetyBlocked(response: any): boolean;
|
|
1074
1084
|
/**
|
|
1075
1085
|
* Core Gemini TTS call: text + API key in, WAV + token usage out.
|
|
1076
1086
|
*
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
1079
|
-
*
|
|
1087
|
+
* 3.8 TTS returns WAV with a RIFF header by default (3.1 returned headerless
|
|
1088
|
+
* audio/l16); raw PCM is still wrapped if a response ever carries it.
|
|
1089
|
+
*
|
|
1090
|
+
* When a styled request comes back safety-blocked, the line is read once more
|
|
1091
|
+
* without the style: a block on the direction should not silence the line. An
|
|
1092
|
+
* unstyled block is not repeated.
|
|
1080
1093
|
*/
|
|
1081
1094
|
declare function generateGoogleTtsAudio(text: string, apiKey: string, options: GoogleTtsAudioOptions): Promise<GoogleTtsResult>;
|
|
1082
1095
|
|
|
@@ -1791,4 +1804,4 @@ declare class MiniMaxAgent extends AbstractAgent {
|
|
|
1791
1804
|
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1792
1805
|
}
|
|
1793
1806
|
|
|
1794
|
-
export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend,
|
|
1807
|
+
export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -907,6 +907,8 @@ interface SpeechResult {
|
|
|
907
907
|
audio: ArrayBuffer;
|
|
908
908
|
costUSD: number;
|
|
909
909
|
usage: SpeechUsage;
|
|
910
|
+
/** Gemini only: the styled request was safety-blocked, so the line was read without its style. */
|
|
911
|
+
styleDropped?: boolean;
|
|
910
912
|
}
|
|
911
913
|
interface TranscriptionRequest {
|
|
912
914
|
audio: ArrayBuffer;
|
|
@@ -943,7 +945,7 @@ interface VoiceAgent {
|
|
|
943
945
|
declare const VOICE_MODEL_CONSTANTS: {
|
|
944
946
|
readonly OPENAI_TTS: "gpt-4o-mini-tts";
|
|
945
947
|
readonly OPENAI_STT: "whisper-1";
|
|
946
|
-
readonly GOOGLE_TTS: "gemini-3.
|
|
948
|
+
readonly GOOGLE_TTS: "gemini-3.8-flash-lite-tts";
|
|
947
949
|
readonly GOOGLE_STT: "gemini-3.5-transcribe";
|
|
948
950
|
};
|
|
949
951
|
declare const SUPPORTED_VOICE_PROVIDERS: readonly VoiceProvider[];
|
|
@@ -1006,7 +1008,7 @@ declare class OpenAiVoiceAgent implements VoiceAgent {
|
|
|
1006
1008
|
declare class GoogleVoiceAgent implements VoiceAgent {
|
|
1007
1009
|
private readonly apiKey;
|
|
1008
1010
|
readonly provider: "google";
|
|
1009
|
-
readonly ttsModel: "gemini-3.
|
|
1011
|
+
readonly ttsModel: "gemini-3.8-flash-lite-tts";
|
|
1010
1012
|
readonly sttModel: "gemini-3.5-transcribe";
|
|
1011
1013
|
constructor(apiKey: string);
|
|
1012
1014
|
speak(request: SpeechRequest): Promise<SpeechResult>;
|
|
@@ -1042,7 +1044,7 @@ declare function transcribeWithOpenAi(audioBuffer: ArrayBuffer, apiKey: string,
|
|
|
1042
1044
|
interface GoogleTtsAudioOptions {
|
|
1043
1045
|
/** e.g. "Kore", "Puck" */
|
|
1044
1046
|
voiceName: string;
|
|
1045
|
-
/** "mysteriously", "excitedly", or a longer direction */
|
|
1047
|
+
/** "mysteriously", "excitedly", or a longer direction; sent as speechMetadata.style */
|
|
1046
1048
|
voiceStyle?: string;
|
|
1047
1049
|
}
|
|
1048
1050
|
interface GoogleTtsResult {
|
|
@@ -1053,15 +1055,16 @@ interface GoogleTtsResult {
|
|
|
1053
1055
|
inputTokens: number;
|
|
1054
1056
|
outputTokens: number;
|
|
1055
1057
|
};
|
|
1058
|
+
/** True when the styled request was safety-blocked and the line was read without its style. */
|
|
1059
|
+
styleDropped?: boolean;
|
|
1056
1060
|
}
|
|
1057
1061
|
/**
|
|
1058
|
-
* Gemini TTS
|
|
1059
|
-
*
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
1062
|
-
* value feeds OpenAI's `instructions`, so one field serves both providers.
|
|
1062
|
+
* Gemini 3.8 TTS reads the part text as a verbatim transcript: an inline
|
|
1063
|
+
* "Say cheerfully:" prefix (the 3.1 convention) may be spoken aloud. Delivery
|
|
1064
|
+
* direction goes in the part's `speechMetadata.style` instead, short adverb or
|
|
1065
|
+
* longer sentence alike. Trailing punctuation is trimmed; blank means none.
|
|
1063
1066
|
*/
|
|
1064
|
-
declare function
|
|
1067
|
+
declare function normalizeTtsStyle(voiceStyle?: string): string | undefined;
|
|
1065
1068
|
/** Wraps raw 16-bit mono PCM in a WAV header. */
|
|
1066
1069
|
declare function pcmToWav(pcmData: Uint8Array, sampleRate?: number): ArrayBuffer;
|
|
1067
1070
|
/**
|
|
@@ -1071,12 +1074,22 @@ declare function pcmToWav(pcmData: Uint8Array, sampleRate?: number): ArrayBuffer
|
|
|
1071
1074
|
* difference between a diagnosable log line and "no audio data".
|
|
1072
1075
|
*/
|
|
1073
1076
|
declare function describeEmptyTtsResponse(response: any): string;
|
|
1077
|
+
/**
|
|
1078
|
+
* A safety block on the prompt or the candidate. The 3.1 preview model
|
|
1079
|
+
* false-positived on volume directions ("Say quietly: <harmless line>" blocked
|
|
1080
|
+
* 4 of 6 on 2026-09-24); 3.8 Flash-Lite with the style in speechMetadata passed
|
|
1081
|
+
* the same lines 9 of 9, but the fallback below stays as a net.
|
|
1082
|
+
*/
|
|
1083
|
+
declare function isSafetyBlocked(response: any): boolean;
|
|
1074
1084
|
/**
|
|
1075
1085
|
* Core Gemini TTS call: text + API key in, WAV + token usage out.
|
|
1076
1086
|
*
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
1079
|
-
*
|
|
1087
|
+
* 3.8 TTS returns WAV with a RIFF header by default (3.1 returned headerless
|
|
1088
|
+
* audio/l16); raw PCM is still wrapped if a response ever carries it.
|
|
1089
|
+
*
|
|
1090
|
+
* When a styled request comes back safety-blocked, the line is read once more
|
|
1091
|
+
* without the style: a block on the direction should not silence the line. An
|
|
1092
|
+
* unstyled block is not repeated.
|
|
1080
1093
|
*/
|
|
1081
1094
|
declare function generateGoogleTtsAudio(text: string, apiKey: string, options: GoogleTtsAudioOptions): Promise<GoogleTtsResult>;
|
|
1082
1095
|
|
|
@@ -1791,4 +1804,4 @@ declare class MiniMaxAgent extends AbstractAgent {
|
|
|
1791
1804
|
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1792
1805
|
}
|
|
1793
1806
|
|
|
1794
|
-
export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend,
|
|
1807
|
+
export { type AIMessage, ANTHROPIC_REASONING_EFFORTS, API_KEY_CONSTANTS, AbstractAgent, type AgentActivityData, AgentFactory, type AgentLoggingConfig, type AnthropicReasoningEffort, type AnthropicTokenUsage, type ApiKeyMap, type BeforeAskHook, BotResponseError, BudgetController, type BudgetControllerOptions, BudgetExceededError, type BudgetLimit, type BudgetVerdict, CACHE_TIER_MARKER, ClaudeAgent, type CostCalculationOptions, DEEPSEEK_PEAK_SCHEDULE, DEEPSEEK_REASONING_EFFORTS, DEFAULT_LOGGING_CONFIG, DEFAULT_MAX_OUTPUT_TOKENS, type DeepSeekReasoningEffort, type DeepSeekTokenUsage, DeepSeekV2Agent, FUGU_REASONING_EFFORTS, FuguAgent, type FuguReasoningEffort, GEMINI_AUDIO_TOKENS_PER_SECOND, GEMINI_REASONING_EFFORTS, GLM_REASONING_EFFORTS, type GeminiReasoningEffort, GlmAgent, type GlmReasoningEffort, GoogleAgent, type GoogleSttOptions, type GoogleSttResult, type GoogleTokenUsage, type GoogleTtsAudioOptions, type GoogleTtsResult, GoogleVoiceAgent, Gpt5Agent, GrokAgent, type GrokTokenUsage, InMemorySpendStore, type JsonSchemaOptions, KIMI_REASONING_EFFORTS, KimiAgent, type KimiReasoningEffort, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MISTRAL_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, type MistralReasoningEffort, type MistralTokenUsage, type Modality, ModelAuthenticationError, type ModelConfig, ModelError, ModelInvalidResponseError, ModelOverloadError, type ModelPricing, ModelQuotaExceededError, ModelRateLimitError, ModelRefusalError, type ModelTag, ModelUnavailableError, OPENAI_REASONING_EFFORTS, type OpenAIReasoningEffort, type OpenAITokenUsage, type OpenAiSttOptions, type OpenAiSttResult, type OpenAiTtsAudioOptions, type OpenAiTtsVoice, OpenAiVoiceAgent, type PeakPricing, type PricingUnit, type ProviderSchema, type TokenUsage as ProviderTokenUsage, type ProviderType, QwenAgent, REASONING_EFFORT_SCALE, type ReasoningEffort, SUPPORTED_VOICE_PROVIDERS, type SpeechRequest, type SpeechResult, type SpeechUsage, type SpendInput, type SpendKind, type SpendLedger, type SpendLedgers, type SpendStore, type SpendWindow, SupportedAiKeyNames, SupportedAiModels, type TokenPairUsage, type TokenUsage$1 as TokenUsage, type TranscriptionRequest, type TranscriptionResult, type TranscriptionUsage, VOICE_MODEL_CONSTANTS, VOICE_MODEL_PRICING, VOICE_PROVIDER_API_KEY, type VoiceAgent, VoiceAgentFactory, type VoiceModelPricing, type VoiceProvider, XAI_REASONING_EFFORTS, type XaiReasoningEffort, ZodSchemaConverter, applySpend, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, describeEmptyTtsResponse, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$6 as extractDeepSeekTokenUsageFromResponse, extractFirstJsonObject, extractGoogleTokenUsage, extractTokenUsageFromResponse$1 as extractGoogleTokenUsageFromResponse, extractGrokTokenUsage, extractTokenUsageFromResponse$4 as extractGrokTokenUsageFromResponse, extractKimiTokenUsage, extractTokenUsageFromResponse$5 as extractKimiTokenUsageFromResponse, extractMetaTokenUsage, extractTokenUsageFromResponse$3 as extractMetaTokenUsageFromResponse, extractMistralTokenUsage, extractTokenUsageFromResponse as extractMistralTokenUsageFromResponse, extractOpenAITokenUsage, extractTokenUsageFromResponse$7 as extractOpenAITokenUsageFromResponse, extractTokenUsage, extractUsageAndCalculateCost, firstRefusal, generateGoogleTtsAudio, generateOpenAiTtsAudio, generateSchemaInstructions, getModelConfigByApiName, getModelDisplayName, getModelProviderName, getModelTags, getProviderSignatureFields, isBudgetExceededError, isHybridThinkingModel, isInPeakWindow, isPeakBilling, isSafetyBlocked, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, normalizeTtsStyle, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toKimiEffort, toMetaEffort, toMistralEffort, toOpenAIEffort, toXaiEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
|
package/dist/index.js
CHANGED
|
@@ -87,7 +87,6 @@ __export(src_exports, {
|
|
|
87
87
|
XAI_REASONING_EFFORTS: () => XAI_REASONING_EFFORTS,
|
|
88
88
|
ZodSchemaConverter: () => ZodSchemaConverter,
|
|
89
89
|
applySpend: () => applySpend,
|
|
90
|
-
buildGoogleTtsPrompt: () => buildGoogleTtsPrompt,
|
|
91
90
|
calculateAnthropicCost: () => calculateAnthropicCost,
|
|
92
91
|
calculateCost: () => calculateCost,
|
|
93
92
|
calculateDeepSeekCost: () => calculateDeepSeekCost,
|
|
@@ -140,6 +139,7 @@ __export(src_exports, {
|
|
|
140
139
|
isHybridThinkingModel: () => isHybridThinkingModel,
|
|
141
140
|
isInPeakWindow: () => isInPeakWindow,
|
|
142
141
|
isPeakBilling: () => isPeakBilling,
|
|
142
|
+
isSafetyBlocked: () => isSafetyBlocked,
|
|
143
143
|
isWeekendAt: () => isWeekendAt,
|
|
144
144
|
ledgerSpend: () => ledgerSpend,
|
|
145
145
|
logger: () => logger,
|
|
@@ -147,6 +147,7 @@ __export(src_exports, {
|
|
|
147
147
|
modelHasTag: () => modelHasTag,
|
|
148
148
|
modelIsFast: () => modelIsFast,
|
|
149
149
|
needsPromptBasedSchema: () => needsPromptBasedSchema,
|
|
150
|
+
normalizeTtsStyle: () => normalizeTtsStyle,
|
|
150
151
|
parseAndValidateLlmJson: () => parseAndValidateLlmJson,
|
|
151
152
|
pcmToWav: () => pcmToWav,
|
|
152
153
|
periodEnd: () => periodEnd,
|
|
@@ -1931,8 +1932,9 @@ function extractTokenUsageFromResponse8(response) {
|
|
|
1931
1932
|
var VOICE_MODEL_CONSTANTS = {
|
|
1932
1933
|
OPENAI_TTS: "gpt-4o-mini-tts",
|
|
1933
1934
|
OPENAI_STT: "whisper-1",
|
|
1934
|
-
// ai.google.dev/gemini-api/docs/speech-generation
|
|
1935
|
-
|
|
1935
|
+
// ai.google.dev/gemini-api/docs/speech-generation — Google's named replacement
|
|
1936
|
+
// for gemini-3.1-flash-tts-preview (2026-09-24: ~6 s vs ~15 s per line, ~4x cheaper)
|
|
1937
|
+
GOOGLE_TTS: "gemini-3.8-flash-lite-tts",
|
|
1936
1938
|
// ai.google.dev/gemini-api/docs/transcribe — Interactions API only (see google-stt.ts)
|
|
1937
1939
|
GOOGLE_STT: "gemini-3.5-transcribe"
|
|
1938
1940
|
};
|
|
@@ -1944,9 +1946,9 @@ var VOICE_PROVIDER_API_KEY = {
|
|
|
1944
1946
|
var VOICE_MODEL_PRICING = {
|
|
1945
1947
|
[VOICE_MODEL_CONSTANTS.OPENAI_TTS]: { pricePerMillionCharacters: 15 },
|
|
1946
1948
|
[VOICE_MODEL_CONSTANTS.OPENAI_STT]: { pricePerMinute: 6e-3 },
|
|
1947
|
-
//
|
|
1948
|
-
//
|
|
1949
|
-
[VOICE_MODEL_CONSTANTS.GOOGLE_TTS]: { textInputPricePerM:
|
|
1949
|
+
// ~32 audio tokens per second of speech, so a 15-second line is ~$0.003.
|
|
1950
|
+
// Google doubles both rates to $1 / $12 on 2027-01-01 — update then.
|
|
1951
|
+
[VOICE_MODEL_CONSTANTS.GOOGLE_TTS]: { textInputPricePerM: 0.5, audioOutputPricePerM: 6 },
|
|
1950
1952
|
// ~25 audio tokens per second in, ~175 text tokens per minute out: ≈ $0.005/min.
|
|
1951
1953
|
[VOICE_MODEL_CONSTANTS.GOOGLE_STT]: { audioInputPricePerM: 2, textOutputPricePerM: 12 }
|
|
1952
1954
|
};
|
|
@@ -2053,12 +2055,10 @@ var import_genai = require("@google/genai");
|
|
|
2053
2055
|
var AUDIO_TOKENS_PER_SECOND = 32;
|
|
2054
2056
|
var SAMPLE_RATE = 24e3;
|
|
2055
2057
|
var PCM_BYTES_PER_SECOND = SAMPLE_RATE * 2;
|
|
2056
|
-
|
|
2058
|
+
var WAV_HEADER_BYTES = 44;
|
|
2059
|
+
function normalizeTtsStyle(voiceStyle) {
|
|
2057
2060
|
const style = voiceStyle?.trim().replace(/[:.!,;\s]+$/, "");
|
|
2058
|
-
|
|
2059
|
-
const isShort = style.split(/\s+/).length <= 3 && !/[.!?,;]/.test(style);
|
|
2060
|
-
return isShort ? `Say ${style}: ${text}` : `${style}:
|
|
2061
|
-
${text}`;
|
|
2061
|
+
return style || void 0;
|
|
2062
2062
|
}
|
|
2063
2063
|
function pcmToWav(pcmData, sampleRate = SAMPLE_RATE) {
|
|
2064
2064
|
const numChannels = 1;
|
|
@@ -2102,28 +2102,51 @@ function describeEmptyTtsResponse(response) {
|
|
|
2102
2102
|
if (!parts.length) bits.push("no parts");
|
|
2103
2103
|
return bits.join(", ");
|
|
2104
2104
|
}
|
|
2105
|
+
function isSafetyBlocked(response) {
|
|
2106
|
+
const finish = response?.candidates?.[0]?.finishReason;
|
|
2107
|
+
return finish === "SAFETY" || finish === "PROHIBITED_CONTENT" || !!response?.promptFeedback?.blockReason;
|
|
2108
|
+
}
|
|
2109
|
+
function findAudioPart(response) {
|
|
2110
|
+
const parts = response?.candidates?.[0]?.content?.parts ?? [];
|
|
2111
|
+
const inline = parts.find((part) => part.inlineData?.mimeType?.startsWith("audio/") && part.inlineData?.data)?.inlineData;
|
|
2112
|
+
return inline ? { data: inline.data, mimeType: inline.mimeType } : void 0;
|
|
2113
|
+
}
|
|
2105
2114
|
async function generateGoogleTtsAudio(text, apiKey, options) {
|
|
2106
2115
|
const client = new import_genai.GoogleGenAI({ apiKey });
|
|
2107
|
-
const
|
|
2116
|
+
const request = (style2) => client.models.generateContent({
|
|
2108
2117
|
model: VOICE_MODEL_CONSTANTS.GOOGLE_TTS,
|
|
2109
|
-
contents: [{ parts: [{ text:
|
|
2118
|
+
contents: [{ parts: [style2 ? { text, speechMetadata: { style: style2 } } : { text }] }],
|
|
2110
2119
|
config: {
|
|
2111
2120
|
responseModalities: ["AUDIO"],
|
|
2112
2121
|
speechConfig: { voiceConfig: { prebuiltVoiceConfig: { voiceName: options.voiceName } } }
|
|
2113
2122
|
}
|
|
2114
2123
|
});
|
|
2115
|
-
const
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2124
|
+
const style = normalizeTtsStyle(options.voiceStyle);
|
|
2125
|
+
let response = await request(style);
|
|
2126
|
+
let styleDropped = false;
|
|
2127
|
+
let blockedInputTokens = 0;
|
|
2128
|
+
if (!findAudioPart(response) && style && isSafetyBlocked(response)) {
|
|
2129
|
+
blockedInputTokens = response?.usageMetadata?.promptTokenCount ?? 0;
|
|
2130
|
+
response = await request(void 0);
|
|
2131
|
+
styleDropped = true;
|
|
2132
|
+
}
|
|
2133
|
+
const audioPart = findAudioPart(response);
|
|
2134
|
+
if (!audioPart) {
|
|
2135
|
+
throw new Error(`No audio data in Google TTS response (${describeEmptyTtsResponse(response)}${styleDropped ? ", also without the style" : ""})`);
|
|
2136
|
+
}
|
|
2137
|
+
const bytes = new Uint8Array(Buffer.from(audioPart.data, "base64"));
|
|
2138
|
+
const isWav = /^audio\/(x-)?wav/i.test(audioPart.mimeType);
|
|
2139
|
+
const audio = isWav ? bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) : pcmToWav(bytes);
|
|
2140
|
+
const pcmBytes = isWav ? Math.max(0, bytes.length - WAV_HEADER_BYTES) : bytes.length;
|
|
2122
2141
|
const usageMetadata = response.usageMetadata ?? {};
|
|
2123
|
-
const inputTokens = usageMetadata.promptTokenCount ?? 0;
|
|
2142
|
+
const inputTokens = (usageMetadata.promptTokenCount ?? 0) + blockedInputTokens;
|
|
2124
2143
|
const reportedOutput = usageMetadata.candidatesTokenCount;
|
|
2125
|
-
const outputTokens = reportedOutput && reportedOutput > 0 ? reportedOutput : Math.ceil(
|
|
2126
|
-
return {
|
|
2144
|
+
const outputTokens = reportedOutput && reportedOutput > 0 ? reportedOutput : Math.ceil(pcmBytes / PCM_BYTES_PER_SECOND * AUDIO_TOKENS_PER_SECOND);
|
|
2145
|
+
return {
|
|
2146
|
+
audio,
|
|
2147
|
+
usage: { inputTokens, outputTokens },
|
|
2148
|
+
...styleDropped ? { styleDropped } : {}
|
|
2149
|
+
};
|
|
2127
2150
|
}
|
|
2128
2151
|
|
|
2129
2152
|
// src/voice/google-stt.ts
|
|
@@ -2154,11 +2177,11 @@ var GoogleVoiceAgent = class {
|
|
|
2154
2177
|
ttsModel = VOICE_MODEL_CONSTANTS.GOOGLE_TTS;
|
|
2155
2178
|
sttModel = VOICE_MODEL_CONSTANTS.GOOGLE_STT;
|
|
2156
2179
|
async speak(request) {
|
|
2157
|
-
const { audio, usage } = await generateGoogleTtsAudio(request.text, this.apiKey, {
|
|
2180
|
+
const { audio, usage, styleDropped } = await generateGoogleTtsAudio(request.text, this.apiKey, {
|
|
2158
2181
|
voiceName: request.voice,
|
|
2159
2182
|
voiceStyle: request.voiceStyle
|
|
2160
2183
|
});
|
|
2161
|
-
return { audio, costUSD: calculateGeminiTtsCost(usage), usage };
|
|
2184
|
+
return { audio, costUSD: calculateGeminiTtsCost(usage), usage, ...styleDropped ? { styleDropped } : {} };
|
|
2162
2185
|
}
|
|
2163
2186
|
async transcribe(request) {
|
|
2164
2187
|
const { text, durationSeconds, usage } = await transcribeWithGemini(request.audio, this.apiKey, { mimeType: request.mimeType });
|
|
@@ -5527,7 +5550,6 @@ var AgentFactory = class {
|
|
|
5527
5550
|
XAI_REASONING_EFFORTS,
|
|
5528
5551
|
ZodSchemaConverter,
|
|
5529
5552
|
applySpend,
|
|
5530
|
-
buildGoogleTtsPrompt,
|
|
5531
5553
|
calculateAnthropicCost,
|
|
5532
5554
|
calculateCost,
|
|
5533
5555
|
calculateDeepSeekCost,
|
|
@@ -5580,6 +5602,7 @@ var AgentFactory = class {
|
|
|
5580
5602
|
isHybridThinkingModel,
|
|
5581
5603
|
isInPeakWindow,
|
|
5582
5604
|
isPeakBilling,
|
|
5605
|
+
isSafetyBlocked,
|
|
5583
5606
|
isWeekendAt,
|
|
5584
5607
|
ledgerSpend,
|
|
5585
5608
|
logger,
|
|
@@ -5587,6 +5610,7 @@ var AgentFactory = class {
|
|
|
5587
5610
|
modelHasTag,
|
|
5588
5611
|
modelIsFast,
|
|
5589
5612
|
needsPromptBasedSchema,
|
|
5613
|
+
normalizeTtsStyle,
|
|
5590
5614
|
parseAndValidateLlmJson,
|
|
5591
5615
|
pcmToWav,
|
|
5592
5616
|
periodEnd,
|