mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 07:03:44 +00:00
Custom provider WIP
This commit is contained in:
parent
389c80d7a8
commit
1f9a3a00cc
17 changed files with 1185 additions and 107 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import type { CustomProvidersStore } from "./stores/custom-providers-store.js";
|
||||
import type { ProviderKeysStore } from "./stores/provider-keys-store.js";
|
||||
import type { SessionsStore } from "./stores/sessions-store.js";
|
||||
import type { SettingsStore } from "./stores/settings-store.js";
|
||||
|
|
@ -12,16 +13,19 @@ export class AppStorage {
|
|||
readonly settings: SettingsStore;
|
||||
readonly providerKeys: ProviderKeysStore;
|
||||
readonly sessions: SessionsStore;
|
||||
readonly customProviders: CustomProvidersStore;
|
||||
|
||||
constructor(
|
||||
settings: SettingsStore,
|
||||
providerKeys: ProviderKeysStore,
|
||||
sessions: SessionsStore,
|
||||
customProviders: CustomProvidersStore,
|
||||
backend: StorageBackend,
|
||||
) {
|
||||
this.settings = settings;
|
||||
this.providerKeys = providerKeys;
|
||||
this.sessions = sessions;
|
||||
this.customProviders = customProviders;
|
||||
this.backend = backend;
|
||||
}
|
||||
|
||||
|
|
|
|||
62
packages/web-ui/src/storage/stores/custom-providers-store.ts
Normal file
62
packages/web-ui/src/storage/stores/custom-providers-store.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import type { Model } from "@mariozechner/pi-ai";
|
||||
import { Store } from "../store.js";
|
||||
import type { StoreConfig } from "../types.js";
|
||||
|
||||
export type AutoDiscoveryProviderType = "ollama" | "llama.cpp" | "vllm" | "lmstudio";
|
||||
|
||||
export type CustomProviderType =
|
||||
| AutoDiscoveryProviderType // Auto-discovery - models fetched on-demand
|
||||
| "openai-completions" // Manual models - stored in provider.models
|
||||
| "openai-responses" // Manual models - stored in provider.models
|
||||
| "anthropic-messages"; // Manual models - stored in provider.models
|
||||
|
||||
export interface CustomProvider {
|
||||
id: string; // UUID
|
||||
name: string; // Display name, also used as Model.provider
|
||||
type: CustomProviderType;
|
||||
baseUrl: string;
|
||||
apiKey?: string; // Optional, applies to all models
|
||||
|
||||
// For manual types ONLY - models stored directly on provider
|
||||
// Auto-discovery types: models fetched on-demand, never stored
|
||||
models?: Model<any>[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Store for custom LLM providers (auto-discovery servers + manual providers).
|
||||
*/
|
||||
export class CustomProvidersStore extends Store {
|
||||
getConfig(): StoreConfig {
|
||||
return {
|
||||
name: "custom-providers",
|
||||
};
|
||||
}
|
||||
|
||||
async get(id: string): Promise<CustomProvider | null> {
|
||||
return this.getBackend().get("custom-providers", id);
|
||||
}
|
||||
|
||||
async set(provider: CustomProvider): Promise<void> {
|
||||
await this.getBackend().set("custom-providers", provider.id, provider);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
await this.getBackend().delete("custom-providers", id);
|
||||
}
|
||||
|
||||
async getAll(): Promise<CustomProvider[]> {
|
||||
const keys = await this.getBackend().keys("custom-providers");
|
||||
const providers: CustomProvider[] = [];
|
||||
for (const key of keys) {
|
||||
const provider = await this.get(key);
|
||||
if (provider) {
|
||||
providers.push(provider);
|
||||
}
|
||||
}
|
||||
return providers;
|
||||
}
|
||||
|
||||
async has(id: string): Promise<boolean> {
|
||||
return this.getBackend().has("custom-providers", id);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue