/implement_plan @thoughts/shared/plans/2026-04-06-route-handlers-to-internal-trpc.md
- User
/implement_plan @thoughts/shared/plans/2026-04-06-route-handlers-to-internal-trpc.md
- User
implement_plan /implement_plan @thoughts/shared/plans/2026-04-06-route-handlers-to-internal-trpc.md
Assistant· claude-opus-4-6
I'll read all the key files mentioned in the plan to understand the current state before implementing.
Assistant· claude-opus-4-6
Now let me read the OAuth route handlers and related files.
Assistant· claude-opus-4-6
Let me check one more reference file and the existing router directory structure.
Assistant· claude-opus-4-6
Good — I can see the
satisfies TRPCRouterRecordpattern. Now I have full context. Let me create tasks and start implementing Phase 1.Assistant· claude-opus-4-6
Now update
internal.ts— for Phase 1 we only mount webhooks (oauth comes in Phase 2). I'll keep the import ready but comment-free since the oauth router doesn't exist yet.Assistant· claude-opus-4-6
Now slim down the ingest route handler to a thin HTTP adapter.
Assistant· claude-opus-4-6
Now let me run the automated verification checks.
Assistant· claude-opus-4-6
Let me check how existing procedures define their zod inputs to understand the type errors.
Assistant· claude-opus-4-6
The
z.record()needs two args in their zod version. Let me check usage patterns.Assistant· claude-opus-4-6
The existing pattern is
z.record(z.string(), z.string())— key + value schemas. Let me also check the Headers constructor issue.Assistant· claude-opus-4-6
Now fix the other two errors. Line 97 has the
headers[key]issue — withRecord<string, string>, accessing by key could returnstringnotstring | undefined, but the TS error says{} | undefined. This is likely becausez.record(z.string(), z.string())output maps toPartial<Record<string, string>>or similar. Let me also fix thenew Headers(headers)issue where the record type doesn't matchHeadersInit.Assistant· claude-opus-4-6
@api/platformpasses. Now check the platform app typecheck.Assistant· claude-opus-4-6
The path alias is
~/*not@/*. The internal-caller file is atapps/platform/src/lib/internal-caller.ts, so the import should use~/lib/internal-caller.Assistant· claude-opus-4-6
Both typechecks pass. Now run the build.
Assistant· claude-opus-4-6
Build passes cleanly. All Phase 1 automated verification is complete. Let me update the plan checkboxes.
Assistant· claude-opus-4-6
Now update the plan file to check off Phase 1 automated criteria. Note: the plan uses
~/lib/internal-callernot@/lib/internal-caller— I should also correct the plan's code snippets for the OAuth routes coming in Phase 2.Assistant· claude-opus-4-6
Phase 1 Complete — Ready for Manual Verification
Automated verification passed:
pnpm --filter @api/platform typecheckpassespnpm --filter @lightfast/platform typecheckpassespnpm build:platformpasses
Please perform the manual verification steps listed in the plan:
POST /api/ingest/githubwith valid HMAC returns202 { status: "accepted", deliveryId: "..." }POST /api/ingest/unknownreturns404 { error: "unknown_provider: unknown" }POST /api/ingest/githubwith invalid signature returns401 { error: "signature_invalid" }- Observability middleware fires — check logs for
[trpc] okwithsource: "route"on success and[trpc] client erroron 4xx
Implementation adaptations from plan:
z.record(z.string())→z.record(z.string(), z.string())(Zod requires key+value schemas)@/lib/→~/lib/(platform app uses path alias)
- User
question for this, dont we technically know the data format? im just curious whether it's smarter to have mostof the header conversion stuff in the actually route.ts and when passed into webhook.ingest it's post-transformed into correct types?
Assistant· claude-opus-4-6
Good question. You're right — the route handler is the HTTP boundary, so it makes sense for it to own the HTTP→data transformation. The procedure should receive clean, typed data rather than re-parsing HTTP artifacts.
The current split is:
- Route handler:
req.text(), then serializesreq.headersintoRecord<string, string> - Procedure: receives , reconstructs to pass to
- Route handler:
- User
proceed
Assistant· claude-opus-4-6
Let me check the OAuth lib imports I'll need — specifically
buildAuthorizeUrlreturn type andgetOAuthResultsignature.Assistant· claude-opus-4-6
Good, I have all the types. Now create the OAuth internal router.
Assistant· claude-opus-4-6
Mount the OAuth sub-router on the internal router.
Assistant· claude-opus-4-6
Now slim down the 3 OAuth route handlers. Using
~/lib/internal-caller(learned from Phase 1).Assistant· claude-opus-4-6
Fix the
parseErrorternary incallback.ts:351.Assistant· claude-opus-4-6
Now run automated verification.
Assistant· claude-opus-4-6
Both pass. Build next.
Assistant· claude-opus-4-6
Now run
pnpm check(the full monorepo check from Phase 2 success criteria).Assistant· claude-opus-4-6
Import ordering issues. Let me autofix them all.
Assistant· claude-opus-4-6
Good, all 7 files auto-fixed. Let me verify everything still passes.
Assistant· claude-opus-4-6
All clean. Now let me also quickly verify typecheck and build still pass after the lint fixes.
Assistant· claude-opus-4-6
Now update the Phase 2 success criteria in the plan.
Assistant· claude-opus-4-6
Now let me proceed to Phase 3 (Cleanup) since you said proceed.
Assistant· claude-opus-4-6
Both checks pass cleanly. Zero direct DB/lib imports in route handlers, and
internalRouteris not referenced in the app layer.Assistant· claude-opus-4-6
Update Phase 3 checkboxes in the plan.
Assistant· claude-opus-4-6
All 3 phases are implemented. Here's a summary of everything that was done:
Phase 1 — Webhooks Sub-Router
- Created
api/platform/src/router/internal/webhooks.tswithingestprocedure (HMAC verification, DB persist, Inngest dispatch) - Updated
api/platform/src/internal.tsto mountwebhooksInternalRouter - Slimmed
apps/platform/src/app/api/ingest/[provider]/route.tsto a thin HTTP adapter
Phase 2 — OAuth Sub-Router
- Created
api/platform/src/router/internal/oauth.tswithbuildAuthorizeUrl,processCallback,pollResultprocedures - Mounted
oauthInternalRouteron the internal router - Slimmed all 3 OAuth route handlers (authorize, callback, poll) to thin HTTP adapters
- Fixed
parseErrorternary inapi/platform/src/lib/oauth/callback.ts:351
- Created
- User
all good run. create new branch + pr
Assistant· claude-opus-4-6