nolo-cli 0.1.40 → 0.1.42
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 +27 -12
- package/agent-runtime/agentThread.ts +222 -0
- package/agent-runtime/agentThreadAdmission.ts +74 -0
- package/agent-runtime/dialogWritePlan.ts +42 -0
- package/agent-runtime/hostAdapter.ts +1 -0
- package/agent-runtime/hybridRecordStore.ts +5 -3
- package/agent-runtime/index.ts +43 -0
- package/agent-runtime/localLoop.ts +31 -2
- package/agent-runtime/localToolPolicy.ts +1 -0
- package/agent-runtime/localWorkspaceTools.ts +1258 -78
- package/agent-runtime/noloWorkspaceTools.ts +20 -1
- package/agent-runtime/runtimeToolPolicy.ts +1 -5
- package/agent-runtime/runtimeToolSurface.ts +1 -0
- package/agentAliases.ts +29 -9
- package/agentInternalCommandEntries.ts +11 -3
- package/agentMachineCommands.ts +1 -0
- package/agentRecordCommands.ts +2 -2
- package/agentRecordHelpers.ts +59 -6
- package/agentRunCommand.ts +84 -19
- 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 +599 -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 +264 -46
- 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 +2135 -0
- package/ai/agent/streamAgentChatTurnUtils.ts +923 -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 +1165 -0
- package/ai/chat/accumulateToolCallChunks.ts +126 -0
- package/ai/chat/fetchUtils.ts +143 -0
- package/ai/chat/inlineImageUrlsForCustomProvider.ts +122 -0
- package/ai/chat/parseApiError.ts +67 -0
- package/ai/chat/parseMultilineSSE.ts +95 -0
- package/ai/chat/sendOpenAICompletionsRequest.ts +921 -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 +22 -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 +31 -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/policy.ts +49 -0
- package/ai/memory/queryShared.ts +167 -0
- package/ai/memory/recentRelationshipRecap.ts +251 -0
- package/ai/memory/remember.ts +111 -0
- package/ai/memory/scope.ts +74 -0
- package/ai/memory/store.ts +20 -0
- package/ai/memory/storeShared.ts +76 -0
- package/ai/memory/types.ts +52 -0
- package/ai/memory/understanding.ts +341 -0
- package/ai/memory/understandingGreeting.ts +264 -0
- package/ai/policy/personalizationDialog.ts +333 -0
- package/ai/policy/runtimePolicy.ts +526 -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 +214 -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 +54 -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 +2290 -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 +193 -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 +638 -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 +326 -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/toolPacks.ts +19 -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 +58 -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/deletedFavoriteProjection.ts +31 -0
- package/app/favorite/favoriteSlice.ts +690 -0
- package/app/favorite/type.ts +43 -0
- package/app/hooks/deleteDbKey.ts +254 -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 +2206 -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 +118 -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 +75 -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 +78 -0
- package/auth/authSlice.ts +531 -0
- package/auth/client/loginRequest.ts +14 -0
- package/auth/resetAuthScopedClientState.ts +27 -0
- package/auth/routes.ts +183 -0
- package/auth/token.ts +63 -0
- package/auth/types.ts +40 -0
- package/chat/chat.locale.ts +817 -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 +202 -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/dialogAttachmentCleanup.ts +135 -0
- package/chat/dialog/dialogSlice.ts +985 -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/activityCompletion.ts +97 -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/imagePayloadPersistence.ts +22 -0
- package/chat/messages/messageAgent.ts +8 -0
- package/chat/messages/messageContent.ts +203 -0
- package/chat/messages/messageContract.ts +88 -0
- package/chat/messages/messageSlice.ts +1386 -0
- package/chat/messages/toolThunks.ts +646 -0
- package/chat/messages/types.ts +8 -1
- package/chat/messages/web/toolDisplayName.ts +686 -0
- package/cli/agentAliases.ts +29 -9
- package/cli/agentInternalCommandEntries.ts +11 -3
- package/cli/agentMachineCommands.ts +1 -0
- package/cli/agentRecordCommands.ts +2 -2
- package/cli/agentRecordHelpers.ts +59 -6
- package/cli/agentRunCommand.ts +84 -19
- package/cli/client/agentRun.ts +92 -261
- package/cli/client/localRuntimeAdapter.ts +292 -50
- package/cli/commandRegistry.ts +7 -4
- package/cli/dialogAttachmentCleanup.ts +151 -0
- package/cli/dialogCommands.ts +163 -61
- package/cli/dialogInternalCommandEntries.ts +1 -1
- package/cli/docCreateCommands.ts +345 -0
- package/cli/docInternalCommandEntries.ts +11 -0
- package/cli/docPageHelpers.ts +80 -0
- package/cli/docSkillHelpers.ts +67 -0
- package/cli/docSpaceHelpers.ts +46 -0
- package/cli/internalCommandEntries.ts +4 -0
- package/cli/machineCommands.ts +18 -34
- package/cli/memoryCommands.ts +253 -0
- package/cli/memoryInternalCommandEntries.ts +9 -0
- package/cli/qoderUsageProbe.ts +252 -0
- package/cli/scriptCommandEntries.ts +0 -3
- package/cli/secretScan.ts +31 -0
- package/cli/tableCommands.ts +248 -13
- package/cli/workflowInternalCommandEntries.ts +2 -3
- package/client/agentRun.test.ts +119 -83
- package/client/agentRun.ts +92 -261
- package/client/localRuntimeAdapter.test.ts +894 -32
- package/client/localRuntimeAdapter.ts +292 -50
- package/commandRegistry.ts +7 -4
- package/connector-experimental/capabilities.ts +10 -9
- 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 +260 -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/tenantPlacement.ts +57 -0
- package/database/userPreferenceRegister.ts +131 -0
- package/database/utils/ulid.ts +1 -0
- package/dialogAttachmentCleanup.ts +151 -0
- package/dialogCommands.ts +163 -61
- package/dialogInternalCommandEntries.ts +1 -1
- package/docCreateCommands.ts +345 -0
- package/docInternalCommandEntries.ts +11 -0
- package/docPageHelpers.ts +80 -0
- package/docSkillHelpers.ts +67 -0
- package/docSpaceHelpers.ts +46 -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 +271 -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/redaction.ts +68 -0
- package/integrations/xhs-reader/types.ts +277 -0
- package/integrations/xhs-reader/url.ts +80 -0
- package/internalCommandEntries.ts +4 -0
- package/machineCommands.ts +18 -34
- package/memoryCommands.ts +253 -0
- package/memoryInternalCommandEntries.ts +9 -0
- package/package.json +454 -9
- package/qoderUsageProbe.ts +252 -0
- package/render/contentIcon/types.ts +167 -0
- package/render/page/createPageAction.ts +183 -0
- package/render/page/docSlice.ts +495 -0
- package/render/page/types.ts +19 -0
- package/render/table/createTableAction.ts +274 -0
- package/render/table/deleteTableAction.ts +193 -0
- package/render/table/fetchAndCacheTableRows.ts +174 -0
- package/render/table/tableSlice.ts +1167 -0
- package/render/table/toolValueUtils.ts +363 -0
- package/render/table/types.ts +262 -0
- package/render/table/utils/tableSerialization.ts +50 -0
- package/scriptCommandEntries.ts +0 -3
- package/secretScan.ts +31 -0
- package/server/handlers/agentRun/types.ts +105 -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
- package/tableCommands.ts +248 -13
- package/workflowInternalCommandEntries.ts +2 -3
- package/ai/tools/agent/taskRunTool.ts +0 -112
- package/cli/client/taskRunPrompt.ts +0 -27
- package/cli/taskRunCommand.ts +0 -265
- package/client/taskRunPrompt.ts +0 -27
- package/taskRunCommand.ts +0 -265
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { patchRecord, loadTableMetaOrThrow, ensureRowsLoaded, resolveTableIdentity } from "./toolShared";
|
|
2
|
+
import type { RootState } from "../../../app/store";
|
|
3
|
+
import type { TableColumn } from "../../../render/table/types";
|
|
4
|
+
import { ulid } from "../../../database/utils/ulid";
|
|
5
|
+
|
|
6
|
+
const requireTableIdentity = (args: { tenantId?: string; tableId?: string }, thunkApi: any) => {
|
|
7
|
+
const state = thunkApi.getState() as RootState;
|
|
8
|
+
const { tenantId, tableId } = resolveTableIdentity(args, state);
|
|
9
|
+
if (!tenantId || !tableId) {
|
|
10
|
+
throw new Error("需要显式提供 tenantId 和 tableId,或在已打开的表页面中调用。");
|
|
11
|
+
}
|
|
12
|
+
return { tenantId, tableId };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const ensureColumnName = (name: unknown): string => {
|
|
16
|
+
if (typeof name !== "string" || !name.trim()) {
|
|
17
|
+
throw new Error("列名不能为空。");
|
|
18
|
+
}
|
|
19
|
+
return name.trim();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const normalizeOptions = (options: unknown): string[] | undefined => {
|
|
23
|
+
if (!Array.isArray(options)) return undefined;
|
|
24
|
+
const normalized = options
|
|
25
|
+
.map((value) => (typeof value === "string" ? value.trim() : ""))
|
|
26
|
+
.filter(Boolean);
|
|
27
|
+
return normalized.length > 0 ? normalized : undefined;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const addTableColumnFunctionSchema = {
|
|
31
|
+
name: "addTableColumn",
|
|
32
|
+
description: "向指定表中新增一列。",
|
|
33
|
+
parameters: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
tenantId: { type: "string" },
|
|
37
|
+
tableId: { type: "string" },
|
|
38
|
+
name: { type: "string" },
|
|
39
|
+
label: { type: "string" },
|
|
40
|
+
type: {
|
|
41
|
+
type: "string",
|
|
42
|
+
enum: ["text", "number", "boolean", "date", "datetime", "select", "multi_select"],
|
|
43
|
+
},
|
|
44
|
+
description: { type: "string" },
|
|
45
|
+
required: { type: "boolean" },
|
|
46
|
+
options: { type: "array", items: { type: "string" } },
|
|
47
|
+
},
|
|
48
|
+
required: ["name"],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export async function addTableColumnFunc(args: any, thunkApi: any) {
|
|
53
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
54
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
55
|
+
const name = ensureColumnName(args?.name);
|
|
56
|
+
if (tableMeta.columns.some((column) => column.name === name)) {
|
|
57
|
+
throw new Error(`字段 ${name} 已存在。`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const column: TableColumn = {
|
|
61
|
+
id: ulid(),
|
|
62
|
+
name,
|
|
63
|
+
label: typeof args?.label === "string" && args.label.trim() ? args.label.trim() : name,
|
|
64
|
+
type: typeof args?.type === "string" ? args.type : "text",
|
|
65
|
+
description: typeof args?.description === "string" && args.description.trim() ? args.description.trim() : undefined,
|
|
66
|
+
required: typeof args?.required === "boolean" ? args.required : undefined,
|
|
67
|
+
options: normalizeOptions(args?.options),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const updatedAt = new Date().toISOString();
|
|
71
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
72
|
+
columns: [...tableMeta.columns, column],
|
|
73
|
+
updatedAt,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
rawData: updated,
|
|
78
|
+
displayData: `已向表「${tableMeta.displayName || tableId}」新增字段 ${name}。`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const deleteTableColumnFunctionSchema = {
|
|
83
|
+
name: "deleteTableColumn",
|
|
84
|
+
description: "删除指定表中的某一列,并同步从已有行中移除该字段。",
|
|
85
|
+
parameters: {
|
|
86
|
+
type: "object",
|
|
87
|
+
properties: {
|
|
88
|
+
tenantId: { type: "string" },
|
|
89
|
+
tableId: { type: "string" },
|
|
90
|
+
columnName: { type: "string" },
|
|
91
|
+
},
|
|
92
|
+
required: ["columnName"],
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export async function deleteTableColumnFunc(args: any, thunkApi: any) {
|
|
97
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
98
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
99
|
+
const columnName = ensureColumnName(args?.columnName);
|
|
100
|
+
if (!tableMeta.columns.some((column) => column.name === columnName)) {
|
|
101
|
+
throw new Error(`字段 ${columnName} 不存在。`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const rows = await ensureRowsLoaded(thunkApi, tenantId, tableId);
|
|
105
|
+
const updatedAt = new Date().toISOString();
|
|
106
|
+
for (const row of rows) {
|
|
107
|
+
if (Object.prototype.hasOwnProperty.call(row, columnName)) {
|
|
108
|
+
await patchRecord(thunkApi, row.dbKey, {
|
|
109
|
+
[columnName]: null,
|
|
110
|
+
updatedAt,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
116
|
+
columns: tableMeta.columns.filter((column) => column.name !== columnName),
|
|
117
|
+
updatedAt,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
rawData: updated,
|
|
122
|
+
displayData: `已从表「${tableMeta.displayName || tableId}」删除字段 ${columnName}。`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const renameTableColumnFunctionSchema = {
|
|
127
|
+
name: "renameTableColumn",
|
|
128
|
+
description: "修改表字段的 machine name,并同步迁移所有已有行的数据 key。",
|
|
129
|
+
parameters: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: {
|
|
132
|
+
tenantId: { type: "string" },
|
|
133
|
+
tableId: { type: "string" },
|
|
134
|
+
oldName: { type: "string" },
|
|
135
|
+
newName: { type: "string" },
|
|
136
|
+
},
|
|
137
|
+
required: ["oldName", "newName"],
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export async function renameTableColumnFunc(args: any, thunkApi: any) {
|
|
142
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
143
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
144
|
+
const oldName = ensureColumnName(args?.oldName);
|
|
145
|
+
const newName = ensureColumnName(args?.newName);
|
|
146
|
+
|
|
147
|
+
if (!tableMeta.columns.some((column) => column.name === oldName)) {
|
|
148
|
+
throw new Error(`字段 ${oldName} 不存在。`);
|
|
149
|
+
}
|
|
150
|
+
if (tableMeta.columns.some((column) => column.name === newName)) {
|
|
151
|
+
throw new Error(`字段 ${newName} 已存在。`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const rows = await ensureRowsLoaded(thunkApi, tenantId, tableId);
|
|
155
|
+
const updatedAt = new Date().toISOString();
|
|
156
|
+
for (const row of rows) {
|
|
157
|
+
if (Object.prototype.hasOwnProperty.call(row, oldName)) {
|
|
158
|
+
await patchRecord(thunkApi, row.dbKey, {
|
|
159
|
+
[newName]: row[oldName],
|
|
160
|
+
[oldName]: null,
|
|
161
|
+
updatedAt,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
167
|
+
columns: tableMeta.columns.map((column) =>
|
|
168
|
+
column.name === oldName ? { ...column, name: newName } : column
|
|
169
|
+
),
|
|
170
|
+
updatedAt,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
rawData: updated,
|
|
175
|
+
displayData: `已将表「${tableMeta.displayName || tableId}」中的字段 ${oldName} 重命名为 ${newName}。`,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export const renameTableColumnLabelFunctionSchema = {
|
|
180
|
+
name: "renameTableColumnLabel",
|
|
181
|
+
description: "修改表字段的显示名,不改变行数据里的 key。",
|
|
182
|
+
parameters: {
|
|
183
|
+
type: "object",
|
|
184
|
+
properties: {
|
|
185
|
+
tenantId: { type: "string" },
|
|
186
|
+
tableId: { type: "string" },
|
|
187
|
+
columnName: { type: "string" },
|
|
188
|
+
newLabel: { type: "string" },
|
|
189
|
+
},
|
|
190
|
+
required: ["columnName", "newLabel"],
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export async function renameTableColumnLabelFunc(args: any, thunkApi: any) {
|
|
195
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
196
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
197
|
+
const columnName = ensureColumnName(args?.columnName);
|
|
198
|
+
const newLabel = ensureColumnName(args?.newLabel);
|
|
199
|
+
|
|
200
|
+
if (!tableMeta.columns.some((column) => column.name === columnName)) {
|
|
201
|
+
throw new Error(`字段 ${columnName} 不存在。`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
205
|
+
columns: tableMeta.columns.map((column) =>
|
|
206
|
+
column.name === columnName ? { ...column, label: newLabel } : column
|
|
207
|
+
),
|
|
208
|
+
updatedAt: new Date().toISOString(),
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
rawData: updated,
|
|
213
|
+
displayData: `已将字段 ${columnName} 的显示名更新为 ${newLabel}。`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export const renameTableFunctionSchema = {
|
|
218
|
+
name: "renameTable",
|
|
219
|
+
description: "更新表的显示名称。",
|
|
220
|
+
parameters: {
|
|
221
|
+
type: "object",
|
|
222
|
+
properties: {
|
|
223
|
+
tenantId: { type: "string" },
|
|
224
|
+
tableId: { type: "string" },
|
|
225
|
+
newName: { type: "string" },
|
|
226
|
+
},
|
|
227
|
+
required: ["newName"],
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export async function renameTableFunc(args: any, thunkApi: any) {
|
|
232
|
+
const { tenantId, tableId } = requireTableIdentity(args, thunkApi);
|
|
233
|
+
const tableMeta = await loadTableMetaOrThrow(thunkApi, tenantId, tableId);
|
|
234
|
+
const newName = ensureColumnName(args?.newName);
|
|
235
|
+
const updated = await patchRecord(thunkApi, tableMeta.dbKey, {
|
|
236
|
+
displayName: newName,
|
|
237
|
+
updatedAt: new Date().toISOString(),
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
rawData: updated,
|
|
242
|
+
displayData: `已将表名更新为「${newName}」。`,
|
|
243
|
+
};
|
|
244
|
+
}
|