@agnosticui/a2ui-vue 0.0.0-stage → 2.0.0-alpha.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 CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # `@agnosticui/a2ui-vue`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Spec-compliant **A2UI `v1.0`** Vue 3 renderer (`<AgA2uiSurface>`) and `useA2uiSurface()` composable backed by `@agnosticui/a2ui-lit`.
4
+
5
+ ## Quick Usage
6
+
7
+ ```vue
8
+ <script setup lang="ts">
9
+ import { onMounted } from 'vue';
10
+ import 'agnosticui-core/styles/tokens.css';
11
+ import 'agnosticui-core/styles/tokens-dark.css';
12
+ import {
13
+ AgA2uiSurface,
14
+ useA2uiSurface,
15
+ type A2uiWireMessage,
16
+ } from '@agnosticui/a2ui-vue';
17
+
18
+ const props = defineProps<{ messages: A2uiWireMessage[] }>();
19
+
20
+ const { surface, surfaceRef, processMessages } = useA2uiSurface({
21
+ validateOnAction: true,
22
+ onAction: (detail) => console.log('Validated A2UI action:', detail),
23
+ });
24
+
25
+ onMounted(() => {
26
+ processMessages(props.messages);
27
+ });
28
+ </script>
29
+
30
+ <template>
31
+ <AgA2uiSurface ref="surfaceRef" :surface="surface" />
32
+ </template>
33
+ ```
34
+
35
+ ## Local Development Workflow
36
+
37
+ `@agnosticui/a2ui-vue` depends on compiled types and runtime re-exports from `@agnosticui/a2ui-lit` (`../lit/dist`). Always build `renderers/lit` first when testing or building from the **repository root**:
38
+
39
+ ```bash
40
+ # Build lit first, then test, build, and pack vue
41
+ (cd v2/a2ui/renderers/lit && npm test && npm run build) && \
42
+ (cd v2/a2ui/renderers/vue && npm test && npm run build && npm pack)
43
+ ```
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @file index.ts
3
+ * @description Vue 3 renderer and composable bindings (@agnosticui/a2ui-vue)
4
+ * for AgnosticUI's A2UI v1.0 catalog and Light-DOM <a2ui-surface>.
5
+ */
6
+ import { type DefineComponent, type Ref, type ShallowRef } from 'vue';
7
+ import { A2uiSurface, AGNOSTICUI_CATALOG_ID, AgnosticUICatalog, registerAgnosticUICatalog, runSurfaceValidation, createMockA2uiStream, type LitComponentApi, type SurfaceModel, type A2uiWireMessage } from '@agnosticui/a2ui-lit';
8
+ /**
9
+ * Idempotently registers all 25 AgnosticUI A2UI v1.0 custom elements.
10
+ * Safe to call multiple times across Vue 3 components or tests.
11
+ */
12
+ export declare function ensureAgnosticUICatalog(): void;
13
+ export type A2uiActionEvent = CustomEvent<Record<string, unknown>>;
14
+ export interface AgA2uiSurfaceProps {
15
+ surface?: SurfaceModel<LitComponentApi>;
16
+ }
17
+ /**
18
+ * Vue 3 component wrapper around Light-DOM <a2ui-surface>.
19
+ * Assigns the reactive SurfaceModel JS property directly onto the custom element
20
+ * and forwards validated 'a2uiaction' events.
21
+ */
22
+ export declare const AgA2uiSurface: DefineComponent<AgA2uiSurfaceProps>;
23
+ export interface UseA2uiSurfaceOptions {
24
+ /** Surface ID matching createSurface.surfaceId (default: 'support_surface'). */
25
+ surfaceId?: string;
26
+ /** Optional callback invoked when a validated A2UI action fires on the surface. */
27
+ onAction?: (detail: Record<string, unknown>) => void;
28
+ /** Automatically run FACE reportValidity() before invoking onAction (default: true). */
29
+ validateOnAction?: boolean;
30
+ }
31
+ export interface UseA2uiSurfaceResult {
32
+ surface: ShallowRef<SurfaceModel<LitComponentApi> | undefined>;
33
+ surfaceRef: Ref<A2uiSurface | null>;
34
+ processMessages: (messages: A2uiWireMessage[]) => void;
35
+ streamMessages: (messages: A2uiWireMessage[], delayMs?: number) => Promise<void>;
36
+ resetSurface: () => void;
37
+ validate: (report?: boolean) => boolean;
38
+ getDataModel: () => unknown;
39
+ }
40
+ /**
41
+ * Vue 3 composable managing an A2UI v1.0 MessageProcessor bound to AgnosticUICatalog,
42
+ * exposing reactive SurfaceModel state, FACE validation, and action handling.
43
+ */
44
+ export declare function useA2uiSurface(options?: UseA2uiSurfaceOptions): UseA2uiSurfaceResult;
45
+ export { AGNOSTICUI_CATALOG_ID, AgnosticUICatalog, registerAgnosticUICatalog, runSurfaceValidation, createMockA2uiStream, type A2uiWireMessage, };
package/dist/index.js ADDED
@@ -0,0 +1,154 @@
1
+ /**
2
+ * @file index.ts
3
+ * @description Vue 3 renderer and composable bindings (@agnosticui/a2ui-vue)
4
+ * for AgnosticUI's A2UI v1.0 catalog and Light-DOM <a2ui-surface>.
5
+ */
6
+ import { defineComponent, h, onMounted, onUnmounted, ref, shallowRef, watch, } from 'vue';
7
+ import { MessageProcessor, AGNOSTICUI_CATALOG_ID, AgnosticUICatalog, registerAgnosticUICatalog, runSurfaceValidation, createMockA2uiStream, } from '@agnosticui/a2ui-lit';
8
+ let catalogRegistered = false;
9
+ /**
10
+ * Idempotently registers all 25 AgnosticUI A2UI v1.0 custom elements.
11
+ * Safe to call multiple times across Vue 3 components or tests.
12
+ */
13
+ export function ensureAgnosticUICatalog() {
14
+ if (catalogRegistered)
15
+ return;
16
+ registerAgnosticUICatalog();
17
+ catalogRegistered = true;
18
+ }
19
+ /**
20
+ * Vue 3 component wrapper around Light-DOM <a2ui-surface>.
21
+ * Assigns the reactive SurfaceModel JS property directly onto the custom element
22
+ * and forwards validated 'a2uiaction' events.
23
+ */
24
+ export const AgA2uiSurface = defineComponent({
25
+ name: 'AgA2uiSurface',
26
+ props: {
27
+ surface: {
28
+ type: Object,
29
+ default: undefined,
30
+ },
31
+ },
32
+ emits: {
33
+ a2uiaction: (_detail) => true,
34
+ },
35
+ setup(props, { attrs, emit, expose }) {
36
+ ensureAgnosticUICatalog();
37
+ const elementRef = ref(null);
38
+ const syncSurface = (nextSurface) => {
39
+ if (elementRef.value && elementRef.value.surface !== nextSurface) {
40
+ elementRef.value.surface = nextSurface;
41
+ }
42
+ };
43
+ const handleDomAction = (evt) => {
44
+ const detail = evt.detail ?? {};
45
+ emit('a2uiaction', detail);
46
+ };
47
+ onMounted(() => {
48
+ syncSurface(props.surface);
49
+ elementRef.value?.addEventListener('a2uiaction', handleDomAction);
50
+ });
51
+ onUnmounted(() => {
52
+ elementRef.value?.removeEventListener('a2uiaction', handleDomAction);
53
+ });
54
+ watch(() => props.surface, (nextSurface) => {
55
+ syncSurface(nextSurface);
56
+ }, { immediate: true });
57
+ expose({ elementRef });
58
+ return () => h('a2ui-surface', {
59
+ ...attrs,
60
+ ref: elementRef,
61
+ });
62
+ },
63
+ });
64
+ /**
65
+ * Vue 3 composable managing an A2UI v1.0 MessageProcessor bound to AgnosticUICatalog,
66
+ * exposing reactive SurfaceModel state, FACE validation, and action handling.
67
+ */
68
+ export function useA2uiSurface(options = {}) {
69
+ const { surfaceId = 'support_surface', onAction, validateOnAction = true, } = options;
70
+ ensureAgnosticUICatalog();
71
+ const surface = shallowRef(undefined);
72
+ const surfaceRef = ref(null);
73
+ let processor = new MessageProcessor([AgnosticUICatalog]);
74
+ let unsubscribeAction = null;
75
+ const resolveSurfaceElement = () => {
76
+ const raw = surfaceRef.value;
77
+ if (!raw)
78
+ return null;
79
+ if (typeof raw.querySelectorAll === 'function') {
80
+ return raw;
81
+ }
82
+ return raw.elementRef ?? null;
83
+ };
84
+ const handleResolvedAction = (detail) => {
85
+ const el = resolveSurfaceElement();
86
+ if (el && validateOnAction && !runSurfaceValidation(el, true)) {
87
+ return;
88
+ }
89
+ onAction?.(detail);
90
+ };
91
+ const bindProcessor = (nextProcessor) => {
92
+ unsubscribeAction?.();
93
+ processor = nextProcessor;
94
+ const sub = processor.model.onAction.subscribe((action) => {
95
+ const detail = action;
96
+ handleResolvedAction(detail);
97
+ });
98
+ unsubscribeAction = () => sub.unsubscribe();
99
+ };
100
+ bindProcessor(processor);
101
+ const resetSurface = () => {
102
+ bindProcessor(new MessageProcessor([AgnosticUICatalog]));
103
+ surface.value = undefined;
104
+ };
105
+ const processMessages = (messages) => {
106
+ for (const msg of messages) {
107
+ const envelope = msg;
108
+ const targetId = envelope.createSurface?.surfaceId;
109
+ if (targetId && processor.model.getSurface(targetId)) {
110
+ processor.processMessages([
111
+ { version: '1.0', deleteSurface: { surfaceId: targetId } },
112
+ ]);
113
+ }
114
+ processor.processMessages([msg]);
115
+ }
116
+ const nextModel = processor.model.getSurface(surfaceId);
117
+ surface.value = nextModel;
118
+ const el = resolveSurfaceElement();
119
+ if (el) {
120
+ el.surface = nextModel;
121
+ el.requestUpdate();
122
+ }
123
+ };
124
+ const streamMessages = async (messages, delayMs = 0) => {
125
+ for await (const msg of createMockA2uiStream(messages, delayMs)) {
126
+ processMessages([msg]);
127
+ }
128
+ };
129
+ const validate = (report = true) => {
130
+ const el = resolveSurfaceElement();
131
+ if (!el)
132
+ return true;
133
+ return runSurfaceValidation(el, report);
134
+ };
135
+ const getDataModel = () => {
136
+ const current = processor.model.getSurface(surfaceId);
137
+ if (!current)
138
+ return {};
139
+ return current.dataModel.get('') ?? current.dataModel.get('/') ?? {};
140
+ };
141
+ onUnmounted(() => {
142
+ unsubscribeAction?.();
143
+ });
144
+ return {
145
+ surface,
146
+ surfaceRef,
147
+ processMessages,
148
+ streamMessages,
149
+ resetSurface,
150
+ validate,
151
+ getDataModel,
152
+ };
153
+ }
154
+ export { AGNOSTICUI_CATALOG_ID, AgnosticUICatalog, registerAgnosticUICatalog, runSurfaceValidation, createMockA2uiStream, };
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@agnosticui/a2ui-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0-alpha.1",
4
+ "description": "A2UI v1.0 Vue 3 renderer and surface composable for AgnosticUI",
5
+ "author": "AgnosticUI",
6
+ "license": "Apache-2.0",
7
+ "homepage": "https://agnosticui.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com",
11
+ "directory": "v2/a2ui/renderers/vue"
12
+ },
13
+ "keywords": [
14
+ "a2ui",
15
+ "a2ui-v1",
16
+ "agnosticui",
17
+ "generative-ui",
18
+ "vue",
19
+ "vue3",
20
+ "web-components"
21
+ ],
22
+ "type": "module",
23
+ "main": "dist/index.js",
24
+ "types": "dist/index.d.ts",
25
+ "files": [
26
+ "dist",
27
+ "README.md"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ }
34
+ },
35
+ "scripts": {
36
+ "test": "vitest run",
37
+ "typecheck": "tsc --noEmit",
38
+ "build": "tsc"
39
+ },
40
+ "peerDependencies": {
41
+ "@a2ui/lit": "^0.15.0",
42
+ "@a2ui/web_core": "^0.15.0",
43
+ "@agnosticui/a2ui-lit": ">=2.0.0-alpha.1",
44
+ "agnosticui-core": ">=2.0.0-alpha.31",
45
+ "lit": "^3.0.0",
46
+ "vue": ">=3"
47
+ },
48
+ "devDependencies": {
49
+ "@a2ui/lit": "^0.15.0",
50
+ "@a2ui/web_core": "^0.15.0",
51
+ "@agnosticui/a2ui-lit": "^2.0.0-alpha.1",
52
+ "@types/node": "^26.6.6",
53
+ "@vitejs/plugin-vue": "^6.0.1",
54
+ "@vue/test-utils": "^2.4.6",
55
+ "agnosticui-core": "^2.0.0-alpha.31",
56
+ "jsdom": "^26.1.0",
57
+ "lit": "^3.3.3",
58
+ "typescript": "^7.0.2",
59
+ "vitest": "^5.1.0",
60
+ "vue": "^3.5.22"
61
+ }
62
+ }