@sveda-ai/vue 0.2.4 → 0.3.1

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 (47) 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.d.ts +1 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +3350 -3223
  21. package/dist/lib/assistantMessage.d.ts +1 -0
  22. package/dist/lib/assistantMessage.d.ts.map +1 -1
  23. package/dist/lib/toolConfirmation.d.ts +11 -0
  24. package/dist/lib/toolConfirmation.d.ts.map +1 -0
  25. package/dist/plugin.d.ts +1 -0
  26. package/dist/plugin.d.ts.map +1 -1
  27. package/dist/styles.css +1 -1
  28. package/dist/vue.css +1 -1
  29. package/package.json +9 -2
  30. package/src/components/chat/AnimatedStreamBlock.vue +12 -10
  31. package/src/components/chat/ChatInput.vue +13 -5
  32. package/src/components/chat/ChatMessageActivityBlock.vue +64 -7
  33. package/src/components/chat/ChatMessageItem.vue +2 -0
  34. package/src/components/chat/ChatMessageList.vue +2 -0
  35. package/src/components/shell/SvedaChat.vue +10 -1
  36. package/src/components/shell/SvedaInputSection.vue +2 -0
  37. package/src/components/shell/SvedaLandingView.vue +3 -1
  38. package/src/composables/useSvedaChat.ts +27 -6
  39. package/src/composables/useSvedaChatPage.ts +8 -0
  40. package/src/composables/useSvedaMessaging.ts +3 -2
  41. package/src/composables/useSvedaStreaming.ts +23 -0
  42. package/src/i18n/locales/en.ts +3 -0
  43. package/src/i18n/locales/ru.ts +3 -0
  44. package/src/index.ts +1 -0
  45. package/src/lib/assistantMessage.ts +2 -0
  46. package/src/lib/toolConfirmation.ts +31 -0
  47. package/src/plugin.ts +2 -0
@@ -176,6 +176,7 @@
176
176
  v-model:thinking-enabled="chat.thinkingEnabled"
177
177
  v-model:pending-files="chat.pendingChatFiles"
178
178
  :is-loading="chat.isLoading || chat.isLoadingChatHistory"
179
+ :confirmation-pending="chat.confirmationPending"
179
180
  :has-current-chat="chat.hasCurrentChat"
180
181
  :is-streaming="chat.isStreaming"
181
182
  :context-window-usage-percent="chat.contextWindowUsagePercent"
@@ -208,6 +209,8 @@
208
209
  class="mb-4 max-h-[30vh] flex-none"
209
210
  @near-bottom-change="chat.handleMessagesNearBottomChange"
210
211
  @activity-link-click="chat.handleActivityLinkClick"
212
+ @confirm-tool="chat.resolveToolConfirmation($event, 'approve')"
213
+ @deny-tool="chat.resolveToolConfirmation($event, 'deny')"
211
214
  />
212
215
  </template>
213
216
  </SvedaLandingView>
@@ -232,6 +235,8 @@
232
235
  :thinking-message="chat.thinkingMessage"
233
236
  @near-bottom-change="chat.handleMessagesNearBottomChange"
234
237
  @activity-link-click="chat.handleActivityLinkClick"
238
+ @confirm-tool="chat.resolveToolConfirmation($event, 'approve')"
239
+ @deny-tool="chat.resolveToolConfirmation($event, 'deny')"
235
240
  />
236
241
  <SvedaMaxStepsNotice
237
242
  v-if="chat.showMaxStepsContinueNotice"
@@ -251,6 +256,7 @@
251
256
  v-model:selected-chat-model="chat.selectedChatModel"
252
257
  v-model:thinking-enabled="chat.thinkingEnabled"
253
258
  :is-loading="chat.isLoading || chat.isLoadingChatHistory"
259
+ :confirmation-pending="chat.confirmationPending"
254
260
  :has-current-chat="chat.hasCurrentChat"
255
261
  :is-streaming="chat.isStreaming"
