diff --git a/docs/api/routes-all.md b/docs/api/routes-all.md index 289946f..f71f7f7 100644 --- a/docs/api/routes-all.md +++ b/docs/api/routes-all.md @@ -485,7 +485,6 @@ _none_ - `modelconversation-`: `{}` - `brand`: `{ sender, brandId }` - `draft`: `{ sender, action, name, content }` - - `draft:request`: `{ requestId, action, name, target, sender }` ### Section: /health diff --git a/docs/api/routes/events.md b/docs/api/routes/events.md index 5a49d01..20f3af2 100644 --- a/docs/api/routes/events.md +++ b/docs/api/routes/events.md @@ -45,7 +45,6 @@ richer payload. | `modelconversation-` | `{}` | Conversation-specific updates on the same model conversation thread; the concrete ID is used in the event name | | `brand` | `{ sender, brandId }` | `POST /brand`, `PATCH /brand/{id}`, `DELETE /brand/{id}`, `POST /brand/{id}/image`, `DELETE /brand/{id}/image` | | `draft` | `{ sender, action, name, content }` | Draft update on `drafts/quote`, `drafts/order`, `drafts/delivery` (`sender` echoes the caller's `x-client-id`) | -| `draft:request` | `{ requestId, action, name, target, sender }` | Server request to frontend to read a draft or list drafts | The `brand` payload is `{ sender, brandId }`: `sender` echoes the caller's `x-client-id` header (empty string if absent) so the sender diff --git a/src/api/routes/events.js b/src/api/routes/events.js index 515353a..03e4a9f 100644 --- a/src/api/routes/events.js +++ b/src/api/routes/events.js @@ -54,7 +54,6 @@ export function register(app, basePath = '') { * | `modelconversation-` | `{}` | Conversation-specific updates on the same model conversation thread; the concrete ID is used in the event name | * | `brand` | `{ sender, brandId }` | `POST /brand`, `PATCH /brand/{id}`, `DELETE /brand/{id}`, `POST /brand/{id}/image`, `DELETE /brand/{id}/image` | * | `draft` | `{ sender, action, name, content }` | Draft update on `drafts/quote`, `drafts/order`, `drafts/delivery` (`sender` echoes the caller's `x-client-id`) | - * | `draft:request` | `{ requestId, action, name, target, sender }` | Server request to frontend to read a draft or list drafts | * * The `brand` payload is `{ sender, brandId }`: `sender` echoes the * caller's `x-client-id` header (empty string if absent) so the sender @@ -99,8 +98,6 @@ export function register(app, basePath = '') { * payload: "{ sender, brandId }" * - name: draft * payload: "{ sender, action, name, content }" - * - name: draft:request - * payload: "{ requestId, action, name, target, sender }" * responses: * 200: * description: | diff --git a/src/api/sse.js b/src/api/sse.js index c5e7bab..1b9d3cd 100644 --- a/src/api/sse.js +++ b/src/api/sse.js @@ -75,7 +75,7 @@ export function hasActiveClient({ companyId, userId, clientId } = {}) { * Broadcast or target a named signal to subscribers. * If `targetClientId` or `targetUserId` is specified, sends only to matching clients of that user. * - * @param {string} signal - SSE event name (e.g. `category`, `draft`, `draft:request`) + * @param {string} signal - SSE event name (e.g. `category`, `draft`, `modelconversation`) * @param {{ companyId: number, data?: string|object, targetClientId?: string, targetUserId?: number }} options */ export function emit(signal, { companyId, data, targetClientId, targetUserId }) { diff --git a/src/services/draftManager.js b/src/services/draftManager.js index 1188c25..4da33bc 100644 --- a/src/services/draftManager.js +++ b/src/services/draftManager.js @@ -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} */ -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,