Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

69 lines
1.5 KiB
TypeScript

import { normalizeBoolean, normalizeTextValue } from "./settingsNormalization";
export type QuickPhrase = {
id: string;
title: string;
content: string;
enabled: boolean;
};
function isPlainRecord(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === "object" && !Array.isArray(value);
}
const MAX_QUICK_PHRASES = 100;
const MAX_QUICK_PHRASE_TITLE_LENGTH = 80;
const MAX_QUICK_PHRASE_CONTENT_LENGTH = 20_000;
function normalizeQuickPhrase(value: unknown): QuickPhrase | null {
if (!isPlainRecord(value)) {
return null;
}
const id = normalizeTextValue(value.id);
const title = normalizeTextValue(value.title).slice(
0,
MAX_QUICK_PHRASE_TITLE_LENGTH
);
const content = normalizeTextValue(value.content).slice(
0,
MAX_QUICK_PHRASE_CONTENT_LENGTH
);
const enabled = normalizeBoolean(value.enabled) ?? true;
if (id.length === 0 || title.length === 0 || content.length === 0) {
return null;
}
return { id, title, content, enabled };
}
export function normalizeQuickPhrases(value: unknown): QuickPhrase[] {
if (!Array.isArray(value)) {
return [];
}
const normalized: QuickPhrase[] = [];
const seenIds = new Set<string>();
for (const item of value) {
const phrase = normalizeQuickPhrase(item);
if (!phrase) {
continue;
}
if (seenIds.has(phrase.id)) {
continue;
}
seenIds.add(phrase.id);
normalized.push(phrase);
if (normalized.length >= MAX_QUICK_PHRASES) {
break;
}
}
return normalized;
}