Files
Arcrun/cli/src/lib/api-recipe-seeds.ts
T
Leo fb2d0b0c2d feat(self-hosted): acr init --self-hosted installer + recipe push 把關 + commit 部署 wasm
讓任何 CC 用自己的 CF 帳號一鍵 self-host arcrun(戰法轉 self-hosted 開源)。

Task 1 — acr init --self-hosted installer(用戶只給 CF Account ID + token,其餘自動):
- cli/src/lib/cf-api.ts: CfAccountClient(驗 token / 建 KV 冪等 / 建 R2 / 查 workers.dev subdomain)
- cli/src/lib/deploy.ts: 從 GitHub codeload tarball 拉部署物 → 注入用戶 KV id → wrangler deploy
  (tier1 component-builds 先、tier2 cypher-executor/registry 後;部分失敗誠實回報不假綠)
- cli/src/lib/api-recipe-seeds.ts: 10 個現役 API recipe 種子(KBDB 採 Supabase 模式)
- cli/src/commands/init.ts: initSelfHosted() 改寫成 installer 流程
- cli/src/commands/update.ts: acr update(拉新 ref 重部署)
- cypher-executor/scripts/seed-api-recipes.ts: prod 補灌腳本

Task 2 — recipe 入庫把關(封鎖自製零件後,CC 唯一能擴充的是 recipe):
- cli/src/commands/recipe.ts: 新增 probeRecipeEndpoint 打通檢查(提醒級不硬擋,
  含模板誠實說明待 run 才知,401/403 標多半缺 credential 非 bug)
- 資料外流提醒沿用既有 obtainExposureConsent(非 TTY 拒絕)

部署物產製:commit 預編譯 wasm 進 repo(推翻 rule 05「wasm 不 commit」):
- .gitignore: 放行 .component-builds/**/component.wasm(registry 中間產物仍排除)
- 只 commit 19 個正當零件 wasm;claude_api / km_writer / kbdb_upsert_block 排除
  (非薄殼、是把工作流硬塞進零件,違反 DECISIONS §1,待降級)
- rule 05 同步記錄此慣例變更 + 膨脹 trade-off

SDD: sdk-and-website/self-hosted-init.md(installer 定案)、
     component-gatekeeping/recipe-push-gatekeeping.md(recipe 把關)
README 重寫成單一 self-hosted 路徑。CLI typecheck exit 0。

未完(待 richblack):push 此 commit 到 GitHub 後 codeload 才拿得到 wasm;
用第二 CF 帳號端對端驗收 acr init --self-hosted。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 18:44:41 +08:00

