@handsforbots/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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2024 Alex Lana and Hands for Bots contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # @handsforbots/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
+ UI. Vue bindings for Hands for Bots: plugin and composables for messages, actions, context and stimuli.
4
+
5
+ Part of [Hands for Bots](https://github.com/handsforbots/handsforbots), a headless multimodal and action layer between users, GUIs and agents.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @handsforbots/vue@alpha @handsforbots/core@alpha
11
+ ```
12
+
13
+ Also needs: `vue`.
14
+
15
+ ## Documentation
16
+
17
+ - [This package](https://github.com/handsforbots/handsforbots/blob/main/docs/en-us/plugins.md#vue)
18
+ - [Getting started](https://github.com/handsforbots/handsforbots/blob/main/docs/en-us/getting-started.md)
19
+ - [Documentação em português](https://github.com/handsforbots/handsforbots/blob/main/docs/pt-br/README.md)
20
+
21
+ ## License
22
+
23
+ MIT
@@ -0,0 +1,23 @@
1
+ import { type MaybeRefOrGetter, type ObjectDirective } from 'vue';
2
+ import { type AutofocusOptions, type TextFocusOptions, type TextFocusTarget } from '@handsforbots/widget/focus';
3
+ export type TextFocusBinding = boolean | (AutofocusOptions & {
4
+ within?: TextFocusOptions['within'];
5
+ }) | null | undefined;
6
+ /**
7
+ * Focus a text field. Pass a template ref (or a getter) for that field.
8
+ * `onLoad` focuses when the field is available and again if the switch turns
9
+ * on later. `onClick` focuses on a click that is not a control or a text
10
+ * selection. In a template, `v-text-focus` names the element for you.
11
+ */
12
+ export declare function useTextFocus(input: MaybeRefOrGetter<HTMLElement | null | undefined>, options?: MaybeRefOrGetter<AutofocusOptions & {
13
+ within?: TextFocusOptions['within'];
14
+ }>): void;
15
+ /**
16
+ * Vue directive: the element it sits on is the text field.
17
+ * `v-text-focus="true"` is the load switch. `v-text-focus="{ onLoad, onClick }"`
18
+ * sets each switch. `h4bVue` registers it; import `vTextFocus` to use it locally.
19
+ * The browser's `autofocus` attribute is the load switch alone, applied once.
20
+ */
21
+ export declare const vTextFocus: ObjectDirective<HTMLElement, TextFocusBinding>;
22
+ export type { AutofocusOptions, TextFocusTarget };
23
+ //# sourceMappingURL=focus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../src/focus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,KAAK,CAAA;AACjF,OAAO,EAAiC,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAE9I,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,CAAC,gBAAgB,GAAG;IAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;AAExH;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,gBAAgB,CAAC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,EACvD,OAAO,GAAE,gBAAgB,CAAC,gBAAgB,GAAG;IAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAM,GACzF,IAAI,CAsBN;AAMD;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE,eAAe,CAAC,WAAW,EAAE,gBAAgB,CAWrE,CAAA;AAiBD,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAA"}
package/dist/focus.js ADDED
@@ -0,0 +1,60 @@
1
+ import { toValue, watch } from 'vue';
2
+ import { autofocusFlags, bindTextFocus } from '@handsforbots/widget/focus';
3
+ /**
4
+ * Focus a text field. Pass a template ref (or a getter) for that field.
5
+ * `onLoad` focuses when the field is available and again if the switch turns
6
+ * on later. `onClick` focuses on a click that is not a control or a text
7
+ * selection. In a template, `v-text-focus` names the element for you.
8
+ */
9
+ export function useTextFocus(input, options = {}) {
10
+ watch([
11
+ () => toValue(input) ?? null,
12
+ () => toValue(options)?.onLoad === true,
13
+ () => toValue(options)?.onClick === true,
14
+ () => toValue(options)?.within,
15
+ ], ([element, onLoad, onClick, within], previous, onCleanup) => {
16
+ const hadField = previous?.[0] instanceof HTMLElement;
17
+ const loadedAlready = previous?.[1] === true && hadField;
18
+ onCleanup(bindTextFocus({
19
+ input: () => toValue(input) ?? element,
20
+ onLoad: onLoad && !loadedAlready,
21
+ onClick,
22
+ ...(within === undefined ? {} : { within }),
23
+ }));
24
+ }, { immediate: true });
25
+ }
26
+ const memory = new WeakMap();
27
+ /**
28
+ * Vue directive: the element it sits on is the text field.
29
+ * `v-text-focus="true"` is the load switch. `v-text-focus="{ onLoad, onClick }"`
30
+ * sets each switch. `h4bVue` registers it; import `vTextFocus` to use it locally.
31
+ * The browser's `autofocus` attribute is the load switch alone, applied once.
32
+ */
33
+ export const vTextFocus = {
34
+ mounted(element, binding) {
35
+ sync(element, binding.value);
36
+ },
37
+ updated(element, binding) {
38
+ sync(element, binding.value);
39
+ },
40
+ unmounted(element) {
41
+ memory.get(element)?.stop();
42
+ memory.delete(element);
43
+ },
44
+ };
45
+ function sync(element, value) {
46
+ const flags = autofocusFlags(value);
47
+ const within = value && typeof value === 'object' ? value.within : undefined;
48
+ const previous = memory.get(element);
49
+ if (previous && previous.onLoad === flags.onLoad && previous.onClick === flags.onClick && previous.within === within)
50
+ return;
51
+ previous?.stop();
52
+ const stop = bindTextFocus({
53
+ input: element,
54
+ onLoad: flags.onLoad && !previous?.onLoad,
55
+ onClick: flags.onClick,
56
+ ...(within === undefined ? {} : { within }),
57
+ });
58
+ memory.set(element, { stop, onLoad: flags.onLoad, onClick: flags.onClick, within });
59
+ }
60
+ //# sourceMappingURL=focus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus.js","sourceRoot":"","sources":["../src/focus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAA+C,MAAM,KAAK,CAAA;AACjF,OAAO,EAAE,cAAc,EAAE,aAAa,EAAsE,MAAM,4BAA4B,CAAA;AAI9I;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAuD,EACvD,OAAO,GAAiF,EAAE;IAE1F,KAAK,CACH;QACE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI;QAC5B,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI;QACvC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI;QACxC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM;KA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OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;IAC5E,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACpC,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,IAAI,QAAQ,CAAC,MAAM,KAAK,MAAM;QAAE,OAAM;IAC5H,QAAQ,EAAE,IAAI,EAAE,CAAA;IAChB,MAAM,IAAI,GAAG,aAAa,CAAC;QACzB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,MAAM;QACzC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;KAC5C,CAAC,CAAA;IACF,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;AACrF,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { type ComputedRef, type InjectionKey, type MaybeRefOrGetter, type Plugin, type ShallowRef } from 'vue';
2
+ import { vTextFocus } from './focus.js';
3
+ import { type ActionDefinition, type Events, type H4B, type H4BSnapshot, type Message, type Modality, type Services, type SourceView, type TurnStatus } from '@handsforbots/core';
4
+ export declare const H4BKey: InjectionKey<H4B>;
5
+ /**
6
+ * Vue plugin that makes an H4B instance available to composables. Create and
7
+ * start the instance outside components (it owns plugins, devices and
8
+ * connections):
9
+ *
10
+ * const h4b = createH4B({ plugins: [...] })
11
+ * await h4b.start()
12
+ * createApp(App).use(h4bVue(h4b)).mount('#app')
13
+ */
14
+ export declare function h4bVue(h4b: H4B): Plugin;
15
+ /** Provides an H4B instance to a component subtree (alternative to `h4bVue`). */
16
+ export declare function provideH4B(h4b: H4B): void;
17
+ export declare function useH4B(): H4B;
18
+ /**
19
+ * Subscribes to the kernel store. Select fields of the snapshot (they keep
20
+ * their identity until they change) rather than building new objects; the
21
+ * ref only triggers when the selected value changes.
22
+ */
23
+ export declare function useH4BState<T = H4BSnapshot>(selector?: (snapshot: H4BSnapshot) => T): Readonly<ShallowRef<T>>;
24
+ export declare const useMessages: () => Readonly<ShallowRef<Message[]>>;
25
+ export declare const useTurn: () => Readonly<ShallowRef<TurnStatus | undefined>>;
26
+ export declare const useBusy: () => Readonly<ShallowRef<boolean>>;
27
+ /**
28
+ * A message's sources split from its text (ADR 0014): `segments` (text and
29
+ * references), `cited` (numbered) and `consulted`. Render titles and excerpts
30
+ * as text, and links only through `safeSourceUrl`.
31
+ */
32
+ export declare const useSources: (message: MaybeRefOrGetter<Message>) => ComputedRef<SourceView>;
33
+ export declare const useSharedState: <T = unknown>() => Readonly<ShallowRef<T>>;
34
+ /** Listens to a kernel notification for the component's (or scope's) lifetime. */
35
+ export declare function useH4BEvent<K extends keyof Events>(event: K, listener: (payload: Events[K]) => unknown): void;
36
+ /** Every stimulus as it arrives (UI effects, renders, deltas…). */
37
+ export declare function useStimulus(listener: (payload: Events['stimulus']) => unknown): void;
38
+ /**
39
+ * A plugin service (e.g. `voice`), kept up to date when it is provided or
40
+ * removed after the component mounted. `undefined` while it is not installed.
41
+ */
42
+ export declare function useService<K extends keyof Services>(key: K): Readonly<ShallowRef<Services[K] | undefined>>;
43
+ /** Any store-like plugin service (e.g. `voice`): `getState()` + `subscribe()`. */
44
+ export type ExternalStore<S> = {
45
+ getState(): S;
46
+ subscribe(listener: () => void): () => void;
47
+ };
48
+ /**
49
+ * Subscribes to a plugin service with state, e.g.
50
+ * `const voiceState = useStore(useService('voice'))`. The source may be a
51
+ * ref or getter; the subscription follows it. `undefined` while there is no
52
+ * store.
53
+ */
54
+ export declare function useStore<S>(source: MaybeRefOrGetter<ExternalStore<S> | undefined>): Readonly<ShallowRef<S | undefined>>;
55
+ /**
56
+ * Registers an action for the component's (or scope's) lifetime. The handler
57
+ * runs in the component's closure, so it always sees current refs.
58
+ */
59
+ export declare function useAction<I, O>(action: ActionDefinition<I, O>): void;
60
+ /**
61
+ * Keeps a context signal in sync with a value (current page, selection,
62
+ * filters…). Pass a ref or getter to follow changes; `undefined` removes it.
63
+ */
64
+ export declare function useContextSignal(key: string, value: MaybeRefOrGetter<unknown>, options?: {
65
+ modality?: Modality;
66
+ source?: string;
67
+ }): void;
68
+ export { useTextFocus, type AutofocusOptions, type TextFocusBinding, type TextFocusTarget } from './focus.js';
69
+ export { vTextFocus };
70
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,UAAU,EAChB,MAAM,KAAK,CAAA;AACZ,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAA;AAE3B,eAAO,MAAM,MAAM,EAAE,YAAY,CAAC,GAAG,CAAiB,CAAA;AAEtD;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAOvC;AAED,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAEzC;AAED,wBAAgB,MAAM,IAAI,GAAG,CAI5B;AAED;;;;GAIG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E,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;CAAE,CAAA;AAE7F;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,GACrD,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAYrC;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAEpE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAChC,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GACrD,IAAI,CAuBN;AAED,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AAC7G,OAAO,EAAE,UAAU,EAAE,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,128 @@
1
+ import { computed, inject, onScopeDispose, provide, shallowReadonly, shallowRef, toValue, watch, } from 'vue';
2
+ import { vTextFocus } from './focus.js';
3
+ import { sourceView, } from '@handsforbots/core';
4
+ export const H4BKey = Symbol('h4b');
5
+ /**
6
+ * Vue plugin that makes an H4B instance available to composables. Create and
7
+ * start the instance outside components (it owns plugins, devices and
8
+ * connections):
9
+ *
10
+ * const h4b = createH4B({ plugins: [...] })
11
+ * await h4b.start()
12
+ * createApp(App).use(h4bVue(h4b)).mount('#app')
13
+ */
14
+ export function h4bVue(h4b) {
15
+ return {
16
+ install(app) {
17
+ app.provide(H4BKey, h4b);
18
+ app.directive('text-focus', vTextFocus);
19
+ },
20
+ };
21
+ }
22
+ /** Provides an H4B instance to a component subtree (alternative to `h4bVue`). */
23
+ export function provideH4B(h4b) {
24
+ provide(H4BKey, h4b);
25
+ }
26
+ export function useH4B() {
27
+ const h4b = inject(H4BKey, null);
28
+ if (!h4b)
29
+ throw new Error('[h4b] useH4B needs app.use(h4bVue(h4b)) or provideH4B(h4b) in an ancestor');
30
+ return h4b;
31
+ }
32
+ /**
33
+ * Subscribes to the kernel store. Select fields of the snapshot (they keep
34
+ * their identity until they change) rather than building new objects; the
35
+ * ref only triggers when the selected value changes.
36
+ */
37
+ export function useH4BState(selector = (s) => s) {
38
+ const h4b = useH4B();
39
+ const state = shallowRef(selector(h4b.getSnapshot()));
40
+ const unsubscribe = h4b.subscribe(() => {
41
+ state.value = selector(h4b.getSnapshot());
42
+ });
43
+ onScopeDispose(unsubscribe);
44
+ return shallowReadonly(state);
45
+ }
46
+ export const useMessages = () => useH4BState((s) => s.messages);
47
+ export const useTurn = () => useH4BState((s) => s.turn);
48
+ export const useBusy = () => useH4BState((s) => s.busy);
49
+ /**
50
+ * A message's sources split from its text (ADR 0014): `segments` (text and
51
+ * references), `cited` (numbered) and `consulted`. Render titles and excerpts
52
+ * as text, and links only through `safeSourceUrl`.
53
+ */
54
+ export const useSources = (message) => computed(() => sourceView(toValue(message)));
55
+ export const useSharedState = () => useH4BState((s) => s.state);
56
+ /** Listens to a kernel notification for the component's (or scope's) lifetime. */
57
+ export function useH4BEvent(event, listener) {
58
+ onScopeDispose(useH4B().on(event, listener));
59
+ }
60
+ /** Every stimulus as it arrives (UI effects, renders, deltas…). */
61
+ export function useStimulus(listener) {
62
+ useH4BEvent('stimulus', listener);
63
+ }
64
+ /**
65
+ * A plugin service (e.g. `voice`), kept up to date when it is provided or
66
+ * removed after the component mounted. `undefined` while it is not installed.
67
+ */
68
+ export function useService(key) {
69
+ const h4b = useH4B();
70
+ const service = shallowRef(h4b.get(key));
71
+ const refresh = (payload) => {
72
+ if (payload.key === key)
73
+ service.value = h4b.get(key);
74
+ };
75
+ onScopeDispose(h4b.on('service.provided', refresh));
76
+ onScopeDispose(h4b.on('service.removed', refresh));
77
+ return shallowReadonly(service);
78
+ }
79
+ /**
80
+ * Subscribes to a plugin service with state, e.g.
81
+ * `const voiceState = useStore(useService('voice'))`. The source may be a
82
+ * ref or getter; the subscription follows it. `undefined` while there is no
83
+ * store.
84
+ */
85
+ export function useStore(source) {
86
+ const state = shallowRef();
87
+ watch(() => toValue(source), (store, _previous, onCleanup) => {
88
+ state.value = store?.getState();
89
+ if (!store)
90
+ return;
91
+ onCleanup(store.subscribe(() => (state.value = store.getState())));
92
+ }, { immediate: true, flush: 'sync' });
93
+ return shallowReadonly(state);
94
+ }
95
+ /**
96
+ * Registers an action for the component's (or scope's) lifetime. The handler
97
+ * runs in the component's closure, so it always sees current refs.
98
+ */
99
+ export function useAction(action) {
100
+ onScopeDispose(useH4B().actions.register(action));
101
+ }
102
+ /**
103
+ * Keeps a context signal in sync with a value (current page, selection,
104
+ * filters…). Pass a ref or getter to follow changes; `undefined` removes it.
105
+ */
106
+ export function useContextSignal(key, value, options = {}) {
107
+ const h4b = useH4B();
108
+ watch(() => {
109
+ const current = toValue(value);
110
+ return current === undefined ? undefined : JSON.stringify(current);
111
+ }, (serialized) => {
112
+ if (serialized === undefined) {
113
+ h4b.removeContext(key);
114
+ return;
115
+ }
116
+ h4b.signal({
117
+ kind: 'context',
118
+ key,
119
+ modality: options.modality ?? 'gui-event',
120
+ source: options.source ?? 'vue',
121
+ parts: [{ type: 'data', name: key, value: JSON.parse(serialized) }],
122
+ });
123
+ }, { immediate: true });
124
+ onScopeDispose(() => h4b.removeContext(key));
125
+ }
126
+ export { useTextFocus } from './focus.js';
127
+ export { vTextFocus };
128
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,MAAM,EACN,cAAc,EACd,OAAO,EACP,eAAe,EACf,UAAU,EACV,O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G,OAAO,CAAC,KAAK,CAAC,CAAA;QAC9B,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IACpE,CAAC,EACD,CAAC,UAAU,EAAE,EAAE;QACb,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;YACtB,OAAM;QACR,CAAC;QACD,GAAG,CAAC,MAAM,CAAC;YACT,IAAI,EAAE,SAAS;YACf,GAAG;YACH,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,WAAW;YACzC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK;YAC/B,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;SACpE,CAAC,CAAA;IACJ,CAAC,EACD,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CAAA;IACD,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAA;AAC9C,CAAC;AAED,OAAO,EAAE,YAAY,EAAsE,MAAM,YAAY,CAAA;AAC7G,OAAO,EAAE,UAAU,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@handsforbots/vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "2.0.0-alpha.1",
4
+ "description": "UI. Vue bindings for Hands for Bots: plugin and composables for messages, actions, context and stimuli.",
5
+ "keywords": [
6
+ "handsforbots",
7
+ "h4b",
8
+ "h4b-ui"
9
+ ],
10
+ "license": "MIT",
11
+ "homepage": "https://github.com/handsforbots/handsforbots/blob/main/docs/en-us/plugins.md#vue",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/handsforbots/handsforbots.git",
15
+ "directory": "packages/vue"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/handsforbots/handsforbots/issues"
19
+ },
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js"
26
+ }
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "peerDependencies": {
35
+ "vue": ">=3.3",
36
+ "@handsforbots/core": "^2.0.0-alpha.1"
37
+ },
38
+ "dependencies": {
39
+ "@handsforbots/widget": "^2.0.0-alpha.1"
40
+ },
41
+ "devDependencies": {
42
+ "jsdom": "^27.0.0",
43
+ "vue": "^3.5.0",
44
+ "@handsforbots/core": "^2.0.0-alpha.1",
45
+ "@handsforbots/voice": "^2.0.0-alpha.1"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.build.json",
49
+ "typecheck": "tsc -p tsconfig.json --noEmit"
50
+ }
6
51
  }