(
code: string,
artifactId: string | undefined,
extra: McpRequestJoinKeys,
)
| 1785 | // invented a five-segment address would only be naming a role the artifact |
| 1786 | // has no binding for, and would be refused. |
| 1787 | const executeCodeFromApp = ( |
| 1788 | code: string, |
| 1789 | artifactId: string | undefined, |
| 1790 | extra: McpRequestJoinKeys, |
| 1791 | ): Effect.Effect<McpToolResult, E> => |
| 1792 | Effect.gen(function* () { |
| 1793 | const resolution = yield* resolveArtifactAction({ code, artifactId, loadArtifact }); |
| 1794 | debugLog("execute_action.call", { |
| 1795 | elicitationMode: elicitationMode.mode, |
| 1796 | elicitationSupport: getElicitationSupport(server), |
| 1797 | codeLength: code.length, |
| 1798 | status: resolution.status, |
| 1799 | artifactId: artifactId ?? null, |
| 1800 | }); |
| 1801 | if (resolution.status === "invalid_action_code") { |
| 1802 | yield* Effect.annotateCurrentSpan({ "mcp.execute_action.rejected": true }); |
| 1803 | return actionRejectedResult(); |
| 1804 | } |
| 1805 | if (resolution.status === "artifact_unavailable") { |
| 1806 | return actionArtifactUnavailableResult(); |
| 1807 | } |
| 1808 | if (resolution.status === "binding_unresolved") { |
| 1809 | yield* Effect.annotateCurrentSpan({ |
| 1810 | "mcp.execute_action.binding_unresolved": true, |
| 1811 | "mcp.execute_action.role": resolution.role, |
| 1812 | }); |
| 1813 | return bindingUnresolvedResult({ |
| 1814 | role: resolution.role, |
| 1815 | integration: resolution.integration, |
| 1816 | message: resolution.message, |
| 1817 | candidates: yield* bindingCandidates(resolution.integration), |
| 1818 | }); |
| 1819 | } |
| 1820 | const boundCode = resolution.code; |
| 1821 | |
| 1822 | if (elicitationMode.mode === "native") { |
| 1823 | return yield* executeWithNativeElicitation(boundCode, extra); |
| 1824 | } |
| 1825 | const outcome = yield* engine.executeWithPause(boundCode); |
| 1826 | debugLog("execute_action.paused_flow_result", { |
| 1827 | status: outcome.status, |
| 1828 | executionId: outcome.status === "paused" ? outcome.execution.id : undefined, |
| 1829 | interactionKind: |
| 1830 | outcome.status === "paused" |
| 1831 | ? pausedInteractionKind(outcome.execution.elicitationContext.request) |
| 1832 | : undefined, |
| 1833 | }); |
| 1834 | if (outcome.status === "paused") { |
| 1835 | return yield* formatPausedModelResult(outcome.execution, "execute_action"); |
| 1836 | } |
| 1837 | return toMcpResult(outcome.result); |
| 1838 | }).pipe( |
| 1839 | Effect.withSpan("mcp.host.tool.execute_action", { |
| 1840 | attributes: { |
| 1841 | "mcp.tool.name": "execute-action", |
| 1842 | "mcp.execute.code_length": code.length, |
| 1843 | }, |
| 1844 | }), |
no test coverage detected