feat(sdk): widen anthropic-compat types to match real claude-agent-sdk shape#368
Conversation
…k shape
Absorb existing @anthropic-ai/claude-agent-sdk consumers without per-callsite
casts. Four type-surface widenings on the @protolabsai/sdk/anthropic-compat
subpath, applied to both the hand-rolled .d.ts.template (the shipped contract)
and the runtime anthropic-compat.ts:
- HookCallback: 3-arg shape (input, toolUseId, { signal }) matching the real
SDK. The runtime wrapper now forwards toolUseId and an AbortSignal — the
query's abortController signal when supplied, else a fresh non-aborting one.
- mcpServers: McpServerConfig widened to a union of structured stdio/http/sdk
shapes plus a Record<string, unknown> fallback, so the typed union from
@protolabsai/types (no index signature) assigns cleanly. Passed through to
proto verbatim.
- systemPrompt: accepts a string or structured { type: 'preset', preset,
append }. A string passes through; a preset is mapped onto proto's preset
shape (proto consumes .append; its preset literal differs from claude_code).
- outputFormat: accepts string | { type: 'json_schema', schema }; still
dropped at runtime (proto has no structured-output option).
Bumps @protolabsai/sdk 0.3.4 -> 0.3.5. The issue's acceptance target now
typechecks against the shipped dist .d.ts under strict mode with no casts.
Adds anthropic-compat.test.ts covering the translation paths.
Closes #256.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
👀 Quinn is reviewing — verdict (PASS / WARN / FAIL) + findings to follow. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
WalkthroughThe SDK's anthropic-compat layer is widened to match the real Claude SDK type surface. HookCallback now accepts three arguments with abort signal support; new structured types for MCP servers, system prompts (presets), and output formats are exported. Hook wrapping threads the abort signal through the callback chain, and option translation converts systemPrompt presets to proto's expected shape while passing mcpServers and abort controllers through. ChangesAnthropic compat layer type widening and hook signal threading
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
QA Audit — PR #368 | feat(sdk): widen anthropic-compat types to match real claude-agent-sdk shape
VERDICT: WARN
CI Status
- Lint: queued
- CodeQL: queued
⏳ Non-terminal — formal PASS/FAIL follows when checks settle.
Diff Review
Widens the @protolabsai/sdk/anthropic-compat type surface across 4 axes in both the shipped .d.ts.template and runtime anthropic-compat.ts:
HookCallback→ 3-arg(input, toolUseId, { signal }). Runtime wrapper threadstoolUseIdandAbortSignal.mcpServers→McpStdioServerConfig | McpHttpServerConfig | McpSdkServerConfig | Record<string, unknown>union. Enables direct assignment from@protolabsai/typeswithout per-callsite casts.systemPrompt→string | { type: 'preset', preset, append? }. Preset maps to proto viaresolveSystemPromptOption.outputFormat→string | { type: 'json_schema', schema }. Dropped at runtime.
Both type definition files updated in lockstep; version bump 0.3.4 → 0.3.5.
Observations
- Gap: Clawpatch unavailable — base ref
'main'not a valid SHA in the checkout cache. Structural cross-file review could not run. - Gap: The diff is truncated at 532 lines (cap at 200 lines per call). The runtime implementation changes — hook invocation, signal threading, system prompt resolution, mcpServers passthrough, outputFormat handling — are not visible in the diff output. The type widening is sound, but the runtime correctness claims ("passes through verbatim", "signal threading", "preset→proto mapping") cannot be verified against the visible diff. These are the core functional claims of the PR.
- Verified: No unresolved CodeRabbit threads.
- Verified: Both
anthropic-compat.d.ts.templateandanthropic-compat.tsare updated consistently. - LOW:
ProtoMcpServerstype alias removed from runtime file; the docstring saysmcpServerspasses through verbatim — if the runtime forward logic changed, it's in the truncated portion.
Checks: 2 | Passed: 0 | Failed: 0 | Gaps: 2
— Quinn, QA Engineer
|
Submitted |
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
There was a problem hiding this comment.
CI terminal-green, no blockers on prior review — auto-approving on green (QwenLM#748).
Closes #256.
Summary
Widens the
@protolabsai/sdk/anthropic-compattype surface so existing@anthropic-ai/claude-agent-sdkconsumers migrate with a one-line import swap — no per-callsite casts. Applied to both the hand-rolledanthropic-compat.d.ts.template(the shipped contract, copied verbatim todist/anthropic-compat.d.ts) and the runtimeanthropic-compat.ts.The four widenings
HookCallback→ 3-arg(input, toolUseId, { signal }), matching the real SDK. The runtime wrapper forwardstoolUseIdand anAbortSignal— the query'sabortControllersignal when supplied, otherwise a fresh non-aborting one so the contract always holds.mcpServers—McpServerConfigwidened to a union of structured stdio/http/sdk shapes plus aRecord<string, unknown>fallback, so the typed union from@protolabsai/types(no index signature) assigns cleanly. Passed through to proto verbatim (single cast at the translation boundary).systemPrompt— acceptsstring | { type: 'preset', preset, append }. A string passes through; a preset maps onto proto's preset shape (proto consumes.append; its preset literal differs fromclaude_code). proto already supported this shape viaresolveSystemPromptOption.outputFormat— acceptsstring | { type: 'json_schema', schema }; still dropped at runtime (proto has no structured-output option).Bumps
@protolabsai/sdk0.3.4 → 0.3.5.Validation
dist/anthropic-compat.d.tsunder--strictwith no casts beyond the issue's own union-narrowing.test/unit/anthropic-compat.test.ts(6 tests) covers: preset→proto mapping, string passthrough, mcpServers passthrough, outputFormat drop, the 3-arg hook contract +block→{ shouldSkip, message }translation, and abortController signal threading.npm run typecheckclean; full SDK suite green (204 passed).Unblocks protoMaker PR 4 (removing the Anthropic SDK dep) —
sdk-options.tsbecomes a near-trivial import swap.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Breaking Changes
toolUseIdand abort signal parameters.