@prismshadow/penguin-library-project · library/project/src/project.ts:409

ProjectConfigStore

interface

ProjectConfigStore: the mechanism ProjectConfigService implements.

API

@Interface()
export abstract class ProjectConfigStore {
  abstract readRaw(projectId: string): Promise<RawTable>;
  abstract migrateStoredConfigs(): Promise<void>;
  abstract loadConfig(projectId: string): Promise<ProjectConfig>;
  abstract writeRaw(projectId: string, data: RawTable): Promise<void>;
  abstract writeInitialConfig(projectId: string, name: string): Promise<void>;
  abstract ensurePresetModels(projectId: string): Promise<boolean>;
  abstract seedPresetPromotions(projectId: string): Promise<void>;
  abstract getName(projectId: string): Promise<string | undefined>;
  abstract setName(projectId: string, name: string): Promise<void>;
  abstract getDefaultModelRef(projectId: string): Promise<ModelRef | undefined>;
  abstract setDefaultModelRef(projectId: string, ref: ModelRefDto): Promise<ModelRefDto>;
  abstract getChatDefaults(projectId: string): Promise<ChatDefaultsDto>;
  abstract setChatDefaults(projectId: string, req: ChatDefaultsDto): Promise<ChatDefaultsDto>;
  abstract getPluginTables(projectId: string): Promise<PluginTables>;
  abstract setPluginTables(projectId: string, tables: PluginTables): Promise<PluginTables>;
  abstract getCommandPolicy(projectId: string): Promise<CommandPolicyDto>;
  abstract setCommandPolicy(
      projectId: string,
      req: {
        enabled?: boolean;
        rules: {
          name: string;
          pattern: string;
          description?: string;
          enabled?: boolean;
          action?: "deny" | "ask";
        }[];
      },
    ): Promise<CommandPolicyDto>;
  abstract getPricing(
      projectId: string,
      provider: string,
      modelId: string,
    ): Promise<TieredRates | undefined>;
  abstract detectVision(
      projectId: string,
      req: ModelVisionDetectRequest,
    ): Promise<ModelVisionDetectResponse>;
  abstract testModel(
      projectId: string,
      req: ModelTestRequest,
      testRequestFor?: ModelTestRequestSource,
    ): Promise<ModelTestResponse>;
  abstract detectProtocol(
      projectId: string,
      req: ModelProtocolDetectRequest,
    ): Promise<ModelProtocolDetectResponse>;
  abstract listEndpointModels(
      req: EndpointModelListRequest,
      listImpl?: (options: ListEndpointModelsOptions) => Promise<string[]>,
      timeoutMs?: number,
    ): Promise<EndpointModelListResponse>;
  abstract getModels(projectId: string): Promise<ModelsResponse>;
  abstract updateModels(projectId: string, req: ModelsUpdateRequest): Promise<ModelsResponse>;
  abstract setProviderConnection(
      projectId: string,
      provider: string,
      patch: ProviderConnectionUpdate,
    ): Promise<ProviderConnectionResponse>;
  abstract syncPresets(projectId: string, mode: PresetSyncMode): Promise<PresetSyncResponse>;
  abstract setGroupApiKey(
      projectId: string,
      provider: string,
      apiKey: string,
    ): Promise<GroupKeyApplied>;
  abstract setGroupApiKeyWithProviderAuthToken(
      projectId: string,
      provider: string,
      apiKey: string,
      token: Omit<ModelProviderAuthToken, "provider" | "updatedAt">,
      options?: { expectedRefreshToken?: string },
    ): Promise<number>;
  abstract getGroupApiKey(projectId: string, provider: string): Promise<string | undefined>;
  abstract getModelApiKey(
      projectId: string,
      provider: string,
      modelId: string,
    ): Promise<string | undefined>;
  abstract getGroupBalanceKey(projectId: string, provider: string): Promise<string | undefined>;
  abstract setModelApiKeyResolver(
      resolver: (context: ModelRequestContext) => Promise<string | undefined>,
    ): void;
  abstract mergePlatformModels(
      projectId: string,
      provider: string,
      catalog: PlatformModelCatalog,
      apiKey: string,
      applyKeyToExisting: boolean,
    ): Promise<PlatformModelApplyResult>;
  abstract completeOnce(projectId: string, prompt: string): Promise<UtilityCompletion>;
  abstract getToolModels(projectId: string): Promise<Record<string, ModelRefDto>>;
  abstract setToolModel(
      projectId: string,
      key: string,
      model: ModelRefDto | null,
    ): Promise<Record<string, ModelRefDto>>;
  abstract modelRequestApiKey(projectId: string, model: ModelRefDto): Promise<string | undefined>;
}

Contract Topology

Static AST wiring across @Module / @Provide / @Use

Members (37)

readRaw

