@hiper2d/ai-agents 0.18.0 → 0.19.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/index.d.mts +31 -1
- package/dist/index.d.ts +31 -1
- package/dist/index.js +60 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -293,6 +293,17 @@ declare class ModelInvalidResponseError extends ModelError {
|
|
|
293
293
|
* Google's non-configurable filter — no safetySettings change lifts it.
|
|
294
294
|
* `reason` = the blockReason or finishReason string.
|
|
295
295
|
*/
|
|
296
|
+
/**
|
|
297
|
+
* The provider did not answer within the agent's `requestTimeoutMs`. The ask gives up
|
|
298
|
+
* instead of hanging until the host's serverless function is killed, which leaves no log
|
|
299
|
+
* line and no error for the player to retry from. Observed 2026-10-01: `deepseek-flash`
|
|
300
|
+
* accepted requests and never answered (no tokens, even streaming) while `deepseek-v4-pro`
|
|
301
|
+
* on the same key answered in 0.5s. Retryable — usually on another model.
|
|
302
|
+
*/
|
|
303
|
+
declare class ModelTimeoutError extends ModelError {
|
|
304
|
+
timeoutMs: number;
|
|
305
|
+
constructor(modelType: string, timeoutMs: number);
|
|
306
|
+
}
|
|
296
307
|
declare class ModelRefusalError extends ModelError {
|
|
297
308
|
reason?: string;
|
|
298
309
|
constructor(modelType: string, message?: string, reason?: string);
|
|
@@ -364,6 +375,7 @@ declare const LLM_CONSTANTS: {
|
|
|
364
375
|
GEMINI_PRO: string;
|
|
365
376
|
GEMINI_FLASH: string;
|
|
366
377
|
GEMINI_LITE: string;
|
|
378
|
+
MISTRAL_LARGE: string;
|
|
367
379
|
MISTRAL_MEDIUM: string;
|
|
368
380
|
MISTRAL_SMALL: string;
|
|
369
381
|
GROK: string;
|
|
@@ -388,6 +400,13 @@ declare const LLM_CONSTANTS: {
|
|
|
388
400
|
* runaway one. Reasoning effort and thinking budgets are the knobs that change spend.
|
|
389
401
|
*/
|
|
390
402
|
declare const DEFAULT_MAX_OUTPUT_TOKENS = 8192;
|
|
403
|
+
/**
|
|
404
|
+
* Wall-clock limit on one ask, retries inside the provider SDK included. Past it the ask
|
|
405
|
+
* throws ModelTimeoutError. Measured 2026-10-01 over 7k production calls (14 days): 0.5%
|
|
406
|
+
* ran past 60s — mostly Grok turns and story generation. Callers that legitimately need
|
|
407
|
+
* longer raise `requestTimeoutMs` on the instance, like maxOutputTokens.
|
|
408
|
+
*/
|
|
409
|
+
declare const DEFAULT_REQUEST_TIMEOUT_MS = 60000;
|
|
391
410
|
type ModelTag = 'very-fast' | 'fast' | 'slow' | 'very-slow' | 'extremely-slow' | 'cheap' | 'expensive';
|
|
392
411
|
type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
393
412
|
/**
|
|
@@ -1286,6 +1305,12 @@ declare abstract class AbstractAgent {
|
|
|
1286
1305
|
*/
|
|
1287
1306
|
reasoningEffort?: ReasoningEffort;
|
|
1288
1307
|
thinkingBudgetTokens?: number;
|
|
1308
|
+
/**
|
|
1309
|
+
* Wall-clock limit on one ask (DEFAULT_REQUEST_TIMEOUT_MS). Past it the ask throws
|
|
1310
|
+
* ModelTimeoutError; the provider request is abandoned, not cancelled. Raise it per
|
|
1311
|
+
* instance for calls that legitimately run long, like maxOutputTokens.
|
|
1312
|
+
*/
|
|
1313
|
+
requestTimeoutMs: number;
|
|
1289
1314
|
protected readonly instruction: string;
|
|
1290
1315
|
/**
|
|
1291
1316
|
* The instruction split on CACHE_TIER_MARKER: [shared static tier, per-bot tier].
|
|
@@ -1306,6 +1331,11 @@ declare abstract class AbstractAgent {
|
|
|
1306
1331
|
*/
|
|
1307
1332
|
askWithZodSchema<T>(zodSchema: z.ZodSchema<T>, messages: AIMessage[]): Promise<[T, string, TokenUsage$1?, string?]>;
|
|
1308
1333
|
askText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1334
|
+
/**
|
|
1335
|
+
* Races the provider call against requestTimeoutMs. A hung provider (accepts the request,
|
|
1336
|
+
* never answers) otherwise runs until the host kills the function with no error to show.
|
|
1337
|
+
*/
|
|
1338
|
+
private withTimeout;
|
|
1309
1339
|
private stampDuration;
|
|
1310
1340
|
/** Failed calls carry their duration too — a 35s provider stall that errors is still signal. */
|
|
1311
1341
|
private stampErrorDuration;
|
|
@@ -1804,4 +1834,4 @@ declare class MiniMaxAgent extends AbstractAgent {
|
|
|
1804
1834
|
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1805
1835
|
}
|
|
1806
1836
|
|
|
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 };
|
|
1837
|
+
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, DEFAULT_REQUEST_TIMEOUT_MS, 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, ModelTimeoutError, 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
|
@@ -293,6 +293,17 @@ declare class ModelInvalidResponseError extends ModelError {
|
|
|
293
293
|
* Google's non-configurable filter — no safetySettings change lifts it.
|
|
294
294
|
* `reason` = the blockReason or finishReason string.
|
|
295
295
|
*/
|
|
296
|
+
/**
|
|
297
|
+
* The provider did not answer within the agent's `requestTimeoutMs`. The ask gives up
|
|
298
|
+
* instead of hanging until the host's serverless function is killed, which leaves no log
|
|
299
|
+
* line and no error for the player to retry from. Observed 2026-10-01: `deepseek-flash`
|
|
300
|
+
* accepted requests and never answered (no tokens, even streaming) while `deepseek-v4-pro`
|
|
301
|
+
* on the same key answered in 0.5s. Retryable — usually on another model.
|
|
302
|
+
*/
|
|
303
|
+
declare class ModelTimeoutError extends ModelError {
|
|
304
|
+
timeoutMs: number;
|
|
305
|
+
constructor(modelType: string, timeoutMs: number);
|
|
306
|
+
}
|
|
296
307
|
declare class ModelRefusalError extends ModelError {
|
|
297
308
|
reason?: string;
|
|
298
309
|
constructor(modelType: string, message?: string, reason?: string);
|
|
@@ -364,6 +375,7 @@ declare const LLM_CONSTANTS: {
|
|
|
364
375
|
GEMINI_PRO: string;
|
|
365
376
|
GEMINI_FLASH: string;
|
|
366
377
|
GEMINI_LITE: string;
|
|
378
|
+
MISTRAL_LARGE: string;
|
|
367
379
|
MISTRAL_MEDIUM: string;
|
|
368
380
|
MISTRAL_SMALL: string;
|
|
369
381
|
GROK: string;
|
|
@@ -388,6 +400,13 @@ declare const LLM_CONSTANTS: {
|
|
|
388
400
|
* runaway one. Reasoning effort and thinking budgets are the knobs that change spend.
|
|
389
401
|
*/
|
|
390
402
|
declare const DEFAULT_MAX_OUTPUT_TOKENS = 8192;
|
|
403
|
+
/**
|
|
404
|
+
* Wall-clock limit on one ask, retries inside the provider SDK included. Past it the ask
|
|
405
|
+
* throws ModelTimeoutError. Measured 2026-10-01 over 7k production calls (14 days): 0.5%
|
|
406
|
+
* ran past 60s — mostly Grok turns and story generation. Callers that legitimately need
|
|
407
|
+
* longer raise `requestTimeoutMs` on the instance, like maxOutputTokens.
|
|
408
|
+
*/
|
|
409
|
+
declare const DEFAULT_REQUEST_TIMEOUT_MS = 60000;
|
|
391
410
|
type ModelTag = 'very-fast' | 'fast' | 'slow' | 'very-slow' | 'extremely-slow' | 'cheap' | 'expensive';
|
|
392
411
|
type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
393
412
|
/**
|
|
@@ -1286,6 +1305,12 @@ declare abstract class AbstractAgent {
|
|
|
1286
1305
|
*/
|
|
1287
1306
|
reasoningEffort?: ReasoningEffort;
|
|
1288
1307
|
thinkingBudgetTokens?: number;
|
|
1308
|
+
/**
|
|
1309
|
+
* Wall-clock limit on one ask (DEFAULT_REQUEST_TIMEOUT_MS). Past it the ask throws
|
|
1310
|
+
* ModelTimeoutError; the provider request is abandoned, not cancelled. Raise it per
|
|
1311
|
+
* instance for calls that legitimately run long, like maxOutputTokens.
|
|
1312
|
+
*/
|
|
1313
|
+
requestTimeoutMs: number;
|
|
1289
1314
|
protected readonly instruction: string;
|
|
1290
1315
|
/**
|
|
1291
1316
|
* The instruction split on CACHE_TIER_MARKER: [shared static tier, per-bot tier].
|
|
@@ -1306,6 +1331,11 @@ declare abstract class AbstractAgent {
|
|
|
1306
1331
|
*/
|
|
1307
1332
|
askWithZodSchema<T>(zodSchema: z.ZodSchema<T>, messages: AIMessage[]): Promise<[T, string, TokenUsage$1?, string?]>;
|
|
1308
1333
|
askText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1334
|
+
/**
|
|
1335
|
+
* Races the provider call against requestTimeoutMs. A hung provider (accepts the request,
|
|
1336
|
+
* never answers) otherwise runs until the host kills the function with no error to show.
|
|
1337
|
+
*/
|
|
1338
|
+
private withTimeout;
|
|
1309
1339
|
private stampDuration;
|
|
1310
1340
|
/** Failed calls carry their duration too — a 35s provider stall that errors is still signal. */
|
|
1311
1341
|
private stampErrorDuration;
|
|
@@ -1804,4 +1834,4 @@ declare class MiniMaxAgent extends AbstractAgent {
|
|
|
1804
1834
|
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1805
1835
|
}
|
|
1806
1836
|
|
|
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 };
|
|
1837
|
+
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, DEFAULT_REQUEST_TIMEOUT_MS, 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, ModelTimeoutError, 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
|
@@ -43,6 +43,7 @@ __export(src_exports, {
|
|
|
43
43
|
DEEPSEEK_REASONING_EFFORTS: () => DEEPSEEK_REASONING_EFFORTS,
|
|
44
44
|
DEFAULT_LOGGING_CONFIG: () => DEFAULT_LOGGING_CONFIG,
|
|
45
45
|
DEFAULT_MAX_OUTPUT_TOKENS: () => DEFAULT_MAX_OUTPUT_TOKENS,
|
|
46
|
+
DEFAULT_REQUEST_TIMEOUT_MS: () => DEFAULT_REQUEST_TIMEOUT_MS,
|
|
46
47
|
DeepSeekV2Agent: () => DeepSeekV2Agent,
|
|
47
48
|
FUGU_REASONING_EFFORTS: () => FUGU_REASONING_EFFORTS,
|
|
48
49
|
FuguAgent: () => FuguAgent,
|
|
@@ -72,6 +73,7 @@ __export(src_exports, {
|
|
|
72
73
|
ModelQuotaExceededError: () => ModelQuotaExceededError,
|
|
73
74
|
ModelRateLimitError: () => ModelRateLimitError,
|
|
74
75
|
ModelRefusalError: () => ModelRefusalError,
|
|
76
|
+
ModelTimeoutError: () => ModelTimeoutError,
|
|
75
77
|
ModelUnavailableError: () => ModelUnavailableError,
|
|
76
78
|
OPENAI_REASONING_EFFORTS: () => OPENAI_REASONING_EFFORTS,
|
|
77
79
|
OpenAiVoiceAgent: () => OpenAiVoiceAgent,
|
|
@@ -889,6 +891,14 @@ var ModelInvalidResponseError = class extends ModelError {
|
|
|
889
891
|
this.truncated = truncated;
|
|
890
892
|
}
|
|
891
893
|
};
|
|
894
|
+
var ModelTimeoutError = class extends ModelError {
|
|
895
|
+
timeoutMs;
|
|
896
|
+
constructor(modelType, timeoutMs) {
|
|
897
|
+
super(`${modelType} did not respond within ${Math.round(timeoutMs / 1e3)}s`, modelType);
|
|
898
|
+
this.name = "ModelTimeoutError";
|
|
899
|
+
this.timeoutMs = timeoutMs;
|
|
900
|
+
}
|
|
901
|
+
};
|
|
892
902
|
var ModelRefusalError = class extends ModelError {
|
|
893
903
|
reason;
|
|
894
904
|
constructor(modelType, message = `${modelType} refused to answer (stop_reason: refusal)`, reason) {
|
|
@@ -974,6 +984,9 @@ var LLM_CONSTANTS = {
|
|
|
974
984
|
GEMINI_PRO: "gemini-pro",
|
|
975
985
|
GEMINI_FLASH: "gemini-flash",
|
|
976
986
|
GEMINI_LITE: "gemini-lite",
|
|
987
|
+
// Reused 2026-10-06 for Mistral Large 4: the old id (Large 3) was retired 2026-09-18 and
|
|
988
|
+
// consumers had mapped it away, so the version-free id was free again.
|
|
989
|
+
MISTRAL_LARGE: "mistral-large",
|
|
977
990
|
MISTRAL_MEDIUM: "mistral-medium",
|
|
978
991
|
MISTRAL_SMALL: "mistral-small",
|
|
979
992
|
GROK: "grok",
|
|
@@ -992,6 +1005,7 @@ var LLM_CONSTANTS = {
|
|
|
992
1005
|
MUSE_SPARK: "muse-spark"
|
|
993
1006
|
};
|
|
994
1007
|
var DEFAULT_MAX_OUTPUT_TOKENS = 8192;
|
|
1008
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 6e4;
|
|
995
1009
|
var SupportedAiModels = {
|
|
996
1010
|
// Claude Fable 5.1 (2026-09-02, was Fable 5) - frontier reasoning model. Thinking is always on (no non-thinking variant).
|
|
997
1011
|
[LLM_CONSTANTS.CLAUDE_FABLE]: {
|
|
@@ -1180,6 +1194,21 @@ var SupportedAiModels = {
|
|
|
1180
1194
|
// returns `mistral-medium-3-5`, `mistral-medium-3`, `mistral-medium-latest` and
|
|
1181
1195
|
// `magistral-medium-latest` as one entry — so Magistral seats had silently become Medium
|
|
1182
1196
|
// seats already. Consumers map both retired ids onto the surviving pair.
|
|
1197
|
+
//
|
|
1198
|
+
// Mistral Large 4 added 2026-10-06 under the freed `mistral-large` picker id. The model list
|
|
1199
|
+
// reports reasoning: true (Large 3 said false), 512K context; same reasoning_effort switch,
|
|
1200
|
+
// but only 'high' and 'none' are accepted (medium/low are a 400). Live 2026-10-06 at high:
|
|
1201
|
+
// a chat-turn schema ask took 14-21s with 1.3-2k output tokens (~$0.003), one constrained
|
|
1202
|
+
// pick took 49s — it thinks long, so it is cheap but slow.
|
|
1203
|
+
[LLM_CONSTANTS.MISTRAL_LARGE]: {
|
|
1204
|
+
displayName: "Mistral Large 4",
|
|
1205
|
+
// `mistral-large-4-0` is the same entry; `mistral-large-latest` still points at Large 3.
|
|
1206
|
+
modelApiName: "mistral-large-4",
|
|
1207
|
+
apiKeyName: API_KEY_CONSTANTS.MISTRAL,
|
|
1208
|
+
hasThinking: true,
|
|
1209
|
+
reasoningEffort: "high",
|
|
1210
|
+
tags: ["slow", "cheap"]
|
|
1211
|
+
},
|
|
1183
1212
|
[LLM_CONSTANTS.MISTRAL_MEDIUM]: {
|
|
1184
1213
|
displayName: "Mistral Medium 3.5",
|
|
1185
1214
|
// The docs' explicit 3.5 id. It was `mistral-medium-3` until 2026-09-18, which Mistral
|
|
@@ -1569,7 +1598,13 @@ var MODEL_PRICING = {
|
|
|
1569
1598
|
// Mistral models (mistral.ai/pricing/api, verified 2026-09-18). Cached tokens bill at 10% of
|
|
1570
1599
|
// the input price (documented on the prompt_cache_key param; no per-model cached prices
|
|
1571
1600
|
// published). Reasoning tokens are counted inside completion_tokens — no separate
|
|
1572
|
-
// reasoning_tokens field — so the output rate already covers the trace.
|
|
1601
|
+
// reasoning_tokens field — so the output rate already covers the trace. Large 4 added
|
|
1602
|
+
// 2026-10-06 at its published rates ($0.07 cached, not an exact 10%).
|
|
1603
|
+
[SupportedAiModels[LLM_CONSTANTS.MISTRAL_LARGE].modelApiName]: {
|
|
1604
|
+
inputPrice: 0.68,
|
|
1605
|
+
outputPrice: 2.09,
|
|
1606
|
+
cacheHitPrice: 0.07
|
|
1607
|
+
},
|
|
1573
1608
|
[SupportedAiModels[LLM_CONSTANTS.MISTRAL_MEDIUM].modelApiName]: {
|
|
1574
1609
|
inputPrice: 1.5,
|
|
1575
1610
|
outputPrice: 7.5,
|
|
@@ -1667,6 +1702,7 @@ var HYBRID_THINKING_API_NAMES = /* @__PURE__ */ new Set([
|
|
|
1667
1702
|
SupportedAiModels[LLM_CONSTANTS.MINIMAX].modelApiName,
|
|
1668
1703
|
// Mistral reasons only when asked (`reasoning_effort`), and we always ask — hybrid by the
|
|
1669
1704
|
// same definition as Qwen. Added 2026-09-18 when the two entries went thinking-on.
|
|
1705
|
+
SupportedAiModels[LLM_CONSTANTS.MISTRAL_LARGE].modelApiName,
|
|
1670
1706
|
SupportedAiModels[LLM_CONSTANTS.MISTRAL_MEDIUM].modelApiName,
|
|
1671
1707
|
SupportedAiModels[LLM_CONSTANTS.MISTRAL_SMALL].modelApiName
|
|
1672
1708
|
]);
|
|
@@ -2403,6 +2439,12 @@ var AbstractAgent = class {
|
|
|
2403
2439
|
*/
|
|
2404
2440
|
reasoningEffort;
|
|
2405
2441
|
thinkingBudgetTokens;
|
|
2442
|
+
/**
|
|
2443
|
+
* Wall-clock limit on one ask (DEFAULT_REQUEST_TIMEOUT_MS). Past it the ask throws
|
|
2444
|
+
* ModelTimeoutError; the provider request is abandoned, not cancelled. Raise it per
|
|
2445
|
+
* instance for calls that legitimately run long, like maxOutputTokens.
|
|
2446
|
+
*/
|
|
2447
|
+
requestTimeoutMs = DEFAULT_REQUEST_TIMEOUT_MS;
|
|
2406
2448
|
instruction;
|
|
2407
2449
|
/**
|
|
2408
2450
|
* The instruction split on CACHE_TIER_MARKER: [shared static tier, per-bot tier].
|
|
@@ -2437,7 +2479,7 @@ var AbstractAgent = class {
|
|
|
2437
2479
|
if (beforeAskHook) await beforeAskHook(this);
|
|
2438
2480
|
const startedAt = Date.now();
|
|
2439
2481
|
try {
|
|
2440
|
-
const [result, thinking, usage, signature] = await this.doAskWithZodSchema(zodSchema, messages);
|
|
2482
|
+
const [result, thinking, usage, signature] = await this.withTimeout(this.doAskWithZodSchema(zodSchema, messages));
|
|
2441
2483
|
return [result, thinking, this.stampDuration(usage, startedAt), signature];
|
|
2442
2484
|
} catch (error) {
|
|
2443
2485
|
this.stampErrorDuration(error, startedAt);
|
|
@@ -2448,13 +2490,25 @@ var AbstractAgent = class {
|
|
|
2448
2490
|
if (beforeAskHook) await beforeAskHook(this);
|
|
2449
2491
|
const startedAt = Date.now();
|
|
2450
2492
|
try {
|
|
2451
|
-
const [content, thinking, usage, signature] = await this.doAskText(messages);
|
|
2493
|
+
const [content, thinking, usage, signature] = await this.withTimeout(this.doAskText(messages));
|
|
2452
2494
|
return [content, thinking, this.stampDuration(usage, startedAt), signature];
|
|
2453
2495
|
} catch (error) {
|
|
2454
2496
|
this.stampErrorDuration(error, startedAt);
|
|
2455
2497
|
throw error;
|
|
2456
2498
|
}
|
|
2457
2499
|
}
|
|
2500
|
+
/**
|
|
2501
|
+
* Races the provider call against requestTimeoutMs. A hung provider (accepts the request,
|
|
2502
|
+
* never answers) otherwise runs until the host kills the function with no error to show.
|
|
2503
|
+
*/
|
|
2504
|
+
withTimeout(call) {
|
|
2505
|
+
const timeoutMs = this.requestTimeoutMs;
|
|
2506
|
+
let timer;
|
|
2507
|
+
const timeout = new Promise((_, reject) => {
|
|
2508
|
+
timer = setTimeout(() => reject(new ModelTimeoutError(this.model, timeoutMs)), timeoutMs);
|
|
2509
|
+
});
|
|
2510
|
+
return Promise.race([call, timeout]).finally(() => clearTimeout(timer));
|
|
2511
|
+
}
|
|
2458
2512
|
stampDuration(usage, startedAt) {
|
|
2459
2513
|
return usage ? { ...usage, durationMs: Date.now() - startedAt } : usage;
|
|
2460
2514
|
}
|
|
@@ -5470,6 +5524,7 @@ var AgentFactory = class {
|
|
|
5470
5524
|
case LLM_CONSTANTS.DEEPSEEK_PRO:
|
|
5471
5525
|
return new DeepSeekV2Agent(name, instruction, model.modelApiName, key, model.temperature ?? 0, shouldEnableThinking);
|
|
5472
5526
|
// Mistral models
|
|
5527
|
+
case LLM_CONSTANTS.MISTRAL_LARGE:
|
|
5473
5528
|
case LLM_CONSTANTS.MISTRAL_MEDIUM:
|
|
5474
5529
|
case LLM_CONSTANTS.MISTRAL_SMALL:
|
|
5475
5530
|
return new MistralAgent(name, instruction, model.modelApiName, key, shouldEnableThinking);
|
|
@@ -5520,6 +5575,7 @@ var AgentFactory = class {
|
|
|
5520
5575
|
DEEPSEEK_REASONING_EFFORTS,
|
|
5521
5576
|
DEFAULT_LOGGING_CONFIG,
|
|
5522
5577
|
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
5578
|
+
DEFAULT_REQUEST_TIMEOUT_MS,
|
|
5523
5579
|
DeepSeekV2Agent,
|
|
5524
5580
|
FUGU_REASONING_EFFORTS,
|
|
5525
5581
|
FuguAgent,
|
|
@@ -5549,6 +5605,7 @@ var AgentFactory = class {
|
|
|
5549
5605
|
ModelQuotaExceededError,
|
|
5550
5606
|
ModelRateLimitError,
|
|
5551
5607
|
ModelRefusalError,
|
|
5608
|
+
ModelTimeoutError,
|
|
5552
5609
|
ModelUnavailableError,
|
|
5553
5610
|
OPENAI_REASONING_EFFORTS,
|
|
5554
5611
|
OpenAiVoiceAgent,
|