CLI perf: reduce deps (#22652)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
|
||||
import { Log } from "../util"
|
||||
import { Installation } from "../installation"
|
||||
import { InstallationVersion } from "../installation/version"
|
||||
import { OAUTH_DUMMY_KEY } from "../auth"
|
||||
import os from "os"
|
||||
import { setTimeout as sleep } from "node:timers/promises"
|
||||
@@ -510,7 +511,7 @@ export async function CodexAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": `opencode/${Installation.VERSION}`,
|
||||
"User-Agent": `opencode/${InstallationVersion}`,
|
||||
},
|
||||
body: JSON.stringify({ client_id: CLIENT_ID }),
|
||||
})
|
||||
@@ -534,7 +535,7 @@ export async function CodexAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": `opencode/${Installation.VERSION}`,
|
||||
"User-Agent": `opencode/${InstallationVersion}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
device_auth_id: deviceData.device_auth_id,
|
||||
@@ -594,7 +595,7 @@ export async function CodexAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
"chat.headers": async (input, output) => {
|
||||
if (input.model.providerID !== "openai") return
|
||||
output.headers.originator = "opencode"
|
||||
output.headers["User-Agent"] = `opencode/${Installation.VERSION} (${os.platform()} ${os.release()}; ${os.arch()})`
|
||||
output.headers["User-Agent"] = `opencode/${InstallationVersion} (${os.platform()} ${os.release()}; ${os.arch()})`
|
||||
output.headers.session_id = input.sessionID
|
||||
},
|
||||
"chat.params": async (input, output) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
|
||||
import type { Model } from "@opencode-ai/sdk/v2"
|
||||
import { Installation } from "@/installation"
|
||||
import { InstallationVersion } from "@/installation/version"
|
||||
import { iife } from "@/util/iife"
|
||||
import { Log } from "../../util"
|
||||
import { setTimeout as sleep } from "node:timers/promises"
|
||||
@@ -70,7 +71,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
base(auth.enterpriseUrl),
|
||||
{
|
||||
Authorization: `Bearer ${auth.refresh}`,
|
||||
"User-Agent": `opencode/${Installation.VERSION}`,
|
||||
"User-Agent": `opencode/${InstallationVersion}`,
|
||||
},
|
||||
provider.models,
|
||||
).catch((error) => {
|
||||
@@ -150,7 +151,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
const headers: Record<string, string> = {
|
||||
"x-initiator": isAgent ? "agent" : "user",
|
||||
...(init?.headers as Record<string, string>),
|
||||
"User-Agent": `opencode/${Installation.VERSION}`,
|
||||
"User-Agent": `opencode/${InstallationVersion}`,
|
||||
Authorization: `Bearer ${info.refresh}`,
|
||||
"Openai-Intent": "conversation-edits",
|
||||
}
|
||||
@@ -226,7 +227,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": `opencode/${Installation.VERSION}`,
|
||||
"User-Agent": `opencode/${InstallationVersion}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
client_id: CLIENT_ID,
|
||||
@@ -256,7 +257,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": `opencode/${Installation.VERSION}`,
|
||||
"User-Agent": `opencode/${InstallationVersion}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
client_id: CLIENT_ID,
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
printParseErrorCode,
|
||||
} from "jsonc-parser"
|
||||
|
||||
import { ConfigPaths } from "@/config"
|
||||
import * as ConfigPaths from "@/config/paths"
|
||||
import { Global } from "@/global"
|
||||
import { Filesystem } from "@/util"
|
||||
import { Flock } from "@opencode-ai/shared/util/flock"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { Config } from "@/config"
|
||||
import { Installation } from "@/installation"
|
||||
import {
|
||||
checkPluginCompatibility,
|
||||
createPluginEntry,
|
||||
@@ -10,11 +8,13 @@ import {
|
||||
type PluginPackage,
|
||||
type PluginSource,
|
||||
} from "./shared"
|
||||
import { ConfigPlugin } from "@/config/plugin"
|
||||
import { InstallationVersion } from "@/installation/version"
|
||||
|
||||
export namespace PluginLoader {
|
||||
export type Plan = {
|
||||
spec: string
|
||||
options: Config.PluginOptions | undefined
|
||||
options: ConfigPlugin.Options | undefined
|
||||
deprecated: boolean
|
||||
}
|
||||
export type Resolved = Plan & {
|
||||
@@ -33,7 +33,7 @@ export namespace PluginLoader {
|
||||
mod: Record<string, unknown>
|
||||
}
|
||||
|
||||
type Candidate = { origin: Config.PluginOrigin; plan: Plan }
|
||||
type Candidate = { origin: ConfigPlugin.Origin; plan: Plan }
|
||||
type Report = {
|
||||
start?: (candidate: Candidate, retry: boolean) => void
|
||||
missing?: (candidate: Candidate, retry: boolean, message: string, resolved: Missing) => void
|
||||
@@ -46,9 +46,9 @@ export namespace PluginLoader {
|
||||
) => void
|
||||
}
|
||||
|
||||
function plan(item: Config.PluginSpec): Plan {
|
||||
const spec = Config.pluginSpecifier(item)
|
||||
return { spec, options: Config.pluginOptions(item), deprecated: isDeprecatedPlugin(spec) }
|
||||
function plan(item: ConfigPlugin.Spec): Plan {
|
||||
const spec = ConfigPlugin.pluginSpecifier(item)
|
||||
return { spec, options: ConfigPlugin.pluginOptions(item), deprecated: isDeprecatedPlugin(spec) }
|
||||
}
|
||||
|
||||
export async function resolve(
|
||||
@@ -88,7 +88,7 @@ export namespace PluginLoader {
|
||||
|
||||
if (base.source === "npm") {
|
||||
try {
|
||||
await checkPluginCompatibility(base.target, Installation.VERSION, base.pkg)
|
||||
await checkPluginCompatibility(base.target, InstallationVersion, base.pkg)
|
||||
} catch (error) {
|
||||
return { ok: false, stage: "compatibility", error }
|
||||
}
|
||||
@@ -111,8 +111,8 @@ export namespace PluginLoader {
|
||||
candidate: Candidate,
|
||||
kind: PluginKind,
|
||||
retry: boolean,
|
||||
finish: ((load: Loaded, origin: Config.PluginOrigin, retry: boolean) => Promise<R | undefined>) | undefined,
|
||||
missing: ((value: Missing, origin: Config.PluginOrigin, retry: boolean) => Promise<R | undefined>) | undefined,
|
||||
finish: ((load: Loaded, origin: ConfigPlugin.Origin, retry: boolean) => Promise<R | undefined>) | undefined,
|
||||
missing: ((value: Missing, origin: ConfigPlugin.Origin, retry: boolean) => Promise<R | undefined>) | undefined,
|
||||
report: Report | undefined,
|
||||
): Promise<R | undefined> {
|
||||
const plan = candidate.plan
|
||||
@@ -141,11 +141,11 @@ export namespace PluginLoader {
|
||||
}
|
||||
|
||||
type Input<R> = {
|
||||
items: Config.PluginOrigin[]
|
||||
items: ConfigPlugin.Origin[]
|
||||
kind: PluginKind
|
||||
wait?: () => Promise<void>
|
||||
finish?: (load: Loaded, origin: Config.PluginOrigin, retry: boolean) => Promise<R | undefined>
|
||||
missing?: (value: Missing, origin: Config.PluginOrigin, retry: boolean) => Promise<R | undefined>
|
||||
finish?: (load: Loaded, origin: ConfigPlugin.Origin, retry: boolean) => Promise<R | undefined>
|
||||
missing?: (value: Missing, origin: ConfigPlugin.Origin, retry: boolean) => Promise<R | undefined>
|
||||
report?: Report
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user