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.
Files changed (308) hide show
  1. package/agent-runtime/agentRecordConfig.ts +0 -2
  2. package/agent-runtime/hostAdapter.ts +0 -1
  3. package/agent-runtime/hostRuntimeCapabilities.ts +7 -0
  4. package/agent-runtime/hostRuntimeConfig.ts +86 -0
  5. package/agent-runtime/index.ts +13 -0
  6. package/agent-runtime/localToolPolicy.ts +13 -6
  7. package/agent-runtime/localWorkspaceTools.ts +333 -30
  8. package/agent-runtime/platformChatProvider.ts +4 -1
  9. package/agent-runtime/runtimeToolPolicy.ts +32 -47
  10. package/agent-runtime/shellCommandPolicy.ts +117 -0
  11. package/agent-runtime/toolGate.ts +38 -0
  12. package/agentRecordCommands.ts +1 -1
  13. package/agentRecordHelpers.ts +35 -20
  14. package/agentRunParsing.ts +18 -5
  15. package/agentRuntimeLocal.ts +10 -0
  16. package/ai/agent/agentRunDialogLineage.ts +56 -0
  17. package/ai/agent/agentSlice.ts +45 -10
  18. package/ai/agent/avatarUtils.ts +1 -1
  19. package/ai/agent/buildSystemPrompt.ts +1 -2
  20. package/ai/agent/cliExecutor.ts +330 -19
  21. package/ai/agent/createAgentSchema.ts +22 -0
  22. package/ai/agent/hooks/fetchPublicAgents.ts +14 -39
  23. package/ai/agent/hooks/usePublicAgents.ts +90 -192
  24. package/ai/agent/publicAgentCatalog.ts +359 -0
  25. package/ai/agent/publicAgentIdentity.ts +76 -0
  26. package/ai/agent/server/fetchPublicAgents.ts +21 -46
  27. package/ai/agent/serverOrigin.ts +7 -0
  28. package/ai/agent/streamAgentChatTurn.ts +23 -21
  29. package/ai/agent/streamAgentChatTurnUtils.ts +292 -6
  30. package/ai/agent/types.ts +2 -0
  31. package/ai/agent/web/agentDisplayUtils.ts +171 -0
  32. package/ai/agent/web/useAgentModelAvatarComponent.ts +32 -0
  33. package/ai/ai.locale.ts +8 -0
  34. package/ai/chat/sendOpenAICompletionsRequest.native.ts +15 -0
  35. package/ai/chat/sendOpenAICompletionsRequest.ts +93 -1
  36. package/ai/chat/sendOpenAIResponseRequest.ts +86 -9
  37. package/ai/chat/updateTotalUsage.ts +7 -0
  38. package/ai/llm/deepinfra.ts +30 -15
  39. package/ai/llm/mistral.ts +3 -4
  40. package/ai/llm/providers.ts +2 -0
  41. package/ai/llm/types.ts +15 -0
  42. package/ai/memory/capture.ts +3 -3
  43. package/ai/memory/consolidate.ts +2 -2
  44. package/ai/memory/delete.ts +4 -3
  45. package/ai/memory/query.ts +3 -3
  46. package/ai/memory/remember.ts +2 -2
  47. package/ai/memory/store.ts +3 -3
  48. package/ai/memory/storeShared.ts +3 -2
  49. package/ai/policy/commercialMultiplier.ts +16 -0
  50. package/ai/token/billingAdminAuditEvent.ts +68 -0
  51. package/ai/token/billingAdminAuditEventWriter.ts +41 -0
  52. package/ai/token/billingAnomaly.ts +90 -0
  53. package/ai/token/billingAnomalyLifecycle.ts +54 -0
  54. package/ai/token/billingAnomalyLifecycleWriter.ts +44 -0
  55. package/ai/token/billingAnomalyWriter.ts +41 -0
  56. package/ai/token/calculatePrice.ts +3 -2
  57. package/ai/token/deepinfraReconciliation.ts +153 -0
  58. package/ai/token/deepinfraRequestIdQuery.ts +92 -0
  59. package/ai/token/externalToolCost.ts +54 -41
  60. package/ai/token/missingUsageEstimate.ts +12 -3
  61. package/ai/token/normalizeUsage.ts +45 -5
  62. package/ai/token/openaiReconciliation.ts +188 -0
  63. package/ai/token/providerBillableEvent.ts +84 -0
  64. package/ai/token/providerBillableEventWriter.ts +36 -0
  65. package/ai/token/providerBillingAnomalyDrilldown.ts +308 -0
  66. package/ai/token/providerBillingDrilldown.ts +361 -0
  67. package/ai/token/providerBillingHealthReport.ts +366 -0
  68. package/ai/token/providerCall.ts +144 -0
  69. package/ai/token/providerCallSweeper.ts +168 -0
  70. package/ai/token/providerCallWriter.ts +33 -0
  71. package/ai/token/providerCredential.ts +89 -0
  72. package/ai/token/providerCredentialAnomaly.ts +154 -0
  73. package/ai/token/providerCredentialLifecycle.ts +59 -0
  74. package/ai/token/providerCredentialLifecycleWriter.ts +44 -0
  75. package/ai/token/providerCredentialRegistry.ts +83 -0
  76. package/ai/token/providerCredentialRegistryCommand.ts +97 -0
  77. package/ai/token/providerCredentialRegistryList.ts +124 -0
  78. package/ai/token/providerCredentialRegistryResolver.ts +150 -0
  79. package/ai/token/providerCredentialRegistryWriter.ts +41 -0
  80. package/ai/token/providerCredentialRotationCommand.ts +102 -0
  81. package/ai/token/providerCredentialRuntime.ts +56 -0
  82. package/ai/token/providerDispatchIntent.ts +67 -0
  83. package/ai/token/providerDispatchIntentWriter.ts +36 -0
  84. package/ai/token/providerGateway.ts +260 -0
  85. package/ai/token/providerReconciliation.ts +148 -0
  86. package/ai/token/providerReconciliationLocal.ts +97 -0
  87. package/ai/token/providerReconciliationRunner.ts +165 -0
  88. package/ai/token/providerReconciliationWriter.ts +41 -0
  89. package/ai/token/ratingResult.ts +202 -0
  90. package/ai/token/ratingResultWriter.ts +33 -0
  91. package/ai/token/serverDialogProjection.ts +5 -3
  92. package/ai/token/serverTokenWriter.ts +11 -3
  93. package/ai/token/types.ts +10 -0
  94. package/ai/tools/agent/callAgentTool.ts +3 -4
  95. package/ai/tools/agent/presets/appBuilderPreset.ts +5 -7
  96. package/ai/tools/agent/runStreamingAgentTool.ts +1 -2
  97. package/ai/tools/agent/streamParallelAgentsTool.ts +2 -3
  98. package/ai/tools/readXPostTool.ts +1 -5
  99. package/app/admin/adminPages.ts +9 -0
  100. package/app/i18n/i18n.config.ts +5 -0
  101. package/app/i18n/translations/pricing.locale.ts +397 -0
  102. package/app/utils/desktopAgentRuntimeStatusClient.ts +5 -4
  103. package/app/utils/desktopAgentRuntimeTurnClient.ts +4 -1
  104. package/app/utils/imageUtils.ts +64 -34
  105. package/auth/adminPermissions.ts +18 -0
  106. package/auth/authSlice.ts +26 -12
  107. package/auth/hooks/useFetchUsers.ts +3 -0
  108. package/auth/routes.ts +46 -0
  109. package/auth/server/accessActivity.ts +4 -3
  110. package/auth/server/adminPermissions.ts +43 -0
  111. package/auth/server/adminUsageReport.ts +375 -0
  112. package/auth/server/billingAnomalies.ts +235 -0
  113. package/auth/server/billingUsageReport.ts +41 -2
  114. package/auth/server/creatorEarningCreditConversion.ts +10 -2
  115. package/auth/server/deduct.ts +14 -7
  116. package/auth/server/delete.ts +10 -2
  117. package/auth/server/disable.ts +4 -3
  118. package/auth/server/emailAutomation.ts +7 -5
  119. package/auth/server/emailDbConfig.ts +4 -2
  120. package/auth/server/emailDelivery.ts +24 -20
  121. package/auth/server/emailDeliveryGuards.ts +10 -7
  122. package/auth/server/emailPreferences.ts +6 -4
  123. package/auth/server/emailReport.ts +6 -4
  124. package/auth/server/emailRuntimeConfig.ts +3 -3
  125. package/auth/server/emailScenarioNotifications.ts +9 -8
  126. package/auth/server/enable.ts +4 -3
  127. package/auth/server/getRechargeHistory.ts +3 -2
  128. package/auth/server/getUser.ts +3 -2
  129. package/auth/server/gptProAccess.ts +44 -0
  130. package/auth/server/inviteReward.ts +10 -7
  131. package/auth/server/listusers.ts +6 -4
  132. package/auth/server/login.ts +2 -2
  133. package/auth/server/productEntitlements.ts +7 -4
  134. package/auth/server/productPurchase.ts +10 -2
  135. package/auth/server/providerBillingDrilldown.ts +47 -0
  136. package/auth/server/providerBillingHealth.ts +71 -0
  137. package/auth/server/providerCredentials.ts +136 -0
  138. package/auth/server/recharge.ts +14 -8
  139. package/auth/server/revokeSessions.ts +4 -3
  140. package/auth/server/route.ts +77 -0
  141. package/auth/server/sendEmail.ts +5 -4
  142. package/auth/server/signup.ts +10 -3
  143. package/auth/server/token.ts +53 -55
  144. package/auth/server/tokenUsageBilling.ts +18 -7
  145. package/auth/server/usageManagementAccess.ts +43 -0
  146. package/auth/server/usageReport.ts +59 -0
  147. package/auth/types.ts +12 -0
  148. package/auth/utils.ts +24 -22
  149. package/authCommands.ts +36 -2
  150. package/buildPublish.ts +3 -1
  151. package/buildPublishArtifactAssembly.ts +62 -1
  152. package/buildPublishImportAnalysis.ts +21 -16
  153. package/chat/dialog/dialogLaunchScope.ts +32 -0
  154. package/chat/dialog/objectAssistantRegistry.ts +2 -2
  155. package/chat/dialog/useCreateDialog.ts +1 -1
  156. package/chat/hooks/useChatInput.ts +41 -10
  157. package/chat/messages/messageSlice.ts +5 -1
  158. package/chat/messages/pendingAttachmentParts.ts +28 -2
  159. package/chat/messages/sendFirstMessage.ts +76 -79
  160. package/chat/messages/types.ts +9 -0
  161. package/chat/messages/web/streamingMarkdownModel.ts +41 -0
  162. package/chat/messages/web/useStreamingReveal.ts +91 -0
  163. package/chat/web/messageInputAgentUi.ts +94 -6
  164. package/cliEnvHelpers.ts +8 -0
  165. package/cliRuntimeDoctorReport.ts +193 -0
  166. package/client/agentConfigResolver.test.ts +0 -2
  167. package/client/agentRun.test.ts +171 -10
  168. package/client/agentRun.ts +44 -637
  169. package/client/agentRunInput.ts +10 -0
  170. package/client/agentRunLocalExecutor.ts +179 -0
  171. package/client/agentRunServerTransport.ts +394 -0
  172. package/client/agentRunTaskRunRecorder.ts +176 -0
  173. package/client/localRuntimeAdapter.test.ts +236 -9
  174. package/client/localRuntimeAdapter.ts +221 -23
  175. package/client/localToolPolicy.test.ts +28 -4
  176. package/connector-experimental/daemonLauncher.ts +38 -4
  177. package/connectorRunArtifact.ts +34 -10
  178. package/connectorWebSocketTarget.ts +9 -5
  179. package/core/builtinAgents.ts +155 -11
  180. package/create/space/contentLabels.ts +1 -1
  181. package/create/space/contentTypeMeta.ts +3 -2
  182. package/create/space/sidebarVisibleTypes.ts +27 -0
  183. package/create/space/space.locale.ts +76 -4
  184. package/database/actions/agentReadResolution.ts +2 -8
  185. package/database/actions/read.ts +11 -9
  186. package/database/actions/readAndWait.ts +10 -5
  187. package/database/server/agentDelegation.ts +3 -2
  188. package/database/server/authorityStoreConformance.ts +209 -0
  189. package/database/server/authorityStoreTypes.ts +31 -0
  190. package/database/server/coreDataProxy.ts +1 -1
  191. package/database/server/dataHandlers.ts +13 -5
  192. package/database/server/db.ts +15 -34
  193. package/database/server/delete.ts +88 -71
  194. package/database/server/emailRepository.ts +11 -9
  195. package/database/server/fileService.ts +2 -1
  196. package/database/server/legacyServerDb.ts +58 -0
  197. package/database/server/levelAuthorityStore.ts +75 -0
  198. package/database/server/memoryAuthorityStore.ts +133 -0
  199. package/database/server/patch.ts +13 -12
  200. package/database/server/query.ts +3 -2
  201. package/database/server/read.ts +33 -30
  202. package/database/server/resourceAccess.ts +7 -5
  203. package/database/server/serverStoreFactory.ts +124 -0
  204. package/database/server/spaceMemberAuthority.ts +3 -2
  205. package/database/server/storeBatchCompat.ts +37 -0
  206. package/database/server/testAuthorityStore.ts +76 -0
  207. package/database/server/write.ts +29 -27
  208. package/integrations/anthropic/anthropicModels.ts +12 -12
  209. package/integrations/deepseek/models.ts +67 -67
  210. package/integrations/google/models.ts +111 -53
  211. package/integrations/openai/models.ts +22 -22
  212. package/integrations/xai/models.ts +1 -1
  213. package/localRuntimeDb.ts +39 -2
  214. package/machineCommandPrompts.ts +2 -0
  215. package/machineCommands.ts +193 -63
  216. package/machineWsRunDispatch.ts +80 -15
  217. package/machineWsSession.ts +39 -2
  218. package/noloReadBridgePrompt.ts +16 -0
  219. package/package.json +99 -6
  220. package/render/layout/mainLayoutViewMode.ts +25 -0
  221. package/render/page/server/createPage.ts +3 -1
  222. package/render/page/server/handleCreatePage.ts +2 -11
  223. package/runtimeDoctorCommands.ts +15 -66
  224. package/server/api/methods.ts +34 -12
  225. package/server/api/tableHandlers.ts +6 -3
  226. package/server/authenticateToken.ts +47 -2
  227. package/server/billingLedgerRoutes.ts +15 -0
  228. package/server/buildManifest.ts +54 -0
  229. package/server/coreReadiness.ts +34 -25
  230. package/server/coreRuntime.ts +15 -10
  231. package/server/handlers/activityStatsHandler.ts +5 -2
  232. package/server/handlers/agentEmailRegistrationE2EHandler.ts +25 -23
  233. package/server/handlers/agentRun/agentLookup.ts +1 -7
  234. package/server/handlers/agentRun/autonomousRuntime.ts +11 -10
  235. package/server/handlers/agentRun/builtinAgents.ts +12 -88
  236. package/server/handlers/agentRun/continueDialogContext.ts +15 -3
  237. package/server/handlers/agentRun/{inheritedDialogPrompt.ts → conversationReference.ts} +3 -3
  238. package/server/handlers/agentRun/dialogLookup.ts +4 -3
  239. package/server/handlers/agentRun/index.ts +864 -404
  240. package/server/handlers/agentRun/localRuntimeBootstrap.ts +17 -1
  241. package/server/handlers/agentRun/loop.ts +920 -508
  242. package/server/handlers/agentRun/machineConnector.ts +56 -8
  243. package/server/handlers/agentRun/machineRunAudit.ts +3 -2
  244. package/server/handlers/agentRun/modelUsageToolHandlers.ts +13 -10
  245. package/server/handlers/agentRun/requestContext.ts +12 -8
  246. package/server/handlers/agentRun/runtimeExecutionContext.ts +15 -3
  247. package/server/handlers/agentRun/runtimePreparation.ts +26 -24
  248. package/server/handlers/agentRun/runtimeRouting.ts +25 -40
  249. package/server/handlers/agentRun/runtimeSystemMessages.ts +65 -0
  250. package/server/handlers/agentRun/saveDialog.ts +97 -87
  251. package/server/handlers/agentRun/taskRunToolHandler.ts +9 -7
  252. package/server/handlers/agentRun/toolExecutor.ts +42 -78
  253. package/server/handlers/agentRun/types.ts +2 -1
  254. package/server/handlers/appDeployStatusStore.ts +17 -10
  255. package/server/handlers/appDomainHandler.ts +21 -15
  256. package/server/handlers/appLegacyInfraCleanup.ts +5 -2
  257. package/server/handlers/appSandboxHandler.ts +29 -8
  258. package/server/handlers/appSpaceAccess.ts +15 -8
  259. package/server/handlers/chatHandler.ts +22 -2
  260. package/server/handlers/chatUpstreamRetry.ts +225 -2
  261. package/server/handlers/connector/connectorConnectionRegistry.ts +55 -7
  262. package/server/handlers/connector/connectorWebSocket.ts +14 -10
  263. package/server/handlers/desktopAgentRuntimeAdapter.ts +4 -4
  264. package/server/handlers/desktopAgentRuntimeHostCapabilities.ts +25 -0
  265. package/server/handlers/desktopAgentRuntimeReadiness.ts +62 -0
  266. package/server/handlers/desktopAgentRuntimeStatusHandler.ts +38 -30
  267. package/server/handlers/desktopAgentRuntimeTurnHandler.ts +7 -3
  268. package/server/handlers/desktopAgentRuntimeTurnService.ts +39 -45
  269. package/server/handlers/desktopLlamaRuntimeHandler.ts +85 -51
  270. package/server/handlers/desktopUpdaterHandler.ts +132 -24
  271. package/server/handlers/favoriteHandlers.ts +8 -2
  272. package/server/handlers/getDialogBillingHandler.ts +4 -3
  273. package/server/handlers/getTransactionsHandler.ts +5 -2
  274. package/server/handlers/machines/machineBinding.ts +1 -0
  275. package/server/handlers/machines/machineHandlers.ts +0 -14
  276. package/server/handlers/machines/machineInstallAssets.ts +4 -2
  277. package/server/handlers/notificationEmitter.ts +5 -3
  278. package/server/handlers/notificationsHandler.ts +5 -2
  279. package/server/handlers/providerCallsRecentHandler.ts +234 -0
  280. package/server/handlers/providerReconciliationRunHandler.ts +180 -0
  281. package/server/handlers/providerRequestIdsHandler.ts +105 -0
  282. package/server/handlers/tableAccess.ts +6 -2
  283. package/server/handlers/tableToolHandlers.ts +28 -14
  284. package/server/handlers/userSecretsHandler.ts +17 -6
  285. package/server/handlers/versionHandler.ts +9 -4
  286. package/server/handlers/versionStore.ts +18 -10
  287. package/server/html/ssrPreload.ts +5 -3
  288. package/server/payments/crypto/cryptoUsdcBasePaymentProvider.ts +11 -8
  289. package/server/payments/crypto/cryptoUsdcBaseScanner.ts +12 -7
  290. package/server/payments/crypto/cryptoUsdtTronPaymentProvider.ts +11 -8
  291. package/server/payments/crypto/cryptoUsdtTronScanner.ts +9 -7
  292. package/server/payments/waffo/waffoPaymentProvider.ts +12 -9
  293. package/server/runtimeRole.ts +15 -0
  294. package/server/scheduler/scheduledTaskRuntime.ts +4 -2
  295. package/server/scheduler/schedulerService.ts +2 -2
  296. package/server/taskRunBridgeRoutes.ts +8 -5
  297. package/share/server/fetchCommunityShares.ts +1 -1
  298. package/share/server/helpers.ts +19 -17
  299. package/share/server/importShare.ts +9 -13
  300. package/share/server/listCommunityShares.ts +4 -4
  301. package/share/server/purchaseDoc.ts +8 -16
  302. package/share/server/readCommunityShareCover.ts +3 -2
  303. package/share/server/readSharedTable.ts +14 -13
  304. package/share/server/tableReplication.ts +42 -39
  305. package/spaceAttachCommands.ts +135 -0
  306. package/spaceInternalCommandEntries.ts +2 -0
  307. package/ai/agent/runtimeServerBase.ts +0 -37
  308. package/server/handlers/desktopAgentRuntimeHostFacts.ts +0 -40
