Skip to content

Commit 7637a6a

Browse files
Merge remote-tracking branch 'upstream/dev' into ocv
2 parents 69178dc + 65e3348 commit 7637a6a

File tree

11 files changed

+134
-24
lines changed

11 files changed

+134
-24
lines changed

bun.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/hashes.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"nodeModules": {
3-
"x86_64-linux": "sha256-fNRQYkucjXr1D61HJRScJpDa6+oBdyhgTBxCu+PE2kQ=",
4-
"aarch64-linux": "sha256-V8J6kn2nSdXrplyqi6aIqNlHcVjSxvye+yC/YFO7PF4=",
5-
"aarch64-darwin": "sha256-6cLmUJVUycGALCmslXuloVGBSlFOSHRjsWjx7KOW8rg=",
6-
"x86_64-darwin": "sha256-kcOSO3NFIJh79ylLotG41ovWLQfH5kh1WYFghUu+4HE="
3+
"x86_64-linux": "sha256-g29OM3dy+sZ3ioTs8zjQOK1N+KnNr9ptP9xtdPcdr64=",
4+
"aarch64-linux": "sha256-Iu91KwDcV5omkf4Ngny1aYpyCkPLjuoWOVUDOJUhW1k=",
5+
"aarch64-darwin": "sha256-bk3G6m+Yo60Ea3Kyglc37QZf5Vm7MLMFcxemjc7HnL0=",
6+
"x86_64-darwin": "sha256-y3hooQw13Z3Cu0KFfXYdpkTEeKTyuKd+a/jsXHQLdqA="
77
}
88
}

