@shop-os/modelkit 0.3.4 → 0.3.6
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/CHANGELOG.md +19 -0
- package/dist/catalog.cjs +48 -3
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.js +48 -3
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +85 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +85 -14
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, experimental_generateVideo, generateText as generateText$1, LanguageModel, FlexibleSchema, InferSchema, ToolSet, Output, streamText as streamText$1, JSONValue, generateObject as generateObject$1, streamObject as streamObject$1, LanguageModelUsage } from 'ai';
|
|
1
|
+
import { ImageModel, experimental_generateVideo, generateText as generateText$1, LanguageModel, FlexibleSchema, InferSchema, ToolSet, Output, streamText as streamText$1, JSONValue, generateObject as generateObject$1, streamObject as streamObject$1, LanguageModelUsage, ProviderMetadata } from 'ai';
|
|
2
2
|
export * from 'ai';
|
|
3
3
|
export { Warning as AiWarning } from 'ai';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -1302,7 +1302,7 @@ declare function mergeTextProviderOptions(catalog: CatalogModel, caller: AiTextP
|
|
|
1302
1302
|
*/
|
|
1303
1303
|
declare function passthroughTextModel(model: TextModelInstance): CatalogModel;
|
|
1304
1304
|
/** Canonical token usage for a completed text call. Quantity is total tokens. */
|
|
1305
|
-
declare function textUsageEvent(model: CatalogModel, provider: string, usage: LanguageModelUsage): UsageEvent;
|
|
1305
|
+
declare function textUsageEvent(model: CatalogModel, provider: string, usage: LanguageModelUsage, providerMetadata?: ProviderMetadata): UsageEvent;
|
|
1306
1306
|
|
|
1307
1307
|
/** The SDK's streamText option union; `experimental_prepareStep` is a generateText-only alias. */
|
|
1308
1308
|
type StreamTextCallOptions<TOOLS extends ToolSet, OUTPUT extends Output.Output = Output.Output<string, string, never>> = ModelkitStreamTextOptions<TOOLS, OUTPUT> & {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, experimental_generateVideo, generateText as generateText$1, LanguageModel, FlexibleSchema, InferSchema, ToolSet, Output, streamText as streamText$1, JSONValue, generateObject as generateObject$1, streamObject as streamObject$1, LanguageModelUsage } from 'ai';
|
|
1
|
+
import { ImageModel, experimental_generateVideo, generateText as generateText$1, LanguageModel, FlexibleSchema, InferSchema, ToolSet, Output, streamText as streamText$1, JSONValue, generateObject as generateObject$1, streamObject as streamObject$1, LanguageModelUsage, ProviderMetadata } from 'ai';
|
|
2
2
|
export * from 'ai';
|
|
3
3
|
export { Warning as AiWarning } from 'ai';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -1302,7 +1302,7 @@ declare function mergeTextProviderOptions(catalog: CatalogModel, caller: AiTextP
|
|
|
1302
1302
|
*/
|
|
1303
1303
|
declare function passthroughTextModel(model: TextModelInstance): CatalogModel;
|
|
1304
1304
|
/** Canonical token usage for a completed text call. Quantity is total tokens. */
|
|
1305
|
-
declare function textUsageEvent(model: CatalogModel, provider: string, usage: LanguageModelUsage): UsageEvent;
|
|
1305
|
+
declare function textUsageEvent(model: CatalogModel, provider: string, usage: LanguageModelUsage, providerMetadata?: ProviderMetadata): UsageEvent;
|
|
1306
1306
|
|
|
1307
1307
|
/** The SDK's streamText option union; `experimental_prepareStep` is a generateText-only alias. */
|
|
1308
1308
|
type StreamTextCallOptions<TOOLS extends ToolSet, OUTPUT extends Output.Output = Output.Output<string, string, never>> = ModelkitStreamTextOptions<TOOLS, OUTPUT> & {
|
package/dist/index.js
CHANGED
|
@@ -1191,12 +1191,18 @@ var TEXT_MODELS = [
|
|
|
1191
1191
|
contextWindow: 1048576
|
|
1192
1192
|
}
|
|
1193
1193
|
}),
|
|
1194
|
+
// Perplexity stopped serving Sonar Chat Completions on 2026-09-27; @ai-sdk/perplexity 3.1
|
|
1195
|
+
// speaks the Agent API, which rejects the bare `sonar*` ids. Its migration guide maps Sonar
|
|
1196
|
+
// and Sonar Pro to the `fast` preset and Sonar Reasoning Pro to `low`
|
|
1197
|
+
// (docs.perplexity.ai/docs/agent-api/migrate-from-sonar/overview).
|
|
1194
1198
|
text("sonar", "Sonar", "sonar", {
|
|
1199
|
+
lifecycle: "deprecated",
|
|
1200
|
+
replacedBy: "perplexity/sonar",
|
|
1195
1201
|
exposure: [],
|
|
1196
1202
|
display: {
|
|
1197
1203
|
provider: "perplexity",
|
|
1198
1204
|
costTier: 1,
|
|
1199
|
-
description: "Perplexity Sonar
|
|
1205
|
+
description: "Perplexity Sonar on Chat Completions, which Perplexity stopped serving on 2026-09-27; calls now fail."
|
|
1200
1206
|
},
|
|
1201
1207
|
capabilities: {
|
|
1202
1208
|
vision: true,
|
|
@@ -1204,11 +1210,13 @@ var TEXT_MODELS = [
|
|
|
1204
1210
|
}
|
|
1205
1211
|
}),
|
|
1206
1212
|
text("sonar-pro", "Sonar Pro", "sonar-pro", {
|
|
1213
|
+
lifecycle: "deprecated",
|
|
1214
|
+
replacedBy: "perplexity/fast",
|
|
1207
1215
|
exposure: [],
|
|
1208
1216
|
display: {
|
|
1209
1217
|
provider: "perplexity",
|
|
1210
1218
|
costTier: 2,
|
|
1211
|
-
description: "Perplexity Sonar Pro
|
|
1219
|
+
description: "Perplexity Sonar Pro on Chat Completions, which Perplexity stopped serving on 2026-09-27; calls now fail."
|
|
1212
1220
|
},
|
|
1213
1221
|
capabilities: {
|
|
1214
1222
|
vision: true,
|
|
@@ -1216,12 +1224,49 @@ var TEXT_MODELS = [
|
|
|
1216
1224
|
}
|
|
1217
1225
|
}),
|
|
1218
1226
|
text("sonar-reasoning-pro", "Sonar Reasoning Pro", "sonar-reasoning-pro", {
|
|
1227
|
+
lifecycle: "deprecated",
|
|
1228
|
+
replacedBy: "perplexity/fast",
|
|
1219
1229
|
exposure: [],
|
|
1220
1230
|
display: {
|
|
1221
1231
|
provider: "perplexity",
|
|
1222
1232
|
costTier: 2,
|
|
1223
|
-
description: "Perplexity Sonar Reasoning Pro
|
|
1233
|
+
description: "Perplexity Sonar Reasoning Pro on Chat Completions, which Perplexity stopped serving on 2026-09-27; calls now fail."
|
|
1234
|
+
},
|
|
1235
|
+
capabilities: {
|
|
1236
|
+
vision: true,
|
|
1237
|
+
contextWindow: 128e3
|
|
1238
|
+
}
|
|
1239
|
+
}),
|
|
1240
|
+
// Sonar as an Agent API model. A bare model searches only when given the web_search
|
|
1241
|
+
// tool, so the row sends it on every call; the answer's sources come from its results.
|
|
1242
|
+
text("perplexity/sonar", "Perplexity Sonar", "perplexity/sonar", {
|
|
1243
|
+
exposure: [],
|
|
1244
|
+
providerOptions: {
|
|
1245
|
+
modelkit: { provider: "perplexity" },
|
|
1246
|
+
perplexity: { tools: [{ type: "web_search" }] }
|
|
1247
|
+
},
|
|
1248
|
+
display: {
|
|
1249
|
+
provider: "perplexity",
|
|
1250
|
+
costTier: 1,
|
|
1251
|
+
description: "Perplexity Sonar on the Agent API with web search, returning answers grounded in cited sources."
|
|
1252
|
+
},
|
|
1253
|
+
// Perplexity publishes no Agent API context window; Sonar's own is 128K.
|
|
1254
|
+
capabilities: {
|
|
1255
|
+
vision: true,
|
|
1256
|
+
contextWindow: 128e3
|
|
1257
|
+
}
|
|
1258
|
+
}),
|
|
1259
|
+
// The Agent API `fast` preset: openai/gpt-5.6-luna with one web search, Perplexity's
|
|
1260
|
+
// recommended replacement for Sonar and Sonar Pro.
|
|
1261
|
+
text("perplexity/fast", "Perplexity Fast", "fast", {
|
|
1262
|
+
exposure: [],
|
|
1263
|
+
providerOptions: { modelkit: { provider: "perplexity" } },
|
|
1264
|
+
display: {
|
|
1265
|
+
provider: "perplexity",
|
|
1266
|
+
costTier: 1,
|
|
1267
|
+
description: "Perplexity Agent API fast preset: a quick web-grounded answer from one search."
|
|
1224
1268
|
},
|
|
1269
|
+
// No published preset window; Sonar's 128K, the size the preset replaces.
|
|
1225
1270
|
capabilities: {
|
|
1226
1271
|
vision: true,
|
|
1227
1272
|
contextWindow: 128e3
|
|
@@ -2923,7 +2968,7 @@ function detectTextProvider(modelId) {
|
|
|
2923
2968
|
if (id.startsWith("claude") || id.includes("anthropic.")) return "anthropic";
|
|
2924
2969
|
if (id.startsWith("gemini") || id.startsWith("gemma")) return "google";
|
|
2925
2970
|
if (id.startsWith("grok")) return "xai";
|
|
2926
|
-
if (id.startsWith("sonar")) return "perplexity";
|
|
2971
|
+
if (id.startsWith("sonar") || id.startsWith("perplexity/")) return "perplexity";
|
|
2927
2972
|
if (id.startsWith("deepseek")) return "deepseek";
|
|
2928
2973
|
if (id.startsWith("kimi") || id.startsWith("moonshot")) return "moonshot";
|
|
2929
2974
|
if (id.startsWith("minimax")) return "minimax";
|
|
@@ -7882,6 +7927,7 @@ function adapterServesType(adapter, type) {
|
|
|
7882
7927
|
}
|
|
7883
7928
|
if (type === "video") return adapter.generateVideo !== void 0;
|
|
7884
7929
|
if (type === "audio") return adapter.generateAudio !== void 0;
|
|
7930
|
+
if (type === "video-tool") return adapter.submitVideoTool !== void 0;
|
|
7885
7931
|
return adapter.languageModel !== void 0;
|
|
7886
7932
|
}
|
|
7887
7933
|
function dataOnlyCapable(row) {
|
|
@@ -8768,6 +8814,7 @@ function keysFromEnv(env, prefix = "") {
|
|
|
8768
8814
|
|
|
8769
8815
|
// src/text.ts
|
|
8770
8816
|
import "ai";
|
|
8817
|
+
import { z as z22 } from "zod";
|
|
8771
8818
|
function mergeTextProviderOptions(catalog, caller) {
|
|
8772
8819
|
const merged = {};
|
|
8773
8820
|
const catalogOptions = catalog.providerOptions ?? {};
|
|
@@ -8806,11 +8853,18 @@ function passthroughTextModel(model) {
|
|
|
8806
8853
|
pricingKind: "token"
|
|
8807
8854
|
};
|
|
8808
8855
|
}
|
|
8809
|
-
|
|
8856
|
+
var perplexityCostSchema = z22.object({
|
|
8857
|
+
perplexity: z22.object({ cost: z22.object({ totalCost: z22.number().finite().nonnegative() }) })
|
|
8858
|
+
});
|
|
8859
|
+
function reportedCostUsd(metadata) {
|
|
8860
|
+
const parsed = perplexityCostSchema.safeParse(metadata);
|
|
8861
|
+
return parsed.success ? parsed.data.perplexity.cost.totalCost : void 0;
|
|
8862
|
+
}
|
|
8863
|
+
function textUsageEvent(model, provider, usage2, providerMetadata) {
|
|
8810
8864
|
const inputTokens = usage2.inputTokens ?? 0;
|
|
8811
8865
|
const outputTokens = usage2.outputTokens ?? 0;
|
|
8812
8866
|
const total = usage2.totalTokens ?? inputTokens + outputTokens;
|
|
8813
|
-
|
|
8867
|
+
const event = {
|
|
8814
8868
|
model: model.id,
|
|
8815
8869
|
provider,
|
|
8816
8870
|
modality: "TEXT",
|
|
@@ -8819,6 +8873,9 @@ function textUsageEvent(model, provider, usage2) {
|
|
|
8819
8873
|
inputTokens,
|
|
8820
8874
|
outputTokens
|
|
8821
8875
|
};
|
|
8876
|
+
const cost = reportedCostUsd(providerMetadata);
|
|
8877
|
+
if (cost !== void 0) event.reportedCostUsd = cost;
|
|
8878
|
+
return event;
|
|
8822
8879
|
}
|
|
8823
8880
|
|
|
8824
8881
|
// src/text-steps.ts
|
|
@@ -8845,12 +8902,20 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
|
|
|
8845
8902
|
const grouped = /* @__PURE__ */ new Map();
|
|
8846
8903
|
for (const [index, step] of results.entries()) {
|
|
8847
8904
|
const target = steps.get(index) ?? initial;
|
|
8848
|
-
const event = textUsageEvent(
|
|
8905
|
+
const event = textUsageEvent(
|
|
8906
|
+
target.entry,
|
|
8907
|
+
target.provider,
|
|
8908
|
+
step.usage,
|
|
8909
|
+
step.providerMetadata
|
|
8910
|
+
);
|
|
8849
8911
|
const previous = grouped.get(target.entry.id);
|
|
8850
8912
|
if (previous) {
|
|
8851
8913
|
previous.quantity += event.quantity;
|
|
8852
8914
|
previous.inputTokens = (previous.inputTokens ?? 0) + (event.inputTokens ?? 0);
|
|
8853
8915
|
previous.outputTokens = (previous.outputTokens ?? 0) + (event.outputTokens ?? 0);
|
|
8916
|
+
if (event.reportedCostUsd !== void 0) {
|
|
8917
|
+
previous.reportedCostUsd = (previous.reportedCostUsd ?? 0) + event.reportedCostUsd;
|
|
8918
|
+
}
|
|
8854
8919
|
} else {
|
|
8855
8920
|
grouped.set(target.entry.id, event);
|
|
8856
8921
|
}
|
|
@@ -8869,7 +8934,7 @@ import {
|
|
|
8869
8934
|
streamObject as aiStreamObject2,
|
|
8870
8935
|
streamText as aiStreamText2
|
|
8871
8936
|
} from "ai";
|
|
8872
|
-
import { z as
|
|
8937
|
+
import { z as z23 } from "zod";
|
|
8873
8938
|
|
|
8874
8939
|
// src/generated-image.ts
|
|
8875
8940
|
function toGeneratedImage(image) {
|
|
@@ -8951,10 +9016,10 @@ function textAbortOptions(sdk, context) {
|
|
|
8951
9016
|
if (abortSignal) return { abortSignal };
|
|
8952
9017
|
return {};
|
|
8953
9018
|
}
|
|
8954
|
-
var catalogId =
|
|
8955
|
-
var exactSize =
|
|
8956
|
-
var sdkRatio =
|
|
8957
|
-
var sizeTier =
|
|
9019
|
+
var catalogId = z23.string();
|
|
9020
|
+
var exactSize = z23.templateLiteral([z23.number(), "x", z23.number()]);
|
|
9021
|
+
var sdkRatio = z23.templateLiteral([z23.number(), ":", z23.number()]);
|
|
9022
|
+
var sizeTier = z23.enum(["512", "1K", "2K", "4K"]);
|
|
8958
9023
|
function isCatalogId(model) {
|
|
8959
9024
|
return catalogId.safeParse(model).success;
|
|
8960
9025
|
}
|
|
@@ -9523,7 +9588,9 @@ function createModelKit(config, adapters) {
|
|
|
9523
9588
|
providerOptions: mergeTextProviderOptions(entry, options.providerOptions)
|
|
9524
9589
|
};
|
|
9525
9590
|
const result = await aiGenerateObject2(sdkOptions);
|
|
9526
|
-
await emit(
|
|
9591
|
+
await emit(
|
|
9592
|
+
withRowUnit(textUsageEvent(entry, provider, result.usage, result.providerMetadata))
|
|
9593
|
+
);
|
|
9527
9594
|
return result;
|
|
9528
9595
|
},
|
|
9529
9596
|
streamObject(options, call = {}) {
|
|
@@ -9535,7 +9602,11 @@ function createModelKit(config, adapters) {
|
|
|
9535
9602
|
model: languageModel2,
|
|
9536
9603
|
providerOptions: mergeTextProviderOptions(entry, options.providerOptions),
|
|
9537
9604
|
onFinish: async (event) => {
|
|
9538
|
-
await emit(
|
|
9605
|
+
await emit(
|
|
9606
|
+
withRowUnit(
|
|
9607
|
+
textUsageEvent(entry, provider, event.usage, event.providerMetadata)
|
|
9608
|
+
)
|
|
9609
|
+
);
|
|
9539
9610
|
await callerOnFinish?.(event);
|
|
9540
9611
|
}
|
|
9541
9612
|
};
|