rusticai-api 0.1.0__tar.gz → 1.1.0__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.
Files changed (31) hide show
  1. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/PKG-INFO +8 -8
  2. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/pyproject.toml +16 -14
  3. rusticai_api-1.1.0/src/rustic_ai/api_server/addons/__init__.py +4 -0
  4. rusticai_api-1.1.0/src/rustic_ai/api_server/addons/boards/__init__.py +5 -0
  5. rusticai_api-1.1.0/src/rustic_ai/api_server/addons/boards/board_store.py +124 -0
  6. rusticai_api-1.1.0/src/rustic_ai/api_server/addons/boards/models.py +23 -0
  7. rusticai_api-1.1.0/src/rustic_ai/api_server/addons/boards/router.py +156 -0
  8. rusticai_api-1.1.0/src/rustic_ai/api_server/addons/boards/schema.py +34 -0
  9. rusticai_api-1.1.0/src/rustic_ai/api_server/addons/router.py +7 -0
  10. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/catalog/catalog_store.py +77 -32
  11. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/catalog/models.py +14 -2
  12. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/catalog/router.py +106 -17
  13. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/guilds/comms_manager.py +48 -18
  14. rusticai_api-1.1.0/src/rustic_ai/api_server/guilds/models.py +12 -0
  15. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/guilds/router.py +40 -7
  16. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/guilds/schema.py +4 -0
  17. rusticai_api-1.1.0/src/rustic_ai/api_server/guilds/service.py +96 -0
  18. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/guilds/system_comms_manager.py +36 -16
  19. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/logging/config.py +20 -2
  20. rusticai_api-1.1.0/src/rustic_ai/api_server/logging/format.py +97 -0
  21. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/main.py +2 -1
  22. rusticai_api-0.1.0/src/rustic_ai/api_server/guilds/service.py +0 -57
  23. rusticai_api-0.1.0/src/rustic_ai/api_server/logging/format.py +0 -24
  24. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/README.md +0 -0
  25. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/__init__.py +0 -0
  26. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/api_dependency_manager.py +0 -0
  27. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/catalog/__init__.py +0 -0
  28. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/guilds/__init__.py +0 -0
  29. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/guilds/socket.py +0 -0
  30. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/logging/__init__.py +0 -0
  31. {rusticai_api-0.1.0 → rusticai_api-1.1.0}/src/rustic_ai/api_server/main_debug.py +0 -0
@@ -1,23 +1,23 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: rusticai-api
3
- Version: 0.1.0
3
+ Version: 1.1.0
4
4
  Summary: API Server for Rustic AI
5
- License: Apache-2.0
5
+ License-Expression: Apache-2.0
6
6
  Author: Dragonscale Industries Inc.
7
7
  Author-email: dev@dragonscale.ai
8
- Requires-Python: >=3.12,<3.13
9
- Classifier: License :: OSI Approved :: Apache Software License
8
+ Requires-Python: >=3.13,<3.14
10
9
  Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
12
11
  Provides-Extra: test
13
12
  Requires-Dist: fastapi (>=0.115.8,<0.116.0)
14
13
  Requires-Dist: griffe (>=1.7.2,<2.0.0)
15
14
  Requires-Dist: opentelemetry-distro (>=0.52b1,<0.53)
16
15
  Requires-Dist: psycopg (>=3.2.6,<4.0.0)
17
16
  Requires-Dist: ptvsd (>=4.3.2,<5.0.0)
17
+ Requires-Dist: python-json-logger (>=3.3.0,<4.0.0)
18
18
  Requires-Dist: python-multipart (>=0.0.20,<0.0.21)
19
- Requires-Dist: rusticai-core (>=0.1.0,<0.2.0)
20
- Requires-Dist: rusticai-ray (>=0.1.0,<0.2.0)
19
+ Requires-Dist: rusticai-core (>=1.1.0,<1.2.0)
20
+ Requires-Dist: rusticai-ray (>=1.1.0,<1.2.0)
21
21
  Requires-Dist: starlette (>=0.45.3,<0.46.0)
