Files
FastGPT/packages/service/core/chat/utils.ts
Archer d571c768ea V4.14.1 feature (#5880)
* feat: app split (#5858)

* feat: app split script

* fix: app split

* chore: app split script try-catch

* adjust dashborad page (#5872)

* create page

* create page

* create button

* router name

* bot

* template

* create page

* mobile

* toolfolder

* fix

* fix

* fix build

* split tool select

* img

* doc

* rename enum

* fix page adjust (#5883)

* fix page adjust

* fix ad store

* fix: initv4141 (#5886)

* fix: create app

* doc

* hide api

* doc

* feat: payment pause interactive (#5892)

* fix: copy clbs (#5889)

* fix: copy clbs

* fix: copy clbs

* fix: http protocol handling in baseURL (#5890)

* fix: http protocol handling in baseURL

* ui fix

* auto saved version

* fix

* auto save

* fix: model permission modal (#5895)

* folder

* fix: del app

* navbar

* fix: plugin file selector (#5893)

* fix: plugin file selector

* fix: plugin file selector

* workflow tool inputform

* pick

---------

Co-authored-by: archer <545436317@qq.com>

* fix: workflow tool time

* doc

* fix workorder button (#5896)

* add inform track (#5897)

* remove invalid track

* comment

* feat: marketplace refresh api (#5884)

* marketplace refresh

* fix: helper bot menu button (#5898)

---------

Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com>
Co-authored-by: heheer <heheer@sealos.io>
Co-authored-by: 伍闲犬 <whoeverimf5@gmail.com>
2025-11-11 14:05:02 +08:00

64 lines
2.1 KiB
TypeScript

import { ChatItemValueTypeEnum, ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import type { ChatItemType } from '@fastgpt/global/core/chat/type';
import { getS3ChatSource } from '../../common/s3/sources/chat';
import type { FlowNodeInputItemType } from '@fastgpt/global/core/workflow/type/io';
import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
export const addPreviewUrlToChatItems = async (
histories: ChatItemType[],
type: 'chatFlow' | 'workflowTool'
) => {
async function addToChatflow(item: ChatItemType) {
for await (const value of item.value) {
if (value.type === ChatItemValueTypeEnum.file && value.file && value.file.key) {
value.file.url = await s3ChatSource.createGetChatFileURL({
key: value.file.key,
external: true
});
}
}
}
async function addToWorkflowTool(item: ChatItemType) {
if (item.obj !== ChatRoleEnum.Human || !Array.isArray(item.value)) return;
for (let j = 0; j < item.value.length; j++) {
const value = item.value[j];
if (value.type !== ChatItemValueTypeEnum.text) continue;
const inputValueString = value.text?.content || '';
const parsedInputValue = JSON.parse(inputValueString) as FlowNodeInputItemType[];
for (const input of parsedInputValue) {
if (
input.renderTypeList[0] !== FlowNodeInputTypeEnum.fileSelect ||
!Array.isArray(input.value)
)
continue;
for (const file of input.value) {
if (!file.key) continue;
const url = await getS3ChatSource().createGetChatFileURL({
key: file.key,
external: true
});
file.url = url;
}
}
item.value[j].text = {
...value.text,
content: JSON.stringify(parsedInputValue)
};
}
}
// Presign file urls
const s3ChatSource = getS3ChatSource();
for await (const item of histories) {
if (type === 'chatFlow') {
await addToChatflow(item);
} else if (type === 'workflowTool') {
await addToWorkflowTool(item);
}
}
};