diff --git a/typescript/core/web_core/CHANGELOG.md b/typescript/core/web_core/CHANGELOG.md index 4f1a729391..7ef147a6cf 100644 --- a/typescript/core/web_core/CHANGELOG.md +++ b/typescript/core/web_core/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased - **BREAKING CHANGE**: Validate pre-1.0 nested function calls against their catalog function `returnType` and the enclosing `Dynamic*` property or argument slot schema in `PayloadValidator`, and enforce `additionalProperties: false`, `minimum`/`maximum` numeric bounds, `format: 'uri'` string checks, and `anyOf` required-argument disjunctions (`length` and `numeric`) across both generated basic catalog schemas and `Catalog.fromJson()`. Recommended migration: remove undeclared function arguments, supply at least one bound on `length` and `numeric`, pass a scheme-prefixed URI to `openUrl.url`, and match or omit `returnType` on nested function calls ([#4173](https://github.com/a2ui-project/a2ui/issues/4173), [#4187](https://github.com/a2ui-project/a2ui/pull/4187)). +- Add the `@a2ui/web_core/catalogs/basic/v1/api` entry, which exports the v1 basic catalog's component APIs, functions and theme schema without the Lit custom elements, so renderers that run without a DOM (such as React Native) can import them. `@a2ui/web_core/catalogs/basic/v1` re-exports the custom elements, and Lit's browser build fails to load when `HTMLElement` is not defined. [#4238](https://github.com/a2ui-project/a2ui/issues/4238) - **BREAKING CHANGE**: Widen `OutboundMessageListener` to accept `OutboundActionMessage` and `RendererErrorMessage` in addition to `RendererFunctionResponseMessage` and `CallAgentFunctionMessage`, and add `MessageProcessorOptions.unifiedOutbound` and `OutboundActionMessage` so opting in routes surface actions and non-`v0.8` processing errors through `outboundListener` alongside RPC messages while keeping `actionHandler` and `errorHandler` active for local side effects. Recommended migration: widen typed `OutboundMessageListener` callbacks to accept the union or narrow on `'action' in message` and `'error' in message`. [#4015](https://github.com/a2ui-project/a2ui/issues/4015), [#4078](https://github.com/a2ui-project/a2ui/pull/4078) - **BREAKING CHANGE**: `SurfaceModel.protocolVersion` now records the `createSurface` message protocol version before falling back to the default catalog's `protocolVersion`, matching Dart and Swift. A `v0.9.1` `createSurface` on a `v0.9` catalog now sets `surface.protocolVersion` to `'v0.9.1'`. Recommended migration: pass a target version to `getRendererDataModel(version)` when active surfaces mix `'v0.9'` and `'v0.9.1'`. [#4015](https://github.com/a2ui-project/a2ui/issues/4015), [#4077](https://github.com/a2ui-project/a2ui/pull/4077) - **BREAKING CHANGE**: (v0_9) `MessageProcessor` and `PayloadValidator` treat a component's `metadata` key as an ordinary property on v0.9 surfaces and catalogs, since v0.9 defines no component metadata: it stays in `ComponentModel.properties`, is validated against the component's schema, and `ComponentModel.metadata` stays `undefined`. Before, it was checked against the v1.0 metadata rules and moved out of the properties. Recommended migration: declare `metadata` in the component schema to accept it on v0.9, or move to v1.0 for component metadata. [#4137](https://github.com/a2ui-project/a2ui/issues/4137), [#4140](https://github.com/a2ui-project/a2ui/pull/4140) diff --git a/typescript/core/web_core/package.json b/typescript/core/web_core/package.json index 69257d9b0b..92d11881fe 100644 --- a/typescript/core/web_core/package.json +++ b/typescript/core/web_core/package.json @@ -110,6 +110,10 @@ "types": "./dist/src/catalogs/basic/v1/index.d.ts", "default": "./dist/src/catalogs/basic/v1/index.js" }, + "./catalogs/basic/v1/api": { + "types": "./dist/src/catalogs/basic/v1/api.d.ts", + "default": "./dist/src/catalogs/basic/v1/api.js" + }, "./universal": { "types": "./dist/src/universal/index.d.ts", "default": "./dist/src/universal/index.js" diff --git a/typescript/core/web_core/src/catalogs/basic/v1/api.test.ts b/typescript/core/web_core/src/catalogs/basic/v1/api.test.ts new file mode 100644 index 0000000000..9d7005d3de --- /dev/null +++ b/typescript/core/web_core/src/catalogs/basic/v1/api.test.ts @@ -0,0 +1,45 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as assert from 'node:assert'; +import {spawnSync} from 'node:child_process'; +import {describe, it} from 'node:test'; +import {fileURLToPath} from 'node:url'; + +// Loads a module in a fresh Node process with the 'browser' export condition +// and no DOM, which is how Metro (React Native) resolves packages. +function importWithoutDom(file: string) { + const url = new URL(file, import.meta.url).href; + return spawnSync( + process.execPath, + ['--conditions=browser', '--input-type=module', '-e', `await import(${JSON.stringify(url)});`], + {encoding: 'utf8', cwd: fileURLToPath(new URL('.', import.meta.url))}, + ); +} + +describe('v1 basic catalog api entry', () => { + it('loads without a DOM', () => { + const result = importWithoutDom('./api.js'); + assert.strictEqual(result.status, 0, result.stderr); + }); + + it('exports the component APIs and functions', async () => { + const api = await import('./api.js'); + assert.strictEqual(api.BASIC_COMPONENTS.length, 18); + assert.ok(api.BASIC_COMPONENTS.includes(api.ButtonApi)); + assert.ok(api.BASIC_FUNCTIONS.length > 0); + }); +}); diff --git a/typescript/core/web_core/src/catalogs/basic/v1/api.ts b/typescript/core/web_core/src/catalogs/basic/v1/api.ts new file mode 100644 index 0000000000..8f29c2da79 --- /dev/null +++ b/typescript/core/web_core/src/catalogs/basic/v1/api.ts @@ -0,0 +1,86 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// The v1 basic catalog's component APIs, functions and theme schema, without +// the Lit custom elements. Renderers that do not run in a browser (React +// Native, server-side validation) import this entry, because './index.js' +// re-exports the custom elements and Lit's browser build defines classes that +// extend HTMLElement as soon as it loads. + +export { + AudioPlayerApi, + ButtonApi, + CardApi, + CheckBoxApi, + ChoicePickerApi, + ColumnApi, + DateTimeInputApi, + DividerApi, + IconApi, + ImageApi, + ListApi, + ModalApi, + RowApi, + SliderApi, + TabsApi, + TextApi, + TextFieldApi, + VideoApi, + WeightSchema, + BASIC_COMPONENTS, + BASIC_CATALOG_DOCUMENT_OPTIONS, +} from './components/basic_components.js'; +export { + BASIC_FUNCTIONS, + createBasicCatalogFunctions, + AndImplementation, + OrImplementation, + NotImplementation, + FormatStringImplementation, + FormatNumberImplementation, + createFormatNumberImplementation, + FormatCurrencyImplementation, + createFormatCurrencyImplementation, + FormatDateImplementation, + createFormatDateImplementation, + PluralizeImplementation, + createPluralizeImplementation, + OpenUrlImplementation, +} from './functions/basic_functions.js'; +export { + RequiredApi, + RegexApi, + LengthApi, + NumericApi, + EmailApi, + FormatStringApi, + FormatNumberApi, + FormatCurrencyApi, + FormatDateApi, + PluralizeApi, + OpenUrlApi, + AndApi, + OrApi, + NotApi, + BASIC_FUNCTION_APIS, + V10_SPEC_FUNCTION_APIS, +} from './functions/basic_functions_api.js'; +export { + BasicCatalogThemeSchema, + BasicCatalogThemeSchema as ThemeSchema, + type BasicCatalogTheme, + isValidCssColor, +} from '../../../universal/basic_catalog/theme.js';