feat(core): add command registry (#30624)
This commit is contained in:
parent
70bb710715
commit
1ff19103a2
150 changed files with 4642 additions and 2546 deletions
23
packages/server/src/middleware/schema-error.ts
Normal file
23
packages/server/src/middleware/schema-error.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import * as Log from "@opencode-ai/core/util/log"
|
||||
import { Effect } from "effect"
|
||||
import { HttpApiMiddleware } from "effect/unstable/httpapi"
|
||||
import { InvalidRequestError } from "../errors"
|
||||
|
||||
const log = Log.create({ service: "server" })
|
||||
const REASON_LIMIT = 1024
|
||||
|
||||
function truncateReason(reason: string) {
|
||||
if (reason.length <= REASON_LIMIT) return reason
|
||||
return reason.slice(0, REASON_LIMIT) + `... (${reason.length - REASON_LIMIT} more chars)`
|
||||
}
|
||||
|
||||
export class SchemaErrorMiddleware extends HttpApiMiddleware.Service<SchemaErrorMiddleware>()(
|
||||
"@opencode/HttpApiSchemaError",
|
||||
{ error: InvalidRequestError },
|
||||
) {}
|
||||
|
||||
export const schemaErrorLayer = HttpApiMiddleware.layerSchemaErrorTransform(SchemaErrorMiddleware, (error) => {
|
||||
const reason = truncateReason(error.cause.message)
|
||||
log.warn("schema rejection", { kind: error.kind, reason })
|
||||
return Effect.fail(new InvalidRequestError({ message: reason, kind: error.kind }))
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue