@intlayer/ai 8.4.4 → 8.4.5

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.
@@ -0,0 +1,29 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -0,0 +1,98 @@
1
+ const require_runtime = require('./_rolldown/runtime.cjs');
2
+ let node_fs = require("node:fs");
3
+ let node_path = require("node:path");
4
+ let node_url = require("node:url");
5
+
6
+ //#region \0utils:asset
7
+ const hereDirname = () => {
8
+ try {
9
+ return (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
10
+ } catch {
11
+ return typeof __dirname !== "undefined" ? __dirname : process.cwd();
12
+ }
13
+ };
14
+ const findDistRoot = (startDir) => {
15
+ let dir = startDir;
16
+ for (let i = 0; i < 12; i++) {
17
+ if ((0, node_path.basename)(dir) === "dist") return dir;
18
+ const parent = (0, node_path.resolve)(dir, "..");
19
+ if (parent === dir) break;
20
+ dir = parent;
21
+ }
22
+ return null;
23
+ };
24
+ const normalizeFrameFile = (file) => {
25
+ if (!file) return null;
26
+ try {
27
+ if (file.startsWith("file://")) return (0, node_url.fileURLToPath)(file);
28
+ } catch {}
29
+ return file;
30
+ };
31
+ /**
32
+ * Returns the directory of the *caller* module that invoked readAsset.
33
+ * Prefers non-virtual frames; falls back to the first real frame.
34
+ */
35
+ const getCallerDir = () => {
36
+ const prev = Error.prepareStackTrace;
37
+ try {
38
+ Error.prepareStackTrace = (_, structured) => structured;
39
+ const err = /* @__PURE__ */ new Error();
40
+ Error.captureStackTrace(err, getCallerDir);
41
+ /** @type {import('node:vm').CallSite[]} */
42
+ const frames = err.stack || [];
43
+ const isVirtualPath = (p) => p.includes(`${node_path.sep}_virtual${node_path.sep}`) || p.includes("/_virtual/");
44
+ for (const frame of frames) {
45
+ const file = normalizeFrameFile(typeof frame.getFileName === "function" ? frame.getFileName() : null);
46
+ if (!file) continue;
47
+ if (file.includes("node:internal") || file.includes(`${node_path.sep}internal${node_path.sep}modules${node_path.sep}`)) continue;
48
+ if (!isVirtualPath(file)) return (0, node_path.dirname)(file);
49
+ }
50
+ for (const frame of frames) {
51
+ const file = normalizeFrameFile(typeof frame.getFileName === "function" ? frame.getFileName() : null);
52
+ if (file) return (0, node_path.dirname)(file);
53
+ }
54
+ } catch {} finally {
55
+ Error.prepareStackTrace = prev;
56
+ }
57
+ return hereDirname();
58
+ };
59
+ /**
60
+ * Read an asset copied from src/** to dist/assets/**.
61
+ * - './' or '../' is resolved relative to the *caller module's* emitted directory.
62
+ * - otherwise, treat as src-relative.
63
+ *
64
+ * @param {string} relPath - e.g. './PROMPT.md' or 'utils/AI/askDocQuestion/embeddings/<fileKey>.json'
65
+ * @param {BufferEncoding} [encoding='utf8']
66
+ */
67
+ const readAsset = (relPath, encoding = "utf8") => {
68
+ const here = hereDirname();
69
+ const distRoot = findDistRoot(here) ?? (0, node_path.resolve)(here, "..", "..", "dist");
70
+ const assetsRoot = (0, node_path.join)(distRoot, "assets");
71
+ const tried = [];
72
+ /**
73
+ * Transform dist/(esm|cjs)/... and _virtual/ prefix to clean subpath (Windows-safe)
74
+ */
75
+ const callerSubpath = (0, node_path.relative)(distRoot, getCallerDir()).split("\\").join("/").replace(/^(?:dist\/)?(?:esm|cjs)\//, "").replace(/^_virtual\//, "");
76
+ if (relPath.startsWith("./") || relPath.startsWith("../")) {
77
+ const fromCallerAbs = (0, node_path.resolve)(assetsRoot, callerSubpath, relPath);
78
+ tried.push(fromCallerAbs);
79
+ if ((0, node_fs.existsSync)(fromCallerAbs)) return (0, node_fs.readFileSync)(fromCallerAbs, encoding);
80
+ }
81
+ const directPath = (0, node_path.join)(assetsRoot, relPath);
82
+ tried.push(directPath);
83
+ if ((0, node_fs.existsSync)(directPath)) return (0, node_fs.readFileSync)(directPath, encoding);
84
+ if (callerSubpath) {
85
+ const nested = (0, node_path.join)(assetsRoot, callerSubpath, relPath);
86
+ tried.push(nested);
87
+ if ((0, node_fs.existsSync)(nested)) return (0, node_fs.readFileSync)(nested, encoding);
88
+ }
89
+ const msg = [
90
+ "readAsset: file not found.",
91
+ "Searched:",
92
+ ...tried.map((p) => `- ${p}`)
93
+ ].join("\n");
94
+ throw new Error(msg);
95
+ };
96
+
97
+ //#endregion
98
+ exports.readAsset = readAsset;
@@ -1 +1,206 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./aiSdk-Du5xFzsz.cjs`);let t=require(`@intlayer/types/config`);exports.AIProvider=t.AiProviders,exports.getAIConfig=e.t;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let _intlayer_config_colors = require("@intlayer/config/colors");
4
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
5
+ let _intlayer_config_logger = require("@intlayer/config/logger");
6
+ let _intlayer_types_config = require("@intlayer/types/config");
7
+
8
+ //#region src/aiSdk.ts
9
+ const getAPIKey = (accessType, aiOptions, isAuthenticated = false) => {
10
+ const defaultApiKey = process.env.OPENAI_API_KEY;
11
+ if (accessType.includes("public")) return aiOptions?.apiKey ?? defaultApiKey;
12
+ if (accessType.includes("apiKey") && aiOptions?.apiKey) return aiOptions?.apiKey;
13
+ if (accessType.includes("registered_user") && isAuthenticated) return aiOptions?.apiKey ?? defaultApiKey;
14
+ if (accessType.includes("premium_user") && isAuthenticated) return aiOptions?.apiKey ?? defaultApiKey;
15
+ };
16
+ const getModelName = (provider, userApiKey, userModel, defaultModel = "gpt-5-mini") => {
17
+ if (userApiKey || provider === _intlayer_types_config.AiProviders.OLLAMA) {
18
+ if (provider === _intlayer_types_config.AiProviders.OPENAI) return userModel ?? defaultModel;
19
+ if (userModel) return userModel;
20
+ switch (provider) {
21
+ default: return "-";
22
+ }
23
+ }
24
+ if (userModel || provider) throw new Error("The user should use his own API key to use a custom model");
25
+ return defaultModel;
26
+ };
27
+ const getLanguageModel = async (aiOptions, apiKey, defaultModel) => {
28
+ const loadModule = async (packageName) => {
29
+ try {
30
+ return await import(packageName);
31
+ } catch {
32
+ (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} The package "${(0, _intlayer_config_logger.colorize)(packageName, _intlayer_config_colors.GREEN)}" is required to use this AI provider. Please install it using: ${(0, _intlayer_config_logger.colorize)(`npm install ${packageName}`, _intlayer_config_colors.GREY_DARK)}`, { level: "error" });
33
+ process.exit();
34
+ }
35
+ };
36
+ const provider = aiOptions.provider ?? _intlayer_types_config.AiProviders.OPENAI;
37
+ const selectedModel = getModelName(provider, apiKey, aiOptions.model, defaultModel);
38
+ const baseURL = aiOptions.baseURL;
39
+ switch (provider) {
40
+ case _intlayer_types_config.AiProviders.OPENAI: {
41
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
42
+ const { createOpenAI } = await loadModule("@ai-sdk/openai");
43
+ return createOpenAI({
44
+ apiKey,
45
+ baseURL,
46
+ ...otherOptions
47
+ })(selectedModel);
48
+ }
49
+ case _intlayer_types_config.AiProviders.ANTHROPIC: {
50
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
51
+ const { createAnthropic } = await loadModule("@ai-sdk/anthropic");
52
+ return createAnthropic({
53
+ apiKey,
54
+ baseURL,
55
+ ...otherOptions
56
+ })(selectedModel);
57
+ }
58
+ case _intlayer_types_config.AiProviders.MISTRAL: {
59
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
60
+ const { createMistral } = await loadModule("@ai-sdk/mistral");
61
+ return createMistral({
62
+ apiKey,
63
+ baseURL,
64
+ ...otherOptions
65
+ })(selectedModel);
66
+ }
67
+ case _intlayer_types_config.AiProviders.DEEPSEEK: {
68
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
69
+ const { createDeepSeek } = await loadModule("@ai-sdk/deepseek");
70
+ return createDeepSeek({
71
+ apiKey,
72
+ baseURL,
73
+ ...otherOptions
74
+ })(selectedModel);
75
+ }
76
+ case _intlayer_types_config.AiProviders.GEMINI: {
77
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
78
+ const { createGoogleGenerativeAI } = await loadModule("@ai-sdk/google");
79
+ return createGoogleGenerativeAI({
80
+ apiKey,
81
+ baseURL,
82
+ ...otherOptions
83
+ })(selectedModel);
84
+ }
85
+ case _intlayer_types_config.AiProviders.GOOGLEVERTEX: {
86
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
87
+ const { createVertex } = await loadModule("@ai-sdk/google-vertex");
88
+ return createVertex({
89
+ apiKey,
90
+ baseURL,
91
+ ...otherOptions
92
+ })(selectedModel);
93
+ }
94
+ case _intlayer_types_config.AiProviders.GOOGLEGENERATIVEAI: {
95
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
96
+ const { createGoogleGenerativeAI } = await loadModule("@ai-sdk/google");
97
+ return createGoogleGenerativeAI({
98
+ apiKey,
99
+ baseURL,
100
+ ...otherOptions
101
+ })(selectedModel);
102
+ }
103
+ case _intlayer_types_config.AiProviders.OLLAMA: {
104
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
105
+ const { createOpenAI } = await loadModule("@ai-sdk/openai");
106
+ return createOpenAI({
107
+ baseURL: baseURL ?? "http://localhost:11434/v1",
108
+ apiKey: apiKey ?? "ollama",
109
+ ...otherOptions
110
+ }).chat(selectedModel);
111
+ }
112
+ case _intlayer_types_config.AiProviders.OPENROUTER: {
113
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
114
+ const { createOpenRouter } = await loadModule("@openrouter/ai-sdk-provider");
115
+ return createOpenRouter({
116
+ apiKey,
117
+ baseURL,
118
+ ...otherOptions
119
+ })(selectedModel);
120
+ }
121
+ case _intlayer_types_config.AiProviders.ALIBABA: {
122
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
123
+ const { createAlibaba } = await loadModule("@ai-sdk/alibaba");
124
+ return createAlibaba({
125
+ apiKey,
126
+ baseURL,
127
+ ...otherOptions
128
+ })(selectedModel);
129
+ }
130
+ case _intlayer_types_config.AiProviders.FIREWORKS: {
131
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
132
+ const { createFireworks } = await loadModule("@ai-sdk/fireworks");
133
+ return createFireworks({
134
+ apiKey,
135
+ baseURL,
136
+ ...otherOptions
137
+ })(selectedModel);
138
+ }
139
+ case _intlayer_types_config.AiProviders.GROQ: {
140
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
141
+ const { createGroq } = await loadModule("@ai-sdk/groq");
142
+ return createGroq({
143
+ apiKey,
144
+ baseURL,
145
+ ...otherOptions
146
+ })(selectedModel);
147
+ }
148
+ case _intlayer_types_config.AiProviders.HUGGINGFACE: {
149
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
150
+ const { createHuggingFace } = await loadModule("@ai-sdk/huggingface");
151
+ return createHuggingFace({
152
+ apiKey,
153
+ baseURL,
154
+ ...otherOptions
155
+ })(selectedModel);
156
+ }
157
+ case _intlayer_types_config.AiProviders.BEDROCK: {
158
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
159
+ const { createAmazonBedrock } = await loadModule("@ai-sdk/amazon-bedrock");
160
+ return createAmazonBedrock({
161
+ accessKeyId: apiKey,
162
+ baseURL,
163
+ ...otherOptions
164
+ })(selectedModel);
165
+ }
166
+ case _intlayer_types_config.AiProviders.TOGETHERAI: {
167
+ const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
168
+ const { createTogetherAI } = await loadModule("@ai-sdk/togetherai");
169
+ return createTogetherAI({
170
+ apiKey,
171
+ baseURL,
172
+ ...otherOptions
173
+ })(selectedModel);
174
+ }
175
+ default: throw new Error(`Provider ${provider} not supported`);
176
+ }
177
+ };
178
+ const DEFAULT_PROVIDER = _intlayer_types_config.AiProviders.OPENAI;
179
+ /**
180
+ * Get AI model configuration based on the selected provider and options
181
+ * This function handles the configuration for different AI providers
182
+ *
183
+ * @param options Configuration options including provider, API keys, models and temperature
184
+ * @returns Configured AI model ready to use with generateText
185
+ */
186
+ const getAIConfig = async (options, isAuthenticated = false) => {
187
+ const { userOptions, projectOptions, defaultOptions, accessType = ["registered_user"] } = options;
188
+ const aiOptions = {
189
+ provider: DEFAULT_PROVIDER,
190
+ ...defaultOptions,
191
+ ...projectOptions,
192
+ ...userOptions
193
+ };
194
+ const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);
195
+ if (!apiKey && aiOptions.provider !== _intlayer_types_config.AiProviders.OLLAMA) throw new Error(`API key for ${aiOptions.provider} is missing`);
196
+ return {
197
+ model: await getLanguageModel(aiOptions, apiKey, defaultOptions?.model),
198
+ temperature: aiOptions.temperature,
199
+ dataSerialization: aiOptions.dataSerialization
200
+ };
201
+ };
202
+
203
+ //#endregion
204
+ exports.AIProvider = _intlayer_types_config.AiProviders;
205
+ exports.getAIConfig = getAIConfig;
206
+ //# sourceMappingURL=aiSdk.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aiSdk.cjs","names":["AiProviders","x","ANSIColors"],"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 { createOpenAI, OpenAIProvider } from '@ai-sdk/openai';\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';\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];\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];\n\nexport type Messages = (\n | SystemModelMessage\n | UserModelMessage\n | AssistantModelMessage\n | ToolModelMessage\n)[];\n\n/**\n * Supported AI models\n */\nexport type Model =\n | AnthropicModel\n | DeepSeekModel\n | MistralModel\n | OpenAIModel\n | OpenRouterModel\n | GoogleModel\n | VertexModel\n | AlibabaModel\n | AmazonBedrockModel\n | FireworksModel\n | GroqModel\n | HuggingFaceModel\n | TogetherAIModel\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 | ({ 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 getAPIKey = (\n accessType: AccessType[],\n aiOptions?: AIOptions,\n isAuthenticated: boolean = false\n) => {\n const defaultApiKey = process.env.OPENAI_API_KEY;\n\n if (accessType.includes('public')) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n if (accessType.includes('apiKey') && aiOptions?.apiKey) {\n return aiOptions?.apiKey;\n }\n\n if (accessType.includes('registered_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n // TODO: Implement premium user access\n if (accessType.includes('premium_user') && isAuthenticated) {\n return aiOptions?.apiKey ?? defaultApiKey;\n }\n\n return undefined;\n};\n\nconst getModelName = (\n provider: AiProviders,\n userApiKey: string | undefined,\n userModel?: Model,\n defaultModel: Model = 'gpt-5-mini'\n): Model => {\n // If the user uses their own API key, allow custom model selection\n if (userApiKey || provider === AiProviders.OLLAMA) {\n if (provider === AiProviders.OPENAI) {\n return userModel ?? defaultModel;\n }\n\n if (userModel) {\n return userModel;\n }\n\n switch (provider) {\n default:\n return '-';\n }\n }\n\n // Guard: Prevent custom model usage without a user API key\n if (userModel || provider) {\n throw new Error(\n 'The user should use his own API key to use a custom model'\n );\n }\n\n return defaultModel;\n};\n\nconst getLanguageModel = async (\n aiOptions: AIOptions,\n apiKey: string | undefined,\n defaultModel?: Model\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 apiKey,\n aiOptions.model,\n defaultModel\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 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\nconst DEFAULT_PROVIDER: AiProviders = AiProviders.OPENAI as AiProviders;\n\nexport type AIConfigOptions = {\n userOptions?: AIOptions;\n projectOptions?: AIOptions;\n defaultOptions?: AIOptions;\n accessType?: AccessType[];\n};\n\n/**\n * Get AI model configuration based on the selected provider and options\n * This function handles the configuration for different AI providers\n *\n * @param options Configuration options including provider, API keys, models and temperature\n * @returns Configured AI model ready to use with generateText\n */\nexport const getAIConfig = async (\n options: AIConfigOptions,\n isAuthenticated: boolean = false\n): Promise<AIConfig> => {\n const {\n userOptions,\n projectOptions,\n defaultOptions,\n accessType = ['registered_user'],\n } = options;\n\n const aiOptions = {\n provider: DEFAULT_PROVIDER,\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 (!apiKey && aiOptions.provider !== AiProviders.OLLAMA) {\n throw new Error(`API key for ${aiOptions.provider} is missing`);\n }\n\n const languageModel = await getLanguageModel(\n aiOptions,\n apiKey,\n defaultOptions?.model\n );\n\n return {\n model: languageModel,\n temperature: aiOptions.temperature,\n dataSerialization: aiOptions.dataSerialization,\n };\n};\n"],"mappings":";;;;;;;;AAoLA,MAAM,aACJ,YACA,WACA,kBAA2B,UACxB;CACH,MAAM,gBAAgB,QAAQ,IAAI;AAElC,KAAI,WAAW,SAAS,SAAS,CAC/B,QAAO,WAAW,UAAU;AAG9B,KAAI,WAAW,SAAS,SAAS,IAAI,WAAW,OAC9C,QAAO,WAAW;AAGpB,KAAI,WAAW,SAAS,kBAAkB,IAAI,gBAC5C,QAAO,WAAW,UAAU;AAI9B,KAAI,WAAW,SAAS,eAAe,IAAI,gBACzC,QAAO,WAAW,UAAU;;AAMhC,MAAM,gBACJ,UACA,YACA,WACA,eAAsB,iBACZ;AAEV,KAAI,cAAc,aAAaA,mCAAY,QAAQ;AACjD,MAAI,aAAaA,mCAAY,OAC3B,QAAO,aAAa;AAGtB,MAAI,UACF,QAAO;AAGT,UAAQ,UAAR;GACE,QACE,QAAO;;;AAKb,KAAI,aAAa,SACf,OAAM,IAAI,MACR,4DACD;AAGH,QAAO;;AAGT,MAAM,mBAAmB,OACvB,WACA,QACA,iBACG;CACH,MAAM,aAAa,OAAU,gBAAoC;AAC/D,MAAI;AACF,UAAQ,MAAM,OA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Y,SAAS,gBAAgB;;;AAW3D,MAAM,mBAAgCA,mCAAY;;;;;;;;AAgBlD,MAAa,cAAc,OACzB,SACA,kBAA2B,UACL;CACtB,MAAM,EACJ,aACA,gBACA,gBACA,aAAa,CAAC,kBAAkB,KAC9B;CAEJ,MAAM,YAAY;EAChB,UAAU;EACV,GAAG;EACH,GAAG;EACH,GAAG;EACJ;CAED,MAAM,SAAS,UAAU,YAAY,WAAW,gBAAgB;AAGhE,KAAI,CAAC,UAAU,UAAU,aAAaA,mCAAY,OAChD,OAAM,IAAI,MAAM,eAAe,UAAU,SAAS,aAAa;AASjE,QAAO;EACL,OAPoB,MAAM,iBAC1B,WACA,QACA,gBAAgB,MACjB;EAIC,aAAa,UAAU;EACvB,mBAAmB,UAAU;EAC9B"}
@@ -1,4 +1,56 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../aiSdk-Du5xFzsz.cjs`);const e=require(`../_utils_asset-mukucLSM.cjs`);let t=require(`ai`),n=require(`zod`);const r={},i=async({fileContent:r,tags:i,aiConfig:a,applicationContext:o})=>{let s=e.t(`./PROMPT.md`),c=e.t(`./EXAMPLE_REQUEST.md`),l=e.t(`./EXAMPLE_RESPONSE.md`),u=s.replace(`{{applicationContext}}`,o??``).replace(`{{tags}}`,i?JSON.stringify(i.map(({key:e,description:t})=>`- ${e}: ${t}`).join(`
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require__utils_asset = require('../_virtual/_utils_asset.cjs');
4
+ let ai = require("ai");
5
+ let zod = require("zod");
2
6
 
