feat(core): add WorkspaceContext (#15409)

This commit is contained in:
James Long
2026-02-28 20:44:54 -05:00
committed by GitHub
parent 114eb42444
commit cec16dfe95
2 changed files with 44 additions and 5 deletions

View 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
}
},
}