256
262
  :status-banner="chat.chatInputStatusBanner"
@@ -351,6 +357,8 @@
351
357
  :thinking-message="chat.thinkingMessage"
352
358
  @near-bottom-change="chat.handleMessagesNearBottomChange"
353
359
  @activity-link-click="chat.handleActivityLinkClick"
360
+ @confirm-tool="chat.resolveToolConfirmation($event, 'approve')"
361
+ @deny-tool="chat.resolveToolConfirmation($event, 'deny')"
354
362
  />
355
363
  <SvedaMaxStepsNotice
356
364
  v-if="chat.showMaxStepsContinueNotice"
@@ -369,7 +377,7 @@
369
377
  class="shrink-0 px-4 pb-1 pt-0"
370
378
  :prompts="chat.quickPromptButtons"
371
379
  :title="chat.t('quickPromptsTitle')"
372
- :disabled="chat.isLoading || chat.isStreaming"
380
+ :disabled="chat.isLoading || chat.isStreaming || chat.confirmationPending"
373
381
  @select="chat.sendQuickPrompt"
374
382
  />
375
383
  <SvedaInputSection
@@ -378,6 +386,7 @@
378
386
  v-model:selected-chat-model="chat.selectedChatModel"
379
387
  v-model:thinking-enabled="chat.thinkingEnabled"
380
388
  :is-loading="chat.isLoading || chat.isLoadingChatHistory"
389
+ :confirmation-pending="chat.confirmationPending"
381
390
  :has-current-chat="chat.hasCurrentChat"
382
391
  :is-streaming="chat.isStreaming"
383
392
  :status-banner="chat.chatInputStatusBanner"
@@ -10,6 +10,7 @@
10
10
 
