mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-19 01:51:21 +08:00
fix: type FIM stream response instead of z.any()/unknown
This commit is contained in:
@@ -96,6 +96,27 @@ export function createKiloRoutes(deps: KiloRoutesDeps) {
|
||||
currentOrgId: z.string().nullable(),
|
||||
})
|
||||
|
||||
const FimStreamChunk = z.object({
|
||||
choices: z
|
||||
.array(
|
||||
z.object({
|
||||
delta: z
|
||||
.object({
|
||||
content: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
usage: z
|
||||
.object({
|
||||
prompt_tokens: z.number().optional(),
|
||||
completion_tokens: z.number().optional(),
|
||||
})
|
||||
.optional(),
|
||||
cost: z.number().optional(),
|
||||
})
|
||||
|
||||
return new Hono()
|
||||
.get(
|
||||
"/profile",
|
||||
@@ -193,7 +214,7 @@ export function createKiloRoutes(deps: KiloRoutesDeps) {
|
||||
description: "Streaming FIM completion response",
|
||||
content: {
|
||||
"text/event-stream": {
|
||||
schema: resolver(z.any()),
|
||||
schema: resolver(FimStreamChunk),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Session, Agent, Provider, Event, ProviderListResponse } from "@kilocode/sdk/v2/client"
|
||||
import type { Session, Agent, Event, ProviderListResponse } from "@kilocode/sdk/v2/client"
|
||||
|
||||
/** A single provider entry as returned by the /provider list endpoint. */
|
||||
export type ProviderInfo = ProviderListResponse["all"][number]
|
||||
|
||||
@@ -95,18 +95,13 @@ export class AutocompleteModel {
|
||||
)
|
||||
|
||||
for await (const chunk of stream) {
|
||||
const event = chunk as {
|
||||
choices?: Array<{ delta?: { content?: string } }>
|
||||
usage?: { prompt_tokens?: number; completion_tokens?: number }
|
||||
cost?: number
|
||||
}
|
||||
const content = event.choices?.[0]?.delta?.content
|
||||
const content = chunk.choices?.[0]?.delta?.content
|
||||
if (content) onChunk(content)
|
||||
if (event.usage) {
|
||||
inputTokens = event.usage.prompt_tokens ?? 0
|
||||
outputTokens = event.usage.completion_tokens ?? 0
|
||||
if (chunk.usage) {
|
||||
inputTokens = chunk.usage.prompt_tokens ?? 0
|
||||
outputTokens = chunk.usage.completion_tokens ?? 0
|
||||
}
|
||||
if (event.cost !== undefined) cost = event.cost
|
||||
if (chunk.cost !== undefined) cost = chunk.cost
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -4578,9 +4578,22 @@ export type KiloFimResponses = {
|
||||
/**
|
||||
* Streaming FIM completion response
|
||||
*/
|
||||
200: unknown
|
||||
200: {
|
||||
choices?: Array<{
|
||||
delta?: {
|
||||
content?: string
|
||||
}
|
||||
}>
|
||||
usage?: {
|
||||
prompt_tokens?: number
|
||||
completion_tokens?: number
|
||||
}
|
||||
cost?: number
|
||||
}
|
||||
}
|
||||
|
||||
export type KiloFimResponse = KiloFimResponses[keyof KiloFimResponses]
|
||||
|
||||
export type KiloNotificationsData = {
|
||||
body?: never
|
||||
path?: never
|
||||
|
||||
Reference in New Issue
Block a user