@lingo.dev/_compiler 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.cjs CHANGED
@@ -4,7 +4,7 @@ var _unplugin = require('unplugin');
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@lingo.dev/_compiler",
7
- version: "0.2.3",
7
+ version: "0.3.0",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -46,6 +46,8 @@ var package_default = {
46
46
  "@babel/parser": "^7.26.7",
47
47
  "@babel/traverse": "^7.27.4",
48
48
  "@babel/types": "^7.26.7",
49
+ "@lingo.dev/_sdk": "workspace:*",
50
+ "@openrouter/ai-sdk-provider": "^0.7.1",
49
51
  ai: "^4.2.10",
50
52
  dedent: "^1.6.0",
51
53
  dotenv: "^16.4.5",
@@ -53,11 +55,13 @@ var package_default = {
53
55
  ini: "^5.0.0",
54
56
  lodash: "^4.17.21",
55
57
  "object-hash": "^3.0.0",
58
+ "ollama-ai-provider": "^1.2.0",
56
59
  prettier: "^3.4.2",
57
60
  unplugin: "^2.1.2",
58
61
  vitest: "^2.1.4",
59
62
  zod: "^3.24.1"
60
- }
63
+ },
64
+ packageManager: "pnpm@9.12.3"
61
65
  };
62
66
 
63
67
  // src/index.ts
