@dsh-mobile/mobile-remote 3.3.1 → 3.4.1-beta.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 +9 -5
- package/docs/PRIVACY-POLICY.en.md +10 -3
- package/docs/PRIVACY-POLICY.md +10 -3
- package/docs/USER-GUIDE.zh-CN.md +1 -0
- package/lib/account-usage-query.js +60 -60
- package/lib/account-usage.js +10 -10
- package/lib/api-helpers.js +109 -109
- package/lib/assistant-prefs.js +82 -59
- package/lib/auto-config.js +65 -65
- package/lib/backup.js +117 -117
- package/lib/break-reminder.js +45 -45
- package/lib/client.js +93 -93
- package/lib/config.js +234 -218
- package/lib/git-read-bundled-provider.js +12 -12
- package/lib/git-read-service.js +5 -5
- package/lib/host-compat.js +84 -84
- package/lib/http-util.js +17 -17
- package/lib/index.js +1534 -1534
- package/lib/memory/context.js +44 -44
- package/lib/memory/decay.js +93 -93
- package/lib/memory/extract.js +77 -77
- package/lib/memory/routes.js +33 -33
- package/lib/memory/store.js +196 -196
- package/lib/notify-copy.js +93 -93
- package/lib/permission-guide.js +86 -86
- package/lib/persona-cards.js +73 -65
- package/lib/phone-action-args.js +175 -0
- package/lib/phone-actions.js +227 -0
- package/lib/phone-announce.js +58 -0
- package/lib/proactive-material.js +42 -42
- package/lib/proactive.js +121 -121
- package/lib/protected-paths.js +79 -79
- package/lib/protocol.js +61 -26
- package/lib/push.js +29 -29
- package/lib/rate-limit.js +16 -16
- package/lib/relay/connector.js +246 -102
- package/lib/relay/crypto.js +15 -15
- package/lib/relay/devices.js +36 -36
- package/lib/relay/fingerprint.js +34 -34
- package/lib/relay/identity.js +26 -26
- package/lib/relay/mux.js +60 -46
- package/lib/relay/noise.js +40 -40
- package/lib/relay/on-demand.js +33 -33
- package/lib/relay/p2p.js +239 -0
- package/lib/relay/pairing.js +24 -24
- package/lib/relay/phone.js +62 -40
- package/lib/relay/serve.js +21 -21
- package/lib/relay/signal.js +69 -0
- package/lib/relay/ws-server.js +32 -32
- package/lib/reminders.js +15 -15
- package/lib/rpc-adapter.js +43 -43
- package/lib/session-list.js +31 -31
- package/lib/session-rotation.js +95 -95
- package/lib/session-title-cache.js +35 -35
- package/lib/session-title-refresh.js +51 -51
- package/lib/timeline.js +140 -140
- package/lib/turn-outline.js +104 -104
- package/package.json +3 -13
package/lib/rpc-adapter.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
6
|
import { redactPathText } from "./api-helpers.js";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
29
|
const goalRefArgs = (p) => ({ agentId: p.sessionId, ref: p.ref });
|
|
30
30
|
export const RPC_ENDPOINT_RENAMES = {
|
|
31
31
|
"session.models": "session/modelCatalog",
|
|
@@ -58,11 +58,11 @@ export const RPC_PAYLOAD_ADAPTER = {
|
|
|
58
58
|
"goal.resume": goalRefArgs,
|
|
59
59
|
"goal.complete": goalRefArgs,
|
|
60
60
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
66
|
const ENDPOINT_UNAVAILABLE_CODES = new Set([
|
|
67
67
|
"gateway/invocation-unavailable",
|
|
68
68
|
"gateway/definition-unavailable",
|
|
@@ -70,21 +70,21 @@ const ENDPOINT_UNAVAILABLE_CODES = new Set([
|
|
|
70
70
|
]);
|
|
71
71
|
export const isEndpointUnavailable = (err) => ENDPOINT_UNAVAILABLE_CODES.has(err?.code);
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
export const RPC_STREAM_METHODS = new Set(["session.control"]);
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
export const projectionOf = (control, sessionId) =>
|
|
77
77
|
control?.type === "baseline" ? control.value?.projections?.[sessionId]?.values : undefined;
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
88
|
export const rpcError = (err, fallbackCode) => {
|
|
89
89
|
const rawCode = typeof err?.code === "string" && err.code !== "" ? err.code : fallbackCode;
|
|
90
90
|
const code = rawCode === "session/not-found" ? "session-not-found" : rawCode;
|
|
@@ -95,8 +95,8 @@ export const rpcError = (err, fallbackCode) => {
|
|
|
95
95
|
: err?.name === "TimeoutError" || err?.name === "AbortError"
|
|
96
96
|
? 504
|
|
97
97
|
: err?.status ?? 400;
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
|
|
99
|
+
|
|
100
100
|
let message;
|
|
101
101
|
try {
|
|
102
102
|
message = redactPathText(err?.message ?? String(err));
|
package/lib/session-list.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
5
|
import { isVisibleConversationMessage } from "./timeline.js";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
11
|
export const sessionListSortKey = (row) => {
|
|
12
12
|
if (typeof row?.lastMessageAt === "number") return row.lastMessageAt;
|
|
13
13
|
if (typeof row?.lastActivity === "number") return row.lastActivity;
|
|
14
14
|
return typeof row?.createdAt === "number" ? row.createdAt : 0;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
export const compareSessionsForList = (a, b) => {
|
|
19
19
|
const diff = sessionListSortKey(b) - sessionListSortKey(a);
|
|
20
20
|
if (diff !== 0) return diff;
|
|
21
21
|
return String(a?.id ?? "").localeCompare(String(b?.id ?? ""));
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
export const latestMessageTimeOf = (events) => {
|
|
26
26
|
let latest = null;
|
|
27
27
|
for (const event of events ?? []) {
|
|
@@ -33,25 +33,25 @@ export const latestMessageTimeOf = (events) => {
|
|
|
33
33
|
return latest;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
export const CORPUS_FRESH_MS = 30 * 60 * 1000;
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
55
|
export const planMessageTimePrune = ({
|
|
56
56
|
messageTimeIds,
|
|
57
57
|
corpusIds,
|
|
@@ -63,15 +63,15 @@ export const planMessageTimePrune = ({
|
|
|
63
63
|
const corpus = corpusIds instanceof Set ? corpusIds : new Set(corpusIds ?? []);
|
|
64
64
|
const fresh = corpusObservedAt > 0 && corpus.size > 0 && now - corpusObservedAt <= freshMs;
|
|
65
65
|
if (!fresh) {
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
return { remove: [], misses: new Set() };
|
|
68
68
|
}
|
|
69
69
|
const nextMisses = new Set();
|
|
70
70
|
const remove = [];
|
|
71
71
|
for (const id of messageTimeIds ?? []) {
|
|
72
|
-
if (corpus.has(id)) continue;
|
|
73
|
-
if (misses.has(id)) remove.push(id);
|
|
74
|
-
else nextMisses.add(id);
|
|
72
|
+
if (corpus.has(id)) continue;
|
|
73
|
+
if (misses.has(id)) remove.push(id);
|
|
74
|
+
else nextMisses.add(id);
|
|
75
75
|
}
|
|
76
76
|
return { remove, misses: nextMisses };
|
|
77
77
|
};
|
package/lib/session-rotation.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
17
|
import { localDayKey } from "./proactive.js";
|
|
18
18
|
import { blocksToText } from "./timeline.js";
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
27
|
export function dayKey(at) {
|
|
28
28
|
const d = at instanceof Date ? at : new Date(at);
|
|
29
29
|
if (Number.isNaN(d.getTime())) return "";
|
|
30
30
|
return localDayKey(d);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
46
|
export function rotationAdvice({ lastMessageAt, now = new Date(), busy = false } = {}) {
|
|
47
47
|
const last = Number(lastMessageAt);
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
|
|
49
|
+
|
|
50
50
|
if (!Number.isFinite(last) || last <= 0) {
|
|
51
51
|
return { shouldRotate: false, reason: "unknown-last-message", idleDays: 0 };
|
|
52
52
|
}
|
|
@@ -61,13 +61,13 @@ export function rotationAdvice({ lastMessageAt, now = new Date(), busy = false }
|
|
|
61
61
|
return { shouldRotate: false, reason: "same-day", idleDays: 0 };
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
|
|
65
|
+
|
|
66
66
|
const idleDays = Math.max(1, calendarDaysBetween(lastDay, today));
|
|
67
67
|
return { shouldRotate: true, reason: "crossed-day", idleDays };
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
function calendarDaysBetween(fromKey, toKey) {
|
|
72
72
|
const [fy, fm, fd] = fromKey.split("-").map(Number);
|
|
73
73
|
const [ty, tm, td] = toKey.split("-").map(Number);
|
|
@@ -76,30 +76,30 @@ function calendarDaysBetween(fromKey, toKey) {
|
|
|
76
76
|
return Math.round((b - a) / 86_400_000);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
export const MAX_LINE_CHARS = 120;
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
export const MAX_LINES = 3;
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
103
|
export function recentUserLines(events, { limit = MAX_LINES } = {}) {
|
|
104
104
|
if (!Array.isArray(events)) return [];
|
|
105
105
|
const lines = [];
|
|
@@ -107,13 +107,13 @@ export function recentUserLines(events, { limit = MAX_LINES } = {}) {
|
|
|
107
107
|
if (ev?.type !== "user/message") continue;
|
|
108
108
|
const data = ev.data;
|
|
109
109
|
if (!data || typeof data !== "object") continue;
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
const kind = data.message?.source?.kind ?? data.source?.kind;
|
|
112
112
|
if (typeof kind === "string" && kind !== "" && kind !== "user") continue;
|
|
113
113
|
|
|
114
114
|
const text = oneLine(textOf(data));
|
|
115
115
|
if (!text) continue;
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
if (lines.includes(text)) continue;
|
|
118
118
|
lines.push(text);
|
|
119
119
|
if (lines.length > limit) lines.shift();
|
|
@@ -121,12 +121,12 @@ export function recentUserLines(events, { limit = MAX_LINES } = {}) {
|
|
|
121
121
|
return lines;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
130
|
function textOf(data) {
|
|
131
131
|
if (typeof data.text === "string") return data.text;
|
|
132
132
|
const content = data.message?.content;
|
|
@@ -134,7 +134,7 @@ function textOf(data) {
|
|
|
134
134
|
return "";
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
|
|
138
138
|
function oneLine(raw) {
|
|
139
139
|
if (typeof raw !== "string") return "";
|
|
140
140
|
const flat = raw.replace(/\s+/g, " ").trim();
|
|
@@ -142,19 +142,19 @@ function oneLine(raw) {
|
|
|
142
142
|
return flat.length > MAX_LINE_CHARS ? `${flat.slice(0, MAX_LINE_CHARS)}…` : flat;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
158
|
export function resumeBrief({ lines = [], idleDays = 1, sessionTitle = "" } = {}) {
|
|
159
159
|
const usable = (Array.isArray(lines) ? lines : []).filter(
|
|
160
160
|
(l) => typeof l === "string" && l.trim() !== "",
|
|
@@ -175,24 +175,24 @@ export function resumeBrief({ lines = [], idleDays = 1, sessionTitle = "" } = {}
|
|
|
175
175
|
].join("\n");
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
188
|
export function buildRotation({ events, lastMessageAt, now = new Date(), busy = false, sessionTitle = "" }) {
|
|
189
189
|
const advice = rotationAdvice({ lastMessageAt, now, busy });
|
|
190
190
|
const lines = recentUserLines(events);
|
|
191
191
|
return {
|
|
192
192
|
...advice,
|
|
193
193
|
lines,
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
|
|
195
|
+
|
|
196
196
|
brief: advice.shouldRotate ? resumeBrief({ lines, idleDays: advice.idleDays, sessionTitle }) : "",
|
|
197
197
|
};
|
|
198
198
|
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
12
|
|
|
13
13
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { dirname } from "node:path";
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
export const DEFAULT_MAX_ENTRIES = 1000;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
25
|
export const createTitleCache = ({ file, maxEntries = DEFAULT_MAX_ENTRIES, now = Date.now }) => {
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
const entries = new Map();
|
|
28
28
|
let dirty = false;
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
34
|
const load = () => {
|
|
35
35
|
entries.clear();
|
|
36
36
|
dirty = false;
|
|
@@ -44,7 +44,7 @@ export const createTitleCache = ({ file, maxEntries = DEFAULT_MAX_ENTRIES, now =
|
|
|
44
44
|
if (id === "") continue;
|
|
45
45
|
if (!value || typeof value !== "object" || Array.isArray(value)) continue;
|
|
46
46
|
if (typeof value.revision !== "string" || value.revision === "") continue;
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
if (value.title !== null && typeof value.title !== "string") continue;
|
|
49
49
|
const title = value.title === "" ? null : value.title;
|
|
50
50
|
entries.set(id, { title, revision: value.revision, at: typeof value.at === "number" ? value.at : 0 });
|
|
@@ -55,24 +55,24 @@ export const createTitleCache = ({ file, maxEntries = DEFAULT_MAX_ENTRIES, now =
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
63
|
const get = (id, revision) => {
|
|
64
64
|
if (typeof id !== "string" || id === "" || typeof revision !== "string" || revision === "") {
|
|
65
65
|
return { hit: false };
|
|
66
66
|
}
|
|
67
67
|
const entry = entries.get(id);
|
|
68
68
|
if (!entry || entry.revision !== revision) return { hit: false };
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
entry.at = now();
|
|
71
71
|
dirty = true;
|
|
72
72
|
return { hit: true, title: entry.title };
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
const set = (id, revision, title) => {
|
|
77
77
|
if (typeof id !== "string" || id === "" || typeof revision !== "string" || revision === "") return;
|
|
78
78
|
entries.set(id, {
|
|
@@ -84,7 +84,7 @@ export const createTitleCache = ({ file, maxEntries = DEFAULT_MAX_ENTRIES, now =
|
|
|
84
84
|
prune();
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
const prune = () => {
|
|
89
89
|
if (entries.size <= maxEntries) return;
|
|
90
90
|
const sorted = [...entries.entries()].sort((a, b) => a[1].at - b[1].at);
|
|
@@ -95,7 +95,7 @@ export const createTitleCache = ({ file, maxEntries = DEFAULT_MAX_ENTRIES, now =
|
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
const flush = () => {
|
|
100
100
|
if (!dirty) return false;
|
|
101
101
|
try {
|
|
@@ -106,7 +106,7 @@ export const createTitleCache = ({ file, maxEntries = DEFAULT_MAX_ENTRIES, now =
|
|
|
106
106
|
dirty = false;
|
|
107
107
|
return true;
|
|
108
108
|
} catch {
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
return false;
|
|
111
111
|
}
|
|
112
112
|
};
|
|
@@ -117,7 +117,7 @@ export const createTitleCache = ({ file, maxEntries = DEFAULT_MAX_ENTRIES, now =
|
|
|
117
117
|
set,
|
|
118
118
|
flush,
|
|
119
119
|
size: () => entries.size,
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
peek: (id) => entries.get(id),
|
|
122
122
|
};
|
|
123
123
|
};
|