promptopskit 0.9.1 → 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 +1 -1
- package/dist/{chunk-QZHR2YMK.js → chunk-6ICAKKV3.js} +60 -20
- package/dist/{chunk-QZHR2YMK.js.map → chunk-6ICAKKV3.js.map} +1 -1
- package/dist/{chunk-O3SRIDTH.js → chunk-A2VPKL4X.js} +2 -2
- package/dist/{chunk-C5HHTLZX.js → chunk-CGBEKODU.js} +2 -2
- package/dist/{chunk-D23T3X4V.js → chunk-DA2NSBIN.js} +2 -2
- package/dist/{chunk-EDHPVR2F.js → chunk-DAJMCV4F.js} +3 -3
- package/dist/{chunk-QHAIOVQ3.js → chunk-XSSET4QN.js} +2 -2
- package/dist/{chunk-7GMCNHXJ.js → chunk-YLJGWVZ6.js} +3 -3
- package/dist/index.cjs +59 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -7
- package/dist/providers/anthropic.cjs +59 -19
- package/dist/providers/anthropic.cjs.map +1 -1
- package/dist/providers/anthropic.js +2 -2
- package/dist/providers/gemini.cjs +59 -19
- package/dist/providers/gemini.cjs.map +1 -1
- package/dist/providers/gemini.js +2 -2
- package/dist/providers/llmasaservice.cjs +59 -19
- package/dist/providers/llmasaservice.cjs.map +1 -1
- package/dist/providers/llmasaservice.js +3 -3
- package/dist/providers/openai-responses.cjs +59 -19
- package/dist/providers/openai-responses.cjs.map +1 -1
- package/dist/providers/openai-responses.js +2 -2
- package/dist/providers/openai.cjs +59 -19
- package/dist/providers/openai.cjs.map +1 -1
- package/dist/providers/openai.js +2 -2
- package/dist/providers/openrouter.cjs +59 -19
- package/dist/providers/openrouter.cjs.map +1 -1
- package/dist/providers/openrouter.js +3 -3
- package/package.json +1 -1
- /package/dist/{chunk-O3SRIDTH.js.map → chunk-A2VPKL4X.js.map} +0 -0
- /package/dist/{chunk-C5HHTLZX.js.map → chunk-CGBEKODU.js.map} +0 -0
- /package/dist/{chunk-D23T3X4V.js.map → chunk-DA2NSBIN.js.map} +0 -0
- /package/dist/{chunk-EDHPVR2F.js.map → chunk-DAJMCV4F.js.map} +0 -0
- /package/dist/{chunk-QHAIOVQ3.js.map → chunk-XSSET4QN.js.map} +0 -0
- /package/dist/{chunk-7GMCNHXJ.js.map → chunk-YLJGWVZ6.js.map} +0 -0
package/README.md
CHANGED
|
@@ -292,7 +292,7 @@ cache:
|
|
|
292
292
|
retention: 24h
|
|
293
293
|
```
|
|
294
294
|
|
|
295
|
-
At render time, pass the caller-owned API key. PromptOpsKit calls `POST https://api.thetokencompany.com/v1/compress` directly with `fetch`; no TheTokenCompany SDK is required.
|
|
295
|
+
At render time, pass the caller-owned API key. PromptOpsKit calls `POST https://api.thetokencompany.com/v1/compress` directly with `fetch`; no TheTokenCompany SDK is required. If credentials are unavailable or the backend call fails, PromptOpsKit preserves the original prompt text, returns a `POK057` warning in `warnings`, and reports zero token savings with matching input/output token counts. Library rendering does not log this fallback to the console.
|
|
296
296
|
|
|
297
297
|
```typescript
|
|
298
298
|
const result = await kit.renderPrompt({
|
|
@@ -1632,6 +1632,7 @@ async function applyPromptCompressionForRender(asset, runtime) {
|
|
|
1632
1632
|
aggressiveness: theTokenCompanyConfig?.aggressiveness
|
|
1633
1633
|
});
|
|
1634
1634
|
promptTemplate = result.output;
|
|
1635
|
+
warnings.push(...result.warnings ?? []);
|
|
1635
1636
|
compression.push({
|
|
1636
1637
|
provider: "thetokencompany",
|
|
1637
1638
|
model,
|
|
@@ -1697,41 +1698,80 @@ function reportHeuristicCompressionWarnings2(warnings, compressionWarnings, scop
|
|
|
1697
1698
|
async function compressWithTheTokenCompany(input, options) {
|
|
1698
1699
|
const apiKey = options.apiKey ?? getEnv("THETOKENCOMPANY_API_KEY") ?? getEnv("TTC_API_KEY");
|
|
1699
1700
|
if (!apiKey) {
|
|
1700
|
-
|
|
1701
|
-
|
|
1701
|
+
return createTheTokenCompanyFallback(
|
|
1702
|
+
input,
|
|
1703
|
+
"no API key was provided"
|
|
1702
1704
|
);
|
|
1703
1705
|
}
|
|
1704
1706
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1705
1707
|
if (!fetchImpl) {
|
|
1706
|
-
|
|
1708
|
+
return createTheTokenCompanyFallback(
|
|
1709
|
+
input,
|
|
1710
|
+
"fetch is unavailable in this runtime"
|
|
1711
|
+
);
|
|
1707
1712
|
}
|
|
1708
1713
|
const baseURL = (options.baseURL ?? THETOKENCOMPANY_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
1709
1714
|
const compressionSettings = options.aggressiveness === void 0 ? void 0 : { aggressiveness: options.aggressiveness };
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1715
|
+
let response;
|
|
1716
|
+
try {
|
|
1717
|
+
response = await fetchImpl(`${baseURL}/v1/compress`, {
|
|
1718
|
+
method: "POST",
|
|
1719
|
+
headers: {
|
|
1720
|
+
Authorization: `Bearer ${apiKey}`,
|
|
1721
|
+
"Content-Type": "application/json"
|
|
1722
|
+
},
|
|
1723
|
+
body: JSON.stringify({
|
|
1724
|
+
model: options.model,
|
|
1725
|
+
input,
|
|
1726
|
+
...compressionSettings ? { compression_settings: compressionSettings } : {}
|
|
1727
|
+
})
|
|
1728
|
+
});
|
|
1729
|
+
} catch (error) {
|
|
1730
|
+
return createTheTokenCompanyFallback(
|
|
1718
1731
|
input,
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
}
|
|
1732
|
+
`request failed: ${toErrorMessage(error)}`
|
|
1733
|
+
);
|
|
1734
|
+
}
|
|
1722
1735
|
if (!response.ok) {
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
`
|
|
1736
|
+
return createTheTokenCompanyFallback(
|
|
1737
|
+
input,
|
|
1738
|
+
`service returned HTTP ${response.status}`
|
|
1739
|
+
);
|
|
1740
|
+
}
|
|
1741
|
+
let data;
|
|
1742
|
+
try {
|
|
1743
|
+
data = await response.json();
|
|
1744
|
+
} catch (error) {
|
|
1745
|
+
return createTheTokenCompanyFallback(
|
|
1746
|
+
input,
|
|
1747
|
+
`response body was not valid JSON: ${toErrorMessage(error)}`
|
|
1726
1748
|
);
|
|
1727
1749
|
}
|
|
1728
|
-
const data = await response.json();
|
|
1729
1750
|
const normalized = normalizeTheTokenCompanyCompressResponse(data);
|
|
1730
1751
|
if (!normalized) {
|
|
1731
|
-
|
|
1752
|
+
return createTheTokenCompanyFallback(
|
|
1753
|
+
input,
|
|
1754
|
+
"response payload was invalid"
|
|
1755
|
+
);
|
|
1732
1756
|
}
|
|
1733
1757
|
return normalized;
|
|
1734
1758
|
}
|
|
1759
|
+
function createTheTokenCompanyFallback(input, reason) {
|
|
1760
|
+
const tokens = estimateHeuristicTokens(input);
|
|
1761
|
+
return {
|
|
1762
|
+
output: input,
|
|
1763
|
+
output_tokens: tokens,
|
|
1764
|
+
input_tokens: tokens,
|
|
1765
|
+
tokens_saved: 0,
|
|
1766
|
+
compression_ratio: tokens === 0 ? 0 : 1,
|
|
1767
|
+
warnings: [
|
|
1768
|
+
`POK057: TheTokenCompany compression skipped; using uncompressed prompt with zero token savings (${reason}).`
|
|
1769
|
+
]
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
function toErrorMessage(error) {
|
|
1773
|
+
return error instanceof Error && error.message ? error.message : "unknown error";
|
|
1774
|
+
}
|
|
1735
1775
|
function normalizeTheTokenCompanyCompressResponse(data) {
|
|
1736
1776
|
if (typeof data.output !== "string" || typeof data.output_tokens !== "number") {
|
|
1737
1777
|
return void 0;
|
|
@@ -1857,4 +1897,4 @@ export {
|
|
|
1857
1897
|
withPromptInputSupport,
|
|
1858
1898
|
applyRawProviderBody
|
|
1859
1899
|
};
|
|
1860
|
-
//# sourceMappingURL=chunk-
|
|
1900
|
+
//# sourceMappingURL=chunk-6ICAKKV3.js.map
|