@node-llm/core 1.15.2 → 1.16.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/dist/aliases.d.ts +315 -26
- package/dist/aliases.d.ts.map +1 -1
- package/dist/aliases.js +334 -45
- package/dist/chat/Chat.d.ts +22 -2
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +45 -3
- package/dist/chat/ChatOptions.d.ts +3 -1
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatResponse.d.ts +8 -2
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +9 -3
- package/dist/chat/ChatStream.d.ts.map +1 -1
- package/dist/chat/ChatStream.js +2 -0
- package/dist/chat/Tool.d.ts.map +1 -1
- package/dist/chat/Tool.js +21 -11
- package/dist/chat/ToolHandler.d.ts.map +1 -1
- package/dist/chat/ToolHandler.js +9 -2
- package/dist/chat/Validation.d.ts +1 -0
- package/dist/chat/Validation.d.ts.map +1 -1
- package/dist/chat/Validation.js +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/llm.d.ts +4 -0
- package/dist/llm.d.ts.map +1 -1
- package/dist/models/ModelRegistry.d.ts +3 -0
- package/dist/models/ModelRegistry.d.ts.map +1 -1
- package/dist/models/ModelRegistry.js +53 -16
- package/dist/models/PricingRegistry.d.ts.map +1 -1
- package/dist/models/PricingRegistry.js +14 -0
- package/dist/models/models.json +15118 -8614
- package/dist/providers/BaseProvider.d.ts.map +1 -1
- package/dist/providers/BaseProvider.js +1 -0
- package/dist/providers/Provider.d.ts +33 -0
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.js +1 -1
- package/dist/providers/anthropic/Capabilities.d.ts +1 -0
- package/dist/providers/anthropic/Capabilities.d.ts.map +1 -1
- package/dist/providers/anthropic/Capabilities.js +15 -34
- package/dist/providers/anthropic/Chat.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.js +16 -2
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +15 -1
- package/dist/providers/bedrock/BedrockProvider.d.ts +1 -1
- package/dist/providers/bedrock/BedrockProvider.js +1 -1
- package/dist/providers/bedrock/Capabilities.d.ts +3 -28
- package/dist/providers/bedrock/Capabilities.d.ts.map +1 -1
- package/dist/providers/bedrock/Capabilities.js +62 -183
- package/dist/providers/bedrock/Chat.d.ts.map +1 -1
- package/dist/providers/bedrock/Chat.js +1 -0
- package/dist/providers/bedrock/Streaming.d.ts.map +1 -1
- package/dist/providers/bedrock/Streaming.js +1 -0
- package/dist/providers/bedrock/mapper.d.ts +4 -3
- package/dist/providers/bedrock/mapper.d.ts.map +1 -1
- package/dist/providers/bedrock/mapper.js +19 -4
- package/dist/providers/deepseek/Capabilities.d.ts +2 -1
- package/dist/providers/deepseek/Capabilities.d.ts.map +1 -1
- package/dist/providers/deepseek/Capabilities.js +21 -30
- package/dist/providers/deepseek/DeepSeekProvider.d.ts +1 -1
- package/dist/providers/gemini/Capabilities.d.ts +1 -1
- package/dist/providers/gemini/Capabilities.d.ts.map +1 -1
- package/dist/providers/gemini/Capabilities.js +33 -87
- package/dist/providers/gemini/Chat.d.ts.map +1 -1
- package/dist/providers/gemini/Chat.js +44 -9
- package/dist/providers/gemini/ChatUtils.d.ts.map +1 -1
- package/dist/providers/gemini/ChatUtils.js +59 -49
- package/dist/providers/gemini/GeminiProvider.js +1 -1
- package/dist/providers/gemini/Image.d.ts.map +1 -1
- package/dist/providers/gemini/Image.js +17 -5
- package/dist/providers/gemini/Streaming.d.ts.map +1 -1
- package/dist/providers/gemini/Streaming.js +41 -1
- package/dist/providers/gemini/types.d.ts +1 -0
- package/dist/providers/gemini/types.d.ts.map +1 -1
- package/dist/providers/mistral/Capabilities.d.ts +1 -0
- package/dist/providers/mistral/Capabilities.d.ts.map +1 -1
- package/dist/providers/mistral/Capabilities.js +30 -59
- package/dist/providers/mistral/Chat.d.ts.map +1 -1
- package/dist/providers/mistral/Chat.js +13 -1
- package/dist/providers/mistral/Streaming.d.ts.map +1 -1
- package/dist/providers/mistral/Streaming.js +13 -1
- package/dist/providers/mistral/Transcription.d.ts.map +1 -1
- package/dist/providers/mistral/Transcription.js +3 -1
- package/dist/providers/ollama/Capabilities.d.ts +1 -0
- package/dist/providers/ollama/Capabilities.d.ts.map +1 -1
- package/dist/providers/ollama/Capabilities.js +17 -27
- package/dist/providers/openai/Capabilities.d.ts +2 -1
- package/dist/providers/openai/Capabilities.d.ts.map +1 -1
- package/dist/providers/openai/Capabilities.js +35 -71
- package/dist/providers/openai/Chat.d.ts.map +1 -1
- package/dist/providers/openai/Chat.js +4 -1
- package/dist/providers/openai/Image.d.ts +1 -0
- package/dist/providers/openai/Image.d.ts.map +1 -1
- package/dist/providers/openai/Image.js +61 -2
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +7 -1
- package/dist/providers/openai/Transcription.d.ts.map +1 -1
- package/dist/providers/openai/Transcription.js +7 -2
- package/dist/providers/openrouter/Capabilities.d.ts +10 -9
- package/dist/providers/openrouter/Capabilities.d.ts.map +1 -1
- package/dist/providers/openrouter/Capabilities.js +25 -48
- package/dist/providers/utils.d.ts +4 -0
- package/dist/providers/utils.d.ts.map +1 -1
- package/dist/providers/utils.js +11 -0
- package/dist/providers/xai/Capabilities.d.ts +13 -9
- package/dist/providers/xai/Capabilities.d.ts.map +1 -1
- package/dist/providers/xai/Capabilities.js +34 -65
- package/dist/transcription/Transcription.d.ts +23 -1
- package/dist/transcription/Transcription.d.ts.map +1 -1
- package/dist/transcription/Transcription.js +22 -0
- package/dist/utils/Binary.d.ts +8 -0
- package/dist/utils/Binary.d.ts.map +1 -1
- package/dist/utils/Binary.js +12 -0
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { buildUrl } from "./utils.js";
|
|
|
4
4
|
import { APIError } from "../../errors/index.js";
|
|
5
5
|
import { logger } from "../../utils/logger.js";
|
|
6
6
|
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
7
|
-
import { mapSystemMessages } from "../utils.js";
|
|
7
|
+
import { mapSystemMessages, normalizeOpenAIToolChoice } from "../utils.js";
|
|
8
8
|
import { enforceStrictSchema } from "../../schema/strict.js";
|
|
9
9
|
export class OpenAIStreaming {
|
|
10
10
|
providerOrUrl;
|
|
@@ -72,6 +72,12 @@ export class OpenAIStreaming {
|
|
|
72
72
|
return tool;
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
+
if (request.tool_choice) {
|
|
76
|
+
body.tool_choice = normalizeOpenAIToolChoice(request.tool_choice);
|
|
77
|
+
}
|
|
78
|
+
if (request.parallel_tool_calls !== undefined) {
|
|
79
|
+
body.parallel_tool_calls = request.parallel_tool_calls;
|
|
80
|
+
}
|
|
75
81
|
if (request.prediction) {
|
|
76
82
|
body.prediction = {
|
|
77
83
|
type: "content",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transcription.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAwB,MAAM,gBAAgB,CAAC;AAQnG,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAU9D,oBAAoB;
|
|
1
|
+
{"version":3,"file":"Transcription.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAwB,MAAM,gBAAgB,CAAC;AAQnG,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAU9D,oBAAoB;YAuEpB,iBAAiB;CAgIhC"}
|
|
@@ -32,6 +32,9 @@ export class OpenAITranscription {
|
|
|
32
32
|
if (request.language) {
|
|
33
33
|
formData.append("language", request.language);
|
|
34
34
|
}
|
|
35
|
+
if (request.timestamp_granularities) {
|
|
36
|
+
request.timestamp_granularities.forEach((g) => formData.append("timestamp_granularities[]", g));
|
|
37
|
+
}
|
|
35
38
|
const url = buildUrl(this.baseUrl, "/audio/transcriptions");
|
|
36
39
|
logger.logRequest("OpenAI", "POST", url, {
|
|
37
40
|
model: request.model || DEFAULT_MODELS.TRANSCRIPTION,
|
|
@@ -57,8 +60,10 @@ export class OpenAITranscription {
|
|
|
57
60
|
id: s.id,
|
|
58
61
|
start: s.start,
|
|
59
62
|
end: s.end,
|
|
60
|
-
text: s.text
|
|
61
|
-
|
|
63
|
+
text: s.text,
|
|
64
|
+
speaker: s.speaker
|
|
65
|
+
})),
|
|
66
|
+
words: json.words
|
|
62
67
|
};
|
|
63
68
|
}
|
|
64
69
|
async transcribeViaChat(request) {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export declare class OpenRouterCapabilities {
|
|
2
2
|
private static findModel;
|
|
3
|
-
static supportsVision(
|
|
4
|
-
static supportsTools(
|
|
5
|
-
static supportsStructuredOutput(
|
|
6
|
-
static supportsEmbeddings(
|
|
7
|
-
static supportsImageGeneration(
|
|
8
|
-
static supportsTranscription(
|
|
9
|
-
static supportsModeration(
|
|
10
|
-
static supportsReasoning(
|
|
11
|
-
static
|
|
3
|
+
static supportsVision(modelId: string): boolean;
|
|
4
|
+
static supportsTools(modelId: string): boolean;
|
|
5
|
+
static supportsStructuredOutput(modelId: string): boolean;
|
|
6
|
+
static supportsEmbeddings(modelId: string): boolean;
|
|
7
|
+
static supportsImageGeneration(_modelId: string): boolean;
|
|
8
|
+
static supportsTranscription(_modelId: string): boolean;
|
|
9
|
+
static supportsModeration(_modelId: string): boolean;
|
|
10
|
+
static supportsReasoning(modelId: string): boolean;
|
|
11
|
+
static supportsToolChoice(_modelId: string): boolean;
|
|
12
|
+
static getContextWindow(modelId: string): number | null;
|
|
12
13
|
}
|
|
13
14
|
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/openrouter/Capabilities.ts"],"names":[],"mappings":"AAEA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,MAAM,CAAC,SAAS;IAIxB,MAAM,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/openrouter/Capabilities.ts"],"names":[],"mappings":"AAEA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,MAAM,CAAC,SAAS;IAIxB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAO/C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAQ9C,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOzD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAMnD,MAAM,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIzD,MAAM,CAAC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIvD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOlD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAGxD"}
|
|
@@ -1,64 +1,41 @@
|
|
|
1
1
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
2
2
|
export class OpenRouterCapabilities {
|
|
3
|
-
static findModel(
|
|
4
|
-
return ModelRegistry.find(
|
|
3
|
+
static findModel(modelId) {
|
|
4
|
+
return ModelRegistry.find(modelId, "openrouter");
|
|
5
5
|
}
|
|
6
|
-
static supportsVision(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return info.capabilities.includes("vision") || info.modalities.input.includes("image");
|
|
10
|
-
// Fallback heuristics
|
|
11
|
-
return (model.includes("vision") ||
|
|
12
|
-
model.includes("gpt-4o") ||
|
|
13
|
-
model.includes("claude-3") ||
|
|
14
|
-
model.includes("gemini-1.5") ||
|
|
15
|
-
model.includes("gemini-2.0") ||
|
|
16
|
-
model.includes("flash") ||
|
|
17
|
-
model.includes("gemini-pro-vision"));
|
|
6
|
+
static supportsVision(modelId) {
|
|
7
|
+
return (ModelRegistry.supports(modelId, "vision", "openrouter") ||
|
|
8
|
+
/vision|gpt-4o|claude-3|gemini|flash/.test(modelId.toLowerCase()));
|
|
18
9
|
}
|
|
19
|
-
static supportsTools(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Fallback: Default to true for OpenRouter as most models support tools
|
|
24
|
-
// but this is the "honest" check we wanted.
|
|
25
|
-
return true;
|
|
10
|
+
static supportsTools(modelId) {
|
|
11
|
+
return (ModelRegistry.supports(modelId, "tools", "openrouter") ||
|
|
12
|
+
ModelRegistry.supports(modelId, "function_calling", "openrouter") ||
|
|
13
|
+
true); // OpenRouter usually supports tools on most modern models
|
|
26
14
|
}
|
|
27
|
-
static supportsStructuredOutput(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return info.capabilities.includes("structured_output") || info.id.includes("gpt-4");
|
|
31
|
-
// Fallback heuristics
|
|
32
|
-
return model.includes("gpt-4") || model.includes("gpt-3.5") || model.includes("claude-3");
|
|
15
|
+
static supportsStructuredOutput(modelId) {
|
|
16
|
+
return (ModelRegistry.supports(modelId, "structured_output", "openrouter") ||
|
|
17
|
+
/gpt-4|gpt-3\.5|claude-3/.test(modelId.toLowerCase()));
|
|
33
18
|
}
|
|
34
|
-
static supportsEmbeddings(
|
|
35
|
-
|
|
36
|
-
if (info)
|
|
37
|
-
return info.capabilities.includes("embeddings");
|
|
38
|
-
// Fallback heuristics
|
|
39
|
-
return model.includes("embedding") || model.includes("text-sdk");
|
|
19
|
+
static supportsEmbeddings(modelId) {
|
|
20
|
+
return (ModelRegistry.supports(modelId, "embeddings", "openrouter") || modelId.includes("embedding"));
|
|
40
21
|
}
|
|
41
|
-
static supportsImageGeneration(
|
|
22
|
+
static supportsImageGeneration(_modelId) {
|
|
42
23
|
return false;
|
|
43
24
|
}
|
|
44
|
-
static supportsTranscription(
|
|
25
|
+
static supportsTranscription(_modelId) {
|
|
45
26
|
return false;
|
|
46
27
|
}
|
|
47
|
-
static supportsModeration(
|
|
28
|
+
static supportsModeration(_modelId) {
|
|
48
29
|
return false;
|
|
49
30
|
}
|
|
50
|
-
static supportsReasoning(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return
|
|
56
|
-
model.includes("o3") ||
|
|
57
|
-
model.includes("deepseek-r1") ||
|
|
58
|
-
model.includes("qwq"));
|
|
31
|
+
static supportsReasoning(modelId) {
|
|
32
|
+
return (ModelRegistry.supports(modelId, "reasoning", "openrouter") ||
|
|
33
|
+
/o1-|o3-|reasoner|-r1|qwq/.test(modelId.toLowerCase()));
|
|
34
|
+
}
|
|
35
|
+
static supportsToolChoice(_modelId) {
|
|
36
|
+
return true;
|
|
59
37
|
}
|
|
60
|
-
static getContextWindow(
|
|
61
|
-
|
|
62
|
-
return info?.context_window ?? null;
|
|
38
|
+
static getContextWindow(modelId) {
|
|
39
|
+
return ModelRegistry.getContextWindow(modelId, "openrouter") ?? null;
|
|
63
40
|
}
|
|
64
41
|
}
|
|
@@ -5,4 +5,8 @@ import { Message } from "../chat/Message.js";
|
|
|
5
5
|
* If supportsDeveloperRole is false, both "system" and "developer" messages are mapped to "system".
|
|
6
6
|
*/
|
|
7
7
|
export declare function mapSystemMessages(messages: Message[], supportsDeveloperRole: boolean): Message[];
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes tool choice for OpenAI-compatible providers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizeOpenAIToolChoice(choice: any): any;
|
|
8
12
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,qBAAqB,EAAE,OAAO,GAAG,OAAO,EAAE,CAUhG"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,qBAAqB,EAAE,OAAO,GAAG,OAAO,EAAE,CAUhG;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,CAM1D"}
|
package/dist/providers/utils.js
CHANGED
|
@@ -14,3 +14,14 @@ export function mapSystemMessages(messages, supportsDeveloperRole) {
|
|
|
14
14
|
return msg;
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes tool choice for OpenAI-compatible providers.
|
|
19
|
+
*/
|
|
20
|
+
export function normalizeOpenAIToolChoice(choice) {
|
|
21
|
+
if (!choice)
|
|
22
|
+
return undefined;
|
|
23
|
+
if (typeof choice === "string" && !["auto", "none", "required"].includes(choice)) {
|
|
24
|
+
return { type: "function", function: { name: choice } };
|
|
25
|
+
}
|
|
26
|
+
return choice;
|
|
27
|
+
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { ModelPricing } from "../../models/types.js";
|
|
1
2
|
export declare class Capabilities {
|
|
2
|
-
static supportsVision(
|
|
3
|
-
static supportsTools(
|
|
4
|
-
static supportsStructuredOutput(
|
|
5
|
-
static supportsEmbeddings(
|
|
6
|
-
static supportsImageGeneration(
|
|
7
|
-
static supportsTranscription(
|
|
8
|
-
static supportsModeration(
|
|
9
|
-
static supportsReasoning(
|
|
10
|
-
static
|
|
3
|
+
static supportsVision(modelId: string): boolean;
|
|
4
|
+
static supportsTools(modelId: string): boolean;
|
|
5
|
+
static supportsStructuredOutput(modelId: string): boolean;
|
|
6
|
+
static supportsEmbeddings(modelId: string): boolean;
|
|
7
|
+
static supportsImageGeneration(modelId: string): boolean;
|
|
8
|
+
static supportsTranscription(modelId: string): boolean;
|
|
9
|
+
static supportsModeration(modelId: string): boolean;
|
|
10
|
+
static supportsReasoning(modelId: string): boolean;
|
|
11
|
+
static supportsToolChoice(_modelId: string): boolean;
|
|
12
|
+
static getContextWindow(modelId: string): number;
|
|
13
|
+
static getPricing(modelId: string): ModelPricing | undefined;
|
|
14
|
+
private static findModel;
|
|
11
15
|
}
|
|
12
16
|
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/xai/Capabilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/xai/Capabilities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,qBAAa,YAAY;IACvB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI/C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAS9C,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOzD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAInD,MAAM,CAAC,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAQxD,MAAM,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAItD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAInD,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIlD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAIhD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAI5D,OAAO,CAAC,MAAM,CAAC,SAAS;CAGzB"}
|
|
@@ -1,79 +1,48 @@
|
|
|
1
1
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
2
|
-
|
|
3
|
-
"grok-2-vision-1212",
|
|
4
|
-
"grok-4-0709",
|
|
5
|
-
"grok-4-fast-non-reasoning",
|
|
6
|
-
"grok-4-fast-reasoning",
|
|
7
|
-
"grok-4.1-fast-non-reasoning",
|
|
8
|
-
"grok-4.1-fast-reasoning",
|
|
9
|
-
"grok-4-1-fast-non-reasoning",
|
|
10
|
-
"grok-4-1-fast-reasoning"
|
|
11
|
-
];
|
|
12
|
-
const REASONING_MODELS = [
|
|
13
|
-
"grok-3-mini",
|
|
14
|
-
"grok-4-0709",
|
|
15
|
-
"grok-4-fast-reasoning",
|
|
16
|
-
"grok-4.1-fast-reasoning",
|
|
17
|
-
"grok-4-1-fast-reasoning",
|
|
18
|
-
"grok-code-fast-1"
|
|
19
|
-
];
|
|
2
|
+
import { PricingRegistry } from "../../models/PricingRegistry.js";
|
|
20
3
|
export class Capabilities {
|
|
21
|
-
static supportsVision(
|
|
22
|
-
|
|
23
|
-
if (registryModel?.capabilities.includes("vision"))
|
|
24
|
-
return true;
|
|
25
|
-
return model.includes("vision") || VISION_MODELS.includes(model);
|
|
4
|
+
static supportsVision(modelId) {
|
|
5
|
+
return ModelRegistry.supports(modelId, "vision", "xai");
|
|
26
6
|
}
|
|
27
|
-
static supportsTools(
|
|
28
|
-
if (this.supportsImageGeneration(
|
|
7
|
+
static supportsTools(modelId) {
|
|
8
|
+
if (this.supportsImageGeneration(modelId))
|
|
29
9
|
return false;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return true;
|
|
10
|
+
return (ModelRegistry.supports(modelId, "tools", "xai") ||
|
|
11
|
+
ModelRegistry.supports(modelId, "function_calling", "xai") ||
|
|
12
|
+
!modelId.includes("image"));
|
|
34
13
|
}
|
|
35
|
-
static supportsStructuredOutput(
|
|
36
|
-
if (this.supportsImageGeneration(
|
|
14
|
+
static supportsStructuredOutput(modelId) {
|
|
15
|
+
if (this.supportsImageGeneration(modelId))
|
|
37
16
|
return false;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return
|
|
17
|
+
return (ModelRegistry.supports(modelId, "structured_output", "xai") || !modelId.includes("image"));
|
|
18
|
+
}
|
|
19
|
+
static supportsEmbeddings(modelId) {
|
|
20
|
+
return ModelRegistry.supports(modelId, "embeddings", "xai");
|
|
42
21
|
}
|
|
43
|
-
static
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return false;
|
|
22
|
+
static supportsImageGeneration(modelId) {
|
|
23
|
+
return (ModelRegistry.supports(modelId, "image_generation", "xai") ||
|
|
24
|
+
modelId.includes("image") ||
|
|
25
|
+
modelId.includes("imagine"));
|
|
48
26
|
}
|
|
49
|
-
static
|
|
50
|
-
|
|
51
|
-
if (registryModel?.capabilities.includes("image_generation"))
|
|
52
|
-
return true;
|
|
53
|
-
return model.includes("image") || model.includes("imagine");
|
|
27
|
+
static supportsTranscription(modelId) {
|
|
28
|
+
return ModelRegistry.supports(modelId, "transcription", "xai");
|
|
54
29
|
}
|
|
55
|
-
static
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
30
|
+
static supportsModeration(modelId) {
|
|
31
|
+
return ModelRegistry.supports(modelId, "moderation", "xai");
|
|
32
|
+
}
|
|
33
|
+
static supportsReasoning(modelId) {
|
|
34
|
+
return ModelRegistry.supports(modelId, "reasoning", "xai") || modelId.includes("reasoning");
|
|
35
|
+
}
|
|
36
|
+
static supportsToolChoice(_modelId) {
|
|
37
|
+
return true;
|
|
60
38
|
}
|
|
61
|
-
static
|
|
62
|
-
|
|
63
|
-
if (registryModel?.capabilities.includes("moderation"))
|
|
64
|
-
return true;
|
|
65
|
-
return false;
|
|
39
|
+
static getContextWindow(modelId) {
|
|
40
|
+
return ModelRegistry.getContextWindow(modelId, "xai") ?? 128_000;
|
|
66
41
|
}
|
|
67
|
-
static
|
|
68
|
-
|
|
69
|
-
if (registryModel?.capabilities.includes("reasoning"))
|
|
70
|
-
return true;
|
|
71
|
-
return model.includes("reasoning") || REASONING_MODELS.includes(model);
|
|
42
|
+
static getPricing(modelId) {
|
|
43
|
+
return PricingRegistry.getPricing(modelId, "xai");
|
|
72
44
|
}
|
|
73
|
-
static
|
|
74
|
-
|
|
75
|
-
if (registryModel?.context_window)
|
|
76
|
-
return registryModel.context_window;
|
|
77
|
-
return 128000;
|
|
45
|
+
static findModel(modelId) {
|
|
46
|
+
return ModelRegistry.find(modelId, "xai");
|
|
78
47
|
}
|
|
79
48
|
}
|
|
@@ -1,11 +1,33 @@
|
|
|
1
|
-
import { TranscriptionResponse, TranscriptionSegment } from "../providers/Provider.js";
|
|
1
|
+
import { TranscriptionResponse, TranscriptionSegment, TranscriptionWord } from "../providers/Provider.js";
|
|
2
2
|
export declare class Transcription {
|
|
3
3
|
private readonly response;
|
|
4
4
|
constructor(response: TranscriptionResponse);
|
|
5
5
|
get text(): string;
|
|
6
6
|
get model(): string;
|
|
7
7
|
get segments(): TranscriptionSegment[];
|
|
8
|
+
get words(): TranscriptionWord[];
|
|
8
9
|
get duration(): number | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Serializable object containing all response metadata.
|
|
12
|
+
* Perfect for database persistence — mirrors ChatResponseString.meta.
|
|
13
|
+
*/
|
|
14
|
+
get meta(): {
|
|
15
|
+
text: string;
|
|
16
|
+
model: string;
|
|
17
|
+
duration: number | undefined;
|
|
18
|
+
segments: TranscriptionSegment[] | undefined;
|
|
19
|
+
words: TranscriptionWord[] | undefined;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Alias for meta (backwards compatibility).
|
|
23
|
+
*/
|
|
24
|
+
get raw(): {
|
|
25
|
+
text: string;
|
|
26
|
+
model: string;
|
|
27
|
+
duration: number | undefined;
|
|
28
|
+
segments: TranscriptionSegment[] | undefined;
|
|
29
|
+
words: TranscriptionWord[] | undefined;
|
|
30
|
+
};
|
|
9
31
|
toString(): string;
|
|
10
32
|
}
|
|
11
33
|
//# sourceMappingURL=Transcription.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transcription.d.ts","sourceRoot":"","sources":["../../src/transcription/Transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"Transcription.d.ts","sourceRoot":"","sources":["../../src/transcription/Transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE1G,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,qBAAqB;IAE5D,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,QAAQ,IAAI,oBAAoB,EAAE,CAErC;IAED,IAAI,KAAK,IAAI,iBAAiB,EAAE,CAE/B;IAED,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAEjC;IAED;;;OAGG;IACH,IAAI,IAAI;;;;;;MAQP;IAED;;OAEG;IACH,IAAI,GAAG;;;;;;MAEN;IAED,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -12,9 +12,31 @@ export class Transcription {
|
|
|
12
12
|
get segments() {
|
|
13
13
|
return this.response.segments || [];
|
|
14
14
|
}
|
|
15
|
+
get words() {
|
|
16
|
+
return this.response.words || [];
|
|
17
|
+
}
|
|
15
18
|
get duration() {
|
|
16
19
|
return this.response.duration;
|
|
17
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Serializable object containing all response metadata.
|
|
23
|
+
* Perfect for database persistence — mirrors ChatResponseString.meta.
|
|
24
|
+
*/
|
|
25
|
+
get meta() {
|
|
26
|
+
return {
|
|
27
|
+
text: this.response.text,
|
|
28
|
+
model: this.response.model,
|
|
29
|
+
duration: this.response.duration,
|
|
30
|
+
segments: this.response.segments,
|
|
31
|
+
words: this.response.words
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Alias for meta (backwards compatibility).
|
|
36
|
+
*/
|
|
37
|
+
get raw() {
|
|
38
|
+
return this.meta;
|
|
39
|
+
}
|
|
18
40
|
toString() {
|
|
19
41
|
return this.text;
|
|
20
42
|
}
|
package/dist/utils/Binary.d.ts
CHANGED
|
@@ -7,6 +7,14 @@ export declare class BinaryUtils {
|
|
|
7
7
|
* Converts a URL (data:, http:, or local path) to a base64 string and mime type.
|
|
8
8
|
*/
|
|
9
9
|
static toBase64(url: string): Promise<Base64Data | null>;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a Base64Data object to a Blob.
|
|
12
|
+
*/
|
|
13
|
+
static base64ToBlob(binary: Base64Data): Blob;
|
|
14
|
+
/**
|
|
15
|
+
* Converts a Base64Data object to a Buffer.
|
|
16
|
+
*/
|
|
17
|
+
static base64ToBuffer(binary: Base64Data): Buffer;
|
|
10
18
|
private static guessMimeType;
|
|
11
19
|
}
|
|
12
20
|
//# sourceMappingURL=Binary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Binary.d.ts","sourceRoot":"","sources":["../../src/utils/Binary.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAW;IACtB;;OAEG;WACU,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA0C9D,OAAO,CAAC,MAAM,CAAC,aAAa;CA0B7B"}
|
|
1
|
+
{"version":3,"file":"Binary.d.ts","sourceRoot":"","sources":["../../src/utils/Binary.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAW;IACtB;;OAEG;WACU,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA0C9D;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAI7C;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;IAIjD,OAAO,CAAC,MAAM,CAAC,aAAa;CA0B7B"}
|
package/dist/utils/Binary.js
CHANGED
|
@@ -51,6 +51,18 @@ export class BinaryUtils {
|
|
|
51
51
|
}
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Converts a Base64Data object to a Blob.
|
|
56
|
+
*/
|
|
57
|
+
static base64ToBlob(binary) {
|
|
58
|
+
return new Blob([new Uint8Array(this.base64ToBuffer(binary))], { type: binary.mimeType });
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Converts a Base64Data object to a Buffer.
|
|
62
|
+
*/
|
|
63
|
+
static base64ToBuffer(binary) {
|
|
64
|
+
return Buffer.from(binary.data, "base64");
|
|
65
|
+
}
|
|
54
66
|
static guessMimeType(filePath) {
|
|
55
67
|
const ext = path.extname(filePath).toLowerCase();
|
|
56
68
|
switch (ext) {
|