{"repo": "chogng/comet", "files": {"src/cs/code/electron-main/agentHost/cometModelCatalog.ts": {"d082ddb081dcb19b0cc9cea9aa7cea3baa9df311": {"t": 1786068364.6909223, "n": 23775, "h": "6367c5261aea6a60", "c": "/*---------------------------------------------------------------------------------------------\n * Copyright (c) Comet. All rights reserved.\n * Licensed under the MIT License. See LICENSE.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { createHash } from 'node:crypto';\n\nimport { CancellationError } from 'cs/base/common/errors';\nimport type {\n\tIAgentAttachmentCapabilities,\n\tIAgentExecutionProfileRequest,\n\tIAgentModelDescriptor,\n} from 'cs/platform/agentHost/common/agent';\nimport {\n\tvalidateAndFreezeAgentConfigurationCandidate,\n\ttype IAgentConfigurationSchema,\n} from 'cs/platform/agentHost/common/configuration';\nimport {\n\tvalidateAndFreezeAgentCredentialReference,\n\ttype IAgentCredentialResolver,\n} from 'cs/platform/agentHost/common/credentials';\nimport { AgentHostError, AgentHostErrorCode } from 'cs/platform/agentHost/common/errors';\nimport {\n\tAgentExecutionPresetId,\n\tAgentModelId,\n\tcreateAgentExecutionPresetId,\n\tcreateAgentConfigurationSchemaRevision,\n\tcreateAgentModelDescriptorRevision,\n\tcreateAgentModelId,\n} from 'cs/platform/agentHost/common/identities';\nimport { COMET_TOOL_SCHEMA_PROFILE } from 'cs/platform/agentHost/common/tools';\nimport { encodeAgentHostProtocolValue, type AgentHostProtocolValue } from 'cs/platform/agentHost/common/protocolValues';\nimport type {\n\tICometExecutionProfileResolution,\n\tICometExecutionProfileResolver,\n\tICometModelRuntime,\n} from 'cs/platform/agentHost/node/agents/comet/cometModel';\nimport { CometModelError } from 'cs/platform/agentHost/node/agents/comet/cometModel';\nimport {\n\tCOMET_MODEL_CREDENTIAL_CONFIGURATION_PROPERTY,\n\tCOMET_MODEL_ENDPOINT_CONFIGURATION_PROPERTY,\n\tCOMET_MODEL_PROVIDER_MODEL_CONFIGURATION_PROPERTY,\n\tCOMET_PROVIDER_API_KEY_CREDENTIAL_PROVIDER,\n\tcreateCometModelConfigurationSchema,\n} from 'cs/platform/agentHost/node/agents/comet/cometConfiguration';\nimport { COMET_AGENT_ID, COMET_AGENT_PACKAGE_ID } from 'cs/platform/agentHost/node/agents/comet/cometAgent';\nimport {\n\tOpenAIResponsesModelRuntime,\n\tOPENAI_RESPONSES_INPUT_FILE_MEDIA_TYPES,\n\ttype IOpenAIResponsesConnectionResolutionRequest,\n\ttype IOpenAIResponsesConnectionResolver,\n\ttype IOpenAIResponsesExecutionSettings,\n} from 'cs/platform/agentHost/node/agents/comet/providers/openAIResponses';\nimport {\n\tOpenAIChatCompletionsModelRuntime,\n\tOPENAI_CHAT_COMPLETIONS_TEXT_MEDIA_TYPES,\n\ttype IOpenAIChatCompletionsConnectionResolutionRequest,\n\ttype IOpenAIChatCompletionsConnectionResolver,\n\ttype IOpenAIChatCompletionsExecutionSettings,\n} from 'cs/platform/agentHost/node/agents/comet/providers/openAIChatCompletions';\nimport { ArticleAttachmentRepresentationMediaType } from 'cs/workbench/contrib/fetch/common/articleChatAttachments';\n\nexport const COMET_AUTOMATIC_EXECUTION_PRESET = createAgentExecutionPresetId('comet.automatic');\n\nconst maximumSteps = 16;\nconst maximumRequestMilliseconds = 5 * 60 * 1_000;\nconst maximumRequestBytes = 64 * 1024 * 1024;\nconst maximumResponseBytes = 32 * 1024 * 1024;\nconst maximumAttachmentCount = 16;\nconst maximumAttachmentItemBytes = 10 * 1024 * 1024;\nconst maximumAttachmentTotalBytes = 20 * 1024 * 1024;\nconst maximumAttachmentTreeDepth = 32;\nconst maximumAttachmentTreeEntries = 4_096;\nconst cometBlobAttachmentRepresentationMediaTypes = Object.freeze([\n\t'application/vnd.comet.file+json',\n\t'application/vnd.comet.editor-snapshot+json',\n\tArticleAttachmentRepresentationMediaType,\n\t'application/vnd.comet.pdf-selection+json',\n]);\nconst cometResponsesAttachmentRepresentationMediaTypes = Object.freeze([\n\t...cometBlobAttachmentRepresentationMediaTypes,\n\t'application/vnd.comet.directory+json',\n]);\n\n/** Supplies the production credential, network, and clock authorities. */\nexport interface IProductionCometModelCatalogOptions {\n\treadonly credentials: IAgentCredentialResolver;\n\treadonly fetch: (url: string, init: RequestInit) => Promise;\n\treadonly now: () => number;\n}\n\n/** Contains the exact model runtimes and execution-profile resolver registered for Comet. */\nexport interface IProductionCometModelCatalog {\n\treadonly models: readonly ICometModelRuntime[];\n\treadonly executionProfileResolver: ICometExecutionProfileResolver;\n\treadonly automaticPreset: AgentExecutionPresetId;\n\treadonly automaticModel: AgentModelId;\n}\n\ninterface IProductCometModelDefinitionBase {\n\treadonly model: AgentModelId;\n\treadonly runtime: string;\n\treadonly displayName: string;\n\treadonly endpoint: string;\n\treadonly providerModel: string;\n\treadonly credentialReference: string;\n\treadonly attachments: IAgentAttachmentCapabilities;\n}\n\ntype IProductCometModelDefinition =\n\t| IProductCometModelDefinitionBase & {\n\t\treadonly protocol: 'openai-responses';\n\t\treadonly settings: IOpenAIResponsesExecutionSettings;\n\t}\n\t| IProductCometModelDefinitionBase & {\n\t\treadonly protocol: 'openai-chat-completions';\n\t\treadonly settings: IOpenAIChatCompletionsExecutionSettings;\n\t};\n\ntype IConfiguredModelOption = IProductCometModelDefinition & {\n\treadonly configurationSchema: IAgentConfigurationSchema;\n};\n\nfunction invalidConfiguration(message: string, data: { readonly field: string; readonly value: string }): never {\n\tthrow new CometModelError('invalidConfiguration', message, data);\n}\n\nconst textAttachmentMediaTypes = Object.freeze([\n\t...cometBlobAttachmentRepresentationMediaTypes,\n\t...OPENAI_CHAT_COMPLETIONS_TEXT_MEDIA_TYPES,\n]);\nconst imageAttachmentMediaTypes = Object.freeze([\n\t...textAttachmentMediaTypes,\n\t'image/png',\n\t'image/jpeg',\n\t'image/webp',\n\t'image/gif',\n]);\nconst responsesAttachmentMediaTypes = Object.freeze([\n\t...cometResponsesAttachmentRepresentationMediaTypes,\n\t...OPENAI_RESPONSES_INPUT_FILE_MEDIA_TYPES,\n\t'image/png',\n\t'image/jpeg',\n\t'image/webp',\n\t'image/gif',\n]);\nconst textAttachmentCapabilities: IAgentAttachmentCapabilities = Object.freeze({\n\tcarriers: Object.freeze(['inline', 'reference'] as const),\n\tshapes: Object.freeze(['blob'] as const),\n\tmediaTypes: textAttachmentMediaTypes,\n\tmaximumCount: maximumAttachmentCount,\n\tmaximumItemBytes: maximumAttachmentItemBytes,\n\tmaximumTotalBytes: maximumAttachmentTotalBytes,\n\tmaximumTreeDepth: 0,\n\tmaximumTreeEntries: 0,\n\tsupportsClientContentForBackgroundExecution: true,\n});\nconst imageAttachmentCapabilities: IAgentAttachmentCapabilities = Object.freeze({\n\t...textAttachmentCapabilities,\n\tmediaTypes: imageAttachmentMediaTypes,\n});\nconst responsesAttachmentCapabilities: IAgentAttachmentCapabilities = Object.freeze({\n\tcarriers: Object.freeze(['inline', 'reference'] as const),\n\tshapes: Object.freeze(['blob', 'tree'] as const),\n\tmediaTypes: responsesAttachmentMediaTypes,\n\tmaximumCount: maximumAttachmentCount,\n\tmaximumItemBytes: maximumAttachmentItemBytes,\n\tmaximumTotalBytes: maximumAttachmentTotalBytes,\n\tmaximumTreeDepth: maximumAttachmentTreeDepth,\n\tmaximumTreeEntries: maximumAttachmentTreeEntries,\n\tsupportsClientContentForBackgroundExecution: true,\n});\n\nconst productCometModelDefinitions: readonly IProductCometModelDefinition[] = Object.freeze([\n\tObject.freeze({\n\t\tprotocol: 'openai-chat-completions',\n\t\tmodel: createAgentModelId('glm:glm-4.7-flash'),\n\t\truntime: 'openai.chat-completions.glm.glm-4.7-flash.unspecified.unspecified',\n\t\tdisplayName: 'GLM-4.7-Flash',\n\t\tendpoint: 'https://open.bigmodel.cn/api/paas/v4/chat/completions',\n\t\tproviderModel: 'glm-4.7-flash',\n\t\tcredentialReference: 'glm',\n\t\tsettings: Object.freeze({ version: 1, maxOutputTokens: 131_072, maximumOutputTokensField: 'max_tokens' }),\n\t\tattachments: textAttachmentCapabilities,\n\t}),\n\tObject.freeze({\n\t\tprotocol: 'openai-chat-completions',\n\t\tmodel: createAgentModelId('glm:glm-4.6v-flash'),\n\t\truntime: 'openai.chat-completions.glm.glm-4.6v-flash.unspecified.unspecified',\n\t\tdisplayName: 'GLM-4.6V-Flash',\n\t\tendpoint: 'https://open.bigmodel.cn/api/paas/v4/chat/completions',\n\t\tproviderModel: 'glm-4.6v-flash',\n\t\tcredentialReference: 'glm',\n\t\tsettings: Object.freeze({ version: 1, maxOutputTokens: 32_768, maximumOutputTokensField: 'max_tokens' }),\n\t\tattachments: imageAttachmentCapabilities,\n\t}),\n\tObject.freeze({\n\t\tprotocol: 'openai-chat-completions',\n\t\tmodel: createAgentModelId('kimi:kimi-k2.5'),\n\t\truntime: 'openai.chat-completions.kimi.kimi-k2.5.unspecified.unspecified',\n\t\tdisplayName: 'Kimi K2.5',\n\t\tendpoint: 'https://api.moonshot.cn/v1/chat/completions',\n\t\tproviderModel: 'kimi-k2.5',\n\t\tcredentialReference: 'kimi',\n\t\tsettings: Object.freeze({ version: 1, maxOutputTokens: 32_768, maximumOutputTokensField: 'max_completion_tokens' }),\n\t\tattachments: imageAttachmentCapabilities,\n\t}),\n\tObject.freeze({\n\t\tprotocol: 'openai-chat-completions',\n\t\tmodel: createAgentModelId('deepseek:deepseek-v4-flash'),\n\t\truntime: 'openai.chat-completions.deepseek.deepseek-v4-flash.unspecified.unspecified',\n\t\tdisplayName: 'DeepSeek V4 Flash',\n\t\tendpoint: 'https://api.deepseek.com/chat/completions',\n\t\tproviderModel: 'deepseek-v4-flash',\n\t\tcredentialReference: 'deepseek',\n\t\tsettings: Object.freeze({ version: 1, maxOutputTokens: 384_000, maximumOutputTokensField: 'max_tokens' }),\n\t\tattachments: textAttachmentCapabilities,\n\t}),\n\tObject.freeze({\n\t\tprotocol: 'openai-responses',\n\t\tmodel: createAgentModelId('openai:gpt-5-codex:medium'),\n\t\truntime: 'openai.responses.openai.gpt-5-codex.medium.unspecified',\n\t\tdisplayName: 'GPT-5 Codex Medium',\n\t\tendpoint: 'https://api.openai.com/v1/responses',\n\t\tproviderModel: 'gpt-5-codex',\n\t\tcredentialReference: 'openai',\n\t\tsettings: Object.freeze({\n\t\t\tversion: 1,\n\t\t\tmaxOutputTokens: 128_000,\n\t\t\ttemperature: null,\n\t\t\treasoning: Object.freeze({ effort: 'medium', summary: 'auto' }),\n\t\t\tserviceTier: null,\n\t\t\tparallelToolCalls: true,\n\t\t}),\n\t\tattachments: responsesAttachmentCapabilities,\n\t}),\n\tObject.freeze({\n\t\tprotocol: 'openai-responses',\n\t\tmodel: createAgentModelId('openai:gpt-5.5:medium'),\n\t\truntime: 'openai.responses.openai.gpt-5.5.medium.unspecified',\n\t\tdisplayName: 'GPT-5.5 Medium',\n\t\tendpoint: 'https://api.openai.com/v1/responses',\n\t\tproviderModel: 'gpt-5.5',\n\t\tcredentialReference: 'openai',\n\t\tsettings: Object.freeze({\n\t\t\tversion: 1,\n\t\t\tmaxOutputTokens: 128_000,\n\t\t\ttemperature: null,\n\t\t\treasoning: Object.freeze({ effort: 'medium', summary: 'auto' }),\n\t\t\tserviceTier: null,\n\t\t\tparallelToolCalls: true,\n\t\t}),\n\t\tattachments: responsesAttachmentCapabilities,\n\t}),\n]);\nconst automaticModel = createAgentModelId('glm:glm-4.7-flash');\n\nfunction validateProductEndpoint(definition: IProductCometModelDefinition): void {\n\tlet endpoint: URL;\n\ttry {\n\t\tendpoint = new URL(definition.endpoint);\n\t} catch {\n\t\treturn invalidConfiguration('Comet product model endpoint is invalid', {\n\t\t\tfield: 'productCometModelDefinitions.endpoint',\n\t\t\tvalue: definition.endpoint,\n\t\t});\n\t}\n\tconst expectedSuffix = definition.protocol === 'openai-responses' ? '/responses' : '/chat/completions';\n\tif (\n\t\tendpoint.protocol !== 'https:'\n\t\t|| endpoint.username.length !== 0\n\t\t|| endpoint.password.length !== 0\n\t\t|| endpoint.search.length !== 0\n\t\t|| endpoint.hash.length !== 0\n\t\t|| !endpoint.pathname.endsWith(expectedSuffix)\n\t\t|| endpoint.toString() !== definition.endpoint\n\t) {\n\t\treturn invalidConfiguration('Comet product model endpoint is invalid', {\n\t\t\tfield: 'productCometModelDefinitions.endpoint',\n\t\t\tvalue: definition.endpoint,\n\t\t});\n\t}\n}\n\nfunction createProductModelConfigurationSchema(\n\tdefinition: IProductCometModelDefinition,\n): IAgentConfigurationSchema {\n\tconst candidate = createCometModelConfigurationSchema({\n\t\trevision: createAgentConfigurationSchemaRevision('content-addressing'),\n\t\tendpoint: definition.endpoint,\n\t\tproviderModel: definition.providerModel,\n\t\tcredentialReference: definition.credentialReference,\n\t});\n\tconst content = Object.freeze({\n\t\tprofile: candidate.profile,\n\t\tagent: candidate.agent,\n\t\tscope: candidate.scope,\n\t\tproperties: candidate.properties,\n\t});\n\tconst revision = createAgentConfigurationSchemaRevision(\n\t\t`sha256:${createHash('sha256')\n\t\t\t.update(encodeAgentHostProtocolValue(content as unknown as AgentHostProtocolValue))\n\t\t\t.digest('hex')}`,\n\t);\n\treturn createCometModelConfigurationSchema({\n\t\trevision,\n\t\tendpoint: definition.endpoint,\n\t\tproviderModel: definition.providerModel,\n\t\tcredentialReference: definition.credentialReference,\n\t});\n}\n\nfunction productModelDescriptor(\n\tdefinition: IProductCometModelDefinition,\n\tconfigurationSchema: IAgentConfigurationSchema,\n): IAgentModelDescriptor {\n\tif (new Set(definition.attachments.mediaTypes).size !== definition.attachments.mediaTypes.length) {\n\t\treturn invalidConfiguration('Comet product model descriptor contains duplicate attachment media types', {\n\t\t\tfield: 'productCometModelDefinitions.attachments.mediaTypes',\n\t\t\tvalue: definition.model,\n\t\t});\n\t}\n\tconst content = Object.freeze({\n\t\tid: definition.model,\n\t\tdisplayName: definition.displayName,\n\t\tenabled: true,\n\t\tconfigurationSchema,\n\t\ttoolSchemaProfiles: Object.freeze([COMET_TOOL_SCHEMA_PROFILE]),\n\t\tattachments: definition.attachments,\n\t});\n\tconst revisionPayload = Object.freeze({\n\t\tprotocol: definition.protocol,\n\t\truntime: definition.runtime,\n\t\tsettings: definition.settings,\n\t\tdescriptor: content,\n\t});\n\tconst revision = createAgentModelDescriptorRevision(\n\t\t`sha256:${createHash('sha256')\n\t\t\t.update(encodeAgentHostProtocolValue(revisionPayload as unknown as AgentHostProtocolValue))\n\t\t\t.digest('hex')}`,\n\t);\n\treturn Object.freeze({\n\t\t...content,\n\t\trevision,\n\t});\n}\n\ntype CometConnectionResolutionRequest =\n\t| IOpenAIResponsesConnectionResolutionRequest\n\t| IOpenAIChatCompletionsConnectionResolutionRequest;\n\nasync function resolveConfiguredConnection(\n\texpected: IConfiguredModelOption,\n\tcredentials: IAgentCredentialResolver,\n\trequest: CometConnectionResolutionRequest,\n) {\n\tif (request.runtime !== expected.runtime || request.model !== expected.model) {\n\t\tthrow new CometModelError('executionConnectionChanged', 'Comet model connection identity changed');\n\t}\n\tconst configuration = validateAndFreezeAgentConfigurationCandidate(\n\t\texpected.configurationSchema,\n\t\trequest.step.modelConfiguration,\n\t\t'model',\n\t\ttrue,\n\t);\n\tconst endpoint = configuration.values[COMET_MODEL_ENDPOINT_CONFIGURATION_PROPERTY];\n\tconst providerModel = configuration.values[COMET_MODEL_PROVIDER_MODEL_CONFIGURATION_PROPERTY];\n\tconst credential = validateAndFreezeAgentCredentialReference(\n\t\tconfiguration.values[COMET_MODEL_CREDENTIAL_CONFIGURATION_PROPERTY],\n\t);\n\tif (typeof endpoint !== 'string' || typeof providerModel !== 'string') {\n\t\tthrow new CometModelError('invalidConfiguration', 'Comet model connection configuration is incomplete');\n\t}\n\tif (\n\t\tendpoint !== expected.endpoint\n\t\t|| providerModel !== expected.providerModel\n\t\t|| credential.provider !== COMET_PROVIDER_API_KEY_CREDENTIAL_PROVIDER\n\t\t|| credential.scope !== 'llm'\n\t\t|| credential.reference !== expected.credentialReference\n\t) {\n\t\tthrow new CometModelError(\n\t\t\t'invalidConfiguration',\n\t\t\t'Comet model connection configuration changed from its product-owned descriptor',\n\t\t);\n\t}\n\tconst credentialIdentity = encodeAgentHostProtocolValue(credential);\n\tif (!request.step.credentials.some(candidate => (\n\t\tencodeAgentHostProtocolValue(validateAndFreezeAgentCredentialReference(candidate)) === credentialIdentity\n\t))) {\n\t\tthrow new CometModelError('invalidConfiguration', 'Comet model credential is not bound to the addressed Turn');\n\t}\n\tlet apiKey: string;\n\ttry {\n\t\tapiKey = await credentials.resolve({\n\t\t\tpackageId: COMET_AGENT_PACKAGE_ID,\n\t\t\tagentId: COMET_AGENT_ID,\n\t\t\truntimeRegistration: request.step.runtimeRegistration,\n\t\t\tsession: request.step.session,\n\t\t\tchat: request.step.chat,\n\t\t\tturn: request.step.turn,\n\t\t\tcredential,\n\t\t}, request.token);\n\t} catch (error) {\n\t\tif (error instanceof CancellationError) {\n\t\t\tthrow error;\n\t\t}\n\t\tif (\n\t\t\terror instanceof AgentHostError\n\t\t\t&& (error.code === AgentHostErrorCode.CredentialUnavailable\n\t\t\t\t|| error.code === AgentHostErrorCode.CredentialUnauthorized)\n\t\t) {\n\t\t\tthrow new CometModelError('providerCredentialRequired', 'Comet model credential is unavailable');\n\t\t}\n\t\tthrow new CometModelError('connectionResolutionFailed', 'Comet model credential resolution failed');\n\t}\n\tif (request.signal.aborted) {\n\t\tthrow new CancellationError();\n\t}\n\treturn Object.freeze({ endpoint, providerModel, apiKey });\n}\n\n/** Resolves one exact Responses connection from the accepted model configuration. */\nclass ResponsesConfigurationConnectionResolver implements IOpenAIResponsesConnectionResolver {\n\tconstructor(\n\t\tprivate readonly expected: Extract,\n\t\tprivate readonly credentials: IAgentCredentialResolver,\n\t) {}\n\n\tresolve(request: IOpenAIResponsesConnectionResolutionRequest) {\n\t\treturn resolveConfiguredConnection(this.expected, this.credentials, request);\n\t}\n}\n\n/** Resolves one exact Chat Completions connection from the accepted model configuration. */\nclass ChatCompletionsConfigurationConnectionResolver implements IOpenAIChatCompletionsConnectionResolver {\n\tconstructor(\n\t\tprivate readonly expected: Extract,\n\t\tprivate readonly credentials: IAgentCredentialResolver,\n\t) {}\n\n\tresolve(request: IOpenAIChatCompletionsConnectionResolutionRequest) {\n\t\treturn resolveConfiguredConnection(this.expected, this.credentials, request);\n\t}\n}\n\nfunction selectionRecord(value: AgentHostProtocolValue): Readonly> {\n\tif (value === null || typeof value !== 'object' || Array.isArray(value)) {\n\t\tthrow new CometModelError('invalidExecutionSelection', 'Invalid Comet execution profile selection', {\n\t\t\tfield: 'selection.value',\n\t\t\tvalue: typeof value,\n\t\t});\n\t}\n\treturn value as Readonly>;\n}\n\nfunction exactSelectionValue(\n\tselection: Readonly>,\n\tfield: 'model' | 'preset',\n): string {\n\tif (Object.keys(selection).length !== 1 || typeof selection[field] !== 'string') {\n\t\tthrow new CometModelError('invalidExecutionSelection', 'Invalid Comet execution profile selection', {\n\t\t\tfield: `selection.value.${field}`,\n\t\t\tvalue: 'invalid',\n\t\t});\n\t}\n\treturn selection[field];\n}\n\nclass ProductionCometExecutionProfileResolver implements ICometExecutionProfileResolver {\n\tprivate readonly models = new Map();\n\tprivate readonly productPresets = new Map();\n\n\tconstructor(configured: readonly IConfiguredModelOption[], automatic: IConfiguredModelOption) {\n\t\tfor (const entry of configured) {\n\t\t\tthis.models.set(entry.model, Object.freeze({\n\t\t\t\tconfigurationSchema: entry.configurationSchema,\n\t\t\t\tresolution: Object.freeze({\n\t\t\t\t\tmodelRuntime: entry.runtime,\n\t\t\t\t\tsettings: entry.settings as unknown as AgentHostProtocolValue,\n\t\t\t\t\tmaximumSteps,\n\t\t\t\t}),\n\t\t\t}));\n\t\t}\n\t\tthis.productPresets.set(COMET_AUTOMATIC_EXECUTION_PRESET, Object.freeze({\n\t\t\tconfigurationSchema: automatic.configurationSchema,\n\t\t\tresolution: Object.freeze({\n\t\t\t\tmodelRuntime: automatic.runtime,\n\t\t\t\tsettings: automatic.settings as unknown as AgentHostProtocolValue,\n\t\t\t\tmaximumSteps,\n\t\t\t}),\n\t\t}));\n\t}\n\n\tasync resolve(request: IAgentExecutionProfileRequest): Promise {\n\t\tconst selection = selectionRecord(request.selection.value);\n\t\tif (request.selection.kind === 'user') {\n\t\t\tconst value = exactSelectionValue(selection, 'model');\n\t\t\tlet model: AgentModelId;\n\t\t\ttry {\n\t\t\t\tmodel = createAgentModelId(value);\n\t\t\t} catch {\n\t\t\t\tthrow new CometModelError('invalidExecutionSelection', 'Invalid Comet model selection', {\n\t\t\t\t\tfield: 'selection.value.model',\n\t\t\t\t\tvalue: value.slice(0, 256),\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst binding = this.models.get(model);\n\t\t\tif (binding === undefined) {\n\t\t\t\tthrow new CometModelError('invalidExecutionSelection', 'Unknown Comet model selection', {\n\t\t\t\t\tfield: 'selection.value.model',\n\t\t\t\t\tvalue: model,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (request.selection.configuration.schema !== binding.configurationSchema.revision) {\n\t\t\t\tthrow new CometModelError('invalidExecutionSelection', 'Comet model configuration schema changed');\n\t\t\t}\n\t\t\treturn binding.resolution;\n\t\t}\n\t\tif (request.selection.kind === 'product') {\n\t\t\tconst value = exactSelectionValue(selection, 'preset');\n\t\t\tlet preset: AgentExecutionPresetId;\n\t\t\ttry {\n\t\t\t\tpreset = createAgentExecutionPresetId(value);\n\t\t\t} catch {\n\t\t\t\tthrow new CometModelError('invalidExecutionSelection', 'Invalid Comet product preset selection', {\n\t\t\t\t\tfield: 'selection.value.preset',\n\t\t\t\t\tvalue: value.slice(0, 256),\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst binding = this.productPresets.get(preset);\n\t\t\tif (binding === undefined) {\n\t\t\t\tthrow new CometModelError('invalidExecutionSelection', 'Unknown Comet product preset selection', {\n\t\t\t\t\tfield: 'selection.value.preset',\n\t\t\t\t\tvalue: preset,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (request.selection.configuration.schema !== binding.configurationSchema.revision) {\n\t\t\t\tthrow new CometModelError('invalidExecutionSelection', 'Comet preset configuration schema changed');\n\t\t\t}\n\t\t\treturn binding.resolution;\n\t\t}\n\t\tthrow new CometModelError('invalidExecutionSelection', 'Invalid Comet execution profile selection', {\n\t\t\tfield: 'selection.kind',\n\t\t\tvalue: request.selection.kind,\n\t\t});\n\t}\n}\n\n/** Builds the exact product-owned Comet model catalog. */\nexport function createProductionCometModelCatalog(options: IProductionCometModelCatalogOptions): IProductionCometModelCatalog {\n\tif (\n\t\toptions.credentials === null\n\t\t|| typeof options.credentials !== 'object'\n\t\t|| typeof options.credentials.resolve !== 'function'\n\t\t|| typeof options.fetch !== 'function'\n\t\t|| typeof options.now !== 'function'\n\t) {\n\t\treturn invalidConfiguration('Comet model catalog dependencies are invalid', {\n\t\t\tfield: 'options',\n\t\t\tvalue: 'invalid',\n\t\t});\n\t}\n\tconst configured = productCometModelDefinitions.map(definition => {\n\t\tvalidateProductEndpoint(definition);\n\t\tconst configurationSchema = createProductModelConfigurationSchema(definition);\n\t\treturn Object.freeze({ ...definition, configurationSchema });\n\t});\n\tconst configuredByModel = new Map(configured.map(entry => [entry.model, entry] as const));\n\tif (configuredByModel.size !== configured.length) {\n\t\treturn invalidConfiguration('Comet model catalog contains duplicate model identities', {\n\t\t\tfield: 'productCometModelDefinitions.model',\n\t\t\tvalue: 'duplicate',\n\t\t});\n\t}\n\tconst automatic = configuredByModel.get(automaticModel);\n\tif (automatic === undefined) {\n\t\treturn invalidConfiguration('Comet automatic profile requires the product-owned model', {\n\t\t\tfield: 'automaticModel',\n\t\t\tvalue: automaticModel,\n\t\t});\n\t}\n\tconst models: ICometModelRuntime[] = configured.map(entry => {\n\t\tif (entry.protocol === 'openai-responses') {\n\t\t\treturn new OpenAIResponsesModelRuntime({\n\t\t\t\tid: entry.runtime,\n\t\t\t\tdescriptor: productModelDescriptor(entry, entry.configurationSchema),\n\t\t\t\tconnectionResolver: new ResponsesConfigurationConnectionResolver(entry, options.credentials),\n\t\t\t\tmaximumRequestMilliseconds,\n\t\t\t\tmaximumRequestBytes,\n\t\t\t\tmaximumResponseBytes,\n\t\t\t\tfetch: options.fetch,\n\t\t\t\tnow: options.now,\n\t\t\t});\n\t\t}\n\t\treturn new OpenAIChatCompletionsModelRuntime({\n\t\t\tid: entry.runtime,\n\t\t\tdescriptor: productModelDescriptor(entry, entry.configurationSchema),\n\t\t\tconnectionResolver: new ChatCompletionsConfigurationConnectionResolver(entry, options.credentials),\n\t\t\tmaximumRequestMilliseconds,\n\t\t\tmaximumRequestBytes,\n\t\t\tmaximumResponseBytes,\n\t\t\tfetch: options.fetch,\n\t\t\tnow: options.now,\n\t\t});\n\t});\n\tconst executionProfileResolver = new ProductionCometExecutionProfileResolver(configured, automatic);\n\treturn Object.freeze({\n\t\tmodels: Object.freeze(models),\n\t\texecutionProfileResolver,\n\t\tautomaticPreset: COMET_AUTOMATIC_EXECUTION_PRESET,\n\t\tautomaticModel: automatic.model,\n\t});\n}\n"}}}}