@hiper2d/ai-agents 0.3.1 → 0.4.1
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 +1 -1
- package/dist/index.d.mts +92 -5
- package/dist/index.d.ts +92 -5
- package/dist/index.js +287 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +281 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hiper2d/ai-agents
|
|
2
2
|
|
|
3
|
-
Multi-provider AI agent layer for TypeScript apps: one `AbstractAgent` interface over
|
|
3
|
+
Multi-provider AI agent layer for TypeScript apps: one `AbstractAgent` interface over 12 LLM
|
|
4
4
|
providers, schema-validated JSON asks (zod), reasoning/thinking extraction, a model catalog
|
|
5
5
|
with per-model tuning defaults, and token cost accounting (cache tiers, extended context,
|
|
6
6
|
peak-valley pricing).
|
package/dist/index.d.mts
CHANGED
|
@@ -15,6 +15,7 @@ interface AIMessage {
|
|
|
15
15
|
anthropicThinkingSignature?: string;
|
|
16
16
|
googleThoughtSignature?: string;
|
|
17
17
|
grokEncryptedReasoning?: string;
|
|
18
|
+
metaEncryptedReasoning?: string;
|
|
18
19
|
}
|
|
19
20
|
interface TokenUsage$1 {
|
|
20
21
|
inputTokens: number;
|
|
@@ -331,6 +332,7 @@ declare const API_KEY_CONSTANTS: {
|
|
|
331
332
|
readonly FUGU: "FUGU_API_KEY";
|
|
332
333
|
readonly QWEN: "QWEN_API_KEY";
|
|
333
334
|
readonly MINIMAX: "MINIMAX_API_KEY";
|
|
335
|
+
readonly META: "META_API_KEY";
|
|
334
336
|
};
|
|
335
337
|
declare const SupportedAiKeyNames: Record<string, string>;
|
|
336
338
|
declare const LLM_CONSTANTS: {
|
|
@@ -359,6 +361,7 @@ declare const LLM_CONSTANTS: {
|
|
|
359
361
|
QWEN_MAX: string;
|
|
360
362
|
QWEN_FLASH: string;
|
|
361
363
|
MINIMAX: string;
|
|
364
|
+
MUSE_SPARK: string;
|
|
362
365
|
};
|
|
363
366
|
/**
|
|
364
367
|
* Per-request output ceiling for ordinary requests. Reasoning tokens are billed inside this
|
|
@@ -493,6 +496,7 @@ declare function getProviderSignatureFields(aiType: string, signature?: string):
|
|
|
493
496
|
anthropicThinkingSignature?: string;
|
|
494
497
|
googleThoughtSignature?: string;
|
|
495
498
|
grokEncryptedReasoning?: string;
|
|
499
|
+
metaEncryptedReasoning?: string;
|
|
496
500
|
};
|
|
497
501
|
|
|
498
502
|
/**
|
|
@@ -512,6 +516,8 @@ declare function getProviderSignatureFields(aiType: string, signature?: string):
|
|
|
512
516
|
* - Z.AI GLM-5.3 / 5.3-Flash: low|high|max only
|
|
513
517
|
* - DeepSeek V4: low|high|max (the API itself aliases medium → high)
|
|
514
518
|
* - Sakana Fugu: high|xhigh
|
|
519
|
+
* - Meta Muse Spark (verified 2026-09-12): minimal|low|medium|high|xhigh|max ("none" → 400; max is
|
|
520
|
+
* Standard tier only)
|
|
515
521
|
* Qwen accepts reasoning_effort but ignores it (thinking_budget is its knob); MiniMax, Kimi,
|
|
516
522
|
* Grok and Mistral expose no effort parameter.
|
|
517
523
|
*/
|
|
@@ -521,6 +527,7 @@ type GeminiReasoningEffort = 'minimal' | 'low' | 'medium' | 'high';
|
|
|
521
527
|
type GlmReasoningEffort = 'low' | 'high' | 'max';
|
|
522
528
|
type DeepSeekReasoningEffort = 'low' | 'high' | 'max';
|
|
523
529
|
type FuguReasoningEffort = 'high' | 'xhigh';
|
|
530
|
+
type MetaReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
524
531
|
/** The shared scale, lowest first. */
|
|
525
532
|
declare const REASONING_EFFORT_SCALE: readonly ReasoningEffort[];
|
|
526
533
|
declare const OPENAI_REASONING_EFFORTS: readonly OpenAIReasoningEffort[];
|
|
@@ -529,6 +536,7 @@ declare const GEMINI_REASONING_EFFORTS: readonly GeminiReasoningEffort[];
|
|
|
529
536
|
declare const GLM_REASONING_EFFORTS: readonly GlmReasoningEffort[];
|
|
530
537
|
declare const DEEPSEEK_REASONING_EFFORTS: readonly DeepSeekReasoningEffort[];
|
|
531
538
|
declare const FUGU_REASONING_EFFORTS: readonly FuguReasoningEffort[];
|
|
539
|
+
declare const META_REASONING_EFFORTS: readonly MetaReasoningEffort[];
|
|
532
540
|
/** Clamps `effort` to the nearest level in `allowed` (by rank on the shared scale, ties go up). */
|
|
533
541
|
declare function clampReasoningEffort<T extends ReasoningEffort>(effort: ReasoningEffort, allowed: readonly T[]): T;
|
|
534
542
|
declare const toOpenAIEffort: (effort: ReasoningEffort) => OpenAIReasoningEffort;
|
|
@@ -536,6 +544,7 @@ declare const toAnthropicEffort: (effort: ReasoningEffort) => AnthropicReasoning
|
|
|
536
544
|
declare const toGeminiEffort: (effort: ReasoningEffort) => GeminiReasoningEffort;
|
|
537
545
|
declare const toGlmEffort: (effort: ReasoningEffort) => GlmReasoningEffort;
|
|
538
546
|
declare const toDeepSeekEffort: (effort: ReasoningEffort) => DeepSeekReasoningEffort;
|
|
547
|
+
declare const toMetaEffort: (effort: ReasoningEffort) => MetaReasoningEffort;
|
|
539
548
|
declare const toFuguEffort: (effort: ReasoningEffort) => FuguReasoningEffort;
|
|
540
549
|
|
|
541
550
|
/**
|
|
@@ -601,6 +610,11 @@ declare function extractKimiTokenUsage(response: any): TokenUsage | null;
|
|
|
601
610
|
* Grok uses OpenAI-compatible format
|
|
602
611
|
*/
|
|
603
612
|
declare function extractGrokTokenUsage(response: any): TokenUsage | null;
|
|
613
|
+
/**
|
|
614
|
+
* Meta-specific token usage extraction
|
|
615
|
+
* The Meta Model API uses the OpenAI-compatible format
|
|
616
|
+
*/
|
|
617
|
+
declare function extractMetaTokenUsage(response: any): TokenUsage | null;
|
|
604
618
|
/**
|
|
605
619
|
* Anthropic-specific token usage extraction
|
|
606
620
|
* Anthropic may have different response format
|
|
@@ -643,7 +657,7 @@ interface OpenAITokenUsage {
|
|
|
643
657
|
cacheHitTokens?: number;
|
|
644
658
|
reasoningTokens?: number;
|
|
645
659
|
}
|
|
646
|
-
declare function extractTokenUsageFromResponse$
|
|
660
|
+
declare function extractTokenUsageFromResponse$7(response: any): OpenAITokenUsage | null;
|
|
647
661
|
|
|
648
662
|
/**
|
|
649
663
|
* DeepSeek pricing utilities
|
|
@@ -671,7 +685,7 @@ interface DeepSeekTokenUsage {
|
|
|
671
685
|
cacheMissTokens?: number;
|
|
672
686
|
reasoningTokens?: number;
|
|
673
687
|
}
|
|
674
|
-
declare function extractTokenUsageFromResponse$
|
|
688
|
+
declare function extractTokenUsageFromResponse$6(response: any): DeepSeekTokenUsage | null;
|
|
675
689
|
|
|
676
690
|
/**
|
|
677
691
|
* Kimi (Moonshot AI) pricing utilities
|
|
@@ -696,7 +710,7 @@ interface KimiTokenUsage {
|
|
|
696
710
|
completionTokens: number;
|
|
697
711
|
totalTokens: number;
|
|
698
712
|
}
|
|
699
|
-
declare function extractTokenUsageFromResponse$
|
|
713
|
+
declare function extractTokenUsageFromResponse$5(response: any): KimiTokenUsage | null;
|
|
700
714
|
|
|
701
715
|
/**
|
|
702
716
|
* Grok (xAI) pricing utilities
|
|
@@ -723,7 +737,29 @@ interface GrokTokenUsage {
|
|
|
723
737
|
cacheHitTokens?: number;
|
|
724
738
|
reasoningTokens?: number;
|
|
725
739
|
}
|
|
726
|
-
declare function extractTokenUsageFromResponse$
|
|
740
|
+
declare function extractTokenUsageFromResponse$4(response: any): GrokTokenUsage | null;
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Meta Model API (Muse Spark) pricing utilities
|
|
744
|
+
* Re-exports unified utilities with Meta-specific naming, like the other providers
|
|
745
|
+
*/
|
|
746
|
+
/**
|
|
747
|
+
* Calculate the cost for token usage based on Meta pricing
|
|
748
|
+
* @param model - The Meta model name (e.g. muse-spark-1.3)
|
|
749
|
+
* @param inputTokens - Number of input tokens used (cached tokens are a subset of these)
|
|
750
|
+
* @param outputTokens - Number of output tokens used (includes reasoning tokens)
|
|
751
|
+
* @param cacheHitTokens - Number of cached input tokens (input_tokens_details.cached_tokens)
|
|
752
|
+
* @returns Cost in USD
|
|
753
|
+
*/
|
|
754
|
+
declare function calculateMetaCost(model: string, inputTokens: number, outputTokens: number, cacheHitTokens?: number): number;
|
|
755
|
+
interface MetaTokenUsage {
|
|
756
|
+
promptTokens: number;
|
|
757
|
+
completionTokens: number;
|
|
758
|
+
totalTokens: number;
|
|
759
|
+
cacheHitTokens?: number;
|
|
760
|
+
reasoningTokens?: number;
|
|
761
|
+
}
|
|
762
|
+
declare function extractTokenUsageFromResponse$3(response: any): MetaTokenUsage | null;
|
|
727
763
|
|
|
728
764
|
/**
|
|
729
765
|
* Anthropic pricing utilities
|
|
@@ -1460,6 +1496,57 @@ declare class GrokAgent extends AbstractAgent {
|
|
|
1460
1496
|
private extractTokenUsage;
|
|
1461
1497
|
}
|
|
1462
1498
|
|
|
1499
|
+
/**
|
|
1500
|
+
* Meta Model API agent (Muse Spark) on the Responses API at api.meta.ai.
|
|
1501
|
+
*
|
|
1502
|
+
* Muse Spark is an always-on reasoning model: `reasoning.effort` picks the depth
|
|
1503
|
+
* (minimal … max; "none" is rejected with a 400) and the catalog pins a default per entry.
|
|
1504
|
+
* The chain of thought itself is never returned; a summary is requested with
|
|
1505
|
+
* `reasoning.summary: "auto"` and surfaces as the thinking string. Each response's encrypted
|
|
1506
|
+
* reasoning items (requested via `include: ["reasoning.encrypted_content"]`) come back as the
|
|
1507
|
+
* 4th tuple element, are stored on the message as `metaEncryptedReasoning`, and are replayed
|
|
1508
|
+
* into `input` on later turns so the model keeps its reasoning across the conversation —
|
|
1509
|
+
* the same contract as the Grok agent.
|
|
1510
|
+
*
|
|
1511
|
+
* Prompt caching is automatic on Meta's side; `prompt_cache_key` only routes requests that
|
|
1512
|
+
* share a prefix to the same backend, so it is derived from the bot's identity + system
|
|
1513
|
+
* prompt (stable within a game day, like Grok's conversation id).
|
|
1514
|
+
*
|
|
1515
|
+
* Structured output uses the documented `text.format` json_schema mode (strict: false —
|
|
1516
|
+
* Meta's strict subset forbids optional keys and unions that game schemas use), with the
|
|
1517
|
+
* schema description also appended to the prompt and the lenient parser on the way back.
|
|
1518
|
+
*/
|
|
1519
|
+
declare class MetaAgent extends AbstractAgent {
|
|
1520
|
+
private readonly client;
|
|
1521
|
+
private readonly promptCacheKey;
|
|
1522
|
+
private readonly logTemplates;
|
|
1523
|
+
private readonly errorMessages;
|
|
1524
|
+
constructor(name: string, instruction: string, model: string, apiKey: string, temperature: number, enableThinking?: boolean, agentLoggingConfig?: AgentLoggingConfig);
|
|
1525
|
+
/**
|
|
1526
|
+
* Structured output: json_schema format on the Responses API plus the schema described
|
|
1527
|
+
* in the prompt, parsed leniently and validated with Zod.
|
|
1528
|
+
*/
|
|
1529
|
+
doAskWithZodSchema<T>(zodSchema: z.ZodSchema<T>, messages: AIMessage[]): Promise<[T, string, TokenUsage$1?, string?]>;
|
|
1530
|
+
/**
|
|
1531
|
+
* Plain-text ask: no JSON mode and no schema appended to the prompt.
|
|
1532
|
+
* Reasoning extraction and token accounting are identical to askWithZodSchema.
|
|
1533
|
+
*/
|
|
1534
|
+
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1535
|
+
private createResponse;
|
|
1536
|
+
/**
|
|
1537
|
+
* Converts history to Responses API input items. The system instruction is merged into
|
|
1538
|
+
* the leading system message; assistant messages carrying stored encrypted reasoning get
|
|
1539
|
+
* their reasoning items replayed right before them.
|
|
1540
|
+
*/
|
|
1541
|
+
private buildResponsesInput;
|
|
1542
|
+
/**
|
|
1543
|
+
* Walks the response output items: reasoning items yield the human-readable summary
|
|
1544
|
+
* plus the encrypted items (serialized for storage/replay); message items yield text.
|
|
1545
|
+
*/
|
|
1546
|
+
private extractResponseParts;
|
|
1547
|
+
private extractTokenUsage;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1463
1550
|
declare class KimiAgent extends AbstractAgent {
|
|
1464
1551
|
private readonly client;
|
|
1465
1552
|
private get defaultParams();
|
|
@@ -1582,4 +1669,4 @@ declare class MiniMaxAgent extends AbstractAgent {
|
|
|
1582
1669
|
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1583
1670
|
}
|
|
1584
1671
|
|
|
1585
|
-
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, KimiAgent, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, MODEL_PRICING, MiniMaxAgent, MistralAgent, 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, ZodSchemaConverter, applySpend, buildGoogleTtsPrompt, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$
|
|
1672
|
+
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, KimiAgent, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, 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, ZodSchemaConverter, applySpend, buildGoogleTtsPrompt, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, 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, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toMetaEffort, toOpenAIEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ interface AIMessage {
|
|
|
15
15
|
anthropicThinkingSignature?: string;
|
|
16
16
|
googleThoughtSignature?: string;
|
|
17
17
|
grokEncryptedReasoning?: string;
|
|
18
|
+
metaEncryptedReasoning?: string;
|
|
18
19
|
}
|
|
19
20
|
interface TokenUsage$1 {
|
|
20
21
|
inputTokens: number;
|
|
@@ -331,6 +332,7 @@ declare const API_KEY_CONSTANTS: {
|
|
|
331
332
|
readonly FUGU: "FUGU_API_KEY";
|
|
332
333
|
readonly QWEN: "QWEN_API_KEY";
|
|
333
334
|
readonly MINIMAX: "MINIMAX_API_KEY";
|
|
335
|
+
readonly META: "META_API_KEY";
|
|
334
336
|
};
|
|
335
337
|
declare const SupportedAiKeyNames: Record<string, string>;
|
|
336
338
|
declare const LLM_CONSTANTS: {
|
|
@@ -359,6 +361,7 @@ declare const LLM_CONSTANTS: {
|
|
|
359
361
|
QWEN_MAX: string;
|
|
360
362
|
QWEN_FLASH: string;
|
|
361
363
|
MINIMAX: string;
|
|
364
|
+
MUSE_SPARK: string;
|
|
362
365
|
};
|
|
363
366
|
/**
|
|
364
367
|
* Per-request output ceiling for ordinary requests. Reasoning tokens are billed inside this
|
|
@@ -493,6 +496,7 @@ declare function getProviderSignatureFields(aiType: string, signature?: string):
|
|
|
493
496
|
anthropicThinkingSignature?: string;
|
|
494
497
|
googleThoughtSignature?: string;
|
|
495
498
|
grokEncryptedReasoning?: string;
|
|
499
|
+
metaEncryptedReasoning?: string;
|
|
496
500
|
};
|
|
497
501
|
|
|
498
502
|
/**
|
|
@@ -512,6 +516,8 @@ declare function getProviderSignatureFields(aiType: string, signature?: string):
|
|
|
512
516
|
* - Z.AI GLM-5.3 / 5.3-Flash: low|high|max only
|
|
513
517
|
* - DeepSeek V4: low|high|max (the API itself aliases medium → high)
|
|
514
518
|
* - Sakana Fugu: high|xhigh
|
|
519
|
+
* - Meta Muse Spark (verified 2026-09-12): minimal|low|medium|high|xhigh|max ("none" → 400; max is
|
|
520
|
+
* Standard tier only)
|
|
515
521
|
* Qwen accepts reasoning_effort but ignores it (thinking_budget is its knob); MiniMax, Kimi,
|
|
516
522
|
* Grok and Mistral expose no effort parameter.
|
|
517
523
|
*/
|
|
@@ -521,6 +527,7 @@ type GeminiReasoningEffort = 'minimal' | 'low' | 'medium' | 'high';
|
|
|
521
527
|
type GlmReasoningEffort = 'low' | 'high' | 'max';
|
|
522
528
|
type DeepSeekReasoningEffort = 'low' | 'high' | 'max';
|
|
523
529
|
type FuguReasoningEffort = 'high' | 'xhigh';
|
|
530
|
+
type MetaReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
524
531
|
/** The shared scale, lowest first. */
|
|
525
532
|
declare const REASONING_EFFORT_SCALE: readonly ReasoningEffort[];
|
|
526
533
|
declare const OPENAI_REASONING_EFFORTS: readonly OpenAIReasoningEffort[];
|
|
@@ -529,6 +536,7 @@ declare const GEMINI_REASONING_EFFORTS: readonly GeminiReasoningEffort[];
|
|
|
529
536
|
declare const GLM_REASONING_EFFORTS: readonly GlmReasoningEffort[];
|
|
530
537
|
declare const DEEPSEEK_REASONING_EFFORTS: readonly DeepSeekReasoningEffort[];
|
|
531
538
|
declare const FUGU_REASONING_EFFORTS: readonly FuguReasoningEffort[];
|
|
539
|
+
declare const META_REASONING_EFFORTS: readonly MetaReasoningEffort[];
|
|
532
540
|
/** Clamps `effort` to the nearest level in `allowed` (by rank on the shared scale, ties go up). */
|
|
533
541
|
declare function clampReasoningEffort<T extends ReasoningEffort>(effort: ReasoningEffort, allowed: readonly T[]): T;
|
|
534
542
|
declare const toOpenAIEffort: (effort: ReasoningEffort) => OpenAIReasoningEffort;
|
|
@@ -536,6 +544,7 @@ declare const toAnthropicEffort: (effort: ReasoningEffort) => AnthropicReasoning
|
|
|
536
544
|
declare const toGeminiEffort: (effort: ReasoningEffort) => GeminiReasoningEffort;
|
|
537
545
|
declare const toGlmEffort: (effort: ReasoningEffort) => GlmReasoningEffort;
|
|
538
546
|
declare const toDeepSeekEffort: (effort: ReasoningEffort) => DeepSeekReasoningEffort;
|
|
547
|
+
declare const toMetaEffort: (effort: ReasoningEffort) => MetaReasoningEffort;
|
|
539
548
|
declare const toFuguEffort: (effort: ReasoningEffort) => FuguReasoningEffort;
|
|
540
549
|
|
|
541
550
|
/**
|
|
@@ -601,6 +610,11 @@ declare function extractKimiTokenUsage(response: any): TokenUsage | null;
|
|
|
601
610
|
* Grok uses OpenAI-compatible format
|
|
602
611
|
*/
|
|
603
612
|
declare function extractGrokTokenUsage(response: any): TokenUsage | null;
|
|
613
|
+
/**
|
|
614
|
+
* Meta-specific token usage extraction
|
|
615
|
+
* The Meta Model API uses the OpenAI-compatible format
|
|
616
|
+
*/
|
|
617
|
+
declare function extractMetaTokenUsage(response: any): TokenUsage | null;
|
|
604
618
|
/**
|
|
605
619
|
* Anthropic-specific token usage extraction
|
|
606
620
|
* Anthropic may have different response format
|
|
@@ -643,7 +657,7 @@ interface OpenAITokenUsage {
|
|
|
643
657
|
cacheHitTokens?: number;
|
|
644
658
|
reasoningTokens?: number;
|
|
645
659
|
}
|
|
646
|
-
declare function extractTokenUsageFromResponse$
|
|
660
|
+
declare function extractTokenUsageFromResponse$7(response: any): OpenAITokenUsage | null;
|
|
647
661
|
|
|
648
662
|
/**
|
|
649
663
|
* DeepSeek pricing utilities
|
|
@@ -671,7 +685,7 @@ interface DeepSeekTokenUsage {
|
|
|
671
685
|
cacheMissTokens?: number;
|
|
672
686
|
reasoningTokens?: number;
|
|
673
687
|
}
|
|
674
|
-
declare function extractTokenUsageFromResponse$
|
|
688
|
+
declare function extractTokenUsageFromResponse$6(response: any): DeepSeekTokenUsage | null;
|
|
675
689
|
|
|
676
690
|
/**
|
|
677
691
|
* Kimi (Moonshot AI) pricing utilities
|
|
@@ -696,7 +710,7 @@ interface KimiTokenUsage {
|
|
|
696
710
|
completionTokens: number;
|
|
697
711
|
totalTokens: number;
|
|
698
712
|
}
|
|
699
|
-
declare function extractTokenUsageFromResponse$
|
|
713
|
+
declare function extractTokenUsageFromResponse$5(response: any): KimiTokenUsage | null;
|
|
700
714
|
|
|
701
715
|
/**
|
|
702
716
|
* Grok (xAI) pricing utilities
|
|
@@ -723,7 +737,29 @@ interface GrokTokenUsage {
|
|
|
723
737
|
cacheHitTokens?: number;
|
|
724
738
|
reasoningTokens?: number;
|
|
725
739
|
}
|
|
726
|
-
declare function extractTokenUsageFromResponse$
|
|
740
|
+
declare function extractTokenUsageFromResponse$4(response: any): GrokTokenUsage | null;
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Meta Model API (Muse Spark) pricing utilities
|
|
744
|
+
* Re-exports unified utilities with Meta-specific naming, like the other providers
|
|
745
|
+
*/
|
|
746
|
+
/**
|
|
747
|
+
* Calculate the cost for token usage based on Meta pricing
|
|
748
|
+
* @param model - The Meta model name (e.g. muse-spark-1.3)
|
|
749
|
+
* @param inputTokens - Number of input tokens used (cached tokens are a subset of these)
|
|
750
|
+
* @param outputTokens - Number of output tokens used (includes reasoning tokens)
|
|
751
|
+
* @param cacheHitTokens - Number of cached input tokens (input_tokens_details.cached_tokens)
|
|
752
|
+
* @returns Cost in USD
|
|
753
|
+
*/
|
|
754
|
+
declare function calculateMetaCost(model: string, inputTokens: number, outputTokens: number, cacheHitTokens?: number): number;
|
|
755
|
+
interface MetaTokenUsage {
|
|
756
|
+
promptTokens: number;
|
|
757
|
+
completionTokens: number;
|
|
758
|
+
totalTokens: number;
|
|
759
|
+
cacheHitTokens?: number;
|
|
760
|
+
reasoningTokens?: number;
|
|
761
|
+
}
|
|
762
|
+
declare function extractTokenUsageFromResponse$3(response: any): MetaTokenUsage | null;
|
|
727
763
|
|
|
728
764
|
/**
|
|
729
765
|
* Anthropic pricing utilities
|
|
@@ -1460,6 +1496,57 @@ declare class GrokAgent extends AbstractAgent {
|
|
|
1460
1496
|
private extractTokenUsage;
|
|
1461
1497
|
}
|
|
1462
1498
|
|
|
1499
|
+
/**
|
|
1500
|
+
* Meta Model API agent (Muse Spark) on the Responses API at api.meta.ai.
|
|
1501
|
+
*
|
|
1502
|
+
* Muse Spark is an always-on reasoning model: `reasoning.effort` picks the depth
|
|
1503
|
+
* (minimal … max; "none" is rejected with a 400) and the catalog pins a default per entry.
|
|
1504
|
+
* The chain of thought itself is never returned; a summary is requested with
|
|
1505
|
+
* `reasoning.summary: "auto"` and surfaces as the thinking string. Each response's encrypted
|
|
1506
|
+
* reasoning items (requested via `include: ["reasoning.encrypted_content"]`) come back as the
|
|
1507
|
+
* 4th tuple element, are stored on the message as `metaEncryptedReasoning`, and are replayed
|
|
1508
|
+
* into `input` on later turns so the model keeps its reasoning across the conversation —
|
|
1509
|
+
* the same contract as the Grok agent.
|
|
1510
|
+
*
|
|
1511
|
+
* Prompt caching is automatic on Meta's side; `prompt_cache_key` only routes requests that
|
|
1512
|
+
* share a prefix to the same backend, so it is derived from the bot's identity + system
|
|
1513
|
+
* prompt (stable within a game day, like Grok's conversation id).
|
|
1514
|
+
*
|
|
1515
|
+
* Structured output uses the documented `text.format` json_schema mode (strict: false —
|
|
1516
|
+
* Meta's strict subset forbids optional keys and unions that game schemas use), with the
|
|
1517
|
+
* schema description also appended to the prompt and the lenient parser on the way back.
|
|
1518
|
+
*/
|
|
1519
|
+
declare class MetaAgent extends AbstractAgent {
|
|
1520
|
+
private readonly client;
|
|
1521
|
+
private readonly promptCacheKey;
|
|
1522
|
+
private readonly logTemplates;
|
|
1523
|
+
private readonly errorMessages;
|
|
1524
|
+
constructor(name: string, instruction: string, model: string, apiKey: string, temperature: number, enableThinking?: boolean, agentLoggingConfig?: AgentLoggingConfig);
|
|
1525
|
+
/**
|
|
1526
|
+
* Structured output: json_schema format on the Responses API plus the schema described
|
|
1527
|
+
* in the prompt, parsed leniently and validated with Zod.
|
|
1528
|
+
*/
|
|
1529
|
+
doAskWithZodSchema<T>(zodSchema: z.ZodSchema<T>, messages: AIMessage[]): Promise<[T, string, TokenUsage$1?, string?]>;
|
|
1530
|
+
/**
|
|
1531
|
+
* Plain-text ask: no JSON mode and no schema appended to the prompt.
|
|
1532
|
+
* Reasoning extraction and token accounting are identical to askWithZodSchema.
|
|
1533
|
+
*/
|
|
1534
|
+
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1535
|
+
private createResponse;
|
|
1536
|
+
/**
|
|
1537
|
+
* Converts history to Responses API input items. The system instruction is merged into
|
|
1538
|
+
* the leading system message; assistant messages carrying stored encrypted reasoning get
|
|
1539
|
+
* their reasoning items replayed right before them.
|
|
1540
|
+
*/
|
|
1541
|
+
private buildResponsesInput;
|
|
1542
|
+
/**
|
|
1543
|
+
* Walks the response output items: reasoning items yield the human-readable summary
|
|
1544
|
+
* plus the encrypted items (serialized for storage/replay); message items yield text.
|
|
1545
|
+
*/
|
|
1546
|
+
private extractResponseParts;
|
|
1547
|
+
private extractTokenUsage;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1463
1550
|
declare class KimiAgent extends AbstractAgent {
|
|
1464
1551
|
private readonly client;
|
|
1465
1552
|
private get defaultParams();
|
|
@@ -1582,4 +1669,4 @@ declare class MiniMaxAgent extends AbstractAgent {
|
|
|
1582
1669
|
doAskText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
|
|
1583
1670
|
}
|
|
1584
1671
|
|
|
1585
|
-
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, KimiAgent, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, MODEL_PRICING, MiniMaxAgent, MistralAgent, 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, ZodSchemaConverter, applySpend, buildGoogleTtsPrompt, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, evaluateBudget, extractAnthropicTokenUsage, extractTokenUsageFromResponse$2 as extractAnthropicTokenUsageFromResponse, extractDeepSeekTokenUsage, extractTokenUsageFromResponse$
|
|
1672
|
+
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, KimiAgent, type KimiTokenUsage, type LLMModel, LLM_CONSTANTS, type LlmLogger, type LoggingConfig, MESSAGE_ROLE, META_REASONING_EFFORTS, MODEL_PRICING, MetaAgent, type MetaReasoningEffort, type MetaTokenUsage, MiniMaxAgent, MistralAgent, 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, ZodSchemaConverter, applySpend, buildGoogleTtsPrompt, calculateAnthropicCost, calculateCost, calculateDeepSeekCost, calculateGeminiSttCost, calculateGeminiTtsCost, calculateGoogleCost, calculateGrokCost, calculateKimiCost, calculateMetaCost, calculateMistralCost, calculateModelCost, calculateOpenAICost, calculateOpenAiSttCost, calculateOpenAiTtsCost, clampReasoningEffort, cleanResponse, createCatalog, createVoiceAgent, 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, isWeekendAt, ledgerSpend, logger, mergeThinking, modelHasTag, modelIsFast, needsPromptBasedSchema, parseAndValidateLlmJson, pcmToWav, periodEnd, periodKey, safeValidateResponse, setBeforeAskHook, setLlmLogger, stableHashHex, stripInlineThinking, supportsNativeJsonSchema, toAnthropicEffort, toDeepSeekEffort, toFuguEffort, toGeminiEffort, toGlmEffort, toMetaEffort, toOpenAIEffort, transcribeWithGemini, transcribeWithOpenAi, validateResponse };
|