@mnemom/agent-alignment-protocol 0.1.0
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.d.mts +683 -0
- package/dist/index.d.ts +683 -0
- package/dist/index.js +625 -0
- package/dist/index.mjs +576 -0
- package/package.json +56 -0
- package/src/constants.ts +44 -0
- package/src/index.ts +135 -0
- package/src/schemas/alignment-card.ts +166 -0
- package/src/schemas/ap-trace.ts +163 -0
- package/src/schemas/index.ts +7 -0
- package/src/schemas/value-coherence.ts +177 -0
- package/src/verification/api.ts +565 -0
- package/src/verification/features.ts +157 -0
- package/src/verification/index.ts +7 -0
- package/src/verification/models.ts +182 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Alignment Protocol (AAP) - TypeScript SDK
|
|
3
|
+
*
|
|
4
|
+
* This package provides the core verification functionality for AAP:
|
|
5
|
+
* - verifyTrace: Verify a single AP-Trace against an Alignment Card
|
|
6
|
+
* - checkCoherence: Check value coherence between two Alignment Cards
|
|
7
|
+
* - detectDrift: Detect behavioral drift from declared alignment over time
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { verifyTrace, checkCoherence, detectDrift } from 'agent-alignment-protocol';
|
|
12
|
+
* import type { AlignmentCard, APTrace } from 'agent-alignment-protocol';
|
|
13
|
+
*
|
|
14
|
+
* // Verify a trace
|
|
15
|
+
* const result = verifyTrace(trace, card);
|
|
16
|
+
* if (!result.verified) {
|
|
17
|
+
* console.log('Violations:', result.violations);
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Check coherence between two cards
|
|
21
|
+
* const coherence = checkCoherence(myCard, theirCard);
|
|
22
|
+
* if (!coherence.compatible) {
|
|
23
|
+
* console.log('Value conflicts:', coherence.value_alignment.conflicts);
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // Detect drift over time
|
|
27
|
+
* const alerts = detectDrift(card, recentTraces);
|
|
28
|
+
* for (const alert of alerts) {
|
|
29
|
+
* console.log('Drift detected:', alert.analysis.drift_direction);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @see https://aap.dev for documentation
|
|
34
|
+
* @see SPEC.md for protocol specification
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
// Main API exports
|
|
38
|
+
export { verifyTrace, checkCoherence, detectDrift } from "./verification/api";
|
|
39
|
+
|
|
40
|
+
// Schema types
|
|
41
|
+
export type {
|
|
42
|
+
// Alignment Card
|
|
43
|
+
AlignmentCard,
|
|
44
|
+
Principal,
|
|
45
|
+
PrincipalType,
|
|
46
|
+
RelationshipType,
|
|
47
|
+
Values,
|
|
48
|
+
ValueDefinition,
|
|
49
|
+
HierarchyType,
|
|
50
|
+
AutonomyEnvelope,
|
|
51
|
+
EscalationTrigger,
|
|
52
|
+
TriggerAction,
|
|
53
|
+
MonetaryValue,
|
|
54
|
+
AuditCommitment,
|
|
55
|
+
AuditStorage,
|
|
56
|
+
StorageType,
|
|
57
|
+
TamperEvidence,
|
|
58
|
+
} from "./schemas/alignment-card";
|
|
59
|
+
|
|
60
|
+
export type {
|
|
61
|
+
// AP-Trace
|
|
62
|
+
APTrace,
|
|
63
|
+
Action,
|
|
64
|
+
ActionType,
|
|
65
|
+
ActionCategory,
|
|
66
|
+
ActionTarget,
|
|
67
|
+
Decision,
|
|
68
|
+
Alternative,
|
|
69
|
+
Escalation,
|
|
70
|
+
EscalationStatus,
|
|
71
|
+
TriggerCheck,
|
|
72
|
+
PrincipalResponse,
|
|
73
|
+
TraceContext,
|
|
74
|
+
} from "./schemas/ap-trace";
|
|
75
|
+
|
|
76
|
+
export type {
|
|
77
|
+
// Value Coherence
|
|
78
|
+
AlignmentCardRequest,
|
|
79
|
+
AlignmentCardResponse,
|
|
80
|
+
ValueCoherenceCheck,
|
|
81
|
+
CoherenceResultMessage,
|
|
82
|
+
ValueCoherenceMessage,
|
|
83
|
+
RequesterInfo,
|
|
84
|
+
TaskContext,
|
|
85
|
+
Signature,
|
|
86
|
+
ProposedCollaboration,
|
|
87
|
+
DataSharing,
|
|
88
|
+
AutonomyScope,
|
|
89
|
+
Coherence,
|
|
90
|
+
ValueAlignmentDetail,
|
|
91
|
+
ValueConflict,
|
|
92
|
+
ProposedResolution,
|
|
93
|
+
} from "./schemas/value-coherence";
|
|
94
|
+
|
|
95
|
+
// Result types
|
|
96
|
+
export type {
|
|
97
|
+
VerificationResult,
|
|
98
|
+
Violation,
|
|
99
|
+
ViolationType,
|
|
100
|
+
Severity,
|
|
101
|
+
Warning,
|
|
102
|
+
VerificationMetadata,
|
|
103
|
+
CoherenceResult,
|
|
104
|
+
ValueAlignment,
|
|
105
|
+
ValueConflictResult,
|
|
106
|
+
DriftAlert,
|
|
107
|
+
DriftAnalysis,
|
|
108
|
+
DriftDirection,
|
|
109
|
+
DriftIndicator,
|
|
110
|
+
} from "./verification/models";
|
|
111
|
+
|
|
112
|
+
// Utility exports
|
|
113
|
+
export {
|
|
114
|
+
isCardExpired,
|
|
115
|
+
hasValue,
|
|
116
|
+
isActionBounded,
|
|
117
|
+
isActionForbidden,
|
|
118
|
+
} from "./schemas/alignment-card";
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
getSelectedAlternative,
|
|
122
|
+
wasEscalated,
|
|
123
|
+
hadViolations,
|
|
124
|
+
} from "./schemas/ap-trace";
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
extractCardFeatures,
|
|
128
|
+
extractTraceFeatures,
|
|
129
|
+
cosineSimilarity,
|
|
130
|
+
} from "./verification/features";
|
|
131
|
+
|
|
132
|
+
export { createViolation, VIOLATION_SEVERITY } from "./verification/models";
|
|
133
|
+
|
|
134
|
+
// Constants
|
|
135
|
+
export * from "./constants";
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Alignment Card schema - Agent alignment declaration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the Alignment Card structure per SPEC Section 4. An Alignment Card
|
|
5
|
+
* is a structured document declaring an agent's alignment posture.
|
|
6
|
+
*
|
|
7
|
+
* @see SPEC.md Section 4 for complete specification.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Type of principal the agent serves. */
|
|
11
|
+
export type PrincipalType = "human" | "organization" | "agent" | "unspecified";
|
|
12
|
+
|
|
13
|
+
/** Nature of authority delegation from principal to agent. */
|
|
14
|
+
export type RelationshipType = "delegated_authority" | "advisory" | "autonomous";
|
|
15
|
+
|
|
16
|
+
/** How value conflicts are resolved. */
|
|
17
|
+
export type HierarchyType = "lexicographic" | "weighted" | "contextual";
|
|
18
|
+
|
|
19
|
+
/** Action to take when escalation trigger matches. */
|
|
20
|
+
export type TriggerAction = "escalate" | "deny" | "log";
|
|
21
|
+
|
|
22
|
+
/** Audit log storage type. */
|
|
23
|
+
export type StorageType = "local" | "remote" | "distributed";
|
|
24
|
+
|
|
25
|
+
/** Tamper-evidence mechanism for audit logs. */
|
|
26
|
+
export type TamperEvidence = "append_only" | "signed" | "merkle";
|
|
27
|
+
|
|
28
|
+
/** Principal relationship declaration (SPEC Section 4.3). */
|
|
29
|
+
export interface Principal {
|
|
30
|
+
/** Type of principal */
|
|
31
|
+
type: PrincipalType;
|
|
32
|
+
/** Principal identifier (DID, email, org ID) */
|
|
33
|
+
identifier?: string | null;
|
|
34
|
+
/** Nature of authority delegation */
|
|
35
|
+
relationship: RelationshipType;
|
|
36
|
+
/** Endpoint for escalation notifications */
|
|
37
|
+
escalation_contact?: string | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Definition of a custom value. */
|
|
41
|
+
export interface ValueDefinition {
|
|
42
|
+
/** Human-readable name */
|
|
43
|
+
name: string;
|
|
44
|
+
/** What this value means operationally */
|
|
45
|
+
description: string;
|
|
46
|
+
/** Priority for lexicographic ordering (higher = more important) */
|
|
47
|
+
priority?: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Value declarations (SPEC Section 4.4). */
|
|
51
|
+
export interface Values {
|
|
52
|
+
/** List of value identifiers */
|
|
53
|
+
declared: string[];
|
|
54
|
+
/** Definitions for non-standard values */
|
|
55
|
+
definitions?: Record<string, ValueDefinition> | null;
|
|
56
|
+
/** Values this agent refuses to coordinate with */
|
|
57
|
+
conflicts_with?: string[] | null;
|
|
58
|
+
/** How value conflicts are resolved */
|
|
59
|
+
hierarchy?: HierarchyType | null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Condition that triggers escalation (SPEC Section 4.5). */
|
|
63
|
+
export interface EscalationTrigger {
|
|
64
|
+
/** Condition expression (see SPEC Section 4.6) */
|
|
65
|
+
condition: string;
|
|
66
|
+
/** Action to take when trigger matches */
|
|
67
|
+
action: TriggerAction;
|
|
68
|
+
/** Human-readable explanation */
|
|
69
|
+
reason: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Monetary value specification. */
|
|
73
|
+
export interface MonetaryValue {
|
|
74
|
+
/** Numeric amount */
|
|
75
|
+
amount: number;
|
|
76
|
+
/** ISO 4217 currency code */
|
|
77
|
+
currency?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Autonomy bounds and escalation triggers (SPEC Section 4.5). */
|
|
81
|
+
export interface AutonomyEnvelope {
|
|
82
|
+
/** Actions permitted without escalation */
|
|
83
|
+
bounded_actions: string[];
|
|
84
|
+
/** Conditions requiring escalation */
|
|
85
|
+
escalation_triggers: EscalationTrigger[];
|
|
86
|
+
/** Maximum transaction value without escalation */
|
|
87
|
+
max_autonomous_value?: MonetaryValue | null;
|
|
88
|
+
/** Actions never permitted */
|
|
89
|
+
forbidden_actions?: string[] | null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Audit log storage configuration. */
|
|
93
|
+
export interface AuditStorage {
|
|
94
|
+
/** Storage type */
|
|
95
|
+
type: StorageType;
|
|
96
|
+
/** Storage endpoint or location */
|
|
97
|
+
location?: string | null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Audit trail commitments (SPEC Section 4.7). */
|
|
101
|
+
export interface AuditCommitment {
|
|
102
|
+
/** Trace format identifier */
|
|
103
|
+
trace_format?: string;
|
|
104
|
+
/** Minimum retention period in days */
|
|
105
|
+
retention_days: number;
|
|
106
|
+
/** Storage configuration */
|
|
107
|
+
storage?: AuditStorage | null;
|
|
108
|
+
/** Whether traces can be queried externally */
|
|
109
|
+
queryable: boolean;
|
|
110
|
+
/** Endpoint for trace queries (required if queryable=true) */
|
|
111
|
+
query_endpoint?: string | null;
|
|
112
|
+
/** Tamper-evidence mechanism */
|
|
113
|
+
tamper_evidence?: TamperEvidence | null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Alignment Card - Agent alignment declaration (SPEC Section 4).
|
|
118
|
+
*
|
|
119
|
+
* A structured document declaring an agent's alignment posture. It MUST be
|
|
120
|
+
* machine-readable (JSON) and SHOULD be human-readable.
|
|
121
|
+
*/
|
|
122
|
+
export interface AlignmentCard {
|
|
123
|
+
/** AAP specification version */
|
|
124
|
+
aap_version?: string;
|
|
125
|
+
/** Unique identifier for this card (UUID or URI) */
|
|
126
|
+
card_id: string;
|
|
127
|
+
/** Identifier for the agent (DID, URL, or UUID) */
|
|
128
|
+
agent_id: string;
|
|
129
|
+
/** When this card was issued (ISO 8601) */
|
|
130
|
+
issued_at: string;
|
|
131
|
+
/** When this card expires (ISO 8601) */
|
|
132
|
+
expires_at?: string | null;
|
|
133
|
+
/** Principal relationship declaration */
|
|
134
|
+
principal: Principal;
|
|
135
|
+
/** Value declarations */
|
|
136
|
+
values: Values;
|
|
137
|
+
/** Autonomy bounds and escalation triggers */
|
|
138
|
+
autonomy_envelope: AutonomyEnvelope;
|
|
139
|
+
/** Audit trail commitments */
|
|
140
|
+
audit_commitment: AuditCommitment;
|
|
141
|
+
/** Protocol-specific extensions */
|
|
142
|
+
extensions?: Record<string, unknown> | null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Utility functions
|
|
146
|
+
|
|
147
|
+
/** Check if an alignment card has expired. */
|
|
148
|
+
export function isCardExpired(card: AlignmentCard): boolean {
|
|
149
|
+
if (!card.expires_at) return false;
|
|
150
|
+
return new Date() > new Date(card.expires_at);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Check if a value is declared in the card. */
|
|
154
|
+
export function hasValue(card: AlignmentCard, value: string): boolean {
|
|
155
|
+
return card.values.declared.includes(value);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Check if an action is in the bounded actions list. */
|
|
159
|
+
export function isActionBounded(card: AlignmentCard, action: string): boolean {
|
|
160
|
+
return card.autonomy_envelope.bounded_actions.includes(action);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Check if an action is forbidden. */
|
|
164
|
+
export function isActionForbidden(card: AlignmentCard, action: string): boolean {
|
|
165
|
+
return (card.autonomy_envelope.forbidden_actions ?? []).includes(action);
|
|
166
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AP-Trace schema - Audit log format for agent decisions.
|
|
3
|
+
*
|
|
4
|
+
* Defines the AP-Trace structure per SPEC Section 5. An AP-Trace entry
|
|
5
|
+
* records an agent's decision process.
|
|
6
|
+
*
|
|
7
|
+
* @see SPEC.md Section 5 for complete specification.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Type of action taken or considered. */
|
|
11
|
+
export type ActionType = "recommend" | "execute" | "escalate" | "deny";
|
|
12
|
+
|
|
13
|
+
/** How the action relates to the autonomy envelope. */
|
|
14
|
+
export type ActionCategory = "bounded" | "escalation_trigger" | "forbidden";
|
|
15
|
+
|
|
16
|
+
/** Status of an escalation. */
|
|
17
|
+
export type EscalationStatus = "pending" | "approved" | "denied" | "timeout";
|
|
18
|
+
|
|
19
|
+
/** Resource affected by the action. */
|
|
20
|
+
export interface ActionTarget {
|
|
21
|
+
/** Resource type */
|
|
22
|
+
type: string;
|
|
23
|
+
/** Resource identifier */
|
|
24
|
+
identifier: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Action taken or considered (SPEC Section 5.4). */
|
|
28
|
+
export interface Action {
|
|
29
|
+
/** Action type */
|
|
30
|
+
type: ActionType;
|
|
31
|
+
/** Human-readable action name */
|
|
32
|
+
name: string;
|
|
33
|
+
/** How this action relates to autonomy envelope */
|
|
34
|
+
category: ActionCategory;
|
|
35
|
+
/** Resource affected */
|
|
36
|
+
target?: ActionTarget | null;
|
|
37
|
+
/** Action parameters */
|
|
38
|
+
parameters?: Record<string, unknown> | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** An alternative considered during decision-making. */
|
|
42
|
+
export interface Alternative {
|
|
43
|
+
/** Unique identifier for this option */
|
|
44
|
+
option_id: string;
|
|
45
|
+
/** Human-readable description */
|
|
46
|
+
description: string;
|
|
47
|
+
/** Computed score (0.0 to 1.0) */
|
|
48
|
+
score?: number | null;
|
|
49
|
+
/** Breakdown of score components */
|
|
50
|
+
scoring_factors?: Record<string, number> | null;
|
|
51
|
+
/** Concerns or flags about this option */
|
|
52
|
+
flags?: string[] | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Decision process record (SPEC Section 5.5). */
|
|
56
|
+
export interface Decision {
|
|
57
|
+
/** Options evaluated (minimum 1) */
|
|
58
|
+
alternatives_considered: Alternative[];
|
|
59
|
+
/** Option ID selected */
|
|
60
|
+
selected: string;
|
|
61
|
+
/** Human-readable explanation of why this was chosen */
|
|
62
|
+
selection_reasoning: string;
|
|
63
|
+
/** Values that influenced this decision */
|
|
64
|
+
values_applied: string[];
|
|
65
|
+
/** Decision confidence (0.0 to 1.0) */
|
|
66
|
+
confidence?: number | null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Record of checking an escalation trigger. */
|
|
70
|
+
export interface TriggerCheck {
|
|
71
|
+
/** Trigger condition that was checked */
|
|
72
|
+
trigger: string;
|
|
73
|
+
/** Whether the trigger matched */
|
|
74
|
+
matched: boolean;
|
|
75
|
+
/** Observed value (for comparison triggers) */
|
|
76
|
+
value_observed?: unknown | null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Response from principal to escalation. */
|
|
80
|
+
export interface PrincipalResponse {
|
|
81
|
+
/** Principal's decision */
|
|
82
|
+
decision: string;
|
|
83
|
+
/** When decision was made (ISO 8601) */
|
|
84
|
+
timestamp: string;
|
|
85
|
+
/** Conditions attached to approval */
|
|
86
|
+
conditions?: string[] | null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Escalation evaluation record (SPEC Section 5.6). */
|
|
90
|
+
export interface Escalation {
|
|
91
|
+
/** Whether escalation was evaluated */
|
|
92
|
+
evaluated: boolean;
|
|
93
|
+
/** Triggers that were evaluated */
|
|
94
|
+
triggers_checked?: TriggerCheck[] | null;
|
|
95
|
+
/** Whether escalation is required */
|
|
96
|
+
required: boolean;
|
|
97
|
+
/** Human-readable explanation */
|
|
98
|
+
reason: string;
|
|
99
|
+
/** Escalation request ID (if escalation required) */
|
|
100
|
+
escalation_id?: string | null;
|
|
101
|
+
/** Status of escalation (if escalation required) */
|
|
102
|
+
escalation_status?: EscalationStatus | null;
|
|
103
|
+
/** Principal's response (if escalation required) */
|
|
104
|
+
principal_response?: PrincipalResponse | null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Additional context for the trace (SPEC Section 5.7). */
|
|
108
|
+
export interface TraceContext {
|
|
109
|
+
/** Session identifier */
|
|
110
|
+
session_id?: string | null;
|
|
111
|
+
/** Turn number in conversation */
|
|
112
|
+
conversation_turn?: number | null;
|
|
113
|
+
/** IDs of related prior traces */
|
|
114
|
+
prior_trace_ids?: string[] | null;
|
|
115
|
+
/** Environment metadata (client, locale, etc.) */
|
|
116
|
+
environment?: Record<string, unknown> | null;
|
|
117
|
+
/** Additional arbitrary metadata */
|
|
118
|
+
metadata?: Record<string, unknown> | null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* AP-Trace - Audit log entry for agent decisions (SPEC Section 5).
|
|
123
|
+
*
|
|
124
|
+
* An AP-Trace records an agent's decision process, enabling verification
|
|
125
|
+
* that observed behavior is consistent with declared alignment.
|
|
126
|
+
*/
|
|
127
|
+
export interface APTrace {
|
|
128
|
+
/** Unique identifier (UUID) */
|
|
129
|
+
trace_id: string;
|
|
130
|
+
/** Agent that generated this trace */
|
|
131
|
+
agent_id: string;
|
|
132
|
+
/** Alignment Card in effect */
|
|
133
|
+
card_id: string;
|
|
134
|
+
/** When this trace was created (ISO 8601) */
|
|
135
|
+
timestamp: string;
|
|
136
|
+
/** Action taken or considered */
|
|
137
|
+
action: Action;
|
|
138
|
+
/** Decision process record */
|
|
139
|
+
decision: Decision;
|
|
140
|
+
/** Escalation evaluation (if applicable) */
|
|
141
|
+
escalation?: Escalation | null;
|
|
142
|
+
/** Additional context */
|
|
143
|
+
context?: TraceContext | null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Utility functions
|
|
147
|
+
|
|
148
|
+
/** Get the selected alternative from the decision. */
|
|
149
|
+
export function getSelectedAlternative(trace: APTrace): Alternative | undefined {
|
|
150
|
+
return trace.decision.alternatives_considered.find(
|
|
151
|
+
(alt) => alt.option_id === trace.decision.selected
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Check if this decision was escalated. */
|
|
156
|
+
export function wasEscalated(trace: APTrace): boolean {
|
|
157
|
+
return trace.escalation != null && trace.escalation.required;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Check if the action was forbidden or triggered unhandled escalation. */
|
|
161
|
+
export function hadViolations(trace: APTrace): boolean {
|
|
162
|
+
return trace.action.category === "forbidden";
|
|
163
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value Coherence Handshake messages - Agent-to-agent alignment verification.
|
|
3
|
+
*
|
|
4
|
+
* Defines the message types for the Value Coherence Handshake protocol
|
|
5
|
+
* per SPEC Section 6.
|
|
6
|
+
*
|
|
7
|
+
* @see SPEC.md Section 6 for complete specification.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { AlignmentCard } from "./alignment-card";
|
|
11
|
+
|
|
12
|
+
/** Information about the agent making a request. */
|
|
13
|
+
export interface RequesterInfo {
|
|
14
|
+
/** Agent identifier (DID, URL, or UUID) */
|
|
15
|
+
agent_id: string;
|
|
16
|
+
/** Requester's Alignment Card ID */
|
|
17
|
+
card_id: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Context about the task for which alignment is being checked. */
|
|
21
|
+
export interface TaskContext {
|
|
22
|
+
/** Type of task being proposed */
|
|
23
|
+
task_type: string;
|
|
24
|
+
/** Values required for this task */
|
|
25
|
+
values_required?: string[] | null;
|
|
26
|
+
/** Categories of data involved */
|
|
27
|
+
data_categories?: string[] | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Request for an agent's Alignment Card (SPEC Section 6.3.1). */
|
|
31
|
+
export interface AlignmentCardRequest {
|
|
32
|
+
/** Message type identifier */
|
|
33
|
+
message_type?: "alignment_card_request";
|
|
34
|
+
/** Unique request identifier */
|
|
35
|
+
request_id: string;
|
|
36
|
+
/** Information about requesting agent */
|
|
37
|
+
requester: RequesterInfo;
|
|
38
|
+
/** Context about the proposed task */
|
|
39
|
+
task_context?: TaskContext | null;
|
|
40
|
+
/** When request was made (ISO 8601) */
|
|
41
|
+
timestamp?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Cryptographic signature for authentication. */
|
|
45
|
+
export interface Signature {
|
|
46
|
+
/** Signature algorithm (e.g., Ed25519) */
|
|
47
|
+
algorithm: string;
|
|
48
|
+
/** Base64-encoded signature */
|
|
49
|
+
value: string;
|
|
50
|
+
/** Key identifier */
|
|
51
|
+
key_id: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Response with an agent's Alignment Card (SPEC Section 6.3.2). */
|
|
55
|
+
export interface AlignmentCardResponse {
|
|
56
|
+
/** Message type identifier */
|
|
57
|
+
message_type?: "alignment_card_response";
|
|
58
|
+
/** Request ID being responded to */
|
|
59
|
+
request_id: string;
|
|
60
|
+
/** Responder's Alignment Card */
|
|
61
|
+
alignment_card: AlignmentCard;
|
|
62
|
+
/** Optional signature for authentication */
|
|
63
|
+
signature?: Signature | null;
|
|
64
|
+
/** When response was made (ISO 8601) */
|
|
65
|
+
timestamp?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Data sharing specification for collaboration. */
|
|
69
|
+
export interface DataSharing {
|
|
70
|
+
/** Data categories initiator will share */
|
|
71
|
+
from_initiator?: string[];
|
|
72
|
+
/** Data categories responder will share */
|
|
73
|
+
from_responder?: string[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Scope of autonomous actions for collaboration. */
|
|
77
|
+
export interface AutonomyScope {
|
|
78
|
+
/** Actions initiator may take */
|
|
79
|
+
initiator_actions?: string[];
|
|
80
|
+
/** Actions responder may take */
|
|
81
|
+
responder_actions?: string[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Proposed collaboration details. */
|
|
85
|
+
export interface ProposedCollaboration {
|
|
86
|
+
/** Type of task */
|
|
87
|
+
task_type: string;
|
|
88
|
+
/** Values both agents should apply */
|
|
89
|
+
values_intersection?: string[] | null;
|
|
90
|
+
/** Data sharing specification */
|
|
91
|
+
data_sharing?: DataSharing | null;
|
|
92
|
+
/** Scope of autonomous actions */
|
|
93
|
+
autonomy_scope?: AutonomyScope | null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Value coherence check request (SPEC Section 6.3.3). */
|
|
97
|
+
export interface ValueCoherenceCheck {
|
|
98
|
+
/** Message type identifier */
|
|
99
|
+
message_type?: "value_coherence_check";
|
|
100
|
+
/** Request ID */
|
|
101
|
+
request_id: string;
|
|
102
|
+
/** Initiator's Alignment Card ID */
|
|
103
|
+
initiator_card_id: string;
|
|
104
|
+
/** Responder's Alignment Card ID */
|
|
105
|
+
responder_card_id: string;
|
|
106
|
+
/** Proposed collaboration details */
|
|
107
|
+
proposed_collaboration: ProposedCollaboration;
|
|
108
|
+
/** When check was requested (ISO 8601) */
|
|
109
|
+
timestamp?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** A conflict between values declared by two agents. */
|
|
113
|
+
export interface ValueConflict {
|
|
114
|
+
/** Value from initiating agent */
|
|
115
|
+
initiator_value: string;
|
|
116
|
+
/** Value from responding agent */
|
|
117
|
+
responder_value: string;
|
|
118
|
+
/** Type of conflict (incompatible, priority_mismatch, etc.) */
|
|
119
|
+
conflict_type: string;
|
|
120
|
+
/** Human-readable explanation */
|
|
121
|
+
description: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Detailed value alignment analysis. */
|
|
125
|
+
export interface ValueAlignmentDetail {
|
|
126
|
+
/** Values present in both cards */
|
|
127
|
+
matched?: string[];
|
|
128
|
+
/** Values in one card but not the other */
|
|
129
|
+
unmatched?: string[];
|
|
130
|
+
/** Direct value conflicts */
|
|
131
|
+
conflicts?: ValueConflict[];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Coherence assessment. */
|
|
135
|
+
export interface Coherence {
|
|
136
|
+
/** Whether agents are compatible */
|
|
137
|
+
compatible: boolean;
|
|
138
|
+
/** Coherence score (0.0 to 1.0) */
|
|
139
|
+
score: number;
|
|
140
|
+
/** Detailed alignment analysis */
|
|
141
|
+
value_alignment: ValueAlignmentDetail;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Proposed resolution for value conflicts. */
|
|
145
|
+
export interface ProposedResolution {
|
|
146
|
+
/** Resolution type */
|
|
147
|
+
type: string;
|
|
148
|
+
/** Why this resolution is proposed */
|
|
149
|
+
reason: string;
|
|
150
|
+
/** Alternative proposal (if applicable) */
|
|
151
|
+
alternative?: Record<string, unknown> | null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Coherence result message (SPEC Section 6.3.4). */
|
|
155
|
+
export interface CoherenceResultMessage {
|
|
156
|
+
/** Message type identifier */
|
|
157
|
+
message_type?: "coherence_result";
|
|
158
|
+
/** Request ID being responded to */
|
|
159
|
+
request_id: string;
|
|
160
|
+
/** Coherence assessment */
|
|
161
|
+
coherence: Coherence;
|
|
162
|
+
/** Whether to proceed with coordination */
|
|
163
|
+
proceed: boolean;
|
|
164
|
+
/** Conditions for proceeding (if any) */
|
|
165
|
+
conditions?: string[] | null;
|
|
166
|
+
/** Proposed resolution (if conflicts exist) */
|
|
167
|
+
proposed_resolution?: ProposedResolution | null;
|
|
168
|
+
/** When result was generated (ISO 8601) */
|
|
169
|
+
timestamp?: string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Union of all Value Coherence Handshake message types. */
|
|
173
|
+
export type ValueCoherenceMessage =
|
|
174
|
+
| AlignmentCardRequest
|
|
175
|
+
| AlignmentCardResponse
|
|
176
|
+
| ValueCoherenceCheck
|
|
177
|
+
| CoherenceResultMessage;
|