codex-overleaf-link 2.2.0 → 2.3.0
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 +25 -23
- package/extension/bootstrap/manifest.template.json +1 -1
- package/extension/runtime-manifest.json +5 -71
- package/extension/src/background.js +53 -69
- package/extension/src/backgroundUpdateCoordinator.js +128 -66
- package/extension/src/content/applyResultFormatters.js +2 -3
- package/extension/src/content/contentRuntime.js +650 -1449
- package/extension/src/content/contextTray.js +4 -6
- package/extension/src/content/diagnosticsController.js +1 -2
- package/extension/src/content/diffReviewPanel.js +14 -13
- package/extension/src/content/generated/content.bundle.js +41370 -0
- package/extension/src/content/generated/content.bundle.meta.json +102 -0
- package/extension/src/content/legacyGlobalRegistry.js +129 -0
- package/extension/src/content/markdownText.js +5 -7
- package/extension/src/content/modelPicker.js +1 -1
- package/extension/src/content/modelPickerSupport.js +10 -5
- package/extension/src/content/moduleRegistryKernel.js +125 -0
- package/extension/src/content/nativeCompatibilityController.js +313 -0
- package/extension/src/content/otWarmMirror.js +7 -5
- package/extension/src/content/pageBridgeClient.js +224 -0
- package/extension/src/content/panelMaintenance.js +8 -3
- package/extension/src/content/postNavigationSettlementPersistence.js +100 -0
- package/extension/src/content/projectProviderSelection.js +4 -12
- package/extension/src/content/projectSessionCleanup.js +3 -3
- package/extension/src/content/providerSettingsCoordinator.js +59 -26
- package/extension/src/content/providerSettingsDialog.js +30 -18
- package/extension/src/content/recentProjects.js +15 -23
- package/extension/src/content/runGuidanceController.js +1 -1
- package/extension/src/content/runQueueScheduler.js +129 -29
- package/extension/src/content/runSettlementPersistence.js +51 -0
- package/extension/src/content/runTimelineView.js +11 -8
- package/extension/src/content/scopedPersistenceCoordinator.js +100 -0
- package/extension/src/content/scopedPersistenceDetachedCommit.js +47 -0
- package/extension/src/content/scopedPersistencePanelState.js +111 -0
- package/extension/src/content/sessionManager.js +15 -12
- package/extension/src/content/sessionPersistence.js +67 -8
- package/extension/src/content/updateNotice.js +10 -4
- package/extension/src/content/writebackOrchestrator.js +91 -23
- package/extension/src/contentScript.js +5 -1
- package/extension/src/page/trackedChangesLifecycle.js +6 -1
- package/extension/src/pageBridge.js +47 -98
- package/extension/src/shared/agentTranscript.js +8 -5
- package/extension/src/shared/compatibility.js +1 -1
- package/extension/src/shared/governanceRules.js +1 -1
- package/extension/src/shared/managedUpdateProjection.js +337 -0
- package/extension/src/shared/nativeRequestIdentity.js +60 -0
- package/extension/src/shared/otText.js +0 -19
- package/extension/src/shared/pageRpcContract.js +136 -0
- package/extension/src/shared/runExecutionSnapshot.js +177 -0
- package/extension/src/shared/runExecutionSnapshotCodec.js +168 -0
- package/extension/src/shared/runInputQueue.js +81 -34
- package/extension/src/shared/scopedPersistenceBrowserAdapter.js +79 -0
- package/extension/src/shared/scopedPersistenceQueuePolicy.js +181 -0
- package/extension/src/shared/scopedPersistenceTransaction.js +238 -0
- package/extension/src/shared/sessionState.js +64 -48
- package/extension/src/shared/settlementFacts.js +351 -0
- package/extension/src/shared/storageDb.js +19 -5
- package/extension/src/shared/storageMigration.js +275 -61
- package/extension/src/shared/storageSessionClaims.js +60 -0
- package/extension/src/shared/updateConsent.js +4 -0
- package/extension/src/shared/updateRevocationIntent.js +109 -0
- package/extension/src/shared/writebackEvidenceProjection.js +150 -0
- package/extension/src/shared/writebackOperationEvidence.js +143 -0
- package/extension/src/shared/writebackSettlement.js +705 -0
- package/native-host/src/codexRuntimeIdentity.js +1 -1
- package/native-host/src/codexSessionRunner.js +7 -13
- package/native-host/src/index.js +3 -69
- package/native-host/src/managedInstall.js +50 -8
- package/native-host/src/mirrorWorkspace.js +15 -8
- package/native-host/src/nativeTransportEnvelope.js +148 -0
- package/native-host/src/taskRunnerRuntime.js +3 -3
- package/package.json +13 -5
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
(function initCodexOverleafSettlementFacts(root, factory) {
|
|
2
|
+
if (typeof module === 'object' && module.exports) {
|
|
3
|
+
module.exports = factory(require('./failureReasons'));
|
|
4
|
+
} else {
|
|
5
|
+
root.CodexOverleafModuleRegistry.define('SettlementFacts', ['FailureReasons'], factory);
|
|
6
|
+
}
|
|
7
|
+
})(typeof window !== 'undefined' ? window : globalThis, function settlementFactsFactory(DefaultFailureReasons) {
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const SETTLEMENT_FACTS_MAX_BYTES = 32 * 1024;
|
|
11
|
+
const SESSION_SETTLEMENT_DETAIL_MAX_BYTES = 512 * 1024;
|
|
12
|
+
const RECOVERY_FIELDS = Object.freeze([
|
|
13
|
+
'appliedOperations', 'undoOperations', 'undoBaseFiles', 'undoTrackedChanges',
|
|
14
|
+
'undoExpectedFiles', 'undoStatus', 'interruptedDraft'
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
function compactSettlementFacts(value = {}, maxBytes = SETTLEMENT_FACTS_MAX_BYTES) {
|
|
18
|
+
const legacyFailures = value.primaryFailure && typeof value.primaryFailure === 'object'
|
|
19
|
+
? [value.primaryFailure]
|
|
20
|
+
: [];
|
|
21
|
+
const facts = {
|
|
22
|
+
schemaVersion: 1,
|
|
23
|
+
documentEffect: normalizeDocumentEffect(
|
|
24
|
+
value.documentEffect || (value.changedDocument === true ? 'changed' : '')
|
|
25
|
+
),
|
|
26
|
+
evidence: normalizeEvidence(value),
|
|
27
|
+
fileSettlements: normalizeFiles(value.fileSettlements),
|
|
28
|
+
failures: normalizeFailures(Array.isArray(value.failures) ? value.failures : legacyFailures),
|
|
29
|
+
recoveryAvailability: normalizeAvailability(value.recoveryAvailability),
|
|
30
|
+
recoveryDisposition: normalizeDisposition(value.recoveryDisposition),
|
|
31
|
+
capturedAt: typeof value.capturedAt === 'string' ? value.capturedAt : ''
|
|
32
|
+
};
|
|
33
|
+
if (value.compaction && typeof value.compaction === 'object') {
|
|
34
|
+
facts.compaction = normalizeCompaction(value.compaction);
|
|
35
|
+
}
|
|
36
|
+
if (estimateBytes(facts) <= maxBytes) return facts;
|
|
37
|
+
|
|
38
|
+
const files = facts.fileSettlements;
|
|
39
|
+
files.sort((left, right) => importance(left) - importance(right)
|
|
40
|
+
|| left.path.localeCompare(right.path));
|
|
41
|
+
const omitted = {
|
|
42
|
+
failureOrRecovery: Number(facts.compaction?.omittedFileSettlements?.failureOrRecovery || 0),
|
|
43
|
+
changed: Number(facts.compaction?.omittedFileSettlements?.changed || 0),
|
|
44
|
+
unchangedOrUnknown: Number(facts.compaction?.omittedFileSettlements?.unchangedOrUnknown || 0)
|
|
45
|
+
};
|
|
46
|
+
facts.compaction = {
|
|
47
|
+
...(facts.compaction || {}),
|
|
48
|
+
omittedFileSettlements: omitted,
|
|
49
|
+
omittedFailures: Number(facts.compaction?.omittedFailures || 0)
|
|
50
|
+
};
|
|
51
|
+
while (files.length && estimateBytes(facts) > maxBytes) {
|
|
52
|
+
omitted[category(files.shift())]++;
|
|
53
|
+
}
|
|
54
|
+
facts.fileSettlements = files.sort((left, right) => left.path.localeCompare(right.path));
|
|
55
|
+
if (estimateBytes(facts) > maxBytes) {
|
|
56
|
+
const primaryFailure = selectPrimaryFailure(facts.failures);
|
|
57
|
+
facts.failures = facts.failures.map(compactFailure);
|
|
58
|
+
if (primaryFailure) {
|
|
59
|
+
const primaryIndex = facts.failures.findIndex(item =>
|
|
60
|
+
item.code === primaryFailure.code
|
|
61
|
+
&& item.stage === primaryFailure.stage
|
|
62
|
+
&& item.severity === primaryFailure.severity
|
|
63
|
+
&& item.file === primaryFailure.file
|
|
64
|
+
);
|
|
65
|
+
if (primaryIndex > 0) {
|
|
66
|
+
facts.failures.unshift(facts.failures.splice(primaryIndex, 1)[0]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
while (facts.failures.length > 1 && estimateBytes(facts) > maxBytes) {
|
|
70
|
+
facts.failures.pop();
|
|
71
|
+
facts.compaction.omittedFailures++;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return facts;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function compactSessionSettlementFacts(runs = [], options = {}) {
|
|
78
|
+
const sanitize = options.sanitize instanceof Function ? options.sanitize : cloneValue;
|
|
79
|
+
const measure = options.estimateBytes instanceof Function ? options.estimateBytes : estimateBytes;
|
|
80
|
+
const maxDetailBytes = Number.isFinite(options.maxDetailBytes)
|
|
81
|
+
? Math.max(0, options.maxDetailBytes)
|
|
82
|
+
: SESSION_SETTLEMENT_DETAIL_MAX_BYTES;
|
|
83
|
+
const entries = (Array.isArray(runs) ? runs : [])
|
|
84
|
+
.filter(run => run?.id && (
|
|
85
|
+
(run.settlement && typeof run.settlement === 'object')
|
|
86
|
+
|| (run.settlementFacts && typeof run.settlementFacts === 'object')
|
|
87
|
+
))
|
|
88
|
+
.map((run, index) => ({
|
|
89
|
+
id: run.id,
|
|
90
|
+
protected: run.status === 'running'
|
|
91
|
+
|| run.trackedChangeStatus === 'pending'
|
|
92
|
+
|| run.trackedChangeStatus === 'needs_review'
|
|
93
|
+
|| index === runs.length - 1,
|
|
94
|
+
facts: sanitize(run.settlement && typeof run.settlement === 'object'
|
|
95
|
+
? run.settlement
|
|
96
|
+
: run.settlementFacts)
|
|
97
|
+
}));
|
|
98
|
+
const detailBytes = () => entries.reduce((total, entry) =>
|
|
99
|
+
total + measure(entry.facts.fileSettlements || []), 0);
|
|
100
|
+
const candidates = [
|
|
101
|
+
...entries.filter(entry => !entry.protected),
|
|
102
|
+
...entries.filter(entry => entry.protected)
|
|
103
|
+
];
|
|
104
|
+
for (const entry of candidates) {
|
|
105
|
+
if (detailBytes() <= maxDetailBytes) break;
|
|
106
|
+
compactSettlementFileDetails(entry.facts, () => detailBytes() <= maxDetailBytes);
|
|
107
|
+
}
|
|
108
|
+
return new Map(entries.map(entry => [entry.id, entry.facts]));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function compactSettlementFileDetails(facts, budgetSatisfied) {
|
|
112
|
+
const files = Array.isArray(facts?.fileSettlements) ? [...facts.fileSettlements] : [];
|
|
113
|
+
files.sort((left, right) => importance(left) - importance(right)
|
|
114
|
+
|| String(left?.path || '').localeCompare(String(right?.path || '')));
|
|
115
|
+
const omitted = {
|
|
116
|
+
failureOrRecovery: positive(facts?.compaction?.omittedFileSettlements?.failureOrRecovery),
|
|
117
|
+
changed: positive(facts?.compaction?.omittedFileSettlements?.changed),
|
|
118
|
+
unchangedOrUnknown: positive(facts?.compaction?.omittedFileSettlements?.unchangedOrUnknown)
|
|
119
|
+
};
|
|
120
|
+
while (files.length && !budgetSatisfied()) {
|
|
121
|
+
omitted[category(files.shift())]++;
|
|
122
|
+
facts.fileSettlements = [...files].sort((left, right) =>
|
|
123
|
+
String(left?.path || '').localeCompare(String(right?.path || '')));
|
|
124
|
+
facts.compaction = { ...(facts.compaction || {}), omittedFileSettlements: omitted };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function projectRunSettlement(run = {}) {
|
|
129
|
+
const storedFacts = run.settlement && typeof run.settlement === 'object'
|
|
130
|
+
? run.settlement
|
|
131
|
+
: run.settlementFacts;
|
|
132
|
+
const facts = storedFacts && typeof storedFacts === 'object'
|
|
133
|
+
? compactSettlementFacts(storedFacts)
|
|
134
|
+
: null;
|
|
135
|
+
const primaryFailure = selectPrimaryFailure(facts?.failures || []);
|
|
136
|
+
const status = text(run.trackedChangeStatus);
|
|
137
|
+
const actionable = status === 'pending' || status === 'needs_review';
|
|
138
|
+
const terminal = status === 'accepted' || status === 'rejected';
|
|
139
|
+
const payload = run.recoveryPayload && typeof run.recoveryPayload === 'object'
|
|
140
|
+
? run.recoveryPayload
|
|
141
|
+
: run;
|
|
142
|
+
const tracked = hasItems(payload.undoTrackedChanges);
|
|
143
|
+
const anyRecovery = tracked
|
|
144
|
+
|| hasItems(payload.undoOperations)
|
|
145
|
+
|| hasItems(payload.undoBaseFiles)
|
|
146
|
+
|| hasItems(payload.undoExpectedFiles)
|
|
147
|
+
|| hasItems(payload.appliedOperations);
|
|
148
|
+
const canAccept = actionable && tracked;
|
|
149
|
+
const canUndo = !terminal
|
|
150
|
+
&& run.undoStatus !== 'applied'
|
|
151
|
+
&& (actionable ? anyRecovery : (!status && anyRecovery));
|
|
152
|
+
const failureTerminalState = normalizeTerminalState(primaryFailure?.terminalState);
|
|
153
|
+
return {
|
|
154
|
+
changedDocument: projectDocumentEffect(facts?.documentEffect, run.changedDocument),
|
|
155
|
+
primaryFailure,
|
|
156
|
+
failureTerminalState,
|
|
157
|
+
canAccept,
|
|
158
|
+
canUndo,
|
|
159
|
+
canRetry: Boolean(primaryFailure?.retryable),
|
|
160
|
+
terminalState: failureTerminalState || '',
|
|
161
|
+
actions: { accept: canAccept, undo: canUndo }
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function deriveLegacyProjection(run = {}) {
|
|
166
|
+
return projectRunSettlement({ ...run, settlement: null, settlementFacts: null });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function normalizeEvidence(value = {}) {
|
|
170
|
+
const evidence = value.evidence && typeof value.evidence === 'object' ? value.evidence : {};
|
|
171
|
+
const legacySave = value.save && typeof value.save === 'object' ? value.save : {};
|
|
172
|
+
const savedCandidate = evidence.saved
|
|
173
|
+
|| (legacySave.confidence === 'verified' ? 'verified'
|
|
174
|
+
: legacySave.confidence === 'quiet-observed' ? 'quiet-observed' : '');
|
|
175
|
+
return {
|
|
176
|
+
applied: allowed(evidence.applied, ['none', 'partial', 'complete', 'unknown'], 'unknown'),
|
|
177
|
+
readBack: allowed(evidence.readBack, ['not-attempted', 'exact', 'partial', 'mismatch', 'unavailable'], 'not-attempted'),
|
|
178
|
+
saved: allowed(savedCandidate, ['not-attempted', 'not-required', 'quiet-observed', 'verified', 'failed', 'unavailable'], 'not-attempted'),
|
|
179
|
+
mirrored: normalizeMirror(evidence.mirrored || value.mirror?.state),
|
|
180
|
+
compiled: normalizeCompile(evidence.compiled || value.compile?.state),
|
|
181
|
+
settled: allowed(evidence.settled, ['unsettled', 'partial', 'complete', 'needs-review'], 'unsettled')
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function normalizeFiles(value) {
|
|
186
|
+
return (Array.isArray(value) ? value : []).map(file => ({
|
|
187
|
+
path: safePath(file?.path),
|
|
188
|
+
operationIds: strings(file?.operationIds, 100),
|
|
189
|
+
relatedPaths: strings(file?.relatedPaths, 20).map(safePath).filter(Boolean),
|
|
190
|
+
applied: allowed(file?.applied, ['none', 'partial', 'complete', 'failed', 'unknown'],
|
|
191
|
+
file?.applied === true ? 'complete' : 'unknown'),
|
|
192
|
+
documentEffect: normalizeDocumentEffect(file?.documentEffect),
|
|
193
|
+
readBack: normalizeReadback(file?.readBack),
|
|
194
|
+
recoveryKind: allowed(file?.recoveryKind,
|
|
195
|
+
['tracked-changes', 'editor-history', 'legacy-baseline', 'mixed', 'none'], 'none'),
|
|
196
|
+
failureCodes: strings(file?.failureCodes, 40)
|
|
197
|
+
})).filter(file => file.path);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function normalizeFailures(value) {
|
|
201
|
+
return (Array.isArray(value) ? value : []).filter(item => item && typeof item === 'object')
|
|
202
|
+
.map(item => ({
|
|
203
|
+
code: text(item.code).slice(0, 120),
|
|
204
|
+
stage: text(item.stage).slice(0, 40),
|
|
205
|
+
severity: text(item.severity).slice(0, 40),
|
|
206
|
+
userMessage: text(item.userMessage).slice(0, 1000),
|
|
207
|
+
retryable: item.retryable === true,
|
|
208
|
+
nextAction: text(item.nextAction).slice(0, 1000),
|
|
209
|
+
file: safePath(item.file),
|
|
210
|
+
operationType: text(item.operationType).slice(0, 80),
|
|
211
|
+
changedDocument: item.changedDocument === true,
|
|
212
|
+
terminalState: normalizeTerminalState(item.terminalState)
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function normalizeDocumentEffect(value) {
|
|
217
|
+
return allowed(value === 'possible' ? 'possibly-changed' : text(value),
|
|
218
|
+
['unchanged', 'changed', 'possibly-changed', 'unknown'], 'unknown');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function normalizeReadback(value) {
|
|
222
|
+
if (value === 'match') return 'exact';
|
|
223
|
+
if (value === 'missing' || value === 'unknown') return 'unavailable';
|
|
224
|
+
return allowed(value, ['not-attempted', 'exact', 'mismatch', 'unavailable'], 'not-attempted');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function normalizeMirror(value) {
|
|
228
|
+
if (value === 'not_started' || !value) return 'not-attempted';
|
|
229
|
+
if (value === 'pending') return 'not-attempted';
|
|
230
|
+
return allowed(value, ['not-attempted', 'complete', 'partial', 'failed', 'unknown'], 'unknown');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function normalizeCompile(value) {
|
|
234
|
+
if (value === 'success' || value === 'completed') return 'succeeded';
|
|
235
|
+
if (value === 'not_started' || !value) return 'not-attempted';
|
|
236
|
+
return allowed(value, ['not-attempted', 'succeeded', 'failed', 'unknown'], 'unknown');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function normalizeAvailability(value = {}) {
|
|
240
|
+
return {
|
|
241
|
+
trackedChanges: value?.trackedChanges === true,
|
|
242
|
+
editorHistory: value?.editorHistory === true,
|
|
243
|
+
legacyBaseline: value?.legacyBaseline === true
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function normalizeDisposition(value = {}) {
|
|
248
|
+
return Object.fromEntries(RECOVERY_FIELDS.map(field => [
|
|
249
|
+
field, value?.[field] === 'clear' ? 'clear' : 'preserve'
|
|
250
|
+
]));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function normalizeCompaction(value = {}) {
|
|
254
|
+
const omitted = value.omittedFileSettlements || {};
|
|
255
|
+
return {
|
|
256
|
+
omittedFileSettlements: {
|
|
257
|
+
failureOrRecovery: positive(omitted.failureOrRecovery),
|
|
258
|
+
changed: positive(omitted.changed),
|
|
259
|
+
unchangedOrUnknown: positive(omitted.unchangedOrUnknown)
|
|
260
|
+
},
|
|
261
|
+
omittedFailures: positive(value.omittedFailures)
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function projectDocumentEffect(effect, legacy) {
|
|
266
|
+
if (effect === 'changed') return true;
|
|
267
|
+
if (effect === 'unchanged') return false;
|
|
268
|
+
if (effect === 'possibly-changed' || effect === 'unknown') return null;
|
|
269
|
+
return legacy === true ? true : legacy === false ? false : null;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function category(file = {}) {
|
|
273
|
+
if (file.failureCodes?.length || (file.recoveryKind && file.recoveryKind !== 'none')) return 'failureOrRecovery';
|
|
274
|
+
return file.documentEffect === 'changed' || file.documentEffect === 'possibly-changed'
|
|
275
|
+
? 'changed'
|
|
276
|
+
: 'unchangedOrUnknown';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function importance(file) {
|
|
280
|
+
const value = category(file);
|
|
281
|
+
return value === 'unchangedOrUnknown' ? 1 : value === 'changed' ? 2 : 3;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function compactFailure(item = {}) {
|
|
285
|
+
const { userMessage, nextAction, ...compact } = item;
|
|
286
|
+
return compact;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function selectPrimaryFailure(failures) {
|
|
290
|
+
return DefaultFailureReasons?.selectPrimaryFailure instanceof Function
|
|
291
|
+
? DefaultFailureReasons.selectPrimaryFailure(failures)
|
|
292
|
+
: failures[0] || null;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function normalizeTerminalState(value) {
|
|
296
|
+
return allowed(text(value), ['failed', 'blocked', 'degraded', 'needs_review'], null);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function safePath(value) {
|
|
300
|
+
const path = text(value).replace(/\\/g, '/');
|
|
301
|
+
if (!path || path.startsWith('/') || /^[A-Za-z]:\//.test(path) || path.split('/').includes('..')) return '';
|
|
302
|
+
return path.slice(0, 300);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function strings(value, limit) {
|
|
306
|
+
return (Array.isArray(value) ? value : []).map(text).filter(Boolean).slice(0, limit);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function hasItems(value) {
|
|
310
|
+
return Array.isArray(value)
|
|
311
|
+
? value.length > 0
|
|
312
|
+
: Boolean(value && typeof value === 'object' && Object.keys(value).length);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function estimateBytes(value) {
|
|
316
|
+
const serialized = JSON.stringify(value);
|
|
317
|
+
return typeof TextEncoder !== 'undefined'
|
|
318
|
+
? new TextEncoder().encode(serialized).length
|
|
319
|
+
: serialized.length * 2;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function cloneValue(value) {
|
|
323
|
+
try {
|
|
324
|
+
return JSON.parse(JSON.stringify(value));
|
|
325
|
+
} catch (_error) {
|
|
326
|
+
return {};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function allowed(value, values, fallback) {
|
|
331
|
+
return values.includes(value) ? value : fallback;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function positive(value) {
|
|
335
|
+
return Math.max(0, Number(value) || 0);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function text(value) {
|
|
339
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
RECOVERY_FIELDS,
|
|
344
|
+
SESSION_SETTLEMENT_DETAIL_MAX_BYTES,
|
|
345
|
+
SETTLEMENT_FACTS_MAX_BYTES,
|
|
346
|
+
compactSessionSettlementFacts,
|
|
347
|
+
compactSettlementFacts,
|
|
348
|
+
deriveLegacyProjection,
|
|
349
|
+
projectRunSettlement
|
|
350
|
+
};
|
|
351
|
+
});
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
(function initStorageDb(root, factory) {
|
|
2
2
|
if (typeof module === 'object' && module.exports) {
|
|
3
|
-
module.exports = factory(require('./storageRunActions'), require('./runInputQueue')
|
|
3
|
+
module.exports = factory(require('./storageRunActions'), require('./runInputQueue'),
|
|
4
|
+
require('./settlementFacts'), require('./storageSessionClaims'));
|
|
4
5
|
} else {
|
|
5
|
-
root.
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
root.CodexOverleafModuleRegistry.define('StorageDb', [
|
|
7
|
+
'StorageRunActions',
|
|
8
|
+
'RunInputQueue',
|
|
9
|
+
'SettlementFacts',
|
|
10
|
+
'StorageSessionClaims'
|
|
11
|
+
], factory);
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== 'undefined' ? globalThis : window, function storageDbFactory(StorageRunActions, RunInputQueue, SettlementFacts, StorageSessionClaims) {
|
|
8
14
|
'use strict';
|
|
9
|
-
if (!StorageRunActions?.compactRunsForStorage || !StorageRunActions?.compactRunActionPayload || !StorageRunActions?.compactProviderSnapshot || !StorageRunActions?.compactStructuredEventValue || !StorageRunActions?.hashString || !RunInputQueue?.compactForStorage) {
|
|
15
|
+
if (!StorageRunActions?.compactRunsForStorage || !StorageRunActions?.compactRunActionPayload || !StorageRunActions?.compactProviderSnapshot || !StorageRunActions?.compactStructuredEventValue || !StorageRunActions?.hashString || !RunInputQueue?.compactForStorage || !SettlementFacts?.compactSettlementFacts || !StorageSessionClaims?.createSessionClaimer) {
|
|
10
16
|
throw new Error('Codex Overleaf storage run-action helpers are unavailable.');
|
|
11
17
|
}
|
|
12
18
|
// IndexedDB versions are monotonic; v2.0 RC profiles have already opened v3.
|
|
@@ -127,6 +133,7 @@
|
|
|
127
133
|
};
|
|
128
134
|
});
|
|
129
135
|
}
|
|
136
|
+
var claimSessionsForAccount = StorageSessionClaims.createSessionClaimer(openDb, function () { return IDBKeyRange; });
|
|
130
137
|
|
|
131
138
|
function putRecord(storeName, record) {
|
|
132
139
|
return openDb().then(function (db) {
|
|
@@ -688,6 +695,12 @@
|
|
|
688
695
|
if (VALID_TRACKED_CHANGE_STATUSES[run.trackedChangeStatus] === true) {
|
|
689
696
|
compact.trackedChangeStatus = run.trackedChangeStatus;
|
|
690
697
|
}
|
|
698
|
+
var settlement = run.settlement && typeof run.settlement === 'object'
|
|
699
|
+
? run.settlement
|
|
700
|
+
: run.settlementFacts;
|
|
701
|
+
if (settlement && typeof settlement === 'object') {
|
|
702
|
+
compact.settlement = compactStructuredEventValueForStorage(SettlementFacts.compactSettlementFacts(settlement), 0);
|
|
703
|
+
}
|
|
691
704
|
return compact;
|
|
692
705
|
}
|
|
693
706
|
|
|
@@ -1325,6 +1338,7 @@
|
|
|
1325
1338
|
putRecords: putRecords,
|
|
1326
1339
|
getRecord: getRecord,
|
|
1327
1340
|
getAllByIndex: getAllByIndex,
|
|
1341
|
+
claimSessionsForAccount: claimSessionsForAccount,
|
|
1328
1342
|
deleteRecord: deleteRecord,
|
|
1329
1343
|
deleteByIndex: deleteByIndex,
|
|
1330
1344
|
clearStore: clearStore,
|