Skip to content

Commit 2c52bd1

Browse files
ci: apply automated fixes
1 parent 0e72363 commit 2c52bd1

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

.changeset/migrate-groq-openrouter-to-openai-base.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Migrate `ai-groq` and `ai-openrouter` onto `OpenAICompatibleChatCompletionsTextAdapter` so they share the stream accumulator, partial-JSON tool-call buffer, RUN_ERROR taxonomy, and lifecycle gates with `ai-openai` / `ai-grok`. Removes ~1k LOC of duplicated stream processing.
88

9-
`@tanstack/openai-base` adds three protected hooks on `OpenAICompatibleChatCompletionsTextAdapter` so providers with non-OpenAI SDK shapes can reuse the base: `callChatCompletion` and `callChatCompletionStream` (SDK call sites for non-streaming and streaming Chat Completions), and `extractReasoning` (surface reasoning content from chunk shapes that carry it, e.g. OpenRouter's `delta.reasoningDetails`, into the base's REASONING_* + legacy STEP_STARTED/STEP_FINISHED lifecycle). Also adds `transformStructuredOutput` for subclasses (like OpenRouter) that preserve nulls in structured output instead of converting them to undefined.
9+
`@tanstack/openai-base` adds three protected hooks on `OpenAICompatibleChatCompletionsTextAdapter` so providers with non-OpenAI SDK shapes can reuse the base: `callChatCompletion` and `callChatCompletionStream` (SDK call sites for non-streaming and streaming Chat Completions), and `extractReasoning` (surface reasoning content from chunk shapes that carry it, e.g. OpenRouter's `delta.reasoningDetails`, into the base's REASONING\_\* + legacy STEP_STARTED/STEP_FINISHED lifecycle). Also adds `transformStructuredOutput` for subclasses (like OpenRouter) that preserve nulls in structured output instead of converting them to undefined.
1010

1111
`@tanstack/ai-groq` drops the `groq-sdk` dependency in favour of the OpenAI SDK pointed at `https://api.groq.com/openai/v1` (the same pattern as `ai-grok` against xAI). The Groq-specific quirk where streaming usage arrives under `chunk.x_groq.usage` is preserved via a small `processStreamChunks` wrapper that promotes it to the standard `chunk.usage` slot.
1212

packages/typescript/ai-groq/tests/groq-adapter.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ function createAsyncIterable<T>(chunks: Array<T>): AsyncIterable<T> {
5656
// = createGroqText(...)`. The wrapped factories below apply the pending
5757
// mock to the returned adapter so it intercepts subsequent chatStream/
5858
// structuredOutput calls.
59-
let pendingMockCreate:
60-
| Mock<(...args: Array<unknown>) => unknown>
61-
| undefined
59+
let pendingMockCreate: Mock<(...args: Array<unknown>) => unknown> | undefined
6260

6361
function setupMockSdkClient(
6462
streamChunks: Array<Record<string, unknown>>,

packages/typescript/ai-openrouter/src/adapters/text.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ export class OpenRouterTextAdapter<
9898
// client we never use. The OpenRouter SDK supports a Promise-returning
9999
// apiKey getter; the OpenAI SDK's constructor here is a no-op for our
100100
// purposes, so any string suffices.
101-
const apiKey =
102-
typeof config.apiKey === 'string' ? config.apiKey : 'unused'
101+
const apiKey = typeof config.apiKey === 'string' ? config.apiKey : 'unused'
103102
super(
104103
{ apiKey, baseURL: 'https://openrouter.ai/api/v1' },
105104
model,
@@ -259,7 +258,9 @@ export class OpenRouterTextAdapter<
259258
const modelOptions = options.modelOptions as
260259
| (Record<string, any> & { variant?: string })
261260
| undefined
262-
const variantSuffix = modelOptions?.variant ? `:${modelOptions.variant}` : ''
261+
const variantSuffix = modelOptions?.variant
262+
? `:${modelOptions.variant}`
263+
: ''
263264

264265
const messages: Array<any> = []
265266
if (options.systemPrompts?.length) {
@@ -412,9 +413,12 @@ async function* adaptOpenRouterStreamChunks(
412413

413414
// Surface upstream errors so the base can route them to RUN_ERROR.
414415
if ((chunk as any).error) {
415-
throw Object.assign(new Error((chunk as any).error.message || 'OpenRouter stream error'), {
416-
code: (chunk as any).error.code,
417-
})
416+
throw Object.assign(
417+
new Error((chunk as any).error.message || 'OpenRouter stream error'),
418+
{
419+
code: (chunk as any).error.code,
420+
},
421+
)
418422
}
419423

420424
yield adapted as ChatCompletionChunk

packages/typescript/openai-base/src/adapters/chat-completions-text.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ export class OpenAICompatibleChatCompletionsTextAdapter<
256256
protected async callChatCompletionStream(
257257
params: OpenAI_SDK.Chat.Completions.ChatCompletionCreateParamsStreaming,
258258
requestOptions: ReturnType<typeof extractRequestOptions>,
259-
): Promise<
260-
AsyncIterable<OpenAI_SDK.Chat.Completions.ChatCompletionChunk>
261-
> {
259+
): Promise<AsyncIterable<OpenAI_SDK.Chat.Completions.ChatCompletionChunk>> {
262260
return this.client.chat.completions.create(params, requestOptions)
263261
}
264262

0 commit comments

Comments
 (0)