@librechat/agents 3.7.7 → 3.7.8
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 +23 -3
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/constants.cjs +10 -0
- package/dist/cjs/common/constants.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +16 -5
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/langfuseTraceShaping.cjs +75 -0
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs +1 -1
- package/dist/cjs/llm/fake.cjs +9 -5
- package/dist/cjs/llm/fake.cjs.map +1 -1
- package/dist/cjs/llm/invoke.cjs +1 -1
- package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
- package/dist/cjs/llm/prepareProviderRequest.cjs +2 -2
- package/dist/cjs/llm/providers.cjs +1 -1
- package/dist/cjs/llm/truncation.cjs +1 -0
- package/dist/cjs/main.cjs +3 -2
- package/dist/cjs/messages/format.cjs +298 -3
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +1 -1
- package/dist/cjs/run.cjs +25 -15
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +1 -1
- package/dist/cjs/summarization/node.cjs +43 -9
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/summarization/semanticIndex.cjs +362 -0
- package/dist/cjs/summarization/semanticIndex.cjs.map +1 -0
- package/dist/cjs/tools/subagent/childGraphConfig.cjs +2 -1
- package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/esm/agents/AgentContext.mjs +23 -3
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/constants.mjs +10 -1
- package/dist/esm/common/constants.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +16 -5
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/langfuseTraceShaping.mjs +75 -0
- package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
- package/dist/esm/llm/bedrock/toolCache.mjs +1 -1
- package/dist/esm/llm/fake.mjs +9 -5
- package/dist/esm/llm/fake.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
- package/dist/esm/llm/prepareProviderRequest.mjs +2 -2
- package/dist/esm/llm/providers.mjs +1 -1
- package/dist/esm/llm/truncation.mjs +1 -1
- package/dist/esm/main.mjs +4 -4
- package/dist/esm/messages/format.mjs +298 -3
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +1 -1
- package/dist/esm/run.mjs +25 -15
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +1 -1
- package/dist/esm/summarization/node.mjs +43 -9
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/summarization/semanticIndex.mjs +360 -0
- package/dist/esm/summarization/semanticIndex.mjs.map +1 -0
- package/dist/esm/tools/subagent/childGraphConfig.mjs +2 -1
- package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/types/agents/AgentContext.d.ts +27 -1
- package/dist/types/common/constants.d.ts +10 -0
- package/dist/types/graphs/Graph.d.ts +15 -0
- package/dist/types/llm/fake.d.ts +12 -2
- package/dist/types/messages/format.d.ts +10 -1
- package/dist/types/run.d.ts +17 -5
- package/dist/types/summarization/semanticIndex.d.ts +19 -0
- package/dist/types/types/graph.d.ts +9 -1
- package/dist/types/types/summarize.d.ts +38 -0
- package/package.json +2 -1
- package/src/agents/AgentContext.ts +61 -1
- package/src/common/constants.ts +11 -0
- package/src/graphs/Graph.ts +41 -8
- package/src/langfuseTraceShaping.ts +94 -0
- package/src/llm/fake.ts +35 -4
- package/src/messages/format.ts +652 -4
- package/src/run.ts +36 -10
- package/src/summarization/node.ts +90 -33
- package/src/summarization/semanticIndex.ts +653 -0
- package/src/tools/subagent/childGraphConfig.ts +3 -0
- package/src/types/graph.ts +9 -0
- package/src/types/summarize.ts +50 -0
package/dist/esm/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ACTIVITY_LABEL_RUN_NAME, ACTIVITY_PHASE_LABEL_RUN_NAME, ACTIVITY_PHASE_RUN_NAME, AGENT_MODEL_CALL_RUN_NAME, ANTHROPIC_TOOL_TOKEN_MULTIPLIER, DEFAULT_MAX_SEALS, DEFAULT_RECURSION_LIMIT, DEFAULT_TOOL_TOKEN_MULTIPLIER, MULTI_AGENT_GRAPH_RUN_NAME, PREEMPT_BOUNDARY_HOOK_TIMEOUT_MS, REASONING_LABEL_RUN_NAME, STANDARD_GRAPH_RUN_NAME } from "./common/constants.mjs";
|
|
1
|
+
import { ACTIVITY_LABEL_RUN_NAME, ACTIVITY_PHASE_LABEL_RUN_NAME, ACTIVITY_PHASE_RUN_NAME, AGENT_MODEL_CALL_RUN_NAME, ANTHROPIC_TOOL_TOKEN_MULTIPLIER, COMPACTION_SEMANTIC_INDEX_LIMITS, DEFAULT_MAX_SEALS, DEFAULT_RECURSION_LIMIT, DEFAULT_TOOL_TOKEN_MULTIPLIER, MULTI_AGENT_GRAPH_RUN_NAME, PREEMPT_BOUNDARY_HOOK_TIMEOUT_MS, REASONING_LABEL_RUN_NAME, STANDARD_GRAPH_RUN_NAME } from "./common/constants.mjs";
|
|
2
2
|
import { CODE_EXECUTION_TOOLS, Callback, CommonEvents, Constants, ContentTypes, EnvVar, GraphEvents, GraphNodeActions, GraphNodeKeys, LOCAL_CODING_BUNDLE_NAMES, LOCAL_CODING_TOOL_NAMES, Providers, StepTypes, TitleMethod, ToolCallTypes } from "./common/enum.mjs";
|
|
3
3
|
import "./common/index.mjs";
|
|
4
4
|
import { composeAbortSignals, isPresent, parseBooleanEnv, unescapeObject } from "./utils/misc.mjs";
|
|
@@ -6,11 +6,12 @@ import { HARD_MAX_TOOL_RESULT_CHARS, HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE, calculateM
|
|
|
6
6
|
import { markTokenCounterCacheCompatible } from "./llm/tokenCounterCacheCompatibility.mjs";
|
|
7
7
|
import { IMAGE_TOKEN_SAFETY_MARGIN, TokenEncoderManager, UnsafeTokenMeasurementError, apportionTokenCounts, createTokenCounter, encodingForModel, estimateAnthropicImageTokens, estimateDocumentBlockTokens, estimateImageBlockTokens, estimateOpenAIImageTokens, estimateTimedMediaBlockTokens, extractImageDimensions, getTokenCountForMessage, hasUnsafeStructuredSerialization } from "./utils/tokens.mjs";
|
|
8
8
|
import { PROVIDER_MESSAGE_PROVENANCE_LIMITS, PROVIDER_MESSAGE_PROVENANCE_VERSION, appendProviderMessageProvenance, getProviderMessageProvenance, getProviderSourceMessageIds, hasBijectiveProviderContentPartMapping, inspectProviderMessageProvenance, inspectProviderSourceMessageIds, setFreshProviderMessageProvenance, setInvalidProviderMessageProvenance, setProviderMessageProvenance, stampSyntheticProviderMessage } from "./messages/provenance.mjs";
|
|
9
|
+
import { registerProvider } from "./llm/providerRegistry.mjs";
|
|
10
|
+
import { constructorChainHasLcName, isAnthropicLike, isGoogleLike, isLibreChatOpenAIModel, isOpenAILike } from "./utils/llm.mjs";
|
|
9
11
|
import { DEFAULT_PROMPT_CACHE_TTL, addBedrockCacheControl, addBedrockTailCacheControl, addCacheControl, addCacheControlToStablePrefixMessages, addTailCacheControl, buildAnthropicCacheControl, buildBedrockCachePoint, cloneMessage, resolveBedrockPromptCacheTtl, resolvePromptCacheTtl, stripAnthropicCacheControl, stripBedrockCacheControl, supportsBedrockToolCache } from "./messages/cache.mjs";
|
|
10
12
|
import { OPENAI_RESPONSES_ACTIVE_REASONING_ID_KEY, OPENAI_RESPONSES_REPLAY_POSITIONS_KEY, convertMessagesToContent, dropIncompleteToolStreamContent, findLastIndex, formatAnthropicArtifactContent, formatAnthropicMessage, formatArtifactPayload, getConverseOverrideMessage, modifyDeltaProperties, projectAnthropicArtifactContent, projectArtifactPayload, projectCacheControlledToolOutputsToText, projectComputerCallOutputsToText, projectOpenAIChatToolMessageContent, projectOpenAIResponsesToolMessageContent, projectOpenAIToolMessageContent, projectOpenRouterToolMessageContent, projectSingleTextToolOutputsToText, projectStructuredToolOutputsToText, projectToolStreamContentForProvider } from "./messages/core.mjs";
|
|
11
13
|
import { getMessageId } from "./messages/ids.mjs";
|
|
12
14
|
import { DEFAULT_CONTEXT_PRUNING_SETTINGS, resolveContextPruningSettings } from "./messages/contextPruningSettings.mjs";
|
|
13
|
-
import { registerProvider } from "./llm/providerRegistry.mjs";
|
|
14
15
|
import { applyContextPruning } from "./messages/contextPruning.mjs";
|
|
15
16
|
import { CALIBRATION_RATIO_MAX, CALIBRATION_RATIO_MIN, DEFAULT_RESERVE_RATIO, ORIGINAL_CONTENT_MAX_CHARS, REPLY_PRIMER_TOKENS, calculateMaxToolCallInputChars, calculateTotalTokens, checkValidNumber, clampCalibrationRatio, createPruneMessages, enforceOriginalContentCap, getMessagesWithinTokenLimit, maskConsumedToolResults, preFlightTruncateToolCallInputs, preFlightTruncateToolResults, projectToolCallInputs, projectToolMessagesForProvider, repairOrphanedToolMessages, sanitizeOrphanToolBlocks, serializeToolCallInput } from "./messages/prune.mjs";
|
|
16
17
|
import { syncBudgetDerivedFields } from "./messages/budget.mjs";
|
|
@@ -27,7 +28,6 @@ import { getAssistantTextPhase, getMessageCreationContentMetadata, splitAssistan
|
|
|
27
28
|
import { ProviderMessageProjectionInvariantError, inspectProviderMessageProjection, resolveProviderMessageProjectionInvariantMode } from "./messages/projectionInvariant.mjs";
|
|
28
29
|
import "./messages/index.mjs";
|
|
29
30
|
import { joinKeys, resetIfNotEmpty } from "./utils/graph.mjs";
|
|
30
|
-
import { constructorChainHasLcName, isAnthropicLike, isGoogleLike, isLibreChatOpenAIModel, isOpenAILike } from "./utils/llm.mjs";
|
|
31
31
|
import { resolveFetchProxyAgent, shouldBypassProxy } from "./utils/proxy.mjs";
|
|
32
32
|
import { DEFAULT_MAX_TOOL_CALL_ARG_BYTES, StreamLimitExceededError, resolveStreamLimits } from "./llm/streamLimits.mjs";
|
|
33
33
|
import { handleServerToolResult, handleToolCallChunks, handleToolCalls, toolResultTypes } from "./tools/handlers.mjs";
|
|
@@ -118,4 +118,4 @@ import "./langchain/index.mjs";
|
|
|
118
118
|
import "./provider-registration.mjs";
|
|
119
119
|
import { DEFAULT_STREAM_DELAY, computeAdaptivePieceSize, resolveStreamDelay, smoothStream } from "./llm/stream/smoother.mjs";
|
|
120
120
|
import { BaseCheckpointSaver, Command, INTERRUPT, MemorySaver, interrupt, isInterrupted } from "@langchain/langgraph";
|
|
121
|
-
export { ACTIVITY_LABEL_RUN_NAME, ACTIVITY_PHASE_LABEL_RUN_NAME, ACTIVITY_PHASE_RUN_NAME, AGENT_MODEL_CALL_RUN_NAME, AIMessage, AIMessageChunk, ANTHROPIC_TOOL_TOKEN_MULTIPLIER, ASK_USER_QUESTION_ID_PATTERN, AgentSession, BASH_SHELL_GUIDANCE, BaseCheckpointSaver, BaseMessage, BaseMessageChunk, BashExecutionToolDefinition, BashExecutionToolDescription, BashExecutionToolName, BashExecutionToolSchema, BashProgrammaticToolCallingDefinition, BashProgrammaticToolCallingDescription, BashProgrammaticToolCallingName, BashProgrammaticToolCallingSchema, BashToolOutputReferencesGuide, CALIBRATION_RATIO_MAX, CALIBRATION_RATIO_MIN, CLOUDFLARE_BASH_CODING_TOOL_NAMES, CLOUDFLARE_CODING_TOOL_NAMES, CODE_API_AUTHORIZATION_ERROR_MESSAGE, CODE_API_EXECUTION_FAILED_ERROR_MESSAGE, CODE_API_EXPECTED_PROFILE_HEADER, CODE_API_INVALID_REQUEST_ERROR_MESSAGE, CODE_API_RATE_LIMITED_ERROR_MESSAGE, CODE_API_UNAVAILABLE_ERROR_MESSAGE, CODE_ARTIFACT_PATH_GUIDANCE, CODE_EXECUTION_TOOLS, Calculator, CalculatorSchema, CalculatorToolDefinition, CalculatorToolDescription, CalculatorToolName, Callback, ChatModelStreamHandler, CloudflareBashExecutionToolDescription, CloudflareCodeExecutionToolDescription, CodeApiRequestError, CodeExecutionToolDefinition, CodeExecutionToolDescription, CodeExecutionToolName, CodeExecutionToolSchema, Command, CommonEvents, CompileCheckToolName, Constants, ContentTypes, DATE_RANGE, DEFAULT_CONTEXT_PRUNING_SETTINGS, DEFAULT_COUNTRY_DESCRIPTION, DEFAULT_HOOK_TIMEOUT_MS, DEFAULT_INTRA_TURN_RETAIN_RATIO, DEFAULT_MAX_SEALS, DEFAULT_MAX_TOOL_CALL_ARG_BYTES, DEFAULT_PROMPT_CACHE_TTL, DEFAULT_QUERY_DESCRIPTION, DEFAULT_RECURSION_LIMIT, DEFAULT_RESERVE_RATIO, DEFAULT_RETAIN_RECENT_TURNS, DEFAULT_STREAM_DELAY, DEFAULT_SUBAGENT_DESCRIPTION, DEFAULT_TOOL_TOKEN_MULTIPLIER, DynamicStructuredTool, EnvVar, EventActorExecutor, FAILED_EXECUTION_FILE_REMINDER, FakeChatModel, Graph, GraphEvents, GraphNodeActions, GraphNodeKeys, HARD_MAX_TOOL_RESULT_CHARS, HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE, HOOK_EVENTS, HOOK_INJECTED_MESSAGES_CAPABLE, HOOK_PREEMPT_BOUNDARY_CAPABLE, HandlerRegistry, HookRegistry, HumanMessage, IMAGE_TOKEN_SAFETY_MARGIN, INTENT_ARG, INTENT_DESCRIPTION, INTENT_LABEL_MARKER, INTENT_PROPERTY, INTERRUPT, InMemorySubagentTaskStore, JsonlSessionStore, LLMStreamHandler, LOCAL_CODING_BUNDLE_NAMES, LOCAL_CODING_TOOL_NAMES, LOCAL_SPAWN_TIMEOUT_MS, LocalBashExecutionToolDescription, LocalCodeExecutionToolDescription, LocalEditFileToolName, LocalEditFileToolSchema, LocalFileCheckpointerImpl, LocalGlobSearchToolName, LocalGlobSearchToolSchema, LocalGrepSearchToolName, LocalGrepSearchToolSchema, LocalListDirectoryToolName, LocalListDirectoryToolSchema, LocalReadFileToolSchema, LocalWriteFileToolName, LocalWriteFileToolSchema, MAX_ASK_USER_QUESTIONS, MAX_CACHE_SIZE, MAX_PATTERN_LENGTH, MULTI_AGENT_GRAPH_RUN_NAME, MemorySaver, ModelEndHandler, MultiAgentGraph, OPENAI_RESPONSES_ACTIVE_REASONING_ID_KEY, OPENAI_RESPONSES_REPLAY_POSITIONS_KEY, ORIGINAL_CONTENT_MAX_CHARS, PREDECESSOR_HANDOFF_CUE, PREEMPT_BOUNDARY_HOOK_TIMEOUT_MS, PROVIDER_MESSAGE_PROVENANCE_LIMITS, PROVIDER_MESSAGE_PROVENANCE_VERSION, ProgrammaticToolCallingDefinition, ProgrammaticToolCallingDescription, ProgrammaticToolCallingName, ProgrammaticToolCallingSchema, PromptTemplate, ProviderMessageProjectionInvariantError, Providers, REASONING_LABEL_RUN_NAME, REMOVE_ALL_MESSAGES, REPLY_PRIMER_TOKENS, ReadFileToolDefinition, ReadFileToolDescription, ReadFileToolName, ReadFileToolSchema, Run, Runnable, RunnableCallable, RunnableLambda, RunnableSequence, SDK_STREAM_DISPATCH, STANDARD_GRAPH_RUN_NAME, STATEFUL_BASH_NOTE, STATEFUL_ENV_NOTE, SessionManager, SkillToolDefinition, SkillToolDescription, SkillToolName, SkillToolSchema, StandardGraph, StatefulBashExecutionToolDescription, StatefulCodeExecutionToolDescription, StepTypes, StreamLimitExceededError, StructuredTool, SubagentExecutor, SubagentToolDefinition, SubagentToolDescription, SubagentToolName, SubagentToolSchema, SystemMessage, TMP_SCRATCH_OUTPUT_REMINDER, TOOL_APPROVAL_EXECUTION_SCOPE_CONFIG_KEY, TestChatStreamHandler, TestLLMStreamHandler, TitleMethod, TokenEncoderManager, Tool, ToolCallTypes, ToolEndHandler, ToolMessage, ToolNode, ToolSearchToolDefinition, ToolSearchToolDescription, ToolSearchToolName, ToolSearchToolSchema, UnsafeTokenMeasurementError, WebSearchToolDefinition, WebSearchToolDescription, WebSearchToolName, WebSearchToolSchema, _createBashProgramForTests, _resetLocalEngineWarningsForTests, _resetRipgrepCacheForTests, _resetSyntaxCheckProbeCacheForTests, _resetUnrecognizedTriggerWarnings, addBedrockCacheControl, addBedrockTailCacheControl, addCacheControl, addCacheControlToStablePrefixMessages, addCodeApiExecutionProfileHeader, addTailCacheControl, appendCodeSessionFileSummary, appendFailedExecutionFileReminder, appendPredecessorHandoffCue, appendProviderMessageProvenance, appendTmpScratchReminder, applyContextPruning, applyEdit, applyOutcome, applyPreToolUseHooksForBridge, apportionTokenCounts, askUserQuestion, askUserQuestions, attemptInvoke, bashAstFindingsToErrors, buildAnthropicCacheControl, buildBashExecutionToolDescription, buildBashExecutionToolSchema, buildBedrockCachePoint, buildChildInputs, buildCodeApiEndpoint, buildCodeApiExecutionErrorMessage, buildCodeApiHttpErrorMessage, buildCodeExecutionToolDescription, buildCodeExecutionToolSchema, buildSandboxRuntimeConfig, buildSubagentToolParams, calculateMaxToolCallInputChars, calculateMaxToolResultChars, calculateMaxTotalToolOutputSize, calculateTotalTokens, canSealPreempt, checkValidNumber, clampCalibrationRatio, classifyAttachment, clientExecTimeoutMs, clientFsTimeoutMs, cloneMessage, coalesceAdjacentUserTurns, commandAvailabilityEnvCacheKey, compactSyntheticProviderContextMessage, composeAbortSignals, composeEventHandlers, computeAdaptivePieceSize, constructorChainHasLcName, convertInjectedMessages, convertMessagesToContent, countNestedGroups, countrySchema, createAgentSession, createBashExecutionTool, createBashProgrammaticToolCallingSchema, createBashProgrammaticToolCallingTool, createCloudflareBashExecutionTool, createCloudflareBashProgrammaticToolCallingTool, createCloudflareBridgeRuntime, createCloudflareCodeExecutionTool, createCloudflareCodingToolBundle, createCloudflareCodingTools, createCloudflareExecutionTool, createCloudflareExecutionWorld, createCloudflareLocalExecutionConfig, createCloudflareProgrammaticToolCallingTool, createCloudflareWorkspaceFS, createCodeExecutionTool, createCompileCheckTool, createCompileCheckToolDefinition, createContentAggregator, createEventActorExecutor, createFakeStreamingLLM, createGraph, createHandlers, createLocalBashExecutionTool, createLocalBashProgrammaticToolCallingTool, createLocalCodeExecutionTool, createLocalCodingToolBundle, createLocalCodingToolDefinitions, createLocalCodingToolRegistry, createLocalCodingTools, createLocalEditFileTool, createLocalFileCheckpointer, createLocalGlobSearchTool, createLocalGrepSearchTool, createLocalListDirectoryTool, createLocalProgrammaticToolCallingTool, createLocalReadFileTool, createLocalWriteFileTool, createMetadataAggregator, createProgrammaticToolCallingSchema, createProgrammaticToolCallingTool, createPruneMessages, createRemoveAllMessage, createRunHandlers, createSchemaOnlyTool, createSchemaOnlyTools, createSearchTool, createSubagentToolDefinition, createTokenCounter, createToolErrorOwnership, createToolPolicyHook, createToolSearch, createWorkspacePolicyHook, dateSchema, decodeFile, defaultOmitOptions, deriveMessages, deserializeMessage, dispatchesChatModelStream, dropIncompleteToolStreamContent, emptyOutputMessage, encodeFile, encodingForModel, enforceOriginalContentCap, ensureThinkingBlockInMessages, escapeRegexSpecialChars, estimateAnthropicImageTokens, estimateDocumentBlockTokens, estimateImageBlockTokens, estimateOpenAIImageTokens, estimateTimedMediaBlockTokens, execWithClientTimeout, executeCloudflareBash, executeCloudflareCode, executeHooks, executeLocalBash, executeLocalBashWithArgs, executeLocalCode, executeParallelSearches, executeTools, extractErrorMessage, extractImageDimensions, extractMcpServerName, extractTextFromContent, extractToolDiscoveries, extractUsedBashToolNames, extractUsedToolNames, fetchSessionFiles, filterBashToolsByUsage, filterGraphSubagentResult, filterSubagentResult, filterToolsByUsage, findLastIndex, flattenLegacyContent, foldToolBlocksForToollessAgent, formatAgentMessages, formatAnthropicArtifactContent, formatAnthropicMessage, formatArtifactPayload, formatCloudflareOutput, formatCompletedResponse, formatContentStrings, formatFromLangChain, formatLangChainMessages, formatMediaMessage, formatMessage, formatServerListing, formatSkillCatalog, getAssistantTextPhase, getAvailableMcpServers, getBaseToolName, getBufferString, getChatModelClass, getChunkContent, getCloudflareWorkspaceRoot, getCodeBaseURL, getContextOverflowInfo, getConverseOverrideMessage, getDeferredToolsListing, getExecutionWorld, getLocalCwd, getLocalSessionId, getMaxOutputTokensKey, getMessageCreationContentMetadata, getMessageId, getMessagesWithinTokenLimit, getProviderMessageProvenance, getProviderSourceMessageIds, getReadRoots, getSpawn, getTokenCountForMessage, getWorkspaceFS, getWorkspaceRoots, getWriteRoots, handleServerToolResult, handleToolCallChunks, handleToolCalls, hasBijectiveProviderContentPartMapping, hasNestedQuantifier, hasNestedQuantifiers, hasToolSearchInCurrentTurn, hasUnsafeStructuredSerialization, imageAttachmentContent, imagesSchema, initializeModel, inspectProviderMessageProjection, inspectProviderMessageProvenance, inspectProviderSourceMessageIds, interrupt, isAIMessage, isAnthropicLike, isAskUserQuestionsInterrupt, isBaseMessage, isContextOverflowError, isDangerousPattern, isFromAnyMcpServer, isFromMcpServer, isGoogleLike, isGraphSubagentConfig, isIntentLabelProperty, isInterrupted, isLegacyConvertible, isLibreChatOpenAIModel, isLikelyContextOverflowError, isOpenAILike, isPresent, isProgrammaticRunnerAutoBound, isProgrammaticRunnerResolvedDirectly, isSyntheticProviderContextMessage, isThinkingEnabled, isToolMessage, isZodSchema, joinKeys, labelContentByAgent, locateEdit, makeIsDeferred, makeRequest, mapChatMessagesToStoredMessages, mapStoredMessagesToChatMessages, markTokenCounterCacheCompatible, maskConsumedToolResults, matchesQuery, messagesStateReducer, modifyDeltaProperties, newsSchema, nodeExecutionWorld, normalizeBashToolResultsForReplay, normalizeCodeApiRequestError, normalizeServerFilter, normalizeSubagentConfigEntries, normalizeSubagentConfigs, normalizeToBashIdentifier, normalizeToPythonIdentifier, outcomeFieldsFromResult, parseBooleanEnv, partitionAndMarkAnthropicToolCache, performLocalSearch, preFlightTruncateToolCallInputs, preFlightTruncateToolResults, prepareProviderRequest, probeLocalCommandAvailability, projectAgentContextUsage, projectAnthropicArtifactContent, projectArtifactPayload, projectCacheControlledToolOutputsToText, projectComputerCallOutputsToText, projectOpenAIChatToolMessageContent, projectOpenAIResponsesToolMessageContent, projectOpenAIToolMessageContent, projectOpenRouterToolMessageContent, projectSingleTextToolOutputsToText, projectStructuredToolOutputsToText, projectToolCallInputs, projectToolMessagesForProvider, projectToolStreamContentForProvider, querySchema, readIntent, readOutcomeFields, registerProvider, removePredecessorHandoffCue, repairOrphanedToolMessages, resetIfNotEmpty, resolveBedrockPromptCacheTtl, resolveCloudflareSandbox, resolveCodeApiAuthHeaders, resolveContextPruningSettings, resolveFetchProxyAgent, resolveIntraTurnRetainTokens, resolveLocalExecutionConfig, resolveLocalExecutionTools, resolveLocalImplementationNames, resolveLocalToolRegistry, resolveLocalToolsForBinding, resolvePromptCacheTtl, resolveProviderMessageProjectionInvariantMode, resolveSearchOutcome, resolveStreamDelay, resolveStreamLimits, resolveSubagentConfigEntries, resolveSubagentConfigs, resolveToolOutcome, resolveWorkspacePath, resolveWorkspacePathSafe, runBashAstChecks, runPostEditSyntaxCheck, sanitizeOrphanToolBlocks, sanitizeRegex, selectRuntimeSessionHint, serializeMessage, serializeToolCallInput, setCommandAvailabilityCacheEntry, setFreshProviderMessageProvenance, setInvalidProviderMessageProvenance, setProviderMessageProvenance, shellQuote, shiftIndexTokenCountMap, shouldBypassProxy, shouldTriggerSummarization, sleep, smoothStream, spawnLocalProcess, splitAssistantTextContentByPhase, splitAtRecencyBoundary, stampSyntheticProviderMessage, strictAlternationProviders, stripAnthropicCacheControl, stripBedrockCacheControl, stripCodeSessionFileSummary, stripIntent, summarizeEvent, supportsBedrockToolCache, syncBudgetDerivedFields, toJsonSchema, tool, toolResultTypes, toolsCondition, truncateLocalOutput, truncateToolInput, truncateToolResultContent, tryFallbackProviders, unescapeObject, unwrapToolResponse, validateBashCommand, validateCloudflareBashCommand, videosSchema, withClientTimeout, withIntent, withMessageRole, withoutIntent };
|
|
121
|
+
export { ACTIVITY_LABEL_RUN_NAME, ACTIVITY_PHASE_LABEL_RUN_NAME, ACTIVITY_PHASE_RUN_NAME, AGENT_MODEL_CALL_RUN_NAME, AIMessage, AIMessageChunk, ANTHROPIC_TOOL_TOKEN_MULTIPLIER, ASK_USER_QUESTION_ID_PATTERN, AgentSession, BASH_SHELL_GUIDANCE, BaseCheckpointSaver, BaseMessage, BaseMessageChunk, BashExecutionToolDefinition, BashExecutionToolDescription, BashExecutionToolName, BashExecutionToolSchema, BashProgrammaticToolCallingDefinition, BashProgrammaticToolCallingDescription, BashProgrammaticToolCallingName, BashProgrammaticToolCallingSchema, BashToolOutputReferencesGuide, CALIBRATION_RATIO_MAX, CALIBRATION_RATIO_MIN, CLOUDFLARE_BASH_CODING_TOOL_NAMES, CLOUDFLARE_CODING_TOOL_NAMES, CODE_API_AUTHORIZATION_ERROR_MESSAGE, CODE_API_EXECUTION_FAILED_ERROR_MESSAGE, CODE_API_EXPECTED_PROFILE_HEADER, CODE_API_INVALID_REQUEST_ERROR_MESSAGE, CODE_API_RATE_LIMITED_ERROR_MESSAGE, CODE_API_UNAVAILABLE_ERROR_MESSAGE, CODE_ARTIFACT_PATH_GUIDANCE, CODE_EXECUTION_TOOLS, COMPACTION_SEMANTIC_INDEX_LIMITS, Calculator, CalculatorSchema, CalculatorToolDefinition, CalculatorToolDescription, CalculatorToolName, Callback, ChatModelStreamHandler, CloudflareBashExecutionToolDescription, CloudflareCodeExecutionToolDescription, CodeApiRequestError, CodeExecutionToolDefinition, CodeExecutionToolDescription, CodeExecutionToolName, CodeExecutionToolSchema, Command, CommonEvents, CompileCheckToolName, Constants, ContentTypes, DATE_RANGE, DEFAULT_CONTEXT_PRUNING_SETTINGS, DEFAULT_COUNTRY_DESCRIPTION, DEFAULT_HOOK_TIMEOUT_MS, DEFAULT_INTRA_TURN_RETAIN_RATIO, DEFAULT_MAX_SEALS, DEFAULT_MAX_TOOL_CALL_ARG_BYTES, DEFAULT_PROMPT_CACHE_TTL, DEFAULT_QUERY_DESCRIPTION, DEFAULT_RECURSION_LIMIT, DEFAULT_RESERVE_RATIO, DEFAULT_RETAIN_RECENT_TURNS, DEFAULT_STREAM_DELAY, DEFAULT_SUBAGENT_DESCRIPTION, DEFAULT_TOOL_TOKEN_MULTIPLIER, DynamicStructuredTool, EnvVar, EventActorExecutor, FAILED_EXECUTION_FILE_REMINDER, FakeChatModel, Graph, GraphEvents, GraphNodeActions, GraphNodeKeys, HARD_MAX_TOOL_RESULT_CHARS, HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE, HOOK_EVENTS, HOOK_INJECTED_MESSAGES_CAPABLE, HOOK_PREEMPT_BOUNDARY_CAPABLE, HandlerRegistry, HookRegistry, HumanMessage, IMAGE_TOKEN_SAFETY_MARGIN, INTENT_ARG, INTENT_DESCRIPTION, INTENT_LABEL_MARKER, INTENT_PROPERTY, INTERRUPT, InMemorySubagentTaskStore, JsonlSessionStore, LLMStreamHandler, LOCAL_CODING_BUNDLE_NAMES, LOCAL_CODING_TOOL_NAMES, LOCAL_SPAWN_TIMEOUT_MS, LocalBashExecutionToolDescription, LocalCodeExecutionToolDescription, LocalEditFileToolName, LocalEditFileToolSchema, LocalFileCheckpointerImpl, LocalGlobSearchToolName, LocalGlobSearchToolSchema, LocalGrepSearchToolName, LocalGrepSearchToolSchema, LocalListDirectoryToolName, LocalListDirectoryToolSchema, LocalReadFileToolSchema, LocalWriteFileToolName, LocalWriteFileToolSchema, MAX_ASK_USER_QUESTIONS, MAX_CACHE_SIZE, MAX_PATTERN_LENGTH, MULTI_AGENT_GRAPH_RUN_NAME, MemorySaver, ModelEndHandler, MultiAgentGraph, OPENAI_RESPONSES_ACTIVE_REASONING_ID_KEY, OPENAI_RESPONSES_REPLAY_POSITIONS_KEY, ORIGINAL_CONTENT_MAX_CHARS, PREDECESSOR_HANDOFF_CUE, PREEMPT_BOUNDARY_HOOK_TIMEOUT_MS, PROVIDER_MESSAGE_PROVENANCE_LIMITS, PROVIDER_MESSAGE_PROVENANCE_VERSION, ProgrammaticToolCallingDefinition, ProgrammaticToolCallingDescription, ProgrammaticToolCallingName, ProgrammaticToolCallingSchema, PromptTemplate, ProviderMessageProjectionInvariantError, Providers, REASONING_LABEL_RUN_NAME, REMOVE_ALL_MESSAGES, REPLY_PRIMER_TOKENS, ReadFileToolDefinition, ReadFileToolDescription, ReadFileToolName, ReadFileToolSchema, Run, Runnable, RunnableCallable, RunnableLambda, RunnableSequence, SDK_STREAM_DISPATCH, STANDARD_GRAPH_RUN_NAME, STATEFUL_BASH_NOTE, STATEFUL_ENV_NOTE, SessionManager, SkillToolDefinition, SkillToolDescription, SkillToolName, SkillToolSchema, StandardGraph, StatefulBashExecutionToolDescription, StatefulCodeExecutionToolDescription, StepTypes, StreamLimitExceededError, StructuredTool, SubagentExecutor, SubagentToolDefinition, SubagentToolDescription, SubagentToolName, SubagentToolSchema, SystemMessage, TMP_SCRATCH_OUTPUT_REMINDER, TOOL_APPROVAL_EXECUTION_SCOPE_CONFIG_KEY, TestChatStreamHandler, TestLLMStreamHandler, TitleMethod, TokenEncoderManager, Tool, ToolCallTypes, ToolEndHandler, ToolMessage, ToolNode, ToolSearchToolDefinition, ToolSearchToolDescription, ToolSearchToolName, ToolSearchToolSchema, UnsafeTokenMeasurementError, WebSearchToolDefinition, WebSearchToolDescription, WebSearchToolName, WebSearchToolSchema, _createBashProgramForTests, _resetLocalEngineWarningsForTests, _resetRipgrepCacheForTests, _resetSyntaxCheckProbeCacheForTests, _resetUnrecognizedTriggerWarnings, addBedrockCacheControl, addBedrockTailCacheControl, addCacheControl, addCacheControlToStablePrefixMessages, addCodeApiExecutionProfileHeader, addTailCacheControl, appendCodeSessionFileSummary, appendFailedExecutionFileReminder, appendPredecessorHandoffCue, appendProviderMessageProvenance, appendTmpScratchReminder, applyContextPruning, applyEdit, applyOutcome, applyPreToolUseHooksForBridge, apportionTokenCounts, askUserQuestion, askUserQuestions, attemptInvoke, bashAstFindingsToErrors, buildAnthropicCacheControl, buildBashExecutionToolDescription, buildBashExecutionToolSchema, buildBedrockCachePoint, buildChildInputs, buildCodeApiEndpoint, buildCodeApiExecutionErrorMessage, buildCodeApiHttpErrorMessage, buildCodeExecutionToolDescription, buildCodeExecutionToolSchema, buildSandboxRuntimeConfig, buildSubagentToolParams, calculateMaxToolCallInputChars, calculateMaxToolResultChars, calculateMaxTotalToolOutputSize, calculateTotalTokens, canSealPreempt, checkValidNumber, clampCalibrationRatio, classifyAttachment, clientExecTimeoutMs, clientFsTimeoutMs, cloneMessage, coalesceAdjacentUserTurns, commandAvailabilityEnvCacheKey, compactSyntheticProviderContextMessage, composeAbortSignals, composeEventHandlers, computeAdaptivePieceSize, constructorChainHasLcName, convertInjectedMessages, convertMessagesToContent, countNestedGroups, countrySchema, createAgentSession, createBashExecutionTool, createBashProgrammaticToolCallingSchema, createBashProgrammaticToolCallingTool, createCloudflareBashExecutionTool, createCloudflareBashProgrammaticToolCallingTool, createCloudflareBridgeRuntime, createCloudflareCodeExecutionTool, createCloudflareCodingToolBundle, createCloudflareCodingTools, createCloudflareExecutionTool, createCloudflareExecutionWorld, createCloudflareLocalExecutionConfig, createCloudflareProgrammaticToolCallingTool, createCloudflareWorkspaceFS, createCodeExecutionTool, createCompileCheckTool, createCompileCheckToolDefinition, createContentAggregator, createEventActorExecutor, createFakeStreamingLLM, createGraph, createHandlers, createLocalBashExecutionTool, createLocalBashProgrammaticToolCallingTool, createLocalCodeExecutionTool, createLocalCodingToolBundle, createLocalCodingToolDefinitions, createLocalCodingToolRegistry, createLocalCodingTools, createLocalEditFileTool, createLocalFileCheckpointer, createLocalGlobSearchTool, createLocalGrepSearchTool, createLocalListDirectoryTool, createLocalProgrammaticToolCallingTool, createLocalReadFileTool, createLocalWriteFileTool, createMetadataAggregator, createProgrammaticToolCallingSchema, createProgrammaticToolCallingTool, createPruneMessages, createRemoveAllMessage, createRunHandlers, createSchemaOnlyTool, createSchemaOnlyTools, createSearchTool, createSubagentToolDefinition, createTokenCounter, createToolErrorOwnership, createToolPolicyHook, createToolSearch, createWorkspacePolicyHook, dateSchema, decodeFile, defaultOmitOptions, deriveMessages, deserializeMessage, dispatchesChatModelStream, dropIncompleteToolStreamContent, emptyOutputMessage, encodeFile, encodingForModel, enforceOriginalContentCap, ensureThinkingBlockInMessages, escapeRegexSpecialChars, estimateAnthropicImageTokens, estimateDocumentBlockTokens, estimateImageBlockTokens, estimateOpenAIImageTokens, estimateTimedMediaBlockTokens, execWithClientTimeout, executeCloudflareBash, executeCloudflareCode, executeHooks, executeLocalBash, executeLocalBashWithArgs, executeLocalCode, executeParallelSearches, executeTools, extractErrorMessage, extractImageDimensions, extractMcpServerName, extractTextFromContent, extractToolDiscoveries, extractUsedBashToolNames, extractUsedToolNames, fetchSessionFiles, filterBashToolsByUsage, filterGraphSubagentResult, filterSubagentResult, filterToolsByUsage, findLastIndex, flattenLegacyContent, foldToolBlocksForToollessAgent, formatAgentMessages, formatAnthropicArtifactContent, formatAnthropicMessage, formatArtifactPayload, formatCloudflareOutput, formatCompletedResponse, formatContentStrings, formatFromLangChain, formatLangChainMessages, formatMediaMessage, formatMessage, formatServerListing, formatSkillCatalog, getAssistantTextPhase, getAvailableMcpServers, getBaseToolName, getBufferString, getChatModelClass, getChunkContent, getCloudflareWorkspaceRoot, getCodeBaseURL, getContextOverflowInfo, getConverseOverrideMessage, getDeferredToolsListing, getExecutionWorld, getLocalCwd, getLocalSessionId, getMaxOutputTokensKey, getMessageCreationContentMetadata, getMessageId, getMessagesWithinTokenLimit, getProviderMessageProvenance, getProviderSourceMessageIds, getReadRoots, getSpawn, getTokenCountForMessage, getWorkspaceFS, getWorkspaceRoots, getWriteRoots, handleServerToolResult, handleToolCallChunks, handleToolCalls, hasBijectiveProviderContentPartMapping, hasNestedQuantifier, hasNestedQuantifiers, hasToolSearchInCurrentTurn, hasUnsafeStructuredSerialization, imageAttachmentContent, imagesSchema, initializeModel, inspectProviderMessageProjection, inspectProviderMessageProvenance, inspectProviderSourceMessageIds, interrupt, isAIMessage, isAnthropicLike, isAskUserQuestionsInterrupt, isBaseMessage, isContextOverflowError, isDangerousPattern, isFromAnyMcpServer, isFromMcpServer, isGoogleLike, isGraphSubagentConfig, isIntentLabelProperty, isInterrupted, isLegacyConvertible, isLibreChatOpenAIModel, isLikelyContextOverflowError, isOpenAILike, isPresent, isProgrammaticRunnerAutoBound, isProgrammaticRunnerResolvedDirectly, isSyntheticProviderContextMessage, isThinkingEnabled, isToolMessage, isZodSchema, joinKeys, labelContentByAgent, locateEdit, makeIsDeferred, makeRequest, mapChatMessagesToStoredMessages, mapStoredMessagesToChatMessages, markTokenCounterCacheCompatible, maskConsumedToolResults, matchesQuery, messagesStateReducer, modifyDeltaProperties, newsSchema, nodeExecutionWorld, normalizeBashToolResultsForReplay, normalizeCodeApiRequestError, normalizeServerFilter, normalizeSubagentConfigEntries, normalizeSubagentConfigs, normalizeToBashIdentifier, normalizeToPythonIdentifier, outcomeFieldsFromResult, parseBooleanEnv, partitionAndMarkAnthropicToolCache, performLocalSearch, preFlightTruncateToolCallInputs, preFlightTruncateToolResults, prepareProviderRequest, probeLocalCommandAvailability, projectAgentContextUsage, projectAnthropicArtifactContent, projectArtifactPayload, projectCacheControlledToolOutputsToText, projectComputerCallOutputsToText, projectOpenAIChatToolMessageContent, projectOpenAIResponsesToolMessageContent, projectOpenAIToolMessageContent, projectOpenRouterToolMessageContent, projectSingleTextToolOutputsToText, projectStructuredToolOutputsToText, projectToolCallInputs, projectToolMessagesForProvider, projectToolStreamContentForProvider, querySchema, readIntent, readOutcomeFields, registerProvider, removePredecessorHandoffCue, repairOrphanedToolMessages, resetIfNotEmpty, resolveBedrockPromptCacheTtl, resolveCloudflareSandbox, resolveCodeApiAuthHeaders, resolveContextPruningSettings, resolveFetchProxyAgent, resolveIntraTurnRetainTokens, resolveLocalExecutionConfig, resolveLocalExecutionTools, resolveLocalImplementationNames, resolveLocalToolRegistry, resolveLocalToolsForBinding, resolvePromptCacheTtl, resolveProviderMessageProjectionInvariantMode, resolveSearchOutcome, resolveStreamDelay, resolveStreamLimits, resolveSubagentConfigEntries, resolveSubagentConfigs, resolveToolOutcome, resolveWorkspacePath, resolveWorkspacePathSafe, runBashAstChecks, runPostEditSyntaxCheck, sanitizeOrphanToolBlocks, sanitizeRegex, selectRuntimeSessionHint, serializeMessage, serializeToolCallInput, setCommandAvailabilityCacheEntry, setFreshProviderMessageProvenance, setInvalidProviderMessageProvenance, setProviderMessageProvenance, shellQuote, shiftIndexTokenCountMap, shouldBypassProxy, shouldTriggerSummarization, sleep, smoothStream, spawnLocalProcess, splitAssistantTextContentByPhase, splitAtRecencyBoundary, stampSyntheticProviderMessage, strictAlternationProviders, stripAnthropicCacheControl, stripBedrockCacheControl, stripCodeSessionFileSummary, stripIntent, summarizeEvent, supportsBedrockToolCache, syncBudgetDerivedFields, toJsonSchema, tool, toolResultTypes, toolsCondition, truncateLocalOutput, truncateToolInput, truncateToolResultContent, tryFallbackProviders, unescapeObject, unwrapToolResponse, validateBashCommand, validateCloudflareBashCommand, videosSchema, withClientTimeout, withIntent, withMessageRole, withoutIntent };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { COMPACTION_SEMANTIC_INDEX_LIMITS } from "../common/constants.mjs";
|
|
1
2
|
import "../common/enum.mjs";
|
|
2
3
|
import "../common/index.mjs";
|
|
3
4
|
import { HARD_MAX_TOOL_RESULT_CHARS } from "../utils/truncation.mjs";
|
|
@@ -5,6 +6,7 @@ import { compactToolContent, getToolContentCharLength, isAtomicToolContentBlock,
|
|
|
5
6
|
import { hasBijectiveProviderContentPartMapping, inspectProviderMessageProvenance, inspectProviderSourceMessageIds, setFreshProviderMessageProvenance, setInvalidProviderMessageProvenance, setProviderMessageProvenance } from "./provenance.mjs";
|
|
6
7
|
import { toLangChainContent, toLangChainMessageFields } from "./langchain.mjs";
|
|
7
8
|
import { appendProviderToolCallDescriptor, consumeProviderToolResultPair, getBoundedProviderPairingArrayProperty, getProviderToolCallPartDescriptor, getProviderToolResultPartDescriptor, hasStructurallyValidAnthropicWebSearchResultContent } from "./toolResultTypes.mjs";
|
|
9
|
+
import { setCompactionSemanticIndexProvidedEntryCount } from "../summarization/semanticIndex.mjs";
|
|
8
10
|
import { normalizeAnthropicToolCallId } from "../llm/anthropic/utils/message_inputs.mjs";
|
|
9
11
|
import { flattenLegacyContent, isLegacyConvertible } from "./content.mjs";
|
|
10
12
|
import { emitAgentLog } from "../utils/events.mjs";
|
|
@@ -140,6 +142,281 @@ function getToolUseId(part) {
|
|
|
140
142
|
if (!("tool_use_id" in part) || typeof part.tool_use_id !== "string") return;
|
|
141
143
|
return part.tool_use_id;
|
|
142
144
|
}
|
|
145
|
+
const DERIVED_SEMANTIC_HEAD_LIMIT = COMPACTION_SEMANTIC_INDEX_LIMITS.maxInputEntries / 4;
|
|
146
|
+
const DERIVED_SEMANTIC_TAIL_LIMIT = COMPACTION_SEMANTIC_INDEX_LIMITS.maxInputEntries / 2;
|
|
147
|
+
const DERIVED_SEMANTIC_TYPE_EDGE_LIMIT = COMPACTION_SEMANTIC_INDEX_LIMITS.maxInputEntries / 32;
|
|
148
|
+
const DERIVED_SEMANTIC_TYPE_HASH = Object.freeze({
|
|
149
|
+
tool_intent: 1,
|
|
150
|
+
tool_outcome: 2,
|
|
151
|
+
activity_phase: 3,
|
|
152
|
+
reasoning_label: 4
|
|
153
|
+
});
|
|
154
|
+
function createDerivedCompactionSemanticIndexCollector() {
|
|
155
|
+
return {
|
|
156
|
+
entries: [],
|
|
157
|
+
entryCount: 0
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function createCompactionSemanticCoverageState() {
|
|
161
|
+
return {
|
|
162
|
+
head: [],
|
|
163
|
+
tail: {
|
|
164
|
+
entries: [],
|
|
165
|
+
cursor: 0
|
|
166
|
+
},
|
|
167
|
+
latestByIdentityHash: /* @__PURE__ */ new Map(),
|
|
168
|
+
typeCoverage: /* @__PURE__ */ new Map()
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function getDerivedCompactionSemanticLocalId(entry) {
|
|
172
|
+
if (entry.type === "reasoning_label") return entry.reasoningStepId.trim();
|
|
173
|
+
if (entry.type !== "activity_phase") return entry.toolCallId.trim();
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
function hashDerivedCompactionSemanticIdentityString(initialHash, value) {
|
|
177
|
+
let hash = initialHash;
|
|
178
|
+
for (let index = 0; index < value.length; index++) {
|
|
179
|
+
hash ^= value.charCodeAt(index);
|
|
180
|
+
hash = Math.imul(hash, 16777619);
|
|
181
|
+
}
|
|
182
|
+
return hash;
|
|
183
|
+
}
|
|
184
|
+
function hashDerivedCompactionSemanticIdentity(entry) {
|
|
185
|
+
let hash = 2166136261 ^ DERIVED_SEMANTIC_TYPE_HASH[entry.type];
|
|
186
|
+
hash = Math.imul(hash, 16777619);
|
|
187
|
+
hash = hashDerivedCompactionSemanticIdentityString(hash, entry.sourceMessageId.trim());
|
|
188
|
+
hash ^= entry.sourceContentIndex;
|
|
189
|
+
hash = Math.imul(hash, 16777619);
|
|
190
|
+
hash = hashDerivedCompactionSemanticIdentityString(hash, getDerivedCompactionSemanticLocalId(entry));
|
|
191
|
+
return hash >>> 0;
|
|
192
|
+
}
|
|
193
|
+
function entriesShareDerivedCompactionSemanticIdentity(left, right) {
|
|
194
|
+
return left.type === right.type && left.sourceMessageId.trim() === right.sourceMessageId.trim() && left.sourceContentIndex === right.sourceContentIndex && getDerivedCompactionSemanticLocalId(left) === getDerivedCompactionSemanticLocalId(right);
|
|
195
|
+
}
|
|
196
|
+
function entriesHaveConflictingSemanticState(left, right) {
|
|
197
|
+
return left.status !== right.status || left.redacted === true !== (right.redacted === true) || left.text.replace(/\s+/g, " ").trim() !== right.text.replace(/\s+/g, " ").trim();
|
|
198
|
+
}
|
|
199
|
+
function retainCompactionSemanticEntry(entry) {
|
|
200
|
+
entry.retentionCount++;
|
|
201
|
+
}
|
|
202
|
+
function releaseCompactionSemanticEntry(coverage, entry) {
|
|
203
|
+
entry.retentionCount--;
|
|
204
|
+
if (entry.retentionCount === 0 && coverage.latestByIdentityHash.has(entry.identityHash)) {
|
|
205
|
+
const bucket = coverage.latestByIdentityHash.get(entry.identityHash);
|
|
206
|
+
if (bucket == null) return;
|
|
207
|
+
const entryIndex = bucket.indexOf(entry);
|
|
208
|
+
if (entryIndex >= 0) bucket.splice(entryIndex, 1);
|
|
209
|
+
if (bucket.length === 0) coverage.latestByIdentityHash.delete(entry.identityHash);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function appendCompactionSemanticEntryRing(coverage, ring, entry, limit) {
|
|
213
|
+
if (ring.entries.length < limit) {
|
|
214
|
+
ring.entries.push(entry);
|
|
215
|
+
retainCompactionSemanticEntry(entry);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
releaseCompactionSemanticEntry(coverage, ring.entries[ring.cursor]);
|
|
219
|
+
ring.entries[ring.cursor] = entry;
|
|
220
|
+
retainCompactionSemanticEntry(entry);
|
|
221
|
+
ring.cursor = (ring.cursor + 1) % limit;
|
|
222
|
+
}
|
|
223
|
+
function renewCompactionSemanticEntryRing(coverage, ring, entry, limit) {
|
|
224
|
+
const existingIndex = ring.entries.indexOf(entry);
|
|
225
|
+
if (existingIndex < 0) {
|
|
226
|
+
appendCompactionSemanticEntryRing(coverage, ring, entry, limit);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (ring.entries.length < limit) {
|
|
230
|
+
ring.entries.splice(existingIndex, 1);
|
|
231
|
+
ring.entries.push(entry);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const newestIndex = (ring.cursor + ring.entries.length - 1) % ring.entries.length;
|
|
235
|
+
let currentIndex = existingIndex;
|
|
236
|
+
for (let offset = 0; currentIndex !== newestIndex && offset < ring.entries.length; offset++) {
|
|
237
|
+
const nextIndex = (currentIndex + 1) % ring.entries.length;
|
|
238
|
+
ring.entries[currentIndex] = ring.entries[nextIndex];
|
|
239
|
+
currentIndex = nextIndex;
|
|
240
|
+
}
|
|
241
|
+
ring.entries[newestIndex] = entry;
|
|
242
|
+
}
|
|
243
|
+
function renewCoverageBalancedCompactionSemanticEntry(coverage, entry) {
|
|
244
|
+
renewCompactionSemanticEntryRing(coverage, coverage.tail, entry, DERIVED_SEMANTIC_TAIL_LIMIT);
|
|
245
|
+
const typeCoverage = coverage.typeCoverage.get(entry.entry.type);
|
|
246
|
+
if (typeCoverage == null) return;
|
|
247
|
+
renewCompactionSemanticEntryRing(coverage, typeCoverage.tail, entry, DERIVED_SEMANTIC_TYPE_EDGE_LIMIT);
|
|
248
|
+
}
|
|
249
|
+
function appendDerivedCompactionSemanticEntry(collector, entry) {
|
|
250
|
+
let boundedEntry = entry;
|
|
251
|
+
if (entry.status === "pending") boundedEntry = {
|
|
252
|
+
...entry,
|
|
253
|
+
text: ""
|
|
254
|
+
};
|
|
255
|
+
else if (entry.text.length > COMPACTION_SEMANTIC_INDEX_LIMITS.maxInputTextChars) boundedEntry = {
|
|
256
|
+
...entry,
|
|
257
|
+
text: "",
|
|
258
|
+
redacted: true
|
|
259
|
+
};
|
|
260
|
+
const order = collector.entryCount;
|
|
261
|
+
collector.entryCount++;
|
|
262
|
+
if (collector.coverage == null && collector.entries.length < COMPACTION_SEMANTIC_INDEX_LIMITS.maxInputEntries) {
|
|
263
|
+
collector.entries.push(boundedEntry);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const orderedEntry = {
|
|
267
|
+
entry: boundedEntry,
|
|
268
|
+
identityHash: hashDerivedCompactionSemanticIdentity(boundedEntry),
|
|
269
|
+
order,
|
|
270
|
+
retentionCount: 0
|
|
271
|
+
};
|
|
272
|
+
if (collector.coverage == null) {
|
|
273
|
+
collector.coverage = createCompactionSemanticCoverageState();
|
|
274
|
+
for (let order = 0; order < collector.entries.length; order++) appendCoverageBalancedCompactionSemanticEntry(collector.coverage, {
|
|
275
|
+
entry: collector.entries[order],
|
|
276
|
+
identityHash: hashDerivedCompactionSemanticIdentity(collector.entries[order]),
|
|
277
|
+
order,
|
|
278
|
+
retentionCount: 0
|
|
279
|
+
});
|
|
280
|
+
collector.entries = [];
|
|
281
|
+
}
|
|
282
|
+
appendCoverageBalancedCompactionSemanticEntry(collector.coverage, orderedEntry);
|
|
283
|
+
}
|
|
284
|
+
function appendCoverageBalancedCompactionSemanticEntry(coverage, orderedEntry) {
|
|
285
|
+
const identityHash = orderedEntry.identityHash;
|
|
286
|
+
const identityBucket = coverage.latestByIdentityHash.get(identityHash);
|
|
287
|
+
const current = identityBucket?.find(({ entry }) => entriesShareDerivedCompactionSemanticIdentity(entry, orderedEntry.entry));
|
|
288
|
+
if (current != null) {
|
|
289
|
+
if (orderedEntry.entry.revision < current.entry.revision) return;
|
|
290
|
+
if (orderedEntry.entry.revision === current.entry.revision) {
|
|
291
|
+
if (entriesHaveConflictingSemanticState(current.entry, orderedEntry.entry)) {
|
|
292
|
+
current.entry = {
|
|
293
|
+
...current.entry,
|
|
294
|
+
text: "",
|
|
295
|
+
redacted: true
|
|
296
|
+
};
|
|
297
|
+
current.order = orderedEntry.order;
|
|
298
|
+
renewCoverageBalancedCompactionSemanticEntry(coverage, current);
|
|
299
|
+
}
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
current.entry = orderedEntry.entry;
|
|
303
|
+
current.order = orderedEntry.order;
|
|
304
|
+
renewCoverageBalancedCompactionSemanticEntry(coverage, current);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (identityBucket == null) coverage.latestByIdentityHash.set(identityHash, [orderedEntry]);
|
|
308
|
+
else identityBucket.push(orderedEntry);
|
|
309
|
+
if (coverage.head.length < DERIVED_SEMANTIC_HEAD_LIMIT) {
|
|
310
|
+
coverage.head.push(orderedEntry);
|
|
311
|
+
retainCompactionSemanticEntry(orderedEntry);
|
|
312
|
+
}
|
|
313
|
+
appendCompactionSemanticEntryRing(coverage, coverage.tail, orderedEntry, DERIVED_SEMANTIC_TAIL_LIMIT);
|
|
314
|
+
let typeCoverage = coverage.typeCoverage.get(orderedEntry.entry.type);
|
|
315
|
+
if (typeCoverage == null) {
|
|
316
|
+
typeCoverage = {
|
|
317
|
+
head: [],
|
|
318
|
+
tail: {
|
|
319
|
+
entries: [],
|
|
320
|
+
cursor: 0
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
coverage.typeCoverage.set(orderedEntry.entry.type, typeCoverage);
|
|
324
|
+
}
|
|
325
|
+
if (typeCoverage.head.length < DERIVED_SEMANTIC_TYPE_EDGE_LIMIT) {
|
|
326
|
+
typeCoverage.head.push(orderedEntry);
|
|
327
|
+
retainCompactionSemanticEntry(orderedEntry);
|
|
328
|
+
}
|
|
329
|
+
appendCompactionSemanticEntryRing(coverage, typeCoverage.tail, orderedEntry, DERIVED_SEMANTIC_TYPE_EDGE_LIMIT);
|
|
330
|
+
}
|
|
331
|
+
function finalizeDerivedCompactionSemanticIndex(collector) {
|
|
332
|
+
if (collector == null || collector.entryCount === 0) return;
|
|
333
|
+
if (collector.coverage == null) {
|
|
334
|
+
setCompactionSemanticIndexProvidedEntryCount(collector.entries, collector.entryCount);
|
|
335
|
+
return collector.entries;
|
|
336
|
+
}
|
|
337
|
+
const retained = /* @__PURE__ */ new Map();
|
|
338
|
+
const retain = (entries) => {
|
|
339
|
+
for (const { entry, order } of entries) retained.set(order, entry);
|
|
340
|
+
};
|
|
341
|
+
retain(collector.coverage.head);
|
|
342
|
+
retain(collector.coverage.tail.entries);
|
|
343
|
+
for (const typeCoverage of collector.coverage.typeCoverage.values()) {
|
|
344
|
+
retain(typeCoverage.head);
|
|
345
|
+
retain(typeCoverage.tail.entries);
|
|
346
|
+
}
|
|
347
|
+
const result = [...retained.entries()].sort(([left], [right]) => left - right).map(([, entry]) => entry);
|
|
348
|
+
setCompactionSemanticIndexProvidedEntryCount(result, collector.entryCount);
|
|
349
|
+
return result;
|
|
350
|
+
}
|
|
351
|
+
function collectCompactionSemanticEntriesFromPart(collector, part, sourceMessageId, sourceContentIndex, retainedSourceContentStart, retainedSourceContentEnd, intentToolNames, parsedToolInput) {
|
|
352
|
+
if (sourceMessageId.length > COMPACTION_SEMANTIC_INDEX_LIMITS.maxIdentityChars) return;
|
|
353
|
+
if (part.type === "tool_call") {
|
|
354
|
+
if (sourceContentIndex < 0 || sourceContentIndex > COMPACTION_SEMANTIC_INDEX_LIMITS.maxSourceContentIndex) return;
|
|
355
|
+
const toolCall = part.tool_call;
|
|
356
|
+
const toolCallId = toolCall?.id;
|
|
357
|
+
if (typeof toolCallId !== "string" || toolCallId === "" || toolCallId.length > COMPACTION_SEMANTIC_INDEX_LIMITS.maxIdentityChars) return;
|
|
358
|
+
if (typeof toolCall.name === "string" && intentToolNames?.has(toolCall.name) === true) {
|
|
359
|
+
const intent = parsedToolInput != null && typeof parsedToolInput === "object" && !Array.isArray(parsedToolInput) ? parsedToolInput.intent : void 0;
|
|
360
|
+
if (typeof intent === "string" && intent !== "") appendDerivedCompactionSemanticEntry(collector, {
|
|
361
|
+
type: "tool_intent",
|
|
362
|
+
sourceMessageId,
|
|
363
|
+
sourceContentIndex,
|
|
364
|
+
revision: 0,
|
|
365
|
+
status: "committed",
|
|
366
|
+
text: intent,
|
|
367
|
+
toolCallId
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
if (typeof toolCall.outcome === "string" && toolCall.outcome !== "") appendDerivedCompactionSemanticEntry(collector, {
|
|
371
|
+
type: "tool_outcome",
|
|
372
|
+
sourceMessageId,
|
|
373
|
+
sourceContentIndex,
|
|
374
|
+
revision: 0,
|
|
375
|
+
status: "committed",
|
|
376
|
+
text: toolCall.outcome,
|
|
377
|
+
toolCallId
|
|
378
|
+
});
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (part.type === "think") {
|
|
382
|
+
if (sourceContentIndex < 0 || sourceContentIndex > COMPACTION_SEMANTIC_INDEX_LIMITS.maxSourceContentIndex) return;
|
|
383
|
+
const reasoningStepId = part.reasoning_label_step_id;
|
|
384
|
+
const revision = part.reasoning_label_revision;
|
|
385
|
+
const status = part.reasoning_label_status;
|
|
386
|
+
const text = part.reasoning_label;
|
|
387
|
+
if (typeof reasoningStepId !== "string" || reasoningStepId === "" || reasoningStepId.length > COMPACTION_SEMANTIC_INDEX_LIMITS.maxIdentityChars || typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 0) return;
|
|
388
|
+
const malformedState = status !== "complete" && status !== "streaming" || typeof text !== "string";
|
|
389
|
+
appendDerivedCompactionSemanticEntry(collector, {
|
|
390
|
+
type: "reasoning_label",
|
|
391
|
+
sourceMessageId,
|
|
392
|
+
sourceContentIndex,
|
|
393
|
+
revision,
|
|
394
|
+
status: status === "streaming" || malformedState ? "pending" : "committed",
|
|
395
|
+
text: typeof text === "string" ? text : "",
|
|
396
|
+
reasoningStepId,
|
|
397
|
+
...malformedState ? { redacted: true } : {}
|
|
398
|
+
});
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (part.type !== "activity_label" || part.activity_label_type !== "phase") return;
|
|
402
|
+
const activitySourceContentIndex = part.activity_start_index;
|
|
403
|
+
if (typeof activitySourceContentIndex !== "number" || !Number.isSafeInteger(activitySourceContentIndex) || activitySourceContentIndex < retainedSourceContentStart || activitySourceContentIndex >= retainedSourceContentEnd || activitySourceContentIndex > COMPACTION_SEMANTIC_INDEX_LIMITS.maxSourceContentIndex) return;
|
|
404
|
+
const revision = part.activity_label_revision;
|
|
405
|
+
if (revision !== void 0 && (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 0)) return;
|
|
406
|
+
const malformedPending = part.pending !== void 0 && typeof part.pending !== "boolean";
|
|
407
|
+
const malformedText = typeof part.activity_label !== "string";
|
|
408
|
+
const malformedState = malformedPending || malformedText;
|
|
409
|
+
const text = typeof part.activity_label === "string" ? part.activity_label : "";
|
|
410
|
+
appendDerivedCompactionSemanticEntry(collector, {
|
|
411
|
+
type: "activity_phase",
|
|
412
|
+
sourceMessageId,
|
|
413
|
+
sourceContentIndex: activitySourceContentIndex,
|
|
414
|
+
revision: revision ?? 0,
|
|
415
|
+
status: part.pending === true || malformedPending ? "pending" : "committed",
|
|
416
|
+
text,
|
|
417
|
+
...malformedState ? { redacted: true } : {}
|
|
418
|
+
});
|
|
419
|
+
}
|
|
143
420
|
function collectTrustedToolResultSourceContentPartIndices(content, sourceContentPartOffset) {
|
|
144
421
|
if (content == null) return;
|
|
145
422
|
let calls;
|
|
@@ -295,6 +572,10 @@ function formatAssistantMessage(message, options) {
|
|
|
295
572
|
const emittedServerToolUseIds = /* @__PURE__ */ new Set();
|
|
296
573
|
const pendingServerToolUses = /* @__PURE__ */ new Map();
|
|
297
574
|
const shouldPreserveReasoningContent = options?.preserveReasoningContent === true;
|
|
575
|
+
const compactionSemanticIndex = options?.compactionSemanticIndex;
|
|
576
|
+
const semanticSourceMessageId = compactionSemanticIndex != null && options?.sourceMessageId != null && options.sourceMessageId.length <= COMPACTION_SEMANTIC_INDEX_LIMITS.maxIdentityChars ? options.sourceMessageId : void 0;
|
|
577
|
+
const retainedSourceContentStart = options?.sourceContentPartOffset ?? 0;
|
|
578
|
+
const retainedSourceContentEnd = options?.retainedSourceContentEnd ?? retainedSourceContentStart;
|
|
298
579
|
const serverToolResultIds = /* @__PURE__ */ new Set();
|
|
299
580
|
const preferredToolCallParts = /* @__PURE__ */ new Map();
|
|
300
581
|
const takePendingReasoningContent = () => {
|
|
@@ -353,6 +634,7 @@ function formatAssistantMessage(message, options) {
|
|
|
353
634
|
for (let partIndex = 0; partIndex < contentParts.length; partIndex++) {
|
|
354
635
|
const part = contentParts[partIndex];
|
|
355
636
|
if (part == null) continue;
|
|
637
|
+
if (part.type === "activity_label") continue;
|
|
356
638
|
const isTrustedResult = isTrustedServerToolResult(part, getSourcePartIndices(partIndex), options?.toolSourceContentPartIndices);
|
|
357
639
|
if (isTrustedResult) {
|
|
358
640
|
trustedServerToolResultPartIndices ??= /* @__PURE__ */ new Set();
|
|
@@ -374,6 +656,10 @@ function formatAssistantMessage(message, options) {
|
|
|
374
656
|
const part = contentParts[partIndex];
|
|
375
657
|
if (part == null) continue;
|
|
376
658
|
const sourcePartIndices = getSourcePartIndices(partIndex);
|
|
659
|
+
if (part.type === "activity_label") {
|
|
660
|
+
if (compactionSemanticIndex != null && semanticSourceMessageId != null && typeof sourcePartIndices === "number") collectCompactionSemanticEntriesFromPart(compactionSemanticIndex, part, semanticSourceMessageId, sourcePartIndices, retainedSourceContentStart, retainedSourceContentEnd, options?.intentToolNames);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
377
663
|
const toolUseId = getToolUseId(part);
|
|
378
664
|
if (toolUseId != null) {
|
|
379
665
|
const isServerToolResult = trustedServerToolResultPartIndices?.has(partIndex) === true;
|
|
@@ -418,12 +704,14 @@ function formatAssistantMessage(message, options) {
|
|
|
418
704
|
if (options?.provider === "anthropic" && typeof _tool_call.id === "string" && _tool_call.id.startsWith("srvtoolu_")) {
|
|
419
705
|
if (!serverToolResultIds.has(_tool_call.id) && options.preserveUnpairedServerToolUses !== true) continue;
|
|
420
706
|
if (emittedServerToolUseIds.has(_tool_call.id) || pendingServerToolUses.has(_tool_call.id)) continue;
|
|
707
|
+
const serverToolInput = parseServerToolInput(_args);
|
|
708
|
+
if (compactionSemanticIndex != null && semanticSourceMessageId != null && typeof sourcePartIndices === "number") collectCompactionSemanticEntriesFromPart(compactionSemanticIndex, part, semanticSourceMessageId, sourcePartIndices, retainedSourceContentStart, retainedSourceContentEnd, options.intentToolNames, serverToolInput);
|
|
421
709
|
pendingServerToolUses.set(_tool_call.id, {
|
|
422
710
|
content: {
|
|
423
711
|
type: "server_tool_use",
|
|
424
712
|
id: _tool_call.id,
|
|
425
713
|
name: _tool_call.name,
|
|
426
|
-
input:
|
|
714
|
+
input: serverToolInput
|
|
427
715
|
},
|
|
428
716
|
sourceContentPartIndices: sourcePartIndices
|
|
429
717
|
});
|
|
@@ -442,6 +730,7 @@ function formatAssistantMessage(message, options) {
|
|
|
442
730
|
if (typeof _args === "string") args = { input: _args };
|
|
443
731
|
}
|
|
444
732
|
tool_call.args = args;
|
|
733
|
+
if (compactionSemanticIndex != null && semanticSourceMessageId != null && typeof sourcePartIndices === "number") collectCompactionSemanticEntriesFromPart(compactionSemanticIndex, part, semanticSourceMessageId, sourcePartIndices, retainedSourceContentStart, retainedSourceContentEnd, options?.intentToolNames, args);
|
|
445
734
|
if (options?.provider === "anthropic" && Array.isArray(lastAIMessage.content)) {
|
|
446
735
|
const content = lastAIMessage.content;
|
|
447
736
|
content.push({
|
|
@@ -461,6 +750,7 @@ function formatAssistantMessage(message, options) {
|
|
|
461
750
|
content: formatToolCallOutput(output)
|
|
462
751
|
}), "tool"), "tool", sourcePartIndices);
|
|
463
752
|
} else if (part.type === "think" || part.type === "thinking" || part.type === "reasoning" || part.type === "reasoning_content" || part.type === "redacted_thinking") {
|
|
753
|
+
if (part.type === "think" && compactionSemanticIndex != null && semanticSourceMessageId != null && typeof sourcePartIndices === "number") collectCompactionSemanticEntriesFromPart(compactionSemanticIndex, part, semanticSourceMessageId, sourcePartIndices, retainedSourceContentStart, retainedSourceContentEnd, options?.intentToolNames);
|
|
464
754
|
hasReasoning = true;
|
|
465
755
|
pendingReasoningContent += extractReasoningContent(part);
|
|
466
756
|
appendSourceContentPartIndices(pendingReasoningSourcePartIndices, sourcePartIndices);
|
|
@@ -487,7 +777,7 @@ function formatAssistantMessage(message, options) {
|
|
|
487
777
|
hasReasoning = false;
|
|
488
778
|
pendingReasoningContent = "";
|
|
489
779
|
pendingReasoningSourcePartIndices = [];
|
|
490
|
-
} else if (part.type === "error" || part.type === "agent_update" || part.type === "summary"
|
|
780
|
+
} else if (part.type === "error" || part.type === "agent_update" || part.type === "summary") continue;
|
|
491
781
|
else {
|
|
492
782
|
if (part.type === "text" && !getTextContent(part).trim()) continue;
|
|
493
783
|
currentContent.push(part);
|
|
@@ -764,6 +1054,7 @@ function extractSkillName(args) {
|
|
|
764
1054
|
const formatAgentMessages = (payload, indexTokenCountMap, tools, skills, options) => {
|
|
765
1055
|
const messages = [];
|
|
766
1056
|
const legacyContentEnabled = options?.legacyContent === true;
|
|
1057
|
+
const compactionSemanticIndexCollector = options?.compactionSemanticIndex != null ? createDerivedCompactionSemanticIndexCollector() : void 0;
|
|
767
1058
|
const emitFormattedMessage = (message) => {
|
|
768
1059
|
if (legacyContentEnabled && isLegacyConvertible(message)) {
|
|
769
1060
|
const flattened = flattenLegacyContent(message.content);
|
|
@@ -914,9 +1205,12 @@ const formatAgentMessages = (payload, indexTokenCountMap, tools, skills, options
|
|
|
914
1205
|
}
|
|
915
1206
|
}
|
|
916
1207
|
const formattedMessages = formatAssistantMessage(processedMessage, {
|
|
1208
|
+
compactionSemanticIndex: compactionSemanticIndexCollector,
|
|
1209
|
+
intentToolNames: options?.compactionSemanticIndex?.intentToolNames,
|
|
917
1210
|
preserveUnpairedServerToolUses: i === payload.length - 1,
|
|
918
1211
|
preserveReasoningContent: options?.preserveReasoningContent ?? options?.provider === "deepseek",
|
|
919
1212
|
provider: options?.provider,
|
|
1213
|
+
retainedSourceContentEnd: sourceContentPartOffset + (Array.isArray(message.content) ? message.content.length : 0),
|
|
920
1214
|
sourceMessageId,
|
|
921
1215
|
sourceContentPartOffset,
|
|
922
1216
|
sourceContentPartIndices: processedSourceContentPartIndices,
|
|
@@ -1043,7 +1337,8 @@ const formatAgentMessages = (payload, indexTokenCountMap, tools, skills, options
|
|
|
1043
1337
|
text: summaryBoundary.text,
|
|
1044
1338
|
tokenCount: summaryBoundary.tokenCount
|
|
1045
1339
|
} : void 0,
|
|
1046
|
-
boundaryTokenAdjustment
|
|
1340
|
+
boundaryTokenAdjustment,
|
|
1341
|
+
compactionSemanticIndex: finalizeDerivedCompactionSemanticIndex(compactionSemanticIndexCollector)
|
|
1047
1342
|
};
|
|
1048
1343
|
};
|
|
1049
1344
|
function shiftIndexTokenCountMap(indexTokenCountMap, instructionsTokenCount) {
|