Fix(queue): auto-send queued messages FIFO (#1254)
* fix(queue): auto-send queued messages FIFO * test(queue): cover FIFO queued auto-send payload * test(queue): stub config store in auto-send tests * fix(test): complete Agent type in queued auto-send test --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
2c25bfc8d7
commit
462cebdf95
@@ -1,5 +1,4 @@
|
||||
import React from 'react';
|
||||
import type { AttachedFile } from '@/stores/types/sessionTypes';
|
||||
import { useMessageQueueStore, type QueuedMessage } from '@/stores/messageQueueStore';
|
||||
import { useSessionUIStore } from '@/sync/session-ui-store';
|
||||
import { useSelectionStore } from '@/sync/selection-store';
|
||||
@@ -21,37 +20,21 @@ const hasRecentAbort = (sessionId: string): boolean => {
|
||||
return Date.now() - abortRecord.timestamp < RECENT_ABORT_WINDOW_MS;
|
||||
};
|
||||
|
||||
const buildQueuedPayload = (queue: QueuedMessage[]) => {
|
||||
const agents = useConfigStore.getState().getVisibleAgents();
|
||||
let primaryText = '';
|
||||
let primaryAttachments: AttachedFile[] = [];
|
||||
let agentMentionName: string | undefined;
|
||||
const additionalParts: Array<{ text: string; attachments?: AttachedFile[] }> = [];
|
||||
|
||||
for (let i = 0; i < queue.length; i += 1) {
|
||||
const queued = queue[i];
|
||||
const { sanitizedText, mention } = parseAgentMentions(queued.content, agents);
|
||||
|
||||
if (!agentMentionName && mention?.name) {
|
||||
agentMentionName = mention.name;
|
||||
}
|
||||
|
||||
if (i === 0) {
|
||||
primaryText = sanitizedText;
|
||||
primaryAttachments = queued.attachments ?? [];
|
||||
} else {
|
||||
additionalParts.push({
|
||||
text: sanitizedText,
|
||||
attachments: queued.attachments,
|
||||
});
|
||||
}
|
||||
export const buildQueuedAutoSendPayload = (queue: QueuedMessage[]) => {
|
||||
const queued = queue[0];
|
||||
if (!queued) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const agents = useConfigStore.getState().getVisibleAgents();
|
||||
const { sanitizedText, mention } = parseAgentMentions(queued.content, agents);
|
||||
|
||||
return {
|
||||
primaryText,
|
||||
primaryAttachments,
|
||||
agentMentionName,
|
||||
additionalParts: additionalParts.length > 0 ? additionalParts : undefined,
|
||||
queuedMessageId: queued.id,
|
||||
primaryText: sanitizedText,
|
||||
primaryAttachments: queued.attachments ?? [],
|
||||
agentMentionName: mention?.name,
|
||||
sendConfig: queued.sendConfig,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -125,13 +108,16 @@ export function useQueuedMessageAutoSend(enabledOrOptions?: boolean | { enabled?
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = buildQueuedPayload(queueSnapshot);
|
||||
if (!payload.primaryText && payload.primaryAttachments.length === 0 && !payload.additionalParts?.length) {
|
||||
const payload = buildQueuedAutoSendPayload(queueSnapshot);
|
||||
if (!payload) {
|
||||
return;
|
||||
}
|
||||
if (!payload.primaryText && payload.primaryAttachments.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use send config captured at queue time; fall back to current config
|
||||
const captured = queueSnapshot[0]?.sendConfig;
|
||||
const captured = payload.sendConfig;
|
||||
const resolved = captured?.providerID && captured?.modelID
|
||||
? captured
|
||||
: resolveSessionSendConfig(sessionId);
|
||||
@@ -149,15 +135,13 @@ export function useQueuedMessageAutoSend(enabledOrOptions?: boolean | { enabled?
|
||||
resolved.agent,
|
||||
payload.primaryAttachments,
|
||||
payload.agentMentionName,
|
||||
payload.additionalParts,
|
||||
undefined,
|
||||
resolved.variant,
|
||||
'normal'
|
||||
);
|
||||
|
||||
const removeFromQueue = useMessageQueueStore.getState().removeFromQueue;
|
||||
queueSnapshot.forEach((item) => {
|
||||
removeFromQueue(sessionId, item.id);
|
||||
});
|
||||
removeFromQueue(sessionId, payload.queuedMessageId);
|
||||
} catch (error) {
|
||||
console.warn('[queue] queued auto-send failed:', error);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user