mirror of
https://github.com/sortedcord/omnia.git
synced 2026-07-22 03:52:48 +05:30
feat(gui): Duplicate existing model instances (#32)
(fixes Allow Instance Duplication Fixes #32)
This commit is contained in:
@@ -62,6 +62,50 @@ export class ProviderManager {
|
||||
};
|
||||
}
|
||||
|
||||
static duplicate(id: string): ModelProviderInstance | null {
|
||||
const db = getDb();
|
||||
const source = db
|
||||
.prepare("SELECT * FROM provider_instances WHERE id = ?")
|
||||
.get(id) as DbRow | undefined;
|
||||
if (!source) return null;
|
||||
|
||||
const newId = "provider-" + Date.now();
|
||||
const newName = `${source.name} (Copy)`;
|
||||
|
||||
const activeCount = db
|
||||
.prepare(
|
||||
"SELECT COUNT(*) as count FROM provider_instances WHERE isActive = 1 AND type = ?",
|
||||
)
|
||||
.get(source.type) as { count: number };
|
||||
const isActive = activeCount.count === 0 ? 1 : 0;
|
||||
|
||||
db.prepare(
|
||||
`INSERT INTO provider_instances (id, name, providerName, apiKey, isActive, modelName, type, maxContext, endpointUrl)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
).run(
|
||||
newId,
|
||||
newName,
|
||||
source.providerName,
|
||||
source.apiKey,
|
||||
isActive,
|
||||
source.modelName,
|
||||
source.type,
|
||||
source.maxContext,
|
||||
source.endpointUrl,
|
||||
);
|
||||
|
||||
return {
|
||||
id: newId,
|
||||
name: newName,
|
||||
providerName: source.providerName,
|
||||
apiKey: source.apiKey,
|
||||
isActive: isActive === 1,
|
||||
modelName: source.modelName || undefined,
|
||||
type: source.type as "generative" | "embedding",
|
||||
maxContext: source.maxContext,
|
||||
endpointUrl: source.endpointUrl || undefined,
|
||||
};
|
||||
}
|
||||
static delete(id: string): void {
|
||||
const db = getDb();
|
||||
const provider = db
|
||||
|
||||
Reference in New Issue
Block a user