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,315 @@
|
|
|
1
|
+
// 文件: ai/tools/table/createTableTool.ts
|
|
2
|
+
|
|
3
|
+
import { createTable } from "../../../render/table/tableSlice";
|
|
4
|
+
import { SEPARATOR } from "../../../database/keys";
|
|
5
|
+
|
|
6
|
+
type ColumnType =
|
|
7
|
+
| "text"
|
|
8
|
+
| "number"
|
|
9
|
+
| "boolean"
|
|
10
|
+
| "date"
|
|
11
|
+
| "datetime"
|
|
12
|
+
| "select"
|
|
13
|
+
| "multi_select";
|
|
14
|
+
|
|
15
|
+
interface ToolTableColumnInput {
|
|
16
|
+
name: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
type?: ColumnType;
|
|
19
|
+
description?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
options?: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type CreateTableToolArgs = {
|
|
25
|
+
spaceId?: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
tags?: string[];
|
|
29
|
+
categoryId?: string;
|
|
30
|
+
columns: ToolTableColumnInput[];
|
|
31
|
+
withDefaultRows?: boolean;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type CreateTableResult = {
|
|
35
|
+
rawData: any;
|
|
36
|
+
displayData: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 解析 meta dbKey,得到 tenantId / tableId
|
|
41
|
+
* 约定:meta-{tenantId}-{tableId}
|
|
42
|
+
*/
|
|
43
|
+
const parseMetaKey = (dbKey: string): { tenantId: string; tableId: string } => {
|
|
44
|
+
const parts = dbKey.split(SEPARATOR);
|
|
45
|
+
if (parts[0] !== "meta" || parts.length < 3) {
|
|
46
|
+
return { tenantId: "", tableId: "" };
|
|
47
|
+
}
|
|
48
|
+
const tenantId = parts[1];
|
|
49
|
+
const tableId = parts.slice(2).join(SEPARATOR);
|
|
50
|
+
return { tenantId, tableId };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const toPreviewJson = (value: unknown, maxLength = 400): string => {
|
|
54
|
+
try {
|
|
55
|
+
const json = JSON.stringify(value, null, 2);
|
|
56
|
+
if (json.length <= maxLength) return json;
|
|
57
|
+
return `${json.slice(0, maxLength)}\n…(已截断)…`;
|
|
58
|
+
} catch {
|
|
59
|
+
return "[无法序列化为 JSON]";
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* [Schema] createTable:为当前用户创建一张新表
|
|
65
|
+
*/
|
|
66
|
+
export const createTableFunctionSchema = {
|
|
67
|
+
name: "createTable",
|
|
68
|
+
description: [
|
|
69
|
+
"在当前用户(租户)下创建一张新的结构化数据表。",
|
|
70
|
+
"根据用户的描述,设计表的标题(title)、用途说明(description)以及字段列表(columns)。",
|
|
71
|
+
"字段名建议使用简洁的英文或拼音(如 name, desc, status, dueDate),避免空格和特殊符号。",
|
|
72
|
+
].join("\n"),
|
|
73
|
+
parameters: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {
|
|
76
|
+
spaceId: {
|
|
77
|
+
type: "string",
|
|
78
|
+
description:
|
|
79
|
+
"可选:指定要创建到的 Space ID。不传则使用当前 Space。",
|
|
80
|
+
},
|
|
81
|
+
title: {
|
|
82
|
+
type: "string",
|
|
83
|
+
description:
|
|
84
|
+
"表的显示名称,可以使用中文,例如「任务清单」「客户管理」。",
|
|
85
|
+
},
|
|
86
|
+
description: {
|
|
87
|
+
type: "string",
|
|
88
|
+
description:
|
|
89
|
+
"表用途说明(给人和 AI 看):建议描述每一行代表什么,以及这张表大致用来干什么。",
|
|
90
|
+
},
|
|
91
|
+
tags: {
|
|
92
|
+
type: "array",
|
|
93
|
+
items: { type: "string" },
|
|
94
|
+
description:
|
|
95
|
+
"可选:表示该表的关键词标签列表,例如 [\"记账\",\"交易\",\"预算\"]。主要供 AI 选表使用,用户无需手动维护。",
|
|
96
|
+
},
|
|
97
|
+
categoryId: {
|
|
98
|
+
type: "string",
|
|
99
|
+
description: "可选:Space 内分类 ID。",
|
|
100
|
+
},
|
|
101
|
+
columns: {
|
|
102
|
+
type: "array",
|
|
103
|
+
description: [
|
|
104
|
+
"要创建的字段列表,至少包含 1 个字段。",
|
|
105
|
+
"字段顺序会按数组顺序保存。",
|
|
106
|
+
"",
|
|
107
|
+
"每个字段对象支持:",
|
|
108
|
+
"- name: 字段 machine 名(英文/拼音,无空格),必填;",
|
|
109
|
+
"- label: 字段显示名,可中文;",
|
|
110
|
+
"- type: 字段类型,默认 text,可选:text/number/boolean/date/datetime/select/multi_select;",
|
|
111
|
+
"- description: 字段含义说明,给人和 AI 看;",
|
|
112
|
+
"- required: 是否必填;",
|
|
113
|
+
"- options: 对于 select/multi_select 的可选值列表。",
|
|
114
|
+
].join("\n"),
|
|
115
|
+
minItems: 1,
|
|
116
|
+
items: {
|
|
117
|
+
type: "object",
|
|
118
|
+
properties: {
|
|
119
|
+
name: {
|
|
120
|
+
type: "string",
|
|
121
|
+
description:
|
|
122
|
+
"字段名(machine name),例如 name、desc、status、dueDate。必须是单个标识符,不要包含空格。",
|
|
123
|
+
},
|
|
124
|
+
label: {
|
|
125
|
+
type: "string",
|
|
126
|
+
description:
|
|
127
|
+
"字段显示名,可中文,例如「订单金额」「备注」。不填时前端会回退为 name。",
|
|
128
|
+
},
|
|
129
|
+
type: {
|
|
130
|
+
type: "string",
|
|
131
|
+
enum: [
|
|
132
|
+
"text",
|
|
133
|
+
"number",
|
|
134
|
+
"boolean",
|
|
135
|
+
"date",
|
|
136
|
+
"datetime",
|
|
137
|
+
"select",
|
|
138
|
+
"multi_select",
|
|
139
|
+
],
|
|
140
|
+
description:
|
|
141
|
+
"字段类型,默认 text。选择类字段请使用 select 或 multi_select。",
|
|
142
|
+
},
|
|
143
|
+
description: {
|
|
144
|
+
type: "string",
|
|
145
|
+
description:
|
|
146
|
+
"字段含义说明,既给用户也给 AI 看,例如「订单金额(单位人民币)」。",
|
|
147
|
+
},
|
|
148
|
+
required: {
|
|
149
|
+
type: "boolean",
|
|
150
|
+
description: "是否为必填字段。",
|
|
151
|
+
},
|
|
152
|
+
options: {
|
|
153
|
+
type: "array",
|
|
154
|
+
items: { type: "string" },
|
|
155
|
+
description:
|
|
156
|
+
"当 type 为 select 或 multi_select 时可用,表示允许的取值列表,例如 [\"created\",\"paid\",\"done\"]。",
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
required: ["name"],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
withDefaultRows: {
|
|
163
|
+
type: "boolean",
|
|
164
|
+
description:
|
|
165
|
+
"是否自动创建两行示例数据。默认 false(AI 创建的表通常不需要示例行)。",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
required: ["columns"],
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* [Executor] 创建一张新表(调用 tableSlice.createTable thunk)
|
|
174
|
+
*/
|
|
175
|
+
export async function createTableFunc(
|
|
176
|
+
args: CreateTableToolArgs,
|
|
177
|
+
thunkApi: any
|
|
178
|
+
): Promise<CreateTableResult> {
|
|
179
|
+
const spaceId =
|
|
180
|
+
typeof args?.spaceId === "string" && args.spaceId.trim()
|
|
181
|
+
? args.spaceId.trim()
|
|
182
|
+
: undefined;
|
|
183
|
+
const title =
|
|
184
|
+
typeof args?.title === "string" && args.title.trim()
|
|
185
|
+
? args.title.trim()
|
|
186
|
+
: undefined;
|
|
187
|
+
const description =
|
|
188
|
+
typeof args?.description === "string" && args.description.trim()
|
|
189
|
+
? args.description.trim()
|
|
190
|
+
: undefined;
|
|
191
|
+
const tags =
|
|
192
|
+
Array.isArray(args?.tags) && args.tags.length
|
|
193
|
+
? args.tags
|
|
194
|
+
.map((t) => (typeof t === "string" ? t.trim() : ""))
|
|
195
|
+
.filter(Boolean)
|
|
196
|
+
: undefined;
|
|
197
|
+
const categoryId =
|
|
198
|
+
typeof args?.categoryId === "string" && args.categoryId.trim()
|
|
199
|
+
? args.categoryId.trim()
|
|
200
|
+
: undefined;
|
|
201
|
+
const withDefaultRows =
|
|
202
|
+
typeof args?.withDefaultRows === "boolean" ? args.withDefaultRows : false;
|
|
203
|
+
|
|
204
|
+
const columnsInput = Array.isArray(args?.columns) ? args.columns : [];
|
|
205
|
+
|
|
206
|
+
if (columnsInput.length === 0) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
"createTable.columns 至少需要包含一个字段,请根据用户需求设计字段。"
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 1. 清洗字段:去空白、去重
|
|
213
|
+
const seen = new Set<string>();
|
|
214
|
+
const sanitizedColumns: ToolTableColumnInput[] = [];
|
|
215
|
+
|
|
216
|
+
for (const col of columnsInput) {
|
|
217
|
+
if (!col || typeof col.name !== "string") continue;
|
|
218
|
+
const name = col.name.trim();
|
|
219
|
+
if (!name) continue;
|
|
220
|
+
if (seen.has(name)) continue;
|
|
221
|
+
seen.add(name);
|
|
222
|
+
|
|
223
|
+
const sanitized: ToolTableColumnInput = { name };
|
|
224
|
+
|
|
225
|
+
if (typeof col.label === "string" && col.label.trim()) {
|
|
226
|
+
sanitized.label = col.label.trim();
|
|
227
|
+
}
|
|
228
|
+
if (typeof col.type === "string") {
|
|
229
|
+
sanitized.type = col.type as ColumnType;
|
|
230
|
+
}
|
|
231
|
+
if (typeof col.description === "string" && col.description.trim()) {
|
|
232
|
+
sanitized.description = col.description.trim();
|
|
233
|
+
}
|
|
234
|
+
if (typeof col.required === "boolean") {
|
|
235
|
+
sanitized.required = col.required;
|
|
236
|
+
}
|
|
237
|
+
if (Array.isArray(col.options)) {
|
|
238
|
+
const opts = col.options
|
|
239
|
+
.map((opt) => (typeof opt === "string" ? opt.trim() : ""))
|
|
240
|
+
.filter(Boolean);
|
|
241
|
+
if (opts.length) sanitized.options = opts;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
sanitizedColumns.push(sanitized);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (sanitizedColumns.length === 0) {
|
|
248
|
+
throw new Error(
|
|
249
|
+
"createTable.columns 中没有任何有效的字段名,请为至少一个字段提供非空的 name。"
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// 2. 构造 CreateTableArgs(与 render/table/createTableAction.ts 对齐)
|
|
254
|
+
const createArgs: any = {
|
|
255
|
+
spaceId,
|
|
256
|
+
title,
|
|
257
|
+
description,
|
|
258
|
+
tags,
|
|
259
|
+
categoryId,
|
|
260
|
+
columns: sanitizedColumns,
|
|
261
|
+
withDefaultRows,
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
const actionResult = await thunkApi.dispatch(createTable(createArgs));
|
|
266
|
+
|
|
267
|
+
if (!createTable.fulfilled.match(actionResult)) {
|
|
268
|
+
const msg =
|
|
269
|
+
(actionResult.payload as string) ||
|
|
270
|
+
actionResult.error?.message ||
|
|
271
|
+
"创建表失败";
|
|
272
|
+
throw new Error(msg);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// createTableAction 返回的是 dbKey(string)
|
|
276
|
+
const dbKey = actionResult.payload as string;
|
|
277
|
+
|
|
278
|
+
// 解析出 tenantId / tableId
|
|
279
|
+
const { tenantId, tableId } = parseMetaKey(dbKey);
|
|
280
|
+
|
|
281
|
+
const finalTitle = title || "新建表格";
|
|
282
|
+
const colNamesForDisplay = sanitizedColumns.map((c) => c.name).join(", ");
|
|
283
|
+
|
|
284
|
+
// 给聊天前端的结构化数据,供 Tool 卡片渲染
|
|
285
|
+
const tableMetaForUi = {
|
|
286
|
+
dbKey, // meta-{tenantId}-{tableId}
|
|
287
|
+
tenantId,
|
|
288
|
+
tableId,
|
|
289
|
+
displayName: finalTitle,
|
|
290
|
+
description,
|
|
291
|
+
tags,
|
|
292
|
+
columns: sanitizedColumns, // [{ name, label?, type?, description?, required?, options? }]
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
rawData: tableMetaForUi,
|
|
297
|
+
displayData:
|
|
298
|
+
`已创建新表「${finalTitle}」(tableId: ${tableId})。\n` +
|
|
299
|
+
`字段列表:${colNamesForDisplay}\n\n` +
|
|
300
|
+
`接下来调用 addTableRow 时,请传入完整结构:\n` +
|
|
301
|
+
`{\n` +
|
|
302
|
+
` "tenantId": "${tenantId}",\n` +
|
|
303
|
+
` "tableId": "${tableId}",\n` +
|
|
304
|
+
` "values": {\n` +
|
|
305
|
+
` "列名": "字段值"\n` +
|
|
306
|
+
` }\n` +
|
|
307
|
+
`}\n\n` +
|
|
308
|
+
`服务器返回 dbKey:\n${toPreviewJson(dbKey)}`,
|
|
309
|
+
};
|
|
310
|
+
} catch (error: any) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
`createTable 调用失败:${error?.message ?? "未知错误"}`
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import type { RootState } from "../../../app/store";
|
|
2
|
+
import { buildNoloTableQueryRequest } from "../../../agent-runtime/noloWorkspaceTools";
|
|
3
|
+
import {
|
|
4
|
+
applyRowFilters,
|
|
5
|
+
formatKnownColumns,
|
|
6
|
+
normalizeRowValues,
|
|
7
|
+
pickRowColumns,
|
|
8
|
+
sortRows,
|
|
9
|
+
type RowFilters,
|
|
10
|
+
} from "../../../render/table/toolValueUtils";
|
|
11
|
+
import { buildNewRow, ensureRowsLoaded, loadTableMetaOrThrow, patchRecord, resolveRowOrThrow, resolveTableIdentity, writeRow } from "./toolShared";
|
|
12
|
+
|
|
13
|
+
const toPreviewJson = (value: unknown, maxLength = 600): string => {
|
|
14
|
+
try {
|
|
15
|
+
const json = JSON.stringify(value, null, 2);
|
|
16
|
+
if (json.length <= maxLength) return json;
|
|
17
|
+
return `${json.slice(0, maxLength)}\n…(已截断)…`;
|
|
18
|
+
} catch {
|
|
19
|
+
return "[无法序列化为 JSON]";
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const selectCurrentUserId = (state: RootState) =>
|
|
24
|
+
typeof state.auth?.currentUser?.userId === "string"
|
|
25
|
+
? state.auth.currentUser.userId
|
|
26
|
+
: undefined;
|
|
27
|
+
|
|
28
|
+
const normalizeTableQueryArgs = (args: any, thunkApi: any) => {
|
|
29
|
+
const state = thunkApi.getState() as RootState;
|
|
30
|
+
return buildNoloTableQueryRequest(args ?? {}, selectCurrentUserId(state)) ?? args;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const requireTableIdentity = (args: { tenantId?: string; tableId?: string }, thunkApi: any) => {
|
|
34
|
+
const state = thunkApi.getState() as RootState;
|
|
35
|
+
const { tenantId, tableId } = resolveTableIdentity(args, state);
|
|
36
|
+
if (!tenantId || !tableId) {
|
|
37
|
+
throw new Error("需要显式提供 tenantId 和 tableId,或在已打开的表页面中调用。");
|
|
38
|
+
}
|
|
39
|
+
return { tenantId, tableId };
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const queryTableRowsFunctionSchema = {
|
|
43
|
+
name: "queryTableRows",
|
|
44
|
+
description: "查询指定表中的行,支持简单字段过滤、排序、分页和返回指定列。",
|
|
45
|
+
parameters: {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {
|
|
48
|
+
tenantId: { type: "string", description: "租户 ID。聊天场景中必须显式传入。" },
|
|
49
|
+
tableId: { type: "string", description: "表 ID。聊天场景中必须显式传入。" },
|
|
50
|
+
table: { type: "string", description: "表 ID 或 meta-tenantId-tableId;兼容 Nolo CLI 参数。" },
|
|
51
|
+
metaKey: { type: "string", description: "表 meta key;兼容 table。" },
|
|
52
|
+
row: { type: "string", description: "可选 rowId 或 row-* dbKey,只查一行。" },
|
|
53
|
+
filters: {
|
|
54
|
+
type: "object",
|
|
55
|
+
description: "按列名做精确匹配过滤,例如 {\"status\":\"todo\"}。",
|
|
56
|
+
},
|
|
57
|
+
columns: {
|
|
58
|
+
type: "array",
|
|
59
|
+
items: { type: "string" },
|
|
60
|
+
description: "可选:只返回这些列。",
|
|
61
|
+
},
|
|
62
|
+
limit: { type: "number", description: "最多返回多少行,默认 20,最大 200。" },
|
|
63
|
+
offset: { type: "number", description: "从第几行开始返回,默认 0。" },
|
|
64
|
+
includeBaseFields: {
|
|
65
|
+
type: "boolean",
|
|
66
|
+
description: "配合 columns 使用。设为 false 时不额外返回 dbKey/rowId/tenantId/tableId/createdAt/updatedAt,适合任务表概览。",
|
|
67
|
+
},
|
|
68
|
+
sortBy: { type: "string", description: "排序字段,默认 updatedAt。" },
|
|
69
|
+
sortOrder: {
|
|
70
|
+
type: "string",
|
|
71
|
+
enum: ["asc", "desc"],
|
|
72
|
+
description: "排序方向,默认 desc。",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export async function queryTableRowsFunc(args: any, thunkApi: any) {
|
|
79
|
+
args = normalizeTableQueryArgs(args, thunkApi);
|
|
80
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
81
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
82
|
+
const rows = await ensureRowsLoaded(thunkApi, tenantId, tableId);
|
|
83
|
+
const filters = (args?.filters ?? {}) as RowFilters;
|
|
84
|
+
const limit = Math.min(Math.max(Number(args?.limit ?? 20), 1), 200);
|
|
85
|
+
const offset = Math.max(Number(args?.offset ?? 0), 0);
|
|
86
|
+
const sortBy = typeof args?.sortBy === "string" && args.sortBy.trim() ? args.sortBy.trim() : "updatedAt";
|
|
87
|
+
const sortOrder = args?.sortOrder === "asc" ? "asc" : "desc";
|
|
88
|
+
const columns = Array.isArray(args?.columns)
|
|
89
|
+
? args.columns.filter((value: unknown): value is string => typeof value === "string" && value.trim().length > 0)
|
|
90
|
+
: undefined;
|
|
91
|
+
const includeBaseFields = args?.includeBaseFields !== false;
|
|
92
|
+
|
|
93
|
+
const filtered = applyRowFilters(rows, filters);
|
|
94
|
+
const sorted = sortRows(filtered, sortBy, sortOrder);
|
|
95
|
+
const page = sorted.slice(offset, offset + limit);
|
|
96
|
+
const items = columns ? page.map((row) => pickRowColumns(row, columns, { includeBaseFields })) : page;
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
rawData: {
|
|
100
|
+
tenantId,
|
|
101
|
+
tableId,
|
|
102
|
+
total: filtered.length,
|
|
103
|
+
limit,
|
|
104
|
+
offset,
|
|
105
|
+
items,
|
|
106
|
+
},
|
|
107
|
+
displayData:
|
|
108
|
+
`在表「${tableMeta.displayName || tableId}」中查询到 ${filtered.length} 行,当前返回 ${items.length} 行。\n` +
|
|
109
|
+
`字段:${formatKnownColumns(tableMeta)}\n\n` +
|
|
110
|
+
`${toPreviewJson(items)}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const updateTableRowFunctionSchema = {
|
|
115
|
+
name: "updateTableRow",
|
|
116
|
+
description: "按 rowId 或 dbKey 更新指定表中的一行数据,只修改 changes 中提供的字段。",
|
|
117
|
+
parameters: {
|
|
118
|
+
type: "object",
|
|
119
|
+
properties: {
|
|
120
|
+
tenantId: { type: "string" },
|
|
121
|
+
tableId: { type: "string" },
|
|
122
|
+
rowId: { type: "string", description: "要更新的行 ID。" },
|
|
123
|
+
dbKey: { type: "string", description: "要更新的行 dbKey。rowId 与 dbKey 二选一即可。" },
|
|
124
|
+
changes: {
|
|
125
|
+
type: "object",
|
|
126
|
+
description: "要修改的字段集合,例如 {\"status\":\"done\"}。",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
required: ["changes"],
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export async function updateTableRowFunc(args: any, thunkApi: any) {
|
|
134
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
135
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
136
|
+
const targetRow = await resolveRowOrThrow(thunkApi, { tenantId, tableId, rowId: args?.rowId, dbKey: args?.dbKey });
|
|
137
|
+
const changes = args?.changes;
|
|
138
|
+
|
|
139
|
+
if (!changes || typeof changes !== "object" || Array.isArray(changes)) {
|
|
140
|
+
throw new Error("updateTableRow.changes 必须是对象。");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const normalized = normalizeRowValues(tableMeta.columns, changes, { mode: "update" });
|
|
144
|
+
if (normalized.errors.length > 0) {
|
|
145
|
+
throw new Error(normalized.errors.join("\n"));
|
|
146
|
+
}
|
|
147
|
+
if (Object.keys(normalized.sanitizedValues).length === 0) {
|
|
148
|
+
throw new Error(
|
|
149
|
+
`updateTableRow 没有可更新的有效字段。已知字段:${formatKnownColumns(tableMeta)}`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const updatedAt = new Date().toISOString();
|
|
154
|
+
const updated = await patchRecord(thunkApi, targetRow.dbKey, {
|
|
155
|
+
...normalized.sanitizedValues,
|
|
156
|
+
updatedAt,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const ignoredInfo =
|
|
160
|
+
normalized.ignoredColumns.length > 0
|
|
161
|
+
? `\n\n注意:以下字段已忽略:${normalized.ignoredColumns.join(", ")}`
|
|
162
|
+
: "";
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
rawData: updated,
|
|
166
|
+
displayData:
|
|
167
|
+
`已更新表「${tableMeta.displayName || tableId}」中的行 ${targetRow.rowId}。${ignoredInfo}\n\n` +
|
|
168
|
+
`${toPreviewJson(updated)}`,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export const deleteTableRowFunctionSchema = {
|
|
173
|
+
name: "deleteTableRow",
|
|
174
|
+
description: "删除指定表中的一行数据(软删除)。",
|
|
175
|
+
parameters: {
|
|
176
|
+
type: "object",
|
|
177
|
+
properties: {
|
|
178
|
+
tenantId: { type: "string" },
|
|
179
|
+
tableId: { type: "string" },
|
|
180
|
+
rowId: { type: "string" },
|
|
181
|
+
dbKey: { type: "string" },
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export async function deleteTableRowFunc(args: any, thunkApi: any) {
|
|
187
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
188
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
189
|
+
const targetRow = await resolveRowOrThrow(thunkApi, { tenantId, tableId, rowId: args?.rowId, dbKey: args?.dbKey });
|
|
190
|
+
const updatedAt = new Date().toISOString();
|
|
191
|
+
const deleted = await patchRecord(thunkApi, targetRow.dbKey, {
|
|
192
|
+
deletedAt: updatedAt,
|
|
193
|
+
updatedAt,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
rawData: deleted,
|
|
198
|
+
displayData: `已从表「${tableMeta.displayName || tableId}」中删除行 ${targetRow.rowId}。`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export const addTableRowsFunctionSchema = {
|
|
203
|
+
name: "addTableRows",
|
|
204
|
+
description: "批量向指定表中新增多行数据。",
|
|
205
|
+
parameters: {
|
|
206
|
+
type: "object",
|
|
207
|
+
properties: {
|
|
208
|
+
tenantId: { type: "string" },
|
|
209
|
+
tableId: { type: "string" },
|
|
210
|
+
rows: {
|
|
211
|
+
type: "array",
|
|
212
|
+
items: { type: "object" },
|
|
213
|
+
description: "每一项都是一行数据对象,key 必须是表中的列名。",
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
required: ["rows"],
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export async function addTableRowsFunc(args: any, thunkApi: any) {
|
|
221
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
222
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
223
|
+
const rows = Array.isArray(args?.rows) ? args.rows : [];
|
|
224
|
+
if (rows.length === 0) {
|
|
225
|
+
throw new Error("addTableRows.rows 至少需要包含一行。");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const createdRows: any[] = [];
|
|
229
|
+
const ignoredColumns = new Set<string>();
|
|
230
|
+
for (const row of rows) {
|
|
231
|
+
if (!row || typeof row !== "object" || Array.isArray(row)) {
|
|
232
|
+
throw new Error("addTableRows.rows 中的每一项都必须是对象。");
|
|
233
|
+
}
|
|
234
|
+
const normalized = normalizeRowValues(tableMeta.columns, row, { mode: "create" });
|
|
235
|
+
if (normalized.errors.length > 0) {
|
|
236
|
+
throw new Error(normalized.errors.join("\n"));
|
|
237
|
+
}
|
|
238
|
+
if (Object.keys(normalized.sanitizedValues).length === 0) {
|
|
239
|
+
throw new Error(`存在一行没有任何有效字段。已知字段:${formatKnownColumns(tableMeta)}`);
|
|
240
|
+
}
|
|
241
|
+
normalized.ignoredColumns.forEach((column) => ignoredColumns.add(column));
|
|
242
|
+
const created = buildNewRow(tenantId, tableId, normalized.sanitizedValues);
|
|
243
|
+
await writeRow(thunkApi, created);
|
|
244
|
+
createdRows.push(created);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const ignoredInfo =
|
|
248
|
+
ignoredColumns.size > 0 ? `\n\n注意:以下字段已忽略:${Array.from(ignoredColumns).join(", ")}` : "";
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
rawData: {
|
|
252
|
+
count: createdRows.length,
|
|
253
|
+
items: createdRows,
|
|
254
|
+
},
|
|
255
|
+
displayData:
|
|
256
|
+
`已向表「${tableMeta.displayName || tableId}」批量新增 ${createdRows.length} 行。${ignoredInfo}\n\n` +
|
|
257
|
+
`${toPreviewJson(createdRows.slice(0, 10))}`,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export const updateTableRowsFunctionSchema = {
|
|
262
|
+
name: "updateTableRows",
|
|
263
|
+
description: "批量更新多行数据。每项都需要 rowId 或 dbKey,以及 changes。",
|
|
264
|
+
parameters: {
|
|
265
|
+
type: "object",
|
|
266
|
+
properties: {
|
|
267
|
+
tenantId: { type: "string" },
|
|
268
|
+
tableId: { type: "string" },
|
|
269
|
+
updates: {
|
|
270
|
+
type: "array",
|
|
271
|
+
items: {
|
|
272
|
+
type: "object",
|
|
273
|
+
properties: {
|
|
274
|
+
rowId: { type: "string" },
|
|
275
|
+
dbKey: { type: "string" },
|
|
276
|
+
changes: { type: "object" },
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
required: ["updates"],
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
export async function updateTableRowsFunc(args: any, thunkApi: any) {
|
|
286
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
287
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
288
|
+
const updates = Array.isArray(args?.updates) ? args.updates : [];
|
|
289
|
+
if (updates.length === 0) {
|
|
290
|
+
throw new Error("updateTableRows.updates 至少需要包含一项。");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const results: any[] = [];
|
|
294
|
+
const ignoredColumns = new Set<string>();
|
|
295
|
+
for (const item of updates) {
|
|
296
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
297
|
+
throw new Error("updateTableRows.updates 中的每一项都必须是对象。");
|
|
298
|
+
}
|
|
299
|
+
const targetRow = await resolveRowOrThrow(thunkApi, {
|
|
300
|
+
tenantId,
|
|
301
|
+
tableId,
|
|
302
|
+
rowId: item.rowId,
|
|
303
|
+
dbKey: item.dbKey,
|
|
304
|
+
});
|
|
305
|
+
const normalized = normalizeRowValues(tableMeta.columns, item.changes ?? {}, { mode: "update" });
|
|
306
|
+
if (normalized.errors.length > 0) {
|
|
307
|
+
throw new Error(normalized.errors.join("\n"));
|
|
308
|
+
}
|
|
309
|
+
if (Object.keys(normalized.sanitizedValues).length === 0) {
|
|
310
|
+
throw new Error(`行 ${targetRow.rowId} 没有可更新的有效字段。`);
|
|
311
|
+
}
|
|
312
|
+
normalized.ignoredColumns.forEach((column) => ignoredColumns.add(column));
|
|
313
|
+
const updated = await patchRecord(thunkApi, targetRow.dbKey, {
|
|
314
|
+
...normalized.sanitizedValues,
|
|
315
|
+
updatedAt: new Date().toISOString(),
|
|
316
|
+
});
|
|
317
|
+
results.push(updated);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const ignoredInfo =
|
|
321
|
+
ignoredColumns.size > 0 ? `\n\n注意:以下字段已忽略:${Array.from(ignoredColumns).join(", ")}` : "";
|
|
322
|
+
|
|
323
|
+
return {
|
|
324
|
+
rawData: {
|
|
325
|
+
count: results.length,
|
|
326
|
+
items: results,
|
|
327
|
+
},
|
|
328
|
+
displayData:
|
|
329
|
+
`已批量更新表「${tableMeta.displayName || tableId}」中的 ${results.length} 行。${ignoredInfo}`,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export const deleteTableRowsFunctionSchema = {
|
|
334
|
+
name: "deleteTableRows",
|
|
335
|
+
description: "批量删除多行数据(软删除)。",
|
|
336
|
+
parameters: {
|
|
337
|
+
type: "object",
|
|
338
|
+
properties: {
|
|
339
|
+
tenantId: { type: "string" },
|
|
340
|
+
tableId: { type: "string" },
|
|
341
|
+
rowIds: {
|
|
342
|
+
type: "array",
|
|
343
|
+
items: { type: "string" },
|
|
344
|
+
description: "要删除的 rowId 列表。",
|
|
345
|
+
},
|
|
346
|
+
dbKeys: {
|
|
347
|
+
type: "array",
|
|
348
|
+
items: { type: "string" },
|
|
349
|
+
description: "要删除的 dbKey 列表。",
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
export async function deleteTableRowsFunc(args: any, thunkApi: any) {
|
|
356
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
357
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
358
|
+
const rowIds = Array.isArray(args?.rowIds) ? args.rowIds : [];
|
|
359
|
+
const dbKeys = Array.isArray(args?.dbKeys) ? args.dbKeys : [];
|
|
360
|
+
const targets = [
|
|
361
|
+
...rowIds.map((rowId: string) => ({ rowId })),
|
|
362
|
+
...dbKeys.map((dbKey: string) => ({ dbKey })),
|
|
363
|
+
];
|
|
364
|
+
|
|
365
|
+
if (targets.length === 0) {
|
|
366
|
+
throw new Error("deleteTableRows 需要至少提供一个 rowId 或 dbKey。");
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const results = [];
|
|
370
|
+
for (const target of targets) {
|
|
371
|
+
const row = await resolveRowOrThrow(thunkApi, { tenantId, tableId, rowId: target.rowId, dbKey: target.dbKey });
|
|
372
|
+
const deleted = await patchRecord(thunkApi, row.dbKey, {
|
|
373
|
+
deletedAt: new Date().toISOString(),
|
|
374
|
+
updatedAt: new Date().toISOString(),
|
|
375
|
+
});
|
|
376
|
+
results.push(deleted);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return {
|
|
380
|
+
rawData: {
|
|
381
|
+
count: results.length,
|
|
382
|
+
items: results,
|
|
383
|
+
},
|
|
384
|
+
displayData: `已从表「${tableMeta.displayName || tableId}」中批量删除 ${results.length} 行。`,
|
|
385
|
+
};
|
|
386
|
+
}
|