packages/app/src/pages/layout/sidebar-workspace.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ const WorkspaceSessionList = (props: {
274274
<div class="relative w-full py-1">
275275
<Button
276276
variant="ghost"
277-
class="flex w-full text-left justify-start text-14-regular text-text-weak pl-9 pr-10"
277+
class="flex w-full text-left justify-start text-14-regular text-text-weak pl-2 pr-10"
278278
size="large"
279279
onClick={(e: MouseEvent) => {
280280
props.loadMore()

packages/app/src/pages/session/message-timeline.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,10 @@ export function MessageTimeline(props: {
642642
onClick={props.onResumeScroll}
643643
>
644644
<div
645-
class="flex items-center justify-center w-8 h-6 rounded-[6px] border border-[var(--gray-dark-7)] bg-[color-mix(in_srgb,var(--gray-dark-3)_80%,transparent)] backdrop-blur-[0.75px] transition-colors group-hover:border-[var(--gray-dark-8)] [--icon-base:var(--gray-dark-10)] group-hover:[--icon-base:var(--gray-dark-11)]"
645+
class="flex items-center justify-center w-8 h-6 rounded-[6px] border border-border-weaker-base bg-[color-mix(in_srgb,var(--surface-raised-stronger-non-alpha)_80%,transparent)] backdrop-blur-[0.75px] transition-colors group-hover:border-[var(--border-weak-base)] group-hover:[--icon-base:var(--icon-hover)]"
646646
style={{
647647
"box-shadow":
648-
"0 51px 60px 0 rgba(0,0,0,0.13), 0 15.375px 18.088px 0 rgba(0,0,0,0.19), 0 6.386px 7.513px 0 rgba(0,0,0,0.25), 0 2.31px 2.717px 0 rgba(0,0,0,0.38)",
648+
"0 51px 60px 0 rgba(0,0,0,0.10), 0 15px 18px 0 rgba(0,0,0,0.12), 0 6.386px 7.513px 0 rgba(0,0,0,0.12), 0 2.31px 2.717px 0 rgba(0,0,0,0.20)",
649649
}}
650650
>
651651
<Icon name="arrow-down-to-line" size="small" />

packages/opencode/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"@actions/core": "1.11.1",
7777
"@actions/github": "6.0.1",
7878
"@agentclientprotocol/sdk": "0.16.1",
79+
"@ai-sdk/alibaba": "1.0.17",
7980
"@ai-sdk/amazon-bedrock": "4.0.93",
8081
"@ai-sdk/anthropic": "3.0.67",
8182
"@ai-sdk/azure": "3.0.49",

packages/opencode/src/cli/cmd/providers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ async function handlePluginAuth(plugin: { auth: PluginAuth }, provider: string,
148148
}
149149

150150
if (method.type === "api") {
151+
const key = await prompts.password({
152+
message: "Enter your API key",
153+
validate: (x) => (x && x.length > 0 ? undefined : "Required"),
154+
})
155+
if (prompts.isCancel(key)) throw new UI.CancelledError()
156+
151157
if (method.authorize) {
152158
const result = await method.authorize(inputs)
153159
if (result.type === "failed") {
@@ -157,7 +163,7 @@ async function handlePluginAuth(plugin: { auth: PluginAuth }, provider: string,
157163
const saveProvider = result.provider ?? provider
158164
await Auth.set(saveProvider, {
159165
type: "api",
160-
key: result.key,
166+
key: result.key ?? key,
161167
})
162168
prompts.log.success("Login successful")
163169
}

packages/opencode/src/provider/provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { createTogetherAI } from "@ai-sdk/togetherai"
4646
import { createPerplexity } from "@ai-sdk/perplexity"
4747
import { createVercel } from "@ai-sdk/vercel"
4848
import { createVenice } from "venice-ai-sdk-provider"
49+
import { createAlibaba } from "@ai-sdk/alibaba"
4950
import {
5051
createGitLab,
5152
VERSION as GITLAB_PROVIDER_VERSION,
@@ -145,6 +146,7 @@ export namespace Provider {
145146
"@ai-sdk/togetherai": createTogetherAI,
146147
"@ai-sdk/perplexity": createPerplexity,
147148
"@ai-sdk/vercel": createVercel,
149+
"@ai-sdk/alibaba": createAlibaba,
148150
"gitlab-ai-provider": createGitLab,
149151
"@ai-sdk/github-copilot": createGitHubCopilotOpenAICompatible,
150152
"venice-ai-sdk-provider": createVenice,

packages/opencode/src/provider/transform.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ export namespace ProviderTransform {
209209
copilot: {
210210
copilot_cache_control: { type: "ephemeral" },
211211
},
212+
alibaba: {
213+
cacheControl: { type: "ephemeral" },
214+
},
212215
}
213216

214217
for (const msg of unique([...system, ...final])) {
@@ -285,7 +288,8 @@ export namespace ProviderTransform {
285288
model.api.id.includes("claude") ||
286289
model.id.includes("anthropic") ||
287290
model.id.includes("claude") ||
288-
model.api.npm === "@ai-sdk/anthropic") &&
291+
model.api.npm === "@ai-sdk/anthropic" ||
292+
model.api.npm === "@ai-sdk/alibaba") &&
289293
model.api.npm !== "@ai-sdk/gateway"
290294
) {
291295
msgs = applyCaching(msgs, model)

packages/opencode/src/session/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BusEvent } from "@/bus/bus-event"
44
import { Bus } from "@/bus"
55
import { Decimal } from "decimal.js"
66
import z from "zod"
7-
import { type ProviderMetadata } from "ai"
7+
import { type ProviderMetadata, type LanguageModelUsage } from "ai"
88
import { Flag } from "../flag/flag"
99
import { Installation } from "../installation"
1010

@@ -28,7 +28,6 @@ import { SessionID, MessageID, PartID } from "./schema"
2828
import type { Provider } from "@/provider/provider"
2929
import { Permission } from "@/permission"
3030
import { Global } from "@/global"
31-
import type { LanguageModelV2Usage } from "@ai-sdk/provider"
3231
import { Effect, Layer, Option, Context } from "effect"
3332
import { makeRuntime } from "@/effect/run-service"
3433

@@ -240,7 +239,7 @@ export namespace Session {
240239

241240
export const getUsage = (input: {
242241
model: Provider.Model
243-
usage: LanguageModelV2Usage
242+
usage: LanguageModelUsage
244243
metadata?: ProviderMetadata
245244
}) => {
246245
const safe = (value: number) => {
@@ -249,11 +248,14 @@ export namespace Session {
249248
}
250249
const inputTokens = safe(input.usage.inputTokens ?? 0)
251250
const outputTokens = safe(input.usage.outputTokens ?? 0)
252-
const reasoningTokens = safe(input.usage.reasoningTokens ?? 0)
251+
const reasoningTokens = safe(input.usage.outputTokenDetails?.reasoningTokens ?? input.usage.reasoningTokens ?? 0)
253252

254-
const cacheReadInputTokens = safe(input.usage.cachedInputTokens ?? 0)
253+
const cacheReadInputTokens = safe(
254+
input.usage.inputTokenDetails?.cacheReadTokens ?? input.usage.cachedInputTokens ?? 0,
255+
)
255256
const cacheWriteInputTokens = safe(
256-
(input.metadata?.["anthropic"]?.["cacheCreationInputTokens"] ??
257+
(input.usage.inputTokenDetails?.cacheWriteTokens ??
258+
input.metadata?.["anthropic"]?.["cacheCreationInputTokens"] ??
257259
// google-vertex-anthropic returns metadata under "vertex" key
258260
// (AnthropicMessagesLanguageModel custom provider key from 'vertex.anthropic.messages')
259261
input.metadata?.["vertex"]?.["cacheCreationInputTokens"] ??
@@ -274,7 +276,7 @@ export namespace Session {
274276
const tokens = {
275277
total,
276278
input: adjustedInputTokens,
277-
output: outputTokens - reasoningTokens,
279+
output: safe(outputTokens - reasoningTokens),
278280
reasoning: reasoningTokens,
279281
cache: {
280282
write: cacheWriteInputTokens,

packages/opencode/test/session/compaction.test.ts

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,15 @@ describe("session.getUsage", () => {
10051005
inputTokens: 1000,
10061006
outputTokens: 500,
10071007
totalTokens: 1500,
1008+
inputTokenDetails: {
1009+
noCacheTokens: undefined,
1010+
cacheReadTokens: undefined,
1011+
cacheWriteTokens: undefined,
1012+
},
1013+
outputTokenDetails: {
1014+
textTokens: undefined,
1015+
reasoningTokens: undefined,
1016+
},
10081017
},
10091018
})
10101019

@@ -1023,7 +1032,15 @@ describe("session.getUsage", () => {
10231032
inputTokens: 1000,
10241033
outputTokens: 500,
10251034
totalTokens: 1500,
1026-
cachedInputTokens: 200,
1035+
inputTokenDetails: {
1036+
noCacheTokens: 800,
1037+
cacheReadTokens: 200,
1038+
cacheWriteTokens: undefined,
1039+
},
1040+
outputTokenDetails: {
1041+
textTokens: undefined,
1042+
reasoningTokens: undefined,
1043+
},
10271044
},
10281045
})
10291046

@@ -1039,6 +1056,15 @@ describe("session.getUsage", () => {
10391056
inputTokens: 1000,
10401057
outputTokens: 500,
10411058
totalTokens: 1500,
1059+
inputTokenDetails: {
1060+
noCacheTokens: undefined,
1061+
cacheReadTokens: undefined,
1062+
cacheWriteTokens: undefined,
1063+
},
1064+
outputTokenDetails: {
1065+
textTokens: undefined,
1066+
reasoningTokens: undefined,
1067+
},
10421068
},
10431069
metadata: {
10441070
anthropic: {
@@ -1059,7 +1085,15 @@ describe("session.getUsage", () => {
10591085
inputTokens: 1000,
10601086
outputTokens: 500,
10611087
totalTokens: 1500,
1062-
cachedInputTokens: 200,
1088+
inputTokenDetails: {
1089+
noCacheTokens: 800,
1090+
cacheReadTokens: 200,
1091+
cacheWriteTokens: undefined,
1092+
},
1093+
outputTokenDetails: {
1094+
textTokens: undefined,
1095+
reasoningTokens: undefined,
1096+
},
10631097
},
10641098
metadata: {
10651099
anthropic: {},
@@ -1078,7 +1112,15 @@ describe("session.getUsage", () => {
10781112
inputTokens: 1000,
10791113
outputTokens: 500,
10801114
totalTokens: 1500,
1081-
reasoningTokens: 100,
1115+
inputTokenDetails: {
1116+
noCacheTokens: undefined,
1117+
cacheReadTokens: undefined,
1118+
cacheWriteTokens: undefined,
1119+
},
1120+
outputTokenDetails: {
1121+
textTokens: 400,
1122+
reasoningTokens: 100,
1123+
},
10821124
},
10831125
})
10841126

@@ -1104,7 +1146,15 @@ describe("session.getUsage", () => {
11041146
inputTokens: 0,
11051147
outputTokens: 1_000_000,
11061148
totalTokens: 1_000_000,
1107-
reasoningTokens: 250_000,
1149+
inputTokenDetails: {
1150+
noCacheTokens: undefined,
1151+
cacheReadTokens: undefined,
1152+
cacheWriteTokens: undefined,
1153+
},
1154+
outputTokenDetails: {
1155+
textTokens: 750_000,
1156+
reasoningTokens: 250_000,
1157+
},
11081158
},
11091159
})
11101160

@@ -1121,6 +1171,15 @@ describe("session.getUsage", () => {
11211171
inputTokens: 0,
11221172
outputTokens: 0,
11231173
totalTokens: 0,
1174+
inputTokenDetails: {
1175+
noCacheTokens: undefined,
1176+
cacheReadTokens: undefined,
1177+
cacheWriteTokens: undefined,
1178+
},
1179+
outputTokenDetails: {
1180+
textTokens: undefined,
1181+
reasoningTokens: undefined,
1182+
},
11241183
},
11251184
})
11261185

@@ -1148,6 +1207,15 @@ describe("session.getUsage", () => {
11481207
inputTokens: 1_000_000,
11491208
outputTokens: 100_000,
11501209
totalTokens: 1_100_000,
1210+
inputTokenDetails: {
1211+
noCacheTokens: undefined,
1212+
cacheReadTokens: undefined,
1213+
cacheWriteTokens: undefined,
1214+
},
1215+
outputTokenDetails: {
1216+
textTokens: undefined,
1217+
reasoningTokens: undefined,
1218+
},
11511219
},
11521220
})
11531221

@@ -1163,7 +1231,15 @@ describe("session.getUsage", () => {
11631231
inputTokens: 1000,
11641232
outputTokens: 500,
11651233
totalTokens: 1500,
1166-
cachedInputTokens: 200,
1234+
inputTokenDetails: {
1235+
noCacheTokens: 800,
1236+
cacheReadTokens: 200,
1237+
cacheWriteTokens: undefined,
1238+
},
1239+
outputTokenDetails: {
1240+
textTokens: undefined,
1241+
reasoningTokens: undefined,
1242+
},
11671243
}
11681244
if (npm === "@ai-sdk/amazon-bedrock") {
11691245
const result = Session.getUsage({
@@ -1214,7 +1290,15 @@ describe("session.getUsage", () => {
12141290
inputTokens: 1000,
12151291
outputTokens: 500,
12161292
totalTokens: 1500,
1217-
cachedInputTokens: 200,
1293+
inputTokenDetails: {
1294+
noCacheTokens: 800,
1295+
cacheReadTokens: 200,
1296+
cacheWriteTokens: undefined,
1297+
},
1298+
outputTokenDetails: {
1299+
textTokens: undefined,
1300+
reasoningTokens: undefined,
1301+
},
12181302
},
12191303
metadata: {
12201304
vertex: {

0 commit comments

Comments
 (0)