Skip to content

Commit f884766

Browse files
thdxractions-userll931217neominikjayair
authored
v2 message format and upgrade to ai sdk v5 (anomalyco#743)
Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Liang-Shih Lin <liangshihlin@proton.me> Co-authored-by: Dominik Engelhardt <dominikengelhardt@ymail.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: adamdottv <2363879+adamdottv@users.noreply.github.com>
1 parent 76b2e45 commit f884766

File tree

116 files changed

+4520
-6763
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+4520
-6763
lines changed

.github/workflows/stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ jobs:
2828
git config --local user.email "action@github.com"
2929
git config --local user.name "GitHub Action"
3030
git add STATS.md
31-
git diff --staged --quiet || git commit -m "Update download stats $(date -I)"
31+
git diff --staged --quiet || git commit -m "ignore: update download stats $(date -I)"
3232
git push

bun.lock

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

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"catalog": {
1818
"typescript": "5.8.2",
1919
"@types/node": "22.13.9",
20-
"zod": "3.24.2",
21-
"ai": "4.3.16"
20+
"zod": "3.25.49",
21+
"ai": "5.0.0-beta.7"
2222
}
2323
},
2424
"devDependencies": {
@@ -31,10 +31,8 @@
3131
},
3232
"license": "MIT",
3333
"prettier": {
34-
"semi": false
35-
},
36-
"overrides": {
37-
"zod": "3.24.2"
34+
"semi": false,
35+
"printWidth": 120
3836
},
3937
"trustedDependencies": [
4038
"esbuild",

packages/function/src/api.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ export class SyncServer extends DurableObject<Env> {
3838

3939
async publish(key: string, content: any) {
4040
const sessionID = await this.getSessionID()
41-
if (
42-
!key.startsWith(`session/info/${sessionID}`) &&
43-
!key.startsWith(`session/message/${sessionID}/`)
44-
)
41+
if (!key.startsWith(`session/info/${sessionID}`) && !key.startsWith(`session/message/${sessionID}/`))
4542
return new Response("Error: Invalid key", { status: 400 })
4643

4744
// store message
@@ -184,17 +181,15 @@ export default {
184181
}
185182
const id = url.searchParams.get("id")
186183
console.log("share_poll", id)
187-
if (!id)
188-
return new Response("Error: Share ID is required", { status: 400 })
184+
if (!id) return new Response("Error: Share ID is required", { status: 400 })
189185
const stub = env.SYNC_SERVER.get(env.SYNC_SERVER.idFromName(id))
190186
return stub.fetch(request)
191187
}
192188

193189
if (request.method === "GET" && method === "share_data") {
194190
const id = url.searchParams.get("id")
195191
console.log("share_data", id)
196-
if (!id)
197-
return new Response("Error: Share ID is required", { status: 400 })
192+
if (!id) return new Response("Error: Share ID is required", { status: 400 })
198193
const stub = env.SYNC_SERVER.get(env.SYNC_SERVER.idFromName(id))
199194
const data = await stub.getData()
200195

packages/opencode/script/publish.ts

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ for (const [os, arch] of targets) {
5757
2,
5858
),
5959
)
60-
if (!dry)
61-
await $`cd dist/${name} && bun publish --access public --tag ${npmTag}`
60+
if (!dry) await $`cd dist/${name} && bun publish --access public --tag ${npmTag}`
6261
optionalDependencies[name] = version
6362
}
6463

@@ -82,24 +81,19 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
8281
2,
8382
),
8483
)
85-
if (!dry)
86-
await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${npmTag}`
84+
if (!dry) await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${npmTag}`
8785

8886
if (!snapshot) {
8987
// Github Release
9088
for (const key of Object.keys(optionalDependencies)) {
9189
await $`cd dist/${key}/bin && zip -r ../../${key}.zip *`
9290
}
9391

94-
const previous = await fetch(
95-
"https://api.github.com/repos/sst/opencode/releases/latest",
96-
)
92+
const previous = await fetch("https://api.github.com/repos/sst/opencode/releases/latest")
9793
.then((res) => res.json())
9894
.then((data) => data.tag_name)
9995

100-
const commits = await fetch(
101-
`https://api.github.com/repos/sst/opencode/compare/${previous}...HEAD`,
102-
)
96+
const commits = await fetch(`https://api.github.com/repos/sst/opencode/compare/${previous}...HEAD`)
10397
.then((res) => res.json())
10498
.then((data) => data.commits || [])
10599

@@ -117,26 +111,13 @@ if (!snapshot) {
117111
})
118112
.join("\n")
119113

