@fiodos/web-core 0.1.0

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.
Files changed (84) hide show
  1. package/LICENSE +77 -0
  2. package/dist/cjs/adapters/webNavigationAdapter.d.ts +31 -0
  3. package/dist/cjs/adapters/webNavigationAdapter.js +45 -0
  4. package/dist/cjs/adapters/webStorageAdapter.d.ts +13 -0
  5. package/dist/cjs/adapters/webStorageAdapter.js +57 -0
  6. package/dist/cjs/adapters/webVoiceAdapter.d.ts +16 -0
  7. package/dist/cjs/adapters/webVoiceAdapter.js +477 -0
  8. package/dist/cjs/api/backendClient.d.ts +31 -0
  9. package/dist/cjs/api/backendClient.js +182 -0
  10. package/dist/cjs/api/backendTelemetry.d.ts +23 -0
  11. package/dist/cjs/api/backendTelemetry.js +80 -0
  12. package/dist/cjs/api/clientBootstrap.d.ts +44 -0
  13. package/dist/cjs/api/clientBootstrap.js +68 -0
  14. package/dist/cjs/api/errors.d.ts +11 -0
  15. package/dist/cjs/api/errors.js +16 -0
  16. package/dist/cjs/bridge/createBridge.d.ts +13 -0
  17. package/dist/cjs/bridge/createBridge.js +15 -0
  18. package/dist/cjs/config/types.d.ts +63 -0
  19. package/dist/cjs/config/types.js +9 -0
  20. package/dist/cjs/context/screenContextStore.d.ts +26 -0
  21. package/dist/cjs/context/screenContextStore.js +25 -0
  22. package/dist/cjs/controller/AgentController.d.ts +115 -0
  23. package/dist/cjs/controller/AgentController.js +594 -0
  24. package/dist/cjs/core/turnEngine.d.ts +70 -0
  25. package/dist/cjs/core/turnEngine.js +96 -0
  26. package/dist/cjs/dropin/createFiodosAgent.d.ts +60 -0
  27. package/dist/cjs/dropin/createFiodosAgent.js +143 -0
  28. package/dist/cjs/dropin/createFyodosAgent.d.ts +60 -0
  29. package/dist/cjs/dropin/createFyodosAgent.js +143 -0
  30. package/dist/cjs/index.d.ts +45 -0
  31. package/dist/cjs/index.js +67 -0
  32. package/dist/cjs/orb/mountOrb.d.ts +24 -0
  33. package/dist/cjs/orb/mountOrb.js +694 -0
  34. package/dist/cjs/orb/orbView.d.ts +56 -0
  35. package/dist/cjs/orb/orbView.js +426 -0
  36. package/dist/cjs/orb/publishedConfig.d.ts +32 -0
  37. package/dist/cjs/orb/publishedConfig.js +70 -0
  38. package/dist/cjs/package.json +1 -0
  39. package/dist/cjs/speech/speechSession.d.ts +35 -0
  40. package/dist/cjs/speech/speechSession.js +60 -0
  41. package/dist/cjs/ui/messages.d.ts +36 -0
  42. package/dist/cjs/ui/messages.js +41 -0
  43. package/dist/esm/adapters/webNavigationAdapter.d.ts +31 -0
  44. package/dist/esm/adapters/webNavigationAdapter.js +41 -0
  45. package/dist/esm/adapters/webStorageAdapter.d.ts +13 -0
  46. package/dist/esm/adapters/webStorageAdapter.js +54 -0
  47. package/dist/esm/adapters/webVoiceAdapter.d.ts +16 -0
  48. package/dist/esm/adapters/webVoiceAdapter.js +474 -0
  49. package/dist/esm/api/backendClient.d.ts +31 -0
  50. package/dist/esm/api/backendClient.js +178 -0
  51. package/dist/esm/api/backendTelemetry.d.ts +23 -0
  52. package/dist/esm/api/backendTelemetry.js +77 -0
  53. package/dist/esm/api/clientBootstrap.d.ts +44 -0
  54. package/dist/esm/api/clientBootstrap.js +63 -0
  55. package/dist/esm/api/errors.d.ts +11 -0
  56. package/dist/esm/api/errors.js +11 -0
  57. package/dist/esm/bridge/createBridge.d.ts +13 -0
  58. package/dist/esm/bridge/createBridge.js +12 -0
  59. package/dist/esm/config/types.d.ts +63 -0
  60. package/dist/esm/config/types.js +6 -0
  61. package/dist/esm/context/screenContextStore.d.ts +26 -0
  62. package/dist/esm/context/screenContextStore.js +22 -0
  63. package/dist/esm/controller/AgentController.d.ts +115 -0
  64. package/dist/esm/controller/AgentController.js +590 -0
  65. package/dist/esm/core/turnEngine.d.ts +70 -0
  66. package/dist/esm/core/turnEngine.js +92 -0
  67. package/dist/esm/dropin/createFiodosAgent.d.ts +60 -0
  68. package/dist/esm/dropin/createFiodosAgent.js +140 -0
  69. package/dist/esm/dropin/createFyodosAgent.d.ts +60 -0
  70. package/dist/esm/dropin/createFyodosAgent.js +140 -0
  71. package/dist/esm/index.d.ts +45 -0
  72. package/dist/esm/index.js +38 -0
  73. package/dist/esm/orb/mountOrb.d.ts +24 -0
  74. package/dist/esm/orb/mountOrb.js +691 -0
  75. package/dist/esm/orb/orbView.d.ts +56 -0
  76. package/dist/esm/orb/orbView.js +421 -0
  77. package/dist/esm/orb/publishedConfig.d.ts +32 -0
  78. package/dist/esm/orb/publishedConfig.js +67 -0
  79. package/dist/esm/package.json +1 -0
  80. package/dist/esm/speech/speechSession.d.ts +35 -0
  81. package/dist/esm/speech/speechSession.js +57 -0
  82. package/dist/esm/ui/messages.d.ts +36 -0
  83. package/dist/esm/ui/messages.js +38 -0
  84. package/package.json +38 -0
