@tansy/ai-gateway 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mohamed Salah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ <!-- Generated by scripts/package-metadata.mjs. Change that script, not this file. -->
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # @tansy/ai-gateway
4
+
5
+ Vercel AI Gateway for @tansy/ai.
6
+
7
+ ```bash
8
+ npm install @tansy/ai-gateway
9
+ ```
10
+
11
+ Add it to `tansy.config.ts`. See [the ai plugin documentation](https://github.com/mhmdsalahsebai/tansy/blob/main/docs/plugins/ai.md) for what it adds and the options it takes.
12
+
13
+ A first-party plugin for [tansy](https://github.com/mhmdsalahsebai/tansy), a self-hosted, runtime-schema CMS for Next.js. MIT licensed.
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /** Vercel AI Gateway, through the AI SDK's @ai-sdk/gateway. */
2
+ export declare const gateway: (options?: {
3
+ defaultModel?: string;
4
+ }) => import("@tansy/ai/provider").AiProvider;
package/index.js ADDED
@@ -0,0 +1,44 @@
1
+ import { createGateway } from "@ai-sdk/gateway";
2
+ import { defineAiProvider, fetchModelsJson, guessCapabilities, str } from "@tansy/ai/provider";
3
+ /** Vercel AI Gateway, through the AI SDK's @ai-sdk/gateway. */
4
+ export const gateway = (options = {}) => defineAiProvider({
5
+ id: "gateway",
6
+ label: "Vercel AI Gateway",
7
+ defaultModel: options.defaultModel ?? "anthropic/claude-sonnet-5.5",
8
+ // Its settings in other interface languages. English is each setting's own label and description.
9
+ messages: {
10
+ ar: {
11
+ settings: {
12
+ gatewayApiKey: {
13
+ label: "مفتاح API لـ Vercel AI Gateway",
14
+ description: "نماذج من كل مزوّد كبير بمفتاح واحد، بصيغة provider/model، مثل openai/gpt-6-astra. من vercel.com ← AI Gateway ← API keys."
15
+ }
16
+ }
17
+ }
18
+ },
19
+ settings: () => [
20
+ { name: "gatewayApiKey", type: "secret", env: "AI_GATEWAY_API_KEY", label: "Vercel AI Gateway API key", description: "Models from every major provider with one key, as provider/model, such as openai/gpt-6-astra. From vercel.com → AI Gateway → API keys." },
21
+ ],
22
+ ready: (settings) => Boolean(str(settings.gatewayApiKey)),
23
+ model: (settings, modelId) => createGateway({ apiKey: str(settings.gatewayApiKey) })(modelId),
24
+ imageModel: (settings, modelId) => (guessCapabilities(modelId).output?.includes("image") && !/gemini/.test(modelId) ? createGateway({ apiKey: str(settings.gatewayApiKey) }).imageModel(modelId) : undefined),
25
+ // The gateway says each model's kind and tags: tool-use, reasoning, vision, image-generation.
26
+ models: async (settings) => {
27
+ const json = await fetchModelsJson("https://ai-gateway.vercel.sh/v1/models", { headers: { authorization: `Bearer ${str(settings.gatewayApiKey)}` } });
28
+ return (Array.isArray(json.data) ? json.data : [])
29
+ .filter((model) => typeof model.id === "string" && (model.type === "language" || model.type === "image" || model.type === undefined))
30
+ .map((model) => {
31
+ const tags = Array.isArray(model.tags) ? model.tags : [];
32
+ const image = model.type === "image";
33
+ const input = ["text", ...(tags.includes("vision") ? ["image"] : []), ...(tags.includes("file-input") ? ["file"] : [])];
34
+ return {
35
+ value: model.id,
36
+ label: typeof model.name === "string" ? model.name : undefined,
37
+ capabilities: image
38
+ ? { input: ["text"], output: ["image"], reported: true }
39
+ : { input, output: tags.includes("image-generation") ? ["text", "image"] : ["text"], tools: tags.includes("tool-use"), reasoning: tags.includes("reasoning"), structured: tags.includes("tool-use"), reported: true },
40
+ };
41
+ })
42
+ .sort((a, b) => a.value.localeCompare(b.value));
43
+ },
44
+ });
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@tansy/ai-gateway",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Vercel AI Gateway for @tansy/ai.",
5
+ "keywords": [
6
+ "tansy",
7
+ "tansy-ai-provider"
8
+ ],
9
+ "license": "MIT",
10
+ "author": "Mohamed Salah <mohamedsalahsebai@gmail.com>",
11
+ "homepage": "https://github.com/mhmdsalahsebai/tansy",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/mhmdsalahsebai/tansy.git",
15
+ "directory": "plugins/ai-gateway"
16
+ },
17
+ "bugs": "https://github.com/mhmdsalahsebai/tansy/issues",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./index.d.ts",
21
+ "default": "./index.js"
22
+ }
23
+ },
24
+ "peerDependencies": {
25
+ "@tansy/ai": "^0.1.0",
26
+ "tansy": "^0.1.0"
27
+ },
28
+ "dependencies": {
29
+ "@ai-sdk/gateway": "^4.0.146"
30
+ }
31
+ }