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/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
LLMASASERVICE_SDK_PLACEHOLDER_API_KEY,
|
|
6
6
|
createLLMAsAServiceOpenAIConfig,
|
|
7
7
|
llmasaserviceAdapter
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YLJGWVZ6.js";
|
|
9
9
|
import {
|
|
10
10
|
applyUsageTapEntitlements,
|
|
11
11
|
beginUsageTapCall,
|
|
@@ -24,19 +24,19 @@ import {
|
|
|
24
24
|
} from "./chunk-AGTGIZMR.js";
|
|
25
25
|
import {
|
|
26
26
|
openaiResponsesAdapter
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-XSSET4QN.js";
|
|
28
28
|
import {
|
|
29
29
|
anthropicAdapter
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-DA2NSBIN.js";
|
|
31
31
|
import {
|
|
32
32
|
geminiAdapter
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-A2VPKL4X.js";
|
|
34
34
|
import {
|
|
35
35
|
openrouterAdapter
|
|
36
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-DAJMCV4F.js";
|
|
37
37
|
import {
|
|
38
38
|
openaiAdapter
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-CGBEKODU.js";
|
|
40
40
|
import {
|
|
41
41
|
DEFAULT_PROMPTS_DIR,
|
|
42
42
|
PromptCache,
|
|
@@ -58,7 +58,7 @@ import {
|
|
|
58
58
|
sanitizeContextVariables,
|
|
59
59
|
summarizePromptCompression,
|
|
60
60
|
withPromptResolutionDefaults
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-6ICAKKV3.js";
|
|
62
62
|
import {
|
|
63
63
|
PromptAssetOverridesSchema,
|
|
64
64
|
PromptAssetSchema,
|
|
@@ -2457,6 +2457,7 @@ async function applyPromptCompressionForRender(asset, runtime) {
|
|
|
2457
2457
|
aggressiveness: theTokenCompanyConfig?.aggressiveness
|
|
2458
2458
|
});
|
|
2459
2459
|
promptTemplate = result.output;
|
|
2460
|
+
warnings.push(...result.warnings ?? []);
|
|
2460
2461
|
compression.push({
|
|
2461
2462
|
provider: "thetokencompany",
|
|
2462
2463
|
model,
|
|
@@ -2522,39 +2523,97 @@ function reportHeuristicCompressionWarnings2(warnings, compressionWarnings, scop
|
|
|
2522
2523
|
async function compressWithTheTokenCompany(input, options) {
|
|
2523
2524
|
const apiKey = options.apiKey ?? getEnv("THETOKENCOMPANY_API_KEY") ?? getEnv("TTC_API_KEY");
|
|
2524
2525
|
if (!apiKey) {
|
|
2525
|
-
|
|
2526
|
-
|
|
2526
|
+
return createTheTokenCompanyFallback(
|
|
2527
|
+
input,
|
|
2528
|
+
"no API key was provided"
|
|
2527
2529
|
);
|
|
2528
2530
|
}
|
|
2529
2531
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
2530
2532
|
if (!fetchImpl) {
|
|
2531
|
-
|
|
2533
|
+
return createTheTokenCompanyFallback(
|
|
2534
|
+
input,
|
|
2535
|
+
"fetch is unavailable in this runtime"
|
|
2536
|
+
);
|
|
2532
2537
|
}
|
|
2533
2538
|
const baseURL = (options.baseURL ?? THETOKENCOMPANY_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
2534
2539
|
const compressionSettings = options.aggressiveness === void 0 ? void 0 : { aggressiveness: options.aggressiveness };
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2540
|
+
let response;
|
|
2541
|
+
try {
|
|
2542
|
+
response = await fetchImpl(`${baseURL}/v1/compress`, {
|
|
2543
|
+
method: "POST",
|
|
2544
|
+
headers: {
|
|
2545
|
+
Authorization: `Bearer ${apiKey}`,
|
|
2546
|
+
"Content-Type": "application/json"
|
|
2547
|
+
},
|
|
2548
|
+
body: JSON.stringify({
|
|
2549
|
+
model: options.model,
|
|
2550
|
+
input,
|
|
2551
|
+
...compressionSettings ? { compression_settings: compressionSettings } : {}
|
|
2552
|
+
})
|
|
2553
|
+
});
|
|
2554
|
+
} catch (error) {
|
|
2555
|
+
return createTheTokenCompanyFallback(
|
|
2543
2556
|
input,
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
}
|
|
2557
|
+
`request failed: ${toErrorMessage(error)}`
|
|
2558
|
+
);
|
|
2559
|
+
}
|
|
2547
2560
|
if (!response.ok) {
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
`
|
|
2561
|
+
return createTheTokenCompanyFallback(
|
|
2562
|
+
input,
|
|
2563
|
+
`service returned HTTP ${response.status}`
|
|
2564
|
+
);
|
|
2565
|
+
}
|
|
2566
|
+
let data;
|
|
2567
|
+
try {
|
|
2568
|
+
data = await response.json();
|
|
2569
|
+
} catch (error) {
|
|
2570
|
+
return createTheTokenCompanyFallback(
|
|
2571
|
+
input,
|
|
2572
|
+
`response body was not valid JSON: ${toErrorMessage(error)}`
|
|
2551
2573
|
);
|
|
2552
2574
|
}
|
|
2553
|
-
const
|
|
2554
|
-
if (
|
|
2555
|
-
|
|
2575
|
+
const normalized = normalizeTheTokenCompanyCompressResponse(data);
|
|
2576
|
+
if (!normalized) {
|
|
2577
|
+
return createTheTokenCompanyFallback(
|
|
2578
|
+
input,
|
|
2579
|
+
"response payload was invalid"
|
|
2580
|
+
);
|
|
2556
2581
|
}
|
|
2557
|
-
return
|
|
2582
|
+
return normalized;
|
|
2583
|
+
}
|
|
2584
|
+
function createTheTokenCompanyFallback(input, reason) {
|
|
2585
|
+
const tokens = estimateHeuristicTokens(input);
|
|
2586
|
+
return {
|
|
2587
|
+
output: input,
|
|
2588
|
+
output_tokens: tokens,
|
|
2589
|
+
input_tokens: tokens,
|
|
2590
|
+
tokens_saved: 0,
|
|
2591
|
+
compression_ratio: tokens === 0 ? 0 : 1,
|
|
2592
|
+
warnings: [
|
|
2593
|
+
`POK057: TheTokenCompany compression skipped; using uncompressed prompt with zero token savings (${reason}).`
|
|
2594
|
+
]
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
function toErrorMessage(error) {
|
|
2598
|
+
return error instanceof Error && error.message ? error.message : "unknown error";
|
|
2599
|
+
}
|
|
2600
|
+
function normalizeTheTokenCompanyCompressResponse(data) {
|
|
2601
|
+
if (typeof data.output !== "string" || typeof data.output_tokens !== "number") {
|
|
2602
|
+
return void 0;
|
|
2603
|
+
}
|
|
2604
|
+
const inputTokens = typeof data.input_tokens === "number" ? data.input_tokens : data.original_input_tokens;
|
|
2605
|
+
if (typeof inputTokens !== "number") {
|
|
2606
|
+
return void 0;
|
|
2607
|
+
}
|
|
2608
|
+
const tokensSaved = typeof data.tokens_saved === "number" ? data.tokens_saved : inputTokens - data.output_tokens;
|
|
2609
|
+
const compressionRatio = typeof data.compression_ratio === "number" ? data.compression_ratio : data.output_tokens === 0 ? 0 : inputTokens / data.output_tokens;
|
|
2610
|
+
return {
|
|
2611
|
+
output: data.output,
|
|
2612
|
+
output_tokens: data.output_tokens,
|
|
2613
|
+
input_tokens: inputTokens,
|
|
2614
|
+
tokens_saved: tokensSaved,
|
|
2615
|
+
compression_ratio: compressionRatio
|
|
2616
|
+
};
|
|
2558
2617
|
}
|
|
2559
2618
|
function getEnv(name) {
|
|
2560
2619
|
if (typeof process === "undefined") {
|