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,289 @@
|
|
|
1
|
+
// packages/ai/tools/cloudflareCrawlTool.ts
|
|
2
|
+
// Cloudflare Browser Rendering /crawl 工具
|
|
3
|
+
// Docs: https://developers.cloudflare.com/browser-rendering/rest-api/crawl-endpoint/
|
|
4
|
+
|
|
5
|
+
import { callToolApi } from "./toolApiClient";
|
|
6
|
+
import { assertFetchableDocsUrl, discoverCanonicalDocsUrl } from "./fetchWebpageSupport";
|
|
7
|
+
|
|
8
|
+
// ──────────────────────────────────────────────────────────
|
|
9
|
+
// Schema
|
|
10
|
+
// ──────────────────────────────────────────────────────────
|
|
11
|
+
export const cloudflareCrawlFunctionSchema = {
|
|
12
|
+
name: "cloudflareCrawl",
|
|
13
|
+
description:
|
|
14
|
+
"使用 Cloudflare Browser Rendering 的 /crawl 接口,从指定 URL 出发自动发现并爬取整个站点(或指定深度/页数)," +
|
|
15
|
+
"支持 JS 渲染,返回 Markdown 格式内容,适合需要抓取多页且页面依赖 JavaScript 渲染的场景。" +
|
|
16
|
+
"如果目标是单页静态内容,优先使用 fetchWebpage;此工具适合多页爬取或需要完整站点索引的任务。",
|
|
17
|
+
parameters: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
url: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "爬取起始 URL,必须是完整的 http/https 地址。",
|
|
23
|
+
},
|
|
24
|
+
limit: {
|
|
25
|
+
type: "integer",
|
|
26
|
+
description: "最多爬取的页面数量(默认 10,最大 100000)。建议先从小值开始测试。",
|
|
27
|
+
default: 10,
|
|
28
|
+
},
|
|
29
|
+
depth: {
|
|
30
|
+
type: "integer",
|
|
31
|
+
description: "从起始 URL 开始的最大链接层深度(默认不限)。",
|
|
32
|
+
},
|
|
33
|
+
formats: {
|
|
34
|
+
type: "array",
|
|
35
|
+
items: { type: "string", enum: ["markdown", "html"] },
|
|
36
|
+
description: "返回格式,支持 markdown(推荐)和 html,默认 [\"markdown\"]。",
|
|
37
|
+
default: ["markdown"],
|
|
38
|
+
},
|
|
39
|
+
render: {
|
|
40
|
+
type: "boolean",
|
|
41
|
+
description:
|
|
42
|
+
"是否启动无头浏览器执行 JavaScript(默认 true)。" +
|
|
43
|
+
"静态网站可设为 false 以加快速度。",
|
|
44
|
+
default: true,
|
|
45
|
+
},
|
|
46
|
+
source: {
|
|
47
|
+
type: "string",
|
|
48
|
+
enum: ["all", "sitemaps", "links"],
|
|
49
|
+
description: "URL 发现来源:all(默认)、sitemaps 或 links。",
|
|
50
|
+
},
|
|
51
|
+
includeSubdomains: {
|
|
52
|
+
type: "boolean",
|
|
53
|
+
description: "是否跟踪子域名链接(默认 false)。",
|
|
54
|
+
},
|
|
55
|
+
includePatterns: {
|
|
56
|
+
type: "array",
|
|
57
|
+
items: { type: "string" },
|
|
58
|
+
description: "只访问匹配这些通配符的 URL(* 匹配单段,** 匹配多段)。",
|
|
59
|
+
},
|
|
60
|
+
excludePatterns: {
|
|
61
|
+
type: "array",
|
|
62
|
+
items: { type: "string" },
|
|
63
|
+
description: "跳过匹配这些通配符的 URL(优先级高于 includePatterns)。",
|
|
64
|
+
},
|
|
65
|
+
wait: {
|
|
66
|
+
type: "boolean",
|
|
67
|
+
description:
|
|
68
|
+
"是否等待爬取完成后再返回结果(默认 true,服务端最多等 60s)。" +
|
|
69
|
+
"设为 false 时立即返回 jobId,可用 cloudflareCrawlStatus 工具轮询结果。",
|
|
70
|
+
default: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
required: ["url"],
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// ──────────────────────────────────────────────────────────
|
|
78
|
+
// Types
|
|
79
|
+
// ──────────────────────────────────────────────────────────
|
|
80
|
+
interface CrawlRecord {
|
|
81
|
+
url: string;
|
|
82
|
+
status: string;
|
|
83
|
+
markdown?: string;
|
|
84
|
+
html?: string;
|
|
85
|
+
metadata?: {
|
|
86
|
+
status: number;
|
|
87
|
+
title: string;
|
|
88
|
+
url: string;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface CrawlResult {
|
|
93
|
+
jobId: string;
|
|
94
|
+
status?: string;
|
|
95
|
+
total?: number;
|
|
96
|
+
finished?: number;
|
|
97
|
+
browserSecondsUsed?: number;
|
|
98
|
+
records?: CrawlRecord[];
|
|
99
|
+
cursor?: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ──────────────────────────────────────────────────────────
|
|
103
|
+
// Executor: 启动爬取(可选等待结果)
|
|
104
|
+
// ──────────────────────────────────────────────────────────
|
|
105
|
+
export async function cloudflareCrawlFunc(
|
|
106
|
+
args: {
|
|
107
|
+
url: string;
|
|
108
|
+
limit?: number;
|
|
109
|
+
depth?: number;
|
|
110
|
+
formats?: string[];
|
|
111
|
+
render?: boolean;
|
|
112
|
+
source?: string;
|
|
113
|
+
includeSubdomains?: boolean;
|
|
114
|
+
includePatterns?: string[];
|
|
115
|
+
excludePatterns?: string[];
|
|
116
|
+
wait?: boolean;
|
|
117
|
+
},
|
|
118
|
+
thunkApi: any
|
|
119
|
+
): Promise<{ rawData: any; displayData: string }> {
|
|
120
|
+
const {
|
|
121
|
+
url,
|
|
122
|
+
limit = 10,
|
|
123
|
+
depth,
|
|
124
|
+
formats = ["markdown"],
|
|
125
|
+
render = true,
|
|
126
|
+
source,
|
|
127
|
+
includeSubdomains,
|
|
128
|
+
includePatterns,
|
|
129
|
+
excludePatterns,
|
|
130
|
+
wait = true,
|
|
131
|
+
} = args;
|
|
132
|
+
|
|
133
|
+
if (!url || !url.startsWith("http")) {
|
|
134
|
+
throw new Error("必须提供有效的 http/https URL");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const resolution = await discoverCanonicalDocsUrl(url);
|
|
138
|
+
const targetUrl = resolution.resolvedUrl;
|
|
139
|
+
if (targetUrl !== url) {
|
|
140
|
+
await assertFetchableDocsUrl(targetUrl, fetch, url);
|
|
141
|
+
}
|
|
142
|
+
const normalizationNote =
|
|
143
|
+
targetUrl !== url ? `\n🧭 文档地址已规范化: ${url} → ${targetUrl}` : "";
|
|
144
|
+
|
|
145
|
+
const options: Record<string, any> = {};
|
|
146
|
+
if (includeSubdomains !== undefined) options.includeSubdomains = includeSubdomains;
|
|
147
|
+
if (includePatterns?.length) options.includePatterns = includePatterns;
|
|
148
|
+
if (excludePatterns?.length) options.excludePatterns = excludePatterns;
|
|
149
|
+
|
|
150
|
+
const body: Record<string, any> = { url: targetUrl, limit, formats, render, wait };
|
|
151
|
+
if (depth !== undefined) body.depth = depth;
|
|
152
|
+
if (source !== undefined) body.source = source;
|
|
153
|
+
if (Object.keys(options).length > 0) body.options = options;
|
|
154
|
+
|
|
155
|
+
const data = await callToolApi<CrawlResult>(
|
|
156
|
+
thunkApi,
|
|
157
|
+
"/api/cloudflare-crawl",
|
|
158
|
+
body,
|
|
159
|
+
{ withAuth: true }
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// 仅返回 jobId(未等待)
|
|
163
|
+
if (!wait || data.status === "running") {
|
|
164
|
+
const rawData = targetUrl === url ? data : { ...data, originalUrl: url, resolvedUrl: targetUrl };
|
|
165
|
+
return {
|
|
166
|
+
rawData,
|
|
167
|
+
displayData:
|
|
168
|
+
`🚀 爬取任务已启动 (jobId: ${data.jobId})\n目标: ${targetUrl}` +
|
|
169
|
+
normalizationNote +
|
|
170
|
+
`\n使用 cloudflareCrawlStatus 工具查询结果。`,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 已完成:格式化结果
|
|
175
|
+
const records = data.records ?? [];
|
|
176
|
+
const completedCount = records.filter((r) => r.status === "completed").length;
|
|
177
|
+
const mdParts = records
|
|
178
|
+
.filter((r) => r.status === "completed" && r.markdown)
|
|
179
|
+
.map((r) => `## ${r.metadata?.title || r.url}\n> ${r.url}\n\n${r.markdown}`)
|
|
180
|
+
.join("\n\n---\n\n");
|
|
181
|
+
|
|
182
|
+
const rawData = {
|
|
183
|
+
jobId: data.jobId,
|
|
184
|
+
status: data.status,
|
|
185
|
+
total: data.total,
|
|
186
|
+
finished: data.finished,
|
|
187
|
+
browserSecondsUsed: data.browserSecondsUsed,
|
|
188
|
+
pages: records.map((r) => ({
|
|
189
|
+
url: r.url,
|
|
190
|
+
status: r.status,
|
|
191
|
+
title: r.metadata?.title,
|
|
192
|
+
content: r.markdown || r.html || "",
|
|
193
|
+
})),
|
|
194
|
+
...(targetUrl === url ? {} : { originalUrl: url, resolvedUrl: targetUrl }),
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const statusIcon = data.status === "completed" ? "✅" : "⚠️";
|
|
198
|
+
const displayData =
|
|
199
|
+
`${statusIcon} Cloudflare 爬取完成\n` +
|
|
200
|
+
`- 目标: ${targetUrl}\n` +
|
|
201
|
+
`- 状态: ${data.status}\n` +
|
|
202
|
+
`- 已完成页面: ${completedCount} / ${data.total ?? "?"}\n` +
|
|
203
|
+
`- 浏览器用时: ${data.browserSecondsUsed?.toFixed(1) ?? "?"}s` +
|
|
204
|
+
normalizationNote +
|
|
205
|
+
`\n\n` +
|
|
206
|
+
(mdParts ? `**内容摘要(前 3 页):**\n\n${records.slice(0, 3).map((r) => `- [${r.metadata?.title || r.url}](${r.url})`).join("\n")}` : "无可用内容");
|
|
207
|
+
|
|
208
|
+
return { rawData, displayData };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ──────────────────────────────────────────────────────────
|
|
212
|
+
// Schema: 查询已有任务状态
|
|
213
|
+
// ──────────────────────────────────────────────────────────
|
|
214
|
+
export const cloudflareCrawlStatusFunctionSchema = {
|
|
215
|
+
name: "cloudflareCrawlStatus",
|
|
216
|
+
description:
|
|
217
|
+
"查询由 cloudflareCrawl 工具创建的爬取任务的当前状态和结果。" +
|
|
218
|
+
"当 cloudflareCrawl 以 wait=false 模式启动时,使用此工具轮询结果。",
|
|
219
|
+
parameters: {
|
|
220
|
+
type: "object",
|
|
221
|
+
properties: {
|
|
222
|
+
jobId: {
|
|
223
|
+
type: "string",
|
|
224
|
+
description: "由 cloudflareCrawl 返回的任务 ID。",
|
|
225
|
+
},
|
|
226
|
+
limit: {
|
|
227
|
+
type: "integer",
|
|
228
|
+
description: "最多返回多少条记录(用于分页)。",
|
|
229
|
+
},
|
|
230
|
+
status: {
|
|
231
|
+
type: "string",
|
|
232
|
+
enum: ["queued", "completed", "disallowed", "skipped", "errored", "cancelled"],
|
|
233
|
+
description: "按 URL 状态过滤结果。",
|
|
234
|
+
},
|
|
235
|
+
cursor: {
|
|
236
|
+
type: "integer",
|
|
237
|
+
description: "分页游标,从上一页响应的 cursor 字段获取。",
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
required: ["jobId"],
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// ──────────────────────────────────────────────────────────
|
|
245
|
+
// Executor: 查询任务状态
|
|
246
|
+
// ──────────────────────────────────────────────────────────
|
|
247
|
+
export async function cloudflareCrawlStatusFunc(
|
|
248
|
+
args: { jobId: string; limit?: number; status?: string; cursor?: number },
|
|
249
|
+
thunkApi: any
|
|
250
|
+
): Promise<{ rawData: any; displayData: string }> {
|
|
251
|
+
const { jobId, limit, status, cursor } = args;
|
|
252
|
+
|
|
253
|
+
if (!jobId) throw new Error("必须提供 jobId");
|
|
254
|
+
|
|
255
|
+
// 通过 GET /api/cloudflare-crawl/:jobId 查询
|
|
256
|
+
const { getToolRequestContext } = await import("./toolApiClient");
|
|
257
|
+
const { baseUrl, token } = getToolRequestContext(thunkApi);
|
|
258
|
+
|
|
259
|
+
const params = new URLSearchParams();
|
|
260
|
+
if (limit !== undefined) params.set("limit", String(limit));
|
|
261
|
+
if (status) params.set("status", status);
|
|
262
|
+
if (cursor !== undefined) params.set("cursor", String(cursor));
|
|
263
|
+
const qs = params.toString() ? `?${params}` : "";
|
|
264
|
+
|
|
265
|
+
const headers: Record<string, string> = { "Content-Type": "application/json" };
|
|
266
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
267
|
+
|
|
268
|
+
const resp = await fetch(`${baseUrl}/api/cloudflare-crawl/${jobId}${qs}`, { headers });
|
|
269
|
+
if (!resp.ok) {
|
|
270
|
+
const err = await resp.json().catch(() => ({})) as any;
|
|
271
|
+
throw new Error(`查询爬取任务失败: ${err?.error?.message ?? resp.status}`);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const data = await resp.json() as CrawlResult & { status: string };
|
|
275
|
+
|
|
276
|
+
const isRunning = data.status === "running";
|
|
277
|
+
const statusIcon = isRunning ? "🔄" : data.status === "completed" ? "✅" : "⚠️";
|
|
278
|
+
const records = (data as any).records ?? [];
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
rawData: data,
|
|
282
|
+
displayData:
|
|
283
|
+
`${statusIcon} 任务 ${jobId} 状态: ${data.status}\n` +
|
|
284
|
+
`- 总页面: ${(data as any).total ?? "?"}, 已完成: ${(data as any).finished ?? "?"}\n` +
|
|
285
|
+
(records.length > 0
|
|
286
|
+
? `\n已抓取页面:\n${records.slice(0, 5).map((r: CrawlRecord) => ` - ${r.metadata?.title || r.url} (${r.status})`).join("\n")}`
|
|
287
|
+
: ""),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { buildToolRequestHeaders, getToolBaseUrl } from "./toolApiClient";
|
|
2
|
+
|
|
3
|
+
export type CodeSearchArgs = {
|
|
4
|
+
query?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
pathScope?: string;
|
|
7
|
+
glob?: string;
|
|
8
|
+
mode?: "content" | "files";
|
|
9
|
+
maxResults?: number;
|
|
10
|
+
maxFiles?: number;
|
|
11
|
+
caseSensitive?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const codeSearchFunctionSchema = {
|
|
15
|
+
name: "codeSearch",
|
|
16
|
+
description: [
|
|
17
|
+
"使用 ripgrep (rg) 在项目代码中搜索文本,或按 glob 列出文件。",
|
|
18
|
+
"",
|
|
19
|
+
"推荐场景:",
|
|
20
|
+
"- mode=content:按关键词搜索代码内容,替代旧的 searchRepo。",
|
|
21
|
+
"- mode=files:按路径范围和 glob 列出文件,替代旧的 listFiles。",
|
|
22
|
+
"",
|
|
23
|
+
"参数说明:",
|
|
24
|
+
"- query:搜索文本;mode=content 时必填,mode=files 时可省略。",
|
|
25
|
+
"- path/pathScope:限制搜索目录,例如 'packages/server'。",
|
|
26
|
+
"- glob:可选文件匹配模式,例如 '**/*.ts'。",
|
|
27
|
+
"- maxResults:最大返回数量;兼容旧参数 maxFiles。",
|
|
28
|
+
"- caseSensitive:是否区分大小写,默认 false。",
|
|
29
|
+
].join("\n"),
|
|
30
|
+
parameters: {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
query: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: "可选:要搜索的文本。mode=content 时必须提供。",
|
|
36
|
+
},
|
|
37
|
+
path: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "可选:限制搜索目录,例如 'packages/ai'。",
|
|
40
|
+
},
|
|
41
|
+
pathScope: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "兼容旧参数:限制搜索目录,例如 'packages/ai'。",
|
|
44
|
+
},
|
|
45
|
+
glob: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "可选:文件 glob,例如 '**/*.ts'。",
|
|
48
|
+
},
|
|
49
|
+
mode: {
|
|
50
|
+
type: "string",
|
|
51
|
+
enum: ["content", "files"],
|
|
52
|
+
description: "搜索模式:content=搜内容,files=列文件。",
|
|
53
|
+
},
|
|
54
|
+
maxResults: {
|
|
55
|
+
type: "number",
|
|
56
|
+
description: "最大返回数量。兼容旧参数 maxFiles。",
|
|
57
|
+
},
|
|
58
|
+
maxFiles: {
|
|
59
|
+
type: "number",
|
|
60
|
+
description: "兼容旧参数:等价于 maxResults。",
|
|
61
|
+
},
|
|
62
|
+
caseSensitive: {
|
|
63
|
+
type: "boolean",
|
|
64
|
+
description: "是否区分大小写,默认 false。",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export async function codeSearchFunc(
|
|
71
|
+
args: CodeSearchArgs,
|
|
72
|
+
thunkApi: any,
|
|
73
|
+
context?: { signal?: AbortSignal; agentKey?: string },
|
|
74
|
+
): Promise<{ rawData: any; displayData?: string }> {
|
|
75
|
+
const baseUrl = getToolBaseUrl(thunkApi);
|
|
76
|
+
const apiUrl = `${baseUrl}/api/code-search`;
|
|
77
|
+
const mode = args.mode ?? "content";
|
|
78
|
+
|
|
79
|
+
const response = await fetch(apiUrl, {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: buildToolRequestHeaders(thunkApi, {
|
|
82
|
+
withAuth: true,
|
|
83
|
+
agentKey: context?.agentKey,
|
|
84
|
+
}),
|
|
85
|
+
signal: context?.signal,
|
|
86
|
+
body: JSON.stringify({
|
|
87
|
+
query: args.query,
|
|
88
|
+
path: args.path ?? args.pathScope,
|
|
89
|
+
glob: args.glob,
|
|
90
|
+
mode,
|
|
91
|
+
maxResults: args.maxResults ?? args.maxFiles,
|
|
92
|
+
caseSensitive: args.caseSensitive,
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const responseText = await response.text();
|
|
97
|
+
let data: any = null;
|
|
98
|
+
try {
|
|
99
|
+
data = responseText ? JSON.parse(responseText) : {};
|
|
100
|
+
} catch {
|
|
101
|
+
data = null;
|
|
102
|
+
}
|
|
103
|
+
if (!response.ok || data?.error) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
data?.error ||
|
|
106
|
+
`codeSearch 请求失败: ${response.status}${responseText ? `. 响应: ${responseText}` : ""}`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (mode === "files") {
|
|
111
|
+
const files = Array.isArray(data.files) ? data.files : [];
|
|
112
|
+
return {
|
|
113
|
+
rawData: data,
|
|
114
|
+
displayData: `📁 codeSearch 列出 ${files.length} 个文件${data.truncated ? "(已截断)" : ""}`,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const hits = Array.isArray(data.hits) ? data.hits : [];
|
|
119
|
+
return {
|
|
120
|
+
rawData: data,
|
|
121
|
+
displayData: `🔍 codeSearch 找到 ${hits.length} 条匹配${data.truncated ? "(已截断)" : ""}`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// 文件路径: packages/ai/tools/codeTools.ts
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
readFileFunctionSchema,
|
|
5
|
+
readFileFunc,
|
|
6
|
+
readFilePreviewFunc,
|
|
7
|
+
} from "./readFileTool";
|
|
8
|
+
import {
|
|
9
|
+
writeFileFunctionSchema,
|
|
10
|
+
writeFileFunc,
|
|
11
|
+
writeFilePreviewFunc,
|
|
12
|
+
} from "./writeFileTool";
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
codeSearchFunctionSchema,
|
|
16
|
+
codeSearchFunc,
|
|
17
|
+
} from "./codeSearchTool";
|
|
18
|
+
import {
|
|
19
|
+
applyEditFunctionSchema,
|
|
20
|
+
applyEditFunc,
|
|
21
|
+
} from "./applyEditTool";
|
|
22
|
+
import {
|
|
23
|
+
applyLineEditsFunctionSchema,
|
|
24
|
+
applyLineEditsFunc,
|
|
25
|
+
} from "./applyLineEditsTool";
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
import type { ToolDefinition } from "./index";
|
|
29
|
+
|
|
30
|
+
export const codeToolDefinitions: ToolDefinition[] = [
|
|
31
|
+
{
|
|
32
|
+
id: "readFile",
|
|
33
|
+
schema: readFileFunctionSchema,
|
|
34
|
+
executor: readFileFunc,
|
|
35
|
+
previewExecutor: readFilePreviewFunc,
|
|
36
|
+
description: {
|
|
37
|
+
name: "readFile",
|
|
38
|
+
description:
|
|
39
|
+
"读取项目中的指定文本文件的完整内容,常用于在修改前先查看代码。",
|
|
40
|
+
category: "代码 / 文件操作",
|
|
41
|
+
},
|
|
42
|
+
behavior: "data",
|
|
43
|
+
uiGroup: "data",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "writeFile",
|
|
47
|
+
schema: writeFileFunctionSchema,
|
|
48
|
+
executor: writeFileFunc,
|
|
49
|
+
previewExecutor: writeFilePreviewFunc,
|
|
50
|
+
description: {
|
|
51
|
+
name: "writeFile",
|
|
52
|
+
description:
|
|
53
|
+
"在项目中创建或覆盖一个文件的完整内容,适合新建文件或整文件重写。",
|
|
54
|
+
category: "代码编辑",
|
|
55
|
+
},
|
|
56
|
+
behavior: "action",
|
|
57
|
+
cancelable: true,
|
|
58
|
+
uiGroup: "data",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "applyEdit",
|
|
62
|
+
schema: applyEditFunctionSchema,
|
|
63
|
+
executor: applyEditFunc,
|
|
64
|
+
description: {
|
|
65
|
+
name: "applyEdit",
|
|
66
|
+
description:
|
|
67
|
+
"基于精确文本片段执行局部代码修改,默认唯一匹配,适合作为首选编辑工具。",
|
|
68
|
+
category: "代码编辑",
|
|
69
|
+
},
|
|
70
|
+
behavior: "action",
|
|
71
|
+
cancelable: true,
|
|
72
|
+
uiGroup: "data",
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
id: "codeSearch",
|
|
77
|
+
schema: codeSearchFunctionSchema,
|
|
78
|
+
executor: codeSearchFunc,
|
|
79
|
+
description: {
|
|
80
|
+
name: "codeSearch",
|
|
81
|
+
description: "基于 rg 搜索代码内容或列出文件,统一替代旧的 searchRepo/listFiles。",
|
|
82
|
+
category: "代码分析",
|
|
83
|
+
},
|
|
84
|
+
behavior: "data",
|
|
85
|
+
uiGroup: "data",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "applyLineEdits",
|
|
89
|
+
schema: applyLineEditsFunctionSchema,
|
|
90
|
+
executor: applyLineEditsFunc,
|
|
91
|
+
description: {
|
|
92
|
+
name: "applyLineEdits",
|
|
93
|
+
description:
|
|
94
|
+
"对指定代码文件按行号执行精确的文本编辑操作,适合 applyEdit 不方便表达的局部修改。",
|
|
95
|
+
category: "代码编辑",
|
|
96
|
+
},
|
|
97
|
+
behavior: "action",
|
|
98
|
+
cancelable: true,
|
|
99
|
+
uiGroup: "data",
|
|
100
|
+
},
|
|
101
|
+
];
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { convertMarxistsBookToOfflineHtml } from "./marxistsOfflineBook";
|
|
2
|
+
|
|
3
|
+
export const convertMarxistsBookToOfflineHtmlFunctionSchema = {
|
|
4
|
+
name: "convertMarxistsBookToOfflineHtml",
|
|
5
|
+
description:
|
|
6
|
+
"将 Marxists.org 中文旧式书籍页面转换成离线单 HTML。会从章节 URL 推导目录页,下载同目录章节、CSS 和背景图,保留原始排版并内嵌资源,适合 iPad/移动设备离线阅读。",
|
|
7
|
+
parameters: {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
startUrl: {
|
|
11
|
+
type: "string",
|
|
12
|
+
description:
|
|
13
|
+
"任意一个 Marxists.org 中文书籍章节 URL,例如 https://www.marxists.org/chinese/fromm/1973/01.htm。",
|
|
14
|
+
},
|
|
15
|
+
encoding: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "源站 HTML/CSS 编码,老中文页面通常是 gb2312。默认 gb2312。",
|
|
18
|
+
default: "gb2312",
|
|
19
|
+
},
|
|
20
|
+
outputMode: {
|
|
21
|
+
type: "string",
|
|
22
|
+
enum: ["summary", "html"],
|
|
23
|
+
description:
|
|
24
|
+
"summary 只返回元数据和文件引用;html 同时返回完整 HTML 字符串。需要直接拿到文件内容时用 html。",
|
|
25
|
+
default: "summary",
|
|
26
|
+
},
|
|
27
|
+
singleFileName: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description:
|
|
30
|
+
"生成文件建议名称,默认根据书名或 URL 生成;server-side agent 可用它作为保存文件名。",
|
|
31
|
+
},
|
|
32
|
+
maxPages: {
|
|
33
|
+
type: "number",
|
|
34
|
+
description: "最多允许抓取的同目录章节页数量,默认 80,防止误抓整个站点。",
|
|
35
|
+
default: 80,
|
|
36
|
+
},
|
|
37
|
+
saveAsFile: {
|
|
38
|
+
type: "boolean",
|
|
39
|
+
description:
|
|
40
|
+
"server-side agent 可设为 true,将 HTML 保存为 Nolo 文件并返回下载 URL;如果只需要 HTML 字符串,可设为 false。",
|
|
41
|
+
default: true,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
required: ["startUrl"],
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type ConvertMarxistsBookToolArgs = {
|
|
49
|
+
startUrl: string;
|
|
50
|
+
encoding?: string;
|
|
51
|
+
outputMode?: "summary" | "html";
|
|
52
|
+
singleFileName?: string;
|
|
53
|
+
maxPages?: number;
|
|
54
|
+
saveAsFile?: boolean;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export async function convertMarxistsBookToOfflineHtmlFunc(
|
|
58
|
+
args: ConvertMarxistsBookToolArgs,
|
|
59
|
+
): Promise<{ rawData: Record<string, unknown>; displayData: string }> {
|
|
60
|
+
const result = await convertMarxistsBookToOfflineHtml({
|
|
61
|
+
startUrl: args.startUrl,
|
|
62
|
+
encoding: args.encoding,
|
|
63
|
+
maxPages: args.maxPages,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const rawData: Record<string, unknown> = {
|
|
67
|
+
title: result.title,
|
|
68
|
+
startUrl: result.startUrl,
|
|
69
|
+
indexUrl: result.indexUrl,
|
|
70
|
+
stylesheetUrl: result.stylesheetUrl,
|
|
71
|
+
pages: result.pages,
|
|
72
|
+
validation: result.validation,
|
|
73
|
+
fileName: args.singleFileName,
|
|
74
|
+
};
|
|
75
|
+
if (args.outputMode === "html") {
|
|
76
|
+
rawData.html = result.html;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
rawData,
|
|
81
|
+
displayData: formatMarxistsOfflineBookDisplayData({
|
|
82
|
+
...rawData,
|
|
83
|
+
htmlIncluded: args.outputMode === "html",
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function formatMarxistsOfflineBookDisplayData(data: Record<string, unknown>): string {
|
|
89
|
+
const validation = (data.validation ?? {}) as any;
|
|
90
|
+
const pages = Array.isArray(data.pages) ? data.pages : [];
|
|
91
|
+
return [
|
|
92
|
+
"✅ 已生成离线 HTML",
|
|
93
|
+
`书名:${data.title || "未知"}`,
|
|
94
|
+
`章节数:${validation.pageCount ?? pages.length}`,
|
|
95
|
+
`大小:${validation.byteLength ?? "未知"} bytes`,
|
|
96
|
+
`资源内嵌:${validation.hasEmbeddedAssets ? "是" : "否"}`,
|
|
97
|
+
`残留网络 URL:${validation.hasNetworkUrls ? "是" : "否"}`,
|
|
98
|
+
data.fileUrl ? `文件:${data.fileUrl}` : undefined,
|
|
99
|
+
data.htmlIncluded ? "已在 rawData.html 返回完整 HTML。" : undefined,
|
|
100
|
+
]
|
|
101
|
+
.filter(Boolean)
|
|
102
|
+
.join("\n");
|
|
103
|
+
}
|