2525 >
2626 <robot-setting-popover
2727 v-if =" showPopover"
28- :typeValue =" selectedModel"
2928 @changeType =" changeModel"
3029 @close =" closePanel"
3130 ></robot-setting-popover >
7271 placeholder =" 请输入问题或“/”唤起指令,支持粘贴文档"
7372 :clearable =" true"
7473 :showWordLimit =" true"
75- :allowFiles ="
76- singleAttachmentItems.length < 1 && VISUAL_MODEL.includes(selectedModel.model) && aiType === BUILD_TYPE
77- "
74+ :allowFiles =" singleAttachmentItems.length < 1 && isVisualModel() && aiType === AI_MODES['Builder']"
7875 uploadTooltip =" 支持上传1张图片"
7976 @submit =" sendContent(inputContent, false)"
8077 @files-selected =" handleSingleFilesSelected"
9491 </template >
9592 <template #footer-left >
9693 <robot-type-select :aiType =" aiType" @typeChange =" typeChange" ></robot-type-select >
97- <mcp-server :position =" mcpDrawerPosition" v-if =" aiType === TALK_TYPE " ></mcp-server >
94+ <mcp-server :position =" mcpDrawerPosition" v-if =" aiType === AI_MODES['Chat'] " ></mcp-server >
9895 </template >
9996 </tr-sender >
10097 </template >
@@ -122,7 +119,14 @@ import {
122119 type Component
123120} from ' vue'
124121import { Notify , Loading , TinyPopover , TinyDialogBox } from ' @opentiny/vue'
125- import { useHistory , useCanvas , useModal , getMetaApi , META_SERVICE } from ' @opentiny/tiny-engine-meta-register'
122+ import {
123+ useRobot ,
124+ useHistory ,
125+ useCanvas ,
126+ useModal ,
127+ getMetaApi ,
128+ META_SERVICE
129+ } from ' @opentiny/tiny-engine-meta-register'
126130import { ToolbarBase } from ' @opentiny/tiny-engine-common'
127131import {
128132 TrContainer ,
@@ -138,17 +142,6 @@ import { IconNewSession } from '@opentiny/tiny-robot-svgs'
138142import SchemaRenderer from ' @opentiny/tiny-schema-renderer'
139143import { utils } from ' @opentiny/tiny-engine-utils'
140144import RobotSettingPopover from ' ./RobotSettingPopover.vue'
141- import {
142- getBlockContent ,
143- initBlockList ,
144- getAIModelOptions ,
145- defaultSelectedModel ,
146- isValidFastJsonPatch ,
147- VISUAL_MODEL ,
148- TALK_TYPE ,
149- MCP_TYPE ,
150- BUILD_TYPE
151- } from ' ./js/robotSetting'
152145import { PROMPTS } from ' ./js/prompts'
153146import * as jsonpatch from ' fast-json-patch'
154147import { chatStream , checkComponentNameExists } from ' ./js/utils'
@@ -190,6 +183,15 @@ export default {
190183 },
191184 emits: [' close-chat' ],
192185 setup() {
186+ const {
187+ getBlockContent,
188+ initBlockList,
189+ getAIModelOptions,
190+ isValidFastJsonPatch,
191+ VISUAL_MODEL,
192+ AI_MODES,
193+ robotSettingState
194+ } = useRobot ()
193195 const { pageState, importSchema, setSaved } = useCanvas ()
194196 const AIModelOptions = getAIModelOptions ()
195197 const robotVisible = ref (false )
@@ -201,7 +203,6 @@ export default {
201203 const connectedFailed = ref (false )
202204 const inputContent = ref (' ' )
203205 const inProcesing = ref (false )
204- const selectedModel = ref (defaultSelectedModel )
205206 const { confirm } = useModal ()
206207 const showPopover = ref (false )
207208 const searchContent = ref (' ' )
@@ -210,7 +211,7 @@ export default {
210211 const singleAttachmentItems = ref ([])
211212 const imageUrl = ref (' ' )
212213 const MESSAGE_TIP = ' 已生成新的页面效果。'
213- const aiType = ref (TALK_TYPE )
214+ const aiType = ref (AI_MODES [ ' Chat ' ] )
214215 const chatContainerRef = ref (null )
215216 const showTeleport = ref (false )
216217 const { deepClone, string2Obj, reactiveObj2String : obj2String } = utils
@@ -226,7 +227,7 @@ export default {
226227 ? JSON .stringify (sessionProcess )
227228 : JSON .stringify ({
228229 foundationModel: {
229- ... selectedModel . value
230+ ... robotSettingState . selectedModel
230231 },
231232 messages: [],
232233 displayMessages: [], // 专门用来进行展示的消息,非原始消息,仅作为展示但是不作为请求的发送
@@ -260,7 +261,7 @@ export default {
260261 const sendProcess = { ... sessionProcess }
261262 const firstMessage = sendProcess .messages [0 ]
262263 let firstContent = firstMessage .content
263- if (aiType .value === BUILD_TYPE ) {
264+ if (aiType .value === AI_MODES [ ' Builder ' ] ) {
264265 firstContent = firstMessage .content .map ((item ) => {
265266 if (item .type === ' text' ) {
266267 item .text = ` [指令] ${PROMPTS }\n [知识] ${searchContent .value }\n [当前schema] ${JSON .stringify (
@@ -270,7 +271,7 @@ export default {
270271 return item
271272 })
272273 }
273- if (useMcpServer ().isToolsEnabled && aiType .value === TALK_TYPE ) {
274+ if (useMcpServer ().isToolsEnabled && aiType .value === AI_MODES [ ' Chat ' ] ) {
274275 firstContent = ` ${getBlockContent ()}\n ${codeRules }\n ${firstMessage .content [0 ]?.text || ' ' } `
275276 }
276277
@@ -313,7 +314,7 @@ export default {
313314 // 处理响应
314315 const handleResponse = ({ id , chatMessage }: { id: string ; chatMessage: any }, currentJson ) => {
315316 try {
316- if (aiType .value === BUILD_TYPE ) {
317+ if (aiType .value === AI_MODES [ ' Builder ' ] ) {
317318 const regex = / ```json([\s\S ] *? )```/
318319 const match = chatMessage ?.content .match (regex )
319320
@@ -337,7 +338,7 @@ export default {
337338 inProcesing .value = false
338339 connectedFailed .value = false
339340 }
340- if (aiType .value === TALK_TYPE ) {
341+ if (aiType .value === AI_MODES [ ' Chat ' ] ) {
341342 sessionProcess .messages .push (getAiRespMessage (chatMessage ?.content ))
342343 sessionProcess .displayMessages .push (getAiRespMessage (chatMessage ?.content ))
343344 messages .value [messages .value .length - 1 ].content = chatMessage ?.content
@@ -353,16 +354,16 @@ export default {
353354 // 发送流式请求
354355 const sendStreamRequest = async () => {
355356 const requestData = getSendSeesionProcess ()
356- if (useMcpServer ().isToolsEnabled && aiType .value === TALK_TYPE ) {
357+ if (useMcpServer ().isToolsEnabled && aiType .value === AI_MODES [ ' Chat ' ] ) {
357358 try {
358359 requestLoading .value = true
359360 await scrollContent ()
360361 await sendMcpRequest (messages .value , {
361- model: selectedModel . value .model ,
362+ model: robotSettingState . selectedModel .model ,
362363 headers: {
363- Authorization: ` Bearer ${selectedModel . value .apiKey || import .meta .env .VITE_API_TOKEN } `
364+ Authorization: ` Bearer ${robotSettingState . selectedModel .apiKey || import .meta .env .VITE_API_TOKEN } `
364365 },
365- baseUrl: selectedModel . value .baseUrl
366+ baseUrl: robotSettingState . selectedModel .baseUrl
366367 })
367368 } catch (error ) {
368369 const { renderContent } = messages .value .at (- 1 )!
@@ -458,7 +459,7 @@ export default {
458459 }
459460 },
460461 {
461- Authorization: ` Bearer ${selectedModel . value .apiKey || import .meta .env .VITE_API_TOKEN } `
462+ Authorization: ` Bearer ${robotSettingState . selectedModel .apiKey || import .meta .env .VITE_API_TOKEN } `
462463 }
463464 )
464465 }
@@ -499,7 +500,7 @@ export default {
499500 text
500501 }
501502 ]
502- if (singleAttachmentItems .value .length > 0 && aiType .value === BUILD_TYPE ) {
503+ if (singleAttachmentItems .value .length > 0 && aiType .value === AI_MODES [ ' Builder ' ] ) {
503504 content .push ({
504505 type: ' image_url' ,
505506 image_url: {
@@ -529,7 +530,7 @@ export default {
529530 if (chatWindowOpened .value === false ) {
530531 await resizeChatWindow ()
531532 }
532- if (! sessionProcess ?.messages ?.length && aiType .value !== TALK_TYPE ) {
533+ if (! sessionProcess ?.messages ?.length && aiType .value !== AI_MODES [ ' Chat ' ] ) {
533534 sessionProcess ?.messages .push ({
534535 role: ' system' ,
535536 content: [
@@ -545,7 +546,7 @@ export default {
545546 messages .value .push (message )
546547 sessionProcess ?.messages .push (getSessionMessage (realContent ))
547548 sessionProcess ?.displayMessages .push (message )
548- if (aiType .value === BUILD_TYPE && (! searchContent .value || ! sessionProcess .messages ?.length )) {
549+ if (aiType .value === AI_MODES [ ' Builder ' ] && (! searchContent .value || ! sessionProcess .messages ?.length )) {
549550 await search (realContent )
550551 }
551552
@@ -564,10 +565,10 @@ export default {
564565
565566 // 根据localstorage初始化AI大模型
566567 const initCurrentModel = (aiSession ) => {
567- selectedModel . value = {
568+ robotSettingState . selectedModel = {
568569 ... JSON .parse (aiSession )?.foundationModel
569570 }
570- aiType .value = JSON .parse (aiSession )?.aiType
571+ aiType .value = JSON .parse (aiSession )?.aiType || aiType . value
571572 }
572573
573574 const initChat = () => {
@@ -614,16 +615,20 @@ export default {
614615 }
615616
616617 const changeModel = (model ) => {
617- if (selectedModel .value .baseUrl !== model .baseUrl || selectedModel .value !== model .model ) {
618+ if (
619+ robotSettingState .selectedModel .baseUrl !== model .baseUrl ||
620+ robotSettingState .selectedModel .model !== model .model
621+ ) {
618622 confirm ({
619623 title: ' 切换AI大模型' ,
620624 message: ' 切换AI大模型将导致当前会话被清空,重新开启新会话,是否继续?' ,
621625 exec() {
622- selectedModel . value = {
626+ robotSettingState . selectedModel = {
623627 label: model .label || model .model ,
624628 activeName: model .activeName ,
625629 baseUrl: model .baseUrl ,
626630 model: model .model ,
631+ completeModel: model .completeModel ,
627632 apiKey: model .apiKey
628633 }
629634 singleAttachmentItems .value = []
@@ -633,11 +638,11 @@ export default {
633638 })
634639 }
635640 if (
636- selectedModel . value .apiKey !== model .apiKey &&
637- selectedModel . value .baseUrl === model .baseUrl &&
638- selectedModel . value .model === model .model
641+ robotSettingState . selectedModel .apiKey !== model .apiKey &&
642+ robotSettingState . selectedModel .baseUrl === model .baseUrl &&
643+ robotSettingState . selectedModel .model === model .model
639644 ) {
640- selectedModel . value .apiKey = model .apiKey
645+ robotSettingState . selectedModel .apiKey = model .apiKey
641646 changeApiKey ()
642647 }
643648 }
@@ -791,6 +796,12 @@ export default {
791796 }
792797 })
793798
799+ const isVisualModel = () => {
800+ const platform = AIModelOptions .find ((option ) => option .value === robotSettingState .selectedModel .baseUrl )
801+ const modelAbility = platform .model .find ((item ) => item .value === robotSettingState .selectedModel .model )
802+ return modelAbility ?.ability ?.includes (' visual' ) || false
803+ }
804+
794805 return {
795806 chatContainerRef ,
796807 robotVisible ,
@@ -800,7 +811,7 @@ export default {
800811 inputContent ,
801812 connectedFailed ,
802813 AIModelOptions ,
803- selectedModel ,
814+ robotSettingState ,
804815 showPopover ,
805816 fullscreen ,
806817 welcomeIcon ,
@@ -813,9 +824,7 @@ export default {
813824 MarkdownRenderer ,
814825 requestLoading ,
815826 aiType ,
816- TALK_TYPE ,
817- MCP_TYPE ,
818- BUILD_TYPE ,
827+ AI_MODES ,
819828 showTeleport ,
820829 sendContent ,
821830 endContent ,
@@ -830,6 +839,7 @@ export default {
830839 handleSingleFileRemove ,
831840 handleSingleFileRetry ,
832841 typeChange ,
842+ isVisualModel ,
833843 contentRenderers ,
834844 mcpDrawerPosition
835845 }
0 commit comments