mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-03 23:22:14 +08:00
* fix(models): preserve import metadata and enable new native models Signed-off-by: zqchris <chrisz83@gmail.com> * fix(models): preserve inherited window provenance and isolate model sizes Signed-off-by: zqchris <chrisz83@gmail.com> * fix(models): preserve sparse sync data and authoritative snapshots Signed-off-by: zqchris <chrisz83@gmail.com> * fix(pi): hide Fast preference paths from shell environments Signed-off-by: zqchris <chrisz83@gmail.com> * fix(models): scope sync metadata retention to the same connection Signed-off-by: zqchris <chrisz83@gmail.com> * fix(models): preserve failed catalogs and accept sparse native models Signed-off-by: zqchris <chrisz83@gmail.com> * test(models): align refresh and native defaults with import behavior Signed-off-by: zqchris <chrisz83@gmail.com> * test(models): align gateway defaults and await durable runner state Signed-off-by: zqchris <chrisz83@gmail.com> * fix(models): reconcile refreshed windows and preserve server native identity Signed-off-by: zqchris <chrisz83@gmail.com> * fix(pi): read Fast preferences from host memory over RPC Signed-off-by: zqchris <chrisz83@gmail.com> * fix(models): retain generation adapters and filter imported efforts Signed-off-by: zqchris <chrisz83@gmail.com> * fix(models): adapt reasoning metadata when filling runtimes Signed-off-by: zqchris <chrisz83@gmail.com> * docs(models): align Fast runtime guidance with host RPC Signed-off-by: zqchris <chrisz83@gmail.com> --------- Signed-off-by: zqchris <chrisz83@gmail.com>
66 lines
2.4 KiB
TypeScript
66 lines
2.4 KiB
TypeScript
import type {
|
|
AgentKind,
|
|
ProviderPreset,
|
|
ProviderPresetRuntime,
|
|
ProviderRuntimeModelConfig,
|
|
} from '@cindy/model-providers';
|
|
|
|
/** Remote presets may predate explicit Pi protocol metadata. Such a runtime is not saveable. */
|
|
export function isConfiguredPresetRuntime(
|
|
agent: AgentKind,
|
|
runtime: ProviderPresetRuntime | undefined,
|
|
): runtime is ProviderPresetRuntime {
|
|
return runtime !== undefined && (agent !== 'pi' || runtime.wireProtocol !== undefined);
|
|
}
|
|
|
|
export function configuredPresetAgents(preset: ProviderPreset): AgentKind[] {
|
|
return (Object.keys(preset.runtimes) as AgentKind[]).filter((agent) =>
|
|
isConfiguredPresetRuntime(agent, preset.runtimes[agent]),
|
|
);
|
|
}
|
|
|
|
export function savedCustomProviderModelShape(
|
|
model: ProviderRuntimeModelConfig,
|
|
includePiApi: boolean,
|
|
): ProviderRuntimeModelConfig {
|
|
const { piApi, ...portable } = structuredClone(model);
|
|
return {
|
|
...portable,
|
|
id: model.id.trim(),
|
|
name: model.name.trim(),
|
|
...(!includePiApi && !model.api && piApi ? { api: piApi } : {}),
|
|
...(includePiApi && piApi ? { piApi } : {}),
|
|
};
|
|
}
|
|
|
|
/** Copy reasoning metadata into a runtime's supported vocabulary without mutating the source. */
|
|
export function adaptCustomProviderModelEfforts(
|
|
source: ProviderRuntimeModelConfig,
|
|
agent: AgentKind,
|
|
): ProviderRuntimeModelConfig {
|
|
const model = structuredClone(source);
|
|
// Adapt every representation before persistence; canonical metadata otherwise
|
|
// bypasses the legacy field validator. Keep Pi's shared endpoint record intact.
|
|
if (agent !== 'pi') {
|
|
const supported = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
if (model.reasoningEfforts) {
|
|
model.reasoningEfforts = model.reasoningEfforts.filter(effort => supported.has(effort));
|
|
}
|
|
if (model.reasoningDefaultEffort != null &&
|
|
(!supported.has(model.reasoningDefaultEffort) ||
|
|
(model.reasoningEfforts && !model.reasoningEfforts.includes(model.reasoningDefaultEffort)))) {
|
|
delete model.reasoningDefaultEffort;
|
|
}
|
|
for (const metadata of [model, model.discoveredMetadata]) {
|
|
if (!metadata) continue;
|
|
if (metadata.efforts) metadata.efforts = metadata.efforts.filter(effort => supported.has(effort));
|
|
if (metadata.defaultEffort != null &&
|
|
(!supported.has(metadata.defaultEffort) ||
|
|
(metadata.efforts && !metadata.efforts.includes(metadata.defaultEffort)))) {
|
|
delete metadata.defaultEffort;
|
|
}
|
|
}
|
|
}
|
|
return model;
|
|
}
|