@sveda-ai/vue 0.2.0 → 0.3.0

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 (46) hide show
  1. package/dist/components/chat/ChatInput.vue.d.ts +2 -0
  2. package/dist/components/chat/ChatInput.vue.d.ts.map +1 -1
  3. package/dist/components/chat/ChatMessageActivityBlock.vue.d.ts +1 -1
  4. package/dist/components/chat/ChatMessageList.vue.d.ts.map +1 -1
  5. package/dist/components/shell/SvedaInputSection.vue.d.ts +2 -0
  6. package/dist/components/shell/SvedaLandingView.vue.d.ts +2 -0
  7. package/dist/components/shell/SvedaLandingView.vue.d.ts.map +1 -1
  8. package/dist/composables/useSvedaChat.d.ts +5 -0
  9. package/dist/composables/useSvedaChat.d.ts.map +1 -1
  10. package/dist/composables/useSvedaChatPage.d.ts +5 -0
  11. package/dist/composables/useSvedaChatPage.d.ts.map +1 -1
  12. package/dist/composables/useSvedaMessaging.d.ts +1 -0
  13. package/dist/composables/useSvedaMessaging.d.ts.map +1 -1
  14. package/dist/composables/useSvedaStreaming.d.ts +1 -0
  15. package/dist/composables/useSvedaStreaming.d.ts.map +1 -1
  16. package/dist/i18n/locales/en.d.ts.map +1 -1
  17. package/dist/i18n/locales/ru.d.ts.map +1 -1
  18. package/dist/index.js +3203 -3059
  19. package/dist/lib/assistantMessage.d.ts +1 -0
  20. package/dist/lib/assistantMessage.d.ts.map +1 -1
  21. package/dist/lib/chatI18nKeys.d.ts.map +1 -1
  22. package/dist/lib/chatMessageVisibility.d.ts +2 -0
  23. package/dist/lib/chatMessageVisibility.d.ts.map +1 -1
  24. package/dist/lib/toolConfirmation.d.ts +11 -0
  25. package/dist/lib/toolConfirmation.d.ts.map +1 -0
  26. package/dist/styles.css +2 -2
  27. package/dist/vue.css +1 -1
  28. package/package.json +9 -2
  29. package/src/components/chat/ChatInput.vue +13 -5
  30. package/src/components/chat/ChatMessageActivityBlock.vue +55 -2
  31. package/src/components/chat/ChatMessageItem.vue +2 -0
  32. package/src/components/chat/ChatMessageList.vue +35 -2
  33. package/src/components/shell/SvedaChat.vue +10 -1
  34. package/src/components/shell/SvedaInputSection.vue +2 -0
  35. package/src/components/shell/SvedaLandingView.vue +3 -1
  36. package/src/composables/useSvedaChatPage.ts +8 -0
  37. package/src/composables/useSvedaMessaging.ts +3 -2
  38. package/src/composables/useSvedaStreaming.ts +23 -0
  39. package/src/i18n/locales/en.ts +7 -1
  40. package/src/i18n/locales/ru.ts +7 -1
  41. package/src/lib/assistantMessage.ts +3 -1
  42. package/src/lib/chatI18nKeys.ts +4 -2
  43. package/src/lib/chatMessageVisibility.ts +43 -1
  44. package/src/lib/toolConfirmation.ts +31 -0
  45. package/src/markdown.css +96 -0
  46. package/src/styles.css +1 -0
