nolo-cli 0.1.39 → 0.1.41
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 +4 -4
- package/agent-runtime/dialogWritePlan.ts +39 -0
- package/agent-runtime/hostAdapter.ts +4 -0
- package/agent-runtime/hybridRecordStore.ts +5 -3
- package/agent-runtime/index.ts +15 -0
- package/agent-runtime/localLoop.ts +87 -7
- package/agent-runtime/localToolPolicy.ts +2 -13
- package/agent-runtime/localWorkspaceTools.ts +42 -110
- package/agent-runtime/runtimeToolPolicy.ts +2 -11
- package/agent-runtime/runtimeToolSurface.ts +198 -0
- package/agent-runtime/types.ts +1 -0
- package/agentAliases.ts +2 -1
- package/agentRunCommand.ts +10 -32
- package/agentRuntimeLocal.ts +1 -0
- package/ai/agent/_executeModel.ts +146 -0
- package/ai/agent/agentSlice.ts +556 -1
- package/ai/agent/appWorkingMemory.ts +126 -0
- package/ai/agent/buildEditingContext.ts +378 -0
- package/ai/agent/buildSystemPrompt.ts +585 -0
- package/ai/agent/canvasEditingContext.ts +49 -0
- package/ai/agent/cleanAgentMessages.ts +140 -0
- package/ai/agent/cliChatClient.ts +153 -0
- package/ai/agent/cliExecutor.ts +314 -40
- package/ai/agent/contextCompiler.ts +107 -0
- package/ai/agent/contextLayerContract.ts +44 -0
- package/ai/agent/createAgentSchema.ts +272 -0
- package/ai/agent/currentTimeContext.ts +65 -0
- package/ai/agent/executeToolCall.ts +58 -0
- package/ai/agent/fetchAgentContexts.ts +42 -0
- package/ai/agent/generatePrompt.ts +3 -0
- package/ai/agent/getFullChatContextKeys.ts +168 -0
- package/ai/agent/guidedCreation/capabilities.ts +84 -0
- package/ai/agent/guidedCreation/types.ts +38 -0
- package/ai/agent/isLiveAudioOnlyAgent.ts +26 -0
- package/ai/agent/liveAudioModel.ts +2 -0
- package/ai/agent/pageBuilderHandoffRules.ts +75 -0
- package/ai/agent/persistMessageWithFixedId.ts +37 -0
- package/ai/agent/planSlice.ts +259 -0
- package/ai/agent/referenceUtils.ts +229 -0
- package/ai/agent/runAgentBackground.ts +310 -0
- package/ai/agent/runAgentClientLoop.ts +164 -0
- package/ai/agent/runtimeGuidance.ts +116 -0
- package/ai/agent/serverOrigin.ts +7 -0
- package/ai/agent/startParallelAgentStreams.ts +424 -0
- package/ai/agent/startupProtocol.ts +53 -0
- package/ai/agent/streamAgentChatTurn.ts +2001 -0
- package/ai/agent/streamAgentChatTurnUtils.ts +860 -0
- package/ai/agent/toolFailureGuard.ts +99 -0
- package/ai/agent/types.ts +73 -0
- package/ai/agent/utils/imageOutput.ts +37 -0
- package/ai/agent/utils/publicImageAgentMode.ts +26 -0
- package/ai/ai.locale.ts +1095 -0
- package/ai/chat/accumulateToolCallChunks.ts +126 -0
- package/ai/chat/fetchUtils.ts +143 -0
- package/ai/chat/inlineImageUrlsForCustomProvider.ts +117 -0
- package/ai/chat/parseApiError.ts +67 -0
- package/ai/chat/parseMultilineSSE.ts +95 -0
- package/ai/chat/sendOpenAICompletionsRequest.ts +897 -0
- package/ai/chat/sendOpenAIResponseRequest.ts +720 -0
- package/ai/chat/serverProxyRetry.ts +102 -0
- package/ai/chat/shouldUseServerProxy.ts +18 -0
- package/ai/chat/streamRetry.ts +46 -0
- package/ai/chat/updateTotalUsage.ts +89 -0
- package/ai/context/buildReferenceContext.ts +437 -0
- package/ai/context/retention.ts +165 -0
- package/ai/context/tokenUtils.ts +78 -0
- package/ai/llm/agentCapabilities.ts +74 -0
- package/ai/llm/deepinfra.ts +79 -0
- package/ai/llm/fireworks.ts +68 -0
- package/ai/llm/generateRequestBody.ts +165 -0
- package/ai/llm/getModelContextWindow.ts +93 -0
- package/ai/llm/getPricing.ts +252 -0
- package/ai/llm/imagePricing.ts +66 -0
- package/ai/llm/isResponseAPIModel.ts +13 -0
- package/ai/llm/kimi.ts +23 -0
- package/ai/llm/mimo.ts +99 -0
- package/ai/llm/mistral.ts +21 -0
- package/ai/llm/models.ts +45 -0
- package/ai/llm/openrouterModels.ts +6 -0
- package/ai/llm/providers.ts +313 -0
- package/ai/llm/reasoningModels.ts +27 -0
- package/ai/llm/types.ts +82 -0
- package/ai/llm/usageRequestOptions.ts +59 -0
- package/ai/memory/queryShared.ts +161 -0
- package/ai/memory/recentRelationshipRecap.ts +247 -0
- package/ai/memory/remember.ts +167 -0
- package/ai/memory/store.ts +20 -0
- package/ai/memory/storeShared.ts +76 -0
- package/ai/memory/types.ts +46 -0
- package/ai/memory/understanding.ts +349 -0
- package/ai/memory/understandingGreeting.ts +264 -0
- package/ai/policy/personalizationDialog.ts +333 -0
- package/ai/policy/runtimePolicy.ts +454 -0
- package/ai/policy/selfUpdateFields.ts +48 -0
- package/ai/policy/types.ts +64 -0
- package/ai/skills/referenceRuntime.ts +274 -0
- package/ai/skills/skillDiagnostics.ts +251 -0
- package/ai/skills/skillDocBuilder.ts +139 -0
- package/ai/skills/skillSummaryMarker.ts +26 -0
- package/ai/token/calculatePrice.ts +576 -0
- package/ai/token/missingUsageEstimate.ts +42 -0
- package/ai/token/normalizeUsage.ts +124 -0
- package/ai/token/openaiImageGenerationUsage.ts +56 -0
- package/ai/token/prepareTokenUsageData.ts +93 -0
- package/ai/token/resolveBillingTarget.ts +52 -0
- package/ai/token/saveTokenRecord.ts +53 -0
- package/ai/token/types.ts +103 -0
- package/ai/tools/agent/agentTools.ts +235 -0
- package/ai/tools/agent/agentUpdateShared.ts +311 -0
- package/ai/tools/agent/callAgentTool.ts +139 -0
- package/ai/tools/agent/createAgentTool.ts +512 -0
- package/ai/tools/agent/createDialogTool.ts +69 -0
- package/ai/tools/agent/createSkillAgentTool.ts +62 -0
- package/ai/tools/agent/parallelBudget.ts +221 -0
- package/ai/tools/agent/prepareAgentDraftTool.ts +159 -0
- package/ai/tools/agent/presets/appBuilderPreset.ts +154 -0
- package/ai/tools/agent/runLlmTool.ts +96 -0
- package/ai/tools/agent/runStreamingAgentTool.ts +73 -0
- package/ai/tools/agent/skillAgentArgs.ts +106 -0
- package/ai/tools/agent/startAgentDialogTool.ts +53 -0
- package/ai/tools/agent/streamParallelAgentsTool.ts +123 -0
- package/ai/tools/agent/updateAgentTool.ts +96 -0
- package/ai/tools/agent/updateSelfTool.ts +113 -0
- package/ai/tools/amazonProductScraperTool.ts +86 -0
- package/ai/tools/apifyActorClient.ts +45 -0
- package/ai/tools/appEditGuard.ts +372 -0
- package/ai/tools/appReadSnapshot.ts +153 -0
- package/ai/tools/appTools.ts +1549 -0
- package/ai/tools/applyEditTool.ts +259 -0
- package/ai/tools/applyLineEditsTool.ts +315 -0
- package/ai/tools/browserTools/click.ts +33 -0
- package/ai/tools/browserTools/closeSession.ts +29 -0
- package/ai/tools/browserTools/common.ts +27 -0
- package/ai/tools/browserTools/openSession.ts +48 -0
- package/ai/tools/browserTools/readContent.ts +38 -0
- package/ai/tools/browserTools/selectOption.ts +46 -0
- package/ai/tools/browserTools/typeText.ts +42 -0
- package/ai/tools/category/createCategoryTool.ts +66 -0
- package/ai/tools/category/queryContentsByCategoryTool.ts +69 -0
- package/ai/tools/category/updateContentCategoryTool.ts +75 -0
- package/ai/tools/cfBrowserTools.ts +319 -0
- package/ai/tools/cfSpeechToTextTool.ts +49 -0
- package/ai/tools/checkEnvTool.ts +102 -0
- package/ai/tools/cloudflareCrawlTool.ts +289 -0
- package/ai/tools/codeSearchTool.ts +123 -0
- package/ai/tools/codeTools.ts +101 -0
- package/ai/tools/convertMarxistsBookTool.ts +103 -0
- package/ai/tools/createDocTool.ts +132 -0
- package/ai/tools/createSkillDocTool.ts +155 -0
- package/ai/tools/createWorkflowTool.ts +154 -0
- package/ai/tools/delayTool.ts +31 -0
- package/ai/tools/deleteSpacesTool.ts +325 -0
- package/ai/tools/deleteSpacesToolModel.ts +159 -0
- package/ai/tools/devReloadUtils.ts +29 -0
- package/ai/tools/dialogMessageSearch.ts +137 -0
- package/ai/tools/doctorSkillTool.ts +72 -0
- package/ai/tools/ecommerceScraperTool.ts +86 -0
- package/ai/tools/emailTools.ts +549 -0
- package/ai/tools/evalSkillTool.ts +92 -0
- package/ai/tools/exaSearchTool.ts +63 -0
- package/ai/tools/execShellTool.ts +266 -0
- package/ai/tools/executeSqlTool.ts +192 -0
- package/ai/tools/fetchWebpageSupport.ts +333 -0
- package/ai/tools/fetchWebpageTool.ts +97 -0
- package/ai/tools/geminiImagePreviewTool.ts +386 -0
- package/ai/tools/generateDocxTool.ts +215 -0
- package/ai/tools/googleSearchScraperTool.ts +106 -0
- package/ai/tools/importDataTool.ts +133 -0
- package/ai/tools/importSkillTool.ts +162 -0
- package/ai/tools/index.ts +2308 -0
- package/ai/tools/jdProductScraperTool.ts +821 -0
- package/ai/tools/listUserSpacesTool.ts +113 -0
- package/ai/tools/localFilesTool.ts +276 -0
- package/ai/tools/marxistsOfflineBook.ts +253 -0
- package/ai/tools/modelUsageTools.ts +206 -0
- package/ai/tools/noloWorkspaceReadTools.ts +467 -0
- package/ai/tools/olmOcrTool.ts +33 -0
- package/ai/tools/openaiImageTool.ts +267 -0
- package/ai/tools/prepareTools.ts +23 -0
- package/ai/tools/readDocTool.ts +88 -0
- package/ai/tools/readFileTool.ts +214 -0
- package/ai/tools/readTool.ts +194 -0
- package/ai/tools/readXPostTool.ts +229 -0
- package/ai/tools/readXhsProfileTool.ts +627 -0
- package/ai/tools/rememberMemoryTool.ts +84 -0
- package/ai/tools/remotionVideoTool.ts +151 -0
- package/ai/tools/searchDialogMessagesTool.ts +222 -0
- package/ai/tools/searchWorkspaceTool.ts +259 -0
- package/ai/tools/skillFollowup.ts +86 -0
- package/ai/tools/surfWeatherTool.ts +169 -0
- package/ai/tools/table/addTableRowTool.ts +217 -0
- package/ai/tools/table/createTableTool.ts +315 -0
- package/ai/tools/table/rowTools.ts +386 -0
- package/ai/tools/table/schemaTools.ts +244 -0
- package/ai/tools/table/shareTableTool.ts +148 -0
- package/ai/tools/table/toolShared.ts +129 -0
- package/ai/tools/taobaoTmallProductScraperTool.ts +49 -0
- package/ai/tools/toolApiClient.ts +279 -0
- package/ai/tools/toolResultError.ts +42 -0
- package/ai/tools/toolRunSlice.ts +303 -0
- package/ai/tools/toolSchemaCompatibility.ts +53 -0
- package/ai/tools/uiAskChoiceTool.ts +104 -0
- package/ai/tools/updateContentTitleTool.ts +84 -0
- package/ai/tools/updateDocTool.ts +105 -0
- package/ai/tools/updateUserPreferenceProfileTool.ts +153 -0
- package/ai/tools/wereadGatewayTool.ts +152 -0
- package/ai/tools/whisperTool.ts +76 -0
- package/ai/tools/writeFileTool.ts +213 -0
- package/ai/tools/youtubeScraperTool.ts +116 -0
- package/ai/tools/ziweiChartTool.ts +678 -0
- package/ai/types.ts +55 -0
- package/ai/workflow/workflowExecutor.ts +323 -0
- package/ai/workflow/workflowSlice.ts +73 -0
- package/ai/workflow/workflowTypes.ts +106 -0
- package/app/actions/syncAppRecord.ts +73 -0
- package/app/constants/animationSets.ts +21 -0
- package/app/constants/appEditor.ts +99 -0
- package/app/favorite/favoriteSlice.ts +690 -0
- package/app/favorite/type.ts +43 -0
- package/app/hooks/deleteDbKey.ts +233 -0
- package/app/i18n/client.ts +13 -0
- package/app/i18n/i18n.base.ts +14 -0
- package/app/i18n/i18n.config.ts +77 -0
- package/app/i18n/index.ts +15 -0
- package/app/i18n/mapLanguage.ts +11 -0
- package/app/i18n/translations/appBuilder.locale.ts +453 -0
- package/app/i18n/translations/error.locale.ts +246 -0
- package/app/i18n/translations/interface.locale.ts +2174 -0
- package/app/i18n/translations/pricing.locale.ts +397 -0
- package/app/i18n/translations/privacy.locale.ts +168 -0
- package/app/i18n/translations/seo.locale.ts +129 -0
- package/app/i18n/translations/terms.locale.ts +124 -0
- package/app/i18n/types.ts +6 -0
- package/app/notifications/model.ts +77 -0
- package/app/notifications/notificationSlice.ts +141 -0
- package/app/reducer.ts +36 -0
- package/app/settings/dbActionThunks.ts +34 -0
- package/app/settings/defaultSpacePreference.ts +87 -0
- package/app/settings/settingSlice.tsx +1212 -0
- package/app/settings/settingsRecord.ts +8 -0
- package/app/stateViews/runtime.ts +90 -0
- package/app/store.ts +55 -0
- package/app/theme/colors.ts +280 -0
- package/app/theme/fontPreference.ts +77 -0
- package/app/theme/theme.config.ts +120 -0
- package/app/theme/themeModeBootstrap.ts +123 -0
- package/app/types/appSummary.ts +114 -0
- package/app/types.ts +358 -0
- package/app/utils/appKeys.ts +55 -0
- package/app/utils/async.ts +28 -0
- package/app/utils/desktopAgentRuntimeTurnClient.ts +73 -0
- package/app/utils/env.ts +17 -0
- package/app/utils/fileUtils.ts +229 -0
- package/app/utils/imageUtils.ts +274 -0
- package/app/utils/myContentItems.ts +289 -0
- package/app/utils/retryAfter.ts +36 -0
- package/app/utils/retryFetch.ts +61 -0
- package/app/utils/toast.ts +3 -0
- package/auth/action/signUpAction.ts +227 -0
- package/auth/adminPermissions.ts +18 -0
- package/auth/authSlice.ts +531 -0
- package/auth/client/loginRequest.ts +14 -0
- package/auth/resetAuthScopedClientState.ts +27 -0
- package/auth/routes.ts +178 -0
- package/auth/token.ts +63 -0
- package/auth/types.ts +40 -0
- package/chat/chat.locale.ts +813 -0
- package/chat/dialog/actions/addCybotAction.ts +52 -0
- package/chat/dialog/actions/addReferenceKeysAction.ts +62 -0
- package/chat/dialog/actions/builtinDialogLlm.ts +35 -0
- package/chat/dialog/actions/cleanupCliSession.ts +40 -0
- package/chat/dialog/actions/createDialogAction.ts +379 -0
- package/chat/dialog/actions/createScheduledTaskAction.ts +78 -0
- package/chat/dialog/actions/handleSendMessageAction.ts +197 -0
- package/chat/dialog/actions/handleSendMessageResolver.ts +27 -0
- package/chat/dialog/actions/removeCybotAction.ts +6 -0
- package/chat/dialog/actions/removeDialogAgentAction.ts +44 -0
- package/chat/dialog/actions/replacePrimaryCybotAction.ts +6 -0
- package/chat/dialog/actions/setPrimaryDialogAgentAction.ts +52 -0
- package/chat/dialog/actions/updateDialogSummaryAction.ts +430 -0
- package/chat/dialog/actions/updateDialogTitleAction.ts +151 -0
- package/chat/dialog/actions/updateDialogTitlePolicy.ts +30 -0
- package/chat/dialog/actions/updateTokensAction.ts +233 -0
- package/chat/dialog/dialogAgents.ts +72 -0
- package/chat/dialog/dialogSlice.ts +872 -0
- package/chat/dialog/dialogTitle.ts +81 -0
- package/chat/dialog/dialogTokenStats.ts +12 -0
- package/chat/dialog/dialogUrl.ts +6 -0
- package/chat/dialog/goal.ts +108 -0
- package/chat/dialog/objectAssistantRegistry.ts +286 -0
- package/chat/dialog/schedule.ts +17 -0
- package/chat/messages/fetchAndCacheMessages.ts +119 -0
- package/chat/messages/fetchConvMsgs.ts +51 -0
- package/chat/messages/fileUrl.ts +13 -0
- package/chat/messages/messageAgent.ts +8 -0
- package/chat/messages/messageContent.ts +199 -0
- package/chat/messages/messageContract.ts +88 -0
- package/chat/messages/messageSlice.ts +1367 -0
- package/chat/messages/toolThunks.ts +625 -0
- package/cli/agentAliases.ts +2 -1
- package/cli/agentRunCommand.ts +10 -32
- package/cli/agentRuntimeLocal.ts +1 -0
- package/cli/client/agentRun.ts +67 -95
- package/cli/client/localRuntimeAdapter.ts +323 -54
- package/cli/commandRegistry.ts +2 -2
- package/cli/machineWsRunDispatch.ts +51 -6
- package/cli/offlineMarxistsAgentCommand.ts +6 -4
- package/client/agentConfigResolver.test.ts +2 -2
- package/client/agentRun.test.ts +175 -57
- package/client/agentRun.ts +67 -95
- package/client/localRuntimeAdapter.test.ts +682 -37
- package/client/localRuntimeAdapter.ts +323 -54
- package/client/localRuntimeDryRun.test.ts +23 -9
- package/client/localToolPolicy.test.ts +4 -4
- package/commandRegistry.ts +2 -2
- package/core/builtinAgents.ts +209 -0
- package/core/config.ts +15 -0
- package/core/crypto.ts +51 -0
- package/core/generateKeyPairFromSeedV1.ts +15 -0
- package/core/generateMainKey.ts +22 -0
- package/core/init.ts +41 -0
- package/core/localOrigins.ts +8 -0
- package/core/password.ts +13 -0
- package/core/prefix.ts +23 -0
- package/create/editor/transforms/fromMarkdown/index.ts +260 -0
- package/create/editor/transforms/fromMarkdown/inline.ts +285 -0
- package/create/editor/transforms/fromMarkdown/table.ts +130 -0
- package/create/editor/transforms/markdownToSlate.ts +24 -0
- package/create/editor/transforms/slateToRenderMarkdown.ts +218 -0
- package/create/editor/transforms/slateToSimplifiedMarkdown.ts +224 -0
- package/create/editor/transforms/slateToText.ts +33 -0
- package/create/editor/utils/slateUtils.ts +233 -0
- package/create/space/addSpaceAction.ts +193 -0
- package/create/space/category/categoryActions.ts +427 -0
- package/create/space/changeSpaceAction.ts +36 -0
- package/create/space/constants.ts +8 -0
- package/create/space/content/addContentAction.ts +116 -0
- package/create/space/content/contentThunks.ts +90 -0
- package/create/space/content/deleteContentFromSpaceAction.ts +187 -0
- package/create/space/content/deleteMultipleContentAction.ts +112 -0
- package/create/space/content/moveContentAction.ts +285 -0
- package/create/space/content/updateContentCategoryAction.ts +154 -0
- package/create/space/content/updateContentTitleAction.ts +151 -0
- package/create/space/content/uploadAndAddFileToSpaceAction.ts +98 -0
- package/create/space/contentKeyUtils.ts +117 -0
- package/create/space/deleteSpaceAction.ts +276 -0
- package/create/space/fetchSpaceAction.ts +70 -0
- package/create/space/fetchSpaceSidebarStateAction.ts +26 -0
- package/create/space/loadDefaultSpaceAction.ts +57 -0
- package/create/space/member/addMemberAction.ts +79 -0
- package/create/space/member/fetchUserSpaceMembershipsAction.ts +386 -0
- package/create/space/member/memberThunks.ts +47 -0
- package/create/space/member/removeMemberAction.ts +67 -0
- package/create/space/resolvePreferredSpaceId.ts +113 -0
- package/create/space/sidebarVisibleTypes.ts +241 -0
- package/create/space/space.locale.ts +1087 -0
- package/create/space/spaceAccess.ts +182 -0
- package/create/space/spaceCollapsedState.ts +54 -0
- package/create/space/spaceKeys.ts +65 -0
- package/create/space/spaceSlice.ts +328 -0
- package/create/space/spaceThunks.ts +410 -0
- package/create/space/types.ts +27 -0
- package/create/space/updateSpaceAction.ts +107 -0
- package/create/space/utils/permissions.ts +47 -0
- package/create/types.ts +21 -0
- package/database/actions/agentReadResolution.ts +33 -0
- package/database/actions/common.ts +243 -0
- package/database/actions/deleteFile.ts +40 -0
- package/database/actions/fileContent.ts +125 -0
- package/database/actions/patch.ts +155 -0
- package/database/actions/read.ts +358 -0
- package/database/actions/readAndWait.ts +260 -0
- package/database/actions/readRequestManager.ts +120 -0
- package/database/actions/readResolution.ts +125 -0
- package/database/actions/remove.ts +94 -0
- package/database/actions/replication.ts +477 -0
- package/database/actions/upload.ts +186 -0
- package/database/actions/upsert.ts +56 -0
- package/database/actions/write.ts +146 -0
- package/database/authority/ownerKey.ts +80 -0
- package/database/authority/recordAuthority.ts +67 -0
- package/database/authority/userAuthorityRegistry.ts +54 -0
- package/database/client/fetchUserData.ts +61 -0
- package/database/dbActionThunks.ts +1 -0
- package/database/dbSlice.ts +149 -0
- package/database/fileRing.ts +51 -0
- package/database/fileStorage.ts +232 -0
- package/database/fileUrl.ts +34 -0
- package/database/keys.ts +767 -0
- package/database/queryPrefixes.ts +14 -0
- package/database/requests.ts +443 -0
- package/database/runtimeServerContext.ts +54 -0
- package/database/server/levelAuthorityStore.ts +20 -1
- package/database/tenantPlacement.ts +57 -0
- package/database/userPreferenceRegister.ts +131 -0
- package/database/utils/ulid.ts +1 -0
- package/integrations/anthropic/anthropicModels.ts +47 -0
- package/integrations/deepseek/models.ts +37 -0
- package/integrations/google/models.ts +341 -0
- package/integrations/openai/chatCompletionStreamMode.ts +10 -0
- package/integrations/openai/filterAndCleanMessages.ts +284 -0
- package/integrations/openai/flexTier.ts +102 -0
- package/integrations/openai/generateOpenAIRequestBody.ts +274 -0
- package/integrations/openai/generateResponseRequestBody.ts +77 -0
- package/integrations/openai/models.ts +271 -0
- package/integrations/openai/providerBodyCompatibility.ts +23 -0
- package/integrations/openai/responsesHelpers.ts +297 -0
- package/integrations/x-reader/types.ts +109 -0
- package/integrations/xai/models.ts +13 -0
- package/integrations/xhs-reader/analyze/profileAnalyzer.ts +205 -0
- package/integrations/xhs-reader/backends/playwrightProfileCollector.ts +624 -0
- package/integrations/xhs-reader/bridge/readXhsProfileWithBridge.ts +227 -0
- package/integrations/xhs-reader/client/xhsWebApiClient.ts +229 -0
- package/integrations/xhs-reader/normalize.ts +390 -0
- package/integrations/xhs-reader/orchestrator.ts +178 -0
- package/integrations/xhs-reader/redaction.ts +68 -0
- package/integrations/xhs-reader/types.ts +244 -0
- package/integrations/xhs-reader/url.ts +57 -0
- package/machineWsRunDispatch.ts +51 -6
- package/offlineMarxistsAgentCommand.ts +6 -4
- package/package.json +430 -3
- package/render/page/createPageAction.ts +183 -0
- package/render/page/docSlice.ts +468 -0
- package/render/page/types.ts +17 -0
- package/render/table/createTableAction.ts +270 -0
- package/render/table/deleteTableAction.ts +193 -0
- package/render/table/fetchAndCacheTableRows.ts +174 -0
- package/render/table/tableSlice.ts +1106 -0
- package/render/table/toolValueUtils.ts +363 -0
- package/render/table/types.ts +252 -0
- package/render/table/utils/tableSerialization.ts +50 -0
- package/server/handlers/agentRun/types.ts +104 -0
- package/share/action.ts +225 -0
- package/share/helpers.ts +302 -0
- package/share/keys.ts +243 -0
- package/share/publicSharePolicy.ts +27 -0
- package/share/shareSlice.ts +53 -0
- package/share/types.ts +100 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// 文件: ai/tools/uiAskChoiceTool.ts
|
|
2
|
+
|
|
3
|
+
export const uiAskChoiceFunctionSchema = {
|
|
4
|
+
name: "ui_ask_choice",
|
|
5
|
+
description: [
|
|
6
|
+
"当你需要让用户在几个互斥的选项之间做选择时,使用本工具。",
|
|
7
|
+
"",
|
|
8
|
+
"这是一个通用的“出选项”工具,适用于多种场景,例如:",
|
|
9
|
+
"1)用户的需求比较宽泛或模糊,你可以给出 2~5 个不同方向的候选方案,让 TA 先选一个方向;",
|
|
10
|
+
"2)一个计划 / 流程到了分支节点,需要用户决定下一步做什么;",
|
|
11
|
+
"3)你想为用户设计一组练习题、测试题或问卷题(如出题练习、人格测试等单选题);",
|
|
12
|
+
"4)在新阶段/新会话中,根据系统提示或用户画像,给出若干“接下来可以尝试的事情”(例如功能导航或使用技巧)。",
|
|
13
|
+
"",
|
|
14
|
+
"使用建议:",
|
|
15
|
+
"- 当你判断“先给出 2~5 个明确选项能显著帮用户理清下一步要做什么”时,可以主动调用本工具;",
|
|
16
|
+
"- 如果用户的目标已经非常具体、清晰,并且你可以直接给出高质量答案,优先直接回答,而不是再弹出选择菜单;",
|
|
17
|
+
"- 默认情况下,不要在完全没有有效上下文的场景(例如用户只说“你好”)立刻调用本工具,除非系统提示中已经明确要求你在新会话开头用它来生成欢迎菜单或功能导航;",
|
|
18
|
+
"- 请把给用户看的问题写在 question 字段中,不要在同一轮 assistant 普通文本里重复这句话;",
|
|
19
|
+
"- 每个选项的 userMessage 建议写成完整的一句话,方便后续理解上下文;如果留空,将自动使用 label 作为 userMessage。",
|
|
20
|
+
"",
|
|
21
|
+
"在代码协作场景下的推荐用法:",
|
|
22
|
+
"- 如果你已经在本轮 assistant 的 content 中给出了分析、说明或多个备选方案,可以在同一轮消息的结尾调用本工具,请用户选择“是否根据上述方案开始实际修改代码”或“优先执行哪一个方案/步骤”。",
|
|
23
|
+
"- 在这种情况下,question 字段通常是一个简短的问题(例如:“接下来你希望我按哪个方案来具体修改代码?”),而详细的解释和方案描述放在 content 中。",
|
|
24
|
+
"- 如果当前对话只需要一个简单的选择,而不需要额外解释,你也可以不输出额外的 content,而只调用本工具,由 question 字段直接向用户提问。"
|
|
25
|
+
].join("\n"),
|
|
26
|
+
parameters: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
question: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description:
|
|
32
|
+
"展示给用户的问题文案,用一句话说明要做什么选择。例如:“接下来你更希望我帮你做哪件事?”。不要在同一轮 assistant 普通文本里重复这句话。"
|
|
33
|
+
},
|
|
34
|
+
choices: {
|
|
35
|
+
type: "array",
|
|
36
|
+
description:
|
|
37
|
+
"备选项列表。每个选项会渲染成一个按钮,供用户点击选择。",
|
|
38
|
+
items: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
id: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description:
|
|
44
|
+
"选项内部标识(用于后续逻辑或调试,不会直接展示给用户)。"
|
|
45
|
+
},
|
|
46
|
+
label: {
|
|
47
|
+
type: "string",
|
|
48
|
+
description:
|
|
49
|
+
"显示给用户看的按钮文字。例如:“生成本周周报”。"
|
|
50
|
+
},
|
|
51
|
+
userMessage: {
|
|
52
|
+
type: "string",
|
|
53
|
+
description: [
|
|
54
|
+
"用户点击此选项后,你希望作为下一条 user 消息发送给模型的自然语言内容。",
|
|
55
|
+
"建议写成完整的一句话,例如:“帮我生成一份本周的工作周报”。",
|
|
56
|
+
"如果留空,将使用 label 作为 userMessage。"
|
|
57
|
+
].join(" ")
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
required: ["id", "label"]
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
blocking: {
|
|
64
|
+
type: "boolean",
|
|
65
|
+
description: [
|
|
66
|
+
"是否需要等待用户选择之后,再继续当前流程(例如 Plan)。",
|
|
67
|
+
"默认 true:即发出问题后,等待用户点击某个选项再继续。"
|
|
68
|
+
].join(" "),
|
|
69
|
+
default: true
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
required: ["question", "choices"]
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
export async function uiAskChoiceFunc(
|
|
76
|
+
args: any,
|
|
77
|
+
_thunkApi: AppThunkApi
|
|
78
|
+
): Promise<{
|
|
79
|
+
rawData: {
|
|
80
|
+
type: "ui_ask_choice";
|
|
81
|
+
question: string;
|
|
82
|
+
choices: any[];
|
|
83
|
+
blocking: boolean;
|
|
84
|
+
};
|
|
85
|
+
displayData: string;
|
|
86
|
+
}> {
|
|
87
|
+
const question = String(args?.question ?? "").trim();
|
|
88
|
+
const choices = Array.isArray(args?.choices) ? args.choices : [];
|
|
89
|
+
const blocking = args?.blocking !== false;
|
|
90
|
+
|
|
91
|
+
if (!question || choices.length === 0) {
|
|
92
|
+
throw new Error("ui_ask_choice 需要 question 和至少一个 choice。");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
rawData: {
|
|
97
|
+
type: "ui_ask_choice",
|
|
98
|
+
question,
|
|
99
|
+
choices,
|
|
100
|
+
blocking,
|
|
101
|
+
},
|
|
102
|
+
displayData: question,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { updateContentTitle } from "../../create/space/spaceSlice"; // 假设有一个对应的 action
|
|
2
|
+
import { selectCurrentSpaceId } from "../../create/space/spaceSlice";
|
|
3
|
+
|
|
4
|
+
// Tool definition
|
|
5
|
+
export const updateContentTitleTool = {
|
|
6
|
+
type: "function",
|
|
7
|
+
function: {
|
|
8
|
+
name: "update_content_title",
|
|
9
|
+
description: "更新当前空间中某个内容的标题",
|
|
10
|
+
parameters: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
contentId: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "要更新的内容ID",
|
|
16
|
+
},
|
|
17
|
+
title: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "新的页面标题",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
required: ["contentId", "title"],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 更新当前空间中某个内容标题的实现
|
|
29
|
+
* @param args 工具参数 { contentId: string, title: string }
|
|
30
|
+
* @param thunkApi Redux Thunk API { dispatch, getState }
|
|
31
|
+
* @returns Promise<{ success: true, id: string, title: string } | never> - 成功时返回包含 id 和新标题的对象,失败时抛出错误
|
|
32
|
+
*/
|
|
33
|
+
export const updateContentTitleFunc = async (
|
|
34
|
+
args: { contentId: string; title: string },
|
|
35
|
+
thunkApi: any /* Replace 'any' with your actual ThunkApi type */
|
|
36
|
+
) => {
|
|
37
|
+
const { dispatch, getState } = thunkApi;
|
|
38
|
+
const state = getState(); // Assuming getState returns RootState
|
|
39
|
+
const spaceId = selectCurrentSpaceId(state); // 获取当前空间ID
|
|
40
|
+
const { contentId, title } = args;
|
|
41
|
+
|
|
42
|
+
console.log(
|
|
43
|
+
`[updateContentTitleFunc] spaceId: ${spaceId}, contentId: ${contentId}, title: ${title}`
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (!spaceId) {
|
|
47
|
+
console.error("[updateContentTitleFunc] 更新标题失败:未找到当前空间ID");
|
|
48
|
+
throw new Error("无法更新标题,因为当前空间未设定。");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!contentId) {
|
|
52
|
+
console.error("[updateContentTitleFunc] 更新标题失败:未提供内容ID");
|
|
53
|
+
throw new Error("无法更新标题,因为内容ID未提供。");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
// 调用 updateContentTitle action (直接从 spaceSlice 中导入)
|
|
58
|
+
console.log(
|
|
59
|
+
"[updateContentTitleFunc] Dispatching updateContentTitle action..."
|
|
60
|
+
);
|
|
61
|
+
const updatedContentId = await dispatch(
|
|
62
|
+
updateContentTitle({
|
|
63
|
+
spaceId,
|
|
64
|
+
contentId,
|
|
65
|
+
title: title.trim(), // 确保标题去除首尾空格
|
|
66
|
+
})
|
|
67
|
+
).unwrap(); // unwrap 会在失败时抛出错误
|
|
68
|
+
|
|
69
|
+
console.log(
|
|
70
|
+
`[updateContentTitleFunc] Content title updated successfully. contentId: ${updatedContentId}`
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// 返回结构化数据
|
|
74
|
+
return {
|
|
75
|
+
success: true, // 明确表示成功
|
|
76
|
+
id: updatedContentId, // 返回内容ID
|
|
77
|
+
title: title, // 返回使用的新标题
|
|
78
|
+
};
|
|
79
|
+
} catch (error: any) {
|
|
80
|
+
console.error("[updateContentTitleFunc] 更新标题失败:", error);
|
|
81
|
+
const errorMessage = error?.message || JSON.stringify(error) || "未知错误";
|
|
82
|
+
throw new Error(`更新标题时出错: ${errorMessage}`);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// ai/tools/updateDocTool.ts
|
|
2
|
+
|
|
3
|
+
import { readAction } from "../../database/actions/read";
|
|
4
|
+
import { write } from "../../database/dbSlice";
|
|
5
|
+
import { markdownToSlate } from "../../create/editor/transforms/markdownToSlate";
|
|
6
|
+
import { slateToRenderMarkdown } from "../../create/editor/transforms/slateToRenderMarkdown";
|
|
7
|
+
import { extractMentionsFromSlate } from "../../create/editor/utils/slateUtils";
|
|
8
|
+
import type { PageData } from "../../render/page/types";
|
|
9
|
+
import { parseSkillDocProtocol } from "../skills/skillDocProtocol";
|
|
10
|
+
|
|
11
|
+
export const updateDocFunctionSchema = {
|
|
12
|
+
name: "updateDoc",
|
|
13
|
+
description: "更新指定页面/文档的内容。支持全量覆盖或在末尾追加内容。",
|
|
14
|
+
parameters: {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
id: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "页面/文档的 dbKey,通常以 page- 开头,例如 page-user-01ABC...",
|
|
20
|
+
},
|
|
21
|
+
content: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "要更新或追加的 Markdown 格式内容。",
|
|
24
|
+
},
|
|
25
|
+
mode: {
|
|
26
|
+
type: "string",
|
|
27
|
+
enum: ["replace", "append"],
|
|
28
|
+
description: "更新模式:'replace' 表示全量覆盖(默认),'append' 表示在页面末尾追加。",
|
|
29
|
+
default: "replace",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
required: ["id", "content"],
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* [Executor] 'updateDoc' 工具的执行函数。
|
|
38
|
+
*/
|
|
39
|
+
export async function updateDocFunc(
|
|
40
|
+
args: { id: string; content: string; mode?: "replace" | "append" },
|
|
41
|
+
thunkApi: any
|
|
42
|
+
): Promise<{ rawData: any; displayData: string }> {
|
|
43
|
+
const { id, content, mode = "replace" } = args;
|
|
44
|
+
const { dispatch } = thunkApi;
|
|
45
|
+
|
|
46
|
+
if (!id.toLowerCase().startsWith("page-")) {
|
|
47
|
+
throw new Error("updateDoc 工具仅支持更新页面 (page-xxx)。");
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
// 1. 读取原页面数据
|
|
51
|
+
const originalData = (await readAction({ dbKey: id }, thunkApi)) as PageData;
|
|
52
|
+
if (!originalData) {
|
|
53
|
+
throw new Error(`未找到 ID 为 ${id} 的页面。`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const currentMarkdown =
|
|
57
|
+
typeof originalData.content === "string" && originalData.content.trim()
|
|
58
|
+
? originalData.content
|
|
59
|
+
: slateToRenderMarkdown(
|
|
60
|
+
Array.isArray(originalData.slateData) ? originalData.slateData : [],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const mergedMarkdown = mode === "append"
|
|
64
|
+
? [currentMarkdown, content].filter(Boolean).join("\n\n")
|
|
65
|
+
: content;
|
|
66
|
+
const parsedProtocol = parseSkillDocProtocol(
|
|
67
|
+
mergedMarkdown,
|
|
68
|
+
originalData.meta,
|
|
69
|
+
originalData.tools,
|
|
70
|
+
);
|
|
71
|
+
const finalSlateData = markdownToSlate(parsedProtocol.content);
|
|
72
|
+
const tools = extractMentionsFromSlate(finalSlateData as any);
|
|
73
|
+
|
|
74
|
+
// 3. 构造更新后的数据
|
|
75
|
+
const updatedPageData: PageData = {
|
|
76
|
+
...originalData,
|
|
77
|
+
slateData: finalSlateData,
|
|
78
|
+
content: parsedProtocol.content,
|
|
79
|
+
tools,
|
|
80
|
+
...(parsedProtocol.meta ? { meta: parsedProtocol.meta } : {}),
|
|
81
|
+
updated_at: new Date().toISOString(),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// 4. 写入数据库
|
|
85
|
+
// 4. 写入数据库
|
|
86
|
+
await (dispatch as any)(write({ data: updatedPageData, customKey: id })).unwrap();
|
|
87
|
+
|
|
88
|
+
const displayData = mode === "append"
|
|
89
|
+
? `已成功在页面《${originalData.title}》末尾追加了内容。`
|
|
90
|
+
: `页面《${originalData.title}》的内容已成功更新。`;
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
rawData: { success: true, id, title: originalData.title },
|
|
94
|
+
displayData,
|
|
95
|
+
};
|
|
96
|
+
} catch (error: any) {
|
|
97
|
+
console.error("执行 updateDoc 工具时出错:", error);
|
|
98
|
+
throw new Error(`更新页面失败:${error?.message || String(error)}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// ── 向后兼容别名(旧名 updatePage / update_page)────────────────────────────
|
|
102
|
+
/** @deprecated 使用 updateDocFunctionSchema */
|
|
103
|
+
export const updatePageFunctionSchema = updateDocFunctionSchema;
|
|
104
|
+
/** @deprecated 使用 updateDocFunc */
|
|
105
|
+
export const updatePageFunc = updateDocFunc;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
KnowledgeCaptureLevel,
|
|
3
|
+
SpaceContextLevel,
|
|
4
|
+
TonePreset,
|
|
5
|
+
} from "../policy/types";
|
|
6
|
+
import {
|
|
7
|
+
normalizeAgentUpdateFieldList,
|
|
8
|
+
type AgentUpdateField,
|
|
9
|
+
} from "../policy/selfUpdateFields";
|
|
10
|
+
|
|
11
|
+
async function dispatchSetSettings(thunkApi: any, changes: Record<string, unknown>) {
|
|
12
|
+
const injectedSetSettings = thunkApi?.extra?.setSettings;
|
|
13
|
+
const setSettings =
|
|
14
|
+
typeof injectedSetSettings === "function"
|
|
15
|
+
? injectedSetSettings
|
|
16
|
+
: (await import("../../app/settings/settingSlice")).setSettings;
|
|
17
|
+
await thunkApi.dispatch(setSettings(changes as any)).unwrap();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface UpdateUserPreferenceProfileArgs {
|
|
21
|
+
userTonePreset?: TonePreset;
|
|
22
|
+
knowledgeCaptureLevel?: KnowledgeCaptureLevel;
|
|
23
|
+
spaceContextLevel?: SpaceContextLevel;
|
|
24
|
+
autoApproveSelfUpdateFields?: AgentUpdateField[];
|
|
25
|
+
globalPrompt?: string;
|
|
26
|
+
defaultAgentId?: string;
|
|
27
|
+
summary?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const updateUserPreferenceProfileFunctionSchema = {
|
|
31
|
+
name: "updateUserPreferenceProfile",
|
|
32
|
+
description: [
|
|
33
|
+
"当你已经明确收集到用户的个性化偏好时,使用本工具把这些偏好保存到用户设置里。",
|
|
34
|
+
"适用于保存 tone、knowledge capture、space context,以及用户的 global prompt / 自我介绍摘要。",
|
|
35
|
+
"只有在用户已经明确表达或确认后才调用;不要在信息不充分时猜测。",
|
|
36
|
+
"调用后,你应当用自然语言简要总结已保存的设置,并说明用户之后可以继续调整。",
|
|
37
|
+
].join("\n"),
|
|
38
|
+
parameters: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
userTonePreset: {
|
|
42
|
+
type: "string",
|
|
43
|
+
enum: ["default", "direct", "pragmatic", "friendly", "professional"],
|
|
44
|
+
description: "用户偏好的交流语气。",
|
|
45
|
+
},
|
|
46
|
+
knowledgeCaptureLevel: {
|
|
47
|
+
type: "integer",
|
|
48
|
+
enum: [1, 2, 3, 4],
|
|
49
|
+
description: "知识沉淀级别:1 不主动创建;2 先问再创建;3 回答后建议;4 高价值结果可自动创建。",
|
|
50
|
+
},
|
|
51
|
+
spaceContextLevel: {
|
|
52
|
+
type: "integer",
|
|
53
|
+
enum: [1, 2, 3, 4],
|
|
54
|
+
description: "空间上下文级别:1 不自动读取;2 只看结构和标题;3 轻量读取;4 自适应读取。",
|
|
55
|
+
},
|
|
56
|
+
autoApproveSelfUpdateFields: {
|
|
57
|
+
type: "array",
|
|
58
|
+
items: {
|
|
59
|
+
type: "string",
|
|
60
|
+
enum: [
|
|
61
|
+
"name",
|
|
62
|
+
"model",
|
|
63
|
+
"provider",
|
|
64
|
+
"prompt",
|
|
65
|
+
"introduction",
|
|
66
|
+
"greeting",
|
|
67
|
+
"isPublic",
|
|
68
|
+
"tags",
|
|
69
|
+
"tools",
|
|
70
|
+
"references",
|
|
71
|
+
"temperature",
|
|
72
|
+
"top_p",
|
|
73
|
+
"frequency_penalty",
|
|
74
|
+
"presence_penalty",
|
|
75
|
+
"max_tokens",
|
|
76
|
+
"reasoning_effort",
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
description: "哪些 updateSelf 字段以后不再询问用户,直接自动通过。",
|
|
80
|
+
},
|
|
81
|
+
globalPrompt: {
|
|
82
|
+
type: "string",
|
|
83
|
+
description: "可选:用户希望长期保留的一小段通用偏好说明。未明确确认时不要写。",
|
|
84
|
+
},
|
|
85
|
+
defaultAgentId: {
|
|
86
|
+
type: "string",
|
|
87
|
+
description: "可选:用户明确要求切换首页默认 agent 时才填写。",
|
|
88
|
+
},
|
|
89
|
+
summary: {
|
|
90
|
+
type: "string",
|
|
91
|
+
description: "给开发和日志看的简短总结,不会影响设置本身。",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
} as const,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export async function updateUserPreferenceProfileFunc(
|
|
98
|
+
args: UpdateUserPreferenceProfileArgs,
|
|
99
|
+
thunkApi: any
|
|
100
|
+
): Promise<{ rawData: unknown; displayData: string }> {
|
|
101
|
+
const changes: Record<string, unknown> = {};
|
|
102
|
+
|
|
103
|
+
if (args.userTonePreset) {
|
|
104
|
+
changes.userTonePreset = args.userTonePreset;
|
|
105
|
+
}
|
|
106
|
+
if (typeof args.knowledgeCaptureLevel === "number") {
|
|
107
|
+
changes.knowledgeCaptureLevel = args.knowledgeCaptureLevel;
|
|
108
|
+
}
|
|
109
|
+
if (typeof args.spaceContextLevel === "number") {
|
|
110
|
+
changes.spaceContextLevel = args.spaceContextLevel;
|
|
111
|
+
changes.enableReadCurrentSpace = args.spaceContextLevel > 1;
|
|
112
|
+
}
|
|
113
|
+
if (Array.isArray(args.autoApproveSelfUpdateFields)) {
|
|
114
|
+
changes.autoApproveSelfUpdateFields = normalizeAgentUpdateFieldList(
|
|
115
|
+
args.autoApproveSelfUpdateFields,
|
|
116
|
+
[]
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
if (typeof args.globalPrompt === "string" && args.globalPrompt.trim()) {
|
|
120
|
+
changes.globalPrompt = args.globalPrompt.trim();
|
|
121
|
+
}
|
|
122
|
+
if (typeof args.defaultAgentId === "string" && args.defaultAgentId.trim()) {
|
|
123
|
+
changes.defaultAgentId = args.defaultAgentId.trim();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (Object.keys(changes).length === 0) {
|
|
127
|
+
throw new Error("没有可保存的用户偏好设置。");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
await dispatchSetSettings(thunkApi, changes);
|
|
131
|
+
|
|
132
|
+
const rawData = {
|
|
133
|
+
success: true,
|
|
134
|
+
updated: changes,
|
|
135
|
+
summary: args.summary?.trim() || null,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const labels: string[] = [];
|
|
139
|
+
if (changes.userTonePreset) labels.push(`语气=${changes.userTonePreset}`);
|
|
140
|
+
if (changes.knowledgeCaptureLevel)
|
|
141
|
+
labels.push(`知识沉淀=${changes.knowledgeCaptureLevel}`);
|
|
142
|
+
if (changes.spaceContextLevel)
|
|
143
|
+
labels.push(`空间读取=${changes.spaceContextLevel}`);
|
|
144
|
+
if (changes.autoApproveSelfUpdateFields)
|
|
145
|
+
labels.push("自我更新免询问字段已更新");
|
|
146
|
+
if (changes.defaultAgentId) labels.push("默认助手已更新");
|
|
147
|
+
if (changes.globalPrompt) labels.push("通用提示词已更新");
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
rawData,
|
|
151
|
+
displayData: `已保存用户偏好:${labels.join(",")}`,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { callToolApi } from "./toolApiClient";
|
|
2
|
+
|
|
3
|
+
export const WEREAD_DEFAULT_SKILL_VERSION = "1.0.3";
|
|
4
|
+
export const WEREAD_GATEWAY_URL = "https://i.weread.qq.com/api/agent/gateway";
|
|
5
|
+
|
|
6
|
+
export interface WereadGatewayArgs {
|
|
7
|
+
api_name?: string;
|
|
8
|
+
skill_version?: string;
|
|
9
|
+
params?: Record<string, unknown>;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface WereadGatewayRunOptions {
|
|
14
|
+
apiKey: string;
|
|
15
|
+
fetchImpl?: typeof fetch;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const wereadGatewayFunctionSchema = {
|
|
19
|
+
name: "wereadGateway",
|
|
20
|
+
description:
|
|
21
|
+
"调用微信读书 Agent API Gateway。用于搜索书籍、查看书架、阅读统计、笔记划线、书评和推荐。业务参数必须平铺在请求体顶层。",
|
|
22
|
+
parameters: {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
api_name: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "微信读书接口名,例如 /store/search、/shelf/sync、/user/notebooks。",
|
|
28
|
+
},
|
|
29
|
+
skill_version: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "微信读书 skill 版本;未传时使用当前内置版本。",
|
|
32
|
+
},
|
|
33
|
+
params: {
|
|
34
|
+
type: "object",
|
|
35
|
+
description: "业务参数对象。工具会自动把字段平铺到请求体顶层,不会以 params 包裹转发。",
|
|
36
|
+
additionalProperties: true,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
required: ["api_name"],
|
|
40
|
+
} as const,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const RESERVED_ARG_KEYS = new Set(["api_name", "skill_version", "params"]);
|
|
44
|
+
|
|
45
|
+
function normalizeApiName(value: unknown): string {
|
|
46
|
+
return typeof value === "string" ? value.trim() : "";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function normalizeSkillVersion(value: unknown): string {
|
|
50
|
+
return typeof value === "string" && value.trim()
|
|
51
|
+
? value.trim()
|
|
52
|
+
: WEREAD_DEFAULT_SKILL_VERSION;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function normalizeParams(value: unknown): Record<string, unknown> {
|
|
56
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
57
|
+
return value as Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function buildWereadGatewayRequestBody(args: WereadGatewayArgs): Record<string, unknown> {
|
|
61
|
+
const apiName = normalizeApiName(args.api_name);
|
|
62
|
+
if (!apiName) {
|
|
63
|
+
throw new Error("wereadGateway 需要 api_name。");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const flattened: Record<string, unknown> = {
|
|
67
|
+
...normalizeParams(args.params),
|
|
68
|
+
};
|
|
69
|
+
for (const [key, value] of Object.entries(args)) {
|
|
70
|
+
if (!RESERVED_ARG_KEYS.has(key)) {
|
|
71
|
+
flattened[key] = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
api_name: apiName,
|
|
77
|
+
...flattened,
|
|
78
|
+
skill_version: normalizeSkillVersion(args.skill_version),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function extractUpgradeMessage(data: unknown): string | null {
|
|
83
|
+
const upgradeInfo = (data as any)?.upgrade_info;
|
|
84
|
+
return typeof upgradeInfo?.message === "string" && upgradeInfo.message.trim()
|
|
85
|
+
? upgradeInfo.message.trim()
|
|
86
|
+
: null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function extractErrcode(data: unknown): number {
|
|
90
|
+
const raw = (data as any)?.errcode;
|
|
91
|
+
return typeof raw === "number" && Number.isFinite(raw) ? raw : 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function extractErrorMessage(data: unknown): string {
|
|
95
|
+
const record = data as any;
|
|
96
|
+
return (
|
|
97
|
+
(typeof record?.errmsg === "string" && record.errmsg.trim()) ||
|
|
98
|
+
(typeof record?.message === "string" && record.message.trim()) ||
|
|
99
|
+
"微信读书接口返回错误"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function runWereadGatewayRequest(
|
|
104
|
+
args: WereadGatewayArgs,
|
|
105
|
+
options: WereadGatewayRunOptions
|
|
106
|
+
): Promise<{ rawData: unknown; displayData: string }> {
|
|
107
|
+
const apiKey = options.apiKey.trim();
|
|
108
|
+
if (!apiKey) {
|
|
109
|
+
throw new Error("缺少 WEREAD_API_KEY。请先在设置 -> 密钥中保存 WEREAD_API_KEY。");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const body = buildWereadGatewayRequestBody(args);
|
|
113
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
114
|
+
const response = await fetchImpl(WEREAD_GATEWAY_URL, {
|
|
115
|
+
method: "POST",
|
|
116
|
+
headers: {
|
|
117
|
+
Authorization: `Bearer ${apiKey}`,
|
|
118
|
+
"Content-Type": "application/json",
|
|
119
|
+
},
|
|
120
|
+
body: JSON.stringify(body),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const data = await response.json().catch(async () => ({
|
|
124
|
+
errmsg: await response.text().catch(() => ""),
|
|
125
|
+
}));
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
throw new Error(`微信读书接口请求失败:HTTP ${response.status}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const upgradeMessage = extractUpgradeMessage(data);
|
|
131
|
+
if (upgradeMessage) {
|
|
132
|
+
throw new Error(`微信读书 Skill 需要升级:${upgradeMessage}`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const errcode = extractErrcode(data);
|
|
136
|
+
if (errcode !== 0) {
|
|
137
|
+
throw new Error(`微信读书接口返回错误 ${errcode}:${extractErrorMessage(data)}`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const apiName = String(body.api_name);
|
|
141
|
+
return {
|
|
142
|
+
rawData: data,
|
|
143
|
+
displayData: `微信读书接口 ${apiName} 调用成功。\n\n${JSON.stringify(data, null, 2)}`,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function wereadGatewayFunc(
|
|
148
|
+
args: WereadGatewayArgs,
|
|
149
|
+
thunkApi: any
|
|
150
|
+
): Promise<{ rawData: unknown; displayData: string }> {
|
|
151
|
+
return callToolApi(thunkApi, "/api/weread/gateway", args, { withAuth: true });
|
|
152
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { callToolApi } from "./toolApiClient";
|
|
2
|
+
|
|
3
|
+
const SHARED_PARAMS = {
|
|
4
|
+
type: "object",
|
|
5
|
+
properties: {
|
|
6
|
+
audioUrl: {
|
|
7
|
+
type: "string",
|
|
8
|
+
description:
|
|
9
|
+
"音频来源:内部文件 ID (file-... 或 ULID)、公开 http/https URL,或 base64 data URI(data:audio/...;base64,...)。支持 mp3、wav、m4a、ogg、flac 等常见格式。",
|
|
10
|
+
},
|
|
11
|
+
language: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description:
|
|
14
|
+
"可选,指定音频语言以提升精度(如 'zh'、'en'、'ja')。不指定则自动检测。",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
required: ["audioUrl"],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// ── whisper-large-v3-turbo(快速、便宜)──────────────────
|
|
21
|
+
|
|
22
|
+
export const whisperTurboSchema = {
|
|
23
|
+
name: "whisper_turbo",
|
|
24
|
+
description:
|
|
25
|
+
"使用 openai/whisper-large-v3-turbo 对音频进行语音转文字(ASR)。速度快、价格低($0.0002/min),适合大多数场景的实时或批量转录。",
|
|
26
|
+
parameters: SHARED_PARAMS,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const whisperTurboFunc = async (
|
|
30
|
+
input: any,
|
|
31
|
+
thunkApi: any
|
|
32
|
+
): Promise<any> => {
|
|
33
|
+
const { audioUrl, language } = input;
|
|
34
|
+
const data = await callToolApi(
|
|
35
|
+
thunkApi,
|
|
36
|
+
"/api/whisper-turbo",
|
|
37
|
+
{ audioUrl, language },
|
|
38
|
+
{ withAuth: true }
|
|
39
|
+
);
|
|
40
|
+
return {
|
|
41
|
+
summary: "Transcription completed",
|
|
42
|
+
text: data.text || "",
|
|
43
|
+
language: data.language,
|
|
44
|
+
duration: data.duration,
|
|
45
|
+
rawData: data,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// ── whisper-large-v3(高精度)────────────────────────────
|
|
50
|
+
|
|
51
|
+
export const whisperV3Schema = {
|
|
52
|
+
name: "whisper_v3",
|
|
53
|
+
description:
|
|
54
|
+
"使用 openai/whisper-large-v3 对音频进行高精度语音转文字(ASR)。精度更高(尤其多语言/中文),价格稍高($0.00045/min),适合对准确率要求严格的场景。",
|
|
55
|
+
parameters: SHARED_PARAMS,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const whisperV3Func = async (
|
|
59
|
+
input: any,
|
|
60
|
+
thunkApi: any
|
|
61
|
+
): Promise<any> => {
|
|
62
|
+
const { audioUrl, language } = input;
|
|
63
|
+
const data = await callToolApi(
|
|
64
|
+
thunkApi,
|
|
65
|
+
"/api/whisper-v3",
|
|
66
|
+
{ audioUrl, language },
|
|
67
|
+
{ withAuth: true }
|
|
68
|
+
);
|
|
69
|
+
return {
|
|
70
|
+
summary: "Transcription completed",
|
|
71
|
+
text: data.text || "",
|
|
72
|
+
language: data.language,
|
|
73
|
+
duration: data.duration,
|
|
74
|
+
rawData: data,
|
|
75
|
+
};
|
|
76
|
+
};
|