120-
if (!dry)
121-
await $`gh release create v${version} --title "v${version}" --notes ${notes} ./dist/*.zip`
114+
if (!dry) await $`gh release create v${version} --title "v${version}" --notes ${notes} ./dist/*.zip`
122115

123116
// Calculate SHA values
124-
const arm64Sha =
125-
await $`sha256sum ./dist/opencode-linux-arm64.zip | cut -d' ' -f1`
126-
.text()
127-
.then((x) => x.trim())
128-
const x64Sha =
129-
await $`sha256sum ./dist/opencode-linux-x64.zip | cut -d' ' -f1`
130-
.text()
131-
.then((x) => x.trim())
132-
const macX64Sha =
133-
await $`sha256sum ./dist/opencode-darwin-x64.zip | cut -d' ' -f1`
134-
.text()
135-
.then((x) => x.trim())
136-
const macArm64Sha =
137-
await $`sha256sum ./dist/opencode-darwin-arm64.zip | cut -d' ' -f1`
138-
.text()
139-
.then((x) => x.trim())
117+
const arm64Sha = await $`sha256sum ./dist/opencode-linux-arm64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
118+
const x64Sha = await $`sha256sum ./dist/opencode-linux-x64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
119+
const macX64Sha = await $`sha256sum ./dist/opencode-darwin-x64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
120+
const macArm64Sha = await $`sha256sum ./dist/opencode-darwin-arm64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
140121

