@taskforcehq/taskforce 0.3.328 → 0.3.330

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 (485) hide show
  1. package/dist/Taskforce.module.css +523 -79
  2. package/dist/TaskforceCore.js +237 -230
  3. package/dist/annotatedAttachments/AnnotatedAttachmentSessionStore.js +1 -1
  4. package/dist/cli.js +34 -0
  5. package/dist/cliCloudTargetGuard.d.ts +5 -0
  6. package/dist/cliCloudTargetGuard.js +11 -0
  7. package/dist/components/features/AiProfilesModule.js +3 -5
  8. package/dist/components/features/AnnotatedAttachmentWorkspace.js +24 -8
  9. package/dist/components/features/TaskSettings.d.ts +12 -1
  10. package/dist/components/features/TaskSettings.js +217 -54
  11. package/dist/components/features/TaskforceAgentsModule.d.ts +1 -2
  12. package/dist/components/features/TaskforceAgentsModule.js +586 -116
  13. package/dist/components/features/agentCapabilities/AgentCapabilitiesPrototype.d.ts +1 -1
  14. package/dist/components/features/agentConnections/AgentConnectionControl.d.ts +15 -0
  15. package/dist/components/features/agentConnections/AgentConnectionControl.js +125 -0
  16. package/dist/components/features/agentConnections/ModelConnectionsPanel.d.ts +18 -0
  17. package/dist/components/features/agentConnections/ModelConnectionsPanel.js +393 -0
  18. package/dist/components/features/agentConnections/modelConnectionsApi.d.ts +65 -0
  19. package/dist/components/features/agentConnections/modelConnectionsApi.js +129 -0
  20. package/dist/components/features/planning/PlanningModule.js +2 -5
  21. package/dist/components/features/planning/PlanningTaskOrderList.d.ts +1 -1
  22. package/dist/components/features/planning/PlanningTaskOrderList.js +17 -6
  23. package/dist/components/features/planning/planningTaskArrangement.d.ts +1 -0
  24. package/dist/components/features/planning/planningTaskArrangement.js +5 -5
  25. package/dist/components/features/taskforceAgentAssignments/AgentBehaviorAssignments.js +15 -24
  26. package/dist/components/features/taskforceAgentEditorModel.d.ts +2 -1
  27. package/dist/components/features/taskforceAgentEditorModel.js +5 -1
  28. package/dist/components/features/workflowManager/workflowManagerApi.d.ts +1 -1
  29. package/dist/components/features/workflowManager/workflowManagerApi.js +3 -0
  30. package/dist/components/task/TaskCard.d.ts +5 -0
  31. package/dist/components/task/TaskCard.js +65 -10
  32. package/dist/components/task/TaskImageReviews.js +14 -5
  33. package/dist/components/task/TaskKanban.d.ts +6 -1
  34. package/dist/components/task/TaskKanban.js +152 -6
  35. package/dist/components/task/TaskList.d.ts +5 -0
  36. package/dist/components/task/TaskList.js +3 -3
  37. package/dist/components/task/TaskWorkflowAssignmentField.js +68 -10
  38. package/dist/components/ui/PasswordInput.d.ts +6 -0
  39. package/dist/components/ui/PasswordInput.js +11 -0
  40. package/dist/components/ui/TopNoticeLayer.js +1 -1
  41. package/dist/components/views/AppShellHeader.js +32 -11
  42. package/dist/components/views/PlanComparisonPage.js +12 -0
  43. package/dist/components/views/StandaloneLayout.js +32 -55
  44. package/dist/components/views/WidgetView.js +3 -3
  45. package/dist/components/views/panels/PlanningDrawer.js +5 -12
  46. package/dist/components/views/standalone/modals/AccountSettingsModal.js +26 -17
  47. package/dist/components/views/standalone/modals/SyncStatusModal.d.ts +4 -3
  48. package/dist/components/views/standalone/modals/SyncStatusModal.js +33 -38
  49. package/dist/config/envSchema.js +60 -1
  50. package/dist/config/localServiceRuntimeContract.d.ts +13 -0
  51. package/dist/config/localServiceRuntimeContract.js +135 -0
  52. package/dist/core/AiProfileService.js +46 -8
  53. package/dist/core/DeletedTaskLifecycleService.d.ts +1 -0
  54. package/dist/core/DeletedTaskLifecycleService.js +37 -6
  55. package/dist/core/McpTokenService.d.ts +23 -1
  56. package/dist/core/McpTokenService.js +93 -10
  57. package/dist/core/TaskAttachmentLinksDurableMutationService.d.ts +3 -2
  58. package/dist/core/TaskAttachmentLinksDurableMutationService.js +33 -9
  59. package/dist/core/TaskChecklistCommandService.d.ts +27 -0
  60. package/dist/core/TaskChecklistCommandService.js +83 -5
  61. package/dist/core/TaskLifecycleCommandService.d.ts +3 -1
  62. package/dist/core/TaskLifecycleCommandService.js +6 -2
  63. package/dist/core/Taskforce.d.ts +94 -2
  64. package/dist/core/Taskforce.js +760 -36
  65. package/dist/core/types.d.ts +14 -0
  66. package/dist/documentReviews/commandService.d.ts +2 -1
  67. package/dist/documentReviews/commandService.js +6 -3
  68. package/dist/hooks/sync/orchestratorShared.d.ts +1 -0
  69. package/dist/hooks/sync/orchestratorShared.js +2 -0
  70. package/dist/hooks/sync/useDurableLocalOutboxDrain.d.ts +1 -1
  71. package/dist/hooks/sync/useDurableTaskCreateMutation.js +1 -1
  72. package/dist/hooks/sync/useDurableTaskMetadataMutation.d.ts +1 -0
  73. package/dist/hooks/sync/useDurableTaskMetadataMutation.js +1 -0
  74. package/dist/hooks/sync/useDurableTaskStatusMutation.d.ts +1 -0
  75. package/dist/hooks/sync/useLocalSyncCoordinatorSnapshot.d.ts +3 -0
  76. package/dist/hooks/sync/useLocalSyncCoordinatorSnapshot.js +85 -9
  77. package/dist/hooks/sync/useSyncStatusControls.d.ts +4 -1
  78. package/dist/hooks/sync/useSyncStatusControls.js +47 -11
  79. package/dist/hooks/tasks/taskHttpMutation.js +1 -0
  80. package/dist/hooks/tasks/useCloudTaskSearch.d.ts +12 -0
  81. package/dist/hooks/tasks/useCloudTaskSearch.js +71 -0
  82. package/dist/hooks/tasks/useTaskDescriptionImageDraftRecovery.d.ts +16 -0
  83. package/dist/hooks/tasks/useTaskDescriptionImageDraftRecovery.js +197 -0
  84. package/dist/hooks/tasks/useTaskEditorNavigation.d.ts +16 -3
  85. package/dist/hooks/tasks/useTaskEditorNavigation.js +72 -13
  86. package/dist/hooks/tasks/useTaskFormActions.d.ts +6 -0
  87. package/dist/hooks/tasks/useTaskFormActions.js +65 -12
  88. package/dist/hooks/ui/useSettingsModel.d.ts +24 -2
  89. package/dist/hooks/ui/useSettingsModel.js +13 -2
  90. package/dist/hooks/ui/useSettingsPersistence.d.ts +12 -1
  91. package/dist/hooks/ui/useSettingsPersistence.js +74 -47
  92. package/dist/hooks/useFilterSort.d.ts +7 -3
  93. package/dist/hooks/useFilterSort.js +15 -5
  94. package/dist/hooks/useSyncOrchestrator.d.ts +3 -0
  95. package/dist/hooks/useSyncOrchestrator.js +111 -2
  96. package/dist/hooks/useTaskData.d.ts +40 -1
  97. package/dist/hooks/useTaskData.js +240 -9
  98. package/dist/hooks/useTaskMutations.d.ts +12 -2
  99. package/dist/hooks/useTaskMutations.js +266 -52
  100. package/dist/hooks/useTaskforce.d.ts +39 -9
  101. package/dist/hooks/useTaskforce.js +359 -40
  102. package/dist/hooks/useUiNotice.d.ts +4 -0
  103. package/dist/hooks/useUiNotice.js +4 -0
  104. package/dist/mcp/adminWorkspaceRegistrar.js +3 -3
  105. package/dist/mcp/clientRegistry.d.ts +2 -2
  106. package/dist/mcp/clientRegistry.js +1 -1
  107. package/dist/mcp/documentAssetRegistrar.js +53 -41
  108. package/dist/mcp/documentHelpers.d.ts +1 -0
  109. package/dist/mcp/documentHelpers.js +7 -3
  110. package/dist/mcp/durableTaskMutationRouter.d.ts +4 -1
  111. package/dist/mcp/durableTaskMutationRouter.js +10 -0
  112. package/dist/mcp/durableTaskRelationshipMutationRouter.js +4 -0
  113. package/dist/mcp/httpProtocolRouting.d.ts +10 -0
  114. package/dist/mcp/httpProtocolRouting.js +19 -0
  115. package/dist/mcp/localCliHealth.d.ts +2 -2
  116. package/dist/mcp/localCliHealth.js +2 -2
  117. package/dist/mcp/localServiceProxy.d.ts +1 -0
  118. package/dist/mcp/localServiceProxy.js +530 -68
  119. package/dist/mcp/planningAttachmentCommandAdapter.d.ts +3 -1
  120. package/dist/mcp/planningAttachmentCommandAdapter.js +20 -2
  121. package/dist/mcp/runtime.d.ts +54 -79
  122. package/dist/mcp/runtime.js +556 -139
  123. package/dist/mcp/taskPlanningRegistrar.js +64 -42
  124. package/dist/mcp/toolCallCompatibility.js +38 -1
  125. package/dist/mcp/toolCatalog.d.ts +1 -0
  126. package/dist/mcp/toolProfiles.d.ts +2 -0
  127. package/dist/mcp/toolProfiles.js +10 -0
  128. package/dist/mcp/toolRegistry.d.ts +1 -0
  129. package/dist/mcp/toolRegistry.js +1 -0
  130. package/dist/mcp/workflowExecutionRegistrar.js +4 -4
  131. package/dist/migrations/taskSchemaMigrations.d.ts +5 -0
  132. package/dist/migrations/taskSchemaMigrations.js +427 -0
  133. package/dist/runtime/appGateDefinitions.d.ts +30 -6
  134. package/dist/runtime/appGateDefinitions.js +6 -6
  135. package/dist/runtime/appGates.d.ts +13 -13
  136. package/dist/runtime/appGates.js +36 -13
  137. package/dist/runtime/nodeAppGates.d.ts +8 -0
  138. package/dist/runtime/nodeAppGates.js +27 -0
  139. package/dist/server/cloudCollectionRead.d.ts +1 -1
  140. package/dist/server/cloudCollectionRead.js +2 -2
  141. package/dist/server/index.d.ts +6 -0
  142. package/dist/server/index.js +123 -14
  143. package/dist/server/localDatabaseIdentity.js +4 -1
  144. package/dist/server/localServiceLease.d.ts +3 -0
  145. package/dist/server/localServiceLease.js +11 -2
  146. package/dist/server/localServiceSessions.d.ts +14 -17
  147. package/dist/server/localServiceSessions.js +308 -94
  148. package/dist/server/localWorkspaceSyncServerRuntime.js +12 -7
  149. package/dist/server/rateLimit.d.ts +1 -0
  150. package/dist/server/rateLimit.js +4 -0
  151. package/dist/server/realtimeSyncWs.js +36 -12
  152. package/dist/server/routes/admin.d.ts +4 -0
  153. package/dist/server/routes/admin.js +113 -3
  154. package/dist/server/routes/agentRoles.js +3 -2
  155. package/dist/server/routes/agentSkills.js +3 -2
  156. package/dist/server/routes/agents.d.ts +7 -0
  157. package/dist/server/routes/agents.js +394 -39
  158. package/dist/server/routes/annotatedAttachments.js +3 -2
  159. package/dist/server/routes/auth.js +3 -1
  160. package/dist/server/routes/billing.js +5 -1
  161. package/dist/server/routes/durableTaskHttpRouters.d.ts +11 -2
  162. package/dist/server/routes/executorPhaseAApprovals.d.ts +19 -0
  163. package/dist/server/routes/executorPhaseAApprovals.js +140 -0
  164. package/dist/server/routes/executorPhaseAIssuerRedemptions.d.ts +11 -0
  165. package/dist/server/routes/executorPhaseAIssuerRedemptions.js +24 -0
  166. package/dist/server/routes/githubReviewEvidence.d.ts +19 -0
  167. package/dist/server/routes/githubReviewEvidence.js +116 -0
  168. package/dist/server/routes/localService.d.ts +15 -4
  169. package/dist/server/routes/localService.js +138 -40
  170. package/dist/server/routes/modelConnections.d.ts +24 -0
  171. package/dist/server/routes/modelConnections.js +205 -0
  172. package/dist/server/routes/primitives.d.ts +2 -0
  173. package/dist/server/routes/shared.d.ts +19 -0
  174. package/dist/server/routes/shared.js +95 -19
  175. package/dist/server/routes/sync.js +1 -0
  176. package/dist/server/routes/syncAuxRoutes.js +9 -2
  177. package/dist/server/routes/syncPullApplyRoutes.js +23 -4
  178. package/dist/server/routes/syncPushRoutes.d.ts +1 -0
  179. package/dist/server/routes/syncPushRoutes.js +1 -0
  180. package/dist/server/routes/syncV3FeedRoutes.js +27 -16
  181. package/dist/server/routes/syncV3LocalCaptureRoutes.js +28 -2
  182. package/dist/server/routes/syncV3LocalFeedApplyRoutes.d.ts +1 -0
  183. package/dist/server/routes/syncV3LocalFeedApplyRoutes.js +26 -0
  184. package/dist/server/routes/syncV3OperationRoutes.js +45 -9
  185. package/dist/server/routes/tasks.js +124 -13
  186. package/dist/server/routes/workflows.js +9 -1
  187. package/dist/server/routes/workspaces.js +43 -1
  188. package/dist/server/routes.js +59 -0
  189. package/dist/server/workspaceDeletionAdmission.d.ts +23 -0
  190. package/dist/server/workspaceDeletionAdmission.js +50 -0
  191. package/dist/service/localServiceCli.js +16 -0
  192. package/dist/service/localServiceClientLifecycle.js +36 -10
  193. package/dist/services/codexAppServerModelGateway.d.ts +161 -0
  194. package/dist/services/codexAppServerModelGateway.js +663 -0
  195. package/dist/services/codexDeviceCodeLoginManager.d.ts +39 -0
  196. package/dist/services/codexDeviceCodeLoginManager.js +265 -0
  197. package/dist/services/codexModelProviderConnectionLifecycle.d.ts +8 -0
  198. package/dist/services/codexModelProviderConnectionLifecycle.js +73 -0
  199. package/dist/services/executorPhaseAApprovalRuntime.d.ts +14 -0
  200. package/dist/services/executorPhaseAApprovalRuntime.js +24 -0
  201. package/dist/services/executorPhaseAApprovalService.d.ts +40 -0
  202. package/dist/services/executorPhaseAApprovalService.js +609 -0
  203. package/dist/services/executorPhaseADriftEvaluator.d.ts +78 -0
  204. package/dist/services/executorPhaseADriftEvaluator.js +93 -0
  205. package/dist/services/executorPhaseAIssuerCore.d.ts +126 -0
  206. package/dist/services/executorPhaseAIssuerCore.js +295 -0
  207. package/dist/services/executorPhaseAIssuerRedemptionService.d.ts +34 -0
  208. package/dist/services/executorPhaseAIssuerRedemptionService.js +158 -0
  209. package/dist/services/githubReviewEvidenceRuntime.d.ts +14 -0
  210. package/dist/services/githubReviewEvidenceRuntime.js +30 -0
  211. package/dist/services/githubReviewEvidenceService.d.ts +93 -0
  212. package/dist/services/githubReviewEvidenceService.js +336 -0
  213. package/dist/services/modelGateway.d.ts +7 -0
  214. package/dist/services/modelProviderConnectionService.d.ts +71 -0
  215. package/dist/services/modelProviderConnectionService.js +279 -0
  216. package/dist/services/modelProviderCredentialHome.d.ts +32 -0
  217. package/dist/services/modelProviderCredentialHome.js +271 -0
  218. package/dist/services/ownerScopedModelConnectionGateway.d.ts +12 -0
  219. package/dist/services/ownerScopedModelConnectionGateway.js +30 -0
  220. package/dist/services/taskforceAgentConnectionBindingService.d.ts +66 -0
  221. package/dist/services/taskforceAgentConnectionBindingService.js +185 -0
  222. package/dist/services/taskforceAgentMcpBridge.d.ts +8 -2
  223. package/dist/services/taskforceAgentMcpBridge.js +30 -27
  224. package/dist/shared/adminEdgeProxy.d.ts +5 -0
  225. package/dist/shared/adminEdgeProxy.js +94 -0
  226. package/dist/shared/adminProxySessionCookies.d.ts +16 -0
  227. package/dist/shared/adminProxySessionCookies.js +86 -0
  228. package/dist/shared/aiProfileColors.d.ts +31 -1
  229. package/dist/shared/aiProfileColors.js +14 -6
  230. package/dist/shared/executorPhaseAApprovalGoldenVector.json +269 -0
  231. package/dist/shared/executorPhaseAApprovalReceipt.d.ts +112 -0
  232. package/dist/shared/executorPhaseAApprovalReceipt.js +58 -0
  233. package/dist/shared/executorPhaseAApprovalTrustPolicy.json +10 -0
  234. package/dist/shared/executorPhaseADriftContracts.d.ts +37 -0
  235. package/dist/shared/executorPhaseADriftContracts.js +63 -0
  236. package/dist/shared/executorPhaseAIssuerContracts.d.ts +75 -0
  237. package/dist/shared/executorPhaseAIssuerContracts.js +90 -0
  238. package/dist/shared/executorPhaseARunAuthorization.d.ts +120 -0
  239. package/dist/shared/executorPhaseARunAuthorization.js +232 -0
  240. package/dist/shared/executorPhaseASchemaValidation.d.ts +7 -0
  241. package/dist/shared/executorPhaseASchemaValidation.js +53 -0
  242. package/dist/shared/executorPhaseASchemas/approval-receipt.schema.json +106 -0
  243. package/dist/shared/executorPhaseASchemas/drift-attestation.schema.json +54 -0
  244. package/dist/shared/executorPhaseASchemas/drift-request.schema.json +47 -0
  245. package/dist/shared/executorPhaseASchemas/foundation-manifest.schema.json +29 -0
  246. package/dist/shared/executorPhaseASchemas/issuer-audit-record.schema.json +24 -0
  247. package/dist/shared/executorPhaseASchemas/issuer-proof.schema.json +43 -0
  248. package/dist/shared/executorPhaseASchemas/issuer-redemption-request.schema.json +18 -0
  249. package/dist/shared/executorPhaseASchemas/issuer-redemption-response.schema.json +39 -0
  250. package/dist/shared/executorPhaseASchemas/logical-envelope.schema.json +149 -0
  251. package/dist/shared/executorPhaseASchemas/preflight-report.schema.json +216 -0
  252. package/dist/shared/executorPhaseASchemas/run-capability.schema.json +111 -0
  253. package/dist/shared/executorPhaseASchemas/sender-proof.schema.json +37 -0
  254. package/dist/shared/executorPhaseASchemas/workload-grant.schema.json +68 -0
  255. package/dist/shared/executorPhaseASchemas/workload-jwt-claims.schema.json +67 -0
  256. package/dist/shared/executorPhaseATiming.d.ts +1 -0
  257. package/dist/shared/executorPhaseATiming.js +1 -0
  258. package/dist/shared/planningIdentity.js +1 -1
  259. package/dist/shared/productLogoKeys.d.ts +2 -0
  260. package/dist/shared/productLogoKeys.js +18 -0
  261. package/dist/shared/taskforceAgentDefinition.d.ts +0 -1
  262. package/dist/shared/taskforceAgentDefinition.js +6 -3
  263. package/dist/shared/taskforceAgentModels.d.ts +1 -0
  264. package/dist/shared/taskforceAgentModels.js +36 -3
  265. package/dist/shared/userFeatureGrants.d.ts +4 -0
  266. package/dist/shared/userFeatureGrants.js +7 -0
  267. package/dist/storage/executorPhaseAApprovalReceiptStore.d.ts +37 -0
  268. package/dist/storage/executorPhaseAApprovalReceiptStore.js +81 -0
  269. package/dist/storage/executorPhaseARunAuthorizationStore.d.ts +103 -0
  270. package/dist/storage/executorPhaseARunAuthorizationStore.js +492 -0
  271. package/dist/storage/githubReviewEvidenceInstallationStore.d.ts +26 -0
  272. package/dist/storage/githubReviewEvidenceInstallationStore.js +89 -0
  273. package/dist/storage/modelProviderConnectionStore.d.ts +99 -0
  274. package/dist/storage/modelProviderConnectionStore.js +446 -0
  275. package/dist/storage/postgresAdapter.d.ts +24 -3
  276. package/dist/storage/postgresAdapter.js +117 -14
  277. package/dist/storage/postgresWorker.js +22 -5
  278. package/dist/storage/postgresWorkerProtocol.d.ts +30 -0
  279. package/dist/storage/postgresWorkerProtocol.js +30 -0
  280. package/dist/storage/taskforceAgentConnectionBindingStore.d.ts +31 -0
  281. package/dist/storage/taskforceAgentConnectionBindingStore.js +84 -0
  282. package/dist/sync/cloudSyncApi.d.ts +4 -1
  283. package/dist/sync/cloudSyncApi.js +7 -2
  284. package/dist/sync/contentSyncState.d.ts +1 -1
  285. package/dist/sync/coordinator/localSyncExecutionPermitStore.d.ts +1 -0
  286. package/dist/sync/coordinator/localSyncExecutionPermitStore.js +67 -30
  287. package/dist/sync/coordinator/localWorkspaceSyncPendingV2PushProgress.d.ts +10 -0
  288. package/dist/sync/coordinator/localWorkspaceSyncPendingV2PushProgress.js +29 -0
  289. package/dist/sync/coordinator/localWorkspaceSyncRunner.js +6 -2
  290. package/dist/sync/coordinator/localWorkspaceSyncRunnerState.d.ts +15 -1
  291. package/dist/sync/coordinator/localWorkspaceSyncRunnerState.js +99 -2
  292. package/dist/sync/coordinator/workspaceSyncCredentialBroker.d.ts +1 -0
  293. package/dist/sync/coordinator/workspaceSyncCredentialBroker.js +33 -4
  294. package/dist/sync/engine/workspaceSyncContentLifecycleAdapter.d.ts +2 -1
  295. package/dist/sync/engine/workspaceSyncContentVersionStore.d.ts +38 -0
  296. package/dist/sync/engine/workspaceSyncContentVersionStore.js +50 -1
  297. package/dist/sync/engine/workspaceSyncEngineBrowserGatewayRemoteServices.js +20 -2
  298. package/dist/sync/engine/workspaceSyncEngineLifecyclePolicy.js +6 -6
  299. package/dist/sync/engine/workspaceSyncEngineLocalServices.d.ts +4 -0
  300. package/dist/sync/engine/workspaceSyncEngineLocalServices.js +11 -0
  301. package/dist/sync/engine/workspaceSyncEnginePushCompletion.d.ts +14 -0
  302. package/dist/sync/engine/workspaceSyncEnginePushCompletion.js +84 -0
  303. package/dist/sync/engine/workspaceSyncEngineRecovery.js +1 -0
  304. package/dist/sync/engine/workspaceSyncEngineRemoteServices.d.ts +11 -0
  305. package/dist/sync/engine/workspaceSyncEngineRemoteServices.js +2 -1
  306. package/dist/sync/engine/workspaceSyncEngineRuntime.d.ts +1 -0
  307. package/dist/sync/engine/workspaceSyncEngineRuntime.js +1 -0
  308. package/dist/sync/engine/workspaceSyncEngineServerRemoteServices.js +31 -4
  309. package/dist/sync/engine/workspaceSyncEngineServerRunnerOperations.d.ts +3 -1
  310. package/dist/sync/engine/workspaceSyncEngineServerRunnerOperations.js +134 -43
  311. package/dist/sync/engine/workspaceSyncEngineServerSnapshotReader.js +6 -0
  312. package/dist/sync/engine/workspaceSyncEngineTransfers.d.ts +1 -1
  313. package/dist/sync/engine/workspaceSyncEngineTransfers.js +11 -4
  314. package/dist/sync/engine/workspaceSyncV2ChangeDispatcher.d.ts +1 -0
  315. package/dist/sync/engine/workspaceSyncV2ChangeDispatcher.js +29 -0
  316. package/dist/sync/syncApplyHandlers.d.ts +2 -0
  317. package/dist/sync/syncApplyHandlers.js +10 -1
  318. package/dist/sync/syncService.d.ts +17 -0
  319. package/dist/sync/syncService.js +87 -19
  320. package/dist/sync/taskforceAgentSyncAuthorization.d.ts +16 -0
  321. package/dist/sync/taskforceAgentSyncAuthorization.js +20 -0
  322. package/dist/sync/v3/combinedFeedCapability.js +8 -0
  323. package/dist/sync/v3/durableInitiativeMutationRouter.js +18 -10
  324. package/dist/sync/v3/durableOperationReplay.d.ts +14 -0
  325. package/dist/sync/v3/durableOperationReplay.js +18 -0
  326. package/dist/sync/v3/durableTaskAttachmentLinksMutationRouter.d.ts +2 -0
  327. package/dist/sync/v3/durableTaskAttachmentLinksMutationRouter.js +14 -1
  328. package/dist/sync/v3/durableTaskChecklistMutationRouter.d.ts +4 -1
  329. package/dist/sync/v3/durableTaskChecklistMutationRouter.js +62 -15
  330. package/dist/sync/v3/durableTaskCommentMutationRouter.js +3 -0
  331. package/dist/sync/v3/durableTaskHttpBulkMutationRouter.d.ts +1 -0
  332. package/dist/sync/v3/durableTaskHttpBulkMutationRouter.js +30 -8
  333. package/dist/sync/v3/durableTaskHttpRootMutationRouter.d.ts +5 -3
  334. package/dist/sync/v3/durableTaskHttpRootMutationRouter.js +37 -2
  335. package/dist/sync/v3/durableTaxonomyMutationRouter.js +5 -0
  336. package/dist/sync/v3/durableWorkflowRuntimeMutationRouter.d.ts +11 -0
  337. package/dist/sync/v3/durableWorkflowRuntimeMutationRouter.js +39 -10
  338. package/dist/sync/v3/durableWorkstreamMutationRouter.js +18 -10
  339. package/dist/sync/v3/durableWorkstreamTaskOrderMutationRouter.js +16 -5
  340. package/dist/sync/v3/localOutboxDispatchRuntime.js +2 -2
  341. package/dist/sync/v3/localTaskAttachmentLinksOutboxService.d.ts +2 -0
  342. package/dist/sync/v3/localTaskAttachmentLinksOutboxService.js +47 -7
  343. package/dist/sync/v3/localTaskChecklistOutboxHandler.js +16 -2
  344. package/dist/sync/v3/localTaskChecklistOutboxService.d.ts +4 -0
  345. package/dist/sync/v3/localTaskChecklistOutboxService.js +14 -1
  346. package/dist/sync/v3/localTaskCreateOutboxService.js +15 -6
  347. package/dist/sync/v3/localTaskMetadataClient.d.ts +1 -0
  348. package/dist/sync/v3/localTaskMetadataClient.js +1 -0
  349. package/dist/sync/v3/localTaskMetadataOutboxHandler.js +5 -1
  350. package/dist/sync/v3/localTaskMetadataOutboxService.d.ts +2 -0
  351. package/dist/sync/v3/localTaskMetadataOutboxService.js +7 -0
  352. package/dist/sync/v3/localTaskRestoreOutboxService.js +14 -6
  353. package/dist/sync/v3/localTaskStatusClient.d.ts +1 -0
  354. package/dist/sync/v3/localTaskStatusClient.js +6 -1
  355. package/dist/sync/v3/localTaskStatusOutboxService.d.ts +10 -0
  356. package/dist/sync/v3/localTaskStatusOutboxService.js +272 -24
  357. package/dist/sync/v3/syncDurabilityStore.d.ts +41 -0
  358. package/dist/sync/v3/syncDurabilityStore.js +199 -13
  359. package/dist/sync/v3/taskAttachmentLinksMutationService.d.ts +6 -4
  360. package/dist/sync/v3/taskAttachmentLinksMutationService.js +19 -10
  361. package/dist/sync/v3/taskChecklistMutationService.d.ts +15 -2
  362. package/dist/sync/v3/taskChecklistMutationService.js +48 -1
  363. package/dist/sync/v3/taskCreateMutationService.d.ts +2 -2
  364. package/dist/sync/v3/taskCreateMutationService.js +7 -4
  365. package/dist/sync/v3/taskMetadataMutationService.d.ts +3 -0
  366. package/dist/sync/v3/taskMetadataMutationService.js +4 -0
  367. package/dist/sync/v3/taskRestoreMutationService.d.ts +2 -2
  368. package/dist/sync/v3/taskRestoreMutationService.js +7 -4
  369. package/dist/sync/v3/taskStatusMutationService.d.ts +31 -1
  370. package/dist/sync/v3/taskStatusMutationService.js +123 -3
  371. package/dist/sync/v3/workflowAssignmentSync.d.ts +6 -0
  372. package/dist/sync/v3/workflowAssignmentSync.js +30 -0
  373. package/dist/sync/v3/workspaceSyncJournalReader.js +1 -1
  374. package/dist/sync/v3/workspaceSyncOperationRetentionService.d.ts +16 -0
  375. package/dist/sync/v3/workspaceSyncOperationRetentionService.js +83 -0
  376. package/dist/sync/v3/workspaceSyncV2ProjectionExclusions.d.ts +1 -1
  377. package/dist/sync/v3/workspaceSyncV2ProjectionExclusions.js +13 -3
  378. package/dist/sync/v3/workspaceSyncV3AttachmentApplyObligationStore.d.ts +11 -0
  379. package/dist/sync/v3/workspaceSyncV3AttachmentApplyObligationStore.js +27 -10
  380. package/dist/sync/v3/workspaceSyncV3AttachmentAssetHydration.d.ts +2 -1
  381. package/dist/sync/v3/workspaceSyncV3AttachmentAssetHydration.js +52 -10
  382. package/dist/sync/v3/workspaceSyncV3CloudOperationHandler.d.ts +1 -0
  383. package/dist/sync/v3/workspaceSyncV3CloudOperationHandler.js +18 -3
  384. package/dist/sync/v3/workspaceSyncV3CombinedFeedOrchestrator.js +8 -3
  385. package/dist/sync/v3/workspaceSyncV3CombinedLocalApply.js +51 -10
  386. package/dist/sync/v3/workspaceSyncV3CombinedRepairBaseline.d.ts +14 -0
  387. package/dist/sync/v3/workspaceSyncV3CombinedRepairBaseline.js +49 -25
  388. package/dist/sync/v3/workspaceSyncV3CombinedRepairMaterialization.d.ts +13 -4
  389. package/dist/sync/v3/workspaceSyncV3CombinedRepairMaterialization.js +124 -57
  390. package/dist/sync/v3/workspaceSyncV3CombinedRepairSnapshot.d.ts +20 -0
  391. package/dist/sync/v3/workspaceSyncV3CombinedRepairSnapshot.js +106 -30
  392. package/dist/sync/v3/workspaceSyncV3CombinedWireContract.d.ts +4 -1
  393. package/dist/sync/v3/workspaceSyncV3CombinedWireContract.js +34 -0
  394. package/dist/sync/v3/workspaceSyncV3CoverageRegistry.js +12 -0
  395. package/dist/sync/v3/workspaceSyncV3FeedProfile.d.ts +1 -1
  396. package/dist/sync/v3/workspaceSyncV3LegacyBoundaryAttestation.d.ts +1 -0
  397. package/dist/sync/v3/workspaceSyncV3LegacyBoundaryAttestation.js +23 -10
  398. package/dist/sync/v3/workspaceSyncV3NestedTaskApply.d.ts +3 -0
  399. package/dist/sync/v3/workspaceSyncV3NestedTaskApply.js +64 -13
  400. package/dist/sync/v3/workspaceSyncV3NestedTaskCodecs.d.ts +9 -0
  401. package/dist/sync/v3/workspaceSyncV3NestedTaskCodecs.js +26 -0
  402. package/dist/sync/v3/workspaceSyncV3NestedTaskProjection.d.ts +15 -5
  403. package/dist/sync/v3/workspaceSyncV3NestedTaskProjection.js +50 -14
  404. package/dist/sync/v3/workspaceSyncV3NestedTaskRepairSnapshot.d.ts +2 -1
  405. package/dist/sync/v3/workspaceSyncV3NestedTaskRepairSnapshot.js +11 -3
  406. package/dist/sync/v3/workspaceSyncV3OperationProtocol.d.ts +5 -0
  407. package/dist/sync/v3/workspaceSyncV3OperatorDiagnostics.d.ts +7 -0
  408. package/dist/sync/v3/workspaceSyncV3OperatorDiagnostics.js +55 -9
  409. package/dist/sync/v3/workspaceSyncV3RepairSnapshotRetentionService.d.ts +17 -0
  410. package/dist/sync/v3/workspaceSyncV3RepairSnapshotRetentionService.js +64 -0
  411. package/dist/sync/v3/workspaceSyncV3TaskCommentAudit.js +9 -2
  412. package/dist/sync/v3/workspaceSyncV3TaskCoverCoverage.d.ts +7 -0
  413. package/dist/sync/v3/workspaceSyncV3TaskCoverCoverage.js +37 -0
  414. package/dist/sync/v3/workspaceSyncV3TaskCoverWireContract.d.ts +6 -0
  415. package/dist/sync/v3/workspaceSyncV3TaskCoverWireContract.js +9 -0
  416. package/dist/sync/v3/workspaceSyncV3WorkflowTaskCoverCoverage.d.ts +7 -0
  417. package/dist/sync/v3/workspaceSyncV3WorkflowTaskCoverCoverage.js +33 -0
  418. package/dist/sync/v3/workspaceSyncV3WorkflowTaskCoverWireContract.d.ts +7 -0
  419. package/dist/sync/v3/workspaceSyncV3WorkflowTaskCoverWireContract.js +8 -0
  420. package/dist/sync/workspacePullFeed.js +2 -1
  421. package/dist/sync/workspaceRepair.d.ts +8 -2
  422. package/dist/sync/workspaceRepair.js +222 -6
  423. package/dist/sync/workspaceSyncModel.d.ts +21 -0
  424. package/dist/sync/workspaceSyncModel.js +35 -7
  425. package/dist/sync/workspaceSyncState.d.ts +1 -0
  426. package/dist/sync/workspaceSyncV2SnapshotBuilder.d.ts +6 -0
  427. package/dist/sync/workspaceSyncV2SnapshotBuilder.js +5 -0
  428. package/dist/types.d.ts +47 -1
  429. package/dist/types.js +6 -0
  430. package/dist/ui/assets/AiIdentityRosterCard-OcSz1PkK.js +1 -0
  431. package/dist/ui/assets/AiProfilesModule-ByhYW5Xi.js +1 -0
  432. package/dist/ui/assets/AnnotatedAttachmentWorkspace-BTM6nIg_.js +3 -0
  433. package/dist/ui/assets/AnnotatedAttachmentWorkspace-TzYu7pkG.css +1 -0
  434. package/dist/ui/assets/{AssetTraySortControl-Kf1pelSy.js → AssetTraySortControl-DabEG8L4.js} +1 -1
  435. package/dist/ui/assets/{ContextAttachmentManager-B8boOs6Q.js → ContextAttachmentManager-Coa8yVGM.js} +2 -2
  436. package/dist/ui/assets/{DocumentWorkspace-DXH4XUsB.js → DocumentWorkspace-BB0qhdix.js} +1 -1
  437. package/dist/ui/assets/{EntityActivityTimeline-BtSTq0ON.js → EntityActivityTimeline-CZ8x4UJE.js} +1 -1
  438. package/dist/ui/assets/PlanningModule-pRPjR7v5.js +1 -0
  439. package/dist/ui/assets/PlansPage-D86pZSSl.js +1 -0
  440. package/dist/ui/assets/TaskContextUpload-BVIkU9yT.js +1 -0
  441. package/dist/ui/assets/TaskSettings-Cv1mNhv_.js +12 -0
  442. package/dist/ui/assets/TaskforceAgentsModule-b-8R25cJ.css +1 -0
  443. package/dist/ui/assets/TaskforceAgentsModule-gmH-PD2q.js +24 -0
  444. package/dist/ui/assets/{WorkflowManagerModule-DWFspC-o.js → WorkflowManagerModule-DbfnHJ-f.js} +1 -1
  445. package/dist/ui/assets/index-BZ-hdZSk.css +1 -0
  446. package/dist/ui/assets/index-CTsDBaef.js +7 -0
  447. package/dist/ui/assets/{vendor-icons-BkFLXavV.js → vendor-icons-Bsq-mcEn.js} +1 -1
  448. package/dist/ui/branding/logos/letterhead_dark.png +0 -0
  449. package/dist/ui/branding/logos/letterhead_light.png +0 -0
  450. package/dist/ui/branding/logos/signature_dark.png +0 -0
  451. package/dist/ui/branding/logos/signature_light.png +0 -0
  452. package/dist/ui/index.html +3 -3
  453. package/dist/utils/aiProfileDefaultLogo.js +16 -48
  454. package/dist/utils/httpSetCookie.d.ts +1 -0
  455. package/dist/utils/httpSetCookie.js +4 -1
  456. package/dist/utils/localRuntimeUrl.d.ts +1 -0
  457. package/dist/utils/localRuntimeUrl.js +14 -0
  458. package/dist/utils/productLogoRegistry.d.ts +2 -0
  459. package/dist/utils/productLogoRegistry.js +36 -0
  460. package/dist/utils/syncStatusPresentation.d.ts +4 -0
  461. package/dist/utils/syncStatusPresentation.js +17 -0
  462. package/dist/utils/taskActivity.d.ts +3 -2
  463. package/dist/utils/taskActivity.js +19 -2
  464. package/dist/utils/taskEditorReconciliation.d.ts +40 -0
  465. package/dist/utils/taskEditorReconciliation.js +217 -0
  466. package/dist/utils/taskEvents.d.ts +2 -0
  467. package/dist/utils/taskNormalization.d.ts +1 -0
  468. package/dist/utils/taskNormalization.js +39 -0
  469. package/dist/utils/taskSearch.js +2 -2
  470. package/dist/utils/uiNotice.d.ts +4 -0
  471. package/dist/utils/workspaceSyncPresentation.d.ts +1 -1
  472. package/dist/utils/workspaceSyncPresentation.js +23 -17
  473. package/package.json +36 -6
  474. package/dist/ui/assets/AiIdentityRosterCard-MZs7lVED.js +0 -1
  475. package/dist/ui/assets/AiProfilesModule-C3i0LOxe.js +0 -1
  476. package/dist/ui/assets/AnnotatedAttachmentWorkspace-CBRZ8rca.css +0 -1
  477. package/dist/ui/assets/AnnotatedAttachmentWorkspace-DVZk5Tln.js +0 -3
  478. package/dist/ui/assets/PlanningModule-BPVyEa-f.js +0 -1
  479. package/dist/ui/assets/PlansPage-ChqgxALc.js +0 -1
  480. package/dist/ui/assets/TaskContextUpload-CB3ol0sN.js +0 -1
  481. package/dist/ui/assets/TaskSettings-g4ECKNOz.js +0 -12
  482. package/dist/ui/assets/TaskforceAgentsModule-BazdUwxZ.js +0 -21
  483. package/dist/ui/assets/TaskforceAgentsModule-D6IC0S7Q.css +0 -1
  484. package/dist/ui/assets/index-BUplSsv_.js +0 -7
  485. package/dist/ui/assets/index-gz2EXuoK.css +0 -1
