ai 2.1.0 → 2.1.2
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/dist/index.d.ts +48 -8
- package/dist/index.mjs +234 -26
- package/package.json +4 -4
- package/react/dist/index.d.ts +206 -3
- package/react/dist/index.mjs +384 -7
- package/svelte/dist/index.d.ts +194 -4
- package/svelte/dist/index.mjs +779 -7
- package/vue/dist/index.d.ts +194 -4
- package/vue/dist/index.mjs +345 -7
- package/dist/ai-stream.d.ts +0 -18
- package/dist/ai-stream.js +0 -132
- package/dist/ai-stream.mjs +0 -15
- package/dist/anthropic-stream.d.ts +0 -5
- package/dist/anthropic-stream.js +0 -133
- package/dist/anthropic-stream.mjs +0 -10
- package/dist/chunk-2JQWCLY2.mjs +0 -70
- package/dist/chunk-7KLTYB74.mjs +0 -70
- package/dist/chunk-BJMBMGA3.mjs +0 -34
- package/dist/chunk-KKQRUR3E.mjs +0 -51
- package/dist/chunk-RBP6ONSV.mjs +0 -45
- package/dist/chunk-TWW2ODJW.mjs +0 -32
- package/dist/chunk-U2OQ6HW6.mjs +0 -41
- package/dist/chunk-UJV6VDVU.mjs +0 -97
- package/dist/huggingface-stream.d.ts +0 -5
- package/dist/huggingface-stream.js +0 -121
- package/dist/huggingface-stream.mjs +0 -10
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.js +0 -568
- package/dist/index.test.mjs +0 -286
- package/dist/langchain-stream.d.ts +0 -12
- package/dist/langchain-stream.js +0 -102
- package/dist/langchain-stream.mjs +0 -10
- package/dist/openai-stream.d.ts +0 -5
- package/dist/openai-stream.js +0 -144
- package/dist/openai-stream.mjs +0 -10
- package/dist/streaming-text-response.d.ts +0 -17
- package/dist/streaming-text-response.js +0 -75
- package/dist/streaming-text-response.mjs +0 -11
- package/react/dist/chunk-5PP6W52J.mjs +0 -202
- package/react/dist/chunk-6EH3SWMP.mjs +0 -55
- package/react/dist/chunk-PW6HSU2N.mjs +0 -154
- package/react/dist/types-f862f74a.d.ts +0 -123
- package/react/dist/use-chat.d.ts +0 -42
- package/react/dist/use-chat.js +0 -276
- package/react/dist/use-chat.mjs +0 -8
- package/react/dist/use-completion.d.ts +0 -47
- package/react/dist/use-completion.js +0 -229
- package/react/dist/use-completion.mjs +0 -8
- package/svelte/dist/chunk-6USBQIV6.mjs +0 -177
- package/svelte/dist/chunk-BQ64GHZ3.mjs +0 -136
- package/svelte/dist/chunk-CENOSGDG.mjs +0 -493
- package/svelte/dist/types-f862f74a.d.ts +0 -123
- package/svelte/dist/use-chat.d.ts +0 -39
- package/svelte/dist/use-chat.js +0 -680
- package/svelte/dist/use-chat.mjs +0 -7
- package/svelte/dist/use-completion.d.ts +0 -38
- package/svelte/dist/use-completion.js +0 -640
- package/svelte/dist/use-completion.mjs +0 -7
- package/vue/dist/chunk-FT26CHLO.mjs +0 -137
- package/vue/dist/chunk-OYI6GFBM.mjs +0 -178
- package/vue/dist/chunk-WXH4YPZV.mjs +0 -54
- package/vue/dist/types-f862f74a.d.ts +0 -123
- package/vue/dist/use-chat.d.ts +0 -39
- package/vue/dist/use-chat.js +0 -252
- package/vue/dist/use-chat.mjs +0 -7
- package/vue/dist/use-completion.d.ts +0 -38
- package/vue/dist/use-completion.js +0 -212
- package/vue/dist/use-completion.mjs +0 -7
@@ -1,493 +0,0 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
6
|
-
var __spreadValues = (a, b) => {
|
7
|
-
for (var prop in b || (b = {}))
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
10
|
-
if (__getOwnPropSymbols)
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
12
|
-
if (__propIsEnum.call(b, prop))
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
14
|
-
}
|
15
|
-
return a;
|
16
|
-
};
|
17
|
-
var __async = (__this, __arguments, generator) => {
|
18
|
-
return new Promise((resolve, reject) => {
|
19
|
-
var fulfilled = (value) => {
|
20
|
-
try {
|
21
|
-
step(generator.next(value));
|
22
|
-
} catch (e) {
|
23
|
-
reject(e);
|
24
|
-
}
|
25
|
-
};
|
26
|
-
var rejected = (value) => {
|
27
|
-
try {
|
28
|
-
step(generator.throw(value));
|
29
|
-
} catch (e) {
|
30
|
-
reject(e);
|
31
|
-
}
|
32
|
-
};
|
33
|
-
var step = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected);
|
34
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
35
|
-
});
|
36
|
-
};
|
37
|
-
|
38
|
-
// ../../node_modules/.pnpm/swrev@3.0.0/node_modules/swrev/dist/swrev.es.js
|
39
|
-
var __defProp2 = Object.defineProperty;
|
40
|
-
var __defProps = Object.defineProperties;
|
41
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
42
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
43
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
44
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
45
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
46
|
-
var __spreadValues2 = (a, b) => {
|
47
|
-
for (var prop in b || (b = {}))
|
48
|
-
if (__hasOwnProp2.call(b, prop))
|
49
|
-
__defNormalProp2(a, prop, b[prop]);
|
50
|
-
if (__getOwnPropSymbols2)
|
51
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
52
|
-
if (__propIsEnum2.call(b, prop))
|
53
|
-
__defNormalProp2(a, prop, b[prop]);
|
54
|
-
}
|
55
|
-
return a;
|
56
|
-
};
|
57
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
58
|
-
var __publicField = (obj, key, value) => {
|
59
|
-
__defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
60
|
-
return value;
|
61
|
-
};
|
62
|
-
var DefaultSWREventManager = class {
|
63
|
-
constructor() {
|
64
|
-
__publicField(this, "listeners", /* @__PURE__ */ new Map());
|
65
|
-
}
|
66
|
-
subscribe(key, listener) {
|
67
|
-
if (!this.listeners.has(key))
|
68
|
-
this.listeners.set(key, []);
|
69
|
-
if (this.listeners.get(key).includes(listener))
|
70
|
-
return;
|
71
|
-
this.listeners.get(key).push(listener);
|
72
|
-
}
|
73
|
-
unsubscribe(key, listener) {
|
74
|
-
if (!this.listeners.has(key))
|
75
|
-
return;
|
76
|
-
if (!this.listeners.get(key).includes(listener))
|
77
|
-
return;
|
78
|
-
this.listeners.get(key).splice(this.listeners.get(key).indexOf(listener), 1);
|
79
|
-
if (this.listeners.get(key).length === 0)
|
80
|
-
this.listeners.delete(key);
|
81
|
-
}
|
82
|
-
emit(key, payload) {
|
83
|
-
if (!this.listeners.has(key))
|
84
|
-
return;
|
85
|
-
this.listeners.get(key).forEach((listener) => listener(payload));
|
86
|
-
}
|
87
|
-
};
|
88
|
-
var defaultCacheRemoveOptions = {
|
89
|
-
broadcast: false
|
90
|
-
};
|
91
|
-
var defaultCacheClearOptions = {
|
92
|
-
broadcast: false
|
93
|
-
};
|
94
|
-
var CacheItem = class {
|
95
|
-
constructor({ data, expiresAt = null }) {
|
96
|
-
__publicField(this, "data");
|
97
|
-
__publicField(this, "expiresAt");
|
98
|
-
this.data = data;
|
99
|
-
this.expiresAt = expiresAt;
|
100
|
-
}
|
101
|
-
isResolving() {
|
102
|
-
return this.data instanceof Promise;
|
103
|
-
}
|
104
|
-
hasExpired() {
|
105
|
-
return this.expiresAt === null || this.expiresAt < /* @__PURE__ */ new Date();
|
106
|
-
}
|
107
|
-
expiresIn(milliseconds) {
|
108
|
-
this.expiresAt = /* @__PURE__ */ new Date();
|
109
|
-
this.expiresAt.setMilliseconds(this.expiresAt.getMilliseconds() + milliseconds);
|
110
|
-
return this;
|
111
|
-
}
|
112
|
-
};
|
113
|
-
var DefaultCache = class {
|
114
|
-
constructor() {
|
115
|
-
__publicField(this, "elements", /* @__PURE__ */ new Map());
|
116
|
-
__publicField(this, "event", new DefaultSWREventManager());
|
117
|
-
}
|
118
|
-
resolve(key, value) {
|
119
|
-
Promise.resolve(value.data).then((detail) => {
|
120
|
-
if (detail === void 0 || detail === null) {
|
121
|
-
return this.remove(key);
|
122
|
-
}
|
123
|
-
value.data = detail;
|
124
|
-
this.broadcast(key, detail);
|
125
|
-
});
|
126
|
-
}
|
127
|
-
get(key) {
|
128
|
-
return this.elements.get(key);
|
129
|
-
}
|
130
|
-
set(key, value) {
|
131
|
-
this.elements.set(key, value);
|
132
|
-
this.resolve(key, value);
|
133
|
-
}
|
134
|
-
remove(key, options) {
|
135
|
-
const { broadcast } = __spreadValues2(__spreadValues2({}, defaultCacheRemoveOptions), options);
|
136
|
-
if (broadcast)
|
137
|
-
this.broadcast(key, void 0);
|
138
|
-
this.elements.delete(key);
|
139
|
-
}
|
140
|
-
clear(options) {
|
141
|
-
const { broadcast } = __spreadValues2(__spreadValues2({}, defaultCacheClearOptions), options);
|
142
|
-
if (broadcast)
|
143
|
-
for (const key of this.elements.keys())
|
144
|
-
this.broadcast(key, void 0);
|
145
|
-
this.elements.clear();
|
146
|
-
}
|
147
|
-
has(key) {
|
148
|
-
return this.elements.has(key);
|
149
|
-
}
|
150
|
-
subscribe(key, listener) {
|
151
|
-
this.event.subscribe(key, listener);
|
152
|
-
}
|
153
|
-
unsubscribe(key, listener) {
|
154
|
-
this.event.unsubscribe(key, listener);
|
155
|
-
}
|
156
|
-
broadcast(key, data) {
|
157
|
-
this.event.emit(key, data);
|
158
|
-
}
|
159
|
-
};
|
160
|
-
var defaultOptions = {
|
161
|
-
cache: new DefaultCache(),
|
162
|
-
errors: new DefaultSWREventManager(),
|
163
|
-
fetcher: (url) => __async(void 0, null, function* () {
|
164
|
-
const response = yield fetch(url);
|
165
|
-
if (!response.ok)
|
166
|
-
throw Error("Not a 2XX response.");
|
167
|
-
return response.json();
|
168
|
-
}),
|
169
|
-
initialData: void 0,
|
170
|
-
loadInitialCache: true,
|
171
|
-
revalidateOnStart: true,
|
172
|
-
dedupingInterval: 2e3,
|
173
|
-
revalidateOnFocus: true,
|
174
|
-
focusThrottleInterval: 5e3,
|
175
|
-
revalidateOnReconnect: true,
|
176
|
-
reconnectWhen: (notify, { enabled }) => {
|
177
|
-
if (enabled && typeof window !== "undefined") {
|
178
|
-
window.addEventListener("online", notify);
|
179
|
-
return () => window.removeEventListener("online", notify);
|
180
|
-
}
|
181
|
-
return () => {
|
182
|
-
};
|
183
|
-
},
|
184
|
-
focusWhen: (notify, { enabled, throttleInterval }) => {
|
185
|
-
if (enabled && typeof window !== "undefined") {
|
186
|
-
let lastFocus = null;
|
187
|
-
const rawHandler = () => {
|
188
|
-
const now = Date.now();
|
189
|
-
if (lastFocus === null || now - lastFocus > throttleInterval) {
|
190
|
-
lastFocus = now;
|
191
|
-
notify();
|
192
|
-
}
|
193
|
-
};
|
194
|
-
window.addEventListener("focus", rawHandler);
|
195
|
-
return () => window.removeEventListener("focus", rawHandler);
|
196
|
-
}
|
197
|
-
return () => {
|
198
|
-
};
|
199
|
-
}
|
200
|
-
};
|
201
|
-
var defaultRevalidateOptions = __spreadProps(__spreadValues2({}, defaultOptions), {
|
202
|
-
force: false
|
203
|
-
});
|
204
|
-
var defaultMutateOptions = {
|
205
|
-
revalidate: true,
|
206
|
-
revalidateOptions: __spreadValues2({}, defaultRevalidateOptions)
|
207
|
-
};
|
208
|
-
var defaultClearOptions = {
|
209
|
-
broadcast: false
|
210
|
-
};
|
211
|
-
var SWR = class {
|
212
|
-
constructor(options) {
|
213
|
-
__publicField(this, "options");
|
214
|
-
this.options = __spreadValues2(__spreadValues2({}, defaultOptions), options);
|
215
|
-
}
|
216
|
-
get cache() {
|
217
|
-
return this.options.cache;
|
218
|
-
}
|
219
|
-
get errors() {
|
220
|
-
return this.options.errors;
|
221
|
-
}
|
222
|
-
requestData(key, fetcher) {
|
223
|
-
return Promise.resolve(fetcher(key)).catch((data) => {
|
224
|
-
this.errors.emit(key, data);
|
225
|
-
return void 0;
|
226
|
-
});
|
227
|
-
}
|
228
|
-
resolveKey(key) {
|
229
|
-
if (typeof key === "function") {
|
230
|
-
try {
|
231
|
-
return key();
|
232
|
-
} catch (e) {
|
233
|
-
return void 0;
|
234
|
-
}
|
235
|
-
}
|
236
|
-
return key;
|
237
|
-
}
|
238
|
-
clear(keys, options) {
|
239
|
-
const ops = __spreadValues2(__spreadValues2({}, defaultClearOptions), options);
|
240
|
-
if (keys === void 0 || keys === null)
|
241
|
-
return this.cache.clear(ops);
|
242
|
-
if (!Array.isArray(keys))
|
243
|
-
return this.cache.remove(keys, ops);
|
244
|
-
for (const key of keys)
|
245
|
-
this.cache.remove(key, ops);
|
246
|
-
}
|
247
|
-
revalidate(key, options) {
|
248
|
-
if (!key)
|
249
|
-
return;
|
250
|
-
const { fetcher: defaultFetcher, dedupingInterval: defaultDedupingInterval } = this.options;
|
251
|
-
const { force, fetcher, dedupingInterval } = __spreadValues2(__spreadValues2(__spreadValues2({}, defaultRevalidateOptions), { fetcher: defaultFetcher, dedupingInterval: defaultDedupingInterval }), options);
|
252
|
-
let data = void 0;
|
253
|
-
if (force || !this.cache.has(key) || this.cache.has(key) && this.cache.get(key).hasExpired()) {
|
254
|
-
data = this.requestData(key, fetcher);
|
255
|
-
}
|
256
|
-
if (data !== void 0) {
|
257
|
-
this.mutate(key, new CacheItem({ data }).expiresIn(dedupingInterval), {
|
258
|
-
revalidate: false
|
259
|
-
});
|
260
|
-
}
|
261
|
-
}
|
262
|
-
mutate(key, value, options) {
|
263
|
-
if (!key)
|
264
|
-
return;
|
265
|
-
const { revalidate: revalidateAfterMutation, revalidateOptions } = __spreadValues2(__spreadValues2({}, defaultMutateOptions), options);
|
266
|
-
let data;
|
267
|
-
if (typeof value === "function") {
|
268
|
-
let state = null;
|
269
|
-
if (this.cache.has(key)) {
|
270
|
-
const item = this.cache.get(key);
|
271
|
-
if (!item.isResolving())
|
272
|
-
state = item.data;
|
273
|
-
}
|
274
|
-
data = value(state);
|
275
|
-
} else {
|
276
|
-
data = value;
|
277
|
-
}
|
278
|
-
this.cache.set(key, data instanceof CacheItem ? data : new CacheItem({ data }));
|
279
|
-
if (revalidateAfterMutation)
|
280
|
-
this.revalidate(key, revalidateOptions);
|
281
|
-
}
|
282
|
-
subscribeData(key, onData) {
|
283
|
-
if (key) {
|
284
|
-
const handler = (payload) => onData(payload);
|
285
|
-
this.cache.subscribe(key, handler);
|
286
|
-
return () => this.cache.unsubscribe(key, handler);
|
287
|
-
}
|
288
|
-
return () => {
|
289
|
-
};
|
290
|
-
}
|
291
|
-
subscribeErrors(key, onError) {
|
292
|
-
if (key) {
|
293
|
-
const handler = (payload) => onError(payload);
|
294
|
-
this.errors.subscribe(key, handler);
|
295
|
-
return () => this.errors.unsubscribe(key, handler);
|
296
|
-
}
|
297
|
-
return () => {
|
298
|
-
};
|
299
|
-
}
|
300
|
-
get(key) {
|
301
|
-
if (key && this.cache.has(key)) {
|
302
|
-
const item = this.cache.get(key);
|
303
|
-
if (!item.isResolving())
|
304
|
-
return item.data;
|
305
|
-
}
|
306
|
-
return void 0;
|
307
|
-
}
|
308
|
-
getWait(key) {
|
309
|
-
return new Promise((resolve, reject) => {
|
310
|
-
const unsubscribe = this.subscribeData(key, (data) => {
|
311
|
-
unsubscribe();
|
312
|
-
return resolve(data);
|
313
|
-
});
|
314
|
-
const unsubscribeErrors = this.subscribeErrors(key, (error) => {
|
315
|
-
unsubscribeErrors();
|
316
|
-
return reject(error);
|
317
|
-
});
|
318
|
-
const current = this.get(key);
|
319
|
-
if (current)
|
320
|
-
return resolve(current);
|
321
|
-
});
|
322
|
-
}
|
323
|
-
subscribe(key, onData, onError, options) {
|
324
|
-
const {
|
325
|
-
fetcher,
|
326
|
-
initialData,
|
327
|
-
loadInitialCache,
|
328
|
-
revalidateOnStart,
|
329
|
-
dedupingInterval,
|
330
|
-
revalidateOnFocus,
|
331
|
-
focusThrottleInterval,
|
332
|
-
revalidateOnReconnect,
|
333
|
-
reconnectWhen,
|
334
|
-
focusWhen
|
335
|
-
} = __spreadValues2(__spreadValues2({}, this.options), options);
|
336
|
-
const mutateCurrent = (value, options2) => {
|
337
|
-
return this.mutate(this.resolveKey(key), value, options2);
|
338
|
-
};
|
339
|
-
const revalidateCurrent = (options2) => {
|
340
|
-
return this.revalidate(this.resolveKey(key), options2);
|
341
|
-
};
|
342
|
-
const revalidateCurrentWithOptions = () => {
|
343
|
-
return revalidateCurrent({ fetcher, dedupingInterval });
|
344
|
-
};
|
345
|
-
if (revalidateOnStart)
|
346
|
-
revalidateCurrentWithOptions();
|
347
|
-
const unsubscribeData = this.subscribeData(this.resolveKey(key), onData);
|
348
|
-
const unsubscribeErrors = this.subscribeErrors(this.resolveKey(key), onError);
|
349
|
-
const unsubscribeVisibility = focusWhen(revalidateCurrentWithOptions, {
|
350
|
-
throttleInterval: focusThrottleInterval,
|
351
|
-
enabled: revalidateOnFocus
|
352
|
-
});
|
353
|
-
const unsubscribeNetwork = reconnectWhen(revalidateCurrentWithOptions, {
|
354
|
-
enabled: revalidateOnReconnect
|
355
|
-
});
|
356
|
-
const unsubscribe = () => {
|
357
|
-
unsubscribeData();
|
358
|
-
unsubscribeErrors();
|
359
|
-
unsubscribeVisibility == null ? void 0 : unsubscribeVisibility();
|
360
|
-
unsubscribeNetwork == null ? void 0 : unsubscribeNetwork();
|
361
|
-
};
|
362
|
-
if (initialData) {
|
363
|
-
mutateCurrent(initialData, { revalidate: false });
|
364
|
-
}
|
365
|
-
if (loadInitialCache) {
|
366
|
-
const cachedData = this.get(this.resolveKey(key));
|
367
|
-
if (cachedData)
|
368
|
-
onData(cachedData);
|
369
|
-
}
|
370
|
-
return { unsubscribe };
|
371
|
-
}
|
372
|
-
};
|
373
|
-
|
374
|
-
// ../../node_modules/.pnpm/sswr@1.10.0_svelte@3.59.1/node_modules/sswr/dist/sswr.mjs
|
375
|
-
import { beforeUpdate as _, onDestroy as D } from "svelte";
|
376
|
-
function h() {
|
377
|
-
}
|
378
|
-
function E(t) {
|
379
|
-
return t();
|
380
|
-
}
|
381
|
-
function q(t) {
|
382
|
-
t.forEach(E);
|
383
|
-
}
|
384
|
-
function w(t) {
|
385
|
-
return typeof t == "function";
|
386
|
-
}
|
387
|
-
function K(t, e) {
|
388
|
-
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
389
|
-
}
|
390
|
-
function x(t, ...e) {
|
391
|
-
if (t == null)
|
392
|
-
return h;
|
393
|
-
const n = t.subscribe(...e);
|
394
|
-
return n.unsubscribe ? () => n.unsubscribe() : n;
|
395
|
-
}
|
396
|
-
Promise.resolve();
|
397
|
-
var v = [];
|
398
|
-
function z(t, e) {
|
399
|
-
return {
|
400
|
-
subscribe: m(t, e).subscribe
|
401
|
-
};
|
402
|
-
}
|
403
|
-
function m(t, e = h) {
|
404
|
-
let n;
|
405
|
-
const r = /* @__PURE__ */ new Set();
|
406
|
-
function c(i) {
|
407
|
-
if (K(t, i) && (t = i, n)) {
|
408
|
-
const f = !v.length;
|
409
|
-
for (const s of r)
|
410
|
-
s[1](), v.push(s, t);
|
411
|
-
if (f) {
|
412
|
-
for (let s = 0; s < v.length; s += 2)
|
413
|
-
v[s][0](v[s + 1]);
|
414
|
-
v.length = 0;
|
415
|
-
}
|
416
|
-
}
|
417
|
-
}
|
418
|
-
function l(i) {
|
419
|
-
c(i(t));
|
420
|
-
}
|
421
|
-
function d(i, f = h) {
|
422
|
-
const s = [i, f];
|
423
|
-
return r.add(s), r.size === 1 && (n = e(c) || h), i(t), () => {
|
424
|
-
r.delete(s), r.size === 0 && (n(), n = null);
|
425
|
-
};
|
426
|
-
}
|
427
|
-
return { set: c, update: l, subscribe: d };
|
428
|
-
}
|
429
|
-
function S(t, e, n) {
|
430
|
-
const r = !Array.isArray(t), c = r ? [t] : t, l = e.length < 2;
|
431
|
-
return z(n, (d) => {
|
432
|
-
let i = false;
|
433
|
-
const f = [];
|
434
|
-
let s = 0, p = h;
|
435
|
-
const o = () => {
|
436
|
-
if (s)
|
437
|
-
return;
|
438
|
-
p();
|
439
|
-
const a = e(r ? f[0] : f, d);
|
440
|
-
l ? d(a) : p = w(a) ? a : h;
|
441
|
-
}, b = c.map((a, g) => x(a, (y) => {
|
442
|
-
f[g] = y, s &= ~(1 << g), i && o();
|
443
|
-
}, () => {
|
444
|
-
s |= 1 << g;
|
445
|
-
}));
|
446
|
-
return i = true, o(), function() {
|
447
|
-
q(b), p();
|
448
|
-
};
|
449
|
-
});
|
450
|
-
}
|
451
|
-
var A = class extends SWR {
|
452
|
-
/**
|
453
|
-
* Svelte specific use of SWR.
|
454
|
-
*/
|
455
|
-
useSWR(e, n) {
|
456
|
-
let r;
|
457
|
-
const c = m(void 0, () => () => r == null ? void 0 : r()), l = m(void 0, () => () => r == null ? void 0 : r());
|
458
|
-
_(() => {
|
459
|
-
const o = (a) => {
|
460
|
-
l.set(void 0), c.set(a);
|
461
|
-
}, b = (a) => l.set(a);
|
462
|
-
r || (r = this.subscribe(e, o, b, __spreadValues({
|
463
|
-
loadInitialCache: true
|
464
|
-
}, n)).unsubscribe);
|
465
|
-
}), D(() => r == null ? void 0 : r());
|
466
|
-
const d = (o, b) => this.mutate(this.resolveKey(e), o, __spreadValues({
|
467
|
-
revalidateOptions: n
|
468
|
-
}, 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);
|
469
|
-
return { data: c, error: l, mutate: d, revalidate: i, clear: f, isLoading: s, isValid: p };
|
470
|
-
}
|
471
|
-
};
|
472
|
-
var W = (t) => new A(t);
|
473
|
-
var u = W();
|
474
|
-
var $ = (t, e) => u.useSWR(t, e);
|
475
|
-
|
476
|
-
// shared/utils.ts
|
477
|
-
import { customAlphabet } from "nanoid";
|
478
|
-
var nanoid = customAlphabet(
|
479
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
480
|
-
7
|
481
|
-
);
|
482
|
-
var decoder = new TextDecoder();
|
483
|
-
function decodeAIStreamChunk(chunk) {
|
484
|
-
return decoder.decode(chunk);
|
485
|
-
}
|
486
|
-
|
487
|
-
export {
|
488
|
-
__spreadValues,
|
489
|
-
__async,
|
490
|
-
$,
|
491
|
-
nanoid,
|
492
|
-
decodeAIStreamChunk
|
493
|
-
};
|
@@ -1,123 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Shared types between the API and UI packages.
|
3
|
-
*/
|
4
|
-
type Message = {
|
5
|
-
id: string;
|
6
|
-
createdAt?: Date;
|
7
|
-
content: string;
|
8
|
-
role: 'system' | 'user' | 'assistant';
|
9
|
-
};
|
10
|
-
type CreateMessage = {
|
11
|
-
id?: string;
|
12
|
-
createdAt?: Date;
|
13
|
-
content: string;
|
14
|
-
role: 'system' | 'user' | 'assistant';
|
15
|
-
};
|
16
|
-
type UseChatOptions = {
|
17
|
-
/**
|
18
|
-
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
19
|
-
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
20
|
-
*/
|
21
|
-
api?: string;
|
22
|
-
/**
|
23
|
-
* An unique identifier for the chat. If not provided, a random one will be
|
24
|
-
* generated. When provided, the `useChat` hook with the same `id` will
|
25
|
-
* have shared states across components.
|
26
|
-
*/
|
27
|
-
id?: string;
|
28
|
-
/**
|
29
|
-
* Initial messages of the chat. Useful to load an existing chat history.
|
30
|
-
*/
|
31
|
-
initialMessages?: Message[];
|
32
|
-
/**
|
33
|
-
* Initial input of the chat.
|
34
|
-
*/
|
35
|
-
initialInput?: string;
|
36
|
-
/**
|
37
|
-
* Callback function to be called when the API response is received.
|
38
|
-
*/
|
39
|
-
onResponse?: (response: Response) => void;
|
40
|
-
/**
|
41
|
-
* Callback function to be called when the chat is finished streaming.
|
42
|
-
*/
|
43
|
-
onFinish?: (message: Message) => void;
|
44
|
-
/**
|
45
|
-
* Callback function to be called when an error is encountered.
|
46
|
-
*/
|
47
|
-
onError?: (error: Error) => void;
|
48
|
-
/**
|
49
|
-
* HTTP headers to be sent with the API request.
|
50
|
-
*/
|
51
|
-
headers?: Record<string, string> | Headers;
|
52
|
-
/**
|
53
|
-
* Extra body object to be sent with the API request.
|
54
|
-
* @example
|
55
|
-
* Send a `sessionId` to the API along with the messages.
|
56
|
-
* ```js
|
57
|
-
* useChat({
|
58
|
-
* body: {
|
59
|
-
* sessionId: '123',
|
60
|
-
* }
|
61
|
-
* })
|
62
|
-
* ```
|
63
|
-
*/
|
64
|
-
body?: object;
|
65
|
-
/**
|
66
|
-
* Whether to send extra message fields such as `message.id` and `message.createdAt` to the API.
|
67
|
-
* Defaults to `false`. When set to `true`, the API endpoint might need to
|
68
|
-
* handle the extra fields before forwarding the request to the AI service.
|
69
|
-
*/
|
70
|
-
sendExtraMessageFields?: boolean;
|
71
|
-
};
|
72
|
-
type UseCompletionOptions = {
|
73
|
-
/**
|
74
|
-
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
75
|
-
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
76
|
-
*/
|
77
|
-
api?: string;
|
78
|
-
/**
|
79
|
-
* An unique identifier for the chat. If not provided, a random one will be
|
80
|
-
* generated. When provided, the `useChat` hook with the same `id` will
|
81
|
-
* have shared states across components.
|
82
|
-
*/
|
83
|
-
id?: string;
|
84
|
-
/**
|
85
|
-
* Initial prompt input of the completion.
|
86
|
-
*/
|
87
|
-
initialInput?: string;
|
88
|
-
/**
|
89
|
-
* Initial completion result. Useful to load an existing history.
|
90
|
-
*/
|
91
|
-
initialCompletion?: string;
|
92
|
-
/**
|
93
|
-
* Callback function to be called when the API response is received.
|
94
|
-
*/
|
95
|
-
onResponse?: (response: Response) => void;
|
96
|
-
/**
|
97
|
-
* Callback function to be called when the completion is finished streaming.
|
98
|
-
*/
|
99
|
-
onFinish?: (prompt: string, completion: string) => void;
|
100
|
-
/**
|
101
|
-
* Callback function to be called when an error is encountered.
|
102
|
-
*/
|
103
|
-
onError?: (error: Error) => void;
|
104
|
-
/**
|
105
|
-
* HTTP headers to be sent with the API request.
|
106
|
-
*/
|
107
|
-
headers?: Record<string, string> | Headers;
|
108
|
-
/**
|
109
|
-
* Extra body object to be sent with the API request.
|
110
|
-
* @example
|
111
|
-
* Send a `sessionId` to the API along with the prompt.
|
112
|
-
* ```js
|
113
|
-
* useChat({
|
114
|
-
* body: {
|
115
|
-
* sessionId: '123',
|
116
|
-
* }
|
117
|
-
* })
|
118
|
-
* ```
|
119
|
-
*/
|
120
|
-
body?: object;
|
121
|
-
};
|
122
|
-
|
123
|
-
export { CreateMessage as C, Message as M, UseChatOptions as U, UseCompletionOptions as a };
|
@@ -1,39 +0,0 @@
|
|
1
|
-
import { Readable, Writable } from 'svelte/store';
|
2
|
-
import { M as Message, C as CreateMessage, U as UseChatOptions } from './types-f862f74a.js';
|
3
|
-
|
4
|
-
type UseChatHelpers = {
|
5
|
-
/** Current messages in the chat */
|
6
|
-
messages: Readable<Message[]>;
|
7
|
-
/** The error object of the API request */
|
8
|
-
error: Readable<undefined | Error>;
|
9
|
-
/**
|
10
|
-
* Append a user message to the chat list. This triggers the API call to fetch
|
11
|
-
* the assistant's response.
|
12
|
-
*/
|
13
|
-
append: (message: Message | CreateMessage) => Promise<string | null | undefined>;
|
14
|
-
/**
|
15
|
-
* Reload the last AI chat response for the given chat history. If the last
|
16
|
-
* message isn't from the assistant, it will request the API to generate a
|
17
|
-
* new response.
|
18
|
-
*/
|
19
|
-
reload: () => Promise<string | null | undefined>;
|
20
|
-
/**
|
21
|
-
* Abort the current request immediately, keep the generated tokens if any.
|
22
|
-
*/
|
23
|
-
stop: () => void;
|
24
|
-
/**
|
25
|
-
* Update the `messages` state locally. This is useful when you want to
|
26
|
-
* edit the messages on the client, and then trigger the `reload` method
|
27
|
-
* manually to regenerate the AI response.
|
28
|
-
*/
|
29
|
-
setMessages: (messages: Message[]) => void;
|
30
|
-
/** The current value of the input */
|
31
|
-
input: Writable<string>;
|
32
|
-
/** Form submission handler to automattically reset input and append a user message */
|
33
|
-
handleSubmit: (e: any) => void;
|
34
|
-
/** Whether the API request is in progress */
|
35
|
-
isLoading: Writable<boolean>;
|
36
|
-
};
|
37
|
-
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, onResponse, onFinish, onError, headers, body }?: UseChatOptions): UseChatHelpers;
|
38
|
-
|
39
|
-
export { CreateMessage, Message, UseChatHelpers, UseChatOptions, useChat };
|