fix: treat unicode with iter instead of length
Project CI / Repository checks (pull_request) Successful in 3m59s
Project CI / Frontend tests (pull_request) Successful in 4m18s
Project CI / Native shell tests (pull_request) Successful in 3m58s
Project CI / Backend tests (pull_request) Successful in 3m14s

This commit is contained in:
2026-07-24 13:06:22 +08:00
parent cd4f7b782f
commit f12fe2de32
+10 -10
View File
@@ -7,10 +7,7 @@ export const EDITOR_AGENT_ERROR_MESSAGE_PREFIX = 'ERROR ';
export type EditorAgentMessageRole = 'user' | 'assistant' | 'system';
export type EditorAgentToolCallStatus =
| 'not_completed'
| 'completed'
| 'failed'
| 'cancelled';
'not_completed' | 'completed' | 'failed' | 'cancelled';
export type EditorAgentAttachmentSource = 'canvas_resource' | 'library_asset';
@@ -24,7 +21,10 @@ function isUnsafeEditorAgentAttachmentLabelCharacter(character: string) {
(codePoint >= 0x5b && codePoint <= 0x60) ||
(codePoint >= 0x7b && codePoint <= 0x7e);
const isUnsafeAsciiPunctuation =
isAsciiPunctuation && character !== '-' && character !== '_' && character !== '.';
isAsciiPunctuation &&
character !== '-' &&
character !== '_' &&
character !== '.';
return isControlCharacter || isUnsafeAsciiPunctuation;
}
@@ -34,6 +34,7 @@ function normalizeEditorAgentAttachmentLabel(
) {
const normalizeCandidate = (candidate: string | null | undefined) => {
const normalized: string[] = [];
let codePoints = 0;
let pendingSpace = false;
for (const character of candidate?.trim() ?? '') {
if (isUnsafeEditorAgentAttachmentLabelCharacter(character)) {
@@ -45,18 +46,17 @@ function normalizeEditorAgentAttachmentLabel(
}
if (
pendingSpace &&
normalized.length + 1 <
EDITOR_AGENT_ATTACHMENT_LABEL_MAX_CODE_POINTS
codePoints + 1 < EDITOR_AGENT_ATTACHMENT_LABEL_MAX_CODE_POINTS
) {
normalized.push(' ');
codePoints += 1;
}
pendingSpace = false;
if (
normalized.length >= EDITOR_AGENT_ATTACHMENT_LABEL_MAX_CODE_POINTS
) {
if (codePoints >= EDITOR_AGENT_ATTACHMENT_LABEL_MAX_CODE_POINTS) {
break;
}
normalized.push(character);
codePoints += 1;
}
return normalized.join('').trim();
};