@taskforcehq/taskforce 0.3.303 → 0.3.305
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -247
- package/dist/Taskforce.module.css +102 -5
- package/dist/TaskforceCore.js +635 -238
- package/dist/TaskforceCore.test.js +2243 -495
- package/dist/annotatedAttachments/service.d.ts +1 -1
- package/dist/annotatedAttachments/types.d.ts +1 -1
- package/dist/compat/workspaceSyncCompat.js +6 -0
- package/dist/components/features/AgentsModule.js +1 -1
- package/dist/components/features/AgentsModule.test.js +1 -1
- package/dist/components/features/DocumentIndex.d.ts +1 -1
- package/dist/components/features/DocumentIndex.js +1 -1
- package/dist/components/features/DocumentViewer.d.ts +1 -1
- package/dist/components/features/DocumentViewer.js +32 -9
- package/dist/components/features/DocumentWorkspace.d.ts +5 -22
- package/dist/components/features/DocumentWorkspace.js +12 -155
- package/dist/components/features/DocumentWorkspace.test.js +193 -6
- package/dist/components/features/TaskSettings.js +87 -41
- package/dist/components/features/TaskSettings.test.js +180 -40
- package/dist/components/features/documentWorkspaceModel.d.ts +24 -0
- package/dist/components/features/documentWorkspaceModel.js +57 -0
- package/dist/components/features/useDocumentWorkspaceController.d.ts +34 -0
- package/dist/components/features/useDocumentWorkspaceController.js +113 -0
- package/dist/components/task/TaskActionHeader.d.ts +2 -1
- package/dist/components/task/TaskActionHeader.js +3 -3
- package/dist/components/task/TaskActionHeader.test.js +8 -0
- package/dist/components/task/TaskCard.js +16 -1
- package/dist/components/task/TaskCard.test.js +31 -0
- package/dist/components/task/TaskForm.d.ts +9 -8
- package/dist/components/task/TaskForm.js +374 -219
- package/dist/components/task/TaskForm.test.js +482 -361
- package/dist/components/task/TaskKanban.d.ts +1 -1
- package/dist/components/task/TaskKanban.js +33 -161
- package/dist/components/task/TaskStatusActions.d.ts +6 -1
- package/dist/components/task/TaskStatusActions.js +8 -3
- package/dist/components/task/TaskStatusActions.test.js +9 -0
- package/dist/components/task/taskKanbanDropRules.d.ts +58 -0
- package/dist/components/task/taskKanbanDropRules.js +187 -0
- package/dist/components/task/taskKanbanDropRules.test.d.ts +1 -0
- package/dist/components/task/taskKanbanDropRules.test.js +114 -0
- package/dist/components/ui/Modal.d.ts +1 -1
- package/dist/components/ui/Modal.js +1 -0
- package/dist/components/views/AppShellHeader.js +5 -1
- package/dist/components/views/AppShellHeader.test.js +4 -0
- package/dist/components/views/PlanComparisonPage.d.ts +3 -2
- package/dist/components/views/PlanComparisonPage.js +9 -10
- package/dist/components/views/PlanComparisonPage.test.js +55 -41
- package/dist/components/views/PlansPage.d.ts +5 -1
- package/dist/components/views/PlansPage.js +150 -81
- package/dist/components/views/PlansPage.test.js +367 -41
- package/dist/components/views/StandaloneLayout.js +135 -54
- package/dist/components/views/WidgetView.js +11 -2
- package/dist/components/views/panels/FilterToolbar.test.js +6 -4
- package/dist/components/views/standalone/modals/AccountHubModal.d.ts +2 -14
- package/dist/components/views/standalone/modals/AccountHubModal.js +12 -14
- package/dist/components/views/standalone/modals/AccountHubModal.test.js +24 -1
- package/dist/components/views/standalone/modals/SyncStatusModal.js +1 -1
- package/dist/config/envSchema.js +1 -1
- package/dist/core/AiProfileService.d.ts +6 -1
- package/dist/core/AiProfileService.js +161 -16
- package/dist/core/AiProfileService.test.js +3 -1
- package/dist/core/AiProfiles.test.js +200 -0
- package/dist/core/AuthTokenService.test.d.ts +1 -0
- package/dist/core/AuthTokenService.test.js +78 -0
- package/dist/core/DeletedTaskLifecycleService.d.ts +2 -1
- package/dist/core/EntitlementsPolicy.test.js +75 -13
- package/dist/core/PlanEntitlementService.d.ts +9 -1
- package/dist/core/PlanEntitlementService.js +144 -19
- package/dist/core/PlanVersionPolicy.test.js +19 -26
- package/dist/core/SignupMonetizationSettings.test.js +75 -15
- package/dist/core/SystemAdmin.test.js +212 -56
- package/dist/core/TaskActivityService.d.ts +4 -1
- package/dist/core/TaskActivityService.js +45 -0
- package/dist/core/TaskAuditTimeline.test.js +52 -1
- package/dist/core/TaskTaxonomyValidation.test.js +53 -0
- package/dist/core/Taskforce.d.ts +18 -11
- package/dist/core/Taskforce.js +93 -12
- package/dist/core/WorkspacePlanMode.test.js +73 -8
- package/dist/core/shared.d.ts +2 -0
- package/dist/core/shared.js +11 -0
- package/dist/documentReviews/service.d.ts +1 -1
- package/dist/documentReviews/types.d.ts +1 -1
- package/dist/hooks/auth/useTaskforceAuthBootstrap.d.ts +48 -0
- package/dist/hooks/auth/useTaskforceAuthBootstrap.js +219 -0
- package/dist/hooks/sync/auth.d.ts +37 -0
- package/dist/hooks/sync/auth.js +63 -0
- package/dist/hooks/sync/bootstrap.d.ts +34 -0
- package/dist/hooks/sync/bootstrap.js +52 -0
- package/dist/hooks/sync/orchestratorShared.d.ts +36 -0
- package/dist/hooks/sync/orchestratorShared.js +209 -0
- package/dist/hooks/sync/orchestratorShared.test.d.ts +1 -0
- package/dist/hooks/sync/orchestratorShared.test.js +49 -0
- package/dist/hooks/sync/realtime.d.ts +25 -0
- package/dist/hooks/sync/realtime.js +60 -0
- package/dist/hooks/sync/recovery.d.ts +69 -0
- package/dist/hooks/sync/recovery.js +118 -0
- package/dist/hooks/sync/transfers.d.ts +123 -0
- package/dist/hooks/sync/transfers.js +435 -0
- package/dist/hooks/sync/useDataVersionRefresh.d.ts +16 -0
- package/dist/hooks/sync/useDataVersionRefresh.js +73 -0
- package/dist/hooks/ui/useResourceExport.d.ts +3 -1
- package/dist/hooks/ui/useResourceExport.js +5 -2
- package/dist/hooks/ui/useWorkflowTemplates.js +11 -6
- package/dist/hooks/useRealtimeSync.js +2 -1
- package/dist/hooks/useSyncOrchestrator.aiProfiles.test.js +8 -0
- package/dist/hooks/useSyncOrchestrator.context-assets.test.d.ts +1 -0
- package/dist/hooks/useSyncOrchestrator.context-assets.test.js +228 -0
- package/dist/hooks/useSyncOrchestrator.d.ts +12 -8
- package/dist/hooks/useSyncOrchestrator.js +388 -879
- package/dist/hooks/useSyncOrchestrator.retry-closure.test.js +641 -6
- package/dist/hooks/useTaskMutations.d.ts +2 -1
- package/dist/hooks/useTaskMutations.js +57 -7
- package/dist/hooks/useTaskMutations.test.js +176 -0
- package/dist/hooks/useTaskforce.d.ts +13 -4
- package/dist/hooks/useTaskforce.js +302 -817
- package/dist/hooks/useTaskforce.sync-behavior.test.js +78 -0
- package/dist/hooks/useWorkspaceSyncController.d.ts +4 -1
- package/dist/hooks/useWorkspaceSyncController.js +33 -11
- package/dist/hooks/useWorkspaceSyncController.test.js +1 -0
- package/dist/hooks/workspace/useTaskforceApiRouting.test.js +17 -0
- package/dist/hooks/workspace/useTaskforceWorkspaceBootstrap.d.ts +166 -0
- package/dist/hooks/workspace/useTaskforceWorkspaceBootstrap.js +434 -0
- package/dist/hooks/workspace/workspaceLocalState.d.ts +19 -0
- package/dist/hooks/workspace/workspaceLocalState.js +100 -0
- package/dist/hooks/workspace/workspaceLocalState.test.d.ts +1 -0
- package/dist/hooks/workspace/workspaceLocalState.test.js +59 -0
- package/dist/localization/locales/en-US.js +2 -2
- package/dist/mcp/adminWorkspaceRegistrar.d.ts +2 -0
- package/dist/mcp/adminWorkspaceRegistrar.js +154 -0
- package/dist/mcp/canonicalAssetHelpers.d.ts +70 -0
- package/dist/mcp/canonicalAssetHelpers.js +259 -0
- package/dist/mcp/clientIntegrations.d.ts +12 -1
- package/dist/mcp/clientIntegrations.js +161 -6
- package/dist/mcp/clientIntegrations.test.js +76 -4
- package/dist/mcp/collaborationRegistrar.d.ts +2 -0
- package/dist/mcp/collaborationRegistrar.js +71 -0
- package/dist/mcp/documentAssetRegistrar.d.ts +2 -0
- package/dist/mcp/documentAssetRegistrar.js +346 -0
- package/dist/mcp/documentHelpers.d.ts +100 -0
- package/dist/mcp/documentHelpers.js +161 -0
- package/dist/mcp/runtime.js +2455 -3925
- package/dist/mcp/runtime.test.js +240 -8
- package/dist/mcp/taskAttachmentHelpers.d.ts +41 -0
- package/dist/mcp/taskAttachmentHelpers.js +60 -0
- package/dist/mcp/taskAttachmentTypes.d.ts +37 -0
- package/dist/mcp/taskAttachmentTypes.js +1 -0
- package/dist/mcp/taskPlanningRegistrar.d.ts +2 -0
- package/dist/mcp/taskPlanningRegistrar.js +418 -0
- package/dist/mcp/toolCatalog.d.ts +35 -0
- package/dist/mcp/toolCatalog.js +3 -0
- package/dist/plugins/vite.js +1 -1
- package/dist/runtime/appGateDefinitions.d.ts +1 -1
- package/dist/runtime/appGateDefinitions.js +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +46 -3
- package/dist/server/index.test.js +12 -1
- package/dist/server/routes/admin.d.ts +1 -5
- package/dist/server/routes/admin.js +151 -80
- package/dist/server/routes/annotatedAttachments.d.ts +1 -1
- package/dist/server/routes/annotatedAttachments.js +1 -1
- package/dist/server/routes/auth.d.ts +1 -4
- package/dist/server/routes/auth.js +59 -64
- package/dist/server/routes/authSupport.d.ts +30 -0
- package/dist/server/routes/authSupport.js +81 -0
- package/dist/server/routes/billing.d.ts +1 -1
- package/dist/server/routes/billing.js +122 -255
- package/dist/server/routes/billing.test.js +257 -86
- package/dist/server/routes/documentReviews.d.ts +1 -1
- package/dist/server/routes/documentReviews.js +1 -1
- package/dist/server/routes/documents.d.ts +4 -2
- package/dist/server/routes/documents.js +73 -7
- package/dist/server/routes/primitives.d.ts +11 -0
- package/dist/server/routes/primitives.js +73 -0
- package/dist/server/routes/resources.d.ts +1 -1
- package/dist/server/routes/resources.js +1 -1
- package/dist/server/routes/shared.d.ts +31 -1
- package/dist/server/routes/shared.js +26 -0
- package/dist/server/routes/sync.d.ts +1 -1
- package/dist/server/routes/sync.integration.test.js +20 -0
- package/dist/server/routes/sync.js +111 -238
- package/dist/server/routes/tasks.d.ts +1 -1
- package/dist/server/routes/tasks.js +50 -8
- package/dist/server/routes/workspaces.d.ts +1 -1
- package/dist/server/routes/workspaces.js +1 -1
- package/dist/server/routes.d.ts +2 -9
- package/dist/server/routes.js +84 -181
- package/dist/server/routes.test.js +912 -32
- package/dist/shared/taskActor.d.ts +10 -0
- package/dist/shared/taskActor.js +1 -0
- package/dist/sync/collaborationSyncPayload.js +4 -0
- package/dist/sync/collaborationSyncPayload.test.js +8 -0
- package/dist/sync/collaborationSyncState.d.ts +3 -1
- package/dist/sync/collaborationSyncState.js +19 -0
- package/dist/sync/contentSyncState.js +28 -17
- package/dist/sync/syncApplyHandlers.d.ts +87 -1
- package/dist/sync/syncApplyHandlers.js +370 -8
- package/dist/sync/syncApplyHandlers.test.d.ts +1 -0
- package/dist/sync/syncApplyHandlers.test.js +379 -0
- package/dist/sync/syncService.d.ts +9 -1
- package/dist/sync/syncService.js +44 -2
- package/dist/sync/syncService.test.js +62 -0
- package/dist/sync/workspacePullFeed.d.ts +1 -0
- package/dist/sync/workspacePullFeed.js +66 -59
- package/dist/sync/workspacePullFeed.test.js +72 -4
- package/dist/sync/workspaceSyncModel.d.ts +25 -1
- package/dist/sync/workspaceSyncModel.js +77 -3
- package/dist/sync/workspaceSyncModel.test.js +153 -0
- package/dist/sync/workspaceSyncState.d.ts +2 -0
- package/dist/sync/workspaceSyncState.js +1 -0
- package/dist/types.d.ts +2 -10
- package/dist/ui/assets/AgentsModule-N2MnQBZk.js +1 -0
- package/dist/ui/assets/{AnnotatedAttachmentWorkspace-C_TmXZwA.js → AnnotatedAttachmentWorkspace-BG6P_GVW.js} +1 -1
- package/dist/ui/assets/DocumentWorkspace-B3nV_Gc5.css +1 -0
- package/dist/ui/assets/DocumentWorkspace-DRbDMwh8.js +252 -0
- package/dist/ui/assets/{InitiativesModule-4-Rh2K2n.js → InitiativesModule-Dhm7M8e7.js} +1 -1
- package/dist/ui/assets/{PlansPage-BlVC_lRq.css → PlansPage-C2dd2n1X.css} +1 -1
- package/dist/ui/assets/PlansPage-Cq0zXj3I.js +1 -0
- package/dist/ui/assets/TaskSettings-ln0aF7xc.js +9 -0
- package/dist/ui/assets/{WorkflowsModule-CGk9s3NJ.js → WorkflowsModule-BcS4afRn.js} +1 -1
- package/dist/ui/assets/index-C2-OXZV7.css +1 -0
- package/dist/ui/assets/index-DcSI5F86.js +6 -0
- package/dist/ui/assets/{vendor-icons-pWocEipT.js → vendor-icons-BSUaRwF8.js} +1 -1
- package/dist/ui/index.html +4 -4
- package/dist/utils/commercialLifecyclePresentation.d.ts +19 -0
- package/dist/utils/commercialLifecyclePresentation.js +196 -0
- package/dist/utils/taskActivity.js +4 -0
- package/dist/utils/taskActivity.test.js +25 -1
- package/package.json +10 -1
- package/scripts/check-cloud-mcp.mjs +83 -0
- package/scripts/playwright-auth.sh +9 -1
- package/scripts/run-billing-performance-smoke.sh +24 -0
- package/dist/ui/assets/AgentsModule-CpsTmrIW.js +0 -1
- package/dist/ui/assets/DocumentWorkspace-C3GyzrWm.js +0 -250
- package/dist/ui/assets/DocumentWorkspace-C_8T8oz-.css +0 -1
- package/dist/ui/assets/PlansPage-BP7AYOqr.js +0 -1
- package/dist/ui/assets/TaskSettings-BOC5F6Ag.js +0 -8
- package/dist/ui/assets/index-CLIMgR6g.js +0 -6
- package/dist/ui/assets/index-DneETxcu.css +0 -1
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
|
-
import { parseJsonBody } from '
|
|
2
|
+
import { parseJsonBody } from './primitives.js';
|
|
3
3
|
import { normalizeTaskDataRelativePath, ObjectStorageClient } from '../../storage/objectStorageClient.js';
|
|
4
4
|
import { WorkspaceAssetStore, } from '../../storage/workspaceAssetStore.js';
|
|
5
5
|
import { resolveSessionCookieAttributesForRequest } from '../auth.js';
|
|
6
6
|
import { decryptDocument, ENCRYPTION_PREFIX } from '../../sync/encryptionService.js';
|
|
7
7
|
import { isAiProfileSurfaceType } from '../../shared/aiProfileSurfaceType.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { normalizeBinaryAssetDeleteSyncPayload, normalizeBinaryAssetSyncPayload, normalizeDocumentDeleteSyncPayload, normalizeDocumentSyncPayload, serializeBinaryAssetSyncPayload, serializeDocumentSyncPayload } from '../../sync/contentSyncPayload.js';
|
|
8
|
+
import { serializeTaskForSync, } from '../../sync/taskSyncPayload.js';
|
|
9
|
+
import { serializeBinaryAssetSyncPayload, serializeDocumentSyncPayload, } from '../../sync/contentSyncPayload.js';
|
|
11
10
|
import { createContentSyncState } from '../../sync/contentSyncState.js';
|
|
12
|
-
import { normalizeAiProfileSyncPayload, normalizeAnnotatedAttachmentSessionSyncPayload,
|
|
11
|
+
import { normalizeAiProfileSyncPayload, normalizeAnnotatedAttachmentSessionSyncPayload, normalizeDocumentReviewCommentSyncPayload, normalizeDocumentReviewSessionSyncPayload, } from '../../sync/collaborationSyncPayload.js';
|
|
13
12
|
import { createCollaborationSyncState } from '../../sync/collaborationSyncState.js';
|
|
14
13
|
import { buildWorkspacePullFeed } from '../../sync/workspacePullFeed.js';
|
|
15
14
|
import { normalizeInitiativeSyncPayload, normalizeTaxonomySyncPayload, normalizeWorkstreamSyncPayload, } from '../../sync/planningSyncPayload.js';
|
|
16
|
-
import { applyAiProfileAndMemberSyncChanges, applyCollaborationSyncChanges, applyContentSyncChanges, applyPlanningSyncChanges,
|
|
15
|
+
import { applyAiProfileAndMemberSyncChanges, applyCollaborationSyncChanges, applyContentSyncChanges, applyPlanningSyncChanges, applyPreparedTaskSyncSnapshot, applyTaskActivitySyncChanges, applyTaskSyncDeletes, classifyWorkspaceSyncChanges, prepareTaskSyncSnapshotApply, } from '../../sync/syncApplyHandlers.js';
|
|
17
16
|
import { applyWorkspaceRepair } from '../../sync/workspaceRepair.js';
|
|
18
17
|
function decodeWorkspaceSyncCursor(raw) {
|
|
19
18
|
const value = String(raw || '').trim();
|
|
@@ -60,6 +59,40 @@ function normalizeIncomingAiProfileSurfaceType(value, context) {
|
|
|
60
59
|
}
|
|
61
60
|
return normalized;
|
|
62
61
|
}
|
|
62
|
+
function normalizeTaskEventSyncPayload(raw, workspaceId, sourceWatermark) {
|
|
63
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
64
|
+
return null;
|
|
65
|
+
const source = raw;
|
|
66
|
+
const id = String(source.id || '').trim();
|
|
67
|
+
const taskId = String(source.taskId || source.task_id || '').trim();
|
|
68
|
+
const action = String(source.action || '').trim();
|
|
69
|
+
const actor = String(source.actor || 'system').trim() || 'system';
|
|
70
|
+
const createdAt = String(source.createdAt || source.created_at || sourceWatermark || '').trim();
|
|
71
|
+
if (!id || !taskId || !action || !Number.isFinite(Date.parse(createdAt)))
|
|
72
|
+
return null;
|
|
73
|
+
const actorType = source.actorType === 'ai' || source.actorType === 'human' || source.actorType === 'system'
|
|
74
|
+
? source.actorType
|
|
75
|
+
: source.actor_type === 'ai' || source.actor_type === 'human' || source.actor_type === 'system'
|
|
76
|
+
? source.actor_type
|
|
77
|
+
: actor.startsWith('ai-profile-')
|
|
78
|
+
? 'ai'
|
|
79
|
+
: actor === 'system'
|
|
80
|
+
? 'system'
|
|
81
|
+
: 'human';
|
|
82
|
+
const details = source.details && typeof source.details === 'object' && !Array.isArray(source.details)
|
|
83
|
+
? source.details
|
|
84
|
+
: {};
|
|
85
|
+
return {
|
|
86
|
+
id,
|
|
87
|
+
taskId,
|
|
88
|
+
workspaceId,
|
|
89
|
+
action,
|
|
90
|
+
actor,
|
|
91
|
+
actorType,
|
|
92
|
+
details,
|
|
93
|
+
createdAt
|
|
94
|
+
};
|
|
95
|
+
}
|
|
63
96
|
export function registerSyncRoutes(deps) {
|
|
64
97
|
const { addRoute, core, context, auditAuthAction, resolveErrorStatusCode, requestWorkspaceId, resolveRequestAccess, isReservedWorkspaceId, createSessionTokenCookie } = deps;
|
|
65
98
|
const readPushIdempotency = (workspaceId, key) => {
|
|
@@ -190,32 +223,7 @@ export function registerSyncRoutes(deps) {
|
|
|
190
223
|
workspaceDocumentSnapshotCache,
|
|
191
224
|
});
|
|
192
225
|
const collaborationSyncState = createCollaborationSyncState({ core });
|
|
193
|
-
const hasTaskReferenceNumberDrift = (workspaceId, task) => {
|
|
194
|
-
const taskId = String(task?.id || '').trim();
|
|
195
|
-
const incomingReferenceNumber = Number.isFinite(Number(task?.referenceNumber))
|
|
196
|
-
? Math.max(1, Math.floor(Number(task?.referenceNumber)))
|
|
197
|
-
: null;
|
|
198
|
-
if (!incomingReferenceNumber)
|
|
199
|
-
return false;
|
|
200
|
-
const existingTask = core.resolveTaskIdentifier(`T-${incomingReferenceNumber}`, workspaceId);
|
|
201
|
-
if (!existingTask || existingTask.id === taskId)
|
|
202
|
-
return false;
|
|
203
|
-
recordSyncDiagnostic(workspaceId, 'apply', 'Detected task reference number mismatch during normal sync.', {
|
|
204
|
-
source: 'tasks.referenceNumber.mismatch',
|
|
205
|
-
taskId: taskId || null,
|
|
206
|
-
taskTitle: typeof task?.title === 'string' ? task.title.trim() || null : null,
|
|
207
|
-
existingTaskId: existingTask.id,
|
|
208
|
-
existingTaskTitle: existingTask.title || null,
|
|
209
|
-
referenceLabel: `T-${incomingReferenceNumber}`,
|
|
210
|
-
existingReferenceNumber: existingTask.referenceNumber ?? incomingReferenceNumber,
|
|
211
|
-
incomingReferenceNumber
|
|
212
|
-
});
|
|
213
|
-
return true;
|
|
214
|
-
};
|
|
215
226
|
const dispatchWorkspaceSyncChanges = async (workspaceId, incomingChanges, options) => {
|
|
216
|
-
const tasks = [];
|
|
217
|
-
const archived = [];
|
|
218
|
-
const incomingTaskDeletes = new Map();
|
|
219
227
|
const emittedEventIds = new Set();
|
|
220
228
|
const unsubscribeRealtime = core.onRealtimeMutation((event) => {
|
|
221
229
|
const eventWorkspaceId = String(event?.workspaceId || '').trim();
|
|
@@ -225,224 +233,63 @@ export function registerSyncRoutes(deps) {
|
|
|
225
233
|
if (eventId)
|
|
226
234
|
emittedEventIds.add(eventId);
|
|
227
235
|
});
|
|
228
|
-
let incomingTaxonomies = null;
|
|
229
|
-
let incomingTaxonomyState = null;
|
|
230
|
-
let incomingTaxonomiesUpdatedAt = '';
|
|
231
|
-
const incomingInitiatives = new Map();
|
|
232
|
-
const incomingWorkstreams = new Map();
|
|
233
|
-
const incomingAiProfiles = new Map();
|
|
234
|
-
const incomingDocuments = [];
|
|
235
|
-
const incomingDocumentDeletes = new Map();
|
|
236
|
-
const incomingDocumentReviewSessions = new Map();
|
|
237
|
-
const incomingDocumentReviewSessionDeletes = new Map();
|
|
238
|
-
const incomingDocumentReviewComments = new Map();
|
|
239
|
-
const incomingDocumentReviewCommentDeletes = new Map();
|
|
240
|
-
const incomingAnnotatedAttachmentSessions = new Map();
|
|
241
|
-
const incomingAnnotatedAttachmentSessionDeletes = new Map();
|
|
242
|
-
const incomingAssets = [];
|
|
243
|
-
const incomingAssetDeletes = new Map();
|
|
244
236
|
try {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (taxonomy?.updatedAt)
|
|
255
|
-
incomingTaxonomiesUpdatedAt = taxonomy.updatedAt;
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
if (op === 'initiative-upsert') {
|
|
259
|
-
const initiative = normalizeInitiativeSyncPayload(raw.initiative, String(raw.updatedAt || raw.watermark || '').trim());
|
|
260
|
-
if (initiative)
|
|
261
|
-
incomingInitiatives.set(initiative.id, initiative);
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
if (op === 'workstream-upsert') {
|
|
265
|
-
const workstream = normalizeWorkstreamSyncPayload(raw.workstream, String(raw.updatedAt || raw.watermark || '').trim());
|
|
266
|
-
if (workstream)
|
|
267
|
-
incomingWorkstreams.set(workstream.id, workstream);
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
if (op === 'ai-profile-upsert') {
|
|
271
|
-
const profile = normalizeAiProfileSyncPayload(raw.profile, workspaceId, normalizeIncomingAiProfileSurfaceType, 'apply.aiProfileUpsert');
|
|
272
|
-
const profileId = String(profile?.id || '').trim();
|
|
273
|
-
if (profileId && profile) {
|
|
274
|
-
const profileWorkspaceId = String(profile.workspaceId || '').trim();
|
|
275
|
-
if (profileWorkspaceId && profileWorkspaceId !== workspaceId) {
|
|
276
|
-
recordSyncDiagnostic(workspaceId, 'apply', `Rejected ai-profile-upsert for profile ${profileId}: workspace mismatch (expected ${workspaceId}, got ${profileWorkspaceId}).`, {
|
|
277
|
-
source: 'apply.aiProfileWorkspaceMismatch',
|
|
278
|
-
workspaceId,
|
|
279
|
-
profileId,
|
|
280
|
-
expectedWorkspaceId: workspaceId,
|
|
281
|
-
receivedWorkspaceId: profileWorkspaceId
|
|
282
|
-
});
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
incomingAiProfiles.set(profileId, {
|
|
286
|
-
...profile,
|
|
287
|
-
workspaceId,
|
|
288
|
-
createdAt: profile.createdAt || String(raw.updatedAt || raw.watermark || '').trim(),
|
|
289
|
-
updatedAt: profile.updatedAt || String(raw.updatedAt || raw.watermark || '').trim(),
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
if (op === 'document-upsert') {
|
|
295
|
-
const document = normalizeDocumentSyncPayload(raw, normalizeWorkspaceSyncDocumentPath);
|
|
296
|
-
if (document)
|
|
297
|
-
incomingDocuments.push(document);
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
if (op === 'document-delete') {
|
|
301
|
-
const deletedDocument = normalizeDocumentDeleteSyncPayload(raw, normalizeWorkspaceSyncDocumentPath);
|
|
302
|
-
if (deletedDocument)
|
|
303
|
-
incomingDocumentDeletes.set(deletedDocument.path, deletedDocument.deletedAt);
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
if (op === 'asset-upsert') {
|
|
307
|
-
const asset = normalizeBinaryAssetSyncPayload(raw, (rawPath) => normalizeTaskDataRelativePath(String(rawPath || '').trim()));
|
|
308
|
-
if (asset)
|
|
309
|
-
incomingAssets.push(asset);
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
if (op === 'asset-delete') {
|
|
313
|
-
const deletedAsset = normalizeBinaryAssetDeleteSyncPayload(raw, (rawPath) => normalizeTaskDataRelativePath(String(rawPath || '').trim()));
|
|
314
|
-
if (deletedAsset)
|
|
315
|
-
incomingAssetDeletes.set(deletedAsset.path, deletedAsset.deletedAt);
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
if (op === 'document-review-session-upsert') {
|
|
319
|
-
const session = normalizeDocumentReviewSessionSyncPayload(raw.session, String(raw.updatedAt || raw.watermark || '').trim());
|
|
320
|
-
if (session)
|
|
321
|
-
incomingDocumentReviewSessions.set(session.id, session);
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
if (op === 'document-review-session-delete') {
|
|
325
|
-
const deletedSession = normalizeDeleteSyncPayload(raw, 'sessionId');
|
|
326
|
-
if (deletedSession)
|
|
327
|
-
incomingDocumentReviewSessionDeletes.set(deletedSession.id, deletedSession.deletedAt);
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
if (op === 'document-review-comment-upsert') {
|
|
331
|
-
const comment = normalizeDocumentReviewCommentSyncPayload(raw.comment, { sourceWatermark: String(raw.updatedAt || raw.watermark || '').trim() });
|
|
332
|
-
if (comment)
|
|
333
|
-
incomingDocumentReviewComments.set(comment.id, comment);
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
if (op === 'document-review-comment-delete') {
|
|
337
|
-
const deletedComment = normalizeDeleteSyncPayload(raw, 'commentId');
|
|
338
|
-
if (deletedComment)
|
|
339
|
-
incomingDocumentReviewCommentDeletes.set(deletedComment.id, deletedComment.deletedAt);
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
if (op === 'annotated-attachment-session-upsert') {
|
|
343
|
-
const session = normalizeAnnotatedAttachmentSessionSyncPayload(raw.session, workspaceId, String(raw.updatedAt || raw.watermark || '').trim());
|
|
344
|
-
if (session)
|
|
345
|
-
incomingAnnotatedAttachmentSessions.set(session.id, session);
|
|
346
|
-
continue;
|
|
347
|
-
}
|
|
348
|
-
if (op === 'annotated-attachment-session-delete') {
|
|
349
|
-
const deletedSession = normalizeDeleteSyncPayload(raw, 'sessionId');
|
|
350
|
-
if (deletedSession)
|
|
351
|
-
incomingAnnotatedAttachmentSessionDeletes.set(deletedSession.id, deletedSession.deletedAt);
|
|
352
|
-
continue;
|
|
353
|
-
}
|
|
354
|
-
if (op !== 'delete')
|
|
355
|
-
continue;
|
|
356
|
-
const task = normalizeTaskSyncPayload(raw.task);
|
|
357
|
-
const deleteTaskId = String(raw.taskId || raw.id || task?.id || '').trim();
|
|
358
|
-
if (deleteTaskId) {
|
|
359
|
-
incomingTaskDeletes.set(deleteTaskId, String(raw.deletedAt || raw.watermark || new Date().toISOString()).trim());
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
for (const change of incomingChanges) {
|
|
363
|
-
const raw = change;
|
|
364
|
-
const op = String(raw.op || '').trim().toLowerCase();
|
|
365
|
-
if (op === 'delete'
|
|
366
|
-
|| op === 'initiative-upsert'
|
|
367
|
-
|| op === 'workstream-upsert'
|
|
368
|
-
|| op === 'document-upsert'
|
|
369
|
-
|| op === 'document-delete'
|
|
370
|
-
|| op === 'asset-upsert'
|
|
371
|
-
|| op === 'asset-delete'
|
|
372
|
-
|| op === 'document-review-session-upsert'
|
|
373
|
-
|| op === 'document-review-session-delete'
|
|
374
|
-
|| op === 'document-review-comment-upsert'
|
|
375
|
-
|| op === 'document-review-comment-delete'
|
|
376
|
-
|| op === 'annotated-attachment-session-upsert'
|
|
377
|
-
|| op === 'annotated-attachment-session-delete')
|
|
378
|
-
continue;
|
|
379
|
-
const task = normalizeTaskSyncPayload(raw.task);
|
|
380
|
-
if (!task)
|
|
381
|
-
continue;
|
|
382
|
-
const taskId = String(task.id || '').trim();
|
|
383
|
-
hasTaskReferenceNumberDrift(workspaceId, task);
|
|
384
|
-
const deleteWatermark = taskId ? String(incomingTaskDeletes.get(taskId) || '').trim() : '';
|
|
385
|
-
if (taskId && deleteWatermark) {
|
|
386
|
-
const compareAgainstDelete = resolveSyncConflictOrdering(deleteWatermark, String(task.updatedAt || task.createdAt || '').trim(), `delete:${taskId}`, getTaskMutationTieBreak(task, raw.archived === true || task?.isArchived === true));
|
|
387
|
-
if (compareAgainstDelete >= 0)
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
390
|
-
const markedArchived = raw.archived === true || task?.isArchived === true;
|
|
391
|
-
if (markedArchived)
|
|
392
|
-
archived.push(task);
|
|
393
|
-
else
|
|
394
|
-
tasks.push(task);
|
|
395
|
-
}
|
|
396
|
-
for (const [taskId, deleteWatermark] of incomingTaskDeletes.entries()) {
|
|
397
|
-
try {
|
|
398
|
-
const existingTask = core.getTask(taskId, workspaceId);
|
|
399
|
-
if (existingTask) {
|
|
400
|
-
const compareAgainstExisting = resolveSyncConflictOrdering(deleteWatermark, getTaskMutationWatermark(existingTask), `delete:${taskId}`, getTaskMutationTieBreak(existingTask, Boolean(existingTask.isArchived)));
|
|
401
|
-
if (compareAgainstExisting < 0)
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
core.deleteTaskForSync(taskId, workspaceId, { persistBackup: false });
|
|
405
|
-
}
|
|
406
|
-
catch (error) {
|
|
407
|
-
recordSyncDiagnostic(workspaceId, 'apply', 'Failed to delete task during sync apply.', {
|
|
408
|
-
source: 'apply.deleteTask',
|
|
409
|
-
taskId,
|
|
410
|
-
error: String(error?.message || error || '')
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
}
|
|
237
|
+
const applyModel = classifyWorkspaceSyncChanges({
|
|
238
|
+
workspaceId,
|
|
239
|
+
incomingChanges,
|
|
240
|
+
normalizeWorkspaceSyncDocumentPath,
|
|
241
|
+
normalizeTaskAssetPath: (rawPath) => normalizeTaskDataRelativePath(String(rawPath || '').trim()),
|
|
242
|
+
normalizeIncomingAiProfileSurfaceType,
|
|
243
|
+
normalizeTaskEventSyncPayload,
|
|
244
|
+
recordSyncDiagnostic,
|
|
245
|
+
});
|
|
414
246
|
applyPlanningSyncChanges({
|
|
415
247
|
core,
|
|
416
248
|
workspaceId,
|
|
417
|
-
incomingInitiatives,
|
|
418
|
-
incomingWorkstreams,
|
|
419
|
-
incomingTaxonomies,
|
|
420
|
-
incomingTaxonomyState,
|
|
421
|
-
incomingTaxonomiesUpdatedAt,
|
|
249
|
+
incomingInitiatives: applyModel.planning.incomingInitiatives,
|
|
250
|
+
incomingWorkstreams: applyModel.planning.incomingWorkstreams,
|
|
251
|
+
incomingTaxonomies: applyModel.planning.incomingTaxonomies,
|
|
252
|
+
incomingTaxonomyState: applyModel.planning.incomingTaxonomyState,
|
|
253
|
+
incomingTaxonomiesUpdatedAt: applyModel.planning.incomingTaxonomiesUpdatedAt,
|
|
422
254
|
workspaceTaxonomySyncMeta,
|
|
423
255
|
recordSyncDiagnostic,
|
|
424
256
|
});
|
|
425
257
|
applyAiProfileAndMemberSyncChanges({
|
|
426
258
|
core,
|
|
427
259
|
workspaceId,
|
|
428
|
-
incomingAiProfiles,
|
|
260
|
+
incomingAiProfiles: applyModel.profiles.incomingAiProfiles,
|
|
429
261
|
workspaceMembers: options?.workspaceMembers,
|
|
430
262
|
recordSyncDiagnostic,
|
|
431
263
|
assertSyncedAiProfilesPersisted,
|
|
432
264
|
createSyncRouteError,
|
|
433
265
|
});
|
|
434
|
-
|
|
266
|
+
const preparedTaskSnapshot = prepareTaskSyncSnapshotApply({
|
|
267
|
+
core,
|
|
268
|
+
workspaceId,
|
|
269
|
+
taskMutations: applyModel.taskMutations,
|
|
270
|
+
recordSyncDiagnostic,
|
|
271
|
+
});
|
|
272
|
+
validateTaskActorAssignments(workspaceId, preparedTaskSnapshot.tasks, preparedTaskSnapshot.archived);
|
|
435
273
|
await applyContentSyncChanges({
|
|
436
274
|
core,
|
|
437
275
|
workspaceId,
|
|
438
|
-
incomingDocuments,
|
|
439
|
-
incomingDocumentDeletes,
|
|
440
|
-
incomingAssets,
|
|
441
|
-
incomingAssetDeletes,
|
|
276
|
+
incomingDocuments: applyModel.content.incomingDocuments,
|
|
277
|
+
incomingDocumentDeletes: applyModel.content.incomingDocumentDeletes,
|
|
278
|
+
incomingAssets: applyModel.content.incomingAssets,
|
|
279
|
+
incomingAssetDeletes: applyModel.content.incomingAssetDeletes,
|
|
442
280
|
basePath: core.getPaths().basePath,
|
|
443
281
|
hasObjectStorageClient: () => Boolean(getObjectStorageClient()),
|
|
444
282
|
hasDocumentSyncMetadataDrift: contentSyncState.hasDocumentSyncMetadataDrift,
|
|
445
283
|
hasBinaryAssetSyncMetadataDrift: contentSyncState.hasBinaryAssetSyncMetadataDrift,
|
|
284
|
+
getExistingDocument: (docPath, targetWorkspaceId) => {
|
|
285
|
+
const asset = workspaceAssetStore?.getByStorageKey(docPath, targetWorkspaceId) || null;
|
|
286
|
+
return asset
|
|
287
|
+
? {
|
|
288
|
+
updatedAt: asset.updatedAt,
|
|
289
|
+
contentHash: asset.contentSha256
|
|
290
|
+
}
|
|
291
|
+
: null;
|
|
292
|
+
},
|
|
446
293
|
writeWorkspaceSyncDocument: contentSyncState.writeWorkspaceSyncDocument,
|
|
447
294
|
deleteWorkspaceSyncDocument: contentSyncState.deleteWorkspaceSyncDocument,
|
|
448
295
|
writeWorkspaceSyncBinaryAsset: contentSyncState.writeWorkspaceSyncBinaryAsset,
|
|
@@ -454,20 +301,34 @@ export function registerSyncRoutes(deps) {
|
|
|
454
301
|
applyCollaborationSyncChanges({
|
|
455
302
|
core,
|
|
456
303
|
workspaceId,
|
|
457
|
-
incomingDocumentReviewSessions,
|
|
458
|
-
incomingDocumentReviewSessionDeletes,
|
|
459
|
-
incomingDocumentReviewComments,
|
|
460
|
-
incomingDocumentReviewCommentDeletes,
|
|
461
|
-
incomingAnnotatedAttachmentSessions,
|
|
462
|
-
incomingAnnotatedAttachmentSessionDeletes,
|
|
304
|
+
incomingDocumentReviewSessions: applyModel.collaboration.incomingDocumentReviewSessions,
|
|
305
|
+
incomingDocumentReviewSessionDeletes: applyModel.collaboration.incomingDocumentReviewSessionDeletes,
|
|
306
|
+
incomingDocumentReviewComments: applyModel.collaboration.incomingDocumentReviewComments,
|
|
307
|
+
incomingDocumentReviewCommentDeletes: applyModel.collaboration.incomingDocumentReviewCommentDeletes,
|
|
308
|
+
incomingAnnotatedAttachmentSessions: applyModel.collaboration.incomingAnnotatedAttachmentSessions,
|
|
309
|
+
incomingAnnotatedAttachmentSessionDeletes: applyModel.collaboration.incomingAnnotatedAttachmentSessionDeletes,
|
|
310
|
+
recordSyncDiagnostic,
|
|
311
|
+
createSyncRouteError,
|
|
312
|
+
});
|
|
313
|
+
const deleteCount = applyTaskSyncDeletes({
|
|
314
|
+
core,
|
|
315
|
+
workspaceId,
|
|
316
|
+
taskMutations: applyModel.taskMutations,
|
|
317
|
+
recordSyncDiagnostic,
|
|
318
|
+
});
|
|
319
|
+
const result = applyPreparedTaskSyncSnapshot({
|
|
320
|
+
core,
|
|
321
|
+
workspaceId,
|
|
322
|
+
prepared: preparedTaskSnapshot,
|
|
323
|
+
});
|
|
324
|
+
applyTaskActivitySyncChanges({
|
|
325
|
+
core,
|
|
326
|
+
workspaceId,
|
|
327
|
+
incomingTaskEvents: applyModel.taskActivity.incomingTaskEvents,
|
|
463
328
|
recordSyncDiagnostic,
|
|
464
329
|
createSyncRouteError,
|
|
465
330
|
});
|
|
466
|
-
|
|
467
|
-
tasks: tasks.map(taskSyncPayloadToCoreTask),
|
|
468
|
-
archived: archived.map(taskSyncPayloadToCoreTask)
|
|
469
|
-
}, workspaceId);
|
|
470
|
-
return { result, deleteCount: incomingTaskDeletes.size, emittedEventIds: Array.from(emittedEventIds) };
|
|
331
|
+
return { result, deleteCount, emittedEventIds: Array.from(emittedEventIds) };
|
|
471
332
|
}
|
|
472
333
|
finally {
|
|
473
334
|
unsubscribeRealtime();
|
|
@@ -1257,6 +1118,10 @@ export function registerSyncRoutes(deps) {
|
|
|
1257
1118
|
}
|
|
1258
1119
|
}
|
|
1259
1120
|
let incomingChanges = Array.isArray(body?.changes) ? body.changes : [];
|
|
1121
|
+
const incomingTaskUpsertIds = incomingChanges
|
|
1122
|
+
.filter((change) => change?.op === 'upsert')
|
|
1123
|
+
.map((change) => String(change.task?.id || '').trim())
|
|
1124
|
+
.filter((taskId) => taskId.length > 0);
|
|
1260
1125
|
const allowReferenceNumberReassignment = body?.repair === true;
|
|
1261
1126
|
// Decrypt asset and document content if TASKFORCE_SYNC_KEY is configured on this server.
|
|
1262
1127
|
// The local runtime encrypts content before pushing; the cloud must decrypt before writing to storage.
|
|
@@ -1311,12 +1176,20 @@ export function registerSyncRoutes(deps) {
|
|
|
1311
1176
|
const { result, deleteCount, emittedEventIds } = await dispatchWorkspaceSyncChanges(targetWorkspaceId, incomingChanges, {
|
|
1312
1177
|
allowReferenceNumberReassignment
|
|
1313
1178
|
});
|
|
1179
|
+
const appliedTaskUpserts = incomingTaskUpsertIds
|
|
1180
|
+
.map((taskId) => core.getTask(taskId, targetWorkspaceId))
|
|
1181
|
+
.filter((task) => Boolean(task))
|
|
1182
|
+
.map((task) => ({
|
|
1183
|
+
archived: Boolean(task.isArchived),
|
|
1184
|
+
task: serializeTaskForSync(task)
|
|
1185
|
+
}));
|
|
1314
1186
|
const durationMs = Date.now() - startedAtMs;
|
|
1315
1187
|
const payload = JSON.stringify({
|
|
1316
1188
|
success: true,
|
|
1317
1189
|
workspaceId: targetWorkspaceId,
|
|
1318
1190
|
idempotencyKey: idempotencyKey || null,
|
|
1319
1191
|
emittedEventIds,
|
|
1192
|
+
appliedTaskUpserts,
|
|
1320
1193
|
result,
|
|
1321
1194
|
durationMs
|
|
1322
1195
|
});
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
53
53
|
import { TaskforceCore } from '../../core/Taskforce.js';
|
|
54
54
|
import { type ResolvedObjectStorageConfig } from '../../storage/objectStorage.js';
|
|
55
|
-
import { type RouteHandler, type RouteContext } from '
|
|
55
|
+
import { type RouteHandler, type RouteContext } from './primitives.js';
|
|
56
56
|
export interface TaskRouteDependencies {
|
|
57
57
|
addRoute: (method: string, path: string, handler: RouteHandler) => void;
|
|
58
58
|
core: TaskforceCore;
|
|
@@ -54,11 +54,19 @@ import { toPublicObjectStorageConfig } from '../../storage/objectStorage.js';
|
|
|
54
54
|
import { getRuntimeCapabilities } from '../../runtime/capabilities.js';
|
|
55
55
|
import { resolveBuildInfo } from '../buildInfo.js';
|
|
56
56
|
import { resolveRealtimeSyncFlag } from '../../sync/realtimeFeature.js';
|
|
57
|
-
import { parseJsonBody } from '
|
|
57
|
+
import { parseJsonBody } from './primitives.js';
|
|
58
|
+
import { resolveRequestAccess } from '../auth.js';
|
|
58
59
|
import { resolveErrorStatusCode, requestHeader, requestRuntimeMode } from './shared.js';
|
|
59
60
|
import { listBuiltInCustomTaxonomyLibraryPacks } from '../../shared/customTaxonomyLibrary.js';
|
|
60
61
|
import { listBuiltInTaxonomyLibraryPacks } from '../../shared/taxonomyLibrary.js';
|
|
61
62
|
import { shouldUseProvisionalTaskReferences } from '../../utils/taskReferences.js';
|
|
63
|
+
function createUiStateRequestId() {
|
|
64
|
+
return `ui-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
65
|
+
}
|
|
66
|
+
function attachUiStateDebugHeaders(res, requestId) {
|
|
67
|
+
res.setHeader('x-taskforce-ui-state-route', 'tasks');
|
|
68
|
+
res.setHeader('x-taskforce-ui-state-request-id', requestId);
|
|
69
|
+
}
|
|
62
70
|
// === SECTION: Registration ===
|
|
63
71
|
export function registerTaskRoutes(deps) {
|
|
64
72
|
const { addRoute, core, context, requestWorkspaceId, ensureAppAccess, resolveEffectiveObjectStorageConfig, buildBatchSummary, CLOUD_SAFE_CONFIG_PATHS, } = deps;
|
|
@@ -155,16 +163,31 @@ export function registerTaskRoutes(deps) {
|
|
|
155
163
|
|| ((isLocalRuntime && allowCreate && !explicitWorkspaceId) ? '' : headerWorkspaceId)).trim() || 'default';
|
|
156
164
|
try {
|
|
157
165
|
const workspaceExists = Boolean(core.getWorkspaceProfile(incomingWorkspaceId));
|
|
166
|
+
const authConfig = context.authConfig;
|
|
167
|
+
const requestAccess = authConfig?.enabled
|
|
168
|
+
? resolveRequestAccess(req, authConfig)
|
|
169
|
+
: null;
|
|
158
170
|
const shouldCreateWorkspace = Boolean(name
|
|
159
171
|
&& (incomingWorkspaceId === 'default' || !workspaceExists)
|
|
160
172
|
&& (isLocalRuntime || allowCreate));
|
|
161
173
|
const workspace = shouldCreateWorkspace
|
|
162
|
-
?
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
174
|
+
? (!isLocalRuntime
|
|
175
|
+
&& requestAccess?.authenticated
|
|
176
|
+
&& requestAccess.userId
|
|
177
|
+
&& requestAccess.userId !== 'anonymous'
|
|
178
|
+
? core.createWorkspaceForUser({
|
|
179
|
+
userId: requestAccess.userId,
|
|
180
|
+
preferredWorkspaceId: incomingWorkspaceId === 'default' ? undefined : incomingWorkspaceId,
|
|
181
|
+
name,
|
|
182
|
+
description,
|
|
183
|
+
role: 'owner'
|
|
184
|
+
})
|
|
185
|
+
: core.createWorkspace({
|
|
186
|
+
workspaceId: incomingWorkspaceId === 'default' ? undefined : incomingWorkspaceId,
|
|
187
|
+
name,
|
|
188
|
+
description,
|
|
189
|
+
slug
|
|
190
|
+
}))
|
|
168
191
|
: core.updateWorkspaceProfile(incomingWorkspaceId, { name, description, slug });
|
|
169
192
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
170
193
|
res.end(JSON.stringify({ success: true, workspace }));
|
|
@@ -179,6 +202,9 @@ export function registerTaskRoutes(deps) {
|
|
|
179
202
|
addRoute('GET', '/api/taskforce/ui-state', async (req, res) => {
|
|
180
203
|
if (!ensureAppAccess(req, res))
|
|
181
204
|
return;
|
|
205
|
+
const requestId = createUiStateRequestId();
|
|
206
|
+
const startedAt = Date.now();
|
|
207
|
+
attachUiStateDebugHeaders(res, requestId);
|
|
182
208
|
try {
|
|
183
209
|
const url = new URL(req.url || '/', 'http://localhost');
|
|
184
210
|
const requestedWorkspaceId = String(url.searchParams.get('workspaceId') || '').trim();
|
|
@@ -194,6 +220,12 @@ export function registerTaskRoutes(deps) {
|
|
|
194
220
|
}
|
|
195
221
|
catch (error) {
|
|
196
222
|
const statusCode = resolveErrorStatusCode(error, 400);
|
|
223
|
+
console.warn('[Taskforce][ui-state] GET failed', {
|
|
224
|
+
requestId,
|
|
225
|
+
durationMs: Date.now() - startedAt,
|
|
226
|
+
error: String(error?.message || 'Failed to read UI state'),
|
|
227
|
+
path: req.url || '/api/taskforce/ui-state'
|
|
228
|
+
});
|
|
197
229
|
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
198
230
|
res.end(JSON.stringify({ success: false, error: String(error?.message || 'Failed to read UI state') }));
|
|
199
231
|
}
|
|
@@ -202,6 +234,9 @@ export function registerTaskRoutes(deps) {
|
|
|
202
234
|
addRoute('POST', '/api/taskforce/ui-state', async (req, res) => {
|
|
203
235
|
if (!ensureAppAccess(req, res))
|
|
204
236
|
return;
|
|
237
|
+
const requestId = createUiStateRequestId();
|
|
238
|
+
const startedAt = Date.now();
|
|
239
|
+
attachUiStateDebugHeaders(res, requestId);
|
|
205
240
|
const body = await parseJsonBody(req);
|
|
206
241
|
try {
|
|
207
242
|
const requestedWorkspaceId = String(body?.workspaceId || '').trim();
|
|
@@ -222,6 +257,13 @@ export function registerTaskRoutes(deps) {
|
|
|
222
257
|
}
|
|
223
258
|
catch (error) {
|
|
224
259
|
const statusCode = resolveErrorStatusCode(error, 400);
|
|
260
|
+
console.warn('[Taskforce][ui-state] POST failed', {
|
|
261
|
+
requestId,
|
|
262
|
+
durationMs: Date.now() - startedAt,
|
|
263
|
+
error: String(error?.message || 'Failed to merge UI state'),
|
|
264
|
+
path: req.url || '/api/taskforce/ui-state',
|
|
265
|
+
stateKey: String(body?.stateKey || body?.key || '').trim() || 'default'
|
|
266
|
+
});
|
|
225
267
|
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
226
268
|
res.end(JSON.stringify({ success: false, error: String(error?.message || 'Failed to merge UI state') }));
|
|
227
269
|
}
|
|
@@ -398,7 +440,7 @@ export function registerTaskRoutes(deps) {
|
|
|
398
440
|
: body;
|
|
399
441
|
const updated = core.updateTask(params.id, updates, workspaceId, {
|
|
400
442
|
actorRef: 'user',
|
|
401
|
-
|
|
443
|
+
saveSource
|
|
402
444
|
});
|
|
403
445
|
if (!updated) {
|
|
404
446
|
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { IncomingMessage, ServerResponse } from 'http';
|
|
15
15
|
import type { TaskforceCore } from '../../core/Taskforce.js';
|
|
16
|
-
import type
|
|
16
|
+
import { type RouteHandler, type RouteContext } from './primitives.js';
|
|
17
17
|
import { ObjectStorageClient } from '../../storage/objectStorageClient.js';
|
|
18
18
|
export interface WorkspaceRouteDependencies {
|
|
19
19
|
addRoute: (method: string, path: string, handler: RouteHandler) => void;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import * as fs from 'fs';
|
|
15
15
|
import * as path from 'path';
|
|
16
|
-
import { parseJsonBody } from '
|
|
16
|
+
import { parseJsonBody } from './primitives.js';
|
|
17
17
|
import { resolveRequestAccess, createSessionTokenCookie, resolveSessionCookieAttributesForRequest, } from '../auth.js';
|
|
18
18
|
import { isWorkspaceSwitchingEnabledForRuntime } from '../../shared/runtimeContract.js';
|
|
19
19
|
import { resolveErrorStatusCode } from './shared.js';
|
package/dist/server/routes.d.ts
CHANGED
|
@@ -4,17 +4,14 @@
|
|
|
4
4
|
* Extracted from vite.ts plugin to be reusable in both Vite plugin and standalone server.
|
|
5
5
|
* This is a minimal implementation with core routes - additional routes can be added incrementally.
|
|
6
6
|
*/
|
|
7
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
8
7
|
import { TaskforceCore } from '../core/Taskforce.js';
|
|
9
|
-
import { type
|
|
10
|
-
|
|
11
|
-
export type RouteHandler = (req: IncomingMessage, res: ServerResponse, params: Record<string, string>) => Promise<void>;
|
|
8
|
+
import { type RouteContext, type RouteHandler } from './routes/primitives.js';
|
|
9
|
+
export { parseJsonBody } from './routes/primitives.js';
|
|
12
10
|
export interface Route {
|
|
13
11
|
pattern: RegExp;
|
|
14
12
|
keys: string[];
|
|
15
13
|
handler: RouteHandler;
|
|
16
14
|
}
|
|
17
|
-
export declare function parseJsonBody(req: IncomingMessage, maxBytes?: number): Promise<any>;
|
|
18
15
|
/**
|
|
19
16
|
* Create API routes for Taskforce
|
|
20
17
|
*
|
|
@@ -60,10 +57,6 @@ export declare function parseJsonBody(req: IncomingMessage, maxBytes?: number):
|
|
|
60
57
|
* - POST /api/taskforce/export-resources
|
|
61
58
|
* - GET /api/taskforce/health
|
|
62
59
|
*/
|
|
63
|
-
export interface RouteContext {
|
|
64
|
-
authConfig?: TaskforceAuthConfig;
|
|
65
|
-
objectStorage?: ResolvedObjectStorageConfig;
|
|
66
|
-
}
|
|
67
60
|
export declare function createRoutes(core: TaskforceCore, context?: RouteContext): Route[];
|
|
68
61
|
export declare function matchRoute(method: string, pathname: string, routes: Route[]): {
|
|
69
62
|
handler: RouteHandler;
|