@aloth/olcli 0.13.1 → 0.15.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 +5 -1
- package/dist/cli.js +107 -5
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +103 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +317 -47
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +45 -5
- package/dist/mcp.js.map +1 -1
- package/dist/tracked-changes.d.ts +136 -0
- package/dist/tracked-changes.d.ts.map +1 -0
- package/dist/tracked-changes.js +250 -0
- package/dist/tracked-changes.js.map +1 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Read docs/ARCHITECTURE.md before changing anything in this file.
|
|
16
16
|
*/
|
|
17
|
+
import { RejectConflictError, type ShareJsTextOp, type TrackedChangeAuthor, type TrackedChangeKind } from './tracked-changes.js';
|
|
17
18
|
export interface Project {
|
|
18
19
|
id: string;
|
|
19
20
|
name: string;
|
|
@@ -94,7 +95,58 @@ export type CommentStatus = 'all' | 'open' | 'resolved';
|
|
|
94
95
|
export interface ListCommentsOptions {
|
|
95
96
|
status?: CommentStatus;
|
|
96
97
|
contextLines?: number;
|
|
98
|
+
/** Sockets used to join docs in parallel (1-8). Defaults to OLCLI_CONCURRENCY, else 4. */
|
|
99
|
+
concurrency?: number;
|
|
97
100
|
}
|
|
101
|
+
export declare const DEFAULT_COMMENT_CONCURRENCY = 4;
|
|
102
|
+
export declare const MAX_COMMENT_CONCURRENCY = 8;
|
|
103
|
+
/**
|
|
104
|
+
* Resolve the socket pool size from an explicit value, then OLCLI_CONCURRENCY,
|
|
105
|
+
* then the default. Throws on anything that is not an integer from 1 to 8.
|
|
106
|
+
*/
|
|
107
|
+
export declare function resolveCommentConcurrency(value?: number | string, env?: NodeJS.ProcessEnv): number;
|
|
108
|
+
/** A tracked change (suggested edit) with its project location. */
|
|
109
|
+
export interface TrackedChange {
|
|
110
|
+
id: string;
|
|
111
|
+
docId: string;
|
|
112
|
+
path: string;
|
|
113
|
+
kind: TrackedChangeKind;
|
|
114
|
+
/** Offset into the visible text of the doc, tracked deletes excluded. */
|
|
115
|
+
position: number;
|
|
116
|
+
line: number;
|
|
117
|
+
column: number;
|
|
118
|
+
/** Inserted text for an insert, removed text for a delete. */
|
|
119
|
+
text: string;
|
|
120
|
+
author: TrackedChangeAuthor;
|
|
121
|
+
timestamp?: string;
|
|
122
|
+
context?: CommentContext;
|
|
123
|
+
}
|
|
124
|
+
export interface ListTrackedChangesOptions {
|
|
125
|
+
contextLines?: number;
|
|
126
|
+
/** Sockets used to join docs in parallel (1-8). Defaults to OLCLI_CONCURRENCY, else 4. */
|
|
127
|
+
concurrency?: number;
|
|
128
|
+
}
|
|
129
|
+
/** Comments and tracked changes from a single pass over the project's docs. */
|
|
130
|
+
export interface ProjectReview {
|
|
131
|
+
comments: ProjectComment[];
|
|
132
|
+
changes: TrackedChange[];
|
|
133
|
+
}
|
|
134
|
+
export interface RejectionDocPlan {
|
|
135
|
+
docId: string;
|
|
136
|
+
path: string;
|
|
137
|
+
/** Doc version the plan was computed at. */
|
|
138
|
+
version: number;
|
|
139
|
+
changes: TrackedChange[];
|
|
140
|
+
/** ShareJS ops in the order they are sent, highest position first. */
|
|
141
|
+
ops: ShareJsTextOp[];
|
|
142
|
+
/** Unified diff of the doc before and after the rejection. */
|
|
143
|
+
diff: string;
|
|
144
|
+
}
|
|
145
|
+
export interface RejectionPlan {
|
|
146
|
+
changes: TrackedChange[];
|
|
147
|
+
docs: RejectionDocPlan[];
|
|
148
|
+
}
|
|
149
|
+
export { RejectConflictError };
|
|
98
150
|
export interface AddCommentOptions {
|
|
99
151
|
filePath: string;
|
|
100
152
|
content: string;
|
|
@@ -382,7 +434,58 @@ export declare class OverleafClient {
|
|
|
382
434
|
resolved_at?: string;
|
|
383
435
|
resolved_by_user_id?: string;
|
|
384
436
|
}>>;
|
|
437
|
+
/**
|
|
438
|
+
* Join every doc over a small pool of sockets. One socket cannot overlap
|
|
439
|
+
* requests: its long-poll hands an ack to whichever request polls first, so
|
|
440
|
+
* concurrent joinDoc calls on a shared session time out.
|
|
441
|
+
*
|
|
442
|
+
* The first socket must open. Extra sockets that are rate limited (HTTP 429)
|
|
443
|
+
* are dropped and the remaining sockets take over their share, down to one.
|
|
444
|
+
* After the first join failure no socket starts another join; the error is
|
|
445
|
+
* rethrown once every socket has been closed.
|
|
446
|
+
*/
|
|
447
|
+
private joinDocuments;
|
|
385
448
|
listComments(projectId: string, options?: ListCommentsOptions): Promise<ProjectComment[]>;
|
|
449
|
+
/** Comments and tracked changes from a single pass over the project's docs. */
|
|
450
|
+
listReview(projectId: string, options?: ListCommentsOptions): Promise<ProjectReview>;
|
|
451
|
+
private commentsFromDocs;
|
|
452
|
+
/**
|
|
453
|
+
* Users who made tracked changes, including people no longer on the
|
|
454
|
+
* project. Best effort: an error here only costs author names.
|
|
455
|
+
*/
|
|
456
|
+
private getChangesUsers;
|
|
457
|
+
/** Tracked changes of one joined doc, with the visible text their positions refer to. */
|
|
458
|
+
private docTrackedChanges;
|
|
459
|
+
/**
|
|
460
|
+
* List tracked changes (suggested insertions and deletions) across the
|
|
461
|
+
* project, sorted by path and position.
|
|
462
|
+
*/
|
|
463
|
+
listTrackedChanges(projectId: string, options?: ListTrackedChangesOptions): Promise<TrackedChange[]>;
|
|
464
|
+
private changesFromDocs;
|
|
465
|
+
/**
|
|
466
|
+
* Accept tracked changes: the suggested text stays and the suggestion
|
|
467
|
+
* markers go. Ids come from `listTrackedChanges`. Every id must resolve
|
|
468
|
+
* before anything is sent; changes are accepted per doc with one request
|
|
469
|
+
* each (POST /project/<id>/doc/<doc>/changes/accept, the editor's route).
|
|
470
|
+
* Afterwards the project is re-read and any id still present is an error.
|
|
471
|
+
*/
|
|
472
|
+
acceptTrackedChanges(projectId: string, ids: string[]): Promise<TrackedChange[]>;
|
|
473
|
+
private selectTrackedChanges;
|
|
474
|
+
/**
|
|
475
|
+
* Work out what rejecting `ids` would do, without writing anything:
|
|
476
|
+
* per doc the ops to send and a diff of the result. Fails with
|
|
477
|
+
* RejectConflictError if a change no longer matches the text, and refuses
|
|
478
|
+
* history-ot docs, whose rejection path is not implemented.
|
|
479
|
+
*/
|
|
480
|
+
planTrackedChangeRejection(projectId: string, ids: string[]): Promise<RejectionPlan>;
|
|
481
|
+
/**
|
|
482
|
+
* Reject tracked changes: inserted text is removed, deleted text is put
|
|
483
|
+
* back. The plan is recomputed per doc right before writing, and a doc
|
|
484
|
+
* whose version moved since `plan` was made is refused, so the user never
|
|
485
|
+
* applies something other than the preview they saw. Afterwards the
|
|
486
|
+
* project is re-read and any id still present is an error.
|
|
487
|
+
*/
|
|
488
|
+
rejectTrackedChanges(projectId: string, plan: RejectionPlan): Promise<RejectionPlan>;
|
|
386
489
|
resolveComment(projectId: string, threadId: string): Promise<ProjectComment>;
|
|
387
490
|
reopenComment(projectId: string, threadId: string): Promise<ProjectComment>;
|
|
388
491
|
deleteComment(projectId: string, threadId: string): Promise<ProjectComment>;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,OAAO,EACL,mBAAmB,EAQnB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAU9B,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,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AAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC3D,8EAA8E;QAC9E,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IAmCF;;OAEG;IACG,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAG3E"}
|
package/dist/client.js
CHANGED
|
@@ -20,12 +20,31 @@ import { dirname, join } from 'node:path';
|
|
|
20
20
|
import { fileURLToPath } from 'node:url';
|
|
21
21
|
import * as https from 'node:https';
|
|
22
22
|
import * as http from 'node:http';
|
|
23
|
+
import { RejectConflictError, buildUserDirectory, planRejection, renderRejectionDiff, describeAuthor, parseHistoryOtChanges, parseShareJsChanges } from './tracked-changes.js';
|
|
23
24
|
// Read version from package.json
|
|
24
25
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
25
26
|
const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));
|
|
26
27
|
const USER_AGENT = `olcli/${pkg.version}`;
|
|
27
28
|
const DEFAULT_BASE_URL = 'https://www.overleaf.com';
|
|
28
29
|
const RESOURCE_PATH_FAILURE_HINT = ' (Perhaps the resource file you specified does not exist in the project?)';
|
|
30
|
+
export const DEFAULT_COMMENT_CONCURRENCY = 4;
|
|
31
|
+
export const MAX_COMMENT_CONCURRENCY = 8;
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the socket pool size from an explicit value, then OLCLI_CONCURRENCY,
|
|
34
|
+
* then the default. Throws on anything that is not an integer from 1 to 8.
|
|
35
|
+
*/
|
|
36
|
+
export function resolveCommentConcurrency(value, env = process.env) {
|
|
37
|
+
const source = value ?? env.OLCLI_CONCURRENCY;
|
|
38
|
+
if (source === undefined || source === '')
|
|
39
|
+
return DEFAULT_COMMENT_CONCURRENCY;
|
|
40
|
+
const parsed = typeof source === 'number' ? source : Number(String(source).trim());
|
|
41
|
+
if (!Number.isInteger(parsed) || parsed < 1 || parsed > MAX_COMMENT_CONCURRENCY) {
|
|
42
|
+
const origin = value ?? `OLCLI_CONCURRENCY=${env.OLCLI_CONCURRENCY}`;
|
|
43
|
+
throw new Error(`Concurrency must be an integer from 1 to ${MAX_COMMENT_CONCURRENCY} (got ${origin})`);
|
|
44
|
+
}
|
|
45
|
+
return parsed;
|
|
46
|
+
}
|
|
47
|
+
export { RejectConflictError };
|
|
29
48
|
export class OverleafClient {
|
|
30
49
|
cookies;
|
|
31
50
|
csrf;
|
|
@@ -874,7 +893,9 @@ export class OverleafClient {
|
|
|
874
893
|
timeoutMs: 5000
|
|
875
894
|
});
|
|
876
895
|
if (!handshakeResponse.ok) {
|
|
877
|
-
|
|
896
|
+
const error = new Error(`Failed to open project socket: ${handshakeResponse.status}`);
|
|
897
|
+
error.status = handshakeResponse.status;
|
|
898
|
+
throw error;
|
|
878
899
|
}
|
|
879
900
|
this.applySetCookieHeaders(handshakeResponse.headers['set-cookie']);
|
|
880
901
|
const sid = handshakeResponse.body.trim().split(':')[0];
|
|
@@ -998,6 +1019,12 @@ export class OverleafClient {
|
|
|
998
1019
|
comment.op.c = this.decodeOverleafUtf8(comment.op.c);
|
|
999
1020
|
}
|
|
1000
1021
|
}
|
|
1022
|
+
for (const change of decodedRanges.changes || []) {
|
|
1023
|
+
if (typeof change?.op?.i === 'string')
|
|
1024
|
+
change.op.i = this.decodeOverleafUtf8(change.op.i);
|
|
1025
|
+
if (typeof change?.op?.d === 'string')
|
|
1026
|
+
change.op.d = this.decodeOverleafUtf8(change.op.d);
|
|
1027
|
+
}
|
|
1001
1028
|
return {
|
|
1002
1029
|
docId,
|
|
1003
1030
|
lines: decodedLines,
|
|
@@ -1685,60 +1712,99 @@ export class OverleafClient {
|
|
|
1685
1712
|
this.applySetCookieHeaders(response.headers['set-cookie']);
|
|
1686
1713
|
return response.body;
|
|
1687
1714
|
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Join every doc over a small pool of sockets. One socket cannot overlap
|
|
1717
|
+
* requests: its long-poll hands an ack to whichever request polls first, so
|
|
1718
|
+
* concurrent joinDoc calls on a shared session time out.
|
|
1719
|
+
*
|
|
1720
|
+
* The first socket must open. Extra sockets that are rate limited (HTTP 429)
|
|
1721
|
+
* are dropped and the remaining sockets take over their share, down to one.
|
|
1722
|
+
* After the first join failure no socket starts another join; the error is
|
|
1723
|
+
* rethrown once every socket has been closed.
|
|
1724
|
+
*/
|
|
1725
|
+
async joinDocuments(projectId, docs, concurrency = DEFAULT_COMMENT_CONCURRENCY) {
|
|
1726
|
+
const joined = new Array(docs.length);
|
|
1727
|
+
if (docs.length === 0)
|
|
1728
|
+
return joined;
|
|
1729
|
+
let next = 0;
|
|
1730
|
+
let failure;
|
|
1731
|
+
const work = async (session) => {
|
|
1732
|
+
try {
|
|
1733
|
+
while (failure === undefined && next < docs.length) {
|
|
1734
|
+
const index = next++;
|
|
1735
|
+
try {
|
|
1736
|
+
joined[index] = await this.joinDocument(session, docs[index].id);
|
|
1737
|
+
}
|
|
1738
|
+
catch (error) {
|
|
1739
|
+
if (failure === undefined)
|
|
1740
|
+
failure = error;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
finally {
|
|
1745
|
+
await this.closeProjectSocket(session);
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
const first = await this.openProjectSocket(projectId);
|
|
1749
|
+
const extra = Array.from({ length: Math.min(concurrency, docs.length) - 1 }, async () => {
|
|
1750
|
+
let session;
|
|
1751
|
+
try {
|
|
1752
|
+
session = await this.openProjectSocket(projectId);
|
|
1753
|
+
}
|
|
1754
|
+
catch (error) {
|
|
1755
|
+
if (error.status === 429)
|
|
1756
|
+
return;
|
|
1757
|
+
if (failure === undefined)
|
|
1758
|
+
failure = error;
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
await work(session);
|
|
1762
|
+
});
|
|
1763
|
+
await Promise.allSettled([work(first), ...extra]);
|
|
1764
|
+
if (failure !== undefined)
|
|
1765
|
+
throw failure;
|
|
1766
|
+
return joined;
|
|
1767
|
+
}
|
|
1688
1768
|
async listComments(projectId, options = {}) {
|
|
1689
|
-
const
|
|
1769
|
+
const projectInfo = await this.getProjectInfo(projectId);
|
|
1770
|
+
const docs = this.collectProjectDocs(projectInfo);
|
|
1771
|
+
const threads = await this.getCommentThreads(projectId);
|
|
1772
|
+
const joinedDocs = await this.joinDocuments(projectId, docs, resolveCommentConcurrency(options.concurrency));
|
|
1773
|
+
return this.commentsFromDocs(docs, joinedDocs, threads, options.status || 'all', options.contextLines || 0);
|
|
1774
|
+
}
|
|
1775
|
+
/** Comments and tracked changes from a single pass over the project's docs. */
|
|
1776
|
+
async listReview(projectId, options = {}) {
|
|
1690
1777
|
const contextLines = options.contextLines || 0;
|
|
1691
1778
|
const projectInfo = await this.getProjectInfo(projectId);
|
|
1692
1779
|
const docs = this.collectProjectDocs(projectInfo);
|
|
1693
1780
|
const threads = await this.getCommentThreads(projectId);
|
|
1781
|
+
const joinedDocs = await this.joinDocuments(projectId, docs, resolveCommentConcurrency(options.concurrency));
|
|
1782
|
+
return {
|
|
1783
|
+
comments: this.commentsFromDocs(docs, joinedDocs, threads, options.status || 'all', contextLines),
|
|
1784
|
+
changes: await this.changesFromDocs(projectId, projectInfo, docs, joinedDocs, contextLines)
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
commentsFromDocs(docs, joinedDocs, threads, status, contextLines) {
|
|
1694
1788
|
const comments = [];
|
|
1695
|
-
const
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
const joinedDoc = await this.joinDocument(session, doc.id);
|
|
1699
|
-
if (joinedDoc.type === 'history-ot') {
|
|
1700
|
-
for (const comment of joinedDoc.ranges.comments || []) {
|
|
1701
|
-
const ranges = comment.ranges || [];
|
|
1702
|
-
const firstRange = ranges[0];
|
|
1703
|
-
if (!firstRange)
|
|
1704
|
-
continue;
|
|
1705
|
-
const selectedText = ranges
|
|
1706
|
-
.map((range) => joinedDoc.content.slice(range.pos, range.pos + range.length))
|
|
1707
|
-
.join('');
|
|
1708
|
-
const location = this.positionToLineColumn(joinedDoc.content, firstRange.pos);
|
|
1709
|
-
const thread = threads[comment.id] || { messages: [] };
|
|
1710
|
-
const resolved = Boolean(comment.resolved || thread.resolved);
|
|
1711
|
-
comments.push({
|
|
1712
|
-
threadId: comment.id,
|
|
1713
|
-
docId: doc.id,
|
|
1714
|
-
path: doc.path,
|
|
1715
|
-
position: firstRange.pos,
|
|
1716
|
-
line: location.line,
|
|
1717
|
-
column: location.column,
|
|
1718
|
-
selectedText,
|
|
1719
|
-
resolved,
|
|
1720
|
-
messages: thread.messages || [],
|
|
1721
|
-
context: this.buildCommentContext(joinedDoc.content, location.line, contextLines)
|
|
1722
|
-
});
|
|
1723
|
-
}
|
|
1724
|
-
continue;
|
|
1725
|
-
}
|
|
1789
|
+
for (const [index, doc] of docs.entries()) {
|
|
1790
|
+
const joinedDoc = joinedDocs[index];
|
|
1791
|
+
if (joinedDoc.type === 'history-ot') {
|
|
1726
1792
|
for (const comment of joinedDoc.ranges.comments || []) {
|
|
1727
|
-
const
|
|
1728
|
-
const
|
|
1729
|
-
if (!
|
|
1793
|
+
const ranges = comment.ranges || [];
|
|
1794
|
+
const firstRange = ranges[0];
|
|
1795
|
+
if (!firstRange)
|
|
1730
1796
|
continue;
|
|
1731
|
-
const selectedText =
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
const location = this.positionToLineColumn(joinedDoc.content,
|
|
1735
|
-
const thread = threads[
|
|
1736
|
-
const resolved = Boolean(comment.resolved ||
|
|
1797
|
+
const selectedText = ranges
|
|
1798
|
+
.map((range) => joinedDoc.content.slice(range.pos, range.pos + range.length))
|
|
1799
|
+
.join('');
|
|
1800
|
+
const location = this.positionToLineColumn(joinedDoc.content, firstRange.pos);
|
|
1801
|
+
const thread = threads[comment.id] || { messages: [] };
|
|
1802
|
+
const resolved = Boolean(comment.resolved || thread.resolved);
|
|
1737
1803
|
comments.push({
|
|
1738
|
-
threadId,
|
|
1804
|
+
threadId: comment.id,
|
|
1739
1805
|
docId: doc.id,
|
|
1740
1806
|
path: doc.path,
|
|
1741
|
-
position:
|
|
1807
|
+
position: firstRange.pos,
|
|
1742
1808
|
line: location.line,
|
|
1743
1809
|
column: location.column,
|
|
1744
1810
|
selectedText,
|
|
@@ -1747,10 +1813,32 @@ export class OverleafClient {
|
|
|
1747
1813
|
context: this.buildCommentContext(joinedDoc.content, location.line, contextLines)
|
|
1748
1814
|
});
|
|
1749
1815
|
}
|
|
1816
|
+
continue;
|
|
1817
|
+
}
|
|
1818
|
+
for (const comment of joinedDoc.ranges.comments || []) {
|
|
1819
|
+
const op = comment.op || {};
|
|
1820
|
+
const threadId = op.t || comment.id;
|
|
1821
|
+
if (!threadId || typeof op.p !== 'number')
|
|
1822
|
+
continue;
|
|
1823
|
+
const selectedText = typeof op.c === 'string'
|
|
1824
|
+
? op.c
|
|
1825
|
+
: joinedDoc.content.slice(op.p, op.p + (op.c?.length || 0));
|
|
1826
|
+
const location = this.positionToLineColumn(joinedDoc.content, op.p);
|
|
1827
|
+
const thread = threads[threadId] || { messages: [] };
|
|
1828
|
+
const resolved = Boolean(comment.resolved || op.resolved || thread.resolved);
|
|
1829
|
+
comments.push({
|
|
1830
|
+
threadId,
|
|
1831
|
+
docId: doc.id,
|
|
1832
|
+
path: doc.path,
|
|
1833
|
+
position: op.p,
|
|
1834
|
+
line: location.line,
|
|
1835
|
+
column: location.column,
|
|
1836
|
+
selectedText,
|
|
1837
|
+
resolved,
|
|
1838
|
+
messages: thread.messages || [],
|
|
1839
|
+
context: this.buildCommentContext(joinedDoc.content, location.line, contextLines)
|
|
1840
|
+
});
|
|
1750
1841
|
}
|
|
1751
|
-
}
|
|
1752
|
-
finally {
|
|
1753
|
-
await this.closeProjectSocket(session);
|
|
1754
1842
|
}
|
|
1755
1843
|
return comments
|
|
1756
1844
|
.filter(comment => {
|
|
@@ -1760,6 +1848,188 @@ export class OverleafClient {
|
|
|
1760
1848
|
})
|
|
1761
1849
|
.sort((a, b) => a.path.localeCompare(b.path) || a.position - b.position);
|
|
1762
1850
|
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Users who made tracked changes, including people no longer on the
|
|
1853
|
+
* project. Best effort: an error here only costs author names.
|
|
1854
|
+
*/
|
|
1855
|
+
async getChangesUsers(projectId) {
|
|
1856
|
+
try {
|
|
1857
|
+
const response = await this.httpRequest(`${this.baseUrl}/project/${projectId}/changes/users`, {
|
|
1858
|
+
headers: this.getHeaders(),
|
|
1859
|
+
expect: 'json'
|
|
1860
|
+
});
|
|
1861
|
+
if (!response.ok || !Array.isArray(response.body))
|
|
1862
|
+
return [];
|
|
1863
|
+
return response.body;
|
|
1864
|
+
}
|
|
1865
|
+
catch {
|
|
1866
|
+
return [];
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
/** Tracked changes of one joined doc, with the visible text their positions refer to. */
|
|
1870
|
+
docTrackedChanges(joinedDoc) {
|
|
1871
|
+
if (joinedDoc.type === 'history-ot')
|
|
1872
|
+
return parseHistoryOtChanges(joinedDoc.ranges);
|
|
1873
|
+
return { changes: parseShareJsChanges(joinedDoc.ranges), visibleContent: joinedDoc.content };
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* List tracked changes (suggested insertions and deletions) across the
|
|
1877
|
+
* project, sorted by path and position.
|
|
1878
|
+
*/
|
|
1879
|
+
async listTrackedChanges(projectId, options = {}) {
|
|
1880
|
+
const projectInfo = await this.getProjectInfo(projectId);
|
|
1881
|
+
const docs = this.collectProjectDocs(projectInfo);
|
|
1882
|
+
const joinedDocs = await this.joinDocuments(projectId, docs, resolveCommentConcurrency(options.concurrency));
|
|
1883
|
+
return this.changesFromDocs(projectId, projectInfo, docs, joinedDocs, options.contextLines || 0);
|
|
1884
|
+
}
|
|
1885
|
+
async changesFromDocs(projectId, projectInfo, docs, joinedDocs, contextLines) {
|
|
1886
|
+
const perDoc = joinedDocs.map(doc => this.docTrackedChanges(doc));
|
|
1887
|
+
const anyChanges = perDoc.some(doc => doc.changes.length > 0);
|
|
1888
|
+
const users = buildUserDirectory(projectInfo, anyChanges ? await this.getChangesUsers(projectId) : []);
|
|
1889
|
+
const result = [];
|
|
1890
|
+
for (const [index, doc] of docs.entries()) {
|
|
1891
|
+
const { changes, visibleContent } = perDoc[index];
|
|
1892
|
+
for (const change of changes) {
|
|
1893
|
+
const location = this.positionToLineColumn(visibleContent, change.position);
|
|
1894
|
+
result.push({
|
|
1895
|
+
id: change.id,
|
|
1896
|
+
docId: doc.id,
|
|
1897
|
+
path: doc.path,
|
|
1898
|
+
kind: change.kind,
|
|
1899
|
+
position: change.position,
|
|
1900
|
+
line: location.line,
|
|
1901
|
+
column: location.column,
|
|
1902
|
+
text: change.text,
|
|
1903
|
+
author: describeAuthor(change.userId, users),
|
|
1904
|
+
...(change.timestamp ? { timestamp: change.timestamp } : {}),
|
|
1905
|
+
...(contextLines > 0 ? { context: this.buildCommentContext(visibleContent, location.line, contextLines) } : {})
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
return result.sort((a, b) => a.path.localeCompare(b.path) || a.position - b.position);
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Accept tracked changes: the suggested text stays and the suggestion
|
|
1913
|
+
* markers go. Ids come from `listTrackedChanges`. Every id must resolve
|
|
1914
|
+
* before anything is sent; changes are accepted per doc with one request
|
|
1915
|
+
* each (POST /project/<id>/doc/<doc>/changes/accept, the editor's route).
|
|
1916
|
+
* Afterwards the project is re-read and any id still present is an error.
|
|
1917
|
+
*/
|
|
1918
|
+
async acceptTrackedChanges(projectId, ids) {
|
|
1919
|
+
const selected = this.selectTrackedChanges(await this.listTrackedChanges(projectId), ids);
|
|
1920
|
+
const byDoc = new Map();
|
|
1921
|
+
for (const change of selected)
|
|
1922
|
+
byDoc.set(change.docId, [...(byDoc.get(change.docId) ?? []), change]);
|
|
1923
|
+
for (const [docId, changes] of byDoc) {
|
|
1924
|
+
const response = await this.httpRequest(`${this.baseUrl}/project/${projectId}/doc/${docId}/changes/accept`, {
|
|
1925
|
+
method: 'POST',
|
|
1926
|
+
headers: this.getHeaders(true),
|
|
1927
|
+
body: JSON.stringify({ change_ids: changes.map(change => change.id) }),
|
|
1928
|
+
expect: 'text'
|
|
1929
|
+
});
|
|
1930
|
+
if (!response.ok) {
|
|
1931
|
+
throw new Error(`Failed to accept tracked changes in ${changes[0].path}: ${response.status}`);
|
|
1932
|
+
}
|
|
1933
|
+
this.applySetCookieHeaders(response.headers['set-cookie']);
|
|
1934
|
+
}
|
|
1935
|
+
const after = await this.listTrackedChanges(projectId);
|
|
1936
|
+
const remaining = selected.filter(change => after.some(other => other.docId === change.docId && other.id === change.id));
|
|
1937
|
+
if (remaining.length > 0) {
|
|
1938
|
+
throw new Error(`Overleaf did not accept: ${remaining.map(change => change.id).join(', ')}`);
|
|
1939
|
+
}
|
|
1940
|
+
return selected;
|
|
1941
|
+
}
|
|
1942
|
+
selectTrackedChanges(all, ids) {
|
|
1943
|
+
const wanted = [...new Set(ids)];
|
|
1944
|
+
if (wanted.length === 0)
|
|
1945
|
+
throw new Error('No tracked change id given');
|
|
1946
|
+
const selected = [];
|
|
1947
|
+
const missing = [];
|
|
1948
|
+
for (const id of wanted) {
|
|
1949
|
+
const matches = all.filter(change => change.id === id);
|
|
1950
|
+
if (matches.length === 0)
|
|
1951
|
+
missing.push(id);
|
|
1952
|
+
else if (matches.length > 1)
|
|
1953
|
+
throw new Error(`Tracked change id ${id} is ambiguous: it occurs in ${matches.map(m => m.path).join(', ')}`);
|
|
1954
|
+
else
|
|
1955
|
+
selected.push(matches[0]);
|
|
1956
|
+
}
|
|
1957
|
+
if (missing.length > 0) {
|
|
1958
|
+
const hint = all.length === 0
|
|
1959
|
+
? ' (this project has no tracked changes; track changes requires the project owner to have an Overleaf premium plan)'
|
|
1960
|
+
: '';
|
|
1961
|
+
throw new Error(`Tracked change${missing.length === 1 ? '' : 's'} not found: ${missing.join(', ')}${hint}`);
|
|
1962
|
+
}
|
|
1963
|
+
return selected;
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Work out what rejecting `ids` would do, without writing anything:
|
|
1967
|
+
* per doc the ops to send and a diff of the result. Fails with
|
|
1968
|
+
* RejectConflictError if a change no longer matches the text, and refuses
|
|
1969
|
+
* history-ot docs, whose rejection path is not implemented.
|
|
1970
|
+
*/
|
|
1971
|
+
async planTrackedChangeRejection(projectId, ids) {
|
|
1972
|
+
const projectInfo = await this.getProjectInfo(projectId);
|
|
1973
|
+
const docs = this.collectProjectDocs(projectInfo);
|
|
1974
|
+
const joinedDocs = await this.joinDocuments(projectId, docs);
|
|
1975
|
+
const all = await this.changesFromDocs(projectId, projectInfo, docs, joinedDocs, 0);
|
|
1976
|
+
const selected = this.selectTrackedChanges(all, ids);
|
|
1977
|
+
const plans = [];
|
|
1978
|
+
for (const [index, doc] of docs.entries()) {
|
|
1979
|
+
const changes = selected.filter(change => change.docId === doc.id);
|
|
1980
|
+
if (changes.length === 0)
|
|
1981
|
+
continue;
|
|
1982
|
+
const joinedDoc = joinedDocs[index];
|
|
1983
|
+
if (joinedDoc.type !== 'sharejs-text-ot') {
|
|
1984
|
+
throw new Error(`Rejecting tracked changes is not supported for ${doc.path} (doc type ${joinedDoc.type}); nothing was changed`);
|
|
1985
|
+
}
|
|
1986
|
+
// Keep the tracker's order: filter the parsed list rather than the sorted one.
|
|
1987
|
+
const wantedIds = new Set(changes.map(change => change.id));
|
|
1988
|
+
const ordered = parseShareJsChanges(joinedDoc.ranges).filter(change => wantedIds.has(change.id));
|
|
1989
|
+
const result = planRejection(joinedDoc.content, ordered);
|
|
1990
|
+
plans.push({
|
|
1991
|
+
docId: doc.id,
|
|
1992
|
+
path: doc.path,
|
|
1993
|
+
version: joinedDoc.version,
|
|
1994
|
+
changes,
|
|
1995
|
+
ops: result.ops,
|
|
1996
|
+
diff: renderRejectionDiff(doc.path, joinedDoc.content, result.content)
|
|
1997
|
+
});
|
|
1998
|
+
}
|
|
1999
|
+
return { changes: selected, docs: plans };
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* Reject tracked changes: inserted text is removed, deleted text is put
|
|
2003
|
+
* back. The plan is recomputed per doc right before writing, and a doc
|
|
2004
|
+
* whose version moved since `plan` was made is refused, so the user never
|
|
2005
|
+
* applies something other than the preview they saw. Afterwards the
|
|
2006
|
+
* project is re-read and any id still present is an error.
|
|
2007
|
+
*/
|
|
2008
|
+
async rejectTrackedChanges(projectId, plan) {
|
|
2009
|
+
for (const docPlan of plan.docs) {
|
|
2010
|
+
const session = await this.openProjectSocket(projectId);
|
|
2011
|
+
try {
|
|
2012
|
+
const joinedDoc = await this.joinDocument(session, docPlan.docId);
|
|
2013
|
+
if (joinedDoc.version !== docPlan.version) {
|
|
2014
|
+
throw new RejectConflictError(`${docPlan.path} changed since the preview (version ${docPlan.version} -> ${joinedDoc.version}); nothing more was written, run the command again`);
|
|
2015
|
+
}
|
|
2016
|
+
await this.socketRpc(session, 'applyOtUpdate', [docPlan.docId, {
|
|
2017
|
+
doc: docPlan.docId,
|
|
2018
|
+
op: docPlan.ops,
|
|
2019
|
+
v: docPlan.version
|
|
2020
|
+
}]);
|
|
2021
|
+
}
|
|
2022
|
+
finally {
|
|
2023
|
+
await this.closeProjectSocket(session);
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
const after = await this.listTrackedChanges(projectId);
|
|
2027
|
+
const remaining = plan.changes.filter(change => after.some(other => other.docId === change.docId && other.id === change.id));
|
|
2028
|
+
if (remaining.length > 0) {
|
|
2029
|
+
throw new Error(`Overleaf did not reject: ${remaining.map(change => change.id).join(', ')}`);
|
|
2030
|
+
}
|
|
2031
|
+
return plan;
|
|
2032
|
+
}
|
|
1763
2033
|
async resolveComment(projectId, threadId) {
|
|
1764
2034
|
const comment = await this.findComment(projectId, threadId);
|
|
1765
2035
|
const response = await this.httpRequest(`${this.baseUrl}/project/${projectId}/doc/${comment.docId}/thread/${threadId}/resolve`, {
|