feat: add Code-style voice composer to current Agents trial

This commit is contained in:
鲨鱼辣椒 committed 2026-10-13 19:12:35 +08:00
1 parent 7c51bb4a00
commit f61efaf046
60 files changed
+3383 -1286

No files matched your search

+39
View File
@@ -49,6 +49,7 @@ const MESSAGES: Record<string, string> = {
knowledge_processing: '知识库有文档正在处理,请完成后再维护',
agent_archived: '请先从归档恢复智能体,再启用',
attachment_too_large: '附件最大支持 5 MB',
attachment_invalid: '附件内容或文件名称无效,请重新选择文件',
avatar_too_large: '头像图片不能超过 5 MB',
avatar_invalid: '请选择有效的 PNG、JPEG、WebP 或 GIF 图片(最大 5 MB)',
download_failed: '文件保存失败,请重试',
@@ -489,8 +490,46 @@ export class CloudAgentsModule {
}
async upload(): Promise<CloudUpload | null> {
const binding = getWorksSquareAccountBinding();
if (!binding) throw new CloudAgentsError(401, 'session_expired');
const body = await this.pickUpload();
this.requireCurrent(binding);
if (!body) return null;
const result = await this.uploadTemporaryAttachment(body);
this.requireCurrent(binding);
return result;
}
async uploadBytes(value: unknown): Promise<CloudUpload> {
const binding = getWorksSquareAccountBinding();
if (!binding) throw new CloudAgentsError(401, 'session_expired');
const input = record(value);
const limit = 5 * 1024 * 1024;
if (Object.keys(input).some(key => !['bytesBase64', 'fileName', 'mimeType'].includes(key))
|| typeof input.fileName !== 'string' || !input.fileName.trim() || input.fileName.length > 255
|| /[\\/]/.test(input.fileName) || Array.from(input.fileName).some(char => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127)
|| ['.', '..'].includes(input.fileName)
|| typeof input.mimeType !== 'string' || input.mimeType.length > 127
|| !/^[a-zA-Z0-9][a-zA-Z0-9!#$&^_.+-]*\/[a-zA-Z0-9][a-zA-Z0-9!#$&^_.+-]*$/.test(input.mimeType)
|| typeof input.bytesBase64 !== 'string' || !input.bytesBase64) {
throw new CloudAgentsError(422, 'attachment_invalid', 'definitive_failure');
}
if (input.bytesBase64.length > Math.ceil(limit / 3) * 4) throw new CloudAgentsError(422, 'attachment_too_large', 'definitive_failure');
if (input.bytesBase64.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(input.bytesBase64)) {
throw new CloudAgentsError(422, 'attachment_invalid', 'definitive_failure');
}
const bytes = Buffer.from(input.bytesBase64, 'base64');
if (!bytes.length || bytes.toString('base64') !== input.bytesBase64) throw new CloudAgentsError(422, 'attachment_invalid', 'definitive_failure');
if (bytes.length > limit) throw new CloudAgentsError(422, 'attachment_too_large', 'definitive_failure');
const body = new FormData();
body.append('file', new Blob([new Uint8Array(bytes)], { type: input.mimeType }), input.fileName);
this.requireCurrent(binding);
const result = await this.uploadTemporaryAttachment(body);
this.requireCurrent(binding);
return result;
}
private async uploadTemporaryAttachment(body: FormData): Promise<CloudUpload> {
const result = record(await this.request('/api/makelore/attachments/tmp', 'POST', body));
return {
object_name: textField(result.object_name, 2048), file_name: textField(result.file_name, 255),