-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathconsolidationPromptPolicy.js
More file actions
68 lines (60 loc) · 1.84 KB
/
Copy pathconsolidationPromptPolicy.js
File metadata and controls
68 lines (60 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (C) 2024–2026 Aiko Hanasaki
// SPDX-License-Identifier: AGPL-3.0-only
import {
CONSOLIDATION_REGENERATION_PRESET_KEY,
GROUP_CHAT_CONSOLIDATION_PRESET_KEY,
} from './constants.js';
export function isRegenerationOnlyPreset(key) {
return String(key || '').trim() === CONSOLIDATION_REGENERATION_PRESET_KEY;
}
export function isGroupChatOnlyPreset(key) {
return String(key || '').trim() === GROUP_CHAT_CONSOLIDATION_PRESET_KEY;
}
export function isOrdinaryConsolidationPreset(key) {
return !isRegenerationOnlyPreset(key) && !isGroupChatOnlyPreset(key);
}
export function buildConsolidationPromptsExportData(
data = null,
builtIns = {},
getDisplayName = key => String(key || ''),
) {
const source = data && typeof data === 'object' ? data : {};
const overrides = source.overrides && typeof source.overrides === 'object'
? { ...source.overrides }
: {};
for (const [key, prompt] of Object.entries(builtIns || {})) {
if (
overrides[key] ||
typeof prompt !== 'string' ||
!prompt.trim()
) {
continue;
}
overrides[key] = {
displayName: getDisplayName(key, prompt),
prompt,
createdAt: null,
};
}
return {
...source,
overrides,
};
}
export function selectConsolidationDefaultPresetKey(data = null, builtIns = {}) {
const overrides = data?.overrides && typeof data.overrides === 'object'
? data.overrides
: {};
const preferred = String(data?.defaultPresetKey || '').trim();
if (
preferred &&
isOrdinaryConsolidationPreset(preferred) &&
(overrides[preferred] || builtIns[preferred])
) {
return preferred;
}
if (overrides.arc_default || builtIns.arc_default) return 'arc_default';
return Object.keys(overrides).find(isOrdinaryConsolidationPreset)
|| Object.keys(builtIns).find(isOrdinaryConsolidationPreset)
|| 'arc_default';
}