@tansy/ai-commandcode 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 +21 -0
- package/README.md +12 -2
- package/index.d.ts +9 -0
- package/index.js +54 -0
- package/package.json +30 -4
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
|
-
|
|
1
|
+
<!-- Generated by scripts/package-metadata.mjs. Change that script, not this file. -->
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @tansy/ai-commandcode
|
|
4
|
+
|
|
5
|
+
Command Code for @tansy/ai: Claude, GPT, Gemini and open models with one Command Code key.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tansy/ai-commandcode
|
|
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,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Code's provider API (commandcode.ai/docs/provider), with one key. Claude is asked
|
|
3
|
+
* only through Anthropic's Messages, as Command Code serves it nowhere else; GPT, Gemini,
|
|
4
|
+
* Grok and the open models (DeepSeek, Kimi, GLM, Qwen, MiniMax…) through OpenAI's chat API,
|
|
5
|
+
* which every one of them answers on.
|
|
6
|
+
*/
|
|
7
|
+
export declare const commandcode: (options?: {
|
|
8
|
+
defaultModel?: string;
|
|
9
|
+
}) => import("@tansy/ai/provider").AiProvider;
|
package/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
2
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
3
|
+
import { defineAiProvider, openAiModels, str } from "@tansy/ai/provider";
|
|
4
|
+
const BASE_URL = "https://api.commandcode.ai/provider/v1";
|
|
5
|
+
/** The routes Command Code serves a model on, from its model list. */
|
|
6
|
+
const endpointsOf = (model) => Array.isArray(model.supported_endpoints) ? model.supported_endpoints.filter((item) => typeof item === "string") : null;
|
|
7
|
+
/**
|
|
8
|
+
* Command Code's provider API (commandcode.ai/docs/provider), with one key. Claude is asked
|
|
9
|
+
* only through Anthropic's Messages, as Command Code serves it nowhere else; GPT, Gemini,
|
|
10
|
+
* Grok and the open models (DeepSeek, Kimi, GLM, Qwen, MiniMax…) through OpenAI's chat API,
|
|
11
|
+
* which every one of them answers on.
|
|
12
|
+
*/
|
|
13
|
+
export const commandcode = (options = {}) => defineAiProvider({
|
|
14
|
+
id: "commandcode",
|
|
15
|
+
label: "Command Code",
|
|
16
|
+
icon: "commandcode",
|
|
17
|
+
defaultModel: options.defaultModel ?? "claude-haiku-5-5",
|
|
18
|
+
// Its settings in other interface languages. English is each setting's own label and description.
|
|
19
|
+
messages: {
|
|
20
|
+
ar: {
|
|
21
|
+
settings: {
|
|
22
|
+
commandcodeApiKey: {
|
|
23
|
+
label: "مفتاح API لـ Command Code",
|
|
24
|
+
description: "من commandcode.ai/settings/keys. تحتاج خطة غير Go."
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
settings: () => [
|
|
30
|
+
{ name: "commandcodeApiKey", type: "secret", env: "COMMANDCODE_API_KEY", label: "Command Code API key", description: "From commandcode.ai/settings/keys. Any plan but Go." },
|
|
31
|
+
],
|
|
32
|
+
ready: (settings) => Boolean(str(settings.commandcodeApiKey)),
|
|
33
|
+
model: (settings, modelId) => {
|
|
34
|
+
const apiKey = str(settings.commandcodeApiKey);
|
|
35
|
+
if (/^claude-/.test(modelId))
|
|
36
|
+
return createAnthropic({ baseURL: BASE_URL, apiKey })(modelId);
|
|
37
|
+
return createOpenAICompatible({ name: "commandcode", baseURL: BASE_URL, apiKey, includeUsage: true })(modelId);
|
|
38
|
+
},
|
|
39
|
+
// Its list names each model and the routes it's served on, but not what it reads or calls,
|
|
40
|
+
// so that comes from its name. Models served only elsewhere, such as the decision models on
|
|
41
|
+
// /systemone, can't chat and are left out.
|
|
42
|
+
models: async (settings) => {
|
|
43
|
+
const skipped = new Set();
|
|
44
|
+
const models = await openAiModels(BASE_URL, str(settings.commandcodeApiKey) || undefined, {
|
|
45
|
+
label: (model) => {
|
|
46
|
+
const endpoints = endpointsOf(model);
|
|
47
|
+
if (endpoints && !endpoints.includes("/messages") && !endpoints.includes("/chat/completions"))
|
|
48
|
+
skipped.add(model.id);
|
|
49
|
+
return typeof model.name === "string" ? model.name : undefined;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
return models.filter((model) => !skipped.has(model.value));
|
|
53
|
+
},
|
|
54
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tansy/ai-commandcode",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Command Code for @tansy/ai: Claude, GPT, Gemini and open models with one Command Code key.",
|
|
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-commandcode"
|
|
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/anthropic": "^4.0.105",
|
|
30
|
+
"@ai-sdk/openai-compatible": "^3.0.92"
|
|
31
|
+
}
|
|
32
|
+
}
|