readRaw(projectId: string): Promise<RawTable>
@paramprojectIdstring
@returnsPromise<RawTable>

migrateStoredConfigs

migrateStoredConfigs(): Promise<void>

Reads every Project's config once, so what the read path's one-time migrations write back (core's and the server's) is on disk before any Session opens one.

@returnsPromise<void>

loadConfig

loadConfig(projectId: string): Promise<ProjectConfig>
@paramprojectIdstring
@returnsPromise<ProjectConfig>

writeRaw

writeRaw(projectId: string, data: RawTable): Promise<void>
@paramprojectIdstring
@paramdataRawTable
@returnsPromise<void>

writeInitialConfig

writeInitialConfig(projectId: string, name: string): Promise<void>
@paramprojectIdstring
@paramnamestring
@returnsPromise<void>

ensurePresetModels

ensurePresetModels(projectId: string): Promise<boolean>
@paramprojectIdstring
@returnsPromise<boolean>

seedPresetPromotions

seedPresetPromotions(projectId: string): Promise<void>
@paramprojectIdstring
@returnsPromise<void>

getName

getName(projectId: string): Promise<string | undefined>
@paramprojectIdstring
@returnsPromise<string | undefined>

setName

setName(projectId: string, name: string): Promise<void>
@paramprojectIdstring
@paramnamestring
@returnsPromise<void>

getDefaultModelRef

getDefaultModelRef(projectId: string): Promise<ModelRef | undefined>
@paramprojectIdstring
@returnsPromise<ModelRef | undefined>

setDefaultModelRef

setDefaultModelRef(projectId: string, ref: ModelRefDto): Promise<ModelRefDto>
@paramprojectIdstring
@paramrefModelRefDto
@returnsPromise<ModelRefDto>

getChatDefaults

getChatDefaults(projectId: string): Promise<ChatDefaultsDto>
@paramprojectIdstring
@returnsPromise<ChatDefaultsDto>

setChatDefaults

setChatDefaults(projectId: string, req: ChatDefaultsDto): Promise<ChatDefaultsDto>
@paramprojectIdstring
@paramreqChatDefaultsDto
@returnsPromise<ChatDefaultsDto>

getPluginTables

getPluginTables(projectId: string): Promise<PluginTables>

The [plugins] key: the shared table and each machine's own, package name → requirement, in the file's order.

@paramprojectIdstring
@returnsPromise<PluginTables>

setPluginTables

setPluginTables(projectId: string, tables: PluginTables): Promise<PluginTables>

Replaces the tables (a declarative PUT); answers what was written.

@paramprojectIdstring
@paramtablesPluginTables
@returnsPromise<PluginTables>

getCommandPolicy

getCommandPolicy(projectId: string): Promise<CommandPolicyDto>
@paramprojectIdstring
@returnsPromise<CommandPolicyDto>

setCommandPolicy

setCommandPolicy(projectId: string, req: { enabled?: boolean; rules: { name: string; pattern: string; description?: string; enabled?: boolean; action?: "deny" | "ask"; }[]; }): Promise<CommandPolicyDto>
@paramprojectIdstring
@paramreq{ enabled?: boolean; rules: { name: string; pattern: string; description?: string; enabled?: boolean; action?: "deny" | "ask"; }[]; }
@returnsPromise<CommandPolicyDto>

getPricing

getPricing(projectId: string, provider: string, modelId: string): Promise<TieredRates | undefined>
@paramprojectIdstring
@paramproviderstring
@parammodelIdstring
@returnsPromise<TieredRates | undefined>

detectVision

detectVision(projectId: string, req: ModelVisionDetectRequest): Promise<ModelVisionDetectResponse>
@paramprojectIdstring
@paramreqModelVisionDetectRequest
@returnsPromise<ModelVisionDetectResponse>

testModel

testModel(projectId: string, req: ModelTestRequest, testRequestFor?: ModelTestRequestSource): Promise<ModelTestResponse>

The connection test; testRequestFor names a tool model's own request (ModelTestRequestSource).

@paramprojectIdstring
@paramreqModelTestRequest
@paramtestRequestFor?ModelTestRequestSource
@returnsPromise<ModelTestResponse>

detectProtocol

detectProtocol(projectId: string, req: ModelProtocolDetectRequest): Promise<ModelProtocolDetectResponse>
@paramprojectIdstring
@paramreqModelProtocolDetectRequest
@returnsPromise<ModelProtocolDetectResponse>

listEndpointModels

listEndpointModels(req: EndpointModelListRequest, listImpl?: (options: ListEndpointModelsOptions) => Promise<string[]>, timeoutMs?: number): Promise<EndpointModelListResponse>
@paramreqEndpointModelListRequest
@paramlistImpl?(options: ListEndpointModelsOptions) => Promise<string[]>
@paramtimeoutMs?number
@returnsPromise<EndpointModelListResponse>

getModels

