Skip to content

Commit fe4c65f

Browse files
committed
refactor(providers): replace legacy as-any stream casts with annotated typed casts
1 parent f69e913 commit fe4c65f

2 files changed

Lines changed: 32 additions & 25 deletions

File tree

apps/sim/providers/deepseek/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ export const deepseekProvider: ProviderConfig = {
206206
streamFormat: 'agent-events-v1',
207207
createStream: ({ output }) =>
208208
createReadableStreamFromDeepseekStream(
209-
streamResponse as any,
209+
// double-cast-allowed: payload is untyped so the SDK cannot resolve the streaming overload; the stream yields OpenAI ChatCompletionChunk objects
210+
streamResponse as unknown as AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>,
210211
(content, usage, thinking) => {
211212
output.content = content
212213
output.tokens = {
@@ -591,7 +592,8 @@ export const deepseekProvider: ProviderConfig = {
591592
streamFormat: 'agent-events-v1',
592593
createStream: ({ output }) =>
593594
createReadableStreamFromDeepseekStream(
594-
streamResponse as any,
595+
// double-cast-allowed: payload is untyped so the SDK cannot resolve the streaming overload; the stream yields OpenAI ChatCompletionChunk objects
596+
streamResponse as unknown as AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>,
595597
(content, usage, thinking) => {
596598
output.content = content
597599
output.tokens = {

apps/sim/providers/groq/index.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,32 +228,36 @@ export const groqProvider: ProviderConfig = {
228228
isStreaming: true,
229229
streamFormat: 'agent-events-v1',
230230
createStream: ({ output }) =>
231-
createReadableStreamFromGroqStream(streamResponse as any, (content, usage, thinking) => {
232-
output.content = content
233-
output.tokens = {
234-
input: usage.prompt_tokens,
235-
output: usage.completion_tokens,
236-
total: usage.total_tokens,
237-
}
231+
createReadableStreamFromGroqStream(
232+
// double-cast-allowed: payload is untyped so the SDK cannot resolve the streaming overload; groq-sdk stream chunks are wire-compatible with the OpenAI ChatCompletionChunk shape the adapter consumes
233+
streamResponse as unknown as AsyncIterable<ChatCompletionChunk>,
234+
(content, usage, thinking) => {
235+
output.content = content
236+
output.tokens = {
237+
input: usage.prompt_tokens,
238+
output: usage.completion_tokens,
239+
total: usage.total_tokens,
240+
}
238241

239-
const costResult = calculateCost(
240-
request.model,
241-
usage.prompt_tokens,
242-
usage.completion_tokens
243-
)
244-
output.cost = {
245-
input: costResult.input,
246-
output: costResult.output,
247-
total: costResult.total,
248-
}
242+
const costResult = calculateCost(
243+
request.model,
244+
usage.prompt_tokens,
245+
usage.completion_tokens
246+
)
247+
output.cost = {
248+
input: costResult.input,
249+
output: costResult.output,
250+
total: costResult.total,
251+
}
249252

250-
if (thinking) {
251-
const segment = output.providerTiming?.timeSegments?.[0]
252-
if (segment) {
253-
segment.thinkingContent = thinking
253+
if (thinking) {
254+
const segment = output.providerTiming?.timeSegments?.[0]
255+
if (segment) {
256+
segment.thinkingContent = thinking
257+
}
254258
}
255259
}
256-
}),
260+
),
257261
})
258262

259263
return streamingResult
@@ -543,7 +547,8 @@ export const groqProvider: ProviderConfig = {
543547
streamFormat: 'agent-events-v1',
544548
createStream: ({ output }) =>
545549
createReadableStreamFromGroqStream(
546-
streamResponse as any,
550+
// double-cast-allowed: payload is untyped so the SDK cannot resolve the streaming overload; groq-sdk stream chunks are wire-compatible with the OpenAI ChatCompletionChunk shape the adapter consumes
551+
streamResponse as unknown as AsyncIterable<ChatCompletionChunk>,
547552
(content, usage, thinking) => {
548553
output.content = content
549554
output.tokens = {

0 commit comments

Comments
 (0)