promptopskit 0.9.0 → 0.9.2
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/README.md +19 -6
- package/dist/{chunk-NS6OTKY2.js → chunk-6ICAKKV3.js} +81 -22
- package/dist/{chunk-NS6OTKY2.js.map → chunk-6ICAKKV3.js.map} +1 -1
- package/dist/{chunk-FJ3D76IV.js → chunk-A2VPKL4X.js} +2 -2
- package/dist/{chunk-SVNQNMMV.js → chunk-CGBEKODU.js} +2 -2
- package/dist/{chunk-Q67E2GGD.js → chunk-DA2NSBIN.js} +2 -2
- package/dist/{chunk-AAQNCAVA.js → chunk-DAJMCV4F.js} +3 -3
- package/dist/{chunk-E2AIIPQC.js → chunk-XSSET4QN.js} +2 -2
- package/dist/{chunk-W6XHGSPJ.js → chunk-YLJGWVZ6.js} +3 -3
- package/dist/index.cjs +80 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -7
- package/dist/providers/anthropic.cjs +80 -21
- package/dist/providers/anthropic.cjs.map +1 -1
- package/dist/providers/anthropic.js +2 -2
- package/dist/providers/gemini.cjs +80 -21
- package/dist/providers/gemini.cjs.map +1 -1
- package/dist/providers/gemini.js +2 -2
- package/dist/providers/llmasaservice.cjs +80 -21
- package/dist/providers/llmasaservice.cjs.map +1 -1
- package/dist/providers/llmasaservice.js +3 -3
- package/dist/providers/openai-responses.cjs +80 -21
- package/dist/providers/openai-responses.cjs.map +1 -1
- package/dist/providers/openai-responses.js +2 -2
- package/dist/providers/openai.cjs +80 -21
- package/dist/providers/openai.cjs.map +1 -1
- package/dist/providers/openai.js +2 -2
- package/dist/providers/openrouter.cjs +80 -21
- package/dist/providers/openrouter.cjs.map +1 -1
- package/dist/providers/openrouter.js +3 -3
- package/package.json +1 -1
- /package/dist/{chunk-FJ3D76IV.js.map → chunk-A2VPKL4X.js.map} +0 -0
- /package/dist/{chunk-SVNQNMMV.js.map → chunk-CGBEKODU.js.map} +0 -0
- /package/dist/{chunk-Q67E2GGD.js.map → chunk-DA2NSBIN.js.map} +0 -0
- /package/dist/{chunk-AAQNCAVA.js.map → chunk-DAJMCV4F.js.map} +0 -0
- /package/dist/{chunk-E2AIIPQC.js.map → chunk-XSSET4QN.js.map} +0 -0
- /package/dist/{chunk-W6XHGSPJ.js.map → chunk-YLJGWVZ6.js.map} +0 -0
package/dist/providers/gemini.js
CHANGED
|
@@ -2462,6 +2462,7 @@ async function applyPromptCompressionForRender(asset, runtime) {
|
|
|
2462
2462
|
aggressiveness: theTokenCompanyConfig?.aggressiveness
|
|
2463
2463
|
});
|
|
2464
2464
|
promptTemplate = result.output;
|
|
2465
|
+
warnings.push(...result.warnings ?? []);
|
|
2465
2466
|
compression.push({
|
|
2466
2467
|
provider: "thetokencompany",
|
|
2467
2468
|
model,
|
|
@@ -2527,39 +2528,97 @@ function reportHeuristicCompressionWarnings2(warnings, compressionWarnings, scop
|
|
|
2527
2528
|
async function compressWithTheTokenCompany(input, options) {
|
|
2528
2529
|
const apiKey = options.apiKey ?? getEnv("THETOKENCOMPANY_API_KEY") ?? getEnv("TTC_API_KEY");
|
|
2529
2530
|
if (!apiKey) {
|
|
2530
|
-
|
|
2531
|
-
|
|
2531
|
+
return createTheTokenCompanyFallback(
|
|
2532
|
+
input,
|
|
2533
|
+
"no API key was provided"
|
|
2532
2534
|
);
|
|
2533
2535
|
}
|
|
2534
2536
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2535
2537
|
if (!fetchImpl) {
|
|
2536
|
-
|
|
2538
|
+
return createTheTokenCompanyFallback(
|
|
2539
|
+
input,
|
|
2540
|
+
"fetch is unavailable in this runtime"
|
|
2541
|
+
);
|
|
2537
2542
|
}
|
|
2538
2543
|
const baseURL = (options.baseURL ?? THETOKENCOMPANY_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
2539
2544
|
const compressionSettings = options.aggressiveness === void 0 ? void 0 : { aggressiveness: options.aggressiveness };
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2545
|
+
let response;
|
|
2546
|
+
try {
|
|
2547
|
+
response = await fetchImpl(`${baseURL}/v1/compress`, {
|
|
2548
|
+
method: "POST",
|
|
2549
|
+
headers: {
|
|
2550
|
+
Authorization: `Bearer ${apiKey}`,
|
|
2551
|
+
"Content-Type": "application/json"
|
|
2552
|
+
},
|
|
2553
|
+
body: JSON.stringify({
|
|
2554
|
+
model: options.model,
|
|
2555
|
+
input,
|
|
2556
|
+
...compressionSettings ? { compression_settings: compressionSettings } : {}
|
|
2557
|
+
})
|
|
2558
|
+
});
|
|
2559
|
+
} catch (error) {
|
|
2560
|
+
return createTheTokenCompanyFallback(
|
|
2548
2561
|
input,
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
}
|
|
2562
|
+
`request failed: ${toErrorMessage(error)}`
|
|
2563
|
+
);
|
|
2564
|
+
}
|
|
2552
2565
|
if (!response.ok) {
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
`
|
|
2566
|
+
return createTheTokenCompanyFallback(
|
|
2567
|
+
input,
|
|
2568
|
+
`service returned HTTP ${response.status}`
|
|
2556
2569
|
);
|
|
2557
2570
|
}
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2571
|
+
let data;
|
|
2572
|
+
try {
|
|
2573
|
+
data = await response.json();
|
|
2574
|
+
} catch (error) {
|
|
2575
|
+
return createTheTokenCompanyFallback(
|
|
2576
|
+
input,
|
|
2577
|
+
`response body was not valid JSON: ${toErrorMessage(error)}`
|
|
2578
|
+
);
|
|
2579
|
+
}
|
|
2580
|
+
const normalized = normalizeTheTokenCompanyCompressResponse(data);
|
|
2581
|
+
if (!normalized) {
|
|
2582
|
+
return createTheTokenCompanyFallback(
|
|
2583
|
+
input,
|
|
2584
|
+
"response payload was invalid"
|
|
2585
|
+
);
|
|
2561
2586
|
}
|
|
2562
|
-
return
|
|
2587
|
+
return normalized;
|
|
2588
|
+
}
|
|
2589
|
+
function createTheTokenCompanyFallback(input, reason) {
|
|
2590
|
+
const tokens = estimateHeuristicTokens(input);
|
|
2591
|
+
return {
|
|
2592
|
+
output: input,
|
|
2593
|
+
output_tokens: tokens,
|
|
2594
|
+
input_tokens: tokens,
|
|
2595
|
+
tokens_saved: 0,
|
|
2596
|
+
compression_ratio: tokens === 0 ? 0 : 1,
|
|
2597
|
+
warnings: [
|
|
2598
|
+
`POK057: TheTokenCompany compression skipped; using uncompressed prompt with zero token savings (${reason}).`
|
|
2599
|
+
]
|
|
2600
|
+
};
|
|
2601
|
+
}
|
|
2602
|
+
function toErrorMessage(error) {
|
|
2603
|
+
return error instanceof Error && error.message ? error.message : "unknown error";
|
|
2604
|
+
}
|
|
2605
|
+
function normalizeTheTokenCompanyCompressResponse(data) {
|
|
2606
|
+
if (typeof data.output !== "string" || typeof data.output_tokens !== "number") {
|
|
2607
|
+
return void 0;
|
|
2608
|
+
}
|
|
2609
|
+
const inputTokens = typeof data.input_tokens === "number" ? data.input_tokens : data.original_input_tokens;
|
|
2610
|
+
if (typeof inputTokens !== "number") {
|
|
2611
|
+
return void 0;
|
|
2612
|
+
}
|
|
2613
|
+
const tokensSaved = typeof data.tokens_saved === "number" ? data.tokens_saved : inputTokens - data.output_tokens;
|
|
2614
|
+
const compressionRatio = typeof data.compression_ratio === "number" ? data.compression_ratio : data.output_tokens === 0 ? 0 : inputTokens / data.output_tokens;
|
|
2615
|
+
return {
|
|
2616
|
+
output: data.output,
|
|
2617
|
+
output_tokens: data.output_tokens,
|
|
2618
|
+
input_tokens: inputTokens,
|
|
2619
|
+
tokens_saved: tokensSaved,
|
|
2620
|
+
compression_ratio: compressionRatio
|
|
2621
|
+
};
|
|
2563
2622
|
}
|
|
2564
2623
|
function getEnv(name) {
|
|
2565
2624
|
if (typeof process === "undefined") {
|