fix(ui): use model input limit for avail tokens
Upgrade @opencode-ai/sdk to 1.2.6 and prefer v2 model limit.input when present for the session AVAIL chip; otherwise keep the existing context-window-based estimate.
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -2809,9 +2809,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@opencode-ai/sdk": {
|
"node_modules/@opencode-ai/sdk": {
|
||||||
"version": "1.1.11",
|
"version": "1.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/@opencode-ai/sdk/-/sdk-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@opencode-ai/sdk/-/sdk-1.2.6.tgz",
|
||||||
"integrity": "sha512-vqdNDz8Q+4bygmDdQem6oxhU31ci4JVdoND4ZJNeCs9x6OIU6MM3ybgemGpzNkgtJDlfb4xCdrPaZZ6Sr3V1IQ==",
|
"integrity": "sha512-dWMF8Aku4h7fh8sw5tQ2FtbqRLbIFT8FcsukpxTird49ax7oUXP+gzqxM/VdxHjfksQvzLBjLZyMdDStc5g7xA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@pinojs/redact": {
|
"node_modules/@pinojs/redact": {
|
||||||
@@ -12075,7 +12075,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@git-diff-view/solid": "^0.0.8",
|
"@git-diff-view/solid": "^0.0.8",
|
||||||
"@kobalte/core": "0.13.11",
|
"@kobalte/core": "0.13.11",
|
||||||
"@opencode-ai/sdk": "1.1.11",
|
"@opencode-ai/sdk": "1.2.6",
|
||||||
"@solidjs/router": "^0.13.0",
|
"@solidjs/router": "^0.13.0",
|
||||||
"@suid/icons-material": "^0.9.0",
|
"@suid/icons-material": "^0.9.0",
|
||||||
"@suid/material": "^0.19.0",
|
"@suid/material": "^0.19.0",
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@git-diff-view/solid": "^0.0.8",
|
"@git-diff-view/solid": "^0.0.8",
|
||||||
"@kobalte/core": "0.13.11",
|
"@kobalte/core": "0.13.11",
|
||||||
"@opencode-ai/sdk": "1.1.11",
|
"@opencode-ai/sdk": "1.2.6",
|
||||||
"@solidjs/router": "^0.13.0",
|
"@solidjs/router": "^0.13.0",
|
||||||
"@suid/icons-material": "^0.9.0",
|
"@suid/icons-material": "^0.9.0",
|
||||||
"@suid/material": "^0.19.0",
|
"@suid/material": "^0.19.0",
|
||||||
|
|||||||
@@ -63,9 +63,14 @@ export function updateSessionInfo(instanceId: string, sessionId: string): void {
|
|||||||
resolveSelectedModel(instanceProviders, latestProviderId, latestModelId)
|
resolveSelectedModel(instanceProviders, latestProviderId, latestModelId)
|
||||||
|
|
||||||
let modelOutputLimit = DEFAULT_MODEL_OUTPUT_LIMIT
|
let modelOutputLimit = DEFAULT_MODEL_OUTPUT_LIMIT
|
||||||
|
let modelInputLimit: number | null = null
|
||||||
|
|
||||||
if (selectedModel) {
|
if (selectedModel) {
|
||||||
contextWindow = selectedModel.limit?.context ?? 0
|
contextWindow = selectedModel.limit?.context ?? 0
|
||||||
|
const inputLimit = selectedModel.limit?.input
|
||||||
|
if (typeof inputLimit === "number" && inputLimit > 0) {
|
||||||
|
modelInputLimit = inputLimit
|
||||||
|
}
|
||||||
const outputLimit = selectedModel.limit?.output
|
const outputLimit = selectedModel.limit?.output
|
||||||
if (typeof outputLimit === "number" && outputLimit > 0) {
|
if (typeof outputLimit === "number" && outputLimit > 0) {
|
||||||
modelOutputLimit = Math.min(outputLimit, DEFAULT_MODEL_OUTPUT_LIMIT)
|
modelOutputLimit = Math.min(outputLimit, DEFAULT_MODEL_OUTPUT_LIMIT)
|
||||||
@@ -107,7 +112,13 @@ export function updateSessionInfo(instanceId: string, sessionId: string): void {
|
|||||||
|
|
||||||
const outputBudget = Math.min(modelOutputLimit, DEFAULT_MODEL_OUTPUT_LIMIT)
|
const outputBudget = Math.min(modelOutputLimit, DEFAULT_MODEL_OUTPUT_LIMIT)
|
||||||
|
|
||||||
if (!contextAvailableFromPrevious) {
|
if (modelInputLimit !== null) {
|
||||||
|
// Prefer explicit input limits when provided by the API.
|
||||||
|
// This is used by the UI "Avail" chip.
|
||||||
|
contextAvailableTokens = modelInputLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!contextAvailableFromPrevious && contextAvailableTokens === null) {
|
||||||
if (contextWindow > 0) {
|
if (contextWindow > 0) {
|
||||||
if (latestHasContextUsage && actualUsageTokens > 0) {
|
if (latestHasContextUsage && actualUsageTokens > 0) {
|
||||||
contextAvailableTokens = Math.max(contextWindow - (actualUsageTokens + outputBudget), 0)
|
contextAvailableTokens = Math.max(contextWindow - (actualUsageTokens + outputBudget), 0)
|
||||||
|
|||||||
@@ -291,12 +291,13 @@ async function createSession(instanceId: string, agent?: string): Promise<Sessio
|
|||||||
const initialProvider = instanceProviders.find((p) => p.id === session.model.providerId)
|
const initialProvider = instanceProviders.find((p) => p.id === session.model.providerId)
|
||||||
const initialModel = initialProvider?.models.find((m) => m.id === session.model.modelId)
|
const initialModel = initialProvider?.models.find((m) => m.id === session.model.modelId)
|
||||||
const initialContextWindow = initialModel?.limit?.context ?? 0
|
const initialContextWindow = initialModel?.limit?.context ?? 0
|
||||||
|
const initialInputLimit = initialModel?.limit?.input ?? 0
|
||||||
const initialSubscriptionModel = initialModel?.cost?.input === 0 && initialModel?.cost?.output === 0
|
const initialSubscriptionModel = initialModel?.cost?.input === 0 && initialModel?.cost?.output === 0
|
||||||
const initialOutputLimit =
|
const initialOutputLimit =
|
||||||
initialModel?.limit?.output && initialModel.limit.output > 0
|
initialModel?.limit?.output && initialModel.limit.output > 0
|
||||||
? initialModel.limit.output
|
? initialModel.limit.output
|
||||||
: DEFAULT_MODEL_OUTPUT_LIMIT
|
: DEFAULT_MODEL_OUTPUT_LIMIT
|
||||||
const initialContextAvailable = initialContextWindow > 0 ? initialContextWindow : null
|
const initialContextAvailable = initialInputLimit > 0 ? initialInputLimit : initialContextWindow > 0 ? initialContextWindow : null
|
||||||
|
|
||||||
setSessionInfoByInstance((prev) => {
|
setSessionInfoByInstance((prev) => {
|
||||||
const next = new Map(prev)
|
const next = new Map(prev)
|
||||||
@@ -398,10 +399,11 @@ async function forkSession(
|
|||||||
const forkProvider = instanceProviders.find((p) => p.id === forkedSession.model.providerId)
|
const forkProvider = instanceProviders.find((p) => p.id === forkedSession.model.providerId)
|
||||||
const forkModel = forkProvider?.models.find((m) => m.id === forkedSession.model.modelId)
|
const forkModel = forkProvider?.models.find((m) => m.id === forkedSession.model.modelId)
|
||||||
const forkContextWindow = forkModel?.limit?.context ?? 0
|
const forkContextWindow = forkModel?.limit?.context ?? 0
|
||||||
|
const forkInputLimit = forkModel?.limit?.input ?? 0
|
||||||
const forkSubscriptionModel = forkModel?.cost?.input === 0 && forkModel?.cost?.output === 0
|
const forkSubscriptionModel = forkModel?.cost?.input === 0 && forkModel?.cost?.output === 0
|
||||||
const forkOutputLimit =
|
const forkOutputLimit =
|
||||||
forkModel?.limit?.output && forkModel.limit.output > 0 ? forkModel.limit.output : DEFAULT_MODEL_OUTPUT_LIMIT
|
forkModel?.limit?.output && forkModel.limit.output > 0 ? forkModel.limit.output : DEFAULT_MODEL_OUTPUT_LIMIT
|
||||||
const forkContextAvailable = forkContextWindow > 0 ? forkContextWindow : null
|
const forkContextAvailable = forkInputLimit > 0 ? forkInputLimit : forkContextWindow > 0 ? forkContextWindow : null
|
||||||
|
|
||||||
setSessionInfoByInstance((prev) => {
|
setSessionInfoByInstance((prev) => {
|
||||||
const next = new Map(prev)
|
const next = new Map(prev)
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ export interface Model {
|
|||||||
variantKeys?: string[]
|
variantKeys?: string[]
|
||||||
limit?: {
|
limit?: {
|
||||||
context?: number
|
context?: number
|
||||||
|
input?: number
|
||||||
output?: number
|
output?: number
|
||||||
}
|
}
|
||||||
cost?: {
|
cost?: {
|
||||||
|
|||||||
Reference in New Issue
Block a user