@budibase/frontend-core 3.30.5 → 3.31.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/package.json +2 -2
- package/src/api/agents.ts +16 -0
- package/src/api/ai.ts +81 -2
- package/src/components/Chatbox/index.svelte +14 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.31.0",
|
|
4
4
|
"description": "Budibase frontend core libraries used in builder and client",
|
|
5
5
|
"author": "Budibase",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"vitest": "^3.2.4"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "1a410a1809b5010ddf7055fc7f240aa38c6ed3ef"
|
|
28
28
|
}
|
package/src/api/agents.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
DuplicateAgentResponse,
|
|
6
6
|
FetchAgentFilesResponse,
|
|
7
7
|
FetchAgentsResponse,
|
|
8
|
+
ProvisionAgentMSTeamsChannelRequest,
|
|
9
|
+
ProvisionAgentMSTeamsChannelResponse,
|
|
8
10
|
SyncAgentDiscordCommandsRequest,
|
|
9
11
|
SyncAgentDiscordCommandsResponse,
|
|
10
12
|
ToggleAgentDiscordRequest,
|
|
@@ -36,6 +38,10 @@ export interface AgentEndpoints {
|
|
|
36
38
|
agentId: string,
|
|
37
39
|
body?: SyncAgentDiscordCommandsRequest
|
|
38
40
|
) => Promise<SyncAgentDiscordCommandsResponse>
|
|
41
|
+
provisionAgentMSTeamsChannel: (
|
|
42
|
+
agentId: string,
|
|
43
|
+
body?: ProvisionAgentMSTeamsChannelRequest
|
|
44
|
+
) => Promise<ProvisionAgentMSTeamsChannelResponse>
|
|
39
45
|
toggleAgentDiscordDeployment: (
|
|
40
46
|
agentId: string,
|
|
41
47
|
enabled: boolean
|
|
@@ -115,6 +121,16 @@ export const buildAgentEndpoints = (API: BaseAPIClient): AgentEndpoints => ({
|
|
|
115
121
|
})
|
|
116
122
|
},
|
|
117
123
|
|
|
124
|
+
provisionAgentMSTeamsChannel: async (agentId: string, body) => {
|
|
125
|
+
return await API.post<
|
|
126
|
+
ProvisionAgentMSTeamsChannelRequest | undefined,
|
|
127
|
+
ProvisionAgentMSTeamsChannelResponse
|
|
128
|
+
>({
|
|
129
|
+
url: `/api/agent/${agentId}/ms-teams/provision`,
|
|
130
|
+
body,
|
|
131
|
+
})
|
|
132
|
+
},
|
|
133
|
+
|
|
118
134
|
toggleAgentDiscordDeployment: async (agentId: string, enabled: boolean) => {
|
|
119
135
|
return await API.post<
|
|
120
136
|
ToggleAgentDiscordRequest,
|
package/src/api/ai.ts
CHANGED
|
@@ -6,11 +6,43 @@ import {
|
|
|
6
6
|
} from "@budibase/types"
|
|
7
7
|
import { BaseAPIClient } from "./types"
|
|
8
8
|
|
|
9
|
+
const SSE_EVENT_DELIMITER = "\n\n"
|
|
10
|
+
const SSE_DATA_PREFIX = "data:"
|
|
11
|
+
|
|
12
|
+
type TablesStreamEvent =
|
|
13
|
+
| {
|
|
14
|
+
type: "progress"
|
|
15
|
+
message: string
|
|
16
|
+
}
|
|
17
|
+
| {
|
|
18
|
+
type: "result"
|
|
19
|
+
createdTables?: GenerateTablesResponse["createdTables"]
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
type: "error"
|
|
23
|
+
message?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const parseSSEEventChunk = (chunk: string): TablesStreamEvent | null => {
|
|
27
|
+
const dataLines = chunk
|
|
28
|
+
.split("\n")
|
|
29
|
+
.map(line => line.trimEnd())
|
|
30
|
+
.filter(line => line.startsWith(SSE_DATA_PREFIX))
|
|
31
|
+
.map(line => line.slice(SSE_DATA_PREFIX.length).trim())
|
|
32
|
+
|
|
33
|
+
if (dataLines.length === 0) {
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return JSON.parse(dataLines.join("\n")) as TablesStreamEvent
|
|
38
|
+
}
|
|
39
|
+
|
|
9
40
|
export interface AIEndpoints {
|
|
10
41
|
generateCronExpression: (prompt: string) => Promise<{ message: string }>
|
|
11
42
|
generateJs: (req: GenerateJsRequest) => Promise<GenerateJsResponse>
|
|
12
43
|
generateTables: (
|
|
13
|
-
req: GenerateTablesRequest
|
|
44
|
+
req: GenerateTablesRequest,
|
|
45
|
+
onProgress?: (message: string) => void
|
|
14
46
|
) => Promise<GenerateTablesResponse>
|
|
15
47
|
}
|
|
16
48
|
|
|
@@ -32,10 +64,57 @@ export const buildAIEndpoints = (API: BaseAPIClient): AIEndpoints => ({
|
|
|
32
64
|
})
|
|
33
65
|
},
|
|
34
66
|
|
|
35
|
-
generateTables: async req => {
|
|
67
|
+
generateTables: async (req, onProgress) => {
|
|
36
68
|
return await API.post({
|
|
37
69
|
url: "/api/ai/tables",
|
|
38
70
|
body: req,
|
|
71
|
+
parseResponse: async response => {
|
|
72
|
+
try {
|
|
73
|
+
const reader = response.body?.getReader()
|
|
74
|
+
if (!reader) {
|
|
75
|
+
throw new Error("Streaming not supported in this browser")
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const decoder = new TextDecoder()
|
|
79
|
+
let buffer = ""
|
|
80
|
+
let finalResponse: GenerateTablesResponse | undefined
|
|
81
|
+
|
|
82
|
+
while (true) {
|
|
83
|
+
const { done, value } = await reader.read()
|
|
84
|
+
if (done) {
|
|
85
|
+
break
|
|
86
|
+
}
|
|
87
|
+
buffer += decoder.decode(value, { stream: true })
|
|
88
|
+
|
|
89
|
+
let boundary = buffer.indexOf(SSE_EVENT_DELIMITER)
|
|
90
|
+
while (boundary !== -1) {
|
|
91
|
+
const eventChunk = buffer.slice(0, boundary)
|
|
92
|
+
buffer = buffer.slice(boundary + SSE_EVENT_DELIMITER.length)
|
|
93
|
+
|
|
94
|
+
const event = parseSSEEventChunk(eventChunk)
|
|
95
|
+
if (event?.type === "progress" && onProgress) {
|
|
96
|
+
onProgress(event.message)
|
|
97
|
+
}
|
|
98
|
+
if (event?.type === "result") {
|
|
99
|
+
finalResponse = { createdTables: event.createdTables || [] }
|
|
100
|
+
}
|
|
101
|
+
if (event?.type === "error") {
|
|
102
|
+
throw new Error(event.message || "Error generating tables")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
boundary = buffer.indexOf(SSE_EVENT_DELIMITER)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!finalResponse) {
|
|
110
|
+
throw new Error("No result received from table generation stream")
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return finalResponse
|
|
114
|
+
} catch (error: any) {
|
|
115
|
+
throw new Error(error?.message || "Error generating tables")
|
|
116
|
+
}
|
|
117
|
+
},
|
|
39
118
|
})
|
|
40
119
|
},
|
|
41
120
|
})
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
Icon,
|
|
6
6
|
ProgressCircle,
|
|
7
7
|
Body,
|
|
8
|
+
Helpers,
|
|
8
9
|
} from "@budibase/bbui"
|
|
9
10
|
import type {
|
|
10
11
|
ChatConversation,
|
|
@@ -62,6 +63,7 @@
|
|
|
62
63
|
})
|
|
63
64
|
)
|
|
64
65
|
|
|
66
|
+
let stableSessionId = $state(Helpers.uuid())
|
|
65
67
|
let chatAreaElement = $state<HTMLDivElement>()
|
|
66
68
|
let textareaElement = $state<HTMLTextAreaElement>()
|
|
67
69
|
let expandedTools = $state<Record<string, boolean>>({})
|
|
@@ -178,6 +180,7 @@
|
|
|
178
180
|
agentId: chat?.agentId,
|
|
179
181
|
transient: !persistConversation,
|
|
180
182
|
isPreview: isAgentPreviewChat,
|
|
183
|
+
sessionId: stableSessionId,
|
|
181
184
|
title: chat?.title,
|
|
182
185
|
messages,
|
|
183
186
|
},
|
|
@@ -213,7 +216,16 @@
|
|
|
213
216
|
},
|
|
214
217
|
onError: error => {
|
|
215
218
|
console.error(error)
|
|
216
|
-
|
|
219
|
+
let message = error.message || "Failed to send message"
|
|
220
|
+
try {
|
|
221
|
+
const parsed = JSON.parse(message)
|
|
222
|
+
if (parsed?.message) {
|
|
223
|
+
message = parsed.message
|
|
224
|
+
}
|
|
225
|
+
} catch {
|
|
226
|
+
// not JSON, use as-is
|
|
227
|
+
}
|
|
228
|
+
notifications.error(message)
|
|
217
229
|
},
|
|
218
230
|
})
|
|
219
231
|
|
|
@@ -242,6 +254,7 @@
|
|
|
242
254
|
$effect(() => {
|
|
243
255
|
if (chat?._id !== lastChatId) {
|
|
244
256
|
lastChatId = chat?._id
|
|
257
|
+
stableSessionId = Helpers.uuid()
|
|
245
258
|
chatInstance.messages = chat?.messages || []
|
|
246
259
|
expandedTools = {}
|
|
247
260
|
}
|