@intlayer/ai 8.1.1 → 8.1.3-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,97 +1,2 @@
1
- let node_fs = require("node:fs");
2
- let node_path = require("node:path");
3
- let node_url = require("node:url");
4
-
5
- //#region \0utils:asset
6
- const hereDirname = () => {
7
- try {
8
- return (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
9
- } catch {
10
- return typeof __dirname !== "undefined" ? __dirname : process.cwd();
11
- }
12
- };
13
- const findDistRoot = (startDir) => {
14
- let dir = startDir;
15
- for (let i = 0; i < 12; i++) {
16
- if ((0, node_path.basename)(dir) === "dist") return dir;
17
- const parent = (0, node_path.resolve)(dir, "..");
18
- if (parent === dir) break;
19
- dir = parent;
20
- }
21
- return null;
22
- };
23
- const normalizeFrameFile = (file) => {
24
- if (!file) return null;
25
- try {
26
- if (file.startsWith("file://")) return (0, node_url.fileURLToPath)(file);
27
- } catch {}
28
- return file;
29
- };
30
- /**
31
- * Returns the directory of the *caller* module that invoked readAsset.
32
- * Prefers non-virtual frames; falls back to the first real frame.
33
- */
34
- const getCallerDir = () => {
35
- const prev = Error.prepareStackTrace;
36
- try {
37
- Error.prepareStackTrace = (_, structured) => structured;
38
- const err = /* @__PURE__ */ new Error();
39
- Error.captureStackTrace(err, getCallerDir);
40
- /** @type {import('node:vm').CallSite[]} */
41
- const frames = err.stack || [];
42
- const isVirtualPath = (p) => p.includes(`${node_path.sep}_virtual${node_path.sep}`) || p.includes("/_virtual/");
43
- for (const frame of frames) {
44
- const file = normalizeFrameFile(typeof frame.getFileName === "function" ? frame.getFileName() : null);
45
- if (!file) continue;
46
- if (file.includes("node:internal") || file.includes(`${node_path.sep}internal${node_path.sep}modules${node_path.sep}`)) continue;
47
- if (!isVirtualPath(file)) return (0, node_path.dirname)(file);
48
- }
49
- for (const frame of frames) {
50
- const file = normalizeFrameFile(typeof frame.getFileName === "function" ? frame.getFileName() : null);
51
- if (file) return (0, node_path.dirname)(file);
52
- }
53
- } catch {} finally {
54
- Error.prepareStackTrace = prev;
55
- }
56
- return hereDirname();
57
- };
58
- /**
59
- * Read an asset copied from src/** to dist/assets/**.
60
- * - './' or '../' is resolved relative to the *caller module's* emitted directory.
61
- * - otherwise, treat as src-relative.
62
- *
63
- * @param {string} relPath - e.g. './PROMPT.md' or 'utils/AI/askDocQuestion/embeddings/<fileKey>.json'
64
- * @param {BufferEncoding} [encoding='utf8']
65
- */
66
- const readAsset = (relPath, encoding = "utf8") => {
67
- const here = hereDirname();
68
- const distRoot = findDistRoot(here) ?? (0, node_path.resolve)(here, "..", "..", "dist");
69
- const assetsRoot = (0, node_path.join)(distRoot, "assets");
70
- const tried = [];
71
- /**
72
- * Transform dist/(esm|cjs)/... and _virtual/ prefix to clean subpath (Windows-safe)
73
- */
74
- const callerSubpath = (0, node_path.relative)(distRoot, getCallerDir()).split("\\").join("/").replace(/^(?:dist\/)?(?:esm|cjs)\//, "").replace(/^_virtual\//, "");
75
- if (relPath.startsWith("./") || relPath.startsWith("../")) {
76
- const fromCallerAbs = (0, node_path.resolve)(assetsRoot, callerSubpath, relPath);
77
- tried.push(fromCallerAbs);
78
- if ((0, node_fs.existsSync)(fromCallerAbs)) return (0, node_fs.readFileSync)(fromCallerAbs, encoding);
79
- }
80
- const directPath = (0, node_path.join)(assetsRoot, relPath);
81
- tried.push(directPath);
82
- if ((0, node_fs.existsSync)(directPath)) return (0, node_fs.readFileSync)(directPath, encoding);
83
- if (callerSubpath) {
84
- const nested = (0, node_path.join)(assetsRoot, callerSubpath, relPath);
85
- tried.push(nested);
86
- if ((0, node_fs.existsSync)(nested)) return (0, node_fs.readFileSync)(nested, encoding);
87
- }
88
- const msg = [
89
- "readAsset: file not found.",
90
- "Searched:",
91
- ...tried.map((p) => `- ${p}`)
92
- ].join("\n");
93
- throw new Error(msg);
94
- };
95
-
96
- //#endregion
97
- exports.readAsset = readAsset;
1
+ let e=require(`node:fs`),t=require(`node:path`),n=require(`node:url`);const r=()=>{try{return(0,t.dirname)((0,n.fileURLToPath)(require(`url`).pathToFileURL(__filename).href))}catch{return typeof __dirname<`u`?__dirname:process.cwd()}},i=e=>{let n=e;for(let e=0;e<12;e++){if((0,t.basename)(n)===`dist`)return n;let e=(0,t.resolve)(n,`..`);if(e===n)break;n=e}return null},a=e=>{if(!e)return null;try{if(e.startsWith(`file://`))return(0,n.fileURLToPath)(e)}catch{}return e},o=()=>{let e=Error.prepareStackTrace;try{Error.prepareStackTrace=(e,t)=>t;let e=Error();Error.captureStackTrace(e,o);let n=e.stack||[],r=e=>e.includes(`${t.sep}_virtual${t.sep}`)||e.includes(`/_virtual/`);for(let e of n){let n=a(typeof e.getFileName==`function`?e.getFileName():null);if(n&&!(n.includes(`node:internal`)||n.includes(`${t.sep}internal${t.sep}modules${t.sep}`))&&!r(n))return(0,t.dirname)(n)}for(let e of n){let n=a(typeof e.getFileName==`function`?e.getFileName():null);if(n)return(0,t.dirname)(n)}}catch{}finally{Error.prepareStackTrace=e}return r()},s=(n,a=`utf8`)=>{let s=r(),c=i(s)??(0,t.resolve)(s,`..`,`..`,`dist`),l=(0,t.join)(c,`assets`),u=[],d=(0,t.relative)(c,o()).split(`\\`).join(`/`).replace(/^(?:dist\/)?(?:esm|cjs)\//,``).replace(/^_virtual\//,``);if(n.startsWith(`./`)||n.startsWith(`../`)){let r=(0,t.resolve)(l,d,n);if(u.push(r),(0,e.existsSync)(r))return(0,e.readFileSync)(r,a)}let f=(0,t.join)(l,n);if(u.push(f),(0,e.existsSync)(f))return(0,e.readFileSync)(f,a);if(d){let r=(0,t.join)(l,d,n);if(u.push(r),(0,e.existsSync)(r))return(0,e.readFileSync)(r,a)}let p=[`readAsset: file not found.`,`Searched:`,...u.map(e=>`- ${e}`)].join(`
2
+ `);throw Error(p)};exports.readAsset=s;
@@ -1,203 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- let _intlayer_config = require("@intlayer/config");
3
- let _intlayer_types = require("@intlayer/types");
4
-
5
- //#region src/aiSdk.ts
6
- const getAPIKey = (accessType, aiOptions, isAuthenticated = false) => {
7
- const defaultApiKey = process.env.OPENAI_API_KEY;
8
- if (accessType.includes("public")) return aiOptions?.apiKey ?? defaultApiKey;
9
- if (accessType.includes("apiKey") && aiOptions?.apiKey) return aiOptions?.apiKey;
10
- if (accessType.includes("registered_user") && isAuthenticated) return aiOptions?.apiKey ?? defaultApiKey;
11
- if (accessType.includes("premium_user") && isAuthenticated) return aiOptions?.apiKey ?? defaultApiKey;
12
- };
13
- const getModelName = (provider, userApiKey, userModel, defaultModel = "gpt-5-mini") => {
14
- if (userApiKey || provider === _intlayer_types.AiProviders.OLLAMA) {
15
- if (provider === _intlayer_types.AiProviders.OPENAI) return userModel ?? defaultModel;
16
- if (userModel) return userModel;
17
- switch (provider) {
18
- default: return "-";
19
- }
20
- }
21
- if (userModel || provider) throw new Error("The user should use his own API key to use a custom model");
22
- return defaultModel;
23
- };
24
- const getLanguageModel = async (aiOptions, apiKey, defaultModel) => {
25
- const loadModule = async (packageName) => {
26
- try {
27
- return await import(packageName);
28
- } catch {
29
- (0, _intlayer_config.logger)(`${_intlayer_config.x} The package "${(0, _intlayer_config.colorize)(packageName, _intlayer_config.ANSIColors.GREEN)}" is required to use this AI provider. Please install it using: ${(0, _intlayer_config.colorize)(`npm install ${packageName}`, _intlayer_config.ANSIColors.GREY_DARK)}`, { level: "error" });
30
- process.exit();
31
- }
32
- };
33
- const provider = aiOptions.provider ?? _intlayer_types.AiProviders.OPENAI;
34
- const selectedModel = getModelName(provider, apiKey, aiOptions.model, defaultModel);
35
- const baseURL = aiOptions.baseURL;
36
- switch (provider) {
37
- case _intlayer_types.AiProviders.OPENAI: {
38
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
39
- const { createOpenAI } = await loadModule("@ai-sdk/openai");
40
- return createOpenAI({
41
- apiKey,
42
- baseURL,
43
- ...otherOptions
44
- })(selectedModel);
45
- }
46
- case _intlayer_types.AiProviders.ANTHROPIC: {
47
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
48
- const { createAnthropic } = await loadModule("@ai-sdk/anthropic");
49
- return createAnthropic({
50
- apiKey,
51
- baseURL,
52
- ...otherOptions
53
- })(selectedModel);
54
- }
55
- case _intlayer_types.AiProviders.MISTRAL: {
56
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
57
- const { createMistral } = await loadModule("@ai-sdk/mistral");
58
- return createMistral({
59
- apiKey,
60
- baseURL,
61
- ...otherOptions
62
- })(selectedModel);
63
- }
64
- case _intlayer_types.AiProviders.DEEPSEEK: {
65
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
66
- const { createDeepSeek } = await loadModule("@ai-sdk/deepseek");
67
- return createDeepSeek({
68
- apiKey,
69
- baseURL,
70
- ...otherOptions
71
- })(selectedModel);
72
- }
73
- case _intlayer_types.AiProviders.GEMINI: {
74
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
75
- const { createGoogleGenerativeAI } = await loadModule("@ai-sdk/google");
76
- return createGoogleGenerativeAI({
77
- apiKey,
78
- baseURL,
79
- ...otherOptions
80
- })(selectedModel);
81
- }
82
- case _intlayer_types.AiProviders.GOOGLEVERTEX: {
83
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
84
- const { createVertex } = await loadModule("@ai-sdk/google-vertex");
85
- return createVertex({
86
- apiKey,
87
- baseURL,
88
- ...otherOptions
89
- })(selectedModel);
90
- }
91
- case _intlayer_types.AiProviders.GOOGLEGENERATIVEAI: {
92
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
93
- const { createGoogleGenerativeAI } = await loadModule("@ai-sdk/google");
94
- return createGoogleGenerativeAI({
95
- apiKey,
96
- baseURL,
97
- ...otherOptions
98
- })(selectedModel);
99
- }
100
- case _intlayer_types.AiProviders.OLLAMA: {
101
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
102
- const { createOpenAI } = await loadModule("@ai-sdk/openai");
103
- return createOpenAI({
104
- baseURL: baseURL ?? "http://localhost:11434/v1",
105
- apiKey: apiKey ?? "ollama",
106
- ...otherOptions
107
- }).chat(selectedModel);
108
- }
109
- case _intlayer_types.AiProviders.OPENROUTER: {
110
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
111
- const { createOpenRouter } = await loadModule("@openrouter/ai-sdk-provider");
112
- return createOpenRouter({
113
- apiKey,
114
- baseURL,
115
- ...otherOptions
116
- })(selectedModel);
117
- }
118
- case _intlayer_types.AiProviders.ALIBABA: {
119
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
120
- const { createAlibaba } = await loadModule("@ai-sdk/alibaba");
121
- return createAlibaba({
122
- apiKey,
123
- baseURL,
124
- ...otherOptions
125
- })(selectedModel);
126
- }
127
- case _intlayer_types.AiProviders.FIREWORKS: {
128
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
129
- const { createFireworks } = await loadModule("@ai-sdk/fireworks");
130
- return createFireworks({
131
- apiKey,
132
- baseURL,
133
- ...otherOptions
134
- })(selectedModel);
135
- }
136
- case _intlayer_types.AiProviders.GROQ: {
137
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
138
- const { createGroq } = await loadModule("@ai-sdk/groq");
139
- return createGroq({
140
- apiKey,
141
- baseURL,
142
- ...otherOptions
143
- })(selectedModel);
144
- }
145
- case _intlayer_types.AiProviders.HUGGINGFACE: {
146
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
147
- const { createHuggingFace } = await loadModule("@ai-sdk/huggingface");
148
- return createHuggingFace({
149
- apiKey,
150
- baseURL,
151
- ...otherOptions
152
- })(selectedModel);
153
- }
154
- case _intlayer_types.AiProviders.BEDROCK: {
155
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
156
- const { createAmazonBedrock } = await loadModule("@ai-sdk/amazon-bedrock");
157
- return createAmazonBedrock({
158
- accessKeyId: apiKey,
159
- baseURL,
160
- ...otherOptions
161
- })(selectedModel);
162
- }
163
- case _intlayer_types.AiProviders.TOGETHERAI: {
164
- const { provider, model, temperature, applicationContext, dataSerialization, apiKey: _apiKey, baseURL: _baseURL, ...otherOptions } = aiOptions;
165
- const { createTogetherAI } = await loadModule("@ai-sdk/togetherai");
166
- return createTogetherAI({
167
- apiKey,
168
- baseURL,
169
- ...otherOptions
170
- })(selectedModel);
171
- }
172
- default: throw new Error(`Provider ${provider} not supported`);
173
- }
174
- };
175
- const DEFAULT_PROVIDER = _intlayer_types.AiProviders.OPENAI;
176
- /**
177
- * Get AI model configuration based on the selected provider and options
178
- * This function handles the configuration for different AI providers
179
- *
180
- * @param options Configuration options including provider, API keys, models and temperature
181
- * @returns Configured AI model ready to use with generateText
182
- */
183
- const getAIConfig = async (options, isAuthenticated = false) => {
184
- const { userOptions, projectOptions, defaultOptions, accessType = ["registered_user"] } = options;
185
- const aiOptions = {
186
- provider: DEFAULT_PROVIDER,
187
- ...defaultOptions,
188
- ...projectOptions,
189
- ...userOptions
190
- };
191
- const apiKey = getAPIKey(accessType, aiOptions, isAuthenticated);
192
- if (!apiKey && aiOptions.provider !== _intlayer_types.AiProviders.OLLAMA) throw new Error(`API key for ${aiOptions.provider} is missing`);
193
- return {
194
- model: await getLanguageModel(aiOptions, apiKey, defaultOptions?.model),
195
- temperature: aiOptions.temperature,
196
- dataSerialization: aiOptions.dataSerialization
197
- };
198
- };
199
-
200
- //#endregion
201
- exports.AIProvider = _intlayer_types.AiProviders;
202
- exports.getAIConfig = getAIConfig;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@intlayer/config/logger`),t=require(`@intlayer/types`);const n=(e,t,n=!1)=>{let r=process.env.OPENAI_API_KEY;if(e.includes(`public`))return t?.apiKey??r;if(e.includes(`apiKey`)&&t?.apiKey)return t?.apiKey;if(e.includes(`registered_user`)&&n||e.includes(`premium_user`)&&n)return t?.apiKey??r},r=(e,n,r,i=`gpt-5-mini`)=>{if(n||e===t.AiProviders.OLLAMA){if(e===t.AiProviders.OPENAI)return r??i;if(r)return r;switch(e){default:return`-`}}if(r||e)throw Error(`The user should use his own API key to use a custom model`);return i},i=async(n,i,a)=>{let o=async t=>{try{return await import(t)}catch{(0,e.logger)(`${e.x} The package "${(0,e.colorize)(t,e.ANSIColors.GREEN)}" is required to use this AI provider. Please install it using: ${(0,e.colorize)(`npm install ${t}`,e.ANSIColors.GREY_DARK)}`,{level:`error`}),process.exit()}},s=n.provider??t.AiProviders.OPENAI,c=r(s,i,n.model,a),l=n.baseURL;switch(s){case t.AiProviders.OPENAI:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createOpenAI:p}=await o(`@ai-sdk/openai`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.ANTHROPIC:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createAnthropic:p}=await o(`@ai-sdk/anthropic`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.MISTRAL:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createMistral:p}=await o(`@ai-sdk/mistral`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.DEEPSEEK:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createDeepSeek:p}=await o(`@ai-sdk/deepseek`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.GEMINI:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createGoogleGenerativeAI:p}=await o(`@ai-sdk/google`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.GOOGLEVERTEX:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createVertex:p}=await o(`@ai-sdk/google-vertex`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.GOOGLEGENERATIVEAI:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createGoogleGenerativeAI:p}=await o(`@ai-sdk/google`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.OLLAMA:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createOpenAI:p}=await o(`@ai-sdk/openai`);return p({baseURL:l??`http://localhost:11434/v1`,apiKey:i??`ollama`,...f}).chat(c)}case t.AiProviders.OPENROUTER:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createOpenRouter:p}=await o(`@openrouter/ai-sdk-provider`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.ALIBABA:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createAlibaba:p}=await o(`@ai-sdk/alibaba`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.FIREWORKS:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createFireworks:p}=await o(`@ai-sdk/fireworks`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.GROQ:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createGroq:p}=await o(`@ai-sdk/groq`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.HUGGINGFACE:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createHuggingFace:p}=await o(`@ai-sdk/huggingface`);return p({apiKey:i,baseURL:l,...f})(c)}case t.AiProviders.BEDROCK:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createAmazonBedrock:p}=await o(`@ai-sdk/amazon-bedrock`);return p({accessKeyId:i,baseURL:l,...f})(c)}case t.AiProviders.TOGETHERAI:{let{provider:e,model:t,temperature:r,applicationContext:a,dataSerialization:s,apiKey:u,baseURL:d,...f}=n,{createTogetherAI:p}=await o(`@ai-sdk/togetherai`);return p({apiKey:i,baseURL:l,...f})(c)}default:throw Error(`Provider ${s} not supported`)}},a=t.AiProviders.OPENAI,o=async(e,r=!1)=>{let{userOptions:o,projectOptions:s,defaultOptions:c,accessType:l=[`registered_user`]}=e,u={provider:a,...c,...s,...o},d=n(l,u,r);if(!d&&u.provider!==t.AiProviders.OLLAMA)throw Error(`API key for ${u.provider} is missing`);return{model:await i(u,d,c?.model),temperature:u.temperature,dataSerialization:u.dataSerialization}};exports.AIProvider=t.AiProviders,exports.getAIConfig=o;
203
2
  //# sourceMappingURL=aiSdk.cjs.map
