managed-deepagents 0.10.3.dev7__py3-none-win_amd64.whl → 0.10.3.dev8__py3-none-win_amd64.whl

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.
Binary file
@@ -31,6 +31,11 @@ from uuid import UUID
31
31
  from langgraph_sdk import Auth
32
32
  from langgraph_sdk.auth import is_studio_user
33
33
  from langgraph_sdk.auth.types import (
34
+ AssistantsCreate,
35
+ AssistantsDelete,
36
+ AssistantsRead,
37
+ AssistantsSearch,
38
+ AssistantsUpdate,
34
39
  AuthContext,
35
40
  BaseUser,
36
41
  CronsCreate,
@@ -69,6 +74,7 @@ from managed_deepagents._thread_record import (
69
74
  THREAD_CONVERSATION_METADATA,
70
75
  THREAD_PARTICIPANTS_METADATA,
71
76
  THREAD_RECORD_METADATA,
77
+ is_person_principal,
72
78
  names_thread_record_key,
73
79
  parse_thread_record,
74
80
  strip_thread_record_keys,
@@ -79,6 +85,11 @@ ThreadsValue = (
79
85
  ThreadsCreate | ThreadsRead | ThreadsUpdate | ThreadsDelete | ThreadsSearch | RunsCreate
80
86
  )
81
87
  CronsValue = CronsCreate | CronsRead | CronsUpdate | CronsDelete | CronsSearch
88
+ AssistantsValue = (
89
+ AssistantsCreate | AssistantsRead | AssistantsUpdate | AssistantsDelete | AssistantsSearch
90
+ )
91
+ #: Metadata key naming the person who created an assistant.
92
+ ASSISTANT_OWNER_METADATA = "mda_assistant_owner"
82
93
 
83
94
  HeaderName = str | bytes
84
95
  HeaderValue = str | bytes | None
@@ -390,6 +401,7 @@ def build_managed_auth(identity: IdentityDefinitionLike) -> Auth:
390
401
  # dead handlers.
391
402
  auth.authenticate(authenticate)
392
403
  auth.on(_scope_any)
404
+ auth.on.assistants(_scope_assistants)
393
405
  auth.on.threads(_scope_threads)
394
406
  auth.on.crons(_scope_crons)
395
407
  auth.on.store(_scope_store)
@@ -540,6 +552,46 @@ async def _scope_any(ctx: AuthContext, value: dict[str, Any]) -> None:
540
552
  raise _http_exception(err) from err
541
553
 
542
554
 
555
+ async def _scope_assistants(ctx: AuthContext, value: AssistantsValue) -> FilterType | None:
556
+ """Anyone may read assistants; a person may create, update and delete their own."""
557
+ # An assistant's metadata merges into its runs' too, so no caller, Studio
558
+ # included, may give an assistant a thread record.
559
+ _strip_metadata_record(value)
560
+ _strip_metadata_record(_field(value, "config"))
561
+ if _is_unscoped_principal(ctx.user) or ctx.action in {"read", "search"}:
562
+ return None
563
+ owner = _field(ctx.user, "mda_user_id")
564
+ if (
565
+ not is_person_principal(owner)
566
+ or _field(ctx.user, "mda_user_kind") == "service"
567
+ or _field(ctx.user, "mda_source_provider") is not None
568
+ ):
569
+ raise _http_exception(
570
+ ManagedAuthError(403, f"assistants:{ctx.action} is not permitted for this caller")
571
+ )
572
+ owner = str(owner)
573
+ _check_assistant_payload(value)
574
+ if ctx.action == "create":
575
+ # Mutate in place: the server keeps the metadata object it passed in.
576
+ metadata = _field(value, "metadata")
577
+ if not isinstance(metadata, dict):
578
+ metadata = cast("dict[str, Any]", value)["metadata"] = {}
579
+ metadata[ASSISTANT_OWNER_METADATA] = owner
580
+ return {ASSISTANT_OWNER_METADATA: owner}
581
+
582
+
583
+ def _check_assistant_payload(value: object) -> None:
584
+ """Assistant context, config and metadata merge into runs: no managed keys or principal."""
585
+ holders = (
586
+ _field(value, "metadata"),
587
+ _field(value, "context"),
588
+ _field(_field(value, "config"), "configurable"),
589
+ )
590
+ keys = [str(key) for holder in holders if isinstance(holder, Mapping) for key in holder]
591
+ if any(key.startswith(("mda_", "langgraph_", "__")) for key in keys):
592
+ raise _http_exception(ManagedAuthError(403, "Invalid assistant config"))
593
+
594
+
543
595
  async def _scope_crons(ctx: AuthContext, value: CronsValue) -> FilterType | None:
544
596
  try:
545
597
  return await authorize_schedule(ctx.user, ctx.action, value)
@@ -9,13 +9,14 @@ from collections.abc import Mapping
9
9
  from datetime import UTC, datetime
10
10
  from http import HTTPStatus
11
11
  from typing import TYPE_CHECKING, Literal, NotRequired, cast
12
- from uuid import NAMESPACE_URL, UUID, uuid5
12
+ from uuid import NAMESPACE_URL, UUID, uuid4, uuid5
13
13
 
14
14
  import httpx
15
15
  from langgraph_sdk import Auth
16
16
  from pydantic import ConfigDict, TypeAdapter, ValidationError, with_config
17
17
  from typing_extensions import TypedDict
18
18
 
19
+ from managed_deepagents._channels.http.studio import _GRAPH_NAMESPACE
19
20
  from managed_deepagents._channels.schedule_delivery import read_schedule_deliver_to
20
21
  from managed_deepagents._channels.source_providers import is_trusted_source_provider
21
22
  from managed_deepagents._identity_runtime import _auth_user_fields, _field, is_studio_auth_user
@@ -28,6 +29,7 @@ from managed_deepagents._thread_record import (
28
29
  THREAD_CONVERSATION_METADATA,
29
30
  THREAD_PARTICIPANTS_METADATA,
30
31
  THREAD_RECORD_METADATA,
32
+ is_person_principal,
31
33
  parse_thread_record,
32
34
  strip_thread_record_keys,
33
35
  )
@@ -316,7 +318,9 @@ def schedule_handoff_user(
316
318
  if raw is None:
317
319
  return None
318
320
  access = _ACCESS.validate_python(json.loads(_verified_handoff(headers, raw)), strict=True)
319
- UUID(access["assistant"])
321
+ # A person's API cron update names no assistant, so its limit search spans all of them.
322
+ if access["assistant"] or (method, path) != ("POST", "/runs/crons/search"):
323
+ UUID(access["assistant"])
320
324
  if "thread" in access:
321
325
  UUID(access["thread"])
322
326
  reads = method == "GET" and path == f"/threads/{access['thread']}"
@@ -339,7 +343,6 @@ def schedule_handoff_user(
339
343
  not in (access["owner"].removeprefix("user:"), access.get("run_as", {}).get("id"))
340
344
  or not access["owner"].startswith("user:")
341
345
  or execution.get("mda_user_kind") == "service"
342
- or not execution.get("mda_agent_auth_principal_id")
343
346
  ):
344
347
  raise ValueError("Schedule access is not permitted")
345
348
  user: ScheduleHandoffUser = {**execution}
@@ -372,24 +375,26 @@ async def authorize_schedule( # noqa: C901 - one branch per cron event check
372
375
  # ``CronsCreate`` / ``CronsUpdate`` TypedDicts do not declare it.
373
376
  data = cast("dict[str, object]", value)
374
377
  _guard_cron_record(action, data, access)
375
- metadata = data.get("metadata")
376
- payload = data.get("payload")
377
378
  if access is None:
378
379
  from managed_deepagents._identity_auth import is_local_dev_unscoped_user # noqa: PLC0415
379
380
 
380
381
  operator = is_studio_auth_user(user) or _is_local_dev_operator(user)
381
- if not (operator or is_local_dev_unscoped_user(user)):
382
- raise ValueError("Schedule access is not permitted")
383
- if action == "delete" and not operator:
384
- return {"mda_managed_by": "api"}
385
- return await _authorize_studio_schedule(action, data, deploy=operator)
386
- filters = {"mda_schedule_owner": access["owner"], "mda_schedule_assistant": access["assistant"]}
382
+ if operator or is_local_dev_unscoped_user(user):
383
+ if action == "delete" and not operator:
384
+ return {"mda_managed_by": "api"}
385
+ return await _authorize_studio_schedule(action, data, deploy=operator)
386
+ access = _person_access(user, action, data)
387
+ metadata = data.get("metadata")
388
+ payload = data.get("payload")
389
+ filters = {"mda_schedule_owner": access["owner"]}
390
+ if access["assistant"]:
391
+ filters["mda_schedule_assistant"] = access["assistant"]
387
392
  if action in {"update", "delete"}:
388
393
  filters["mda_managed_by"] = "runtime"
389
394
  if action == "create":
390
395
  if (
391
396
  not isinstance(payload, dict)
392
- or payload.get("assistant_id") != access["assistant"]
397
+ or _assistant_id(payload.get("assistant_id"), _GRAPH_NAMESPACE) != access["assistant"]
393
398
  or not isinstance(metadata, dict)
394
399
  or metadata.get("mda_managed_by") != "runtime"
395
400
  ):
@@ -415,6 +420,89 @@ async def authorize_schedule( # noqa: C901 - one branch per cron event check
415
420
  return filters
416
421
 
417
422
 
423
+ def _person_access(user: BaseUser, action: str, data: dict[str, object]) -> ScheduleAccess:
424
+ """A person's own API crons, which run as them like their runtime user schedules."""
425
+ user_id = _field(user, "mda_user_id")
426
+ if (
427
+ not is_person_principal(user_id)
428
+ or _field(user, "mda_user_kind") == "service"
429
+ or _field(user, "mda_source_provider") is not None
430
+ ):
431
+ raise ValueError("Schedule access is not permitted")
432
+ # Agent Auth resolves the principal from these identity fields when the cron fires.
433
+ execution = validate_execution(
434
+ {
435
+ **{key: _field(user, key) for key in _PERSON_IDENTITY_KEYS if _field(user, key)},
436
+ "identity": user_id,
437
+ "permissions": [],
438
+ "mda_user_id": user_id,
439
+ "mda_source_provider": "schedule",
440
+ "mda_scheduled_run": True,
441
+ }
442
+ )
443
+ payload = data.get("payload")
444
+ if action == "create":
445
+ _prepare_person_cron(data)
446
+ # Context and config carry a runtime schedule's routing and principal; recreate to change them.
447
+ elif isinstance(payload, dict) and {"assistant_id", "context", "config"} & payload.keys():
448
+ raise ValueError("Schedule access is not permitted")
449
+ return {
450
+ "owner": f"user:{user_id}",
451
+ "assistant": _assistant_id(_field(payload, "assistant_id"), _GRAPH_NAMESPACE) or "",
452
+ "execution": execution,
453
+ }
454
+
455
+
456
+ _PERSON_IDENTITY_KEYS = (
457
+ "mda_agent_auth_principal_id",
458
+ "mda_identity_provider",
459
+ "mda_identity_issuer",
460
+ "mda_identity_subject",
461
+ )
462
+
463
+
464
+ def _prepare_person_cron(data: dict[str, object]) -> None:
465
+ """Tag a person's new API cron as their runtime user schedule."""
466
+ if data.get("thread_id"):
467
+ raise Auth.exceptions.HTTPException(
468
+ status_code=403,
469
+ detail="Schedule access is not permitted: API crons must create a new thread per run",
470
+ )
471
+ metadata = data.get("metadata")
472
+ if metadata is None:
473
+ metadata = data["metadata"] = {}
474
+ payload = data.get("payload")
475
+ if (
476
+ not isinstance(metadata, dict)
477
+ or any(key.startswith("mda_") for key in metadata)
478
+ or not isinstance(payload, dict)
479
+ ):
480
+ raise ValueError("Schedule access is not permitted")
481
+ metadata["mda_managed_by"] = "runtime"
482
+ _wrap_person_context(payload)
483
+
484
+
485
+ def _wrap_person_context(payload: dict[str, object]) -> None:
486
+ """Add the schedule name runtime crons carry to the caller's authored context."""
487
+ _check_api_context(payload)
488
+ context = payload.get("context") or {}
489
+ payload["context"] = {
490
+ "mda_schedule": {"name": str(uuid4())},
491
+ **cast("dict[str, object]", context),
492
+ }
493
+
494
+
495
+ def _assistant_id(value: object, namespace: UUID = NAMESPACE_URL) -> str | None:
496
+ """An assistant UUID, or a UUID derived from a graph name."""
497
+ if not isinstance(value, str):
498
+ return None
499
+ try:
500
+ UUID(value)
501
+ except ValueError:
502
+ return str(uuid5(namespace, value))
503
+ return value
504
+
505
+
418
506
  def _guard_cron_record(action: str, data: dict[str, object], access: ScheduleAccess | None) -> None:
419
507
  """Keep a thread record only on a runtime new-thread schedule, for its execution.
420
508
 
@@ -510,11 +598,7 @@ async def _authorize_studio_schedule(
510
598
  or metadata.get("mda_managed_by") != "deploy"
511
599
  ):
512
600
  raise ValueError("Schedule access is not permitted")
513
- assistant = payload["assistant_id"]
514
- try:
515
- UUID(assistant)
516
- except ValueError:
517
- assistant = str(uuid5(NAMESPACE_URL, assistant))
601
+ assistant = str(_assistant_id(payload["assistant_id"]))
518
602
  if api:
519
603
  # Not `mda_managed`: deploy reconciliation and runtime schedule tools leave it alone.
520
604
  metadata["mda_managed_by"] = "api"
@@ -660,7 +744,7 @@ async def _check_schedule_limit(access: ScheduleAccess, cron_id: str | None = No
660
744
  f"{base}/runs/crons/search",
661
745
  headers=headers,
662
746
  json={
663
- "assistant_id": access["assistant"],
747
+ **({"assistant_id": access["assistant"]} if access["assistant"] else {}),
664
748
  "metadata": {"mda_managed_by": "runtime"},
665
749
  "select": ["cron_id", "end_time"],
666
750
  "limit": _SEARCH_PAGE,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: managed-deepagents
3
- Version: 0.10.3.dev7
3
+ Version: 0.10.3.dev8
4
4
  Summary: Managed Deep Agents — the define_deep_agent authoring interface plus the CLI that compiles and deploys a code-first Deep Agent repository to a managed LangGraph runtime.
5
5
  Author: LangChain
6
6
  License: MIT
@@ -16,7 +16,7 @@ managed_deepagents/_eval_filesystem.py,sha256=_oRR0CUzpO7XND2JkkNUZH63m5kwxmGcR7
16
16
  managed_deepagents/_extension.py,sha256=MqCWS4AGxiURPtLlA2y_tWKdRL8Zu1-VZyQ6Q3HDgzc,5315
17
17
  managed_deepagents/_graph_build_timing.py,sha256=ritnkUzuKQ4-S00bzFB9-S6DtZkl9xslQVh0enVcQag,4996
18
18
  managed_deepagents/_http_status.py,sha256=NPTvc7Ct6T84gWXniO1gOIkTDpf4_5g7drQDeca1ydA,1644
19
- managed_deepagents/_identity_auth.py,sha256=LArpJvONfK58LviMjQ-b4b4TNST4EU7nRqzPe3Cg8n0,47443
19
+ managed_deepagents/_identity_auth.py,sha256=CHeUA_CQQgx21aK_KtqzV6OmGks1ndyIht0AD7445WM,49667
20
20
  managed_deepagents/_identity_http.py,sha256=EA9ssCqCCAI0IWJgk7kUwl2gmDFfBUOO5X2oI1ipL-Y,18963
21
21
  managed_deepagents/_identity_links.py,sha256=-k49Br6muYfrRpnHY0rFpTOg7pdm5c6xh9fJRCz8-Qw,8099
22
22
  managed_deepagents/_identity_runtime.py,sha256=6Q3YU2N_9WDIlkHqIxhDGclCD2eyxfIACNBPtVl5Hg4,26279
@@ -35,7 +35,7 @@ managed_deepagents/_run_input.py,sha256=VdIysM5tIFx8Fjmbr3dkNIHYovcHmSC-wtwRuqYo
35
35
  managed_deepagents/_run_local.py,sha256=pKGh_JKUW8RaTFy9EpBor893KCjBV2cCJZzsiBCeaWA,2852
36
36
  managed_deepagents/_runtime_schedules.py,sha256=EDYtFxpbj4jZjV5-1mgWZn598g86NsgvsC_pEa2rGKk,30377
37
37
  managed_deepagents/_sandbox_proxy.py,sha256=AFrcC07nTHaAQhGCDttncv3SkGL5h1JBcfxv7Psgn6c,9835
38
- managed_deepagents/_schedule_auth.py,sha256=m8QB-d8AL4eIsdeK_brJ5Mm4qZHP8NxaZwluYXvQZQg,26918
38
+ managed_deepagents/_schedule_auth.py,sha256=2VFjBf7QRHIFtTP0CYvEiAC5eNZyo0eO5fgUWXasmhM,30160
39
39
  managed_deepagents/_schedule_channel.py,sha256=r0EWl4OrBJRnwKETHjKdScYIfdi0lrUEGdajX6FGIdQ,1109
40
40
  managed_deepagents/_schedule_time.py,sha256=uNyULRjoD0HzPVvV-W772HPb3BYCt0fwEbbT9Ec__Jc,3710
41
41
  managed_deepagents/_static_entry.py,sha256=QgvrnBLue6elOHSWdIFosFEfYMp4V9YDwBlZSe_NyQA,635
@@ -53,7 +53,7 @@ managed_deepagents/run_context.py,sha256=IayZdcpPrKVss70Hro8qI-EWtL94HZt4JKefzec
53
53
  managed_deepagents/runtime.py,sha256=M5-XlwkTfWV6Gyl4w9vClFFF0GvOWZEc6-_wPyxn5W0,136847
54
54
  managed_deepagents/sandbox.py,sha256=cS66-vFcARsbHR3fH5jvWd4qF-MAjiGqRe-_Kocsqtg,4693
55
55
  managed_deepagents/schedules.py,sha256=z_OlmZ7hW7LdvWLem-BiA131nHwFvUDSW_0-ObzU_G4,6039
56
- managed_deepagents/_binaries/mda.exe,sha256=iQZx-XUnXGHdAGpbrGcyn2jCgKEC7nSKjNtv1iabQUU,5157888
56
+ managed_deepagents/_binaries/mda.exe,sha256=ZXjMx82mcY0XWpitY8LMqF8z1lHzRjNTgTJuVE2zgJ4,5157888
57
57
  managed_deepagents/_channels/__init__.py,sha256=mMgqza7EWRjhJM0lXlFd-W6wBYZrFkpLQ4_30Bpij7k,249
58
58
  managed_deepagents/_channels/actor.py,sha256=3d_1-ia6vwVjXkw7PYn5gg6BjnlPwRXW4nW2C5vAO7c,5203
59
59
  managed_deepagents/_channels/assistant_text.py,sha256=nf00-KJXNev-e_TkAK_8SBI3J9TiOis1GkGV_zT5048,8472
@@ -156,9 +156,9 @@ managed_deepagents/identity/__init__.py,sha256=uZUKDHtfBc0n-T2xoJEFMqMplmXwAK7hb
156
156
  managed_deepagents/identity/claims.py,sha256=prby7r_8Lww3MmoBm8PX6PsSGE3GwSHkr8mVIz_08nU,1180
157
157
  managed_deepagents/identity/options.py,sha256=x_yMbXEFR7zXyehEjDHG2qjAlukXjrRBcQLcM6IndLM,2550
158
158
  managed_deepagents/identity/supabase.py,sha256=8uobl3WCrQL_ieSXG8KTLf1th7Qjim9liZT50HeaJE0,6026
159
- managed_deepagents-0.10.3.dev7.dist-info/licenses/LICENSE,sha256=WnPZQQ608ojZUkXl7BW6VbKloIAibZiGm1K6cjeZOL8,1066
160
- managed_deepagents-0.10.3.dev7.dist-info/METADATA,sha256=DaesUoVTSNkE_pijLrvuX5z_XofDpNGXy2zclioNCfc,95067
161
- managed_deepagents-0.10.3.dev7.dist-info/WHEEL,sha256=bhMFZwp6VMtrbl2Ck6PlXryKaCggO1NzYn_HcFbBF1I,97
162
- managed_deepagents-0.10.3.dev7.dist-info/entry_points.txt,sha256=ziZqkKuaDO3qHCjKmBhrx9cm3ok8bZ9xcEDpUTj4unM,53
163
- managed_deepagents-0.10.3.dev7.dist-info/top_level.txt,sha256=fdBo4O0Hlol_w022tTLB5ftZpamb4yJoQ3MUvjgTGfA,19
164
- managed_deepagents-0.10.3.dev7.dist-info/RECORD,,
159
+ managed_deepagents-0.10.3.dev8.dist-info/licenses/LICENSE,sha256=WnPZQQ608ojZUkXl7BW6VbKloIAibZiGm1K6cjeZOL8,1066
160
+ managed_deepagents-0.10.3.dev8.dist-info/METADATA,sha256=z51m1rT_7M6Wg-Fw0RodnsOFCjnnK46H-JXmIzaINVk,95067
161
+ managed_deepagents-0.10.3.dev8.dist-info/WHEEL,sha256=bhMFZwp6VMtrbl2Ck6PlXryKaCggO1NzYn_HcFbBF1I,97
162
+ managed_deepagents-0.10.3.dev8.dist-info/entry_points.txt,sha256=ziZqkKuaDO3qHCjKmBhrx9cm3ok8bZ9xcEDpUTj4unM,53
163
+ managed_deepagents-0.10.3.dev8.dist-info/top_level.txt,sha256=fdBo4O0Hlol_w022tTLB5ftZpamb4yJoQ3MUvjgTGfA,19
164
+ managed_deepagents-0.10.3.dev8.dist-info/RECORD,,