@librechat/agents 3.8.0 → 3.8.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/dist/cjs/agents/AgentContext.cjs +13 -3
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +176 -55
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +16 -6
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/hitl/approvalReview.cjs +89 -0
- package/dist/cjs/hitl/approvalReview.cjs.map +1 -0
- package/dist/cjs/langfuse.cjs +42 -0
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +42 -0
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/langfuseTraceShaping.cjs +7 -1
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +6 -10
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +2 -7
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/contextPressureMeter.cjs +51 -10
- package/dist/cjs/llm/contextPressureMeter.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +1 -1
- package/dist/cjs/llm/invoke.cjs +2 -2
- package/dist/cjs/llm/openai/index.cjs +4 -3
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +5 -4
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/preempt.cjs +3 -2
- package/dist/cjs/llm/preempt.cjs.map +1 -1
- package/dist/cjs/llm/prepareProviderRequest.cjs +9 -7
- package/dist/cjs/llm/prepareProviderRequest.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs +1 -1
- package/dist/cjs/main.cjs +14 -8
- package/dist/cjs/messages/alternation.cjs +1 -5
- package/dist/cjs/messages/alternation.cjs.map +1 -1
- package/dist/cjs/messages/budget.cjs +206 -7
- package/dist/cjs/messages/budget.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +3 -9
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +26 -38
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +132 -43
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/index.cjs +2 -0
- package/dist/cjs/messages/prune.cjs +14 -9
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/reasoningTypes.cjs +21 -0
- package/dist/cjs/messages/reasoningTypes.cjs.map +1 -0
- package/dist/cjs/messages/recency.cjs +15 -94
- package/dist/cjs/messages/recency.cjs.map +1 -1
- package/dist/cjs/messages/toolHistoryProjection.cjs +243 -0
- package/dist/cjs/messages/toolHistoryProjection.cjs.map +1 -0
- package/dist/cjs/messages/toolResultTypes.cjs +145 -4
- package/dist/cjs/messages/toolResultTypes.cjs.map +1 -1
- package/dist/cjs/run.cjs +22 -10
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +7 -5
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/session/JsonlSessionStore.cjs +3 -0
- package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -1
- package/dist/cjs/session/index.cjs +1 -1
- package/dist/cjs/session/sessionProjection.cjs +75 -0
- package/dist/cjs/session/sessionProjection.cjs.map +1 -0
- package/dist/cjs/stream.cjs +20 -19
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/index.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +19 -9
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/summarization/shared.cjs +9 -0
- package/dist/cjs/summarization/shared.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +256 -84
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +1 -1
- package/dist/cjs/tools/local/LocalCodingTools.cjs +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +24 -9
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs +2 -0
- package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
- package/dist/cjs/tools/toolBatchReplay.cjs +187 -0
- package/dist/cjs/tools/toolBatchReplay.cjs.map +1 -0
- package/dist/cjs/tools/toolOutputReferences.cjs +12 -0
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/cjs/types/hitl.cjs +4 -0
- package/dist/cjs/types/hitl.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +13 -0
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +105 -0
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +13 -3
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +178 -57
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +16 -6
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/hitl/approvalReview.mjs +83 -0
- package/dist/esm/hitl/approvalReview.mjs.map +1 -0
- package/dist/esm/langfuse.mjs +43 -2
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +41 -1
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/langfuseTraceShaping.mjs +7 -1
- package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +6 -10
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +2 -7
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/contextPressureMeter.mjs +52 -11
- package/dist/esm/llm/contextPressureMeter.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +1 -1
- package/dist/esm/llm/invoke.mjs +2 -2
- package/dist/esm/llm/openai/index.mjs +2 -1
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +5 -4
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/preempt.mjs +2 -1
- package/dist/esm/llm/preempt.mjs.map +1 -1
- package/dist/esm/llm/prepareProviderRequest.mjs +9 -7
- package/dist/esm/llm/prepareProviderRequest.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs +1 -1
- package/dist/esm/main.mjs +13 -10
- package/dist/esm/messages/alternation.mjs +2 -6
- package/dist/esm/messages/alternation.mjs.map +1 -1
- package/dist/esm/messages/budget.mjs +206 -8
- package/dist/esm/messages/budget.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +3 -9
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +24 -34
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +133 -44
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/index.mjs +2 -0
- package/dist/esm/messages/prune.mjs +14 -9
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/reasoningTypes.mjs +20 -0
- package/dist/esm/messages/reasoningTypes.mjs.map +1 -0
- package/dist/esm/messages/recency.mjs +16 -95
- package/dist/esm/messages/recency.mjs.map +1 -1
- package/dist/esm/messages/toolHistoryProjection.mjs +237 -0
- package/dist/esm/messages/toolHistoryProjection.mjs.map +1 -0
- package/dist/esm/messages/toolResultTypes.mjs +141 -4
- package/dist/esm/messages/toolResultTypes.mjs.map +1 -1
- package/dist/esm/run.mjs +23 -11
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +7 -5
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/session/JsonlSessionStore.mjs +3 -0
- package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
- package/dist/esm/session/index.mjs +1 -1
- package/dist/esm/session/sessionProjection.mjs +72 -0
- package/dist/esm/session/sessionProjection.mjs.map +1 -0
- package/dist/esm/stream.mjs +17 -16
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/index.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +20 -10
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/summarization/shared.mjs +9 -1
- package/dist/esm/summarization/shared.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +256 -84
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +24 -9
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
- package/dist/esm/tools/toolBatchReplay.mjs +176 -0
- package/dist/esm/tools/toolBatchReplay.mjs.map +1 -0
- package/dist/esm/tools/toolOutputReferences.mjs +12 -0
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/esm/types/hitl.mjs +4 -1
- package/dist/esm/types/hitl.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +13 -0
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +105 -1
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +13 -1
- package/dist/types/graphs/Graph.d.ts +27 -0
- package/dist/types/hitl/approvalReview.d.ts +32 -0
- package/dist/types/hooks/types.d.ts +4 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/langfuse.d.ts +5 -0
- package/dist/types/langfuseToolOutputTracing.d.ts +2 -0
- package/dist/types/llm/contextPressureMeter.d.ts +2 -1
- package/dist/types/llm/prepareProviderRequest.d.ts +7 -1
- package/dist/types/messages/budget.d.ts +15 -10
- package/dist/types/messages/core.d.ts +8 -17
- package/dist/types/messages/format.d.ts +3 -2
- package/dist/types/messages/index.d.ts +1 -1
- package/dist/types/messages/prune.d.ts +1 -1
- package/dist/types/messages/reasoningTypes.d.ts +7 -0
- package/dist/types/messages/recency.d.ts +3 -0
- package/dist/types/messages/toolHistoryProjection.d.ts +65 -0
- package/dist/types/messages/toolResultTypes.d.ts +31 -1
- package/dist/types/session/sessionProjection.d.ts +10 -0
- package/dist/types/summarization/index.d.ts +2 -1
- package/dist/types/summarization/node.d.ts +1 -0
- package/dist/types/summarization/shared.d.ts +12 -0
- package/dist/types/tools/ToolNode.d.ts +12 -6
- package/dist/types/tools/subagent/SubagentReplay.d.ts +2 -0
- package/dist/types/tools/toolBatchReplay.d.ts +54 -0
- package/dist/types/tools/toolOutputReferences.d.ts +2 -0
- package/dist/types/types/graph.d.ts +20 -0
- package/dist/types/types/run.d.ts +4 -0
- package/dist/types/types/summarize.d.ts +4 -1
- package/dist/types/utils/tokens.d.ts +2 -1
- package/package.json +1 -1
- package/src/agents/AgentContext.ts +34 -3
- package/src/graphs/Graph.ts +465 -147
- package/src/graphs/MultiAgentGraph.ts +28 -6
- package/src/hitl/approvalReview.ts +209 -0
- package/src/hooks/types.ts +4 -1
- package/src/index.ts +1 -0
- package/src/langfuse.ts +67 -9
- package/src/langfuseToolOutputTracing.ts +91 -0
- package/src/langfuseTraceShaping.ts +17 -4
- package/src/llm/anthropic/utils/message_inputs.ts +5 -10
- package/src/llm/bedrock/utils/message_inputs.ts +2 -8
- package/src/llm/contextPressureMeter.ts +80 -12
- package/src/llm/openai/utils/index.ts +5 -4
- package/src/llm/prepareProviderRequest.ts +21 -16
- package/src/messages/alternation.ts +2 -15
- package/src/messages/budget.ts +439 -23
- package/src/messages/cache.ts +8 -9
- package/src/messages/core.ts +65 -95
- package/src/messages/format.ts +262 -78
- package/src/messages/index.ts +1 -1
- package/src/messages/prune.ts +31 -12
- package/src/messages/reasoningTypes.ts +23 -0
- package/src/messages/recency.ts +35 -179
- package/src/messages/toolHistoryProjection.ts +460 -0
- package/src/messages/toolResultTypes.ts +331 -100
- package/src/run.ts +44 -22
- package/src/session/AgentSession.ts +33 -16
- package/src/session/JsonlSessionStore.ts +6 -0
- package/src/session/sessionProjection.ts +126 -0
- package/src/stream.ts +14 -19
- package/src/summarization/index.ts +2 -0
- package/src/summarization/node.ts +62 -13
- package/src/summarization/shared.ts +23 -0
- package/src/tools/ToolNode.ts +518 -184
- package/src/tools/subagent/SubagentExecutor.ts +35 -6
- package/src/tools/subagent/SubagentReplay.ts +2 -2
- package/src/tools/toolBatchReplay.ts +395 -0
- package/src/tools/toolOutputReferences.ts +16 -0
- package/src/types/graph.ts +20 -0
- package/src/types/run.ts +4 -0
- package/src/types/summarize.ts +4 -1
- package/src/utils/events.ts +19 -0
- package/src/utils/tokens.ts +183 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
2
|
+
import type { ToolApprovalInterruptPayload, ToolApprovalRequest, ToolApprovalReviewConfig } from '@/types/hitl';
|
|
3
|
+
/**
|
|
4
|
+
* Private resume-only config entry populated from the checkpointed interrupt.
|
|
5
|
+
* Hosts must never need to construct or inspect this value.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TOOL_APPROVAL_REVIEW_CONFIG_KEY = "__librechat_tool_approval_review";
|
|
8
|
+
export interface ToolApprovalReviewEvidence {
|
|
9
|
+
interruptId: string;
|
|
10
|
+
payload: ToolApprovalInterruptPayload;
|
|
11
|
+
owner?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ReviewedToolApproval {
|
|
14
|
+
request: ToolApprovalRequest;
|
|
15
|
+
reviewConfig: ToolApprovalReviewConfig;
|
|
16
|
+
}
|
|
17
|
+
/** Detach approval payloads from host- or transport-owned object graphs. */
|
|
18
|
+
export declare function cloneToolApprovalInterruptPayload<T>(payload: T): T;
|
|
19
|
+
/** Build trusted review evidence from the interrupt restored by `Run`. */
|
|
20
|
+
export declare function createToolApprovalReviewEvidence(interruptId: string | undefined, payload: unknown, owner?: string): ToolApprovalReviewEvidence | undefined;
|
|
21
|
+
/** Read only well-shaped evidence from a ToolNode's runnable config. */
|
|
22
|
+
export declare function getToolApprovalReviewEvidence(config: RunnableConfig, owner?: string): ToolApprovalReviewEvidence | undefined;
|
|
23
|
+
export declare function getReviewedToolApproval(payload: ToolApprovalInterruptPayload | undefined, toolCallId: string | undefined): ReviewedToolApproval | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Bind a resume decision to the exact proposal the reviewer saw. Description
|
|
26
|
+
* text is deliberately excluded: it explains policy but cannot change the
|
|
27
|
+
* side effect. Tool identity, normalized arguments and available decisions
|
|
28
|
+
* are execution-authoritative.
|
|
29
|
+
*/
|
|
30
|
+
export declare function toolApprovalProposalMatches(current: ReviewedToolApproval, reviewed: ReviewedToolApproval): boolean;
|
|
31
|
+
/** Preserve batch order as part of the decision-to-request binding. */
|
|
32
|
+
export declare function toolApprovalPayloadMatches(current: ToolApprovalInterruptPayload, reviewed: ToolApprovalInterruptPayload): boolean;
|
|
@@ -213,9 +213,11 @@ export interface PreCompactHookInput extends BaseHookInput {
|
|
|
213
213
|
/**
|
|
214
214
|
* What triggered compaction. Matches `SummarizationTrigger.type` from the
|
|
215
215
|
* agent's summarization config. `'default'` means no trigger was
|
|
216
|
-
* configured and compaction fired because messages were pruned
|
|
216
|
+
* configured and compaction fired because messages were pruned;
|
|
217
|
+
* `'manual'` means the host asked for the summary outright and no trigger
|
|
218
|
+
* was evaluated.
|
|
217
219
|
*/
|
|
218
|
-
trigger: 'token_ratio' | 'remaining_tokens' | 'messages_to_refine' | 'default' | (string & {});
|
|
220
|
+
trigger: 'token_ratio' | 'remaining_tokens' | 'messages_to_refine' | 'default' | 'manual' | (string & {});
|
|
219
221
|
}
|
|
220
222
|
export interface PostCompactHookInput extends BaseHookInput {
|
|
221
223
|
hook_event_name: 'PostCompact';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './run';
|
|
|
2
2
|
export * from './stream';
|
|
3
3
|
export * from './events';
|
|
4
4
|
export * from './messages';
|
|
5
|
+
export { LANGFUSE_OBSERVATION_METADATA_ARTIFACT_KEY } from './langfuseToolOutputTracing';
|
|
5
6
|
export * from './graphs';
|
|
6
7
|
export * from './agents/projection';
|
|
7
8
|
export * from './summarization';
|
package/dist/types/langfuse.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CallbackHandler } from '@langfuse/langchain';
|
|
2
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
2
3
|
import type { SpanContext } from '@opentelemetry/api';
|
|
3
4
|
import type { ResolvedLangfuseToolOutputTracingConfig } from '@/langfuseRuntimeContext';
|
|
4
5
|
import type * as t from '@/types';
|
|
@@ -72,4 +73,8 @@ export declare function hasExplicitLangfuseConfig(contexts: Iterable<{
|
|
|
72
73
|
langfuse?: t.LangfuseConfig;
|
|
73
74
|
}>): boolean;
|
|
74
75
|
export declare function isLangfuseCallbackHandler(value: unknown): boolean;
|
|
76
|
+
/** Host results have passed host output filters. Record only reserved metadata,
|
|
77
|
+
* not arguments, rows, errors, or attachments. These completion observations
|
|
78
|
+
* do not measure tool latency; execution timing belongs in the metadata. */
|
|
79
|
+
export declare function traceHostToolResults(request: t.ToolExecuteBatchRequest, results: t.ToolExecuteResult[], config?: RunnableConfig): Promise<void>;
|
|
75
80
|
export declare function disposeLangfuseHandler(value: unknown): Promise<void>;
|
|
@@ -4,11 +4,13 @@ import type { ResolvedLangfuseToolOutputTracingConfig } from '@/langfuseRuntimeC
|
|
|
4
4
|
import type * as t from '@/types';
|
|
5
5
|
import { LANGFUSE_TOOL_OUTPUT_REDACTION_TEXT, resolveLangfuseConfig } from '@/langfuseConfig';
|
|
6
6
|
export { LANGFUSE_TOOL_OUTPUT_REDACTION_TEXT, resolveLangfuseConfig };
|
|
7
|
+
export declare const LANGFUSE_OBSERVATION_METADATA_ARTIFACT_KEY = "librechatLangfuseObservationMetadata";
|
|
7
8
|
/** Whether a tool's outputs are excluded from tracing (global disable or
|
|
8
9
|
* `redactedToolNames` match). Exported for the activity-label prompt
|
|
9
10
|
* builder, whose prompt becomes Langfuse generation input. */
|
|
10
11
|
export declare function shouldRedactTool(toolName: string | undefined, config: ResolvedLangfuseToolOutputTracingConfig): boolean;
|
|
11
12
|
export declare function classifyLangfuseToolNodeSpan(span: ReadableSpan): void;
|
|
13
|
+
export declare function getToolObservationMetadata(artifact: unknown): Record<string, string | number | boolean>;
|
|
12
14
|
export declare function redactLangfuseSpanToolOutputs(span: ReadableSpan, config: ResolvedLangfuseToolOutputTracingConfig): void;
|
|
13
15
|
export declare function prepareLangfuseSpanForExport(span: ReadableSpan, config?: ResolvedLangfuseToolOutputTracingConfig): void;
|
|
14
16
|
export declare function createLangfuseSpanProcessor(params?: LangfuseSpanProcessorParams, runLangfuse?: t.LangfuseConfig, agentLangfuse?: t.LangfuseConfig): SpanProcessor;
|
|
@@ -8,6 +8,7 @@ interface ContextPressureUsage {
|
|
|
8
8
|
calibrationRatio?: number;
|
|
9
9
|
}
|
|
10
10
|
interface ContextPressureMeterParams {
|
|
11
|
+
provider?: t.ProviderName;
|
|
11
12
|
tokenCounter?: t.TokenCounter;
|
|
12
13
|
tokenCountCache?: ExactTokenCountCache;
|
|
13
14
|
sourceMessages: BaseMessage[];
|
|
@@ -32,5 +33,5 @@ export interface ExactTokenCountCache {
|
|
|
32
33
|
/** Reuses exact counts only while every token-relevant stable field matches. */
|
|
33
34
|
export declare function createExactTokenCountCache(tokenCounter: t.TokenCounter): ExactTokenCountCache;
|
|
34
35
|
/** Measures repeated provider projections while tokenizing each message object once. */
|
|
35
|
-
export declare function createContextPressureMeter({ tokenCounter, tokenCountCache, sourceMessages, retainedMessages, indexTokenCountMap, contextUsage, instructionTokens, calibrationRatio, }: ContextPressureMeterParams): ContextPressureMeter;
|
|
36
|
+
export declare function createContextPressureMeter({ provider, tokenCounter, tokenCountCache, sourceMessages, retainedMessages, indexTokenCountMap, contextUsage, instructionTokens, calibrationRatio, }: ContextPressureMeterParams): ContextPressureMeter;
|
|
36
37
|
export {};
|
|
@@ -2,6 +2,7 @@ import type { BaseMessage } from '@langchain/core/messages';
|
|
|
2
2
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
3
3
|
import type { ToolOutputReferenceRegistry } from '@/tools/toolOutputReferences';
|
|
4
4
|
import type * as t from '@/types';
|
|
5
|
+
import type { ToolHistoryPreparation } from '@/messages/toolHistoryProjection';
|
|
5
6
|
declare const preparedProviderRequestBrand: unique symbol;
|
|
6
7
|
export type ProviderMessageProjectionMode = 'chat-messages' | 'openai-responses';
|
|
7
8
|
export interface ProviderPayloadMeasurement {
|
|
@@ -10,6 +11,9 @@ export interface ProviderPayloadMeasurement {
|
|
|
10
11
|
readonly availableMessageTokens?: number;
|
|
11
12
|
readonly contextBudget?: number;
|
|
12
13
|
readonly effectiveInstructionTokens?: number;
|
|
14
|
+
readonly toolMessageTokens?: number;
|
|
15
|
+
readonly toolMessageTokenCounts?: Record<string, number>;
|
|
16
|
+
readonly toolMessageUsageError?: Error;
|
|
13
17
|
}
|
|
14
18
|
export interface PreparedProviderRequest {
|
|
15
19
|
readonly model: t.ChatModel;
|
|
@@ -32,6 +36,7 @@ export interface PrepareProviderRequestParams {
|
|
|
32
36
|
config?: RunnableConfig;
|
|
33
37
|
maxToolResultChars?: number;
|
|
34
38
|
measure?: (messages: BaseMessage[]) => ProviderPayloadMeasurement;
|
|
39
|
+
toolHistory?: ToolHistoryPreparation;
|
|
35
40
|
}
|
|
36
41
|
export declare function usesNativeOpenAIResponses(model: t.ChatModel, provider: t.ProviderName, callOptions?: unknown): boolean;
|
|
37
42
|
interface ProjectMessagesForProviderParams {
|
|
@@ -40,6 +45,7 @@ interface ProjectMessagesForProviderParams {
|
|
|
40
45
|
provider: t.ProviderName;
|
|
41
46
|
maxToolResultChars?: number;
|
|
42
47
|
callOptions?: unknown;
|
|
48
|
+
toolHistory?: ToolHistoryPreparation;
|
|
43
49
|
}
|
|
44
50
|
/** Produces the provider-facing representation before adapter serialization. */
|
|
45
51
|
export declare function projectMessagesForProvider(params: ProjectMessagesForProviderParams): BaseMessage[];
|
|
@@ -49,6 +55,6 @@ export declare function resolveServingModelId(model: unknown): string | undefine
|
|
|
49
55
|
* Finalizes one provider request and measures the exact message array that
|
|
50
56
|
* will be passed to LangChain. Source messages remain untouched.
|
|
51
57
|
*/
|
|
52
|
-
export declare function prepareProviderRequest({ model, messages, provider, context, config, maxToolResultChars, measure, }: PrepareProviderRequestParams): PreparedProviderRequest;
|
|
58
|
+
export declare function prepareProviderRequest({ model, messages, provider, context, config, maxToolResultChars, measure, toolHistory, }: PrepareProviderRequestParams): PreparedProviderRequest;
|
|
53
59
|
export declare function assertPreparedProviderRequestFor(request: PreparedProviderRequest, model: t.ChatModel, provider: t.ProviderName, config?: RunnableConfig): void;
|
|
54
60
|
export {};
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
1
3
|
import type * as t from '@/types';
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
/** Counts retained tool exchanges without serializing arguments or result content. */
|
|
5
|
+
export interface ToolMessageUsageAccumulator {
|
|
6
|
+
add(message: BaseMessage, getRawTokens: () => number): void;
|
|
7
|
+
finish(calibrationRatio?: number): Pick<t.TokenBudgetBreakdown, 'toolMessageTokens' | 'toolMessageTokenCounts'>;
|
|
8
|
+
}
|
|
9
|
+
/** Accumulates tool-share attribution while its caller walks a provider payload. */
|
|
10
|
+
export declare function createToolMessageUsageAccumulator(provider?: t.ProviderName): ToolMessageUsageAccumulator;
|
|
11
|
+
/** Reconciles derived budget fields and, when supplied, the retained tool share.
|
|
12
|
+
* The index map is keyed before pruning, so it cannot index the retained context.
|
|
13
|
+
* Callers may pass the existing exact token cache's counter, never a stale index lookup.
|
|
14
|
+
* Runs on the live pre-invoke path, so an unusable count drops the tool share
|
|
15
|
+
* (warned once) instead of failing the model call it only measures. */
|
|
16
|
+
export declare function syncBudgetDerivedFields(usage: t.ContextUsageEvent, context?: readonly BaseMessage[], tokenCounter?: t.TokenCounter, config?: RunnableConfig, provider?: t.ProviderName, toolMessageUsageError?: Error): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AIMessage, BaseMessage, ToolMessage, HumanMessage, AIMessageChunk } from '@langchain/core/messages';
|
|
2
2
|
import type * as t from '@/types';
|
|
3
|
+
import type { ToolHistoryPreparation } from './toolHistoryProjection';
|
|
3
4
|
export declare function getConverseOverrideMessage({ userMessage, lastMessageX, lastMessageY, }: {
|
|
4
5
|
userMessage: string[];
|
|
5
6
|
lastMessageX: AIMessageChunk | null;
|
|
@@ -8,8 +9,7 @@ export declare function getConverseOverrideMessage({ userMessage, lastMessageX,
|
|
|
8
9
|
/**
|
|
9
10
|
* True when a content block is a provider reasoning block: Anthropic
|
|
10
11
|
* `thinking` / `redacted_thinking`, Google `reasoning`, Bedrock
|
|
11
|
-
* `reasoning_content`, and
|
|
12
|
-
* those names.
|
|
12
|
+
* `reasoning_content`, LibreChat `think`, and their known streamed variants.
|
|
13
13
|
*
|
|
14
14
|
* Shared rather than re-derived because two very different readers must agree
|
|
15
15
|
* on the same answer: the stream classifier, which decides what the host has
|
|
@@ -17,30 +17,22 @@ export declare function getConverseOverrideMessage({ userMessage, lastMessageX,
|
|
|
17
17
|
* holds anything worth keeping. A turn the host renders as thinking-only must
|
|
18
18
|
* never look like a visible answer to the gate.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* carries the `reasoning` prefix.
|
|
20
|
+
* Exact matching prevents unrelated custom block types that happen to share a
|
|
21
|
+
* prefix from being silently classified as hidden reasoning.
|
|
23
22
|
*/
|
|
24
|
-
export
|
|
25
|
-
type?: string;
|
|
26
|
-
}): boolean;
|
|
23
|
+
export { isReasoningContentBlock } from './reasoningTypes';
|
|
27
24
|
export declare function modifyDeltaProperties(provider: t.ProviderName, obj?: AIMessageChunk): AIMessageChunk | undefined;
|
|
28
25
|
export declare function formatAnthropicMessage(message: AIMessageChunk): AIMessage;
|
|
29
26
|
export declare function convertMessagesToContent(messages: BaseMessage[]): t.MessageContentComplex[];
|
|
30
27
|
type ResponsesReplayProjection = 'fallback' | 'native';
|
|
31
|
-
export
|
|
28
|
+
export { OPENAI_RESPONSES_REPLAY_POSITIONS_KEY } from './toolHistoryProjection';
|
|
32
29
|
/** Reasoning item currently streaming, so a terminal ciphertext seals against its own id. */
|
|
33
30
|
export declare const OPENAI_RESPONSES_ACTIVE_REASONING_ID_KEY = "__openai_responses_active_reasoning_id__";
|
|
34
|
-
export type ResponsesReplayPosition
|
|
35
|
-
contentIndex?: number;
|
|
36
|
-
itemId: string;
|
|
37
|
-
kind: 'message' | 'output' | 'reasoning' | 'text';
|
|
38
|
-
outputIndex: number;
|
|
39
|
-
};
|
|
31
|
+
export type { ResponsesReplayPosition } from './toolHistoryProjection';
|
|
40
32
|
/** Drops incomplete streamed text blocks before provider-facing tool shaping. */
|
|
41
33
|
export declare function dropIncompleteToolStreamContent(content: AIMessage['content']): AIMessage['content'];
|
|
42
34
|
/** Applies sealed-Responses safety and drops incomplete streamed text input. */
|
|
43
|
-
export declare function projectToolStreamContentForProvider(messages: BaseMessage[], responsesReplayProjection?: ResponsesReplayProjection, maxChars?: number): BaseMessage[];
|
|
35
|
+
export declare function projectToolStreamContentForProvider(messages: BaseMessage[], responsesReplayProjection?: ResponsesReplayProjection, maxChars?: number, preparation?: ToolHistoryPreparation): BaseMessage[];
|
|
44
36
|
/** Projects OpenAI-compatible tool content without changing parsed call parents. */
|
|
45
37
|
export declare function projectOpenAIToolMessageContent(messages: BaseMessage[], maxChars?: number): BaseMessage[];
|
|
46
38
|
/** Projects an actual OpenAI-compatible Chat attempt and removes cache metadata. */
|
|
@@ -76,4 +68,3 @@ export declare function formatArtifactPayload(messages: BaseMessage[]): void;
|
|
|
76
68
|
export declare function findLastIndex<T>(array: T[], predicate: (value: T) => boolean): number;
|
|
77
69
|
/** Whether message content carries non-whitespace text in any text block. */
|
|
78
70
|
export declare function hasNonEmptyTextContent(content: BaseMessage['content']): boolean;
|
|
79
|
-
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AIMessage, ToolMessage, BaseMessage, HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
2
|
import type { MessageContentImageUrl } from '@langchain/core/messages';
|
|
3
3
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
|
+
import type { ToolHistoryPreparation } from './toolHistoryProjection';
|
|
4
5
|
import type { MessageContentComplex, TPayload, ProviderName, CompactionSemanticIndex, CompactionSemanticIndexSnapshot } from '@/types';
|
|
5
6
|
import { Providers } from '@/common';
|
|
6
7
|
interface MediaMessageParams {
|
|
@@ -211,7 +212,7 @@ export declare function compactSyntheticProviderContextMessage(message: HumanMes
|
|
|
211
212
|
* compatibility for callers that don't yet pass the boundary.
|
|
212
213
|
* @returns The messages array with tool sequences converted to buffer strings if necessary
|
|
213
214
|
*/
|
|
214
|
-
export declare function ensureThinkingBlockInMessages(messages: BaseMessage[], _provider: ProviderName, config?: RunnableConfig, runStartIndex?: number): BaseMessage[];
|
|
215
|
+
export declare function ensureThinkingBlockInMessages(messages: BaseMessage[], _provider: ProviderName, config?: RunnableConfig, runStartIndex?: number, preparation?: ToolHistoryPreparation): BaseMessage[];
|
|
215
216
|
/**
|
|
216
217
|
* Folds tool_use / tool_result content into plain text for an agent that binds
|
|
217
218
|
* no tools.
|
|
@@ -233,5 +234,5 @@ export declare function ensureThinkingBlockInMessages(messages: BaseMessage[], _
|
|
|
233
234
|
* original array is returned unchanged when it holds no tool content (the common
|
|
234
235
|
* fresh-tool-less-agent case).
|
|
235
236
|
*/
|
|
236
|
-
export declare function foldToolBlocksForToollessAgent(messages: BaseMessage[], config?: RunnableConfig): BaseMessage[];
|
|
237
|
+
export declare function foldToolBlocksForToollessAgent(messages: BaseMessage[], config?: RunnableConfig, preserveNativeOpenAIResponses?: boolean, preparation?: ToolHistoryPreparation): BaseMessage[];
|
|
237
238
|
export {};
|
|
@@ -261,7 +261,7 @@ export declare function projectToolCallInputs(messages: BaseMessage[], maxInputC
|
|
|
261
261
|
* Derives provider-safe tool history in one pass by dropping incomplete stream
|
|
262
262
|
* content and bounding every provider-consumed tool-call input representation.
|
|
263
263
|
*/
|
|
264
|
-
export declare function projectToolMessagesForProvider(messages: BaseMessage[], maxInputChars: number): BaseMessage[];
|
|
264
|
+
export declare function projectToolMessagesForProvider(messages: BaseMessage[], maxInputChars: number, provider?: ProviderName): BaseMessage[];
|
|
265
265
|
export declare function preFlightTruncateToolCallInputs(params: {
|
|
266
266
|
messages: BaseMessage[];
|
|
267
267
|
maxContextTokens: number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Identifies every persisted or streamed reasoning content-block shape. */
|
|
2
|
+
export declare function isReasoningContentBlock(block: {
|
|
3
|
+
type?: unknown;
|
|
4
|
+
}): boolean;
|
|
5
|
+
export declare function isAnthropicThinkingContentBlock(block: {
|
|
6
|
+
type?: unknown;
|
|
7
|
+
}): boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import type { ProviderName } from '@/types/llm';
|
|
2
3
|
export declare const DEFAULT_RETAIN_RECENT_TURNS = 2;
|
|
3
4
|
export declare const DEFAULT_INTRA_TURN_RETAIN_RATIO = 0.16;
|
|
4
5
|
/**
|
|
@@ -6,6 +7,8 @@ export declare const DEFAULT_INTRA_TURN_RETAIN_RATIO = 0.16;
|
|
|
6
7
|
* and a tail (to be preserved verbatim).
|
|
7
8
|
*/
|
|
8
9
|
export interface RecencyWindowOptions {
|
|
10
|
+
/** Serving provider used to interpret generic `ChatMessage` roles. */
|
|
11
|
+
provider?: ProviderName;
|
|
9
12
|
/**
|
|
10
13
|
* Maximum number of recent user-led turns to keep in the tail. A "turn"
|
|
11
14
|
* begins at a user-authored HumanMessage and includes every following
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { BaseMessage, ContentBlock } from '@langchain/core/messages';
|
|
2
|
+
interface ToolHistoryCallMirror {
|
|
3
|
+
readonly name?: string;
|
|
4
|
+
readonly arguments: string;
|
|
5
|
+
}
|
|
6
|
+
export type ToolHistoryCallMirrors = Map<string, ToolHistoryCallMirror | null>;
|
|
7
|
+
/** Only complete argument representations can establish that a call is a mirror. */
|
|
8
|
+
export declare function recordToolHistoryCallMirror(mirrors: ToolHistoryCallMirrors, block: unknown): void;
|
|
9
|
+
export declare function isToolHistoryCallMirror(mirrors: ToolHistoryCallMirrors | undefined, id: unknown, name: unknown, args: unknown): boolean;
|
|
10
|
+
export declare const OPENAI_RESPONSES_REPLAY_POSITIONS_KEY = "__openai_responses_replay_positions__";
|
|
11
|
+
export type ResponsesReplayPosition = {
|
|
12
|
+
contentIndex?: number;
|
|
13
|
+
itemId: string;
|
|
14
|
+
kind: 'message' | 'output' | 'reasoning' | 'text';
|
|
15
|
+
outputIndex: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function isResponsesReplayPosition(value: unknown): value is ResponsesReplayPosition;
|
|
18
|
+
/** Provider evidence is selected once; a sidecar never replaces message content. */
|
|
19
|
+
export interface ResponsesHistorySource {
|
|
20
|
+
readonly coverage: 'complete-output' | 'tool-sidecar';
|
|
21
|
+
readonly items: unknown[];
|
|
22
|
+
readonly message?: BaseMessage;
|
|
23
|
+
}
|
|
24
|
+
export interface OrderedToolHistoryProjection {
|
|
25
|
+
readonly source: ResponsesHistorySource;
|
|
26
|
+
readonly contributions: readonly ResponsesHistoryContribution[];
|
|
27
|
+
readonly hasToolContent: boolean;
|
|
28
|
+
readonly truncated: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface ToolHistoryPreparation {
|
|
31
|
+
get(message: BaseMessage): OrderedToolHistoryProjection | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** A preparation owns this cache; changed messages must be copy-on-write. */
|
|
34
|
+
export declare function createToolHistoryPreparation(): ToolHistoryPreparation;
|
|
35
|
+
export interface ToolHistoryPosition {
|
|
36
|
+
readonly outputIndex: number;
|
|
37
|
+
readonly contentIndex?: number;
|
|
38
|
+
readonly itemId?: string;
|
|
39
|
+
}
|
|
40
|
+
export type ResponsesHistoryContribution = ToolHistoryPosition & ({
|
|
41
|
+
readonly kind: 'text';
|
|
42
|
+
readonly actor: 'model';
|
|
43
|
+
readonly text: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: 'call';
|
|
46
|
+
readonly actor: 'model';
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly callId?: string;
|
|
49
|
+
readonly arguments: unknown;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: 'image';
|
|
52
|
+
readonly actor: 'tool';
|
|
53
|
+
readonly image: ContentBlock.Multimodal.Image;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: 'provider-item';
|
|
56
|
+
readonly actor: 'model' | 'tool';
|
|
57
|
+
readonly providerType: string;
|
|
58
|
+
readonly value: unknown;
|
|
59
|
+
});
|
|
60
|
+
export declare function getResponsesHistorySource(message: BaseMessage): ResponsesHistorySource | undefined;
|
|
61
|
+
/** Complete generated images retain their actual format across replay and folding. */
|
|
62
|
+
export declare function getGeneratedImageMimeType(data: string): string;
|
|
63
|
+
/** Streaming positions order sidecar evidence only when text positions map exactly. */
|
|
64
|
+
export declare function projectResponsesHistory(source: ResponsesHistorySource, consumeWork: () => boolean): Generator<ResponsesHistoryContribution>;
|
|
65
|
+
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import type { ProviderName } from '@/types/llm';
|
|
1
3
|
export type ProviderToolCallKind = 'tool' | 'server' | 'anthropic-server' | 'mcp' | 'google' | 'bedrock';
|
|
2
4
|
export interface ProviderToolCallPartDescriptor {
|
|
3
5
|
readonly callId: string;
|
|
@@ -15,7 +17,7 @@ export interface ProviderToolResultPartDescriptor {
|
|
|
15
17
|
}
|
|
16
18
|
export interface ProviderToolCallIndexEntry {
|
|
17
19
|
readonly descriptor: ProviderToolCallPartDescriptor;
|
|
18
|
-
|
|
20
|
+
secondarySourceTypes?: Set<string>;
|
|
19
21
|
}
|
|
20
22
|
export type ProviderToolCallIndex = Map<string, ProviderToolCallIndexEntry | null>;
|
|
21
23
|
export declare const PROVIDER_TOOL_RESULT_MAX_ARRAY_ENTRIES = 256;
|
|
@@ -27,7 +29,35 @@ export declare function getBoundedProviderPairingArrayProperty(value: unknown, k
|
|
|
27
29
|
export declare function isBoundedProviderPairingString(value: unknown, allowEmpty?: boolean): value is string;
|
|
28
30
|
export declare function hasStructurallyValidAnthropicWebSearchResultContent(part: unknown): boolean;
|
|
29
31
|
export declare function getProviderToolResultPartDescriptor(part: unknown): ProviderToolResultPartDescriptor | undefined;
|
|
32
|
+
export declare function isProviderToolCallContentPart(part: unknown): boolean;
|
|
33
|
+
export declare function isProviderToolContentPart(part: unknown): boolean;
|
|
30
34
|
export declare function getProviderAIMessageToolCallDescriptor(toolCall: unknown): ProviderToolCallPartDescriptor | undefined;
|
|
31
35
|
export declare function getProviderToolCallPartDescriptor(part: unknown): ProviderToolCallPartDescriptor | undefined;
|
|
32
36
|
export declare function appendProviderToolCallDescriptor(index: ProviderToolCallIndex, descriptor: ProviderToolCallPartDescriptor): void;
|
|
37
|
+
/** Google's built-in code execution emits an `executableCode` part with no call
|
|
38
|
+
* id; its `codeExecutionResult` pairs by adjacency instead. */
|
|
39
|
+
export declare function isExecutableCodePart(part: unknown): boolean;
|
|
33
40
|
export declare function consumeProviderToolResultPair(descriptor: ProviderToolResultPartDescriptor, calls: ProviderToolCallIndex, previousPart?: unknown): boolean;
|
|
41
|
+
export declare function getLegacyFunctionCallId(name: string): string | undefined;
|
|
42
|
+
export type ProviderMessageRole = 'assistant' | 'user' | 'system' | 'tool' | 'function';
|
|
43
|
+
/**
|
|
44
|
+
* Normalizes a message to the role a provider converter would send it as. A
|
|
45
|
+
* `ChatMessage` reports its type as `generic` and carries the wire role on
|
|
46
|
+
* `role`, so every classifier that keys on `getType()` alone silently skips
|
|
47
|
+
* generic assistant, tool and function messages the converters accept.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getProviderMessageRole(message: BaseMessage, provider?: ProviderName): ProviderMessageRole | undefined;
|
|
50
|
+
export declare function getRawToolCallDescriptor(toolCall: unknown): ProviderToolCallPartDescriptor | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Appends every tool call an assistant message carries: parsed
|
|
53
|
+
* `AIMessage.tool_calls`, raw `additional_kwargs.tool_calls` (where OpenAI
|
|
54
|
+
* keeps calls when the parsed array is empty) and a legacy
|
|
55
|
+
* `additional_kwargs.function_call`. Content-block calls are the caller's to
|
|
56
|
+
* append, since only the caller knows whether the block is being replayed.
|
|
57
|
+
* Returns how many descriptors were recognized, so a caller can tell an
|
|
58
|
+
* invocation from a plain assistant turn without re-deriving the shapes.
|
|
59
|
+
*/
|
|
60
|
+
export declare function appendProviderMessageToolCalls(message: BaseMessage, calls: ProviderToolCallIndex, provider?: ProviderName): number;
|
|
61
|
+
/** Describes a whole-message tool result: a `ToolMessage`, a `FunctionMessage`,
|
|
62
|
+
* or a generic message carrying the equivalent wire role. */
|
|
63
|
+
export declare function getProviderToolMessageResultDescriptor(message: BaseMessage, provider?: ProviderName): ProviderToolResultPartDescriptor | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DerivedSessionMessages } from './deriveMessages';
|
|
2
|
+
import type { SessionEntry } from './types';
|
|
3
|
+
import type { JsonlSessionStore } from './JsonlSessionStore';
|
|
4
|
+
/** Internal: only AgentSession's unexposed stores may reuse log topology. */
|
|
5
|
+
export declare function initializeSessionProjection(store: JsonlSessionStore, entries: readonly SessionEntry[]): void;
|
|
6
|
+
/** Forks share entry references, so exposing either disables the whole family. */
|
|
7
|
+
export declare function shareSessionProjectionOwnership(source: JsonlSessionStore, target: JsonlSessionStore): void;
|
|
8
|
+
export declare function releaseSessionProjection(store: JsonlSessionStore): void;
|
|
9
|
+
/** Reuses log topology, but materializes fresh mutable messages for every run. */
|
|
10
|
+
export declare function deriveSessionMessages(store: JsonlSessionStore | undefined): DerivedSessionMessages;
|
|
@@ -4,7 +4,8 @@ import type { SummarizationTrigger } from '@/types';
|
|
|
4
4
|
* default prompts stay out of it: LibreChat's manual flow deliberately words
|
|
5
5
|
* its own, so exporting these would publish an API with no consumer.
|
|
6
6
|
*/
|
|
7
|
-
export { buildSummarizationInstruction, buildSummaryCarrierText, separateSummarizationParameters, } from './shared';
|
|
7
|
+
export { buildSummarizationInstruction, buildSummaryCarrierText, separateSummarizationParameters, ManualSummarizationSkippedError, } from './shared';
|
|
8
|
+
export type { ManualSummarizationSkipReason } from './shared';
|
|
8
9
|
/** For tests only. Resets the dedup set so warnings can be observed again. */
|
|
9
10
|
export declare function _resetUnrecognizedTriggerWarnings(): void;
|
|
10
11
|
/**
|
|
@@ -45,6 +45,7 @@ export declare function createSummarizeNode({ agentContext, graph: adapterGraph,
|
|
|
45
45
|
}, config?: RunnableConfig) => Promise<{
|
|
46
46
|
summarizationRequest: undefined;
|
|
47
47
|
messages?: BaseMessage[];
|
|
48
|
+
manualSummary?: string;
|
|
48
49
|
}>;
|
|
49
50
|
/** Creates an `onChunk` callback that dispatches `ON_SUMMARIZE_DELTA` events for streaming. */
|
|
50
51
|
export declare function createSummarizationChunkHandler({ stepId, config, provider, reasoningKey, graph, }: {
|
|
@@ -23,3 +23,15 @@ export declare function separateSummarizationParameters(parameters: Record<strin
|
|
|
23
23
|
maxSummaryTokens?: number;
|
|
24
24
|
};
|
|
25
25
|
export declare function buildSummarizationInstruction(promptText: string, updatePromptText: string | undefined, priorSummaryText?: string, semanticIndexAppendix?: string): string;
|
|
26
|
+
/** Why a summarize-only run could not attempt its summary. */
|
|
27
|
+
export type ManualSummarizationSkipReason = 'disabled' | 'exhausted' | 'instructions_exceed_budget' | 'nothing_to_summarize';
|
|
28
|
+
/**
|
|
29
|
+
* A summarize-only run asked for a summary the graph could not attempt.
|
|
30
|
+
* Thrown rather than ending the run quietly: the summary is the whole result
|
|
31
|
+
* of such a run, so a host left with neither a summary nor an error would
|
|
32
|
+
* have nothing to show the user.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ManualSummarizationSkippedError extends Error {
|
|
35
|
+
readonly reason: ManualSummarizationSkipReason;
|
|
36
|
+
constructor(reason: ManualSummarizationSkipReason, message: string);
|
|
37
|
+
}
|
|
@@ -2,7 +2,7 @@ import { ToolCall } from '@langchain/core/messages/tool';
|
|
|
2
2
|
import { END, Command, MessagesAnnotation } from '@langchain/langgraph';
|
|
3
3
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
4
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
5
|
-
import type { ToolOutputResolveView, ResolvedArgsByCallId } from '@/tools/toolOutputReferences';
|
|
5
|
+
import type { ToolOutputResolveView, ToolOutputReferenceState, ResolvedArgsByCallId } from '@/tools/toolOutputReferences';
|
|
6
6
|
import type { SubagentToolNodeResumeState } from '@/tools/subagent/SubagentReplay';
|
|
7
7
|
import type * as t from '@/types';
|
|
8
8
|
import { ToolOutputReferenceRegistry } from '@/tools/toolOutputReferences';
|
|
@@ -53,6 +53,10 @@ type RunToolBatchContext<T = unknown> = {
|
|
|
53
53
|
additionalContextsSink?: string[];
|
|
54
54
|
/** Stable identity of the assistant tool-call batch across HITL replay. */
|
|
55
55
|
replayBatchKey?: string;
|
|
56
|
+
/** Positions in the original proposal, before completed calls are filtered. */
|
|
57
|
+
replayCallPositions?: ReadonlyMap<ToolCall, number>;
|
|
58
|
+
/** Tool-call identities owned by this ToolNode invocation. */
|
|
59
|
+
approvalScopeCallIds?: ReadonlySet<string>;
|
|
56
60
|
/**
|
|
57
61
|
* Graph state the ToolNode was invoked with, threaded from `run()`
|
|
58
62
|
* so `tool.invoke` can forward it as langgraph 1.4's `runtime.state`
|
|
@@ -116,10 +120,10 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
116
120
|
* the Run ends.
|
|
117
121
|
*/
|
|
118
122
|
private directPathTurns;
|
|
119
|
-
/** Terminal results
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
private
|
|
123
|
+
/** Terminal direct results that must survive a LangGraph replay of the
|
|
124
|
+
* containing ToolNode. Includes the sidecar data the fresh batch needs for
|
|
125
|
+
* hook-context injection and completion-event deduplication. */
|
|
126
|
+
private settledDirectResultsByBatch;
|
|
123
127
|
/** Tool registry for filtering (lazy computation of programmatic maps) */
|
|
124
128
|
private toolRegistry?;
|
|
125
129
|
/** Schema-only definitions used when event mode has no runtime registry. */
|
|
@@ -527,7 +531,9 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
527
531
|
* invocations cannot race on shared mutable state.
|
|
528
532
|
*/
|
|
529
533
|
private executeViaEvent;
|
|
530
|
-
protected run(input: any, config: RunnableConfig
|
|
534
|
+
protected run(input: any, config: RunnableConfig, referenceReplay?: {
|
|
535
|
+
state?: ToolOutputReferenceState;
|
|
536
|
+
}): Promise<T>;
|
|
531
537
|
private isSendInput;
|
|
532
538
|
private isMessagesState;
|
|
533
539
|
}
|
|
@@ -67,6 +67,8 @@ export interface SubagentResumeManifest {
|
|
|
67
67
|
version: 1;
|
|
68
68
|
executions: SubagentResumeExecution[];
|
|
69
69
|
}
|
|
70
|
+
export declare function isToolNodeResumeState(value: unknown): value is SubagentToolNodeResumeState;
|
|
71
|
+
export declare function isToolOutputReferenceState(value: unknown): value is ToolOutputReferenceState;
|
|
70
72
|
export declare function getSubagentResumeManifest(payload: unknown): SubagentResumeManifest | undefined;
|
|
71
73
|
export declare function requireValidSubagentResumeManifest(payload: unknown): SubagentResumeManifest | undefined;
|
|
72
74
|
export declare function attachSubagentResumeManifest(payload: unknown, manifest: SubagentResumeManifest): object;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Command } from '@langchain/langgraph';
|
|
2
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
|
+
import type { SubagentToolNodeResumeState } from '@/tools/subagent/SubagentReplay';
|
|
5
|
+
import type { ToolOutputReferenceState } from '@/tools/toolOutputReferences';
|
|
6
|
+
export declare const TOOL_BATCH_REPLAY_KEY = "__librechat_tool_batch_replay";
|
|
7
|
+
export interface SettledToolBatchResult {
|
|
8
|
+
proposal: {
|
|
9
|
+
name: string;
|
|
10
|
+
args: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
output: BaseMessage | Command;
|
|
13
|
+
additionalContexts: string[];
|
|
14
|
+
resolvedArgs?: Record<string, unknown>;
|
|
15
|
+
completionHandled?: boolean;
|
|
16
|
+
referenceContent?: string;
|
|
17
|
+
turn?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ToolBatchReplayRecord {
|
|
20
|
+
owner: string;
|
|
21
|
+
batch: string;
|
|
22
|
+
encoding: string;
|
|
23
|
+
data: string;
|
|
24
|
+
turnState?: SubagentToolNodeResumeState;
|
|
25
|
+
referenceState?: ToolOutputReferenceState;
|
|
26
|
+
}
|
|
27
|
+
interface ToolBatchReplayState {
|
|
28
|
+
version: 1;
|
|
29
|
+
approvalOwner?: string;
|
|
30
|
+
records: ToolBatchReplayRecord[];
|
|
31
|
+
wrappedPayload?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** The only host-to-runtime entry point for checkpoint-owned tool replay state. */
|
|
34
|
+
export declare function restoreToolReplayConfig(configurable: Record<string, unknown>, interruptId: string | undefined, payload: unknown): void;
|
|
35
|
+
export declare function getToolBatchReplayOwner(config: RunnableConfig, agentId: string): string;
|
|
36
|
+
export declare function getToolBatchReplayScope(config: RunnableConfig): string | undefined;
|
|
37
|
+
/** Foreign approval evidence may only transit a checkpoint-proven child path. */
|
|
38
|
+
export declare function isChildToolApprovalOwner(config: RunnableConfig, owner: string, trustedParentCallIds: ReadonlySet<string>): boolean;
|
|
39
|
+
/** Rebind only the checkpoint-proven source execution when a child fork is created. */
|
|
40
|
+
export declare function rebindToolBatchReplayScope(configurable: Record<string, unknown>, sourceScope: string, destinationScope: string): void;
|
|
41
|
+
/** A fork may be paused again before it consumes its pending interrupt. */
|
|
42
|
+
export declare function rebindToolBatchReplayPayload(payload: unknown, sourceScope: string, destinationScope: string): unknown;
|
|
43
|
+
export declare function getToolBatchReplayState(payload: unknown): ToolBatchReplayState | undefined;
|
|
44
|
+
export declare function stripToolBatchReplayState(payload: unknown): unknown;
|
|
45
|
+
/** Decode outer execution metadata before shape-sensitive child wrappers. */
|
|
46
|
+
export declare function getPublicToolInterruptPayload(payload: unknown): unknown;
|
|
47
|
+
export declare function attachToolBatchReplayState(payload: unknown, owner: string, batches: ReadonlyMap<string, ReadonlyMap<string, object>>, turnState?: SubagentToolNodeResumeState, referenceState?: ToolOutputReferenceState): Promise<unknown>;
|
|
48
|
+
export declare function restoreToolBatchReplayState(config: RunnableConfig, owner: string): Promise<Array<{
|
|
49
|
+
batch: string;
|
|
50
|
+
results: Array<[string, SettledToolBatchResult]>;
|
|
51
|
+
turnState?: SubagentToolNodeResumeState;
|
|
52
|
+
referenceState?: ToolOutputReferenceState;
|
|
53
|
+
}>>;
|
|
54
|
+
export {};
|
|
@@ -199,6 +199,8 @@ export declare class ToolOutputReferenceRegistry {
|
|
|
199
199
|
snapshot(runId: string | undefined): ToolOutputResolveView;
|
|
200
200
|
/** Captures the checkpoint-safe state needed to resume one run bucket. */
|
|
201
201
|
snapshotState(runId: string | undefined): ToolOutputReferenceState;
|
|
202
|
+
/** Restore batch inputs without rolling back graph-owned concurrent outputs. */
|
|
203
|
+
resumeBatch(runId: string, state: ToolOutputReferenceState): ToolOutputResolveView;
|
|
202
204
|
/** Restores a checkpointed run bucket under the current resume scope. */
|
|
203
205
|
restoreState(runId: string | undefined, state: ToolOutputReferenceState): void;
|
|
204
206
|
private resolveAgainst;
|
|
@@ -30,6 +30,13 @@ export type SystemCallbacks = {
|
|
|
30
30
|
export type BaseGraphState = {
|
|
31
31
|
messages: BaseMessage[];
|
|
32
32
|
runStepState?: RunStepResumeState;
|
|
33
|
+
/**
|
|
34
|
+
* The summary a summarize-only run produced. Kept in state because such a
|
|
35
|
+
* run has no assistant reply: trace roots report it as the run's output
|
|
36
|
+
* instead of the retained tail or the raw state. Empty once any later run
|
|
37
|
+
* on the same checkpointed thread starts, so it never outlives its run.
|
|
38
|
+
*/
|
|
39
|
+
manualSummary?: string;
|
|
33
40
|
};
|
|
34
41
|
export type AgentSubgraphState = BaseGraphState & {
|
|
35
42
|
summarizationRequest?: SummarizationNodeInput;
|
|
@@ -725,6 +732,19 @@ interface AgentInputFields {
|
|
|
725
732
|
*/
|
|
726
733
|
discoveredTools?: string[];
|
|
727
734
|
summarizationEnabled?: boolean;
|
|
735
|
+
/**
|
|
736
|
+
* Runs this agent as a summarize-only pass: the first model step requests
|
|
737
|
+
* summarization outright instead of consulting the trigger, and the step
|
|
738
|
+
* after the summary emits its context snapshot and ends the run without a
|
|
739
|
+
* model call. Hosts use it for user-initiated compaction, where the summary
|
|
740
|
+
* is the whole response. Requires `summarizationEnabled`: a run that cannot
|
|
741
|
+
* attempt the summary rejects with `ManualSummarizationSkippedError`
|
|
742
|
+
* rather than ending with nothing, and one whose provider calls all fail
|
|
743
|
+
* keeps the history and reports the failure on the summary step. A
|
|
744
|
+
* multi-agent workflow compiles to the agent that opted in alone; no other
|
|
745
|
+
* agent runs.
|
|
746
|
+
*/
|
|
747
|
+
summarizeOnly?: boolean;
|
|
728
748
|
summarizationConfig?: SummarizationConfig;
|
|
729
749
|
/**
|
|
730
750
|
* Optional host-supplied, user-visible guidance for compaction. The SDK
|