@chat-js/registry 0.2.0-beta.6 → 0.2.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,7 +30,7 @@ Source folders group items by category. Each gateway has a `gateway.ts`; each to
30
30
 
31
31
  The selected gateway installs into the app's `chatjs/providers/gateway.ts` slot. Tools install under `chatjs/tools/<id>/` with generated installation inputs and app-owned integration modules. Third-party destination namespacing is not inferred from registry aliases and is not added by this source reorganization.
32
32
 
33
- `packages/gateways` owns shared runtime contracts. `packages/cli` owns installation and configuration. `apps/chat` is the reference consumer and app template source. New categories such as layouts and caches should introduce source folders and contracts when their first implementation is added, rather than empty scaffolding.
33
+ `apps/chat/chatjs/core/gateway/` contains the shared gateway runtime and types shipped with each app. `packages/cli` owns installation and configuration. `apps/chat` is the reference consumer and app template source. New categories such as layouts and caches should introduce source folders and contracts when their first implementation is added, rather than empty scaffolding.
34
34
 
35
35
  ## Ownership inventory
36
36
 
@@ -3,13 +3,12 @@
3
3
  "name": "litellm-gateway",
4
4
  "title": "LiteLLM",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@ai-sdk/openai-compatible@3.0.92"
8
7
  ],
