@sudobility/shapeshyft_engine 1.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/CLAUDE.md +27 -0
- package/README.md +11 -0
- package/dist/config/providers.d.ts +111 -0
- package/dist/config/providers.d.ts.map +1 -0
- package/dist/config/providers.js +1535 -0
- package/dist/config/providers.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api-helper.d.ts +35 -0
- package/dist/lib/api-helper.d.ts.map +1 -0
- package/dist/lib/api-helper.js +123 -0
- package/dist/lib/api-helper.js.map +1 -0
- package/dist/lib/capability-validator.d.ts +36 -0
- package/dist/lib/capability-validator.d.ts.map +1 -0
- package/dist/lib/capability-validator.js +140 -0
- package/dist/lib/capability-validator.js.map +1 -0
- package/dist/lib/media-constants.d.ts +55 -0
- package/dist/lib/media-constants.d.ts.map +1 -0
- package/dist/lib/media-constants.js +166 -0
- package/dist/lib/media-constants.js.map +1 -0
- package/dist/lib/media-conversion.d.ts +36 -0
- package/dist/lib/media-conversion.d.ts.map +1 -0
- package/dist/lib/media-conversion.js +87 -0
- package/dist/lib/media-conversion.js.map +1 -0
- package/dist/lib/media-utils.d.ts +35 -0
- package/dist/lib/media-utils.d.ts.map +1 -0
- package/dist/lib/media-utils.js +173 -0
- package/dist/lib/media-utils.js.map +1 -0
- package/dist/lib/output-limit.d.ts +38 -0
- package/dist/lib/output-limit.d.ts.map +1 -0
- package/dist/lib/output-limit.js +54 -0
- package/dist/lib/output-limit.js.map +1 -0
- package/dist/lib/prompt-builder.d.ts +94 -0
- package/dist/lib/prompt-builder.d.ts.map +1 -0
- package/dist/lib/prompt-builder.js +408 -0
- package/dist/lib/prompt-builder.js.map +1 -0
- package/dist/lib/reserved-fields.d.ts +41 -0
- package/dist/lib/reserved-fields.d.ts.map +1 -0
- package/dist/lib/reserved-fields.js +47 -0
- package/dist/lib/reserved-fields.js.map +1 -0
- package/dist/services/llm/anthropic.d.ts +16 -0
- package/dist/services/llm/anthropic.d.ts.map +1 -0
- package/dist/services/llm/anthropic.js +154 -0
- package/dist/services/llm/anthropic.js.map +1 -0
- package/dist/services/llm/custom.d.ts +51 -0
- package/dist/services/llm/custom.d.ts.map +1 -0
- package/dist/services/llm/custom.js +419 -0
- package/dist/services/llm/custom.js.map +1 -0
- package/dist/services/llm/extract-json.d.ts +17 -0
- package/dist/services/llm/extract-json.d.ts.map +1 -0
- package/dist/services/llm/extract-json.js +60 -0
- package/dist/services/llm/extract-json.js.map +1 -0
- package/dist/services/llm/finish-reason.d.ts +21 -0
- package/dist/services/llm/finish-reason.d.ts.map +1 -0
- package/dist/services/llm/finish-reason.js +55 -0
- package/dist/services/llm/finish-reason.js.map +1 -0
- package/dist/services/llm/gemini.d.ts +26 -0
- package/dist/services/llm/gemini.d.ts.map +1 -0
- package/dist/services/llm/gemini.js +178 -0
- package/dist/services/llm/gemini.js.map +1 -0
- package/dist/services/llm/groq.d.ts +28 -0
- package/dist/services/llm/groq.d.ts.map +1 -0
- package/dist/services/llm/groq.js +237 -0
- package/dist/services/llm/groq.js.map +1 -0
- package/dist/services/llm/index.d.ts +19 -0
- package/dist/services/llm/index.d.ts.map +1 -0
- package/dist/services/llm/index.js +88 -0
- package/dist/services/llm/index.js.map +1 -0
- package/dist/services/llm/openai.d.ts +101 -0
- package/dist/services/llm/openai.d.ts.map +1 -0
- package/dist/services/llm/openai.js +561 -0
- package/dist/services/llm/openai.js.map +1 -0
- package/dist/services/llm/types.d.ts +110 -0
- package/dist/services/llm/types.d.ts.map +1 -0
- package/dist/services/llm/types.js +16 -0
- package/dist/services/llm/types.js.map +1 -0
- package/dist/types/index.d.ts +812 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +366 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gro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AC;QACD,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAEzD,OAAO;YACL,KAAK;YACL,QAAQ;YACR,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,UAAU;oBAChB,QAAQ,EAAE;wBACR,IAAI,EAAE,qBAAqB;wBAC3B,WAAW,EAAE,kDAAkD;wBAC/D,UAAU,EAAE,OAAO,CAAC,YAAY;qBACjC;iBACF;aACF;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE;aAC1C;YACD,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,CAAC;YACrC,UAAU,EAAE,OAAO,CAAC,SAAS;SAC9B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview LLM provider factory and exports
|
|
3
|
+
* @description Creates the appropriate LLM provider instance based on provider type.
|
|
4
|
+
* OpenAI-compatible providers (Mistral, xAI, DeepSeek, Perplexity, Cohere) reuse
|
|
5
|
+
* the OpenAIProvider class. Groq has a dedicated provider for Whisper transcription.
|
|
6
|
+
*/
|
|
7
|
+
import type { LlmProvider } from "../../types/index.js";
|
|
8
|
+
import type { ILLMProvider, ProviderConfig } from "./types.js";
|
|
9
|
+
export type { ILLMProvider, LLMRequest, LLMResponse, ProviderConfig, } from "./types.js";
|
|
10
|
+
export { estimateCost, getModelPricing } from "./types.js";
|
|
11
|
+
/**
|
|
12
|
+
* Create an LLM provider instance based on provider type
|
|
13
|
+
*/
|
|
14
|
+
export declare function createLLMProvider(providerType: LlmProvider, config: ProviderConfig): ILLMProvider;
|
|
15
|
+
/**
|
|
16
|
+
* Provider endpoint hints for Type 3/4 endpoints
|
|
17
|
+
*/
|
|
18
|
+
export declare const PROVIDER_ENDPOINTS: Record<LlmProvider, string>;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/llm/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAO/D,YAAY,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE3D;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,WAAW,EACzB,MAAM,EAAE,cAAc,GACrB,YAAY,CAkDd;AAcD;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAY1D,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview LLM provider factory and exports
|
|
3
|
+
* @description Creates the appropriate LLM provider instance based on provider type.
|
|
4
|
+
* OpenAI-compatible providers (Mistral, xAI, DeepSeek, Perplexity, Cohere) reuse
|
|
5
|
+
* the OpenAIProvider class. Groq has a dedicated provider for Whisper transcription.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAIProvider } from "./openai.js";
|
|
8
|
+
import { AnthropicProvider } from "./anthropic.js";
|
|
9
|
+
import { GeminiProvider } from "./gemini.js";
|
|
10
|
+
import { GroqProvider } from "./groq.js";
|
|
11
|
+
import { CustomLLMProvider } from "./custom.js";
|
|
12
|
+
export { estimateCost, getModelPricing } from "./types.js";
|
|
13
|
+
/**
|
|
14
|
+
* Create an LLM provider instance based on provider type
|
|
15
|
+
*/
|
|
16
|
+
export function createLLMProvider(providerType, config) {
|
|
17
|
+
switch (providerType) {
|
|
18
|
+
case "openai":
|
|
19
|
+
// The only caller that is OpenAI itself: its newer models name the output
|
|
20
|
+
// cap `max_completion_tokens`, which the compatible providers do not know.
|
|
21
|
+
return new OpenAIProvider(config, { isOpenAi: true });
|
|
22
|
+
case "anthropic":
|
|
23
|
+
return new AnthropicProvider(config);
|
|
24
|
+
case "gemini":
|
|
25
|
+
return new GeminiProvider(config);
|
|
26
|
+
case "groq":
|
|
27
|
+
return new GroqProvider(config); // Groq has dedicated provider for Whisper
|
|
28
|
+
// Providers with OpenAI-compatible API format. Supply the provider's own
|
|
29
|
+
// base URL so requests don't fall through to api.openai.com.
|
|
30
|
+
case "mistral":
|
|
31
|
+
case "xai":
|
|
32
|
+
case "perplexity":
|
|
33
|
+
return new OpenAIProvider({
|
|
34
|
+
...config,
|
|
35
|
+
endpointUrl: config.endpointUrl ?? OPENAI_COMPATIBLE_BASE_URLS[providerType],
|
|
36
|
+
});
|
|
37
|
+
/*
|
|
38
|
+
DeepSeek V4 reasons by default, and thinking mode rejects `tool_choice`.
|
|
39
|
+
|
|
40
|
+
Turning thinking off restores function calling — and is the right trade
|
|
41
|
+
anyway: measured on the same two-bar plan, 844 output tokens and 8.6s
|
|
42
|
+
with thinking against 126 tokens and 2.4s without, for an answer of the
|
|
43
|
+
same size. The reasoning is discarded, so it was working the caller paid
|
|
44
|
+
for and never saw.
|
|
45
|
+
*/
|
|
46
|
+
case "deepseek":
|
|
47
|
+
return new OpenAIProvider({
|
|
48
|
+
...config,
|
|
49
|
+
endpointUrl: config.endpointUrl ?? OPENAI_COMPATIBLE_BASE_URLS[providerType],
|
|
50
|
+
}, { disableThinking: true });
|
|
51
|
+
// NOTE: Cohere's API is NOT OpenAI-compatible (different request/response
|
|
52
|
+
// shape); routing it through OpenAIProvider will not work regardless of base
|
|
53
|
+
// URL. It needs a dedicated provider — left as-is to avoid changing behavior.
|
|
54
|
+
case "cohere":
|
|
55
|
+
return new OpenAIProvider(config);
|
|
56
|
+
case "lm_studio":
|
|
57
|
+
return new CustomLLMProvider(config);
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unknown provider type: ${providerType}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* OpenAI-SDK base URLs for OpenAI-compatible providers (no /chat/completions —
|
|
64
|
+
* the SDK appends the path). Used by the factory so these providers reach their
|
|
65
|
+
* own API rather than api.openai.com.
|
|
66
|
+
*/
|
|
67
|
+
const OPENAI_COMPATIBLE_BASE_URLS = {
|
|
68
|
+
mistral: "https://api.mistral.ai/v1",
|
|
69
|
+
xai: "https://api.x.ai/v1",
|
|
70
|
+
deepseek: "https://api.deepseek.com/v1",
|
|
71
|
+
perplexity: "https://api.perplexity.ai",
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Provider endpoint hints for Type 3/4 endpoints
|
|
75
|
+
*/
|
|
76
|
+
export const PROVIDER_ENDPOINTS = {
|
|
77
|
+
openai: "https://api.openai.com/v1/chat/completions",
|
|
78
|
+
anthropic: "https://api.anthropic.com/v1/messages",
|
|
79
|
+
gemini: "https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent",
|
|
80
|
+
mistral: "https://api.mistral.ai/v1/chat/completions",
|
|
81
|
+
cohere: "https://api.cohere.ai/v1/chat",
|
|
82
|
+
groq: "https://api.groq.com/openai/v1/chat/completions",
|
|
83
|
+
xai: "https://api.x.ai/v1/chat/completions",
|
|
84
|
+
deepseek: "https://api.deepseek.com/v1/chat/completions",
|
|
85
|
+
perplexity: "https://api.perplexity.ai/chat/completions",
|
|
86
|
+
lm_studio: "{custom_endpoint}",
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/llm/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,C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AAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;QACvC;YACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,YAAY,EAAE,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,2BAA2B,GAAyC;IACxE,OAAO,EAAE,2BAA2B;IACpC,GAAG,EAAE,qBAAqB;IAC1B,QAAQ,EAAE,6BAA6B;IACvC,UAAU,EAAE,2BAA2B;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAgC;IAC7D,MAAM,EAAE,4CAA4C;IACpD,SAAS,EAAE,uCAAuC;IAClD,MAAM,EACJ,iFAAiF;IACnF,OAAO,EAAE,4CAA4C;IACrD,MAAM,EAAE,+BAA+B;IACvC,IAAI,EAAE,iDAAiD;IACvD,GAAG,EAAE,sCAAsC;IAC3C,QAAQ,EAAE,8CAA8C;IACxD,UAAU,EAAE,4CAA4C;IACxD,SAAS,EAAE,mBAAmB;CAC/B,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview OpenAI LLM provider
|
|
3
|
+
* @description Implements the ILLMProvider interface for OpenAI models.
|
|
4
|
+
* Also used by Mistral, xAI, DeepSeek, Perplexity, and Cohere
|
|
5
|
+
* (OpenAI-compatible APIs). Supports function calling for structured output,
|
|
6
|
+
* multimodal input (images, audio), and audio output generation.
|
|
7
|
+
*/
|
|
8
|
+
import { type ILLMProvider, type LLMRequest, type LLMResponse, type ProviderConfig } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* What a provider calls its cap on generated tokens.
|
|
11
|
+
*
|
|
12
|
+
* OpenAI's own newer models reject `max_tokens` outright —
|
|
13
|
+
* "Unsupported parameter: 'max_tokens' is not supported with this model. Use
|
|
14
|
+
* 'max_completion_tokens' instead" — while the OpenAI-*compatible* third
|
|
15
|
+
* parties served by this same class (DeepSeek, Mistral, xAI, Perplexity) know
|
|
16
|
+
* only `max_tokens`. One class, two vocabularies, so the caller says which.
|
|
17
|
+
*/
|
|
18
|
+
export type TokenLimitParam = "max_tokens" | "max_completion_tokens";
|
|
19
|
+
/**
|
|
20
|
+
* What to call the output cap for this provider and model.
|
|
21
|
+
*
|
|
22
|
+
* Both halves matter. The provider decides the vocabulary available; the model
|
|
23
|
+
* decides which of it applies, and the model is chosen per endpoint rather than
|
|
24
|
+
* per provider — so this cannot be settled when the client is constructed.
|
|
25
|
+
*/
|
|
26
|
+
export declare function tokenLimitParamFor(isOpenAi: boolean, model: string): TokenLimitParam;
|
|
27
|
+
export declare class OpenAIProvider implements ILLMProvider {
|
|
28
|
+
readonly providerName: "openai";
|
|
29
|
+
private client;
|
|
30
|
+
private defaultModel;
|
|
31
|
+
private disableThinking;
|
|
32
|
+
/** Whether this client talks to OpenAI itself, or an OpenAI-compatible third party. */
|
|
33
|
+
private isOpenAi;
|
|
34
|
+
constructor(config: ProviderConfig,
|
|
35
|
+
/**
|
|
36
|
+
* Per-provider quirks. Defaults keep every provider that works today
|
|
37
|
+
* working; only one known to need otherwise opts out.
|
|
38
|
+
*/
|
|
39
|
+
options?: {
|
|
40
|
+
/**
|
|
41
|
+
* Turn the model's chain of thought off.
|
|
42
|
+
*
|
|
43
|
+
* DeepSeek V4 reasons by default, and that is measurably the wrong
|
|
44
|
+
* trade here: the same two-bar plan cost 844 output tokens and 8.6s
|
|
45
|
+
* thinking, against 126 tokens and 2.4s with it off — and the reasoning
|
|
46
|
+
* is discarded, so the caller pays for working it never sees. Worse,
|
|
47
|
+
* thinking mode *rejects* `tool_choice`, so leaving it on also costs the
|
|
48
|
+
* structured-output guarantee.
|
|
49
|
+
*
|
|
50
|
+
* Sent as DeepSeek's native `thinking` object. Its type error on a
|
|
51
|
+
* boolean — "thinking: invalid type: boolean `false`, expected .." — is
|
|
52
|
+
* what identified the parameter.
|
|
53
|
+
*/
|
|
54
|
+
disableThinking?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* True for OpenAI itself. The OpenAI-compatible providers served by this
|
|
57
|
+
* same class (DeepSeek, Mistral, xAI, Perplexity, Cohere) are not, and
|
|
58
|
+
* only know `max_tokens`.
|
|
59
|
+
*/
|
|
60
|
+
isOpenAi?: boolean;
|
|
61
|
+
});
|
|
62
|
+
generate(request: LLMRequest): Promise<LLMResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Generate using the OpenAI Responses API with web search enabled.
|
|
65
|
+
* The model can search the web and then call the structured_response function.
|
|
66
|
+
*/
|
|
67
|
+
private static INPUT_LAYOUTS;
|
|
68
|
+
/** Check if a renderable tree contains input controls (clarification). */
|
|
69
|
+
private containsInputControls;
|
|
70
|
+
/**
|
|
71
|
+
* Wrap the user's output schema in a container that lets the AI signal
|
|
72
|
+
* whether it needs a web search before it can answer.
|
|
73
|
+
*/
|
|
74
|
+
private buildTriageSchema;
|
|
75
|
+
/**
|
|
76
|
+
* Build the system prompt for step 1: try to answer fully, signal
|
|
77
|
+
* web_search_needed only if real-time data is genuinely required.
|
|
78
|
+
*/
|
|
79
|
+
/**
|
|
80
|
+
* Call the Responses API with a forced function call.
|
|
81
|
+
* Used for both the triage step and the structuring step.
|
|
82
|
+
*/
|
|
83
|
+
private callResponsesStructured;
|
|
84
|
+
/**
|
|
85
|
+
* Search the web via the Responses API and return a text summary.
|
|
86
|
+
*/
|
|
87
|
+
private searchWeb;
|
|
88
|
+
/** Build Responses API input from an LLM request. */
|
|
89
|
+
private buildResponsesInput;
|
|
90
|
+
/**
|
|
91
|
+
* Main entry point when web search is enabled on the endpoint.
|
|
92
|
+
*
|
|
93
|
+
* 1. Try to answer via Responses API with triage wrapper schema.
|
|
94
|
+
* AI provides full answer OR signals web_search_needed.
|
|
95
|
+
* 2. If no search needed → return user_data directly.
|
|
96
|
+
* 3. If search needed → web search → structure results.
|
|
97
|
+
*/
|
|
98
|
+
private generateWithSearch;
|
|
99
|
+
buildApiPayload(request: LLMRequest): Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
//# source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