(
address: ToolAddress,
args: unknown,
options?: InvokeOptions,
)
| 4177 | }); |
| 4178 | |
| 4179 | const execute = ( |
| 4180 | address: ToolAddress, |
| 4181 | args: unknown, |
| 4182 | options?: InvokeOptions, |
| 4183 | ): Effect.Effect<unknown, ExecuteError> => { |
| 4184 | const handler = pickHandler(options); |
| 4185 | return Effect.gen(function* () { |
| 4186 | // 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 |
| 4187 | const formatInvocationCauseMessage = (cause: unknown): string => { |
| 4188 | if (cause instanceof Error && cause.message.length > 0) return cause.message; |
| 4189 | // Non-Error / empty-message causes: `String(plainObject)` renders |
| 4190 | // "[object Object]", which is what telemetry then shows as the only |
| 4191 | // label for the failure. Prefer the tag, else stringify structurally. |
| 4192 | if (typeof cause === "object" && cause !== null) { |
| 4193 | const tag = (cause as { readonly _tag?: unknown })._tag; |
| 4194 | if (typeof tag === "string") return tag; |
| 4195 | return Inspectable.toStringUnknown(cause, 0); |
| 4196 | } |
| 4197 | return String(cause); |
| 4198 | }; |
| 4199 | // oxlint-enable executor/no-instanceof-error, executor/no-unknown-error-message, executor/no-manual-tag-check |
| 4200 | const wrapInvocationError = <A, E>( |
| 4201 | effect: Effect.Effect<A, E>, |
| 4202 | ): Effect.Effect<A, ToolInvocationError> => |
| 4203 | effect.pipe( |
| 4204 | Effect.mapError( |
| 4205 | (cause) => |
| 4206 | new ToolInvocationError({ |
| 4207 | address, |
| 4208 | message: formatInvocationCauseMessage(cause), |
| 4209 | cause, |
| 4210 | }), |
| 4211 | ), |
| 4212 | ); |
| 4213 | |
| 4214 | // Static path — O(1) map lookup for plugin-contributed static tools |
| 4215 | // (core-tools, plugin executor namespaces). Addressed by their fqid, |
| 4216 | // not the 5-segment dynamic form. |
| 4217 | const staticEntry = staticTools.get(String(address)); |
| 4218 | if (staticEntry) { |
| 4219 | const policyRules = yield* listActivePolicyRuleSet(); |
| 4220 | const policy = yield* resolvePolicyFromRuleSet( |
| 4221 | String(address), |
| 4222 | policyRules, |
| 4223 | staticEntry.tool.annotations?.requiresApproval, |
| 4224 | ); |
| 4225 | if (policy.action === "block") { |
| 4226 | return yield* new ToolBlockedError({ |
| 4227 | address, |
| 4228 | pattern: policy.pattern ?? "*", |
| 4229 | }); |
| 4230 | } |
| 4231 | yield* enforceApproval(staticEntry.tool.annotations, address, args, policy, handler); |
| 4232 | return yield* wrapInvocationError( |
| 4233 | staticEntry.tool.handler({ |
| 4234 | ctx: staticEntry.ctx, |
| 4235 | args, |
| 4236 | elicit: buildElicit(address, args, handler), |
no test coverage detected