glchat-a2ui-react-renderer 0.3.6 → 0.4.1
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/README.md +200 -267
- package/dist/index.d.ts +13 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -4
- package/dist/src/Provider.d.ts +33 -8
- package/dist/src/Provider.d.ts.map +1 -1
- package/dist/src/Provider.js +12 -10
- package/dist/src/SurfaceRenderer.d.ts +7 -1
- package/dist/src/SurfaceRenderer.d.ts.map +1 -1
- package/dist/src/SurfaceRenderer.js +2 -2
- package/dist/src/components/a2ui/v0_9/AudioPlayer/AudioPlayer.d.ts +1 -5
- package/dist/src/components/a2ui/v0_9/AudioPlayer/AudioPlayer.d.ts.map +1 -1
- package/dist/src/components/a2ui/v0_9/AudioPlayer/AudioPlayer.js +2 -12
- package/dist/src/components/a2ui/v0_9/Button/Button.d.ts +73 -239
- package/dist/src/components/a2ui/v0_9/Button/Button.d.ts.map +1 -1
- package/dist/src/components/a2ui/v0_9/Button/Button.js +2 -13
- package/dist/src/components/a2ui/v0_9/ChoicePicker/ChoicePicker.d.ts +1 -8
- package/dist/src/components/a2ui/v0_9/ChoicePicker/ChoicePicker.d.ts.map +1 -1
- package/dist/src/components/a2ui/v0_9/ChoicePicker/ChoicePicker.js +2 -51
- package/dist/src/components/a2ui/v0_9/TagInput/TagInput.d.ts +40 -196
- package/dist/src/components/a2ui/v0_9/TagInput/TagInput.d.ts.map +1 -1
- package/dist/src/components/a2ui/v0_9/TagInput/TagInput.js +3 -10
- package/dist/src/components/a2ui/v0_9/Timeout/Timeout.d.ts +24 -100
- package/dist/src/components/a2ui/v0_9/Timeout/Timeout.d.ts.map +1 -1
- package/dist/src/components/a2ui/v0_9/Timeout/Timeout.js +3 -23
- package/dist/src/components/a2ui/v0_9/common.d.ts +11 -57
- package/dist/src/components/a2ui/v0_9/common.d.ts.map +1 -1
- package/dist/src/components/a2ui/v0_9/common.js +0 -9
- package/dist/src/components/a2ui/v1_0/AudioPlayer/AudioPlayer.d.ts +3 -0
- package/dist/src/components/a2ui/v1_0/AudioPlayer/AudioPlayer.d.ts.map +1 -0
- package/dist/src/components/a2ui/v1_0/AudioPlayer/AudioPlayer.js +6 -0
- package/dist/src/components/a2ui/v1_0/Button/Button.d.ts +223 -0
- package/dist/src/components/a2ui/v1_0/Button/Button.d.ts.map +1 -0
- package/dist/src/components/a2ui/v1_0/Button/Button.js +26 -0
- package/dist/src/components/a2ui/v1_0/ChoicePicker/ChoicePicker.d.ts +3 -0
- package/dist/src/components/a2ui/v1_0/ChoicePicker/ChoicePicker.d.ts.map +1 -0
- package/dist/src/components/a2ui/v1_0/ChoicePicker/ChoicePicker.js +6 -0
- package/dist/src/components/a2ui/v1_0/TagInput/TagInput.d.ts +214 -0
- package/dist/src/components/a2ui/v1_0/TagInput/TagInput.d.ts.map +1 -0
- package/dist/src/components/a2ui/v1_0/TagInput/TagInput.js +34 -0
- package/dist/src/components/a2ui/v1_0/Timeout/Timeout.d.ts +58 -0
- package/dist/src/components/a2ui/v1_0/Timeout/Timeout.d.ts.map +1 -0
- package/dist/src/components/a2ui/v1_0/Timeout/Timeout.js +25 -0
- package/dist/src/components/a2ui/v1_0/common.d.ts +15 -0
- package/dist/src/components/a2ui/v1_0/common.d.ts.map +1 -0
- package/dist/src/components/a2ui/v1_0/common.js +16 -0
- package/dist/src/components/a2ui/views/AudioPlayer/AudioPlayer.d.ts +14 -0
- package/dist/src/components/a2ui/views/AudioPlayer/AudioPlayer.d.ts.map +1 -0
- package/dist/src/components/a2ui/views/AudioPlayer/AudioPlayer.js +10 -0
- package/dist/src/components/a2ui/views/Button/Button.d.ts +18 -0
- package/dist/src/components/a2ui/views/Button/Button.d.ts.map +1 -0
- package/dist/src/components/a2ui/views/Button/Button.js +22 -0
- package/dist/src/components/a2ui/views/ChoicePicker/ChoicePicker.d.ts +25 -0
- package/dist/src/components/a2ui/views/ChoicePicker/ChoicePicker.d.ts.map +1 -0
- package/dist/src/components/a2ui/views/ChoicePicker/ChoicePicker.js +46 -0
- package/dist/src/components/a2ui/views/ChoicePicker/theme.d.ts.map +1 -0
- package/dist/src/components/a2ui/views/TagInput/TagInput.d.ts +16 -0
- package/dist/src/components/a2ui/views/TagInput/TagInput.d.ts.map +1 -0
- package/dist/src/components/a2ui/views/TagInput/TagInput.js +12 -0
- package/dist/src/components/a2ui/views/Timeout/Timeout.d.ts +9 -0
- package/dist/src/components/a2ui/views/Timeout/Timeout.d.ts.map +1 -0
- package/dist/src/components/a2ui/views/Timeout/Timeout.js +27 -0
- package/dist/src/components/a2ui/views/weight.d.ts +7 -0
- package/dist/src/components/a2ui/views/weight.d.ts.map +1 -0
- package/dist/src/components/a2ui/views/weight.js +9 -0
- package/dist/src/core/SurfaceErrorBoundary.d.ts +27 -0
- package/dist/src/core/SurfaceErrorBoundary.d.ts.map +1 -0
- package/dist/src/core/SurfaceErrorBoundary.js +24 -0
- package/dist/src/core/SurfaceGroupProvider.d.ts +40 -0
- package/dist/src/core/SurfaceGroupProvider.d.ts.map +1 -0
- package/dist/src/core/SurfaceGroupProvider.js +142 -0
- package/dist/src/core/SurfaceRenderer.d.ts +4 -0
- package/dist/src/core/SurfaceRenderer.d.ts.map +1 -0
- package/dist/src/core/SurfaceRenderer.js +64 -0
- package/dist/src/core/errors.d.ts +44 -0
- package/dist/src/core/errors.d.ts.map +1 -0
- package/dist/src/core/errors.js +42 -0
- package/dist/src/core/types.d.ts +11 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +1 -0
- package/dist/src/core/unknownComponent.d.ts +28 -0
- package/dist/src/core/unknownComponent.d.ts.map +1 -0
- package/dist/src/core/unknownComponent.js +41 -0
- package/dist/src/{v0_9 → core}/useSurfaces.d.ts +3 -3
- package/dist/src/core/useSurfaces.d.ts.map +1 -0
- package/dist/src/utils/detectVersion.d.ts +4 -2
- package/dist/src/utils/detectVersion.d.ts.map +1 -1
- package/dist/src/utils/detectVersion.js +5 -1
- package/dist/src/v0_8/Provider.d.ts +2 -1
- package/dist/src/v0_8/Provider.d.ts.map +1 -1
- package/dist/src/v0_8/Provider.js +3 -8
- package/dist/src/v0_9/Provider.d.ts +13 -13
- package/dist/src/v0_9/Provider.d.ts.map +1 -1
- package/dist/src/v0_9/Provider.js +14 -61
- package/dist/src/v0_9/catalog.d.ts +2 -8
- package/dist/src/v0_9/catalog.d.ts.map +1 -1
- package/dist/src/v0_9/catalog.js +3 -17
- package/dist/src/v1_0/Provider.d.ts +27 -0
- package/dist/src/v1_0/Provider.d.ts.map +1 -0
- package/dist/src/v1_0/Provider.js +35 -0
- package/dist/src/v1_0/catalog.d.ts +52 -0
- package/dist/src/v1_0/catalog.d.ts.map +1 -0
- package/dist/src/v1_0/catalog.js +118 -0
- package/dist/src/v1_0/types.d.ts +13 -0
- package/dist/src/v1_0/types.d.ts.map +1 -0
- package/dist/src/v1_0/types.js +1 -0
- package/json/README.md +27 -30
- package/json/v0_9/glchat_standard_catalog_definition.json +5 -5
- package/json/v1_0/a2ui-sample-messages-extension.json +150 -0
- package/json/v1_0/a2ui-sample-messages.json +144 -0
- package/json/v1_0/glchat_extension_catalog_definition.json +794 -0
- package/json/v1_0/glchat_standard_catalog_definition.json +1487 -0
- package/package.json +4 -4
- package/styles/globals.css +136 -67
- package/dist/src/components/a2ui/v0_9/ChoicePicker/theme.d.ts.map +0 -1
- package/dist/src/components/a2ui/v0_9/UnknownComponent/UnknownComponent.d.ts +0 -231
- package/dist/src/components/a2ui/v0_9/UnknownComponent/UnknownComponent.d.ts.map +0 -1
- package/dist/src/components/a2ui/v0_9/UnknownComponent/UnknownComponent.js +0 -24
- package/dist/src/v0_9/SurfaceErrorBoundary.d.ts +0 -18
- package/dist/src/v0_9/SurfaceErrorBoundary.d.ts.map +0 -1
- package/dist/src/v0_9/SurfaceErrorBoundary.js +0 -24
- package/dist/src/v0_9/SurfaceRenderer.d.ts +0 -3
- package/dist/src/v0_9/SurfaceRenderer.d.ts.map +0 -1
- package/dist/src/v0_9/SurfaceRenderer.js +0 -47
- package/dist/src/v0_9/useSurfaces.d.ts.map +0 -1
- /package/dist/src/components/a2ui/{v0_9 → views}/ChoicePicker/theme.d.ts +0 -0
- /package/dist/src/components/a2ui/{v0_9 → views}/ChoicePicker/theme.js +0 -0
- /package/dist/src/{v0_9 → core}/useSurfaces.js +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Component, type ReactNode } from 'react';
|
|
2
|
+
import { type A2UIError } from './errors.js';
|
|
3
|
+
type SurfaceErrorBoundaryProps = Readonly<{
|
|
4
|
+
surfaceId: string;
|
|
5
|
+
/** Reports the render error to the host. */
|
|
6
|
+
report: (error: A2UIError) => void;
|
|
7
|
+
/** Renders the error UI. */
|
|
8
|
+
renderError: (error: A2UIError) => ReactNode;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}>;
|
|
11
|
+
type SurfaceErrorBoundaryState = {
|
|
12
|
+
failed: boolean;
|
|
13
|
+
cause: unknown;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Catches render errors from `@a2ui/react` catalog components, so one broken
|
|
17
|
+
* surface does not unmount the host tree.
|
|
18
|
+
*/
|
|
19
|
+
export declare class SurfaceErrorBoundary extends Component<SurfaceErrorBoundaryProps, SurfaceErrorBoundaryState> {
|
|
20
|
+
state: SurfaceErrorBoundaryState;
|
|
21
|
+
static getDerivedStateFromError(cause: unknown): SurfaceErrorBoundaryState;
|
|
22
|
+
private toError;
|
|
23
|
+
componentDidCatch(): void;
|
|
24
|
+
render(): ReactNode;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=SurfaceErrorBoundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SurfaceErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/core/SurfaceErrorBoundary.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE1D,KAAK,yBAAyB,GAAG,QAAQ,CAAC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,MAAM,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACnC,4BAA4B;IAC5B,WAAW,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC;IAC7C,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC,CAAC;AACH,KAAK,yBAAyB,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAErE;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,SAAS,CACjD,yBAAyB,EACzB,yBAAyB,CAC1B;IACC,KAAK,EAAE,yBAAyB,CAAuC;IAEvE,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,yBAAyB;IAI1E,OAAO,CAAC,OAAO;IAIf,iBAAiB,IAAI,IAAI;IAIzB,MAAM,IAAI,SAAS;CAIpB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
import { createError } from './errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* Catches render errors from `@a2ui/react` catalog components, so one broken
|
|
6
|
+
* surface does not unmount the host tree.
|
|
7
|
+
*/
|
|
8
|
+
export class SurfaceErrorBoundary extends Component {
|
|
9
|
+
state = { failed: false, cause: undefined };
|
|
10
|
+
static getDerivedStateFromError(cause) {
|
|
11
|
+
return { failed: true, cause };
|
|
12
|
+
}
|
|
13
|
+
toError() {
|
|
14
|
+
return createError('RENDER_FAILED', 'render', this.state.cause, this.props.surfaceId);
|
|
15
|
+
}
|
|
16
|
+
componentDidCatch() {
|
|
17
|
+
this.props.report(this.toError());
|
|
18
|
+
}
|
|
19
|
+
render() {
|
|
20
|
+
if (this.state.failed)
|
|
21
|
+
return this.props.renderError(this.toError());
|
|
22
|
+
return this.props.children;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PropsWithChildren } from 'react';
|
|
2
|
+
import { type ReactCatalogComponent } from '@a2ui/react';
|
|
3
|
+
import type { MessageProcessor, SurfaceGroupModel } from '@a2ui/web_core';
|
|
4
|
+
import { type V09Message, type V1Message } from '../utils/detectVersion.js';
|
|
5
|
+
import { type A2UIError, type A2UIErrorHandler } from './errors.js';
|
|
6
|
+
import type { ActionOptions } from './types.js';
|
|
7
|
+
/** Protocol versions handled by the shared (v0.9+) message pipeline. */
|
|
8
|
+
export type SurfaceGroupVersion = 'v0.9' | 'v1.0';
|
|
9
|
+
/** Messages handled by the shared (v0.9+) message pipeline. */
|
|
10
|
+
export type SurfaceGroupMessage = V09Message | V1Message;
|
|
11
|
+
export type SurfaceGroupProviderProps<A, M extends SurfaceGroupMessage> = {
|
|
12
|
+
/** Processor built by the version provider (catalogs, version options). */
|
|
13
|
+
processor: MessageProcessor<ReactCatalogComponent>;
|
|
14
|
+
/** Only this version's messages are processed. */
|
|
15
|
+
version: SurfaceGroupVersion;
|
|
16
|
+
/** Optional rewrite of new messages before processing (e.g. catalog ID fallback). */
|
|
17
|
+
prepareMessages?: (messages: M[]) => M[];
|
|
18
|
+
messages?: M[];
|
|
19
|
+
onAction?: (action: A, options?: ActionOptions) => void | Promise<void>;
|
|
20
|
+
onError?: A2UIErrorHandler;
|
|
21
|
+
};
|
|
22
|
+
type SurfaceGroupContextValue = {
|
|
23
|
+
model: SurfaceGroupModel<ReactCatalogComponent>;
|
|
24
|
+
hasMessages: boolean;
|
|
25
|
+
/** The upstream processor, e.g. for `processor.callAgentFunction(...)` (v1.0). */
|
|
26
|
+
processor: MessageProcessor<ReactCatalogComponent>;
|
|
27
|
+
/** Processing errors by surface ID; the renderer shows them in place of the surface. */
|
|
28
|
+
surfaceErrors: ReadonlyMap<string, A2UIError>;
|
|
29
|
+
/** Reports an error to the host (`onError`, or a short console line). */
|
|
30
|
+
report: (error: A2UIError) => void;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Version-neutral message processing and surface state for A2UI v0.9 and v1.0.
|
|
34
|
+
* The version providers (`V09Provider`, `V1Provider`) build the processor;
|
|
35
|
+
* this component feeds it messages, forwards actions and reports errors.
|
|
36
|
+
*/
|
|
37
|
+
export declare function SurfaceGroupProvider<A, M extends SurfaceGroupMessage>({ processor, version, prepareMessages, messages, onAction, onError, children, }: Readonly<PropsWithChildren<SurfaceGroupProviderProps<A, M>>>): import("react").JSX.Element;
|
|
38
|
+
export declare function useSurfaceGroup(): SurfaceGroupContextValue;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=SurfaceGroupProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SurfaceGroupProvider.d.ts","sourceRoot":"","sources":["../../../src/core/SurfaceGroupProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAW/C,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAI1E,OAAO,EAAwB,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,wEAAwE;AACxE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,CAAC;AAElD,+DAA+D;AAC/D,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,SAAS,CAAC;AAEzD,MAAM,MAAM,yBAAyB,CAAC,CAAC,EAAE,CAAC,SAAS,mBAAmB,IAAI;IACxE,2EAA2E;IAC3E,SAAS,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IACnD,kDAAkD;IAClD,OAAO,EAAE,mBAAmB,CAAC;IAC7B,qFAAqF;IACrF,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;IACzC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,CAAC;IAChD,WAAW,EAAE,OAAO,CAAC;IACrB,kFAAkF;IAClF,SAAS,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IACnD,wFAAwF;IACxF,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9C,yEAAyE;IACzE,MAAM,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;CACpC,CAAC;AAeF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,CAAC,SAAS,mBAAmB,EAAE,EACrE,SAAS,EACT,OAAO,EACP,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,QAAQ,GACT,EAAE,QAAQ,CAAC,iBAAiB,CAAC,yBAAyB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,+BAuI9D;AAED,wBAAgB,eAAe,IAAI,wBAAwB,CAI1D"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
4
|
+
import { MarkdownContext } from '@a2ui/react';
|
|
5
|
+
import { renderMarkdown } from '@a2ui/markdown-it';
|
|
6
|
+
import { InlineAlert } from '../components/ui/InlineAlert/InlineAlert.js';
|
|
7
|
+
import { detectMessageVersion } from '../utils/detectVersion.js';
|
|
8
|
+
import { errorText, reportError, toProcessError, } from './errors.js';
|
|
9
|
+
const SurfaceGroupContext = createContext(null);
|
|
10
|
+
const WIRE_VERSION = { 'v0.9': 'v0.9', 'v1.0': '1.0' };
|
|
11
|
+
/** Surface whose content a message (re)defines; a success there clears its error. */
|
|
12
|
+
function definedSurfaceId(message) {
|
|
13
|
+
const body = message.createSurface ??
|
|
14
|
+
message.updateComponents;
|
|
15
|
+
const surfaceId = body?.surfaceId;
|
|
16
|
+
return typeof surfaceId === 'string' ? surfaceId : undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Version-neutral message processing and surface state for A2UI v0.9 and v1.0.
|
|
20
|
+
* The version providers (`V09Provider`, `V1Provider`) build the processor;
|
|
21
|
+
* this component feeds it messages, forwards actions and reports errors.
|
|
22
|
+
*/
|
|
23
|
+
export function SurfaceGroupProvider({ processor, version, prepareMessages, messages, onAction, onError, children, }) {
|
|
24
|
+
const onActionRef = useRef(onAction);
|
|
25
|
+
const onErrorRef = useRef(onError);
|
|
26
|
+
const processingRef = useRef(false);
|
|
27
|
+
const [surfaceErrors, setSurfaceErrors] = useState(new Map());
|
|
28
|
+
const [groupError, setGroupError] = useState(null);
|
|
29
|
+
const hasMessages = !!messages?.length;
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
onActionRef.current = onAction;
|
|
32
|
+
}, [onAction]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
onErrorRef.current = onError;
|
|
35
|
+
}, [onError]);
|
|
36
|
+
const report = useCallback((error) => reportError(error, onErrorRef.current), []);
|
|
37
|
+
const processedCountRef = useRef(0);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const subscription = processor.model.onAction.subscribe((action) => {
|
|
40
|
+
// `sendDataModel` surfaces: attach their current data models to the action.
|
|
41
|
+
const dataModel = processor.getRendererDataModel();
|
|
42
|
+
void onActionRef.current?.(action, dataModel ? { dataModel } : undefined);
|
|
43
|
+
});
|
|
44
|
+
return () => subscription.unsubscribe();
|
|
45
|
+
}, [processor]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
// Upstream errors after rendering (bindings, function calls, actions). It
|
|
48
|
+
// also emits processing failures here; those are reported from the catch
|
|
49
|
+
// below instead, so skip events raised while processing.
|
|
50
|
+
const errors = processor.model.onError.subscribe((payload) => {
|
|
51
|
+
if (processingRef.current)
|
|
52
|
+
return;
|
|
53
|
+
report({
|
|
54
|
+
code: payload.code,
|
|
55
|
+
source: 'runtime',
|
|
56
|
+
message: payload.message,
|
|
57
|
+
surfaceId: payload.surfaceId,
|
|
58
|
+
cause: payload,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
const deleted = processor.model.onSurfaceDeleted.subscribe((surfaceId) => {
|
|
62
|
+
setSurfaceErrors((current) => {
|
|
63
|
+
if (!current.has(surfaceId))
|
|
64
|
+
return current;
|
|
65
|
+
const next = new Map(current);
|
|
66
|
+
next.delete(surfaceId);
|
|
67
|
+
return next;
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
return () => {
|
|
71
|
+
errors.unsubscribe();
|
|
72
|
+
deleted.unsubscribe();
|
|
73
|
+
};
|
|
74
|
+
}, [processor, report]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!messages?.length)
|
|
77
|
+
return;
|
|
78
|
+
if (messages.length < processedCountRef.current) {
|
|
79
|
+
processedCountRef.current = 0;
|
|
80
|
+
}
|
|
81
|
+
if (processedCountRef.current >= messages.length)
|
|
82
|
+
return;
|
|
83
|
+
// web_core >= 0.12 processes every protocol version (and fails on catalogs
|
|
84
|
+
// it does not have). Version routing/mismatch is owned by the top-level
|
|
85
|
+
// Provider, so only feed this processor messages of its own version.
|
|
86
|
+
const ownVersion = messages.slice(processedCountRef.current).filter((message) => {
|
|
87
|
+
const messageVersion = detectMessageVersion(message);
|
|
88
|
+
return messageVersion === null || messageVersion === version;
|
|
89
|
+
});
|
|
90
|
+
const pending = prepareMessages ? prepareMessages(ownVersion) : ownVersion;
|
|
91
|
+
processedCountRef.current = messages.length;
|
|
92
|
+
// One message at a time: a rejected message does not drop the ones after it.
|
|
93
|
+
const failed = new Map();
|
|
94
|
+
const succeeded = new Set();
|
|
95
|
+
let latestGroupError = null;
|
|
96
|
+
for (const message of pending) {
|
|
97
|
+
const surfaceId = definedSurfaceId(message);
|
|
98
|
+
processingRef.current = true;
|
|
99
|
+
try {
|
|
100
|
+
processor.processMessages([message]);
|
|
101
|
+
latestGroupError = null;
|
|
102
|
+
if (surfaceId) {
|
|
103
|
+
succeeded.add(surfaceId);
|
|
104
|
+
failed.delete(surfaceId);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (caught) {
|
|
108
|
+
const error = toProcessError(caught, message, WIRE_VERSION[version]);
|
|
109
|
+
if (error.surfaceId) {
|
|
110
|
+
failed.set(error.surfaceId, error);
|
|
111
|
+
succeeded.delete(error.surfaceId);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
latestGroupError = error;
|
|
115
|
+
}
|
|
116
|
+
report(error);
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
processingRef.current = false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
setGroupError(latestGroupError);
|
|
123
|
+
if (failed.size || succeeded.size) {
|
|
124
|
+
setSurfaceErrors((current) => {
|
|
125
|
+
const next = new Map(current);
|
|
126
|
+
for (const id of succeeded)
|
|
127
|
+
next.delete(id);
|
|
128
|
+
for (const [id, error] of failed)
|
|
129
|
+
next.set(id, error);
|
|
130
|
+
return next;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}, [messages, processor, prepareMessages, version, report]);
|
|
134
|
+
const contextValue = useMemo(() => ({ model: processor.model, hasMessages, processor, surfaceErrors, report }), [processor, hasMessages, surfaceErrors, report]);
|
|
135
|
+
return (_jsx(SurfaceGroupContext.Provider, { value: contextValue, children: _jsxs(MarkdownContext.Provider, { value: renderMarkdown, children: [groupError ? (_jsx("div", { className: "a2ui-surface", children: _jsx(InlineAlert, { role: "alert", variant: "warning", children: errorText(groupError) }) })) : null, children] }) }));
|
|
136
|
+
}
|
|
137
|
+
export function useSurfaceGroup() {
|
|
138
|
+
const ctx = useContext(SurfaceGroupContext);
|
|
139
|
+
if (!ctx)
|
|
140
|
+
throw new Error('useSurfaceGroup must be used inside Provider (v0.9 or v1.0)');
|
|
141
|
+
return ctx;
|
|
142
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SurfaceRendererProps } from '../SurfaceRenderer.js';
|
|
2
|
+
/** Renders surfaces of the shared v0.9 / v1.0 pipeline. */
|
|
3
|
+
export declare function CoreSurfaceRenderer(props: Readonly<SurfaceRendererProps>): import("react").JSX.Element;
|
|
4
|
+
//# sourceMappingURL=SurfaceRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SurfaceRenderer.d.ts","sourceRoot":"","sources":["../../../src/core/SurfaceRenderer.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAoElE,2DAA2D;AAC3D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC,+BAqDxE"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
4
|
+
import { A2uiSurface } from '@a2ui/react';
|
|
5
|
+
import { InlineAlert } from '../components/ui/InlineAlert/InlineAlert.js';
|
|
6
|
+
import { errorText } from './errors.js';
|
|
7
|
+
import { SurfaceErrorBoundary } from './SurfaceErrorBoundary.js';
|
|
8
|
+
import { useSurfaceGroup } from './SurfaceGroupProvider.js';
|
|
9
|
+
import { useSurfaces } from './useSurfaces.js';
|
|
10
|
+
const DEFAULT_FALLBACK = _jsx(_Fragment, {});
|
|
11
|
+
/** True when the surface has a `root` component (replace `@a2ui` "[Loading root...]"). */
|
|
12
|
+
function useHasRootComponent(surface) {
|
|
13
|
+
const subscribe = useCallback((onStoreChange) => {
|
|
14
|
+
const created = surface.componentsModel.onCreated.subscribe(() => onStoreChange());
|
|
15
|
+
const deleted = surface.componentsModel.onDeleted.subscribe(() => onStoreChange());
|
|
16
|
+
return () => {
|
|
17
|
+
created.unsubscribe();
|
|
18
|
+
deleted.unsubscribe();
|
|
19
|
+
};
|
|
20
|
+
}, [surface]);
|
|
21
|
+
const getSnapshot = useCallback(() => surface.componentsModel.get('root') != null, [surface]);
|
|
22
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
23
|
+
}
|
|
24
|
+
function DefaultError({ error }) {
|
|
25
|
+
return (_jsx(InlineAlert, { role: "alert", variant: "warning", children: errorText(error) }));
|
|
26
|
+
}
|
|
27
|
+
function SurfaceView({ surface, className, fallback, renderError, }) {
|
|
28
|
+
const { report } = useSurfaceGroup();
|
|
29
|
+
const hasRoot = useHasRootComponent(surface);
|
|
30
|
+
// No root yet and nothing failed: the surface is still loading (streaming).
|
|
31
|
+
if (!hasRoot)
|
|
32
|
+
return _jsx(_Fragment, { children: fallback });
|
|
33
|
+
return (_jsx("div", { className: className, children: _jsx(SurfaceErrorBoundary, { surfaceId: surface.id, report: report, renderError: renderError, children: _jsx(A2uiSurface, { surface: surface }) }, surface.id) }));
|
|
34
|
+
}
|
|
35
|
+
/** Renders surfaces of the shared v0.9 / v1.0 pipeline. */
|
|
36
|
+
export function CoreSurfaceRenderer(props) {
|
|
37
|
+
const { model, surfaceErrors } = useSurfaceGroup();
|
|
38
|
+
const surfaces = useSurfaces(model);
|
|
39
|
+
const fallback = props.fallback ?? DEFAULT_FALLBACK;
|
|
40
|
+
const surfaceClassName = props.className ? `a2ui-surface ${props.className}` : 'a2ui-surface';
|
|
41
|
+
const { errorFallback } = props;
|
|
42
|
+
const renderError = useCallback((error) => {
|
|
43
|
+
if (errorFallback === undefined)
|
|
44
|
+
return _jsx(DefaultError, { error: error });
|
|
45
|
+
return typeof errorFallback === 'function' ? errorFallback(error) : errorFallback;
|
|
46
|
+
}, [errorFallback]);
|
|
47
|
+
const renderSurface = (surfaceId, surface) => {
|
|
48
|
+
const error = surfaceErrors.get(surfaceId);
|
|
49
|
+
if (error) {
|
|
50
|
+
return (_jsx("div", { className: surfaceClassName, children: renderError(error) }, surfaceId));
|
|
51
|
+
}
|
|
52
|
+
if (!surface)
|
|
53
|
+
return _jsx(_Fragment, { children: fallback });
|
|
54
|
+
return (_jsx(SurfaceView, { surface: surface, className: surfaceClassName, fallback: fallback, renderError: renderError }, surfaceId));
|
|
55
|
+
};
|
|
56
|
+
if (props.surfaceId !== undefined) {
|
|
57
|
+
return renderSurface(props.surfaceId, model.getSurface(props.surfaceId));
|
|
58
|
+
}
|
|
59
|
+
// Surfaces that failed before they were created (e.g. unknown catalog) still show their error.
|
|
60
|
+
const failedOnly = [...surfaceErrors.keys()].filter((id) => !model.getSurface(id));
|
|
61
|
+
if (surfaces.length === 0 && failedOnly.length === 0)
|
|
62
|
+
return _jsx(_Fragment, { children: fallback });
|
|
63
|
+
return (_jsxs(_Fragment, { children: [surfaces.map((surface) => renderSurface(surface.id, surface)), failedOnly.map((id) => renderSurface(id, undefined))] }));
|
|
64
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Where in the pipeline an error happened. */
|
|
2
|
+
export type A2UIErrorSource =
|
|
3
|
+
/** An A2UI message was rejected while processing (schema, catalog, integrity, …). */
|
|
4
|
+
'process'
|
|
5
|
+
/** A component threw while rendering. */
|
|
6
|
+
| 'render'
|
|
7
|
+
/** Upstream reported an error after rendering (binding, function call, action). */
|
|
8
|
+
| 'runtime'
|
|
9
|
+
/** Messages switched protocol version after the Provider locked one. */
|
|
10
|
+
| 'version';
|
|
11
|
+
/** Error reported to `onError` and shown by the renderer. */
|
|
12
|
+
export type A2UIError = {
|
|
13
|
+
/**
|
|
14
|
+
* Machine-readable code. Error code coming from:
|
|
15
|
+
* - `@a2ui/web_core` (e.g. `VALIDATION_FAILED`, `CATALOG_NOT_FOUND`, `INTEGRITY_ERROR`)
|
|
16
|
+
* - renderer addons (e.g. `RENDER_FAILED` and `VERSION_MISMATCH`).
|
|
17
|
+
*/
|
|
18
|
+
code: string;
|
|
19
|
+
source: A2UIErrorSource;
|
|
20
|
+
/** Developer-facing description; serializable, safe to log. */
|
|
21
|
+
message: string;
|
|
22
|
+
/** Surface the error belongs to, when known. */
|
|
23
|
+
surfaceId?: string;
|
|
24
|
+
/** JSON Pointer to the offending field, when known (e.g. `/components/1/text`). */
|
|
25
|
+
path?: string;
|
|
26
|
+
/** The original thrown value, for debugging. */
|
|
27
|
+
cause: unknown;
|
|
28
|
+
};
|
|
29
|
+
export type A2UIErrorHandler = (error: A2UIError) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Builds an `A2UIError` for a message that failed to process, using upstream's
|
|
32
|
+
* spec error mapping (code, surfaceId, path).
|
|
33
|
+
*/
|
|
34
|
+
export declare function toProcessError(error: unknown, rawMessage: unknown, version: string): A2UIError;
|
|
35
|
+
/** Builds an `A2UIError` for errors the renderer itself raises. */
|
|
36
|
+
export declare function createError(code: string, source: A2UIErrorSource, cause: unknown, surfaceId?: string): A2UIError;
|
|
37
|
+
/**
|
|
38
|
+
* Sends the error to the host's `onError`.
|
|
39
|
+
* Without one, logs a single short line (no stack).
|
|
40
|
+
*/
|
|
41
|
+
export declare function reportError(error: A2UIError, onError: A2UIErrorHandler | undefined): void;
|
|
42
|
+
/** Default end-user text for an error, e.g. in the inline alert. */
|
|
43
|
+
export declare function errorText(error: Pick<A2UIError, 'code'>): string;
|
|
44
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/core/errors.ts"],"names":[],"mappings":"AAEA,+CAA+C;AAC/C,MAAM,MAAM,eAAe;AACzB,qFAAqF;AACnF,SAAS;AACX,yCAAyC;GACvC,QAAQ;AACV,mFAAmF;GACjF,SAAS;AACX,wEAAwE;GACtE,SAAS,CAAC;AAEd,6DAA6D;AAC7D,MAAM,MAAM,SAAS,GAAG;IACtB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;AAM1D;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAa9F;AAED,mEAAmE;AACnE,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,MAAM,GACjB,SAAS,CAEX;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,QAUlF;AAED,oEAAoE;AACpE,wBAAgB,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,MAAM,CAEhE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { extractEnvelopeErrorContext, mapErrorToRendererMessage } from '@a2ui/web_core';
|
|
2
|
+
function messageOf(error) {
|
|
3
|
+
return error instanceof Error ? error.message : String(error);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Builds an `A2UIError` for a message that failed to process, using upstream's
|
|
7
|
+
* spec error mapping (code, surfaceId, path).
|
|
8
|
+
*/
|
|
9
|
+
export function toProcessError(error, rawMessage, version) {
|
|
10
|
+
const { error: body } = mapErrorToRendererMessage(error, extractEnvelopeErrorContext(rawMessage, version));
|
|
11
|
+
return {
|
|
12
|
+
code: body.code,
|
|
13
|
+
source: 'process',
|
|
14
|
+
message: messageOf(error),
|
|
15
|
+
surfaceId: body.surfaceId || undefined,
|
|
16
|
+
path: body.path || undefined,
|
|
17
|
+
cause: error,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Builds an `A2UIError` for errors the renderer itself raises. */
|
|
21
|
+
export function createError(code, source, cause, surfaceId) {
|
|
22
|
+
return { code, source, message: messageOf(cause), surfaceId, cause };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sends the error to the host's `onError`.
|
|
26
|
+
* Without one, logs a single short line (no stack).
|
|
27
|
+
*/
|
|
28
|
+
export function reportError(error, onError) {
|
|
29
|
+
if (onError) {
|
|
30
|
+
onError(error);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const where = [error.surfaceId && `surface "${error.surfaceId}"`, error.path]
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.join(', ');
|
|
36
|
+
// eslint-disable-next-line no-console -- single-line fallback when the host has no onError
|
|
37
|
+
console.warn(`[glchat-a2ui] ${error.code}${where ? ` (${where})` : ''}: ${error.message}`);
|
|
38
|
+
}
|
|
39
|
+
/** Default end-user text for an error, e.g. in the inline alert. */
|
|
40
|
+
export function errorText(error) {
|
|
41
|
+
return `Unable to display this content. (${error.code})`;
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data models of the surfaces created with `sendDataModel: true`, keyed by
|
|
3
|
+
* surface ID: `{ version, surfaces: { [surfaceId]: data } }`.
|
|
4
|
+
*/
|
|
5
|
+
export type RendererDataModel = Record<string, unknown>;
|
|
6
|
+
/** Extra information sent with an action. */
|
|
7
|
+
export type ActionOptions = {
|
|
8
|
+
/** Present only when at least one surface set `sendDataModel: true`. */
|
|
9
|
+
dataModel?: RendererDataModel;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD,6CAA6C;AAC7C,MAAM,MAAM,aAAa,GAAG;IAC1B,wEAAwE;IACxE,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ReactCatalogComponent } from '@a2ui/react';
|
|
2
|
+
import type { Catalog } from '@a2ui/web_core/v0_9';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* Fallback API used when a message references a component type that is not
|
|
6
|
+
* registered in the active catalog. Properties are accepted but ignored.
|
|
7
|
+
*/
|
|
8
|
+
export declare const UnknownComponentApi: {
|
|
9
|
+
name: string;
|
|
10
|
+
schema: z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Renders a warning alert for unknown component types.
|
|
14
|
+
* Wired into catalogs via `installUnknownComponentFallback`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const UnknownComponentFallback: import("@a2ui/react").ReactComponentImplementation<z.ZodTypeAny>;
|
|
17
|
+
/**
|
|
18
|
+
* Makes `catalog.components.get(type)` return the warning fallback when the
|
|
19
|
+
* type is not registered, so unknown components render an alert instead of
|
|
20
|
+
* `@a2ui/react`'s red placeholder. Works for v0.9 and v1.0 catalogs.
|
|
21
|
+
*
|
|
22
|
+
* The fallback is also registered as a real entry: since @a2ui/react 0.13,
|
|
23
|
+
* `A2uiSurface` wraps every registered React entry as a custom element (with
|
|
24
|
+
* a `tagName`) so Lit basic components (Column, Row, …) can host it. Looking
|
|
25
|
+
* the fallback up through the map returns that wrapped entry.
|
|
26
|
+
*/
|
|
27
|
+
export declare function installUnknownComponentFallback(catalog: Catalog<ReactCatalogComponent>): void;
|
|
28
|
+
//# sourceMappingURL=unknownComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unknownComponent.d.ts","sourceRoot":"","sources":["../../../src/core/unknownComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA2C,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;CAM/B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,kEAOpC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAW7F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createBinderlessComponentImplementation } from '@a2ui/react';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { InlineAlert } from '../components/ui/InlineAlert/InlineAlert.js';
|
|
6
|
+
/**
|
|
7
|
+
* Fallback API used when a message references a component type that is not
|
|
8
|
+
* registered in the active catalog. Properties are accepted but ignored.
|
|
9
|
+
*/
|
|
10
|
+
export const UnknownComponentApi = {
|
|
11
|
+
name: '__UnknownComponent__',
|
|
12
|
+
schema: z
|
|
13
|
+
.object({})
|
|
14
|
+
.passthrough()
|
|
15
|
+
.describe('Placeholder for an unsupported or unregistered A2UI component.'),
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Renders a warning alert for unknown component types.
|
|
19
|
+
* Wired into catalogs via `installUnknownComponentFallback`.
|
|
20
|
+
*/
|
|
21
|
+
export const UnknownComponentFallback = createBinderlessComponentImplementation(UnknownComponentApi, ({ context }) => (_jsx(InlineAlert, { role: "status", variant: "warning", children: `Unknown A2UI component: ${context.componentModel.type}` })));
|
|
22
|
+
/**
|
|
23
|
+
* Makes `catalog.components.get(type)` return the warning fallback when the
|
|
24
|
+
* type is not registered, so unknown components render an alert instead of
|
|
25
|
+
* `@a2ui/react`'s red placeholder. Works for v0.9 and v1.0 catalogs.
|
|
26
|
+
*
|
|
27
|
+
* The fallback is also registered as a real entry: since @a2ui/react 0.13,
|
|
28
|
+
* `A2uiSurface` wraps every registered React entry as a custom element (with
|
|
29
|
+
* a `tagName`) so Lit basic components (Column, Row, …) can host it. Looking
|
|
30
|
+
* the fallback up through the map returns that wrapped entry.
|
|
31
|
+
*/
|
|
32
|
+
export function installUnknownComponentFallback(catalog) {
|
|
33
|
+
const map = catalog.components;
|
|
34
|
+
if (map.__glchatUnknownFallback) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const originalGet = map.get.bind(map);
|
|
38
|
+
map.set(UnknownComponentFallback.name, UnknownComponentFallback);
|
|
39
|
+
map.get = ((name) => originalGet(name) ?? originalGet(UnknownComponentFallback.name));
|
|
40
|
+
map.__glchatUnknownFallback = true;
|
|
41
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { SurfaceGroupModel, SurfaceModel } from '@a2ui/web_core
|
|
1
|
+
import type { ReactCatalogComponent } from '@a2ui/react';
|
|
2
|
+
import type { SurfaceGroupModel, SurfaceModel } from '@a2ui/web_core';
|
|
3
3
|
/**
|
|
4
4
|
* Subscribes to surface creation/deletion on a `SurfaceGroupModel` and returns
|
|
5
5
|
* the current list of surfaces. The returned array is referentially stable
|
|
6
6
|
* until the set of surfaces changes, so it is safe for `useSyncExternalStore`.
|
|
7
7
|
*/
|
|
8
|
-
export declare function useSurfaces(model: SurfaceGroupModel<
|
|
8
|
+
export declare function useSurfaces(model: SurfaceGroupModel<ReactCatalogComponent>): SurfaceModel<ReactCatalogComponent>[];
|
|
9
9
|
//# sourceMappingURL=useSurfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSurfaces.d.ts","sourceRoot":"","sources":["../../../src/core/useSurfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGtE;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,GAC9C,YAAY,CAAC,qBAAqB,CAAC,EAAE,CA6BvC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { A2uiMessage } from '@a2ui/web_core/v0_9';
|
|
2
2
|
import type { ServerToClientMessage } from '@a2ui/web_core/v0_8';
|
|
3
|
-
|
|
3
|
+
import type { AgentToRendererMessage } from '@a2ui/web_core/v1_0';
|
|
4
|
+
export type A2UIVersion = 'v0.8' | 'v0.9' | 'v1.0';
|
|
4
5
|
export type V08Message = ServerToClientMessage;
|
|
5
6
|
export type V09Message = A2uiMessage;
|
|
6
|
-
export type
|
|
7
|
+
export type V1Message = AgentToRendererMessage;
|
|
8
|
+
export type A2UIMessage = V08Message | V09Message | V1Message;
|
|
7
9
|
export declare function detectMessageVersion(message: A2UIMessage): A2UIVersion | null;
|
|
8
10
|
export declare function detectMessagesVersion(messages: A2UIMessage[]): A2UIVersion | null;
|
|
9
11
|
//# sourceMappingURL=detectVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectVersion.d.ts","sourceRoot":"","sources":["../../../src/utils/detectVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"detectVersion.d.ts","sourceRoot":"","sources":["../../../src/utils/detectVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAElE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AASnD,MAAM,MAAM,UAAU,GAAG,qBAAqB,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC;AACrC,MAAM,MAAM,SAAS,GAAG,sBAAsB,CAAC;AAC/C,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;AAE9D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAiB7E;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,WAAW,GAAG,IAAI,CAMjF"}
|
|
@@ -7,10 +7,14 @@ const V08_MESSAGE_KEYS = [
|
|
|
7
7
|
export function detectMessageVersion(message) {
|
|
8
8
|
if (message && typeof message === 'object' && 'version' in message) {
|
|
9
9
|
const version = message.version;
|
|
10
|
-
|
|
10
|
+
// v0.9.1 is a wire-compatible revision handled by the same v0.9 processor.
|
|
11
|
+
if (version === 'v0.9' || version === 'v0.9.1')
|
|
11
12
|
return 'v0.9';
|
|
12
13
|
if (version === 'v0.8')
|
|
13
14
|
return 'v0.8';
|
|
15
|
+
// v1.0 envelopes use the bare `"1.0"`; web_core also accepts `"v1.0"`.
|
|
16
|
+
if (version === '1.0' || version === 'v1.0')
|
|
17
|
+
return 'v1.0';
|
|
14
18
|
}
|
|
15
19
|
for (const key of V08_MESSAGE_KEYS) {
|
|
16
20
|
if (key in message) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { PropsWithChildren } from 'react';
|
|
2
2
|
import { ComponentRegistry, type A2UIClientEventMessage } from '@a2ui/react/v0_8';
|
|
3
3
|
import type { Theme } from '@a2ui/web_core/v0_8';
|
|
4
|
+
import { type A2UIErrorHandler } from '../core/errors.js';
|
|
4
5
|
import type { V08Message } from '../utils/detectVersion.js';
|
|
5
6
|
export type V08ActionPayload = NonNullable<A2UIClientEventMessage['userAction']>;
|
|
6
7
|
export type V08ActionHandler = (action: V08ActionPayload) => void | Promise<void>;
|
|
7
|
-
export type V08MessageErrorHandler =
|
|
8
|
+
export type V08MessageErrorHandler = A2UIErrorHandler;
|
|
8
9
|
export type V08ProviderProps = {
|
|
9
10
|
messages?: V08Message[];
|
|
10
11
|
theme?: Theme;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../src/v0_8/Provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAW/C,OAAO,EAEL,iBAAiB,EAEjB,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAyB,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAGxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAI5D,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC;AACjF,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAClF,MAAM,MAAM,sBAAsB,GAAG,
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../src/v0_8/Provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAW/C,OAAO,EAEL,iBAAiB,EAEjB,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAyB,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAGxE,OAAO,EAAuC,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAI5D,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC;AACjF,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAClF,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AAEtD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC9B,CAAC;AAkDF,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,OAAO,EACP,QAAQ,EAAE,YAAY,EACtB,QAAQ,GACT,EAAE,QAAQ,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC,+BAgC/C;AAED,wBAAgB,eAAe,IAAI,iBAAiB,CAInD"}
|
|
@@ -3,10 +3,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
4
4
|
import { A2UIProvider, ComponentRegistry, useA2UI, } from '@a2ui/react/v0_8';
|
|
5
5
|
import { InlineAlert } from '../components/ui/InlineAlert/InlineAlert.js';
|
|
6
|
+
import { createError, errorText, reportError } from '../core/errors.js';
|
|
6
7
|
import { ensureGlchatComponentsRegistered } from './registry.js';
|
|
7
8
|
import { mergeGlchatTheme } from './theme.js';
|
|
8
9
|
const A2UIRegistryContext = createContext(null);
|
|
9
|
-
const PROCESS_ERROR_MESSAGE =
|
|
10
|
+
const PROCESS_ERROR_MESSAGE = errorText({ code: 'PROCESSING_FAILED' });
|
|
10
11
|
function MessagesProcessor({ messages, onError, }) {
|
|
11
12
|
const { processMessages } = useA2UI();
|
|
12
13
|
const processedCountRef = useRef(0);
|
|
@@ -28,13 +29,7 @@ function MessagesProcessor({ messages, onError, }) {
|
|
|
28
29
|
}
|
|
29
30
|
catch (error) {
|
|
30
31
|
setProcessError(PROCESS_ERROR_MESSAGE);
|
|
31
|
-
|
|
32
|
-
onError(error);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
// eslint-disable-next-line no-console
|
|
36
|
-
console.error('[glchat-a2ui] Failed to process v0.8 messages:', error);
|
|
37
|
-
}
|
|
32
|
+
reportError(createError('PROCESSING_FAILED', 'process', error), onError);
|
|
38
33
|
}
|
|
39
34
|
}, [messages, onError, processMessages]);
|
|
40
35
|
if (!processError)
|