nolo-cli 0.1.30 → 0.1.31
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/agentRecordConfig.ts +0 -2
- package/agent-runtime/hostAdapter.ts +0 -1
- package/agent-runtime/hostRuntimeCapabilities.ts +7 -0
- package/agent-runtime/hostRuntimeConfig.ts +86 -0
- package/agent-runtime/index.ts +13 -0
- package/agent-runtime/localToolPolicy.ts +13 -6
- package/agent-runtime/localWorkspaceTools.ts +333 -30
- package/agent-runtime/platformChatProvider.ts +4 -1
- package/agent-runtime/runtimeToolPolicy.ts +32 -47
- package/agent-runtime/shellCommandPolicy.ts +117 -0
- package/agent-runtime/toolGate.ts +38 -0
- package/agentRecordCommands.ts +1 -1
- package/agentRecordHelpers.ts +35 -20
- package/agentRunParsing.ts +18 -5
- package/agentRuntimeLocal.ts +10 -0
- package/ai/agent/agentRunDialogLineage.ts +56 -0
- package/ai/agent/agentSlice.ts +45 -10
- package/ai/agent/avatarUtils.ts +1 -1
- package/ai/agent/buildSystemPrompt.ts +1 -2
- package/ai/agent/cliExecutor.ts +330 -19
- package/ai/agent/createAgentSchema.ts +22 -0
- package/ai/agent/hooks/fetchPublicAgents.ts +14 -39
- package/ai/agent/hooks/usePublicAgents.ts +90 -192
- package/ai/agent/publicAgentCatalog.ts +359 -0
- package/ai/agent/publicAgentIdentity.ts +76 -0
- package/ai/agent/server/fetchPublicAgents.ts +21 -46
- package/ai/agent/serverOrigin.ts +7 -0
- package/ai/agent/streamAgentChatTurn.ts +23 -21
- package/ai/agent/streamAgentChatTurnUtils.ts +292 -6
- package/ai/agent/types.ts +2 -0
- package/ai/agent/web/agentDisplayUtils.ts +171 -0
- package/ai/agent/web/useAgentModelAvatarComponent.ts +32 -0
- package/ai/ai.locale.ts +8 -0
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +15 -0
- package/ai/chat/sendOpenAICompletionsRequest.ts +93 -1
- package/ai/chat/sendOpenAIResponseRequest.ts +86 -9
- package/ai/chat/updateTotalUsage.ts +7 -0
- package/ai/llm/deepinfra.ts +30 -15
- package/ai/llm/mistral.ts +3 -4
- package/ai/llm/providers.ts +2 -0
- package/ai/llm/types.ts +15 -0
- package/ai/memory/capture.ts +3 -3
- package/ai/memory/consolidate.ts +2 -2
- package/ai/memory/delete.ts +4 -3
- package/ai/memory/query.ts +3 -3
- package/ai/memory/remember.ts +2 -2
- package/ai/memory/store.ts +3 -3
- package/ai/memory/storeShared.ts +3 -2
- package/ai/policy/commercialMultiplier.ts +16 -0
- package/ai/token/billingAdminAuditEvent.ts +68 -0
- package/ai/token/billingAdminAuditEventWriter.ts +41 -0
- package/ai/token/billingAnomaly.ts +90 -0
- package/ai/token/billingAnomalyLifecycle.ts +54 -0
- package/ai/token/billingAnomalyLifecycleWriter.ts +44 -0
- package/ai/token/billingAnomalyWriter.ts +41 -0
- package/ai/token/calculatePrice.ts +3 -2
- package/ai/token/deepinfraReconciliation.ts +153 -0
- package/ai/token/deepinfraRequestIdQuery.ts +92 -0
- package/ai/token/externalToolCost.ts +54 -41
- package/ai/token/missingUsageEstimate.ts +12 -3
- package/ai/token/normalizeUsage.ts +45 -5
- package/ai/token/openaiReconciliation.ts +188 -0
- package/ai/token/providerBillableEvent.ts +84 -0
- package/ai/token/providerBillableEventWriter.ts +36 -0
- package/ai/token/providerBillingAnomalyDrilldown.ts +308 -0
- package/ai/token/providerBillingDrilldown.ts +361 -0
- package/ai/token/providerBillingHealthReport.ts +366 -0
- package/ai/token/providerCall.ts +144 -0
- package/ai/token/providerCallSweeper.ts +168 -0
- package/ai/token/providerCallWriter.ts +33 -0
- package/ai/token/providerCredential.ts +89 -0
- package/ai/token/providerCredentialAnomaly.ts +154 -0
- package/ai/token/providerCredentialLifecycle.ts +59 -0
- package/ai/token/providerCredentialLifecycleWriter.ts +44 -0
- package/ai/token/providerCredentialRegistry.ts +83 -0
- package/ai/token/providerCredentialRegistryCommand.ts +97 -0
- package/ai/token/providerCredentialRegistryList.ts +124 -0
- package/ai/token/providerCredentialRegistryResolver.ts +150 -0
- package/ai/token/providerCredentialRegistryWriter.ts +41 -0
- package/ai/token/providerCredentialRotationCommand.ts +102 -0
- package/ai/token/providerCredentialRuntime.ts +56 -0
- package/ai/token/providerDispatchIntent.ts +67 -0
- package/ai/token/providerDispatchIntentWriter.ts +36 -0
- package/ai/token/providerGateway.ts +260 -0
- package/ai/token/providerReconciliation.ts +148 -0
- package/ai/token/providerReconciliationLocal.ts +97 -0
- package/ai/token/providerReconciliationRunner.ts +165 -0
- package/ai/token/providerReconciliationWriter.ts +41 -0
- package/ai/token/ratingResult.ts +202 -0
- package/ai/token/ratingResultWriter.ts +33 -0
- package/ai/token/serverDialogProjection.ts +5 -3
- package/ai/token/serverTokenWriter.ts +11 -3
- package/ai/token/types.ts +10 -0
- package/ai/tools/agent/callAgentTool.ts +3 -4
- package/ai/tools/agent/presets/appBuilderPreset.ts +5 -7
- package/ai/tools/agent/runStreamingAgentTool.ts +1 -2
- package/ai/tools/agent/streamParallelAgentsTool.ts +2 -3
- package/ai/tools/readXPostTool.ts +1 -5
- package/app/admin/adminPages.ts +9 -0
- package/app/i18n/i18n.config.ts +5 -0
- package/app/i18n/translations/pricing.locale.ts +397 -0
- package/app/utils/desktopAgentRuntimeStatusClient.ts +5 -4
- package/app/utils/desktopAgentRuntimeTurnClient.ts +4 -1
- package/app/utils/imageUtils.ts +64 -34
- package/auth/adminPermissions.ts +18 -0
- package/auth/authSlice.ts +26 -12
- package/auth/hooks/useFetchUsers.ts +3 -0
- package/auth/routes.ts +46 -0
- package/auth/server/accessActivity.ts +4 -3
- package/auth/server/adminPermissions.ts +43 -0
- package/auth/server/adminUsageReport.ts +375 -0
- package/auth/server/billingAnomalies.ts +235 -0
- package/auth/server/billingUsageReport.ts +41 -2
- package/auth/server/creatorEarningCreditConversion.ts +10 -2
- package/auth/server/deduct.ts +14 -7
- package/auth/server/delete.ts +10 -2
- package/auth/server/disable.ts +4 -3
- package/auth/server/emailAutomation.ts +7 -5
- package/auth/server/emailDbConfig.ts +4 -2
- package/auth/server/emailDelivery.ts +24 -20
- package/auth/server/emailDeliveryGuards.ts +10 -7
- package/auth/server/emailPreferences.ts +6 -4
- package/auth/server/emailReport.ts +6 -4
- package/auth/server/emailRuntimeConfig.ts +3 -3
- package/auth/server/emailScenarioNotifications.ts +9 -8
- package/auth/server/enable.ts +4 -3
- package/auth/server/getRechargeHistory.ts +3 -2
- package/auth/server/getUser.ts +3 -2
- package/auth/server/gptProAccess.ts +44 -0
- package/auth/server/inviteReward.ts +10 -7
- package/auth/server/listusers.ts +6 -4
- package/auth/server/login.ts +2 -2
- package/auth/server/productEntitlements.ts +7 -4
- package/auth/server/productPurchase.ts +10 -2
- package/auth/server/providerBillingDrilldown.ts +47 -0
- package/auth/server/providerBillingHealth.ts +71 -0
- package/auth/server/providerCredentials.ts +136 -0
- package/auth/server/recharge.ts +14 -8
- package/auth/server/revokeSessions.ts +4 -3
- package/auth/server/route.ts +77 -0
- package/auth/server/sendEmail.ts +5 -4
- package/auth/server/signup.ts +10 -3
- package/auth/server/token.ts +53 -55
- package/auth/server/tokenUsageBilling.ts +18 -7
- package/auth/server/usageManagementAccess.ts +43 -0
- package/auth/server/usageReport.ts +59 -0
- package/auth/types.ts +12 -0
- package/auth/utils.ts +24 -22
- package/authCommands.ts +36 -2
- package/buildPublish.ts +3 -1
- package/buildPublishArtifactAssembly.ts +62 -1
- package/buildPublishImportAnalysis.ts +21 -16
- package/chat/dialog/dialogLaunchScope.ts +32 -0
- package/chat/dialog/objectAssistantRegistry.ts +2 -2
- package/chat/dialog/useCreateDialog.ts +1 -1
- package/chat/hooks/useChatInput.ts +41 -10
- package/chat/messages/messageSlice.ts +5 -1
- package/chat/messages/pendingAttachmentParts.ts +28 -2
- package/chat/messages/sendFirstMessage.ts +76 -79
- package/chat/messages/types.ts +9 -0
- package/chat/messages/web/streamingMarkdownModel.ts +41 -0
- package/chat/messages/web/useStreamingReveal.ts +91 -0
- package/chat/web/messageInputAgentUi.ts +94 -6
- package/cliEnvHelpers.ts +8 -0
- package/cliRuntimeDoctorReport.ts +193 -0
- package/client/agentConfigResolver.test.ts +0 -2
- package/client/agentRun.test.ts +171 -10
- package/client/agentRun.ts +44 -637
- package/client/agentRunInput.ts +10 -0
- package/client/agentRunLocalExecutor.ts +179 -0
- package/client/agentRunServerTransport.ts +394 -0
- package/client/agentRunTaskRunRecorder.ts +176 -0
- package/client/localRuntimeAdapter.test.ts +236 -9
- package/client/localRuntimeAdapter.ts +221 -23
- package/client/localToolPolicy.test.ts +28 -4
- package/connector-experimental/daemonLauncher.ts +38 -4
- package/connectorRunArtifact.ts +34 -10
- package/connectorWebSocketTarget.ts +9 -5
- package/core/builtinAgents.ts +155 -11
- package/create/space/contentLabels.ts +1 -1
- package/create/space/contentTypeMeta.ts +3 -2
- package/create/space/sidebarVisibleTypes.ts +27 -0
- package/create/space/space.locale.ts +76 -4
- package/database/actions/agentReadResolution.ts +2 -8
- package/database/actions/read.ts +11 -9
- package/database/actions/readAndWait.ts +10 -5
- package/database/server/agentDelegation.ts +3 -2
- package/database/server/authorityStoreConformance.ts +209 -0
- package/database/server/authorityStoreTypes.ts +31 -0
- package/database/server/coreDataProxy.ts +1 -1
- package/database/server/dataHandlers.ts +13 -5
- package/database/server/db.ts +15 -34
- package/database/server/delete.ts +88 -71
- package/database/server/emailRepository.ts +11 -9
- package/database/server/fileService.ts +2 -1
- package/database/server/legacyServerDb.ts +58 -0
- package/database/server/levelAuthorityStore.ts +75 -0
- package/database/server/memoryAuthorityStore.ts +133 -0
- package/database/server/patch.ts +13 -12
- package/database/server/query.ts +3 -2
- package/database/server/read.ts +33 -30
- package/database/server/resourceAccess.ts +7 -5
- package/database/server/serverStoreFactory.ts +124 -0
- package/database/server/spaceMemberAuthority.ts +3 -2
- package/database/server/storeBatchCompat.ts +37 -0
- package/database/server/testAuthorityStore.ts +76 -0
- package/database/server/write.ts +29 -27
- package/integrations/anthropic/anthropicModels.ts +12 -12
- package/integrations/deepseek/models.ts +67 -67
- package/integrations/google/models.ts +111 -53
- package/integrations/openai/models.ts +22 -22
- package/integrations/xai/models.ts +1 -1
- package/localRuntimeDb.ts +39 -2
- package/machineCommandPrompts.ts +2 -0
- package/machineCommands.ts +193 -63
- package/machineWsRunDispatch.ts +80 -15
- package/machineWsSession.ts +39 -2
- package/noloReadBridgePrompt.ts +16 -0
- package/package.json +99 -6
- package/render/layout/mainLayoutViewMode.ts +25 -0
- package/render/page/server/createPage.ts +3 -1
- package/render/page/server/handleCreatePage.ts +2 -11
- package/runtimeDoctorCommands.ts +15 -66
- package/server/api/methods.ts +34 -12
- package/server/api/tableHandlers.ts +6 -3
- package/server/authenticateToken.ts +47 -2
- package/server/billingLedgerRoutes.ts +15 -0
- package/server/buildManifest.ts +54 -0
- package/server/coreReadiness.ts +34 -25
- package/server/coreRuntime.ts +15 -10
- package/server/handlers/activityStatsHandler.ts +5 -2
- package/server/handlers/agentEmailRegistrationE2EHandler.ts +25 -23
- package/server/handlers/agentRun/agentLookup.ts +1 -7
- package/server/handlers/agentRun/autonomousRuntime.ts +11 -10
- package/server/handlers/agentRun/builtinAgents.ts +12 -88
- package/server/handlers/agentRun/continueDialogContext.ts +15 -3
- package/server/handlers/agentRun/{inheritedDialogPrompt.ts → conversationReference.ts} +3 -3
- package/server/handlers/agentRun/dialogLookup.ts +4 -3
- package/server/handlers/agentRun/index.ts +864 -404
- package/server/handlers/agentRun/localRuntimeBootstrap.ts +17 -1
- package/server/handlers/agentRun/loop.ts +920 -508
- package/server/handlers/agentRun/machineConnector.ts +56 -8
- package/server/handlers/agentRun/machineRunAudit.ts +3 -2
- package/server/handlers/agentRun/modelUsageToolHandlers.ts +13 -10
- package/server/handlers/agentRun/requestContext.ts +12 -8
- package/server/handlers/agentRun/runtimeExecutionContext.ts +15 -3
- package/server/handlers/agentRun/runtimePreparation.ts +26 -24
- package/server/handlers/agentRun/runtimeRouting.ts +25 -40
- package/server/handlers/agentRun/runtimeSystemMessages.ts +65 -0
- package/server/handlers/agentRun/saveDialog.ts +97 -87
- package/server/handlers/agentRun/taskRunToolHandler.ts +9 -7
- package/server/handlers/agentRun/toolExecutor.ts +42 -78
- package/server/handlers/agentRun/types.ts +2 -1
- package/server/handlers/appDeployStatusStore.ts +17 -10
- package/server/handlers/appDomainHandler.ts +21 -15
- package/server/handlers/appLegacyInfraCleanup.ts +5 -2
- package/server/handlers/appSandboxHandler.ts +29 -8
- package/server/handlers/appSpaceAccess.ts +15 -8
- package/server/handlers/chatHandler.ts +22 -2
- package/server/handlers/chatUpstreamRetry.ts +225 -2
- package/server/handlers/connector/connectorConnectionRegistry.ts +55 -7
- package/server/handlers/connector/connectorWebSocket.ts +14 -10
- package/server/handlers/desktopAgentRuntimeAdapter.ts +4 -4
- package/server/handlers/desktopAgentRuntimeHostCapabilities.ts +25 -0
- package/server/handlers/desktopAgentRuntimeReadiness.ts +62 -0
- package/server/handlers/desktopAgentRuntimeStatusHandler.ts +38 -30
- package/server/handlers/desktopAgentRuntimeTurnHandler.ts +7 -3
- package/server/handlers/desktopAgentRuntimeTurnService.ts +39 -45
- package/server/handlers/desktopLlamaRuntimeHandler.ts +85 -51
- package/server/handlers/desktopUpdaterHandler.ts +132 -24
- package/server/handlers/favoriteHandlers.ts +8 -2
- package/server/handlers/getDialogBillingHandler.ts +4 -3
- package/server/handlers/getTransactionsHandler.ts +5 -2
- package/server/handlers/machines/machineBinding.ts +1 -0
- package/server/handlers/machines/machineHandlers.ts +0 -14
- package/server/handlers/machines/machineInstallAssets.ts +4 -2
- package/server/handlers/notificationEmitter.ts +5 -3
- package/server/handlers/notificationsHandler.ts +5 -2
- package/server/handlers/providerCallsRecentHandler.ts +234 -0
- package/server/handlers/providerReconciliationRunHandler.ts +180 -0
- package/server/handlers/providerRequestIdsHandler.ts +105 -0
- package/server/handlers/tableAccess.ts +6 -2
- package/server/handlers/tableToolHandlers.ts +28 -14
- package/server/handlers/userSecretsHandler.ts +17 -6
- package/server/handlers/versionHandler.ts +9 -4
- package/server/handlers/versionStore.ts +18 -10
- package/server/html/ssrPreload.ts +5 -3
- package/server/payments/crypto/cryptoUsdcBasePaymentProvider.ts +11 -8
- package/server/payments/crypto/cryptoUsdcBaseScanner.ts +12 -7
- package/server/payments/crypto/cryptoUsdtTronPaymentProvider.ts +11 -8
- package/server/payments/crypto/cryptoUsdtTronScanner.ts +9 -7
- package/server/payments/waffo/waffoPaymentProvider.ts +12 -9
- package/server/runtimeRole.ts +15 -0
- package/server/scheduler/scheduledTaskRuntime.ts +4 -2
- package/server/scheduler/schedulerService.ts +2 -2
- package/server/taskRunBridgeRoutes.ts +8 -5
- package/share/server/fetchCommunityShares.ts +1 -1
- package/share/server/helpers.ts +19 -17
- package/share/server/importShare.ts +9 -13
- package/share/server/listCommunityShares.ts +4 -4
- package/share/server/purchaseDoc.ts +8 -16
- package/share/server/readCommunityShareCover.ts +3 -2
- package/share/server/readSharedTable.ts +14 -13
- package/share/server/tableReplication.ts +42 -39
- package/spaceAttachCommands.ts +135 -0
- package/spaceInternalCommandEntries.ts +2 -0
- package/ai/agent/runtimeServerBase.ts +0 -37
- package/server/handlers/desktopAgentRuntimeHostFacts.ts +0 -40
|
@@ -9,10 +9,9 @@ import {
|
|
|
9
9
|
} from "@waffo/pancake-ts";
|
|
10
10
|
import { ulid } from "ulid";
|
|
11
11
|
import { CORS_HEADERS_AUTH } from "../../../auth/utils";
|
|
12
|
-
import {
|
|
12
|
+
import { readUserFromRequest } from "../../../auth/server/token";
|
|
13
13
|
import { rechargeUserBalance } from "../../../auth/server/recharge";
|
|
14
|
-
import
|
|
15
|
-
import { createResponse } from "../../createResponse";
|
|
14
|
+
import { getServerAuthorityStore } from "../../../database/server/db";
|
|
16
15
|
import type { PaymentProvider } from "../paymentProvider";
|
|
17
16
|
import {
|
|
18
17
|
getRechargeCreditLimits,
|
|
@@ -63,6 +62,8 @@ const jsonError = (
|
|
|
63
62
|
const paymentKey = (paymentRequestId: string) =>
|
|
64
63
|
`${WAFFO_PAYMENT_PREFIX}${paymentRequestId}`;
|
|
65
64
|
|
|
65
|
+
const getWaffoStore = () => getServerAuthorityStore();
|
|
66
|
+
|
|
66
67
|
const getMerchantId = () =>
|
|
67
68
|
process.env.WAFFO_MERCHANT_ID?.trim() || DEFAULT_MERCHANT_ID;
|
|
68
69
|
|
|
@@ -156,8 +157,10 @@ export const handleCreateWaffoOrder = async (req: Request) => {
|
|
|
156
157
|
);
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
const authResult = await
|
|
160
|
-
if (authResult
|
|
160
|
+
const authResult = await readUserFromRequest(req);
|
|
161
|
+
if (!authResult?.userId) {
|
|
162
|
+
return jsonError(401, "Authentication required.", "AUTH_REQUIRED");
|
|
163
|
+
}
|
|
161
164
|
|
|
162
165
|
let body: any = {};
|
|
163
166
|
try {
|
|
@@ -178,7 +181,7 @@ export const handleCreateWaffoOrder = async (req: Request) => {
|
|
|
178
181
|
const { credits } = validation;
|
|
179
182
|
|
|
180
183
|
const userId = String(authResult.userId || "");
|
|
181
|
-
const user = await
|
|
184
|
+
const user = await getWaffoStore().get(`user:${userId}`).catch(() => null);
|
|
182
185
|
const username =
|
|
183
186
|
typeof user?.username === "string"
|
|
184
187
|
? user.username
|
|
@@ -233,7 +236,7 @@ export const handleCreateWaffoOrder = async (req: Request) => {
|
|
|
233
236
|
tokenExpiresAt: result.tokenExpiresAt,
|
|
234
237
|
},
|
|
235
238
|
};
|
|
236
|
-
await
|
|
239
|
+
await getWaffoStore().put(paymentKey(paymentRequestId), record);
|
|
237
240
|
|
|
238
241
|
return jsonResponse({
|
|
239
242
|
success: true,
|
|
@@ -300,7 +303,7 @@ export const handleWaffoWebhook = async (req: Request) => {
|
|
|
300
303
|
}
|
|
301
304
|
|
|
302
305
|
const key = paymentKey(paymentRequestId);
|
|
303
|
-
const record = (await
|
|
306
|
+
const record = (await getWaffoStore().get(key).catch(() => null)) as
|
|
304
307
|
| WaffoPaymentRecord
|
|
305
308
|
| null;
|
|
306
309
|
if (!record) {
|
|
@@ -310,7 +313,7 @@ export const handleWaffoWebhook = async (req: Request) => {
|
|
|
310
313
|
});
|
|
311
314
|
}
|
|
312
315
|
|
|
313
|
-
await
|
|
316
|
+
await getWaffoStore().put(key, {
|
|
314
317
|
...record,
|
|
315
318
|
status: "paid",
|
|
316
319
|
updatedAt: Date.now(),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type NoloRuntimeRole = "core" | "overlay" | "web";
|
|
2
|
+
|
|
3
|
+
export function resolveRuntimeRole(
|
|
4
|
+
env: Record<string, string | undefined> = process.env
|
|
5
|
+
): NoloRuntimeRole {
|
|
6
|
+
const raw = String(env.NOLO_SERVER_RUNTIME_ROLE || "")
|
|
7
|
+
.trim()
|
|
8
|
+
.toLowerCase();
|
|
9
|
+
if (raw === "overlay" || raw === "web") return raw;
|
|
10
|
+
return "core";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function shouldRunBackgroundWorkers(role: NoloRuntimeRole): boolean {
|
|
14
|
+
return role === "core";
|
|
15
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Agent, DialogConfig, ScheduledTaskConfig } from "../../app/types";
|
|
2
2
|
import { DataType } from "../../create/types";
|
|
3
|
-
import
|
|
3
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
4
4
|
import { createDialogKey, createUserKey } from "../../database/keys";
|
|
5
5
|
import { extractCustomId } from "../../core/prefix";
|
|
6
6
|
import { resolveMemoryRuntime } from "../../ai/memory/runtime";
|
|
@@ -23,8 +23,10 @@ import { resolveAutonomousRuntimeContext } from "../handlers/agentRun/autonomous
|
|
|
23
23
|
|
|
24
24
|
export const DEFAULT_SCHEDULED_MAX_ROUNDS = 12;
|
|
25
25
|
|
|
26
|
+
const getScheduledTaskRuntimeStore = () => getServerAuthorityStore();
|
|
27
|
+
|
|
26
28
|
const defaultRuntimeDeps = {
|
|
27
|
-
serverDb,
|
|
29
|
+
serverDb: getScheduledTaskRuntimeStore(),
|
|
28
30
|
fetchConvMsgs,
|
|
29
31
|
runAgentLoop,
|
|
30
32
|
appendToExistingDialog,
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* 生命周期由 server/entry.ts 管理(startAgentTaskScheduler / stopAgentTaskScheduler)。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
11
11
|
import { DataType } from "../../create/types";
|
|
12
12
|
import type { DialogConfig, ScheduledTaskConfig } from "../../app/types";
|
|
13
13
|
import { executeScheduledTaskRun } from "./scheduledTaskRuntime";
|
|
14
14
|
|
|
15
15
|
const defaultSchedulerDeps = {
|
|
16
|
-
serverDb,
|
|
16
|
+
serverDb: getServerAuthorityStore(),
|
|
17
17
|
executeScheduledTaskRun,
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readUserFromRequest } from "../auth/server/token";
|
|
2
2
|
import { createApiRouteFamily } from "./apiRouteAdapter";
|
|
3
3
|
import { DataType } from "../create/types";
|
|
4
4
|
import { createKey } from "../database/keys";
|
|
5
|
-
import
|
|
5
|
+
import { getServerAuthorityStore } from "../database/server/db";
|
|
6
6
|
import { fetchMessages } from "../chat/messages/fetchMessages";
|
|
7
7
|
import { authenticateMachineToken } from "./handlers/machines/machineAuth";
|
|
8
8
|
import {
|
|
@@ -15,6 +15,8 @@ const JSON_HEADERS: Record<string, string> = {
|
|
|
15
15
|
"Access-Control-Allow-Origin": "*",
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const getTaskRunBridgeStore = () => getServerAuthorityStore();
|
|
19
|
+
|
|
18
20
|
function json(body: unknown, status = 200) {
|
|
19
21
|
return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS });
|
|
20
22
|
}
|
|
@@ -24,7 +26,7 @@ async function authenticateTaskRunBridge(req: Request): Promise<{ userId: string
|
|
|
24
26
|
if (machineAuth instanceof Response) return machineAuth;
|
|
25
27
|
if (machineAuth?.userId) return { userId: machineAuth.userId };
|
|
26
28
|
|
|
27
|
-
const user = await
|
|
29
|
+
const user = await readUserFromRequest(req);
|
|
28
30
|
if (!user?.userId) {
|
|
29
31
|
return json({ ok: false, error: "Unauthorized" }, 401);
|
|
30
32
|
}
|
|
@@ -70,9 +72,10 @@ export async function handleDialogReadBridge(req: Request) {
|
|
|
70
72
|
: 50;
|
|
71
73
|
|
|
72
74
|
try {
|
|
75
|
+
const store = getTaskRunBridgeStore();
|
|
73
76
|
const [meta, msgs] = await Promise.all([
|
|
74
|
-
|
|
75
|
-
fetchMessages(
|
|
77
|
+
store.get(expectedDialogKey),
|
|
78
|
+
fetchMessages(store, dialogId, { limit, throwOnError: true }),
|
|
76
79
|
]);
|
|
77
80
|
return json({ ok: true, meta, msgs });
|
|
78
81
|
} catch (error) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 路径: share/server/fetchCommunityShares.ts
|
|
2
2
|
// 职责:SSR 专用——直接读取 serverDb,获取社区分享列表,供 render.tsx 预载使用
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { ensureServerDbOpen } from "../../database/server/db";
|
|
5
5
|
import { shareKey } from "../keys";
|
|
6
6
|
import type { ShareSummary } from "../types";
|
|
7
7
|
import { scanIndexToSummaries } from "./helpers";
|
package/share/server/helpers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
2
2
|
import { shareKey } from "../keys";
|
|
3
3
|
import { isShareType, type ShareSummary, type ShareType } from "../types";
|
|
4
4
|
import { DataType } from "../../create/types";
|
|
@@ -48,12 +48,13 @@ export const resolveIndexedDbKey = (raw: any): string => {
|
|
|
48
48
|
return "";
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
export const readShareByDbKey = async (dbKey: string): Promise<any | null> => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
export const readShareByDbKey = async (dbKey: string): Promise<any | null> => {
|
|
52
|
+
const store = getServerAuthorityStore();
|
|
53
|
+
try {
|
|
54
|
+
return await store.get(dbKey);
|
|
55
|
+
} catch (error: unknown) {
|
|
56
|
+
if (isLevelNotFoundError(error)) return null;
|
|
57
|
+
throw error;
|
|
57
58
|
}
|
|
58
59
|
};
|
|
59
60
|
|
|
@@ -165,15 +166,16 @@ export const toShareSummary = (
|
|
|
165
166
|
|
|
166
167
|
// ── Generic index scan → ShareSummary[] ─────────────────────────────
|
|
167
168
|
|
|
168
|
-
export const scanIndexToSummaries = async (
|
|
169
|
-
range: { start: string; end: string },
|
|
170
|
-
limit: number,
|
|
171
|
-
cursor: string | undefined,
|
|
172
|
-
summaryOptions: ToSummaryOptions = {}
|
|
173
|
-
): Promise<{ shares: ShareSummary[]; nextCursor?: string }> => {
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
|
|
169
|
+
export const scanIndexToSummaries = async (
|
|
170
|
+
range: { start: string; end: string },
|
|
171
|
+
limit: number,
|
|
172
|
+
cursor: string | undefined,
|
|
173
|
+
summaryOptions: ToSummaryOptions = {}
|
|
174
|
+
): Promise<{ shares: ShareSummary[]; nextCursor?: string }> => {
|
|
175
|
+
const store = getServerAuthorityStore();
|
|
176
|
+
const shares: ShareSummary[] = [];
|
|
177
|
+
const seen = new Set<string>();
|
|
178
|
+
let lastIndexKey = "";
|
|
177
179
|
|
|
178
180
|
const iterOptions: any = { gte: range.start, lte: range.end };
|
|
179
181
|
if (cursor) {
|
|
@@ -181,7 +183,7 @@ export const scanIndexToSummaries = async (
|
|
|
181
183
|
delete iterOptions.gte;
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
for await (const [indexKey, rawIndexValue] of
|
|
186
|
+
for await (const [indexKey, rawIndexValue] of store.iterator(iterOptions)) {
|
|
185
187
|
if (shares.length >= limit) {
|
|
186
188
|
return { shares, nextCursor: lastIndexKey };
|
|
187
189
|
}
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
* 5. importCount +1(一次,不重复)
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { readUserFromRequest } from "../../auth/server/token";
|
|
16
16
|
import {
|
|
17
17
|
getProductPriceCredits,
|
|
18
18
|
hasActiveEntitlement,
|
|
19
19
|
} from "../../auth/server/productEntitlements";
|
|
20
|
-
import
|
|
20
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
21
21
|
import { logger } from "../../auth/server/shared";
|
|
22
22
|
import { createPageServer } from "../../render/page/server/createPage";
|
|
23
23
|
import { resolveSharePaidAccess } from "../paidAccess";
|
|
@@ -37,22 +37,17 @@ const extractToken = (req: Request): string | null => {
|
|
|
37
37
|
|
|
38
38
|
/** 认证,token 无效 / 缺失时返回 null */
|
|
39
39
|
async function authenticate(req: Request): Promise<string | null> {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const user = await handleToken(authReq, mockRes);
|
|
44
|
-
return user?.userId ?? null;
|
|
45
|
-
} catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
40
|
+
const user = await readUserFromRequest(req);
|
|
41
|
+
return user?.userId ?? null;
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
/** 原子自增 importCount(最终一致,不需要严格原子性) */
|
|
51
45
|
async function incrementImportCount(token: string): Promise<void> {
|
|
46
|
+
const store = getServerAuthorityStore();
|
|
52
47
|
const dbKey = `share-${token}`;
|
|
53
48
|
try {
|
|
54
|
-
const record: any = await
|
|
55
|
-
await
|
|
49
|
+
const record: any = await store.get(dbKey);
|
|
50
|
+
await store.put(dbKey, {
|
|
56
51
|
...record,
|
|
57
52
|
meta: { ...(record?.meta ?? {}), importCount: (record?.meta?.importCount ?? 0) + 1 },
|
|
58
53
|
});
|
|
@@ -70,6 +65,7 @@ export async function handleImportShare(req: Request): Promise<Response> {
|
|
|
70
65
|
new Response(JSON.stringify({ success: false, message: "请先登录" }), { status: 401, headers: CORS_HEADERS });
|
|
71
66
|
|
|
72
67
|
try {
|
|
68
|
+
const store = getServerAuthorityStore();
|
|
73
69
|
// 1. 鉴权
|
|
74
70
|
const userId = await authenticate(req);
|
|
75
71
|
if (!userId) return json401();
|
|
@@ -81,7 +77,7 @@ export async function handleImportShare(req: Request): Promise<Response> {
|
|
|
81
77
|
// 3. 读取 share 记录
|
|
82
78
|
let shareData: any;
|
|
83
79
|
try {
|
|
84
|
-
shareData = await
|
|
80
|
+
shareData = await store.get(`share-${token}`);
|
|
85
81
|
} catch {
|
|
86
82
|
return new Response(
|
|
87
83
|
JSON.stringify({ success: false, message: "分享不存在" }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ensureServerDbOpen } from "../../database/server/db";
|
|
1
|
+
import { ensureServerDbOpen, getServerAuthorityStore } from "../../database/server/db";
|
|
2
2
|
import { shareKey } from "../keys";
|
|
3
3
|
import { normalizeUserId } from "../helpers";
|
|
4
4
|
import {
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
scanIndexToSummaries,
|
|
10
10
|
toShareSummary,
|
|
11
11
|
} from "./helpers";
|
|
12
|
-
import serverDb from "../../database/server/db";
|
|
13
12
|
import { parseToken, verifyToken } from "../../auth/token";
|
|
14
13
|
import { assertSessionTokenVersion } from "../../auth/sessionTokenVersion";
|
|
15
14
|
import { DB_PREFIX } from "../../database/keys";
|
|
@@ -43,6 +42,7 @@ export const handleListCreatorCommunityShares = async (req: ShareListRequest) =>
|
|
|
43
42
|
|
|
44
43
|
try {
|
|
45
44
|
await ensureServerDbOpen();
|
|
45
|
+
const store = getServerAuthorityStore();
|
|
46
46
|
|
|
47
47
|
const range = shareKey.communityCreatorRange(requestedUserId);
|
|
48
48
|
const result = await scanIndexToSummaries(range, limit, cursor, {
|
|
@@ -55,7 +55,7 @@ export const handleListCreatorCommunityShares = async (req: ShareListRequest) =>
|
|
|
55
55
|
if (result.shares.length === 0 && !cursor) {
|
|
56
56
|
const shareRange = shareKey.range();
|
|
57
57
|
const legacyShares = [];
|
|
58
|
-
for await (const [dbKey, rawValue] of
|
|
58
|
+
for await (const [dbKey, rawValue] of store.iterator({
|
|
59
59
|
gte: shareRange.start,
|
|
60
60
|
lte: shareRange.end,
|
|
61
61
|
})) {
|
|
@@ -116,7 +116,7 @@ const getAuthorizedUserId = async (req: Request): Promise<string | null> => {
|
|
|
116
116
|
if (!userId || typeof userId !== "string") return null;
|
|
117
117
|
|
|
118
118
|
try {
|
|
119
|
-
const user = await
|
|
119
|
+
const user = await getServerAuthorityStore().get(`${DB_PREFIX.USER}${userId}`);
|
|
120
120
|
if (!user?.publicKey || user?.isDisabled) return null;
|
|
121
121
|
|
|
122
122
|
const payload = verifyToken(token, user.publicKey);
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* - 检查当前用户是否有权访问(已购买或免费)
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
12
|
+
import { readUserFromRequest } from "../../auth/server/token";
|
|
13
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
14
14
|
import { logger } from "../../auth/server/shared";
|
|
15
15
|
import {
|
|
16
16
|
getProductPriceCredits,
|
|
@@ -36,24 +36,15 @@ const extractToken = (req: Request): string | null => {
|
|
|
36
36
|
|
|
37
37
|
/** 认证并返回 userId,无 token 时返回 null(不抛错) */
|
|
38
38
|
async function authenticate(req: Request): Promise<string | null> {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
// 我们用 mock 让它静默返回 null
|
|
42
|
-
const mockRes: any = {
|
|
43
|
-
status: () => ({ json: () => null }),
|
|
44
|
-
};
|
|
45
|
-
try {
|
|
46
|
-
const user = await handleToken(authReq, mockRes);
|
|
47
|
-
return user?.userId ?? null;
|
|
48
|
-
} catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
39
|
+
const user = await readUserFromRequest(req);
|
|
40
|
+
return user?.userId ?? null;
|
|
51
41
|
}
|
|
52
42
|
|
|
53
43
|
// ── POST /api/share/:token/purchase ──────────────────────────────────
|
|
54
44
|
|
|
55
45
|
export async function handlePurchaseDoc(req: Request): Promise<Response> {
|
|
56
46
|
try {
|
|
47
|
+
const store = getServerAuthorityStore();
|
|
57
48
|
const userId = await authenticate(req);
|
|
58
49
|
if (!userId) {
|
|
59
50
|
return new Response(
|
|
@@ -74,7 +65,7 @@ export async function handlePurchaseDoc(req: Request): Promise<Response> {
|
|
|
74
65
|
const shareDbKey = `share-${token}`;
|
|
75
66
|
let shareData: any;
|
|
76
67
|
try {
|
|
77
|
-
shareData = await
|
|
68
|
+
shareData = await store.get(shareDbKey);
|
|
78
69
|
} catch {
|
|
79
70
|
return new Response(
|
|
80
71
|
JSON.stringify({ success: false, message: "分享不存在" }),
|
|
@@ -158,6 +149,7 @@ export async function handlePurchaseDoc(req: Request): Promise<Response> {
|
|
|
158
149
|
|
|
159
150
|
export async function handleCheckDocAccess(req: Request): Promise<Response> {
|
|
160
151
|
try {
|
|
152
|
+
const store = getServerAuthorityStore();
|
|
161
153
|
const userId = await authenticate(req);
|
|
162
154
|
const token = extractToken(req);
|
|
163
155
|
|
|
@@ -171,7 +163,7 @@ export async function handleCheckDocAccess(req: Request): Promise<Response> {
|
|
|
171
163
|
// 读取 share 记录获取价格
|
|
172
164
|
let shareData: any;
|
|
173
165
|
try {
|
|
174
|
-
shareData = await
|
|
166
|
+
shareData = await store.get(`share-${token}`);
|
|
175
167
|
} catch {
|
|
176
168
|
return new Response(
|
|
177
169
|
JSON.stringify({ success: false, message: "分享不存在" }),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
|
-
import {
|
|
2
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
3
|
+
import { ensureDbOpen } from "../../database/server/ensureDbOpen";
|
|
3
4
|
import { shareKey } from "../keys";
|
|
4
5
|
import { toSafeString } from "../helpers";
|
|
5
6
|
import { errorResponse, readShareByDbKey } from "./helpers";
|
|
@@ -39,7 +40,7 @@ export const handleReadCommunityShareCover = async (req: CommunityCoverRequest)
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
try {
|
|
42
|
-
await
|
|
43
|
+
await ensureDbOpen(getServerAuthorityStore());
|
|
43
44
|
|
|
44
45
|
const rawShare = await readShareByDbKey(shareKey.create(token));
|
|
45
46
|
if (!rawShare || rawShare?.meta?.visibility !== "community") {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
2
2
|
import { rowKey } from "../../database/keys";
|
|
3
3
|
import { DataType } from "../../create/types";
|
|
4
4
|
import { isTombstoneRecord } from "../../database/tombstones";
|
|
@@ -62,12 +62,13 @@ const resolveRowLimit = (value: unknown): number | null => {
|
|
|
62
62
|
return parsed;
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
export async function readSharedTablePreview(
|
|
66
|
-
token: string,
|
|
67
|
-
options: ReadSharedTablePreviewOptions = {}
|
|
68
|
-
): Promise<SharedTablePreview | null> {
|
|
69
|
-
const
|
|
70
|
-
const
|
|
65
|
+
export async function readSharedTablePreview(
|
|
66
|
+
token: string,
|
|
67
|
+
options: ReadSharedTablePreviewOptions = {}
|
|
68
|
+
): Promise<SharedTablePreview | null> {
|
|
69
|
+
const store = getServerAuthorityStore();
|
|
70
|
+
const rowLimit = resolveRowLimit(options.rowLimit);
|
|
71
|
+
const shareData = await readShareByDbKey(`share-${token}`);
|
|
71
72
|
if (!shareData || isTombstoneRecord(shareData)) return null;
|
|
72
73
|
|
|
73
74
|
const liveTable = toLiveTableMetadata(shareData);
|
|
@@ -85,12 +86,12 @@ export async function readSharedTablePreview(
|
|
|
85
86
|
: null;
|
|
86
87
|
if (!tenantId || !tableId) return null;
|
|
87
88
|
|
|
88
|
-
const rows: Record<string, unknown>[] = [];
|
|
89
|
-
const { gte, lte } = rowKey.range(tenantId, tableId);
|
|
90
|
-
for await (const [, value] of
|
|
91
|
-
if (value?.type === DataType.TABLE_ROW && !value?.deletedAt) {
|
|
92
|
-
rows.push(value);
|
|
93
|
-
if (rowLimit != null && rows.length >= rowLimit) break;
|
|
89
|
+
const rows: Record<string, unknown>[] = [];
|
|
90
|
+
const { gte, lte } = rowKey.range(tenantId, tableId);
|
|
91
|
+
for await (const [, value] of store.iterator({ gte, lte })) {
|
|
92
|
+
if (value?.type === DataType.TABLE_ROW && !value?.deletedAt) {
|
|
93
|
+
rows.push(value);
|
|
94
|
+
if (rowLimit != null && rows.length >= rowLimit) break;
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { rowKey } from "../../database/keys";
|
|
3
|
-
import { noloWriteRequest } from "../../database/requests";
|
|
4
|
-
import { isTombstoneRecord } from "../../database/tombstones";
|
|
5
|
-
import { readShareByDbKey } from "./helpers";
|
|
1
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
2
|
+
import { rowKey } from "../../database/keys";
|
|
3
|
+
import { noloWriteRequest } from "../../database/requests";
|
|
4
|
+
import { isTombstoneRecord } from "../../database/tombstones";
|
|
5
|
+
import { readShareByDbKey } from "./helpers";
|
|
6
6
|
|
|
7
7
|
type BootstrapArgs = {
|
|
8
8
|
shareDbKey: string;
|
|
@@ -58,16 +58,17 @@ type MutationArgs = {
|
|
|
58
58
|
) => Promise<void>;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
const defaultPatchShareMeta = async (
|
|
62
|
-
shareDbKey: string,
|
|
63
|
-
changes: Record<string, unknown>
|
|
64
|
-
) => {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
const defaultPatchShareMeta = async (
|
|
62
|
+
shareDbKey: string,
|
|
63
|
+
changes: Record<string, unknown>
|
|
64
|
+
) => {
|
|
65
|
+
const store = getServerAuthorityStore();
|
|
66
|
+
const shareRecord = await readShareByDbKey(shareDbKey);
|
|
67
|
+
if (!shareRecord || isTombstoneRecord(shareRecord)) return;
|
|
68
|
+
await store.put(shareDbKey, {
|
|
69
|
+
...shareRecord,
|
|
70
|
+
meta: {
|
|
71
|
+
...(shareRecord.meta ?? {}),
|
|
71
72
|
...changes,
|
|
72
73
|
},
|
|
73
74
|
});
|
|
@@ -95,15 +96,16 @@ export const isLiveTableShareRecord = (shareRecord: any, tableDbKey?: string): b
|
|
|
95
96
|
|
|
96
97
|
export const patchShareMeta = defaultPatchShareMeta;
|
|
97
98
|
|
|
98
|
-
export async function findActiveLiveShareByTable(
|
|
99
|
-
tenantId: string,
|
|
100
|
-
tableId: string
|
|
101
|
-
): Promise<(Record<string, unknown> & { dbKey: string }) | null> {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
export async function findActiveLiveShareByTable(
|
|
100
|
+
tenantId: string,
|
|
101
|
+
tableId: string
|
|
102
|
+
): Promise<(Record<string, unknown> & { dbKey: string }) | null> {
|
|
103
|
+
const store = getServerAuthorityStore();
|
|
104
|
+
const tableDbKey = `meta-${tenantId}-${tableId}`;
|
|
105
|
+
for await (const [dbKey, value] of store.iterator({
|
|
106
|
+
gte: "share-",
|
|
107
|
+
lte: "share-\uffff",
|
|
108
|
+
})) {
|
|
107
109
|
if (isLiveTableShareRecord(value, tableDbKey)) {
|
|
108
110
|
return {
|
|
109
111
|
...value,
|
|
@@ -112,21 +114,22 @@ export async function findActiveLiveShareByTable(
|
|
|
112
114
|
}
|
|
113
115
|
}
|
|
114
116
|
return null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const defaultLoadOriginTableSnapshot = async (tableDbKey: string) => {
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const defaultLoadOriginTableSnapshot = async (tableDbKey: string) => {
|
|
120
|
+
const store = getServerAuthorityStore();
|
|
121
|
+
const tableMeta = await store.get(tableDbKey);
|
|
122
|
+
const tenantId =
|
|
123
|
+
typeof tableMeta?.tenantId === "string" ? tableMeta.tenantId : "";
|
|
124
|
+
const tableId = typeof tableMeta?.tableId === "string" ? tableMeta.tableId : "";
|
|
125
|
+
const rows: any[] = [];
|
|
126
|
+
|
|
127
|
+
if (tenantId && tableId) {
|
|
128
|
+
const { gte, lte } = rowKey.range(tenantId, tableId);
|
|
129
|
+
for await (const [, value] of store.iterator({ gte, lte })) {
|
|
130
|
+
if (!value?.deletedAt) {
|
|
131
|
+
rows.push(value);
|
|
132
|
+
}
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
|