Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(ai): UI for failed tool calls (#2472)

Eric Hayesc108de3202fe
diff --git a/js/app/packages/core/component/AI/component/message/AssistantMessage.tsx b/js/app/packages/core/component/AI/component/message/AssistantMessage.tsx
index bbd922ee11..32ae1190a0 100644
--- a/js/app/packages/core/component/AI/component/message/AssistantMessage.tsx
+++ b/js/app/packages/core/component/AI/component/message/AssistantMessage.tsx
@@ -281,7 +281,10 @@ function AssistantMessageParts(props: {
});
const parts = createMemo(() => {
- return props.parts.filter((part) => part.type !== 'toolCallResponseJson');
+ return props.parts.filter(
+ (part) =>
+ part.type !== 'toolCallResponseJson' && part.type !== 'toolCallErr'
+ );
});
const keyedParts = createMemo(() => {
@@ -339,20 +342,6 @@ function AssistantMessageParts(props: {
);
})()}
</Match>
- <Match when={type() === 'toolCallErr'}>
- {(() => {
- const toolError = () =>
- currentPart() as Extract<
- AssistantMessagePart,
- { type: 'toolCallErr' }
- >;
- return (
- <div class="px-2 py-1 text-sm text-ink-muted">
- Tool `{toolError().name}` failed: {toolError().description}
- </div>
- );
- })()}
- </Match>
<Match when={type() === 'text'}>
{(() => {
const text = () => {
diff --git a/js/app/packages/core/component/AI/component/tool/BaseTool.tsx b/js/app/packages/core/component/AI/component/tool/BaseTool.tsx
index 301a07595d..fadee638b3 100644
--- a/js/app/packages/core/component/AI/component/tool/BaseTool.tsx
+++ b/js/app/packages/core/component/AI/component/tool/BaseTool.tsx
@@ -1,5 +1,5 @@
import { type Component, type JSX, Show } from 'solid-js';
-import type { RenderContext } from './ToolRenderer';
+import { type RenderContext, useToolError } from './ToolRenderer';
type ToolCallProps = {
icon: Component<JSX.SvgSVGAttributes<SVGSVGElement>>;
@@ -15,11 +15,19 @@ type ToolResponseProps = {
};
function BaseToolCall(props: ToolCallProps) {
+ const error = useToolError();
+
return (
- <div class="relative text-sm text-ink-extra-muted border-l pl-4 border-edge">
+ <div
+ class="relative text-sm text-ink-extra-muted border-l pl-4 border-edge"
+ classList={{ 'opacity-50': !!error }}
+ >
<div class="flex w-full items-center gap-x-2">
<props.icon class="h-[20px] w-[20px] shrink-0 text-accent" />
<div class="min-w-0 flex-1 p-2">{props.children}</div>
+ <Show when={error}>
+ <span class="shrink-0 pr-2 text-ink-muted">Failed</span>
+ </Show>
</div>
<Show when={props.response}>
<div class="pl-8 mb-2">{props.response}</div>
diff --git a/js/app/packages/core/component/AI/component/tool/ToolRenderer.tsx b/js/app/packages/core/component/AI/component/tool/ToolRenderer.tsx
index 159eaa08c3..5db6c3a5b2 100644
--- a/js/app/packages/core/component/AI/component/tool/ToolRenderer.tsx
+++ b/js/app/packages/core/component/AI/component/tool/ToolRenderer.tsx
@@ -1,9 +1,17 @@
-import type { Component } from 'solid-js';
+import { type Component, createContext, useContext } from 'solid-js';
import type {
NamedTool,
ToolName,
} from '@service-cognition/generated/tools/tool';
+export const ToolErrorContext = createContext<
+ (() => string | undefined) | undefined
+>();
+export const useToolError = () => {
+ const accessor = useContext(ToolErrorContext);
+ return accessor?.();
+};
+
export type RenderContext = {
renderContext: {
isStreaming: boolean;
diff --git a/js/app/packages/core/component/AI/component/tool/handler.tsx b/js/app/packages/core/component/AI/component/tool/handler.tsx
index f5e35c6afe..6383c98813 100644
--- a/js/app/packages/core/component/AI/component/tool/handler.tsx
+++ b/js/app/packages/core/component/AI/component/tool/handler.tsx
@@ -19,11 +19,12 @@ import { readThreadHandler } from './ReadThread';
import { contentSearchHandler, nameSearchHandler } from './Search';
import { sendEmailHandler } from './SendEmail';
import { textEditorCodeExecutionHandler } from './TextEditorCodeExecution';
-import type {
- RenderContext,
- ToolHandler,
- ToolHandlerMap,
- ToolRenderContext,
+import {
+ ToolErrorContext,
+ type RenderContext,
+ type ToolHandler,
+ type ToolHandlerMap,
+ type ToolRenderContext,
} from './ToolRenderer';
import { updateThreadLabelsHandler } from './UpdateThreadLabels';
import { webFetchHandler } from './WebFetch';
@@ -105,14 +106,18 @@ export function RenderTool(props: ToolProps) {
};
return (
- <Dynamic
- component={handler.render}
- {...context}
- response={response()}
- renderContext={{
- isStreaming: props.renderContext.renderContext.isStreaming,
- }}
- />
+ <ToolErrorContext.Provider
+ value={() => (props.isComplete && !response() ? 'failed' : undefined)}
+ >
+ <Dynamic
+ component={handler.render}
+ {...context}
+ response={response()}
+ renderContext={{
+ isStreaming: props.renderContext.renderContext.isStreaming,
+ }}
+ />
+ </ToolErrorContext.Provider>
);
}