Skip to content

Commit d4dc142

Browse files
committed
core: add client identification to user agent and request headers for better tracking
1 parent bfdb236 commit d4dc142

4 files changed

Lines changed: 5 additions & 1 deletion

File tree

packages/opencode/src/flag/flag.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export namespace Flag {
1111
export const OPENCODE_ENABLE_EXPERIMENTAL_MODELS = truthy("OPENCODE_ENABLE_EXPERIMENTAL_MODELS")
1212
export const OPENCODE_DISABLE_AUTOCOMPACT = truthy("OPENCODE_DISABLE_AUTOCOMPACT")
1313
export const OPENCODE_FAKE_VCS = process.env["OPENCODE_FAKE_VCS"]
14+
export const OPENCODE_CLIENT = process.env["OPENCODE_CLIENT"] ?? "cli"
1415

1516
// Experimental
1617
export const OPENCODE_EXPERIMENTAL = truthy("OPENCODE_EXPERIMENTAL")

packages/opencode/src/installation/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import z from "zod"
66
import { NamedError } from "@opencode-ai/util/error"
77
import { Log } from "../util/log"
88
import { iife } from "@/util/iife"
9+
import { Flag } from "../flag/flag"
910

1011
declare global {
1112
const OPENCODE_VERSION: string
@@ -162,7 +163,7 @@ export namespace Installation {
162163

163164
export const VERSION = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "local"
164165
export const CHANNEL = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local"
165-
export const USER_AGENT = `opencode/${CHANNEL}/${VERSION}`
166+
export const USER_AGENT = `opencode/${CHANNEL}/${VERSION}/${Flag.OPENCODE_CLIENT}`
166167

167168
export async function latest(installMethod?: Method) {
168169
const detectedMethod = installMethod || (await method())

packages/opencode/src/session/prompt.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ export namespace SessionPrompt {
590590
"x-opencode-project": Instance.project.id,
591591
"x-opencode-session": sessionID,
592592
"x-opencode-request": lastUser.id,
593+
"x-opencode-client": Flag.OPENCODE_CLIENT,
593594
}
594595
: undefined),
595596
...model.headers,

packages/tauri/src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ fn spawn_sidecar(app: &AppHandle, port: u16) -> CommandChild {
6767
.sidecar("opencode")
6868
.unwrap()
6969
.env("OPENCODE_EXPERIMENTAL_ICON_DISCOVERY", "true")
70+
.env("OPENCODE_CLIENT", "desktop")
7071
.args(["serve", &format!("--port={port}")])
7172
.spawn()
7273
.expect("Failed to spawn opencode");

0 commit comments

Comments
 (0)