@clinebot/llms 0.0.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/README.md +198 -0
- package/dist/config-browser.d.ts +3 -0
- package/dist/config.d.ts +3 -0
- package/dist/index.browser.d.ts +4 -0
- package/dist/index.browser.js +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/models/generated-access.d.ts +4 -0
- package/dist/models/generated-provider-loaders.d.ts +13 -0
- package/dist/models/generated.d.ts +14 -0
- package/dist/models/index.d.ts +43 -0
- package/dist/models/models-dev-catalog.d.ts +32 -0
- package/dist/models/providers/aihubmix.d.ts +5 -0
- package/dist/models/providers/anthropic.d.ts +53 -0
- package/dist/models/providers/asksage.d.ts +5 -0
- package/dist/models/providers/baseten.d.ts +5 -0
- package/dist/models/providers/bedrock.d.ts +7 -0
- package/dist/models/providers/cerebras.d.ts +7 -0
- package/dist/models/providers/claude-code.d.ts +4 -0
- package/dist/models/providers/cline.d.ts +34 -0
- package/dist/models/providers/deepseek.d.ts +8 -0
- package/dist/models/providers/dify.d.ts +5 -0
- package/dist/models/providers/doubao.d.ts +7 -0
- package/dist/models/providers/fireworks.d.ts +8 -0
- package/dist/models/providers/gemini.d.ts +9 -0
- package/dist/models/providers/groq.d.ts +8 -0
- package/dist/models/providers/hicap.d.ts +5 -0
- package/dist/models/providers/huawei-cloud-maas.d.ts +5 -0
- package/dist/models/providers/huggingface.d.ts +6 -0
- package/dist/models/providers/index.d.ts +45 -0
- package/dist/models/providers/litellm.d.ts +5 -0
- package/dist/models/providers/lmstudio.d.ts +5 -0
- package/dist/models/providers/minimax.d.ts +7 -0
- package/dist/models/providers/mistral.d.ts +5 -0
- package/dist/models/providers/moonshot.d.ts +7 -0
- package/dist/models/providers/nebius.d.ts +7 -0
- package/dist/models/providers/nous-research.d.ts +7 -0
- package/dist/models/providers/oca.d.ts +9 -0
- package/dist/models/providers/ollama.d.ts +5 -0
- package/dist/models/providers/openai-codex.d.ts +10 -0
- package/dist/models/providers/openai.d.ts +9 -0
- package/dist/models/providers/opencode.d.ts +10 -0
- package/dist/models/providers/openrouter.d.ts +7 -0
- package/dist/models/providers/qwen-code.d.ts +7 -0
- package/dist/models/providers/qwen.d.ts +7 -0
- package/dist/models/providers/requesty.d.ts +6 -0
- package/dist/models/providers/sambanova.d.ts +7 -0
- package/dist/models/providers/sapaicore.d.ts +7 -0
- package/dist/models/providers/together.d.ts +8 -0
- package/dist/models/providers/vercel-ai-gateway.d.ts +5 -0
- package/dist/models/providers/vertex.d.ts +7 -0
- package/dist/models/providers/xai.d.ts +8 -0
- package/dist/models/providers/zai.d.ts +7 -0
- package/dist/models/query.d.ts +181 -0
- package/dist/models/registry.d.ts +123 -0
- package/dist/models/schemas/index.d.ts +7 -0
- package/dist/models/schemas/model.d.ts +340 -0
- package/dist/models/schemas/query.d.ts +191 -0
- package/dist/providers/handlers/ai-sdk-community.d.ts +46 -0
- package/dist/providers/handlers/ai-sdk-provider-base.d.ts +32 -0
- package/dist/providers/handlers/anthropic-base.d.ts +26 -0
- package/dist/providers/handlers/asksage.d.ts +12 -0
- package/dist/providers/handlers/auth.d.ts +5 -0
- package/dist/providers/handlers/base.d.ts +55 -0
- package/dist/providers/handlers/bedrock-base.d.ts +23 -0
- package/dist/providers/handlers/bedrock-client.d.ts +4 -0
- package/dist/providers/handlers/community-sdk.d.ts +97 -0
- package/dist/providers/handlers/fetch-base.d.ts +18 -0
- package/dist/providers/handlers/gemini-base.d.ts +25 -0
- package/dist/providers/handlers/index.d.ts +19 -0
- package/dist/providers/handlers/openai-base.d.ts +54 -0
- package/dist/providers/handlers/openai-responses.d.ts +64 -0
- package/dist/providers/handlers/providers.d.ts +43 -0
- package/dist/providers/handlers/r1-base.d.ts +62 -0
- package/dist/providers/handlers/registry.d.ts +106 -0
- package/dist/providers/handlers/vertex.d.ts +32 -0
- package/dist/providers/index.d.ts +100 -0
- package/dist/providers/public.browser.d.ts +2 -0
- package/dist/providers/public.d.ts +3 -0
- package/dist/providers/shared/openai-compatible.d.ts +10 -0
- package/dist/providers/transform/ai-sdk-community-format.d.ts +9 -0
- package/dist/providers/transform/anthropic-format.d.ts +24 -0
- package/dist/providers/transform/content-format.d.ts +3 -0
- package/dist/providers/transform/gemini-format.d.ts +19 -0
- package/dist/providers/transform/index.d.ts +10 -0
- package/dist/providers/transform/openai-format.d.ts +36 -0
- package/dist/providers/transform/r1-format.d.ts +26 -0
- package/dist/providers/types/config.d.ts +261 -0
- package/dist/providers/types/handler.d.ts +71 -0
- package/dist/providers/types/index.d.ts +11 -0
- package/dist/providers/types/messages.d.ts +139 -0
- package/dist/providers/types/model-info.d.ts +32 -0
- package/dist/providers/types/provider-ids.d.ts +63 -0
- package/dist/providers/types/settings.d.ts +308 -0
- package/dist/providers/types/stream.d.ts +106 -0
- package/dist/providers/utils/index.d.ts +7 -0
- package/dist/providers/utils/retry.d.ts +38 -0
- package/dist/providers/utils/stream-processor.d.ts +110 -0
- package/dist/providers/utils/tool-processor.d.ts +34 -0
- package/dist/sdk.d.ts +18 -0
- package/dist/types.d.ts +60 -0
- package/package.json +66 -0
- package/src/catalog.ts +20 -0
- package/src/config-browser.ts +11 -0
- package/src/config.ts +49 -0
- package/src/index.browser.ts +9 -0
- package/src/index.ts +10 -0
- package/src/live-providers.test.ts +137 -0
- package/src/models/generated-access.ts +41 -0
- package/src/models/generated-provider-loaders.ts +166 -0
- package/src/models/generated.ts +11997 -0
- package/src/models/index.ts +271 -0
- package/src/models/models-dev-catalog.test.ts +161 -0
- package/src/models/models-dev-catalog.ts +161 -0
- package/src/models/providers/aihubmix.ts +19 -0
- package/src/models/providers/anthropic.ts +60 -0
- package/src/models/providers/asksage.ts +19 -0
- package/src/models/providers/baseten.ts +21 -0
- package/src/models/providers/bedrock.ts +30 -0
- package/src/models/providers/cerebras.ts +24 -0
- package/src/models/providers/claude-code.ts +51 -0
- package/src/models/providers/cline.ts +25 -0
- package/src/models/providers/deepseek.ts +33 -0
- package/src/models/providers/dify.ts +17 -0
- package/src/models/providers/doubao.ts +33 -0
- package/src/models/providers/fireworks.ts +34 -0
- package/src/models/providers/gemini.ts +43 -0
- package/src/models/providers/groq.ts +33 -0
- package/src/models/providers/hicap.ts +18 -0
- package/src/models/providers/huawei-cloud-maas.ts +18 -0
- package/src/models/providers/huggingface.ts +22 -0
- package/src/models/providers/index.ts +162 -0
- package/src/models/providers/litellm.ts +19 -0
- package/src/models/providers/lmstudio.ts +22 -0
- package/src/models/providers/minimax.ts +34 -0
- package/src/models/providers/mistral.ts +19 -0
- package/src/models/providers/moonshot.ts +34 -0
- package/src/models/providers/nebius.ts +24 -0
- package/src/models/providers/nous-research.ts +21 -0
- package/src/models/providers/oca.ts +30 -0
- package/src/models/providers/ollama.ts +18 -0
- package/src/models/providers/openai-codex.ts +30 -0
- package/src/models/providers/openai.ts +43 -0
- package/src/models/providers/opencode.ts +28 -0
- package/src/models/providers/openrouter.ts +24 -0
- package/src/models/providers/qwen-code.ts +33 -0
- package/src/models/providers/qwen.ts +34 -0
- package/src/models/providers/requesty.ts +23 -0
- package/src/models/providers/sambanova.ts +23 -0
- package/src/models/providers/sapaicore.ts +34 -0
- package/src/models/providers/together.ts +35 -0
- package/src/models/providers/vercel-ai-gateway.ts +23 -0
- package/src/models/providers/vertex.ts +36 -0
- package/src/models/providers/xai.ts +34 -0
- package/src/models/providers/zai.ts +25 -0
- package/src/models/query.ts +407 -0
- package/src/models/registry.ts +511 -0
- package/src/models/schemas/index.ts +62 -0
- package/src/models/schemas/model.ts +308 -0
- package/src/models/schemas/query.ts +336 -0
- package/src/providers/browser.ts +4 -0
- package/src/providers/handlers/ai-sdk-community.ts +226 -0
- package/src/providers/handlers/ai-sdk-provider-base.ts +193 -0
- package/src/providers/handlers/anthropic-base.ts +372 -0
- package/src/providers/handlers/asksage.test.ts +103 -0
- package/src/providers/handlers/asksage.ts +138 -0
- package/src/providers/handlers/auth.test.ts +19 -0
- package/src/providers/handlers/auth.ts +121 -0
- package/src/providers/handlers/base.test.ts +46 -0
- package/src/providers/handlers/base.ts +160 -0
- package/src/providers/handlers/bedrock-base.ts +390 -0
- package/src/providers/handlers/bedrock-client.ts +100 -0
- package/src/providers/handlers/codex.test.ts +123 -0
- package/src/providers/handlers/community-sdk.test.ts +288 -0
- package/src/providers/handlers/community-sdk.ts +392 -0
- package/src/providers/handlers/fetch-base.ts +68 -0
- package/src/providers/handlers/gemini-base.ts +302 -0
- package/src/providers/handlers/index.ts +67 -0
- package/src/providers/handlers/openai-base.ts +277 -0
- package/src/providers/handlers/openai-responses.ts +598 -0
- package/src/providers/handlers/providers.test.ts +120 -0
- package/src/providers/handlers/providers.ts +563 -0
- package/src/providers/handlers/r1-base.ts +280 -0
- package/src/providers/handlers/registry.ts +185 -0
- package/src/providers/handlers/vertex.test.ts +124 -0
- package/src/providers/handlers/vertex.ts +292 -0
- package/src/providers/index.ts +534 -0
- package/src/providers/public.browser.ts +20 -0
- package/src/providers/public.ts +51 -0
- package/src/providers/shared/openai-compatible.ts +63 -0
- package/src/providers/transform/ai-sdk-community-format.test.ts +73 -0
- package/src/providers/transform/ai-sdk-community-format.ts +115 -0
- package/src/providers/transform/anthropic-format.ts +218 -0
- package/src/providers/transform/content-format.ts +34 -0
- package/src/providers/transform/format-conversion.test.ts +310 -0
- package/src/providers/transform/gemini-format.ts +167 -0
- package/src/providers/transform/index.ts +22 -0
- package/src/providers/transform/openai-format.ts +247 -0
- package/src/providers/transform/r1-format.ts +287 -0
- package/src/providers/types/config.ts +388 -0
- package/src/providers/types/handler.ts +87 -0
- package/src/providers/types/index.ts +120 -0
- package/src/providers/types/messages.ts +158 -0
- package/src/providers/types/model-info.test.ts +57 -0
- package/src/providers/types/model-info.ts +65 -0
- package/src/providers/types/provider-ids.test.ts +12 -0
- package/src/providers/types/provider-ids.ts +89 -0
- package/src/providers/types/settings.test.ts +49 -0
- package/src/providers/types/settings.ts +533 -0
- package/src/providers/types/stream.ts +117 -0
- package/src/providers/utils/index.ts +27 -0
- package/src/providers/utils/retry.test.ts +140 -0
- package/src/providers/utils/retry.ts +188 -0
- package/src/providers/utils/stream-processor.test.ts +232 -0
- package/src/providers/utils/stream-processor.ts +472 -0
- package/src/providers/utils/tool-processor.test.ts +34 -0
- package/src/providers/utils/tool-processor.ts +111 -0
- package/src/sdk.ts +264 -0
- package/src/types.ts +79 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message Types
|
|
3
|
+
*
|
|
4
|
+
* Standardized message format for input to providers.
|
|
5
|
+
* This is a simplified, provider-agnostic format that can be
|
|
6
|
+
* converted to any provider's native format.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Message roles
|
|
11
|
+
*/
|
|
12
|
+
export type MessageRole = "user" | "assistant";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Text content block
|
|
16
|
+
*/
|
|
17
|
+
export interface TextContent {
|
|
18
|
+
type: "text";
|
|
19
|
+
text: string;
|
|
20
|
+
/** Thought signature for this text part (Gemini) */
|
|
21
|
+
signature?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* File content block for Cline
|
|
26
|
+
*/
|
|
27
|
+
export interface FileContent {
|
|
28
|
+
type: "file";
|
|
29
|
+
content: string;
|
|
30
|
+
/** Absolute Path */
|
|
31
|
+
path: string;
|
|
32
|
+
source?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Image content block
|
|
37
|
+
*/
|
|
38
|
+
export interface ImageContent {
|
|
39
|
+
type: "image";
|
|
40
|
+
/** Base64 encoded image data */
|
|
41
|
+
data: string;
|
|
42
|
+
/** MIME type (e.g., "image/png", "image/jpeg") */
|
|
43
|
+
mediaType: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Tool use content block (assistant's tool call)
|
|
48
|
+
*/
|
|
49
|
+
export interface ToolUseContent {
|
|
50
|
+
type: "tool_use";
|
|
51
|
+
/** Unique ID for this tool call */
|
|
52
|
+
id: string;
|
|
53
|
+
/** Name of the tool being called */
|
|
54
|
+
name: string;
|
|
55
|
+
/** Arguments for the tool call */
|
|
56
|
+
input: Record<string, unknown>;
|
|
57
|
+
/** Thought signature for this function call part (Gemini) */
|
|
58
|
+
signature?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Tool result content block (user's response to tool call)
|
|
63
|
+
*/
|
|
64
|
+
export interface ToolResultContent {
|
|
65
|
+
type: "tool_result";
|
|
66
|
+
/** ID of the tool call this is responding to */
|
|
67
|
+
tool_use_id: string;
|
|
68
|
+
/** Result content (can be text or error) */
|
|
69
|
+
content: string | Array<TextContent | ImageContent | FileContent>;
|
|
70
|
+
/** Whether this result represents an error */
|
|
71
|
+
is_error?: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Thinking/reasoning content block
|
|
76
|
+
*/
|
|
77
|
+
export interface ThinkingContent {
|
|
78
|
+
type: "thinking";
|
|
79
|
+
/** The thinking/reasoning text */
|
|
80
|
+
thinking: string;
|
|
81
|
+
/** Signature for the thinking block (provider-specific) */
|
|
82
|
+
signature?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Redacted thinking content block
|
|
87
|
+
*/
|
|
88
|
+
export interface RedactedThinkingContent {
|
|
89
|
+
type: "redacted_thinking";
|
|
90
|
+
/** Encrypted/redacted data */
|
|
91
|
+
data: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Union of all content block types
|
|
96
|
+
*/
|
|
97
|
+
export type ContentBlock =
|
|
98
|
+
| TextContent
|
|
99
|
+
| ImageContent
|
|
100
|
+
| ToolUseContent
|
|
101
|
+
| ToolResultContent
|
|
102
|
+
| ThinkingContent
|
|
103
|
+
| FileContent
|
|
104
|
+
| RedactedThinkingContent;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A single message in the conversation
|
|
108
|
+
*/
|
|
109
|
+
export interface Message {
|
|
110
|
+
/** Message role */
|
|
111
|
+
role: MessageRole;
|
|
112
|
+
/** Message content - can be a simple string or array of content blocks */
|
|
113
|
+
content: string | ContentBlock[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Extended message with metadata (used for storage/history)
|
|
118
|
+
*/
|
|
119
|
+
export interface MessageWithMetadata extends Message {
|
|
120
|
+
/** Unique message ID */
|
|
121
|
+
id?: string;
|
|
122
|
+
/** Provider ID used to generate this message */
|
|
123
|
+
providerId?: string;
|
|
124
|
+
/** Model ID used to generate this message */
|
|
125
|
+
modelId?: string;
|
|
126
|
+
/** Model info at the time of generation */
|
|
127
|
+
modelInfo?: {
|
|
128
|
+
id: string;
|
|
129
|
+
provider: string;
|
|
130
|
+
};
|
|
131
|
+
/** Token usage metrics */
|
|
132
|
+
metrics?: {
|
|
133
|
+
inputTokens?: number;
|
|
134
|
+
outputTokens?: number;
|
|
135
|
+
cacheReadTokens?: number;
|
|
136
|
+
cacheWriteTokens?: number;
|
|
137
|
+
cost?: number;
|
|
138
|
+
};
|
|
139
|
+
/** Timestamp of when the message was created */
|
|
140
|
+
ts?: number;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Tool definition for native tool calling
|
|
145
|
+
*/
|
|
146
|
+
export interface ToolDefinition {
|
|
147
|
+
/** Tool name */
|
|
148
|
+
name: string;
|
|
149
|
+
/** Tool description */
|
|
150
|
+
description: string;
|
|
151
|
+
/** JSON Schema for the tool's input parameters */
|
|
152
|
+
inputSchema: {
|
|
153
|
+
type: "object";
|
|
154
|
+
properties: Record<string, unknown>;
|
|
155
|
+
required?: string[];
|
|
156
|
+
additionalProperties?: boolean;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { ModelInfo } from "../../models/schemas/model";
|
|
3
|
+
import {
|
|
4
|
+
getModelPricing,
|
|
5
|
+
hasModelCapability,
|
|
6
|
+
supportsModelThinking,
|
|
7
|
+
} from "./model-info";
|
|
8
|
+
|
|
9
|
+
function createModel(overrides: Partial<ModelInfo> = {}): ModelInfo {
|
|
10
|
+
return {
|
|
11
|
+
id: "test-model",
|
|
12
|
+
...overrides,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("model-info helpers", () => {
|
|
17
|
+
it("checks capabilities safely when capabilities are absent", () => {
|
|
18
|
+
const info = createModel();
|
|
19
|
+
|
|
20
|
+
expect(hasModelCapability(info, "reasoning")).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("detects capability membership when present", () => {
|
|
24
|
+
const info = createModel({
|
|
25
|
+
capabilities: ["tools", "reasoning"],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(hasModelCapability(info, "reasoning")).toBe(true);
|
|
29
|
+
expect(hasModelCapability(info, "images")).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("detects thinking support from either thinkingConfig or reasoning capability", () => {
|
|
33
|
+
const byCapability = createModel({
|
|
34
|
+
capabilities: ["reasoning"],
|
|
35
|
+
});
|
|
36
|
+
const byConfig = createModel({
|
|
37
|
+
thinkingConfig: { maxBudget: 1024 },
|
|
38
|
+
});
|
|
39
|
+
const unsupported = createModel({
|
|
40
|
+
capabilities: ["tools"],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
expect(supportsModelThinking(byCapability)).toBe(true);
|
|
44
|
+
expect(supportsModelThinking(byConfig)).toBe(true);
|
|
45
|
+
expect(supportsModelThinking(unsupported)).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("returns pricing if set, otherwise empty pricing object", () => {
|
|
49
|
+
const priced = createModel({
|
|
50
|
+
pricing: { input: 1.2, output: 2.4 },
|
|
51
|
+
});
|
|
52
|
+
const unpriced = createModel();
|
|
53
|
+
|
|
54
|
+
expect(getModelPricing(priced)).toEqual({ input: 1.2, output: 2.4 });
|
|
55
|
+
expect(getModelPricing(unpriced)).toEqual({});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Information Types
|
|
3
|
+
*
|
|
4
|
+
* Re-exports model types from @clinebot/models (the single source of truth)
|
|
5
|
+
* and provides provider-specific helpers and aliases.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
ModelCapability,
|
|
10
|
+
ModelInfo,
|
|
11
|
+
ModelPricing,
|
|
12
|
+
ThinkingConfig,
|
|
13
|
+
} from "../../models/schemas/model";
|
|
14
|
+
import { ApiFormat } from "../../models/schemas/model";
|
|
15
|
+
|
|
16
|
+
export type { ModelCapability, ModelInfo, ModelPricing, ThinkingConfig };
|
|
17
|
+
export { ApiFormat };
|
|
18
|
+
export type { ApiFormat as ApiFormatType } from "../../models/schemas/model";
|
|
19
|
+
|
|
20
|
+
// =============================================================================
|
|
21
|
+
// Helper Functions
|
|
22
|
+
// =============================================================================
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Check if a model has a specific capability
|
|
26
|
+
*/
|
|
27
|
+
export function hasModelCapability(
|
|
28
|
+
info: ModelInfo,
|
|
29
|
+
capability: ModelCapability,
|
|
30
|
+
): boolean {
|
|
31
|
+
return info.capabilities?.includes(capability) ?? false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Check if a model supports explicit thinking/reasoning controls.
|
|
36
|
+
*/
|
|
37
|
+
export function supportsModelThinking(info: ModelInfo): boolean {
|
|
38
|
+
return Boolean(info.thinkingConfig) || hasModelCapability(info, "reasoning");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get pricing for a model
|
|
43
|
+
*/
|
|
44
|
+
export function getModelPricing(info: ModelInfo): ModelPricing {
|
|
45
|
+
return info.pricing ?? {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// =============================================================================
|
|
49
|
+
// Model with ID
|
|
50
|
+
// =============================================================================
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Model with its identifier
|
|
54
|
+
*/
|
|
55
|
+
export interface ModelWithId {
|
|
56
|
+
id: string;
|
|
57
|
+
info: ModelInfo;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// =============================================================================
|
|
61
|
+
// Type Aliases (for backwards compatibility)
|
|
62
|
+
// =============================================================================
|
|
63
|
+
|
|
64
|
+
/** Alias for ModelInfo - all model types use the same interface */
|
|
65
|
+
export type OpenAICompatibleModelInfo = ModelInfo;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { getProviderIds } from "../../models/registry";
|
|
3
|
+
import { BUILT_IN_PROVIDER_IDS } from "./provider-ids";
|
|
4
|
+
|
|
5
|
+
describe("provider-ids", () => {
|
|
6
|
+
it("keeps built-in provider ids aligned with model registry loaders", () => {
|
|
7
|
+
const registryProviderIds = new Set(getProviderIds());
|
|
8
|
+
for (const providerId of BUILT_IN_PROVIDER_IDS) {
|
|
9
|
+
expect(registryProviderIds.has(providerId)).toBe(true);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in provider IDs
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for all built-in provider identifiers.
|
|
5
|
+
* Use BUILT_IN_PROVIDER_IDS for runtime operations (validation, iteration)
|
|
6
|
+
* Use BuiltInProviderId type for compile-time type safety
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export enum BUILT_IN_PROVIDER {
|
|
10
|
+
// First-party
|
|
11
|
+
ANTHROPIC = "anthropic",
|
|
12
|
+
CLAUDE_CODE = "claude-code",
|
|
13
|
+
CLINE = "cline",
|
|
14
|
+
// OpenAI variants
|
|
15
|
+
OPENAI = "openai", // OpenAi Completions
|
|
16
|
+
OPENAI_NATIVE = "openai-native",
|
|
17
|
+
OPENAI_CODEX = "openai-codex",
|
|
18
|
+
// CLI / Subscription-based providers
|
|
19
|
+
OPENCODE = "opencode",
|
|
20
|
+
// Cloud providers
|
|
21
|
+
BEDROCK = "bedrock",
|
|
22
|
+
VERTEX = "vertex",
|
|
23
|
+
GEMINI = "gemini",
|
|
24
|
+
// Local/self-hosted
|
|
25
|
+
OLLAMA = "ollama",
|
|
26
|
+
LMSTUDIO = "lmstudio",
|
|
27
|
+
// OpenAI-compatible
|
|
28
|
+
DEEPSEEK = "deepseek",
|
|
29
|
+
XAI = "xai",
|
|
30
|
+
TOGETHER = "together",
|
|
31
|
+
FIREWORKS = "fireworks",
|
|
32
|
+
GROQ = "groq",
|
|
33
|
+
CEREBRAS = "cerebras",
|
|
34
|
+
SAMBANOVA = "sambanova",
|
|
35
|
+
NEBIUS = "nebius",
|
|
36
|
+
BASETEN = "baseten",
|
|
37
|
+
REQUESTY = "requesty",
|
|
38
|
+
LITELLM = "litellm",
|
|
39
|
+
HUGGINGFACE = "huggingface",
|
|
40
|
+
VERCEL_AI_GATEWAY = "vercel-ai-gateway",
|
|
41
|
+
AIHUBMIX = "aihubmix",
|
|
42
|
+
HICAP = "hicap",
|
|
43
|
+
NOUS_RESEARCH = "nousResearch",
|
|
44
|
+
HUAWEI_CLOUD_MAAS = "huawei-cloud-maas",
|
|
45
|
+
// Regional/specialized
|
|
46
|
+
QWEN = "qwen",
|
|
47
|
+
QWEN_CODE = "qwen-code",
|
|
48
|
+
DOUBAO = "doubao",
|
|
49
|
+
MISTRAL = "mistral",
|
|
50
|
+
MOONSHOT = "moonshot",
|
|
51
|
+
ASKSAGE = "asksage",
|
|
52
|
+
ZAI = "zai",
|
|
53
|
+
MINIMAX = "minimax",
|
|
54
|
+
DIFY = "dify",
|
|
55
|
+
OCA = "oca",
|
|
56
|
+
SAPAICORE = "sapaicore",
|
|
57
|
+
// Aggregators
|
|
58
|
+
OPENROUTER = "openrouter",
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Provider ID aliases normalized to canonical built-in IDs.
|
|
63
|
+
*
|
|
64
|
+
* Keep this map as the single source of truth for alias handling.
|
|
65
|
+
*/
|
|
66
|
+
export const PROVIDER_ID_ALIASES: Record<string, BUILT_IN_PROVIDER> = {
|
|
67
|
+
openai: BUILT_IN_PROVIDER.OPENAI_NATIVE,
|
|
68
|
+
togetherai: BUILT_IN_PROVIDER.TOGETHER,
|
|
69
|
+
"sap-ai-core": BUILT_IN_PROVIDER.SAPAICORE,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const BUILT_IN_PROVIDER_IDS = Object.values(BUILT_IN_PROVIDER) as [
|
|
73
|
+
BUILT_IN_PROVIDER,
|
|
74
|
+
...BUILT_IN_PROVIDER[],
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
/** Type derived from the array - use for type annotations */
|
|
78
|
+
export type BuiltInProviderId = (typeof BUILT_IN_PROVIDER_IDS)[number];
|
|
79
|
+
|
|
80
|
+
/** Check if a string is a valid built-in provider ID */
|
|
81
|
+
export function isBuiltInProviderId(id: string): id is BuiltInProviderId {
|
|
82
|
+
return BUILT_IN_PROVIDER_IDS.includes(id as BuiltInProviderId);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Normalize provider aliases to canonical IDs */
|
|
86
|
+
export function normalizeProviderId(providerId: string): string {
|
|
87
|
+
const normalized = providerId.trim();
|
|
88
|
+
return PROVIDER_ID_ALIASES[normalized] ?? normalized;
|
|
89
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { resolveProviderModelCatalogKeys } from "@clinebot/shared";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { getGeneratedModelsForProvider } from "../../models/generated-access";
|
|
4
|
+
import type { ProviderSettings } from "./settings";
|
|
5
|
+
import { toProviderConfig } from "./settings";
|
|
6
|
+
|
|
7
|
+
describe("toProviderConfig", () => {
|
|
8
|
+
it("backfills knownModels from generated catalogs for anthropic", () => {
|
|
9
|
+
const anthropicModels = getGeneratedModelsForProvider("anthropic");
|
|
10
|
+
const modelId = Object.keys(anthropicModels)[0];
|
|
11
|
+
expect(modelId).toBeTruthy();
|
|
12
|
+
if (!modelId) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const settings: ProviderSettings = {
|
|
17
|
+
provider: "anthropic",
|
|
18
|
+
apiKey: "test-key",
|
|
19
|
+
model: modelId,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const config = toProviderConfig(settings);
|
|
23
|
+
|
|
24
|
+
expect(config.knownModels?.[modelId]).toEqual(anthropicModels[modelId]);
|
|
25
|
+
expect(config.knownModels?.[modelId]?.pricing).toBeDefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("hydrates cline knownModels using shared catalog key mapping", () => {
|
|
29
|
+
const gatewayModels = Object.assign(
|
|
30
|
+
{},
|
|
31
|
+
...resolveProviderModelCatalogKeys("cline").map((providerId) =>
|
|
32
|
+
getGeneratedModelsForProvider(providerId),
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
const modelId = "openai/gpt-5.3-codex";
|
|
36
|
+
expect(gatewayModels[modelId]).toBeDefined();
|
|
37
|
+
|
|
38
|
+
const settings: ProviderSettings = {
|
|
39
|
+
provider: "cline",
|
|
40
|
+
apiKey: "test-key",
|
|
41
|
+
model: modelId,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const config = toProviderConfig(settings);
|
|
45
|
+
|
|
46
|
+
expect(config.knownModels?.[modelId]).toEqual(gatewayModels[modelId]);
|
|
47
|
+
expect(config.knownModels?.[modelId]?.pricing).toBeDefined();
|
|
48
|
+
});
|
|
49
|
+
});
|