(
address: ToolAddress,
args: unknown,
options?: InvokeOptions,
)
| 3619 | }); |
| 3620 | |
| 3621 | const execute = ( |
| 3622 | address: ToolAddress, |
| 3623 | args: unknown, |
| 3624 | options?: InvokeOptions, |
| 3625 | ): Effect.Effect<unknown, ExecuteError> => { |
| 3626 | const handler = pickHandler(options); |
| 3627 | return Effect.gen(function* () { |
| 3628 | // oxlint-disable executor/no-instanceof-error, executor/no-unknown-error-message, executor/no-manual-tag-check -- boundary: normalize arbitrary unknown plugin failures into a human-readable message for ToolInvocationError/telemetry |
| 3629 | const formatInvocationCauseMessage = (cause: unknown): string => { |
| 3630 | if (cause instanceof Error && cause.message.length > 0) return cause.message; |
| 3631 | // Non-Error / empty-message causes: `String(plainObject)` renders |
| 3632 | // "[object Object]", which is what telemetry then shows as the only |
| 3633 | // label for the failure. Prefer the tag, else stringify structurally. |
| 3634 | if (typeof cause === "object" && cause !== null) { |
| 3635 | const tag = (cause as { readonly _tag?: unknown })._tag; |
| 3636 | if (typeof tag === "string") return tag; |
| 3637 | return Inspectable.toStringUnknown(cause, 0); |
| 3638 | } |
| 3639 | return String(cause); |
| 3640 | }; |
| 3641 | // oxlint-enable executor/no-instanceof-error, executor/no-unknown-error-message, executor/no-manual-tag-check |
| 3642 | const wrapInvocationError = <A, E>( |
| 3643 | effect: Effect.Effect<A, E>, |
| 3644 | ): Effect.Effect<A, ToolInvocationError> => |
| 3645 | effect.pipe( |
| 3646 | Effect.mapError( |
| 3647 | (cause) => |
| 3648 | new ToolInvocationError({ |
| 3649 | address, |
| 3650 | message: formatInvocationCauseMessage(cause), |
| 3651 | cause, |
| 3652 | }), |
| 3653 | ), |
| 3654 | ); |
| 3655 | |
| 3656 | // Static path — O(1) map lookup for plugin-contributed static tools |
| 3657 | // (core-tools, plugin executor namespaces). Addressed by their fqid, |
| 3658 | // not the 5-segment dynamic form. |
| 3659 | const staticEntry = staticTools.get(String(address)); |
| 3660 | if (staticEntry) { |
| 3661 | const policyRules = yield* listActivePolicyRuleSet(); |
| 3662 | const policy = yield* resolvePolicyFromRuleSet( |
| 3663 | String(address), |
| 3664 | policyRules, |
| 3665 | staticEntry.tool.annotations?.requiresApproval, |
| 3666 | ); |
| 3667 | if (policy.action === "block") { |
| 3668 | return yield* new ToolBlockedError({ |
| 3669 | address, |
| 3670 | pattern: policy.pattern ?? "*", |
| 3671 | }); |
| 3672 | } |
| 3673 | yield* enforceApproval(staticEntry.tool.annotations, address, args, policy, handler); |
| 3674 | return yield* wrapInvocationError( |
| 3675 | staticEntry.tool.handler({ |
| 3676 | ctx: staticEntry.ctx, |
| 3677 | args, |
| 3678 | elicit: buildElicit(address, args, handler), |
no test coverage detected