3
- `),null,2):``),{dataSerialization:d,...f}=a,{output:p,...m}=f,{output:h,usage:g}=await(0,t.generateText)({...m,output:t.Output.object({schema:n.z.object({title:n.z.string(),description:n.z.string(),tags:n.z.array(n.z.string())})}),messages:[{role:`system`,content:u},{role:`user`,content:c},{role:`assistant`,content:l},{role:`user`,content:r}]});return{fileContent:h,tokenUsed:g?.totalTokens??0}};exports.aiDefaultOptions=r,exports.auditDictionaryMetadata=i;
7
+ //#region src/auditDictionaryMetadata/index.ts
8
+ const aiDefaultOptions = {};
9
+ /**
10
+ * Audits a content declaration file by constructing a prompt for AI models.
11
+ * The prompt includes details about the project's locales, file paths of content declarations,
12
+ * and requests for identifying issues or inconsistencies.
13
+ */
14
+ const auditDictionaryMetadata = async ({ fileContent, tags, aiConfig, applicationContext }) => {
15
+ const CHAT_GPT_PROMPT = require__utils_asset.readAsset("./PROMPT.md");
16
+ const EXAMPLE_REQUEST = require__utils_asset.readAsset("./EXAMPLE_REQUEST.md");
17
+ const EXAMPLE_RESPONSE = require__utils_asset.readAsset("./EXAMPLE_RESPONSE.md");
18
+ const prompt = CHAT_GPT_PROMPT.replace("{{applicationContext}}", applicationContext ?? "").replace("{{tags}}", tags ? JSON.stringify(tags.map(({ key, description }) => `- ${key}: ${description}`).join("\n\n"), null, 2) : "");
19
+ const { dataSerialization, ...restAiConfig } = aiConfig;
20
+ const { output: _unusedOutput, ...validAiConfig } = restAiConfig;
21
+ const { output, usage } = await (0, ai.generateText)({
22
+ ...validAiConfig,
23
+ output: ai.Output.object({ schema: zod.z.object({
24
+ title: zod.z.string(),
25
+ description: zod.z.string(),
26
+ tags: zod.z.array(zod.z.string())
27
+ }) }),
28
+ messages: [
29
+ {
30
+ role: "system",
31
+ content: prompt
32
+ },
33
+ {
34
+ role: "user",
35
+ content: EXAMPLE_REQUEST
36
+ },
37
+ {
38
+ role: "assistant",
39
+ content: EXAMPLE_RESPONSE
40
+ },
41
+ {
42
+ role: "user",
43
+ content: fileContent
44
+ }
45
+ ]
46
+ });
47
+ return {
48
+ fileContent: output,
49
+ tokenUsed: usage?.totalTokens ?? 0
50
+ };
51
+ };
52
+
53
+ //#endregion
54
+ exports.aiDefaultOptions = aiDefaultOptions;
55
+ exports.auditDictionaryMetadata = auditDictionaryMetadata;
4
56
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["readAsset","Output","z"],"sources":["../../../src/auditDictionaryMetadata/index.ts"],"sourcesContent":["import { readAsset } from 'utils:asset';\nimport { generateText, Output } from 'ai';\nimport { z } from 'zod';\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 messages: [\n { role: 'system', content: prompt },\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":"yLA0BA,MAAa,EAA8B,EAE1C,CAOY,EAA0B,MAAO,CAC5C,cACA,OACA,WACA,wBAGG,CACH,IAAM,EAAkBA,EAAAA,EAAU,cAAc,CAC1C,EAAkBA,EAAAA,EAAU,uBAAuB,CACnD,EAAmBA,EAAAA,EAAU,wBAAwB,CAGrD,EAAS,EAAgB,QAC7B,yBACA,GAAsB,GACvB,CAAC,QACA,WACA,EACI,KAAK,UACH,EACG,KAAK,CAAE,MAAK,iBAAkB,KAAK,EAAI,IAAI,IAAc,CACzD,KAAK;;EAAO,CACf,KACA,EACD,CACD,GACL,CAEK,CAAE,oBAAmB,GAAG,GAAiB,EACzC,CAAE,OAAQ,EAAe,GAAG,GAAkB,EAG9C,CAAE,SAAQ,SAAU,MAAA,EAAA,EAAA,cAAmB,CAC3C,GAAG,EACH,OAAQC,EAAAA,OAAO,OAAO,CACpB,OAAQC,EAAAA,EAAE,OAAO,CACf,MAAOA,EAAAA,EAAE,QAAQ,CACjB,YAAaA,EAAAA,EAAE,QAAQ,CACvB,KAAMA,EAAAA,EAAE,MAAMA,EAAAA,EAAE,QAAQ,CAAC,CAC1B,CAAC,CACH,CAAC,CACF,SAAU,CACR,CAAE,KAAM,SAAU,QAAS,EAAQ,CACnC,CAAE,KAAM,OAAQ,QAAS,EAAiB,CAC1C,CAAE,KAAM,YAAa,QAAS,EAAkB,CAChD,CACE,KAAM,OACN,QAAS,EACV,CACF,CACF,CAAC,CAEF,MAAO,CACL,YAAa,EACb,UAAW,GAAO,aAAe,EAClC"}
1
+ {"version":3,"file":"index.cjs","names":["readAsset","Output","z"],"sources":["../../../src/auditDictionaryMetadata/index.ts"],"sourcesContent":["import { readAsset } from 'utils:asset';\nimport { generateText, Output } from 'ai';\nimport { z } from 'zod';\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 messages: [\n { role: 'system', content: prompt },\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,EAE1C;;;;;;AAOD,MAAa,0BAA0B,OAAO,EAC5C,aACA,MACA,UACA,yBAGG;CACH,MAAM,kBAAkBA,+BAAU,cAAc;CAChD,MAAM,kBAAkBA,+BAAU,uBAAuB;CACzD,MAAM,mBAAmBA,+BAAU,wBAAwB;CAG3D,MAAM,SAAS,gBAAgB,QAC7B,0BACA,sBAAsB,GACvB,CAAC,QACA,YACA,OACI,KAAK,UACH,KACG,KAAK,EAAE,KAAK,kBAAkB,KAAK,IAAI,IAAI,cAAc,CACzD,KAAK,OAAO,EACf,MACA,EACD,GACD,GACL;CAED,MAAM,EAAE,mBAAmB,GAAG,iBAAiB;CAC/C,MAAM,EAAE,QAAQ,eAAe,GAAG,kBAAkB;CAGpD,MAAM,EAAE,QAAQ,UAAU,2BAAmB;EAC3C,GAAG;EACH,QAAQC,UAAO,OAAO,EACpB,QAAQC,MAAE,OAAO;GACf,OAAOA,MAAE,QAAQ;GACjB,aAAaA,MAAE,QAAQ;GACvB,MAAMA,MAAE,MAAMA,MAAE,QAAQ,CAAC;GAC1B,CAAC,EACH,CAAC;EACF,UAAU;GACR;IAAE,MAAM;IAAU,SAAS;IAAQ;GACnC;IAAE,MAAM;IAAQ,SAAS;IAAiB;GAC1C;IAAE,MAAM;IAAa,SAAS;IAAkB;GAChD;IACE,MAAM;IACN,SAAS;IACV;GACF;EACF,CAAC;AAEF,QAAO;EACL,aAAa;EACb,WAAW,OAAO,eAAe;EAClC"}
@@ -1,2 +1,26 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./aiSdk-Du5xFzsz.cjs`);let e=require(`ai`);const t={model:`gpt-4o-mini`},n=async({messages:t,aiConfig:n})=>{let{text:r,usage:i}=await(0,e.generateText)({...n,messages:t});return{fileContent:r,tokenUsed:i?.totalTokens??0}};exports.aiDefaultOptions=t,exports.customQuery=n;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let ai = require("ai");
4
+
5
+ //#region src/customQuery.ts
6
+ const aiDefaultOptions = { model: "gpt-4o-mini" };
7
+ /**
8
+ * CustomQuery a content declaration file by constructing a prompt for AI models.
9
+ * The prompt includes details about the project's locales, file paths of content declarations,
10
+ * and requests for identifying issues or inconsistencies.
11
+ */
12
+ const customQuery = async ({ messages, aiConfig }) => {
13
+ const { text: newContent, usage } = await (0, ai.generateText)({
14
+ ...aiConfig,
15
+ messages
16
+ });
17
+ return {
18
+ fileContent: newContent,
19
+ tokenUsed: usage?.totalTokens ?? 0
20
+ };
21
+ };
22
+
23
+ //#endregion
24
+ exports.aiDefaultOptions = aiDefaultOptions;
25
+ exports.customQuery = customQuery;
2
26
  //# sourceMappingURL=customQuery.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"customQuery.cjs","names":[],"sources":["../../src/customQuery.ts"],"sourcesContent":["import { generateText } from 'ai';\nimport type { AIConfig, AIOptions, Messages } from './aiSdk';\n\nexport type CustomQueryOptions = {\n messages: Messages;\n aiConfig: AIConfig;\n};\n\nexport type CustomQueryResultData = {\n fileContent: string;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n model: 'gpt-4o-mini',\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 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 messages,\n });\n\n return {\n fileContent: newContent,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":"uHAaA,MAAa,EAA8B,CACzC,MAAO,cAER,CAOY,EAAc,MAAO,CAChC,WACA,cACoE,CAEpE,GAAM,CAAE,KAAM,EAAY,SAAU,MAAA,EAAA,EAAA,cAAmB,CACrD,GAAG,EACH,WACD,CAAC,CAEF,MAAO,CACL,YAAa,EACb,UAAW,GAAO,aAAe,EAClC"}
