@meistrari/chat-nuxt 1.2.1 → 1.2.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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meistrari/chat-nuxt",
3
3
  "configKey": "chatNuxt",
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -1,6 +1,6 @@
1
1
  import * as Sentry from "@sentry/nuxt";
2
2
  import { exportConversationToMarkdown } from "../utils/export-conversation.js";
3
- import { addFilesToConversation } from "./useConversationFiles.js";
3
+ import { useConversationFileActions } from "./useConversationFiles.js";
4
4
  function getStepKey(step) {
5
5
  if (typeof step === "string") {
6
6
  return `text:${step.slice(0, 100)}`;
@@ -146,6 +146,7 @@ export function useChat() {
146
146
  const chatApi = useChatApi();
147
147
  const embedConfig = useEmbedConfig();
148
148
  const { user: authUser, activeOrganization } = useTelaApplicationAuth();
149
+ const { addFilesToConversation } = useConversationFileActions();
149
150
  const chatScope = computed(() => embedConfig?.workspaceId.value.trim() || activeOrganization.value?.id?.trim() || "default");
150
151
  const currentConversationBuckets = useState("chat-current-conversation", () => ({}));
151
152
  const messageBuckets = useState("chat-messages", () => ({}));
@@ -1,5 +1,8 @@
1
1
  import type { MessageFile, MessageRole } from '../types/chat.js';
2
2
  export declare function addFilesToConversation(conversationId: string, newFiles: MessageFile[], messageId: string, messageRole: MessageRole): void;
3
+ export declare function useConversationFileActions(): {
4
+ addFilesToConversation: (conversationId: string, newFiles: MessageFile[], messageId: string, messageRole: MessageRole) => void;
5
+ };
3
6
  export declare function useConversationFiles(conversationId: Ref<string | null | undefined>): {
4
7
  files: any;
5
8
  total: any;
@@ -1,9 +1,13 @@
1
1
  import { generateFileId } from "../utils/file.js";
2
- const sharedFiles = useState("conversationFiles", () => ({}));
3
- const sharedLoading = useState("conversationFilesLoading", () => ({}));
4
- const sharedError = useState("conversationFilesError", () => ({}));
5
- export function addFilesToConversation(conversationId, newFiles, messageId, messageRole) {
6
- const current = sharedFiles.value[conversationId] ?? [];
2
+ function useConversationFilesState() {
3
+ return {
4
+ files: useState("conversationFiles", () => ({})),
5
+ loading: useState("conversationFilesLoading", () => ({})),
6
+ error: useState("conversationFilesError", () => ({}))
7
+ };
8
+ }
9
+ function addFilesToConversationState(state, conversationId, newFiles, messageId, messageRole) {
10
+ const current = state.files.value[conversationId] ?? [];
7
11
  const filesToAdd = newFiles.filter((f) => !current.some((existing) => existing.url === f.url)).map((f) => ({
8
12
  id: generateFileId(f.url),
9
13
  url: f.url,
@@ -16,26 +20,36 @@ export function addFilesToConversation(conversationId, newFiles, messageId, mess
16
20
  size: f.size
17
21
  }));
18
22
  if (filesToAdd.length > 0) {
19
- sharedFiles.value = {
20
- ...sharedFiles.value,
23
+ state.files.value = {
24
+ ...state.files.value,
21
25
  [conversationId]: [...filesToAdd, ...current]
22
26
  };
23
27
  }
24
28
  }
29
+ export function addFilesToConversation(conversationId, newFiles, messageId, messageRole) {
30
+ addFilesToConversationState(useConversationFilesState(), conversationId, newFiles, messageId, messageRole);
31
+ }
32
+ export function useConversationFileActions() {
33
+ const state = useConversationFilesState();
34
+ return {
35
+ addFilesToConversation: (conversationId, newFiles, messageId, messageRole) => addFilesToConversationState(state, conversationId, newFiles, messageId, messageRole)
36
+ };
37
+ }
25
38
  export function useConversationFiles(conversationId) {
26
39
  const chatApi = useChatApi();
40
+ const state = useConversationFilesState();
27
41
  const files = computed(() => {
28
42
  const id = conversationId.value;
29
- return id ? sharedFiles.value[id] ?? [] : [];
43
+ return id ? state.files.value[id] ?? [] : [];
30
44
  });
31
45
  const total = computed(() => files.value.length);
32
46
  const loading = computed(() => {
33
47
  const id = conversationId.value;
34
- return id ? sharedLoading.value[id] ?? false : false;
48
+ return id ? state.loading.value[id] ?? false : false;
35
49
  });
36
50
  const error = computed(() => {
37
51
  const id = conversationId.value;
38
- return id ? sharedError.value[id] ?? null : null;
52
+ return id ? state.error.value[id] ?? null : null;
39
53
  });
40
54
  let currentFetchId = 0;
41
55
  async function fetchFiles() {
@@ -43,27 +57,27 @@ export function useConversationFiles(conversationId) {
43
57
  if (!id)
44
58
  return;
45
59
  const fetchId = ++currentFetchId;
46
- sharedLoading.value = { ...sharedLoading.value, [id]: true };
47
- sharedError.value = { ...sharedError.value, [id]: null };
60
+ state.loading.value = { ...state.loading.value, [id]: true };
61
+ state.error.value = { ...state.error.value, [id]: null };
48
62
  try {
49
63
  const response = await $fetch(
50
64
  chatApi.path(`/conversations/${id}/files`),
51
65
  chatApi.withChatHeaders()
52
66
  );
53
67
  if (fetchId === currentFetchId) {
54
- sharedFiles.value = { ...sharedFiles.value, [id]: response.files };
68
+ state.files.value = { ...state.files.value, [id]: response.files };
55
69
  }
56
70
  } catch (err) {
57
71
  if (fetchId === currentFetchId) {
58
- sharedError.value = {
59
- ...sharedError.value,
72
+ state.error.value = {
73
+ ...state.error.value,
60
74
  [id]: err instanceof Error ? err.message : "Falha ao buscar arquivos"
61
75
  };
62
- sharedFiles.value = { ...sharedFiles.value, [id]: [] };
76
+ state.files.value = { ...state.files.value, [id]: [] };
63
77
  }
64
78
  } finally {
65
79
  if (fetchId === currentFetchId) {
66
- sharedLoading.value = { ...sharedLoading.value, [id]: false };
80
+ state.loading.value = { ...state.loading.value, [id]: false };
67
81
  }
68
82
  }
69
83
  }
@@ -1,5 +1,5 @@
1
- const knowledgeSources = useState("knowledgeSources", () => []);
2
1
  export function useKnowledgeSources() {
2
+ const knowledgeSources = useState("knowledgeSources", () => []);
3
3
  function setKnowledgeSources(sources) {
4
4
  knowledgeSources.value = sources ?? [];
5
5
  }
@@ -1,11 +1,16 @@
1
- const mediaCache = useIDB({
2
- storeName: "vault-media-cache",
3
- version: 2
4
- });
1
+ let mediaCache = null;
2
+ function getMediaCache() {
3
+ mediaCache ??= useIDB({
4
+ storeName: "vault-media-cache",
5
+ version: 2
6
+ });
7
+ return mediaCache;
8
+ }
5
9
  export function useMediaCache() {
10
+ const mediaCache2 = getMediaCache();
6
11
  async function getCached(cacheKey) {
7
12
  try {
8
- const cachedData = await mediaCache.get(cacheKey);
13
+ const cachedData = await mediaCache2.get(cacheKey);
9
14
  if (cachedData)
10
15
  return cachedData;
11
16
  return null;
@@ -15,13 +20,13 @@ export function useMediaCache() {
15
20
  }
16
21
  async function setCache(cacheKey, base64) {
17
22
  try {
18
- await mediaCache.set(cacheKey, base64);
23
+ await mediaCache2.set(cacheKey, base64);
19
24
  } catch {
20
25
  }
21
26
  }
22
27
  async function removeFromCache(cacheKey) {
23
28
  try {
24
- await mediaCache.remove(cacheKey);
29
+ await mediaCache2.remove(cacheKey);
25
30
  } catch {
26
31
  }
27
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/chat-nuxt",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {