nolo-cli 0.1.45 → 0.1.47
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 +272 -118
- package/index.js +73946 -0
- package/package.json +10 -635
- 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 -40
- package/agentCommandSupport.ts +0 -81
- package/agentInternalCommandEntries.ts +0 -44
- package/agentListCommands.ts +0 -185
- package/agentListHelpers.ts +0 -242
- package/agentMachineCommands.ts +0 -426
- package/agentNameResolver.ts +0 -164
- package/agentPullCommand.ts +0 -142
- package/agentRecordCommands.ts +0 -224
- package/agentRecordHelpers.ts +0 -592
- package/agentRunCommand.ts +0 -568
- 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 -40
- 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 -426
- package/cli/agentNameResolver.ts +0 -164
- package/cli/agentPullCommand.ts +0 -142
- package/cli/agentRecordCommands.ts +0 -224
- package/cli/agentRecordHelpers.ts +0 -592
- package/cli/agentRunCommand.ts +0 -568
- 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 -735
- 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 -1098
- 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 -312
- 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 -315
- 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 -1346
- package/client/agentRun.ts +0 -735
- 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 -2809
- package/client/localRuntimeAdapter.ts +0 -1098
- 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 -312
- 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 -315
- 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,1212 +0,0 @@
|
|
|
1
|
-
// app/settings/settingSlice.ts
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
buildCreateSlice,
|
|
5
|
-
asyncThunkCreator,
|
|
6
|
-
createSelector,
|
|
7
|
-
type PayloadAction,
|
|
8
|
-
} from "@reduxjs/toolkit";
|
|
9
|
-
import type { RootState } from "../store";
|
|
10
|
-
import { isProduction } from "../utils/env";
|
|
11
|
-
import { getIsDesktopApp } from "../utils/env";
|
|
12
|
-
import { getAllServers } from "../../database/actions/common";
|
|
13
|
-
import { SERVERS } from "../../database/config";
|
|
14
|
-
import { createUserKey, createUserPreferenceKey } from "../../database/keys";
|
|
15
|
-
import { selectUserId } from "../../auth/authSlice";
|
|
16
|
-
import {
|
|
17
|
-
USER_PREFERENCE_NAMES,
|
|
18
|
-
buildDefaultAgentPreferenceRegisterRecord,
|
|
19
|
-
readUserPreferenceRegisterValue,
|
|
20
|
-
} from "../../database/userPreferenceRegister";
|
|
21
|
-
|
|
22
|
-
// 从分离的配置文件导入静态主题数据
|
|
23
|
-
import {
|
|
24
|
-
DEFAULT_THEME_NAME,
|
|
25
|
-
SPACE,
|
|
26
|
-
THEME_COLORS,
|
|
27
|
-
MODE_COLORS,
|
|
28
|
-
} from "../theme/theme.config";
|
|
29
|
-
import {
|
|
30
|
-
normalizeThemeName,
|
|
31
|
-
resolveThemeModeIsDark,
|
|
32
|
-
SYSTEM_DARK_MEDIA_QUERY,
|
|
33
|
-
} from "../theme/themeModeBootstrap";
|
|
34
|
-
import {
|
|
35
|
-
DEFAULT_FONT_PRESET,
|
|
36
|
-
FONT_PRESET_CSS_VARIABLES,
|
|
37
|
-
type FontPreset,
|
|
38
|
-
normalizeFontPreset,
|
|
39
|
-
} from "../theme/fontPreference";
|
|
40
|
-
import { legacyNoloAgentId, noloAgentId } from "../../core/init";
|
|
41
|
-
import { DEFAULT_ANIMATION_SET_INDEX } from "../constants/animationSets";
|
|
42
|
-
import {
|
|
43
|
-
areSidebarVisibleTypesEqual,
|
|
44
|
-
DEFAULT_SIDEBAR_VISIBLE_TYPES,
|
|
45
|
-
LEGACY_DEFAULT_SIDEBAR_VISIBLE_TYPES,
|
|
46
|
-
normalizeSidebarVisibleTypes,
|
|
47
|
-
type SidebarVisibleType,
|
|
48
|
-
} from "../../create/space/sidebarVisibleTypes";
|
|
49
|
-
import { normalizeSpaceId } from "../../create/space/spaceKeys";
|
|
50
|
-
import {
|
|
51
|
-
DEFAULT_USER_PREFERENCE_PROFILE,
|
|
52
|
-
type KnowledgeCaptureLevel,
|
|
53
|
-
type SpaceContextLevel,
|
|
54
|
-
type TonePreset,
|
|
55
|
-
} from "../../ai/policy/types";
|
|
56
|
-
import {
|
|
57
|
-
DEFAULT_AUTO_APPROVED_SELF_UPDATE_FIELDS,
|
|
58
|
-
normalizeAgentUpdateFieldList,
|
|
59
|
-
type AgentUpdateField,
|
|
60
|
-
} from "../../ai/policy/selfUpdateFields";
|
|
61
|
-
import { getSettingDbActionThunks } from "./dbActionThunks";
|
|
62
|
-
import {
|
|
63
|
-
normalizeDefaultSpaceIdPreference,
|
|
64
|
-
persistDefaultSpacePreference,
|
|
65
|
-
readDefaultSpaceIdPreference,
|
|
66
|
-
} from "./defaultSpacePreference";
|
|
67
|
-
import { withSettingsRecordSchema } from "./settingsRecord";
|
|
68
|
-
|
|
69
|
-
// --- State 定义 (包含所有字段) ---
|
|
70
|
-
interface SettingState {
|
|
71
|
-
isAutoSync: boolean;
|
|
72
|
-
currentServer: string;
|
|
73
|
-
defaultSpaceId?: string | null;
|
|
74
|
-
syncServers: string[];
|
|
75
|
-
showThinking: boolean;
|
|
76
|
-
preferredAnimationSet: number;
|
|
77
|
-
maxExecutionTime: number;
|
|
78
|
-
maxCost: number;
|
|
79
|
-
themeName: keyof typeof THEME_COLORS;
|
|
80
|
-
themeMode: "system" | "light" | "dark";
|
|
81
|
-
isDark: boolean; // resolved value: managed by setThemeMode + useSystemTheme
|
|
82
|
-
sidebarWidth: number;
|
|
83
|
-
headerHeight: number;
|
|
84
|
-
density: "compact" | "spacious";
|
|
85
|
-
fontPreset: FontPreset;
|
|
86
|
-
|
|
87
|
-
// 编辑器配置
|
|
88
|
-
editorDefaultMode: "markdown" | "block";
|
|
89
|
-
editorLightCodeTheme: string;
|
|
90
|
-
editorDarkCodeTheme: string;
|
|
91
|
-
editorWordCountEnabled: boolean;
|
|
92
|
-
editorShortcuts: {
|
|
93
|
-
heading: boolean;
|
|
94
|
-
ulist: boolean;
|
|
95
|
-
olist: boolean;
|
|
96
|
-
quote: boolean;
|
|
97
|
-
code: boolean;
|
|
98
|
-
tasklist: boolean;
|
|
99
|
-
};
|
|
100
|
-
editorFontSize: number;
|
|
101
|
-
editorAutoSave: boolean;
|
|
102
|
-
editorAutoSaveInterval: number;
|
|
103
|
-
editorLineNumbers: boolean;
|
|
104
|
-
editorWordWrap: boolean;
|
|
105
|
-
editorSpellCheck: boolean;
|
|
106
|
-
editorTabSize: number;
|
|
107
|
-
editorFontFamily: string;
|
|
108
|
-
|
|
109
|
-
// 是否允许读取当前空间内容作为上下文
|
|
110
|
-
enableReadCurrentSpace: boolean;
|
|
111
|
-
|
|
112
|
-
// 侧边栏默认显示的内容类型
|
|
113
|
-
sidebarVisibleTypes: SidebarVisibleType[];
|
|
114
|
-
|
|
115
|
-
// 通用提示词
|
|
116
|
-
globalPrompt: string;
|
|
117
|
-
|
|
118
|
-
// 用户偏好的语气 preset(尽量通用,不覆盖 agent 自身人格)
|
|
119
|
-
userTonePreset: TonePreset;
|
|
120
|
-
|
|
121
|
-
// AI 对知识沉淀(doc/table)的主动程度
|
|
122
|
-
knowledgeCaptureLevel: KnowledgeCaptureLevel;
|
|
123
|
-
|
|
124
|
-
// AI 使用当前空间作为上下文的积极程度
|
|
125
|
-
spaceContextLevel: SpaceContextLevel;
|
|
126
|
-
|
|
127
|
-
// updateSelf 默认哪些字段不再询问
|
|
128
|
-
autoApproveSelfUpdateFields: AgentUpdateField[];
|
|
129
|
-
|
|
130
|
-
// ADDED: AI Recent Content Limit
|
|
131
|
-
aiRecentContentLimit: number;
|
|
132
|
-
|
|
133
|
-
// 上下文保留程度 1-100(默认 50)
|
|
134
|
-
// 值越高 = 保留越多历史上下文,新对话空间越小
|
|
135
|
-
contextRetention: number;
|
|
136
|
-
|
|
137
|
-
// 默认启动的智能体 ID
|
|
138
|
-
defaultAgentId?: string;
|
|
139
|
-
|
|
140
|
-
// PDF OCR 模型选择("none" 表示不使用 OCR,用 pdf.js 提取文本)
|
|
141
|
-
ocrModel: "none" | "olm_ocr";
|
|
142
|
-
|
|
143
|
-
// 对话页面快捷滚动按钮
|
|
144
|
-
showScrollToTopButton: boolean;
|
|
145
|
-
showScrollToBottomButton: boolean;
|
|
146
|
-
createMenuOpenCount: number;
|
|
147
|
-
|
|
148
|
-
[key: string]: any;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export const SYSTEM_DEFAULT_AGENT_ID = "system-default";
|
|
152
|
-
|
|
153
|
-
// --- 初始状态 (包含所有字段的默认值) ---
|
|
154
|
-
const initialState: SettingState = {
|
|
155
|
-
isAutoSync: false,
|
|
156
|
-
currentServer: isProduction ? SERVERS.MAIN : SERVERS.US,
|
|
157
|
-
defaultSpaceId: null,
|
|
158
|
-
syncServers: Object.values(SERVERS),
|
|
159
|
-
showThinking: true,
|
|
160
|
-
preferredAnimationSet: DEFAULT_ANIMATION_SET_INDEX,
|
|
161
|
-
maxExecutionTime: 600_000,
|
|
162
|
-
maxCost: 1,
|
|
163
|
-
themeName: DEFAULT_THEME_NAME,
|
|
164
|
-
themeMode: "system" as const,
|
|
165
|
-
isDark: false,
|
|
166
|
-
sidebarWidth: 320,
|
|
167
|
-
headerHeight: 56,
|
|
168
|
-
density: "compact" as const,
|
|
169
|
-
fontPreset: DEFAULT_FONT_PRESET,
|
|
170
|
-
editorDefaultMode: "markdown",
|
|
171
|
-
editorLightCodeTheme: "default",
|
|
172
|
-
editorDarkCodeTheme: "okaidia",
|
|
173
|
-
editorWordCountEnabled: true,
|
|
174
|
-
editorShortcuts: {
|
|
175
|
-
heading: true,
|
|
176
|
-
ulist: true,
|
|
177
|
-
olist: true,
|
|
178
|
-
quote: true,
|
|
179
|
-
code: true,
|
|
180
|
-
tasklist: true,
|
|
181
|
-
},
|
|
182
|
-
editorFontSize: 14,
|
|
183
|
-
editorAutoSave: true,
|
|
184
|
-
editorAutoSaveInterval: 30,
|
|
185
|
-
editorLineNumbers: false,
|
|
186
|
-
editorWordWrap: true,
|
|
187
|
-
editorSpellCheck: true,
|
|
188
|
-
editorTabSize: 2,
|
|
189
|
-
editorFontFamily: "SF Mono, Monaco, Cascadia Code, Roboto Mono, monospace",
|
|
190
|
-
enableReadCurrentSpace: true,
|
|
191
|
-
sidebarVisibleTypes: [...DEFAULT_SIDEBAR_VISIBLE_TYPES],
|
|
192
|
-
globalPrompt:
|
|
193
|
-
"以下是关于我的通用说明,请在任意场景下都以此来理解和服务我:\n" +
|
|
194
|
-
"1. 我希望你用清晰、简洁的方式回答问题,并在必要时给出示例。\n" +
|
|
195
|
-
"2. 如果有多种解决方案,请先给出推荐方案,再简要说明其他方案的优缺点。\n" +
|
|
196
|
-
"3. 当你不确定答案时,请明确说明不确定,并推测可能的方向,而不是编造事实。\n" +
|
|
197
|
-
"4. 如果涉及代码,请优先使用现代、通用的最佳实践。",
|
|
198
|
-
userTonePreset: DEFAULT_USER_PREFERENCE_PROFILE.tone?.preset ?? "default",
|
|
199
|
-
knowledgeCaptureLevel: DEFAULT_USER_PREFERENCE_PROFILE.knowledgeCaptureLevel,
|
|
200
|
-
spaceContextLevel: DEFAULT_USER_PREFERENCE_PROFILE.spaceContextLevel,
|
|
201
|
-
autoApproveSelfUpdateFields: [...DEFAULT_AUTO_APPROVED_SELF_UPDATE_FIELDS],
|
|
202
|
-
aiRecentContentLimit: 50,
|
|
203
|
-
contextRetention: 50,
|
|
204
|
-
defaultAgentId: SYSTEM_DEFAULT_AGENT_ID,
|
|
205
|
-
ocrModel: "olm_ocr",
|
|
206
|
-
showScrollToTopButton: false,
|
|
207
|
-
showScrollToBottomButton: false,
|
|
208
|
-
createMenuOpenCount: 0,
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// --- Slice 创建 ---
|
|
212
|
-
const createSliceWithThunks = buildCreateSlice({
|
|
213
|
-
creators: { asyncThunk: asyncThunkCreator },
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const hasOwn = (target: object, key: string): boolean =>
|
|
217
|
-
Object.prototype.hasOwnProperty.call(target, key);
|
|
218
|
-
|
|
219
|
-
const normalizeSidebarVisibleTypesSetting = (
|
|
220
|
-
value: unknown
|
|
221
|
-
): SidebarVisibleType[] => {
|
|
222
|
-
const rawValues = Array.isArray(value)
|
|
223
|
-
? value.filter((item): item is string => typeof item === "string")
|
|
224
|
-
: undefined;
|
|
225
|
-
const normalized = normalizeSidebarVisibleTypes(rawValues);
|
|
226
|
-
|
|
227
|
-
if (
|
|
228
|
-
rawValues &&
|
|
229
|
-
areSidebarVisibleTypesEqual(normalized, LEGACY_DEFAULT_SIDEBAR_VISIBLE_TYPES)
|
|
230
|
-
) {
|
|
231
|
-
return [...DEFAULT_SIDEBAR_VISIBLE_TYPES];
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return normalized;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
const normalizeDefaultAgentIdSetting = (
|
|
238
|
-
value: unknown
|
|
239
|
-
): string | undefined => {
|
|
240
|
-
if (typeof value !== "string" || value.trim() === "") {
|
|
241
|
-
return undefined;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return value === legacyNoloAgentId ||
|
|
245
|
-
value === noloAgentId ||
|
|
246
|
-
value === SYSTEM_DEFAULT_AGENT_ID
|
|
247
|
-
? SYSTEM_DEFAULT_AGENT_ID
|
|
248
|
-
: value;
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
const normalizeAuthorityHomeServerSetting = (value: unknown): string | null => {
|
|
252
|
-
if (typeof value !== "string") return null;
|
|
253
|
-
const trimmed = value.trim().replace(/\/+$/, "");
|
|
254
|
-
return /^https?:\/\//i.test(trimmed) ? trimmed : null;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
const normalizeTonePresetSetting = (value: unknown): TonePreset => {
|
|
258
|
-
switch (value) {
|
|
259
|
-
case "professional":
|
|
260
|
-
case "friendly":
|
|
261
|
-
case "direct":
|
|
262
|
-
case "pragmatic":
|
|
263
|
-
case "default":
|
|
264
|
-
return value;
|
|
265
|
-
default:
|
|
266
|
-
return DEFAULT_USER_PREFERENCE_PROFILE.tone?.preset ?? "default";
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
const normalizePolicyLevelSetting = (
|
|
271
|
-
value: unknown,
|
|
272
|
-
fallback: KnowledgeCaptureLevel | SpaceContextLevel
|
|
273
|
-
): KnowledgeCaptureLevel | SpaceContextLevel => {
|
|
274
|
-
const n = Number(value);
|
|
275
|
-
if (n === 1 || n === 2 || n === 3 || n === 4) {
|
|
276
|
-
return n;
|
|
277
|
-
}
|
|
278
|
-
return fallback;
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
const resolveDefaultAgentIdSetting = (value: unknown): string =>
|
|
282
|
-
normalizeDefaultAgentIdSetting(value) ?? SYSTEM_DEFAULT_AGENT_ID;
|
|
283
|
-
|
|
284
|
-
const selectResolvedDefaultAgentId = (value: unknown): string => {
|
|
285
|
-
const normalizedValue = resolveDefaultAgentIdSetting(value);
|
|
286
|
-
return normalizedValue === SYSTEM_DEFAULT_AGENT_ID
|
|
287
|
-
? noloAgentId
|
|
288
|
-
: normalizedValue;
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
const hexToRgbString = (value?: string): string | null => {
|
|
292
|
-
if (typeof value !== "string") return null;
|
|
293
|
-
const normalized = value.trim().replace(/^#/, "");
|
|
294
|
-
const safe = normalized.length === 3
|
|
295
|
-
? normalized
|
|
296
|
-
.split("")
|
|
297
|
-
.map((char) => char + char)
|
|
298
|
-
.join("")
|
|
299
|
-
: normalized;
|
|
300
|
-
|
|
301
|
-
if (!/^[0-9a-fA-F]{6}$/.test(safe)) return null;
|
|
302
|
-
|
|
303
|
-
const intValue = Number.parseInt(safe, 16);
|
|
304
|
-
const r = (intValue >> 16) & 255;
|
|
305
|
-
const g = (intValue >> 8) & 255;
|
|
306
|
-
const b = intValue & 255;
|
|
307
|
-
return `${r}, ${g}, ${b}`;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
const alphaColor = (hex: string | undefined, alpha: number, fallback: string): string => {
|
|
311
|
-
const rgb = hexToRgbString(hex);
|
|
312
|
-
return rgb ? `rgba(${rgb}, ${alpha})` : fallback;
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
const getCachedDefaultAgentRegisterRecord = (
|
|
316
|
-
getState: () => RootState,
|
|
317
|
-
registerKey: string
|
|
318
|
-
) => {
|
|
319
|
-
const record = getState().db.entities[registerKey];
|
|
320
|
-
return record && typeof record === "object" ? record : null;
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
const persistDefaultAgentRegister = async (
|
|
324
|
-
dispatch: any,
|
|
325
|
-
getState: () => RootState,
|
|
326
|
-
userId: string,
|
|
327
|
-
value: string | null,
|
|
328
|
-
) => {
|
|
329
|
-
const registerKey = createUserPreferenceKey.defaultAgent(userId);
|
|
330
|
-
let previousRecord = getCachedDefaultAgentRegisterRecord(getState, registerKey);
|
|
331
|
-
if (!previousRecord) {
|
|
332
|
-
previousRecord = await dispatch(getSettingDbActionThunks().readAndWait(registerKey))
|
|
333
|
-
.unwrap()
|
|
334
|
-
.catch(() => null);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const previousValue =
|
|
338
|
-
readUserPreferenceRegisterValue<string>(
|
|
339
|
-
previousRecord,
|
|
340
|
-
USER_PREFERENCE_NAMES.DEFAULT_AGENT
|
|
341
|
-
) ?? null;
|
|
342
|
-
if (previousRecord && previousValue === value) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
await dispatch(
|
|
347
|
-
getSettingDbActionThunks().write({
|
|
348
|
-
customKey: registerKey,
|
|
349
|
-
data: buildDefaultAgentPreferenceRegisterRecord({
|
|
350
|
-
userId,
|
|
351
|
-
defaultAgentId: value,
|
|
352
|
-
previousRecord,
|
|
353
|
-
}),
|
|
354
|
-
})
|
|
355
|
-
).unwrap();
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
const omitKeys = <T extends Record<string, any>>(
|
|
359
|
-
record: T,
|
|
360
|
-
keys: readonly string[],
|
|
361
|
-
) => {
|
|
362
|
-
const next = { ...record };
|
|
363
|
-
keys.forEach((key) => {
|
|
364
|
-
delete next[key];
|
|
365
|
-
});
|
|
366
|
-
return next;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const normalizeSettingChanges = (
|
|
370
|
-
changes: Partial<SettingState>
|
|
371
|
-
): Partial<SettingState> => {
|
|
372
|
-
let normalizedChanges = changes;
|
|
373
|
-
|
|
374
|
-
if (hasOwn(normalizedChanges, "sidebarVisibleTypes")) {
|
|
375
|
-
normalizedChanges = {
|
|
376
|
-
...normalizedChanges,
|
|
377
|
-
sidebarVisibleTypes: normalizeSidebarVisibleTypesSetting(
|
|
378
|
-
normalizedChanges.sidebarVisibleTypes
|
|
379
|
-
),
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (hasOwn(normalizedChanges, "defaultAgentId")) {
|
|
384
|
-
normalizedChanges = {
|
|
385
|
-
...normalizedChanges,
|
|
386
|
-
defaultAgentId: normalizeDefaultAgentIdSetting(
|
|
387
|
-
normalizedChanges.defaultAgentId
|
|
388
|
-
),
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
if (hasOwn(normalizedChanges, "defaultSpaceId")) {
|
|
393
|
-
normalizedChanges = {
|
|
394
|
-
...normalizedChanges,
|
|
395
|
-
defaultSpaceId: normalizeDefaultSpaceIdPreference(
|
|
396
|
-
normalizedChanges.defaultSpaceId
|
|
397
|
-
),
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if (hasOwn(normalizedChanges, "themeName")) {
|
|
402
|
-
const themeName = normalizeThemeName(normalizedChanges.themeName);
|
|
403
|
-
normalizedChanges = themeName
|
|
404
|
-
? {
|
|
405
|
-
...normalizedChanges,
|
|
406
|
-
themeName,
|
|
407
|
-
}
|
|
408
|
-
: omitKeys(normalizedChanges, ["themeName"]);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (hasOwn(normalizedChanges, "fontPreset")) {
|
|
412
|
-
const fontPreset = normalizeFontPreset(normalizedChanges.fontPreset);
|
|
413
|
-
normalizedChanges = fontPreset
|
|
414
|
-
? {
|
|
415
|
-
...normalizedChanges,
|
|
416
|
-
fontPreset,
|
|
417
|
-
}
|
|
418
|
-
: omitKeys(normalizedChanges, ["fontPreset"]);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (hasOwn(normalizedChanges, "userTonePreset")) {
|
|
422
|
-
normalizedChanges = {
|
|
423
|
-
...normalizedChanges,
|
|
424
|
-
userTonePreset: normalizeTonePresetSetting(
|
|
425
|
-
normalizedChanges.userTonePreset
|
|
426
|
-
),
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (hasOwn(normalizedChanges, "knowledgeCaptureLevel")) {
|
|
431
|
-
normalizedChanges = {
|
|
432
|
-
...normalizedChanges,
|
|
433
|
-
knowledgeCaptureLevel: normalizePolicyLevelSetting(
|
|
434
|
-
normalizedChanges.knowledgeCaptureLevel,
|
|
435
|
-
DEFAULT_USER_PREFERENCE_PROFILE.knowledgeCaptureLevel
|
|
436
|
-
) as KnowledgeCaptureLevel,
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
if (hasOwn(normalizedChanges, "spaceContextLevel")) {
|
|
441
|
-
normalizedChanges = {
|
|
442
|
-
...normalizedChanges,
|
|
443
|
-
spaceContextLevel: normalizePolicyLevelSetting(
|
|
444
|
-
normalizedChanges.spaceContextLevel,
|
|
445
|
-
DEFAULT_USER_PREFERENCE_PROFILE.spaceContextLevel
|
|
446
|
-
) as SpaceContextLevel,
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (hasOwn(normalizedChanges, "autoApproveSelfUpdateFields")) {
|
|
451
|
-
normalizedChanges = {
|
|
452
|
-
...normalizedChanges,
|
|
453
|
-
autoApproveSelfUpdateFields: normalizeAgentUpdateFieldList(
|
|
454
|
-
normalizedChanges.autoApproveSelfUpdateFields
|
|
455
|
-
),
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
return normalizedChanges;
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
const LOCAL_FIRST_APPEARANCE_KEYS: ReadonlySet<keyof SettingState> = new Set([
|
|
463
|
-
"themeName",
|
|
464
|
-
"themeMode",
|
|
465
|
-
"isDark",
|
|
466
|
-
"density",
|
|
467
|
-
"fontPreset",
|
|
468
|
-
]);
|
|
469
|
-
|
|
470
|
-
const LOCAL_ONLY_SETTINGS_KEYS: ReadonlySet<keyof SettingState> = new Set([
|
|
471
|
-
"themeName",
|
|
472
|
-
"themeMode",
|
|
473
|
-
"isDark",
|
|
474
|
-
"density",
|
|
475
|
-
"fontPreset",
|
|
476
|
-
]);
|
|
477
|
-
|
|
478
|
-
const isLocalFirstAppearanceChange = (
|
|
479
|
-
changes: Partial<SettingState>
|
|
480
|
-
): boolean => {
|
|
481
|
-
const keys = Object.keys(changes) as Array<keyof SettingState>;
|
|
482
|
-
return (
|
|
483
|
-
keys.length > 0 &&
|
|
484
|
-
keys.every((key) => LOCAL_FIRST_APPEARANCE_KEYS.has(key))
|
|
485
|
-
);
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
const stripRegisterBackedFieldsFromSettingsWrite = (
|
|
489
|
-
changes: Partial<SettingState>
|
|
490
|
-
): Partial<SettingState> => {
|
|
491
|
-
return omitKeys(changes, [
|
|
492
|
-
"defaultSpaceId",
|
|
493
|
-
"userAuthorityRegistry",
|
|
494
|
-
...LOCAL_ONLY_SETTINGS_KEYS,
|
|
495
|
-
]);
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
const sanitizeStoredSettingsRecord = (
|
|
499
|
-
settingsRecord: any
|
|
500
|
-
): Record<string, any> | null => {
|
|
501
|
-
if (!settingsRecord || typeof settingsRecord !== "object") {
|
|
502
|
-
return null;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
const sanitizedSettings = omitKeys(settingsRecord, [
|
|
506
|
-
"defaultSpaceId",
|
|
507
|
-
"schemaVersion",
|
|
508
|
-
...LOCAL_ONLY_SETTINGS_KEYS,
|
|
509
|
-
]);
|
|
510
|
-
return Object.keys(sanitizedSettings).length > 0 ? sanitizedSettings : null;
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
export const hydrateStoredSettings = ({
|
|
514
|
-
userId,
|
|
515
|
-
settingsRecord,
|
|
516
|
-
defaultSpaceId,
|
|
517
|
-
authorityHomeServer,
|
|
518
|
-
}: {
|
|
519
|
-
userId?: string | null;
|
|
520
|
-
settingsRecord: any;
|
|
521
|
-
defaultSpaceId?: string | null;
|
|
522
|
-
authorityHomeServer?: string | null;
|
|
523
|
-
}): Record<string, any> | null => {
|
|
524
|
-
const resolvedDefaultAgentId =
|
|
525
|
-
normalizeDefaultAgentIdSetting(settingsRecord?.defaultAgentId) ??
|
|
526
|
-
SYSTEM_DEFAULT_AGENT_ID;
|
|
527
|
-
|
|
528
|
-
const baseSettings = sanitizeStoredSettingsRecord(settingsRecord) ?? {};
|
|
529
|
-
const normalizedAuthorityHome =
|
|
530
|
-
normalizeAuthorityHomeServerSetting(authorityHomeServer);
|
|
531
|
-
const userAuthorityRegistry =
|
|
532
|
-
userId && normalizedAuthorityHome
|
|
533
|
-
? {
|
|
534
|
-
...((baseSettings.userAuthorityRegistry &&
|
|
535
|
-
typeof baseSettings.userAuthorityRegistry === "object")
|
|
536
|
-
? baseSettings.userAuthorityRegistry
|
|
537
|
-
: {}),
|
|
538
|
-
[userId]: normalizedAuthorityHome,
|
|
539
|
-
}
|
|
540
|
-
: baseSettings.userAuthorityRegistry;
|
|
541
|
-
const hydratedSettings = {
|
|
542
|
-
...baseSettings,
|
|
543
|
-
...(userAuthorityRegistry ? { userAuthorityRegistry } : {}),
|
|
544
|
-
defaultSpaceId: normalizeDefaultSpaceIdPreference(defaultSpaceId) ?? null,
|
|
545
|
-
defaultAgentId: resolvedDefaultAgentId,
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
return Object.keys(hydratedSettings).length > 0 ? hydratedSettings : null;
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
export const buildSettingsPersistencePlan = ({
|
|
552
|
-
userId,
|
|
553
|
-
currentSettings,
|
|
554
|
-
changes,
|
|
555
|
-
previousDefaultAgentRecord,
|
|
556
|
-
}: {
|
|
557
|
-
userId: string;
|
|
558
|
-
currentSettings: Partial<SettingState>;
|
|
559
|
-
changes: Partial<SettingState>;
|
|
560
|
-
previousDefaultAgentRecord: any;
|
|
561
|
-
}) => {
|
|
562
|
-
const normalizedChanges = normalizeSettingChanges(changes);
|
|
563
|
-
const persistedChanges =
|
|
564
|
-
stripRegisterBackedFieldsFromSettingsWrite(normalizedChanges);
|
|
565
|
-
const previousDefaultAgentId =
|
|
566
|
-
normalizeDefaultAgentIdSetting(currentSettings.defaultAgentId) ??
|
|
567
|
-
SYSTEM_DEFAULT_AGENT_ID;
|
|
568
|
-
const nextDefaultAgentId =
|
|
569
|
-
normalizeDefaultAgentIdSetting(normalizedChanges.defaultAgentId) ?? null;
|
|
570
|
-
|
|
571
|
-
const previousDefaultAgentValue =
|
|
572
|
-
readUserPreferenceRegisterValue<string>(
|
|
573
|
-
previousDefaultAgentRecord,
|
|
574
|
-
USER_PREFERENCE_NAMES.DEFAULT_AGENT
|
|
575
|
-
) ?? null;
|
|
576
|
-
|
|
577
|
-
const defaultAgentRegisterWrite =
|
|
578
|
-
hasOwn(normalizedChanges, "defaultAgentId") &&
|
|
579
|
-
previousDefaultAgentId !== (nextDefaultAgentId ?? SYSTEM_DEFAULT_AGENT_ID) &&
|
|
580
|
-
(!previousDefaultAgentRecord || previousDefaultAgentValue !== nextDefaultAgentId)
|
|
581
|
-
? {
|
|
582
|
-
customKey: createUserPreferenceKey.defaultAgent(userId),
|
|
583
|
-
data: buildDefaultAgentPreferenceRegisterRecord({
|
|
584
|
-
userId,
|
|
585
|
-
defaultAgentId: nextDefaultAgentId,
|
|
586
|
-
previousRecord: previousDefaultAgentRecord,
|
|
587
|
-
}),
|
|
588
|
-
}
|
|
589
|
-
: null;
|
|
590
|
-
|
|
591
|
-
const settingsPatch =
|
|
592
|
-
Object.keys(persistedChanges).length > 0
|
|
593
|
-
? {
|
|
594
|
-
dbKey: createUserKey.settings(userId),
|
|
595
|
-
changes: withSettingsRecordSchema(persistedChanges),
|
|
596
|
-
}
|
|
597
|
-
: null;
|
|
598
|
-
|
|
599
|
-
return {
|
|
600
|
-
normalizedChanges,
|
|
601
|
-
defaultAgentRegisterWrite,
|
|
602
|
-
settingsPatch,
|
|
603
|
-
};
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
const settingSlice = createSliceWithThunks({
|
|
607
|
-
name: "settings",
|
|
608
|
-
initialState,
|
|
609
|
-
reducers: (create) => ({
|
|
610
|
-
_updateSettingsState: (
|
|
611
|
-
state,
|
|
612
|
-
action: PayloadAction<Partial<SettingState>>
|
|
613
|
-
) => {
|
|
614
|
-
Object.assign(state, normalizeSettingChanges(action.payload));
|
|
615
|
-
},
|
|
616
|
-
clearDefaultSpaceId: (state) => {
|
|
617
|
-
state.defaultSpaceId = initialState.defaultSpaceId;
|
|
618
|
-
},
|
|
619
|
-
addHostToCurrentServer: (state, action: PayloadAction<string>) => {
|
|
620
|
-
const rawValue = action.payload;
|
|
621
|
-
if (typeof rawValue !== "string" || rawValue.trim() === "") return;
|
|
622
|
-
|
|
623
|
-
const trimmed = rawValue.trim();
|
|
624
|
-
if (/^https?:\/\//i.test(trimmed)) {
|
|
625
|
-
try {
|
|
626
|
-
state.currentServer = new URL(trimmed).origin;
|
|
627
|
-
return;
|
|
628
|
-
} catch {
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
const host = trimmed.replace(/^\/+|\/+$/g, "");
|
|
634
|
-
const [hostname] = host.split(":");
|
|
635
|
-
if (!hostname) return;
|
|
636
|
-
const isIpAddress = /^(\d{1,3}\.){3}\d{1,3}$/.test(hostname);
|
|
637
|
-
const isLocal =
|
|
638
|
-
["nolotus.local", "localhost"].includes(hostname) || isIpAddress;
|
|
639
|
-
const protocol = isLocal ? "http" : "https";
|
|
640
|
-
state.currentServer = `${protocol}://${host}`;
|
|
641
|
-
},
|
|
642
|
-
getSettings: create.asyncThunk(
|
|
643
|
-
async (_, { dispatch, getState }) => {
|
|
644
|
-
const userId = selectUserId(getState() as RootState);
|
|
645
|
-
if (!userId) return null;
|
|
646
|
-
const settingsKey = createUserKey.settings(userId);
|
|
647
|
-
const authorityHomeKey = createUserPreferenceKey.authorityHome(userId);
|
|
648
|
-
const [settingsRecord, defaultSpaceId, authorityHomeRecord] = await Promise.all([
|
|
649
|
-
dispatch(getSettingDbActionThunks().readAndWait(settingsKey))
|
|
650
|
-
.unwrap()
|
|
651
|
-
.catch(() => null),
|
|
652
|
-
readDefaultSpaceIdPreference(dispatch, userId),
|
|
653
|
-
dispatch(getSettingDbActionThunks().readAndWait(authorityHomeKey))
|
|
654
|
-
.unwrap()
|
|
655
|
-
.catch(() => null),
|
|
656
|
-
]);
|
|
657
|
-
const authorityHomeServer =
|
|
658
|
-
readUserPreferenceRegisterValue<string>(
|
|
659
|
-
authorityHomeRecord,
|
|
660
|
-
USER_PREFERENCE_NAMES.AUTHORITY_HOME
|
|
661
|
-
) ?? null;
|
|
662
|
-
|
|
663
|
-
return hydrateStoredSettings({
|
|
664
|
-
userId,
|
|
665
|
-
settingsRecord,
|
|
666
|
-
defaultSpaceId,
|
|
667
|
-
authorityHomeServer,
|
|
668
|
-
});
|
|
669
|
-
},
|
|
670
|
-
{
|
|
671
|
-
fulfilled: (state, action) => {
|
|
672
|
-
if (action.payload) {
|
|
673
|
-
const normalizedPayload = normalizeSettingChanges(
|
|
674
|
-
action.payload as Partial<SettingState>
|
|
675
|
-
);
|
|
676
|
-
const { currentServer: _ignored, ...settingsToApply } = normalizedPayload;
|
|
677
|
-
Object.assign(state, settingsToApply);
|
|
678
|
-
}
|
|
679
|
-
},
|
|
680
|
-
}
|
|
681
|
-
),
|
|
682
|
-
setSettings: create.asyncThunk(
|
|
683
|
-
async (changes: Partial<SettingState>, { dispatch, getState }) => {
|
|
684
|
-
const currentSettings = (getState() as RootState).settings;
|
|
685
|
-
const normalizedChanges = normalizeSettingChanges(changes);
|
|
686
|
-
const nextDefaultSpaceId =
|
|
687
|
-
normalizeDefaultSpaceIdPreference(normalizedChanges.defaultSpaceId) ??
|
|
688
|
-
null;
|
|
689
|
-
const previousDefaultAgentId =
|
|
690
|
-
normalizeDefaultAgentIdSetting(
|
|
691
|
-
currentSettings.defaultAgentId,
|
|
692
|
-
) ?? SYSTEM_DEFAULT_AGENT_ID;
|
|
693
|
-
const userId = selectUserId(getState() as RootState);
|
|
694
|
-
if (!userId) {
|
|
695
|
-
if (!isLocalFirstAppearanceChange(normalizedChanges)) {
|
|
696
|
-
throw new Error("User not found for persisting settings.");
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
dispatch(settingSlice.actions._updateSettingsState(normalizedChanges));
|
|
700
|
-
return normalizedChanges;
|
|
701
|
-
}
|
|
702
|
-
const persistencePlan = buildSettingsPersistencePlan({
|
|
703
|
-
userId,
|
|
704
|
-
currentSettings,
|
|
705
|
-
changes: normalizedChanges,
|
|
706
|
-
previousDefaultAgentRecord: null,
|
|
707
|
-
});
|
|
708
|
-
dispatch(settingSlice.actions._updateSettingsState(persistencePlan.normalizedChanges));
|
|
709
|
-
if (hasOwn(changes, "defaultSpaceId")) {
|
|
710
|
-
await persistDefaultSpacePreference(
|
|
711
|
-
dispatch,
|
|
712
|
-
userId,
|
|
713
|
-
nextDefaultSpaceId
|
|
714
|
-
);
|
|
715
|
-
}
|
|
716
|
-
const nextDefaultAgentId =
|
|
717
|
-
normalizeDefaultAgentIdSetting(persistencePlan.normalizedChanges.defaultAgentId) ??
|
|
718
|
-
null;
|
|
719
|
-
if (
|
|
720
|
-
hasOwn(changes, "defaultAgentId") &&
|
|
721
|
-
previousDefaultAgentId !== (nextDefaultAgentId ?? SYSTEM_DEFAULT_AGENT_ID)
|
|
722
|
-
) {
|
|
723
|
-
await persistDefaultAgentRegister(
|
|
724
|
-
dispatch,
|
|
725
|
-
() => getState() as RootState,
|
|
726
|
-
userId,
|
|
727
|
-
nextDefaultAgentId,
|
|
728
|
-
);
|
|
729
|
-
}
|
|
730
|
-
if (persistencePlan.settingsPatch) {
|
|
731
|
-
await dispatch(
|
|
732
|
-
getSettingDbActionThunks().upsert({
|
|
733
|
-
dbKey: persistencePlan.settingsPatch.dbKey,
|
|
734
|
-
data: persistencePlan.settingsPatch.changes,
|
|
735
|
-
})
|
|
736
|
-
).unwrap();
|
|
737
|
-
}
|
|
738
|
-
return persistencePlan.normalizedChanges;
|
|
739
|
-
}
|
|
740
|
-
),
|
|
741
|
-
changeTheme: create.asyncThunk(
|
|
742
|
-
async (themeName: keyof typeof THEME_COLORS, { dispatch }) =>
|
|
743
|
-
dispatch(setSettings({ themeName })).unwrap()
|
|
744
|
-
),
|
|
745
|
-
changeDensity: create.asyncThunk(
|
|
746
|
-
async (density: "compact" | "spacious", { dispatch }) =>
|
|
747
|
-
dispatch(setSettings({ density })).unwrap()
|
|
748
|
-
),
|
|
749
|
-
changeFontPreset: create.asyncThunk(
|
|
750
|
-
async (fontPreset: FontPreset, { dispatch }) =>
|
|
751
|
-
dispatch(setSettings({ fontPreset })).unwrap()
|
|
752
|
-
),
|
|
753
|
-
changeDarkMode: create.asyncThunk(async (isDark: boolean, { dispatch }) =>
|
|
754
|
-
dispatch(setSettings({ isDark, themeMode: isDark ? "dark" : "light" })).unwrap()
|
|
755
|
-
),
|
|
756
|
-
toggleShowThinking: create.asyncThunk(async (_, { dispatch, getState }) => {
|
|
757
|
-
const currentShowThinking = (getState() as RootState).settings
|
|
758
|
-
.showThinking;
|
|
759
|
-
return dispatch(
|
|
760
|
-
setSettings({ showThinking: !currentShowThinking })
|
|
761
|
-
).unwrap();
|
|
762
|
-
}),
|
|
763
|
-
setThemeFollowsSystem: create.asyncThunk(
|
|
764
|
-
async (follows: boolean, { dispatch }) =>
|
|
765
|
-
dispatch(setSettings({ themeMode: follows ? "system" : "light" })).unwrap()
|
|
766
|
-
),
|
|
767
|
-
setSidebarWidth: create.asyncThunk(
|
|
768
|
-
async (sidebarWidth: number, { dispatch }) =>
|
|
769
|
-
dispatch(setSettings({ sidebarWidth })).unwrap()
|
|
770
|
-
),
|
|
771
|
-
toggleEnableReadCurrentSpace: create.asyncThunk(
|
|
772
|
-
async (_, { dispatch, getState }) => {
|
|
773
|
-
const current = (getState() as RootState).settings
|
|
774
|
-
.enableReadCurrentSpace;
|
|
775
|
-
return dispatch(
|
|
776
|
-
setSettings({
|
|
777
|
-
enableReadCurrentSpace: !current,
|
|
778
|
-
spaceContextLevel: current ? 1 : DEFAULT_USER_PREFERENCE_PROFILE.spaceContextLevel,
|
|
779
|
-
})
|
|
780
|
-
).unwrap();
|
|
781
|
-
}
|
|
782
|
-
),
|
|
783
|
-
setEditorDefaultMode: create.asyncThunk(
|
|
784
|
-
async (mode: "markdown" | "block", { dispatch }) =>
|
|
785
|
-
dispatch(setSettings({ editorDefaultMode: mode })).unwrap()
|
|
786
|
-
),
|
|
787
|
-
setEditorLightCodeTheme: create.asyncThunk(
|
|
788
|
-
async (theme: string, { dispatch }) =>
|
|
789
|
-
dispatch(setSettings({ editorLightCodeTheme: theme })).unwrap()
|
|
790
|
-
),
|
|
791
|
-
setEditorDarkCodeTheme: create.asyncThunk(
|
|
792
|
-
async (theme: string, { dispatch }) =>
|
|
793
|
-
dispatch(setSettings({ editorDarkCodeTheme: theme })).unwrap()
|
|
794
|
-
),
|
|
795
|
-
setEditorCodeTheme: create.asyncThunk(async (theme: string, { dispatch }) =>
|
|
796
|
-
dispatch(
|
|
797
|
-
setSettings({
|
|
798
|
-
editorLightCodeTheme: theme,
|
|
799
|
-
editorDarkCodeTheme: theme,
|
|
800
|
-
})
|
|
801
|
-
).unwrap()
|
|
802
|
-
),
|
|
803
|
-
toggleEditorWordCount: create.asyncThunk(
|
|
804
|
-
async (_, { dispatch, getState }) => {
|
|
805
|
-
const current = (getState() as RootState).settings
|
|
806
|
-
.editorWordCountEnabled;
|
|
807
|
-
return dispatch(
|
|
808
|
-
setSettings({ editorWordCountEnabled: !current })
|
|
809
|
-
).unwrap();
|
|
810
|
-
}
|
|
811
|
-
),
|
|
812
|
-
toggleEditorShortcut: create.asyncThunk(
|
|
813
|
-
async (key: string, { dispatch, getState }) => {
|
|
814
|
-
const currentShortcuts = (getState() as RootState).settings
|
|
815
|
-
.editorShortcuts;
|
|
816
|
-
const newShortcuts = {
|
|
817
|
-
...currentShortcuts,
|
|
818
|
-
[key]: !currentShortcuts[key],
|
|
819
|
-
};
|
|
820
|
-
return dispatch(
|
|
821
|
-
setSettings({ editorShortcuts: newShortcuts })
|
|
822
|
-
).unwrap();
|
|
823
|
-
}
|
|
824
|
-
),
|
|
825
|
-
setEditorFontSize: create.asyncThunk(
|
|
826
|
-
async (fontSize: number, { dispatch }) =>
|
|
827
|
-
dispatch(setSettings({ editorFontSize: fontSize })).unwrap()
|
|
828
|
-
),
|
|
829
|
-
toggleEditorAutoSave: create.asyncThunk(
|
|
830
|
-
async (_, { dispatch, getState }) => {
|
|
831
|
-
const current = (getState() as RootState).settings.editorAutoSave;
|
|
832
|
-
return dispatch(setSettings({ editorAutoSave: !current })).unwrap();
|
|
833
|
-
}
|
|
834
|
-
),
|
|
835
|
-
setEditorAutoSaveInterval: create.asyncThunk(
|
|
836
|
-
async (interval: number, { dispatch }) =>
|
|
837
|
-
dispatch(setSettings({ editorAutoSaveInterval: interval })).unwrap()
|
|
838
|
-
),
|
|
839
|
-
setGlobalPrompt: create.asyncThunk(
|
|
840
|
-
async (prompt: string, { dispatch }) =>
|
|
841
|
-
dispatch(setSettings({ globalPrompt: prompt })).unwrap()
|
|
842
|
-
),
|
|
843
|
-
setUserTonePreset: create.asyncThunk(
|
|
844
|
-
async (tone: TonePreset, { dispatch }) =>
|
|
845
|
-
dispatch(setSettings({ userTonePreset: tone })).unwrap()
|
|
846
|
-
),
|
|
847
|
-
setKnowledgeCaptureLevel: create.asyncThunk(
|
|
848
|
-
async (level: KnowledgeCaptureLevel, { dispatch }) =>
|
|
849
|
-
dispatch(setSettings({ knowledgeCaptureLevel: level })).unwrap()
|
|
850
|
-
),
|
|
851
|
-
setSpaceContextLevel: create.asyncThunk(
|
|
852
|
-
async (level: SpaceContextLevel, { dispatch }) =>
|
|
853
|
-
dispatch(
|
|
854
|
-
setSettings({
|
|
855
|
-
spaceContextLevel: level,
|
|
856
|
-
enableReadCurrentSpace: level > 1,
|
|
857
|
-
})
|
|
858
|
-
).unwrap()
|
|
859
|
-
),
|
|
860
|
-
// ADDED action
|
|
861
|
-
setAiRecentContentLimit: create.asyncThunk(
|
|
862
|
-
async (limit: number, { dispatch }) =>
|
|
863
|
-
dispatch(setSettings({ aiRecentContentLimit: limit })).unwrap()
|
|
864
|
-
),
|
|
865
|
-
setContextRetention: create.asyncThunk(
|
|
866
|
-
async (retention: number, { dispatch }) =>
|
|
867
|
-
dispatch(setSettings({ contextRetention: retention })).unwrap()
|
|
868
|
-
),
|
|
869
|
-
setMaxExecutionTime: create.asyncThunk(
|
|
870
|
-
async (time: number, { dispatch }) =>
|
|
871
|
-
dispatch(setSettings({ maxExecutionTime: time })).unwrap()
|
|
872
|
-
),
|
|
873
|
-
setDefaultAgentId: create.asyncThunk(
|
|
874
|
-
async (agentId: string, { dispatch }) =>
|
|
875
|
-
dispatch(setSettings({ defaultAgentId: agentId })).unwrap()
|
|
876
|
-
),
|
|
877
|
-
setPreferredAnimationSet: create.asyncThunk(
|
|
878
|
-
async (index: number, { dispatch }) =>
|
|
879
|
-
dispatch(setSettings({ preferredAnimationSet: index })).unwrap()
|
|
880
|
-
),
|
|
881
|
-
setThemeMode: create.asyncThunk(
|
|
882
|
-
async (mode: "system" | "light" | "dark", { dispatch }) => {
|
|
883
|
-
const changes: Partial<SettingState> = { themeMode: mode };
|
|
884
|
-
const systemPrefersDark =
|
|
885
|
-
typeof window !== "undefined" &&
|
|
886
|
-
window.matchMedia(SYSTEM_DARK_MEDIA_QUERY).matches;
|
|
887
|
-
changes.isDark = resolveThemeModeIsDark(mode, systemPrefersDark);
|
|
888
|
-
return dispatch(setSettings(changes)).unwrap();
|
|
889
|
-
}
|
|
890
|
-
),
|
|
891
|
-
}),
|
|
892
|
-
});
|
|
893
|
-
|
|
894
|
-
// --- 导出 Actions ---
|
|
895
|
-
export const {
|
|
896
|
-
getSettings,
|
|
897
|
-
setSettings,
|
|
898
|
-
clearDefaultSpaceId,
|
|
899
|
-
addHostToCurrentServer,
|
|
900
|
-
changeTheme,
|
|
901
|
-
changeDensity,
|
|
902
|
-
changeFontPreset,
|
|
903
|
-
changeDarkMode,
|
|
904
|
-
toggleShowThinking,
|
|
905
|
-
setThemeFollowsSystem,
|
|
906
|
-
setSidebarWidth,
|
|
907
|
-
toggleEnableReadCurrentSpace,
|
|
908
|
-
setEditorDefaultMode,
|
|
909
|
-
setEditorLightCodeTheme,
|
|
910
|
-
setEditorDarkCodeTheme,
|
|
911
|
-
setEditorCodeTheme,
|
|
912
|
-
toggleEditorWordCount,
|
|
913
|
-
toggleEditorShortcut,
|
|
914
|
-
setEditorFontSize,
|
|
915
|
-
toggleEditorAutoSave,
|
|
916
|
-
setEditorAutoSaveInterval,
|
|
917
|
-
setGlobalPrompt,
|
|
918
|
-
setUserTonePreset,
|
|
919
|
-
setKnowledgeCaptureLevel,
|
|
920
|
-
setSpaceContextLevel,
|
|
921
|
-
setAiRecentContentLimit,
|
|
922
|
-
setContextRetention, // ADDED
|
|
923
|
-
setMaxExecutionTime,
|
|
924
|
-
setDefaultAgentId,
|
|
925
|
-
setPreferredAnimationSet,
|
|
926
|
-
setThemeMode,
|
|
927
|
-
} = settingSlice.actions;
|
|
928
|
-
|
|
929
|
-
// --- 导出 Selectors ---
|
|
930
|
-
export const selectSettings = (state: RootState) => state.settings;
|
|
931
|
-
const isLocalServerUrl = (value: string | undefined): boolean => {
|
|
932
|
-
if (typeof value !== "string") return false;
|
|
933
|
-
return /^https?:\/\/(?:(?:\d{1,3}\.){3}\d{1,3}|localhost|nolotus\.local)(?::\d+)?$/i.test(
|
|
934
|
-
value.trim()
|
|
935
|
-
);
|
|
936
|
-
};
|
|
937
|
-
|
|
938
|
-
const resolveDesktopSafeServer = (value: string | undefined): string => {
|
|
939
|
-
if (!getIsDesktopApp()) return value || SERVERS.MAIN;
|
|
940
|
-
return isLocalServerUrl(value) ? SERVERS.MAIN : value || SERVERS.MAIN;
|
|
941
|
-
};
|
|
942
|
-
|
|
943
|
-
export const selectCurrentServer = createSelector(
|
|
944
|
-
[selectSettings],
|
|
945
|
-
(settings) => resolveDesktopSafeServer(settings.currentServer)
|
|
946
|
-
);
|
|
947
|
-
export const selectSyncServers = createSelector([selectSettings], (settings): string[] =>
|
|
948
|
-
(settings.syncServers || []).filter(
|
|
949
|
-
(server) => !getIsDesktopApp() || !isLocalServerUrl(server)
|
|
950
|
-
)
|
|
951
|
-
);
|
|
952
|
-
export const selectRemoteServer = selectCurrentServer;
|
|
953
|
-
export const selectRemoteSyncServers = selectSyncServers;
|
|
954
|
-
export const selectRemoteServers = createSelector(
|
|
955
|
-
[selectRemoteServer, selectRemoteSyncServers],
|
|
956
|
-
(currentServer, syncServers) => getAllServers(currentServer, syncServers)
|
|
957
|
-
);
|
|
958
|
-
export const selectDefaultSpaceId = (
|
|
959
|
-
state: RootState
|
|
960
|
-
): string | null | undefined => state.settings.defaultSpaceId;
|
|
961
|
-
|
|
962
|
-
export const selectPreferredAnimationSet = (state: RootState): number =>
|
|
963
|
-
state.settings.preferredAnimationSet ?? DEFAULT_ANIMATION_SET_INDEX;
|
|
964
|
-
export const selectShowThinking = (state: RootState): boolean =>
|
|
965
|
-
state.settings.showThinking;
|
|
966
|
-
export const selectMaxCost = (state: RootState): number =>
|
|
967
|
-
state.settings.maxCost;
|
|
968
|
-
export const selectMaxExecutionTime = (state: RootState): number =>
|
|
969
|
-
state.settings.maxExecutionTime;
|
|
970
|
-
export const selectIsDark = (state: RootState): boolean =>
|
|
971
|
-
state.settings.isDark;
|
|
972
|
-
export const selectThemeMode = (state: RootState): "system" | "light" | "dark" =>
|
|
973
|
-
state.settings.themeMode ?? "system";
|
|
974
|
-
export const selectHeaderHeight = (state: RootState): number =>
|
|
975
|
-
state.settings.headerHeight;
|
|
976
|
-
export const selectThemeName = (state: RootState): keyof typeof THEME_COLORS =>
|
|
977
|
-
state.settings.themeName;
|
|
978
|
-
export const selectThemeFollowsSystem = (state: RootState): boolean =>
|
|
979
|
-
(state.settings.themeMode ?? "system") === "system";
|
|
980
|
-
export const selectSidebarWidth = (state: RootState): number =>
|
|
981
|
-
state.settings.sidebarWidth;
|
|
982
|
-
export const selectDensity = (state: RootState): "compact" | "spacious" =>
|
|
983
|
-
state.settings.density ?? "compact";
|
|
984
|
-
export const selectFontPreset = (state: RootState): FontPreset =>
|
|
985
|
-
normalizeFontPreset(state.settings.fontPreset) ?? DEFAULT_FONT_PRESET;
|
|
986
|
-
export const selectEnableReadCurrentSpace = (state: RootState): boolean =>
|
|
987
|
-
state.settings.enableReadCurrentSpace;
|
|
988
|
-
export const selectSidebarVisibleTypes = createSelector(
|
|
989
|
-
[(state: RootState) => state.settings.sidebarVisibleTypes],
|
|
990
|
-
(sidebarVisibleTypes): SidebarVisibleType[] =>
|
|
991
|
-
normalizeSidebarVisibleTypesSetting(sidebarVisibleTypes)
|
|
992
|
-
);
|
|
993
|
-
export const selectGlobalPrompt = (state: RootState): string =>
|
|
994
|
-
state.settings.globalPrompt;
|
|
995
|
-
export const selectUserTonePreset = (state: RootState): TonePreset =>
|
|
996
|
-
normalizeTonePresetSetting(state.settings.userTonePreset);
|
|
997
|
-
export const selectKnowledgeCaptureLevel = (
|
|
998
|
-
state: RootState
|
|
999
|
-
): KnowledgeCaptureLevel =>
|
|
1000
|
-
normalizePolicyLevelSetting(
|
|
1001
|
-
state.settings.knowledgeCaptureLevel,
|
|
1002
|
-
DEFAULT_USER_PREFERENCE_PROFILE.knowledgeCaptureLevel
|
|
1003
|
-
) as KnowledgeCaptureLevel;
|
|
1004
|
-
export const selectSpaceContextLevel = (
|
|
1005
|
-
state: RootState
|
|
1006
|
-
): SpaceContextLevel =>
|
|
1007
|
-
state.settings.enableReadCurrentSpace === false
|
|
1008
|
-
? 1
|
|
1009
|
-
:
|
|
1010
|
-
normalizePolicyLevelSetting(
|
|
1011
|
-
state.settings.spaceContextLevel,
|
|
1012
|
-
DEFAULT_USER_PREFERENCE_PROFILE.spaceContextLevel
|
|
1013
|
-
) as SpaceContextLevel;
|
|
1014
|
-
export const selectAutoApproveSelfUpdateFields = createSelector(
|
|
1015
|
-
[(state: RootState) => state.settings.autoApproveSelfUpdateFields],
|
|
1016
|
-
(fields) =>
|
|
1017
|
-
normalizeAgentUpdateFieldList(
|
|
1018
|
-
fields,
|
|
1019
|
-
DEFAULT_AUTO_APPROVED_SELF_UPDATE_FIELDS
|
|
1020
|
-
)
|
|
1021
|
-
);
|
|
1022
|
-
export const selectAiRecentContentLimit = (state: RootState): number =>
|
|
1023
|
-
state.settings.aiRecentContentLimit ?? 50; // ADDED
|
|
1024
|
-
export const selectContextRetention = (state: RootState): number =>
|
|
1025
|
-
state.settings.contextRetention ?? 50;
|
|
1026
|
-
export const selectDefaultAgentPreference = (state: RootState): string =>
|
|
1027
|
-
resolveDefaultAgentIdSetting(state.settings.defaultAgentId);
|
|
1028
|
-
export const selectDefaultAgentId = (state: RootState): string =>
|
|
1029
|
-
selectResolvedDefaultAgentId(state.settings.defaultAgentId);
|
|
1030
|
-
|
|
1031
|
-
export const selectOcrModel = (
|
|
1032
|
-
state: RootState
|
|
1033
|
-
): "none" | "olm_ocr" =>
|
|
1034
|
-
state.settings.ocrModel === "none" ? "none" : "olm_ocr";
|
|
1035
|
-
|
|
1036
|
-
export const selectShowScrollToTopButton = (state: RootState): boolean =>
|
|
1037
|
-
state.settings.showScrollToTopButton ?? false;
|
|
1038
|
-
export const selectShowScrollToBottomButton = (state: RootState): boolean =>
|
|
1039
|
-
state.settings.showScrollToBottomButton ?? false;
|
|
1040
|
-
export const selectCreateMenuOpenCount = (state: RootState): number => {
|
|
1041
|
-
const value = Number(state.settings.createMenuOpenCount);
|
|
1042
|
-
return Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
|
|
1043
|
-
};
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
export const selectEditorDefaultMode = (
|
|
1047
|
-
state: RootState
|
|
1048
|
-
): "markdown" | "block" => state.settings.editorDefaultMode;
|
|
1049
|
-
export const selectEditorLightCodeTheme = (state: RootState): string =>
|
|
1050
|
-
state.settings.editorLightCodeTheme;
|
|
1051
|
-
export const selectEditorDarkCodeTheme = (state: RootState): string =>
|
|
1052
|
-
state.settings.editorDarkCodeTheme;
|
|
1053
|
-
export const selectEditorCodeTheme = createSelector(
|
|
1054
|
-
[selectEditorLightCodeTheme, selectEditorDarkCodeTheme, selectIsDark],
|
|
1055
|
-
(lightTheme, darkTheme, isDark) => (isDark ? darkTheme : lightTheme)
|
|
1056
|
-
);
|
|
1057
|
-
export const selectEditorWordCountEnabled = (state: RootState): boolean =>
|
|
1058
|
-
state.settings.editorWordCountEnabled;
|
|
1059
|
-
export const selectEditorShortcuts = (state: RootState) =>
|
|
1060
|
-
state.settings.editorShortcuts;
|
|
1061
|
-
export const selectEditorFontSize = (state: RootState): number =>
|
|
1062
|
-
state.settings.editorFontSize;
|
|
1063
|
-
export const selectEditorAutoSave = (state: RootState): boolean =>
|
|
1064
|
-
state.settings.editorAutoSave;
|
|
1065
|
-
export const selectEditorAutoSaveInterval = (state: RootState): number =>
|
|
1066
|
-
state.settings.editorAutoSaveInterval;
|
|
1067
|
-
|
|
1068
|
-
export const selectTheme = createSelector(
|
|
1069
|
-
[
|
|
1070
|
-
selectThemeName,
|
|
1071
|
-
selectIsDark,
|
|
1072
|
-
selectSidebarWidth,
|
|
1073
|
-
selectHeaderHeight,
|
|
1074
|
-
selectDensity,
|
|
1075
|
-
selectFontPreset,
|
|
1076
|
-
],
|
|
1077
|
-
(themeName, isDark, sidebarWidth, headerHeight, density, fontPreset) => {
|
|
1078
|
-
const mode = isDark ? "dark" : "light";
|
|
1079
|
-
const validThemeName = THEME_COLORS[themeName]
|
|
1080
|
-
? themeName
|
|
1081
|
-
: DEFAULT_THEME_NAME;
|
|
1082
|
-
const validFontPreset =
|
|
1083
|
-
normalizeFontPreset(fontPreset) ?? DEFAULT_FONT_PRESET;
|
|
1084
|
-
const baseColors = MODE_COLORS[mode];
|
|
1085
|
-
const themeColors = THEME_COLORS[validThemeName][mode];
|
|
1086
|
-
// 主题 surface 字段覆盖中性底色,实现完整主题体验
|
|
1087
|
-
const c = { ...baseColors, ...themeColors } as typeof baseColors & typeof themeColors & { textHeading?: string };
|
|
1088
|
-
const compact = density === "compact";
|
|
1089
|
-
return {
|
|
1090
|
-
sidebarWidth: `${sidebarWidth}px`,
|
|
1091
|
-
headerHeight: `${headerHeight}px`,
|
|
1092
|
-
sidebarItemHeight: compact ? "36px" : "40px",
|
|
1093
|
-
sidebarIconSize: compact ? "18px" : "20px",
|
|
1094
|
-
sidebarItemGap: compact ? "2px" : "4px",
|
|
1095
|
-
// Density-aware spacing scale (4px grid → 5px grid)
|
|
1096
|
-
space: compact
|
|
1097
|
-
? SPACE
|
|
1098
|
-
: {
|
|
1099
|
-
0: "0", 1: "5px", 2: "10px", 3: "14px", 4: "20px", 5: "24px",
|
|
1100
|
-
6: "30px", 7: "34px", 8: "40px", 10: "50px", 12: "60px",
|
|
1101
|
-
14: "70px", 16: "80px", 20: "100px", 24: "120px",
|
|
1102
|
-
},
|
|
1103
|
-
// Semantic typography scale
|
|
1104
|
-
fontSize: {
|
|
1105
|
-
xs: compact ? "11px" : "12px",
|
|
1106
|
-
sm: compact ? "12px" : "13px",
|
|
1107
|
-
base: compact ? "14px" : "15px",
|
|
1108
|
-
md: compact ? "14px" : "15.5px",
|
|
1109
|
-
lg: compact ? "16px" : "17.5px",
|
|
1110
|
-
xl: compact ? "20px" : "22px",
|
|
1111
|
-
"2xl": compact ? "24px" : "26px",
|
|
1112
|
-
},
|
|
1113
|
-
// Semantic line-height scale
|
|
1114
|
-
leading: {
|
|
1115
|
-
tight: compact ? "1.3" : "1.4",
|
|
1116
|
-
normal: compact ? "1.45" : "1.6",
|
|
1117
|
-
relaxed: compact ? "1.6" : "1.75",
|
|
1118
|
-
},
|
|
1119
|
-
// Component height scale (buttons, inputs, list items)
|
|
1120
|
-
control: {
|
|
1121
|
-
xs: compact ? "24px" : "28px",
|
|
1122
|
-
sm: compact ? "28px" : "32px",
|
|
1123
|
-
md: compact ? "36px" : "40px",
|
|
1124
|
-
lg: compact ? "40px" : "46px",
|
|
1125
|
-
xl: compact ? "48px" : "56px",
|
|
1126
|
-
},
|
|
1127
|
-
// Border radius scale
|
|
1128
|
-
radius: {
|
|
1129
|
-
sm: compact ? "4px" : "6px",
|
|
1130
|
-
md: compact ? "8px" : "10px",
|
|
1131
|
-
lg: compact ? "12px" : "14px",
|
|
1132
|
-
xl: compact ? "16px" : "20px",
|
|
1133
|
-
},
|
|
1134
|
-
font: FONT_PRESET_CSS_VARIABLES[validFontPreset],
|
|
1135
|
-
...c,
|
|
1136
|
-
borderSubtle: c.borderLight,
|
|
1137
|
-
borderFaint: alphaColor(c.border, isDark ? 0.22 : 0.35, c.borderLight),
|
|
1138
|
-
borderStrong: c.borderHover,
|
|
1139
|
-
surface: c.backgroundSecondary,
|
|
1140
|
-
surfaceElevated: c.backgroundTertiary,
|
|
1141
|
-
surfaceCanvas: c.background,
|
|
1142
|
-
surfaceSidebar: isDark ? c.backgroundSecondary : c.background,
|
|
1143
|
-
surfacePanel: c.backgroundSecondary,
|
|
1144
|
-
surfaceCard: c.messageBackground,
|
|
1145
|
-
surfaceRaised: isDark ? c.backgroundTertiary : c.backgroundSecondary,
|
|
1146
|
-
surfaceInset: isDark ? c.backgroundSecondary : alphaColor(c.borderHover, 0.05, c.codeBackground),
|
|
1147
|
-
surfaceCode: c.codeBackground,
|
|
1148
|
-
surfaceInteractive: c.backgroundTertiary,
|
|
1149
|
-
surfaceInteractiveHover: c.backgroundHover,
|
|
1150
|
-
textMuted: c.textSecondary,
|
|
1151
|
-
textSubtle: c.textTertiary,
|
|
1152
|
-
textHeading: c.textHeading ?? c.text,
|
|
1153
|
-
borderMuted: alphaColor(c.borderHover, isDark ? 0.3 : 0.24, c.borderLight),
|
|
1154
|
-
accentSoft: alphaColor(c.primary, isDark ? 0.18 : 0.1, c.primaryGhost),
|
|
1155
|
-
shadow: c.shadowMedium,
|
|
1156
|
-
shadow1: `0 1px 2px ${c.shadowLight}`,
|
|
1157
|
-
shadow2: `0 8px 24px -12px ${c.shadowMedium}`,
|
|
1158
|
-
shadow3: `0 18px 44px -24px ${c.shadowHeavy}`,
|
|
1159
|
-
primaryBorder: c.borderAccent ?? c.primary,
|
|
1160
|
-
primaryBgStrong: alphaColor(c.primary, isDark ? 0.18 : 0.1, c.primaryGhost),
|
|
1161
|
-
success: c.success,
|
|
1162
|
-
warning: c.warning,
|
|
1163
|
-
info: c.info,
|
|
1164
|
-
successGhost: alphaColor(c.success, isDark ? 0.2 : 0.12, "rgba(16, 185, 129, 0.12)"),
|
|
1165
|
-
warningGhost: alphaColor(c.warning, isDark ? 0.2 : 0.12, "rgba(245, 158, 11, 0.12)"),
|
|
1166
|
-
infoGhost: alphaColor(c.info, isDark ? 0.2 : 0.12, "rgba(59, 130, 246, 0.12)"),
|
|
1167
|
-
errorGhost: alphaColor(c.error, isDark ? 0.2 : 0.12, "rgba(239, 68, 68, 0.12)"),
|
|
1168
|
-
primaryRgb: hexToRgbString(c.primary) ?? "59, 130, 246",
|
|
1169
|
-
focusRing: alphaColor(c.primary, isDark ? 0.3 : 0.22, c.primaryGhost),
|
|
1170
|
-
};
|
|
1171
|
-
}
|
|
1172
|
-
);
|
|
1173
|
-
|
|
1174
|
-
export const selectEditorConfig = createSelector(
|
|
1175
|
-
[
|
|
1176
|
-
selectEditorDefaultMode,
|
|
1177
|
-
selectEditorLightCodeTheme,
|
|
1178
|
-
selectEditorDarkCodeTheme,
|
|
1179
|
-
selectEditorWordCountEnabled,
|
|
1180
|
-
selectEditorShortcuts,
|
|
1181
|
-
selectEditorFontSize,
|
|
1182
|
-
selectEditorAutoSave,
|
|
1183
|
-
selectEditorAutoSaveInterval,
|
|
1184
|
-
selectIsDark,
|
|
1185
|
-
],
|
|
1186
|
-
(
|
|
1187
|
-
defaultMode,
|
|
1188
|
-
lightCodeTheme,
|
|
1189
|
-
darkCodeTheme,
|
|
1190
|
-
wordCountEnabled,
|
|
1191
|
-
shortcuts,
|
|
1192
|
-
fontSize,
|
|
1193
|
-
autoSave,
|
|
1194
|
-
autoSaveInterval,
|
|
1195
|
-
isDark
|
|
1196
|
-
) => {
|
|
1197
|
-
const codeTheme = isDark ? darkCodeTheme : lightCodeTheme;
|
|
1198
|
-
return {
|
|
1199
|
-
defaultMode,
|
|
1200
|
-
codeTheme,
|
|
1201
|
-
lightCodeTheme,
|
|
1202
|
-
darkCodeTheme,
|
|
1203
|
-
wordCountEnabled,
|
|
1204
|
-
shortcuts,
|
|
1205
|
-
fontSize,
|
|
1206
|
-
autoSave,
|
|
1207
|
-
autoSaveInterval,
|
|
1208
|
-
};
|
|
1209
|
-
}
|
|
1210
|
-
);
|
|
1211
|
-
|
|
1212
|
-
export default settingSlice.reducer;
|