@hiper2d/ai-agents 0.5.0 → 0.5.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/dist/index.mjs CHANGED
@@ -1830,6 +1830,21 @@ function pcmToWav(pcmData, sampleRate = SAMPLE_RATE) {
1830
1830
  new Uint8Array(buffer, headerSize).set(pcmData);
1831
1831
  return buffer;
1832
1832
  }
1833
+ function describeEmptyTtsResponse(response) {
1834
+ const candidate = response?.candidates?.[0];
1835
+ const parts = candidate?.content?.parts ?? [];
1836
+ const bits = [];
1837
+ bits.push(`finishReason=${candidate?.finishReason ?? "none"}`);
1838
+ if (!response?.candidates?.length) bits.push("no candidates");
1839
+ const block = response?.promptFeedback?.blockReason;
1840
+ if (block) bits.push(`blockReason=${block}`);
1841
+ const text = parts.map((p) => typeof p?.text === "string" ? p.text : "").join(" ").trim();
1842
+ if (text) bits.push(`text="${text.slice(0, 120)}"`);
1843
+ const otherMimes = parts.map((p) => p?.inlineData?.mimeType).filter(Boolean);
1844
+ if (otherMimes.length) bits.push(`inlineData=${otherMimes.join(",")}`);
1845
+ if (!parts.length) bits.push("no parts");
1846
+ return bits.join(", ");
1847
+ }
1833
1848
  async function generateGoogleTtsAudio(text, apiKey, options) {
1834
1849
  const client = new GoogleGenAI({ apiKey });
1835
1850
  const response = await client.models.generateContent({
@@ -1840,10 +1855,11 @@ async function generateGoogleTtsAudio(text, apiKey, options) {
1840
1855
  speechConfig: { voiceConfig: { prebuiltVoiceConfig: { voiceName: options.voiceName } } }
1841
1856
  }
1842
1857
  });
1843
- const parts = response.candidates?.[0]?.content?.parts ?? [];
1858
+ const candidate = response.candidates?.[0];
1859
+ const parts = candidate?.content?.parts ?? [];
1844
1860
  const audioPart = parts.find((part) => part.inlineData?.mimeType?.startsWith("audio/"));
1845
1861
  if (!audioPart?.inlineData?.data) {
1846
- throw new Error("No audio data in Google TTS response");
1862
+ throw new Error(`No audio data in Google TTS response (${describeEmptyTtsResponse(response)})`);
1847
1863
  }
1848
1864
  const pcmData = new Uint8Array(Buffer.from(audioPart.inlineData.data, "base64"));
1849
1865
  const usageMetadata = response.usageMetadata ?? {};
@@ -5093,6 +5109,7 @@ export {
5093
5109
  cleanResponse,
5094
5110
  createCatalog,
5095
5111
  createVoiceAgent,
5112
+ describeEmptyTtsResponse,
5096
5113
  evaluateBudget,
5097
5114
  extractAnthropicTokenUsage,
5098
5115
  extractTokenUsageFromResponse6 as extractAnthropicTokenUsageFromResponse,