@@ -1 +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 { ANSIColors, colorize, logger, x } from '@intlayer/config';\nimport { AiProviders } from '@intlayer/types';\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":";;;;;AAmLA,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,kBAA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;GACxB,MAAM,EACJ,UACA,OACA,aACA,oBACA,mBACA,QAAQ,SACR,SAAS,UACT,GAAG,iBACD;GAEJ,MAAM,EAAE,wBAAwB,MAAM,WAEpC,yBAAyB;AAQ3B,UANgB,oBAAoB;IAClC,aAAa;IACb;IACA,GAAG;IACJ,CAAC,CAEa,cAAwB;;EAGzC,KAAKA,4BAAY,YAAY;GAC3B,MAAM,EACJ,UACA,OACA,aACA,oBACA,mBACA,QAAQ,SACR,SAAS,UACT,GAAG,iBACD;GAEJ,MAAM,EAAE,qBACN,MAAM,WACJ,qBACD;AAQH,UANmB,iBAAiB;IAClC;IACA;IACA,GAAG;IACJ,CAAC,CAEgB,cAAwB;;EAG5C,QACE,OAAM,IAAI,MAAM,YAAY,SAAS,gBAAgB;;;AAW3D,MAAM,mBAAgCA,4BAAY;;;;;;;;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,4BAAY,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
+ {"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 { ANSIColors, colorize, logger, x } from '@intlayer/config/logger';\nimport { AiProviders } from '@intlayer/types';\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":"yIAmLA,MAAM,GACJ,EACA,EACA,EAA2B,KACxB,CACH,IAAM,EAAgB,QAAQ,IAAI,eAElC,GAAI,EAAW,SAAS,SAAS,CAC/B,OAAO,GAAW,QAAU,EAG9B,GAAI,EAAW,SAAS,SAAS,EAAI,GAAW,OAC9C,OAAO,GAAW,OAQpB,GALI,EAAW,SAAS,kBAAkB,EAAI,GAK1C,EAAW,SAAS,eAAe,EAAI,EACzC,OAAO,GAAW,QAAU,GAM1B,GACJ,EACA,EACA,EACA,EAAsB,eACZ,CA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,EACb,UACA,GAAG,EACJ,CAAC,CAEa,EAAwB,CAGzC,KAAKA,EAAAA,YAAY,WAAY,CAC3B,GAAM,CACJ,WACA,QACA,cACA,qBACA,oBACA,OAAQ,EACR,QAAS,EACT,GAAG,GACD,EAEE,CAAE,oBACN,MAAM,EACJ,qBACD,CAQH,OANmB,EAAiB,CAClC,SACA,UACA,GAAG,EACJ,CAAC,CAEgB,EAAwB,CAG5C,QACE,MAAU,MAAM,YAAY,EAAS,gBAAgB,GAWrD,EAAgCA,EAAAA,YAAY,OAgBrC,EAAc,MACzB,EACA,EAA2B,KACL,CACtB,GAAM,CACJ,cACA,iBACA,iBACA,aAAa,CAAC,kBAAkB,EAC9B,EAEE,EAAY,CAChB,SAAU,EACV,GAAG,EACH,GAAG,EACH,GAAG,EACJ,CAEK,EAAS,EAAU,EAAY,EAAW,EAAgB,CAGhE,GAAI,CAAC,GAAU,EAAU,WAAaA,EAAAA,YAAY,OAChD,MAAU,MAAM,eAAe,EAAU,SAAS,aAAa,CASjE,MAAO,CACL,MAPoB,MAAM,EAC1B,EACA,EACA,GAAgB,MACjB,CAIC,YAAa,EAAU,YACvB,kBAAmB,EAAU,kBAC9B"}
@@ -1,55 +1,4 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require__utils_asset = require('../_virtual/_utils_asset.cjs');
3
- let ai = require("ai");
4
- let zod = require("zod");
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_utils_asset.cjs`);let t=require(`ai`),n=require(`zod`);const r={},i=async({fileContent:r,tags:i,aiConfig:a,applicationContext:o})=>{let s=e.readAsset(`./PROMPT.md`),c=e.readAsset(`./EXAMPLE_REQUEST.md`),l=e.readAsset(`./EXAMPLE_RESPONSE.md`),u=s.replace(`{{applicationContext}}`,o??``).replace(`{{tags}}`,i?JSON.stringify(i.map(({key:e,description:t})=>`- ${e}: ${t}`).join(`
5
2
 
