@agenticprimitives/fabric 0.0.0-alpha.1 → 0.0.0-alpha.10
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/CLAUDE.md +22 -2
- package/README.md +16 -16
- package/dist/case-emissions.d.ts +95 -0
- package/dist/case-emissions.d.ts.map +1 -0
- package/dist/case-emissions.js +208 -0
- package/dist/case-emissions.js.map +1 -0
- package/dist/case-machine.d.ts +28 -2
- package/dist/case-machine.d.ts.map +1 -1
- package/dist/case-machine.js +34 -7
- package/dist/case-machine.js.map +1 -1
- package/dist/cloudflare/index.d.ts +1 -0
- package/dist/cloudflare/index.d.ts.map +1 -1
- package/dist/cloudflare/index.js +4 -0
- package/dist/cloudflare/index.js.map +1 -1
- package/dist/cloudflare/interaction-store.d.ts +55 -0
- package/dist/cloudflare/interaction-store.d.ts.map +1 -0
- package/dist/cloudflare/interaction-store.js +230 -0
- package/dist/cloudflare/interaction-store.js.map +1 -0
- package/dist/cloudflare/principal-gateway-do.d.ts +118 -2
- package/dist/cloudflare/principal-gateway-do.d.ts.map +1 -1
- package/dist/cloudflare/principal-gateway-do.js +182 -7
- package/dist/cloudflare/principal-gateway-do.js.map +1 -1
- package/dist/communicative-act.d.ts +24 -1
- package/dist/communicative-act.d.ts.map +1 -1
- package/dist/communicative-act.js +28 -0
- package/dist/communicative-act.js.map +1 -1
- package/dist/delivery-envelope.d.ts.map +1 -1
- package/dist/delivery-envelope.js +0 -1
- package/dist/delivery-envelope.js.map +1 -1
- package/dist/enum-retirement.d.ts +43 -0
- package/dist/enum-retirement.d.ts.map +1 -0
- package/dist/enum-retirement.js +93 -0
- package/dist/enum-retirement.js.map +1 -0
- package/dist/exchange-record.d.ts +35 -4
- package/dist/exchange-record.d.ts.map +1 -1
- package/dist/exchange-record.js.map +1 -1
- package/dist/exchange-reducer.d.ts +32 -4
- package/dist/exchange-reducer.d.ts.map +1 -1
- package/dist/exchange-reducer.js +75 -1
- package/dist/exchange-reducer.js.map +1 -1
- package/dist/exchange-state.d.ts +30 -8
- package/dist/exchange-state.d.ts.map +1 -1
- package/dist/exchange-state.js +12 -10
- package/dist/exchange-state.js.map +1 -1
- package/dist/inbox-doc.d.ts +2 -2
- package/dist/inbox-doc.d.ts.map +1 -1
- package/dist/inbox-doc.js.map +1 -1
- package/dist/inbox-projection.d.ts +2 -2
- package/dist/inbox-projection.d.ts.map +1 -1
- package/dist/inbox-projection.js.map +1 -1
- package/dist/inbox-revision.d.ts +42 -0
- package/dist/inbox-revision.d.ts.map +1 -0
- package/dist/inbox-revision.js +57 -0
- package/dist/inbox-revision.js.map +1 -0
- package/dist/index.d.ts +23 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -2
- package/dist/index.js.map +1 -1
- package/dist/interaction-machines.d.ts +136 -0
- package/dist/interaction-machines.d.ts.map +1 -0
- package/dist/interaction-machines.js +174 -0
- package/dist/interaction-machines.js.map +1 -0
- package/dist/interaction-profile.d.ts +126 -0
- package/dist/interaction-profile.d.ts.map +1 -0
- package/dist/interaction-profile.js +192 -0
- package/dist/interaction-profile.js.map +1 -0
- package/dist/interaction-record.d.ts +168 -0
- package/dist/interaction-record.d.ts.map +1 -0
- package/dist/interaction-record.js +108 -0
- package/dist/interaction-record.js.map +1 -0
- package/dist/interactions/machine.d.ts +2 -2
- package/dist/interactions/machine.d.ts.map +1 -1
- package/dist/interactions/machine.js +2 -2
- package/dist/interactions/machine.js.map +1 -1
- package/dist/interactions/store.d.ts +9 -0
- package/dist/interactions/store.d.ts.map +1 -1
- package/dist/interactions/store.js +57 -2
- package/dist/interactions/store.js.map +1 -1
- package/dist/messaging/board.d.ts +86 -6
- package/dist/messaging/board.d.ts.map +1 -1
- package/dist/messaging/board.js +100 -9
- package/dist/messaging/board.js.map +1 -1
- package/dist/messaging/consult-routing.d.ts +289 -0
- package/dist/messaging/consult-routing.d.ts.map +1 -0
- package/dist/messaging/consult-routing.js +455 -0
- package/dist/messaging/consult-routing.js.map +1 -0
- package/dist/messaging/consult.d.ts +158 -0
- package/dist/messaging/consult.d.ts.map +1 -0
- package/dist/messaging/consult.js +141 -0
- package/dist/messaging/consult.js.map +1 -0
- package/dist/messaging/conversation-interaction.d.ts +66 -0
- package/dist/messaging/conversation-interaction.d.ts.map +1 -0
- package/dist/messaging/conversation-interaction.js +139 -0
- package/dist/messaging/conversation-interaction.js.map +1 -0
- package/dist/messaging/delivery.d.ts +2 -2
- package/dist/messaging/delivery.d.ts.map +1 -1
- package/dist/messaging/delivery.js +8 -1
- package/dist/messaging/delivery.js.map +1 -1
- package/dist/messaging/directory.d.ts +16 -0
- package/dist/messaging/directory.d.ts.map +1 -1
- package/dist/messaging/directory.js.map +1 -1
- package/dist/messaging/envelope.d.ts +7 -3
- package/dist/messaging/envelope.d.ts.map +1 -1
- package/dist/messaging/envelope.js +18 -1
- package/dist/messaging/envelope.js.map +1 -1
- package/dist/messaging/hash.d.ts +8 -2
- package/dist/messaging/hash.d.ts.map +1 -1
- package/dist/messaging/hash.js +6 -0
- package/dist/messaging/hash.js.map +1 -1
- package/dist/messaging/inbox-assistant.d.ts +80 -0
- package/dist/messaging/inbox-assistant.d.ts.map +1 -0
- package/dist/messaging/inbox-assistant.js +125 -0
- package/dist/messaging/inbox-assistant.js.map +1 -0
- package/dist/messaging/index.d.ts +9 -3
- package/dist/messaging/index.d.ts.map +1 -1
- package/dist/messaging/index.js +17 -2
- package/dist/messaging/index.js.map +1 -1
- package/dist/messaging/projector.d.ts +3 -3
- package/dist/messaging/projector.d.ts.map +1 -1
- package/dist/messaging/projector.js.map +1 -1
- package/dist/messaging/receipts.d.ts +3 -3
- package/dist/messaging/receipts.d.ts.map +1 -1
- package/dist/messaging/receipts.js.map +1 -1
- package/dist/messaging/rules.d.ts +10 -3
- package/dist/messaging/rules.d.ts.map +1 -1
- package/dist/messaging/rules.js +8 -1
- package/dist/messaging/rules.js.map +1 -1
- package/dist/messaging/store.d.ts +4 -4
- package/dist/messaging/store.d.ts.map +1 -1
- package/dist/messaging/store.js +5 -3
- package/dist/messaging/store.js.map +1 -1
- package/dist/messaging/types.d.ts +52 -0
- package/dist/messaging/types.d.ts.map +1 -1
- package/dist/messaging/types.js +18 -1
- package/dist/messaging/types.js.map +1 -1
- package/dist/messaging/vault-store.d.ts +35 -2
- package/dist/messaging/vault-store.d.ts.map +1 -1
- package/dist/messaging/vault-store.js +53 -5
- package/dist/messaging/vault-store.js.map +1 -1
- package/dist/protocol-binding.d.ts +71 -0
- package/dist/protocol-binding.d.ts.map +1 -0
- package/dist/protocol-binding.js +0 -0
- package/dist/protocol-binding.js.map +1 -0
- package/dist/record-catalog.d.ts.map +1 -1
- package/dist/record-catalog.js +19 -0
- package/dist/record-catalog.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
// In-memory InteractionStore: cases + transition log with idempotent replay
|
|
2
2
|
// and deterministic expiry sweeps (spec 309 §6.1, §8.10).
|
|
3
3
|
import { applyInteractionTransition, isTerminalState } from './machine.js';
|
|
4
|
+
import { applyCaseEmissions, caseTransitionEmissions } from '../case-emissions.js';
|
|
4
5
|
export function createInMemoryInteractionStore() {
|
|
5
6
|
const cases = new Map();
|
|
6
7
|
const events = new Map();
|
|
7
8
|
const appliedKeys = new Map();
|
|
9
|
+
const decisions = new Map();
|
|
10
|
+
const commitments = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* spec 340 W10 — record what the transition emitted into the other two machines.
|
|
13
|
+
*
|
|
14
|
+
* Called only after the case machine ACCEPTED, and derived from the PRE-transition case: the seed
|
|
15
|
+
* reads identity and party fields, none of which a transition changes.
|
|
16
|
+
*
|
|
17
|
+
* A rejected emission does not roll back the case. That is deliberate and it is the honest option:
|
|
18
|
+
* the case transition is already a fact, and the alternatives are worse — silently dropping it would
|
|
19
|
+
* make an unrecorded determination indistinguishable from a recorded one, and unwinding an accepted
|
|
20
|
+
* transition would let the decision machine veto a move the case machine's own rules permitted.
|
|
21
|
+
* `void` on a case that never had a commitment is the ordinary, expected case of this.
|
|
22
|
+
*/
|
|
23
|
+
function emit(before, event) {
|
|
24
|
+
const emissions = caseTransitionEmissions(before, {
|
|
25
|
+
version: 'ap.case.event.v1',
|
|
26
|
+
caseId: event.interactionId,
|
|
27
|
+
transition: event.transition,
|
|
28
|
+
actor: event.actor,
|
|
29
|
+
at: event.at,
|
|
30
|
+
});
|
|
31
|
+
if (!emissions.decision && !emissions.commitment)
|
|
32
|
+
return;
|
|
33
|
+
const out = applyCaseEmissions(emissions, {
|
|
34
|
+
decision: decisions.get(event.interactionId) ?? null,
|
|
35
|
+
commitment: commitments.get(event.interactionId) ?? null,
|
|
36
|
+
}, { actor: event.actor, at: event.at });
|
|
37
|
+
if (out.decision?.applied)
|
|
38
|
+
decisions.set(event.interactionId, out.decision.record);
|
|
39
|
+
if (out.commitment?.applied)
|
|
40
|
+
commitments.set(event.interactionId, out.commitment.record);
|
|
41
|
+
}
|
|
8
42
|
return {
|
|
9
43
|
putCase(c) {
|
|
10
44
|
if (c.state !== 'draft') {
|
|
@@ -27,15 +61,26 @@ export function createInMemoryInteractionStore() {
|
|
|
27
61
|
if (event.idempotencyKey !== undefined && keys.has(event.idempotencyKey)) {
|
|
28
62
|
return { ok: true, case: current };
|
|
29
63
|
}
|
|
30
|
-
|
|
64
|
+
// W10b-3: the case machine cannot see the decision machine, so the store — which holds both —
|
|
65
|
+
// supplies it. `issue-credential` refuses without a granted determination.
|
|
66
|
+
const result = applyInteractionTransition(current, event, {
|
|
67
|
+
decisionState: decisions.get(event.interactionId)?.state ?? null,
|
|
68
|
+
});
|
|
31
69
|
if (!result.ok)
|
|
32
70
|
return result;
|
|
33
71
|
cases.set(event.interactionId, result.case);
|
|
34
72
|
events.get(event.interactionId).push(event);
|
|
35
73
|
if (event.idempotencyKey !== undefined)
|
|
36
74
|
keys.add(event.idempotencyKey);
|
|
75
|
+
emit(current, event);
|
|
37
76
|
return result;
|
|
38
77
|
},
|
|
78
|
+
getDecision(id) {
|
|
79
|
+
return decisions.get(id) ?? null;
|
|
80
|
+
},
|
|
81
|
+
getCommitment(id) {
|
|
82
|
+
return commitments.get(id) ?? null;
|
|
83
|
+
},
|
|
39
84
|
listEvents(id) {
|
|
40
85
|
return [...(events.get(id) ?? [])];
|
|
41
86
|
},
|
|
@@ -55,10 +100,20 @@ export function createInMemoryInteractionStore() {
|
|
|
55
100
|
transition: 'expire',
|
|
56
101
|
actor: c.responder, // role 'any' — deterministic sweep, not a user action
|
|
57
102
|
at: nowIso,
|
|
58
|
-
});
|
|
103
|
+
}, { decisionState: decisions.get(c.id)?.state ?? null });
|
|
59
104
|
if (result.ok) {
|
|
60
105
|
cases.set(c.id, result.case);
|
|
61
106
|
expired.push(result.case);
|
|
107
|
+
// The sweep records the determination too. `expire` is the one decision transition the
|
|
108
|
+
// machine lets any actor make, and the emission attributes it to the creditor rather than
|
|
109
|
+
// to `c.responder` — the sweep's stand-in actor, who decided nothing.
|
|
110
|
+
emit(c, {
|
|
111
|
+
version: 'ap.interaction.event.v1',
|
|
112
|
+
interactionId: c.id,
|
|
113
|
+
transition: 'expire',
|
|
114
|
+
actor: c.responder,
|
|
115
|
+
at: nowIso,
|
|
116
|
+
});
|
|
62
117
|
}
|
|
63
118
|
}
|
|
64
119
|
return expired;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/interactions/store.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0DAA0D;AAE1D,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAyB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/interactions/store.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0DAA0D;AAE1D,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAyB,MAAM,cAAc,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AA6BnF,MAAM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ope, ContextRefV1, ConversationDescriptorV1 } from './types.js';
|
|
3
|
+
import { type ConsultProvenanceV1 } from './consult.js';
|
|
3
4
|
export interface ChannelMessageEntryV1 {
|
|
4
|
-
envelope:
|
|
5
|
+
envelope: AnyMessageEnvelope;
|
|
5
6
|
authorName: string;
|
|
7
|
+
/** spec 324 §9 acting-agent provenance (spec 327): WHO performed the authoring move when it was
|
|
8
|
+
* not a human session — for org-assistant posts, the org SA (CAIP-10). Absent ⇒ human-session
|
|
9
|
+
* post. Never erased; the UI renders an "agent" badge from it. */
|
|
10
|
+
actor?: CanonicalAgentId;
|
|
11
|
+
/** spec 329 §6 — PROV attribution on a turn-2 synthesis post (consulted agents + the contributing
|
|
12
|
+
* ConsultationIntent record ids). Absent on every non-synthesis post. */
|
|
13
|
+
prov?: ConsultProvenanceV1;
|
|
14
|
+
}
|
|
15
|
+
/** Steward-controlled org-assistant enablement for one topic (spec 327; 318 §8.1 slice — the org's
|
|
16
|
+
* OWN agent, not a participant bot). Handle + display name are captured AT ENABLE TIME so trigger
|
|
17
|
+
* matching and attribution need no per-post chain read (ADR-0012); re-enabling refreshes both
|
|
18
|
+
* after a name rotation. */
|
|
19
|
+
export interface TopicAssistantV1 {
|
|
20
|
+
/** 'mention' — reply only when a post @-mentions the org. 'all' — reply to every member post. */
|
|
21
|
+
trigger: 'mention' | 'all';
|
|
22
|
+
/** Lowercased mention label, e.g. 'grace' for grace.impact — matched as @grace / @grace.impact.
|
|
23
|
+
* Empty ONLY for trigger:'all' (a nameless org cannot be mentioned). */
|
|
24
|
+
mentionHandle: string;
|
|
25
|
+
/** Author display name stamped on assistant posts (org primary name / profile display name). */
|
|
26
|
+
displayName: string;
|
|
27
|
+
enabledBy: string;
|
|
28
|
+
enabledAt: string;
|
|
29
|
+
}
|
|
30
|
+
/** Steward-controlled member ROUTING enablement for one topic (spec 329 §7): the org's assistant
|
|
31
|
+
* may consult opted-in member agents in this topic. Requires the assistant ON (routing is a mode
|
|
32
|
+
* of the 327 assistant, never a second bot); the org-level consult wire (§3.1) is custodied
|
|
33
|
+
* separately at the org's execution point — flag without wire ⇒ routing stays inert. */
|
|
34
|
+
export interface TopicRoutingV1 {
|
|
35
|
+
/** Fan-out K per routed question (1..5, default 3 — spec 329 §4). */
|
|
36
|
+
maxFanout: number;
|
|
37
|
+
enabledBy: string;
|
|
38
|
+
enabledAt: string;
|
|
6
39
|
}
|
|
7
40
|
export interface ChannelV1 {
|
|
8
41
|
descriptor: ConversationDescriptorV1;
|
|
9
42
|
title: string;
|
|
10
43
|
createdBy: string;
|
|
11
44
|
messages: ChannelMessageEntryV1[];
|
|
45
|
+
/** apmsg:participationPolicy — `open` (every org MEMBER automatically participates; derived, never a
|
|
46
|
+
* stored list) or `restricted` (invite-only; `participants` is the projection of accepted
|
|
47
|
+
* DiscussionParticipation situations). Absent ⇒ resolved from legacy `visibility` (public→open,
|
|
48
|
+
* private→restricted); absent both ⇒ open. */
|
|
49
|
+
participationPolicy?: 'open' | 'restricted';
|
|
12
50
|
visibility?: 'public' | 'private';
|
|
13
|
-
/** For a
|
|
51
|
+
/** For a restricted topic: the PARTICIPANT SAs (lowercased 0x) allowed to see/post — a projection of
|
|
52
|
+
* accepted participations (the creator is always included). Legacy field name `members` kept on the
|
|
53
|
+
* wire; these are discussion PARTICIPANTS, not the org member roster. */
|
|
14
54
|
members?: string[];
|
|
55
|
+
/** Present ⇔ the org's own agent participates in this topic (spec 327). */
|
|
56
|
+
assistant?: TopicAssistantV1;
|
|
57
|
+
/** Present ⇔ member routing is steward-enabled on this topic (spec 329; requires `assistant`). */
|
|
58
|
+
routing?: TopicRoutingV1;
|
|
15
59
|
}
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
60
|
+
/** Resolve a topic's participation policy, mapping the legacy `visibility` wire field
|
|
61
|
+
* (public→open, private→restricted). Absent both ⇒ open (the default + all legacy topics). */
|
|
62
|
+
export declare function channelParticipationPolicy(channel: Pick<ChannelV1, 'participationPolicy' | 'visibility'>): 'open' | 'restricted';
|
|
63
|
+
/** Can `viewerSa` (0x) see this topic? OPEN ⇒ always (every org member; the caller already gated org
|
|
64
|
+
* membership). RESTRICTED ⇒ only listed participants. `isSteward` overrides (a steward/custodian is a
|
|
65
|
+
* facilitator of every topic). One mechanism — used by the store list + the UI. */
|
|
18
66
|
export declare function canSeeChannel(channel: ChannelV1, viewerSa: string, isSteward?: boolean): boolean;
|
|
19
67
|
/** Bounded per-channel history in the board doc (projection only — bodies live in the vault). */
|
|
20
68
|
export declare const BOARD_HISTORY_LIMIT = 200;
|
|
69
|
+
/** Should a just-committed post trigger the topic's org assistant (spec 327 §3)? Pure predicate —
|
|
70
|
+
* the caller supplies the posted body text (it never round-trips through the stored entry, whose
|
|
71
|
+
* body is hash-bound in the vault). False when the assistant is off, when the post is itself
|
|
72
|
+
* agent-authored (`actor` set), or when the author IS the org — the community contextRef, NOT
|
|
73
|
+
* `descriptor.owner` (that is the topic CREATOR) — so the assistant NEVER triggers itself, even
|
|
74
|
+
* in `trigger:'all'` topics. */
|
|
75
|
+
export declare function assistantTrigger(channel: Pick<ChannelV1, 'assistant' | 'descriptor'>, post: {
|
|
76
|
+
from: CanonicalAgentId;
|
|
77
|
+
actor?: CanonicalAgentId;
|
|
78
|
+
bodyText: string;
|
|
79
|
+
}): boolean;
|
|
80
|
+
/** Enable/refresh (`assistant` set) or disable (`assistant` undefined) the org assistant on a topic
|
|
81
|
+
* (mutates the channel on success). Steward gating + audit are the caller's, as with every board
|
|
82
|
+
* mutation. `trigger:'mention'` requires a mention handle — a nameless org cannot be mentioned. */
|
|
83
|
+
export declare function setTopicAssistant(board: ChannelV1[], channelId: string, assistant: TopicAssistantV1 | undefined): BoardResult<{
|
|
84
|
+
channel: ChannelV1;
|
|
85
|
+
}>;
|
|
86
|
+
/** Enable/refresh (`routing` set) or disable (`routing` undefined) member routing on a topic
|
|
87
|
+
* (spec 329 §7). Enabling REQUIRES the 327 assistant to be on (routing is a mode of the
|
|
88
|
+
* assistant's turn); fan-out is clamped fail-closed to the approved 1..5 window. Disabling the
|
|
89
|
+
* ASSISTANT also disables routing transitively (setTopicAssistant clears it below). */
|
|
90
|
+
export declare function setTopicRouting(board: ChannelV1[], channelId: string, routing: TopicRoutingV1 | undefined): BoardResult<{
|
|
91
|
+
channel: ChannelV1;
|
|
92
|
+
}>;
|
|
21
93
|
export type BoardResult<T> = {
|
|
22
94
|
ok: true;
|
|
23
95
|
} & T | {
|
|
@@ -33,6 +105,7 @@ export declare function createBoardChannel(board: ChannelV1[], opts: {
|
|
|
33
105
|
title: string;
|
|
34
106
|
createdBy: string;
|
|
35
107
|
now?: string;
|
|
108
|
+
participationPolicy?: 'open' | 'restricted';
|
|
36
109
|
visibility?: 'public' | 'private';
|
|
37
110
|
members?: string[];
|
|
38
111
|
creatorSa?: string;
|
|
@@ -48,7 +121,14 @@ export declare function appendBoardPost(board: ChannelV1[], opts: {
|
|
|
48
121
|
authorName: string;
|
|
49
122
|
bodyText: string;
|
|
50
123
|
now?: string;
|
|
124
|
+
actor?: CanonicalAgentId;
|
|
125
|
+
/** spec 329 §6 — EXTRA context refs beyond the channel's own (the `routed-consultation` chip on
|
|
126
|
+
* the turn-1 status + turn-2 synthesis). Appended after the descriptor refs, deduped by
|
|
127
|
+
* kind+id; the envelope validator's MAX_CONTEXT_REFS bound still applies (fail-closed). */
|
|
128
|
+
contextRefs?: ContextRefV1[];
|
|
129
|
+
/** spec 329 §6 — PROV attribution stored on the entry (synthesis posts only). */
|
|
130
|
+
prov?: ConsultProvenanceV1;
|
|
51
131
|
}): Promise<BoardResult<{
|
|
52
|
-
envelope:
|
|
132
|
+
envelope: AnyMessageEnvelope;
|
|
53
133
|
}>>;
|
|
54
134
|
//# sourceMappingURL=board.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board.d.ts","sourceRoot":"","sources":["../../src/messaging/board.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;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AK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E;;6FAE6F;AAC7F,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,EAAE,EAClB,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3N,WAAW,CAAC;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,CAAC,CAkCrC;AAED;;uFAEuF;AACvF,wBAAsB,eAAe,CACnC,KAAK,EAAE,SAAS,EAAE,EAClB,IAAI,EAAE;IACJ,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACxH;;gGAE4F;IAC5F,WAAW,CAAC,EAAE,YAAY,EAAE,CAAC;IAC7B,iFAAiF;IACjF,IAAI,CAAC,EAAE,mBAAmB,CAAC;CAC5B,GACA,OAAO,CAAC,WAAW,CAAC;IAAE,QAAQ,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAAC,CAmCxD"}
|
package/dist/messaging/board.js
CHANGED
|
@@ -2,10 +2,19 @@ import { generateConversationId, generateMessageId, validateMessageEnvelope } fr
|
|
|
2
2
|
import { sha256Hex32 } from './hash.js';
|
|
3
3
|
import { validateConversationDescriptor } from './conversation.js';
|
|
4
4
|
import { topicBodyResource } from './vault-store.js';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { ROUTING_FANOUT_DEFAULT, ROUTING_FANOUT_MAX, ROUTING_FANOUT_MIN } from './consult.js';
|
|
6
|
+
/** Resolve a topic's participation policy, mapping the legacy `visibility` wire field
|
|
7
|
+
* (public→open, private→restricted). Absent both ⇒ open (the default + all legacy topics). */
|
|
8
|
+
export function channelParticipationPolicy(channel) {
|
|
9
|
+
if (channel.participationPolicy)
|
|
10
|
+
return channel.participationPolicy;
|
|
11
|
+
return channel.visibility === 'private' ? 'restricted' : 'open';
|
|
12
|
+
}
|
|
13
|
+
/** Can `viewerSa` (0x) see this topic? OPEN ⇒ always (every org member; the caller already gated org
|
|
14
|
+
* membership). RESTRICTED ⇒ only listed participants. `isSteward` overrides (a steward/custodian is a
|
|
15
|
+
* facilitator of every topic). One mechanism — used by the store list + the UI. */
|
|
7
16
|
export function canSeeChannel(channel, viewerSa, isSteward = false) {
|
|
8
|
-
if (channel
|
|
17
|
+
if (channelParticipationPolicy(channel) === 'open')
|
|
9
18
|
return true;
|
|
10
19
|
if (isSteward)
|
|
11
20
|
return true;
|
|
@@ -14,6 +23,82 @@ export function canSeeChannel(channel, viewerSa, isSteward = false) {
|
|
|
14
23
|
}
|
|
15
24
|
/** Bounded per-channel history in the board doc (projection only — bodies live in the vault). */
|
|
16
25
|
export const BOARD_HISTORY_LIMIT = 200;
|
|
26
|
+
/** Should a just-committed post trigger the topic's org assistant (spec 327 §3)? Pure predicate —
|
|
27
|
+
* the caller supplies the posted body text (it never round-trips through the stored entry, whose
|
|
28
|
+
* body is hash-bound in the vault). False when the assistant is off, when the post is itself
|
|
29
|
+
* agent-authored (`actor` set), or when the author IS the org — the community contextRef, NOT
|
|
30
|
+
* `descriptor.owner` (that is the topic CREATOR) — so the assistant NEVER triggers itself, even
|
|
31
|
+
* in `trigger:'all'` topics. */
|
|
32
|
+
export function assistantTrigger(channel, post) {
|
|
33
|
+
const assistant = channel.assistant;
|
|
34
|
+
if (!assistant)
|
|
35
|
+
return false;
|
|
36
|
+
if (post.actor)
|
|
37
|
+
return false;
|
|
38
|
+
const org = channel.descriptor.contextRefs?.find((r) => r.kind === 'community')?.id?.toLowerCase();
|
|
39
|
+
if (org && String(post.from).toLowerCase().endsWith(org))
|
|
40
|
+
return false;
|
|
41
|
+
if (assistant.trigger === 'all')
|
|
42
|
+
return true;
|
|
43
|
+
const handle = assistant.mentionHandle.trim().toLowerCase();
|
|
44
|
+
if (!handle)
|
|
45
|
+
return false;
|
|
46
|
+
// @handle, optionally with its dotted parent name (@handle.<parent>…) — TLD-agnostic (the parent
|
|
47
|
+
// registry is app config, never package vocabulary — ADR-0021). Case-insensitive, word-bounded
|
|
48
|
+
// (name labels are [a-z0-9-]); a preceding name char (e.g. an email local part) is not a mention.
|
|
49
|
+
const esc = handle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
50
|
+
const mention = new RegExp(`(?:^|[^a-z0-9-])@${esc}(?:\\.[a-z0-9-]+)*(?![a-z0-9-])`, 'i');
|
|
51
|
+
if (mention.test(post.bodyText))
|
|
52
|
+
return true;
|
|
53
|
+
// `@ask` — the universal, org-agnostic assistant alias: members shouldn't have to remember the
|
|
54
|
+
// org's handle to talk to its assistant. Same word-bounding rules; only meaningful where an
|
|
55
|
+
// assistant is enabled, so it can never mis-route across orgs.
|
|
56
|
+
return ASK_ALIAS.test(post.bodyText);
|
|
57
|
+
}
|
|
58
|
+
const ASK_ALIAS = /(?:^|[^a-z0-9-])@ask(?![a-z0-9-])/i;
|
|
59
|
+
/** Enable/refresh (`assistant` set) or disable (`assistant` undefined) the org assistant on a topic
|
|
60
|
+
* (mutates the channel on success). Steward gating + audit are the caller's, as with every board
|
|
61
|
+
* mutation. `trigger:'mention'` requires a mention handle — a nameless org cannot be mentioned. */
|
|
62
|
+
export function setTopicAssistant(board, channelId, assistant) {
|
|
63
|
+
const channel = board.find((c) => c.descriptor.id === channelId);
|
|
64
|
+
if (!channel)
|
|
65
|
+
return { ok: false, error: 'unknown channel' };
|
|
66
|
+
if (!assistant) {
|
|
67
|
+
delete channel.assistant;
|
|
68
|
+
// spec 329 §8 — assistant off ⇒ routing off transitively (routing is a mode of the assistant).
|
|
69
|
+
delete channel.routing;
|
|
70
|
+
return { ok: true, channel };
|
|
71
|
+
}
|
|
72
|
+
const mentionHandle = assistant.mentionHandle.trim().toLowerCase();
|
|
73
|
+
if (assistant.trigger === 'mention' && !mentionHandle) {
|
|
74
|
+
return { ok: false, error: 'mention trigger requires the org to have a primary name' };
|
|
75
|
+
}
|
|
76
|
+
if (!assistant.displayName.trim())
|
|
77
|
+
return { ok: false, error: 'displayName required' };
|
|
78
|
+
channel.assistant = { ...assistant, mentionHandle };
|
|
79
|
+
return { ok: true, channel };
|
|
80
|
+
}
|
|
81
|
+
/** Enable/refresh (`routing` set) or disable (`routing` undefined) member routing on a topic
|
|
82
|
+
* (spec 329 §7). Enabling REQUIRES the 327 assistant to be on (routing is a mode of the
|
|
83
|
+
* assistant's turn); fan-out is clamped fail-closed to the approved 1..5 window. Disabling the
|
|
84
|
+
* ASSISTANT also disables routing transitively (setTopicAssistant clears it below). */
|
|
85
|
+
export function setTopicRouting(board, channelId, routing) {
|
|
86
|
+
const channel = board.find((c) => c.descriptor.id === channelId);
|
|
87
|
+
if (!channel)
|
|
88
|
+
return { ok: false, error: 'unknown channel' };
|
|
89
|
+
if (!routing) {
|
|
90
|
+
delete channel.routing;
|
|
91
|
+
return { ok: true, channel };
|
|
92
|
+
}
|
|
93
|
+
if (!channel.assistant)
|
|
94
|
+
return { ok: false, error: 'routing requires the topic assistant to be enabled first' };
|
|
95
|
+
const raw = Number(routing.maxFanout);
|
|
96
|
+
const maxFanout = Number.isFinite(raw)
|
|
97
|
+
? Math.min(Math.max(Math.round(raw), ROUTING_FANOUT_MIN), ROUTING_FANOUT_MAX)
|
|
98
|
+
: ROUTING_FANOUT_DEFAULT;
|
|
99
|
+
channel.routing = { ...routing, maxFanout };
|
|
100
|
+
return { ok: true, channel };
|
|
101
|
+
}
|
|
17
102
|
/** Create a channel on the board (mutates `board` on success). Title-unique per context.
|
|
18
103
|
* `contextId` is the org/context SA (substrate vocabulary — spec 322 §5; the wire literal
|
|
19
104
|
* `kind:'community'` is inside signed hashes and renames only at 316's envelope re-cut). */
|
|
@@ -24,7 +109,8 @@ export function createBoardChannel(board, opts) {
|
|
|
24
109
|
if (board.some((c) => c.title.toLowerCase() === title.toLowerCase())) {
|
|
25
110
|
return { ok: false, error: 'a channel with this title already exists' };
|
|
26
111
|
}
|
|
27
|
-
|
|
112
|
+
// New callers say participationPolicy; legacy callers say visibility. restricted ≡ private.
|
|
113
|
+
const isPrivate = opts.participationPolicy ? opts.participationPolicy === 'restricted' : opts.visibility === 'private';
|
|
28
114
|
const descriptor = {
|
|
29
115
|
version: 'ap.conversation.v1',
|
|
30
116
|
id: generateConversationId(),
|
|
@@ -40,12 +126,14 @@ export function createBoardChannel(board, opts) {
|
|
|
40
126
|
const errors = validateConversationDescriptor(descriptor);
|
|
41
127
|
if (errors.length > 0)
|
|
42
128
|
return { ok: false, error: `invalid channel: ${errors.join(', ')}` };
|
|
43
|
-
// The creator is always a
|
|
129
|
+
// The creator is always a participant of a restricted topic; dedupe + lowercase.
|
|
44
130
|
const members = isPrivate
|
|
45
131
|
? [...new Set([opts.creatorSa?.toLowerCase(), ...(opts.members ?? []).map((m) => m.toLowerCase())].filter((m) => !!m))]
|
|
46
132
|
: undefined;
|
|
47
133
|
const channel = {
|
|
48
134
|
descriptor, title, createdBy: opts.createdBy, messages: [],
|
|
135
|
+
// Dual-write: participationPolicy is the vocabulary; visibility stays for legacy readers.
|
|
136
|
+
participationPolicy: isPrivate ? 'restricted' : 'open',
|
|
49
137
|
...(isPrivate ? { visibility: 'private', members } : {}),
|
|
50
138
|
};
|
|
51
139
|
board.push(channel);
|
|
@@ -63,11 +151,14 @@ export async function appendBoardPost(board, opts) {
|
|
|
63
151
|
return { ok: false, error: 'unknown channel' };
|
|
64
152
|
const now = opts.now ?? new Date().toISOString();
|
|
65
153
|
const messageId = generateMessageId();
|
|
154
|
+
const baseRefs = channel.descriptor.contextRefs ?? [];
|
|
155
|
+
const extraRefs = (opts.contextRefs ?? []).filter((r) => !baseRefs.some((b) => b.kind === r.kind && b.id === r.id));
|
|
156
|
+
const contextRefs = [...baseRefs, ...extraRefs];
|
|
66
157
|
const envelope = {
|
|
67
|
-
version: 'ap.message.
|
|
158
|
+
version: 'ap.message.v2',
|
|
68
159
|
id: messageId,
|
|
69
160
|
conversationId: channel.descriptor.id,
|
|
70
|
-
|
|
161
|
+
performative: 'INFORM',
|
|
71
162
|
from: opts.from,
|
|
72
163
|
// Shared-board addressing: the descriptor's owner stands for the board (spec 313 §6).
|
|
73
164
|
to: [channel.descriptor.owner],
|
|
@@ -76,12 +167,12 @@ export async function appendBoardPost(board, opts) {
|
|
|
76
167
|
body: { resource: topicBodyResource(channel.descriptor.id, messageId), classification: 'internal', updatedAt: now },
|
|
77
168
|
bodyHash: await sha256Hex32(new TextEncoder().encode(bodyText)),
|
|
78
169
|
bodyContentType: 'text/plain',
|
|
79
|
-
contextRefs
|
|
170
|
+
contextRefs,
|
|
80
171
|
};
|
|
81
172
|
const errors = validateMessageEnvelope(envelope);
|
|
82
173
|
if (errors.length > 0)
|
|
83
174
|
return { ok: false, error: `invalid post: ${errors.join(', ')}` };
|
|
84
|
-
channel.messages.push({ envelope, authorName: opts.authorName });
|
|
175
|
+
channel.messages.push({ envelope, authorName: opts.authorName, ...(opts.actor ? { actor: opts.actor } : {}), ...(opts.prov ? { prov: opts.prov } : {}) });
|
|
85
176
|
if (channel.messages.length > BOARD_HISTORY_LIMIT) {
|
|
86
177
|
channel.messages.splice(0, channel.messages.length - BOARD_HISTORY_LIMIT);
|
|
87
178
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board.js","sourceRoot":"","sources":["../../src/messaging/board.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,uBAAu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