22
22
  Requires-Dist: uvicorn (>=0.34.0,<0.35.0)
23
23
  Requires-Dist: websockets (>=15.0.1,<16.0.0)
@@ -2,24 +2,25 @@
2
2
  requires = ["poetry-core"]
3
3
  build-backend = "poetry.core.masonry.api"
4
4
 
5
- [tool.poetry]
5
+
6
+ [project]
6
7
  name = "rusticai-api"
7
- version = "0.1.0"
8
+ version = "1.1.0"
8
9
  description = "API Server for Rustic AI"
9
- authors = ["Dragonscale Industries Inc. <dev@dragonscale.ai>"]
10
+ authors = [{name = "Dragonscale Industries Inc.", email = "dev@dragonscale.ai"}]
10
11
  license = "Apache-2.0"
11
12
  readme = "README.md"
12
- homepage = "https://www.rustic.ai/"
13
- repository = "https://github.com/rustic-ai/rustic-ai"
14
- packages = [{ include = "rustic_ai", from = "src" }]
13
+ requires-python = ">=3.13,<3.14"
14
+ dynamic = ["dependencies"]
15
+ urls = { Homepage = "https://www.rustic.ai/", Repository = "https://github.com/rustic-ai/rustic-ai", "Rustic AI Core" = "https://pypi.org/project/rusticai-core/" }
15
16
 
16
- [tool.poetry.urls]
17
- "Rustic AI Core" = "https://pypi.org/project/rusticai-core/"
17
+
18
+ [tool.poetry]
19
+ packages = [{ include = "rustic_ai", from = "src" }]
18
20
 
19
21
  [tool.poetry.dependencies]
20
- python = ">=3.12,<3.13"
21
- rusticai-core = { version = "0.1.0"}
22
- rusticai-ray = { version = "0.1.0"}
22
+ rusticai-core = { version = "1.1.0"}
23
+ rusticai-ray = { version = "1.1.0"}
23
24
  fastapi = "^0.115.8"
24
25
  starlette = "^0.45.3"
25
26
  uvicorn = "^0.34.0"
@@ -29,6 +30,7 @@ opentelemetry-distro = "^0.52b1"
29
30
  websockets = "^15.0.1"
30
31
  griffe = "^1.7.2"
31
32
  psycopg = "^3.2.6"
33
+ python-json-logger = "^3.3.0"
32
34
 
33
35
  [tool.poetry-monorepo.deps]
34
36
 
@@ -45,14 +47,14 @@ isort = "^6.0.0"
45
47
  mypy = "^1.15.0"
46
48
  pytest-asyncio = "^0.25.3"
47
49
  httpx = "^0.28.1"
48
- rusticai-testing = { version = "0.1.0"}
50
+ rusticai-testing = { version = "1.1.0"}
49
51
 
50
52
  [tool.poetry.extras]
51
53
  test = ["pytest", "pytest-asyncio", "httpx", "rusticai-testing"]
52
54
 
53
55
  [tool.black]
54
56
  line-length = 120
55
- target-version = ['py312']
57
+ target-version = ['py313']
56
58
  include = '\.pyi?$'
