nyx-agent-types 0.1.0

Implementation-detail serde and TypeScript wire types shared by nyx-agent crates.
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
//! Product-reset DTOs: launch profiles, environment runs, internal
//! pentest signals/candidates, verification attempts, and verified
//! vulnerabilities.

use serde::{Deserialize, Serialize};
use ts_rs::TS;

use crate::project::{
    AuthSetupResponse, ProjectAuthOwnedObject, ProjectRecord, ProjectRuntimeEnvVar,
};

pub fn clamp_risk_score(score: f64) -> f64 {
    if score.is_finite() {
        score.clamp(0.0, 10.0)
    } else {
        0.0
    }
}

pub fn risk_rating_for_score(score: f64) -> &'static str {
    let score = clamp_risk_score(score);
    if score >= 9.0 {
        "Critical"
    } else if score >= 7.0 {
        "High"
    } else if score >= 4.0 {
        "Medium"
    } else if score >= 1.0 {
        "Low"
    } else {
        "Info"
    }
}

pub fn canonical_risk_rating(raw: &str, score: f64) -> String {
    match raw.trim().to_ascii_lowercase().as_str() {
        "critical" => "Critical".to_string(),
        "high" => "High".to_string(),
        "medium" | "moderate" => "Medium".to_string(),
        "low" => "Low".to_string(),
        "info" | "informational" => "Info".to_string(),
        _ => risk_rating_for_score(score).to_string(),
    }
}

fn default_risk_rating() -> String {
    "Info".to_string()
}

fn default_risk_score_source() -> String {
    "heuristic".to_string()
}

