(
address: ToolAddress,
args: unknown,
options?: InvokeOptions,
)
| 3718 | }); |
| 3719 | |
| 3720 | const execute = ( |
| 3721 | address: ToolAddress, |
| 3722 | args: unknown, |
| 3723 | options?: InvokeOptions, |
| 3724 | ): Effect.Effect<unknown, ExecuteError> => { |
| 3725 | const handler = pickHandler(options); |
| 3726 | return Effect.gen(function* () { |
| 3727 | // 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 |
| 3728 | const formatInvocationCauseMessage = (cause: unknown): string => { |
| 3729 | if (cause instanceof Error && cause.message.length > 0) return cause.message; |
| 3730 | // Non-Error / empty-message causes: `String(plainObject)` renders |
| 3731 | // "[object Object]", which is what telemetry then shows as the only |
| 3732 | // label for the failure. Prefer the tag, else stringify structurally. |
| 3733 | if (typeof cause === "object" && cause !== null) { |
| 3734 | const tag = (cause as { readonly _tag?: unknown })._tag; |
| 3735 | if (typeof tag === "string") return tag; |
| 3736 | return Inspectable.toStringUnknown(cause, 0); |
| 3737 | } |
| 3738 | return String(cause); |
| 3739 | }; |
| 3740 | // oxlint-enable executor/no-instanceof-error, executor/no-unknown-error-message, executor/no-manual-tag-check |
| 3741 | const wrapInvocationError = <A, E>( |
| 3742 | effect: Effect.Effect<A, E>, |
| 3743 | ): Effect.Effect<A, ToolInvocationError> => |
| 3744 | effect.pipe( |
| 3745 | Effect.mapError( |
| 3746 | (cause) => |
| 3747 | new ToolInvocationError({ |
| 3748 | address, |
| 3749 | message: formatInvocationCauseMessage(cause), |
| 3750 | cause, |
| 3751 | }), |
| 3752 | ), |
| 3753 | ); |
| 3754 | |
| 3755 | // Static path — O(1) map lookup for plugin-contributed static tools |
| 3756 | // (core-tools, plugin executor namespaces). Addressed by their fqid, |
| 3757 | // not the 5-segment dynamic form. |
| 3758 | const staticEntry = staticTools.get(String(address)); |
| 3759 | if (staticEntry) { |
| 3760 | const policyRules = yield* listActivePolicyRuleSet(); |
| 3761 | const policy = yield* resolvePolicyFromRuleSet( |
| 3762 | String(address), |
| 3763 | policyRules, |
| 3764 | staticEntry.tool.annotations?.requiresApproval, |
| 3765 | ); |
| 3766 | if (policy.action === "block") { |
| 3767 | return yield* new ToolBlockedError({ |
| 3768 | address, |
| 3769 | pattern: policy.pattern ?? "*", |
| 3770 | }); |
| 3771 | } |
| 3772 | yield* enforceApproval(staticEntry.tool.annotations, address, args, policy, handler); |
| 3773 | return yield* wrapInvocationError( |
| 3774 | staticEntry.tool.handler({ |
| 3775 | ctx: staticEntry.ctx, |
| 3776 | args, |
| 3777 | elicit: buildElicit(address, args, handler), |
no test coverage detected