@linnlabs/linnkit 0.10.0 → 0.21.0
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 +156 -1
- package/dist/{agent-invocation-BHcNfrBV.d.cts → agent-invocation-CAlm9qOw.d.cts} +1 -1
- package/dist/{agent-invocation-BznDaXDs.d.ts → agent-invocation-DKoEDLkl.d.ts} +1 -1
- package/dist/{ai-engine.types-vZRnQcJa.d.ts → ai-engine.types-CeLoM624.d.cts} +9 -1
- package/dist/{ai-engine.types-BpeU_XQG.d.cts → ai-engine.types-LqmnfR2W.d.ts} +9 -1
- package/dist/{audit-CtcfART1.d.ts → audit-BuWHoMEr.d.ts} +4 -2
- package/dist/{audit-LeOrm2hX.d.cts → audit-DnzNQzwq.d.cts} +4 -2
- package/dist/cli.cjs +565 -194
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +565 -194
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +590 -26
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.d.cts +84 -7
- package/dist/context-manager.d.ts +84 -7
- package/dist/context-manager.js +590 -26
- package/dist/context-manager.js.map +1 -1
- package/dist/{context-trace-BHKDS-eq.d.cts → context-trace-DrtvKac4.d.cts} +36 -3
- package/dist/{context-trace-CHbqHmyE.d.ts → context-trace-WV1HAZeB.d.ts} +36 -3
- package/dist/contracts.cjs +222 -1
- package/dist/contracts.cjs.map +1 -1
- package/dist/contracts.d.cts +5 -3
- package/dist/contracts.d.ts +5 -3
- package/dist/contracts.js +202 -2
- package/dist/contracts.js.map +1 -1
- package/dist/{defaultGraphExecutor-C2E59v_R.d.cts → defaultGraphExecutor-L1ri3oij.d.cts} +35 -7
- package/dist/{defaultGraphExecutor-B29_qTHy.d.ts → defaultGraphExecutor-QzzdudLQ.d.ts} +35 -7
- package/dist/{index-BAaUP9yU.d.cts → index-BeQO0rx2.d.cts} +328 -263
- package/dist/{index-Cvr23YCl.d.cts → index-CDofGr_4.d.ts} +24 -6
- package/dist/{index-CKQzzZ5Y.d.cts → index-Crl5E4eF.d.cts} +26 -3
- package/dist/{index-C0DAjsdX.d.ts → index-DWGKvssS.d.ts} +2 -2
- package/dist/{index-D0mKxTR5.d.ts → index-X5lYU1Lj.d.ts} +26 -3
- package/dist/{index-DDzuSb0n.d.ts → index-uCNCpJBg.d.cts} +24 -6
- package/dist/{index-BaVpVNi2.d.ts → index-wOZD-p2-.d.ts} +328 -263
- package/dist/{index-BnYCS8Zg.d.cts → index-wXVAHZ0D.d.cts} +2 -2
- package/dist/index.cjs +893 -312
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -14
- package/dist/index.d.ts +17 -14
- package/dist/index.js +893 -312
- package/dist/index.js.map +1 -1
- package/dist/{messages-XthmnHZ3.d.cts → messages-Br5SiLD3.d.cts} +706 -1
- package/dist/{messages-XthmnHZ3.d.ts → messages-Br5SiLD3.d.ts} +706 -1
- package/dist/{ports-s-tSp3sB.d.cts → ports-Dugizzje.d.cts} +4 -0
- package/dist/{ports-DpPTFhSd.d.ts → ports-fhp84x_C.d.ts} +4 -0
- package/dist/ports.d.cts +8 -5
- package/dist/ports.d.ts +8 -5
- package/dist/quickstart.cjs +564 -193
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.d.cts +9 -8
- package/dist/quickstart.d.ts +9 -8
- package/dist/quickstart.js +564 -193
- package/dist/quickstart.js.map +1 -1
- package/dist/{runAgent-C6F-399C.d.ts → runAgent-BmMSju8I.d.ts} +4 -4
- package/dist/{runAgent-ilEj66Ik.d.cts → runAgent-CKgcRSRH.d.cts} +4 -4
- package/dist/{runHandle-BNOqS-Bl.d.cts → runHandle-DH4VmQx6.d.cts} +4 -2
- package/dist/{runHandle-BdLXOFqF.d.ts → runHandle-o3p06Nva.d.ts} +4 -2
- package/dist/runtime-kernel/events.cjs +201 -1
- package/dist/runtime-kernel/events.cjs.map +1 -1
- package/dist/runtime-kernel/events.d.cts +3 -3
- package/dist/runtime-kernel/events.d.ts +3 -3
- package/dist/runtime-kernel/events.js +201 -1
- package/dist/runtime-kernel/events.js.map +1 -1
- package/dist/runtime-kernel.cjs +824 -264
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.d.cts +14 -12
- package/dist/runtime-kernel.d.ts +14 -12
- package/dist/runtime-kernel.js +816 -265
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +847 -264
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.d.cts +14 -12
- package/dist/testkit.d.ts +14 -12
- package/dist/testkit.js +847 -264
- package/dist/testkit.js.map +1 -1
- package/dist/{agentSpec-Du4Iye0q.d.cts → token-accounting-CwpSPg4y.d.cts} +1265 -1
- package/dist/{agentSpec-Du4Iye0q.d.ts → token-accounting-CwpSPg4y.d.ts} +1265 -1
- package/dist/token-calibration-Cxv6dDYF.d.cts +327 -0
- package/dist/token-calibration-Cxv6dDYF.d.ts +327 -0
- package/dist/token-counter-CFfP8PQb.d.cts +26 -0
- package/dist/token-counter-SFyyTeaG.d.ts +26 -0
- package/dist/token-usage-CqwT7-5K.d.cts +133 -0
- package/dist/token-usage-CqwT7-5K.d.ts +133 -0
- package/dist/{tokenizer-DFL4I7-I.d.ts → tokenizer-BFJNCHFX.d.ts} +1 -1
- package/dist/{tokenizer-DH_JXv-H.d.cts → tokenizer-DoGsBE3A.d.cts} +1 -1
- package/docs/README.md +1 -1
- package/docs/integration/README.md +2 -2
- package/docs/integration/agent-registration-guide.md +2 -0
- package/docs/integration/context-engineering.md +53 -1
- package/docs/integration/context-fences.md +12 -0
- package/package.json +2 -2
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { A as AiMessage, a as AssistantMessage } from './messages-
|
|
2
|
-
import { C as ChatMessage, P as ProviderContext$2, M as MessageProcessingState, B as BaseContextProvider$2, a as ProviderResult, I as IContextProvider$2, b as ContextTraceCollector, S as SummarizationCallbacks, G as GenerateRequest, c as GenerateResponse, d as ContextTrace } from './context-trace-
|
|
3
|
-
export { e as ChatDocumentMetadata, f as ChatProjectMetadata, g as ChatUserQuote, h as ContextProviderError, i as ContextProviderErrorCode, j as ContextProviderErrorOptions, k as ContextTraceEvent, l as ContextTraceMessageDecisionEvent, m as ContextTraceProviderEvent, n as MessageRole, o as MessageType,
|
|
1
|
+
import { A as AiMessage, a as AssistantMessage } from './messages-Br5SiLD3.cjs';
|
|
2
|
+
import { C as ChatMessage, P as ProviderContext$2, M as MessageProcessingState, B as BaseContextProvider$2, a as ProviderResult, I as IContextProvider$2, R as RemoteTokenCountTrace, b as ContextTraceCollector, S as SummarizationCallbacks, G as GenerateRequest, c as GenerateResponse, d as ContextTrace } from './context-trace-DrtvKac4.cjs';
|
|
3
|
+
export { e as ChatDocumentMetadata, f as ChatProjectMetadata, g as ChatUserQuote, h as ContextProviderError, i as ContextProviderErrorCode, j as ContextProviderErrorOptions, k as ContextTraceEvent, l as ContextTraceMessageDecisionEvent, m as ContextTraceProviderEvent, n as MessageRole, o as MessageType, p as RecentRejection, q as SUMMARIZATION_FAILED_ERROR_CODE, T as TOOL_HISTORY_OVERFLOW_ERROR_CODE, r as isContextProviderError } from './context-trace-DrtvKac4.cjs';
|
|
4
4
|
export { C as CHECKPOINT_MARKER_TYPE } from './checkpointMarker-DAI3wUQu.cjs';
|
|
5
|
-
import { A as AgentSpecToolOutputPolicy, a as AgentSpecProviderReplayPolicy, b as AgentSpecCheckpointPolicy, c as AgentSpecSummarizationPolicy, d as AgentSpecContextTracePolicy, e as AgentSpecSystemReminderPolicy, f as AgentSpec, g as AgentSpecContextPolicy, h as AgentSpecContextPolicyInput } from './
|
|
5
|
+
import { A as AgentSpecToolOutputPolicy, a as AgentSpecProviderReplayPolicy, b as AgentSpecCheckpointPolicy, c as AgentSpecSummarizationPolicy, d as AgentSpecContextTracePolicy, e as AgentSpecSystemReminderPolicy, f as AgentSpec, g as AgentSpecContextPolicy, h as AgentSpecContextPolicyInput, i as AgentSpecTokenEstimationPolicy, C as ContextTokenComponent } from './token-accounting-CwpSPg4y.cjs';
|
|
6
6
|
import { R as RuntimeEvent } from './todo-Ca8llpRQ.cjs';
|
|
7
|
-
import { T as
|
|
7
|
+
import { T as TokenRoute } from './token-usage-CqwT7-5K.cjs';
|
|
8
|
+
import { T as TokenUsageCalibrationTrace, a as TokenUsageCalibrationSample, C as ContextBuildTokenEstimate } from './token-calibration-Cxv6dDYF.cjs';
|
|
9
|
+
import { T as TokenCounterPort } from './token-counter-CFfP8PQb.cjs';
|
|
10
|
+
import { T as TokenizerPort } from './tokenizer-DoGsBE3A.cjs';
|
|
8
11
|
import { T as ToolArgs } from './toolContracts-Bm3EZ1UM.cjs';
|
|
9
12
|
import 'zod';
|
|
10
|
-
import './ai-engine.types-
|
|
13
|
+
import './ai-engine.types-CeLoM624.cjs';
|
|
11
14
|
|
|
12
15
|
type FenceLlmRole = 'user' | 'system';
|
|
13
16
|
type FencePlacement = 'after-system' | 'before-current-user' | 'after-current-user' | 'after-last-tool-result';
|
|
@@ -973,6 +976,26 @@ interface RunContextPipelineResult {
|
|
|
973
976
|
states: MessageProcessingState[];
|
|
974
977
|
}
|
|
975
978
|
|
|
979
|
+
interface TokenUsageCalibrationState {
|
|
980
|
+
enabled: boolean;
|
|
981
|
+
route?: TokenRoute;
|
|
982
|
+
sampleCount: number;
|
|
983
|
+
coefficient?: number;
|
|
984
|
+
minSamples?: number;
|
|
985
|
+
minCoefficient?: number;
|
|
986
|
+
maxCoefficient?: number;
|
|
987
|
+
sampleLedgerEntryIds?: string[];
|
|
988
|
+
}
|
|
989
|
+
interface CalibrateTokenEstimateInput {
|
|
990
|
+
localEstimateTokens: number;
|
|
991
|
+
state: TokenUsageCalibrationState;
|
|
992
|
+
}
|
|
993
|
+
interface CalibratedTokenEstimate {
|
|
994
|
+
tokens: number;
|
|
995
|
+
trace: TokenUsageCalibrationTrace;
|
|
996
|
+
}
|
|
997
|
+
declare function calibrateTokenEstimate(input: CalibrateTokenEstimateInput): CalibratedTokenEstimate;
|
|
998
|
+
|
|
976
999
|
interface ContextManagerBaseConfig {
|
|
977
1000
|
AVG_CHARS_PER_TOKEN: number;
|
|
978
1001
|
TOOL_CALL_OVERHEAD_TOKENS?: number;
|
|
@@ -984,6 +1007,14 @@ interface ContextManagerBaseOptions<TConfig, TRegistry> {
|
|
|
984
1007
|
providerRegistry?: TRegistry;
|
|
985
1008
|
tokenizer?: TokenizerPort;
|
|
986
1009
|
tokenizerModelId?: string;
|
|
1010
|
+
tokenCounter?: TokenCounterPort;
|
|
1011
|
+
tokenRoute?: TokenRoute;
|
|
1012
|
+
remoteCount?: AgentSpecTokenEstimationPolicy['remoteCount'];
|
|
1013
|
+
tokenCalibration?: {
|
|
1014
|
+
policy?: AgentSpecTokenEstimationPolicy['calibration'];
|
|
1015
|
+
route?: TokenRoute;
|
|
1016
|
+
samples?: readonly TokenUsageCalibrationSample[];
|
|
1017
|
+
};
|
|
987
1018
|
}
|
|
988
1019
|
interface ContextManagerBaseInit<TConfig, TRegistry> {
|
|
989
1020
|
defaultConfig: TConfig;
|
|
@@ -999,12 +1030,31 @@ declare abstract class ContextManagerBase<TConfig extends ContextManagerBaseConf
|
|
|
999
1030
|
protected logger: Logger;
|
|
1000
1031
|
protected tokenizer: TokenizerPort;
|
|
1001
1032
|
protected tokenizerModelId?: string;
|
|
1033
|
+
private readonly tokenCounter?;
|
|
1034
|
+
private readonly tokenRoute?;
|
|
1035
|
+
private readonly remoteCountPolicy?;
|
|
1036
|
+
private tokenCalibrationState;
|
|
1002
1037
|
private readonly validateConfigFn;
|
|
1003
1038
|
private readonly invalidConfigMessage;
|
|
1004
1039
|
private readonly hasCustomTokenizer;
|
|
1005
1040
|
protected constructor(options: ContextManagerBaseOptions<TConfig, TRegistry>, init: ContextManagerBaseInit<TConfig, TRegistry>);
|
|
1006
1041
|
private createDefaultTokenizer;
|
|
1007
1042
|
protected estimateTokens(message: AiMessage): number;
|
|
1043
|
+
protected estimateTokensWithCalibrationTrace(message: AiMessage): {
|
|
1044
|
+
tokens: number;
|
|
1045
|
+
calibrationTrace: ReturnType<typeof calibrateTokenEstimate>['trace'];
|
|
1046
|
+
};
|
|
1047
|
+
protected getTokenCalibrationTrace(): ReturnType<typeof calibrateTokenEstimate>['trace'];
|
|
1048
|
+
protected getTokenRoute(): TokenRoute | undefined;
|
|
1049
|
+
protected estimateLocalTokens(messages: readonly AiMessage[]): number;
|
|
1050
|
+
protected countMessagesWithRemoteCounter(input: {
|
|
1051
|
+
messages: readonly AiMessage[];
|
|
1052
|
+
localEstimateTokens: number;
|
|
1053
|
+
signal?: AbortSignal;
|
|
1054
|
+
}): Promise<{
|
|
1055
|
+
tokens: number;
|
|
1056
|
+
trace: RemoteTokenCountTrace;
|
|
1057
|
+
}>;
|
|
1008
1058
|
protected debug(message: string, data?: Record<string, unknown>): void;
|
|
1009
1059
|
protected runPipeline<TContext extends ProviderContext$2<TConfig>, TPhase extends PropertyKey, TStats extends ContextPipelineStats<TPhase>>(options: {
|
|
1010
1060
|
messages: AiMessage[];
|
|
@@ -1023,6 +1073,7 @@ declare abstract class ContextManagerBase<TConfig extends ContextManagerBaseConf
|
|
|
1023
1073
|
* AgentMessageOrchestrator 会按 request 自动处理,直接使用 ContextManager 的高级接入方才需要手动调用。
|
|
1024
1074
|
*/
|
|
1025
1075
|
updateTokenizerModelId(modelId: string | undefined): void;
|
|
1076
|
+
updateTokenCalibration(input: ContextManagerBaseOptions<TConfig, TRegistry>['tokenCalibration']): void;
|
|
1026
1077
|
}
|
|
1027
1078
|
|
|
1028
1079
|
/**
|
|
@@ -1059,6 +1110,10 @@ interface ContextBuildResult$1 {
|
|
|
1059
1110
|
events?: RuntimeEvent[];
|
|
1060
1111
|
/** ContextTrace:解释本次上下文构建如何保留/裁剪消息。 */
|
|
1061
1112
|
contextTrace?: ContextTrace;
|
|
1113
|
+
/** 构建期 token 估算快照,用于 host 把本地估算与响应后 actual usage 配对。 */
|
|
1114
|
+
tokenEstimate?: ContextBuildTokenEstimate;
|
|
1115
|
+
/** 构建期上下文分项 token 估算,用于 trace、账本与 host 面板后端。 */
|
|
1116
|
+
tokenComponents?: ContextTokenComponent[];
|
|
1062
1117
|
}
|
|
1063
1118
|
/**
|
|
1064
1119
|
* Agent专用智能上下文管理器
|
|
@@ -1080,6 +1135,10 @@ declare class AgentContextManager extends ContextManagerBase<AgentContextBuilder
|
|
|
1080
1135
|
providerRegistry?: ContextProviderRegistry$1;
|
|
1081
1136
|
tokenizer?: TokenizerPort;
|
|
1082
1137
|
tokenizerModelId?: string;
|
|
1138
|
+
tokenCounter?: TokenCounterPort;
|
|
1139
|
+
tokenRoute?: TokenRoute;
|
|
1140
|
+
remoteCount?: ContextManagerBaseOptions<AgentContextBuilderConfig, ContextProviderRegistry$1>['remoteCount'];
|
|
1141
|
+
tokenCalibration?: ContextManagerBaseOptions<AgentContextBuilderConfig, ContextProviderRegistry$1>['tokenCalibration'];
|
|
1083
1142
|
});
|
|
1084
1143
|
/**
|
|
1085
1144
|
* 主入口:为Agent构建智能上下文
|
|
@@ -1096,6 +1155,7 @@ declare class AgentContextManager extends ContextManagerBase<AgentContextBuilder
|
|
|
1096
1155
|
private getPhaseByProviderName;
|
|
1097
1156
|
private initializeBuildStats;
|
|
1098
1157
|
private buildFinalResult;
|
|
1158
|
+
private buildContextTokenEstimate;
|
|
1099
1159
|
/**
|
|
1100
1160
|
* 生成优化建议
|
|
1101
1161
|
*/
|
|
@@ -1474,10 +1534,24 @@ interface AgentOrchestratorOptions {
|
|
|
1474
1534
|
contextPolicy: AgentSpecContextPolicy | undefined;
|
|
1475
1535
|
contextBuilderConfig: Partial<AgentContextBuilderConfig>;
|
|
1476
1536
|
}) => ContextProviderRegistry$1;
|
|
1537
|
+
resolveTokenCalibration?: (params: {
|
|
1538
|
+
request: AgentProfileRequest;
|
|
1539
|
+
modelId: string;
|
|
1540
|
+
contextPolicy: AgentSpecContextPolicy | undefined;
|
|
1541
|
+
}) => {
|
|
1542
|
+
route?: TokenRoute;
|
|
1543
|
+
samples?: readonly TokenUsageCalibrationSample[];
|
|
1544
|
+
} | undefined;
|
|
1477
1545
|
taskResolver: AgentTaskResolver;
|
|
1478
1546
|
providerRegistry: ContextProviderRegistry$1;
|
|
1479
1547
|
fenceRegistry?: FenceRegistry;
|
|
1480
1548
|
tokenizer?: TokenizerPort;
|
|
1549
|
+
tokenCounter?: TokenCounterPort;
|
|
1550
|
+
resolveTokenRoute?: (params: {
|
|
1551
|
+
request: AgentProfileRequest;
|
|
1552
|
+
modelId: string;
|
|
1553
|
+
contextPolicy: AgentSpecContextPolicy | undefined;
|
|
1554
|
+
}) => TokenRoute | undefined;
|
|
1481
1555
|
}
|
|
1482
1556
|
interface AgentProcessingResult {
|
|
1483
1557
|
messages: AiMessage[];
|
|
@@ -1886,6 +1960,8 @@ interface ContextBuildResult {
|
|
|
1886
1960
|
};
|
|
1887
1961
|
/** 🔥 新增:Provider生成的运行时事件(如摘要事件) */
|
|
1888
1962
|
events?: RuntimeEvent[];
|
|
1963
|
+
/** 构建期 token 估算快照。Chat 目前无 route,host 可只读 token 数。 */
|
|
1964
|
+
tokenEstimate?: ContextBuildTokenEstimate;
|
|
1889
1965
|
}
|
|
1890
1966
|
/**
|
|
1891
1967
|
* 智能上下文管理器 - Provider编排器
|
|
@@ -1911,6 +1987,7 @@ declare class ContextManager extends ContextManagerBase<ContextBuilderConfig, Co
|
|
|
1911
1987
|
private getPhaseByProviderName;
|
|
1912
1988
|
private initializeBuildStats;
|
|
1913
1989
|
private buildFinalResult;
|
|
1990
|
+
private buildContextTokenEstimate;
|
|
1914
1991
|
/**
|
|
1915
1992
|
* 生成优化建议
|
|
1916
1993
|
*/
|
|
@@ -2224,4 +2301,4 @@ interface ChatGenerateRequestAdapterInput extends AgentProfileRequest {
|
|
|
2224
2301
|
*/
|
|
2225
2302
|
declare function buildGenerateRequestFromAgentRequest(request: ChatGenerateRequestAdapterInput, conversationHistory: AiMessage[]): GenerateRequest;
|
|
2226
2303
|
|
|
2227
|
-
export { AGENT_CONSTANTS, AGENT_CONTEXT_BUILDER_CONFIG, AISummaryGenerator, type AgentContextBuilderConfigOverrides, type AgentSpecExecutionOptions, type AgentSpecPreprocessorOptions, type AgentSpecProviderOptions, type AgentSpecRuntimeOptions, BaseContextProvider$1 as BaseContextProvider, BaseConversationalTask, BasePreprocessor$1 as BasePreprocessor, ContextProviderRegistry as ChatContextProviderRegistry, CoreContextProvider as ChatCoreContextProvider, ChatMessage, MessageOrchestrator as ChatMessageOrchestrator, type OrchestratorOptions as ChatOrchestratorOptions, type ChatTaskResolver, WorkingMemoryProvider as ChatWorkingMemoryProvider, ContextProviderRegistry$2 as ContextProviderRegistry, ContextTrace, ContextTraceCollector, CurrentTurnMessageAssembler, type CurrentTurnMessageAssemblerOptions, DEFAULT_MUST_KEEP_POLICY, type FenceDescriptor, type FenceInjection, type FenceLifetime, FenceLifetimePreprocessor, type FenceLifetimePreprocessorOptions, type FenceLlmRole, type FencePlacement, type FenceRegistry, GenerateRequest, GenerateResponse, type HistoryPurificationConfig, HistoryPurificationPreprocessor, type IChatTask, type IContextProvider$1 as IContextProvider, type IPreprocessor$1 as IPreprocessor, type LlmMessage, type MergeContextPolicyParams, type MessageFormatOptions, type MessageFormatterOptions, MessageProcessingState, type MustKeepPolicy, type MustKeepTruncationRule, type NativeToolCallingMessage, type PreprocessorContext$1 as PreprocessorContext, type PreprocessorResult$1 as PreprocessorResult, type ProviderContext$1 as ProviderContext, ProviderResult, SummarizationCallbacks, SummarizationCandidateSelector, type SummarizationOptions, SummarizationProvider, SummarizationStateUtils, SummarizationTrigger, type ToolSummaryProvider, config as agentConfig, index$5 as agentContext, contracts as agentContracts, index$3 as agentOrchestration, index$4 as agentPreprocessors, agentSpecToContextBuilderConfig, agentSpecToRuntimeOptions, index$2 as agentTasks, index$1 as agentTools, index as agentUtils, aiMessageToChatMessage, buildGenerateRequestFromAgentRequest, chatMessageToAiMessage, contextPolicyToContextBuilderConfig, contextPolicyToExecutionOptions, contextPolicyToMustKeepPolicy, contextPolicyToPreprocessorOptions, contextPolicyToProviderOptions, contextPolicyToRuntimeOptions, contextPolicyToSystemReminderOptions, convertEventToChatMessage, convertEventsToChatMessages, createFenceRegistry, createMessageFormatter, findMatchingTruncationRule, formatAgentLlmMessages, getDefaultTokenConfig, mergeContextPolicy, messageFormatter };
|
|
2304
|
+
export { AGENT_CONSTANTS, AGENT_CONTEXT_BUILDER_CONFIG, AISummaryGenerator, type AgentContextBuilderConfigOverrides, type AgentSpecExecutionOptions, type AgentSpecPreprocessorOptions, type AgentSpecProviderOptions, type AgentSpecRuntimeOptions, BaseContextProvider$1 as BaseContextProvider, BaseConversationalTask, BasePreprocessor$1 as BasePreprocessor, ContextProviderRegistry as ChatContextProviderRegistry, CoreContextProvider as ChatCoreContextProvider, ChatMessage, MessageOrchestrator as ChatMessageOrchestrator, type OrchestratorOptions as ChatOrchestratorOptions, type ChatTaskResolver, WorkingMemoryProvider as ChatWorkingMemoryProvider, ContextProviderRegistry$2 as ContextProviderRegistry, ContextTrace, ContextTraceCollector, CurrentTurnMessageAssembler, type CurrentTurnMessageAssemblerOptions, DEFAULT_MUST_KEEP_POLICY, type FenceDescriptor, type FenceInjection, type FenceLifetime, FenceLifetimePreprocessor, type FenceLifetimePreprocessorOptions, type FenceLlmRole, type FencePlacement, type FenceRegistry, GenerateRequest, GenerateResponse, type HistoryPurificationConfig, HistoryPurificationPreprocessor, type IChatTask, type IContextProvider$1 as IContextProvider, type IPreprocessor$1 as IPreprocessor, type LlmMessage, type MergeContextPolicyParams, type MessageFormatOptions, type MessageFormatterOptions, MessageProcessingState, type MustKeepPolicy, type MustKeepTruncationRule, type NativeToolCallingMessage, type PreprocessorContext$1 as PreprocessorContext, type PreprocessorResult$1 as PreprocessorResult, type ProviderContext$1 as ProviderContext, ProviderResult, RemoteTokenCountTrace, SummarizationCallbacks, SummarizationCandidateSelector, type SummarizationOptions, SummarizationProvider, SummarizationStateUtils, SummarizationTrigger, type ToolSummaryProvider, config as agentConfig, index$5 as agentContext, contracts as agentContracts, index$3 as agentOrchestration, index$4 as agentPreprocessors, agentSpecToContextBuilderConfig, agentSpecToRuntimeOptions, index$2 as agentTasks, index$1 as agentTools, index as agentUtils, aiMessageToChatMessage, buildGenerateRequestFromAgentRequest, chatMessageToAiMessage, contextPolicyToContextBuilderConfig, contextPolicyToExecutionOptions, contextPolicyToMustKeepPolicy, contextPolicyToPreprocessorOptions, contextPolicyToProviderOptions, contextPolicyToRuntimeOptions, contextPolicyToSystemReminderOptions, convertEventToChatMessage, convertEventsToChatMessages, createFenceRegistry, createMessageFormatter, findMatchingTruncationRule, formatAgentLlmMessages, getDefaultTokenConfig, mergeContextPolicy, messageFormatter };
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { A as AiMessage, a as AssistantMessage } from './messages-
|
|
2
|
-
import { C as ChatMessage, P as ProviderContext$2, M as MessageProcessingState, B as BaseContextProvider$2, a as ProviderResult, I as IContextProvider$2, b as ContextTraceCollector, S as SummarizationCallbacks, G as GenerateRequest, c as GenerateResponse, d as ContextTrace } from './context-trace-
|
|
3
|
-
export { e as ChatDocumentMetadata, f as ChatProjectMetadata, g as ChatUserQuote, h as ContextProviderError, i as ContextProviderErrorCode, j as ContextProviderErrorOptions, k as ContextTraceEvent, l as ContextTraceMessageDecisionEvent, m as ContextTraceProviderEvent, n as MessageRole, o as MessageType,
|
|
1
|
+
import { A as AiMessage, a as AssistantMessage } from './messages-Br5SiLD3.js';
|
|
2
|
+
import { C as ChatMessage, P as ProviderContext$2, M as MessageProcessingState, B as BaseContextProvider$2, a as ProviderResult, I as IContextProvider$2, R as RemoteTokenCountTrace, b as ContextTraceCollector, S as SummarizationCallbacks, G as GenerateRequest, c as GenerateResponse, d as ContextTrace } from './context-trace-WV1HAZeB.js';
|
|
3
|
+
export { e as ChatDocumentMetadata, f as ChatProjectMetadata, g as ChatUserQuote, h as ContextProviderError, i as ContextProviderErrorCode, j as ContextProviderErrorOptions, k as ContextTraceEvent, l as ContextTraceMessageDecisionEvent, m as ContextTraceProviderEvent, n as MessageRole, o as MessageType, p as RecentRejection, q as SUMMARIZATION_FAILED_ERROR_CODE, T as TOOL_HISTORY_OVERFLOW_ERROR_CODE, r as isContextProviderError } from './context-trace-WV1HAZeB.js';
|
|
4
4
|
export { C as CHECKPOINT_MARKER_TYPE } from './checkpointMarker-DAI3wUQu.js';
|
|
5
|
-
import { A as AgentSpecToolOutputPolicy, a as AgentSpecProviderReplayPolicy, b as AgentSpecCheckpointPolicy, c as AgentSpecSummarizationPolicy, d as AgentSpecContextTracePolicy, e as AgentSpecSystemReminderPolicy, f as AgentSpec, g as AgentSpecContextPolicy, h as AgentSpecContextPolicyInput } from './
|
|
5
|
+
import { A as AgentSpecToolOutputPolicy, a as AgentSpecProviderReplayPolicy, b as AgentSpecCheckpointPolicy, c as AgentSpecSummarizationPolicy, d as AgentSpecContextTracePolicy, e as AgentSpecSystemReminderPolicy, f as AgentSpec, g as AgentSpecContextPolicy, h as AgentSpecContextPolicyInput, i as AgentSpecTokenEstimationPolicy, C as ContextTokenComponent } from './token-accounting-CwpSPg4y.js';
|
|
6
6
|
import { R as RuntimeEvent } from './todo-Ca8llpRQ.js';
|
|
7
|
-
import { T as
|
|
7
|
+
import { T as TokenRoute } from './token-usage-CqwT7-5K.js';
|
|
8
|
+
import { T as TokenUsageCalibrationTrace, a as TokenUsageCalibrationSample, C as ContextBuildTokenEstimate } from './token-calibration-Cxv6dDYF.js';
|
|
9
|
+
import { T as TokenCounterPort } from './token-counter-SFyyTeaG.js';
|
|
10
|
+
import { T as TokenizerPort } from './tokenizer-BFJNCHFX.js';
|
|
8
11
|
import { T as ToolArgs } from './toolContracts-f8lzZBNa.js';
|
|
9
12
|
import 'zod';
|
|
10
|
-
import './ai-engine.types-
|
|
13
|
+
import './ai-engine.types-LqmnfR2W.js';
|
|
11
14
|
|
|
12
15
|
type FenceLlmRole = 'user' | 'system';
|
|
13
16
|
type FencePlacement = 'after-system' | 'before-current-user' | 'after-current-user' | 'after-last-tool-result';
|
|
@@ -973,6 +976,26 @@ interface RunContextPipelineResult {
|
|
|
973
976
|
states: MessageProcessingState[];
|
|
974
977
|
}
|
|
975
978
|
|
|
979
|
+
interface TokenUsageCalibrationState {
|
|
980
|
+
enabled: boolean;
|
|
981
|
+
route?: TokenRoute;
|
|
982
|
+
sampleCount: number;
|
|
983
|
+
coefficient?: number;
|
|
984
|
+
minSamples?: number;
|
|
985
|
+
minCoefficient?: number;
|
|
986
|
+
maxCoefficient?: number;
|
|
987
|
+
sampleLedgerEntryIds?: string[];
|
|
988
|
+
}
|
|
989
|
+
interface CalibrateTokenEstimateInput {
|
|
990
|
+
localEstimateTokens: number;
|
|
991
|
+
state: TokenUsageCalibrationState;
|
|
992
|
+
}
|
|
993
|
+
interface CalibratedTokenEstimate {
|
|
994
|
+
tokens: number;
|
|
995
|
+
trace: TokenUsageCalibrationTrace;
|
|
996
|
+
}
|
|
997
|
+
declare function calibrateTokenEstimate(input: CalibrateTokenEstimateInput): CalibratedTokenEstimate;
|
|
998
|
+
|
|
976
999
|
interface ContextManagerBaseConfig {
|
|
977
1000
|
AVG_CHARS_PER_TOKEN: number;
|
|
978
1001
|
TOOL_CALL_OVERHEAD_TOKENS?: number;
|
|
@@ -984,6 +1007,14 @@ interface ContextManagerBaseOptions<TConfig, TRegistry> {
|
|
|
984
1007
|
providerRegistry?: TRegistry;
|
|
985
1008
|
tokenizer?: TokenizerPort;
|
|
986
1009
|
tokenizerModelId?: string;
|
|
1010
|
+
tokenCounter?: TokenCounterPort;
|
|
1011
|
+
tokenRoute?: TokenRoute;
|
|
1012
|
+
remoteCount?: AgentSpecTokenEstimationPolicy['remoteCount'];
|
|
1013
|
+
tokenCalibration?: {
|
|
1014
|
+
policy?: AgentSpecTokenEstimationPolicy['calibration'];
|
|
1015
|
+
route?: TokenRoute;
|
|
1016
|
+
samples?: readonly TokenUsageCalibrationSample[];
|
|
1017
|
+
};
|
|
987
1018
|
}
|
|
988
1019
|
interface ContextManagerBaseInit<TConfig, TRegistry> {
|
|
989
1020
|
defaultConfig: TConfig;
|
|
@@ -999,12 +1030,31 @@ declare abstract class ContextManagerBase<TConfig extends ContextManagerBaseConf
|
|
|
999
1030
|
protected logger: Logger;
|
|
1000
1031
|
protected tokenizer: TokenizerPort;
|
|
1001
1032
|
protected tokenizerModelId?: string;
|
|
1033
|
+
private readonly tokenCounter?;
|
|
1034
|
+
private readonly tokenRoute?;
|
|
1035
|
+
private readonly remoteCountPolicy?;
|
|
1036
|
+
private tokenCalibrationState;
|
|
1002
1037
|
private readonly validateConfigFn;
|
|
1003
1038
|
private readonly invalidConfigMessage;
|
|
1004
1039
|
private readonly hasCustomTokenizer;
|
|
1005
1040
|
protected constructor(options: ContextManagerBaseOptions<TConfig, TRegistry>, init: ContextManagerBaseInit<TConfig, TRegistry>);
|
|
1006
1041
|
private createDefaultTokenizer;
|
|
1007
1042
|
protected estimateTokens(message: AiMessage): number;
|
|
1043
|
+
protected estimateTokensWithCalibrationTrace(message: AiMessage): {
|
|
1044
|
+
tokens: number;
|
|
1045
|
+
calibrationTrace: ReturnType<typeof calibrateTokenEstimate>['trace'];
|
|
1046
|
+
};
|
|
1047
|
+
protected getTokenCalibrationTrace(): ReturnType<typeof calibrateTokenEstimate>['trace'];
|
|
1048
|
+
protected getTokenRoute(): TokenRoute | undefined;
|
|
1049
|
+
protected estimateLocalTokens(messages: readonly AiMessage[]): number;
|
|
1050
|
+
protected countMessagesWithRemoteCounter(input: {
|
|
1051
|
+
messages: readonly AiMessage[];
|
|
1052
|
+
localEstimateTokens: number;
|
|
1053
|
+
signal?: AbortSignal;
|
|
1054
|
+
}): Promise<{
|
|
1055
|
+
tokens: number;
|
|
1056
|
+
trace: RemoteTokenCountTrace;
|
|
1057
|
+
}>;
|
|
1008
1058
|
protected debug(message: string, data?: Record<string, unknown>): void;
|
|
1009
1059
|
protected runPipeline<TContext extends ProviderContext$2<TConfig>, TPhase extends PropertyKey, TStats extends ContextPipelineStats<TPhase>>(options: {
|
|
1010
1060
|
messages: AiMessage[];
|
|
@@ -1023,6 +1073,7 @@ declare abstract class ContextManagerBase<TConfig extends ContextManagerBaseConf
|
|
|
1023
1073
|
* AgentMessageOrchestrator 会按 request 自动处理,直接使用 ContextManager 的高级接入方才需要手动调用。
|
|
1024
1074
|
*/
|
|
1025
1075
|
updateTokenizerModelId(modelId: string | undefined): void;
|
|
1076
|
+
updateTokenCalibration(input: ContextManagerBaseOptions<TConfig, TRegistry>['tokenCalibration']): void;
|
|
1026
1077
|
}
|
|
1027
1078
|
|
|
1028
1079
|
/**
|
|
@@ -1059,6 +1110,10 @@ interface ContextBuildResult$1 {
|
|
|
1059
1110
|
events?: RuntimeEvent[];
|
|
1060
1111
|
/** ContextTrace:解释本次上下文构建如何保留/裁剪消息。 */
|
|
1061
1112
|
contextTrace?: ContextTrace;
|
|
1113
|
+
/** 构建期 token 估算快照,用于 host 把本地估算与响应后 actual usage 配对。 */
|
|
1114
|
+
tokenEstimate?: ContextBuildTokenEstimate;
|
|
1115
|
+
/** 构建期上下文分项 token 估算,用于 trace、账本与 host 面板后端。 */
|
|
1116
|
+
tokenComponents?: ContextTokenComponent[];
|
|
1062
1117
|
}
|
|
1063
1118
|
/**
|
|
1064
1119
|
* Agent专用智能上下文管理器
|
|
@@ -1080,6 +1135,10 @@ declare class AgentContextManager extends ContextManagerBase<AgentContextBuilder
|
|
|
1080
1135
|
providerRegistry?: ContextProviderRegistry$1;
|
|
1081
1136
|
tokenizer?: TokenizerPort;
|
|
1082
1137
|
tokenizerModelId?: string;
|
|
1138
|
+
tokenCounter?: TokenCounterPort;
|
|
1139
|
+
tokenRoute?: TokenRoute;
|
|
1140
|
+
remoteCount?: ContextManagerBaseOptions<AgentContextBuilderConfig, ContextProviderRegistry$1>['remoteCount'];
|
|
1141
|
+
tokenCalibration?: ContextManagerBaseOptions<AgentContextBuilderConfig, ContextProviderRegistry$1>['tokenCalibration'];
|
|
1083
1142
|
});
|
|
1084
1143
|
/**
|
|
1085
1144
|
* 主入口:为Agent构建智能上下文
|
|
@@ -1096,6 +1155,7 @@ declare class AgentContextManager extends ContextManagerBase<AgentContextBuilder
|
|
|
1096
1155
|
private getPhaseByProviderName;
|
|
1097
1156
|
private initializeBuildStats;
|
|
1098
1157
|
private buildFinalResult;
|
|
1158
|
+
private buildContextTokenEstimate;
|
|
1099
1159
|
/**
|
|
1100
1160
|
* 生成优化建议
|
|
1101
1161
|
*/
|
|
@@ -1474,10 +1534,24 @@ interface AgentOrchestratorOptions {
|
|
|
1474
1534
|
contextPolicy: AgentSpecContextPolicy | undefined;
|
|
1475
1535
|
contextBuilderConfig: Partial<AgentContextBuilderConfig>;
|
|
1476
1536
|
}) => ContextProviderRegistry$1;
|
|
1537
|
+
resolveTokenCalibration?: (params: {
|
|
1538
|
+
request: AgentProfileRequest;
|
|
1539
|
+
modelId: string;
|
|
1540
|
+
contextPolicy: AgentSpecContextPolicy | undefined;
|
|
1541
|
+
}) => {
|
|
1542
|
+
route?: TokenRoute;
|
|
1543
|
+
samples?: readonly TokenUsageCalibrationSample[];
|
|
1544
|
+
} | undefined;
|
|
1477
1545
|
taskResolver: AgentTaskResolver;
|
|
1478
1546
|
providerRegistry: ContextProviderRegistry$1;
|
|
1479
1547
|
fenceRegistry?: FenceRegistry;
|
|
1480
1548
|
tokenizer?: TokenizerPort;
|
|
1549
|
+
tokenCounter?: TokenCounterPort;
|
|
1550
|
+
resolveTokenRoute?: (params: {
|
|
1551
|
+
request: AgentProfileRequest;
|
|
1552
|
+
modelId: string;
|
|
1553
|
+
contextPolicy: AgentSpecContextPolicy | undefined;
|
|
1554
|
+
}) => TokenRoute | undefined;
|
|
1481
1555
|
}
|
|
1482
1556
|
interface AgentProcessingResult {
|
|
1483
1557
|
messages: AiMessage[];
|
|
@@ -1886,6 +1960,8 @@ interface ContextBuildResult {
|
|
|
1886
1960
|
};
|
|
1887
1961
|
/** 🔥 新增:Provider生成的运行时事件(如摘要事件) */
|
|
1888
1962
|
events?: RuntimeEvent[];
|
|
1963
|
+
/** 构建期 token 估算快照。Chat 目前无 route,host 可只读 token 数。 */
|
|
1964
|
+
tokenEstimate?: ContextBuildTokenEstimate;
|
|
1889
1965
|
}
|
|
1890
1966
|
/**
|
|
1891
1967
|
* 智能上下文管理器 - Provider编排器
|
|
@@ -1911,6 +1987,7 @@ declare class ContextManager extends ContextManagerBase<ContextBuilderConfig, Co
|
|
|
1911
1987
|
private getPhaseByProviderName;
|
|
1912
1988
|
private initializeBuildStats;
|
|
1913
1989
|
private buildFinalResult;
|
|
1990
|
+
private buildContextTokenEstimate;
|
|
1914
1991
|
/**
|
|
1915
1992
|
* 生成优化建议
|
|
1916
1993
|
*/
|
|
@@ -2224,4 +2301,4 @@ interface ChatGenerateRequestAdapterInput extends AgentProfileRequest {
|
|
|
2224
2301
|
*/
|
|
2225
2302
|
declare function buildGenerateRequestFromAgentRequest(request: ChatGenerateRequestAdapterInput, conversationHistory: AiMessage[]): GenerateRequest;
|
|
2226
2303
|
|
|
2227
|
-
export { AGENT_CONSTANTS, AGENT_CONTEXT_BUILDER_CONFIG, AISummaryGenerator, type AgentContextBuilderConfigOverrides, type AgentSpecExecutionOptions, type AgentSpecPreprocessorOptions, type AgentSpecProviderOptions, type AgentSpecRuntimeOptions, BaseContextProvider$1 as BaseContextProvider, BaseConversationalTask, BasePreprocessor$1 as BasePreprocessor, ContextProviderRegistry as ChatContextProviderRegistry, CoreContextProvider as ChatCoreContextProvider, ChatMessage, MessageOrchestrator as ChatMessageOrchestrator, type OrchestratorOptions as ChatOrchestratorOptions, type ChatTaskResolver, WorkingMemoryProvider as ChatWorkingMemoryProvider, ContextProviderRegistry$2 as ContextProviderRegistry, ContextTrace, ContextTraceCollector, CurrentTurnMessageAssembler, type CurrentTurnMessageAssemblerOptions, DEFAULT_MUST_KEEP_POLICY, type FenceDescriptor, type FenceInjection, type FenceLifetime, FenceLifetimePreprocessor, type FenceLifetimePreprocessorOptions, type FenceLlmRole, type FencePlacement, type FenceRegistry, GenerateRequest, GenerateResponse, type HistoryPurificationConfig, HistoryPurificationPreprocessor, type IChatTask, type IContextProvider$1 as IContextProvider, type IPreprocessor$1 as IPreprocessor, type LlmMessage, type MergeContextPolicyParams, type MessageFormatOptions, type MessageFormatterOptions, MessageProcessingState, type MustKeepPolicy, type MustKeepTruncationRule, type NativeToolCallingMessage, type PreprocessorContext$1 as PreprocessorContext, type PreprocessorResult$1 as PreprocessorResult, type ProviderContext$1 as ProviderContext, ProviderResult, SummarizationCallbacks, SummarizationCandidateSelector, type SummarizationOptions, SummarizationProvider, SummarizationStateUtils, SummarizationTrigger, type ToolSummaryProvider, config as agentConfig, index$5 as agentContext, contracts as agentContracts, index$3 as agentOrchestration, index$4 as agentPreprocessors, agentSpecToContextBuilderConfig, agentSpecToRuntimeOptions, index$2 as agentTasks, index$1 as agentTools, index as agentUtils, aiMessageToChatMessage, buildGenerateRequestFromAgentRequest, chatMessageToAiMessage, contextPolicyToContextBuilderConfig, contextPolicyToExecutionOptions, contextPolicyToMustKeepPolicy, contextPolicyToPreprocessorOptions, contextPolicyToProviderOptions, contextPolicyToRuntimeOptions, contextPolicyToSystemReminderOptions, convertEventToChatMessage, convertEventsToChatMessages, createFenceRegistry, createMessageFormatter, findMatchingTruncationRule, formatAgentLlmMessages, getDefaultTokenConfig, mergeContextPolicy, messageFormatter };
|
|
2304
|
+
export { AGENT_CONSTANTS, AGENT_CONTEXT_BUILDER_CONFIG, AISummaryGenerator, type AgentContextBuilderConfigOverrides, type AgentSpecExecutionOptions, type AgentSpecPreprocessorOptions, type AgentSpecProviderOptions, type AgentSpecRuntimeOptions, BaseContextProvider$1 as BaseContextProvider, BaseConversationalTask, BasePreprocessor$1 as BasePreprocessor, ContextProviderRegistry as ChatContextProviderRegistry, CoreContextProvider as ChatCoreContextProvider, ChatMessage, MessageOrchestrator as ChatMessageOrchestrator, type OrchestratorOptions as ChatOrchestratorOptions, type ChatTaskResolver, WorkingMemoryProvider as ChatWorkingMemoryProvider, ContextProviderRegistry$2 as ContextProviderRegistry, ContextTrace, ContextTraceCollector, CurrentTurnMessageAssembler, type CurrentTurnMessageAssemblerOptions, DEFAULT_MUST_KEEP_POLICY, type FenceDescriptor, type FenceInjection, type FenceLifetime, FenceLifetimePreprocessor, type FenceLifetimePreprocessorOptions, type FenceLlmRole, type FencePlacement, type FenceRegistry, GenerateRequest, GenerateResponse, type HistoryPurificationConfig, HistoryPurificationPreprocessor, type IChatTask, type IContextProvider$1 as IContextProvider, type IPreprocessor$1 as IPreprocessor, type LlmMessage, type MergeContextPolicyParams, type MessageFormatOptions, type MessageFormatterOptions, MessageProcessingState, type MustKeepPolicy, type MustKeepTruncationRule, type NativeToolCallingMessage, type PreprocessorContext$1 as PreprocessorContext, type PreprocessorResult$1 as PreprocessorResult, type ProviderContext$1 as ProviderContext, ProviderResult, RemoteTokenCountTrace, SummarizationCallbacks, SummarizationCandidateSelector, type SummarizationOptions, SummarizationProvider, SummarizationStateUtils, SummarizationTrigger, type ToolSummaryProvider, config as agentConfig, index$5 as agentContext, contracts as agentContracts, index$3 as agentOrchestration, index$4 as agentPreprocessors, agentSpecToContextBuilderConfig, agentSpecToRuntimeOptions, index$2 as agentTasks, index$1 as agentTools, index as agentUtils, aiMessageToChatMessage, buildGenerateRequestFromAgentRequest, chatMessageToAiMessage, contextPolicyToContextBuilderConfig, contextPolicyToExecutionOptions, contextPolicyToMustKeepPolicy, contextPolicyToPreprocessorOptions, contextPolicyToProviderOptions, contextPolicyToRuntimeOptions, contextPolicyToSystemReminderOptions, convertEventToChatMessage, convertEventsToChatMessages, createFenceRegistry, createMessageFormatter, findMatchingTruncationRule, formatAgentLlmMessages, getDefaultTokenConfig, mergeContextPolicy, messageFormatter };
|