@molecule/app-svelte 3.5.1 → 3.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +287 -76
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/live-store.d.ts +0 -8
- package/dist/hooks/live-store.d.ts.map +1 -1
- package/dist/hooks/live-store.js +0 -13
- package/dist/hooks/maybe-readable.d.ts +36 -0
- package/dist/hooks/maybe-readable.d.ts.map +1 -0
- package/dist/hooks/maybe-readable.js +36 -0
- package/dist/hooks/useAIModels.d.ts +8 -2
- package/dist/hooks/useAIModels.d.ts.map +1 -1
- package/dist/hooks/useAIModels.js +44 -17
- package/dist/hooks/useAuth.d.ts +10 -4
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +39 -13
- package/dist/hooks/useForm.d.ts +13 -5
- package/dist/hooks/useForm.d.ts.map +1 -1
- package/dist/hooks/useForm.js +90 -58
- package/dist/hooks/useHttp.d.ts +28 -22
- package/dist/hooks/useHttp.d.ts.map +1 -1
- package/dist/hooks/useHttp.js +67 -96
- package/dist/hooks/useOAuth.d.ts +23 -7
- package/dist/hooks/useOAuth.d.ts.map +1 -1
- package/dist/hooks/useOAuth.js +51 -18
- package/dist/hooks/useOptimisticToggle.d.ts +67 -0
- package/dist/hooks/useOptimisticToggle.d.ts.map +1 -0
- package/dist/hooks/useOptimisticToggle.js +52 -0
- package/dist/hooks/useOptimisticValue.d.ts +11 -4
- package/dist/hooks/useOptimisticValue.d.ts.map +1 -1
- package/dist/hooks/useOptimisticValue.js +40 -49
- package/dist/hooks/usePush.d.ts +7 -3
- package/dist/hooks/usePush.d.ts.map +1 -1
- package/dist/hooks/usePush.js +26 -6
- package/dist/hooks/useRouter.d.ts +13 -7
- package/dist/hooks/useRouter.d.ts.map +1 -1
- package/dist/hooks/useRouter.js +39 -18
- package/dist/hooks/useStorage.d.ts +22 -9
- package/dist/hooks/useStorage.d.ts.map +1 -1
- package/dist/hooks/useStorage.js +146 -69
- package/dist/hooks/useStore.d.ts +14 -7
- package/dist/hooks/useStore.d.ts.map +1 -1
- package/dist/hooks/useStore.js +46 -9
- package/dist/hooks/useTranslation.d.ts +6 -2
- package/dist/hooks/useTranslation.d.ts.map +1 -1
- package/dist/hooks/useTranslation.js +11 -6
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/link/Link.svelte +33 -0
- package/dist/link/Link.svelte.d.ts +12 -0
- package/dist/link/Link.svelte.d.ts.map +1 -0
- package/dist/link/index.d.ts +23 -0
- package/dist/link/index.d.ts.map +1 -0
- package/dist/link/index.js +22 -0
- package/dist/link/types.d.ts +26 -0
- package/dist/link/types.d.ts.map +1 -0
- package/dist/link/types.js +6 -0
- package/dist/stores/chat.d.ts +4 -3
- package/dist/stores/chat.d.ts.map +1 -1
- package/dist/stores/chat.js +14 -15
- package/package.json +5 -5
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { type Readable } from 'svelte/store';
|
|
9
9
|
import type { I18nProvider, TranslateOptions } from '@molecule/app-i18n';
|
|
10
|
+
import { type MaybeReadable } from './maybe-readable.js';
|
|
10
11
|
/**
|
|
11
12
|
* Options for the shorthand form of {@link UseTFunction}: the fallback text
|
|
12
13
|
* is passed positionally, so only `count` remains here.
|
|
@@ -99,8 +100,11 @@ export declare function useDirection(): Readable<'ltr' | 'rtl'>;
|
|
|
99
100
|
* using the current locale. For plain `Error` instances, `error.message` is
|
|
100
101
|
* returned unchanged.
|
|
101
102
|
*
|
|
102
|
-
*
|
|
103
|
+
* The error may be a plain value or a readable store of one: setting the store
|
|
104
|
+
* replaces the message on the same component, the way React's re-render does.
|
|
105
|
+
*
|
|
106
|
+
* @param error - The error to translate, or `null`/`undefined` (or a store of either).
|
|
103
107
|
* @returns A readable store of the translated error string, or null.
|
|
104
108
|
*/
|
|
105
|
-
export declare function useI18nError(error: Error | null | undefined): Readable<string | null>;
|
|
109
|
+
export declare function useI18nError(error: MaybeReadable<Error | null | undefined>): Readable<string | null>;
|
|
106
110
|
//# sourceMappingURL=useTranslation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslation.d.ts","sourceRoot":"","sources":["../../src/hooks/useTranslation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAsB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAE1E,OAAO,KAAK,EAEV,YAAY,EAGZ,gBAAgB,EACjB,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"useTranslation.d.ts","sourceRoot":"","sources":["../../src/hooks/useTranslation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAsB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAE1E,OAAO,KAAK,EAEV,YAAY,EAGZ,gBAAgB,EACjB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAEpE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAA;AAEzE;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG;IAC7C,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAAA;CACxE,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,CAAA;IACpB,8BAA8B;IAC9B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxB,kCAAkC;IAClC,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC,CAAA;IACpC,8BAA8B;IAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IACzD,8CAA8C;IAC9C,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;IAC1C,4CAA4C;IAC5C,UAAU,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;IACtC,0CAA0C;IAC1C,SAAS,EAAE,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,CAAA;CACnC;AAqDD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,IAAI,oBAAoB,CAmBrD;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,IAAI,YAAY,CAenC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,QAAQ,CAAC,MAAM,CAAC,CAG5C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,CAGtD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,aAAa,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,GAC7C,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAazB"}
|
|
@@ -9,6 +9,7 @@ import { onDestroy } from 'svelte';
|
|
|
9
9
|
import { derived, fromStore, writable } from 'svelte/store';
|
|
10
10
|
import { I18nError } from '@molecule/app-i18n';
|
|
11
11
|
import { useI18nProvider } from '../context.js';
|
|
12
|
+
import { toReadable } from './maybe-readable.js';
|
|
12
13
|
/**
|
|
13
14
|
* Subscribes the calling component to the provider's locale notifications,
|
|
14
15
|
* like React's `useLocaleSnapshot`.
|
|
@@ -140,20 +141,24 @@ export function useDirection() {
|
|
|
140
141
|
* using the current locale. For plain `Error` instances, `error.message` is
|
|
141
142
|
* returned unchanged.
|
|
142
143
|
*
|
|
143
|
-
*
|
|
144
|
+
* The error may be a plain value or a readable store of one: setting the store
|
|
145
|
+
* replaces the message on the same component, the way React's re-render does.
|
|
146
|
+
*
|
|
147
|
+
* @param error - The error to translate, or `null`/`undefined` (or a store of either).
|
|
144
148
|
* @returns A readable store of the translated error string, or null.
|
|
145
149
|
*/
|
|
146
150
|
export function useI18nError(error) {
|
|
147
151
|
const { t, locale } = useTranslation();
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
const errorStore = toReadable(error);
|
|
153
|
+
return derived([errorStore, locale], ([current]) => {
|
|
154
|
+
if (!current)
|
|
150
155
|
return null;
|
|
151
156
|
// defaultValue is the I18nError's own message — the fallback text its
|
|
152
157
|
// throw site provided. Without it, a key the CLIENT dictionary lacks
|
|
153
158
|
// renders as the raw key instead of a message.
|
|
154
|
-
if (
|
|
155
|
-
return t(
|
|
159
|
+
if (current instanceof I18nError) {
|
|
160
|
+
return t(current.i18nKey, current.i18nValues, { defaultValue: current.message });
|
|
156
161
|
}
|
|
157
|
-
return
|
|
162
|
+
return current.message;
|
|
158
163
|
});
|
|
159
164
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -51,12 +51,16 @@
|
|
|
51
51
|
* config; don't wrap in try/catch.
|
|
52
52
|
* - Results are Svelte stores — read them with the `$` prefix (`$isAuthenticated`, `$theme`);
|
|
53
53
|
* actions (`logout`, `toggleTheme`, `setTheme`) are plain functions.
|
|
54
|
+
* - In-app links are `Link` (`<Link to="/settings">`): it navigates through the router with
|
|
55
|
+
* react-router `<Link>`'s click rules. A hand-written click handler that calls `navigate()`
|
|
56
|
+
* breaks ctrl/cmd-click (new tab) unless it repeats those rules.
|
|
54
57
|
*
|
|
55
58
|
* @module
|
|
56
59
|
*/
|
|
57
60
|
export * from './agent-identity.js';
|
|
58
61
|
export * from './context.js';
|
|
59
62
|
export * from './hooks/index.js';
|
|
63
|
+
export * from './link/index.js';
|
|
60
64
|
export * from './session-ready/index.js';
|
|
61
65
|
export * from './stores/index.js';
|
|
62
66
|
export * from './types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -51,12 +51,16 @@
|
|
|
51
51
|
* config; don't wrap in try/catch.
|
|
52
52
|
* - Results are Svelte stores — read them with the `$` prefix (`$isAuthenticated`, `$theme`);
|
|
53
53
|
* actions (`logout`, `toggleTheme`, `setTheme`) are plain functions.
|
|
54
|
+
* - In-app links are `Link` (`<Link to="/settings">`): it navigates through the router with
|
|
55
|
+
* react-router `<Link>`'s click rules. A hand-written click handler that calls `navigate()`
|
|
56
|
+
* breaks ctrl/cmd-click (new tab) unless it repeats those rules.
|
|
54
57
|
*
|
|
55
58
|
* @module
|
|
56
59
|
*/
|
|
57
60
|
export * from './agent-identity.js';
|
|
58
61
|
export * from './context.js';
|
|
59
62
|
export * from './hooks/index.js';
|
|
63
|
+
export * from './link/index.js';
|
|
60
64
|
export * from './session-ready/index.js';
|
|
61
65
|
export * from './stores/index.js';
|
|
62
66
|
export * from './types.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
An `<a href={to}>` that navigates in-app through the molecule router, with
|
|
4
|
+
react-router `<Link>`'s rules (`followRouterLink` from `@molecule/app-routing`):
|
|
5
|
+
a plain primary click navigates without a page load; a ctrl/cmd, shift or alt
|
|
6
|
+
click, a `target` other than `_self`, a click an `onclick` already prevented,
|
|
7
|
+
and a URL on another origin are left to the browser.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { followRouterLink } from '@molecule/app-routing'
|
|
11
|
+
|
|
12
|
+
import { useRouterInstance } from '../context.js'
|
|
13
|
+
import type { LinkProps } from './types.js'
|
|
14
|
+
|
|
15
|
+
let { to, replace, state, children, onclick, ...anchor }: LinkProps = $props()
|
|
16
|
+
|
|
17
|
+
const router = useRouterInstance()
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Runs the caller's `onclick`, then navigates in-app for a click the router
|
|
21
|
+
* should take.
|
|
22
|
+
*
|
|
23
|
+
* @param event - The anchor's click event.
|
|
24
|
+
*/
|
|
25
|
+
function handleClick(
|
|
26
|
+
event: MouseEvent & { currentTarget: EventTarget & HTMLAnchorElement },
|
|
27
|
+
): void {
|
|
28
|
+
onclick?.(event)
|
|
29
|
+
followRouterLink(event, to, router, { replace, state })
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<a {...anchor} href={to} onclick={handleClick}>{@render children?.()}</a>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LinkProps } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* An `<a href={to}>` that navigates in-app through the molecule router, with
|
|
4
|
+
* react-router `<Link>`'s rules (`followRouterLink` from `@molecule/app-routing`):
|
|
5
|
+
* a plain primary click navigates without a page load; a ctrl/cmd, shift or alt
|
|
6
|
+
* click, a `target` other than `_self`, a click an `onclick` already prevented,
|
|
7
|
+
* and a URL on another origin are left to the browser.
|
|
8
|
+
*/
|
|
9
|
+
declare const Link: import("svelte").Component<LinkProps, {}, "">;
|
|
10
|
+
type Link = ReturnType<typeof Link>;
|
|
11
|
+
export default Link;
|
|
12
|
+
//# sourceMappingURL=Link.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Link.svelte.d.ts","sourceRoot":"","sources":["../../src/link/Link.svelte"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA+B5C;;;;;;GAMG;AACH,QAAA,MAAM,IAAI,+CAAwC,CAAC;AACnD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Link`: an in-app anchor for Svelte, the counterpart of react-router's `<Link>`.
|
|
3
|
+
*
|
|
4
|
+
* Use it for every internal link instead of an anchor with a click handler that
|
|
5
|
+
* calls `navigate()`. It reads the router from `setMoleculeContext`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```svelte
|
|
9
|
+
* <script lang="ts">
|
|
10
|
+
* import { Link } from '@molecule/app-svelte'
|
|
11
|
+
* </script>
|
|
12
|
+
*
|
|
13
|
+
* <nav>
|
|
14
|
+
* <Link to="/projects" class="nav-link">Projects</Link>
|
|
15
|
+
* <Link to="/login" replace state={{ from: '/projects' }}>Log in</Link>
|
|
16
|
+
* </nav>
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
export { default as Link } from './Link.svelte';
|
|
22
|
+
export * from './types.js';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/link/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,eAAe,CAAA;AAC/C,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Link`: an in-app anchor for Svelte, the counterpart of react-router's `<Link>`.
|
|
3
|
+
*
|
|
4
|
+
* Use it for every internal link instead of an anchor with a click handler that
|
|
5
|
+
* calls `navigate()`. It reads the router from `setMoleculeContext`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```svelte
|
|
9
|
+
* <script lang="ts">
|
|
10
|
+
* import { Link } from '@molecule/app-svelte'
|
|
11
|
+
* </script>
|
|
12
|
+
*
|
|
13
|
+
* <nav>
|
|
14
|
+
* <Link to="/projects" class="nav-link">Projects</Link>
|
|
15
|
+
* <Link to="/login" replace state={{ from: '/projects' }}>Log in</Link>
|
|
16
|
+
* </nav>
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
export { default as Link } from './Link.svelte';
|
|
22
|
+
export * from './types.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props of the Svelte `Link` component.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { Snippet } from 'svelte';
|
|
7
|
+
import type { HTMLAnchorAttributes } from 'svelte/elements';
|
|
8
|
+
/**
|
|
9
|
+
* Props for `Link`. Every other anchor attribute (`class`, `target`, `rel`,
|
|
10
|
+
* `aria-*`, `data-*`, `onclick`) goes on the anchor.
|
|
11
|
+
*/
|
|
12
|
+
export interface LinkProps extends Omit<HTMLAnchorAttributes, 'href' | 'children'> {
|
|
13
|
+
/** Destination: an app path (`/settings?tab=billing#plan`) or a URL. Rendered as the anchor's `href`. */
|
|
14
|
+
to: string;
|
|
15
|
+
/**
|
|
16
|
+
* Replace the current history entry instead of pushing one. When omitted, a
|
|
17
|
+
* link to the location already shown replaces it and any other link pushes,
|
|
18
|
+
* as with react-router's `<Link>`.
|
|
19
|
+
*/
|
|
20
|
+
replace?: boolean;
|
|
21
|
+
/** State stored with the new history entry (read back with `useLocation()`). */
|
|
22
|
+
state?: unknown;
|
|
23
|
+
/** The link's content. */
|
|
24
|
+
children?: Snippet;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/link/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAE3D;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,UAAU,CAAC;IAChF,yGAAyG;IACzG,EAAE,EAAE,MAAM,CAAA;IACV;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB"}
|
package/dist/stores/chat.d.ts
CHANGED
|
@@ -46,9 +46,10 @@ export declare const resetChatStoresForTests: typeof coreResetChatStoresForTests
|
|
|
46
46
|
* the controls (send, abort, queue edits, history). Call it during component
|
|
47
47
|
* init.
|
|
48
48
|
*
|
|
49
|
-
* The options may be a readable store
|
|
50
|
-
*
|
|
51
|
-
*
|
|
49
|
+
* The options may be a plain value or a readable store of one (a store holding
|
|
50
|
+
* `undefined` means no options): a new `endpoint` switches conversation and a
|
|
51
|
+
* new `projectId` moves to that project's transcript, on the same component,
|
|
52
|
+
* the way React re-renders `useChat`.
|
|
52
53
|
*
|
|
53
54
|
* @param options - Chat options (or a store of them): endpoint, project id, history loading, callbacks.
|
|
54
55
|
* @returns Each state field as a readable store, and the chat controls.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/stores/chat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAgB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEpE,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,eAAe,IAAI,mBAAmB,EAEtC,iBAAiB,IAAI,qBAAqB,EAC1C,uBAAuB,IAAI,2BAA2B,EACvD,MAAM,uBAAuB,CAAA;AAK9B,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,kBAAkB,CAAA;AAE/C,0CAA0C;AAC1C,MAAM,MAAM,kBAAkB,GAAG,eAAe,CAAA;AAEhD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,CAAC,IAAI,MAAM,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;CACtE,GAAG,mBAAmB,CAAA;AAEvB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,mBAAyC,CAAA;AAE9E;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAAO,qBAA6C,CAAA;AAEpF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,OAAO,2BAChB,CAAA;AAE7B
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/stores/chat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAgB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEpE,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,eAAe,IAAI,mBAAmB,EAEtC,iBAAiB,IAAI,qBAAqB,EAC1C,uBAAuB,IAAI,2BAA2B,EACvD,MAAM,uBAAuB,CAAA;AAK9B,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,kBAAkB,CAAA;AAE/C,0CAA0C;AAC1C,MAAM,MAAM,kBAAkB,GAAG,eAAe,CAAA;AAEhD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,CAAC,IAAI,MAAM,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;CACtE,GAAG,mBAAmB,CAAA;AAEvB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,mBAAyC,CAAA;AAE9E;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAAO,qBAA6C,CAAA;AAEpF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,OAAO,2BAChB,CAAA;AAE7B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC,GAAG,aAAa,CA2BzF"}
|
package/dist/stores/chat.js
CHANGED
|
@@ -8,7 +8,7 @@ import { onDestroy, onMount } from 'svelte';
|
|
|
8
8
|
import { derived, get, writable } from 'svelte/store';
|
|
9
9
|
import { convergeHistory as coreConvergeHistory, createChatSession, localOnlyMessages as coreLocalOnlyMessages, resetChatStoresForTests as coreResetChatStoresForTests, } from '@molecule/app-ai-chat';
|
|
10
10
|
import { useChatProvider } from '../context.js';
|
|
11
|
-
import {
|
|
11
|
+
import { toReadable } from '../hooks/maybe-readable.js';
|
|
12
12
|
/**
|
|
13
13
|
* Converges the local transcript with authoritative server history. See
|
|
14
14
|
* `convergeHistory` in `@molecule/app-ai-chat`.
|
|
@@ -37,9 +37,10 @@ export const resetChatStoresForTests = coreResetChatStoresForTests;
|
|
|
37
37
|
* the controls (send, abort, queue edits, history). Call it during component
|
|
38
38
|
* init.
|
|
39
39
|
*
|
|
40
|
-
* The options may be a readable store
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* The options may be a plain value or a readable store of one (a store holding
|
|
41
|
+
* `undefined` means no options): a new `endpoint` switches conversation and a
|
|
42
|
+
* new `projectId` moves to that project's transcript, on the same component,
|
|
43
|
+
* the way React re-renders `useChat`.
|
|
43
44
|
*
|
|
44
45
|
* @param options - Chat options (or a store of them): endpoint, project id, history loading, callbacks.
|
|
45
46
|
* @returns Each state field as a readable store, and the chat controls.
|
|
@@ -57,25 +58,23 @@ export const resetChatStoresForTests = coreResetChatStoresForTests;
|
|
|
57
58
|
*/
|
|
58
59
|
export function useChat(options) {
|
|
59
60
|
const provider = useChatProvider();
|
|
60
|
-
|
|
61
|
+
const optionsStore = toReadable(options);
|
|
62
|
+
let current = get(optionsStore);
|
|
61
63
|
const session = createChatSession({ ...current, provider });
|
|
62
64
|
const state = writable(session.getState());
|
|
63
65
|
const unsubscribe = session.subscribe(() => state.set(session.getState()));
|
|
64
66
|
// New options reach the session as React's re-render does; a changed
|
|
65
67
|
// endpoint is a conversation change, which the session loads. The store
|
|
66
68
|
// calls back at once with the options the session was created with.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
session.update({ ...next, provider });
|
|
74
|
-
});
|
|
75
|
-
}
|
|
69
|
+
const stopOptions = optionsStore.subscribe((next) => {
|
|
70
|
+
if (next === current)
|
|
71
|
+
return;
|
|
72
|
+
current = next;
|
|
73
|
+
session.update({ ...current, provider });
|
|
74
|
+
});
|
|
76
75
|
onMount(() => session.connect());
|
|
77
76
|
onDestroy(() => {
|
|
78
|
-
stopOptions
|
|
77
|
+
stopOptions();
|
|
79
78
|
unsubscribe();
|
|
80
79
|
});
|
|
81
80
|
const fields = Object.fromEntries(Object.keys(session.getState()).map((key) => [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-svelte",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.1",
|
|
4
4
|
"description": "Svelte framework bindings for molecule.dev",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@molecule/app-auth": "^3.0.0",
|
|
39
39
|
"@molecule/app-code-editor": "^1.0.1",
|
|
40
40
|
"@molecule/app-device": "^1.0.1",
|
|
41
|
-
"@molecule/app-forms": "^2.
|
|
41
|
+
"@molecule/app-forms": "^2.4.0",
|
|
42
42
|
"@molecule/app-http": "^1.0.1",
|
|
43
43
|
"@molecule/app-i18n": "^1.0.1",
|
|
44
44
|
"@molecule/app-ide": "^1.0.1",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"@molecule/app-logger": "^1.0.1",
|
|
47
47
|
"@molecule/app-platform": "^1.0.1",
|
|
48
48
|
"@molecule/app-push": "^1.0.1",
|
|
49
|
-
"@molecule/app-routing": "^1.
|
|
49
|
+
"@molecule/app-routing": "^1.3.0",
|
|
50
50
|
"@molecule/app-state": "^1.2.0",
|
|
51
51
|
"@molecule/app-storage": "^1.1.1",
|
|
52
52
|
"@molecule/app-theme": "^1.0.1",
|
|
53
53
|
"@molecule/app-ui": "^1.0.1",
|
|
54
54
|
"@molecule/app-utilities": "^1.0.1",
|
|
55
55
|
"@molecule/app-version": "^1.0.1",
|
|
56
|
-
"svelte": "^5.
|
|
56
|
+
"svelte": "^5.7.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"@molecule/app-code-editor": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@molecule/app-ai-chat": "1.8.0",
|
|
71
71
|
"@molecule/app-ai-models": "1.4.4",
|
|
72
72
|
"@molecule/app-framework-conformance": "0.0.0",
|
|
73
|
-
"@molecule/app-utilities": "1.0.
|
|
73
|
+
"@molecule/app-utilities": "1.0.7",
|
|
74
74
|
"@sveltejs/package": "3.0.2",
|
|
75
75
|
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
76
76
|
"@types/node": "26.6.5",
|