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.
@@ -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 = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected);
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@3.0.0/node_modules/swrev/dist/swrev.es.js
42
- var __defProp2 = Object.defineProperty;
43
- var __defProps = Object.defineProperties;
44
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
45
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
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
- __publicField(this, "listeners", /* @__PURE__ */ new Map());
50
+ h(this, "listeners", /* @__PURE__ */ new Map());
68
51
  }
69
- subscribe(key, listener) {
70
- if (!this.listeners.has(key))
71
- this.listeners.set(key, []);
72
- if (this.listeners.get(key).includes(listener))
73
- return;
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
- unsubscribe(key, listener) {
77
- if (!this.listeners.has(key))
78
- return;
79
- if (!this.listeners.get(key).includes(listener))
80
- return;
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
- emit(key, payload) {
86
- if (!this.listeners.has(key))
87
- return;
88
- this.listeners.get(key).forEach((listener) => listener(payload));
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 defaultCacheRemoveOptions = {
71
+ var L = {
92
72
  broadcast: false
93
73
  };
94
- var defaultCacheClearOptions = {
74
+ var S = {
95
75
  broadcast: false
96
76
  };
97
- var CacheItem = class {
98
- constructor({ data, expiresAt = null }) {
99
- __publicField(this, "data");
100
- __publicField(this, "expiresAt");
101
- this.data = data;
102
- this.expiresAt = expiresAt;
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
- expiresIn(milliseconds) {
111
- this.expiresAt = /* @__PURE__ */ new Date();
112
- this.expiresAt.setMilliseconds(this.expiresAt.getMilliseconds() + milliseconds);
113
- return this;
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 DefaultCache = class {
106
+ var q = class {
117
107
  constructor() {
118
- __publicField(this, "elements", /* @__PURE__ */ new Map());
119
- __publicField(this, "event", new DefaultSWREventManager());
108
+ h(this, "elements", /* @__PURE__ */ new Map());
109
+ h(this, "event", new I());
120
110
  }
121
- resolve(key, value) {
122
- Promise.resolve(value.data).then((detail) => {
123
- if (detail === void 0 || detail === null) {
124
- return this.remove(key);
125
- }
126
- value.data = detail;
127
- this.broadcast(key, detail);
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
- get(key) {
131
- return this.elements.get(key);
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
- set(key, value) {
134
- this.elements.set(key, value);
135
- this.resolve(key, value);
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
- remove(key, options) {
138
- const { broadcast } = __spreadValues2(__spreadValues2({}, defaultCacheRemoveOptions), options);
139
- if (broadcast)
140
- this.broadcast(key, void 0);
141
- this.elements.delete(key);
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
- clear(options) {
144
- const { broadcast } = __spreadValues2(__spreadValues2({}, defaultCacheClearOptions), options);
145
- if (broadcast)
146
- for (const key of this.elements.keys())
147
- this.broadcast(key, void 0);
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
- has(key) {
151
- return this.elements.has(key);
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
- subscribe(key, listener) {
154
- this.event.subscribe(key, listener);
163
+ /**
164
+ * Subscribes the callback to the given key.
165
+ */
166
+ subscribe(e, t) {
167
+ this.event.subscribe(e, t);
155
168
  }
156
- unsubscribe(key, listener) {
157
- this.event.unsubscribe(key, listener);
169
+ /**
170
+ * Unsubscribes to the given key events.
171
+ */
172
+ unsubscribe(e, t) {
173
+ this.event.unsubscribe(e, t);
158
174
  }
159
- broadcast(key, data) {
160
- this.event.emit(key, data);
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 defaultOptions = {
164
- cache: new DefaultCache(),
165
- errors: new DefaultSWREventManager(),
166
- fetcher: (url) => __async(void 0, null, function* () {
167
- const response = yield fetch(url);
168
- if (!response.ok)
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 response.json();
189
+ return e.json();
171
190
  }),
172
- initialData: void 0,
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: (notify, { enabled }) => {
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: (notify, { enabled, throttleInterval }) => {
188
- if (enabled && typeof window !== "undefined") {
189
- let lastFocus = null;
190
- const rawHandler = () => {
191
- const now = Date.now();
192
- if (lastFocus === null || now - lastFocus > throttleInterval) {
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", rawHandler);
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 defaultRevalidateOptions = __spreadProps(__spreadValues2({}, defaultOptions), {
214
+ var E = __spreadProps(__spreadValues({}, x), {
205
215
  force: false
206
216
  });
207
- var defaultMutateOptions = {
217
+ var T = {
208
218
  revalidate: true,
209
- revalidateOptions: __spreadValues2({}, defaultRevalidateOptions)
219
+ revalidateOptions: __spreadValues({}, E),
220
+ revalidateFunction: void 0
210
221
  };
211
- var defaultClearOptions = {
222
+ var X = {
212
223
  broadcast: false
213
224
  };
214
- var SWR = class {
215
- constructor(options) {
216
- __publicField(this, "options");
217
- this.options = __spreadValues2(__spreadValues2({}, defaultOptions), options);
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
- requestData(key, fetcher) {
226
- return Promise.resolve(fetcher(key)).catch((data) => {
227
- this.errors.emit(key, data);
228
- return void 0;
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
- resolveKey(key) {
232
- if (typeof key === "function") {
255
+ /**
256
+ * Resolves the given to a SWRKey or undefined.
257
+ */
258
+ resolveKey(e) {
259
+ if (typeof e == "function")
233
260
  try {
234
- return key();
235
- } catch (e) {
236
- return void 0;
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
- mutate(key, value, options) {
266
- if (!key)
267
- return;
268
- const { revalidate: revalidateAfterMutation, revalidateOptions } = __spreadValues2(__spreadValues2({}, defaultMutateOptions), options);
269
- let data;
270
- if (typeof value === "function") {
271
- let state = null;
272
- if (this.cache.has(key)) {
273
- const item = this.cache.get(key);
274
- if (!item.isResolving())
275
- state = item.data;
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
- data = value(state);
278
- } else {
279
- data = value;
280
- }
281
- this.cache.set(key, data instanceof CacheItem ? data : new CacheItem({ data }));
282
- if (revalidateAfterMutation)
283
- this.revalidate(key, revalidateOptions);
284
- }
285
- subscribeData(key, onData) {
286
- if (key) {
287
- const handler = (payload) => onData(payload);
288
- this.cache.subscribe(key, handler);
289
- return () => this.cache.unsubscribe(key, handler);
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
- subscribeErrors(key, onError) {
295
- if (key) {
296
- const handler = (payload) => onError(payload);
297
- this.errors.subscribe(key, handler);
298
- return () => this.errors.unsubscribe(key, handler);
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
- get(key) {
304
- if (key && this.cache.has(key)) {
305
- const item = this.cache.get(key);
306
- if (!item.isResolving())
307
- return item.data;
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
- getWait(key) {
312
- return new Promise((resolve, reject) => {
313
- const unsubscribe = this.subscribeData(key, (data) => {
314
- unsubscribe();
315
- return resolve(data);
316
- });
317
- const unsubscribeErrors = this.subscribeErrors(key, (error) => {
318
- unsubscribeErrors();
319
- return reject(error);
320
- });
321
- const current = this.get(key);
322
- if (current)
323
- return resolve(current);
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
- subscribe(key, onData, onError, options) {
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
- initialData,
330
- loadInitialCache,
331
- revalidateOnStart,
332
- dedupingInterval,
333
- revalidateOnFocus,
334
- focusThrottleInterval,
335
- revalidateOnReconnect,
336
- reconnectWhen,
337
- focusWhen
338
- } = __spreadValues2(__spreadValues2({}, this.options), options);
339
- const mutateCurrent = (value, options2) => {
340
- return this.mutate(this.resolveKey(key), value, options2);
341
- };
342
- const revalidateCurrent = (options2) => {
343
- return this.revalidate(this.resolveKey(key), options2);
344
- };
345
- const revalidateCurrentWithOptions = () => {
346
- return revalidateCurrent({ fetcher, dedupingInterval });
347
- };
348
- if (revalidateOnStart)
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
- const unsubscribe = () => {
360
- unsubscribeData();
361
- unsubscribeErrors();
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@1.10.0_svelte@4.0.0/node_modules/sswr/dist/sswr.mjs
378
- import { beforeUpdate as _, onDestroy as D } from "svelte";
379
- function h() {
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 E(t) {
424
+ function D(t) {
382
425
  return t();
383
426
  }
384
- function q(t) {
385
- t.forEach(E);
427
+ function q2(t) {
428
+ t.forEach(D);
386
429
  }
387
- function w(t) {
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 x(t, ...e) {
394
- if (t == null)
395
- return h;
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 z(t, e) {
446
+ function A(t, e) {
402
447
  return {
403
- subscribe: m(t, e).subscribe
448
+ subscribe: y(t, e).subscribe
404
449
  };
405
450
  }
406
- function m(t, e = h) {
451
+ function y(t, e = p) {
407
452
  let n;
408
453
  const r = /* @__PURE__ */ new Set();
409
- function c(i) {
410
- if (K(t, i) && (t = i, n)) {
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 l(i) {
422
- c(i(t));
466
+ function a(u) {
467
+ i(u(t));
423
468
  }
424
- function d(i, f = h) {
425
- const s = [i, f];
426
- return r.add(s), r.size === 1 && (n = e(c) || h), i(t), () => {
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: c, update: l, subscribe: d };
475
+ return { set: i, update: a, subscribe: d };
431
476
  }
432
- function S(t, e, n) {
433
- const r = !Array.isArray(t), c = r ? [t] : t, l = e.length < 2;
434
- return z(n, (d) => {
435
- let i = false;
436
- const f = [];
437
- let s = 0, p = h;
438
- const o = () => {
439
- if (s)
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
- p();
442
- const a = e(r ? f[0] : f, d);
443
- l ? d(a) : p = w(a) ? a : h;
444
- }, b = c.map((a, g) => x(a, (y) => {
445
- f[g] = y, s &= ~(1 << g), i && o();
446
- }, () => {
447
- s |= 1 << g;
448
- }));
449
- return i = true, o(), function() {
450
- q(b), p();
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 A = class extends SWR {
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 c = m(void 0, () => () => r == null ? void 0 : r()), l = m(void 0, () => () => r == null ? void 0 : r());
461
- _(() => {
462
- const o = (a) => {
463
- l.set(void 0), c.set(a);
464
- }, b = (a) => l.set(a);
465
- r || (r = this.subscribe(e, o, b, __spreadValues({
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
- }), D(() => r == null ? void 0 : r());
469
- const d = (o, b) => this.mutate(this.resolveKey(e), o, __spreadValues({
522
+ }), E2(() => r == null ? void 0 : r());
523
+ const d = (o, l) => this.mutate(this.resolveKey(e), o, __spreadValues({
470
524
  revalidateOptions: n
471
- }, b)), i = (o) => this.revalidate(this.resolveKey(e), __spreadValues(__spreadValues({}, n), o)), f = (o) => this.clear(this.resolveKey(e), o), s = S([c, l], ([o, b]) => o === void 0 && b === void 0), p = S([c, l], ([o, b]) => o !== void 0 && b === void 0);
472
- return { data: c, error: l, mutate: d, revalidate: i, clear: f, isLoading: s, isValid: p };
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 A(t);
476
- var u = W();
477
- var $ = (t, e) => u.useSWR(t, e);
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 } = $(key, {
651
+ const { data, mutate: originalMutate } = F2(key, {
598
652
  fetcher: () => store[key] || initialMessages,
599
- initialData: initialMessages
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 } = $(key, {
801
+ const { data, mutate: originalMutate } = F2(key, {
748
802
  fetcher: () => store2[key] || initialCompletion,
749
- initialData: initialCompletion
803
+ fallbackData: initialCompletion
750
804
  });
751
805
  data.set(initialCompletion);
752
806
  const mutate = (data2) => {