1
+ {"version":3,"file":"customQuery.cjs","names":[],"sources":["../../src/customQuery.ts"],"sourcesContent":["import { generateText } from 'ai';\nimport type { AIConfig, AIOptions, Messages } from './aiSdk';\n\nexport type CustomQueryOptions = {\n messages: Messages;\n aiConfig: AIConfig;\n};\n\nexport type CustomQueryResultData = {\n fileContent: string;\n tokenUsed: number;\n};\n\nexport const aiDefaultOptions: AIOptions = {\n model: 'gpt-4o-mini',\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 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 messages,\n });\n\n return {\n fileContent: newContent,\n tokenUsed: usage?.totalTokens ?? 0,\n };\n};\n"],"mappings":";;;;;AAaA,MAAa,mBAA8B,EACzC,OAAO,eAER;;;;;;AAOD,MAAa,cAAc,OAAO,EAChC,UACA,eACoE;CAEpE,MAAM,EAAE,MAAM,YAAY,UAAU,2BAAmB;EACrD,GAAG;EACH;EACD,CAAC;AAEF,QAAO;EACL,aAAa;EACb,WAAW,OAAO,eAAe;EAClC"}
@@ -1 +1,28 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./aiSdk-Du5xFzsz.cjs`),t=require(`./customQuery.cjs`),n=require(`./auditDictionaryMetadata/index.cjs`),r=require(`./utils/extractJSON.cjs`),i=require(`./translateJSON/index.cjs`);let a=require(`ai`),o=require(`@intlayer/types/config`);exports.AIProvider=o.AiProviders,exports.auditDictionaryMetadata=n.auditDictionaryMetadata,exports.customQuery=t.customQuery,exports.extractJson=r.extractJson,Object.defineProperty(exports,`generateText`,{enumerable:!0,get:function(){return a.generateText}}),exports.getAIConfig=e.t,Object.defineProperty(exports,`streamText`,{enumerable:!0,get:function(){return a.streamText}}),exports.translateJSON=i.translateJSON;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_customQuery = require('./customQuery.cjs');
4
+ const require_aiSdk = require('./aiSdk.cjs');
5
+ const require_auditDictionaryMetadata_index = require('./auditDictionaryMetadata/index.cjs');
6
+ const require_utils_extractJSON = require('./utils/extractJSON.cjs');
7
+ const require_translateJSON_index = require('./translateJSON/index.cjs');
8
+ let ai = require("ai");
9
+ let _intlayer_types_config = require("@intlayer/types/config");
10
+
11
+ exports.AIProvider = _intlayer_types_config.AiProviders;
12
+ exports.auditDictionaryMetadata = require_auditDictionaryMetadata_index.auditDictionaryMetadata;
13
+ exports.customQuery = require_customQuery.customQuery;
14
+ exports.extractJson = require_utils_extractJSON.extractJson;
15
+ Object.defineProperty(exports, 'generateText', {
16
+ enumerable: true,
17
+ get: function () {
18
+ return ai.generateText;
19
+ }
20
+ });
21
+ exports.getAIConfig = require_aiSdk.getAIConfig;
22
+ Object.defineProperty(exports, 'streamText', {
23
+ enumerable: true,
24
+ get: function () {
25
+ return ai.streamText;
26
+ }
27
+ });
28
+ exports.translateJSON = require_translateJSON_index.translateJSON;