6
- //#region src/auditDictionaryMetadata/index.ts
7
- const aiDefaultOptions = {};
8
- /**
9
- * Audits a content declaration file by constructing a prompt for AI models.
10
- * The prompt includes details about the project's locales, file paths of content declarations,
11
- * and requests for identifying issues or inconsistencies.
12
- */
13
- const auditDictionaryMetadata = async ({ fileContent, tags, aiConfig, applicationContext }) => {
14
- const CHAT_GPT_PROMPT = require__utils_asset.readAsset("./PROMPT.md");
15
- const EXAMPLE_REQUEST = require__utils_asset.readAsset("./EXAMPLE_REQUEST.md");
16
- const EXAMPLE_RESPONSE = require__utils_asset.readAsset("./EXAMPLE_RESPONSE.md");
17
- const prompt = CHAT_GPT_PROMPT.replace("{{applicationContext}}", applicationContext ?? "").replace("{{tags}}", tags ? JSON.stringify(tags.map(({ key, description }) => `- ${key}: ${description}`).join("\n\n"), null, 2) : "");
18
- const { dataSerialization, ...restAiConfig } = aiConfig;
19
- const { output: _unusedOutput, ...validAiConfig } = restAiConfig;
20
- const { output, usage } = await (0, ai.generateText)({
21
- ...validAiConfig,
22
- output: ai.Output.object({ schema: zod.z.object({
23
- title: zod.z.string(),
24
- description: zod.z.string(),
25
- tags: zod.z.array(zod.z.string())
26
- }) }),
27
- messages: [
28
- {
29
- role: "system",
30
- content: prompt
31
- },
32
- {
33
- role: "user",
34
- content: EXAMPLE_REQUEST
35
- },
36
- {
37
- role: "assistant",
38
- content: EXAMPLE_RESPONSE
39
- },
40
- {
41
- role: "user",
42
- content: fileContent
43
- }
44
- ]
45
- });
46
- return {
47
- fileContent: output,
48
- tokenUsed: usage?.totalTokens ?? 0
49
- };
50
- };
51
-
52
- //#endregion
53
- exports.aiDefaultOptions = aiDefaultOptions;
54
- exports.auditDictionaryMetadata = auditDictionaryMetadata;
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;
55
4
  //# 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":";;;;;;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
