@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.cjs
CHANGED
|
@@ -1310,12 +1310,18 @@ var TEXT_MODELS = [
|
|
|
1310
1310
|
contextWindow: 1048576
|
|
1311
1311
|
}
|
|
1312
1312
|
}),
|
|
1313
|
+
// Perplexity stopped serving Sonar Chat Completions on 2026-09-27; @ai-sdk/perplexity 3.1
|
|
1314
|
+
// speaks the Agent API, which rejects the bare `sonar*` ids. Its migration guide maps Sonar
|
|
1315
|
+
// and Sonar Pro to the `fast` preset and Sonar Reasoning Pro to `low`
|
|
1316
|
+
// (docs.perplexity.ai/docs/agent-api/migrate-from-sonar/overview).
|
|
1313
1317
|
text("sonar", "Sonar", "sonar", {
|
|
1318
|
+
lifecycle: "deprecated",
|
|
1319
|
+
replacedBy: "perplexity/sonar",
|
|
1314
1320
|
exposure: [],
|
|
1315
1321
|
display: {
|
|
1316
1322
|
provider: "perplexity",
|
|
1317
1323
|
costTier: 1,
|
|
1318
|
-
description: "Perplexity Sonar
|
|
1324
|
+
description: "Perplexity Sonar on Chat Completions, which Perplexity stopped serving on 2026-09-27; calls now fail."
|
|
1319
1325
|
},
|
|
1320
1326
|
capabilities: {
|
|
1321
1327
|
vision: true,
|
|
@@ -1323,11 +1329,13 @@ var TEXT_MODELS = [
|
|
|
1323
1329
|
}
|
|
1324
1330
|
}),
|
|
1325
1331
|
text("sonar-pro", "Sonar Pro", "sonar-pro", {
|
|
1332
|
+
lifecycle: "deprecated",
|
|
1333
|
+
replacedBy: "perplexity/fast",
|
|
1326
1334
|
exposure: [],
|
|
1327
1335
|
display: {
|
|
1328
1336
|
provider: "perplexity",
|
|
1329
1337
|
costTier: 2,
|
|
1330
|
-
description: "Perplexity Sonar Pro
|
|
1338
|
+
description: "Perplexity Sonar Pro on Chat Completions, which Perplexity stopped serving on 2026-09-27; calls now fail."
|
|
1331
1339
|
},
|
|
1332
1340
|
capabilities: {
|
|
1333
1341
|
vision: true,
|
|
@@ -1335,12 +1343,49 @@ var TEXT_MODELS = [
|
|
|
1335
1343
|
}
|
|
1336
1344
|
}),
|
|
1337
1345
|
text("sonar-reasoning-pro", "Sonar Reasoning Pro", "sonar-reasoning-pro", {
|
|
1346
|
+
lifecycle: "deprecated",
|
|
1347
|
+
replacedBy: "perplexity/fast",
|
|
1338
1348
|
exposure: [],
|
|
1339
1349
|
display: {
|
|
1340
1350
|
provider: "perplexity",
|
|
1341
1351
|
costTier: 2,
|
|
1342
|
-
description: "Perplexity Sonar Reasoning Pro
|
|
1352
|
+
description: "Perplexity Sonar Reasoning Pro on Chat Completions, which Perplexity stopped serving on 2026-09-27; calls now fail."
|
|
1353
|
+
},
|
|
1354
|
+
capabilities: {
|
|
1355
|
+
vision: true,
|
|
1356
|
+
contextWindow: 128e3
|
|
1357
|
+
}
|
|
1358
|
+
}),
|
|
1359
|
+
// Sonar as an Agent API model. A bare model searches only when given the web_search
|
|
1360
|
+
// tool, so the row sends it on every call; the answer's sources come from its results.
|
|
1361
|
+
text("perplexity/sonar", "Perplexity Sonar", "perplexity/sonar", {
|
|
1362
|
+
exposure: [],
|
|
1363
|
+
providerOptions: {
|
|
1364
|
+
modelkit: { provider: "perplexity" },
|
|
1365
|
+
perplexity: { tools: [{ type: "web_search" }] }
|
|
1366
|
+
},
|
|
1367
|
+
display: {
|
|
1368
|
+
provider: "perplexity",
|
|
1369
|
+
costTier: 1,
|
|
1370
|
+
description: "Perplexity Sonar on the Agent API with web search, returning answers grounded in cited sources."
|
|
1371
|
+
},
|
|
1372
|
+
// Perplexity publishes no Agent API context window; Sonar's own is 128K.
|
|
1373
|
+
capabilities: {
|
|
1374
|
+
vision: true,
|
|
1375
|
+
contextWindow: 128e3
|
|
1376
|
+
}
|
|
1377
|
+
}),
|
|
1378
|
+
// The Agent API `fast` preset: openai/gpt-5.6-luna with one web search, Perplexity's
|
|
1379
|
+
// recommended replacement for Sonar and Sonar Pro.
|
|
1380
|
+
text("perplexity/fast", "Perplexity Fast", "fast", {
|
|
1381
|
+
exposure: [],
|
|
1382
|
+
providerOptions: { modelkit: { provider: "perplexity" } },
|
|
1383
|
+
display: {
|
|
1384
|
+
provider: "perplexity",
|
|
1385
|
+
costTier: 1,
|
|
1386
|
+
description: "Perplexity Agent API fast preset: a quick web-grounded answer from one search."
|
|
1343
1387
|
},
|
|
1388
|
+
// No published preset window; Sonar's 128K, the size the preset replaces.
|
|
1344
1389
|
capabilities: {
|
|
1345
1390
|
vision: true,
|
|
1346
1391
|
contextWindow: 128e3
|
|
@@ -3042,7 +3087,7 @@ function detectTextProvider(modelId) {
|
|
|
3042
3087
|
if (id.startsWith("claude") || id.includes("anthropic.")) return "anthropic";
|
|
3043
3088
|
if (id.startsWith("gemini") || id.startsWith("gemma")) return "google";
|
|
3044
3089
|
if (id.startsWith("grok")) return "xai";
|
|
3045
|
-
if (id.startsWith("sonar")) return "perplexity";
|
|
3090
|
+
if (id.startsWith("sonar") || id.startsWith("perplexity/")) return "perplexity";
|
|
3046
3091
|
if (id.startsWith("deepseek")) return "deepseek";
|
|
3047
3092
|
if (id.startsWith("kimi") || id.startsWith("moonshot")) return "moonshot";
|
|
3048
3093
|
if (id.startsWith("minimax")) return "minimax";
|
|
@@ -7999,6 +8044,7 @@ function adapterServesType(adapter, type) {
|
|
|
7999
8044
|
}
|
|
8000
8045
|
if (type === "video") return adapter.generateVideo !== void 0;
|
|
8001
8046
|
if (type === "audio") return adapter.generateAudio !== void 0;
|
|
8047
|
+
if (type === "video-tool") return adapter.submitVideoTool !== void 0;
|
|
8002
8048
|
return adapter.languageModel !== void 0;
|
|
8003
8049
|
}
|
|
8004
8050
|
function dataOnlyCapable(row) {
|
|
@@ -8885,6 +8931,7 @@ function keysFromEnv(env, prefix = "") {
|
|
|
8885
8931
|
|
|
8886
8932
|
// src/text.ts
|
|
8887
8933
|
var import_ai4 = require("ai");
|
|
8934
|
+
var import_zod22 = require("zod");
|
|
8888
8935
|
function mergeTextProviderOptions(catalog, caller) {
|
|
8889
8936
|
const merged = {};
|
|
8890
8937
|
const catalogOptions = catalog.providerOptions ?? {};
|
|
@@ -8923,11 +8970,18 @@ function passthroughTextModel(model) {
|
|
|
8923
8970
|
pricingKind: "token"
|
|
8924
8971
|
};
|
|
8925
8972
|
}
|
|
8926
|
-
|
|
8973
|
+
var perplexityCostSchema = import_zod22.z.object({
|
|
8974
|
+
perplexity: import_zod22.z.object({ cost: import_zod22.z.object({ totalCost: import_zod22.z.number().finite().nonnegative() }) })
|
|
8975
|
+
});
|
|
8976
|
+
function reportedCostUsd(metadata) {
|
|
8977
|
+
const parsed = perplexityCostSchema.safeParse(metadata);
|
|
8978
|
+
return parsed.success ? parsed.data.perplexity.cost.totalCost : void 0;
|
|
8979
|
+
}
|
|
8980
|
+
function textUsageEvent(model, provider, usage2, providerMetadata) {
|
|
8927
8981
|
const inputTokens = usage2.inputTokens ?? 0;
|
|
8928
8982
|
const outputTokens = usage2.outputTokens ?? 0;
|
|
8929
8983
|
const total = usage2.totalTokens ?? inputTokens + outputTokens;
|
|
8930
|
-
|
|
8984
|
+
const event = {
|
|
8931
8985
|
model: model.id,
|
|
8932
8986
|
provider,
|
|
8933
8987
|
modality: "TEXT",
|
|
@@ -8936,6 +8990,9 @@ function textUsageEvent(model, provider, usage2) {
|
|
|
8936
8990
|
inputTokens,
|
|
8937
8991
|
outputTokens
|
|
8938
8992
|
};
|
|
8993
|
+
const cost = reportedCostUsd(providerMetadata);
|
|
8994
|
+
if (cost !== void 0) event.reportedCostUsd = cost;
|
|
8995
|
+
return event;
|
|
8939
8996
|
}
|
|
8940
8997
|
|
|
8941
8998
|
// src/text-steps.ts
|
|
@@ -8962,12 +9019,20 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
|
|
|
8962
9019
|
const grouped = /* @__PURE__ */ new Map();
|
|
8963
9020
|
for (const [index, step] of results.entries()) {
|
|
8964
9021
|
const target = steps.get(index) ?? initial;
|
|
8965
|
-
const event = textUsageEvent(
|
|
9022
|
+
const event = textUsageEvent(
|
|
9023
|
+
target.entry,
|
|
9024
|
+
target.provider,
|
|
9025
|
+
step.usage,
|
|
9026
|
+
step.providerMetadata
|
|
9027
|
+
);
|
|
8966
9028
|
const previous = grouped.get(target.entry.id);
|
|
8967
9029
|
if (previous) {
|
|
8968
9030
|
previous.quantity += event.quantity;
|
|
8969
9031
|
previous.inputTokens = (previous.inputTokens ?? 0) + (event.inputTokens ?? 0);
|
|
8970
9032
|
previous.outputTokens = (previous.outputTokens ?? 0) + (event.outputTokens ?? 0);
|
|
9033
|
+
if (event.reportedCostUsd !== void 0) {
|
|
9034
|
+
previous.reportedCostUsd = (previous.reportedCostUsd ?? 0) + event.reportedCostUsd;
|
|
9035
|
+
}
|
|
8971
9036
|
} else {
|
|
8972
9037
|
grouped.set(target.entry.id, event);
|
|
8973
9038
|
}
|
|
@@ -8979,7 +9044,7 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
|
|
|
8979
9044
|
|
|
8980
9045
|
// src/client.ts
|
|
8981
9046
|
var import_ai5 = require("ai");
|
|
8982
|
-
var
|
|
9047
|
+
var import_zod23 = require("zod");
|
|
8983
9048
|
|
|
8984
9049
|
// src/generated-image.ts
|
|
8985
9050
|
function toGeneratedImage(image) {
|
|
@@ -9061,10 +9126,10 @@ function textAbortOptions(sdk, context) {
|
|
|
9061
9126
|
if (abortSignal) return { abortSignal };
|
|
9062
9127
|
return {};
|
|
9063
9128
|
}
|
|
9064
|
-
var catalogId =
|
|
9065
|
-
var exactSize =
|
|
9066
|
-
var sdkRatio =
|
|
9067
|
-
var sizeTier =
|
|
9129
|
+
var catalogId = import_zod23.z.string();
|
|
9130
|
+
var exactSize = import_zod23.z.templateLiteral([import_zod23.z.number(), "x", import_zod23.z.number()]);
|
|
9131
|
+
var sdkRatio = import_zod23.z.templateLiteral([import_zod23.z.number(), ":", import_zod23.z.number()]);
|
|
9132
|
+
var sizeTier = import_zod23.z.enum(["512", "1K", "2K", "4K"]);
|
|
9068
9133
|
function isCatalogId(model) {
|
|
9069
9134
|
return catalogId.safeParse(model).success;
|
|
9070
9135
|
}
|
|
@@ -9633,7 +9698,9 @@ function createModelKit(config, adapters) {
|
|
|
9633
9698
|
providerOptions: mergeTextProviderOptions(entry, options.providerOptions)
|
|
9634
9699
|
};
|
|
9635
9700
|
const result = await (0, import_ai5.generateObject)(sdkOptions);
|
|
9636
|
-
await emit(
|
|
9701
|
+
await emit(
|
|
9702
|
+
withRowUnit(textUsageEvent(entry, provider, result.usage, result.providerMetadata))
|
|
9703
|
+
);
|
|
9637
9704
|
return result;
|
|
9638
9705
|
},
|
|
9639
9706
|
streamObject(options, call = {}) {
|
|
@@ -9645,7 +9712,11 @@ function createModelKit(config, adapters) {
|
|
|
9645
9712
|
model: languageModel2,
|
|
9646
9713
|
providerOptions: mergeTextProviderOptions(entry, options.providerOptions),
|
|
9647
9714
|
onFinish: async (event) => {
|
|
9648
|
-
await emit(
|
|
9715
|
+
await emit(
|
|
9716
|
+
withRowUnit(
|
|
9717
|
+
textUsageEvent(entry, provider, event.usage, event.providerMetadata)
|
|
9718
|
+
)
|
|
9719
|
+
);
|
|
9649
9720
|
await callerOnFinish?.(event);
|
|
9650
9721
|
}
|
|
9651
9722
|
};
|