mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-14 12:10:45 +03:00
refactor(core): deduplicate session token types and tighten provider plugins (#57994)
This commit is contained in:
committed by
GitHub
Unverified
parent
199ad46421
commit
9624ff1d48
@@ -14,7 +14,7 @@ const decodeADCFile = Schema.decodeUnknownOption(
|
||||
Schema.fromJsonString(Schema.Struct({ quota_project_id: Schema.optional(Schema.String) })),
|
||||
)
|
||||
|
||||
function resolveProject(options: Record<string, any>) {
|
||||
function resolveProject(options: Record<string, unknown>) {
|
||||
// models.dev advertises GOOGLE_VERTEX_PROJECT for Vertex, while Google SDKs
|
||||
// and ADC examples commonly use the broader Google Cloud project aliases.
|
||||
const project =
|
||||
@@ -26,7 +26,7 @@ function resolveProject(options: Record<string, any>) {
|
||||
return typeof project === "string" ? project : undefined
|
||||
}
|
||||
|
||||
function resolveLocation(options: Record<string, any>) {
|
||||
function resolveLocation(options: Record<string, unknown>) {
|
||||
const location =
|
||||
options.location ??
|
||||
process.env.GOOGLE_VERTEX_LOCATION ??
|
||||
@@ -203,10 +203,11 @@ export const GoogleVertexPlugin = define({
|
||||
const location = resolveLocation(settings) ?? "global"
|
||||
for (const model of models.list(item.provider.id)) {
|
||||
if (typeof model.settings?.baseURL !== "string") continue
|
||||
const baseURL = replaceVertexVars(model.settings.baseURL, project, location)
|
||||
models.update(item.provider.id, model.id, (draft) => {
|
||||
draft.settings = {
|
||||
...draft.settings,
|
||||
baseURL: replaceVertexVars(String(draft.settings?.baseURL), project, location),
|
||||
baseURL,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ const device = (app: App.Info) =>
|
||||
),
|
||||
),
|
||||
),
|
||||
refresh: (value) => refresh(deviceMethodID, Credential.OAuth.make({ ...value, methodID: deviceMethodID }), app),
|
||||
refresh: (value) => refresh(deviceMethodID, value, app),
|
||||
}) satisfies IntegrationOAuthMethodRegistration
|
||||
|
||||
export const XAIPlugin = define({
|
||||
|
||||
@@ -17,6 +17,7 @@ import { InstructionEntry } from "./instruction-entry.js"
|
||||
import { Slug } from "../util/slug.js"
|
||||
import { FSUtil } from "@opencode/util/fs-util"
|
||||
import { Money } from "@opencode/schema/money"
|
||||
import type { TokenUsage } from "@opencode/schema/token-usage"
|
||||
import { Worktree } from "@opencode/schema/worktree"
|
||||
import { Project } from "@opencode/schema/project"
|
||||
import { AbsolutePath, RelativePath } from "../schema.js"
|
||||
@@ -36,12 +37,7 @@ export class SessionAlreadyProjected extends Error {}
|
||||
|
||||
type Usage = {
|
||||
cost: number
|
||||
tokens: {
|
||||
input: number
|
||||
output: number
|
||||
reasoning: number
|
||||
cache: { read: number; write: number }
|
||||
}
|
||||
tokens: TokenUsage.Info
|
||||
}
|
||||
|
||||
const ForkBatchSize = 500
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export * as SessionStats from "./stats.js"
|
||||
|
||||
import { DateTime, Effect, Option, Schema } from "effect"
|
||||
import { DateTime, Effect, Option, Schema, type Types } from "effect"
|
||||
import { and, eq, gte, inArray, lt, sql } from "drizzle-orm"
|
||||
import { Model } from "@opencode/schema/model"
|
||||
import { Money } from "@opencode/schema/money"
|
||||
@@ -22,12 +22,7 @@ type Input = {
|
||||
readonly tools?: ToolMode
|
||||
}
|
||||
|
||||
type Tokens = {
|
||||
input: number
|
||||
output: number
|
||||
reasoning: number
|
||||
cache: { read: number; write: number }
|
||||
}
|
||||
type Tokens = Types.DeepMutable<TokenUsage.Info>
|
||||
|
||||
type MessageRow = {
|
||||
sessionID: string
|
||||
@@ -375,7 +370,7 @@ function emptyTokens(): Tokens {
|
||||
return { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } }
|
||||
}
|
||||
|
||||
function addTokens(target: Tokens, source: Tokens) {
|
||||
function addTokens(target: Tokens, source: TokenUsage.Info) {
|
||||
target.input += source.input
|
||||
target.output += source.output
|
||||
target.reasoning += source.reasoning
|
||||
|
||||
Reference in New Issue
Block a user