@brightbeamai/chap-coordinator 0.2.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.
Files changed (53) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +271 -0
  3. package/dist/api-C3nkEk-B.d.cts +260 -0
  4. package/dist/api-CmSvlIqO.d.ts +260 -0
  5. package/dist/api.cjs +125 -0
  6. package/dist/api.cjs.map +1 -0
  7. package/dist/api.d.cts +4 -0
  8. package/dist/api.d.ts +4 -0
  9. package/dist/api.js +98 -0
  10. package/dist/api.js.map +1 -0
  11. package/dist/index.cjs +2804 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.cts +175 -0
  14. package/dist/index.d.ts +175 -0
  15. package/dist/index.js +2762 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/jsonrpc.cjs +103 -0
  18. package/dist/jsonrpc.cjs.map +1 -0
  19. package/dist/jsonrpc.d.cts +65 -0
  20. package/dist/jsonrpc.d.ts +65 -0
  21. package/dist/jsonrpc.js +76 -0
  22. package/dist/jsonrpc.js.map +1 -0
  23. package/dist/methods.cjs +19 -0
  24. package/dist/methods.cjs.map +1 -0
  25. package/dist/methods.d.cts +455 -0
  26. package/dist/methods.d.ts +455 -0
  27. package/dist/methods.js +1 -0
  28. package/dist/methods.js.map +1 -0
  29. package/dist/patch.cjs +277 -0
  30. package/dist/patch.cjs.map +1 -0
  31. package/dist/patch.d.cts +29 -0
  32. package/dist/patch.d.ts +29 -0
  33. package/dist/patch.js +250 -0
  34. package/dist/patch.js.map +1 -0
  35. package/dist/storage/sqlite.cjs +94 -0
  36. package/dist/storage/sqlite.cjs.map +1 -0
  37. package/dist/storage/sqlite.d.cts +67 -0
  38. package/dist/storage/sqlite.d.ts +67 -0
  39. package/dist/storage/sqlite.js +76 -0
  40. package/dist/storage/sqlite.js.map +1 -0
  41. package/dist/storage/store.cjs +45 -0
  42. package/dist/storage/store.cjs.map +1 -0
  43. package/dist/storage/store.d.cts +53 -0
  44. package/dist/storage/store.d.ts +53 -0
  45. package/dist/storage/store.js +20 -0
  46. package/dist/storage/store.js.map +1 -0
  47. package/dist/types.cjs +34 -0
  48. package/dist/types.cjs.map +1 -0
  49. package/dist/types.d.cts +287 -0
  50. package/dist/types.d.ts +287 -0
  51. package/dist/types.js +9 -0
  52. package/dist/types.js.map +1 -0
  53. package/package.json +52 -0