@@ -204,7 +208,7 @@ function findExistingImport(ast, exportedName, moduleName) {
204
208
  let result = null;
205
209
  _traverse2.default.call(void 0, ast, {
206
210
  ImportDeclaration(path7) {
207
- if (path7.node.source.value !== moduleName) {
211
+ if (!moduleName.includes(path7.node.source.value)) {
208
212
  return;
209
213
  }
210
214
  for (const specifier of path7.node.specifiers) {
@@ -244,14 +248,14 @@ function createImportDeclaration(ast, localName, exportedName, moduleName) {
244
248
  t2.identifier(exportedName)
245
249
  );
246
250
  const existingImport = path7.get("body").find(
247
- (nodePath) => t2.isImportDeclaration(nodePath.node) && nodePath.node.source.value === moduleName
251
+ (nodePath) => t2.isImportDeclaration(nodePath.node) && moduleName.includes(nodePath.node.source.value)
248
252
  );
249
253
  if (existingImport && t2.isImportDeclaration(existingImport.node)) {
250
254
  existingImport.node.specifiers.push(importSpecifier2);
251
255
  } else {
252
256
  const importDeclaration2 = t2.importDeclaration(
253
257
  [importSpecifier2],
254
- t2.stringLiteral(moduleName)
258
+ t2.stringLiteral(moduleName[0])
255
259
  );
256
260
  const lastImportIndex = findLastImportIndex(path7);
257
261
  path7.node.body.splice(lastImportIndex + 1, 0, importDeclaration2);
@@ -345,6 +349,11 @@ function getNestedJsxElements(nodePath) {
345
349
  }
346
350
 
347
351
  // src/_const.ts
352
+ var ModuleId = {
353
+ ReactClient: ["lingo.dev/react/client", "lingo.dev/react-client"],
354
+ ReactRSC: ["lingo.dev/react/rsc", "lingo.dev/react-rsc"],
355
+ ReactRouter: ["lingo.dev/react/react-router", "lingo.dev/react-router"]
356
+ };
348
357
  var LCP_DICTIONARY_FILE_NAME = "dictionary.js";
349
358
 
350
359
  // src/jsx-provider.ts
@@ -357,11 +366,11 @@ var jsxProviderMutation = createCodeMutation((payload) => {
357
366
  return;
358
367
  }
359
368
  const lingoProviderImport = getOrCreateImport(payload.ast, {
360
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
369
+ moduleName: ModuleId.ReactRSC,
361
370
  exportedName: "LingoProvider"
362
371
  });
363
372
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
364
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
373
+ moduleName: ModuleId.ReactRSC,
365
374
  exportedName: "loadDictionary"
366
375
  });
367
376
  const loadDictionaryArrow = t4.arrowFunctionExpression(
@@ -921,7 +930,10 @@ var LCPCache = class {
921
930
  // src/lib/lcp/api/index.ts
922
931
  var _groq = require('@ai-sdk/groq');
923
932
  var _google = require('@ai-sdk/google');
933
+ var _aisdkprovider = require('@openrouter/ai-sdk-provider');
934
+ var _ollamaaiprovider = require('ollama-ai-provider');
924
935
  var _ai = require('ai');
936
+ var __sdk = require('@lingo.dev/_sdk');
925
937
 
926
938
 
927
939
  // src/utils/locales.ts
@@ -944,7 +956,16 @@ function getLocaleModel(localeModels, sourceLocale, targetLocale) {
944
956
  ];
945
957
  const modelKey = localeKeys.find((key) => localeModels.hasOwnProperty(key));
946
958
  if (modelKey) {
947
- const [provider, model] = _optionalChain([localeModels, 'access', _29 => _29[modelKey], 'optionalAccess', _30 => _30.split, 'call', _31 => _31(":")]);
959
+ const value = localeModels[modelKey];
960
+ const firstColonIndex = _optionalChain([value, 'optionalAccess', _29 => _29.indexOf, 'call', _30 => _30(":")]);
961
+ if (value && firstColonIndex !== -1 && firstColonIndex !== void 0) {
962
+ const provider2 = value.substring(0, firstColonIndex);
963
+ const model2 = value.substring(firstColonIndex + 1);
964
+ if (provider2 && model2) {
965
+ return { provider: provider2, model: model2 };
966
+ }
967
+ }
968
+ const [provider, model] = _optionalChain([value, 'optionalAccess', _31 => _31.split, 'call', _32 => _32(":")]) || [];
948
969
  if (provider && model) {
949
970
  return { provider, model };
950
971
  }
@@ -957,7 +978,7 @@ var prompt_default = (args) => {
957
978
  return getUserSystemPrompt(args) || getBuiltInSystemPrompt(args);
958
979
  };
959
980
  function getUserSystemPrompt(args) {
960
- const userPrompt = _optionalChain([args, 'access', _32 => _32.prompt, 'optionalAccess', _33 => _33.trim, 'call', _34 => _34(), 'optionalAccess', _35 => _35.replace, 'call', _36 => _36("{SOURCE_LOCALE}", args.sourceLocale), 'optionalAccess', _37 => _37.replace, 'call', _38 => _38("{TARGET_LOCALE}", args.targetLocale)]);
981
+ const userPrompt = _optionalChain([args, 'access', _33 => _33.prompt, 'optionalAccess', _34 => _34.trim, 'call', _35 => _35(), 'optionalAccess', _36 => _36.replace, 'call', _37 => _37("{SOURCE_LOCALE}", args.sourceLocale), 'optionalAccess', _38 => _38.replace, 'call', _39 => _39("{TARGET_LOCALE}", args.targetLocale)]);
961
982
  if (userPrompt) {
962
983
  console.log("\u2728 Compiler is using user-defined prompt.");
963
984
  return userPrompt;
@@ -1167,7 +1188,7 @@ function getKeyFromEnv(envVarName) {
1167
1188
  path.default.resolve(process.cwd(), ".env.development")
1168
1189
  ]
1169
1190
  });
1170
- return _optionalChain([result, 'optionalAccess', _39 => _39.parsed, 'optionalAccess', _40 => _40[envVarName]]);
1191
+ return _optionalChain([result, 'optionalAccess', _40 => _40.parsed, 'optionalAccess', _41 => _41[envVarName]]);
1171
1192
  }
1172
1193
  function getKeyFromRc(rcPath) {
1173
1194
  const rc = getRc();
@@ -1183,6 +1204,15 @@ function getGroqKeyFromRc() {
1183
1204
  function getGroqKeyFromEnv() {
1184
1205
  return getKeyFromEnv("GROQ_API_KEY");
1185
1206
  }
1207
+ function getLingoDotDevKeyFromEnv() {
1208
+ return getKeyFromEnv("LINGODOTDEV_API_KEY");
1209
+ }
1210
+ function getLingoDotDevKeyFromRc() {
1211
+ return getKeyFromRc("auth.apiKey");
1212
+ }
1213
+ function getLingoDotDevKey() {
1214
+ return getLingoDotDevKeyFromEnv() || getLingoDotDevKeyFromRc();
1215
+ }
1186
1216
  function getGoogleKey() {
1187
1217
  return getGoogleKeyFromEnv() || getGoogleKeyFromRc();
1188
1218
  }
@@ -1192,6 +1222,15 @@ function getGoogleKeyFromRc() {
1192
1222
  function getGoogleKeyFromEnv() {
1193
1223
  return getKeyFromEnv("GOOGLE_API_KEY");
1194
1224
  }
1225
+ function getOpenRouterKey() {
1226
+ return getOpenRouterKeyFromEnv() || getOpenRouterKeyFromRc();
1227
+ }
1228
+ function getOpenRouterKeyFromRc() {
1229
+ return getKeyFromRc("llm.openrouterApiKey");
1230
+ }
1231
+ function getOpenRouterKeyFromEnv() {
1232
+ return getKeyFromEnv("OPENROUTER_API_KEY");
1233
+ }
1195
1234
 
1196
1235
  // src/lib/lcp/api/index.ts
1197
1236
 
@@ -1217,6 +1256,22 @@ var providerDetails = {
1217
1256
  apiKeyConfigKey: "llm.googleApiKey",
1218
1257
  getKeyLink: "https://ai.google.dev/",
1219
1258
  docsLink: "https://ai.google.dev/gemini-api/docs/troubleshooting"
1259
+ },
1260
+ openrouter: {
1261
+ name: "OpenRouter",
1262
+ apiKeyEnvVar: "OPENROUTER_API_KEY",
1263
+ apiKeyConfigKey: "llm.openrouterApiKey",
1264
+ getKeyLink: "https://openrouter.ai",
1265
+ docsLink: "https://openrouter.ai/docs"
1266
+ },
1267
+ ollama: {
1268
+ name: "Ollama",
1269
+ apiKeyEnvVar: void 0,
1270
+ // Ollama doesn't require an API key
1271
+ apiKeyConfigKey: void 0,
1272
+ // Ollama doesn't require an API key
1273
+ getKeyLink: "https://ollama.com/download",
1274
+ docsLink: "https://github.com/ollama/ollama/tree/main/docs"
1220
1275
  }
1221
1276
  };
1222
1277
 
@@ -1303,59 +1358,118 @@ var LCPAPI = class {
1303
1358
  };
1304
1359
  return dictionary;
1305
1360
  }
1306
- static async _translateChunk(models, sourceDictionary, sourceLocale, targetLocale) {
1307
- const { provider, model } = getLocaleModel(
1308
- models,
1309
- sourceLocale,
1310
- targetLocale
1311
- );
1312
- if (!provider || !model) {
1361
+ static _createLingoDotDevEngine() {
1362
+ if (isRunningInCIOrDocker()) {
1363
+ const apiKeyFromEnv = getLingoDotDevKeyFromEnv();
1364
+ if (!apiKeyFromEnv) {
1365
+ this._failMissingLLMKeyCi("lingo.dev");
1366
+ }
1367
+ }
1368
+ const apiKey = getLingoDotDevKey();
1369
+ if (!apiKey) {
1313
1370
  throw new Error(
1314
- `\u26A0\uFE0F Locale "${targetLocale}" is not configured. Add provider and model for this locale to your config, e.g., "groq:llama3-8b-8192".`
1371
+ "\u26A0\uFE0F Lingo.dev API key not found. Please set LINGODOTDEV_API_KEY environment variable or configure it user-wide."
1315
1372
  );
1316
1373
  }
1317
- try {
1318
- const aiModel = this._createAiModel(provider, model, targetLocale);
1319
- console.log(
1320
- `\u2728 Using model "${model}" from "${provider}" to translate from "${sourceLocale}" to "${targetLocale}"`
1321
- );
1322
- const response = await _ai.generateText.call(void 0, {
1323
- model: aiModel,
1324
- messages: [
1374
+ console.log(`Creating Lingo.dev client`);
1375
+ return new (0, __sdk.LingoDotDevEngine)({
1376
+ apiKey
1377
+ });
1378
+ }
1379
+ static async _translateChunk(models, sourceDictionary, sourceLocale, targetLocale) {
1380
+ if (models === "lingo.dev") {
1381
+ try {
1382
+ const lingoDotDevEngine = this._createLingoDotDevEngine();
1383
+ console.log(
1384
+ `\u2728 Using Lingo.dev Engine to localize from "${sourceLocale}" to "${targetLocale}"`
1385
+ );
1386
+ const result = await lingoDotDevEngine.localizeObject(
1387
+ sourceDictionary,
1325
1388
  {
1326
- role: "system",
1327
- content: prompt_default({ sourceLocale, targetLocale })
1328
- },
1329
- ...shots_default.flatMap((shotsTuple) => [
1389
+ sourceLocale,
1390
+ targetLocale
1391
+ }
1392
+ );
1393
+ return result;
1394
+ } catch (error) {
1395
+ this._failLLMFailureLocal(
1396
+ "lingo.dev",
1397
+ targetLocale,
1398
+ error instanceof Error ? error.message : "Unknown error"
1399
+ );
1400
+ throw error;
1401
+ }
1402
+ } else {
1403
+ const { provider, model } = getLocaleModel(
1404
+ models,
1405
+ sourceLocale,
1406
+ targetLocale
1407
+ );
1408
+ if (!provider || !model) {
1409
+ throw new Error(
1410
+ _dedent2.default`
1411
+ 🚫 Lingo.dev Localization Engine Not Configured!
1412
+
1413
+ The "models" parameter is missing or incomplete in your Lingo.dev configuration.
1414
+
1415
+ 👉 To fix this, set the "models" parameter to either:
1416
+ • "lingo.dev" (for the default engine)
1417
+ • a map of locale-to-model, e.g. { "models": { "en:es": "openai:gpt-3.5-turbo" } }
1418
+
1419
+ Example:
1420
+ {
1421
+ // ...
1422
+ "models": "lingo.dev"
1423
+ }
1424
+
1425
+ For more details, see: https://lingo.dev/compiler
1426
+ To get help, join our Discord: https://lingo.dev/go/discord
1427
+ `
1428
+ );
1429
+ }
1430
+ try {
1431
+ const aiModel = this._createAiModel(provider, model, targetLocale);
1432
+ console.log(
1433
+ `\u2139\uFE0F Using raw LLM API ("${provider}":"${model}") to translate from "${sourceLocale}" to "${targetLocale}"`
1434
+ );
1435
+ const response = await _ai.generateText.call(void 0, {
1436
+ model: aiModel,
1437
+ messages: [
1330
1438
  {
1331
- role: "user",
1332
- content: obj2xml(shotsTuple[0])
1439
+ role: "system",
1440
+ content: prompt_default({ sourceLocale, targetLocale })
1333
1441
  },
1442
+ ...shots_default.flatMap((shotsTuple) => [
1443
+ {
1444
+ role: "user",
1445
+ content: obj2xml(shotsTuple[0])
1446
+ },
1447
+ {
1448
+ role: "assistant",
1449
+ content: obj2xml(shotsTuple[1])
1450
+ }
1451
+ ]),
1334
1452
  {
1335
- role: "assistant",
1336
- content: obj2xml(shotsTuple[1])
1453
+ role: "user",
1454
+ content: obj2xml(sourceDictionary)
1337
1455
  }
1338
- ]),
1339
- {
1340
- role: "user",
1341
- content: obj2xml(sourceDictionary)
1342
- }
1343
- ]
1344
- });
1345
- console.log("Response text received for", targetLocale);
1346
- let responseText = response.text;
1347
- responseText = responseText.substring(
1348
- responseText.indexOf("<"),
1349
- responseText.lastIndexOf(">") + 1
1350
- );
1351
- return xml2obj(responseText);
1352
- } catch (error) {
1353
- this._failLLMFailureLocal(
1354
- provider,
1355
- targetLocale,
1356
- error instanceof Error ? error.message : "Unknown error"
1357
- );
1358
- throw error;
1456
+ ]
1457
+ });
1458
+ console.log("Response text received for", targetLocale);
1459
+ let responseText = response.text;
1460
+ responseText = responseText.substring(
1461
+ responseText.indexOf("<"),
1462
+ responseText.lastIndexOf(">") + 1
1463
+ );
1464
+ return xml2obj(responseText);
1465
+ } catch (error) {
1466
+ this._failLLMFailureLocal(
1467
+ provider,
1468
+ targetLocale,
1469
+ error instanceof Error ? error.message : "Unknown error"
1470
+ );
1471
+ throw error;
1472
+ }
1359
1473
  }
1360
1474
  }
1361
1475
  /**
@@ -1369,7 +1483,7 @@ var LCPAPI = class {
1369
1483
  */
1370
1484
  static _createAiModel(providerId, modelId, targetLocale) {
1371
1485
  switch (providerId) {
1372
- case "groq":
1486
+ case "groq": {
1373
1487
  if (isRunningInCIOrDocker()) {
1374
1488
  const groqFromEnv = getGroqKeyFromEnv();
1375
1489
  if (!groqFromEnv) {
@@ -1386,7 +1500,8 @@ var LCPAPI = class {
1386
1500
  `Creating Groq client for ${targetLocale} using model ${modelId}`
1387
1501
  );
1388
1502
  return _groq.createGroq.call(void 0, { apiKey: groqKey })(modelId);
1389
- case "google":
1503
+ }
1504
+ case "google": {
1390
1505
  if (isRunningInCIOrDocker()) {
1391
1506
  const googleFromEnv = getGoogleKeyFromEnv();
1392
1507
  if (!googleFromEnv) {
@@ -1403,10 +1518,38 @@ var LCPAPI = class {
1403
1518
  `Creating Google Generative AI client for ${targetLocale} using model ${modelId}`
1404
1519
  );
1405
1520
  return _google.createGoogleGenerativeAI.call(void 0, { apiKey: googleKey })(modelId);
1406
- default:
1521
+ }
1522
+ case "openrouter": {
1523
+ if (isRunningInCIOrDocker()) {
1524
+ const openRouterFromEnv = getOpenRouterKeyFromEnv();
1525
+ if (!openRouterFromEnv) {
1526
+ this._failMissingLLMKeyCi(providerId);
1527
+ }
1528
+ }
1529
+ const openRouterKey = getOpenRouterKey();
1530
+ if (!openRouterKey) {
1531
+ throw new Error(
1532
+ "\u26A0\uFE0F OpenRouter API key not found. Please set OPENROUTER_API_KEY environment variable or configure it user-wide."
1533
+ );
1534
+ }
1535
+ console.log(
1536
+ `Creating OpenRouter client for ${targetLocale} using model ${modelId}`
1537
+ );
1538
+ return _aisdkprovider.createOpenRouter.call(void 0, {
1539
+ apiKey: openRouterKey
1540
+ })(modelId);
1541
+ }
1542
+ case "ollama": {
1543
+ console.log(
1544
+ `Creating Ollama client for ${targetLocale} using model ${modelId} at default Ollama address`
1545
+ );
1546
+ return _ollamaaiprovider.createOllama.call(void 0, )(modelId);
1547
+ }
1548
+ default: {
1407
1549
  throw new Error(
1408
1550
  `\u26A0\uFE0F Provider "${providerId}" for locale "${targetLocale}" is not supported. Only "groq" and "google" providers are supported at the moment.`
1409
1551
  );
1552
+ }
1410
1553
  }
1411
1554
  }
1412
1555
  /**
@@ -1495,7 +1638,7 @@ var LCPAPI = class {
1495
1638
  This error comes from the ${details.name} API, please check their documentation for more details: ${details.docsLink}
1496
1639
 
1497
1640
  ⭐️ Also:
1498
- 1. Did you set ${details.apiKeyEnvVar} environment variable correctly?
1641
+ 1. Did you set ${details.apiKeyEnvVar ? `${details.apiKeyEnvVar}` : "the provider API key"} environment variable correctly ${!details.apiKeyEnvVar ? "(if required)" : ""}?
1499
1642
  2. Did you reach any limits of your ${details.name} account?
1500
1643
  3. If you have questions, feature requests, or would like to contribute, join our Discord: https://lingo.dev/go/discord
1501
1644
 
@@ -1509,31 +1652,39 @@ var LCPAPI = class {
1509
1652
 
1510
1653
  // src/lib/lcp/server.ts
1511
1654
  var LCPServer = (_class = class {
1512
- static __initStatic() {this.isLoading = false}
1655
+ static __initStatic() {this.dictionariesCache = null}
1656
+ static __initStatic2() {this.inFlightPromise = null}
1513
1657
  static async loadDictionaries(params) {
1514
- while (this.isLoading) {
1515
- await new Promise(function(resolve3) {
1516
- setTimeout(resolve3, 500);
1517
- });
1658
+ if (this.dictionariesCache) {
1659
+ return this.dictionariesCache;
1518
1660
  }
1519
- this.isLoading = true;
1520
- const targetLocales = _lodash2.default.uniq([
1521
- ...params.targetLocales,
1522
- params.sourceLocale
1523
- ]);
1524
- const dictionaries = await Promise.all(
1525
- targetLocales.map(
1526
- (targetLocale) => this.loadDictionaryForLocale({ ...params, targetLocale })
1527
- )
1528
- );
1529
- const result = _lodash2.default.fromPairs(
1530
- targetLocales.map((targetLocale, index) => [
1531
- targetLocale,
1532
- dictionaries[index]
1533
- ])
1534
- );
1535
- this.isLoading = false;
1536
- return result;
1661
+ if (this.inFlightPromise) {
1662
+ return this.inFlightPromise;
1663
+ }
1664
+ this.inFlightPromise = (async () => {
1665
+ try {
1666
+ const targetLocales = _lodash2.default.uniq([
1667
+ ...params.targetLocales,
1668
+ params.sourceLocale
1669
+ ]);
1670
+ const dictionaries = await Promise.all(
1671
+ targetLocales.map(
1672
+ (targetLocale) => this.loadDictionaryForLocale({ ...params, targetLocale })
1673
+ )
1674
+ );
1675
+ const result = _lodash2.default.fromPairs(
1676
+ targetLocales.map((targetLocale, index) => [
1677
+ targetLocale,
1678
+ dictionaries[index]
1679
+ ])
1680
+ );
1681
+ this.dictionariesCache = result;
1682
+ return result;
1683
+ } finally {
1684
+ this.inFlightPromise = null;
1685
+ }
1686
+ })();
1687
+ return this.inFlightPromise;
1537
1688
  }
1538
1689
  static async loadDictionaryForLocale(params) {
1539
1690
  const sourceDictionary = this._extractSourceDictionary(
@@ -1698,14 +1849,14 @@ var LCPServer = (_class = class {
1698
1849
  const sourceFile = _lodash2.default.get(sourceDictionary.files, fileName);
1699
1850
  const targetFile = _lodash2.default.get(targetDictionary.files, fileName);
1700
1851
  const entries = removeEmptyEntries ? _lodash2.default.pickBy(
1701
- _optionalChain([sourceFile, 'optionalAccess', _41 => _41.entries]) || {},
1702
- (value) => _optionalChain([String, 'call', _42 => _42(value || ""), 'optionalAccess', _43 => _43.trim, 'optionalCall', _44 => _44(), 'optionalAccess', _45 => _45.length]) > 0
1703
- ) : _optionalChain([sourceFile, 'optionalAccess', _46 => _46.entries]) || {};
1852
+ _optionalChain([sourceFile, 'optionalAccess', _42 => _42.entries]) || {},
1853
+ (value) => _optionalChain([String, 'call', _43 => _43(value || ""), 'optionalAccess', _44 => _44.trim, 'optionalCall', _45 => _45(), 'optionalAccess', _46 => _46.length]) > 0
1854
+ ) : _optionalChain([sourceFile, 'optionalAccess', _47 => _47.entries]) || {};
1704
1855
  return [
1705
1856
  fileName,
1706
1857
  {
1707
1858
  ...targetFile,
1708
- entries: _lodash2.default.merge(_optionalChain([targetFile, 'optionalAccess', _47 => _47.entries]) || {}, entries)
1859
+ entries: _lodash2.default.merge({}, _optionalChain([targetFile, 'optionalAccess', _48 => _48.entries]) || {}, entries)
1709
1860
  }
1710
1861
  ];
1711
1862
  }).fromPairs().value();
@@ -1722,7 +1873,7 @@ var LCPServer = (_class = class {
1722
1873
  0
1723
1874
  );
1724
1875
  }
1725
- }, _class.__initStatic(), _class);
1876
+ }, _class.__initStatic(), _class.__initStatic2(), _class);
1726
1877
 
1727
1878
  // src/utils/invokations.ts
1728
1879
 
@@ -1731,7 +1882,7 @@ function findInvokations(ast, params) {
1731
1882
  const result = [];
1732
1883
  _traverse2.default.call(void 0, ast, {
1733
1884
  ImportDeclaration(path7) {
1734
- if (path7.node.source.value !== params.moduleName) return;
1885
+ if (!params.moduleName.includes(path7.node.source.value)) return;
1735
1886
  const importNames = /* @__PURE__ */ new Map();
1736
1887
  const specifiers = path7.node.specifiers;
1737
1888
  specifiers.forEach((specifier) => {
@@ -1805,7 +1956,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1805
1956
  return payload;
1806
1957
  }
1807
1958
  const invokations = findInvokations(payload.ast, {
1808
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
1959
+ moduleName: ModuleId.ReactRSC,
1809
1960
  functionName: "loadDictionary"
1810
1961
  });
1811
1962
  const allLocales = Array.from(
@@ -1813,7 +1964,7 @@ var rscDictionaryLoaderMutation = createCodeMutation((payload) => {
1813
1964
  );
1814
1965
  for (const invokation of invokations) {
1815
1966
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
1816
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */,
1967
+ moduleName: ModuleId.ReactRSC,
1817
1968
  exportedName: "loadDictionary_internal"
1818
1969
  });
1819
1970
  if (t13.isIdentifier(invokation.callee)) {
@@ -1839,7 +1990,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1839
1990
  return payload;
1840
1991
  }
1841
1992
  const invokations = findInvokations(payload.ast, {
1842
- moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
1993
+ moduleName: ModuleId.ReactRouter,
1843
1994
  functionName: "loadDictionary"
1844
1995
  });
1845
1996
  const allLocales = Array.from(
@@ -1847,7 +1998,7 @@ var reactRouterDictionaryLoaderMutation = createCodeMutation(
1847
1998
  );
1848
1999
  for (const invokation of invokations) {
1849
2000
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
1850
- moduleName: "lingo.dev/react/react-router" /* ReactRouter */,
2001
+ moduleName: ModuleId.ReactRouter,
1851
2002
  exportedName: "loadDictionary_internal"
1852
2003
  });
1853
2004
  if (t14.isIdentifier(invokation.callee)) {
@@ -1889,7 +2040,7 @@ function jsxFragmentMutation(payload) {
1889
2040
  if (!fragmentImportName) {
1890
2041
  const result = getOrCreateImport(ast, {
1891
2042
  exportedName: "Fragment",
1892
- moduleName: "react"
2043
+ moduleName: ["react"]
1893
2044
  });
1894
2045
  fragmentImportName = result.importedName;
1895
2046
  }
@@ -1911,9 +2062,9 @@ function jsxFragmentMutation(payload) {
1911
2062
  var jsxHtmlLangMutation = createCodeMutation((payload) => {
1912
2063
  _traverse2.default.call(void 0, payload.ast, {
1913
2064
  JSXElement: (path7) => {
1914
- if (_optionalChain([getJsxElementName, 'call', _48 => _48(path7), 'optionalAccess', _49 => _49.toLowerCase, 'call', _50 => _50()]) === "html") {
2065
+ if (_optionalChain([getJsxElementName, 'call', _49 => _49(path7), 'optionalAccess', _50 => _50.toLowerCase, 'call', _51 => _51()]) === "html") {
1915
2066
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
1916
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
2067
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
1917
2068
  const lingoHtmlComponentImport = getOrCreateImport(payload.ast, {
1918
2069
  moduleName: packagePath,
1919
2070
  exportedName: "LingoHtmlComponent"
@@ -2146,7 +2297,7 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2146
2297
  const mode = getModuleExecutionMode(payload.ast, payload.params.rsc);
2147
2298
  const jsxAttributeScopes = collectJsxAttributeScopes(payload.ast);
2148
2299
  for (const [jsxScope, attributes] of jsxAttributeScopes) {
2149
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
2300
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
2150
2301
  const lingoComponentImport = getOrCreateImport(payload.ast, {
2151
2302
  moduleName: packagePath,
2152
2303
  exportedName: "LingoAttributeComponent"
@@ -2192,7 +2343,7 @@ var lingoJsxAttributeScopeInjectMutation = createCodeMutation(
2192
2343
  if (mode === "server") {
2193
2344
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
2194
2345
  exportedName: "loadDictionary",
2195
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2346
+ moduleName: ModuleId.ReactRSC
2196
2347
  });
2197
2348
  jsxScope.node.openingElement.attributes.push(
2198
2349
  t18.jsxAttribute(
@@ -2332,7 +2483,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2332
2483
  if (skip) {
2333
2484
  continue;
2334
2485
  }
2335
- const packagePath = mode === "client" ? "lingo.dev/react/client" /* ReactClient */ : "lingo.dev/react/rsc" /* ReactRSC */;
2486
+ const packagePath = mode === "client" ? ModuleId.ReactClient : ModuleId.ReactRSC;
2336
2487
  const lingoComponentImport = getOrCreateImport(payload.ast, {
2337
2488
  moduleName: packagePath,
2338
2489
  exportedName: "LingoComponent"
@@ -2395,7 +2546,7 @@ var lingoJsxScopeInjectMutation = createCodeMutation((payload) => {
2395
2546
  if (mode === "server") {
2396
2547
  const loadDictionaryImport = getOrCreateImport(payload.ast, {
2397
2548
  exportedName: "loadDictionary",
2398
- moduleName: "lingo.dev/react/rsc" /* ReactRSC */
2549
+ moduleName: ModuleId.ReactRSC
2399
2550
  });
2400
2551
  originalAttributes.push(
2401
2552
  t22.jsxAttribute(
@@ -2460,7 +2611,7 @@ var jsxRemoveAttributesMutation = createCodeMutation(
2460
2611
 
2461
2612
  var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2462
2613
  const invokations = findInvokations(payload.ast, {
2463
- moduleName: "lingo.dev/react/client" /* ReactClient */,
2614
+ moduleName: ModuleId.ReactClient,
2464
2615
  functionName: "loadDictionary"
2465
2616
  });
2466
2617
  const allLocales = Array.from(
@@ -2468,7 +2619,7 @@ var clientDictionaryLoaderMutation = createCodeMutation((payload) => {
2468
2619
  );
2469
2620
  for (const invokation of invokations) {
2470
2621
  const internalDictionaryLoader = getOrCreateImport(payload.ast, {
2471
- moduleName: "lingo.dev/react/client" /* ReactClient */,
2622
+ moduleName: ModuleId.ReactClient,
2472
2623
  exportedName: "loadDictionary_internal"
2473
2624
  });
2474
2625
  if (t24.isIdentifier(invokation.callee)) {
@@ -2494,6 +2645,10 @@ var keyCheckers = {
2494
2645
  google: {
2495
2646
  checkEnv: getGoogleKeyFromEnv,
2496
2647
  checkRc: getGoogleKeyFromRc
2648
+ },
2649
+ "lingo.dev": {
2650
+ checkEnv: getLingoDotDevKeyFromEnv,
2651
+ checkRc: getLingoDotDevKeyFromRc
2497
2652
  }
2498
2653
  };
2499
2654
  var unplugin = _unplugin.createUnplugin.call(void 0,
@@ -2501,26 +2656,31 @@ var unplugin = _unplugin.createUnplugin.call(void 0,
2501
2656
  console.log("\u2139\uFE0F Starting Lingo.dev compiler...");
2502
2657
  const params = _lodash2.default.defaults(_params, defaultParams);
2503
2658
  if (!isRunningInCIOrDocker()) {
2504
- validateLLMKeyDetails(params.models);
2505
- }
2506
- const invalidLocales = getInvalidLocales(
2507
- params.models,
2508
- params.sourceLocale,
2509
- params.targetLocales
2510
- );
2511
- if (invalidLocales.length > 0) {
2512
- console.log(_dedent2.default`
2513
- \n
2514
- ⚠️ Lingo.dev Localization Compiler requires LLM model setup for the following locales: ${invalidLocales.join(", ")}.
2515
-
2516
- ⭐️ Next steps:
2517
- 1. Refer to documentation for help: https://docs.lingo.dev/
2518
- 2. If you want to use a different LLM, raise an issue in our open-source repo: https://lingo.dev/go/gh
2519
- 3. If you have questions, feature requests, or would like to contribute, join our Discord: https://lingo.dev/go/discord
2520
-
2521
-
2522
- `);
2523
- process.exit(1);
2659
+ if (params.models === "lingo.dev") {
2660
+ validateLLMKeyDetails(["lingo.dev"]);
2661
+ } else {
2662
+ const configuredProviders = getConfiguredProviders(params.models);
2663
+ validateLLMKeyDetails(configuredProviders);
2664
+ const invalidLocales = getInvalidLocales(
2665
+ params.models,
2666
+ params.sourceLocale,
2667
+ params.targetLocales
2668
+ );
2669
+ if (invalidLocales.length > 0) {
2670
+ console.log(_dedent2.default`
2671
+ \n
2672
+ ⚠️ Lingo.dev Localization Compiler requires LLM model setup for the following locales: ${invalidLocales.join(", ")}.
2673
+
2674
+ ⭐️ Next steps:
2675
+ 1. Refer to documentation for help: https://docs.lingo.dev/
2676
+ 2. If you want to use a different LLM, raise an issue in our open-source repo: https://lingo.dev/go/gh
2677
+ 3. If you have questions, feature requests, or would like to contribute, join our Discord: https://lingo.dev/go/discord
2678
+
2679
+
2680
+ `);
2681
+ process.exit(1);
2682
+ }
2683
+ }
2524
2684
  }
2525
2685
  LCPCache.ensureDictionaryFile({
2526
2686
  sourceRoot: params.sourceRoot,
@@ -2548,6 +2708,7 @@ var unplugin = _unplugin.createUnplugin.call(void 0,
2548
2708
  lingoDir: params.lingoDir
2549
2709
  });
2550
2710
  const dictionary = dictionaries[moduleInfo.params.locale];
2711
+ console.log(JSON.stringify(dictionary, null, 2));
2551
2712
  return {
2552
2713
  code: `export default ${JSON.stringify(dictionary, null, 2)}`
2553
2714
  };
@@ -2616,10 +2777,12 @@ var src_default = {
2616
2777
  return config2;
2617
2778
  }
2618
2779
  };
2619
- function validateLLMKeyDetails(models) {
2620
- const configuredProviders = _lodash2.default.chain(Object.values(models)).map((modelString) => modelString.split(":")[0]).filter(Boolean).uniq().filter(
2780
+ function getConfiguredProviders(models) {
2781
+ return _lodash2.default.chain(Object.values(models)).map((modelString) => modelString.split(":")[0]).filter(Boolean).uniq().filter(
2621
2782
  (providerId) => providerDetails.hasOwnProperty(providerId) && keyCheckers.hasOwnProperty(providerId)
2622
2783
  ).value();
2784
+ }
2785
+ function validateLLMKeyDetails(configuredProviders) {
2623
2786
  if (configuredProviders.length === 0) {
2624
2787
  return;
2625
2788
  }