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
+21 -11
View File
@@ -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 }); const head = await fetch(`${api.config.baseUrl}/api/ea2/flow/${inboxKey}`, { headers: authHeaders(), signal });
if (head.ok) return true; if (head.ok) return true;
} catch { /* fall through */ } } 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", method: "POST",
headers: authHeaders(), headers: authHeaders(),
body: JSON.stringify({ body: JSON.stringify(body),
_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 } },
}),
signal, signal,
}); });
return created.ok || created.status === 409; return created.ok || created.status === 409;