diff --git a/src/lib/chatApi.ts b/src/lib/chatApi.ts index d025002..0caae22 100644 --- a/src/lib/chatApi.ts +++ b/src/lib/chatApi.ts @@ -41,19 +41,29 @@ async function ensureInbox(inboxKey: string, email: string, signal?: AbortSignal const head = await fetch(`${api.config.baseUrl}/api/ea2/flow/${inboxKey}`, { headers: authHeaders(), signal }); if (head.ok) return true; } catch { /* fall through */ } - const created = await fetch(`${api.config.baseUrl}/api/ea2/flow`, { + const body = { + request_id: newRequestId(), + ops: [ + { + op: "create", + coll: "flow", + data: { + _key: inboxKey, + kind: "value", + status: "published", + name: inboxKey, + display_name: `Inbox · ${email}`, + description: `Chat inbox anchor for ${email}`, + source_context: "CANVAS_CHAT_INBOX", + config: { chat: { owner_email: email } }, + }, + }, + ], + }; + const created = await fetch(`${api.config.baseUrl}/api/ea2/apply-batch`, { method: "POST", headers: authHeaders(), - body: JSON.stringify({ - _key: inboxKey, - kind: "value", - status: "published", - name: inboxKey, - display_name: `Inbox · ${email}`, - description: `Chat inbox anchor for ${email}`, - source_context: "CANVAS_CHAT_INBOX", - config: { chat: { owner_email: email } }, - }), + body: JSON.stringify(body), signal, }); return created.ok || created.status === 409;