fix(chat): create inbox via apply-batch (POST /api/ea2/flow rejects _key)

This commit is contained in:
2026-06-14 13:53:21 +04:00
parent 7aaba5fb47
commit 07eb93f67c
+15 -5
View File
@@ -41,10 +41,13 @@ 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`, {
method: "POST",
headers: authHeaders(),
body: JSON.stringify({
const body = {
request_id: newRequestId(),
ops: [
{
op: "create",
coll: "flow",
data: {
_key: inboxKey,
kind: "value",
status: "published",
@@ -53,7 +56,14 @@ async function ensureInbox(inboxKey: string, email: string, signal?: AbortSignal
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(body),
signal,
});
return created.ok || created.status === 409;