-
Notifications
You must be signed in to change notification settings - Fork 158
feat(ui): add A2A error extension #1655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * Copyright 2025 © BeeAI a Series of LF Projects, LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import z from 'zod'; | ||
|
|
||
| import type { A2AUiExtension } from '../types'; | ||
|
|
||
| const URI = 'https://a2a-extensions.agentstack.beeai.dev/ui/error/v1'; | ||
|
|
||
| const errorSchema = z.object({ | ||
| title: z.string(), | ||
| message: z.string(), | ||
| }); | ||
|
|
||
| const errorGroupSchema = z.object({ | ||
| message: z.string(), | ||
| errors: z.array(errorSchema), | ||
| }); | ||
|
|
||
| const schema = z.object({ | ||
| error: z.union([errorSchema, errorGroupSchema]), | ||
| context: z.record(z.string(), z.unknown()).nullish(), | ||
| stack_trace: z.string().nullish(), | ||
| }); | ||
|
|
||
| export type ErrorMetadata = z.infer<typeof schema>; | ||
|
|
||
| export const errorExtension: A2AUiExtension<typeof URI, ErrorMetadata> = { | ||
| getMessageMetadataSchema: () => z.object({ [URI]: schema }).partial(), | ||
| getUri: () => URI, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ interface Props { | |
| className?: string; | ||
| buttonClassName?: string; | ||
| useBlockElement?: boolean; | ||
| autoExpandOnContentChange?: boolean; | ||
| } | ||
|
|
||
| export function LineClampText({ | ||
|
|
@@ -27,16 +28,18 @@ export function LineClampText({ | |
| className, | ||
| buttonClassName, | ||
| useBlockElement, | ||
| autoExpandOnContentChange, | ||
| children, | ||
| }: PropsWithChildren<Props>) { | ||
| const id = useId(); | ||
| const textRef = useRef<HTMLDivElement>(null); | ||
| const sentinelRef = useRef<HTMLSpanElement>(null); | ||
| const initialOverflowRef = useRef<boolean | null>(null); | ||
|
|
||
| const [isExpanded, setIsExpanded] = useState(false); | ||
| const [overflowDetected, setOverflowDetected] = useState(false); | ||
|
|
||
| const showButton = isExpanded || overflowDetected; | ||
| const showButton = (isExpanded || overflowDetected) && (initialOverflowRef.current ?? true); | ||
|
||
|
|
||
| const Component = useBlockElement ? 'div' : 'span'; | ||
| const buttonProps = { | ||
|
|
@@ -56,7 +59,17 @@ export function LineClampText({ | |
|
|
||
| const observer = new IntersectionObserver( | ||
| ([entry]) => { | ||
| setOverflowDetected(!entry.isIntersecting); | ||
| const isOverflowing = !entry.isIntersecting; | ||
|
|
||
| setOverflowDetected(isOverflowing); | ||
|
|
||
| if (initialOverflowRef.current === null) { | ||
| initialOverflowRef.current = isOverflowing; | ||
| } | ||
|
|
||
| if (autoExpandOnContentChange && initialOverflowRef.current === false && isOverflowing) { | ||
| setIsExpanded(true); | ||
| } | ||
| }, | ||
| { | ||
| root: textElement, | ||
|
|
@@ -69,7 +82,7 @@ export function LineClampText({ | |
| return () => { | ||
| observer.disconnect(); | ||
| }; | ||
| }, [isExpanded]); | ||
| }, [autoExpandOnContentChange, isExpanded]); | ||
|
|
||
| return ( | ||
| <Component className={clsx(classes.root, className)}> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.