feat(mira): 河道 → wiki 自動化(fire-and-forget 觸發 wiki_synthesis)

對應 polaris/mira/.agents/specs/mira-app/tasks.md 7B.3h(簡化版)。

原計畫用 arcrun cron 零件 → cypher-executor scheduled() handler,但發現
cron 零件只是 validator,cypher-executor 還沒實作 scheduled()。為了不擋
「河道書寫 → 自動產 wiki」這條 UX,先做 fire-and-forget 版本:

- 新 cypher-executor route POST /mira/wiki-from-raw
  - body: { raw_block_id }
  - server 端從 MIRA_CONFIG secret 補 partner key / mira_token / 三個 block IDs
  - waitUntil 背景跑 executeWebhookGraph,立刻回 202
- landing 河道 post composer 成功寫 raw 後 fire-and-forget triggerWikiSynthesis()
  跟既有 triggerAiReply() 同範式
- types.ts 加 MIRA_CONFIG?: string

部署後需手動:
  echo '{"service_api_key":"ak_...","data_api_key":"ak_...","schema_block_id":"...","skill_block_id":"...","entities_block_id":"...","mira_token":"..."}' \
    | wrangler secret put MIRA_CONFIG

UX:河道貼一則 → AI reply 30s 內 → wiki 60-90s 內出現在 /mira/wiki。

arcrun.md 記 P1 #3:cypher-executor 加 scheduled() handler,那是真正的
cron 路線,封測前不擋。
This commit is contained in:
2026-05-14 13:50:13 +08:00
parent 933ae6cb13
commit 660b32eafd
5 changed files with 159 additions and 0 deletions
+27
View File
@@ -158,6 +158,29 @@ export default function MiraPage() {
// ─── AI 回覆觸發器(fire-and-forget)──────────────────────
async function triggerWikiSynthesis(opts: { rawBlockId: string }) {
// 對應 cypher-executor routes/mira.ts POST /mira/wiki-from-raw
// server 端從 MIRA_CONFIG secret 補齊所有 partner key / token / block IDs
// workflow 跑 60-90s,這裡 fire-and-forget 不等結果(拿 202 立刻回)
try {
const res = await fetch(`${API_BASE}/mira/wiki-from-raw`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ raw_block_id: opts.rawBlockId }),
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
console.warn('[mira wiki-from-raw] not triggered:', res.status, data);
return;
}
const data = await res.json().catch(() => ({}));
console.log('[mira wiki-from-raw] accepted:', data);
} catch (e) {
console.warn('[mira wiki-from-raw] error:', e);
}
}
async function triggerAiReply(opts: {
apiKey: string;
postContent: string;
@@ -272,6 +295,10 @@ function PostComposer({
parentBlockId: postBlockId,
pageName,
});
// fire-and-forget 觸發 wiki_synthesis7B.3h 簡化版:從 frontend 直接觸發,不走 cron
// 對應 routes/mira.tsserver 端從 MIRA_CONFIG secret 補齊 token / block IDs
void triggerWikiSynthesis({ rawBlockId: postBlockId });
onAiTriggered(pageName);
// 給 D1 GROUP BY 查詢看到新資料的時間