fix: resolve state variable shadowing in command, plugin, and tool/registry
The cache→state rename caused inner InstanceState.get() results to shadow the outer state handle, breaking type inference. Rename inner bindings to `s` to match the convention used in the other files.
This commit is contained in:
@@ -164,13 +164,13 @@ export namespace Command {
|
||||
const state = yield* InstanceState.make<State>((ctx) => init(ctx))
|
||||
|
||||
const get = Effect.fn("Command.get")(function* (name: string) {
|
||||
const state = yield* InstanceState.get(state)
|
||||
return state.commands[name]
|
||||
const s = yield* InstanceState.get(state)
|
||||
return s.commands[name]
|
||||
})
|
||||
|
||||
const list = Effect.fn("Command.list")(function* () {
|
||||
const state = yield* InstanceState.get(state)
|
||||
return Object.values(state.commands)
|
||||
const s = yield* InstanceState.get(state)
|
||||
return Object.values(s.commands)
|
||||
})
|
||||
|
||||
return Service.of({ get, list })
|
||||
|
||||
@@ -279,8 +279,8 @@ export namespace Plugin {
|
||||
Output = Parameters<Required<Hooks>[Name]>[1],
|
||||
>(name: Name, input: Input, output: Output) {
|
||||
if (!name) return output
|
||||
const state = yield* InstanceState.get(state)
|
||||
for (const hook of state.hooks) {
|
||||
const s = yield* InstanceState.get(state)
|
||||
for (const hook of s.hooks) {
|
||||
const fn = hook[name] as any
|
||||
if (!fn) continue
|
||||
yield* Effect.promise(async () => fn(input, output))
|
||||
@@ -289,8 +289,8 @@ export namespace Plugin {
|
||||
})
|
||||
|
||||
const list = Effect.fn("Plugin.list")(function* () {
|
||||
const state = yield* InstanceState.get(state)
|
||||
return state.hooks
|
||||
const s = yield* InstanceState.get(state)
|
||||
return s.hooks
|
||||
})
|
||||
|
||||
const init = Effect.fn("Plugin.init")(function* () {
|
||||
|
||||
@@ -139,18 +139,18 @@ export namespace ToolRegistry {
|
||||
})
|
||||
|
||||
const register = Effect.fn("ToolRegistry.register")(function* (tool: Tool.Info) {
|
||||
const state = yield* InstanceState.get(state)
|
||||
const idx = state.custom.findIndex((t) => t.id === tool.id)
|
||||
const s = yield* InstanceState.get(state)
|
||||
const idx = s.custom.findIndex((t) => t.id === tool.id)
|
||||
if (idx >= 0) {
|
||||
state.custom.splice(idx, 1, tool)
|
||||
s.custom.splice(idx, 1, tool)
|
||||
return
|
||||
}
|
||||
state.custom.push(tool)
|
||||
s.custom.push(tool)
|
||||
})
|
||||
|
||||
const ids = Effect.fn("ToolRegistry.ids")(function* () {
|
||||
const state = yield* InstanceState.get(state)
|
||||
const tools = yield* all(state.custom)
|
||||
const s = yield* InstanceState.get(state)
|
||||
const tools = yield* all(s.custom)
|
||||
return tools.map((t) => t.id)
|
||||
})
|
||||
|
||||
@@ -158,8 +158,8 @@ export namespace ToolRegistry {
|
||||
model: { providerID: ProviderID; modelID: ModelID },
|
||||
agent?: Agent.Info,
|
||||
) {
|
||||
const state = yield* InstanceState.get(state)
|
||||
const allTools = yield* all(state.custom)
|
||||
const s = yield* InstanceState.get(state)
|
||||
const allTools = yield* all(s.custom)
|
||||
const filtered = allTools.filter((tool) => {
|
||||
if (tool.id === "codesearch" || tool.id === "websearch") {
|
||||
return model.providerID === ProviderID.opencode || Flag.OPENCODE_ENABLE_EXA
|
||||
|
||||
Reference in New Issue
Block a user