@sveda-ai/vue 0.3.1 → 0.3.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.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/dist/appearance.d.ts +4 -53
  3. package/dist/appearance.d.ts.map +1 -1
  4. package/dist/composables/useSvedaChat.d.ts +7 -149
  5. package/dist/composables/useSvedaChat.d.ts.map +1 -1
  6. package/dist/composables/useSvedaChatLayout.d.ts +1 -1
  7. package/dist/composables/useSvedaChatLayout.d.ts.map +1 -1
  8. package/dist/composables/useSvedaChatPage.d.ts +6 -91
  9. package/dist/composables/useSvedaChatPage.d.ts.map +1 -1
  10. package/dist/composables/useSvedaPrompts.d.ts +1 -1
  11. package/dist/composables/useSvedaPrompts.d.ts.map +1 -1
  12. package/dist/composables/useSvedaStreaming.d.ts +3 -6
  13. package/dist/composables/useSvedaStreaming.d.ts.map +1 -1
  14. package/dist/index.d.ts +3 -10
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3035 -4437
  17. package/dist/plugin.d.ts.map +1 -1
  18. package/dist/styles.css +2 -1
  19. package/dist/ui/sheet/index.d.ts +1 -1
  20. package/dist/ui/toast/Toast.vue.d.ts +2 -2
  21. package/dist/vue.css +1 -1
  22. package/package.json +20 -28
  23. package/src/appearance.ts +44 -652
  24. package/src/components/chat/ChatMessageActivityBlock.vue +1 -1
  25. package/src/components/chat/ChatMessageItem.vue +3 -3
  26. package/src/components/chat/ChatMessageList.vue +1 -1
  27. package/src/components/shell/SvedaTabs.vue +1 -1
  28. package/src/composables/useSvedaChat.ts +53 -573
  29. package/src/composables/useSvedaChatLayout.ts +1 -1
  30. package/src/composables/useSvedaChatPage.ts +1 -1
  31. package/src/composables/useSvedaPrompts.ts +1 -1
  32. package/src/composables/useSvedaStreaming.ts +41 -368
  33. package/src/index.ts +14 -11
  34. package/src/plugin.ts +1 -3
  35. package/src/theme.test.mjs +5 -4
  36. package/dist/i18n/locales/en.d.ts +0 -4
  37. package/dist/i18n/locales/en.d.ts.map +0 -1
  38. package/dist/i18n/locales/ru.d.ts +0 -4
  39. package/dist/i18n/locales/ru.d.ts.map +0 -1
  40. package/dist/lib/assistantMessage.d.ts +0 -90
  41. package/dist/lib/assistantMessage.d.ts.map +0 -1
  42. package/dist/lib/chatHistoryMerge.d.ts +0 -20
  43. package/dist/lib/chatHistoryMerge.d.ts.map +0 -1
  44. package/dist/lib/chatI18nKeys.d.ts +0 -2
  45. package/dist/lib/chatI18nKeys.d.ts.map +0 -1
  46. package/dist/lib/chatMessageVisibility.d.ts +0 -6
  47. package/dist/lib/chatMessageVisibility.d.ts.map +0 -1
  48. package/dist/lib/chatResize.d.ts +0 -42
  49. package/dist/lib/chatResize.d.ts.map +0 -1
  50. package/dist/lib/chatTabs.d.ts +0 -9
  51. package/dist/lib/chatTabs.d.ts.map +0 -1
  52. package/dist/lib/chatTitle.d.ts +0 -3
  53. package/dist/lib/chatTitle.d.ts.map +0 -1
  54. package/dist/lib/chatUiStorage.d.ts +0 -6
  55. package/dist/lib/chatUiStorage.d.ts.map +0 -1
  56. package/dist/lib/finalizeMessages.d.ts +0 -21
  57. package/dist/lib/finalizeMessages.d.ts.map +0 -1
  58. package/dist/lib/markdown.d.ts +0 -8
  59. package/dist/lib/markdown.d.ts.map +0 -1
  60. package/dist/lib/modelLabels.d.ts +0 -3
  61. package/dist/lib/modelLabels.d.ts.map +0 -1
  62. package/dist/lib/toolConfirmation.d.ts +0 -11
  63. package/dist/lib/toolConfirmation.d.ts.map +0 -1
  64. package/dist/lib/userMessage.d.ts +0 -17
  65. package/dist/lib/userMessage.d.ts.map +0 -1
  66. package/src/i18n/locales/en.ts +0 -64
  67. package/src/i18n/locales/ru.ts +0 -65
  68. package/src/lib/assistantMessage.ts +0 -439
  69. package/src/lib/chatHistoryMerge.ts +0 -93
  70. package/src/lib/chatI18nKeys.ts +0 -64
  71. package/src/lib/chatMessageVisibility.ts +0 -92
  72. package/src/lib/chatResize.ts +0 -123
  73. package/src/lib/chatTabs.ts +0 -54
  74. package/src/lib/chatTitle.ts +0 -30
  75. package/src/lib/chatUiStorage.ts +0 -69
  76. package/src/lib/finalizeMessages.ts +0 -81
  77. package/src/lib/markdown.ts +0 -90
  78. package/src/lib/modelLabels.ts +0 -24
  79. package/src/lib/toolConfirmation.ts +0 -31
  80. package/src/lib/userMessage.ts +0 -55
