lingo.dev 0.98.0 → 0.99.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/cli.mjs CHANGED
@@ -30,7 +30,8 @@ function getSettings(explicitApiKey) {
30
30
  openaiApiKey: env.OPENAI_API_KEY || systemFile.llm?.openaiApiKey,
31
31
  anthropicApiKey: env.ANTHROPIC_API_KEY || systemFile.llm?.anthropicApiKey,
32
32
  groqApiKey: env.GROQ_API_KEY || systemFile.llm?.groqApiKey,
33
- googleApiKey: env.GOOGLE_API_KEY || systemFile.llm?.googleApiKey
33
+ googleApiKey: env.GOOGLE_API_KEY || systemFile.llm?.googleApiKey,
34
+ openrouterApiKey: env.OPENROUTER_API_KEY || systemFile.llm?.openrouterApiKey
34
35
  }
35
36
  };
36
37
  }
@@ -59,7 +60,8 @@ var SettingsSchema = Z.object({
59
60
  openaiApiKey: Z.string().optional(),
60
61
  anthropicApiKey: Z.string().optional(),
61
62
  groqApiKey: Z.string().optional(),
62
- googleApiKey: Z.string().optional()
63
+ googleApiKey: Z.string().optional(),
64
+ openrouterApiKey: Z.string().optional()
63
65
  })
64
66
  });
65
67
  var SETTINGS_KEYS = flattenZodObject(
@@ -83,7 +85,8 @@ function _loadEnv() {
83
85
  OPENAI_API_KEY: Z.string().optional(),
84
86
  ANTHROPIC_API_KEY: Z.string().optional(),
85
87
  GROQ_API_KEY: Z.string().optional(),
86
- GOOGLE_API_KEY: Z.string().optional()
88
+ GOOGLE_API_KEY: Z.string().optional(),
89
+ OPENROUTER_API_KEY: Z.string().optional()
87
90
  }).passthrough().parse(process.env);
88
91
  }
89
92
  function _loadSystemFile() {
@@ -100,7 +103,8 @@ function _loadSystemFile() {
100
103
  openaiApiKey: Z.string().optional(),
101
104
  anthropicApiKey: Z.string().optional(),
102
105
  groqApiKey: Z.string().optional(),
103
- googleApiKey: Z.string().optional()
106
+ googleApiKey: Z.string().optional(),
107
+ openrouterApiKey: Z.string().optional()
104
108
  }).optional()
105
109
  }).passthrough().parse(data);
106
110
  }
@@ -163,6 +167,12 @@ function _envVarsInfo() {
163
167
  `\u2139\uFE0F Using GOOGLE_API_KEY env var instead of key from user config`
164
168
  );
165
169
  }