@@ -0,0 +1,99 @@
1
+ import type { DatabaseAdapter } from './databaseAdapter.js';
2
+ export type ModelProviderConnectionLifecycleStatus = 'pending' | 'active' | 'reconnect_required' | 'disconnected' | 'revoked';
3
+ export interface ModelProviderConnectionDisplayMetadata {
4
+ displayName?: string;
5
+ accountLabel?: string;
6
+ accountEmail?: string;
7
+ planLabel?: string;
8
+ }
9
+ export interface ModelProviderConnectionRecord {
10
+ id: string;
11
+ tenantId: string;
12
+ ownerUserId: string;
13
+ providerKey: string;
14
+ authenticationType: string;
15
+ lifecycleStatus: ModelProviderConnectionLifecycleStatus;
16
+ displayMetadata: ModelProviderConnectionDisplayMetadata;
17
+ credentialHomeRef: string;
18
+ lastVerifiedAt: string | null;
19
+ lastRefreshedAt: string | null;
20
+ lastFailureAt: string | null;
21
+ failureCode: string | null;
22
+ disconnectedAt: string | null;
23
+ revokedAt: string | null;
24
+ createdAt: string;
25
+ updatedAt: string;
26
+ }
27
+ export interface ModelProviderConnectionLease {
28
+ connectionId: string;
29
+ token: string;
30
+ operation: string;
31
+ acquiredAt: string;
32
+ expiresAt: string;
33
+ }
34
+ export declare class ModelProviderConnectionError extends Error {
35
+ readonly statusCode: number;
36
+ readonly code: string;
37
+ constructor(message: string, statusCode: number, code: string);
38
+ }
39
+ export declare function sanitizeModelProviderConnectionDisplayMetadata(value: unknown): ModelProviderConnectionDisplayMetadata;
40
+ export declare class ModelProviderConnectionStore {
41
+ private readonly db;
42
+ private readonly tenantId;
43
+ private readonly now;
44
+ constructor(db: DatabaseAdapter, tenantId: string, now?: () => Date);
45
+ private leaseNow;
46
+ private leaseClockPredicate;
47
+ create(input: {
48
+ ownerUserId: string;
49
+ providerKey: string;
50
+ authenticationType: string;
51
+ displayMetadata?: unknown;
52
+ }): ModelProviderConnectionRecord;
53
+ listOwned(ownerUserIdRaw: string): ModelProviderConnectionRecord[];
54
+ getOwned(ownerUserIdRaw: string, connectionIdRaw: string): ModelProviderConnectionRecord | null;
55
+ requireOwned(ownerUserId: string, connectionId: string): ModelProviderConnectionRecord;
56
+ renameOwned(ownerUserId: string, connectionId: string, displayNameRaw: unknown): ModelProviderConnectionRecord;
57
+ requireOwnedUnderLease(ownerUserId: string, connectionId: string, leaseToken: string): ModelProviderConnectionRecord;
58
+ deletePendingOwned(ownerUserId: string, connectionId: string): boolean;
59
+ acquireLease(input: {
60
+ ownerUserId: string;
61
+ connectionId: string;
62
+ operation: string;
63
+ durationMs?: number;
64
+ }): ModelProviderConnectionLease;
65
+ renewLease(lease: ModelProviderConnectionLease, durationMs?: number): boolean;
66
+ releaseLease(lease: ModelProviderConnectionLease): boolean;
67
+ completeLease(lease: ModelProviderConnectionLease): boolean;
68
+ deleteCleanableUnderLease(input: {
69
+ ownerUserId: string;
70
+ connectionId: string;
71
+ leaseToken: string;
72
+ }): boolean;
73
+ markVerified(input: {
74
+ ownerUserId: string;
75
+ connectionId: string;
76
+ leaseToken: string;
77
+ displayMetadata?: unknown;
78
+ }): ModelProviderConnectionRecord;
79
+ markRefreshed(input: {
80
+ ownerUserId: string;
81
+ connectionId: string;
82
+ leaseToken: string;
83
+ displayMetadata?: unknown;
84
+ }): ModelProviderConnectionRecord;
85
+ markReconnectRequired(input: {
86
+ ownerUserId: string;
87
+ connectionId: string;
88
+ leaseToken: string;
89
+ failureCode: string;
90
+ }): ModelProviderConnectionRecord;
91
+ markDisconnected(input: {
92
+ ownerUserId: string;
93
+ connectionId: string;
94
+ leaseToken: string;
95
+ }): ModelProviderConnectionRecord;
96
+ private updateUnderLease;
97
+ private updateUnderLeaseTransaction;
98
+ private insertEvent;
99
+ }
@@ -0,0 +1,446 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ export class ModelProviderConnectionError extends Error {
3
+ statusCode;
4
+ code;
5
+ constructor(message, statusCode, code) {
6
+ super(message);
7
+ this.statusCode = statusCode;
8
+ this.code = code;
9
+ this.name = 'ModelProviderConnectionError';
10
+ }
11
+ }
12
+ const SAFE_METADATA_KEYS = ['accountLabel', 'accountEmail', 'planLabel'];
13
+ const MAX_DISPLAY_NAME_LENGTH = 80;
14
+ const POSTGRES_LEASE_CLOCK_SQL = `TO_CHAR(
15
+ clock_timestamp() AT TIME ZONE 'UTC',
16
+ 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
17
+ )`;
18
+ const POSTGRES_LEASE_EXPIRY_SQL = `TO_CHAR(
19
+ (clock_timestamp() + (CAST(? AS BIGINT) * INTERVAL '1 millisecond')) AT TIME ZONE 'UTC',
20
+ 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
21
+ )`;
22
+ function randomOpaqueId(prefix) {
23
+ return `${prefix}_${randomBytes(24).toString('base64url')}`;
24
+ }
25
+ function normalizeIdentifier(value, label) {
26
+ const normalized = String(value || '').trim().toLowerCase();
27
+ if (!/^[a-z][a-z0-9._-]{0,63}$/.test(normalized)) {
28
+ throw new ModelProviderConnectionError(`${label} is invalid.`, 400, 'MODEL_CONNECTION_INVALID_INPUT');
29
+ }
30
+ return normalized;
31
+ }
32
+ export function sanitizeModelProviderConnectionDisplayMetadata(value) {
33
+ if (!value || typeof value !== 'object' || Array.isArray(value))
34
+ return {};
35
+ const source = value;
36
+ const result = {};
37
+ for (const key of SAFE_METADATA_KEYS) {
38
+ const normalized = typeof source[key] === 'string'
39
+ ? String(source[key]).trim().slice(0, 200)
40
+ : '';
41
+ const sanitized = normalized
42
+ .replace(/sk-[A-Za-z0-9_-]{8,}/g, '[redacted]')
43
+ .replace(/(Bearer\s+)[^\s]+/gi, '$1[redacted]')
44
+ .replace(/\beyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\b/g, '[redacted]');
45
+ if (sanitized)
46
+ result[key] = sanitized;
47
+ }
48
+ return result;
49
+ }
50
+ function normalizeDisplayName(value) {
51
+ if (typeof value !== 'string') {
52
+ throw new ModelProviderConnectionError('Display name must be a nonempty string of at most 80 characters.', 400, 'MODEL_CONNECTION_INVALID_DISPLAY_NAME');
53
+ }
54
+ const displayName = value.trim();
55
+ if (!displayName || displayName.length > MAX_DISPLAY_NAME_LENGTH) {
56
+ throw new ModelProviderConnectionError('Display name must be a nonempty string of at most 80 characters.', 400, 'MODEL_CONNECTION_INVALID_DISPLAY_NAME');
57
+ }
58
+ return displayName;
59
+ }
60
+ function parseDisplayMetadata(value) {
61
+ try {
62
+ const parsed = JSON.parse(String(value || '{}'));
63
+ const metadata = sanitizeModelProviderConnectionDisplayMetadata(parsed);
64
+ if (typeof parsed.displayName === 'string') {
65
+ const displayName = parsed.displayName.trim().slice(0, MAX_DISPLAY_NAME_LENGTH);
66
+ if (displayName)
67
+ metadata.displayName = displayName;
68
+ }
69
+ return metadata;
70
+ }
71
+ catch {
72
+ return {};
73
+ }
74
+ }
75
+ function mapRow(row) {
76
+ const status = String(row.lifecycle_status || 'pending');
77
+ return {
78
+ id: String(row.id || ''),
79
+ tenantId: String(row.tenant_id || 'default'),
80
+ ownerUserId: String(row.owner_user_id || ''),
81
+ providerKey: String(row.provider_key || ''),
82
+ authenticationType: String(row.authentication_type || ''),
83
+ lifecycleStatus: status,
84
+ displayMetadata: parseDisplayMetadata(row.display_metadata_json),
85
+ credentialHomeRef: String(row.credential_home_ref || ''),
86
+ lastVerifiedAt: row.last_verified_at ? String(row.last_verified_at) : null,
87
+ lastRefreshedAt: row.last_refreshed_at ? String(row.last_refreshed_at) : null,
88
+ lastFailureAt: row.last_failure_at ? String(row.last_failure_at) : null,
89
+ failureCode: row.failure_code ? String(row.failure_code) : null,
90
+ disconnectedAt: row.disconnected_at ? String(row.disconnected_at) : null,
91
+ revokedAt: row.revoked_at ? String(row.revoked_at) : null,
92
+ createdAt: String(row.created_at || ''),
93
+ updatedAt: String(row.updated_at || ''),
94
+ };
95
+ }
96
+ export class ModelProviderConnectionStore {
97
+ db;
98
+ tenantId;
99
+ now;
100
+ constructor(db, tenantId, now = () => new Date()) {
101
+ this.db = db;
102
+ this.tenantId = tenantId;
103
+ this.now = now;
104
+ }
105
+ leaseNow() {
106
+ if (this.db.provider === 'sqlite')
107
+ return this.now();
108
+ const row = this.db.prepare(`
109
+ SELECT ${POSTGRES_LEASE_CLOCK_SQL} AS current_time
110
+ `).get();
111
+ const currentTime = new Date(String(row?.current_time || ''));
112
+ if (Number.isNaN(currentTime.getTime())) {
113
+ throw new Error('[Taskforce] PostgreSQL did not return a valid lease clock value.');
114
+ }
115
+ return currentTime;
116
+ }
117
+ leaseClockPredicate(nowIso) {
118
+ return this.db.provider === 'postgres'
119
+ ? { sql: POSTGRES_LEASE_CLOCK_SQL, params: [] }
120
+ : { sql: '?', params: [nowIso] };
121
+ }
122
+ create(input) {
123
+ const ownerUserId = String(input.ownerUserId || '').trim();
124
+ if (!ownerUserId) {
125
+ throw new ModelProviderConnectionError('Authentication is required.', 401, 'AUTH_REQUIRED');
126
+ }
127
+ const providerKey = normalizeIdentifier(input.providerKey, 'Provider key');
128
+ const authenticationType = normalizeIdentifier(input.authenticationType, 'Authentication type');
129
+ const id = randomOpaqueId('mpc');
130
+ const credentialHomeRef = randomOpaqueId('home');
131
+ const now = this.now().toISOString();
132
+ const displayMetadata = sanitizeModelProviderConnectionDisplayMetadata(input.displayMetadata);
133
+ this.db.transaction(() => {
134
+ this.db.prepare(`
135
+ INSERT INTO model_provider_connections (
136
+ id, tenant_id, owner_user_id, provider_key, authentication_type,
137
+ lifecycle_status, display_metadata_json, credential_home_ref,
138
+ created_at, updated_at
139
+ ) VALUES (?, ?, ?, ?, ?, 'pending', ?, ?, ?, ?)
140
+ `).run(id, this.tenantId, ownerUserId, providerKey, authenticationType, JSON.stringify(displayMetadata), credentialHomeRef, now, now);
141
+ this.insertEvent({
142
+ connectionId: id,
143
+ ownerUserId,
144
+ actorUserId: ownerUserId,
145
+ eventType: 'created',
146
+ outcome: 'success',
147
+ createdAt: now,
148
+ });
149
+ })();
150
+ return this.requireOwned(ownerUserId, id);
151
+ }
152
+ listOwned(ownerUserIdRaw) {
153
+ const ownerUserId = String(ownerUserIdRaw || '').trim();
154
+ if (!ownerUserId)
155
+ return [];
156
+ const rows = this.db.prepare(`
157
+ SELECT *
158
+ FROM model_provider_connections
159
+ WHERE tenant_id = ? AND owner_user_id = ?
160
+ ORDER BY created_at ASC, id ASC
161
+ `).all(this.tenantId, ownerUserId);
162
+ return rows.map(mapRow);
163
+ }
164
+ getOwned(ownerUserIdRaw, connectionIdRaw) {
165
+ const ownerUserId = String(ownerUserIdRaw || '').trim();
166
+ const connectionId = String(connectionIdRaw || '').trim();
167
+ if (!ownerUserId || !connectionId)
168
+ return null;
169
+ const row = this.db.prepare(`
170
+ SELECT *
171
+ FROM model_provider_connections
172
+ WHERE tenant_id = ? AND owner_user_id = ? AND id = ?
173
+ LIMIT 1
174
+ `).get(this.tenantId, ownerUserId, connectionId);
175
+ return row ? mapRow(row) : null;
176
+ }
177
+ requireOwned(ownerUserId, connectionId) {
178
+ const connection = this.getOwned(ownerUserId, connectionId);
179
+ if (!connection) {
180
+ throw new ModelProviderConnectionError('Model connection was not found.', 404, 'MODEL_CONNECTION_NOT_FOUND');
181
+ }
182
+ return connection;
183
+ }
184
+ renameOwned(ownerUserId, connectionId, displayNameRaw) {
185
+ const displayName = normalizeDisplayName(displayNameRaw);
186
+ return this.db.transaction(() => {
187
+ const current = this.requireOwned(ownerUserId, connectionId);
188
+ const now = this.now().toISOString();
189
+ const result = this.db.prepare(`
190
+ UPDATE model_provider_connections
191
+ SET display_metadata_json = ?, updated_at = ?
192
+ WHERE tenant_id = ? AND owner_user_id = ? AND id = ?
193
+ `).run(JSON.stringify({ ...current.displayMetadata, displayName }), now, this.tenantId, ownerUserId, connectionId);
194
+ if (Number(result?.changes || 0) !== 1) {
195
+ throw new ModelProviderConnectionError('Model connection was not found.', 404, 'MODEL_CONNECTION_NOT_FOUND');
196
+ }
197
+ this.insertEvent({
198
+ connectionId,
199
+ ownerUserId,
200
+ actorUserId: ownerUserId,
201
+ eventType: 'renamed',
202
+ outcome: 'success',
203
+ createdAt: now,
204
+ });
205
+ return this.requireOwned(ownerUserId, connectionId);
206
+ })();
207
+ }
208
+ requireOwnedUnderLease(ownerUserId, connectionId, leaseToken) {
209
+ const now = this.leaseNow().toISOString();
210
+ const clock = this.leaseClockPredicate(now);
211
+ const row = this.db.prepare(`
212
+ SELECT connection.*
213
+ FROM model_provider_connections connection
214
+ WHERE connection.tenant_id = ? AND connection.owner_user_id = ? AND connection.id = ?
215
+ AND EXISTS (
216
+ SELECT 1 FROM model_provider_connection_leases lease
217
+ WHERE lease.tenant_id = connection.tenant_id
218
+ AND lease.connection_id = connection.id
219
+ AND lease.lease_token = ?
220
+ AND lease.expires_at > ${clock.sql}
221
+ )
222
+ LIMIT 1
223
+ `).get(this.tenantId, ownerUserId, connectionId, leaseToken, ...clock.params);
224
+ if (!row) {
225
+ throw new ModelProviderConnectionError('Model connection operation lease is no longer valid.', 409, 'MODEL_CONNECTION_LEASE_LOST');
226
+ }
227
+ return mapRow(row);
228
+ }
229
+ deletePendingOwned(ownerUserId, connectionId) {
230
+ return this.db.transaction(() => {
231
+ const result = this.db.prepare(`
232
+ DELETE FROM model_provider_connections
233
+ WHERE tenant_id = ? AND owner_user_id = ? AND id = ? AND lifecycle_status = 'pending'
234
+ `).run(this.tenantId, ownerUserId, connectionId);
235
+ if (Number(result?.changes || 0) === 1) {
236
+ this.db.prepare(`
237
+ DELETE FROM model_provider_connection_events
238
+ WHERE tenant_id = ? AND connection_id = ?
239
+ `).run(this.tenantId, connectionId);
240
+ return true;
241
+ }
242
+ return false;
243
+ })();
244
+ }
245
+ acquireLease(input) {
246
+ this.requireOwned(input.ownerUserId, input.connectionId);
247
+ const operation = normalizeIdentifier(input.operation, 'Connection operation');
248
+ const durationMs = Math.min(10 * 60_000, Math.max(1_000, input.durationMs ?? 120_000));
249
+ const token = randomOpaqueId('lease');
250
+ if (this.db.provider === 'postgres') {
251
+ const row = this.db.prepare(`
252
+ INSERT INTO model_provider_connection_leases (
253
+ tenant_id, connection_id, lease_token, operation, acquired_at, expires_at, updated_at
254
+ ) VALUES (
255
+ ?, ?, ?, ?, ${POSTGRES_LEASE_CLOCK_SQL}, ${POSTGRES_LEASE_EXPIRY_SQL}, ${POSTGRES_LEASE_CLOCK_SQL}
256
+ )
257
+ ON CONFLICT (tenant_id, connection_id) DO UPDATE SET
258
+ lease_token = excluded.lease_token,
259
+ operation = excluded.operation,
260
+ acquired_at = ${POSTGRES_LEASE_CLOCK_SQL},
261
+ expires_at = ${POSTGRES_LEASE_EXPIRY_SQL},
262
+ updated_at = ${POSTGRES_LEASE_CLOCK_SQL}
263
+ WHERE model_provider_connection_leases.expires_at <= ${POSTGRES_LEASE_CLOCK_SQL}
264
+ RETURNING acquired_at, expires_at
265
+ `).get(this.tenantId, input.connectionId, token, operation, durationMs, durationMs);
266
+ if (!row) {
267
+ throw new ModelProviderConnectionError('Model connection is busy. Try again shortly.', 409, 'MODEL_CONNECTION_BUSY');
268
+ }
269
+ return {
270
+ connectionId: input.connectionId,
271
+ token,
272
+ operation,
273
+ acquiredAt: String(row.acquired_at || ''),
274
+ expiresAt: String(row.expires_at || ''),
275
+ };
276
+ }
277
+ const acquiredAt = this.leaseNow();
278
+ const acquiredAtIso = acquiredAt.toISOString();
279
+ const expiresAt = new Date(acquiredAt.getTime() + durationMs).toISOString();
280
+ const result = this.db.prepare(`
281
+ INSERT INTO model_provider_connection_leases (
282
+ tenant_id, connection_id, lease_token, operation, acquired_at, expires_at, updated_at
283
+ ) VALUES (?, ?, ?, ?, ?, ?, ?)
284
+ ON CONFLICT (tenant_id, connection_id) DO UPDATE SET
285
+ lease_token = excluded.lease_token,
286
+ operation = excluded.operation,
287
+ acquired_at = excluded.acquired_at,
288
+ expires_at = excluded.expires_at,
289
+ updated_at = excluded.updated_at
290
+ WHERE model_provider_connection_leases.expires_at <= excluded.acquired_at
291
+ `).run(this.tenantId, input.connectionId, token, operation, acquiredAtIso, expiresAt, acquiredAtIso);
292
+ if (Number(result?.changes || 0) !== 1) {
293
+ throw new ModelProviderConnectionError('Model connection is busy. Try again shortly.', 409, 'MODEL_CONNECTION_BUSY');
294
+ }
295
+ return { connectionId: input.connectionId, token, operation, acquiredAt: acquiredAtIso, expiresAt };
296
+ }
297
+ renewLease(lease, durationMs = 120_000) {
298
+ const boundedDurationMs = Math.min(10 * 60_000, Math.max(1_000, durationMs));
299
+ if (this.db.provider === 'postgres') {
300
+ const row = this.db.prepare(`
301
+ UPDATE model_provider_connection_leases
302
+ SET expires_at = ${POSTGRES_LEASE_EXPIRY_SQL},
303
+ updated_at = ${POSTGRES_LEASE_CLOCK_SQL}
304
+ WHERE tenant_id = ? AND connection_id = ? AND lease_token = ?
305
+ AND expires_at > ${POSTGRES_LEASE_CLOCK_SQL}
306
+ RETURNING expires_at
307
+ `).get(boundedDurationMs, this.tenantId, lease.connectionId, lease.token);
308
+ return Boolean(row);
309
+ }
310
+ const now = this.leaseNow();
311
+ const nowIso = now.toISOString();
312
+ const expiresAt = new Date(now.getTime() + boundedDurationMs).toISOString();
313
+ const clock = this.leaseClockPredicate(nowIso);
314
+ const result = this.db.prepare(`
315
+ UPDATE model_provider_connection_leases
316
+ SET expires_at = ?, updated_at = ?
317
+ WHERE tenant_id = ? AND connection_id = ? AND lease_token = ? AND expires_at > ${clock.sql}
318
+ `).run(expiresAt, nowIso, this.tenantId, lease.connectionId, lease.token, ...clock.params);
319
+ return Number(result?.changes || 0) === 1;
320
+ }
321
+ releaseLease(lease) {
322
+ const result = this.db.prepare(`
323
+ DELETE FROM model_provider_connection_leases
324
+ WHERE tenant_id = ? AND connection_id = ? AND lease_token = ?
325
+ `).run(this.tenantId, lease.connectionId, lease.token);
326
+ return Number(result?.changes || 0) === 1;
327
+ }
328
+ completeLease(lease) {
329
+ const now = this.leaseNow().toISOString();
330
+ const clock = this.leaseClockPredicate(now);
331
+ const result = this.db.prepare(`
332
+ DELETE FROM model_provider_connection_leases
333
+ WHERE tenant_id = ? AND connection_id = ? AND lease_token = ? AND expires_at > ${clock.sql}
334
+ `).run(this.tenantId, lease.connectionId, lease.token, ...clock.params);
335
+ return Number(result?.changes || 0) === 1;
336
+ }
337
+ deleteCleanableUnderLease(input) {
338
+ return this.db.transaction(() => {
339
+ const now = this.leaseNow().toISOString();
340
+ const clock = this.leaseClockPredicate(now);
341
+ const result = this.db.prepare(`
342
+ DELETE FROM model_provider_connections
343
+ WHERE tenant_id = ? AND owner_user_id = ? AND id = ?
344
+ AND lifecycle_status IN ('pending', 'reconnect_required', 'disconnected', 'revoked')
345
+ AND EXISTS (
346
+ SELECT 1 FROM model_provider_connection_leases lease
347
+ WHERE lease.tenant_id = model_provider_connections.tenant_id
348
+ AND lease.connection_id = model_provider_connections.id
349
+ AND lease.lease_token = ?
350
+ AND lease.expires_at > ${clock.sql}
351
+ )
352
+ `).run(this.tenantId, input.ownerUserId, input.connectionId, input.leaseToken, ...clock.params);
353
+ if (Number(result?.changes || 0) !== 1)
354
+ return false;
355
+ this.insertEvent({
356
+ connectionId: input.connectionId,
357
+ ownerUserId: input.ownerUserId,
358
+ actorUserId: input.ownerUserId,
359
+ eventType: 'cleaned_up',
360
+ outcome: 'success',
361
+ createdAt: now,
362
+ });
363
+ return true;
364
+ })();
365
+ }
366
+ markVerified(input) {
367
+ return this.updateUnderLease(input, 'active', {
368
+ displayMetadata: input.displayMetadata,
369
+ verified: true,
370
+ eventType: 'verified',
371
+ });
372
+ }
373
+ markRefreshed(input) {
374
+ return this.updateUnderLease(input, 'active', {
375
+ displayMetadata: input.displayMetadata,
376
+ refreshed: true,
377
+ eventType: 'refreshed',
378
+ });
379
+ }
380
+ markReconnectRequired(input) {
381
+ return this.updateUnderLease(input, 'reconnect_required', {
382
+ failureCode: normalizeIdentifier(input.failureCode, 'Failure code'),
383
+ eventType: 'reconnect_required',
384
+ });
385
+ }
386
+ markDisconnected(input) {
387
+ return this.updateUnderLease(input, 'disconnected', {
388
+ disconnected: true,
389
+ eventType: 'disconnected',
390
+ });
391
+ }
392
+ updateUnderLease(input, lifecycleStatus, options) {
393
+ return this.db.transaction(() => this.updateUnderLeaseTransaction(input, lifecycleStatus, options))();
394
+ }
395
+ updateUnderLeaseTransaction(input, lifecycleStatus, options) {
396
+ this.requireOwned(input.ownerUserId, input.connectionId);
397
+ const now = this.leaseNow().toISOString();
398
+ const clock = this.leaseClockPredicate(now);
399
+ const current = this.requireOwned(input.ownerUserId, input.connectionId);
400
+ const displayMetadata = options.displayMetadata === undefined
401
+ ? current.displayMetadata
402
+ : {
403
+ ...current.displayMetadata,
404
+ ...sanitizeModelProviderConnectionDisplayMetadata(options.displayMetadata),
405
+ };
406
+ const result = this.db.prepare(`
407
+ UPDATE model_provider_connections
408
+ SET lifecycle_status = ?, display_metadata_json = ?,
409
+ last_verified_at = CASE WHEN ? = 1 THEN ? ELSE last_verified_at END,
410
+ last_refreshed_at = CASE WHEN ? = 1 THEN ? ELSE last_refreshed_at END,
411
+ last_failure_at = CASE WHEN CAST(? AS TEXT) IS NOT NULL THEN ? ELSE NULL END,
412
+ failure_code = ?,
413
+ disconnected_at = CASE WHEN ? = 1 THEN ? ELSE disconnected_at END,
414
+ updated_at = ?
415
+ WHERE tenant_id = ? AND owner_user_id = ? AND id = ?
416
+ AND EXISTS (
417
+ SELECT 1 FROM model_provider_connection_leases lease
418
+ WHERE lease.tenant_id = model_provider_connections.tenant_id
419
+ AND lease.connection_id = model_provider_connections.id
420
+ AND lease.lease_token = ?
421
+ AND lease.expires_at > ${clock.sql}
422
+ )
423
+ `).run(lifecycleStatus, JSON.stringify(displayMetadata), options.verified ? 1 : 0, now, options.refreshed ? 1 : 0, now, options.failureCode || null, now, options.failureCode || null, options.disconnected ? 1 : 0, now, now, this.tenantId, input.ownerUserId, input.connectionId, input.leaseToken, ...clock.params);
424
+ if (Number(result?.changes || 0) !== 1) {
425
+ throw new ModelProviderConnectionError('Model connection operation lease is no longer valid.', 409, 'MODEL_CONNECTION_LEASE_LOST');
426
+ }
427
+ this.insertEvent({
428
+ connectionId: input.connectionId,
429
+ ownerUserId: input.ownerUserId,
430
+ actorUserId: input.ownerUserId,
431
+ eventType: options.eventType,
432
+ outcome: options.failureCode ? 'failure' : 'success',
433
+ reasonCode: options.failureCode,
434
+ createdAt: now,
435
+ });
436
+ return this.requireOwned(input.ownerUserId, input.connectionId);
437
+ }
438
+ insertEvent(input) {
439
+ this.db.prepare(`
440
+ INSERT INTO model_provider_connection_events (
441
+ id, tenant_id, connection_id, owner_user_id, actor_user_id,
442
+ event_type, outcome, reason_code, created_at
443
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
444
+ `).run(randomOpaqueId('mpce'), this.tenantId, input.connectionId, input.ownerUserId, input.actorUserId, input.eventType, input.outcome, input.reasonCode || null, input.createdAt);
445
+ }
446
+ }
@@ -1,4 +1,18 @@
1
1
  import { type DatabaseAdapter, type DatabaseStatement } from './databaseAdapter.js';
