-
Notifications
You must be signed in to change notification settings - Fork 0
feat(api): REST API (server/api, Hono) を Cloudflare Workers ランタイム対応にする (#1091) #1123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8a549f9
feat(api): migrate REST API to Cloudflare Workers runtime (#1091)
otomatty c48d6ef
docs(aidlc): record #1091 AI-DLC workflow artifacts and affirmed prac…
otomatty 316f1be
chore(ci): ignore workerd virtual module 'cloudflare:test' in knip
otomatty 83332a0
docs(api): expand Worker secret examples with boot-required vs option…
otomatty 1b87780
docs(cloudflare-zedi): add how-to-obtain guide for Worker secret values
otomatty 2e6ccc5
docs(cloudflare-zedi): reframe secret guide for fresh dev setup (otom…
otomatty ba8d9f8
Merge remote-tracking branch 'origin/develop' into feature/1091
otomatty 9103e3a
feat(auth): restrict social sign-in to Google only
otomatty 2afd488
docs(audit): add multiple HUMAN_TURN event timestamps to audit log
otomatty 6bd442e
Merge branch 'develop' into feature/1091
otomatty 6ca9b7e
fix(ci): stop knip from loading workerd vitest config
otomatty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
.agents/skills/cloudflare-zedi/references/worker-secret-values.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # Worker secrets の値の取得方法 / How to obtain each Worker secret | ||
|
|
||
| `server/api/.env.worker.dev`(および `.env.worker.production`)を埋めるときの、 | ||
| **各値をどこから取るか**の実務ガイド。何のための値か・ライフサイクルは | ||
| [secrets-template.md](secrets-template.md) を、鍵名の一覧は | ||
| `server/api/.env.worker.dev.example` を正とする。 | ||
|
|
||
| > 大原則: ほとんどの値は **Railway で現在稼働中の api サービスの Variables から | ||
| > そのままコピー**する(本番と同じ値で dev Worker を動かす)。新規に発行するのは | ||
| > R2 アクセスキーと(必要なら)Sentry DSN くらい。 | ||
| > | ||
| > 取得元: | ||
| > | ||
| > - **Railway**: dashboard → プロジェクト → `api` サービス → **Variables** タブ。 | ||
| > 値は目のアイコンで表示、またはコピー。CLI なら `railway variables`(要ログイン)。 | ||
| > - 秘密値は **Issue / PR / チャットに貼らない**。`.env.worker.dev`(gitignore 済み)にだけ書く。 | ||
|
|
||
| --- | ||
|
|
||
| ## 必須 / Required at boot(未設定だと `wrangler deploy` が失敗する) | ||
|
|
||
| ### BETTER_AUTH_SECRET | ||
|
|
||
| - **取得**: Railway `api` の `BETTER_AUTH_SECRET` をそのままコピー。 | ||
| - ⚠️ API / MCP / hocuspocus と**必ず同一値**(署名鍵の共有)。新規生成しない。 | ||
|
|
||
| ### BETTER_AUTH_URL | ||
|
|
||
| - **取得**: dev Worker の公開 URL。 | ||
| - workers.dev を使う場合: `https://zedi-api-dev.<アカウントのサブドメイン>.workers.dev` | ||
| - サブドメインは Cloudflare dashboard → **Workers & Pages** → `zedi-api-dev` を開くと | ||
| 表示される URL、または **Workers & Pages → 右側の `<xxx>.workers.dev` サブドメイン**で確認。 | ||
| - custom domain(`api-dev.zedi-note.app` 等)を後で使う場合はそれを設定。 | ||
| - ⚠️ 認証フローの dev 検証は #1090(D1)後なので、起動時に URL としてパースできれば | ||
| 暫定値で可。ただし OAuth コールバック base になるため、OAuth を実際に試すときは | ||
| この URL を Google/GitHub の redirect URI にも登録する。 | ||
|
|
||
| ### CORS_ORIGIN | ||
|
|
||
| - **取得**: Railway `api` の `CORS_ORIGIN` をコピー(フロント/admin のオリジン、カンマ区切り)。 | ||
| - dev フロントを Pages で見る場合の例: `https://zedi-dev.pages.dev,https://zedi-admin-dev.pages.dev` | ||
| - Chrome 拡張を使うなら `chrome-extension://<id>` も含める(`chrome://extensions` で ID 確認)。 | ||
|
|
||
| ### GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET | ||
|
|
||
| - **取得(推奨)**: Railway `api` の同名変数をコピー。 | ||
| - **元の発行元**: [Google Cloud Console](https://console.cloud.google.com/apis/credentials) | ||
| → APIs & Services → **Credentials** → OAuth 2.0 Client IDs → 該当クライアント。 | ||
| Secret は「Reset」しない限り再表示可(クライアント作成時のもの)。 | ||
| - OAuth を dev Worker URL で試すなら、同画面の **Authorized redirect URIs** に | ||
| `<BETTER_AUTH_URL>/api/auth/callback/google` を追加。 | ||
|
|
||
| ### GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET | ||
|
|
||
| - **取得(推奨)**: Railway `api` の同名変数をコピー。 | ||
| - **元の発行元**: GitHub → Settings → **Developer settings** → **OAuth Apps** → | ||
| 該当アプリ。Client secret は再表示不可なので、無ければ「Generate a new client secret」。 | ||
| - dev Worker URL で試すなら **Authorization callback URL** に | ||
| `<BETTER_AUTH_URL>/api/auth/callback/github` を追加。 | ||
|
|
||
| ### DATABASE_URL | ||
|
|
||
| - **取得**: #1090(D1 移行)まで **到達しないプレースホルダで可**。 | ||
| 例ファイルの `postgresql://placeholder:unused@127.0.0.1:5432/unused` のままで良い。 | ||
| - 理由: auth.ts がモジュールロード時に pg.Pool を構築するため起動時に必須だが、 | ||
| 実接続は DB 依存ルートを叩くまで発生しない(遅延接続)。dev の DB 依存経路の | ||
| 検証は #1090 後。 | ||
| - (もし dev で実 DB に繋ぎたい場合のみ)Railway Postgres の接続文字列をコピー。 | ||
|
|
||
| --- | ||
|
|
||
| ## 任意 / Optional(未設定なら no-op、またはその機能だけ無効) | ||
|
|
||
| ### SENTRY_DSN_API | ||
|
|
||
| - **取得**: [Sentry](https://sentry.io) → 対象プロジェクト → Settings → **Client Keys (DSN)**。 | ||
| または Railway `api` の同名変数をコピー。 | ||
| - 空のままなら Sentry 送信は no-op(起動には影響しない)。 | ||
|
|
||
| ### STORAGE_ENDPOINT / STORAGE_ACCESS_KEY / STORAGE_SECRET_KEY / STORAGE_BUCKET_NAME | ||
|
|
||
| - presigned URL 生成にのみ必要(R2 の読み書きは `STORAGE_BUCKET` binding が処理)。 | ||
| - **STORAGE_ENDPOINT**: `https://<CLOUDFLARE_ACCOUNT_ID>.r2.cloudflarestorage.com` | ||
| (アカウント ID = `175c04a4465bcc9815b21176a852f0c0`)。 | ||
| - **STORAGE_ACCESS_KEY / STORAGE_SECRET_KEY**: R2 の S3 互換キー。 | ||
| - 今回 `zedi-migration` トークン作成時に発行された **アクセスキー ID / シークレット | ||
| アクセスキー**をそのまま使える(`.env` の `CLOUDFLARE_R2_ACCESS_KEY_ID` / | ||
| `CLOUDFLARE_R2_SECRET_ACCESS_KEY`)。 | ||
| - もしくは Cloudflare dashboard → **R2 → Manage R2 API Tokens** で専用トークンを発行 | ||
| (MCP では発行不可)。Railway で稼働中の `STORAGE_*` は別トークン由来なので touch しない。 | ||
| - **STORAGE_BUCKET_NAME**: dev は `zedi-storage-dev`(例ファイル既定)。 | ||
|
|
||
| ### RESEND_API_KEY / RESEND_FROM_EMAIL | ||
|
|
||
| - **取得**: [Resend](https://resend.com/api-keys) の API キー、または Railway からコピー。 | ||
| - 未設定なら招待メール等のメール送信が無効になるだけ(起動には影響しない)。 | ||
|
|
||
| ### MCP_REDIRECT_URI_ALLOW / MCP_JWT_EXP_DAYS | ||
|
|
||
| - 外部 MCP クライアント連携を dev で使う場合のみ。Railway `api` からコピー。 | ||
| - 未設定だと `/api/mcp/authorize-code` が全 redirect を拒否する(MCP 機能のみ無効)。 | ||
|
|
||
| ### OPENROUTER_API_KEY / YOUTUBE_DATA_API_KEY | ||
|
|
||
| - それぞれ AI モデル料金 sync / YouTube クリップ用の任意キー。Railway からコピー。 | ||
|
|
||
| --- | ||
|
|
||
| ## 投入と確認 / Put & verify | ||
|
|
||
| ```bash | ||
| cd server/api | ||
| bun run worker:secrets:put -- --env dev --dry-run # 埋めた項目の確認(空値はスキップされる) | ||
| bun run worker:secrets:put -- --env dev # 一括投入 | ||
| bunx wrangler secret list --env dev # Worker 側に載った secret 名の確認 | ||
| ``` | ||
|
|
||
| - ⚠️ `worker:secrets:put` は **空値をスキップ**する。必須 8 項目に実値が入っていないと | ||
| アップロードされず、deploy が `... must be set` で失敗する。`--dry-run` で 8 項目 | ||
| (最低でも `DATABASE_URL` プレースホルダ含む)が出ることを確認する。 | ||
| - ⚠️ **順序**: secrets 投入 → その後 `wrangler deploy`(deploy 時の起動検証で必須値を読む)。 | ||
| - 投入後、CI の `deploy-api-worker-dev.yml` を再実行するか develop への push で dev デプロイ。 | ||
|
|
||
| --- | ||
|
|
||
| ## 関連 / Related | ||
|
|
||
| - [secrets-template.md](secrets-template.md) — 全 secret のライフサイクル台帳 | ||
| - [token-scopes.md](token-scopes.md) — API トークンのスコープと作成手順 | ||
| - `server/api/.env.worker.dev.example` — 鍵名と必須/任意の区別 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
aidlc/spaces/default/intents/260718-api-workers-migration/aidlc-state.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # AI-DLC State Tracking | ||
|
|
||
| ## Project Information | ||
| - **Project**: https://github.com/otomatty/zedi/issues/1091 こちらのissueに取り組んでください | ||
| - **Project Type**: Brownfield | ||
| - **Scope**: infra | ||
| - **Start Date**: 2026-07-18T02:00:49Z | ||
| - **State Version**: 7 | ||
| - **Active Agent**: aidlc-operations-agent | ||
| - **Worktree Path**: | ||
| - **Bolt Refs**: | ||
| - **Practices Affirmed Timestamp**: 2026-07-18T03:56:48Z | ||
|
|
||
| ## Scope Configuration | ||
| - **Stages to Execute**: 0.1, 0.2, 0.3, 2.2, 2.3, 3.2, 3.3, 3.4, 3.7, 4.1, 4.2, 4.3, 4.4 | ||
| - **Stages to Skip**: 1.1 (intent-capture), 1.2 (market-research), 1.3 (feasibility), 1.4 (scope-definition), 1.5 (team-formation), 1.6 (rough-mockups), 1.7 (approval-handoff), 2.1 (reverse-engineering), 2.4 (user-stories), 2.5 (refined-mockups), 2.6 (application-design), 2.7 (units-generation), 2.8 (delivery-planning), 3.1 (functional-design), 3.5 (code-generation), 3.6 (build-and-test), 4.5 (incident-response), 4.6 (performance-validation), 4.7 (feedback-optimization) | ||
| - **Depth**: Standard | ||
| - **Test Strategy**: Standard | ||
|
|
||
| ## Workspace State | ||
| - **Project Root**: C:\Users\saedg\apps\zedi | ||
| - **Languages**: TypeScript | ||
| - **Frameworks**: Vite, React | ||
| - **Build System**: bun (package.json) | ||
|
|
||
| ## Execution Plan Summary | ||
| - **Total Stages**: 13 | ||
| - **Completed**: 13 | ||
| - **In Progress**: none | ||
|
|
||
| ## Runtime State | ||
| - **Revision Count**: 0 | ||
|
|
||
| - **Skeleton Stance**: on | ||
| ## Phase Progress | ||
| <!-- Status values: Pending, Active, Verified, Skipped --> | ||
|
|
||
| - **Initialization**: Verified | ||
| - **Ideation**: Skipped | ||
| - **Inception**: Verified | ||
| - **Construction**: Verified | ||
| - **Operation**: Verified | ||
|
|
||
| ## Stage Progress | ||
| <!-- Checkbox states: [ ] not started, [-] in progress, [?] awaiting approval (gate open), [R] revising (user rejected gate), [x] completed, [S] skipped via --stage/--phase jump --> | ||
|
|
||
| ### INITIALIZATION PHASE | ||
| - [x] workspace-scaffold — EXECUTE | ||
| - [x] workspace-detection — EXECUTE | ||
| - [x] state-init — EXECUTE | ||
|
|
||
| ### IDEATION PHASE | ||
| - [ ] intent-capture — SKIP | ||
| - [ ] market-research — SKIP | ||
| - [ ] feasibility — SKIP | ||
| - [ ] scope-definition — SKIP | ||
| - [ ] team-formation — SKIP | ||
| - [ ] rough-mockups — SKIP | ||
| - [ ] approval-handoff — SKIP | ||
|
|
||
| ### INCEPTION PHASE | ||
| - [ ] reverse-engineering — SKIP | ||
| - [x] practices-discovery — EXECUTE | ||
| - [x] requirements-analysis — EXECUTE | ||
| - [ ] user-stories — SKIP | ||
| - [ ] refined-mockups — SKIP | ||
| - [ ] application-design — SKIP | ||
| - [ ] units-generation — SKIP | ||
| - [ ] delivery-planning — SKIP | ||
|
|
||
| ### CONSTRUCTION PHASE | ||
| Per unit: [TBD] | ||
| - [ ] functional-design — SKIP | ||
| - [x] nfr-requirements — EXECUTE | ||
| - [x] nfr-design — EXECUTE | ||
| - [x] infrastructure-design — EXECUTE | ||
| - [ ] code-generation — SKIP | ||
| - [ ] build-and-test — SKIP | ||
| - [x] ci-pipeline — EXECUTE | ||
|
|
||
| ### OPERATION PHASE | ||
| - [x] deployment-pipeline — EXECUTE | ||
| - [x] environment-provisioning — EXECUTE | ||
| - [x] deployment-execution — EXECUTE | ||
| - [x] observability-setup — EXECUTE | ||
| - [ ] incident-response — SKIP | ||
| - [ ] performance-validation — SKIP | ||
| - [ ] feedback-optimization — SKIP | ||
|
|
||
| ## Current Status | ||
| - **Lifecycle Phase**: OPERATION | ||
| - **Current Stage**: observability-setup | ||
| - **Next Stage**: none | ||
| - **Status**: Completed | ||
| - **Last Updated**: 2026-07-18T08:12:11Z | ||
|
|
||
| ## Session Resume Point | ||
| - **Last Completed Stage**: observability-setup | ||
| - **Next Action**: Workflow complete | ||
| - **Pending Artifacts**: none | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Remove workstation-specific absolute paths from the tracked artifacts.
aidlc/spaces/default/intents/260718-api-workers-migration/aidlc-state.md#L21-L21: replaceC:\Users\saedg\apps\zediwith a repository-relative path or placeholder.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L214-L214: redact the absoluteDestinationpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L225-L225: redact the absoluteDestinationpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L246-L246: redact the absolute--project-dirpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L255-L255: redact the absolute--project-dirpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L338-L338: redact the absoluteDestinationpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L349-L349: redact the absoluteDestinationpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L445-L445: redact the absoluteDestinationpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L520-L520: redact the absoluteDestinationpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L531-L531: redact the absoluteDestinationpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L594-L594: redact the absoluteDestinationpath.aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L605-L605: redact the absoluteDestinationpath.📍 Affects 2 files
aidlc/spaces/default/intents/260718-api-workers-migration/aidlc-state.md#L21-L21(this comment)aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L214-L214aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L225-L225aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L246-L246aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L255-L255aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L338-L338aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L349-L349aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L445-L445aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L520-L520aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L531-L531aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L594-L594aidlc/spaces/default/intents/260718-api-workers-migration/audit/saedgewell-353e06d8a0b4.md#L605-L605🤖 Prompt for AI Agents