9
8
  "files": [
10
9
  {
11
10
  "path": "src/gateways/litellm/gateway.ts",
12
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst MODEL_DISCOVERY_TIMEOUT_MS = 10_000;\nconst TRAILING_SLASHES_REGEX = /\\/+$/u;\n\nconst litellmModelSchema = z.object({\n created: z.number().optional(),\n id: z.string(),\n object: z.string().optional(),\n owned_by: z.string().optional(),\n});\nconst litellmModelsResponseSchema = z.object({\n data: z.array(litellmModelSchema),\n});\n\ntype LiteLLMModelResponse = z.infer<\n typeof litellmModelsResponseSchema\n>[\"data\"][number];\n\nconst getModelsUrl = (baseURL: string): string => {\n const normalizedBaseURL = baseURL.replace(TRAILING_SLASHES_REGEX, \"\");\n if (normalizedBaseURL.endsWith(\"/v1\")) {\n return `${normalizedBaseURL}/models`;\n }\n return `${normalizedBaseURL}/v1/models`;\n};\n\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst toAiGatewayModel = (model: LiteLLMModelResponse): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_LIMIT,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"litellm\",\n pricing: {},\n type: \"language\",\n});\n\nclass LiteLLMGateway\n extends GatewayRuntime\n implements GatewayProvider<\"litellm\">\n{\n public readonly type = \"litellm\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"LITELLM_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"litellm\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.LITELLM_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.LITELLM_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\"No LITELLM_BASE_URL found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = getModelsUrl(baseURL);\n this.log.debug({ url }, \"Fetching models from LiteLLM proxy\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n signal: AbortSignal.timeout(MODEL_DISCOVERY_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"LiteLLM proxy returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const body = litellmModelsResponseSchema.parse(await response.json());\n const models = body.data;\n const result = models.map((model) => toAiGatewayModel(model));\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from LiteLLM proxy\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from LiteLLM proxy, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { LiteLLMGateway as Gateway, LiteLLMGateway };\n",
11
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst MODEL_DISCOVERY_TIMEOUT_MS = 10_000;\nconst TRAILING_SLASHES_REGEX = /\\/+$/u;\n\nconst litellmModelSchema = z.object({\n created: z.number().optional(),\n id: z.string(),\n object: z.string().optional(),\n owned_by: z.string().optional(),\n});\nconst litellmModelsResponseSchema = z.object({\n data: z.array(litellmModelSchema),\n});\n\ntype LiteLLMModelResponse = z.infer<\n typeof litellmModelsResponseSchema\n>[\"data\"][number];\n\nconst getModelsUrl = (baseURL: string): string => {\n const normalizedBaseURL = baseURL.replace(TRAILING_SLASHES_REGEX, \"\");\n if (normalizedBaseURL.endsWith(\"/v1\")) {\n return `${normalizedBaseURL}/models`;\n }\n return `${normalizedBaseURL}/v1/models`;\n};\n\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst toAiGatewayModel = (model: LiteLLMModelResponse): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_LIMIT,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"litellm\",\n pricing: {},\n type: \"language\",\n});\n\nclass LiteLLMGateway\n extends GatewayRuntime\n implements GatewayProvider<\"litellm\">\n{\n public readonly type = \"litellm\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"LITELLM_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"litellm\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.LITELLM_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.LITELLM_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\"No LITELLM_BASE_URL found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = getModelsUrl(baseURL);\n this.log.debug({ url }, \"Fetching models from LiteLLM proxy\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n signal: AbortSignal.timeout(MODEL_DISCOVERY_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"LiteLLM proxy returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const body = litellmModelsResponseSchema.parse(await response.json());\n const models = body.data;\n const result = models.map((model) => toAiGatewayModel(model));\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from LiteLLM proxy\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from LiteLLM proxy, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { LiteLLMGateway as Gateway, LiteLLMGateway };\n",
13
12
  "type": "registry:file",
14
13
  "target": "~/chatjs/providers/gateway.ts"
15
14
  }
@@ -3,14 +3,13 @@
3
3
  "name": "openai-compatible-gateway",
4
4
  "title": "OpenAI Compatible",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@ai-sdk/openai-compatible@3.0.92",
8
7
  "zod@4.5.4"
9
8
  ],
10
9
  "files": [
11
10
  {
12
11
  "path": "src/gateways/openai-compatible/gateway.ts",
13
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAICompatibleModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAICompatibleModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"unknown\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAICompatibleGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai-compatible\">\n{\n public readonly type = \"openai-compatible\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"OPENAI_COMPATIBLE_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"openai-compatible\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_COMPATIBLE_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.OPENAI_COMPATIBLE_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\n \"No OPENAI_COMPATIBLE_BASE_URL found, using fallback models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = `${baseURL}/models`;\n this.log.debug({ url }, \"Fetching models from OpenAI-compatible provider\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI-compatible provider returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI-compatible provider\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI-compatible provider, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAICompatibleGateway as Gateway, OpenAICompatibleGateway };\n",
12
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAICompatibleModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAICompatibleModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"unknown\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAICompatibleGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai-compatible\">\n{\n public readonly type = \"openai-compatible\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"OPENAI_COMPATIBLE_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"openai-compatible\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_COMPATIBLE_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.OPENAI_COMPATIBLE_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\n \"No OPENAI_COMPATIBLE_BASE_URL found, using fallback models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = `${baseURL}/models`;\n this.log.debug({ url }, \"Fetching models from OpenAI-compatible provider\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI-compatible provider returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI-compatible provider\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI-compatible provider, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAICompatibleGateway as Gateway, OpenAICompatibleGateway };\n",
14
13
  "type": "registry:file",
15
14
  "target": "~/chatjs/providers/gateway.ts"
16
15
  }
@@ -3,14 +3,13 @@
3
3
  "name": "openai-gateway",
4
4
  "title": "OpenAI",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@ai-sdk/openai@4.0.117",
8
7
  "zod@4.5.4"
9
8
  ],
10
9
  "files": [
11
10
  {
12
11
  "path": "src/gateways/openai/gateway.ts",
13
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type {\n ExtractImageModelIdFromProvider,\n ExtractModelIdFromProvider,\n} from \"@chat-js/gateways/provider-types\";\n\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\nimport { z } from \"zod\";\n\ntype OpenaiImageModelId = ExtractImageModelIdFromProvider<typeof createOpenAI>;\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAIModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAIModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by:\n (model.owned_by === \"system\" ? \"openai\" : model.owned_by) ?? \"openai\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAIGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai\">\n{\n public readonly type = \"openai\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAI> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENAI_API_KEY is not configured\");\n }\n return createOpenAI({ apiKey });\n }\n\n public createLanguageModel(\n modelId: ExtractModelIdFromProvider<typeof createOpenAI>\n ): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: OpenaiImageModelId): ImageModel {\n const provider = this.getProvider();\n return provider.image(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENAI_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://api.openai.com/v1/models\";\n this.log.debug({ url }, \"Fetching models from OpenAI\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAIGateway as Gateway, OpenAIGateway };\n",
12
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\nimport { z } from \"zod\";\n\nconst MODEL_ID_PARAMETER_INDEX = 0;\ntype OpenAiLanguageModelId = Parameters<\n ReturnType<typeof createOpenAI>[\"languageModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\ntype OpenAiImageModelId = Parameters<\n ReturnType<typeof createOpenAI>[\"image\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAIModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAIModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by:\n (model.owned_by === \"system\" ? \"openai\" : model.owned_by) ?? \"openai\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAIGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai\">\n{\n public readonly type = \"openai\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAI> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENAI_API_KEY is not configured\");\n }\n return createOpenAI({ apiKey });\n }\n\n public createLanguageModel(modelId: OpenAiLanguageModelId): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: OpenAiImageModelId): ImageModel {\n const provider = this.getProvider();\n return provider.image(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENAI_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://api.openai.com/v1/models\";\n this.log.debug({ url }, \"Fetching models from OpenAI\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAIGateway as Gateway, OpenAIGateway };\n",
14
13
  "type": "registry:file",
15
14
  "target": "~/chatjs/providers/gateway.ts"
16
15
  }
@@ -3,14 +3,13 @@
3
3
  "name": "openrouter-gateway",
4
4
  "title": "OpenRouter",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@openrouter/ai-sdk-provider@3.0.0",
8
7
  "zod@4.5.4"
9
8
  ],
10
9
  "files": [
11
10
  {
12
11
  "path": "src/gateways/openrouter/gateway.ts",
13
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport { createOpenRouter } from \"@openrouter/ai-sdk-provider\";\n\nimport { z } from \"zod\";\n\nconst MODEL_OWNER_SEGMENT_INDEX = 0;\nconst EMPTY_TAG_COUNT = 0;\nconst OPENROUTER_MODELS_URL = \"https://openrouter.ai/api/v1/models\";\n\nconst modalitiesSchema = z.array(z.string()).nullish();\nconst providerModelSchema = z.object({\n architecture: z\n .object({\n input_modalities: modalitiesSchema,\n output_modalities: modalitiesSchema,\n })\n .nullish(),\n context_length: z.number().nullish(),\n created: z.number().nullish(),\n description: z.string().nullish(),\n id: z.string(),\n name: z.string().nullish(),\n pricing: z\n .object({\n completion: z.string().optional(),\n image: z.string().optional(),\n input_cache_read: z.string().optional(),\n input_cache_write: z.string().optional(),\n prompt: z.string().optional(),\n web_search: z.string().optional(),\n })\n .nullish(),\n supported_parameters: z.array(z.string()).nullish(),\n top_provider: z\n .object({ max_completion_tokens: z.number().nullish() })\n .nullish(),\n});\ntype OpenRouterModelResponse = Omit<\n z.output<typeof providerModelSchema>,\n \"architecture\" | \"pricing\" | \"top_provider\" | \"supported_parameters\"\n> & {\n architecture?: {\n readonly input_modalities?: readonly string[] | null;\n readonly output_modalities?: readonly string[] | null;\n } | null;\n pricing?: Readonly<z.output<typeof providerModelSchema>[\"pricing\"]>;\n top_provider?: Readonly<z.output<typeof providerModelSchema>[\"top_provider\"]>;\n supported_parameters?: readonly string[] | null;\n};\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst deriveTags = (model: Readonly<OpenRouterModelResponse>): string[] => {\n const inputMods = (model.architecture ?? {}).input_modalities ?? [\"text\"];\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n const supportedParams = model.supported_parameters ?? [];\n\n const capabilities: readonly (readonly [boolean, string])[] = [\n [inputMods.includes(\"image\"), \"vision\"],\n [inputMods.includes(\"file\"), \"file-input\"],\n [outputMods.includes(\"image\"), \"image-generation\"],\n [\n supportedParams.includes(\"reasoning\") ||\n supportedParams.includes(\"include_reasoning\"),\n \"reasoning\",\n ],\n [supportedParams.includes(\"tools\"), \"tool-use\"],\n ];\n return capabilities.filter(([supported]) => supported).map(([, tag]) => tag);\n};\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenRouterModelResponse>\n): AiGatewayModel => {\n const tags = deriveTags(model);\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n\n let type: \"language\" | \"embedding\" | \"image\" = \"language\";\n if (!outputMods.includes(\"text\") && outputMods.includes(\"image\")) {\n type = \"image\";\n }\n\n const owned_by =\n model.id.split(\"/\").at(MODEL_OWNER_SEGMENT_INDEX) ?? \"unknown\";\n\n return {\n context_window: model.context_length ?? UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: model.description ?? \"\",\n id: model.id,\n max_tokens:\n (model.top_provider ?? {}).max_completion_tokens ?? UNKNOWN_MODEL_LIMIT,\n name: model.name ?? model.id,\n object: \"model\",\n owned_by,\n pricing: {\n image: (model.pricing ?? {}).image,\n input: (model.pricing ?? {}).prompt,\n input_cache_read: (model.pricing ?? {}).input_cache_read,\n input_cache_write: (model.pricing ?? {}).input_cache_write,\n output: (model.pricing ?? {}).completion,\n web_search: (model.pricing ?? {}).web_search,\n },\n tags: tags.length > EMPTY_TAG_COUNT ? tags : undefined,\n type,\n };\n};\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenRouterGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openrouter\">\n{\n public readonly type = \"openrouter\" as const;\n\n private getProvider(): ReturnType<typeof createOpenRouter> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENROUTER_API_KEY is not configured\");\n }\n return createOpenRouter({ apiKey });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider.chat(modelId);\n }\n\n // OpenRouter generates images through multimodal language models.\n public readonly createImageModel = null;\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENROUTER_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENROUTER_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = OPENROUTER_MODELS_URL;\n this.log.debug({ url }, \"Fetching models from OpenRouter\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenRouter returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenRouter\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenRouter, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenRouterGateway as Gateway, OpenRouterGateway };\n",
12
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport { createOpenRouter } from \"@openrouter/ai-sdk-provider\";\n\nimport { z } from \"zod\";\n\nconst MODEL_OWNER_SEGMENT_INDEX = 0;\nconst EMPTY_TAG_COUNT = 0;\nconst OPENROUTER_MODELS_URL = \"https://openrouter.ai/api/v1/models\";\n\nconst modalitiesSchema = z.array(z.string()).nullish();\nconst providerModelSchema = z.object({\n architecture: z\n .object({\n input_modalities: modalitiesSchema,\n output_modalities: modalitiesSchema,\n })\n .nullish(),\n context_length: z.number().nullish(),\n created: z.number().nullish(),\n description: z.string().nullish(),\n id: z.string(),\n name: z.string().nullish(),\n pricing: z\n .object({\n completion: z.string().optional(),\n image: z.string().optional(),\n input_cache_read: z.string().optional(),\n input_cache_write: z.string().optional(),\n prompt: z.string().optional(),\n web_search: z.string().optional(),\n })\n .nullish(),\n supported_parameters: z.array(z.string()).nullish(),\n top_provider: z\n .object({ max_completion_tokens: z.number().nullish() })\n .nullish(),\n});\ntype OpenRouterModelResponse = Omit<\n z.output<typeof providerModelSchema>,\n \"architecture\" | \"pricing\" | \"top_provider\" | \"supported_parameters\"\n> & {\n architecture?: {\n readonly input_modalities?: readonly string[] | null;\n readonly output_modalities?: readonly string[] | null;\n } | null;\n pricing?: Readonly<z.output<typeof providerModelSchema>[\"pricing\"]>;\n top_provider?: Readonly<z.output<typeof providerModelSchema>[\"top_provider\"]>;\n supported_parameters?: readonly string[] | null;\n};\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst deriveTags = (model: Readonly<OpenRouterModelResponse>): string[] => {\n const inputMods = (model.architecture ?? {}).input_modalities ?? [\"text\"];\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n const supportedParams = model.supported_parameters ?? [];\n\n const capabilities: readonly (readonly [boolean, string])[] = [\n [inputMods.includes(\"image\"), \"vision\"],\n [inputMods.includes(\"file\"), \"file-input\"],\n [outputMods.includes(\"image\"), \"image-generation\"],\n [\n supportedParams.includes(\"reasoning\") ||\n supportedParams.includes(\"include_reasoning\"),\n \"reasoning\",\n ],\n [supportedParams.includes(\"tools\"), \"tool-use\"],\n ];\n return capabilities.filter(([supported]) => supported).map(([, tag]) => tag);\n};\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenRouterModelResponse>\n): AiGatewayModel => {\n const tags = deriveTags(model);\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n\n let type: \"language\" | \"embedding\" | \"image\" = \"language\";\n if (!outputMods.includes(\"text\") && outputMods.includes(\"image\")) {\n type = \"image\";\n }\n\n const owned_by =\n model.id.split(\"/\").at(MODEL_OWNER_SEGMENT_INDEX) ?? \"unknown\";\n\n return {\n context_window: model.context_length ?? UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: model.description ?? \"\",\n id: model.id,\n max_tokens:\n (model.top_provider ?? {}).max_completion_tokens ?? UNKNOWN_MODEL_LIMIT,\n name: model.name ?? model.id,\n object: \"model\",\n owned_by,\n pricing: {\n image: (model.pricing ?? {}).image,\n input: (model.pricing ?? {}).prompt,\n input_cache_read: (model.pricing ?? {}).input_cache_read,\n input_cache_write: (model.pricing ?? {}).input_cache_write,\n output: (model.pricing ?? {}).completion,\n web_search: (model.pricing ?? {}).web_search,\n },\n tags: tags.length > EMPTY_TAG_COUNT ? tags : undefined,\n type,\n };\n};\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenRouterGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openrouter\">\n{\n public readonly type = \"openrouter\" as const;\n\n private getProvider(): ReturnType<typeof createOpenRouter> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENROUTER_API_KEY is not configured\");\n }\n return createOpenRouter({ apiKey });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider.chat(modelId);\n }\n\n // OpenRouter generates images through multimodal language models.\n public readonly createImageModel = null;\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENROUTER_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENROUTER_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = OPENROUTER_MODELS_URL;\n this.log.debug({ url }, \"Fetching models from OpenRouter\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenRouter returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenRouter\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenRouter, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenRouterGateway as Gateway, OpenRouterGateway };\n",
14
13
  "type": "registry:file",
15
14
  "target": "~/chatjs/providers/gateway.ts"
16
15
  }
@@ -1898,8 +1898,8 @@
1898
1898
  "name": "vercel-gateway",
1899
1899
  "title": "Vercel AI Gateway",
1900
1900
  "dependencies": [
1901
- "@chat-js/gateways@0.2.2",
1902
- "@ai-sdk/gateway@4.0.145"
1901
+ "@ai-sdk/gateway@4.0.145",
1902
+ "zod@4.5.4"
1903
1903
  ],
1904
1904
  "files": [
1905
1905
  {
@@ -1970,7 +1970,6 @@
1970
1970
  "name": "openai-gateway",
1971
1971
  "title": "OpenAI",
1972
1972
  "dependencies": [
1973
- "@chat-js/gateways@0.2.2",
1974
1973
  "@ai-sdk/openai@4.0.117",
1975
1974
  "zod@4.5.4"
1976
1975
  ],
@@ -2033,7 +2032,6 @@
2033
2032
  "name": "openai-compatible-gateway",
2034
2033
  "title": "OpenAI Compatible",
2035
2034
  "dependencies": [
2036
- "@chat-js/gateways@0.2.2",
2037
2035
  "@ai-sdk/openai-compatible@3.0.92",
2038
2036
  "zod@4.5.4"
2039
2037
  ],
@@ -2098,7 +2096,6 @@
2098
2096
  "name": "openrouter-gateway",
2099
2097
  "title": "OpenRouter",
2100
2098
  "dependencies": [
2101
- "@chat-js/gateways@0.2.2",
2102
2099
  "@openrouter/ai-sdk-provider@3.0.0",
2103
2100
  "zod@4.5.4"
2104
2101
  ],
@@ -2168,7 +2165,6 @@
2168
2165
  "name": "litellm-gateway",
2169
2166
  "title": "LiteLLM",
2170
2167
  "dependencies": [
2171
- "@chat-js/gateways@0.2.2",
2172
2168
  "@ai-sdk/openai-compatible@3.0.92"
2173
2169
  ],
2174
2170
  "files": [
@@ -3,13 +3,13 @@
3
3
  "name": "vercel-gateway",
4
4
  "title": "Vercel AI Gateway",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
- "@ai-sdk/gateway@4.0.145"
6
+ "@ai-sdk/gateway@4.0.145",
7
+ "zod@4.5.4"
8
8
  ],
9
9
  "files": [
10
10
  {
11
11
  "path": "src/gateways/vercel/gateway.ts",
12
- "content": "import type {\n Experimental_VideoModelV4,\n LanguageModelV4,\n} from \"@ai-sdk/provider\";\nimport {\n aiGatewayModelDiscriminatorSchema,\n aiGatewayModelSchema,\n aiGatewayModelsEnvelopeSchema,\n isAiGatewayModelType,\n} from \"@chat-js/gateways/models\";\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\nimport type { ImageModel } from \"ai\";\n\nimport { createGateway } from \"@ai-sdk/gateway\";\nimport type { gateway } from \"@ai-sdk/gateway\";\n\nconst MODEL_ID_PARAMETER_INDEX = 0;\ntype VercelImageModelId = Parameters<\n (typeof gateway)[\"imageModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\ntype VercelVideoModelId = Parameters<\n (typeof gateway)[\"videoModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\n\nconst EMPTY_MODEL_TYPE_COUNT = 0;\n\nclass VercelGateway\n extends GatewayRuntime\n implements GatewayProvider<\"vercel\">\n{\n public readonly type = \"vercel\" as const;\n\n public createLanguageModel(\n modelId: Parameters<\n (typeof gateway)[\"languageModel\"]\n >[typeof MODEL_ID_PARAMETER_INDEX]\n ): LanguageModelV4 {\n return this.getProvider()(modelId);\n }\n\n public createImageModel(modelId: VercelImageModelId): ImageModel {\n return this.getProvider().imageModel(modelId);\n }\n\n public createVideoModel(\n modelId: VercelVideoModelId\n ): Experimental_VideoModelV4 {\n return this.getProvider().videoModel(modelId);\n }\n\n private provider?: ReturnType<typeof createGateway>;\n\n private getProvider(): ReturnType<typeof createGateway> {\n this.provider ??= createGateway({ apiKey: this.env.AI_GATEWAY_API_KEY });\n return this.provider;\n }\n\n private getApiKey(): string | undefined {\n const apiKey = this.env.AI_GATEWAY_API_KEY;\n\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n return apiKey;\n }\n return this.env.VERCEL_OIDC_TOKEN;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No AI gateway API key found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://ai-gateway.vercel.sh/v1/models\";\n this.log.debug({ url }, \"Fetching models from Vercel AI Gateway\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"Vercel AI Gateway returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const bodyRaw: unknown = await response.json();\n const body = aiGatewayModelsEnvelopeSchema.parse(bodyRaw);\n const unsupportedTypes = new Set<string>();\n const models: AiGatewayModel[] = [];\n\n for (const candidate of body.data) {\n const { type } = aiGatewayModelDiscriminatorSchema.parse(candidate);\n if (isAiGatewayModelType(type)) {\n const model = aiGatewayModelSchema.parse(candidate);\n models.push({ ...model, type });\n } else {\n unsupportedTypes.add(type);\n }\n }\n\n if (unsupportedTypes.size > EMPTY_MODEL_TYPE_COUNT) {\n this.log.warn(\n {\n modelCount: body.data.length,\n skippedModelCount: body.data.length - models.length,\n unsupportedTypes: [...unsupportedTypes],\n },\n \"Skipping models with unsupported types from Vercel AI Gateway\"\n );\n }\n\n this.log.info(\n { modelCount: models.length },\n \"Successfully fetched models from Vercel AI Gateway\"\n );\n return models;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from Vercel AI Gateway, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { VercelGateway as Gateway, VercelGateway };\n",
12
+ "content": "import type {\n Experimental_VideoModelV4,\n LanguageModelV4,\n} from \"@ai-sdk/provider\";\nimport {\n aiGatewayModelSchema,\n isAiGatewayModelType,\n} from \"@/chatjs/core/gateway/models\";\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\nimport type { ImageModel } from \"ai\";\n\nimport { createGateway } from \"@ai-sdk/gateway\";\nimport type { gateway } from \"@ai-sdk/gateway\";\nimport { z } from \"zod\";\n\nconst MODEL_ID_PARAMETER_INDEX = 0;\ntype VercelImageModelId = Parameters<\n (typeof gateway)[\"imageModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\ntype VercelVideoModelId = Parameters<\n (typeof gateway)[\"videoModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\n\nconst EMPTY_MODEL_TYPE_COUNT = 0;\nconst modelDiscriminatorSchema = z.object({ type: z.string() });\nconst modelsEnvelopeSchema = z.object({\n data: z.array(z.unknown()),\n object: z.literal(\"list\"),\n});\n\nclass VercelGateway\n extends GatewayRuntime\n implements GatewayProvider<\"vercel\">\n{\n public readonly type = \"vercel\" as const;\n\n public createLanguageModel(\n modelId: Parameters<\n (typeof gateway)[\"languageModel\"]\n >[typeof MODEL_ID_PARAMETER_INDEX]\n ): LanguageModelV4 {\n return this.getProvider()(modelId);\n }\n\n public createImageModel(modelId: VercelImageModelId): ImageModel {\n return this.getProvider().imageModel(modelId);\n }\n\n public createVideoModel(\n modelId: VercelVideoModelId\n ): Experimental_VideoModelV4 {\n return this.getProvider().videoModel(modelId);\n }\n\n private provider?: ReturnType<typeof createGateway>;\n\n private getProvider(): ReturnType<typeof createGateway> {\n this.provider ??= createGateway({ apiKey: this.env.AI_GATEWAY_API_KEY });\n return this.provider;\n }\n\n private getApiKey(): string | undefined {\n const apiKey = this.env.AI_GATEWAY_API_KEY;\n\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n return apiKey;\n }\n return this.env.VERCEL_OIDC_TOKEN;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No AI gateway API key found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://ai-gateway.vercel.sh/v1/models\";\n this.log.debug({ url }, \"Fetching models from Vercel AI Gateway\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"Vercel AI Gateway returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const bodyRaw: unknown = await response.json();\n const body = modelsEnvelopeSchema.parse(bodyRaw);\n const unsupportedTypes = new Set<string>();\n const models: AiGatewayModel[] = [];\n\n for (const candidate of body.data) {\n const { type } = modelDiscriminatorSchema.parse(candidate);\n if (isAiGatewayModelType(type)) {\n models.push(aiGatewayModelSchema.parse(candidate));\n } else {\n unsupportedTypes.add(type);\n }\n }\n\n if (unsupportedTypes.size > EMPTY_MODEL_TYPE_COUNT) {\n this.log.warn(\n {\n modelCount: body.data.length,\n skippedModelCount: body.data.length - models.length,\n unsupportedTypes: [...unsupportedTypes],\n },\n \"Skipping models with unsupported types from Vercel AI Gateway\"\n );\n }\n\n this.log.info(\n { modelCount: models.length },\n \"Successfully fetched models from Vercel AI Gateway\"\n );\n return models;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from Vercel AI Gateway, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { VercelGateway as Gateway, VercelGateway };\n",
13
13
  "type": "registry:file",
14
14
  "target": "~/chatjs/providers/gateway.ts"
15
15
  }
@@ -3,13 +3,12 @@
3
3
  "name": "litellm-gateway",
4
4
  "title": "LiteLLM",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@ai-sdk/openai-compatible@3.0.92"
8
7
  ],
9
8
  "files": [
10
9
  {
11
10
  "path": "src/gateways/litellm/gateway.ts",
12
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst MODEL_DISCOVERY_TIMEOUT_MS = 10_000;\nconst TRAILING_SLASHES_REGEX = /\\/+$/u;\n\nconst litellmModelSchema = z.object({\n created: z.number().optional(),\n id: z.string(),\n object: z.string().optional(),\n owned_by: z.string().optional(),\n});\nconst litellmModelsResponseSchema = z.object({\n data: z.array(litellmModelSchema),\n});\n\ntype LiteLLMModelResponse = z.infer<\n typeof litellmModelsResponseSchema\n>[\"data\"][number];\n\nconst getModelsUrl = (baseURL: string): string => {\n const normalizedBaseURL = baseURL.replace(TRAILING_SLASHES_REGEX, \"\");\n if (normalizedBaseURL.endsWith(\"/v1\")) {\n return `${normalizedBaseURL}/models`;\n }\n return `${normalizedBaseURL}/v1/models`;\n};\n\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst toAiGatewayModel = (model: LiteLLMModelResponse): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_LIMIT,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"litellm\",\n pricing: {},\n type: \"language\",\n});\n\nclass LiteLLMGateway\n extends GatewayRuntime\n implements GatewayProvider<\"litellm\">\n{\n public readonly type = \"litellm\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"LITELLM_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"litellm\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.LITELLM_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.LITELLM_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\"No LITELLM_BASE_URL found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = getModelsUrl(baseURL);\n this.log.debug({ url }, \"Fetching models from LiteLLM proxy\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n signal: AbortSignal.timeout(MODEL_DISCOVERY_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"LiteLLM proxy returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const body = litellmModelsResponseSchema.parse(await response.json());\n const models = body.data;\n const result = models.map((model) => toAiGatewayModel(model));\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from LiteLLM proxy\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from LiteLLM proxy, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { LiteLLMGateway as Gateway, LiteLLMGateway };\n",
11
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst MODEL_DISCOVERY_TIMEOUT_MS = 10_000;\nconst TRAILING_SLASHES_REGEX = /\\/+$/u;\n\nconst litellmModelSchema = z.object({\n created: z.number().optional(),\n id: z.string(),\n object: z.string().optional(),\n owned_by: z.string().optional(),\n});\nconst litellmModelsResponseSchema = z.object({\n data: z.array(litellmModelSchema),\n});\n\ntype LiteLLMModelResponse = z.infer<\n typeof litellmModelsResponseSchema\n>[\"data\"][number];\n\nconst getModelsUrl = (baseURL: string): string => {\n const normalizedBaseURL = baseURL.replace(TRAILING_SLASHES_REGEX, \"\");\n if (normalizedBaseURL.endsWith(\"/v1\")) {\n return `${normalizedBaseURL}/models`;\n }\n return `${normalizedBaseURL}/v1/models`;\n};\n\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst toAiGatewayModel = (model: LiteLLMModelResponse): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_LIMIT,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"litellm\",\n pricing: {},\n type: \"language\",\n});\n\nclass LiteLLMGateway\n extends GatewayRuntime\n implements GatewayProvider<\"litellm\">\n{\n public readonly type = \"litellm\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"LITELLM_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"litellm\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.LITELLM_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.LITELLM_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\"No LITELLM_BASE_URL found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = getModelsUrl(baseURL);\n this.log.debug({ url }, \"Fetching models from LiteLLM proxy\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n signal: AbortSignal.timeout(MODEL_DISCOVERY_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"LiteLLM proxy returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const body = litellmModelsResponseSchema.parse(await response.json());\n const models = body.data;\n const result = models.map((model) => toAiGatewayModel(model));\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from LiteLLM proxy\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from LiteLLM proxy, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { LiteLLMGateway as Gateway, LiteLLMGateway };\n",
13
12
  "type": "registry:file",
14
13
  "target": "~/chatjs/providers/gateway.ts"
15
14
  }
@@ -3,14 +3,13 @@
3
3
  "name": "openai-compatible-gateway",
4
4
  "title": "OpenAI Compatible",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@ai-sdk/openai-compatible@3.0.92",
8
7
  "zod@4.5.4"
9
8
  ],
10
9
  "files": [
11
10
  {
12
11
  "path": "src/gateways/openai-compatible/gateway.ts",
13
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAICompatibleModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAICompatibleModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"unknown\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAICompatibleGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai-compatible\">\n{\n public readonly type = \"openai-compatible\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"OPENAI_COMPATIBLE_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"openai-compatible\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_COMPATIBLE_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.OPENAI_COMPATIBLE_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\n \"No OPENAI_COMPATIBLE_BASE_URL found, using fallback models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = `${baseURL}/models`;\n this.log.debug({ url }, \"Fetching models from OpenAI-compatible provider\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI-compatible provider returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI-compatible provider\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI-compatible provider, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAICompatibleGateway as Gateway, OpenAICompatibleGateway };\n",
12
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAICompatibleModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAICompatibleModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"unknown\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAICompatibleGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai-compatible\">\n{\n public readonly type = \"openai-compatible\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"OPENAI_COMPATIBLE_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"openai-compatible\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_COMPATIBLE_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.OPENAI_COMPATIBLE_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\n \"No OPENAI_COMPATIBLE_BASE_URL found, using fallback models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = `${baseURL}/models`;\n this.log.debug({ url }, \"Fetching models from OpenAI-compatible provider\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI-compatible provider returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI-compatible provider\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI-compatible provider, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAICompatibleGateway as Gateway, OpenAICompatibleGateway };\n",
14
13
  "type": "registry:file",
15
14
  "target": "~/chatjs/providers/gateway.ts"
16
15
  }
@@ -3,14 +3,13 @@
3
3
  "name": "openai-gateway",
4
4
  "title": "OpenAI",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@ai-sdk/openai@4.0.117",
8
7
  "zod@4.5.4"
9
8
  ],
10
9
  "files": [
11
10
  {
12
11
  "path": "src/gateways/openai/gateway.ts",
13
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type {\n ExtractImageModelIdFromProvider,\n ExtractModelIdFromProvider,\n} from \"@chat-js/gateways/provider-types\";\n\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\nimport { z } from \"zod\";\n\ntype OpenaiImageModelId = ExtractImageModelIdFromProvider<typeof createOpenAI>;\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAIModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAIModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by:\n (model.owned_by === \"system\" ? \"openai\" : model.owned_by) ?? \"openai\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAIGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai\">\n{\n public readonly type = \"openai\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAI> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENAI_API_KEY is not configured\");\n }\n return createOpenAI({ apiKey });\n }\n\n public createLanguageModel(\n modelId: ExtractModelIdFromProvider<typeof createOpenAI>\n ): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: OpenaiImageModelId): ImageModel {\n const provider = this.getProvider();\n return provider.image(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENAI_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://api.openai.com/v1/models\";\n this.log.debug({ url }, \"Fetching models from OpenAI\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAIGateway as Gateway, OpenAIGateway };\n",
12
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\nimport { z } from \"zod\";\n\nconst MODEL_ID_PARAMETER_INDEX = 0;\ntype OpenAiLanguageModelId = Parameters<\n ReturnType<typeof createOpenAI>[\"languageModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\ntype OpenAiImageModelId = Parameters<\n ReturnType<typeof createOpenAI>[\"image\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAIModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAIModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by:\n (model.owned_by === \"system\" ? \"openai\" : model.owned_by) ?? \"openai\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAIGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai\">\n{\n public readonly type = \"openai\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAI> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENAI_API_KEY is not configured\");\n }\n return createOpenAI({ apiKey });\n }\n\n public createLanguageModel(modelId: OpenAiLanguageModelId): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: OpenAiImageModelId): ImageModel {\n const provider = this.getProvider();\n return provider.image(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENAI_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://api.openai.com/v1/models\";\n this.log.debug({ url }, \"Fetching models from OpenAI\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAIGateway as Gateway, OpenAIGateway };\n",
14
13
  "type": "registry:file",
15
14
  "target": "~/chatjs/providers/gateway.ts"
16
15
  }
@@ -3,14 +3,13 @@
3
3
  "name": "openrouter-gateway",
4
4
  "title": "OpenRouter",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@openrouter/ai-sdk-provider@3.0.0",
8
7
  "zod@4.5.4"
9
8
  ],
10
9
  "files": [
11
10
  {
12
11
  "path": "src/gateways/openrouter/gateway.ts",
13
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport { createOpenRouter } from \"@openrouter/ai-sdk-provider\";\n\nimport { z } from \"zod\";\n\nconst MODEL_OWNER_SEGMENT_INDEX = 0;\nconst EMPTY_TAG_COUNT = 0;\nconst OPENROUTER_MODELS_URL = \"https://openrouter.ai/api/v1/models\";\n\nconst modalitiesSchema = z.array(z.string()).nullish();\nconst providerModelSchema = z.object({\n architecture: z\n .object({\n input_modalities: modalitiesSchema,\n output_modalities: modalitiesSchema,\n })\n .nullish(),\n context_length: z.number().nullish(),\n created: z.number().nullish(),\n description: z.string().nullish(),\n id: z.string(),\n name: z.string().nullish(),\n pricing: z\n .object({\n completion: z.string().optional(),\n image: z.string().optional(),\n input_cache_read: z.string().optional(),\n input_cache_write: z.string().optional(),\n prompt: z.string().optional(),\n web_search: z.string().optional(),\n })\n .nullish(),\n supported_parameters: z.array(z.string()).nullish(),\n top_provider: z\n .object({ max_completion_tokens: z.number().nullish() })\n .nullish(),\n});\ntype OpenRouterModelResponse = Omit<\n z.output<typeof providerModelSchema>,\n \"architecture\" | \"pricing\" | \"top_provider\" | \"supported_parameters\"\n> & {\n architecture?: {\n readonly input_modalities?: readonly string[] | null;\n readonly output_modalities?: readonly string[] | null;\n } | null;\n pricing?: Readonly<z.output<typeof providerModelSchema>[\"pricing\"]>;\n top_provider?: Readonly<z.output<typeof providerModelSchema>[\"top_provider\"]>;\n supported_parameters?: readonly string[] | null;\n};\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst deriveTags = (model: Readonly<OpenRouterModelResponse>): string[] => {\n const inputMods = (model.architecture ?? {}).input_modalities ?? [\"text\"];\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n const supportedParams = model.supported_parameters ?? [];\n\n const capabilities: readonly (readonly [boolean, string])[] = [\n [inputMods.includes(\"image\"), \"vision\"],\n [inputMods.includes(\"file\"), \"file-input\"],\n [outputMods.includes(\"image\"), \"image-generation\"],\n [\n supportedParams.includes(\"reasoning\") ||\n supportedParams.includes(\"include_reasoning\"),\n \"reasoning\",\n ],\n [supportedParams.includes(\"tools\"), \"tool-use\"],\n ];\n return capabilities.filter(([supported]) => supported).map(([, tag]) => tag);\n};\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenRouterModelResponse>\n): AiGatewayModel => {\n const tags = deriveTags(model);\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n\n let type: \"language\" | \"embedding\" | \"image\" = \"language\";\n if (!outputMods.includes(\"text\") && outputMods.includes(\"image\")) {\n type = \"image\";\n }\n\n const owned_by =\n model.id.split(\"/\").at(MODEL_OWNER_SEGMENT_INDEX) ?? \"unknown\";\n\n return {\n context_window: model.context_length ?? UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: model.description ?? \"\",\n id: model.id,\n max_tokens:\n (model.top_provider ?? {}).max_completion_tokens ?? UNKNOWN_MODEL_LIMIT,\n name: model.name ?? model.id,\n object: \"model\",\n owned_by,\n pricing: {\n image: (model.pricing ?? {}).image,\n input: (model.pricing ?? {}).prompt,\n input_cache_read: (model.pricing ?? {}).input_cache_read,\n input_cache_write: (model.pricing ?? {}).input_cache_write,\n output: (model.pricing ?? {}).completion,\n web_search: (model.pricing ?? {}).web_search,\n },\n tags: tags.length > EMPTY_TAG_COUNT ? tags : undefined,\n type,\n };\n};\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenRouterGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openrouter\">\n{\n public readonly type = \"openrouter\" as const;\n\n private getProvider(): ReturnType<typeof createOpenRouter> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENROUTER_API_KEY is not configured\");\n }\n return createOpenRouter({ apiKey });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider.chat(modelId);\n }\n\n // OpenRouter generates images through multimodal language models.\n public readonly createImageModel = null;\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENROUTER_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENROUTER_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = OPENROUTER_MODELS_URL;\n this.log.debug({ url }, \"Fetching models from OpenRouter\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenRouter returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenRouter\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenRouter, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenRouterGateway as Gateway, OpenRouterGateway };\n",
12
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport { createOpenRouter } from \"@openrouter/ai-sdk-provider\";\n\nimport { z } from \"zod\";\n\nconst MODEL_OWNER_SEGMENT_INDEX = 0;\nconst EMPTY_TAG_COUNT = 0;\nconst OPENROUTER_MODELS_URL = \"https://openrouter.ai/api/v1/models\";\n\nconst modalitiesSchema = z.array(z.string()).nullish();\nconst providerModelSchema = z.object({\n architecture: z\n .object({\n input_modalities: modalitiesSchema,\n output_modalities: modalitiesSchema,\n })\n .nullish(),\n context_length: z.number().nullish(),\n created: z.number().nullish(),\n description: z.string().nullish(),\n id: z.string(),\n name: z.string().nullish(),\n pricing: z\n .object({\n completion: z.string().optional(),\n image: z.string().optional(),\n input_cache_read: z.string().optional(),\n input_cache_write: z.string().optional(),\n prompt: z.string().optional(),\n web_search: z.string().optional(),\n })\n .nullish(),\n supported_parameters: z.array(z.string()).nullish(),\n top_provider: z\n .object({ max_completion_tokens: z.number().nullish() })\n .nullish(),\n});\ntype OpenRouterModelResponse = Omit<\n z.output<typeof providerModelSchema>,\n \"architecture\" | \"pricing\" | \"top_provider\" | \"supported_parameters\"\n> & {\n architecture?: {\n readonly input_modalities?: readonly string[] | null;\n readonly output_modalities?: readonly string[] | null;\n } | null;\n pricing?: Readonly<z.output<typeof providerModelSchema>[\"pricing\"]>;\n top_provider?: Readonly<z.output<typeof providerModelSchema>[\"top_provider\"]>;\n supported_parameters?: readonly string[] | null;\n};\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst deriveTags = (model: Readonly<OpenRouterModelResponse>): string[] => {\n const inputMods = (model.architecture ?? {}).input_modalities ?? [\"text\"];\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n const supportedParams = model.supported_parameters ?? [];\n\n const capabilities: readonly (readonly [boolean, string])[] = [\n [inputMods.includes(\"image\"), \"vision\"],\n [inputMods.includes(\"file\"), \"file-input\"],\n [outputMods.includes(\"image\"), \"image-generation\"],\n [\n supportedParams.includes(\"reasoning\") ||\n supportedParams.includes(\"include_reasoning\"),\n \"reasoning\",\n ],\n [supportedParams.includes(\"tools\"), \"tool-use\"],\n ];\n return capabilities.filter(([supported]) => supported).map(([, tag]) => tag);\n};\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenRouterModelResponse>\n): AiGatewayModel => {\n const tags = deriveTags(model);\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n\n let type: \"language\" | \"embedding\" | \"image\" = \"language\";\n if (!outputMods.includes(\"text\") && outputMods.includes(\"image\")) {\n type = \"image\";\n }\n\n const owned_by =\n model.id.split(\"/\").at(MODEL_OWNER_SEGMENT_INDEX) ?? \"unknown\";\n\n return {\n context_window: model.context_length ?? UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: model.description ?? \"\",\n id: model.id,\n max_tokens:\n (model.top_provider ?? {}).max_completion_tokens ?? UNKNOWN_MODEL_LIMIT,\n name: model.name ?? model.id,\n object: \"model\",\n owned_by,\n pricing: {\n image: (model.pricing ?? {}).image,\n input: (model.pricing ?? {}).prompt,\n input_cache_read: (model.pricing ?? {}).input_cache_read,\n input_cache_write: (model.pricing ?? {}).input_cache_write,\n output: (model.pricing ?? {}).completion,\n web_search: (model.pricing ?? {}).web_search,\n },\n tags: tags.length > EMPTY_TAG_COUNT ? tags : undefined,\n type,\n };\n};\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenRouterGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openrouter\">\n{\n public readonly type = \"openrouter\" as const;\n\n private getProvider(): ReturnType<typeof createOpenRouter> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENROUTER_API_KEY is not configured\");\n }\n return createOpenRouter({ apiKey });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider.chat(modelId);\n }\n\n // OpenRouter generates images through multimodal language models.\n public readonly createImageModel = null;\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENROUTER_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENROUTER_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = OPENROUTER_MODELS_URL;\n this.log.debug({ url }, \"Fetching models from OpenRouter\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenRouter returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenRouter\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenRouter, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenRouterGateway as Gateway, OpenRouterGateway };\n",
14
13
  "type": "registry:file",
15
14
  "target": "~/chatjs/providers/gateway.ts"
16
15
  }
@@ -3,13 +3,12 @@
3
3
  "name": "litellm-gateway",
4
4
  "title": "LiteLLM",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@ai-sdk/openai-compatible@3.0.92"
8
7
  ],
9
8
  "files": [
10
9
  {
11
10
  "path": "src/gateways/litellm/gateway.ts",
12
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst MODEL_DISCOVERY_TIMEOUT_MS = 10_000;\nconst TRAILING_SLASHES_REGEX = /\\/+$/u;\n\nconst litellmModelSchema = z.object({\n created: z.number().optional(),\n id: z.string(),\n object: z.string().optional(),\n owned_by: z.string().optional(),\n});\nconst litellmModelsResponseSchema = z.object({\n data: z.array(litellmModelSchema),\n});\n\ntype LiteLLMModelResponse = z.infer<\n typeof litellmModelsResponseSchema\n>[\"data\"][number];\n\nconst getModelsUrl = (baseURL: string): string => {\n const normalizedBaseURL = baseURL.replace(TRAILING_SLASHES_REGEX, \"\");\n if (normalizedBaseURL.endsWith(\"/v1\")) {\n return `${normalizedBaseURL}/models`;\n }\n return `${normalizedBaseURL}/v1/models`;\n};\n\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst toAiGatewayModel = (model: LiteLLMModelResponse): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_LIMIT,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"litellm\",\n pricing: {},\n type: \"language\",\n});\n\nclass LiteLLMGateway\n extends GatewayRuntime\n implements GatewayProvider<\"litellm\">\n{\n public readonly type = \"litellm\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"LITELLM_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"litellm\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.LITELLM_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.LITELLM_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\"No LITELLM_BASE_URL found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = getModelsUrl(baseURL);\n this.log.debug({ url }, \"Fetching models from LiteLLM proxy\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n signal: AbortSignal.timeout(MODEL_DISCOVERY_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"LiteLLM proxy returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const body = litellmModelsResponseSchema.parse(await response.json());\n const models = body.data;\n const result = models.map((model) => toAiGatewayModel(model));\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from LiteLLM proxy\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from LiteLLM proxy, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { LiteLLMGateway as Gateway, LiteLLMGateway };\n",
11
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst MODEL_DISCOVERY_TIMEOUT_MS = 10_000;\nconst TRAILING_SLASHES_REGEX = /\\/+$/u;\n\nconst litellmModelSchema = z.object({\n created: z.number().optional(),\n id: z.string(),\n object: z.string().optional(),\n owned_by: z.string().optional(),\n});\nconst litellmModelsResponseSchema = z.object({\n data: z.array(litellmModelSchema),\n});\n\ntype LiteLLMModelResponse = z.infer<\n typeof litellmModelsResponseSchema\n>[\"data\"][number];\n\nconst getModelsUrl = (baseURL: string): string => {\n const normalizedBaseURL = baseURL.replace(TRAILING_SLASHES_REGEX, \"\");\n if (normalizedBaseURL.endsWith(\"/v1\")) {\n return `${normalizedBaseURL}/models`;\n }\n return `${normalizedBaseURL}/v1/models`;\n};\n\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst toAiGatewayModel = (model: LiteLLMModelResponse): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_LIMIT,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"litellm\",\n pricing: {},\n type: \"language\",\n});\n\nclass LiteLLMGateway\n extends GatewayRuntime\n implements GatewayProvider<\"litellm\">\n{\n public readonly type = \"litellm\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"LITELLM_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"litellm\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.LITELLM_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.LITELLM_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\"No LITELLM_BASE_URL found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = getModelsUrl(baseURL);\n this.log.debug({ url }, \"Fetching models from LiteLLM proxy\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n signal: AbortSignal.timeout(MODEL_DISCOVERY_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"LiteLLM proxy returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const body = litellmModelsResponseSchema.parse(await response.json());\n const models = body.data;\n const result = models.map((model) => toAiGatewayModel(model));\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from LiteLLM proxy\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from LiteLLM proxy, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { LiteLLMGateway as Gateway, LiteLLMGateway };\n",
13
12
  "type": "registry:file",
14
13
  "target": "~/chatjs/providers/gateway.ts"
15
14
  }
@@ -3,14 +3,13 @@
3
3
  "name": "openai-compatible-gateway",
4
4
  "title": "OpenAI Compatible",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@ai-sdk/openai-compatible@3.0.92",
8
7
  "zod@4.5.4"
9
8
  ],
10
9
  "files": [
11
10
  {
12
11
  "path": "src/gateways/openai-compatible/gateway.ts",
13
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAICompatibleModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAICompatibleModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"unknown\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAICompatibleGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai-compatible\">\n{\n public readonly type = \"openai-compatible\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"OPENAI_COMPATIBLE_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"openai-compatible\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_COMPATIBLE_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.OPENAI_COMPATIBLE_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\n \"No OPENAI_COMPATIBLE_BASE_URL found, using fallback models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = `${baseURL}/models`;\n this.log.debug({ url }, \"Fetching models from OpenAI-compatible provider\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI-compatible provider returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI-compatible provider\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI-compatible provider, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAICompatibleGateway as Gateway, OpenAICompatibleGateway };\n",
12
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { z } from \"zod\";\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAICompatibleModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAICompatibleModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by: model.owned_by ?? \"unknown\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAICompatibleGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai-compatible\">\n{\n public readonly type = \"openai-compatible\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAICompatible> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n throw new Error(\"OPENAI_COMPATIBLE_BASE_URL is not configured\");\n }\n return createOpenAICompatible({\n apiKey,\n baseURL,\n name: \"openai-compatible\",\n });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: string): ImageModel {\n const provider = this.getProvider();\n return provider.imageModel(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_COMPATIBLE_API_KEY;\n }\n\n private getBaseURL(): string | undefined {\n const baseURL = this.env.OPENAI_COMPATIBLE_BASE_URL;\n if (baseURL === undefined || baseURL === \"\") {\n return undefined;\n }\n return z.url().parse(baseURL);\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n const baseURL = this.getBaseURL();\n\n if (!(typeof baseURL === \"string\" && baseURL !== \"\")) {\n this.log.warn(\n \"No OPENAI_COMPATIBLE_BASE_URL found, using fallback models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = `${baseURL}/models`;\n this.log.debug({ url }, \"Fetching models from OpenAI-compatible provider\");\n\n try {\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n headers.Authorization = `Bearer ${apiKey}`;\n }\n\n const response = await this.fetch(url, {\n headers,\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI-compatible provider returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI-compatible provider\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI-compatible provider, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAICompatibleGateway as Gateway, OpenAICompatibleGateway };\n",
14
13
  "type": "registry:file",
15
14
  "target": "~/chatjs/providers/gateway.ts"
16
15
  }
@@ -3,14 +3,13 @@
3
3
  "name": "openai-gateway",
4
4
  "title": "OpenAI",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@ai-sdk/openai@4.0.117",
8
7
  "zod@4.5.4"
9
8
  ],
10
9
  "files": [
11
10
  {
12
11
  "path": "src/gateways/openai/gateway.ts",
13
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type {\n ExtractImageModelIdFromProvider,\n ExtractModelIdFromProvider,\n} from \"@chat-js/gateways/provider-types\";\n\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\nimport { z } from \"zod\";\n\ntype OpenaiImageModelId = ExtractImageModelIdFromProvider<typeof createOpenAI>;\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAIModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAIModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by:\n (model.owned_by === \"system\" ? \"openai\" : model.owned_by) ?? \"openai\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAIGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai\">\n{\n public readonly type = \"openai\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAI> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENAI_API_KEY is not configured\");\n }\n return createOpenAI({ apiKey });\n }\n\n public createLanguageModel(\n modelId: ExtractModelIdFromProvider<typeof createOpenAI>\n ): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: OpenaiImageModelId): ImageModel {\n const provider = this.getProvider();\n return provider.image(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENAI_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://api.openai.com/v1/models\";\n this.log.debug({ url }, \"Fetching models from OpenAI\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAIGateway as Gateway, OpenAIGateway };\n",
12
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\n\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport type { ImageModel } from \"ai\";\nimport { createOpenAI } from \"@ai-sdk/openai\";\nimport { z } from \"zod\";\n\nconst MODEL_ID_PARAMETER_INDEX = 0;\ntype OpenAiLanguageModelId = Parameters<\n ReturnType<typeof createOpenAI>[\"languageModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\ntype OpenAiImageModelId = Parameters<\n ReturnType<typeof createOpenAI>[\"image\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\n\nconst providerModelSchema = z.object({\n created: z.number().nullish(),\n id: z.string(),\n owned_by: z.string().nullish(),\n});\ntype OpenAIModelResponse = z.output<typeof providerModelSchema>;\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenAIModelResponse>\n): AiGatewayModel => ({\n context_window: UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: \"\",\n id: model.id,\n max_tokens: UNKNOWN_MODEL_LIMIT,\n name: model.id,\n object: \"model\",\n owned_by:\n (model.owned_by === \"system\" ? \"openai\" : model.owned_by) ?? \"openai\",\n pricing: {},\n type: \"language\",\n});\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenAIGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openai\">\n{\n public readonly type = \"openai\" as const;\n\n private getProvider(): ReturnType<typeof createOpenAI> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENAI_API_KEY is not configured\");\n }\n return createOpenAI({ apiKey });\n }\n\n public createLanguageModel(modelId: OpenAiLanguageModelId): LanguageModelV4 {\n const provider = this.getProvider();\n return provider(modelId);\n }\n\n public createImageModel(modelId: OpenAiImageModelId): ImageModel {\n const provider = this.getProvider();\n return provider.image(modelId);\n }\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENAI_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENAI_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://api.openai.com/v1/models\";\n this.log.debug({ url }, \"Fetching models from OpenAI\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenAI returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenAI\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenAI, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenAIGateway as Gateway, OpenAIGateway };\n",
14
13
  "type": "registry:file",
15
14
  "target": "~/chatjs/providers/gateway.ts"
16
15
  }
@@ -3,14 +3,13 @@
3
3
  "name": "openrouter-gateway",
4
4
  "title": "OpenRouter",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
6
  "@openrouter/ai-sdk-provider@3.0.0",
8
7
  "zod@4.5.4"
9
8
  ],
10
9
  "files": [
11
10
  {
12
11
  "path": "src/gateways/openrouter/gateway.ts",
13
- "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\n\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\n\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\n\nimport { createOpenRouter } from \"@openrouter/ai-sdk-provider\";\n\nimport { z } from \"zod\";\n\nconst MODEL_OWNER_SEGMENT_INDEX = 0;\nconst EMPTY_TAG_COUNT = 0;\nconst OPENROUTER_MODELS_URL = \"https://openrouter.ai/api/v1/models\";\n\nconst modalitiesSchema = z.array(z.string()).nullish();\nconst providerModelSchema = z.object({\n architecture: z\n .object({\n input_modalities: modalitiesSchema,\n output_modalities: modalitiesSchema,\n })\n .nullish(),\n context_length: z.number().nullish(),\n created: z.number().nullish(),\n description: z.string().nullish(),\n id: z.string(),\n name: z.string().nullish(),\n pricing: z\n .object({\n completion: z.string().optional(),\n image: z.string().optional(),\n input_cache_read: z.string().optional(),\n input_cache_write: z.string().optional(),\n prompt: z.string().optional(),\n web_search: z.string().optional(),\n })\n .nullish(),\n supported_parameters: z.array(z.string()).nullish(),\n top_provider: z\n .object({ max_completion_tokens: z.number().nullish() })\n .nullish(),\n});\ntype OpenRouterModelResponse = Omit<\n z.output<typeof providerModelSchema>,\n \"architecture\" | \"pricing\" | \"top_provider\" | \"supported_parameters\"\n> & {\n architecture?: {\n readonly input_modalities?: readonly string[] | null;\n readonly output_modalities?: readonly string[] | null;\n } | null;\n pricing?: Readonly<z.output<typeof providerModelSchema>[\"pricing\"]>;\n top_provider?: Readonly<z.output<typeof providerModelSchema>[\"top_provider\"]>;\n supported_parameters?: readonly string[] | null;\n};\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst deriveTags = (model: Readonly<OpenRouterModelResponse>): string[] => {\n const inputMods = (model.architecture ?? {}).input_modalities ?? [\"text\"];\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n const supportedParams = model.supported_parameters ?? [];\n\n const capabilities: readonly (readonly [boolean, string])[] = [\n [inputMods.includes(\"image\"), \"vision\"],\n [inputMods.includes(\"file\"), \"file-input\"],\n [outputMods.includes(\"image\"), \"image-generation\"],\n [\n supportedParams.includes(\"reasoning\") ||\n supportedParams.includes(\"include_reasoning\"),\n \"reasoning\",\n ],\n [supportedParams.includes(\"tools\"), \"tool-use\"],\n ];\n return capabilities.filter(([supported]) => supported).map(([, tag]) => tag);\n};\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenRouterModelResponse>\n): AiGatewayModel => {\n const tags = deriveTags(model);\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n\n let type: \"language\" | \"embedding\" | \"image\" = \"language\";\n if (!outputMods.includes(\"text\") && outputMods.includes(\"image\")) {\n type = \"image\";\n }\n\n const owned_by =\n model.id.split(\"/\").at(MODEL_OWNER_SEGMENT_INDEX) ?? \"unknown\";\n\n return {\n context_window: model.context_length ?? UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: model.description ?? \"\",\n id: model.id,\n max_tokens:\n (model.top_provider ?? {}).max_completion_tokens ?? UNKNOWN_MODEL_LIMIT,\n name: model.name ?? model.id,\n object: \"model\",\n owned_by,\n pricing: {\n image: (model.pricing ?? {}).image,\n input: (model.pricing ?? {}).prompt,\n input_cache_read: (model.pricing ?? {}).input_cache_read,\n input_cache_write: (model.pricing ?? {}).input_cache_write,\n output: (model.pricing ?? {}).completion,\n web_search: (model.pricing ?? {}).web_search,\n },\n tags: tags.length > EMPTY_TAG_COUNT ? tags : undefined,\n type,\n };\n};\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenRouterGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openrouter\">\n{\n public readonly type = \"openrouter\" as const;\n\n private getProvider(): ReturnType<typeof createOpenRouter> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENROUTER_API_KEY is not configured\");\n }\n return createOpenRouter({ apiKey });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider.chat(modelId);\n }\n\n // OpenRouter generates images through multimodal language models.\n public readonly createImageModel = null;\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENROUTER_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENROUTER_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = OPENROUTER_MODELS_URL;\n this.log.debug({ url }, \"Fetching models from OpenRouter\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenRouter returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenRouter\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenRouter, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenRouterGateway as Gateway, OpenRouterGateway };\n",
12
+ "content": "import type { LanguageModelV4 } from \"@ai-sdk/provider\";\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\n\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\n\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\n\nimport { createOpenRouter } from \"@openrouter/ai-sdk-provider\";\n\nimport { z } from \"zod\";\n\nconst MODEL_OWNER_SEGMENT_INDEX = 0;\nconst EMPTY_TAG_COUNT = 0;\nconst OPENROUTER_MODELS_URL = \"https://openrouter.ai/api/v1/models\";\n\nconst modalitiesSchema = z.array(z.string()).nullish();\nconst providerModelSchema = z.object({\n architecture: z\n .object({\n input_modalities: modalitiesSchema,\n output_modalities: modalitiesSchema,\n })\n .nullish(),\n context_length: z.number().nullish(),\n created: z.number().nullish(),\n description: z.string().nullish(),\n id: z.string(),\n name: z.string().nullish(),\n pricing: z\n .object({\n completion: z.string().optional(),\n image: z.string().optional(),\n input_cache_read: z.string().optional(),\n input_cache_write: z.string().optional(),\n prompt: z.string().optional(),\n web_search: z.string().optional(),\n })\n .nullish(),\n supported_parameters: z.array(z.string()).nullish(),\n top_provider: z\n .object({ max_completion_tokens: z.number().nullish() })\n .nullish(),\n});\ntype OpenRouterModelResponse = Omit<\n z.output<typeof providerModelSchema>,\n \"architecture\" | \"pricing\" | \"top_provider\" | \"supported_parameters\"\n> & {\n architecture?: {\n readonly input_modalities?: readonly string[] | null;\n readonly output_modalities?: readonly string[] | null;\n } | null;\n pricing?: Readonly<z.output<typeof providerModelSchema>[\"pricing\"]>;\n top_provider?: Readonly<z.output<typeof providerModelSchema>[\"top_provider\"]>;\n supported_parameters?: readonly string[] | null;\n};\nconst providerModelListSchema = z.object({\n data: z.array(z.unknown()),\n});\n\nconst deriveTags = (model: Readonly<OpenRouterModelResponse>): string[] => {\n const inputMods = (model.architecture ?? {}).input_modalities ?? [\"text\"];\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n const supportedParams = model.supported_parameters ?? [];\n\n const capabilities: readonly (readonly [boolean, string])[] = [\n [inputMods.includes(\"image\"), \"vision\"],\n [inputMods.includes(\"file\"), \"file-input\"],\n [outputMods.includes(\"image\"), \"image-generation\"],\n [\n supportedParams.includes(\"reasoning\") ||\n supportedParams.includes(\"include_reasoning\"),\n \"reasoning\",\n ],\n [supportedParams.includes(\"tools\"), \"tool-use\"],\n ];\n return capabilities.filter(([supported]) => supported).map(([, tag]) => tag);\n};\n\nconst EMPTY_MODEL_COUNT = 0;\nconst UNKNOWN_MODEL_LIMIT = 0;\nconst UNKNOWN_MODEL_TIMESTAMP = 0;\nconst toAiGatewayModel = (\n model: Readonly<OpenRouterModelResponse>\n): AiGatewayModel => {\n const tags = deriveTags(model);\n const outputMods = (model.architecture ?? {}).output_modalities ?? [\"text\"];\n\n let type: \"language\" | \"embedding\" | \"image\" = \"language\";\n if (!outputMods.includes(\"text\") && outputMods.includes(\"image\")) {\n type = \"image\";\n }\n\n const owned_by =\n model.id.split(\"/\").at(MODEL_OWNER_SEGMENT_INDEX) ?? \"unknown\";\n\n return {\n context_window: model.context_length ?? UNKNOWN_MODEL_LIMIT,\n created: model.created ?? UNKNOWN_MODEL_TIMESTAMP,\n description: model.description ?? \"\",\n id: model.id,\n max_tokens:\n (model.top_provider ?? {}).max_completion_tokens ?? UNKNOWN_MODEL_LIMIT,\n name: model.name ?? model.id,\n object: \"model\",\n owned_by,\n pricing: {\n image: (model.pricing ?? {}).image,\n input: (model.pricing ?? {}).prompt,\n input_cache_read: (model.pricing ?? {}).input_cache_read,\n input_cache_write: (model.pricing ?? {}).input_cache_write,\n output: (model.pricing ?? {}).completion,\n web_search: (model.pricing ?? {}).web_search,\n },\n tags: tags.length > EMPTY_TAG_COUNT ? tags : undefined,\n type,\n };\n};\n\n// Validate the wire envelope separately from each model so valid neighbors survive.\nconst parseProviderModels = (value: unknown): AiGatewayModel[] => {\n const body = providerModelListSchema.parse(value);\n const result = body.data.flatMap((entry): AiGatewayModel[] => {\n const model = providerModelSchema.safeParse(entry);\n if (!model.success) {\n return [];\n }\n return [toAiGatewayModel(model.data)];\n });\n // A genuinely empty catalog is valid; a nonempty unparseable catalog is not.\n if (\n body.data.length > EMPTY_MODEL_COUNT &&\n result.length === EMPTY_MODEL_COUNT\n ) {\n throw new Error(\"Provider catalog contains no valid models.\");\n }\n return result;\n};\n\nclass OpenRouterGateway\n extends GatewayRuntime\n implements GatewayProvider<\"openrouter\">\n{\n public readonly type = \"openrouter\" as const;\n\n private getProvider(): ReturnType<typeof createOpenRouter> {\n const apiKey = this.getApiKey();\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n throw new Error(\"OPENROUTER_API_KEY is not configured\");\n }\n return createOpenRouter({ apiKey });\n }\n\n public createLanguageModel(modelId: string): LanguageModelV4 {\n const provider = this.getProvider();\n return provider.chat(modelId);\n }\n\n // OpenRouter generates images through multimodal language models.\n public readonly createImageModel = null;\n\n public readonly createVideoModel = null;\n\n private getApiKey(): string | undefined {\n return this.env.OPENROUTER_API_KEY;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No OPENROUTER_API_KEY found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = OPENROUTER_MODELS_URL;\n this.log.debug({ url }, \"Fetching models from OpenRouter\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"OpenRouter returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const result = parseProviderModels(await response.json());\n\n this.log.info(\n { modelCount: result.length },\n \"Successfully fetched models from OpenRouter\"\n );\n return result;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from OpenRouter, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { OpenRouterGateway as Gateway, OpenRouterGateway };\n",
14
13
  "type": "registry:file",
15
14
  "target": "~/chatjs/providers/gateway.ts"
16
15
  }
@@ -1898,8 +1898,8 @@
1898
1898
  "name": "vercel-gateway",
1899
1899
  "title": "Vercel AI Gateway",
1900
1900
  "dependencies": [
1901
- "@chat-js/gateways@0.2.2",
1902
- "@ai-sdk/gateway@4.0.145"
1901
+ "@ai-sdk/gateway@4.0.145",
1902
+ "zod@4.5.4"
1903
1903
  ],
1904
1904
  "files": [
1905
1905
  {
@@ -1970,7 +1970,6 @@
1970
1970
  "name": "openai-gateway",
1971
1971
  "title": "OpenAI",
1972
1972
  "dependencies": [
1973
- "@chat-js/gateways@0.2.2",
1974
1973
  "@ai-sdk/openai@4.0.117",
1975
1974
  "zod@4.5.4"
1976
1975
  ],
@@ -2033,7 +2032,6 @@
2033
2032
  "name": "openai-compatible-gateway",
2034
2033
  "title": "OpenAI Compatible",
2035
2034
  "dependencies": [
2036
- "@chat-js/gateways@0.2.2",
2037
2035
  "@ai-sdk/openai-compatible@3.0.92",
2038
2036
  "zod@4.5.4"
2039
2037
  ],
@@ -2098,7 +2096,6 @@
2098
2096
  "name": "openrouter-gateway",
2099
2097
  "title": "OpenRouter",
2100
2098
  "dependencies": [
2101
- "@chat-js/gateways@0.2.2",
2102
2099
  "@openrouter/ai-sdk-provider@3.0.0",
2103
2100
  "zod@4.5.4"
2104
2101
  ],
@@ -2168,7 +2165,6 @@
2168
2165
  "name": "litellm-gateway",
2169
2166
  "title": "LiteLLM",
2170
2167
  "dependencies": [
2171
- "@chat-js/gateways@0.2.2",
2172
2168
  "@ai-sdk/openai-compatible@3.0.92"
2173
2169
  ],
2174
2170
  "files": [
@@ -3,13 +3,13 @@
3
3
  "name": "vercel-gateway",
4
4
  "title": "Vercel AI Gateway",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
- "@ai-sdk/gateway@4.0.145"
6
+ "@ai-sdk/gateway@4.0.145",
7
+ "zod@4.5.4"
8
8
  ],
9
9
  "files": [
10
10
  {
11
11
  "path": "src/gateways/vercel/gateway.ts",
12
- "content": "import type {\n Experimental_VideoModelV4,\n LanguageModelV4,\n} from \"@ai-sdk/provider\";\nimport {\n aiGatewayModelDiscriminatorSchema,\n aiGatewayModelSchema,\n aiGatewayModelsEnvelopeSchema,\n isAiGatewayModelType,\n} from \"@chat-js/gateways/models\";\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\nimport type { ImageModel } from \"ai\";\n\nimport { createGateway } from \"@ai-sdk/gateway\";\nimport type { gateway } from \"@ai-sdk/gateway\";\n\nconst MODEL_ID_PARAMETER_INDEX = 0;\ntype VercelImageModelId = Parameters<\n (typeof gateway)[\"imageModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\ntype VercelVideoModelId = Parameters<\n (typeof gateway)[\"videoModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\n\nconst EMPTY_MODEL_TYPE_COUNT = 0;\n\nclass VercelGateway\n extends GatewayRuntime\n implements GatewayProvider<\"vercel\">\n{\n public readonly type = \"vercel\" as const;\n\n public createLanguageModel(\n modelId: Parameters<\n (typeof gateway)[\"languageModel\"]\n >[typeof MODEL_ID_PARAMETER_INDEX]\n ): LanguageModelV4 {\n return this.getProvider()(modelId);\n }\n\n public createImageModel(modelId: VercelImageModelId): ImageModel {\n return this.getProvider().imageModel(modelId);\n }\n\n public createVideoModel(\n modelId: VercelVideoModelId\n ): Experimental_VideoModelV4 {\n return this.getProvider().videoModel(modelId);\n }\n\n private provider?: ReturnType<typeof createGateway>;\n\n private getProvider(): ReturnType<typeof createGateway> {\n this.provider ??= createGateway({ apiKey: this.env.AI_GATEWAY_API_KEY });\n return this.provider;\n }\n\n private getApiKey(): string | undefined {\n const apiKey = this.env.AI_GATEWAY_API_KEY;\n\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n return apiKey;\n }\n return this.env.VERCEL_OIDC_TOKEN;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No AI gateway API key found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://ai-gateway.vercel.sh/v1/models\";\n this.log.debug({ url }, \"Fetching models from Vercel AI Gateway\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"Vercel AI Gateway returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const bodyRaw: unknown = await response.json();\n const body = aiGatewayModelsEnvelopeSchema.parse(bodyRaw);\n const unsupportedTypes = new Set<string>();\n const models: AiGatewayModel[] = [];\n\n for (const candidate of body.data) {\n const { type } = aiGatewayModelDiscriminatorSchema.parse(candidate);\n if (isAiGatewayModelType(type)) {\n const model = aiGatewayModelSchema.parse(candidate);\n models.push({ ...model, type });\n } else {\n unsupportedTypes.add(type);\n }\n }\n\n if (unsupportedTypes.size > EMPTY_MODEL_TYPE_COUNT) {\n this.log.warn(\n {\n modelCount: body.data.length,\n skippedModelCount: body.data.length - models.length,\n unsupportedTypes: [...unsupportedTypes],\n },\n \"Skipping models with unsupported types from Vercel AI Gateway\"\n );\n }\n\n this.log.info(\n { modelCount: models.length },\n \"Successfully fetched models from Vercel AI Gateway\"\n );\n return models;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from Vercel AI Gateway, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { VercelGateway as Gateway, VercelGateway };\n",
12
+ "content": "import type {\n Experimental_VideoModelV4,\n LanguageModelV4,\n} from \"@ai-sdk/provider\";\nimport {\n aiGatewayModelSchema,\n isAiGatewayModelType,\n} from \"@/chatjs/core/gateway/models\";\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\nimport type { ImageModel } from \"ai\";\n\nimport { createGateway } from \"@ai-sdk/gateway\";\nimport type { gateway } from \"@ai-sdk/gateway\";\nimport { z } from \"zod\";\n\nconst MODEL_ID_PARAMETER_INDEX = 0;\ntype VercelImageModelId = Parameters<\n (typeof gateway)[\"imageModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\ntype VercelVideoModelId = Parameters<\n (typeof gateway)[\"videoModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\n\nconst EMPTY_MODEL_TYPE_COUNT = 0;\nconst modelDiscriminatorSchema = z.object({ type: z.string() });\nconst modelsEnvelopeSchema = z.object({\n data: z.array(z.unknown()),\n object: z.literal(\"list\"),\n});\n\nclass VercelGateway\n extends GatewayRuntime\n implements GatewayProvider<\"vercel\">\n{\n public readonly type = \"vercel\" as const;\n\n public createLanguageModel(\n modelId: Parameters<\n (typeof gateway)[\"languageModel\"]\n >[typeof MODEL_ID_PARAMETER_INDEX]\n ): LanguageModelV4 {\n return this.getProvider()(modelId);\n }\n\n public createImageModel(modelId: VercelImageModelId): ImageModel {\n return this.getProvider().imageModel(modelId);\n }\n\n public createVideoModel(\n modelId: VercelVideoModelId\n ): Experimental_VideoModelV4 {\n return this.getProvider().videoModel(modelId);\n }\n\n private provider?: ReturnType<typeof createGateway>;\n\n private getProvider(): ReturnType<typeof createGateway> {\n this.provider ??= createGateway({ apiKey: this.env.AI_GATEWAY_API_KEY });\n return this.provider;\n }\n\n private getApiKey(): string | undefined {\n const apiKey = this.env.AI_GATEWAY_API_KEY;\n\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n return apiKey;\n }\n return this.env.VERCEL_OIDC_TOKEN;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No AI gateway API key found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://ai-gateway.vercel.sh/v1/models\";\n this.log.debug({ url }, \"Fetching models from Vercel AI Gateway\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"Vercel AI Gateway returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const bodyRaw: unknown = await response.json();\n const body = modelsEnvelopeSchema.parse(bodyRaw);\n const unsupportedTypes = new Set<string>();\n const models: AiGatewayModel[] = [];\n\n for (const candidate of body.data) {\n const { type } = modelDiscriminatorSchema.parse(candidate);\n if (isAiGatewayModelType(type)) {\n models.push(aiGatewayModelSchema.parse(candidate));\n } else {\n unsupportedTypes.add(type);\n }\n }\n\n if (unsupportedTypes.size > EMPTY_MODEL_TYPE_COUNT) {\n this.log.warn(\n {\n modelCount: body.data.length,\n skippedModelCount: body.data.length - models.length,\n unsupportedTypes: [...unsupportedTypes],\n },\n \"Skipping models with unsupported types from Vercel AI Gateway\"\n );\n }\n\n this.log.info(\n { modelCount: models.length },\n \"Successfully fetched models from Vercel AI Gateway\"\n );\n return models;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from Vercel AI Gateway, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { VercelGateway as Gateway, VercelGateway };\n",
13
13
  "type": "registry:file",
14
14
  "target": "~/chatjs/providers/gateway.ts"
15
15
  }
@@ -1898,8 +1898,8 @@
1898
1898
  "name": "vercel-gateway",
1899
1899
  "title": "Vercel AI Gateway",
1900
1900
  "dependencies": [
1901
- "@chat-js/gateways@0.2.2",
1902
- "@ai-sdk/gateway@4.0.145"
1901
+ "@ai-sdk/gateway@4.0.145",
1902
+ "zod@4.5.4"
1903
1903
  ],
1904
1904
  "files": [
1905
1905
  {
@@ -1970,7 +1970,6 @@
1970
1970
  "name": "openai-gateway",
1971
1971
  "title": "OpenAI",
1972
1972
  "dependencies": [
1973
- "@chat-js/gateways@0.2.2",
1974
1973
  "@ai-sdk/openai@4.0.117",
1975
1974
  "zod@4.5.4"
1976
1975
  ],
@@ -2033,7 +2032,6 @@
2033
2032
  "name": "openai-compatible-gateway",
2034
2033
  "title": "OpenAI Compatible",
2035
2034
  "dependencies": [
2036
- "@chat-js/gateways@0.2.2",
2037
2035
  "@ai-sdk/openai-compatible@3.0.92",
2038
2036
  "zod@4.5.4"
2039
2037
  ],
@@ -2098,7 +2096,6 @@
2098
2096
  "name": "openrouter-gateway",
2099
2097
  "title": "OpenRouter",
2100
2098
  "dependencies": [
2101
- "@chat-js/gateways@0.2.2",
2102
2099
  "@openrouter/ai-sdk-provider@3.0.0",
2103
2100
  "zod@4.5.4"
2104
2101
  ],
@@ -2168,7 +2165,6 @@
2168
2165
  "name": "litellm-gateway",
2169
2166
  "title": "LiteLLM",
2170
2167
  "dependencies": [
2171
- "@chat-js/gateways@0.2.2",
2172
2168
  "@ai-sdk/openai-compatible@3.0.92"
2173
2169
  ],
2174
2170
  "files": [
@@ -3,13 +3,13 @@
3
3
  "name": "vercel-gateway",
4
4
  "title": "Vercel AI Gateway",
5
5
  "dependencies": [
6
- "@chat-js/gateways@0.2.2",
7
- "@ai-sdk/gateway@4.0.145"
6
+ "@ai-sdk/gateway@4.0.145",
7
+ "zod@4.5.4"
8
8
  ],
9
9
  "files": [
10
10
  {
11
11
  "path": "src/gateways/vercel/gateway.ts",
12
- "content": "import type {\n Experimental_VideoModelV4,\n LanguageModelV4,\n} from \"@ai-sdk/provider\";\nimport {\n aiGatewayModelDiscriminatorSchema,\n aiGatewayModelSchema,\n aiGatewayModelsEnvelopeSchema,\n isAiGatewayModelType,\n} from \"@chat-js/gateways/models\";\nimport type { AiGatewayModel } from \"@chat-js/gateways/models\";\nimport type { GatewayProvider } from \"@chat-js/gateways/gateway-provider\";\nimport { GatewayRuntime } from \"@chat-js/gateways/runtime\";\nimport type { ImageModel } from \"ai\";\n\nimport { createGateway } from \"@ai-sdk/gateway\";\nimport type { gateway } from \"@ai-sdk/gateway\";\n\nconst MODEL_ID_PARAMETER_INDEX = 0;\ntype VercelImageModelId = Parameters<\n (typeof gateway)[\"imageModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\ntype VercelVideoModelId = Parameters<\n (typeof gateway)[\"videoModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\n\nconst EMPTY_MODEL_TYPE_COUNT = 0;\n\nclass VercelGateway\n extends GatewayRuntime\n implements GatewayProvider<\"vercel\">\n{\n public readonly type = \"vercel\" as const;\n\n public createLanguageModel(\n modelId: Parameters<\n (typeof gateway)[\"languageModel\"]\n >[typeof MODEL_ID_PARAMETER_INDEX]\n ): LanguageModelV4 {\n return this.getProvider()(modelId);\n }\n\n public createImageModel(modelId: VercelImageModelId): ImageModel {\n return this.getProvider().imageModel(modelId);\n }\n\n public createVideoModel(\n modelId: VercelVideoModelId\n ): Experimental_VideoModelV4 {\n return this.getProvider().videoModel(modelId);\n }\n\n private provider?: ReturnType<typeof createGateway>;\n\n private getProvider(): ReturnType<typeof createGateway> {\n this.provider ??= createGateway({ apiKey: this.env.AI_GATEWAY_API_KEY });\n return this.provider;\n }\n\n private getApiKey(): string | undefined {\n const apiKey = this.env.AI_GATEWAY_API_KEY;\n\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n return apiKey;\n }\n return this.env.VERCEL_OIDC_TOKEN;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No AI gateway API key found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://ai-gateway.vercel.sh/v1/models\";\n this.log.debug({ url }, \"Fetching models from Vercel AI Gateway\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"Vercel AI Gateway returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const bodyRaw: unknown = await response.json();\n const body = aiGatewayModelsEnvelopeSchema.parse(bodyRaw);\n const unsupportedTypes = new Set<string>();\n const models: AiGatewayModel[] = [];\n\n for (const candidate of body.data) {\n const { type } = aiGatewayModelDiscriminatorSchema.parse(candidate);\n if (isAiGatewayModelType(type)) {\n const model = aiGatewayModelSchema.parse(candidate);\n models.push({ ...model, type });\n } else {\n unsupportedTypes.add(type);\n }\n }\n\n if (unsupportedTypes.size > EMPTY_MODEL_TYPE_COUNT) {\n this.log.warn(\n {\n modelCount: body.data.length,\n skippedModelCount: body.data.length - models.length,\n unsupportedTypes: [...unsupportedTypes],\n },\n \"Skipping models with unsupported types from Vercel AI Gateway\"\n );\n }\n\n this.log.info(\n { modelCount: models.length },\n \"Successfully fetched models from Vercel AI Gateway\"\n );\n return models;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from Vercel AI Gateway, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { VercelGateway as Gateway, VercelGateway };\n",
12
+ "content": "import type {\n Experimental_VideoModelV4,\n LanguageModelV4,\n} from \"@ai-sdk/provider\";\nimport {\n aiGatewayModelSchema,\n isAiGatewayModelType,\n} from \"@/chatjs/core/gateway/models\";\nimport type { AiGatewayModel } from \"@/chatjs/core/gateway/models\";\nimport type { GatewayProvider } from \"@/chatjs/core/gateway/gateway-provider\";\nimport { GatewayRuntime } from \"@/chatjs/core/gateway/runtime\";\nimport type { ImageModel } from \"ai\";\n\nimport { createGateway } from \"@ai-sdk/gateway\";\nimport type { gateway } from \"@ai-sdk/gateway\";\nimport { z } from \"zod\";\n\nconst MODEL_ID_PARAMETER_INDEX = 0;\ntype VercelImageModelId = Parameters<\n (typeof gateway)[\"imageModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\ntype VercelVideoModelId = Parameters<\n (typeof gateway)[\"videoModel\"]\n>[typeof MODEL_ID_PARAMETER_INDEX];\n\nconst EMPTY_MODEL_TYPE_COUNT = 0;\nconst modelDiscriminatorSchema = z.object({ type: z.string() });\nconst modelsEnvelopeSchema = z.object({\n data: z.array(z.unknown()),\n object: z.literal(\"list\"),\n});\n\nclass VercelGateway\n extends GatewayRuntime\n implements GatewayProvider<\"vercel\">\n{\n public readonly type = \"vercel\" as const;\n\n public createLanguageModel(\n modelId: Parameters<\n (typeof gateway)[\"languageModel\"]\n >[typeof MODEL_ID_PARAMETER_INDEX]\n ): LanguageModelV4 {\n return this.getProvider()(modelId);\n }\n\n public createImageModel(modelId: VercelImageModelId): ImageModel {\n return this.getProvider().imageModel(modelId);\n }\n\n public createVideoModel(\n modelId: VercelVideoModelId\n ): Experimental_VideoModelV4 {\n return this.getProvider().videoModel(modelId);\n }\n\n private provider?: ReturnType<typeof createGateway>;\n\n private getProvider(): ReturnType<typeof createGateway> {\n this.provider ??= createGateway({ apiKey: this.env.AI_GATEWAY_API_KEY });\n return this.provider;\n }\n\n private getApiKey(): string | undefined {\n const apiKey = this.env.AI_GATEWAY_API_KEY;\n\n if (typeof apiKey === \"string\" && apiKey !== \"\") {\n return apiKey;\n }\n return this.env.VERCEL_OIDC_TOKEN;\n }\n\n public async fetchModels(): Promise<AiGatewayModel[]> {\n const apiKey = this.getApiKey();\n\n if (!(typeof apiKey === \"string\" && apiKey !== \"\")) {\n this.log.warn(\"No AI gateway API key found, using fallback models\");\n return [...this.getFallbackModels(this.type)];\n }\n\n const url = \"https://ai-gateway.vercel.sh/v1/models\";\n this.log.debug({ url }, \"Fetching models from Vercel AI Gateway\");\n\n try {\n const response = await this.fetch(url, {\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n this.log.error(\n { status: response.status, statusText: response.statusText, url },\n \"Vercel AI Gateway returned non-OK response\"\n );\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const bodyRaw: unknown = await response.json();\n const body = modelsEnvelopeSchema.parse(bodyRaw);\n const unsupportedTypes = new Set<string>();\n const models: AiGatewayModel[] = [];\n\n for (const candidate of body.data) {\n const { type } = modelDiscriminatorSchema.parse(candidate);\n if (isAiGatewayModelType(type)) {\n models.push(aiGatewayModelSchema.parse(candidate));\n } else {\n unsupportedTypes.add(type);\n }\n }\n\n if (unsupportedTypes.size > EMPTY_MODEL_TYPE_COUNT) {\n this.log.warn(\n {\n modelCount: body.data.length,\n skippedModelCount: body.data.length - models.length,\n unsupportedTypes: [...unsupportedTypes],\n },\n \"Skipping models with unsupported types from Vercel AI Gateway\"\n );\n }\n\n this.log.info(\n { modelCount: models.length },\n \"Successfully fetched models from Vercel AI Gateway\"\n );\n return models;\n } catch (error) {\n this.log.error(\n { err: error, url },\n \"Error fetching models from Vercel AI Gateway, falling back to generated models\"\n );\n return [...this.getFallbackModels(this.type)];\n }\n }\n}\nexport { VercelGateway as Gateway, VercelGateway };\n",
13
13
  "type": "registry:file",
14
14
  "target": "~/chatjs/providers/gateway.ts"
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chat-js/registry",
3
- "version": "0.2.0-beta.6",
3
+ "version": "0.2.0-beta.7",
4
4
  "private": false,
5
5
  "description": "ChatJS tool and gateway registry items",
6
6
  "keywords": [
@@ -36,7 +36,7 @@
36
36
  "test:types": "tsc --noEmit && tsc --noEmit -p scripts/tsconfig.json",
37
37
  "test:unit": "bun test src",
38
38
  "test:native": "bun run build && bun test --timeout 180000 test/native-eve.test.ts",
39
- "test:installation": "bunx turbo run build --filter=@chat-js/gateways --filter=@chat-js/thread && bun run --cwd ../cli template:sync && bun test --timeout 60000 test/installation-validation.test.ts",
39
+ "test:installation": "bunx turbo run build --filter=@chat-js/thread && bun run --cwd ../cli template:sync && bun test --timeout 60000 test/installation-validation.test.ts",
40
40
  "profile:validation": "bun scripts/validation-profile.ts",
41
41
  "test:visual": "vitest run --config visual/vitest.config.ts",
42
42
  "check": "bun run test:types && bun run test:unit && bun run test:visual",
@@ -54,7 +54,6 @@
54
54
  "@ai-sdk/openai-compatible": "3.0.92",
55
55
  "@ai-sdk/provider": "4.0.38",
56
56
  "@better-auth/electron": "1.6.2",
57
- "@chat-js/gateways": "workspace:*",
58
57
  "@chat-js/registry-validation": "workspace:*",
59
58
  "@hookform/resolvers": "^5.2.1",
60
59
  "@lexical/react": "^0.32.1",