+ {"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":"wJA0BA,MAAa,EAA8B,EAE1C,CAOY,EAA0B,MAAO,CAC5C,cACA,OACA,WACA,wBAGG,CACH,IAAM,EAAkBA,EAAAA,UAAU,cAAc,CAC1C,EAAkBA,EAAAA,UAAU,uBAAuB,CACnD,EAAmBA,EAAAA,UAAU,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,25 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- let ai = require("ai");
3
-
4
- //#region src/customQuery.ts
5
- const aiDefaultOptions = { model: "gpt-4o-mini" };
6
- /**
7
- * CustomQuery a content declaration file by constructing a prompt for AI models.
8
- * The prompt includes details about the project's locales, file paths of content declarations,
9
- * and requests for identifying issues or inconsistencies.
10
- */
11
- const customQuery = async ({ messages, aiConfig }) => {
12
- const { text: newContent, usage } = await (0, ai.generateText)({
13
- ...aiConfig,
14
- messages
15
- });
16
- return {
17
- fileContent: newContent,
18
- tokenUsed: usage?.totalTokens ?? 0
19
- };
20
- };
21
-
22
- //#endregion
23
- exports.aiDefaultOptions = aiDefaultOptions;
24
- exports.customQuery = customQuery;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});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;
25
2
  //# 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":";;;;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
