@shop-os/modelkit 0.3.5 → 0.3.7
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 +86 -15
- 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 +86 -15
- 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";
|
|
@@ -6823,6 +6868,7 @@ var openaiImageAdapter = {
|
|
|
6823
6868
|
|
|
6824
6869
|
// src/adapters/prodia.ts
|
|
6825
6870
|
var PRODIA_JOB_URL = "https://inference.prodia.com/v2/job";
|
|
6871
|
+
var FLUX_2_PRO_T2I_JOB = "inference.flux-2.pro.txt2img.v1";
|
|
6826
6872
|
var FLUX_2_PRO_JOB = "inference.flux-2.pro.img2img.v1";
|
|
6827
6873
|
var FLUX_KLEIN_T2I_JOB = "inference.flux-2.klein.txt2img.v1";
|
|
6828
6874
|
var FLUX_KLEIN_I2I_JOB = "inference.flux-2.klein.img2img.v1";
|
|
@@ -6995,7 +7041,7 @@ async function generateProdiaImage(req, ctx) {
|
|
|
6995
7041
|
safety_tolerance: 5
|
|
6996
7042
|
};
|
|
6997
7043
|
if (req.seed !== void 0) config.seed = req.seed;
|
|
6998
|
-
job = { type: FLUX_2_PRO_JOB, config };
|
|
7044
|
+
job = { type: refs.length > 0 ? FLUX_2_PRO_JOB : FLUX_2_PRO_T2I_JOB, config };
|
|
6999
7045
|
inputs = refs;
|
|
7000
7046
|
accept = "image/png";
|
|
7001
7047
|
mime = "image/png";
|
|
@@ -8886,6 +8932,7 @@ function keysFromEnv(env, prefix = "") {
|
|
|
8886
8932
|
|
|
8887
8933
|
// src/text.ts
|
|
8888
8934
|
var import_ai4 = require("ai");
|
|
8935
|
+
var import_zod22 = require("zod");
|
|
8889
8936
|
function mergeTextProviderOptions(catalog, caller) {
|
|
8890
8937
|
const merged = {};
|
|
8891
8938
|
const catalogOptions = catalog.providerOptions ?? {};
|
|
@@ -8924,11 +8971,18 @@ function passthroughTextModel(model) {
|
|
|
8924
8971
|
pricingKind: "token"
|
|
8925
8972
|
};
|
|
8926
8973
|
}
|
|
8927
|
-
|
|
8974
|
+
var perplexityCostSchema = import_zod22.z.object({
|
|
8975
|
+
perplexity: import_zod22.z.object({ cost: import_zod22.z.object({ totalCost: import_zod22.z.number().finite().nonnegative() }) })
|
|
8976
|
+
});
|
|
8977
|
+
function reportedCostUsd(metadata) {
|
|
8978
|
+
const parsed = perplexityCostSchema.safeParse(metadata);
|
|
8979
|
+
return parsed.success ? parsed.data.perplexity.cost.totalCost : void 0;
|
|
8980
|
+
}
|
|
8981
|
+
function textUsageEvent(model, provider, usage2, providerMetadata) {
|
|
8928
8982
|
const inputTokens = usage2.inputTokens ?? 0;
|
|
8929
8983
|
const outputTokens = usage2.outputTokens ?? 0;
|
|
8930
8984
|
const total = usage2.totalTokens ?? inputTokens + outputTokens;
|
|
8931
|
-
|
|
8985
|
+
const event = {
|
|
8932
8986
|
model: model.id,
|
|
8933
8987
|
provider,
|
|
8934
8988
|
modality: "TEXT",
|
|
@@ -8937,6 +8991,9 @@ function textUsageEvent(model, provider, usage2) {
|
|
|
8937
8991
|
inputTokens,
|
|
8938
8992
|
outputTokens
|
|
8939
8993
|
};
|
|
8994
|
+
const cost = reportedCostUsd(providerMetadata);
|
|
8995
|
+
if (cost !== void 0) event.reportedCostUsd = cost;
|
|
8996
|
+
return event;
|
|
8940
8997
|
}
|
|
8941
8998
|
|
|
8942
8999
|
// src/text-steps.ts
|
|
@@ -8963,12 +9020,20 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
|
|
|
8963
9020
|
const grouped = /* @__PURE__ */ new Map();
|
|
8964
9021
|
for (const [index, step] of results.entries()) {
|
|
8965
9022
|
const target = steps.get(index) ?? initial;
|
|
8966
|
-
const event = textUsageEvent(
|
|
9023
|
+
const event = textUsageEvent(
|
|
9024
|
+
target.entry,
|
|
9025
|
+
target.provider,
|
|
9026
|
+
step.usage,
|
|
9027
|
+
step.providerMetadata
|
|
9028
|
+
);
|
|
8967
9029
|
const previous = grouped.get(target.entry.id);
|
|
8968
9030
|
if (previous) {
|
|
8969
9031
|
previous.quantity += event.quantity;
|
|
8970
9032
|
previous.inputTokens = (previous.inputTokens ?? 0) + (event.inputTokens ?? 0);
|
|
8971
9033
|
previous.outputTokens = (previous.outputTokens ?? 0) + (event.outputTokens ?? 0);
|
|
9034
|
+
if (event.reportedCostUsd !== void 0) {
|
|
9035
|
+
previous.reportedCostUsd = (previous.reportedCostUsd ?? 0) + event.reportedCostUsd;
|
|
9036
|
+
}
|
|
8972
9037
|
} else {
|
|
8973
9038
|
grouped.set(target.entry.id, event);
|
|
8974
9039
|
}
|
|
@@ -8980,7 +9045,7 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
|
|
|
8980
9045
|
|
|
8981
9046
|
// src/client.ts
|
|
8982
9047
|
var import_ai5 = require("ai");
|
|
8983
|
-
var
|
|
9048
|
+
var import_zod23 = require("zod");
|
|
8984
9049
|
|
|
8985
9050
|
// src/generated-image.ts
|
|
8986
9051
|
function toGeneratedImage(image) {
|
|
@@ -9062,10 +9127,10 @@ function textAbortOptions(sdk, context) {
|
|
|
9062
9127
|
if (abortSignal) return { abortSignal };
|
|
9063
9128
|
return {};
|
|
9064
9129
|
}
|
|
9065
|
-
var catalogId =
|
|
9066
|
-
var exactSize =
|
|
9067
|
-
var sdkRatio =
|
|
9068
|
-
var sizeTier =
|
|
9130
|
+
var catalogId = import_zod23.z.string();
|
|
9131
|
+
var exactSize = import_zod23.z.templateLiteral([import_zod23.z.number(), "x", import_zod23.z.number()]);
|
|
9132
|
+
var sdkRatio = import_zod23.z.templateLiteral([import_zod23.z.number(), ":", import_zod23.z.number()]);
|
|
9133
|
+
var sizeTier = import_zod23.z.enum(["512", "1K", "2K", "4K"]);
|
|
9069
9134
|
function isCatalogId(model) {
|
|
9070
9135
|
return catalogId.safeParse(model).success;
|
|
9071
9136
|
}
|
|
@@ -9634,7 +9699,9 @@ function createModelKit(config, adapters) {
|
|
|
9634
9699
|
providerOptions: mergeTextProviderOptions(entry, options.providerOptions)
|
|
9635
9700
|
};
|
|
9636
9701
|
const result = await (0, import_ai5.generateObject)(sdkOptions);
|
|
9637
|
-
await emit(
|
|
9702
|
+
await emit(
|
|
9703
|
+
withRowUnit(textUsageEvent(entry, provider, result.usage, result.providerMetadata))
|
|
9704
|
+
);
|
|
9638
9705
|
return result;
|
|
9639
9706
|
},
|
|
9640
9707
|
streamObject(options, call = {}) {
|
|
@@ -9646,7 +9713,11 @@ function createModelKit(config, adapters) {
|
|
|
9646
9713
|
model: languageModel2,
|
|
9647
9714
|
providerOptions: mergeTextProviderOptions(entry, options.providerOptions),
|
|
9648
9715
|
onFinish: async (event) => {
|
|
9649
|
-
await emit(
|
|
9716
|
+
await emit(
|
|
9717
|
+
withRowUnit(
|
|
9718
|
+
textUsageEvent(entry, provider, event.usage, event.providerMetadata)
|
|
9719
|
+
)
|
|
9720
|
+
);
|
|
9650
9721
|
await callerOnFinish?.(event);
|
|
9651
9722
|
}
|
|
9652
9723
|
};
|