@moxuli/moremote 0.1.6 → 0.1.8
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 +34 -14
- package/dist/activity-capabilities.d.ts +21 -0
- package/dist/activity-capabilities.js +107 -0
- package/dist/cloud-client.d.ts +10 -1
- package/dist/cloud-client.js +43 -3
- package/dist/enrollment-files.d.ts +1 -0
- package/dist/enrollment-files.js +7 -0
- package/dist/event-publication.d.ts +6 -0
- package/dist/event-publication.js +48 -0
- package/dist/journal.d.ts +3 -0
- package/dist/journal.js +7 -1
- package/dist/limits.d.ts +1 -0
- package/dist/limits.js +1 -1
- package/dist/live-activity-titles.d.ts +20 -0
- package/dist/live-activity-titles.js +34 -0
- package/dist/live-activity.d.ts +64 -0
- package/dist/live-activity.js +143 -0
- package/dist/live-directory.d.ts +19 -0
- package/dist/live-directory.js +87 -0
- package/dist/live-workspaces.d.ts +26 -0
- package/dist/live-workspaces.js +217 -0
- package/dist/notification-preview.d.ts +29 -0
- package/dist/notification-preview.js +75 -0
- package/dist/official-client.d.ts +74 -1
- package/dist/official-client.js +63 -12
- package/dist/resources.js +20 -2
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.js +14 -13
- package/docs/STATE.md +110 -515
- package/docs/configuration.md +33 -0
- package/docs/journal/2026-11-14-state-before-0.1.6-part-1.md +400 -0
- package/docs/journal/2026-11-14-state-before-0.1.6-part-2.md +115 -0
- package/docs/journal/2026-11-15-custom-origin-release.md +35 -0
- package/docs/journal/2026-11-15-informative-notifications-activity-release.md +31 -0
- package/docs/journal/2026-11-15-informative-notifications-and-settings.md +41 -0
- package/docs/journal/2026-11-15-live-activity-title-provenance.md +88 -0
- package/docs/journal/2026-11-15-remote-activity-local-acceptance.md +85 -0
- package/docs/journal/2026-11-15-title-provenance-release.md +86 -0
- package/docs/plans/2026-11-10-notification-delivery.md +8 -0
- package/docs/plans/2026-11-15-remote-activity-and-shared-events.md +99 -0
- package/docs/specs/01-architecture.md +15 -2
- package/docs/specs/02-encrypted-delivery.md +44 -0
- package/docs/specs/03-api-contract.md +54 -6
- package/docs/specs/04-control-and-receipt-lifecycle.md +5 -0
- package/docs/specs/05-endpoint-and-lifecycle.md +19 -0
- package/package.json +2 -2
- package/vectors/remote-activity-v2.json +30 -0
|
@@ -3,8 +3,10 @@ import type { ServerInfoStatusPayload, AgentSnapshotPayload } from '@getpaseo/pr
|
|
|
3
3
|
import type { Config, Pair } from './config.js';
|
|
4
4
|
import type { Command, OfficialOperations } from './operations.js';
|
|
5
5
|
import { type ReceiptState, type OperationJournal, type Occurrence } from './journal.js';
|
|
6
|
+
import { type NotificationPreview } from './notification-preview.js';
|
|
6
7
|
import { type Evidence } from './evidence.js';
|
|
7
8
|
export interface Attention {
|
|
9
|
+
preview?: NotificationPreview;
|
|
8
10
|
agentId: string;
|
|
9
11
|
requestId?: string;
|
|
10
12
|
requestBinding?: string;
|
|
@@ -26,19 +28,90 @@ export declare class OfficialClient implements OfficialOperations {
|
|
|
26
28
|
private journal?;
|
|
27
29
|
readonly sdk: DaemonClient;
|
|
28
30
|
private subscription;
|
|
31
|
+
private liveDirectory;
|
|
29
32
|
readonly generation: `${string}-${string}-${string}-${string}-${string}`;
|
|
30
33
|
private serverId;
|
|
31
34
|
private callbacks;
|
|
32
35
|
private unlisten;
|
|
36
|
+
private terminalPublished;
|
|
33
37
|
private terminalReads;
|
|
38
|
+
private previewLanes;
|
|
39
|
+
private previewLane;
|
|
34
40
|
private requestReads;
|
|
35
41
|
private observationOrder;
|
|
42
|
+
private previewAgents;
|
|
36
43
|
private pendingTasks;
|
|
37
44
|
constructor(config: Config, journal?: OperationJournal | undefined);
|
|
38
45
|
connect(): Promise<void>;
|
|
46
|
+
setLiveActivityEnabled(enabled: boolean): void;
|
|
47
|
+
liveActivitySnapshot(): {
|
|
48
|
+
daemonServerId: string;
|
|
49
|
+
hostName: string;
|
|
50
|
+
agents: {
|
|
51
|
+
id: string;
|
|
52
|
+
provider: string;
|
|
53
|
+
cwd: string;
|
|
54
|
+
model: string | null;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
lastUserMessageAt: string | null;
|
|
58
|
+
status: "error" | "initializing" | "idle" | "running" | "closed";
|
|
59
|
+
capabilities: import("@getpaseo/protocol/agent-types").AgentCapabilityFlags;
|
|
60
|
+
currentModeId: string | null;
|
|
61
|
+
availableModes: import("@getpaseo/protocol/agent-types").AgentMode[];
|
|
62
|
+
pendingPermissions: import("@getpaseo/protocol/agent-types").AgentPermissionRequest[];
|
|
63
|
+
persistence: import("@getpaseo/protocol/agent-types").AgentPersistenceHandle | null;
|
|
64
|
+
title: string | null;
|
|
65
|
+
labels: Record<string, string>;
|
|
66
|
+
workspaceId?: string | undefined;
|
|
67
|
+
features?: ({
|
|
68
|
+
type: "toggle";
|
|
69
|
+
id: string;
|
|
70
|
+
label: string;
|
|
71
|
+
value: boolean;
|
|
72
|
+
description?: string | undefined;
|
|
73
|
+
tooltip?: string | undefined;
|
|
74
|
+
icon?: string | undefined;
|
|
75
|
+
} | {
|
|
76
|
+
type: "select";
|
|
77
|
+
id: string;
|
|
78
|
+
label: string;
|
|
79
|
+
value: string | null;
|
|
80
|
+
options: {
|
|
81
|
+
id: string;
|
|
82
|
+
label: string;
|
|
83
|
+
description?: string | undefined;
|
|
84
|
+
isDefault?: boolean | undefined;
|
|
85
|
+
metadata?: Record<string, unknown> | undefined;
|
|
86
|
+
}[];
|
|
87
|
+
description?: string | undefined;
|
|
88
|
+
tooltip?: string | undefined;
|
|
89
|
+
icon?: string | undefined;
|
|
90
|
+
desktopTrigger?: "label" | "icon" | undefined;
|
|
91
|
+
})[] | undefined;
|
|
92
|
+
thinkingOptionId?: string | null | undefined;
|
|
93
|
+
effectiveThinkingOptionId?: string | null | undefined;
|
|
94
|
+
activeTurn?: {
|
|
95
|
+
turnId: string;
|
|
96
|
+
startedAt: string | null;
|
|
97
|
+
} | null | undefined;
|
|
98
|
+
runtimeInfo?: import("@getpaseo/protocol/agent-types").AgentRuntimeInfo | undefined;
|
|
99
|
+
lastUsage?: import("@getpaseo/protocol/agent-types").AgentUsage | undefined;
|
|
100
|
+
lastError?: string | undefined;
|
|
101
|
+
requiresAttention?: boolean | undefined;
|
|
102
|
+
attentionReason?: "error" | "permission" | "finished" | null | undefined;
|
|
103
|
+
attentionTimestamp?: string | null | undefined;
|
|
104
|
+
archivedAt?: string | null | undefined;
|
|
105
|
+
providerUnavailable?: boolean | undefined;
|
|
106
|
+
internal?: boolean | undefined;
|
|
107
|
+
}[];
|
|
108
|
+
workspaces: import("./live-activity-titles.js").LiveWorkspace[];
|
|
109
|
+
requestWorkspace: (id: string) => void;
|
|
110
|
+
} | null;
|
|
39
111
|
info(): ServerInfoStatusPayload | null;
|
|
40
112
|
private emit;
|
|
41
113
|
private emitRequest;
|
|
114
|
+
private withPreviewSlot;
|
|
42
115
|
private readTerminal;
|
|
43
116
|
private terminalTimestamp;
|
|
44
117
|
private fenceTerminalRead;
|
|
@@ -104,7 +177,7 @@ export declare class OfficialClient implements OfficialOperations {
|
|
|
104
177
|
lastUsage?: import("@getpaseo/protocol/agent-types").AgentUsage | undefined;
|
|
105
178
|
lastError?: string | undefined;
|
|
106
179
|
requiresAttention?: boolean | undefined;
|
|
107
|
-
attentionReason?: "
|
|
180
|
+
attentionReason?: "error" | "permission" | "finished" | null | undefined;
|
|
108
181
|
attentionTimestamp?: string | null | undefined;
|
|
109
182
|
archivedAt?: string | null | undefined;
|
|
110
183
|
providerUnavailable?: boolean | undefined;
|
package/dist/official-client.js
CHANGED
|
@@ -10,6 +10,8 @@ import { createHostClient, parseHostTarget } from '@getpaseo/client/node';
|
|
|
10
10
|
import { normalizeLoopbackToLocalhost, parseConnectionUri } from '@getpaseo/protocol/daemon-endpoints';
|
|
11
11
|
import { occurrenceBinding } from './bindings.js';
|
|
12
12
|
import { LIMITS } from './limits.js';
|
|
13
|
+
import { buildNotificationPreview } from './notification-preview.js';
|
|
14
|
+
import { LiveDirectory } from './live-directory.js';
|
|
13
15
|
import { evidenceForCommand, contentDigest } from './evidence.js';
|
|
14
16
|
function boundedFile(path, max) { if (statSync(path).size > max)
|
|
15
17
|
throw Error('OFFICIAL_FILE_LIMIT'); const raw = readFileSync(path, 'utf8'); if (Buffer.byteLength(raw) > max)
|
|
@@ -51,13 +53,18 @@ export class OfficialClient {
|
|
|
51
53
|
journal;
|
|
52
54
|
sdk;
|
|
53
55
|
subscription;
|
|
56
|
+
liveDirectory;
|
|
54
57
|
generation = randomUUID();
|
|
55
58
|
serverId = '';
|
|
56
59
|
callbacks = new Set();
|
|
57
60
|
unlisten;
|
|
61
|
+
terminalPublished = new Map();
|
|
58
62
|
terminalReads = new Map();
|
|
63
|
+
previewLanes = [Promise.resolve(), Promise.resolve()];
|
|
64
|
+
previewLane = 0;
|
|
59
65
|
requestReads = new Set();
|
|
60
66
|
observationOrder = 0;
|
|
67
|
+
previewAgents = new Map();
|
|
61
68
|
pendingTasks = new Map();
|
|
62
69
|
constructor(config, journal) {
|
|
63
70
|
this.config = config;
|
|
@@ -65,6 +72,7 @@ export class OfficialClient {
|
|
|
65
72
|
const target = config.target || localListen(config.paseoHome);
|
|
66
73
|
const password = parseHostTarget(target).password || process.env.PASEO_PASSWORD;
|
|
67
74
|
this.sdk = createHostClient(target, { clientId: config.clientId, clientType: 'cli', appVersion: 'moremote-cli/0.1.0', ...(password ? { password } : { localCredential: () => readLocalCredentialForTarget(config.paseoHome, target) }), reconnect: { enabled: false }, connectTimeoutMs: 15000, logger: { debug() { }, info() { }, warn() { }, error() { } } });
|
|
75
|
+
this.liveDirectory = new LiveDirectory(this.sdk);
|
|
68
76
|
}
|
|
69
77
|
async connect() {
|
|
70
78
|
await this.sdk.connect();
|
|
@@ -118,6 +126,8 @@ export class OfficialClient {
|
|
|
118
126
|
this.subscription = this.sdk.observeEvents(['agent_attention_required', 'agent_permission_request', 'agent_permission_resolved', 'status.server_info'], { notifications: false });
|
|
119
127
|
await this.subscription.ready;
|
|
120
128
|
}
|
|
129
|
+
setLiveActivityEnabled(enabled) { this.liveDirectory.setEnabled(enabled); }
|
|
130
|
+
liveActivitySnapshot() { const agents = this.liveDirectory.snapshot(); return agents ? { daemonServerId: this.serverId, hostName: this.info()?.hostname || hostname(), agents, workspaces: this.liveDirectory.workspaces(), requestWorkspace: (id) => this.liveDirectory.requestWorkspace(id) } : null; }
|
|
121
131
|
info() { return this.sdk.getLastServerInfoMessage(); }
|
|
122
132
|
emit(event) { if (Number.isSafeInteger(event.timestamp) && event.timestamp >= 0)
|
|
123
133
|
for (const cb of this.callbacks)
|
|
@@ -129,12 +139,38 @@ export class OfficialClient {
|
|
|
129
139
|
// Pending requests have independent lifetimes. The global attention clock can
|
|
130
140
|
// still describe an older finished turn; never use it to expire a new request.
|
|
131
141
|
// Runtime journals retain one observation clock per exact current occurrence.
|
|
132
|
-
|
|
142
|
+
const agent = this.previewAgents.get(agentId);
|
|
143
|
+
this.emit({ agentId, requestId: request.id, occurrence, kind: request.kind === 'question' ? 'question' : 'permission', timestamp: occurrence?.createdAt ?? Date.now(), ...(agent ? { preview: buildNotificationPreview(agent, this.info()?.hostname || hostname(), request.kind === 'question' ? 'question' : 'permission', request) } : {}) });
|
|
133
144
|
}
|
|
134
|
-
|
|
145
|
+
async withPreviewSlot(body) {
|
|
146
|
+
const lane = this.previewLane++ % this.previewLanes.length;
|
|
147
|
+
const pending = this.previewLanes[lane].then(body);
|
|
148
|
+
this.previewLanes[lane] = pending.then(() => { }, () => { });
|
|
149
|
+
return pending;
|
|
150
|
+
}
|
|
151
|
+
readTerminal(event, initialAgent) {
|
|
135
152
|
const read = { event, valid: true, next: null };
|
|
136
153
|
this.terminalReads.set(event.agentId, read);
|
|
137
|
-
const complete = (agent) => {
|
|
154
|
+
const complete = async (agent) => {
|
|
155
|
+
if (this.terminalReads.get(event.agentId) !== read)
|
|
156
|
+
return;
|
|
157
|
+
let entries = [];
|
|
158
|
+
const canonical = agent ? this.terminalTimestamp(agent, event) : null;
|
|
159
|
+
const published = canonical !== null && this.terminalPublished.get(event.agentId) === event.kind + ':' + canonical;
|
|
160
|
+
if (!published && read.valid && !read.next && agent && canonical !== null && event.kind === 'finished') {
|
|
161
|
+
try {
|
|
162
|
+
const timeline = await this.withPreviewSlot(async () => {
|
|
163
|
+
if (!read.valid || read.next || this.terminalReads.get(event.agentId) !== read || event.timestamp + LIMITS.snapshotMs <= Date.now())
|
|
164
|
+
return null;
|
|
165
|
+
return this.sdk.fetchAgentTimeline(event.agentId, { direction: 'tail', projection: 'canonical', limit: 30, timeout: 5000 });
|
|
166
|
+
});
|
|
167
|
+
if (!timeline || timeline.agentId !== event.agentId || this.terminalTimestamp(timeline.agent, event) !== canonical)
|
|
168
|
+
read.valid = false;
|
|
169
|
+
else if (!timeline.staleCursor && !timeline.gap)
|
|
170
|
+
entries = timeline.entries;
|
|
171
|
+
}
|
|
172
|
+
catch { /* Title/host remain useful when an optional read fails; never delay beyond five seconds. */ }
|
|
173
|
+
}
|
|
138
174
|
if (this.terminalReads.get(event.agentId) !== read)
|
|
139
175
|
return;
|
|
140
176
|
this.terminalReads.delete(event.agentId);
|
|
@@ -142,15 +178,21 @@ export class OfficialClient {
|
|
|
142
178
|
this.readTerminal(read.next);
|
|
143
179
|
return;
|
|
144
180
|
}
|
|
145
|
-
if (!read.valid)
|
|
181
|
+
if (!read.valid || published)
|
|
146
182
|
return;
|
|
147
183
|
const timestamp = this.terminalTimestamp(agent, event);
|
|
148
|
-
if (timestamp !== null)
|
|
149
|
-
this.
|
|
184
|
+
if (timestamp !== null && agent) {
|
|
185
|
+
if (this.terminalPublished.size >= LIMITS.attention && !this.terminalPublished.has(event.agentId))
|
|
186
|
+
this.terminalPublished.delete(this.terminalPublished.keys().next().value);
|
|
187
|
+
this.terminalPublished.set(event.agentId, event.kind + ':' + timestamp);
|
|
188
|
+
this.emit({ agentId: event.agentId, kind: event.kind, timestamp, preview: buildNotificationPreview(agent, this.info()?.hostname || hostname(), event.kind, undefined, entries) });
|
|
189
|
+
}
|
|
150
190
|
};
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
191
|
+
// One bounded optional canonical tail, never an additional live subscription or write.
|
|
192
|
+
if (initialAgent)
|
|
193
|
+
void complete(initialAgent);
|
|
194
|
+
else
|
|
195
|
+
void this.sdk.fetchAgent({ agentId: event.agentId, timeout: 15000 }).then(value => complete(value?.agent || null)).catch(() => complete(null));
|
|
154
196
|
}
|
|
155
197
|
terminalTimestamp(agent, event) {
|
|
156
198
|
if (!agent || agent.id !== event.agentId || !agent.requiresAttention || agent.attentionReason !== event.kind || agent.activeTurn)
|
|
@@ -210,6 +252,10 @@ export class OfficialClient {
|
|
|
210
252
|
}
|
|
211
253
|
async current(agentId) { return this.readCurrent(agentId); }
|
|
212
254
|
rememberRequests(agentId, agent) {
|
|
255
|
+
if (agent?.pendingPermissions.length)
|
|
256
|
+
this.previewAgents.set(agentId, agent);
|
|
257
|
+
else
|
|
258
|
+
this.previewAgents.delete(agentId);
|
|
213
259
|
if (agent?.pendingPermissions.length)
|
|
214
260
|
this.pendingTasks.set(agentId, projectTask(agent));
|
|
215
261
|
else
|
|
@@ -259,8 +305,13 @@ export class OfficialClient {
|
|
|
259
305
|
for (const a of agents) {
|
|
260
306
|
for (const request of a.pendingPermissions)
|
|
261
307
|
this.emitRequest(a.id, request);
|
|
262
|
-
if (a.
|
|
263
|
-
|
|
308
|
+
if (a.attentionReason && a.attentionReason !== 'permission' && a.attentionTimestamp && !this.terminalReads.has(a.id)) {
|
|
309
|
+
const event = { agentId: a.id, kind: a.attentionReason, timestamp: Date.parse(a.attentionTimestamp), observedOrder: read.observedOrder };
|
|
310
|
+
// Recovery uses the same fenced preview read as live events, without blocking
|
|
311
|
+
// directory/control polling or reading expired history. At most two tails run.
|
|
312
|
+
if (this.terminalTimestamp(a, event) !== null && event.timestamp + LIMITS.snapshotMs > Date.now() && this.terminalPublished.get(a.id) !== event.kind + ':' + event.timestamp)
|
|
313
|
+
this.readTerminal(event, a);
|
|
314
|
+
}
|
|
264
315
|
}
|
|
265
316
|
return { ...this.notificationSnapshot(), hostName: (info.hostname || hostname()).slice(0, 256), measuredAt: Date.now() };
|
|
266
317
|
}
|
|
@@ -268,5 +319,5 @@ export class OfficialClient {
|
|
|
268
319
|
this.requestReads.delete(read);
|
|
269
320
|
}
|
|
270
321
|
}
|
|
271
|
-
async close() { this.pendingTasks.clear(); this.terminalReads.clear(); this.requestReads.clear(); this.unlisten?.(); await this.subscription?.release().catch(() => { }); await this.sdk.close(); }
|
|
322
|
+
async close() { this.liveDirectory.stop(); this.callbacks.clear(); this.terminalPublished.clear(); this.previewAgents.clear(); this.pendingTasks.clear(); this.terminalReads.clear(); this.requestReads.clear(); this.unlisten?.(); await this.subscription?.release().catch(() => { }); await this.sdk.close(); }
|
|
272
323
|
}
|
package/dist/resources.js
CHANGED
|
@@ -32,9 +32,25 @@ export function inspectResource(path, kind, optional = false, privateMode = true
|
|
|
32
32
|
assertResource(stat, kind, privateMode);
|
|
33
33
|
return stat;
|
|
34
34
|
}
|
|
35
|
+
function inspectReadPath(path, privateMode, opened) {
|
|
36
|
+
const observed = lstatSync(path);
|
|
37
|
+
assertResource(observed, 'file', privateMode, true);
|
|
38
|
+
if (opened && sameResource(opened, observed) && (opened.size !== observed.size || opened.mtimeMs !== observed.mtimeMs))
|
|
39
|
+
throw Error('FOREIGN_RESOURCE_CHANGED');
|
|
40
|
+
if (observed.nlink !== 0)
|
|
41
|
+
return observed;
|
|
42
|
+
// POSIX pathname lookup can retain the old inode while rename retires it.
|
|
43
|
+
// Only a different, strictly validated owned replacement permits reopening.
|
|
44
|
+
const replacement = inspectResource(path, 'file', false, privateMode);
|
|
45
|
+
if (!replacement || sameResource(observed, replacement))
|
|
46
|
+
throw Error('FOREIGN_RESOURCE_CHANGED');
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
35
49
|
export function readPrivateText(path, limit, encoding = 'utf8', privateMode = true) {
|
|
36
50
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
37
|
-
const before =
|
|
51
|
+
const before = inspectReadPath(path, privateMode);
|
|
52
|
+
if (!before)
|
|
53
|
+
continue;
|
|
38
54
|
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
39
55
|
try {
|
|
40
56
|
const opened = fstatSync(fd);
|
|
@@ -67,7 +83,9 @@ export function readPrivateText(path, limit, encoding = 'utf8', privateMode = tr
|
|
|
67
83
|
// later atomic replacement would otherwise permit reopening the pathname.
|
|
68
84
|
if (opened.size !== size || opened.size !== finished.size || opened.mtimeMs !== finished.mtimeMs)
|
|
69
85
|
throw Error('FOREIGN_RESOURCE_CHANGED');
|
|
70
|
-
const after =
|
|
86
|
+
const after = inspectReadPath(path, privateMode, opened);
|
|
87
|
+
if (!after)
|
|
88
|
+
continue;
|
|
71
89
|
// Only an ordinary owned replacement permits another read. Linked, foreign
|
|
72
90
|
// or insecure paths fail inspection, and in-place mutation is never retried.
|
|
73
91
|
if (after && !sameResource(opened, after))
|
package/dist/runtime.d.ts
CHANGED
|
@@ -4,11 +4,12 @@ import { OperationJournal, type Occurrence } from './journal.js';
|
|
|
4
4
|
export declare function queueAttention(journal: OperationJournal, pair: Pair, event: Attention & {
|
|
5
5
|
sourceFingerprint?: string;
|
|
6
6
|
occurrence?: Occurrence;
|
|
7
|
-
}, now?: number): Promise<void>;
|
|
7
|
+
}, now?: number, includePreview?: boolean): Promise<void>;
|
|
8
8
|
export declare function boundAttention(journal: OperationJournal, pair: Pair, event: Attention, official: Pick<OfficialClient, 'requestContext' | 'generation'>): Promise<Attention | {
|
|
9
9
|
occurrence: Occurrence;
|
|
10
10
|
sourceFingerprint: string;
|
|
11
11
|
requestBinding: string;
|
|
12
|
+
preview?: import("./notification-preview.js").NotificationPreview;
|
|
12
13
|
agentId: string;
|
|
13
14
|
requestId?: string;
|
|
14
15
|
kind: "finished" | "question" | "permission" | "error";
|
package/dist/runtime.js
CHANGED
|
@@ -16,8 +16,11 @@ import { LIMITS, object } from './limits.js';
|
|
|
16
16
|
import { NotificationStatePublisher } from './notification-state.js';
|
|
17
17
|
import { LocalEnrollment } from './local-enrollment.js';
|
|
18
18
|
import { inspectResource } from './resources.js';
|
|
19
|
+
import { LiveActivityPublisher } from './live-activity.js';
|
|
20
|
+
import { publishEvents } from './event-publication.js';
|
|
21
|
+
import { encryptNotificationPreview } from './notification-preview.js';
|
|
19
22
|
function stableId(value) { const h = createHash('sha256').update(JSON.stringify(value)).digest('hex').slice(0, 32); return h.slice(0, 8) + '-' + h.slice(8, 12) + '-' + h.slice(12, 16) + '-' + h.slice(16, 20) + '-' + h.slice(20); }
|
|
20
|
-
export async function queueAttention(journal, pair, event, now = Date.now()) {
|
|
23
|
+
export async function queueAttention(journal, pair, event, now = Date.now(), includePreview = true) {
|
|
21
24
|
if (event.timestamp + LIMITS.snapshotMs <= now || event.timestamp > now + LIMITS.futureMs)
|
|
22
25
|
return;
|
|
23
26
|
const payload = { agentId: event.agentId, kind: event.kind, timestamp: event.timestamp, ...(event.requestId ? { requestId: event.requestId } : {}), ...(event.requestBinding ? { requestBinding: event.requestBinding } : {}) };
|
|
@@ -26,10 +29,11 @@ export async function queueAttention(journal, pair, event, now = Date.now()) {
|
|
|
26
29
|
const id = event.requestId && event.occurrence ? stableId([pair.pairId, event.agentId, event.kind, event.requestId, 'occurrence', event.occurrence.occurrenceId]) : stableId([pair.pairId, event.agentId, event.kind, event.requestId || '', event.sourceFingerprint || '', event.requestId && !event.sourceFingerprint ? null : event.timestamp]);
|
|
27
30
|
const issuedAt = event.timestamp;
|
|
28
31
|
const envelope = await sealEnvelope(decode(pair.rootKey, 32), { version: 1, pairId: pair.pairId, id, channel: 'attention', issuedAt, expiresAt: issuedAt + LIMITS.snapshotMs }, payload);
|
|
32
|
+
const preview = includePreview && event.preview ? await encryptNotificationPreview(pair, envelope, { agentId: event.agentId, kind: event.kind, timestamp: event.timestamp }, event.preview) : undefined;
|
|
29
33
|
const topic = await presenceTopic(decode(pair.rootKey, 32), pair.pairId, event.agentId);
|
|
30
34
|
if (event.occurrence && !journal.isCurrent(event.occurrence))
|
|
31
35
|
return;
|
|
32
|
-
journal.queueAttention(pair.pairId, id, envelope.expiresAt, { id, kind: event.kind, topic, envelope }, payload);
|
|
36
|
+
journal.queueAttention(pair.pairId, id, envelope.expiresAt, { id, kind: event.kind, topic, envelope, ...(preview ? { preview } : {}) }, payload);
|
|
33
37
|
}
|
|
34
38
|
export async function boundAttention(journal, pair, event, official) {
|
|
35
39
|
if (!event.requestId)
|
|
@@ -115,6 +119,7 @@ export async function runRuntime(dir, version) {
|
|
|
115
119
|
let measuredAt = 0;
|
|
116
120
|
let snapshot;
|
|
117
121
|
const statePublisher = new NotificationStatePublisher();
|
|
122
|
+
const livePublisher = new LiveActivityPublisher(journal);
|
|
118
123
|
const retryStates = new Map();
|
|
119
124
|
const pollOrigins = new Set();
|
|
120
125
|
process.once('SIGINT', stop);
|
|
@@ -252,6 +257,7 @@ export async function runRuntime(dir, version) {
|
|
|
252
257
|
lastError = 'ATTENTION_QUEUE_LIMIT'; });
|
|
253
258
|
measuredAt = 0;
|
|
254
259
|
}
|
|
260
|
+
official.setLiveActivityEnabled(config.cloudEnabled && config.pairs.some(pair => pair.active && !journal.pairRevoked(pair.pairId) && !!clouds.get(pair.pairId)?.liveActivityInterest));
|
|
255
261
|
try {
|
|
256
262
|
await enrollment.cycle(config, official.info().serverId, pair => {
|
|
257
263
|
const origin = pair.apiOrigin || config.apiOrigin;
|
|
@@ -285,7 +291,7 @@ export async function runRuntime(dir, version) {
|
|
|
285
291
|
for (const event of events) {
|
|
286
292
|
const bound = await boundAttention(journal, pair, event, official);
|
|
287
293
|
if (bound)
|
|
288
|
-
await queueAttention(journal, pair, bound);
|
|
294
|
+
await queueAttention(journal, pair, bound, Date.now(), clouds.get(pair.pairId)?.notificationPreviews === true);
|
|
289
295
|
}
|
|
290
296
|
for (const pair of config.pairs) {
|
|
291
297
|
if (stopped)
|
|
@@ -329,16 +335,11 @@ export async function runRuntime(dir, version) {
|
|
|
329
335
|
catch (error) {
|
|
330
336
|
failure = error;
|
|
331
337
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
journal.attentionSent(pair.pairId, item.id);
|
|
338
|
-
}
|
|
339
|
-
catch (error) {
|
|
340
|
-
failure = error;
|
|
341
|
-
}
|
|
338
|
+
try {
|
|
339
|
+
await publishEvents(pair, cloud, journal, livePublisher, official.liveActivitySnapshot(), detailsCurrent);
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
failure = error;
|
|
342
343
|
}
|
|
343
344
|
// Publication failures are independent from acquisition. Preserve the normal
|
|
344
345
|
// three-second command/control cadence while still surfacing degraded status.
|