Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions apps/api/src/handlers/discord/__tests__/fast-agent.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions apps/api/src/handlers/discord/__tests__/index.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 44 additions & 14 deletions apps/api/src/handlers/discord/fast-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
getDiscordFooterlessFinalChunk,
getThreadReplyFooterRecord,
resolveFastSessionReplyFooterContext,
setThreadReplyFooterRecord,
rememberThreadReplyFooterAfterEdit,
withThreadReplyFooterLock,
} from '@roomote/communication';
import {
Expand Down Expand Up @@ -334,6 +334,7 @@ export async function processDiscordFastAgentMessage(
textWithFooter,
footerText,
}),
refresh: { footerText, channelId: footerMessageChannelId },
};
},
clearPreviousFooter: async (previousFooterRecord) => {
Expand Down Expand Up @@ -513,7 +514,7 @@ export async function processDiscordFastAgentMessage(
// and this replacement would re-mark the old message as carrier.
const replaced = await withThreadReplyFooterLock({
lockKey: `discord:thread_reply_footer_lock:${footerChannelId}:${footerStateThreadId}`,
fn: async () => {
fn: async (assertLock, lock) => {
const footerRecord = await getThreadReplyFooterRecord(
'discord',
footerChannelId,
Expand All @@ -523,6 +524,7 @@ export async function processDiscordFastAgentMessage(
const replacementText = isFooterCarrier
? `${text}\n\n${footerText}`
: text;
await assertLock();

if (replacementText.length > DISCORD_MAX_MESSAGE_LENGTH) {
const placeholder = 'Reconnected to the inference provider.';
Expand All @@ -537,12 +539,26 @@ export async function processDiscordFastAgentMessage(
// The relocation that follows rewrites this message to its
// stored footerless text; keep that text current so the
// edit does not resurrect the pre-retry notice.
await setThreadReplyFooterRecord(
'discord',
footerChannelId,
footerStateThreadId,
{ messageId, textWithoutFooter: placeholder },
).catch(() => {});
await rememberThreadReplyFooterAfterEdit({
provider: 'discord',
channelId: footerChannelId,
threadId: footerStateThreadId,
assertLock,
lock,
record: {
...footerRecord,
messageId,
textWithoutFooter: placeholder,
refresh: { footerText, channelId: channel.channelId },
},
clearOwnFooter: () =>
input.provider.editMessage({
channelId: channel.channelId,
messageId,
text: placeholder,
preserveButtons: true,
}),
}).catch(() => {});
}
return false;
}
Expand All @@ -553,12 +569,26 @@ export async function processDiscordFastAgentMessage(
text: replacementText,
});
if (isFooterCarrier) {
await setThreadReplyFooterRecord(
'discord',
footerChannelId,
footerStateThreadId,
{ messageId, textWithoutFooter: text },
).catch(() => {});
await rememberThreadReplyFooterAfterEdit({
provider: 'discord',
channelId: footerChannelId,
threadId: footerStateThreadId,
assertLock,
lock,
record: {
...footerRecord,
messageId,
textWithoutFooter: text,
refresh: { footerText, channelId: channel.channelId },
},
clearOwnFooter: () =>
input.provider.editMessage({
channelId: channel.channelId,
messageId,
text,
preserveButtons: true,
}),
}).catch(() => {});
}
return true;
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading