@intlayer/ai 7.3.0-canary.0 → 7.3.1
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 +2 -0
- package/dist/cjs/aiSdk.cjs +14 -28
- package/dist/cjs/aiSdk.cjs.map +1 -1
- package/dist/esm/aiSdk.mjs +14 -28
- package/dist/esm/aiSdk.mjs.map +1 -1
- package/dist/types/aiSdk.d.ts +6 -2
- package/dist/types/aiSdk.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
<a href="https://github.com/aymericzip/intlayer/blob/main/LICENSE" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/license/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="license"/></a>
|
|
25
25
|
<a href="https://github.com/aymericzip/intlayer/commits/main" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/last-commit/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="last commit"/>
|
|
26
26
|
</a>
|
|
27
|
+
<a href="https://bountyhub.dev/bounties?repo=intlayer" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/badge/Bounties-on%20BountyHub-yellow?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="Bounties on BountyHub"/>
|
|
28
|
+
</a>
|
|
27
29
|
</p>
|
|
28
30
|
|
|
29
31
|

|
package/dist/cjs/aiSdk.cjs
CHANGED
|
@@ -23,7 +23,7 @@ const getAPIKey = (accessType, aiOptions, isAuthenticated = false) => {
|
|
|
23
23
|
if (accessType.includes("registered_user") && isAuthenticated) return aiOptions?.apiKey ?? defaultApiKey;
|
|
24
24
|
if (accessType.includes("premium_user") && isAuthenticated) return aiOptions?.apiKey ?? defaultApiKey;
|
|
25
25
|
};
|
|
26
|
-
const
|
|
26
|
+
const getModelName = (provider, userApiKey, userModel, defaultModel = "gpt-5-mini") => {
|
|
27
27
|
if (userApiKey) {
|
|
28
28
|
if (provider && provider === AIProvider.OPENAI) return userModel ?? defaultModel;
|
|
29
29
|
switch (provider) {
|
|
@@ -37,6 +37,17 @@ const getModel = (provider, userApiKey, userModel, defaultModel = "gpt-5-mini")
|
|
|
37
37
|
if (userModel || provider) throw new Error("The user should use his own API key to use a custom model");
|
|
38
38
|
return defaultModel;
|
|
39
39
|
};
|
|
40
|
+
const getLanguageModel = (aiOptions, apiKey, defaultModel) => {
|
|
41
|
+
const selectedModel = getModelName(aiOptions.provider, apiKey, aiOptions.model, defaultModel);
|
|
42
|
+
switch (aiOptions.provider) {
|
|
43
|
+
case AIProvider.OPENAI: return (0, __ai_sdk_openai.createOpenAI)({ apiKey })(selectedModel);
|
|
44
|
+
case AIProvider.ANTHROPIC: return (0, __ai_sdk_anthropic.createAnthropic)({ apiKey })(selectedModel);
|
|
45
|
+
case AIProvider.MISTRAL: return (0, __ai_sdk_mistral.createMistral)({ apiKey })(selectedModel);
|
|
46
|
+
case AIProvider.DEEPSEEK: return (0, __ai_sdk_deepseek.createDeepSeek)({ apiKey })(selectedModel);
|
|
47
|
+
case AIProvider.GEMINI: return (0, __ai_sdk_google.createGoogleGenerativeAI)({ apiKey })(selectedModel);
|
|
48
|
+
default: throw new Error(`Provider ${aiOptions.provider} not supported`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
40
51
|
const DEFAULT_PROVIDER = AIProvider.OPENAI;
|
|
41
52
|
const DEFAULT_TEMPERATURE = 1;
|
|
42
53
|
/**
|
|
@@ -56,34 +67,9 @@ const getAIConfig = async (options, isAuthenticated = false) => {
|
|
|
56
67
|
};
|
|
57
68
|
const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);
|
|
58
69
|
if (!apiKey) throw new Error(`API key for ${aiOptions.provider} is missing`);
|
|
59
|
-
const selectedModel = getModel(aiOptions.provider, apiKey, aiOptions.model, defaultOptions?.model);
|
|
60
|
-
const protectedOptions = {
|
|
61
|
-
...aiOptions,
|
|
62
|
-
apiKey,
|
|
63
|
-
model: selectedModel
|
|
64
|
-
};
|
|
65
|
-
let languageModel;
|
|
66
|
-
switch (protectedOptions.provider) {
|
|
67
|
-
case AIProvider.OPENAI:
|
|
68
|
-
languageModel = (0, __ai_sdk_openai.createOpenAI)({ apiKey })(selectedModel);
|
|
69
|
-
break;
|
|
70
|
-
case AIProvider.ANTHROPIC:
|
|
71
|
-
languageModel = (0, __ai_sdk_anthropic.createAnthropic)({ apiKey })(selectedModel);
|
|
72
|
-
break;
|
|
73
|
-
case AIProvider.MISTRAL:
|
|
74
|
-
languageModel = (0, __ai_sdk_mistral.createMistral)({ apiKey })(selectedModel);
|
|
75
|
-
break;
|
|
76
|
-
case AIProvider.DEEPSEEK:
|
|
77
|
-
languageModel = (0, __ai_sdk_deepseek.createDeepSeek)({ apiKey })(selectedModel);
|
|
78
|
-
break;
|
|
79
|
-
case AIProvider.GEMINI:
|
|
80
|
-
languageModel = (0, __ai_sdk_google.createGoogleGenerativeAI)({ apiKey })(selectedModel);
|
|
81
|
-
break;
|
|
82
|
-
default: throw new Error(`Provider ${protectedOptions.provider} not supported`);
|
|
83
|
-
}
|
|
84
70
|
return {
|
|
85
|
-
model:
|
|
86
|
-
temperature:
|
|
71
|
+
model: getLanguageModel(aiOptions, apiKey, defaultOptions?.model),
|
|
72
|
+
temperature: aiOptions.temperature
|
|
87
73
|
};
|
|
88
74
|
};
|
|
89
75
|
|
package/dist/cjs/aiSdk.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSdk.cjs","names":["DEFAULT_PROVIDER: AIProvider","DEFAULT_TEMPERATURE: number"
|
|
1
|
+
{"version":3,"file":"aiSdk.cjs","names":["DEFAULT_PROVIDER: AIProvider","DEFAULT_TEMPERATURE: number"],"sources":["../../src/aiSdk.ts"],"sourcesContent":["import { type anthropic, createAnthropic } from '@ai-sdk/anthropic';\nimport { createDeepSeek, type deepseek } from '@ai-sdk/deepseek';\nimport { createGoogleGenerativeAI, type google } from '@ai-sdk/google';\nimport { createMistral, type mistral } from '@ai-sdk/mistral';\nimport { createOpenAI, type openai } from '@ai-sdk/openai';\nimport type {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\n\ntype AnthropicModel = Parameters<typeof anthropic>[0];\ntype DeepSeekModel = Parameters<typeof deepseek>[0];\ntype MistralModel = Parameters<typeof mistral>[0];\ntype OpenAIModel = Parameters<typeof openai>[0];\ntype GoogleModel = Parameters<typeof google>[0];\n\nexport type Messages = (\n | SystemModelMessage\n | UserModelMessage\n | AssistantModelMessage\n | ToolModelMessage\n)[];\n\n/**\n * Supported AI models\n */\nexport type Model =\n | AnthropicModel\n | DeepSeekModel\n | MistralModel\n | OpenAIModel\n | GoogleModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\nexport enum AIProvider {\n OPENAI = 'openai',\n ANTHROPIC = 'anthropic',\n MISTRAL = 'mistral',\n DEEPSEEK = 'deepseek',\n GEMINI = 'gemini',\n}\n\nexport type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'none';\n\n/**\n * Common options for all AI providers\n */\nexport type AIOptions = {\n provider?: AIProvider;\n model?: Model;\n temperature?: number;\n apiKey?: string;\n applicationContext?: string;\n};\n\n// Define the structure of messages used in chat completions\nexport type ChatCompletionRequestMessage = {\n role: 'system' | 'user' | 'assistant'; // The role of the message sender\n content: string; // The text content of the message\n timestamp?: Date; // The timestamp of the message\n};\n\ntype AccessType = 'apiKey' | 'registered_user' | 'premium_user' | 'public';\n\nconst getAPIKey = (\n accessType: AccessType[],\n aiOptions?: AIOptions,\n isAuthenticated: boolean = false\n) => {\n const defaultApiKey = process.env.OPENAI_API_KEY;\n\n if (accessType.includes('public')) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n if (accessType.includes('apiKey') && aiOptions?.apiKey) {\n return aiOptions?.apiKey;\n }\n\n if (accessType.includes('registered_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n return undefined;\n};\n\nconst getModelName = (\n provider: AIProvider,\n userApiKey: string,\n userModel?: Model,\n defaultModel: Model = 'gpt-5-mini'\n): Model => {\n // If the user uses their own API key, allow custom model selection\n if (userApiKey) {\n if (provider && provider === AIProvider.OPENAI) {\n return userModel ?? defaultModel;\n }\n\n switch (provider) {\n case AIProvider.ANTHROPIC:\n return 'claude-sonnet-4-5-20250929';\n case AIProvider.MISTRAL:\n return 'mistral-large-latest';\n case AIProvider.DEEPSEEK:\n return 'deepseek-coder';\n case AIProvider.GEMINI:\n return 'gemini-2.5-flash';\n default:\n return defaultModel;\n }\n }\n\n // Guard: Prevent custom model usage without a user API key\n if (userModel || provider) {\n throw new Error(\n 'The user should use his own API key to use a custom model'\n );\n }\n\n return defaultModel;\n};\n\nconst getLanguageModel = (\n aiOptions: AIOptions,\n apiKey: string,\n defaultModel?: Model\n) => {\n const selectedModel = getModelName(\n aiOptions.provider as AIProvider,\n apiKey,\n aiOptions.model,\n defaultModel\n );\n\n switch (aiOptions.provider) {\n case AIProvider.OPENAI: {\n return createOpenAI({\n apiKey,\n })(selectedModel);\n }\n\n case AIProvider.ANTHROPIC: {\n return createAnthropic({\n apiKey,\n })(selectedModel);\n }\n\n case AIProvider.MISTRAL: {\n return createMistral({\n apiKey,\n })(selectedModel);\n }\n\n case AIProvider.DEEPSEEK: {\n return createDeepSeek({\n apiKey,\n })(selectedModel);\n }\n\n case AIProvider.GEMINI: {\n return createGoogleGenerativeAI({\n apiKey,\n })(selectedModel);\n }\n\n default: {\n throw new Error(`Provider ${aiOptions.provider} not supported`);\n }\n }\n};\n\nexport type AIConfig = Omit<Parameters<typeof generateText>[0], 'prompt'> & {\n reasoningEffort?: ReasoningEffort;\n textVerbosity?: 'low' | 'medium' | 'high';\n};\n\nconst DEFAULT_PROVIDER: AIProvider = AIProvider.OPENAI as AIProvider;\nconst DEFAULT_TEMPERATURE: number = 1; // ChatGPT 5 accept only temperature 1\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Get AI model configuration based on the selected provider and options\n * This function handles the configuration for different AI providers\n *\n * @param options Configuration options including provider, API keys, models and temperature\n * @returns Configured AI model ready to use with generateText\n */\nexport const getAIConfig = async (\n options: AIConfigOptions,\n isAuthenticated: boolean = false\n): Promise<AIConfig> => {\n const {\n userOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const aiOptions = {\n provider: DEFAULT_PROVIDER,\n temperature: DEFAULT_TEMPERATURE,\n ...defaultOptions,\n ...userOptions,\n } satisfies AIOptions;\n\n const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);\n\n // Check if API key is provided\n if (!apiKey) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const languageModel = getLanguageModel(\n aiOptions,\n apiKey,\n defaultOptions?.model\n );\n\n return {\n model: languageModel,\n temperature: aiOptions.temperature,\n };\n};\n"],"mappings":";;;;;;;;;;AAwCA,IAAY,oDAAL;AACL;AACA;AACA;AACA;AACA;;;AAyBF,MAAM,aACJ,YACA,WACA,kBAA2B,UACxB;CACH,MAAM,gBAAgB,QAAQ,IAAI;AAElC,KAAI,WAAW,SAAS,SAAS,CAC/B,QAAO,WAAW,UAAU;AAG9B,KAAI,WAAW,SAAS,SAAS,IAAI,WAAW,OAC9C,QAAO,WAAW;AAGpB,KAAI,WAAW,SAAS,kBAAkB,IAAI,gBAC5C,QAAO,WAAW,UAAU;AAI9B,KAAI,WAAW,SAAS,eAAe,IAAI,gBACzC,QAAO,WAAW,UAAU;;AAMhC,MAAM,gBACJ,UACA,YACA,WACA,eAAsB,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 const getAPIKey = (accessType, aiOptions, isAuthenticated = false) => {
|
|
|
23
23
|
if (accessType.includes("registered_user") && isAuthenticated) return aiOptions?.apiKey ?? defaultApiKey;
|
|
24
24
|
if (accessType.includes("premium_user") && isAuthenticated) return aiOptions?.apiKey ?? defaultApiKey;
|
|
25
25
|
};
|
|
26
|
-
const
|
|
26
|
+
const getModelName = (provider, userApiKey, userModel, defaultModel = "gpt-5-mini") => {
|
|
27
27
|
if (userApiKey) {
|
|
28
28
|
if (provider && provider === AIProvider.OPENAI) return userModel ?? defaultModel;
|
|
29
29
|
switch (provider) {
|
|
@@ -37,6 +37,17 @@ const getModel = (provider, userApiKey, userModel, defaultModel = "gpt-5-mini")
|
|
|
37
37
|
if (userModel || provider) throw new Error("The user should use his own API key to use a custom model");
|
|
38
38
|
return defaultModel;
|
|
39
39
|
};
|
|
40
|
+
const getLanguageModel = (aiOptions, apiKey, defaultModel) => {
|
|
41
|
+
const selectedModel = getModelName(aiOptions.provider, apiKey, aiOptions.model, defaultModel);
|
|
42
|
+
switch (aiOptions.provider) {
|
|
43
|
+
case AIProvider.OPENAI: return createOpenAI({ apiKey })(selectedModel);
|
|
44
|
+
case AIProvider.ANTHROPIC: return createAnthropic({ apiKey })(selectedModel);
|
|
45
|
+
case AIProvider.MISTRAL: return createMistral({ apiKey })(selectedModel);
|
|
46
|
+
case AIProvider.DEEPSEEK: return createDeepSeek({ apiKey })(selectedModel);
|
|
47
|
+
case AIProvider.GEMINI: return createGoogleGenerativeAI({ apiKey })(selectedModel);
|
|
48
|
+
default: throw new Error(`Provider ${aiOptions.provider} not supported`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
40
51
|
const DEFAULT_PROVIDER = AIProvider.OPENAI;
|
|
41
52
|
const DEFAULT_TEMPERATURE = 1;
|
|
42
53
|
/**
|
|
@@ -56,34 +67,9 @@ const getAIConfig = async (options, isAuthenticated = false) => {
|
|
|
56
67
|
};
|
|
57
68
|
const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);
|
|
58
69
|
if (!apiKey) throw new Error(`API key for ${aiOptions.provider} is missing`);
|
|
59
|
-
const selectedModel = getModel(aiOptions.provider, apiKey, aiOptions.model, defaultOptions?.model);
|
|
60
|
-
const protectedOptions = {
|
|
61
|
-
...aiOptions,
|
|
62
|
-
apiKey,
|
|
63
|
-
model: selectedModel
|
|
64
|
-
};
|
|
65
|
-
let languageModel;
|
|
66
|
-
switch (protectedOptions.provider) {
|
|
67
|
-
case AIProvider.OPENAI:
|
|
68
|
-
languageModel = createOpenAI({ apiKey })(selectedModel);
|
|
69
|
-
break;
|
|
70
|
-
case AIProvider.ANTHROPIC:
|
|
71
|
-
languageModel = createAnthropic({ apiKey })(selectedModel);
|
|
72
|
-
break;
|
|
73
|
-
case AIProvider.MISTRAL:
|
|
74
|
-
languageModel = createMistral({ apiKey })(selectedModel);
|
|
75
|
-
break;
|
|
76
|
-
case AIProvider.DEEPSEEK:
|
|
77
|
-
languageModel = createDeepSeek({ apiKey })(selectedModel);
|
|
78
|
-
break;
|
|
79
|
-
case AIProvider.GEMINI:
|
|
80
|
-
languageModel = createGoogleGenerativeAI({ apiKey })(selectedModel);
|
|
81
|
-
break;
|
|
82
|
-
default: throw new Error(`Provider ${protectedOptions.provider} not supported`);
|
|
83
|
-
}
|
|
84
70
|
return {
|
|
85
|
-
model:
|
|
86
|
-
temperature:
|
|
71
|
+
model: getLanguageModel(aiOptions, apiKey, defaultOptions?.model),
|
|
72
|
+
temperature: aiOptions.temperature
|
|
87
73
|
};
|
|
88
74
|
};
|
|
89
75
|
|
package/dist/esm/aiSdk.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSdk.mjs","names":["DEFAULT_PROVIDER: AIProvider","DEFAULT_TEMPERATURE: number"
|
|
1
|
+
{"version":3,"file":"aiSdk.mjs","names":["DEFAULT_PROVIDER: AIProvider","DEFAULT_TEMPERATURE: number"],"sources":["../../src/aiSdk.ts"],"sourcesContent":["import { type anthropic, createAnthropic } from '@ai-sdk/anthropic';\nimport { createDeepSeek, type deepseek } from '@ai-sdk/deepseek';\nimport { createGoogleGenerativeAI, type google } from '@ai-sdk/google';\nimport { createMistral, type mistral } from '@ai-sdk/mistral';\nimport { createOpenAI, type openai } from '@ai-sdk/openai';\nimport type {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\n\ntype AnthropicModel = Parameters<typeof anthropic>[0];\ntype DeepSeekModel = Parameters<typeof deepseek>[0];\ntype MistralModel = Parameters<typeof mistral>[0];\ntype OpenAIModel = Parameters<typeof openai>[0];\ntype GoogleModel = Parameters<typeof google>[0];\n\nexport type Messages = (\n | SystemModelMessage\n | UserModelMessage\n | AssistantModelMessage\n | ToolModelMessage\n)[];\n\n/**\n * Supported AI models\n */\nexport type Model =\n | AnthropicModel\n | DeepSeekModel\n | MistralModel\n | OpenAIModel\n | GoogleModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\nexport enum AIProvider {\n OPENAI = 'openai',\n ANTHROPIC = 'anthropic',\n MISTRAL = 'mistral',\n DEEPSEEK = 'deepseek',\n GEMINI = 'gemini',\n}\n\nexport type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'none';\n\n/**\n * Common options for all AI providers\n */\nexport type AIOptions = {\n provider?: AIProvider;\n model?: Model;\n temperature?: number;\n apiKey?: string;\n applicationContext?: string;\n};\n\n// Define the structure of messages used in chat completions\nexport type ChatCompletionRequestMessage = {\n role: 'system' | 'user' | 'assistant'; // The role of the message sender\n content: string; // The text content of the message\n timestamp?: Date; // The timestamp of the message\n};\n\ntype AccessType = 'apiKey' | 'registered_user' | 'premium_user' | 'public';\n\nconst getAPIKey = (\n accessType: AccessType[],\n aiOptions?: AIOptions,\n isAuthenticated: boolean = false\n) => {\n const defaultApiKey = process.env.OPENAI_API_KEY;\n\n if (accessType.includes('public')) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n if (accessType.includes('apiKey') && aiOptions?.apiKey) {\n return aiOptions?.apiKey;\n }\n\n if (accessType.includes('registered_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n return undefined;\n};\n\nconst getModelName = (\n provider: AIProvider,\n userApiKey: string,\n userModel?: Model,\n defaultModel: Model = 'gpt-5-mini'\n): Model => {\n // If the user uses their own API key, allow custom model selection\n if (userApiKey) {\n if (provider && provider === AIProvider.OPENAI) {\n return userModel ?? defaultModel;\n }\n\n switch (provider) {\n case AIProvider.ANTHROPIC:\n return 'claude-sonnet-4-5-20250929';\n case AIProvider.MISTRAL:\n return 'mistral-large-latest';\n case AIProvider.DEEPSEEK:\n return 'deepseek-coder';\n case AIProvider.GEMINI:\n return 'gemini-2.5-flash';\n default:\n return defaultModel;\n }\n }\n\n // Guard: Prevent custom model usage without a user API key\n if (userModel || provider) {\n throw new Error(\n 'The user should use his own API key to use a custom model'\n );\n }\n\n return defaultModel;\n};\n\nconst getLanguageModel = (\n aiOptions: AIOptions,\n apiKey: string,\n defaultModel?: Model\n) => {\n const selectedModel = getModelName(\n aiOptions.provider as AIProvider,\n apiKey,\n aiOptions.model,\n defaultModel\n );\n\n switch (aiOptions.provider) {\n case AIProvider.OPENAI: {\n return createOpenAI({\n apiKey,\n })(selectedModel);\n }\n\n case AIProvider.ANTHROPIC: {\n return createAnthropic({\n apiKey,\n })(selectedModel);\n }\n\n case AIProvider.MISTRAL: {\n return createMistral({\n apiKey,\n })(selectedModel);\n }\n\n case AIProvider.DEEPSEEK: {\n return createDeepSeek({\n apiKey,\n })(selectedModel);\n }\n\n case AIProvider.GEMINI: {\n return createGoogleGenerativeAI({\n apiKey,\n })(selectedModel);\n }\n\n default: {\n throw new Error(`Provider ${aiOptions.provider} not supported`);\n }\n }\n};\n\nexport type AIConfig = Omit<Parameters<typeof generateText>[0], 'prompt'> & {\n reasoningEffort?: ReasoningEffort;\n textVerbosity?: 'low' | 'medium' | 'high';\n};\n\nconst DEFAULT_PROVIDER: AIProvider = AIProvider.OPENAI as AIProvider;\nconst DEFAULT_TEMPERATURE: number = 1; // ChatGPT 5 accept only temperature 1\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Get AI model configuration based on the selected provider and options\n * This function handles the configuration for different AI providers\n *\n * @param options Configuration options including provider, API keys, models and temperature\n * @returns Configured AI model ready to use with generateText\n */\nexport const getAIConfig = async (\n options: AIConfigOptions,\n isAuthenticated: boolean = false\n): Promise<AIConfig> => {\n const {\n userOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const aiOptions = {\n provider: DEFAULT_PROVIDER,\n temperature: DEFAULT_TEMPERATURE,\n ...defaultOptions,\n ...userOptions,\n } satisfies AIOptions;\n\n const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);\n\n // Check if API key is provided\n if (!apiKey) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const languageModel = getLanguageModel(\n aiOptions,\n apiKey,\n defaultOptions?.model\n );\n\n return {\n model: languageModel,\n temperature: aiOptions.temperature,\n };\n};\n"],"mappings":";;;;;;;;;;AAwCA,IAAY,oDAAL;AACL;AACA;AACA;AACA;AACA;;;AAyBF,MAAM,aACJ,YACA,WACA,kBAA2B,UACxB;CACH,MAAM,gBAAgB,QAAQ,IAAI;AAElC,KAAI,WAAW,SAAS,SAAS,CAC/B,QAAO,WAAW,UAAU;AAG9B,KAAI,WAAW,SAAS,SAAS,IAAI,WAAW,OAC9C,QAAO,WAAW;AAGpB,KAAI,WAAW,SAAS,kBAAkB,IAAI,gBAC5C,QAAO,WAAW,UAAU;AAI9B,KAAI,WAAW,SAAS,eAAe,IAAI,gBACzC,QAAO,WAAW,UAAU;;AAMhC,MAAM,gBACJ,UACA,YACA,WACA,eAAsB,iBACZ;AAEV,K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+26,7 @@ declare enum AIProvider {
|
|
|
26
26
|
DEEPSEEK = "deepseek",
|
|
27
27
|
GEMINI = "gemini",
|
|
28
28
|
}
|
|
29
|
+
type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'none';
|
|
29
30
|
/**
|
|
30
31
|
* Common options for all AI providers
|
|
31
32
|
*/
|
|
@@ -42,7 +43,10 @@ type ChatCompletionRequestMessage = {
|
|
|
42
43
|
timestamp?: Date;
|
|
43
44
|
};
|
|
44
45
|
type AccessType = 'apiKey' | 'registered_user' | 'premium_user' | 'public';
|
|
45
|
-
type AIConfig = Omit<Parameters<typeof generateText>[0], 'prompt'
|
|
46
|
+
type AIConfig = Omit<Parameters<typeof generateText>[0], 'prompt'> & {
|
|
47
|
+
reasoningEffort?: ReasoningEffort;
|
|
48
|
+
textVerbosity?: 'low' | 'medium' | 'high';
|
|
49
|
+
};
|
|
46
50
|
type AIConfigOptions = {
|
|
47
51
|
userOptions?: AIOptions;
|
|
48
52
|
defaultOptions?: AIOptions;
|
|
@@ -57,5 +61,5 @@ type AIConfigOptions = {
|
|
|
57
61
|
*/
|
|
58
62
|
declare const getAIConfig: (options: AIConfigOptions, isAuthenticated?: boolean) => Promise<AIConfig>;
|
|
59
63
|
//#endregion
|
|
60
|
-
export { AIConfig, AIConfigOptions, AIOptions, AIProvider, ChatCompletionRequestMessage, Messages, Model, getAIConfig };
|
|
64
|
+
export { AIConfig, AIConfigOptions, AIOptions, AIProvider, ChatCompletionRequestMessage, Messages, Model, ReasoningEffort, getAIConfig };
|
|
61
65
|
//# sourceMappingURL=aiSdk.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSdk.d.ts","names":[],"sources":["../../src/aiSdk.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAaK,cAAA,GAAiB,kBAAkB;KACnC,aAAA,GAAgB,kBAAkB;AAH3B,KAIP,YAAA,GAAe,UAFD,CAAA,OAEmB,OAFhB,CAAA,CAAA,CAAA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A,UAAA;EACA,MAAA,GAAA,QAAA;;AAMQ,KAQA,eAAA,GARU,SAAA,GAAA,KAAA,GAAA,QAAA,GAAA,MAAA,GAAA,MAAA;AAQtB;AAKA;AASA;AAMK,KAfO,SAAA,GAeG;EAkHH,QAAA,CAAA,EAhIC,UAgIO;EAA0B,KAAA,CAAA,EA/HpC,KA+HoC;EAAlB,WAAA,CAAA,EAAA,MAAA;EAAL,MAAA,CAAA,EAAA,MAAA;EACH,kBAAA,CAAA,EAAA,MAAA;CAAe;AAOvB,KAhIA,4BAAA,GAgIe;EACX,IAAA,EAAA,QAAA,GAAA,MAAA,GAAA,WAAA;EACG,OAAA,EAAA,MAAA;EACJ,SAAA,CAAA,EAhID,IAgIC;CAAU;AAUzB,KAvIK,UAAA,GAyKJ,QAAA,GAAA,iBAAA,GAAA,cAAA,GAAA,QAAA;AAjCU,KAtBC,QAAA,GAAW,IAsBZ,CAtBiB,UAsBjB,CAAA,OAtBmC,YAsBnC,CAAA,CAAA,CAAA,CAAA,EAAA,QAAA,CAAA,GAAA;EAEA,eAAA,CAAA,EAvBS,eAuBT;EAAR,aAAA,CAAA,EAAA,KAAA,GAAA,QAAA,GAAA,MAAA;CAAO;KAhBE,eAAA;gBACI;mBACG;eACJ;;;;;;;;;cAUF,uBACF,+CAER,QAAQ"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AIConfig, AIConfigOptions, AIOptions, AIProvider, ChatCompletionRequestMessage, Messages, Model, getAIConfig } from "./aiSdk.js";
|
|
1
|
+
import { AIConfig, AIConfigOptions, AIOptions, AIProvider, ChatCompletionRequestMessage, Messages, Model, ReasoningEffort, getAIConfig } from "./aiSdk.js";
|
|
2
2
|
import { AuditDictionaryMetadataOptions, AuditFileResultData, auditDictionaryMetadata } from "./auditDictionaryMetadata/index.js";
|
|
3
3
|
import { CustomQueryOptions, CustomQueryResultData, customQuery } from "./customQuery.js";
|
|
4
4
|
import { TranslateJSONOptions, TranslateJSONResultData, translateJSON } from "./translateJSON/index.js";
|
|
5
5
|
import { extractJson } from "./utils/extractJSON.js";
|
|
6
6
|
import { generateText, streamText } from "ai";
|
|
7
|
-
export { AIConfig, AIConfigOptions, AIOptions, AIProvider, type AuditDictionaryMetadataOptions, type AuditFileResultData, ChatCompletionRequestMessage, type CustomQueryOptions, type CustomQueryResultData, Messages, Model, type TranslateJSONOptions, type TranslateJSONResultData, auditDictionaryMetadata, customQuery, extractJson, generateText, getAIConfig, streamText, translateJSON };
|
|
7
|
+
export { AIConfig, AIConfigOptions, AIOptions, AIProvider, type AuditDictionaryMetadataOptions, type AuditFileResultData, ChatCompletionRequestMessage, type CustomQueryOptions, type CustomQueryResultData, Messages, Model, ReasoningEffort, type TranslateJSONOptions, type TranslateJSONResultData, auditDictionaryMetadata, customQuery, extractJson, generateText, getAIConfig, streamText, translateJSON };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/ai",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "SDK that provides AI capabilities for Intlayer applications",
|
|
6
6
|
"keywords": [
|
|
@@ -77,10 +77,10 @@
|
|
|
77
77
|
"@ai-sdk/google": "2.0.40",
|
|
78
78
|
"@ai-sdk/mistral": "2.0.24",
|
|
79
79
|
"@ai-sdk/openai": "2.0.71",
|
|
80
|
-
"@intlayer/api": "7.3.
|
|
81
|
-
"@intlayer/config": "7.3.
|
|
82
|
-
"@intlayer/core": "7.3.
|
|
83
|
-
"@intlayer/types": "7.3.
|
|
80
|
+
"@intlayer/api": "7.3.1",
|
|
81
|
+
"@intlayer/config": "7.3.1",
|
|
82
|
+
"@intlayer/core": "7.3.1",
|
|
83
|
+
"@intlayer/types": "7.3.1",
|
|
84
84
|
"ai": "5.0.98"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|