ai 2.1.23 → 2.1.24
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/package.json +19 -6
- package/solid/dist/index.d.ts +239 -0
- package/solid/dist/index.js +411 -0
- package/solid/dist/index.mjs +386 -0
- package/svelte/dist/index.js +364 -310
- package/svelte/dist/index.mjs +367 -313
package/svelte/dist/index.mjs
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
|
+
var __defProps = Object.defineProperties;
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
14
16
|
}
|
15
17
|
return a;
|
16
18
|
};
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
17
20
|
var __async = (__this, __arguments, generator) => {
|
18
21
|
return new Promise((resolve, reject) => {
|
19
22
|
var fulfilled = (value) => {
|
@@ -30,7 +33,7 @@ var __async = (__this, __arguments, generator) => {
|
|
30
33
|
reject(e);
|
31
34
|
}
|
32
35
|
};
|
33
|
-
var step = (
|
36
|
+
var step = (x3) => x3.done ? resolve(x3.value) : Promise.resolve(x3.value).then(fulfilled, rejected);
|
34
37
|
step((generator = generator.apply(__this, __arguments)).next());
|
35
38
|
});
|
36
39
|
};
|
@@ -38,376 +41,418 @@ var __async = (__this, __arguments, generator) => {
|
|
38
41
|
// svelte/use-chat.ts
|
39
42
|
import { get, writable } from "svelte/store";
|
40
43
|
|
41
|
-
// ../../node_modules/.pnpm/swrev@
|
42
|
-
var
|
43
|
-
var
|
44
|
-
var
|
45
|
-
var
|
46
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
47
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
48
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
49
|
-
var __spreadValues2 = (a, b) => {
|
50
|
-
for (var prop in b || (b = {}))
|
51
|
-
if (__hasOwnProp2.call(b, prop))
|
52
|
-
__defNormalProp2(a, prop, b[prop]);
|
53
|
-
if (__getOwnPropSymbols2)
|
54
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
55
|
-
if (__propIsEnum2.call(b, prop))
|
56
|
-
__defNormalProp2(a, prop, b[prop]);
|
57
|
-
}
|
58
|
-
return a;
|
59
|
-
};
|
60
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
61
|
-
var __publicField = (obj, key, value) => {
|
62
|
-
__defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
63
|
-
return value;
|
64
|
-
};
|
65
|
-
var DefaultSWREventManager = class {
|
44
|
+
// ../../node_modules/.pnpm/swrev@4.0.0/node_modules/swrev/dist/swrev.mjs
|
45
|
+
var P = Object.defineProperty;
|
46
|
+
var F = (r, e, t) => e in r ? P(r, e, { enumerable: true, configurable: true, writable: true, value: t }) : r[e] = t;
|
47
|
+
var h = (r, e, t) => (F(r, typeof e != "symbol" ? e + "" : e, t), t);
|
48
|
+
var I = class {
|
66
49
|
constructor() {
|
67
|
-
|
50
|
+
h(this, "listeners", /* @__PURE__ */ new Map());
|
68
51
|
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
this.listeners.get(key).push(listener);
|
52
|
+
/**
|
53
|
+
* Subscribes a given listener.
|
54
|
+
*/
|
55
|
+
subscribe(e, t) {
|
56
|
+
this.listeners.has(e) || this.listeners.set(e, []), !this.listeners.get(e).includes(t) && this.listeners.get(e).push(t);
|
75
57
|
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
this.listeners.get(key).splice(this.listeners.get(key).indexOf(listener), 1);
|
82
|
-
if (this.listeners.get(key).length === 0)
|
83
|
-
this.listeners.delete(key);
|
58
|
+
/**
|
59
|
+
* Unsubscribes the given listener.
|
60
|
+
*/
|
61
|
+
unsubscribe(e, t) {
|
62
|
+
this.listeners.has(e) && this.listeners.get(e).includes(t) && (this.listeners.get(e).splice(this.listeners.get(e).indexOf(t), 1), this.listeners.get(e).length === 0 && this.listeners.delete(e));
|
84
63
|
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
64
|
+
/**
|
65
|
+
* Emits an event to all active listeners.
|
66
|
+
*/
|
67
|
+
emit(e, t) {
|
68
|
+
this.listeners.has(e) && this.listeners.get(e).forEach((s) => s(t));
|
89
69
|
}
|
90
70
|
};
|
91
|
-
var
|
71
|
+
var L = {
|
92
72
|
broadcast: false
|
93
73
|
};
|
94
|
-
var
|
74
|
+
var S = {
|
95
75
|
broadcast: false
|
96
76
|
};
|
97
|
-
var
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
this
|
77
|
+
var O = class {
|
78
|
+
/**
|
79
|
+
* Creates the cache item given the data and expiration at.
|
80
|
+
*/
|
81
|
+
constructor({ data: e, expiresAt: t = null }) {
|
82
|
+
h(this, "data");
|
83
|
+
h(this, "expiresAt");
|
84
|
+
this.data = e, this.expiresAt = t;
|
103
85
|
}
|
86
|
+
/**
|
87
|
+
* Determines if the current cache item is still being resolved.
|
88
|
+
* This returns true if data is a promise, or false if type `D`.
|
89
|
+
*/
|
104
90
|
isResolving() {
|
105
91
|
return this.data instanceof Promise;
|
106
92
|
}
|
93
|
+
/**
|
94
|
+
* Determines if the given cache item has expired.
|
95
|
+
*/
|
107
96
|
hasExpired() {
|
108
97
|
return this.expiresAt === null || this.expiresAt < /* @__PURE__ */ new Date();
|
109
98
|
}
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
99
|
+
/**
|
100
|
+
* Set the expiration time of the given cache item relative to now.
|
101
|
+
*/
|
102
|
+
expiresIn(e) {
|
103
|
+
return this.expiresAt = /* @__PURE__ */ new Date(), this.expiresAt.setMilliseconds(this.expiresAt.getMilliseconds() + e), this;
|
114
104
|
}
|
115
105
|
};
|
116
|
-
var
|
106
|
+
var q = class {
|
117
107
|
constructor() {
|
118
|
-
|
119
|
-
|
108
|
+
h(this, "elements", /* @__PURE__ */ new Map());
|
109
|
+
h(this, "event", new I());
|
120
110
|
}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
111
|
+
/**
|
112
|
+
* Resolves the promise and replaces the Promise to the resolved data.
|
113
|
+
* It also broadcasts the value change if needed or deletes the key if
|
114
|
+
* the value resolves to undefined or null.
|
115
|
+
*/
|
116
|
+
resolve(e, t) {
|
117
|
+
Promise.resolve(t.data).then((s) => {
|
118
|
+
if (s == null)
|
119
|
+
return this.remove(e);
|
120
|
+
t.data = s, this.broadcast(e, s);
|
128
121
|
});
|
129
122
|
}
|
130
|
-
|
131
|
-
|
123
|
+
/**
|
124
|
+
* Gets an element from the cache.
|
125
|
+
*
|
126
|
+
* It is assumed the item always exist when
|
127
|
+
* you get it. Use the has method to check
|
128
|
+
* for the existence of it.
|
129
|
+
*/
|
130
|
+
get(e) {
|
131
|
+
return this.elements.get(e);
|
132
132
|
}
|
133
|
-
|
134
|
-
|
135
|
-
|
133
|
+
/**
|
134
|
+
* Sets an element to the cache.
|
135
|
+
*/
|
136
|
+
set(e, t) {
|
137
|
+
this.elements.set(e, t), this.resolve(e, t);
|
136
138
|
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
139
|
+
/**
|
140
|
+
* Removes an key-value pair from the cache.
|
141
|
+
*/
|
142
|
+
remove(e, t) {
|
143
|
+
const { broadcast: s } = __spreadValues(__spreadValues({}, L), t);
|
144
|
+
s && this.broadcast(e, void 0), this.elements.delete(e);
|
142
145
|
}
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
146
|
+
/**
|
147
|
+
* Removes all the key-value pairs from the cache.
|
148
|
+
*/
|
149
|
+
clear(e) {
|
150
|
+
const { broadcast: t } = __spreadValues(__spreadValues({}, S), e);
|
151
|
+
if (t)
|
152
|
+
for (const s of this.elements.keys())
|
153
|
+
this.broadcast(s, void 0);
|
148
154
|
this.elements.clear();
|
149
155
|
}
|
150
|
-
|
151
|
-
|
156
|
+
/**
|
157
|
+
* Determines if the given key exists
|
158
|
+
* in the cache.
|
159
|
+
*/
|
160
|
+
has(e) {
|
161
|
+
return this.elements.has(e);
|
152
162
|
}
|
153
|
-
|
154
|
-
|
163
|
+
/**
|
164
|
+
* Subscribes the callback to the given key.
|
165
|
+
*/
|
166
|
+
subscribe(e, t) {
|
167
|
+
this.event.subscribe(e, t);
|
155
168
|
}
|
156
|
-
|
157
|
-
|
169
|
+
/**
|
170
|
+
* Unsubscribes to the given key events.
|
171
|
+
*/
|
172
|
+
unsubscribe(e, t) {
|
173
|
+
this.event.unsubscribe(e, t);
|
158
174
|
}
|
159
|
-
|
160
|
-
|
175
|
+
/**
|
176
|
+
* Broadcasts a value change on all subscribed instances.
|
177
|
+
*/
|
178
|
+
broadcast(e, t) {
|
179
|
+
this.event.emit(e, t);
|
161
180
|
}
|
162
181
|
};
|
163
|
-
var
|
164
|
-
cache: new
|
165
|
-
errors: new
|
166
|
-
fetcher: (
|
167
|
-
const
|
168
|
-
if (!
|
182
|
+
var x = {
|
183
|
+
cache: new q(),
|
184
|
+
errors: new I(),
|
185
|
+
fetcher: (r) => __async(void 0, null, function* () {
|
186
|
+
const e = yield fetch(r);
|
187
|
+
if (!e.ok)
|
169
188
|
throw Error("Not a 2XX response.");
|
170
|
-
return
|
189
|
+
return e.json();
|
171
190
|
}),
|
172
|
-
|
191
|
+
fallbackData: void 0,
|
173
192
|
loadInitialCache: true,
|
174
193
|
revalidateOnStart: true,
|
175
194
|
dedupingInterval: 2e3,
|
176
195
|
revalidateOnFocus: true,
|
177
196
|
focusThrottleInterval: 5e3,
|
178
197
|
revalidateOnReconnect: true,
|
179
|
-
reconnectWhen: (
|
180
|
-
if (enabled && typeof window !== "undefined") {
|
181
|
-
window.addEventListener("online", notify);
|
182
|
-
return () => window.removeEventListener("online", notify);
|
183
|
-
}
|
184
|
-
return () => {
|
185
|
-
};
|
198
|
+
reconnectWhen: (r, { enabled: e }) => e && typeof window < "u" ? (window.addEventListener("online", r), () => window.removeEventListener("online", r)) : () => {
|
186
199
|
},
|
187
|
-
focusWhen: (
|
188
|
-
if (
|
189
|
-
let
|
190
|
-
const
|
191
|
-
const
|
192
|
-
|
193
|
-
lastFocus = now;
|
194
|
-
notify();
|
195
|
-
}
|
200
|
+
focusWhen: (r, { enabled: e, throttleInterval: t }) => {
|
201
|
+
if (e && typeof window < "u") {
|
202
|
+
let s = null;
|
203
|
+
const i = () => {
|
204
|
+
const a = Date.now();
|
205
|
+
(s === null || a - s > t) && (s = a, r());
|
196
206
|
};
|
197
|
-
window.addEventListener("focus",
|
198
|
-
return () => window.removeEventListener("focus", rawHandler);
|
207
|
+
return window.addEventListener("focus", i), () => window.removeEventListener("focus", i);
|
199
208
|
}
|
200
209
|
return () => {
|
201
210
|
};
|
202
|
-
}
|
211
|
+
},
|
212
|
+
revalidateFunction: void 0
|
203
213
|
};
|
204
|
-
var
|
214
|
+
var E = __spreadProps(__spreadValues({}, x), {
|
205
215
|
force: false
|
206
216
|
});
|
207
|
-
var
|
217
|
+
var T = {
|
208
218
|
revalidate: true,
|
209
|
-
revalidateOptions:
|
219
|
+
revalidateOptions: __spreadValues({}, E),
|
220
|
+
revalidateFunction: void 0
|
210
221
|
};
|
211
|
-
var
|
222
|
+
var X = {
|
212
223
|
broadcast: false
|
213
224
|
};
|
214
|
-
var
|
215
|
-
|
216
|
-
|
217
|
-
|
225
|
+
var H = class {
|
226
|
+
/**
|
227
|
+
* Creates a new instance of SWR.
|
228
|
+
*/
|
229
|
+
constructor(e) {
|
230
|
+
h(this, "options");
|
231
|
+
this.options = __spreadValues(__spreadValues({}, x), e);
|
218
232
|
}
|
233
|
+
/**
|
234
|
+
* Gets the cache of the SWR.
|
235
|
+
*/
|
219
236
|
get cache() {
|
220
237
|
return this.options.cache;
|
221
238
|
}
|
239
|
+
/**
|
240
|
+
* Gets the cache of the SWR.
|
241
|
+
*/
|
222
242
|
get errors() {
|
223
243
|
return this.options.errors;
|
224
244
|
}
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
245
|
+
/**
|
246
|
+
* Requests the data using the provided fetcher.
|
247
|
+
*/
|
248
|
+
requestData(e, t) {
|
249
|
+
return __async(this, null, function* () {
|
250
|
+
return yield Promise.resolve(t(e)).catch((s) => {
|
251
|
+
throw this.errors.emit(e, s), s;
|
252
|
+
});
|
229
253
|
});
|
230
254
|
}
|
231
|
-
|
232
|
-
|
255
|
+
/**
|
256
|
+
* Resolves the given to a SWRKey or undefined.
|
257
|
+
*/
|
258
|
+
resolveKey(e) {
|
259
|
+
if (typeof e == "function")
|
233
260
|
try {
|
234
|
-
return
|
235
|
-
} catch (
|
236
|
-
return
|
261
|
+
return e();
|
262
|
+
} catch (e2) {
|
263
|
+
return;
|
237
264
|
}
|
238
|
-
|
239
|
-
return key;
|
240
|
-
}
|
241
|
-
clear(keys, options) {
|
242
|
-
const ops = __spreadValues2(__spreadValues2({}, defaultClearOptions), options);
|
243
|
-
if (keys === void 0 || keys === null)
|
244
|
-
return this.cache.clear(ops);
|
245
|
-
if (!Array.isArray(keys))
|
246
|
-
return this.cache.remove(keys, ops);
|
247
|
-
for (const key of keys)
|
248
|
-
this.cache.remove(key, ops);
|
249
|
-
}
|
250
|
-
revalidate(key, options) {
|
251
|
-
if (!key)
|
252
|
-
return;
|
253
|
-
const { fetcher: defaultFetcher, dedupingInterval: defaultDedupingInterval } = this.options;
|
254
|
-
const { force, fetcher, dedupingInterval } = __spreadValues2(__spreadValues2(__spreadValues2({}, defaultRevalidateOptions), { fetcher: defaultFetcher, dedupingInterval: defaultDedupingInterval }), options);
|
255
|
-
let data = void 0;
|
256
|
-
if (force || !this.cache.has(key) || this.cache.has(key) && this.cache.get(key).hasExpired()) {
|
257
|
-
data = this.requestData(key, fetcher);
|
258
|
-
}
|
259
|
-
if (data !== void 0) {
|
260
|
-
this.mutate(key, new CacheItem({ data }).expiresIn(dedupingInterval), {
|
261
|
-
revalidate: false
|
262
|
-
});
|
263
|
-
}
|
265
|
+
return e;
|
264
266
|
}
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
267
|
+
/**
|
268
|
+
* Clear the specified keys from the cache. If no keys
|
269
|
+
* are specified, it clears all the cache keys.
|
270
|
+
*/
|
271
|
+
clear(e, t) {
|
272
|
+
const s = __spreadValues(__spreadValues({}, X), t);
|
273
|
+
if (e == null)
|
274
|
+
return this.cache.clear(s);
|
275
|
+
if (!Array.isArray(e))
|
276
|
+
return this.cache.remove(e, s);
|
277
|
+
for (const i of e)
|
278
|
+
this.cache.remove(i, s);
|
279
|
+
}
|
280
|
+
/**
|
281
|
+
* Revalidates the key and mutates the cache if needed.
|
282
|
+
*/
|
283
|
+
revalidate(e, t) {
|
284
|
+
return __async(this, null, function* () {
|
285
|
+
if (!e)
|
286
|
+
throw new Error("[Revalidate] Key issue: ${key}");
|
287
|
+
const { fetcher: s, dedupingInterval: i } = this.options, { force: a, fetcher: o, dedupingInterval: n } = __spreadValues(__spreadProps(__spreadValues({}, E), {
|
288
|
+
fetcher: s,
|
289
|
+
dedupingInterval: i
|
290
|
+
}), t);
|
291
|
+
if (a || !this.cache.has(e) || this.cache.has(e) && this.cache.get(e).hasExpired()) {
|
292
|
+
const c2 = this.requestData(e, o), l = c2.catch(() => {
|
293
|
+
});
|
294
|
+
return this.cache.set(e, new O({ data: l }).expiresIn(n)), yield c2;
|
276
295
|
}
|
277
|
-
|
278
|
-
}
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
296
|
+
return this.getWait(e);
|
297
|
+
});
|
298
|
+
}
|
299
|
+
/**
|
300
|
+
* Mutates the data of a given key with a new value.
|
301
|
+
* This is used to replace the cache contents of the
|
302
|
+
* given key manually.
|
303
|
+
*/
|
304
|
+
mutate(e, t, s) {
|
305
|
+
return __async(this, null, function* () {
|
306
|
+
var _a;
|
307
|
+
if (!e)
|
308
|
+
throw new Error("[Mutate] Key issue: ${key}");
|
309
|
+
const {
|
310
|
+
revalidate: i,
|
311
|
+
revalidateOptions: a,
|
312
|
+
revalidateFunction: o
|
313
|
+
} = __spreadValues(__spreadValues({}, T), s);
|
314
|
+
let n;
|
315
|
+
if (typeof t == "function") {
|
316
|
+
let c2;
|
317
|
+
if (this.cache.has(e)) {
|
318
|
+
const l = this.cache.get(e);
|
319
|
+
l.isResolving() || (c2 = l.data);
|
320
|
+
}
|
321
|
+
n = t(c2);
|
322
|
+
} else
|
323
|
+
n = t;
|
324
|
+
return this.cache.set(e, new O({ data: n })), i ? yield (_a = o == null ? void 0 : o(e, a)) != null ? _a : this.revalidate(e, a) : n;
|
325
|
+
});
|
326
|
+
}
|
327
|
+
/**
|
328
|
+
* Gets the data of the given key. Keep in mind
|
329
|
+
* this data will be stale and revalidate in the background
|
330
|
+
* unless specified otherwise.
|
331
|
+
*/
|
332
|
+
subscribeData(e, t) {
|
333
|
+
if (e) {
|
334
|
+
const s = (i) => t(i);
|
335
|
+
return this.cache.subscribe(e, s), () => this.cache.unsubscribe(e, s);
|
290
336
|
}
|
291
337
|
return () => {
|
292
338
|
};
|
293
339
|
}
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
340
|
+
/**
|
341
|
+
* Subscribes to errors on the given key.
|
342
|
+
*/
|
343
|
+
subscribeErrors(e, t) {
|
344
|
+
if (e) {
|
345
|
+
const s = (i) => t(i);
|
346
|
+
return this.errors.subscribe(e, s), () => this.errors.unsubscribe(e, s);
|
299
347
|
}
|
300
348
|
return () => {
|
301
349
|
};
|
302
350
|
}
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
351
|
+
/**
|
352
|
+
* Gets the current cached data of the given key.
|
353
|
+
* This does not trigger any revalidation nor mutation
|
354
|
+
* of the data.
|
355
|
+
* - If the data has never been validated
|
356
|
+
* (there is no cache) it will return undefined.
|
357
|
+
* - If the item is pending to resolve (there is a request
|
358
|
+
* pending to resolve) it will return undefined.
|
359
|
+
*/
|
360
|
+
get(e) {
|
361
|
+
if (e && this.cache.has(e)) {
|
362
|
+
const t = this.cache.get(e);
|
363
|
+
if (!t.isResolving())
|
364
|
+
return t.data;
|
308
365
|
}
|
309
|
-
return void 0;
|
310
366
|
}
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
367
|
+
/**
|
368
|
+
* Gets an element from the cache. The difference
|
369
|
+
* with the get is that this method returns a promise
|
370
|
+
* that will resolve the the value. If there's no item
|
371
|
+
* in the cache, it will wait for it before resolving.
|
372
|
+
*/
|
373
|
+
getWait(e) {
|
374
|
+
return new Promise((t, s) => {
|
375
|
+
const i = this.subscribeData(e, (n) => {
|
376
|
+
if (i(), n !== void 0)
|
377
|
+
return t(n);
|
378
|
+
}), a = this.subscribeErrors(e, (n) => {
|
379
|
+
if (a(), n !== void 0)
|
380
|
+
return s(n);
|
381
|
+
}), o = this.get(e);
|
382
|
+
if (o !== void 0)
|
383
|
+
return t(o);
|
324
384
|
});
|
325
385
|
}
|
326
|
-
|
386
|
+
/**
|
387
|
+
* Use a SWR value given the key and
|
388
|
+
* subscribe to future changes.
|
389
|
+
*/
|
390
|
+
subscribe(e, t, s, i) {
|
327
391
|
const {
|
328
|
-
fetcher,
|
329
|
-
|
330
|
-
loadInitialCache,
|
331
|
-
revalidateOnStart,
|
332
|
-
dedupingInterval,
|
333
|
-
revalidateOnFocus,
|
334
|
-
focusThrottleInterval,
|
335
|
-
revalidateOnReconnect,
|
336
|
-
reconnectWhen,
|
337
|
-
focusWhen
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
}
|
348
|
-
|
349
|
-
revalidateCurrentWithOptions();
|
350
|
-
const unsubscribeData = this.subscribeData(this.resolveKey(key), onData);
|
351
|
-
const unsubscribeErrors = this.subscribeErrors(this.resolveKey(key), onError);
|
352
|
-
const unsubscribeVisibility = focusWhen(revalidateCurrentWithOptions, {
|
353
|
-
throttleInterval: focusThrottleInterval,
|
354
|
-
enabled: revalidateOnFocus
|
355
|
-
});
|
356
|
-
const unsubscribeNetwork = reconnectWhen(revalidateCurrentWithOptions, {
|
357
|
-
enabled: revalidateOnReconnect
|
392
|
+
fetcher: a,
|
393
|
+
fallbackData: o,
|
394
|
+
loadInitialCache: n,
|
395
|
+
revalidateOnStart: c2,
|
396
|
+
dedupingInterval: l,
|
397
|
+
revalidateOnFocus: A2,
|
398
|
+
focusThrottleInterval: C,
|
399
|
+
revalidateOnReconnect: R,
|
400
|
+
reconnectWhen: W2,
|
401
|
+
focusWhen: D2,
|
402
|
+
revalidateFunction: d
|
403
|
+
} = __spreadValues(__spreadValues({}, this.options), i), K2 = (m) => {
|
404
|
+
var _a;
|
405
|
+
return (_a = d == null ? void 0 : d(this.resolveKey(e), m)) != null ? _a : this.revalidate(this.resolveKey(e), m);
|
406
|
+
}, f = () => K2({ fetcher: a, dedupingInterval: l }), u = n ? this.get(this.resolveKey(e)) : o != null ? o : void 0, g = c2 ? f() : Promise.resolve(void 0), M = u ? Promise.resolve(u) : g;
|
407
|
+
u && (t == null || t(u));
|
408
|
+
const v2 = t ? this.subscribeData(this.resolveKey(e), t) : void 0, b = s ? this.subscribeErrors(this.resolveKey(e), s) : void 0, p2 = D2(f, {
|
409
|
+
throttleInterval: C,
|
410
|
+
enabled: A2
|
411
|
+
}), w2 = W2(f, {
|
412
|
+
enabled: R
|
358
413
|
});
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
unsubscribeVisibility == null ? void 0 : unsubscribeVisibility();
|
363
|
-
unsubscribeNetwork == null ? void 0 : unsubscribeNetwork();
|
364
|
-
};
|
365
|
-
if (initialData) {
|
366
|
-
mutateCurrent(initialData, { revalidate: false });
|
367
|
-
}
|
368
|
-
if (loadInitialCache) {
|
369
|
-
const cachedData = this.get(this.resolveKey(key));
|
370
|
-
if (cachedData)
|
371
|
-
onData(cachedData);
|
372
|
-
}
|
373
|
-
return { unsubscribe };
|
414
|
+
return { unsubscribe: () => {
|
415
|
+
v2 == null || v2(), b == null || b(), p2 == null || p2(), w2 == null || w2();
|
416
|
+
}, dataPromise: M, revalidatePromise: g };
|
374
417
|
}
|
375
418
|
};
|
376
419
|
|
377
|
-
// ../../node_modules/.pnpm/sswr@
|
378
|
-
import { beforeUpdate as
|
379
|
-
function
|
420
|
+
// ../../node_modules/.pnpm/sswr@2.0.0_svelte@4.0.0/node_modules/sswr/dist/sswr.mjs
|
421
|
+
import { beforeUpdate as w, onDestroy as E2 } from "svelte";
|
422
|
+
function p() {
|
380
423
|
}
|
381
|
-
function
|
424
|
+
function D(t) {
|
382
425
|
return t();
|
383
426
|
}
|
384
|
-
function
|
385
|
-
t.forEach(
|
427
|
+
function q2(t) {
|
428
|
+
t.forEach(D);
|
386
429
|
}
|
387
|
-
function
|
430
|
+
function x2(t) {
|
388
431
|
return typeof t == "function";
|
389
432
|
}
|
390
433
|
function K(t, e) {
|
391
434
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
392
435
|
}
|
393
|
-
function
|
394
|
-
if (t == null)
|
395
|
-
|
436
|
+
function z(t, ...e) {
|
437
|
+
if (t == null) {
|
438
|
+
for (const r of e)
|
439
|
+
r(void 0);
|
440
|
+
return p;
|
441
|
+
}
|
396
442
|
const n = t.subscribe(...e);
|
397
443
|
return n.unsubscribe ? () => n.unsubscribe() : n;
|
398
444
|
}
|
399
|
-
Promise.resolve();
|
400
445
|
var v = [];
|
401
|
-
function
|
446
|
+
function A(t, e) {
|
402
447
|
return {
|
403
|
-
subscribe:
|
448
|
+
subscribe: y(t, e).subscribe
|
404
449
|
};
|
405
450
|
}
|
406
|
-
function
|
451
|
+
function y(t, e = p) {
|
407
452
|
let n;
|
408
453
|
const r = /* @__PURE__ */ new Set();
|
409
|
-
function
|
410
|
-
if (K(t,
|
454
|
+
function i(u) {
|
455
|
+
if (K(t, u) && (t = u, n)) {
|
411
456
|
const f = !v.length;
|
412
457
|
for (const s of r)
|
413
458
|
s[1](), v.push(s, t);
|
@@ -418,63 +463,72 @@ function m(t, e = h) {
|
|
418
463
|
}
|
419
464
|
}
|
420
465
|
}
|
421
|
-
function
|
422
|
-
|
466
|
+
function a(u) {
|
467
|
+
i(u(t));
|
423
468
|
}
|
424
|
-
function d(
|
425
|
-
const s = [
|
426
|
-
return r.add(s), r.size === 1 && (n = e(
|
427
|
-
r.delete(s), r.size === 0 && (n(), n = null);
|
469
|
+
function d(u, f = p) {
|
470
|
+
const s = [u, f];
|
471
|
+
return r.add(s), r.size === 1 && (n = e(i, a) || p), u(t), () => {
|
472
|
+
r.delete(s), r.size === 0 && n && (n(), n = null);
|
428
473
|
};
|
429
474
|
}
|
430
|
-
return { set:
|
475
|
+
return { set: i, update: a, subscribe: d };
|
431
476
|
}
|
432
|
-
function
|
433
|
-
const r = !Array.isArray(t),
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
477
|
+
function S2(t, e, n) {
|
478
|
+
const r = !Array.isArray(t), i = r ? [t] : t;
|
479
|
+
if (!i.every(Boolean))
|
480
|
+
throw new Error("derived() expects stores as input, got a falsy value");
|
481
|
+
const a = e.length < 2;
|
482
|
+
return A(n, (d, u) => {
|
483
|
+
let f = false;
|
484
|
+
const s = [];
|
485
|
+
let h2 = 0, o = p;
|
486
|
+
const l = () => {
|
487
|
+
if (h2)
|
440
488
|
return;
|
441
|
-
|
442
|
-
const
|
443
|
-
|
444
|
-
},
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
489
|
+
o();
|
490
|
+
const b = e(r ? s[0] : s, d, u);
|
491
|
+
a ? d(b) : o = x2(b) ? b : p;
|
492
|
+
}, g = i.map(
|
493
|
+
(b, m) => z(
|
494
|
+
b,
|
495
|
+
(R) => {
|
496
|
+
s[m] = R, h2 &= ~(1 << m), f && l();
|
497
|
+
},
|
498
|
+
() => {
|
499
|
+
h2 |= 1 << m;
|
500
|
+
}
|
501
|
+
)
|
502
|
+
);
|
503
|
+
return f = true, l(), function() {
|
504
|
+
q2(g), o(), f = false;
|
451
505
|
};
|
452
506
|
});
|
453
507
|
}
|
454
|
-
var
|
508
|
+
var O2 = class extends H {
|
455
509
|
/**
|
456
510
|
* Svelte specific use of SWR.
|
457
511
|
*/
|
458
512
|
useSWR(e, n) {
|
459
513
|
let r;
|
460
|
-
const
|
461
|
-
|
462
|
-
const o = (
|
463
|
-
|
464
|
-
},
|
465
|
-
r || (r = this.subscribe(e, o,
|
514
|
+
const i = y(void 0, () => () => r == null ? void 0 : r()), a = y(void 0, () => () => r == null ? void 0 : r());
|
515
|
+
w(() => {
|
516
|
+
const o = (g) => {
|
517
|
+
a.set(void 0), i.set(g);
|
518
|
+
}, l = (g) => a.set(g);
|
519
|
+
r || (r = this.subscribe(e, o, l, __spreadValues({
|
466
520
|
loadInitialCache: true
|
467
521
|
}, n)).unsubscribe);
|
468
|
-
}),
|
469
|
-
const d = (o,
|
522
|
+
}), E2(() => r == null ? void 0 : r());
|
523
|
+
const d = (o, l) => this.mutate(this.resolveKey(e), o, __spreadValues({
|
470
524
|
revalidateOptions: n
|
471
|
-
},
|
472
|
-
return { data:
|
525
|
+
}, l)), u = (o) => this.revalidate(this.resolveKey(e), __spreadValues(__spreadValues({}, n), o)), f = (o) => this.clear(this.resolveKey(e), o), s = S2([i, a], ([o, l]) => o === void 0 && l === void 0), h2 = S2([i, a], ([o, l]) => o !== void 0 && l === void 0);
|
526
|
+
return { data: i, error: a, mutate: d, revalidate: u, clear: f, isLoading: s, isValid: h2 };
|
473
527
|
}
|
474
528
|
};
|
475
|
-
var W = (t) => new
|
476
|
-
var
|
477
|
-
var
|
529
|
+
var W = (t) => new O2(t);
|
530
|
+
var c = W();
|
531
|
+
var F2 = (t, e) => c.useSWR(t, e);
|
478
532
|
|
479
533
|
// shared/utils.ts
|
480
534
|
import { customAlphabet } from "nanoid/non-secure";
|
@@ -594,9 +648,9 @@ function useChat({
|
|
594
648
|
} = {}) {
|
595
649
|
const chatId = id || `chat-${uniqueId++}`;
|
596
650
|
const key = `${api}|${chatId}`;
|
597
|
-
const { data, mutate: originalMutate } =
|
651
|
+
const { data, mutate: originalMutate } = F2(key, {
|
598
652
|
fetcher: () => store[key] || initialMessages,
|
599
|
-
|
653
|
+
fallbackData: initialMessages
|
600
654
|
});
|
601
655
|
data.set(initialMessages);
|
602
656
|
const mutate = (data2) => {
|
@@ -744,9 +798,9 @@ function useCompletion({
|
|
744
798
|
} = {}) {
|
745
799
|
const completionId = id || `completion-${uniqueId2++}`;
|
746
800
|
const key = `${api}|${completionId}`;
|
747
|
-
const { data, mutate: originalMutate } =
|
801
|
+
const { data, mutate: originalMutate } = F2(key, {
|
748
802
|
fetcher: () => store2[key] || initialCompletion,
|
749
|
-
|
803
|
+
fallbackData: initialCompletion
|
750
804
|
});
|
751
805
|
data.set(initialCompletion);
|
752
806
|
const mutate = (data2) => {
|