mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-25 08:02:15 +00:00
feat(plugin): allow tool hooks to fail with tool errors (#41668)
This commit is contained in:
parent
c401076b6f
commit
47c8d85904
4 changed files with 78 additions and 10 deletions
|
|
@ -4,9 +4,11 @@ export interface Registration {
|
|||
readonly dispose: Effect.Effect<void>
|
||||
}
|
||||
|
||||
export type Hooks<Spec> = <Name extends keyof Spec>(
|
||||
export type Hooks<Spec, Failures extends Record<keyof Spec, unknown> = Record<keyof Spec, never>> = <
|
||||
Name extends keyof Spec,
|
||||
>(
|
||||
name: Name,
|
||||
callback: (input: Spec[Name]) => Effect.Effect<void>,
|
||||
callback: (input: Spec[Name]) => Effect.Effect<void, Failures[Name]>,
|
||||
) => Effect.Effect<Registration, never, Scope.Scope>
|
||||
|
||||
export type Transform<Input> = (callback: (input: Input) => void) => Effect.Effect<Registration, never, Scope.Scope>
|
||||
|
|
|
|||
|
|
@ -38,7 +38,13 @@ export interface ToolHooks {
|
|||
)
|
||||
}
|
||||
|
||||
// Only execute.before may fail: a Tool.Error rejects the call before the tool runs.
|
||||
export interface ToolFailures extends Record<keyof ToolHooks, unknown> {
|
||||
readonly "execute.before": Tool.Error
|
||||
readonly "execute.after": never
|
||||
}
|
||||
|
||||
export interface ToolDomain {
|
||||
readonly transform: Transform<ToolDraft>
|
||||
readonly hook: Hooks<ToolHooks>
|
||||
readonly hook: Hooks<ToolHooks, ToolFailures>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue