Upgrade to AI sdk with codemod (#1000)

This commit is contained in:
Will Chen
2025-08-18 22:21:27 -07:00
committed by GitHub
parent 573642ae5f
commit d535db6251
9 changed files with 168 additions and 335 deletions

View File

@@ -1,7 +1,4 @@
import {
LanguageModelV1,
LanguageModelV1ObjectGenerationMode,
} from "@ai-sdk/provider";
import { LanguageModel } from "ai";
import { OpenAICompatibleChatLanguageModel } from "@ai-sdk/openai-compatible";
import {
FetchFunction,
@@ -9,7 +6,6 @@ import {
withoutTrailingSlash,
} from "@ai-sdk/provider-utils";
import { OpenAICompatibleChatSettings } from "@ai-sdk/openai-compatible";
import log from "electron-log";
import { getExtraProviderOptions } from "./thinking_utils";
import type { UserSettings } from "../../lib/schemas";
@@ -18,7 +14,7 @@ const logger = log.scope("llm_engine_provider");
export type ExampleChatModelId = string & {};
export interface ExampleChatSettings extends OpenAICompatibleChatSettings {
export interface ExampleChatSettings {
files?: { path: string; content: string }[];
}
export interface ExampleProviderSettings {
@@ -56,10 +52,7 @@ export interface DyadEngineProvider {
/**
Creates a model for text generation.
*/
(
modelId: ExampleChatModelId,
settings?: ExampleChatSettings,
): LanguageModelV1;
(modelId: ExampleChatModelId, settings?: ExampleChatSettings): LanguageModel;
/**
Creates a chat model for text generation.
@@ -67,7 +60,7 @@ Creates a chat model for text generation.
chatModel(
modelId: ExampleChatModelId,
settings?: ExampleChatSettings,
): LanguageModelV1;
): LanguageModel;
}
export function createDyadEngine(
@@ -113,13 +106,13 @@ export function createDyadEngine(
settings: ExampleChatSettings = {},
) => {
// Extract files from settings to process them appropriately
const { files, ...restSettings } = settings;
const { files } = settings;
// Create configuration with file handling
const config = {
...getCommonModelConfig(),
defaultObjectGenerationMode:
"tool" as LanguageModelV1ObjectGenerationMode,
// defaultObjectGenerationMode:
// "tool" as LanguageModelV1ObjectGenerationMode,
// Custom fetch implementation that adds files to the request
fetch: (input: RequestInfo | URL, init?: RequestInit) => {
// Use default fetch if no init or body
@@ -181,7 +174,7 @@ export function createDyadEngine(
},
};
return new OpenAICompatibleChatLanguageModel(modelId, restSettings, config);
return new OpenAICompatibleChatLanguageModel(modelId, config);
};
const provider = (