mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-28 19:11:03 +08:00
fix(cli): address Kilo gateway review feedback
This commit is contained in:
@@ -23,10 +23,11 @@ import { DIRECT_FIM_ENV, requestMistralFim, resolveFimTarget } from "@kilocode/k
|
||||
import { DIRECT_EDIT_ENV, extractFencedBody, resolveEditTarget } from "@kilocode/kilo-gateway/edit"
|
||||
import { buildMercuryEditPrompt } from "@kilocode/kilo-gateway/edit-prompt"
|
||||
import { buildKiloHeaders } from "@kilocode/kilo-gateway"
|
||||
import { Effect } from "effect"
|
||||
import { Effect, Schema } from "effect"
|
||||
import * as Stream from "effect/Stream"
|
||||
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http"
|
||||
import { HttpApiBuilder, HttpApiError } from "effect/unstable/httpapi"
|
||||
import * as Log from "@opencode-ai/core/util/log"
|
||||
import { Auth } from "@/auth"
|
||||
import { EffectBridge } from "@/effect/bridge"
|
||||
import { Bus } from "@/bus"
|
||||
@@ -38,16 +39,17 @@ import { InstanceHttpApi } from "@/server/routes/instance/httpapi/api"
|
||||
import { MessageTable, PartTable, SessionTable } from "@/session/session.sql"
|
||||
import { Session } from "@/session/session"
|
||||
import { Database } from "@/storage/db"
|
||||
import { AudioTranscriptionsBody, EditBody, FimBody } from "../groups/kilo-gateway"
|
||||
import { AudioTranscriptionsBody, ClawStatus, EditBody, FimBody } from "../groups/kilo-gateway"
|
||||
|
||||
const FIM_TIMEOUT_MS = 30_000
|
||||
const log = Log.create({ service: "kilo-gateway" })
|
||||
|
||||
function jsonError(error: string, status: number) {
|
||||
return HttpServerResponse.jsonUnsafe({ error }, { status })
|
||||
}
|
||||
|
||||
function logError(route: string, err: unknown) {
|
||||
console.error(`[Kilo Gateway] ${route}: unhandled error`, err instanceof Error ? err.message : err)
|
||||
log.error("unhandled error", { route, err })
|
||||
}
|
||||
|
||||
export const kiloGatewayHandlers = HttpApiBuilder.group(InstanceHttpApi, "kilo", (handlers) =>
|
||||
@@ -322,7 +324,7 @@ export const kiloGatewayHandlers = HttpApiBuilder.group(InstanceHttpApi, "kilo",
|
||||
try: async () => {
|
||||
const response = await fetch(`${KILO_API_BASE}/api/kiloclaw/status`, { headers })
|
||||
if (!response.ok) throw new GatewayError(await response.text(), response.status)
|
||||
return response.json()
|
||||
return Schema.decodeUnknownPromise(ClawStatus)(await response.json())
|
||||
},
|
||||
catch: (err) => err,
|
||||
}).pipe(
|
||||
|
||||
@@ -56,6 +56,7 @@ const layer = HttpRouter.serve(
|
||||
const it = testEffect(layer)
|
||||
|
||||
function stub(run: () => Response | Promise<Response>) {
|
||||
// These tests run sequentially; scope the process-global override and delegate in-process server traffic.
|
||||
const original = globalThis.fetch
|
||||
const fetch: typeof globalThis.fetch = Object.assign(
|
||||
async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
|
||||
Reference in New Issue
Block a user