No JSDoc comment in source yet.
API
@Component({
name: "ProjectConfigServiceImpl",
key: "@prismshadow/penguin-server#ProjectConfigService",
})
export class ProjectConfigService implements ProjectConfigStore {
@Use() private readonly paths!: ProjectPaths;
@Use() private readonly promotions?: ModelPromotions;
@Use() private readonly providerAuthTokens?: ModelProviderAuthTokens;
setModelApiKeyResolver(resolver: (context: ModelRequestContext) => Promise<string | undefined>): void;
async readRaw(projectId: string): Promise<RawTable>;
async migrateStoredConfigs(): Promise<void>;
async loadConfig(projectId: string): Promise<ProjectConfig>;
async writeRaw(projectId: string, data: RawTable): Promise<void>;
async writeInitialConfig(projectId: string, name: string): Promise<void>;
async ensurePresetModels(projectId: string): Promise<boolean>;
async seedPresetPromotions(projectId: string): Promise<void>;
async getName(projectId: string): Promise<string | undefined>;
async setName(projectId: string, name: string): Promise<void>;
async getDefaultModelRef(projectId: string): Promise<ModelRef | undefined>;
async setDefaultModelRef(projectId: string, ref: ModelRefDto): Promise<ModelRefDto>;
async getToolModels(projectId: string): Promise<Record<string, ModelRefDto>>;
async setToolModel(projectId: string, key: string, model: ModelRefDto | null): Promise<Record<string, ModelRefDto>>;
async modelRequestApiKey(projectId: string, model: ModelRefDto): Promise<string | undefined>;
async getChatDefaults(projectId: string): Promise<ChatDefaultsDto>;
async setChatDefaults(projectId: string, req: ChatDefaultsDto): Promise<ChatDefaultsDto>;
async getCommandPolicy(projectId: string): Promise<CommandPolicyDto>;
async setCommandPolicy(projectId: string, req: {
enabled?: boolean;
rules: {
name: string;
pattern: string;
description?: string;
enabled?: boolean;
action?: "deny" | "ask";
}[];
}): Promise<CommandPolicyDto>;
async getPluginTables(projectId: string): Promise<PluginTables>;
async setPluginTables(projectId: string, tables: PluginTables): Promise<PluginTables>;
async getPricing(projectId: string, provider: string, modelId: string): Promise<TieredRates | undefined>;
async detectVision(projectId: string, req: ModelVisionDetectRequest): Promise<ModelVisionDetectResponse>;
async completeOnce(projectId: string, prompt: string): Promise<UtilityCompletion>;
async testModel(projectId: string, req: ModelTestRequest, testRequestFor?: ModelTestRequestSource): Promise<ModelTestResponse>;
async detectProtocol(projectId: string, req: ModelProtocolDetectRequest): Promise<ModelProtocolDetectResponse>;
async listEndpointModels(req: EndpointModelListRequest, listImpl: typeof coreListEndpointModels = coreListEndpointModels, timeoutMs: number = LIST_MODELS_TIMEOUT_MS): Promise<EndpointModelListResponse>;
async getModels(projectId: string): Promise<ModelsResponse>;
async updateModels(projectId: string, req: ModelsUpdateRequest): Promise<ModelsResponse>;
async setProviderConnection(projectId: string, provider: string, patch: ProviderConnectionUpdate): Promise<ProviderConnectionResponse>;
async setGroupApiKey(projectId: string, provider: string, apiKey: string): Promise<GroupKeyApplied>;
async setGroupApiKeyWithProviderAuthToken(projectId: string, provider: string, apiKey: string, token: Omit<ModelProviderAuthToken, "provider" | "updatedAt">, options: { expectedRefreshToken?: string } = {}): Promise<number>;
async getGroupApiKey(projectId: string, provider: string): Promise<string | undefined>;
async getModelApiKey(projectId: string, provider: string, modelId: string): Promise<string | undefined>;
async getGroupBalanceKey(projectId: string, provider: string): Promise<string | undefined>;
async mergePlatformModels(projectId: string, provider: string, catalog: PlatformModelCatalog, apiKey: string, applyKeyToExisting: boolean): Promise<PlatformModelApplyResult>;
async syncPresets(projectId: string, mode: PresetSyncMode): Promise<PresetSyncResponse>;
}Dependencies & Wiring
Extracted from class decoratorsMethods (37)
setModelApiKeyResolver
setModelApiKeyResolver(resolver: (context: ModelRequestContext) => Promise<string | undefined>): void(context: ModelRequestContext) => Promise<string | undefined>voidreadRaw
async readRaw(projectId: string): Promise<RawTable>Reads the raw TOML object; returns an empty object if the file doesn't exist (does not write to disk).
stringPromise<RawTable>migrateStoredConfigs
async migrateStoredConfigs(): Promise<void>Reads every Project's config once through readTable, so what the server's read path writes back — core's one-time migrations and the server's own (project-config-migrations.ts: Penguin Go's pre-MMSP routes) — is on disk before anything else opens a file: core's loader, which a Session created or resumed through the SDK reads with, runs none of the server's. Called once as the App starts, before the schedulers. A file that does not parse is left for the next read that needs it to report. Exists for the one-time migrations alone, so it goes with them at the 0.3.0 release preparation (changelog/0.2.17/2026-10-15-backward-compatibility.md).
Promise<void>loadConfig
async loadConfig(projectId: string): Promise<ProjectConfig>Typed view of the same cached table — byte-for-byte the semantics of core's
loadProjectConfig (missing file → core's default config, which carries no models; legacy
format → the same error, via core's shared narrowing) without its per-call readFile + parse.
Serves the scheduler's model-ref validation (see schedule-store).
stringPromise<ProjectConfig>writeRaw
async writeRaw(projectId: string, data: RawTable): Promise<void>Writes the whole object to disk: the file inlines secrets like api_key, always written with mode 0600, and replaced atomically so a crash mid-write cannot truncate it — matching core's saveProjectConfig behavior.
stringRawTablePromise<void>writeInitialConfig
async writeInitialConfig(projectId: string, name: string): Promise<void>Initial config for a newly created Project: display name + the built-in catalog's seed
(presetProjectConfig: no default model — the user chooses one — each built-in group's
[providers.<id>] table —
endpoint and protocol — and all preset entries; an entry stores its catalog facts, plus a
protocol or endpoint only where it differs from its group's table — and no key). From here
on the file alone says where every request goes; the catalog is not read again when one is
built. Users only need to fill in an API key as needed, once per group (left blank on a
first-party vendor group, which names no base URL, MMSP's client reads the vendor's
environment variable).
stringstringPromise<void>ensurePresetModels
async ensurePresetModels(projectId: string): Promise<boolean>Backfills preset models (for onboarding an existing Project, e.g. the
default_project shared with the CLI when the first user is onboarded — its
directory already existed and never went through writeInitialConfig, so it
previously had no models and no default model).
Only backfills when there are no models at all: a Project that already has models configured (via the CLI or edited by the user) is left as-is, and its other fields (name, etc.) are preserved too — existing config is never overwritten. The built-in groups' tables come with the rows, as at init, except that a table the file already holds is kept as it is and the rows are stored against it (presetAdditions). Returns whether it wrote the presets, which is when their promotions are to be seeded too (seedPresetPromotions).
stringPromise<boolean>seedPresetPromotions
async seedPresetPromotions(projectId: string): Promise<void>Stores the built-in catalog's flat promotions for a Project just seeded with the preset
models: the file carries their list prices, and these fractions are the rest of what the
presets bill. The rows reference the Project's projects row (foreign keys are enforced),
so this runs once that row exists.
stringPromise<void>getName
async getName(projectId: string): Promise<string | undefined>Project display name (the toml's name; returns undefined if unset, the frontend falls back to displaying the id).
stringPromise<string | undefined>setName
async setName(projectId: string, name: string): Promise<void>Rewrites the display name, preserving every other field (models, credentials, default model): read-modify-write of the same toml, like ensurePresetModels. The id itself is immutable — only this label changes.
stringstringPromise<void>getDefaultModelRef
async getDefaultModelRef(projectId: string): Promise<ModelRef | undefined>Paired reference of the default Model; returns undefined if unconfigured (or in the old string format).
stringPromise<ModelRef | undefined>setDefaultModelRef
async setDefaultModelRef(projectId: string, ref: ModelRefDto): Promise<ModelRefDto>Sets the default Model to an already-configured entry (the narrow
PUT /models/default route): rewrites only the top-level default_model — the SAME key
the models page's whole-table PUT maintains, so the two surfaces stay single-sourced —
preserving every other field via read-modify-write. The pair must name an entry in
models (the identical rule updateModels applies to defaultModel); a reference
outside the config is a 400, since createSession would error on it immediately. No
runtime invalidation: existing Sessions pin their model at creation, and this route
never touches credentials.
stringModelRefDtoPromise<ModelRefDto>getToolModels
async getToolModels(projectId: string): Promise<Record<string, ModelRefDto>>stringPromise<Record<string, ModelRefDto>>setToolModel
async setToolModel(projectId: string, key: string, model: ModelRefDto | null): Promise<Record<string, ModelRefDto>>Binds one [tools] key, or with null unbinds it: read-modify-write of the same toml, under
the lock the whole-table PUT and "Restore defaults" take, so a binding saved beside them sees
their final rows. The model must be a configured row (400 otherwise); the key's grammar and
which models it accepts are the declaring plugin's (ToolModelBindings checks them first).
stringstringModelRefDto | nullPromise<Record<string, ModelRefDto>>modelRequestApiKey
async modelRequestApiKey(projectId: string, model: ModelRefDto): Promise<string | undefined>The key the host resolves for one request to this model (the Sessions' resolver), if any.
stringModelRefDtoPromise<string | undefined>getChatDefaults
async getChatDefaults(projectId: string): Promise<ChatDefaultsDto>New-chat defaults ([default_chat]): read leniently — same tolerance as core's
loadProjectConfig (an invalid value drops that key; a missing/malformed block reads as
empty). Members may read; only the fields present in the file appear in the DTO.
stringPromise<ChatDefaultsDto>setChatDefaults
async setChatDefaults(projectId: string, req: ChatDefaultsDto): Promise<ChatDefaultsDto>Replaces the whole [default_chat] block (declarative PUT: an omitted key clears it;
an empty request removes the block entirely, restoring the pre-existing behavior).
Field validation (enums / agent existence) happens at the route; this is a
read-modify-write like setName — every other field (models, credentials, name, the
default model) is preserved. Returns the stored block as re-read from disk.
stringChatDefaultsDtoPromise<ChatDefaultsDto>getCommandPolicy
async getCommandPolicy(projectId: string): Promise<CommandPolicyDto>Sandbox command policy ([command_policy]): read leniently, mirroring core's
loadProjectConfig tolerance — a non-boolean enabled reads as true (the default), a
rule missing name or pattern is dropped, and an absent (or non-array) rules value
serves the factory set: a project from before the block was seeded behaves as the
defaults until its first saved edit materializes them. The factory set also rides
along as defaultRules for the settings UI's "restore defaults".
stringPromise<CommandPolicyDto>setCommandPolicy
async setCommandPolicy(projectId: string, req: { enabled?: boolean; rules: { name: string; pattern: string; description?: string; enabled?: boolean; action?: "deny" | "ask"; }[]; }): Promise<CommandPolicyDto>Replaces the [command_policy] block (declarative PUT, validated at the route). A PUT
always materializes the full rule list into the file — model-presets style: once
written, later factory changes never rewrite it — storing per field only what departs
from the defaults (enabled = false, a rule's enabled = false, a non-empty
description, a rule's action = "ask"). Read-modify-write like setChatDefaults,
preserving every other key. Returns the block as re-read.
string{ enabled?: boolean; rules: { name: string; pattern: string; description?: string; enabled?: boolean; action?: "deny" | "ask"; }[]; }Promise<CommandPolicyDto>getPluginTables
async getPluginTables(projectId: string): Promise<PluginTables>The [plugins] key this Project writes: the shared table and each machine's own, in the
file's order; both empty when it asks for none.
stringPromise<PluginTables>setPluginTables
async setPluginTables(projectId: string, tables: PluginTables): Promise<PluginTables>Replaces this Project's plugin tables (a declarative PUT, validated at the route). Read-modify-write like setCommandPolicy, so every other key survives. An empty table is written as an empty table rather than removed: "this Project asks for none" is a decision, and a reader cannot tell it from "never configured" if the key vanishes.
stringPluginTablesPromise<PluginTables>getPricing
async getPricing(projectId: string, provider: string, modelId: string): Promise<TieredRates | undefined>Pricing lookup for usage-recorder: the current pricing for this paired reference (undefined if none -> cost is NULL). The file holds the list price; a stored promotion takes its fraction off both tiers, so a scheduled row on a promotion bills the two factors multiplied. A pair the file no longer stores is uncosted, except a model that is or was the default of new Projects: its usage keeps the catalog's price (retainedCatalogPricing), so deleting the row — by hand or by "Restore defaults" — does not unprice that history.
stringstringstringPromise<TieredRates | undefined>detectVision
async detectVision(projectId: string, req: ModelVisionDetectRequest): Promise<ModelVisionDetectResponse>Model connectivity test: the model reference (provider, modelId) is submitted
as a pair in the request body; sends one minimal request using that model's
config (optionally overridden with an unsaved apiKey / baseUrl) — no tools, no
system prompt, thinking at the lowest level, a tiny output cap, 20s timeout —
just to see whether the endpoint answers. The model id sent to MMSP is
modelId itself (the upstream id verbatim; without a client_type, MMSP routes it
by the vendor family the id begins with).
A reasoning-heavy model can spend the whole tiny output cap on thinking (finish_reason=length with no text — MMSP raises EmptyResponseError, collapsed to a malformed outcome): the endpoint demonstrably streamed model output, which is everything a connectivity test proves, so that case counts as ok too (see probeVerdict).
Never throws: the LLM layer collapses auth/parameter/network errors into an
LLMOutcome, which is translated here into ok / message. Consumes very few
Tokens (single-digit output; speed mode spends up to its 64-token cap to have a
window worth timing), and writes no Trace and records no usage.
Vision capability probe: sends one 1x1 PNG plus a one-word prompt and reports whether the model took it (see services/vision-detect.ts for the verdict rules and why this one costs real money, unlike the protocol probes).
Credential resolution is the connectivity test's, verbatim — the draft row (the request's
key, else the row's own unless "clear" is checked), then the group's [providers.<id>]
connection, then what MMSP's client does with no key (its vendor's variable for its own
default endpoint only; never for a gateway's). Nothing secret is returned; the failure
message is the provider's own text, truncated.
stringModelVisionDetectRequestPromise<ModelVisionDetectResponse>completeOnce
async completeOnce(projectId: string, prompt: string): Promise<UtilityCompletion>One short completion on the Project's default model, for utility asks that belong to
no Session — today the English identifier a display name is translated into. Everything
comes from the stored default entry (credential, base URL, pinned protocol), and the
answer is the model's plain text. Nothing throws: no default model, no entry for it, a
construction that throws on a missing credential, a refusal, a timeout, or an answer with
no text all come back as { ok: false } carrying the reason, which the caller records so
the errors panel can say why the ask produced nothing. Callers must still have a result
that works without it. The request is not metered — it carries no Session to attribute
it to.
Thinking is off and the budget is the shared meta budget, for the same reason core's own
out-of-band requests set them that way: a reasoning model spends thinking out of
maxTokens, so a budget the size of the answer ends the request at finish_reason=length
with no text at all.
stringstringPromise<UtilityCompletion>testModel
async testModel(projectId: string, req: ModelTestRequest, testRequestFor?: ModelTestRequestSource): Promise<ModelTestResponse>stringModelTestRequestModelTestRequestSourcePromise<ModelTestResponse>detectProtocol
async detectProtocol(projectId: string, req: ModelProtocolDetectRequest): Promise<ModelProtocolDetectResponse>Protocol detection for a custom base URL (see services/protocol-detect.ts for the probe order and classification). Credential resolution has four layers, in order:
- the request body's key (what the user just typed in the dialog);
- otherwise, when the optional paired reference names a stored entry and "clear" isn't checked, that entry's own saved key (the frontend only ever sees the mask);
- otherwise the group's key (
[providers.<id>]) — for a row whose own key is absent or cleared, since that row then follows its group, and for a request naming the group alone (the group settings dialog has no model), unless "clear" is checked there, which clears the group key itself; - otherwise the environment, per probe, as MMSP's client for that probe's protocol reads it (PRN-021): its variable only when the probed URL is that client's own default endpoint (envApiKeyForProtocol); anywhere else the probe goes out anonymously. Layers 2 and 3 are read server-side only and never travel back to the browser. Detection still runs with no credential at all: a protocol-shaped 401/403 proves the route. Never throws on probe failures — every outcome is reported per probe.
stringModelProtocolDetectRequestPromise<ModelProtocolDetectResponse>listEndpointModels
async listEndpointModels(req: EndpointModelListRequest, listImpl: typeof coreListEndpointModels = coreListEndpointModels, timeoutMs: number = LIST_MODELS_TIMEOUT_MS): Promise<EndpointModelListResponse>Endpoint model listing for the add-group import (see EndpointModelListRequest). All
parameters come from the request — a group being created has no stored entry to fall
back to; with an omitted key, MMSP's client reads its variable only for its own default
endpoint and refuses any other URL (PRN-021), except an open MMSP server. Never
throws: SDK construction and request failures collapse into { ok:false, message }, an MMSP
UnsupportedOperationError additionally sets unsupported so the dialog can point at
the manual path, and a listing that outlives LIST_MODELS_TIMEOUT_MS is reported as
timed out. Nothing cancels the request behind it: the race only stops waiting, and a
later rejection is already handled by the race itself. The listing is returned
verbatim; dedup against the config is the caller's policy, exactly like the probe
routes never write anything either.
EndpointModelListRequesttypeof coreListEndpointModelsnumberPromise<EndpointModelListResponse>getModels
async getModels(projectId: string): Promise<ModelsResponse>GET models view: masks credentials (the groups' and the rows' own), flags the default
Model; the group is the entry's provider field. The built-in catalog labels a row it
knows (displayName, when the file stores none) and nothing else. vision is the TOML
annotation only — absent = supported (a new Project writes false where the catalog says
so); the catalog is not consulted. pricing is the file's list price, and a row with a
stored promotion reports its fraction as discount.
Two layers of connection are reported: providers (each group's stored
[providers.<id>] values) and, per row, its own values (clientType, credential)
beside effective — what the row is actually used with after core's effectiveConnection
(row -> group -> none, per field; the file's values only), with where each value came
from. The environment fallback (envKey, envKeyMasked, an env key source) is the
variable MMSP's routed client reads for a row with no key in the file (PRN-021: only with
no base URL or the client's own default endpoint), named by the catalog's
modelEnvPreviewKey, which asks MMSP's credentials module.
stringPromise<ModelsResponse>updateModels
async updateModels(projectId: string, req: ModelsUpdateRequest): Promise<ModelsResponse>PUT replaces the whole models table: key =
(provider, modelId); model entries that no longer appear are deleted along
with their inline credential; omitting apiKey keeps the existing value,
providing one overwrites it and records created_at, clearApiKey clears it;
baseUrl null clears it / omitted keeps it. A key change (either the group or
the upstream id changes) is migrated as a pair via renamedFrom: credential and
unknown fields migrate along with the base entry, and default/vision pointers
follow. Other extension fields in the toml (name, etc.) are preserved.
Promotions (web.db) follow the new table once the file is written: a declared
discount is stored (null clears it); an omitted one keeps the stored promotion unless
the entry renames the row or changes its pricing; a row left out of the table takes its
promotion with it. A discount outside (0, 1) rejects the request before any write.
An entry the request adds to a first-party vendor group under a model id MMSP cannot
route — judged on the protocol it would actually run on, its own or its group's — is
rejected as well (model_not_routable), and so is one it adds to a built-in group that
takes no hand-added models when it is not one of that group's presets
(model_not_addable); one already stored under that key is written as it stands. Both
name the entry in details (provider, modelId). See the loops below for why the two
differ. A Penguin Go row or group given a protocol other than MMSP, or the group's cleared,
is penguin_go_protocol_fixed unless that value is the one it already stores.
providers changes the groups' connections, merged per group and per field like
PUT /models/providers/:provider; a group absent there keeps its table. Once the rows are
settled, a user-defined group with no row left loses its table too — that is how
deleting the group cleans up after it.
stringModelsUpdateRequestPromise<ModelsResponse>setProviderConnection
async setProviderConnection(projectId: string, provider: string, patch: ProviderConnectionUpdate): Promise<ProviderConnectionResponse>Changes one group's connection (PUT /models/providers/:provider): [providers.<id>],
merged per field (see patchProviderTable). No row is touched: a model with its own base
URL, protocol or key keeps it. A ModelScope key set or cleared here is the user's own, so
the group's authorization (its refresh token) goes with the old one — "Disconnect" is
{ clearApiKey: true } here, and for ModelScope it ends the authorization too. A protocol
Penguin Go's fixed one does not allow is refused before anything is written
(checkGroupProtocol). Returns the models view as it now stands, with the default a group's
first key offers (connectOfferOf); the default itself is left as it is.
stringstringProviderConnectionUpdatePromise<ProviderConnectionResponse>setGroupApiKey
async setGroupApiKey(projectId: string, provider: string, apiKey: string): Promise<GroupKeyApplied>Writes one API key as a group's key ([providers.<id>].api_key + created_at) — what
Enter key, the Connect flows and the ModelScope refresh all land on. No row is read or
replaced: a model with its own key keeps it (and keeps billing the account it was given),
and a caller that never saw the rest of the table cannot flatten it. A group with no rows
still takes the key.
Returns how many of the group's rows now use it — the ones without a key of their own — and the default a group's first key offers (connectOfferOf), which is not written.
stringstringstringPromise<GroupKeyApplied>setGroupApiKeyWithProviderAuthToken
async setGroupApiKeyWithProviderAuthToken(projectId: string, provider: string, apiKey: string, token: Omit<ModelProviderAuthToken, "provider" | "updatedAt">, options: { expectedRefreshToken?: string } = {}): Promise<number>setGroupApiKey plus the authorization's refresh material (web.db), in one critical
section with the other ModelScope writers. With expectedRefreshToken (a refresh), nothing
is written and 0 returned when the stored refresh token changed meanwhile — a newer
authorization won.
stringstringstringOmit<ModelProviderAuthToken, "provider" | "updatedAt">{ expectedRefreshToken?: string }Promise<number>getGroupApiKey
async getGroupApiKey(projectId: string, provider: string): Promise<string | undefined>A group's key ([providers.<id>].api_key), never a row's own; never sent over HTTP.
stringstringPromise<string | undefined>getModelApiKey
async getModelApiKey(projectId: string, provider: string, modelId: string): Promise<string | undefined>One row's own key — its override of the group's — or undefined; never sent over HTTP.
stringstringstringPromise<string | undefined>getGroupBalanceKey
async getGroupBalanceKey(projectId: string, provider: string): Promise<string | undefined>The key a group's account balance is read with (the catalog's balance descriptor names
the endpoint): the group's key, and never a row's own — a model keyed to another account
says nothing about this group's balance. Without a group key, the vendor's environment
variable, read from this process's env, where MMSP's own client for the vendor reads it for
the group's base URL (the catalog's clientEnvKey): no base URL, or the vendor's default
endpoint. Only a first-party
vendor group has a vendor client (vendorClientType), so a gateway's variable (TokenDance's
OPENAI_API_KEY, if a user clears its base URL) never reaches its balance endpoint, and
Penguin Go takes its key from the config alone. Never returned to the browser.
stringstringPromise<string | undefined>mergePlatformModels
async mergePlatformModels(projectId: string, provider: string, catalog: PlatformModelCatalog, apiKey: string, applyKeyToExisting: boolean): Promise<PlatformModelApplyResult>Penguin Go's catalog, merged into its group. A model the platform advertises and the group
lacks is added with the platform's list price, context
window, vision flag, display name and routing, and its promotion is stored beside it
(web.db). Its protocol and endpoint are stored per field against the group's
[providers.penguin-go] table in the file (the built-in catalog is not consulted): a field
the table holds is followed, the row storing only where it differs from the platform's
group value (the relay URL every model shares); a field the table lacks is written on the
row in full. Existing advertised rows receive the platform's list price and promotion (an
ended promotion is cleared); all other metadata and rows absent from the response are kept. Go-managed routes switch to
MMSP, including model overrides; user-redirected endpoints retain their configuration.
Authorization (applyKeyToExisting) also writes the delivered key once, as the group's
key ([providers.penguin-go]); new rows carry no key of their own and follow it.
Returns how many rows were added, updated (price, promotion or route changed),
and applied: on authorization, how many of the group's rows now use the group key;
otherwise the rows added. An authorization that writes the group's first key reports the
default it offers as defaultOffer (connectOfferOf), without writing it.
stringstringPlatformModelCatalogstringbooleanPromise<PlatformModelApplyResult>syncPresets
async syncPresets(projectId: string, mode: PresetSyncMode): Promise<PresetSyncResponse>"Sync presets", in its two modes (POST /models/sync-presets):
-
add: the catalog's presets the table lacks — retired rows never — are appended, in catalog order, each stored against its group's table in the file field by field (presetAdditions), and their promotions are stored. A group the file has neither rows nor a table for gets the catalog's table. Nothing else moves: no existing row, group table, promotion, key or reference. -
restore: the model configuration becomes a new Project's (presetProjectConfig) and keeps only the API keys. The rows are the non-retired presets in catalog order, the built-in groups' tables the catalog's, and there is no default model and no vision model (a new Project's state: the first-run guide asks for a default again). Everything else goes: every row that is not a preset (the user's own, and those an older catalog added, retired rows included), every user-defined group, every override on a preset row, and every group setting the catalog does not write (custom's base URL included; vLLM's returns to the catalog's local address). Promotions become the catalog's.Penguin Go gets no exception. Its rows beyond the presets and its promotions came from the platform, which prices against its own list: keeping a promotion on a row whose price went back to the catalog's would bill a discount the platform never set on that price. So the group is reset like the others, and the platform's next sync (connect, or "Sync models") brings its models and promotions back under the key that is kept.
Keys stay where they were: a group's on its group, if the group is built-in; a row's on the same row, if that row is a preset. Then relocateSharedKeys runs over every row the file held, the deleted ones included, so a key a deleted row of a built-in group shares with the group's other keyed rows (or holds alone) moves to the group rather than going with the row. Keys on a user-defined group, on the user's models in custom or in a user-defined group, and differing keys on deleted rows go with them.
Returns the models view with added (presets the file lacked) and restored (preset
rows the file held that changed; 0 for add). Nothing is written when nothing changes.
stringPresetSyncModePromise<PresetSyncResponse>