u
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user