ai-mini-box-web 0.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.
- ai_mini_box_web-0.1.0/.gitignore +15 -0
- ai_mini_box_web-0.1.0/LICENSE +21 -0
- ai_mini_box_web-0.1.0/PKG-INFO +73 -0
- ai_mini_box_web-0.1.0/README.md +30 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/__init__.py +0 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/commands.py +14 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/dependencies.py +11 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/routers/__init__.py +0 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/routers/contacts.py +52 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/routers/messages.py +40 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/routers/orders.py +46 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/routers/plugins.py +39 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/routers/products.py +52 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/server.py +25 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/services/__init__.py +0 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/services/plugin_manager.py +38 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/static/assets/index-BcRXnSp3.js +12 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/static/assets/index-DblLUj0D.css +2 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/static/favicon.svg +1 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/static/icons.svg +24 -0
- ai_mini_box_web-0.1.0/ai_mini_box_web/static/index.html +14 -0
- ai_mini_box_web-0.1.0/pyproject.toml +37 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kibertum
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ai-mini-box-web
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Web interface (PWA) for ai-mini-box-core
|
|
5
|
+
Project-URL: Homepage, https://github.com/Kibertum/ai-mini-box
|
|
6
|
+
Project-URL: Repository, https://github.com/Kibertum/ai-mini-box
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Kibertum
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Classifier: Development Status :: 3 - Alpha
|
|
30
|
+
Classifier: Intended Audience :: Developers
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
34
|
+
Classifier: Topic :: Office/Business
|
|
35
|
+
Requires-Python: >=3.12
|
|
36
|
+
Requires-Dist: ai-mini-box-core>=5.0.0
|
|
37
|
+
Requires-Dist: fastapi>=0.115
|
|
38
|
+
Requires-Dist: uvicorn>=0.30
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: httpx>=0.28; extra == 'dev'
|
|
41
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# ai-mini-box-web
|
|
45
|
+
|
|
46
|
+
Web interface (PWA) for [ai-mini-box-core](https://pypi.org/project/ai-mini-box-core/).
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install ai-mini-box-web
|
|
52
|
+
ai-mini-box init
|
|
53
|
+
ai-mini-box serve
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Open http://127.0.0.1:8000
|
|
57
|
+
|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
- Dashboard with entity counters
|
|
61
|
+
- Contacts, Products, Messages, Orders — CRUD via API
|
|
62
|
+
- Plugin dashboard — list installed plugins, view status and logs
|
|
63
|
+
- Built-in Swagger UI at `/docs`
|
|
64
|
+
|
|
65
|
+
## Development
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install -e packages/web[dev]
|
|
69
|
+
cd packages/web/frontend
|
|
70
|
+
npm run dev # hot-reload frontend
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Backend and frontend run separately during development (Vite proxies `/api` to FastAPI).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ai-mini-box-web
|
|
2
|
+
|
|
3
|
+
Web interface (PWA) for [ai-mini-box-core](https://pypi.org/project/ai-mini-box-core/).
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install ai-mini-box-web
|
|
9
|
+
ai-mini-box init
|
|
10
|
+
ai-mini-box serve
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Open http://127.0.0.1:8000
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- Dashboard with entity counters
|
|
18
|
+
- Contacts, Products, Messages, Orders — CRUD via API
|
|
19
|
+
- Plugin dashboard — list installed plugins, view status and logs
|
|
20
|
+
- Built-in Swagger UI at `/docs`
|
|
21
|
+
|
|
22
|
+
## Development
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e packages/web[dev]
|
|
26
|
+
cd packages/web/frontend
|
|
27
|
+
npm run dev # hot-reload frontend
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Backend and frontend run separately during development (Vite proxies `/api` to FastAPI).
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def register(app: typer.Typer):
|
|
5
|
+
@app.command()
|
|
6
|
+
def serve(
|
|
7
|
+
host: str = typer.Option("127.0.0.1", help="Host to bind"),
|
|
8
|
+
port: int = typer.Option(8000, help="Port to bind"),
|
|
9
|
+
reload: bool = typer.Option(False, help="Enable auto-reload for development"),
|
|
10
|
+
):
|
|
11
|
+
"""Start the web interface server."""
|
|
12
|
+
import uvicorn
|
|
13
|
+
|
|
14
|
+
uvicorn.run("ai_mini_box_web.server:app", host=host, port=port, reload=reload)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from collections.abc import Generator
|
|
2
|
+
|
|
3
|
+
from sqlalchemy.orm import Session
|
|
4
|
+
|
|
5
|
+
from ai_mini_box.core.container import RepoContainer
|
|
6
|
+
from ai_mini_box.infrastructure.database import get_db
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_repos() -> Generator[RepoContainer, None, None]:
|
|
10
|
+
with get_db() as session:
|
|
11
|
+
yield RepoContainer(session)
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
2
|
+
|
|
3
|
+
from ai_mini_box.core.container import RepoContainer
|
|
4
|
+
from ai_mini_box.core.models import Contact
|
|
5
|
+
from ai_mini_box_web.dependencies import get_repos
|
|
6
|
+
|
|
7
|
+
router = APIRouter()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@router.get("/")
|
|
11
|
+
def list_contacts(
|
|
12
|
+
limit: int = Query(20, ge=1, le=100),
|
|
13
|
+
offset: int = Query(0, ge=0),
|
|
14
|
+
search: str | None = Query(None),
|
|
15
|
+
repos: RepoContainer = Depends(get_repos),
|
|
16
|
+
):
|
|
17
|
+
if search:
|
|
18
|
+
items = repos.contacts.search(search)
|
|
19
|
+
return [c.model_dump() for c in items]
|
|
20
|
+
items = repos.contacts.list(limit=limit, offset=offset)
|
|
21
|
+
return [c.model_dump() for c in items]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@router.get("/{item_id}")
|
|
25
|
+
def get_contact(item_id: int, repos: RepoContainer = Depends(get_repos)):
|
|
26
|
+
item = repos.contacts.get_by_id(item_id)
|
|
27
|
+
if item is None:
|
|
28
|
+
raise HTTPException(404)
|
|
29
|
+
return item.model_dump()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@router.post("/", status_code=201)
|
|
33
|
+
def create_contact(data: dict, repos: RepoContainer = Depends(get_repos)):
|
|
34
|
+
contact = Contact(**data)
|
|
35
|
+
created = repos.contacts.add(contact)
|
|
36
|
+
return created.model_dump()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@router.put("/{item_id}")
|
|
40
|
+
def update_contact(item_id: int, data: dict, repos: RepoContainer = Depends(get_repos)):
|
|
41
|
+
existing = repos.contacts.get_by_id(item_id)
|
|
42
|
+
if existing is None:
|
|
43
|
+
raise HTTPException(404)
|
|
44
|
+
updated = existing.model_copy(update=data)
|
|
45
|
+
result = repos.contacts.update(updated)
|
|
46
|
+
return result.model_dump()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@router.delete("/{item_id}", status_code=204)
|
|
50
|
+
def delete_contact(item_id: int, repos: RepoContainer = Depends(get_repos)):
|
|
51
|
+
if not repos.contacts.delete(item_id):
|
|
52
|
+
raise HTTPException(404)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
2
|
+
|
|
3
|
+
from ai_mini_box.core.container import RepoContainer
|
|
4
|
+
from ai_mini_box.core.models import Message, Topic
|
|
5
|
+
from ai_mini_box_web.dependencies import get_repos
|
|
6
|
+
|
|
7
|
+
router = APIRouter()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@router.get("/")
|
|
11
|
+
def list_messages(
|
|
12
|
+
limit: int = Query(20, ge=1, le=100),
|
|
13
|
+
offset: int = Query(0, ge=0),
|
|
14
|
+
topic: Topic | None = Query(None),
|
|
15
|
+
search: str | None = Query(None),
|
|
16
|
+
repos: RepoContainer = Depends(get_repos),
|
|
17
|
+
):
|
|
18
|
+
if search:
|
|
19
|
+
items = repos.messages.search(search, topic=topic.value if topic else None)
|
|
20
|
+
return [m.model_dump() for m in items]
|
|
21
|
+
filters = {}
|
|
22
|
+
if topic:
|
|
23
|
+
filters["topic"] = topic
|
|
24
|
+
items = repos.messages.list(limit=limit, offset=offset, **filters)
|
|
25
|
+
return [m.model_dump() for m in items]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@router.get("/{item_id}")
|
|
29
|
+
def get_message(item_id: int, repos: RepoContainer = Depends(get_repos)):
|
|
30
|
+
item = repos.messages.get_by_id(item_id)
|
|
31
|
+
if item is None:
|
|
32
|
+
raise HTTPException(404)
|
|
33
|
+
return item.model_dump()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@router.post("/", status_code=201)
|
|
37
|
+
def create_message(data: dict, repos: RepoContainer = Depends(get_repos)):
|
|
38
|
+
message = Message(**data)
|
|
39
|
+
created = repos.messages.add(message)
|
|
40
|
+
return created.model_dump()
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
2
|
+
|
|
3
|
+
from ai_mini_box.core.container import RepoContainer
|
|
4
|
+
from ai_mini_box.core.models import Order, OrderStatus
|
|
5
|
+
from ai_mini_box_web.dependencies import get_repos
|
|
6
|
+
|
|
7
|
+
router = APIRouter()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@router.get("/")
|
|
11
|
+
def list_orders(
|
|
12
|
+
limit: int = Query(20, ge=1, le=100),
|
|
13
|
+
offset: int = Query(0, ge=0),
|
|
14
|
+
status: OrderStatus | None = Query(None),
|
|
15
|
+
repos: RepoContainer = Depends(get_repos),
|
|
16
|
+
):
|
|
17
|
+
filters = {}
|
|
18
|
+
if status:
|
|
19
|
+
filters["status"] = status
|
|
20
|
+
items = repos.orders.list(limit=limit, offset=offset, **filters)
|
|
21
|
+
return [o.model_dump() for o in items]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@router.get("/{item_id}")
|
|
25
|
+
def get_order(item_id: int, repos: RepoContainer = Depends(get_repos)):
|
|
26
|
+
item = repos.orders.get_by_id(item_id)
|
|
27
|
+
if item is None:
|
|
28
|
+
raise HTTPException(404)
|
|
29
|
+
return item.model_dump()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@router.post("/", status_code=201)
|
|
33
|
+
def create_order(data: dict, repos: RepoContainer = Depends(get_repos)):
|
|
34
|
+
order = Order(**data)
|
|
35
|
+
created = repos.orders.add(order)
|
|
36
|
+
return created.model_dump()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@router.put("/{item_id}")
|
|
40
|
+
def update_order(item_id: int, data: dict, repos: RepoContainer = Depends(get_repos)):
|
|
41
|
+
existing = repos.orders.get_by_id(item_id)
|
|
42
|
+
if existing is None:
|
|
43
|
+
raise HTTPException(404)
|
|
44
|
+
updated = existing.model_copy(update=data)
|
|
45
|
+
result = repos.orders.update(updated)
|
|
46
|
+
return result.model_dump()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter
|
|
4
|
+
|
|
5
|
+
from ai_mini_box_web.services.plugin_manager import PluginManager
|
|
6
|
+
|
|
7
|
+
router = APIRouter()
|
|
8
|
+
|
|
9
|
+
_manager = PluginManager()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@router.get("/")
|
|
13
|
+
def list_plugins():
|
|
14
|
+
return _manager.list_plugins()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@router.get("/{name}")
|
|
18
|
+
def get_plugin(name: str):
|
|
19
|
+
plugin = _manager.get_plugin(name)
|
|
20
|
+
if plugin is None:
|
|
21
|
+
from fastapi import HTTPException
|
|
22
|
+
raise HTTPException(404, detail=f"Plugin '{name}' not found")
|
|
23
|
+
return plugin
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@router.post("/{name}/start", status_code=501)
|
|
27
|
+
def start_plugin(name: str):
|
|
28
|
+
return {"detail": "Plugin lifecycle management not yet implemented"}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@router.post("/{name}/stop", status_code=501)
|
|
32
|
+
def stop_plugin(name: str):
|
|
33
|
+
return {"detail": "Plugin lifecycle management not yet implemented"}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@router.get("/{name}/logs")
|
|
37
|
+
def get_plugin_logs(name: str):
|
|
38
|
+
lines = _manager.get_logs(name)
|
|
39
|
+
return {"plugin": name, "lines": lines}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
2
|
+
|
|
3
|
+
from ai_mini_box.core.container import RepoContainer
|
|
4
|
+
from ai_mini_box.core.models import Product
|
|
5
|
+
from ai_mini_box_web.dependencies import get_repos
|
|
6
|
+
|
|
7
|
+
router = APIRouter()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@router.get("/")
|
|
11
|
+
def list_products(
|
|
12
|
+
limit: int = Query(20, ge=1, le=100),
|
|
13
|
+
offset: int = Query(0, ge=0),
|
|
14
|
+
search: str | None = Query(None),
|
|
15
|
+
repos: RepoContainer = Depends(get_repos),
|
|
16
|
+
):
|
|
17
|
+
if search:
|
|
18
|
+
items = repos.products.search(search)
|
|
19
|
+
return [p.model_dump() for p in items]
|
|
20
|
+
items = repos.products.list(limit=limit, offset=offset)
|
|
21
|
+
return [p.model_dump() for p in items]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@router.get("/{item_id}")
|
|
25
|
+
def get_product(item_id: int, repos: RepoContainer = Depends(get_repos)):
|
|
26
|
+
item = repos.products.get_by_id(item_id)
|
|
27
|
+
if item is None:
|
|
28
|
+
raise HTTPException(404)
|
|
29
|
+
return item.model_dump()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@router.post("/", status_code=201)
|
|
33
|
+
def create_product(data: dict, repos: RepoContainer = Depends(get_repos)):
|
|
34
|
+
product = Product(**data)
|
|
35
|
+
created = repos.products.add(product)
|
|
36
|
+
return created.model_dump()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@router.put("/{item_id}")
|
|
40
|
+
def update_product(item_id: int, data: dict, repos: RepoContainer = Depends(get_repos)):
|
|
41
|
+
existing = repos.products.get_by_id(item_id)
|
|
42
|
+
if existing is None:
|
|
43
|
+
raise HTTPException(404)
|
|
44
|
+
updated = existing.model_copy(update=data)
|
|
45
|
+
result = repos.products.update(updated)
|
|
46
|
+
return result.model_dump()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@router.delete("/{item_id}", status_code=204)
|
|
50
|
+
def delete_product(item_id: int, repos: RepoContainer = Depends(get_repos)):
|
|
51
|
+
if not repos.products.delete(item_id):
|
|
52
|
+
raise HTTPException(404)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from contextlib import asynccontextmanager
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from fastapi import FastAPI
|
|
5
|
+
from fastapi.staticfiles import StaticFiles
|
|
6
|
+
|
|
7
|
+
from ai_mini_box_web.routers import contacts, messages, orders, plugins, products
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@asynccontextmanager
|
|
11
|
+
async def lifespan(app: FastAPI):
|
|
12
|
+
yield
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
app = FastAPI(title="AI mini box", version="0.1.0", lifespan=lifespan)
|
|
16
|
+
|
|
17
|
+
app.include_router(contacts.router, prefix="/api/contacts", tags=["contacts"])
|
|
18
|
+
app.include_router(products.router, prefix="/api/products", tags=["products"])
|
|
19
|
+
app.include_router(messages.router, prefix="/api/messages", tags=["messages"])
|
|
20
|
+
app.include_router(orders.router, prefix="/api/orders", tags=["orders"])
|
|
21
|
+
app.include_router(plugins.router, prefix="/api/plugins", tags=["plugins"])
|
|
22
|
+
|
|
23
|
+
static_dir = Path(__file__).parent / "static"
|
|
24
|
+
if static_dir.exists():
|
|
25
|
+
app.mount("/", StaticFiles(directory=str(static_dir), html=True), name="static")
|
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PluginManager:
|
|
6
|
+
def __init__(self):
|
|
7
|
+
self._log_dir = Path("logs")
|
|
8
|
+
self._log_dir.mkdir(parents=True, exist_ok=True)
|
|
9
|
+
|
|
10
|
+
def list_plugins(self) -> list[dict]:
|
|
11
|
+
plugins = []
|
|
12
|
+
for ep in importlib.metadata.entry_points(group="ai_mini_box.tools"):
|
|
13
|
+
module = ep.module if hasattr(ep, "module") else ep.value
|
|
14
|
+
plugins.append({
|
|
15
|
+
"name": ep.name,
|
|
16
|
+
"module": ep.value,
|
|
17
|
+
"status": "stopped",
|
|
18
|
+
"pid": None,
|
|
19
|
+
})
|
|
20
|
+
return plugins
|
|
21
|
+
|
|
22
|
+
def get_plugin(self, name: str) -> dict | None:
|
|
23
|
+
for ep in importlib.metadata.entry_points(group="ai_mini_box.tools"):
|
|
24
|
+
if ep.name == name:
|
|
25
|
+
return {
|
|
26
|
+
"name": ep.name,
|
|
27
|
+
"module": ep.value,
|
|
28
|
+
"status": "stopped",
|
|
29
|
+
"pid": None,
|
|
30
|
+
}
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
def get_logs(self, name: str, max_lines: int = 100) -> list[str]:
|
|
34
|
+
log_file = self._log_dir / f"plugin_{name}.log"
|
|
35
|
+
if not log_file.exists():
|
|
36
|
+
return []
|
|
37
|
+
lines = log_file.read_text(encoding="utf-8", errors="replace").splitlines()
|
|
38
|
+
return lines[-max_lines:]
|