Extract shared buildRunAgentInput() (chat#1813)

Merged
SW
5mo ago
+141-32

PR 3 (api) of the async chat-generation migration tracked in recoupable/chat#1813. Independent of the others — mergeable in parallel.

What

Extracts the RunAgentWorkflowInput construction from handleChatWorkflowStream into a pure, shared lib/chat/buildRunAgentInput.ts. The interactive handler now delegates to it; the upcoming headless /api/chat/generate re-point will call the same builder, so both paths can't drift.

  • Repo identifiers (repoOwner/repoName) and recoupOrgId are derived from clone_url inside the builder — one source of truth (the handler no longer computes them).
  • recoupAccessToken is included only when present, preserving the exfiltration boundary (x-api-key callers omit it).

Behavior-preserving

Pure refactor of a live path. The interactive /api/chat/workflow builds identical input as before.

Tests (TDD, RED→GREEN)

  • 4 new buildRunAgentInput unit tests (field pass-through, clone_url-derived ids/org, recoupAccessToken include/omit, null clone_url).
  • Existing handleChatWorkflowStream suite stays green (20). tsc + lint clean on touched files.

Done-when (issue item)

  • Both callers construct workflow input through one function; no duplication. (Headless caller wired in the re-point PR.)

🤖 Generated with Claude Code


Summary by cubic

Extracted a shared buildRunAgentInput to unify how we construct RunAgentWorkflowInput for interactive /api/chat/workflow and the upcoming headless /api/chat/generate, preventing drift. No behavior changes to the live path; this supports chat#1813.

  • Refactors
    • Moved input-building logic from handleChatWorkflowStream to lib/chat/buildRunAgentInput.ts; the handler now delegates to it.
    • Derived repoOwner/repoName and recoupOrgId from cloneUrl inside the builder as the single source of truth.
    • Forwarded recoupAccessToken only when provided to preserve the exfiltration boundary (x-api-key callers omit it).