@linxiraos/pi-agent-core 1.1.0 → 1.1.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/CHANGELOG.md +12 -0
- package/THIRD-PARTY-NOTICES.txt +22909 -0
- package/dist/types/agent-loop.d.ts +137 -0
- package/dist/types/agent.d.ts +472 -0
- package/dist/types/append-only-context.d.ts +131 -0
- package/dist/types/compaction/branch-summarization.d.ts +102 -0
- package/dist/types/compaction/compaction-v2-streaming.d.ts +85 -0
- package/dist/types/compaction/compaction.d.ts +341 -0
- package/dist/types/compaction/entries.d.ts +120 -0
- package/dist/types/compaction/errors.d.ts +38 -0
- package/dist/types/compaction/index.d.ts +14 -0
- package/dist/types/compaction/message-cache.d.ts +25 -0
- package/dist/types/compaction/messages.d.ts +103 -0
- package/dist/types/compaction/openai.d.ts +118 -0
- package/dist/types/compaction/pruning.d.ts +106 -0
- package/dist/types/compaction/shake.d.ts +100 -0
- package/dist/types/compaction/tool-protection.d.ts +19 -0
- package/dist/types/compaction/transcript-tokens.d.ts +76 -0
- package/dist/types/compaction/utils.d.ts +63 -0
- package/dist/types/compaction.d.ts +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/pause.d.ts +46 -0
- package/dist/types/proxy.d.ts +91 -0
- package/dist/types/replay-policy.d.ts +5 -0
- package/dist/types/run-collector.d.ts +196 -0
- package/dist/types/telemetry.d.ts +625 -0
- package/dist/types/thinking.d.ts +18 -0
- package/dist/types/tokenizer.d.ts +78 -0
- package/dist/types/types.d.ts +786 -0
- package/dist/types/utils/yield.d.ts +71 -0
- package/package.json +80 -77
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Model } from "@linxiraos/pi-ai";
|
|
2
|
+
import { Encoding } from "@linxiraos/pi-natives";
|
|
3
|
+
import type { AgentMessage } from "./types.js";
|
|
4
|
+
/** Maps the catalog-resolved tokenizer family to its native implementation. */
|
|
5
|
+
export declare function tokenizerEncodingForModel(model: Pick<Model, "tokenizer"> | null | undefined): Encoding | null;
|
|
6
|
+
/**
|
|
7
|
+
* `strict` always pays for an exact native count (the catalog-resolved
|
|
8
|
+
* tokenizer when known, o200k_base otherwise). `approximate` and
|
|
9
|
+
* `upperbound` prefer the same exact count for known tokenizer families or
|
|
10
|
+
* when `PI_TOKENIZER_ACCURATE=1` is set; otherwise they use a cheap heuristic:
|
|
11
|
+
* `approximate` a bytes/4 guess, `upperbound` the raw byte length (never
|
|
12
|
+
* undercounts).
|
|
13
|
+
*/
|
|
14
|
+
export type TokenCountMode = "strict" | "approximate" | "upperbound";
|
|
15
|
+
/** Options for {@link Tokenizer.countMessage} / {@link Tokenizer.countMessages}. */
|
|
16
|
+
export interface MessageCountOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Drop opaque provider reasoning payloads (`thinkingSignature`,
|
|
19
|
+
* `redactedThinking`, native server-tool blocks) from the estimate. Those
|
|
20
|
+
* are billed by the provider on replay, so the default counts them — but
|
|
21
|
+
* their *local* byte size can diverge wildly from what the provider
|
|
22
|
+
* charges, so the compaction floor (which only needs the reliably-countable,
|
|
23
|
+
* on-wire-compressible content) excludes them to avoid false triggers on
|
|
24
|
+
* thinking-heavy turns.
|
|
25
|
+
*/
|
|
26
|
+
excludeEncryptedReasoning?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Verdict from {@link Tokenizer.checkTokenBudget}. */
|
|
29
|
+
export interface TokenBudgetCheck {
|
|
30
|
+
/** Whether the text fits the budget. */
|
|
31
|
+
fits: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Token count behind the verdict: the exact native count when `exact` is
|
|
34
|
+
* set, otherwise the cheap byte upper bound (which already fit, so it is
|
|
35
|
+
* only an over-estimate of a count known to be under budget).
|
|
36
|
+
*/
|
|
37
|
+
tokens: number;
|
|
38
|
+
/** Whether the exact tokenizer had to run because the cheap bound busted. */
|
|
39
|
+
exact: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Model-aware local token counter. Immutable: the catalog-resolved encoding
|
|
43
|
+
* is fixed at construction, so a cached count can never straddle two
|
|
44
|
+
* encodings. An `Agent` owns one for its active model (swapping the instance
|
|
45
|
+
* when the model's encoding changes); one-shot flows construct their own for
|
|
46
|
+
* the model that will be billed. Known tokenizer families use exact native
|
|
47
|
+
* counts; unknown models keep the fast byte estimate (or o200k when
|
|
48
|
+
* `PI_TOKENIZER_ACCURATE=1`).
|
|
49
|
+
*/
|
|
50
|
+
export declare class Tokenizer {
|
|
51
|
+
#private;
|
|
52
|
+
constructor(model?: Pick<Model, "tokenizer"> | null);
|
|
53
|
+
get encoding(): Encoding | null;
|
|
54
|
+
countTokens(text: string | string[], mode?: TokenCountMode): number;
|
|
55
|
+
/**
|
|
56
|
+
* Cheap-first budget probe — the way to ask "does this fit in `budget`
|
|
57
|
+
* tokens?" without tokenizing the world.
|
|
58
|
+
*
|
|
59
|
+
* Byte length is a hard upper bound on token count (every token consumes at
|
|
60
|
+
* least one input byte), so text whose raw bytes already fit the budget
|
|
61
|
+
* cannot possibly exceed it — that verdict is returned without tokenizing at
|
|
62
|
+
* all. Only text that busts the bound is ambiguous, and only that case pays
|
|
63
|
+
* for the exact count. Since the bound overshoots ~4x on ordinary prose, the
|
|
64
|
+
* common "comfortably under budget" answer is free.
|
|
65
|
+
*/
|
|
66
|
+
checkTokenBudget(text: string | string[], budget: number): TokenBudgetCheck;
|
|
67
|
+
/**
|
|
68
|
+
* Token estimate for one message under this tokenizer's encoding.
|
|
69
|
+
*
|
|
70
|
+
* Settled historical messages are counted once and reused until an owner
|
|
71
|
+
* (prune/shake/strip-images) calls `invalidateMessageCache`; streaming
|
|
72
|
+
* assistants bypass the memo entirely (see the message-cache settle-gate
|
|
73
|
+
* invariant). Image blocks charge a fixed per-image estimate.
|
|
74
|
+
*/
|
|
75
|
+
countMessage(message: AgentMessage, options?: MessageCountOptions): number;
|
|
76
|
+
/** Sum of {@link countMessage} over `messages`. */
|
|
77
|
+
countMessages(messages: readonly AgentMessage[], options?: MessageCountOptions): number;
|
|
78
|
+
}
|