getModels(projectId: string): Promise<ModelsResponse>
@paramprojectIdstring
@returnsPromise<ModelsResponse>

updateModels

updateModels(projectId: string, req: ModelsUpdateRequest): Promise<ModelsResponse>
@paramprojectIdstring
@paramreqModelsUpdateRequest
@returnsPromise<ModelsResponse>

setProviderConnection

setProviderConnection(projectId: string, provider: string, patch: ProviderConnectionUpdate): Promise<ProviderConnectionResponse>

One group's [providers.<id>] connection, merged per field; rows are never touched. The group's first key reports its connect default as defaultOffer; the default is untouched.

@paramprojectIdstring
@paramproviderstring
@parampatchProviderConnectionUpdate
@returnsPromise<ProviderConnectionResponse>

syncPresets

syncPresets(projectId: string, mode: PresetSyncMode): Promise<PresetSyncResponse>

"Add new models" (add) or "Restore defaults" (restore) against the built-in catalog.

@paramprojectIdstring
@parammodePresetSyncMode
@returnsPromise<PresetSyncResponse>

setGroupApiKey

setGroupApiKey(projectId: string, provider: string, apiKey: string): Promise<GroupKeyApplied>

Writes the group key; resolves to how many of the group's rows use it (none of their own), and the connect default the group's first key offers as the default model.

@paramprojectIdstring
@paramproviderstring
@paramapiKeystring
@returnsPromise<GroupKeyApplied>

setGroupApiKeyWithProviderAuthToken

setGroupApiKeyWithProviderAuthToken(projectId: string, provider: string, apiKey: string, token: Omit<ModelProviderAuthToken, "provider" | "updatedAt">, options?: { expectedRefreshToken?: string }): Promise<number>
@paramprojectIdstring
@paramproviderstring
@paramapiKeystring
@paramtokenOmit<ModelProviderAuthToken, "provider" | "updatedAt">
@paramoptions?{ expectedRefreshToken?: string }
@returnsPromise<number>

getGroupApiKey

getGroupApiKey(projectId: string, provider: string): Promise<string | undefined>

The group key ([providers.<id>].api_key), never a row's own. Server-side only.

@paramprojectIdstring
@paramproviderstring
@returnsPromise<string | undefined>

getModelApiKey

getModelApiKey(projectId: string, provider: string, modelId: string): Promise<string | undefined>

One row's own key (its override of the group's), or undefined. Server-side only.

@paramprojectIdstring
@paramproviderstring
@parammodelIdstring
@returnsPromise<string | undefined>

getGroupBalanceKey

getGroupBalanceKey(projectId: string, provider: string): Promise<string | undefined>

The key a group's account balance is read with: the group key (never a row's own), or else the vendor's environment key where MMSP's vendor client reads it for the group's base URL (none, or the vendor's own default endpoint). Server-side only.

@paramprojectIdstring
@paramproviderstring
@returnsPromise<string | undefined>

setModelApiKeyResolver

setModelApiKeyResolver(resolver: (context: ModelRequestContext) => Promise<string | undefined>): void
@paramresolver(context: ModelRequestContext) => Promise<string | undefined>
@returnsvoid

mergePlatformModels

mergePlatformModels(projectId: string, provider: string, catalog: PlatformModelCatalog, apiKey: string, applyKeyToExisting: boolean): Promise<PlatformModelApplyResult>
@paramprojectIdstring
@paramproviderstring
@paramcatalogPlatformModelCatalog
@paramapiKeystring
@paramapplyKeyToExistingboolean
@returnsPromise<PlatformModelApplyResult>

completeOnce

completeOnce(projectId: string, prompt: string): Promise<UtilityCompletion>
@paramprojectIdstring
@parampromptstring
@returnsPromise<UtilityCompletion>

getToolModels

getToolModels(projectId: string): Promise<Record<string, ModelRefDto>>

The [tools] bindings that name a configured model, by key (an empty object when none does).

@paramprojectIdstring
@returnsPromise<Record<string, ModelRefDto>>

setToolModel

setToolModel(projectId: string, key: string, model: ModelRefDto | null): Promise<Record<string, ModelRefDto>>

Binds key to a configured model, or with null unbinds it; answers the bindings as they now stand. A model the Project does not configure is a 400. Which keys exist, and which models a key accepts, is the binding's declarer's rule (ToolModelBindings), not this store's.

@paramprojectIdstring
@paramkeystring
@parammodelModelRefDto | null
@returnsPromise<Record<string, ModelRefDto>>

modelRequestApiKey

modelRequestApiKey(projectId: string, model: ModelRefDto): Promise<string | undefined>

The key the host resolves for one request to this model (a managed credential it refreshes, as a Session's requests get it), or undefined when the file's own connection applies.

@paramprojectIdstring
@parammodelModelRefDto
@returnsPromise<string | undefined>