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