@budibase/frontend-core 3.23.37 → 3.23.38
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/package.json +2 -2
- package/src/api/agents.ts +15 -1
- package/src/components/Chatbox/index.svelte +22 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "3.23.
|
|
3
|
+
"version": "3.23.38",
|
|
4
4
|
"description": "Budibase frontend core libraries used in builder and client",
|
|
5
5
|
"author": "Budibase",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"shortid": "2.2.15",
|
|
19
19
|
"socket.io-client": "^4.7.5"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "83fecbd6e6b9e5f5d26369ce51d2173801925e3a"
|
|
22
22
|
}
|
package/src/api/agents.ts
CHANGED
|
@@ -40,6 +40,16 @@ export interface AgentEndpoints {
|
|
|
40
40
|
deleteAgent: (agentId: string) => Promise<{ deleted: true }>
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
const throwOnErrorChunk = () =>
|
|
44
|
+
new TransformStream<UIMessageChunk, UIMessageChunk>({
|
|
45
|
+
transform(chunk, controller) {
|
|
46
|
+
if (chunk.type === "error") {
|
|
47
|
+
throw new Error(chunk.errorText || "Agent action failed")
|
|
48
|
+
}
|
|
49
|
+
controller.enqueue(chunk)
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
|
|
43
53
|
export const buildAgentEndpoints = (API: BaseAPIClient): AgentEndpoints => ({
|
|
44
54
|
agentChatStream: async (chat, workspaceId) => {
|
|
45
55
|
const body: ChatAgentRequest = chat
|
|
@@ -69,8 +79,12 @@ export const buildAgentEndpoints = (API: BaseAPIClient): AgentEndpoints => ({
|
|
|
69
79
|
const chunkStream = response.body
|
|
70
80
|
.pipeThrough(new TextDecoderStream())
|
|
71
81
|
.pipeThrough(createSseToJsonTransformStream<UIMessageChunk>())
|
|
82
|
+
.pipeThrough(throwOnErrorChunk())
|
|
72
83
|
|
|
73
|
-
return readUIMessageStream({
|
|
84
|
+
return readUIMessageStream({
|
|
85
|
+
stream: chunkStream,
|
|
86
|
+
terminateOnError: true,
|
|
87
|
+
})
|
|
74
88
|
},
|
|
75
89
|
|
|
76
90
|
removeChat: async (chatId: string) => {
|
|
@@ -16,12 +16,16 @@
|
|
|
16
16
|
export let chat: AgentChat
|
|
17
17
|
export let loading: boolean = false
|
|
18
18
|
|
|
19
|
-
const dispatch = createEventDispatcher<{
|
|
19
|
+
const dispatch = createEventDispatcher<{
|
|
20
|
+
chatSaved: { chatId?: string; chat: AgentChat }
|
|
21
|
+
}>()
|
|
20
22
|
|
|
21
23
|
let inputValue = ""
|
|
22
24
|
let chatAreaElement: HTMLDivElement
|
|
23
25
|
let observer: MutationObserver
|
|
24
26
|
let textareaElement: HTMLTextAreaElement
|
|
27
|
+
let lastFocusedChatId: string | undefined
|
|
28
|
+
let lastFocusedNewChat: AgentChat | undefined
|
|
25
29
|
|
|
26
30
|
$: if (chat?.messages?.length) {
|
|
27
31
|
scrollToBottom()
|
|
@@ -75,7 +79,7 @@
|
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
loading = false
|
|
78
|
-
dispatch("chatSaved", { chatId: chat._id
|
|
82
|
+
dispatch("chatSaved", { chatId: chat._id, chat })
|
|
79
83
|
} catch (err: any) {
|
|
80
84
|
console.error(err)
|
|
81
85
|
notifications.error(err.message)
|
|
@@ -111,6 +115,22 @@
|
|
|
111
115
|
}
|
|
112
116
|
})
|
|
113
117
|
|
|
118
|
+
$: {
|
|
119
|
+
const currentId = chat?._id
|
|
120
|
+
const isNewChat =
|
|
121
|
+
!currentId && (!chat?.messages || chat.messages.length === 0)
|
|
122
|
+
const shouldFocus =
|
|
123
|
+
textareaElement &&
|
|
124
|
+
((currentId && currentId !== lastFocusedChatId) ||
|
|
125
|
+
(isNewChat && chat && chat !== lastFocusedNewChat))
|
|
126
|
+
|
|
127
|
+
if (shouldFocus) {
|
|
128
|
+
tick().then(() => textareaElement?.focus())
|
|
129
|
+
lastFocusedChatId = currentId
|
|
130
|
+
lastFocusedNewChat = isNewChat ? chat : undefined
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
114
134
|
onDestroy(() => {
|
|
115
135
|
observer.disconnect()
|
|
116
136
|
})
|