2
+ import { type PostgresAdapterDeadlineOptions, type PostgresWorkerOperation } from './postgresWorkerProtocol.js';
3
+ export declare class PostgresWorkerOutcomeUnknownError extends Error {
4
+ readonly code = "POSTGRES_WORKER_OUTCOME_UNKNOWN";
5
+ readonly operation: PostgresWorkerOperation;
6
+ constructor(operation: PostgresWorkerOperation, detail?: string);
7
+ }
8
+ export declare class PostgresWorkerUnavailableError extends Error {
9
+ readonly code = "POSTGRES_WORKER_UNAVAILABLE";
10
+ constructor();
11
+ }
12
+ export declare class PostgresDatabaseError extends Error {
13
+ readonly code: string;
14
+ constructor(message: string, code: string);
15
+ }
2
16
  export declare function replaceQMarkParams(sql: string, params: unknown[]): {
3
17
  text: string;
4
18
  values: unknown[];
@@ -6,13 +20,20 @@ export declare function replaceQMarkParams(sql: string, params: unknown[]): {
6
20
  export declare function translateInsertOrReplace(sql: string): string;
7
21
  export declare class PostgresAdapter implements DatabaseAdapter {
8
22
  readonly provider: "postgres";
9
- readonly open = true;
10
- private readonly worker;
23
+ private worker;
24
+ private readonly connectionString;
25
+ private readonly deadlines;
26
+ private readonly retiringWorkers;
27
+ private consecutiveUnexpectedExits;
28
+ private closed;
11
29
  private readonly encoder;
12
30
  private readonly decoder;
13
31
  private txId;
14
32
  private savepointCounter;
15
- constructor(connectionString?: string);
33
+ constructor(connectionString?: string, deadlineOptions?: PostgresAdapterDeadlineOptions);
34
+ get open(): boolean;
35
+ private createWorker;
36
+ private quarantineWorker;
16
37
  private callWorker;
17
38
  private query;
18
39
  private bindParams;