From b5e50d435d33517a9716386ba15287d9bbdc6ee3 Mon Sep 17 00:00:00 2001 From: Jose Montes Date: Wed, 7 Oct 2026 23:02:36 +0000 Subject: [PATCH] feat(catalogs): add the WebAppFrameUrl and WebAppFrameSrcdoc universal components --- typescript/catalogs/iframe/CHANGELOG.md | 9 +- typescript/catalogs/iframe/README.md | 182 ++++++++++- typescript/catalogs/iframe/karma.conf.cjs | 12 +- typescript/catalogs/iframe/package.json | 5 + .../catalogs/iframe/src/catalog.test.ts | 70 ++++- typescript/catalogs/iframe/src/catalog.ts | 15 + .../src/components/srcdoc_content.test.ts | 160 ++++++++++ .../iframe/src/components/srcdoc_content.ts | 121 ++++++++ .../src/components/web_app_frame_common.ts | 73 +++++ .../components/web_app_frame_srcdoc.test.ts | 270 +++++++++++++++++ .../src/components/web_app_frame_srcdoc.ts | 87 ++++++ .../src/components/web_app_frame_url.test.ts | 264 ++++++++++++++++ .../src/components/web_app_frame_url.ts | 115 +++++++ typescript/catalogs/iframe/src/index.ts | 25 +- .../iframe/src/testing/frame_test_support.ts | 260 ++++++++++++++++ .../iframe/tests/fixtures/apps/test_app.html | 153 ++++++++++ .../tests/fixtures/inert/sandbox-url.html | 25 ++ .../iframe/tests/fixtures/inert/sandbox.html | 25 ++ .../tests/web_app_frame_scenarios.test.ts | 286 ++++++++++++++++++ typescript/catalogs/iframe/tsconfig.test.json | 10 +- 20 files changed, 2133 insertions(+), 34 deletions(-) create mode 100644 typescript/catalogs/iframe/src/components/srcdoc_content.test.ts create mode 100644 typescript/catalogs/iframe/src/components/srcdoc_content.ts create mode 100644 typescript/catalogs/iframe/src/components/web_app_frame_common.ts create mode 100644 typescript/catalogs/iframe/src/components/web_app_frame_srcdoc.test.ts create mode 100644 typescript/catalogs/iframe/src/components/web_app_frame_srcdoc.ts create mode 100644 typescript/catalogs/iframe/src/components/web_app_frame_url.test.ts create mode 100644 typescript/catalogs/iframe/src/components/web_app_frame_url.ts create mode 100644 typescript/catalogs/iframe/src/testing/frame_test_support.ts create mode 100644 typescript/catalogs/iframe/tests/fixtures/apps/test_app.html create mode 100644 typescript/catalogs/iframe/tests/fixtures/inert/sandbox-url.html create mode 100644 typescript/catalogs/iframe/tests/fixtures/inert/sandbox.html create mode 100644 typescript/catalogs/iframe/tests/web_app_frame_scenarios.test.ts diff --git a/typescript/catalogs/iframe/CHANGELOG.md b/typescript/catalogs/iframe/CHANGELOG.md index bcda24ab58..44d013d7a9 100644 --- a/typescript/catalogs/iframe/CHANGELOG.md +++ b/typescript/catalogs/iframe/CHANGELOG.md @@ -2,7 +2,8 @@ ## Unreleased -- Add the `@a2ui/catalog-iframe` package: the sandbox proxy asset with its configuration - (`configureSandbox`, `resolveSandboxUrl`), the `FrameHost` interface and the `WebAppFrameBridge` - host bridge with allowlist validation, data model sync, function calls and sizing. - [#2797](https://github.com/a2ui-project/a2ui/pull/2797) +- Add the `@a2ui/catalog-iframe` package: `iframeCatalog` with the `WebAppFrameUrl` and + `WebAppFrameSrcdoc` universal components, which render a web app inside the sandbox proxy and + connect it to the surface through `WebAppFrameBridge`. Hosts serve the sandbox asset and locate + it with `configureSandbox`. [#2797](https://github.com/a2ui-project/a2ui/pull/2797) + [#2798](https://github.com/a2ui-project/a2ui/pull/2798) diff --git a/typescript/catalogs/iframe/README.md b/typescript/catalogs/iframe/README.md index 88158d7a17..70924739f1 100644 --- a/typescript/catalogs/iframe/README.md +++ b/typescript/catalogs/iframe/README.md @@ -5,26 +5,136 @@ application or an external web app, inside a sandboxed frame that talks to the h the `a2ui_*` message protocol defined in the [WebApp iframe component specification](../../../catalogs/iframe/web_app_frame_specification.md). -This release contains the building blocks the frame components are made of: +The package contains: +- `iframeCatalog`, with the two universal components of the catalog, `WebAppFrameUrl` and + `WebAppFrameSrcdoc`; - the sandbox proxy asset (`sandbox/` in the published package) and the configuration of where the host serves it; - `WebAppFrameBridge`, the host side of the protocol: `MessagePort` handshake, two-way data model sync for `data.paths`, `allowedEvents`, `allowedFunctions` and `mutableData` allowlists with JSON Schema validation, function calls, resize requests and host context updates; -- the zod schemas of the wire messages and the `FrameHost` interface a renderer adapts its component - context to. - -The `WebAppFrameUrl` and `WebAppFrameSrcdoc` components that use them are added in a following -release, together with the catalog registration. +- `SandboxedFrameElement` and `ComponentContextFrameHost`, the base class and the host adapter the + components are built on, for catalogs that add their own sandboxed frame components. ## Installation ```bash -npm install @a2ui/catalog-iframe +npm install @a2ui/catalog-iframe @a2ui/web_core lit +``` + +`@a2ui/web_core` and `lit` are peer dependencies: the components are universal components built on +`A2uiLitElement` from `@a2ui/web_core/v1_0`. The package also depends on `zod` and `ajv` +and expects a browser environment. + +## Usage + +The components are custom elements that any renderer able to host universal components can render. +Register the catalog with the `MessageProcessor` next to the catalogs you already use, and serve the +sandbox asset (next section): + +```ts +import {basicCatalog, MessageProcessor} from '@a2ui/web_core/v1_0'; +import {iframeCatalog} from '@a2ui/catalog-iframe'; + +const processor = new MessageProcessor([basicCatalog, iframeCatalog]); +``` + +A surface resolves components through its default catalog, the `catalogId` of its +`createSurface` message, unless a component names another registered catalog with its own +`catalogId`. A payload that mixes frames with basic components therefore creates the surface with +the basic catalog id and marks the frame component: + +```json +{ + "id": "counter_app", + "component": "WebAppFrameSrcdoc", + "catalogId": "https://a2ui.org/specification/v1_0/catalogs/iframe/catalog.json", + "height": 160, + "htmlContent": "..." +} ``` -The package depends on `zod` and `ajv` and expects a browser environment. +A frame's `allowedFunctions` resolve against the frame component's own catalog first and then +the surface default, so a frame on such a surface can call the basic catalog's functions. + +## Components + +Both components render one `