120 lines
4.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* api-recipe-seeds.ts
*
* 現役 API recipe 的種子定義。self-host 新帳號 init 時把這些灌進空的 RECIPES KV
* (透過 cypher-executor 的 POST /recipes,或 CF KV REST API 直接寫)。
*
* API recipe = http_request + 固定設定(endpoint/method 模板)。
* 不需 deploy Workercypher-executor 執行時直接 fetch(見 cypher-executor/src/routes/recipes.ts)。
*
* 放在 CLI 端而非 cypher-executor/src
* - seed 資料是「installer 要灌進用戶 KV 的種子」,本就屬 CLI 職責(SDD self-hosted-init.md §4)。
* - rule 02 §2.2 hook 擋 cypher-executor TS hard-code API endpointseed 的 endpoint 是資料欄位,
* 放 CLI 端避開誤判,也更符合職責切分。
*
* 來源:2026-06-01 從 prod cypher.arcrun.dev/recipes 逐一查得的現役定義。
* 對應 SDD.agents/specs/arcrun/sdk-and-website/self-hosted-init.md §5
*
* KBDB recipekbdb_*)採 Supabase 模式(richblack 2026-06-02):
* 進 seed = 展示能力(引子)。使用者要用 → 去 arcrun 取統一 API Key 當 credential。
* FOLLOW-UPKBDB 端):endpoint 現為 kbdb.finally.clickKBDB 應改用統一對外網址;
* KBDB 改網址後同步更新此處。seed 先照現況進。
*/
export interface ApiRecipeSeed {
canonical_id: string;
display_name: string;
description?: string;
endpoint: string;
method: string;
auth_service?: string;
}
export const API_RECIPE_SEEDS: ApiRecipeSeed[] = [
// ── KBDBSupabase 模式,auth_service=kbdb static_key)──
{
canonical_id: 'kbdb_get',
display_name: 'KBDB Get',
description: 'GET 讀取 block / 查詢。_path 帶查詢路徑。auth: kbdb static_key。',
endpoint: 'https://kbdb.finally.click{{_path}}',
method: 'GET',
auth_service: 'kbdb',
},
{
canonical_id: 'kbdb_create_block',
display_name: 'KBDB Create Block',
description: 'POST /blocks 建立 block。body 帶 block 欄位(content/type/page_name/source/user_id 等)。auth: kbdb static_key。',
endpoint: 'https://kbdb.finally.click/blocks',
method: 'POST',
auth_service: 'kbdb',
},
{
canonical_id: 'kbdb_patch_block',
display_name: 'KBDB Patch Block',
description: 'PATCH /blocks/:id 局部更新。_path 帶 /blocks/{id}body 帶要改的欄位。auth: kbdb static_key。',
endpoint: 'https://kbdb.finally.click{{_path}}',
method: 'PATCH',
auth_service: 'kbdb',
},
{
canonical_id: 'kbdb_delete',
display_name: 'KBDB Delete',
description: 'DELETE /blocks/:id 刪除 block。_path 帶 /blocks/{id}。auth: kbdb static_key。',
endpoint: 'https://kbdb.finally.click{{_path}}',
method: 'DELETE',
auth_service: 'kbdb',
},
{
canonical_id: 'kbdb_ingest',
display_name: 'KBDB Ingest',
description: 'POST /blocks/ingest 批次寫入。body 帶 input。auth: kbdb static_key。',
endpoint: 'https://kbdb.finally.click/blocks/ingest',
method: 'POST',
auth_service: 'kbdb',
},
// ── Googleservice_account)──
{
canonical_id: 'gmail_send',
display_name: 'Gmail Send',
description: '寄 Gmail。POST messages/sendbody 帶 rawbase64url MIME)。auth: google service_account。',
endpoint: 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send',
method: 'POST',
auth_service: 'google_gmail_sa',
},
{
canonical_id: 'google_sheets_append',
display_name: 'Google Sheets Append',
description: '寫 Sheets。PUT values?valueInputOption=RAWbody 帶 values。auth: google service_account。',
endpoint: 'https://sheets.googleapis.com{{_path}}',
method: 'PUT',
auth_service: 'google_sheets_sa',
},
{
canonical_id: 'google_sheets_read',
display_name: 'Google Sheets Read',
description: '讀 Sheets。GET values。_path 帶完整路徑。auth: google service_account。',
endpoint: 'https://sheets.googleapis.com{{_path}}',
method: 'GET',
auth_service: 'google_sheets_sa',
},
// ── 訊息(static_key)──
{
canonical_id: 'telegram_send',
display_name: 'Telegram Send',
description: 'Telegram sendMessage。token 在 URL path{{auth.bot_token}}),body 帶 chat_id+text。auth: static_key path 注入。',
endpoint: 'https://api.telegram.org/bot{{auth.bot_token}}/sendMessage',
method: 'POST',
auth_service: 'telegram',
},
{
canonical_id: 'line_notify_send',
display_name: 'LINE Notify',
description: 'LINE Notify 推訊息。POST notifybody 帶 messageform-urlencoded)。auth: static_key Bearer line token。',
endpoint: 'https://notify-api.line.me/api/notify',
method: 'POST',
auth_service: 'line_notify',
},
];