@dreamlake/dreamlake-cli 0.104.8 → 0.105.1
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/dist/api/index.d.ts +27 -17
- package/dist/api/index.js +25 -16
- package/dist/api/memo-character-plan.d.ts +2 -0
- package/dist/api/memo-character-plan.js +2 -0
- package/dist/api/memo-editing.d.ts +2 -0
- package/dist/api/memo-editing.js +2 -0
- package/dist/api/memo-edits.d.ts +63 -0
- package/dist/api/memo-edits.js +206 -0
- package/dist/api/memo-events.d.ts +44 -0
- package/dist/api/memo-events.js +65 -0
- package/dist/api/memo-facade.d.ts +294 -0
- package/dist/api/memo-facade.js +382 -0
- package/dist/api/memo-files.d.ts +111 -0
- package/dist/api/memo-files.js +110 -0
- package/dist/api/memo-html-read.d.ts +2 -0
- package/dist/api/memo-html-read.js +2 -0
- package/dist/api/memo-html.d.ts +2 -0
- package/dist/api/memo-html.js +2 -0
- package/dist/api/memo-linger.d.ts +85 -0
- package/dist/api/memo-linger.js +271 -0
- package/dist/api/memo-presence.d.ts +109 -0
- package/dist/api/memo-presence.js +75 -0
- package/dist/api/memo-reading.d.ts +55 -0
- package/dist/api/memo-reading.js +43 -0
- package/dist/api/memo-toc.d.ts +2 -0
- package/dist/api/memo-toc.js +2 -0
- package/dist/api/memo-write.d.ts +119 -0
- package/dist/api/memo-write.js +221 -0
- package/dist/api/memos.d.ts +344 -0
- package/dist/api/memos.js +231 -0
- package/dist/api/note-character-plan.d.ts +2 -2
- package/dist/api/note-character-plan.js +2 -2
- package/dist/api/note-editing.d.ts +2 -2
- package/dist/api/note-editing.js +2 -2
- package/dist/api/note-edits.d.ts +2 -59
- package/dist/api/note-edits.js +2 -205
- package/dist/api/note-events.d.ts +2 -41
- package/dist/api/note-events.js +2 -64
- package/dist/api/note-facade.d.ts +2 -268
- package/dist/api/note-facade.js +2 -376
- package/dist/api/note-files.d.ts +2 -102
- package/dist/api/note-files.js +2 -107
- package/dist/api/note-html-read.d.ts +2 -2
- package/dist/api/note-html-read.js +2 -2
- package/dist/api/note-html.d.ts +2 -2
- package/dist/api/note-html.js +2 -2
- package/dist/api/note-linger.d.ts +2 -83
- package/dist/api/note-linger.js +2 -270
- package/dist/api/note-presence.d.ts +2 -100
- package/dist/api/note-presence.js +2 -73
- package/dist/api/note-reading.d.ts +2 -51
- package/dist/api/note-reading.js +2 -42
- package/dist/api/note-toc.d.ts +2 -2
- package/dist/api/note-toc.js +2 -2
- package/dist/api/note-write.d.ts +2 -110
- package/dist/api/note-write.js +2 -217
- package/dist/api/notes.d.ts +2 -335
- package/dist/api/notes.js +2 -230
- package/dist/api/open-resources.js +3 -3
- package/dist/cli/folders/index.d.ts +1 -1
- package/dist/cli/folders/index.js +4 -4
- package/dist/cli/help-examples.generated.js +6 -6
- package/dist/cli/index.js +2 -2
- package/dist/cli/{notes → memos}/api-transport.d.ts +1 -1
- package/dist/cli/{notes → memos}/api-transport.js +1 -1
- package/dist/cli/{notes → memos}/archive-command.d.ts +1 -1
- package/dist/cli/{notes → memos}/archive-command.js +5 -5
- package/dist/cli/{notes → memos}/character-plan.d.ts +3 -1
- package/dist/cli/{notes → memos}/character-plan.js +7 -5
- package/dist/cli/{notes → memos}/document.d.ts +9 -9
- package/dist/cli/{notes → memos}/document.js +12 -12
- package/dist/cli/{notes → memos}/edit-commands.d.ts +8 -8
- package/dist/cli/{notes → memos}/edit-commands.js +14 -14
- package/dist/cli/{notes → memos}/events.d.ts +3 -3
- package/dist/cli/{notes → memos}/events.js +2 -2
- package/dist/cli/{notes → memos}/files-commands.d.ts +2 -2
- package/dist/cli/{notes → memos}/files-commands.js +5 -5
- package/dist/cli/{notes → memos}/index.d.ts +16 -16
- package/dist/cli/{notes → memos}/index.js +53 -53
- package/dist/cli/{notes → memos}/linger.d.ts +3 -3
- package/dist/cli/{notes → memos}/linger.js +5 -5
- package/dist/cli/{notes → memos}/move-command.d.ts +5 -5
- package/dist/cli/{notes → memos}/move-command.js +6 -6
- package/dist/cli/{notes → memos}/rm-command.d.ts +2 -2
- package/dist/cli/{notes → memos}/rm-command.js +2 -2
- package/dist/cli/{notes → memos}/select-command.d.ts +1 -1
- package/dist/cli/{notes → memos}/select-command.js +4 -4
- package/dist/cli/{notes → memos}/suggest-diff.d.ts +1 -1
- package/dist/cli/{notes → memos}/suggest-diff.js +2 -2
- package/dist/cli/{notes → memos}/transfer-command.d.ts +2 -2
- package/dist/cli/{notes → memos}/transfer-command.js +2 -2
- package/dist/cli/share.d.ts +1 -1
- package/dist/cli/share.js +1 -1
- package/dist/cli/skill/index.js +1 -1
- package/dist/cli/update/index.js +3 -3
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +9 -9
- /package/dist/cli/{notes → memos}/editing.d.ts +0 -0
- /package/dist/cli/{notes → memos}/editing.js +0 -0
- /package/dist/cli/{notes → memos}/html-read.d.ts +0 -0
- /package/dist/cli/{notes → memos}/html-read.js +0 -0
- /package/dist/cli/{notes → memos}/html.d.ts +0 -0
- /package/dist/cli/{notes → memos}/html.js +0 -0
- /package/dist/cli/{notes → memos}/media-commands.d.ts +0 -0
- /package/dist/cli/{notes → memos}/media-commands.js +0 -0
- /package/dist/cli/{notes → memos}/toc.d.ts +0 -0
- /package/dist/cli/{notes → memos}/toc.js +0 -0
- /package/dist/cli/{notes → memos}/version-commands.d.ts +0 -0
- /package/dist/cli/{notes → memos}/version-commands.js +0 -0
|
@@ -1,83 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface NoteLingerOptions {
|
|
4
|
-
signal: AbortSignal;
|
|
5
|
-
format?: 'diff' | 'inline-dff';
|
|
6
|
-
debounce?: string;
|
|
7
|
-
throttle?: string;
|
|
8
|
-
ifMatch?: string;
|
|
9
|
-
intent?: string;
|
|
10
|
-
}
|
|
11
|
-
export type NoteLingerEvent = ({
|
|
12
|
-
type: 'snapshot';
|
|
13
|
-
observedAt: number;
|
|
14
|
-
selectionHash: string;
|
|
15
|
-
participants: Participant[];
|
|
16
|
-
} & LingerRead) | {
|
|
17
|
-
type: 'update';
|
|
18
|
-
observedAt: number;
|
|
19
|
-
content?: LingerRead;
|
|
20
|
-
joined: Participant[];
|
|
21
|
-
left: Participant[];
|
|
22
|
-
activities: Activity[];
|
|
23
|
-
selections: (Participant & {
|
|
24
|
-
hash: string;
|
|
25
|
-
})[];
|
|
26
|
-
};
|
|
27
|
-
export declare const LINGER_BATCH_MS = 2000;
|
|
28
|
-
/** Durations are bounded to avoid accidental busy loops or effectively silent sessions. */
|
|
29
|
-
export declare function lingerDuration(value: string | undefined, option: string): number;
|
|
30
|
-
export interface Activity {
|
|
31
|
-
id: string;
|
|
32
|
-
agent: {
|
|
33
|
-
id: string;
|
|
34
|
-
name: string;
|
|
35
|
-
owner: string;
|
|
36
|
-
};
|
|
37
|
-
kind: "read" | "insert";
|
|
38
|
-
scope: string;
|
|
39
|
-
hash: string;
|
|
40
|
-
ranges: {
|
|
41
|
-
start: number;
|
|
42
|
-
end: number;
|
|
43
|
-
}[];
|
|
44
|
-
at: number;
|
|
45
|
-
expiresAt: number;
|
|
46
|
-
}
|
|
47
|
-
export interface LingerRead {
|
|
48
|
-
note: string;
|
|
49
|
-
hash: string;
|
|
50
|
-
revision: string;
|
|
51
|
-
content?: string;
|
|
52
|
-
base?: string;
|
|
53
|
-
patch?: string;
|
|
54
|
-
format?: string;
|
|
55
|
-
}
|
|
56
|
-
interface Observation {
|
|
57
|
-
body: LingerRead;
|
|
58
|
-
participants: Participant[];
|
|
59
|
-
activities: Activity[];
|
|
60
|
-
}
|
|
61
|
-
export interface LingerRuntime {
|
|
62
|
-
signal?: AbortSignal;
|
|
63
|
-
events?: typeof readNoteEvents;
|
|
64
|
-
now(): number;
|
|
65
|
-
wait(ms: number, signal: AbortSignal): Promise<void>;
|
|
66
|
-
}
|
|
67
|
-
/** Stable activity fingerprints suppress renewed read/typing observations each poll. */
|
|
68
|
-
export declare class LingerBatch {
|
|
69
|
-
private readonly self;
|
|
70
|
-
private participants;
|
|
71
|
-
private activity;
|
|
72
|
-
private selections;
|
|
73
|
-
constructor(initial: Observation, self: string);
|
|
74
|
-
others(rows: Participant[]): Participant[];
|
|
75
|
-
diff(next: Observation): {
|
|
76
|
-
joined: Participant[];
|
|
77
|
-
left: Participant[];
|
|
78
|
-
activities: Activity[];
|
|
79
|
-
selections: Participant[];
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
export declare function watchNote(t: Transport, path: string, id: string, opts: NoteLingerOptions, receive: (event: NoteLingerEvent) => void | Promise<void>, clock?: LingerRuntime): Promise<void>;
|
|
83
|
-
export {};
|
|
1
|
+
/** @deprecated Import the canonical Memo module. */
|
|
2
|
+
export * from "./memo-linger.js";
|
package/dist/api/note-linger.js
CHANGED
|
@@ -1,270 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
-
import { readNoteEvents } from './note-events.js';
|
|
5
|
-
import { notePresenceIntent as presenceIntent } from './note-presence.js';
|
|
6
|
-
export const LINGER_BATCH_MS = 2000;
|
|
7
|
-
/** Durations are bounded to avoid accidental busy loops or effectively silent sessions. */
|
|
8
|
-
export function lingerDuration(value, option) {
|
|
9
|
-
if (value === undefined)
|
|
10
|
-
return LINGER_BATCH_MS;
|
|
11
|
-
const match = /^(\d+(?:\.\d+)?)(ms|s|m)$/.exec(value);
|
|
12
|
-
const ms = match ? Number(match[1]) * ({ ms: 1, s: 1000, m: 60000 }[match[2]] ?? 0) : NaN;
|
|
13
|
-
if (!Number.isFinite(ms) || ms < 250 || ms > 300000)
|
|
14
|
-
throw new Error(`${option} requires a duration from 250ms to 5m (for example 500ms or 2s)`);
|
|
15
|
-
return ms;
|
|
16
|
-
}
|
|
17
|
-
const HEARTBEAT_MS = 20_000;
|
|
18
|
-
const runtime = {
|
|
19
|
-
now: Date.now,
|
|
20
|
-
wait: async (ms, signal) => { await delay(ms, undefined, { signal }); },
|
|
21
|
-
};
|
|
22
|
-
/** Stable activity fingerprints suppress renewed read/typing observations each poll. */
|
|
23
|
-
export class LingerBatch {
|
|
24
|
-
self;
|
|
25
|
-
participants = new Map();
|
|
26
|
-
activity = new Map();
|
|
27
|
-
selections = new Map();
|
|
28
|
-
constructor(initial, self) {
|
|
29
|
-
this.self = self;
|
|
30
|
-
this.diff(initial);
|
|
31
|
-
}
|
|
32
|
-
others(rows) { return rows.filter(p => p.user.id !== this.self); }
|
|
33
|
-
diff(next) {
|
|
34
|
-
const current = new Map(this.others(next.participants).map(p => [p.client, p]));
|
|
35
|
-
const joined = [...current].filter(([id]) => !this.participants.has(id)).map(([, p]) => p);
|
|
36
|
-
const left = [...this.participants].filter(([id]) => !current.has(id)).map(([, p]) => p);
|
|
37
|
-
const selections = [...current.values()].flatMap(p => {
|
|
38
|
-
const fingerprint = JSON.stringify(p.selection ?? null);
|
|
39
|
-
const changed = this.selections.get(p.client) !== fingerprint;
|
|
40
|
-
this.selections.set(p.client, fingerprint);
|
|
41
|
-
return changed && (p.selection || this.participants.has(p.client)) ? [p] : [];
|
|
42
|
-
});
|
|
43
|
-
for (const p of left) {
|
|
44
|
-
this.selections.delete(p.client);
|
|
45
|
-
selections.push({ ...p, selection: null });
|
|
46
|
-
}
|
|
47
|
-
this.participants = current;
|
|
48
|
-
const seen = new Map();
|
|
49
|
-
const activities = next.activities.filter(a => {
|
|
50
|
-
if (`agent:${a.agent.owner}:${a.agent.id}` === this.self)
|
|
51
|
-
return false;
|
|
52
|
-
const key = `${a.agent.owner}:${a.agent.id}:${a.kind}`;
|
|
53
|
-
const fingerprint = JSON.stringify([a.hash, a.scope, a.ranges]);
|
|
54
|
-
seen.set(key, fingerprint);
|
|
55
|
-
return this.activity.get(key) !== fingerprint;
|
|
56
|
-
});
|
|
57
|
-
this.activity = seen;
|
|
58
|
-
return { joined, left, activities, selections };
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
export async function watchNote(t, path, id, opts, receive, clock = { ...runtime, signal: opts.signal }) {
|
|
62
|
-
const format = opts.format ?? 'diff';
|
|
63
|
-
if (!['diff', 'inline-dff'].includes(format))
|
|
64
|
-
throw new Error('--format must be diff or inline-dff');
|
|
65
|
-
if (opts.ifMatch !== undefined && (!opts.ifMatch.trim() || opts.ifMatch === '*' || /[\r\n]/.test(opts.ifMatch)))
|
|
66
|
-
throw new Error('--if-match requires an exact saved revision');
|
|
67
|
-
let debounce, throttle, intent;
|
|
68
|
-
try {
|
|
69
|
-
debounce = lingerDuration(opts.debounce, '--debounce');
|
|
70
|
-
throttle = lingerDuration(opts.throttle, '--throttle');
|
|
71
|
-
intent = presenceIntent(opts.intent);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
const abort = new AbortController();
|
|
77
|
-
const stop = () => abort.abort();
|
|
78
|
-
clock.signal?.addEventListener('abort', stop, { once: true });
|
|
79
|
-
if (clock.signal?.aborted)
|
|
80
|
-
stop();
|
|
81
|
-
let leave;
|
|
82
|
-
let streaming;
|
|
83
|
-
let failure;
|
|
84
|
-
try {
|
|
85
|
-
if (abort.signal.aborted)
|
|
86
|
-
return;
|
|
87
|
-
const request = (suffix, extra = {}) => {
|
|
88
|
-
const { method, ...options } = extra;
|
|
89
|
-
return t.request(method ?? 'GET', path + suffix, {
|
|
90
|
-
signal: abort.signal, timeoutMs: 30000, redirect: 'error', ...options,
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
// Install cleanup before join: a lost join response may still have created a lease.
|
|
94
|
-
leave = () => t.request('POST', path + '/presence', {
|
|
95
|
-
json: { action: 'leave' }, timeoutMs: 5000, redirect: 'error',
|
|
96
|
-
});
|
|
97
|
-
// Intent rides the join only; heartbeats omit the field, which preserves it.
|
|
98
|
-
const joined = await request('/presence', { method: 'POST', json: { action: 'join', ...(intent ? { intent } : {}) } });
|
|
99
|
-
if (typeof joined?.state?.user?.id !== 'string')
|
|
100
|
-
throw new Error('server did not return an agent presence session');
|
|
101
|
-
const self = joined.state.user.id;
|
|
102
|
-
let heartbeat = clock.now();
|
|
103
|
-
let latest, sequence = 0, handled = -1, streamError;
|
|
104
|
-
let wake = new AbortController();
|
|
105
|
-
const wait = async (ms) => {
|
|
106
|
-
wake = new AbortController();
|
|
107
|
-
try {
|
|
108
|
-
await clock.wait(ms, AbortSignal.any([abort.signal, wake.signal]));
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
if (!wake.signal.aborted && !abort.signal.aborted)
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
streaming = (clock.events ?? readNoteEvents)(path + '/events', '', id, abort.signal, event => {
|
|
116
|
-
latest = event;
|
|
117
|
-
sequence++;
|
|
118
|
-
wake.abort();
|
|
119
|
-
}, async (_url, options) => {
|
|
120
|
-
if (!t.raw)
|
|
121
|
-
throw new Error('transport_does_not_support_streaming');
|
|
122
|
-
return t.raw('GET', path + '/events', { headers: options?.headers, signal: options?.signal, timeoutMs: null, redirect: 'error' });
|
|
123
|
-
}).then(() => {
|
|
124
|
-
if (!abort.signal.aborted)
|
|
125
|
-
streamError = new Error('Memos event stream disconnected');
|
|
126
|
-
wake.abort();
|
|
127
|
-
}, error => { streamError = error; wake.abort(); });
|
|
128
|
-
while (!latest && !streamError && !abort.signal.aborted)
|
|
129
|
-
await wait(45000);
|
|
130
|
-
if (abort.signal.aborted)
|
|
131
|
-
return;
|
|
132
|
-
if (streamError)
|
|
133
|
-
throw streamError;
|
|
134
|
-
const readBody = async (previous) => {
|
|
135
|
-
const query = new URLSearchParams({ contract: 'v2' });
|
|
136
|
-
if (previous) {
|
|
137
|
-
query.set('since', previous.hash);
|
|
138
|
-
query.set('format', format);
|
|
139
|
-
}
|
|
140
|
-
const body = await request('/body?' + query, { headers: !previous && opts.ifMatch ? { 'If-Match': opts.ifMatch } : {} });
|
|
141
|
-
if (body.note !== id || !/^sha256:[a-f0-9]{64}$/.test(body.hash ?? '') || typeof body.revision !== 'string' || !body.revision || /[\r\n]/.test(body.revision))
|
|
142
|
-
throw new Error('invalid Memos v2 snapshot');
|
|
143
|
-
if (!previous) {
|
|
144
|
-
if (typeof body.content !== 'string' || 'sha256:' + createHash('sha256').update(body.content).digest('hex') !== body.hash)
|
|
145
|
-
throw new Error('source does not match the returned hash');
|
|
146
|
-
if (opts.ifMatch && body.revision !== opts.ifMatch)
|
|
147
|
-
throw new Error('memo changed since the acknowledged revision');
|
|
148
|
-
}
|
|
149
|
-
else if (body.base !== previous.hash || body.format !== format || typeof body.patch !== 'string') {
|
|
150
|
-
throw new Error('invalid incremental Memos v2 response');
|
|
151
|
-
}
|
|
152
|
-
return body;
|
|
153
|
-
};
|
|
154
|
-
const readActivities = async () => {
|
|
155
|
-
const feed = await request('/agent-activity');
|
|
156
|
-
if (!Array.isArray(feed?.activities))
|
|
157
|
-
throw new Error('server does not support activity reads');
|
|
158
|
-
return feed.activities;
|
|
159
|
-
};
|
|
160
|
-
const initialEvent = latest;
|
|
161
|
-
handled = sequence;
|
|
162
|
-
let initial = { body: await readBody(), participants: initialEvent.participants, activities: await readActivities() };
|
|
163
|
-
if (abort.signal.aborted)
|
|
164
|
-
return;
|
|
165
|
-
if (streamError)
|
|
166
|
-
throw streamError;
|
|
167
|
-
let previous = initial.body;
|
|
168
|
-
let observedActivities = initial.activities;
|
|
169
|
-
const batches = new LingerBatch(initial, self);
|
|
170
|
-
await receive({ type: 'snapshot', observedAt: clock.now(), ...initial.body, selectionHash: initialEvent.hash, participants: batches.others(initial.participants) });
|
|
171
|
-
// Release the full initial source rather than holding it through the entire session.
|
|
172
|
-
previous = { note: previous.note, hash: previous.hash, revision: previous.revision };
|
|
173
|
-
initial = undefined;
|
|
174
|
-
let observedHash = initialEvent.hash;
|
|
175
|
-
let activityVersion = initialEvent.activityVersion;
|
|
176
|
-
let lastEditAt = clock.now(), lastOutputAt = clock.now();
|
|
177
|
-
let dirtyContent = initialEvent.hash !== previous.hash;
|
|
178
|
-
const arrivals = new Map(), departures = new Map();
|
|
179
|
-
const activity = new Map();
|
|
180
|
-
const selections = new Map();
|
|
181
|
-
while (!abort.signal.aborted) {
|
|
182
|
-
if (streamError)
|
|
183
|
-
throw streamError;
|
|
184
|
-
if (sequence !== handled) {
|
|
185
|
-
handled = sequence;
|
|
186
|
-
const event = latest;
|
|
187
|
-
if (event.hash !== observedHash) {
|
|
188
|
-
observedHash = event.hash;
|
|
189
|
-
lastEditAt = clock.now();
|
|
190
|
-
dirtyContent = true;
|
|
191
|
-
}
|
|
192
|
-
if (event.activityVersion !== activityVersion)
|
|
193
|
-
observedActivities = await readActivities();
|
|
194
|
-
const delta = batches.diff({ body: previous, participants: event.participants, activities: observedActivities });
|
|
195
|
-
activityVersion = event.activityVersion;
|
|
196
|
-
for (const p of delta.joined) {
|
|
197
|
-
if (!departures.delete(p.client))
|
|
198
|
-
arrivals.set(p.client, p);
|
|
199
|
-
}
|
|
200
|
-
for (const p of delta.left) {
|
|
201
|
-
if (!arrivals.delete(p.client))
|
|
202
|
-
departures.set(p.client, p);
|
|
203
|
-
}
|
|
204
|
-
for (const p of delta.selections)
|
|
205
|
-
selections.set(p.client, p);
|
|
206
|
-
for (const a of delta.activities)
|
|
207
|
-
activity.set(`${a.agent.owner}:${a.agent.id}:${a.kind}`, a);
|
|
208
|
-
}
|
|
209
|
-
if (clock.now() - heartbeat >= HEARTBEAT_MS) {
|
|
210
|
-
await request('/presence', { method: 'POST', json: { action: 'heartbeat' } });
|
|
211
|
-
heartbeat = clock.now();
|
|
212
|
-
}
|
|
213
|
-
const now = clock.now();
|
|
214
|
-
const deliverContent = dirtyContent && now - lastEditAt >= debounce;
|
|
215
|
-
if (now - lastOutputAt >= throttle && (deliverContent || arrivals.size || departures.size || activity.size || selections.size)) {
|
|
216
|
-
const nextBody = deliverContent ? await readBody(previous) : undefined;
|
|
217
|
-
if (abort.signal.aborted)
|
|
218
|
-
break;
|
|
219
|
-
if (streamError)
|
|
220
|
-
throw streamError;
|
|
221
|
-
// A source event arriving during the read needs its own quiet period.
|
|
222
|
-
if (sequence !== handled && latest.hash !== observedHash)
|
|
223
|
-
continue;
|
|
224
|
-
const events = { joined: [...arrivals.values()], left: [...departures.values()], activities: [...activity.values()],
|
|
225
|
-
selections: [...selections.values()].map(p => ({ ...p, hash: observedHash })) };
|
|
226
|
-
await receive({ type: 'update', observedAt: clock.now(), ...(nextBody ? { content: nextBody } : {}), ...events });
|
|
227
|
-
lastOutputAt = clock.now();
|
|
228
|
-
arrivals.clear();
|
|
229
|
-
departures.clear();
|
|
230
|
-
activity.clear();
|
|
231
|
-
selections.clear();
|
|
232
|
-
if (nextBody) {
|
|
233
|
-
previous = { note: nextBody.note, hash: nextBody.hash, revision: nextBody.revision };
|
|
234
|
-
dirtyContent = false;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if (sequence !== handled)
|
|
238
|
-
continue;
|
|
239
|
-
const deadlines = [heartbeat + HEARTBEAT_MS];
|
|
240
|
-
if (arrivals.size || departures.size || activity.size || selections.size)
|
|
241
|
-
deadlines.push(lastOutputAt + throttle);
|
|
242
|
-
if (dirtyContent)
|
|
243
|
-
deadlines.push(Math.max(lastEditAt + debounce, lastOutputAt + throttle));
|
|
244
|
-
await wait(Math.max(1, Math.min(...deadlines) - clock.now()));
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
catch (error) {
|
|
248
|
-
if (!abort.signal.aborted) {
|
|
249
|
-
failure = error;
|
|
250
|
-
throw error;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
finally {
|
|
254
|
-
abort.abort();
|
|
255
|
-
await streaming;
|
|
256
|
-
try {
|
|
257
|
-
if (leave)
|
|
258
|
-
await leave();
|
|
259
|
-
}
|
|
260
|
-
catch (error) {
|
|
261
|
-
if (failure instanceof Error)
|
|
262
|
-
Object.assign(failure, { cleanupError: error });
|
|
263
|
-
else
|
|
264
|
-
throw error;
|
|
265
|
-
}
|
|
266
|
-
finally {
|
|
267
|
-
clock.signal?.removeEventListener('abort', stop);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
1
|
+
/** @deprecated Import the canonical Memo module. */
|
|
2
|
+
export * from "./memo-linger.js";
|
|
@@ -1,100 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
import { type NoteEvent, type Participant } from './note-events.js';
|
|
4
|
-
export interface NoteRange {
|
|
5
|
-
start: number;
|
|
6
|
-
end: number;
|
|
7
|
-
}
|
|
8
|
-
export interface NotePresenceRoster {
|
|
9
|
-
participants: Participant[];
|
|
10
|
-
observedAt: number;
|
|
11
|
-
}
|
|
12
|
-
export interface NoteContributorsPage {
|
|
13
|
-
sessions: {
|
|
14
|
-
id: string;
|
|
15
|
-
name: string;
|
|
16
|
-
namespaceSlug: string;
|
|
17
|
-
contribution: {
|
|
18
|
-
kind: 'created' | 'edited';
|
|
19
|
-
firstAt: string;
|
|
20
|
-
lastAt: string;
|
|
21
|
-
} | null;
|
|
22
|
-
}[];
|
|
23
|
-
hasMore: boolean;
|
|
24
|
-
nextCursor: string | null;
|
|
25
|
-
}
|
|
26
|
-
export interface NotePresenceReceipt {
|
|
27
|
-
state?: {
|
|
28
|
-
user?: Participant['user'];
|
|
29
|
-
expiresAt: number;
|
|
30
|
-
activity?: {
|
|
31
|
-
kind: string;
|
|
32
|
-
hash: string;
|
|
33
|
-
ranges: NoteRange[];
|
|
34
|
-
expiresAt: number;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
[key: string]: unknown;
|
|
38
|
-
}
|
|
39
|
-
export interface NoteActivity {
|
|
40
|
-
id: string;
|
|
41
|
-
agent: {
|
|
42
|
-
id: string;
|
|
43
|
-
name: string;
|
|
44
|
-
owner: string;
|
|
45
|
-
};
|
|
46
|
-
kind: 'read' | 'insert';
|
|
47
|
-
scope: string;
|
|
48
|
-
hash: string;
|
|
49
|
-
ranges: NoteRange[];
|
|
50
|
-
at: number;
|
|
51
|
-
expiresAt: number;
|
|
52
|
-
}
|
|
53
|
-
export interface NoteSelectionOptions {
|
|
54
|
-
text: string;
|
|
55
|
-
section?: string;
|
|
56
|
-
occurrence?: number;
|
|
57
|
-
hash?: string;
|
|
58
|
-
}
|
|
59
|
-
export interface NoteSelectionReceipt {
|
|
60
|
-
note: string;
|
|
61
|
-
hash: string;
|
|
62
|
-
text: string;
|
|
63
|
-
scope: {
|
|
64
|
-
kind: 'note';
|
|
65
|
-
} | {
|
|
66
|
-
kind: 'section';
|
|
67
|
-
anchor: string;
|
|
68
|
-
};
|
|
69
|
-
range: NoteRange;
|
|
70
|
-
occurrence: number;
|
|
71
|
-
matches: number;
|
|
72
|
-
published: true;
|
|
73
|
-
selectionExpiresAt: number;
|
|
74
|
-
presenceExpiresAt: number;
|
|
75
|
-
}
|
|
76
|
-
export declare function notePresenceIntent(value: string | undefined): {
|
|
77
|
-
summary: string;
|
|
78
|
-
} | undefined;
|
|
79
|
-
export declare function notePresenceApi(t: Transport, base: string): {
|
|
80
|
-
contributors: (id: string, options?: {
|
|
81
|
-
cursor?: string;
|
|
82
|
-
pageSize?: number;
|
|
83
|
-
}) => Promise<NoteContributorsPage>;
|
|
84
|
-
/** No join or heartbeat. The optional input retains the former POST API for compatibility. */
|
|
85
|
-
presence: {
|
|
86
|
-
(id: string): Promise<NotePresenceRoster>;
|
|
87
|
-
/** @deprecated Use visit or updatePresence for explicit mutations. */
|
|
88
|
-
(id: string, input: Record<string, unknown>): Promise<NotePresenceReceipt>;
|
|
89
|
-
};
|
|
90
|
-
presenceText: (id: string) => Promise<string>;
|
|
91
|
-
updatePresence: (id: string, input: Record<string, unknown>, options?: RequestOptions) => Promise<NotePresenceReceipt>;
|
|
92
|
-
visit: (id: string, options?: {
|
|
93
|
-
intent?: string;
|
|
94
|
-
}) => Promise<NotePresenceReceipt>;
|
|
95
|
-
activity: (id: string, options?: RequestOptions) => Promise<{
|
|
96
|
-
activities: NoteActivity[];
|
|
97
|
-
}>;
|
|
98
|
-
events: (id: string, signal: AbortSignal, receive: (event: NoteEvent) => void) => Promise<void>;
|
|
99
|
-
selectText: (id: string, options: NoteSelectionOptions) => Promise<NoteSelectionReceipt>;
|
|
100
|
-
};
|
|
1
|
+
/** @deprecated Import the canonical Memo module. */
|
|
2
|
+
export * from "./memo-presence.js";
|
|
@@ -1,73 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
import { find } from './note-editing.js';
|
|
4
|
-
import { readNoteEvents } from './note-events.js';
|
|
5
|
-
export function notePresenceIntent(value) {
|
|
6
|
-
if (value === undefined)
|
|
7
|
-
return undefined;
|
|
8
|
-
const summary = value.trim();
|
|
9
|
-
if (!summary || Array.from(summary).length > 280)
|
|
10
|
-
throw new Error('--intent requires 1–280 characters of plain text (one short sentence of purpose)');
|
|
11
|
-
return { summary };
|
|
12
|
-
}
|
|
13
|
-
export function notePresenceApi(t, base) {
|
|
14
|
-
const path = (id) => `${base}/${seg(id)}`;
|
|
15
|
-
const updatePresence = (id, input, options = {}) => t.request('POST', path(id) + '/presence', { ...options, json: input });
|
|
16
|
-
const presence = (id, input) => input === undefined
|
|
17
|
-
? t.request('GET', path(id) + '/presence', { query: { format: 'json' } })
|
|
18
|
-
: updatePresence(id, input);
|
|
19
|
-
return {
|
|
20
|
-
contributors: (id, options = {}) => t.request('GET', path(id) + '/contributors', { query: options }),
|
|
21
|
-
/** No join or heartbeat. The optional input retains the former POST API for compatibility. */
|
|
22
|
-
presence: presence,
|
|
23
|
-
presenceText: async (id) => {
|
|
24
|
-
if (!t.raw)
|
|
25
|
-
throw new Error('transport_does_not_support_streaming');
|
|
26
|
-
return (await t.raw('GET', path(id) + '/presence', { query: { format: 'text' }, redirect: 'error' })).text();
|
|
27
|
-
},
|
|
28
|
-
updatePresence,
|
|
29
|
-
visit: (id, options = {}) => {
|
|
30
|
-
const intent = notePresenceIntent(options.intent);
|
|
31
|
-
return updatePresence(id, { action: 'join', ...(intent ? { intent } : {}) });
|
|
32
|
-
},
|
|
33
|
-
activity: (id, options = {}) => t.request('GET', path(id) + '/agent-activity', options),
|
|
34
|
-
events: (id, signal, receive) => {
|
|
35
|
-
if (!t.raw)
|
|
36
|
-
throw new Error('transport_does_not_support_streaming');
|
|
37
|
-
return readNoteEvents(path(id) + '/events', '', id, signal, receive, async (_url, options) => t.raw('GET', path(id) + '/events', { headers: options?.headers, signal: options?.signal, timeoutMs: null, redirect: 'error' }));
|
|
38
|
-
},
|
|
39
|
-
selectText: async (id, options) => {
|
|
40
|
-
if (!options.text || options.section === '')
|
|
41
|
-
throw new Error('give nonempty text and an optional nonempty section anchor');
|
|
42
|
-
if (options.occurrence !== undefined && (!Number.isSafeInteger(options.occurrence) || options.occurrence === 0))
|
|
43
|
-
throw new Error('--occurrence (-o) must be a nonzero integer: 1 is first, -1 is last');
|
|
44
|
-
if (options.hash !== undefined && !/^sha256:[a-f0-9]{64}$/.test(options.hash))
|
|
45
|
-
throw new Error('--hash must be sha256: followed by 64 lowercase hex digits');
|
|
46
|
-
const snapshot = await t.request('GET', options.section !== undefined ? path(id) + '/sections/' + seg(options.section) : path(id) + '/body', { query: options.section === undefined ? { contract: 'v2' } : undefined, headers: { 'X-DreamLake-Agent-Id': '' } });
|
|
47
|
-
const source = options.section !== undefined ? snapshot.text : snapshot.content;
|
|
48
|
-
const offset = options.section !== undefined ? snapshot.range?.start : 0;
|
|
49
|
-
if (typeof source !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(snapshot.hash ?? '') || !Number.isSafeInteger(offset) || offset < 0 ||
|
|
50
|
-
(options.section !== undefined && snapshot.range?.end !== offset + Array.from(source).length))
|
|
51
|
-
throw new Error('server did not provide canonical source/hash and code-point range; section selection requires the updated Memos server');
|
|
52
|
-
if (options.hash !== undefined && options.hash !== snapshot.hash)
|
|
53
|
-
throw new ApiError(409, 'stale_range', { note: id });
|
|
54
|
-
const matches = find(source, options.text), requested = options.occurrence ?? 1;
|
|
55
|
-
const nth = requested < 0 ? matches.length + requested + 1 : requested;
|
|
56
|
-
if (!matches.length || nth < 1 || nth > matches.length)
|
|
57
|
-
throw new ApiError(422, 'note_selection_no_match', { matches: matches.length, occurrence: requested });
|
|
58
|
-
if (matches.length > 1 && options.occurrence === undefined)
|
|
59
|
-
throw new ApiError(422, 'note_selection_ambiguous', { matches: matches.length });
|
|
60
|
-
const match = matches[nth - 1], range = { start: offset + match.ind[0], end: offset + match.ind[1] };
|
|
61
|
-
const result = await updatePresence(id, { action: 'seek', hash: snapshot.hash, ranges: [range] });
|
|
62
|
-
const activity = result.state?.activity;
|
|
63
|
-
if (activity?.kind !== 'seeking' || activity.hash !== snapshot.hash || activity.ranges?.length !== 1 ||
|
|
64
|
-
activity.ranges[0].start !== range.start || activity.ranges[0].end !== range.end ||
|
|
65
|
-
!Number.isFinite(activity.expiresAt) || !Number.isFinite(result.state?.expiresAt))
|
|
66
|
-
throw new ApiError(503, 'note_selection_unconfirmed', { note: id, hash: snapshot.hash, range });
|
|
67
|
-
return { note: id, hash: snapshot.hash, text: match.text,
|
|
68
|
-
scope: options.section === undefined ? { kind: 'note' } : { kind: 'section', anchor: options.section },
|
|
69
|
-
range, occurrence: nth, matches: matches.length, published: true,
|
|
70
|
-
selectionExpiresAt: activity.expiresAt, presenceExpiresAt: result.state.expiresAt };
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
1
|
+
/** @deprecated Import the canonical Memo module. */
|
|
2
|
+
export * from "./memo-presence.js";
|
|
@@ -1,51 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface NoteReadingOptions {
|
|
4
|
-
at?: string;
|
|
5
|
-
start?: number;
|
|
6
|
-
limit?: number;
|
|
7
|
-
section?: string;
|
|
8
|
-
tag?: string;
|
|
9
|
-
toc?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface NoteReadingPage {
|
|
12
|
-
note: string;
|
|
13
|
-
hash: string;
|
|
14
|
-
revision: string;
|
|
15
|
-
text: string;
|
|
16
|
-
scope: string;
|
|
17
|
-
sourceType: 'markdown' | 'html';
|
|
18
|
-
start: number;
|
|
19
|
-
end: number;
|
|
20
|
-
total: number;
|
|
21
|
-
complete: boolean;
|
|
22
|
-
next: number | null;
|
|
23
|
-
}
|
|
24
|
-
/** Same addressed, revision-pinned reading contract as the built-in agent. */
|
|
25
|
-
export declare function readNoteView(t: Transport, namespace: string, note: string, options?: NoteReadingOptions): Promise<NoteReadingPage>;
|
|
26
|
-
export declare class InvalidLineRange extends Error {
|
|
27
|
-
constructor(message: string);
|
|
28
|
-
}
|
|
29
|
-
/** A focused read (contract section C): the exact slice with its global address. Never a complete body. */
|
|
30
|
-
export interface NoteFocusedRead {
|
|
31
|
-
note: string;
|
|
32
|
-
hash: string;
|
|
33
|
-
revision: string;
|
|
34
|
-
/** 1-based, inclusive source lines. */
|
|
35
|
-
lines: [number, number];
|
|
36
|
-
/** [start, end) in Unicode code points of the complete source. */
|
|
37
|
-
chars: [number, number];
|
|
38
|
-
/** What was selected, in the terms it was asked for. */
|
|
39
|
-
scope: {
|
|
40
|
-
lines: [number, number];
|
|
41
|
-
};
|
|
42
|
-
content: string;
|
|
43
|
-
complete: false;
|
|
44
|
-
/** The line after `lines[1]`, when the source has one. */
|
|
45
|
-
next?: number;
|
|
46
|
-
}
|
|
47
|
-
/** 1-based inclusive lines → a [start, end) code-point range of the source. The
|
|
48
|
-
* last line's newline belongs to it; a final newline does not start a line.
|
|
49
|
-
* Code points, never UTF-16 units, so CJK and emoji address correctly. */
|
|
50
|
-
export declare function lineRange(content: string, lines: [number, number]): Pick<NoteFocusedRead, 'lines' | 'chars' | 'content' | 'next'>;
|
|
51
|
-
export declare function focusedRead(snapshot: NoteSource, lines: [number, number]): NoteFocusedRead;
|
|
1
|
+
/** @deprecated Import the canonical Memo module. */
|
|
2
|
+
export * from "./memo-reading.js";
|
package/dist/api/note-reading.js
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export async function readNoteView(t, namespace, note, options = {}) {
|
|
4
|
-
if (!isObjectId(note))
|
|
5
|
-
throw new Error('expected a 24-hex memo id');
|
|
6
|
-
if ((options.start ?? 0) > 0 && !options.at)
|
|
7
|
-
throw new Error('reading continuation requires the original revision');
|
|
8
|
-
const page = await t.request('GET', `/namespaces/${seg(namespace)}/notes/${note}/body`, { query: { contract: 'v2', view: 'reading', ...options } });
|
|
9
|
-
if (page.note !== note || typeof page.revision !== 'string' || !page.revision || /[\r\n]/.test(page.revision) || options.at && page.revision !== options.at ||
|
|
10
|
-
!/^sha256:[a-f0-9]{64}$/.test(page.hash) || typeof page.text !== 'string' || !['markdown', 'html'].includes(page.sourceType) || typeof page.scope !== 'string' ||
|
|
11
|
-
![page.start, page.end, page.total].every(n => Number.isSafeInteger(n) && n >= 0) || page.start !== (options.start ?? 0) || page.end < page.start || page.end > page.total ||
|
|
12
|
-
Array.from(page.text).length !== page.end - page.start || page.complete !== (page.end === page.total) || page.next !== (page.complete ? null : page.end) || !page.complete && page.end === page.start)
|
|
13
|
-
throw new Error('invalid Memo reading page');
|
|
14
|
-
return page;
|
|
15
|
-
}
|
|
16
|
-
export class InvalidLineRange extends Error {
|
|
17
|
-
constructor(message) { super(message); this.name = 'InvalidLineRange'; }
|
|
18
|
-
}
|
|
19
|
-
/** 1-based inclusive lines → a [start, end) code-point range of the source. The
|
|
20
|
-
* last line's newline belongs to it; a final newline does not start a line.
|
|
21
|
-
* Code points, never UTF-16 units, so CJK and emoji address correctly. */
|
|
22
|
-
export function lineRange(content, lines) {
|
|
23
|
-
if (!Array.isArray(lines) || lines.length !== 2 || !lines.every(n => Number.isSafeInteger(n)))
|
|
24
|
-
throw new InvalidLineRange('lines must be two integers [first, last], 1-based and inclusive');
|
|
25
|
-
const [first, last] = lines;
|
|
26
|
-
if (first < 1 || last < first)
|
|
27
|
-
throw new InvalidLineRange(`line range ${first}:${last} is not a range; lines are 1-based and inclusive`);
|
|
28
|
-
const points = Array.from(content), starts = [0];
|
|
29
|
-
for (let i = 0; i < points.length; i++)
|
|
30
|
-
if (points[i] === '\n' && i + 1 < points.length)
|
|
31
|
-
starts.push(i + 1);
|
|
32
|
-
const total = points.length === 0 ? 0 : starts.length;
|
|
33
|
-
// Refused, not clamped: a range past the end is a misread length, not a request for "to the end".
|
|
34
|
-
if (last > total)
|
|
35
|
-
throw new InvalidLineRange(`line ${last} is past the end of a ${total}-line memo`);
|
|
36
|
-
const start = starts[first - 1], end = last < total ? starts[last] : points.length;
|
|
37
|
-
return { lines: [first, last], chars: [start, end], content: points.slice(start, end).join(''), ...(last < total ? { next: last + 1 } : {}) };
|
|
38
|
-
}
|
|
39
|
-
export function focusedRead(snapshot, lines) {
|
|
40
|
-
const range = lineRange(snapshot.content, lines);
|
|
41
|
-
return { note: snapshot.note, hash: snapshot.hash, revision: snapshot.revision, lines: range.lines, chars: range.chars, scope: { lines: range.lines }, content: range.content, complete: false, ...(range.next === undefined ? {} : { next: range.next }) };
|
|
42
|
-
}
|
|
1
|
+
/** @deprecated Import the canonical Memo module. */
|
|
2
|
+
export * from "./memo-reading.js";
|
package/dist/api/note-toc.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export * from "
|
|
1
|
+
/** @deprecated Import the canonical Memo module. */
|
|
2
|
+
export * from "./memo-toc.js";
|
package/dist/api/note-toc.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export * from "
|
|
1
|
+
/** @deprecated Import the canonical Memo module. */
|
|
2
|
+
export * from "./memo-toc.js";
|