170
+ if (env.OPENROUTER_API_KEY && systemFile.llm?.openrouterApiKey) {
171
+ console.info(
172
+ "\x1B[36m%s\x1B[0m",
173
+ `\u2139\uFE0F Using OPENROUTER_API_KEY env var instead of key from user config`
174
+ );
175
+ }
166
176
  if (env.LINGODOTDEV_API_URL) {
167
177
  console.info(
168
178
  "\x1B[36m%s\x1B[0m",
@@ -4537,6 +4547,8 @@ function countWordsInRecord(payload) {
4537
4547
  import { createOpenAI } from "@ai-sdk/openai";
4538
4548
  import { createAnthropic } from "@ai-sdk/anthropic";
4539
4549
  import { createGoogleGenerativeAI } from "@ai-sdk/google";
4550
+ import { createOpenRouter } from "@openrouter/ai-sdk-provider";
4551
+ import { createOllama } from "ollama-ai-provider";
4540
4552
  function createProcessor(provider, params) {
4541
4553
  if (!provider) {
4542
4554
  const result = createLingoLocalizer(params);
@@ -4549,10 +4561,10 @@ function createProcessor(provider, params) {
4549
4561
  }
4550
4562
  function getPureModelProvider(provider) {
4551
4563
  const createMissingKeyErrorMessage = (providerId, envVar) => dedent4`
4552
- You're trying to use raw ${chalk5.dim(providerId)} API for translation, however, ${chalk5.dim(envVar)} environment variable is not set.
4564
+ You're trying to use raw ${chalk5.dim(providerId)} API for translation. ${envVar ? `However, ${chalk5.dim(envVar)} environment variable is not set.` : "However, that provider is unavailable."}
4553
4565
 
4554
4566
  To fix this issue:
4555
- 1. Set ${chalk5.dim(envVar)} in your environment variables, or
4567
+ 1. ${envVar ? `Set ${chalk5.dim(envVar)} in your environment variables` : "Set the environment variable for your provider (if required)"}, or
4556
4568
  2. Remove the ${chalk5.italic("provider")} node from your i18n.json configuration to switch to ${chalk5.hex(colors.green)("Lingo.dev")}
4557
4569
 
4558
4570
  ${chalk5.hex(colors.blue)("Docs: https://lingo.dev/go/docs")}
@@ -4567,7 +4579,7 @@ function getPureModelProvider(provider) {
4567
4579
  ${chalk5.hex(colors.blue)("Docs: https://lingo.dev/go/docs")}
4568
4580
  `;
4569
4581
  switch (provider?.id) {
4570
- case "openai":
4582
+ case "openai": {
4571
4583
  if (!process.env.OPENAI_API_KEY) {
4572
4584
  throw new Error(
4573
4585
  createMissingKeyErrorMessage("OpenAI", "OPENAI_API_KEY")
@@ -4577,7 +4589,8 @@ function getPureModelProvider(provider) {
4577
4589
  apiKey: process.env.OPENAI_API_KEY,
4578
4590
  baseURL: provider.baseUrl
4579
4591
  })(provider.model);
4580
- case "anthropic":
4592
+ }
4593
+ case "anthropic": {
4581
4594
  if (!process.env.ANTHROPIC_API_KEY) {
4582
4595
  throw new Error(
4583
4596
  createMissingKeyErrorMessage("Anthropic", "ANTHROPIC_API_KEY")
@@ -4586,7 +4599,8 @@ function getPureModelProvider(provider) {
4586
4599
  return createAnthropic({
4587
4600
  apiKey: process.env.ANTHROPIC_API_KEY
4588
4601
  })(provider.model);
4589
- case "google":
4602
+ }
4603
+ case "google": {
4590
4604
  if (!process.env.GOOGLE_API_KEY) {
4591
4605
  throw new Error(
4592
4606
  createMissingKeyErrorMessage("Google", "GOOGLE_API_KEY")
@@ -4595,8 +4609,24 @@ function getPureModelProvider(provider) {
4595
4609
  return createGoogleGenerativeAI({
4596
4610
  apiKey: process.env.GOOGLE_API_KEY
4597
4611
  })(provider.model);
4598
- default:
4612
+ }
4613
+ case "openrouter": {
4614
+ if (!process.env.OPENROUTER_API_KEY) {
4615
+ throw new Error(
4616
+ createMissingKeyErrorMessage("OpenRouter", "OPENROUTER_API_KEY")
4617
+ );
4618
+ }
4619
+ return createOpenRouter({
4620
+ apiKey: process.env.OPENROUTER_API_KEY,
4621
+ baseURL: provider.baseUrl
4622
+ })(provider.model);
4623
+ }
4624
+ case "ollama": {
4625
+ return createOllama()(provider.model);
4626
+ }
4627
+ default: {
4599
4628
  throw new Error(createUnsupportedProviderErrorMessage(provider?.id));
4629
+ }
4600
4630
  }
4601
4631
  }
4602
4632
 
@@ -5692,10 +5722,12 @@ function createLingoDotDevLocalizer(explicitApiKey) {
5692
5722
  import { createAnthropic as createAnthropic2 } from "@ai-sdk/anthropic";
5693
5723
  import { createGoogleGenerativeAI as createGoogleGenerativeAI2 } from "@ai-sdk/google";
5694
5724
  import { createOpenAI as createOpenAI2 } from "@ai-sdk/openai";
5725
+ import { createOpenRouter as createOpenRouter2 } from "@openrouter/ai-sdk-provider";
5695
5726
  import chalk9 from "chalk";
5696
5727
  import dedent6 from "dedent";
5697
5728
  import { generateText as generateText2 } from "ai";
5698
5729
  import { jsonrepair as jsonrepair3 } from "jsonrepair";
5730
+ import { createOllama as createOllama2 } from "ollama-ai-provider";
5699
5731
  function createExplicitLocalizer(provider) {
5700
5732
  switch (provider.id) {
5701
5733
  default:
@@ -5734,27 +5766,42 @@ function createExplicitLocalizer(provider) {
5734
5766
  apiKeyName: "GOOGLE_API_KEY",
5735
5767
  baseUrl: provider.baseUrl
5736
5768
  });
5769
+ case "openrouter":
5770
+ return createAiSdkLocalizer({
5771
+ factory: (params) => createOpenRouter2(params).languageModel(provider.model),
5772
+ id: provider.id,
5773
+ prompt: provider.prompt,
5774
+ apiKeyName: "OPENROUTER_API_KEY",
5775
+ baseUrl: provider.baseUrl
5776
+ });
5777
+ case "ollama":
5778
+ return createAiSdkLocalizer({
5779
+ factory: (_params) => createOllama2().languageModel(provider.model),
5780
+ id: provider.id,
5781
+ prompt: provider.prompt,
5782
+ skipAuth: true
5783
+ });
5737
5784
  }
5738
5785
  }
5739
5786
  function createAiSdkLocalizer(params) {
5740
- const apiKey = process.env[params.apiKeyName];
5741
- if (!apiKey) {
5787
+ const skipAuth = params.skipAuth === true;
5788
+ const apiKey = process.env[params?.apiKeyName ?? ""];
5789
+ if (!skipAuth && !apiKey || !params.apiKeyName) {
5742
5790
  throw new Error(
5743
5791
  dedent6`
5744
- You're trying to use raw ${chalk9.dim(params.id)} API for translation, however, ${chalk9.dim(params.apiKeyName)} environment variable is not set.
5792
+ You're trying to use raw ${chalk9.dim(params.id)} API for translation. ${params.apiKeyName ? `However, ${chalk9.dim(params.apiKeyName)} environment variable is not set.` : "However, that provider is unavailable."}
5745
5793
 
5746
5794
  To fix this issue:
5747
- 1. Set ${chalk9.dim(params.apiKeyName)} in your environment variables, or
5795
+ 1. ${params.apiKeyName ? `Set ${chalk9.dim(params.apiKeyName)} in your environment variables` : "Set the environment variable for your provider (if required)"}, or
5748
5796
  2. Remove the ${chalk9.italic("provider")} node from your i18n.json configuration to switch to ${chalk9.hex(colors.green)("Lingo.dev")}
5749
5797
 
5750
5798
  ${chalk9.hex(colors.blue)("Docs: https://lingo.dev/go/docs")}
5751
5799
  `
5752
5800
  );
5753
5801
  }
5754
- const model = params.factory({
5755
- apiKey,
5756
- baseUrl: params.baseUrl
5757
- });
5802
+ const model = params.factory(
5803
+ skipAuth ? {} : { apiKey, baseUrl: params.baseUrl }
5804
+ );
5758
5805
  return {
5759
5806
  id: params.id,
5760
5807
  checkAuth: async () => {
@@ -7538,7 +7585,7 @@ async function renderHero2() {
7538
7585
  // package.json
7539
7586
  var package_default = {
7540
7587
  name: "lingo.dev",
7541
- version: "0.98.0",
7588
+ version: "0.99.0",
7542
7589
  description: "Lingo.dev CLI",
7543
7590
  private: false,
7544
7591
  publishConfig: {
@@ -7666,6 +7713,7 @@ var package_default = {
7666
7713
  "@lingo.dev/_sdk": "workspace:*",
7667
7714
  "@lingo.dev/_spec": "workspace:*",
7668
7715
  "@modelcontextprotocol/sdk": "^1.5.0",
7716
+ "@openrouter/ai-sdk-provider": "^0.7.1",
7669
7717
  "@paralleldrive/cuid2": "^2.2.2",
7670
7718
  ai: "^4.3.15",
7671
7719
  bitbucket: "^2.12.0",
@@ -7707,6 +7755,7 @@ var package_default = {
7707
7755
  "node-webvtt": "^1.9.4",
7708
7756
  "object-hash": "^3.0.0",
7709
7757
  octokit: "^4.0.2",
7758
+ "ollama-ai-provider": "^1.2.0",
7710
7759
  open: "^10.1.2",
7711
7760
  ora: "^8.1.1",
7712
7761
  "p-limit": "^6.2.0",