@songsid/agend 2.4.0-beta.10 → 2.4.0-beta.11
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/auth-api.js +1 -0
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/claude-code.js +35 -9
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/codex-precaution.d.ts +7 -0
- package/dist/backend/codex-precaution.js +102 -0
- package/dist/backend/codex-precaution.js.map +1 -0
- package/dist/backend/codex.d.ts +1 -0
- package/dist/backend/codex.js +18 -0
- package/dist/backend/codex.js.map +1 -1
- package/dist/backend/grok.js +21 -6
- package/dist/backend/grok.js.map +1 -1
- package/dist/backend/types.d.ts +9 -1
- package/dist/backend/types.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/cli-audited.js +3 -3
- package/dist/cli-audited.js.map +1 -1
- package/dist/daemon.js +2 -2
- package/dist/daemon.js.map +1 -1
- package/dist/event-log.d.ts +12 -0
- package/dist/event-log.js +40 -0
- package/dist/event-log.js.map +1 -1
- package/dist/fleet-manager.d.ts +17 -1
- package/dist/fleet-manager.js +116 -3
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/hub/SKILL.md +13 -6
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +10 -1
- package/dist/hub/admin-dashboard.js +3 -3
- package/dist/hub/admin-dashboard.js.map +1 -1
- package/dist/hub/agent-catalog-model.d.ts +276 -0
- package/dist/hub/agent-catalog-model.js +49 -0
- package/dist/hub/agent-catalog-model.js.map +1 -0
- package/dist/hub/agent-catalog.d.ts +137 -0
- package/dist/hub/agent-catalog.js +118 -0
- package/dist/hub/agent-catalog.js.map +1 -0
- package/dist/hub/agent-intro.d.ts +31 -0
- package/dist/hub/agent-intro.js +51 -0
- package/dist/hub/agent-intro.js.map +1 -0
- package/dist/hub/catalog.d.ts +4 -2
- package/dist/hub/catalog.js +19 -3
- package/dist/hub/catalog.js.map +1 -1
- package/dist/hub/client.d.ts +2 -0
- package/dist/hub/client.js +21 -1
- package/dist/hub/client.js.map +1 -1
- package/dist/hub/compose/member.d.ts +6 -0
- package/dist/hub/compose/member.js +68 -10
- package/dist/hub/compose/member.js.map +1 -1
- package/dist/hub/compose/server.d.ts +4 -0
- package/dist/hub/compose/server.js +2 -1
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/execution/service.d.ts +1 -1
- package/dist/hub/execution/service.js +1 -0
- package/dist/hub/execution/service.js.map +1 -1
- package/dist/hub/http/compose.d.ts +2 -0
- package/dist/hub/http/compose.js +98 -14
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/http/schema.js +9 -0
- package/dist/hub/http/schema.js.map +1 -1
- package/dist/hub/mcp/tools.js +2 -1
- package/dist/hub/mcp/tools.js.map +1 -1
- package/dist/hub/member/agent-catalog.d.ts +28 -0
- package/dist/hub/member/agent-catalog.js +80 -0
- package/dist/hub/member/agent-catalog.js.map +1 -0
- package/dist/hub/member/exposure-api.d.ts +3 -3
- package/dist/hub/member/exposure-api.js +4 -4
- package/dist/hub/member/exposure-api.js.map +1 -1
- package/dist/hub/member/exposures.d.ts +12 -4
- package/dist/hub/member/exposures.js +27 -13
- package/dist/hub/member/exposures.js.map +1 -1
- package/dist/hub/member/room-ask.d.ts +4 -1
- package/dist/hub/member/room-ask.js +6 -3
- package/dist/hub/member/room-ask.js.map +1 -1
- package/dist/hub/member/room-context-budget.d.ts +5 -0
- package/dist/hub/member/room-context-budget.js +34 -0
- package/dist/hub/member/room-context-budget.js.map +1 -0
- package/dist/hub/member/sharing-journal.d.ts +252 -0
- package/dist/hub/member/sharing-journal.js +212 -0
- package/dist/hub/member/sharing-journal.js.map +1 -0
- package/dist/hub/member/sharing-link.d.ts +25 -0
- package/dist/hub/member/sharing-link.js +68 -0
- package/dist/hub/member/sharing-link.js.map +1 -0
- package/dist/hub/member/sharing-result.d.ts +6 -0
- package/dist/hub/member/sharing-result.js +46 -0
- package/dist/hub/member/sharing-result.js.map +1 -0
- package/dist/hub/member/sharing.d.ts +37 -0
- package/dist/hub/member/sharing.js +181 -0
- package/dist/hub/member/sharing.js.map +1 -0
- package/dist/hub/personal/owner-host.d.ts +6 -0
- package/dist/hub/personal/owner-host.js +4 -2
- package/dist/hub/personal/owner-host.js.map +1 -1
- package/dist/hub/protocol.d.ts +226 -0
- package/dist/hub/protocol.js +3 -0
- package/dist/hub/protocol.js.map +1 -1
- package/dist/hub/rooms/agents.d.ts +1 -0
- package/dist/hub/rooms/agents.js +13 -2
- package/dist/hub/rooms/agents.js.map +1 -1
- package/dist/hub/rooms/direct-view.d.ts +5 -1
- package/dist/hub/rooms/direct-view.js +2 -2
- package/dist/hub/rooms/direct-view.js.map +1 -1
- package/dist/hub/rooms/service.d.ts +32 -0
- package/dist/hub/rooms/service.js +25 -11
- package/dist/hub/rooms/service.js.map +1 -1
- package/dist/hub/rooms/types.d.ts +2 -1
- package/dist/hub/rooms.d.ts +1 -0
- package/dist/hub/rooms.js +9 -4
- package/dist/hub/rooms.js.map +1 -1
- package/dist/hub/runtime.d.ts +1 -1
- package/dist/hub/server.js +23 -1
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/sharing-previous-access.d.ts +22 -0
- package/dist/hub/sharing-previous-access.js +93 -0
- package/dist/hub/sharing-previous-access.js.map +1 -0
- package/dist/hub/sharing-requests.d.ts +171 -0
- package/dist/hub/sharing-requests.js +311 -0
- package/dist/hub/sharing-requests.js.map +1 -0
- package/dist/hub/sharing-retention.d.ts +47 -0
- package/dist/hub/sharing-retention.js +83 -0
- package/dist/hub/sharing-retention.js.map +1 -0
- package/dist/hub/sharing-withdrawal.d.ts +14 -0
- package/dist/hub/sharing-withdrawal.js +28 -0
- package/dist/hub/sharing-withdrawal.js.map +1 -0
- package/dist/hub/types.d.ts +6 -2
- package/dist/hub-page-sharing-settings.d.ts +6 -0
- package/dist/hub-page-sharing-settings.js +19 -0
- package/dist/hub-page-sharing-settings.js.map +1 -0
- package/dist/hub-sharing-notice.d.ts +43 -0
- package/dist/hub-sharing-notice.js +34 -0
- package/dist/hub-sharing-notice.js.map +1 -0
- package/dist/locale.js +58 -0
- package/dist/locale.js.map +1 -1
- package/dist/login-flows.js +1 -1
- package/dist/login-flows.js.map +1 -1
- package/dist/needs-you.js +1 -0
- package/dist/needs-you.js.map +1 -1
- package/dist/office-share-page.js +1 -1
- package/dist/office-share-page.js.map +1 -1
- package/dist/public-web-gateway.js +4 -2
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/remote-card-answer.d.ts +1 -1
- package/dist/remote-card-answer.js +8 -1
- package/dist/remote-card-answer.js.map +1 -1
- package/dist/remote-card-prompt.js +1 -1
- package/dist/remote-card-prompt.js.map +1 -1
- package/dist/settings-api.d.ts +1 -0
- package/dist/settings-api.js +84 -10
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-baseline.d.ts +3 -0
- package/dist/settings-baseline.js +2 -2
- package/dist/settings-baseline.js.map +1 -1
- package/dist/settings-change.js +1 -0
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.d.ts +3 -0
- package/dist/settings-effect.js +16 -1
- package/dist/settings-effect.js.map +1 -1
- package/dist/ui/fleet-office-card.js +8 -4
- package/dist/ui/fleet-office-pack.d.ts +1 -0
- package/dist/ui/fleet-office-pack.js +6 -2
- package/dist/ui/fleet-office-play.js +84 -0
- package/dist/ui/fleet-office-store.js +23 -0
- package/dist/ui/fleet-office-zones.js +5 -1
- package/dist/ui/fleet-office.js +78 -8
- package/dist/ui/hub-agent-intro.js +26 -0
- package/dist/ui/hub-chat-strings.js +4 -4
- package/dist/ui/hub-client.js +12 -1
- package/dist/ui/hub-grant-picker.js +25 -11
- package/dist/ui/hub-group-strings.js +3 -3
- package/dist/ui/hub-my-agents-model.js +42 -0
- package/dist/ui/hub-my-agents-strings.js +18 -0
- package/dist/ui/hub-my-agents.js +141 -0
- package/dist/ui/hub-owner-strings.js +5 -5
- package/dist/ui/hub-personal-agent.js +5 -4
- package/dist/ui/hub-room-composer.js +27 -4
- package/dist/ui/hub-room-list.js +3 -2
- package/dist/ui/hub-room-members.js +3 -2
- package/dist/ui/hub-room-new.js +1 -1
- package/dist/ui/hub-room-strings.js +2 -2
- package/dist/ui/hub-room-thread.js +4 -2
- package/dist/ui/hub-strings.js +5 -5
- package/dist/ui/hub-welcome.js +6 -6
- package/dist/ui/notice-hub-sharing.js +81 -0
- package/dist/ui/panel-hub.js +16 -11
- package/dist/ui/panel-notices.js +2 -1
- package/dist/ui/settings-hub-connection.js +2 -2
- package/dist/ui/settings-hub-page-sharing.js +52 -0
- package/dist/ui/settings-hub.js +4 -2
- package/dist/ui/settings-registry.js +1 -0
- package/dist/ui/shared/app-shell.js +8 -2
- package/dist/ui/shared/app-store.js +6 -2
- package/dist/ui/shared/hub-chat.css +3 -0
- package/dist/ui/shared/hub-my-agents.css +35 -0
- package/dist/web-api.d.ts +4 -1
- package/dist/web-api.js +55 -1
- package/dist/web-api.js.map +1 -1
- package/dist/web-notices.d.ts +17 -0
- package/dist/web-notices.js +47 -6
- package/dist/web-notices.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/** Durable per-row owner intent/results; mutation receipts join the canonical writer's own transaction. */
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { canonicalArguments, personKeyString, sha256 } from "../identity.js";
|
|
5
|
+
import { epoch, hash, identifier, plain, uuid, validated, HubProtocolError } from "../validation.js";
|
|
6
|
+
import { exposureRequestSchema, exposureRequestRefusalSchema } from "../agent-catalog-model.js";
|
|
7
|
+
import { hubLocalExposureSchema } from "../execution/service.js";
|
|
8
|
+
export const HUB_SHARING_UNDO_MS = 24 * 60 * 60_000;
|
|
9
|
+
export const HUB_MEMBER_SHARING_MIGRATION = Object.freeze({ component: "s3c-hub-sharing", version: 1, up(db) {
|
|
10
|
+
db.exec(`CREATE TABLE hub_member_sharing_requests(id TEXT PRIMARY KEY,binding TEXT NOT NULL,notice_key TEXT UNIQUE NOT NULL,body TEXT NOT NULL,digest TEXT NOT NULL,updated_at INTEGER NOT NULL);
|
|
11
|
+
CREATE INDEX hub_member_sharing_binding ON hub_member_sharing_requests(binding);`);
|
|
12
|
+
} });
|
|
13
|
+
const outcomeSchema = z.union([z.strictObject({ ok: z.literal(true) }), z.strictObject({ ok: z.literal(false), code: exposureRequestRefusalSchema })]);
|
|
14
|
+
export const sharingPlanSchema = z.strictObject({ action: z.enum(["share", "stop"]), target: plain(128), agent: identifier.nullable(),
|
|
15
|
+
name: plain(256), kind: z.enum(["agent", "classic-room"]), incarnation: hash.nullable(), before: hubLocalExposureSchema.nullable() });
|
|
16
|
+
const rowSchema = sharingPlanSchema.extend({ after: hubLocalExposureSchema.nullable(), outcome: outcomeSchema.nullable(),
|
|
17
|
+
undoAfter: hubLocalExposureSchema.nullable(), undoOutcome: outcomeSchema.nullable() });
|
|
18
|
+
const recordSchema = z.strictObject({ id: uuid, binding: plain(512), noticeKey: hash, request: exposureRequestSchema, requestDigest: hash,
|
|
19
|
+
receivedAt: epoch, noticeAt: epoch.nullable(), undoUntil: epoch.nullable(), noticeDurable: z.boolean(), finalNoticeDurable: z.boolean(),
|
|
20
|
+
rows: z.array(rowSchema).min(1).max(64), resultAcked: z.boolean(), undoId: uuid.nullable(), undoAt: epoch.nullable(), undoActor: plain(256).nullable(), undoAcked: z.boolean(), undoNoticeDurable: z.boolean() });
|
|
21
|
+
export class HubMemberSharingJournal {
|
|
22
|
+
options;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
26
|
+
current() { if (!this.options.current())
|
|
27
|
+
throw new HubProtocolError("stale"); }
|
|
28
|
+
decode(raw) {
|
|
29
|
+
if (raw.binding !== this.options.binding)
|
|
30
|
+
throw new HubProtocolError("denied");
|
|
31
|
+
try {
|
|
32
|
+
if (sha256(raw.body) !== raw.digest)
|
|
33
|
+
throw Error("digest");
|
|
34
|
+
const r = validated(recordSchema, JSON.parse(raw.body));
|
|
35
|
+
if (r.id !== raw.id || r.noticeKey !== raw.notice_key || r.noticeKey !== sha256(canonicalArguments([r.binding, r.id])) || r.binding !== raw.binding || sha256(canonicalArguments(r.request)) !== r.requestDigest || personKeyString(r.request.by) !== personKeyString(this.options.owner))
|
|
36
|
+
throw Error("binding");
|
|
37
|
+
return r;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new HubProtocolError("uncertain");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
save(r) {
|
|
44
|
+
this.current();
|
|
45
|
+
validated(recordSchema, r);
|
|
46
|
+
const body = canonicalArguments(r);
|
|
47
|
+
if (this.options.db.prepare("UPDATE hub_member_sharing_requests SET body=?,digest=?,updated_at=? WHERE id=? AND binding=?").run(body, sha256(body), this.options.now(), r.id, this.options.binding).changes !== 1)
|
|
48
|
+
throw new HubProtocolError("stale");
|
|
49
|
+
}
|
|
50
|
+
read(id) {
|
|
51
|
+
this.current();
|
|
52
|
+
validated(uuid, id);
|
|
53
|
+
const raw = this.options.db.prepare("SELECT id,notice_key,binding,body,digest FROM hub_member_sharing_requests WHERE id=?").get(id);
|
|
54
|
+
return raw && raw.binding === this.options.binding ? this.decode(raw) : null;
|
|
55
|
+
}
|
|
56
|
+
byNotice(key) {
|
|
57
|
+
this.current();
|
|
58
|
+
validated(hash, key);
|
|
59
|
+
const raw = this.options.db.prepare("SELECT id,notice_key,binding,body,digest FROM hub_member_sharing_requests WHERE notice_key=? AND binding=?").get(key, this.options.binding);
|
|
60
|
+
return raw ? this.decode(raw) : null;
|
|
61
|
+
}
|
|
62
|
+
edit(id, work) {
|
|
63
|
+
const change = () => { this.current(); const r = this.read(id); if (!r)
|
|
64
|
+
throw new HubProtocolError("not-found"); const result = work(r); this.save(r); return result; };
|
|
65
|
+
return this.options.db.inTransaction ? change() : this.options.db.transaction(change).immediate();
|
|
66
|
+
}
|
|
67
|
+
reserve(id, input, plans, refusal) {
|
|
68
|
+
this.current();
|
|
69
|
+
validated(uuid, id);
|
|
70
|
+
const request = validated(exposureRequestSchema, input), now = this.options.now();
|
|
71
|
+
if (personKeyString(request.by) !== personKeyString(this.options.owner))
|
|
72
|
+
throw new HubProtocolError("denied");
|
|
73
|
+
return this.options.db.transaction(() => {
|
|
74
|
+
const raw = this.options.db.prepare("SELECT id,notice_key,binding,body,digest FROM hub_member_sharing_requests WHERE id=?").get(id);
|
|
75
|
+
if (raw) {
|
|
76
|
+
const r = this.decode(raw);
|
|
77
|
+
if (r.requestDigest !== sha256(canonicalArguments(request)))
|
|
78
|
+
throw new HubProtocolError("conflict");
|
|
79
|
+
return r;
|
|
80
|
+
}
|
|
81
|
+
if (now >= request.expiresAt || request.createdAt > now + 30_000)
|
|
82
|
+
throw new HubProtocolError("expired");
|
|
83
|
+
const targets = [...request.share.map(target => ({ action: "share", target })), ...request.stop.map(target => ({ action: "stop", target }))];
|
|
84
|
+
const checked = plans.map(p => validated(sharingPlanSchema, p));
|
|
85
|
+
if (checked.length !== targets.length || checked.some((p, i) => p.action !== targets[i].action || p.target !== targets[i].target))
|
|
86
|
+
throw new HubProtocolError("invalid");
|
|
87
|
+
for (const p of checked)
|
|
88
|
+
if (p.before && (personKeyString(p.before.exposure.owner) !== personKeyString(request.by) || p.before.exposure.fleetId !== this.options.fleetId || p.before.agent !== p.agent))
|
|
89
|
+
throw new HubProtocolError("denied");
|
|
90
|
+
if (this.options.db.prepare("SELECT count(*) n FROM hub_member_sharing_requests WHERE binding=?").get(this.options.binding).n >= 512)
|
|
91
|
+
throw new HubProtocolError("backpressure");
|
|
92
|
+
const r = { id, binding: this.options.binding, noticeKey: sha256(canonicalArguments([this.options.binding, id])), request, requestDigest: sha256(canonicalArguments(request)), receivedAt: now,
|
|
93
|
+
noticeAt: null, undoUntil: null, noticeDurable: false, finalNoticeDurable: false, resultAcked: false, undoId: null, undoAt: null, undoActor: null, undoAcked: false, undoNoticeDurable: false,
|
|
94
|
+
rows: checked.map(p => ({ ...p, after: null, outcome: refusal ? { ok: false, code: validated(exposureRequestRefusalSchema, refusal) } : null, undoAfter: null, undoOutcome: null })) };
|
|
95
|
+
const body = canonicalArguments(validated(recordSchema, r));
|
|
96
|
+
this.current();
|
|
97
|
+
this.options.db.prepare("INSERT INTO hub_member_sharing_requests VALUES(?,?,?,?,?,?)").run(id, this.options.binding, r.noticeKey, body, sha256(body), now);
|
|
98
|
+
return r;
|
|
99
|
+
}).immediate();
|
|
100
|
+
}
|
|
101
|
+
prepareNotice(id) {
|
|
102
|
+
this.edit(id, r => { if (r.noticeAt === null) {
|
|
103
|
+
r.noticeAt = this.options.now();
|
|
104
|
+
r.undoUntil = r.noticeAt + HUB_SHARING_UNDO_MS;
|
|
105
|
+
} });
|
|
106
|
+
return this.read(id);
|
|
107
|
+
}
|
|
108
|
+
noticeSaved(id) { this.edit(id, r => { if (r.noticeAt === null)
|
|
109
|
+
throw new HubProtocolError("conflict"); r.noticeDurable = true; }); }
|
|
110
|
+
noticeRefused(id) { this.edit(id, r => { if (!r.noticeDurable) {
|
|
111
|
+
r.noticeAt = null;
|
|
112
|
+
r.undoUntil = null;
|
|
113
|
+
} }); }
|
|
114
|
+
finalNoticeSaved(id) { this.edit(id, r => { if (r.rows.some(row => row.outcome === null))
|
|
115
|
+
throw new HubProtocolError("conflict"); r.finalNoticeDurable = true; }); }
|
|
116
|
+
committed(id, index, next, undo) {
|
|
117
|
+
if (!this.options.db.inTransaction)
|
|
118
|
+
throw Error("A sharing receipt requires the exposure writer transaction");
|
|
119
|
+
this.edit(id, r => {
|
|
120
|
+
const row = r.rows[index];
|
|
121
|
+
if (!row || !r.noticeDurable || row[undo ? "undoOutcome" : "outcome"] !== null)
|
|
122
|
+
throw new HubProtocolError("conflict");
|
|
123
|
+
if (!undo && this.options.now() >= r.request.expiresAt)
|
|
124
|
+
throw new HubProtocolError("expired");
|
|
125
|
+
if (undo && (!r.undoId || r.undoUntil === null || this.options.now() >= r.undoUntil || row.outcome?.ok !== true))
|
|
126
|
+
throw new HubProtocolError("expired");
|
|
127
|
+
if (!row.agent || !row.incarnation || this.options.agentToken(row.agent) !== row.incarnation)
|
|
128
|
+
throw new HubProtocolError("stale");
|
|
129
|
+
const before = undo ? row.after : row.before;
|
|
130
|
+
const after = validated(hubLocalExposureSchema, next);
|
|
131
|
+
if (after.agent !== row.agent || after.exposure.fleetId !== this.options.fleetId || personKeyString(after.exposure.owner) !== personKeyString(this.options.owner)
|
|
132
|
+
|| after.exposure.revision !== (before?.exposure.revision ?? 0) + 1 || (before && after.exposure.id !== before.exposure.id))
|
|
133
|
+
throw new HubProtocolError("conflict");
|
|
134
|
+
const expected = (row.action === "share") !== undo ? "published" : "withdrawn";
|
|
135
|
+
const stored = this.options.db.prepare("SELECT committed FROM hub_exposures WHERE id=?").get(after.exposure.id);
|
|
136
|
+
if (after.exposure.state !== expected || !stored || canonicalArguments(JSON.parse(stored.committed)) !== canonicalArguments(after))
|
|
137
|
+
throw new HubProtocolError("conflict");
|
|
138
|
+
if (undo) {
|
|
139
|
+
row.undoAfter = after;
|
|
140
|
+
row.undoOutcome = { ok: true };
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
row.after = after;
|
|
144
|
+
row.outcome = { ok: true };
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
applied(id, index, next) { return this.committed(id, index, next, false); }
|
|
150
|
+
undone(id, index, next) { return this.committed(id, index, next, true); }
|
|
151
|
+
refuse(id, index, code, undo = false) {
|
|
152
|
+
validated(exposureRequestRefusalSchema, code);
|
|
153
|
+
this.edit(id, r => {
|
|
154
|
+
const row = r.rows[index];
|
|
155
|
+
if (!row)
|
|
156
|
+
throw new HubProtocolError("invalid");
|
|
157
|
+
const key = undo ? "undoOutcome" : "outcome";
|
|
158
|
+
if (row[key] !== null) {
|
|
159
|
+
if (row[key]?.ok === false && row[key].code === code)
|
|
160
|
+
return;
|
|
161
|
+
throw new HubProtocolError("conflict");
|
|
162
|
+
}
|
|
163
|
+
row[key] = { ok: false, code };
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
beginUndo(id, actor) {
|
|
167
|
+
this.edit(id, r => {
|
|
168
|
+
if (r.undoId)
|
|
169
|
+
return;
|
|
170
|
+
if (!r.rows.some(row => row.outcome?.ok === true))
|
|
171
|
+
throw new HubProtocolError("denied");
|
|
172
|
+
if (!r.noticeDurable || !r.finalNoticeDurable || r.undoUntil === null || this.options.now() >= r.undoUntil)
|
|
173
|
+
throw new HubProtocolError("expired");
|
|
174
|
+
r.undoId = randomUUID();
|
|
175
|
+
r.undoAt = this.options.now();
|
|
176
|
+
r.undoActor = validated(plain(256), actor);
|
|
177
|
+
});
|
|
178
|
+
return this.read(id);
|
|
179
|
+
}
|
|
180
|
+
undoNoticeSaved(id) { this.edit(id, r => { if (!r.undoId || r.rows.some(row => row.outcome?.ok === true && row.undoOutcome === null))
|
|
181
|
+
throw new HubProtocolError("conflict"); r.undoNoticeDurable = true; }); }
|
|
182
|
+
acknowledge(id, undo = false) {
|
|
183
|
+
this.edit(id, r => {
|
|
184
|
+
if (undo) {
|
|
185
|
+
if (!r.undoId || !r.undoNoticeDurable || r.rows.some(row => row.outcome?.ok === true && row.undoOutcome === null))
|
|
186
|
+
throw new HubProtocolError("conflict");
|
|
187
|
+
r.undoAcked = true;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
if (!r.finalNoticeDurable)
|
|
191
|
+
throw new HubProtocolError("conflict");
|
|
192
|
+
r.resultAcked = true;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
pending() {
|
|
197
|
+
this.current();
|
|
198
|
+
return this.options.db.prepare("SELECT id,notice_key,binding,body,digest FROM hub_member_sharing_requests WHERE binding=? ORDER BY updated_at LIMIT 512").all(this.options.binding)
|
|
199
|
+
.map(raw => this.decode(raw)).filter(r => !r.resultAcked || !!r.undoId && !r.undoAcked);
|
|
200
|
+
}
|
|
201
|
+
prune() {
|
|
202
|
+
this.current();
|
|
203
|
+
this.options.db.transaction(() => {
|
|
204
|
+
for (const raw of this.options.db.prepare("SELECT id,notice_key,binding,body,digest FROM hub_member_sharing_requests WHERE binding=?").all(this.options.binding)) {
|
|
205
|
+
const r = this.decode(raw);
|
|
206
|
+
if (this.options.now() >= (r.undoUntil ?? r.receivedAt + HUB_SHARING_UNDO_MS))
|
|
207
|
+
this.options.db.prepare("DELETE FROM hub_member_sharing_requests WHERE id=? AND binding=?").run(r.id, this.options.binding);
|
|
208
|
+
}
|
|
209
|
+
}).immediate();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=sharing-journal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharing-journal.js","sourceRoot":"","sources":["../../../src/hub/member/sharing-journal.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACrG,OAAO,EAAE,qBAAqB,EAAE,4BAA4B,EAA2B,MAAM,2BAA2B,CAAC;AACzH,OAAO,EAAE,sBAAsB,EAAyB,MAAM,yBAAyB,CAAC;AAGxF,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;AACpD,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAC,iBAAiB,EAAC,OAAO,EAAC,CAAC,EAAC,EAAE,CAAC,EAAoB;QACvH,EAAE,CAAC,IAAI,CAAC;qFA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AC,EAAE,CAAC,WAAW,CAAC,GAAE,EAAE;YAAC,KAAI,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,2FAA2F,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAU,EAAC,CAAC;gBACxN,MAAM,CAAC,GAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAAA,IAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAE,CAAC,CAAC,CAAC,SAAS,IAAE,CAAC,CAAC,UAAU,GAAC,mBAAmB,CAAC;oBAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,kEAAkE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7N,CAAC;QAAA,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Durable member outbox. Lost result/ACKs only repeat frozen metadata, never a writer input. */
|
|
2
|
+
import { type HubExposureRequest } from "../agent-catalog-model.js";
|
|
3
|
+
import type { HubMemberLink } from "../client.js";
|
|
4
|
+
import { HubMemberSharing } from "./sharing.js";
|
|
5
|
+
import { HubMemberSharingJournal } from "./sharing-journal.js";
|
|
6
|
+
export declare class HubMemberSharingLink {
|
|
7
|
+
private readonly options;
|
|
8
|
+
private link;
|
|
9
|
+
private running;
|
|
10
|
+
private timer;
|
|
11
|
+
private closed;
|
|
12
|
+
constructor(options: {
|
|
13
|
+
sharing: HubMemberSharing;
|
|
14
|
+
journal: HubMemberSharingJournal;
|
|
15
|
+
current(): boolean;
|
|
16
|
+
failed(): void;
|
|
17
|
+
});
|
|
18
|
+
connected(link: HubMemberLink): void;
|
|
19
|
+
disconnected(): void;
|
|
20
|
+
receive(id: string, value: HubExposureRequest, link: HubMemberLink): void;
|
|
21
|
+
private current;
|
|
22
|
+
flush(): Promise<void>;
|
|
23
|
+
private pump;
|
|
24
|
+
close(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Durable member outbox. Lost result/ACKs only repeat frozen metadata, never a writer input. */
|
|
2
|
+
import { HUB_EXPOSURE_REQUEST_CAPABILITY } from "../agent-catalog-model.js";
|
|
3
|
+
import { sharingResult, sharingUndo } from "./sharing-result.js";
|
|
4
|
+
export class HubMemberSharingLink {
|
|
5
|
+
options;
|
|
6
|
+
link = null;
|
|
7
|
+
running = null;
|
|
8
|
+
timer = null;
|
|
9
|
+
closed = false;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
connected(link) {
|
|
14
|
+
if (this.closed || !this.options.current() || !link.current() || !link.features.has(HUB_EXPOSURE_REQUEST_CAPABILITY))
|
|
15
|
+
return;
|
|
16
|
+
this.link = link;
|
|
17
|
+
if (!this.timer) {
|
|
18
|
+
this.timer = setInterval(() => { void this.flush(); }, 3_000);
|
|
19
|
+
this.timer.unref();
|
|
20
|
+
}
|
|
21
|
+
void this.flush();
|
|
22
|
+
}
|
|
23
|
+
disconnected() { this.link = null; if (this.timer)
|
|
24
|
+
clearInterval(this.timer); this.timer = null; }
|
|
25
|
+
receive(id, value, link) {
|
|
26
|
+
if (this.link !== link || !this.current(link))
|
|
27
|
+
return;
|
|
28
|
+
// The socket receive queue must remain free to deliver this operation's ACK.
|
|
29
|
+
void this.options.sharing.apply(id, value, () => this.current(link)).then(() => this.flush()).catch(() => this.options.failed());
|
|
30
|
+
}
|
|
31
|
+
current(link) {
|
|
32
|
+
return !this.closed && this.options.current() && this.link === link && link.current() && link.features.has(HUB_EXPOSURE_REQUEST_CAPABILITY);
|
|
33
|
+
}
|
|
34
|
+
flush() {
|
|
35
|
+
return this.running ??= this.pump().catch(() => { this.options.failed(); }).finally(() => { this.running = null; });
|
|
36
|
+
}
|
|
37
|
+
async pump() {
|
|
38
|
+
const link = this.link;
|
|
39
|
+
if (!link || !this.current(link))
|
|
40
|
+
return;
|
|
41
|
+
for (let record of this.options.journal.pending()) {
|
|
42
|
+
if (!this.current(link))
|
|
43
|
+
return;
|
|
44
|
+
if (!record.finalNoticeDurable) {
|
|
45
|
+
record = await this.options.sharing.apply(record.id, record.request, () => this.current(link));
|
|
46
|
+
if (!this.current(link))
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!record.resultAcked) {
|
|
50
|
+
const ack = await link.exchange({ v: 1, type: "exposure.request-result", requestId: record.id,
|
|
51
|
+
linkEpoch: link.linkEpoch, payload: sharingResult(record) }, "exposure.request-ack");
|
|
52
|
+
if (!this.current(link) || ack.type !== "exposure.request-ack" || !ack.payload.ok)
|
|
53
|
+
return;
|
|
54
|
+
this.options.journal.acknowledge(record.id);
|
|
55
|
+
}
|
|
56
|
+
record = this.options.journal.read(record.id);
|
|
57
|
+
if (record.undoId && !record.undoAcked && record.undoNoticeDurable) {
|
|
58
|
+
const ack = await link.exchange({ v: 1, type: "exposure.undo", requestId: record.undoId,
|
|
59
|
+
linkEpoch: link.linkEpoch, payload: sharingUndo(record) }, "exposure.undo-result");
|
|
60
|
+
if (!this.current(link) || ack.type !== "exposure.undo-result" || !ack.payload.ok)
|
|
61
|
+
return;
|
|
62
|
+
this.options.journal.acknowledge(record.id, true);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
close() { this.closed = true; this.disconnected(); }
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=sharing-link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharing-link.js","sourceRoot":"","sources":["../../../src/hub/member/sharing-link.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,+BAA+B,EAA2B,MAAM,2BAA2B,CAAC;AAIrG,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACj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,OAAO,CAAC,EAAE;oBAAE,OAAO;gBAC1F,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;IACH,CAAC;IACD,KAAK,KAAW,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;CAC3D"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type HubExposureRequestResult, type HubExposureUndo } from "../agent-catalog-model.js";
|
|
2
|
+
import { type HubSharingNotice } from "../../hub-sharing-notice.js";
|
|
3
|
+
import type { SharingRecord } from "./sharing-journal.js";
|
|
4
|
+
export declare function sharingResult(record: SharingRecord): HubExposureRequestResult;
|
|
5
|
+
export declare function sharingUndo(record: SharingRecord): HubExposureUndo;
|
|
6
|
+
export declare function sharingNotice(record: SharingRecord, hubName: string): HubSharingNotice;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { exposureRequestResultSchema, exposureUndoSchema } from "../agent-catalog-model.js";
|
|
2
|
+
import { hubSharingNoticeSchema } from "../../hub-sharing-notice.js";
|
|
3
|
+
import { validated, HubProtocolError } from "../validation.js";
|
|
4
|
+
const pointer = (value) => ({
|
|
5
|
+
id: value.exposure.id, revision: value.exposure.revision, state: value.exposure.state,
|
|
6
|
+
});
|
|
7
|
+
export function sharingResult(record) {
|
|
8
|
+
if (!record.finalNoticeDurable || record.noticeAt === null || record.undoUntil === null)
|
|
9
|
+
throw new HubProtocolError("unavailable");
|
|
10
|
+
const results = record.rows.map(row => {
|
|
11
|
+
const target = row.action === "share" ? { instance: row.target } : { exposureId: row.target };
|
|
12
|
+
if (!row.outcome)
|
|
13
|
+
throw new HubProtocolError("unavailable");
|
|
14
|
+
return row.outcome.ok ? { ...target, ok: true, before: row.before ? pointer(row.before) : null, after: pointer(row.after) }
|
|
15
|
+
: { ...target, ...row.outcome };
|
|
16
|
+
});
|
|
17
|
+
return validated(exposureRequestResultSchema, { noticeAt: record.noticeAt, undoUntil: record.undoUntil, results });
|
|
18
|
+
}
|
|
19
|
+
export function sharingUndo(record) {
|
|
20
|
+
if (!record.undoId || record.noticeAt === null || !record.undoNoticeDurable)
|
|
21
|
+
throw new HubProtocolError("unavailable");
|
|
22
|
+
const results = record.rows.flatMap((row, index) => {
|
|
23
|
+
if (!row.outcome?.ok)
|
|
24
|
+
return [];
|
|
25
|
+
if (!row.undoOutcome)
|
|
26
|
+
throw new HubProtocolError("unavailable");
|
|
27
|
+
return [row.undoOutcome.ok ? { index, ok: true, before: pointer(row.after), after: pointer(row.undoAfter) }
|
|
28
|
+
: { index, ...row.undoOutcome }];
|
|
29
|
+
});
|
|
30
|
+
return validated(exposureUndoSchema, { originalRequestId: record.id, noticeAt: record.noticeAt, results });
|
|
31
|
+
}
|
|
32
|
+
export function sharingNotice(record, hubName) {
|
|
33
|
+
if (record.noticeAt === null || record.undoUntil === null)
|
|
34
|
+
throw new HubProtocolError("unavailable");
|
|
35
|
+
return validated(hubSharingNoticeSchema, {
|
|
36
|
+
key: record.noticeKey, hubName, byName: record.request.byName ?? "Hub owner", at: record.noticeAt, undoUntil: record.undoUntil,
|
|
37
|
+
version: 1 + record.rows.filter(row => row.outcome !== null).length + (record.undoId ? 100 + record.rows.filter(row => row.undoOutcome !== null).length : 0),
|
|
38
|
+
state: record.undoId ? record.rows.every(row => !row.outcome?.ok || row.undoOutcome !== null) ? "undone" : "undoing" : record.rows.every(row => row.outcome !== null) ? "complete" : "pending",
|
|
39
|
+
rows: record.rows.map(row => ({ name: row.name, kind: row.kind, action: row.action,
|
|
40
|
+
state: row.undoOutcome ? row.undoOutcome.ok ? "undone" : "changed" : !row.outcome ? "pending" : !row.outcome.ok ? "refused" : row.action === "share" ? "shared" : "stopped",
|
|
41
|
+
...((row.undoOutcome && !row.undoOutcome.ok ? row.undoOutcome.code : row.outcome && !row.outcome.ok ? row.outcome.code : null) ? {
|
|
42
|
+
code: row.undoOutcome && !row.undoOutcome.ok ? row.undoOutcome.code : row.outcome.code
|
|
43
|
+
} : {}) })),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=sharing-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharing-result.js","sourceRoot":"","sources":["../../../src/hub/member/sharing-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAgF,MAAM,2BAA2B,CAAC;AAC1K,OAAO,EAAE,sBAAsB,EAAyB,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,OAAO,GAAG,CAAC,KAA0D,EAAsB,EAAE,CAAC,CAAC;IACnG,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK;CACtF,CAAC,CAAC;AACH,MAAM,UAAU,aAAa,CAAC,MAAqB;IACjD,IAAI,CAAC,MAAM,CAAC,kBAAkB,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI;QAAE,MAAM,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAAC;IACnI,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACpC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;QAC9F,IAAI,CAAC,GAAG,CAAC,OAAO;YAAE,MAAM,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAC5D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CAAC,CAAC;KAC7H,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Hub owner requests use the same writer as Settings. The journal, never a chat button, proves each effect. */
|
|
2
|
+
import type { HubAgentCatalog, HubExposureRequest } from "../agent-catalog-model.js";
|
|
3
|
+
import type { MemberCatalogAgent } from "./agent-catalog.js";
|
|
4
|
+
import type { HubMemberExposureApi } from "./exposure-api.js";
|
|
5
|
+
import { type HubExposureStore } from "./exposures.js";
|
|
6
|
+
import { HubMemberSharingJournal, type SharingRecord } from "./sharing-journal.js";
|
|
7
|
+
export interface HubMemberSharingOptions {
|
|
8
|
+
journal: HubMemberSharingJournal;
|
|
9
|
+
store: HubExposureStore;
|
|
10
|
+
api: HubMemberExposureApi;
|
|
11
|
+
catalog(): HubAgentCatalog;
|
|
12
|
+
agents(): MemberCatalogAgent[];
|
|
13
|
+
current(): boolean;
|
|
14
|
+
enabled(): boolean;
|
|
15
|
+
now(): number;
|
|
16
|
+
/** Upsert the same web notice durably. False means definitely not saved; a throw is uncertain. */
|
|
17
|
+
notice(record: SharingRecord): Promise<boolean>;
|
|
18
|
+
snapshot(): Promise<unknown>;
|
|
19
|
+
}
|
|
20
|
+
export declare class HubMemberSharing {
|
|
21
|
+
private readonly options;
|
|
22
|
+
private tail;
|
|
23
|
+
private fence;
|
|
24
|
+
constructor(options: HubMemberSharingOptions);
|
|
25
|
+
private serial;
|
|
26
|
+
private current;
|
|
27
|
+
private token;
|
|
28
|
+
private local;
|
|
29
|
+
private plan;
|
|
30
|
+
private refusal;
|
|
31
|
+
private receipt;
|
|
32
|
+
private knownRefusal;
|
|
33
|
+
private change;
|
|
34
|
+
apply(id: string, request: HubExposureRequest, current?: () => boolean): Promise<SharingRecord>;
|
|
35
|
+
/** The caller supplies a rechecked local-admin fence, never an AD identity inferred from the local administrator. */
|
|
36
|
+
undo(noticeKey: string, actor: string, authorized: () => boolean): Promise<SharingRecord>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { canonicalArguments } from "../identity.js";
|
|
2
|
+
import { HubProtocolError } from "../validation.js";
|
|
3
|
+
import { HUB_AGENT_MODE } from "./agent-mode.js";
|
|
4
|
+
import { HubExposureRefusal } from "./exposures.js";
|
|
5
|
+
const same = (a, b) => canonicalArguments(a) === canonicalArguments(b);
|
|
6
|
+
export class HubMemberSharing {
|
|
7
|
+
options;
|
|
8
|
+
tail = Promise.resolve();
|
|
9
|
+
fence = null;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
serial(work, fence) {
|
|
14
|
+
const result = this.tail.then(async () => {
|
|
15
|
+
this.fence = fence ?? null;
|
|
16
|
+
try {
|
|
17
|
+
return await work();
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
this.fence = null;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
this.tail = result.catch(() => { });
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
current() {
|
|
27
|
+
if (!this.options.current() || this.fence && !this.fence())
|
|
28
|
+
throw new HubProtocolError("stale");
|
|
29
|
+
}
|
|
30
|
+
token(agent) {
|
|
31
|
+
return this.options.agents().find(row => row.instance === agent)?.incarnation ?? null;
|
|
32
|
+
}
|
|
33
|
+
local(agent) {
|
|
34
|
+
return this.options.store.list().find(row => row.agent === agent)?.committed ?? null;
|
|
35
|
+
}
|
|
36
|
+
plan(request) {
|
|
37
|
+
const sources = this.options.agents(), locals = this.options.store.list();
|
|
38
|
+
return [...request.share.map(target => ({ action: "share", target })),
|
|
39
|
+
...request.stop.map(target => ({ action: "stop", target }))].map(({ action, target }) => {
|
|
40
|
+
const before = action === "share" ? locals.find(row => row.agent === target)?.committed ?? null
|
|
41
|
+
: locals.find(row => row.committed?.exposure.id === target)?.committed ?? null;
|
|
42
|
+
const source = sources.find(row => row.instance === (action === "share" ? target : before?.agent));
|
|
43
|
+
return { action, target, before, agent: source?.instance ?? null, name: source?.displayName ?? before?.exposure.displayName ?? target,
|
|
44
|
+
kind: source?.kind ?? "agent", incarnation: source?.incarnation ?? null };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
refusal(record, row, undo) {
|
|
48
|
+
if (!undo && !this.options.enabled())
|
|
49
|
+
return "switched-off";
|
|
50
|
+
if (!undo && this.options.now() >= record.request.expiresAt)
|
|
51
|
+
return "expired";
|
|
52
|
+
if (undo && (record.undoUntil === null || this.options.now() >= record.undoUntil))
|
|
53
|
+
return "expired";
|
|
54
|
+
if (!row.agent || !row.incarnation)
|
|
55
|
+
return "unknown-agent";
|
|
56
|
+
const source = this.options.agents().find(agent => agent.instance === row.agent);
|
|
57
|
+
if (!source || source.incarnation !== row.incarnation)
|
|
58
|
+
return "stale-list";
|
|
59
|
+
if (!source.shareable && (row.action === "share") !== undo)
|
|
60
|
+
return "not-shareable";
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
receipt(record, index, undo) {
|
|
64
|
+
const row = record.rows[index];
|
|
65
|
+
const actor = undo ? { kind: "local-host" } : { kind: "person", person: record.request.by };
|
|
66
|
+
return { requestId: undo ? record.undoId : record.id, actor,
|
|
67
|
+
assertCurrent: () => {
|
|
68
|
+
this.current();
|
|
69
|
+
const refusal = this.refusal(record, row, undo);
|
|
70
|
+
if (refusal)
|
|
71
|
+
throw new HubProtocolError(refusal === "expired" ? "expired" : "stale");
|
|
72
|
+
return undefined;
|
|
73
|
+
},
|
|
74
|
+
committed: next => undo ? this.options.journal.undone(record.id, index, next) : this.options.journal.applied(record.id, index, next) };
|
|
75
|
+
}
|
|
76
|
+
knownRefusal(error) {
|
|
77
|
+
if (!(error instanceof HubExposureRefusal))
|
|
78
|
+
return null;
|
|
79
|
+
return error.code === "limit" ? "limit" : error.code === "unknown_agent" ? "unknown-agent"
|
|
80
|
+
: error.code === "not_enforceable" ? "not-shareable" : "stale-list";
|
|
81
|
+
}
|
|
82
|
+
async change(record, index, undo) {
|
|
83
|
+
const row = record.rows[index];
|
|
84
|
+
if (undo ? row.outcome?.ok !== true || row.undoOutcome !== null : row.outcome !== null)
|
|
85
|
+
return;
|
|
86
|
+
this.current();
|
|
87
|
+
let refusal = this.refusal(record, row, undo);
|
|
88
|
+
const expected = undo ? row.after : row.before;
|
|
89
|
+
if (!refusal && !same(this.local(row.agent), expected))
|
|
90
|
+
refusal = "stale-list";
|
|
91
|
+
const publishing = (row.action === "share") !== undo;
|
|
92
|
+
// Ticking an already shared agent is not permission to revise it; only a withdrawn/absent mapping can be shared.
|
|
93
|
+
if (!refusal && !undo && publishing && expected?.exposure.state !== undefined && expected.exposure.state !== "withdrawn")
|
|
94
|
+
refusal = "stale-list";
|
|
95
|
+
if (!refusal && !publishing && (!expected || expected.exposure.state === "withdrawn"))
|
|
96
|
+
refusal = "stale-list";
|
|
97
|
+
if (refusal) {
|
|
98
|
+
this.options.journal.refuse(record.id, index, refusal, undo);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const receipt = this.receipt(record, index, undo);
|
|
103
|
+
if (publishing) {
|
|
104
|
+
this.options.api.publish({ agent: row.agent, dataViewId: HUB_AGENT_MODE, tools: [],
|
|
105
|
+
expectedRevision: expected?.exposure.revision ?? 0, contactLimit: undo ? row.before?.contactLimit !== false : true }, receipt);
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
await this.options.api.withdraw(expected.exposure.id, expected.exposure.revision, receipt);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
// An atomic receipt wins over a lost caller result. An unclassified failure remains pending, never "not shared".
|
|
112
|
+
const saved = this.options.journal.read(record.id).rows[index];
|
|
113
|
+
if ((undo ? saved.undoOutcome : saved.outcome)?.ok)
|
|
114
|
+
return;
|
|
115
|
+
const code = this.knownRefusal(error);
|
|
116
|
+
if (!code)
|
|
117
|
+
throw error;
|
|
118
|
+
this.options.journal.refuse(record.id, index, code, undo);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async apply(id, request, current) {
|
|
122
|
+
return this.serial(async () => {
|
|
123
|
+
this.current();
|
|
124
|
+
this.options.journal.prune();
|
|
125
|
+
let record = this.options.journal.read(id);
|
|
126
|
+
const fresh = !record;
|
|
127
|
+
const catalog = fresh ? this.options.catalog() : null;
|
|
128
|
+
const refused = fresh && !this.options.enabled() ? "switched-off"
|
|
129
|
+
: fresh && catalog.revision !== request.catalogRevision ? "stale-list" : undefined;
|
|
130
|
+
record = this.options.journal.reserve(id, request, fresh ? this.plan(request) : [], refused);
|
|
131
|
+
if (record.finalNoticeDurable)
|
|
132
|
+
return record;
|
|
133
|
+
if (!record.noticeDurable) {
|
|
134
|
+
record = this.options.journal.prepareNotice(id);
|
|
135
|
+
if (!await this.options.notice(record)) {
|
|
136
|
+
this.options.journal.noticeRefused(id);
|
|
137
|
+
throw new HubProtocolError("unavailable");
|
|
138
|
+
}
|
|
139
|
+
this.current();
|
|
140
|
+
this.options.journal.noticeSaved(id);
|
|
141
|
+
}
|
|
142
|
+
for (let i = 0; i < record.rows.length; i++)
|
|
143
|
+
await this.change(this.options.journal.read(id), i, false);
|
|
144
|
+
record = this.options.journal.read(id);
|
|
145
|
+
if (!await this.options.notice(record))
|
|
146
|
+
throw new HubProtocolError("unavailable");
|
|
147
|
+
this.current();
|
|
148
|
+
this.options.journal.finalNoticeSaved(id);
|
|
149
|
+
await this.options.snapshot();
|
|
150
|
+
return this.options.journal.read(id);
|
|
151
|
+
}, current);
|
|
152
|
+
}
|
|
153
|
+
/** The caller supplies a rechecked local-admin fence, never an AD identity inferred from the local administrator. */
|
|
154
|
+
async undo(noticeKey, actor, authorized) {
|
|
155
|
+
return this.serial(async () => {
|
|
156
|
+
this.current();
|
|
157
|
+
if (!authorized())
|
|
158
|
+
throw new HubProtocolError("denied");
|
|
159
|
+
let record = this.options.journal.byNotice(noticeKey);
|
|
160
|
+
if (!record)
|
|
161
|
+
throw new HubProtocolError("not-found");
|
|
162
|
+
this.fence = authorized;
|
|
163
|
+
record = this.options.journal.beginUndo(record.id, actor);
|
|
164
|
+
for (let i = 0; i < record.rows.length; i++) {
|
|
165
|
+
if (!authorized())
|
|
166
|
+
throw new HubProtocolError("denied");
|
|
167
|
+
await this.change(record, i, true);
|
|
168
|
+
record = this.options.journal.read(record.id);
|
|
169
|
+
}
|
|
170
|
+
if (!await this.options.notice(record))
|
|
171
|
+
throw new HubProtocolError("unavailable");
|
|
172
|
+
this.current();
|
|
173
|
+
if (!authorized())
|
|
174
|
+
throw new HubProtocolError("denied");
|
|
175
|
+
this.options.journal.undoNoticeSaved(record.id);
|
|
176
|
+
await this.options.snapshot();
|
|
177
|
+
return this.options.journal.read(record.id);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=sharing.js.map
|