@jsb188/graphql 1.1.12 → 1.1.13
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/LICENSE +21 -0
- package/audience.d.ts +14 -152
- package/cache/config.ts +35 -32
- package/cache/index.helpers.ts +1 -1
- package/cache/index.ts +73 -44
- package/cache/mounted-queries.ts +33 -0
- package/cache/persist.ts +10 -4
- package/cache/realtime-fence.ts +47 -0
- package/cache/realtime-live.ts +17 -0
- package/client/draft-persistence.ts +10 -39
- package/client/index.ts +2 -1
- package/client/request.ts +9 -34
- package/client/storage-asset.ts +58 -0
- package/gql/fragments/accountAuthFragments.ts +0 -4
- package/gql/fragments/agentNoteFragments.ts +8 -2
- package/gql/fragments/aiChatFragments.ts +0 -2
- package/gql/fragments/aiChatLinkFragments.ts +8 -0
- package/gql/fragments/audienceFragments.ts +1 -66
- package/gql/fragments/emailFragments.ts +27 -4
- package/gql/fragments/emailOutreachFragments.ts +281 -0
- package/gql/fragments/inboundContactFragments.ts +1 -1
- package/gql/fragments/libraryFragments.ts +120 -0
- package/gql/fragments/organizationFragments.ts +4 -2
- package/gql/fragments/scheduleFragments.ts +241 -324
- package/gql/fragments/sheetFragments.ts +4 -53
- package/gql/fragments/workWaitFragments.ts +13 -0
- package/gql/fragments/workflowFragments.ts +20 -4
- package/gql/mutations/agentNoteMutations.ts +2 -0
- package/gql/mutations/aiChatLinkMutations.ts +13 -0
- package/gql/mutations/aiChatMutations.ts +4 -6
- package/gql/mutations/audienceMutations.ts +0 -13
- package/gql/mutations/authMutations.ts +12 -60
- package/gql/mutations/emailMutations.ts +22 -0
- package/gql/mutations/emailOutreachMutations.ts +139 -0
- package/gql/mutations/index.ts +3 -1
- package/gql/mutations/organizationMutations.ts +2 -2
- package/gql/mutations/scheduleMutations.ts +61 -787
- package/gql/mutations/storageMutations.ts +1 -0
- package/gql/mutations/workflowMutations.ts +76 -0
- package/gql/queries/agentMemoryQueries.ts +6 -2
- package/gql/queries/agentNoteQueries.ts +26 -29
- package/gql/queries/aiChatQueries.ts +39 -40
- package/gql/queries/audienceQueries.ts +31 -55
- package/gql/queries/authQueries.ts +16 -6
- package/gql/queries/billingQueries.ts +26 -10
- package/gql/queries/dataTableQueries.ts +24 -15
- package/gql/queries/emailOutreachQueries.ts +282 -0
- package/gql/queries/emailQueries.ts +39 -12
- package/gql/queries/emailReplyReportQueries.ts +60 -9
- package/gql/queries/fieldDocQueries.ts +36 -14
- package/gql/queries/inboundContactQueries.ts +11 -4
- package/gql/queries/index.ts +2 -2
- package/gql/queries/libraryQueries.ts +112 -0
- package/gql/queries/logQueries.ts +31 -12
- package/gql/queries/organizationQueries.ts +31 -12
- package/gql/queries/qrCodeQueries.ts +11 -4
- package/gql/queries/scheduleQueries.ts +252 -505
- package/gql/queries/sheetQueries.ts +36 -14
- package/gql/queries/storageQueries.ts +11 -4
- package/gql/queries/workflowQueries.ts +53 -10
- package/gql/reactivity.ts +98 -0
- package/gql/recordReads.ts +171 -0
- package/hooks/index.ts +79 -52
- package/hooks/use-agentNote-mtn.ts +7 -0
- package/hooks/use-agentNote-qry.ts +30 -58
- package/hooks/use-agentNote-recovery.ts +6 -21
- package/hooks/use-aiChat-mtn.ts +9 -4
- package/hooks/use-aiChat-qry.ts +28 -7
- package/hooks/use-audience-mtn.ts +0 -24
- package/hooks/use-audience-qry.helpers.ts +0 -24
- package/hooks/use-audience-qry.ts +1 -86
- package/hooks/use-dataTable-mtn.ts +3 -3
- package/hooks/use-dataTable-qry.ts +7 -2
- package/hooks/use-email-mtn.ts +26 -0
- package/hooks/use-email-qry.helpers.ts +1 -1
- package/hooks/use-email-qry.ts +18 -3
- package/hooks/use-emailOutreach-mtn.ts +211 -0
- package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
- package/hooks/use-emailOutreach-qry.ts +367 -0
- package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
- package/hooks/use-fieldDoc-qry.ts +1 -1
- package/hooks/use-library-qry.ts +233 -0
- package/hooks/use-qrCode-qry.ts +1 -1
- package/hooks/use-schedule-mtn.ts +10 -300
- package/hooks/use-schedule-qry.ts +168 -680
- package/hooks/use-schedule-reactive.ts +71 -339
- package/hooks/use-sheet-qry.ts +6 -1
- package/hooks/use-workflow-mtn.ts +45 -1
- package/hooks/use-workflow-qry.ts +22 -2
- package/libs/ai-chat-link-events.ts +78 -0
- package/libs/data-changes.helpers.ts +161 -0
- package/libs/data-changes.ts +382 -0
- package/libs/fragment-realtime-sequence.ts +3 -3
- package/libs/record-read.ts +327 -0
- package/libs/sheet-command-batch.ts +3 -2
- package/libs/sheet-realtime-packet.ts +53 -0
- package/loaders/emailPreference.ts +18 -24
- package/package.json +44 -17
- package/schedule.d.ts +267 -874
- package/types.d.ts +3 -1
- package/cache/index.chat-activity.test.ts +0 -119
- package/cache/index.chat.test.ts +0 -92
- package/cache/index.regression.test.ts +0 -149
- package/cache/index.test.ts +0 -1209
- package/deno.lock +0 -187
- package/deno.test.json +0 -12
- package/gql/fragments/campaignFragments.ts +0 -566
- package/gql/mutations/campaignMutations.ts +0 -258
- package/gql/queries/appQueries.ts +0 -14
- package/gql/queries/campaignQueries.ts +0 -236
- package/hooks/index.helpers.test.ts +0 -50
- package/hooks/use-agentNote-recovery.helpers.test.ts +0 -68
- package/hooks/use-aiChat-qry.helpers.test.ts +0 -63
- package/hooks/use-app-qry.ts +0 -22
- package/hooks/use-audience-qry.helpers.test.ts +0 -80
- package/hooks/use-campaign-generation-recovery.ts +0 -53
- package/hooks/use-campaign-mtn.ts +0 -436
- package/hooks/use-campaign-qry.helpers.ts +0 -40
- package/hooks/use-campaign-qry.ts +0 -834
- package/hooks/use-emailCampaignReplyReport-qry.ts +0 -27
- package/hooks/use-fieldDoc-qry.helpers.test.ts +0 -65
- package/hooks/use-publicFormEmail-mtn.ts +0 -27
- package/libs/fragment-recovery.test.ts +0 -326
- package/libs/fragment-recovery.ts +0 -325
- package/libs/orchestrator-realtime.helpers.test.ts +0 -229
- package/libs/orchestrator-realtime.helpers.ts +0 -317
- package/libs/orchestrator-realtime.ts +0 -433
- package/libs/request-cache-regression.test.ts +0 -122
- package/libs/request-managed-session.test.ts +0 -574
- package/libs/request-no-store.test.ts +0 -419
- package/libs/sheet-view-realtime-router.test.ts +0 -214
- package/libs/sse-ticket.test.ts +0 -26
- package/loaders/campaign.test.ts +0 -186
- package/loaders/campaign.ts +0 -110
- package/tests/agent-note-detail-cache.test.ts +0 -120
- package/tests/agent-note-search.test.ts +0 -444
- package/tsconfig.json +0 -13
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import type { AIChatType } from '@jsb188/app/types/ai.d.ts';
|
|
2
|
-
import type { OrchestratorArtifactKind, OrchestratorArtifactWSObj } from '@jsb188/app/types/app.d.ts';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Types
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// CREATED sticks for the rest of the session; later edits never downgrade it
|
|
9
|
-
export type OrchestratorArtifactState = 'CREATED' | 'EDITED';
|
|
10
|
-
|
|
11
|
-
// One sheet, tab, data table, form or workflow the orchestrator created or edited in a session
|
|
12
|
-
export interface OrchestratorArtifactObj {
|
|
13
|
-
key: string;
|
|
14
|
-
kind: OrchestratorArtifactKind;
|
|
15
|
-
state: OrchestratorArtifactState;
|
|
16
|
-
// The organization the orchestrator made it in; its page only opens under that login
|
|
17
|
-
organizationId: string | null;
|
|
18
|
-
sheetId: string | null;
|
|
19
|
-
sheetTabId: string | null;
|
|
20
|
-
dataTableId: string | null;
|
|
21
|
-
fieldDocId: string | null;
|
|
22
|
-
fieldDocProgramId: string | null;
|
|
23
|
-
// Current publication state is observed separately from the historical tool event.
|
|
24
|
-
hasDraft: boolean | null;
|
|
25
|
-
draftStateAt: string | null;
|
|
26
|
-
workflowId: string | null;
|
|
27
|
-
// Workflows only: whether new matching logs run it (null while unknown)
|
|
28
|
-
active: boolean | null;
|
|
29
|
-
title: string | null;
|
|
30
|
-
at: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// In-memory chat selection and artifact state
|
|
34
|
-
export interface OrchestratorSessionData {
|
|
35
|
-
aiChatId: string | null;
|
|
36
|
-
chatType: AIChatType | null;
|
|
37
|
-
artifacts: OrchestratorArtifactObj[];
|
|
38
|
-
// Whether any sheet, tab or data table was CREATED in this session (gates DATA_TABLE navigation)
|
|
39
|
-
hasCreated: boolean;
|
|
40
|
-
// Tool call ids already applied, oldest first
|
|
41
|
-
callIds: string[];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface OrchestratorArtifactApplyResult {
|
|
45
|
-
session: OrchestratorSessionData;
|
|
46
|
-
// The artifact the owning tab should navigate to, if this event calls for it
|
|
47
|
-
navigateTo: OrchestratorArtifactObj | null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Constants
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
export const ORCHESTRATOR_SESSION_LIMITS = {
|
|
55
|
-
maxArtifacts: 50,
|
|
56
|
-
// Twice the server's catch-up window (orchestratorArtifactOps.ts), so a caught-up call is never applied twice
|
|
57
|
-
maxCallIds: 200,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/*
|
|
61
|
-
* Return a fresh session with no chat and no artifacts.
|
|
62
|
-
*/
|
|
63
|
-
export function getEmptyOrchestratorSessionData(): OrchestratorSessionData {
|
|
64
|
-
return {
|
|
65
|
-
aiChatId: null,
|
|
66
|
-
chatType: null,
|
|
67
|
-
artifacts: [],
|
|
68
|
-
hasCreated: false,
|
|
69
|
-
callIds: [],
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/*
|
|
74
|
-
* Return the list identity of one artifact (kind + its own id), or null when the id is missing.
|
|
75
|
-
*/
|
|
76
|
-
export function getOrchestratorArtifactKey(p: {
|
|
77
|
-
kind: OrchestratorArtifactKind;
|
|
78
|
-
sheetId?: string | null;
|
|
79
|
-
sheetTabId?: string | null;
|
|
80
|
-
dataTableId?: string | null;
|
|
81
|
-
fieldDocId?: string | null;
|
|
82
|
-
workflowId?: string | null;
|
|
83
|
-
}) {
|
|
84
|
-
let id: string | null | undefined;
|
|
85
|
-
switch (p.kind) {
|
|
86
|
-
case 'SHEET':
|
|
87
|
-
id = p.sheetId;
|
|
88
|
-
break;
|
|
89
|
-
case 'SHEET_TAB':
|
|
90
|
-
id = p.sheetTabId;
|
|
91
|
-
break;
|
|
92
|
-
case 'DATA_TABLE':
|
|
93
|
-
id = p.dataTableId;
|
|
94
|
-
break;
|
|
95
|
-
case 'FIELD_DOC':
|
|
96
|
-
id = p.fieldDocId;
|
|
97
|
-
break;
|
|
98
|
-
case 'WORKFLOW':
|
|
99
|
-
id = p.workflowId;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return id ? `${p.kind}:${id}` : null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/*
|
|
107
|
-
* Return whether a live creation of this kind may open its page on its own. Forms and workflows are only
|
|
108
|
-
* listed, so the grid behind the orchestrator stays put.
|
|
109
|
-
*/
|
|
110
|
-
function isOrchestratorNavigableKind(kind: OrchestratorArtifactKind) {
|
|
111
|
-
return kind === 'SHEET' || kind === 'SHEET_TAB' || kind === 'DATA_TABLE';
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/*
|
|
115
|
-
* Return the artifact list after one deletion. A deleted spreadsheet takes its listed tabs with it, and a
|
|
116
|
-
* deleted tab is no longer the tab its spreadsheet opens on. Unchanged entries keep their identity.
|
|
117
|
-
*/
|
|
118
|
-
function removeOrchestratorDeletedArtifact(artifacts: OrchestratorArtifactObj[], key: string, update: OrchestratorArtifactWSObj) {
|
|
119
|
-
return artifacts.flatMap((artifact) => {
|
|
120
|
-
if (artifact.key === key || (update.kind === 'SHEET' && artifact.kind === 'SHEET_TAB' && artifact.sheetId === update.sheetId)) {
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
update.kind === 'SHEET_TAB' &&
|
|
126
|
-
artifact.kind === 'SHEET' &&
|
|
127
|
-
artifact.sheetId === update.sheetId &&
|
|
128
|
-
artifact.sheetTabId === update.sheetTabId
|
|
129
|
-
) {
|
|
130
|
-
return [{ ...artifact, sheetTabId: null }];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return [artifact];
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/*
|
|
138
|
-
* Return whether two artifact lists hold the same entries in the same order.
|
|
139
|
-
*/
|
|
140
|
-
function isSameOrchestratorArtifactList(a: OrchestratorArtifactObj[], b: OrchestratorArtifactObj[]) {
|
|
141
|
-
return a.length === b.length && a.every((artifact, i) => artifact === b[i]);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/*
|
|
145
|
-
* Merge a form's current draft state by observation time, so a delayed catch-up cannot restore an old draft.
|
|
146
|
-
*/
|
|
147
|
-
function getOrchestratorDraftState(update: OrchestratorArtifactWSObj, existing?: OrchestratorArtifactObj) {
|
|
148
|
-
const draftStateAt = update.draftStateAt || update.at;
|
|
149
|
-
if (
|
|
150
|
-
update.kind === 'FIELD_DOC' &&
|
|
151
|
-
typeof update.hasDraft === 'boolean' &&
|
|
152
|
-
(!existing?.draftStateAt || draftStateAt >= existing.draftStateAt)
|
|
153
|
-
) {
|
|
154
|
-
return { hasDraft: update.hasDraft, draftStateAt };
|
|
155
|
-
}
|
|
156
|
-
return { hasDraft: existing?.hasDraft ?? null, draftStateAt: existing?.draftStateAt || null };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/*
|
|
160
|
-
* Refresh an already-seen call's form state after catch-up reads the current draft without replaying the edit.
|
|
161
|
-
*/
|
|
162
|
-
function refreshOrchestratorDraftState(session: OrchestratorSessionData, update: OrchestratorArtifactWSObj) {
|
|
163
|
-
if (update.kind !== 'FIELD_DOC' || typeof update.hasDraft !== 'boolean') return null;
|
|
164
|
-
const key = getOrchestratorArtifactKey(update);
|
|
165
|
-
let changed = false;
|
|
166
|
-
const artifacts = session.artifacts.map((artifact) => {
|
|
167
|
-
if (artifact.key !== key) return artifact;
|
|
168
|
-
const next = getOrchestratorDraftState(update, artifact);
|
|
169
|
-
if (next.hasDraft === artifact.hasDraft && next.draftStateAt === artifact.draftStateAt) return artifact;
|
|
170
|
-
changed = true;
|
|
171
|
-
return { ...artifact, ...next };
|
|
172
|
-
});
|
|
173
|
-
return changed ? { ...session, artifacts } : null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/*
|
|
177
|
-
* Return one artifact after an event, keeping what an earlier event already knew when this one omits it.
|
|
178
|
-
*/
|
|
179
|
-
function getUpdatedOrchestratorArtifact(
|
|
180
|
-
key: string,
|
|
181
|
-
update: OrchestratorArtifactWSObj,
|
|
182
|
-
existing: OrchestratorArtifactObj | undefined,
|
|
183
|
-
): OrchestratorArtifactObj {
|
|
184
|
-
return {
|
|
185
|
-
key,
|
|
186
|
-
kind: update.kind,
|
|
187
|
-
state: update.action === 'CREATED' || existing?.state === 'CREATED' ? 'CREATED' : 'EDITED',
|
|
188
|
-
organizationId: update.organizationId || existing?.organizationId || null,
|
|
189
|
-
sheetId: update.sheetId || existing?.sheetId || null,
|
|
190
|
-
sheetTabId: update.sheetTabId || existing?.sheetTabId || null,
|
|
191
|
-
dataTableId: update.dataTableId || existing?.dataTableId || null,
|
|
192
|
-
fieldDocId: update.fieldDocId || existing?.fieldDocId || null,
|
|
193
|
-
fieldDocProgramId: update.fieldDocProgramId || existing?.fieldDocProgramId || null,
|
|
194
|
-
...getOrchestratorDraftState(update, existing),
|
|
195
|
-
workflowId: update.workflowId || existing?.workflowId || null,
|
|
196
|
-
active: typeof update.active === 'boolean' ? update.active : (existing?.active ?? null),
|
|
197
|
-
title: update.title || existing?.title || null,
|
|
198
|
-
at: update.at || new Date().toISOString(),
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/*
|
|
203
|
-
* Apply one live artifact event to a session. Already-applied calls only refresh current draft state.
|
|
204
|
-
* Navigation: SHEET and SHEET_TAB creations always navigate; a DATA_TABLE creation only when
|
|
205
|
-
* no sheet, tab or table was created earlier in the session. Forms, workflows, updates and
|
|
206
|
-
* deletions never navigate.
|
|
207
|
-
*/
|
|
208
|
-
export function applyOrchestratorArtifactUpdate(
|
|
209
|
-
session: OrchestratorSessionData,
|
|
210
|
-
update: OrchestratorArtifactWSObj,
|
|
211
|
-
): OrchestratorArtifactApplyResult | null {
|
|
212
|
-
if (session.callIds.includes(update.callId)) {
|
|
213
|
-
const refreshed = refreshOrchestratorDraftState(session, update);
|
|
214
|
-
return refreshed ? { session: refreshed, navigateTo: null } : null;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const callIds = [...session.callIds, update.callId].slice(-ORCHESTRATOR_SESSION_LIMITS.maxCallIds);
|
|
218
|
-
const key = getOrchestratorArtifactKey(update);
|
|
219
|
-
if (!key) {
|
|
220
|
-
return { session: { ...session, callIds }, navigateTo: null };
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (update.action === 'DELETED') {
|
|
224
|
-
const artifacts = removeOrchestratorDeletedArtifact(session.artifacts, key, update);
|
|
225
|
-
return { session: { ...session, artifacts, callIds }, navigateTo: null };
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const existing = session.artifacts.find((artifact) => artifact.key === key);
|
|
229
|
-
const artifact = getUpdatedOrchestratorArtifact(key, update, existing);
|
|
230
|
-
// Most recently touched first
|
|
231
|
-
const artifacts = [artifact, ...session.artifacts.filter((item) => item.key !== key)].slice(
|
|
232
|
-
0,
|
|
233
|
-
ORCHESTRATOR_SESSION_LIMITS.maxArtifacts,
|
|
234
|
-
);
|
|
235
|
-
const createdGrid = update.action === 'CREATED' && isOrchestratorNavigableKind(update.kind);
|
|
236
|
-
const shouldNavigate = createdGrid && existing?.state !== 'CREATED' && (update.kind !== 'DATA_TABLE' || !session.hasCreated);
|
|
237
|
-
|
|
238
|
-
return {
|
|
239
|
-
session: {
|
|
240
|
-
...session,
|
|
241
|
-
artifacts,
|
|
242
|
-
callIds,
|
|
243
|
-
hasCreated: session.hasCreated || createdGrid,
|
|
244
|
-
},
|
|
245
|
-
navigateTo: shouldNavigate ? artifact : null,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/*
|
|
250
|
-
* Apply one caught-up artifact event (see mergeOrchestratorArtifactUpdates). An already applied
|
|
251
|
-
* deletion is applied again, since the creation it follows may only be arriving now.
|
|
252
|
-
*/
|
|
253
|
-
function mergeOrchestratorArtifactUpdate(
|
|
254
|
-
session: OrchestratorSessionData,
|
|
255
|
-
update: OrchestratorArtifactWSObj,
|
|
256
|
-
): OrchestratorSessionData {
|
|
257
|
-
const key = getOrchestratorArtifactKey(update);
|
|
258
|
-
if (session.callIds.includes(update.callId)) {
|
|
259
|
-
if (!key || update.action !== 'DELETED') {
|
|
260
|
-
return refreshOrchestratorDraftState(session, update) || session;
|
|
261
|
-
}
|
|
262
|
-
const artifacts = removeOrchestratorDeletedArtifact(session.artifacts, key, update);
|
|
263
|
-
return isSameOrchestratorArtifactList(artifacts, session.artifacts) ? session : { ...session, artifacts };
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const newer = session.artifacts.find((artifact) => artifact.key === key && artifact.at > update.at);
|
|
267
|
-
const merged = applyOrchestratorArtifactUpdate(session, update)?.session;
|
|
268
|
-
if (!merged || !newer) {
|
|
269
|
-
return merged || session;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Older than what this tab already lists: it may only add a CREATED state or missing fields
|
|
273
|
-
return {
|
|
274
|
-
...merged,
|
|
275
|
-
artifacts: merged.artifacts.map((artifact) =>
|
|
276
|
-
artifact.key === key
|
|
277
|
-
? {
|
|
278
|
-
...artifact,
|
|
279
|
-
sheetTabId: newer.sheetTabId || artifact.sheetTabId,
|
|
280
|
-
fieldDocProgramId: newer.fieldDocProgramId || artifact.fieldDocProgramId,
|
|
281
|
-
active: newer.active ?? artifact.active,
|
|
282
|
-
title: newer.title || artifact.title,
|
|
283
|
-
at: newer.at,
|
|
284
|
-
}
|
|
285
|
-
: artifact,
|
|
286
|
-
),
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/*
|
|
291
|
-
* Merge caught-up artifact events (oldest first) that this tab may have missed while it was not
|
|
292
|
-
* watching. Unlike live events they never navigate. Calls already applied are skipped, entries are
|
|
293
|
-
* re-sorted newest first (a caught-up event can be older than one received live), and the caught-up
|
|
294
|
-
* call ids are remembered as the newest, so a later catch-up only refreshes current form draft state.
|
|
295
|
-
* Returns null when nothing changed.
|
|
296
|
-
*/
|
|
297
|
-
export function mergeOrchestratorArtifactUpdates(
|
|
298
|
-
session: OrchestratorSessionData,
|
|
299
|
-
updates: OrchestratorArtifactWSObj[],
|
|
300
|
-
): OrchestratorSessionData | null {
|
|
301
|
-
let merged = session;
|
|
302
|
-
for (const update of updates) {
|
|
303
|
-
merged = mergeOrchestratorArtifactUpdate(merged, update);
|
|
304
|
-
}
|
|
305
|
-
if (merged === session) {
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const caughtUpCallIds = new Set(updates.map((update) => update.callId));
|
|
310
|
-
return {
|
|
311
|
-
...merged,
|
|
312
|
-
artifacts: [...merged.artifacts].sort((a, b) => (a.at === b.at ? 0 : a.at > b.at ? -1 : 1)),
|
|
313
|
-
callIds: [...session.callIds.filter((callId) => !caughtUpCallIds.has(callId)), ...caughtUpCallIds].slice(
|
|
314
|
-
-ORCHESTRATOR_SESSION_LIMITS.maxCallIds,
|
|
315
|
-
),
|
|
316
|
-
};
|
|
317
|
-
}
|