@@ -10,6 +10,7 @@
10
10
  defineProps({
11
11
  inputMessage: String,
12
12
  isLoading: Boolean,
13
+ confirmationPending: Boolean,
13
14
  hasCurrentChat: Boolean,
14
15
  isStreaming: Boolean,
15
16
  pendingFiles: {
@@ -55,6 +56,7 @@
55
56
  @update:model-value="onInputUpdate"
56
57
  @update:pending-files="val => emit('update:pendingFiles', val)"
57
58
  :is-loading="isLoading"
59
+ :confirmation-pending="confirmationPending"
58
60
  :has-current-chat="hasCurrentChat"
59
61
  :is-streaming="isStreaming"
60
62
  :status-banner="statusBanner"
@@ -85,7 +87,7 @@
85
87
  class="px-4"
86
88
  :prompts="quickPromptButtons"
87
89
  :title="t('quickPromptsTitle')"
88
- :disabled="isLoading || isStreaming"
90
+ :disabled="isLoading || isStreaming || confirmationPending"
89
91
  @select="$emit('sendQuickPrompt', $event)"
90
92
  />
91
93
  </div>
@@ -13,6 +13,7 @@ import { useSvedaPrompts, type SvedaQuickPromptItem } from './useSvedaPrompts';
13
13
  import { useSvedaScroll, type SvedaScrollContainer } from './useSvedaScroll';
14
14
  import { useSvedaShell, type SvedaBrandInfo } from './useSvedaShell';
15
15
  import { useSvedaStreaming } from './useSvedaStreaming';
16
+ import { hasPendingToolConfirmation } from '../lib/toolConfirmation';
16
17
 
17
18
  export const svedaErrorMessage = (error: unknown, fallback: string): string => {
18
19
  if (error instanceof Error && error.message.trim()) {
@@ -106,6 +107,7 @@ export function useSvedaChatPage(options: SvedaChatPageOptions, elementRefs: Sve
106
107
  const {
107
108
  sendMessage: sendMessageStreaming,
108
109
  continueAfterMaxSteps: continueStreamingAfterMaxSteps,
110
+ resolveToolConfirmation: resolveStreamingToolConfirmation,
109
111
  isStreaming,
110
112
  isThinking,
111
113
  thinkingMessage,
@@ -160,6 +162,9 @@ export function useSvedaChatPage(options: SvedaChatPageOptions, elementRefs: Sve
160
162
  scrollBridge.scrollToBottom = scroll.scrollToBottom;
161
163
 
162
164
  const pageContext = options.pageContext ?? computed(() => ({}));
165
+ const confirmationPending = computed(() => hasPendingToolConfirmation(currentChat.value?.messages));
166
+ const resolveToolConfirmation = (toolCallId: string, decision: 'approve' | 'deny') =>
167
+ resolveStreamingToolConfirmation(toolCallId, decision, pageContext.value);
163
168
 
164
169
  const messaging = useSvedaMessaging({
165
170
  isLoading,
@@ -171,6 +176,7 @@ export function useSvedaChatPage(options: SvedaChatPageOptions, elementRefs: Sve
171
176
  resetAgentCompletedNotice: scroll.resetAgentCompletedNotice,
172
177
  resetMaxStepsContinueNotice: maxStepsContinue.resetMaxStepsContinueNotice,
173
178
  extractingDocuments: documents.extractingDocuments,
179
+ confirmationPending,
174
180
  extractChatDocuments: documents.extractChatDocuments,
175
181
  buildChatDocumentSections: documents.buildChatDocumentSections,
176
182
  onDocumentExtractError: documents.showDocumentExtractError,
@@ -321,6 +327,8 @@ export function useSvedaChatPage(options: SvedaChatPageOptions, elementRefs: Sve
321
327
  maxStepsContinueMessage,
322
328
  maxStepsContinueDisabled: maxStepsContinue.maxStepsContinueDisabled,
323
329
  continueAfterMaxSteps,
330
+ confirmationPending,
331
+ resolveToolConfirmation,
324
332
  isImmersiveLandingLayout,
325
333
  agentTasks,
326
334
  hasActiveAgentTasks,
@@ -17,6 +17,7 @@ export function useSvedaMessaging(deps: {
17
17
  resetAgentCompletedNotice: () => void;
18
18
  resetMaxStepsContinueNotice?: (chatId?: string) => void;
19
19
  extractingDocuments: Ref<boolean>;
20
+ confirmationPending?: Ref<boolean>;
20
21
  extractChatDocuments: (files: File[]) => Promise<{ items: SvedaExtractedDocumentItem[] }>;
21
22
  buildChatDocumentSections: (items: SvedaExtractedDocumentItem[]) => string;
22
23
  onDocumentExtractError: (error: unknown) => void;
@@ -27,7 +28,7 @@ export function useSvedaMessaging(deps: {
27
28
  const beforeSend = inject(SvedaBeforeSendKey, null);
28
29
 
29
30
  const sendMessage = async () => {
30
- if (deps.isLoading.value || !deps.currentChat.value) {
31
+ if (deps.isLoading.value || deps.confirmationPending?.value || !deps.currentChat.value) {
31
32
  return;
32
33
  }
33
34
  const text = inputMessage.value.trim();
@@ -92,7 +93,7 @@ export function useSvedaMessaging(deps: {
92
93
  };
93
94
 
94
95
  const sendQuickPrompt = async (prompt: string) => {
95
- if (!prompt || deps.isLoading.value || !deps.currentChat.value) {
96
+ if (!prompt || deps.isLoading.value || deps.confirmationPending?.value || !deps.currentChat.value) {
96
97
  return;
97
98
  }
98
99
 
@@ -393,6 +393,28 @@ export function useSvedaStreaming(
393
393
  scrollToBottom();
394
394
  };
395
395
 
396
+ const resolveToolConfirmation = async (
397
+ toolCallId: string,
398
+ decision: 'approve' | 'deny',
399
+ pageContext: Record<string, unknown> = {}
400
+ ) => {
401
+ const chatId = store.currentChat.value?.id;
402
+ if (!chatId || !toolCallId) {
403
+ return;
404
+ }
405
+ const session = ensureSession(chatId);
406
+ session.setMessages(store.currentChat.value?.messages ?? []);
407
+ try {
408
+ await session.resolveToolConfirmation(toolCallId, decision, {
409
+ ...resolveSendOptions(),
410
+ context: { ...pageContext },
411
+ });
412
+ } catch {
413
+ return;
414
+ }
415
+ scrollToBottom();
416
+ };
417
+
396
418
  onUnmounted(() => {
397
419
  for (const [chatId, unsubscribes] of subscriptions.entries()) {
398
420
  client.session(chatId).stop();
@@ -405,6 +427,7 @@ export function useSvedaStreaming(
405
427
  return {
406
428
  sendMessage,
407
429
  continueAfterMaxSteps,
430
+ resolveToolConfirmation,
408
431
  isStreaming,
409
432
  isThinking,
410
433
  thinkingMessage,
@@ -14,6 +14,7 @@ const en: SvedaMessages = {
14
14
  renameChat: 'Rename chat',
15
15
  renameChatPlaceholder: 'Enter chat name',
16
16
  analyzingRequest: 'Analyzing your request...',
17
+ preparingReply: 'Preparing a reply…',
17
18
  errorSendingMessage: 'Failed to send message. Please try again.',
18
19
  agentFinishedNotice: 'Agent finished',
19
20
  maxStepsReachedNotice:
@@ -44,7 +45,7 @@ const en: SvedaMessages = {
44
45
  agentTasksTitle: 'Parallel agents',
45
46
  agentTasksSpawnPhase: 'Batch agent run',
46
47
  phaseSearchSubagents: 'Search scouts',
47
- phaseToolCalling: 'Using tools',
48
+ phaseToolCalling: 'Using tools…',
48
49
  agentTaskStatusPending: 'Pending',
49
50
  agentTaskStatusRunning: 'Running',
50
51
  agentTaskStatusCompleted: 'Done',
@@ -53,6 +54,11 @@ const en: SvedaMessages = {
53
54
  commonCancel: 'Cancel',
54
55
  commonSave: 'Save',
55
56
  commonError: 'Error',
57
+ 'tools.web_search': 'Search the web',
58
+ 'tools.web_fetch': 'Read page',
59
+ toolConfirmationPrompt: 'This action needs your confirmation before it runs.',
60
+ toolConfirm: 'Confirm',
61
+ toolDeny: 'Deny',
56
62
  };
57
63
 
58
64
  export default en;
@@ -14,6 +14,7 @@ const ru: SvedaMessages = {
14
14
  renameChat: 'Переименовать чат',
15
15
  renameChatPlaceholder: 'Введите название чата',
16
16
  analyzingRequest: 'Анализирую ваш запрос...',
17
+ preparingReply: 'Готовлю ответ…',
17
18
  errorSendingMessage: 'Не удалось отправить сообщение. Попробуйте ещё раз.',
18
19
  agentFinishedNotice: 'Агент закончил работу',
19
20
  maxStepsReachedNotice:
@@ -45,7 +46,7 @@ const ru: SvedaMessages = {
45
46
  agentTasksTitle: 'Параллельные агенты',
46
47
  agentTasksSpawnPhase: 'Пакетный запуск агентов',
47
48
  phaseSearchSubagents: 'Поисковые скауты',
48
- phaseToolCalling: 'Вызов инструментов',
49
+ phaseToolCalling: 'Вызываю инструменты…',
49
50
  agentTaskStatusPending: 'Ожидание',
50
51
  agentTaskStatusRunning: 'Выполняется',
51
52
  agentTaskStatusCompleted: 'Готово',
@@ -54,6 +55,11 @@ const ru: SvedaMessages = {
54
55
  commonCancel: 'Отмена',
55
56
  commonSave: 'Сохранить',
56
57
  commonError: 'Ошибка',
58
+ 'tools.web_search': 'Поиск в интернете',
59
+ 'tools.web_fetch': 'Чтение страницы',
60
+ toolConfirmationPrompt: 'Это действие выполнится только после вашего подтверждения.',
61
+ toolConfirm: 'Подтвердить',
62
+ toolDeny: 'Отказать',
57
63
  };
58
64
 
59
65
  export default ru;
@@ -19,6 +19,7 @@ export type SvedaAssistantMessagePart = {
19
19
  errorText?: string;
20
20
  renderHint?: string;
21
21
  renderData?: Record<string, unknown>;
22
+ confirmation?: string;
22
23
  };
23
24
 
24
25
  export type SvedaLegacyActivity = {
@@ -100,6 +101,7 @@ function svedaToolPartToInvocation(
100
101
  output: result?.output,
101
102
  renderHint: result?.renderHint,
102
103
  renderData: result?.renderData,
104
+ confirmation: call?.confirmation,
103
105
  state: result ? 'result' : 'call',
104
106
  };
105
107
  }
@@ -285,7 +287,7 @@ export function buildAssistantMessageSegments(
285
287
  return segments;
286
288
  }
287
289
 
288
- const READ_ONLY_TOOL_PREFIXES = ['get_', 'list_', 'search_', 'read_'];
290
+ const READ_ONLY_TOOL_PREFIXES = ['get_', 'list_', 'search_', 'read_', 'web_'];
289
291
 
290
292
  export function getToolNameFromPart(part: { toolName?: string; type?: string }): string {
291
293
  if (part.toolName) {
@@ -16,7 +16,8 @@ export const chatComponentI18nKeys: Record<string, Record<string, string>> = {
16
16
  cancel: 'Cancel',
17
17
  delete: 'Delete',
18
18
  pendingStatus: 'Processing your request...',
19
- phaseToolCalling: 'Using tools',
19
+ preparingReply: 'Preparing a reply…',
20
+ phaseToolCalling: 'Using tools…',
20
21
  activityGroupSteps: '{label}: {count}',
21
22
  voiceInputStart: 'Voice input',
22
23
  voiceInputStop: 'Stop recording',
@@ -46,7 +47,8 @@ export const chatComponentI18nKeys: Record<string, Record<string, string>> = {
46
47
  cancel: 'Отмена',
47
48
  delete: 'Удалить',
48
49
  pendingStatus: 'Обрабатываем ваш запрос...',
49
- phaseToolCalling: 'Вызов инструментов',
50
+ preparingReply: 'Готовлю ответ…',
51
+ phaseToolCalling: 'Вызываю инструменты…',
50
52
  activityGroupSteps: '{label}: {count}',
51
53
  voiceInputStart: 'Голосовой ввод',
52
54
  voiceInputStop: 'Остановить запись',
@@ -29,6 +29,48 @@ export function messageHasVisibleAssistantContent(
29
29
  return Boolean(message.content?.trim() || message.reasoningStream?.trim());
30
30
  }
31
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
+
32
74
  export function shouldShowChatPendingIndicator(
33
75
  isThinking: boolean,
34
76
  messages: SvedaChatMessageLike[]
@@ -46,5 +88,5 @@ export function shouldShowChatPendingIndicator(
46
88
  return true;
47
89
  }
48
90
 
49
- return !messageHasVisibleAssistantContent(lastMessage);
91
+ return !messageHasAssistantAnswerText(lastMessage);
50
92
  }
@@ -0,0 +1,31 @@
1
+ type ToolPart = {
2
+ type?: string;
3
+ toolCallId?: string;
4
+ confirmation?: string;
5
+ };
6
+
7
+ type ToolMessage = {
8
+ parts?: ToolPart[];
9
+ };
10
+
11
+ export function hasPendingToolConfirmation(messages: ToolMessage[] | null | undefined): boolean {
12
+ const resolved = new Set<string>();
13
+ for (const message of messages ?? []) {
14
+ for (const part of message.parts ?? []) {
15
+ if (part.type === 'tool-result' && part.toolCallId) {
16
+ resolved.add(part.toolCallId);
17
+ }
18
+ }
19
+ }
20
+
21
+ return (messages ?? []).some(message =>
22
+ (message.parts ?? []).some(
23
+ part =>
24
+ part.type === 'tool-call' &&
25
+ part.confirmation === 'required' &&
26
+ typeof part.toolCallId === 'string' &&
27
+ part.toolCallId !== '' &&
28
+ !resolved.has(part.toolCallId)
29
+ )
30
+ );
31
+ }
@@ -0,0 +1,96 @@
1
+ .sveda-chat .prose {
2
+ line-height: 1.55;
3
+ }
4
+
5
+ .sveda-chat .prose h1,
6
+ .sveda-chat .prose h2,
7
+ .sveda-chat .prose h3,
8
+ .sveda-chat .prose h4 {
9
+ color: inherit;
10
+ line-height: 1.3;
11
+ letter-spacing: -0.01em;
12
+ }
13
+
14
+ .sveda-chat .prose h1 {
15
+ font-size: 1.2rem;
16
+ font-weight: 700;
17
+ margin: 0.9em 0 0.35em;
18
+ }
19
+
20
+ .sveda-chat .prose h2 {
21
+ font-size: 1.08rem;
22
+ font-weight: 650;
23
+ margin: 0.85em 0 0.3em;
24
+ }
25
+
26
+ .sveda-chat .prose h3,
27
+ .sveda-chat .prose h4 {
28
+ font-size: 1rem;
29
+ font-weight: 600;
30
+ margin: 0.75em 0 0.25em;
31
+ }
32
+
33
+ .sveda-chat .prose h1:first-child,
34
+ .sveda-chat .prose h2:first-child,
35
+ .sveda-chat .prose h3:first-child,
36
+ .sveda-chat .prose h4:first-child {
37
+ margin-top: 0;
38
+ }
39
+
40
+ .sveda-chat .prose p {
41
+ margin: 0.45em 0;
42
+ }
43
+
44
+ .sveda-chat .prose p:first-child {
45
+ margin-top: 0;
46
+ }
47
+
48
+ .sveda-chat .prose p:last-child {
49
+ margin-bottom: 0;
50
+ }
51
+
52
+ .sveda-chat .prose ul,
53
+ .sveda-chat .prose ol {
54
+ margin: 0.4em 0;
55
+ padding-left: 1.25rem;
56
+ }
57
+
58
+ .sveda-chat .prose ul {
59
+ list-style-type: disc;
60
+ }
61
+
62
+ .sveda-chat .prose ol {
63
+ list-style-type: decimal;
64
+ }
65
+
66
+ .sveda-chat .prose li {
67
+ display: list-item;
68
+ margin: 0.2em 0;
69
+ }
70
+
71
+ .sveda-chat .prose li > p {
72
+ margin: 0.15em 0;
73
+ }
74
+
75
+ .sveda-chat .prose hr {
76
+ border: 0;
77
+ border-top: 1px solid hsl(var(--sveda-border));
78
+ margin: 0.9em 0;
79
+ }
80
+
81
+ .sveda-chat .prose a {
82
+ color: hsl(var(--sveda-brand));
83
+ text-decoration: underline;
84
+ text-underline-offset: 2px;
85
+ }
86
+
87
+ .sveda-chat .prose blockquote {
88
+ margin: 0.5em 0;
89
+ padding-left: 0.75rem;
90
+ border-left: 2px solid hsl(var(--sveda-border));
91
+ color: hsl(var(--sveda-muted-foreground));
92
+ }
93
+
94
+ .sveda-chat .prose strong {
95
+ font-weight: 650;
96
+ }
package/src/styles.css CHANGED
@@ -1,4 +1,5 @@
1
1
  @import './theme.css';
2
+ @import './markdown.css';
2
3
 
3
4
  @tailwind base;
4
5
  @tailwind components;