@kunal_dutt/token-lens 0.2.25 → 0.2.27
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/PRIVACY.md +1 -1
- package/README.md +2 -1
- package/check-agent.mjs +14 -13
- package/gateway.mjs +73 -66
- package/package.json +1 -1
- package/sdk.mjs +2 -2
- package/server.mjs +86 -75
- package/token-lens.mcpb +0 -0
- package/types/src/core/compare.d.ts +22 -0
- package/types/src/core/data.d.ts +39 -0
- package/types/src/core/forecast.d.ts +43 -0
- package/types/src/core/index.d.ts +3 -0
package/token-lens.mcpb
CHANGED
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check a prompt someone shortened by hand (or with another tool) against the
|
|
3
|
+
* original: tokens and money saved, and whether anything that steers the
|
|
4
|
+
* answer went missing. Uses the same meaning guard as Token Lens's own
|
|
5
|
+
* rewrites, so a hand edit is held to the same bar.
|
|
6
|
+
*/
|
|
7
|
+
import { type Savings } from "./cost";
|
|
8
|
+
import type { ModelProfile } from "./models";
|
|
9
|
+
export interface PromptComparison {
|
|
10
|
+
before: number;
|
|
11
|
+
after: number;
|
|
12
|
+
/** Positive when the edit is shorter. */
|
|
13
|
+
saved: Savings;
|
|
14
|
+
/** True when every number, URL, code span, quote, negation, constraint and instruction word is kept. */
|
|
15
|
+
sameInstructions: boolean;
|
|
16
|
+
/** Facts or constraints the edit dropped, e.g. "negation: not", "number: 30". */
|
|
17
|
+
lostFacts: string[];
|
|
18
|
+
/** Content words the edit dropped (beyond politeness and filler). */
|
|
19
|
+
lostWords: string[];
|
|
20
|
+
verdict: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function comparePrompts(original: string, edited: string, profile: ModelProfile): PromptComparison;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lossless compaction of pasted data. Pretty-printed JSON spends many tokens
|
|
3
|
+
* on indentation and line breaks the model doesn't need: the same values,
|
|
4
|
+
* keys and order fit in far fewer tokens. Only whitespace outside JSON strings
|
|
5
|
+
* is removed, and each block is proven identical by parsing both versions.
|
|
6
|
+
* Outside code fences, trailing spaces and runs of blank lines go too;
|
|
7
|
+
* indentation and every other character stay as written.
|
|
8
|
+
*
|
|
9
|
+
* Skipped when the request is about formatting itself (indent, pretty-print,
|
|
10
|
+
* whitespace), since there the layout is the subject.
|
|
11
|
+
*/
|
|
12
|
+
import type { ModelProfile } from "./models";
|
|
13
|
+
export interface DataBlock {
|
|
14
|
+
kind: "json";
|
|
15
|
+
/** Where it was found: "whole text", "```json block 2", "lines 4-31". */
|
|
16
|
+
where: string;
|
|
17
|
+
tokens: number;
|
|
18
|
+
compactTokens: number;
|
|
19
|
+
}
|
|
20
|
+
export interface CompactResult {
|
|
21
|
+
text: string;
|
|
22
|
+
before: number;
|
|
23
|
+
after: number;
|
|
24
|
+
saved: number;
|
|
25
|
+
blocks: DataBlock[];
|
|
26
|
+
/** Plain-words list of what changed. */
|
|
27
|
+
changes: string[];
|
|
28
|
+
/** Evidence: each JSON block parses to the same value before and after. */
|
|
29
|
+
checks: Array<{
|
|
30
|
+
name: string;
|
|
31
|
+
passed: boolean;
|
|
32
|
+
detail: string;
|
|
33
|
+
}>;
|
|
34
|
+
/** Why nothing was compacted, when that's the case. */
|
|
35
|
+
skipped?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Removes whitespace outside JSON strings. Every other character stays, in order. */
|
|
38
|
+
export declare function minifyJson(src: string): string;
|
|
39
|
+
export declare function compactData(text: string, profile: ModelProfile): CompactResult;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Monthly cost forecast for an app or agent on the model it already uses, and
|
|
3
|
+
* what the same-answer options cut from it: prompt caching for the part every
|
|
4
|
+
* call repeats, and the provider's half-price batch option for work that can
|
|
5
|
+
* wait. Never a different model. Long-context pricing applies when a call's
|
|
6
|
+
* input passes the model's price step.
|
|
7
|
+
*/
|
|
8
|
+
import type { ModelProfile } from "./models";
|
|
9
|
+
export interface ForecastInput {
|
|
10
|
+
/** Input tokens per call, including the repeated part. */
|
|
11
|
+
inputTokens: number;
|
|
12
|
+
/** Output tokens per call (the answer, plus reasoning tokens on thinking models). */
|
|
13
|
+
outputTokens: number;
|
|
14
|
+
callsPerDay: number;
|
|
15
|
+
/** Tokens at the start of every call that never change (system prompt, tools, examples). */
|
|
16
|
+
repeatedPrefixTokens?: number;
|
|
17
|
+
/** Share of calls that can wait up to 24 hours for the answer (0 to 1). */
|
|
18
|
+
canWaitShare?: number;
|
|
19
|
+
/** Days per month, default 30. */
|
|
20
|
+
days?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ForecastLine {
|
|
23
|
+
id: "now" | "caching" | "batch" | "both";
|
|
24
|
+
label: string;
|
|
25
|
+
monthlyUsd: number;
|
|
26
|
+
savedUsd: number;
|
|
27
|
+
note: string;
|
|
28
|
+
}
|
|
29
|
+
export interface Forecast {
|
|
30
|
+
priced: boolean;
|
|
31
|
+
callsPerMonth: number;
|
|
32
|
+
longContext: boolean;
|
|
33
|
+
/** Rates used, USD per 1M tokens. */
|
|
34
|
+
rates: {
|
|
35
|
+
input: number;
|
|
36
|
+
output: number;
|
|
37
|
+
cached: number | null;
|
|
38
|
+
};
|
|
39
|
+
lines: ForecastLine[];
|
|
40
|
+
}
|
|
41
|
+
/** Providers whose own API has a half-price batch option on the same model. */
|
|
42
|
+
export declare const BATCH_FAMILIES: Set<string>;
|
|
43
|
+
export declare function forecastCost(profile: ModelProfile, f: ForecastInput): Forecast;
|
|
@@ -12,6 +12,9 @@ export * from "./advice";
|
|
|
12
12
|
export * from "./budget";
|
|
13
13
|
export * from "./compress";
|
|
14
14
|
export * from "./cost";
|
|
15
|
+
export * from "./compare";
|
|
16
|
+
export * from "./data";
|
|
17
|
+
export * from "./forecast";
|
|
15
18
|
export * from "./guard";
|
|
16
19
|
export * from "./hotspots";
|
|
17
20
|
export * from "./media";
|