This commit is contained in:
seb
2026-10-16 15:38:47 +02:00
parent 5ed634990e
commit f506dd35be
5 changed files with 6 additions and 28 deletions

View File

@@ -136,14 +136,14 @@ export async function resolveCompanyForUser(googleAuthId) {
* Request a draft content.
* Stateless model:
* - If cached, returns immediately.
* - In conversation: emits `draft:request` with conversationId and raises DirectReturnError(..., { recordResult: false })
* so the assistant tool call remains the last message in `modelmessage` until frontend responds.
* - In conversation: raises DirectReturnError(..., { recordResult: false }) so the assistant
* tool call remains the last message in `modelmessage` until answered (exactly like ask_user).
* - Outside conversation: returns default empty draft envelope.
*
* @param {{ companyId?: number, userId: number, conversationId?: number, clientId?: string, name: string }} options
* @param {{ companyId?: number, userId: number, conversationId?: number, name: string }} options
* @returns {Promise<any>}
*/
export async function requestDraftRead({ companyId, userId, conversationId, clientId, name }) {
export async function requestDraftRead({ companyId, userId, conversationId, name }) {
const effectiveCompanyId = companyId != null ? companyId : await resolveCompanyForUser(userId);
if (effectiveCompanyId == null) {
throw new Error('No company selected');
@@ -155,24 +155,7 @@ export async function requestDraftRead({ companyId, userId, conversationId, clie
}
if (conversationId) {
const requestId = `conv_${conversationId}_${name}`;
// Emit request over SSE with conversationId
emit('draft:request', {
companyId: effectiveCompanyId,
targetUserId: userId,
targetClientId: clientId,
data: {
requestId,
conversationId,
action: 'read',
name,
target: name,
sender: clientId || '',
},
});
// Halt turn statelessly; assistant tool call stays as the last message in modelmessage
// Halt turn statelessly; assistant tool call stays as the last message in modelmessage, like ask_user
throw new DirectReturnError({
action: 'draft_read',
draft: name,