@ulam/halohalo 0.3.2 → 0.3.3

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/vue.js CHANGED
@@ -1,73 +1,73 @@
1
- /**
2
- * @ulam/halohalo/vue: Vue composables adapter
3
- */
4
- import { ref, readonly } from 'vue'
5
- import { createCompletion } from './createCompletion.js'
6
- import { createProviderConfig } from './createProviderConfig.js'
7
-
8
- /**
9
- * Reactive wrapper around createCompletion(). Returns reactive loading and
10
- * animating state, plus complete() and cancel() functions.
11
- *
12
- * @param {object} [defaultOptions] - default options merged into every complete() call
13
- */
14
- export function useCompletion(defaultOptions = {}) {
15
- const instance = createCompletion()
16
- const loading = ref(false)
17
- const animating = ref(false)
18
-
19
- const unsubscribe = instance.subscribe(({ loading: l, animating: a }) => {
20
- loading.value = l
21
- animating.value = a
22
- })
23
-
24
- // caller should invoke cleanup() in onUnmounted if used inside a component
25
- function cleanup() {
26
- instance.cancel()
27
- unsubscribe()
28
- }
29
-
30
- return {
31
- loading: readonly(loading),
32
- animating: readonly(animating),
33
- complete: (callOptions) => instance.complete({ ...defaultOptions, ...callOptions }),
34
- cancel: () => instance.cancel(),
35
- cleanup,
36
- }
37
- }
38
-
39
- /**
40
- * Reactive wrapper around createProviderConfig(). All config fields are reactive
41
- * refs; setters update the underlying singleton and trigger re-reads.
42
- *
43
- * @param {object} [storageKeys]
44
- * @param {Array} [providers]
45
- */
46
- export function useProviderConfig(storageKeys, providers) {
47
- const config = createProviderConfig(storageKeys, providers)
48
-
49
- const provider = ref(config.provider)
50
- const models = ref(config.models)
51
- const mode = ref(config.mode)
52
-
53
- const unsubscribe = config.subscribe(() => {
54
- provider.value = config.provider
55
- models.value = config.models
56
- mode.value = config.mode
57
- })
58
-
59
- return {
60
- provider: readonly(provider),
61
- models: readonly(models),
62
- mode: readonly(mode),
63
- providers: config.providers,
64
- setProvider: (id) => config.setProvider(id),
65
- setModel: (pid, mid) => config.setModel(pid, mid),
66
- setMode: (v) => config.setMode(v),
67
- setKey: (pid, v) => config.setKey(pid, v),
68
- getKey: (pid) => config.getKey(pid),
69
- getModel: (pid) => config.getModel(pid),
70
- getLabel: (pid) => config.getLabel(pid),
71
- cleanup: unsubscribe,
72
- }
73
- }
1
+ /**
2
+ * @ulam/halohalo/vue: Vue composables adapter
3
+ */
4
+ import { ref, readonly } from 'vue'
5
+ import { createCompletion } from './createCompletion.js'
6
+ import { createProviderConfig } from './createProviderConfig.js'
7
+
8
+ /**
9
+ * Reactive wrapper around createCompletion(). Returns reactive loading and
10
+ * animating state, plus complete() and cancel() functions.
11
+ *
12
+ * @param {object} [defaultOptions] - default options merged into every complete() call
13
+ */
14
+ export function useCompletion(defaultOptions = {}) {
15
+ const instance = createCompletion()
16
+ const loading = ref(false)
17
+ const animating = ref(false)
18
+
19
+ const unsubscribe = instance.subscribe(({ loading: l, animating: a }) => {
20
+ loading.value = l
21
+ animating.value = a
22
+ })
23
+
24
+ // caller should invoke cleanup() in onUnmounted if used inside a component
25
+ function cleanup() {
26
+ instance.cancel()
27
+ unsubscribe()
28
+ }
29
+
30
+ return {
31
+ loading: readonly(loading),
32
+ animating: readonly(animating),
33
+ complete: (callOptions) => instance.complete({ ...defaultOptions, ...callOptions }),
34
+ cancel: () => instance.cancel(),
35
+ cleanup,
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Reactive wrapper around createProviderConfig(). All config fields are reactive
41
+ * refs; setters update the underlying singleton and trigger re-reads.
42
+ *
43
+ * @param {object} [storageKeys]
44
+ * @param {Array} [providers]
45
+ */
46
+ export function useProviderConfig(storageKeys, providers) {
47
+ const config = createProviderConfig(storageKeys, providers)
48
+
49
+ const provider = ref(config.provider)
50
+ const models = ref(config.models)
51
+ const mode = ref(config.mode)
52
+
53
+ const unsubscribe = config.subscribe(() => {
54
+ provider.value = config.provider
55
+ models.value = config.models
56
+ mode.value = config.mode
57
+ })
58
+
59
+ return {
60
+ provider: readonly(provider),
61
+ models: readonly(models),
62
+ mode: readonly(mode),
63
+ providers: config.providers,
64
+ setProvider: (id) => config.setProvider(id),
65
+ setModel: (pid, mid) => config.setModel(pid, mid),
66
+ setMode: (v) => config.setMode(v),
67
+ setKey: (pid, v) => config.setKey(pid, v),
68
+ getKey: (pid) => config.getKey(pid),
69
+ getModel: (pid) => config.getModel(pid),
70
+ getLabel: (pid) => config.getLabel(pid),
71
+ cleanup: unsubscribe,
72
+ }
73
+ }