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
//! Environment wire types for the Gemini Interactions API.
//!
//! An environment is a server-side sandbox workspace attached to an interaction.
//! It represents the second state dimension (sandbox state), distinct from
//! conversation state managed via `previous_interaction_id`.
//!
//! Three forms are supported:
//! - Request a fresh remote sandbox (`"remote"`)
//! - Resume an existing environment by ID (e.g. `"env_abc123"`)
//! - Provide an inline configuration with sources and network rules
//!
//! All types in this module are gated behind the `interactions` feature flag.
use HashMap;
use fmt;
use ;
// ══════════════════════════════════════════════════════════════════════
// Environment (polymorphic request field)
// ══════════════════════════════════════════════════════════════════════
/// The `environment` request field: attach a sandbox to an interaction.
///
/// Three forms: request a fresh remote sandbox, resume an existing one by ID,
/// or provide an inline configuration with sources and network rules.
///
/// # Example
///
/// ```rust
/// use adk_gemini::interactions::{Environment, EnvironmentConfig};
///
/// // Request a fresh remote sandbox
/// let env = Environment::remote();
///
/// // Resume an existing environment
/// let env = Environment::resume("env_abc123");
///
/// // Provide inline configuration
/// let config = EnvironmentConfig::new();
/// let env = Environment::config(config);
/// ```
// ══════════════════════════════════════════════════════════════════════
// EnvironmentConfig
// ══════════════════════════════════════════════════════════════════════
/// Inline environment configuration: type, sources, and network rules.
///
/// Describes a sandbox environment to create, including filesystem sources to
/// seed and network egress rules.
///
/// # Example
///
/// ```rust
/// use adk_gemini::interactions::{EnvironmentConfig, EnvironmentSource, NetworkConfig};
///
/// let config = EnvironmentConfig::new()
/// .with_sources(vec![
/// EnvironmentSource::Repository {
/// source: "https://github.com/user/repo".to_string(),
/// target: "/workspace".to_string(),
/// },
/// ])
/// .with_network(NetworkConfig::disabled());
/// ```
// ══════════════════════════════════════════════════════════════════════
// EnvironmentSource (polymorphic)
// ══════════════════════════════════════════════════════════════════════
/// A source entry that seeds the sandbox filesystem.
///
/// Each source has a `type` discriminator and provides content to be placed at a
/// `target` path within the sandbox.
///
/// # Example
///
/// ```rust
/// use adk_gemini::interactions::EnvironmentSource;
///
/// // Inline content (max 1 MB per file, 2 MB total)
/// let inline = EnvironmentSource::Inline {
/// content: "fn main() {}".to_string(),
/// target: "/workspace/main.rs".to_string(),
/// };
///
/// // Git repository (max 500 MB)
/// let repo = EnvironmentSource::Repository {
/// source: "https://github.com/user/repo".to_string(),
/// target: "/workspace".to_string(),
/// };
///
/// // Google Cloud Storage object (max 2 GB)
/// let gcs = EnvironmentSource::Gcs {
/// source: "gs://bucket/archive.tar.gz".to_string(),
/// target: "/workspace".to_string(),
/// };
/// ```
// ══════════════════════════════════════════════════════════════════════
// NetworkConfig (polymorphic)
// ══════════════════════════════════════════════════════════════════════
/// Network egress configuration for an environment.
///
/// Either all outbound traffic is disabled, or an allowlist of domains is
/// specified with optional credential injection via transform maps.
///
/// # Example
///
/// ```rust
/// use adk_gemini::interactions::{NetworkConfig, NetworkRule, TransformMap};
/// use std::collections::HashMap;
///
/// // Block all outbound traffic
/// let disabled = NetworkConfig::disabled();
///
/// // Allow specific domains
/// let allowlist = NetworkConfig::allowlist(vec![
/// NetworkRule::new("crates.io"),
/// NetworkRule::new("*.github.com")
/// .with_transform(TransformMap(HashMap::from([
/// ("Authorization".to_string(), "Bearer ghp_xxx".to_string()),
/// ]))),
/// ]);
/// ```
// ══════════════════════════════════════════════════════════════════════
// NetworkRule and TransformMap
// ══════════════════════════════════════════════════════════════════════
/// A single network allowlist entry.
///
/// Specifies a domain pattern and optional HTTP header injection for credential
/// forwarding through the egress proxy.
///
/// # Example
///
/// ```rust
/// use adk_gemini::interactions::{NetworkRule, TransformMap};
/// use std::collections::HashMap;
///
/// // Simple domain allowlist entry
/// let rule = NetworkRule::new("crates.io");
///
/// // Domain with credential injection
/// let rule = NetworkRule::new("*.github.com")
/// .with_transform(TransformMap(HashMap::from([
/// ("Authorization".to_string(), "Bearer ghp_xxx".to_string()),
/// ])));
/// ```
/// A flat map of HTTP header names to credential values.
///
/// Implements a custom [`Debug`] that redacts all values to prevent credential
/// leakage in logs. Serialization preserves the actual values for the wire.
///
/// # Example
///
/// ```rust
/// use adk_gemini::interactions::TransformMap;
/// use std::collections::HashMap;
///
/// let map = TransformMap(HashMap::from([
/// ("Authorization".to_string(), "Bearer secret_token".to_string()),
/// ]));
///
/// // Debug output redacts values
/// let debug = format!("{:?}", map);
/// assert!(debug.contains("Authorization"));
/// assert!(debug.contains("[REDACTED]"));
/// assert!(!debug.contains("secret_token"));
///
/// // Serialization preserves actual values
/// let json = serde_json::to_string(&map).unwrap();
/// assert!(json.contains("secret_token"));
/// ```
;