@flanksource/clicky-ui 0.3.29 → 0.3.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai.cjs +48 -3
- package/dist/ai.cjs.map +1 -1
- package/dist/ai.js +46 -1
- package/dist/ai.js.map +1 -1
- package/dist/components/DateField.d.ts +1 -1
- package/dist/components/DatePicker.d.ts +1 -1
- package/dist/components/DateTimePicker.d.ts +1 -1
- package/dist/components/mdx-editor-callout-model.d.ts +1 -1
- package/dist/data/MarkdownEditor.model.d.ts +1 -1
- package/dist/data/ai/ChatWindow.catalogs.cjs +11 -5
- package/dist/data/ai/ChatWindow.catalogs.cjs.map +1 -1
- package/dist/data/ai/ChatWindow.catalogs.d.ts +2 -1
- package/dist/data/ai/ChatWindow.catalogs.d.ts.map +1 -1
- package/dist/data/ai/ChatWindow.catalogs.js +11 -5
- package/dist/data/ai/ChatWindow.catalogs.js.map +1 -1
- package/dist/data/ai/ChatWindow.cjs +1 -0
- package/dist/data/ai/ChatWindow.cjs.map +1 -1
- package/dist/data/ai/ChatWindow.d.ts.map +1 -1
- package/dist/data/ai/ChatWindow.js +1 -0
- package/dist/data/ai/ChatWindow.js.map +1 -1
- package/dist/data/ai/PromptRunEditor/VariablesField.cjs +79 -0
- package/dist/data/ai/PromptRunEditor/VariablesField.cjs.map +1 -0
- package/dist/data/ai/PromptRunEditor/VariablesField.d.ts +8 -0
- package/dist/data/ai/PromptRunEditor/VariablesField.d.ts.map +1 -0
- package/dist/data/ai/PromptRunEditor/VariablesField.js +79 -0
- package/dist/data/ai/PromptRunEditor/VariablesField.js.map +1 -0
- package/dist/data/ai/PromptRunEditor/index.cjs +61 -69
- package/dist/data/ai/PromptRunEditor/index.cjs.map +1 -1
- package/dist/data/ai/PromptRunEditor/index.d.ts +11 -1
- package/dist/data/ai/PromptRunEditor/index.d.ts.map +1 -1
- package/dist/data/ai/PromptRunEditor/index.js +61 -69
- package/dist/data/ai/PromptRunEditor/index.js.map +1 -1
- package/dist/data/ai/PromptRunEditor/model.cjs.map +1 -1
- package/dist/data/ai/PromptRunEditor/model.d.ts +2 -0
- package/dist/data/ai/PromptRunEditor/model.d.ts.map +1 -1
- package/dist/data/ai/PromptRunEditor/model.js.map +1 -1
- package/dist/data/ai/SpecRuntimeEditor/ModelSection.cjs +4 -3
- package/dist/data/ai/SpecRuntimeEditor/ModelSection.cjs.map +1 -1
- package/dist/data/ai/SpecRuntimeEditor/ModelSection.d.ts.map +1 -1
- package/dist/data/ai/SpecRuntimeEditor/ModelSection.js +2 -1
- package/dist/data/ai/SpecRuntimeEditor/ModelSection.js.map +1 -1
- package/dist/data/ai/SpecRuntimeEditor/PermissionModeField.cjs +2 -2
- package/dist/data/ai/SpecRuntimeEditor/PermissionModeField.cjs.map +1 -1
- package/dist/data/ai/SpecRuntimeEditor/PermissionModeField.js +1 -1
- package/dist/data/ai/SpecRuntimeEditor/index.cjs +4 -3
- package/dist/data/ai/SpecRuntimeEditor/index.cjs.map +1 -1
- package/dist/data/ai/SpecRuntimeEditor/index.d.ts.map +1 -1
- package/dist/data/ai/SpecRuntimeEditor/index.js +2 -1
- package/dist/data/ai/SpecRuntimeEditor/index.js.map +1 -1
- package/dist/data/ai/index.d.ts +3 -2
- package/dist/data/ai/index.d.ts.map +1 -1
- package/dist/data/ai/runtime-profile.cjs.map +1 -1
- package/dist/data/ai/runtime-profile.d.ts +9 -7
- package/dist/data/ai/runtime-profile.d.ts.map +1 -1
- package/dist/data/ai/runtime-profile.js.map +1 -1
- package/dist/data/ai/runtime-profiles/OrderedPresetSelect.cjs +111 -0
- package/dist/data/ai/runtime-profiles/OrderedPresetSelect.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/OrderedPresetSelect.d.ts +7 -0
- package/dist/data/ai/runtime-profiles/OrderedPresetSelect.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/OrderedPresetSelect.js +111 -0
- package/dist/data/ai/runtime-profiles/OrderedPresetSelect.js.map +1 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.cjs +313 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.d.ts +8 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.js +313 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategiesEditor.js.map +1 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategyConditionRow.cjs +98 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategyConditionRow.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategyConditionRow.d.ts +11 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategyConditionRow.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategyConditionRow.js +98 -0
- package/dist/data/ai/runtime-profiles/PermissionStrategyConditionRow.js.map +1 -0
- package/dist/data/ai/runtime-profiles/PresetSpecEditor.cjs +35 -0
- package/dist/data/ai/runtime-profiles/PresetSpecEditor.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/PresetSpecEditor.d.ts +11 -0
- package/dist/data/ai/runtime-profiles/PresetSpecEditor.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/PresetSpecEditor.js +35 -0
- package/dist/data/ai/runtime-profiles/PresetSpecEditor.js.map +1 -0
- package/dist/data/ai/runtime-profiles/PresetWorkspace.cjs +179 -0
- package/dist/data/ai/runtime-profiles/PresetWorkspace.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/PresetWorkspace.d.ts +22 -0
- package/dist/data/ai/runtime-profiles/PresetWorkspace.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/PresetWorkspace.js +179 -0
- package/dist/data/ai/runtime-profiles/PresetWorkspace.js.map +1 -0
- package/dist/data/ai/runtime-profiles/ProfileSpecEditor.cjs +57 -0
- package/dist/data/ai/runtime-profiles/ProfileSpecEditor.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/ProfileSpecEditor.d.ts +18 -0
- package/dist/data/ai/runtime-profiles/ProfileSpecEditor.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/ProfileSpecEditor.js +57 -0
- package/dist/data/ai/runtime-profiles/ProfileSpecEditor.js.map +1 -0
- package/dist/data/ai/runtime-profiles/ProfileWorkspace.cjs +135 -0
- package/dist/data/ai/runtime-profiles/ProfileWorkspace.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/ProfileWorkspace.d.ts +23 -0
- package/dist/data/ai/runtime-profiles/ProfileWorkspace.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/ProfileWorkspace.js +135 -0
- package/dist/data/ai/runtime-profiles/ProfileWorkspace.js.map +1 -0
- package/dist/data/ai/runtime-profiles/ResolutionInspector.cjs +85 -0
- package/dist/data/ai/runtime-profiles/ResolutionInspector.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/ResolutionInspector.d.ts +7 -0
- package/dist/data/ai/runtime-profiles/ResolutionInspector.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/ResolutionInspector.js +85 -0
- package/dist/data/ai/runtime-profiles/ResolutionInspector.js.map +1 -0
- package/dist/data/ai/runtime-profiles/ResolutionTrace.cjs +42 -0
- package/dist/data/ai/runtime-profiles/ResolutionTrace.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/ResolutionTrace.d.ts +6 -0
- package/dist/data/ai/runtime-profiles/ResolutionTrace.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/ResolutionTrace.js +42 -0
- package/dist/data/ai/runtime-profiles/ResolutionTrace.js.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeLibraryList.cjs +93 -0
- package/dist/data/ai/runtime-profiles/RuntimeLibraryList.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeLibraryList.d.ts +18 -0
- package/dist/data/ai/runtime-profiles/RuntimeLibraryList.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeLibraryList.js +93 -0
- package/dist/data/ai/runtime-profiles/RuntimeLibraryList.js.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimePersistenceBar.cjs +44 -0
- package/dist/data/ai/runtime-profiles/RuntimePersistenceBar.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimePersistenceBar.d.ts +6 -0
- package/dist/data/ai/runtime-profiles/RuntimePersistenceBar.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimePersistenceBar.js +44 -0
- package/dist/data/ai/runtime-profiles/RuntimePersistenceBar.js.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.cjs +198 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.d.ts +12 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.js +198 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.js.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.model.cjs +97 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.model.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.model.d.ts +26 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.model.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.model.js +97 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilePicker.model.js.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.cjs +143 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.d.ts +25 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.js +143 -0
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.js.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeStatusNotice.cjs +41 -0
- package/dist/data/ai/runtime-profiles/RuntimeStatusNotice.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeStatusNotice.d.ts +8 -0
- package/dist/data/ai/runtime-profiles/RuntimeStatusNotice.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/RuntimeStatusNotice.js +41 -0
- package/dist/data/ai/runtime-profiles/RuntimeStatusNotice.js.map +1 -0
- package/dist/data/ai/runtime-profiles/index.d.ts +20 -0
- package/dist/data/ai/runtime-profiles/index.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/types.d.ts +50 -0
- package/dist/data/ai/runtime-profiles/types.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/use-permission-catalog.cjs +37 -0
- package/dist/data/ai/runtime-profiles/use-permission-catalog.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/use-permission-catalog.d.ts +5 -0
- package/dist/data/ai/runtime-profiles/use-permission-catalog.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/use-permission-catalog.js +37 -0
- package/dist/data/ai/runtime-profiles/use-permission-catalog.js.map +1 -0
- package/dist/data/ai/runtime-profiles/use-resolution.cjs +43 -0
- package/dist/data/ai/runtime-profiles/use-resolution.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/use-resolution.d.ts +4 -0
- package/dist/data/ai/runtime-profiles/use-resolution.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/use-resolution.js +43 -0
- package/dist/data/ai/runtime-profiles/use-resolution.js.map +1 -0
- package/dist/data/ai/runtime-profiles/use-runtime-families.cjs +38 -0
- package/dist/data/ai/runtime-profiles/use-runtime-families.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/use-runtime-families.d.ts +3 -0
- package/dist/data/ai/runtime-profiles/use-runtime-families.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/use-runtime-families.js +38 -0
- package/dist/data/ai/runtime-profiles/use-runtime-families.js.map +1 -0
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.cjs +107 -0
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.cjs.map +1 -0
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.d.ts +35 -0
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.d.ts.map +1 -0
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.js +107 -0
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.js.map +1 -0
- package/dist/data/ai/use-session-scroll.cjs.map +1 -1
- package/dist/data/ai/use-session-scroll.d.ts +2 -2
- package/dist/data/ai/use-session-scroll.d.ts.map +1 -1
- package/dist/data/ai/use-session-scroll.js.map +1 -1
- package/dist/data/badge-variants.d.ts +1 -1
- package/dist/data/runtime/RuntimeBar.cjs +3 -2
- package/dist/data/runtime/RuntimeBar.cjs.map +1 -1
- package/dist/data/runtime/RuntimeBar.d.ts.map +1 -1
- package/dist/data/runtime/RuntimeBar.js +3 -2
- package/dist/data/runtime/RuntimeBar.js.map +1 -1
- package/dist/data/runtime/runtime-field-support.cjs +3 -3
- package/dist/data/runtime/runtime-field-support.cjs.map +1 -1
- package/dist/data/runtime/runtime-field-support.js +1 -1
- package/dist/data/runtime/runtime-mode.cjs +14 -47
- package/dist/data/runtime/runtime-mode.cjs.map +1 -1
- package/dist/data/runtime/runtime-mode.d.ts +5 -7
- package/dist/data/runtime/runtime-mode.d.ts.map +1 -1
- package/dist/data/runtime/runtime-mode.js +7 -39
- package/dist/data/runtime/runtime-mode.js.map +1 -1
- package/dist/data/version-info.cjs +3 -3
- package/dist/data/version-info.js +3 -3
- package/dist/index.cjs +52 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/permission-strategies.cjs +155 -0
- package/dist/lib/permission-strategies.cjs.map +1 -0
- package/dist/lib/permission-strategies.d.ts +35 -0
- package/dist/lib/permission-strategies.d.ts.map +1 -0
- package/dist/lib/permission-strategies.js +155 -0
- package/dist/lib/permission-strategies.js.map +1 -0
- package/dist/lib/runtime-family.cjs +51 -0
- package/dist/lib/runtime-family.cjs.map +1 -0
- package/dist/lib/runtime-family.d.ts +25 -0
- package/dist/lib/runtime-family.d.ts.map +1 -0
- package/dist/lib/runtime-family.js +51 -0
- package/dist/lib/runtime-family.js.map +1 -0
- package/dist/lib/runtime-profile-model.cjs +129 -0
- package/dist/lib/runtime-profile-model.cjs.map +1 -0
- package/dist/lib/runtime-profile-model.d.ts +30 -0
- package/dist/lib/runtime-profile-model.d.ts.map +1 -0
- package/dist/lib/runtime-profile-model.js +129 -0
- package/dist/lib/runtime-profile-model.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/utils.cjs +52 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +5 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +53 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { moveItem, isPlainObject } from "./collections.js";
|
|
2
|
+
import { runtimeModeFromModel, familyForModel, modeOptionFor } from "./runtime-family.js";
|
|
3
|
+
function reorderProfilePresets(profile, from, to) {
|
|
4
|
+
if (!profile.presets[from] || !profile.presets[to]) {
|
|
5
|
+
throw new Error(`cannot reorder preset from ${from} to ${to}`);
|
|
6
|
+
}
|
|
7
|
+
return { ...profile, presets: moveItem(profile.presets, from, to) };
|
|
8
|
+
}
|
|
9
|
+
function presetForRef(ref, presets) {
|
|
10
|
+
const name = ref.trim().toLowerCase();
|
|
11
|
+
return presets.find((preset) => preset.id === ref) ?? presets.find((preset) => preset.name.trim().toLowerCase() === name);
|
|
12
|
+
}
|
|
13
|
+
function presetsOf(profile, presets) {
|
|
14
|
+
const found = [];
|
|
15
|
+
const missing = [];
|
|
16
|
+
for (const ref of profile.presets) {
|
|
17
|
+
const preset = presetForRef(ref, presets);
|
|
18
|
+
if (preset) found.push(preset);
|
|
19
|
+
else missing.push(ref);
|
|
20
|
+
}
|
|
21
|
+
return { found, missing };
|
|
22
|
+
}
|
|
23
|
+
function authoredRuntimeSpec(profile, presets) {
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
|
+
if (!profile) return {};
|
|
26
|
+
const runtime = {};
|
|
27
|
+
for (const preset of presetsOf(profile, presets).found) {
|
|
28
|
+
if ((_a = preset.spec.model) == null ? void 0 : _a.trim()) runtime.model = preset.spec.model;
|
|
29
|
+
if ((_b = preset.spec.mode) == null ? void 0 : _b.trim()) runtime.mode = preset.spec.mode;
|
|
30
|
+
}
|
|
31
|
+
if ((_c = profile.spec.model) == null ? void 0 : _c.trim()) runtime.model = profile.spec.model;
|
|
32
|
+
if ((_d = profile.spec.mode) == null ? void 0 : _d.trim()) runtime.mode = profile.spec.mode;
|
|
33
|
+
return runtime;
|
|
34
|
+
}
|
|
35
|
+
function referencedBy(preset, profiles) {
|
|
36
|
+
const name = preset.name.trim().toLowerCase();
|
|
37
|
+
return profiles.filter(
|
|
38
|
+
(profile) => profile.presets.some(
|
|
39
|
+
(ref) => ref === preset.id || ref.trim().toLowerCase() === name
|
|
40
|
+
)
|
|
41
|
+
).map((profile) => profile.name);
|
|
42
|
+
}
|
|
43
|
+
function duplicateName(name, existing) {
|
|
44
|
+
return nextNewName(`${name.trim()} copy`, existing);
|
|
45
|
+
}
|
|
46
|
+
function nextNewName(base, existing) {
|
|
47
|
+
const occupied = new Set(existing.map((item) => item.trim().toLowerCase()));
|
|
48
|
+
if (!occupied.has(base.toLowerCase())) return base;
|
|
49
|
+
let index = 2;
|
|
50
|
+
while (occupied.has(`${base} ${index}`.toLowerCase())) index += 1;
|
|
51
|
+
return `${base} ${index}`;
|
|
52
|
+
}
|
|
53
|
+
function uniqueName(name, id, records) {
|
|
54
|
+
const normalized = name.trim().toLowerCase();
|
|
55
|
+
if (!normalized) return false;
|
|
56
|
+
return !records.some(
|
|
57
|
+
(record) => record.id !== id && record.name.trim().toLowerCase() === normalized
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function permissionTarget(spec, families) {
|
|
61
|
+
var _a;
|
|
62
|
+
const model = spec == null ? void 0 : spec.model;
|
|
63
|
+
const mode = runtimeModeFromModel(model) || ((_a = spec == null ? void 0 : spec.mode) == null ? void 0 : _a.trim());
|
|
64
|
+
const family = familyForModel(families, [], model);
|
|
65
|
+
if (!family || !mode || !modeOptionFor(families, mode, family.id)) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
return { provider: family.provider, mode };
|
|
69
|
+
}
|
|
70
|
+
function newProfileRecord(profiles, id) {
|
|
71
|
+
const name = nextNewName(
|
|
72
|
+
"New profile",
|
|
73
|
+
profiles.map((item) => item.name)
|
|
74
|
+
);
|
|
75
|
+
return { id, name, spec: {}, presets: [] };
|
|
76
|
+
}
|
|
77
|
+
function newPresetRecord(presets, id) {
|
|
78
|
+
const name = nextNewName(
|
|
79
|
+
"New preset",
|
|
80
|
+
presets.map((item) => item.name)
|
|
81
|
+
);
|
|
82
|
+
return { id, name, scope: "surface", spec: {} };
|
|
83
|
+
}
|
|
84
|
+
function duplicateRecord(records, sourceId, id) {
|
|
85
|
+
const source = records.find((record) => record.id === sourceId);
|
|
86
|
+
if (!source) throw new Error(`cannot duplicate missing record "${sourceId}"`);
|
|
87
|
+
return {
|
|
88
|
+
...structuredClone(source),
|
|
89
|
+
id,
|
|
90
|
+
name: duplicateName(
|
|
91
|
+
source.name,
|
|
92
|
+
records.map((record) => record.name)
|
|
93
|
+
)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function selectionAfterDelete(records, deletedId, selectedId) {
|
|
97
|
+
var _a;
|
|
98
|
+
if (selectedId !== deletedId) return selectedId;
|
|
99
|
+
return (_a = records.find((record) => record.id !== deletedId)) == null ? void 0 : _a.id;
|
|
100
|
+
}
|
|
101
|
+
function mergeRuntimeSpec(base, overlay) {
|
|
102
|
+
return mergeRecords(base, overlay);
|
|
103
|
+
}
|
|
104
|
+
function mergeRecords(base, overlay) {
|
|
105
|
+
const merged = structuredClone(base);
|
|
106
|
+
for (const [key, value] of Object.entries(overlay)) {
|
|
107
|
+
if (value === void 0) continue;
|
|
108
|
+
const current = merged[key];
|
|
109
|
+
merged[key] = isPlainObject(current) && isPlainObject(value) ? mergeRecords(current, value) : structuredClone(value);
|
|
110
|
+
}
|
|
111
|
+
return merged;
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
authoredRuntimeSpec,
|
|
115
|
+
duplicateName,
|
|
116
|
+
duplicateRecord,
|
|
117
|
+
mergeRuntimeSpec,
|
|
118
|
+
newPresetRecord,
|
|
119
|
+
newProfileRecord,
|
|
120
|
+
nextNewName,
|
|
121
|
+
permissionTarget,
|
|
122
|
+
presetForRef,
|
|
123
|
+
presetsOf,
|
|
124
|
+
referencedBy,
|
|
125
|
+
reorderProfilePresets,
|
|
126
|
+
selectionAfterDelete,
|
|
127
|
+
uniqueName
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=runtime-profile-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-profile-model.js","sources":["../../src/lib/runtime-profile-model.ts"],"sourcesContent":["import { isPlainObject, moveItem } from \"./collections\";\nimport {\n type SpecRuntimeFamily,\n} from \"../data/runtime/runtime-mode\";\nimport {\n familyForModel,\n modeOptionFor,\n runtimeModeFromModel,\n} from \"./runtime-family\";\nimport type { RuntimePreset, RuntimeProfile } from \"../data/ai/runtime-profile\";\nimport type { AISpecRuntimeSpec } from \"../data/ai/SpecRuntimeEditor.model\";\nimport type { RuntimePermissionTarget } from \"../data/ai/runtime-profiles/types\";\n\nexport function reorderProfilePresets(\n profile: RuntimeProfile,\n from: number,\n to: number,\n): RuntimeProfile {\n if (!profile.presets[from] || !profile.presets[to]) {\n throw new Error(`cannot reorder preset from ${from} to ${to}`);\n }\n return { ...profile, presets: moveItem(profile.presets, from, to) };\n}\n\nexport function presetForRef(\n ref: string,\n presets: RuntimePreset[],\n): RuntimePreset | undefined {\n const name = ref.trim().toLowerCase();\n return (\n presets.find((preset) => preset.id === ref) ??\n presets.find((preset) => preset.name.trim().toLowerCase() === name)\n );\n}\n\nexport function presetsOf(\n profile: Pick<RuntimeProfile, \"presets\">,\n presets: RuntimePreset[],\n): { found: RuntimePreset[]; missing: string[] } {\n const found: RuntimePreset[] = [];\n const missing: string[] = [];\n for (const ref of profile.presets) {\n const preset = presetForRef(ref, presets);\n if (preset) found.push(preset);\n else missing.push(ref);\n }\n return { found, missing };\n}\n\nexport function authoredRuntimeSpec(\n profile: RuntimeProfile | undefined,\n presets: RuntimePreset[],\n): Pick<AISpecRuntimeSpec, \"model\" | \"mode\"> {\n if (!profile) return {};\n const runtime: Pick<AISpecRuntimeSpec, \"model\" | \"mode\"> = {};\n for (const preset of presetsOf(profile, presets).found) {\n if (preset.spec.model?.trim()) runtime.model = preset.spec.model;\n if (preset.spec.mode?.trim()) runtime.mode = preset.spec.mode;\n }\n if (profile.spec.model?.trim()) runtime.model = profile.spec.model;\n if (profile.spec.mode?.trim()) runtime.mode = profile.spec.mode;\n return runtime;\n}\n\nexport function referencedBy(\n preset: Pick<RuntimePreset, \"id\" | \"name\">,\n profiles: RuntimeProfile[],\n): string[] {\n const name = preset.name.trim().toLowerCase();\n return profiles\n .filter((profile) =>\n profile.presets.some(\n (ref) => ref === preset.id || ref.trim().toLowerCase() === name,\n ),\n )\n .map((profile) => profile.name);\n}\n\nexport function duplicateName(name: string, existing: string[]): string {\n return nextNewName(`${name.trim()} copy`, existing);\n}\n\nexport function nextNewName(base: string, existing: string[]): string {\n const occupied = new Set(existing.map((item) => item.trim().toLowerCase()));\n if (!occupied.has(base.toLowerCase())) return base;\n let index = 2;\n while (occupied.has(`${base} ${index}`.toLowerCase())) index += 1;\n return `${base} ${index}`;\n}\n\nexport function uniqueName(\n name: string,\n id: string,\n records: Array<{ id: string; name: string }>,\n) {\n const normalized = name.trim().toLowerCase();\n if (!normalized) return false;\n return !records.some(\n (record) =>\n record.id !== id && record.name.trim().toLowerCase() === normalized,\n );\n}\n\nexport function permissionTarget(\n spec: AISpecRuntimeSpec | undefined,\n families: SpecRuntimeFamily[],\n): RuntimePermissionTarget | undefined {\n const model = spec?.model;\n const mode = runtimeModeFromModel(model) || spec?.mode?.trim();\n const family = familyForModel(families, [], model);\n if (!family || !mode || !modeOptionFor(families, mode, family.id)) {\n return undefined;\n }\n return { provider: family.provider, mode };\n}\n\nexport function newProfileRecord(\n profiles: RuntimeProfile[],\n id: string,\n): RuntimeProfile {\n const name = nextNewName(\n \"New profile\",\n profiles.map((item) => item.name),\n );\n return { id, name, spec: {}, presets: [] };\n}\n\nexport function newPresetRecord(\n presets: RuntimePreset[],\n id: string,\n): RuntimePreset {\n const name = nextNewName(\n \"New preset\",\n presets.map((item) => item.name),\n );\n return { id, name, scope: \"surface\", spec: {} };\n}\n\nexport function duplicateRecord<T extends { id: string; name: string }>(\n records: T[],\n sourceId: string,\n id: string,\n): T {\n const source = records.find((record) => record.id === sourceId);\n if (!source) throw new Error(`cannot duplicate missing record \"${sourceId}\"`);\n return {\n ...structuredClone(source),\n id,\n name: duplicateName(\n source.name,\n records.map((record) => record.name),\n ),\n };\n}\n\nexport function selectionAfterDelete(\n records: Array<{ id: string }>,\n deletedId: string,\n selectedId: string | undefined,\n): string | undefined {\n if (selectedId !== deletedId) return selectedId;\n return records.find((record) => record.id !== deletedId)?.id;\n}\n\nexport function mergeRuntimeSpec<T extends AISpecRuntimeSpec>(\n base: AISpecRuntimeSpec,\n overlay: T,\n): T {\n return mergeRecords(base, overlay) as T;\n}\n\nfunction mergeRecords(\n base: Record<string, unknown>,\n overlay: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = structuredClone(base);\n for (const [key, value] of Object.entries(overlay)) {\n if (value === undefined) continue;\n const current = merged[key];\n merged[key] =\n isPlainObject(current) && isPlain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