Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions renderers/web_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.8.8
- Remove schema definition tweaks from 0.8.7

## 0.8.7

- Adds `catalogId` to v0.8 schemas (was removed by mistake earlier)
Expand Down
2 changes: 1 addition & 1 deletion renderers/web_core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@a2ui/web_core",
"version": "0.8.7",
"version": "0.8.8",
"description": "A2UI Core Library",
"main": "./dist/src/v0_8/index.js",
"types": "./dist/src/v0_8/index.d.ts",
Expand Down
13 changes: 6 additions & 7 deletions renderers/web_core/src/v0_8/data/model-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
SurfaceID,
SurfaceUpdateMessage,
MessageProcessor,
ValueMap,
} from "../types/types.js";
import { A2uiMessageSchema } from "../schema/server-to-client.js";
import { A2uiStateError, A2uiValidationError } from "../errors.js";
Expand Down Expand Up @@ -256,7 +255,7 @@ export class A2uiMessageProcessor implements MessageProcessor {
return map;
}

private setDataByPath(root: DataMap, path: string, value: DataValue | ValueMap[]): void {
private setDataByPath(root: DataMap, path: string, value: DataValue): void {
// Check if the incoming value is the special key-value array format.
if (
Array.isArray(value) &&
Expand All @@ -270,23 +269,23 @@ export class A2uiMessageProcessor implements MessageProcessor {

if (valueKey) {
// Extract the primitive value
value = item[valueKey] as DataValue | ValueMap[];
value = item[valueKey];

// We must still process this value in case it's a valueMap or
// a JSON string.
if (valueKey === "valueMap" && Array.isArray(value)) {
value = this.convertKeyValueArrayToMap(value as DataArray);
value = this.convertKeyValueArrayToMap(value);
} else if (typeof value === "string") {
value = this.parseIfJsonString(value);
}
// Now, `value` is the primitive (e.g., "hi"), and we continue
// the function.
} else {
// Malformed, but fall back to existing behavior.
value = this.convertKeyValueArrayToMap(value as DataArray);
value = this.convertKeyValueArrayToMap(value);
}
} else {
value = this.convertKeyValueArrayToMap(value as DataArray);
value = this.convertKeyValueArrayToMap(value);
}
}

Expand Down Expand Up @@ -339,7 +338,7 @@ export class A2uiMessageProcessor implements MessageProcessor {
}

const finalSegment = segments[segments.length - 1];
const storedValue = value as DataValue;
const storedValue = value;
if (current instanceof this.mapCtor) {
current.set(finalSegment, storedValue);
} else if (Array.isArray(current) && /^\d+$/.test(finalSegment)) {
Expand Down
38 changes: 19 additions & 19 deletions renderers/web_core/src/v0_8/types/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ import type {
VideoSchema,
} from "../schema/common-types.js";

export declare interface Action extends z.infer<typeof ActionSchema> {}
export declare interface Text extends z.infer<typeof TextSchema> {}
export declare interface Image extends z.infer<typeof ImageSchema> {}
export declare interface Icon extends z.infer<typeof IconSchema> {}
export declare interface Video extends z.infer<typeof VideoSchema> {}
export declare interface AudioPlayer extends z.infer<typeof AudioPlayerSchema> {}
export declare interface Tabs extends z.infer<typeof TabsSchema> {}
export declare interface Row extends z.infer<typeof RowSchema> {}
export declare interface Column extends z.infer<typeof ColumnSchema> {}
export declare interface List extends z.infer<typeof ListSchema> {}
export declare interface Button extends z.infer<typeof ButtonSchema> {}
export declare interface Modal extends z.infer<typeof ModalSchema> {}
export declare interface Card extends z.infer<typeof CardSchema> {}
export declare interface Divider extends z.infer<typeof DividerSchema> {}
export declare interface TextField extends z.infer<typeof TextFieldSchema> {}
export declare interface Checkbox extends z.infer<typeof CheckboxSchema> {}
export declare interface DateTimeInput extends z.infer<typeof DateTimeInputSchema> {}
export declare interface MultipleChoice extends z.infer<typeof MultipleChoiceSchema> {}
export declare interface Slider extends z.infer<typeof SliderSchema> {}
export type Action = z.infer<typeof ActionSchema>;
export type Text = z.infer<typeof TextSchema>;
export type Image = z.infer<typeof ImageSchema>;
export type Icon = z.infer<typeof IconSchema>;
export type Video = z.infer<typeof VideoSchema>;
export type AudioPlayer = z.infer<typeof AudioPlayerSchema>;
export type Tabs = z.infer<typeof TabsSchema>;
export type Row = z.infer<typeof RowSchema>;
export type Column = z.infer<typeof ColumnSchema>;
export type List = z.infer<typeof ListSchema>;
export type Button = z.infer<typeof ButtonSchema>;
export type Modal = z.infer<typeof ModalSchema>;
export type Card = z.infer<typeof CardSchema>;
export type Divider = z.infer<typeof DividerSchema>;
export type TextField = z.infer<typeof TextFieldSchema>;
export type Checkbox = z.infer<typeof CheckboxSchema>;
export type DateTimeInput = z.infer<typeof DateTimeInputSchema>;
export type MultipleChoice = z.infer<typeof MultipleChoiceSchema>;
export type Slider = z.infer<typeof SliderSchema>;
6 changes: 3 additions & 3 deletions renderers/web_core/src/v0_8/types/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import type {
BooleanValueSchema,
} from "../schema/common-types.js";

export declare interface StringValue extends z.infer<typeof StringValueSchema> {}
export declare interface NumberValue extends z.infer<typeof NumberValueSchema> {}
export declare interface BooleanValue extends z.infer<typeof BooleanValueSchema> {}
export type StringValue = z.infer<typeof StringValueSchema>;
export type NumberValue = z.infer<typeof NumberValueSchema>;
export type BooleanValue = z.infer<typeof BooleanValueSchema>;
88 changes: 14 additions & 74 deletions renderers/web_core/src/v0_8/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,13 @@ export { type Action } from "./components.js";
import {
AudioPlayer,
Button,
Card,
Checkbox,
Column,
DateTimeInput,
Divider,
Icon,
Image,
List,
Modal,
MultipleChoice,
Row,
Slider,
Tabs,
Text,
TextField,
Video,
Expand Down Expand Up @@ -256,87 +250,33 @@ export declare type DataMap = Map<string, DataValue>;
export declare type DataArray = DataValue[];

/** A template for creating components from a list in the data model. */
export declare interface ComponentArrayTemplate
extends z.infer<typeof ComponentArrayTemplateSchema> {
componentId: string;
dataBinding: string;
}
export type ComponentArrayTemplate = z.infer<
typeof ComponentArrayTemplateSchema
>;

/** Defines a list of child components, either explicitly or via a template. */
export declare interface ComponentArrayReference
extends z.infer<typeof ComponentArrayReferenceSchema> {
explicitList?: string[];
template?: ComponentArrayTemplate;
}
export type ComponentArrayReference = z.infer<
typeof ComponentArrayReferenceSchema
>;

/** Represents the general shape of a component's properties. */
export declare interface ComponentProperties extends z.infer<typeof ComponentPropertiesSchema> {
Text?: Text;
Image?: Image;
Icon?: Icon;
Video?: Video;
AudioPlayer?: AudioPlayer;
Row?: Row;
Column?: Column;
List?: List;
Card?: Card;
Tabs?: Tabs;
Divider?: Divider;
Modal?: Modal;
Button?: Button;
Checkbox?: Checkbox;
TextField?: TextField;
DateTimeInput?: DateTimeInput;
MultipleChoice?: MultipleChoice;
Slider?: Slider;
}
export type ComponentProperties = z.infer<typeof ComponentPropertiesSchema>;

/** A raw component instance from a SurfaceUpdate message. */
export declare interface ComponentInstance extends z.infer<typeof ComponentInstanceSchema> {
id: string;
weight?: number;
component: ComponentProperties;
}
export type ComponentInstance = z.infer<typeof ComponentInstanceSchema>;

export declare interface BeginRenderingMessage extends z.infer<typeof BeginRenderingMessageSchema> {
surfaceId: string;
root: string;
styles?: {
font?: string;
primaryColor?: string;
};
}
export type BeginRenderingMessage = z.infer<typeof BeginRenderingMessageSchema>;

export declare interface SurfaceUpdateMessage extends z.infer<typeof SurfaceUpdateMessageSchema> {
surfaceId: string;
components: ComponentInstance[];
}
export type SurfaceUpdateMessage = z.infer<typeof SurfaceUpdateMessageSchema>;

export declare interface DataModelUpdate extends z.infer<typeof DataModelUpdateMessageSchema> {
surfaceId: string;
path?: string;
contents: ValueMap[];
}
export type DataModelUpdate = z.infer<typeof DataModelUpdateMessageSchema>;

// ValueMap is a type of DataObject for passing to the data model.
export declare interface ValueMap extends z.infer<typeof ValueMapSchema> {
key: string;
valueString?: string;
valueNumber?: number;
valueBoolean?: boolean;
valueMap?: ValueMap[];
}
export type ValueMap = z.infer<typeof ValueMapSchema>;

export declare interface DeleteSurfaceMessage extends z.infer<typeof DeleteSurfaceMessageSchema> {
surfaceId: string;
}
export type DeleteSurfaceMessage = z.infer<typeof DeleteSurfaceMessageSchema>;

export declare interface ServerToClientMessage extends z.infer<typeof A2uiMessageSchema> {
beginRendering?: BeginRenderingMessage;
surfaceUpdate?: SurfaceUpdateMessage;
dataModelUpdate?: DataModelUpdate;
deleteSurface?: DeleteSurfaceMessage;
}
export type ServerToClientMessage = z.infer<typeof A2uiMessageSchema>;

/**
* A recursive type for any value that can appear within a resolved component
Expand Down
46 changes: 9 additions & 37 deletions renderers/web_core/src/v0_9/schema/server-to-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,38 +91,14 @@ export const DeleteSurfaceMessageSchema = z
})
.strict();

export declare interface CreateSurfaceMessage extends z.infer<typeof CreateSurfaceMessageSchema> {
version: "v0.9";
createSurface: {
surfaceId: string;
catalogId: string;
theme?: any;
sendDataModel?: boolean;
};
}
export declare interface UpdateComponentsMessage
extends z.infer<typeof UpdateComponentsMessageSchema> {
version: "v0.9";
updateComponents: {
surfaceId: string;
components: any[];
};
}
export declare interface UpdateDataModelMessage
extends z.infer<typeof UpdateDataModelMessageSchema> {
version: "v0.9";
updateDataModel: {
surfaceId: string;
path?: string;
value?: any;
};
}
export declare interface DeleteSurfaceMessage extends z.infer<typeof DeleteSurfaceMessageSchema> {
version: "v0.9";
deleteSurface: {
surfaceId: string;
};
}
export type CreateSurfaceMessage = z.infer<typeof CreateSurfaceMessageSchema>;
export type UpdateComponentsMessage = z.infer<
typeof UpdateComponentsMessageSchema
>;
export type UpdateDataModelMessage = z.infer<
typeof UpdateDataModelMessageSchema
>;
export type DeleteSurfaceMessage = z.infer<typeof DeleteSurfaceMessageSchema>;

export const A2uiMessageSchema = z.union([
CreateSurfaceMessageSchema,
Expand All @@ -132,8 +108,4 @@ export const A2uiMessageSchema = z.union([
]);

/** A message sent from the A2UI server to the client. */
export type A2uiMessage =
| CreateSurfaceMessage
| UpdateComponentsMessage
| UpdateDataModelMessage
| DeleteSurfaceMessage;
export type A2uiMessage = z.infer<typeof A2uiMessageSchema>;
Loading