|
15 | 15 | from core.middleware import INTERNAL_TOOL_HEADER, require_admin |
16 | 16 | from routes.auth_routes import SESSION_COOKIE |
17 | 17 | from src.diogenes_host_services import HostServiceError, HostServicesManager |
| 18 | +from src.diogenes_librarian_workspace import ( |
| 19 | + LibrarianWorkspaceClient, |
| 20 | + LibrarianWorkspaceError, |
| 21 | +) |
| 22 | +from src.diogenes_persephone_workspace import ( |
| 23 | + PersephoneWorkspaceControl, |
| 24 | + PersephoneWorkspaceError, |
| 25 | +) |
| 26 | +from src.diogenes_roboomp_workspace import ( |
| 27 | + RoboOMPWorkspaceControl, |
| 28 | + RoboOMPWorkspaceError, |
| 29 | +) |
18 | 30 | from src.diogenes_docker_projects import ( |
19 | 31 | DockerProjectControl, |
20 | 32 | DockerResourceControl, |
|
24 | 36 | read_docker_log, |
25 | 37 | save_docker_document, |
26 | 38 | ) |
27 | | -from src.diogenes_skill_auditor import SkillAuditorControl, collect_skills |
| 39 | +from src.diogenes_skill_auditor import ( |
| 40 | + SkillAuditorControl, |
| 41 | + collect_retrieval_catalog, |
| 42 | + collect_retrieval_runtime, |
| 43 | + collect_skills, |
| 44 | + inspect_retrieval_skill, |
| 45 | + search_retrieval_skills, |
| 46 | +) |
28 | 47 | from src.diogenes_user_scripts import UserScriptControl |
29 | 48 | from src.sandwich_runtime import ( |
30 | 49 | collect_sandwich_status, |
@@ -145,8 +164,31 @@ class SandwichLifecyclePlanRequest(BaseModel): |
145 | 164 |
|
146 | 165 |
|
147 | 166 | class SkillAuditorPlanRequest(BaseModel): |
148 | | - skill_id: str |
| 167 | + skill_id: str = "" |
149 | 168 | action: str |
| 169 | + query: str = "" |
| 170 | + harness: str = "" |
| 171 | + |
| 172 | + |
| 173 | +class LibrarianChatRequest(BaseModel): |
| 174 | + messages: list[dict[str, object]] |
| 175 | + model: str = "" |
| 176 | + |
| 177 | + |
| 178 | +class PersephoneLifecyclePlanRequest(BaseModel): |
| 179 | + action: str |
| 180 | + |
| 181 | + |
| 182 | +class PersephoneMutationPlanRequest(BaseModel): |
| 183 | + mutation: dict[str, object] |
| 184 | + |
| 185 | + |
| 186 | +class RoboOMPLifecyclePlanRequest(BaseModel): |
| 187 | + action: str |
| 188 | + |
| 189 | + |
| 190 | +class RoboOMPMutationPlanRequest(BaseModel): |
| 191 | + mutation: dict[str, object] |
150 | 192 |
|
151 | 193 |
|
152 | 194 | class RuntimeDocumentSaveRequest(BaseModel): |
@@ -186,6 +228,10 @@ def _job_http_error(exc: RuntimeJobError) -> HTTPException: |
186 | 228 | return HTTPException(400, str(exc)) |
187 | 229 |
|
188 | 230 |
|
| 231 | +def _librarian_http_error(exc: LibrarianWorkspaceError) -> HTTPException: |
| 232 | + return HTTPException(exc.status_code, str(exc)) |
| 233 | + |
| 234 | + |
189 | 235 | def _require_operator_admin(request: Request) -> None: |
190 | 236 | """Require a human admin; internal agent and bearer-token bypasses stay out.""" |
191 | 237 | user = getattr(request.state, "current_user", None) |
@@ -232,6 +278,15 @@ def setup_ulysses_routes( |
232 | 278 | skill_auditor_control_factory: Callable[ |
233 | 279 | [], SkillAuditorControl |
234 | 280 | ] = SkillAuditorControl, |
| 281 | + librarian_client_factory: Callable[ |
| 282 | + [], LibrarianWorkspaceClient |
| 283 | + ] = LibrarianWorkspaceClient, |
| 284 | + persephone_control_factory: Callable[ |
| 285 | + [], PersephoneWorkspaceControl |
| 286 | + ] = PersephoneWorkspaceControl, |
| 287 | + roboomp_control_factory: Callable[ |
| 288 | + [], RoboOMPWorkspaceControl |
| 289 | + ] = RoboOMPWorkspaceControl, |
235 | 290 | sandwich_collector: Callable[[], dict] = collect_sandwich_status, |
236 | 291 | managed_runtime_collector: Callable[[], dict] = collect_managed_runtimes, |
237 | 292 | docker_project_collector: Callable[[], dict] = collect_docker_projects, |
@@ -397,6 +452,287 @@ async def get_skill_audit(request: Request) -> dict: |
397 | 452 | except RuntimeJobError as exc: |
398 | 453 | raise HTTPException(400, str(exc)) from exc |
399 | 454 |
|
| 455 | + @router.get("/skills/catalog") |
| 456 | + async def get_retrieval_catalog( |
| 457 | + request: Request, |
| 458 | + refresh: bool = False, |
| 459 | + ) -> dict: |
| 460 | + require_admin(request) |
| 461 | + try: |
| 462 | + return await run_in_threadpool( |
| 463 | + collect_retrieval_catalog, |
| 464 | + refresh=refresh, |
| 465 | + ) |
| 466 | + except RuntimeJobError as exc: |
| 467 | + raise HTTPException(400, str(exc)) from exc |
| 468 | + |
| 469 | + @router.get("/skills/inspect") |
| 470 | + async def get_retrieval_skill( |
| 471 | + request: Request, |
| 472 | + skill_id: str, |
| 473 | + ) -> dict: |
| 474 | + require_admin(request) |
| 475 | + try: |
| 476 | + return await run_in_threadpool(inspect_retrieval_skill, skill_id) |
| 477 | + except RuntimeJobError as exc: |
| 478 | + raise HTTPException(400, str(exc)) from exc |
| 479 | + |
| 480 | + @router.get("/skills/search") |
| 481 | + async def search_retrieval_catalog( |
| 482 | + request: Request, |
| 483 | + query: str, |
| 484 | + limit: int = 24, |
| 485 | + ) -> dict: |
| 486 | + require_admin(request) |
| 487 | + try: |
| 488 | + return await run_in_threadpool( |
| 489 | + search_retrieval_skills, |
| 490 | + query, |
| 491 | + limit=limit, |
| 492 | + ) |
| 493 | + except RuntimeJobError as exc: |
| 494 | + raise HTTPException(400, str(exc)) from exc |
| 495 | + |
| 496 | + @router.get("/skills/runtime") |
| 497 | + async def get_retrieval_runtime(request: Request) -> dict: |
| 498 | + require_admin(request) |
| 499 | + try: |
| 500 | + return await run_in_threadpool(collect_retrieval_runtime) |
| 501 | + except RuntimeJobError as exc: |
| 502 | + raise HTTPException(400, str(exc)) from exc |
| 503 | + |
| 504 | + @router.get("/library/overview") |
| 505 | + async def get_librarian_overview(request: Request) -> dict: |
| 506 | + require_admin(request) |
| 507 | + try: |
| 508 | + return await librarian_client_factory().overview() |
| 509 | + except LibrarianWorkspaceError as exc: |
| 510 | + raise _librarian_http_error(exc) from exc |
| 511 | + |
| 512 | + @router.get("/library/concept") |
| 513 | + async def get_librarian_concept(request: Request, path: str) -> dict: |
| 514 | + require_admin(request) |
| 515 | + try: |
| 516 | + return await librarian_client_factory().concept(path) |
| 517 | + except LibrarianWorkspaceError as exc: |
| 518 | + raise _librarian_http_error(exc) from exc |
| 519 | + |
| 520 | + @router.get("/library/search") |
| 521 | + async def search_librarian( |
| 522 | + request: Request, |
| 523 | + query: str, |
| 524 | + concept_type: str = "", |
| 525 | + tag: str = "", |
| 526 | + ) -> list: |
| 527 | + require_admin(request) |
| 528 | + try: |
| 529 | + return await librarian_client_factory().search( |
| 530 | + query, |
| 531 | + concept_type=concept_type, |
| 532 | + tag=tag, |
| 533 | + ) |
| 534 | + except LibrarianWorkspaceError as exc: |
| 535 | + raise _librarian_http_error(exc) from exc |
| 536 | + |
| 537 | + @router.get("/library/graph") |
| 538 | + async def get_librarian_graph(request: Request) -> dict: |
| 539 | + require_admin(request) |
| 540 | + try: |
| 541 | + return await librarian_client_factory().graph() |
| 542 | + except LibrarianWorkspaceError as exc: |
| 543 | + raise _librarian_http_error(exc) from exc |
| 544 | + |
| 545 | + @router.get("/library/traces") |
| 546 | + async def get_librarian_traces(request: Request) -> list: |
| 547 | + require_admin(request) |
| 548 | + try: |
| 549 | + return await librarian_client_factory().traces() |
| 550 | + except LibrarianWorkspaceError as exc: |
| 551 | + raise _librarian_http_error(exc) from exc |
| 552 | + |
| 553 | + @router.get("/library/trace") |
| 554 | + async def get_librarian_trace(request: Request, trace_id: str) -> dict: |
| 555 | + require_admin(request) |
| 556 | + try: |
| 557 | + return await librarian_client_factory().trace(trace_id) |
| 558 | + except LibrarianWorkspaceError as exc: |
| 559 | + raise _librarian_http_error(exc) from exc |
| 560 | + |
| 561 | + @router.get("/library/dreams") |
| 562 | + async def get_librarian_dreams(request: Request) -> dict: |
| 563 | + require_admin(request) |
| 564 | + try: |
| 565 | + return await librarian_client_factory().dreams() |
| 566 | + except LibrarianWorkspaceError as exc: |
| 567 | + raise _librarian_http_error(exc) from exc |
| 568 | + |
| 569 | + @router.get("/library/dreams/{proposal_id}") |
| 570 | + async def get_librarian_dream(request: Request, proposal_id: str) -> dict: |
| 571 | + require_admin(request) |
| 572 | + try: |
| 573 | + return await librarian_client_factory().dream(proposal_id) |
| 574 | + except LibrarianWorkspaceError as exc: |
| 575 | + raise _librarian_http_error(exc) from exc |
| 576 | + |
| 577 | + @router.post("/library/chat") |
| 578 | + async def chat_with_librarian( |
| 579 | + request: Request, |
| 580 | + body: LibrarianChatRequest, |
| 581 | + ) -> dict: |
| 582 | + _require_operator_admin(request) |
| 583 | + try: |
| 584 | + return await librarian_client_factory().chat( |
| 585 | + body.messages, |
| 586 | + model=body.model, |
| 587 | + ) |
| 588 | + except LibrarianWorkspaceError as exc: |
| 589 | + raise _librarian_http_error(exc) from exc |
| 590 | + |
| 591 | + @router.post("/library/dreams/propose") |
| 592 | + async def propose_librarian_dream(request: Request) -> dict: |
| 593 | + _require_operator_admin(request) |
| 594 | + try: |
| 595 | + return await librarian_client_factory().propose_dream() |
| 596 | + except LibrarianWorkspaceError as exc: |
| 597 | + raise _librarian_http_error(exc) from exc |
| 598 | + |
| 599 | + @router.post("/library/dreams/{proposal_id}/{action}") |
| 600 | + async def act_on_librarian_dream( |
| 601 | + request: Request, |
| 602 | + proposal_id: str, |
| 603 | + action: str, |
| 604 | + ) -> dict: |
| 605 | + _require_operator_admin(request) |
| 606 | + try: |
| 607 | + return await librarian_client_factory().dream_action( |
| 608 | + proposal_id, |
| 609 | + action, |
| 610 | + ) |
| 611 | + except LibrarianWorkspaceError as exc: |
| 612 | + raise _librarian_http_error(exc) from exc |
| 613 | + |
| 614 | + @router.get("/persephone/workspace") |
| 615 | + async def get_persephone_workspace( |
| 616 | + request: Request, |
| 617 | + limit: int = 50, |
| 618 | + ) -> dict: |
| 619 | + require_admin(request) |
| 620 | + try: |
| 621 | + return await run_in_threadpool( |
| 622 | + persephone_control_factory().observe, |
| 623 | + limit=limit, |
| 624 | + ) |
| 625 | + except PersephoneWorkspaceError as exc: |
| 626 | + raise HTTPException(503, str(exc)) from exc |
| 627 | + |
| 628 | + @router.get("/persephone/queue/{kind}/{record_id}") |
| 629 | + async def get_persephone_queue_record( |
| 630 | + request: Request, |
| 631 | + kind: str, |
| 632 | + record_id: int, |
| 633 | + ) -> dict: |
| 634 | + require_admin(request) |
| 635 | + try: |
| 636 | + return await run_in_threadpool( |
| 637 | + persephone_control_factory().queue_record, |
| 638 | + kind=kind, |
| 639 | + record_id=record_id, |
| 640 | + ) |
| 641 | + except PersephoneWorkspaceError as exc: |
| 642 | + raise HTTPException(400, str(exc)) from exc |
| 643 | + |
| 644 | + @router.post("/persephone/lifecycle/jobs/plan") |
| 645 | + async def plan_persephone_lifecycle( |
| 646 | + request: Request, |
| 647 | + body: PersephoneLifecyclePlanRequest, |
| 648 | + ) -> dict: |
| 649 | + _require_operator_admin(request) |
| 650 | + try: |
| 651 | + plan, token = await run_in_threadpool( |
| 652 | + persephone_control_factory().create_lifecycle_plan, |
| 653 | + action=body.action, |
| 654 | + ) |
| 655 | + return {"job": plan, "confirmation_token": token} |
| 656 | + except RuntimeJobError as exc: |
| 657 | + raise _job_http_error(exc) from exc |
| 658 | + |
| 659 | + @router.post("/persephone/mutations/jobs/plan") |
| 660 | + async def plan_persephone_mutation( |
| 661 | + request: Request, |
| 662 | + body: PersephoneMutationPlanRequest, |
| 663 | + ) -> dict: |
| 664 | + _require_operator_admin(request) |
| 665 | + try: |
| 666 | + plan, token = await run_in_threadpool( |
| 667 | + persephone_control_factory().create_mutation_plan, |
| 668 | + body.mutation, |
| 669 | + ) |
| 670 | + return {"job": plan, "confirmation_token": token} |
| 671 | + except RuntimeJobError as exc: |
| 672 | + raise _job_http_error(exc) from exc |
| 673 | + |
| 674 | + @router.get("/roboomp/workspace") |
| 675 | + async def get_roboomp_workspace( |
| 676 | + request: Request, |
| 677 | + limit: int = 50, |
| 678 | + state: str = "open", |
| 679 | + ) -> dict: |
| 680 | + require_admin(request) |
| 681 | + try: |
| 682 | + return await run_in_threadpool( |
| 683 | + roboomp_control_factory().observe, |
| 684 | + limit=limit, |
| 685 | + state=state, |
| 686 | + ) |
| 687 | + except RoboOMPWorkspaceError as exc: |
| 688 | + raise HTTPException(503, str(exc)) from exc |
| 689 | + |
| 690 | + @router.get("/roboomp/issues/inspect") |
| 691 | + async def inspect_roboomp_issue( |
| 692 | + request: Request, |
| 693 | + issue: str, |
| 694 | + limit: int = 50, |
| 695 | + ) -> dict: |
| 696 | + require_admin(request) |
| 697 | + try: |
| 698 | + return await run_in_threadpool( |
| 699 | + roboomp_control_factory().inspect, |
| 700 | + issue=issue, |
| 701 | + limit=limit, |
| 702 | + ) |
| 703 | + except RoboOMPWorkspaceError as exc: |
| 704 | + raise HTTPException(400, str(exc)) from exc |
| 705 | + |
| 706 | + @router.post("/roboomp/lifecycle/jobs/plan") |
| 707 | + async def plan_roboomp_lifecycle( |
| 708 | + request: Request, |
| 709 | + body: RoboOMPLifecyclePlanRequest, |
| 710 | + ) -> dict: |
| 711 | + _require_operator_admin(request) |
| 712 | + try: |
| 713 | + plan, token = await run_in_threadpool( |
| 714 | + roboomp_control_factory().create_lifecycle_plan, |
| 715 | + action=body.action, |
| 716 | + ) |
| 717 | + return {"job": plan, "confirmation_token": token} |
| 718 | + except RuntimeJobError as exc: |
| 719 | + raise _job_http_error(exc) from exc |
| 720 | + |
| 721 | + @router.post("/roboomp/mutations/jobs/plan") |
| 722 | + async def plan_roboomp_mutation( |
| 723 | + request: Request, |
| 724 | + body: RoboOMPMutationPlanRequest, |
| 725 | + ) -> dict: |
| 726 | + _require_operator_admin(request) |
| 727 | + try: |
| 728 | + plan, token = await run_in_threadpool( |
| 729 | + roboomp_control_factory().create_mutation_plan, |
| 730 | + body.mutation, |
| 731 | + ) |
| 732 | + return {"job": plan, "confirmation_token": token} |
| 733 | + except RuntimeJobError as exc: |
| 734 | + raise _job_http_error(exc) from exc |
| 735 | + |
400 | 736 | @router.get("/docker/projects/{project_id}/documents") |
401 | 737 | async def get_docker_project_documents( |
402 | 738 | request: Request, |
@@ -586,6 +922,8 @@ async def plan_skill_auditor_action( |
586 | 922 | skill_auditor_control_factory().create_plan, |
587 | 923 | skill_id=body.skill_id, |
588 | 924 | action=body.action, |
| 925 | + query=body.query, |
| 926 | + harness=body.harness, |
589 | 927 | ) |
590 | 928 | return {"job": plan, "confirmation_token": token} |
591 | 929 | except RuntimeJobError as exc: |
|
0 commit comments