@@ -1,439 +0,0 @@
1
- export interface SvedaResourceLink {
2
- label: string;
3
- url: string;
4
- icon?: string;
5
- kind?: 'created' | 'reference';
6
- }
7
-
8
- export type SvedaAssistantMessagePart = {
9
- type?: string;
10
- text?: string;
11
- state?: string;
12
- toolName?: string;
13
- toolCallId?: string;
14
- target?: string;
15
- output?: unknown;
16
- result?: unknown;
17
- input?: unknown;
18
- args?: unknown;
19
- errorText?: string;
20
- renderHint?: string;
21
- renderData?: Record<string, unknown>;
22
- confirmation?: string;
23
- };
24
-
25
- export type SvedaLegacyActivity = {
26
- phase?: string;
27
- steps?: Array<{
28
- id: string;
29
- label: string;
30
- status: string;
31
- detail?: string;
32
- kind?: string;
33
- activityGroupKey?: string;
34
- activityGroupLabel?: string;
35
- display?: { name?: string; link?: string };
36
- }>;
37
- };
38
-
39
- export type SvedaChatMessageLike = {
40
- id?: string;
41
- role?: string;
42
- content?: string;
43
- parts?: SvedaAssistantMessagePart[];
44
- reasoningStream?: string;
45
- activity?: SvedaLegacyActivity;
46
- toolInvocations?: SvedaAssistantMessagePart[];
47
- resources?: SvedaResourceLink[];
48
- streaming?: boolean;
49
- isError?: boolean;
50
- attachmentNames?: string[];
51
- metadata?: {
52
- attachmentNames?: string[];
53
- };
54
- };
55
-
56
- export type AssistantMessageSegment =
57
- | {
58
- kind: 'activity';
59
- id: string;
60
- invocations: SvedaAssistantMessagePart[];
61
- legacyActivity?: SvedaLegacyActivity;
62
- }
63
- | {
64
- kind: 'comment';
65
- id: string;
66
- text: string;
67
- streaming: boolean;
68
- }
69
- | {
70
- kind: 'answer';
71
- id: string;
72
- text: string;
73
- streaming: boolean;
74
- }
75
- | {
76
- kind: 'reasoning';
77
- id: string;
78
- text: string;
79
- streaming: boolean;
80
- };
81
-
82
- export function isAssistantToolPart(part: SvedaAssistantMessagePart | null | undefined): boolean {
83
- if (!part || typeof part.type !== 'string') {
84
- return false;
85
- }
86
- if (part.type === 'tool-call' || part.type === 'tool-result') {
87
- return false;
88
- }
89
- return part.type === 'dynamic-tool' || part.type.startsWith('tool-');
90
- }
91
-
92
- function svedaToolPartToInvocation(
93
- call: SvedaAssistantMessagePart | undefined,
94
- result: SvedaAssistantMessagePart | undefined
95
- ): SvedaAssistantMessagePart {
96
- return {
97
- type: 'dynamic-tool',
98
- toolCallId: call?.toolCallId ?? result?.toolCallId ?? '',
99
- toolName: call?.toolName ?? result?.toolName ?? '',
100
- input: call?.input,
101
- output: result?.output,
102
- renderHint: result?.renderHint,
103
- renderData: result?.renderData,
104
- confirmation: call?.confirmation,
105
- state: result ? 'result' : 'call',
106
- };
107
- }
108
-
109
- export function buildAssistantMessageSegments(
110
- message: SvedaChatMessageLike
111
- ): AssistantMessageSegment[] {
112
- const parts = Array.isArray(message.parts) ? message.parts : [];
113
-
114
- if (parts.length === 0) {
115
- const segments: AssistantMessageSegment[] = [];
116
-
117
- const legacyInvocations = Array.isArray(message.toolInvocations) ? message.toolInvocations : [];
118
- if (legacyInvocations.length > 0) {
119
- segments.push({
120
- kind: 'activity',
121
- id: 'activity-legacy-tools',
122
- invocations: legacyInvocations,
123
- });
124
- } else if (message.activity?.steps?.length) {
125
- segments.push({
126
- kind: 'activity',
127
- id: 'activity-legacy',
128
- invocations: [],
129
- legacyActivity: message.activity,
130
- });
131
- }
132
-
133
- if (message.reasoningStream?.trim()) {
134
- segments.push({
135
- kind: 'reasoning',
136
- id: 'reasoning-legacy',
137
- text: message.reasoningStream.trim(),
138
- streaming: false,
139
- });
140
- }
141
-
142
- if (message.content?.trim()) {
143
- segments.push({
144
- kind: 'answer',
145
- id: 'answer-legacy',
146
- text: message.content.trim(),
147
- streaming: false,
148
- });
149
- }
150
-
151
- return segments;
152
- }
153
-
154
- const resultsByCallId = new Map<string, SvedaAssistantMessagePart>();
155
- for (const part of parts) {
156
- if (part.type === 'tool-result' && part.toolCallId) {
157
- resultsByCallId.set(part.toolCallId, part);
158
- }
159
- }
160
- const consumedResultIds = new Set<string>();
161
-
162
- const segments: AssistantMessageSegment[] = [];
163
- let toolBuffer: SvedaAssistantMessagePart[] = [];
164
- const textBuffer: Array<{ part: SvedaAssistantMessagePart; index: number }> = [];
165
-
166
- const lastTextPartIndex = parts.reduce((lastIndex, part, index) => {
167
- if (part.type === 'text' && part.text?.trim()) {
168
- return index;
169
- }
170
- return lastIndex;
171
- }, -1);
172
-
173
- const flushTools = () => {
174
- if (toolBuffer.length === 0) {
175
- return;
176
- }
177
- segments.push({
178
- kind: 'activity',
179
- id: `activity-${segments.length}`,
180
- invocations: [...toolBuffer],
181
- });
182
- toolBuffer = [];
183
- };
184
-
185
- const flushText = () => {
186
- const buffered = textBuffer.filter(
187
- entry => entry.part.type === 'text' && entry.part.text?.trim()
188
- );
189
- textBuffer.length = 0;
190
- if (buffered.length === 0) {
191
- return;
192
- }
193
-
194
- const text = buffered.map(entry => String(entry.part.text).trim()).join('\n\n');
195
- const streaming = buffered.some(entry => entry.part.state === 'streaming');
196
- const maxTextIndex = Math.max(...buffered.map(entry => entry.index));
197
- const isAnswer = lastTextPartIndex >= 0 && maxTextIndex === lastTextPartIndex;
198
-
199
- segments.push({
200
- kind: isAnswer ? 'answer' : 'comment',
201
- id: `text-${segments.length}`,
202
- text,
203
- streaming,
204
- });
205
- };
206
-
207
- for (let index = 0; index < parts.length; index += 1) {
208
- const part = parts[index];
209
-
210
- if (part.type === 'tool-call') {
211
- if (textBuffer.length > 0) {
212
- flushText();
213
- }
214
- const result = part.toolCallId ? resultsByCallId.get(part.toolCallId) : undefined;
215
- if (result && part.toolCallId) {
216
- consumedResultIds.add(part.toolCallId);
217
- }
218
- toolBuffer.push(svedaToolPartToInvocation(part, result));
219
- continue;
220
- }
221
-
222
- if (part.type === 'tool-result') {
223
- if (part.toolCallId && consumedResultIds.has(part.toolCallId)) {
224
- continue;
225
- }
226
- if (textBuffer.length > 0) {
227
- flushText();
228
- }
229
- toolBuffer.push(svedaToolPartToInvocation(undefined, part));
230
- continue;
231
- }
232
-
233
- if (isAssistantToolPart(part)) {
234
- if (textBuffer.length > 0) {
235
- flushText();
236
- }
237
- toolBuffer.push(part);
238
- continue;
239
- }
240
-
241
- if (part.type === 'reasoning' && part.text?.trim()) {
242
- flushTools();
243
- if (textBuffer.length > 0) {
244
- flushText();
245
- }
246
- segments.push({
247
- kind: 'reasoning',
248
- id: `reasoning-${segments.length}`,
249
- text: part.text.trim(),
250
- streaming: part.state === 'streaming',
251
- });
252
- continue;
253
- }
254
-
255
- if (part.type === 'text') {
256
- if (toolBuffer.length > 0) {
257
- flushTools();
258
- }
259
- textBuffer.push({ part, index });
260
- continue;
261
- }
262
- }
263
-
264
- flushText();
265
- flushTools();
266
-
267
- let hasAnswer = segments.some(segment => segment.kind === 'answer');
268
- if (!hasAnswer) {
269
- for (let i = segments.length - 1; i >= 0; i -= 1) {
270
- if (segments[i].kind === 'comment') {
271
- segments[i] = { ...segments[i], kind: 'answer' } as AssistantMessageSegment;
272
- hasAnswer = true;
273
- break;
274
- }
275
- }
276
- }
277
-
278
- if (!hasAnswer && message.content?.trim()) {
279
- segments.push({
280
- kind: 'answer',
281
- id: 'answer-content-fallback',
282
- text: message.content.trim(),
283
- streaming: false,
284
- });
285
- }
286
-
287
- return segments;
288
- }
289
-
290
- const READ_ONLY_TOOL_PREFIXES = ['get_', 'list_', 'search_', 'read_', 'web_'];
291
-
292
- export function getToolNameFromPart(part: { toolName?: string; type?: string }): string {
293
- if (part.toolName) {
294
- return part.toolName;
295
- }
296
- if (
297
- typeof part.type === 'string' &&
298
- part.type.startsWith('tool-') &&
299
- part.type !== 'tool-call' &&
300
- part.type !== 'tool-result'
301
- ) {
302
- return part.type.slice('tool-'.length);
303
- }
304
- return '';
305
- }
306
-
307
- export function parseToolResultOutput(output: unknown): Record<string, unknown> | null {
308
- if (output === undefined || output === null) {
309
- return null;
310
- }
311
- if (typeof output === 'object') {
312
- return output as Record<string, unknown>;
313
- }
314
- if (typeof output !== 'string' || output.trim() === '') {
315
- return null;
316
- }
317
- try {
318
- const parsed = JSON.parse(output) as unknown;
319
- return typeof parsed === 'object' && parsed !== null
320
- ? (parsed as Record<string, unknown>)
321
- : null;
322
- } catch {
323
- return null;
324
- }
325
- }
326
-
327
- export function getActivityGroupKey(toolName: string): string {
328
- if (!toolName) {
329
- return '';
330
- }
331
- if (READ_ONLY_TOOL_PREFIXES.some(prefix => toolName.startsWith(prefix))) {
332
- return `reader:${toolName}`;
333
- }
334
- return '';
335
- }
336
-
337
- export function getActivityGroupLabel(_toolName: string, translatedToolName: string): string {
338
- return translatedToolName;
339
- }
340
-
341
- function normalizeResourceLink(raw: unknown): SvedaResourceLink | null {
342
- if (!raw || typeof raw !== 'object') {
343
- return null;
344
- }
345
- const record = raw as Record<string, unknown>;
346
- const label = record.label ?? record.name;
347
- const url = record.url ?? record.link;
348
- if (typeof label !== 'string' || label.trim() === '') {
349
- return null;
350
- }
351
- if (typeof url !== 'string' || url.trim() === '') {
352
- return null;
353
- }
354
- const icon = typeof record.icon === 'string' && record.icon.trim() !== '' ? record.icon.trim() : undefined;
355
- return { label: label.trim(), url: url.trim(), ...(icon ? { icon } : {}) };
356
- }
357
-
358
- function pushResourceLink(resources: SvedaResourceLink[], resource: SvedaResourceLink): void {
359
- if (!resource.label || !resource.url) {
360
- return;
361
- }
362
- if (resources.some(existing => existing.url === resource.url)) {
363
- return;
364
- }
365
- resources.push(resource);
366
- }
367
-
368
- export function collectResourceLinks(message: SvedaChatMessageLike): SvedaResourceLink[] {
369
- const collected: SvedaResourceLink[] = [];
370
- const parts = [
371
- ...(Array.isArray(message.toolInvocations) ? message.toolInvocations : []),
372
- ...(Array.isArray(message.parts) ? message.parts : []),
373
- ];
374
-
375
- for (const part of parts) {
376
- if (!part || typeof part !== 'object') {
377
- continue;
378
- }
379
-
380
- if (part.type === 'tool-result' && part.renderHint === 'resource_links') {
381
- const links = part.renderData?.links;
382
- if (Array.isArray(links)) {
383
- for (const raw of links) {
384
- const link = normalizeResourceLink(raw);
385
- if (link) {
386
- pushResourceLink(collected, { ...link, kind: link.kind ?? 'reference' });
387
- }
388
- }
389
- }
390
- continue;
391
- }
392
-
393
- if (part.type === 'tool-result' || isAssistantToolPart(part)) {
394
- const resultData = parseToolResultOutput(part.output !== undefined ? part.output : part.result);
395
- if (!resultData || resultData.success === false) {
396
- continue;
397
- }
398
-
399
- const display = resultData.display as { name?: unknown; link?: unknown } | undefined;
400
- if (display?.name && display?.link) {
401
- pushResourceLink(collected, {
402
- label: String(display.name),
403
- url: String(display.link),
404
- kind: 'created',
405
- });
406
- }
407
-
408
- const links = resultData.links;
409
- if (Array.isArray(links)) {
410
- for (const raw of links) {
411
- const link = normalizeResourceLink(raw);
412
- if (link) {
413
- pushResourceLink(collected, { ...link, kind: link.kind ?? 'reference' });
414
- }
415
- }
416
- }
417
- }
418
- }
419
-
420
- return collected;
421
- }
422
-
423
- export function enrichMessagesWithResourceLinks<
424
- T extends { role?: string; resources?: SvedaResourceLink[] },
425
- >(messages: T[]): T[] {
426
- return messages.map(message => {
427
- if (message.role !== 'assistant') {
428
- return message;
429
- }
430
- const resources = collectResourceLinks(message);
431
- if (resources.length === 0) {
432
- return message;
433
- }
434
- return {
435
- ...message,
436
- resources,
437
- };
438
- });
439
- }
@@ -1,93 +0,0 @@
1
- export type SvedaMergeableChatHistory<TMessage> = {
2
- id: string;
3
- title: string;
4
- preview?: string;
5
- messages: TMessage[];
6
- tokensUsed: number;
7
- contextWindowTokens: number;
8
- createdAt: number;
9
- updatedAt: number;
10
- messagesLoaded: boolean;
11
- };
12
-
13
- export const mergeServerChatHistories = <T extends SvedaMergeableChatHistory<unknown>>(
14
- serverHistories: T[],
15
- currentChat: T | null
16
- ): T[] => {
17
- if (!currentChat) {
18
- return serverHistories;
19
- }
20
-
21
- const index = serverHistories.findIndex(chat => chat.id === currentChat.id);
22
- if (index === -1) {
23
- return [currentChat, ...serverHistories];
24
- }
25
-
26
- if (currentChat.messagesLoaded && !serverHistories[index].messagesLoaded) {
27
- const next = [...serverHistories];
28
- next[index] = {
29
- ...serverHistories[index],
30
- messages: currentChat.messages,
31
- messagesLoaded: true,
32
- };
33
- return next;
34
- }
35
-
36
- return serverHistories;
37
- };
38
-
39
- export const resolveMergedCurrentChat = <T extends { id: string }>(
40
- histories: T[],
41
- currentChat: T | null
42
- ): T | null => {
43
- if (!currentChat) {
44
- return null;
45
- }
46
-
47
- return histories.find(chat => chat.id === currentChat.id) ?? currentChat;
48
- };
49
-
50
- export const upsertChatHistoryMessages = <T extends SvedaMergeableChatHistory<unknown>>(
51
- histories: T[],
52
- currentChat: T | null,
53
- chatId: string,
54
- messages: T['messages'],
55
- now: number = Date.now()
56
- ): { histories: T[]; current: T | null } => {
57
- const index = histories.findIndex(chat => chat.id === chatId);
58
- if (index !== -1) {
59
- const next = [...histories];
60
- next[index] = {
61
- ...histories[index],
62
- messages,
63
- messagesLoaded: true,
64
- updatedAt: now,
65
- };
66
-
67
- return {
68
- histories: next,
69
- current: currentChat?.id === chatId ? next[index] : currentChat,
70
- };
71
- }
72
-
73
- const base = currentChat?.id === chatId ? currentChat : null;
74
- const upserted = {
75
- ...(base ?? {
76
- id: chatId,
77
- title: '',
78
- preview: '',
79
- tokensUsed: 0,
80
- contextWindowTokens: 0,
81
- createdAt: now,
82
- }),
83
- id: chatId,
84
- messages,
85
- messagesLoaded: true,
86
- updatedAt: now,
87
- } as T;
88
-
89
- return {
90
- histories: [upserted, ...histories],
91
- current: currentChat === null || currentChat.id === chatId ? upserted : currentChat,
92
- };
93
- };
@@ -1,64 +0,0 @@
1
- export const chatComponentI18nKeys: Record<string, Record<string, string>> = {
2
- en: {
3
- typeMessage: 'Ask AI to help you...',
4
- chatAttachFiles: 'Attach files (PDF, Word, Excel, presentations, images…)',
5
- chatRemoveFile: 'Remove file',
6
- attachmentsLabel: 'Attachments',
7
- attachmentOnlyPlaceholder: 'Documents: {names}',
8
- chatHistory: 'Chat History',
9
- searchChats: 'Search chats...',
10
- noChatsFound: 'No chats found',
11
- today: 'Today',
12
- yesterday: 'Yesterday',
13
- dayBeforeYesterday: 'Day before yesterday',
14
- daysAgo: '{count} days ago',
15
- renameChat: 'Rename chat',
16
- cancel: 'Cancel',
17
- delete: 'Delete',
18
- pendingStatus: 'Processing your request...',
19
- preparingReply: 'Preparing a reply…',
20
- phaseToolCalling: 'Using tools…',
21
- activityGroupSteps: '{label}: {count}',
22
- voiceInputStart: 'Voice input',
23
- voiceInputStop: 'Stop recording',
24
- voiceInputUnsupported: 'Voice input is not supported in this browser.',
25
- voiceInputError: 'Voice input',
26
- voiceInputPermissionDenied: 'Microphone access was denied.',
27
- voiceInputErrorGeneric: 'Something went wrong. Try again.',
28
- voiceInputBrowserWarningTitle: 'Voice input in this browser',
29
- voiceInputBrowserWarningDescription:
30
- 'Speech recognition may be inaccurate or unstable. For best results, use Google Chrome or Microsoft Edge. You can still continue in your current browser.',
31
- voiceInputBrowserWarningContinue: 'Continue anyway',
32
- },
33
- ru: {
34
- typeMessage: 'Попросите AI помочь вам...',
35
- chatAttachFiles: 'Прикрепить файлы (PDF, Word, Excel, презентации, изображения…)',
36
- chatRemoveFile: 'Убрать файл',
37
- attachmentsLabel: 'Вложения',
38
- attachmentOnlyPlaceholder: 'Документы: {names}',
39
- chatHistory: 'История чатов',
40
- searchChats: 'Поиск по чатам...',
41
- noChatsFound: 'Чаты не найдены',
42
- today: 'Сегодня',
43
- yesterday: 'Вчера',
44
- dayBeforeYesterday: 'Позавчера',
45
- daysAgo: '{count} дней назад',
46
- renameChat: 'Переименовать чат',
47
- cancel: 'Отмена',
48
- delete: 'Удалить',
49
- pendingStatus: 'Обрабатываем ваш запрос...',
50
- preparingReply: 'Готовлю ответ…',
51
- phaseToolCalling: 'Вызываю инструменты…',
52
- activityGroupSteps: '{label}: {count}',
53
- voiceInputStart: 'Голосовой ввод',
54
- voiceInputStop: 'Остановить запись',
55
- voiceInputUnsupported: 'Голосовой ввод не поддерживается в этом браузере.',
56
- voiceInputError: 'Голосовой ввод',
57
- voiceInputPermissionDenied: 'Доступ к микрофону запрещён.',
58
- voiceInputErrorGeneric: 'Не получилось. Попробуйте ещё раз.',
59
- voiceInputBrowserWarningTitle: 'Голосовой ввод в этом браузере',
60
- voiceInputBrowserWarningDescription:
61
- 'Распознавание речи может работать неточно или нестабильно. Для лучшего результата используйте Google Chrome или Microsoft Edge. Вы всё равно можете продолжить в текущем браузере.',
62
- voiceInputBrowserWarningContinue: 'Всё равно продолжить',
63
- },
64
- };
@@ -1,92 +0,0 @@
1
- import { isAssistantToolPart, type SvedaChatMessageLike } from './assistantMessage.js';
2
-
3
- export function messageHasVisibleAssistantContent(
4
- message: SvedaChatMessageLike | null | undefined
5
- ): boolean {
6
- if (!message || message.role !== 'assistant') {
7
- return false;
8
- }
9
-
10
- if (Array.isArray(message.parts) && message.parts.length > 0) {
11
- return message.parts.some(part => {
12
- if (part.type === 'text' && part.text?.trim()) {
13
- return true;
14
- }
15
- if (part.type === 'reasoning' && part.text?.trim()) {
16
- return true;
17
- }
18
- if (part.type === 'tool-call' || part.type === 'tool-result') {
19
- return true;
20
- }
21
- if (isAssistantToolPart(part)) {
22
- return true;
23
- }
24
-
25
- return false;
26
- });
27
- }
28
-
29
- return Boolean(message.content?.trim() || message.reasoningStream?.trim());
30
- }
31
-
32
- export function messageHasAssistantAnswerText(
33
- message: SvedaChatMessageLike | null | undefined
34
- ): boolean {
35
- if (!message || message.role !== 'assistant') {
36
- return false;
37
- }
38
-
39
- if (Array.isArray(message.parts) && message.parts.length > 0) {
40
- return message.parts.some(part => part.type === 'text' && Boolean(part.text?.trim()));
41
- }
42
-
43
- return Boolean(message.content?.trim());
44
- }
45
-
46
- export function assistantHasActiveTools(message: SvedaChatMessageLike | null | undefined): boolean {
47
- if (!message || message.role !== 'assistant' || !Array.isArray(message.parts)) {
48
- return false;
49
- }
50
-
51
- const completed = new Set(
52
- message.parts
53
- .filter(part => part.type === 'tool-result' && part.toolCallId)
54
- .map(part => part.toolCallId as string)
55
- );
56
-
57
- return message.parts.some(part => {
58
- if (part.type === 'tool-call') {
59
- return part.toolCallId ? !completed.has(part.toolCallId) : true;
60
- }
61
- if (isAssistantToolPart(part)) {
62
- const state = part.state ?? '';
63
- return (
64
- state !== 'result' &&
65
- state !== 'output-available' &&
66
- state !== 'output-error' &&
67
- state !== 'output-denied'
68
- );
69
- }
70
- return false;
71
- });
72
- }
73
-
74
- export function shouldShowChatPendingIndicator(
75
- isThinking: boolean,
76
- messages: SvedaChatMessageLike[]
77
- ): boolean {
78
- if (!isThinking) {
79
- return false;
80
- }
81
-
82
- const lastMessage = messages[messages.length - 1];
83
- if (!lastMessage) {
84
- return true;
85
- }
86
-
87
- if (lastMessage.role === 'user') {
88
- return true;
89
- }
90
-
91
- return !messageHasAssistantAnswerText(lastMessage);
92
- }