mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-26 03:44:58 +08:00
* Initial plan * feat: Add API key authentication system backend Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * feat: Add API key management UI in frontend sidebar Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * fix: Correct import paths in API controller groups Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * fix: Address code review feedback - add i18n and validation Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * refactor: Enable API key auth on existing endpoints instead of creating separate service API - Added USER_TOKEN_OR_API_KEY auth type that accepts both authentication methods - Removed separate /api/service/v1/models endpoints - Updated existing endpoints (models, bots, pipelines) to accept API keys - External services can now use API keys to access all existing LangBot APIs - Updated documentation to reflect unified API approach Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * docs: Add OpenAPI specification for API key authenticated endpoints Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * chore: rename openapi spec * perf: ui and i18n * fix: ui bug * chore: tidy docs * chore: fix linter errors --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> Co-authored-by: Junyan Qin <rockchinq@gmail.com>
45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
import quart
|
|
|
|
from ... import group
|
|
|
|
|
|
@group.group_class('bots', '/api/v1/platform/bots')
|
|
class BotsRouterGroup(group.RouterGroup):
|
|
async def initialize(self) -> None:
|
|
@self.route('', methods=['GET', 'POST'], auth_type=group.AuthType.USER_TOKEN_OR_API_KEY)
|
|
async def _() -> str:
|
|
if quart.request.method == 'GET':
|
|
return self.success(data={'bots': await self.ap.bot_service.get_bots()})
|
|
elif quart.request.method == 'POST':
|
|
json_data = await quart.request.json
|
|
bot_uuid = await self.ap.bot_service.create_bot(json_data)
|
|
return self.success(data={'uuid': bot_uuid})
|
|
|
|
@self.route('/<bot_uuid>', methods=['GET', 'PUT', 'DELETE'], auth_type=group.AuthType.USER_TOKEN_OR_API_KEY)
|
|
async def _(bot_uuid: str) -> str:
|
|
if quart.request.method == 'GET':
|
|
bot = await self.ap.bot_service.get_bot(bot_uuid)
|
|
if bot is None:
|
|
return self.http_status(404, -1, 'bot not found')
|
|
return self.success(data={'bot': bot})
|
|
elif quart.request.method == 'PUT':
|
|
json_data = await quart.request.json
|
|
await self.ap.bot_service.update_bot(bot_uuid, json_data)
|
|
return self.success()
|
|
elif quart.request.method == 'DELETE':
|
|
await self.ap.bot_service.delete_bot(bot_uuid)
|
|
return self.success()
|
|
|
|
@self.route('/<bot_uuid>/logs', methods=['POST'], auth_type=group.AuthType.USER_TOKEN_OR_API_KEY)
|
|
async def _(bot_uuid: str) -> str:
|
|
json_data = await quart.request.json
|
|
from_index = json_data.get('from_index', -1)
|
|
max_count = json_data.get('max_count', 10)
|
|
logs, total_count = await self.ap.bot_service.list_event_logs(bot_uuid, from_index, max_count)
|
|
return self.success(
|
|
data={
|
|
'logs': logs,
|
|
'total_count': total_count,
|
|
}
|
|
)
|