@@ -0,0 +1,36 @@
1
+ /**
2
+ * UI strings for the web orb (buttons, modal titles, consent copy). Spoken
3
+ * agent messages come from @fiodos/core's AgentMessages; these are only the
4
+ * DOM-chrome labels the orb renders. English and Spanish ship built-in.
5
+ */
6
+ export interface WebUiMessages {
7
+ /** Accessible label for the orb button. */
8
+ orbLabel: string;
9
+ /** Confirmation modal title. */
10
+ confirmTitle: string;
11
+ /** Confirm button label. */
12
+ confirmLabel: string;
13
+ /** Cancel button label. */
14
+ cancelLabel: string;
15
+ /** Consent modal title. */
16
+ consentTitle: string;
17
+ /** Consent body paragraph. */
18
+ consentBody: string;
19
+ /** Consent accept button. */
20
+ consentAccept: string;
21
+ /** Consent decline button. */
22
+ consentDecline: string;
23
+ /** Placeholder for the text input bubble. */
24
+ textPlaceholder: string;
25
+ /** Accessible label for the keyboard chip beside the orb. */
26
+ keyboardChipLabel: string;
27
+ /** Send button label for the text bubble. */
28
+ sendLabel: string;
29
+ /** Spoken/shown when the browser lacks speech recognition. */
30
+ voiceUnavailable: string;
31
+ }
32
+ export interface ResolveUiMessagesOptions {
33
+ catalogs?: Record<string, WebUiMessages>;
34
+ overrides?: Partial<WebUiMessages>;
35
+ }
36
+ export declare function resolveUiMessages(locale: string, options?: ResolveUiMessagesOptions): WebUiMessages;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveUiMessages = resolveUiMessages;
4
+ const en = {
5
+ orbLabel: 'Voice assistant',
6
+ confirmTitle: 'Confirm',
7
+ confirmLabel: 'Confirm',
8
+ cancelLabel: 'Cancel',
9
+ consentTitle: 'Voice assistant',
10
+ consentBody: 'This assistant uses your microphone to understand voice commands and may navigate or perform actions in this app on your behalf. Your speech is processed to answer you and is not stored as a transcript.',
11
+ consentAccept: 'Allow',
12
+ consentDecline: 'Not now',
13
+ textPlaceholder: 'Type a message…',
14
+ keyboardChipLabel: 'Type instead of talking',
15
+ sendLabel: 'Send',
16
+ voiceUnavailable: 'Voice input is not available in this browser. You can type instead.',
17
+ };
18
+ const es = {
19
+ orbLabel: 'Asistente de voz',
20
+ confirmTitle: 'Confirmar',
21
+ confirmLabel: 'Confirmar',
22
+ cancelLabel: 'Cancelar',
23
+ consentTitle: 'Asistente de voz',
24
+ consentBody: 'Este asistente usa tu micrófono para entender comandos de voz y puede navegar o realizar acciones en esta app en tu nombre. Tu voz se procesa para responderte y no se guarda como transcripción.',
25
+ consentAccept: 'Permitir',
26
+ consentDecline: 'Ahora no',
27
+ textPlaceholder: 'Escribe un mensaje…',
28
+ keyboardChipLabel: 'Escribir en lugar de hablar',
29
+ sendLabel: 'Enviar',
30
+ voiceUnavailable: 'La entrada por voz no está disponible en este navegador. Puedes escribir.',
31
+ };
32
+ const CATALOGS = { en, es };
33
+ function baseLanguage(locale) {
34
+ return locale.split(/[-_]/)[0]?.toLowerCase() ?? locale.toLowerCase();
35
+ }
36
+ function resolveUiMessages(locale, options = {}) {
37
+ const externals = options.catalogs ?? {};
38
+ const base = baseLanguage(locale);
39
+ const resolved = externals[locale] ?? CATALOGS[locale] ?? externals[base] ?? CATALOGS[base] ?? en;
40
+ return options.overrides ? { ...resolved, ...options.overrides } : resolved;
41
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Web NavigationAdapter — framework-agnostic. The manifest route strings for a
3
+ * web app are URL paths (e.g. "/cart"). The host provides a `navigate` delegate
4
+ * (Vue Router's `router.push`, SvelteKit's `goto`, Angular Router's
5
+ * `navigateByUrl`, or a plain `location.assign`) and the adapter forwards the
6
+ * opaque route string. The router owns query-string / param interpretation.
7
+ *
8
+ * `setCurrentRoute` lets the host keep `getCurrentRoute()` in sync with the
9
+ * live pathname (telemetry + LLM context). No framework imports here — each
10
+ * binding wires its own router-change subscription.
11
+ */
12
+ import type { NavigationAdapter } from '@fiodos/core';
13
+ export declare const BACK_ROUTE = "BACK";
14
+ export interface WebNavigationAdapterOptions {
15
+ /**
16
+ * Forwards a manifest route string to the host router. MUST throw on failure
17
+ * so the engine can degrade to an ActionResult error.
18
+ */
19
+ navigate: (route: string) => void;
20
+ /** Go back. Defaults to history.back() (or backFallbackRoute when empty). */
21
+ back?: () => void;
22
+ /** Current route. Defaults to location.pathname + location.search. */
23
+ getCurrentRoute?: () => string | null;
24
+ /** Route navigated to when back() is called with no history. */
25
+ backFallbackRoute?: string;
26
+ }
27
+ export interface WebNavigationAdapter extends NavigationAdapter {
28
+ /** Updates the tracked current route (called by the host on route change). */
29
+ setCurrentRoute(route: string | null): void;
30
+ }
31
+ export declare function createWebNavigationAdapter(options: WebNavigationAdapterOptions): WebNavigationAdapter;
@@ -0,0 +1,41 @@
1
+ export const BACK_ROUTE = 'BACK';
2
+ function defaultCurrentRoute() {
3
+ if (typeof window === 'undefined' || !window.location)
4
+ return null;
5
+ return `${window.location.pathname}${window.location.search}`;
6
+ }
7
+ export function createWebNavigationAdapter(options) {
8
+ let tracked = null;
9
+ let hasNavigated = false;
10
+ return {
11
+ navigate(route) {
12
+ if (!route || route === BACK_ROUTE) {
13
+ this.back();
14
+ return;
15
+ }
16
+ hasNavigated = true;
17
+ options.navigate(route);
18
+ },
19
+ back() {
20
+ if (options.back) {
21
+ options.back();
22
+ return;
23
+ }
24
+ if (hasNavigated && typeof window !== 'undefined' && window.history?.length > 1) {
25
+ window.history.back();
26
+ return;
27
+ }
28
+ if (options.backFallbackRoute) {
29
+ options.navigate(options.backFallbackRoute);
30
+ }
31
+ },
32
+ getCurrentRoute() {
33
+ if (tracked != null)
34
+ return tracked;
35
+ return options.getCurrentRoute ? options.getCurrentRoute() : defaultCurrentRoute();
36
+ },
37
+ setCurrentRoute(route) {
38
+ tracked = route;
39
+ },
40
+ };
41
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Web StorageAdapter — backs the consent manager (and any future per-app
3
+ * preferences) with window.localStorage by default. The @fiodos/core contract
4
+ * is async; localStorage is sync, so we wrap calls in resolved promises. If
5
+ * localStorage is unavailable (private mode, SSR, disabled) we degrade to an
6
+ * in-memory map (consent just won't persist across reloads).
7
+ */
8
+ import type { StorageAdapter } from '@fiodos/core';
9
+ export interface WebStorageAdapterOptions {
10
+ /** Storage backend. Defaults to window.localStorage. */
11
+ backend?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
12
+ }
13
+ export declare function createWebStorageAdapter(options?: WebStorageAdapterOptions): StorageAdapter;
@@ -0,0 +1,54 @@
1
+ function resolveBackend(preferred) {
2
+ if (preferred)
3
+ return preferred;
4
+ try {
5
+ if (typeof window !== 'undefined' && window.localStorage) {
6
+ const probe = '__fyodos_probe__';
7
+ window.localStorage.setItem(probe, '1');
8
+ window.localStorage.removeItem(probe);
9
+ return window.localStorage;
10
+ }
11
+ }
12
+ catch {
13
+ /* localStorage blocked — fall through to memory */
14
+ }
15
+ const mem = new Map();
16
+ return {
17
+ getItem: (k) => (mem.has(k) ? mem.get(k) : null),
18
+ setItem: (k, v) => {
19
+ mem.set(k, v);
20
+ },
21
+ removeItem: (k) => {
22
+ mem.delete(k);
23
+ },
24
+ };
25
+ }
26
+ export function createWebStorageAdapter(options = {}) {
27
+ const backend = resolveBackend(options.backend);
28
+ return {
29
+ async getItem(key) {
30
+ try {
31
+ return backend.getItem(key);
32
+ }
33
+ catch {
34
+ return null;
35
+ }
36
+ },
37
+ async setItem(key, value) {
38
+ try {
39
+ backend.setItem(key, value);
40
+ }
41
+ catch {
42
+ /* quota/availability errors are non-fatal for consent */
43
+ }
44
+ },
45
+ async removeItem(key) {
46
+ try {
47
+ backend.removeItem(key);
48
+ }
49
+ catch {
50
+ /* non-fatal */
51
+ }
52
+ },
53
+ };
54
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Web VoiceAdapter — browser STT via the Web Speech API
3
+ * (`SpeechRecognition` / `webkitSpeechRecognition`) and TTS playback of
4
+ * server-generated MP3 (base64) through an <audio> element, with a device
5
+ * SpeechSynthesis fallback. Availability is browser-dependent (Chrome/Edge/
6
+ * Safari yes; Firefox no), so `isRecognitionAvailable()` is honest and the UI
7
+ * must fall back to text input when it returns false.
8
+ *
9
+ * Framework-agnostic: shared by every Fiodos web binding.
10
+ */
11
+ import type { VoiceAdapter } from '@fiodos/core';
12
+ export interface WebVoiceAdapterOptions {
13
+ /** Disable the SpeechSynthesis fallback when server MP3 is missing. */
14
+ disableDeviceTtsFallback?: boolean;
15
+ }
16
+ export declare function createWebVoiceAdapter(options?: WebVoiceAdapterOptions): VoiceAdapter;