feat: enhance message context with full ID support for replies and caching
- Updated message processing to include full message IDs alongside short IDs for better context resolution. - Improved reply handling by caching inbound messages, allowing for accurate sender and body resolution without exposing dropped content. - Adjusted tests to validate the new full ID properties and their integration into the message handling workflow.
This commit is contained in:
@@ -299,6 +299,8 @@ export async function runAgentTurnWithFallback(params: {
|
||||
const { text, skip } = normalizeStreamingText(payload);
|
||||
const hasPayloadMedia = (payload.mediaUrls?.length ?? 0) > 0;
|
||||
if (skip && !hasPayloadMedia) return;
|
||||
const currentMessageId =
|
||||
params.sessionCtx.MessageSidFull ?? params.sessionCtx.MessageSid;
|
||||
const taggedPayload = applyReplyTagsToPayload(
|
||||
{
|
||||
text,
|
||||
@@ -308,12 +310,12 @@ export async function runAgentTurnWithFallback(params: {
|
||||
replyToTag: payload.replyToTag,
|
||||
replyToCurrent: payload.replyToCurrent,
|
||||
},
|
||||
params.sessionCtx.MessageSid,
|
||||
currentMessageId,
|
||||
);
|
||||
// Let through payloads with audioAsVoice flag even if empty (need to track it)
|
||||
if (!isRenderablePayload(taggedPayload) && !payload.audioAsVoice) return;
|
||||
const parsed = parseReplyDirectives(taggedPayload.text ?? "", {
|
||||
currentMessageId: params.sessionCtx.MessageSid,
|
||||
currentMessageId,
|
||||
silentToken: SILENT_REPLY_TOKEN,
|
||||
});
|
||||
const cleaned = parsed.text || undefined;
|
||||
|
||||
@@ -377,7 +377,7 @@ export async function runReplyAgent(params: {
|
||||
directlySentBlockKeys,
|
||||
replyToMode,
|
||||
replyToChannel,
|
||||
currentMessageId: sessionCtx.MessageSid,
|
||||
currentMessageId: sessionCtx.MessageSidFull ?? sessionCtx.MessageSid,
|
||||
messageProvider: followupRun.run.messageProvider,
|
||||
messagingToolSentTexts: runResult.messagingToolSentTexts,
|
||||
messagingToolSentTargets: runResult.messagingToolSentTargets,
|
||||
|
||||
@@ -350,7 +350,7 @@ export async function runPreparedReply(
|
||||
const authProfileIdSource = sessionEntry?.authProfileOverrideSource;
|
||||
const followupRun = {
|
||||
prompt: queuedBody,
|
||||
messageId: sessionCtx.MessageSid,
|
||||
messageId: sessionCtx.MessageSidFull ?? sessionCtx.MessageSid,
|
||||
summaryLine: baseBodyTrimmedRaw,
|
||||
enqueuedAt: Date.now(),
|
||||
// Originating channel for reply routing.
|
||||
|
||||
@@ -38,10 +38,14 @@ export type MsgContext = {
|
||||
AccountId?: string;
|
||||
ParentSessionKey?: string;
|
||||
MessageSid?: string;
|
||||
/** Provider-specific full message id when MessageSid is a shortened alias. */
|
||||
MessageSidFull?: string;
|
||||
MessageSids?: string[];
|
||||
MessageSidFirst?: string;
|
||||
MessageSidLast?: string;
|
||||
ReplyToId?: string;
|
||||
/** Provider-specific full reply-to id when ReplyToId is a shortened alias. */
|
||||
ReplyToIdFull?: string;
|
||||
ReplyToBody?: string;
|
||||
ReplyToSender?: string;
|
||||
ForwardedFrom?: string;
|
||||
|
||||
@@ -212,6 +212,7 @@ export type ChannelThreadingContext = {
|
||||
Channel?: string;
|
||||
To?: string;
|
||||
ReplyToId?: string;
|
||||
ReplyToIdFull?: string;
|
||||
ThreadLabel?: string;
|
||||
MessageThreadId?: string | number;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user