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,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 = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected);
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@3.0.0/node_modules/swrev/dist/swrev.es.js
66
- var __defProp2 = Object.defineProperty;
67
- var __defProps = Object.defineProperties;
68
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
69
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
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
- __publicField(this, "listeners", /* @__PURE__ */ new Map());
74
+ h(this, "listeners", /* @__PURE__ */ new Map());
92
75
  }
93
- subscribe(key, listener) {
94
- if (!this.listeners.has(key))
95
- this.listeners.set(key, []);
96
- if (this.listeners.get(key).includes(listener))
97
- return;
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
- unsubscribe(key, listener) {
101
- if (!this.listeners.has(key))
102
- return;
103
- if (!this.listeners.get(key).includes(listener))
104
- return;
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
- emit(key, payload) {
110
- if (!this.listeners.has(key))
111
- return;
112
- this.listeners.get(key).forEach((listener) => listener(payload));
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 defaultCacheRemoveOptions = {
95
+ var L = {
116
96
  broadcast: false
117
97
  };
118
- var defaultCacheClearOptions = {
98
+ var S = {
119
99
  broadcast: false
120
100
  };
121
- var CacheItem = class {
122
- constructor({ data, expiresAt = null }) {
123
- __publicField(this, "data");
124
- __publicField(this, "expiresAt");
125
- this.data = data;
126
- this.expiresAt = expiresAt;
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
- expiresIn(milliseconds) {
135
- this.expiresAt = /* @__PURE__ */ new Date();
136
- this.expiresAt.setMilliseconds(this.expiresAt.getMilliseconds() + milliseconds);
137
- return this;
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 DefaultCache = class {
130
+ var q = class {
141
131
  constructor() {
142
- __publicField(this, "elements", /* @__PURE__ */ new Map());
143
- __publicField(this, "event", new DefaultSWREventManager());
132
+ h(this, "elements", /* @__PURE__ */ new Map());
133
+ h(this, "event", new I());
144
134
  }
145
- resolve(key, value) {
146
- Promise.resolve(value.data).then((detail) => {
147
- if (detail === void 0 || detail === null) {
148
- return this.remove(key);
149
- }
150
- value.data = detail;
151
- this.broadcast(key, detail);
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
- get(key) {
155
- return this.elements.get(key);
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
- set(key, value) {
158
- this.elements.set(key, value);
159
- this.resolve(key, value);
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
- remove(key, options) {
162
- const { broadcast } = __spreadValues2(__spreadValues2({}, defaultCacheRemoveOptions), options);
163
- if (broadcast)
164
- this.broadcast(key, void 0);
165
- this.elements.delete(key);
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
- clear(options) {
168
- const { broadcast } = __spreadValues2(__spreadValues2({}, defaultCacheClearOptions), options);
169
- if (broadcast)
170
- for (const key of this.elements.keys())
171
- this.broadcast(key, void 0);
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
- has(key) {
175
- return this.elements.has(key);
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
- subscribe(key, listener) {
178
- this.event.subscribe(key, listener);
187
+ /**
188
+ * Subscribes the callback to the given key.
189
+ */
190
+ subscribe(e, t) {
191
+ this.event.subscribe(e, t);
179
192
  }
180
- unsubscribe(key, listener) {
181
- this.event.unsubscribe(key, listener);
193
+ /**
194
+ * Unsubscribes to the given key events.
195
+ */
196
+ unsubscribe(e, t) {
197
+ this.event.unsubscribe(e, t);
182
198
  }
183
- broadcast(key, data) {
184
- this.event.emit(key, data);
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 defaultOptions = {
188
- cache: new DefaultCache(),
189
- errors: new DefaultSWREventManager(),
190
- fetcher: (url) => __async(void 0, null, function* () {
191
- const response = yield fetch(url);
192
- if (!response.ok)
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 response.json();
213
+ return e.json();
195
214
  }),
196
- initialData: void 0,
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: (notify, { enabled }) => {
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: (notify, { enabled, throttleInterval }) => {
212
- if (enabled && typeof window !== "undefined") {
213
- let lastFocus = null;
214
- const rawHandler = () => {
215
- const now = Date.now();
216
- if (lastFocus === null || now - lastFocus > throttleInterval) {
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", rawHandler);
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 defaultRevalidateOptions = __spreadProps(__spreadValues2({}, defaultOptions), {
238
+ var E = __spreadProps(__spreadValues({}, x), {
229
239
  force: false
230
240
  });
231
- var defaultMutateOptions = {
241
+ var T = {
232
242
  revalidate: true,
233
- revalidateOptions: __spreadValues2({}, defaultRevalidateOptions)
243
+ revalidateOptions: __spreadValues({}, E),
244
+ revalidateFunction: void 0
234
245
  };
235
- var defaultClearOptions = {
246
+ var X = {
236
247
  broadcast: false
237
248
  };
238
- var SWR = class {
239
- constructor(options) {
240
- __publicField(this, "options");
241
- this.options = __spreadValues2(__spreadValues2({}, defaultOptions), options);
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
- requestData(key, fetcher) {
250
- return Promise.resolve(fetcher(key)).catch((data) => {
251
- this.errors.emit(key, data);
252
- return void 0;
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
- resolveKey(key) {
256
- if (typeof key === "function") {
279
+ /**
280
+ * Resolves the given to a SWRKey or undefined.
281
+ */
282
+ resolveKey(e) {
283
+ if (typeof e == "function")
257
284
  try {
258
- return key();
259
- } catch (e) {
260
- return void 0;
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
- mutate(key, value, options) {
290
- if (!key)
291
- return;
292
- const { revalidate: revalidateAfterMutation, revalidateOptions } = __spreadValues2(__spreadValues2({}, defaultMutateOptions), options);
293
- let data;
294
- if (typeof value === "function") {
295
- let state = null;
296
- if (this.cache.has(key)) {
297
- const item = this.cache.get(key);
298
- if (!item.isResolving())
299
- state = item.data;
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
- data = value(state);
302
- } else {
303
- data = value;
304
- }
305
- this.cache.set(key, data instanceof CacheItem ? data : new CacheItem({ data }));
306
- if (revalidateAfterMutation)
307
- this.revalidate(key, revalidateOptions);
308
- }
309
- subscribeData(key, onData) {
310
- if (key) {
311
- const handler = (payload) => onData(payload);
312
- this.cache.subscribe(key, handler);
313
- return () => this.cache.unsubscribe(key, handler);
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
- subscribeErrors(key, onError) {
319
- if (key) {
320
- const handler = (payload) => onError(payload);
321
- this.errors.subscribe(key, handler);
322
- return () => this.errors.unsubscribe(key, handler);
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
- get(key) {
328
- if (key && this.cache.has(key)) {
329
- const item = this.cache.get(key);
330
- if (!item.isResolving())
331
- return item.data;
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
- getWait(key) {
336
- return new Promise((resolve, reject) => {
337
- const unsubscribe = this.subscribeData(key, (data) => {
338
- unsubscribe();
339
- return resolve(data);
340
- });
341
- const unsubscribeErrors = this.subscribeErrors(key, (error) => {
342
- unsubscribeErrors();
343
- return reject(error);
344
- });
345
- const current = this.get(key);
346
- if (current)
347
- return resolve(current);
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
- subscribe(key, onData, onError, options) {
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
- initialData,
354
- loadInitialCache,
355
- revalidateOnStart,
356
- dedupingInterval,
357
- revalidateOnFocus,
358
- focusThrottleInterval,
359
- revalidateOnReconnect,
360
- reconnectWhen,
361
- focusWhen
362
- } = __spreadValues2(__spreadValues2({}, this.options), options);
363
- const mutateCurrent = (value, options2) => {
364
- return this.mutate(this.resolveKey(key), value, options2);
365
- };
366
- const revalidateCurrent = (options2) => {
367
- return this.revalidate(this.resolveKey(key), options2);
368
- };
369
- const revalidateCurrentWithOptions = () => {
370
- return revalidateCurrent({ fetcher, dedupingInterval });
371
- };
372
- if (revalidateOnStart)
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
- const unsubscribe = () => {
384
- unsubscribeData();
385
- unsubscribeErrors();
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@1.10.0_svelte@4.0.0/node_modules/sswr/dist/sswr.mjs
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 h() {
446
+ function p() {
404
447
  }
405
- function E(t) {
448
+ function D(t) {
406
449
  return t();
407
450
  }
408
- function q(t) {
409
- t.forEach(E);
451
+ function q2(t) {
452
+ t.forEach(D);
410
453
  }
411
- function w(t) {
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 x(t, ...e) {
418
- if (t == null)
419
- return h;
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 z(t, e) {
470
+ function A(t, e) {
426
471
  return {
427
- subscribe: m(t, e).subscribe
472
+ subscribe: y(t, e).subscribe
428
473
  };
429
474
  }
430
- function m(t, e = h) {
475
+ function y(t, e = p) {
431
476
  let n;
432
477
  const r = /* @__PURE__ */ new Set();
433
- function c(i) {
434
- if (K(t, i) && (t = i, n)) {
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 l(i) {
446
- c(i(t));
490
+ function a(u) {
491
+ i(u(t));
447
492
  }
448
- function d(i, f = h) {
449
- const s = [i, f];
450
- return r.add(s), r.size === 1 && (n = e(c) || h), i(t), () => {
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: c, update: l, subscribe: d };
499
+ return { set: i, update: a, subscribe: d };
455
500
  }
456
- function S(t, e, n) {
457
- const r = !Array.isArray(t), c = r ? [t] : t, l = e.length < 2;
458
- return z(n, (d) => {
459
- let i = false;
460
- const f = [];
461
- let s = 0, p = h;
462
- const o = () => {
463
- if (s)
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
- p();
466
- const a = e(r ? f[0] : f, d);
467
- l ? d(a) : p = w(a) ? a : h;
468
- }, b = c.map((a, g) => x(a, (y) => {
469
- f[g] = y, s &= ~(1 << g), i && o();
470
- }, () => {
471
- s |= 1 << g;
472
- }));
473
- return i = true, o(), function() {
474
- q(b), p();
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 A = class extends SWR {
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 c = m(void 0, () => () => r == null ? void 0 : r()), l = m(void 0, () => () => r == null ? void 0 : r());
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 = (a) => {
487
- l.set(void 0), c.set(a);
488
- }, b = (a) => l.set(a);
489
- r || (r = this.subscribe(e, o, b, __spreadValues({
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, b) => this.mutate(this.resolveKey(e), o, __spreadValues({
547
+ const d = (o, l) => this.mutate(this.resolveKey(e), o, __spreadValues({
494
548
  revalidateOptions: n
495
- }, 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);
496
- return { data: c, error: l, mutate: d, revalidate: i, clear: f, isLoading: s, isValid: p };
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 A(t);
500
- var u = W();
501
- var $ = (t, e) => u.useSWR(t, e);
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 } = $(key, {
675
+ const { data, mutate: originalMutate } = F2(key, {
622
676
  fetcher: () => store[key] || initialMessages,
623
- initialData: initialMessages
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 } = $(key, {
825
+ const { data, mutate: originalMutate } = F2(key, {
772
826
  fetcher: () => store2[key] || initialCompletion,
773
- initialData: initialCompletion
827
+ fallbackData: initialCompletion
774
828
  });
775
829
  data.set(initialCompletion);
776
830
  const mutate = (data2) => {