fix: treat unicode with iter instead of length
This commit is contained in:
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user