nolo-cli 0.1.44 → 0.1.46
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/README.md +258 -102
- package/index.js +73433 -0
- package/package.json +10 -633
- package/LICENSE +0 -21
- package/agent-runtime/agentConfigOptions.ts +0 -12
- package/agent-runtime/agentRecordConfig.ts +0 -101
- package/agent-runtime/agentRecordKeys.ts +0 -14
- package/agent-runtime/agentThread.ts +0 -222
- package/agent-runtime/agentThreadAdmission.ts +0 -74
- package/agent-runtime/dialogMessageRecord.ts +0 -16
- package/agent-runtime/dialogWritePlan.ts +0 -211
- package/agent-runtime/hostAdapter.ts +0 -81
- package/agent-runtime/hybridRecordStore.ts +0 -170
- package/agent-runtime/index.ts +0 -184
- package/agent-runtime/localDialogRead.ts +0 -23
- package/agent-runtime/localLoop.ts +0 -334
- package/agent-runtime/localToolPolicy.ts +0 -179
- package/agent-runtime/localWorkspaceTools.ts +0 -2310
- package/agent-runtime/noloWorkspaceTools.ts +0 -390
- package/agent-runtime/openAiCompatibleProvider.ts +0 -74
- package/agent-runtime/openAiCompatibleProviderConfig.ts +0 -27
- package/agent-runtime/platformChatProvider.ts +0 -229
- package/agent-runtime/providerResolution.ts +0 -302
- package/agent-runtime/runtimeDecision.ts +0 -70
- package/agent-runtime/runtimeFacts.ts +0 -40
- package/agent-runtime/runtimeToolPolicy.ts +0 -191
- package/agent-runtime/runtimeToolSurface.ts +0 -199
- package/agent-runtime/shellCommandPolicy.ts +0 -120
- package/agent-runtime/types.ts +0 -137
- package/agentAliases.ts +0 -110
- package/agentCommandSupport.ts +0 -81
- package/agentInternalCommandEntries.ts +0 -44
- package/agentListCommands.ts +0 -185
- package/agentListHelpers.ts +0 -242
- package/agentMachineCommands.ts +0 -403
- package/agentPullCommand.ts +0 -142
- package/agentRecordCommands.ts +0 -226
- package/agentRecordHelpers.ts +0 -571
- package/agentRunCommand.ts +0 -556
- package/agentRuntimeCommands.ts +0 -7
- package/agentRuntimeLocal.ts +0 -45
- package/ai/agent/_executeModel.ts +0 -146
- package/ai/agent/agentSlice.ts +0 -557
- package/ai/agent/appWorkingMemory.ts +0 -126
- package/ai/agent/buildEditingContext.ts +0 -378
- package/ai/agent/buildSystemPrompt.ts +0 -599
- package/ai/agent/canvasEditingContext.ts +0 -49
- package/ai/agent/cleanAgentMessages.ts +0 -140
- package/ai/agent/cliChatClient.ts +0 -153
- package/ai/agent/cliExecutor.ts +0 -1465
- package/ai/agent/cliPrompt.ts +0 -10
- package/ai/agent/contextCompiler.ts +0 -107
- package/ai/agent/contextLayerContract.ts +0 -44
- package/ai/agent/createAgentSchema.ts +0 -272
- package/ai/agent/currentTimeContext.ts +0 -65
- package/ai/agent/executeToolCall.ts +0 -58
- package/ai/agent/fetchAgentContexts.ts +0 -42
- package/ai/agent/generatePrompt.ts +0 -3
- package/ai/agent/getFullChatContextKeys.ts +0 -168
- package/ai/agent/guidedCreation/capabilities.ts +0 -84
- package/ai/agent/guidedCreation/types.ts +0 -38
- package/ai/agent/isLiveAudioOnlyAgent.ts +0 -26
- package/ai/agent/liveAudioModel.ts +0 -2
- package/ai/agent/machineRunPermissions.ts +0 -113
- package/ai/agent/pageBuilderHandoffRules.ts +0 -75
- package/ai/agent/persistMessageWithFixedId.ts +0 -37
- package/ai/agent/planSlice.ts +0 -259
- package/ai/agent/referenceUtils.ts +0 -229
- package/ai/agent/runAgentBackground.ts +0 -310
- package/ai/agent/runAgentClientLoop.ts +0 -164
- package/ai/agent/runtimeGuidance.ts +0 -116
- package/ai/agent/serverOrigin.ts +0 -7
- package/ai/agent/startParallelAgentStreams.ts +0 -424
- package/ai/agent/startupProtocol.ts +0 -53
- package/ai/agent/streamAgentChatTurn.ts +0 -2135
- package/ai/agent/streamAgentChatTurnUtils.ts +0 -923
- package/ai/agent/toolFailureGuard.ts +0 -99
- package/ai/agent/types.ts +0 -73
- package/ai/agent/utils/imageOutput.ts +0 -37
- package/ai/agent/utils/publicImageAgentMode.ts +0 -26
- package/ai/agent.ts +0 -2
- package/ai/ai.locale.ts +0 -1165
- package/ai/chat/accumulateToolCallChunks.ts +0 -126
- package/ai/chat/fetchUtils.ts +0 -143
- package/ai/chat/inlineImageUrlsForCustomProvider.ts +0 -122
- package/ai/chat/parseApiError.ts +0 -67
- package/ai/chat/parseMultilineSSE.ts +0 -95
- package/ai/chat/sendOpenAICompletionsRequest.ts +0 -921
- package/ai/chat/sendOpenAIResponseRequest.ts +0 -720
- package/ai/chat/serverProxyRetry.ts +0 -102
- package/ai/chat/shouldUseServerProxy.ts +0 -18
- package/ai/chat/streamRetry.ts +0 -46
- package/ai/chat/updateTotalUsage.ts +0 -89
- package/ai/context/buildReferenceContext.ts +0 -437
- package/ai/context/retention.ts +0 -165
- package/ai/context/tokenUtils.ts +0 -78
- package/ai/index.ts +0 -1
- package/ai/llm/agentCapabilities.ts +0 -74
- package/ai/llm/deepinfra.ts +0 -79
- package/ai/llm/fireworks.ts +0 -68
- package/ai/llm/generateRequestBody.ts +0 -165
- package/ai/llm/getModelContextWindow.ts +0 -93
- package/ai/llm/getPricing.ts +0 -252
- package/ai/llm/imagePricing.ts +0 -66
- package/ai/llm/isResponseAPIModel.ts +0 -13
- package/ai/llm/kimi.ts +0 -22
- package/ai/llm/mimo.ts +0 -99
- package/ai/llm/mistral.ts +0 -21
- package/ai/llm/models.ts +0 -45
- package/ai/llm/openrouterModels.ts +0 -31
- package/ai/llm/providers.ts +0 -313
- package/ai/llm/reasoningModels.ts +0 -27
- package/ai/llm/types.ts +0 -82
- package/ai/llm/usageRequestOptions.ts +0 -59
- package/ai/memory/policy.ts +0 -49
- package/ai/memory/queryShared.ts +0 -167
- package/ai/memory/recentRelationshipRecap.ts +0 -251
- package/ai/memory/remember.ts +0 -111
- package/ai/memory/scope.ts +0 -74
- package/ai/memory/store.ts +0 -20
- package/ai/memory/storeShared.ts +0 -76
- package/ai/memory/types.ts +0 -52
- package/ai/memory/understanding.ts +0 -341
- package/ai/memory/understandingGreeting.ts +0 -264
- package/ai/policy/personalizationDialog.ts +0 -333
- package/ai/policy/runtimePolicy.ts +0 -526
- package/ai/policy/selfUpdateFields.ts +0 -48
- package/ai/policy/types.ts +0 -64
- package/ai/skills/referenceRuntime.ts +0 -274
- package/ai/skills/skillDiagnostics.ts +0 -251
- package/ai/skills/skillDocBuilder.ts +0 -139
- package/ai/skills/skillDocProtocol.ts +0 -526
- package/ai/skills/skillSummaryMarker.ts +0 -26
- package/ai/token/calculatePrice.ts +0 -576
- package/ai/token/missingUsageEstimate.ts +0 -42
- package/ai/token/normalizeUsage.ts +0 -124
- package/ai/token/openaiImageGenerationUsage.ts +0 -56
- package/ai/token/prepareTokenUsageData.ts +0 -93
- package/ai/token/resolveBillingTarget.ts +0 -52
- package/ai/token/saveTokenRecord.ts +0 -53
- package/ai/token/types.ts +0 -103
- package/ai/tools/agent/agentTools.ts +0 -214
- package/ai/tools/agent/agentUpdateShared.ts +0 -311
- package/ai/tools/agent/callAgentTool.ts +0 -139
- package/ai/tools/agent/createAgentTool.ts +0 -512
- package/ai/tools/agent/createDialogTool.ts +0 -69
- package/ai/tools/agent/createSkillAgentTool.ts +0 -62
- package/ai/tools/agent/parallelBudget.ts +0 -221
- package/ai/tools/agent/prepareAgentDraftTool.ts +0 -159
- package/ai/tools/agent/presets/appBuilderPreset.ts +0 -154
- package/ai/tools/agent/runLlmTool.ts +0 -96
- package/ai/tools/agent/runStreamingAgentTool.ts +0 -73
- package/ai/tools/agent/skillAgentArgs.ts +0 -106
- package/ai/tools/agent/startAgentDialogTool.ts +0 -54
- package/ai/tools/agent/streamParallelAgentsTool.ts +0 -123
- package/ai/tools/agent/updateAgentTool.ts +0 -96
- package/ai/tools/agent/updateSelfTool.ts +0 -113
- package/ai/tools/amazonProductScraperTool.ts +0 -86
- package/ai/tools/apifyActorClient.ts +0 -45
- package/ai/tools/appEditGuard.ts +0 -372
- package/ai/tools/appReadSnapshot.ts +0 -153
- package/ai/tools/appTools.ts +0 -1549
- package/ai/tools/applyEditTool.ts +0 -259
- package/ai/tools/applyLineEditsTool.ts +0 -315
- package/ai/tools/browserTools/click.ts +0 -33
- package/ai/tools/browserTools/closeSession.ts +0 -29
- package/ai/tools/browserTools/common.ts +0 -27
- package/ai/tools/browserTools/openSession.ts +0 -48
- package/ai/tools/browserTools/readContent.ts +0 -38
- package/ai/tools/browserTools/selectOption.ts +0 -46
- package/ai/tools/browserTools/typeText.ts +0 -42
- package/ai/tools/category/createCategoryTool.ts +0 -66
- package/ai/tools/category/queryContentsByCategoryTool.ts +0 -69
- package/ai/tools/category/updateContentCategoryTool.ts +0 -75
- package/ai/tools/cfBrowserTools.ts +0 -319
- package/ai/tools/cfSpeechToTextTool.ts +0 -49
- package/ai/tools/checkEnvTool.ts +0 -102
- package/ai/tools/cloudflareCrawlTool.ts +0 -289
- package/ai/tools/codeSearchTool.ts +0 -123
- package/ai/tools/codeTools.ts +0 -101
- package/ai/tools/convertMarxistsBookTool.ts +0 -103
- package/ai/tools/createDocTool.ts +0 -132
- package/ai/tools/createSkillDocTool.ts +0 -155
- package/ai/tools/createWorkflowTool.ts +0 -154
- package/ai/tools/delayTool.ts +0 -31
- package/ai/tools/deleteSpacesTool.ts +0 -325
- package/ai/tools/deleteSpacesToolModel.ts +0 -159
- package/ai/tools/devReloadUtils.ts +0 -29
- package/ai/tools/dialogMessageSearch.ts +0 -137
- package/ai/tools/doctorSkillTool.ts +0 -72
- package/ai/tools/ecommerceScraperTool.ts +0 -86
- package/ai/tools/emailTools.ts +0 -549
- package/ai/tools/evalSkillTool.ts +0 -92
- package/ai/tools/exaSearchTool.ts +0 -63
- package/ai/tools/execShellTool.ts +0 -266
- package/ai/tools/executeSqlTool.ts +0 -192
- package/ai/tools/fetchWebpageSupport.ts +0 -333
- package/ai/tools/fetchWebpageTool.ts +0 -97
- package/ai/tools/geminiImagePreviewTool.ts +0 -386
- package/ai/tools/generateDocxTool.ts +0 -215
- package/ai/tools/googleSearchScraperTool.ts +0 -106
- package/ai/tools/importDataTool.ts +0 -133
- package/ai/tools/importSkillTool.ts +0 -162
- package/ai/tools/index.ts +0 -2290
- package/ai/tools/jdProductScraperTool.ts +0 -821
- package/ai/tools/listUserSpacesTool.ts +0 -113
- package/ai/tools/localFilesTool.ts +0 -276
- package/ai/tools/marxistsOfflineBook.ts +0 -253
- package/ai/tools/modelUsageTools.ts +0 -206
- package/ai/tools/noloWorkspaceReadTools.ts +0 -467
- package/ai/tools/olmOcrTool.ts +0 -33
- package/ai/tools/openaiImageTool.ts +0 -267
- package/ai/tools/prepareTools.ts +0 -193
- package/ai/tools/readDocTool.ts +0 -88
- package/ai/tools/readFileTool.ts +0 -214
- package/ai/tools/readTool.ts +0 -194
- package/ai/tools/readXPostTool.ts +0 -229
- package/ai/tools/readXhsProfileTool.ts +0 -638
- package/ai/tools/rememberMemoryTool.ts +0 -84
- package/ai/tools/remotionVideoTool.ts +0 -151
- package/ai/tools/searchDialogMessagesTool.ts +0 -222
- package/ai/tools/searchWorkspaceTool.ts +0 -259
- package/ai/tools/skillFollowup.ts +0 -86
- package/ai/tools/surfWeatherTool.ts +0 -169
- package/ai/tools/table/addTableRowTool.ts +0 -217
- package/ai/tools/table/createTableTool.ts +0 -326
- package/ai/tools/table/rowTools.ts +0 -386
- package/ai/tools/table/schemaTools.ts +0 -244
- package/ai/tools/table/shareTableTool.ts +0 -148
- package/ai/tools/table/toolShared.ts +0 -129
- package/ai/tools/taobaoTmallProductScraperTool.ts +0 -49
- package/ai/tools/toolApiClient.ts +0 -279
- package/ai/tools/toolNameAliases.ts +0 -70
- package/ai/tools/toolPacks.ts +0 -19
- package/ai/tools/toolResultError.ts +0 -42
- package/ai/tools/toolRunSlice.ts +0 -303
- package/ai/tools/toolSchemaCompatibility.ts +0 -53
- package/ai/tools/uiAskChoiceTool.ts +0 -104
- package/ai/tools/updateContentTitleTool.ts +0 -84
- package/ai/tools/updateDocTool.ts +0 -105
- package/ai/tools/updateUserPreferenceProfileTool.ts +0 -153
- package/ai/tools/wereadGatewayTool.ts +0 -152
- package/ai/tools/whisperTool.ts +0 -76
- package/ai/tools/writeFileTool.ts +0 -213
- package/ai/tools/youtubeScraperTool.ts +0 -116
- package/ai/tools/ziweiChartTool.ts +0 -678
- package/ai/types.ts +0 -58
- package/ai/workflow/workflowExecutor.ts +0 -323
- package/ai/workflow/workflowSlice.ts +0 -73
- package/ai/workflow/workflowTypes.ts +0 -106
- package/app/actions/syncAppRecord.ts +0 -73
- package/app/constants/animationSets.ts +0 -21
- package/app/constants/appEditor.ts +0 -99
- package/app/favorite/deletedFavoriteProjection.ts +0 -31
- package/app/favorite/favoriteSlice.ts +0 -690
- package/app/favorite/type.ts +0 -43
- package/app/hooks/deleteDbKey.ts +0 -254
- package/app/i18n/client.ts +0 -13
- package/app/i18n/i18n.base.ts +0 -14
- package/app/i18n/i18n.config.ts +0 -77
- package/app/i18n/index.ts +0 -15
- package/app/i18n/mapLanguage.ts +0 -11
- package/app/i18n/translations/appBuilder.locale.ts +0 -453
- package/app/i18n/translations/error.locale.ts +0 -246
- package/app/i18n/translations/interface.locale.ts +0 -2206
- package/app/i18n/translations/pricing.locale.ts +0 -397
- package/app/i18n/translations/privacy.locale.ts +0 -168
- package/app/i18n/translations/seo.locale.ts +0 -129
- package/app/i18n/translations/terms.locale.ts +0 -124
- package/app/i18n/types.ts +0 -6
- package/app/notifications/model.ts +0 -77
- package/app/notifications/notificationSlice.ts +0 -141
- package/app/reducer.ts +0 -36
- package/app/settings/dbActionThunks.ts +0 -34
- package/app/settings/defaultSpacePreference.ts +0 -87
- package/app/settings/settingSlice.tsx +0 -1212
- package/app/settings/settingsRecord.ts +0 -8
- package/app/stateViews/runtime.ts +0 -90
- package/app/store.ts +0 -55
- package/app/theme/colors.ts +0 -280
- package/app/theme/fontPreference.ts +0 -77
- package/app/theme/theme.config.ts +0 -120
- package/app/theme/themeModeBootstrap.ts +0 -123
- package/app/types/appSummary.ts +0 -118
- package/app/types.ts +0 -358
- package/app/utils/appKeys.ts +0 -55
- package/app/utils/async.ts +0 -28
- package/app/utils/desktopAgentRuntimeTurnClient.ts +0 -75
- package/app/utils/env.ts +0 -17
- package/app/utils/fileUtils.ts +0 -229
- package/app/utils/imageUtils.ts +0 -274
- package/app/utils/myContentItems.ts +0 -317
- package/app/utils/retryAfter.ts +0 -36
- package/app/utils/retryFetch.ts +0 -61
- package/app/utils/toast.ts +0 -3
- package/auth/action/signUpAction.ts +0 -227
- package/auth/adminPermissions.ts +0 -78
- package/auth/authSlice.ts +0 -531
- package/auth/client/loginRequest.ts +0 -14
- package/auth/resetAuthScopedClientState.ts +0 -27
- package/auth/routes.ts +0 -183
- package/auth/token.ts +0 -63
- package/auth/types.ts +0 -40
- package/authCommands.ts +0 -230
- package/chat/chat.locale.ts +0 -817
- package/chat/dialog/actions/addCybotAction.ts +0 -52
- package/chat/dialog/actions/addReferenceKeysAction.ts +0 -62
- package/chat/dialog/actions/builtinDialogLlm.ts +0 -35
- package/chat/dialog/actions/cleanupCliSession.ts +0 -40
- package/chat/dialog/actions/createDialogAction.ts +0 -379
- package/chat/dialog/actions/createScheduledTaskAction.ts +0 -78
- package/chat/dialog/actions/handleSendMessageAction.ts +0 -202
- package/chat/dialog/actions/handleSendMessageResolver.ts +0 -27
- package/chat/dialog/actions/removeCybotAction.ts +0 -6
- package/chat/dialog/actions/removeDialogAgentAction.ts +0 -44
- package/chat/dialog/actions/replacePrimaryCybotAction.ts +0 -6
- package/chat/dialog/actions/setPrimaryDialogAgentAction.ts +0 -52
- package/chat/dialog/actions/updateDialogSummaryAction.ts +0 -430
- package/chat/dialog/actions/updateDialogTitleAction.ts +0 -151
- package/chat/dialog/actions/updateDialogTitlePolicy.ts +0 -30
- package/chat/dialog/actions/updateTokensAction.ts +0 -233
- package/chat/dialog/dialogAgents.ts +0 -72
- package/chat/dialog/dialogAttachmentCleanup.ts +0 -135
- package/chat/dialog/dialogSlice.ts +0 -985
- package/chat/dialog/dialogTitle.ts +0 -81
- package/chat/dialog/dialogTokenStats.ts +0 -12
- package/chat/dialog/dialogUrl.ts +0 -6
- package/chat/dialog/goal.ts +0 -108
- package/chat/dialog/objectAssistantRegistry.ts +0 -286
- package/chat/dialog/schedule.ts +0 -17
- package/chat/messages/activityCompletion.ts +0 -97
- package/chat/messages/fetchAndCacheMessages.ts +0 -119
- package/chat/messages/fetchConvMsgs.ts +0 -51
- package/chat/messages/fetchMessages.ts +0 -84
- package/chat/messages/fileUrl.ts +0 -13
- package/chat/messages/imagePayloadPersistence.ts +0 -22
- package/chat/messages/messageAgent.ts +0 -8
- package/chat/messages/messageContent.ts +0 -203
- package/chat/messages/messageContract.ts +0 -88
- package/chat/messages/messageSlice.ts +0 -1386
- package/chat/messages/toolThunks.ts +0 -646
- package/chat/messages/types.ts +0 -192
- package/chat/messages/web/toolDisplayName.ts +0 -686
- package/cli/agentAliases.ts +0 -110
- package/cli/agentCommandSupport.ts +0 -81
- package/cli/agentInternalCommandEntries.ts +0 -44
- package/cli/agentListCommands.ts +0 -185
- package/cli/agentListHelpers.ts +0 -242
- package/cli/agentMachineCommands.ts +0 -403
- package/cli/agentPullCommand.ts +0 -142
- package/cli/agentRecordCommands.ts +0 -226
- package/cli/agentRecordHelpers.ts +0 -571
- package/cli/agentRunCommand.ts +0 -556
- package/cli/agentRuntimeLocal.ts +0 -45
- package/cli/authCommands.ts +0 -230
- package/cli/cliCommandAdapters.ts +0 -28
- package/cli/cliCommandDispatch.ts +0 -66
- package/cli/cliCommandFactories.ts +0 -66
- package/cli/cliCommandTypes.ts +0 -49
- package/cli/cliEnvHelpers.ts +0 -116
- package/cli/cliSpaceHelpers.ts +0 -39
- package/cli/client/agentConfigResolver.ts +0 -1
- package/cli/client/agentRun.ts +0 -795
- package/cli/client/compactDialog.ts +0 -222
- package/cli/client/hybridRecordStore.ts +0 -52
- package/cli/client/localAgentRecords.ts +0 -7
- package/cli/client/localDialogRecords.ts +0 -30
- package/cli/client/localProviderResolver.ts +0 -1
- package/cli/client/localRuntimeAdapter.ts +0 -1104
- package/cli/client/localToolPolicy.ts +0 -8
- package/cli/client/profileConfig.ts +0 -101
- package/cli/client/streamingOutput.ts +0 -38
- package/cli/commandRegistry.ts +0 -98
- package/cli/connectorRunArtifact.ts +0 -120
- package/cli/connectorWebSocketTarget.ts +0 -112
- package/cli/defaultServer.ts +0 -1
- package/cli/dialogAttachmentCleanup.ts +0 -151
- package/cli/dialogCommands.ts +0 -1120
- package/cli/dialogInternalCommandEntries.ts +0 -17
- package/cli/docCreateCommands.ts +0 -345
- package/cli/docInternalCommandEntries.ts +0 -11
- package/cli/docPageHelpers.ts +0 -80
- package/cli/docSkillHelpers.ts +0 -67
- package/cli/docSpaceHelpers.ts +0 -46
- package/cli/globalRecordOperations.ts +0 -258
- package/cli/internalCommandEntries.ts +0 -18
- package/cli/localRuntimeAuthority.ts +0 -182
- package/cli/localRuntimeDb.ts +0 -26
- package/cli/machineCommands.ts +0 -307
- package/cli/machineDaemonCommands.ts +0 -185
- package/cli/machineHeartbeatCommands.ts +0 -30
- package/cli/machineStatusCommands.ts +0 -95
- package/cli/machineWatchCommands.ts +0 -41
- package/cli/machineWsPromptMaterialization.ts +0 -89
- package/cli/machineWsRunDispatch.ts +0 -695
- package/cli/machineWsSession.ts +0 -213
- package/cli/memoryCommands.ts +0 -253
- package/cli/memoryInternalCommandEntries.ts +0 -9
- package/cli/offlineMarxistsAgentCommand.ts +0 -316
- package/cli/qoderUsageProbe.ts +0 -252
- package/cli/runtimeDoctorCommands.ts +0 -174
- package/cli/runtimeModeArgs.ts +0 -33
- package/cli/scriptCommandEntries.ts +0 -66
- package/cli/secretScan.ts +0 -31
- package/cli/systemInternalCommandEntries.ts +0 -65
- package/cli/tableCommands.ts +0 -453
- package/cli/tui/readlineWorkspace.ts +0 -210
- package/cli/tui/session.ts +0 -554
- package/cli/updateCommands.ts +0 -134
- package/cli/workflowInternalCommandEntries.ts +0 -10
- package/cliCommandAdapters.ts +0 -28
- package/cliCommandDispatch.ts +0 -66
- package/cliCommandFactories.ts +0 -66
- package/cliCommandTypes.ts +0 -49
- package/cliEnvHelpers.ts +0 -116
- package/cliSpaceHelpers.ts +0 -39
- package/client/agentConfigResolver.test.ts +0 -69
- package/client/agentConfigResolver.ts +0 -1
- package/client/agentRun.test.ts +0 -1344
- package/client/agentRun.ts +0 -795
- package/client/compactDialog.test.ts +0 -238
- package/client/compactDialog.ts +0 -222
- package/client/hybridRecordStore.test.ts +0 -157
- package/client/hybridRecordStore.ts +0 -52
- package/client/localAgentRecords.test.ts +0 -27
- package/client/localAgentRecords.ts +0 -7
- package/client/localDialogRecords.test.ts +0 -124
- package/client/localDialogRecords.ts +0 -30
- package/client/localProviderResolver.test.ts +0 -102
- package/client/localProviderResolver.ts +0 -1
- package/client/localRuntimeAdapter.test.ts +0 -2804
- package/client/localRuntimeAdapter.ts +0 -1104
- package/client/localRuntimeDryRun.test.ts +0 -135
- package/client/localToolPolicy.test.ts +0 -48
- package/client/localToolPolicy.ts +0 -8
- package/client/profileConfig.test.ts +0 -106
- package/client/profileConfig.ts +0 -101
- package/client/streamingOutput.test.ts +0 -22
- package/client/streamingOutput.ts +0 -38
- package/commandRegistry.ts +0 -98
- package/connector-experimental/capabilities.ts +0 -75
- package/connector-experimental/codexBinary.ts +0 -41
- package/connector-experimental/heartbeatLoop.ts +0 -22
- package/connector-experimental/machineInfo.ts +0 -46
- package/connector-experimental/protocol.ts +0 -54
- package/connectorRunArtifact.ts +0 -120
- package/connectorWebSocketTarget.ts +0 -112
- package/core/builtinAgents.ts +0 -209
- package/core/config.ts +0 -15
- package/core/crypto.ts +0 -51
- package/core/generateKeyPairFromSeedV1.ts +0 -15
- package/core/generateMainKey.ts +0 -22
- package/core/init.ts +0 -41
- package/core/localOrigins.ts +0 -8
- package/core/password.ts +0 -13
- package/core/prefix.ts +0 -23
- package/create/editor/transforms/fromMarkdown/index.ts +0 -260
- package/create/editor/transforms/fromMarkdown/inline.ts +0 -285
- package/create/editor/transforms/fromMarkdown/table.ts +0 -130
- package/create/editor/transforms/markdownToSlate.ts +0 -24
- package/create/editor/transforms/slateToRenderMarkdown.ts +0 -218
- package/create/editor/transforms/slateToSimplifiedMarkdown.ts +0 -224
- package/create/editor/transforms/slateToText.ts +0 -33
- package/create/editor/utils/slateUtils.ts +0 -233
- package/create/space/addSpaceAction.ts +0 -193
- package/create/space/category/categoryActions.ts +0 -427
- package/create/space/changeSpaceAction.ts +0 -36
- package/create/space/constants.ts +0 -8
- package/create/space/content/addContentAction.ts +0 -116
- package/create/space/content/contentThunks.ts +0 -90
- package/create/space/content/deleteContentFromSpaceAction.ts +0 -187
- package/create/space/content/deleteMultipleContentAction.ts +0 -112
- package/create/space/content/moveContentAction.ts +0 -285
- package/create/space/content/updateContentCategoryAction.ts +0 -154
- package/create/space/content/updateContentTitleAction.ts +0 -151
- package/create/space/content/uploadAndAddFileToSpaceAction.ts +0 -98
- package/create/space/contentKeyUtils.ts +0 -117
- package/create/space/deleteSpaceAction.ts +0 -276
- package/create/space/fetchSpaceAction.ts +0 -70
- package/create/space/fetchSpaceSidebarStateAction.ts +0 -26
- package/create/space/loadDefaultSpaceAction.ts +0 -57
- package/create/space/member/addMemberAction.ts +0 -79
- package/create/space/member/fetchUserSpaceMembershipsAction.ts +0 -386
- package/create/space/member/memberThunks.ts +0 -47
- package/create/space/member/removeMemberAction.ts +0 -67
- package/create/space/resolvePreferredSpaceId.ts +0 -113
- package/create/space/sidebarVisibleTypes.ts +0 -260
- package/create/space/space.locale.ts +0 -1087
- package/create/space/spaceAccess.ts +0 -182
- package/create/space/spaceCollapsedState.ts +0 -54
- package/create/space/spaceKeys.ts +0 -65
- package/create/space/spaceSlice.ts +0 -328
- package/create/space/spaceThunks.ts +0 -410
- package/create/space/types.ts +0 -27
- package/create/space/updateSpaceAction.ts +0 -107
- package/create/space/utils/permissions.ts +0 -47
- package/create/types.ts +0 -21
- package/database/actions/agentReadResolution.ts +0 -33
- package/database/actions/common.ts +0 -243
- package/database/actions/deleteFile.ts +0 -40
- package/database/actions/fileContent.ts +0 -125
- package/database/actions/patch.ts +0 -155
- package/database/actions/read.ts +0 -358
- package/database/actions/readAndWait.ts +0 -260
- package/database/actions/readRequestManager.ts +0 -120
- package/database/actions/readResolution.ts +0 -125
- package/database/actions/remove.ts +0 -94
- package/database/actions/replication.ts +0 -477
- package/database/actions/upload.ts +0 -186
- package/database/actions/upsert.ts +0 -56
- package/database/actions/write.ts +0 -146
- package/database/authority/ownerKey.ts +0 -80
- package/database/authority/recordAuthority.ts +0 -67
- package/database/authority/userAuthorityRegistry.ts +0 -54
- package/database/client/fetchUserData.ts +0 -61
- package/database/config.ts +0 -40
- package/database/dbActionThunks.ts +0 -1
- package/database/dbSlice.ts +0 -149
- package/database/fileRing.ts +0 -51
- package/database/fileStorage.ts +0 -232
- package/database/fileUrl.ts +0 -34
- package/database/keys.ts +0 -767
- package/database/queryPrefixes.ts +0 -14
- package/database/requests.ts +0 -443
- package/database/runtimeServerContext.ts +0 -54
- package/database/server/authorityStoreTypes.ts +0 -31
- package/database/server/cliAuthorityBrokerClient.ts +0 -227
- package/database/server/cliAuthorityBrokerServer.ts +0 -283
- package/database/server/cliAuthorityBrokerTypes.ts +0 -43
- package/database/server/cliAuthorityStoreDriver.ts +0 -98
- package/database/server/db.ts +0 -99
- package/database/server/dbPath.ts +0 -20
- package/database/server/ensureDbOpen.ts +0 -12
- package/database/server/legacyServerDb.ts +0 -58
- package/database/server/levelAuthorityStore.ts +0 -114
- package/database/server/memoryAuthorityStore.ts +0 -133
- package/database/server/serverStoreFactory.ts +0 -118
- package/database/tenantPlacement.ts +0 -57
- package/database/tombstones.ts +0 -52
- package/database/userDataMerge.ts +0 -95
- package/database/userPreferenceRegister.ts +0 -131
- package/database/utils/ulid.ts +0 -1
- package/defaultServer.ts +0 -1
- package/dialogAttachmentCleanup.ts +0 -151
- package/dialogCommands.ts +0 -1120
- package/dialogInternalCommandEntries.ts +0 -17
- package/docCreateCommands.ts +0 -345
- package/docInternalCommandEntries.ts +0 -11
- package/docPageHelpers.ts +0 -80
- package/docSkillHelpers.ts +0 -67
- package/docSpaceHelpers.ts +0 -46
- package/globalRecordOperations.ts +0 -258
- package/index.ts +0 -78
- package/integrations/anthropic/anthropicModels.ts +0 -47
- package/integrations/deepseek/models.ts +0 -37
- package/integrations/google/models.ts +0 -341
- package/integrations/openai/chatCompletionStreamMode.ts +0 -10
- package/integrations/openai/filterAndCleanMessages.ts +0 -284
- package/integrations/openai/flexTier.ts +0 -102
- package/integrations/openai/generateOpenAIRequestBody.ts +0 -271
- package/integrations/openai/generateResponseRequestBody.ts +0 -77
- package/integrations/openai/models.ts +0 -271
- package/integrations/openai/providerBodyCompatibility.ts +0 -23
- package/integrations/openai/responsesHelpers.ts +0 -297
- package/integrations/x-reader/types.ts +0 -109
- package/integrations/xai/models.ts +0 -13
- package/integrations/xhs-reader/redaction.ts +0 -68
- package/integrations/xhs-reader/types.ts +0 -277
- package/integrations/xhs-reader/url.ts +0 -80
- package/internalCommandEntries.ts +0 -18
- package/localRuntimeAuthority.ts +0 -182
- package/localRuntimeDb.ts +0 -26
- package/machineCommands.ts +0 -307
- package/machineDaemonCommands.ts +0 -185
- package/machineHeartbeatCommands.ts +0 -30
- package/machineStatusCommands.ts +0 -95
- package/machineWatchCommands.ts +0 -41
- package/machineWsPromptMaterialization.ts +0 -89
- package/machineWsRunDispatch.ts +0 -695
- package/machineWsSession.ts +0 -213
- package/memoryCommands.ts +0 -253
- package/memoryInternalCommandEntries.ts +0 -9
- package/offlineMarxistsAgentCommand.ts +0 -316
- package/qoderUsageProbe.ts +0 -252
- package/render/contentIcon/types.ts +0 -167
- package/render/page/createPageAction.ts +0 -183
- package/render/page/docSlice.ts +0 -495
- package/render/page/types.ts +0 -19
- package/render/table/activityColumns.ts +0 -6
- package/render/table/createTableAction.ts +0 -274
- package/render/table/deleteTableAction.ts +0 -193
- package/render/table/fetchAndCacheTableRows.ts +0 -174
- package/render/table/tableSlice.ts +0 -1167
- package/render/table/toolValueUtils.ts +0 -363
- package/render/table/types.ts +0 -262
- package/render/table/utils/tableSerialization.ts +0 -50
- package/runtimeDoctorCommands.ts +0 -174
- package/runtimeModeArgs.ts +0 -33
- package/scriptCommandEntries.ts +0 -66
- package/secretScan.ts +0 -31
- package/server/handlers/agentRun/types.ts +0 -105
- package/share/action.ts +0 -225
- package/share/helpers.ts +0 -302
- package/share/keys.ts +0 -243
- package/share/publicSharePolicy.ts +0 -27
- package/share/shareSlice.ts +0 -53
- package/share/types.ts +0 -100
- package/systemInternalCommandEntries.ts +0 -65
- package/tableCommands.ts +0 -453
- package/tui/readlineWorkspace.ts +0 -210
- package/tui/session.ts +0 -554
- package/updateCommands.ts +0 -134
- package/workflowInternalCommandEntries.ts +0 -10
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
// 文件路径: packages/chat/dialog/actions/updateDialogSummaryAction.ts
|
|
2
|
-
|
|
3
|
-
import type { RootState } from "../../../app/store";
|
|
4
|
-
import { runLlm } from "../../../ai/agent/agentSlice";
|
|
5
|
-
import {
|
|
6
|
-
buildBuiltinSummaryContent,
|
|
7
|
-
BUILTIN_SUMMARY_LLM_CONFIG,
|
|
8
|
-
} from "./builtinDialogLlm";
|
|
9
|
-
import { patch, selectById } from "../../../database/dbSlice";
|
|
10
|
-
// import { selectAllMsgs, selectMsgsByDialogId } from "../../messages/messageSlice"; // CIRCULAR
|
|
11
|
-
import { serializeMessageContent } from "../../messages/messageContent";
|
|
12
|
-
import { DialogConfig, Agent } from "../../../app/types";
|
|
13
|
-
import { selectContextRetention } from "../../../app/settings/settingSlice";
|
|
14
|
-
import { getModelContextWindow } from "../../../ai/llm/getModelContextWindow";
|
|
15
|
-
import { estimateTokenCount } from "../../../ai/context/tokenUtils";
|
|
16
|
-
import { extractCustomId } from "../../../core/prefix";
|
|
17
|
-
import type { Message } from "../../messages/types";
|
|
18
|
-
import {
|
|
19
|
-
ConversationLoad,
|
|
20
|
-
planContextUsage,
|
|
21
|
-
} from "../../../ai/context/retention";
|
|
22
|
-
|
|
23
|
-
// --- 常量 ---
|
|
24
|
-
const MIN_COMPRESS_COUNT = 5; // 至少压缩5条以上才有意义
|
|
25
|
-
const MIN_PROACTIVE_MESSAGE_COUNT = 6;
|
|
26
|
-
const MIN_PROACTIVE_TOKENS = 1800;
|
|
27
|
-
const PROACTIVE_SUMMARY_MAX_INPUT_TOKENS = 12000;
|
|
28
|
-
const ACTIVE_SUMMARY_TAIL_KEEP_COUNT = 2;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// --- 辅助函数 ---
|
|
32
|
-
|
|
33
|
-
const getMessageTokenCount = (msg: any): number => {
|
|
34
|
-
if (msg.usage?.completion_tokens) {
|
|
35
|
-
return msg.usage.completion_tokens;
|
|
36
|
-
}
|
|
37
|
-
const content = serializeMessageContent(msg.content) || "";
|
|
38
|
-
return estimateTokenCount(content);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const getMessagesForDialogFromState = (
|
|
42
|
-
state: RootState,
|
|
43
|
-
dialogId: string
|
|
44
|
-
): Message[] => {
|
|
45
|
-
const msgsState = state.message.dialogStateById[dialogId]?.msgs;
|
|
46
|
-
if (!msgsState || !msgsState.ids) return [];
|
|
47
|
-
|
|
48
|
-
return (msgsState.ids as string[])
|
|
49
|
-
.map(id => msgsState.entities[id])
|
|
50
|
-
.filter(Boolean) as Message[];
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const formatMessagesForSummary = (msgs: Message[]): string =>
|
|
54
|
-
msgs
|
|
55
|
-
.map(m => {
|
|
56
|
-
const content = serializeMessageContent(m.content) || "[非文本内容]";
|
|
57
|
-
return `${m.role}: ${content}`;
|
|
58
|
-
})
|
|
59
|
-
.join("\n");
|
|
60
|
-
|
|
61
|
-
const findMessageIndexById = (msgs: Message[], id?: string): number =>
|
|
62
|
-
id ? msgs.findIndex(m => m.id === id) : -1;
|
|
63
|
-
|
|
64
|
-
const hasOpenEndedToolCall = (msg: Message | undefined): boolean =>
|
|
65
|
-
!!msg && Array.isArray((msg as any).tool_calls) && (msg as any).tool_calls.length > 0;
|
|
66
|
-
|
|
67
|
-
const truncateMessagesForSummary = (msgs: Message[]): Message[] => {
|
|
68
|
-
let total = 0;
|
|
69
|
-
let start = msgs.length;
|
|
70
|
-
|
|
71
|
-
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
72
|
-
const t = getMessageTokenCount(msgs[i]);
|
|
73
|
-
if (total + t > PROACTIVE_SUMMARY_MAX_INPUT_TOKENS) break;
|
|
74
|
-
total += t;
|
|
75
|
-
start = i;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return msgs.slice(start);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const buildPreviousSummaryWithProactive = (
|
|
82
|
-
dialogConfig: DialogConfig,
|
|
83
|
-
shouldConsumeProactive: boolean
|
|
84
|
-
): string => {
|
|
85
|
-
const base = dialogConfig.summary || "";
|
|
86
|
-
const proactive = shouldConsumeProactive ? dialogConfig.proactiveSummary || "" : "";
|
|
87
|
-
|
|
88
|
-
if (!base && !proactive) return "";
|
|
89
|
-
if (!proactive) return base;
|
|
90
|
-
if (!base) return `【主动工作摘要】\n${proactive}`;
|
|
91
|
-
|
|
92
|
-
return `${base}\n\n【主动工作摘要】\n${proactive}`;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const isActiveSummaryWorthDoing = (
|
|
96
|
-
pendingTokens: number,
|
|
97
|
-
contextWindow: number
|
|
98
|
-
): boolean => {
|
|
99
|
-
const minTokens = Math.min(
|
|
100
|
-
40_000,
|
|
101
|
-
Math.max(10_000, Math.floor(contextWindow * 0.05))
|
|
102
|
-
);
|
|
103
|
-
return pendingTokens >= minTokens;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// --- Action ---
|
|
107
|
-
const classifyConversationLoad = (msgs: Message[]): ConversationLoad => {
|
|
108
|
-
const N = 20;
|
|
109
|
-
if (!Array.isArray(msgs) || msgs.length === 0) return "light";
|
|
110
|
-
|
|
111
|
-
const tail = msgs.slice(-N);
|
|
112
|
-
const tokenSamples = tail.map(getMessageTokenCount);
|
|
113
|
-
if (tokenSamples.length === 0) return "light";
|
|
114
|
-
|
|
115
|
-
const sum = tokenSamples.reduce((acc, v) => acc + v, 0);
|
|
116
|
-
const avg = sum / tokenSamples.length;
|
|
117
|
-
const sorted = [...tokenSamples].sort((a, b) => a - b);
|
|
118
|
-
const p95 = sorted[Math.floor((sorted.length - 1) * 0.95)];
|
|
119
|
-
|
|
120
|
-
if (p95 < 200 && avg < 120) {
|
|
121
|
-
return "light";
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (p95 > 2000 || avg > 1200) {
|
|
125
|
-
return "heavy";
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return "medium";
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const summarizingDialogs = new Set<string>();
|
|
133
|
-
|
|
134
|
-
export const updateDialogSummaryAction = async (
|
|
135
|
-
args: {
|
|
136
|
-
dialogKey: string;
|
|
137
|
-
preFetchedMessages?: Message[];
|
|
138
|
-
force?: boolean;
|
|
139
|
-
reason?: "task_completed" | "context_budget";
|
|
140
|
-
},
|
|
141
|
-
thunkApi: any
|
|
142
|
-
) => {
|
|
143
|
-
const { dialogKey, preFetchedMessages, force = false } = args;
|
|
144
|
-
|
|
145
|
-
// 0. 并发锁:避免同一个 Dialog 同时进行多个摘要任务
|
|
146
|
-
if (summarizingDialogs.has(dialogKey)) return;
|
|
147
|
-
summarizingDialogs.add(dialogKey);
|
|
148
|
-
|
|
149
|
-
const { dispatch, getState } = thunkApi;
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
const state = getState() as RootState;
|
|
153
|
-
const dialogId = extractCustomId(dialogKey);
|
|
154
|
-
|
|
155
|
-
const dialogConfig = selectById(state, dialogKey) as DialogConfig;
|
|
156
|
-
if (!dialogConfig) return;
|
|
157
|
-
|
|
158
|
-
// 1. 获取配置
|
|
159
|
-
const retention = selectContextRetention(state);
|
|
160
|
-
|
|
161
|
-
let contextWindow = 128000;
|
|
162
|
-
if (dialogConfig.cybots && dialogConfig.cybots.length > 0) {
|
|
163
|
-
const agentId = dialogConfig.cybots[0];
|
|
164
|
-
const agent = selectById(state, agentId) as Agent;
|
|
165
|
-
if (agent?.model) {
|
|
166
|
-
contextWindow = getModelContextWindow(agent.model);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// 2. 获取消息
|
|
171
|
-
const allMsgs =
|
|
172
|
-
preFetchedMessages || getMessagesForDialogFromState(state, dialogId);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
// 3. 找到最后一次压缩的位置
|
|
178
|
-
const lastSummarizedId = dialogConfig.summarizedBeforeId;
|
|
179
|
-
let startIndex = 0;
|
|
180
|
-
if (lastSummarizedId) {
|
|
181
|
-
const found = allMsgs.findIndex(m => m.id === lastSummarizedId);
|
|
182
|
-
if (found !== -1) {
|
|
183
|
-
startIndex = found + 1;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// 待处理的消息(尚未被压缩进 summary)
|
|
188
|
-
const pendingMsgs = allMsgs.slice(startIndex);
|
|
189
|
-
if (pendingMsgs.length === 0) return;
|
|
190
|
-
|
|
191
|
-
// 4. 计算当前总开销 = 已有 Summary + 待处理消息
|
|
192
|
-
const summaryTokens = estimateTokenCount(dialogConfig.summary || "");
|
|
193
|
-
const pendingTokens = pendingMsgs.reduce((sum, msg) => sum + getMessageTokenCount(msg), 0);
|
|
194
|
-
const totalUsed = summaryTokens + pendingTokens;
|
|
195
|
-
|
|
196
|
-
// 5. 基于模型窗口 / slider / 近期负载,规划历史预算
|
|
197
|
-
const adjustedSummaryTokens = Math.max(summaryTokens, 1000);
|
|
198
|
-
const recentLoad = classifyConversationLoad(pendingMsgs);
|
|
199
|
-
|
|
200
|
-
const { historyBudget, rawMessageBudget } = planContextUsage({
|
|
201
|
-
contextWindow,
|
|
202
|
-
retentionSlider: retention,
|
|
203
|
-
summaryTokens: adjustedSummaryTokens,
|
|
204
|
-
recentLoad,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
const shouldRunActiveSummary =
|
|
208
|
-
force &&
|
|
209
|
-
!hasOpenEndedToolCall(pendingMsgs[pendingMsgs.length - 1]) &&
|
|
210
|
-
isActiveSummaryWorthDoing(pendingTokens, contextWindow);
|
|
211
|
-
|
|
212
|
-
// 历史 + 待处理总开销未达到预算,且没有明确的主动归档信号,不触发压缩
|
|
213
|
-
if (totalUsed < historyBudget && !shouldRunActiveSummary) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// 6. 需要压缩:决定把哪些消息压进去
|
|
218
|
-
// 目标:压缩后,summary + 保留的原始消息 ≈ historyBudget,
|
|
219
|
-
// 且尽量保留最近的若干条消息。
|
|
220
|
-
|
|
221
|
-
let tokensToKeep = 0;
|
|
222
|
-
let keepCount = 0;
|
|
223
|
-
|
|
224
|
-
// 从后往前数,保留最近的消息直到填满 rawMessageBudget
|
|
225
|
-
for (let i = pendingMsgs.length - 1; i >= 0; i--) {
|
|
226
|
-
const t = getMessageTokenCount(pendingMsgs[i]);
|
|
227
|
-
if (tokensToKeep + t > rawMessageBudget) break;
|
|
228
|
-
tokensToKeep += t;
|
|
229
|
-
keepCount++;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// 主动归档时保留最后两条原文,避免刚给用户的结论立刻被折叠进 summary。
|
|
233
|
-
let compressCount =
|
|
234
|
-
shouldRunActiveSummary && totalUsed < historyBudget
|
|
235
|
-
? Math.max(0, pendingMsgs.length - ACTIVE_SUMMARY_TAIL_KEEP_COUNT)
|
|
236
|
-
: pendingMsgs.length - keepCount;
|
|
237
|
-
|
|
238
|
-
// Guard: Prevent breaking tool chains or compressing open-ended tool calls
|
|
239
|
-
// OpenAI requires: Assistant(tool_calls) -> Tool(output) must be contiguous.
|
|
240
|
-
|
|
241
|
-
// 1. Ensure we do not cut immediately before a 'tool' message.
|
|
242
|
-
// If pendingMsgs[compressCount] (the first kept message) is 'tool',
|
|
243
|
-
// it means we are summarizing its parent 'assistant'. This is illegal.
|
|
244
|
-
while (compressCount > 0 && compressCount < pendingMsgs.length && pendingMsgs[compressCount].role === 'tool') {
|
|
245
|
-
compressCount--;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// 2. Ensure the last compressed message is not an assistant with tool_calls that needs a future tool output
|
|
249
|
-
// (This is implicitly covered by #1 if tool output exists, but if tool output hasn't arrived yet,
|
|
250
|
-
// we must check the last message itself).
|
|
251
|
-
// Actually, if tool output hasn't arrived, 'updateDialogSummaryAction' is usually called after 'messageStreamEnd'.
|
|
252
|
-
// If the last message is Assistant(tool_calls), the NEXT message (not yet in list) will be Tool.
|
|
253
|
-
// So we should NOT compress the last message if it has tool_calls.
|
|
254
|
-
if (compressCount > 0) {
|
|
255
|
-
const lastCompressed = pendingMsgs[compressCount - 1];
|
|
256
|
-
const hasToolCalls = Array.isArray((lastCompressed as any).tool_calls) && (lastCompressed as any).tool_calls.length > 0;
|
|
257
|
-
if (hasToolCalls) {
|
|
258
|
-
// If we are chopping off the end of the conversation, and it ends with a tool call,
|
|
259
|
-
// we must preserve it until tool output arrives.
|
|
260
|
-
// Actually, just to be safe, never compress an active tool call.
|
|
261
|
-
compressCount--;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
// 2. 可压缩的消息太少,不值得压缩
|
|
267
|
-
if (compressCount < MIN_COMPRESS_COUNT) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const msgsToCompress = pendingMsgs.slice(0, compressCount);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
// 最后一条被压缩的消息
|
|
275
|
-
const newSummarizedBeforeId = msgsToCompress[msgsToCompress.length - 1].id;
|
|
276
|
-
|
|
277
|
-
// 7. 提取引用 Keys (pageKey/dialogKey) 并保存
|
|
278
|
-
// 这一步非常重要:因为这些消息即将从 context 中消失,必须把 key 留下来
|
|
279
|
-
// 我们复用 addReferenceKeysAction 的逻辑,或者通过 content 提取
|
|
280
|
-
// 这里直接提取然后 patch dialog
|
|
281
|
-
const extractedKeys = new Set(dialogConfig.referenceKeys || []);
|
|
282
|
-
msgsToCompress.forEach(msg => {
|
|
283
|
-
// 简单遍历 content
|
|
284
|
-
if (Array.isArray(msg.content)) {
|
|
285
|
-
msg.content.forEach((p: any) => {
|
|
286
|
-
if (p?.pageKey) extractedKeys.add(p.pageKey);
|
|
287
|
-
if (p?.dialogKey) extractedKeys.add(p.dialogKey);
|
|
288
|
-
});
|
|
289
|
-
} else if (msg.content && typeof msg.content === 'object') {
|
|
290
|
-
const c: any = msg.content;
|
|
291
|
-
if (c.pageKey) extractedKeys.add(c.pageKey);
|
|
292
|
-
if (c.dialogKey) extractedKeys.add(c.dialogKey);
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
// 8. 生成新 Summary (结构化记忆升级版)
|
|
297
|
-
// 目标:将线性摘要升级为 "事实 (Facts) + 剧情 (Narrative)" 双轨记忆。
|
|
298
|
-
// 这能显著提升 Agent 的 "智商",防止关键配置在长对话中被遗忘。
|
|
299
|
-
|
|
300
|
-
const proactiveBeforeIndex = findMessageIndexById(
|
|
301
|
-
allMsgs,
|
|
302
|
-
dialogConfig.proactiveSummaryBeforeId
|
|
303
|
-
);
|
|
304
|
-
const shouldConsumeProactive =
|
|
305
|
-
!!dialogConfig.proactiveSummary &&
|
|
306
|
-
proactiveBeforeIndex !== -1 &&
|
|
307
|
-
proactiveBeforeIndex < startIndex + compressCount;
|
|
308
|
-
|
|
309
|
-
const previousSummary = buildPreviousSummaryWithProactive(
|
|
310
|
-
dialogConfig,
|
|
311
|
-
shouldConsumeProactive
|
|
312
|
-
);
|
|
313
|
-
const messagesText = formatMessagesForSummary(msgsToCompress);
|
|
314
|
-
|
|
315
|
-
const promptContent = buildBuiltinSummaryContent(
|
|
316
|
-
previousSummary,
|
|
317
|
-
messagesText
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
try {
|
|
321
|
-
// 调用内置 Summary LLM
|
|
322
|
-
const newSummary = await dispatch(
|
|
323
|
-
runLlm({
|
|
324
|
-
llmConfig: BUILTIN_SUMMARY_LLM_CONFIG,
|
|
325
|
-
content: promptContent,
|
|
326
|
-
billingDialogKey: dialogKey,
|
|
327
|
-
})
|
|
328
|
-
).unwrap();
|
|
329
|
-
|
|
330
|
-
if (newSummary && typeof newSummary === "string" && newSummary.trim()) {
|
|
331
|
-
const currentCount = dialogConfig.compressionCount || 0;
|
|
332
|
-
|
|
333
|
-
await dispatch(
|
|
334
|
-
patch({
|
|
335
|
-
dbKey: dialogKey,
|
|
336
|
-
changes: {
|
|
337
|
-
summary: newSummary.trim(),
|
|
338
|
-
summarizedBeforeId: newSummarizedBeforeId,
|
|
339
|
-
referenceKeys: Array.from(extractedKeys),
|
|
340
|
-
compressionCount: currentCount + 1,
|
|
341
|
-
summaryPending: false, // Explicitly clear pending flag
|
|
342
|
-
...(shouldConsumeProactive
|
|
343
|
-
? {
|
|
344
|
-
proactiveSummary: "",
|
|
345
|
-
proactiveSummaryBeforeId: undefined,
|
|
346
|
-
}
|
|
347
|
-
: {}),
|
|
348
|
-
},
|
|
349
|
-
})
|
|
350
|
-
).unwrap();
|
|
351
|
-
|
|
352
|
-
console.log(`[ContextCompression] Compressed ${compressCount} messages. New summary len: ${newSummary.length}`);
|
|
353
|
-
}
|
|
354
|
-
} catch (err) {
|
|
355
|
-
console.error("[ContextCompression] Failed:", err);
|
|
356
|
-
}
|
|
357
|
-
} finally {
|
|
358
|
-
summarizingDialogs.delete(dialogKey);
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
export const updateDialogProactiveSummaryAction = async (
|
|
363
|
-
args: { dialogKey: string; preFetchedMessages?: Message[] },
|
|
364
|
-
thunkApi: any
|
|
365
|
-
) => {
|
|
366
|
-
const { dialogKey, preFetchedMessages } = args;
|
|
367
|
-
if (summarizingDialogs.has(dialogKey)) return;
|
|
368
|
-
if (summarizingDialogs.has(`proactive:${dialogKey}`)) return;
|
|
369
|
-
summarizingDialogs.add(`proactive:${dialogKey}`);
|
|
370
|
-
|
|
371
|
-
const { dispatch, getState } = thunkApi;
|
|
372
|
-
|
|
373
|
-
try {
|
|
374
|
-
const state = getState() as RootState;
|
|
375
|
-
const dialogId = extractCustomId(dialogKey);
|
|
376
|
-
const dialogConfig = selectById(state, dialogKey) as DialogConfig;
|
|
377
|
-
if (!dialogConfig) return;
|
|
378
|
-
|
|
379
|
-
const allMsgs = preFetchedMessages || getMessagesForDialogFromState(state, dialogId);
|
|
380
|
-
if (!allMsgs.length) return;
|
|
381
|
-
|
|
382
|
-
const hardSummaryIndex = findMessageIndexById(allMsgs, dialogConfig.summarizedBeforeId);
|
|
383
|
-
const proactiveIndex = findMessageIndexById(allMsgs, dialogConfig.proactiveSummaryBeforeId);
|
|
384
|
-
const startIndex = Math.max(hardSummaryIndex, proactiveIndex) + 1;
|
|
385
|
-
const pendingMsgs = allMsgs.slice(startIndex);
|
|
386
|
-
if (pendingMsgs.length < MIN_PROACTIVE_MESSAGE_COUNT) return;
|
|
387
|
-
|
|
388
|
-
if (hasOpenEndedToolCall(pendingMsgs[pendingMsgs.length - 1])) return;
|
|
389
|
-
|
|
390
|
-
const pendingTokens = pendingMsgs.reduce((sum, msg) => sum + getMessageTokenCount(msg), 0);
|
|
391
|
-
const hasToolOutput = pendingMsgs.some(msg => msg.role === "tool");
|
|
392
|
-
if (!hasToolOutput && pendingTokens < MIN_PROACTIVE_TOKENS) return;
|
|
393
|
-
|
|
394
|
-
const msgsToSummarize = truncateMessagesForSummary(pendingMsgs);
|
|
395
|
-
if (msgsToSummarize.length < MIN_PROACTIVE_MESSAGE_COUNT && !hasToolOutput) return;
|
|
396
|
-
|
|
397
|
-
const newProactiveBeforeId = pendingMsgs[pendingMsgs.length - 1].id;
|
|
398
|
-
const previousSummary = dialogConfig.proactiveSummary || "";
|
|
399
|
-
const messagesText = formatMessagesForSummary(msgsToSummarize);
|
|
400
|
-
const promptContent = buildBuiltinSummaryContent(previousSummary, messagesText);
|
|
401
|
-
|
|
402
|
-
try {
|
|
403
|
-
const newSummary = await dispatch(
|
|
404
|
-
runLlm({
|
|
405
|
-
llmConfig: BUILTIN_SUMMARY_LLM_CONFIG,
|
|
406
|
-
content: promptContent,
|
|
407
|
-
billingDialogKey: dialogKey,
|
|
408
|
-
})
|
|
409
|
-
).unwrap();
|
|
410
|
-
|
|
411
|
-
if (newSummary && typeof newSummary === "string" && newSummary.trim()) {
|
|
412
|
-
await dispatch(
|
|
413
|
-
patch({
|
|
414
|
-
dbKey: dialogKey,
|
|
415
|
-
changes: {
|
|
416
|
-
proactiveSummary: newSummary.trim(),
|
|
417
|
-
proactiveSummaryBeforeId: newProactiveBeforeId,
|
|
418
|
-
},
|
|
419
|
-
})
|
|
420
|
-
).unwrap();
|
|
421
|
-
|
|
422
|
-
console.log(`[ContextCompression] Proactive summary updated. len: ${newSummary.length}`);
|
|
423
|
-
}
|
|
424
|
-
} catch (err) {
|
|
425
|
-
console.error("[ContextCompression] Proactive summary failed:", err);
|
|
426
|
-
}
|
|
427
|
-
} finally {
|
|
428
|
-
summarizingDialogs.delete(`proactive:${dialogKey}`);
|
|
429
|
-
}
|
|
430
|
-
};
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
// chat/dialogs/updateDialogTitleAction.ts
|
|
2
|
-
|
|
3
|
-
import { runLlm } from "../../../ai/agent/agentSlice";
|
|
4
|
-
import type { RootState } from "../../../app/store";
|
|
5
|
-
import {
|
|
6
|
-
updateContentTitle,
|
|
7
|
-
} from "../../../create/space/spaceSlice";
|
|
8
|
-
import { normalizeSpaceId } from "../../../create/space/spaceKeys";
|
|
9
|
-
import { patch, selectById } from "../../../database/dbSlice";
|
|
10
|
-
import { extractCustomId } from "../../../core/prefix";
|
|
11
|
-
import { format } from "date-fns";
|
|
12
|
-
import { selectAllMsgs } from "../../messages/messageSlice";
|
|
13
|
-
import { serializeMessageContent } from "../../messages/messageContent";
|
|
14
|
-
import {
|
|
15
|
-
BUILTIN_TITLE_LLM_CONFIG,
|
|
16
|
-
} from "./builtinDialogLlm";
|
|
17
|
-
import {
|
|
18
|
-
shouldUpdateTitle,
|
|
19
|
-
} from "./updateDialogTitlePolicy";
|
|
20
|
-
import {
|
|
21
|
-
buildDialogFallbackTitleFromMessages,
|
|
22
|
-
resolveDialogTitle,
|
|
23
|
-
} from "../dialogTitle";
|
|
24
|
-
|
|
25
|
-
// --- 常量 ---
|
|
26
|
-
const MAX_MESSAGES_FOR_CONTEXT = 20;
|
|
27
|
-
|
|
28
|
-
const isAssistantToolStub = (msg: any) =>
|
|
29
|
-
msg?.role === "assistant" &&
|
|
30
|
-
(msg.content == null ||
|
|
31
|
-
(typeof msg.content === "string" && msg.content.trim().length === 0) ||
|
|
32
|
-
(Array.isArray(msg.content) && msg.content.length === 0)) &&
|
|
33
|
-
Array.isArray(msg?.tool_calls) &&
|
|
34
|
-
msg.tool_calls.length > 0;
|
|
35
|
-
|
|
36
|
-
const dedupeById = <T extends { id?: string }>(messages: T[]) => {
|
|
37
|
-
const seen = new Set<string>();
|
|
38
|
-
return messages.filter((message) => {
|
|
39
|
-
const id = typeof message.id === "string" ? message.id : "";
|
|
40
|
-
if (!id || seen.has(id)) return false;
|
|
41
|
-
seen.add(id);
|
|
42
|
-
return true;
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const getMessageContextForTitle = (
|
|
47
|
-
state: RootState,
|
|
48
|
-
dialogKey: string,
|
|
49
|
-
selectAllMessages: typeof selectAllMsgs = selectAllMsgs
|
|
50
|
-
) => {
|
|
51
|
-
const allMsgs = selectAllMessages(state, extractCustomId(dialogKey));
|
|
52
|
-
|
|
53
|
-
const flattened = Array.isArray(allMsgs)
|
|
54
|
-
? typeof (allMsgs as any).flat === "function"
|
|
55
|
-
? (allMsgs as any).flat()
|
|
56
|
-
: (allMsgs as any).reduce(
|
|
57
|
-
(acc: any[], cur: any) => acc.concat(cur),
|
|
58
|
-
[]
|
|
59
|
-
)
|
|
60
|
-
: [];
|
|
61
|
-
|
|
62
|
-
const normalized = flattened
|
|
63
|
-
.filter((msg: any) => msg?.role !== "tool" && !isAssistantToolStub(msg))
|
|
64
|
-
.map((msg: any) => {
|
|
65
|
-
const textContent = serializeMessageContent(msg?.content, "这里是一个图片");
|
|
66
|
-
if (!textContent) return null;
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
...msg,
|
|
70
|
-
content: textContent as string, // 之后只会用到 role + content
|
|
71
|
-
};
|
|
72
|
-
})
|
|
73
|
-
.filter(Boolean) as Array<{ role: any; content: string }>;
|
|
74
|
-
|
|
75
|
-
const earlyUserTurns = normalized.filter((msg) => msg.role === "user").slice(0, 3);
|
|
76
|
-
const recentTurns = normalized.slice(-12);
|
|
77
|
-
|
|
78
|
-
return dedupeById([...earlyUserTurns, ...recentTurns]).slice(
|
|
79
|
-
0,
|
|
80
|
-
MAX_MESSAGES_FOR_CONTEXT
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
type UpdateDialogTitleDeps = {
|
|
85
|
-
runLlmAction?: typeof runLlm;
|
|
86
|
-
patchAction?: typeof patch;
|
|
87
|
-
selectDialogById?: typeof selectById;
|
|
88
|
-
selectAllMessages?: typeof selectAllMsgs;
|
|
89
|
-
updateSpaceContentTitle?: typeof updateContentTitle;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// --- 异步 Thunk Action ---
|
|
93
|
-
export const updateDialogTitleActionWithDeps = async (
|
|
94
|
-
args,
|
|
95
|
-
thunkApi,
|
|
96
|
-
deps: UpdateDialogTitleDeps = {}
|
|
97
|
-
) => {
|
|
98
|
-
const {
|
|
99
|
-
runLlmAction = runLlm,
|
|
100
|
-
patchAction = patch,
|
|
101
|
-
selectDialogById = selectById,
|
|
102
|
-
selectAllMessages = selectAllMsgs,
|
|
103
|
-
updateSpaceContentTitle = updateContentTitle,
|
|
104
|
-
} = deps;
|
|
105
|
-
const { dialogKey } = args;
|
|
106
|
-
const { dispatch, getState } = thunkApi;
|
|
107
|
-
const state = getState() as RootState;
|
|
108
|
-
|
|
109
|
-
const dialogConfig = selectDialogById(state, dialogKey);
|
|
110
|
-
if (
|
|
111
|
-
!dialogConfig ||
|
|
112
|
-
!shouldUpdateTitle(dialogConfig.createdAt, dialogConfig.updatedAt)
|
|
113
|
-
) {
|
|
114
|
-
return dialogConfig;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const messageContext = getMessageContextForTitle(state, dialogKey, selectAllMessages);
|
|
118
|
-
if (messageContext.length === 0) {
|
|
119
|
-
return dialogConfig;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const content = JSON.stringify(
|
|
123
|
-
messageContext.map((msg) => ({ role: msg.role, content: msg.content }))
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const generatedTitle = await dispatch(
|
|
127
|
-
runLlmAction({
|
|
128
|
-
llmConfig: BUILTIN_TITLE_LLM_CONFIG,
|
|
129
|
-
content,
|
|
130
|
-
billingDialogKey: dialogKey,
|
|
131
|
-
})
|
|
132
|
-
).unwrap();
|
|
133
|
-
|
|
134
|
-
const fallbackTitle =
|
|
135
|
-
buildDialogFallbackTitleFromMessages(messageContext) ||
|
|
136
|
-
`Conversation on ${format(new Date(), "MMM d")}`;
|
|
137
|
-
const title = resolveDialogTitle(generatedTitle, fallbackTitle);
|
|
138
|
-
|
|
139
|
-
const spaceId =
|
|
140
|
-
dialogConfig?.spaceId && normalizeSpaceId(dialogConfig.spaceId);
|
|
141
|
-
if (spaceId) {
|
|
142
|
-
dispatch(updateSpaceContentTitle({ spaceId, contentKey: dialogKey, title }));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return await dispatch(
|
|
146
|
-
patchAction({ dbKey: dialogKey, changes: { title } })
|
|
147
|
-
).unwrap();
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export const updateDialogTitleAction = async (args, thunkApi) =>
|
|
151
|
-
updateDialogTitleActionWithDeps(args, thunkApi);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { differenceInMinutes } from "date-fns";
|
|
2
|
-
|
|
3
|
-
export const TITLE_UPDATE_INTERVAL_MINUTES = 30;
|
|
4
|
-
|
|
5
|
-
const FORCE_UPDATE_FOR_TEST = false;
|
|
6
|
-
|
|
7
|
-
export const shouldUpdateTitle = (
|
|
8
|
-
createdAt?: string,
|
|
9
|
-
lastUpdatedAt?: string,
|
|
10
|
-
now = new Date()
|
|
11
|
-
): boolean => {
|
|
12
|
-
if (FORCE_UPDATE_FOR_TEST) return true;
|
|
13
|
-
|
|
14
|
-
const lastUpdate = lastUpdatedAt ? new Date(lastUpdatedAt) : null;
|
|
15
|
-
const creation = createdAt ? new Date(createdAt) : null;
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
!lastUpdate ||
|
|
19
|
-
!creation ||
|
|
20
|
-
Number.isNaN(lastUpdate.getTime()) ||
|
|
21
|
-
Number.isNaN(creation.getTime())
|
|
22
|
-
) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
differenceInMinutes(now, creation) <= TITLE_UPDATE_INTERVAL_MINUTES ||
|
|
28
|
-
differenceInMinutes(now, lastUpdate) >= TITLE_UPDATE_INTERVAL_MINUTES
|
|
29
|
-
);
|
|
30
|
-
};
|