@lynx-js/genui 0.0.1-rc.0
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/LICENSE +202 -0
- package/README.md +170 -0
- package/a2ui/README.md +140 -0
- package/a2ui/dist/catalog/Button/catalog.json +156 -0
- package/a2ui/dist/catalog/Button/index.d.ts +35 -0
- package/a2ui/dist/catalog/Button/index.js +35 -0
- package/a2ui/dist/catalog/Button/index.js.map +1 -0
- package/a2ui/dist/catalog/Card/catalog.json +24 -0
- package/a2ui/dist/catalog/Card/index.d.ts +11 -0
- package/a2ui/dist/catalog/Card/index.js +19 -0
- package/a2ui/dist/catalog/Card/index.js.map +1 -0
- package/a2ui/dist/catalog/CheckBox/catalog.json +170 -0
- package/a2ui/dist/catalog/CheckBox/index.d.ts +32 -0
- package/a2ui/dist/catalog/CheckBox/index.js +24 -0
- package/a2ui/dist/catalog/CheckBox/index.js.map +1 -0
- package/a2ui/dist/catalog/Column/catalog.json +57 -0
- package/a2ui/dist/catalog/Column/index.d.ts +15 -0
- package/a2ui/dist/catalog/Column/index.js +55 -0
- package/a2ui/dist/catalog/Column/index.js.map +1 -0
- package/a2ui/dist/catalog/Divider/catalog.json +14 -0
- package/a2ui/dist/catalog/Divider/index.d.ts +9 -0
- package/a2ui/dist/catalog/Divider/index.js +8 -0
- package/a2ui/dist/catalog/Divider/index.js.map +1 -0
- package/a2ui/dist/catalog/Icon/catalog.json +45 -0
- package/a2ui/dist/catalog/Icon/index.d.ts +14 -0
- package/a2ui/dist/catalog/Icon/index.js +11 -0
- package/a2ui/dist/catalog/Icon/index.js.map +1 -0
- package/a2ui/dist/catalog/Image/catalog.json +62 -0
- package/a2ui/dist/catalog/Image/index.d.ts +16 -0
- package/a2ui/dist/catalog/Image/index.js +30 -0
- package/a2ui/dist/catalog/Image/index.js.map +1 -0
- package/a2ui/dist/catalog/LineChart/catalog.json +98 -0
- package/a2ui/dist/catalog/LineChart/index.d.ts +31 -0
- package/a2ui/dist/catalog/LineChart/index.js +195 -0
- package/a2ui/dist/catalog/LineChart/index.js.map +1 -0
- package/a2ui/dist/catalog/List/catalog.json +52 -0
- package/a2ui/dist/catalog/List/index.d.ts +15 -0
- package/a2ui/dist/catalog/List/index.js +53 -0
- package/a2ui/dist/catalog/List/index.js.map +1 -0
- package/a2ui/dist/catalog/Modal/catalog.json +18 -0
- package/a2ui/dist/catalog/Modal/index.d.ts +12 -0
- package/a2ui/dist/catalog/Modal/index.js +33 -0
- package/a2ui/dist/catalog/Modal/index.js.map +1 -0
- package/a2ui/dist/catalog/PieChart/catalog.json +87 -0
- package/a2ui/dist/catalog/PieChart/index.d.ts +37 -0
- package/a2ui/dist/catalog/PieChart/index.js +131 -0
- package/a2ui/dist/catalog/PieChart/index.js.map +1 -0
- package/a2ui/dist/catalog/RadioGroup/catalog.json +184 -0
- package/a2ui/dist/catalog/RadioGroup/index.d.ts +36 -0
- package/a2ui/dist/catalog/RadioGroup/index.js +36 -0
- package/a2ui/dist/catalog/RadioGroup/index.js.map +1 -0
- package/a2ui/dist/catalog/Row/catalog.json +57 -0
- package/a2ui/dist/catalog/Row/index.d.ts +15 -0
- package/a2ui/dist/catalog/Row/index.js +28 -0
- package/a2ui/dist/catalog/Row/index.js.map +1 -0
- package/a2ui/dist/catalog/Slider/catalog.json +183 -0
- package/a2ui/dist/catalog/Slider/index.d.ts +41 -0
- package/a2ui/dist/catalog/Slider/index.js +39 -0
- package/a2ui/dist/catalog/Slider/index.js.map +1 -0
- package/a2ui/dist/catalog/Slider/utils.d.ts +11 -0
- package/a2ui/dist/catalog/Slider/utils.js +58 -0
- package/a2ui/dist/catalog/Slider/utils.js.map +1 -0
- package/a2ui/dist/catalog/Tabs/catalog.json +28 -0
- package/a2ui/dist/catalog/Tabs/index.d.ts +12 -0
- package/a2ui/dist/catalog/Tabs/index.js +32 -0
- package/a2ui/dist/catalog/Tabs/index.js.map +1 -0
- package/a2ui/dist/catalog/Text/catalog.json +74 -0
- package/a2ui/dist/catalog/Text/index.d.ts +18 -0
- package/a2ui/dist/catalog/Text/index.js +27 -0
- package/a2ui/dist/catalog/Text/index.js.map +1 -0
- package/a2ui/dist/catalog/TextField/catalog.json +147 -0
- package/a2ui/dist/catalog/TextField/index.d.ts +35 -0
- package/a2ui/dist/catalog/TextField/index.js +43 -0
- package/a2ui/dist/catalog/TextField/index.js.map +1 -0
- package/a2ui/dist/catalog/TextField/utils.d.ts +7 -0
- package/a2ui/dist/catalog/TextField/utils.js +51 -0
- package/a2ui/dist/catalog/TextField/utils.js.map +1 -0
- package/a2ui/dist/catalog/defineCatalog.d.ts +119 -0
- package/a2ui/dist/catalog/defineCatalog.js +196 -0
- package/a2ui/dist/catalog/defineCatalog.js.map +1 -0
- package/a2ui/dist/catalog/index.d.ts +20 -0
- package/a2ui/dist/catalog/index.js +26 -0
- package/a2ui/dist/catalog/index.js.map +1 -0
- package/a2ui/dist/catalog/utils/chart.d.ts +3 -0
- package/a2ui/dist/catalog/utils/chart.js +28 -0
- package/a2ui/dist/catalog/utils/chart.js.map +1 -0
- package/a2ui/dist/functions/index.d.ts +19 -0
- package/a2ui/dist/functions/index.js +87 -0
- package/a2ui/dist/functions/index.js.map +1 -0
- package/a2ui/dist/index.d.ts +11 -0
- package/a2ui/dist/index.js +35 -0
- package/a2ui/dist/index.js.map +1 -0
- package/a2ui/dist/react/A2UI.d.ts +77 -0
- package/a2ui/dist/react/A2UI.js +159 -0
- package/a2ui/dist/react/A2UI.js.map +1 -0
- package/a2ui/dist/react/A2UIProvider.d.ts +25 -0
- package/a2ui/dist/react/A2UIProvider.js +20 -0
- package/a2ui/dist/react/A2UIProvider.js.map +1 -0
- package/a2ui/dist/react/A2UIRenderer.d.ts +34 -0
- package/a2ui/dist/react/A2UIRenderer.js +161 -0
- package/a2ui/dist/react/A2UIRenderer.js.map +1 -0
- package/a2ui/dist/react/FormContext.d.ts +10 -0
- package/a2ui/dist/react/FormContext.js +12 -0
- package/a2ui/dist/react/FormContext.js.map +1 -0
- package/a2ui/dist/react/index.d.ts +8 -0
- package/a2ui/dist/react/index.js +23 -0
- package/a2ui/dist/react/index.js.map +1 -0
- package/a2ui/dist/react/useA2UIContext.d.ts +7 -0
- package/a2ui/dist/react/useA2UIContext.js +19 -0
- package/a2ui/dist/react/useA2UIContext.js.map +1 -0
- package/a2ui/dist/react/useAction.d.ts +9 -0
- package/a2ui/dist/react/useAction.js +38 -0
- package/a2ui/dist/react/useAction.js.map +1 -0
- package/a2ui/dist/react/useCatalog.d.ts +7 -0
- package/a2ui/dist/react/useCatalog.js +13 -0
- package/a2ui/dist/react/useCatalog.js.map +1 -0
- package/a2ui/dist/react/useChecks.d.ts +27 -0
- package/a2ui/dist/react/useChecks.js +76 -0
- package/a2ui/dist/react/useChecks.js.map +1 -0
- package/a2ui/dist/react/useDataBinding.d.ts +10 -0
- package/a2ui/dist/react/useDataBinding.js +175 -0
- package/a2ui/dist/react/useDataBinding.js.map +1 -0
- package/a2ui/dist/store/FormController.d.ts +23 -0
- package/a2ui/dist/store/FormController.js +40 -0
- package/a2ui/dist/store/FormController.js.map +1 -0
- package/a2ui/dist/store/FunctionRegistry.d.ts +47 -0
- package/a2ui/dist/store/FunctionRegistry.js +23 -0
- package/a2ui/dist/store/FunctionRegistry.js.map +1 -0
- package/a2ui/dist/store/MessageProcessor.d.ts +28 -0
- package/a2ui/dist/store/MessageProcessor.js +408 -0
- package/a2ui/dist/store/MessageProcessor.js.map +1 -0
- package/a2ui/dist/store/MessageStore.d.ts +38 -0
- package/a2ui/dist/store/MessageStore.js +37 -0
- package/a2ui/dist/store/MessageStore.js.map +1 -0
- package/a2ui/dist/store/Resource.d.ts +45 -0
- package/a2ui/dist/store/Resource.js +80 -0
- package/a2ui/dist/store/Resource.js.map +1 -0
- package/a2ui/dist/store/SignalStore.d.ts +10 -0
- package/a2ui/dist/store/SignalStore.js +29 -0
- package/a2ui/dist/store/SignalStore.js.map +1 -0
- package/a2ui/dist/store/index.d.ts +14 -0
- package/a2ui/dist/store/index.js +15 -0
- package/a2ui/dist/store/index.js.map +1 -0
- package/a2ui/dist/store/payloadNormalizer.d.ts +27 -0
- package/a2ui/dist/store/payloadNormalizer.js +179 -0
- package/a2ui/dist/store/payloadNormalizer.js.map +1 -0
- package/a2ui/dist/store/resolveFunctionCall.d.ts +18 -0
- package/a2ui/dist/store/resolveFunctionCall.js +131 -0
- package/a2ui/dist/store/resolveFunctionCall.js.map +1 -0
- package/a2ui/dist/store/types.d.ts +68 -0
- package/a2ui/dist/store/types.js +2 -0
- package/a2ui/dist/store/types.js.map +1 -0
- package/a2ui/dist/tsconfig.build.tsbuildinfo +1 -0
- package/a2ui/styles/catalog/Button.css +83 -0
- package/a2ui/styles/catalog/Card.css +49 -0
- package/a2ui/styles/catalog/CheckBox.css +46 -0
- package/a2ui/styles/catalog/Column.css +89 -0
- package/a2ui/styles/catalog/Divider.css +20 -0
- package/a2ui/styles/catalog/Icon.css +39 -0
- package/a2ui/styles/catalog/Image.css +54 -0
- package/a2ui/styles/catalog/LineChart.css +116 -0
- package/a2ui/styles/catalog/List.css +38 -0
- package/a2ui/styles/catalog/Modal.css +60 -0
- package/a2ui/styles/catalog/PieChart.css +109 -0
- package/a2ui/styles/catalog/RadioGroup.css +123 -0
- package/a2ui/styles/catalog/Row.css +83 -0
- package/a2ui/styles/catalog/Slider.css +96 -0
- package/a2ui/styles/catalog/Tabs.css +46 -0
- package/a2ui/styles/catalog/Text.css +121 -0
- package/a2ui/styles/catalog/TextField.css +48 -0
- package/a2ui/styles/theme.css +62 -0
- package/a2ui-catalog-extractor/README.md +605 -0
- package/a2ui-catalog-extractor/bin/a2ui-catalog-extractor.js +6 -0
- package/a2ui-catalog-extractor/dist/cli.d.ts +12 -0
- package/a2ui-catalog-extractor/dist/cli.js +171 -0
- package/a2ui-catalog-extractor/dist/cli.js.map +1 -0
- package/a2ui-catalog-extractor/dist/index.d.ts +140 -0
- package/a2ui-catalog-extractor/dist/index.js +755 -0
- package/a2ui-catalog-extractor/dist/index.js.map +1 -0
- package/a2ui-catalog-extractor/dist/tsconfig.build.tsbuildinfo +1 -0
- package/a2ui-catalog-extractor/skills/a2ui-catalog-extractor/SKILL.md +30 -0
- package/a2ui-prompt/README.md +65 -0
- package/a2ui-prompt/dist/index.d.ts +91 -0
- package/a2ui-prompt/dist/index.js +767 -0
- package/cli/README.md +88 -0
- package/cli/bin/cli.js +271 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/index.ts +114 -0
- package/openui/README.md +211 -0
- package/openui/dist/catalog/Action/index.d.ts +20 -0
- package/openui/dist/catalog/Action/index.js +23 -0
- package/openui/dist/catalog/Action/index.js.map +1 -0
- package/openui/dist/catalog/Button/index.d.ts +64 -0
- package/openui/dist/catalog/Button/index.js +75 -0
- package/openui/dist/catalog/Button/index.js.map +1 -0
- package/openui/dist/catalog/Card/index.d.ts +34 -0
- package/openui/dist/catalog/Card/index.js +69 -0
- package/openui/dist/catalog/Card/index.js.map +1 -0
- package/openui/dist/catalog/CardHeader/index.d.ts +5 -0
- package/openui/dist/catalog/CardHeader/index.js +18 -0
- package/openui/dist/catalog/CardHeader/index.js.map +1 -0
- package/openui/dist/catalog/Separator/index.d.ts +2 -0
- package/openui/dist/catalog/Separator/index.js +13 -0
- package/openui/dist/catalog/Separator/index.js.map +1 -0
- package/openui/dist/catalog/Stack/index.d.ts +29 -0
- package/openui/dist/catalog/Stack/index.js +61 -0
- package/openui/dist/catalog/Stack/index.js.map +1 -0
- package/openui/dist/catalog/Tag/index.d.ts +4 -0
- package/openui/dist/catalog/Tag/index.js +15 -0
- package/openui/dist/catalog/Tag/index.js.map +1 -0
- package/openui/dist/catalog/TextContent/index.d.ts +11 -0
- package/openui/dist/catalog/TextContent/index.js +33 -0
- package/openui/dist/catalog/TextContent/index.js.map +1 -0
- package/openui/dist/catalog/index.d.ts +7 -0
- package/openui/dist/catalog/index.js +11 -0
- package/openui/dist/catalog/index.js.map +1 -0
- package/openui/dist/catalog/utils.d.ts +2 -0
- package/openui/dist/catalog/utils.js +17 -0
- package/openui/dist/catalog/utils.js.map +1 -0
- package/openui/dist/core/context.d.ts +112 -0
- package/openui/dist/core/context.js +99 -0
- package/openui/dist/core/context.js.map +1 -0
- package/openui/dist/core/createLibrary.d.ts +10 -0
- package/openui/dist/core/createLibrary.js +36 -0
- package/openui/dist/core/createLibrary.js.map +1 -0
- package/openui/dist/core/hooks/index.d.ts +4 -0
- package/openui/dist/core/hooks/index.js +6 -0
- package/openui/dist/core/hooks/index.js.map +1 -0
- package/openui/dist/core/hooks/useFormValidation.d.ts +13 -0
- package/openui/dist/core/hooks/useFormValidation.js +76 -0
- package/openui/dist/core/hooks/useFormValidation.js.map +1 -0
- package/openui/dist/core/hooks/useOpenUIState.d.ts +33 -0
- package/openui/dist/core/hooks/useOpenUIState.js +413 -0
- package/openui/dist/core/hooks/useOpenUIState.js.map +1 -0
- package/openui/dist/core/hooks/useStateField.d.ts +2 -0
- package/openui/dist/core/hooks/useStateField.js +11 -0
- package/openui/dist/core/hooks/useStateField.js.map +1 -0
- package/openui/dist/core/index.d.ts +7 -0
- package/openui/dist/core/index.js +8 -0
- package/openui/dist/core/index.js.map +1 -0
- package/openui/dist/core/library.d.ts +20 -0
- package/openui/dist/core/library.js +13 -0
- package/openui/dist/core/library.js.map +1 -0
- package/openui/dist/core/renderer.css +271 -0
- package/openui/dist/core/renderer.d.ts +9 -0
- package/openui/dist/core/renderer.js +139 -0
- package/openui/dist/core/renderer.js.map +1 -0
- package/openui/dist/core/utils.d.ts +1 -0
- package/openui/dist/core/utils.js +76 -0
- package/openui/dist/core/utils.js.map +1 -0
- package/package.json +120 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { batch, signal } from '@preact/signals';
|
|
5
|
+
export class SignalStore {
|
|
6
|
+
signals = new Map();
|
|
7
|
+
getSignal(path, initialValue) {
|
|
8
|
+
let s = this.signals.get(path);
|
|
9
|
+
if (!s) {
|
|
10
|
+
s = signal(initialValue);
|
|
11
|
+
this.signals.set(path, s);
|
|
12
|
+
}
|
|
13
|
+
return s;
|
|
14
|
+
}
|
|
15
|
+
update(path, value) {
|
|
16
|
+
const s = this.getSignal(path);
|
|
17
|
+
if (s.value !== value) {
|
|
18
|
+
s.value = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
updateBatch(updates) {
|
|
22
|
+
batch(() => {
|
|
23
|
+
for (const { path, value } of updates) {
|
|
24
|
+
this.update(path, value);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=SignalStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignalStore.js","sourceRoot":"","sources":["../../src/store/SignalStore.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGhD,MAAM,OAAO,WAAW;IACd,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;IAErD,SAAS,CAAC,IAAY,EAAE,YAAsB;QAC5C,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,CAAC,EAAE,CAAC;YACP,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;YACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,CAAC,IAAY,EAAE,KAAc;QACjC,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;YACtB,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;QAClB,CAAC;IACH,CAAC;IAED,WAAW,CAAC,OAA2C;QACrD,KAAK,CAAC,GAAG,EAAE;YACT,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,OAAO,EAAE,CAAC;gBACtC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createMessageStore } from './MessageStore.js';
|
|
2
|
+
export type { MessageStore, MessageStoreOptions } from './MessageStore.js';
|
|
3
|
+
export { MessageProcessor } from './MessageProcessor.js';
|
|
4
|
+
export type { A2UIEvent } from './MessageProcessor.js';
|
|
5
|
+
export { createResource } from './Resource.js';
|
|
6
|
+
export type { Resource as RawResource, ResourceStatus } from './Resource.js';
|
|
7
|
+
export { SignalStore } from './SignalStore.js';
|
|
8
|
+
export { createFallbackMessagesFromPlainText, createTextCardMessages, normalizePayloadToMessages, prepareMessagesForProcessing, } from './payloadNormalizer.js';
|
|
9
|
+
export type { A2UIClientEventMessage, ComponentInstance, GenericComponentProps, Resource, ResourceInfo, ServerToClientMessage, Surface, SurfaceId, UserActionPayload, } from './types.js';
|
|
10
|
+
export { FunctionRegistry, functionRegistry } from './FunctionRegistry.js';
|
|
11
|
+
export type { FunctionEntry, FunctionImpl } from './FunctionRegistry.js';
|
|
12
|
+
export type { FunctionCallContext } from './FunctionRegistry.js';
|
|
13
|
+
export { executeFunctionCall, isDataBinding, isFunctionCall, resolveDynamicValue, resolveFunctionArguments, } from './resolveFunctionCall.js';
|
|
14
|
+
export type { ResolveFunctionOptions } from './resolveFunctionCall.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
export { createMessageStore } from './MessageStore.js';
|
|
5
|
+
export { MessageProcessor } from './MessageProcessor.js';
|
|
6
|
+
export { createResource } from './Resource.js';
|
|
7
|
+
export { SignalStore } from './SignalStore.js';
|
|
8
|
+
export { createFallbackMessagesFromPlainText, createTextCardMessages, normalizePayloadToMessages, prepareMessagesForProcessing, } from './payloadNormalizer.js';
|
|
9
|
+
export { FunctionRegistry, functionRegistry } from './FunctionRegistry.js';
|
|
10
|
+
// `createFormController` + `FormController` are intentionally not exported.
|
|
11
|
+
// `useChecks` uses them internally to keep the door open for a follow-up
|
|
12
|
+
// `<Form>` component, but they aren't public API until that consumer
|
|
13
|
+
// lands and validates the shape.
|
|
14
|
+
export { executeFunctionCall, isDataBinding, isFunctionCall, resolveDynamicValue, resolveFunctionArguments, } from './resolveFunctionCall.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,mCAAmC,EACnC,sBAAsB,EACtB,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAYhC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG3E,4EAA4E;AAC5E,yEAAyE;AACzE,qEAAqE;AACrE,iCAAiC;AACjC,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ServerToClientMessage } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build a single-Text fallback message stream from a plain string. Used by
|
|
4
|
+
* transports / `Session.ingest` callers that receive free-form text from
|
|
5
|
+
* the agent instead of structured protocol messages.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createFallbackMessagesFromPlainText(text: string): ServerToClientMessage[];
|
|
8
|
+
/**
|
|
9
|
+
* Build a Card-wrapped Text fallback message stream from a plain string.
|
|
10
|
+
* Used when the agent emits text payloads with `kind: 'text'`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createTextCardMessages(text: string): ServerToClientMessage[];
|
|
13
|
+
/**
|
|
14
|
+
* Normalize an arbitrary payload (string, array, object) into a flat list of
|
|
15
|
+
* `ServerToClientMessage` records. Pass-through for already-structured
|
|
16
|
+
* messages; falls back to wrapping plain text in a Text/Card surface.
|
|
17
|
+
*/
|
|
18
|
+
export declare function normalizePayloadToMessages(payload: unknown): ServerToClientMessage[];
|
|
19
|
+
/**
|
|
20
|
+
* Tag messages with the given messageId and report whether any of them
|
|
21
|
+
* carries a non-empty `updateComponents`. Also dedupes `createSurface`
|
|
22
|
+
* messages against the set of currently-active surfaces.
|
|
23
|
+
*/
|
|
24
|
+
export declare function prepareMessagesForProcessing(rawMessages: ServerToClientMessage[], messageId: string, activeSurfaceIds: Set<string>): {
|
|
25
|
+
messages: ServerToClientMessage[];
|
|
26
|
+
hasComponentUpdate: boolean;
|
|
27
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
function randomId(prefix = '') {
|
|
2
|
+
return prefix + Date.now().toString(36)
|
|
3
|
+
+ Math.random().toString(36).slice(2, 10);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Build a single-Text fallback message stream from a plain string. Used by
|
|
7
|
+
* transports / `Session.ingest` callers that receive free-form text from
|
|
8
|
+
* the agent instead of structured protocol messages.
|
|
9
|
+
*/
|
|
10
|
+
export function createFallbackMessagesFromPlainText(text) {
|
|
11
|
+
const surfaceId = 'default';
|
|
12
|
+
const rootId = 'root-text';
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
createSurface: {
|
|
16
|
+
surfaceId,
|
|
17
|
+
catalogId: 'inline-text',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
updateComponents: {
|
|
22
|
+
surfaceId,
|
|
23
|
+
components: [
|
|
24
|
+
{
|
|
25
|
+
id: rootId,
|
|
26
|
+
component: 'Text',
|
|
27
|
+
text,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build a Card-wrapped Text fallback message stream from a plain string.
|
|
36
|
+
* Used when the agent emits text payloads with `kind: 'text'`.
|
|
37
|
+
*/
|
|
38
|
+
export function createTextCardMessages(text) {
|
|
39
|
+
const surfaceId = randomId('text_surface_');
|
|
40
|
+
const rootId = 'root';
|
|
41
|
+
const textId = 'text';
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
createSurface: {
|
|
45
|
+
surfaceId,
|
|
46
|
+
catalogId: 'inline-text',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
updateComponents: {
|
|
51
|
+
surfaceId,
|
|
52
|
+
components: [
|
|
53
|
+
{
|
|
54
|
+
id: rootId,
|
|
55
|
+
component: 'Card',
|
|
56
|
+
child: textId,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: textId,
|
|
60
|
+
component: 'Text',
|
|
61
|
+
text,
|
|
62
|
+
variant: 'body',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Normalize an arbitrary payload (string, array, object) into a flat list of
|
|
71
|
+
* `ServerToClientMessage` records. Pass-through for already-structured
|
|
72
|
+
* messages; falls back to wrapping plain text in a Text/Card surface.
|
|
73
|
+
*/
|
|
74
|
+
export function normalizePayloadToMessages(payload) {
|
|
75
|
+
const messages = [];
|
|
76
|
+
const add = (value) => {
|
|
77
|
+
// Treat only `null` / `undefined` as no-ops — `0`, `false`, `''` are
|
|
78
|
+
// legitimate fallback payloads upstream callers may produce.
|
|
79
|
+
if (value === null || value === undefined)
|
|
80
|
+
return;
|
|
81
|
+
if (Array.isArray(value)) {
|
|
82
|
+
for (const item of value)
|
|
83
|
+
add(item);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
messages.push(value);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const handle = (value) => {
|
|
90
|
+
if (value === null || value === undefined)
|
|
91
|
+
return;
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
for (const item of value)
|
|
94
|
+
handle(item);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === 'string') {
|
|
98
|
+
add(createFallbackMessagesFromPlainText(value));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (typeof value === 'number' || typeof value === 'boolean'
|
|
102
|
+
|| typeof value === 'bigint') {
|
|
103
|
+
// Coerce non-string primitives so payloads like `0` or `false`
|
|
104
|
+
// surface as visible fallback messages instead of disappearing.
|
|
105
|
+
add(createFallbackMessagesFromPlainText(String(value)));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (typeof value === 'object') {
|
|
109
|
+
const v = value;
|
|
110
|
+
if (v['createSurface'] || v['updateComponents'] || v['updateDataModel']
|
|
111
|
+
|| v['deleteSurface']) {
|
|
112
|
+
add(v);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if ('kind' in v && 'data' in v) {
|
|
116
|
+
if (v['kind'] === 'data') {
|
|
117
|
+
handle(v['data']);
|
|
118
|
+
}
|
|
119
|
+
else if (v['kind'] === 'text') {
|
|
120
|
+
add(createTextCardMessages(typeof v['data'] === 'string' ? v['data'] : String(v['data'])));
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(v['messages'])) {
|
|
125
|
+
handle(v['messages']);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
// `JSON.stringify` throws on circular refs and `BigInt` values; fall
|
|
129
|
+
// back to a generic placeholder rather than letting the whole
|
|
130
|
+
// normalize call crash.
|
|
131
|
+
let serialized;
|
|
132
|
+
try {
|
|
133
|
+
serialized = JSON.stringify(v);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
serialized = '[unserializable object]';
|
|
137
|
+
}
|
|
138
|
+
add(createFallbackMessagesFromPlainText(serialized));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
handle(payload);
|
|
143
|
+
return messages;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Tag messages with the given messageId and report whether any of them
|
|
147
|
+
* carries a non-empty `updateComponents`. Also dedupes `createSurface`
|
|
148
|
+
* messages against the set of currently-active surfaces.
|
|
149
|
+
*/
|
|
150
|
+
export function prepareMessagesForProcessing(rawMessages, messageId, activeSurfaceIds) {
|
|
151
|
+
let hasComponentUpdate = false;
|
|
152
|
+
const messages = rawMessages.filter((msg) => {
|
|
153
|
+
const deletedSurfaceId = msg
|
|
154
|
+
.deleteSurface?.surfaceId;
|
|
155
|
+
if (typeof deletedSurfaceId === 'string') {
|
|
156
|
+
activeSurfaceIds.delete(deletedSurfaceId);
|
|
157
|
+
}
|
|
158
|
+
const createdSurfaceId = msg
|
|
159
|
+
.createSurface?.surfaceId;
|
|
160
|
+
if (typeof createdSurfaceId === 'string') {
|
|
161
|
+
if (activeSurfaceIds.has(createdSurfaceId)) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
activeSurfaceIds.add(createdSurfaceId);
|
|
165
|
+
}
|
|
166
|
+
if ((msg
|
|
167
|
+
.updateComponents
|
|
168
|
+
&& Array.isArray(msg
|
|
169
|
+
.updateComponents?.components)
|
|
170
|
+
&& ((msg
|
|
171
|
+
.updateComponents?.components ?? []).length > 0))) {
|
|
172
|
+
hasComponentUpdate = true;
|
|
173
|
+
}
|
|
174
|
+
msg.messageId ??= messageId;
|
|
175
|
+
return true;
|
|
176
|
+
});
|
|
177
|
+
return { messages, hasComponentUpdate };
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=payloadNormalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payloadNormalizer.js","sourceRoot":"","sources":["../../src/store/payloadNormalizer.ts"],"names":[],"mappings":"AAKA,SAAS,QAAQ,CAAC,MAAM,GAAG,EAAE;IAC3B,OAAO,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;UACnC,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CACjD,IAAY;IAEZ,MAAM,SAAS,GAAG,SAAS,CAAC;IAC5B,MAAM,MAAM,GAAG,WAAW,CAAC;IAE3B,OAAO;QACL;YACE,aAAa,EAAE;gBACb,SAAS;gBACT,SAAS,EAAE,aAAa;aACzB;SACF;QACD;YACE,gBAAgB,EAAE;gBAChB,SAAS;gBACT,UAAU,EAAE;oBACV;wBACE,EAAE,EAAE,MAAM;wBACV,SAAS,EAAE,MAAM;wBACjB,IAAI;qBACL;iBACF;aACF;SACF;KACyB,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,IAAY;IAEZ,MAAM,SAAS,GAAG,QAAQ,CAAC,eAAe,CAAC,C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AU,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EACrD,CAAC;YACD,kBAAkB,GAAG,IAAI,CAAC;QAC5B,CAAC;QAED,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC;QAE5B,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as v0_9 from '@a2ui/web_core/v0_9';
|
|
2
|
+
import type { FunctionRegistry } from './FunctionRegistry.js';
|
|
3
|
+
import type { MessageProcessor } from './MessageProcessor.js';
|
|
4
|
+
import type { CatalogFunctionEntry } from '../catalog/defineCatalog.js';
|
|
5
|
+
export declare function isDataBinding(value: unknown): value is v0_9.DataBinding;
|
|
6
|
+
export declare function isFunctionCall(value: unknown): value is v0_9.FunctionCall;
|
|
7
|
+
export declare function resolveDynamicValue(processor: MessageProcessor, value: unknown, surfaceId: string, dataContextPath?: string, options?: ResolveFunctionOptions): unknown;
|
|
8
|
+
export declare function resolveFunctionArguments(processor: MessageProcessor, args: Record<string, unknown> | undefined, surfaceId: string, dataContextPath?: string, options?: ResolveFunctionOptions): Record<string, unknown>;
|
|
9
|
+
export interface ResolveFunctionOptions {
|
|
10
|
+
functions?: readonly CatalogFunctionEntry[] | undefined;
|
|
11
|
+
registry?: FunctionRegistry | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolve arguments, look the function up in the registry, and invoke it.
|
|
15
|
+
* When no impl is registered, log once and return `undefined` so callers
|
|
16
|
+
* (checks, dynamic-property bindings) can degrade gracefully.
|
|
17
|
+
*/
|
|
18
|
+
export declare function executeFunctionCall(processor: MessageProcessor, fn: v0_9.FunctionCall, surfaceId: string, dataContextPath?: string, options?: ResolveFunctionOptions): unknown;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { computed, signal } from '@preact/signals';
|
|
2
|
+
import { functionRegistry } from './FunctionRegistry.js';
|
|
3
|
+
function isObject(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null;
|
|
5
|
+
}
|
|
6
|
+
export function isDataBinding(value) {
|
|
7
|
+
return isObject(value) && 'path' in value;
|
|
8
|
+
}
|
|
9
|
+
export function isFunctionCall(value) {
|
|
10
|
+
return isObject(value) && 'call' in value;
|
|
11
|
+
}
|
|
12
|
+
function resolveFromStore(processor, path, surfaceId, dataContextPath) {
|
|
13
|
+
const surface = processor.getOrCreateSurface(surfaceId);
|
|
14
|
+
const store = surface.store;
|
|
15
|
+
const resolvedPath = processor.resolvePath(path, dataContextPath);
|
|
16
|
+
const signal = store.getSignal(resolvedPath);
|
|
17
|
+
const raw = signal.value;
|
|
18
|
+
if (raw === undefined || raw === null)
|
|
19
|
+
return raw;
|
|
20
|
+
if (typeof raw !== 'string')
|
|
21
|
+
return raw;
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(raw);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return raw;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function setInStore(processor, path, value, surfaceId, dataContextPath) {
|
|
30
|
+
const surface = processor.getOrCreateSurface(surfaceId);
|
|
31
|
+
const resolvedPath = processor.resolvePath(path, dataContextPath);
|
|
32
|
+
surface.store.update(resolvedPath, value);
|
|
33
|
+
}
|
|
34
|
+
function signalFromStore(processor, path, surfaceId, dataContextPath) {
|
|
35
|
+
const surface = processor.getOrCreateSurface(surfaceId);
|
|
36
|
+
const resolvedPath = processor.resolvePath(path, dataContextPath);
|
|
37
|
+
return surface.store.getSignal(resolvedPath);
|
|
38
|
+
}
|
|
39
|
+
export function resolveDynamicValue(processor, value, surfaceId, dataContextPath, options = {}) {
|
|
40
|
+
if (typeof value === 'string' || typeof value === 'number'
|
|
41
|
+
|| typeof value === 'boolean') {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
return value.map(item => resolveDynamicValue(processor, item, surfaceId, dataContextPath, options));
|
|
46
|
+
}
|
|
47
|
+
if (isDataBinding(value)) {
|
|
48
|
+
return resolveFromStore(processor, value.path, surfaceId, dataContextPath);
|
|
49
|
+
}
|
|
50
|
+
if (isFunctionCall(value)) {
|
|
51
|
+
return executeFunctionCall(processor, value, surfaceId, dataContextPath, options);
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
function resolveSignal(processor, value, surfaceId, dataContextPath, options) {
|
|
56
|
+
if (isDataBinding(value)) {
|
|
57
|
+
return signalFromStore(processor, value.path, surfaceId, dataContextPath);
|
|
58
|
+
}
|
|
59
|
+
if (isFunctionCall(value)) {
|
|
60
|
+
return computed(() => executeFunctionCall(processor, value, surfaceId, dataContextPath, options));
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
return computed(() => value.map(item => resolveDynamicValue(processor, item, surfaceId, dataContextPath, options)));
|
|
64
|
+
}
|
|
65
|
+
return signal(value);
|
|
66
|
+
}
|
|
67
|
+
function createFunctionContext(processor, surfaceId, dataContextPath, options) {
|
|
68
|
+
return {
|
|
69
|
+
processor,
|
|
70
|
+
surfaceId,
|
|
71
|
+
...(dataContextPath === undefined ? {} : { dataContextPath }),
|
|
72
|
+
resolveDynamicValue(value) {
|
|
73
|
+
return resolveDynamicValue(processor, value, surfaceId, dataContextPath, options);
|
|
74
|
+
},
|
|
75
|
+
resolveSignal(value) {
|
|
76
|
+
return resolveSignal(processor, value, surfaceId, dataContextPath, options);
|
|
77
|
+
},
|
|
78
|
+
set(path, value) {
|
|
79
|
+
setInStore(processor, path, value, surfaceId, dataContextPath);
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export function resolveFunctionArguments(processor, args, surfaceId, dataContextPath, options = {}) {
|
|
84
|
+
const resolved = {};
|
|
85
|
+
if (!args)
|
|
86
|
+
return resolved;
|
|
87
|
+
for (const [key, raw] of Object.entries(args)) {
|
|
88
|
+
if (Array.isArray(raw) || isDataBinding(raw) || isFunctionCall(raw)) {
|
|
89
|
+
resolved[key] = resolveDynamicValue(processor, raw, surfaceId, dataContextPath, options);
|
|
90
|
+
}
|
|
91
|
+
else if (isObject(raw)) {
|
|
92
|
+
resolved[key] = { ...raw };
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
resolved[key] = resolveDynamicValue(processor, raw, surfaceId, dataContextPath, options);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return resolved;
|
|
99
|
+
}
|
|
100
|
+
function resolveFunctionImpl(name, options) {
|
|
101
|
+
const scoped = options.functions?.find(entry => entry.name === name)?.impl;
|
|
102
|
+
if (scoped)
|
|
103
|
+
return scoped;
|
|
104
|
+
return (options.registry ?? functionRegistry).resolve(name);
|
|
105
|
+
}
|
|
106
|
+
const warnedUnknownFunctions = new Set();
|
|
107
|
+
/**
|
|
108
|
+
* Resolve arguments, look the function up in the registry, and invoke it.
|
|
109
|
+
* When no impl is registered, log once and return `undefined` so callers
|
|
110
|
+
* (checks, dynamic-property bindings) can degrade gracefully.
|
|
111
|
+
*/
|
|
112
|
+
export function executeFunctionCall(processor, fn, surfaceId, dataContextPath, options = {}) {
|
|
113
|
+
const impl = resolveFunctionImpl(fn.call, options);
|
|
114
|
+
const resolvedArgs = resolveFunctionArguments(processor, fn.args, surfaceId, dataContextPath, options);
|
|
115
|
+
if (!impl) {
|
|
116
|
+
if (!warnedUnknownFunctions.has(fn.call)) {
|
|
117
|
+
warnedUnknownFunctions.add(fn.call);
|
|
118
|
+
console.warn(`[a2ui] No client implementation registered for function `
|
|
119
|
+
+ `"${fn.call}". Returning undefined.`);
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
return impl(resolvedArgs, createFunctionContext(processor, surfaceId, dataContextPath, options));
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.warn(`[a2ui] Function "${fn.call}" threw while resolving. Returning undefined.`, error);
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=resolveFunctionCall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveFunctionCall.js","sourceRoot":"","sources":["../../src/store/resolveFunctionCall.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AASzD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,IAAI,KAAK,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,IAAI,KAAK,CAAC;AAC5C,CAAC;AAED,SAAS,gBAAgB,CACvB,SAA2B,EAC3B,IAAY,EACZ,SAAiB,EACjB,eAAwB;IAExB,MAAM,OAAO,GAAG,SAAS,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACxD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,MAAM,YAAY,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IAClE,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;IACzB,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC;IAClD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GA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,CAAC,IAAI,CACV,oBAAoB,EAAE,CAAC,IAAI,+CAA+C,EAC1E,KAAK,CACN,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type * as v0_9 from '@a2ui/web_core/v0_9';
|
|
2
|
+
import type { Resource as GenericResource } from './Resource.js';
|
|
3
|
+
import type { SignalStore } from './SignalStore.js';
|
|
4
|
+
export type SurfaceId = string;
|
|
5
|
+
export type ComponentInstance = v0_9.AnyComponent & {
|
|
6
|
+
/**
|
|
7
|
+
* Absolute data context path for this component when created via a template.
|
|
8
|
+
* Used for resolving relative bindings inside the component tree.
|
|
9
|
+
*/
|
|
10
|
+
dataContextPath?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Internal metadata for templated containers so we can re-expand on
|
|
13
|
+
* data model updates.
|
|
14
|
+
*/
|
|
15
|
+
__template?: {
|
|
16
|
+
componentId: v0_9.ComponentId;
|
|
17
|
+
path: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export interface Surface {
|
|
21
|
+
surfaceId: SurfaceId;
|
|
22
|
+
catalogId?: string;
|
|
23
|
+
theme?: Readonly<Record<string, unknown>>;
|
|
24
|
+
sendDataModel?: boolean | undefined;
|
|
25
|
+
/** id of the root component for this surface (must be 'root'). */
|
|
26
|
+
rootComponentId?: string | null;
|
|
27
|
+
components: Map<string, ComponentInstance>;
|
|
28
|
+
resources: Map<string, Resource>;
|
|
29
|
+
store: SignalStore;
|
|
30
|
+
}
|
|
31
|
+
export interface ResourceInfo {
|
|
32
|
+
/**
|
|
33
|
+
* Internal event type emitted by the processor.
|
|
34
|
+
*/
|
|
35
|
+
type: 'beginRendering' | 'surfaceUpdate' | 'deleteSurface';
|
|
36
|
+
surfaceId: string;
|
|
37
|
+
surface: Surface;
|
|
38
|
+
component?: ComponentInstance;
|
|
39
|
+
}
|
|
40
|
+
export type Resource = GenericResource<ResourceInfo>;
|
|
41
|
+
export type ServerToClientMessage = v0_9.A2uiMessage & {
|
|
42
|
+
/**
|
|
43
|
+
* Message id injected by the client.
|
|
44
|
+
*/
|
|
45
|
+
messageId?: string;
|
|
46
|
+
};
|
|
47
|
+
export interface UserActionPayload {
|
|
48
|
+
name: string;
|
|
49
|
+
surfaceId: string;
|
|
50
|
+
sourceComponentId: string;
|
|
51
|
+
timestamp: string;
|
|
52
|
+
context: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
export type A2UIClientEventMessage = string | {
|
|
55
|
+
text?: string;
|
|
56
|
+
sessionId?: string;
|
|
57
|
+
} | {
|
|
58
|
+
userAction: UserActionPayload;
|
|
59
|
+
sessionId?: string;
|
|
60
|
+
};
|
|
61
|
+
export interface GenericComponentProps {
|
|
62
|
+
id?: string;
|
|
63
|
+
surface: Surface;
|
|
64
|
+
setValue?: (key: string, value: unknown) => void;
|
|
65
|
+
sendAction?: (action: Record<string, unknown>) => void;
|
|
66
|
+
dataContextPath?: string;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/store/types.ts"],"names":[],"mappings":""}
|