Skip to content

Commit 10d9917

Browse files
authored
Merge pull request #34 from TencentCloudBase/dev
Dev
2 parents eb4916e + 52fbbac commit 10d9917

File tree

19 files changed

+701
-381
lines changed

19 files changed

+701
-381
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [1.8.1](https://github.com/TencentCloudBase/cloudbase-agent-ui/compare/v1.8.0...v1.8.1) (2025-04-08)
6+
7+
8+
### Bug Fixes
9+
10+
* 3.8.1版本切换兼容 ([190a59f](https://github.com/TencentCloudBase/cloudbase-agent-ui/commit/190a59f87d3323cb971b7627eb1806e6493651d6))
11+
* 支持用户内容粘贴及修改 ([5fb0e3e](https://github.com/TencentCloudBase/cloudbase-agent-ui/commit/5fb0e3ea033d1df5cfbb8459b129970d235b0b5c))
12+
* fix showToolcall icon ([a523d7f](https://github.com/TencentCloudBase/cloudbase-agent-ui/commit/a523d7fbaa4c3b0365eb548cb7b1122b0b8e6d90))
13+
* fix style ([1cd0289](https://github.com/TencentCloudBase/cloudbase-agent-ui/commit/1cd02891c0decf1e4d23714c5c3a2eae75299209))
14+
* fix toolcall error ([2ec9c52](https://github.com/TencentCloudBase/cloudbase-agent-ui/commit/2ec9c52024ca0114c262427924347d1fb6533528))
15+
* remove invalid comment ([77c433b](https://github.com/TencentCloudBase/cloudbase-agent-ui/commit/77c433b4c994958f95c79c8f2946038e8d5a4225))
16+
517
## [1.8.0](https://github.com/TencentCloudBase/cloudbase-agent-ui/compare/v1.7.0...v1.8.0) (2025-03-31)
618

719

Lines changed: 152 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,218 +1,259 @@
11
// components/agent-ui-new/chatFIle/chatFile.js
2-
import {getCloudInstance} from '../tools'
2+
import { getCloudInstance, compareVersions } from "../tools";
33
Component({
44
lifetimes: {
55
attached: async function () {
6-
console.log('enableDel', this.data.enableDel)
7-
const { tempFileName, rawFileName, rawType, tempPath, fileId, botId, parsed } = this.data.fileData
8-
const type = this.getFileType(rawFileName || tempFileName)
9-
console.log('type', type)
6+
console.log("enableDel", this.data.enableDel);
7+
const { tempFileName, rawFileName, rawType, tempPath, fileId, botId, parsed } = this.data.fileData;
8+
const type = this.getFileType(rawFileName || tempFileName);
9+
console.log("type", type);
1010
if (!fileId) {
1111
this.setData({
12-
formatSize: '上传中',
13-
iconPath: '../imgs/' + type + '.svg'
14-
})
12+
formatSize: "上传中",
13+
iconPath: "../imgs/" + type + ".svg",
14+
});
1515
}
1616

1717
if (fileId && parsed) {
1818
this.setData({
1919
formatSize: this.transformSize(this.data.fileData.fileSize),
20-
iconPath: '../imgs/' + type + '.svg'
21-
})
22-
return
20+
iconPath: "../imgs/" + type + ".svg",
21+
});
22+
return;
2323
}
24-
const cloudInstance= await getCloudInstance()
24+
const cloudInstance = await getCloudInstance();
2525
// console.log('file', cloudInstance)
2626
// 上传云存储获取 fileId
2727
// console.log('rawFileName tempFileName tempPath', rawFileName, tempFileName, tempPath)
2828
cloudInstance.uploadFile({
29-
cloudPath: this.generateCosUploadPath(botId, rawFileName ? (rawFileName.split('.')[0] + '-' + tempFileName) : tempFileName), // 云上文件路径
29+
cloudPath: this.generateCosUploadPath(
30+
botId,
31+
rawFileName ? rawFileName.split(".")[0] + "-" + tempFileName : tempFileName
32+
), // 云上文件路径
3033
filePath: tempPath,
31-
success: async res => {
32-
const { token } = await cloudInstance.extend.AI.bot.tokenManager.getToken()
33-
const fileId = res.fileID
34+
success: async (res) => {
35+
const appBaseInfo = wx.getAppBaseInfo();
36+
const fileId = res.fileID;
3437
this.setData({
35-
formatSize: '解析中',
36-
})
37-
wx.request({
38-
url: `https://${cloudInstance.env||cloudInstance.extend.AI.bot.context.env}.api.tcloudbasegateway.com/v1/aibot/bots/${botId}/files`,
39-
data: {
40-
fileList: [{
41-
fileName: rawFileName || tempFileName,
42-
fileId,
43-
type: rawType
44-
}]
45-
},
46-
header: {
47-
Authorization: `Bearer ${token}`
48-
},
49-
method: 'POST',
50-
success: (res) => {
51-
console.log('resolve agent file res', res)
52-
this.setData({
53-
formatSize: this.transformSize(this.data.fileData.fileSize),
54-
})
55-
this.triggerEvent('changeChild', { tempId: this.data.fileData.tempId, fileId, parsed: true })
56-
},
57-
fail(e) {
58-
console.log('resolve agent file e', e)
59-
}
60-
})
38+
formatSize: "解析中",
39+
});
40+
41+
console.log("当前版本", appBaseInfo.SDKVersion);
42+
// 3.8.1 及以上版本走sdk 内置方法
43+
if (compareVersions(appBaseInfo.SDKVersion, "3.8.1") < 0) {
44+
const { token } = await cloudInstance.extend.AI.bot.tokenManager.getToken();
45+
wx.request({
46+
url: `https://${
47+
cloudInstance.env || cloudInstance.extend.AI.bot.context.env
48+
}.api.tcloudbasegateway.com/v1/aibot/bots/${botId}/files`,
49+
data: {
50+
fileList: [
51+
{
52+
fileName: rawFileName || tempFileName,
53+
fileId,
54+
type: rawType,
55+
},
56+
],
57+
},
58+
header: {
59+
Authorization: `Bearer ${token}`,
60+
},
61+
method: "POST",
62+
success: (res) => {
63+
console.log("resolve agent file res", res);
64+
this.setData({
65+
formatSize: this.transformSize(this.data.fileData.fileSize),
66+
});
67+
this.triggerEvent("changeChild", { tempId: this.data.fileData.tempId, fileId, parsed: true });
68+
},
69+
fail(e) {
70+
console.log("resolve agent file e", e);
71+
},
72+
});
73+
} else {
74+
const ai = cloudInstance.extend.AI;
75+
ai.request({
76+
path: `bots/${botId}/files`, // 填写 "v1/aibot/" 后面的内容
77+
data: {
78+
fileList: [
79+
{
80+
fileName: rawFileName || tempFileName,
81+
fileId,
82+
type: rawType,
83+
},
84+
],
85+
}, // any
86+
method: "POST",
87+
timeout: 30000,
88+
success: (res) => {
89+
console.log("resolve agent file res", res);
90+
this.setData({
91+
formatSize: this.transformSize(this.data.fileData.fileSize),
92+
});
93+
this.triggerEvent("changeChild", { tempId: this.data.fileData.tempId, fileId, parsed: true });
94+
},
95+
fail: (e) => {
96+
console.log("e", e);
97+
},
98+
complete: () => {},
99+
header: {},
100+
});
101+
}
102+
},
103+
fail: (err) => {
104+
console.error("上传失败:", err);
61105
},
62-
fail: err => {
63-
console.error('上传失败:', err);
64-
}
65106
});
66-
}
107+
},
67108
},
68109
observers: {
69-
'fileData.fileId': function (fileId) {
110+
"fileData.fileId": function (fileId) {
70111
this.setData({
71-
formatSize: fileId ? this.transformSize(this.data.fileData.fileSize) : '上传中'
72-
})
112+
formatSize: fileId ? this.transformSize(this.data.fileData.fileSize) : "上传中",
113+
});
73114
},
74-
'fileData.parsed': function (parsed) {
115+
"fileData.parsed": function (parsed) {
75116
this.setData({
76-
formatSize: parsed ? this.transformSize(this.data.fileData.fileSize) : '解析中'
77-
})
78-
}
117+
formatSize: parsed ? this.transformSize(this.data.fileData.fileSize) : "解析中",
118+
});
119+
},
79120
},
80121
/**
81122
* 组件的属性列表
82123
*/
83124
properties: {
84125
enableDel: {
85126
type: Boolean,
86-
value: false
127+
value: false,
87128
},
88129
fileData: {
89130
type: Object,
90131
value: {
91-
tempId: '',
92-
rawType: '',
93-
tempFileName: '',
94-
rawFileName: '',
95-
tempPath: '',
132+
tempId: "",
133+
rawType: "",
134+
tempFileName: "",
135+
rawFileName: "",
136+
tempPath: "",
96137
fileSize: 0,
97-
fileUrl: '',
98-
fileId: '',
99-
parsed: false
100-
}
101-
}
138+
fileUrl: "",
139+
fileId: "",
140+
parsed: false,
141+
},
142+
},
102143
},
103144

104145
/**
105146
* 组件的初始数据
106147
*/
107148
data: {
108-
formatSize: '',
109-
iconPath: '../imgs/file.svg'
149+
formatSize: "",
150+
iconPath: "../imgs/file.svg",
110151
},
111152
/**
112153
* 组件的方法列表,
113154
*/
114155
methods: {
115156
generateCosUploadPath: function (botId, fileName) {
116-
return `agent_file/${botId}/${fileName}`
157+
return `agent_file/${botId}/${fileName}`;
117158
},
118159
// 提取文件后缀
119160
getFileType: function (fileName) {
120-
let index = fileName.lastIndexOf('.');
161+
let index = fileName.lastIndexOf(".");
121162
const fileExt = fileName.substring(index + 1);
122-
if (fileExt === 'docx' || fileExt === 'doc') {
123-
return 'word'
163+
if (fileExt === "docx" || fileExt === "doc") {
164+
return "word";
124165
}
125-
if (fileExt === 'xlsx' || fileExt === 'xls' || fileExt === 'csv') {
126-
return 'excel'
166+
if (fileExt === "xlsx" || fileExt === "xls" || fileExt === "csv") {
167+
return "excel";
127168
}
128-
if (fileExt === 'png' || fileExt === 'jpg' || fileExt === 'jpeg' || fileExt === 'svg') {
129-
return 'image'
169+
if (fileExt === "png" || fileExt === "jpg" || fileExt === "jpeg" || fileExt === "svg") {
170+
return "image";
130171
}
131172

132-
if (fileExt === 'ppt' || fileExt === 'pptx') {
133-
return 'ppt'
173+
if (fileExt === "ppt" || fileExt === "pptx") {
174+
return "ppt";
134175
}
135176

136-
if (fileExt === 'pdf') {
137-
return 'pdf'
177+
if (fileExt === "pdf") {
178+
return "pdf";
138179
}
139-
return 'file'
180+
return "file";
140181
},
141182
// 转换文件大小(原始单位为B)
142183
transformSize: function (size) {
143184
if (size < 1024) {
144-
return size + 'B';
185+
return size + "B";
145186
} else if (size < 1024 * 1024) {
146-
return (size / 1024).toFixed(2) + 'KB';
187+
return (size / 1024).toFixed(2) + "KB";
147188
} else {
148-
return (size / 1024 / 1024).toFixed(2) + 'MB';
189+
return (size / 1024 / 1024).toFixed(2) + "MB";
149190
}
150191
},
151192
removeFileFromParents: function () {
152-
console.log('remove', this.data.fileData)
153-
this.triggerEvent('removeChild', { tempId: this.data.fileData.tempId })
193+
console.log("remove", this.data.fileData);
194+
this.triggerEvent("removeChild", { tempId: this.data.fileData.tempId });
154195
},
155196
openFileByWx: function (tempPath) {
156-
const fileExt = tempPath.split('.')[1]
157-
if (['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf'].includes(fileExt)) {
197+
const fileExt = tempPath.split(".")[1];
198+
if (["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"].includes(fileExt)) {
158199
wx.openDocument({
159200
filePath: tempPath,
160201
success: function (res) {
161-
console.log('打开文档成功')
202+
console.log("打开文档成功");
162203
},
163204
fail: function (err) {
164-
console.log('打开文档失败', err)
165-
}
166-
})
205+
console.log("打开文档失败", err);
206+
},
207+
});
167208
} else {
168209
wx.showModal({
169210
content: "当前支持预览文件类型为 pdf、doc、docx、ppt、pptx、xls、xlsx",
170211
showCancel: false,
171-
confirmText: '确定'
172-
})
212+
confirmText: "确定",
213+
});
173214
}
174215
},
175216
previewImageByWx: function (fileId) {
176217
wx.previewImage({
177218
urls: [fileId],
178219
showmenu: true,
179220
success: function (res) {
180-
console.log('previewImage res', res)
221+
console.log("previewImage res", res);
181222
},
182223
fail: function (e) {
183-
console.log('previewImage e', e)
184-
}
185-
})
224+
console.log("previewImage e", e);
225+
},
226+
});
186227
},
187228
openFile: async function () {
188229
if (this.data.fileData.tempPath) {
189230
// 本地上传的文件
190-
if (this.data.fileData.rawType === 'file') {
191-
this.openFileByWx(this.data.fileData.tempPath)
231+
if (this.data.fileData.rawType === "file") {
232+
this.openFileByWx(this.data.fileData.tempPath);
192233
} else {
193-
console.log('fileId', this.data.fileData.fileId)
234+
console.log("fileId", this.data.fileData.fileId);
194235
if (this.data.fileData.fileId) {
195-
this.previewImageByWx(this.data.fileData.fileId)
236+
this.previewImageByWx(this.data.fileData.fileId);
196237
}
197238
}
198239
} else if (this.data.fileData.fileId) {
199240
// 针对历史记录中带cloudID的处理(历史记录中附带的文件)
200-
const cloudInsatnce=await getCloudInstance()
241+
const cloudInsatnce = await getCloudInstance();
201242
cloudInsatnce.downloadFile({
202243
fileID: this.data.fileData.fileId,
203-
success: res => {
204-
console.log('download res', res)
205-
if (this.data.fileData.rawType === 'file') {
206-
this.openFileByWx(res.tempFilePath)
244+
success: (res) => {
245+
console.log("download res", res);
246+
if (this.data.fileData.rawType === "file") {
247+
this.openFileByWx(res.tempFilePath);
207248
} else {
208-
this.previewImageByWx(this.data.fileData.fileId)
249+
this.previewImageByWx(this.data.fileData.fileId);
209250
}
210251
},
211-
fail: err => {
212-
console.log('download err', err)
213-
}
214-
})
252+
fail: (err) => {
253+
console.log("download err", err);
254+
},
255+
});
215256
}
216-
}
257+
},
217258
},
218259
});

0 commit comments

Comments
 (0)