Skip to content

Commit e8407e6

Browse files
feat: upgrade to ai sdk 6 (#1559)
* chore: upgrade to ai sdk 5 to resolve security vulns Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * chore: changeset Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * feat: upgrade to zod 4 Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * chore: remove zod-to-json-schema from the codebase Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: use "Z" not "z" Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: use error.issues Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: perform more zod 4 migrations Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: resolve type errors in mcp.ts (used any, might manually verify everything still works fine) Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: remove defaults from optional fields in zod 4 (fixes failing tests) Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * chore: fmt Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * chore: remove unused zod-to-json-schema dep Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: use prefault Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: revert Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: upgrade new deps Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: sort deps Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * fix: revert to zod 3 for docs script Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * chore: upgrade to ai sdk 6 Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> * chore: sync lockfile Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> --------- Signed-off-by: The-Best-Codes <bestcodes.official@gmail.com> Co-authored-by: Max Prilutskiy <5614659+maxprilutskiy@users.noreply.github.com>
1 parent e2d2cef commit e8407e6

21 files changed

Lines changed: 279 additions & 126 deletions

File tree

.changeset/pink-lemons-buy.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@lingo.dev/_compiler": minor
3+
"lingo.dev": minor
4+
---
5+
6+
Upgrade Compiler and CLI to AI SDK v5.

packages/cli/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@
129129
"author": "",
130130
"license": "Apache-2.0",
131131
"dependencies": {
132-
"@ai-sdk/anthropic": "1.2.11",
133-
"@ai-sdk/google": "1.2.19",
134-
"@ai-sdk/mistral": "1.2.8",
135-
"@ai-sdk/openai": "1.3.22",
132+
"@ai-sdk/anthropic": "3.0.9",
133+
"@ai-sdk/google": "3.0.6",
134+
"@ai-sdk/mistral": "3.0.5",
135+
"@ai-sdk/openai": "3.0.7",
136136
"@babel/generator": "7.28.5",
137137
"@babel/parser": "7.28.5",
138138
"@babel/traverse": "7.28.5",
@@ -150,10 +150,10 @@
150150
"@lingo.dev/_spec": "workspace:*",
151151
"@markdoc/markdoc": "0.5.4",
152152
"@modelcontextprotocol/sdk": "1.22.0",
153-
"@openrouter/ai-sdk-provider": "0.7.1",
153+
"@openrouter/ai-sdk-provider": "6.0.0-alpha.1",
154154
"@paralleldrive/cuid2": "2.2.2",
155155
"@types/ejs": "3.1.5",
156-
"ai": "4.3.15",
156+
"ai": "6.0.25",
157157
"bitbucket": "2.12.0",
158158
"chalk": "5.6.2",
159159
"chokidar": "4.0.3",
@@ -200,7 +200,7 @@
200200
"node-webvtt": "1.9.4",
201201
"object-hash": "3.0.0",
202202
"octokit": "4.0.2",
203-
"ollama-ai-provider": "1.2.0",
203+
"ollama-ai-provider-v2": "2.0.0",
204204
"open": "10.2.0",
205205
"ora": "8.1.1",
206206
"p-limit": "6.2.0",
@@ -227,7 +227,7 @@
227227
"xml2js": "0.6.2",
228228
"xpath": "0.0.34",
229229
"yaml": "2.8.1",
230-
"zod": "3.25.76"
230+
"zod": "4.1.12"
231231
},
232232
"devDependencies": {
233233
"@types/babel__generator": "7.27.0",
@@ -258,4 +258,4 @@
258258
"node": ">=18"
259259
},
260260
"packageManager": "pnpm@9.12.3"
261-
}
261+
}

packages/cli/src/cli/cmd/i18n.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ function parseFlags(options: any) {
651651
strict: Z.boolean().optional(),
652652
key: Z.string().optional(),
653653
file: Z.array(Z.string()).optional(),
654-
interactive: Z.boolean().default(false),
655-
debug: Z.boolean().default(false),
654+
interactive: Z.boolean().prefault(false),
655+
debug: Z.boolean().prefault(false),
656656
}).parse(options);
657657
}
658658

packages/cli/src/cli/cmd/lockfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ export default new Command()
6161
});
6262

6363
const flagsSchema = Z.object({
64-
force: Z.boolean().default(false),
64+
force: Z.boolean().prefault(false),
6565
});

