feat(plugin): expose app metadata (#38179)
This commit is contained in:
parent
2ed8fe5960
commit
8de40be6ea
71 changed files with 477 additions and 286 deletions
33
packages/core/src/app.ts
Normal file
33
packages/core/src/app.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
export * as App from "./app"
|
||||
|
||||
import { Context, Layer } from "effect"
|
||||
import { makeGlobalNode } from "@opencode-ai/util/effect/app-node"
|
||||
|
||||
export interface Info {
|
||||
readonly name: string
|
||||
readonly version: string
|
||||
readonly channel: string
|
||||
}
|
||||
|
||||
export const Metadata = Context.Reference<Info>("@opencode/App", {
|
||||
defaultValue: () => make(),
|
||||
})
|
||||
|
||||
export function make(input: Partial<Info> = {}): Info {
|
||||
return {
|
||||
name: input.name ?? "opencode",
|
||||
version: input.version ?? "unknown",
|
||||
channel: input.channel ?? "unknown",
|
||||
}
|
||||
}
|
||||
|
||||
export function useragent(app: Info) {
|
||||
return `opencode/${app.channel}/${app.version}/${app.name}`
|
||||
}
|
||||
|
||||
export const layer = (input?: Partial<Info>) => Layer.succeed(Metadata, make(input))
|
||||
|
||||
export const configured = (input?: Partial<Info>) =>
|
||||
makeGlobalNode({ service: Metadata, layer: layer(input), deps: [] })
|
||||
|
||||
export const node = configured()
|
||||
Loading…
Add table
Add a link
Reference in a new issue