@peac/adapter-runtime-governance 0.12.9

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/index.mjs ADDED
@@ -0,0 +1,505 @@
1
+ import { issue } from '@peac/protocol';
2
+ import { decode } from '@peac/crypto';
3
+
4
+ // src/constants.ts
5
+ var EXTENSION_NAMESPACE = "org.peacprotocol/runtime-governance";
6
+ var TYPE_PREFIX = "org.peacprotocol/runtime-governance-";
7
+ var EVENT_TYPES = {
8
+ POLICY_DECISION: `${TYPE_PREFIX}policy-decision`,
9
+ AUDIT_ENTRY: `${TYPE_PREFIX}audit-entry`,
10
+ AUTHORITY_SCOPE: `${TYPE_PREFIX}authority-scope`,
11
+ LIFECYCLE_EVENT: `${TYPE_PREFIX}lifecycle-event`,
12
+ TRUST_OBSERVATION: `${TYPE_PREFIX}trust-observation`,
13
+ COMPLIANCE_OBSERVATION: `${TYPE_PREFIX}compliance-observation`
14
+ };
15
+ var FIELD_LIMITS = {
16
+ /** Identifiers: provider, agent_id, session_id, entry_id, etc. */
17
+ maxIdentifier: 256,
18
+ /** General string fields: action, matched_rule, policy_name, etc. */
19
+ maxString: 1024,
20
+ /** Digest strings: previous_hash, entry_hash, etc. */
21
+ maxDigest: 512,
22
+ /** URI fields: source_artifact_ref, etc. */
23
+ maxUri: 2048,
24
+ /** Timestamp fields: source_timestamp, etc. */
25
+ maxTimestamp: 64,
26
+ /** CloudEvents type URIs. */
27
+ maxCloudEventType: 256,
28
+ /** Array fields: effective_scope, matched_invariants. */
29
+ maxArrayLength: 64,
30
+ /** Array entry string length. */
31
+ maxArrayEntry: 256,
32
+ /** Framework token length. */
33
+ maxFramework: 128
34
+ };
35
+
36
+ // src/types.ts
37
+ var RUNTIME_GOVERNANCE_FAMILIES = [
38
+ "policy_decision",
39
+ "audit_entry",
40
+ "authority_scope",
41
+ "lifecycle_event",
42
+ "trust_observation",
43
+ "compliance_observation"
44
+ ];
45
+
46
+ // src/families.ts
47
+ var FAMILY_REGISTRY = {
48
+ policy_decision: { type: EVENT_TYPES.POLICY_DECISION, kind: "evidence" },
49
+ audit_entry: { type: EVENT_TYPES.AUDIT_ENTRY, kind: "evidence" },
50
+ authority_scope: { type: EVENT_TYPES.AUTHORITY_SCOPE, kind: "evidence" },
51
+ lifecycle_event: { type: EVENT_TYPES.LIFECYCLE_EVENT, kind: "evidence" },
52
+ trust_observation: { type: EVENT_TYPES.TRUST_OBSERVATION, kind: "evidence" },
53
+ compliance_observation: { type: EVENT_TYPES.COMPLIANCE_OBSERVATION, kind: "evidence" }
54
+ };
55
+
56
+ // src/normalize.ts
57
+ var NormalizationError = class extends Error {
58
+ constructor(message, field) {
59
+ super(message);
60
+ this.field = field;
61
+ this.name = "NormalizationError";
62
+ }
63
+ };
64
+ function requireString(value, field, maxLen) {
65
+ if (typeof value !== "string") {
66
+ throw new NormalizationError(`${field} must be a string`, field);
67
+ }
68
+ if (value.length === 0) {
69
+ throw new NormalizationError(`${field} must not be empty`, field);
70
+ }
71
+ if (value.length > maxLen) {
72
+ throw new NormalizationError(`${field} exceeds max length ${maxLen}`, field);
73
+ }
74
+ return value;
75
+ }
76
+ function optionalString(value, field, maxLen) {
77
+ if (value === void 0 || value === null) return void 0;
78
+ return requireString(value, field, maxLen);
79
+ }
80
+ function optionalFiniteNumber(value, field, min, max) {
81
+ if (value === void 0 || value === null) return void 0;
82
+ if (typeof value !== "number" || !Number.isFinite(value)) {
83
+ throw new NormalizationError(`${field} must be a finite number`, field);
84
+ }
85
+ if (min !== void 0 && value < min) {
86
+ throw new NormalizationError(`${field} must be >= ${min}`, field);
87
+ }
88
+ if (max !== void 0 && value > max) {
89
+ throw new NormalizationError(`${field} must be <= ${max}`, field);
90
+ }
91
+ return value;
92
+ }
93
+ function optionalInteger(value, field, min, max) {
94
+ const n = optionalFiniteNumber(value, field, min, max);
95
+ if (n !== void 0 && !Number.isInteger(n)) {
96
+ throw new NormalizationError(`${field} must be an integer`, field);
97
+ }
98
+ return n;
99
+ }
100
+ function optionalBoolean(value, field) {
101
+ if (value === void 0 || value === null) return void 0;
102
+ if (typeof value !== "boolean") {
103
+ throw new NormalizationError(`${field} must be a boolean`, field);
104
+ }
105
+ return value;
106
+ }
107
+ var RFC3339_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
108
+ function optionalRfc3339(value, field, maxLen) {
109
+ const s = optionalString(value, field, maxLen);
110
+ if (s !== void 0 && !RFC3339_PATTERN.test(s)) {
111
+ throw new NormalizationError(`${field} must be RFC 3339 format`, field);
112
+ }
113
+ return s;
114
+ }
115
+ var DIGEST_PATTERN = /^[a-zA-Z0-9_-]+:[a-fA-F0-9]+$/;
116
+ function optionalDigest(value, field, maxLen) {
117
+ const s = optionalString(value, field, maxLen);
118
+ if (s !== void 0 && !DIGEST_PATTERN.test(s)) {
119
+ throw new NormalizationError(`${field} must match digest pattern (algorithm:hex)`, field);
120
+ }
121
+ return s;
122
+ }
123
+ var URI_PATTERN = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
124
+ function optionalUri(value, field, maxLen) {
125
+ const s = optionalString(value, field, maxLen);
126
+ if (s !== void 0 && !URI_PATTERN.test(s)) {
127
+ throw new NormalizationError(`${field} must be a valid URI`, field);
128
+ }
129
+ return s;
130
+ }
131
+ function optionalStringArray(value, field, maxLen, maxEntryLen) {
132
+ if (value === void 0 || value === null) return void 0;
133
+ if (!Array.isArray(value)) {
134
+ throw new NormalizationError(`${field} must be an array`, field);
135
+ }
136
+ if (value.length > maxLen) {
137
+ throw new NormalizationError(`${field} exceeds max length ${maxLen}`, field);
138
+ }
139
+ return value.map((entry, i) => requireString(entry, `${field}[${i}]`, maxEntryLen));
140
+ }
141
+ function normalizePolicyDecision(input) {
142
+ return {
143
+ family: "policy_decision",
144
+ action: requireString(input.action, "action", FIELD_LIMITS.maxString),
145
+ matched_rule: optionalString(input.matched_rule, "matched_rule", FIELD_LIMITS.maxString),
146
+ policy_name: optionalString(input.policy_name, "policy_name", FIELD_LIMITS.maxString),
147
+ reason: optionalString(input.reason, "reason", FIELD_LIMITS.maxString),
148
+ evaluation_ms: optionalFiniteNumber(input.evaluation_ms, "evaluation_ms", 0)
149
+ };
150
+ }
151
+ function normalizeAuditEntry(input) {
152
+ return {
153
+ family: "audit_entry",
154
+ entry_id: optionalString(input.entry_id, "entry_id", FIELD_LIMITS.maxIdentifier),
155
+ event_type: optionalString(input.event_type, "event_type", FIELD_LIMITS.maxString),
156
+ outcome: optionalString(input.outcome, "outcome", FIELD_LIMITS.maxString),
157
+ previous_hash: optionalDigest(input.previous_hash, "previous_hash", FIELD_LIMITS.maxDigest),
158
+ entry_hash: optionalDigest(input.entry_hash, "entry_hash", FIELD_LIMITS.maxDigest),
159
+ trace_id: optionalString(input.trace_id, "trace_id", FIELD_LIMITS.maxIdentifier)
160
+ };
161
+ }
162
+ function normalizeAuthorityScope(input) {
163
+ return {
164
+ family: "authority_scope",
165
+ decision: optionalString(input.decision, "decision", FIELD_LIMITS.maxString),
166
+ effective_scope: optionalStringArray(
167
+ input.effective_scope,
168
+ "effective_scope",
169
+ FIELD_LIMITS.maxArrayLength,
170
+ FIELD_LIMITS.maxArrayEntry
171
+ ),
172
+ trust_tier: optionalString(input.trust_tier, "trust_tier", FIELD_LIMITS.maxString),
173
+ matched_invariants: optionalStringArray(
174
+ input.matched_invariants,
175
+ "matched_invariants",
176
+ FIELD_LIMITS.maxArrayLength,
177
+ FIELD_LIMITS.maxArrayEntry
178
+ )
179
+ };
180
+ }
181
+ function normalizeLifecycleEvent(input) {
182
+ return {
183
+ family: "lifecycle_event",
184
+ lifecycle_event_type: optionalString(
185
+ input.lifecycle_event_type,
186
+ "lifecycle_event_type",
187
+ FIELD_LIMITS.maxString
188
+ ),
189
+ previous_state: optionalString(input.previous_state, "previous_state", FIELD_LIMITS.maxString),
190
+ new_state: optionalString(input.new_state, "new_state", FIELD_LIMITS.maxString),
191
+ actor: optionalString(input.actor, "actor", FIELD_LIMITS.maxIdentifier)
192
+ };
193
+ }
194
+ function normalizeTrustObservation(input) {
195
+ return {
196
+ family: "trust_observation",
197
+ peer_id: optionalString(input.peer_id, "peer_id", FIELD_LIMITS.maxIdentifier),
198
+ action: optionalString(input.action, "action", FIELD_LIMITS.maxString),
199
+ success: optionalBoolean(input.success, "success"),
200
+ trust_delta: optionalInteger(input.trust_delta, "trust_delta", -1e3, 1e3),
201
+ trust_score: optionalInteger(input.trust_score, "trust_score", 0, 1e3)
202
+ };
203
+ }
204
+ function normalizeComplianceObservation(input) {
205
+ return {
206
+ family: "compliance_observation",
207
+ framework: optionalString(input.framework, "framework", FIELD_LIMITS.maxFramework),
208
+ compliance_score: optionalFiniteNumber(input.compliance_score, "compliance_score", 0, 100),
209
+ violation_count: optionalInteger(input.violation_count, "violation_count", 0),
210
+ evidence_item_count: optionalInteger(input.evidence_item_count, "evidence_item_count", 0)
211
+ };
212
+ }
213
+ var FAMILY_NORMALIZERS = {
214
+ policy_decision: normalizePolicyDecision,
215
+ audit_entry: normalizeAuditEntry,
216
+ authority_scope: normalizeAuthorityScope,
217
+ lifecycle_event: normalizeLifecycleEvent,
218
+ trust_observation: normalizeTrustObservation,
219
+ compliance_observation: normalizeComplianceObservation
220
+ };
221
+ function normalizeUpstream(input) {
222
+ if (input === void 0 || input === null) return void 0;
223
+ if (typeof input !== "object" || Array.isArray(input)) {
224
+ throw new NormalizationError("upstream must be a plain object", "upstream");
225
+ }
226
+ const obj = input;
227
+ return {
228
+ source_system: optionalString(
229
+ obj.source_system,
230
+ "upstream.source_system",
231
+ FIELD_LIMITS.maxIdentifier
232
+ ),
233
+ source_event_type: optionalString(
234
+ obj.source_event_type,
235
+ "upstream.source_event_type",
236
+ FIELD_LIMITS.maxIdentifier
237
+ ),
238
+ source_event_id: optionalString(
239
+ obj.source_event_id,
240
+ "upstream.source_event_id",
241
+ FIELD_LIMITS.maxIdentifier
242
+ ),
243
+ source_timestamp: optionalRfc3339(
244
+ obj.source_timestamp,
245
+ "upstream.source_timestamp",
246
+ FIELD_LIMITS.maxTimestamp
247
+ ),
248
+ source_artifact_hash: optionalDigest(
249
+ obj.source_artifact_hash,
250
+ "upstream.source_artifact_hash",
251
+ FIELD_LIMITS.maxDigest
252
+ ),
253
+ source_artifact_ref: optionalUri(
254
+ obj.source_artifact_ref,
255
+ "upstream.source_artifact_ref",
256
+ FIELD_LIMITS.maxUri
257
+ ),
258
+ source_cloud_event_type: optionalString(
259
+ obj.source_cloud_event_type,
260
+ "upstream.source_cloud_event_type",
261
+ FIELD_LIMITS.maxCloudEventType
262
+ )
263
+ };
264
+ }
265
+ function normalizeRuntimeGovernanceEvent(input) {
266
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
267
+ throw new NormalizationError("input must be a plain object", "input");
268
+ }
269
+ const obj = input;
270
+ const eventName = requireString(obj.event_name, "event_name", FIELD_LIMITS.maxString);
271
+ if (typeof obj.payload !== "object" || obj.payload === null || Array.isArray(obj.payload)) {
272
+ throw new NormalizationError("payload must be a plain object", "payload");
273
+ }
274
+ const payloadObj = obj.payload;
275
+ const family = payloadObj.family;
276
+ if (typeof family !== "string" || !RUNTIME_GOVERNANCE_FAMILIES.includes(family)) {
277
+ throw new NormalizationError(
278
+ `payload.family must be one of: ${RUNTIME_GOVERNANCE_FAMILIES.join(", ")}`,
279
+ "payload.family"
280
+ );
281
+ }
282
+ const normalizer = FAMILY_NORMALIZERS[family];
283
+ const payload = normalizer(payloadObj);
284
+ return {
285
+ event_name: eventName,
286
+ payload,
287
+ upstream: normalizeUpstream(obj.upstream)
288
+ };
289
+ }
290
+
291
+ // src/builders.ts
292
+ function stripUndefined(obj) {
293
+ const result = {};
294
+ for (const [key, value] of Object.entries(obj)) {
295
+ if (value !== void 0) {
296
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
297
+ const nested = stripUndefined(value);
298
+ if (Object.keys(nested).length > 0) {
299
+ result[key] = nested;
300
+ }
301
+ } else {
302
+ result[key] = value;
303
+ }
304
+ }
305
+ }
306
+ return result;
307
+ }
308
+ function buildPolicyDecisionExtension(payload, common, upstream) {
309
+ return stripUndefined({
310
+ ...common,
311
+ action: payload.action,
312
+ matched_rule: payload.matched_rule,
313
+ policy_name: payload.policy_name,
314
+ reason: payload.reason,
315
+ evaluation_ms: payload.evaluation_ms,
316
+ upstream
317
+ });
318
+ }
319
+ function buildAuditEntryExtension(payload, common, upstream) {
320
+ return stripUndefined({
321
+ ...common,
322
+ entry_id: payload.entry_id,
323
+ event_type: payload.event_type,
324
+ outcome: payload.outcome,
325
+ previous_hash: payload.previous_hash,
326
+ entry_hash: payload.entry_hash,
327
+ trace_id: payload.trace_id,
328
+ upstream
329
+ });
330
+ }
331
+ function buildAuthorityScopeExtension(payload, common, upstream) {
332
+ return stripUndefined({
333
+ ...common,
334
+ decision: payload.decision,
335
+ effective_scope: payload.effective_scope,
336
+ trust_tier: payload.trust_tier,
337
+ matched_invariants: payload.matched_invariants,
338
+ upstream
339
+ });
340
+ }
341
+ function buildLifecycleEventExtension(payload, common, upstream) {
342
+ return stripUndefined({
343
+ ...common,
344
+ lifecycle_event_type: payload.lifecycle_event_type,
345
+ previous_state: payload.previous_state,
346
+ new_state: payload.new_state,
347
+ actor: payload.actor,
348
+ upstream
349
+ });
350
+ }
351
+ function buildTrustObservationExtension(payload, common, upstream) {
352
+ return stripUndefined({
353
+ ...common,
354
+ peer_id: payload.peer_id,
355
+ action: payload.action,
356
+ success: payload.success,
357
+ trust_delta: payload.trust_delta,
358
+ trust_score: payload.trust_score,
359
+ upstream
360
+ });
361
+ }
362
+ function buildComplianceObservationExtension(payload, common, upstream) {
363
+ return stripUndefined({
364
+ ...common,
365
+ framework: payload.framework,
366
+ compliance_score: payload.compliance_score,
367
+ violation_count: payload.violation_count,
368
+ evidence_item_count: payload.evidence_item_count,
369
+ upstream
370
+ });
371
+ }
372
+ var FAMILY_BUILDERS = {
373
+ policy_decision: (p, c, u) => buildPolicyDecisionExtension(p, c, u),
374
+ audit_entry: (p, c, u) => buildAuditEntryExtension(p, c, u),
375
+ authority_scope: (p, c, u) => buildAuthorityScopeExtension(p, c, u),
376
+ lifecycle_event: (p, c, u) => buildLifecycleEventExtension(p, c, u),
377
+ trust_observation: (p, c, u) => buildTrustObservationExtension(p, c, u),
378
+ compliance_observation: (p, c, u) => buildComplianceObservationExtension(p, c, u)
379
+ };
380
+
381
+ // src/issue.ts
382
+ function validateIssueOptions(options) {
383
+ if (!(options.privateKey instanceof Uint8Array) || options.privateKey.length !== 32) {
384
+ throw new Error("privateKey must be a 32-byte Uint8Array");
385
+ }
386
+ if (typeof options.kid !== "string" || options.kid.length === 0 || options.kid.length > 256) {
387
+ throw new Error("kid must be a non-empty string (max 256 chars)");
388
+ }
389
+ if (typeof options.issuer !== "string" || options.issuer.length === 0) {
390
+ throw new Error("issuer must be a non-empty string");
391
+ }
392
+ if (typeof options.sessionId !== "string" || options.sessionId.length === 0 || options.sessionId.length > 256) {
393
+ throw new Error("sessionId must be a non-empty string (max 256 chars)");
394
+ }
395
+ if (typeof options.agentId !== "string" || options.agentId.length === 0 || options.agentId.length > 256) {
396
+ throw new Error("agentId must be a non-empty string (max 256 chars)");
397
+ }
398
+ if (typeof options.provider !== "string" || options.provider.length === 0 || options.provider.length > 256) {
399
+ throw new Error("provider must be a non-empty string (max 256 chars)");
400
+ }
401
+ }
402
+ async function issueRuntimeGovernanceRecord(event, options) {
403
+ validateIssueOptions(options);
404
+ const entry = FAMILY_REGISTRY[event.payload.family];
405
+ const { privateKey, kid, issuer, sessionId, agentId, provider } = options;
406
+ const common = {
407
+ session_id: sessionId,
408
+ event: event.event_name,
409
+ agent_id: agentId,
410
+ provider
411
+ };
412
+ const extensionData = FAMILY_BUILDERS[event.payload.family](
413
+ event.payload,
414
+ common,
415
+ event.upstream
416
+ );
417
+ const { jws } = await issue({
418
+ iss: issuer,
419
+ kind: entry.kind,
420
+ type: entry.type,
421
+ privateKey,
422
+ kid,
423
+ extensions: { [EXTENSION_NAMESPACE]: extensionData }
424
+ });
425
+ return { jws, type: entry.type, family: event.payload.family };
426
+ }
427
+ var KNOWN_SUFFIXES = new Set(RUNTIME_GOVERNANCE_FAMILIES.map((f) => f.replace(/_/g, "-")));
428
+ function buildSessionSummary(receipts) {
429
+ if (receipts.length === 0) {
430
+ return { sessionId: "", receipts: 0, families: [], unknownTypeCount: 0, issuer: "" };
431
+ }
432
+ let sessionId = "";
433
+ let issuer = "";
434
+ let unknownTypeCount = 0;
435
+ const familySet = /* @__PURE__ */ new Set();
436
+ for (const jws of receipts) {
437
+ const decoded = decode(jws);
438
+ const claims = decoded.payload;
439
+ if (!issuer && typeof claims.iss === "string") {
440
+ issuer = claims.iss;
441
+ }
442
+ const extensions = claims.extensions;
443
+ const govExt = extensions?.[EXTENSION_NAMESPACE];
444
+ if (govExt) {
445
+ if (!sessionId && typeof govExt.session_id === "string") {
446
+ sessionId = govExt.session_id;
447
+ }
448
+ }
449
+ const type = claims.type;
450
+ if (type?.startsWith(TYPE_PREFIX)) {
451
+ const suffix = type.slice(TYPE_PREFIX.length);
452
+ if (KNOWN_SUFFIXES.has(suffix)) {
453
+ familySet.add(suffix.replace(/-/g, "_"));
454
+ } else {
455
+ unknownTypeCount++;
456
+ }
457
+ } else if (type) {
458
+ unknownTypeCount++;
459
+ }
460
+ }
461
+ return {
462
+ sessionId,
463
+ receipts: receipts.length,
464
+ families: [...familySet].sort(),
465
+ unknownTypeCount,
466
+ issuer
467
+ };
468
+ }
469
+
470
+ // src/mappers/agt.ts
471
+ var AGT_FAMILY_MAP = {
472
+ policy_decision: "policy_decision",
473
+ audit_entry: "audit_entry",
474
+ authority_scope: "authority_scope",
475
+ lifecycle_event: "lifecycle_event",
476
+ trust_observation: "trust_observation",
477
+ compliance_observation: "compliance_observation"
478
+ };
479
+ function mapAgtEvent(input) {
480
+ const family = AGT_FAMILY_MAP[input.family];
481
+ if (!family) {
482
+ throw new NormalizationError(`unrecognized AGT family: ${input.family}`, "family");
483
+ }
484
+ const raw = {
485
+ event_name: input.event,
486
+ payload: {
487
+ family,
488
+ ...input.data
489
+ },
490
+ upstream: input.source ? {
491
+ source_system: input.source.system,
492
+ source_event_type: input.source.event_type,
493
+ source_event_id: input.source.event_id,
494
+ source_timestamp: input.source.timestamp,
495
+ source_artifact_hash: input.source.artifact_hash,
496
+ source_artifact_ref: input.source.artifact_ref,
497
+ source_cloud_event_type: input.source.cloud_event_type
498
+ } : void 0
499
+ };
500
+ return normalizeRuntimeGovernanceEvent(raw);
501
+ }
502
+
503
+ export { EVENT_TYPES, EXTENSION_NAMESPACE, FAMILY_REGISTRY, FIELD_LIMITS, NormalizationError, RUNTIME_GOVERNANCE_FAMILIES, TYPE_PREFIX, buildSessionSummary, issueRuntimeGovernanceRecord, mapAgtEvent, normalizeRuntimeGovernanceEvent };
504
+ //# sourceMappingURL=index.mjs.map
505
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts","../src/types.ts","../src/families.ts","../src/normalize.ts","../src/builders.ts","../src/issue.ts","../src/session-summary.ts","../src/mappers/agt.ts"],"names":[],"mappings":";;;;AASO,IAAM,mBAAA,GAAsB;AAG5B,IAAM,WAAA,GAAc;AAMpB,IAAM,WAAA,GAAc;AAAA,EACzB,eAAA,EAAiB,GAAG,WAAW,CAAA,eAAA,CAAA;AAAA,EAC/B,WAAA,EAAa,GAAG,WAAW,CAAA,WAAA,CAAA;AAAA,EAC3B,eAAA,EAAiB,GAAG,WAAW,CAAA,eAAA,CAAA;AAAA,EAC/B,eAAA,EAAiB,GAAG,WAAW,CAAA,eAAA,CAAA;AAAA,EAC/B,iBAAA,EAAmB,GAAG,WAAW,CAAA,iBAAA,CAAA;AAAA,EACjC,sBAAA,EAAwB,GAAG,WAAW,CAAA,sBAAA;AACxC;AAKO,IAAM,YAAA,GAAe;AAAA;AAAA,EAE1B,aAAA,EAAe,GAAA;AAAA;AAAA,EAEf,SAAA,EAAW,IAAA;AA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;AAAA,MAC5B,iBAAA,EAAmB,MAAM,MAAA,CAAO,UAAA;AAAA,MAChC,eAAA,EAAiB,MAAM,MAAA,CAAO,QAAA;AAAA,MAC9B,gBAAA,EAAkB,MAAM,MAAA,CAAO,SAAA;AAAA,MAC/B,oBAAA,EAAsB,MAAM,MAAA,CAAO,aAAA;AAAA,MACnC,mBAAA,EAAqB,MAAM,MAAA,CAAO,YAAA;AAAA,MAClC,uBAAA,EAAyB,MAAM,MAAA,CAAO;AAAA,KACxC,GACA;AAAA,GACN;AAEA,EAAA,OAAO,gCAAgC,GAAG,CAAA;AAC5C","file":"index.mjs","sourcesContent":["/**\n * @peac/adapter-runtime-governance constants\n *\n * Vendor-neutral type URIs and extension namespace for runtime\n * governance record families. Observation-specific suffixes prevent\n * semantic bleed into authoritative claims.\n */\n\n/** Extension namespace for runtime governance record metadata. */\nexport const EXTENSION_NAMESPACE = 'org.peacprotocol/runtime-governance' as const;\n\n/** Reverse-DNS type prefix for all runtime governance record families. */\nexport const TYPE_PREFIX = 'org.peacprotocol/runtime-governance-' as const;\n\n/**\n * Canonical type URIs for the 6 runtime governance record families.\n * Each suffix is observation-specific (e.g., \"policy-decision\" not \"policy\").\n */\nexport const EVENT_TYPES = {\n POLICY_DECISION: `${TYPE_PREFIX}policy-decision`,\n AUDIT_ENTRY: `${TYPE_PREFIX}audit-entry`,\n AUTHORITY_SCOPE: `${TYPE_PREFIX}authority-scope`,\n LIFECYCLE_EVENT: `${TYPE_PREFIX}lifecycle-event`,\n TRUST_OBSERVATION: `${TYPE_PREFIX}trust-observation`,\n COMPLIANCE_OBSERVATION: `${TYPE_PREFIX}compliance-observation`,\n} as const;\n\nexport type EventType = (typeof EVENT_TYPES)[keyof typeof EVENT_TYPES];\n\n/** Maximum field lengths for validation. */\nexport const FIELD_LIMITS = {\n /** Identifiers: provider, agent_id, session_id, entry_id, etc. */\n maxIdentifier: 256,\n /** General string fields: action, matched_rule, policy_name, etc. */\n maxString: 1024,\n /** Digest strings: previous_hash, entry_hash, etc. */\n maxDigest: 512,\n /** URI fields: source_artifact_ref, etc. */\n maxUri: 2048,\n /** Timestamp fields: source_timestamp, etc. */\n maxTimestamp: 64,\n /** CloudEvents type URIs. */\n maxCloudEventType: 256,\n /** Array fields: effective_scope, matched_invariants. */\n maxArrayLength: 64,\n /** Array entry string length. */\n maxArrayEntry: 256,\n /** Framework token length. */\n maxFramework: 128,\n} as const;\n","/**\n * @peac/adapter-runtime-governance types\n *\n * Discriminated union payload model with per-family typing.\n * No weak Record<string, unknown> blobs.\n */\n\n/**\n * Runtime governance record families.\n * String-literal union (not enum) for lighter output and tree-shaking.\n */\nexport const RUNTIME_GOVERNANCE_FAMILIES = [\n 'policy_decision',\n 'audit_entry',\n 'authority_scope',\n 'lifecycle_event',\n 'trust_observation',\n 'compliance_observation',\n] as const;\n\nexport type RuntimeGovernanceFamily = (typeof RUNTIME_GOVERNANCE_FAMILIES)[number];\n\n/**\n * Preserved upstream artifact context.\n * All optional, all observational. Bounded fields, no arbitrary passthrough.\n */\nexport interface PreservedUpstreamArtifact {\n /** Upstream system identifier (max 256 chars). */\n source_system?: string;\n /** Upstream event type identifier (max 256 chars). */\n source_event_type?: string;\n /** Upstream event identifier for deduplication (max 256 chars). */\n source_event_id?: string;\n /** Upstream event timestamp (RFC 3339, max 64 chars). */\n source_timestamp?: string;\n /** Hash of upstream artifact (max 512 chars). */\n source_artifact_hash?: string;\n /** URI or reference to upstream artifact (max 2048 chars). */\n source_artifact_ref?: string;\n /** CloudEvents type URI for cross-system correlation (max 256 chars). */\n source_cloud_event_type?: string;\n}\n\n/** Policy decision payload. */\nexport interface PolicyDecisionPayload {\n family: 'policy_decision';\n action: string;\n matched_rule?: string;\n policy_name?: string;\n reason?: string;\n evaluation_ms?: number;\n}\n\n/** Audit entry payload. */\nexport interface AuditEntryPayload {\n family: 'audit_entry';\n entry_id?: string;\n event_type?: string;\n outcome?: string;\n previous_hash?: string;\n entry_hash?: string;\n trace_id?: string;\n}\n\n/** Authority scope payload. */\nexport interface AuthorityScopePayload {\n family: 'authority_scope';\n decision?: string;\n effective_scope?: string[];\n trust_tier?: string;\n matched_invariants?: string[];\n}\n\n/** Lifecycle event payload. */\nexport interface LifecycleEventPayload {\n family: 'lifecycle_event';\n lifecycle_event_type?: string;\n previous_state?: string;\n new_state?: string;\n actor?: string;\n}\n\n/** Trust observation payload. */\nexport interface TrustObservationPayload {\n family: 'trust_observation';\n peer_id?: string;\n action?: string;\n success?: boolean;\n trust_delta?: number;\n trust_score?: number;\n}\n\n/** Compliance observation payload. */\nexport interface ComplianceObservationPayload {\n family: 'compliance_observation';\n framework?: string;\n compliance_score?: number;\n violation_count?: number;\n evidence_item_count?: number;\n}\n\n/** Discriminated union of all family payloads. */\nexport type RuntimeGovernancePayload =\n | PolicyDecisionPayload\n | AuditEntryPayload\n | AuthorityScopePayload\n | LifecycleEventPayload\n | TrustObservationPayload\n | ComplianceObservationPayload;\n\n/**\n * Normalized runtime governance event.\n * Generic input to issueRuntimeGovernanceRecord().\n */\nexport interface RuntimeGovernanceEvent {\n /** Specific event name (e.g., 'policy.evaluated'). */\n event_name: string;\n /** Typed, validated payload (discriminated by family). */\n payload: RuntimeGovernancePayload;\n /** Optional preserved upstream artifact context. */\n upstream?: PreservedUpstreamArtifact;\n}\n\n/** Options for issuing a runtime governance record. */\nexport interface IssueOptions {\n /** Ed25519 private key (32 bytes). Caller-provided; never stored. */\n privateKey: Uint8Array;\n /** Key ID (max 256 chars). */\n kid: string;\n /** Canonical issuer URL (HTTPS or DID). */\n issuer: string;\n /** Session identifier for event correlation. */\n sessionId: string;\n /** Agent identifier. */\n agentId: string;\n /** Provider name. Caller-supplied; never hardcoded. */\n provider: string;\n}\n\n/** Result of issuing a runtime governance record. */\nexport interface IssueResult {\n /** Compact JWS (signed Interaction Record). */\n jws: string;\n /** PEAC event type URI used. */\n type: string;\n /** Record family. */\n family: RuntimeGovernanceFamily;\n}\n\n/** Session summary aggregated from decoded receipts. */\nexport interface SessionSummary {\n /** Session identifier. */\n sessionId: string;\n /** Total receipts in the session. */\n receipts: number;\n /** Distinct families represented (sorted alphabetically). */\n families: RuntimeGovernanceFamily[];\n /** Count of receipts with unrecognized type URIs. */\n unknownTypeCount: number;\n /** Issuer (from the first receipt, or empty if no receipts). */\n issuer: string;\n}\n","/**\n * Family registry.\n *\n * Maps each RuntimeGovernanceFamily to its canonical type URI\n * and Interaction Record kind. All families produce `evidence` kind.\n */\n\nimport { EVENT_TYPES, type EventType } from './constants.js';\nimport type { RuntimeGovernanceFamily } from './types.js';\n\nexport interface FamilyEntry {\n /** Canonical type URI for this family. */\n type: EventType;\n /** Interaction Record kind. Always 'evidence' for runtime governance. */\n kind: 'evidence';\n}\n\nexport const FAMILY_REGISTRY: Record<RuntimeGovernanceFamily, FamilyEntry> = {\n policy_decision: { type: EVENT_TYPES.POLICY_DECISION, kind: 'evidence' },\n audit_entry: { type: EVENT_TYPES.AUDIT_ENTRY, kind: 'evidence' },\n authority_scope: { type: EVENT_TYPES.AUTHORITY_SCOPE, kind: 'evidence' },\n lifecycle_event: { type: EVENT_TYPES.LIFECYCLE_EVENT, kind: 'evidence' },\n trust_observation: { type: EVENT_TYPES.TRUST_OBSERVATION, kind: 'evidence' },\n compliance_observation: { type: EVENT_TYPES.COMPLIANCE_OBSERVATION, kind: 'evidence' },\n};\n","/**\n * @peac/adapter-runtime-governance normalization and validation\n *\n * Fail-closed input validation for runtime governance payloads.\n * Rejects malformed input with descriptive errors.\n *\n * These are adapter-level shape prechecks: string presence, max lengths,\n * numeric bounds, RFC 3339 format, digest grammar (algorithm:hex), and\n * URI scheme presence. Protocol-layer validation (@peac/protocol issue()\n * and @peac/schema Wire02ClaimsSchema) remains authoritative for issuer\n * canonicality, JOSE hardening, and wire-format compliance. Adapter\n * validators catch obviously malformed input before it reaches the\n * protocol layer.\n *\n * PEAC validates the structure of carried values, not upstream truth.\n * Trust scores are structurally validated (finite, 0-1000 integer)\n * but never derived, recomputed, ranked, or authoritatively assessed.\n */\n\nimport { FIELD_LIMITS } from './constants.js';\nimport { RUNTIME_GOVERNANCE_FAMILIES } from './types.js';\nimport type {\n RuntimeGovernanceFamily,\n RuntimeGovernancePayload,\n PreservedUpstreamArtifact,\n RuntimeGovernanceEvent,\n} from './types.js';\n\nexport class NormalizationError extends Error {\n constructor(\n message: string,\n public readonly field: string\n ) {\n super(message);\n this.name = 'NormalizationError';\n }\n}\n\nfunction requireString(value: unknown, field: string, maxLen: number): string {\n if (typeof value !== 'string') {\n throw new NormalizationError(`${field} must be a string`, field);\n }\n if (value.length === 0) {\n throw new NormalizationError(`${field} must not be empty`, field);\n }\n if (value.length > maxLen) {\n throw new NormalizationError(`${field} exceeds max length ${maxLen}`, field);\n }\n return value;\n}\n\nfunction optionalString(value: unknown, field: string, maxLen: number): string | undefined {\n if (value === undefined || value === null) return undefined;\n return requireString(value, field, maxLen);\n}\n\nfunction optionalFiniteNumber(\n value: unknown,\n field: string,\n min?: number,\n max?: number\n): number | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new NormalizationError(`${field} must be a finite number`, field);\n }\n if (min !== undefined && value < min) {\n throw new NormalizationError(`${field} must be >= ${min}`, field);\n }\n if (max !== undefined && value > max) {\n throw new NormalizationError(`${field} must be <= ${max}`, field);\n }\n return value;\n}\n\nfunction optionalInteger(\n value: unknown,\n field: string,\n min?: number,\n max?: number\n): number | undefined {\n const n = optionalFiniteNumber(value, field, min, max);\n if (n !== undefined && !Number.isInteger(n)) {\n throw new NormalizationError(`${field} must be an integer`, field);\n }\n return n;\n}\n\nfunction optionalBoolean(value: unknown, field: string): boolean | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value !== 'boolean') {\n throw new NormalizationError(`${field} must be a boolean`, field);\n }\n return value;\n}\n\nconst RFC3339_PATTERN = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$/;\n\nfunction optionalRfc3339(value: unknown, field: string, maxLen: number): string | undefined {\n const s = optionalString(value, field, maxLen);\n if (s !== undefined && !RFC3339_PATTERN.test(s)) {\n throw new NormalizationError(`${field} must be RFC 3339 format`, field);\n }\n return s;\n}\n\nconst DIGEST_PATTERN = /^[a-zA-Z0-9_-]+:[a-fA-F0-9]+$/;\n\nfunction optionalDigest(value: unknown, field: string, maxLen: number): string | undefined {\n const s = optionalString(value, field, maxLen);\n if (s !== undefined && !DIGEST_PATTERN.test(s)) {\n throw new NormalizationError(`${field} must match digest pattern (algorithm:hex)`, field);\n }\n return s;\n}\n\nconst URI_PATTERN = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;\n\nfunction optionalUri(value: unknown, field: string, maxLen: number): string | undefined {\n const s = optionalString(value, field, maxLen);\n if (s !== undefined && !URI_PATTERN.test(s)) {\n throw new NormalizationError(`${field} must be a valid URI`, field);\n }\n return s;\n}\n\nfunction optionalStringArray(\n value: unknown,\n field: string,\n maxLen: number,\n maxEntryLen: number\n): string[] | undefined {\n if (value === undefined || value === null) return undefined;\n if (!Array.isArray(value)) {\n throw new NormalizationError(`${field} must be an array`, field);\n }\n if (value.length > maxLen) {\n throw new NormalizationError(`${field} exceeds max length ${maxLen}`, field);\n }\n return value.map((entry, i) => requireString(entry, `${field}[${i}]`, maxEntryLen));\n}\n\nfunction normalizePolicyDecision(input: Record<string, unknown>): RuntimeGovernancePayload {\n return {\n family: 'policy_decision',\n action: requireString(input.action, 'action', FIELD_LIMITS.maxString),\n matched_rule: optionalString(input.matched_rule, 'matched_rule', FIELD_LIMITS.maxString),\n policy_name: optionalString(input.policy_name, 'policy_name', FIELD_LIMITS.maxString),\n reason: optionalString(input.reason, 'reason', FIELD_LIMITS.maxString),\n evaluation_ms: optionalFiniteNumber(input.evaluation_ms, 'evaluation_ms', 0),\n };\n}\n\nfunction normalizeAuditEntry(input: Record<string, unknown>): RuntimeGovernancePayload {\n return {\n family: 'audit_entry',\n entry_id: optionalString(input.entry_id, 'entry_id', FIELD_LIMITS.maxIdentifier),\n event_type: optionalString(input.event_type, 'event_type', FIELD_LIMITS.maxString),\n outcome: optionalString(input.outcome, 'outcome', FIELD_LIMITS.maxString),\n previous_hash: optionalDigest(input.previous_hash, 'previous_hash', FIELD_LIMITS.maxDigest),\n entry_hash: optionalDigest(input.entry_hash, 'entry_hash', FIELD_LIMITS.maxDigest),\n trace_id: optionalString(input.trace_id, 'trace_id', FIELD_LIMITS.maxIdentifier),\n };\n}\n\nfunction normalizeAuthorityScope(input: Record<string, unknown>): RuntimeGovernancePayload {\n return {\n family: 'authority_scope',\n decision: optionalString(input.decision, 'decision', FIELD_LIMITS.maxString),\n effective_scope: optionalStringArray(\n input.effective_scope,\n 'effective_scope',\n FIELD_LIMITS.maxArrayLength,\n FIELD_LIMITS.maxArrayEntry\n ),\n trust_tier: optionalString(input.trust_tier, 'trust_tier', FIELD_LIMITS.maxString),\n matched_invariants: optionalStringArray(\n input.matched_invariants,\n 'matched_invariants',\n FIELD_LIMITS.maxArrayLength,\n FIELD_LIMITS.maxArrayEntry\n ),\n };\n}\n\nfunction normalizeLifecycleEvent(input: Record<string, unknown>): RuntimeGovernancePayload {\n return {\n family: 'lifecycle_event',\n lifecycle_event_type: optionalString(\n input.lifecycle_event_type,\n 'lifecycle_event_type',\n FIELD_LIMITS.maxString\n ),\n previous_state: optionalString(input.previous_state, 'previous_state', FIELD_LIMITS.maxString),\n new_state: optionalString(input.new_state, 'new_state', FIELD_LIMITS.maxString),\n actor: optionalString(input.actor, 'actor', FIELD_LIMITS.maxIdentifier),\n };\n}\n\nfunction normalizeTrustObservation(input: Record<string, unknown>): RuntimeGovernancePayload {\n return {\n family: 'trust_observation',\n peer_id: optionalString(input.peer_id, 'peer_id', FIELD_LIMITS.maxIdentifier),\n action: optionalString(input.action, 'action', FIELD_LIMITS.maxString),\n success: optionalBoolean(input.success, 'success'),\n trust_delta: optionalInteger(input.trust_delta, 'trust_delta', -1000, 1000),\n trust_score: optionalInteger(input.trust_score, 'trust_score', 0, 1000),\n };\n}\n\nfunction normalizeComplianceObservation(input: Record<string, unknown>): RuntimeGovernancePayload {\n return {\n family: 'compliance_observation',\n framework: optionalString(input.framework, 'framework', FIELD_LIMITS.maxFramework),\n compliance_score: optionalFiniteNumber(input.compliance_score, 'compliance_score', 0, 100),\n violation_count: optionalInteger(input.violation_count, 'violation_count', 0),\n evidence_item_count: optionalInteger(input.evidence_item_count, 'evidence_item_count', 0),\n };\n}\n\nconst FAMILY_NORMALIZERS: Record<\n RuntimeGovernanceFamily,\n (input: Record<string, unknown>) => RuntimeGovernancePayload\n> = {\n policy_decision: normalizePolicyDecision,\n audit_entry: normalizeAuditEntry,\n authority_scope: normalizeAuthorityScope,\n lifecycle_event: normalizeLifecycleEvent,\n trust_observation: normalizeTrustObservation,\n compliance_observation: normalizeComplianceObservation,\n};\n\nfunction normalizeUpstream(input: unknown): PreservedUpstreamArtifact | undefined {\n if (input === undefined || input === null) return undefined;\n if (typeof input !== 'object' || Array.isArray(input)) {\n throw new NormalizationError('upstream must be a plain object', 'upstream');\n }\n const obj = input as Record<string, unknown>;\n return {\n source_system: optionalString(\n obj.source_system,\n 'upstream.source_system',\n FIELD_LIMITS.maxIdentifier\n ),\n source_event_type: optionalString(\n obj.source_event_type,\n 'upstream.source_event_type',\n FIELD_LIMITS.maxIdentifier\n ),\n source_event_id: optionalString(\n obj.source_event_id,\n 'upstream.source_event_id',\n FIELD_LIMITS.maxIdentifier\n ),\n source_timestamp: optionalRfc3339(\n obj.source_timestamp,\n 'upstream.source_timestamp',\n FIELD_LIMITS.maxTimestamp\n ),\n source_artifact_hash: optionalDigest(\n obj.source_artifact_hash,\n 'upstream.source_artifact_hash',\n FIELD_LIMITS.maxDigest\n ),\n source_artifact_ref: optionalUri(\n obj.source_artifact_ref,\n 'upstream.source_artifact_ref',\n FIELD_LIMITS.maxUri\n ),\n source_cloud_event_type: optionalString(\n obj.source_cloud_event_type,\n 'upstream.source_cloud_event_type',\n FIELD_LIMITS.maxCloudEventType\n ),\n };\n}\n\n/**\n * Normalize and validate a raw runtime governance event input.\n * Fail-closed: rejects malformed input with descriptive errors.\n */\nexport function normalizeRuntimeGovernanceEvent(input: unknown): RuntimeGovernanceEvent {\n if (typeof input !== 'object' || input === null || Array.isArray(input)) {\n throw new NormalizationError('input must be a plain object', 'input');\n }\n const obj = input as Record<string, unknown>;\n\n const eventName = requireString(obj.event_name, 'event_name', FIELD_LIMITS.maxString);\n\n if (typeof obj.payload !== 'object' || obj.payload === null || Array.isArray(obj.payload)) {\n throw new NormalizationError('payload must be a plain object', 'payload');\n }\n const payloadObj = obj.payload as Record<string, unknown>;\n\n const family = payloadObj.family;\n if (\n typeof family !== 'string' ||\n !(RUNTIME_GOVERNANCE_FAMILIES as readonly string[]).includes(family)\n ) {\n throw new NormalizationError(\n `payload.family must be one of: ${RUNTIME_GOVERNANCE_FAMILIES.join(', ')}`,\n 'payload.family'\n );\n }\n\n const normalizer = FAMILY_NORMALIZERS[family as RuntimeGovernanceFamily];\n const payload = normalizer(payloadObj);\n\n return {\n event_name: eventName,\n payload,\n upstream: normalizeUpstream(obj.upstream),\n };\n}\n","/**\n * @peac/adapter-runtime-governance extension builders\n *\n * Explicit per-family extension data builders. Each builder selects\n * exactly which fields appear in the extension output. Unknown upstream\n * fields never become top-level extension keys.\n */\n\nimport type {\n RuntimeGovernancePayload,\n PolicyDecisionPayload,\n AuditEntryPayload,\n AuthorityScopePayload,\n LifecycleEventPayload,\n TrustObservationPayload,\n ComplianceObservationPayload,\n PreservedUpstreamArtifact,\n RuntimeGovernanceFamily,\n} from './types.js';\n\ninterface CommonFields {\n session_id: string;\n event: string;\n agent_id: string;\n provider: string;\n}\n\nfunction stripUndefined(obj: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n if (value !== undefined) {\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n const nested = stripUndefined(value as Record<string, unknown>);\n if (Object.keys(nested).length > 0) {\n result[key] = nested;\n }\n } else {\n result[key] = value;\n }\n }\n }\n return result;\n}\n\nfunction buildPolicyDecisionExtension(\n payload: PolicyDecisionPayload,\n common: CommonFields,\n upstream?: PreservedUpstreamArtifact\n): Record<string, unknown> {\n return stripUndefined({\n ...common,\n action: payload.action,\n matched_rule: payload.matched_rule,\n policy_name: payload.policy_name,\n reason: payload.reason,\n evaluation_ms: payload.evaluation_ms,\n upstream,\n });\n}\n\nfunction buildAuditEntryExtension(\n payload: AuditEntryPayload,\n common: CommonFields,\n upstream?: PreservedUpstreamArtifact\n): Record<string, unknown> {\n return stripUndefined({\n ...common,\n entry_id: payload.entry_id,\n event_type: payload.event_type,\n outcome: payload.outcome,\n previous_hash: payload.previous_hash,\n entry_hash: payload.entry_hash,\n trace_id: payload.trace_id,\n upstream,\n });\n}\n\nfunction buildAuthorityScopeExtension(\n payload: AuthorityScopePayload,\n common: CommonFields,\n upstream?: PreservedUpstreamArtifact\n): Record<string, unknown> {\n return stripUndefined({\n ...common,\n decision: payload.decision,\n effective_scope: payload.effective_scope,\n trust_tier: payload.trust_tier,\n matched_invariants: payload.matched_invariants,\n upstream,\n });\n}\n\nfunction buildLifecycleEventExtension(\n payload: LifecycleEventPayload,\n common: CommonFields,\n upstream?: PreservedUpstreamArtifact\n): Record<string, unknown> {\n return stripUndefined({\n ...common,\n lifecycle_event_type: payload.lifecycle_event_type,\n previous_state: payload.previous_state,\n new_state: payload.new_state,\n actor: payload.actor,\n upstream,\n });\n}\n\nfunction buildTrustObservationExtension(\n payload: TrustObservationPayload,\n common: CommonFields,\n upstream?: PreservedUpstreamArtifact\n): Record<string, unknown> {\n return stripUndefined({\n ...common,\n peer_id: payload.peer_id,\n action: payload.action,\n success: payload.success,\n trust_delta: payload.trust_delta,\n trust_score: payload.trust_score,\n upstream,\n });\n}\n\nfunction buildComplianceObservationExtension(\n payload: ComplianceObservationPayload,\n common: CommonFields,\n upstream?: PreservedUpstreamArtifact\n): Record<string, unknown> {\n return stripUndefined({\n ...common,\n framework: payload.framework,\n compliance_score: payload.compliance_score,\n violation_count: payload.violation_count,\n evidence_item_count: payload.evidence_item_count,\n upstream,\n });\n}\n\ntype ExtensionBuilder = (\n payload: RuntimeGovernancePayload,\n common: CommonFields,\n upstream?: PreservedUpstreamArtifact\n) => Record<string, unknown>;\n\n/**\n * Per-family extension builder registry.\n * issueRuntimeGovernanceRecord() dispatches to the correct builder.\n */\nexport const FAMILY_BUILDERS: Record<RuntimeGovernanceFamily, ExtensionBuilder> = {\n policy_decision: (p, c, u) => buildPolicyDecisionExtension(p as PolicyDecisionPayload, c, u),\n audit_entry: (p, c, u) => buildAuditEntryExtension(p as AuditEntryPayload, c, u),\n authority_scope: (p, c, u) => buildAuthorityScopeExtension(p as AuthorityScopePayload, c, u),\n lifecycle_event: (p, c, u) => buildLifecycleEventExtension(p as LifecycleEventPayload, c, u),\n trust_observation: (p, c, u) =>\n buildTrustObservationExtension(p as TrustObservationPayload, c, u),\n compliance_observation: (p, c, u) =>\n buildComplianceObservationExtension(p as ComplianceObservationPayload, c, u),\n};\n","/**\n * @peac/adapter-runtime-governance record issuance\n *\n * Generic issuance function that dispatches to per-family extension\n * builders. Source-specific mappers (e.g., mapAgtEvent) produce the\n * RuntimeGovernanceEvent input; this function handles signing.\n *\n * PEAC validates the structure and signature of the PEAC record,\n * not the truth of the upstream governance decision or the operating\n * effectiveness of the upstream control plane.\n */\n\nimport { issue } from '@peac/protocol';\nimport { EXTENSION_NAMESPACE } from './constants.js';\nimport { FAMILY_REGISTRY } from './families.js';\nimport { FAMILY_BUILDERS } from './builders.js';\nimport type { RuntimeGovernanceEvent, IssueOptions, IssueResult } from './types.js';\n\n/**\n * Issue a signed Interaction Record for a normalized runtime governance event.\n *\n * Use source-specific mappers (e.g., mapAgtEvent) to produce the event input.\n * The provider field is always caller-supplied and never hardcoded.\n */\nfunction validateIssueOptions(options: IssueOptions): void {\n if (!(options.privateKey instanceof Uint8Array) || options.privateKey.length !== 32) {\n throw new Error('privateKey must be a 32-byte Uint8Array');\n }\n if (typeof options.kid !== 'string' || options.kid.length === 0 || options.kid.length > 256) {\n throw new Error('kid must be a non-empty string (max 256 chars)');\n }\n if (typeof options.issuer !== 'string' || options.issuer.length === 0) {\n throw new Error('issuer must be a non-empty string');\n }\n if (\n typeof options.sessionId !== 'string' ||\n options.sessionId.length === 0 ||\n options.sessionId.length > 256\n ) {\n throw new Error('sessionId must be a non-empty string (max 256 chars)');\n }\n if (\n typeof options.agentId !== 'string' ||\n options.agentId.length === 0 ||\n options.agentId.length > 256\n ) {\n throw new Error('agentId must be a non-empty string (max 256 chars)');\n }\n if (\n typeof options.provider !== 'string' ||\n options.provider.length === 0 ||\n options.provider.length > 256\n ) {\n throw new Error('provider must be a non-empty string (max 256 chars)');\n }\n}\n\nexport async function issueRuntimeGovernanceRecord(\n event: RuntimeGovernanceEvent,\n options: IssueOptions\n): Promise<IssueResult> {\n validateIssueOptions(options);\n const entry = FAMILY_REGISTRY[event.payload.family];\n const { privateKey, kid, issuer, sessionId, agentId, provider } = options;\n\n const common = {\n session_id: sessionId,\n event: event.event_name,\n agent_id: agentId,\n provider,\n };\n\n const extensionData = FAMILY_BUILDERS[event.payload.family](\n event.payload,\n common,\n event.upstream\n );\n\n const { jws } = await issue({\n iss: issuer,\n kind: entry.kind,\n type: entry.type,\n privateKey,\n kid,\n extensions: { [EXTENSION_NAMESPACE]: extensionData },\n });\n\n return { jws, type: entry.type, family: event.payload.family };\n}\n","/**\n * @peac/adapter-runtime-governance session summary builder\n *\n * Aggregates decoded receipts into a session summary.\n * Decode-only (does NOT verify signatures; caller should verify first).\n * Returns deterministic family order (sorted alphabetically).\n * Counts unknown/unsupported type URIs separately.\n * Never implies verification or finality.\n */\n\nimport { decode } from '@peac/crypto';\nimport { EXTENSION_NAMESPACE, TYPE_PREFIX } from './constants.js';\nimport {\n RUNTIME_GOVERNANCE_FAMILIES,\n type RuntimeGovernanceFamily,\n type SessionSummary,\n} from './types.js';\n\n/** Reverse lookup set for known family suffixes. */\nconst KNOWN_SUFFIXES = new Set(RUNTIME_GOVERNANCE_FAMILIES.map((f) => f.replace(/_/g, '-')));\n\n/**\n * Build a session summary from an array of signed JWS receipts.\n *\n * Decodes each JWS (does NOT verify signatures; caller should verify first).\n * Extracts session ID, families, and issuer from claims and extensions.\n * Unknown type URIs are counted but not included in the families list.\n *\n * @param receipts - Array of compact JWS strings (must be valid JWS format)\n * @returns Session summary with deterministic family ordering\n */\nexport function buildSessionSummary(receipts: string[]): SessionSummary {\n if (receipts.length === 0) {\n return { sessionId: '', receipts: 0, families: [], unknownTypeCount: 0, issuer: '' };\n }\n\n let sessionId = '';\n let issuer = '';\n let unknownTypeCount = 0;\n const familySet = new Set<RuntimeGovernanceFamily>();\n\n for (const jws of receipts) {\n const decoded = decode(jws);\n const claims = decoded.payload as Record<string, unknown>;\n\n if (!issuer && typeof claims.iss === 'string') {\n issuer = claims.iss;\n }\n\n const extensions = claims.extensions as Record<string, unknown> | undefined;\n const govExt = extensions?.[EXTENSION_NAMESPACE] as Record<string, unknown> | undefined;\n\n if (govExt) {\n if (!sessionId && typeof govExt.session_id === 'string') {\n sessionId = govExt.session_id;\n }\n }\n\n const type = claims.type as string | undefined;\n if (type?.startsWith(TYPE_PREFIX)) {\n const suffix = type.slice(TYPE_PREFIX.length);\n if (KNOWN_SUFFIXES.has(suffix)) {\n familySet.add(suffix.replace(/-/g, '_') as RuntimeGovernanceFamily);\n } else {\n unknownTypeCount++;\n }\n } else if (type) {\n unknownTypeCount++;\n }\n }\n\n return {\n sessionId,\n receipts: receipts.length,\n families: [...familySet].sort(),\n unknownTypeCount,\n issuer,\n };\n}\n","/**\n * AGT-specific mapper\n *\n * Normalizes AGT-shaped JSON input into the generic\n * RuntimeGovernanceEvent model. Accepts raw JSON (not AGT SDK objects).\n *\n * Pinned to AGT v3.1.0 pre-release documentation (as of 2026-04-13).\n */\n\nimport { normalizeRuntimeGovernanceEvent, NormalizationError } from '../normalize.js';\nimport type { RuntimeGovernanceEvent, RuntimeGovernanceFamily } from '../types.js';\n\n/** AGT-shaped input. Raw JSON, not SDK objects. */\nexport interface AgtEventInput {\n /** Family name matching a RuntimeGovernanceFamily. */\n family: string;\n /** Specific event name (e.g., 'policy.evaluated'). */\n event: string;\n /** Event-specific data fields. */\n data: Record<string, unknown>;\n /** Optional upstream source context. */\n source?: {\n system?: string;\n event_type?: string;\n event_id?: string;\n timestamp?: string;\n artifact_hash?: string;\n artifact_ref?: string;\n cloud_event_type?: string;\n };\n}\n\nconst AGT_FAMILY_MAP: Record<string, RuntimeGovernanceFamily> = {\n policy_decision: 'policy_decision',\n audit_entry: 'audit_entry',\n authority_scope: 'authority_scope',\n lifecycle_event: 'lifecycle_event',\n trust_observation: 'trust_observation',\n compliance_observation: 'compliance_observation',\n};\n\n/**\n * Map an AGT-shaped event input to a normalized RuntimeGovernanceEvent.\n * Throws NormalizationError on unrecognized or malformed input.\n */\nexport function mapAgtEvent(input: AgtEventInput): RuntimeGovernanceEvent {\n const family = AGT_FAMILY_MAP[input.family];\n if (!family) {\n throw new NormalizationError(`unrecognized AGT family: ${input.family}`, 'family');\n }\n\n const raw = {\n event_name: input.event,\n payload: {\n family,\n ...input.data,\n },\n upstream: input.source\n ? {\n source_system: input.source.system,\n source_event_type: input.source.event_type,\n source_event_id: input.source.event_id,\n source_timestamp: input.source.timestamp,\n source_artifact_hash: input.source.artifact_hash,\n source_artifact_ref: input.source.artifact_ref,\n source_cloud_event_type: input.source.cloud_event_type,\n }\n : undefined,\n };\n\n return normalizeRuntimeGovernanceEvent(raw);\n}\n"]}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @peac/adapter-runtime-governance record issuance
3
+ *
4
+ * Generic issuance function that dispatches to per-family extension
5
+ * builders. Source-specific mappers (e.g., mapAgtEvent) produce the
6
+ * RuntimeGovernanceEvent input; this function handles signing.
7
+ *
8
+ * PEAC validates the structure and signature of the PEAC record,
9
+ * not the truth of the upstream governance decision or the operating
10
+ * effectiveness of the upstream control plane.
11
+ */
12
+ import type { RuntimeGovernanceEvent, IssueOptions, IssueResult } from './types.js';
13
+ export declare function issueRuntimeGovernanceRecord(event: RuntimeGovernanceEvent, options: IssueOptions): Promise<IssueResult>;
14
+ //# sourceMappingURL=issue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.d.ts","sourceRoot":"","sources":["../src/issue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAyCpF,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,WAAW,CAAC,CA4BtB"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * AGT-specific mapper
3
+ *
4
+ * Normalizes AGT-shaped JSON input into the generic
5
+ * RuntimeGovernanceEvent model. Accepts raw JSON (not AGT SDK objects).
6
+ *
7
+ * Pinned to AGT v3.1.0 pre-release documentation (as of 2026-04-13).
8
+ */
9
+ import type { RuntimeGovernanceEvent } from '../types.js';
10
+ /** AGT-shaped input. Raw JSON, not SDK objects. */
11
+ export interface AgtEventInput {
12
+ /** Family name matching a RuntimeGovernanceFamily. */
13
+ family: string;
14
+ /** Specific event name (e.g., 'policy.evaluated'). */
15
+ event: string;
16
+ /** Event-specific data fields. */
17
+ data: Record<string, unknown>;
18
+ /** Optional upstream source context. */
19
+ source?: {
20
+ system?: string;
21
+ event_type?: string;
22
+ event_id?: string;
23
+ timestamp?: string;
24
+ artifact_hash?: string;
25
+ artifact_ref?: string;
26
+ cloud_event_type?: string;
27
+ };
28
+ }
29
+ /**
30
+ * Map an AGT-shaped event input to a normalized RuntimeGovernanceEvent.
31
+ * Throws NormalizationError on unrecognized or malformed input.
32
+ */
33
+ export declare function mapAgtEvent(input: AgtEventInput): RuntimeGovernanceEvent;
34
+ //# sourceMappingURL=agt.d.ts.map