mirror of
https://github.com/anomalyco/opencode.git
synced 2026-02-01 22:48:16 +00:00
feat(plugin): expose server URL to plugins (#6373)
This commit is contained in:
committed by
GitHub
parent
1d589c7ac7
commit
4657fa823f
@@ -24,6 +24,7 @@ export namespace Plugin {
|
||||
project: Instance.project,
|
||||
worktree: Instance.worktree,
|
||||
directory: Instance.directory,
|
||||
serverUrl: Server.url(),
|
||||
$: Bun.$,
|
||||
}
|
||||
const plugins = [...(config.plugin ?? [])]
|
||||
|
||||
@@ -57,6 +57,12 @@ globalThis.AI_SDK_LOG_WARNINGS = false
|
||||
export namespace Server {
|
||||
const log = Log.create({ service: "server" })
|
||||
|
||||
let _url: URL | undefined
|
||||
|
||||
export function url(): URL {
|
||||
return _url ?? new URL("http://localhost:4096")
|
||||
}
|
||||
|
||||
export const Event = {
|
||||
Connected: BusEvent.define("server.connected", z.object({})),
|
||||
Disposed: BusEvent.define("global.disposed", z.object({})),
|
||||
@@ -2666,6 +2672,8 @@ export namespace Server {
|
||||
const server = opts.port === 0 ? (tryServe(4096) ?? tryServe(0)) : tryServe(opts.port)
|
||||
if (!server) throw new Error(`Failed to start server on port ${opts.port}`)
|
||||
|
||||
_url = server.url
|
||||
|
||||
const shouldPublishMDNS =
|
||||
opts.mdns &&
|
||||
server.port &&
|
||||
|
||||
@@ -28,6 +28,7 @@ export type PluginInput = {
|
||||
project: Project
|
||||
directory: string
|
||||
worktree: string
|
||||
serverUrl: URL
|
||||
$: BunShell
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user