// ***************************************************************************** // Copyright (C) 2026 EclipseSource GmbH. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** import { ReactNode } from '@theia/core/shared/react'; import { OpenerService } from '@theia/core/lib/browser'; import { isToolCallContent, ToolCallResult } from '@theia/ai-core'; import { MarkdownRender } from './markdown-part-renderer.js'; import { McpAppFrame } from './mcp-app-frame.js'; /** Parses a tool call result that may be a JSON string, returning the original value on failure. */ export function tryParseToolCallResult(result: ToolCallResult): ToolCallResult { if (!result) { return undefined; } try { return typeof result === 'string' ? JSON.parse(result) : result; } catch (error) { return result; } } /** * Renders a tool call result (client or server tool). Shared between {@link ToolCallPartRenderer} * and the server tool renderer so both display results consistently. */ export function renderToolCallResult(rawResult: ToolCallResult, openerService: OpenerService): ReactNode { const result = tryParseToolCallResult(rawResult); if (!result) { return undefined; } // eslint-disable-next-line no-null/no-null if (typeof result !== 'object' || result === null) { return
{String(result)};
}
if (isToolCallContent(result)) {
return {content.data}{JSON.stringify(content, undefined, 2)}{JSON.stringify(result, undefined, 2)};
}