mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-02 23:23:45 +00:00
feat(core): add WorkspaceContext (#15409)
This commit is contained in:
23
packages/opencode/src/control-plane/workspace-context.ts
Normal file
23
packages/opencode/src/control-plane/workspace-context.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Context } from "../util/context"
|
||||
|
||||
interface Context {
|
||||
workspaceID?: string
|
||||
}
|
||||
|
||||
const context = Context.create<Context>("workspace")
|
||||
|
||||
export const WorkspaceContext = {
|
||||
async provide<R>(input: { workspaceID?: string; fn: () => R }): Promise<R> {
|
||||
return context.provide({ workspaceID: input.workspaceID }, async () => {
|
||||
return input.fn()
|
||||
})
|
||||
},
|
||||
|
||||
get workspaceID() {
|
||||
try {
|
||||
return context.use().workspaceID
|
||||
} catch (e) {
|
||||
return undefined
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user