fn default_risk_score_rationale() -> String {
    "Legacy record did not include a backend risk score.".to_string()
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct LaunchStep {
    pub command: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub repo_id: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub repo_name: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub working_directory: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "number")]
    pub timeout_seconds: Option<u64>,
    /// Optional stdin text written to the command after spawn. Useful
    /// for local-only tools that still ask for confirmation even when
    /// running in a non-interactive launch hook.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub stdin: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct LaunchHealthCheck {
    pub kind: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub url: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub host: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "number")]
    pub port: Option<u16>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub command: Option<LaunchStep>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "number")]
    pub timeout_seconds: Option<u64>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct LaunchEnvRef {
    /// `env-file` values are paths resolved relative to the launch
    /// step's working directory. `env-var` values are process env var
    /// names forwarded from the daemon environment.
    pub kind: String,
    pub value: String,
    #[serde(default)]
    pub secret: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct LaunchWorkingDir {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub repo_id: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub repo_name: Option<String>,
    pub path: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectLaunchProfile {
    pub id: String,
    pub project_id: String,
    pub name: String,
    pub mode: String,
    #[serde(default)]
    pub build_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub start_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub seed_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub reset_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub login_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub stop_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub health_checks: Vec<LaunchHealthCheck>,
    #[serde(default)]
    pub target_urls: Vec<String>,
    #[serde(default)]
    pub env_refs: Vec<LaunchEnvRef>,
    #[serde(default)]
    pub working_dirs: Vec<LaunchWorkingDir>,
    pub readiness: String,
    #[ts(type = "number")]
    pub created_at: i64,
    #[ts(type = "number")]
    pub updated_at: i64,
    pub is_default: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectLaunchProfileInput {
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub mode: Option<String>,
    #[serde(default)]
    pub build_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub start_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub seed_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub reset_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub login_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub stop_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub health_checks: Vec<LaunchHealthCheck>,
    #[serde(default)]
    pub target_urls: Vec<String>,
    #[serde(default)]
    pub env_refs: Vec<LaunchEnvRef>,
    #[serde(default)]
    pub working_dirs: Vec<LaunchWorkingDir>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectSetupRequest {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub target_base_url: Option<String>,
    #[serde(default = "default_project_setup_enabled")]
    pub project_setup: bool,
    #[serde(default)]
    pub seed_setup: bool,
    #[serde(default)]
    pub auth_setup: bool,
}

fn default_project_setup_enabled() -> bool {
    true
}

impl Default for ProjectSetupRequest {
    fn default() -> Self {
        Self { target_base_url: None, project_setup: true, seed_setup: false, auth_setup: false }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
#[serde(rename_all = "snake_case")]
pub enum ProjectSetupVerificationStatus {
    Verified,
    NeedsReview,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectSetupVerification {
    pub status: ProjectSetupVerificationStatus,
    #[serde(default)]
    pub checks: Vec<String>,
    #[serde(default)]
    pub warnings: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct SeedSetupPlan {
    #[serde(default)]
    pub seed_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub reset_steps: Vec<LaunchStep>,
    #[serde(default)]
    pub env_vars: Vec<ProjectRuntimeEnvVar>,
    #[serde(default)]
    pub roles: Vec<String>,
    #[serde(default)]
    pub seeded_objects: Vec<ProjectAuthOwnedObject>,
    pub summary: String,
    #[serde(default)]
    pub checks: Vec<String>,
    #[serde(default)]
    pub warnings: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct SeedSetupResponse {
    pub plan: SeedSetupPlan,
    pub verification: ProjectSetupVerification,
    pub message: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectSetupResponse {
    pub project: ProjectRecord,
    pub profile: ProjectLaunchProfile,
    pub agent_used: bool,
    pub verification: ProjectSetupVerification,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub seed_setup: Option<SeedSetupResponse>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub auth_setup: Option<AuthSetupResponse>,
    pub message: String,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
#[serde(rename_all = "snake_case")]
pub enum ProjectSetupJobStatus {
    Queued,
    Running,
    Succeeded,
    Failed,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
#[serde(rename_all = "snake_case")]
pub enum ProjectSetupPhase {
    Queued,
    CollectingRepos,
    StartingAgent,
    InspectingProject,
    InspectingSeed,
    ApplyingSeed,
    InspectingAuth,
    ApplyingProfile,
    Complete,
    Failed,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectSetupJobEvent {
    #[ts(type = "number")]
    pub at: i64,
    pub phase: ProjectSetupPhase,
    pub message: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectSetupError {
    pub code: String,
    pub title: String,
    pub detail: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub hint: Option<String>,
    pub retryable: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectSetupJobRecord {
    pub id: String,
    pub project_id: String,
    pub status: ProjectSetupJobStatus,
    pub phase: ProjectSetupPhase,
    pub message: String,
    #[ts(type = "number")]
    pub started_at: i64,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "number")]
    pub finished_at: Option<i64>,
    #[serde(default)]
    pub events: Vec<ProjectSetupJobEvent>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub result: Option<ProjectSetupResponse>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub error: Option<ProjectSetupError>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectSetupStartResponse {
    pub job: ProjectSetupJobRecord,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct ProjectSetupJobListResponse {
    pub jobs: Vec<ProjectSetupJobRecord>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct EnvironmentRunRecord {
    pub id: String,
    pub run_id: String,
    pub project_id: String,
    pub profile_id: String,
    pub status: String,
    #[ts(type = "number | null")]
    pub started_at: Option<i64>,
    #[ts(type = "number | null")]
    pub ready_at: Option<i64>,
    #[ts(type = "number | null")]
    pub stopped_at: Option<i64>,
    #[serde(default)]
    pub target_urls: Vec<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "unknown")]
    pub health: Option<serde_json::Value>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub logs_dir: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "unknown")]
    pub teardown: Option<serde_json::Value>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct NyxSignalRecord {
    pub id: String,
    pub run_id: String,
    pub project_id: String,
    pub repo_id: String,
    pub repo: String,
    pub path: String,
    #[ts(type = "number | null")]
    pub line: Option<i64>,
    pub cap: String,
    pub rule: String,
    pub severity: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub message: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "unknown")]
    pub evidence: Option<serde_json::Value>,
    pub signal_kind: String,
    pub meaningful: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub suppressed_reason: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub agent_candidate_id: Option<String>,
    #[ts(type = "number")]
    pub created_at: i64,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct PentestCandidateRecord {
    pub id: String,
    pub run_id: String,
    pub project_id: String,
    pub source: String,
    #[serde(default)]
    pub source_ids: Vec<String>,
    pub title: String,
    pub vuln_class: String,
    pub severity_guess: String,
    #[serde(default)]
    #[ts(type = "Array<unknown>")]
    pub affected_components: Vec<serde_json::Value>,
    pub hypothesis: String,
    pub test_plan: String,
    pub status: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub rejection_reason: Option<String>,
    pub confidence: f64,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub trace_id: Option<String>,
    #[ts(type = "number")]
    pub created_at: i64,
    #[ts(type = "number")]
    pub updated_at: i64,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct VerificationAttemptRecord {
    pub id: String,
    pub run_id: String,
    pub project_id: String,
    pub environment_run_id: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub candidate_id: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub chain_id: Option<String>,
    pub method: String,
    pub status: String,
    #[ts(type = "number")]
    pub started_at: i64,
    #[ts(type = "number | null")]
    pub finished_at: Option<i64>,
    #[ts(type = "number | null")]
    pub duration_ms: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "unknown")]
    pub request: Option<serde_json::Value>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "unknown")]
    pub response: Option<serde_json::Value>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "unknown")]
    pub oracle: Option<serde_json::Value>,
    #[serde(default)]
    pub artifact_paths: Vec<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub error: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub replay_stable: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct AuthzMatrixEntryRecord {
    pub id: String,
    pub run_id: String,
    pub project_id: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub candidate_id: Option<String>,
    pub verification_attempt_id: String,
    pub probe_kind: String,
    pub role: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub owner_role: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub tenant: Option<String>,
    pub resource: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub object_id: Option<String>,
    pub action: String,
    pub endpoint: String,
    pub expected_decision: String,
    pub observed_decision: String,
    #[ts(type = "number | null")]
    pub observed_status: Option<i64>,
    pub body_marker_result: String,
    pub confidence: f64,
    #[serde(default)]
    #[ts(type = "unknown")]
    pub evidence: serde_json::Value,
    #[ts(type = "number")]
    pub created_at: i64,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct ExplorationMemoryRecord {
    pub id: String,
    pub project_id: String,
    pub repo: String,
    pub run_id: String,
    pub source: String,
    pub hypothesis: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub endpoint: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub role_context: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub object_context: Option<String>,
    pub result: String,
    pub reason: String,
    #[serde(default)]
    pub useful_markers: Vec<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub auth_session_notes: Option<String>,
    #[serde(default)]
    pub follow_up_ideas: Vec<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub candidate_id: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub verification_attempt_id: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub trace_id: Option<String>,
    pub memory_key: String,
    #[ts(type = "number")]
    pub created_at: i64,
    #[ts(type = "number")]
    pub updated_at: i64,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct VerifiedVulnerabilityRecord {
    pub id: String,
    pub run_id: String,
    pub project_id: String,
    pub title: String,
    pub severity: String,
    pub confidence: f64,
    #[serde(default)]
    pub risk_score: f64,
    #[serde(default = "default_risk_rating")]
    pub risk_rating: String,
    #[serde(default = "default_risk_score_source")]
    pub risk_score_source: String,
    #[serde(default = "default_risk_score_rationale")]
    pub risk_score_rationale: String,
    pub vuln_class: String,
    #[serde(default)]
    #[ts(type = "Array<unknown>")]
    pub affected_components: Vec<serde_json::Value>,
    pub business_impact: String,
    pub evidence_summary: String,
    pub repro_steps: String,
    pub remediation: String,
    #[serde(default)]
    pub source_candidate_ids: Vec<String>,
    #[serde(default)]
    pub source_signal_ids: Vec<String>,
    #[serde(default)]
    pub verification_attempt_ids: Vec<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub chain_id: Option<String>,
    pub status: String,
    #[ts(type = "number")]
    pub first_seen: i64,
    #[ts(type = "number")]
    pub last_seen: i64,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct RouteEvidence {
    pub path: String,
    #[ts(type = "number | null")]
    pub line: Option<i64>,
    pub snippet: String,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, TS)]
pub struct RouteModelEndpoint {
    pub method: String,
    pub path: String,
    #[serde(default)]
    pub framework: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub repo: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub handler_file: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub handler_name: Option<String>,
    #[ts(type = "number | null")]
    pub line: Option<i64>,
    #[serde(default)]
    pub params: Vec<String>,
    #[serde(default)]
    pub query_params: Vec<String>,
    #[serde(default)]
    pub middleware: Vec<String>,
    #[serde(default)]
    pub auth_checks: Vec<String>,
    #[serde(default)]
    pub role_checks: Vec<String>,
    #[serde(default)]
    pub body_fields: Vec<String>,
    #[serde(default)]
    pub request_fields: Vec<String>,
    #[serde(default)]
    pub response_hints: Vec<String>,
    #[serde(default)]
    pub service_calls: Vec<String>,
    #[serde(default)]
    pub model_names: Vec<String>,
    #[serde(default)]
    pub resource_names: Vec<String>,
    #[serde(default)]
    pub tenant_fields: Vec<String>,
    #[serde(default)]
    pub owner_fields: Vec<String>,
    #[serde(default)]
    pub side_effects: Vec<String>,
    #[serde(default)]
    pub state_changing: bool,
    pub confidence: f64,
    #[serde(default)]
    pub evidence: Vec<RouteEvidence>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct FrontendRouteModel {
    pub path: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub repo: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub file: Option<String>,
    #[ts(type = "number | null")]
    pub line: Option<i64>,
    pub confidence: f64,
    #[serde(default)]
    pub evidence: Vec<RouteEvidence>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct ApiClientCallModel {
    pub method: String,
    pub path: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub repo: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub file: Option<String>,
    #[ts(type = "number | null")]
    pub line: Option<i64>,
    pub confidence: f64,
    #[serde(default)]
    pub evidence: Vec<RouteEvidence>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct FormModel {
    pub method: String,
    pub action: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub repo: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub file: Option<String>,
    #[ts(type = "number | null")]
    pub line: Option<i64>,
    #[serde(default)]
    pub fields: Vec<String>,
    #[serde(default)]
    pub csrf_markers: Vec<String>,
    #[serde(default)]
    pub state_changing: bool,
    pub confidence: f64,
    #[serde(default)]
    pub evidence: Vec<RouteEvidence>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, TS)]
pub struct RouteModel {
    #[serde(default)]
    pub backend_routes: Vec<RouteModelEndpoint>,
    #[serde(default)]
    pub frontend_routes: Vec<FrontendRouteModel>,
    #[serde(default)]
    pub api_client_calls: Vec<ApiClientCallModel>,
    #[serde(default)]
    pub forms: Vec<FormModel>,
    #[serde(default)]
    pub notes: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct RouteModelRecord {
    pub id: String,
    pub run_id: String,
    pub project_id: String,
    pub model: RouteModel,
    #[ts(type = "number")]
    pub created_at: i64,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct StartPentestRequest {
    #[serde(default)]
    pub exploit_mode_enabled: bool,
    #[serde(default)]
    pub allow_state_changing_live_probes: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub exploit_dry_run: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub browser_checks_enabled: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub business_logic_templates_enabled: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub research_mode_enabled: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional)]
    pub unsafe_attack_agent_enabled: Option<bool>,
    #[serde(default)]
    pub business_logic_template_ids: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct StartPentestResponse {
    pub run_id: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct TestLaunchTargetRequest {
    pub url: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "number")]
    pub timeout_seconds: Option<u64>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
pub struct TestLaunchTargetResponse {
    pub ok: bool,
    pub url: String,
    pub message: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[ts(optional, type = "number")]
    pub status: Option<u16>,
    #[ts(type = "number")]
    pub elapsed_ms: u64,
}