11
11
  defineProps({
12
12
  isLoading: { type: Boolean, default: false },
13
+ confirmationPending: { type: Boolean, default: false },
13
14
  hasCurrentChat: { type: Boolean, default: false },
14
15
  isStreaming: { type: Boolean, default: false },
15
16
  statusBanner: { type: String, default: '' },
@@ -28,6 +29,7 @@
28
29
  v-model="inputMessage"
29
30
  v-model:pending-files="pendingFiles"
30
31
  :is-loading="isLoading"
32
+ :confirmation-pending="confirmationPending"
31
33
  :has-current-chat="hasCurrentChat"
32
34
  :is-streaming="isStreaming"
33
35
  :status-banner="statusBanner"
@@ -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>
@@ -17,7 +17,7 @@ import {
17
17
  type SvedaFinalizableMessage,
18
18
  } from '../lib/finalizeMessages';
19
19
  import { getUserMessageAttachmentNames, getUserMessageText } from '../lib/userMessage';
20
- import { SvedaClientKey } from '../plugin';
20
+ import { SvedaClientKey, SVEDA_EMBED_AUTH_EVENT } from '../plugin';
21
21
 
22
22
  export interface SvedaChatHistory {
23
23
  id: string;
@@ -135,8 +135,22 @@ const mapServerHistory = (
135
135
 
136
136
  const historiesEndpointConfigured = (): boolean => Boolean(activeClient?.endpoints.histories);
137
137
 
138
+ const embedAuthReady = (): boolean => {
139
+ if (!activeClient || activeClient.credentials !== 'omit') {
140
+ return true;
141
+ }
142
+
143
+ const headers = activeClient.resolveHeaders();
144
+ return Boolean(
145
+ headers['X-Sveda-Embed-Token'] ||
146
+ headers['x-sveda-embed-token'] ||
147
+ headers.Authorization ||
148
+ headers.authorization,
149
+ );
150
+ };
151
+
138
152
  const fetchHistoriesFromServer = async (): Promise<SvedaChatHistory[]> => {
139
- if (!activeClient || !historiesEndpointConfigured()) {
153
+ if (!activeClient || !historiesEndpointConfigured() || !embedAuthReady()) {
140
154
  return [];
141
155
  }
142
156
 
@@ -150,7 +164,7 @@ const fetchHistoriesFromServer = async (): Promise<SvedaChatHistory[]> => {
150
164
  };
151
165
 
152
166
  const fetchChatHistoryFromServer = async (chatId: string): Promise<SvedaChatHistory | null> => {
153
- if (!activeClient || !historiesEndpointConfigured()) {
167
+ if (!activeClient || !historiesEndpointConfigured() || !embedAuthReady()) {
154
168
  return null;
155
169
  }
156
170
 
@@ -164,7 +178,7 @@ const fetchChatHistoryFromServer = async (chatId: string): Promise<SvedaChatHist
164
178
  };
165
179
 
166
180
  const deleteChatOnServer = async (chatId: string) => {
167
- if (!activeClient || !historiesEndpointConfigured()) {
181
+ if (!activeClient || !historiesEndpointConfigured() || !embedAuthReady()) {
168
182
  return;
169
183
  }
170
184
 
@@ -176,7 +190,7 @@ const deleteChatOnServer = async (chatId: string) => {
176
190
  };
177
191
 
178
192
  const renameChatOnServer = async (chatId: string, title: string) => {
179
- if (!activeClient || !historiesEndpointConfigured()) {
193
+ if (!activeClient || !historiesEndpointConfigured() || !embedAuthReady()) {
180
194
  return;
181
195
  }
182
196
 
@@ -452,7 +466,14 @@ export const useSvedaChat = () => {
452
466
 
453
467
  if (!initialized) {
454
468
  initialized = true;
455
- if (historiesEndpointConfigured()) {
469
+ if (typeof window !== 'undefined') {
470
+ window.addEventListener(SVEDA_EMBED_AUTH_EVENT, () => {
471
+ if (historiesEndpointConfigured() && embedAuthReady()) {
472
+ void loadHistories();
473
+ }
474
+ });
475
+ }
476
+ if (historiesEndpointConfigured() && embedAuthReady()) {
456
477
  void loadHistories();
457
478
  }
458
479
  }
@@ -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,
@@ -56,6 +56,9 @@ const en: SvedaMessages = {
56
56
  commonError: 'Error',
57
57
  'tools.web_search': 'Search the web',
58
58
  'tools.web_fetch': 'Read page',
59
+ toolConfirmationPrompt: 'This action needs your confirmation before it runs.',
60
+ toolConfirm: 'Confirm',
61
+ toolDeny: 'Deny',
59
62
  };
60
63
 
61
64
  export default en;
@@ -57,6 +57,9 @@ const ru: SvedaMessages = {
57
57
  commonError: 'Ошибка',
58
58
  'tools.web_search': 'Поиск в интернете',
59
59
  'tools.web_fetch': 'Чтение страницы',
60
+ toolConfirmationPrompt: 'Это действие выполнится только после вашего подтверждения.',
61
+ toolConfirm: 'Подтвердить',
62
+ toolDeny: 'Отказать',
60
63
  };
61
64
 
62
65
  export default ru;
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export {
11
11
  SvedaFillHostKey,
12
12
  SvedaHideLauncherKey,
13
13
  SvedaBeforeSendKey,
14
+ SVEDA_EMBED_AUTH_EVENT,
14
15
  } from './plugin';
15
16
  export type {
16
17
  SvedaPluginOptions,
@@ -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
  }
@@ -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
+ }
package/src/plugin.ts CHANGED
@@ -84,6 +84,8 @@ export const SvedaHideLauncherKey: InjectionKey<boolean> = Symbol('sveda-hide-la
84
84
 
85
85
  export const SvedaBeforeSendKey: InjectionKey<SvedaBeforeSend | null> = Symbol('sveda-before-send');
86
86
 
87
+ export const SVEDA_EMBED_AUTH_EVENT = 'sveda-embed-auth';
88
+
87
89
  const DEFAULT_CONFIG: SvedaConfig = {
88
90
  brand: { name: 'Sveda', logoUrl: null },
89
91
  models: [],