chore: format audioAsVoice updates
Co-authored-by: Manuel Hettich <17690367+ManuelHettich@users.noreply.github.com>
This commit is contained in:
committed by
Peter Steinberger
parent
8c7d1781bc
commit
5fedfd8d15
@@ -1658,10 +1658,17 @@ export async function runEmbeddedPiAgent(params: {
|
|||||||
if (inlineToolResults) {
|
if (inlineToolResults) {
|
||||||
for (const { toolName, meta } of toolMetas) {
|
for (const { toolName, meta } of toolMetas) {
|
||||||
const agg = formatToolAggregate(toolName, meta ? [meta] : []);
|
const agg = formatToolAggregate(toolName, meta ? [meta] : []);
|
||||||
const { text: cleanedText, mediaUrls, audioAsVoice } =
|
const {
|
||||||
splitMediaFromOutput(agg);
|
text: cleanedText,
|
||||||
|
mediaUrls,
|
||||||
|
audioAsVoice,
|
||||||
|
} = splitMediaFromOutput(agg);
|
||||||
if (cleanedText)
|
if (cleanedText)
|
||||||
replyItems.push({ text: cleanedText, media: mediaUrls, audioAsVoice });
|
replyItems.push({
|
||||||
|
text: cleanedText,
|
||||||
|
media: mediaUrls,
|
||||||
|
audioAsVoice,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1680,15 +1687,22 @@ export async function runEmbeddedPiAgent(params: {
|
|||||||
? [fallbackAnswerText]
|
? [fallbackAnswerText]
|
||||||
: [];
|
: [];
|
||||||
for (const text of answerTexts) {
|
for (const text of answerTexts) {
|
||||||
const { text: cleanedText, mediaUrls, audioAsVoice } =
|
const {
|
||||||
splitMediaFromOutput(text);
|
text: cleanedText,
|
||||||
|
mediaUrls,
|
||||||
|
audioAsVoice,
|
||||||
|
} = splitMediaFromOutput(text);
|
||||||
if (
|
if (
|
||||||
!cleanedText &&
|
!cleanedText &&
|
||||||
(!mediaUrls || mediaUrls.length === 0) &&
|
(!mediaUrls || mediaUrls.length === 0) &&
|
||||||
!audioAsVoice
|
!audioAsVoice
|
||||||
)
|
)
|
||||||
continue;
|
continue;
|
||||||
replyItems.push({ text: cleanedText, media: mediaUrls, audioAsVoice });
|
replyItems.push({
|
||||||
|
text: cleanedText,
|
||||||
|
media: mediaUrls,
|
||||||
|
audioAsVoice,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if any replyItem has audioAsVoice tag - if so, apply to all media payloads
|
// Check if any replyItem has audioAsVoice tag - if so, apply to all media payloads
|
||||||
|
|||||||
@@ -440,7 +440,8 @@ export function subscribeEmbeddedPiSession(params: {
|
|||||||
const splitResult = splitMediaFromOutput(chunk);
|
const splitResult = splitMediaFromOutput(chunk);
|
||||||
const { text: cleanedText, mediaUrls, audioAsVoice } = splitResult;
|
const { text: cleanedText, mediaUrls, audioAsVoice } = splitResult;
|
||||||
// Skip empty payloads, but always emit if audioAsVoice is set (to propagate the flag)
|
// Skip empty payloads, but always emit if audioAsVoice is set (to propagate the flag)
|
||||||
if (!cleanedText && (!mediaUrls || mediaUrls.length === 0) && !audioAsVoice) return;
|
if (!cleanedText && (!mediaUrls || mediaUrls.length === 0) && !audioAsVoice)
|
||||||
|
return;
|
||||||
void params.onBlockReply({
|
void params.onBlockReply({
|
||||||
text: cleanedText,
|
text: cleanedText,
|
||||||
mediaUrls: mediaUrls?.length ? mediaUrls : undefined,
|
mediaUrls: mediaUrls?.length ? mediaUrls : undefined,
|
||||||
@@ -863,8 +864,11 @@ export function subscribeEmbeddedPiSession(params: {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
lastBlockReplyText = text;
|
lastBlockReplyText = text;
|
||||||
const { text: cleanedText, mediaUrls, audioAsVoice } =
|
const {
|
||||||
splitMediaFromOutput(text);
|
text: cleanedText,
|
||||||
|
mediaUrls,
|
||||||
|
audioAsVoice,
|
||||||
|
} = splitMediaFromOutput(text);
|
||||||
// Emit if there's content OR audioAsVoice flag (to propagate the flag)
|
// Emit if there's content OR audioAsVoice flag (to propagate the flag)
|
||||||
if (
|
if (
|
||||||
cleanedText ||
|
cleanedText ||
|
||||||
|
|||||||
@@ -541,7 +541,10 @@ export async function runReplyAgent(params: {
|
|||||||
sessionCtx.MessageSid,
|
sessionCtx.MessageSid,
|
||||||
);
|
);
|
||||||
// Let through payloads with audioAsVoice flag even if empty (need to track it)
|
// Let through payloads with audioAsVoice flag even if empty (need to track it)
|
||||||
if (!isRenderablePayload(taggedPayload) && !payload.audioAsVoice)
|
if (
|
||||||
|
!isRenderablePayload(taggedPayload) &&
|
||||||
|
!payload.audioAsVoice
|
||||||
|
)
|
||||||
return;
|
return;
|
||||||
const audioTagResult = extractAudioTag(taggedPayload.text);
|
const audioTagResult = extractAudioTag(taggedPayload.text);
|
||||||
const cleaned = audioTagResult.cleaned || undefined;
|
const cleaned = audioTagResult.cleaned || undefined;
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ export function splitMediaFromOutput(raw: string): {
|
|||||||
if (media.length === 0) {
|
if (media.length === 0) {
|
||||||
const result: ReturnType<typeof splitMediaFromOutput> = {
|
const result: ReturnType<typeof splitMediaFromOutput> = {
|
||||||
// Return cleaned text if we found a media token OR audio tag, otherwise original
|
// Return cleaned text if we found a media token OR audio tag, otherwise original
|
||||||
text: (foundMediaToken || hasAudioAsVoice) ? cleanedText : trimmedRaw,
|
text: foundMediaToken || hasAudioAsVoice ? cleanedText : trimmedRaw,
|
||||||
};
|
};
|
||||||
if (hasAudioAsVoice) result.audioAsVoice = true;
|
if (hasAudioAsVoice) result.audioAsVoice = true;
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ import { resolveTelegramAccount } from "./accounts.js";
|
|||||||
import { createTelegramDraftStream } from "./draft-stream.js";
|
import { createTelegramDraftStream } from "./draft-stream.js";
|
||||||
import { resolveTelegramFetch } from "./fetch.js";
|
import { resolveTelegramFetch } from "./fetch.js";
|
||||||
import { markdownToTelegramHtml } from "./format.js";
|
import { markdownToTelegramHtml } from "./format.js";
|
||||||
import { resolveTelegramVoiceDecision } from "./voice.js";
|
|
||||||
import {
|
import {
|
||||||
readTelegramAllowFromStore,
|
readTelegramAllowFromStore,
|
||||||
upsertTelegramPairingRequest,
|
upsertTelegramPairingRequest,
|
||||||
} from "./pairing-store.js";
|
} from "./pairing-store.js";
|
||||||
|
import { resolveTelegramVoiceDecision } from "./voice.js";
|
||||||
|
|
||||||
const PARSE_ERR_RE =
|
const PARSE_ERR_RE =
|
||||||
/can't parse entities|parse entities|find end of the entity/i;
|
/can't parse entities|parse entities|find end of the entity/i;
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import type {
|
|||||||
} from "@grammyjs/types";
|
} from "@grammyjs/types";
|
||||||
import { type ApiClientOptions, Bot, InputFile } from "grammy";
|
import { type ApiClientOptions, Bot, InputFile } from "grammy";
|
||||||
import { loadConfig } from "../config/config.js";
|
import { loadConfig } from "../config/config.js";
|
||||||
|
import { logVerbose } from "../globals.js";
|
||||||
import { formatErrorMessage } from "../infra/errors.js";
|
import { formatErrorMessage } from "../infra/errors.js";
|
||||||
import { recordProviderActivity } from "../infra/provider-activity.js";
|
import { recordProviderActivity } from "../infra/provider-activity.js";
|
||||||
import type { RetryConfig } from "../infra/retry.js";
|
import type { RetryConfig } from "../infra/retry.js";
|
||||||
import { createTelegramRetryRunner } from "../infra/retry-policy.js";
|
import { createTelegramRetryRunner } from "../infra/retry-policy.js";
|
||||||
import { logVerbose } from "../globals.js";
|
|
||||||
import { mediaKindFromMime } from "../media/constants.js";
|
import { mediaKindFromMime } from "../media/constants.js";
|
||||||
import { isGifMedia } from "../media/mime.js";
|
import { isGifMedia } from "../media/mime.js";
|
||||||
import { loadWebMedia } from "../web/media.js";
|
import { loadWebMedia } from "../web/media.js";
|
||||||
|
|||||||
Reference in New Issue
Block a user