Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(web-chat): coerce tool output to string before trimEnd (#2663)

Matt Lewisfccbf2bbc355
diff --git a/.changeset/web-chat-tool-trimend-type.md b/.changeset/web-chat-tool-trimend-type.md
new file mode 100644
index 000000000..ebcbbdd33
--- /dev/null
+++ b/.changeset/web-chat-tool-trimend-type.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Fix a TypeScript error in the generated Web Chat `tool.tsx` where `trimEnd` was called on `string | number` values returned by the tool output helper.
diff --git a/apps/docs/registry/channel/web/components/ai-elements/tool.tsx b/apps/docs/registry/channel/web/components/ai-elements/tool.tsx
index 0453c89ab..6859d968b 100644
--- a/apps/docs/registry/channel/web/components/ai-elements/tool.tsx
+++ b/apps/docs/registry/channel/web/components/ai-elements/tool.tsx
@@ -125,8 +125,10 @@ export const BashToolContent = ({
<span className="mb-2 block font-sans text-[10px] text-muted-foreground uppercase tracking-wide">
Output
</span>
- {stdout ? <span className="block">{stdout.trimEnd()}</span> : null}
- {stderr ? <span className="block text-destructive">{stderr.trimEnd()}</span> : null}
+ {stdout ? <span className="block">{String(stdout).trimEnd()}</span> : null}
+ {stderr ? (
+ <span className="block text-destructive">{String(stderr).trimEnd()}</span>
+ ) : null}
{typeof exitCode === "number" && exitCode !== 0 ? (
<span className="block text-muted-foreground">Exited with code {exitCode}</span>
) : null}
diff --git a/packages/eve/src/setup/scaffold/create/web-template.ts b/packages/eve/src/setup/scaffold/create/web-template.ts
index 3ec3ffee9..739735332 100644
--- a/packages/eve/src/setup/scaffold/create/web-template.ts
+++ b/packages/eve/src/setup/scaffold/create/web-template.ts
@@ -39,7 +39,7 @@ export const WEB_APP_TEMPLATE_FILES = {
"components/ai-elements/shimmer.tsx":
'"use client";\n\nimport { cn } from "@/lib/utils";\nimport type { MotionProps } from "motion/react";\nimport { motion } from "motion/react";\nimport type { CSSProperties, ElementType, JSX } from "react";\nimport { memo, useMemo } from "react";\n\ntype MotionHTMLProps = MotionProps & Record<string, unknown>;\n\n// Cache motion components at module level to avoid creating during render\nconst motionComponentCache = new Map<\n keyof JSX.IntrinsicElements,\n React.ComponentType<MotionHTMLProps>\n>();\n\nconst getMotionComponent = (element: keyof JSX.IntrinsicElements) => {\n let component = motionComponentCache.get(element);\n if (!component) {\n component = motion.create(element);\n motionComponentCache.set(element, component);\n }\n return component;\n};\n\nexport interface TextShimmerProps {\n children: string;\n as?: ElementType;\n className?: string;\n duration?: number;\n spread?: number;\n}\n\nconst ShimmerComponent = ({\n children,\n as: Component = "p",\n className,\n duration = 2,\n spread = 2,\n}: TextShimmerProps) => {\n const MotionComponent = getMotionComponent(Component as keyof JSX.IntrinsicElements);\n\n const dynamicSpread = useMemo(() => (children?.length ?? 0) * spread, [children, spread]);\n\n return (\n <MotionComponent\n animate={{ backgroundPosition: "0% center" }}\n className={cn(\n "relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent",\n "[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",\n className,\n )}\n initial={{ backgroundPosition: "100% center" }}\n style={\n {\n "--spread": `${dynamicSpread}px`,\n backgroundImage:\n "var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))",\n } as CSSProperties\n }\n transition={{\n duration,\n ease: "linear",\n repeat: Number.POSITIVE_INFINITY,\n }}\n >\n {children}\n </MotionComponent>\n );\n};\n\nexport const Shimmer = memo(ShimmerComponent);\n',
"components/ai-elements/tool.tsx":
- '"use client";\n\nimport { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";\nimport { cn } from "@/lib/utils";\nimport type { DynamicToolUIPart, ToolUIPart } from "ai";\nimport { ChevronRightIcon, TerminalIcon, WrenchIcon } from "lucide-react";\nimport type { ComponentProps, ReactNode } from "react";\nimport { isValidElement } from "react";\n\nimport { CodeBlock } from "./code-block";\n\nconst compactCodeBlockClassName =\n "rounded-none border-0 bg-transparent [&_pre]:!bg-transparent [&_pre]:px-3 [&_pre]:pt-2 [&_pre]:pb-3 [&_pre]:text-xs [&_code]:text-xs";\n\nexport type ToolProps = ComponentProps<typeof Collapsible>;\n\nexport const Tool = ({ className, ...props }: ToolProps) => (\n <Collapsible className={cn("group not-prose w-full", className)} {...props} />\n);\n\nexport type ToolPart = ToolUIPart | DynamicToolUIPart;\n\nexport type ToolHeaderProps = {\n title?: string;\n className?: string;\n} & (\n | { type: ToolUIPart["type"]; state: ToolUIPart["state"]; toolName?: never }\n | {\n type: DynamicToolUIPart["type"];\n state: DynamicToolUIPart["state"];\n toolName: string;\n }\n);\n\nconst statusLabels: Record<ToolPart["state"], string> = {\n "approval-requested": "Awaiting Approval",\n "approval-responded": "Responded",\n "input-available": "Running",\n "input-streaming": "Pending",\n "output-available": "Completed",\n "output-denied": "Denied",\n "output-error": "Error",\n};\n\nexport const getStatusIndicator = (status: ToolPart["state"]) =>\n status === "output-available" ? null : (\n <span className={cn("text-sm", status === "output-error" && "text-destructive")}>\n {statusLabels[status]}\n </span>\n );\n\nexport const ToolHeader = ({\n className,\n title,\n type,\n state,\n toolName,\n ...props\n}: ToolHeaderProps) => {\n const derivedName = type === "dynamic-tool" ? toolName : type.split("-").slice(1).join("-");\n const displayName = title ?? derivedName;\n\n return (\n <CollapsibleTrigger\n className={cn(\n "flex w-full items-center gap-2 py-0.5 text-left text-muted-foreground transition-colors hover:text-foreground",\n className,\n )}\n {...props}\n >\n {displayName === "bash" ? (\n <TerminalIcon className="size-4 shrink-0" />\n ) : (\n <WrenchIcon className="size-4 shrink-0" />\n )}\n <span className="text-sm">{displayName}</span>\n {getStatusIndicator(state)}\n <ChevronRightIcon className="size-3.5 shrink-0 transition-transform group-data-[state=open]:rotate-90" />\n </CollapsibleTrigger>\n );\n};\n\nexport type ToolContentProps = ComponentProps<typeof CollapsibleContent>;\n\nexport const ToolContent = ({ className, ...props }: ToolContentProps) => (\n <CollapsibleContent\n className={cn(\n "data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 space-y-4 py-2 text-popover-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",\n className,\n )}\n {...props}\n />\n);\n\nexport type BashToolContentProps = ComponentProps<"div"> & {\n input: ToolPart["input"];\n output: ToolPart["output"];\n errorText: ToolPart["errorText"];\n};\n\nexport const BashToolContent = ({\n className,\n input,\n output,\n errorText,\n ...props\n}: BashToolContentProps) => {\n const command = getRecordValue(input, "command");\n const stdout = getRecordValue(output, "stdout") ?? (typeof output === "string" ? output : "");\n const stderr = getRecordValue(output, "stderr") ?? errorText ?? "";\n const exitCode = getRecordValue(output, "exitCode");\n const hasResult = Boolean(stdout || stderr || (typeof exitCode === "number" && exitCode !== 0));\n\n return (\n <div className={cn("space-y-2", className)} {...props}>\n <pre className="overflow-x-auto whitespace-pre-wrap rounded-md bg-muted/50 p-3 font-mono text-xs leading-relaxed">\n <code>\n <span className="text-muted-foreground">$ </span>\n {command ?? "…"}\n </code>\n </pre>\n {hasResult ? (\n <pre className="overflow-x-auto whitespace-pre-wrap rounded-md bg-muted/50 p-3 font-mono text-xs leading-relaxed">\n <code>\n <span className="mb-2 block font-sans text-[10px] text-muted-foreground uppercase tracking-wide">\n Output\n </span>\n {stdout ? <span className="block">{stdout.trimEnd()}</span> : null}\n {stderr ? <span className="block text-destructive">{stderr.trimEnd()}</span> : null}\n {typeof exitCode === "number" && exitCode !== 0 ? (\n <span className="block text-muted-foreground">Exited with code {exitCode}</span>\n ) : null}\n </code>\n </pre>\n ) : null}\n </div>\n );\n};\n\nconst getRecordValue = (value: unknown, key: string): string | number | undefined => {\n if (typeof value !== "object" || value === null || !(key in value)) {\n return undefined;\n }\n\n const property = value[key as keyof typeof value];\n return typeof property === "string" || typeof property === "number" ? property : undefined;\n};\n\nexport type ToolInputProps = ComponentProps<"div"> & {\n input: ToolPart["input"];\n};\n\nexport const ToolInput = ({ className, input, ...props }: ToolInputProps) => (\n <div className={cn("overflow-hidden rounded-md bg-muted/50", className)} {...props}>\n <span className="block px-3 pt-3 font-sans text-[10px] text-muted-foreground uppercase tracking-wide">\n Parameters\n </span>\n <div>\n <CodeBlock\n className={compactCodeBlockClassName}\n code={JSON.stringify(input, null, 2)}\n language="json"\n />\n </div>\n </div>\n);\n\nexport type ToolOutputProps = ComponentProps<"div"> & {\n output: ToolPart["output"];\n errorText: ToolPart["errorText"];\n};\n\nexport const ToolOutput = ({ className, output, errorText, ...props }: ToolOutputProps) => {\n if (!(output || errorText)) {\n return null;\n }\n\n let Output = <div>{output as ReactNode}</div>;\n\n if (typeof output === "object" && !isValidElement(output)) {\n Output = (\n <CodeBlock\n className={compactCodeBlockClassName}\n code={JSON.stringify(output, null, 2)}\n language="json"\n />\n );\n } else if (typeof output === "string") {\n Output = <CodeBlock className={compactCodeBlockClassName} code={output} language="json" />;\n }\n\n return (\n <div\n className={cn(\n "overflow-x-auto rounded-md text-xs [&_table]:w-full",\n errorText ? "bg-destructive/10 text-destructive" : "bg-muted/50 text-foreground",\n className,\n )}\n {...props}\n >\n <span className="block px-3 pt-3 font-sans text-[10px] text-muted-foreground uppercase tracking-wide">\n {errorText ? "Error" : "Result"}\n </span>\n {errorText && <div className="px-3 pt-2 pb-3">{errorText}</div>}\n {Output}\n </div>\n );\n};\n',
+ '"use client";\n\nimport { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";\nimport { cn } from "@/lib/utils";\nimport type { DynamicToolUIPart, ToolUIPart } from "ai";\nimport { ChevronRightIcon, TerminalIcon, WrenchIcon } from "lucide-react";\nimport type { ComponentProps, ReactNode } from "react";\nimport { isValidElement } from "react";\n\nimport { CodeBlock } from "./code-block";\n\nconst compactCodeBlockClassName =\n "rounded-none border-0 bg-transparent [&_pre]:!bg-transparent [&_pre]:px-3 [&_pre]:pt-2 [&_pre]:pb-3 [&_pre]:text-xs [&_code]:text-xs";\n\nexport type ToolProps = ComponentProps<typeof Collapsible>;\n\nexport const Tool = ({ className, ...props }: ToolProps) => (\n <Collapsible className={cn("group not-prose w-full", className)} {...props} />\n);\n\nexport type ToolPart = ToolUIPart | DynamicToolUIPart;\n\nexport type ToolHeaderProps = {\n title?: string;\n className?: string;\n} & (\n | { type: ToolUIPart["type"]; state: ToolUIPart["state"]; toolName?: never }\n | {\n type: DynamicToolUIPart["type"];\n state: DynamicToolUIPart["state"];\n toolName: string;\n }\n);\n\nconst statusLabels: Record<ToolPart["state"], string> = {\n "approval-requested": "Awaiting Approval",\n "approval-responded": "Responded",\n "input-available": "Running",\n "input-streaming": "Pending",\n "output-available": "Completed",\n "output-denied": "Denied",\n "output-error": "Error",\n};\n\nexport const getStatusIndicator = (status: ToolPart["state"]) =>\n status === "output-available" ? null : (\n <span className={cn("text-sm", status === "output-error" && "text-destructive")}>\n {statusLabels[status]}\n </span>\n );\n\nexport const ToolHeader = ({\n className,\n title,\n type,\n state,\n toolName,\n ...props\n}: ToolHeaderProps) => {\n const derivedName = type === "dynamic-tool" ? toolName : type.split("-").slice(1).join("-");\n const displayName = title ?? derivedName;\n\n return (\n <CollapsibleTrigger\n className={cn(\n "flex w-full items-center gap-2 py-0.5 text-left text-muted-foreground transition-colors hover:text-foreground",\n className,\n )}\n {...props}\n >\n {displayName === "bash" ? (\n <TerminalIcon className="size-4 shrink-0" />\n ) : (\n <WrenchIcon className="size-4 shrink-0" />\n )}\n <span className="text-sm">{displayName}</span>\n {getStatusIndicator(state)}\n <ChevronRightIcon className="size-3.5 shrink-0 transition-transform group-data-[state=open]:rotate-90" />\n </CollapsibleTrigger>\n );\n};\n\nexport type ToolContentProps = ComponentProps<typeof CollapsibleContent>;\n\nexport const ToolContent = ({ className, ...props }: ToolContentProps) => (\n <CollapsibleContent\n className={cn(\n "data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 space-y-4 py-2 text-popover-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",\n className,\n )}\n {...props}\n />\n);\n\nexport type BashToolContentProps = ComponentProps<"div"> & {\n input: ToolPart["input"];\n output: ToolPart["output"];\n errorText: ToolPart["errorText"];\n};\n\nexport const BashToolContent = ({\n className,\n input,\n output,\n errorText,\n ...props\n}: BashToolContentProps) => {\n const command = getRecordValue(input, "command");\n const stdout = getRecordValue(output, "stdout") ?? (typeof output === "string" ? output : "");\n const stderr = getRecordValue(output, "stderr") ?? errorText ?? "";\n const exitCode = getRecordValue(output, "exitCode");\n const hasResult = Boolean(stdout || stderr || (typeof exitCode === "number" && exitCode !== 0));\n\n return (\n <div className={cn("space-y-2", className)} {...props}>\n <pre className="overflow-x-auto whitespace-pre-wrap rounded-md bg-muted/50 p-3 font-mono text-xs leading-relaxed">\n <code>\n <span className="text-muted-foreground">$ </span>\n {command ?? "…"}\n </code>\n </pre>\n {hasResult ? (\n <pre className="overflow-x-auto whitespace-pre-wrap rounded-md bg-muted/50 p-3 font-mono text-xs leading-relaxed">\n <code>\n <span className="mb-2 block font-sans text-[10px] text-muted-foreground uppercase tracking-wide">\n Output\n </span>\n {stdout ? <span className="block">{String(stdout).trimEnd()}</span> : null}\n {stderr ? (\n <span className="block text-destructive">{String(stderr).trimEnd()}</span>\n ) : null}\n {typeof exitCode === "number" && exitCode !== 0 ? (\n <span className="block text-muted-foreground">Exited with code {exitCode}</span>\n ) : null}\n </code>\n </pre>\n ) : null}\n </div>\n );\n};\n\nconst getRecordValue = (value: unknown, key: string): string | number | undefined => {\n if (typeof value !== "object" || value === null || !(key in value)) {\n return undefined;\n }\n\n const property = value[key as keyof typeof value];\n return typeof property === "string" || typeof property === "number" ? property : undefined;\n};\n\nexport type ToolInputProps = ComponentProps<"div"> & {\n input: ToolPart["input"];\n};\n\nexport const ToolInput = ({ className, input, ...props }: ToolInputProps) => (\n <div className={cn("overflow-hidden rounded-md bg-muted/50", className)} {...props}>\n <span className="block px-3 pt-3 font-sans text-[10px] text-muted-foreground uppercase tracking-wide">\n Parameters\n </span>\n <div>\n <CodeBlock\n className={compactCodeBlockClassName}\n code={JSON.stringify(input, null, 2)}\n language="json"\n />\n </div>\n </div>\n);\n\nexport type ToolOutputProps = ComponentProps<"div"> & {\n output: ToolPart["output"];\n errorText: ToolPart["errorText"];\n};\n\nexport const ToolOutput = ({ className, output, errorText, ...props }: ToolOutputProps) => {\n if (!(output || errorText)) {\n return null;\n }\n\n let Output = <div>{output as ReactNode}</div>;\n\n if (typeof output === "object" && !isValidElement(output)) {\n Output = (\n <CodeBlock\n className={compactCodeBlockClassName}\n code={JSON.stringify(output, null, 2)}\n language="json"\n />\n );\n } else if (typeof output === "string") {\n Output = <CodeBlock className={compactCodeBlockClassName} code={output} language="json" />;\n }\n\n return (\n <div\n className={cn(\n "overflow-x-auto rounded-md text-xs [&_table]:w-full",\n errorText ? "bg-destructive/10 text-destructive" : "bg-muted/50 text-foreground",\n className,\n )}\n {...props}\n >\n <span className="block px-3 pt-3 font-sans text-[10px] text-muted-foreground uppercase tracking-wide">\n {errorText ? "Error" : "Result"}\n </span>\n {errorText && <div className="px-3 pt-2 pb-3">{errorText}</div>}\n {Output}\n </div>\n );\n};\n',
"components/ui/badge.tsx":
'import * as React from "react";\nimport { cva, type VariantProps } from "class-variance-authority";\nimport { Slot } from "radix-ui";\n\nimport { cn } from "@/lib/utils";\n\nconst badgeVariants = cva(\n "inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3",\n {\n variants: {\n variant: {\n default: "bg-primary text-primary-foreground [a&]:hover:bg-primary/90",\n secondary: "bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",\n destructive:\n "bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90",\n outline:\n "border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",\n ghost: "[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",\n link: "text-primary underline-offset-4 [a&]:hover:underline",\n },\n },\n defaultVariants: {\n variant: "default",\n },\n },\n);\n\nfunction Badge({\n className,\n variant = "default",\n asChild = false,\n ...props\n}: React.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & { asChild?: boolean }) {\n const Comp = asChild ? Slot.Root : "span";\n\n return (\n <Comp\n data-slot="badge"\n data-variant={variant}\n className={cn(badgeVariants({ variant }), className)}\n {...props}\n />\n );\n}\n\nexport { Badge, badgeVariants };\n',
"components/ui/button-group.tsx":