tool-error.ts 518 B

1234567891011
  1. import { Schema } from "effect"
  2. /** Safe operational refusal from a standard tool pack, reported as `ToolFailure`. */
  3. export class ToolError extends Schema.TaggedErrorClass<ToolError>()("ToolError", {
  4. message: Schema.String,
  5. cause: Schema.optionalKey(Schema.Defect()),
  6. }) {}
  7. /** Creates a tool refusal whose message is safe to include in an execution diagnostic. */
  8. export const toolError = (message: string, cause?: unknown): ToolError =>
  9. new ToolError({ message, ...(cause === undefined ? {} : { cause }) })