From f12fe2de3242f0dc47a14e554c8a967d175a00c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 24 Jul 2026 13:06:22 +0800 Subject: [PATCH] fix: treat unicode with iter instead of length --- packages/shared/src/contracts/editorAgent.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/shared/src/contracts/editorAgent.ts b/packages/shared/src/contracts/editorAgent.ts index 849a0c0a2..b8296dd2f 100644 --- a/packages/shared/src/contracts/editorAgent.ts +++ b/packages/shared/src/contracts/editorAgent.ts @@ -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(); };