u
This commit is contained in:
@@ -485,7 +485,6 @@ _none_
|
||||
- `modelconversation-<id>`: `{}`
|
||||
- `brand`: `{ sender, brandId }`
|
||||
- `draft`: `{ sender, action, name, content }`
|
||||
- `draft:request`: `{ requestId, action, name, target, sender }`
|
||||
|
||||
### Section: /health
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ richer payload.
|
||||
| `modelconversation-<id>` | `{}` | 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
|
||||
|
||||
@@ -54,7 +54,6 @@ export function register(app, basePath = '') {
|
||||
* | `modelconversation-<id>` | `{}` | 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: |
|
||||
|
||||
@@ -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 }) {
|
||||
|
||||
@@ -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