+ {"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":"uFAaA,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,27 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_aiSdk = require('./aiSdk.cjs');
3
- const require_customQuery = require('./customQuery.cjs');
4
- const require_auditDictionaryMetadata_index = require('./auditDictionaryMetadata/index.cjs');
5
- const require_translateJSON_index = require('./translateJSON/index.cjs');
6
- const require_utils_extractJSON = require('./utils/extractJSON.cjs');
7
- let ai = require("ai");
8
- let _intlayer_types = require("@intlayer/types");
9
-
10
- exports.AIProvider = _intlayer_types.AiProviders;
11
- exports.auditDictionaryMetadata = require_auditDictionaryMetadata_index.auditDictionaryMetadata;
12
- exports.customQuery = require_customQuery.customQuery;
13
- exports.extractJson = require_utils_extractJSON.extractJson;
14
- Object.defineProperty(exports, 'generateText', {
15
- enumerable: true,
16
- get: function () {
17
- return ai.generateText;
18
- }
19
- });
20
- exports.getAIConfig = require_aiSdk.getAIConfig;
21
- Object.defineProperty(exports, 'streamText', {
22
- enumerable: true,
23
- get: function () {
24
- return ai.streamText;
25
- }
26
- });
27
- exports.translateJSON = require_translateJSON_index.translateJSON;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./aiSdk.cjs`),t=require(`./customQuery.cjs`),n=require(`./auditDictionaryMetadata/index.cjs`),r=require(`./translateJSON/index.cjs`),i=require(`./utils/extractJSON.cjs`);let a=require(`ai`),o=require(`@intlayer/types`);exports.AIProvider=o.AiProviders,exports.auditDictionaryMetadata=n.auditDictionaryMetadata,exports.customQuery=t.customQuery,exports.extractJson=i.extractJson,Object.defineProperty(exports,`generateText`,{enumerable:!0,get:function(){return a.generateText}}),exports.getAIConfig=e.getAIConfig,Object.defineProperty(exports,`streamText`,{enumerable:!0,get:function(){return a.streamText}}),exports.translateJSON=r.translateJSON;