@molecule/app-react 1.0.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 (131) hide show
  1. package/LICENSE +115 -0
  2. package/README.md +2645 -0
  3. package/dist/agent-identity.d.ts +40 -0
  4. package/dist/agent-identity.d.ts.map +1 -0
  5. package/dist/agent-identity.js +31 -0
  6. package/dist/agent-identity.js.map +1 -0
  7. package/dist/contexts.d.ts +69 -0
  8. package/dist/contexts.d.ts.map +1 -0
  9. package/dist/contexts.js +70 -0
  10. package/dist/contexts.js.map +1 -0
  11. package/dist/hooks/index.d.ts +32 -0
  12. package/dist/hooks/index.d.ts.map +1 -0
  13. package/dist/hooks/index.js +32 -0
  14. package/dist/hooks/index.js.map +1 -0
  15. package/dist/hooks/useAIModels.d.ts +48 -0
  16. package/dist/hooks/useAIModels.d.ts.map +1 -0
  17. package/dist/hooks/useAIModels.js +145 -0
  18. package/dist/hooks/useAIModels.js.map +1 -0
  19. package/dist/hooks/useAsyncState.d.ts +41 -0
  20. package/dist/hooks/useAsyncState.d.ts.map +1 -0
  21. package/dist/hooks/useAsyncState.js +77 -0
  22. package/dist/hooks/useAsyncState.js.map +1 -0
  23. package/dist/hooks/useAuth.d.ts +43 -0
  24. package/dist/hooks/useAuth.d.ts.map +1 -0
  25. package/dist/hooks/useAuth.js +106 -0
  26. package/dist/hooks/useAuth.js.map +1 -0
  27. package/dist/hooks/useCapacitorApp.d.ts +35 -0
  28. package/dist/hooks/useCapacitorApp.d.ts.map +1 -0
  29. package/dist/hooks/useCapacitorApp.js +61 -0
  30. package/dist/hooks/useCapacitorApp.js.map +1 -0
  31. package/dist/hooks/useChangePassword.d.ts +34 -0
  32. package/dist/hooks/useChangePassword.d.ts.map +1 -0
  33. package/dist/hooks/useChangePassword.js +37 -0
  34. package/dist/hooks/useChangePassword.js.map +1 -0
  35. package/dist/hooks/useChat.d.ts +30 -0
  36. package/dist/hooks/useChat.d.ts.map +1 -0
  37. package/dist/hooks/useChat.js +1510 -0
  38. package/dist/hooks/useChat.js.map +1 -0
  39. package/dist/hooks/useDevice.d.ts +39 -0
  40. package/dist/hooks/useDevice.d.ts.map +1 -0
  41. package/dist/hooks/useDevice.js +41 -0
  42. package/dist/hooks/useDevice.js.map +1 -0
  43. package/dist/hooks/useEditor.d.ts +20 -0
  44. package/dist/hooks/useEditor.d.ts.map +1 -0
  45. package/dist/hooks/useEditor.js +98 -0
  46. package/dist/hooks/useEditor.js.map +1 -0
  47. package/dist/hooks/useForm.d.ts +87 -0
  48. package/dist/hooks/useForm.d.ts.map +1 -0
  49. package/dist/hooks/useForm.js +148 -0
  50. package/dist/hooks/useForm.js.map +1 -0
  51. package/dist/hooks/useHttp.d.ts +103 -0
  52. package/dist/hooks/useHttp.d.ts.map +1 -0
  53. package/dist/hooks/useHttp.js +161 -0
  54. package/dist/hooks/useHttp.js.map +1 -0
  55. package/dist/hooks/useLogger.d.ts +68 -0
  56. package/dist/hooks/useLogger.d.ts.map +1 -0
  57. package/dist/hooks/useLogger.js +95 -0
  58. package/dist/hooks/useLogger.js.map +1 -0
  59. package/dist/hooks/useLogin.d.ts +35 -0
  60. package/dist/hooks/useLogin.d.ts.map +1 -0
  61. package/dist/hooks/useLogin.js +37 -0
  62. package/dist/hooks/useLogin.js.map +1 -0
  63. package/dist/hooks/useOAuth.d.ts +83 -0
  64. package/dist/hooks/useOAuth.d.ts.map +1 -0
  65. package/dist/hooks/useOAuth.js +348 -0
  66. package/dist/hooks/useOAuth.js.map +1 -0
  67. package/dist/hooks/usePasswordReset.d.ts +43 -0
  68. package/dist/hooks/usePasswordReset.d.ts.map +1 -0
  69. package/dist/hooks/usePasswordReset.js +50 -0
  70. package/dist/hooks/usePasswordReset.js.map +1 -0
  71. package/dist/hooks/usePlatform.d.ts +38 -0
  72. package/dist/hooks/usePlatform.d.ts.map +1 -0
  73. package/dist/hooks/usePlatform.js +40 -0
  74. package/dist/hooks/usePlatform.js.map +1 -0
  75. package/dist/hooks/usePreview.d.ts +20 -0
  76. package/dist/hooks/usePreview.d.ts.map +1 -0
  77. package/dist/hooks/usePreview.js +62 -0
  78. package/dist/hooks/usePreview.js.map +1 -0
  79. package/dist/hooks/usePromise.d.ts +39 -0
  80. package/dist/hooks/usePromise.d.ts.map +1 -0
  81. package/dist/hooks/usePromise.js +92 -0
  82. package/dist/hooks/usePromise.js.map +1 -0
  83. package/dist/hooks/usePush.d.ts +50 -0
  84. package/dist/hooks/usePush.d.ts.map +1 -0
  85. package/dist/hooks/usePush.js +89 -0
  86. package/dist/hooks/usePush.js.map +1 -0
  87. package/dist/hooks/useRouter.d.ts +65 -0
  88. package/dist/hooks/useRouter.d.ts.map +1 -0
  89. package/dist/hooks/useRouter.js +120 -0
  90. package/dist/hooks/useRouter.js.map +1 -0
  91. package/dist/hooks/useSignup.d.ts +35 -0
  92. package/dist/hooks/useSignup.d.ts.map +1 -0
  93. package/dist/hooks/useSignup.js +37 -0
  94. package/dist/hooks/useSignup.js.map +1 -0
  95. package/dist/hooks/useStorage.d.ts +72 -0
  96. package/dist/hooks/useStorage.d.ts.map +1 -0
  97. package/dist/hooks/useStorage.js +144 -0
  98. package/dist/hooks/useStorage.js.map +1 -0
  99. package/dist/hooks/useStore.d.ts +51 -0
  100. package/dist/hooks/useStore.d.ts.map +1 -0
  101. package/dist/hooks/useStore.js +86 -0
  102. package/dist/hooks/useStore.js.map +1 -0
  103. package/dist/hooks/useTheme.d.ts +50 -0
  104. package/dist/hooks/useTheme.d.ts.map +1 -0
  105. package/dist/hooks/useTheme.js +135 -0
  106. package/dist/hooks/useTheme.js.map +1 -0
  107. package/dist/hooks/useTranslation.d.ts +69 -0
  108. package/dist/hooks/useTranslation.d.ts.map +1 -0
  109. package/dist/hooks/useTranslation.js +131 -0
  110. package/dist/hooks/useTranslation.js.map +1 -0
  111. package/dist/hooks/useVersion.d.ts +41 -0
  112. package/dist/hooks/useVersion.d.ts.map +1 -0
  113. package/dist/hooks/useVersion.js +73 -0
  114. package/dist/hooks/useVersion.js.map +1 -0
  115. package/dist/hooks/useWorkspace.d.ts +18 -0
  116. package/dist/hooks/useWorkspace.d.ts.map +1 -0
  117. package/dist/hooks/useWorkspace.js +67 -0
  118. package/dist/hooks/useWorkspace.js.map +1 -0
  119. package/dist/index.d.ts +80 -0
  120. package/dist/index.d.ts.map +1 -0
  121. package/dist/index.js +80 -0
  122. package/dist/index.js.map +1 -0
  123. package/dist/providers.d.ts +189 -0
  124. package/dist/providers.d.ts.map +1 -0
  125. package/dist/providers.js +248 -0
  126. package/dist/providers.js.map +1 -0
  127. package/dist/types.d.ts +381 -0
  128. package/dist/types.d.ts.map +1 -0
  129. package/dist/types.js +7 -0
  130. package/dist/types.js.map +1 -0
  131. package/package.json +82 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * React hook for authentication.