@@ -0,0 +1,287 @@
1
+ /**
2
+ * @brightbeamai/chap-coordinator. type vocabulary
3
+ *
4
+ * Wire-shape and in-memory types for the Coordinator. The schemas at
5
+ * schemas/ are the normative wire types; these mirror them in
6
+ * TypeScript for in-process use.
7
+ */
8
+ type ParticipantUri = string;
9
+ type WorkspaceId = string;
10
+ type TaskId = string;
11
+ type ArtefactId = string;
12
+ type ParticipantType = "human" | "agent" | "service" | "group" | "workspace";
13
+ interface Envelope {
14
+ jsonrpc: "2.0";
15
+ id?: string | number;
16
+ method?: string;
17
+ params?: Record<string, unknown>;
18
+ result?: unknown;
19
+ error?: {
20
+ code: number;
21
+ message: string;
22
+ data?: unknown;
23
+ };
24
+ /** security-signed/1.0: top-level signature, signed over JCS of the
25
+ * envelope with this field removed. Form: ``ed25519:<kid>:<b64>``. */
26
+ sig?: string;
27
+ }
28
+ type Mode = "shadow" | "trial" | "production";
29
+ type WorkspaceState = "active" | "paused" | "closed";
30
+ type PauseScope = "task" | "participant" | "workspace";
31
+ type TaskState = "created" | "in_progress" | "review_requested" | "completed" | "declined" | "abstained" | "escalated" | "superseded" | "paused" | "cancelled";
32
+ interface Jwk {
33
+ kty: "OKP";
34
+ crv: "Ed25519";
35
+ kid: string;
36
+ x: string;
37
+ use?: string;
38
+ alg?: string;
39
+ }
40
+ /** A participant's JWK plus the validity window. Lookup by
41
+ * (participant, kid, ts) so historical envelopes verify across
42
+ * rotation per security-signed/1.0 S3-S5. */
43
+ interface KeyRecord {
44
+ jwk: Jwk;
45
+ kid: string;
46
+ valid_from: string;
47
+ valid_until?: string;
48
+ revoked_at?: string;
49
+ revoked_reason?: string;
50
+ }
51
+ interface Member {
52
+ uri: ParticipantUri;
53
+ type: ParticipantType;
54
+ role: string;
55
+ joined: string;
56
+ display_name?: string;
57
+ capabilities?: Record<string, unknown>;
58
+ scopes?: string[];
59
+ keys: KeyRecord[];
60
+ paused: boolean;
61
+ oidc_sub?: string;
62
+ oidc_auth_time?: number;
63
+ vc_holder?: string;
64
+ }
65
+ interface TaskRoutingHints {
66
+ criticality?: "low" | "medium" | "high" | "critical";
67
+ deadline?: string;
68
+ max_cost_usd?: number;
69
+ risk_tier?: string;
70
+ [extra: string]: unknown;
71
+ }
72
+ interface ArtefactRoutingHints {
73
+ confidence?: number | string;
74
+ model_id?: string;
75
+ cost_consumed_usd?: number;
76
+ latency_ms?: number;
77
+ [extra: string]: unknown;
78
+ }
79
+ interface JsonPatchOp {
80
+ op: "add" | "replace" | "remove" | "copy" | "move" | "test";
81
+ path: string;
82
+ value?: unknown;
83
+ from?: string;
84
+ }
85
+ interface OverrideArtefact {
86
+ id: ArtefactId;
87
+ task_id: TaskId;
88
+ reviewer: ParticipantUri;
89
+ based_on_artefact: unknown;
90
+ diff: JsonPatchOp[];
91
+ result: unknown;
92
+ rationale: string;
93
+ tags: string[];
94
+ policy_refs: string[];
95
+ ts: string;
96
+ logical_id?: string;
97
+ instance_id?: string;
98
+ intent_preserved?: boolean;
99
+ }
100
+ interface RouteDecisionArtefact {
101
+ id: ArtefactId;
102
+ kind: "route_decision";
103
+ decision_type: "task.route" | "review.depth" | "escalate.auto";
104
+ outcome: unknown;
105
+ produced_by: ParticipantUri;
106
+ produced_at: string;
107
+ task?: TaskId;
108
+ policy_id?: string;
109
+ hints_observed: Record<string, unknown>;
110
+ rationale: string;
111
+ [extra: string]: unknown;
112
+ }
113
+ interface SnapshotArtefact {
114
+ id: ArtefactId;
115
+ kind: "snapshot";
116
+ ts: string;
117
+ by: ParticipantUri;
118
+ workspace: WorkspaceId;
119
+ audit_seq: number;
120
+ label?: string;
121
+ include: string[];
122
+ state: Record<string, unknown>;
123
+ }
124
+ interface WhisperPrompt {
125
+ id: ArtefactId;
126
+ task_id: TaskId;
127
+ asker: ParticipantUri;
128
+ askee: ParticipantUri[];
129
+ question: string;
130
+ options?: Array<{
131
+ id: string;
132
+ label?: string;
133
+ }>;
134
+ asked_at: string;
135
+ deadline_ms: number;
136
+ default_if_lapsed: unknown;
137
+ urgency: "low" | "medium" | "high";
138
+ state: "pending" | "answered" | "lapsed";
139
+ answered_at?: string;
140
+ answered_by?: ParticipantUri;
141
+ answer_option?: string;
142
+ answer_text?: string;
143
+ comment?: string;
144
+ default_applied?: unknown;
145
+ }
146
+ interface DeliberationVote {
147
+ ts: string;
148
+ voter: ParticipantUri;
149
+ vote: "yea" | "nay" | "abstain";
150
+ weight?: number;
151
+ comment?: string;
152
+ veto_invoked?: boolean;
153
+ }
154
+ interface Deliberation {
155
+ id: string;
156
+ task_id?: TaskId;
157
+ opener: ParticipantUri;
158
+ participants: ParticipantUri[];
159
+ rule: string;
160
+ question?: string;
161
+ weights?: Record<ParticipantUri, number>;
162
+ veto?: Record<ParticipantUri, boolean>;
163
+ deadline?: string;
164
+ state: "open" | "closed" | "lapsed";
165
+ comments: {
166
+ ts: string;
167
+ from: ParticipantUri;
168
+ text: string;
169
+ }[];
170
+ votes: DeliberationVote[];
171
+ outcome?: {
172
+ outcome: "approved" | "rejected" | "error";
173
+ rule: string;
174
+ tally?: {
175
+ yea: number;
176
+ nay: number;
177
+ };
178
+ vetoes?: ParticipantUri[];
179
+ reason?: string;
180
+ };
181
+ opened_at: string;
182
+ }
183
+ interface HandoffTaskItem {
184
+ task_id: TaskId;
185
+ title?: string;
186
+ status_summary?: string;
187
+ next_action?: string;
188
+ blockers?: string[];
189
+ }
190
+ interface Handoff {
191
+ id: string;
192
+ proposer: ParticipantUri;
193
+ recipient: ParticipantUri;
194
+ proposed_at: string;
195
+ tasks: HandoffTaskItem[];
196
+ summary?: string;
197
+ context_links: string[];
198
+ state: "proposed" | "accepted" | "declined";
199
+ resolved_at?: string;
200
+ accepted_by?: ParticipantUri;
201
+ accepted_task_ids?: TaskId[];
202
+ accept_comment?: string;
203
+ decline_reason?: string;
204
+ decline_suggested_target?: ParticipantUri;
205
+ }
206
+ interface ReviewDecision {
207
+ reviewer: ParticipantUri;
208
+ kind: "approve" | "reject" | "override" | "abstain";
209
+ ts: string;
210
+ comment?: string;
211
+ tags?: string[];
212
+ override_artefact_id?: ArtefactId;
213
+ abstain_category?: string;
214
+ }
215
+ interface Task {
216
+ id: TaskId;
217
+ kind: string;
218
+ state: TaskState;
219
+ assignee: ParticipantUri;
220
+ delegator: ParticipantUri;
221
+ input: Record<string, unknown>;
222
+ output?: unknown;
223
+ confidence?: number | string;
224
+ deadline?: string;
225
+ created_at: string;
226
+ updated_at: string;
227
+ mode: Mode;
228
+ review_required?: boolean;
229
+ routing_hints?: TaskRoutingHints;
230
+ artefact_routing_hints?: ArtefactRoutingHints;
231
+ review?: {
232
+ requested_at: string;
233
+ requested_to: ParticipantUri[];
234
+ rule: string;
235
+ deadline?: string;
236
+ decisions: ReviewDecision[];
237
+ };
238
+ history: {
239
+ ts: string;
240
+ from: ParticipantUri;
241
+ state: TaskState;
242
+ note?: string;
243
+ }[];
244
+ supersedes?: TaskId;
245
+ superseded_by?: TaskId;
246
+ parent?: TaskId;
247
+ paused: boolean;
248
+ /** Transient: holds the artefact passed to review.request so
249
+ * decide.override can use it as the patch base. */
250
+ pending_artefact?: unknown;
251
+ }
252
+ interface AuditEntry {
253
+ seq: number;
254
+ arrived: string;
255
+ envelope: Envelope;
256
+ prev_hash?: string;
257
+ }
258
+ interface Workspace {
259
+ id: WorkspaceId;
260
+ created: string;
261
+ state: WorkspaceState;
262
+ profiles: string[];
263
+ mode: Mode;
264
+ mode_ceiling: Mode;
265
+ routing_policy_uri?: string;
266
+ step_up_window_sec: number;
267
+ members: Map<ParticipantUri, Member>;
268
+ tasks: Map<TaskId, Task>;
269
+ overrides: Map<ArtefactId, OverrideArtefact>;
270
+ whispers: Map<string, WhisperPrompt>;
271
+ deliberations: Map<string, Deliberation>;
272
+ handoffs: Map<string, Handoff>;
273
+ snapshots: Map<ArtefactId, SnapshotArtefact>;
274
+ route_decisions: Map<ArtefactId, RouteDecisionArtefact>;
275
+ audit: AuditEntry[];
276
+ chain_head?: string;
277
+ chain_enabled: boolean;
278
+ }
279
+ /**
280
+ * Listener callback invoked synchronously when an envelope is appended
281
+ * to the workspace audit log.
282
+ */
283
+ type AuditListener = (workspace: Workspace, entry: AuditEntry) => void;
284
+ /** True iff mode `a` is <= ceiling. */
285
+ declare function modeLE(a: Mode, ceiling: Mode): boolean;
286
+
287
+ export { type ArtefactId, type ArtefactRoutingHints, type AuditEntry, type AuditListener, type Deliberation, type DeliberationVote, type Envelope, type Handoff, type HandoffTaskItem, type JsonPatchOp, type Jwk, type KeyRecord, type Member, type Mode, type OverrideArtefact, type ParticipantType, type ParticipantUri, type PauseScope, type ReviewDecision, type RouteDecisionArtefact, type SnapshotArtefact, type Task, type TaskId, type TaskRoutingHints, type TaskState, type WhisperPrompt, type Workspace, type WorkspaceId, type WorkspaceState, modeLE };
@@ -0,0 +1,287 @@
1
+ /**
2
+ * @brightbeamai/chap-coordinator. type vocabulary
3
+ *
4
+ * Wire-shape and in-memory types for the Coordinator. The schemas at
5
+ * schemas/ are the normative wire types; these mirror them in
6
+ * TypeScript for in-process use.
7
+ */
8
+ type ParticipantUri = string;
9
+ type WorkspaceId = string;
10
+ type TaskId = string;
11
+ type ArtefactId = string;
12
+ type ParticipantType = "human" | "agent" | "service" | "group" | "workspace";
13
+ interface Envelope {
14
+ jsonrpc: "2.0";
15
+ id?: string | number;
16
+ method?: string;
17
+ params?: Record<string, unknown>;
18
+ result?: unknown;
19
+ error?: {
20
+ code: number;
21
+ message: string;
22
+ data?: unknown;
23
+ };
24
+ /** security-signed/1.0: top-level signature, signed over JCS of the
25
+ * envelope with this field removed. Form: ``ed25519:<kid>:<b64>``. */
26
+ sig?: string;
27
+ }
28
+ type Mode = "shadow" | "trial" | "production";
29
+ type WorkspaceState = "active" | "paused" | "closed";
30
+ type PauseScope = "task" | "participant" | "workspace";
31
+ type TaskState = "created" | "in_progress" | "review_requested" | "completed" | "declined" | "abstained" | "escalated" | "superseded" | "paused" | "cancelled";
32
+ interface Jwk {
33
+ kty: "OKP";
34
+ crv: "Ed25519";
35
+ kid: string;
36
+ x: string;
37
+ use?: string;
38
+ alg?: string;
39
+ }
40
+ /** A participant's JWK plus the validity window. Lookup by
41
+ * (participant, kid, ts) so historical envelopes verify across
42
+ * rotation per security-signed/1.0 S3-S5. */
43
+ interface KeyRecord {
44
+ jwk: Jwk;
45
+ kid: string;
46
+ valid_from: string;
47
+ valid_until?: string;
48
+ revoked_at?: string;
49
+ revoked_reason?: string;
50
+ }
51
+ interface Member {
52
+ uri: ParticipantUri;
53
+ type: ParticipantType;
54
+ role: string;
55
+ joined: string;
56
+ display_name?: string;
57
+ capabilities?: Record<string, unknown>;
58
+ scopes?: string[];
59
+ keys: KeyRecord[];
60
+ paused: boolean;
61
+ oidc_sub?: string;
62
+ oidc_auth_time?: number;
63
+ vc_holder?: string;
64
+ }
65
+ interface TaskRoutingHints {
66
+ criticality?: "low" | "medium" | "high" | "critical";
67
+ deadline?: string;
68
+ max_cost_usd?: number;
69
+ risk_tier?: string;
70
+ [extra: string]: unknown;
71
+ }
72
+ interface ArtefactRoutingHints {
73
+ confidence?: number | string;
74
+ model_id?: string;
75
+ cost_consumed_usd?: number;
76
+ latency_ms?: number;
77
+ [extra: string]: unknown;
78
+ }
79
+ interface JsonPatchOp {
80
+ op: "add" | "replace" | "remove" | "copy" | "move" | "test";
81
+ path: string;
82
+ value?: unknown;
83
+ from?: string;
84
+ }
85
+ interface OverrideArtefact {
86
+ id: ArtefactId;
87
+ task_id: TaskId;
88
+ reviewer: ParticipantUri;
89
+ based_on_artefact: unknown;
90
+ diff: JsonPatchOp[];
91
+ result: unknown;
92
+ rationale: string;
93
+ tags: string[];
94
+ policy_refs: string[];
95
+ ts: string;
96
+ logical_id?: string;
97
+ instance_id?: string;
98
+ intent_preserved?: boolean;
99
+ }
100
+ interface RouteDecisionArtefact {
101
+ id: ArtefactId;
102
+ kind: "route_decision";
103
+ decision_type: "task.route" | "review.depth" | "escalate.auto";
104
+ outcome: unknown;
105
+ produced_by: ParticipantUri;
106
+ produced_at: string;
107
+ task?: TaskId;
108
+ policy_id?: string;
109
+ hints_observed: Record<string, unknown>;
110
+ rationale: string;
111
+ [extra: string]: unknown;
112
+ }
113
+ interface SnapshotArtefact {
114
+ id: ArtefactId;
115
+ kind: "snapshot";
116
+ ts: string;
117
+ by: ParticipantUri;
118
+ workspace: WorkspaceId;
119
+ audit_seq: number;
120
+ label?: string;
121
+ include: string[];
122
+ state: Record<string, unknown>;
123
+ }
124
+ interface WhisperPrompt {
125
+ id: ArtefactId;
126
+ task_id: TaskId;
127
+ asker: ParticipantUri;
128
+ askee: ParticipantUri[];
129
+ question: string;
130
+ options?: Array<{
131
+ id: string;
132
+ label?: string;
133
+ }>;
134
+ asked_at: string;
135
+ deadline_ms: number;
136
+ default_if_lapsed: unknown;
137
+ urgency: "low" | "medium" | "high";
138
+ state: "pending" | "answered" | "lapsed";
139
+ answered_at?: string;
140
+ answered_by?: ParticipantUri;
141
+ answer_option?: string;
142
+ answer_text?: string;
143
+ comment?: string;
144
+ default_applied?: unknown;
145
+ }
146
+ interface DeliberationVote {
147
+ ts: string;
148
+ voter: ParticipantUri;
149
+ vote: "yea" | "nay" | "abstain";
150
+ weight?: number;
151
+ comment?: string;
152
+ veto_invoked?: boolean;
153
+ }
154
+ interface Deliberation {
155
+ id: string;
156
+ task_id?: TaskId;
157
+ opener: ParticipantUri;
158
+ participants: ParticipantUri[];
159
+ rule: string;
160
+ question?: string;
161
+ weights?: Record<ParticipantUri, number>;
162
+ veto?: Record<ParticipantUri, boolean>;
163
+ deadline?: string;
164
+ state: "open" | "closed" | "lapsed";
165
+ comments: {
166
+ ts: string;
167
+ from: ParticipantUri;
168
+ text: string;
169
+ }[];
170
+ votes: DeliberationVote[];
171
+ outcome?: {
172
+ outcome: "approved" | "rejected" | "error";
173
+ rule: string;
174
+ tally?: {
175
+ yea: number;
176
+ nay: number;
177
+ };
178
+ vetoes?: ParticipantUri[];
179
+ reason?: string;
180
+ };
181
+ opened_at: string;
182
+ }
183
+ interface HandoffTaskItem {
184
+ task_id: TaskId;
185
+ title?: string;
186
+ status_summary?: string;
187
+ next_action?: string;
188
+ blockers?: string[];
189
+ }
190
+ interface Handoff {
191
+ id: string;
192
+ proposer: ParticipantUri;
193
+ recipient: ParticipantUri;
194
+ proposed_at: string;
195
+ tasks: HandoffTaskItem[];
196
+ summary?: string;
197
+ context_links: string[];
198
+ state: "proposed" | "accepted" | "declined";
199
+ resolved_at?: string;
200
+ accepted_by?: ParticipantUri;
201
+ accepted_task_ids?: TaskId[];
202
+ accept_comment?: string;
203
+ decline_reason?: string;
204
+ decline_suggested_target?: ParticipantUri;
205
+ }
206
+ interface ReviewDecision {
207
+ reviewer: ParticipantUri;
208
+ kind: "approve" | "reject" | "override" | "abstain";
209
+ ts: string;
210
+ comment?: string;
211
+ tags?: string[];
212
+ override_artefact_id?: ArtefactId;
213
+ abstain_category?: string;
214
+ }
215
+ interface Task {
216
+ id: TaskId;
217
+ kind: string;
218
+ state: TaskState;
219
+ assignee: ParticipantUri;
220
+ delegator: ParticipantUri;
221
+ input: Record<string, unknown>;
222
+ output?: unknown;
223
+ confidence?: number | string;
224
+ deadline?: string;
225
+ created_at: string;
226
+ updated_at: string;
227
+ mode: Mode;
228
+ review_required?: boolean;
229
+ routing_hints?: TaskRoutingHints;
230
+ artefact_routing_hints?: ArtefactRoutingHints;
231
+ review?: {
232
+ requested_at: string;
233
+ requested_to: ParticipantUri[];
234
+ rule: string;
235
+ deadline?: string;
236
+ decisions: ReviewDecision[];
237
+ };
238
+ history: {
239
+ ts: string;
240
+ from: ParticipantUri;
241
+ state: TaskState;
242
+ note?: string;
243
+ }[];
244
+ supersedes?: TaskId;
245
+ superseded_by?: TaskId;
246
+ parent?: TaskId;
247
+ paused: boolean;
248
+ /** Transient: holds the artefact passed to review.request so
249
+ * decide.override can use it as the patch base. */
250
+ pending_artefact?: unknown;
251
+ }
252
+ interface AuditEntry {
253
+ seq: number;
254
+ arrived: string;
255
+ envelope: Envelope;
256
+ prev_hash?: string;
257
+ }
258
+ interface Workspace {
259
+ id: WorkspaceId;
260
+ created: string;
261
+ state: WorkspaceState;
262
+ profiles: string[];
263
+ mode: Mode;
264
+ mode_ceiling: Mode;
265
+ routing_policy_uri?: string;
266
+ step_up_window_sec: number;
267
+ members: Map<ParticipantUri, Member>;
268
+ tasks: Map<TaskId, Task>;
269
+ overrides: Map<ArtefactId, OverrideArtefact>;
270
+ whispers: Map<string, WhisperPrompt>;
271
+ deliberations: Map<string, Deliberation>;
272
+ handoffs: Map<string, Handoff>;
273
+ snapshots: Map<ArtefactId, SnapshotArtefact>;
274
+ route_decisions: Map<ArtefactId, RouteDecisionArtefact>;
275
+ audit: AuditEntry[];
276
+ chain_head?: string;
277
+ chain_enabled: boolean;
278
+ }
279
+ /**
280
+ * Listener callback invoked synchronously when an envelope is appended
281
+ * to the workspace audit log.
282
+ */
283
+ type AuditListener = (workspace: Workspace, entry: AuditEntry) => void;
284
+ /** True iff mode `a` is <= ceiling. */
285
+ declare function modeLE(a: Mode, ceiling: Mode): boolean;
286
+
287
+ export { type ArtefactId, type ArtefactRoutingHints, type AuditEntry, type AuditListener, type Deliberation, type DeliberationVote, type Envelope, type Handoff, type HandoffTaskItem, type JsonPatchOp, type Jwk, type KeyRecord, type Member, type Mode, type OverrideArtefact, type ParticipantType, type ParticipantUri, type PauseScope, type ReviewDecision, type RouteDecisionArtefact, type SnapshotArtefact, type Task, type TaskId, type TaskRoutingHints, type TaskState, type WhisperPrompt, type Workspace, type WorkspaceId, type WorkspaceState, modeLE };
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ // src/types.ts
2
+ function modeLE(a, ceiling) {
3
+ const order = { shadow: 0, trial: 1, production: 2 };
4
+ return order[a] <= order[ceiling];
5
+ }
6
+ export {
7
+ modeLE
8
+ };
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * @brightbeamai/chap-coordinator. type vocabulary\n *\n * Wire-shape and in-memory types for the Coordinator. The schemas at\n * schemas/ are the normative wire types; these mirror them in\n * TypeScript for in-process use.\n */\n\nexport type ParticipantUri = string;\nexport type WorkspaceId = string;\nexport type TaskId = string;\nexport type ArtefactId = string;\n\nexport type ParticipantType = \"human\" | \"agent\" | \"service\" | \"group\" | \"workspace\";\n\nexport interface Envelope {\n jsonrpc: \"2.0\";\n id?: string | number;\n method?: string;\n params?: Record<string, unknown>;\n result?: unknown;\n error?: { code: number; message: string; data?: unknown };\n /** security-signed/1.0: top-level signature, signed over JCS of the\n * envelope with this field removed. Form: ``ed25519:<kid>:<b64>``. */\n sig?: string;\n}\n\nexport type Mode = \"shadow\" | \"trial\" | \"production\";\nexport type WorkspaceState = \"active\" | \"paused\" | \"closed\";\nexport type PauseScope = \"task\" | \"participant\" | \"workspace\";\n\nexport type TaskState =\n | \"created\"\n | \"in_progress\"\n | \"review_requested\"\n | \"completed\"\n | \"declined\"\n | \"abstained\"\n | \"escalated\"\n | \"superseded\"\n | \"paused\"\n | \"cancelled\";\n\n// ============================================================\n// Key records (security-signed/1.0)\n// ============================================================\n\nexport interface Jwk {\n kty: \"OKP\";\n crv: \"Ed25519\";\n kid: string;\n x: string;\n use?: string;\n alg?: string;\n}\n\n/** A participant's JWK plus the validity window. Lookup by\n * (participant, kid, ts) so historical envelopes verify across\n * rotation per security-signed/1.0 S3-S5. */\nexport interface KeyRecord {\n jwk: Jwk;\n kid: string;\n valid_from: string; // ISO timestamp; inclusive\n valid_until?: string; // ISO timestamp; exclusive; absent = unbounded\n revoked_at?: string;\n revoked_reason?: string;\n}\n\n// ============================================================\n// Participants\n// ============================================================\n\nexport interface Member {\n uri: ParticipantUri;\n type: ParticipantType;\n role: string;\n joined: string;\n display_name?: string;\n capabilities?: Record<string, unknown>;\n scopes?: string[];\n keys: KeyRecord[];\n paused: boolean; // control.pause scope=participant\n oidc_sub?: string;\n oidc_auth_time?: number; // unix seconds\n vc_holder?: string;\n}\n\n// ============================================================\n// Routing hints\n// ============================================================\n\nexport interface TaskRoutingHints {\n criticality?: \"low\" | \"medium\" | \"high\" | \"critical\";\n deadline?: string;\n max_cost_usd?: number;\n risk_tier?: string;\n [extra: string]: unknown;\n}\n\nexport interface ArtefactRoutingHints {\n confidence?: number | string;\n model_id?: string;\n cost_consumed_usd?: number;\n latency_ms?: number;\n [extra: string]: unknown;\n}\n\n// ============================================================\n// JSON Patch (RFC 6902)\n// ============================================================\n\nexport interface JsonPatchOp {\n op: \"add\" | \"replace\" | \"remove\" | \"copy\" | \"move\" | \"test\";\n path: string;\n value?: unknown;\n from?: string;\n}\n\n// ============================================================\n// Override artefact (review/1.0)\n// ============================================================\n\nexport interface OverrideArtefact {\n id: ArtefactId;\n task_id: TaskId;\n reviewer: ParticipantUri;\n based_on_artefact: unknown;\n diff: JsonPatchOp[];\n result: unknown;\n rationale: string;\n tags: string[];\n policy_refs: string[];\n ts: string;\n logical_id?: string;\n instance_id?: string;\n intent_preserved?: boolean;\n}\n\n// ============================================================\n// Route decision artefact (routing/1.0)\n// ============================================================\n\nexport interface RouteDecisionArtefact {\n id: ArtefactId;\n kind: \"route_decision\";\n decision_type: \"task.route\" | \"review.depth\" | \"escalate.auto\";\n outcome: unknown;\n produced_by: ParticipantUri;\n produced_at: string;\n task?: TaskId;\n policy_id?: string;\n hints_observed: Record<string, unknown>;\n rationale: string;\n // Auxiliary fields per decision_type:\n // task.route: alternatives_considered\n // review.depth: sampling_probability\n // escalate.auto: escalation_target\n [extra: string]: unknown;\n}\n\n// ============================================================\n// Snapshot artefact (control/1.0)\n// ============================================================\n\nexport interface SnapshotArtefact {\n id: ArtefactId;\n kind: \"snapshot\";\n ts: string;\n by: ParticipantUri;\n workspace: WorkspaceId;\n audit_seq: number;\n label?: string;\n include: string[];\n state: Record<string, unknown>;\n}\n\n// ============================================================\n// Whisper (whisper/1.0)\n// ============================================================\n\nexport interface WhisperPrompt {\n id: ArtefactId;\n task_id: TaskId;\n asker: ParticipantUri;\n askee: ParticipantUri[];\n question: string;\n options?: Array<{ id: string; label?: string }>;\n asked_at: string;\n deadline_ms: number;\n default_if_lapsed: unknown;\n urgency: \"low\" | \"medium\" | \"high\";\n state: \"pending\" | \"answered\" | \"lapsed\";\n answered_at?: string;\n answered_by?: ParticipantUri;\n answer_option?: string;\n answer_text?: string;\n comment?: string;\n default_applied?: unknown;\n}\n\n// ============================================================\n// Deliberation (deliberation/1.0)\n// ============================================================\n\nexport interface DeliberationVote {\n ts: string;\n voter: ParticipantUri;\n vote: \"yea\" | \"nay\" | \"abstain\";\n weight?: number;\n comment?: string;\n veto_invoked?: boolean;\n}\n\nexport interface Deliberation {\n id: string;\n task_id?: TaskId;\n opener: ParticipantUri;\n participants: ParticipantUri[];\n rule: string; // raw rule string\n question?: string;\n weights?: Record<ParticipantUri, number>;\n veto?: Record<ParticipantUri, boolean>;\n deadline?: string;\n state: \"open\" | \"closed\" | \"lapsed\";\n comments: { ts: string; from: ParticipantUri; text: string }[];\n votes: DeliberationVote[];\n outcome?: {\n outcome: \"approved\" | \"rejected\" | \"error\";\n rule: string;\n tally?: { yea: number; nay: number };\n vetoes?: ParticipantUri[];\n reason?: string;\n };\n opened_at: string;\n}\n\n// ============================================================\n// Handoff (handoff/1.0)\n// ============================================================\n\nexport interface HandoffTaskItem {\n task_id: TaskId;\n title?: string;\n status_summary?: string;\n next_action?: string;\n blockers?: string[];\n}\n\nexport interface Handoff {\n id: string;\n proposer: ParticipantUri;\n recipient: ParticipantUri; // single URI or \"group:...\"\n proposed_at: string;\n tasks: HandoffTaskItem[];\n summary?: string;\n context_links: string[];\n state: \"proposed\" | \"accepted\" | \"declined\";\n resolved_at?: string;\n accepted_by?: ParticipantUri;\n accepted_task_ids?: TaskId[];\n accept_comment?: string;\n decline_reason?: string;\n decline_suggested_target?: ParticipantUri;\n}\n\n// ============================================================\n// Review decision (review/1.0)\n// ============================================================\n\nexport interface ReviewDecision {\n reviewer: ParticipantUri;\n kind: \"approve\" | \"reject\" | \"override\" | \"abstain\";\n ts: string;\n comment?: string;\n tags?: string[];\n override_artefact_id?: ArtefactId;\n abstain_category?: string;\n}\n\n// ============================================================\n// Task\n// ============================================================\n\nexport interface Task {\n id: TaskId;\n kind: string;\n state: TaskState;\n assignee: ParticipantUri;\n delegator: ParticipantUri;\n input: Record<string, unknown>;\n output?: unknown;\n confidence?: number | string;\n deadline?: string;\n created_at: string;\n updated_at: string;\n mode: Mode;\n review_required?: boolean;\n routing_hints?: TaskRoutingHints;\n artefact_routing_hints?: ArtefactRoutingHints;\n review?: {\n requested_at: string;\n requested_to: ParticipantUri[];\n rule: string;\n deadline?: string;\n decisions: ReviewDecision[];\n };\n history: { ts: string; from: ParticipantUri; state: TaskState; note?: string }[];\n supersedes?: TaskId;\n superseded_by?: TaskId;\n parent?: TaskId;\n paused: boolean;\n /** Transient: holds the artefact passed to review.request so\n * decide.override can use it as the patch base. */\n pending_artefact?: unknown;\n}\n\n// ============================================================\n// Audit\n// ============================================================\n\nexport interface AuditEntry {\n seq: number;\n arrived: string;\n envelope: Envelope;\n prev_hash?: string;\n}\n\n// ============================================================\n// Workspace\n// ============================================================\n\nexport interface Workspace {\n id: WorkspaceId;\n created: string;\n state: WorkspaceState;\n profiles: string[];\n mode: Mode;\n mode_ceiling: Mode;\n routing_policy_uri?: string;\n step_up_window_sec: number;\n members: Map<ParticipantUri, Member>;\n tasks: Map<TaskId, Task>;\n overrides: Map<ArtefactId, OverrideArtefact>;\n whispers: Map<string, WhisperPrompt>;\n deliberations: Map<string, Deliberation>;\n handoffs: Map<string, Handoff>;\n snapshots: Map<ArtefactId, SnapshotArtefact>;\n route_decisions: Map<ArtefactId, RouteDecisionArtefact>;\n audit: AuditEntry[];\n chain_head?: string;\n chain_enabled: boolean;\n}\n\n/**\n * Listener callback invoked synchronously when an envelope is appended\n * to the workspace audit log.\n */\nexport type AuditListener = (workspace: Workspace, entry: AuditEntry) => void;\n\n/** True iff mode `a` is <= ceiling. */\nexport function modeLE(a: Mode, ceiling: Mode): boolean {\n const order: Record<Mode, number> = { shadow: 0, trial: 1, production: 2 };\n return order[a] <= order[ceiling];\n}\n"],"mappings":";AAwWO,SAAS,OAAO,GAAS,SAAwB;AACtD,QAAM,QAA8B,EAAE,QAAQ,GAAG,OAAO,GAAG,YAAY,EAAE;AACzE,SAAO,MAAM,CAAC,KAAK,MAAM,OAAO;AAClC;","names":[]}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@brightbeamai/chap-coordinator",
3
+ "version": "0.2.8",
4
+ "description": "Collaborative Human-Agent Protocol (CHAP): reference TypeScript implementation. Coordinator with Core + every shipped profile, plus pluggable storage and typed method facade.",
5
+ "license": "Apache-2.0",
6
+ "author": "Brightbeam AI <oss@brightbeam.com>",
7
+ "homepage": "https://github.com/BrightbeamAI/chap",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/BrightbeamAI/chap.git",
11
+ "directory": "packages/coordinator"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/BrightbeamAI/chap/issues"
15
+ },
16
+ "keywords": [
17
+ "chap", "agent", "protocol", "audit", "json-rpc",
18
+ "human-ai", "human-agent", "review", "override", "scitt", "mcp", "a2a"
19
+ ],
20
+ "type": "module",
21
+ "engines": { "node": ">=18" },
22
+ "files": ["dist", "README.md", "LICENSE"],
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js", "require": "./dist/index.cjs" },
28
+ "./jsonrpc": { "types": "./dist/jsonrpc.d.ts", "import": "./dist/jsonrpc.js", "require": "./dist/jsonrpc.cjs" },
29
+ "./patch": { "types": "./dist/patch.d.ts", "import": "./dist/patch.js", "require": "./dist/patch.cjs" },
30
+ "./types": { "types": "./dist/types.d.ts", "import": "./dist/types.js", "require": "./dist/types.cjs" },
31
+ "./methods": { "types": "./dist/methods.d.ts", "import": "./dist/methods.js", "require": "./dist/methods.cjs" },
32
+ "./api": { "types": "./dist/api.d.ts", "import": "./dist/api.js", "require": "./dist/api.cjs" },
33
+ "./storage/store": { "types": "./dist/storage/store.d.ts", "import": "./dist/storage/store.js", "require": "./dist/storage/store.cjs" },
34
+ "./storage/sqlite": { "types": "./dist/storage/sqlite.d.ts", "import": "./dist/storage/sqlite.js", "require": "./dist/storage/sqlite.cjs" }
35
+ },
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "test": "tsx --test tests/*.test.ts",
39
+ "typecheck": "tsc",
40
+ "check:schemas": "tsx scripts/check-method-coverage.ts",
41
+ "prepublishOnly": "npm run check:schemas && npm run typecheck && npm run test && npm run build"
42
+ },
43
+ "optionalDependencies": { "better-sqlite3": "^12.11.1" },
44
+ "devDependencies": {
45
+ "@types/node": "^20.11.0",
46
+ "better-sqlite3": "^12.11.1",
47
+ "tsup": "^8.0.0",
48
+ "tsx": "^4.7.0",
49
+ "typescript": "^5.3.0"
50
+ },
51
+ "publishConfig": { "access": "public" }
52
+ }