MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / ToolRunPanel

Function ToolRunPanel

packages/react/src/components/tool-run-panel.tsx:87–364  ·  view source on GitHub ↗
(props: {
  /** Integration slug — the `<integration>` address segment. */
  readonly integration: IntegrationSlug;
  /** Bare tool name — the `<tool>` address segment (may contain dots). */
  readonly toolName: string;
  /** This integration's connections (accounts) across BOTH owners. Each is
   *  addressed under its OWN owner — there is no ambient owner. */
  readonly connections: readonly Connection[];
  /** Pre-select this connection (the account the selected tool belongs to in the
   *  grouped Tools tab). Falls back to the first connection when null/unmatched. */
  readonly initialConnectionName?: ConnectionName | string | null;
})

Source from the content-addressed store, hash-verified

85};
86
87export function ToolRunPanel(props: {
88 /** Integration slug — the `<integration>` address segment. */
89 readonly integration: IntegrationSlug;
90 /** Bare tool name — the `<tool>` address segment (may contain dots). */
91 readonly toolName: string;
92 /** This integration's connections (accounts) across BOTH owners. Each is
93 * addressed under its OWN owner — there is no ambient owner. */
94 readonly connections: readonly Connection[];
95 /** Pre-select this connection (the account the selected tool belongs to in the
96 * grouped Tools tab). Falls back to the first connection when null/unmatched. */
97 readonly initialConnectionName?: ConnectionName | string | null;
98}) {
99 const { integration, toolName, connections, initialConnectionName } = props;
100
101 const [selectedConnection, setSelectedConnection] = useState<ConnectionName | null>(
102 (initialConnectionName as ConnectionName | null) ?? connections[0]?.name ?? null,
103 );
104 const [argsJson, setArgsJson] = useState("{}");
105 const [argsError, setArgsError] = useState<string | null>(null);
106 const [argsMode, setArgsMode] = useState<"form" | "json">("json");
107 const [running, setRunning] = useState(false);
108 const [result, setResult] = useState<RunResult | null>(null);
109
110 const doExecute = useAtomSet(executeCode, { mode: "promiseExit" });
111
112 // Reset the picker + result when the connection set or the tool changes, so a
113 // result never lingers against a stale tool/account. Prefer the tool's own
114 // account (`initialConnectionName`) when it is present in the list.
115 useEffect(() => {
116 setSelectedConnection((current) => {
117 if (
118 initialConnectionName &&
119 connections.some((c: Connection) => c.name === initialConnectionName)
120 ) {
121 return initialConnectionName as ConnectionName;
122 }
123 if (current && connections.some((c: Connection) => c.name === current)) return current;
124 return connections[0]?.name ?? null;
125 });
126 }, [connections, initialConnectionName]);
127
128 useEffect(() => {
129 setResult(null);
130 setArgsError(null);
131 }, [toolName]);
132
133 // The full `Connection` for the selected name — carries its OWN owner, which
134 // is the `<owner>` address segment (never an ambient owner).
135 const selectedConnectionObj = useMemo<Connection | null>(
136 () => connections.find((c: Connection) => c.name === selectedConnection) ?? null,
137 [connections, selectedConnection],
138 );
139
140 // Build the per-connection address `tools.<int>.<owner>.<conn>.<tool>` and the
141 // proxy form (the same string minus the `tools.` root), using the SELECTED
142 // CONNECTION's own owner.
143 const addressNoPrefix = useMemo(
144 () =>

Callers

nothing calls this directly

Calls 5

toolSchemaAtomFunction · 0.90
isRenderableObjectSchemaFunction · 0.90
missingRequiredFieldsFunction · 0.90
toolProxyAddressFunction · 0.85
handleRunFunction · 0.85

Tested by

no test coverage detected