glchat-a2ui-react-renderer 0.3.4 → 0.3.5
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/src/components/a2ui/v0_8/UnknownComponent/UnknownComponent.js +1 -1
- package/dist/src/components/a2ui/v0_9/UnknownComponent/UnknownComponent.d.ts.map +1 -1
- package/dist/src/components/a2ui/v0_9/UnknownComponent/UnknownComponent.js +1 -1
- package/dist/src/v0_8/Provider.js +1 -1
- package/dist/src/v0_9/Provider.js +1 -1
- package/dist/src/v0_9/SurfaceErrorBoundary.d.ts +18 -0
- package/dist/src/v0_9/SurfaceErrorBoundary.d.ts.map +1 -0
- package/dist/src/v0_9/SurfaceErrorBoundary.js +24 -0
- package/dist/src/v0_9/SurfaceRenderer.d.ts.map +1 -1
- package/dist/src/v0_9/SurfaceRenderer.js +3 -2
- package/package.json +1 -1
|
@@ -9,5 +9,5 @@ export function CustomUnknownComponent({ node }) {
|
|
|
9
9
|
const type = node && typeof node === 'object' && 'type' in node && node.type != null
|
|
10
10
|
? String(node.type)
|
|
11
11
|
: 'unknown';
|
|
12
|
-
return (_jsx(InlineAlert, { role: "status", variant: "warning", message: `
|
|
12
|
+
return (_jsx(InlineAlert, { role: "status", variant: "warning", message: `Unknown A2UI component: ${type}` }));
|
|
13
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnknownComponent.d.ts","sourceRoot":"","sources":["../../../../../../src/components/a2ui/v0_9/UnknownComponent/UnknownComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"UnknownComponent.d.ts","sourceRoot":"","sources":["../../../../../../src/components/a2ui/v0_9/UnknownComponent/UnknownComponent.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;0BAwB8pZ,CAAC;;;;;;;;;;;;;;;;;;;0BAAivB,CAAC;;;;;;;;;;;;;;;;;;;;;;;0BAA2sB,CAAC;;;;;;;0BAA0O,CAAC;;;;;;;;;;;;;;;;;;;;;;;0BAA1qD,CAAC;;;;;;;;;;;;;;;;;;;0BAAivB,CAAC;;;;;;;;;;;;;;;;;;;;;;;0BAA2sB,CAAC;;;;;;;0BAA0O,CAAC;;;;;;;;;;;;;;;;;;;;;;;0BAA1qD,CAAC;;;;;;;;;;;;;;;;;;;0BAAivB,CAAC;;;;;;;;;;;;;;;;;;;;;;;0BAA2sB,CAAC;;;;;;;0BAA0O,CAAC;;;;;CAhBv2c,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,yDASpC,CAAC"}
|
|
@@ -21,4 +21,4 @@ export const UnknownComponentApi = {
|
|
|
21
21
|
* Renders a warning alert for unknown component types.
|
|
22
22
|
* Wired into catalogs via `installUnknownComponentFallback`.
|
|
23
23
|
*/
|
|
24
|
-
export const UnknownComponentFallback = createBinderlessComponentImplementation(UnknownComponentApi, ({ context }) => (_jsx(InlineAlert, { role: "status", variant: "warning", message: `
|
|
24
|
+
export const UnknownComponentFallback = createBinderlessComponentImplementation(UnknownComponentApi, ({ context }) => (_jsx(InlineAlert, { role: "status", variant: "warning", message: `Unknown A2UI component: ${context.componentModel.type}` })));
|
|
@@ -6,7 +6,7 @@ import { InlineAlert } from '../components/ui/InlineAlert/InlineAlert.js';
|
|
|
6
6
|
import { ensureGlchatComponentsRegistered } from './registry.js';
|
|
7
7
|
import { mergeGlchatTheme } from './theme.js';
|
|
8
8
|
const A2UIRegistryContext = createContext(null);
|
|
9
|
-
const PROCESS_ERROR_MESSAGE = '
|
|
9
|
+
const PROCESS_ERROR_MESSAGE = 'Failed to process A2UI messages (v0.8)';
|
|
10
10
|
function MessagesProcessor({ messages, onError, }) {
|
|
11
11
|
const { processMessages } = useA2UI();
|
|
12
12
|
const processedCountRef = useRef(0);
|
|
@@ -8,7 +8,7 @@ import { renderMarkdown } from '@a2ui/markdown-it';
|
|
|
8
8
|
import { InlineAlert } from '../components/ui/InlineAlert/InlineAlert.js';
|
|
9
9
|
import { createGlchatCatalog, GLCHAT_CATALOG_ID, installUnknownComponentFallback, withFallbackCatalogId, } from './catalog.js';
|
|
10
10
|
const SurfaceGroupContext = createContext(null);
|
|
11
|
-
const PROCESS_ERROR_MESSAGE = '
|
|
11
|
+
const PROCESS_ERROR_MESSAGE = 'Failed to process A2UI messages (v0.9)';
|
|
12
12
|
export function V09Provider({ messages, onAction, onError, catalog, children, }) {
|
|
13
13
|
const onActionRef = useRef(onAction);
|
|
14
14
|
const onErrorRef = useRef(onError);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
|
2
|
+
type SurfaceErrorBoundaryProps = Readonly<{
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
}>;
|
|
5
|
+
type SurfaceErrorBoundaryState = {
|
|
6
|
+
hasError: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Catches render errors from `@a2ui/react` catalog components.
|
|
10
|
+
*/
|
|
11
|
+
export declare class SurfaceErrorBoundary extends Component<SurfaceErrorBoundaryProps, SurfaceErrorBoundaryState> {
|
|
12
|
+
state: SurfaceErrorBoundaryState;
|
|
13
|
+
static getDerivedStateFromError(): SurfaceErrorBoundaryState;
|
|
14
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
15
|
+
render(): ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=SurfaceErrorBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SurfaceErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/v0_9/SurfaceErrorBoundary.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAMlE,KAAK,yBAAyB,GAAG,QAAQ,CAAC;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AACnE,KAAK,yBAAyB,GAAG;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAEvD;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS,CACjD,yBAAyB,EACzB,yBAAyB,CAC1B;IACC,KAAK,EAAE,yBAAyB,CAAuB;IAEvD,MAAM,CAAC,wBAAwB,IAAI,yBAAyB;IAI5D,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAKtD,MAAM,IAAI,SAAS;CAMpB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Component } from 'react';
|
|
4
|
+
import { InlineAlert } from '../components/ui/InlineAlert/InlineAlert.js';
|
|
5
|
+
const RENDER_ERROR_MESSAGE = 'Failed to render A2UI surface';
|
|
6
|
+
/**
|
|
7
|
+
* Catches render errors from `@a2ui/react` catalog components.
|
|
8
|
+
*/
|
|
9
|
+
export class SurfaceErrorBoundary extends Component {
|
|
10
|
+
state = { hasError: false };
|
|
11
|
+
static getDerivedStateFromError() {
|
|
12
|
+
return { hasError: true };
|
|
13
|
+
}
|
|
14
|
+
componentDidCatch(error, info) {
|
|
15
|
+
// eslint-disable-next-line no-console -- match Provider message-process logging
|
|
16
|
+
console.error('[glchat-a2ui] Failed to render v0.9 surface:', error, info.componentStack);
|
|
17
|
+
}
|
|
18
|
+
render() {
|
|
19
|
+
if (this.state.hasError) {
|
|
20
|
+
return _jsx(InlineAlert, { role: "alert", variant: "warning", message: RENDER_ERROR_MESSAGE });
|
|
21
|
+
}
|
|
22
|
+
return this.props.children;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SurfaceRenderer.d.ts","sourceRoot":"","sources":["../../../src/v0_9/SurfaceRenderer.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"SurfaceRenderer.d.ts","sourceRoot":"","sources":["../../../src/v0_9/SurfaceRenderer.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AA2DlE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC,+BAkCvE"}
|
|
@@ -4,9 +4,10 @@ import { useCallback, useSyncExternalStore } from 'react';
|
|
|
4
4
|
import { A2uiSurface } from '@a2ui/react/v0_9';
|
|
5
5
|
import { InlineAlert } from '../components/ui/InlineAlert/InlineAlert.js';
|
|
6
6
|
import { useSurfaceGroup } from './Provider.js';
|
|
7
|
+
import { SurfaceErrorBoundary } from './SurfaceErrorBoundary.js';
|
|
7
8
|
import { useSurfaces } from './useSurfaces.js';
|
|
8
9
|
const DEFAULT_FALLBACK = _jsx(_Fragment, {});
|
|
9
|
-
const ROOT_MISSING_MESSAGE = '
|
|
10
|
+
const ROOT_MISSING_MESSAGE = 'This A2UI interface could not be loaded because no root component was found.';
|
|
10
11
|
/** True when the surface has a `root` component (replace `@a2ui` "[Loading root...]"). */
|
|
11
12
|
function useHasRootComponent(surface) {
|
|
12
13
|
const subscribe = useCallback((onStoreChange) => {
|
|
@@ -27,7 +28,7 @@ function SurfaceView({ surface, className, fallback, hasMessages, }) {
|
|
|
27
28
|
return _jsx(_Fragment, { children: fallback });
|
|
28
29
|
return (_jsx("div", { className: className, children: _jsx(InlineAlert, { role: "alert", variant: "warning", message: ROOT_MISSING_MESSAGE }) }));
|
|
29
30
|
}
|
|
30
|
-
return (_jsx("div", { className: className, children: _jsx(A2uiSurface, { surface: surface }) }));
|
|
31
|
+
return (_jsx("div", { className: className, children: _jsx(SurfaceErrorBoundary, { children: _jsx(A2uiSurface, { surface: surface }) }) }));
|
|
31
32
|
}
|
|
32
33
|
export function V09SurfaceRenderer(props) {
|
|
33
34
|
const { model, hasMessages } = useSurfaceGroup();
|