@assistant-ui/react 0.5.21 → 0.5.22
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{AssistantTypes-D93BmqD5.d.mts → AssistantTypes-BNB-knVq.d.mts} +1 -1
- package/dist/{AssistantTypes-D93BmqD5.d.ts → AssistantTypes-BNB-knVq.d.ts} +1 -1
- package/dist/chunk-DCHYNTHI.js +11 -0
- package/dist/chunk-DCHYNTHI.js.map +1 -0
- package/dist/chunk-NSPHKRLF.js +819 -0
- package/dist/chunk-NSPHKRLF.js.map +1 -0
- package/dist/{chunk-2RKUKZSZ.mjs → chunk-ZWRFAYHH.mjs} +61 -3
- package/dist/chunk-ZWRFAYHH.mjs.map +1 -0
- package/dist/edge.d.mts +90 -5
- package/dist/edge.d.ts +90 -5
- package/dist/edge.js +0 -1
- package/dist/edge.js.map +1 -1
- package/dist/edge.mjs +799 -49
- package/dist/edge.mjs.map +1 -1
- package/dist/index.d.mts +153 -7
- package/dist/index.d.ts +153 -7
- package/dist/index.js +724 -1596
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +807 -252
- package/dist/index.mjs.map +1 -1
- package/dist/tailwindcss/index.js +24 -53
- package/dist/tailwindcss/index.js.map +1 -1
- package/package.json +1 -12
- package/dist/Thread-BbLf1cc4.d.mts +0 -156
- package/dist/Thread-jfAlPLli.d.ts +0 -156
- package/dist/chunk-2RKUKZSZ.mjs.map +0 -1
- package/dist/chunk-QBS6JLLN.mjs +0 -63
- package/dist/chunk-QBS6JLLN.mjs.map +0 -1
- package/dist/chunk-V66MVXBH.mjs +0 -608
- package/dist/chunk-V66MVXBH.mjs.map +0 -1
- package/dist/internal.d.mts +0 -9
- package/dist/internal.d.ts +0 -9
- package/dist/internal.js +0 -620
- package/dist/internal.js.map +0 -1
- package/dist/internal.mjs +0 -24
- package/dist/internal.mjs.map +0 -1
- package/internal/README.md +0 -1
- package/internal/package.json +0 -5
package/dist/internal.js
DELETED
@@ -1,620 +0,0 @@
|
|
1
|
-
"use client";
|
2
|
-
"use strict";
|
3
|
-
var __create = Object.create;
|
4
|
-
var __defProp = Object.defineProperty;
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
-
var __export = (target, all) => {
|
10
|
-
for (var name in all)
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
12
|
-
};
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
15
|
-
for (let key of __getOwnPropNames(from))
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
|
-
}
|
19
|
-
return to;
|
20
|
-
};
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
27
|
-
mod
|
28
|
-
));
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
30
|
-
|
31
|
-
// src/internal.ts
|
32
|
-
var internal_exports = {};
|
33
|
-
__export(internal_exports, {
|
34
|
-
BaseAssistantRuntime: () => BaseAssistantRuntime,
|
35
|
-
MessageRepository: () => MessageRepository,
|
36
|
-
ProxyConfigProvider: () => ProxyConfigProvider,
|
37
|
-
TooltipIconButton: () => TooltipIconButton,
|
38
|
-
generateId: () => generateId,
|
39
|
-
useSmooth: () => useSmooth,
|
40
|
-
useSmoothStatus: () => useSmoothStatus,
|
41
|
-
withSmoothContextProvider: () => withSmoothContextProvider
|
42
|
-
});
|
43
|
-
module.exports = __toCommonJS(internal_exports);
|
44
|
-
|
45
|
-
// src/types/ModelConfigTypes.ts
|
46
|
-
var import_zod = require("zod");
|
47
|
-
var LanguageModelV1CallSettingsSchema = import_zod.z.object({
|
48
|
-
maxTokens: import_zod.z.number().int().positive().optional(),
|
49
|
-
temperature: import_zod.z.number().optional(),
|
50
|
-
topP: import_zod.z.number().optional(),
|
51
|
-
presencePenalty: import_zod.z.number().optional(),
|
52
|
-
frequencyPenalty: import_zod.z.number().optional(),
|
53
|
-
seed: import_zod.z.number().int().optional(),
|
54
|
-
headers: import_zod.z.record(import_zod.z.string().optional()).optional()
|
55
|
-
});
|
56
|
-
var LanguageModelConfigSchema = import_zod.z.object({
|
57
|
-
apiKey: import_zod.z.string().optional(),
|
58
|
-
baseUrl: import_zod.z.string().optional(),
|
59
|
-
modelName: import_zod.z.string().optional()
|
60
|
-
});
|
61
|
-
var mergeModelConfigs = (configSet) => {
|
62
|
-
const configs = Array.from(configSet).map((c) => c.getModelConfig()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
63
|
-
return configs.reduce((acc, config) => {
|
64
|
-
if (config.system) {
|
65
|
-
if (acc.system) {
|
66
|
-
acc.system += `
|
67
|
-
|
68
|
-
${config.system}`;
|
69
|
-
} else {
|
70
|
-
acc.system = config.system;
|
71
|
-
}
|
72
|
-
}
|
73
|
-
if (config.tools) {
|
74
|
-
for (const [name, tool] of Object.entries(config.tools)) {
|
75
|
-
if (acc.tools?.[name]) {
|
76
|
-
throw new Error(
|
77
|
-
`You tried to define a tool with the name ${name}, but it already exists.`
|
78
|
-
);
|
79
|
-
}
|
80
|
-
if (!acc.tools) acc.tools = {};
|
81
|
-
acc.tools[name] = tool;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
if (config.config) {
|
85
|
-
acc.config = {
|
86
|
-
...acc.config,
|
87
|
-
...config.config
|
88
|
-
};
|
89
|
-
}
|
90
|
-
if (config.callSettings) {
|
91
|
-
acc.callSettings = {
|
92
|
-
...acc.callSettings,
|
93
|
-
...config.callSettings
|
94
|
-
};
|
95
|
-
}
|
96
|
-
return acc;
|
97
|
-
}, {});
|
98
|
-
};
|
99
|
-
|
100
|
-
// src/utils/ProxyConfigProvider.ts
|
101
|
-
var ProxyConfigProvider = class {
|
102
|
-
_providers = /* @__PURE__ */ new Set();
|
103
|
-
getModelConfig() {
|
104
|
-
return mergeModelConfigs(this._providers);
|
105
|
-
}
|
106
|
-
registerModelConfigProvider(provider) {
|
107
|
-
this._providers.add(provider);
|
108
|
-
return () => {
|
109
|
-
this._providers.delete(provider);
|
110
|
-
};
|
111
|
-
}
|
112
|
-
};
|
113
|
-
|
114
|
-
// src/utils/idUtils.tsx
|
115
|
-
var import_non_secure = require("nanoid/non-secure");
|
116
|
-
var generateId = (0, import_non_secure.customAlphabet)(
|
117
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
118
|
-
7
|
119
|
-
);
|
120
|
-
var optimisticPrefix = "__optimistic__";
|
121
|
-
var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
|
122
|
-
|
123
|
-
// src/runtimes/edge/converters/fromCoreMessage.ts
|
124
|
-
var fromCoreMessage = (message, {
|
125
|
-
id = generateId(),
|
126
|
-
status = { type: "complete", reason: "unknown" }
|
127
|
-
} = {}) => {
|
128
|
-
const commonProps = {
|
129
|
-
id,
|
130
|
-
createdAt: /* @__PURE__ */ new Date()
|
131
|
-
};
|
132
|
-
const role = message.role;
|
133
|
-
switch (role) {
|
134
|
-
case "assistant":
|
135
|
-
return {
|
136
|
-
...commonProps,
|
137
|
-
role,
|
138
|
-
content: message.content.map((part) => {
|
139
|
-
if (part.type === "tool-call") {
|
140
|
-
return {
|
141
|
-
...part,
|
142
|
-
argsText: JSON.stringify(part.args)
|
143
|
-
};
|
144
|
-
}
|
145
|
-
return part;
|
146
|
-
}),
|
147
|
-
status
|
148
|
-
};
|
149
|
-
case "user":
|
150
|
-
return {
|
151
|
-
...commonProps,
|
152
|
-
role,
|
153
|
-
content: message.content
|
154
|
-
};
|
155
|
-
case "system":
|
156
|
-
return {
|
157
|
-
...commonProps,
|
158
|
-
role,
|
159
|
-
content: message.content
|
160
|
-
};
|
161
|
-
default: {
|
162
|
-
const unsupportedRole = role;
|
163
|
-
throw new Error(`Unknown message role: ${unsupportedRole}`);
|
164
|
-
}
|
165
|
-
}
|
166
|
-
};
|
167
|
-
|
168
|
-
// src/runtimes/utils/MessageRepository.tsx
|
169
|
-
var findHead = (message) => {
|
170
|
-
if (message.next) return findHead(message.next);
|
171
|
-
return message;
|
172
|
-
};
|
173
|
-
var MessageRepository = class {
|
174
|
-
messages = /* @__PURE__ */ new Map();
|
175
|
-
// message_id -> item
|
176
|
-
head = null;
|
177
|
-
root = {
|
178
|
-
children: []
|
179
|
-
};
|
180
|
-
performOp(newParent, child, operation) {
|
181
|
-
const parentOrRoot = child.prev ?? this.root;
|
182
|
-
const newParentOrRoot = newParent ?? this.root;
|
183
|
-
if (operation === "relink" && parentOrRoot === newParentOrRoot) return;
|
184
|
-
if (operation !== "link") {
|
185
|
-
parentOrRoot.children = parentOrRoot.children.filter(
|
186
|
-
(m) => m !== child.current.id
|
187
|
-
);
|
188
|
-
if (child.prev?.next === child) {
|
189
|
-
const fallbackId = child.prev.children.at(-1);
|
190
|
-
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
191
|
-
if (fallback === void 0) {
|
192
|
-
throw new Error(
|
193
|
-
"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui."
|
194
|
-
);
|
195
|
-
}
|
196
|
-
child.prev.next = fallback;
|
197
|
-
}
|
198
|
-
}
|
199
|
-
if (operation !== "cut") {
|
200
|
-
newParentOrRoot.children = [
|
201
|
-
...newParentOrRoot.children,
|
202
|
-
child.current.id
|
203
|
-
];
|
204
|
-
if (newParent && (findHead(child) === this.head || newParent.next === null)) {
|
205
|
-
newParent.next = child;
|
206
|
-
}
|
207
|
-
child.prev = newParent;
|
208
|
-
}
|
209
|
-
}
|
210
|
-
getMessages() {
|
211
|
-
const messages = new Array(this.head?.level ?? 0);
|
212
|
-
for (let current = this.head; current; current = current.prev) {
|
213
|
-
messages[current.level] = current.current;
|
214
|
-
}
|
215
|
-
return messages;
|
216
|
-
}
|
217
|
-
addOrUpdateMessage(parentId, message) {
|
218
|
-
const existingItem = this.messages.get(message.id);
|
219
|
-
const prev = parentId ? this.messages.get(parentId) : null;
|
220
|
-
if (prev === void 0)
|
221
|
-
throw new Error(
|
222
|
-
"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui."
|
223
|
-
);
|
224
|
-
if (existingItem) {
|
225
|
-
existingItem.current = message;
|
226
|
-
this.performOp(prev, existingItem, "relink");
|
227
|
-
return;
|
228
|
-
}
|
229
|
-
const newItem = {
|
230
|
-
prev,
|
231
|
-
current: message,
|
232
|
-
next: null,
|
233
|
-
children: [],
|
234
|
-
level: prev ? prev.level + 1 : 0
|
235
|
-
};
|
236
|
-
this.messages.set(message.id, newItem);
|
237
|
-
this.performOp(prev, newItem, "link");
|
238
|
-
if (this.head === prev) {
|
239
|
-
this.head = newItem;
|
240
|
-
}
|
241
|
-
}
|
242
|
-
getMessage(messageId) {
|
243
|
-
const message = this.messages.get(messageId);
|
244
|
-
if (!message)
|
245
|
-
throw new Error(
|
246
|
-
"MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui."
|
247
|
-
);
|
248
|
-
return {
|
249
|
-
parentId: message.prev?.current.id ?? null,
|
250
|
-
message: message.current
|
251
|
-
};
|
252
|
-
}
|
253
|
-
appendOptimisticMessage(parentId, message) {
|
254
|
-
let optimisticId;
|
255
|
-
do {
|
256
|
-
optimisticId = generateOptimisticId();
|
257
|
-
} while (this.messages.has(optimisticId));
|
258
|
-
this.addOrUpdateMessage(
|
259
|
-
parentId,
|
260
|
-
fromCoreMessage(message, {
|
261
|
-
id: optimisticId,
|
262
|
-
status: { type: "running" }
|
263
|
-
})
|
264
|
-
);
|
265
|
-
return optimisticId;
|
266
|
-
}
|
267
|
-
deleteMessage(messageId, replacementId) {
|
268
|
-
const message = this.messages.get(messageId);
|
269
|
-
if (!message)
|
270
|
-
throw new Error(
|
271
|
-
"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui."
|
272
|
-
);
|
273
|
-
const replacement = replacementId === void 0 ? message.prev : replacementId === null ? null : this.messages.get(replacementId);
|
274
|
-
if (replacement === void 0)
|
275
|
-
throw new Error(
|
276
|
-
"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui."
|
277
|
-
);
|
278
|
-
for (const child of message.children) {
|
279
|
-
const childMessage = this.messages.get(child);
|
280
|
-
if (!childMessage)
|
281
|
-
throw new Error(
|
282
|
-
"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui."
|
283
|
-
);
|
284
|
-
this.performOp(replacement, childMessage, "relink");
|
285
|
-
}
|
286
|
-
this.performOp(null, message, "cut");
|
287
|
-
this.messages.delete(messageId);
|
288
|
-
if (this.head === message) {
|
289
|
-
this.head = replacement ? findHead(replacement) : null;
|
290
|
-
}
|
291
|
-
}
|
292
|
-
getBranches(messageId) {
|
293
|
-
const message = this.messages.get(messageId);
|
294
|
-
if (!message)
|
295
|
-
throw new Error(
|
296
|
-
"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui."
|
297
|
-
);
|
298
|
-
const { children } = message.prev ?? this.root;
|
299
|
-
return children;
|
300
|
-
}
|
301
|
-
switchToBranch(messageId) {
|
302
|
-
const message = this.messages.get(messageId);
|
303
|
-
if (!message)
|
304
|
-
throw new Error(
|
305
|
-
"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui."
|
306
|
-
);
|
307
|
-
if (message.prev) {
|
308
|
-
message.prev.next = message;
|
309
|
-
}
|
310
|
-
this.head = findHead(message);
|
311
|
-
}
|
312
|
-
resetHead(messageId) {
|
313
|
-
if (messageId === null) {
|
314
|
-
this.head = null;
|
315
|
-
return;
|
316
|
-
}
|
317
|
-
const message = this.messages.get(messageId);
|
318
|
-
if (!message)
|
319
|
-
throw new Error(
|
320
|
-
"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui."
|
321
|
-
);
|
322
|
-
this.head = message;
|
323
|
-
for (let current = message; current; current = current.prev) {
|
324
|
-
if (current.prev) {
|
325
|
-
current.prev.next = current;
|
326
|
-
}
|
327
|
-
}
|
328
|
-
}
|
329
|
-
};
|
330
|
-
|
331
|
-
// src/runtimes/core/BaseAssistantRuntime.tsx
|
332
|
-
var BaseAssistantRuntime = class {
|
333
|
-
constructor(_thread) {
|
334
|
-
this._thread = _thread;
|
335
|
-
this._thread = _thread;
|
336
|
-
}
|
337
|
-
get thread() {
|
338
|
-
return this._thread;
|
339
|
-
}
|
340
|
-
set thread(thread) {
|
341
|
-
this._thread = thread;
|
342
|
-
this.subscriptionHandler();
|
343
|
-
}
|
344
|
-
_subscriptions = /* @__PURE__ */ new Set();
|
345
|
-
subscribe(callback) {
|
346
|
-
this._subscriptions.add(callback);
|
347
|
-
return () => this._subscriptions.delete(callback);
|
348
|
-
}
|
349
|
-
subscriptionHandler = () => {
|
350
|
-
for (const callback of this._subscriptions) callback();
|
351
|
-
};
|
352
|
-
};
|
353
|
-
|
354
|
-
// src/utils/smooth/useSmooth.tsx
|
355
|
-
var import_react4 = require("react");
|
356
|
-
|
357
|
-
// src/context/react/MessageContext.ts
|
358
|
-
var import_react = require("react");
|
359
|
-
var MessageContext = (0, import_react.createContext)(null);
|
360
|
-
function useMessageContext(options) {
|
361
|
-
const context = (0, import_react.useContext)(MessageContext);
|
362
|
-
if (!options?.optional && !context)
|
363
|
-
throw new Error(
|
364
|
-
"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
|
365
|
-
);
|
366
|
-
return context;
|
367
|
-
}
|
368
|
-
|
369
|
-
// src/context/react/ContentPartContext.ts
|
370
|
-
var import_react2 = require("react");
|
371
|
-
var ContentPartContext = (0, import_react2.createContext)(
|
372
|
-
null
|
373
|
-
);
|
374
|
-
function useContentPartContext(options) {
|
375
|
-
const context = (0, import_react2.useContext)(ContentPartContext);
|
376
|
-
if (!options?.optional && !context)
|
377
|
-
throw new Error(
|
378
|
-
"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
|
379
|
-
);
|
380
|
-
return context;
|
381
|
-
}
|
382
|
-
|
383
|
-
// src/utils/smooth/SmoothContext.tsx
|
384
|
-
var import_react3 = require("react");
|
385
|
-
var import_zustand = require("zustand");
|
386
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
387
|
-
var SmoothContext = (0, import_react3.createContext)(null);
|
388
|
-
var makeSmoothContext = (initialState) => {
|
389
|
-
const useSmoothStatus2 = (0, import_zustand.create)(() => initialState);
|
390
|
-
return { useSmoothStatus: useSmoothStatus2 };
|
391
|
-
};
|
392
|
-
var SmoothContextProvider = ({ children }) => {
|
393
|
-
const outer = useSmoothContext({ optional: true });
|
394
|
-
const { useContentPart } = useContentPartContext();
|
395
|
-
const [context] = (0, import_react3.useState)(
|
396
|
-
() => makeSmoothContext(useContentPart.getState().status)
|
397
|
-
);
|
398
|
-
if (outer) return children;
|
399
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SmoothContext.Provider, { value: context, children });
|
400
|
-
};
|
401
|
-
var withSmoothContextProvider = (Component) => {
|
402
|
-
const Wrapped = (0, import_react3.forwardRef)((props, ref) => {
|
403
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SmoothContextProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props, ref }) });
|
404
|
-
});
|
405
|
-
Wrapped.displayName = Component.displayName;
|
406
|
-
return Wrapped;
|
407
|
-
};
|
408
|
-
function useSmoothContext(options) {
|
409
|
-
const context = (0, import_react3.useContext)(SmoothContext);
|
410
|
-
if (!options?.optional && !context)
|
411
|
-
throw new Error(
|
412
|
-
"This component must be used within a SmoothContextProvider."
|
413
|
-
);
|
414
|
-
return context;
|
415
|
-
}
|
416
|
-
var useSmoothStatus = () => {
|
417
|
-
const { useSmoothStatus: useSmoothStatus2 } = useSmoothContext();
|
418
|
-
return useSmoothStatus2();
|
419
|
-
};
|
420
|
-
|
421
|
-
// src/utils/smooth/useSmooth.tsx
|
422
|
-
var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
|
423
|
-
var TextStreamAnimator = class {
|
424
|
-
constructor(currentText, setText) {
|
425
|
-
this.currentText = currentText;
|
426
|
-
this.setText = setText;
|
427
|
-
}
|
428
|
-
animationFrameId = null;
|
429
|
-
lastUpdateTime = Date.now();
|
430
|
-
targetText = "";
|
431
|
-
start() {
|
432
|
-
if (this.animationFrameId !== null) return;
|
433
|
-
this.lastUpdateTime = Date.now();
|
434
|
-
this.animate();
|
435
|
-
}
|
436
|
-
stop() {
|
437
|
-
if (this.animationFrameId !== null) {
|
438
|
-
cancelAnimationFrame(this.animationFrameId);
|
439
|
-
this.animationFrameId = null;
|
440
|
-
}
|
441
|
-
}
|
442
|
-
animate = () => {
|
443
|
-
const currentTime = Date.now();
|
444
|
-
const deltaTime = currentTime - this.lastUpdateTime;
|
445
|
-
let timeToConsume = deltaTime;
|
446
|
-
const remainingChars = this.targetText.length - this.currentText.length;
|
447
|
-
const baseTimePerChar = Math.min(5, 250 / remainingChars);
|
448
|
-
let charsToAdd = 0;
|
449
|
-
while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {
|
450
|
-
charsToAdd++;
|
451
|
-
timeToConsume -= baseTimePerChar;
|
452
|
-
}
|
453
|
-
if (charsToAdd !== remainingChars) {
|
454
|
-
this.animationFrameId = requestAnimationFrame(this.animate);
|
455
|
-
} else {
|
456
|
-
this.animationFrameId = null;
|
457
|
-
}
|
458
|
-
if (charsToAdd === 0) return;
|
459
|
-
this.currentText = this.targetText.slice(
|
460
|
-
0,
|
461
|
-
this.currentText.length + charsToAdd
|
462
|
-
);
|
463
|
-
this.lastUpdateTime = currentTime - timeToConsume;
|
464
|
-
this.setText(this.currentText);
|
465
|
-
};
|
466
|
-
};
|
467
|
-
var SMOOTH_STATUS = Object.freeze({
|
468
|
-
type: "running"
|
469
|
-
});
|
470
|
-
var useSmooth = (state, smooth = false) => {
|
471
|
-
const { useSmoothStatus: useSmoothStatus2 } = useSmoothContext({ optional: true }) ?? {};
|
472
|
-
const {
|
473
|
-
part: { text }
|
474
|
-
} = state;
|
475
|
-
const { useMessage } = useMessageContext();
|
476
|
-
const id = useMessage((m) => m.message.id);
|
477
|
-
const idRef = (0, import_react4.useRef)(id);
|
478
|
-
const [displayedText, setDisplayedText] = (0, import_react4.useState)(text);
|
479
|
-
const setText = (0, import_react_use_callback_ref.useCallbackRef)((text2) => {
|
480
|
-
setDisplayedText(text2);
|
481
|
-
useSmoothStatus2?.setState(text2 !== state.part.text ? SMOOTH_STATUS : state.status);
|
482
|
-
});
|
483
|
-
const [animatorRef] = (0, import_react4.useState)(
|
484
|
-
new TextStreamAnimator(text, setText)
|
485
|
-
);
|
486
|
-
(0, import_react4.useEffect)(() => {
|
487
|
-
if (!smooth) {
|
488
|
-
animatorRef.stop();
|
489
|
-
return;
|
490
|
-
}
|
491
|
-
if (idRef.current !== id || !text.startsWith(animatorRef.targetText)) {
|
492
|
-
idRef.current = id;
|
493
|
-
setText(text);
|
494
|
-
animatorRef.currentText = text;
|
495
|
-
animatorRef.targetText = text;
|
496
|
-
animatorRef.stop();
|
497
|
-
return;
|
498
|
-
}
|
499
|
-
animatorRef.targetText = text;
|
500
|
-
animatorRef.start();
|
501
|
-
}, [setText, animatorRef, id, smooth, text]);
|
502
|
-
(0, import_react4.useEffect)(() => {
|
503
|
-
return () => {
|
504
|
-
animatorRef.stop();
|
505
|
-
};
|
506
|
-
}, [animatorRef]);
|
507
|
-
return (0, import_react4.useMemo)(
|
508
|
-
() => smooth ? {
|
509
|
-
part: { type: "text", text: displayedText },
|
510
|
-
status: text === displayedText ? state.status : SMOOTH_STATUS
|
511
|
-
} : state,
|
512
|
-
[smooth, displayedText, state, text]
|
513
|
-
);
|
514
|
-
};
|
515
|
-
|
516
|
-
// src/ui/base/tooltip-icon-button.tsx
|
517
|
-
var import_react7 = require("react");
|
518
|
-
|
519
|
-
// src/ui/base/tooltip.tsx
|
520
|
-
var TooltipPrimitive = __toESM(require("@radix-ui/react-tooltip"));
|
521
|
-
|
522
|
-
// src/ui/utils/withDefaults.tsx
|
523
|
-
var import_react5 = require("react");
|
524
|
-
var import_classnames = __toESM(require("classnames"));
|
525
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
526
|
-
var withDefaultProps = ({
|
527
|
-
className,
|
528
|
-
...defaultProps
|
529
|
-
}) => ({ className: classNameProp, ...props }) => {
|
530
|
-
return {
|
531
|
-
className: (0, import_classnames.default)(className, classNameProp),
|
532
|
-
...defaultProps,
|
533
|
-
...props
|
534
|
-
};
|
535
|
-
};
|
536
|
-
var withDefaults = (Component, defaultProps) => {
|
537
|
-
const getProps = withDefaultProps(defaultProps);
|
538
|
-
const WithDefaults = (0, import_react5.forwardRef)(
|
539
|
-
(props, ref) => {
|
540
|
-
const ComponentAsAny = Component;
|
541
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ComponentAsAny, { ...getProps(props), ref });
|
542
|
-
}
|
543
|
-
);
|
544
|
-
WithDefaults.displayName = "withDefaults(" + (typeof Component === "string" ? Component : Component.displayName) + ")";
|
545
|
-
return WithDefaults;
|
546
|
-
};
|
547
|
-
|
548
|
-
// src/ui/base/tooltip.tsx
|
549
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
550
|
-
var Tooltip = (props) => {
|
551
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TooltipPrimitive.Root, { ...props }) });
|
552
|
-
};
|
553
|
-
Tooltip.displayName = "Tooltip";
|
554
|
-
var TooltipTrigger = TooltipPrimitive.Trigger;
|
555
|
-
var TooltipContent = withDefaults(TooltipPrimitive.Content, {
|
556
|
-
sideOffset: 4,
|
557
|
-
className: "aui-tooltip-content"
|
558
|
-
});
|
559
|
-
TooltipContent.displayName = "TooltipContent";
|
560
|
-
|
561
|
-
// src/ui/base/button.tsx
|
562
|
-
var import_class_variance_authority = require("class-variance-authority");
|
563
|
-
var import_react_primitive = require("@radix-ui/react-primitive");
|
564
|
-
var import_react6 = require("react");
|
565
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
566
|
-
var buttonVariants = (0, import_class_variance_authority.cva)("aui-button", {
|
567
|
-
variants: {
|
568
|
-
variant: {
|
569
|
-
default: "aui-button-primary",
|
570
|
-
outline: "aui-button-outline",
|
571
|
-
ghost: "aui-button-ghost"
|
572
|
-
},
|
573
|
-
size: {
|
574
|
-
default: "aui-button-medium",
|
575
|
-
icon: "aui-button-icon"
|
576
|
-
}
|
577
|
-
},
|
578
|
-
defaultVariants: {
|
579
|
-
variant: "default",
|
580
|
-
size: "default"
|
581
|
-
}
|
582
|
-
});
|
583
|
-
var Button = (0, import_react6.forwardRef)(
|
584
|
-
({ className, variant, size, ...props }, ref) => {
|
585
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
586
|
-
import_react_primitive.Primitive.button,
|
587
|
-
{
|
588
|
-
className: buttonVariants({ variant, size, className }),
|
589
|
-
...props,
|
590
|
-
ref
|
591
|
-
}
|
592
|
-
);
|
593
|
-
}
|
594
|
-
);
|
595
|
-
Button.displayName = "Button";
|
596
|
-
|
597
|
-
// src/ui/base/tooltip-icon-button.tsx
|
598
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
599
|
-
var TooltipIconButton = (0, import_react7.forwardRef)(({ children, tooltip, side = "bottom", ...rest }, ref) => {
|
600
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Tooltip, { children: [
|
601
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Button, { variant: "ghost", size: "icon", ...rest, ref, children: [
|
602
|
-
children,
|
603
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "aui-sr-only", children: tooltip })
|
604
|
-
] }) }),
|
605
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TooltipContent, { side, children: tooltip })
|
606
|
-
] });
|
607
|
-
});
|
608
|
-
TooltipIconButton.displayName = "TooltipIconButton";
|
609
|
-
// Annotate the CommonJS export names for ESM import in node:
|
610
|
-
0 && (module.exports = {
|
611
|
-
BaseAssistantRuntime,
|
612
|
-
MessageRepository,
|
613
|
-
ProxyConfigProvider,
|
614
|
-
TooltipIconButton,
|
615
|
-
generateId,
|
616
|
-
useSmooth,
|
617
|
-
useSmoothStatus,
|
618
|
-
withSmoothContextProvider
|
619
|
-
});
|
620
|
-
//# sourceMappingURL=internal.js.map
|