hir-123: swap fetch() to @anthropic-ai/sdk in triageReplyLLM#17
Open
jaredzwick wants to merge 1 commit into
Open
hir-123: swap fetch() to @anthropic-ai/sdk in triageReplyLLM#17jaredzwick wants to merge 1 commit into
jaredzwick wants to merge 1 commit into
Conversation
Replaces the direct fetch() call to api.anthropic.com with the official @anthropic-ai/sdk client. Same input/output contract, same model + prompt + heuristic fallback, same never-throws guarantee. Tests now mock the SDK module instead of overriding globalThis.fetch. Follow-up from CTO review on HIR-122 / PR pypesdev#14, founder pre-approved.
jaredzwick
commented
Jun 21, 2026
jaredzwick
left a comment
Collaborator
Author
There was a problem hiding this comment.
CTO Review — LGTM
Clean swap. Removes 21 lines of manual HTTP boilerplate (headers, fetch, JSON parsing) and replaces with 10 lines of typed SDK calls.
Key points:
- Type guard
(block): block is Anthropic.TextBlockis the correct way to narrow the union rather than comparing.typeand casting — gets the discriminated union right. - Signal forwarding moved from the
fetchoptions bag to the second arg ofclient.messages.create()per SDK API — correct. - Test refactor: replacing
globalThis.fetchmock withvi.mock('@anthropic-ai/sdk')is strictly better — it tests through the same import path the production code uses instead of patching the global. Thevi.hoisted()pattern ensures the mock factory runs before imports hoist. - "returns null when the API returns non-200" → "returns null when the SDK throws": correct rename. The SDK surfaces HTTP errors as thrown exceptions, not
ok: falseresponses. - Net: +43/-80 in tests (removes verbose response stubs), +10/-21 in implementation. Strictly a reduction in surface area.
No concerns. Ready to merge.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up from CTO review on HIR-122 for #14. Founder pre-approved deferring the SDK swap out of the original PR.
Summary
fetch()againsthttps://api.anthropic.com/v1/messageswithnew Anthropic({ apiKey }).messages.create({...})from@anthropic-ai/sdk.triageReplyLLM: still returnsTriageResult | null, still validates intent against the enum, still clamps confidence, still wrapped in the same try/catch so it never throws.ANTHROPIC_MODELenv /claude-haiku-4-5-20251001default), sameTRIAGE_PROMPT, same heuristic fallback path — none of those move.@anthropic-ai/sdkmodule directly viavi.mock+vi.hoistedinstead of overridingglobalThis.fetch. All 14replyTriagecases keep their original assertions.Stacked on #14 — base branch is
hir-120/warm-reply-triage. Will rebase tomainafter #14 merges.Out of scope (per HIR-123)
parseLLMJson.Test plan
pnpm test:int— 109 passed, 1 skipped. The unrelatedapi.int.spec.tsPayload-secret env failure exists on the base branch too.npx tsc --noEmit— clean.