sekuire-protocol 0.1.1

Shared protocol types for the Sekuire Agent Identity Protocol
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

// --- Sekuire Identity Protocol ---

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct Manifest {
    pub project: ProjectMetadata,
    pub identity: IdentityConfig,
    /// Optional: agent capability declaration for discovery/orchestration.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub capabilities: Option<AgentCapabilities>,
    /// Optional: discovery metadata (tags, categories, keywords).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub discovery: Option<DiscoveryMetadata>,
    /// Optional: A2A (Agent-to-Agent) runtime settings for managed routing.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub a2a: Option<A2AConfig>,
    /// Optional: deployment/install metadata (env vars, container hints, etc).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub deployment: Option<DeploymentConfig>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct ProjectMetadata {
    pub name: String,
    pub version: String,
    pub description: Option<String>,
    #[serde(default)]
    pub authors: Vec<String>,
    pub license: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct IdentityConfig {
    /// The model identifier (e.g., "gpt-4-0613")
    pub model: String,

    /// Path to the system prompt file (relative to sekuire.json)
    pub system_prompt_path: String,

    /// Path to the tools definition file (relative to sekuire.json)
    pub tools_path: String,

    /// The Blake3 hash of the system prompt content
    pub system_prompt_hash: Option<String>,

    /// The Blake3 hash of the tools definition content
    pub tools_hash: Option<String>,
}

// --- Agent Discovery / Orchestration (Optional) ---

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct AgentCapabilities {
    /// Capabilities this agent provides (e.g., "jira:tickets:create").
    #[serde(default)]
    pub provides: Vec<String>,
    /// Capabilities this agent may require to complete its own tasks.
    #[serde(default)]
    pub requires: Vec<String>,
    /// Optional: preferred delegation targets for sub-tasks.
    #[serde(default)]
    pub delegates_to: Vec<DelegationTarget>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct DelegationTarget {
    pub agent_type: String,
    #[serde(default)]
    pub capabilities: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct DiscoveryMetadata {
    #[serde(default)]
    pub tags: Vec<String>,
    #[serde(default)]
    pub categories: Vec<String>,
    #[serde(default)]
    pub search_keywords: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct A2AConfig {
    /// The agent's upstream A2A task endpoint (used by Sekuire-managed routing).
    /// This should be the base tasks URL, e.g. `http://localhost:8001/a2a/tasks`.
    pub upstream_url: String,
    /// Optional: public base URL for direct calls (non-managed environments).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub public_base_url: Option<String>,
}

// --- Installation / Deployment Metadata (Optional) ---

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct DeploymentConfig {
    /// Environment variables required or supported by this agent.
    #[serde(default)]
    pub env: Vec<EnvVarSpec>,
    /// Optional: suggested container image reference for BYO-host deployments.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub docker_image: Option<String>,
    /// Optional: runtime notes to display in installation instructions.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub notes: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct EnvVarSpec {
    pub name: String,
    #[serde(default)]
    pub required: bool,
    #[serde(default)]
    pub secret: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub example: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub default_value: Option<String>,
}

// --- Registry API Types ---

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct PublishRequest {
    pub manifest: Manifest,
    pub sekuire_id: String, // The calculated hash
    pub signature: String,  // Signed hash
    pub public_key: String, // The signer's public key
    // Organization publishing support
    #[serde(skip_serializing_if = "Option::is_none")]
    pub publisher_org_id: Option<String>, // Organization ID if publishing on behalf of org
    #[serde(skip_serializing_if = "Option::is_none")]
    pub visibility: Option<String>, // Override default visibility (public, private, internal)
}

// --- Trust Registry Types ---

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct AgentResponse {
    pub sekuire_id: String,
    pub public_key: String, // Renamed from author_key to match frontend
    pub name: String,
    pub version: String,
    pub description: Option<String>,
    pub created_at: String, // ISO8601
    pub verification_status: VerificationStatus,
    pub reputation_score: i32, // 0-100
    #[serde(skip_serializing_if = "Option::is_none")]
    pub manifest: Option<serde_json::Value>, // Full manifest for detailed views
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<String>,

    // Publisher information
    #[serde(skip_serializing_if = "Option::is_none")]
    pub publisher_user_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub publisher_email: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub publisher_name: Option<String>,

    // Organization ownership
    #[serde(skip_serializing_if = "Option::is_none")]
    pub publisher_org_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub publisher_org_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub org_metadata: Option<serde_json::Value>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub visibility: Option<AgentVisibility>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub public_url: Option<String>,

    // Repository information
    #[serde(skip_serializing_if = "Option::is_none")]
    pub git_repository: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub commit_hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub repository_verified: Option<bool>,

    // Documentation
    #[serde(skip_serializing_if = "Option::is_none")]
    pub readme_content: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub changelog_content: Option<String>,

    // Review process
    #[serde(skip_serializing_if = "Option::is_none")]
    pub code_review_status: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub security_score: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reviewed_by: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reviewed_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub review_notes: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "snake_case")]
#[cfg_attr(
    feature = "backend",
    sqlx(type_name = "verification_status", rename_all = "snake_case")
)]
pub enum VerificationStatus {
    Unverified,
    Pending,
    Verified,
    Suspended,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "snake_case")]
