@intlayer/ai 9.7.0 → 9.7.2
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/cjs/_virtual/_rolldown/runtime.cjs +1 -2
- package/dist/cjs/_virtual/_utils_asset.cjs +1 -2
- package/dist/cjs/aiSdk.cjs +10 -6
- package/dist/cjs/aiSdk.cjs.map +1 -1
- package/dist/cjs/auditDictionaryMetadata/index.cjs +2 -3
- package/dist/cjs/auditDictionaryMetadata/index.cjs.map +1 -1
- package/dist/cjs/customQuery.cjs +2 -3
- package/dist/cjs/customQuery.cjs.map +1 -1
- package/dist/cjs/index.cjs +16 -11
- package/dist/cjs/translateJSON/index.cjs +4 -5
- package/dist/cjs/translateJSON/index.cjs.map +1 -1
- package/dist/cjs/utils/extractJSON.cjs +1 -2
- package/dist/esm/_virtual/_utils_asset.mjs +1 -2
- package/dist/esm/aiSdk.mjs +3 -4
- package/dist/esm/aiSdk.mjs.map +1 -1
- package/dist/esm/auditDictionaryMetadata/index.mjs +1 -2
- package/dist/esm/auditDictionaryMetadata/index.mjs.map +1 -1
- package/dist/esm/customQuery.mjs +2 -3
- package/dist/esm/customQuery.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/translateJSON/index.mjs +3 -4
- package/dist/esm/translateJSON/index.mjs.map +1 -1
- package/dist/esm/utils/extractJSON.mjs +1 -2
- package/dist/types/aiSdk.d.ts +0 -2
- package/dist/types/aiSdk.d.ts.map +1 -1
- package/dist/types/auditDictionaryMetadata/index.d.ts +1 -2
- package/dist/types/auditDictionaryMetadata/index.d.ts.map +1 -1
- package/dist/types/customQuery.d.ts +0 -2
- package/dist/types/customQuery.d.ts.map +1 -1
- package/dist/types/translateJSON/index.d.ts +1 -2
- package/dist/types/translateJSON/index.d.ts.map +1 -1
- package/dist/types/utils/extractJSON.d.ts +0 -2
- package/dist/types/utils/extractJSON.d.ts.map +1 -1
- package/package.json +36 -36
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -24,5 +24,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
|
|
27
|
-
//#endregion
|
|
28
27
|
exports.__toESM = __toESM;
|
|
@@ -2,7 +2,7 @@ let node_fs = require("node:fs");
|
|
|
2
2
|
let node_path = require("node:path");
|
|
3
3
|
let node_url = require("node:url");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// \0utils:asset
|
|
6
6
|
const hereDirname = () => {
|
|
7
7
|
try {
|
|
8
8
|
return (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
@@ -96,5 +96,4 @@ const readAsset = (relPath, encoding = "utf8") => {
|
|
|
96
96
|
throw new Error(msg);
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
//#endregion
|
|
100
99
|
exports.readAsset = readAsset;
|
package/dist/cjs/aiSdk.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require(
|
|
3
|
-
let ai = require("ai");
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
4
3
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
5
4
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
6
5
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
7
6
|
let _intlayer_types_config = require("@intlayer/types/config");
|
|
7
|
+
let ai = require("ai");
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// src/aiSdk.ts
|
|
10
10
|
const DEFAULT_PROVIDER = _intlayer_types_config.AiProviders.ANTHROPIC;
|
|
11
|
-
const DEFAULT_MODEL = "claude-haiku-
|
|
11
|
+
const DEFAULT_MODEL = "claude-haiku-5-5";
|
|
12
12
|
const DEFAULT_API_KEY = process.env.ANTHROPIC_API_KEY;
|
|
13
13
|
const isMaskedKey = (key) => !!key?.includes("*");
|
|
14
14
|
const getAPIKey = (accessType, aiOptions, isAuthenticated = false) => {
|
|
@@ -249,8 +249,12 @@ const getAIConfig = async (options, isAuthenticated = false) => {
|
|
|
249
249
|
};
|
|
250
250
|
};
|
|
251
251
|
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
Object.defineProperty(exports, "AIProvider", {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
get: function () {
|
|
255
|
+
return _intlayer_types_config.AiProviders;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
254
258
|
exports.checkAISDKAccess = checkAISDKAccess;
|
|
255
259
|
exports.getAIConfig = getAIConfig;
|
|
256
260
|
//# sourceMappingURL=aiSdk.cjs.map
|
package/dist/cjs/aiSdk.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSdk.cjs","names":["AiProviders","x","colorize","ANSIColors","generateTextFn"],"sources":["../../src/aiSdk.ts"],"sourcesContent":["import type { AlibabaProvider, createAlibaba } from '@ai-sdk/alibaba';\nimport type {\n AmazonBedrockProvider,\n createAmazonBedrock,\n} from '@ai-sdk/amazon-bedrock';\nimport type { AnthropicProvider, createAnthropic } from '@ai-sdk/anthropic';\nimport type { createDeepSeek, DeepSeekProvider } from '@ai-sdk/deepseek';\nimport type { createFireworks, FireworksProvider } from '@ai-sdk/fireworks';\nimport type {\n createGoogleGenerativeAI,\n GoogleGenerativeAIProvider,\n} from '@ai-sdk/google';\nimport type {\n createVertex,\n GoogleVertexProvider as VertexProvider,\n} from '@ai-sdk/google-vertex';\nimport type { createGroq, GroqProvider } from '@ai-sdk/groq';\nimport type {\n createHuggingFace,\n HuggingFaceProvider,\n} from '@ai-sdk/huggingface';\nimport type { createMistral, MistralProvider } from '@ai-sdk/mistral';\nimport type { createMoonshotAI, MoonshotAIProvider } from '@ai-sdk/moonshotai';\nimport type { createOpenAI, OpenAIProvider } from '@ai-sdk/openai';\nimport type {\n createOpenAICompatible,\n OpenAICompatibleProvider,\n} from '@ai-sdk/openai-compatible';\nimport type { createTogetherAI, TogetherAIProvider } from '@ai-sdk/togetherai';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, logger, x } from '@intlayer/config/logger';\nimport { AiProviders } from '@intlayer/types/config';\nimport type {\n createOpenRouter,\n OpenRouterProvider,\n} from '@openrouter/ai-sdk-provider';\nimport type {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\nimport { generateText as generateTextFn } from 'ai';\n\nconst DEFAULT_PROVIDER = AiProviders.ANTHROPIC;\nconst DEFAULT_MODEL = 'claude-haiku-4-5';\nconst DEFAULT_API_KEY = process.env.ANTHROPIC_API_KEY;\n\nexport { AiProviders as AIProvider };\n\ntype AnthropicModel = Parameters<AnthropicProvider>[0];\ntype DeepSeekModel = Parameters<DeepSeekProvider>[0];\ntype MistralModel = Parameters<MistralProvider>[0];\ntype OpenAIModel = Parameters<OpenAIProvider>[0];\ntype OpenRouterModel = Parameters<OpenRouterProvider>[0];\ntype GoogleModel = Parameters<GoogleGenerativeAIProvider>[0];\ntype VertexModel = Parameters<VertexProvider>[0];\ntype AlibabaModel = Parameters<AlibabaProvider>[0];\ntype AmazonBedrockModel = Parameters<AmazonBedrockProvider>[0];\ntype FireworksModel = Parameters<FireworksProvider>[0];\ntype GroqModel = Parameters<GroqProvider>[0];\ntype HuggingFaceModel = Parameters<HuggingFaceProvider>[0];\ntype TogetherAIModel = Parameters<TogetherAIProvider>[0];\ntype LMStudioModel = Parameters<OpenAICompatibleProvider>[0];\ntype MoonshotAIModel = Parameters<MoonshotAIProvider>[0];\n\nexport type OpenAIProviderOptions = Parameters<typeof createOpenAI>[0];\nexport type AnthropicProviderOptions = Parameters<typeof createAnthropic>[0];\nexport type MistralProviderOptions = Parameters<typeof createMistral>[0];\nexport type DeepSeekProviderOptions = Parameters<typeof createDeepSeek>[0];\nexport type GoogleProviderOptions = Parameters<\n typeof createGoogleGenerativeAI\n>[0];\nexport type VertexProviderOptions = Parameters<typeof createVertex>[0];\nexport type OpenRouterProviderOptions = Parameters<typeof createOpenRouter>[0];\nexport type AlibabaProviderOptions = Parameters<typeof createAlibaba>[0];\nexport type FireworksProviderOptions = Parameters<typeof createFireworks>[0];\nexport type GroqProviderOptions = Parameters<typeof createGroq>[0];\nexport type HuggingFaceProviderOptions = Parameters<\n typeof createHuggingFace\n>[0];\nexport type AmazonBedrockProviderOptions = Parameters<\n typeof createAmazonBedrock\n>[0];\nexport type TogetherAIProviderOptions = Parameters<typeof createTogetherAI>[0];\nexport type LMStudioProviderOptions = Parameters<\n typeof createOpenAICompatible\n>[0];\nexport type MoonshotAIProviderOptions = Parameters<typeof createMoonshotAI>[0];\n\nexport type SystemMessage =\n | string\n | SystemModelMessage\n | SystemModelMessage[]\n | undefined;\n\nexport type Messages = (\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 | OpenRouterModel\n | GoogleModel\n | VertexModel\n | AlibabaModel\n | AmazonBedrockModel\n | FireworksModel\n | GroqModel\n | HuggingFaceModel\n | TogetherAIModel\n | LMStudioModel\n | MoonshotAIModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\n\nexport type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'none';\n\n/**\n * Common options for all AI providers\n */\ntype CommonAIOptions = {\n model?: Model;\n temperature?: number;\n baseURL?: string;\n apiKey?: string;\n applicationContext?: string;\n dataSerialization?: 'json' | 'toon';\n};\n\nexport type AIOptions = (\n | ({\n provider: AiProviders.OPENAI | `${AiProviders.OPENAI}`;\n } & OpenAIProviderOptions)\n | ({\n provider: AiProviders.ANTHROPIC | `${AiProviders.ANTHROPIC}`;\n } & AnthropicProviderOptions)\n | ({\n provider: AiProviders.MISTRAL | `${AiProviders.MISTRAL}`;\n } & MistralProviderOptions)\n | ({\n provider: AiProviders.DEEPSEEK | `${AiProviders.DEEPSEEK}`;\n } & DeepSeekProviderOptions)\n | ({\n provider: AiProviders.GEMINI | `${AiProviders.GEMINI}`;\n } & GoogleProviderOptions)\n | ({\n provider:\n | AiProviders.GOOGLEGENERATIVEAI\n | `${AiProviders.GOOGLEGENERATIVEAI}`;\n } & GoogleProviderOptions)\n | ({\n provider: AiProviders.OLLAMA | `${AiProviders.OLLAMA}`;\n } & OpenAIProviderOptions)\n | ({\n provider: AiProviders.OPENROUTER | `${AiProviders.OPENROUTER}`;\n } & OpenRouterProviderOptions)\n | ({\n provider: AiProviders.ALIBABA | `${AiProviders.ALIBABA}`;\n } & AlibabaProviderOptions)\n | ({\n provider: AiProviders.FIREWORKS | `${AiProviders.FIREWORKS}`;\n } & FireworksProviderOptions)\n | ({\n provider: AiProviders.GROQ | `${AiProviders.GROQ}`;\n } & GroqProviderOptions)\n | ({\n provider: AiProviders.HUGGINGFACE | `${AiProviders.HUGGINGFACE}`;\n } & HuggingFaceProviderOptions)\n | ({\n provider: AiProviders.BEDROCK | `${AiProviders.BEDROCK}`;\n } & AmazonBedrockProviderOptions)\n | ({\n provider: AiProviders.GOOGLEVERTEX | `${AiProviders.GOOGLEVERTEX}`;\n } & VertexProviderOptions)\n | ({\n provider: AiProviders.TOGETHERAI | `${AiProviders.TOGETHERAI}`;\n } & TogetherAIProviderOptions)\n | ({\n provider: AiProviders.LMSTUDIO | `${AiProviders.LMSTUDIO}`;\n } & LMStudioProviderOptions)\n | ({\n provider: AiProviders.MOONSHOTAI | `${AiProviders.MOONSHOTAI}`;\n } & MoonshotAIProviderOptions)\n | ({ provider?: undefined } & OpenAIProviderOptions)\n) &\n CommonAIOptions;\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 isMaskedKey = (key?: string): boolean => !!key?.includes('*');\n\nconst getAPIKey = (\n accessType: AccessType[],\n aiOptions?: AIOptions,\n isAuthenticated: boolean = false\n) => {\n const apiKey =\n aiOptions?.apiKey && !isMaskedKey(aiOptions.apiKey)\n ? aiOptions.apiKey\n : undefined;\n\n if (accessType.includes('public')) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n if (accessType.includes('apiKey') && apiKey) {\n return apiKey;\n }\n\n if (accessType.includes('registered_user') && isAuthenticated) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && isAuthenticated) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n return undefined;\n};\n\nconst getModelName = (\n provider: AiProviders,\n isUserProvidedKey: boolean,\n userModel?: Model\n): Model => {\n // If the user provides their own API key, allow custom model selection\n if (\n isUserProvidedKey ||\n provider === AiProviders.OLLAMA ||\n provider === AiProviders.LMSTUDIO\n ) {\n if (userModel) {\n return userModel;\n }\n\n // No custom model specified — fall back to the default\n return DEFAULT_MODEL;\n }\n\n // Using backend's default API key — always use the default model,\n // ignore any custom model the user may have passed\n return DEFAULT_MODEL;\n};\n\nconst getLanguageModel = async (\n aiOptions: AIOptions,\n apiKey: string | undefined\n) => {\n const loadModule = async <T>(packageName: string): Promise<T> => {\n try {\n return (await import(packageName)) as T;\n } catch {\n logger(\n `${x} The package \"${colorize(packageName, ANSIColors.GREEN)}\" is required to use this AI provider. Please install it using: ${colorize(`npm install ${packageName}`, ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n );\n process.exit();\n }\n };\n\n const provider = aiOptions.provider ?? AiProviders.OPENAI;\n const selectedModel = getModelName(\n provider as AiProviders,\n !!aiOptions.apiKey, // true only when the user explicitly provided their own key\n aiOptions.model\n );\n\n const baseURL = aiOptions.baseURL;\n\n switch (provider) {\n case AiProviders.OPENAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAI } =\n await loadModule<typeof import('@ai-sdk/openai')>('@ai-sdk/openai');\n\n return createOpenAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.ANTHROPIC: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAnthropic } =\n await loadModule<typeof import('@ai-sdk/anthropic')>(\n '@ai-sdk/anthropic'\n );\n\n return createAnthropic({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.MISTRAL: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createMistral } =\n await loadModule<typeof import('@ai-sdk/mistral')>('@ai-sdk/mistral');\n\n return createMistral({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.DEEPSEEK: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createDeepSeek } =\n await loadModule<typeof import('@ai-sdk/deepseek')>('@ai-sdk/deepseek');\n\n return createDeepSeek({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.GEMINI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGoogleGenerativeAI } =\n await loadModule<typeof import('@ai-sdk/google')>('@ai-sdk/google');\n\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.GOOGLEVERTEX: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createVertex } = await loadModule<\n typeof import('@ai-sdk/google-vertex')\n >('@ai-sdk/google-vertex');\n\n return createVertex({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel as string);\n }\n\n case AiProviders.GOOGLEGENERATIVEAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGoogleGenerativeAI } =\n await loadModule<typeof import('@ai-sdk/google')>('@ai-sdk/google');\n\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel as string);\n }\n\n case AiProviders.OLLAMA: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAI } =\n await loadModule<typeof import('@ai-sdk/openai')>('@ai-sdk/openai');\n\n // Ollama compatible mode:\n const ollama = createOpenAI({\n baseURL: baseURL ?? 'http://localhost:11434/v1',\n apiKey: apiKey ?? 'ollama', // Required but unused by Ollama\n ...otherOptions,\n });\n\n return ollama.chat(selectedModel);\n }\n\n case AiProviders.OPENROUTER: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenRouter } = await loadModule<\n typeof import('@openrouter/ai-sdk-provider')\n >('@openrouter/ai-sdk-provider');\n\n const openrouter = createOpenRouter({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return openrouter(selectedModel as string);\n }\n\n case AiProviders.ALIBABA: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAlibaba } =\n await loadModule<typeof import('@ai-sdk/alibaba')>('@ai-sdk/alibaba');\n\n const alibaba = createAlibaba({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return alibaba(selectedModel as string);\n }\n\n case AiProviders.FIREWORKS: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createFireworks } =\n await loadModule<typeof import('@ai-sdk/fireworks')>(\n '@ai-sdk/fireworks'\n );\n\n const fireworks = createFireworks({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return fireworks(selectedModel as string);\n }\n\n case AiProviders.GROQ: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGroq } =\n await loadModule<typeof import('@ai-sdk/groq')>('@ai-sdk/groq');\n\n const groq = createGroq({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return groq(selectedModel as string);\n }\n\n case AiProviders.HUGGINGFACE: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createHuggingFace } = await loadModule<\n typeof import('@ai-sdk/huggingface')\n >('@ai-sdk/huggingface');\n\n const huggingface = createHuggingFace({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return huggingface(selectedModel as string);\n }\n\n case AiProviders.BEDROCK: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAmazonBedrock } = await loadModule<\n typeof import('@ai-sdk/amazon-bedrock')\n >('@ai-sdk/amazon-bedrock');\n\n const bedrock = createAmazonBedrock({\n accessKeyId: apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return bedrock(selectedModel as string);\n }\n\n case AiProviders.TOGETHERAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createTogetherAI } =\n await loadModule<typeof import('@ai-sdk/togetherai')>(\n '@ai-sdk/togetherai'\n );\n\n const togetherai = createTogetherAI({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return togetherai(selectedModel as string);\n }\n\n case AiProviders.LMSTUDIO: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAICompatible } = await loadModule<\n typeof import('@ai-sdk/openai-compatible')\n >('@ai-sdk/openai-compatible');\n\n const lmstudio = createOpenAICompatible({\n name: 'lmstudio',\n baseURL: baseURL ?? 'http://localhost:1234/v1',\n ...otherOptions,\n });\n\n return lmstudio(selectedModel as string);\n }\n\n case AiProviders.MOONSHOTAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createMoonshotAI } =\n await loadModule<typeof import('@ai-sdk/moonshotai')>(\n '@ai-sdk/moonshotai'\n );\n\n const moonshotai = createMoonshotAI({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return moonshotai(selectedModel as string);\n }\n\n default: {\n throw new Error(`Provider ${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 dataSerialization?: 'json' | 'toon';\n};\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n projectOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Sends a minimal request to verify that the configured AI provider credentials\n * are valid and reachable before starting any bulk operation.\n *\n * @returns true if access is confirmed, false otherwise\n */\nexport const checkAISDKAccess = async (\n aiConfig: AIConfig\n): Promise<{ hasAIAccess: boolean; error?: string }> => {\n try {\n await generateTextFn({\n ...aiConfig,\n messages: [\n {\n role: 'user',\n content: 'ping',\n },\n ],\n maxOutputTokens: 20,\n });\n return { hasAIAccess: true };\n } catch (error) {\n return { hasAIAccess: false, error: (error as Error).message };\n }\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 projectOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const mergeWithoutUndefined = (...sources: (AIOptions | undefined)[]) => {\n const result: Record<string, unknown> = { provider: DEFAULT_PROVIDER };\n for (const source of sources) {\n if (!source) continue;\n for (const [key, value] of Object.entries(source)) {\n if (value === undefined) continue;\n if (key === 'apiKey' && isMaskedKey(value as string)) continue;\n result[key] = value;\n }\n }\n return result;\n };\n\n const aiOptions = mergeWithoutUndefined(\n defaultOptions,\n projectOptions,\n userOptions\n ) as AIOptions;\n\n const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);\n\n // Check if API key is provided\n if (\n !apiKey &&\n aiOptions.provider !== AiProviders.OLLAMA &&\n aiOptions.provider !== AiProviders.LMSTUDIO\n ) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const languageModel = await getLanguageModel(aiOptions, apiKey);\n\n return {\n model: languageModel,\n temperature: aiOptions.temperature,\n dataSerialization: aiOptions.dataSerialization,\n };\n};\n"],"mappings":";;;;;;;;;AA6CA,MAAM,mBA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TextFn"],"sources":["../../src/aiSdk.ts"],"sourcesContent":["import type { AlibabaProvider, createAlibaba } from '@ai-sdk/alibaba';\nimport type {\n AmazonBedrockProvider,\n createAmazonBedrock,\n} from '@ai-sdk/amazon-bedrock';\nimport type { AnthropicProvider, createAnthropic } from '@ai-sdk/anthropic';\nimport type { createDeepSeek, DeepSeekProvider } from '@ai-sdk/deepseek';\nimport type { createFireworks, FireworksProvider } from '@ai-sdk/fireworks';\nimport type {\n createGoogleGenerativeAI,\n GoogleGenerativeAIProvider,\n} from '@ai-sdk/google';\nimport type {\n createVertex,\n GoogleVertexProvider as VertexProvider,\n} from '@ai-sdk/google-vertex';\nimport type { createGroq, GroqProvider } from '@ai-sdk/groq';\nimport type {\n createHuggingFace,\n HuggingFaceProvider,\n} from '@ai-sdk/huggingface';\nimport type { createMistral, MistralProvider } from '@ai-sdk/mistral';\nimport type { createMoonshotAI, MoonshotAIProvider } from '@ai-sdk/moonshotai';\nimport type { createOpenAI, OpenAIProvider } from '@ai-sdk/openai';\nimport type {\n createOpenAICompatible,\n OpenAICompatibleProvider,\n} from '@ai-sdk/openai-compatible';\nimport type { createTogetherAI, TogetherAIProvider } from '@ai-sdk/togetherai';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, logger, x } from '@intlayer/config/logger';\nimport { AiProviders } from '@intlayer/types/config';\nimport type {\n createOpenRouter,\n OpenRouterProvider,\n} from '@openrouter/ai-sdk-provider';\nimport type {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\nimport { generateText as generateTextFn } from 'ai';\n\nconst DEFAULT_PROVIDER = AiProviders.ANTHROPIC;\nconst DEFAULT_MODEL = 'claude-haiku-5-5';\nconst DEFAULT_API_KEY = process.env.ANTHROPIC_API_KEY;\n\nexport { AiProviders as AIProvider };\n\ntype AnthropicModel = Parameters<AnthropicProvider>[0];\ntype DeepSeekModel = Parameters<DeepSeekProvider>[0];\ntype MistralModel = Parameters<MistralProvider>[0];\ntype OpenAIModel = Parameters<OpenAIProvider>[0];\ntype OpenRouterModel = Parameters<OpenRouterProvider>[0];\ntype GoogleModel = Parameters<GoogleGenerativeAIProvider>[0];\ntype VertexModel = Parameters<VertexProvider>[0];\ntype AlibabaModel = Parameters<AlibabaProvider>[0];\ntype AmazonBedrockModel = Parameters<AmazonBedrockProvider>[0];\ntype FireworksModel = Parameters<FireworksProvider>[0];\ntype GroqModel = Parameters<GroqProvider>[0];\ntype HuggingFaceModel = Parameters<HuggingFaceProvider>[0];\ntype TogetherAIModel = Parameters<TogetherAIProvider>[0];\ntype LMStudioModel = Parameters<OpenAICompatibleProvider>[0];\ntype MoonshotAIModel = Parameters<MoonshotAIProvider>[0];\n\nexport type OpenAIProviderOptions = Parameters<typeof createOpenAI>[0];\nexport type AnthropicProviderOptions = Parameters<typeof createAnthropic>[0];\nexport type MistralProviderOptions = Parameters<typeof createMistral>[0];\nexport type DeepSeekProviderOptions = Parameters<typeof createDeepSeek>[0];\nexport type GoogleProviderOptions = Parameters<\n typeof createGoogleGenerativeAI\n>[0];\nexport type VertexProviderOptions = Parameters<typeof createVertex>[0];\nexport type OpenRouterProviderOptions = Parameters<typeof createOpenRouter>[0];\nexport type AlibabaProviderOptions = Parameters<typeof createAlibaba>[0];\nexport type FireworksProviderOptions = Parameters<typeof createFireworks>[0];\nexport type GroqProviderOptions = Parameters<typeof createGroq>[0];\nexport type HuggingFaceProviderOptions = Parameters<\n typeof createHuggingFace\n>[0];\nexport type AmazonBedrockProviderOptions = Parameters<\n typeof createAmazonBedrock\n>[0];\nexport type TogetherAIProviderOptions = Parameters<typeof createTogetherAI>[0];\nexport type LMStudioProviderOptions = Parameters<\n typeof createOpenAICompatible\n>[0];\nexport type MoonshotAIProviderOptions = Parameters<typeof createMoonshotAI>[0];\n\nexport type SystemMessage =\n | string\n | SystemModelMessage\n | SystemModelMessage[]\n | undefined;\n\nexport type Messages = (\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 | OpenRouterModel\n | GoogleModel\n | VertexModel\n | AlibabaModel\n | AmazonBedrockModel\n | FireworksModel\n | GroqModel\n | HuggingFaceModel\n | TogetherAIModel\n | LMStudioModel\n | MoonshotAIModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\n\nexport type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'none';\n\n/**\n * Common options for all AI providers\n */\ntype CommonAIOptions = {\n model?: Model;\n temperature?: number;\n baseURL?: string;\n apiKey?: string;\n applicationContext?: string;\n dataSerialization?: 'json' | 'toon';\n};\n\nexport type AIOptions = (\n | ({\n provider: AiProviders.OPENAI | `${AiProviders.OPENAI}`;\n } & OpenAIProviderOptions)\n | ({\n provider: AiProviders.ANTHROPIC | `${AiProviders.ANTHROPIC}`;\n } & AnthropicProviderOptions)\n | ({\n provider: AiProviders.MISTRAL | `${AiProviders.MISTRAL}`;\n } & MistralProviderOptions)\n | ({\n provider: AiProviders.DEEPSEEK | `${AiProviders.DEEPSEEK}`;\n } & DeepSeekProviderOptions)\n | ({\n provider: AiProviders.GEMINI | `${AiProviders.GEMINI}`;\n } & GoogleProviderOptions)\n | ({\n provider:\n | AiProviders.GOOGLEGENERATIVEAI\n | `${AiProviders.GOOGLEGENERATIVEAI}`;\n } & GoogleProviderOptions)\n | ({\n provider: AiProviders.OLLAMA | `${AiProviders.OLLAMA}`;\n } & OpenAIProviderOptions)\n | ({\n provider: AiProviders.OPENROUTER | `${AiProviders.OPENROUTER}`;\n } & OpenRouterProviderOptions)\n | ({\n provider: AiProviders.ALIBABA | `${AiProviders.ALIBABA}`;\n } & AlibabaProviderOptions)\n | ({\n provider: AiProviders.FIREWORKS | `${AiProviders.FIREWORKS}`;\n } & FireworksProviderOptions)\n | ({\n provider: AiProviders.GROQ | `${AiProviders.GROQ}`;\n } & GroqProviderOptions)\n | ({\n provider: AiProviders.HUGGINGFACE | `${AiProviders.HUGGINGFACE}`;\n } & HuggingFaceProviderOptions)\n | ({\n provider: AiProviders.BEDROCK | `${AiProviders.BEDROCK}`;\n } & AmazonBedrockProviderOptions)\n | ({\n provider: AiProviders.GOOGLEVERTEX | `${AiProviders.GOOGLEVERTEX}`;\n } & VertexProviderOptions)\n | ({\n provider: AiProviders.TOGETHERAI | `${AiProviders.TOGETHERAI}`;\n } & TogetherAIProviderOptions)\n | ({\n provider: AiProviders.LMSTUDIO | `${AiProviders.LMSTUDIO}`;\n } & LMStudioProviderOptions)\n | ({\n provider: AiProviders.MOONSHOTAI | `${AiProviders.MOONSHOTAI}`;\n } & MoonshotAIProviderOptions)\n | ({ provider?: undefined } & OpenAIProviderOptions)\n) &\n CommonAIOptions;\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 isMaskedKey = (key?: string): boolean => !!key?.includes('*');\n\nconst getAPIKey = (\n accessType: AccessType[],\n aiOptions?: AIOptions,\n isAuthenticated: boolean = false\n) => {\n const apiKey =\n aiOptions?.apiKey && !isMaskedKey(aiOptions.apiKey)\n ? aiOptions.apiKey\n : undefined;\n\n if (accessType.includes('public')) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n if (accessType.includes('apiKey') && apiKey) {\n return apiKey;\n }\n\n if (accessType.includes('registered_user') && isAuthenticated) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && isAuthenticated) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n return undefined;\n};\n\nconst getModelName = (\n provider: AiProviders,\n isUserProvidedKey: boolean,\n userModel?: Model\n): Model => {\n // If the user provides their own API key, allow custom model selection\n if (\n isUserProvidedKey ||\n provider === AiProviders.OLLAMA ||\n provider === AiProviders.LMSTUDIO\n ) {\n if (userModel) {\n return userModel;\n }\n\n // No custom model specified — fall back to the default\n return DEFAULT_MODEL;\n }\n\n // Using backend's default API key — always use the default model,\n // ignore any custom model the user may have passed\n return DEFAULT_MODEL;\n};\n\nconst getLanguageModel = async (\n aiOptions: AIOptions,\n apiKey: string | undefined\n) => {\n const loadModule = async <T>(packageName: string): Promise<T> => {\n try {\n return (await import(packageName)) as T;\n } catch {\n logger(\n `${x} The package \"${colorize(packageName, ANSIColors.GREEN)}\" is required to use this AI provider. Please install it using: ${colorize(`npm install ${packageName}`, ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n );\n process.exit();\n }\n };\n\n const provider = aiOptions.provider ?? AiProviders.OPENAI;\n const selectedModel = getModelName(\n provider as AiProviders,\n !!aiOptions.apiKey, // true only when the user explicitly provided their own key\n aiOptions.model\n );\n\n const baseURL = aiOptions.baseURL;\n\n switch (provider) {\n case AiProviders.OPENAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAI } =\n await loadModule<typeof import('@ai-sdk/openai')>('@ai-sdk/openai');\n\n return createOpenAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.ANTHROPIC: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAnthropic } =\n await loadModule<typeof import('@ai-sdk/anthropic')>(\n '@ai-sdk/anthropic'\n );\n\n return createAnthropic({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.MISTRAL: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createMistral } =\n await loadModule<typeof import('@ai-sdk/mistral')>('@ai-sdk/mistral');\n\n return createMistral({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.DEEPSEEK: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createDeepSeek } =\n await loadModule<typeof import('@ai-sdk/deepseek')>('@ai-sdk/deepseek');\n\n return createDeepSeek({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.GEMINI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGoogleGenerativeAI } =\n await loadModule<typeof import('@ai-sdk/google')>('@ai-sdk/google');\n\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.GOOGLEVERTEX: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createVertex } = await loadModule<\n typeof import('@ai-sdk/google-vertex')\n >('@ai-sdk/google-vertex');\n\n return createVertex({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel as string);\n }\n\n case AiProviders.GOOGLEGENERATIVEAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGoogleGenerativeAI } =\n await loadModule<typeof import('@ai-sdk/google')>('@ai-sdk/google');\n\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel as string);\n }\n\n case AiProviders.OLLAMA: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAI } =\n await loadModule<typeof import('@ai-sdk/openai')>('@ai-sdk/openai');\n\n // Ollama compatible mode:\n const ollama = createOpenAI({\n baseURL: baseURL ?? 'http://localhost:11434/v1',\n apiKey: apiKey ?? 'ollama', // Required but unused by Ollama\n ...otherOptions,\n });\n\n return ollama.chat(selectedModel);\n }\n\n case AiProviders.OPENROUTER: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenRouter } = await loadModule<\n typeof import('@openrouter/ai-sdk-provider')\n >('@openrouter/ai-sdk-provider');\n\n const openrouter = createOpenRouter({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return openrouter(selectedModel as string);\n }\n\n case AiProviders.ALIBABA: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAlibaba } =\n await loadModule<typeof import('@ai-sdk/alibaba')>('@ai-sdk/alibaba');\n\n const alibaba = createAlibaba({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return alibaba(selectedModel as string);\n }\n\n case AiProviders.FIREWORKS: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createFireworks } =\n await loadModule<typeof import('@ai-sdk/fireworks')>(\n '@ai-sdk/fireworks'\n );\n\n const fireworks = createFireworks({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return fireworks(selectedModel as string);\n }\n\n case AiProviders.GROQ: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGroq } =\n await loadModule<typeof import('@ai-sdk/groq')>('@ai-sdk/groq');\n\n const groq = createGroq({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return groq(selectedModel as string);\n }\n\n case AiProviders.HUGGINGFACE: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createHuggingFace } = await loadModule<\n typeof import('@ai-sdk/huggingface')\n >('@ai-sdk/huggingface');\n\n const huggingface = createHuggingFace({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return huggingface(selectedModel as string);\n }\n\n case AiProviders.BEDROCK: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAmazonBedrock } = await loadModule<\n typeof import('@ai-sdk/amazon-bedrock')\n >('@ai-sdk/amazon-bedrock');\n\n const bedrock = createAmazonBedrock({\n accessKeyId: apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return bedrock(selectedModel as string);\n }\n\n case AiProviders.TOGETHERAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createTogetherAI } =\n await loadModule<typeof import('@ai-sdk/togetherai')>(\n '@ai-sdk/togetherai'\n );\n\n const togetherai = createTogetherAI({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return togetherai(selectedModel as string);\n }\n\n case AiProviders.LMSTUDIO: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAICompatible } = await loadModule<\n typeof import('@ai-sdk/openai-compatible')\n >('@ai-sdk/openai-compatible');\n\n const lmstudio = createOpenAICompatible({\n name: 'lmstudio',\n baseURL: baseURL ?? 'http://localhost:1234/v1',\n ...otherOptions,\n });\n\n return lmstudio(selectedModel as string);\n }\n\n case AiProviders.MOONSHOTAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createMoonshotAI } =\n await loadModule<typeof import('@ai-sdk/moonshotai')>(\n '@ai-sdk/moonshotai'\n );\n\n const moonshotai = createMoonshotAI({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return moonshotai(selectedModel as string);\n }\n\n default: {\n throw new Error(`Provider ${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 dataSerialization?: 'json' | 'toon';\n};\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n projectOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Sends a minimal request to verify that the configured AI provider credentials\n * are valid and reachable before starting any bulk operation.\n *\n * @returns true if access is confirmed, false otherwise\n */\nexport const checkAISDKAccess = async (\n aiConfig: AIConfig\n): Promise<{ hasAIAccess: boolean; error?: string }> => {\n try {\n await generateTextFn({\n ...aiConfig,\n messages: [\n {\n role: 'user',\n content: 'ping',\n },\n ],\n maxOutputTokens: 20,\n });\n return { hasAIAccess: true };\n } catch (error) {\n return { hasAIAccess: false, error: (error as Error).message };\n }\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 projectOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const mergeWithoutUndefined = (...sources: (AIOptions | undefined)[]) => {\n const result: Record<string, unknown> = { provider: DEFAULT_PROVIDER };\n for (const source of sources) {\n if (!source) continue;\n for (const [key, value] of Object.entries(source)) {\n if (value === undefined) continue;\n if (key === 'apiKey' && isMaskedKey(value as string)) continue;\n result[key] = value;\n }\n }\n return result;\n };\n\n const aiOptions = mergeWithoutUndefined(\n defaultOptions,\n projectOptions,\n userOptions\n ) as AIOptions;\n\n const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);\n\n // Check if API key is provided\n if (\n !apiKey &&\n aiOptions.provider !== AiProviders.OLLAMA &&\n aiOptions.provider !== AiProviders.LMSTUDIO\n ) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const languageModel = await getLanguageModel(aiOptions, apiKey);\n\n return {\n model: languageModel,\n temperature: aiOptions.temperature,\n dataSerialization: aiOptions.dataSerialization,\n };\n};\n"],"mappings":";;;;;;;;;AA6CA,MAAM,mBAAmBA,mCAAY;AACrC,MAAM,gBAAgB;AACtB,MAAM,kBAAkB,QAAQ,IAAI;AAkKpC,MAAM,eAAe,QAA0B,CAAC,CAAC,KAAK,SAAS,GAAG;AAElE,MAAM,aACJ,YACA,WACA,kBAA2B,UACxB;CACH,MAAM,SACJ,WAAW,UAAU,CAAC,YAAY,UAAU,MAAM,IAC9C,UAAU,SACV;CAEN,IAAI,WAAW,SAAS,QAAQ,GAC9B,OAAO,UAAU;CAGnB,IAAI,WAAW,SAAS,QAAQ,KAAK,QACnC,OAAO;CAGT,IAAI,WAAW,SAAS,iBAAiB,KAAK,iBAC5C,OAAO,UAAU;CAInB,IAAI,WAAW,SAAS,cAAc,KAAK,iBACzC,OAAO,UAAU;AAIrB;AAEA,MAAM,gBACJ,UACA,mBACA,cACU;CAEV,IACE,qBACA,aAAaA,mCAAY,UACzB,aAAaA,mCAAY,UACzB;EACA,IAAI,WACF,OAAO;EAIT,OAAO;CACT;CAIA,OAAO;AACT;AAEA,MAAM,mBAAmB,OACvB,WACA,WACG;CACH,MAAM,aAAa,OAAU,gBAAoC;EAC/D,IAAI;GACF,OAAQ,MAAM,OAAO;EACvB,QAAQ;GACN,oCACE,GAAGC,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IACjD,IAAI,UAAU,QAAW;IACzB,IAAI,QAAQ,YAAY,YAAY,KAAe,GAAG;IACtD,OAAO,OAAO;GAChB;EACF;EACA,OAAO;CACT;CAEA,MAAM,YAAY,sBAChB,gBACA,gBACA,WACF;CAEA,MAAM,SAAS,UAAU,YAAY,WAAW,eAAe;CAG/D,IACE,CAAC,UACD,UAAU,aAAaJ,mCAAY,UACnC,UAAU,aAAaA,mCAAY,UAEnC,MAAM,IAAI,MAAM,eAAe,UAAU,SAAS,YAAY;CAKhE,OAAO;EACL,OAAO,MAHmB,iBAAiB,WAAW,MAAM;EAI5D,aAAa,UAAU;EACvB,mBAAmB,UAAU;CAC/B;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require__utils_asset = require(
|
|
2
|
+
const require__utils_asset = require("../_virtual/_utils_asset.cjs");
|
|
3
3
|
let ai = require("ai");
|
|
4
4
|
let zod_mini = require("zod/mini");
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// src/auditDictionaryMetadata/index.ts
|
|
7
7
|
const aiDefaultOptions = {};
|
|
8
8
|
/**
|
|
9
9
|
* Audits a content declaration file by constructing a prompt for AI models.
|
|
@@ -46,7 +46,6 @@ const auditDictionaryMetadata = async ({ fileContent, tags, aiConfig, applicatio
|
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
//#endregion
|
|
50
49
|
exports.aiDefaultOptions = aiDefaultOptions;
|
|
51
50
|
exports.auditDictionaryMetadata = auditDictionaryMetadata;
|
|
52
51
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["readAsset","generateText","Output","z"],"sources":["../../../src/auditDictionaryMetadata/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["readAsset","generateText","Output","z"],"sources":["../../../src/auditDictionaryMetadata/index.ts"],"sourcesContent":["import { generateText, Output } from 'ai';\nimport { readAsset } from 'utils:asset';\nimport { z } from 'zod/mini';\nimport type { AIConfig, AIOptions } from '../aiSdk';\n\ntype Tag = {\n key: string;\n description?: string;\n};\n\nexport type AuditDictionaryMetadataOptions = {\n fileContent: string;\n tags?: Tag[];\n aiConfig: AIConfig;\n applicationContext?: string;\n};\n\nexport type AuditFileResultData = {\n fileContent: {\n title: string;\n description: string;\n tags: string[];\n };\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n // Keep default options\n};\n\n/**\n * Audits a content declaration file by constructing a prompt for AI models.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies.\n */\nexport const auditDictionaryMetadata = async ({\n fileContent,\n tags,\n aiConfig,\n applicationContext,\n}: AuditDictionaryMetadataOptions): Promise<\n AuditFileResultData | undefined\n> => {\n const CHAT_GPT_PROMPT = readAsset('./PROMPT.md');\n const EXAMPLE_REQUEST = readAsset('./EXAMPLE_REQUEST.md');\n const EXAMPLE_RESPONSE = readAsset('./EXAMPLE_RESPONSE.md');\n\n // Prepare the prompt for AI by replacing placeholders with actual values.\n const prompt = CHAT_GPT_PROMPT.replace(\n '{{applicationContext}}',\n applicationContext ?? ''\n ).replace(\n '{{tags}}',\n tags\n ? JSON.stringify(\n tags\n .map(({ key, description }) => `- ${key}: ${description}`)\n .join('\\n\\n'),\n null,\n 2\n )\n : ''\n );\n\n const { dataSerialization, ...restAiConfig } = aiConfig;\n const { output: _unusedOutput, ...validAiConfig } = restAiConfig;\n\n // Use the AI SDK to generate the completion\n const { output, usage } = await generateText({\n ...validAiConfig,\n output: Output.object({\n schema: z.object({\n title: z.string(),\n description: z.string(),\n tags: z.array(z.string()),\n }),\n }),\n system: prompt,\n messages: [\n { role: 'user', content: EXAMPLE_REQUEST },\n { role: 'assistant', content: EXAMPLE_RESPONSE },\n {\n role: 'user',\n content: fileContent,\n },\n ],\n });\n\n return {\n fileContent: output,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;;;;AA0BA,MAAa,mBAA8B,CAE3C;;;;;;AAOA,MAAa,0BAA0B,OAAO,EAC5C,aACA,MACA,UACA,yBAGG;CACH,MAAM,kBAAkBA,+BAAU,aAAa;CAC/C,MAAM,kBAAkBA,+BAAU,sBAAsB;CACxD,MAAM,mBAAmBA,+BAAU,uBAAuB;CAG1D,MAAM,SAAS,gBAAgB,QAC7B,0BACA,sBAAsB,EACxB,CAAC,CAAC,QACA,YACA,OACI,KAAK,UACH,KACG,KAAK,EAAE,KAAK,kBAAkB,KAAK,IAAI,IAAI,aAAa,CAAC,CACzD,KAAK,MAAM,GACd,MACA,CACF,IACA,EACN;CAEA,MAAM,EAAE,mBAAmB,GAAG,iBAAiB;CAC/C,MAAM,EAAE,QAAQ,eAAe,GAAG,kBAAkB;CAGpD,MAAM,EAAE,QAAQ,UAAU,UAAMC,iBAAa;EAC3C,GAAG;EACH,QAAQC,UAAO,OAAO,EACpB,QAAQC,WAAE,OAAO;GACf,OAAOA,WAAE,OAAO;GAChB,aAAaA,WAAE,OAAO;GACtB,MAAMA,WAAE,MAAMA,WAAE,OAAO,CAAC;EAC1B,CAAC,EACH,CAAC;EACD,QAAQ;EACR,UAAU;GACR;IAAE,MAAM;IAAQ,SAAS;GAAgB;GACzC;IAAE,MAAM;IAAa,SAAS;GAAiB;GAC/C;IACE,MAAM;IACN,SAAS;GACX;EACF;CACF,CAAC;CAED,OAAO;EACL,aAAa;EACb,WAAW,OAAO,eAAe;CACnC;AACF"}
|
package/dist/cjs/customQuery.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
let ai = require("ai");
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
const aiDefaultOptions = { model: "gpt-
|
|
4
|
+
// src/customQuery.ts
|
|
5
|
+
const aiDefaultOptions = { model: "gpt-6-luna" };
|
|
6
6
|
/**
|
|
7
7
|
* CustomQuery a content declaration file by constructing a prompt for AI models.
|
|
8
8
|
* The prompt includes details about the project's locales, file paths of content declarations,
|
|
@@ -20,7 +20,6 @@ const customQuery = async ({ messages, system, aiConfig }) => {
|
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
//#endregion
|
|
24
23
|
exports.aiDefaultOptions = aiDefaultOptions;
|
|
25
24
|
exports.customQuery = customQuery;
|
|
26
25
|
//# sourceMappingURL=customQuery.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customQuery.cjs","names":["generateText"],"sources":["../../src/customQuery.ts"],"sourcesContent":["import { generateText, type SystemModelMessage } from 'ai';\nimport type { AIConfig, AIOptions, Messages } from './aiSdk';\n\nexport type CustomQueryOptions = {\n messages: Messages;\n system?: string | SystemModelMessage | SystemModelMessage[];\n aiConfig: AIConfig;\n};\n\nexport type CustomQueryResultData = {\n fileContent: string;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n model: 'gpt-
|
|
1
|
+
{"version":3,"file":"customQuery.cjs","names":["generateText"],"sources":["../../src/customQuery.ts"],"sourcesContent":["import { generateText, type SystemModelMessage } from 'ai';\nimport type { AIConfig, AIOptions, Messages } from './aiSdk';\n\nexport type CustomQueryOptions = {\n messages: Messages;\n system?: string | SystemModelMessage | SystemModelMessage[];\n aiConfig: AIConfig;\n};\n\nexport type CustomQueryResultData = {\n fileContent: string;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n model: 'gpt-6-luna',\n // Keep default options\n};\n\n/**\n * CustomQuery a content declaration file by constructing a prompt for AI models.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies.\n */\nexport const customQuery = async ({\n messages,\n system,\n aiConfig,\n}: CustomQueryOptions): Promise<CustomQueryResultData | undefined> => {\n // Use the AI SDK to generate the completion\n const { text: newContent, usage } = await generateText({\n ...aiConfig,\n system,\n messages,\n });\n\n return {\n fileContent: newContent,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;;AAcA,MAAa,mBAA8B,EACzC,OAAO,aAET;;;;;;AAOA,MAAa,cAAc,OAAO,EAChC,UACA,QACA,eACoE;CAEpE,MAAM,EAAE,MAAM,YAAY,UAAU,UAAMA,iBAAa;EACrD,GAAG;EACH;EACA;CACF,CAAC;CAED,OAAO;EACL,aAAa;EACb,WAAW,OAAO,eAAe;CACnC;AACF"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,43 +1,48 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_aiSdk = require(
|
|
3
|
-
const require_auditDictionaryMetadata_index = require(
|
|
4
|
-
const require_customQuery = require(
|
|
5
|
-
const
|
|
6
|
-
const
|
|
2
|
+
const require_aiSdk = require("./aiSdk.cjs");
|
|
3
|
+
const require_auditDictionaryMetadata_index = require("./auditDictionaryMetadata/index.cjs");
|
|
4
|
+
const require_customQuery = require("./customQuery.cjs");
|
|
5
|
+
const require_translateJSON_index = require("./translateJSON/index.cjs");
|
|
6
|
+
const require_utils_extractJSON = require("./utils/extractJSON.cjs");
|
|
7
7
|
let ai = require("ai");
|
|
8
8
|
let _intlayer_types_config = require("@intlayer/types/config");
|
|
9
9
|
|
|
10
|
-
exports
|
|
10
|
+
Object.defineProperty(exports, "AIProvider", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _intlayer_types_config.AiProviders;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
11
16
|
exports.auditDictionaryMetadata = require_auditDictionaryMetadata_index.auditDictionaryMetadata;
|
|
12
17
|
exports.checkAISDKAccess = require_aiSdk.checkAISDKAccess;
|
|
13
18
|
exports.customQuery = require_customQuery.customQuery;
|
|
14
19
|
exports.extractJson = require_utils_extractJSON.extractJson;
|
|
15
|
-
Object.defineProperty(exports,
|
|
20
|
+
Object.defineProperty(exports, "generateText", {
|
|
16
21
|
enumerable: true,
|
|
17
22
|
get: function () {
|
|
18
23
|
return ai.generateText;
|
|
19
24
|
}
|
|
20
25
|
});
|
|
21
26
|
exports.getAIConfig = require_aiSdk.getAIConfig;
|
|
22
|
-
Object.defineProperty(exports,
|
|
27
|
+
Object.defineProperty(exports, "jsonSchema", {
|
|
23
28
|
enumerable: true,
|
|
24
29
|
get: function () {
|
|
25
30
|
return ai.jsonSchema;
|
|
26
31
|
}
|
|
27
32
|
});
|
|
28
|
-
Object.defineProperty(exports,
|
|
33
|
+
Object.defineProperty(exports, "stepCountIs", {
|
|
29
34
|
enumerable: true,
|
|
30
35
|
get: function () {
|
|
31
36
|
return ai.stepCountIs;
|
|
32
37
|
}
|
|
33
38
|
});
|
|
34
|
-
Object.defineProperty(exports,
|
|
39
|
+
Object.defineProperty(exports, "streamText", {
|
|
35
40
|
enumerable: true,
|
|
36
41
|
get: function () {
|
|
37
42
|
return ai.streamText;
|
|
38
43
|
}
|
|
39
44
|
});
|
|
40
|
-
Object.defineProperty(exports,
|
|
45
|
+
Object.defineProperty(exports, "tool", {
|
|
41
46
|
enumerable: true,
|
|
42
47
|
get: function () {
|
|
43
48
|
return ai.tool;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require__utils_asset = require(
|
|
3
|
-
const require_utils_extractJSON = require(
|
|
2
|
+
const require__utils_asset = require("../_virtual/_utils_asset.cjs");
|
|
3
|
+
const require_utils_extractJSON = require("../utils/extractJSON.cjs");
|
|
4
4
|
let ai = require("ai");
|
|
5
5
|
let zod_mini = require("zod/mini");
|
|
6
6
|
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
@@ -8,10 +8,10 @@ let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
|
8
8
|
let _toon_format_toon = require("@toon-format/toon");
|
|
9
9
|
let _intlayer_types_config = require("@intlayer/types/config");
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// src/translateJSON/index.ts
|
|
12
12
|
const aiDefaultOptions = {
|
|
13
13
|
provider: _intlayer_types_config.AiProviders.OPENAI,
|
|
14
|
-
model: "gpt-5-
|
|
14
|
+
model: "gpt-5.6-terra"
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Format a locale with its name.
|
|
@@ -127,7 +127,6 @@ const translateJSON = async ({ entryFileContent, presetOutputContent, dictionary
|
|
|
127
127
|
};
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
-
//#endregion
|
|
131
130
|
exports.aiDefaultOptions = aiDefaultOptions;
|
|
132
131
|
exports.translateJSON = translateJSON;
|
|
133
132
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["AIProvider","getLocaleName","DEFAULT_LOCALE","z","readAsset","encode","generateText","decode","Output","extractJson"],"sources":["../../../src/translateJSON/index.ts"],"sourcesContent":["import { readAsset } from 'utils:asset';\nimport { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { decode, encode } from '@toon-format/toon';\nimport { generateText, Output } from 'ai';\nimport { z } from 'zod/mini';\nimport { type AIConfig, type AIOptions, AIProvider } from '../aiSdk';\nimport { extractJson } from '../utils/extractJSON';\n\ntype Tag = {\n key: string;\n description?: string;\n};\n\nexport type TranslateJSONOptions<T = JSON> = {\n entryFileContent: T;\n presetOutputContent: Partial<T>;\n dictionaryDescription?: string;\n entryLocale: Locale;\n outputLocale: Locale;\n tags?: Tag[];\n aiConfig: AIConfig;\n mode: 'complete' | 'review';\n applicationContext?: string;\n};\n\nexport type TranslateJSONResultData<T = JSON> = {\n fileContent: T;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n provider: AIProvider.OPENAI,\n model: 'gpt-5-mini',\n};\n\n/**\n * Format a locale with its name.\n *\n * @param locale - The locale to format.\n * @returns A string in the format \"locale: name\", e.g. \"en: English\".\n */\nconst formatLocaleWithName = (locale: Locale): string =>\n `${locale}: ${getLocaleName(locale, DEFAULT_LOCALE)}`;\n\n/**\n * Formats tag instructions for the AI prompt.\n * Creates a string with all available tags and their descriptions.\n *\n * @param tags - The list of tags to format.\n * @returns A formatted string with tag instructions.\n */\nconst formatTagInstructions = (tags: Tag[]): string => {\n if (!tags || tags.length === 0) {\n return '';\n }\n\n // Prepare the tag instructions.\n return `Based on the dictionary content, identify specific tags from the list below that would be relevant:\n \n${tags.map(({ key, description }) => `- ${key}: ${description}`).join('\\n\\n')}`;\n};\n\nconst getModeInstructions = (mode: 'complete' | 'review'): string => {\n if (mode === 'complete') {\n return 'Mode: \"Complete\" - Enrich the preset content with the missing keys and values in the output locale. Do not update existing keys. Everything should be returned in the output.';\n }\n\n return 'Mode: \"Review\" - Fill missing content and review existing keys from the preset content. If a key from the entry is missing in the output, it must be translated to the target language and added. If you detect misspelled content, or content that should be reformulated, correct it. If a translation is not coherent with the desired language, translate it.';\n};\n\nconst jsonToZod = (content: any): z.ZodMiniType => {\n // Base case: content is a string (the translation target)\n if (typeof content === 'string') {\n return z.string();\n }\n\n // Base cases: primitives often preserved in i18n files (e.g. strict numbers/booleans)\n if (typeof content === 'number') {\n return z.number();\n }\n if (typeof content === 'boolean') {\n return z.boolean();\n }\n\n // Recursive case: Array\n if (Array.isArray(content)) {\n // If array is empty, we assume array of strings as default for i18n\n if (content.length === 0) {\n return z.array(z.string());\n }\n // We assume all items in the array share the structure of the first item\n return z.array(jsonToZod(content[0]));\n }\n\n // Recursive case: Object\n if (typeof content === 'object' && content !== null) {\n const shape: Record<string, z.ZodMiniType> = {};\n for (const key in content) {\n shape[key] = jsonToZod(content[key]);\n }\n return z.object(shape);\n }\n\n // Fallback\n return z.string();\n};\n\nconst countKeys = (obj: any): number => {\n if (typeof obj !== 'object' || obj === null) return 0;\n let count = 0;\n for (const key in obj) {\n count += 1 + countKeys(obj[key]);\n }\n return count;\n};\n\n/**\n * TranslateJSONs a content declaration file by constructing a prompt for AI models.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies.\n */\nexport const translateJSON = async <T>({\n entryFileContent,\n presetOutputContent,\n dictionaryDescription,\n aiConfig,\n entryLocale,\n outputLocale,\n tags,\n mode,\n applicationContext,\n}: TranslateJSONOptions<T>): Promise<\n TranslateJSONResultData<T> | undefined\n> => {\n const { dataSerialization, ...restAiConfig } = aiConfig;\n const { output: _unusedOutput, ...validAiConfig } = restAiConfig;\n\n const formattedEntryLocale = formatLocaleWithName(entryLocale);\n const formattedOutputLocale = formatLocaleWithName(outputLocale);\n\n const isToon = dataSerialization === 'toon';\n const promptFile = readAsset(\n isToon ? './PROMPT_TOON.md' : './PROMPT_JSON.md'\n );\n const entryContentStr = isToon\n ? encode(entryFileContent)\n : JSON.stringify(entryFileContent);\n const presetContentStr = isToon\n ? encode(presetOutputContent)\n : JSON.stringify(presetOutputContent);\n\n const schema = jsonToZod(entryFileContent);\n\n // Prepare the prompt for AI by replacing placeholders with actual values.\n const prompt = promptFile\n .replace('{{entryLocale}}', formattedEntryLocale)\n .replace('{{outputLocale}}', formattedOutputLocale)\n .replace('{{presetOutputContent}}', presetContentStr)\n .replace('{{dictionaryDescription}}', dictionaryDescription ?? '')\n .replace('{{applicationContext}}', applicationContext ?? '')\n .replace('{{tagsInstructions}}', formatTagInstructions(tags ?? []))\n .replace('{{modeInstructions}}', getModeInstructions(mode));\n\n if (isToon) {\n const { text, usage } = await generateText({\n ...aiConfig,\n system: prompt,\n messages: [\n {\n role: 'user',\n content: [\n `# Translation Request`,\n `Please translate the following TOON content.`,\n `- **From:** ${formattedEntryLocale}`,\n `- **To:** ${formattedOutputLocale}`,\n ``,\n `## Entry Content:`,\n entryContentStr,\n ].join('\\n'),\n },\n ],\n });\n\n // Strip markdown code blocks if present\n const cleanedText = text\n .replace(/^```(?:toon)?\\n([\\s\\S]*?)\\n```$/gm, '$1')\n .trim();\n\n const decodedJson = decode(cleanedText) as T;\n\n // schema.parse(decodedJson);\n\n return {\n fileContent: decodedJson,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n }\n\n const totalKeys = countKeys(entryFileContent);\n\n const MAX_SAFE_KEYS = 70; // You will need to tune this threshold based on testing\n\n const useStrictOutput = totalKeys <= MAX_SAFE_KEYS;\n\n // Use the AI SDK to generate the completion\n const { text, usage } = await generateText({\n ...validAiConfig,\n\n // Disable schema if Schema is too complex (Block with Anthropic)\n output: useStrictOutput ? Output.object({ schema }) : undefined,\n system: prompt,\n messages: [\n {\n role: 'user',\n content: [\n `# Translation Request`,\n `Please translate the following JSON content.`,\n `- **From:** ${formattedEntryLocale}`,\n `- **To:** ${formattedOutputLocale}`,\n ``,\n `CRITICAL INSTRUCTIONS:`,\n `- You MUST return ONLY raw, valid JSON.`,\n `- DO NOT wrap the response in Markdown code blocks (e.g., no \\`\\`\\`json).`,\n `- DO NOT include any conversational text before or after the JSON object.`,\n ``,\n `## Entry Content:`,\n entryContentStr,\n ].join('\\n'),\n },\n ],\n });\n\n // Extract and re-validate deeply\n const extractedJSON = extractJson(text);\n const validatedContent = schema.parse(extractedJSON) as T;\n\n return {\n fileContent: validatedContent,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;;;;;;;;;AAgCA,MAAa,mBAA8B;CACzC,UAAUA,mCAAW;CACrB,OAAO;AACT;;;;;;;AAQA,MAAM,wBAAwB,WAC5B,GAAG,OAAO,QAAIC,2CAAc,QAAQC,6CAAc;;;;;;;;AASpD,MAAM,yBAAyB,SAAwB;CACrD,IAAI,CAAC,QAAQ,KAAK,WAAW,GAC3B,OAAO;CAIT,OAAO;;EAEP,KAAK,KAAK,EAAE,KAAK,kBAAkB,KAAK,IAAI,IAAI,aAAa,CAAC,CAAC,KAAK,MAAM;AAC5E;AAEA,MAAM,uBAAuB,SAAwC;CACnE,IAAI,SAAS,YACX,OAAO;CAGT,OAAO;A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,WACZ,QAAQ,mBAAmB,oBAAoB,CAAC,CAChD,QAAQ,oBAAoB,qBAAqB,CAAC,CAClD,QAAQ,2BAA2B,gBAAgB,CAAC,CACpD,QAAQ,6BAA6B,yBAAyB,EAAE,CAAC,CACjE,QAAQ,0BAA0B,sBAAsB,EAAE,CAAC,CAC3D,QAAQ,wBAAwB,sBAAsB,QAAQ,CAAC,CAAC,CAAC,CAAC,CAClE,QAAQ,wBAAwB,oBAAoB,IAAI,CAAC;CAE5D,IAAI,QAAQ;EACV,MAAM,EAAE,MAAM,UAAU,UAAMC,iBAAa;GACzC,GAAG;GACH,QAAQ;GACR,UAAU,CACR;IACE,MAAM;IACN,SAAS;KACP;KACA;KACA,eAAe;KACf,aAAa;KACb;KACA;KACA;IACF,CAAC,CAAC,KAAK,IAAI;GACb,CACF;EACF,CAAC;EAGD,MAAM,cAAc,KACjB,QAAQ,qCAAqC,IAAI,CAAC,CAClD,KAAK;EAMR,OAAO;GACL,iBALkBC,0BAAO,WAKF;GACvB,WAAW,OAAO,eAAe;EACnC;CACF;CAMA,MAAM,kBAJY,UAAU,gBAII,KAAK;CAGrC,MAAM,EAAE,MAAM,UAAU,UAAMD,iBAAa;EACzC,GAAG;EAGH,QAAQ,kBAAkBE,UAAO,OAAO,EAAE,OAAO,CAAC,IAAI;EACtD,QAAQ;EACR,UAAU,CACR;GACE,MAAM;GACN,SAAS;IACP;IACA;IACA,eAAe;IACf,aAAa;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACF,CAAC,CAAC,KAAK,IAAI;EACb,CACF;CACF,CAAC;CAGD,MAAM,gBAAgBC,sCAAY,IAAI;CAGtC,OAAO;EACL,aAHuB,OAAO,MAAM,aAGR;EAC5B,WAAW,OAAO,eAAe;CACnC;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["AIProvider","getLocaleName","DEFAULT_LOCALE","z","readAsset","encode","generateText","decode","Output","extractJson"],"sources":["../../../src/translateJSON/index.ts"],"sourcesContent":["import { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { decode, encode } from '@toon-format/toon';\nimport { generateText, Output } from 'ai';\nimport { readAsset } from 'utils:asset';\nimport { z } from 'zod/mini';\nimport { type AIConfig, type AIOptions, AIProvider } from '../aiSdk';\nimport { extractJson } from '../utils/extractJSON';\n\ntype Tag = {\n key: string;\n description?: string;\n};\n\nexport type TranslateJSONOptions<T = JSON> = {\n entryFileContent: T;\n presetOutputContent: Partial<T>;\n dictionaryDescription?: string;\n entryLocale: Locale;\n outputLocale: Locale;\n tags?: Tag[];\n aiConfig: AIConfig;\n mode: 'complete' | 'review';\n applicationContext?: string;\n};\n\nexport type TranslateJSONResultData<T = JSON> = {\n fileContent: T;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n provider: AIProvider.OPENAI,\n model: 'gpt-5.6-terra',\n};\n\n/**\n * Format a locale with its name.\n *\n * @param locale - The locale to format.\n * @returns A string in the format \"locale: name\", e.g. \"en: English\".\n */\nconst formatLocaleWithName = (locale: Locale): string =>\n `${locale}: ${getLocaleName(locale, DEFAULT_LOCALE)}`;\n\n/**\n * Formats tag instructions for the AI prompt.\n * Creates a string with all available tags and their descriptions.\n *\n * @param tags - The list of tags to format.\n * @returns A formatted string with tag instructions.\n */\nconst formatTagInstructions = (tags: Tag[]): string => {\n if (!tags || tags.length === 0) {\n return '';\n }\n\n // Prepare the tag instructions.\n return `Based on the dictionary content, identify specific tags from the list below that would be relevant:\n \n${tags.map(({ key, description }) => `- ${key}: ${description}`).join('\\n\\n')}`;\n};\n\nconst getModeInstructions = (mode: 'complete' | 'review'): string => {\n if (mode === 'complete') {\n return 'Mode: \"Complete\" - Enrich the preset content with the missing keys and values in the output locale. Do not update existing keys. Everything should be returned in the output.';\n }\n\n return 'Mode: \"Review\" - Fill missing content and review existing keys from the preset content. If a key from the entry is missing in the output, it must be translated to the target language and added. If you detect misspelled content, or content that should be reformulated, correct it. If a translation is not coherent with the desired language, translate it.';\n};\n\nconst jsonToZod = (content: any): z.ZodMiniType => {\n // Base case: content is a string (the translation target)\n if (typeof content === 'string') {\n return z.string();\n }\n\n // Base cases: primitives often preserved in i18n files (e.g. strict numbers/booleans)\n if (typeof content === 'number') {\n return z.number();\n }\n if (typeof content === 'boolean') {\n return z.boolean();\n }\n\n // Recursive case: Array\n if (Array.isArray(content)) {\n // If array is empty, we assume array of strings as default for i18n\n if (content.length === 0) {\n return z.array(z.string());\n }\n // We assume all items in the array share the structure of the first item\n return z.array(jsonToZod(content[0]));\n }\n\n // Recursive case: Object\n if (typeof content === 'object' && content !== null) {\n const shape: Record<string, z.ZodMiniType> = {};\n for (const key in content) {\n shape[key] = jsonToZod(content[key]);\n }\n return z.object(shape);\n }\n\n // Fallback\n return z.string();\n};\n\nconst countKeys = (obj: any): number => {\n if (typeof obj !== 'object' || obj === null) return 0;\n let count = 0;\n for (const key in obj) {\n count += 1 + countKeys(obj[key]);\n }\n return count;\n};\n\n/**\n * TranslateJSONs a content declaration file by constructing a prompt for AI models.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies.\n */\nexport const translateJSON = async <T>({\n entryFileContent,\n presetOutputContent,\n dictionaryDescription,\n aiConfig,\n entryLocale,\n outputLocale,\n tags,\n mode,\n applicationContext,\n}: TranslateJSONOptions<T>): Promise<\n TranslateJSONResultData<T> | undefined\n> => {\n const { dataSerialization, ...restAiConfig } = aiConfig;\n const { output: _unusedOutput, ...validAiConfig } = restAiConfig;\n\n const formattedEntryLocale = formatLocaleWithName(entryLocale);\n const formattedOutputLocale = formatLocaleWithName(outputLocale);\n\n const isToon = dataSerialization === 'toon';\n const promptFile = readAsset(\n isToon ? './PROMPT_TOON.md' : './PROMPT_JSON.md'\n );\n const entryContentStr = isToon\n ? encode(entryFileContent)\n : JSON.stringify(entryFileContent);\n const presetContentStr = isToon\n ? encode(presetOutputContent)\n : JSON.stringify(presetOutputContent);\n\n const schema = jsonToZod(entryFileContent);\n\n // Prepare the prompt for AI by replacing placeholders with actual values.\n const prompt = promptFile\n .replace('{{entryLocale}}', formattedEntryLocale)\n .replace('{{outputLocale}}', formattedOutputLocale)\n .replace('{{presetOutputContent}}', presetContentStr)\n .replace('{{dictionaryDescription}}', dictionaryDescription ?? '')\n .replace('{{applicationContext}}', applicationContext ?? '')\n .replace('{{tagsInstructions}}', formatTagInstructions(tags ?? []))\n .replace('{{modeInstructions}}', getModeInstructions(mode));\n\n if (isToon) {\n const { text, usage } = await generateText({\n ...aiConfig,\n system: prompt,\n messages: [\n {\n role: 'user',\n content: [\n `# Translation Request`,\n `Please translate the following TOON content.`,\n `- **From:** ${formattedEntryLocale}`,\n `- **To:** ${formattedOutputLocale}`,\n ``,\n `## Entry Content:`,\n entryContentStr,\n ].join('\\n'),\n },\n ],\n });\n\n // Strip markdown code blocks if present\n const cleanedText = text\n .replace(/^```(?:toon)?\\n([\\s\\S]*?)\\n```$/gm, '$1')\n .trim();\n\n const decodedJson = decode(cleanedText) as T;\n\n // schema.parse(decodedJson);\n\n return {\n fileContent: decodedJson,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n }\n\n const totalKeys = countKeys(entryFileContent);\n\n const MAX_SAFE_KEYS = 70; // You will need to tune this threshold based on testing\n\n const useStrictOutput = totalKeys <= MAX_SAFE_KEYS;\n\n // Use the AI SDK to generate the completion\n const { text, usage } = await generateText({\n ...validAiConfig,\n\n // Disable schema if Schema is too complex (Block with Anthropic)\n output: useStrictOutput ? Output.object({ schema }) : undefined,\n system: prompt,\n messages: [\n {\n role: 'user',\n content: [\n `# Translation Request`,\n `Please translate the following JSON content.`,\n `- **From:** ${formattedEntryLocale}`,\n `- **To:** ${formattedOutputLocale}`,\n ``,\n `CRITICAL INSTRUCTIONS:`,\n `- You MUST return ONLY raw, valid JSON.`,\n `- DO NOT wrap the response in Markdown code blocks (e.g., no \\`\\`\\`json).`,\n `- DO NOT include any conversational text before or after the JSON object.`,\n ``,\n `## Entry Content:`,\n entryContentStr,\n ].join('\\n'),\n },\n ],\n });\n\n // Extract and re-validate deeply\n const extractedJSON = extractJson(text);\n const validatedContent = schema.parse(extractedJSON) as T;\n\n return {\n fileContent: validatedContent,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;;;;;;;;;AAgCA,MAAa,mBAA8B;CACzC,UAAUA,mCAAW;CACrB,OAAO;AACT;;;;;;;AAQA,MAAM,wBAAwB,WAC5B,GAAG,OAAO,QAAIC,2CAAc,QAAQC,6CAAc;;;;;;;;AASpD,MAAM,yBAAyB,SAAwB;CACrD,IAAI,CAAC,QAAQ,KAAK,WAAW,GAC3B,OAAO;CAIT,OAAO;;EAEP,KAAK,KAAK,EAAE,KAAK,kBAAkB,KAAK,IAAI,IAAI,aAAa,CAAC,CAAC,KAAK,MAAM;AAC5E;AAEA,MAAM,uBAAuB,SAAwC;CACnE,IAAI,SAAS,YACX,OAAO;CAGT,OAAO;AACT;AAEA,MAAM,aAAa,YAAgC;CAEjD,IAAI,OAAO,YAAY,UACrB,OAAOC,WAAE,OAAO;CAIlB,IAAI,OAAO,YAAY,UACrB,OAAOA,WAAE,OAAO;CAElB,IAAI,OAAO,YAAY,WACrB,OAAOA,WAAE,QAAQ;CAInB,IAAI,MAAM,QAAQ,OAAO,GAAG;EAE1B,IAAI,QAAQ,WAAW,GACrB,OAAOA,WAAE,MAAMA,WAAE,OAAO,CAAC;EAG3B,OAAOA,WAAE,MAAM,UAAU,QAAQ,EAAE,CAAC;CACtC;CAGA,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM;EACnD,MAAM,QAAuC,CAAC;EAC9C,KAAK,MAAM,OAAO,SAChB,MAAM,OAAO,UAAU,QAAQ,IAAI;EAErC,OAAOA,WAAE,OAAO,KAAK;CACvB;CAGA,OAAOA,WAAE,OAAO;AAClB;AAEA,MAAM,aAAa,QAAqB;CACtC,IAAI,OAAO,QAAQ,YAAY,QAAQ,M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AAO,WAKF;GACvB,WAAW,OAAO,eAAe;EACnC;CACF;CAMA,MAAM,kBAJY,UAAU,gBAII,KAAK;CAGrC,MAAM,EAAE,MAAM,UAAU,UAAMD,iBAAa;EACzC,GAAG;EAGH,QAAQ,kBAAkBE,UAAO,OAAO,EAAE,OAAO,CAAC,IAAI;EACtD,QAAQ;EACR,UAAU,CACR;GACE,MAAM;GACN,SAAS;IACP;IACA;IACA,eAAe;IACf,aAAa;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACF,CAAC,CAAC,KAAK,IAAI;EACb,CACF;CACF,CAAC;CAGD,MAAM,gBAAgBC,sCAAY,IAAI;CAGtC,OAAO;EACL,aAHuB,OAAO,MAAM,aAGR;EAC5B,WAAW,OAAO,eAAe;CACnC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
2
|
+
// src/utils/extractJSON.ts
|
|
3
3
|
/**
|
|
4
4
|
* Extracts and parses the first valid JSON value (object or array) from a string containing arbitrary text.
|
|
5
5
|
* This is used to safely extract JSON from LLM responses that may contain additional text or markdown.
|
|
@@ -72,6 +72,5 @@ const extractJson = (input) => {
|
|
|
72
72
|
throw new Error("Reached end of input without closing JSON bracket.");
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
//#endregion
|
|
76
75
|
exports.extractJson = extractJson;
|
|
77
76
|
//# sourceMappingURL=extractJSON.cjs.map
|
|
@@ -2,7 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// \0utils:asset
|
|
6
6
|
const hereDirname = () => {
|
|
7
7
|
try {
|
|
8
8
|
return dirname(fileURLToPath(import.meta.url));
|
|
@@ -96,5 +96,4 @@ const readAsset = (relPath, encoding = "utf8") => {
|
|
|
96
96
|
throw new Error(msg);
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
//#endregion
|
|
100
99
|
export { readAsset };
|
package/dist/esm/aiSdk.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { generateText } from "ai";
|
|
2
1
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
3
2
|
import { colorize, logger, x } from "@intlayer/config/logger";
|
|
4
3
|
import { AiProviders } from "@intlayer/types/config";
|
|
4
|
+
import { generateText } from "ai";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// src/aiSdk.ts
|
|
7
7
|
const DEFAULT_PROVIDER = AiProviders.ANTHROPIC;
|
|
8
|
-
const DEFAULT_MODEL = "claude-haiku-
|
|
8
|
+
const DEFAULT_MODEL = "claude-haiku-5-5";
|
|
9
9
|
const DEFAULT_API_KEY = process.env.ANTHROPIC_API_KEY;
|
|
10
10
|
const isMaskedKey = (key) => !!key?.includes("*");
|
|
11
11
|
const getAPIKey = (accessType, aiOptions, isAuthenticated = false) => {
|
|
@@ -246,6 +246,5 @@ const getAIConfig = async (options, isAuthenticated = false) => {
|
|
|
246
246
|
};
|
|
247
247
|
};
|
|
248
248
|
|
|
249
|
-
//#endregion
|
|
250
249
|
export { AiProviders as AIProvider, checkAISDKAccess, getAIConfig };
|
|
251
250
|
//# sourceMappingURL=aiSdk.mjs.map
|
package/dist/esm/aiSdk.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSdk.mjs","names":["generateTextFn"],"sources":["../../src/aiSdk.ts"],"sourcesContent":["import type { AlibabaProvider, createAlibaba } from '@ai-sdk/alibaba';\nimport type {\n AmazonBedrockProvider,\n createAmazonBedrock,\n} from '@ai-sdk/amazon-bedrock';\nimport type { AnthropicProvider, createAnthropic } from '@ai-sdk/anthropic';\nimport type { createDeepSeek, DeepSeekProvider } from '@ai-sdk/deepseek';\nimport type { createFireworks, FireworksProvider } from '@ai-sdk/fireworks';\nimport type {\n createGoogleGenerativeAI,\n GoogleGenerativeAIProvider,\n} from '@ai-sdk/google';\nimport type {\n createVertex,\n GoogleVertexProvider as VertexProvider,\n} from '@ai-sdk/google-vertex';\nimport type { createGroq, GroqProvider } from '@ai-sdk/groq';\nimport type {\n createHuggingFace,\n HuggingFaceProvider,\n} from '@ai-sdk/huggingface';\nimport type { createMistral, MistralProvider } from '@ai-sdk/mistral';\nimport type { createMoonshotAI, MoonshotAIProvider } from '@ai-sdk/moonshotai';\nimport type { createOpenAI, OpenAIProvider } from '@ai-sdk/openai';\nimport type {\n createOpenAICompatible,\n OpenAICompatibleProvider,\n} from '@ai-sdk/openai-compatible';\nimport type { createTogetherAI, TogetherAIProvider } from '@ai-sdk/togetherai';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, logger, x } from '@intlayer/config/logger';\nimport { AiProviders } from '@intlayer/types/config';\nimport type {\n createOpenRouter,\n OpenRouterProvider,\n} from '@openrouter/ai-sdk-provider';\nimport type {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\nimport { generateText as generateTextFn } from 'ai';\n\nconst DEFAULT_PROVIDER = AiProviders.ANTHROPIC;\nconst DEFAULT_MODEL = 'claude-haiku-4-5';\nconst DEFAULT_API_KEY = process.env.ANTHROPIC_API_KEY;\n\nexport { AiProviders as AIProvider };\n\ntype AnthropicModel = Parameters<AnthropicProvider>[0];\ntype DeepSeekModel = Parameters<DeepSeekProvider>[0];\ntype MistralModel = Parameters<MistralProvider>[0];\ntype OpenAIModel = Parameters<OpenAIProvider>[0];\ntype OpenRouterModel = Parameters<OpenRouterProvider>[0];\ntype GoogleModel = Parameters<GoogleGenerativeAIProvider>[0];\ntype VertexModel = Parameters<VertexProvider>[0];\ntype AlibabaModel = Parameters<AlibabaProvider>[0];\ntype AmazonBedrockModel = Parameters<AmazonBedrockProvider>[0];\ntype FireworksModel = Parameters<FireworksProvider>[0];\ntype GroqModel = Parameters<GroqProvider>[0];\ntype HuggingFaceModel = Parameters<HuggingFaceProvider>[0];\ntype TogetherAIModel = Parameters<TogetherAIProvider>[0];\ntype LMStudioModel = Parameters<OpenAICompatibleProvider>[0];\ntype MoonshotAIModel = Parameters<MoonshotAIProvider>[0];\n\nexport type OpenAIProviderOptions = Parameters<typeof createOpenAI>[0];\nexport type AnthropicProviderOptions = Parameters<typeof createAnthropic>[0];\nexport type MistralProviderOptions = Parameters<typeof createMistral>[0];\nexport type DeepSeekProviderOptions = Parameters<typeof createDeepSeek>[0];\nexport type GoogleProviderOptions = Parameters<\n typeof createGoogleGenerativeAI\n>[0];\nexport type VertexProviderOptions = Parameters<typeof createVertex>[0];\nexport type OpenRouterProviderOptions = Parameters<typeof createOpenRouter>[0];\nexport type AlibabaProviderOptions = Parameters<typeof createAlibaba>[0];\nexport type FireworksProviderOptions = Parameters<typeof createFireworks>[0];\nexport type GroqProviderOptions = Parameters<typeof createGroq>[0];\nexport type HuggingFaceProviderOptions = Parameters<\n typeof createHuggingFace\n>[0];\nexport type AmazonBedrockProviderOptions = Parameters<\n typeof createAmazonBedrock\n>[0];\nexport type TogetherAIProviderOptions = Parameters<typeof createTogetherAI>[0];\nexport type LMStudioProviderOptions = Parameters<\n typeof createOpenAICompatible\n>[0];\nexport type MoonshotAIProviderOptions = Parameters<typeof createMoonshotAI>[0];\n\nexport type SystemMessage =\n | string\n | SystemModelMessage\n | SystemModelMessage[]\n | undefined;\n\nexport type Messages = (\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 | OpenRouterModel\n | GoogleModel\n | VertexModel\n | AlibabaModel\n | AmazonBedrockModel\n | FireworksModel\n | GroqModel\n | HuggingFaceModel\n | TogetherAIModel\n | LMStudioModel\n | MoonshotAIModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\n\nexport type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'none';\n\n/**\n * Common options for all AI providers\n */\ntype CommonAIOptions = {\n model?: Model;\n temperature?: number;\n baseURL?: string;\n apiKey?: string;\n applicationContext?: string;\n dataSerialization?: 'json' | 'toon';\n};\n\nexport type AIOptions = (\n | ({\n provider: AiProviders.OPENAI | `${AiProviders.OPENAI}`;\n } & OpenAIProviderOptions)\n | ({\n provider: AiProviders.ANTHROPIC | `${AiProviders.ANTHROPIC}`;\n } & AnthropicProviderOptions)\n | ({\n provider: AiProviders.MISTRAL | `${AiProviders.MISTRAL}`;\n } & MistralProviderOptions)\n | ({\n provider: AiProviders.DEEPSEEK | `${AiProviders.DEEPSEEK}`;\n } & DeepSeekProviderOptions)\n | ({\n provider: AiProviders.GEMINI | `${AiProviders.GEMINI}`;\n } & GoogleProviderOptions)\n | ({\n provider:\n | AiProviders.GOOGLEGENERATIVEAI\n | `${AiProviders.GOOGLEGENERATIVEAI}`;\n } & GoogleProviderOptions)\n | ({\n provider: AiProviders.OLLAMA | `${AiProviders.OLLAMA}`;\n } & OpenAIProviderOptions)\n | ({\n provider: AiProviders.OPENROUTER | `${AiProviders.OPENROUTER}`;\n } & OpenRouterProviderOptions)\n | ({\n provider: AiProviders.ALIBABA | `${AiProviders.ALIBABA}`;\n } & AlibabaProviderOptions)\n | ({\n provider: AiProviders.FIREWORKS | `${AiProviders.FIREWORKS}`;\n } & FireworksProviderOptions)\n | ({\n provider: AiProviders.GROQ | `${AiProviders.GROQ}`;\n } & GroqProviderOptions)\n | ({\n provider: AiProviders.HUGGINGFACE | `${AiProviders.HUGGINGFACE}`;\n } & HuggingFaceProviderOptions)\n | ({\n provider: AiProviders.BEDROCK | `${AiProviders.BEDROCK}`;\n } & AmazonBedrockProviderOptions)\n | ({\n provider: AiProviders.GOOGLEVERTEX | `${AiProviders.GOOGLEVERTEX}`;\n } & VertexProviderOptions)\n | ({\n provider: AiProviders.TOGETHERAI | `${AiProviders.TOGETHERAI}`;\n } & TogetherAIProviderOptions)\n | ({\n provider: AiProviders.LMSTUDIO | `${AiProviders.LMSTUDIO}`;\n } & LMStudioProviderOptions)\n | ({\n provider: AiProviders.MOONSHOTAI | `${AiProviders.MOONSHOTAI}`;\n } & MoonshotAIProviderOptions)\n | ({ provider?: undefined } & OpenAIProviderOptions)\n) &\n CommonAIOptions;\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 isMaskedKey = (key?: string): boolean => !!key?.includes('*');\n\nconst getAPIKey = (\n accessType: AccessType[],\n aiOptions?: AIOptions,\n isAuthenticated: boolean = false\n) => {\n const apiKey =\n aiOptions?.apiKey && !isMaskedKey(aiOptions.apiKey)\n ? aiOptions.apiKey\n : undefined;\n\n if (accessType.includes('public')) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n if (accessType.includes('apiKey') && apiKey) {\n return apiKey;\n }\n\n if (accessType.includes('registered_user') && isAuthenticated) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && isAuthenticated) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n return undefined;\n};\n\nconst getModelName = (\n provider: AiProviders,\n isUserProvidedKey: boolean,\n userModel?: Model\n): Model => {\n // If the user provides their own API key, allow custom model selection\n if (\n isUserProvidedKey ||\n provider === AiProviders.OLLAMA ||\n provider === AiProviders.LMSTUDIO\n ) {\n if (userModel) {\n return userModel;\n }\n\n // No custom model specified — fall back to the default\n return DEFAULT_MODEL;\n }\n\n // Using backend's default API key — always use the default model,\n // ignore any custom model the user may have passed\n return DEFAULT_MODEL;\n};\n\nconst getLanguageModel = async (\n aiOptions: AIOptions,\n apiKey: string | undefined\n) => {\n const loadModule = async <T>(packageName: string): Promise<T> => {\n try {\n return (await import(packageName)) as T;\n } catch {\n logger(\n `${x} The package \"${colorize(packageName, ANSIColors.GREEN)}\" is required to use this AI provider. Please install it using: ${colorize(`npm install ${packageName}`, ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n );\n process.exit();\n }\n };\n\n const provider = aiOptions.provider ?? AiProviders.OPENAI;\n const selectedModel = getModelName(\n provider as AiProviders,\n !!aiOptions.apiKey, // true only when the user explicitly provided their own key\n aiOptions.model\n );\n\n const baseURL = aiOptions.baseURL;\n\n switch (provider) {\n case AiProviders.OPENAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAI } =\n await loadModule<typeof import('@ai-sdk/openai')>('@ai-sdk/openai');\n\n return createOpenAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.ANTHROPIC: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAnthropic } =\n await loadModule<typeof import('@ai-sdk/anthropic')>(\n '@ai-sdk/anthropic'\n );\n\n return createAnthropic({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.MISTRAL: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createMistral } =\n await loadModule<typeof import('@ai-sdk/mistral')>('@ai-sdk/mistral');\n\n return createMistral({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.DEEPSEEK: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createDeepSeek } =\n await loadModule<typeof import('@ai-sdk/deepseek')>('@ai-sdk/deepseek');\n\n return createDeepSeek({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.GEMINI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGoogleGenerativeAI } =\n await loadModule<typeof import('@ai-sdk/google')>('@ai-sdk/google');\n\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.GOOGLEVERTEX: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createVertex } = await loadModule<\n typeof import('@ai-sdk/google-vertex')\n >('@ai-sdk/google-vertex');\n\n return createVertex({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel as string);\n }\n\n case AiProviders.GOOGLEGENERATIVEAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGoogleGenerativeAI } =\n await loadModule<typeof import('@ai-sdk/google')>('@ai-sdk/google');\n\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel as string);\n }\n\n case AiProviders.OLLAMA: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAI } =\n await loadModule<typeof import('@ai-sdk/openai')>('@ai-sdk/openai');\n\n // Ollama compatible mode:\n const ollama = createOpenAI({\n baseURL: baseURL ?? 'http://localhost:11434/v1',\n apiKey: apiKey ?? 'ollama', // Required but unused by Ollama\n ...otherOptions,\n });\n\n return ollama.chat(selectedModel);\n }\n\n case AiProviders.OPENROUTER: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenRouter } = await loadModule<\n typeof import('@openrouter/ai-sdk-provider')\n >('@openrouter/ai-sdk-provider');\n\n const openrouter = createOpenRouter({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return openrouter(selectedModel as string);\n }\n\n case AiProviders.ALIBABA: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAlibaba } =\n await loadModule<typeof import('@ai-sdk/alibaba')>('@ai-sdk/alibaba');\n\n const alibaba = createAlibaba({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return alibaba(selectedModel as string);\n }\n\n case AiProviders.FIREWORKS: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createFireworks } =\n await loadModule<typeof import('@ai-sdk/fireworks')>(\n '@ai-sdk/fireworks'\n );\n\n const fireworks = createFireworks({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return fireworks(selectedModel as string);\n }\n\n case AiProviders.GROQ: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGroq } =\n await loadModule<typeof import('@ai-sdk/groq')>('@ai-sdk/groq');\n\n const groq = createGroq({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return groq(selectedModel as string);\n }\n\n case AiProviders.HUGGINGFACE: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createHuggingFace } = await loadModule<\n typeof import('@ai-sdk/huggingface')\n >('@ai-sdk/huggingface');\n\n const huggingface = createHuggingFace({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return huggingface(selectedModel as string);\n }\n\n case AiProviders.BEDROCK: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAmazonBedrock } = await loadModule<\n typeof import('@ai-sdk/amazon-bedrock')\n >('@ai-sdk/amazon-bedrock');\n\n const bedrock = createAmazonBedrock({\n accessKeyId: apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return bedrock(selectedModel as string);\n }\n\n case AiProviders.TOGETHERAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createTogetherAI } =\n await loadModule<typeof import('@ai-sdk/togetherai')>(\n '@ai-sdk/togetherai'\n );\n\n const togetherai = createTogetherAI({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return togetherai(selectedModel as string);\n }\n\n case AiProviders.LMSTUDIO: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAICompatible } = await loadModule<\n typeof import('@ai-sdk/openai-compatible')\n >('@ai-sdk/openai-compatible');\n\n const lmstudio = createOpenAICompatible({\n name: 'lmstudio',\n baseURL: baseURL ?? 'http://localhost:1234/v1',\n ...otherOptions,\n });\n\n return lmstudio(selectedModel as string);\n }\n\n case AiProviders.MOONSHOTAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createMoonshotAI } =\n await loadModule<typeof import('@ai-sdk/moonshotai')>(\n '@ai-sdk/moonshotai'\n );\n\n const moonshotai = createMoonshotAI({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return moonshotai(selectedModel as string);\n }\n\n default: {\n throw new Error(`Provider ${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 dataSerialization?: 'json' | 'toon';\n};\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n projectOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Sends a minimal request to verify that the configured AI provider credentials\n * are valid and reachable before starting any bulk operation.\n *\n * @returns true if access is confirmed, false otherwise\n */\nexport const checkAISDKAccess = async (\n aiConfig: AIConfig\n): Promise<{ hasAIAccess: boolean; error?: string }> => {\n try {\n await generateTextFn({\n ...aiConfig,\n messages: [\n {\n role: 'user',\n content: 'ping',\n },\n ],\n maxOutputTokens: 20,\n });\n return { hasAIAccess: true };\n } catch (error) {\n return { hasAIAccess: false, error: (error as Error).message };\n }\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 projectOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const mergeWithoutUndefined = (...sources: (AIOptions | undefined)[]) => {\n const result: Record<string, unknown> = { provider: DEFAULT_PROVIDER };\n for (const source of sources) {\n if (!source) continue;\n for (const [key, value] of Object.entries(source)) {\n if (value === undefined) continue;\n if (key === 'apiKey' && isMaskedKey(value as string)) continue;\n result[key] = value;\n }\n }\n return result;\n };\n\n const aiOptions = mergeWithoutUndefined(\n defaultOptions,\n projectOptions,\n userOptions\n ) as AIOptions;\n\n const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);\n\n // Check if API key is provided\n if (\n !apiKey &&\n aiOptions.provider !== AiProviders.OLLAMA &&\n aiOptions.provider !== AiProviders.LMSTUDIO\n ) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const languageModel = await getLanguageModel(aiOptions, apiKey);\n\n return {\n model: languageModel,\n temperature: aiOptions.temperature,\n dataSerialization: aiOptions.dataSerialization,\n };\n};\n"],"mappings":";;;;;;AA6CA,MAAM,mBAAmB,YAAY;AACrC,MAAM,gBAAgB;AACtB,MAAM,kBAAkB,QAAQ,IAAI;AAkKpC,MAAM,eAAe,QAA0B,CAAC,CAAC,KAAK,SAAS,GAAG;AAElE,MAAM,aACJ,YACA,WACA,kBAA2B,UACxB;CACH,MAAM,SACJ,WAAW,UAAU,CAAC,YAAY,UAAU,MAAM,IAC9C,UAAU,SACV;CAEN,IAAI,WAAW,SAAS,QAAQ,GAC9B,OAAO,UAAU;CAGnB,IAAI,WAAW,SAAS,QAAQ,KAAK,QACnC,OAAO;CAGT,IAAI,WAAW,SAAS,iBAAiB,KAAK,iBAC5C,OAAO,UAAU;CAInB,IAAI,WAAW,SAAS,cAAc,KAAK,iBACzC,OAAO,UAAU;AAIrB;AAEA,MAAM,gBACJ,UACA,mBACA,cACU;CAEV,IACE,qBACA,aAAa,YAAY,UACzB,aAAa,YAAY,UACzB;EACA,IAAI,WACF,OAAO;EAIT,OAAO;CACT;CAIA,OAAO;AACT;AAEA,MAAM,mBAAmB,OACvB,WACA,WACG;CACH,MAAM,aAAa,OAAU,gBAAoC;EAC/D,IAAI;GACF,OAAQ,MAAM,OAAO;EACvB,QAAQ;GACN,OACE,GAAG,EAAE,gBAAgB,SAAS,aAAa,WAAW,KAAK,EAAE,kEAAkE,SAAS,eAAe,eAAe,WAAW,SAAS,KAC1L,EACE,OAAO,QACT,CACF;GACA,QAAQ,KAAK;EACf;CACF;CAEA,MAAM,WAAW,UAAU,YAAY,YAAY;CACnD,MAAM,gBAAgB,aACpB,UACA,CAAC,CAAC,UAAU,QACZ,UAAU,KACZ;CAEA,MAAM,UAAU,UAAU;CAE1B,QAAQ,UAAR;EACE,KAAK,YAA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,MAAM;EAI5D,aAAa,UAAU;EACvB,mBAAmB,UAAU;CAC/B;AACF"}
|
|
1
|
+
{"version":3,"file":"aiSdk.mjs","names":["generateTextFn"],"sources":["../../src/aiSdk.ts"],"sourcesContent":["import type { AlibabaProvider, createAlibaba } from '@ai-sdk/alibaba';\nimport type {\n AmazonBedrockProvider,\n createAmazonBedrock,\n} from '@ai-sdk/amazon-bedrock';\nimport type { AnthropicProvider, createAnthropic } from '@ai-sdk/anthropic';\nimport type { createDeepSeek, DeepSeekProvider } from '@ai-sdk/deepseek';\nimport type { createFireworks, FireworksProvider } from '@ai-sdk/fireworks';\nimport type {\n createGoogleGenerativeAI,\n GoogleGenerativeAIProvider,\n} from '@ai-sdk/google';\nimport type {\n createVertex,\n GoogleVertexProvider as VertexProvider,\n} from '@ai-sdk/google-vertex';\nimport type { createGroq, GroqProvider } from '@ai-sdk/groq';\nimport type {\n createHuggingFace,\n HuggingFaceProvider,\n} from '@ai-sdk/huggingface';\nimport type { createMistral, MistralProvider } from '@ai-sdk/mistral';\nimport type { createMoonshotAI, MoonshotAIProvider } from '@ai-sdk/moonshotai';\nimport type { createOpenAI, OpenAIProvider } from '@ai-sdk/openai';\nimport type {\n createOpenAICompatible,\n OpenAICompatibleProvider,\n} from '@ai-sdk/openai-compatible';\nimport type { createTogetherAI, TogetherAIProvider } from '@ai-sdk/togetherai';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, logger, x } from '@intlayer/config/logger';\nimport { AiProviders } from '@intlayer/types/config';\nimport type {\n createOpenRouter,\n OpenRouterProvider,\n} from '@openrouter/ai-sdk-provider';\nimport type {\n AssistantModelMessage,\n generateText,\n SystemModelMessage,\n ToolModelMessage,\n UserModelMessage,\n} from 'ai';\nimport { generateText as generateTextFn } from 'ai';\n\nconst DEFAULT_PROVIDER = AiProviders.ANTHROPIC;\nconst DEFAULT_MODEL = 'claude-haiku-5-5';\nconst DEFAULT_API_KEY = process.env.ANTHROPIC_API_KEY;\n\nexport { AiProviders as AIProvider };\n\ntype AnthropicModel = Parameters<AnthropicProvider>[0];\ntype DeepSeekModel = Parameters<DeepSeekProvider>[0];\ntype MistralModel = Parameters<MistralProvider>[0];\ntype OpenAIModel = Parameters<OpenAIProvider>[0];\ntype OpenRouterModel = Parameters<OpenRouterProvider>[0];\ntype GoogleModel = Parameters<GoogleGenerativeAIProvider>[0];\ntype VertexModel = Parameters<VertexProvider>[0];\ntype AlibabaModel = Parameters<AlibabaProvider>[0];\ntype AmazonBedrockModel = Parameters<AmazonBedrockProvider>[0];\ntype FireworksModel = Parameters<FireworksProvider>[0];\ntype GroqModel = Parameters<GroqProvider>[0];\ntype HuggingFaceModel = Parameters<HuggingFaceProvider>[0];\ntype TogetherAIModel = Parameters<TogetherAIProvider>[0];\ntype LMStudioModel = Parameters<OpenAICompatibleProvider>[0];\ntype MoonshotAIModel = Parameters<MoonshotAIProvider>[0];\n\nexport type OpenAIProviderOptions = Parameters<typeof createOpenAI>[0];\nexport type AnthropicProviderOptions = Parameters<typeof createAnthropic>[0];\nexport type MistralProviderOptions = Parameters<typeof createMistral>[0];\nexport type DeepSeekProviderOptions = Parameters<typeof createDeepSeek>[0];\nexport type GoogleProviderOptions = Parameters<\n typeof createGoogleGenerativeAI\n>[0];\nexport type VertexProviderOptions = Parameters<typeof createVertex>[0];\nexport type OpenRouterProviderOptions = Parameters<typeof createOpenRouter>[0];\nexport type AlibabaProviderOptions = Parameters<typeof createAlibaba>[0];\nexport type FireworksProviderOptions = Parameters<typeof createFireworks>[0];\nexport type GroqProviderOptions = Parameters<typeof createGroq>[0];\nexport type HuggingFaceProviderOptions = Parameters<\n typeof createHuggingFace\n>[0];\nexport type AmazonBedrockProviderOptions = Parameters<\n typeof createAmazonBedrock\n>[0];\nexport type TogetherAIProviderOptions = Parameters<typeof createTogetherAI>[0];\nexport type LMStudioProviderOptions = Parameters<\n typeof createOpenAICompatible\n>[0];\nexport type MoonshotAIProviderOptions = Parameters<typeof createMoonshotAI>[0];\n\nexport type SystemMessage =\n | string\n | SystemModelMessage\n | SystemModelMessage[]\n | undefined;\n\nexport type Messages = (\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 | OpenRouterModel\n | GoogleModel\n | VertexModel\n | AlibabaModel\n | AmazonBedrockModel\n | FireworksModel\n | GroqModel\n | HuggingFaceModel\n | TogetherAIModel\n | LMStudioModel\n | MoonshotAIModel\n | (string & {});\n\n/**\n * Supported AI SDK providers\n */\n\nexport type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'none';\n\n/**\n * Common options for all AI providers\n */\ntype CommonAIOptions = {\n model?: Model;\n temperature?: number;\n baseURL?: string;\n apiKey?: string;\n applicationContext?: string;\n dataSerialization?: 'json' | 'toon';\n};\n\nexport type AIOptions = (\n | ({\n provider: AiProviders.OPENAI | `${AiProviders.OPENAI}`;\n } & OpenAIProviderOptions)\n | ({\n provider: AiProviders.ANTHROPIC | `${AiProviders.ANTHROPIC}`;\n } & AnthropicProviderOptions)\n | ({\n provider: AiProviders.MISTRAL | `${AiProviders.MISTRAL}`;\n } & MistralProviderOptions)\n | ({\n provider: AiProviders.DEEPSEEK | `${AiProviders.DEEPSEEK}`;\n } & DeepSeekProviderOptions)\n | ({\n provider: AiProviders.GEMINI | `${AiProviders.GEMINI}`;\n } & GoogleProviderOptions)\n | ({\n provider:\n | AiProviders.GOOGLEGENERATIVEAI\n | `${AiProviders.GOOGLEGENERATIVEAI}`;\n } & GoogleProviderOptions)\n | ({\n provider: AiProviders.OLLAMA | `${AiProviders.OLLAMA}`;\n } & OpenAIProviderOptions)\n | ({\n provider: AiProviders.OPENROUTER | `${AiProviders.OPENROUTER}`;\n } & OpenRouterProviderOptions)\n | ({\n provider: AiProviders.ALIBABA | `${AiProviders.ALIBABA}`;\n } & AlibabaProviderOptions)\n | ({\n provider: AiProviders.FIREWORKS | `${AiProviders.FIREWORKS}`;\n } & FireworksProviderOptions)\n | ({\n provider: AiProviders.GROQ | `${AiProviders.GROQ}`;\n } & GroqProviderOptions)\n | ({\n provider: AiProviders.HUGGINGFACE | `${AiProviders.HUGGINGFACE}`;\n } & HuggingFaceProviderOptions)\n | ({\n provider: AiProviders.BEDROCK | `${AiProviders.BEDROCK}`;\n } & AmazonBedrockProviderOptions)\n | ({\n provider: AiProviders.GOOGLEVERTEX | `${AiProviders.GOOGLEVERTEX}`;\n } & VertexProviderOptions)\n | ({\n provider: AiProviders.TOGETHERAI | `${AiProviders.TOGETHERAI}`;\n } & TogetherAIProviderOptions)\n | ({\n provider: AiProviders.LMSTUDIO | `${AiProviders.LMSTUDIO}`;\n } & LMStudioProviderOptions)\n | ({\n provider: AiProviders.MOONSHOTAI | `${AiProviders.MOONSHOTAI}`;\n } & MoonshotAIProviderOptions)\n | ({ provider?: undefined } & OpenAIProviderOptions)\n) &\n CommonAIOptions;\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 isMaskedKey = (key?: string): boolean => !!key?.includes('*');\n\nconst getAPIKey = (\n accessType: AccessType[],\n aiOptions?: AIOptions,\n isAuthenticated: boolean = false\n) => {\n const apiKey =\n aiOptions?.apiKey && !isMaskedKey(aiOptions.apiKey)\n ? aiOptions.apiKey\n : undefined;\n\n if (accessType.includes('public')) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n if (accessType.includes('apiKey') && apiKey) {\n return apiKey;\n }\n\n if (accessType.includes('registered_user') && isAuthenticated) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && isAuthenticated) {\n return apiKey ?? DEFAULT_API_KEY;\n }\n\n return undefined;\n};\n\nconst getModelName = (\n provider: AiProviders,\n isUserProvidedKey: boolean,\n userModel?: Model\n): Model => {\n // If the user provides their own API key, allow custom model selection\n if (\n isUserProvidedKey ||\n provider === AiProviders.OLLAMA ||\n provider === AiProviders.LMSTUDIO\n ) {\n if (userModel) {\n return userModel;\n }\n\n // No custom model specified — fall back to the default\n return DEFAULT_MODEL;\n }\n\n // Using backend's default API key — always use the default model,\n // ignore any custom model the user may have passed\n return DEFAULT_MODEL;\n};\n\nconst getLanguageModel = async (\n aiOptions: AIOptions,\n apiKey: string | undefined\n) => {\n const loadModule = async <T>(packageName: string): Promise<T> => {\n try {\n return (await import(packageName)) as T;\n } catch {\n logger(\n `${x} The package \"${colorize(packageName, ANSIColors.GREEN)}\" is required to use this AI provider. Please install it using: ${colorize(`npm install ${packageName}`, ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n );\n process.exit();\n }\n };\n\n const provider = aiOptions.provider ?? AiProviders.OPENAI;\n const selectedModel = getModelName(\n provider as AiProviders,\n !!aiOptions.apiKey, // true only when the user explicitly provided their own key\n aiOptions.model\n );\n\n const baseURL = aiOptions.baseURL;\n\n switch (provider) {\n case AiProviders.OPENAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAI } =\n await loadModule<typeof import('@ai-sdk/openai')>('@ai-sdk/openai');\n\n return createOpenAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.ANTHROPIC: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAnthropic } =\n await loadModule<typeof import('@ai-sdk/anthropic')>(\n '@ai-sdk/anthropic'\n );\n\n return createAnthropic({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.MISTRAL: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createMistral } =\n await loadModule<typeof import('@ai-sdk/mistral')>('@ai-sdk/mistral');\n\n return createMistral({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.DEEPSEEK: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createDeepSeek } =\n await loadModule<typeof import('@ai-sdk/deepseek')>('@ai-sdk/deepseek');\n\n return createDeepSeek({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.GEMINI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGoogleGenerativeAI } =\n await loadModule<typeof import('@ai-sdk/google')>('@ai-sdk/google');\n\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel);\n }\n\n case AiProviders.GOOGLEVERTEX: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createVertex } = await loadModule<\n typeof import('@ai-sdk/google-vertex')\n >('@ai-sdk/google-vertex');\n\n return createVertex({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel as string);\n }\n\n case AiProviders.GOOGLEGENERATIVEAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGoogleGenerativeAI } =\n await loadModule<typeof import('@ai-sdk/google')>('@ai-sdk/google');\n\n return createGoogleGenerativeAI({\n apiKey,\n baseURL,\n ...otherOptions,\n })(selectedModel as string);\n }\n\n case AiProviders.OLLAMA: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAI } =\n await loadModule<typeof import('@ai-sdk/openai')>('@ai-sdk/openai');\n\n // Ollama compatible mode:\n const ollama = createOpenAI({\n baseURL: baseURL ?? 'http://localhost:11434/v1',\n apiKey: apiKey ?? 'ollama', // Required but unused by Ollama\n ...otherOptions,\n });\n\n return ollama.chat(selectedModel);\n }\n\n case AiProviders.OPENROUTER: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenRouter } = await loadModule<\n typeof import('@openrouter/ai-sdk-provider')\n >('@openrouter/ai-sdk-provider');\n\n const openrouter = createOpenRouter({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return openrouter(selectedModel as string);\n }\n\n case AiProviders.ALIBABA: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAlibaba } =\n await loadModule<typeof import('@ai-sdk/alibaba')>('@ai-sdk/alibaba');\n\n const alibaba = createAlibaba({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return alibaba(selectedModel as string);\n }\n\n case AiProviders.FIREWORKS: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createFireworks } =\n await loadModule<typeof import('@ai-sdk/fireworks')>(\n '@ai-sdk/fireworks'\n );\n\n const fireworks = createFireworks({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return fireworks(selectedModel as string);\n }\n\n case AiProviders.GROQ: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createGroq } =\n await loadModule<typeof import('@ai-sdk/groq')>('@ai-sdk/groq');\n\n const groq = createGroq({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return groq(selectedModel as string);\n }\n\n case AiProviders.HUGGINGFACE: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createHuggingFace } = await loadModule<\n typeof import('@ai-sdk/huggingface')\n >('@ai-sdk/huggingface');\n\n const huggingface = createHuggingFace({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return huggingface(selectedModel as string);\n }\n\n case AiProviders.BEDROCK: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createAmazonBedrock } = await loadModule<\n typeof import('@ai-sdk/amazon-bedrock')\n >('@ai-sdk/amazon-bedrock');\n\n const bedrock = createAmazonBedrock({\n accessKeyId: apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return bedrock(selectedModel as string);\n }\n\n case AiProviders.TOGETHERAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createTogetherAI } =\n await loadModule<typeof import('@ai-sdk/togetherai')>(\n '@ai-sdk/togetherai'\n );\n\n const togetherai = createTogetherAI({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return togetherai(selectedModel as string);\n }\n\n case AiProviders.LMSTUDIO: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createOpenAICompatible } = await loadModule<\n typeof import('@ai-sdk/openai-compatible')\n >('@ai-sdk/openai-compatible');\n\n const lmstudio = createOpenAICompatible({\n name: 'lmstudio',\n baseURL: baseURL ?? 'http://localhost:1234/v1',\n ...otherOptions,\n });\n\n return lmstudio(selectedModel as string);\n }\n\n case AiProviders.MOONSHOTAI: {\n const {\n provider,\n model,\n temperature,\n applicationContext,\n dataSerialization,\n apiKey: _apiKey,\n baseURL: _baseURL,\n ...otherOptions\n } = aiOptions as any;\n\n const { createMoonshotAI } =\n await loadModule<typeof import('@ai-sdk/moonshotai')>(\n '@ai-sdk/moonshotai'\n );\n\n const moonshotai = createMoonshotAI({\n apiKey,\n baseURL,\n ...otherOptions,\n });\n\n return moonshotai(selectedModel as string);\n }\n\n default: {\n throw new Error(`Provider ${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 dataSerialization?: 'json' | 'toon';\n};\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n projectOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Sends a minimal request to verify that the configured AI provider credentials\n * are valid and reachable before starting any bulk operation.\n *\n * @returns true if access is confirmed, false otherwise\n */\nexport const checkAISDKAccess = async (\n aiConfig: AIConfig\n): Promise<{ hasAIAccess: boolean; error?: string }> => {\n try {\n await generateTextFn({\n ...aiConfig,\n messages: [\n {\n role: 'user',\n content: 'ping',\n },\n ],\n maxOutputTokens: 20,\n });\n return { hasAIAccess: true };\n } catch (error) {\n return { hasAIAccess: false, error: (error as Error).message };\n }\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 projectOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const mergeWithoutUndefined = (...sources: (AIOptions | undefined)[]) => {\n const result: Record<string, unknown> = { provider: DEFAULT_PROVIDER };\n for (const source of sources) {\n if (!source) continue;\n for (const [key, value] of Object.entries(source)) {\n if (value === undefined) continue;\n if (key === 'apiKey' && isMaskedKey(value as string)) continue;\n result[key] = value;\n }\n }\n return result;\n };\n\n const aiOptions = mergeWithoutUndefined(\n defaultOptions,\n projectOptions,\n userOptions\n ) as AIOptions;\n\n const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);\n\n // Check if API key is provided\n if (\n !apiKey &&\n aiOptions.provider !== AiProviders.OLLAMA &&\n aiOptions.provider !== AiProviders.LMSTUDIO\n ) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const languageModel = await getLanguageModel(aiOptions, apiKey);\n\n return {\n model: languageModel,\n temperature: aiOptions.temperature,\n dataSerialization: aiOptions.dataSerialization,\n };\n};\n"],"mappings":";;;;;;AA6CA,MAAM,mBAAmB,YAAY;AACrC,MAAM,gBAAgB;AACtB,MAAM,kBAAkB,QAAQ,IAAI;AAkKpC,MAAM,eAAe,QAA0B,CAAC,CAAC,KAAK,SAAS,GAAG;AAElE,MAAM,aACJ,YACA,WACA,kBAA2B,UACxB;CACH,MAAM,SACJ,WAAW,UAAU,CAAC,YAAY,UAAU,MAAM,IAC9C,UAAU,SACV;CAEN,IAAI,WAAW,SAAS,QAAQ,GAC9B,OAAO,UAAU;CAGnB,IAAI,WAAW,SAAS,QAAQ,KAAK,QACnC,OAAO;CAGT,IAAI,WAAW,SAAS,iBAAiB,KAAK,iBAC5C,OAAO,UAAU;CAInB,IAAI,WAAW,SAAS,cAAc,KAAK,iBACzC,OAAO,UAAU;AAIrB;AAEA,MAAM,gBACJ,UACA,mBACA,cACU;CAEV,IACE,qBACA,aAAa,YAAY,UACzB,aAAa,YAAY,UACzB;EACA,IAAI,WACF,OAAO;EAIT,OAAO;CACT;CAIA,OAAO;AACT;AAEA,MAAM,mBAAmB,OACvB,WACA,WACG;CACH,MA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AAK,UAAU,OAAO,QAAQ,MAAM,GAAG;IACjD,IAAI,UAAU,QAAW;IACzB,IAAI,QAAQ,YAAY,YAAY,KAAe,GAAG;IACtD,OAAO,OAAO;GAChB;EACF;EACA,OAAO;CACT;CAEA,MAAM,YAAY,sBAChB,gBACA,gBACA,WACF;CAEA,MAAM,SAAS,UAAU,YAAY,WAAW,eAAe;CAG/D,IACE,CAAC,UACD,UAAU,aAAa,YAAY,UACnC,UAAU,aAAa,YAAY,UAEnC,MAAM,IAAI,MAAM,eAAe,UAAU,SAAS,YAAY;CAKhE,OAAO;EACL,OAAO,MAHmB,iBAAiB,WAAW,MAAM;EAI5D,aAAa,UAAU;EACvB,mBAAmB,UAAU;CAC/B;AACF"}
|
|
@@ -2,7 +2,7 @@ import { readAsset } from "../_virtual/_utils_asset.mjs";
|
|
|
2
2
|
import { Output, generateText } from "ai";
|
|
3
3
|
import { z } from "zod/mini";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/auditDictionaryMetadata/index.ts
|
|
6
6
|
const aiDefaultOptions = {};
|
|
7
7
|
/**
|
|
8
8
|
* Audits a content declaration file by constructing a prompt for AI models.
|
|
@@ -45,6 +45,5 @@ const auditDictionaryMetadata = async ({ fileContent, tags, aiConfig, applicatio
|
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
//#endregion
|
|
49
48
|
export { aiDefaultOptions, auditDictionaryMetadata };
|
|
50
49
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/auditDictionaryMetadata/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/auditDictionaryMetadata/index.ts"],"sourcesContent":["import { generateText, Output } from 'ai';\nimport { readAsset } from 'utils:asset';\nimport { z } from 'zod/mini';\nimport type { AIConfig, AIOptions } from '../aiSdk';\n\ntype Tag = {\n key: string;\n description?: string;\n};\n\nexport type AuditDictionaryMetadataOptions = {\n fileContent: string;\n tags?: Tag[];\n aiConfig: AIConfig;\n applicationContext?: string;\n};\n\nexport type AuditFileResultData = {\n fileContent: {\n title: string;\n description: string;\n tags: string[];\n };\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n // Keep default options\n};\n\n/**\n * Audits a content declaration file by constructing a prompt for AI models.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies.\n */\nexport const auditDictionaryMetadata = async ({\n fileContent,\n tags,\n aiConfig,\n applicationContext,\n}: AuditDictionaryMetadataOptions): Promise<\n AuditFileResultData | undefined\n> => {\n const CHAT_GPT_PROMPT = readAsset('./PROMPT.md');\n const EXAMPLE_REQUEST = readAsset('./EXAMPLE_REQUEST.md');\n const EXAMPLE_RESPONSE = readAsset('./EXAMPLE_RESPONSE.md');\n\n // Prepare the prompt for AI by replacing placeholders with actual values.\n const prompt = CHAT_GPT_PROMPT.replace(\n '{{applicationContext}}',\n applicationContext ?? ''\n ).replace(\n '{{tags}}',\n tags\n ? JSON.stringify(\n tags\n .map(({ key, description }) => `- ${key}: ${description}`)\n .join('\\n\\n'),\n null,\n 2\n )\n : ''\n );\n\n const { dataSerialization, ...restAiConfig } = aiConfig;\n const { output: _unusedOutput, ...validAiConfig } = restAiConfig;\n\n // Use the AI SDK to generate the completion\n const { output, usage } = await generateText({\n ...validAiConfig,\n output: Output.object({\n schema: z.object({\n title: z.string(),\n description: z.string(),\n tags: z.array(z.string()),\n }),\n }),\n system: prompt,\n messages: [\n { role: 'user', content: EXAMPLE_REQUEST },\n { role: 'assistant', content: EXAMPLE_RESPONSE },\n {\n role: 'user',\n content: fileContent,\n },\n ],\n });\n\n return {\n fileContent: output,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;;;AA0BA,MAAa,mBAA8B,CAE3C;;;;;;AAOA,MAAa,0BAA0B,OAAO,EAC5C,aACA,MACA,UACA,yBAGG;CACH,MAAM,kBAAkB,UAAU,aAAa;CAC/C,MAAM,kBAAkB,UAAU,sBAAsB;CACxD,MAAM,mBAAmB,UAAU,uBAAuB;CAG1D,MAAM,SAAS,gBAAgB,QAC7B,0BACA,sBAAsB,EACxB,CAAC,CAAC,QACA,YACA,OACI,KAAK,UACH,KACG,KAAK,EAAE,KAAK,kBAAkB,KAAK,IAAI,IAAI,aAAa,CAAC,CACzD,KAAK,MAAM,GACd,MACA,CACF,IACA,EACN;CAEA,MAAM,EAAE,mBAAmB,GAAG,iBAAiB;CAC/C,MAAM,EAAE,QAAQ,eAAe,GAAG,kBAAkB;CAGpD,MAAM,EAAE,QAAQ,UAAU,MAAM,aAAa;EAC3C,GAAG;EACH,QAAQ,OAAO,OAAO,EACpB,QAAQ,EAAE,OAAO;GACf,OAAO,EAAE,OAAO;GAChB,aAAa,EAAE,OAAO;GACtB,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC;EAC1B,CAAC,EACH,CAAC;EACD,QAAQ;EACR,UAAU;GACR;IAAE,MAAM;IAAQ,SAAS;GAAgB;GACzC;IAAE,MAAM;IAAa,SAAS;GAAiB;GAC/C;IACE,MAAM;IACN,SAAS;GACX;EACF;CACF,CAAC;CAED,OAAO;EACL,aAAa;EACb,WAAW,OAAO,eAAe;CACnC;AACF"}
|
package/dist/esm/customQuery.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { generateText } from "ai";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const aiDefaultOptions = { model: "gpt-
|
|
3
|
+
// src/customQuery.ts
|
|
4
|
+
const aiDefaultOptions = { model: "gpt-6-luna" };
|
|
5
5
|
/**
|
|
6
6
|
* CustomQuery a content declaration file by constructing a prompt for AI models.
|
|
7
7
|
* The prompt includes details about the project's locales, file paths of content declarations,
|
|
@@ -19,6 +19,5 @@ const customQuery = async ({ messages, system, aiConfig }) => {
|
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
//#endregion
|
|
23
22
|
export { aiDefaultOptions, customQuery };
|
|
24
23
|
//# sourceMappingURL=customQuery.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customQuery.mjs","names":[],"sources":["../../src/customQuery.ts"],"sourcesContent":["import { generateText, type SystemModelMessage } from 'ai';\nimport type { AIConfig, AIOptions, Messages } from './aiSdk';\n\nexport type CustomQueryOptions = {\n messages: Messages;\n system?: string | SystemModelMessage | SystemModelMessage[];\n aiConfig: AIConfig;\n};\n\nexport type CustomQueryResultData = {\n fileContent: string;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n model: 'gpt-
|
|
1
|
+
{"version":3,"file":"customQuery.mjs","names":[],"sources":["../../src/customQuery.ts"],"sourcesContent":["import { generateText, type SystemModelMessage } from 'ai';\nimport type { AIConfig, AIOptions, Messages } from './aiSdk';\n\nexport type CustomQueryOptions = {\n messages: Messages;\n system?: string | SystemModelMessage | SystemModelMessage[];\n aiConfig: AIConfig;\n};\n\nexport type CustomQueryResultData = {\n fileContent: string;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n model: 'gpt-6-luna',\n // Keep default options\n};\n\n/**\n * CustomQuery a content declaration file by constructing a prompt for AI models.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies.\n */\nexport const customQuery = async ({\n messages,\n system,\n aiConfig,\n}: CustomQueryOptions): Promise<CustomQueryResultData | undefined> => {\n // Use the AI SDK to generate the completion\n const { text: newContent, usage } = await generateText({\n ...aiConfig,\n system,\n messages,\n });\n\n return {\n fileContent: newContent,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;AAcA,MAAa,mBAA8B,EACzC,OAAO,aAET;;;;;;AAOA,MAAa,cAAc,OAAO,EAChC,UACA,QACA,eACoE;CAEpE,MAAM,EAAE,MAAM,YAAY,UAAU,MAAM,aAAa;EACrD,GAAG;EACH;EACA;CACF,CAAC;CAED,OAAO;EACL,aAAa;EACb,WAAW,OAAO,eAAe;CACnC;AACF"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AIProvider as AiProviders, checkAISDKAccess, getAIConfig } from "./aiSdk.mjs";
|
|
2
2
|
import { auditDictionaryMetadata } from "./auditDictionaryMetadata/index.mjs";
|
|
3
3
|
import { customQuery } from "./customQuery.mjs";
|
|
4
|
-
import { extractJson } from "./utils/extractJSON.mjs";
|
|
5
4
|
import { translateJSON } from "./translateJSON/index.mjs";
|
|
5
|
+
import { extractJson } from "./utils/extractJSON.mjs";
|
|
6
6
|
import { generateText, jsonSchema, stepCountIs, streamText, tool } from "ai";
|
|
7
7
|
|
|
8
8
|
export { AiProviders as AIProvider, auditDictionaryMetadata, checkAISDKAccess, customQuery, extractJson, generateText, getAIConfig, jsonSchema, stepCountIs, streamText, tool, translateJSON };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AIProvider as AiProviders } from "../aiSdk.mjs";
|
|
2
1
|
import { readAsset } from "../_virtual/_utils_asset.mjs";
|
|
2
|
+
import { AIProvider as AiProviders } from "../aiSdk.mjs";
|
|
3
3
|
import { extractJson } from "../utils/extractJSON.mjs";
|
|
4
4
|
import { Output, generateText } from "ai";
|
|
5
5
|
import { z } from "zod/mini";
|
|
@@ -7,10 +7,10 @@ import { DEFAULT_LOCALE } from "@intlayer/config/defaultValues";
|
|
|
7
7
|
import { getLocaleName } from "@intlayer/core/localization";
|
|
8
8
|
import { decode, encode } from "@toon-format/toon";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// src/translateJSON/index.ts
|
|
11
11
|
const aiDefaultOptions = {
|
|
12
12
|
provider: AiProviders.OPENAI,
|
|
13
|
-
model: "gpt-5-
|
|
13
|
+
model: "gpt-5.6-terra"
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Format a locale with its name.
|
|
@@ -126,6 +126,5 @@ const translateJSON = async ({ entryFileContent, presetOutputContent, dictionary
|
|
|
126
126
|
};
|
|
127
127
|
};
|
|
128
128
|
|
|
129
|
-
//#endregion
|
|
130
129
|
export { aiDefaultOptions, translateJSON };
|
|
131
130
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["AIProvider"],"sources":["../../../src/translateJSON/index.ts"],"sourcesContent":["import { readAsset } from 'utils:asset';\nimport { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { decode, encode } from '@toon-format/toon';\nimport { generateText, Output } from 'ai';\nimport { z } from 'zod/mini';\nimport { type AIConfig, type AIOptions, AIProvider } from '../aiSdk';\nimport { extractJson } from '../utils/extractJSON';\n\ntype Tag = {\n key: string;\n description?: string;\n};\n\nexport type TranslateJSONOptions<T = JSON> = {\n entryFileContent: T;\n presetOutputContent: Partial<T>;\n dictionaryDescription?: string;\n entryLocale: Locale;\n outputLocale: Locale;\n tags?: Tag[];\n aiConfig: AIConfig;\n mode: 'complete' | 'review';\n applicationContext?: string;\n};\n\nexport type TranslateJSONResultData<T = JSON> = {\n fileContent: T;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n provider: AIProvider.OPENAI,\n model: 'gpt-5-mini',\n};\n\n/**\n * Format a locale with its name.\n *\n * @param locale - The locale to format.\n * @returns A string in the format \"locale: name\", e.g. \"en: English\".\n */\nconst formatLocaleWithName = (locale: Locale): string =>\n `${locale}: ${getLocaleName(locale, DEFAULT_LOCALE)}`;\n\n/**\n * Formats tag instructions for the AI prompt.\n * Creates a string with all available tags and their descriptions.\n *\n * @param tags - The list of tags to format.\n * @returns A formatted string with tag instructions.\n */\nconst formatTagInstructions = (tags: Tag[]): string => {\n if (!tags || tags.length === 0) {\n return '';\n }\n\n // Prepare the tag instructions.\n return `Based on the dictionary content, identify specific tags from the list below that would be relevant:\n \n${tags.map(({ key, description }) => `- ${key}: ${description}`).join('\\n\\n')}`;\n};\n\nconst getModeInstructions = (mode: 'complete' | 'review'): string => {\n if (mode === 'complete') {\n return 'Mode: \"Complete\" - Enrich the preset content with the missing keys and values in the output locale. Do not update existing keys. Everything should be returned in the output.';\n }\n\n return 'Mode: \"Review\" - Fill missing content and review existing keys from the preset content. If a key from the entry is missing in the output, it must be translated to the target language and added. If you detect misspelled content, or content that should be reformulated, correct it. If a translation is not coherent with the desired language, translate it.';\n};\n\nconst jsonToZod = (content: any): z.ZodMiniType => {\n // Base case: content is a string (the translation target)\n if (typeof content === 'string') {\n return z.string();\n }\n\n // Base cases: primitives often preserved in i18n files (e.g. strict numbers/booleans)\n if (typeof content === 'number') {\n return z.number();\n }\n if (typeof content === 'boolean') {\n return z.boolean();\n }\n\n // Recursive case: Array\n if (Array.isArray(content)) {\n // If array is empty, we assume array of strings as default for i18n\n if (content.length === 0) {\n return z.array(z.string());\n }\n // We assume all items in the array share the structure of the first item\n return z.array(jsonToZod(content[0]));\n }\n\n // Recursive case: Object\n if (typeof content === 'object' && content !== null) {\n const shape: Record<string, z.ZodMiniType> = {};\n for (const key in content) {\n shape[key] = jsonToZod(content[key]);\n }\n return z.object(shape);\n }\n\n // Fallback\n return z.string();\n};\n\nconst countKeys = (obj: any): number => {\n if (typeof obj !== 'object' || obj === null) return 0;\n let count = 0;\n for (const key in obj) {\n count += 1 + countKeys(obj[key]);\n }\n return count;\n};\n\n/**\n * TranslateJSONs a content declaration file by constructing a prompt for AI models.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies.\n */\nexport const translateJSON = async <T>({\n entryFileContent,\n presetOutputContent,\n dictionaryDescription,\n aiConfig,\n entryLocale,\n outputLocale,\n tags,\n mode,\n applicationContext,\n}: TranslateJSONOptions<T>): Promise<\n TranslateJSONResultData<T> | undefined\n> => {\n const { dataSerialization, ...restAiConfig } = aiConfig;\n const { output: _unusedOutput, ...validAiConfig } = restAiConfig;\n\n const formattedEntryLocale = formatLocaleWithName(entryLocale);\n const formattedOutputLocale = formatLocaleWithName(outputLocale);\n\n const isToon = dataSerialization === 'toon';\n const promptFile = readAsset(\n isToon ? './PROMPT_TOON.md' : './PROMPT_JSON.md'\n );\n const entryContentStr = isToon\n ? encode(entryFileContent)\n : JSON.stringify(entryFileContent);\n const presetContentStr = isToon\n ? encode(presetOutputContent)\n : JSON.stringify(presetOutputContent);\n\n const schema = jsonToZod(entryFileContent);\n\n // Prepare the prompt for AI by replacing placeholders with actual values.\n const prompt = promptFile\n .replace('{{entryLocale}}', formattedEntryLocale)\n .replace('{{outputLocale}}', formattedOutputLocale)\n .replace('{{presetOutputContent}}', presetContentStr)\n .replace('{{dictionaryDescription}}', dictionaryDescription ?? '')\n .replace('{{applicationContext}}', applicationContext ?? '')\n .replace('{{tagsInstructions}}', formatTagInstructions(tags ?? []))\n .replace('{{modeInstructions}}', getModeInstructions(mode));\n\n if (isToon) {\n const { text, usage } = await generateText({\n ...aiConfig,\n system: prompt,\n messages: [\n {\n role: 'user',\n content: [\n `# Translation Request`,\n `Please translate the following TOON content.`,\n `- **From:** ${formattedEntryLocale}`,\n `- **To:** ${formattedOutputLocale}`,\n ``,\n `## Entry Content:`,\n entryContentStr,\n ].join('\\n'),\n },\n ],\n });\n\n // Strip markdown code blocks if present\n const cleanedText = text\n .replace(/^```(?:toon)?\\n([\\s\\S]*?)\\n```$/gm, '$1')\n .trim();\n\n const decodedJson = decode(cleanedText) as T;\n\n // schema.parse(decodedJson);\n\n return {\n fileContent: decodedJson,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n }\n\n const totalKeys = countKeys(entryFileContent);\n\n const MAX_SAFE_KEYS = 70; // You will need to tune this threshold based on testing\n\n const useStrictOutput = totalKeys <= MAX_SAFE_KEYS;\n\n // Use the AI SDK to generate the completion\n const { text, usage } = await generateText({\n ...validAiConfig,\n\n // Disable schema if Schema is too complex (Block with Anthropic)\n output: useStrictOutput ? Output.object({ schema }) : undefined,\n system: prompt,\n messages: [\n {\n role: 'user',\n content: [\n `# Translation Request`,\n `Please translate the following JSON content.`,\n `- **From:** ${formattedEntryLocale}`,\n `- **To:** ${formattedOutputLocale}`,\n ``,\n `CRITICAL INSTRUCTIONS:`,\n `- You MUST return ONLY raw, valid JSON.`,\n `- DO NOT wrap the response in Markdown code blocks (e.g., no \\`\\`\\`json).`,\n `- DO NOT include any conversational text before or after the JSON object.`,\n ``,\n `## Entry Content:`,\n entryContentStr,\n ].join('\\n'),\n },\n ],\n });\n\n // Extract and re-validate deeply\n const extractedJSON = extractJson(text);\n const validatedContent = schema.parse(extractedJSON) as T;\n\n return {\n fileContent: validatedContent,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;;;;;;;;AAgCA,MAAa,mBAA8B;CACzC,UAAUA,YAAW;CACrB,OAAO;AACT;;;;;;;AAQA,MAAM,wBAAwB,WAC5B,GAAG,OAAO,IAAI,cAAc,QAAQ,cAAc;;;;;;;;AASpD,MAAM,yBAAyB,SAAwB;CACrD,IAAI,CAAC,QAAQ,KAAK,WAAW,GAC3B,OAAO;CAIT,OAAO;;EAEP,KAAK,KAAK,EAAE,KAAK,kBAAkB,KAAK,IAAI,IAAI,aAAa,CAAC,CAAC,KAAK,MAAM;AAC5E;AAEA,MAAM,uBAAuB,SAAwC;CACnE,IAAI,SAAS,YACX,OAAO;CAGT,OAAO;AACT;AAEA,MAAM,aAAa,YAAgC;CAEjD,IAAI,OAAO,YAAY,UACrB,OAAO,EAAE,OAAO;CAIlB,IAAI,OAAO,YAAY,UACrB,OAAO,EAAE,OAAO;CAElB,IAAI,OAAO,YAAY,WACrB,OAAO,EAAE,QAAQ;CAInB,IAAI,MAAM,QAAQ,OAAO,GAAG;EAE1B,IAAI,QAAQ,WAAW,GACrB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC;EAG3B,OAAO,EAAE,MAAM,UAAU,QAAQ,EAAE,CAAC;CACtC;CAGA,IAAI,OAAO,YAAY,YAAY,Y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,UAAU,CACR;IACE,MAAM;IACN,SAAS;KACP;KACA;KACA,eAAe;KACf,aAAa;KACb;KACA;KACA;IACF,CAAC,CAAC,KAAK,IAAI;GACb,CACF;EACF,CAAC;EAGD,MAAM,cAAc,KACjB,QAAQ,qCAAqC,IAAI,CAAC,CAClD,KAAK;EAMR,OAAO;GACL,aALkB,OAAO,WAKF;GACvB,WAAW,OAAO,eAAe;EACnC;CACF;CAMA,MAAM,kBAJY,UAAU,gBAII,KAAK;CAGrC,MAAM,EAAE,MAAM,UAAU,MAAM,aAAa;EACzC,GAAG;EAGH,QAAQ,kBAAkB,OAAO,OAAO,EAAE,OAAO,CAAC,IAAI;EACtD,QAAQ;EACR,UAAU,CACR;GACE,MAAM;GACN,SAAS;IACP;IACA;IACA,eAAe;IACf,aAAa;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACF,CAAC,CAAC,KAAK,IAAI;EACb,CACF;CACF,CAAC;CAGD,MAAM,gBAAgB,YAAY,IAAI;CAGtC,OAAO;EACL,aAHuB,OAAO,MAAM,aAGR;EAC5B,WAAW,OAAO,eAAe;CACnC;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["AIProvider"],"sources":["../../../src/translateJSON/index.ts"],"sourcesContent":["import { DEFAULT_LOCALE } from '@intlayer/config/defaultValues';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { decode, encode } from '@toon-format/toon';\nimport { generateText, Output } from 'ai';\nimport { readAsset } from 'utils:asset';\nimport { z } from 'zod/mini';\nimport { type AIConfig, type AIOptions, AIProvider } from '../aiSdk';\nimport { extractJson } from '../utils/extractJSON';\n\ntype Tag = {\n key: string;\n description?: string;\n};\n\nexport type TranslateJSONOptions<T = JSON> = {\n entryFileContent: T;\n presetOutputContent: Partial<T>;\n dictionaryDescription?: string;\n entryLocale: Locale;\n outputLocale: Locale;\n tags?: Tag[];\n aiConfig: AIConfig;\n mode: 'complete' | 'review';\n applicationContext?: string;\n};\n\nexport type TranslateJSONResultData<T = JSON> = {\n fileContent: T;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n provider: AIProvider.OPENAI,\n model: 'gpt-5.6-terra',\n};\n\n/**\n * Format a locale with its name.\n *\n * @param locale - The locale to format.\n * @returns A string in the format \"locale: name\", e.g. \"en: English\".\n */\nconst formatLocaleWithName = (locale: Locale): string =>\n `${locale}: ${getLocaleName(locale, DEFAULT_LOCALE)}`;\n\n/**\n * Formats tag instructions for the AI prompt.\n * Creates a string with all available tags and their descriptions.\n *\n * @param tags - The list of tags to format.\n * @returns A formatted string with tag instructions.\n */\nconst formatTagInstructions = (tags: Tag[]): string => {\n if (!tags || tags.length === 0) {\n return '';\n }\n\n // Prepare the tag instructions.\n return `Based on the dictionary content, identify specific tags from the list below that would be relevant:\n \n${tags.map(({ key, description }) => `- ${key}: ${description}`).join('\\n\\n')}`;\n};\n\nconst getModeInstructions = (mode: 'complete' | 'review'): string => {\n if (mode === 'complete') {\n return 'Mode: \"Complete\" - Enrich the preset content with the missing keys and values in the output locale. Do not update existing keys. Everything should be returned in the output.';\n }\n\n return 'Mode: \"Review\" - Fill missing content and review existing keys from the preset content. If a key from the entry is missing in the output, it must be translated to the target language and added. If you detect misspelled content, or content that should be reformulated, correct it. If a translation is not coherent with the desired language, translate it.';\n};\n\nconst jsonToZod = (content: any): z.ZodMiniType => {\n // Base case: content is a string (the translation target)\n if (typeof content === 'string') {\n return z.string();\n }\n\n // Base cases: primitives often preserved in i18n files (e.g. strict numbers/booleans)\n if (typeof content === 'number') {\n return z.number();\n }\n if (typeof content === 'boolean') {\n return z.boolean();\n }\n\n // Recursive case: Array\n if (Array.isArray(content)) {\n // If array is empty, we assume array of strings as default for i18n\n if (content.length === 0) {\n return z.array(z.string());\n }\n // We assume all items in the array share the structure of the first item\n return z.array(jsonToZod(content[0]));\n }\n\n // Recursive case: Object\n if (typeof content === 'object' && content !== null) {\n const shape: Record<string, z.ZodMiniType> = {};\n for (const key in content) {\n shape[key] = jsonToZod(content[key]);\n }\n return z.object(shape);\n }\n\n // Fallback\n return z.string();\n};\n\nconst countKeys = (obj: any): number => {\n if (typeof obj !== 'object' || obj === null) return 0;\n let count = 0;\n for (const key in obj) {\n count += 1 + countKeys(obj[key]);\n }\n return count;\n};\n\n/**\n * TranslateJSONs a content declaration file by constructing a prompt for AI models.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies.\n */\nexport const translateJSON = async <T>({\n entryFileContent,\n presetOutputContent,\n dictionaryDescription,\n aiConfig,\n entryLocale,\n outputLocale,\n tags,\n mode,\n applicationContext,\n}: TranslateJSONOptions<T>): Promise<\n TranslateJSONResultData<T> | undefined\n> => {\n const { dataSerialization, ...restAiConfig } = aiConfig;\n const { output: _unusedOutput, ...validAiConfig } = restAiConfig;\n\n const formattedEntryLocale = formatLocaleWithName(entryLocale);\n const formattedOutputLocale = formatLocaleWithName(outputLocale);\n\n const isToon = dataSerialization === 'toon';\n const promptFile = readAsset(\n isToon ? './PROMPT_TOON.md' : './PROMPT_JSON.md'\n );\n const entryContentStr = isToon\n ? encode(entryFileContent)\n : JSON.stringify(entryFileContent);\n const presetContentStr = isToon\n ? encode(presetOutputContent)\n : JSON.stringify(presetOutputContent);\n\n const schema = jsonToZod(entryFileContent);\n\n // Prepare the prompt for AI by replacing placeholders with actual values.\n const prompt = promptFile\n .replace('{{entryLocale}}', formattedEntryLocale)\n .replace('{{outputLocale}}', formattedOutputLocale)\n .replace('{{presetOutputContent}}', presetContentStr)\n .replace('{{dictionaryDescription}}', dictionaryDescription ?? '')\n .replace('{{applicationContext}}', applicationContext ?? '')\n .replace('{{tagsInstructions}}', formatTagInstructions(tags ?? []))\n .replace('{{modeInstructions}}', getModeInstructions(mode));\n\n if (isToon) {\n const { text, usage } = await generateText({\n ...aiConfig,\n system: prompt,\n messages: [\n {\n role: 'user',\n content: [\n `# Translation Request`,\n `Please translate the following TOON content.`,\n `- **From:** ${formattedEntryLocale}`,\n `- **To:** ${formattedOutputLocale}`,\n ``,\n `## Entry Content:`,\n entryContentStr,\n ].join('\\n'),\n },\n ],\n });\n\n // Strip markdown code blocks if present\n const cleanedText = text\n .replace(/^```(?:toon)?\\n([\\s\\S]*?)\\n```$/gm, '$1')\n .trim();\n\n const decodedJson = decode(cleanedText) as T;\n\n // schema.parse(decodedJson);\n\n return {\n fileContent: decodedJson,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n }\n\n const totalKeys = countKeys(entryFileContent);\n\n const MAX_SAFE_KEYS = 70; // You will need to tune this threshold based on testing\n\n const useStrictOutput = totalKeys <= MAX_SAFE_KEYS;\n\n // Use the AI SDK to generate the completion\n const { text, usage } = await generateText({\n ...validAiConfig,\n\n // Disable schema if Schema is too complex (Block with Anthropic)\n output: useStrictOutput ? Output.object({ schema }) : undefined,\n system: prompt,\n messages: [\n {\n role: 'user',\n content: [\n `# Translation Request`,\n `Please translate the following JSON content.`,\n `- **From:** ${formattedEntryLocale}`,\n `- **To:** ${formattedOutputLocale}`,\n ``,\n `CRITICAL INSTRUCTIONS:`,\n `- You MUST return ONLY raw, valid JSON.`,\n `- DO NOT wrap the response in Markdown code blocks (e.g., no \\`\\`\\`json).`,\n `- DO NOT include any conversational text before or after the JSON object.`,\n ``,\n `## Entry Content:`,\n entryContentStr,\n ].join('\\n'),\n },\n ],\n });\n\n // Extract and re-validate deeply\n const extractedJSON = extractJson(text);\n const validatedContent = schema.parse(extractedJSON) as T;\n\n return {\n fileContent: validatedContent,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;;;;;;;;AAgCA,MAAa,mBAA8B;CACzC,UAAUA,YAAW;CACrB,OAAO;AACT;;;;;;;AAQA,MAAM,wBAAwB,WAC5B,GAAG,OAAO,IAAI,cAAc,QAAQ,cAAc;;;;;;;;AASpD,MAAM,yBAAyB,SAAwB;CACrD,IAAI,CAAC,QAAQ,KAAK,WAAW,GAC3B,OAAO;CAIT,OAAO;;E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|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils/extractJSON.ts
|
|
2
2
|
/**
|
|
3
3
|
* Extracts and parses the first valid JSON value (object or array) from a string containing arbitrary text.
|
|
4
4
|
* This is used to safely extract JSON from LLM responses that may contain additional text or markdown.
|
|
@@ -71,6 +71,5 @@ const extractJson = (input) => {
|
|
|
71
71
|
throw new Error("Reached end of input without closing JSON bracket.");
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
//#endregion
|
|
75
74
|
export { extractJson };
|
|
76
75
|
//# sourceMappingURL=extractJSON.mjs.map
|
package/dist/types/aiSdk.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ import { TogetherAIProvider, createTogetherAI } from "@ai-sdk/togetherai";
|
|
|
15
15
|
import { AiProviders } from "@intlayer/types/config";
|
|
16
16
|
import { OpenRouterProvider, createOpenRouter } from "@openrouter/ai-sdk-provider";
|
|
17
17
|
import { AssistantModelMessage, SystemModelMessage, ToolModelMessage, UserModelMessage, generateText } from "ai";
|
|
18
|
-
//#region src/aiSdk.d.ts
|
|
19
18
|
type AnthropicModel = Parameters<AnthropicProvider>[0];
|
|
20
19
|
type DeepSeekModel = Parameters<DeepSeekProvider>[0];
|
|
21
20
|
type MistralModel = Parameters<MistralProvider>[0];
|
|
@@ -139,6 +138,5 @@ export declare const checkAISDKAccess: (aiConfig: AIConfig) => Promise<{
|
|
|
139
138
|
* @returns Configured AI model ready to use with generateText
|
|
140
139
|
*/
|
|
141
140
|
export declare const getAIConfig: (options: AIConfigOptions, isAuthenticated?: boolean) => Promise<AIConfig>;
|
|
142
|
-
//#endregion
|
|
143
141
|
export { AiProviders as AIProvider };
|
|
144
142
|
//# sourceMappingURL=aiSdk.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSdk.d.ts","names":[],"sources":["../../src/aiSdk.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"aiSdk.d.ts","names":["VertexProvider"],"sources":["../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C;EAEF,UAAU,YAAY,eAAe,YAAY;IAC/C;EAEF,UAAU,YAAY,UAAU,YAAY;IAC1C;EAEF,UAAU,YAAY,iBAAiB,YAAY;IACjD;EAEF,UAAU,YAAY,aAAa,YAAY;IAC7C;EAEF,UAAU,YAAY,kBAAkB,YAAY;IAClD;EAEF,UAAU,YAAY,gBAAgB,YAAY;IAChD;EAEF,UAAU,YAAY,cAAc,YAAY;IAC9C;EAEF,UAAU,YAAY,gBAAgB,YAAY;IAChD;EACD;IAAyB,0BAE9B;YAGU;EACV;EACA;EACA,YAAY;;KAGT;YAofO,WAAW,KAAK,kBAAkB;EAC5C,kBAAkB;EAClB;EACA;;YAGU;EACV,cAAc;EACd,iBAAiB;EACjB,iBAAiB;EACjB,aAAa;;;;;;;;qBASF,mBAAgB,UACjB,aACT;EAAU;EAAsB;;;;;;;;;qBAyBtB,cAAW,SACb,iBAAe,8BAEvB,QAAQ"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AIConfig, AIOptions } from "../aiSdk.js";
|
|
2
|
-
//#region src/auditDictionaryMetadata/index.d.ts
|
|
3
2
|
type Tag = {
|
|
4
3
|
key: string;
|
|
5
4
|
description?: string;
|
|
@@ -25,5 +24,5 @@ export declare const aiDefaultOptions: AIOptions;
|
|
|
25
24
|
* and requests for identifying issues or inconsistencies.
|
|
26
25
|
*/
|
|
27
26
|
export declare const auditDictionaryMetadata: ({ fileContent, tags, aiConfig, applicationContext }: AuditDictionaryMetadataOptions) => Promise<AuditFileResultData | undefined>;
|
|
28
|
-
|
|
27
|
+
export {};
|
|
29
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/auditDictionaryMetadata/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/auditDictionaryMetadata/index.ts"],"mappings":";KAKK;EACH;EACA;;YAGU;EACV;EACA,OAAO;EACP,UAAU;EACV;;YAGU;EACV;IACE;IACA;IACA;;EAEF;;qBAGW,kBAAkB;;;;;;qBASlB,4BAAuB,aAAA,MAAA,UAAA,sBAKjC,mCAAiC,QAClC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AIConfig, AIOptions, Messages } from "./aiSdk.js";
|
|
2
2
|
import { SystemModelMessage } from "ai";
|
|
3
|
-
//#region src/customQuery.d.ts
|
|
4
3
|
export type CustomQueryOptions = {
|
|
5
4
|
messages: Messages;
|
|
6
5
|
system?: string | SystemModelMessage | SystemModelMessage[];
|
|
@@ -17,5 +16,4 @@ export declare const aiDefaultOptions: AIOptions;
|
|
|
17
16
|
* and requests for identifying issues or inconsistencies.
|
|
18
17
|
*/
|
|
19
18
|
export declare const customQuery: ({ messages, system, aiConfig }: CustomQueryOptions) => Promise<CustomQueryResultData | undefined>;
|
|
20
|
-
//#endregion
|
|
21
19
|
//# sourceMappingURL=customQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customQuery.d.ts","names":[],"sources":["../../src/customQuery.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"customQuery.d.ts","names":[],"sources":["../../src/customQuery.ts"],"mappings":";;YAGY;EACV,UAAU;EACV,kBAAkB,qBAAqB;EACvC,UAAU;;YAGA;EACV;EACA;;qBAGW,kBAAkB;;;;;;qBAUlB,gBAAW,UAAA,QAAA,YAIrB,uBAAqB,QAAQ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AIConfig, AIOptions } from "../aiSdk.js";
|
|
2
2
|
import { Locale } from "@intlayer/types/allLocales";
|
|
3
|
-
//#region src/translateJSON/index.d.ts
|
|
4
3
|
type Tag = {
|
|
5
4
|
key: string;
|
|
6
5
|
description?: string;
|
|
@@ -27,5 +26,5 @@ export declare const aiDefaultOptions: AIOptions;
|
|
|
27
26
|
* and requests for identifying issues or inconsistencies.
|
|
28
27
|
*/
|
|
29
28
|
export declare const translateJSON: <T>({ entryFileContent, presetOutputContent, dictionaryDescription, aiConfig, entryLocale, outputLocale, tags, mode, applicationContext }: TranslateJSONOptions<T>) => Promise<TranslateJSONResultData<T> | undefined>;
|
|
30
|
-
|
|
29
|
+
export {};
|
|
31
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/translateJSON/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/translateJSON/index.ts"],"mappings":";;KAUK;EACH;EACA;;YAGU,qBAAqB,IAAI;EACnC,kBAAkB;EAClB,qBAAqB,QAAQ;EAC7B;EACA,aAAa;EACb,cAAc;EACd,OAAO;EACP,UAAU;EACV;EACA;;YAGU,wBAAwB,IAAI;EACtC,aAAa;EACb;;qBAGW,kBAAkB;;;;;;qBA2FlB,gBAAuB,KAAC,kBAAA,qBAAA,uBAAA,UAAA,aAAA,cAAA,MAAA,MAAA,sBAUlC,qBAAqB,OAAK,QAC3B,wBAAwB"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/utils/extractJSON.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Extracts and parses the first valid JSON value (object or array) from a string containing arbitrary text.
|
|
4
3
|
* This is used to safely extract JSON from LLM responses that may contain additional text or markdown.
|
|
@@ -31,5 +30,4 @@
|
|
|
31
30
|
* @returns {T} The parsed JSON value cast to type T
|
|
32
31
|
*/
|
|
33
32
|
export declare const extractJson: <T = any>(input: string) => T;
|
|
34
|
-
//#endregion
|
|
35
33
|
//# sourceMappingURL=extractJSON.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractJSON.d.ts","names":[],"sources":["../../../src/utils/extractJSON.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"extractJSON.d.ts","names":[],"sources":["../../../src/utils/extractJSON.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA+Ba,cAAe,SAAO,kBAAkB"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/ai",
|
|
3
|
-
"version": "9.7.
|
|
3
|
+
"version": "9.7.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "SDK that provides AI capabilities for Intlayer applications",
|
|
6
6
|
"keywords": [
|
|
7
|
-
"intlayer",
|
|
8
|
-
"application",
|
|
9
7
|
"ai",
|
|
8
|
+
"application",
|
|
10
9
|
"backend",
|
|
11
10
|
"i18n",
|
|
12
|
-
"internationalization"
|
|
11
|
+
"internationalization",
|
|
12
|
+
"intlayer"
|
|
13
13
|
],
|
|
14
14
|
"homepage": "https://intlayer.org",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
17
17
|
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/aymericzip/intlayer.git"
|
|
21
|
-
},
|
|
22
18
|
"license": "Apache-2.0",
|
|
23
19
|
"author": {
|
|
24
20
|
"name": "Aymeric PINEAU",
|
|
@@ -31,15 +27,15 @@
|
|
|
31
27
|
"url": "https://github.com/aymericzip"
|
|
32
28
|
}
|
|
33
29
|
],
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"types": "./dist/types/index.d.ts",
|
|
38
|
-
"require": "./dist/cjs/index.cjs",
|
|
39
|
-
"import": "./dist/esm/index.mjs"
|
|
40
|
-
},
|
|
41
|
-
"./package.json": "./package.json"
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/aymericzip/intlayer.git"
|
|
42
33
|
},
|
|
34
|
+
"files": [
|
|
35
|
+
"./dist",
|
|
36
|
+
"./package.json"
|
|
37
|
+
],
|
|
38
|
+
"sideEffects": false,
|
|
43
39
|
"main": "dist/cjs/index.cjs",
|
|
44
40
|
"module": "dist/esm/index.mjs",
|
|
45
41
|
"types": "dist/types/index.d.ts",
|
|
@@ -50,19 +46,23 @@
|
|
|
50
46
|
]
|
|
51
47
|
}
|
|
52
48
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
"exports": {
|
|
50
|
+
".": {
|
|
51
|
+
"types": "./dist/types/index.d.ts",
|
|
52
|
+
"require": "./dist/cjs/index.cjs",
|
|
53
|
+
"import": "./dist/esm/index.mjs"
|
|
54
|
+
},
|
|
55
|
+
"./package.json": "./package.json"
|
|
56
|
+
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "bun --bun tsdown --config tsdown.config.ts",
|
|
59
59
|
"build:ci": "bun --bun tsdown --config tsdown.config.ts",
|
|
60
60
|
"clean": "bun --bun rimraf ./dist .turbo",
|
|
61
61
|
"dev": "bun --bun tsdown --config tsdown.config.ts --watch",
|
|
62
|
-
"format": "
|
|
63
|
-
"format:fix": "
|
|
64
|
-
"lint": "
|
|
65
|
-
"lint:fix": "
|
|
62
|
+
"format": "oxfmt --check .",
|
|
63
|
+
"format:fix": "oxfmt .",
|
|
64
|
+
"lint": "oxlint .",
|
|
65
|
+
"lint:fix": "oxlint --fix .",
|
|
66
66
|
"prepublish": "cp -f ../../../README.md ./README.md",
|
|
67
67
|
"publish": "bun publish || true",
|
|
68
68
|
"publish:canary": "bun publish --access public --tag canary || true",
|
|
@@ -73,25 +73,25 @@
|
|
|
73
73
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@ai-sdk/anthropic": "4.0.
|
|
77
|
-
"@ai-sdk/openai": "4.0.
|
|
78
|
-
"@intlayer/api": "9.7.
|
|
79
|
-
"@intlayer/config": "9.
|
|
80
|
-
"@intlayer/core": "9.7.
|
|
81
|
-
"@intlayer/types": "9.7.
|
|
82
|
-
"@toon-format/toon": "4.
|
|
83
|
-
"ai": "7.0.
|
|
84
|
-
"zod": "4.6.
|
|
76
|
+
"@ai-sdk/anthropic": "4.0.99",
|
|
77
|
+
"@ai-sdk/openai": "4.0.111",
|
|
78
|
+
"@intlayer/api": "9.7.2",
|
|
79
|
+
"@intlayer/config": "9.7.2",
|
|
80
|
+
"@intlayer/core": "9.7.2",
|
|
81
|
+
"@intlayer/types": "9.7.2",
|
|
82
|
+
"@toon-format/toon": "4.4.0",
|
|
83
|
+
"ai": "7.0.166",
|
|
84
|
+
"zod": "4.6.7"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@types/node": "^26.6.4",
|
|
88
88
|
"@utils/ts-config": "1.0.4",
|
|
89
89
|
"@utils/ts-config-types": "1.0.4",
|
|
90
90
|
"@utils/tsdown-config": "1.0.4",
|
|
91
|
-
"rimraf": "6.1.
|
|
92
|
-
"tsdown": "0.23.
|
|
91
|
+
"rimraf": "6.1.4",
|
|
92
|
+
"tsdown": "0.23.7",
|
|
93
93
|
"typescript": "7.0.2",
|
|
94
|
-
"vitest": "5.0
|
|
94
|
+
"vitest": "5.1.0"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
97
|
"@ai-sdk/alibaba": "<=1.0.0",
|