@@ -1,9 +1,11 @@
1
- import serverDb from "../../database/server/db";
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 serverDb.put(buildJobKey(args.jobId), record);
87
- await serverDb.put(buildLatestKey(args.userId), {
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 serverDb.get(buildJobKey(jobId))) as AppDeployJobRecord;
100
+ const record = (await store.get(buildJobKey(jobId))) as AppDeployJobRecord;
97
101
  if (isExpired(record?.expiresAt)) {
98
- await serverDb.del(buildJobKey(jobId));
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 serverDb.put(buildJobKey(jobId), next);
126
- await serverDb.put(buildLatestKey(next.userId), {
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 serverDb.get(buildLatestKey(userId))) as { jobId?: string };
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 serverDb.iterator()) {
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 serverDb.del(key);
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 serverDb from "../../database/server/db";
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 serverDb.get(`${DOMAIN_HOST_PREFIX}${hostname}`).catch(() => null);
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 = serverDb, req, backfill = true } = options;
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 = serverDb } = options;
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 = serverDb
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 serverDb.get(hostKey).catch(() => null);
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 serverDb.get(domainKey).catch(() => null) as DomainRecord | null;
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
- serverDb.put(hostKey, appId),
372
- serverDb.put(domainKey, record),
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 serverDb.get(hostKey).catch(() => null);
417
+ const currentOwner = await store.get(hostKey).catch(() => null);
412
418
  if (currentOwner === appId) {
413
- await serverDb.del(hostKey).catch(() => {});
419
+ await store.del(hostKey).catch(() => {});
414
420
  }
415
- await serverDb.del(domainKey).catch(() => {});
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 = serverDb
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 serverDb from "../../database/server/db";
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(appId: string, db: any = serverDb): Promise<void> {
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 serverDb from "../../database/server/db";
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 serverDb from "../../database/server/db";
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 serverDb.get(createSpaceKey(normalized));
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 serverDb.get(createSpaceMemberKey(userId, normalized));
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 serverDb.iterator({ gte: prefix, lte: `${prefix}\xff` })) {
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 serverDb.get(spaceKey);
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 serverDb.put(spaceKey, {
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 serverDb.get(spaceKey);
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 serverDb.put(spaceKey, {
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 serverDb from "../../database/server/db";
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 serverDb.get(agentKey);
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 =