mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
refactor(ai): delete dead code and duplicate type names (#60781)
This commit is contained in:
committed by
GitHub
Unverified
parent
635fb7b14d
commit
956e41fd17
@@ -29,7 +29,7 @@ export { ImageClient } from "./image-client.js"
|
||||
export { Auth } from "./route/auth.js"
|
||||
export { ProviderPackage } from "./provider-package.js"
|
||||
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js"
|
||||
export type { Interface as LLMClientShape, LLMClientService } from "./route/client.js"
|
||||
export type { LLMClientService } from "./route/client.js"
|
||||
export {
|
||||
ProtocolID,
|
||||
RouteID,
|
||||
@@ -105,7 +105,6 @@ export {
|
||||
InvalidRequestError,
|
||||
UnsupportedOperationError,
|
||||
ProviderConfigurationError,
|
||||
NoRouteError,
|
||||
AuthenticationError,
|
||||
RateLimitError,
|
||||
QuotaExceededError,
|
||||
@@ -189,7 +188,7 @@ export type {
|
||||
} from "./generation.js"
|
||||
export { ToolFailure, emptyInputJsonSchema, toDefinitions, tool } from "./tool.js"
|
||||
export { ToolRuntime } from "./tool-runtime.js"
|
||||
export type { DispatchResult as ToolDispatchResult, ToolSettlement } from "./tool-runtime.js"
|
||||
export type { ToolSettlement } from "./tool-runtime.js"
|
||||
export type {
|
||||
ExecutableTool,
|
||||
Tool,
|
||||
@@ -201,7 +200,3 @@ export type {
|
||||
ToolToModelOutput,
|
||||
} from "./tool.js"
|
||||
export type { LLM } from "./llm.js"
|
||||
export type {
|
||||
Definition as ProviderPackageDefinition,
|
||||
Settings as ProviderPackageSettings,
|
||||
} from "./provider-package.js"
|
||||
|
||||
@@ -32,8 +32,8 @@ export interface AwaitOptions {
|
||||
readonly poll?: Poll
|
||||
}
|
||||
|
||||
export const DEFAULT_POLL_INTERVAL = Duration.seconds(5)
|
||||
export const DEFAULT_POLL_TIMEOUT = Duration.minutes(10)
|
||||
const DEFAULT_POLL_INTERVAL = Duration.seconds(5)
|
||||
const DEFAULT_POLL_TIMEOUT = Duration.minutes(10)
|
||||
|
||||
export const QueuedEvent = Schema.Struct({
|
||||
type: Schema.tag("generation-queued"),
|
||||
|
||||
@@ -408,7 +408,6 @@ export {
|
||||
InvalidRequestError,
|
||||
UnsupportedOperationError,
|
||||
ProviderConfigurationError,
|
||||
NoRouteError,
|
||||
AuthenticationError,
|
||||
RateLimitError,
|
||||
QuotaExceededError,
|
||||
|
||||
@@ -75,7 +75,7 @@ export const isContextOverflow = (message: string) =>
|
||||
!exclusions.some((pattern) => pattern.test(message)) &&
|
||||
(patterns.some((pattern) => pattern.test(message)) || /^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(message))
|
||||
|
||||
export const isPayloadTooLarge = (message: string) => payloadPatterns.some((pattern) => pattern.test(message))
|
||||
const isPayloadTooLarge = (message: string) => payloadPatterns.some((pattern) => pattern.test(message))
|
||||
|
||||
export const isContextOverflowFailure = (failure: unknown) =>
|
||||
failure instanceof AIError
|
||||
@@ -113,7 +113,6 @@ export const isRetryable = (error: AIError) => {
|
||||
case "ContentPolicy":
|
||||
case "InvalidRequest":
|
||||
case "UnsupportedOperation":
|
||||
case "NoRoute":
|
||||
case "Timeout":
|
||||
return false
|
||||
default: {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
export { Route, LLMClient } from "./client.js"
|
||||
export type {
|
||||
Route as RouteShape,
|
||||
RouteLanguageModelInput,
|
||||
RouteRoutedLanguageModelInput,
|
||||
RouteDefaults,
|
||||
RouteDefaultsInput,
|
||||
AnyRoute,
|
||||
Interface as LLMClientShape,
|
||||
LLMClientService,
|
||||
StreamOptions,
|
||||
CompactMethod,
|
||||
@@ -29,18 +27,15 @@ export * as Transport from "./transport/index.js"
|
||||
export { ProviderShared } from "../protocols/shared.js"
|
||||
export { classifyProviderFailure } from "../provider-error.js"
|
||||
export { mergeHttpOptions } from "../schema/index.js"
|
||||
export type { Definition as AuthShape, AuthInput, Credential, CredentialError } from "./auth.js"
|
||||
export type { AuthInput, Credential, CredentialError } from "./auth.js"
|
||||
export type { ApiKeyMode, AuthOverride, ProviderAuthOption } from "./auth-options.js"
|
||||
export type { Definition as EndpointFn, EndpointInput } from "./endpoint.js"
|
||||
export type { Definition as FramingDef } from "./framing.js"
|
||||
export type { Protocol as ProtocolDef } from "./protocol.js"
|
||||
export type { EndpointInput } from "./endpoint.js"
|
||||
export type {
|
||||
ChannelCheckpoint,
|
||||
ChannelCreate,
|
||||
ChannelObservation,
|
||||
HttpHandler,
|
||||
HttpMiddleware,
|
||||
Transport as TransportDef,
|
||||
TransportExecuteOptions,
|
||||
TransportExecution,
|
||||
TransportRuntime,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Schema } from "effect"
|
||||
import { NonNegativeInt } from "@opencode/schema"
|
||||
import { Tool } from "@opencode/schema/tool"
|
||||
import { ModelID, ProviderID, RouteID } from "./ids.js"
|
||||
import { ProviderID, RouteID } from "./ids.js"
|
||||
import type { LLMResponse } from "./events.js"
|
||||
|
||||
export const ProviderFailureClassification = Schema.Literals(["context-overflow", "payload-too-large"])
|
||||
@@ -65,13 +65,6 @@ export class ProviderConfigurationError extends Schema.TaggedError<ProviderConfi
|
||||
message: Schema.String,
|
||||
}) {}
|
||||
|
||||
export class NoRouteError extends Schema.TaggedError<NoRouteError>("AI.Error.NoRoute")("NoRoute", {
|
||||
...ReasonFields,
|
||||
route: RouteID,
|
||||
provider: ProviderID,
|
||||
model: ModelID,
|
||||
}) {}
|
||||
|
||||
export class AuthenticationError extends Schema.TaggedError<AuthenticationError>("AI.Error.Authentication")(
|
||||
"Authentication",
|
||||
ReasonFields,
|
||||
@@ -147,7 +140,6 @@ export class TimeoutError extends Schema.TaggedError<TimeoutError>("AI.Error.Tim
|
||||
export const AIErrorReason = Schema.Union([
|
||||
InvalidRequestError,
|
||||
UnsupportedOperationError,
|
||||
NoRouteError,
|
||||
AuthenticationError,
|
||||
RateLimitError,
|
||||
QuotaExceededError,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { Effect, Schema, Stream } from "effect"
|
||||
import { ai, LLMRequest, LLMResponse } from "../src/effect.js"
|
||||
import { Route, Endpoint, LLMClient, Protocol, type FramingDef } from "../src/route.js"
|
||||
import { Route, Endpoint, LLMClient, Protocol, type Framing } from "../src/route.js"
|
||||
import { compileRequest } from "../src/route/client.js"
|
||||
import { LanguageModel } from "../src/schema/index.js"
|
||||
import { testEffect } from "./lib/effect.js"
|
||||
@@ -23,7 +23,7 @@ const FakeEvent = Schema.Union([
|
||||
type FakeEvent = Schema.Schema.Type<typeof FakeEvent>
|
||||
const decodeFakeEvents = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Array(FakeEvent)))
|
||||
|
||||
const fakeFraming: FramingDef<FakeEvent> = {
|
||||
const fakeFraming: Framing.Definition<FakeEvent> = {
|
||||
id: "fake-json-array",
|
||||
frame: (bytes) =>
|
||||
Stream.fromEffect(
|
||||
|
||||
@@ -15,12 +15,10 @@ import {
|
||||
LLMRequest,
|
||||
LanguageModel,
|
||||
ModelID,
|
||||
NoRouteError,
|
||||
ProviderID,
|
||||
ProviderInternalError,
|
||||
QuotaExceededError,
|
||||
RateLimitError,
|
||||
RouteID,
|
||||
TimeoutError,
|
||||
ToolOutput,
|
||||
ToolResultValue,
|
||||
@@ -336,12 +334,6 @@ test("AI error reasons are tagged Errors with required messages", () => {
|
||||
provider: model.provider,
|
||||
route: "fake-route",
|
||||
}),
|
||||
new NoRouteError({
|
||||
message: "No route",
|
||||
route: RouteID.make("missing"),
|
||||
provider: model.provider,
|
||||
model: model.id,
|
||||
}),
|
||||
new AuthenticationError({ message: "Missing credentials" }),
|
||||
new RateLimitError({ message: "Rate limited" }),
|
||||
new QuotaExceededError({ message: "Quota exceeded" }),
|
||||
@@ -355,7 +347,6 @@ test("AI error reasons are tagged Errors with required messages", () => {
|
||||
expect(reasons.map((reason) => reason._tag)).toEqual([
|
||||
"InvalidRequest",
|
||||
"UnsupportedOperation",
|
||||
"NoRoute",
|
||||
"Authentication",
|
||||
"RateLimit",
|
||||
"QuotaExceeded",
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
ImageModelSchema,
|
||||
LanguageModel,
|
||||
ProviderConfigurationError,
|
||||
type ProviderPackage,
|
||||
} from "@opencode/ai/effect"
|
||||
import { Auth, mergeHttpOptions } from "@opencode/ai/route"
|
||||
import { Context, Effect, Layer, Schema, Struct } from "effect"
|
||||
@@ -188,7 +189,7 @@ export const withVariant = (
|
||||
}
|
||||
|
||||
export interface Dependencies {
|
||||
readonly loadPackage?: (specifier: string) => Effect.Effect<Provider.ProviderPackage, Provider.LoadError>
|
||||
readonly loadPackage?: (specifier: string) => Effect.Effect<ProviderPackage.Definition, Provider.LoadError>
|
||||
readonly loadAISDK?: (model: RuntimeInfo) => Effect.Effect<LanguageModel, AISDK.InitError>
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Context, Effect, Layer, Option, Schema, Stream, Struct } from "effect"
|
||||
import { Provider } from "@opencode/schema/provider"
|
||||
import { Model } from "@opencode/schema/model"
|
||||
import { makeLocationNode } from "@opencode/util/effect/app-node"
|
||||
import { HttpTimeout, type ProviderPackageDefinition } from "@opencode/ai/effect"
|
||||
import { HttpTimeout, type ProviderPackage } from "@opencode/ai/effect"
|
||||
import { isRecord } from "@opencode/util/record"
|
||||
import { Npm } from "@opencode/util/npm"
|
||||
import type { DeepMutable } from "./schema.js"
|
||||
@@ -42,7 +42,6 @@ export class LoadError extends Schema.TaggedError<LoadError>()("Provider.LoadErr
|
||||
package: Schema.String,
|
||||
cause: Schema.Defect(),
|
||||
}) {}
|
||||
export type ProviderPackage = ProviderPackageDefinition
|
||||
|
||||
const packages = new Map<string, Promise<unknown>>()
|
||||
const builtins = new Map<string, () => Promise<unknown>>([
|
||||
@@ -566,5 +565,5 @@ const importPackage = Effect.fn("Provider.importPackage")(function* (
|
||||
cause: new Error(`Provider package ${specifier} does not export model(modelID, settings)`),
|
||||
})
|
||||
}
|
||||
return module as ProviderPackageDefinition
|
||||
return module as ProviderPackage.Definition
|
||||
})
|
||||
|
||||
@@ -58,8 +58,6 @@ export function toSessionError(cause: unknown): SessionError.Error {
|
||||
return providerError("provider.invalid-request", cause.reason)
|
||||
case "UnsupportedOperation":
|
||||
return providerError("provider.unsupported-operation", cause.reason)
|
||||
case "NoRoute":
|
||||
return providerError("provider.no-route", cause.reason)
|
||||
case "UnknownProvider":
|
||||
return providerError("provider.unknown", cause.reason)
|
||||
case "Timeout":
|
||||
|
||||
@@ -6,8 +6,6 @@ import {
|
||||
InvalidRequestError,
|
||||
UnsupportedOperationError,
|
||||
AIError,
|
||||
NoRouteError,
|
||||
ModelID,
|
||||
ProviderID,
|
||||
ProviderInternalError,
|
||||
QuotaExceededError,
|
||||
@@ -66,18 +64,6 @@ describe("toSessionError", () => {
|
||||
),
|
||||
),
|
||||
).toEqual({ type: "provider.unsupported-operation", message: "no compact endpoint" })
|
||||
expect(
|
||||
toSessionError(
|
||||
llm(
|
||||
new NoRouteError({
|
||||
message: "failed",
|
||||
route: "route",
|
||||
provider: ProviderID.make("provider"),
|
||||
model: ModelID.make("model"),
|
||||
}),
|
||||
),
|
||||
).type,
|
||||
).toBe("provider.no-route")
|
||||
expect(toSessionError(llm(new UnknownProviderError({ message: "unknown" }))).type).toBe("provider.unknown")
|
||||
})
|
||||
|
||||
@@ -347,18 +333,10 @@ describe("toSessionError", () => {
|
||||
llm(new InvalidProviderOutputError({ message: "output" })),
|
||||
llm(new InvalidRequestError({ message: "request" })),
|
||||
llm(new UnsupportedOperationError({ message: "unsupported", operation: "compact" })),
|
||||
llm(
|
||||
new NoRouteError({
|
||||
message: "failed",
|
||||
route: "route",
|
||||
provider: ProviderID.make("provider"),
|
||||
model: ModelID.make("model"),
|
||||
}),
|
||||
),
|
||||
]
|
||||
|
||||
expect(eligible.map(SessionRunnerRetry.isRetryable)).toEqual([true, true, true, true])
|
||||
expect(ineligible.map(SessionRunnerRetry.isRetryable)).toEqual([false, false, false, false, false, false, false])
|
||||
expect(ineligible.map(SessionRunnerRetry.isRetryable)).toEqual([false, false, false, false, false, false])
|
||||
})
|
||||
|
||||
test("retries accepted transport reads but not accepted writes or rejected requests", () => {
|
||||
|
||||
Reference in New Issue
Block a user