@marimo-team/islands 0.23.7-dev20 → 0.23.7-dev22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chat-ui-Cf4tuQ8s.js → chat-ui-Den2QMz-.js} +609 -223
- package/dist/{code-visibility-VP08CFE1.js → code-visibility-geywCqhR.js} +130 -153
- package/dist/{html-to-image-q0T1ijn_.js → html-to-image-DxWM1HVj.js} +2125 -2101
- package/dist/main.js +29 -29
- package/dist/{process-output-DTKS9bKk.js → process-output-DBYxXdrN.js} +1 -1
- package/dist/{reveal-component-ErqOa0Wd.js → reveal-component-BYYXwJoo.js} +2 -2
- package/dist/style.css +1 -1
- package/package.json +3 -3
- package/src/components/chat/chat-components.tsx +47 -0
- package/src/components/chat/chat-display.tsx +41 -7
- package/src/components/chat/chat-panel.tsx +37 -10
- package/src/components/chat/chat-utils.ts +42 -20
- package/src/components/chat/reasoning-accordion.tsx +14 -3
- package/src/components/chat/tool-call/shared.ts +13 -0
- package/src/components/chat/tool-call/tool-approval-card.tsx +62 -0
- package/src/components/chat/tool-call/tool-args.tsx +26 -0
- package/src/components/chat/tool-call/tool-call-view.tsx +99 -0
- package/src/components/chat/tool-call/tool-error-card.tsx +81 -0
- package/src/components/chat/tool-call/tool-history-row.tsx +153 -0
- package/src/components/chat/tool-call/tool-result.tsx +101 -0
- package/src/core/ai/tools/__tests__/registry.test.ts +10 -12
- package/src/core/ai/tools/registry.ts +9 -5
- package/src/components/chat/tool-call-accordion.tsx +0 -247
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { ChevronDownIcon, XCircleIcon } from "lucide-react";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { cn } from "@/utils/cn";
|
|
6
|
+
import { formatToolName } from "./shared";
|
|
7
|
+
import { ToolArgsRenderer } from "./tool-args";
|
|
8
|
+
|
|
9
|
+
interface ToolErrorCardProps {
|
|
10
|
+
toolName: string;
|
|
11
|
+
input: unknown;
|
|
12
|
+
errorText?: string;
|
|
13
|
+
// When false, defaults to collapsed (the conversation has moved past this).
|
|
14
|
+
isLive: boolean;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ToolErrorCard: React.FC<ToolErrorCardProps> = ({
|
|
19
|
+
toolName,
|
|
20
|
+
input,
|
|
21
|
+
errorText,
|
|
22
|
+
isLive,
|
|
23
|
+
className,
|
|
24
|
+
}) => {
|
|
25
|
+
const [open, setOpen] = React.useState(isLive);
|
|
26
|
+
|
|
27
|
+
// Auto-collapse once when the conversation moves past this turn.
|
|
28
|
+
// The user can still re-open manually afterwards; we only do this on the
|
|
29
|
+
// live → not-live transition, never the reverse.
|
|
30
|
+
const wasLive = React.useRef(isLive);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
if (wasLive.current && !isLive) {
|
|
33
|
+
setOpen(false);
|
|
34
|
+
}
|
|
35
|
+
wasLive.current = isLive;
|
|
36
|
+
}, [isLive]);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div
|
|
40
|
+
className={cn(
|
|
41
|
+
"rounded-md border border-(--red-6) bg-(--red-2)",
|
|
42
|
+
className,
|
|
43
|
+
)}
|
|
44
|
+
>
|
|
45
|
+
<button
|
|
46
|
+
type="button"
|
|
47
|
+
onClick={() => setOpen((prev) => !prev)}
|
|
48
|
+
className="w-full flex items-center gap-2 px-3 py-2 text-xs text-(--red-11) hover:bg-(--red-3) rounded-md transition-colors"
|
|
49
|
+
aria-expanded={open}
|
|
50
|
+
>
|
|
51
|
+
<XCircleIcon className="h-3.5 w-3.5 shrink-0" />
|
|
52
|
+
<span className="flex-1 text-left">
|
|
53
|
+
<span className="font-semibold">Failed:</span>{" "}
|
|
54
|
+
<code className="font-mono">{formatToolName(toolName)}</code>
|
|
55
|
+
</span>
|
|
56
|
+
<ChevronDownIcon
|
|
57
|
+
className={cn(
|
|
58
|
+
"h-3.5 w-3.5 shrink-0 transition-transform",
|
|
59
|
+
open && "rotate-180",
|
|
60
|
+
)}
|
|
61
|
+
/>
|
|
62
|
+
</button>
|
|
63
|
+
|
|
64
|
+
{open && (
|
|
65
|
+
<div className="px-3 pb-3 space-y-3 border-t border-(--red-6)/40 pt-3">
|
|
66
|
+
<ToolArgsRenderer input={input} />
|
|
67
|
+
{errorText && (
|
|
68
|
+
<div>
|
|
69
|
+
<h3 className="text-xs font-semibold text-(--red-11) mb-1">
|
|
70
|
+
Error
|
|
71
|
+
</h3>
|
|
72
|
+
<pre className="bg-(--red-2) border border-(--red-6) rounded p-2 text-xs text-(--red-11) leading-relaxed overflow-auto scrollbar-thin max-h-64 whitespace-pre-wrap">
|
|
73
|
+
{errorText}
|
|
74
|
+
</pre>
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { BanIcon, CheckCircleIcon, Loader2, WrenchIcon } from "lucide-react";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import {
|
|
6
|
+
Accordion,
|
|
7
|
+
AccordionContent,
|
|
8
|
+
AccordionItem,
|
|
9
|
+
AccordionTrigger,
|
|
10
|
+
} from "@/components/ui/accordion";
|
|
11
|
+
import { logNever } from "@/utils/assertNever";
|
|
12
|
+
import { cn } from "@/utils/cn";
|
|
13
|
+
import { formatToolName, type ToolApproval, type ToolState } from "./shared";
|
|
14
|
+
import { ToolArgsRenderer } from "./tool-args";
|
|
15
|
+
import { ResultRenderer } from "./tool-result";
|
|
16
|
+
|
|
17
|
+
// States considered "inert" — they represent past or background work that the
|
|
18
|
+
// user does not need to act on.
|
|
19
|
+
export type HistoryState = Exclude<
|
|
20
|
+
ToolState,
|
|
21
|
+
"approval-requested" | "output-error"
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
const STATUS_LABEL: Record<HistoryState, string> = {
|
|
25
|
+
"input-streaming": "Generating",
|
|
26
|
+
"input-available": "Running",
|
|
27
|
+
"approval-responded": "Awaiting result",
|
|
28
|
+
"output-available": "Done",
|
|
29
|
+
"output-denied": "Denied",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const StatusIcon: React.FC<{ state: HistoryState }> = ({ state }) => {
|
|
33
|
+
switch (state) {
|
|
34
|
+
case "input-streaming":
|
|
35
|
+
case "input-available":
|
|
36
|
+
case "approval-responded":
|
|
37
|
+
return <Loader2 className="h-3 w-3 animate-spin" />;
|
|
38
|
+
case "output-available":
|
|
39
|
+
return <CheckCircleIcon className="h-3 w-3 text-(--grass-11)" />;
|
|
40
|
+
case "output-denied":
|
|
41
|
+
return <BanIcon className="h-3 w-3 text-muted-foreground" />;
|
|
42
|
+
default:
|
|
43
|
+
logNever(state);
|
|
44
|
+
return <WrenchIcon className="h-3 w-3" />;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function getTriggerToneClass(state: HistoryState): string {
|
|
49
|
+
switch (state) {
|
|
50
|
+
case "output-available":
|
|
51
|
+
return "text-(--grass-11)/80";
|
|
52
|
+
case "output-denied":
|
|
53
|
+
return "text-muted-foreground";
|
|
54
|
+
case "input-streaming":
|
|
55
|
+
case "input-available":
|
|
56
|
+
case "approval-responded":
|
|
57
|
+
return "";
|
|
58
|
+
default:
|
|
59
|
+
logNever(state);
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface ToolHistoryRowProps {
|
|
65
|
+
toolName: string;
|
|
66
|
+
state: HistoryState;
|
|
67
|
+
input: unknown;
|
|
68
|
+
result?: unknown;
|
|
69
|
+
approval?: ToolApproval;
|
|
70
|
+
index?: number;
|
|
71
|
+
className?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const ToolHistoryRow: React.FC<ToolHistoryRowProps> = ({
|
|
75
|
+
toolName,
|
|
76
|
+
state,
|
|
77
|
+
input,
|
|
78
|
+
result,
|
|
79
|
+
approval,
|
|
80
|
+
index = 0,
|
|
81
|
+
className,
|
|
82
|
+
}) => {
|
|
83
|
+
return (
|
|
84
|
+
<Accordion
|
|
85
|
+
key={`tool-${index}`}
|
|
86
|
+
type="single"
|
|
87
|
+
collapsible={true}
|
|
88
|
+
className={cn("w-full", className)}
|
|
89
|
+
>
|
|
90
|
+
<AccordionItem value="tool-call" className="border-0">
|
|
91
|
+
<AccordionTrigger
|
|
92
|
+
className={cn(
|
|
93
|
+
"h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline",
|
|
94
|
+
getTriggerToneClass(state),
|
|
95
|
+
)}
|
|
96
|
+
>
|
|
97
|
+
<span className="flex items-center gap-1">
|
|
98
|
+
<StatusIcon state={state} />
|
|
99
|
+
{STATUS_LABEL[state]}:
|
|
100
|
+
<code className="font-mono text-xs">
|
|
101
|
+
{formatToolName(toolName)}
|
|
102
|
+
</code>
|
|
103
|
+
</span>
|
|
104
|
+
</AccordionTrigger>
|
|
105
|
+
<AccordionContent className="py-2 px-2">
|
|
106
|
+
<HistoryContent
|
|
107
|
+
state={state}
|
|
108
|
+
input={input}
|
|
109
|
+
result={result}
|
|
110
|
+
approval={approval}
|
|
111
|
+
/>
|
|
112
|
+
</AccordionContent>
|
|
113
|
+
</AccordionItem>
|
|
114
|
+
</Accordion>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const HistoryContent: React.FC<{
|
|
119
|
+
state: HistoryState;
|
|
120
|
+
input: unknown;
|
|
121
|
+
result?: unknown;
|
|
122
|
+
approval?: ToolApproval;
|
|
123
|
+
}> = ({ state, input, result, approval }) => {
|
|
124
|
+
switch (state) {
|
|
125
|
+
case "input-streaming":
|
|
126
|
+
case "input-available":
|
|
127
|
+
case "approval-responded":
|
|
128
|
+
return <ToolArgsRenderer input={input} />;
|
|
129
|
+
|
|
130
|
+
case "output-available":
|
|
131
|
+
return (
|
|
132
|
+
<div className="space-y-3">
|
|
133
|
+
<ToolArgsRenderer input={input} />
|
|
134
|
+
{result != null && <ResultRenderer result={result} />}
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
case "output-denied":
|
|
139
|
+
return (
|
|
140
|
+
<div className="space-y-3">
|
|
141
|
+
<ToolArgsRenderer input={input} />
|
|
142
|
+
<div className="bg-muted/40 border border-border rounded-md p-3 text-xs text-muted-foreground leading-relaxed">
|
|
143
|
+
Tool execution was denied
|
|
144
|
+
{approval?.reason ? `: ${approval.reason}` : "."}
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
default:
|
|
150
|
+
logNever(state);
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { isEmpty } from "lodash-es";
|
|
4
|
+
import { InfoIcon } from "lucide-react";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
|
|
8
|
+
// A value worth rendering: drop null/undefined and empty containers
|
|
9
|
+
// (`{}`, `[]`), but keep meaningful primitives (`0`, `false`, `""`).
|
|
10
|
+
function isUninformative(value: unknown): boolean {
|
|
11
|
+
if (value == null) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === "object") {
|
|
15
|
+
return isEmpty(value);
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Zod schema matching the Python SuccessResult dataclass
|
|
21
|
+
const SuccessResultSchema = z.looseObject({
|
|
22
|
+
status: z.string().default("success"),
|
|
23
|
+
auth_required: z.boolean().default(false),
|
|
24
|
+
action_url: z.any(),
|
|
25
|
+
next_steps: z.any(),
|
|
26
|
+
meta: z.any(),
|
|
27
|
+
message: z.string().nullish(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
type SuccessResult = z.infer<typeof SuccessResultSchema>;
|
|
31
|
+
|
|
32
|
+
const PrettySuccessResult: React.FC<{ data: SuccessResult }> = ({ data }) => {
|
|
33
|
+
const {
|
|
34
|
+
status,
|
|
35
|
+
auth_required,
|
|
36
|
+
action_url: _action_url,
|
|
37
|
+
meta: _meta,
|
|
38
|
+
next_steps: _next_steps,
|
|
39
|
+
message,
|
|
40
|
+
...rest
|
|
41
|
+
} = data;
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className="flex flex-col gap-1.5">
|
|
45
|
+
<div className="flex items-center justify-between">
|
|
46
|
+
<h3 className="text-xs font-semibold text-muted-foreground">
|
|
47
|
+
Tool Result
|
|
48
|
+
</h3>
|
|
49
|
+
<div className="flex items-center gap-2">
|
|
50
|
+
<span className="text-xs px-2 py-0.5 bg-(--grass-2) text-(--grass-11) rounded-full font-medium capitalize">
|
|
51
|
+
{status}
|
|
52
|
+
</span>
|
|
53
|
+
{auth_required && (
|
|
54
|
+
<span className="text-xs px-2 py-0.5 bg-(--amber-2) text-(--amber-11) rounded-full">
|
|
55
|
+
Auth Required
|
|
56
|
+
</span>
|
|
57
|
+
)}
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
{message && (
|
|
62
|
+
<div className="flex items-start gap-2">
|
|
63
|
+
<InfoIcon className="h-3 w-3 text-(--blue-11) mt-0.5 shrink-0" />
|
|
64
|
+
<div className="text-xs text-foreground">{message}</div>
|
|
65
|
+
</div>
|
|
66
|
+
)}
|
|
67
|
+
|
|
68
|
+
{rest && (
|
|
69
|
+
<div className="space-y-3">
|
|
70
|
+
{Object.entries(rest).map(([key, value]) => {
|
|
71
|
+
if (isUninformative(value)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return (
|
|
75
|
+
<div key={key} className="space-y-1.5">
|
|
76
|
+
<span className="text-xs text-muted-foreground">{key}</span>
|
|
77
|
+
<pre className="bg-(--slate-2) p-2 text-muted-foreground border border-(--slate-4) rounded text-xs overflow-auto scrollbar-thin max-h-64">
|
|
78
|
+
{JSON.stringify(value, null, 2)}
|
|
79
|
+
</pre>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
})}
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const ResultRenderer: React.FC<{ result: unknown }> = ({ result }) => {
|
|
90
|
+
const parseResult = SuccessResultSchema.safeParse(result);
|
|
91
|
+
|
|
92
|
+
if (parseResult.success) {
|
|
93
|
+
return <PrettySuccessResult data={parseResult.data} />;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div className="text-xs font-medium text-muted-foreground mb-1 max-h-64 overflow-y-auto scrollbar-thin">
|
|
98
|
+
{typeof result === "string" ? result : JSON.stringify(result, null, 2)}
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
};
|
|
@@ -18,13 +18,11 @@ describe("FrontendToolRegistry", () => {
|
|
|
18
18
|
|
|
19
19
|
it("invokes a tool with valid args and validates input/output", async () => {
|
|
20
20
|
const registry = new FrontendToolRegistry([new TestFrontendTool()]);
|
|
21
|
-
const response = await registry.invoke(
|
|
22
|
-
"test_frontend_tool",
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
{} as never,
|
|
27
|
-
);
|
|
21
|
+
const response = await registry.invoke({
|
|
22
|
+
toolName: "test_frontend_tool",
|
|
23
|
+
rawArgs: { name: "Alice" },
|
|
24
|
+
toolContext: {} as never,
|
|
25
|
+
});
|
|
28
26
|
|
|
29
27
|
// Check InvokeResult wrapper
|
|
30
28
|
expect(response.tool_name).toBe("test_frontend_tool");
|
|
@@ -47,11 +45,11 @@ describe("FrontendToolRegistry", () => {
|
|
|
47
45
|
|
|
48
46
|
it("returns a structured error on invalid args", async () => {
|
|
49
47
|
const registry = new FrontendToolRegistry([new TestFrontendTool()]);
|
|
50
|
-
const response = await registry.invoke(
|
|
51
|
-
"test_frontend_tool",
|
|
52
|
-
{},
|
|
53
|
-
{} as never,
|
|
54
|
-
);
|
|
48
|
+
const response = await registry.invoke({
|
|
49
|
+
toolName: "test_frontend_tool",
|
|
50
|
+
rawArgs: {},
|
|
51
|
+
toolContext: {} as never,
|
|
52
|
+
});
|
|
55
53
|
|
|
56
54
|
// Check InvokeResult wrapper
|
|
57
55
|
expect(response.tool_name).toBe("test_frontend_tool");
|
|
@@ -52,11 +52,15 @@ export class FrontendToolRegistry {
|
|
|
52
52
|
return tool;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
async invoke<TName extends string>(
|
|
56
|
-
toolName
|
|
57
|
-
rawArgs
|
|
58
|
-
toolContext
|
|
59
|
-
|
|
55
|
+
async invoke<TName extends string>({
|
|
56
|
+
toolName,
|
|
57
|
+
rawArgs,
|
|
58
|
+
toolContext,
|
|
59
|
+
}: {
|
|
60
|
+
toolName: TName;
|
|
61
|
+
rawArgs: unknown;
|
|
62
|
+
toolContext: ToolNotebookContext;
|
|
63
|
+
}): Promise<InvokeResult<TName>> {
|
|
60
64
|
const tool = this.getToolOrThrow(toolName);
|
|
61
65
|
const handler = tool.handler;
|
|
62
66
|
const inputSchema = tool.schema;
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
|
|
3
|
-
import type { ToolUIPart } from "ai";
|
|
4
|
-
import { isEmpty } from "lodash-es";
|
|
5
|
-
import {
|
|
6
|
-
CheckCircleIcon,
|
|
7
|
-
InfoIcon,
|
|
8
|
-
Loader2,
|
|
9
|
-
WrenchIcon,
|
|
10
|
-
XCircleIcon,
|
|
11
|
-
} from "lucide-react";
|
|
12
|
-
import React from "react";
|
|
13
|
-
import { z } from "zod";
|
|
14
|
-
import {
|
|
15
|
-
Accordion,
|
|
16
|
-
AccordionContent,
|
|
17
|
-
AccordionItem,
|
|
18
|
-
AccordionTrigger,
|
|
19
|
-
} from "@/components/ui/accordion";
|
|
20
|
-
import { cn } from "@/utils/cn";
|
|
21
|
-
|
|
22
|
-
// Zod schema matching the Python SuccessResult dataclass
|
|
23
|
-
const SuccessResultSchema = z
|
|
24
|
-
.object({
|
|
25
|
-
status: z.string().default("success"),
|
|
26
|
-
auth_required: z.boolean().default(false),
|
|
27
|
-
action_url: z.any(),
|
|
28
|
-
next_steps: z.any(),
|
|
29
|
-
meta: z.any(),
|
|
30
|
-
message: z.string().nullish(),
|
|
31
|
-
})
|
|
32
|
-
.passthrough();
|
|
33
|
-
|
|
34
|
-
type SuccessResult = z.infer<typeof SuccessResultSchema>;
|
|
35
|
-
|
|
36
|
-
const PrettySuccessResult: React.FC<{ data: SuccessResult }> = ({ data }) => {
|
|
37
|
-
const {
|
|
38
|
-
status,
|
|
39
|
-
auth_required,
|
|
40
|
-
action_url: _action_url,
|
|
41
|
-
meta: _meta,
|
|
42
|
-
next_steps: _next_steps,
|
|
43
|
-
message,
|
|
44
|
-
...rest
|
|
45
|
-
} = data;
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<div className="flex flex-col gap-1.5">
|
|
49
|
-
<div className="flex items-center justify-between">
|
|
50
|
-
<h3 className="text-xs font-semibold text-muted-foreground">
|
|
51
|
-
Tool Result
|
|
52
|
-
</h3>
|
|
53
|
-
<div className="flex items-center gap-2">
|
|
54
|
-
<span className="text-xs px-2 py-0.5 bg-[var(--grass-2)] text-[var(--grass-11)] rounded-full font-medium capitalize">
|
|
55
|
-
{status}
|
|
56
|
-
</span>
|
|
57
|
-
{auth_required && (
|
|
58
|
-
<span className="text-xs px-2 py-0.5 bg-[var(--amber-2)] text-[var(--amber-11)] rounded-full">
|
|
59
|
-
Auth Required
|
|
60
|
-
</span>
|
|
61
|
-
)}
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
|
|
65
|
-
{/* Message */}
|
|
66
|
-
{message && (
|
|
67
|
-
<div className="flex items-start gap-2">
|
|
68
|
-
<InfoIcon className="h-3 w-3 text-[var(--blue-11)] mt-0.5 flex-shrink-0" />
|
|
69
|
-
<div className="text-xs text-foreground">{message}</div>
|
|
70
|
-
</div>
|
|
71
|
-
)}
|
|
72
|
-
|
|
73
|
-
{/* Data */}
|
|
74
|
-
{rest && (
|
|
75
|
-
<div className="space-y-3">
|
|
76
|
-
{Object.entries(rest).map(([key, value]) => {
|
|
77
|
-
if (isEmpty(value)) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
return (
|
|
81
|
-
<div key={key} className="space-y-1.5">
|
|
82
|
-
<div className="text-xs font-medium text-muted-foreground capitalize flex items-center gap-2">
|
|
83
|
-
<div className="w-1.5 h-1.5 bg-[var(--blue-9)] rounded-full" />
|
|
84
|
-
{key}
|
|
85
|
-
</div>
|
|
86
|
-
<pre className="bg-[var(--slate-2)] p-2 text-muted-foreground border border-[var(--slate-4)] rounded text-xs overflow-auto scrollbar-thin max-h-64">
|
|
87
|
-
{JSON.stringify(value, null, 2)}
|
|
88
|
-
</pre>
|
|
89
|
-
</div>
|
|
90
|
-
);
|
|
91
|
-
})}
|
|
92
|
-
</div>
|
|
93
|
-
)}
|
|
94
|
-
</div>
|
|
95
|
-
);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const ResultRenderer: React.FC<{ result: unknown }> = ({ result }) => {
|
|
99
|
-
// Try to parse the result with our Zod schema
|
|
100
|
-
const parseResult = SuccessResultSchema.safeParse(result);
|
|
101
|
-
|
|
102
|
-
if (parseResult.success) {
|
|
103
|
-
// If it matches the SuccessResult schema, show the pretty UI
|
|
104
|
-
return <PrettySuccessResult data={parseResult.data} />;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Otherwise, fall back to the current JSON viewer
|
|
108
|
-
return (
|
|
109
|
-
<div className="text-xs font-medium text-muted-foreground mb-1 max-h-64 overflow-y-auto scrollbar-thin">
|
|
110
|
-
{typeof result === "string" ? result : JSON.stringify(result, null, 2)}
|
|
111
|
-
</div>
|
|
112
|
-
);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const ToolArgsRenderer: React.FC<{ input: unknown }> = ({ input }) => {
|
|
116
|
-
const hasinput = input && input !== null;
|
|
117
|
-
|
|
118
|
-
if (!hasinput) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const isEmptyInput = isEmpty(input);
|
|
123
|
-
|
|
124
|
-
const isObject =
|
|
125
|
-
typeof input === "object" &&
|
|
126
|
-
!Array.isArray(input) &&
|
|
127
|
-
Object.keys(input as Record<string, unknown>).length > 0;
|
|
128
|
-
|
|
129
|
-
return (
|
|
130
|
-
<div className="space-y-2">
|
|
131
|
-
<h3 className="text-xs font-semibold text-muted-foreground">
|
|
132
|
-
Tool Request
|
|
133
|
-
</h3>
|
|
134
|
-
<pre className="bg-[var(--slate-2)] p-2 text-muted-foreground border border-[var(--slate-4)] rounded text-xs overflow-auto scrollbar-thin max-h-64">
|
|
135
|
-
{isEmptyInput
|
|
136
|
-
? "{}"
|
|
137
|
-
: isObject
|
|
138
|
-
? JSON.stringify(input, null, 2)
|
|
139
|
-
: String(input)}
|
|
140
|
-
</pre>
|
|
141
|
-
</div>
|
|
142
|
-
);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
interface ToolCallAccordionProps {
|
|
146
|
-
toolName: string;
|
|
147
|
-
result: unknown;
|
|
148
|
-
error?: string;
|
|
149
|
-
index?: number;
|
|
150
|
-
state?: ToolUIPart["state"];
|
|
151
|
-
className?: string;
|
|
152
|
-
input?: unknown;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export const ToolCallAccordion: React.FC<ToolCallAccordionProps> = ({
|
|
156
|
-
toolName,
|
|
157
|
-
result,
|
|
158
|
-
error,
|
|
159
|
-
index = 0,
|
|
160
|
-
state,
|
|
161
|
-
className,
|
|
162
|
-
input,
|
|
163
|
-
}) => {
|
|
164
|
-
const hasResult = state === "output-available" && (result || error);
|
|
165
|
-
const status = error ? "error" : hasResult ? "success" : "loading";
|
|
166
|
-
|
|
167
|
-
const getStatusIcon = () => {
|
|
168
|
-
switch (status) {
|
|
169
|
-
case "loading":
|
|
170
|
-
return <Loader2 className="h-3 w-3 animate-spin" />;
|
|
171
|
-
case "error":
|
|
172
|
-
return <XCircleIcon className="h-3 w-3 text-[var(--red-11)]" />;
|
|
173
|
-
case "success":
|
|
174
|
-
return <CheckCircleIcon className="h-3 w-3 text-[var(--grass-11)]" />;
|
|
175
|
-
default:
|
|
176
|
-
return <WrenchIcon className="h-3 w-3" />;
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const getStatusText = () => {
|
|
181
|
-
if (status === "loading") {
|
|
182
|
-
return "Running";
|
|
183
|
-
}
|
|
184
|
-
if (error) {
|
|
185
|
-
return "Failed";
|
|
186
|
-
}
|
|
187
|
-
if (hasResult) {
|
|
188
|
-
return "Done";
|
|
189
|
-
}
|
|
190
|
-
return "Tool call";
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
return (
|
|
194
|
-
<Accordion
|
|
195
|
-
key={`tool-${index}`}
|
|
196
|
-
type="single"
|
|
197
|
-
collapsible={true}
|
|
198
|
-
className={cn("w-full", className)}
|
|
199
|
-
>
|
|
200
|
-
<AccordionItem value="tool-call" className="border-0">
|
|
201
|
-
<AccordionTrigger
|
|
202
|
-
className={cn(
|
|
203
|
-
"h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline",
|
|
204
|
-
status === "error" && "text-[var(--red-11)]/80",
|
|
205
|
-
status === "success" && "text-[var(--grass-11)]/80",
|
|
206
|
-
)}
|
|
207
|
-
>
|
|
208
|
-
<span className="flex items-center gap-1">
|
|
209
|
-
{getStatusIcon()}
|
|
210
|
-
{getStatusText()}:
|
|
211
|
-
<code className="font-mono text-xs">
|
|
212
|
-
{formatToolName(toolName)}
|
|
213
|
-
</code>
|
|
214
|
-
</span>
|
|
215
|
-
</AccordionTrigger>
|
|
216
|
-
<AccordionContent className="py-2 px-2">
|
|
217
|
-
{/* Only show content when tool is complete */}
|
|
218
|
-
{hasResult && (
|
|
219
|
-
<div className="space-y-3">
|
|
220
|
-
<ToolArgsRenderer input={input} />
|
|
221
|
-
{result !== undefined && result !== null && (
|
|
222
|
-
<ResultRenderer result={result} />
|
|
223
|
-
)}
|
|
224
|
-
|
|
225
|
-
{/* Error */}
|
|
226
|
-
{error && (
|
|
227
|
-
<div className="bg-[var(--red-2)] border border-[var(--red-6)] rounded-lg p-3">
|
|
228
|
-
<div className="text-xs font-semibold text-[var(--red-11)] mb-2 flex items-center gap-2">
|
|
229
|
-
<div className="w-1.5 h-1.5 bg-[var(--red-9)] rounded-full" />
|
|
230
|
-
Error
|
|
231
|
-
</div>
|
|
232
|
-
<div className="text-sm text-[var(--red-11)] leading-relaxed">
|
|
233
|
-
{error}
|
|
234
|
-
</div>
|
|
235
|
-
</div>
|
|
236
|
-
)}
|
|
237
|
-
</div>
|
|
238
|
-
)}
|
|
239
|
-
</AccordionContent>
|
|
240
|
-
</AccordionItem>
|
|
241
|
-
</Accordion>
|
|
242
|
-
);
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
function formatToolName(toolName: string) {
|
|
246
|
-
return toolName.replace("tool-", "");
|
|
247
|
-
}
|