Repository navigation
Description
Summary
grokSummarize(...) (and createGrokSummarize(...)) is not assignable to summarize()'s adapter param for any current Grok model (grok-4.3, grok-build-0.1). This is a real type regression introduced by main's provider-options rewrite; it was never caught because the only call sites live in testing/**, which CI excludes from test:types (see #820).
Repro
import { summarize } from '@tanstack/ai'
import { grokSummarize } from '@tanstack/ai-grok/adapters'
summarize({ adapter: grokSummarize('grok-4.3'), text: 'x' }) // ❌ type error
summarize({ adapter: grokSummarize('grok-build-0.1'), text: 'x' }) // ❌ type errorType 'ChatStreamSummarizeAdapter<"grok-4.3", GrokTextProviderOptions>' is not assignable to
'SummarizeAdapter<string, object>'.
Types of property 'summarize' are incompatible.
Type '(options: SummarizationOptions<GrokTextProviderOptions>) => Promise<SummarizationResult>'
is not assignable to '(options: SummarizationOptions<object>) => Promise<SummarizationResult>'.
... Type 'SummarizationOptions<object>' is not assignable to 'SummarizationOptions<GrokTextProviderOptions>'.
Type 'object' is not assignable to type 'GrokTextProviderOptions'.
OpenAI (openaiSummarize('gpt-5.2')) passes — confirming this is Grok-specific.
Root cause
SummarizeAdapter.summarize is declared as a property (arrow-function type), not a method shorthand (packages/ai/src/activities/summarize/adapter.ts:49). Under strictFunctionTypes, property-position function params are checked contravariantly. So assignability to the constraint SummarizeAdapter<string, object> (the bound on summarize<TAdapter extends SummarizeAdapter<string, object>>) reduces to:
is
objectassignable toTProviderOptions?
For Grok, TProviderOptions is GrokTextProviderOptions, which extends Record<string, unknown> (packages/ai-grok/src/text/text-provider-options.ts:35-36):
export interface GrokTextProviderOptions
extends GrokBaseOptions, Record<string, unknown> { ... }object is not assignable to Record<string, unknown> (an index-signature type), so the check fails. grok-build-0.1 resolves to GrokBuildProviderOptions = Omit<GrokTextProviderOptions, 'reasoning'> & { reasoning?: never }, which retains the index signature and fails the same way.
OpenAI's options (ExternalTextProviderOptions) are a pure intersection of interfaces with all-optional named props and no index signature, and object is assignable to an all-optional object type — which is why OpenAI passes. So the index signature on the Grok options is exactly what breaks it; it is not present on the other providers.
Minimal isolation
const r1: Record<string, unknown> = {} as object // ❌ object not assignable to index-sig type
const r2: { a?: number } = {} as object // ✅ object assignable to all-optional typeFix direction
Make Grok's options match the all-optional, no-index-signature shape the other providers use:
- Drop
extends ... Record<string, unknown>fromGrokTextProviderOptions; keep only the named optional props. - Re-check
GrokBuildProviderOptions'sOmit<..., 'reasoning'>— with the index signature gone,Omitwill preserve the named keys correctly instead of collapsing them intostring.
Confirm afterward that per-model provider-options narrowing (the reasoning?: never distinction for grok-build-0.1) still holds.
Test coverage
- Add a call-site type assertion in
packages/ai-grok/tests/(an included package) so this can never regress silently again:Constructing the adapter (current coverage) is not enough — the constraint only instantiates at thesummarize({ adapter: grokSummarize('grok-4.3'), text: '' }) summarize({ adapter: grokSummarize('grok-build-0.1'), text: '' })
summarize()call site.
Related
- ci: type-check is excluded from examples/** and testing/** — call-site type regressions slip through test:pr #820 — CI gap that allowed this to slip through (
test:typesexcludesexamples/**andtesting/**).
Activity
docs(kiira): fix post-rebase Grok drift + drop migration as-casts
fix(ai-grok): remove Record<string,unknown> index sig from GrokTextPr…
fix(ai-grok): make grok provider options assignable to summarize() ad…
ci: type-check examples/** and testing/** to catch call-site regressi…
fix(ai-grok): make grok provider options assignable to summarize() ad…