@shop-os/modelkit 0.2.6 → 0.2.8

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/dist/index.js CHANGED
@@ -2981,10 +2981,12 @@ function toGeneratedImage(image) {
2981
2981
  import { createAnthropic } from "@ai-sdk/anthropic";
2982
2982
  import { createGoogleGenerativeAI } from "@ai-sdk/google";
2983
2983
  import { createOpenAI } from "@ai-sdk/openai";
2984
+ import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
2984
2985
  import { createPerplexity } from "@ai-sdk/perplexity";
2985
2986
  import { createXai } from "@ai-sdk/xai";
2986
2987
  import { createDeepSeek } from "@ai-sdk/deepseek";
2987
2988
  import { createMoonshotAI } from "@ai-sdk/moonshotai";
2989
+ import { extractReasoningMiddleware, wrapLanguageModel } from "ai";
2988
2990
  import { z as z5 } from "zod";
2989
2991
  var TEXT_PROVIDERS = [
2990
2992
  "openai",
@@ -3112,6 +3114,40 @@ function missingKey(ctx, name) {
3112
3114
  retryable: false
3113
3115
  });
3114
3116
  }
3117
+ function minimaxDefaults(params) {
3118
+ return params.responseFormat?.type === "json" ? { reasoning_split: true, thinking: { type: "disabled" } } : { reasoning_split: true };
3119
+ }
3120
+ var JSON_FENCE = /^\s*```(?:json)?\s*\n?([\s\S]*?)\n?\s*```\s*$/;
3121
+ function stripJsonFence(text2) {
3122
+ const match = JSON_FENCE.exec(text2);
3123
+ return match?.[1] ?? text2;
3124
+ }
3125
+ function minimaxMiddleware(providerName) {
3126
+ return {
3127
+ specificationVersion: "v3",
3128
+ transformParams: async ({ params }) => {
3129
+ if (providerName !== "minimax") return params;
3130
+ const existing = params.providerOptions?.[providerName] ?? {};
3131
+ return {
3132
+ ...params,
3133
+ providerOptions: {
3134
+ ...params.providerOptions,
3135
+ [providerName]: { ...minimaxDefaults(params), ...existing }
3136
+ }
3137
+ };
3138
+ },
3139
+ wrapGenerate: async ({ doGenerate, params }) => {
3140
+ const result = await doGenerate();
3141
+ if (providerName !== "minimax" || params.responseFormat?.type !== "json") return result;
3142
+ return {
3143
+ ...result,
3144
+ content: result.content.map(
3145
+ (part) => part.type === "text" ? { ...part, text: stripJsonFence(part.text) } : part
3146
+ )
3147
+ };
3148
+ }
3149
+ };
3150
+ }
3115
3151
  var aiSdkTextAdapter = {
3116
3152
  id: "ai-sdk-text",
3117
3153
  languageModel(ctx) {
@@ -3134,11 +3170,22 @@ var aiSdkTextAdapter = {
3134
3170
  return createDeepSeek(settings)(route2.modelId);
3135
3171
  case "moonshot":
3136
3172
  return createMoonshotAI(settings)(route2.modelId);
3137
- case "openai-compatible":
3138
- return createOpenAI({
3139
- ...settings,
3140
- name: route2.provider
3141
- }).chat(route2.modelId);
3173
+ case "openai-compatible": {
3174
+ const model = createOpenAICompatible({
3175
+ name: route2.provider,
3176
+ apiKey,
3177
+ baseURL: route2.baseURL,
3178
+ fetch: ctx.fetch,
3179
+ ...route2.headers ? { headers: route2.headers } : {}
3180
+ })(route2.modelId);
3181
+ return wrapLanguageModel({
3182
+ model,
3183
+ middleware: [
3184
+ minimaxMiddleware(route2.provider),
3185
+ extractReasoningMiddleware({ tagName: "think" })
3186
+ ]
3187
+ });
3188
+ }
3142
3189
  case "openai":
3143
3190
  return createOpenAI(settings)(route2.modelId);
3144
3191
  }