nolo-cli 0.1.26 → 0.1.30
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/agent-runtime/dialogStatus.ts +139 -0
- package/agent-runtime/index.ts +8 -0
- package/agentAliases.ts +11 -14
- package/agentCommandSupport.ts +2 -2
- package/agentCreateCustomCommands.ts +278 -0
- package/agentDialogsCommands.ts +227 -0
- package/agentDoctorCommands.ts +203 -0
- package/agentInternalCommandEntries.ts +11 -2
- package/agentListCommands.ts +28 -19
- package/agentMachineCommands.ts +103 -29
- package/agentPullCommand.ts +9 -17
- package/agentRecordCommands.ts +4 -2
- package/agentRecordHelpers.ts +69 -8
- package/agentRunCommand.ts +37 -416
- package/agentRunLocalWorkspace.ts +182 -0
- package/agentRunParsing.ts +279 -0
- package/agentSuperviseCommands.ts +8 -0
- package/agentUnpublishCommands.ts +113 -0
- package/ai/agent/_executeModel.ts +14 -14
- package/ai/agent/agentSlice.ts +8 -8
- package/ai/agent/appWorkingMemory.ts +2 -2
- package/ai/agent/avatarUtils.ts +1 -1
- package/ai/agent/buildEditingContext.ts +3 -3
- package/ai/agent/buildSystemPrompt.ts +16 -7
- package/ai/agent/cleanAgentMessages.ts +1 -1
- package/ai/agent/cliChatClient.ts +3 -3
- package/ai/agent/cliExecutor.ts +4 -2
- package/ai/agent/createAgentSchema.ts +1 -1
- package/ai/agent/executeToolCall.ts +2 -2
- package/ai/agent/fetchAgentContexts.ts +3 -3
- package/ai/agent/getFullChatContextKeys.ts +4 -4
- package/ai/agent/guidedCreation/draft.ts +1 -1
- package/ai/agent/guidedCreation/types.ts +1 -1
- package/ai/agent/hooks/fetchPublicAgents.ts +6 -6
- package/ai/agent/hooks/useAgentConfig.ts +49 -21
- package/ai/agent/hooks/useAgentDialog.ts +1 -1
- package/ai/agent/hooks/useAgentFormValidation.ts +9 -9
- package/ai/agent/hooks/usePublicAgents.ts +9 -9
- package/ai/agent/persistMessageWithFixedId.ts +4 -4
- package/ai/agent/planSlice.ts +1 -1
- package/ai/agent/referenceUtils.ts +4 -4
- package/ai/agent/runAgentBackground.ts +3 -3
- package/ai/agent/runAgentClientLoop.ts +12 -12
- package/ai/agent/runtimeGuidance.ts +1 -1
- package/ai/agent/server/fetchPublicAgents.ts +6 -6
- package/ai/agent/startParallelAgentStreams.ts +12 -12
- package/ai/agent/streamAgentChatTurn.ts +21 -21
- package/ai/agent/streamAgentChatTurnUtils.ts +22 -22
- package/ai/agent/utils/imageOutput.ts +2 -2
- package/ai/agent/utils/publicImageAgentMode.ts +1 -1
- package/ai/agent/utils/sortUtils.ts +1 -1
- package/ai/agent/web/useGuidedAgentCreation.ts +29 -8
- package/ai/chat/fetchUtils.native.ts +2 -2
- package/ai/chat/fetchUtils.ts +2 -2
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +11 -11
- package/ai/chat/sendOpenAICompletionsRequest.ts +12 -12
- package/ai/chat/sendOpenAIResponseRequest.ts +14 -14
- package/ai/chat/shouldUseServerProxy.ts +1 -1
- package/ai/chat/updateTotalUsage.ts +1 -1
- package/ai/context/buildReferenceContext.ts +14 -14
- package/ai/context/calculateContextUsage.ts +1 -1
- package/ai/llm/generateRequestBody.ts +3 -3
- package/ai/llm/getPricing.ts +4 -4
- package/ai/llm/hooks/useModelPricing.ts +2 -2
- package/ai/llm/imagePricing.ts +1 -1
- package/ai/llm/models.ts +3 -3
- package/ai/llm/providers.ts +8 -8
- package/ai/memory/capture.ts +1 -1
- package/ai/memory/consolidate.ts +1 -1
- package/ai/memory/delete.ts +2 -2
- package/ai/memory/query.ts +1 -1
- package/ai/memory/queryShared.ts +1 -1
- package/ai/memory/recentRelationshipRecap.ts +2 -2
- package/ai/memory/remember.ts +1 -1
- package/ai/memory/store.ts +1 -1
- package/ai/memory/storeShared.ts +2 -2
- package/ai/memory/understanding.ts +1 -1
- package/ai/messages/type.ts +1 -1
- package/ai/policy/personalizationDialog.ts +6 -6
- package/ai/policy/runtimePolicy.ts +1 -1
- package/ai/skills/referenceRuntime.ts +1 -1
- package/ai/skills/skillDiagnostics.ts +1 -1
- package/ai/skills/skillDocBuilder.ts +1 -1
- package/ai/skills/skillReferenceSummary.ts +1 -1
- package/ai/skills/skillSummaryMarker.ts +1 -1
- package/ai/token/calculatePrice.ts +5 -5
- package/ai/token/db.ts +3 -3
- package/ai/token/externalToolCost.ts +4 -4
- package/ai/token/hooks/useRecords.ts +3 -3
- package/ai/token/modelUsageQuery.ts +2 -2
- package/ai/token/openaiImageGenerationUsage.ts +2 -2
- package/ai/token/prepareTokenUsageData.ts +1 -1
- package/ai/token/query.ts +1 -1
- package/ai/token/queryUserTokens.ts +1 -1
- package/ai/token/resolveBillingTarget.ts +1 -1
- package/ai/token/saveTokenRecord.ts +5 -5
- package/ai/token/serverDialogProjection.ts +4 -4
- package/ai/token/serverTokenWriter.ts +3 -3
- package/ai/token/tokenThunks.ts +1 -1
- package/ai/tools/agent/agentUpdateShared.ts +4 -4
- package/ai/tools/agent/callAgentTool.ts +3 -3
- package/ai/tools/agent/createAgentTool.ts +12 -12
- package/ai/tools/agent/createDialogTool.ts +3 -3
- package/ai/tools/agent/parallelBudget.ts +2 -2
- package/ai/tools/agent/prepareAgentDraftTool.ts +18 -4
- package/ai/tools/agent/presets/appBuilderPreset.ts +1 -1
- package/ai/tools/agent/runLlmTool.ts +1 -1
- package/ai/tools/agent/skillAgentPreset.ts +6 -6
- package/ai/tools/agent/updateAgentTool.ts +4 -4
- package/ai/tools/agent/updateSelfTool.ts +8 -8
- package/ai/tools/appTools.ts +3 -3
- package/ai/tools/category/createCategoryTool.ts +2 -2
- package/ai/tools/category/queryContentsByCategoryTool.ts +2 -2
- package/ai/tools/category/updateContentCategoryTool.ts +2 -2
- package/ai/tools/createDocTool.ts +3 -3
- package/ai/tools/createPlanTool.ts +9 -9
- package/ai/tools/createSkillDocTool.ts +4 -4
- package/ai/tools/createWorkflowTool.ts +2 -2
- package/ai/tools/deleteSpacesTool.ts +5 -5
- package/ai/tools/deleteSpacesToolModel.ts +1 -1
- package/ai/tools/doctorSkillTool.ts +3 -3
- package/ai/tools/evalSkillTool.ts +3 -3
- package/ai/tools/execShellTool.ts +1 -1
- package/ai/tools/executeSqlTool.ts +1 -1
- package/ai/tools/geminiImagePreviewTool.ts +9 -9
- package/ai/tools/importDataTool.ts +2 -2
- package/ai/tools/importSkillTool.ts +4 -4
- package/ai/tools/index.ts +37 -0
- package/ai/tools/listUserSpacesTool.ts +2 -2
- package/ai/tools/localFilesTool.ts +85 -9
- package/ai/tools/openaiImageTool.ts +9 -9
- package/ai/tools/readDocTool.ts +3 -3
- package/ai/tools/readTool.ts +9 -9
- package/ai/tools/rememberMemoryTool.ts +3 -3
- package/ai/tools/remotionVideoTool.ts +7 -7
- package/ai/tools/searchDialogMessagesTool.ts +2 -2
- package/ai/tools/searchWorkspaceTool.ts +4 -4
- package/ai/tools/table/addTableRowTool.ts +2 -2
- package/ai/tools/table/createTableTool.ts +2 -2
- package/ai/tools/table/rowTools.ts +2 -2
- package/ai/tools/table/schemaTools.ts +3 -3
- package/ai/tools/table/shareTableTool.ts +5 -5
- package/ai/tools/table/toolShared.ts +6 -6
- package/ai/tools/toolApiClient.ts +15 -6
- package/ai/tools/toolRunSlice.ts +2 -2
- package/ai/tools/updateContentTitleTool.ts +2 -2
- package/ai/tools/updateDocTool.ts +7 -7
- package/ai/tools/updateUserPreferenceProfileTool.ts +3 -3
- package/ai/workflow/workflowExecutor.ts +3 -3
- package/ai/workflow/workflowSlice.ts +1 -1
- package/app/actions/syncAppRecord.ts +73 -0
- package/app/admin/adminPages.ts +13 -0
- package/app/colors.ts +1 -0
- package/app/constants/animationSets.ts +21 -0
- package/app/constants/appEditor.ts +99 -0
- package/app/constants/clientDownloads.ts +54 -0
- package/app/constants/desktopReleaseManifest.ts +68 -0
- package/app/constants/homeTabs.ts +15 -0
- package/app/constants/routePaths.ts +15 -0
- package/app/email/emailApiRoutes.ts +14 -0
- package/app/favorite/favoriteSlice.ts +690 -0
- package/app/favorite/type.ts +43 -0
- package/app/favorite/useAgentFavorite.ts +43 -0
- package/app/favorite/useContentFavorite.ts +41 -0
- package/app/fetchOwnedApps.ts +269 -0
- package/app/guide/quickStartGuide.ts +128 -0
- package/app/hooks/deleteDbKey.ts +233 -0
- package/app/hooks/index.ts +4 -0
- package/app/hooks/useAppDetail.ts +208 -0
- package/app/hooks/useAppVersions.ts +52 -0
- package/app/hooks/useAutoResizeTextarea.ts +29 -0
- package/app/hooks/useChatPageTitle.ts +85 -0
- package/app/hooks/useClipboardFiles.ts +20 -0
- package/app/hooks/useDesktopLocalConnectorAutostart.ts +38 -0
- package/app/hooks/useDragResize.ts +91 -0
- package/app/hooks/useElementSizeVar.ts +24 -0
- package/app/hooks/useFileDropZone.ts +52 -0
- package/app/hooks/useHasMounted.ts +11 -0
- package/app/hooks/useImageLoadFallback.ts +19 -0
- package/app/hooks/useIsMobile.ts +46 -0
- package/app/hooks/useMyApps.ts +375 -0
- package/app/hooks/useMyContentItems.ts +91 -0
- package/app/hooks/useNewMessageNotification.ts +81 -0
- package/app/hooks/usePageMeta.ts +107 -0
- package/app/hooks/useRecentlyOpened.ts +84 -0
- package/app/hooks/useUnifiedStore.ts +11 -0
- package/app/hooks/useUserNotifications.ts +197 -0
- package/app/hooks.ts +55 -0
- package/app/i18n/clientResources.ts +65 -0
- package/app/i18n/i18n.base.ts +14 -0
- package/app/i18n/i18n.config.ts +62 -0
- package/app/i18n/i18n.server.ts +13 -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/seo.locale.ts +129 -0
- package/app/i18n/types.ts +6 -0
- package/app/notifications/formatNotification.ts +134 -0
- package/app/notifications/model.ts +77 -0
- package/app/notifications/notificationSlice.ts +141 -0
- package/app/notifications/useNotificationActions.ts +67 -0
- package/app/pages/homeTabState.ts +57 -0
- package/app/pages/quickChatFlow.ts +109 -0
- package/app/pages/rechargeCheckout.ts +23 -0
- package/app/pages/usePageArt.ts +91 -0
- package/app/realtime/sharedSse.ts +182 -0
- package/app/reducer.ts +36 -0
- package/app/seo/pageMeta.ts +123 -0
- package/app/settings/config.ts +54 -0
- package/app/settings/dbActionThunks.ts +34 -0
- package/app/settings/defaultSpacePreference.ts +87 -0
- package/app/settings/navItems.ts +73 -0
- package/app/settings/prepareUserSetting.ts +11 -0
- package/app/settings/settingsRecord.ts +8 -0
- package/app/settings/web/chat-config/useAutoSaveGlobalPrompt.ts +59 -0
- package/app/settings/web/machineStatus.ts +23 -0
- package/app/settings/web/useSettingsStylesheet.ts +28 -0
- package/app/settings/web/userSecurityUtils.ts +21 -0
- package/app/stateViews/runtime.ts +86 -0
- package/app/store.ts +53 -0
- package/app/theme/colors.ts +280 -0
- package/app/theme/fontPreference.ts +77 -0
- package/app/theme/index.ts +7 -0
- package/app/theme/theme.config.ts +120 -0
- package/app/theme/themeModeBootstrap.ts +123 -0
- package/app/theme/useSystemTheme.ts +33 -0
- package/app/types/appSummary.ts +114 -0
- package/app/types.ts +358 -0
- package/app/utils/appDeploySource.ts +50 -0
- package/app/utils/appKeys.ts +55 -0
- package/app/utils/appRuntimeUrl.ts +51 -0
- package/app/utils/async.ts +28 -0
- package/app/utils/asyncMapStatus.ts +31 -0
- package/app/utils/clipboard.ts +86 -0
- package/app/utils/credits.ts +12 -0
- package/app/utils/desktopAgentRuntimeStatusClient.ts +42 -0
- package/app/utils/desktopAgentRuntimeTurnClient.ts +70 -0
- package/app/utils/desktopLocalConnectorClient.ts +83 -0
- package/app/utils/env.ts +12 -0
- package/app/utils/excelToSlate.ts +430 -0
- package/app/utils/fileReaders.ts +12 -0
- package/app/utils/fileUtils.ts +229 -0
- package/app/utils/imageUtils.native.ts +96 -0
- package/app/utils/imageUtils.ts +244 -0
- package/app/utils/ime.ts +43 -0
- package/app/utils/myContentItems.ts +290 -0
- package/app/utils/processDateRange.ts +30 -0
- package/app/utils/retryFetch.ts +61 -0
- package/app/utils/slateToExcel.ts +58 -0
- package/app/utils/toast.native.ts +42 -0
- package/app/utils/toast.ts +3 -0
- package/app/web/spaceInitGuard.ts +28 -0
- package/auth/action/signOutAction.ts +0 -0
- package/auth/action/signUpAction.ts +227 -0
- package/auth/actor.ts +16 -0
- package/auth/authSlice.ts +517 -0
- package/auth/billing.ts +130 -0
- package/auth/client/deleteUserRequest.ts +86 -0
- package/auth/client/loginRequest.ts +14 -0
- package/auth/hooks/useAuth.ts +9 -0
- package/auth/hooks/useDeleteOwnAccount.ts +50 -0
- package/auth/hooks/useDeleteOwnAccountFlow.ts +66 -0
- package/auth/hooks/useDeleteUser.ts +45 -0
- package/auth/hooks/useEnableUser.ts +50 -0
- package/auth/hooks/useFetchUsers.ts +77 -0
- package/auth/hooks/useRechargeUser.ts +82 -0
- package/auth/index.ts +1 -0
- package/auth/invite.ts +19 -0
- package/auth/locale.ts +84 -0
- package/auth/resetAuthScopedClientState.ts +27 -0
- package/auth/rn/tokenManager.ts +72 -0
- package/auth/routes.ts +127 -0
- package/auth/server/accessActivity.ts +143 -0
- package/auth/server/billingFullChainSimulator.ts +325 -0
- package/auth/server/billingUsageReport.ts +192 -0
- package/auth/server/cliLogin.ts +198 -0
- package/auth/server/creatorEarningCreditConversion.ts +515 -0
- package/auth/server/creatorEarningsLedger.ts +165 -0
- package/auth/server/creatorEarningsReport.ts +299 -0
- package/auth/server/creatorSettlementLedger.ts +386 -0
- package/auth/server/creatorSettlementReport.ts +442 -0
- package/auth/server/creatorSplitConfig.ts +191 -0
- package/auth/server/deduct.ts +270 -0
- package/auth/server/delete.ts +887 -0
- package/auth/server/disable.ts +61 -0
- package/auth/server/emailAutomation.ts +358 -0
- package/auth/server/emailAutomationConfig.ts +88 -0
- package/auth/server/emailAutomationRules.ts +94 -0
- package/auth/server/emailAutomationTemplates.ts +131 -0
- package/auth/server/emailAutomationTypes.ts +38 -0
- package/auth/server/emailDbConfig.ts +147 -0
- package/auth/server/emailDelivery.ts +960 -0
- package/auth/server/emailDeliveryGuards.ts +282 -0
- package/auth/server/emailPolicy.ts +43 -0
- package/auth/server/emailPreferences.ts +117 -0
- package/auth/server/emailProvider.ts +277 -0
- package/auth/server/emailReport.ts +439 -0
- package/auth/server/emailRuntimeConfig.ts +86 -0
- package/auth/server/emailScenarioNotifications.ts +340 -0
- package/auth/server/enable.ts +61 -0
- package/auth/server/getRechargeHistory.ts +110 -0
- package/auth/server/getUser.ts +71 -0
- package/auth/server/inviteReward.ts +295 -0
- package/auth/server/inviteRewardEmail.ts +1 -0
- package/auth/server/ledger.ts +422 -0
- package/auth/server/ledgerAudit.ts +424 -0
- package/auth/server/ledgerWitness.ts +472 -0
- package/auth/server/listusers.ts +154 -0
- package/auth/server/locks.ts +32 -0
- package/auth/server/login.ts +184 -0
- package/auth/server/productBillingSplits.ts +166 -0
- package/auth/server/productEntitlements.ts +139 -0
- package/auth/server/productPurchase.ts +382 -0
- package/auth/server/recharge.ts +284 -0
- package/auth/server/revenueShareLedger.ts +389 -0
- package/auth/server/revenueShareReport.ts +258 -0
- package/auth/server/revenueSplitPolicy.ts +119 -0
- package/auth/server/revokeSessions.ts +59 -0
- package/auth/server/route.ts +195 -0
- package/auth/server/sendEmail.ts +176 -0
- package/auth/server/shared.ts +51 -0
- package/auth/server/signup.ts +423 -0
- package/auth/server/signupIpQuota.ts +44 -0
- package/auth/server/token.ts +109 -0
- package/auth/server/tokenUsageBilling.ts +312 -0
- package/auth/server/transfer.ts +40 -0
- package/auth/server/utils.ts +200 -0
- package/auth/sessionTokenVersion.ts +38 -0
- package/auth/token.ts +63 -0
- package/auth/tokenCookie.ts +1 -0
- package/auth/types.ts +28 -0
- package/auth/utils.ts +108 -0
- package/auth/web/bootstrapAuthState.ts +60 -0
- package/auth/web/tokenManager.ts +61 -0
- package/auth/web/useRegister.ts +70 -0
- package/build.ts +16 -0
- package/buildPublish.ts +133 -0
- package/buildPublishArtifactAssembly.ts +346 -0
- package/buildPublishImportAnalysis.ts +237 -0
- package/chat/chat.locale.ts +804 -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/compactDialogAndForkAction.ts +47 -0
- package/chat/dialog/actions/createDialogAction.ts +372 -0
- package/chat/dialog/actions/createScheduledTaskAction.ts +78 -0
- package/chat/dialog/actions/handleSendMessageAction.ts +197 -0
- package/chat/dialog/actions/handleSendMessageResolver.ts +29 -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 +405 -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 +54 -0
- package/chat/dialog/dialogPageRenderMode.ts +182 -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/ensureDialogSpaceAction.ts +208 -0
- package/chat/dialog/goal.ts +108 -0
- package/chat/dialog/hooks/useStreamingSymbol.ts +63 -0
- package/chat/dialog/objectAssistantRegistry.ts +286 -0
- package/chat/dialog/schedule.ts +17 -0
- package/chat/dialog/useCreateDialog.ts +52 -0
- package/chat/hooks/sendPermissionResolver.ts +128 -0
- package/chat/hooks/useChatInput.ts +99 -0
- package/chat/hooks/useChatInputSeed.ts +31 -0
- package/chat/hooks/useMessageInteraction.ts +412 -0
- package/chat/hooks/useSendPermission.ts +92 -0
- package/chat/hooks/useThinkingVisibility.ts +27 -0
- package/chat/messages/browserImageUrl.ts +48 -0
- package/chat/messages/deleteMessages.ts +47 -0
- package/chat/messages/fetchAndCacheMessages.ts +119 -0
- package/chat/messages/fetchConvMsgs.ts +51 -0
- package/chat/messages/fetchMessages.ts +84 -0
- package/chat/messages/fileUrl.ts +13 -0
- package/chat/messages/generateMessageKey.ts +21 -0
- package/chat/messages/hooks/useBase64Migration.ts +115 -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 +1191 -0
- package/chat/messages/pendingAttachmentParts.ts +117 -0
- package/chat/messages/sendFirstMessage.ts +193 -0
- package/chat/messages/toolPresentation.ts +212 -0
- package/chat/messages/toolThunks.ts +625 -0
- package/chat/messages/types.ts +176 -0
- package/chat/messages/web/ChatDisplayContext.ts +14 -0
- package/chat/messages/web/ToolMessageTypes.ts +23 -0
- package/chat/messages/web/diffViewerModel.ts +61 -0
- package/chat/messages/web/groupToolEntries.ts +44 -0
- package/chat/messages/web/groupToolMessages.ts +35 -0
- package/chat/messages/web/inlineReactArtifactParser.ts +63 -0
- package/chat/messages/web/toolDisplayName.ts +22 -0
- package/chat/messages/web/useLoopStopReason.ts +43 -0
- package/chat/messages/ziweiChartDoc.ts +94 -0
- package/chat/web/docxToSlate.ts +597 -0
- package/chat/web/fileProcessor.ts +442 -0
- package/chat/web/hooks/useProgressiveDisplayCount.ts +102 -0
- package/chat/web/messageInputAgentUi.ts +189 -0
- package/chat/web/messageInputKeyBehavior.ts +53 -0
- package/chat/web/messageInputMention.ts +102 -0
- package/chat/web/messageInputSendResolver.ts +51 -0
- package/chat/web/messageSlashCommands.ts +10 -0
- package/chat/web/pdfOcrProcessor.ts +131 -0
- package/chat/web/sidebar/allViewSearch.ts +87 -0
- package/chat/web/sidebar/types.ts +12 -0
- package/chat/web/sidebar/useChatSidebarFilteredData.ts +141 -0
- package/chat/web/sidebar/useSidebarDragAndDrop.ts +56 -0
- package/cliCommandFactories.ts +32 -0
- package/cliEnvHelpers.ts +154 -21
- package/cliIoTypes.ts +3 -0
- package/client/agentRun.ts +26 -229
- package/client/agentRunLocalExecution.test.ts +123 -0
- package/client/agentRunLocalExecution.ts +124 -0
- package/client/agentRunRuntimeSelection.test.ts +158 -0
- package/client/agentRunRuntimeSelection.ts +155 -0
- package/client/profileConfig.test.ts +66 -0
- package/client/profileConfig.ts +41 -0
- package/client/streamingOutput.ts +1 -3
- package/client/taskRunPrompt.ts +7 -24
- package/commandRegistry.ts +2 -2
- package/connector-experimental/daemonLauncher.ts +189 -0
- package/connectorWebSocketTarget.ts +31 -10
- package/core/builtinAgents.ts +58 -0
- package/core/coin.ts +42 -0
- package/core/config.ts +15 -0
- package/core/crypto.ts +51 -0
- package/core/events/types.ts +145 -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/blockCommands.ts +118 -0
- package/create/editor/highlightExample.ts +66 -0
- package/create/editor/imageUpload.ts +66 -0
- package/create/editor/mark.ts +15 -0
- package/create/editor/plugins/normalizeChineseTypography.ts +85 -0
- package/create/editor/plugins/withBlockStructure.ts +53 -0
- package/create/editor/plugins/withChineseTypography.ts +61 -0
- package/create/editor/plugins/withLayout.ts +30 -0
- package/create/editor/plugins/withLinks.ts +13 -0
- package/create/editor/plugins/withMentions.ts +15 -0
- package/create/editor/plugins/withTables.ts +52 -0
- package/create/editor/tableCommands.ts +270 -0
- package/create/editor/theme/prism/default.ts +145 -0
- package/create/editor/theme/prism/githubDark.ts +139 -0
- package/create/editor/theme/prism/githubLight.ts +139 -0
- package/create/editor/theme/prism/index.ts +23 -0
- package/create/editor/theme/prism/okaidia.ts +197 -0
- package/create/editor/toolMentionOptions.ts +19 -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/types.ts +120 -0
- package/create/editor/utils/editorFactory.ts +54 -0
- package/create/editor/utils/hasPlainCodeBlock.ts +39 -0
- package/create/editor/utils/linkCommands.ts +63 -0
- package/create/editor/utils/pdfToSlate.ts +706 -0
- package/create/editor/utils/slateUtils.ts +233 -0
- package/create/editor/utils/txtToSlate.ts +40 -0
- package/create/hooks/category.ts +82 -0
- package/create/routePaths.ts +5 -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 +106 -0
- package/create/space/content/uploadAndAddFileToSpaceAction.ts +98 -0
- package/create/space/contentKeyUtils.ts +117 -0
- package/create/space/contentLabels.ts +56 -0
- package/create/space/contentTypeMeta.ts +169 -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/hooks/agentFetchRetry.ts +19 -0
- package/create/space/hooks/useAgentFetcher.ts +149 -0
- package/create/space/hooks/useGroupedContent.ts +118 -0
- package/create/space/hooks/useSpaceEvents.ts +43 -0
- package/create/space/initialSpace.ts +78 -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/publicCatalogSpace.ts +39 -0
- package/create/space/resolvePreferredSpaceId.ts +113 -0
- package/create/space/sidebarVisibleTypes.ts +214 -0
- package/create/space/space.locale.ts +981 -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/space/validateSpacePermission.ts +38 -0
- package/create/types.ts +21 -0
- package/create/version/appVersionReplication.ts +160 -0
- package/create/version/versionApi.ts +142 -0
- package/customCodingAgentFlow.ts +208 -0
- package/customCodingAgentRecord.ts +179 -0
- package/database/actions/agentReadResolution.ts +33 -0
- package/database/actions/cacheMergedUserData.ts +1 -1
- package/database/actions/common.ts +44 -8
- package/database/actions/fetchUserData.ts +1 -1
- package/database/actions/fileContent.ts +3 -3
- package/database/actions/patch.ts +3 -3
- package/database/actions/read.ts +115 -76
- package/database/actions/readAndWait.ts +54 -86
- package/database/actions/readOutcome.ts +45 -0
- package/database/actions/readResolution.ts +102 -0
- package/database/actions/remove.ts +2 -2
- package/database/actions/upload.ts +4 -4
- package/database/actions/upsert.ts +2 -2
- package/database/actions/write.ts +4 -4
- package/database/client/handleError.ts +1 -1
- package/database/client/queryRequest.ts +1 -1
- package/database/dbSlice.ts +2 -2
- package/database/email.ts +1 -1
- package/database/hooks/useUserData.ts +4 -4
- package/database/keys.ts +2 -2
- package/database/runtimeServerContext.ts +3 -3
- package/database/server/actorAccess.ts +1 -1
- package/database/server/cybotReadonly.ts +1 -1
- package/database/server/dataHandlers.ts +1 -1
- package/database/server/delete.ts +8 -8
- package/database/server/emailRepository.ts +7 -7
- package/database/server/fileService.ts +1 -1
- package/database/server/handleTransaction.ts +2 -2
- package/database/server/patch.ts +3 -3
- package/database/server/read.ts +5 -5
- package/database/server/resourceAccess.ts +2 -2
- package/database/server/routes.ts +3 -3
- package/database/server/write.ts +5 -5
- package/database/table/deleteTable.ts +1 -1
- package/database/userPreferenceRegister.ts +2 -2
- package/dialogDataAccess.ts +186 -0
- package/dialogInternalCommandEntries.ts +11 -0
- package/dialogReadCommands.ts +180 -0
- package/dialogReadHelpers.ts +226 -0
- package/dialogStatusCommands.ts +123 -0
- package/docInternalCommandEntries.ts +20 -0
- package/hybridReadHelpers.ts +109 -0
- package/index.ts +2 -6
- package/integrations/anthropic/anthropicModels.ts +47 -0
- package/integrations/anthropic/type.ts +41 -0
- package/integrations/deepseek/models.ts +67 -0
- package/integrations/google/models.ts +298 -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/postmark/index.ts +57 -0
- package/integrations/resend/index.ts +353 -0
- package/integrations/weather/getWeather.ts +24 -0
- package/integrations/weather/index.ts +6 -0
- package/integrations/weather/routes.ts +31 -0
- package/integrations/weather/weatherApi.ts +27 -0
- package/integrations/weather/weatherConstants.ts +2 -0
- package/integrations/weather/weatherI18n.ts +50 -0
- package/integrations/weather/weatherService.ts +50 -0
- package/integrations/weather/weatherTypes.ts +140 -0
- package/integrations/weather/weatherUtils.ts +46 -0
- package/integrations/x-reader/backends/localBrowser.ts +215 -0
- package/integrations/x-reader/backends/publicFallback.ts +31 -0
- package/integrations/x-reader/backends/rawCdp.ts +218 -0
- package/integrations/x-reader/bridge/chromeBridgeManager.ts +235 -0
- package/integrations/x-reader/bridge/readXPostWithBridge.ts +73 -0
- package/integrations/x-reader/fixtureParser.ts +101 -0
- package/integrations/x-reader/index.ts +9 -0
- package/integrations/x-reader/redaction.ts +27 -0
- package/integrations/x-reader/types.ts +109 -0
- package/integrations/x-reader/visibleTextParser.ts +108 -0
- package/integrations/xai/models.ts +13 -0
- package/internalCommandEntries.ts +8 -0
- package/machineCommandPrompts.ts +77 -0
- package/machineCommandResolution.ts +43 -0
- package/machineCommands.ts +90 -1107
- package/machineDaemonCommands.ts +29 -0
- package/machineHeartbeatCommands.ts +29 -0
- package/machineStatusCommands.ts +87 -0
- package/machineWatchCommands.ts +41 -0
- package/machineWsPromptMaterialization.ts +89 -0
- package/machineWsRunDispatch.ts +570 -0
- package/machineWsSession.ts +155 -0
- package/package.json +109 -5
- package/pageCreateCommands.ts +219 -0
- package/pageDeleteCommands.ts +167 -0
- package/pageReadCommands.ts +151 -0
- package/pageUpdateCommands.ts +249 -0
- package/pageWriteHelpers.ts +209 -0
- package/publishPackage.ts +36 -0
- package/render/canvas/canvasEditContext.ts +1 -1
- package/render/layout/mainLayoutViewMode.ts +1 -1
- package/render/page/createPageAction.ts +12 -12
- package/render/page/docSlice.ts +8 -8
- package/render/page/server/createPage.ts +7 -7
- package/render/page/server/handleCreatePage.ts +2 -2
- package/render/page/types.ts +2 -2
- package/render/surf/utils/groupedWeatherData.ts +1 -1
- package/render/table/createTableAction.ts +7 -7
- package/render/table/deleteTableAction.ts +4 -4
- package/render/table/fetchAndCacheTableRows.ts +2 -2
- package/render/table/tableSlice.ts +6 -6
- package/render/table/types.ts +1 -1
- package/render/table/useCreateTable.ts +2 -2
- package/render/table/useTable.ts +2 -2
- package/render/table/utils/tableSerialization.ts +1 -1
- package/runtimeDoctorCommands.ts +3 -3
- package/runtimeInternalCommandEntries.ts +15 -0
- package/runtimePassthroughCommands.ts +22 -0
- package/scriptCommandEntries.ts +5 -45
- package/scriptPassthroughHelpers.ts +28 -0
- package/secretScanHelpers.ts +31 -0
- package/server/agentEmailRegistrationRoutes.ts +29 -0
- package/server/agentRunRouteContract.ts +9 -0
- package/server/agentRunRoutes.ts +10 -0
- package/server/api/methods.ts +333 -0
- package/server/api/tableHandlers.ts +55 -0
- package/server/api/types.ts +27 -0
- package/server/apiContract.ts +88 -0
- package/server/apiRouteAdapter.ts +218 -0
- package/server/appBundler.ts +90 -0
- package/server/appRoutes.ts +92 -0
- package/server/artifactIconsRoute.ts +89 -0
- package/server/artifactRuntimeRoute.ts +136 -0
- package/server/authenticateToken.ts +73 -0
- package/server/billingLedgerRoutes.ts +48 -0
- package/server/cliChatRoutes.ts +5 -0
- package/server/cloudflareRoutes.ts +35 -0
- package/server/coreHeaders.ts +29 -0
- package/server/coreReadiness.ts +39 -0
- package/server/coreRoutes.ts +65 -0
- package/server/coreRuntime.ts +93 -0
- package/server/createResponse.ts +68 -0
- package/server/cryptoPaymentRoutes.ts +8 -0
- package/server/databaseRoutes.ts +225 -0
- package/server/desktopRuntimeRoutes.ts +120 -0
- package/server/devBuildInfo.ts +51 -0
- package/server/devReload.ts +161 -0
- package/server/devToolPathPolicy.ts +59 -0
- package/server/devToolRoutes.ts +274 -0
- package/server/email/cloudflareEmailProvider.ts +119 -0
- package/server/email/cloudflareInboundBridge.ts +121 -0
- package/server/email/cloudflareInboundWorker.ts +28 -0
- package/server/email/provider.ts +149 -0
- package/server/email/providerRegistry.ts +22 -0
- package/server/emailInboundRoutes.ts +17 -0
- package/server/entry.ts +211 -0
- package/server/handleRPCRequest.ts +117 -0
- package/server/handlers/activityStatsHandler.ts +74 -0
- package/server/handlers/agentEmailRegistrationE2EHandler.ts +406 -0
- package/server/handlers/agentEmailRegistrationE2ERoutes.ts +6 -0
- package/server/handlers/agentRun/agentLookup.ts +77 -0
- package/server/handlers/agentRun/autonomousRuntime.ts +355 -0
- package/server/handlers/agentRun/backgroundRunDialog.ts +31 -0
- package/server/handlers/agentRun/builtinAgents.ts +347 -0
- package/server/handlers/agentRun/continueDialogContext.ts +90 -0
- package/server/handlers/agentRun/debugContext.ts +58 -0
- package/server/handlers/agentRun/dialogLookup.ts +67 -0
- package/server/handlers/agentRun/foregroundStreamDialog.ts +13 -0
- package/server/handlers/agentRun/index.ts +1630 -0
- package/server/handlers/agentRun/inheritedDialogPrompt.ts +111 -0
- package/server/handlers/agentRun/localRuntimeBootstrap.ts +69 -0
- package/server/handlers/agentRun/loop.ts +2210 -0
- package/server/handlers/agentRun/machineConnector.ts +235 -0
- package/server/handlers/agentRun/machineRunAudit.ts +49 -0
- package/server/handlers/agentRun/modelUsageToolHandlers.ts +368 -0
- package/server/handlers/agentRun/referenceRuntime.ts +50 -0
- package/server/handlers/agentRun/requestContext.ts +86 -0
- package/server/handlers/agentRun/response.ts +27 -0
- package/server/handlers/agentRun/runBilling.ts +108 -0
- package/server/handlers/agentRun/runDialogPreparation.ts +55 -0
- package/server/handlers/agentRun/runtimeBinding.ts +61 -0
- package/server/handlers/agentRun/runtimeContext.ts +143 -0
- package/server/handlers/agentRun/runtimeExecutionContext.ts +153 -0
- package/server/handlers/agentRun/runtimePreparation.ts +193 -0
- package/server/handlers/agentRun/runtimeRouting.ts +88 -0
- package/server/handlers/agentRun/runtimeSystemMessages.ts +165 -0
- package/server/handlers/agentRun/saveDialog.ts +1373 -0
- package/server/handlers/agentRun/syncRunDialog.ts +90 -0
- package/server/handlers/agentRun/tableActivityProjection.ts +132 -0
- package/server/handlers/agentRun/taskRunControlPrompt.ts +122 -0
- package/server/handlers/agentRun/taskRunToolHandler.ts +579 -0
- package/server/handlers/agentRun/toolExecutor.ts +2909 -0
- package/server/handlers/agentRun/toolPolicyGuards.ts +295 -0
- package/server/handlers/agentRun/types.ts +94 -0
- package/server/handlers/agentRun/workspaceLease.ts +58 -0
- package/server/handlers/alphaTestRouteGuard.ts +30 -0
- package/server/handlers/apifyActorHandler.ts +170 -0
- package/server/handlers/appDeployFlow.ts +876 -0
- package/server/handlers/appDeployHandler.ts +4 -0
- package/server/handlers/appDeployMutationHandlers.ts +133 -0
- package/server/handlers/appDeployReadHandlers.ts +321 -0
- package/server/handlers/appDeployShared.ts +230 -0
- package/server/handlers/appDeployStatusStore.ts +178 -0
- package/server/handlers/appDomainHandler.ts +476 -0
- package/server/handlers/appLegacyInfraCleanup.ts +7 -0
- package/server/handlers/appSandboxHandler.ts +1055 -0
- package/server/handlers/appSourceReadiness.ts +75 -0
- package/server/handlers/appSpaceAccess.ts +179 -0
- package/server/handlers/applyEditHandler.ts +544 -0
- package/server/handlers/applyLineEditsHandler.ts +1058 -0
- package/server/handlers/billingLedgerAuditHandler.ts +82 -0
- package/server/handlers/billingLedgerWitnessHandler.ts +161 -0
- package/server/handlers/billingUsageReportHandler.ts +90 -0
- package/server/handlers/browserToolHandler.ts +450 -0
- package/server/handlers/cfTextToSpeechHandler.ts +137 -0
- package/server/handlers/cfWhisperHandler.ts +206 -0
- package/server/handlers/chatBillingSse.ts +79 -0
- package/server/handlers/chatHandler.ts +797 -0
- package/server/handlers/chatProxyRouting.ts +404 -0
- package/server/handlers/chatUpstreamRetry.ts +162 -0
- package/server/handlers/checkEnvHandler.ts +250 -0
- package/server/handlers/cliChatHandler.ts +266 -0
- package/server/handlers/cloudflareBrowserHandler.ts +275 -0
- package/server/handlers/cloudflareCrawlHandler.ts +260 -0
- package/server/handlers/codeSearchHandler.ts +484 -0
- package/server/handlers/connector/connectorConnectionRegistry.ts +192 -0
- package/server/handlers/connector/connectorWebSocket.ts +117 -0
- package/server/handlers/creatorEarningsReportHandler.ts +97 -0
- package/server/handlers/creatorSettlementReportHandler.ts +98 -0
- package/server/handlers/deepseekOcrHandler.ts +114 -0
- package/server/handlers/deleteMemoryHandler.ts +115 -0
- package/server/handlers/desktopAgentRuntimeAdapter.ts +307 -0
- package/server/handlers/desktopAgentRuntimeHostFacts.ts +40 -0
- package/server/handlers/desktopAgentRuntimeStatusHandler.ts +54 -0
- package/server/handlers/desktopAgentRuntimeTurnHandler.ts +165 -0
- package/server/handlers/desktopAgentRuntimeTurnService.ts +352 -0
- package/server/handlers/desktopClipboardHandler.ts +104 -0
- package/server/handlers/desktopFiles/handler.ts +159 -0
- package/server/handlers/desktopFiles/operations.ts +202 -0
- package/server/handlers/desktopFiles/sandbox.ts +62 -0
- package/server/handlers/desktopFiles/store.ts +81 -0
- package/server/handlers/desktopLlamaRuntimeHandler.ts +360 -0
- package/server/handlers/desktopLocalConnectorHandler.ts +101 -0
- package/server/handlers/desktopUpdaterHandler.ts +132 -0
- package/server/handlers/dialogEvents.ts +10 -0
- package/server/handlers/emailInboundHandler.ts +65 -0
- package/server/handlers/eventBus.ts +160 -0
- package/server/handlers/exaSearchHandler.ts +73 -0
- package/server/handlers/execShellHandler.ts +661 -0
- package/server/handlers/favoriteHandlers.ts +417 -0
- package/server/handlers/fetchWebpageHandler.ts +117 -0
- package/server/handlers/fileOutlineHandler.ts +107 -0
- package/server/handlers/geminiImagePreviewHandler.ts +612 -0
- package/server/handlers/getDialogBillingHandler.ts +151 -0
- package/server/handlers/getTransactionsHandler.ts +107 -0
- package/server/handlers/googleNativeChat.ts +572 -0
- package/server/handlers/listFilesHandler.ts +139 -0
- package/server/handlers/machines/machineAuth.ts +149 -0
- package/server/handlers/machines/machineBinding.ts +59 -0
- package/server/handlers/machines/machineHandlers.ts +279 -0
- package/server/handlers/machines/machineInstallAssets.ts +563 -0
- package/server/handlers/machines/machineRegistry.ts +89 -0
- package/server/handlers/notificationEmitter.ts +189 -0
- package/server/handlers/notificationsHandler.ts +91 -0
- package/server/handlers/olmOcrHandler.ts +115 -0
- package/server/handlers/openaiImageHandler.ts +500 -0
- package/server/handlers/providerHealthHandler.ts +36 -0
- package/server/handlers/publicHandler.ts +209 -0
- package/server/handlers/readFileHandler.ts +300 -0
- package/server/handlers/readXPostHandler.ts +180 -0
- package/server/handlers/rememberMemoryHandler.ts +69 -0
- package/server/handlers/remotionRenderHandler.ts +236 -0
- package/server/handlers/renderMarkdownHandler.ts +66 -0
- package/server/handlers/revenueShareReportHandler.ts +96 -0
- package/server/handlers/searchRepoHandler.ts +159 -0
- package/server/handlers/tableAccess.ts +34 -0
- package/server/handlers/tableToolHandlers.ts +741 -0
- package/server/handlers/typecheckWorker.ts +54 -0
- package/server/handlers/userEvents.ts +6 -0
- package/server/handlers/userSecretsHandler.ts +210 -0
- package/server/handlers/versionHandler.ts +281 -0
- package/server/handlers/versionStore.ts +176 -0
- package/server/handlers/wereadGatewayHandler.ts +48 -0
- package/server/handlers/whisperHandler.ts +158 -0
- package/server/handlers/writeFileHandler.ts +168 -0
- package/server/html/desktopReleaseManifest.server.ts +17 -0
- package/server/html/generateErrorResponse.ts +22 -0
- package/server/html/serializeState.ts +9 -0
- package/server/html/ssrPreload.ts +247 -0
- package/server/html/template.ts +275 -0
- package/server/httpCompression.ts +102 -0
- package/server/index.ts +0 -0
- package/server/liveReloadScript.ts +105 -0
- package/server/luIconNames.ts +14 -0
- package/server/machineRoutes.ts +44 -0
- package/server/mediaRoutes.ts +25 -0
- package/server/memoryRoutes.ts +14 -0
- package/server/normalizedStatusRoutes.ts +23 -0
- package/server/payments/crypto/cryptoUsdcBaseAddressPool.ts +49 -0
- package/server/payments/crypto/cryptoUsdcBaseConfig.ts +120 -0
- package/server/payments/crypto/cryptoUsdcBasePaymentProvider.ts +134 -0
- package/server/payments/crypto/cryptoUsdcBaseScanner.ts +267 -0
- package/server/payments/crypto/cryptoUsdcBaseWatcher.ts +40 -0
- package/server/payments/crypto/cryptoUsdtTronAddressPool.ts +49 -0
- package/server/payments/crypto/cryptoUsdtTronConfig.ts +120 -0
- package/server/payments/crypto/cryptoUsdtTronPaymentProvider.ts +132 -0
- package/server/payments/crypto/cryptoUsdtTronScanner.ts +313 -0
- package/server/payments/crypto/cryptoUsdtTronWatcher.ts +40 -0
- package/server/payments/paymentProvider.ts +6 -0
- package/server/payments/paymentRoutes.ts +27 -0
- package/server/payments/rechargeCredits.ts +69 -0
- package/server/payments/waffo/waffoPaymentProvider.ts +341 -0
- package/server/preview/previewCapability.ts +90 -0
- package/server/preview/previewConfig.ts +54 -0
- package/server/preview/previewGateway.ts +71 -0
- package/server/preview/previewRealtime.ts +33 -0
- package/server/providerHealthProbe.ts +198 -0
- package/server/providerHealthRoutes.ts +19 -0
- package/server/publicPaths.ts +12 -0
- package/server/publicRequestHandler.ts +15 -0
- package/server/reactAppBuilder.ts +416 -0
- package/server/realtimeRoutes.ts +69 -0
- package/server/renderStream.ts +20 -0
- package/server/routeFactory.ts +45 -0
- package/server/routes.ts +125 -0
- package/server/safeTempFile.ts +48 -0
- package/server/scheduler/scheduledTaskRuntime.ts +228 -0
- package/server/scheduler/schedulerService.ts +290 -0
- package/server/serverDrain.ts +129 -0
- package/server/services/browserSessionManager.ts +354 -0
- package/server/shareRoutes.ts +86 -0
- package/server/sqliteRoutes.ts +141 -0
- package/server/taskRunBridgeRoutes.ts +95 -0
- package/server/tasks.ts +113 -0
- package/server/waffoPaymentRoutes.ts +5 -0
- package/server/webUtilityRoutes.ts +50 -0
- package/server/workerValidator.ts +224 -0
- package/share/action.ts +225 -0
- package/share/clientTableReplication.ts +160 -0
- package/share/helpers.ts +302 -0
- package/share/keys.ts +243 -0
- package/share/link.ts +40 -0
- package/share/loadOwnerShares.ts +154 -0
- package/share/paidAccess.ts +32 -0
- package/share/publicSharePolicy.ts +27 -0
- package/share/server/fetchCommunityShares.ts +45 -0
- package/share/server/helpers.ts +202 -0
- package/share/server/importShare.ts +148 -0
- package/share/server/listCommunityShares.ts +167 -0
- package/share/server/purchaseDoc.ts +224 -0
- package/share/server/readCommunityShareCover.ts +73 -0
- package/share/server/readSharedTable.ts +139 -0
- package/share/server/tableReplication.ts +351 -0
- package/share/shareSlice.ts +53 -0
- package/share/tableShareState.ts +74 -0
- package/share/types.ts +100 -0
- package/spaceCategoryCommands.ts +263 -0
- package/spaceCommands.ts +295 -0
- package/spaceDeleteCommands.ts +312 -0
- package/spaceInternalCommandEntries.ts +19 -0
- package/spaceMutationHelpers.ts +135 -0
- package/spaceReadCommands.ts +323 -0
- package/systemInternalCommandEntries.ts +16 -22
- package/tableCommands.ts +33 -133
- package/tableDataOutput.ts +41 -0
- package/tableDataSafety.ts +26 -0
- package/tableMetaCommands.ts +307 -0
- package/tableMutationCommands.ts +266 -0
- package/tableQueryParsing.ts +90 -0
- package/tableQueryRequest.ts +53 -0
- package/taskRunActions.ts +122 -0
- package/taskRunCommand.ts +16 -211
- package/taskRunParsing.ts +86 -0
- package/taskRunPromptShared.ts +55 -0
- package/tui/session.ts +43 -372
- package/tui/tuiCatalog.ts +22 -0
- package/tui/tuiCommandInterpreter.test.ts +169 -0
- package/tui/tuiCommandInterpreter.ts +253 -0
- package/tui/tuiPresentation.test.ts +154 -0
- package/tui/tuiPresentation.ts +146 -0
- package/workflowInternalCommandEntries.ts +20 -0
- package/offlineMarxistsAgentCommand.ts +0 -314
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { isBudgetedWorkspaceReadKey } from "../../../ai/policy/runtimePolicy";
|
|
2
|
+
import { hasExplicitPublicShareRequest } from "../../../share/publicSharePolicy";
|
|
3
|
+
|
|
4
|
+
import type { ToolExecutionContext } from "./types";
|
|
5
|
+
|
|
6
|
+
export const buildPolicyLimitResult = (
|
|
7
|
+
error: string,
|
|
8
|
+
message: string,
|
|
9
|
+
policy: Record<string, any>,
|
|
10
|
+
): string =>
|
|
11
|
+
JSON.stringify({
|
|
12
|
+
error,
|
|
13
|
+
message,
|
|
14
|
+
policy,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const normalizeUserInput = (value: unknown): string =>
|
|
18
|
+
typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
19
|
+
|
|
20
|
+
const containsAny = (text: string, patterns: readonly string[]): boolean =>
|
|
21
|
+
patterns.some((pattern) => text.includes(pattern));
|
|
22
|
+
|
|
23
|
+
const DESTRUCTIVE_NEGATION_PATTERNS = [
|
|
24
|
+
"别删",
|
|
25
|
+
"别删除",
|
|
26
|
+
"不要删",
|
|
27
|
+
"不要删除",
|
|
28
|
+
"别乱删",
|
|
29
|
+
"别动",
|
|
30
|
+
"不要动",
|
|
31
|
+
"不要清理",
|
|
32
|
+
"不要清空",
|
|
33
|
+
"不要重置",
|
|
34
|
+
"don't delete",
|
|
35
|
+
"do not delete",
|
|
36
|
+
"don't remove",
|
|
37
|
+
"do not remove",
|
|
38
|
+
"without deleting",
|
|
39
|
+
] as const;
|
|
40
|
+
|
|
41
|
+
const EXPLICIT_DESTRUCTIVE_REQUEST_PATTERNS = [
|
|
42
|
+
"删除",
|
|
43
|
+
"删掉",
|
|
44
|
+
"移除",
|
|
45
|
+
"清理",
|
|
46
|
+
"清空",
|
|
47
|
+
"重置",
|
|
48
|
+
"drop",
|
|
49
|
+
"delete",
|
|
50
|
+
"remove",
|
|
51
|
+
"erase",
|
|
52
|
+
"clean up",
|
|
53
|
+
"reset",
|
|
54
|
+
] as const;
|
|
55
|
+
|
|
56
|
+
const SHELL_DESTRUCTIVE_PATTERNS = [
|
|
57
|
+
/\brm\s+(-[^\n\r]*\s+)?/i,
|
|
58
|
+
/\bremove-item\b/i,
|
|
59
|
+
/\bdel\s+\/?[a-z]*\s+/i,
|
|
60
|
+
/\berase\s+/i,
|
|
61
|
+
/\brmdir\s+/i,
|
|
62
|
+
/\brd\s+\/s\b/i,
|
|
63
|
+
/\bgit\s+reset\s+(--hard\b|--merge\b|--keep\b)/i,
|
|
64
|
+
/\bgit\s+clean\s+-[^\n\r]*f/i,
|
|
65
|
+
/\bgit\s+checkout\s+--\b/i,
|
|
66
|
+
/\bgit\s+restore\s+--source=/i,
|
|
67
|
+
] as const;
|
|
68
|
+
|
|
69
|
+
const hasExplicitDestructivePermission = (
|
|
70
|
+
userInput: unknown,
|
|
71
|
+
): boolean => {
|
|
72
|
+
const normalized = normalizeUserInput(userInput);
|
|
73
|
+
if (!normalized) return false;
|
|
74
|
+
if (containsAny(normalized, DESTRUCTIVE_NEGATION_PATTERNS)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
return containsAny(normalized, EXPLICIT_DESTRUCTIVE_REQUEST_PATTERNS);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const guardDestructiveAction = (params: {
|
|
81
|
+
context?: ToolExecutionContext;
|
|
82
|
+
target:
|
|
83
|
+
| "shell_command"
|
|
84
|
+
| "app_delete"
|
|
85
|
+
| "table_row_delete"
|
|
86
|
+
| "table_column_delete";
|
|
87
|
+
detail: string;
|
|
88
|
+
}): string | null => {
|
|
89
|
+
const { context, target, detail } = params;
|
|
90
|
+
if (hasExplicitDestructivePermission(context?.userInput)) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return buildPolicyLimitResult(
|
|
95
|
+
"destructive_action_requires_confirmation",
|
|
96
|
+
`当前运行默认禁止自动执行可能删除用户内容的操作(${detail})。只有当用户在当前请求里明确要求删除/清理时,才能继续;否则请停止并先说明限制。`,
|
|
97
|
+
{
|
|
98
|
+
capability: "destructive_action",
|
|
99
|
+
target,
|
|
100
|
+
detail,
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const isDestructiveShellCommand = (params: {
|
|
106
|
+
command?: unknown;
|
|
107
|
+
input?: unknown;
|
|
108
|
+
}): boolean => {
|
|
109
|
+
const combined = [
|
|
110
|
+
typeof params.command === "string" ? params.command : "",
|
|
111
|
+
typeof params.input === "string" ? params.input : "",
|
|
112
|
+
]
|
|
113
|
+
.filter(Boolean)
|
|
114
|
+
.join("\n");
|
|
115
|
+
|
|
116
|
+
if (!combined.trim()) return false;
|
|
117
|
+
return SHELL_DESTRUCTIVE_PATTERNS.some((pattern) => pattern.test(combined));
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const guardWorkspaceRead = (
|
|
121
|
+
dbKey: unknown,
|
|
122
|
+
context?: ToolExecutionContext,
|
|
123
|
+
): string | null => {
|
|
124
|
+
if (
|
|
125
|
+
!context?.policy?.spaceContext ||
|
|
126
|
+
!context.runtimeState ||
|
|
127
|
+
typeof dbKey !== "string" ||
|
|
128
|
+
!isBudgetedWorkspaceReadKey(dbKey)
|
|
129
|
+
) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const { spaceContext } = context.policy;
|
|
134
|
+
const turnReads = context.runtimeState.autoSpaceReadCountThisRun;
|
|
135
|
+
const totalReads =
|
|
136
|
+
spaceContext.currentAutoReads + context.runtimeState.autoSpaceReadCountThisRun;
|
|
137
|
+
|
|
138
|
+
if (
|
|
139
|
+
turnReads < spaceContext.maxReadCallsPerTurn &&
|
|
140
|
+
totalReads < spaceContext.maxReadCallsPerDialog
|
|
141
|
+
) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return buildPolicyLimitResult(
|
|
146
|
+
"space_read_limit_reached",
|
|
147
|
+
`当前策略下已达到自动读取上限。本轮最多自动读取 ${spaceContext.maxReadCallsPerTurn} 个对象,当前对话最多自动读取 ${spaceContext.maxReadCallsPerDialog} 个对象。请停止继续 read,改为先解释限制或询问用户。`,
|
|
148
|
+
{
|
|
149
|
+
capability: "space_context",
|
|
150
|
+
level: spaceContext.level,
|
|
151
|
+
remainingAutoReadsThisTurn: Math.max(
|
|
152
|
+
0,
|
|
153
|
+
spaceContext.maxReadCallsPerTurn - turnReads,
|
|
154
|
+
),
|
|
155
|
+
remainingAutoReadsThisDialog: Math.max(
|
|
156
|
+
0,
|
|
157
|
+
spaceContext.maxReadCallsPerDialog - totalReads,
|
|
158
|
+
),
|
|
159
|
+
},
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const recordWorkspaceRead = (
|
|
164
|
+
dbKey: unknown,
|
|
165
|
+
context?: ToolExecutionContext,
|
|
166
|
+
): void => {
|
|
167
|
+
if (
|
|
168
|
+
context?.policy?.spaceContext &&
|
|
169
|
+
context.runtimeState &&
|
|
170
|
+
typeof dbKey === "string" &&
|
|
171
|
+
isBudgetedWorkspaceReadKey(dbKey)
|
|
172
|
+
) {
|
|
173
|
+
context.runtimeState.autoSpaceReadCountThisRun += 1;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export const guardKnowledgeCapture = (params: {
|
|
178
|
+
context?: ToolExecutionContext;
|
|
179
|
+
target: "doc" | "table";
|
|
180
|
+
}): string | null => {
|
|
181
|
+
const { context, target } = params;
|
|
182
|
+
if (!context?.policy?.knowledgeCapture || !context.runtimeState) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const { knowledgeCapture } = context.policy;
|
|
187
|
+
const totalCreates =
|
|
188
|
+
knowledgeCapture.currentAutoCreates +
|
|
189
|
+
context.runtimeState.autoKnowledgeCaptureCountThisRun;
|
|
190
|
+
|
|
191
|
+
if (knowledgeCapture.explicitRequest) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (target === "table") {
|
|
196
|
+
if (
|
|
197
|
+
knowledgeCapture.mode !== "auto" ||
|
|
198
|
+
totalCreates >= knowledgeCapture.maxAutoCreatesPerDialog
|
|
199
|
+
) {
|
|
200
|
+
return buildPolicyLimitResult(
|
|
201
|
+
"knowledge_capture_requires_confirmation",
|
|
202
|
+
"当前策略不允许直接创建表格作为知识沉淀结果。请先回答,或询问用户是否需要沉淀成表格。",
|
|
203
|
+
{
|
|
204
|
+
capability: "knowledge_capture",
|
|
205
|
+
level: knowledgeCapture.level,
|
|
206
|
+
mode: knowledgeCapture.mode,
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (knowledgeCapture.mode === "blocked") {
|
|
214
|
+
return buildPolicyLimitResult(
|
|
215
|
+
"knowledge_capture_blocked",
|
|
216
|
+
"当前用户/Agent 策略不允许主动创建知识文档。请先直接回答,或在需要时询问用户是否要沉淀成文档/表格。",
|
|
217
|
+
{
|
|
218
|
+
capability: "knowledge_capture",
|
|
219
|
+
level: knowledgeCapture.level,
|
|
220
|
+
mode: knowledgeCapture.mode,
|
|
221
|
+
},
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (knowledgeCapture.mode === "ask") {
|
|
226
|
+
return buildPolicyLimitResult(
|
|
227
|
+
"knowledge_capture_requires_confirmation",
|
|
228
|
+
"当前策略要求先询问用户,再创建文档/表格。请先说明你建议沉淀什么,再等待用户确认。",
|
|
229
|
+
{
|
|
230
|
+
capability: "knowledge_capture",
|
|
231
|
+
level: knowledgeCapture.level,
|
|
232
|
+
mode: knowledgeCapture.mode,
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (knowledgeCapture.mode === "suggest") {
|
|
238
|
+
return buildPolicyLimitResult(
|
|
239
|
+
"knowledge_capture_suggest_only",
|
|
240
|
+
"当前策略要求先完成回答,再建议是否沉淀为文档/表格;不要直接创建。",
|
|
241
|
+
{
|
|
242
|
+
capability: "knowledge_capture",
|
|
243
|
+
level: knowledgeCapture.level,
|
|
244
|
+
mode: knowledgeCapture.mode,
|
|
245
|
+
},
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (totalCreates >= knowledgeCapture.maxAutoCreatesPerDialog) {
|
|
250
|
+
return buildPolicyLimitResult(
|
|
251
|
+
"knowledge_capture_limit_reached",
|
|
252
|
+
`当前对话已达到自动知识沉淀上限(${knowledgeCapture.maxAutoCreatesPerDialog} 次)。如确需继续,请先询问用户。`,
|
|
253
|
+
{
|
|
254
|
+
capability: "knowledge_capture",
|
|
255
|
+
level: knowledgeCapture.level,
|
|
256
|
+
mode: knowledgeCapture.mode,
|
|
257
|
+
remainingAutoCreates: Math.max(
|
|
258
|
+
0,
|
|
259
|
+
knowledgeCapture.maxAutoCreatesPerDialog - totalCreates,
|
|
260
|
+
),
|
|
261
|
+
},
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return null;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
export const guardPublicTableShare = (
|
|
269
|
+
context?: ToolExecutionContext
|
|
270
|
+
): string | null => {
|
|
271
|
+
if (hasExplicitPublicShareRequest(context?.userInput)) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return buildPolicyLimitResult(
|
|
276
|
+
"public_table_share_requires_confirmation",
|
|
277
|
+
"当前策略不允许在用户未明确要求公开/社区分享时自动发布表。请先解释限制,或等待用户明确表示要公开分享到社区。",
|
|
278
|
+
{
|
|
279
|
+
capability: "public_table_share",
|
|
280
|
+
target: "shareTable",
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
export const recordKnowledgeCapture = (
|
|
286
|
+
context?: ToolExecutionContext,
|
|
287
|
+
): void => {
|
|
288
|
+
if (
|
|
289
|
+
context?.policy?.knowledgeCapture &&
|
|
290
|
+
context.runtimeState &&
|
|
291
|
+
!context.policy.knowledgeCapture.explicitRequest
|
|
292
|
+
) {
|
|
293
|
+
context.runtimeState.autoKnowledgeCaptureCountThisRun += 1;
|
|
294
|
+
}
|
|
295
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// packages/server/handlers/agentRun/types.ts
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DialogPolicyState,
|
|
5
|
+
} from "../../../ai/policy/types";
|
|
6
|
+
import type { ResolvedRuntimePolicy } from "../../../ai/policy/runtimePolicy";
|
|
7
|
+
import type { DialogRuntimeProfile } from "../../../app/types";
|
|
8
|
+
import type { DialogSubjectRef } from "../../../app/types";
|
|
9
|
+
import type {
|
|
10
|
+
AgentRuntimeChatMessage,
|
|
11
|
+
AgentRuntimeResult,
|
|
12
|
+
AgentRuntimeToolCall,
|
|
13
|
+
} from "../../../agent-runtime/types";
|
|
14
|
+
import type { AgentRuntimeOptions } from "../../../ai/agent/types";
|
|
15
|
+
|
|
16
|
+
export type ChatMessage = AgentRuntimeChatMessage;
|
|
17
|
+
|
|
18
|
+
export type AssistantToolCall = AgentRuntimeToolCall;
|
|
19
|
+
|
|
20
|
+
export interface AgentRunRequest {
|
|
21
|
+
agentKey: string;
|
|
22
|
+
userInput:
|
|
23
|
+
| string
|
|
24
|
+
| Array<
|
|
25
|
+
| { type: "text"; text: string }
|
|
26
|
+
| {
|
|
27
|
+
type: "image_url";
|
|
28
|
+
image_url: { url: string };
|
|
29
|
+
google_native?: {
|
|
30
|
+
inlineData: {
|
|
31
|
+
mimeType: string;
|
|
32
|
+
data: string;
|
|
33
|
+
};
|
|
34
|
+
thoughtSignature?: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
>;
|
|
38
|
+
messages?: ChatMessage[]; // 历史对话,调用方自行管理(不持久化)
|
|
39
|
+
runtimeContext?: AgentRunRuntimeContext;
|
|
40
|
+
stream?: boolean;
|
|
41
|
+
maxRounds?: number; // 兼容旧客户端保留,服务端当前不再按工具轮次限制
|
|
42
|
+
timeoutMs?: number; // 可选:调用方为本次 agent run 传入的任务级超时预算
|
|
43
|
+
background?: boolean;
|
|
44
|
+
spaceId?: string;
|
|
45
|
+
category?: string;
|
|
46
|
+
inheritedFromDialogKey?: string;
|
|
47
|
+
parentDialogId?: string;
|
|
48
|
+
runtimeProfile?: DialogRuntimeProfile;
|
|
49
|
+
runtimeOptions?: AgentRuntimeOptions;
|
|
50
|
+
debugContextLayers?: boolean;
|
|
51
|
+
/** 传入已有 dialogId 时,新消息追加到该对话而不是新建 */
|
|
52
|
+
continueDialogId?: string;
|
|
53
|
+
/** UI 已自行管理消息持久化时,设为 false 避免 agent/run 额外创建运行对话 */
|
|
54
|
+
persistDialog?: boolean;
|
|
55
|
+
/** persistDialog=false 时用于工具上下文和计费归属的已有 UI dialogId */
|
|
56
|
+
clientDialogId?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface AgentRunRuntimeContext {
|
|
60
|
+
surface?: "web" | "electron" | "electron-bun" | "cli" | "server-script" | "backend-script" | "react-native" | string;
|
|
61
|
+
host?: string;
|
|
62
|
+
runtime?: string;
|
|
63
|
+
entrypoint?: string;
|
|
64
|
+
capabilities?: string[];
|
|
65
|
+
taskRun?: {
|
|
66
|
+
rowDbKey?: string;
|
|
67
|
+
taskRunId?: string;
|
|
68
|
+
workItemId?: string;
|
|
69
|
+
artifactIds?: string[];
|
|
70
|
+
};
|
|
71
|
+
subjectRefs?: DialogSubjectRef[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface LoopResult extends Omit<AgentRuntimeResult, "policyState"> {
|
|
75
|
+
policyState?: DialogPolicyState;
|
|
76
|
+
artifacts?: unknown;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ToolPolicyRuntimeState {
|
|
80
|
+
autoKnowledgeCaptureCountThisRun: number;
|
|
81
|
+
autoSpaceReadCountThisRun: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface ToolExecutionContext {
|
|
85
|
+
policy?: ResolvedRuntimePolicy;
|
|
86
|
+
runtimeState?: ToolPolicyRuntimeState;
|
|
87
|
+
runtimeContext?: AgentRunRuntimeContext | null;
|
|
88
|
+
userId?: string | null;
|
|
89
|
+
agentKey?: string | null;
|
|
90
|
+
dialogId?: string | null;
|
|
91
|
+
currentSpaceId?: string | null;
|
|
92
|
+
userInput?: string | null;
|
|
93
|
+
imageUrls?: string[];
|
|
94
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { AgentRuntimeToolPolicy } from "../../../agent-runtime";
|
|
2
|
+
import type { ConnectorAgentRunResult } from "../connector/connectorConnectionRegistry";
|
|
3
|
+
|
|
4
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
5
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function stringField(record: Record<string, unknown>, key: string) {
|
|
9
|
+
const value = record[key];
|
|
10
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function stringArray(value: unknown) {
|
|
14
|
+
return Array.isArray(value)
|
|
15
|
+
? value.filter((item): item is string => typeof item === "string" && !!item.trim())
|
|
16
|
+
: [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function extractConnectorArtifact(result: ConnectorAgentRunResult | null | undefined) {
|
|
20
|
+
const artifacts = result?.artifacts;
|
|
21
|
+
if (isRecord(artifacts)) return artifacts;
|
|
22
|
+
if (Array.isArray(artifacts)) {
|
|
23
|
+
return artifacts.find(isRecord);
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function buildWorkspaceLeaseFromConnectorResult(args: {
|
|
29
|
+
result: ConnectorAgentRunResult | null | undefined;
|
|
30
|
+
agentKey: string;
|
|
31
|
+
machineId?: string | null;
|
|
32
|
+
runtimeToolPolicySnapshot?: AgentRuntimeToolPolicy;
|
|
33
|
+
now?: () => number;
|
|
34
|
+
}) {
|
|
35
|
+
const artifact = extractConnectorArtifact(args.result);
|
|
36
|
+
const workspaceRoot = artifact ? stringField(artifact, "cwd") : undefined;
|
|
37
|
+
if (!workspaceRoot) return undefined;
|
|
38
|
+
const createdAt = new Date((args.now ?? Date.now)()).toISOString();
|
|
39
|
+
const changedFiles = stringArray(artifact.changedFiles);
|
|
40
|
+
return {
|
|
41
|
+
id: `machine-${args.machineId || "unbound"}-${createdAt}`,
|
|
42
|
+
source: "machine-connector",
|
|
43
|
+
agentKey: args.agentKey,
|
|
44
|
+
...(args.machineId ? { machineId: args.machineId } : {}),
|
|
45
|
+
workspaceRoot,
|
|
46
|
+
writableRoots: [workspaceRoot],
|
|
47
|
+
createdAt,
|
|
48
|
+
policy: args.runtimeToolPolicySnapshot,
|
|
49
|
+
evidence: {
|
|
50
|
+
artifactKind: "connector-run-artifact",
|
|
51
|
+
...(stringField(artifact, "baseSha") ? { baseSha: stringField(artifact, "baseSha") } : {}),
|
|
52
|
+
...(stringField(artifact, "headSha") ? { headSha: stringField(artifact, "headSha") } : {}),
|
|
53
|
+
...(changedFiles.length > 0 ? { changedFiles } : {}),
|
|
54
|
+
...(stringField(artifact, "statusShort") ? { statusShort: stringField(artifact, "statusShort") } : {}),
|
|
55
|
+
...(stringField(artifact, "diffStat") ? { diffStat: stringField(artifact, "diffStat") } : {}),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const ALLOWED_ALPHA_TEST_HOSTS = new Set([
|
|
2
|
+
"localhost",
|
|
3
|
+
"127.0.0.1",
|
|
4
|
+
"::1",
|
|
5
|
+
"us.nolo.chat",
|
|
6
|
+
]);
|
|
7
|
+
|
|
8
|
+
export function isAlphaTestHost(host: string | null | undefined): boolean {
|
|
9
|
+
const rawHost = String(host ?? "").trim().toLowerCase();
|
|
10
|
+
const normalizedHost =
|
|
11
|
+
rawHost.startsWith("[") && rawHost.includes("]")
|
|
12
|
+
? rawHost.slice(1, rawHost.indexOf("]"))
|
|
13
|
+
: rawHost.split(":")[0];
|
|
14
|
+
|
|
15
|
+
return ALLOWED_ALPHA_TEST_HOSTS.has(normalizedHost);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createAlphaOnlyHandler(
|
|
19
|
+
handler: (req: Request) => Response | Promise<Response>,
|
|
20
|
+
) {
|
|
21
|
+
return async (req: Request): Promise<Response> => {
|
|
22
|
+
const host = req.headers.get("host") || new URL(req.url).host;
|
|
23
|
+
|
|
24
|
+
if (!isAlphaTestHost(host)) {
|
|
25
|
+
return new Response("alpha test routes disabled", { status: 403 });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return handler(req);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// 文件路径: packages/server/handlers/apifyActorHandler.ts
|
|
2
|
+
|
|
3
|
+
import { authenticateRequest, CORS_HEADERS_AUTH } from "../../auth/utils";
|
|
4
|
+
import { getUser } from "../../auth/server/getUser";
|
|
5
|
+
import { checkBasicBalance } from "../../auth/billing";
|
|
6
|
+
import { chargeExternalTool } from "../../ai/token/externalToolCost";
|
|
7
|
+
|
|
8
|
+
const APIFY_TOKEN = process.env.APIFY_TOKEN;
|
|
9
|
+
|
|
10
|
+
type ResultType = "datasetItems" | "run" | "kvOutput";
|
|
11
|
+
|
|
12
|
+
interface ApifyActorRequestBody {
|
|
13
|
+
actorId: string;
|
|
14
|
+
input: any;
|
|
15
|
+
resultType?: ResultType;
|
|
16
|
+
dialogId?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function handleApifyActor(req: Request): Promise<Response> {
|
|
20
|
+
try {
|
|
21
|
+
// 1. 鉴权 + 余额检查
|
|
22
|
+
const auth = await authenticateRequest(req);
|
|
23
|
+
if (auth instanceof Response) return auth;
|
|
24
|
+
|
|
25
|
+
const { userId } = auth;
|
|
26
|
+
const { balance = 0 } = await getUser(userId);
|
|
27
|
+
|
|
28
|
+
const balanceCheck = checkBasicBalance(balance);
|
|
29
|
+
if (!balanceCheck.allowed && balanceCheck.error) {
|
|
30
|
+
return jsonError(
|
|
31
|
+
balanceCheck.error.status,
|
|
32
|
+
balanceCheck.error.message,
|
|
33
|
+
balanceCheck.error.code,
|
|
34
|
+
balanceCheck.error.details
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 2. 解析 body
|
|
39
|
+
const body = (await req
|
|
40
|
+
.json()
|
|
41
|
+
.catch(() => null)) as ApifyActorRequestBody | null;
|
|
42
|
+
|
|
43
|
+
if (!body || typeof body !== "object") {
|
|
44
|
+
return jsonError(
|
|
45
|
+
400,
|
|
46
|
+
"请求体必须是 JSON 对象,并包含 actorId 与 input 字段。",
|
|
47
|
+
"INVALID_BODY"
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { actorId, input, resultType = "datasetItems", dialogId } = body;
|
|
52
|
+
|
|
53
|
+
if (!actorId || typeof actorId !== "string") {
|
|
54
|
+
return jsonError(400, "缺少有效的 actorId(字符串)。", "INVALID_ACTOR");
|
|
55
|
+
}
|
|
56
|
+
if (!input || typeof input !== "object") {
|
|
57
|
+
return jsonError(400, "缺少有效的 input(对象)。", "INVALID_INPUT");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!APIFY_TOKEN) {
|
|
61
|
+
return jsonError(
|
|
62
|
+
500,
|
|
63
|
+
"后端未配置 APIFY_TOKEN 环境变量,无法调用 Apify API。",
|
|
64
|
+
"APIFY_TOKEN_MISSING"
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const normalizedActorId = actorId.replace("/", "~");
|
|
69
|
+
|
|
70
|
+
let suffix: string;
|
|
71
|
+
switch (resultType) {
|
|
72
|
+
case "run":
|
|
73
|
+
suffix = "runs";
|
|
74
|
+
break;
|
|
75
|
+
case "kvOutput":
|
|
76
|
+
suffix = "run-sync";
|
|
77
|
+
break;
|
|
78
|
+
case "datasetItems":
|
|
79
|
+
default:
|
|
80
|
+
suffix = "run-sync-get-dataset-items";
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const url = `https://api.apify.com/v2/acts/${encodeURIComponent(
|
|
85
|
+
normalizedActorId
|
|
86
|
+
)}/${suffix}?token=${APIFY_TOKEN}`;
|
|
87
|
+
|
|
88
|
+
const apifyResp = await fetch(url, {
|
|
89
|
+
method: "POST",
|
|
90
|
+
headers: { "Content-Type": "application/json" },
|
|
91
|
+
body: JSON.stringify(input),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const text = await apifyResp.text();
|
|
95
|
+
let parsed: any = text;
|
|
96
|
+
try {
|
|
97
|
+
parsed = JSON.parse(text);
|
|
98
|
+
} catch {
|
|
99
|
+
// 不是 JSON 就直接原样转发
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!apifyResp.ok) {
|
|
103
|
+
console.error("Apify 调用失败:", apifyResp.status, text);
|
|
104
|
+
return new Response(
|
|
105
|
+
JSON.stringify({
|
|
106
|
+
error: {
|
|
107
|
+
message: "调用 Apify Actor 失败",
|
|
108
|
+
status: apifyResp.status,
|
|
109
|
+
detail: parsed,
|
|
110
|
+
code: "APIFY_CALL_FAILED",
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
{
|
|
114
|
+
status: 502,
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
...CORS_HEADERS_AUTH,
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 扣费:Apify Actor 运行成功后按次收费
|
|
124
|
+
await chargeExternalTool({
|
|
125
|
+
userId,
|
|
126
|
+
toolId: "apify_actor_run",
|
|
127
|
+
dialogId,
|
|
128
|
+
reason: `apify_actor:${actorId}`,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return new Response(JSON.stringify(parsed), {
|
|
132
|
+
status: 200,
|
|
133
|
+
headers: {
|
|
134
|
+
"Content-Type": "application/json",
|
|
135
|
+
...CORS_HEADERS_AUTH,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
} catch (err: any) {
|
|
139
|
+
console.error("handleApifyActor 发生异常:", err);
|
|
140
|
+
return jsonError(
|
|
141
|
+
500,
|
|
142
|
+
`服务器内部错误: ${err?.message || String(err)}`,
|
|
143
|
+
"INTERNAL_ERROR"
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function jsonError(
|
|
149
|
+
status: number,
|
|
150
|
+
message: string,
|
|
151
|
+
code: string = "APIFY_ERROR",
|
|
152
|
+
detail?: any
|
|
153
|
+
): Response {
|
|
154
|
+
return new Response(
|
|
155
|
+
JSON.stringify({
|
|
156
|
+
error: {
|
|
157
|
+
message,
|
|
158
|
+
code,
|
|
159
|
+
detail,
|
|
160
|
+
},
|
|
161
|
+
}),
|
|
162
|
+
{
|
|
163
|
+
status,
|
|
164
|
+
headers: {
|
|
165
|
+
"Content-Type": "application/json",
|
|
166
|
+
...CORS_HEADERS_AUTH,
|
|
167
|
+
},
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}
|