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
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
2
2
|
|
|
3
3
|
export const APP_DEPLOY_JOB_PREFIX = "app-deploy-job-";
|
|
4
4
|
const APP_DEPLOY_LATEST_PREFIX = "app-deploy-latest-";
|
|
5
5
|
const APP_DEPLOY_JOB_TTL_MS = 24 * 60 * 60 * 1000;
|
|
6
6
|
|
|
7
|
+
const getAppDeployStatusStore = () => getServerAuthorityStore();
|
|
8
|
+
|
|
7
9
|
export type AppDeployJobStatus =
|
|
8
10
|
| "pending"
|
|
9
11
|
| "running"
|
|
@@ -71,6 +73,7 @@ export async function createAppDeployJob(args: {
|
|
|
71
73
|
summary?: string;
|
|
72
74
|
steps?: AppDeployJobStep[];
|
|
73
75
|
}): Promise<AppDeployJobRecord> {
|
|
76
|
+
const store = getAppDeployStatusStore();
|
|
74
77
|
const now = new Date().toISOString();
|
|
75
78
|
const record: AppDeployJobRecord = {
|
|
76
79
|
jobId: args.jobId,
|
|
@@ -83,8 +86,8 @@ export async function createAppDeployJob(args: {
|
|
|
83
86
|
updatedAt: now,
|
|
84
87
|
expiresAt: new Date(Date.now() + APP_DEPLOY_JOB_TTL_MS).toISOString(),
|
|
85
88
|
};
|
|
86
|
-
await
|
|
87
|
-
await
|
|
89
|
+
await store.put(buildJobKey(args.jobId), record);
|
|
90
|
+
await store.put(buildLatestKey(args.userId), {
|
|
88
91
|
jobId: args.jobId,
|
|
89
92
|
updatedAt: now,
|
|
90
93
|
});
|
|
@@ -92,10 +95,11 @@ export async function createAppDeployJob(args: {
|
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
export async function getAppDeployJob(jobId: string): Promise<AppDeployJobRecord | null> {
|
|
98
|
+
const store = getAppDeployStatusStore();
|
|
95
99
|
try {
|
|
96
|
-
const record = (await
|
|
100
|
+
const record = (await store.get(buildJobKey(jobId))) as AppDeployJobRecord;
|
|
97
101
|
if (isExpired(record?.expiresAt)) {
|
|
98
|
-
await
|
|
102
|
+
await store.del(buildJobKey(jobId));
|
|
99
103
|
return null;
|
|
100
104
|
}
|
|
101
105
|
return record;
|
|
@@ -113,6 +117,7 @@ export async function patchAppDeployJob(
|
|
|
113
117
|
jobId: string,
|
|
114
118
|
patch: Partial<AppDeployJobRecord>
|
|
115
119
|
): Promise<AppDeployJobRecord | null> {
|
|
120
|
+
const store = getAppDeployStatusStore();
|
|
116
121
|
const prev = patchQueues.get(jobId) ?? Promise.resolve();
|
|
117
122
|
const op = prev.catch(() => {}).then(async (): Promise<AppDeployJobRecord | null> => {
|
|
118
123
|
const current = await getAppDeployJob(jobId);
|
|
@@ -122,8 +127,8 @@ export async function patchAppDeployJob(
|
|
|
122
127
|
...patch,
|
|
123
128
|
updatedAt: new Date().toISOString(),
|
|
124
129
|
};
|
|
125
|
-
await
|
|
126
|
-
await
|
|
130
|
+
await store.put(buildJobKey(jobId), next);
|
|
131
|
+
await store.put(buildLatestKey(next.userId), {
|
|
127
132
|
jobId,
|
|
128
133
|
updatedAt: next.updatedAt,
|
|
129
134
|
});
|
|
@@ -139,8 +144,9 @@ export async function patchAppDeployJob(
|
|
|
139
144
|
}
|
|
140
145
|
|
|
141
146
|
export async function getLatestAppDeployJobId(userId: string): Promise<string | null> {
|
|
147
|
+
const store = getAppDeployStatusStore();
|
|
142
148
|
try {
|
|
143
|
-
const record = (await
|
|
149
|
+
const record = (await store.get(buildLatestKey(userId))) as { jobId?: string };
|
|
144
150
|
return typeof record?.jobId === "string" ? record.jobId : null;
|
|
145
151
|
} catch (error: any) {
|
|
146
152
|
if (error?.notFound) return null;
|
|
@@ -152,13 +158,14 @@ export async function resolveLatestAppDeployJobId(userId: string): Promise<{
|
|
|
152
158
|
jobId: string | null;
|
|
153
159
|
ambiguous: boolean;
|
|
154
160
|
}> {
|
|
161
|
+
const store = getAppDeployStatusStore();
|
|
155
162
|
const jobs: AppDeployJobRecord[] = [];
|
|
156
|
-
for await (const [key, value] of
|
|
163
|
+
for await (const [key, value] of store.iterator()) {
|
|
157
164
|
if (typeof key !== "string" || !key.startsWith(APP_DEPLOY_JOB_PREFIX)) continue;
|
|
158
165
|
const record = value as AppDeployJobRecord;
|
|
159
166
|
if (!record || record.userId !== userId) continue;
|
|
160
167
|
if (isExpired(record.expiresAt)) {
|
|
161
|
-
await
|
|
168
|
+
await store.del(key);
|
|
162
169
|
continue;
|
|
163
170
|
}
|
|
164
171
|
jobs.push(record);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolve4 } from "node:dns/promises";
|
|
2
|
-
import
|
|
2
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
3
3
|
import { getAppRecord, setAppCustomUrl } from "./appSandboxHandler";
|
|
4
4
|
import { hasSpaceRole } from "./appSpaceAccess";
|
|
5
5
|
import {
|
|
@@ -14,6 +14,8 @@ export const APP_ROUTE_PREFIX = "app-route-";
|
|
|
14
14
|
|
|
15
15
|
export type DomainBindMode = "platform_a";
|
|
16
16
|
|
|
17
|
+
const getAppDomainStore = () => getServerAuthorityStore();
|
|
18
|
+
|
|
17
19
|
export interface DomainRecord {
|
|
18
20
|
hostname: string;
|
|
19
21
|
mode: DomainBindMode;
|
|
@@ -176,7 +178,9 @@ export async function handleAppDomainAllow(req: Request): Promise<Response> {
|
|
|
176
178
|
return new Response("denied", { status: 404 });
|
|
177
179
|
}
|
|
178
180
|
|
|
179
|
-
const appId = await
|
|
181
|
+
const appId = await getAppDomainStore()
|
|
182
|
+
.get(`${DOMAIN_HOST_PREFIX}${hostname}`)
|
|
183
|
+
.catch(() => null);
|
|
180
184
|
if (typeof appId === "string" && appId.trim()) {
|
|
181
185
|
return new Response("ok", {
|
|
182
186
|
status: 200,
|
|
@@ -226,7 +230,7 @@ async function listDomainRecords(
|
|
|
226
230
|
backfill?: boolean;
|
|
227
231
|
} = {}
|
|
228
232
|
): Promise<DomainRecord[]> {
|
|
229
|
-
const { db =
|
|
233
|
+
const { db = getAppDomainStore(), req, backfill = true } = options;
|
|
230
234
|
const prefix = `${APP_DOMAIN_PREFIX}${appId}-`;
|
|
231
235
|
const records: DomainRecord[] = [];
|
|
232
236
|
for await (const [key, value] of db.iterator({
|
|
@@ -256,7 +260,7 @@ async function refreshDomainDnsState(
|
|
|
256
260
|
db?: any;
|
|
257
261
|
} = {}
|
|
258
262
|
): Promise<DomainRecord> {
|
|
259
|
-
const { db =
|
|
263
|
+
const { db = getAppDomainStore() } = options;
|
|
260
264
|
const resolvedARecords = await resolveHostnameARecords(record.hostname);
|
|
261
265
|
const pendingDns =
|
|
262
266
|
record.aRecords.length === 0 ||
|
|
@@ -275,7 +279,7 @@ async function refreshDomainDnsState(
|
|
|
275
279
|
async function syncPrimaryCustomUrl(
|
|
276
280
|
appId: string,
|
|
277
281
|
req?: Request,
|
|
278
|
-
db: any =
|
|
282
|
+
db: any = getAppDomainStore()
|
|
279
283
|
): Promise<void> {
|
|
280
284
|
const records = await listDomainRecords(appId, { db, req });
|
|
281
285
|
const active = records.find((record) => !record.pendingDns);
|
|
@@ -346,14 +350,15 @@ export async function handleAppDomainBind(req: Request): Promise<Response> {
|
|
|
346
350
|
}
|
|
347
351
|
|
|
348
352
|
return withHostnameLock(hostname, async () => {
|
|
353
|
+
const store = getAppDomainStore();
|
|
349
354
|
const hostKey = `${DOMAIN_HOST_PREFIX}${hostname}`;
|
|
350
355
|
const domainKey = buildAppDomainKey(appId, hostname);
|
|
351
|
-
const currentOwner = await
|
|
356
|
+
const currentOwner = await store.get(hostKey).catch(() => null);
|
|
352
357
|
if (currentOwner && currentOwner !== appId) {
|
|
353
358
|
return jsonError(409, "该域名已被其他应用绑定", "HOSTNAME_ALREADY_BOUND");
|
|
354
359
|
}
|
|
355
360
|
|
|
356
|
-
const existing = await
|
|
361
|
+
const existing = (await store.get(domainKey).catch(() => null)) as DomainRecord | null;
|
|
357
362
|
const resolvedARecords = await resolveHostnameARecords(hostname);
|
|
358
363
|
const pendingDns = !targetARecords.every((ip) => resolvedARecords.includes(ip));
|
|
359
364
|
const now = new Date().toISOString();
|
|
@@ -368,10 +373,10 @@ export async function handleAppDomainBind(req: Request): Promise<Response> {
|
|
|
368
373
|
};
|
|
369
374
|
|
|
370
375
|
await Promise.all([
|
|
371
|
-
|
|
372
|
-
|
|
376
|
+
store.put(hostKey, appId),
|
|
377
|
+
store.put(domainKey, record),
|
|
373
378
|
]);
|
|
374
|
-
await syncPrimaryCustomUrl(appId, req);
|
|
379
|
+
await syncPrimaryCustomUrl(appId, req, store);
|
|
375
380
|
|
|
376
381
|
return jsonOk({
|
|
377
382
|
success: true,
|
|
@@ -406,14 +411,15 @@ export async function handleAppDomainUnbind(req: Request): Promise<Response> {
|
|
|
406
411
|
}
|
|
407
412
|
|
|
408
413
|
return withHostnameLock(hostname, async () => {
|
|
414
|
+
const store = getAppDomainStore();
|
|
409
415
|
const hostKey = `${DOMAIN_HOST_PREFIX}${hostname}`;
|
|
410
416
|
const domainKey = buildAppDomainKey(appId, hostname);
|
|
411
|
-
const currentOwner = await
|
|
417
|
+
const currentOwner = await store.get(hostKey).catch(() => null);
|
|
412
418
|
if (currentOwner === appId) {
|
|
413
|
-
await
|
|
419
|
+
await store.del(hostKey).catch(() => {});
|
|
414
420
|
}
|
|
415
|
-
await
|
|
416
|
-
await syncPrimaryCustomUrl(appId, req);
|
|
421
|
+
await store.del(domainKey).catch(() => {});
|
|
422
|
+
await syncPrimaryCustomUrl(appId, req, store);
|
|
417
423
|
return jsonOk({ success: true, appId, hostname, removed: true });
|
|
418
424
|
});
|
|
419
425
|
}
|
|
@@ -454,7 +460,7 @@ export async function handleAppDomainList(req: Request): Promise<Response> {
|
|
|
454
460
|
|
|
455
461
|
export async function deleteAppDomains(
|
|
456
462
|
appId: string,
|
|
457
|
-
db: any =
|
|
463
|
+
db: any = getAppDomainStore()
|
|
458
464
|
): Promise<void> {
|
|
459
465
|
const prefix = `${APP_DOMAIN_PREFIX}${appId}-`;
|
|
460
466
|
for await (const [domainKey, value] of db.iterator({
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
2
2
|
|
|
3
3
|
export const APP_ROUTE_PREFIX = "app-route-";
|
|
4
4
|
|
|
5
|
-
export async function deleteLegacyAppInfraRecords(
|
|
5
|
+
export async function deleteLegacyAppInfraRecords(
|
|
6
|
+
appId: string,
|
|
7
|
+
db: any = getServerAuthorityStore(),
|
|
8
|
+
): Promise<void> {
|
|
6
9
|
await db.del(`${APP_ROUTE_PREFIX}${appId}`).catch(() => {});
|
|
7
10
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// 在我们服务器用 Bun Worker 沙箱运行用户部署的应用代码
|
|
3
3
|
// 路由: /apps/:appId/* → 加载代码 → Worker 沙箱执行 → 返回 Response
|
|
4
4
|
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
import { tmpdir } from "os";
|
|
7
|
-
import { writeFile, unlink } from "fs/promises";
|
|
8
|
-
import { pathToFileURL } from "node:url";
|
|
9
|
-
import
|
|
10
|
-
import { saveVersion } from "./versionStore";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { tmpdir } from "os";
|
|
7
|
+
import { writeFile, unlink } from "fs/promises";
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
9
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
10
|
+
import { saveVersion } from "./versionStore";
|
|
11
11
|
import type { BundleFile } from "../appBundler";
|
|
12
12
|
import {
|
|
13
13
|
getSpaceRecord,
|
|
@@ -19,8 +19,29 @@ import {
|
|
|
19
19
|
buildLegacyAppRouteKey,
|
|
20
20
|
buildOwnerScopedAppKey,
|
|
21
21
|
} from "../../app/utils/appKeys";
|
|
22
|
-
import { WEB_AUTH_TOKEN_COOKIE } from "../../auth/tokenCookie";
|
|
23
|
-
import { buildTombstoneRecord, isTombstoneRecord } from "../../database/tombstones";
|
|
22
|
+
import { WEB_AUTH_TOKEN_COOKIE } from "../../auth/tokenCookie";
|
|
23
|
+
import { buildTombstoneRecord, isTombstoneRecord } from "../../database/tombstones";
|
|
24
|
+
|
|
25
|
+
const getAppSandboxStore = () => getServerAuthorityStore();
|
|
26
|
+
const serverDb = {
|
|
27
|
+
get<T = any>(key: string) {
|
|
28
|
+
return getAppSandboxStore().get<T>(key);
|
|
29
|
+
},
|
|
30
|
+
put(key: string, value: unknown) {
|
|
31
|
+
return getAppSandboxStore().put(key, value);
|
|
32
|
+
},
|
|
33
|
+
del(key: string) {
|
|
34
|
+
return getAppSandboxStore().del(key);
|
|
35
|
+
},
|
|
36
|
+
iterator(options?: {
|
|
37
|
+
gte?: string;
|
|
38
|
+
lte?: string;
|
|
39
|
+
lt?: string;
|
|
40
|
+
reverse?: boolean;
|
|
41
|
+
}) {
|
|
42
|
+
return getAppSandboxStore().iterator(options);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
24
45
|
|
|
25
46
|
// ── 存储 key ────────────────────────────────────────────────
|
|
26
47
|
export const APP_CODE_PREFIX = "app-code-";
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
2
2
|
import { buildLegacyAppRouteKey } from "../../app/utils/appKeys";
|
|
3
3
|
import { isTombstoneRecord } from "../../database/tombstones";
|
|
4
4
|
|
|
5
5
|
const SPACE_PREFIX = "space-";
|
|
6
6
|
const SPACE_MEMBER_PREFIX = "space-member-";
|
|
7
7
|
|
|
8
|
+
const getAppSpaceAccessStore = () => getServerAuthorityStore();
|
|
9
|
+
|
|
8
10
|
export type SpaceRole = "owner" | "admin" | "member" | "guest";
|
|
9
11
|
|
|
10
12
|
const ROLE_RANK: Record<SpaceRole, number> = {
|
|
@@ -41,8 +43,9 @@ export const createAppContentKey = (appId: string, appKey?: string): string =>
|
|
|
41
43
|
export async function getSpaceRecord(spaceId?: string | null): Promise<any | null> {
|
|
42
44
|
const normalized = normalizeSpaceId(spaceId);
|
|
43
45
|
if (!normalized) return null;
|
|
46
|
+
const store = getAppSpaceAccessStore();
|
|
44
47
|
try {
|
|
45
|
-
const record = await
|
|
48
|
+
const record = await store.get(createSpaceKey(normalized));
|
|
46
49
|
return isTombstoneRecord(record) ? null : record;
|
|
47
50
|
} catch {
|
|
48
51
|
return null;
|
|
@@ -52,8 +55,9 @@ export async function getSpaceRecord(spaceId?: string | null): Promise<any | nul
|
|
|
52
55
|
export async function getUserSpaceMembership(userId: string, spaceId?: string | null): Promise<any | null> {
|
|
53
56
|
const normalized = normalizeSpaceId(spaceId);
|
|
54
57
|
if (!userId || !normalized) return null;
|
|
58
|
+
const store = getAppSpaceAccessStore();
|
|
55
59
|
try {
|
|
56
|
-
const record = await
|
|
60
|
+
const record = await store.get(createSpaceMemberKey(userId, normalized));
|
|
57
61
|
return isTombstoneRecord(record) ? null : record;
|
|
58
62
|
} catch {
|
|
59
63
|
return null;
|
|
@@ -92,9 +96,10 @@ export async function hasSpaceRole(
|
|
|
92
96
|
|
|
93
97
|
export async function listUserSpaceIds(userId: string): Promise<string[]> {
|
|
94
98
|
if (!userId) return [];
|
|
99
|
+
const store = getAppSpaceAccessStore();
|
|
95
100
|
const prefix = `${SPACE_MEMBER_PREFIX}${userId}-`;
|
|
96
101
|
const ids = new Set<string>();
|
|
97
|
-
for await (const [key, value] of
|
|
102
|
+
for await (const [key, value] of store.iterator({ gte: prefix, lte: `${prefix}\xff` })) {
|
|
98
103
|
if (isTombstoneRecord(value)) continue;
|
|
99
104
|
const rawKey = String(key);
|
|
100
105
|
const spaceId = rawKey.slice(prefix.length);
|
|
@@ -117,9 +122,10 @@ export async function addAppToSpace(params: {
|
|
|
117
122
|
}
|
|
118
123
|
|
|
119
124
|
const spaceKey = createSpaceKey(normalized);
|
|
125
|
+
const store = getAppSpaceAccessStore();
|
|
120
126
|
let spaceData: any;
|
|
121
127
|
try {
|
|
122
|
-
spaceData = await
|
|
128
|
+
spaceData = await store.get(spaceKey);
|
|
123
129
|
} catch {
|
|
124
130
|
throw new Error("space_not_found");
|
|
125
131
|
}
|
|
@@ -127,7 +133,7 @@ export async function addAppToSpace(params: {
|
|
|
127
133
|
const now = params.updatedAt ?? Date.now();
|
|
128
134
|
const contentKey = createAppContentKey(params.appId, params.appKey);
|
|
129
135
|
const legacyContentKey = createAppContentKey(params.appId);
|
|
130
|
-
await
|
|
136
|
+
await store.put(spaceKey, {
|
|
131
137
|
...spaceData,
|
|
132
138
|
updatedAt: now,
|
|
133
139
|
contents: {
|
|
@@ -157,9 +163,10 @@ export async function removeAppFromSpace(
|
|
|
157
163
|
createAppContentKey(appId, appKey ?? undefined),
|
|
158
164
|
createAppContentKey(appId),
|
|
159
165
|
]);
|
|
166
|
+
const store = getAppSpaceAccessStore();
|
|
160
167
|
try {
|
|
161
168
|
const spaceKey = createSpaceKey(normalized);
|
|
162
|
-
const spaceData: any = await
|
|
169
|
+
const spaceData: any = await store.get(spaceKey);
|
|
163
170
|
const nextContents = { ...(spaceData?.contents ?? {}) };
|
|
164
171
|
let changed = false;
|
|
165
172
|
for (const contentKey of contentKeys) {
|
|
@@ -168,7 +175,7 @@ export async function removeAppFromSpace(
|
|
|
168
175
|
changed = true;
|
|
169
176
|
}
|
|
170
177
|
if (changed) {
|
|
171
|
-
await
|
|
178
|
+
await store.put(spaceKey, {
|
|
172
179
|
...spaceData,
|
|
173
180
|
updatedAt: Date.now(),
|
|
174
181
|
contents: nextContents,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
selectUpstreamRequest,
|
|
26
26
|
} from "./chatProxyRouting";
|
|
27
27
|
import { authenticateMachineToken } from "./machines/machineAuth";
|
|
28
|
-
import
|
|
28
|
+
import { getServerAuthorityStore } from "../../database/server/db";
|
|
29
29
|
const encoder = new TextEncoder();
|
|
30
30
|
|
|
31
31
|
// 简单的控制台日志封装,带颜色高亮
|
|
@@ -250,6 +250,13 @@ const normalizeCustomChatUrl = (rawUrl: unknown): string | undefined => {
|
|
|
250
250
|
return url;
|
|
251
251
|
};
|
|
252
252
|
|
|
253
|
+
const inferProviderCallEndpoint = (url: unknown): string | undefined => {
|
|
254
|
+
if (typeof url !== "string") return undefined;
|
|
255
|
+
if (url.includes("/responses")) return "responses";
|
|
256
|
+
if (url.includes("/chat/completions")) return "chat.completions";
|
|
257
|
+
return undefined;
|
|
258
|
+
};
|
|
259
|
+
|
|
253
260
|
const hydrateProxyRequestFromAgent = async (
|
|
254
261
|
request: ChatProxyPayload
|
|
255
262
|
): Promise<ChatProxyPayload> => {
|
|
@@ -262,7 +269,7 @@ const hydrateProxyRequestFromAgent = async (
|
|
|
262
269
|
|
|
263
270
|
let agent: any = null;
|
|
264
271
|
try {
|
|
265
|
-
agent = await
|
|
272
|
+
agent = await getServerAuthorityStore().get(agentKey);
|
|
266
273
|
} catch {
|
|
267
274
|
return request;
|
|
268
275
|
}
|
|
@@ -504,6 +511,19 @@ export async function handleChatRequest(req: Request, extraHeaders = {}) {
|
|
|
504
511
|
fallbackRequests: upstreamRequest.fallbackRequests,
|
|
505
512
|
fallbackOnStatuses: upstreamRequest.fallbackOnStatuses,
|
|
506
513
|
init: upstreamRequest.init,
|
|
514
|
+
providerCallStore: getServerAuthorityStore(),
|
|
515
|
+
providerCallContext: {
|
|
516
|
+
userId,
|
|
517
|
+
dialogId:
|
|
518
|
+
typeof body.dialogId === "string" && body.dialogId.trim()
|
|
519
|
+
? body.dialogId.trim()
|
|
520
|
+
: undefined,
|
|
521
|
+
agentId:
|
|
522
|
+
typeof request.agentKey === "string" && request.agentKey.trim()
|
|
523
|
+
? request.agentKey.trim()
|
|
524
|
+
: undefined,
|
|
525
|
+
endpoint: inferProviderCallEndpoint(upstreamRequest.url),
|
|
526
|
+
},
|
|
507
527
|
});
|
|
508
528
|
clearTimeout(timer);
|
|
509
529
|
const requestedBillingServiceTier =
|