Skip to content

Commit 2a11f45

Browse files
authored
Merge pull request #3748 from illacloud/Release/4.5.15
Release/4.5.15
2 parents 941b074 + bd2fb52 commit 2a11f45

File tree

40 files changed

+1757
-1312
lines changed

40 files changed

+1757
-1312
lines changed

apps/builder/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"private": true,
66
"author": "ILLA Cloud <[email protected]>",
77
"license": "Apache-2.0",
8-
"version": "4.5.14",
8+
"version": "4.5.15",
99
"scripts": {
1010
"dev": "vite --strictPort --force",
1111
"build-cloud": "NODE_OPTIONS=--max-old-space-size=12288 vite build --mode cloud",
@@ -105,6 +105,7 @@
105105
"klona": "^2.0.6",
106106
"lodash-es": "^4.17.21",
107107
"lottie-react": "^2.4.0",
108+
"mammoth": "^1.7.0",
108109
"numbro": "^2.4.0",
109110
"overlap-area": "^1.1.0",
110111
"papaparse": "^5.4.1",
@@ -146,7 +147,7 @@
146147
"toposort": "^2.0.2",
147148
"ts-key-enum": "^2.0.12",
148149
"uuid": "^8.3.2",
149-
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz"
150+
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.1/xlsx-0.20.1.tgz"
150151
},
151152
"devDependencies": {
152153
"@mdx-js/rollup": "^2.3.0",
Lines changed: 3 additions & 0 deletions
Loading

apps/builder/src/page/AI/AIAgent/aiagent.tsx

Lines changed: 127 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
AI_AGENT_MODEL,
2222
AI_AGENT_TYPE,
2323
Agent,
24+
KnowledgeFile,
2425
MemberInfo,
2526
USER_ROLE,
2627
USER_STATUS,
@@ -95,6 +96,7 @@ import { copyToClipboard } from "@/utils/copyToClipboard"
9596
import { track } from "@/utils/mixpanelHelper"
9697
import { ChatContext } from "../components/ChatContext"
9798
import { ErrorText } from "../components/ErrorText"
99+
import KnowledgeUpload from "../components/KnowledgeUpload"
98100
import {
99101
ChatSendRequestPayload,
100102
SenderType,
@@ -126,6 +128,9 @@ import {
126128
} from "./style"
127129
import { agentData2JSONReport } from "./utils"
128130

131+
// TODO: WTF, can edit knowledge file
132+
const CAN_EDIT_KNOWLEDGE_FILE = false
133+
129134
export const AIAgent: FC = () => {
130135
const data = useAsyncValue() as {
131136
agent: Agent
@@ -248,6 +253,7 @@ export const AIAgent: FC = () => {
248253
model: getValues("model"),
249254
prompt: getValues("prompt"),
250255
agentType: getValues("agentType"),
256+
// TODO: add knowledge
251257
} as Agent
252258
}, [getValues])
253259

@@ -315,6 +321,7 @@ export const AIAgent: FC = () => {
315321
threadID: v4(),
316322
prompt: getValues("prompt"),
317323
variables: getValues("variables"),
324+
// TODO: add knowledge
318325
actionID: getValues("aiAgentID"),
319326
modelConfig: getValues("modelConfig"),
320327
model: getValues("model"),
@@ -357,29 +364,39 @@ export const AIAgent: FC = () => {
357364
}
358365

359366
const handleSubmitSave = async (data: Agent) => {
367+
let currentData: Agent = { ...data }
368+
if (
369+
!isPremiumModel(currentData.model) &&
370+
currentData.knowledge?.length > 0
371+
) {
372+
currentData = {
373+
...currentData,
374+
knowledge: [],
375+
}
376+
}
360377
track(
361378
ILLA_MIXPANEL_EVENT_TYPE.CLICK,
362379
ILLA_MIXPANEL_BUILDER_PAGE_NAME.AI_AGENT_EDIT,
363380
{
364381
element: "save",
365-
parameter1: agentData2JSONReport(data),
366-
parameter5: data.aiAgentID || "-1",
382+
parameter1: agentData2JSONReport(currentData),
383+
parameter5: currentData.aiAgentID || "-1",
367384
},
368385
)
369386
let agentInfo: Agent
370387
try {
371-
let updateIconURL = data.icon
372-
if (data.icon !== undefined && data.icon !== "") {
373-
const iconURL = new URL(data.icon)
388+
let updateIconURL = currentData.icon
389+
if (currentData.icon !== undefined && currentData.icon !== "") {
390+
const iconURL = new URL(currentData.icon)
374391
if (iconURL.protocol !== "http:" && iconURL.protocol !== "https:") {
375-
updateIconURL = await uploadAgentIcon(data.icon)
392+
updateIconURL = await uploadAgentIcon(currentData.icon)
376393
}
377394
}
378-
if (data.aiAgentID === undefined || data.aiAgentID === "") {
395+
if (currentData.aiAgentID === undefined || currentData.aiAgentID === "") {
379396
const resp = await createAgent({
380-
...data,
397+
...currentData,
381398
icon: updateIconURL,
382-
variables: data.variables.filter(
399+
variables: currentData.variables.filter(
383400
(v) => v.key !== "" && v.value !== "",
384401
),
385402
})
@@ -399,8 +416,8 @@ export const AIAgent: FC = () => {
399416
})
400417
agentInfo = resp.data
401418
} else {
402-
const resp = await putAgentDetail(data.aiAgentID, {
403-
...data,
419+
const resp = await putAgentDetail(currentData.aiAgentID, {
420+
...currentData,
404421
icon: updateIconURL,
405422
variables: data.variables.filter(
406423
(v) => v.key !== "" && v.value !== "",
@@ -438,6 +455,9 @@ export const AIAgent: FC = () => {
438455
if (!!errors.prompt) {
439456
handleScrollToElement(SCROLL_ID.PROMPT)
440457
validate = false
458+
} else if (!!errors.knowledge) {
459+
handleScrollToElement(SCROLL_ID.KNOWLEDGE)
460+
validate = false
441461
} else if (!!errors.variables) {
442462
handleScrollToElement(SCROLL_ID.VARIABLES)
443463
validate = false
@@ -512,6 +532,17 @@ export const AIAgent: FC = () => {
512532
})
513533
handleScrollToElement(SCROLL_ID.VARIABLES)
514534
return false
535+
} else if (
536+
Array.isArray(getValues("knowledge")) &&
537+
getValues("knowledge").length > 0 &&
538+
getValues("knowledge").some((param) => param.value === "")
539+
) {
540+
setError("variables", {
541+
type: "knowledge",
542+
message: t("dashboard.message.parsing_file_in_prog"),
543+
})
544+
handleScrollToElement(SCROLL_ID.KNOWLEDGE)
545+
return false
515546
}
516547
return true
517548
}
@@ -722,6 +753,75 @@ export const AIAgent: FC = () => {
722753
)}
723754
/>
724755

756+
{CAN_EDIT_KNOWLEDGE_FILE &&
757+
isPremiumModel(getValues("model")) && (
758+
<Controller
759+
name="knowledge"
760+
control={control}
761+
rules={{
762+
validate: (value) => {
763+
const isValidate =
764+
!value ||
765+
value.length === 0 ||
766+
value.every((param) => param.value !== "")
767+
return isValidate ? isValidate : t("")
768+
},
769+
}}
770+
shouldUnregister={false}
771+
render={({ field }) => (
772+
<AIAgentBlock
773+
title={t("knowledge")}
774+
scrollId={SCROLL_ID.KNOWLEDGE}
775+
>
776+
<KnowledgeUpload
777+
addFile={(
778+
file: KnowledgeFile,
779+
isUpdate?: boolean,
780+
) => {
781+
const { name, type } = file
782+
const files = field.value || []
783+
const index = files.findIndex(
784+
(item) =>
785+
item.name === name && item.type === type,
786+
)
787+
if (index !== -1) {
788+
if (isUpdate) {
789+
let needUpdateFile = files[index]
790+
files.splice(index, 1, {
791+
...needUpdateFile,
792+
...file,
793+
})
794+
} else {
795+
const fileNamePrefix = `${
796+
file.name.split(".")[0]
797+
}(${v4().slice(0, 3)})`
798+
799+
files.push({
800+
...file,
801+
name: `${fileNamePrefix}.${file.name.split(
802+
".",
803+
)?.[1]}`,
804+
})
805+
}
806+
} else {
807+
files.push(file)
808+
}
809+
field.onChange(files)
810+
}}
811+
removeFile={(name: string) => {
812+
const currentFiles = field.value || []
813+
const files = currentFiles.filter(
814+
(item) => item.name !== name,
815+
)
816+
field.onChange(files)
817+
}}
818+
values={field.value}
819+
/>
820+
</AIAgentBlock>
821+
)}
822+
/>
823+
)}
824+
725825
<Controller
726826
name="model"
727827
control={control}
@@ -1093,30 +1193,30 @@ export const AIAgent: FC = () => {
10931193
</div>
10941194
<form onSubmit={handleSubmit(handleSubmitSave)}>
10951195
<div css={buttonContainerStyle}>
1096-
<Button
1097-
id="save-button"
1098-
flex="1"
1099-
colorScheme="grayBlue"
1100-
onClick={handleVerifyOnSave}
1101-
size="large"
1102-
loading={isSubmitting}
1103-
>
1104-
{t("editor.ai-agent.save")}
1105-
</Button>
11061196
<Button
11071197
flex="1"
11081198
size="large"
11091199
type="button"
11101200
loading={isConnecting}
1111-
ml="8px"
1112-
colorScheme={getColor("grayBlue", "02")}
1201+
colorScheme="grayBlue"
11131202
leftIcon={isRunning ? <ResetIcon /> : <PlayFillIcon />}
11141203
onClick={handleClickStart}
11151204
>
11161205
{!isRunning
11171206
? t("editor.ai-agent.start")
11181207
: t("editor.ai-agent.restart")}
11191208
</Button>
1209+
<Button
1210+
id="save-button"
1211+
flex="1"
1212+
ml="8px"
1213+
onClick={handleVerifyOnSave}
1214+
colorScheme={getColor("grayBlue", "02")}
1215+
size="large"
1216+
loading={isSubmitting}
1217+
>
1218+
{t("editor.ai-agent.save")}
1219+
</Button>
11201220
</div>
11211221
</form>
11221222
</div>
@@ -1147,9 +1247,12 @@ export const AIAgent: FC = () => {
11471247
currentTeamInfo.myRole,
11481248
contributeField.value,
11491249
)}
1250+
showEditPanel={false}
11501251
isRunning={isRunning}
1252+
isConnecting={isConnecting}
11511253
hasCreated={Boolean(idField.value)}
11521254
isMobile={false}
1255+
model={getValues("model")}
11531256
editState="EDIT"
11541257
agentType={field.value}
11551258
chatMessages={chatMessages}
@@ -1171,7 +1274,7 @@ export const AIAgent: FC = () => {
11711274
sendMessage(
11721275
{
11731276
threadID: message.threadID,
1174-
prompt: encodeURIComponent(message.message),
1277+
prompt: message.message,
11751278
variables: [],
11761279
actionID: getValues("aiAgentID"),
11771280
modelConfig: getValues("modelConfig"),

apps/builder/src/page/AI/AIAgent/interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const AgentInitial: Agent = {
66
agentType: AI_AGENT_TYPE.CHAT,
77
model: AI_AGENT_MODEL.GPT_3_5,
88
variables: [{ key: "", value: "" }],
9+
knowledge: [],
910
prompt: "",
1011
modelConfig: {
1112
stream: true,
@@ -27,6 +28,7 @@ export const AgentInitial: Agent = {
2728
export enum SCROLL_ID {
2829
PROMPT = "prompt",
2930
VARIABLES = "variables",
31+
KNOWLEDGE = "knowledge",
3032
NAME = "name",
3133
DESCRIPTION = "description",
3234
ICON = "icon",

apps/builder/src/page/AI/AIAgentRun/AIAgentRunMobile/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,15 @@ export const AIAgentRunMobile: FC = () => {
529529
<div css={previewChatContainer}>
530530
<PreviewChat
531531
editState="RUN"
532+
showEditPanel={false}
532533
showShareDialog={false}
533534
showContributeDialog={false}
535+
isConnecting={isConnecting}
534536
isRunning={isRunning}
535537
hasCreated={true}
536538
isMobile={true}
537539
agentType={field.value}
540+
model={getValues("model")}
538541
chatMessages={chatMessages}
539542
generationMessage={generationMessage}
540543
isReceiving={isReceiving}

0 commit comments

Comments
 (0)