3
+ *
4
+ * @module
5
+ */
6
+ import type { AuthClient } from '@molecule/app-auth';
7
+ import type { UseAuthOptions, UseAuthResult } from '../types.js';
8
+ /**
9
+ * Hook to access the auth client from context.
10
+ *
11
+ * @returns The auth client from context
12
+ * @throws {Error} Error if used outside of AuthProvider
13
+ */
14
+ export declare function useAuthClient<T = unknown>(): AuthClient<T>;
15
+ /**
16
+ * Hook for authentication state and actions.
17
+ *
18
+ * @param options - Hook options
19
+ * @returns Auth state and action methods
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const { user, isAuthenticated, login, logout } = useAuth()
24
+ *
25
+ * if (isAuthenticated) {
26
+ * return <div>Welcome, {user.name}!</div>
27
+ * }
28
+ * ```
29
+ */
30
+ export declare function useAuth<T = unknown>(options?: UseAuthOptions): UseAuthResult<T>;
31
+ /**
32
+ * Hook to get just the authenticated user.
33
+ *
34
+ * @returns The authenticated user or null
35
+ */
36
+ export declare function useUser<T = unknown>(): T | null;
37
+ /**
38
+ * Hook to check if user is authenticated.
39
+ *
40
+ * @returns Whether the user is authenticated
41
+ */
42
+ export declare function useIsAuthenticated(): boolean;
43
+ //# sourceMappingURL=useAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,UAAU,EAA6C,MAAM,oBAAoB,CAAA;AAI/F,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,CAU1D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC,CAAC,CAAC,CAgE/E;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,GAAG,OAAO,KAAK,CAAC,GAAG,IAAI,CAG/C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAG5C"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * React hook for authentication.
3
+ *
4
+ * @module
5
+ */
6
+ import { useCallback, useContext, useEffect, useRef, useSyncExternalStore } from 'react';
7
+ import { t } from '@molecule/app-i18n';
8
+ import { AuthContext } from '../contexts.js';
9
+ /**
10
+ * Hook to access the auth client from context.
11
+ *
12
+ * @returns The auth client from context
13
+ * @throws {Error} Error if used outside of AuthProvider
14
+ */
15
+ export function useAuthClient() {
16
+ const client = useContext(AuthContext);
17
+ if (!client) {
18
+ throw new Error(t('react.error.useAuthOutsideProvider', undefined, {
19
+ defaultValue: 'useAuthClient must be used within an AuthProvider',
20
+ }));
21
+ }
22
+ return client;
23
+ }
24
+ /**
25
+ * Hook for authentication state and actions.
26
+ *
27
+ * @param options - Hook options
28
+ * @returns Auth state and action methods
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * const { user, isAuthenticated, login, logout } = useAuth()
33
+ *
34
+ * if (isAuthenticated) {
35
+ * return <div>Welcome, {user.name}!</div>
36
+ * }
37
+ * ```
38
+ */
39
+ export function useAuth(options) {
40
+ const client = useAuthClient();
41
+ const { autoRefresh = false } = options ?? {};
42
+ // Subscribe to auth state changes with cached snapshot
43
+ const cachedStateRef = useRef(null);
44
+ const getSnapshot = useCallback(() => {
45
+ const next = client.getState();
46
+ const prev = cachedStateRef.current;
47
+ if (prev !== null &&
48
+ prev.initialized === next.initialized &&
49
+ prev.authenticated === next.authenticated &&
50
+ prev.user === next.user &&
51
+ prev.loading === next.loading &&
52
+ prev.error === next.error) {
53
+ return prev;
54
+ }
55
+ cachedStateRef.current = next;
56
+ return next;
57
+ }, [client]);
58
+ const subscribe = useCallback((onStateChange) => {
59
+ return client.onAuthChange(() => onStateChange());
60
+ }, [client]);
61
+ const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
62
+ // Auto-refresh on mount if requested
63
+ useEffect(() => {
64
+ if (autoRefresh && !state.authenticated && !state.loading) {
65
+ client.refresh().catch(() => {
66
+ // Silently fail - user is just not authenticated
67
+ });
68
+ }
69
+ }, [autoRefresh, client, state.authenticated, state.loading]);
70
+ // Memoized action wrappers
71
+ const login = useCallback((credentials) => client.login(credentials), [client]);
72
+ const logout = useCallback(() => client.logout(), [client]);
73
+ const register = useCallback((data) => client.register(data), [client]);
74
+ const refresh = useCallback(() => client.refresh(), [client]);
75
+ const setUser = useCallback((user) => client.setUser(user), [client]);
76
+ return {
77
+ state,
78
+ login,
79
+ logout,
80
+ register,
81
+ refresh,
82
+ setUser,
83
+ isAuthenticated: state.authenticated,
84
+ isLoading: state.loading,
85
+ user: state.user,
86
+ };
87
+ }
88
+ /**
89
+ * Hook to get just the authenticated user.
90
+ *
91
+ * @returns The authenticated user or null
92
+ */
93
+ export function useUser() {
94
+ const { user } = useAuth();
95
+ return user;
96
+ }
97
+ /**
98
+ * Hook to check if user is authenticated.
99
+ *
100
+ * @returns Whether the user is authenticated
101
+ */
102
+ export function useIsAuthenticated() {
103
+ const { isAuthenticated } = useAuth();
104
+ return isAuthenticated;
105
+ }
106
+ //# sourceMappingURL=useAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * React hook for Capacitor app initialization.
3
+ *
4
+ * @module
5
+ */
6
+ import { type CapacitorAppOptions, type CapacitorAppState } from '@molecule/app-platform';
7
+ /**
8
+ * Hook return type.
9
+ */
10
+ export type UseCapacitorAppResult = CapacitorAppState & {
11
+ initialize: () => Promise<void>;
12
+ };
13
+ /**
14
+ * Hook for Capacitor app initialization and state management.
15
+ *
16
+ * Creates a `CapacitorApp` coordinator on mount, subscribes to state changes,
17
+ * and auto-initializes. Cleans up listeners on unmount via `destroy()`.
18
+ *
19
+ * @param options - Capacitor app configuration options
20
+ * @returns Current app state and an `initialize` function for manual re-initialization
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const { ready, deviceReady, pushReady, error } = useCapacitorApp({
25
+ * pushNotifications: true,
26
+ * deepLinks: true,
27
+ * onDeepLink: (url) => navigate(url),
28
+ * })
29
+ *
30
+ * if (!ready) return <SplashScreen />
31
+ * if (error) return <ErrorScreen error={error} />
32
+ * ```
33
+ */
34
+ export declare function useCapacitorApp(options?: CapacitorAppOptions): UseCapacitorAppResult;
35
+ //# sourceMappingURL=useCapacitorApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCapacitorApp.d.ts","sourceRoot":"","sources":["../../src/hooks/useCapacitorApp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAA;AAE/B;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,GAAG;IACtD,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAChC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,mBAAwB,GAAG,qBAAqB,CAuCxF"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * React hook for Capacitor app initialization.
3
+ *
4
+ * @module
5
+ */
6
+ import { useCallback, useEffect, useRef, useState } from 'react';
7
+ import { createCapacitorApp, } from '@molecule/app-platform';
8
+ /**
9
+ * Hook for Capacitor app initialization and state management.
10
+ *
11
+ * Creates a `CapacitorApp` coordinator on mount, subscribes to state changes,
12
+ * and auto-initializes. Cleans up listeners on unmount via `destroy()`.
13
+ *
14
+ * @param options - Capacitor app configuration options
15
+ * @returns Current app state and an `initialize` function for manual re-initialization
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * const { ready, deviceReady, pushReady, error } = useCapacitorApp({
20
+ * pushNotifications: true,
21
+ * deepLinks: true,
22
+ * onDeepLink: (url) => navigate(url),
23
+ * })
24
+ *
25
+ * if (!ready) return <SplashScreen />
26
+ * if (error) return <ErrorScreen error={error} />
27
+ * ```
28
+ */
29
+ export function useCapacitorApp(options = {}) {
30
+ const appRef = useRef(null);
31
+ // Lazy-init the app instance so it's only created once
32
+ if (!appRef.current) {
33
+ appRef.current = createCapacitorApp(options);
34
+ }
35
+ const [state, setState] = useState(() => appRef.current.getState());
36
+ const initialize = useCallback(async () => {
37
+ if (appRef.current) {
38
+ await appRef.current.initialize();
39
+ }
40
+ }, []);
41
+ useEffect(() => {
42
+ const app = appRef.current;
43
+ // Subscribe to state changes
44
+ const unsubscribe = app.subscribe((newState) => {
45
+ setState(newState);
46
+ });
47
+ // Auto-initialize on mount
48
+ app.initialize().catch(() => {
49
+ // Error is captured in state via the coordinator
50
+ });
51
+ return () => {
52
+ unsubscribe();
53
+ app.destroy();
54
+ };
55
+ }, []);
56
+ return {
57
+ ...state,
58
+ initialize,
59
+ };
60
+ }
61
+ //# sourceMappingURL=useCapacitorApp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCapacitorApp.js","sourceRoot":"","sources":["../../src/hooks/useCapacitorApp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhE,OAAO,EAIL,kBAAkB,GACnB,MAAM,wBAAwB,CAAA;AAS/B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,eAAe,CAAC,UAA+B,EAAE;IAC/D,MAAM,MAAM,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAA;IAEhD,uDAAuD;IACvD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAC9C,CAAC;IAED,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAoB,GAAG,EAAE,CAAC,MAAM,CAAC,OAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;IAEvF,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACxC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAA;QACnC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,GAAG,GAAG,MAAM,CAAC,OAAQ,CAAA;QAE3B,6BAA6B;QAC7B,MAAM,WAAW,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC7C,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACpB,CAAC,CAAC,CAAA;QAEF,2BAA2B;QAC3B,GAAG,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;YAC1B,iDAAiD;QACnD,CAAC,CAAC,CAAA;QAEF,OAAO,GAAG,EAAE;YACV,WAAW,EAAE,CAAA;YACb,GAAG,CAAC,OAAO,EAAE,CAAA;QACf,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,GAAG,KAAK;QACR,UAAU;KACX,CAAA;AACH,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * React hook for changing password with async state tracking.
3
+ *
4
+ * @module
5
+ */
6
+ import { type UsePromiseState } from './usePromise.js';
7
+ /**
8
+ * Return type for useChangePassword hook.
9
+ */
10
+ export interface UseChangePasswordReturn {
11
+ status: UsePromiseState<void>['status'];
12
+ error: UsePromiseState<void>['error'];
13
+ changePassword: (oldPassword: string, newPassword: string) => Promise<void>;
14
+ reset: () => void;
15
+ }
16
+ /**
17
+ * Hook for changing password with async state tracking.
18
+ *
19
+ * @returns Change password state and action
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const { status, error, changePassword } = useChangePassword()
24
+ *
25
+ * <button
26
+ * onClick={() => changePassword(oldPassword, newPassword)}
27
+ * disabled={status === 'pending'}
28
+ * >
29
+ * {status === 'pending' ? 'Changing...' : 'Change Password'}
30
+ * </button>
31
+ * ```
32
+ */
33
+ export declare function useChangePassword(): UseChangePasswordReturn;
34
+ //# sourceMappingURL=useChangePassword.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChangePassword.d.ts","sourceRoot":"","sources":["../../src/hooks/useChangePassword.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAElE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAA;IACvC,KAAK,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAA;IACrC,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3E,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,IAAI,uBAAuB,CAgB3D"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * React hook for changing password with async state tracking.
3
+ *
4
+ * @module
5
+ */
6
+ import { useCallback } from 'react';
7
+ import { useAuthClient } from './useAuth.js';
8
+ import { usePromise } from './usePromise.js';
9
+ /**
10
+ * Hook for changing password with async state tracking.
11
+ *
12
+ * @returns Change password state and action
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * const { status, error, changePassword } = useChangePassword()
17
+ *
18
+ * <button
19
+ * onClick={() => changePassword(oldPassword, newPassword)}
20
+ * disabled={status === 'pending'}
21
+ * >
22
+ * {status === 'pending' ? 'Changing...' : 'Change Password'}
23
+ * </button>
24
+ * ```
25
+ */
26
+ export function useChangePassword() {
27
+ const client = useAuthClient();
28
+ const changeFn = useCallback((oldPassword, newPassword) => client.changePassword(oldPassword, newPassword), [client]);
29
+ const [state, call] = usePromise(changeFn);
30
+ return {
31
+ status: state.status,
32
+ error: state.error,
33
+ changePassword: call,
34
+ reset: state.reset,
35
+ };
36
+ }
37
+ //# sourceMappingURL=useChangePassword.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChangePassword.js","sourceRoot":"","sources":["../../src/hooks/useChangePassword.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAEnC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAA;AAYlE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,MAAM,GAAG,aAAa,EAAE,CAAA;IAE9B,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,WAAmB,EAAE,WAAmB,EAAE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC,EAC7F,CAAC,MAAM,CAAC,CACT,CAAA;IAED,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;IAE1C,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,cAAc,EAAE,IAAI;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAA;AACH,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * React hook for AI chat provider.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ChatProvider } from '@molecule/app-ai-chat';
7
+ import type { UseChatOptions, UseChatResult } from '../types.js';
8
+ /**
9
+ * Test-only: clear all conversation stores. The store is module-level (it must
10
+ * outlive component mounts), so it persists across test cases — reset it in a
11
+ * `beforeEach` the same way tests clear `sessionStorage`.
12
+ */
13
+ export declare function resetChatStoresForTests(): void;
14
+ /**
15
+ * Access the chat provider from context.
16
+ * @returns The ChatProvider instance from the nearest ChatContext.
17
+ * @throws {Error} If called outside a ChatProvider.
18
+ */
19
+ export declare function useChatProvider(): ChatProvider;
20
+ /**
21
+ * Hook for AI chat with streaming support.
22
+ *
23
+ * Manages message state, sends messages to the backend, and handles
24
+ * SSE streaming responses.
25
+ *
26
+ * @param options - Chat configuration including endpoint URL, project ID, and whether to load history on mount.
27
+ * @returns Chat state and controls: messages, isLoading, error, sendMessage, abort, and clearHistory.
28
+ */
29
+ export declare function useChat(options: UseChatOptions): UseChatResult;
30
+ //# sourceMappingURL=useChat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../src/hooks/useChat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,KAAK,EAIV,YAAY,EAGb,MAAM,uBAAuB,CAAA;AAK9B,OAAO,KAAK,EAAsB,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAiUpF;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAK9C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAU9C;AA6CD;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CAg4C9D"}