@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,40 @@
1
+ /**
2
+ * Neutral, app-agnostic identity for the AI coding agent and the host product.
3
+ *
4
+ * The shared chat/IDE packages (`@molecule/app-react`, `@molecule/app-ide-react`)
5
+ * must never hardcode a specific product's agent name or product name in
6
+ * user-facing copy — a *different* app embedding them would inherit the wrong
7
+ * branding (molecule AGENTS.md anti-pattern 14 / the leaks-in-core audit).
8
+ * Instead, shared UI strings interpolate the i18n tokens `{{agentName}}` /
9
+ * `{{productName}}`, and the host supplies its own values via
10
+ * `useChat({ agentName })` and `<ChatPanel agentName productName />`.
11
+ *
12
+ * These NEUTRAL defaults apply when the host passes nothing, so the package on
13
+ * its own never names a specific product — it reads as "the assistant" / "the
14
+ * IDE" until a consuming app sets its own identity.
15
+ *
16
+ * @module
17
+ */
18
+ /**
19
+ * Display identity for the AI coding agent and the host product, used to
20
+ * interpolate the `{{agentName}}` / `{{productName}}` tokens in shared chat/IDE
21
+ * copy. A consuming app sets these to its own agent + product brand names; the
22
+ * shared packages fall back to {@link DEFAULT_AGENT_IDENTITY} when it does not.
23
+ */
24
+ export interface AgentIdentity {
25
+ /** Display name of the AI coding agent. Defaults to {@link DEFAULT_AGENT_NAME}. */
26
+ agentName: string;
27
+ /** Display name of the host product / IDE. Defaults to {@link DEFAULT_PRODUCT_NAME}. */
28
+ productName: string;
29
+ }
30
+ /** Neutral, product-agnostic agent name used when the host supplies none. */
31
+ export declare const DEFAULT_AGENT_NAME = "the assistant";
32
+ /** Neutral, product-agnostic product/IDE name used when the host supplies none. */
33
+ export declare const DEFAULT_PRODUCT_NAME = "the IDE";
34
+ /**
35
+ * The neutral default identity ({@link DEFAULT_AGENT_NAME} +
36
+ * {@link DEFAULT_PRODUCT_NAME}) the shared packages use until a consuming app
37
+ * passes its own.
38
+ */
39
+ export declare const DEFAULT_AGENT_IDENTITY: AgentIdentity;
40
+ //# sourceMappingURL=agent-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-identity.d.ts","sourceRoot":"","sources":["../src/agent-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,mFAAmF;IACnF,SAAS,EAAE,MAAM,CAAA;IACjB,wFAAwF;IACxF,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,kBAAkB,CAAA;AAEjD,mFAAmF;AACnF,eAAO,MAAM,oBAAoB,YAAY,CAAA;AAE7C;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,aAGpC,CAAA"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Neutral, app-agnostic identity for the AI coding agent and the host product.
3
+ *
4
+ * The shared chat/IDE packages (`@molecule/app-react`, `@molecule/app-ide-react`)
5
+ * must never hardcode a specific product's agent name or product name in
6
+ * user-facing copy — a *different* app embedding them would inherit the wrong
7
+ * branding (molecule AGENTS.md anti-pattern 14 / the leaks-in-core audit).
8
+ * Instead, shared UI strings interpolate the i18n tokens `{{agentName}}` /
9
+ * `{{productName}}`, and the host supplies its own values via
10
+ * `useChat({ agentName })` and `<ChatPanel agentName productName />`.
11
+ *
12
+ * These NEUTRAL defaults apply when the host passes nothing, so the package on
13
+ * its own never names a specific product — it reads as "the assistant" / "the
14
+ * IDE" until a consuming app sets its own identity.
15
+ *
16
+ * @module
17
+ */
18
+ /** Neutral, product-agnostic agent name used when the host supplies none. */
19
+ export const DEFAULT_AGENT_NAME = 'the assistant';
20
+ /** Neutral, product-agnostic product/IDE name used when the host supplies none. */
21
+ export const DEFAULT_PRODUCT_NAME = 'the IDE';
22
+ /**
23
+ * The neutral default identity ({@link DEFAULT_AGENT_NAME} +
24
+ * {@link DEFAULT_PRODUCT_NAME}) the shared packages use until a consuming app
25
+ * passes its own.
26
+ */
27
+ export const DEFAULT_AGENT_IDENTITY = {
28
+ agentName: DEFAULT_AGENT_NAME,
29
+ productName: DEFAULT_PRODUCT_NAME,
30
+ };
31
+ //# sourceMappingURL=agent-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-identity.js","sourceRoot":"","sources":["../src/agent-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAeH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAA;AAEjD,mFAAmF;AACnF,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAAA;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,SAAS,EAAE,kBAAkB;IAC7B,WAAW,EAAE,oBAAoB;CAClC,CAAA"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * React contexts for the Molecule framework bindings.
3
+ *
4
+ * These contexts provide access to core molecule providers throughout
5
+ * the React component tree.
6
+ *
7
+ * @module
8
+ */
9
+ import type { ChatProvider } from '@molecule/app-ai-chat';
10
+ import type { AuthClient } from '@molecule/app-auth';
11
+ import type { EditorProvider } from '@molecule/app-code-editor';
12
+ import type { HttpClient } from '@molecule/app-http';
13
+ import type { I18nProvider } from '@molecule/app-i18n';
14
+ import type { WorkspaceProvider } from '@molecule/app-ide';
15
+ import type { PreviewProvider } from '@molecule/app-live-preview';
16
+ import type { LoggerProvider } from '@molecule/app-logger';
17
+ import type { Router } from '@molecule/app-routing';
18
+ import type { StateProvider } from '@molecule/app-state';
19
+ import type { StorageProvider } from '@molecule/app-storage';
20
+ import type { ThemeProvider } from '@molecule/app-theme';
21
+ /**
22
+ * Context for state management provider.
23
+ */
24
+ export declare const StateContext: import("react").Context<StateProvider | null>;
25
+ /**
26
+ * Context for authentication client.
27
+ */
28
+ export declare const AuthContext: import("react").Context<AuthClient<unknown> | null>;
29
+ /**
30
+ * Context for theme provider.
31
+ */
32
+ export declare const ThemeContext: import("react").Context<ThemeProvider | null>;
33
+ /**
34
+ * Context for router.
35
+ */
36
+ export declare const RouterContext: import("react").Context<Router | null>;
37
+ /**
38
+ * Context for internationalization provider.
39
+ */
40
+ export declare const I18nContext: import("react").Context<I18nProvider | null>;
41
+ /**
42
+ * Context for HTTP client.
43
+ */
44
+ export declare const HttpContext: import("react").Context<HttpClient | null>;
45
+ /**
46
+ * Context for storage provider.
47
+ */
48
+ export declare const StorageContext: import("react").Context<StorageProvider | null>;
49
+ /**
50
+ * Context for logger provider.
51
+ */
52
+ export declare const LoggerContext: import("react").Context<LoggerProvider | null>;
53
+ /**
54
+ * Context for AI chat provider.
55
+ */
56
+ export declare const ChatContext: import("react").Context<ChatProvider | null>;
57
+ /**
58
+ * Context for IDE workspace provider.
59
+ */
60
+ export declare const WorkspaceContext: import("react").Context<WorkspaceProvider | null>;
61
+ /**
62
+ * Context for code editor provider.
63
+ */
64
+ export declare const EditorContext: import("react").Context<EditorProvider | null>;
65
+ /**
66
+ * Context for live preview provider.
67
+ */
68
+ export declare const PreviewContext: import("react").Context<PreviewProvider | null>;
69
+ //# sourceMappingURL=contexts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../src/contexts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;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AAc,iDAA8C,CAAA"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * React contexts for the Molecule framework bindings.
3
+ *
4
+ * These contexts provide access to core molecule providers throughout
5
+ * the React component tree.
6
+ *
7
+ * @module
8
+ */
9
+ import { createContext } from 'react';
10
+ /**
11
+ * Context for state management provider.
12
+ */
13
+ export const StateContext = createContext(null);
14
+ StateContext.displayName = 'MoleculeStateContext';
15
+ /**
16
+ * Context for authentication client.
17
+ */
18
+ export const AuthContext = createContext(null);
19
+ AuthContext.displayName = 'MoleculeAuthContext';
20
+ /**
21
+ * Context for theme provider.
22
+ */
23
+ export const ThemeContext = createContext(null);
24
+ ThemeContext.displayName = 'MoleculeThemeContext';
25
+ /**
26
+ * Context for router.
27
+ */
28
+ export const RouterContext = createContext(null);
29
+ RouterContext.displayName = 'MoleculeRouterContext';
30
+ /**
31
+ * Context for internationalization provider.
32
+ */
33
+ export const I18nContext = createContext(null);
34
+ I18nContext.displayName = 'MoleculeI18nContext';
35
+ /**
36
+ * Context for HTTP client.
37
+ */
38
+ export const HttpContext = createContext(null);
39
+ HttpContext.displayName = 'MoleculeHttpContext';
40
+ /**
41
+ * Context for storage provider.
42
+ */
43
+ export const StorageContext = createContext(null);
44
+ StorageContext.displayName = 'MoleculeStorageContext';
45
+ /**
46
+ * Context for logger provider.
47
+ */
48
+ export const LoggerContext = createContext(null);
49
+ LoggerContext.displayName = 'MoleculeLoggerContext';
50
+ /**
51
+ * Context for AI chat provider.
52
+ */
53
+ export const ChatContext = createContext(null);
54
+ ChatContext.displayName = 'MoleculeChatContext';
55
+ /**
56
+ * Context for IDE workspace provider.
57
+ */
58
+ export const WorkspaceContext = createContext(null);
59
+ WorkspaceContext.displayName = 'MoleculeWorkspaceContext';
60
+ /**
61
+ * Context for code editor provider.
62
+ */
63
+ export const EditorContext = createContext(null);
64
+ EditorContext.displayName = 'MoleculeEditorContext';
65
+ /**
66
+ * Context for live preview provider.
67
+ */
68
+ export const PreviewContext = createContext(null);
69
+ PreviewContext.displayName = 'MoleculePreviewContext';
70
+ //# sourceMappingURL=contexts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contexts.js","sourceRoot":"","sources":["../src/contexts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAerC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAuB,IAAI,CAAC,CAAA;AACrE,YAAY,CAAC,WAAW,GAAG,sBAAsB,CAAA;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAA6B,IAAI,CAAC,CAAA;AAC1E,WAAW,CAAC,WAAW,GAAG,qBAAqB,CAAA;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAuB,IAAI,CAAC,CAAA;AACrE,YAAY,CAAC,WAAW,GAAG,sBAAsB,CAAA;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAgB,IAAI,CAAC,CAAA;AAC/D,aAAa,CAAC,WAAW,GAAG,uBAAuB,CAAA;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAsB,IAAI,CAAC,CAAA;AACnE,WAAW,CAAC,WAAW,GAAG,qBAAqB,CAAA;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAoB,IAAI,CAAC,CAAA;AACjE,WAAW,CAAC,WAAW,GAAG,qBAAqB,CAAA;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAyB,IAAI,CAAC,CAAA;AACzE,cAAc,CAAC,WAAW,GAAG,wBAAwB,CAAA;AAErD;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAwB,IAAI,CAAC,CAAA;AACvE,aAAa,CAAC,WAAW,GAAG,uBAAuB,CAAA;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAsB,IAAI,CAAC,CAAA;AACnE,WAAW,CAAC,WAAW,GAAG,qBAAqB,CAAA;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAA2B,IAAI,CAAC,CAAA;AAC7E,gBAAgB,CAAC,WAAW,GAAG,0BAA0B,CAAA;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAwB,IAAI,CAAC,CAAA;AACvE,aAAa,CAAC,WAAW,GAAG,uBAAuB,CAAA;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAyB,IAAI,CAAC,CAAA;AACzE,cAAc,CAAC,WAAW,GAAG,wBAAwB,CAAA"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * React hooks for the Molecule framework bindings.
3
+ *
4
+ * @module
5
+ */
6
+ export * from './useAIModels.js';
7
+ export * from './useAsyncState.js';
8
+ export * from './useAuth.js';
9
+ export * from './useCapacitorApp.js';
10
+ export * from './useChangePassword.js';
11
+ export * from './useChat.js';
12
+ export * from './useDevice.js';
13
+ export * from './useEditor.js';
14
+ export * from './useForm.js';
15
+ export * from './useHttp.js';
16
+ export * from './useLogger.js';
17
+ export * from './useLogin.js';
18
+ export * from './useOAuth.js';
19
+ export * from './usePasswordReset.js';
20
+ export * from './usePlatform.js';
21
+ export * from './usePreview.js';
22
+ export * from './usePromise.js';
23
+ export * from './usePush.js';
24
+ export * from './useRouter.js';
25
+ export * from './useSignup.js';
26
+ export * from './useStorage.js';
27
+ export * from './useStore.js';
28
+ export * from './useTheme.js';
29
+ export * from './useTranslation.js';
30
+ export * from './useVersion.js';
31
+ export * from './useWorkspace.js';
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * React hooks for the Molecule framework bindings.
3
+ *
4
+ * @module
5
+ */
6
+ export * from './useAIModels.js';
7
+ export * from './useAsyncState.js';
8
+ export * from './useAuth.js';
9
+ export * from './useCapacitorApp.js';
10
+ export * from './useChangePassword.js';
11
+ export * from './useChat.js';
12
+ export * from './useDevice.js';
13
+ export * from './useEditor.js';
14
+ export * from './useForm.js';
15
+ export * from './useHttp.js';
16
+ export * from './useLogger.js';
17
+ export * from './useLogin.js';
18
+ export * from './useOAuth.js';
19
+ export * from './usePasswordReset.js';
20
+ export * from './usePlatform.js';
21
+ export * from './usePreview.js';
22
+ export * from './usePromise.js';
23
+ export * from './usePush.js';
24
+ export * from './useRouter.js';
25
+ export * from './useSignup.js';
26
+ export * from './useStorage.js';
27
+ export * from './useStore.js';
28
+ export * from './useTheme.js';
29
+ export * from './useTranslation.js';
30
+ export * from './useVersion.js';
31
+ export * from './useWorkspace.js';
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * React hook for the AI model catalog.
3
+ *
4
+ * Lazily fetches `GET /ai/models` on first mount and caches the result in a
5
+ * module-level singleton so subsequent mounts return synchronously. The picker
6
+ * shows a brief loading state on first open and never refetches afterwards.
7
+ *
8
+ * When a `projectId` is passed, the fetch is project-scoped
9
+ * (`?projectId=<id>`) so servers that support per-project custom
10
+ * ("bring your own AI") models include them; each scope caches independently.
11
+ *
12
+ * @module
13
+ */
14
+ import type { AppModelDefinition, AppModeModelDefaults } from '@molecule/app-ai-models';
15
+ /**
16
+ * Test-only: drops every cached model list so the next `useAIModels` call
17
+ * refetches. Exposed for unit tests; do not call from production code.
18
+ */
19
+ export declare function resetAIModelsCache(): void;
20
+ /**
21
+ * Result returned by `useAIModels`.
22
+ */
23
+ export interface UseAIModelsResult {
24
+ /** Available models, or an empty array while loading. */
25
+ models: AppModelDefinition[];
26
+ /**
27
+ * Per-mode server default model ids for the requester's tier, or `undefined`
28
+ * while loading or on servers that don't provide them.
29
+ */
30
+ defaults: AppModeModelDefaults | undefined;
31
+ /** The single model marked `freeTier: true`, or `undefined`. */
32
+ freeTierModel: AppModelDefinition | undefined;
33
+ /** `true` while the initial fetch is in flight. */
34
+ loading: boolean;
35
+ /** Error from the initial fetch, or `null`. */
36
+ error: Error | null;
37
+ }
38
+ /**
39
+ * Subscribes to the cached AI model catalog. The first mount of a scope
40
+ * triggers a single `GET /ai/models` fetch; subsequent mounts return the
41
+ * cached result.
42
+ *
43
+ * @param projectId - Optional project scope: includes that project's custom
44
+ * ("bring your own AI") models on servers that support them.
45
+ * @returns Models, free-tier model, loading flag, and error.
46
+ */
47
+ export declare function useAIModels(projectId?: string): UseAIModelsResult;
48
+ //# sourceMappingURL=useAIModels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAIModels.d.ts","sourceRoot":"","sources":["../../src/hooks/useAIModels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAkGvF;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CASzC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,yDAAyD;IACzD,MAAM,EAAE,kBAAkB,EAAE,CAAA;IAC5B;;;OAGG;IACH,QAAQ,EAAE,oBAAoB,GAAG,SAAS,CAAA;IAC1C,gEAAgE;IAChE,aAAa,EAAE,kBAAkB,GAAG,SAAS,CAAA;IAC7C,mDAAmD;IACnD,OAAO,EAAE,OAAO,CAAA;IAChB,+CAA+C;IAC/C,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAsCjE"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * React hook for the AI model catalog.
3
+ *
4
+ * Lazily fetches `GET /ai/models` on first mount and caches the result in a
5
+ * module-level singleton so subsequent mounts return synchronously. The picker
6
+ * shows a brief loading state on first open and never refetches afterwards.
7
+ *
8
+ * When a `projectId` is passed, the fetch is project-scoped
9
+ * (`?projectId=<id>`) so servers that support per-project custom
10
+ * ("bring your own AI") models include them; each scope caches independently.
11
+ *
12
+ * @module
13
+ */
14
+ import { useEffect, useState } from 'react';
15
+ import { loadAIModelCatalog, pickFreeTierModel } from '@molecule/app-ai-models';
16
+ import { useHttpClient } from './useHttp.js';
17
+ /** One cache entry per scope — `''` for the unscoped catalog, else the projectId. */
18
+ const caches = new Map();
19
+ /**
20
+ * The cache entry for a scope, created on first use.
21
+ *
22
+ * @param scope - `''` for the unscoped catalog, else the projectId.
23
+ * @returns The scope's cache entry.
24
+ */
25
+ function cacheFor(scope) {
26
+ let cache = caches.get(scope);
27
+ if (!cache) {
28
+ cache = { models: null, defaults: undefined, error: null, inFlight: null };
29
+ caches.set(scope, cache);
30
+ }
31
+ return cache;
32
+ }
33
+ /** Listeners keyed by the same scope as the cache they observe. */
34
+ const listenersByScope = new Map();
35
+ /**
36
+ * The listener set for a scope, created on first use.
37
+ *
38
+ * @param scope - The cache scope.
39
+ * @returns The scope's listener set.
40
+ */
41
+ function listenersFor(scope) {
42
+ let set = listenersByScope.get(scope);
43
+ if (!set) {
44
+ set = new Set();
45
+ listenersByScope.set(scope, set);
46
+ }
47
+ return set;
48
+ }
49
+ /**
50
+ * Broadcasts a scope's current cache state to its subscribed listeners.
51
+ *
52
+ * @param scope - The cache scope to notify.
53
+ */
54
+ function notify(scope) {
55
+ const cache = cacheFor(scope);
56
+ for (const listener of listenersFor(scope)) {
57
+ listener({ models: cache.models, defaults: cache.defaults, error: cache.error });
58
+ }
59
+ }
60
+ /**
61
+ * Triggers (or rejoins) the single in-flight fetch of `/ai/models` for a scope
62
+ * and stores the result in that scope's module-level cache.
63
+ *
64
+ * @param http - HTTP client used for the single fetch.
65
+ * @param scope - `''` for the unscoped catalog, else the projectId.
66
+ * @returns The fetched model list.
67
+ */
68
+ async function fetchOnce(http, scope) {
69
+ const cache = cacheFor(scope);
70
+ if (cache.models)
71
+ return cache.models;
72
+ if (cache.inFlight)
73
+ return cache.inFlight;
74
+ cache.inFlight = loadAIModelCatalog(http, undefined, scope || undefined)
75
+ .then((catalog) => {
76
+ cache.models = catalog.models;
77
+ cache.defaults = catalog.defaults;
78
+ cache.error = null;
79
+ cache.inFlight = null;
80
+ notify(scope);
81
+ return catalog.models;
82
+ })
83
+ .catch((err) => {
84
+ cache.error = err instanceof Error ? err : new Error(String(err));
85
+ cache.inFlight = null;
86
+ notify(scope);
87
+ throw cache.error;
88
+ });
89
+ return cache.inFlight;
90
+ }
91
+ /**
92
+ * Test-only: drops every cached model list so the next `useAIModels` call
93
+ * refetches. Exposed for unit tests; do not call from production code.
94
+ */
95
+ export function resetAIModelsCache() {
96
+ for (const [scope, cache] of caches) {
97
+ cache.models = null;
98
+ cache.defaults = undefined;
99
+ cache.error = null;
100
+ cache.inFlight = null;
101
+ notify(scope);
102
+ }
103
+ caches.clear();
104
+ }
105
+ /**
106
+ * Subscribes to the cached AI model catalog. The first mount of a scope
107
+ * triggers a single `GET /ai/models` fetch; subsequent mounts return the
108
+ * cached result.
109
+ *
110
+ * @param projectId - Optional project scope: includes that project's custom
111
+ * ("bring your own AI") models on servers that support them.
112
+ * @returns Models, free-tier model, loading flag, and error.
113
+ */
114
+ export function useAIModels(projectId) {
115
+ const http = useHttpClient();
116
+ const scope = projectId ?? '';
117
+ const [snapshot, setSnapshot] = useState(() => {
118
+ const cache = cacheFor(scope);
119
+ return { models: cache.models, defaults: cache.defaults, error: cache.error };
120
+ });
121
+ useEffect(() => {
122
+ const cache = cacheFor(scope);
123
+ const listener = (next) => setSnapshot(next);
124
+ listenersFor(scope).add(listener);
125
+ // The scope may have changed since the lazy useState init — resync.
126
+ setSnapshot({ models: cache.models, defaults: cache.defaults, error: cache.error });
127
+ if (!cache.models && !cache.error) {
128
+ void fetchOnce(http, scope).catch(() => {
129
+ // Error is mirrored into cache.error and propagated via the listener.
130
+ });
131
+ }
132
+ return () => {
133
+ listenersFor(scope).delete(listener);
134
+ };
135
+ }, [http, scope]);
136
+ const models = snapshot.models ?? [];
137
+ return {
138
+ models,
139
+ defaults: snapshot.defaults,
140
+ freeTierModel: pickFreeTierModel(models),
141
+ loading: !snapshot.models && !snapshot.error,
142
+ error: snapshot.error,
143
+ };
144
+ }
145
+ //# sourceMappingURL=useAIModels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAIModels.js","sourceRoot":"","sources":["../../src/hooks/useAIModels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAG3C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAG/E,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAS5C,qFAAqF;AACrF,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAA;AAE5C;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,KAAa;IAC7B,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;QAC1E,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC1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,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Async-capable setState function.
3
+ * @param value - The new state value, an updater function receiving previous state, or a Promise resolving to either.
4
+ */
5
+ export type AsyncSetState<T> = (value: T | ((prev: T) => T) | Promise<T | ((prev: T) => T)>) => void;
6
+ /**
7
+ * Async-capable extendState function for partial updates.
8
+ */
9
+ export type AsyncExtendState<T> = (partial: Partial<T> | ((prev: T) => Partial<T>) | Promise<Partial<T> | ((prev: T) => Partial<T>)>) => void;
10
+ /**
11
+ * Hook like useState but accepts Promises and supports partial state extension.
12
+ *
13
+ * @param initialState - Initial state value
14
+ * @returns Tuple of [state, asyncSetState, asyncExtendState]
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * interface State {
19
+ * foo: string
20
+ * bar: string
21
+ * }
22
+ *
23
+ * const [state, setState, extendState] = useAsyncState<State>({
24
+ * foo: 'foo',
25
+ * bar: 'bar',
26
+ * })
27
+ *
28
+ * // Synchronous usage
29
+ * setState({ foo: 'Hello', bar: 'World!' })
30
+ * setState((prev) => ({ ...prev, foo: prev.foo.toUpperCase() }))
31
+ *
32
+ * // Async usage
33
+ * setState(fetchData())
34
+ *
35
+ * // Partial updates
36
+ * extendState({ foo: 'Hello' })
37
+ * extendState(fetchPartialData())
38
+ * ```
39
+ */
40
+ export declare const useAsyncState: <T>(initialState: T) => [T, AsyncSetState<T>, AsyncExtendState<T>];
41
+ //# sourceMappingURL=useAsyncState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAsyncState.d.ts","sourceRoot":"","sources":["../../src/hooks/useAsyncState.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;AAEpG;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAChC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAC9F,IAAI,CAAA;AAET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,cAAc,CAAC,KAAG,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CA2C3F,CAAA"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * React hook for async-capable state management.
3
+ *
4
+ * @module
5
+ */
6
+ import { useCallback, useState } from 'react';
7
+ /**
8
+ * Hook like useState but accepts Promises and supports partial state extension.
9
+ *
10
+ * @param initialState - Initial state value
11
+ * @returns Tuple of [state, asyncSetState, asyncExtendState]
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * interface State {
16
+ * foo: string
17
+ * bar: string
18
+ * }
19
+ *
20
+ * const [state, setState, extendState] = useAsyncState<State>({
21
+ * foo: 'foo',
22
+ * bar: 'bar',
23
+ * })
24
+ *
25
+ * // Synchronous usage
26
+ * setState({ foo: 'Hello', bar: 'World!' })
27
+ * setState((prev) => ({ ...prev, foo: prev.foo.toUpperCase() }))
28
+ *
29
+ * // Async usage
30
+ * setState(fetchData())
31
+ *
32
+ * // Partial updates
33
+ * extendState({ foo: 'Hello' })
34
+ * extendState(fetchPartialData())
35
+ * ```
36
+ */
37
+ export const useAsyncState = (initialState) => {
38
+ const [state, setState] = useState(initialState);
39
+ const asyncSetState = useCallback(async (nextState) => {
40
+ try {
41
+ if (nextState instanceof Promise) {
42
+ nextState = await nextState;
43
+ }
44
+ setState((prev) => {
45
+ if (typeof nextState === 'function') {
46
+ return nextState(prev);
47
+ }
48
+ return nextState;
49
+ });
50
+ }
51
+ catch (_error) {
52
+ // Silently swallow errors from resolved Promises to avoid unhandled rejections
53
+ }
54
+ }, []);
55
+ const asyncExtendState = useCallback(async (partial) => {
56
+ try {
57
+ if (partial instanceof Promise) {
58
+ partial = await partial;
59
+ }
60
+ setState((prev) => {
61
+ let resolved;
62
+ if (typeof partial === 'function') {
63
+ resolved = partial(prev);
64
+ }
65
+ else {
66
+ resolved = partial;
67
+ }
68
+ return { ...prev, ...resolved };
69
+ });
70
+ }
71
+ catch (_error) {
72
+ // Silently swallow errors from resolved Promises to avoid unhandled rejections
73
+ }
74
+ }, []);
75
+ return [state, asyncSetState, asyncExtendState];
76
+ };
77
+ //# sourceMappingURL=useAsyncState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAsyncState.js","sourceRoot":"","sources":["../../src/hooks/useAsyncState.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAe7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAI,YAAe,EAA8C,EAAE;IAC9F,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAI,YAAY,CAAC,CAAA;IAEnD,MAAM,aAAa,GAAG,WAAW,CAAmB,KAAK,EAAE,SAAS,EAAE,EAAE;QACtE,IAAI,CAAC;YACH,IAAI,SAAS,YAAY,OAAO,EAAE,CAAC;gBACjC,SAAS,GAAG,MAAM,SAAS,CAAA;YAC7B,CAAC;YAED,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE;gBAChB,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;oBACpC,OAAQ,SAA4B,CAAC,IAAI,CAAC,CAAA;gBAC5C,CAAC;gBACD,OAAO,SAA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