@meistrari/chat-nuxt 1.1.3 → 1.2.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.
- package/README.md +70 -4
- package/dist/module.d.mts +5 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +58 -19
- package/dist/runtime/components/chat/conversation-list.d.vue.ts +1 -0
- package/dist/runtime/components/chat/conversation-list.vue +22 -2
- package/dist/runtime/components/chat/conversation-list.vue.d.ts +1 -0
- package/dist/runtime/components/chat/message-list.d.vue.ts +1 -0
- package/dist/runtime/components/chat/message-list.vue +23 -2
- package/dist/runtime/components/chat/message-list.vue.d.ts +1 -0
- package/dist/runtime/composables/useChat.d.ts +2 -1
- package/dist/runtime/composables/useChat.js +32 -3
- package/dist/runtime/composables/useChatApi.js +2 -1
- package/dist/runtime/composables/useConversations.d.ts +3 -2
- package/dist/runtime/composables/useConversations.js +99 -11
- package/dist/runtime/composables/useEmbedConfig.d.ts +11 -6
- package/dist/runtime/composables/useEmbedConfig.js +35 -7
- package/dist/runtime/composables/useIDB.js +4 -0
- package/dist/runtime/composables/usePdf.d.ts +840 -1
- package/dist/runtime/composables/usePdf.js +21 -3
- package/dist/runtime/composables/useWorkspaceContextFiles.d.ts +3 -3
- package/dist/runtime/composables/useWorkspaceContextFiles.js +19 -10
- package/dist/runtime/composables/useWorkspaceExternalSkills.d.ts +1 -1
- package/dist/runtime/composables/useWorkspaceExternalSkills.js +5 -6
- package/dist/runtime/composables/useWorkspacePersonalization.d.ts +1 -1
- package/dist/runtime/composables/useWorkspacePersonalization.js +4 -5
- package/dist/runtime/composables/useWorkspaceSettings.js +11 -8
- package/dist/runtime/embed/components/ChatConfigurationModal.d.vue.ts +25 -0
- package/dist/runtime/embed/components/ChatConfigurationModal.vue +373 -0
- package/dist/runtime/embed/components/ChatConfigurationModal.vue.d.ts +25 -0
- package/dist/runtime/embed/components/ChatEmbed.vue +12 -1
- package/dist/runtime/embed/components/ChatEmbedInner.vue +31 -16
- package/dist/runtime/embed/components/configuration/ChatConfigurationContextFilesTab.d.vue.ts +22 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationContextFilesTab.vue +133 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationContextFilesTab.vue.d.ts +22 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationCredentialsTab.d.vue.ts +10 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationCredentialsTab.vue +220 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationCredentialsTab.vue.d.ts +10 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationExternalSkillsTab.d.vue.ts +32 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationExternalSkillsTab.vue +222 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationExternalSkillsTab.vue.d.ts +32 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationKnowledgeSourcesTab.d.vue.ts +18 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationKnowledgeSourcesTab.vue +142 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationKnowledgeSourcesTab.vue.d.ts +18 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationPersonalizationTab.d.vue.ts +10 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationPersonalizationTab.vue +37 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationPersonalizationTab.vue.d.ts +10 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationTelaToolsTab.d.vue.ts +20 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationTelaToolsTab.vue +146 -0
- package/dist/runtime/embed/components/configuration/ChatConfigurationTelaToolsTab.vue.d.ts +20 -0
- package/dist/runtime/server/api/conversations/[id]/duplicate.post.js +45 -12
- package/dist/runtime/types/chat.d.ts +2 -1
- package/dist/runtime/types/workspace-settings.d.ts +3 -0
- package/dist/runtime/types/workspace-settings.js +0 -0
- package/dist/runtime/utils/conversation-list-skeleton.d.ts +31 -0
- package/dist/runtime/utils/conversation-list-skeleton.js +12 -0
- package/dist/runtime/utils/file.js +42 -42
- package/dist/types.d.mts +2 -0
- package/package.json +23 -27
- package/dist/runtime/composables/PageNavigation.d.ts +0 -13
- package/dist/runtime/composables/PageNavigation.js +0 -18
- /package/dist/runtime/components/{pdf-preview.d.vue.ts → pdf-preview.client.d.vue.ts} +0 -0
- /package/dist/runtime/components/{pdf-preview.vue → pdf-preview.client.vue} +0 -0
- /package/dist/runtime/components/{pdf-preview.vue.d.ts → pdf-preview.client.vue.d.ts} +0 -0
- /package/dist/runtime/components/{pdf-viewer.d.vue.ts → pdf-viewer.client.d.vue.ts} +0 -0
- /package/dist/runtime/components/{pdf-viewer.vue → pdf-viewer.client.vue} +0 -0
- /package/dist/runtime/components/{pdf-viewer.vue.d.ts → pdf-viewer.client.vue.d.ts} +0 -0
|
@@ -1,11 +1,38 @@
|
|
|
1
1
|
import * as Sentry from "@sentry/nuxt";
|
|
2
|
+
function sortConversationsByUpdatedAt(conversations) {
|
|
3
|
+
return [...conversations].sort(
|
|
4
|
+
(a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
|
5
|
+
);
|
|
6
|
+
}
|
|
7
|
+
export function mergeFetchedConversations(fetchedConversations, localConversations, deletedConversationIds = [], locallyMutatedConversationIds = []) {
|
|
8
|
+
const deletedIds = new Set(deletedConversationIds);
|
|
9
|
+
const locallyMutatedIds = new Set(locallyMutatedConversationIds);
|
|
10
|
+
const mergedById = /* @__PURE__ */ new Map();
|
|
11
|
+
for (const conversation of fetchedConversations) {
|
|
12
|
+
if (!deletedIds.has(conversation.id)) {
|
|
13
|
+
mergedById.set(conversation.id, conversation);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
for (const conversation of localConversations) {
|
|
17
|
+
if (!deletedIds.has(conversation.id)) {
|
|
18
|
+
if (!mergedById.has(conversation.id) || locallyMutatedIds.has(conversation.id)) {
|
|
19
|
+
mergedById.set(conversation.id, conversation);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return sortConversationsByUpdatedAt([...mergedById.values()]);
|
|
24
|
+
}
|
|
2
25
|
export function useConversations() {
|
|
3
26
|
const chatApi = useChatApi();
|
|
4
27
|
const embedConfig = useEmbedConfig();
|
|
28
|
+
const { activeOrganization } = useTelaApplicationAuth();
|
|
5
29
|
const conversationBuckets = useState("conversations", () => ({}));
|
|
6
30
|
const loadingBuckets = useState("conversations-loading", () => ({}));
|
|
7
31
|
const errorBuckets = useState("conversations-error", () => ({}));
|
|
8
|
-
const
|
|
32
|
+
const mutationVersionBuckets = useState("conversations-mutation-version", () => ({}));
|
|
33
|
+
const deletedIdBuckets = useState("conversations-deleted-ids", () => ({}));
|
|
34
|
+
const mutatedIdBuckets = useState("conversations-mutated-ids", () => ({}));
|
|
35
|
+
const workspaceScope = computed(() => embedConfig?.workspaceId.value.trim() || activeOrganization.value?.id?.trim() || "default");
|
|
9
36
|
const conversations = computed({
|
|
10
37
|
get: () => conversationBuckets.value[workspaceScope.value] ?? [],
|
|
11
38
|
set: (value) => {
|
|
@@ -15,6 +42,33 @@ export function useConversations() {
|
|
|
15
42
|
};
|
|
16
43
|
}
|
|
17
44
|
});
|
|
45
|
+
const mutationVersion = computed({
|
|
46
|
+
get: () => mutationVersionBuckets.value[workspaceScope.value] ?? 0,
|
|
47
|
+
set: (value) => {
|
|
48
|
+
mutationVersionBuckets.value = {
|
|
49
|
+
...mutationVersionBuckets.value,
|
|
50
|
+
[workspaceScope.value]: value
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const deletedConversationIds = computed({
|
|
55
|
+
get: () => deletedIdBuckets.value[workspaceScope.value] ?? [],
|
|
56
|
+
set: (value) => {
|
|
57
|
+
deletedIdBuckets.value = {
|
|
58
|
+
...deletedIdBuckets.value,
|
|
59
|
+
[workspaceScope.value]: value
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const mutatedConversationIds = computed({
|
|
64
|
+
get: () => mutatedIdBuckets.value[workspaceScope.value] ?? [],
|
|
65
|
+
set: (value) => {
|
|
66
|
+
mutatedIdBuckets.value = {
|
|
67
|
+
...mutatedIdBuckets.value,
|
|
68
|
+
[workspaceScope.value]: value
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
});
|
|
18
72
|
const loading = computed({
|
|
19
73
|
get: () => loadingBuckets.value[workspaceScope.value] ?? false,
|
|
20
74
|
set: (value) => {
|
|
@@ -33,6 +87,28 @@ export function useConversations() {
|
|
|
33
87
|
};
|
|
34
88
|
}
|
|
35
89
|
});
|
|
90
|
+
function markMutated(id) {
|
|
91
|
+
mutationVersion.value = mutationVersion.value + 1;
|
|
92
|
+
if (id) {
|
|
93
|
+
mutatedConversationIds.value = [.../* @__PURE__ */ new Set([...mutatedConversationIds.value, id])];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function commitConversations(nextConversations, mutatedId) {
|
|
97
|
+
conversations.value = sortConversationsByUpdatedAt(nextConversations);
|
|
98
|
+
markMutated(mutatedId);
|
|
99
|
+
}
|
|
100
|
+
function addDeletedConversationId(id) {
|
|
101
|
+
deletedConversationIds.value = [.../* @__PURE__ */ new Set([...deletedConversationIds.value, id])];
|
|
102
|
+
markMutated();
|
|
103
|
+
}
|
|
104
|
+
function removeDeletedConversationId(id) {
|
|
105
|
+
deletedConversationIds.value = deletedConversationIds.value.filter((deletedId) => deletedId !== id);
|
|
106
|
+
markMutated();
|
|
107
|
+
}
|
|
108
|
+
function pruneDeletedConversationIds(serverConversations) {
|
|
109
|
+
const returnedIds = new Set(serverConversations.map((conversation) => conversation.id));
|
|
110
|
+
deletedConversationIds.value = deletedConversationIds.value.filter((id) => returnedIds.has(id));
|
|
111
|
+
}
|
|
36
112
|
function cloneAppliedSettingsSnapshot(snapshot) {
|
|
37
113
|
if (!snapshot)
|
|
38
114
|
return null;
|
|
@@ -41,12 +117,26 @@ export function useConversations() {
|
|
|
41
117
|
const fetchConversations = async () => {
|
|
42
118
|
loading.value = true;
|
|
43
119
|
error.value = null;
|
|
120
|
+
const mutationVersionAtStart = mutationVersion.value;
|
|
44
121
|
try {
|
|
45
122
|
const data = await $fetch(
|
|
46
123
|
chatApi.path("/conversations"),
|
|
47
124
|
chatApi.withChatHeaders()
|
|
48
125
|
);
|
|
49
|
-
|
|
126
|
+
const visibleData = data.filter((conversation) => !deletedConversationIds.value.includes(conversation.id));
|
|
127
|
+
if (mutationVersion.value === mutationVersionAtStart) {
|
|
128
|
+
conversations.value = sortConversationsByUpdatedAt(visibleData);
|
|
129
|
+
mutatedConversationIds.value = [];
|
|
130
|
+
} else {
|
|
131
|
+
conversations.value = mergeFetchedConversations(
|
|
132
|
+
visibleData,
|
|
133
|
+
conversations.value,
|
|
134
|
+
deletedConversationIds.value,
|
|
135
|
+
mutatedConversationIds.value
|
|
136
|
+
);
|
|
137
|
+
mutatedConversationIds.value = [];
|
|
138
|
+
}
|
|
139
|
+
pruneDeletedConversationIds(data);
|
|
50
140
|
} catch (err) {
|
|
51
141
|
const message = err instanceof Error ? err.message : "Erro ao carregar conversas";
|
|
52
142
|
error.value = message;
|
|
@@ -65,7 +155,7 @@ export function useConversations() {
|
|
|
65
155
|
body: options?.model ? { model: options.model } : void 0
|
|
66
156
|
})
|
|
67
157
|
);
|
|
68
|
-
|
|
158
|
+
commitConversations([conversation, ...conversations.value], conversation.id);
|
|
69
159
|
return conversation;
|
|
70
160
|
} catch (err) {
|
|
71
161
|
const message = err instanceof Error ? err.message : "Erro ao criar conversa";
|
|
@@ -77,7 +167,8 @@ export function useConversations() {
|
|
|
77
167
|
error.value = null;
|
|
78
168
|
const statusToast = useStatusToast();
|
|
79
169
|
const deletedConversation = conversations.value.find((c) => c.id === id);
|
|
80
|
-
|
|
170
|
+
addDeletedConversationId(id);
|
|
171
|
+
commitConversations(conversations.value.filter((c) => c.id !== id), id);
|
|
81
172
|
try {
|
|
82
173
|
await $fetch(
|
|
83
174
|
chatApi.path(`/conversations/${id}`),
|
|
@@ -91,10 +182,9 @@ export function useConversations() {
|
|
|
91
182
|
});
|
|
92
183
|
return true;
|
|
93
184
|
} catch (err) {
|
|
185
|
+
removeDeletedConversationId(id);
|
|
94
186
|
if (deletedConversation) {
|
|
95
|
-
|
|
96
|
-
(a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
|
97
|
-
);
|
|
187
|
+
commitConversations([...conversations.value, deletedConversation], deletedConversation.id);
|
|
98
188
|
}
|
|
99
189
|
const message = err instanceof Error ? err.message : "Erro ao deletar conversa";
|
|
100
190
|
error.value = message;
|
|
@@ -122,9 +212,7 @@ export function useConversations() {
|
|
|
122
212
|
createdAt: updated.createdAt,
|
|
123
213
|
updatedAt: updated.updatedAt
|
|
124
214
|
};
|
|
125
|
-
|
|
126
|
-
(a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
|
127
|
-
);
|
|
215
|
+
commitConversations(nextConversations, updated.id);
|
|
128
216
|
}
|
|
129
217
|
};
|
|
130
218
|
const renameConversation = async (id, title) => {
|
|
@@ -161,7 +249,7 @@ export function useConversations() {
|
|
|
161
249
|
method: "POST"
|
|
162
250
|
})
|
|
163
251
|
);
|
|
164
|
-
|
|
252
|
+
commitConversations([duplicated, ...conversations.value], duplicated.id);
|
|
165
253
|
statusToast.update({
|
|
166
254
|
text: "Conversa duplicada",
|
|
167
255
|
icon: "i-ph-check"
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import type { DeepReadonly, Ref } from 'vue';
|
|
1
|
+
import type { DeepReadonly, MaybeRefOrGetter, Ref } from 'vue';
|
|
2
2
|
import type { WorkspaceSettings } from './useWorkspaceSettings.js';
|
|
3
3
|
export type EmbedConfig = {
|
|
4
4
|
workspaceId: Ref<string>;
|
|
5
5
|
workspaceSettings: Ref<DeepReadonly<WorkspaceSettings> | WorkspaceSettings | null | undefined>;
|
|
6
6
|
hideSidebar: Ref<boolean>;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
workspaceId: string
|
|
10
|
-
workspaceSettings?: DeepReadonly<WorkspaceSettings> | WorkspaceSettings | null
|
|
11
|
-
hideSidebar?: boolean
|
|
12
|
-
}
|
|
8
|
+
type EmbedConfigInput = {
|
|
9
|
+
workspaceId: MaybeRefOrGetter<string>;
|
|
10
|
+
workspaceSettings?: MaybeRefOrGetter<DeepReadonly<WorkspaceSettings> | WorkspaceSettings | null | undefined>;
|
|
11
|
+
hideSidebar?: MaybeRefOrGetter<boolean | undefined>;
|
|
12
|
+
};
|
|
13
|
+
type ProvideEmbedConfigOptions = {
|
|
14
|
+
syncGlobal?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function provideEmbedConfig(input: EmbedConfigInput, options?: ProvideEmbedConfigOptions): void;
|
|
13
17
|
export declare function useEmbedConfig(): EmbedConfig | null;
|
|
18
|
+
export {};
|
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
const EMBED_CONFIG_KEY = "embed-config";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
function useGlobalEmbedConfigState() {
|
|
3
|
+
return {
|
|
4
|
+
provided: useState("chat-embed-config-provided", () => false),
|
|
5
|
+
workspaceId: useState("chat-embed-config-workspace-id", () => ""),
|
|
6
|
+
workspaceSettings: useState("chat-embed-config-workspace-settings", () => void 0),
|
|
7
|
+
hideSidebar: useState("chat-embed-config-hide-sidebar", () => void 0)
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function provideEmbedConfig(input, options = {}) {
|
|
11
|
+
const config = {
|
|
12
|
+
workspaceId: computed(() => toValue(input.workspaceId)),
|
|
13
|
+
workspaceSettings: computed(() => toValue(input.workspaceSettings)),
|
|
14
|
+
hideSidebar: computed(() => toValue(input.hideSidebar) ?? true)
|
|
15
|
+
};
|
|
16
|
+
const globalConfig = useGlobalEmbedConfigState();
|
|
17
|
+
if (options.syncGlobal ?? true) {
|
|
18
|
+
watchEffect(() => {
|
|
19
|
+
globalConfig.provided.value = true;
|
|
20
|
+
globalConfig.workspaceId.value = config.workspaceId.value;
|
|
21
|
+
globalConfig.workspaceSettings.value = config.workspaceSettings.value;
|
|
22
|
+
globalConfig.hideSidebar.value = config.hideSidebar.value;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
provide(EMBED_CONFIG_KEY, config);
|
|
8
26
|
}
|
|
9
27
|
export function useEmbedConfig() {
|
|
10
|
-
|
|
28
|
+
const injectedConfig = inject(EMBED_CONFIG_KEY, null);
|
|
29
|
+
if (injectedConfig)
|
|
30
|
+
return injectedConfig;
|
|
31
|
+
const globalConfig = useGlobalEmbedConfigState();
|
|
32
|
+
if (!globalConfig.provided.value)
|
|
33
|
+
return null;
|
|
34
|
+
return {
|
|
35
|
+
workspaceId: computed(() => globalConfig.workspaceId.value),
|
|
36
|
+
workspaceSettings: computed(() => globalConfig.workspaceSettings.value),
|
|
37
|
+
hideSidebar: computed(() => globalConfig.hideSidebar.value ?? true)
|
|
38
|
+
};
|
|
11
39
|
}
|
|
@@ -2,6 +2,8 @@ export function useIDB(options) {
|
|
|
2
2
|
const { dbName = "tela", storeName, version } = options;
|
|
3
3
|
let dbInstance = null;
|
|
4
4
|
async function setup() {
|
|
5
|
+
if (!import.meta.client)
|
|
6
|
+
return null;
|
|
5
7
|
if (dbInstance)
|
|
6
8
|
return dbInstance;
|
|
7
9
|
return new Promise((resolve, reject) => {
|
|
@@ -36,6 +38,8 @@ export function useIDB(options) {
|
|
|
36
38
|
}
|
|
37
39
|
async function withStore(mode, callback) {
|
|
38
40
|
const db = await setup();
|
|
41
|
+
if (!db)
|
|
42
|
+
return null;
|
|
39
43
|
return new Promise((resolve, reject) => {
|
|
40
44
|
const transaction = db.transaction(storeName, mode);
|
|
41
45
|
const store = transaction.objectStore(storeName);
|