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
//! Evidence an approver sees with a held call.
//!
//! A call that sends, keeps or acts on an image is held with the exact image as
//! [`Evidence`]: its digest, where it is stored, and an optional overlay of regions. Evidence
//! travels by reference and digest, never as pixels, so held calls, approval requests and
//! audit records stay small, and a surface loads the image through the artifact service with
//! the viewer's own authorisation.
//!
//! | Carried by | Set by |
//! |------------|--------|
//! | [`GovernedCall::evidence`](crate::GovernedCall::evidence) | [`Tool::approval_evidence`](crate::Tool::approval_evidence) through [`GovernedCall::for_tool`](crate::GovernedCall::for_tool), or [`GovernedCall::with_evidence`](crate::GovernedCall::with_evidence) |
//! | [`ToolConfirmationRequest::evidence`](crate::ToolConfirmationRequest::evidence) | The governed path, from the call |
//! | [`ApprovalRequest::evidence`](crate::ApprovalRequest::evidence) | The call's evidence, then any [`ApprovalRoute::evidence`](crate::ApprovalRoute::evidence) |
//!
//! The digests of a held call's own evidence are part of its
//! [fingerprint](crate::ToolConfirmationRequest::fingerprint), so a decision binds to the
//! exact images the approver saw: a call whose image changed before it ran is a different call
//! and is held again. A call without evidence keeps the fingerprint it always had.
//!
//! # Example
//!
//! ```rust
//! use adk_core::{ArtifactLocator, Evidence, ImageEvidence, ToolConfirmationRequest};
//! use serde_json::json;
//!
//! let crop = ImageEvidence::new(
//! "sha256:9f2c0a7e5b1d4c8a6f3e2d1c0b9a8f7e6d5c4b3a2f1e0d9c8b7a6f5e4d3c2b1a",
//! ArtifactLocator::new("desk", "ana", "s1", "egress/invoice-7-total.png", 1),
//! "image/png",
//! 640,
//! 180,
//! )
//! .with_regions(json!({ "regions": [{ "label": "total", "shape": { "box": [12, 8, 300, 60] } }] }))
//! .with_caption("Invoice 7, total field, after redaction");
//!
//! let call = ToolConfirmationRequest::new("vision_describe", json!({ "question": "What is the total?" }))
//! .with_evidence([Evidence::from(crop)]);
//! assert_eq!(call.evidence[0].digest(), "sha256:9f2c0a7e5b1d4c8a6f3e2d1c0b9a8f7e6d5c4b3a2f1e0d9c8b7a6f5e4d3c2b1a");
//! assert_eq!(serde_json::to_value(&call.evidence[0]).unwrap()["kind"], "image");
//! ```
use ;
use Value;
/// Where an artifact version lives in an `ArtifactService`: application, user, session,
/// file name and version.
///
/// # Example
///
/// ```rust
/// use adk_core::ArtifactLocator;
///
/// let locator = ArtifactLocator::new("desk", "ana", "s1", "egress/crop.png", 3);
/// assert_eq!(
/// serde_json::to_value(&locator).unwrap(),
/// serde_json::json!({
/// "appName": "desk", "userId": "ana", "sessionId": "s1",
/// "fileName": "egress/crop.png", "version": 3
/// })
/// );
/// ```
/// One item of evidence held with a call, tagged by `kind` on the wire.
///
/// # Example
///
/// ```rust
/// use adk_core::{ArtifactLocator, Evidence, ImageEvidence};
///
/// let digest = "sha256:0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8";
/// let evidence = Evidence::from(ImageEvidence::new(
/// digest,
/// ArtifactLocator::new("desk", "ana", "s1", "egress/card.png", 1),
/// "image/png",
/// 1024,
/// 640,
/// ));
/// let json = serde_json::to_value(&evidence).unwrap();
/// assert_eq!(json["kind"], "image");
/// assert_eq!(serde_json::from_value::<Evidence>(json).unwrap(), evidence);
/// assert_eq!(evidence.digest(), digest);
/// ```
/// An image held as evidence: its digest, its artifact, its format and size, and an optional
/// overlay of regions and caption.
///
/// `regions` is a `RegionSet` in the wire form `adk-vision` publishes
/// (`adk-vision/schema/region-set.json`), carried as JSON so surfaces can draw it without
/// depending on `adk-vision`.
///
/// # Example
///
/// ```rust
/// use adk_core::{ArtifactLocator, ImageEvidence};
/// use serde_json::json;
///
/// let image = ImageEvidence::new(
/// "sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae",
/// ArtifactLocator::new("desk", "ana", "s1", "egress/receipt.png", 2),
/// "image/png",
/// 800,
/// 1200,
/// )
/// .with_caption("Receipt, faces and card number filled");
/// assert_eq!(image.caption.as_deref(), Some("Receipt, faces and card number filled"));
/// assert!(serde_json::to_value(&image).unwrap().get("regions").is_none());
/// ```