meshagent-api 0.55.0__tar.gz → 0.55.1__tar.gz
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.
- {meshagent_api-0.55.0/meshagent_api.egg-info → meshagent_api-0.55.1}/PKG-INFO +1 -1
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/client.py +1 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/managed_agents.py +244 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/managed_agents_test.py +159 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/service_template_test.py +59 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/specs/service.py +12 -11
- meshagent_api-0.55.1/meshagent/api/version.py +1 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1/meshagent_api.egg-info}/PKG-INFO +1 -1
- meshagent_api-0.55.0/meshagent/api/version.py +0 -1
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/LICENSE +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/MANIFEST.in +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/README.md +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/__init__.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/agent_content.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/aiohttp_redaction.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/chan.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/client_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/crdt.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/dataset_schema.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/entrypoint.js +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/error_codes.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/file_permissions.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/files.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/files_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/helpers.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/http.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/image_runtime.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/keys.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/llm_router_config.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/messaging.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/messaging_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/mime_types.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/mime_types_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/oauth.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/oauth_branding.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/oauth_scopes.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/oauth_scopes_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/participant.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/participant_token.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/participant_token_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/port_forward.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/port_forward_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/protocol.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/protocol_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/py.typed +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/reasoning_schema.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/registry_auth.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/room_ports.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/room_server_client.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/room_server_client_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/runtime.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/runtime_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/schema.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/schema_document.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/schema_document_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/schema_registry.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/schema_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/schema_util.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/service_spec_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/services.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/services_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/sql.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/sql_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/sqlite_batch_integration_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/sqlite_replication_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/sqlite_transfer.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/sqlite_transfer_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/storage_policy_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/token_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/urls.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/webhooks.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/webhooks_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/websocket_protocol.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/websocket_protocol_test.py +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent_api.egg-info/SOURCES.txt +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent_api.egg-info/dependency_links.txt +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent_api.egg-info/requires.txt +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent_api.egg-info/top_level.txt +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/pyproject.toml +0 -0
- {meshagent_api-0.55.0 → meshagent_api-0.55.1}/setup.cfg +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import re
|
|
3
4
|
from typing import Annotated, Any, Literal
|
|
4
5
|
from urllib.parse import urlsplit
|
|
5
6
|
|
|
@@ -249,11 +250,104 @@ class ManagedAgentPythonTool(BaseModel):
|
|
|
249
250
|
return value
|
|
250
251
|
|
|
251
252
|
|
|
253
|
+
class ManagedAgentSecretHeader(BaseModel):
|
|
254
|
+
model_config = ConfigDict(extra="forbid")
|
|
255
|
+
|
|
256
|
+
id: str
|
|
257
|
+
|
|
258
|
+
@field_validator("id")
|
|
259
|
+
@classmethod
|
|
260
|
+
def validate_id(cls, value: str) -> str:
|
|
261
|
+
if not value.strip():
|
|
262
|
+
raise ValueError("secret.id must not be empty")
|
|
263
|
+
return value
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
class ManagedAgentConnectionHeader(BaseModel):
|
|
267
|
+
model_config = ConfigDict(extra="forbid")
|
|
268
|
+
|
|
269
|
+
name: str
|
|
270
|
+
value: str | None = None
|
|
271
|
+
secret: ManagedAgentSecretHeader | None = None
|
|
272
|
+
prefix: str = ""
|
|
273
|
+
|
|
274
|
+
@field_validator("prefix")
|
|
275
|
+
@classmethod
|
|
276
|
+
def validate_prefix(cls, value: str) -> str:
|
|
277
|
+
if any(ord(character) < 32 or ord(character) == 127 for character in value):
|
|
278
|
+
raise ValueError("prefix must not contain control characters")
|
|
279
|
+
return value
|
|
280
|
+
|
|
281
|
+
@model_validator(mode="after")
|
|
282
|
+
def validate_source(self) -> ManagedAgentConnectionHeader:
|
|
283
|
+
if (self.value is None) == (self.secret is None):
|
|
284
|
+
raise ValueError("header requires exactly one of value or secret")
|
|
285
|
+
if self.value is not None and self.prefix:
|
|
286
|
+
raise ValueError("prefix requires secret")
|
|
287
|
+
return self
|
|
288
|
+
|
|
289
|
+
|
|
252
290
|
class ManagedAgentHttpConnection(BaseModel):
|
|
253
291
|
model_config = ConfigDict(extra="forbid")
|
|
254
292
|
|
|
255
293
|
base_url: str
|
|
256
294
|
use_proxy_secret: str | None = None
|
|
295
|
+
headers: list[ManagedAgentConnectionHeader] = Field(default_factory=list)
|
|
296
|
+
|
|
297
|
+
@model_validator(mode="after")
|
|
298
|
+
def validate_headers(self) -> ManagedAgentHttpConnection:
|
|
299
|
+
reserved = {
|
|
300
|
+
"host",
|
|
301
|
+
"content-length",
|
|
302
|
+
"transfer-encoding",
|
|
303
|
+
"connection",
|
|
304
|
+
"proxy-authorization",
|
|
305
|
+
"proxy-authenticate",
|
|
306
|
+
"proxy-connection",
|
|
307
|
+
"keep-alive",
|
|
308
|
+
"upgrade",
|
|
309
|
+
"te",
|
|
310
|
+
"trailer",
|
|
311
|
+
"cookie",
|
|
312
|
+
"set-cookie",
|
|
313
|
+
"sec-websocket-accept",
|
|
314
|
+
"sec-websocket-extensions",
|
|
315
|
+
"sec-websocket-key",
|
|
316
|
+
"sec-websocket-protocol",
|
|
317
|
+
"sec-websocket-version",
|
|
318
|
+
}
|
|
319
|
+
names: set[str] = set()
|
|
320
|
+
secret_count = int(self.use_proxy_secret is not None)
|
|
321
|
+
for header in self.headers:
|
|
322
|
+
name = header.name
|
|
323
|
+
normalized = name.lower()
|
|
324
|
+
if (
|
|
325
|
+
re.fullmatch(r"[!#$%&'*+.^_`|~0-9A-Za-z-]+", name) is None
|
|
326
|
+
or normalized in reserved
|
|
327
|
+
or normalized in names
|
|
328
|
+
):
|
|
329
|
+
raise ValueError(f"header {name} is not allowed")
|
|
330
|
+
names.add(normalized)
|
|
331
|
+
if header.value is not None:
|
|
332
|
+
if any(
|
|
333
|
+
ord(character) < 32 or ord(character) == 127
|
|
334
|
+
for character in header.value
|
|
335
|
+
):
|
|
336
|
+
raise ValueError(f"header {name} has an invalid value")
|
|
337
|
+
else:
|
|
338
|
+
secret_count += 1
|
|
339
|
+
if self.use_proxy_secret is not None and "authorization" in names:
|
|
340
|
+
raise ValueError("Authorization conflicts with use_proxy_secret")
|
|
341
|
+
if secret_count > 16:
|
|
342
|
+
raise ValueError("a connection supports at most 16 secret headers")
|
|
343
|
+
if secret_count and any(
|
|
344
|
+
header.name.lower() == "authorization" and header.value is not None
|
|
345
|
+
for header in self.headers
|
|
346
|
+
):
|
|
347
|
+
raise ValueError(
|
|
348
|
+
"literal Authorization cannot be combined with secret headers"
|
|
349
|
+
)
|
|
350
|
+
return self
|
|
257
351
|
|
|
258
352
|
@field_validator("base_url")
|
|
259
353
|
@classmethod
|
|
@@ -277,6 +371,140 @@ class ManagedAgentHttpConnection(BaseModel):
|
|
|
277
371
|
return value
|
|
278
372
|
|
|
279
373
|
|
|
374
|
+
class ManagedAgentEnvironmentVariable(BaseModel):
|
|
375
|
+
model_config = ConfigDict(extra="forbid")
|
|
376
|
+
|
|
377
|
+
name: str = Field(pattern=r"^[A-Za-z_][A-Za-z0-9_]*$", max_length=128)
|
|
378
|
+
value: str | None = None
|
|
379
|
+
secret: ManagedAgentSecretHeader | None = None
|
|
380
|
+
|
|
381
|
+
@model_validator(mode="after")
|
|
382
|
+
def validate_source(self) -> ManagedAgentEnvironmentVariable:
|
|
383
|
+
if (self.value is None) == (self.secret is None):
|
|
384
|
+
raise ValueError(
|
|
385
|
+
"environment entry requires exactly one of value or secret"
|
|
386
|
+
)
|
|
387
|
+
return self
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
class ManagedAgentDecisionCheck(BaseModel):
|
|
391
|
+
model_config = ConfigDict(extra="forbid")
|
|
392
|
+
type: Literal["decision"] = "decision"
|
|
393
|
+
model: str = Field(pattern=r"^openai/[^/\s]+$")
|
|
394
|
+
instructions: str = Field(min_length=1, max_length=16384)
|
|
395
|
+
minimum_allow_probability: float = Field(ge=0, le=1, allow_inf_nan=False)
|
|
396
|
+
|
|
397
|
+
@field_validator("instructions")
|
|
398
|
+
@classmethod
|
|
399
|
+
def validate_instructions(cls, value: str) -> str:
|
|
400
|
+
if not value.strip() or len(value.encode("utf-8")) > 16384:
|
|
401
|
+
raise ValueError(
|
|
402
|
+
"guardrail instructions must contain 1 to 16384 UTF-8 bytes"
|
|
403
|
+
)
|
|
404
|
+
return value
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
class ManagedAgentGuardrailFailure(BaseModel):
|
|
408
|
+
model_config = ConfigDict(extra="forbid")
|
|
409
|
+
action: Literal["block", "deny", "replace", "pass", "fail"] = "block"
|
|
410
|
+
message: str | None = None
|
|
411
|
+
|
|
412
|
+
@model_validator(mode="after")
|
|
413
|
+
def validate_replacement(self):
|
|
414
|
+
if self.action == "replace" and not (self.message or "").strip():
|
|
415
|
+
raise ValueError("replacement guardrails require a message")
|
|
416
|
+
return self
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
class ManagedAgentGuardrail(BaseModel):
|
|
420
|
+
model_config = ConfigDict(extra="forbid")
|
|
421
|
+
name: str = Field(min_length=1)
|
|
422
|
+
check: ManagedAgentDecisionCheck
|
|
423
|
+
on_reject: ManagedAgentGuardrailFailure = Field(
|
|
424
|
+
default_factory=ManagedAgentGuardrailFailure
|
|
425
|
+
)
|
|
426
|
+
on_error: ManagedAgentGuardrailFailure = Field(
|
|
427
|
+
default_factory=lambda: ManagedAgentGuardrailFailure(action="fail")
|
|
428
|
+
)
|
|
429
|
+
max_retries: int = Field(default=2, ge=0, le=3, strict=True)
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
class ManagedAgentToolMatch(BaseModel):
|
|
433
|
+
model_config = ConfigDict(extra="forbid")
|
|
434
|
+
names: list[str] = Field(min_length=1)
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
class ManagedAgentToolGuardrails(BaseModel):
|
|
438
|
+
model_config = ConfigDict(extra="forbid")
|
|
439
|
+
name: str = Field(min_length=1)
|
|
440
|
+
match: ManagedAgentToolMatch
|
|
441
|
+
input: list[ManagedAgentGuardrail] = Field(default_factory=list)
|
|
442
|
+
output: list[ManagedAgentGuardrail] = Field(default_factory=list)
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
class ManagedAgentOutputGuardrails(BaseModel):
|
|
446
|
+
model_config = ConfigDict(extra="forbid")
|
|
447
|
+
checks: list[ManagedAgentGuardrail] = Field(default_factory=list)
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
class ManagedAgentGuardrails(BaseModel):
|
|
451
|
+
model_config = ConfigDict(extra="forbid")
|
|
452
|
+
input: list[ManagedAgentGuardrail] = Field(default_factory=list)
|
|
453
|
+
tools: list[ManagedAgentToolGuardrails] = Field(default_factory=list)
|
|
454
|
+
output: ManagedAgentOutputGuardrails = Field(
|
|
455
|
+
default_factory=ManagedAgentOutputGuardrails
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
@model_validator(mode="after")
|
|
459
|
+
def validate_rules(self):
|
|
460
|
+
names: set[str] = set()
|
|
461
|
+
rules = [*self.input, *self.output.checks]
|
|
462
|
+
for tool in self.tools:
|
|
463
|
+
if not tool.name.strip() or any(
|
|
464
|
+
not name.strip() for name in tool.match.names
|
|
465
|
+
):
|
|
466
|
+
raise ValueError("tool guardrails require nonempty names")
|
|
467
|
+
rules.extend(tool.input)
|
|
468
|
+
rules.extend(tool.output)
|
|
469
|
+
if len(rules) > 32:
|
|
470
|
+
raise ValueError("at most 32 guardrail checks are allowed")
|
|
471
|
+
boundaries = [
|
|
472
|
+
(self.input, {"block"}),
|
|
473
|
+
(self.output.checks, {"block", "replace"}),
|
|
474
|
+
]
|
|
475
|
+
for tool in self.tools:
|
|
476
|
+
boundaries.extend(
|
|
477
|
+
[
|
|
478
|
+
(tool.input, {"block", "deny"}),
|
|
479
|
+
(tool.output, {"block", "deny", "replace"}),
|
|
480
|
+
]
|
|
481
|
+
)
|
|
482
|
+
for checks, allowed in boundaries:
|
|
483
|
+
for rule in checks:
|
|
484
|
+
if (
|
|
485
|
+
rule.on_reject.action not in allowed
|
|
486
|
+
or rule.on_error.action not in allowed | {"pass", "fail"}
|
|
487
|
+
):
|
|
488
|
+
raise ValueError(
|
|
489
|
+
"guardrail action is not supported at this boundary"
|
|
490
|
+
)
|
|
491
|
+
for rule in rules:
|
|
492
|
+
if (
|
|
493
|
+
not rule.name
|
|
494
|
+
or len(rule.name) > 64
|
|
495
|
+
or any(
|
|
496
|
+
not (char.isascii() and (char.isalnum() or char in "_.-"))
|
|
497
|
+
for char in rule.name
|
|
498
|
+
)
|
|
499
|
+
or rule.name in names
|
|
500
|
+
):
|
|
501
|
+
raise ValueError("guardrail names must be nonempty and unique")
|
|
502
|
+
names.add(rule.name)
|
|
503
|
+
if not rule.check.instructions.strip():
|
|
504
|
+
raise ValueError("guardrail instructions must not be empty")
|
|
505
|
+
return self
|
|
506
|
+
|
|
507
|
+
|
|
280
508
|
class ManagedAgentSpec(BaseModel):
|
|
281
509
|
model_config = ConfigDict(extra="forbid")
|
|
282
510
|
version: Literal["v1"] = "v1"
|
|
@@ -284,6 +512,7 @@ class ManagedAgentSpec(BaseModel):
|
|
|
284
512
|
id: str | None = None
|
|
285
513
|
metadata: ManagedAgentMetadata
|
|
286
514
|
allowed_models: list[ManagedAllowedModel]
|
|
515
|
+
guardrails: ManagedAgentGuardrails | None = None
|
|
287
516
|
run_as: ManagedAgentRunAs | None = None
|
|
288
517
|
llm_delegation: ManagedAgentLlmDelegation = "optional"
|
|
289
518
|
thread_isolation: ManagedAgentThreadIsolation = "global"
|
|
@@ -291,6 +520,7 @@ class ManagedAgentSpec(BaseModel):
|
|
|
291
520
|
toolkits: list[ManagedToolkit] | None = None
|
|
292
521
|
tools: list[ManagedAgentPythonTool] = Field(default_factory=list)
|
|
293
522
|
connections: dict[str, ManagedAgentHttpConnection] = Field(default_factory=dict)
|
|
523
|
+
environment: list[ManagedAgentEnvironmentVariable] = Field(default_factory=list)
|
|
294
524
|
output_modalities: list[str] | None = None
|
|
295
525
|
store: bool = True
|
|
296
526
|
|
|
@@ -302,6 +532,20 @@ class ManagedAgentSpec(BaseModel):
|
|
|
302
532
|
raise ValueError("duplicate Python tool name")
|
|
303
533
|
return value
|
|
304
534
|
|
|
535
|
+
@model_validator(mode="after")
|
|
536
|
+
def validate_environment(self) -> ManagedAgentSpec:
|
|
537
|
+
names = [entry.name for entry in self.environment]
|
|
538
|
+
if len(names) != len(set(names)):
|
|
539
|
+
raise ValueError("duplicate environment variable name")
|
|
540
|
+
if len(names) > 64:
|
|
541
|
+
raise ValueError("at most 64 environment variables are supported")
|
|
542
|
+
if any(entry.secret is not None for entry in self.environment):
|
|
543
|
+
if self.run_as is None or "secrets:read" not in self.run_as.scopes:
|
|
544
|
+
raise ValueError(
|
|
545
|
+
"secret environment variables require run_as with secrets:read"
|
|
546
|
+
)
|
|
547
|
+
return self
|
|
548
|
+
|
|
305
549
|
@model_validator(mode="before")
|
|
306
550
|
@classmethod
|
|
307
551
|
def migrate_legacy_name(cls, value: object) -> object:
|
|
@@ -4,6 +4,81 @@ from pydantic import ValidationError
|
|
|
4
4
|
from meshagent.api.managed_agents import ManagedAgentSpec
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
def test_managed_agent_connection_supports_literal_and_secret_headers():
|
|
8
|
+
from meshagent.api.managed_agents import (
|
|
9
|
+
ManagedAgentHttpConnection,
|
|
10
|
+
ManagedAgentConnectionHeader,
|
|
11
|
+
ManagedAgentSecretHeader,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
connection = ManagedAgentHttpConnection.model_validate(
|
|
15
|
+
{
|
|
16
|
+
"base_url": "https://api.example.com",
|
|
17
|
+
"headers": [
|
|
18
|
+
{
|
|
19
|
+
"name": "Authorization",
|
|
20
|
+
"secret": {"id": "basic"},
|
|
21
|
+
"prefix": "Basic ",
|
|
22
|
+
},
|
|
23
|
+
{"name": "X-API-Key", "secret": {"id": "api-key"}},
|
|
24
|
+
{"name": "Accept", "value": "application/json"},
|
|
25
|
+
],
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
assert connection.headers[0] == ManagedAgentConnectionHeader(
|
|
29
|
+
name="Authorization",
|
|
30
|
+
secret=ManagedAgentSecretHeader(id="basic"),
|
|
31
|
+
prefix="Basic ",
|
|
32
|
+
)
|
|
33
|
+
assert connection.headers[1] == ManagedAgentConnectionHeader(
|
|
34
|
+
name="X-API-Key", secret=ManagedAgentSecretHeader(id="api-key")
|
|
35
|
+
)
|
|
36
|
+
assert connection.headers[2].value == "application/json"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@pytest.mark.parametrize(
|
|
40
|
+
"headers",
|
|
41
|
+
[
|
|
42
|
+
[{"name": "Host", "secret": {"id": "id"}}],
|
|
43
|
+
[{"name": "X-API-Key", "secret": {"id": ""}}],
|
|
44
|
+
[{"name": "X-API-Key", "secret": {"id": "id"}, "prefix": "bad\n"}],
|
|
45
|
+
[
|
|
46
|
+
{"name": "Authorization", "value": "Bearer value"},
|
|
47
|
+
{"name": "X-API-Key", "secret": {"id": "id"}},
|
|
48
|
+
],
|
|
49
|
+
],
|
|
50
|
+
)
|
|
51
|
+
def test_managed_agent_connection_rejects_unsafe_headers(headers):
|
|
52
|
+
from meshagent.api.managed_agents import ManagedAgentHttpConnection
|
|
53
|
+
|
|
54
|
+
with pytest.raises(ValidationError):
|
|
55
|
+
ManagedAgentHttpConnection(base_url="https://api.example.com", headers=headers)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_managed_agent_environment_requires_one_source_and_secret_scope():
|
|
59
|
+
base = {
|
|
60
|
+
"metadata": {"name": "planner"},
|
|
61
|
+
"allowed_models": [],
|
|
62
|
+
"environment": [
|
|
63
|
+
{"name": "CRM_URL", "value": "https://api.example.com"},
|
|
64
|
+
{"name": "CRM_KEY", "secret": {"id": "secret-1"}},
|
|
65
|
+
],
|
|
66
|
+
}
|
|
67
|
+
with pytest.raises(ValidationError, match="secrets:read"):
|
|
68
|
+
ManagedAgentSpec.model_validate(base)
|
|
69
|
+
base["run_as"] = {
|
|
70
|
+
"email": "agent@service.example.meshagent.dev",
|
|
71
|
+
"scopes": ["secrets:read", "llm_proxy"],
|
|
72
|
+
}
|
|
73
|
+
assert len(ManagedAgentSpec.model_validate(base).environment) == 2
|
|
74
|
+
base["environment"].append({"name": "CRM_URL", "value": "duplicate"})
|
|
75
|
+
with pytest.raises(ValidationError, match="duplicate environment"):
|
|
76
|
+
ManagedAgentSpec.model_validate(base)
|
|
77
|
+
base["environment"] = [{"name": "BAD", "value": "x", "secret": {"id": "id"}}]
|
|
78
|
+
with pytest.raises(ValidationError, match="exactly one"):
|
|
79
|
+
ManagedAgentSpec.model_validate(base)
|
|
80
|
+
|
|
81
|
+
|
|
7
82
|
def test_managed_agent_spec_accepts_missing_id_with_metadata_name():
|
|
8
83
|
spec = ManagedAgentSpec.model_validate(
|
|
9
84
|
{
|
|
@@ -302,3 +377,87 @@ def test_python_connections_reject_invalid_urls(url):
|
|
|
302
377
|
|
|
303
378
|
with pytest.raises(ValidationError):
|
|
304
379
|
ManagedAgentHttpConnection(base_url=url)
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def _guarded_spec():
|
|
383
|
+
return {
|
|
384
|
+
"metadata": {"name": "support"},
|
|
385
|
+
"allowed_models": [{"provider": "openai", "model": "gpt-6.1-sol"}],
|
|
386
|
+
"guardrails": {
|
|
387
|
+
"input": [
|
|
388
|
+
{
|
|
389
|
+
"name": "scope",
|
|
390
|
+
"check": {
|
|
391
|
+
"type": "decision",
|
|
392
|
+
"model": "openai/gpt-6-luna",
|
|
393
|
+
"instructions": "Allow support requests.",
|
|
394
|
+
"minimum_allow_probability": 0.9,
|
|
395
|
+
},
|
|
396
|
+
}
|
|
397
|
+
],
|
|
398
|
+
},
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def test_managed_agent_guardrails_round_trip():
|
|
403
|
+
spec = ManagedAgentSpec.model_validate(_guarded_spec())
|
|
404
|
+
assert spec.guardrails.input[0].on_error.action == "fail"
|
|
405
|
+
assert ManagedAgentSpec.model_validate_json(spec.model_dump_json()) == spec
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
@pytest.mark.parametrize("probability", [-0.1, 1.1, float("nan"), float("inf")])
|
|
409
|
+
def test_managed_agent_guardrails_reject_invalid_threshold(probability):
|
|
410
|
+
payload = _guarded_spec()
|
|
411
|
+
payload["guardrails"]["input"][0]["check"]["minimum_allow_probability"] = (
|
|
412
|
+
probability
|
|
413
|
+
)
|
|
414
|
+
with pytest.raises(ValidationError):
|
|
415
|
+
ManagedAgentSpec.model_validate(payload)
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def test_managed_agent_guardrails_reject_duplicate_names_and_invalid_actions():
|
|
419
|
+
payload = _guarded_spec()
|
|
420
|
+
payload["guardrails"]["output"] = {"checks": payload["guardrails"]["input"]}
|
|
421
|
+
with pytest.raises(ValidationError, match="unique"):
|
|
422
|
+
ManagedAgentSpec.model_validate(payload)
|
|
423
|
+
payload = _guarded_spec()
|
|
424
|
+
payload["guardrails"]["input"][0]["on_reject"] = {"action": "deny"}
|
|
425
|
+
with pytest.raises(ValidationError, match="boundary"):
|
|
426
|
+
ManagedAgentSpec.model_validate(payload)
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
@pytest.mark.parametrize("instructions", [" " * 3, "é" * 8193])
|
|
430
|
+
def test_guardrail_instruction_limits_match_runtime_utf8_bytes(instructions):
|
|
431
|
+
payload = _guarded_spec()
|
|
432
|
+
payload["guardrails"]["input"][0]["check"]["instructions"] = instructions
|
|
433
|
+
with pytest.raises(ValidationError, match="UTF-8 bytes"):
|
|
434
|
+
ManagedAgentSpec.model_validate(payload)
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def test_guardrail_instructions_accept_utf8_byte_limit():
|
|
438
|
+
payload = _guarded_spec()
|
|
439
|
+
payload["guardrails"]["input"][0]["check"]["instructions"] = "é" * 8192
|
|
440
|
+
assert ManagedAgentSpec.model_validate(payload).guardrails is not None
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
@pytest.mark.parametrize("retries", [-1, 4, 1.5])
|
|
444
|
+
def test_guardrail_retries_are_bounded(retries):
|
|
445
|
+
payload = _guarded_spec()
|
|
446
|
+
payload["guardrails"]["input"][0]["max_retries"] = retries
|
|
447
|
+
with pytest.raises(ValidationError):
|
|
448
|
+
ManagedAgentSpec.model_validate(payload)
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def test_guardrail_error_policy_defaults_to_fail_and_accepts_pass():
|
|
452
|
+
payload = _guarded_spec()
|
|
453
|
+
spec = ManagedAgentSpec.model_validate(payload)
|
|
454
|
+
assert spec.guardrails.input[0].max_retries == 2
|
|
455
|
+
assert spec.guardrails.input[0].on_error.action == "fail"
|
|
456
|
+
payload["guardrails"]["input"][0]["on_error"] = {"action": "pass"}
|
|
457
|
+
assert (
|
|
458
|
+
ManagedAgentSpec.model_validate(payload).guardrails.input[0].on_error.action
|
|
459
|
+
== "pass"
|
|
460
|
+
)
|
|
461
|
+
payload["guardrails"]["input"][0]["on_reject"] = {"action": "pass"}
|
|
462
|
+
with pytest.raises(ValidationError):
|
|
463
|
+
ManagedAgentSpec.model_validate(payload)
|
|
@@ -1,8 +1,67 @@
|
|
|
1
1
|
import json
|
|
2
2
|
|
|
3
|
+
import pytest
|
|
4
|
+
from jinja2 import UndefinedError
|
|
5
|
+
from jinja2.sandbox import SecurityError
|
|
6
|
+
|
|
3
7
|
from meshagent.api.specs.service import (
|
|
4
8
|
ServiceTemplateSpec,
|
|
9
|
+
format_yaml_value,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.mark.parametrize(
|
|
14
|
+
"render_path", ["scalar", "legacy_scalar", "yaml", "tagged_scalar"]
|
|
5
15
|
)
|
|
16
|
+
@pytest.mark.parametrize(
|
|
17
|
+
"payload",
|
|
18
|
+
[
|
|
19
|
+
"{{ cycler.__init__.__globals__.os.environ['MESHAGENT_TEMPLATE_TEST_SECRET'] }}",
|
|
20
|
+
"{{ lipsum.__globals__.os.environ['MESHAGENT_TEMPLATE_TEST_SECRET'] }}",
|
|
21
|
+
"{{ (cycler|attr('__init__')|attr('__globals__')).os.environ['MESHAGENT_TEMPLATE_TEST_SECRET'] }}",
|
|
22
|
+
],
|
|
23
|
+
)
|
|
24
|
+
def test_service_templates_block_process_environment_access(
|
|
25
|
+
monkeypatch: pytest.MonkeyPatch, render_path: str, payload: str
|
|
26
|
+
):
|
|
27
|
+
monkeypatch.setenv("MESHAGENT_TEMPLATE_TEST_SECRET", "synthetic-template-secret")
|
|
28
|
+
|
|
29
|
+
with pytest.raises((SecurityError, UndefinedError)):
|
|
30
|
+
if render_path == "scalar":
|
|
31
|
+
format_yaml_value(payload, {})
|
|
32
|
+
elif render_path == "legacy_scalar":
|
|
33
|
+
format_yaml_value("!template " + payload, {})
|
|
34
|
+
elif render_path == "yaml":
|
|
35
|
+
ServiceTemplateSpec.from_yaml(
|
|
36
|
+
yaml="version: v1\nkind: ServiceTemplate\nmetadata:\n name: " + payload
|
|
37
|
+
)
|
|
38
|
+
else:
|
|
39
|
+
ServiceTemplateSpec.from_yaml(
|
|
40
|
+
yaml="version: v1\nkind: ServiceTemplate\nmetadata:\n name: !template |-\n {{ payload }}",
|
|
41
|
+
values={"payload": payload},
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_service_template_sandbox_preserves_conditions_loops_and_filters():
|
|
46
|
+
yaml_spec = """
|
|
47
|
+
version: v1
|
|
48
|
+
kind: ServiceTemplate
|
|
49
|
+
metadata:
|
|
50
|
+
name: "{{ name | upper }}"
|
|
51
|
+
{% if enabled %}
|
|
52
|
+
agents:
|
|
53
|
+
{% for index in range(2) %}
|
|
54
|
+
- name: "agent-{{ index }}"
|
|
55
|
+
{% endfor %}
|
|
56
|
+
{% endif %}
|
|
57
|
+
"""
|
|
58
|
+
spec = ServiceTemplateSpec.from_yaml(
|
|
59
|
+
yaml=yaml_spec, values={"name": "support", "enabled": "yes"}
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
assert spec.metadata.name == "SUPPORT"
|
|
63
|
+
assert spec.agents is not None
|
|
64
|
+
assert [agent.name for agent in spec.agents] == ["agent-0", "agent-1"]
|
|
6
65
|
|
|
7
66
|
|
|
8
67
|
def test_service_template_spec_renders_jinja_values():
|
|
@@ -981,6 +981,15 @@ class ExternalServiceTemplateSpec(BaseModel):
|
|
|
981
981
|
url: str
|
|
982
982
|
|
|
983
983
|
|
|
984
|
+
def _render_service_template(source: str, values: dict[str, str]) -> str:
|
|
985
|
+
from jinja2.sandbox import ImmutableSandboxedEnvironment
|
|
986
|
+
|
|
987
|
+
# Service templates are untrusted input. Plain Template permits access to
|
|
988
|
+
# Python internals, including process globals, through its built-in helpers.
|
|
989
|
+
environment = ImmutableSandboxedEnvironment()
|
|
990
|
+
return environment.from_string(source).render(**values)
|
|
991
|
+
|
|
992
|
+
|
|
984
993
|
def format_yaml_value(original: Optional[str], values: dict[str, str]):
|
|
985
994
|
if original is None:
|
|
986
995
|
return None
|
|
@@ -992,10 +1001,7 @@ def format_yaml_value(original: Optional[str], values: dict[str, str]):
|
|
|
992
1001
|
if not legacy_prefixed and not has_jinja_syntax:
|
|
993
1002
|
return original
|
|
994
1003
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
template = Template(value)
|
|
998
|
-
return template.render(**values)
|
|
1004
|
+
return _render_service_template(value, values)
|
|
999
1005
|
|
|
1000
1006
|
|
|
1001
1007
|
def format_yaml_map(original: Optional[dict[str, str]], values: dict[str, str]):
|
|
@@ -1095,8 +1101,6 @@ class ServiceTemplateSpec(BaseModel):
|
|
|
1095
1101
|
|
|
1096
1102
|
@staticmethod
|
|
1097
1103
|
def from_yaml(yaml: str, values: dict[str, str] = {}) -> "ServiceTemplateSpec":
|
|
1098
|
-
from jinja2 import Template
|
|
1099
|
-
|
|
1100
1104
|
YAML, SafeLoader = _yaml_support()
|
|
1101
1105
|
|
|
1102
1106
|
class _ApplyTagLoader(SafeLoader):
|
|
@@ -1104,17 +1108,14 @@ class ServiceTemplateSpec(BaseModel):
|
|
|
1104
1108
|
|
|
1105
1109
|
def _tagged_scalar(loader, tag_suffix, node):
|
|
1106
1110
|
value = loader.construct_scalar(node)
|
|
1107
|
-
|
|
1108
|
-
return template.render(**values)
|
|
1111
|
+
return _render_service_template(value, values)
|
|
1109
1112
|
|
|
1110
1113
|
_ApplyTagLoader.add_multi_constructor("!template", _tagged_scalar)
|
|
1111
1114
|
|
|
1112
1115
|
def load_yaml(y: str):
|
|
1113
1116
|
return YAML.load(y, Loader=_ApplyTagLoader)
|
|
1114
1117
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
rendered = template.render(**values)
|
|
1118
|
+
rendered = _render_service_template(yaml, values)
|
|
1118
1119
|
|
|
1119
1120
|
spec = ServiceTemplateSpec.model_validate(load_yaml(rendered))
|
|
1120
1121
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.55.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.55.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{meshagent_api-0.55.0 → meshagent_api-0.55.1}/meshagent/api/sqlite_batch_integration_test.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|