packages/cli/src/cli/cmd/mcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export default new Command()
4848
"translate",
4949
"Detect language and translate text with Lingo.dev.",
5050
{
51-
text: Z.string(),
52-
targetLocale: Z.string().regex(/^[a-z]{2}(-[A-Z]{2})?$/),
51+
text: Z.string() as any,
52+
targetLocale: Z.string().regex(/^[a-z]{2}(-[A-Z]{2})?$/) as any,
5353
},
5454
async ({ text, targetLocale }) => {
5555
const sourceLocale = await replexicaEngine.recognizeLocale(text);

packages/cli/src/cli/cmd/run/_types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ export const flagsSchema = z.object({
4545
frozen: z.boolean().optional(),
4646
verbose: z.boolean().optional(),
4747
strict: z.boolean().optional(),
48-
interactive: z.boolean().default(false),
49-
concurrency: z.number().positive().default(10),
50-
debug: z.boolean().default(false),
48+
interactive: z.boolean().prefault(false),
49+
concurrency: z.number().positive().prefault(10),
50+
debug: z.boolean().prefault(false),
5151
sourceLocale: z.string().optional(),
5252
targetLocale: z.array(z.string()).optional(),
53-
watch: z.boolean().default(false),
54-
debounce: z.number().positive().default(5000), // 5 seconds default
53+
watch: z.boolean().prefault(false),
54+
debounce: z.number().positive().prefault(5000), // 5 seconds default
5555
sound: z.boolean().optional(),
5656
pseudo: z.boolean().optional(),
5757
});

packages/cli/src/cli/localizer/explicit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { I18nConfig } from "@lingo.dev/_spec";
77
import chalk from "chalk";
88
import dedent from "dedent";
99
import { ILocalizer, LocalizerData } from "./_types";
10-
import { LanguageModel, Message, generateText } from "ai";
10+
import { LanguageModel, ModelMessage, generateText } from "ai";
1111
import { colors } from "../constants";
1212
import { jsonrepair } from "jsonrepair";
13-
import { createOllama } from "ollama-ai-provider";
13+
import { createOllama } from "ollama-ai-provider-v2";
1414

1515
export default function createExplicitLocalizer(
1616
provider: NonNullable<I18nConfig["provider"]>,
@@ -207,7 +207,7 @@ function createAiSdkLocalizer(params: {
207207
[
208208
{ role: "user", content: JSON.stringify(userShot) },
209209
{ role: "assistant", content: JSON.stringify(assistantShot) },
210-
] as Message[],
210+
] as ModelMessage[],
211211
),
212212
{ role: "user", content: JSON.stringify(payload) },
213213
],

packages/cli/src/cli/processor/basic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { generateText, LanguageModelV1 } from "ai";
1+
import { generateText, LanguageModel } from "ai";
22
import { LocalizerInput, LocalizerProgressFn } from "./_base";
33
import _ from "lodash";
44

@@ -7,7 +7,7 @@ type ModelSettings = {
77
};
88

99
export function createBasicTranslator(
10-
model: LanguageModelV1,
10+
model: LanguageModel,
1111
systemPrompt: string,
1212
settings: ModelSettings = {},
1313
) {

packages/cli/src/cli/processor/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createAnthropic } from "@ai-sdk/anthropic";
1010
import { createGoogleGenerativeAI } from "@ai-sdk/google";
1111
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
1212
import { createMistral } from "@ai-sdk/mistral";
13-
import { createOllama } from "ollama-ai-provider";
13+
import { createOllama } from "ollama-ai-provider-v2";
1414

1515
export default function createProcessor(
1616
provider: I18nConfig["provider"],

packages/cli/src/cli/utils/delta.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from "path";
66
import YAML from "yaml";
77

88
const LockSchema = z.object({
9-
version: z.literal(1).default(1),
9+
version: z.literal(1).prefault(1),
1010
checksums: z
1111
.record(
1212
z.string(), // localizable files' keys
@@ -18,9 +18,9 @@ const LockSchema = z.object({
1818
// checksum of the key's value in the source locale
1919
z.string(),
2020
)
21-
.default({}),
21+
.prefault({}),
2222
)
23-
.default({}),
23+
.prefault({}),
2424
});
2525
export type LockData = z.infer<typeof LockSchema>;
2626

0 commit comments

Comments
 (0)