#[cfg_attr(
    feature = "backend",
    sqlx(type_name = "agent_visibility", rename_all = "snake_case")
)]
pub enum AgentVisibility {
    Public,
    Private,
    Internal,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct ReputationResponse {
    pub score: i32,
    pub task_count: i32,
    pub verification_badge: Option<String>, // e.g., "HIPAA"
    pub recent_logs: Vec<ReputationLog>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct ReputationLog {
    pub id: String,
    pub task_hash: String,
    pub rating: i32, // 1-5
    pub comment: Option<String>,
    pub timestamp: String,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct SubmitReputationRequest {
    pub sekuire_id: String,
    pub task_hash: String,
    pub rating: i32,
    pub comment: Option<String>,
    pub signature: String, // Employer's signature over the rating
}

// --- Handshake Protocol ---

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct HandshakeHello {
    pub client_nonce: String, // Random 32-byte hex
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct HandshakeWelcome {
    pub agent_id: String,
    pub agent_nonce: String,      // Random 32-byte hex
    pub signature_c: String,      // Sign(client_nonce) by Agent
    pub credentials: Vec<String>, // List of Signed VCs (JWTs)
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct HandshakeAuth {
    pub signature_a: String, // Sign(agent_nonce) by Client
}

// --- Categories ---

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct Category {
    pub id: String,
    pub name: String,
    pub slug: String,
    pub description: Option<String>,
    pub icon: Option<String>,
    pub parent_id: Option<String>,
    pub parent_name: Option<String>,
    pub is_active: bool,
    pub display_order: i32,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct AssignCategoryRequest {
    pub sekuire_id: String,
    pub category_ids: Vec<String>,           // Category IDs or slugs
    pub primary_category_id: Option<String>, // Optional primary category
}

// --- Verification & Disputes ---

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct VerifyAgentRequest {
    pub sekuire_id: String,
    pub status: VerificationStatus, // Verified, Suspended
    pub badge: Option<String>,      // e.g. "safe", "hipaa"
    pub reason: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct DisputeRequest {
    pub sekuire_id: String,
    pub accuser_id: String, // Employer ID
    pub reason: String,
    pub evidence_log: String, // Signed conversation
}

// --- Deprecated / Legacy Management API (To be refactored) ---

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct CreateOrgRequest {
    pub slug: String,
    pub display_name: String,
    pub billing_email: String,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct OrgResponse {
    pub id: String,
    pub slug: String,
    pub role: String,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct CreateWorkspaceRequest {
    pub name: String,
    pub policy_preset: String,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct WorkspaceResponse {
    pub id: String,
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct InviteRequest {
    pub email: String,
    pub role: String,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct InviteResponse {
    pub id: String,
    pub status: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct UserContextResponse {
    pub id: String,
    pub email: String,
    pub onboarded: bool,
    pub mfa_enabled: bool,
    pub role: Option<String>,
    pub full_name: Option<String>,
    pub avatar_url: Option<String>,
    pub onboarding_step: i32,
    pub profile_completed: bool,
    pub orgs: Vec<OrgSummary>,
    pub workspaces: Vec<WorkspaceSummary>,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct OrgSummary {
    pub id: String,
    pub slug: String,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub workspaces: Vec<WorkspaceSummary>,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct WorkspaceSummary {
    pub id: String,
    pub name: String,
    pub org_id: String,
}

// Task Completion & Reputation
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct TaskCompletionRequest {
    pub sekuire_id: String,
    pub task_hash: String,
    pub rating: i32, // 1-5 stars
    pub comment: Option<String>,
    pub employer_id: String, // Who's rating the agent
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct TaskCompletionResponse {
    pub success: bool,
    pub new_reputation_score: i32,
    pub reputation_change: i32,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct LeaderboardEntry {
    pub rank: i32,
    pub sekuire_id: String,
    pub name: String,
    pub reputation_score: i32,
    pub task_count: i32,
    pub success_rate: f64,
    pub average_rating: f64,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct EnhancedReputationResponse {
    pub score: i32,
    pub rank: Option<i32>,
    pub total_agents: i32,
    pub task_count: i32,
    pub success_count: i32,
    pub dispute_count: i32,
    pub success_rate: f64,
    pub average_rating: f64,
    pub verification_badge: Option<String>,
    pub recent_logs: Vec<ReputationLog>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct VerifyAgentResponse {
    pub verified: bool,
    pub sekuire_id: String,
    pub name: String,
    pub verification_status: VerificationStatus,
    pub reputation_score: i32,
    pub badges: Vec<String>, // ["verified", "hipaa", "pci"]
    pub success_rate: Option<f64>,
    pub task_count: i32,
    pub risk_level: String, // "low", "medium", "high"
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct BadgeRequest {
    pub sekuire_id: String,
    pub badge_type: String, // "hipaa", "pci", "soc2", "verified"
    pub evidence: Option<String>,
}

// Quick Verification - Blue Checkmark API
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct QuickVerifyRequest {
    pub sekuire_id: String,
    pub requesting_agent: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct QuickVerifyResponse {
    pub verified: bool,
    pub sekuire_id: String,
    pub name: String,
    pub verification_status: VerificationStatus,
    pub reputation_score: i32,
    pub badges: Vec<String>,
    pub success_rate: Option<f64>,
    pub task_count: i32,
    pub risk_level: String,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct IssueBadgeRequest {
    pub sekuire_id: String,
    pub badge_type: String,
    pub evidence: Option<String>,
}

// Header Verification
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct VerifyHeadersRequest {
    pub agent_id: String,
    pub reputation: i32,
    pub credentials: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct VerifyHeadersResponse {
    pub valid: bool,
    pub message: String,
    pub discrepancies: Vec<String>,
}

// --- Agent Event Logging Types ---

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "snake_case")]
#[cfg_attr(
    feature = "backend",
    sqlx(type_name = "text", rename_all = "snake_case")
)]
pub enum EventType {
    ToolExecution,
    ModelCall,
    PolicyViolation,
    PolicyCheck,
    NetworkAccess,
    FileAccess,
    Health,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "lowercase")]
#[cfg_attr(
    feature = "backend",
    sqlx(type_name = "text", rename_all = "lowercase")
)]
pub enum Severity {
    Debug,
    Info,
    Warn,
    Error,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct AgentEventLog {
    pub sekuire_id: String,
    pub session_id: String,
    pub workspace_id: Option<String>,
    pub event_type: EventType,
    pub severity: Severity,
    pub event_timestamp: String, // ISO8601
    pub event_data: serde_json::Value,
    pub metadata: serde_json::Value,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct LogEventRequest {
    pub events: Vec<AgentEventLog>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct LogEventResponse {
    pub success: bool,
    pub events_logged: usize,
    pub errors: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct AgentHealthRequest {
    pub sekuire_id: String,
    pub status: String,
    pub session_id: String,
    pub sdk_version: String,
    pub environment: String,
    pub metadata: serde_json::Value,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct AgentHealthResponse {
    pub success: bool,
    pub message: String,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct GetLogsQuery {
    pub limit: Option<i64>,
    pub offset: Option<i64>,
    pub event_type: Option<EventType>,
    pub severity: Option<Severity>,
    pub session_id: Option<String>,
    pub start_time: Option<String>, // ISO8601
    pub end_time: Option<String>,   // ISO8601
}

#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct GetLogsResponse {
    pub logs: Vec<AgentEventLogResponse>,
    pub total: i64,
    pub limit: i64,
    pub offset: i64,
}

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct AgentEventLogResponse {
    pub id: i64,
    pub sekuire_id: String,
    pub session_id: String,
    pub workspace_id: Option<String>,
    pub event_type: EventType,
    pub severity: Severity,
    pub event_timestamp: String,
    pub received_at: String,
    pub event_data: serde_json::Value,
    pub metadata: serde_json::Value,
}