141122
// AUR package
142123
const pkgbuild = [
@@ -170,9 +151,7 @@ if (!snapshot) {
170151
for (const pkg of ["opencode", "opencode-bin"]) {
171152
await $`rm -rf ./dist/aur-${pkg}`
172153
await $`git clone ssh://aur@aur.archlinux.org/${pkg}.git ./dist/aur-${pkg}`
173-
await Bun.file(`./dist/aur-${pkg}/PKGBUILD`).write(
174-
pkgbuild.replace("${pkg}", pkg),
175-
)
154+
await Bun.file(`./dist/aur-${pkg}/PKGBUILD`).write(pkgbuild.replace("${pkg}", pkg))
176155
await $`cd ./dist/aur-${pkg} && makepkg --printsrcinfo > .SRCINFO`
177156
await $`cd ./dist/aur-${pkg} && git add PKGBUILD .SRCINFO`
178157
await $`cd ./dist/aur-${pkg} && git commit -m "Update to v${version}"`

packages/opencode/src/app/app.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,14 @@ export namespace App {
4545
}
4646

4747
export const provideExisting = ctx.provide
48-
export async function provide<T>(
49-
input: Input,
50-
cb: (app: App.Info) => Promise<T>,
51-
) {
48+
export async function provide<T>(input: Input, cb: (app: App.Info) => Promise<T>) {
5249
log.info("creating", {
5350
cwd: input.cwd,
5451
})
55-
const git = await Filesystem.findUp(".git", input.cwd).then(([x]) =>
56-
x ? path.dirname(x) : undefined,
57-
)
52+
const git = await Filesystem.findUp(".git", input.cwd).then(([x]) => (x ? path.dirname(x) : undefined))
5853
log.info("git", { git })
5954

60-
const data = path.join(
61-
Global.Path.data,
62-
"project",
63-
git ? directory(git) : "global",
64-
)
55+
const data = path.join(Global.Path.data, "project", git ? directory(git) : "global")
6556
const stateFile = Bun.file(path.join(data, APP_JSON))
6657
const state = (await stateFile.json().catch(() => ({}))) as {
6758
initialized: number

packages/opencode/src/auth/anthropic.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,8 @@ export namespace AuthAnthropic {
1010
url.searchParams.set("code", "true")
1111
url.searchParams.set("client_id", CLIENT_ID)
1212
url.searchParams.set("response_type", "code")
13-
url.searchParams.set(
14-
"redirect_uri",
15-
"https://console.anthropic.com/oauth/code/callback",
16-
)
17-
url.searchParams.set(
18-
"scope",
19-
"org:create_api_key user:profile user:inference",
20-
)
13+
url.searchParams.set("redirect_uri", "https://console.anthropic.com/oauth/code/callback")
14+
url.searchParams.set("scope", "org:create_api_key user:profile user:inference")
2115
url.searchParams.set("code_challenge", pkce.challenge)
2216
url.searchParams.set("code_challenge_method", "S256")
2317
url.searchParams.set("state", pkce.verifier)
@@ -57,20 +51,17 @@ export namespace AuthAnthropic {
5751
const info = await Auth.get("anthropic")
5852
if (!info || info.type !== "oauth") return
5953
if (info.access && info.expires > Date.now()) return info.access
60-
const response = await fetch(
61-
"https://console.anthropic.com/v1/oauth/token",
62-
{
63-
method: "POST",
64-
headers: {
65-
"Content-Type": "application/json",
66-
},
67-
body: JSON.stringify({
68-
grant_type: "refresh_token",
69-
refresh_token: info.refresh,
70-
client_id: CLIENT_ID,
71-
}),
54+
const response = await fetch("https://console.anthropic.com/v1/oauth/token", {
55+
method: "POST",
56+
headers: {
57+
"Content-Type": "application/json",
7258
},
73-
)
59+
body: JSON.stringify({
60+
grant_type: "refresh_token",
61+
refresh_token: info.refresh,
62+
client_id: CLIENT_ID,
63+
}),
64+
})
7465
if (!response.ok) return
7566
const json = await response.json()
7667
await Auth.set("anthropic", {

packages/opencode/src/auth/copilot.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import path from "path"
44

55
export const AuthCopilot = lazy(async () => {
66
const file = Bun.file(path.join(Global.Path.state, "plugin", "copilot.ts"))
7-
const response = fetch(
8-
"https://raw.githubusercontent.com/sst/opencode-github-copilot/refs/heads/main/auth.ts",
9-
)
7+
const response = fetch("https://raw.githubusercontent.com/sst/opencode-github-copilot/refs/heads/main/auth.ts")
108
.then((x) => Bun.write(file, x))
119
.catch(() => {})
1210

packages/opencode/src/auth/github-copilot.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ export namespace AuthGithubCopilot {
122122
return tokenData.token
123123
}
124124

125-
export const DeviceCodeError = NamedError.create(
126-
"DeviceCodeError",
127-
z.object({}),
128-
)
125+
export const DeviceCodeError = NamedError.create("DeviceCodeError", z.object({}))
129126

130127
export const TokenExchangeError = NamedError.create(
131128
"TokenExchangeError",

packages/opencode/src/bun/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import { readableStreamToText } from "bun"
88
export namespace BunProc {
99
const log = Log.create({ service: "bun" })
1010

11-
export async function run(
12-
cmd: string[],
13-
options?: Bun.SpawnOptions.OptionsObject<any, any, any>,
14-
) {
11+
export async function run(cmd: string[], options?: Bun.SpawnOptions.OptionsObject<any, any, any>) {
1512
log.info("running", {
1613
cmd: [which(), ...cmd],
1714
...options,
@@ -26,9 +23,17 @@ export namespace BunProc {
2623
BUN_BE_BUN: "1",
2724
},
2825
})
29-
const code = await result.exited;
30-
const stdout = result.stdout ? typeof result.stdout === "number" ? result.stdout : await readableStreamToText(result.stdout) : undefined
31-
const stderr = result.stderr ? typeof result.stderr === "number" ? result.stderr : await readableStreamToText(result.stderr) : undefined
26+
const code = await result.exited
27+
const stdout = result.stdout
28+
? typeof result.stdout === "number"
29+
? result.stdout
30+
: await readableStreamToText(result.stdout)
31+
: undefined
32+
const stderr = result.stderr
33+
? typeof result.stderr === "number"
34+
? result.stderr
35+
: await readableStreamToText(result.stderr)
36+
: undefined
3237
log.info("done", {
3338
code,
3439
stdout,
@@ -61,7 +66,7 @@ export namespace BunProc {
6166
if (parsed.dependencies[pkg] === version) return mod
6267
parsed.dependencies[pkg] = version
6368
await Bun.write(pkgjson, JSON.stringify(parsed, null, 2))
64-
await BunProc.run(["install", "--registry=https://registry.npmjs.org"], {
69+
await BunProc.run(["install", "--cwd", Global.Path.cache, "--registry=https://registry.npmjs.org"], {
6570
cwd: Global.Path.cache,
6671
}).catch((e) => {
6772
throw new InstallFailedError(

0 commit comments

Comments
 (0)