@hiper2d/ai-agents 0.1.4 → 0.2.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 +18 -0
- package/dist/index.d.mts +219 -1
- package/dist/index.d.ts +219 -1
- package/dist/index.js +316 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +295 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.mjs
CHANGED
|
@@ -1618,6 +1618,263 @@ function extractTokenUsageFromResponse7(response) {
|
|
|
1618
1618
|
return extractMistralTokenUsage(response);
|
|
1619
1619
|
}
|
|
1620
1620
|
|
|
1621
|
+
// src/voice/voice-catalog.ts
|
|
1622
|
+
var VOICE_MODEL_CONSTANTS = {
|
|
1623
|
+
OPENAI_TTS: "gpt-4o-mini-tts",
|
|
1624
|
+
OPENAI_STT: "whisper-1",
|
|
1625
|
+
// ai.google.dev/gemini-api/docs/speech-generation
|
|
1626
|
+
GOOGLE_TTS: "gemini-3.1-flash-tts-preview",
|
|
1627
|
+
// ai.google.dev/gemini-api/docs/transcribe — Interactions API only (see google-stt.ts)
|
|
1628
|
+
GOOGLE_STT: "gemini-3.5-transcribe"
|
|
1629
|
+
};
|
|
1630
|
+
var SUPPORTED_VOICE_PROVIDERS = ["openai", "google"];
|
|
1631
|
+
var VOICE_PROVIDER_API_KEY = {
|
|
1632
|
+
openai: API_KEY_CONSTANTS.OPENAI,
|
|
1633
|
+
google: API_KEY_CONSTANTS.GOOGLE
|
|
1634
|
+
};
|
|
1635
|
+
var VOICE_MODEL_PRICING = {
|
|
1636
|
+
[VOICE_MODEL_CONSTANTS.OPENAI_TTS]: { pricePerMillionCharacters: 15 },
|
|
1637
|
+
[VOICE_MODEL_CONSTANTS.OPENAI_STT]: { pricePerMinute: 6e-3 },
|
|
1638
|
+
// Measured 2026-09-05: ~32 audio tokens per second of speech, so a 15-second
|
|
1639
|
+
// line is ~$0.01 — about 3-5x an OpenAI line of the same length.
|
|
1640
|
+
[VOICE_MODEL_CONSTANTS.GOOGLE_TTS]: { textInputPricePerM: 1, audioOutputPricePerM: 20 },
|
|
1641
|
+
// ~25 audio tokens per second in, ~175 text tokens per minute out: ≈ $0.005/min.
|
|
1642
|
+
[VOICE_MODEL_CONSTANTS.GOOGLE_STT]: { audioInputPricePerM: 2, textOutputPricePerM: 12 }
|
|
1643
|
+
};
|
|
1644
|
+
|
|
1645
|
+
// src/voice/voice-pricing.ts
|
|
1646
|
+
function roundUSD(value) {
|
|
1647
|
+
return parseFloat((value || 0).toFixed(6));
|
|
1648
|
+
}
|
|
1649
|
+
function calculateOpenAiTtsCost(characterCount) {
|
|
1650
|
+
const rate = VOICE_MODEL_PRICING[VOICE_MODEL_CONSTANTS.OPENAI_TTS]?.pricePerMillionCharacters ?? 0;
|
|
1651
|
+
if (!characterCount || characterCount <= 0 || rate <= 0) return 0;
|
|
1652
|
+
return roundUSD(characterCount / 1e6 * rate);
|
|
1653
|
+
}
|
|
1654
|
+
function calculateOpenAiSttCost(durationSeconds) {
|
|
1655
|
+
const rate = VOICE_MODEL_PRICING[VOICE_MODEL_CONSTANTS.OPENAI_STT]?.pricePerMinute ?? 0;
|
|
1656
|
+
if (!durationSeconds || durationSeconds <= 0 || rate <= 0) return 0;
|
|
1657
|
+
return roundUSD(durationSeconds / 60 * rate);
|
|
1658
|
+
}
|
|
1659
|
+
function calculateGeminiTtsCost(usage) {
|
|
1660
|
+
const pricing = VOICE_MODEL_PRICING[VOICE_MODEL_CONSTANTS.GOOGLE_TTS];
|
|
1661
|
+
return tokenPairCost(usage, pricing?.textInputPricePerM ?? 0, pricing?.audioOutputPricePerM ?? 0);
|
|
1662
|
+
}
|
|
1663
|
+
function calculateGeminiSttCost(usage) {
|
|
1664
|
+
const pricing = VOICE_MODEL_PRICING[VOICE_MODEL_CONSTANTS.GOOGLE_STT];
|
|
1665
|
+
return tokenPairCost(usage, pricing?.audioInputPricePerM ?? 0, pricing?.textOutputPricePerM ?? 0);
|
|
1666
|
+
}
|
|
1667
|
+
function tokenPairCost(usage, inputRate, outputRate) {
|
|
1668
|
+
const inputTokens = Math.max(0, usage.inputTokens || 0);
|
|
1669
|
+
const outputTokens = Math.max(0, usage.outputTokens || 0);
|
|
1670
|
+
return inputTokens / 1e6 * inputRate + outputTokens / 1e6 * outputRate;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
// src/voice/openai-tts.ts
|
|
1674
|
+
import { OpenAI } from "openai";
|
|
1675
|
+
async function generateOpenAiTtsAudio(text, apiKey, options = {}) {
|
|
1676
|
+
const client = new OpenAI({ apiKey });
|
|
1677
|
+
const speechOptions = {
|
|
1678
|
+
model: VOICE_MODEL_CONSTANTS.OPENAI_TTS,
|
|
1679
|
+
voice: options.voice || "alloy",
|
|
1680
|
+
input: text,
|
|
1681
|
+
speed: options.speed || 1,
|
|
1682
|
+
response_format: options.format || "wav"
|
|
1683
|
+
};
|
|
1684
|
+
if (options.instructions) {
|
|
1685
|
+
speechOptions.instructions = options.instructions;
|
|
1686
|
+
}
|
|
1687
|
+
const response = await client.audio.speech.create(speechOptions);
|
|
1688
|
+
return await response.arrayBuffer();
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// src/voice/openai-stt.ts
|
|
1692
|
+
import { OpenAI as OpenAI2 } from "openai";
|
|
1693
|
+
async function transcribeWithOpenAi(audioBuffer, apiKey, options = {}) {
|
|
1694
|
+
const client = new OpenAI2({ apiKey });
|
|
1695
|
+
const audioFile = new File([new Uint8Array(audioBuffer)], options.fileName || "audio.webm", { type: options.mimeType || "audio/webm" });
|
|
1696
|
+
const transcription = await client.audio.transcriptions.create({
|
|
1697
|
+
file: audioFile,
|
|
1698
|
+
model: VOICE_MODEL_CONSTANTS.OPENAI_STT,
|
|
1699
|
+
language: options.language || "en",
|
|
1700
|
+
prompt: options.prompt,
|
|
1701
|
+
temperature: options.temperature || 0,
|
|
1702
|
+
response_format: "verbose_json"
|
|
1703
|
+
});
|
|
1704
|
+
const explicitDuration = Number(transcription?.duration) || 0;
|
|
1705
|
+
const segments = Array.isArray(transcription?.segments) ? transcription.segments : [];
|
|
1706
|
+
const segmentsDuration = segments.reduce((max, segment) => {
|
|
1707
|
+
const end = Number(segment?.end);
|
|
1708
|
+
return end > max ? end : max;
|
|
1709
|
+
}, 0);
|
|
1710
|
+
const text = typeof transcription?.text === "string" ? transcription.text : segments.map((segment) => segment?.text || "").join(" ");
|
|
1711
|
+
return { text: text.trim(), durationSeconds: explicitDuration || segmentsDuration };
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
// src/voice/openai-voice-agent.ts
|
|
1715
|
+
var OpenAiVoiceAgent = class {
|
|
1716
|
+
constructor(apiKey) {
|
|
1717
|
+
this.apiKey = apiKey;
|
|
1718
|
+
}
|
|
1719
|
+
apiKey;
|
|
1720
|
+
provider = "openai";
|
|
1721
|
+
ttsModel = VOICE_MODEL_CONSTANTS.OPENAI_TTS;
|
|
1722
|
+
sttModel = VOICE_MODEL_CONSTANTS.OPENAI_STT;
|
|
1723
|
+
async speak(request) {
|
|
1724
|
+
const audio = await generateOpenAiTtsAudio(request.text, this.apiKey, {
|
|
1725
|
+
voice: request.voice,
|
|
1726
|
+
instructions: request.voiceStyle || void 0
|
|
1727
|
+
});
|
|
1728
|
+
const characters = request.text.length;
|
|
1729
|
+
return { audio, costUSD: calculateOpenAiTtsCost(characters), usage: { characters } };
|
|
1730
|
+
}
|
|
1731
|
+
async transcribe(request) {
|
|
1732
|
+
const { text, durationSeconds } = await transcribeWithOpenAi(request.audio, this.apiKey, {
|
|
1733
|
+
language: request.language,
|
|
1734
|
+
prompt: request.prompt,
|
|
1735
|
+
fileName: request.fileName,
|
|
1736
|
+
mimeType: request.mimeType
|
|
1737
|
+
});
|
|
1738
|
+
return { text, durationSeconds, costUSD: calculateOpenAiSttCost(durationSeconds), usage: { audioSeconds: durationSeconds } };
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
|
|
1742
|
+
// src/voice/google-tts.ts
|
|
1743
|
+
import { GoogleGenAI } from "@google/genai";
|
|
1744
|
+
var AUDIO_TOKENS_PER_SECOND = 32;
|
|
1745
|
+
var SAMPLE_RATE = 24e3;
|
|
1746
|
+
var PCM_BYTES_PER_SECOND = SAMPLE_RATE * 2;
|
|
1747
|
+
function buildGoogleTtsPrompt(text, voiceStyle) {
|
|
1748
|
+
const style = voiceStyle?.trim().replace(/[:.!,;\s]+$/, "");
|
|
1749
|
+
if (!style) return text;
|
|
1750
|
+
const isShort = style.split(/\s+/).length <= 3 && !/[.!?,;]/.test(style);
|
|
1751
|
+
return isShort ? `Say ${style}: ${text}` : `${style}:
|
|
1752
|
+
${text}`;
|
|
1753
|
+
}
|
|
1754
|
+
function pcmToWav(pcmData, sampleRate = SAMPLE_RATE) {
|
|
1755
|
+
const numChannels = 1;
|
|
1756
|
+
const bitsPerSample = 16;
|
|
1757
|
+
const blockAlign = numChannels * (bitsPerSample / 8);
|
|
1758
|
+
const byteRate = sampleRate * blockAlign;
|
|
1759
|
+
const headerSize = 44;
|
|
1760
|
+
const buffer = new ArrayBuffer(headerSize + pcmData.length);
|
|
1761
|
+
const view = new DataView(buffer);
|
|
1762
|
+
const writeString = (offset, str) => {
|
|
1763
|
+
for (let i = 0; i < str.length; i++) view.setUint8(offset + i, str.charCodeAt(i));
|
|
1764
|
+
};
|
|
1765
|
+
writeString(0, "RIFF");
|
|
1766
|
+
view.setUint32(4, 36 + pcmData.length, true);
|
|
1767
|
+
writeString(8, "WAVE");
|
|
1768
|
+
writeString(12, "fmt ");
|
|
1769
|
+
view.setUint32(16, 16, true);
|
|
1770
|
+
view.setUint16(20, 1, true);
|
|
1771
|
+
view.setUint16(22, numChannels, true);
|
|
1772
|
+
view.setUint32(24, sampleRate, true);
|
|
1773
|
+
view.setUint32(28, byteRate, true);
|
|
1774
|
+
view.setUint16(32, blockAlign, true);
|
|
1775
|
+
view.setUint16(34, bitsPerSample, true);
|
|
1776
|
+
writeString(36, "data");
|
|
1777
|
+
view.setUint32(40, pcmData.length, true);
|
|
1778
|
+
new Uint8Array(buffer, headerSize).set(pcmData);
|
|
1779
|
+
return buffer;
|
|
1780
|
+
}
|
|
1781
|
+
async function generateGoogleTtsAudio(text, apiKey, options) {
|
|
1782
|
+
const client = new GoogleGenAI({ apiKey });
|
|
1783
|
+
const response = await client.models.generateContent({
|
|
1784
|
+
model: VOICE_MODEL_CONSTANTS.GOOGLE_TTS,
|
|
1785
|
+
contents: [{ parts: [{ text: buildGoogleTtsPrompt(text, options.voiceStyle) }] }],
|
|
1786
|
+
config: {
|
|
1787
|
+
responseModalities: ["AUDIO"],
|
|
1788
|
+
speechConfig: { voiceConfig: { prebuiltVoiceConfig: { voiceName: options.voiceName } } }
|
|
1789
|
+
}
|
|
1790
|
+
});
|
|
1791
|
+
const parts = response.candidates?.[0]?.content?.parts ?? [];
|
|
1792
|
+
const audioPart = parts.find((part) => part.inlineData?.mimeType?.startsWith("audio/"));
|
|
1793
|
+
if (!audioPart?.inlineData?.data) {
|
|
1794
|
+
throw new Error("No audio data in Google TTS response");
|
|
1795
|
+
}
|
|
1796
|
+
const pcmData = new Uint8Array(Buffer.from(audioPart.inlineData.data, "base64"));
|
|
1797
|
+
const usageMetadata = response.usageMetadata ?? {};
|
|
1798
|
+
const inputTokens = usageMetadata.promptTokenCount ?? 0;
|
|
1799
|
+
const reportedOutput = usageMetadata.candidatesTokenCount;
|
|
1800
|
+
const outputTokens = reportedOutput && reportedOutput > 0 ? reportedOutput : Math.ceil(pcmData.length / PCM_BYTES_PER_SECOND * AUDIO_TOKENS_PER_SECOND);
|
|
1801
|
+
return { audio: pcmToWav(pcmData), usage: { inputTokens, outputTokens } };
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
// src/voice/google-stt.ts
|
|
1805
|
+
import { GoogleGenAI as GoogleGenAI2 } from "@google/genai";
|
|
1806
|
+
var GEMINI_AUDIO_TOKENS_PER_SECOND = 25;
|
|
1807
|
+
async function transcribeWithGemini(audioBuffer, apiKey, options = {}) {
|
|
1808
|
+
const client = new GoogleGenAI2({ apiKey });
|
|
1809
|
+
const interaction = await client.interactions.create({
|
|
1810
|
+
model: VOICE_MODEL_CONSTANTS.GOOGLE_STT,
|
|
1811
|
+
input: [{ type: "audio", data: Buffer.from(audioBuffer).toString("base64"), mime_type: options.mimeType || "audio/webm" }]
|
|
1812
|
+
});
|
|
1813
|
+
const text = typeof interaction?.output_text === "string" ? interaction.output_text.trim() : "";
|
|
1814
|
+
const usage = interaction?.usage ?? {};
|
|
1815
|
+
const byModality = (rows, modality) => (rows ?? []).filter((r) => r?.modality === modality).reduce((sum, r) => sum + (Number(r?.tokens) || 0), 0);
|
|
1816
|
+
const inputTokens = byModality(usage.input_tokens_by_modality, "audio") || usage.total_input_tokens || 0;
|
|
1817
|
+
const invocationOutput = (usage.model_invocation_token_counts ?? []).reduce((sum, inv) => sum + (inv?.candidates_tokens_details ?? []).reduce((s, d) => s + (Number(d?.tokens) || 0), 0), 0);
|
|
1818
|
+
const outputTokens = usage.total_output_tokens || invocationOutput || Math.ceil(text.length / 4);
|
|
1819
|
+
return { text, durationSeconds: inputTokens / GEMINI_AUDIO_TOKENS_PER_SECOND, usage: { inputTokens, outputTokens } };
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
// src/voice/google-voice-agent.ts
|
|
1823
|
+
var GoogleVoiceAgent = class {
|
|
1824
|
+
constructor(apiKey) {
|
|
1825
|
+
this.apiKey = apiKey;
|
|
1826
|
+
}
|
|
1827
|
+
apiKey;
|
|
1828
|
+
provider = "google";
|
|
1829
|
+
ttsModel = VOICE_MODEL_CONSTANTS.GOOGLE_TTS;
|
|
1830
|
+
sttModel = VOICE_MODEL_CONSTANTS.GOOGLE_STT;
|
|
1831
|
+
async speak(request) {
|
|
1832
|
+
const { audio, usage } = await generateGoogleTtsAudio(request.text, this.apiKey, {
|
|
1833
|
+
voiceName: request.voice,
|
|
1834
|
+
voiceStyle: request.voiceStyle
|
|
1835
|
+
});
|
|
1836
|
+
return { audio, costUSD: calculateGeminiTtsCost(usage), usage };
|
|
1837
|
+
}
|
|
1838
|
+
async transcribe(request) {
|
|
1839
|
+
const { text, durationSeconds, usage } = await transcribeWithGemini(request.audio, this.apiKey, { mimeType: request.mimeType });
|
|
1840
|
+
return { text, durationSeconds, costUSD: calculateGeminiSttCost(usage), usage };
|
|
1841
|
+
}
|
|
1842
|
+
};
|
|
1843
|
+
|
|
1844
|
+
// src/voice/voice-agent-factory.ts
|
|
1845
|
+
var VoiceAgentFactory = class _VoiceAgentFactory {
|
|
1846
|
+
/** Build an agent from a key already resolved by the caller. */
|
|
1847
|
+
static createAgent(provider, apiKey) {
|
|
1848
|
+
switch (provider) {
|
|
1849
|
+
case "openai":
|
|
1850
|
+
return new OpenAiVoiceAgent(apiKey);
|
|
1851
|
+
case "google":
|
|
1852
|
+
return new GoogleVoiceAgent(apiKey);
|
|
1853
|
+
default:
|
|
1854
|
+
throw new Error(`Unknown voice provider: ${provider}`);
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Build an agent from a key map (the shape AgentFactory takes), reading the
|
|
1859
|
+
* provider's key by its API_KEY_CONSTANTS name. Throws when the key is missing
|
|
1860
|
+
* so the host can report a misconfiguration before any SDK is touched.
|
|
1861
|
+
*/
|
|
1862
|
+
static createAgentFromKeys(provider, apiKeys) {
|
|
1863
|
+
if (!SUPPORTED_VOICE_PROVIDERS.includes(provider)) {
|
|
1864
|
+
throw new Error(`Unknown voice provider: ${provider}`);
|
|
1865
|
+
}
|
|
1866
|
+
const keyName = VOICE_PROVIDER_API_KEY[provider];
|
|
1867
|
+
const apiKey = apiKeys[keyName];
|
|
1868
|
+
if (!apiKey) {
|
|
1869
|
+
throw new Error(`Missing API key ${keyName} for voice provider ${provider}`);
|
|
1870
|
+
}
|
|
1871
|
+
return _VoiceAgentFactory.createAgent(provider, apiKey);
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
function createVoiceAgent(provider, apiKey) {
|
|
1875
|
+
return VoiceAgentFactory.createAgent(provider, apiKey);
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1621
1878
|
// src/agents/abstract-agent.ts
|
|
1622
1879
|
var AbstractAgent = class {
|
|
1623
1880
|
name;
|
|
@@ -1764,8 +2021,7 @@ ${msg.content}` };
|
|
|
1764
2021
|
};
|
|
1765
2022
|
|
|
1766
2023
|
// src/agents/gpt-5-agent.ts
|
|
1767
|
-
import
|
|
1768
|
-
import { z as z2 } from "zod";
|
|
2024
|
+
import OpenAI3 from "openai";
|
|
1769
2025
|
import { zodTextFormat } from "openai/helpers/zod";
|
|
1770
2026
|
var Gpt5Agent = class extends AbstractAgent {
|
|
1771
2027
|
client;
|
|
@@ -1781,7 +2037,7 @@ var Gpt5Agent = class extends AbstractAgent {
|
|
|
1781
2037
|
};
|
|
1782
2038
|
constructor(name, instruction, model, apiKey, temperature, enableThinking = false, agentLoggingConfig = DEFAULT_LOGGING_CONFIG.agents) {
|
|
1783
2039
|
super(name, instruction, model, temperature, enableThinking, agentLoggingConfig);
|
|
1784
|
-
this.client = new
|
|
2040
|
+
this.client = new OpenAI3({
|
|
1785
2041
|
apiKey
|
|
1786
2042
|
});
|
|
1787
2043
|
}
|
|
@@ -1799,12 +2055,7 @@ var Gpt5Agent = class extends AbstractAgent {
|
|
|
1799
2055
|
`System: ${this.instruction}`,
|
|
1800
2056
|
...this.prepareMessages(messages).map((msg) => `${msg.role === "user" ? "User" : "Assistant"}: ${msg.content}`)
|
|
1801
2057
|
].join("\n\n");
|
|
1802
|
-
|
|
1803
|
-
if (this.enableThinking && zodSchema instanceof z2.ZodObject) {
|
|
1804
|
-
schemaToSend = zodSchema.extend({
|
|
1805
|
-
thinking: z2.string().describe("Your internal chain-of-thought reasoning process used to arrive at the final answer.")
|
|
1806
|
-
});
|
|
1807
|
-
}
|
|
2058
|
+
const schemaToSend = zodSchema;
|
|
1808
2059
|
let response;
|
|
1809
2060
|
try {
|
|
1810
2061
|
response = await this.client.responses.parse({
|
|
@@ -2318,7 +2569,7 @@ ${schemaDescription}`;
|
|
|
2318
2569
|
};
|
|
2319
2570
|
|
|
2320
2571
|
// src/agents/google-agent.ts
|
|
2321
|
-
import { GoogleGenAI } from "@google/genai";
|
|
2572
|
+
import { GoogleGenAI as GoogleGenAI3 } from "@google/genai";
|
|
2322
2573
|
var GoogleAgent = class extends AbstractAgent {
|
|
2323
2574
|
client;
|
|
2324
2575
|
defaultConfig = {
|
|
@@ -2337,7 +2588,7 @@ var GoogleAgent = class extends AbstractAgent {
|
|
|
2337
2588
|
};
|
|
2338
2589
|
constructor(name, instruction, model, apiKey, enableThinking = false, agentLoggingConfig = DEFAULT_LOGGING_CONFIG.agents) {
|
|
2339
2590
|
super(name, instruction, model, 0.2, enableThinking, agentLoggingConfig);
|
|
2340
|
-
this.client = new
|
|
2591
|
+
this.client = new GoogleGenAI3({
|
|
2341
2592
|
apiKey
|
|
2342
2593
|
});
|
|
2343
2594
|
}
|
|
@@ -2898,7 +3149,7 @@ ${schemaDescription}`
|
|
|
2898
3149
|
};
|
|
2899
3150
|
|
|
2900
3151
|
// src/agents/deepseek-v2-agent.ts
|
|
2901
|
-
import
|
|
3152
|
+
import OpenAI4 from "openai";
|
|
2902
3153
|
var DeepSeekV2Agent = class extends AbstractAgent {
|
|
2903
3154
|
client;
|
|
2904
3155
|
// Log message templates
|
|
@@ -2914,7 +3165,7 @@ var DeepSeekV2Agent = class extends AbstractAgent {
|
|
|
2914
3165
|
};
|
|
2915
3166
|
constructor(name, instruction, model, apiKey, temperature, enableThinking = false, agentLoggingConfig = DEFAULT_LOGGING_CONFIG.agents) {
|
|
2916
3167
|
super(name, instruction, model, temperature, enableThinking, agentLoggingConfig);
|
|
2917
|
-
this.client = new
|
|
3168
|
+
this.client = new OpenAI4({
|
|
2918
3169
|
baseURL: "https://api.deepseek.com",
|
|
2919
3170
|
apiKey
|
|
2920
3171
|
});
|
|
@@ -3106,7 +3357,7 @@ ${schemaDescription}`
|
|
|
3106
3357
|
};
|
|
3107
3358
|
|
|
3108
3359
|
// src/agents/grok-agent.ts
|
|
3109
|
-
import { OpenAI as
|
|
3360
|
+
import { OpenAI as OpenAI5 } from "openai";
|
|
3110
3361
|
var GrokAgent = class extends AbstractAgent {
|
|
3111
3362
|
client;
|
|
3112
3363
|
// Log message templates
|
|
@@ -3123,7 +3374,7 @@ var GrokAgent = class extends AbstractAgent {
|
|
|
3123
3374
|
super(name, instruction, model, temperature, enableThinking, agentLoggingConfig);
|
|
3124
3375
|
const convId = stableHashHex(`${name}
|
|
3125
3376
|
${instruction}`);
|
|
3126
|
-
this.client = new
|
|
3377
|
+
this.client = new OpenAI5({
|
|
3127
3378
|
apiKey,
|
|
3128
3379
|
baseURL: "https://api.x.ai/v1",
|
|
3129
3380
|
timeout: 12e5,
|
|
@@ -3296,7 +3547,7 @@ ${input[0].content}`;
|
|
|
3296
3547
|
};
|
|
3297
3548
|
|
|
3298
3549
|
// src/agents/kimi-agent.ts
|
|
3299
|
-
import { OpenAI as
|
|
3550
|
+
import { OpenAI as OpenAI6 } from "openai";
|
|
3300
3551
|
var KimiAgent = class extends AbstractAgent {
|
|
3301
3552
|
client;
|
|
3302
3553
|
// kimi-k3 rejects any temperature other than 1, so we never send the field.
|
|
@@ -3323,7 +3574,7 @@ var KimiAgent = class extends AbstractAgent {
|
|
|
3323
3574
|
};
|
|
3324
3575
|
constructor(name, instruction, model, apiKey, temperature, enableThinking = false, agentLoggingConfig = DEFAULT_LOGGING_CONFIG.agents) {
|
|
3325
3576
|
super(name, instruction, model, temperature, enableThinking, agentLoggingConfig);
|
|
3326
|
-
this.client = new
|
|
3577
|
+
this.client = new OpenAI6({
|
|
3327
3578
|
apiKey,
|
|
3328
3579
|
baseURL: "https://api.moonshot.ai/v1"
|
|
3329
3580
|
});
|
|
@@ -3514,7 +3765,7 @@ ${openAIMessages[0].content}`;
|
|
|
3514
3765
|
};
|
|
3515
3766
|
|
|
3516
3767
|
// src/agents/glm-agent.ts
|
|
3517
|
-
import { OpenAI as
|
|
3768
|
+
import { OpenAI as OpenAI7 } from "openai";
|
|
3518
3769
|
var GlmAgent = class extends AbstractAgent {
|
|
3519
3770
|
client;
|
|
3520
3771
|
// A getter, not a field: `maxOutputTokens` can be raised after construction, and a field
|
|
@@ -3540,7 +3791,7 @@ var GlmAgent = class extends AbstractAgent {
|
|
|
3540
3791
|
};
|
|
3541
3792
|
constructor(name, instruction, model, apiKey, temperature, enableThinking = false, agentLoggingConfig = DEFAULT_LOGGING_CONFIG.agents) {
|
|
3542
3793
|
super(name, instruction, model, temperature, enableThinking, agentLoggingConfig);
|
|
3543
|
-
this.client = new
|
|
3794
|
+
this.client = new OpenAI7({
|
|
3544
3795
|
apiKey,
|
|
3545
3796
|
baseURL: "https://api.z.ai/api/paas/v4/"
|
|
3546
3797
|
});
|
|
@@ -3694,7 +3945,7 @@ ${openAIMessages[0].content}`;
|
|
|
3694
3945
|
};
|
|
3695
3946
|
|
|
3696
3947
|
// src/agents/fugu-agent.ts
|
|
3697
|
-
import { OpenAI as
|
|
3948
|
+
import { OpenAI as OpenAI8 } from "openai";
|
|
3698
3949
|
var FuguAgent = class extends AbstractAgent {
|
|
3699
3950
|
client;
|
|
3700
3951
|
// A getter, not a field: `maxOutputTokens` can be raised after construction, and a field
|
|
@@ -3718,7 +3969,7 @@ var FuguAgent = class extends AbstractAgent {
|
|
|
3718
3969
|
};
|
|
3719
3970
|
constructor(name, instruction, model, apiKey, enableThinking = false, agentLoggingConfig = DEFAULT_LOGGING_CONFIG.agents) {
|
|
3720
3971
|
super(name, instruction, model, 1, enableThinking, agentLoggingConfig);
|
|
3721
|
-
this.client = new
|
|
3972
|
+
this.client = new OpenAI8({
|
|
3722
3973
|
apiKey,
|
|
3723
3974
|
baseURL: "https://api.sakana.ai/v1",
|
|
3724
3975
|
timeout: 12e5
|
|
@@ -3885,7 +4136,7 @@ ${schemaDescription}`;
|
|
|
3885
4136
|
};
|
|
3886
4137
|
|
|
3887
4138
|
// src/agents/qwen-agent.ts
|
|
3888
|
-
import { OpenAI as
|
|
4139
|
+
import { OpenAI as OpenAI9 } from "openai";
|
|
3889
4140
|
var QwenAgent = class extends AbstractAgent {
|
|
3890
4141
|
client;
|
|
3891
4142
|
// A getter, not a field: `maxOutputTokens` can be raised after construction, and a field
|
|
@@ -3910,7 +4161,7 @@ var QwenAgent = class extends AbstractAgent {
|
|
|
3910
4161
|
};
|
|
3911
4162
|
constructor(name, instruction, model, apiKey, temperature, enableThinking = false, agentLoggingConfig = DEFAULT_LOGGING_CONFIG.agents) {
|
|
3912
4163
|
super(name, instruction, model, temperature, enableThinking, agentLoggingConfig);
|
|
3913
|
-
this.client = new
|
|
4164
|
+
this.client = new OpenAI9({
|
|
3914
4165
|
apiKey,
|
|
3915
4166
|
baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
|
|
3916
4167
|
});
|
|
@@ -4085,7 +4336,7 @@ ${openAIMessages[0].content}`;
|
|
|
4085
4336
|
};
|
|
4086
4337
|
|
|
4087
4338
|
// src/agents/minimax-agent.ts
|
|
4088
|
-
import { OpenAI as
|
|
4339
|
+
import { OpenAI as OpenAI10 } from "openai";
|
|
4089
4340
|
var MiniMaxAgent = class extends AbstractAgent {
|
|
4090
4341
|
client;
|
|
4091
4342
|
// A getter, not a field: `maxOutputTokens` can be raised after construction, and a field
|
|
@@ -4110,7 +4361,7 @@ var MiniMaxAgent = class extends AbstractAgent {
|
|
|
4110
4361
|
};
|
|
4111
4362
|
constructor(name, instruction, model, apiKey, temperature, enableThinking = false, agentLoggingConfig = DEFAULT_LOGGING_CONFIG.agents) {
|
|
4112
4363
|
super(name, instruction, model, temperature, enableThinking, agentLoggingConfig);
|
|
4113
|
-
this.client = new
|
|
4364
|
+
this.client = new OpenAI10({
|
|
4114
4365
|
apiKey,
|
|
4115
4366
|
baseURL: "https://api.minimax.io/v1"
|
|
4116
4367
|
});
|
|
@@ -4347,10 +4598,12 @@ export {
|
|
|
4347
4598
|
DeepSeekV2Agent,
|
|
4348
4599
|
FUGU_REASONING_EFFORTS,
|
|
4349
4600
|
FuguAgent,
|
|
4601
|
+
GEMINI_AUDIO_TOKENS_PER_SECOND,
|
|
4350
4602
|
GEMINI_REASONING_EFFORTS,
|
|
4351
4603
|
GLM_REASONING_EFFORTS,
|
|
4352
4604
|
GlmAgent,
|
|
4353
4605
|
GoogleAgent,
|
|
4606
|
+
GoogleVoiceAgent,
|
|
4354
4607
|
Gpt5Agent,
|
|
4355
4608
|
GrokAgent,
|
|
4356
4609
|
KimiAgent,
|
|
@@ -4368,23 +4621,35 @@ export {
|
|
|
4368
4621
|
ModelRefusalError,
|
|
4369
4622
|
ModelUnavailableError,
|
|
4370
4623
|
OPENAI_REASONING_EFFORTS,
|
|
4624
|
+
OpenAiVoiceAgent,
|
|
4371
4625
|
QwenAgent,
|
|
4372
4626
|
REASONING_EFFORT_SCALE,
|
|
4627
|
+
SUPPORTED_VOICE_PROVIDERS,
|
|
4373
4628
|
SupportedAiKeyNames,
|
|
4374
4629
|
SupportedAiModels,
|
|
4630
|
+
VOICE_MODEL_CONSTANTS,
|
|
4631
|
+
VOICE_MODEL_PRICING,
|
|
4632
|
+
VOICE_PROVIDER_API_KEY,
|
|
4633
|
+
VoiceAgentFactory,
|
|
4375
4634
|
ZodSchemaConverter,
|
|
4635
|
+
buildGoogleTtsPrompt,
|
|
4376
4636
|
calculateAnthropicCost,
|
|
4377
4637
|
calculateCost,
|
|
4378
4638
|
calculateDeepSeekCost,
|
|
4639
|
+
calculateGeminiSttCost,
|
|
4640
|
+
calculateGeminiTtsCost,
|
|
4379
4641
|
calculateGoogleCost,
|
|
4380
4642
|
calculateGrokCost,
|
|
4381
4643
|
calculateKimiCost,
|
|
4382
4644
|
calculateMistralCost,
|
|
4383
4645
|
calculateModelCost,
|
|
4384
4646
|
calculateOpenAICost,
|
|
4647
|
+
calculateOpenAiSttCost,
|
|
4648
|
+
calculateOpenAiTtsCost,
|
|
4385
4649
|
clampReasoningEffort,
|
|
4386
4650
|
cleanResponse,
|
|
4387
4651
|
createCatalog,
|
|
4652
|
+
createVoiceAgent,
|
|
4388
4653
|
extractAnthropicTokenUsage,
|
|
4389
4654
|
extractTokenUsageFromResponse5 as extractAnthropicTokenUsageFromResponse,
|
|
4390
4655
|
extractDeepSeekTokenUsage,
|
|
@@ -4402,6 +4667,8 @@ export {
|
|
|
4402
4667
|
extractTokenUsageFromResponse as extractOpenAITokenUsageFromResponse,
|
|
4403
4668
|
extractTokenUsage,
|
|
4404
4669
|
extractUsageAndCalculateCost,
|
|
4670
|
+
generateGoogleTtsAudio,
|
|
4671
|
+
generateOpenAiTtsAudio,
|
|
4405
4672
|
generateSchemaInstructions,
|
|
4406
4673
|
getModelConfigByApiName,
|
|
4407
4674
|
getModelDisplayName,
|
|
@@ -4418,6 +4685,7 @@ export {
|
|
|
4418
4685
|
modelIsFast,
|
|
4419
4686
|
needsPromptBasedSchema,
|
|
4420
4687
|
parseAndValidateLlmJson,
|
|
4688
|
+
pcmToWav,
|
|
4421
4689
|
safeValidateResponse,
|
|
4422
4690
|
setLlmLogger,
|
|
4423
4691
|
stableHashHex,
|
|
@@ -4429,6 +4697,8 @@ export {
|
|
|
4429
4697
|
toGeminiEffort,
|
|
4430
4698
|
toGlmEffort,
|
|
4431
4699
|
toOpenAIEffort,
|
|
4700
|
+
transcribeWithGemini,
|
|
4701
|
+
transcribeWithOpenAi,
|
|
4432
4702
|
validateResponse
|
|
4433
4703
|
};
|
|
4434
4704
|
//# sourceMappingURL=index.mjs.map
|