57
59
  exclude = '''
58
60
  /(
@@ -68,7 +70,7 @@ exclude = '''
68
70
  '''
69
71
 
70
72
  [tool.mypy]
71
- python_version = "3.12"
73
+ python_version = "3.13"
72
74
  ignore_missing_imports = true
73
75
  check_untyped_defs = true
74
76
  plugins = "pydantic.mypy"
@@ -0,0 +1,4 @@
1
+ from .boards import BoardStore
2
+ from .router import addons_router
3
+
4
+ __all__ = ["BoardStore", "addons_router"]
@@ -0,0 +1,5 @@
1
+ from .board_store import BoardStore
2
+ from .models import Board, BoardMessage
3
+ from .router import boards_router
4
+
5
+ __all__ = ["Board", "BoardMessage", "boards_router", "BoardStore"]
@@ -0,0 +1,124 @@
1
+ from typing import List
2
+
3
+ from fastapi import HTTPException
4
+ from sqlalchemy import Engine
5
+ from sqlmodel import Session, select
6
+
7
+ from rustic_ai.api_server.addons.boards.models import Board, BoardMessage
8
+ from rustic_ai.api_server.addons.boards.schema import CreateBoardRequest
9
+ from rustic_ai.core.guild.metastore import GuildModel
10
+
11
+
12
+ class BoardStore:
13
+ def __init__(self, engine: Engine):
14
+ self.engine = engine
15
+
16
+ def create_board(self, guild_id: str, board: CreateBoardRequest) -> str:
17
+ """
18
+ Creates a new board for a guild.
19
+
20
+ Args:
21
+ guild_id (str): The ID of the guild to create the board for.
22
+ board (CreateBoardRequest): The board creation request.
23
+
24
+ Returns:
25
+ str: The ID of the created board.
26
+ """
27
+ with Session(self.engine) as session:
28
+ guild_model = GuildModel.get_by_id(session, guild_id)
29
+ if guild_model is None:
30
+ raise HTTPException(status_code=404, detail="Guild not found")
31
+
32
+ board_model = Board(
33
+ name=board.name,
34
+ guild_id=guild_id,
35
+ created_by=board.created_by,
36
+ is_default=board.is_default,
37
+ is_private=board.is_private,
38
+ )
39
+ session.add(board_model)
40
+ session.commit()
41
+ session.refresh(board_model)
42
+
43
+ return board_model.id
44
+
45
+ def get_boards(self, guild_id: str) -> List[Board]:
46
+ """
47
+ Retrieves all boards for a guild.
48
+
49
+ Args:
50
+ guild_id (str): The ID of the guild to get boards for.
51
+
52
+ Returns:
53
+ List[Board]: List of boards for the guild.
54
+ """
55
+ with Session(self.engine) as session:
56
+ guild_model = GuildModel.get_by_id(session, guild_id)
57
+ if guild_model is None:
58
+ raise HTTPException(status_code=404, detail="Guild not found")
59
+
60
+ statement = select(Board).where(Board.guild_id == guild_id)
61
+ boards = session.exec(statement).all()
62
+
63
+ return list(boards)
64
+
65
+ def add_message_to_board(self, board_id: str, message_id: str) -> None:
66
+ """
67
+ Adds a message to a board.
68
+
69
+ Args:
70
+ board_id (str): The ID of the board to add the message to.
71
+ message_id (str): The ID of the message to add.
72
+ """
73
+ with Session(self.engine) as session:
74
+ board = session.get(Board, board_id)
75
+ if board is None:
76
+ raise HTTPException(status_code=404, detail="Board not found")
77
+
78
+ existing_entry = session.get(BoardMessage, (board_id, message_id))
79
+ if existing_entry is not None:
80
+ raise HTTPException(status_code=409, detail="Message already added to board")
81
+
82
+ board_message = BoardMessage(board_id=board_id, message_id=message_id)
83
+ session.add(board_message)
84
+ session.commit()
85
+
86
+ def get_board_message_ids(self, board_id: str) -> List[str]:
87
+ """
88
+ Retrieves all message IDs for a board.
89
+
90
+ Args:
91
+ board_id (str): The ID of the board to get messages for.
92
+
93
+ Returns:
94
+ List[str]: List of message IDs in the board.
95
+ """
96
+ with Session(self.engine) as session:
97
+ board = session.get(Board, board_id)
98
+ if board is None:
99
+ raise HTTPException(status_code=404, detail="Board not found")
100
+
101
+ statement = select(BoardMessage.message_id).where(BoardMessage.board_id == board_id)
102
+ message_ids = session.exec(statement).all()
103
+
104
+ return list(message_ids)
105
+
106
+ def remove_message_from_board(self, board_id: str, message_id: str) -> None:
107
+ """
108
+ Removes a message from a board.
109
+
110
+ Args:
111
+ board_id (str): The ID of the board to remove the message from.
112
+ message_id (str): The ID of the message to remove.
113
+ """
114
+ with Session(self.engine) as session:
115
+ board = session.get(Board, board_id)
116
+ if board is None:
117
+ raise HTTPException(status_code=404, detail="Board not found")
118
+
119
+ board_message = session.get(BoardMessage, (board_id, message_id))
120
+ if board_message is None:
121
+ raise HTTPException(status_code=404, detail="Message not found on board")
122
+
123
+ session.delete(board_message)
124
+ session.commit()
@@ -0,0 +1,23 @@
1
+ from datetime import datetime, timezone
2
+
3
+ import shortuuid
4
+ from sqlmodel import Field, SQLModel
5
+
6
+
7
+ class Board(SQLModel, table=True):
8
+ __tablename__ = "board"
9
+
10
+ id: str = Field(primary_key=True, index=True, default_factory=shortuuid.uuid)
11
+ name: str = Field(index=True)
12
+ guild_id: str = Field(index=True, foreign_key="guilds.id")
13
+ created_by: str = Field(index=True)
14
+ created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
15
+ is_default: bool = Field(default=False)
16
+ is_private: bool = Field(default=False)
17
+
18
+
19
+ class BoardMessage(SQLModel, table=True):
20
+ __tablename__ = "board_message"
21
+
22
+ board_id: str = Field(primary_key=True, foreign_key="board.id")
23
+ message_id: str = Field(primary_key=True)
@@ -0,0 +1,156 @@
1
+ import logging
2
+
3
+ from fastapi import APIRouter, Depends, HTTPException
4
+ from sqlalchemy import Engine
5
+ from starlette import status
6
+
7
+ from rustic_ai.api_server.addons.boards.board_store import BoardStore
8
+ from rustic_ai.api_server.addons.boards.schema import (
9
+ AddMessageToBoardRequest,
10
+ BoardMessagesResponse,
11
+ BoardResponse,
12
+ BoardsResponse,
13
+ CreateBoardRequest,
14
+ )
15
+ from rustic_ai.api_server.guilds.schema import IdInfo
16
+ from rustic_ai.core.guild.metastore import Metastore
17
+
18
+ boards_router = APIRouter()
19
+
20
+
21
+ @boards_router.post(
22
+ "/",
23
+ response_model=IdInfo,
24
+ status_code=status.HTTP_201_CREATED,
25
+ operation_id="createBoard",
26
+ )
27
+ def create_board(board: CreateBoardRequest, engine: Engine = Depends(Metastore.get_engine)):
28
+ """
29
+ Creates a new board for a guild.
30
+
31
+ Args:
32
+ guild_id (str): The ID of the guild to create the board for.
33
+ board (CreateBoardRequest): The board creation request.
34
+
35
+ Returns:
36
+ IdInfo: The id of the newly created board.
37
+ """
38
+ try:
39
+ board_store = BoardStore(engine)
40
+ board_id = board_store.create_board(board.guild_id, board)
41
+ logging.debug(f"New board created: {board_id}")
42
+ return IdInfo(id=board_id)
43
+ except HTTPException:
44
+ raise
45
+ except Exception as e:
46
+ raise HTTPException(status_code=500, detail=str(e))
47
+
48
+
49
+ @boards_router.get("/", response_model=BoardsResponse, operation_id="getBoards")
50
+ def get_boards(guild_id: str, engine: Engine = Depends(Metastore.get_engine)):
51
+ """
52
+ Retrieves all boards for a guild.
53
+
54
+ Args:
55
+ guild_id (str): The ID of the guild to get boards for.
56
+
57
+ Returns:
58
+ BoardsResponse: The boards for the guild.
59
+ """
60
+ try:
61
+ board_store = BoardStore(engine)
62
+ boards = board_store.get_boards(guild_id)
63
+ board_responses = [
64
+ BoardResponse(
65
+ id=board.id,
66
+ name=board.name,
67
+ guild_id=board.guild_id,
68
+ created_by=board.created_by,
69
+ created_at=board.created_at,
70
+ is_default=board.is_default,
71
+ is_private=board.is_private,
72
+ )
73
+ for board in boards
74
+ ]
75
+ return BoardsResponse(boards=board_responses)
76
+ except HTTPException:
77
+ raise
78
+ except Exception as e:
79
+ raise HTTPException(status_code=500, detail=str(e))
80
+
81
+
82
+ @boards_router.post("/{board_id}/messages", status_code=status.HTTP_200_OK, operation_id="addMessageToBoard")
83
+ def add_message_to_board(
84
+ board_id: str,
85
+ request: AddMessageToBoardRequest,
86
+ engine: Engine = Depends(Metastore.get_engine),
87
+ ):
88
+ """
89
+ Adds a message to a board.
90
+
91
+ Args:
92
+ board_id (str): The ID of the board to add the message to.
93
+ request (AddMessageToBoardRequest): The request containing the message_id.
94
+
95
+ Returns:
96
+ dict: Success message.
97
+ """
98
+ try:
99
+ board_store = BoardStore(engine)
100
+ board_store.add_message_to_board(board_id, request.message_id)
101
+ return {"message": "Message added to the board successfully"}
102
+ except HTTPException:
103
+ raise
104
+ except Exception as e:
105
+ raise HTTPException(status_code=500, detail=str(e))
106
+
107
+
108
+ @boards_router.get(
109
+ "/{board_id}/messages",
110
+ response_model=BoardMessagesResponse,
111
+ operation_id="getBoardMessageIds",
112
+ )
113
+ def get_board_messages(board_id: str, engine: Engine = Depends(Metastore.get_engine)):
114
+ """
115
+ Retrieves all message IDs for a board.
116
+
117
+ Args:
118
+ board_id (str): The ID of the board to get messages for.
119
+
120
+ Returns:
121
+ BoardMessagesResponse: The message IDs in the board.
122
+ """
123
+ try:
124
+ board_store = BoardStore(engine)
125
+ message_ids = board_store.get_board_message_ids(board_id)
126
+ return BoardMessagesResponse(ids=message_ids)
127
+ except HTTPException:
128
+ raise
129
+ except Exception as e:
130
+ raise HTTPException(status_code=500, detail=str(e))
131
+
132
+
133
+ @boards_router.delete(
134
+ "/{board_id}/messages/{message_id}",
135
+ status_code=status.HTTP_200_OK,
136
+ operation_id="removeMessageFromBoard",
137
+ )
138
+ def remove_message_from_board(board_id: str, message_id: str, engine: Engine = Depends(Metastore.get_engine)):
139
+ """
140
+ Removes a message from a board.
141
+
142
+ Args:
143
+ board_id (str): The ID of the board to remove the message from.
144
+ message_id (str): The ID of the message to remove.
145
+
146
+ Returns:
147
+ dict: Success message.
148
+ """
149
+ try:
150
+ board_store = BoardStore(engine)
151
+ board_store.remove_message_from_board(board_id, message_id)
152
+ return {"message": "Message removed from the board successfully"}
153
+ except HTTPException:
154
+ raise
155
+ except Exception as e:
156
+ raise HTTPException(status_code=500, detail=str(e))
@@ -0,0 +1,34 @@
1
+ from datetime import datetime
2
+ from typing import List, Optional
3
+
4
+ from pydantic import BaseModel
5
+
6
+
7
+ class CreateBoardRequest(BaseModel):
8
+ guild_id: str
9
+ name: str
10
+ created_by: str
11
+ is_default: Optional[bool] = False
12
+ is_private: Optional[bool] = False
13
+
14
+
15
+ class BoardResponse(BaseModel):
16
+ id: str
17
+ name: str
18
+ guild_id: str
19
+ created_by: str
20
+ created_at: datetime
21
+ is_default: bool
22
+ is_private: bool
23
+
24
+
25
+ class BoardsResponse(BaseModel):
26
+ boards: List[BoardResponse]
27
+
28
+
29
+ class AddMessageToBoardRequest(BaseModel):
30
+ message_id: str
31
+
32
+
33
+ class BoardMessagesResponse(BaseModel):
34
+ ids: List[str]
@@ -0,0 +1,7 @@
1
+ from fastapi import APIRouter
2
+
3
+ from .boards import boards_router
4
+
5
+ addons_router = APIRouter()
6
+
7
+ addons_router.include_router(boards_router, prefix="/boards", tags=["boards"])
@@ -58,7 +58,7 @@ class CatalogStore:
58
58
  try:
59
59
  blueprint_details = blueprint_create.model_dump(
60
60
  exclude={
61
- "spec": {"id": True, "agents": {"__all__": {"id"}}},
61
+ "spec": True,
62
62
  "tags": True,
63
63
  "commands": True,
64
64
  "starter_prompts": True,
@@ -66,6 +66,7 @@ class CatalogStore:
66
66
  }
67
67
  )
68
68
  blueprint = Blueprint.model_validate(blueprint_details)
69
+ blueprint.spec = blueprint_create.spec
69
70
  session.add(blueprint)
70
71
  session.commit()
71
72
  session.refresh(blueprint)
@@ -110,6 +111,28 @@ class CatalogStore:
110
111
  return None
111
112
  return BlueprintDetailsResponse.from_table(blueprint)
112
113
 
114
+ def get_blueprint_with_exposure(self, blueprint_id: str, user_id: str, org_id: str) -> Optional[Blueprint]:
115
+ with Session(self.engine) as session:
116
+ blueprint = session.get(Blueprint, blueprint_id)
117
+ if not blueprint:
118
+ raise HTTPException(status_code=404, detail="Blueprint not found")
119
+ if blueprint.exposure == BlueprintExposure.PUBLIC:
120
+ return blueprint
121
+ if blueprint.exposure == BlueprintExposure.PRIVATE and blueprint.author_id == user_id:
122
+ return blueprint
123
+ if blueprint.exposure == BlueprintExposure.ORGANIZATION and blueprint.organization_id == org_id:
124
+ return blueprint
125
+ if blueprint.exposure == BlueprintExposure.SHARED and org_id:
126
+ statement = (
127
+ select(BlueprintSharedWithOrganization)
128
+ .where(BlueprintSharedWithOrganization.organization_id == org_id)
129
+ .where(BlueprintSharedWithOrganization.blueprint_id == blueprint_id)
130
+ )
131
+ entry = session.exec(statement).first()
132
+ if entry:
133
+ return blueprint
134
+ return None
135
+
113
136
  def add_tag_to_blueprint(self, blueprint_id: str, tag: str):
114
137
  with Session(self.engine) as session:
115
138
  blueprint = session.get(Blueprint, blueprint_id)
@@ -181,10 +204,19 @@ class CatalogStore:
181
204
  if not blueprint:
182
205
  raise HTTPException(status_code=404, detail=f"Blueprint {blueprint_id} not found")
183
206
 
207
+ # Ensure orginal organization has access when sharing bp with org exposure
208
+ if blueprint.exposure == BlueprintExposure.ORGANIZATION:
209
+ session.add(
210
+ BlueprintSharedWithOrganization(
211
+ organization_id=blueprint.organization_id, blueprint_id=blueprint_id
212
+ )
213
+ )
214
+
184
215
  blueprint.sqlmodel_update({"exposure": BlueprintExposure.SHARED})
185
216
  shared_with_organizations = BlueprintSharedWithOrganization(
186
217
  organization_id=organization_id, blueprint_id=blueprint_id
187
218
  )
219
+
188
220
  session.add(blueprint)
189
221
  session.add(shared_with_organizations)
190
222
  session.commit()
@@ -204,14 +236,19 @@ class CatalogStore:
204
236
  session.delete(entry)
205
237
  session.commit()
206
238
 
239
+ @staticmethod
240
+ def _get_bps_shared_with_org(session: Session, organization_id: str):
241
+ statement = (
242
+ select(Blueprint)
243
+ .join(BlueprintSharedWithOrganization)
244
+ .where(BlueprintSharedWithOrganization.organization_id == organization_id)
245
+ )
246
+ shared_blueprints = session.exec(statement).all()
247
+ return shared_blueprints
248
+
207
249
  def get_blueprints_shared_with_organization(self, organization_id: str) -> List[BlueprintInfoResponse]:
208
250
  with Session(self.engine) as session:
209
- statement = (
210
- select(Blueprint)
211
- .join(BlueprintSharedWithOrganization)
212
- .where(BlueprintSharedWithOrganization.organization_id == organization_id)
213
- )
214
- shared_blueprints = session.exec(statement).all()
251
+ shared_blueprints = self._get_bps_shared_with_org(session, organization_id)
215
252
  return [BlueprintInfoResponse.from_table(b) for b in shared_blueprints]
216
253
 
217
254
  def get_organization_with_shared_blueprint(self, blueprint_id: str) -> List[str]:
@@ -260,7 +297,9 @@ class CatalogStore:
260
297
  blueprint_info = BlueprintInfoResponse.from_table(blueprint).model_dump()
261
298
  return BlueprintResponseWithAccessReason(**blueprint_info, access_organization_id=org_id)
262
299
 
263
- def get_user_accessible_blueprints(self, user_id: str) -> List[BlueprintResponseWithAccessReason]:
300
+ def get_user_accessible_blueprints(
301
+ self, user_id: str, org_id: Optional[str]
302
+ ) -> List[BlueprintResponseWithAccessReason]:
264
303
  with Session(self.engine) as session:
265
304
 
266
305
  public_blueprints_list = session.exec(
@@ -277,30 +316,25 @@ class CatalogStore:
277
316
  b.id: self._blueprint_with_org_access(b) for b in owned_blueprints_list
278
317
  }
279
318
 
280
- # TODO - revisit this when there is a separate central app repository
281
- # user_orgs = user.organizations
282
- #
283
- # org_owned_blueprints: Dict[str, BlueprintResponseWithAccessReason] = {}
284
- # shared_blueprints: Dict[str, BlueprintResponseWithAccessReason] = {}
285
- # for org in user_orgs:
286
- # org_owned_blueprints.update(
287
- # {
288
- # b.id: self._blueprint_with_org_access(b, org_id=org.id)
289
- # for b in org.blueprints
290
- # if b.exposure == BlueprintExposure.ORGANIZATION
291
- # }
292
- # )
293
- #
294
- # shared_blueprints.update(
295
- # {
296
- # b.id: self._blueprint_with_org_access(b, org_id=org.id)
297
- # for b in org.shared_blueprints
298
- # if b.exposure == BlueprintExposure.SHARED
299
- # }
300
- # )
301
- # accessible_bps = {**public_blueprints, **owned_blueprints, **org_owned_blueprints, **shared_blueprints}
302
319
  accessible_bps = {**public_blueprints, **owned_blueprints}
303
320
 
321
+ if org_id and org_id.strip():
322
+ org_blueprints_list = session.exec(
323
+ select(Blueprint)
324
+ .where(Blueprint.organization_id == org_id)
325
+ .where(Blueprint.exposure == BlueprintExposure.ORGANIZATION)
326
+ ).all()
327
+ org_owned_blueprints: Dict[str, BlueprintResponseWithAccessReason] = {
328
+ b.id: self._blueprint_with_org_access(b, org_id=org_id) for b in org_blueprints_list
329
+ }
330
+
331
+ shared_blueprints_list = self._get_bps_shared_with_org(session, org_id)
332
+ shared_blueprints: Dict[str, BlueprintResponseWithAccessReason] = {
333
+ b.id: self._blueprint_with_org_access(b, org_id=org_id) for b in shared_blueprints_list
334
+ }
335
+
336
+ accessible_bps = {**public_blueprints, **owned_blueprints, **org_owned_blueprints, **shared_blueprints}
337
+
304
338
  return list(accessible_bps.values())
305
339
 
306
340
  def create_category(self, category_create: BlueprintCategoryCreate) -> str:
@@ -372,7 +406,7 @@ class CatalogStore:
372
406
  GuildModel.name,
373
407
  Blueprint.id.label("blueprint_id"), # type:ignore
374
408
  Blueprint.icon,
375
- GuildModel.status
409
+ GuildModel.status,
376
410
  )
377
411
  .select_from(GuildModel)
378
412
  .outerjoin(BlueprintGuild, GuildModel.id == BlueprintGuild.guild_id) # type:ignore
@@ -414,7 +448,7 @@ class CatalogStore:
414
448
  GuildModel.name,
415
449
  Blueprint.id.label("blueprint_id"), # type:ignore
416
450
  Blueprint.icon,
417
- GuildModel.status
451
+ GuildModel.status,
418
452
  )
419
453
  .select_from(
420
454
  join(GuildModel, UserGuild, GuildModel.id == UserGuild.guild_id) # type:ignore
@@ -433,6 +467,17 @@ class CatalogStore:
433
467
  guilds: Sequence[BasicGuildInfo] = session.exec(statement).all() # type:ignore
434
468
  return list(guilds)
435
469
 
470
+ def get_users_for_guild(self, guild_id: str) -> List[str]:
471
+ """Get all user IDs associated with a given guild."""
472
+ with Session(self.engine) as session:
473
+ guild = session.get(GuildModel, guild_id)
474
+ if not guild:
475
+ raise HTTPException(status_code=404, detail=f"Guild {guild_id} not found")
476
+
477
+ statement = select(UserGuild.user_id).where(UserGuild.guild_id == guild_id)
478
+ user_ids: Sequence[str] = session.exec(statement).all() # type:ignore
479
+ return list(user_ids)
480
+
436
481
  def add_agent_icon(self, agent_class: str, icon: str):
437
482
  with Session(self.engine) as session:
438
483
  existing_icon = session.get(AgentIcon, agent_class)
@@ -7,7 +7,6 @@ import shortuuid
7
7
  from sqlalchemy.ext.mutable import MutableDict
8
8
  from sqlmodel import JSON, Column, Field, Relationship, SQLModel
9
9
 
10
- from rustic_ai.core.guild.dsl import GuildSpec
11
10
  from rustic_ai.core.guild.metaprog.agent_registry import AgentEntry
12
11
 
13
12
 
@@ -108,7 +107,7 @@ class BlueprintBase(SQLModel):
108
107
 
109
108
 
110
109
  class BlueprintCreate(BlueprintBase):
111
- spec: GuildSpec
110
+ spec: dict
112
111
  tags: Optional[List[str]] = None
113
112
  commands: Optional[List[str]] = None
114
113
  starter_prompts: Optional[List[str]] = None
@@ -331,3 +330,16 @@ class CatalogAgentEntry(SQLModel, table=True):
331
330
  agent_props_schema=base.agent_props_schema,
332
331
  agent_dependencies={dep.dependency_key: dep.model_dump() for dep in base.agent_dependencies},
333
332
  )
333
+
334
+
335
+ class LaunchGuildFromBlueprintRequest(BaseModel):
336
+ """
337
+ Request to launch a guild from a blueprint.
338
+ """
339
+
340
+ guild_name: str
341
+ user_id: str
342
+ org_id: str
343
+ description: Optional[str] = None
344
+ configuration: dict = {}
345
+ guild_id: Optional[str] = None