Compare commits
26 Commits
main
..
14617cba84
| Author | SHA1 | Date | |
|---|---|---|---|
| 14617cba84 | |||
| 8b38e04039 | |||
| 7e3d80b832 | |||
| 5441454993 | |||
| 5af751f575 | |||
| c32de547bf | |||
| 058ec809ff | |||
| e1e0670d0e | |||
| ab073397ba | |||
| 2e5ffa76da | |||
| a864c8b662 | |||
| 35b58bac06 | |||
| ae9013536b | |||
| 592aa5bc6b | |||
| 9d579d9b9f | |||
| 4cb1585f53 | |||
| 5a6b4ebacd | |||
| 277e68f1ed | |||
| 9869ac2f20 | |||
| cd2a0f700f | |||
| 2978be0491 | |||
| 4ebc1db5e6 | |||
| 4b72ab7511 | |||
| 1969af367c | |||
| 20478eb192 | |||
| 310a7b2545 |
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: recreate down reset hard-reset restart frontend deploy rebuild migrate convex-key script
|
.PHONY: recreate down restart frontend deploy rebuild migrate convex-key script
|
||||||
|
|
||||||
recreate:
|
recreate:
|
||||||
docker compose --profile services up -d
|
docker compose --profile services up -d
|
||||||
@@ -6,20 +6,11 @@ recreate:
|
|||||||
down:
|
down:
|
||||||
docker compose --profile services down
|
docker compose --profile services down
|
||||||
|
|
||||||
reset:
|
|
||||||
$(MAKE) down
|
|
||||||
$(MAKE) recreate
|
|
||||||
|
|
||||||
hard-reset:
|
|
||||||
docker compose down
|
|
||||||
docker compose up -d
|
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
docker compose --profile services restart
|
docker compose --profile services restart
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
docker compose build frontend
|
docker compose build frontend
|
||||||
$(MAKE) migrate
|
|
||||||
docker compose up -d frontend
|
docker compose up -d frontend
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
@@ -34,13 +25,7 @@ migrate:
|
|||||||
docker compose run --rm migrate
|
docker compose run --rm migrate
|
||||||
|
|
||||||
convex-key:
|
convex-key:
|
||||||
@output=$$(docker compose exec convex ./generate_admin_key.sh 2>&1); \
|
docker compose exec convex ./generate_admin_key.sh
|
||||||
echo "$$output"; \
|
|
||||||
if echo "$$output" | grep -q "Admin key:"; then \
|
|
||||||
key=$$(echo "$$output" | tail -1); \
|
|
||||||
sed -i '' 's#^CONVEX_SELF_HOSTED_ADMIN_KEY=.*#CONVEX_SELF_HOSTED_ADMIN_KEY='"$$key"'#' frontend/.env; \
|
|
||||||
echo "Updated frontend/.env with new admin key"; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
@cd backend && docker compose --profile scripts run --rm script-runner scripts/$(subst .,/,$(word 2,$(MAKECMDGOALS))).py $(wordlist 3,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
|
@cd backend && docker compose --profile scripts run --rm script-runner scripts/$(subst .,/,$(word 2,$(MAKECMDGOALS))).py $(wordlist 3,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
|
||||||
|
|||||||
@@ -2,18 +2,7 @@ BOT__TOKEN=<BOT__TOKEN>
|
|||||||
|
|
||||||
SITE__URL=<SITE__URL>
|
SITE__URL=<SITE__URL>
|
||||||
|
|
||||||
# Leave ANTHROPIC_API_KEY empty to disable the Anthropic backup.
|
|
||||||
ANTHROPIC_API_KEY=
|
|
||||||
ANTHROPIC_MODEL=claude-opus-4-8
|
|
||||||
|
|
||||||
LOG__LEVEL=INFO
|
LOG__LEVEL=INFO
|
||||||
LOG__LEVEL_EXTERNAL=WARNING
|
LOG__LEVEL_EXTERNAL=WARNING
|
||||||
LOG__SHOW_TIME=false
|
LOG__SHOW_TIME=false
|
||||||
LOG__CONSOLE_WIDTH=150
|
LOG__CONSOLE_WIDTH=150
|
||||||
|
|
||||||
COLLABORATIVE__API_URL=<COLLABORATIVE__API_URL>
|
|
||||||
COLLABORATIVE__API_KEY=
|
|
||||||
COLLABORATIVE__POLL_INTERVAL_SECONDS=8
|
|
||||||
COLLABORATIVE__UPLOAD_MAX_ATTEMPTS=8
|
|
||||||
COLLABORATIVE__UPLOAD_BACKOFF_BASE_SECONDS=2.0
|
|
||||||
COLLABORATIVE__REQUEST_TIMEOUT_SECONDS=30
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ requires-python = ">=3.13"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"aiogram>=3.24.0",
|
"aiogram>=3.24.0",
|
||||||
"convex>=0.7.0",
|
"convex>=0.7.0",
|
||||||
"httpx>=0.27",
|
"pydantic-ai-slim[google]>=1.44.0",
|
||||||
"pydantic-ai-slim[google,anthropic]>=1.44.0",
|
|
||||||
"pydantic-settings>=2.12.0",
|
"pydantic-settings>=2.12.0",
|
||||||
"rich>=14.2.0",
|
"rich>=14.2.0",
|
||||||
"xkcdpass>=1.19.0",
|
"xkcdpass>=1.19.0",
|
||||||
|
|||||||
@@ -11,28 +11,20 @@ setup_logging()
|
|||||||
async def runner() -> None:
|
async def runner() -> None:
|
||||||
from . import handlers # noqa: PLC0415
|
from . import handlers # noqa: PLC0415
|
||||||
from .common import bot, dp # noqa: PLC0415
|
from .common import bot, dp # noqa: PLC0415
|
||||||
from .sync import ( # noqa: PLC0415
|
from .sync import start_sync_listener # noqa: PLC0415
|
||||||
start_room_inbox_poller,
|
|
||||||
start_room_upload_worker,
|
|
||||||
start_sync_listener,
|
|
||||||
)
|
|
||||||
|
|
||||||
dp.include_routers(handlers.router)
|
dp.include_routers(handlers.router)
|
||||||
|
|
||||||
sync_task = asyncio.create_task(start_sync_listener(bot))
|
sync_task = asyncio.create_task(start_sync_listener(bot))
|
||||||
upload_task = asyncio.create_task(start_room_upload_worker(bot))
|
|
||||||
inbox_task = asyncio.create_task(start_room_inbox_poller(bot))
|
|
||||||
|
|
||||||
await bot.delete_webhook(drop_pending_updates=True)
|
await bot.delete_webhook(drop_pending_updates=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await dp.start_polling(bot)
|
await dp.start_polling(bot)
|
||||||
finally:
|
finally:
|
||||||
for t in (sync_task, upload_task, inbox_task):
|
sync_task.cancel()
|
||||||
t.cancel()
|
with contextlib.suppress(asyncio.CancelledError):
|
||||||
for t in (sync_task, upload_task, inbox_task):
|
await sync_task
|
||||||
with contextlib.suppress(asyncio.CancelledError):
|
|
||||||
await t
|
|
||||||
|
|
||||||
|
|
||||||
def plugins() -> None:
|
def plugins() -> None:
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
from aiogram import Router
|
from aiogram import Router
|
||||||
|
|
||||||
from . import apikey, chat, initialize, inject, message, proxy, rag, room, start
|
from . import apikey, chat, initialize, message, start
|
||||||
|
|
||||||
router = Router()
|
router = Router()
|
||||||
|
|
||||||
router.include_routers(
|
router.include_routers(
|
||||||
start.router,
|
start.router, initialize.router, apikey.router, chat.router, message.router
|
||||||
initialize.router,
|
|
||||||
apikey.router,
|
|
||||||
chat.router,
|
|
||||||
rag.router,
|
|
||||||
inject.router,
|
|
||||||
proxy.router,
|
|
||||||
room.router,
|
|
||||||
message.router,
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ async def startup(bot: Bot) -> None:
|
|||||||
types.BotCommand(command="/model", description="Change AI model"),
|
types.BotCommand(command="/model", description="Change AI model"),
|
||||||
types.BotCommand(command="/presets", description="Show prompt presets"),
|
types.BotCommand(command="/presets", description="Show prompt presets"),
|
||||||
types.BotCommand(command="/preset", description="Apply a preset"),
|
types.BotCommand(command="/preset", description="Apply a preset"),
|
||||||
types.BotCommand(command="/proxy", description="Proxy chat to another bot"),
|
|
||||||
types.BotCommand(command="/inject", description="Inject knowledge base"),
|
|
||||||
types.BotCommand(command="/room", description="Manage collaborative room"),
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
logger.info(f"[green]Started as[/] @{(await bot.me()).username}")
|
logger.info(f"[green]Started as[/] @{(await bot.me()).username}")
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
from aiogram import Router
|
|
||||||
|
|
||||||
from .collection import router as collection_router
|
|
||||||
from .handler import router as command_router
|
|
||||||
|
|
||||||
router = Router()
|
|
||||||
|
|
||||||
router.include_routers(command_router, collection_router)
|
|
||||||
|
|
||||||
__all__ = ["router"]
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import io
|
|
||||||
|
|
||||||
from aiogram import Bot, F, Router, types
|
|
||||||
from aiogram.filters import Filter
|
|
||||||
from convex import ConvexInt64
|
|
||||||
|
|
||||||
from utils import env
|
|
||||||
from utils.convex import ConvexClient
|
|
||||||
|
|
||||||
router = Router()
|
|
||||||
convex = ConvexClient(env.convex_url)
|
|
||||||
|
|
||||||
|
|
||||||
class InInjectCollectionMode(Filter):
|
|
||||||
async def __call__(self, message: types.Message) -> bool | dict:
|
|
||||||
if not message.from_user:
|
|
||||||
return False
|
|
||||||
|
|
||||||
user = await convex.query(
|
|
||||||
"users:getByTelegramId", {"telegramId": ConvexInt64(message.from_user.id)}
|
|
||||||
)
|
|
||||||
|
|
||||||
if not user or not user.get("injectCollectionMode"):
|
|
||||||
return False
|
|
||||||
|
|
||||||
return {
|
|
||||||
"inject_user": user,
|
|
||||||
"inject_collection_mode": user["injectCollectionMode"],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
in_collection_mode = InInjectCollectionMode()
|
|
||||||
|
|
||||||
|
|
||||||
@router.message(in_collection_mode, F.text & ~F.text.startswith("/"))
|
|
||||||
async def on_text_in_collection_mode(
|
|
||||||
message: types.Message, inject_user: dict, inject_collection_mode: dict
|
|
||||||
) -> None:
|
|
||||||
if not message.text:
|
|
||||||
return
|
|
||||||
|
|
||||||
db_id = inject_collection_mode["injectDatabaseId"]
|
|
||||||
|
|
||||||
db = await convex.query("inject:getDatabaseById", {"injectDatabaseId": db_id})
|
|
||||||
db_name = db["name"] if db else "database"
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"inject:setContent", {"injectDatabaseId": db_id, "content": message.text}
|
|
||||||
)
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"users:stopInjectCollectionMode", {"userId": inject_user["_id"]}
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.answer(
|
|
||||||
f"✓ Text saved to '{db_name}'.\n\n"
|
|
||||||
f"Connect it with: <code>/inject connect {db_name}</code>",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@router.message(in_collection_mode, F.document)
|
|
||||||
async def on_document_in_collection_mode(
|
|
||||||
message: types.Message, bot: Bot, inject_user: dict, inject_collection_mode: dict
|
|
||||||
) -> None:
|
|
||||||
if not message.document:
|
|
||||||
return
|
|
||||||
|
|
||||||
doc = message.document
|
|
||||||
db_id = inject_collection_mode["injectDatabaseId"]
|
|
||||||
|
|
||||||
db = await convex.query("inject:getDatabaseById", {"injectDatabaseId": db_id})
|
|
||||||
db_name = db["name"] if db else "database"
|
|
||||||
|
|
||||||
file = await bot.get_file(doc.file_id)
|
|
||||||
if not file.file_path:
|
|
||||||
await message.answer("Failed to download file.")
|
|
||||||
return
|
|
||||||
|
|
||||||
buffer = io.BytesIO()
|
|
||||||
await bot.download_file(file.file_path, buffer)
|
|
||||||
text = buffer.getvalue().decode("utf-8")
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"inject:setContent", {"injectDatabaseId": db_id, "content": text}
|
|
||||||
)
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"users:stopInjectCollectionMode", {"userId": inject_user["_id"]}
|
|
||||||
)
|
|
||||||
|
|
||||||
file_name = doc.file_name or "file"
|
|
||||||
await message.answer(
|
|
||||||
f"✓ '{file_name}' saved to '{db_name}'.\n\n"
|
|
||||||
f"Connect it with: <code>/inject connect {db_name}</code>",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
from aiogram import Router, types
|
|
||||||
from aiogram.filters import Command
|
|
||||||
from convex import ConvexInt64
|
|
||||||
|
|
||||||
from utils import env
|
|
||||||
from utils.convex import ConvexClient
|
|
||||||
|
|
||||||
router = Router()
|
|
||||||
convex = ConvexClient(env.convex_url)
|
|
||||||
|
|
||||||
|
|
||||||
@router.message(Command("inject"))
|
|
||||||
async def on_inject(message: types.Message) -> None:
|
|
||||||
if not message.from_user or not message.text:
|
|
||||||
return
|
|
||||||
|
|
||||||
args = message.text.split()[1:]
|
|
||||||
|
|
||||||
if not args:
|
|
||||||
await show_usage(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
user = await convex.query(
|
|
||||||
"users:getByTelegramId", {"telegramId": ConvexInt64(message.from_user.id)}
|
|
||||||
)
|
|
||||||
|
|
||||||
if not user:
|
|
||||||
await message.answer("Use /apikey first to set your Gemini API key.")
|
|
||||||
return
|
|
||||||
|
|
||||||
user_id = user["_id"]
|
|
||||||
command = args[0]
|
|
||||||
|
|
||||||
if command == "list":
|
|
||||||
await list_databases(message, user_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
if len(args) < 2: # noqa: PLR2004
|
|
||||||
await show_usage(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
db_name = args[1]
|
|
||||||
|
|
||||||
if command == "create":
|
|
||||||
await create_database(message, user_id, db_name)
|
|
||||||
elif command == "connect":
|
|
||||||
await connect_database(message, user_id, db_name)
|
|
||||||
elif command == "disconnect":
|
|
||||||
await disconnect_database(message, user_id, db_name)
|
|
||||||
elif command == "clear":
|
|
||||||
await clear_database(message, user_id, db_name)
|
|
||||||
else:
|
|
||||||
await show_usage(message)
|
|
||||||
|
|
||||||
|
|
||||||
async def show_usage(message: types.Message) -> None:
|
|
||||||
await message.answer(
|
|
||||||
"<b>Inject Commands:</b>\n\n"
|
|
||||||
"<code>/inject list</code> - List inject databases\n\n"
|
|
||||||
"<code>/inject create <name></code> - Create and upload one file\n"
|
|
||||||
"<code>/inject connect <name></code> - Connect to all chats\n"
|
|
||||||
"<code>/inject disconnect <name></code> - Disconnect\n"
|
|
||||||
"<code>/inject clear <name></code> - Delete database",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def list_databases(message: types.Message, user_id: str) -> None:
|
|
||||||
databases = await convex.query("inject:listDatabases", {"userId": user_id})
|
|
||||||
connections = await convex.query(
|
|
||||||
"injectConnections:getActiveForUser", {"userId": user_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
connected_db_ids = {conn["injectDatabaseId"] for conn in connections}
|
|
||||||
|
|
||||||
if not databases:
|
|
||||||
await message.answer(
|
|
||||||
"No inject databases found.\n\n"
|
|
||||||
"Create one with: <code>/inject create mydb</code>",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
lines = ["<b>Your inject databases:</b>\n"]
|
|
||||||
for db in databases:
|
|
||||||
status = ""
|
|
||||||
if db["_id"] in connected_db_ids:
|
|
||||||
status += " (connected)"
|
|
||||||
if not db.get("content"):
|
|
||||||
status += " (empty)"
|
|
||||||
lines.append(f"• {db['name']}{status}")
|
|
||||||
|
|
||||||
await message.answer("\n".join(lines), parse_mode="HTML")
|
|
||||||
|
|
||||||
|
|
||||||
async def create_database(message: types.Message, user_id: str, db_name: str) -> None:
|
|
||||||
collection_mode = await convex.query(
|
|
||||||
"users:getInjectCollectionMode", {"userId": user_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
if collection_mode:
|
|
||||||
await message.answer(
|
|
||||||
"Already waiting for a file. Send a file or text to complete."
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
db_id = await convex.mutation(
|
|
||||||
"inject:createDatabase", {"userId": user_id, "name": db_name}
|
|
||||||
)
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"users:startInjectCollectionMode",
|
|
||||||
{"userId": user_id, "injectDatabaseId": db_id},
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.answer(
|
|
||||||
f"<b>Waiting for content for '{db_name}'</b>\n\n"
|
|
||||||
"Send a file (json, txt, csv, etc.) or a text message.\n"
|
|
||||||
"It will be saved automatically.",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def connect_database(message: types.Message, user_id: str, db_name: str) -> None:
|
|
||||||
db = await convex.query("inject:getDatabase", {"userId": user_id, "name": db_name})
|
|
||||||
|
|
||||||
if not db:
|
|
||||||
await message.answer(
|
|
||||||
f"Database '{db_name}' not found.\n"
|
|
||||||
f"Create it with: <code>/inject create {db_name}</code>",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"injectConnections:connect",
|
|
||||||
{"userId": user_id, "injectDatabaseId": db["_id"], "isGlobal": True},
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.answer(f"✓ '{db_name}' connected to all your chats.")
|
|
||||||
|
|
||||||
|
|
||||||
async def disconnect_database(
|
|
||||||
message: types.Message, user_id: str, db_name: str
|
|
||||||
) -> None:
|
|
||||||
db = await convex.query("inject:getDatabase", {"userId": user_id, "name": db_name})
|
|
||||||
|
|
||||||
if not db:
|
|
||||||
await message.answer(f"Database '{db_name}' not found.")
|
|
||||||
return
|
|
||||||
|
|
||||||
result = await convex.mutation(
|
|
||||||
"injectConnections:disconnect",
|
|
||||||
{"userId": user_id, "injectDatabaseId": db["_id"]},
|
|
||||||
)
|
|
||||||
|
|
||||||
if result:
|
|
||||||
await message.answer(f"✓ '{db_name}' disconnected.")
|
|
||||||
else:
|
|
||||||
await message.answer(f"'{db_name}' was not connected.")
|
|
||||||
|
|
||||||
|
|
||||||
async def clear_database(message: types.Message, user_id: str, db_name: str) -> None:
|
|
||||||
db = await convex.query("inject:getDatabase", {"userId": user_id, "name": db_name})
|
|
||||||
|
|
||||||
if not db:
|
|
||||||
await message.answer(f"Database '{db_name}' not found.")
|
|
||||||
return
|
|
||||||
|
|
||||||
await convex.mutation("inject:deleteDatabase", {"injectDatabaseId": db["_id"]})
|
|
||||||
|
|
||||||
await message.answer(f"✓ '{db_name}' deleted.")
|
|
||||||
@@ -3,115 +3,26 @@ import base64
|
|||||||
import contextlib
|
import contextlib
|
||||||
import io
|
import io
|
||||||
import time
|
import time
|
||||||
from collections.abc import Awaitable, Callable
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from aiogram import BaseMiddleware, Bot, F, Router, html, types
|
from aiogram import Bot, F, Router, html, types
|
||||||
from aiogram.enums import ChatAction
|
from aiogram.enums import ChatAction
|
||||||
from aiogram.types import (
|
from aiogram.types import KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove
|
||||||
BufferedInputFile,
|
|
||||||
InputMediaPhoto,
|
|
||||||
KeyboardButton,
|
|
||||||
ReplyKeyboardMarkup,
|
|
||||||
ReplyKeyboardRemove,
|
|
||||||
TelegramObject,
|
|
||||||
)
|
|
||||||
from convex import ConvexInt64
|
from convex import ConvexInt64
|
||||||
|
|
||||||
from bot.handlers.proxy.handler import get_proxy_config, increment_proxy_count
|
|
||||||
from bot.modules.ai import (
|
from bot.modules.ai import (
|
||||||
SUMMARIZE_PROMPT,
|
SUMMARIZE_PROMPT,
|
||||||
AgentDeps,
|
|
||||||
ImageData,
|
ImageData,
|
||||||
create_follow_up_agent,
|
create_follow_up_agent,
|
||||||
create_text_agent,
|
create_text_agent,
|
||||||
get_follow_ups,
|
get_follow_ups,
|
||||||
stream_response,
|
stream_response,
|
||||||
)
|
)
|
||||||
from bot.user_lock import get_user_lock
|
|
||||||
from utils import env
|
from utils import env
|
||||||
from utils.convex import ConvexClient
|
from utils.convex import ConvexClient
|
||||||
from utils.logging import logger
|
|
||||||
|
|
||||||
router = Router()
|
router = Router()
|
||||||
convex = ConvexClient(env.convex_url)
|
convex = ConvexClient(env.convex_url)
|
||||||
|
|
||||||
ALBUM_COLLECT_DELAY = 0.5
|
|
||||||
|
|
||||||
_room_upload_tasks: set[asyncio.Task] = set()
|
|
||||||
|
|
||||||
|
|
||||||
async def _enqueue_room_upload(
|
|
||||||
user_id: str, pin: str, image_b64: str, media_type: str
|
|
||||||
) -> None:
|
|
||||||
try:
|
|
||||||
await convex.mutation(
|
|
||||||
"collaborative:enqueueUpload",
|
|
||||||
{
|
|
||||||
"userId": user_id,
|
|
||||||
"pin": pin,
|
|
||||||
"imageBase64": image_b64,
|
|
||||||
"mediaType": media_type,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"Failed to enqueue room upload: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
def schedule_room_uploads(
|
|
||||||
user: dict, images_base64: list[str], media_types: list[str]
|
|
||||||
) -> None:
|
|
||||||
room = user.get("collaborativeRoom") if user else None
|
|
||||||
if not room:
|
|
||||||
return
|
|
||||||
pin = room.get("pin")
|
|
||||||
if not pin:
|
|
||||||
return
|
|
||||||
user_id = user["_id"]
|
|
||||||
for img_b64, media_type in zip(images_base64, media_types, strict=True):
|
|
||||||
task = asyncio.create_task(
|
|
||||||
_enqueue_room_upload(user_id, pin, img_b64, media_type)
|
|
||||||
)
|
|
||||||
_room_upload_tasks.add(task)
|
|
||||||
task.add_done_callback(_room_upload_tasks.discard)
|
|
||||||
|
|
||||||
|
|
||||||
class AlbumMiddleware(BaseMiddleware):
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self.albums: dict[str, list[types.Message]] = {}
|
|
||||||
self.scheduled: set[str] = set()
|
|
||||||
|
|
||||||
async def __call__(
|
|
||||||
self,
|
|
||||||
handler: Callable[[TelegramObject, dict[str, Any]], Awaitable[Any]],
|
|
||||||
event: TelegramObject,
|
|
||||||
data: dict[str, Any],
|
|
||||||
) -> Any: # noqa: ANN401
|
|
||||||
if not isinstance(event, types.Message) or not event.media_group_id:
|
|
||||||
return await handler(event, data)
|
|
||||||
|
|
||||||
album_id = event.media_group_id
|
|
||||||
if album_id not in self.albums:
|
|
||||||
self.albums[album_id] = []
|
|
||||||
self.albums[album_id].append(event)
|
|
||||||
|
|
||||||
if album_id in self.scheduled:
|
|
||||||
return None
|
|
||||||
|
|
||||||
self.scheduled.add(album_id)
|
|
||||||
await asyncio.sleep(ALBUM_COLLECT_DELAY)
|
|
||||||
|
|
||||||
messages = self.albums.pop(album_id, [])
|
|
||||||
self.scheduled.discard(album_id)
|
|
||||||
|
|
||||||
if messages:
|
|
||||||
data["album"] = messages
|
|
||||||
return await handler(messages[0], data)
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
router.message.middleware(AlbumMiddleware())
|
|
||||||
|
|
||||||
EDIT_THROTTLE_SECONDS = 1.0
|
EDIT_THROTTLE_SECONDS = 1.0
|
||||||
TELEGRAM_MAX_LENGTH = 4096
|
TELEGRAM_MAX_LENGTH = 4096
|
||||||
|
|
||||||
@@ -201,148 +112,36 @@ class StreamingState:
|
|||||||
await self.update_message(self.pending_content, force=True)
|
await self.update_message(self.pending_content, force=True)
|
||||||
|
|
||||||
|
|
||||||
class ProxyStreamingState:
|
|
||||||
def __init__(self, bot: Bot, chat_id: int, message: types.Message) -> None:
|
|
||||||
self.bot = bot
|
|
||||||
self.chat_id = chat_id
|
|
||||||
self.message = message
|
|
||||||
self.last_edit_time = 0.0
|
|
||||||
self.last_content = ""
|
|
||||||
self.pending_content: str | None = None
|
|
||||||
|
|
||||||
async def update_message(self, content: str, *, force: bool = False) -> None:
|
|
||||||
if content == self.last_content:
|
|
||||||
return
|
|
||||||
|
|
||||||
if len(content) > TELEGRAM_MAX_LENGTH:
|
|
||||||
display_content = content[: TELEGRAM_MAX_LENGTH - 3] + "..."
|
|
||||||
else:
|
|
||||||
display_content = content
|
|
||||||
|
|
||||||
now = time.monotonic()
|
|
||||||
if force or (now - self.last_edit_time) >= EDIT_THROTTLE_SECONDS:
|
|
||||||
with contextlib.suppress(Exception):
|
|
||||||
await self.message.edit_text(display_content)
|
|
||||||
self.last_edit_time = now
|
|
||||||
self.last_content = content
|
|
||||||
self.pending_content = None
|
|
||||||
else:
|
|
||||||
self.pending_content = content
|
|
||||||
|
|
||||||
async def flush(self) -> None:
|
|
||||||
if self.pending_content and self.pending_content != self.last_content:
|
|
||||||
await self.update_message(self.pending_content, force=True)
|
|
||||||
|
|
||||||
|
|
||||||
async def send_long_message(
|
async def send_long_message(
|
||||||
bot: Bot,
|
bot: Bot, chat_id: int, text: str, reply_markup: ReplyKeyboardMarkup | None = None
|
||||||
chat_id: int,
|
) -> None:
|
||||||
text: str,
|
|
||||||
reply_markup: ReplyKeyboardMarkup | ReplyKeyboardRemove | None = None,
|
|
||||||
) -> int | None:
|
|
||||||
parts = split_message(text)
|
parts = split_message(text)
|
||||||
first_id: int | None = None
|
|
||||||
for i, part in enumerate(parts):
|
for i, part in enumerate(parts):
|
||||||
is_last = i == len(parts) - 1
|
is_last = i == len(parts) - 1
|
||||||
sent = await bot.send_message(
|
await bot.send_message(
|
||||||
chat_id, html.quote(part), reply_markup=reply_markup if is_last else None
|
chat_id, html.quote(part), reply_markup=reply_markup if is_last else None
|
||||||
)
|
)
|
||||||
if first_id is None:
|
|
||||||
first_id = sent.message_id
|
|
||||||
return first_id
|
|
||||||
|
|
||||||
|
|
||||||
async def process_message_from_web( # noqa: C901, PLR0912, PLR0913, PLR0915
|
async def process_message_from_web( # noqa: C901, PLR0912, PLR0915
|
||||||
convex_user_id: str,
|
convex_user_id: str, text: str, bot: Bot, convex_chat_id: str
|
||||||
text: str,
|
|
||||||
bot: Bot,
|
|
||||||
convex_chat_id: str,
|
|
||||||
images_base64: list[str] | None = None,
|
|
||||||
images_media_types: list[str] | None = None,
|
|
||||||
pending_generation_id: str | None = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
user = await convex.query("users:getById", {"userId": convex_user_id})
|
user = await convex.query("users:getById", {"userId": convex_user_id})
|
||||||
|
|
||||||
if not user or not user.get("geminiApiKey"):
|
if not user or not user.get("geminiApiKey"):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
tg_chat_id = user["telegramChatId"].value if user.get("telegramChatId") else None
|
||||||
is_summarize = text == "/summarize"
|
is_summarize = text == "/summarize"
|
||||||
|
|
||||||
if not is_summarize:
|
|
||||||
user_message_args: dict = {
|
|
||||||
"chatId": convex_chat_id,
|
|
||||||
"role": "user",
|
|
||||||
"content": text,
|
|
||||||
"source": "web",
|
|
||||||
}
|
|
||||||
if images_base64 and images_media_types:
|
|
||||||
user_message_args["imagesBase64"] = images_base64
|
|
||||||
user_message_args["imagesMediaTypes"] = images_media_types
|
|
||||||
await convex.mutation("messages:createFromBackend", user_message_args)
|
|
||||||
|
|
||||||
if pending_generation_id:
|
|
||||||
await convex.mutation(
|
|
||||||
"pendingGenerations:remove", {"id": pending_generation_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
tg_chat_id = user["telegramChatId"].value if user.get("telegramChatId") else None
|
|
||||||
|
|
||||||
if tg_chat_id and not is_summarize:
|
if tg_chat_id and not is_summarize:
|
||||||
if images_base64 and images_media_types:
|
await bot.send_message(
|
||||||
if len(images_base64) == 1:
|
tg_chat_id, f"📱 {html.quote(text)}", reply_markup=ReplyKeyboardRemove()
|
||||||
photo_bytes = base64.b64decode(images_base64[0])
|
)
|
||||||
await bot.send_photo(
|
|
||||||
tg_chat_id,
|
|
||||||
BufferedInputFile(photo_bytes, "photo.jpg"),
|
|
||||||
caption=f"📱 {text}" if text else "📱",
|
|
||||||
reply_markup=ReplyKeyboardRemove(),
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
media = []
|
|
||||||
img_pairs = zip(images_base64, images_media_types, strict=True)
|
|
||||||
for i, (img_b64, _) in enumerate(img_pairs):
|
|
||||||
photo_bytes = base64.b64decode(img_b64)
|
|
||||||
caption = f"📱 {text}" if i == 0 and text else None
|
|
||||||
media.append(
|
|
||||||
InputMediaPhoto(
|
|
||||||
media=BufferedInputFile(photo_bytes, f"photo_{i}.jpg"),
|
|
||||||
caption=caption,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
await bot.send_media_group(tg_chat_id, media)
|
|
||||||
else:
|
|
||||||
await bot.send_message(
|
|
||||||
tg_chat_id, f"📱 {html.quote(text)}", reply_markup=ReplyKeyboardRemove()
|
|
||||||
)
|
|
||||||
|
|
||||||
api_key = user["geminiApiKey"]
|
api_key = user["geminiApiKey"]
|
||||||
model_name = user.get("model", "gemini-3-pro-preview")
|
model_name = user.get("model", "gemini-3-pro-preview")
|
||||||
|
|
||||||
rag_connections = await convex.query(
|
|
||||||
"ragConnections:getActiveForUser", {"userId": convex_user_id}
|
|
||||||
)
|
|
||||||
rag_db_names: list[str] = []
|
|
||||||
if rag_connections:
|
|
||||||
for conn in rag_connections:
|
|
||||||
db = await convex.query(
|
|
||||||
"rag:getDatabaseById", {"ragDatabaseId": conn["ragDatabaseId"]}
|
|
||||||
)
|
|
||||||
if db:
|
|
||||||
rag_db_names.append(db["name"])
|
|
||||||
|
|
||||||
inject_connections = await convex.query(
|
|
||||||
"injectConnections:getActiveForUser", {"userId": convex_user_id}
|
|
||||||
)
|
|
||||||
inject_content = ""
|
|
||||||
if inject_connections:
|
|
||||||
for conn in inject_connections:
|
|
||||||
db = await convex.query(
|
|
||||||
"inject:getDatabaseById", {"injectDatabaseId": conn["injectDatabaseId"]}
|
|
||||||
)
|
|
||||||
if db and db.get("content"):
|
|
||||||
inject_content += db["content"] + "\n\n"
|
|
||||||
inject_content = inject_content.strip()
|
|
||||||
|
|
||||||
assistant_message_id = await convex.mutation(
|
assistant_message_id = await convex.mutation(
|
||||||
"messages:create",
|
"messages:create",
|
||||||
{
|
{
|
||||||
@@ -359,19 +158,8 @@ async def process_message_from_web( # noqa: C901, PLR0912, PLR0913, PLR0915
|
|||||||
)
|
)
|
||||||
|
|
||||||
system_prompt = SUMMARIZE_PROMPT if is_summarize else user.get("systemPrompt")
|
system_prompt = SUMMARIZE_PROMPT if is_summarize else user.get("systemPrompt")
|
||||||
if system_prompt and inject_content:
|
text_agent = create_text_agent(
|
||||||
system_prompt = system_prompt.replace("{theory_database}", inject_content)
|
api_key=api_key, model_name=model_name, system_prompt=system_prompt
|
||||||
text_agent = await create_text_agent(
|
|
||||||
api_key=api_key,
|
|
||||||
model_name=model_name,
|
|
||||||
system_prompt=system_prompt,
|
|
||||||
rag_db_names=rag_db_names or None,
|
|
||||||
)
|
|
||||||
|
|
||||||
agent_deps = (
|
|
||||||
AgentDeps(user_id=convex_user_id, api_key=api_key, rag_db_names=rag_db_names)
|
|
||||||
if rag_db_names
|
|
||||||
else None
|
|
||||||
)
|
)
|
||||||
|
|
||||||
processing_msg = None
|
processing_msg = None
|
||||||
@@ -402,27 +190,19 @@ async def process_message_from_web( # noqa: C901, PLR0912, PLR0913, PLR0915
|
|||||||
chat_images = await fetch_chat_images(convex_chat_id)
|
chat_images = await fetch_chat_images(convex_chat_id)
|
||||||
|
|
||||||
final_answer = await stream_response(
|
final_answer = await stream_response(
|
||||||
text_agent, prompt_text, hist, on_chunk, images=chat_images, deps=agent_deps
|
text_agent, prompt_text, hist, on_chunk, images=chat_images
|
||||||
)
|
)
|
||||||
|
|
||||||
if state:
|
if state:
|
||||||
await state.flush()
|
await state.flush()
|
||||||
|
|
||||||
follow_ups: list[str] = []
|
full_history = [*history, {"role": "assistant", "content": final_answer}]
|
||||||
try:
|
follow_up_model = user.get("followUpModel", "gemini-2.5-flash-lite")
|
||||||
full_history = [*history, {"role": "assistant", "content": final_answer}]
|
follow_up_prompt = user.get("followUpPrompt")
|
||||||
follow_up_model = user.get("followUpModel", "gemini-3.1-flash-lite")
|
follow_up_agent = create_follow_up_agent(
|
||||||
follow_up_prompt = user.get("followUpPrompt")
|
api_key=api_key, model_name=follow_up_model, system_prompt=follow_up_prompt
|
||||||
follow_up_agent = create_follow_up_agent(
|
)
|
||||||
api_key=api_key,
|
follow_ups = await get_follow_ups(follow_up_agent, full_history, chat_images)
|
||||||
model_name=follow_up_model,
|
|
||||||
system_prompt=follow_up_prompt,
|
|
||||||
)
|
|
||||||
follow_ups = await get_follow_ups(
|
|
||||||
follow_up_agent, full_history, chat_images
|
|
||||||
)
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"Follow-up generation failed: {e}")
|
|
||||||
|
|
||||||
if state:
|
if state:
|
||||||
await state.stop_typing()
|
await state.stop_typing()
|
||||||
@@ -455,21 +235,8 @@ async def process_message_from_web( # noqa: C901, PLR0912, PLR0913, PLR0915
|
|||||||
if tg_chat_id and processing_msg:
|
if tg_chat_id and processing_msg:
|
||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
await processing_msg.delete()
|
await processing_msg.delete()
|
||||||
keyboard = (
|
keyboard = make_follow_up_keyboard(follow_ups)
|
||||||
make_follow_up_keyboard(follow_ups)
|
await send_long_message(bot, tg_chat_id, final_answer, keyboard)
|
||||||
if follow_ups
|
|
||||||
else ReplyKeyboardRemove()
|
|
||||||
)
|
|
||||||
sent_id = await send_long_message(bot, tg_chat_id, final_answer, keyboard)
|
|
||||||
if sent_id is not None:
|
|
||||||
with contextlib.suppress(Exception):
|
|
||||||
await convex.mutation(
|
|
||||||
"messages:setTelegramMessageId",
|
|
||||||
{
|
|
||||||
"messageId": assistant_message_id,
|
|
||||||
"telegramMessageId": sent_id,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e: # noqa: BLE001
|
except Exception as e: # noqa: BLE001
|
||||||
if state:
|
if state:
|
||||||
@@ -489,14 +256,8 @@ async def process_message_from_web( # noqa: C901, PLR0912, PLR0913, PLR0915
|
|||||||
await processing_msg.edit_text(truncated)
|
await processing_msg.edit_text(truncated)
|
||||||
|
|
||||||
|
|
||||||
async def process_message( # noqa: C901, PLR0912, PLR0913, PLR0915
|
async def process_message(
|
||||||
user_id: int,
|
user_id: int, text: str, bot: Bot, chat_id: int, *, skip_user_message: bool = False
|
||||||
text: str,
|
|
||||||
bot: Bot,
|
|
||||||
chat_id: int,
|
|
||||||
*,
|
|
||||||
skip_user_message: bool = False,
|
|
||||||
skip_proxy_user_message: bool = False,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
user = await convex.query(
|
user = await convex.query(
|
||||||
"users:getByTelegramId", {"telegramId": ConvexInt64(user_id)}
|
"users:getByTelegramId", {"telegramId": ConvexInt64(user_id)}
|
||||||
@@ -517,199 +278,97 @@ async def process_message( # noqa: C901, PLR0912, PLR0913, PLR0915
|
|||||||
active_chat_id = user["activeChatId"]
|
active_chat_id = user["activeChatId"]
|
||||||
api_key = user["geminiApiKey"]
|
api_key = user["geminiApiKey"]
|
||||||
model_name = user.get("model", "gemini-3-pro-preview")
|
model_name = user.get("model", "gemini-3-pro-preview")
|
||||||
convex_user_id = user["_id"]
|
|
||||||
|
|
||||||
async with get_user_lock(convex_user_id):
|
if not skip_user_message:
|
||||||
proxy_config = get_proxy_config(chat_id)
|
await convex.mutation(
|
||||||
proxy_state: ProxyStreamingState | None = None
|
|
||||||
|
|
||||||
if proxy_config and not skip_proxy_user_message:
|
|
||||||
with contextlib.suppress(Exception):
|
|
||||||
await proxy_config.proxy_bot.send_message(
|
|
||||||
proxy_config.target_chat_id, f"👤 {text}"
|
|
||||||
)
|
|
||||||
await increment_proxy_count(chat_id)
|
|
||||||
proxy_config = get_proxy_config(chat_id)
|
|
||||||
|
|
||||||
rag_connections = await convex.query(
|
|
||||||
"ragConnections:getActiveForUser", {"userId": convex_user_id}
|
|
||||||
)
|
|
||||||
rag_db_names: list[str] = []
|
|
||||||
if rag_connections:
|
|
||||||
for conn in rag_connections:
|
|
||||||
db = await convex.query(
|
|
||||||
"rag:getDatabaseById", {"ragDatabaseId": conn["ragDatabaseId"]}
|
|
||||||
)
|
|
||||||
if db:
|
|
||||||
rag_db_names.append(db["name"])
|
|
||||||
|
|
||||||
inject_connections = await convex.query(
|
|
||||||
"injectConnections:getActiveForUser", {"userId": convex_user_id}
|
|
||||||
)
|
|
||||||
inject_content = ""
|
|
||||||
if inject_connections:
|
|
||||||
for conn in inject_connections:
|
|
||||||
db = await convex.query(
|
|
||||||
"inject:getDatabaseById",
|
|
||||||
{"injectDatabaseId": conn["injectDatabaseId"]},
|
|
||||||
)
|
|
||||||
if db and db.get("content"):
|
|
||||||
inject_content += db["content"] + "\n\n"
|
|
||||||
inject_content = inject_content.strip()
|
|
||||||
|
|
||||||
if not skip_user_message:
|
|
||||||
await convex.mutation(
|
|
||||||
"messages:create",
|
|
||||||
{
|
|
||||||
"chatId": active_chat_id,
|
|
||||||
"role": "user",
|
|
||||||
"content": text,
|
|
||||||
"source": "telegram",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
assistant_message_id = await convex.mutation(
|
|
||||||
"messages:create",
|
"messages:create",
|
||||||
{
|
{
|
||||||
"chatId": active_chat_id,
|
"chatId": active_chat_id,
|
||||||
"role": "assistant",
|
"role": "user",
|
||||||
"content": "",
|
"content": text,
|
||||||
"source": "telegram",
|
"source": "telegram",
|
||||||
"isStreaming": True,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
history = await convex.query(
|
assistant_message_id = await convex.mutation(
|
||||||
"messages:getHistoryForAI", {"chatId": active_chat_id, "limit": 50}
|
"messages:create",
|
||||||
)
|
{
|
||||||
|
"chatId": active_chat_id,
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "",
|
||||||
|
"source": "telegram",
|
||||||
|
"isStreaming": True,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
system_prompt = user.get("systemPrompt")
|
history = await convex.query(
|
||||||
if system_prompt and inject_content:
|
"messages:getHistoryForAI", {"chatId": active_chat_id, "limit": 50}
|
||||||
system_prompt = system_prompt.replace("{theory_database}", inject_content)
|
)
|
||||||
text_agent = await create_text_agent(
|
|
||||||
api_key=api_key,
|
|
||||||
model_name=model_name,
|
|
||||||
system_prompt=system_prompt,
|
|
||||||
rag_db_names=rag_db_names or None,
|
|
||||||
)
|
|
||||||
|
|
||||||
agent_deps = (
|
text_agent = create_text_agent(
|
||||||
AgentDeps(
|
api_key=api_key, model_name=model_name, system_prompt=user.get("systemPrompt")
|
||||||
user_id=convex_user_id, api_key=api_key, rag_db_names=rag_db_names
|
)
|
||||||
)
|
|
||||||
if rag_db_names
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
|
|
||||||
processing_msg = await bot.send_message(chat_id, "...")
|
processing_msg = await bot.send_message(chat_id, "...")
|
||||||
state = StreamingState(bot, chat_id, processing_msg)
|
state = StreamingState(bot, chat_id, processing_msg)
|
||||||
|
|
||||||
if proxy_config:
|
try:
|
||||||
proxy_processing_msg = await proxy_config.proxy_bot.send_message(
|
await state.start_typing()
|
||||||
proxy_config.target_chat_id, "..."
|
|
||||||
)
|
|
||||||
proxy_state = ProxyStreamingState(
|
|
||||||
proxy_config.proxy_bot,
|
|
||||||
proxy_config.target_chat_id,
|
|
||||||
proxy_processing_msg,
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
await state.start_typing()
|
|
||||||
|
|
||||||
async def on_chunk(content: str) -> None:
|
|
||||||
await state.update_message(content)
|
|
||||||
if proxy_state:
|
|
||||||
await proxy_state.update_message(content)
|
|
||||||
await convex.mutation(
|
|
||||||
"messages:update",
|
|
||||||
{"messageId": assistant_message_id, "content": content},
|
|
||||||
)
|
|
||||||
|
|
||||||
chat_images = await fetch_chat_images(active_chat_id)
|
|
||||||
|
|
||||||
final_answer = await stream_response(
|
|
||||||
text_agent,
|
|
||||||
text,
|
|
||||||
history[:-2],
|
|
||||||
on_chunk,
|
|
||||||
images=chat_images,
|
|
||||||
deps=agent_deps,
|
|
||||||
)
|
|
||||||
|
|
||||||
await state.flush()
|
|
||||||
if proxy_state:
|
|
||||||
await proxy_state.flush()
|
|
||||||
|
|
||||||
follow_ups: list[str] = []
|
|
||||||
try:
|
|
||||||
full_history = [
|
|
||||||
*history[:-1],
|
|
||||||
{"role": "assistant", "content": final_answer},
|
|
||||||
]
|
|
||||||
follow_up_model = user.get("followUpModel", "gemini-3.1-flash-lite")
|
|
||||||
follow_up_prompt = user.get("followUpPrompt")
|
|
||||||
follow_up_agent = create_follow_up_agent(
|
|
||||||
api_key=api_key,
|
|
||||||
model_name=follow_up_model,
|
|
||||||
system_prompt=follow_up_prompt,
|
|
||||||
)
|
|
||||||
follow_ups = await get_follow_ups(
|
|
||||||
follow_up_agent, full_history, chat_images
|
|
||||||
)
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"Follow-up generation failed: {e}")
|
|
||||||
|
|
||||||
await state.stop_typing()
|
|
||||||
|
|
||||||
|
async def on_chunk(content: str) -> None:
|
||||||
|
await state.update_message(content)
|
||||||
await convex.mutation(
|
await convex.mutation(
|
||||||
"messages:update",
|
"messages:update",
|
||||||
{
|
{"messageId": assistant_message_id, "content": content},
|
||||||
"messageId": assistant_message_id,
|
|
||||||
"content": final_answer,
|
|
||||||
"followUpOptions": follow_ups,
|
|
||||||
"isStreaming": False,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
with contextlib.suppress(Exception):
|
chat_images = await fetch_chat_images(active_chat_id)
|
||||||
await processing_msg.delete()
|
|
||||||
|
|
||||||
keyboard = (
|
final_answer = await stream_response(
|
||||||
make_follow_up_keyboard(follow_ups)
|
text_agent, text, history[:-2], on_chunk, images=chat_images
|
||||||
if follow_ups
|
)
|
||||||
else ReplyKeyboardRemove()
|
|
||||||
)
|
|
||||||
await send_long_message(bot, chat_id, final_answer, keyboard)
|
|
||||||
|
|
||||||
if proxy_state and proxy_config:
|
await state.flush()
|
||||||
with contextlib.suppress(Exception):
|
|
||||||
await proxy_state.message.delete()
|
|
||||||
parts = split_message(final_answer)
|
|
||||||
for part in parts:
|
|
||||||
await proxy_config.proxy_bot.send_message(
|
|
||||||
proxy_config.target_chat_id, part
|
|
||||||
)
|
|
||||||
await increment_proxy_count(chat_id)
|
|
||||||
|
|
||||||
except Exception as e: # noqa: BLE001
|
full_history = [*history[:-1], {"role": "assistant", "content": final_answer}]
|
||||||
await state.stop_typing()
|
follow_up_model = user.get("followUpModel", "gemini-2.5-flash-lite")
|
||||||
error_msg = f"Error: {e}"
|
follow_up_prompt = user.get("followUpPrompt")
|
||||||
await convex.mutation(
|
follow_up_agent = create_follow_up_agent(
|
||||||
"messages:update",
|
api_key=api_key, model_name=follow_up_model, system_prompt=follow_up_prompt
|
||||||
{
|
)
|
||||||
"messageId": assistant_message_id,
|
follow_ups = await get_follow_ups(follow_up_agent, full_history, chat_images)
|
||||||
"content": error_msg,
|
|
||||||
"isStreaming": False,
|
await state.stop_typing()
|
||||||
},
|
|
||||||
)
|
await convex.mutation(
|
||||||
with contextlib.suppress(Exception):
|
"messages:update",
|
||||||
await processing_msg.edit_text(
|
{
|
||||||
html.quote(error_msg[:TELEGRAM_MAX_LENGTH])
|
"messageId": assistant_message_id,
|
||||||
)
|
"content": final_answer,
|
||||||
if proxy_state:
|
"followUpOptions": follow_ups,
|
||||||
with contextlib.suppress(Exception):
|
"isStreaming": False,
|
||||||
await proxy_state.message.edit_text(error_msg[:TELEGRAM_MAX_LENGTH])
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
with contextlib.suppress(Exception):
|
||||||
|
await processing_msg.delete()
|
||||||
|
|
||||||
|
keyboard = make_follow_up_keyboard(follow_ups)
|
||||||
|
await send_long_message(bot, chat_id, final_answer, keyboard)
|
||||||
|
|
||||||
|
except Exception as e: # noqa: BLE001
|
||||||
|
await state.stop_typing()
|
||||||
|
error_msg = f"Error: {e}"
|
||||||
|
await convex.mutation(
|
||||||
|
"messages:update",
|
||||||
|
{
|
||||||
|
"messageId": assistant_message_id,
|
||||||
|
"content": error_msg,
|
||||||
|
"isStreaming": False,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
with contextlib.suppress(Exception):
|
||||||
|
await processing_msg.edit_text(html.quote(error_msg[:TELEGRAM_MAX_LENGTH]))
|
||||||
|
|
||||||
|
|
||||||
async def send_to_telegram(user_id: int, text: str, bot: Bot) -> None:
|
async def send_to_telegram(user_id: int, text: str, bot: Bot) -> None:
|
||||||
@@ -739,100 +398,6 @@ async def on_text_message(message: types.Message, bot: Bot) -> None:
|
|||||||
await process_message(message.from_user.id, message.text, bot, message.chat.id)
|
await process_message(message.from_user.id, message.text, bot, message.chat.id)
|
||||||
|
|
||||||
|
|
||||||
@router.message(F.media_group_id, F.photo)
|
|
||||||
async def on_album_message(
|
|
||||||
message: types.Message, bot: Bot, album: list[types.Message]
|
|
||||||
) -> None:
|
|
||||||
if not message.from_user:
|
|
||||||
return
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"users:getOrCreate",
|
|
||||||
{
|
|
||||||
"telegramId": ConvexInt64(message.from_user.id),
|
|
||||||
"telegramChatId": ConvexInt64(message.chat.id),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
user = await convex.query(
|
|
||||||
"users:getByTelegramId", {"telegramId": ConvexInt64(message.from_user.id)}
|
|
||||||
)
|
|
||||||
|
|
||||||
if not user or not user.get("activeChatId"):
|
|
||||||
await message.answer("Use /new first to create a chat.")
|
|
||||||
return
|
|
||||||
|
|
||||||
caption = message.caption or "Process the images according to your task"
|
|
||||||
|
|
||||||
images_base64: list[str] = []
|
|
||||||
images_media_types: list[str] = []
|
|
||||||
photos_bytes: list[bytes] = []
|
|
||||||
|
|
||||||
for msg in album:
|
|
||||||
if not msg.photo:
|
|
||||||
continue
|
|
||||||
|
|
||||||
photo = msg.photo[-1]
|
|
||||||
file = await bot.get_file(photo.file_id)
|
|
||||||
if not file.file_path:
|
|
||||||
continue
|
|
||||||
|
|
||||||
buffer = io.BytesIO()
|
|
||||||
await bot.download_file(file.file_path, buffer)
|
|
||||||
image_bytes = buffer.getvalue()
|
|
||||||
photos_bytes.append(image_bytes)
|
|
||||||
images_base64.append(base64.b64encode(image_bytes).decode())
|
|
||||||
|
|
||||||
ext = file.file_path.rsplit(".", 1)[-1].lower()
|
|
||||||
media_type = f"image/{ext}" if ext in ("png", "gif", "webp") else "image/jpeg"
|
|
||||||
images_media_types.append(media_type)
|
|
||||||
|
|
||||||
if not images_base64:
|
|
||||||
await message.answer("Failed to get photos.")
|
|
||||||
return
|
|
||||||
|
|
||||||
proxy_config = get_proxy_config(message.chat.id)
|
|
||||||
if proxy_config:
|
|
||||||
with contextlib.suppress(Exception):
|
|
||||||
media = []
|
|
||||||
for i, photo_bytes in enumerate(photos_bytes):
|
|
||||||
cap = f"👤 {caption}" if i == 0 else None
|
|
||||||
media.append(
|
|
||||||
InputMediaPhoto(
|
|
||||||
media=BufferedInputFile(photo_bytes, f"photo_{i}.jpg"),
|
|
||||||
caption=cap,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
await proxy_config.proxy_bot.send_media_group(
|
|
||||||
proxy_config.target_chat_id, media
|
|
||||||
)
|
|
||||||
await increment_proxy_count(message.chat.id)
|
|
||||||
|
|
||||||
active_chat_id = user["activeChatId"]
|
|
||||||
await convex.mutation(
|
|
||||||
"messages:create",
|
|
||||||
{
|
|
||||||
"chatId": active_chat_id,
|
|
||||||
"role": "user",
|
|
||||||
"content": caption,
|
|
||||||
"source": "telegram",
|
|
||||||
"imagesBase64": images_base64,
|
|
||||||
"imagesMediaTypes": images_media_types,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
schedule_room_uploads(user, images_base64, images_media_types)
|
|
||||||
|
|
||||||
await process_message(
|
|
||||||
message.from_user.id,
|
|
||||||
caption,
|
|
||||||
bot,
|
|
||||||
message.chat.id,
|
|
||||||
skip_user_message=True,
|
|
||||||
skip_proxy_user_message=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@router.message(F.photo)
|
@router.message(F.photo)
|
||||||
async def on_photo_message(message: types.Message, bot: Bot) -> None:
|
async def on_photo_message(message: types.Message, bot: Bot) -> None:
|
||||||
if not message.from_user or not message.photo:
|
if not message.from_user or not message.photo:
|
||||||
@@ -870,16 +435,6 @@ async def on_photo_message(message: types.Message, bot: Bot) -> None:
|
|||||||
ext = file.file_path.rsplit(".", 1)[-1].lower()
|
ext = file.file_path.rsplit(".", 1)[-1].lower()
|
||||||
media_type = f"image/{ext}" if ext in ("png", "gif", "webp") else "image/jpeg"
|
media_type = f"image/{ext}" if ext in ("png", "gif", "webp") else "image/jpeg"
|
||||||
|
|
||||||
proxy_config = get_proxy_config(message.chat.id)
|
|
||||||
if proxy_config:
|
|
||||||
with contextlib.suppress(Exception):
|
|
||||||
await proxy_config.proxy_bot.send_photo(
|
|
||||||
proxy_config.target_chat_id,
|
|
||||||
BufferedInputFile(image_bytes, "photo.jpg"),
|
|
||||||
caption=f"👤 {caption}",
|
|
||||||
)
|
|
||||||
await increment_proxy_count(message.chat.id)
|
|
||||||
|
|
||||||
active_chat_id = user["activeChatId"]
|
active_chat_id = user["activeChatId"]
|
||||||
await convex.mutation(
|
await convex.mutation(
|
||||||
"messages:create",
|
"messages:create",
|
||||||
@@ -893,13 +448,6 @@ async def on_photo_message(message: types.Message, bot: Bot) -> None:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
schedule_room_uploads(user, [image_base64], [media_type])
|
|
||||||
|
|
||||||
await process_message(
|
await process_message(
|
||||||
message.from_user.id,
|
message.from_user.id, caption, bot, message.chat.id, skip_user_message=True
|
||||||
caption,
|
|
||||||
bot,
|
|
||||||
message.chat.id,
|
|
||||||
skip_user_message=True,
|
|
||||||
skip_proxy_user_message=True,
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
from .handler import router
|
|
||||||
|
|
||||||
__all__ = ["router"]
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
import contextlib
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
|
|
||||||
from aiogram import Bot, Router, types
|
|
||||||
from aiogram.client.default import DefaultBotProperties
|
|
||||||
from aiogram.enums import ParseMode
|
|
||||||
from aiogram.filters import Command
|
|
||||||
|
|
||||||
router = Router()
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class ProxyConfig:
|
|
||||||
bot_token: str
|
|
||||||
target_chat_id: int
|
|
||||||
proxy_bot: Bot
|
|
||||||
limit: int = 0
|
|
||||||
message_count: int = field(default=0, init=False)
|
|
||||||
|
|
||||||
|
|
||||||
proxy_states: dict[int, ProxyConfig] = {}
|
|
||||||
|
|
||||||
|
|
||||||
def get_proxy_config(chat_id: int) -> ProxyConfig | None:
|
|
||||||
return proxy_states.get(chat_id)
|
|
||||||
|
|
||||||
|
|
||||||
async def cleanup_proxy(chat_id: int) -> None:
|
|
||||||
config = proxy_states.pop(chat_id, None)
|
|
||||||
if config:
|
|
||||||
await config.proxy_bot.session.close()
|
|
||||||
|
|
||||||
|
|
||||||
async def increment_proxy_count(chat_id: int) -> bool:
|
|
||||||
config = proxy_states.get(chat_id)
|
|
||||||
if not config:
|
|
||||||
return False
|
|
||||||
|
|
||||||
config.message_count += 1
|
|
||||||
|
|
||||||
if config.limit > 0 and config.message_count >= config.limit:
|
|
||||||
await config.proxy_bot.send_message(
|
|
||||||
config.target_chat_id, f"🔗 Proxy finished ({config.limit} messages)"
|
|
||||||
)
|
|
||||||
await cleanup_proxy(chat_id)
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@router.message(Command("proxy"))
|
|
||||||
async def on_proxy(message: types.Message) -> None: # noqa: C901, PLR0912
|
|
||||||
if not message.from_user or not message.text:
|
|
||||||
return
|
|
||||||
|
|
||||||
chat_id = message.chat.id
|
|
||||||
args = message.text.split(maxsplit=3)
|
|
||||||
|
|
||||||
if len(args) == 1:
|
|
||||||
config = get_proxy_config(chat_id)
|
|
||||||
if config:
|
|
||||||
cnt = f" ({config.message_count}/{config.limit})" if config.limit else ""
|
|
||||||
await message.answer(
|
|
||||||
f"Proxy active → chat {config.target_chat_id}{cnt}\n\n"
|
|
||||||
"Use /proxy deactivate to stop."
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
await message.answer(
|
|
||||||
"Usage:\n"
|
|
||||||
"/proxy BOT_TOKEN CHAT_ID [LIMIT] - activate proxy\n"
|
|
||||||
"/proxy deactivate - stop proxy"
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
if args[1].lower() == "deactivate":
|
|
||||||
if chat_id in proxy_states:
|
|
||||||
await cleanup_proxy(chat_id)
|
|
||||||
await message.answer("✓ Proxy deactivated.")
|
|
||||||
else:
|
|
||||||
await message.answer("No active proxy.")
|
|
||||||
return
|
|
||||||
|
|
||||||
if len(args) < 3: # noqa: PLR2004
|
|
||||||
await message.answer("Usage: /proxy BOT_TOKEN CHAT_ID [LIMIT]")
|
|
||||||
return
|
|
||||||
|
|
||||||
bot_token = args[1]
|
|
||||||
try:
|
|
||||||
target_chat_id = int(args[2])
|
|
||||||
except ValueError:
|
|
||||||
await message.answer("Invalid chat ID. Must be a number.")
|
|
||||||
return
|
|
||||||
|
|
||||||
limit = 0
|
|
||||||
if len(args) >= 4: # noqa: PLR2004
|
|
||||||
with contextlib.suppress(ValueError):
|
|
||||||
limit = max(int(args[3]), 0)
|
|
||||||
|
|
||||||
if chat_id in proxy_states:
|
|
||||||
await cleanup_proxy(chat_id)
|
|
||||||
|
|
||||||
try:
|
|
||||||
proxy_bot = Bot(
|
|
||||||
token=bot_token, default=DefaultBotProperties(parse_mode=ParseMode.HTML)
|
|
||||||
)
|
|
||||||
bot_info = await proxy_bot.get_me()
|
|
||||||
|
|
||||||
try:
|
|
||||||
await proxy_bot.send_message(target_chat_id, "🔗 Proxy connected")
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
await proxy_bot.session.close()
|
|
||||||
await message.answer(f"Cannot send to chat {target_chat_id}: {e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
proxy_states[chat_id] = ProxyConfig(
|
|
||||||
bot_token=bot_token,
|
|
||||||
target_chat_id=target_chat_id,
|
|
||||||
proxy_bot=proxy_bot,
|
|
||||||
limit=limit,
|
|
||||||
)
|
|
||||||
|
|
||||||
limit_text = f"\nLimit: {limit} messages" if limit > 0 else ""
|
|
||||||
await message.answer(
|
|
||||||
f"✓ Proxy activated via @{bot_info.username}\n"
|
|
||||||
f"Target: {target_chat_id}{limit_text}\n\n"
|
|
||||||
"All messages will be forwarded."
|
|
||||||
)
|
|
||||||
await message.delete()
|
|
||||||
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
await message.answer(f"Invalid bot token: {e}")
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
from aiogram import Router
|
|
||||||
|
|
||||||
from .collection import router as collection_router
|
|
||||||
from .handler import router as command_router
|
|
||||||
|
|
||||||
router = Router()
|
|
||||||
|
|
||||||
router.include_routers(command_router, collection_router)
|
|
||||||
|
|
||||||
__all__ = ["router"]
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
import io
|
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
from aiogram import Bot, F, Router, types
|
|
||||||
from aiogram.filters import Filter
|
|
||||||
from convex import ConvexInt64
|
|
||||||
|
|
||||||
from utils import env
|
|
||||||
from utils.convex import ConvexClient
|
|
||||||
|
|
||||||
router = Router()
|
|
||||||
convex = ConvexClient(env.convex_url)
|
|
||||||
|
|
||||||
|
|
||||||
class InRagCollectionMode(Filter):
|
|
||||||
async def __call__(self, message: types.Message) -> bool | dict:
|
|
||||||
if not message.from_user:
|
|
||||||
return False
|
|
||||||
|
|
||||||
user = await convex.query(
|
|
||||||
"users:getByTelegramId", {"telegramId": ConvexInt64(message.from_user.id)}
|
|
||||||
)
|
|
||||||
|
|
||||||
if not user or not user.get("ragCollectionMode"):
|
|
||||||
return False
|
|
||||||
|
|
||||||
return {"rag_user": user, "rag_collection_mode": user["ragCollectionMode"]}
|
|
||||||
|
|
||||||
|
|
||||||
in_collection_mode = InRagCollectionMode()
|
|
||||||
|
|
||||||
|
|
||||||
@router.message(in_collection_mode, F.text & ~F.text.startswith("/"))
|
|
||||||
async def on_text_in_collection_mode(
|
|
||||||
message: types.Message, rag_user: dict, rag_collection_mode: dict
|
|
||||||
) -> None:
|
|
||||||
if not message.text:
|
|
||||||
return
|
|
||||||
|
|
||||||
api_key = rag_user.get("geminiApiKey")
|
|
||||||
if not api_key:
|
|
||||||
return
|
|
||||||
|
|
||||||
await convex.action(
|
|
||||||
"rag:addContent",
|
|
||||||
{
|
|
||||||
"userId": rag_user["_id"],
|
|
||||||
"ragDatabaseId": rag_collection_mode["ragDatabaseId"],
|
|
||||||
"apiKey": api_key,
|
|
||||||
"text": message.text,
|
|
||||||
"key": str(uuid4()),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.answer("✓ Text added to knowledge base.")
|
|
||||||
|
|
||||||
|
|
||||||
@router.message(in_collection_mode, F.document)
|
|
||||||
async def on_document_in_collection_mode(
|
|
||||||
message: types.Message, bot: Bot, rag_user: dict, rag_collection_mode: dict
|
|
||||||
) -> None:
|
|
||||||
if not message.document:
|
|
||||||
return
|
|
||||||
|
|
||||||
api_key = rag_user.get("geminiApiKey")
|
|
||||||
if not api_key:
|
|
||||||
return
|
|
||||||
|
|
||||||
doc = message.document
|
|
||||||
if not doc.file_name or not doc.file_name.endswith(".txt"):
|
|
||||||
await message.answer("Only .txt files are supported for RAG.")
|
|
||||||
return
|
|
||||||
|
|
||||||
file = await bot.get_file(doc.file_id)
|
|
||||||
if not file.file_path:
|
|
||||||
await message.answer("Failed to download file.")
|
|
||||||
return
|
|
||||||
|
|
||||||
buffer = io.BytesIO()
|
|
||||||
await bot.download_file(file.file_path, buffer)
|
|
||||||
text = buffer.getvalue().decode("utf-8")
|
|
||||||
|
|
||||||
await convex.action(
|
|
||||||
"rag:addContent",
|
|
||||||
{
|
|
||||||
"userId": rag_user["_id"],
|
|
||||||
"ragDatabaseId": rag_collection_mode["ragDatabaseId"],
|
|
||||||
"apiKey": api_key,
|
|
||||||
"text": text,
|
|
||||||
"key": doc.file_name,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.answer(f"✓ File '{doc.file_name}' added to knowledge base.")
|
|
||||||
@@ -1,217 +0,0 @@
|
|||||||
from aiogram import Router, types
|
|
||||||
from aiogram.filters import Command
|
|
||||||
from convex import ConvexInt64
|
|
||||||
|
|
||||||
from utils import env
|
|
||||||
from utils.convex import ConvexClient
|
|
||||||
|
|
||||||
router = Router()
|
|
||||||
convex = ConvexClient(env.convex_url)
|
|
||||||
|
|
||||||
|
|
||||||
@router.message(Command("rag"))
|
|
||||||
async def on_rag(message: types.Message) -> None: # noqa: C901, PLR0911
|
|
||||||
if not message.from_user or not message.text:
|
|
||||||
return
|
|
||||||
|
|
||||||
args = message.text.split()[1:]
|
|
||||||
|
|
||||||
if not args:
|
|
||||||
await show_usage(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
user = await convex.query(
|
|
||||||
"users:getByTelegramId", {"telegramId": ConvexInt64(message.from_user.id)}
|
|
||||||
)
|
|
||||||
|
|
||||||
if not user:
|
|
||||||
await message.answer("Use /apikey first to set your Gemini API key.")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not user.get("geminiApiKey"):
|
|
||||||
await message.answer("Use /apikey first to set your Gemini API key.")
|
|
||||||
return
|
|
||||||
|
|
||||||
user_id = user["_id"]
|
|
||||||
|
|
||||||
if args[0] == "list":
|
|
||||||
await list_databases(message, user_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
if args[0] == "save":
|
|
||||||
await save_collection(message, user_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
db_name = args[0]
|
|
||||||
|
|
||||||
if len(args) < 2: # noqa: PLR2004
|
|
||||||
await show_db_usage(message, db_name)
|
|
||||||
return
|
|
||||||
|
|
||||||
command = args[1]
|
|
||||||
|
|
||||||
if command == "add":
|
|
||||||
await start_collection(message, user_id, db_name)
|
|
||||||
elif command == "connect":
|
|
||||||
await connect_database(message, user_id, db_name)
|
|
||||||
elif command == "disconnect":
|
|
||||||
await disconnect_database(message, user_id, db_name)
|
|
||||||
elif command == "clear":
|
|
||||||
await clear_database(message, user_id, user["geminiApiKey"], db_name)
|
|
||||||
else:
|
|
||||||
await show_db_usage(message, db_name)
|
|
||||||
|
|
||||||
|
|
||||||
async def show_usage(message: types.Message) -> None:
|
|
||||||
await message.answer(
|
|
||||||
"<b>RAG Commands:</b>\n\n"
|
|
||||||
"<code>/rag list</code> - List your RAG databases\n"
|
|
||||||
"<code>/rag save</code> - Exit collection mode\n\n"
|
|
||||||
"<code>/rag <name> add</code> - Start adding content\n"
|
|
||||||
"<code>/rag <name> connect</code> - Connect to all chats\n"
|
|
||||||
"<code>/rag <name> disconnect</code> - Disconnect\n"
|
|
||||||
"<code>/rag <name> clear</code> - Delete database",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def show_db_usage(message: types.Message, db_name: str) -> None:
|
|
||||||
await message.answer(
|
|
||||||
f"<b>Commands for '{db_name}':</b>\n\n"
|
|
||||||
f"<code>/rag {db_name} add</code> - Start adding content\n"
|
|
||||||
f"<code>/rag {db_name} connect</code> - Connect to all chats\n"
|
|
||||||
f"<code>/rag {db_name} disconnect</code> - Disconnect\n"
|
|
||||||
f"<code>/rag {db_name} clear</code> - Delete database",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def list_databases(message: types.Message, user_id: str) -> None:
|
|
||||||
databases = await convex.query("rag:listDatabases", {"userId": user_id})
|
|
||||||
connections = await convex.query(
|
|
||||||
"ragConnections:getActiveForUser", {"userId": user_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
connected_db_ids = {conn["ragDatabaseId"] for conn in connections}
|
|
||||||
|
|
||||||
if not databases:
|
|
||||||
await message.answer(
|
|
||||||
"No RAG databases found.\n\nCreate one with: <code>/rag mydb add</code>",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
lines = ["<b>Your RAG databases:</b>\n"]
|
|
||||||
for db in databases:
|
|
||||||
status = " (connected)" if db["_id"] in connected_db_ids else ""
|
|
||||||
lines.append(f"• {db['name']}{status}")
|
|
||||||
|
|
||||||
await message.answer("\n".join(lines), parse_mode="HTML")
|
|
||||||
|
|
||||||
|
|
||||||
async def start_collection(message: types.Message, user_id: str, db_name: str) -> None:
|
|
||||||
collection_mode = await convex.query(
|
|
||||||
"users:getRagCollectionMode", {"userId": user_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
if collection_mode:
|
|
||||||
await message.answer(
|
|
||||||
"Already in collection mode. Use <code>/rag save</code> to exit first.",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
db_id = await convex.mutation(
|
|
||||||
"rag:createDatabase", {"userId": user_id, "name": db_name}
|
|
||||||
)
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"users:startRagCollectionMode", {"userId": user_id, "ragDatabaseId": db_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.answer(
|
|
||||||
f"📚 <b>Collection mode started for '{db_name}'</b>\n\n"
|
|
||||||
"Send text messages or .txt files to add content.\n"
|
|
||||||
"Use <code>/rag save</code> when done.",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def save_collection(message: types.Message, user_id: str) -> None:
|
|
||||||
collection_mode = await convex.query(
|
|
||||||
"users:getRagCollectionMode", {"userId": user_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
if not collection_mode:
|
|
||||||
await message.answer("Not in collection mode.")
|
|
||||||
return
|
|
||||||
|
|
||||||
db = await convex.query(
|
|
||||||
"rag:getDatabaseById", {"ragDatabaseId": collection_mode["ragDatabaseId"]}
|
|
||||||
)
|
|
||||||
db_name = db["name"] if db else "database"
|
|
||||||
|
|
||||||
await convex.mutation("users:stopRagCollectionMode", {"userId": user_id})
|
|
||||||
|
|
||||||
await message.answer(
|
|
||||||
f"✓ Collection mode ended for '{db_name}'.\n\n"
|
|
||||||
f"Connect it with: <code>/rag {db_name} connect</code>",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def connect_database(message: types.Message, user_id: str, db_name: str) -> None:
|
|
||||||
db = await convex.query("rag:getDatabase", {"userId": user_id, "name": db_name})
|
|
||||||
|
|
||||||
if not db:
|
|
||||||
await message.answer(
|
|
||||||
f"Database '{db_name}' not found.\n"
|
|
||||||
f"Create it with: <code>/rag {db_name} add</code>",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"ragConnections:connect",
|
|
||||||
{"userId": user_id, "ragDatabaseId": db["_id"], "isGlobal": True},
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.answer(f"✓ '{db_name}' connected to all your chats.")
|
|
||||||
|
|
||||||
|
|
||||||
async def disconnect_database(
|
|
||||||
message: types.Message, user_id: str, db_name: str
|
|
||||||
) -> None:
|
|
||||||
db = await convex.query("rag:getDatabase", {"userId": user_id, "name": db_name})
|
|
||||||
|
|
||||||
if not db:
|
|
||||||
await message.answer(f"Database '{db_name}' not found.")
|
|
||||||
return
|
|
||||||
|
|
||||||
result = await convex.mutation(
|
|
||||||
"ragConnections:disconnect", {"userId": user_id, "ragDatabaseId": db["_id"]}
|
|
||||||
)
|
|
||||||
|
|
||||||
if result:
|
|
||||||
await message.answer(f"✓ '{db_name}' disconnected.")
|
|
||||||
else:
|
|
||||||
await message.answer(f"'{db_name}' was not connected.")
|
|
||||||
|
|
||||||
|
|
||||||
async def clear_database(
|
|
||||||
message: types.Message, user_id: str, api_key: str, db_name: str
|
|
||||||
) -> None:
|
|
||||||
db = await convex.query("rag:getDatabase", {"userId": user_id, "name": db_name})
|
|
||||||
|
|
||||||
if not db:
|
|
||||||
await message.answer(f"Database '{db_name}' not found.")
|
|
||||||
return
|
|
||||||
|
|
||||||
result = await convex.action(
|
|
||||||
"rag:deleteDatabase", {"userId": user_id, "name": db_name, "apiKey": api_key}
|
|
||||||
)
|
|
||||||
|
|
||||||
if result:
|
|
||||||
await message.answer(f"✓ '{db_name}' deleted.")
|
|
||||||
else:
|
|
||||||
await message.answer(f"Failed to delete '{db_name}'.")
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from .handler import router
|
|
||||||
|
|
||||||
__all__ = ["router"]
|
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
from aiogram import Router, types
|
|
||||||
from aiogram.filters import Command
|
|
||||||
from convex import ConvexInt64
|
|
||||||
|
|
||||||
from utils import env
|
|
||||||
from utils.collaborative import CollaborativeHTTPError, get_collaborative_client
|
|
||||||
from utils.convex import ConvexClient
|
|
||||||
from utils.logging import logger
|
|
||||||
|
|
||||||
router = Router()
|
|
||||||
convex = ConvexClient(env.convex_url)
|
|
||||||
|
|
||||||
|
|
||||||
@router.message(Command("room"))
|
|
||||||
async def on_room(message: types.Message) -> None: # noqa: C901
|
|
||||||
if not message.from_user or not message.text:
|
|
||||||
return
|
|
||||||
|
|
||||||
if not env.collaborative.enabled:
|
|
||||||
await message.answer("Collaborative Solver is not configured on this instance.")
|
|
||||||
return
|
|
||||||
|
|
||||||
args = message.text.split()[1:]
|
|
||||||
|
|
||||||
if not args:
|
|
||||||
await show_usage(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
user = await convex.query(
|
|
||||||
"users:getByTelegramId", {"telegramId": ConvexInt64(message.from_user.id)}
|
|
||||||
)
|
|
||||||
if not user:
|
|
||||||
await convex.mutation(
|
|
||||||
"users:getOrCreate",
|
|
||||||
{
|
|
||||||
"telegramId": ConvexInt64(message.from_user.id),
|
|
||||||
"telegramChatId": ConvexInt64(message.chat.id),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
user = await convex.query(
|
|
||||||
"users:getByTelegramId", {"telegramId": ConvexInt64(message.from_user.id)}
|
|
||||||
)
|
|
||||||
if not user:
|
|
||||||
await message.answer("User not found.")
|
|
||||||
return
|
|
||||||
|
|
||||||
user_id = user["_id"]
|
|
||||||
sub = args[0]
|
|
||||||
|
|
||||||
if sub == "create":
|
|
||||||
await create_room(message, user_id)
|
|
||||||
elif sub == "join":
|
|
||||||
if len(args) < 2: # noqa: PLR2004
|
|
||||||
await message.answer(
|
|
||||||
"Usage: <code>/room join <pin></code>", parse_mode="HTML"
|
|
||||||
)
|
|
||||||
return
|
|
||||||
await join_room(message, user_id, args[1].strip())
|
|
||||||
elif sub == "leave":
|
|
||||||
await leave_room(message, user_id, user.get("collaborativeRoom"))
|
|
||||||
elif sub == "status":
|
|
||||||
await show_status(message, user_id, user.get("collaborativeRoom"))
|
|
||||||
else:
|
|
||||||
await show_usage(message)
|
|
||||||
|
|
||||||
|
|
||||||
async def show_usage(message: types.Message) -> None:
|
|
||||||
await message.answer(
|
|
||||||
"<b>Room commands:</b>\n\n"
|
|
||||||
"<code>/room create</code> - Create a new room and get a PIN\n"
|
|
||||||
"<code>/room join <pin></code> - Join an existing room\n"
|
|
||||||
"<code>/room leave</code> - Leave current room\n"
|
|
||||||
"<code>/room status</code> - Show current room status",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def create_room(message: types.Message, user_id: str) -> None:
|
|
||||||
client = get_collaborative_client()
|
|
||||||
try:
|
|
||||||
resp = await client.create_room()
|
|
||||||
except (CollaborativeHTTPError, Exception) as e: # noqa: BLE001
|
|
||||||
logger.error(f"Failed to create room: {e}")
|
|
||||||
await message.answer(f"Failed to create room: {e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
pin = resp.get("pin", "")
|
|
||||||
creator_token = resp.get("creator_token", "")
|
|
||||||
|
|
||||||
if not pin:
|
|
||||||
await message.answer("Got invalid response from solver.")
|
|
||||||
return
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"users:setCollaborativeRoom",
|
|
||||||
{
|
|
||||||
"userId": user_id,
|
|
||||||
"pin": pin,
|
|
||||||
"creatorToken": creator_token,
|
|
||||||
"lastSeenSheetId": 0,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.answer(
|
|
||||||
f"<b>Room created!</b>\n\n"
|
|
||||||
f"PIN: <code>{pin}</code>\n\n"
|
|
||||||
f"Share this PIN with others so they can join with "
|
|
||||||
f"<code>/room join {pin}</code>.",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def join_room(message: types.Message, user_id: str, pin: str) -> None:
|
|
||||||
client = get_collaborative_client()
|
|
||||||
try:
|
|
||||||
sheets_resp = await client.get_sheets(pin)
|
|
||||||
except CollaborativeHTTPError as e:
|
|
||||||
if e.status_code == 404: # noqa: PLR2004
|
|
||||||
await message.answer(
|
|
||||||
f"Room <code>{pin}</code> not found.", parse_mode="HTML"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
await message.answer(f"Failed to join room: {e}")
|
|
||||||
return
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.error(f"Failed to join room: {e}")
|
|
||||||
await message.answer(f"Failed to join room: {e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
sheets = sheets_resp.get("sheets", []) or []
|
|
||||||
last_sheet_id = max((int(s["id"]) for s in sheets), default=0)
|
|
||||||
|
|
||||||
await convex.mutation(
|
|
||||||
"users:setCollaborativeRoom",
|
|
||||||
{"userId": user_id, "pin": pin, "lastSeenSheetId": last_sheet_id},
|
|
||||||
)
|
|
||||||
|
|
||||||
await message.answer(
|
|
||||||
f"Joined room <code>{pin}</code> ({len(sheets)} sheet(s) so far).\n"
|
|
||||||
f"New sheets will appear in the web UI.",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def leave_room(message: types.Message, user_id: str, room: dict | None) -> None:
|
|
||||||
if not room:
|
|
||||||
await message.answer("Not in any room.")
|
|
||||||
return
|
|
||||||
|
|
||||||
pin = room.get("pin", "")
|
|
||||||
creator_token = room.get("creatorToken")
|
|
||||||
|
|
||||||
if creator_token:
|
|
||||||
client = get_collaborative_client()
|
|
||||||
try:
|
|
||||||
await client.delete_room(pin, creator_token)
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"Failed to delete room {pin}: {e}")
|
|
||||||
|
|
||||||
await convex.mutation("users:clearCollaborativeRoom", {"userId": user_id})
|
|
||||||
await message.answer(f"Left room <code>{pin}</code>.", parse_mode="HTML")
|
|
||||||
|
|
||||||
|
|
||||||
async def show_status(message: types.Message, user_id: str, room: dict | None) -> None:
|
|
||||||
if not room:
|
|
||||||
await message.answer(
|
|
||||||
"Not in any room.\n\nUse <code>/room create</code> or "
|
|
||||||
"<code>/room join <pin></code>.",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
pin = room.get("pin", "")
|
|
||||||
client = get_collaborative_client()
|
|
||||||
info: dict = {}
|
|
||||||
sheets_count: int | str = "?"
|
|
||||||
try:
|
|
||||||
info = await client.get_room(pin)
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"get_room failed: {e}")
|
|
||||||
try:
|
|
||||||
sheets_resp = await client.get_sheets(pin)
|
|
||||||
sheets_count = len(sheets_resp.get("sheets", []) or [])
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"get_sheets failed: {e}")
|
|
||||||
|
|
||||||
queue = await convex.query("collaborative:queueDepthForUser", {"userId": user_id})
|
|
||||||
role = "creator" if room.get("creatorToken") else "member"
|
|
||||||
last_seen = room.get("lastSeenSheetId", 0)
|
|
||||||
|
|
||||||
await message.answer(
|
|
||||||
f"<b>Room <code>{pin}</code></b> ({role})\n"
|
|
||||||
f"Members: {info.get('members', '?')}\n"
|
|
||||||
f"Processing: {info.get('processing', False)}\n"
|
|
||||||
f"Sheets in room: {sheets_count}\n"
|
|
||||||
f"Last seen sheet id: {last_seen}\n\n"
|
|
||||||
f"<b>Upload queue:</b>\n"
|
|
||||||
f" pending: {queue.get('pending', 0)}\n"
|
|
||||||
f" uploading: {queue.get('uploading', 0)}\n"
|
|
||||||
f" failed: {queue.get('failed', 0)}",
|
|
||||||
parse_mode="HTML",
|
|
||||||
)
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
from .agent import (
|
from .agent import (
|
||||||
AgentDeps,
|
|
||||||
ImageData,
|
ImageData,
|
||||||
StreamCallback,
|
StreamCallback,
|
||||||
create_follow_up_agent,
|
create_follow_up_agent,
|
||||||
@@ -13,7 +12,6 @@ __all__ = [
|
|||||||
"DEFAULT_FOLLOW_UP",
|
"DEFAULT_FOLLOW_UP",
|
||||||
"PRESETS",
|
"PRESETS",
|
||||||
"SUMMARIZE_PROMPT",
|
"SUMMARIZE_PROMPT",
|
||||||
"AgentDeps",
|
|
||||||
"ImageData",
|
"ImageData",
|
||||||
"StreamCallback",
|
"StreamCallback",
|
||||||
"create_follow_up_agent",
|
"create_follow_up_agent",
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
import time
|
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Awaitable, Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
@@ -9,131 +7,16 @@ from pydantic_ai import (
|
|||||||
ModelMessage,
|
ModelMessage,
|
||||||
ModelRequest,
|
ModelRequest,
|
||||||
ModelResponse,
|
ModelResponse,
|
||||||
RunContext,
|
|
||||||
TextPart,
|
TextPart,
|
||||||
UserPromptPart,
|
UserPromptPart,
|
||||||
)
|
)
|
||||||
from pydantic_ai.models import Model
|
|
||||||
from pydantic_ai.models.fallback import FallbackModel
|
|
||||||
from pydantic_ai.models.google import GoogleModel
|
from pydantic_ai.models.google import GoogleModel
|
||||||
from pydantic_ai.providers.google import GoogleProvider
|
from pydantic_ai.providers.google import GoogleProvider
|
||||||
|
|
||||||
from utils import env
|
|
||||||
from utils.convex import ConvexClient
|
|
||||||
from utils.logging import logger
|
|
||||||
|
|
||||||
from .models import FollowUpOptions
|
from .models import FollowUpOptions
|
||||||
from .prompts import DEFAULT_FOLLOW_UP
|
from .prompts import DEFAULT_FOLLOW_UP
|
||||||
|
|
||||||
StreamCallback = Callable[[str], Awaitable[None]]
|
StreamCallback = Callable[[str], Awaitable[None]]
|
||||||
convex = ConvexClient(env.convex_url)
|
|
||||||
|
|
||||||
CONTENT_FALLBACK_CHAIN = ["gemini-3.5-pro", "gemini-3.1-pro", "gemini-3.5-flash"]
|
|
||||||
FOLLOW_UP_FALLBACK_CHAIN = [
|
|
||||||
"gemini-3.5-flash",
|
|
||||||
"gemini-3.1-flash-lite",
|
|
||||||
"gemini-3.5-flash-lite",
|
|
||||||
]
|
|
||||||
MODELS_CACHE_TTL_SECONDS = 600.0
|
|
||||||
|
|
||||||
_models_cache: dict[str, tuple[float, set[str]]] = {}
|
|
||||||
|
|
||||||
|
|
||||||
def _strip_preview(name: str) -> str:
|
|
||||||
return (
|
|
||||||
name.removesuffix("-preview").rstrip("-") if name.endswith("-preview") else name
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _dedup(names: list[str]) -> list[str]:
|
|
||||||
seen: set[str] = set()
|
|
||||||
result: list[str] = []
|
|
||||||
for name in names:
|
|
||||||
if name and name not in seen:
|
|
||||||
seen.add(name)
|
|
||||||
result.append(name)
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def _fetch_google_models(api_key: str) -> set[str]:
|
|
||||||
names: set[str] = set()
|
|
||||||
try:
|
|
||||||
from google import genai # noqa: PLC0415
|
|
||||||
|
|
||||||
client = genai.Client(api_key=api_key)
|
|
||||||
for model in client.models.list():
|
|
||||||
name = (model.name or "").removeprefix("models/")
|
|
||||||
actions = getattr(model, "supported_actions", None) or getattr(
|
|
||||||
model, "supported_generation_methods", None
|
|
||||||
)
|
|
||||||
if actions and "generateContent" not in actions:
|
|
||||||
continue
|
|
||||||
if name:
|
|
||||||
names.add(name)
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"Failed to list Google models: {e}")
|
|
||||||
return names
|
|
||||||
|
|
||||||
|
|
||||||
async def _available_google_models(api_key: str) -> set[str]:
|
|
||||||
cached = _models_cache.get(api_key)
|
|
||||||
now = time.monotonic()
|
|
||||||
if cached and (now - cached[0]) < MODELS_CACHE_TTL_SECONDS:
|
|
||||||
return cached[1]
|
|
||||||
names = await asyncio.to_thread(_fetch_google_models, api_key)
|
|
||||||
if names:
|
|
||||||
_models_cache[api_key] = (now, names)
|
|
||||||
return names
|
|
||||||
|
|
||||||
|
|
||||||
def _pick_from_available(available: set[str]) -> list[str]:
|
|
||||||
gemini = sorted(
|
|
||||||
n for n in available if n.startswith("gemini-") and "preview" not in n
|
|
||||||
)
|
|
||||||
pros = [n for n in gemini if "pro" in n]
|
|
||||||
flashes = [n for n in gemini if "flash" in n]
|
|
||||||
picked = _dedup([*pros[:2], *flashes[:2]])
|
|
||||||
return picked or sorted(available)[:3]
|
|
||||||
|
|
||||||
|
|
||||||
def _anthropic_model() -> Model | None:
|
|
||||||
key = env.anthropic_api_key.get_secret_value()
|
|
||||||
if not key:
|
|
||||||
return None
|
|
||||||
from pydantic_ai.models.anthropic import AnthropicModel # noqa: PLC0415
|
|
||||||
from pydantic_ai.providers.anthropic import AnthropicProvider # noqa: PLC0415
|
|
||||||
|
|
||||||
return AnthropicModel(env.anthropic_model, provider=AnthropicProvider(api_key=key))
|
|
||||||
|
|
||||||
|
|
||||||
def _as_model(models: list[Model]) -> Model:
|
|
||||||
return models[0] if len(models) == 1 else FallbackModel(*models)
|
|
||||||
|
|
||||||
|
|
||||||
async def build_content_model(api_key: str, requested_model: str) -> Model:
|
|
||||||
candidates = _dedup(
|
|
||||||
[requested_model, _strip_preview(requested_model), *CONTENT_FALLBACK_CHAIN]
|
|
||||||
)
|
|
||||||
available = await _available_google_models(api_key)
|
|
||||||
if available:
|
|
||||||
live = [name for name in candidates if name in available]
|
|
||||||
candidates = live or _pick_from_available(available) or candidates
|
|
||||||
|
|
||||||
provider = GoogleProvider(api_key=api_key)
|
|
||||||
models: list[Model] = [GoogleModel(name, provider=provider) for name in candidates]
|
|
||||||
anthropic = _anthropic_model()
|
|
||||||
if anthropic:
|
|
||||||
models.append(anthropic)
|
|
||||||
return _as_model(models)
|
|
||||||
|
|
||||||
|
|
||||||
def build_follow_up_model(api_key: str, requested_model: str) -> Model:
|
|
||||||
candidates = _dedup(
|
|
||||||
[requested_model, _strip_preview(requested_model), *FOLLOW_UP_FALLBACK_CHAIN]
|
|
||||||
)
|
|
||||||
provider = GoogleProvider(api_key=api_key)
|
|
||||||
models: list[Model] = [GoogleModel(name, provider=provider) for name in candidates]
|
|
||||||
return _as_model(models)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -142,84 +25,34 @@ class ImageData:
|
|||||||
media_type: str
|
media_type: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class AgentDeps:
|
|
||||||
user_id: str
|
|
||||||
api_key: str
|
|
||||||
rag_db_names: list[str]
|
|
||||||
|
|
||||||
|
|
||||||
LATEX_INSTRUCTION = "For math, use LaTeX: $...$ inline, $$...$$ display."
|
LATEX_INSTRUCTION = "For math, use LaTeX: $...$ inline, $$...$$ display."
|
||||||
|
|
||||||
DEFAULT_SYSTEM_PROMPT = (
|
DEFAULT_SYSTEM_PROMPT = (
|
||||||
"You are a helpful AI assistant. Provide clear, concise answers."
|
"You are a helpful AI assistant. Provide clear, concise answers."
|
||||||
)
|
)
|
||||||
|
|
||||||
RAG_SYSTEM_ADDITION = (
|
|
||||||
" You have access to a knowledge base. Use the search_knowledge_base tool "
|
|
||||||
"to find relevant information when the user asks about topics that might "
|
|
||||||
"be covered in the knowledge base."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
def create_text_agent(
|
||||||
async def create_text_agent(
|
|
||||||
api_key: str,
|
api_key: str,
|
||||||
model_name: str = "gemini-3-pro-preview",
|
model_name: str = "gemini-3-pro-preview",
|
||||||
system_prompt: str | None = None,
|
system_prompt: str | None = None,
|
||||||
rag_db_names: list[str] | None = None,
|
) -> Agent[None, str]:
|
||||||
) -> Agent[AgentDeps, str] | Agent[None, str]:
|
provider = GoogleProvider(api_key=api_key)
|
||||||
model = await build_content_model(api_key, model_name)
|
model = GoogleModel(model_name, provider=provider)
|
||||||
base_prompt = system_prompt or DEFAULT_SYSTEM_PROMPT
|
base_prompt = system_prompt or DEFAULT_SYSTEM_PROMPT
|
||||||
|
|
||||||
if rag_db_names:
|
|
||||||
full_prompt = f"{base_prompt}{RAG_SYSTEM_ADDITION} {LATEX_INSTRUCTION}"
|
|
||||||
agent: Agent[AgentDeps, str] = Agent(
|
|
||||||
model, instructions=full_prompt, deps_type=AgentDeps
|
|
||||||
)
|
|
||||||
|
|
||||||
@agent.tool
|
|
||||||
async def search_knowledge_base(ctx: RunContext[AgentDeps], query: str) -> str:
|
|
||||||
"""Search the user's knowledge base for relevant information.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
ctx: The run context containing user dependencies.
|
|
||||||
query: The search query to find relevant information.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Relevant text from the knowledge base.
|
|
||||||
"""
|
|
||||||
logger.info(f"Searching knowledge base for {query}")
|
|
||||||
result = await convex.action(
|
|
||||||
"rag:searchMultiple",
|
|
||||||
{
|
|
||||||
"userId": ctx.deps.user_id,
|
|
||||||
"dbNames": ctx.deps.rag_db_names,
|
|
||||||
"apiKey": ctx.deps.api_key,
|
|
||||||
"query": query,
|
|
||||||
"limit": 5,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if result and result.get("text"):
|
|
||||||
return f"Knowledge base results:\n\n{result['text']}"
|
|
||||||
return "No relevant information found in the knowledge base."
|
|
||||||
|
|
||||||
return agent
|
|
||||||
|
|
||||||
full_prompt = f"{base_prompt} {LATEX_INSTRUCTION}"
|
full_prompt = f"{base_prompt} {LATEX_INSTRUCTION}"
|
||||||
return Agent(model, instructions=full_prompt)
|
return Agent(model, instructions=full_prompt)
|
||||||
|
|
||||||
|
|
||||||
def create_follow_up_agent(
|
def create_follow_up_agent(
|
||||||
api_key: str,
|
api_key: str,
|
||||||
model_name: str = "gemini-3.1-flash-lite-preview",
|
model_name: str = "gemini-2.5-flash-lite",
|
||||||
system_prompt: str | None = None,
|
system_prompt: str | None = None,
|
||||||
) -> Agent[None, FollowUpOptions]:
|
) -> Agent[None, FollowUpOptions]:
|
||||||
model = build_follow_up_model(api_key, model_name)
|
provider = GoogleProvider(api_key=api_key)
|
||||||
|
model = GoogleModel(model_name, provider=provider)
|
||||||
prompt = system_prompt or DEFAULT_FOLLOW_UP
|
prompt = system_prompt or DEFAULT_FOLLOW_UP
|
||||||
agent: Agent[None, FollowUpOptions] = Agent( # ty: ignore[invalid-assignment]
|
return Agent(model, output_type=FollowUpOptions, instructions=prompt)
|
||||||
model, output_type=FollowUpOptions, instructions=prompt
|
|
||||||
)
|
|
||||||
return agent
|
|
||||||
|
|
||||||
|
|
||||||
def build_message_history(history: list[dict[str, str]]) -> list[ModelMessage]:
|
def build_message_history(history: list[dict[str, str]]) -> list[ModelMessage]:
|
||||||
@@ -235,13 +68,12 @@ def build_message_history(history: list[dict[str, str]]) -> list[ModelMessage]:
|
|||||||
|
|
||||||
|
|
||||||
async def stream_response( # noqa: PLR0913
|
async def stream_response( # noqa: PLR0913
|
||||||
text_agent: Agent[AgentDeps, str] | Agent[None, str],
|
text_agent: Agent[None, str],
|
||||||
message: str,
|
message: str,
|
||||||
history: list[dict[str, str]] | None = None,
|
history: list[dict[str, str]] | None = None,
|
||||||
on_chunk: StreamCallback | None = None,
|
on_chunk: StreamCallback | None = None,
|
||||||
image: ImageData | None = None,
|
image: ImageData | None = None,
|
||||||
images: list[ImageData] | None = None,
|
images: list[ImageData] | None = None,
|
||||||
deps: AgentDeps | None = None,
|
|
||||||
) -> str:
|
) -> str:
|
||||||
message_history = build_message_history(history) if history else None
|
message_history = build_message_history(history) if history else None
|
||||||
|
|
||||||
@@ -256,7 +88,7 @@ async def stream_response( # noqa: PLR0913
|
|||||||
else:
|
else:
|
||||||
prompt = message # type: ignore[assignment]
|
prompt = message # type: ignore[assignment]
|
||||||
|
|
||||||
stream = text_agent.run_stream(prompt, message_history=message_history, deps=deps)
|
stream = text_agent.run_stream(prompt, message_history=message_history)
|
||||||
async with stream as result:
|
async with stream as result:
|
||||||
async for text in result.stream_text():
|
async for text in result.stream_text():
|
||||||
if on_chunk:
|
if on_chunk:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
EXAM_SYSTEM = """You help solve problem sets and exams.
|
EXAM_SYSTEM = """You help solve problem sets and exams.
|
||||||
|
|
||||||
When you receive just an IMAGE to process with problems:
|
When you receive an IMAGE with problems:
|
||||||
- Give HINTS in Russian for each problem
|
- Give HINTS in Russian for each problem
|
||||||
- Focus on key insights and potential difficulties,
|
- Focus on key insights and potential difficulties,
|
||||||
give all formulas that will be helpful
|
give all formulas that will be helpful
|
||||||
@@ -9,195 +9,13 @@ give all formulas that will be helpful
|
|||||||
|
|
||||||
When asked for DETAILS on a specific problem (or a problem number):
|
When asked for DETAILS on a specific problem (or a problem number):
|
||||||
- Provide full structured solution in English
|
- Provide full structured solution in English
|
||||||
- Academic style, as it would be written in a notebook on real exam
|
- Academic style, as it would be written in a notebook
|
||||||
- Step by step, clean, no fluff, no overcompications, reuse thoughts inside
|
- Step by step, clean, no fluff"""
|
||||||
one task, as you would write it on an exam, be consistent
|
|
||||||
- This is also true if you get a summary, and then problem number is asked"""
|
|
||||||
|
|
||||||
EXAM_FOLLOW_UP = """Look at the problem set image and list ALL problem numbers as
|
EXAM_FOLLOW_UP = """Look at the problem set image and list problem numbers as options.
|
||||||
options. Split by subparts ONLY if they are totally different tasks, not the steps of
|
If problems have sub-parts (a, b, c), list as: 1a, 1b, 2a, etc.
|
||||||
one.
|
|
||||||
If there are multiple problem sets/sheets, break it down logically and specify set,
|
|
||||||
for example Group A: 1, Group A: 2a, Group B: 2b, etc.
|
|
||||||
Or, Theory: 1, Theory: 2a, Practice: 1, etc.
|
|
||||||
Only output identifiers that exist in the image."""
|
Only output identifiers that exist in the image."""
|
||||||
|
|
||||||
PROOFS_SYSTEM = """
|
|
||||||
You are an Examination Engine designed for Apple Watch output.
|
|
||||||
CONTEXT: You have a loaded JSON database of theoretical knowledge below.
|
|
||||||
|
|
||||||
<THEORY_DATABASE>
|
|
||||||
{theory_database}
|
|
||||||
</THEORY_DATABASE>
|
|
||||||
|
|
||||||
*** PROTOCOL: BATCH PROCESSING ***
|
|
||||||
|
|
||||||
1. IMAGE INPUT (Primary Mode):
|
|
||||||
- **DETECT ALL** tasks/questions visible in the image.
|
|
||||||
- **SOLVE ALL** of them sequentially in a single response.
|
|
||||||
- **ORDER:** Follow the numbering on the exam sheet (Ex 1, Ex 2, ...).
|
|
||||||
- **SEPARATOR:** Use "---" between tasks.
|
|
||||||
- Second image - treat as continuation
|
|
||||||
|
|
||||||
2. SOLVING LOGIC:
|
|
||||||
- **Scan DB first:** Check if the Task matches a Theorem/Proof in JSON.
|
|
||||||
- IF MATCH: Output `statement` AND `proof` VERBATIM from JSON
|
|
||||||
(as requested in task)
|
|
||||||
- IF PARTIAL MATCH (e.g., specific function):
|
|
||||||
Use JSON method but plug in the numbers.
|
|
||||||
- **If NOT in DB:** Solve step-by-step in academic style, dry math as you would
|
|
||||||
write it in exam sheet.
|
|
||||||
- **Style:** Dry, formal, "notebook" style. No conversational filler.
|
|
||||||
- **NEVER summarize.** No "Applying L'Hopital 6 times".
|
|
||||||
- **SHOW ALL STEPS.** Write out $f', f'', f'''$ explicitly.
|
|
||||||
- **Theorems:** Use JSON verbatim.
|
|
||||||
- **Problems:** Step-by-step derivation.
|
|
||||||
|
|
||||||
3. APPLE WATCH FORMATTING (Strict):
|
|
||||||
- **Line Width:** MAX 25-30 chars. Force line breaks often.
|
|
||||||
- **Math:** Standard LaTeX blocks `$$...$$` or inline `$..$`.
|
|
||||||
- **Structure:**
|
|
||||||
**Ex. X ([Topic])**
|
|
||||||
[Solution/Proof]
|
|
||||||
---
|
|
||||||
**Ex. Y ([Topic])**
|
|
||||||
[Solution/Proof]
|
|
||||||
|
|
||||||
4. MULTI-PAGE/TEXT HANDLING:
|
|
||||||
- If user sends a new image -> Assume it's the next page ->
|
|
||||||
Continue to solve tasks as it was continuation, don't repeat already solved tasks.
|
|
||||||
- If user types text (e.g., "proof for lagrange") -> Treat as high-priority override\
|
|
||||||
-> Answer to specific question immediately, don't repeat already solved tasks
|
|
||||||
(help or fix something that you are asked for)
|
|
||||||
- Ignore typos in text input (fuzzy match).
|
|
||||||
"""
|
|
||||||
|
|
||||||
RAGTHEORY_SYSTEM = """You help answer theoretical exam questions.
|
|
||||||
|
|
||||||
When you receive an IMAGE with exam questions:
|
|
||||||
1. Identify ALL questions/blanks to fill
|
|
||||||
2. For EACH question, use search_knowledge_base to find relevant info
|
|
||||||
3. Provide exam-ready answers
|
|
||||||
|
|
||||||
OUTPUT FORMAT:
|
|
||||||
- Number each answer matching the question number
|
|
||||||
- Answer length: match what the question expects
|
|
||||||
(1 sentence, 1-2 sentences, fill blank, list items, etc.)
|
|
||||||
- Write answers EXACTLY as they should appear on the exam sheet - ready to copy 1:1
|
|
||||||
- Use precise terminology from the course
|
|
||||||
- No explanations, no "because", no fluff - just the answer itself
|
|
||||||
- For multi-part questions (a, b, c), answer each part separately
|
|
||||||
|
|
||||||
LANGUAGE: Match the exam language (usually English for technical terms)
|
|
||||||
|
|
||||||
STYLE: Academic, precise, minimal - as if you're writing on paper with limited space
|
|
||||||
|
|
||||||
Example input:
|
|
||||||
"Stigmergy is ............"
|
|
||||||
Example output:
|
|
||||||
"1. Stigmergy is indirect communication through environment\
|
|
||||||
modification, e.g. by leaving some marks."
|
|
||||||
|
|
||||||
Example input:
|
|
||||||
"How is crossing over performed in genetic programming? (one precise sentence)"
|
|
||||||
Example output:
|
|
||||||
"3. Usually implemented as swapping randomly selected subtrees of parent trees"
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
REFERENCE_SYSTEM = """
|
|
||||||
You are an Examination Engine for solving problem sets, designed for Apple Watch output.
|
|
||||||
|
|
||||||
You operate against context bank:
|
|
||||||
|
|
||||||
<EXAM_MATERIALS>
|
|
||||||
{theory_database}
|
|
||||||
</EXAM_MATERIALS>
|
|
||||||
|
|
||||||
*** PROTOCOL: BATCH PROCESSING ***
|
|
||||||
|
|
||||||
1. **DETECT ALL** problems in input.
|
|
||||||
2. **SOLVE ALL** sequentially in one response.
|
|
||||||
3. **ORDER:** follow source numbering. Subparts (a, b, c) stay grouped under parent.
|
|
||||||
4. **SEPARATOR:** "---" between problems.
|
|
||||||
5. **CONTINUATION:** new page after partial solve → don't repeat solved tasks.
|
|
||||||
6. **NO PREAMBLE.** Start directly with **Ex. 1**. No "I see the following problems".
|
|
||||||
|
|
||||||
*** SOLVING LOGIC ***
|
|
||||||
|
|
||||||
This is a PROBLEM-SOLVING engine, not a theory recall engine.
|
|
||||||
Every problem gets a full derivation.
|
|
||||||
|
|
||||||
- **Honor EXAM_MATERIALS first.** If they specify a formula source, notation,
|
|
||||||
forbidden method, required step or example - comply.
|
|
||||||
- Mirror approach exactly: same notation, structure, justification depth, voice.
|
|
||||||
- If no match in materials → infer canonical structure from examples and apply.
|
|
||||||
- **Show all reasoning** that examples show.
|
|
||||||
Don't skip steps "because obvious" if examples don't skip them.
|
|
||||||
- **Brief justifications welcome** when examples use them
|
|
||||||
("by symmetry", "since disjoint", "WLOG"). Match voice.
|
|
||||||
|
|
||||||
*** APPLE WATCH FORMATTING (strict) ***
|
|
||||||
- Line width: MAX 25-30 chars. Force breaks often.
|
|
||||||
- Math: `$$...$$` display, `$...$` inline, standard LaTeX.
|
|
||||||
"""
|
|
||||||
|
|
||||||
CODING_SYSTEM = """
|
|
||||||
You help solve programming, algorithms (Python), and systems (Linux/C/OS)
|
|
||||||
exam problems.
|
|
||||||
Output is consumed on Apple Watch but answers must be paste-ready into Moodle/code boxes
|
|
||||||
|
|
||||||
*** PROTOCOL: BATCH PROCESSING ***
|
|
||||||
|
|
||||||
1. **DETECT ALL** problems in image, solve sequentially.
|
|
||||||
2. **ORDER:** follow numbering on the page.
|
|
||||||
3. **SEPARATOR:** "---" between problems.
|
|
||||||
4. **CONTINUATION:** new image = next page, don't repeat solved tasks.
|
|
||||||
5. **TEXT OVERRIDE:** user types something (e.g. "fix Q3", "redo b",
|
|
||||||
"explain why not c") → answer that specifically. Fuzzy match typos.
|
|
||||||
6. **NO PREAMBLE.** Start directly with **Q1**. No "I see the following...".
|
|
||||||
|
|
||||||
*** CORE PRINCIPLES ***
|
|
||||||
|
|
||||||
- **Read carefully.** Exam questions are full of traps:
|
|
||||||
off-by-one, "select ALL that apply", forbidden methods, edge cases
|
|
||||||
("what if input is empty / negative / EOF?"). Slow down on the wording.
|
|
||||||
|
|
||||||
- **Bold the final answer** of every problem. User scans for it on a watch.
|
|
||||||
|
|
||||||
- **Match what the question actually asks for.** If it asks for "the output",
|
|
||||||
give the output. If it asks "which option", give the letter. If it asks
|
|
||||||
"explain why", explain. Don't dump everything you know.
|
|
||||||
|
|
||||||
- **For MCQ / select-all:** evaluate every option explicitly, don't just pick
|
|
||||||
one. Mark each ✓/✗ with a one-line reason. Watch for "almost true but
|
|
||||||
technically wrong" distractors (wrong complexity, off-by-one in distances,
|
|
||||||
wrong constant in Big-O, etc.).
|
|
||||||
|
|
||||||
- **For code writing:** output COMPLETE, COPY-PASTEABLE code. No "...",
|
|
||||||
no TODOs, no "rest is similar". Match the starter template EXACTLY:
|
|
||||||
same includes, function names, signatures, return types. Respect
|
|
||||||
constraints stated in the problem - they are graded on those.
|
|
||||||
|
|
||||||
- **For traces / step-by-step execution** (sort steps, graph traversal,
|
|
||||||
shell command, register state, whatever): show the state at each step
|
|
||||||
in compact form. Don't summarize ("after 5 iterations..."), show them.
|
|
||||||
|
|
||||||
- **For "what does this command/code do" questions:** mentally execute it.
|
|
||||||
State assumptions about environment if relevant (cwd, perms, shell, libc).
|
|
||||||
|
|
||||||
- **When something is genuinely ambiguous in the problem,** state your
|
|
||||||
assumption in one line, then proceed. Don't ask back - exam mode.
|
|
||||||
|
|
||||||
*** APPLE WATCH FORMATTING ***
|
|
||||||
|
|
||||||
- **Prose lines:** ~25–30 chars, force breaks often.
|
|
||||||
- **Code blocks:** full width is fine, user scrolls.
|
|
||||||
- **Bold** the final answer.
|
|
||||||
- No "Hope this helps", no "Let me know if...", no recap at the end.
|
|
||||||
- ALWAYS output code and commands inside ``` codeblocks to not trigger LaTeX rendering
|
|
||||||
"""
|
|
||||||
|
|
||||||
DEFAULT_FOLLOW_UP = (
|
DEFAULT_FOLLOW_UP = (
|
||||||
"Based on the conversation, suggest 3 short follow-up questions "
|
"Based on the conversation, suggest 3 short follow-up questions "
|
||||||
"the user might want to ask. Each option should be under 50 characters."
|
"the user might want to ask. Each option should be under 50 characters."
|
||||||
@@ -214,10 +32,4 @@ Summarize VERY briefly:
|
|||||||
|
|
||||||
Max 2-3 sentences. This is for Apple Watch display."""
|
Max 2-3 sentences. This is for Apple Watch display."""
|
||||||
|
|
||||||
PRESETS: dict[str, tuple[str, str]] = {
|
PRESETS: dict[str, tuple[str, str]] = {"exam": (EXAM_SYSTEM, EXAM_FOLLOW_UP)}
|
||||||
"exam": (EXAM_SYSTEM, EXAM_FOLLOW_UP),
|
|
||||||
"ragtheory": (RAGTHEORY_SYSTEM, EXAM_FOLLOW_UP),
|
|
||||||
"proofs": (PROOFS_SYSTEM, EXAM_FOLLOW_UP),
|
|
||||||
"reference": (REFERENCE_SYSTEM, EXAM_FOLLOW_UP),
|
|
||||||
"code": (CODING_SYSTEM, EXAM_FOLLOW_UP),
|
|
||||||
}
|
|
||||||
|
|||||||
+7
-178
@@ -1,24 +1,16 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
|
||||||
import time
|
|
||||||
|
|
||||||
from aiogram import Bot
|
from aiogram import Bot
|
||||||
|
|
||||||
from bot.handlers.message.handler import process_message_from_web
|
from bot.handlers.message.handler import process_message_from_web
|
||||||
from bot.user_lock import get_user_lock
|
|
||||||
from utils import env
|
from utils import env
|
||||||
from utils.collaborative import (
|
|
||||||
CollaborativeClient,
|
|
||||||
CollaborativeHTTPError,
|
|
||||||
get_collaborative_client,
|
|
||||||
)
|
|
||||||
from utils.convex import ConvexClient
|
from utils.convex import ConvexClient
|
||||||
from utils.logging import logger
|
from utils.logging import logger
|
||||||
|
|
||||||
convex = ConvexClient(env.convex_url)
|
convex = ConvexClient(env.convex_url)
|
||||||
|
|
||||||
|
|
||||||
background_tasks: set[asyncio.Task] = set()
|
background_tasks = set()
|
||||||
|
|
||||||
|
|
||||||
async def start_sync_listener(bot: Bot) -> None:
|
async def start_sync_listener(bot: Bot) -> None:
|
||||||
@@ -54,176 +46,13 @@ async def start_sync_listener(bot: Bot) -> None:
|
|||||||
|
|
||||||
async def handle_pending_generation(bot: Bot, item: dict, item_id: str) -> None:
|
async def handle_pending_generation(bot: Bot, item: dict, item_id: str) -> None:
|
||||||
try:
|
try:
|
||||||
async with get_user_lock(item["userId"]):
|
await process_message_from_web(
|
||||||
await process_message_from_web(
|
convex_user_id=item["userId"],
|
||||||
convex_user_id=item["userId"],
|
text=item["userMessage"],
|
||||||
text=item["userMessage"],
|
bot=bot,
|
||||||
bot=bot,
|
convex_chat_id=item["chatId"],
|
||||||
convex_chat_id=item["chatId"],
|
)
|
||||||
images_base64=item.get("imagesBase64"),
|
|
||||||
images_media_types=item.get("imagesMediaTypes"),
|
|
||||||
pending_generation_id=item_id,
|
|
||||||
)
|
|
||||||
except Exception as e: # noqa: BLE001
|
except Exception as e: # noqa: BLE001
|
||||||
logger.error(f"Error processing {item_id}: {e}")
|
logger.error(f"Error processing {item_id}: {e}")
|
||||||
finally:
|
finally:
|
||||||
await convex.mutation("pendingGenerations:remove", {"id": item_id})
|
await convex.mutation("pendingGenerations:remove", {"id": item_id})
|
||||||
|
|
||||||
|
|
||||||
async def start_room_upload_worker(bot: Bot) -> None: # noqa: ARG001
|
|
||||||
if not env.collaborative.enabled:
|
|
||||||
logger.info("Collaborative not configured; upload worker disabled.")
|
|
||||||
return
|
|
||||||
|
|
||||||
logger.info("Starting collaborative upload worker...")
|
|
||||||
|
|
||||||
try:
|
|
||||||
reset_count = await convex.mutation("collaborative:resetStuckUploads", {})
|
|
||||||
if reset_count:
|
|
||||||
logger.info(f"Reset {reset_count} stuck uploads to pending.")
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"Failed to reset stuck uploads: {e}")
|
|
||||||
|
|
||||||
in_flight: set[str] = set()
|
|
||||||
sub = convex.subscribe("collaborative:listPendingUploads", {})
|
|
||||||
|
|
||||||
try:
|
|
||||||
async for pending_list in sub:
|
|
||||||
for item in pending_list or []:
|
|
||||||
item_id = item["_id"]
|
|
||||||
if item_id in in_flight:
|
|
||||||
continue
|
|
||||||
if item.get("attempts", 0) >= env.collaborative.upload_max_attempts:
|
|
||||||
continue
|
|
||||||
|
|
||||||
in_flight.add(item_id)
|
|
||||||
task = asyncio.create_task(_handle_upload(item, item_id, in_flight))
|
|
||||||
background_tasks.add(task)
|
|
||||||
task.add_done_callback(background_tasks.discard)
|
|
||||||
except asyncio.CancelledError:
|
|
||||||
logger.info("Upload worker cancelled")
|
|
||||||
raise
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.error(f"Upload worker error: {e}")
|
|
||||||
finally:
|
|
||||||
sub.unsubscribe()
|
|
||||||
|
|
||||||
|
|
||||||
async def _handle_upload(item: dict, item_id: str, in_flight: set[str]) -> None:
|
|
||||||
try:
|
|
||||||
claimed = await convex.mutation("collaborative:markUploading", {"id": item_id})
|
|
||||||
if not claimed:
|
|
||||||
return
|
|
||||||
|
|
||||||
client = get_collaborative_client()
|
|
||||||
try:
|
|
||||||
image_bytes = base64.b64decode(item["imageBase64"])
|
|
||||||
await client.upload_photo(
|
|
||||||
pin=item["pin"], image_bytes=image_bytes, media_type=item["mediaType"]
|
|
||||||
)
|
|
||||||
await convex.mutation("collaborative:markDone", {"id": item_id})
|
|
||||||
logger.info(f"Room upload {item_id} done.")
|
|
||||||
except CollaborativeHTTPError as e:
|
|
||||||
if 400 <= e.status_code < 500: # noqa: PLR2004
|
|
||||||
await convex.mutation(
|
|
||||||
"collaborative:markFailed", {"id": item_id, "error": str(e)}
|
|
||||||
)
|
|
||||||
logger.warning(f"Room upload {item_id} failed (4xx): {e}")
|
|
||||||
else:
|
|
||||||
await _bump_with_backoff(item, item_id, str(e))
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
await _bump_with_backoff(item, item_id, str(e))
|
|
||||||
finally:
|
|
||||||
in_flight.discard(item_id)
|
|
||||||
|
|
||||||
|
|
||||||
async def _bump_with_backoff(item: dict, item_id: str, error: str) -> None:
|
|
||||||
attempts = item.get("attempts", 0) + 1
|
|
||||||
base = env.collaborative.upload_backoff_base_seconds
|
|
||||||
delay_seconds = min(base * (2 ** (attempts - 1)), 60.0)
|
|
||||||
next_retry_at_ms = int((time.time() + delay_seconds) * 1000)
|
|
||||||
await convex.mutation(
|
|
||||||
"collaborative:bumpAttempt",
|
|
||||||
{"id": item_id, "error": error[:500], "nextRetryAt": next_retry_at_ms},
|
|
||||||
)
|
|
||||||
logger.info(
|
|
||||||
f"Room upload {item_id} retry in {delay_seconds:.1f}s "
|
|
||||||
f"(attempt {attempts}): {error[:100]}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def start_room_inbox_poller(bot: Bot) -> None: # noqa: ARG001
|
|
||||||
if not env.collaborative.enabled:
|
|
||||||
logger.info("Collaborative not configured; inbox poller disabled.")
|
|
||||||
return
|
|
||||||
|
|
||||||
logger.info("Starting collaborative inbox poller...")
|
|
||||||
interval = env.collaborative.poll_interval_seconds
|
|
||||||
client = get_collaborative_client()
|
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
users = await convex.query("users:listActiveRoomUsers", {})
|
|
||||||
for user in users or []:
|
|
||||||
await _poll_user_room(client, user)
|
|
||||||
except asyncio.CancelledError:
|
|
||||||
logger.info("Inbox poller cancelled")
|
|
||||||
raise
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"Inbox poller iteration failed: {e}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
await asyncio.sleep(interval)
|
|
||||||
except asyncio.CancelledError:
|
|
||||||
logger.info("Inbox poller cancelled")
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
async def _poll_user_room(client: CollaborativeClient, user: dict) -> None:
|
|
||||||
pin = user["pin"]
|
|
||||||
last_seen_sheet_id = int(user.get("lastSeenSheetId", 0) or 0)
|
|
||||||
user_id = user["_id"]
|
|
||||||
|
|
||||||
try:
|
|
||||||
resp = await client.get_sheets(pin)
|
|
||||||
except CollaborativeHTTPError as e:
|
|
||||||
logger.warning(f"Room {pin} sheets fetch failed ({e.status_code}); skipping.")
|
|
||||||
return
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.warning(f"Room {pin} sheets fetch error: {e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
sheets = resp.get("sheets", []) or []
|
|
||||||
new_sheets = [s for s in sheets if int(s.get("id", 0)) > last_seen_sheet_id]
|
|
||||||
if not new_sheets:
|
|
||||||
return
|
|
||||||
|
|
||||||
user_doc = await convex.query("users:getById", {"userId": user_id})
|
|
||||||
if not user_doc or not user_doc.get("activeChatId"):
|
|
||||||
return
|
|
||||||
|
|
||||||
chat_id = user_doc["activeChatId"]
|
|
||||||
|
|
||||||
payload = [
|
|
||||||
{
|
|
||||||
"sheetId": int(s["id"]),
|
|
||||||
"sheetCreatedAt": float(s.get("created_at", 0)),
|
|
||||||
"text": s.get("text", "") or "",
|
|
||||||
}
|
|
||||||
for s in new_sheets
|
|
||||||
]
|
|
||||||
max_id = max(int(s["id"]) for s in new_sheets)
|
|
||||||
|
|
||||||
try:
|
|
||||||
inserted = await convex.mutation(
|
|
||||||
"incomingSheets:createMany",
|
|
||||||
{"userId": user_id, "chatId": chat_id, "pin": pin, "sheets": payload},
|
|
||||||
)
|
|
||||||
await convex.mutation(
|
|
||||||
"users:setLastSeenSheetId", {"userId": user_id, "sheetId": max_id}
|
|
||||||
)
|
|
||||||
logger.info(
|
|
||||||
f"Room {pin}: ingested {inserted} new sheet(s) (cursor → {max_id})."
|
|
||||||
)
|
|
||||||
except Exception as e: # noqa: BLE001
|
|
||||||
logger.error(f"Failed to ingest sheets for {pin}: {e}")
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
import asyncio
|
|
||||||
|
|
||||||
_locks: dict[str, asyncio.Lock] = {}
|
|
||||||
|
|
||||||
|
|
||||||
def get_user_lock(convex_user_id: str) -> asyncio.Lock:
|
|
||||||
lock = _locks.get(convex_user_id)
|
|
||||||
if lock is None:
|
|
||||||
lock = asyncio.Lock()
|
|
||||||
_locks[convex_user_id] = lock
|
|
||||||
return lock
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
from .client import (
|
|
||||||
CollaborativeClient,
|
|
||||||
CollaborativeHTTPError,
|
|
||||||
get_collaborative_client,
|
|
||||||
)
|
|
||||||
|
|
||||||
__all__ = ["CollaborativeClient", "CollaborativeHTTPError", "get_collaborative_client"]
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
from typing import Any
|
|
||||||
|
|
||||||
import httpx
|
|
||||||
|
|
||||||
from utils import env
|
|
||||||
|
|
||||||
|
|
||||||
class CollaborativeHTTPError(Exception):
|
|
||||||
def __init__(self, status_code: int, body: str) -> None:
|
|
||||||
super().__init__(f"HTTP {status_code}: {body[:200]}")
|
|
||||||
self.status_code = status_code
|
|
||||||
self.body = body
|
|
||||||
|
|
||||||
|
|
||||||
class CollaborativeClient:
|
|
||||||
def __init__(self) -> None:
|
|
||||||
cfg = env.collaborative
|
|
||||||
timeout = httpx.Timeout(connect=10.0, read=30.0, write=60.0, pool=10.0)
|
|
||||||
self._client = httpx.AsyncClient(
|
|
||||||
base_url=cfg.api_url.rstrip("/"),
|
|
||||||
timeout=timeout,
|
|
||||||
headers={"X-API-Key": cfg.api_key.get_secret_value()},
|
|
||||||
)
|
|
||||||
|
|
||||||
async def aclose(self) -> None:
|
|
||||||
await self._client.aclose()
|
|
||||||
|
|
||||||
async def _request(
|
|
||||||
self,
|
|
||||||
method: str,
|
|
||||||
path: str,
|
|
||||||
**kwargs: Any, # noqa: ANN401
|
|
||||||
) -> dict[str, Any]:
|
|
||||||
resp = await self._client.request(method, path, **kwargs)
|
|
||||||
if resp.status_code >= 400: # noqa: PLR2004
|
|
||||||
raise CollaborativeHTTPError(resp.status_code, resp.text)
|
|
||||||
return resp.json()
|
|
||||||
|
|
||||||
async def create_room(self) -> dict[str, str]:
|
|
||||||
return await self._request("POST", "/api/v1/rooms")
|
|
||||||
|
|
||||||
async def get_room(self, pin: str) -> dict[str, Any]:
|
|
||||||
return await self._request("GET", f"/api/v1/rooms/{pin}")
|
|
||||||
|
|
||||||
async def get_sheets(self, pin: str) -> dict[str, Any]:
|
|
||||||
return await self._request("GET", f"/api/v1/rooms/{pin}/sheets")
|
|
||||||
|
|
||||||
async def delete_room(self, pin: str, creator_token: str) -> dict[str, Any]:
|
|
||||||
return await self._request(
|
|
||||||
"DELETE", f"/api/v1/rooms/{pin}", params={"creator_token": creator_token}
|
|
||||||
)
|
|
||||||
|
|
||||||
async def upload_photo(
|
|
||||||
self, pin: str, image_bytes: bytes, media_type: str, filename: str = "photo.jpg"
|
|
||||||
) -> dict[str, Any]:
|
|
||||||
files = {"file": (filename, image_bytes, media_type)}
|
|
||||||
return await self._request("POST", f"/api/v1/rooms/{pin}/upload", files=files)
|
|
||||||
|
|
||||||
|
|
||||||
_client: CollaborativeClient | None = None
|
|
||||||
|
|
||||||
|
|
||||||
def get_collaborative_client() -> CollaborativeClient:
|
|
||||||
global _client # noqa: PLW0603
|
|
||||||
if _client is None:
|
|
||||||
_client = CollaborativeClient()
|
|
||||||
return _client
|
|
||||||
@@ -7,19 +7,15 @@ from convex import ConvexClient as SyncConvexClient
|
|||||||
class ConvexClient:
|
class ConvexClient:
|
||||||
def __init__(self, url: str) -> None:
|
def __init__(self, url: str) -> None:
|
||||||
self._client = SyncConvexClient(url)
|
self._client = SyncConvexClient(url)
|
||||||
self._lock = asyncio.Lock()
|
|
||||||
|
|
||||||
async def query(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
async def query(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
||||||
async with self._lock:
|
return await asyncio.to_thread(self._client.query, name, args or {})
|
||||||
return await asyncio.to_thread(self._client.query, name, args or {})
|
|
||||||
|
|
||||||
async def mutation(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
async def mutation(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
||||||
async with self._lock:
|
return await asyncio.to_thread(self._client.mutation, name, args or {})
|
||||||
return await asyncio.to_thread(self._client.mutation, name, args or {})
|
|
||||||
|
|
||||||
async def action(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
async def action(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
||||||
async with self._lock:
|
return await asyncio.to_thread(self._client.action, name, args or {})
|
||||||
return await asyncio.to_thread(self._client.action, name, args or {})
|
|
||||||
|
|
||||||
def subscribe(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
def subscribe(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
||||||
return self._client.subscribe(name, args or {})
|
return self._client.subscribe(name, args or {})
|
||||||
|
|||||||
@@ -17,46 +17,16 @@ class LogSettings(BaseSettings):
|
|||||||
console_width: int = 150
|
console_width: int = 150
|
||||||
|
|
||||||
|
|
||||||
class CollaborativeSettings(BaseSettings):
|
|
||||||
api_url: str = ""
|
|
||||||
api_key: SecretStr = SecretStr("")
|
|
||||||
poll_interval_seconds: int = 8
|
|
||||||
upload_max_attempts: int = 8
|
|
||||||
upload_backoff_base_seconds: float = 2.0
|
|
||||||
request_timeout_seconds: int = 30
|
|
||||||
|
|
||||||
@property
|
|
||||||
def enabled(self) -> bool:
|
|
||||||
return bool(self.api_url)
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
bot: BotSettings
|
bot: BotSettings
|
||||||
site: SiteSettings
|
site: SiteSettings
|
||||||
log: LogSettings
|
log: LogSettings
|
||||||
collaborative: CollaborativeSettings
|
|
||||||
|
|
||||||
anthropic_api_key: SecretStr = Field(
|
|
||||||
default=SecretStr(""), validation_alias=AliasChoices("ANTHROPIC_API_KEY")
|
|
||||||
)
|
|
||||||
anthropic_model: str = Field(
|
|
||||||
default="claude-sonnet-4-5", validation_alias=AliasChoices("ANTHROPIC_MODEL")
|
|
||||||
)
|
|
||||||
|
|
||||||
convex_url: str = Field(validation_alias=AliasChoices("CONVEX_SELF_HOSTED_URL"))
|
convex_url: str = Field(validation_alias=AliasChoices("CONVEX_SELF_HOSTED_URL"))
|
||||||
convex_http_url: str = Field(
|
|
||||||
default="", validation_alias=AliasChoices("CONVEX_HTTP_URL")
|
|
||||||
)
|
|
||||||
|
|
||||||
model_config = SettingsConfigDict(
|
model_config = SettingsConfigDict(
|
||||||
case_sensitive=False, env_file=".env", env_nested_delimiter="__", extra="ignore"
|
case_sensitive=False, env_file=".env", env_nested_delimiter="__", extra="ignore"
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def convex_http_base_url(self) -> str:
|
|
||||||
if self.convex_http_url:
|
|
||||||
return self.convex_http_url
|
|
||||||
return self.convex_url.replace("/convex", "/convex-http")
|
|
||||||
|
|
||||||
|
|
||||||
env = Settings() # ty:ignore[missing-argument]
|
env = Settings() # ty:ignore[missing-argument]
|
||||||
|
|||||||
Generated
+44
-214
@@ -126,25 +126,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643, upload-time = "2024-05-20T21:33:24.1Z" },
|
{ url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643, upload-time = "2024-05-20T21:33:24.1Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "anthropic"
|
|
||||||
version = "0.105.2"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "anyio" },
|
|
||||||
{ name = "distro" },
|
|
||||||
{ name = "docstring-parser" },
|
|
||||||
{ name = "httpx" },
|
|
||||||
{ name = "jiter" },
|
|
||||||
{ name = "pydantic" },
|
|
||||||
{ name = "sniffio" },
|
|
||||||
{ name = "typing-extensions" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/46/46/47581b8c689c743ceabf6a0f9ff48472160900ce802d26c0fb50423997b3/anthropic-0.105.2.tar.gz", hash = "sha256:0e26b90841c2dced7cc6e98d21d5517d0be33f1876b8e779f478202e28bcaa07", size = 853789, upload-time = "2026-05-29T00:21:14.104Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/83/75/be0c357e33a5a56c8f9db5b4212f886138d2bf59c0952d858f6b75d710ef/anthropic-0.105.2-py3-none-any.whl", hash = "sha256:e53ed5f6bf36fb1ecb9b25d8634cfd30e02fab9fb3374a0c2d5c585874757230", size = 837507, upload-time = "2026-05-29T00:21:15.528Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyio"
|
name = "anyio"
|
||||||
version = "4.12.1"
|
version = "4.12.1"
|
||||||
@@ -173,8 +154,7 @@ source = { editable = "." }
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "aiogram" },
|
{ name = "aiogram" },
|
||||||
{ name = "convex" },
|
{ name = "convex" },
|
||||||
{ name = "httpx" },
|
{ name = "pydantic-ai-slim", extra = ["google"] },
|
||||||
{ name = "pydantic-ai-slim", extra = ["anthropic", "google"] },
|
|
||||||
{ name = "pydantic-settings" },
|
{ name = "pydantic-settings" },
|
||||||
{ name = "rich" },
|
{ name = "rich" },
|
||||||
{ name = "xkcdpass" },
|
{ name = "xkcdpass" },
|
||||||
@@ -184,8 +164,7 @@ dependencies = [
|
|||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "aiogram", specifier = ">=3.24.0" },
|
{ name = "aiogram", specifier = ">=3.24.0" },
|
||||||
{ name = "convex", specifier = ">=0.7.0" },
|
{ name = "convex", specifier = ">=0.7.0" },
|
||||||
{ name = "httpx", specifier = ">=0.27" },
|
{ name = "pydantic-ai-slim", extras = ["google"], specifier = ">=1.44.0" },
|
||||||
{ name = "pydantic-ai-slim", extras = ["google", "anthropic"], specifier = ">=1.44.0" },
|
|
||||||
{ name = "pydantic-settings", specifier = ">=2.12.0" },
|
{ name = "pydantic-settings", specifier = ">=2.12.0" },
|
||||||
{ name = "rich", specifier = ">=14.2.0" },
|
{ name = "rich", specifier = ">=14.2.0" },
|
||||||
{ name = "xkcdpass", specifier = ">=1.19.0" },
|
{ name = "xkcdpass", specifier = ">=1.19.0" },
|
||||||
@@ -200,51 +179,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/e6/ad/3cc14f097111b4de0040c83a525973216457bbeeb63739ef1ed275c1c021/certifi-2026.1.4-py3-none-any.whl", hash = "sha256:9943707519e4add1115f44c2bc244f782c0249876bf51b6599fee1ffbedd685c", size = 152900, upload-time = "2026-01-04T02:42:40.15Z" },
|
{ url = "https://files.pythonhosted.org/packages/e6/ad/3cc14f097111b4de0040c83a525973216457bbeeb63739ef1ed275c1c021/certifi-2026.1.4-py3-none-any.whl", hash = "sha256:9943707519e4add1115f44c2bc244f782c0249876bf51b6599fee1ffbedd685c", size = 152900, upload-time = "2026-01-04T02:42:40.15Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cffi"
|
|
||||||
version = "2.0.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "pycparser", marker = "implementation_name != 'PyPy'" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/eb/56/b1ba7935a17738ae8453301356628e8147c79dbb825bcbc73dc7401f9846/cffi-2.0.0.tar.gz", hash = "sha256:44d1b5909021139fe36001ae048dbdde8214afa20200eda0f64c068cac5d5529", size = 523588, upload-time = "2025-09-08T23:24:04.541Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/4b/8d/a0a47a0c9e413a658623d014e91e74a50cdd2c423f7ccfd44086ef767f90/cffi-2.0.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:00bdf7acc5f795150faa6957054fbbca2439db2f775ce831222b66f192f03beb", size = 185230, upload-time = "2025-09-08T23:23:00.879Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/4a/d2/a6c0296814556c68ee32009d9c2ad4f85f2707cdecfd7727951ec228005d/cffi-2.0.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:45d5e886156860dc35862657e1494b9bae8dfa63bf56796f2fb56e1679fc0bca", size = 181043, upload-time = "2025-09-08T23:23:02.231Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/b0/1e/d22cc63332bd59b06481ceaac49d6c507598642e2230f201649058a7e704/cffi-2.0.0-cp313-cp313-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:07b271772c100085dd28b74fa0cd81c8fb1a3ba18b21e03d7c27f3436a10606b", size = 212446, upload-time = "2025-09-08T23:23:03.472Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a9/f5/a2c23eb03b61a0b8747f211eb716446c826ad66818ddc7810cc2cc19b3f2/cffi-2.0.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:d48a880098c96020b02d5a1f7d9251308510ce8858940e6fa99ece33f610838b", size = 220101, upload-time = "2025-09-08T23:23:04.792Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/f2/7f/e6647792fc5850d634695bc0e6ab4111ae88e89981d35ac269956605feba/cffi-2.0.0-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:f93fd8e5c8c0a4aa1f424d6173f14a892044054871c771f8566e4008eaa359d2", size = 207948, upload-time = "2025-09-08T23:23:06.127Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/cb/1e/a5a1bd6f1fb30f22573f76533de12a00bf274abcdc55c8edab639078abb6/cffi-2.0.0-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:dd4f05f54a52fb558f1ba9f528228066954fee3ebe629fc1660d874d040ae5a3", size = 206422, upload-time = "2025-09-08T23:23:07.753Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/98/df/0a1755e750013a2081e863e7cd37e0cdd02664372c754e5560099eb7aa44/cffi-2.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c8d3b5532fc71b7a77c09192b4a5a200ea992702734a2e9279a37f2478236f26", size = 219499, upload-time = "2025-09-08T23:23:09.648Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/50/e1/a969e687fcf9ea58e6e2a928ad5e2dd88cc12f6f0ab477e9971f2309b57c/cffi-2.0.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:d9b29c1f0ae438d5ee9acb31cadee00a58c46cc9c0b2f9038c6b0b3470877a8c", size = 222928, upload-time = "2025-09-08T23:23:10.928Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/36/54/0362578dd2c9e557a28ac77698ed67323ed5b9775ca9d3fe73fe191bb5d8/cffi-2.0.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:6d50360be4546678fc1b79ffe7a66265e28667840010348dd69a314145807a1b", size = 221302, upload-time = "2025-09-08T23:23:12.42Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/eb/6d/bf9bda840d5f1dfdbf0feca87fbdb64a918a69bca42cfa0ba7b137c48cb8/cffi-2.0.0-cp313-cp313-win32.whl", hash = "sha256:74a03b9698e198d47562765773b4a8309919089150a0bb17d829ad7b44b60d27", size = 172909, upload-time = "2025-09-08T23:23:14.32Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/37/18/6519e1ee6f5a1e579e04b9ddb6f1676c17368a7aba48299c3759bbc3c8b3/cffi-2.0.0-cp313-cp313-win_amd64.whl", hash = "sha256:19f705ada2530c1167abacb171925dd886168931e0a7b78f5bffcae5c6b5be75", size = 183402, upload-time = "2025-09-08T23:23:15.535Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/cb/0e/02ceeec9a7d6ee63bb596121c2c8e9b3a9e150936f4fbef6ca1943e6137c/cffi-2.0.0-cp313-cp313-win_arm64.whl", hash = "sha256:256f80b80ca3853f90c21b23ee78cd008713787b1b1e93eae9f3d6a7134abd91", size = 177780, upload-time = "2025-09-08T23:23:16.761Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/92/c4/3ce07396253a83250ee98564f8d7e9789fab8e58858f35d07a9a2c78de9f/cffi-2.0.0-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:fc33c5141b55ed366cfaad382df24fe7dcbc686de5be719b207bb248e3053dc5", size = 185320, upload-time = "2025-09-08T23:23:18.087Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/59/dd/27e9fa567a23931c838c6b02d0764611c62290062a6d4e8ff7863daf9730/cffi-2.0.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c654de545946e0db659b3400168c9ad31b5d29593291482c43e3564effbcee13", size = 181487, upload-time = "2025-09-08T23:23:19.622Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/d6/43/0e822876f87ea8a4ef95442c3d766a06a51fc5298823f884ef87aaad168c/cffi-2.0.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:24b6f81f1983e6df8db3adc38562c83f7d4a0c36162885ec7f7b77c7dcbec97b", size = 220049, upload-time = "2025-09-08T23:23:20.853Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/b4/89/76799151d9c2d2d1ead63c2429da9ea9d7aac304603de0c6e8764e6e8e70/cffi-2.0.0-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:12873ca6cb9b0f0d3a0da705d6086fe911591737a59f28b7936bdfed27c0d47c", size = 207793, upload-time = "2025-09-08T23:23:22.08Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/bb/dd/3465b14bb9e24ee24cb88c9e3730f6de63111fffe513492bf8c808a3547e/cffi-2.0.0-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:d9b97165e8aed9272a6bb17c01e3cc5871a594a446ebedc996e2397a1c1ea8ef", size = 206300, upload-time = "2025-09-08T23:23:23.314Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/47/d9/d83e293854571c877a92da46fdec39158f8d7e68da75bf73581225d28e90/cffi-2.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:afb8db5439b81cf9c9d0c80404b60c3cc9c3add93e114dcae767f1477cb53775", size = 219244, upload-time = "2025-09-08T23:23:24.541Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/2b/0f/1f177e3683aead2bb00f7679a16451d302c436b5cbf2505f0ea8146ef59e/cffi-2.0.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:737fe7d37e1a1bffe70bd5754ea763a62a066dc5913ca57e957824b72a85e205", size = 222828, upload-time = "2025-09-08T23:23:26.143Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/c6/0f/cafacebd4b040e3119dcb32fed8bdef8dfe94da653155f9d0b9dc660166e/cffi-2.0.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:38100abb9d1b1435bc4cc340bb4489635dc2f0da7456590877030c9b3d40b0c1", size = 220926, upload-time = "2025-09-08T23:23:27.873Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/3e/aa/df335faa45b395396fcbc03de2dfcab242cd61a9900e914fe682a59170b1/cffi-2.0.0-cp314-cp314-win32.whl", hash = "sha256:087067fa8953339c723661eda6b54bc98c5625757ea62e95eb4898ad5e776e9f", size = 175328, upload-time = "2025-09-08T23:23:44.61Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/bb/92/882c2d30831744296ce713f0feb4c1cd30f346ef747b530b5318715cc367/cffi-2.0.0-cp314-cp314-win_amd64.whl", hash = "sha256:203a48d1fb583fc7d78a4c6655692963b860a417c0528492a6bc21f1aaefab25", size = 185650, upload-time = "2025-09-08T23:23:45.848Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/9f/2c/98ece204b9d35a7366b5b2c6539c350313ca13932143e79dc133ba757104/cffi-2.0.0-cp314-cp314-win_arm64.whl", hash = "sha256:dbd5c7a25a7cb98f5ca55d258b103a2054f859a46ae11aaf23134f9cc0d356ad", size = 180687, upload-time = "2025-09-08T23:23:47.105Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/3e/61/c768e4d548bfa607abcda77423448df8c471f25dbe64fb2ef6d555eae006/cffi-2.0.0-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:9a67fc9e8eb39039280526379fb3a70023d77caec1852002b4da7e8b270c4dd9", size = 188773, upload-time = "2025-09-08T23:23:29.347Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/2c/ea/5f76bce7cf6fcd0ab1a1058b5af899bfbef198bea4d5686da88471ea0336/cffi-2.0.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:7a66c7204d8869299919db4d5069a82f1561581af12b11b3c9f48c584eb8743d", size = 185013, upload-time = "2025-09-08T23:23:30.63Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/be/b4/c56878d0d1755cf9caa54ba71e5d049479c52f9e4afc230f06822162ab2f/cffi-2.0.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:7cc09976e8b56f8cebd752f7113ad07752461f48a58cbba644139015ac24954c", size = 221593, upload-time = "2025-09-08T23:23:31.91Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e0/0d/eb704606dfe8033e7128df5e90fee946bbcb64a04fcdaa97321309004000/cffi-2.0.0-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:92b68146a71df78564e4ef48af17551a5ddd142e5190cdf2c5624d0c3ff5b2e8", size = 209354, upload-time = "2025-09-08T23:23:33.214Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/d8/19/3c435d727b368ca475fb8742ab97c9cb13a0de600ce86f62eab7fa3eea60/cffi-2.0.0-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:b1e74d11748e7e98e2f426ab176d4ed720a64412b6a15054378afdb71e0f37dc", size = 208480, upload-time = "2025-09-08T23:23:34.495Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/d0/44/681604464ed9541673e486521497406fadcc15b5217c3e326b061696899a/cffi-2.0.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:28a3a209b96630bca57cce802da70c266eb08c6e97e5afd61a75611ee6c64592", size = 221584, upload-time = "2025-09-08T23:23:36.096Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/25/8e/342a504ff018a2825d395d44d63a767dd8ebc927ebda557fecdaca3ac33a/cffi-2.0.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:7553fb2090d71822f02c629afe6042c299edf91ba1bf94951165613553984512", size = 224443, upload-time = "2025-09-08T23:23:37.328Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e1/5e/b666bacbbc60fbf415ba9988324a132c9a7a0448a9a8f125074671c0f2c3/cffi-2.0.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:6c6c373cfc5c83a975506110d17457138c8c63016b563cc9ed6e056a82f13ce4", size = 223437, upload-time = "2025-09-08T23:23:38.945Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a0/1d/ec1a60bd1a10daa292d3cd6bb0b359a81607154fb8165f3ec95fe003b85c/cffi-2.0.0-cp314-cp314t-win32.whl", hash = "sha256:1fc9ea04857caf665289b7a75923f2c6ed559b8298a1b8c49e59f7dd95c8481e", size = 180487, upload-time = "2025-09-08T23:23:40.423Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/bf/41/4c1168c74fac325c0c8156f04b6749c8b6a8f405bbf91413ba088359f60d/cffi-2.0.0-cp314-cp314t-win_amd64.whl", hash = "sha256:d68b6cef7827e8641e8ef16f4494edda8b36104d79773a334beaa1e3521430f6", size = 191726, upload-time = "2025-09-08T23:23:41.742Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ae/3a/dbeec9d1ee0844c679f6bb5d6ad4e9f198b1224f4e7a32825f47f6192b0c/cffi-2.0.0-cp314-cp314t-win_arm64.whl", hash = "sha256:0a1527a803f0a659de1af2e1fd700213caba79377e27e4693648c2923da066f9", size = 184195, upload-time = "2025-09-08T23:23:43.004Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "charset-normalizer"
|
name = "charset-normalizer"
|
||||||
version = "3.4.4"
|
version = "3.4.4"
|
||||||
@@ -286,6 +220,15 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/0a/4c/925909008ed5a988ccbb72dcc897407e5d6d3bd72410d69e051fc0c14647/charset_normalizer-3.4.4-py3-none-any.whl", hash = "sha256:7a32c560861a02ff789ad905a2fe94e3f840803362c84fecf1851cb4cf3dc37f", size = 53402, upload-time = "2025-10-14T04:42:31.76Z" },
|
{ url = "https://files.pythonhosted.org/packages/0a/4c/925909008ed5a988ccbb72dcc897407e5d6d3bd72410d69e051fc0c14647/charset_normalizer-3.4.4-py3-none-any.whl", hash = "sha256:7a32c560861a02ff789ad905a2fe94e3f840803362c84fecf1851cb4cf3dc37f", size = 53402, upload-time = "2025-10-14T04:42:31.76Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorama"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "convex"
|
name = "convex"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@@ -320,59 +263,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/5d/a6/b01145a2a25c00024809dedf5fce0dc5e7cb3fbde477112e5569f35ff7d1/convex-0.7.0-cp39-abi3-win_amd64.whl", hash = "sha256:ee71e10a883fed22d2d2d43e828162eb0afe2071699fd36d6b0ba63a9639fee1", size = 1150704, upload-time = "2024-12-17T01:03:22.904Z" },
|
{ url = "https://files.pythonhosted.org/packages/5d/a6/b01145a2a25c00024809dedf5fce0dc5e7cb3fbde477112e5569f35ff7d1/convex-0.7.0-cp39-abi3-win_amd64.whl", hash = "sha256:ee71e10a883fed22d2d2d43e828162eb0afe2071699fd36d6b0ba63a9639fee1", size = 1150704, upload-time = "2024-12-17T01:03:22.904Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cryptography"
|
|
||||||
version = "47.0.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "cffi", marker = "platform_python_implementation != 'PyPy'" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/ef/b2/7ffa7fe8207a8c42147ffe70c3e360b228160c1d85dc3faff16aaa3244c0/cryptography-47.0.0.tar.gz", hash = "sha256:9f8e55fe4e63613a5e1cc5819030f27b97742d720203a087802ce4ce9ceb52bb", size = 830863, upload-time = "2026-04-24T19:54:57.056Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a4/98/40dfe932134bdcae4f6ab5927c87488754bf9eb79297d7e0070b78dd58e9/cryptography-47.0.0-cp311-abi3-macosx_10_9_universal2.whl", hash = "sha256:160ad728f128972d362e714054f6ba0067cab7fb350c5202a9ae8ae4ce3ef1a0", size = 7912214, upload-time = "2026-04-24T19:53:03.864Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/34/c6/2733531243fba725f58611b918056b277692f1033373dcc8bd01af1c05d4/cryptography-47.0.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:b9a8943e359b7615db1a3ba587994618e094ff3d6fa5a390c73d079ce18b3973", size = 4644617, upload-time = "2026-04-24T19:53:06.909Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/00/e3/b27be1a670a9b87f855d211cf0e1174a5d721216b7616bd52d8581d912ed/cryptography-47.0.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:f5c15764f261394b22aef6b00252f5195f46f2ca300bec57149474e2538b31f8", size = 4668186, upload-time = "2026-04-24T19:53:09.053Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/81/b9/8443cfe5d17d482d348cee7048acf502bb89a51b6382f06240fd290d4ca3/cryptography-47.0.0-cp311-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:9c59ab0e0fa3a180a5a9c59f3a5abe3ef90d474bc56d7fadfbe80359491b615b", size = 4651244, upload-time = "2026-04-24T19:53:11.217Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/5d/5e/13ed0cdd0eb88ba159d6dd5ebfece8cb901dbcf1ae5ac4072e28b55d3153/cryptography-47.0.0-cp311-abi3-manylinux_2_28_ppc64le.whl", hash = "sha256:34b4358b925a5ea3e14384ca781a2c0ef7ac219b57bb9eacc4457078e2b19f92", size = 5252906, upload-time = "2026-04-24T19:53:13.532Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/64/16/ed058e1df0f33d440217cd120d41d5dda9dd215a80b8187f68483185af82/cryptography-47.0.0-cp311-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:0024b87d47ae2399165a6bfb20d24888881eeab83ae2566d62467c5ff0030ce7", size = 4701842, upload-time = "2026-04-24T19:53:15.618Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/02/e0/3d30986b30fdbd9e969abbdf8ba00ed0618615144341faeb57f395a084fe/cryptography-47.0.0-cp311-abi3-manylinux_2_31_armv7l.whl", hash = "sha256:1e47422b5557bb82d3fff997e8d92cff4e28b9789576984f08c248d2b3535d93", size = 4289313, upload-time = "2026-04-24T19:53:17.755Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/df/fd/32db38e3ad0cb331f0691cb4c7a8a6f176f679124dee746b3af6633db4d9/cryptography-47.0.0-cp311-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:6f29f36582e6151d9686235e586dd35bb67491f024767d10b842e520dc6a07ac", size = 4650964, upload-time = "2026-04-24T19:53:20.062Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/86/53/5395d944dfd48cb1f67917f533c609c34347185ef15eb4308024c876f274/cryptography-47.0.0-cp311-abi3-manylinux_2_34_ppc64le.whl", hash = "sha256:a9b761f012a943b7de0e828843c5688d0de94a0578d44d6c85a1bae32f87791f", size = 5207817, upload-time = "2026-04-24T19:53:22.498Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/34/4f/e5711b28e1901f7d480a2b1b688b645aa4c77c73f10731ed17e7f7db3f0d/cryptography-47.0.0-cp311-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:4e1de79e047e25d6e9f8cea71c86b4a53aced64134f0f003bbcbf3655fd172c8", size = 4701544, upload-time = "2026-04-24T19:53:24.356Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/22/22/c8ddc25de3010fc8da447648f5a092c40e7a8fadf01dd6d255d9c0b9373d/cryptography-47.0.0-cp311-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:ef6b3634087f18d2155b1e8ce264e5345a753da2c5fa9815e7d41315c90f8318", size = 4783536, upload-time = "2026-04-24T19:53:26.665Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/66/b6/d4a68f4ea999c6d89e8498579cba1c5fcba4276284de7773b17e4fa69293/cryptography-47.0.0-cp311-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:11dbb9f50a0f1bb9757b3d8c27c1101780efb8f0bdecfb12439c22a74d64c001", size = 4926106, upload-time = "2026-04-24T19:53:28.686Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/54/ed/5f524db1fade9c013aa618e1c99c6ed05e8ffc9ceee6cda22fed22dda3f4/cryptography-47.0.0-cp311-abi3-win32.whl", hash = "sha256:7fda2f02c9015db3f42bb8a22324a454516ed10a8c29ca6ece6cdbb5efe2a203", size = 3258581, upload-time = "2026-04-24T19:53:31.058Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/b2/dc/1b901990b174786569029f67542b3edf72ac068b6c3c8683c17e6a2f5363/cryptography-47.0.0-cp311-abi3-win_amd64.whl", hash = "sha256:f5c3296dab66202f1b18a91fa266be93d6aa0c2806ea3d67762c69f60adc71aa", size = 3775309, upload-time = "2026-04-24T19:53:33.054Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/14/88/7aa18ad9c11bc87689affa5ce4368d884b517502d75739d475fc6f4a03c7/cryptography-47.0.0-cp314-cp314t-macosx_10_9_universal2.whl", hash = "sha256:be12cb6a204f77ed968bcefe68086eb061695b540a3dd05edac507a3111b25f0", size = 7904299, upload-time = "2026-04-24T19:53:35.003Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/07/55/c18f75724544872f234678fdedc871391722cb34a2aee19faa9f63100bb2/cryptography-47.0.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:2ebd84adf0728c039a3be2700289378e1c164afc6748df1a5ed456767bef9ba7", size = 4631180, upload-time = "2026-04-24T19:53:37.517Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ee/65/31a5cc0eaca99cec5bafffe155d407115d96136bb161e8b49e0ef73f09a7/cryptography-47.0.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:7f68d6fbc7fbbcfb0939fea72c3b96a9f9a6edfc0e1b1d29778a2066030418b1", size = 4653529, upload-time = "2026-04-24T19:53:39.775Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e5/bc/641c0519a495f3bfd0421b48d7cd325c4336578523ccd76ea322b6c29c7a/cryptography-47.0.0-cp314-cp314t-manylinux_2_28_aarch64.whl", hash = "sha256:6651d32eff255423503aa276739da98c30f26c40cbeffcc6048e0d54ef704c0c", size = 4638570, upload-time = "2026-04-24T19:53:42.129Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/2b/f2/300327b0a47f6dc94dd8b71b57052aefe178bb51745073d73d80604f11ab/cryptography-47.0.0-cp314-cp314t-manylinux_2_28_ppc64le.whl", hash = "sha256:3fb8fa48075fad7193f2e5496135c6a76ac4b2aa5a38433df0a539296b377829", size = 5238019, upload-time = "2026-04-24T19:53:44.577Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e9/5a/5b5cf994391d4bf9d9c7efd4c66aabe4d95227256627f8fea6cff7dfadbd/cryptography-47.0.0-cp314-cp314t-manylinux_2_28_x86_64.whl", hash = "sha256:11438c7518132d95f354fa01a4aa2f806d172a061a7bed18cf18cbdacdb204d7", size = 4686832, upload-time = "2026-04-24T19:53:47.015Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/dc/2c/ae950e28fd6475c852fc21a44db3e6b5bcc1261d1e370f2b6e42fa800fef/cryptography-47.0.0-cp314-cp314t-manylinux_2_31_armv7l.whl", hash = "sha256:8c1a736bbb3288005796c3f7ccb9453360d7fed483b13b9f468aea5171432923", size = 4269301, upload-time = "2026-04-24T19:53:48.97Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/67/fb/6a39782e150ffe5cc1b0018cb6ddc48bf7ca62b498d7539ffc8a758e977d/cryptography-47.0.0-cp314-cp314t-manylinux_2_34_aarch64.whl", hash = "sha256:f1557695e5c2b86e204f6ce9470497848634100787935ab7adc5397c54abd7ab", size = 4638110, upload-time = "2026-04-24T19:53:51.011Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/8e/d7/0b3c71090a76e5c203164a47688b697635ece006dcd2499ab3a4dbd3f0bd/cryptography-47.0.0-cp314-cp314t-manylinux_2_34_ppc64le.whl", hash = "sha256:f9a034b642b960767fb343766ae5ba6ad653f2e890ddd82955aef288ffea8736", size = 5194988, upload-time = "2026-04-24T19:53:52.962Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/63/33/63a961498a9df51721ab578c5a2622661411fc520e00bd83b0cc64eb20c4/cryptography-47.0.0-cp314-cp314t-manylinux_2_34_x86_64.whl", hash = "sha256:b1c76fca783aa7698eb21eb14f9c4aa09452248ee54a627d125025a43f83e7a7", size = 4686563, upload-time = "2026-04-24T19:53:55.274Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/b7/bf/5ee5b145248f92250de86145d1c1d6edebbd57a7fe7caa4dedb5d4cf06a1/cryptography-47.0.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:4f7722c97826770bab8ae92959a2e7b20a5e9e9bf4deae68fd86c3ca457bab52", size = 4770094, upload-time = "2026-04-24T19:53:57.753Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/92/43/21d220b2da5d517773894dacdcdb5c682c28d3fffce65548cb06e87d5501/cryptography-47.0.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:09f6d7bf6724f8db8b32f11eccf23efc8e759924bc5603800335cf8859a3ddbd", size = 4913811, upload-time = "2026-04-24T19:54:00.236Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/31/98/dc4ad376ac5f1a1a7d4a83f7b0c6f2bcad36b5d2d8f30aeb482d3a7d9582/cryptography-47.0.0-cp314-cp314t-win32.whl", hash = "sha256:6eebcaf0df1d21ce1f90605c9b432dd2c4f4ab665ac29a40d5e3fc68f51b5e63", size = 3237158, upload-time = "2026-04-24T19:54:02.606Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/bc/da/97f62d18306b5133468bc3f8cc73a3111e8cdc8cf8d3e69474d6e5fd2d1b/cryptography-47.0.0-cp314-cp314t-win_amd64.whl", hash = "sha256:51c9313e90bd1690ec5a75ed047c27c0b8e6c570029712943d6116ef9a90620b", size = 3758706, upload-time = "2026-04-24T19:54:04.433Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e0/34/a4fae8ae7c3bc227460c9ae43f56abf1b911da0ec29e0ebac53bb0a4b6b7/cryptography-47.0.0-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:14432c8a9bcb37009784f9594a62fae211a2ae9543e96c92b2a8e4c3cd5cd0c4", size = 7904072, upload-time = "2026-04-24T19:54:06.411Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/01/64/d7b1e54fdb69f22d24a64bb3e88dc718b31c7fb10ef0b9691a3cf7eeea6e/cryptography-47.0.0-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:07efe86201817e7d3c18781ca9770bc0db04e1e48c994be384e4602bc38f8f27", size = 4635767, upload-time = "2026-04-24T19:54:08.519Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/8b/7b/cca826391fb2a94efdcdfe4631eb69306ee1cff0b22f664a412c90713877/cryptography-47.0.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:2b45761c6ec22b7c726d6a829558777e32d0f1c8be7c3f3480f9c912d5ee8a10", size = 4654350, upload-time = "2026-04-24T19:54:10.795Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/4c/65/4b57bcc823f42a991627c51c2f68c9fd6eb1393c1756aac876cba2accae2/cryptography-47.0.0-cp38-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:edd4da498015da5b9f26d38d3bfc2e90257bfa9cbed1f6767c282a0025ae649b", size = 4643394, upload-time = "2026-04-24T19:54:13.275Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/f4/c4/2c5fbeea70adbbca2bbae865e1d605d6a4a7f8dbd9d33eaf69645087f06c/cryptography-47.0.0-cp38-abi3-manylinux_2_28_ppc64le.whl", hash = "sha256:9af828c0d5a65c70ec729cd7495a4bf1a67ecb66417b8f02ff125ab8a6326a74", size = 5225777, upload-time = "2026-04-24T19:54:15.18Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/7e/b8/ac57107ef32749d2b244e36069bb688792a363aaaa3acc9e3cf84c130315/cryptography-47.0.0-cp38-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:256d07c78a04d6b276f5df935a9923275f53bd1522f214447fdf365494e2d515", size = 4688771, upload-time = "2026-04-24T19:54:17.835Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/56/fc/9f1de22ff8be99d991f240a46863c52d475404c408886c5a38d2b5c3bb26/cryptography-47.0.0-cp38-abi3-manylinux_2_31_armv7l.whl", hash = "sha256:5d0e362ff51041b0c0d219cc7d6924d7b8996f57ce5712bdcef71eb3c65a59cc", size = 4270753, upload-time = "2026-04-24T19:54:19.963Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/00/68/d70c852797aa68e8e48d12e5a87170c43f67bb4a59403627259dd57d15de/cryptography-47.0.0-cp38-abi3-manylinux_2_34_aarch64.whl", hash = "sha256:1581aef4219f7ca2849d0250edaa3866212fb74bf5667284f46aa92f9e65c1ca", size = 4642911, upload-time = "2026-04-24T19:54:21.818Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a5/51/661cbee74f594c5d97ff82d34f10d5551c085ca4668645f4606ebd22bd5d/cryptography-47.0.0-cp38-abi3-manylinux_2_34_ppc64le.whl", hash = "sha256:a49a3eb5341b9503fa3000a9a0db033161db90d47285291f53c2a9d2cd1b7f76", size = 5181411, upload-time = "2026-04-24T19:54:24.376Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/94/87/f2b6c374a82cf076cfa1416992ac8e8ec94d79facc37aec87c1a5cb72352/cryptography-47.0.0-cp38-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:2207a498b03275d0051589e326b79d4cf59985c99031b05bb292ac52631c37fe", size = 4688262, upload-time = "2026-04-24T19:54:26.946Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/14/e2/8b7462f4acf21ec509616f0245018bb197194ab0b65c2ea21a0bdd53c0eb/cryptography-47.0.0-cp38-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:7a02675e2fabd0c0fc04c868b8781863cbf1967691543c22f5470500ff840b31", size = 4775506, upload-time = "2026-04-24T19:54:28.926Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/70/75/158e494e4c08dc05e039da5bb48553826bd26c23930cf8d3cd5f21fa8921/cryptography-47.0.0-cp38-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:80887c5cbd1774683cb126f0ab4184567f080071d5acf62205acb354b4b753b7", size = 4912060, upload-time = "2026-04-24T19:54:30.869Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/06/bd/0a9d3edbf5eadbac926d7b9b3cd0c4be584eeeae4a003d24d9eda4affbbd/cryptography-47.0.0-cp38-abi3-win32.whl", hash = "sha256:ed67ea4e0cfb5faa5bc7ecb6e2b8838f3807a03758eec239d6c21c8769355310", size = 3248487, upload-time = "2026-04-24T19:54:33.494Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/60/80/5681af756d0da3a599b7bdb586fac5a1540f1bcefd2717a20e611ddade45/cryptography-47.0.0-cp38-abi3-win_amd64.whl", hash = "sha256:835d2d7f47cdc53b3224e90810fb1d36ca94ea29cc1801fb4c1bc43876735769", size = 3755737, upload-time = "2026-04-24T19:54:35.408Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "distro"
|
name = "distro"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
@@ -382,15 +272,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/12/b3/231ffd4ab1fc9d679809f356cebee130ac7daa00d6d6f3206dd4fd137e9e/distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2", size = 20277, upload-time = "2023-12-24T09:54:30.421Z" },
|
{ url = "https://files.pythonhosted.org/packages/12/b3/231ffd4ab1fc9d679809f356cebee130ac7daa00d6d6f3206dd4fd137e9e/distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2", size = 20277, upload-time = "2023-12-24T09:54:30.421Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "docstring-parser"
|
|
||||||
version = "0.18.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/e0/4d/f332313098c1de1b2d2ff91cf2674415cc7cddab2ca1b01ae29774bd5fdf/docstring_parser-0.18.0.tar.gz", hash = "sha256:292510982205c12b1248696f44959db3cdd1740237a968ea1e2e7a900eeb2015", size = 29341, upload-time = "2026-04-14T04:09:19.867Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a7/5f/ed01f9a3cdffbd5a008556fc7b2a08ddb1cc6ace7effa7340604b1d16699/docstring_parser-0.18.0-py3-none-any.whl", hash = "sha256:b3fcbed555c47d8479be0796ef7e19c2670d428d72e96da63f3a40122860374b", size = 22484, upload-time = "2026-04-14T04:09:18.638Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "frozenlist"
|
name = "frozenlist"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
@@ -479,15 +360,15 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "google-auth"
|
name = "google-auth"
|
||||||
version = "2.50.0"
|
version = "2.47.0"
|
||||||
source = { registry = "https://pypi.org/simple" }
|
source = { registry = "https://pypi.org/simple" }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "cryptography" },
|
|
||||||
{ name = "pyasn1-modules" },
|
{ name = "pyasn1-modules" },
|
||||||
|
{ name = "rsa" },
|
||||||
]
|
]
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/5f/18/238d7021d151bdab868f23433817b027dd759135202f4dfce0670d1230ca/google_auth-2.50.0.tar.gz", hash = "sha256:f35eafb191195328e8ce10a7883970877e7aeb49c2bfaa54aa0e394316d353d0", size = 336523, upload-time = "2026-04-30T21:19:29.659Z" }
|
sdist = { url = "https://files.pythonhosted.org/packages/60/3c/ec64b9a275ca22fa1cd3b6e77fefcf837b0732c890aa32d2bd21313d9b33/google_auth-2.47.0.tar.gz", hash = "sha256:833229070a9dfee1a353ae9877dcd2dec069a8281a4e72e72f77d4a70ff945da", size = 323719, upload-time = "2026-01-06T21:55:31.045Z" }
|
||||||
wheels = [
|
wheels = [
|
||||||
{ url = "https://files.pythonhosted.org/packages/37/cf/4880c2137c14280b2f59975cdf12cc442bc0ae1f9ea473a26eaa0c146786/google_auth-2.50.0-py3-none-any.whl", hash = "sha256:04382175e28b94f49694977f0a792688b59a668def1499e9d8de996dc9ce5b15", size = 246495, upload-time = "2026-04-30T21:19:27.664Z" },
|
{ url = "https://files.pythonhosted.org/packages/db/18/79e9008530b79527e0d5f79e7eef08d3b179b7f851cfd3a2f27822fbdfa9/google_auth-2.47.0-py3-none-any.whl", hash = "sha256:c516d68336bfde7cf0da26aab674a36fedcf04b37ac4edd59c597178760c3498", size = 234867, upload-time = "2026-01-06T21:55:28.6Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.optional-dependencies]
|
[package.optional-dependencies]
|
||||||
@@ -497,7 +378,7 @@ requests = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "google-genai"
|
name = "google-genai"
|
||||||
version = "1.74.0"
|
version = "1.59.0"
|
||||||
source = { registry = "https://pypi.org/simple" }
|
source = { registry = "https://pypi.org/simple" }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "anyio" },
|
{ name = "anyio" },
|
||||||
@@ -511,18 +392,21 @@ dependencies = [
|
|||||||
{ name = "typing-extensions" },
|
{ name = "typing-extensions" },
|
||||||
{ name = "websockets" },
|
{ name = "websockets" },
|
||||||
]
|
]
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/33/c8/4a8f1de0a3268d526a345b8c74456b3e1e6ffd200982626326cf7ca83e5b/google_genai-1.74.0.tar.gz", hash = "sha256:c4c473cebdeb6e5adbb0639326de66a3a85a2209e0d32de7d66bf05c698abae8", size = 536772, upload-time = "2026-04-29T22:16:35.881Z" }
|
sdist = { url = "https://files.pythonhosted.org/packages/40/34/c03bcbc759d67ac3d96077838cdc1eac85417de6ea3b65b313fe53043eee/google_genai-1.59.0.tar.gz", hash = "sha256:0b7a2dc24582850ae57294209d8dfc2c4f5fcfde0a3f11d81dc5aca75fb619e2", size = 487374, upload-time = "2026-01-15T20:29:46.619Z" }
|
||||||
wheels = [
|
wheels = [
|
||||||
{ url = "https://files.pythonhosted.org/packages/ca/2b/539c328b66f7bfef2df869371a1789361228e5a7694ba02a642608367b46/google_genai-1.74.0-py3-none-any.whl", hash = "sha256:87d0b311c67d4b2a0ca741e9fc6891330c29defae81d46d8db41079aa1a3d80a", size = 790433, upload-time = "2026-04-29T22:16:33.979Z" },
|
{ url = "https://files.pythonhosted.org/packages/aa/53/6d00692fe50d73409b3406ae90c71bc4499c8ae7fac377ba16e283da917c/google_genai-1.59.0-py3-none-any.whl", hash = "sha256:59fc01a225d074fe9d1e626c3433da292f33249dadce4deb34edea698305a6df", size = 719099, upload-time = "2026-01-15T20:29:44.604Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "griffelib"
|
name = "griffe"
|
||||||
version = "2.0.2"
|
version = "1.15.0"
|
||||||
source = { registry = "https://pypi.org/simple" }
|
source = { registry = "https://pypi.org/simple" }
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/9d/82/74f4a3310cdabfbb10da554c3a672847f1ed33c6f61dd472681ce7f1fe67/griffelib-2.0.2.tar.gz", hash = "sha256:3cf20b3bc470e83763ffbf236e0076b1211bac1bc67de13daf494640f2de707e", size = 166461, upload-time = "2026-03-27T11:34:51.091Z" }
|
dependencies = [
|
||||||
|
{ name = "colorama" },
|
||||||
|
]
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/0d/0c/3a471b6e31951dce2360477420d0a8d1e00dea6cf33b70f3e8c3ab6e28e1/griffe-1.15.0.tar.gz", hash = "sha256:7726e3afd6f298fbc3696e67958803e7ac843c1cfe59734b6251a40cdbfb5eea", size = 424112, upload-time = "2025-11-10T15:03:15.52Z" }
|
||||||
wheels = [
|
wheels = [
|
||||||
{ url = "https://files.pythonhosted.org/packages/11/8c/c9138d881c79aa0ea9ed83cbd58d5ca75624378b38cee225dcf5c42cc91f/griffelib-2.0.2-py3-none-any.whl", hash = "sha256:925c857658fb1ba40c0772c37acbc2ab650bd794d9c1b9726922e36ea4117ea1", size = 142357, upload-time = "2026-03-27T11:34:46.275Z" },
|
{ url = "https://files.pythonhosted.org/packages/9c/83/3b1d03d36f224edded98e9affd0467630fc09d766c0e56fb1498cbb04a9b/griffe-1.15.0-py3-none-any.whl", hash = "sha256:6f6762661949411031f5fcda9593f586e6ce8340f0ba88921a0f2ef7a81eb9a3", size = 150705, upload-time = "2025-11-10T15:03:13.549Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -583,60 +467,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/fa/5e/f8e9a1d23b9c20a551a8a02ea3637b4642e22c2626e3a13a9a29cdea99eb/importlib_metadata-8.7.1-py3-none-any.whl", hash = "sha256:5a1f80bf1daa489495071efbb095d75a634cf28a8bc299581244063b53176151", size = 27865, upload-time = "2025-12-21T10:00:18.329Z" },
|
{ url = "https://files.pythonhosted.org/packages/fa/5e/f8e9a1d23b9c20a551a8a02ea3637b4642e22c2626e3a13a9a29cdea99eb/importlib_metadata-8.7.1-py3-none-any.whl", hash = "sha256:5a1f80bf1daa489495071efbb095d75a634cf28a8bc299581244063b53176151", size = 27865, upload-time = "2025-12-21T10:00:18.329Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jiter"
|
|
||||||
version = "0.15.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/66/b5/55f06bb281d92fb3cc86d14e1def2bd908bb77693183e7cb1f5a3c388b0c/jiter-0.15.0.tar.gz", hash = "sha256:4251acc80e2b7c9b7b8823456ea0fceeb0734dac2df7636d3c711b38476b5a76", size = 166640, upload-time = "2026-05-19T10:09:48.361Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e5/f4/f708c900ecee41b2025ef8413d5351e5649eb2125c506f6720cc69b06f5c/jiter-0.15.0-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:1c11465f97e2abf45a014b83b730222f8f1c5335e802c7055a67d50de6f1f4e3", size = 307829, upload-time = "2026-05-19T10:07:59.704Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/86/59/db537c0949e83668c38481d426b9f2fd5ab758c4ee53a811dd0a510626a0/jiter-0.15.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:d1e7b1776f0797956c509e123d0952d10d293a9492dea9f288ab9570ec01d1a5", size = 308445, upload-time = "2026-05-19T10:08:01.184Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/37/38/ea0e13b18c30ef951da0d47d39e7fa9edb82a93a62990ffbd7cea9b622d4/jiter-0.15.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:351a341c2105aa430b7047e30f1bf7975f6313b00165d3fc07be2edaf741f279", size = 336181, upload-time = "2026-05-19T10:08:02.688Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/58/fc/2303901b16c4ba05865588990a420c0b4156270b44379c20931544a1d962/jiter-0.15.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:4ab395feec8d249ec4044e228e98a7033f043426a265df439dc3698823f0a4e4", size = 362985, upload-time = "2026-05-19T10:08:04.394Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/5b/6f/11bace093c52e7d4d26c8e606ccd7ae8c972189622469ec0d9e28161e28b/jiter-0.15.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a2a438005b6f22d0273413484d6094d7c2c5d10ec1b3a3bf128e0d1d3ba53258", size = 453292, upload-time = "2026-05-19T10:08:05.967Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/22/db/987f2f086ca4d7a6582eb4ccd513f9b26b42d9e4243a087609a3137a8fc7/jiter-0.15.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f18f85e4218d1b40f000f42a92239a7a61a902cd42c65e6c360dbd17dcb20894", size = 373501, upload-time = "2026-05-19T10:08:07.857Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/8f/7c/89fbcabb2739b7a5b8dc959a1b6c5761f6484f5fed3486854b3c789bb1de/jiter-0.15.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d1aa62e277fc1cbd80e6deacae6f4d983b41b3d7728e0645c5d741a6149bba45", size = 344683, upload-time = "2026-05-19T10:08:09.431Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/30/6f/6cca7692e7dddfec6d8d76c54dc97f2af2a41df4ac0674b999df1f09a5f3/jiter-0.15.0-cp313-cp313-manylinux_2_31_riscv64.whl", hash = "sha256:6550fa135c7deb8ead6af49ed7ff648532ea8334a1447fe34a36315ef79c5c29", size = 350892, upload-time = "2026-05-19T10:08:11.352Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/39/14/0338d6190cb8e6d22e677ab1d4eabd4117f67cca70c54cd04b82ff64e068/jiter-0.15.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:066f8f33f18b2419cd8213b2436fa7fbc9c499f315971cfa3ce1f9820c001b1b", size = 388723, upload-time = "2026-05-19T10:08:12.912Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/90/31/cc19f4a1bdb6afb09ce6a2f2615aa8d44d994eba0d8e6105ed1af920e736/jiter-0.15.0-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:75e8a04e91432dde9f1838373cf93d23726c79d3e908d319acf0e796f85592e7", size = 516648, upload-time = "2026-05-19T10:08:14.808Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/49/9f/833c541512cd091b63c10c0381973dfe11bc7a503a818c16384417e0c81e/jiter-0.15.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:a97261f1fccb8e50ecd2890a96e46efdc3f57c80a197324c6777827231eca712", size = 547382, upload-time = "2026-05-19T10:08:16.927Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/d2/11/e7b70e91f90bc4477e8eee9e8a5f7cf3cb41b4525d6394dc98a714eb8f7f/jiter-0.15.0-cp313-cp313-win32.whl", hash = "sha256:c77496cb10bd7549690fbbab3e5ec05857b83e49276f4a9423a766ddd2afcd4c", size = 205845, upload-time = "2026-05-19T10:08:18.401Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/4b/23/5c20d9ad6f02c493e4023e5d2d09e1c1f15fe2753c9102c544aff068a88e/jiter-0.15.0-cp313-cp313-win_amd64.whl", hash = "sha256:b15741f501469009ae0ae90b7147958a664a7dede40aa7ff174a8a4645f546d0", size = 196842, upload-time = "2026-05-19T10:08:20.131Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/6b/11/1eb400ef248e8c925fd883fbe325daf5e42cd1b0d308539dd332bd4f7ffc/jiter-0.15.0-cp313-cp313-win_arm64.whl", hash = "sha256:5d6a60072b44c3c2b797a7ddcbcbbf2b34ea3cfd4721580fbfd2a09d9d9b84ba", size = 192212, upload-time = "2026-05-19T10:08:21.807Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/8a/60/2fd8d7c79da8acf9b7b277c7616847773779356b92acfc9bb158452174da/jiter-0.15.0-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:ef1fd24d9413f6209e00d3d5a453e67acfe004a25cc6c8e8484faed4311ab9e8", size = 315065, upload-time = "2026-05-19T10:08:23.218Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/46/f4/008fb7d65e8ac2abf00811651a661e025c4ba80bbc6f378450384ddd3aed/jiter-0.15.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:144f8e72cb53dab146347b91cceac01f5481237f2b93b4a339a1ee8f8878b67c", size = 339444, upload-time = "2026-05-19T10:08:24.701Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/00/55/90b0c7b9c6896c0f2a591dd36d36b71d22e09674bfef178fa03ba3f81499/jiter-0.15.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:553fcac2ef2cb990877f9fc0833b8b629a3e6a5670b6b5fd58219b41a653ddc4", size = 347779, upload-time = "2026-05-19T10:08:26.408Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/51/6b/69666cec5000fd57734c118437394516c749ae8dbeea9fb66d6fef9c4775/jiter-0.15.0-cp313-cp313t-win_amd64.whl", hash = "sha256:774f93f65031856bf14ad9f59bdcab8b8cad501e5ceabd51ba3525f76937a25b", size = 200395, upload-time = "2026-05-19T10:08:28.055Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/39/04/a6aa62cd27e8149b0d28df5561f10f6cceaf7935a9ccf3f1c5a05f9a0cd8/jiter-0.15.0-cp313-cp313t-win_arm64.whl", hash = "sha256:f1e1754960f38ec40613a07e5e372df67acb3b890fb383b6fb3de3e49ddbf3c7", size = 190516, upload-time = "2026-05-19T10:08:29.35Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/eb/d2/079f350ebf7859d081de30aa890f9e3be68516f754f3ba32366ffff4dcee/jiter-0.15.0-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:ac0d9ddea4350974be7a221fc25895f251a8fee748c889bdced2141c0fec1a49", size = 308884, upload-time = "2026-05-19T10:08:31.667Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/04/4e/a2c30a7f69b48c03b20935d647479106fe932f6e63f75faf53937197e05d/jiter-0.15.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:01a8222cf05ab1128e239421156c207949808acaaea2bdfd33130ae666786e86", size = 310028, upload-time = "2026-05-19T10:08:33.304Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/40/90/2e7cdfd3cf8ca967be38c48f5cf474d79f089efaf559a40f15984a77ae69/jiter-0.15.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:182226cbc930c9fab81bc2e41a4da672f89539906dadb05e75670ac07b94f71f", size = 337485, upload-time = "2026-05-19T10:08:35.259Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/9b/11/15a1aa28b120b8ee5b4f1fb894c125046225f09847738bd64233d3b84883/jiter-0.15.0-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:71683c38c825452999b5717fcae07ea708e8c93003e808be4319c1b02e3d176e", size = 364223, upload-time = "2026-05-19T10:08:36.694Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/b7/25/f442e8af5f3d0dcf47b39e83a0efd9ee45ea946aa6d04625dc3181eae3b6/jiter-0.15.0-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:30f2218e6a9e5c18bc10fe6d41ac189c442c88eacf11bad9f28ef95a9bef00e6", size = 456387, upload-time = "2026-05-19T10:08:38.143Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/da/f4/37f2d2c9f64f49af7da652ed7532bb5a2372e588e6927c3fdd76f911db65/jiter-0.15.0-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5157de9f76eb4bc5ea74a1219366a25f945ad305641d74e04f59c54087091aa9", size = 374461, upload-time = "2026-05-19T10:08:39.869Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/60/28/edcfbbbf0cb15436f36664a8908a0df47ab9006298d4cd937dc08ea932d6/jiter-0.15.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:90c5db5527c221249a876160663ab891ace358c17f7b9c93ec1478b7f0550e5c", size = 345924, upload-time = "2026-05-19T10:08:41.668Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/47/13/89fba6398dab7f202b7278c4b4aac122399d2c0183971c4a57a3b7088df5/jiter-0.15.0-cp314-cp314-manylinux_2_31_riscv64.whl", hash = "sha256:3e4540b8e74e4268811ac05db226a6a128ff572e7e0ce3f1163b693cadb184cd", size = 352283, upload-time = "2026-05-19T10:08:43.091Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/1b/da/0f6af8cef2c565a1ab44d970f268c43ccaa72707386ea6388e6fe2b6cd26/jiter-0.15.0-cp314-cp314-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:62ebd14e47e9aed9df4472afcb2663668ce4d74891cd54f86bf6e44029d6dc89", size = 389985, upload-time = "2026-05-19T10:08:44.915Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a1/ec/b9cb7d6d29e24ee14910266157d2a279d7a8f60ee0df7fa840882976ba64/jiter-0.15.0-cp314-cp314-musllinux_1_1_aarch64.whl", hash = "sha256:0be6f5ad41a809f303f416d17cec92a7a725902fb9b4f3de3d19362ac0ef8554", size = 517695, upload-time = "2026-05-19T10:08:46.486Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/64/5e/6d1bda880723aae0ad86b4b763f044362448efe31e3e819635d41cb03451/jiter-0.15.0-cp314-cp314-musllinux_1_1_x86_64.whl", hash = "sha256:813dfbb17d65328bf86e5f0905dd277ba2265d3ca20556e86c0c7035b7182e5a", size = 548868, upload-time = "2026-05-19T10:08:48.026Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/0c/72/7de501cf38dcacaf35098796f3a50e0f2e338baba18a58946c618544b809/jiter-0.15.0-cp314-cp314-win32.whl", hash = "sha256:50e51156192722a9c58db112837d3f8ef96fb3c5ecc14e95f409134b08b158ec", size = 206380, upload-time = "2026-05-19T10:08:49.738Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/1e/a9/e19addf4b0c1bdce52c6da12351e6bc42c340c45e7c09e2158e46d293ccc/jiter-0.15.0-cp314-cp314-win_amd64.whl", hash = "sha256:30ce1a5d16b5641dc935d50ef775af6a0871e3d14ab05d6fc54dff371b78e558", size = 197687, upload-time = "2026-05-19T10:08:51.088Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/f2/c9/776b1db01db25fc6c1d58d1979a37b0a9fe787e5f5b1d062d2eaacb77923/jiter-0.15.0-cp314-cp314-win_arm64.whl", hash = "sha256:510c8b3c17a0ed9ac69850c0438dada3c9b82d9c4d589fcb62002a5a9cf3a866", size = 192571, upload-time = "2026-05-19T10:08:52.451Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a0/f6/45bb4670bacf300fd2c7abadbfb3af376e5f1b6ae75fd9bc069891d15870/jiter-0.15.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:7553333dd0930c104a5a0db8df72bf7219fe663d731383b576bb6ed6351c984d", size = 317151, upload-time = "2026-05-19T10:08:53.867Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/d7/68/ed635ad5acd7b73e454283083bbb7c8205ad10e88b0d9d7d793b09fe8226/jiter-0.15.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f2143ab06181d2b029eedcb6af3cebe95f11bbac62441781860f98ee9330a6a6", size = 341243, upload-time = "2026-05-19T10:08:55.383Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/5d/db/3ff4176b817b8ea33879e71e13d8bc2b0d481a7ed3fe9e080f333d415c16/jiter-0.15.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:6eac374c5c975709b69c10f09afd199df74150172156ad10c8d4fd785b7da995", size = 363629, upload-time = "2026-05-19T10:08:56.928Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ab/24/5f8270e0ba9c883582f96f722f8a0b58015c7ce1f8c6d4571cf394e99b6b/jiter-0.15.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b3b3b775e33d3bfaec9899edc526ae97b0da0bf9d071a46124ba419149a414f8", size = 456198, upload-time = "2026-05-19T10:08:58.618Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/45/5b/76fc02b0b5c54c3d18c60653156e2f76fde1816f9b4722db68d6ee2c897e/jiter-0.15.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:eda3071db3346334beae1360b46da4606da57bf3528c167b3c38533afaf9f2c5", size = 373710, upload-time = "2026-05-19T10:09:00.151Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/c4/52/4310821b0ea9277994d3e1f49fc6a4b34e4800caebacb2c0af81da59a454/jiter-0.15.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c6694a173ecabc12eb60efbc0b474464ead1951ff65cd8b1e72100715c64512b", size = 349901, upload-time = "2026-05-19T10:09:01.621Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/93/fe/67648c35b3594fba8854ac64cc8a826d8bcd18324bbdb53d77697c60b6ef/jiter-0.15.0-cp314-cp314t-manylinux_2_31_riscv64.whl", hash = "sha256:a254e10b593624d230c365b6d616b22ca0ad65e63a16e6631c2b3466022e6ba8", size = 352438, upload-time = "2026-05-19T10:09:03.216Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/cb/28/0a1879d07ad6b3e025a2750027363452ced93c2d16d1c9d4b153ffd51c91/jiter-0.15.0-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:d8d2955167274e15d79a7a020afdd9b39c990eb80b2d89fca695d92dcfdd38ec", size = 388152, upload-time = "2026-05-19T10:09:04.741Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/c1/78/46c6f6b56ba85c90021f4afd72ed42f691f8f84daacb5fe27277070e3858/jiter-0.15.0-cp314-cp314t-musllinux_1_1_aarch64.whl", hash = "sha256:acf4ee4d1fc55917239fe72972fb292dd773055d05eb040d36f4326e02cc2c0e", size = 517707, upload-time = "2026-05-19T10:09:06.231Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ca/cb/720662d4c88fcad606e826fef5424365527ba43ce4868a479aed8f8c507e/jiter-0.15.0-cp314-cp314t-musllinux_1_1_x86_64.whl", hash = "sha256:e7196e56f1cd69af1dbb07dff02dcfb260a50b45a82d409d92a06fedb32473b5", size = 548241, upload-time = "2026-05-19T10:09:08.093Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/60/e3/935b8034fd143f21125c87d51404a9e0e1449186a494405721ff5d1d695e/jiter-0.15.0-cp314-cp314t-win32.whl", hash = "sha256:7f6163c0f10b055245f814dcc59f4818da60dfe72f3e72ab89fc24b6bd5e9c52", size = 207950, upload-time = "2026-05-19T10:09:09.616Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/93/59/984fd9ece895953dad3e0880a650e766f5a2da2c5514f0eafdaaabbeb5f9/jiter-0.15.0-cp314-cp314t-win_amd64.whl", hash = "sha256:980c256edb05b78a111b99c4de3b1d32e31634b867fd1fc2cf726e7b7bba9854", size = 200055, upload-time = "2026-05-19T10:09:11.367Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/0e/a4/cf8d779feb133a27a2e3bc833bccb9e13aa332cdf820497ebf72c10ce8c3/jiter-0.15.0-cp314-cp314t-win_arm64.whl", hash = "sha256:66b1880df2d01e206e8339769d1c7c1753bcb653efd6289e203f6f24ebada0c0", size = 191244, upload-time = "2026-05-19T10:09:12.74Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "logfire-api"
|
name = "logfire-api"
|
||||||
version = "4.19.0"
|
version = "4.19.0"
|
||||||
@@ -860,15 +690,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/47/8d/d529b5d697919ba8c11ad626e835d4039be708a35b0d22de83a269a6682c/pyasn1_modules-0.4.2-py3-none-any.whl", hash = "sha256:29253a9207ce32b64c3ac6600edc75368f98473906e8fd1043bd6b5b1de2c14a", size = 181259, upload-time = "2025-03-28T02:41:19.028Z" },
|
{ url = "https://files.pythonhosted.org/packages/47/8d/d529b5d697919ba8c11ad626e835d4039be708a35b0d22de83a269a6682c/pyasn1_modules-0.4.2-py3-none-any.whl", hash = "sha256:29253a9207ce32b64c3ac6600edc75368f98473906e8fd1043bd6b5b1de2c14a", size = 181259, upload-time = "2025-03-28T02:41:19.028Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pycparser"
|
|
||||||
version = "3.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/1b/7d/92392ff7815c21062bea51aa7b87d45576f649f16458d78b7cf94b9ab2e6/pycparser-3.0.tar.gz", hash = "sha256:600f49d217304a5902ac3c37e1281c9fe94e4d0489de643a9504c5cdfdfc6b29", size = 103492, upload-time = "2026-01-21T14:26:51.89Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/0c/c3/44f3fbbfa403ea2a7c779186dc20772604442dde72947e7d01069cbe98e3/pycparser-3.0-py3-none-any.whl", hash = "sha256:b727414169a36b7d524c1c3e31839a521725078d7b2ff038656844266160a992", size = 48172, upload-time = "2026-01-21T14:26:50.693Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pydantic"
|
name = "pydantic"
|
||||||
version = "2.12.5"
|
version = "2.12.5"
|
||||||
@@ -886,26 +707,23 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pydantic-ai-slim"
|
name = "pydantic-ai-slim"
|
||||||
version = "1.89.1"
|
version = "1.44.0"
|
||||||
source = { registry = "https://pypi.org/simple" }
|
source = { registry = "https://pypi.org/simple" }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "genai-prices" },
|
{ name = "genai-prices" },
|
||||||
{ name = "griffelib" },
|
{ name = "griffe" },
|
||||||
{ name = "httpx" },
|
{ name = "httpx" },
|
||||||
{ name = "opentelemetry-api" },
|
{ name = "opentelemetry-api" },
|
||||||
{ name = "pydantic" },
|
{ name = "pydantic" },
|
||||||
{ name = "pydantic-graph" },
|
{ name = "pydantic-graph" },
|
||||||
{ name = "typing-inspection" },
|
{ name = "typing-inspection" },
|
||||||
]
|
]
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/23/91/b2134056eb5debb7cb28e4efe7ca19fc5c7b2935e55b299a30ddad0d7746/pydantic_ai_slim-1.89.1.tar.gz", hash = "sha256:3ed967bff8dec992a907c1d1dabab2034a5f4aee75289de22e88b2ef9def8da6", size = 614728, upload-time = "2026-05-01T19:09:38.551Z" }
|
sdist = { url = "https://files.pythonhosted.org/packages/24/73/122aafb9bcad78042e2799649db745c357fc594e112c0ad0d8d183fdc447/pydantic_ai_slim-1.44.0.tar.gz", hash = "sha256:1bda6dbec4b94d8e52e32eb1e4c1da14f4f0202414306c65e2c3b43bebd82407", size = 378362, upload-time = "2026-01-17T01:26:09.64Z" }
|
||||||
wheels = [
|
wheels = [
|
||||||
{ url = "https://files.pythonhosted.org/packages/95/14/d0f7c8f828c460a517531e0df7cfe9e20f4315da8357a9068caaf0193bbb/pydantic_ai_slim-1.89.1-py3-none-any.whl", hash = "sha256:9e7d615a0a3e48993d067901e596e85708e9c8d1f6bef96c20c340385028d465", size = 780314, upload-time = "2026-05-01T19:09:28.843Z" },
|
{ url = "https://files.pythonhosted.org/packages/1a/18/2f68a9718843a95c0b4724ab3821ef8f60f7b8ef50e70b3769db3259da81/pydantic_ai_slim-1.44.0-py3-none-any.whl", hash = "sha256:3bf412f43d3ae787350d671f873706ad74603777e04f42411c8fbdf7dced8031", size = 496441, upload-time = "2026-01-17T01:26:00.184Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.optional-dependencies]
|
[package.optional-dependencies]
|
||||||
anthropic = [
|
|
||||||
{ name = "anthropic" },
|
|
||||||
]
|
|
||||||
google = [
|
google = [
|
||||||
{ name = "google-genai" },
|
{ name = "google-genai" },
|
||||||
]
|
]
|
||||||
@@ -965,7 +783,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pydantic-graph"
|
name = "pydantic-graph"
|
||||||
version = "1.89.1"
|
version = "1.44.0"
|
||||||
source = { registry = "https://pypi.org/simple" }
|
source = { registry = "https://pypi.org/simple" }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "httpx" },
|
{ name = "httpx" },
|
||||||
@@ -973,9 +791,9 @@ dependencies = [
|
|||||||
{ name = "pydantic" },
|
{ name = "pydantic" },
|
||||||
{ name = "typing-inspection" },
|
{ name = "typing-inspection" },
|
||||||
]
|
]
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/ea/64/f26c4d17568ab06ae576af0771ad83753cc2661bf9ca5a5698d01404ee20/pydantic_graph-1.89.1.tar.gz", hash = "sha256:99b8ae10fd10400208ee469355969e2dc253a600c3f667a5e790874064846e85", size = 59257, upload-time = "2026-05-01T19:09:40.998Z" }
|
sdist = { url = "https://files.pythonhosted.org/packages/aa/d9/83f1921633634cb1fd5947ebdc48a992cd1e660d9d0ba10f23450af654b8/pydantic_graph-1.44.0.tar.gz", hash = "sha256:81bb14bb47d3313fd7114f3ae9650dab77729451659e0247d298e1800f997c23", size = 58454, upload-time = "2026-01-17T01:26:12.113Z" }
|
||||||
wheels = [
|
wheels = [
|
||||||
{ url = "https://files.pythonhosted.org/packages/7e/52/9070e11f52424fe34e2ca96ae122902cab7c4325e2a90b33d44a410843b1/pydantic_graph-1.89.1-py3-none-any.whl", hash = "sha256:2ebce28573e81de9924c2ff68f90f949ccd96bbc2e8dc6cf4bb96208b34fbec0", size = 73065, upload-time = "2026-05-01T19:09:32.912Z" },
|
{ url = "https://files.pythonhosted.org/packages/6f/e6/f9ed700171435309e214cf19012cf3b391d10ec28786d4a567ee315b1acd/pydantic_graph-1.44.0-py3-none-any.whl", hash = "sha256:5affbfe5779f79946de2c6a6524b98e2344982a129b2a1e19d031e76a5bc1e51", size = 72324, upload-time = "2026-01-17T01:26:04.119Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1038,6 +856,18 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/25/7a/b0178788f8dc6cafce37a212c99565fa1fe7872c70c6c9c1e1a372d9d88f/rich-14.2.0-py3-none-any.whl", hash = "sha256:76bc51fe2e57d2b1be1f96c524b890b816e334ab4c1e45888799bfaab0021edd", size = 243393, upload-time = "2025-10-09T14:16:51.245Z" },
|
{ url = "https://files.pythonhosted.org/packages/25/7a/b0178788f8dc6cafce37a212c99565fa1fe7872c70c6c9c1e1a372d9d88f/rich-14.2.0-py3-none-any.whl", hash = "sha256:76bc51fe2e57d2b1be1f96c524b890b816e334ab4c1e45888799bfaab0021edd", size = 243393, upload-time = "2025-10-09T14:16:51.245Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rsa"
|
||||||
|
version = "4.9.1"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "pyasn1" },
|
||||||
|
]
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/da/8a/22b7beea3ee0d44b1916c0c1cb0ee3af23b700b6da9f04991899d0c555d4/rsa-4.9.1.tar.gz", hash = "sha256:e7bdbfdb5497da4c07dfd35530e1a902659db6ff241e39d9953cad06ebd0ae75", size = 29034, upload-time = "2025-04-16T09:51:18.218Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/64/8d/0133e4eb4beed9e425d9a98ed6e081a55d195481b7632472be1af08d2f6b/rsa-4.9.1-py3-none-any.whl", hash = "sha256:68635866661c6836b8d39430f97a996acbd61bfa49406748ea243539fe239762", size = 34696, upload-time = "2025-04-16T09:51:17.142Z" },
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sniffio"
|
name = "sniffio"
|
||||||
version = "1.3.1"
|
version = "1.3.1"
|
||||||
|
|||||||
+2
-1
@@ -137,7 +137,8 @@ services:
|
|||||||
- migrate
|
- migrate
|
||||||
networks:
|
networks:
|
||||||
database:
|
database:
|
||||||
command: x convex deploy
|
entrypoint: bunx
|
||||||
|
command: convex dev
|
||||||
|
|
||||||
convex-dashboard:
|
convex-dashboard:
|
||||||
image: ghcr.io/get-convex/convex-dashboard:latest
|
image: ghcr.io/get-convex/convex-dashboard:latest
|
||||||
|
|||||||
@@ -5,8 +5,5 @@ yarn.lock
|
|||||||
bun.lock
|
bun.lock
|
||||||
bun.lockb
|
bun.lockb
|
||||||
|
|
||||||
# Convex generated files
|
|
||||||
src/lib/convex/_generated/
|
|
||||||
|
|
||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
/static/
|
/static/
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ai-sdk/google": "^3.0.13",
|
|
||||||
"@convex-dev/rag": "^0.7.0",
|
|
||||||
"convex": "^1.31.5",
|
"convex": "^1.31.5",
|
||||||
"convex-svelte": "^0.0.12",
|
"convex-svelte": "^0.0.12",
|
||||||
"marked": "^17.0.1",
|
"marked": "^17.0.1",
|
||||||
@@ -37,18 +35,6 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
"@ai-sdk/gateway": ["@ai-sdk/gateway@3.0.22", "", { "dependencies": { "@ai-sdk/provider": "3.0.5", "@ai-sdk/provider-utils": "4.0.9", "@vercel/oidc": "3.1.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-NgnlY73JNuooACHqUIz5uMOEWvqR1MMVbb2soGLMozLY1fgwEIF5iJFDAGa5/YArlzw2ATVU7zQu7HkR/FUjgA=="],
|
|
||||||
|
|
||||||
"@ai-sdk/google": ["@ai-sdk/google@3.0.13", "", { "dependencies": { "@ai-sdk/provider": "3.0.5", "@ai-sdk/provider-utils": "4.0.9" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-HYCh8miS4FLxOIpjo/BmoFVMO5BuxNpHVVDQkoJotoH8ZSFftkJJGGayIxQT/Lwx9GGvVVCOQ+lCdBBAnkl1sA=="],
|
|
||||||
|
|
||||||
"@ai-sdk/provider": ["@ai-sdk/provider@3.0.5", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-2Xmoq6DBJqmSl80U6V9z5jJSJP7ehaJJQMy2iFUqTay06wdCqTnPVBBQbtEL8RCChenL+q5DC5H5WzU3vV3v8w=="],
|
|
||||||
|
|
||||||
"@ai-sdk/provider-utils": ["@ai-sdk/provider-utils@4.0.9", "", { "dependencies": { "@ai-sdk/provider": "3.0.5", "@standard-schema/spec": "^1.1.0", "eventsource-parser": "^3.0.6" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-bB4r6nfhBOpmoS9mePxjRoCy+LnzP3AfhyMGCkGL4Mn9clVNlqEeKj26zEKEtB6yoSVcT1IQ0Zh9fytwMCDnow=="],
|
|
||||||
|
|
||||||
"@convex-dev/rag": ["@convex-dev/rag@0.7.0", "", { "dependencies": { "ai": "^6.0.0" }, "peerDependencies": { "@convex-dev/workpool": "^0.3.0", "convex": "^1.24.8", "convex-helpers": "^0.1.94" } }, "sha512-hs/py/0SZ+wcKzP8LtN89HQEI2Ts0AXMUb9N3hIr70nQ/T+wBiEOG+3WI91x1JvbkV0ChWYlaiqB1KzoQHYF1A=="],
|
|
||||||
|
|
||||||
"@convex-dev/workpool": ["@convex-dev/workpool@0.3.1", "", { "peerDependencies": { "convex": "^1.24.8", "convex-helpers": "^0.1.94" } }, "sha512-uw4Mi+irhhoYA/KwaMo5wXyYJ7BbxqeaLcCZbst3t1SxPN5488rpnR0OwBcPDCmwcdQjBVHOx+q8S4GUjq0Csg=="],
|
|
||||||
|
|
||||||
"@emnapi/core": ["@emnapi/core@1.8.1", "", { "dependencies": { "@emnapi/wasi-threads": "1.1.0", "tslib": "^2.4.0" } }, "sha512-AvT9QFpxK0Zd8J0jopedNm+w/2fIzvtPKPjqyw9jwvBaReTTqPBk9Hixaz7KbjimP+QNz605/XnjFcDAL2pqBg=="],
|
"@emnapi/core": ["@emnapi/core@1.8.1", "", { "dependencies": { "@emnapi/wasi-threads": "1.1.0", "tslib": "^2.4.0" } }, "sha512-AvT9QFpxK0Zd8J0jopedNm+w/2fIzvtPKPjqyw9jwvBaReTTqPBk9Hixaz7KbjimP+QNz605/XnjFcDAL2pqBg=="],
|
||||||
|
|
||||||
"@emnapi/runtime": ["@emnapi/runtime@1.8.1", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg=="],
|
"@emnapi/runtime": ["@emnapi/runtime@1.8.1", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg=="],
|
||||||
@@ -147,8 +133,6 @@
|
|||||||
|
|
||||||
"@napi-rs/wasm-runtime": ["@napi-rs/wasm-runtime@0.2.12", "", { "dependencies": { "@emnapi/core": "^1.4.3", "@emnapi/runtime": "^1.4.3", "@tybys/wasm-util": "^0.10.0" } }, "sha512-ZVWUcfwY4E/yPitQJl481FjFo3K22D6qF0DuFH6Y/nbnE11GY5uguDxZMGXPQ8WQ0128MXQD7TnfHyK4oWoIJQ=="],
|
"@napi-rs/wasm-runtime": ["@napi-rs/wasm-runtime@0.2.12", "", { "dependencies": { "@emnapi/core": "^1.4.3", "@emnapi/runtime": "^1.4.3", "@tybys/wasm-util": "^0.10.0" } }, "sha512-ZVWUcfwY4E/yPitQJl481FjFo3K22D6qF0DuFH6Y/nbnE11GY5uguDxZMGXPQ8WQ0128MXQD7TnfHyK4oWoIJQ=="],
|
||||||
|
|
||||||
"@opentelemetry/api": ["@opentelemetry/api@1.9.0", "", {}, "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg=="],
|
|
||||||
|
|
||||||
"@oxc-project/runtime": ["@oxc-project/runtime@0.71.0", "", {}, "sha512-QwoF5WUXIGFQ+hSxWEib4U/aeLoiDN9JlP18MnBgx9LLPRDfn1iICtcow7Jgey6HLH4XFceWXQD5WBJ39dyJcw=="],
|
"@oxc-project/runtime": ["@oxc-project/runtime@0.71.0", "", {}, "sha512-QwoF5WUXIGFQ+hSxWEib4U/aeLoiDN9JlP18MnBgx9LLPRDfn1iICtcow7Jgey6HLH4XFceWXQD5WBJ39dyJcw=="],
|
||||||
|
|
||||||
"@oxc-project/types": ["@oxc-project/types@0.71.0", "", {}, "sha512-5CwQ4MI+P4MQbjLWXgNurA+igGwu/opNetIE13LBs9+V93R64MLvDKOOLZIXSzEfovU3Zef3q3GjPnMTgJTn2w=="],
|
"@oxc-project/types": ["@oxc-project/types@0.71.0", "", {}, "sha512-5CwQ4MI+P4MQbjLWXgNurA+igGwu/opNetIE13LBs9+V93R64MLvDKOOLZIXSzEfovU3Zef3q3GjPnMTgJTn2w=="],
|
||||||
@@ -301,16 +285,12 @@
|
|||||||
|
|
||||||
"@typescript-eslint/visitor-keys": ["@typescript-eslint/visitor-keys@8.53.1", "", { "dependencies": { "@typescript-eslint/types": "8.53.1", "eslint-visitor-keys": "^4.2.1" } }, "sha512-oy+wV7xDKFPRyNggmXuZQSBzvoLnpmJs+GhzRhPjrxl2b/jIlyjVokzm47CZCDUdXKr2zd7ZLodPfOBpOPyPlg=="],
|
"@typescript-eslint/visitor-keys": ["@typescript-eslint/visitor-keys@8.53.1", "", { "dependencies": { "@typescript-eslint/types": "8.53.1", "eslint-visitor-keys": "^4.2.1" } }, "sha512-oy+wV7xDKFPRyNggmXuZQSBzvoLnpmJs+GhzRhPjrxl2b/jIlyjVokzm47CZCDUdXKr2zd7ZLodPfOBpOPyPlg=="],
|
||||||
|
|
||||||
"@vercel/oidc": ["@vercel/oidc@3.1.0", "", {}, "sha512-Fw28YZpRnA3cAHHDlkt7xQHiJ0fcL+NRcIqsocZQUSmbzeIKRpwttJjik5ZGanXP+vlA4SbTg+AbA3bP363l+w=="],
|
|
||||||
|
|
||||||
"@xmldom/xmldom": ["@xmldom/xmldom@0.9.8", "", {}, "sha512-p96FSY54r+WJ50FIOsCOjyj/wavs8921hG5+kVMmZgKcvIKxMXHTrjNJvRgWa/zuX3B6t2lijLNFaOyuxUH+2A=="],
|
"@xmldom/xmldom": ["@xmldom/xmldom@0.9.8", "", {}, "sha512-p96FSY54r+WJ50FIOsCOjyj/wavs8921hG5+kVMmZgKcvIKxMXHTrjNJvRgWa/zuX3B6t2lijLNFaOyuxUH+2A=="],
|
||||||
|
|
||||||
"acorn": ["acorn@8.15.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg=="],
|
"acorn": ["acorn@8.15.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg=="],
|
||||||
|
|
||||||
"acorn-jsx": ["acorn-jsx@5.3.2", "", { "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ=="],
|
"acorn-jsx": ["acorn-jsx@5.3.2", "", { "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ=="],
|
||||||
|
|
||||||
"ai": ["ai@6.0.49", "", { "dependencies": { "@ai-sdk/gateway": "3.0.22", "@ai-sdk/provider": "3.0.5", "@ai-sdk/provider-utils": "4.0.9", "@opentelemetry/api": "1.9.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-LABniBX/0R6Tv+iUK5keUZhZLaZUe4YjP5M2rZ4wAdZ8iKV3EfTAoJxuL1aaWTSJKIilKa9QUEkCgnp89/32bw=="],
|
|
||||||
|
|
||||||
"ajv": ["ajv@6.12.6", "", { "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" } }, "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g=="],
|
"ajv": ["ajv@6.12.6", "", { "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" } }, "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g=="],
|
||||||
|
|
||||||
"ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="],
|
"ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="],
|
||||||
@@ -345,8 +325,6 @@
|
|||||||
|
|
||||||
"convex": ["convex@1.31.5", "", { "dependencies": { "esbuild": "0.27.0", "prettier": "^3.0.0" }, "peerDependencies": { "@auth0/auth0-react": "^2.0.1", "@clerk/clerk-react": "^4.12.8 || ^5.0.0", "react": "^18.0.0 || ^19.0.0-0 || ^19.0.0" }, "optionalPeers": ["@auth0/auth0-react", "@clerk/clerk-react", "react"], "bin": { "convex": "bin/main.js" } }, "sha512-E1IuJKFwMCHDToNGukBPs6c7RFaarR3t8chLF9n98TM5/Tgmj8lM6l7sKM1aJ3VwqGaB4wbeUAPY8osbCOXBhQ=="],
|
"convex": ["convex@1.31.5", "", { "dependencies": { "esbuild": "0.27.0", "prettier": "^3.0.0" }, "peerDependencies": { "@auth0/auth0-react": "^2.0.1", "@clerk/clerk-react": "^4.12.8 || ^5.0.0", "react": "^18.0.0 || ^19.0.0-0 || ^19.0.0" }, "optionalPeers": ["@auth0/auth0-react", "@clerk/clerk-react", "react"], "bin": { "convex": "bin/main.js" } }, "sha512-E1IuJKFwMCHDToNGukBPs6c7RFaarR3t8chLF9n98TM5/Tgmj8lM6l7sKM1aJ3VwqGaB4wbeUAPY8osbCOXBhQ=="],
|
||||||
|
|
||||||
"convex-helpers": ["convex-helpers@0.1.111", "", { "peerDependencies": { "@standard-schema/spec": "^1.0.0", "convex": "^1.25.4", "hono": "^4.0.5", "react": "^17.0.2 || ^18.0.0 || ^19.0.0", "typescript": "^5.5", "zod": "^3.25.0 || ^4.0.0" }, "optionalPeers": ["@standard-schema/spec", "hono", "react", "typescript", "zod"], "bin": { "convex-helpers": "bin.cjs" } }, "sha512-0O59Ohi8HVc3+KULxSC6JHsw8cQJyc8gZ7OAfNRVX7T5Wy6LhPx3l8veYN9avKg7UiPlO7m1eBiQMHKclIyXyQ=="],
|
|
||||||
|
|
||||||
"convex-svelte": ["convex-svelte@0.0.12", "", { "dependencies": { "esm-env": "^1.2.2", "runed": "^0.31.1" }, "peerDependencies": { "convex": "^1.10.0", "svelte": "^5.0.0" } }, "sha512-sUZoYp4ZsokyvKlbbg1dWYB7MkAjZn4nNG9DnADEt9L6KTKuhhnEIt6fdLj+3GnVBUGDTssm17+7ppzFc4y7Gg=="],
|
"convex-svelte": ["convex-svelte@0.0.12", "", { "dependencies": { "esm-env": "^1.2.2", "runed": "^0.31.1" }, "peerDependencies": { "convex": "^1.10.0", "svelte": "^5.0.0" } }, "sha512-sUZoYp4ZsokyvKlbbg1dWYB7MkAjZn4nNG9DnADEt9L6KTKuhhnEIt6fdLj+3GnVBUGDTssm17+7ppzFc4y7Gg=="],
|
||||||
|
|
||||||
"cookie": ["cookie@0.6.0", "", {}, "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw=="],
|
"cookie": ["cookie@0.6.0", "", {}, "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw=="],
|
||||||
@@ -397,8 +375,6 @@
|
|||||||
|
|
||||||
"esutils": ["esutils@2.0.3", "", {}, "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g=="],
|
"esutils": ["esutils@2.0.3", "", {}, "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g=="],
|
||||||
|
|
||||||
"eventsource-parser": ["eventsource-parser@3.0.6", "", {}, "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg=="],
|
|
||||||
|
|
||||||
"fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="],
|
"fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="],
|
||||||
|
|
||||||
"fast-json-stable-stringify": ["fast-json-stable-stringify@2.1.0", "", {}, "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="],
|
"fast-json-stable-stringify": ["fast-json-stable-stringify@2.1.0", "", {}, "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="],
|
||||||
@@ -445,8 +421,6 @@
|
|||||||
|
|
||||||
"json-buffer": ["json-buffer@3.0.1", "", {}, "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ=="],
|
"json-buffer": ["json-buffer@3.0.1", "", {}, "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ=="],
|
||||||
|
|
||||||
"json-schema": ["json-schema@0.4.0", "", {}, "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA=="],
|
|
||||||
|
|
||||||
"json-schema-traverse": ["json-schema-traverse@0.4.1", "", {}, "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="],
|
"json-schema-traverse": ["json-schema-traverse@0.4.1", "", {}, "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="],
|
||||||
|
|
||||||
"json-stable-stringify-without-jsonify": ["json-stable-stringify-without-jsonify@1.0.1", "", {}, "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw=="],
|
"json-stable-stringify-without-jsonify": ["json-stable-stringify-without-jsonify@1.0.1", "", {}, "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw=="],
|
||||||
@@ -629,8 +603,6 @@
|
|||||||
|
|
||||||
"zimmerframe": ["zimmerframe@1.1.4", "", {}, "sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ=="],
|
"zimmerframe": ["zimmerframe@1.1.4", "", {}, "sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ=="],
|
||||||
|
|
||||||
"zod": ["zod@4.3.6", "", {}, "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg=="],
|
|
||||||
|
|
||||||
"@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],
|
"@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],
|
||||||
|
|
||||||
"@eslint/eslintrc/globals": ["globals@14.0.0", "", {}, "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ=="],
|
"@eslint/eslintrc/globals": ["globals@14.0.0", "", {}, "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ=="],
|
||||||
|
|||||||
@@ -22,11 +22,9 @@ export default defineConfig(
|
|||||||
languageOptions: { globals: { ...globals.browser, ...globals.node } },
|
languageOptions: { globals: { ...globals.browser, ...globals.node } },
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
'no-undef': 'off',
|
// typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.
|
||||||
'@typescript-eslint/no-unused-vars': [
|
// see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
|
||||||
'error',
|
'no-undef': 'off'
|
||||||
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,8 +36,6 @@
|
|||||||
"vite": "^7.2.6"
|
"vite": "^7.2.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ai-sdk/google": "^3.0.13",
|
|
||||||
"@convex-dev/rag": "^0.7.0",
|
|
||||||
"convex": "^1.31.5",
|
"convex": "^1.31.5",
|
||||||
"convex-svelte": "^0.0.12",
|
"convex-svelte": "^0.0.12",
|
||||||
"marked": "^17.0.1",
|
"marked": "^17.0.1",
|
||||||
|
|||||||
@@ -1,184 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
showPreview?: boolean;
|
|
||||||
oncapture: (base64: string, mediaType: string) => void;
|
|
||||||
onclose: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { showPreview = true, oncapture, onclose }: Props = $props();
|
|
||||||
|
|
||||||
let videoElement: HTMLVideoElement | null = $state(null);
|
|
||||||
let stream: MediaStream | null = $state(null);
|
|
||||||
let capturedImage: { base64: string; mediaType: string } | null = $state(null);
|
|
||||||
let error: string | null = $state(null);
|
|
||||||
let closed = false;
|
|
||||||
|
|
||||||
async function findUltraWideCamera(): Promise<string | null> {
|
|
||||||
try {
|
|
||||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
||||||
const videoDevices = devices.filter((d) => d.kind === 'videoinput');
|
|
||||||
const ultraWide = videoDevices.find(
|
|
||||||
(d) => d.label.toLowerCase().includes('ultra') && d.label.toLowerCase().includes('back')
|
|
||||||
);
|
|
||||||
return ultraWide?.deviceId ?? null;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function startCamera() {
|
|
||||||
if (closed) return;
|
|
||||||
|
|
||||||
if (!navigator.mediaDevices?.getUserMedia) {
|
|
||||||
error = 'Camera not supported (requires HTTPS)';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
stream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: { facingMode: { ideal: 'environment' } },
|
|
||||||
audio: false
|
|
||||||
});
|
|
||||||
|
|
||||||
const ultraWideId = await findUltraWideCamera();
|
|
||||||
|
|
||||||
if (ultraWideId) {
|
|
||||||
stream.getTracks().forEach((t) => t.stop());
|
|
||||||
stream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: {
|
|
||||||
deviceId: { exact: ultraWideId },
|
|
||||||
width: { ideal: 4032 },
|
|
||||||
height: { ideal: 3024 }
|
|
||||||
},
|
|
||||||
audio: false
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
stream.getTracks().forEach((t) => t.stop());
|
|
||||||
stream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: {
|
|
||||||
facingMode: { ideal: 'environment' },
|
|
||||||
width: { ideal: 4032 },
|
|
||||||
height: { ideal: 3024 }
|
|
||||||
},
|
|
||||||
audio: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (videoElement && !closed) {
|
|
||||||
videoElement.srcObject = stream;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
error = e instanceof Error ? e.message : 'Camera access denied';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function stopCamera() {
|
|
||||||
if (stream) {
|
|
||||||
stream.getTracks().forEach((track) => track.stop());
|
|
||||||
stream = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function capture() {
|
|
||||||
if (!videoElement) return;
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
canvas.width = videoElement.videoWidth;
|
|
||||||
canvas.height = videoElement.videoHeight;
|
|
||||||
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
if (!ctx) return;
|
|
||||||
|
|
||||||
ctx.drawImage(videoElement, 0, 0);
|
|
||||||
|
|
||||||
const maxSize = 1920;
|
|
||||||
const scale = Math.min(maxSize / canvas.width, maxSize / canvas.height, 1);
|
|
||||||
const outCanvas = document.createElement('canvas');
|
|
||||||
outCanvas.width = Math.round(canvas.width * scale);
|
|
||||||
outCanvas.height = Math.round(canvas.height * scale);
|
|
||||||
const outCtx = outCanvas.getContext('2d');
|
|
||||||
if (!outCtx) return;
|
|
||||||
outCtx.drawImage(canvas, 0, 0, outCanvas.width, outCanvas.height);
|
|
||||||
|
|
||||||
const base64 = outCanvas.toDataURL('image/jpeg', 0.65).split(',')[1];
|
|
||||||
const mediaType = 'image/jpeg';
|
|
||||||
|
|
||||||
stopCamera();
|
|
||||||
|
|
||||||
if (showPreview) {
|
|
||||||
capturedImage = { base64, mediaType };
|
|
||||||
} else {
|
|
||||||
oncapture(base64, mediaType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function acceptCapture() {
|
|
||||||
if (capturedImage) {
|
|
||||||
oncapture(capturedImage.base64, capturedImage.mediaType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function retake() {
|
|
||||||
capturedImage = null;
|
|
||||||
startCamera();
|
|
||||||
}
|
|
||||||
|
|
||||||
function close() {
|
|
||||||
closed = true;
|
|
||||||
stopCamera();
|
|
||||||
onclose();
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
startCamera();
|
|
||||||
return () => {
|
|
||||||
closed = true;
|
|
||||||
stopCamera();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="fixed inset-0 z-50 flex flex-col bg-black" data-camera-ui>
|
|
||||||
{#if error}
|
|
||||||
<div class="flex flex-1 flex-col items-center justify-center p-4">
|
|
||||||
<p class="mb-4 text-center text-sm text-red-400">{error}</p>
|
|
||||||
<button onclick={close} class="rounded bg-neutral-700 px-4 py-2 text-sm text-white">
|
|
||||||
Close
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{:else if capturedImage}
|
|
||||||
<div class="relative min-h-0 flex-1">
|
|
||||||
<button class="absolute inset-0" onclick={acceptCapture}>
|
|
||||||
<img
|
|
||||||
src="data:{capturedImage.mediaType};base64,{capturedImage.base64}"
|
|
||||||
alt="Captured"
|
|
||||||
class="h-full w-full object-contain"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="flex gap-4 p-4">
|
|
||||||
<button onclick={retake} class="flex-1 rounded bg-neutral-700 py-3 text-sm text-white">
|
|
||||||
Retake
|
|
||||||
</button>
|
|
||||||
<button onclick={acceptCapture} class="flex-1 rounded bg-blue-600 py-3 text-sm text-white">
|
|
||||||
Use
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<video bind:this={videoElement} autoplay playsinline muted class="h-full w-full object-cover"
|
|
||||||
></video>
|
|
||||||
<button
|
|
||||||
onclick={close}
|
|
||||||
class="absolute top-4 right-4 flex h-8 w-8 items-center justify-center rounded-full bg-black/50 text-white"
|
|
||||||
>
|
|
||||||
×
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onclick={capture}
|
|
||||||
aria-label="Capture photo"
|
|
||||||
class="absolute bottom-8 left-1/2 h-16 w-16 -translate-x-1/2 rounded-full border-4 border-white bg-white/20"
|
|
||||||
></button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
@@ -1,144 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
oncomplete: (base64: string, mediaType: string, thumbnailBase64: string) => void;
|
|
||||||
oncancel: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { oncomplete, oncancel }: Props = $props();
|
|
||||||
|
|
||||||
let count = $state(3);
|
|
||||||
let videoElement: HTMLVideoElement | null = $state(null);
|
|
||||||
let stream: MediaStream | null = $state(null);
|
|
||||||
let error: string | null = $state(null);
|
|
||||||
let cancelled = false;
|
|
||||||
let countdownInterval: ReturnType<typeof setInterval> | null = null;
|
|
||||||
|
|
||||||
async function startCamera() {
|
|
||||||
if (cancelled) return;
|
|
||||||
|
|
||||||
if (!navigator.mediaDevices?.getUserMedia) {
|
|
||||||
error = 'Camera not supported (requires HTTPS)';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const constraints: MediaStreamConstraints = {
|
|
||||||
video: {
|
|
||||||
facingMode: { ideal: 'environment' },
|
|
||||||
width: { ideal: 1920 },
|
|
||||||
height: { ideal: 1080 }
|
|
||||||
},
|
|
||||||
audio: false
|
|
||||||
};
|
|
||||||
|
|
||||||
stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
||||||
|
|
||||||
if (videoElement && !cancelled) {
|
|
||||||
videoElement.srcObject = stream;
|
|
||||||
startCountdown();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
error = e instanceof Error ? e.message : 'Camera access denied';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function stopCamera() {
|
|
||||||
if (countdownInterval) {
|
|
||||||
clearInterval(countdownInterval);
|
|
||||||
countdownInterval = null;
|
|
||||||
}
|
|
||||||
if (stream) {
|
|
||||||
stream.getTracks().forEach((track) => track.stop());
|
|
||||||
stream = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function startCountdown() {
|
|
||||||
countdownInterval = setInterval(() => {
|
|
||||||
if (cancelled) {
|
|
||||||
stopCamera();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
count--;
|
|
||||||
if (count === 0) {
|
|
||||||
if (countdownInterval) clearInterval(countdownInterval);
|
|
||||||
capture();
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
function capture() {
|
|
||||||
if (cancelled || !videoElement) {
|
|
||||||
stopCamera();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
canvas.width = videoElement.videoWidth;
|
|
||||||
canvas.height = videoElement.videoHeight;
|
|
||||||
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
if (!ctx) {
|
|
||||||
stopCamera();
|
|
||||||
oncancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.drawImage(videoElement, 0, 0);
|
|
||||||
|
|
||||||
const base64 = canvas.toDataURL('image/jpeg', 0.85).split(',')[1];
|
|
||||||
const mediaType = 'image/jpeg';
|
|
||||||
|
|
||||||
const thumbMaxSize = 800;
|
|
||||||
const scale = Math.min(thumbMaxSize / canvas.width, thumbMaxSize / canvas.height, 1);
|
|
||||||
const thumbCanvas = document.createElement('canvas');
|
|
||||||
thumbCanvas.width = Math.round(canvas.width * scale);
|
|
||||||
thumbCanvas.height = Math.round(canvas.height * scale);
|
|
||||||
const thumbCtx = thumbCanvas.getContext('2d');
|
|
||||||
if (thumbCtx) {
|
|
||||||
thumbCtx.drawImage(canvas, 0, 0, thumbCanvas.width, thumbCanvas.height);
|
|
||||||
}
|
|
||||||
const thumbnailBase64 = thumbCanvas.toDataURL('image/jpeg', 0.7).split(',')[1];
|
|
||||||
|
|
||||||
stopCamera();
|
|
||||||
oncomplete(base64, mediaType, thumbnailBase64);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleCancel() {
|
|
||||||
cancelled = true;
|
|
||||||
stopCamera();
|
|
||||||
oncancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
startCamera();
|
|
||||||
return () => {
|
|
||||||
cancelled = true;
|
|
||||||
stopCamera();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="fixed inset-0 z-50 flex flex-col bg-black" data-camera-ui>
|
|
||||||
{#if error}
|
|
||||||
<div class="flex flex-1 flex-col items-center justify-center p-4">
|
|
||||||
<p class="mb-4 text-center text-sm text-red-400">{error}</p>
|
|
||||||
<button onclick={handleCancel} class="rounded bg-neutral-700 px-4 py-2 text-sm text-white">
|
|
||||||
Close
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="relative flex-1">
|
|
||||||
<video bind:this={videoElement} autoplay playsinline muted class="h-full w-full object-cover"
|
|
||||||
></video>
|
|
||||||
<div class="absolute inset-0 flex items-center justify-center">
|
|
||||||
<span class="text-8xl font-bold text-white drop-shadow-lg">{count}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="p-4 text-center">
|
|
||||||
<button onclick={handleCancel} class="text-sm text-neutral-400">Cancel</button>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
@@ -1,62 +1,20 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
interface Props {
|
interface Props {
|
||||||
onsubmit: (message: string) => void;
|
onsubmit: (message: string) => void;
|
||||||
onpasteimage?: (base64: string, mediaType: string) => void;
|
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
allowEmpty?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let { onsubmit, onpasteimage, disabled = false, allowEmpty = false }: Props = $props();
|
let { onsubmit, disabled = false }: Props = $props();
|
||||||
let value = $state('');
|
let value = $state('');
|
||||||
|
|
||||||
function handleSubmit(e: Event) {
|
function handleSubmit(e: Event) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const trimmed = value.trim();
|
const trimmed = value.trim();
|
||||||
if ((trimmed || allowEmpty) && !disabled) {
|
if (trimmed && !disabled) {
|
||||||
onsubmit(trimmed);
|
onsubmit(trimmed);
|
||||||
value = '';
|
value = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fileToCompressedBase64(
|
|
||||||
file: File
|
|
||||||
): Promise<{ base64: string; mediaType: string }> {
|
|
||||||
const bitmap = await createImageBitmap(file);
|
|
||||||
const maxSize = 1920;
|
|
||||||
const scale = Math.min(maxSize / bitmap.width, maxSize / bitmap.height, 1);
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
canvas.width = Math.round(bitmap.width * scale);
|
|
||||||
canvas.height = Math.round(bitmap.height * scale);
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
if (!ctx) throw new Error('canvas 2d context unavailable');
|
|
||||||
ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
|
|
||||||
bitmap.close();
|
|
||||||
const base64 = canvas.toDataURL('image/jpeg', 0.65).split(',')[1];
|
|
||||||
return { base64, mediaType: 'image/jpeg' };
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handlePaste(e: ClipboardEvent) {
|
|
||||||
if (!onpasteimage || disabled) return;
|
|
||||||
const items = e.clipboardData?.items;
|
|
||||||
if (!items) return;
|
|
||||||
const imageFiles: File[] = [];
|
|
||||||
for (const item of items) {
|
|
||||||
if (item.kind === 'file' && item.type.startsWith('image/')) {
|
|
||||||
const f = item.getAsFile();
|
|
||||||
if (f) imageFiles.push(f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (imageFiles.length === 0) return;
|
|
||||||
e.preventDefault();
|
|
||||||
for (const file of imageFiles) {
|
|
||||||
try {
|
|
||||||
const { base64, mediaType } = await fileToCompressedBase64(file);
|
|
||||||
onpasteimage(base64, mediaType);
|
|
||||||
} catch {
|
|
||||||
// ignore unreadable image
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form onsubmit={handleSubmit} class="flex gap-1">
|
<form onsubmit={handleSubmit} class="flex gap-1">
|
||||||
@@ -64,7 +22,6 @@
|
|||||||
type="text"
|
type="text"
|
||||||
bind:value
|
bind:value
|
||||||
{disabled}
|
{disabled}
|
||||||
onpaste={handlePaste}
|
|
||||||
placeholder="..."
|
placeholder="..."
|
||||||
class="min-w-0 flex-1 rounded bg-neutral-800 px-2 py-1 text-[10px] text-white placeholder-neutral-500 outline-none"
|
class="min-w-0 flex-1 rounded bg-neutral-800 px-2 py-1 text-[10px] text-white placeholder-neutral-500 outline-none"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { Marked } from 'marked';
|
||||||
import LoadingDots from './LoadingDots.svelte';
|
import LoadingDots from './LoadingDots.svelte';
|
||||||
import { processContent } from '$lib/utils/markdown';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
role: 'user' | 'assistant';
|
role: 'user' | 'assistant';
|
||||||
@@ -9,6 +9,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let { role, content, isStreaming = false }: Props = $props();
|
let { role, content, isStreaming = false }: Props = $props();
|
||||||
|
|
||||||
|
const marked = new Marked({
|
||||||
|
breaks: true,
|
||||||
|
gfm: true
|
||||||
|
});
|
||||||
|
|
||||||
|
function processLatex(text: string): string {
|
||||||
|
return text
|
||||||
|
.replace(/\$\$(.*?)\$\$/gs, (_, tex) => {
|
||||||
|
const encoded = encodeURIComponent(tex.trim());
|
||||||
|
return `<img src="/service/latex?tex=${encoded}&display=1" alt="LaTeX" class="block my-1 max-h-12" />`;
|
||||||
|
})
|
||||||
|
.replace(/\$(.+?)\$/g, (_, tex) => {
|
||||||
|
const encoded = encodeURIComponent(tex.trim());
|
||||||
|
return `<img src="/service/latex?tex=${encoded}" alt="LaTeX" class="inline-block align-middle max-h-4" />`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function processContent(text: string): string {
|
||||||
|
const withLatex = processLatex(text);
|
||||||
|
return marked.parse(withLatex) as string;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { Id } from '$lib/convex/_generated/dataModel';
|
|
||||||
|
|
||||||
interface Photo {
|
|
||||||
_id: Id<'photoDrafts'>;
|
|
||||||
mediaType: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
photos: Photo[];
|
|
||||||
onremove: (index: number) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { photos, onremove }: Props = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if photos.length > 0}
|
|
||||||
<div class="flex flex-wrap gap-1">
|
|
||||||
{#each photos as _photo, i (i)}
|
|
||||||
<button
|
|
||||||
onclick={() => onremove(i)}
|
|
||||||
class="flex items-center gap-1 rounded bg-blue-600/30 px-1.5 py-0.5 text-[8px] text-blue-300"
|
|
||||||
>
|
|
||||||
<span>photo {i + 1}</span>
|
|
||||||
<span class="text-blue-400">×</span>
|
|
||||||
</button>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { Id } from '$lib/convex/_generated/dataModel';
|
|
||||||
import { processContent } from '$lib/utils/markdown';
|
|
||||||
|
|
||||||
interface Sheet {
|
|
||||||
_id: Id<'incomingSheets'>;
|
|
||||||
sheetId: number;
|
|
||||||
text: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
sheets: Sheet[];
|
|
||||||
onaccept: (id: Id<'incomingSheets'>) => void;
|
|
||||||
ondismiss: (id: Id<'incomingSheets'>) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { sheets, onaccept, ondismiss }: Props = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if sheets.length > 0}
|
|
||||||
<div class="space-y-1.5">
|
|
||||||
<div class="text-[8px] tracking-wider text-neutral-500 uppercase">
|
|
||||||
incoming sheets · {sheets.length}
|
|
||||||
</div>
|
|
||||||
{#each sheets as s (s._id)}
|
|
||||||
<div class="rounded border border-neutral-800 bg-neutral-900/60 p-2">
|
|
||||||
<div class="text-[8px] text-neutral-500">sheet #{s.sheetId}</div>
|
|
||||||
<div
|
|
||||||
class="prose-mini mt-1 max-h-64 overflow-y-auto text-[10px] leading-relaxed text-neutral-200"
|
|
||||||
>
|
|
||||||
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
|
||||||
{@html processContent(s.text)}
|
|
||||||
</div>
|
|
||||||
<div class="mt-1.5 flex gap-1">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onclick={() => onaccept(s._id)}
|
|
||||||
class="flex-1 rounded bg-blue-600 py-1 text-[9px] text-white"
|
|
||||||
>
|
|
||||||
accept
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onclick={() => ondismiss(s._id)}
|
|
||||||
class="flex-1 rounded bg-neutral-800 py-1 text-[9px] text-neutral-400"
|
|
||||||
>
|
|
||||||
dismiss
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { processContent } from '$lib/utils/markdown';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
content: string;
|
|
||||||
images?: string[];
|
|
||||||
mediaTypes?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
let { content, images = [], mediaTypes = [] }: Props = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div
|
|
||||||
class="prose-mini w-full rounded-lg bg-blue-600 px-2.5 py-1.5 text-[11px] leading-relaxed text-white opacity-60"
|
|
||||||
>
|
|
||||||
{#if images.length > 0}
|
|
||||||
<div class="mb-1 flex flex-wrap gap-1">
|
|
||||||
{#each images as img, i (i)}
|
|
||||||
<img
|
|
||||||
src={`data:${mediaTypes[i] ?? 'image/jpeg'};base64,${img}`}
|
|
||||||
alt=""
|
|
||||||
class="max-h-16 rounded"
|
|
||||||
/>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{#if content}
|
|
||||||
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
|
||||||
<div>{@html processContent(content)}</div>
|
|
||||||
{/if}
|
|
||||||
<div class="mt-1 flex items-center gap-1 text-[8px] text-blue-100/80">
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
class="h-2.5 w-2.5 animate-spin"
|
|
||||||
fill="none"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="3" opacity="0.3" />
|
|
||||||
<path
|
|
||||||
d="M12 2a10 10 0 0 1 10 10"
|
|
||||||
stroke="currentColor"
|
|
||||||
stroke-width="3"
|
|
||||||
stroke-linecap="round"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
<span>в очереди</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
interface Props {
|
|
||||||
hasCamera: boolean;
|
|
||||||
hasOnlineDevices: boolean;
|
|
||||||
ontakephoto: () => void;
|
|
||||||
onrequestphoto: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { hasCamera, hasOnlineDevices, ontakephoto, onrequestphoto }: Props = $props();
|
|
||||||
let menuOpen = $state(false);
|
|
||||||
|
|
||||||
function handleClick() {
|
|
||||||
if (hasCamera && hasOnlineDevices) {
|
|
||||||
menuOpen = !menuOpen;
|
|
||||||
} else if (hasOnlineDevices) {
|
|
||||||
onrequestphoto();
|
|
||||||
} else {
|
|
||||||
ontakephoto();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleTakePhoto() {
|
|
||||||
menuOpen = false;
|
|
||||||
ontakephoto();
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleRequestPhoto() {
|
|
||||||
menuOpen = false;
|
|
||||||
onrequestphoto();
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleBackdropClick() {
|
|
||||||
menuOpen = false;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="relative">
|
|
||||||
<button
|
|
||||||
onclick={handleClick}
|
|
||||||
class="shrink-0 rounded bg-neutral-800 px-1.5 py-0.5 text-[8px] text-neutral-400"
|
|
||||||
>
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{#if menuOpen}
|
|
||||||
<button class="fixed inset-0 z-40" onclick={handleBackdropClick} aria-label="Close menu"
|
|
||||||
></button>
|
|
||||||
<div
|
|
||||||
class="absolute bottom-full left-0 z-50 mb-1 overflow-hidden rounded bg-neutral-800 shadow-lg"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
onclick={handleTakePhoto}
|
|
||||||
class="block w-full px-3 py-2 text-left text-[10px] whitespace-nowrap text-white hover:bg-neutral-700"
|
|
||||||
>
|
|
||||||
Take photo
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onclick={handleRequestPhoto}
|
|
||||||
class="block w-full px-3 py-2 text-left text-[10px] whitespace-nowrap text-white hover:bg-neutral-700"
|
|
||||||
>
|
|
||||||
Request photo
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
interface Props {
|
|
||||||
base64: string;
|
|
||||||
mediaType: string;
|
|
||||||
onaccept: () => void;
|
|
||||||
onreject: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { base64, mediaType, onaccept, onreject }: Props = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="fixed inset-0 z-50 overflow-auto bg-black" data-camera-ui>
|
|
||||||
<button class="block min-h-full min-w-full" onclick={onaccept}>
|
|
||||||
<img
|
|
||||||
src="data:{mediaType};base64,{base64}"
|
|
||||||
alt="Preview"
|
|
||||||
class="min-h-dvh min-w-full object-cover"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onclick={onreject}
|
|
||||||
class="fixed top-4 right-4 z-[9999] flex h-10 w-10 items-center justify-center rounded-full bg-red-600 text-xl text-white shadow-lg"
|
|
||||||
data-camera-ui
|
|
||||||
>
|
|
||||||
×
|
|
||||||
</button>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
interface Props {
|
|
||||||
onaccept: () => void;
|
|
||||||
ondecline: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { onaccept, ondecline }: Props = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-4" data-camera-ui>
|
|
||||||
<div class="w-full max-w-xs rounded-lg bg-neutral-900 p-4">
|
|
||||||
<p class="mb-4 text-center text-sm text-white">Photo requested</p>
|
|
||||||
<div class="flex gap-3">
|
|
||||||
<button onclick={ondecline} class="flex-1 rounded bg-neutral-700 py-2 text-sm text-white">
|
|
||||||
Decline
|
|
||||||
</button>
|
|
||||||
<button onclick={onaccept} class="flex-1 rounded bg-blue-600 py-2 text-sm text-white">
|
|
||||||
Capture
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
oncapture: (base64: string, mediaType: string, thumbnailBase64: string) => void;
|
|
||||||
onunpair?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { oncapture, onunpair }: Props = $props();
|
|
||||||
|
|
||||||
let videoElement: HTMLVideoElement | null = $state(null);
|
|
||||||
let stream: MediaStream | null = $state(null);
|
|
||||||
let ready = $state(false);
|
|
||||||
|
|
||||||
async function findUltraWideCamera(): Promise<string | null> {
|
|
||||||
try {
|
|
||||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
||||||
const videoDevices = devices.filter((d) => d.kind === 'videoinput');
|
|
||||||
const ultraWide = videoDevices.find(
|
|
||||||
(d) => d.label.toLowerCase().includes('ultra') && d.label.toLowerCase().includes('back')
|
|
||||||
);
|
|
||||||
return ultraWide?.deviceId ?? null;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function startCamera() {
|
|
||||||
if (!navigator.mediaDevices?.getUserMedia) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
stream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: { facingMode: { ideal: 'environment' } },
|
|
||||||
audio: false
|
|
||||||
});
|
|
||||||
|
|
||||||
const ultraWideId = await findUltraWideCamera();
|
|
||||||
|
|
||||||
if (ultraWideId) {
|
|
||||||
stream.getTracks().forEach((t) => t.stop());
|
|
||||||
stream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: {
|
|
||||||
deviceId: { exact: ultraWideId },
|
|
||||||
width: { ideal: 4032 },
|
|
||||||
height: { ideal: 3024 }
|
|
||||||
},
|
|
||||||
audio: false
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
stream.getTracks().forEach((t) => t.stop());
|
|
||||||
stream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: {
|
|
||||||
facingMode: { ideal: 'environment' },
|
|
||||||
width: { ideal: 4032 },
|
|
||||||
height: { ideal: 3024 }
|
|
||||||
},
|
|
||||||
audio: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (videoElement) {
|
|
||||||
videoElement.srcObject = stream;
|
|
||||||
await new Promise<void>((resolve) => {
|
|
||||||
if (videoElement) {
|
|
||||||
videoElement.onloadedmetadata = () => resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ready = true;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
ready = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function capture() {
|
|
||||||
if (!ready || !videoElement) return false;
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
canvas.width = videoElement.videoWidth;
|
|
||||||
canvas.height = videoElement.videoHeight;
|
|
||||||
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
if (!ctx) return false;
|
|
||||||
|
|
||||||
ctx.drawImage(videoElement, 0, 0);
|
|
||||||
|
|
||||||
const maxSize = 1920;
|
|
||||||
const scale = Math.min(maxSize / canvas.width, maxSize / canvas.height, 1);
|
|
||||||
const outCanvas = document.createElement('canvas');
|
|
||||||
outCanvas.width = Math.round(canvas.width * scale);
|
|
||||||
outCanvas.height = Math.round(canvas.height * scale);
|
|
||||||
const outCtx = outCanvas.getContext('2d');
|
|
||||||
if (!outCtx) return false;
|
|
||||||
outCtx.drawImage(canvas, 0, 0, outCanvas.width, outCanvas.height);
|
|
||||||
|
|
||||||
const base64 = outCanvas.toDataURL('image/jpeg', 0.65).split(',')[1];
|
|
||||||
const mediaType = 'image/jpeg';
|
|
||||||
|
|
||||||
const thumbMaxSize = 800;
|
|
||||||
const thumbScale = Math.min(thumbMaxSize / outCanvas.width, thumbMaxSize / outCanvas.height, 1);
|
|
||||||
const thumbCanvas = document.createElement('canvas');
|
|
||||||
thumbCanvas.width = Math.round(outCanvas.width * thumbScale);
|
|
||||||
thumbCanvas.height = Math.round(outCanvas.height * thumbScale);
|
|
||||||
const thumbCtx = thumbCanvas.getContext('2d');
|
|
||||||
if (thumbCtx) {
|
|
||||||
thumbCtx.drawImage(outCanvas, 0, 0, thumbCanvas.width, thumbCanvas.height);
|
|
||||||
}
|
|
||||||
const thumbnailBase64 = thumbCanvas.toDataURL('image/jpeg', 0.6).split(',')[1];
|
|
||||||
|
|
||||||
oncapture(base64, mediaType, thumbnailBase64);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
startCamera();
|
|
||||||
return () => {
|
|
||||||
if (stream) {
|
|
||||||
stream.getTracks().forEach((track) => track.stop());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="fixed inset-0 z-40 bg-black">
|
|
||||||
<video bind:this={videoElement} autoplay playsinline muted class="h-full w-full object-cover"
|
|
||||||
></video>
|
|
||||||
{#if onunpair}
|
|
||||||
<button
|
|
||||||
onclick={onunpair}
|
|
||||||
class="absolute top-4 left-4 z-10 rounded-full bg-red-600/80 px-3 py-1.5 text-xs text-white"
|
|
||||||
>
|
|
||||||
unpair
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
let stealthMode = $state(false);
|
|
||||||
let lastTap = $state({ time: 0, x: 0, y: 0 });
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
document.body.style.touchAction = 'manipulation';
|
|
||||||
return () => {
|
|
||||||
document.body.style.touchAction = '';
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
function isInCenterZone(x: number, y: number): boolean {
|
|
||||||
const w = window.innerWidth;
|
|
||||||
const h = window.innerHeight;
|
|
||||||
return x > w * 0.3 && x < w * 0.7 && y > h * 0.3 && y < h * 0.7;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleTouchEnd(e: TouchEvent) {
|
|
||||||
if (e.touches.length > 0) return;
|
|
||||||
|
|
||||||
const target = e.target as HTMLElement;
|
|
||||||
if (target?.closest('[data-camera-ui]')) return;
|
|
||||||
|
|
||||||
const touch = e.changedTouches[0];
|
|
||||||
const now = Date.now();
|
|
||||||
const x = touch.clientX;
|
|
||||||
const y = touch.clientY;
|
|
||||||
|
|
||||||
if (!isInCenterZone(x, y)) {
|
|
||||||
lastTap = { time: 0, x: 0, y: 0 };
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeDiff = now - lastTap.time;
|
|
||||||
const distX = Math.abs(x - lastTap.x);
|
|
||||||
const distY = Math.abs(y - lastTap.y);
|
|
||||||
|
|
||||||
if (timeDiff < 500 && distX < 50 && distY < 50) {
|
|
||||||
stealthMode = !stealthMode;
|
|
||||||
lastTap = { time: 0, x: 0, y: 0 };
|
|
||||||
e.preventDefault();
|
|
||||||
} else {
|
|
||||||
lastTap = { time: now, x, y };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:document ontouchend={handleTouchEnd} />
|
|
||||||
|
|
||||||
{#if stealthMode}
|
|
||||||
<div class="stealth-overlay" ontouchend={handleTouchEnd}></div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.stealth-overlay {
|
|
||||||
position: fixed;
|
|
||||||
inset: 0;
|
|
||||||
z-index: 9999;
|
|
||||||
background: #000;
|
|
||||||
touch-action: manipulation;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
oncomplete: () => void;
|
|
||||||
oncancel: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { oncomplete, oncancel }: Props = $props();
|
|
||||||
|
|
||||||
let count = $state(3);
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
count--;
|
|
||||||
if (count === 0) {
|
|
||||||
clearInterval(interval);
|
|
||||||
oncomplete();
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="fixed inset-0 z-50 flex flex-col items-center justify-center bg-black" data-camera-ui>
|
|
||||||
<span class="text-8xl font-bold text-white">{count}</span>
|
|
||||||
<button onclick={oncancel} class="mt-8 text-sm text-neutral-400">Cancel</button>
|
|
||||||
</div>
|
|
||||||
@@ -47,11 +47,7 @@ export function usePollingMutation<Mutation extends FunctionReference<'mutation'
|
|||||||
export function usePollingQuery<Query extends FunctionReference<'query'>>(
|
export function usePollingQuery<Query extends FunctionReference<'query'>>(
|
||||||
query: Query,
|
query: Query,
|
||||||
argsGetter: () => FunctionArgs<Query> | 'skip'
|
argsGetter: () => FunctionArgs<Query> | 'skip'
|
||||||
): {
|
): { data: FunctionReturnType<Query> | undefined; error: Error | null; isLoading: boolean } {
|
||||||
data: FunctionReturnType<Query> | undefined;
|
|
||||||
error: Error | null;
|
|
||||||
isLoading: boolean;
|
|
||||||
} {
|
|
||||||
const client = usePollingClient();
|
const client = usePollingClient();
|
||||||
|
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
|
|||||||
+1
-420
@@ -9,19 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type * as chats from "../chats.js";
|
import type * as chats from "../chats.js";
|
||||||
import type * as collaborative from "../collaborative.js";
|
|
||||||
import type * as devicePairings from "../devicePairings.js";
|
|
||||||
import type * as http from "../http.js";
|
|
||||||
import type * as incomingSheets from "../incomingSheets.js";
|
|
||||||
import type * as inject from "../inject.js";
|
|
||||||
import type * as injectConnections from "../injectConnections.js";
|
|
||||||
import type * as messages from "../messages.js";
|
import type * as messages from "../messages.js";
|
||||||
import type * as pairingRequests from "../pairingRequests.js";
|
|
||||||
import type * as pendingGenerations from "../pendingGenerations.js";
|
import type * as pendingGenerations from "../pendingGenerations.js";
|
||||||
import type * as photoDrafts from "../photoDrafts.js";
|
|
||||||
import type * as photoRequests from "../photoRequests.js";
|
|
||||||
import type * as rag from "../rag.js";
|
|
||||||
import type * as ragConnections from "../ragConnections.js";
|
|
||||||
import type * as users from "../users.js";
|
import type * as users from "../users.js";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -32,19 +21,8 @@ import type {
|
|||||||
|
|
||||||
declare const fullApi: ApiFromModules<{
|
declare const fullApi: ApiFromModules<{
|
||||||
chats: typeof chats;
|
chats: typeof chats;
|
||||||
collaborative: typeof collaborative;
|
|
||||||
devicePairings: typeof devicePairings;
|
|
||||||
http: typeof http;
|
|
||||||
incomingSheets: typeof incomingSheets;
|
|
||||||
inject: typeof inject;
|
|
||||||
injectConnections: typeof injectConnections;
|
|
||||||
messages: typeof messages;
|
messages: typeof messages;
|
||||||
pairingRequests: typeof pairingRequests;
|
|
||||||
pendingGenerations: typeof pendingGenerations;
|
pendingGenerations: typeof pendingGenerations;
|
||||||
photoDrafts: typeof photoDrafts;
|
|
||||||
photoRequests: typeof photoRequests;
|
|
||||||
rag: typeof rag;
|
|
||||||
ragConnections: typeof ragConnections;
|
|
||||||
users: typeof users;
|
users: typeof users;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
@@ -74,401 +52,4 @@ export declare const internal: FilterApi<
|
|||||||
FunctionReference<any, "internal">
|
FunctionReference<any, "internal">
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export declare const components: {
|
export declare const components: {};
|
||||||
rag: {
|
|
||||||
chunks: {
|
|
||||||
insert: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
chunks: Array<{
|
|
||||||
content: { metadata?: Record<string, any>; text: string };
|
|
||||||
embedding: Array<number>;
|
|
||||||
searchableText?: string;
|
|
||||||
}>;
|
|
||||||
entryId: string;
|
|
||||||
startOrder: number;
|
|
||||||
},
|
|
||||||
{ status: "pending" | "ready" | "replaced" }
|
|
||||||
>;
|
|
||||||
list: FunctionReference<
|
|
||||||
"query",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
entryId: string;
|
|
||||||
order: "desc" | "asc";
|
|
||||||
paginationOpts: {
|
|
||||||
cursor: string | null;
|
|
||||||
endCursor?: string | null;
|
|
||||||
id?: number;
|
|
||||||
maximumBytesRead?: number;
|
|
||||||
maximumRowsRead?: number;
|
|
||||||
numItems: number;
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{
|
|
||||||
continueCursor: string;
|
|
||||||
isDone: boolean;
|
|
||||||
page: Array<{
|
|
||||||
metadata?: Record<string, any>;
|
|
||||||
order: number;
|
|
||||||
state: "pending" | "ready" | "replaced";
|
|
||||||
text: string;
|
|
||||||
}>;
|
|
||||||
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
||||||
splitCursor?: string | null;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
replaceChunksPage: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{ entryId: string; startOrder: number },
|
|
||||||
{ nextStartOrder: number; status: "pending" | "ready" | "replaced" }
|
|
||||||
>;
|
|
||||||
};
|
|
||||||
entries: {
|
|
||||||
add: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
allChunks?: Array<{
|
|
||||||
content: { metadata?: Record<string, any>; text: string };
|
|
||||||
embedding: Array<number>;
|
|
||||||
searchableText?: string;
|
|
||||||
}>;
|
|
||||||
entry: {
|
|
||||||
contentHash?: string;
|
|
||||||
filterValues: Array<{ name: string; value: any }>;
|
|
||||||
importance: number;
|
|
||||||
key?: string;
|
|
||||||
metadata?: Record<string, any>;
|
|
||||||
namespaceId: string;
|
|
||||||
title?: string;
|
|
||||||
};
|
|
||||||
onComplete?: string;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
created: boolean;
|
|
||||||
entryId: string;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
addAsync: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
chunker: string;
|
|
||||||
entry: {
|
|
||||||
contentHash?: string;
|
|
||||||
filterValues: Array<{ name: string; value: any }>;
|
|
||||||
importance: number;
|
|
||||||
key?: string;
|
|
||||||
metadata?: Record<string, any>;
|
|
||||||
namespaceId: string;
|
|
||||||
title?: string;
|
|
||||||
};
|
|
||||||
onComplete?: string;
|
|
||||||
},
|
|
||||||
{ created: boolean; entryId: string; status: "pending" | "ready" }
|
|
||||||
>;
|
|
||||||
deleteAsync: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{ entryId: string; startOrder: number },
|
|
||||||
null
|
|
||||||
>;
|
|
||||||
deleteByKeyAsync: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{ beforeVersion?: number; key: string; namespaceId: string },
|
|
||||||
null
|
|
||||||
>;
|
|
||||||
deleteByKeySync: FunctionReference<
|
|
||||||
"action",
|
|
||||||
"internal",
|
|
||||||
{ key: string; namespaceId: string },
|
|
||||||
null
|
|
||||||
>;
|
|
||||||
deleteSync: FunctionReference<
|
|
||||||
"action",
|
|
||||||
"internal",
|
|
||||||
{ entryId: string },
|
|
||||||
null
|
|
||||||
>;
|
|
||||||
findByContentHash: FunctionReference<
|
|
||||||
"query",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
contentHash: string;
|
|
||||||
dimension: number;
|
|
||||||
filterNames: Array<string>;
|
|
||||||
key: string;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
contentHash?: string;
|
|
||||||
entryId: string;
|
|
||||||
filterValues: Array<{ name: string; value: any }>;
|
|
||||||
importance: number;
|
|
||||||
key?: string;
|
|
||||||
metadata?: Record<string, any>;
|
|
||||||
replacedAt?: number;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
title?: string;
|
|
||||||
} | null
|
|
||||||
>;
|
|
||||||
get: FunctionReference<
|
|
||||||
"query",
|
|
||||||
"internal",
|
|
||||||
{ entryId: string },
|
|
||||||
{
|
|
||||||
contentHash?: string;
|
|
||||||
entryId: string;
|
|
||||||
filterValues: Array<{ name: string; value: any }>;
|
|
||||||
importance: number;
|
|
||||||
key?: string;
|
|
||||||
metadata?: Record<string, any>;
|
|
||||||
replacedAt?: number;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
title?: string;
|
|
||||||
} | null
|
|
||||||
>;
|
|
||||||
list: FunctionReference<
|
|
||||||
"query",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
namespaceId?: string;
|
|
||||||
order?: "desc" | "asc";
|
|
||||||
paginationOpts: {
|
|
||||||
cursor: string | null;
|
|
||||||
endCursor?: string | null;
|
|
||||||
id?: number;
|
|
||||||
maximumBytesRead?: number;
|
|
||||||
maximumRowsRead?: number;
|
|
||||||
numItems: number;
|
|
||||||
};
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
},
|
|
||||||
{
|
|
||||||
continueCursor: string;
|
|
||||||
isDone: boolean;
|
|
||||||
page: Array<{
|
|
||||||
contentHash?: string;
|
|
||||||
entryId: string;
|
|
||||||
filterValues: Array<{ name: string; value: any }>;
|
|
||||||
importance: number;
|
|
||||||
key?: string;
|
|
||||||
metadata?: Record<string, any>;
|
|
||||||
replacedAt?: number;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
title?: string;
|
|
||||||
}>;
|
|
||||||
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
||||||
splitCursor?: string | null;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
promoteToReady: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{ entryId: string },
|
|
||||||
{
|
|
||||||
replacedEntry: {
|
|
||||||
contentHash?: string;
|
|
||||||
entryId: string;
|
|
||||||
filterValues: Array<{ name: string; value: any }>;
|
|
||||||
importance: number;
|
|
||||||
key?: string;
|
|
||||||
metadata?: Record<string, any>;
|
|
||||||
replacedAt?: number;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
title?: string;
|
|
||||||
} | null;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
};
|
|
||||||
namespaces: {
|
|
||||||
deleteNamespace: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{ namespaceId: string },
|
|
||||||
{
|
|
||||||
deletedNamespace: null | {
|
|
||||||
createdAt: number;
|
|
||||||
dimension: number;
|
|
||||||
filterNames: Array<string>;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
namespaceId: string;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
version: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
deleteNamespaceSync: FunctionReference<
|
|
||||||
"action",
|
|
||||||
"internal",
|
|
||||||
{ namespaceId: string },
|
|
||||||
null
|
|
||||||
>;
|
|
||||||
get: FunctionReference<
|
|
||||||
"query",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
dimension: number;
|
|
||||||
filterNames: Array<string>;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
},
|
|
||||||
null | {
|
|
||||||
createdAt: number;
|
|
||||||
dimension: number;
|
|
||||||
filterNames: Array<string>;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
namespaceId: string;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
version: number;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
getOrCreate: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
dimension: number;
|
|
||||||
filterNames: Array<string>;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
onComplete?: string;
|
|
||||||
status: "pending" | "ready";
|
|
||||||
},
|
|
||||||
{ namespaceId: string; status: "pending" | "ready" }
|
|
||||||
>;
|
|
||||||
list: FunctionReference<
|
|
||||||
"query",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
paginationOpts: {
|
|
||||||
cursor: string | null;
|
|
||||||
endCursor?: string | null;
|
|
||||||
id?: number;
|
|
||||||
maximumBytesRead?: number;
|
|
||||||
maximumRowsRead?: number;
|
|
||||||
numItems: number;
|
|
||||||
};
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
},
|
|
||||||
{
|
|
||||||
continueCursor: string;
|
|
||||||
isDone: boolean;
|
|
||||||
page: Array<{
|
|
||||||
createdAt: number;
|
|
||||||
dimension: number;
|
|
||||||
filterNames: Array<string>;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
namespaceId: string;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
version: number;
|
|
||||||
}>;
|
|
||||||
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
||||||
splitCursor?: string | null;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
listNamespaceVersions: FunctionReference<
|
|
||||||
"query",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
namespace: string;
|
|
||||||
paginationOpts: {
|
|
||||||
cursor: string | null;
|
|
||||||
endCursor?: string | null;
|
|
||||||
id?: number;
|
|
||||||
maximumBytesRead?: number;
|
|
||||||
maximumRowsRead?: number;
|
|
||||||
numItems: number;
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{
|
|
||||||
continueCursor: string;
|
|
||||||
isDone: boolean;
|
|
||||||
page: Array<{
|
|
||||||
createdAt: number;
|
|
||||||
dimension: number;
|
|
||||||
filterNames: Array<string>;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
namespaceId: string;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
version: number;
|
|
||||||
}>;
|
|
||||||
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
||||||
splitCursor?: string | null;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
lookup: FunctionReference<
|
|
||||||
"query",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
dimension: number;
|
|
||||||
filterNames: Array<string>;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
},
|
|
||||||
null | string
|
|
||||||
>;
|
|
||||||
promoteToReady: FunctionReference<
|
|
||||||
"mutation",
|
|
||||||
"internal",
|
|
||||||
{ namespaceId: string },
|
|
||||||
{
|
|
||||||
replacedNamespace: null | {
|
|
||||||
createdAt: number;
|
|
||||||
dimension: number;
|
|
||||||
filterNames: Array<string>;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
namespaceId: string;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
version: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
};
|
|
||||||
search: {
|
|
||||||
search: FunctionReference<
|
|
||||||
"action",
|
|
||||||
"internal",
|
|
||||||
{
|
|
||||||
chunkContext?: { after: number; before: number };
|
|
||||||
embedding: Array<number>;
|
|
||||||
filters: Array<{ name: string; value: any }>;
|
|
||||||
limit: number;
|
|
||||||
modelId: string;
|
|
||||||
namespace: string;
|
|
||||||
vectorScoreThreshold?: number;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
entries: Array<{
|
|
||||||
contentHash?: string;
|
|
||||||
entryId: string;
|
|
||||||
filterValues: Array<{ name: string; value: any }>;
|
|
||||||
importance: number;
|
|
||||||
key?: string;
|
|
||||||
metadata?: Record<string, any>;
|
|
||||||
replacedAt?: number;
|
|
||||||
status: "pending" | "ready" | "replaced";
|
|
||||||
title?: string;
|
|
||||||
}>;
|
|
||||||
results: Array<{
|
|
||||||
content: Array<{ metadata?: Record<string, any>; text: string }>;
|
|
||||||
entryId: string;
|
|
||||||
order: number;
|
|
||||||
score: number;
|
|
||||||
startOrder: number;
|
|
||||||
}>;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -43,15 +43,8 @@ export const clear = mutation({
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
if (args.preserveImages) {
|
if (args.preserveImages && message.imageBase64) {
|
||||||
const hasLegacyImage = message.imageBase64 || message.imagesBase64?.length;
|
continue;
|
||||||
const messageImages = await ctx.db
|
|
||||||
.query('messageImages')
|
|
||||||
.withIndex('by_message_id', (q) => q.eq('messageId', message._id))
|
|
||||||
.first();
|
|
||||||
if (hasLegacyImage || messageImages) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await ctx.db.delete(message._id);
|
await ctx.db.delete(message._id);
|
||||||
}
|
}
|
||||||
@@ -80,28 +73,7 @@ export const getWithUser = query({
|
|||||||
followUpPrompt: v.optional(v.string()),
|
followUpPrompt: v.optional(v.string()),
|
||||||
model: v.string(),
|
model: v.string(),
|
||||||
followUpModel: v.optional(v.string()),
|
followUpModel: v.optional(v.string()),
|
||||||
activeChatId: v.optional(v.id('chats')),
|
activeChatId: v.optional(v.id('chats'))
|
||||||
ragCollectionMode: v.optional(
|
|
||||||
v.object({
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
injectCollectionMode: v.optional(
|
|
||||||
v.object({
|
|
||||||
injectDatabaseId: v.id('injectDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
collaborativeRoom: v.optional(
|
|
||||||
v.object({
|
|
||||||
pin: v.string(),
|
|
||||||
creatorToken: v.optional(v.string()),
|
|
||||||
joinedAt: v.number(),
|
|
||||||
lastSeenHistoryCount: v.optional(v.number()),
|
|
||||||
lastSeenSheetId: v.optional(v.number())
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
v.null()
|
v.null()
|
||||||
|
|||||||
@@ -1,148 +0,0 @@
|
|||||||
import { v } from 'convex/values';
|
|
||||||
import { mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
const PENDING_UPLOAD_RETURN = v.object({
|
|
||||||
_id: v.id('pendingRoomUploads'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
pin: v.string(),
|
|
||||||
imageBase64: v.string(),
|
|
||||||
mediaType: v.string(),
|
|
||||||
status: v.union(
|
|
||||||
v.literal('pending'),
|
|
||||||
v.literal('uploading'),
|
|
||||||
v.literal('done'),
|
|
||||||
v.literal('failed')
|
|
||||||
),
|
|
||||||
attempts: v.number(),
|
|
||||||
lastError: v.optional(v.string()),
|
|
||||||
createdAt: v.number(),
|
|
||||||
updatedAt: v.number()
|
|
||||||
});
|
|
||||||
|
|
||||||
export const enqueueUpload = mutation({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
pin: v.string(),
|
|
||||||
imageBase64: v.string(),
|
|
||||||
mediaType: v.string()
|
|
||||||
},
|
|
||||||
returns: v.id('pendingRoomUploads'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const now = Date.now();
|
|
||||||
return await ctx.db.insert('pendingRoomUploads', {
|
|
||||||
userId: args.userId,
|
|
||||||
pin: args.pin,
|
|
||||||
imageBase64: args.imageBase64,
|
|
||||||
mediaType: args.mediaType,
|
|
||||||
status: 'pending',
|
|
||||||
attempts: 0,
|
|
||||||
createdAt: now,
|
|
||||||
updatedAt: now
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const listPendingUploads = query({
|
|
||||||
args: {},
|
|
||||||
returns: v.array(PENDING_UPLOAD_RETURN),
|
|
||||||
handler: async (ctx) => {
|
|
||||||
const now = Date.now();
|
|
||||||
const items = await ctx.db
|
|
||||||
.query('pendingRoomUploads')
|
|
||||||
.withIndex('by_status_and_updated_at', (q) => q.eq('status', 'pending'))
|
|
||||||
.collect();
|
|
||||||
return items.filter((i) => i.updatedAt <= now);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const markUploading = mutation({
|
|
||||||
args: { id: v.id('pendingRoomUploads') },
|
|
||||||
returns: v.boolean(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const item = await ctx.db.get(args.id);
|
|
||||||
if (!item || item.status !== 'pending') return false;
|
|
||||||
await ctx.db.patch(args.id, { status: 'uploading', updatedAt: Date.now() });
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const markDone = mutation({
|
|
||||||
args: { id: v.id('pendingRoomUploads') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.delete(args.id);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const bumpAttempt = mutation({
|
|
||||||
args: {
|
|
||||||
id: v.id('pendingRoomUploads'),
|
|
||||||
error: v.string(),
|
|
||||||
nextRetryAt: v.number()
|
|
||||||
},
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const item = await ctx.db.get(args.id);
|
|
||||||
if (!item) return null;
|
|
||||||
await ctx.db.patch(args.id, {
|
|
||||||
status: 'pending',
|
|
||||||
attempts: item.attempts + 1,
|
|
||||||
lastError: args.error,
|
|
||||||
updatedAt: args.nextRetryAt
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const markFailed = mutation({
|
|
||||||
args: { id: v.id('pendingRoomUploads'), error: v.string() },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const item = await ctx.db.get(args.id);
|
|
||||||
if (!item) return null;
|
|
||||||
await ctx.db.patch(args.id, {
|
|
||||||
status: 'failed',
|
|
||||||
lastError: args.error,
|
|
||||||
updatedAt: Date.now()
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const resetStuckUploads = mutation({
|
|
||||||
args: {},
|
|
||||||
returns: v.number(),
|
|
||||||
handler: async (ctx) => {
|
|
||||||
const stuck = await ctx.db
|
|
||||||
.query('pendingRoomUploads')
|
|
||||||
.withIndex('by_status_and_updated_at', (q) => q.eq('status', 'uploading'))
|
|
||||||
.collect();
|
|
||||||
const now = Date.now();
|
|
||||||
for (const item of stuck) {
|
|
||||||
await ctx.db.patch(item._id, { status: 'pending', updatedAt: now });
|
|
||||||
}
|
|
||||||
return stuck.length;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const queueDepthForUser = query({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.object({
|
|
||||||
pending: v.number(),
|
|
||||||
uploading: v.number(),
|
|
||||||
failed: v.number()
|
|
||||||
}),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const all = await ctx.db
|
|
||||||
.query('pendingRoomUploads')
|
|
||||||
.withIndex('by_user_id', (q) => q.eq('userId', args.userId))
|
|
||||||
.collect();
|
|
||||||
return {
|
|
||||||
pending: all.filter((i) => i.status === 'pending').length,
|
|
||||||
uploading: all.filter((i) => i.status === 'uploading').length,
|
|
||||||
failed: all.filter((i) => i.status === 'failed').length
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import { defineApp } from 'convex/server';
|
|
||||||
import rag from '@convex-dev/rag/convex.config';
|
|
||||||
|
|
||||||
const app = defineApp();
|
|
||||||
app.use(rag);
|
|
||||||
|
|
||||||
export default app;
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
import { v } from 'convex/values';
|
|
||||||
import { mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
export const register = mutation({
|
|
||||||
args: {
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string(),
|
|
||||||
hasCamera: v.boolean()
|
|
||||||
},
|
|
||||||
returns: v.id('devicePairings'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const existing = await ctx.db
|
|
||||||
.query('devicePairings')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
const device = existing.find((d) => d.deviceId === args.deviceId);
|
|
||||||
|
|
||||||
if (device) {
|
|
||||||
await ctx.db.patch(device._id, {
|
|
||||||
hasCamera: args.hasCamera,
|
|
||||||
lastSeen: Date.now()
|
|
||||||
});
|
|
||||||
return device._id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await ctx.db.insert('devicePairings', {
|
|
||||||
chatId: args.chatId,
|
|
||||||
deviceId: args.deviceId,
|
|
||||||
hasCamera: args.hasCamera,
|
|
||||||
lastSeen: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const heartbeat = mutation({
|
|
||||||
args: {
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string()
|
|
||||||
},
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const devices = await ctx.db
|
|
||||||
.query('devicePairings')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
const device = devices.find((d) => d.deviceId === args.deviceId);
|
|
||||||
if (device) {
|
|
||||||
await ctx.db.patch(device._id, { lastSeen: Date.now() });
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getMyDevice = query({
|
|
||||||
args: { chatId: v.id('chats'), deviceId: v.string() },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('devicePairings'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string(),
|
|
||||||
hasCamera: v.boolean(),
|
|
||||||
pairedWithDeviceId: v.optional(v.string()),
|
|
||||||
lastSeen: v.number()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const devices = await ctx.db
|
|
||||||
.query('devicePairings')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
return devices.find((d) => d.deviceId === args.deviceId) ?? null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getPairedDevice = query({
|
|
||||||
args: { chatId: v.id('chats'), deviceId: v.string() },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('devicePairings'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string(),
|
|
||||||
hasCamera: v.boolean(),
|
|
||||||
pairedWithDeviceId: v.optional(v.string()),
|
|
||||||
lastSeen: v.number()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const devices = await ctx.db
|
|
||||||
.query('devicePairings')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
const myDevice = devices.find((d) => d.deviceId === args.deviceId);
|
|
||||||
if (!myDevice?.pairedWithDeviceId) return null;
|
|
||||||
|
|
||||||
const thirtySecondsAgo = Date.now() - 30000;
|
|
||||||
const paired = devices.find(
|
|
||||||
(d) => d.deviceId === myDevice.pairedWithDeviceId && d.lastSeen > thirtySecondsAgo
|
|
||||||
);
|
|
||||||
return paired ?? null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
import { httpRouter } from 'convex/server';
|
|
||||||
import { httpAction } from './_generated/server';
|
|
||||||
import { api } from './_generated/api';
|
|
||||||
import type { Id } from './_generated/dataModel';
|
|
||||||
|
|
||||||
const http = httpRouter();
|
|
||||||
|
|
||||||
http.route({
|
|
||||||
path: '/rag/search',
|
|
||||||
method: 'POST',
|
|
||||||
handler: httpAction(async (ctx, req) => {
|
|
||||||
const body = await req.json();
|
|
||||||
const { userId, dbNames, query, apiKey, limit } = body as {
|
|
||||||
userId: string;
|
|
||||||
dbNames: string[];
|
|
||||||
query: string;
|
|
||||||
apiKey: string;
|
|
||||||
limit?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!userId || !dbNames || !query || !apiKey) {
|
|
||||||
return new Response(JSON.stringify({ error: 'Missing required fields' }), {
|
|
||||||
status: 400,
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await ctx.runAction(api.rag.searchMultiple, {
|
|
||||||
userId: userId as Id<'users'>,
|
|
||||||
dbNames,
|
|
||||||
apiKey,
|
|
||||||
query,
|
|
||||||
limit
|
|
||||||
});
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result), {
|
|
||||||
status: 200,
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
});
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
export default http;
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
import { v } from 'convex/values';
|
|
||||||
import { mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
const SHEET_RETURN = v.object({
|
|
||||||
_id: v.id('incomingSheets'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
pin: v.string(),
|
|
||||||
sheetId: v.number(),
|
|
||||||
sheetCreatedAt: v.number(),
|
|
||||||
text: v.string(),
|
|
||||||
status: v.union(v.literal('preview'), v.literal('accepted'), v.literal('dismissed')),
|
|
||||||
linkedMessageId: v.optional(v.id('messages')),
|
|
||||||
acceptedAt: v.optional(v.number()),
|
|
||||||
createdAt: v.number()
|
|
||||||
});
|
|
||||||
|
|
||||||
export const createMany = mutation({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
pin: v.string(),
|
|
||||||
sheets: v.array(
|
|
||||||
v.object({
|
|
||||||
sheetId: v.number(),
|
|
||||||
sheetCreatedAt: v.number(),
|
|
||||||
text: v.string()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
},
|
|
||||||
returns: v.number(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const now = Date.now();
|
|
||||||
let inserted = 0;
|
|
||||||
for (const s of args.sheets) {
|
|
||||||
const existing = await ctx.db
|
|
||||||
.query('incomingSheets')
|
|
||||||
.withIndex('by_chat_id_and_sheet_id', (q) =>
|
|
||||||
q.eq('chatId', args.chatId).eq('sheetId', s.sheetId)
|
|
||||||
)
|
|
||||||
.unique();
|
|
||||||
if (existing) continue;
|
|
||||||
await ctx.db.insert('incomingSheets', {
|
|
||||||
userId: args.userId,
|
|
||||||
chatId: args.chatId,
|
|
||||||
pin: args.pin,
|
|
||||||
sheetId: s.sheetId,
|
|
||||||
sheetCreatedAt: s.sheetCreatedAt,
|
|
||||||
text: s.text,
|
|
||||||
status: 'preview',
|
|
||||||
createdAt: now
|
|
||||||
});
|
|
||||||
inserted += 1;
|
|
||||||
}
|
|
||||||
return inserted;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const listForChat = query({
|
|
||||||
args: {
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
status: v.union(v.literal('preview'), v.literal('accepted'), v.literal('dismissed'))
|
|
||||||
},
|
|
||||||
returns: v.array(SHEET_RETURN),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db
|
|
||||||
.query('incomingSheets')
|
|
||||||
.withIndex('by_chat_id_and_status', (q) =>
|
|
||||||
q.eq('chatId', args.chatId).eq('status', args.status)
|
|
||||||
)
|
|
||||||
.order('asc')
|
|
||||||
.collect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const accept = mutation({
|
|
||||||
args: { id: v.id('incomingSheets') },
|
|
||||||
returns: v.union(v.id('messages'), v.null()),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const sheet = await ctx.db.get(args.id);
|
|
||||||
if (!sheet || sheet.status !== 'preview') return null;
|
|
||||||
|
|
||||||
const messageId = await ctx.db.insert('messages', {
|
|
||||||
chatId: sheet.chatId,
|
|
||||||
role: 'user',
|
|
||||||
content: sheet.text,
|
|
||||||
source: 'web',
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
|
|
||||||
const chat = await ctx.db.get(sheet.chatId);
|
|
||||||
if (chat) {
|
|
||||||
await ctx.db.insert('pendingGenerations', {
|
|
||||||
userId: chat.userId,
|
|
||||||
chatId: sheet.chatId,
|
|
||||||
userMessage: sheet.text,
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await ctx.db.patch(args.id, {
|
|
||||||
status: 'accepted',
|
|
||||||
linkedMessageId: messageId,
|
|
||||||
acceptedAt: Date.now()
|
|
||||||
});
|
|
||||||
|
|
||||||
return messageId;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const dismiss = mutation({
|
|
||||||
args: { id: v.id('incomingSheets') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const sheet = await ctx.db.get(args.id);
|
|
||||||
if (!sheet || sheet.status !== 'preview') return null;
|
|
||||||
await ctx.db.patch(args.id, { status: 'dismissed' });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
import { v } from 'convex/values';
|
|
||||||
import { mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
export const createDatabase = mutation({
|
|
||||||
args: { userId: v.id('users'), name: v.string() },
|
|
||||||
returns: v.id('injectDatabases'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const existing = await ctx.db
|
|
||||||
.query('injectDatabases')
|
|
||||||
.withIndex('by_user_id_and_name', (q) => q.eq('userId', args.userId).eq('name', args.name))
|
|
||||||
.unique();
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
return existing._id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await ctx.db.insert('injectDatabases', {
|
|
||||||
userId: args.userId,
|
|
||||||
name: args.name,
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getDatabase = query({
|
|
||||||
args: { userId: v.id('users'), name: v.string() },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('injectDatabases'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
name: v.string(),
|
|
||||||
content: v.optional(v.string()),
|
|
||||||
createdAt: v.number()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db
|
|
||||||
.query('injectDatabases')
|
|
||||||
.withIndex('by_user_id_and_name', (q) => q.eq('userId', args.userId).eq('name', args.name))
|
|
||||||
.unique();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getDatabaseById = query({
|
|
||||||
args: { injectDatabaseId: v.id('injectDatabases') },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('injectDatabases'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
name: v.string(),
|
|
||||||
content: v.optional(v.string()),
|
|
||||||
createdAt: v.number()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db.get(args.injectDatabaseId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const listDatabases = query({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.array(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('injectDatabases'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
name: v.string(),
|
|
||||||
content: v.optional(v.string()),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db
|
|
||||||
.query('injectDatabases')
|
|
||||||
.withIndex('by_user_id', (q) => q.eq('userId', args.userId))
|
|
||||||
.collect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const setContent = mutation({
|
|
||||||
args: { injectDatabaseId: v.id('injectDatabases'), content: v.string() },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.injectDatabaseId, { content: args.content });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const deleteDatabase = mutation({
|
|
||||||
args: { injectDatabaseId: v.id('injectDatabases') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const connections = await ctx.db
|
|
||||||
.query('injectConnections')
|
|
||||||
.withIndex('by_inject_database_id', (q) => q.eq('injectDatabaseId', args.injectDatabaseId))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
for (const conn of connections) {
|
|
||||||
await ctx.db.delete(conn._id);
|
|
||||||
}
|
|
||||||
|
|
||||||
await ctx.db.delete(args.injectDatabaseId);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
import { v } from 'convex/values';
|
|
||||||
import { mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
export const connect = mutation({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
injectDatabaseId: v.id('injectDatabases'),
|
|
||||||
isGlobal: v.optional(v.boolean())
|
|
||||||
},
|
|
||||||
returns: v.id('injectConnections'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const existing = await ctx.db
|
|
||||||
.query('injectConnections')
|
|
||||||
.withIndex('by_user_id_and_inject_database_id', (q) =>
|
|
||||||
q.eq('userId', args.userId).eq('injectDatabaseId', args.injectDatabaseId)
|
|
||||||
)
|
|
||||||
.unique();
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
return existing._id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await ctx.db.insert('injectConnections', {
|
|
||||||
userId: args.userId,
|
|
||||||
injectDatabaseId: args.injectDatabaseId,
|
|
||||||
isGlobal: args.isGlobal ?? true,
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const disconnect = mutation({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
injectDatabaseId: v.id('injectDatabases')
|
|
||||||
},
|
|
||||||
returns: v.boolean(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const existing = await ctx.db
|
|
||||||
.query('injectConnections')
|
|
||||||
.withIndex('by_user_id_and_inject_database_id', (q) =>
|
|
||||||
q.eq('userId', args.userId).eq('injectDatabaseId', args.injectDatabaseId)
|
|
||||||
)
|
|
||||||
.unique();
|
|
||||||
|
|
||||||
if (!existing) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await ctx.db.delete(existing._id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getActiveForUser = query({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.array(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('injectConnections'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
injectDatabaseId: v.id('injectDatabases'),
|
|
||||||
isGlobal: v.boolean(),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db
|
|
||||||
.query('injectConnections')
|
|
||||||
.withIndex('by_user_id', (q) => q.eq('userId', args.userId))
|
|
||||||
.collect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getByInjectDatabaseId = query({
|
|
||||||
args: { injectDatabaseId: v.id('injectDatabases') },
|
|
||||||
returns: v.array(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('injectConnections'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
injectDatabaseId: v.id('injectDatabases'),
|
|
||||||
isGlobal: v.boolean(),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db
|
|
||||||
.query('injectConnections')
|
|
||||||
.withIndex('by_inject_database_id', (q) => q.eq('injectDatabaseId', args.injectDatabaseId))
|
|
||||||
.collect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const deleteConnection = mutation({
|
|
||||||
args: { connectionId: v.id('injectConnections') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.delete(args.connectionId);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { v } from 'convex/values';
|
import { v } from 'convex/values';
|
||||||
import { mutation, query } from './_generated/server';
|
import { mutation, query } from './_generated/server';
|
||||||
import type { Id } from './_generated/dataModel';
|
|
||||||
|
|
||||||
export const listByChat = query({
|
export const listByChat = query({
|
||||||
args: { chatId: v.id('chats') },
|
args: { chatId: v.id('chats') },
|
||||||
@@ -11,6 +10,8 @@ export const listByChat = query({
|
|||||||
chatId: v.id('chats'),
|
chatId: v.id('chats'),
|
||||||
role: v.union(v.literal('user'), v.literal('assistant')),
|
role: v.union(v.literal('user'), v.literal('assistant')),
|
||||||
content: v.string(),
|
content: v.string(),
|
||||||
|
imageBase64: v.optional(v.string()),
|
||||||
|
imageMediaType: v.optional(v.string()),
|
||||||
followUpOptions: v.optional(v.array(v.string())),
|
followUpOptions: v.optional(v.array(v.string())),
|
||||||
source: v.union(v.literal('telegram'), v.literal('web')),
|
source: v.union(v.literal('telegram'), v.literal('web')),
|
||||||
createdAt: v.number(),
|
createdAt: v.number(),
|
||||||
@@ -18,23 +19,11 @@ export const listByChat = query({
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const messages = await ctx.db
|
return await ctx.db
|
||||||
.query('messages')
|
.query('messages')
|
||||||
.withIndex('by_chat_id_and_created_at', (q) => q.eq('chatId', args.chatId))
|
.withIndex('by_chat_id_and_created_at', (q) => q.eq('chatId', args.chatId))
|
||||||
.order('asc')
|
.order('asc')
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
return messages.map((m) => ({
|
|
||||||
_id: m._id,
|
|
||||||
_creationTime: m._creationTime,
|
|
||||||
chatId: m.chatId,
|
|
||||||
role: m.role,
|
|
||||||
content: m.content,
|
|
||||||
followUpOptions: m.followUpOptions,
|
|
||||||
source: m.source,
|
|
||||||
createdAt: m.createdAt,
|
|
||||||
isStreaming: m.isStreaming
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -46,54 +35,11 @@ export const create = mutation({
|
|||||||
source: v.union(v.literal('telegram'), v.literal('web')),
|
source: v.union(v.literal('telegram'), v.literal('web')),
|
||||||
imageBase64: v.optional(v.string()),
|
imageBase64: v.optional(v.string()),
|
||||||
imageMediaType: v.optional(v.string()),
|
imageMediaType: v.optional(v.string()),
|
||||||
imagesBase64: v.optional(v.array(v.string())),
|
|
||||||
imagesMediaTypes: v.optional(v.array(v.string())),
|
|
||||||
photoDraftIds: v.optional(v.array(v.id('photoDrafts'))),
|
|
||||||
followUpOptions: v.optional(v.array(v.string())),
|
followUpOptions: v.optional(v.array(v.string())),
|
||||||
isStreaming: v.optional(v.boolean())
|
isStreaming: v.optional(v.boolean())
|
||||||
},
|
},
|
||||||
returns: v.union(v.id('messages'), v.null()),
|
returns: v.id('messages'),
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const drafts: Array<{ base64: string; mediaType: string; id: Id<'photoDrafts'> }> = [];
|
|
||||||
if (args.photoDraftIds && args.photoDraftIds.length > 0) {
|
|
||||||
for (const draftId of args.photoDraftIds) {
|
|
||||||
const draft = await ctx.db.get(draftId);
|
|
||||||
if (draft) {
|
|
||||||
drafts.push({ base64: draft.base64, mediaType: draft.mediaType, id: draft._id });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.source === 'web' && args.role === 'user') {
|
|
||||||
const chat = await ctx.db.get(args.chatId);
|
|
||||||
if (chat) {
|
|
||||||
const pendingGenId = await ctx.db.insert('pendingGenerations', {
|
|
||||||
userId: chat.userId,
|
|
||||||
chatId: args.chatId,
|
|
||||||
userMessage: args.content,
|
|
||||||
imagesBase64: drafts.length > 0 ? drafts.map((d) => d.base64) : args.imagesBase64,
|
|
||||||
imagesMediaTypes:
|
|
||||||
drafts.length > 0 ? drafts.map((d) => d.mediaType) : args.imagesMediaTypes,
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
|
|
||||||
for (let i = 0; i < drafts.length; i++) {
|
|
||||||
await ctx.db.insert('pendingGenerationImages', {
|
|
||||||
pendingGenerationId: pendingGenId,
|
|
||||||
base64: drafts[i].base64,
|
|
||||||
mediaType: drafts[i].mediaType,
|
|
||||||
order: i
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const draft of drafts) {
|
|
||||||
await ctx.db.delete(draft.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const messageId = await ctx.db.insert('messages', {
|
const messageId = await ctx.db.insert('messages', {
|
||||||
chatId: args.chatId,
|
chatId: args.chatId,
|
||||||
role: args.role,
|
role: args.role,
|
||||||
@@ -101,55 +47,27 @@ export const create = mutation({
|
|||||||
source: args.source,
|
source: args.source,
|
||||||
imageBase64: args.imageBase64,
|
imageBase64: args.imageBase64,
|
||||||
imageMediaType: args.imageMediaType,
|
imageMediaType: args.imageMediaType,
|
||||||
imagesBase64: args.imagesBase64,
|
|
||||||
imagesMediaTypes: args.imagesMediaTypes,
|
|
||||||
followUpOptions: args.followUpOptions,
|
followUpOptions: args.followUpOptions,
|
||||||
createdAt: Date.now(),
|
createdAt: Date.now(),
|
||||||
isStreaming: args.isStreaming
|
isStreaming: args.isStreaming
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let i = 0; i < drafts.length; i++) {
|
if (args.source === 'web' && args.role === 'user') {
|
||||||
await ctx.db.insert('messageImages', {
|
const chat = await ctx.db.get(args.chatId);
|
||||||
messageId,
|
if (chat) {
|
||||||
base64: drafts[i].base64,
|
await ctx.db.insert('pendingGenerations', {
|
||||||
mediaType: drafts[i].mediaType,
|
userId: chat.userId,
|
||||||
order: i
|
chatId: args.chatId,
|
||||||
});
|
userMessage: args.content,
|
||||||
}
|
createdAt: Date.now()
|
||||||
|
});
|
||||||
for (const draft of drafts) {
|
}
|
||||||
await ctx.db.delete(draft.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return messageId;
|
return messageId;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const createFromBackend = mutation({
|
|
||||||
args: {
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
role: v.union(v.literal('user'), v.literal('assistant')),
|
|
||||||
content: v.string(),
|
|
||||||
source: v.union(v.literal('telegram'), v.literal('web')),
|
|
||||||
imagesBase64: v.optional(v.array(v.string())),
|
|
||||||
imagesMediaTypes: v.optional(v.array(v.string())),
|
|
||||||
isStreaming: v.optional(v.boolean())
|
|
||||||
},
|
|
||||||
returns: v.id('messages'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db.insert('messages', {
|
|
||||||
chatId: args.chatId,
|
|
||||||
role: args.role,
|
|
||||||
content: args.content,
|
|
||||||
source: args.source,
|
|
||||||
imagesBase64: args.imagesBase64,
|
|
||||||
imagesMediaTypes: args.imagesMediaTypes,
|
|
||||||
createdAt: Date.now(),
|
|
||||||
isStreaming: args.isStreaming
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const update = mutation({
|
export const update = mutation({
|
||||||
args: {
|
args: {
|
||||||
messageId: v.id('messages'),
|
messageId: v.id('messages'),
|
||||||
@@ -180,24 +98,6 @@ export const update = mutation({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setTelegramMessageId = mutation({
|
|
||||||
args: { messageId: v.id('messages'), telegramMessageId: v.number() },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.messageId, { telegramMessageId: args.telegramMessageId });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getTelegramMessageId = query({
|
|
||||||
args: { messageId: v.id('messages') },
|
|
||||||
returns: v.union(v.number(), v.null()),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const msg = await ctx.db.get(args.messageId);
|
|
||||||
return msg?.telegramMessageId ?? null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getHistoryForAI = query({
|
export const getHistoryForAI = query({
|
||||||
args: { chatId: v.id('chats'), limit: v.optional(v.number()) },
|
args: { chatId: v.id('chats'), limit: v.optional(v.number()) },
|
||||||
returns: v.array(
|
returns: v.array(
|
||||||
@@ -234,8 +134,6 @@ export const getLastAssistantMessage = query({
|
|||||||
content: v.string(),
|
content: v.string(),
|
||||||
imageBase64: v.optional(v.string()),
|
imageBase64: v.optional(v.string()),
|
||||||
imageMediaType: v.optional(v.string()),
|
imageMediaType: v.optional(v.string()),
|
||||||
imagesBase64: v.optional(v.array(v.string())),
|
|
||||||
imagesMediaTypes: v.optional(v.array(v.string())),
|
|
||||||
followUpOptions: v.optional(v.array(v.string())),
|
followUpOptions: v.optional(v.array(v.string())),
|
||||||
source: v.union(v.literal('telegram'), v.literal('web')),
|
source: v.union(v.literal('telegram'), v.literal('web')),
|
||||||
createdAt: v.number(),
|
createdAt: v.number(),
|
||||||
@@ -268,33 +166,11 @@ export const getChatImages = query({
|
|||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
const images: Array<{ base64: string; mediaType: string }> = [];
|
return messages
|
||||||
|
.filter((m) => m.imageBase64 && m.imageMediaType)
|
||||||
for (const m of messages) {
|
.map((m) => ({
|
||||||
const msgImages = await ctx.db
|
base64: m.imageBase64!,
|
||||||
.query('messageImages')
|
mediaType: m.imageMediaType!
|
||||||
.withIndex('by_message_id', (q) => q.eq('messageId', m._id))
|
}));
|
||||||
.collect();
|
|
||||||
|
|
||||||
for (const img of msgImages.sort((a, b) => a.order - b.order)) {
|
|
||||||
images.push({ base64: img.base64, mediaType: img.mediaType });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m.imagesBase64 && m.imagesMediaTypes) {
|
|
||||||
for (let i = 0; i < m.imagesBase64.length; i++) {
|
|
||||||
images.push({
|
|
||||||
base64: m.imagesBase64[i],
|
|
||||||
mediaType: m.imagesMediaTypes[i]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (m.imageBase64 && m.imageMediaType) {
|
|
||||||
images.push({
|
|
||||||
base64: m.imageBase64,
|
|
||||||
mediaType: m.imageMediaType
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return images;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
import { v } from 'convex/values';
|
|
||||||
import { mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
export const create = mutation({
|
|
||||||
args: {
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
fromDeviceId: v.string()
|
|
||||||
},
|
|
||||||
returns: v.id('pairingRequests'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const existing = await ctx.db
|
|
||||||
.query('pairingRequests')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
const pending = existing.find(
|
|
||||||
(r) => r.fromDeviceId === args.fromDeviceId && r.status === 'pending'
|
|
||||||
);
|
|
||||||
if (pending) return pending._id;
|
|
||||||
|
|
||||||
return await ctx.db.insert('pairingRequests', {
|
|
||||||
chatId: args.chatId,
|
|
||||||
fromDeviceId: args.fromDeviceId,
|
|
||||||
status: 'pending',
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const accept = mutation({
|
|
||||||
args: {
|
|
||||||
requestId: v.id('pairingRequests'),
|
|
||||||
acceptingDeviceId: v.string()
|
|
||||||
},
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const request = await ctx.db.get(args.requestId);
|
|
||||||
if (!request || request.status !== 'pending') return null;
|
|
||||||
|
|
||||||
await ctx.db.patch(args.requestId, { status: 'accepted' });
|
|
||||||
|
|
||||||
const devices = await ctx.db
|
|
||||||
.query('devicePairings')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', request.chatId))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
const fromDevice = devices.find((d) => d.deviceId === request.fromDeviceId);
|
|
||||||
const acceptingDevice = devices.find((d) => d.deviceId === args.acceptingDeviceId);
|
|
||||||
|
|
||||||
if (fromDevice) {
|
|
||||||
await ctx.db.patch(fromDevice._id, { pairedWithDeviceId: args.acceptingDeviceId });
|
|
||||||
}
|
|
||||||
if (acceptingDevice) {
|
|
||||||
await ctx.db.patch(acceptingDevice._id, { pairedWithDeviceId: request.fromDeviceId });
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const reject = mutation({
|
|
||||||
args: { requestId: v.id('pairingRequests') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const request = await ctx.db.get(args.requestId);
|
|
||||||
if (!request || request.status !== 'pending') return null;
|
|
||||||
await ctx.db.patch(args.requestId, { status: 'rejected' });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getPending = query({
|
|
||||||
args: { chatId: v.id('chats'), excludeDeviceId: v.string() },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('pairingRequests'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
fromDeviceId: v.string(),
|
|
||||||
status: v.union(v.literal('pending'), v.literal('accepted'), v.literal('rejected')),
|
|
||||||
createdAt: v.number()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const requests = await ctx.db
|
|
||||||
.query('pairingRequests')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
return (
|
|
||||||
requests.find((r) => r.status === 'pending' && r.fromDeviceId !== args.excludeDeviceId) ??
|
|
||||||
null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const unpair = mutation({
|
|
||||||
args: {
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string()
|
|
||||||
},
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const devices = await ctx.db
|
|
||||||
.query('devicePairings')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
const myDevice = devices.find((d) => d.deviceId === args.deviceId);
|
|
||||||
if (!myDevice?.pairedWithDeviceId) return null;
|
|
||||||
|
|
||||||
const pairedDevice = devices.find((d) => d.deviceId === myDevice.pairedWithDeviceId);
|
|
||||||
|
|
||||||
await ctx.db.patch(myDevice._id, { pairedWithDeviceId: undefined });
|
|
||||||
if (pairedDevice) {
|
|
||||||
await ctx.db.patch(pairedDevice._id, { pairedWithDeviceId: undefined });
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -10,77 +10,11 @@ export const list = query({
|
|||||||
userId: v.id('users'),
|
userId: v.id('users'),
|
||||||
chatId: v.id('chats'),
|
chatId: v.id('chats'),
|
||||||
userMessage: v.string(),
|
userMessage: v.string(),
|
||||||
imagesBase64: v.optional(v.array(v.string())),
|
|
||||||
imagesMediaTypes: v.optional(v.array(v.string())),
|
|
||||||
createdAt: v.number()
|
createdAt: v.number()
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
handler: async (ctx) => {
|
handler: async (ctx) => {
|
||||||
const pending = await ctx.db.query('pendingGenerations').collect();
|
return await ctx.db.query('pendingGenerations').collect();
|
||||||
|
|
||||||
const result = [];
|
|
||||||
for (const p of pending) {
|
|
||||||
const images = await ctx.db
|
|
||||||
.query('pendingGenerationImages')
|
|
||||||
.withIndex('by_pending_generation_id', (q) => q.eq('pendingGenerationId', p._id))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
const sortedImages = images.sort((a, b) => a.order - b.order);
|
|
||||||
|
|
||||||
result.push({
|
|
||||||
...p,
|
|
||||||
imagesBase64:
|
|
||||||
sortedImages.length > 0 ? sortedImages.map((img) => img.base64) : p.imagesBase64,
|
|
||||||
imagesMediaTypes:
|
|
||||||
sortedImages.length > 0 ? sortedImages.map((img) => img.mediaType) : p.imagesMediaTypes
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const listByChat = query({
|
|
||||||
args: { chatId: v.id('chats') },
|
|
||||||
returns: v.array(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('pendingGenerations'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userMessage: v.string(),
|
|
||||||
imagesBase64: v.optional(v.array(v.string())),
|
|
||||||
imagesMediaTypes: v.optional(v.array(v.string())),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const pending = await ctx.db
|
|
||||||
.query('pendingGenerations')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.order('asc')
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
const result = [];
|
|
||||||
for (const p of pending) {
|
|
||||||
const images = await ctx.db
|
|
||||||
.query('pendingGenerationImages')
|
|
||||||
.withIndex('by_pending_generation_id', (q) => q.eq('pendingGenerationId', p._id))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
const sortedImages = images.sort((a, b) => a.order - b.order);
|
|
||||||
|
|
||||||
result.push({
|
|
||||||
_id: p._id,
|
|
||||||
_creationTime: p._creationTime,
|
|
||||||
userMessage: p.userMessage,
|
|
||||||
imagesBase64:
|
|
||||||
sortedImages.length > 0 ? sortedImages.map((img) => img.base64) : p.imagesBase64,
|
|
||||||
imagesMediaTypes:
|
|
||||||
sortedImages.length > 0 ? sortedImages.map((img) => img.mediaType) : p.imagesMediaTypes,
|
|
||||||
createdAt: p.createdAt
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -105,39 +39,7 @@ export const remove = mutation({
|
|||||||
args: { id: v.id('pendingGenerations') },
|
args: { id: v.id('pendingGenerations') },
|
||||||
returns: v.null(),
|
returns: v.null(),
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const existing = await ctx.db.get(args.id);
|
|
||||||
if (!existing) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const images = await ctx.db
|
|
||||||
.query('pendingGenerationImages')
|
|
||||||
.withIndex('by_pending_generation_id', (q) => q.eq('pendingGenerationId', args.id))
|
|
||||||
.collect();
|
|
||||||
for (const img of images) {
|
|
||||||
await ctx.db.delete(img._id);
|
|
||||||
}
|
|
||||||
await ctx.db.delete(args.id);
|
await ctx.db.delete(args.id);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getImages = query({
|
|
||||||
args: { pendingGenerationId: v.id('pendingGenerations') },
|
|
||||||
returns: v.array(
|
|
||||||
v.object({
|
|
||||||
base64: v.string(),
|
|
||||||
mediaType: v.string()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const images = await ctx.db
|
|
||||||
.query('pendingGenerationImages')
|
|
||||||
.withIndex('by_pending_generation_id', (q) =>
|
|
||||||
q.eq('pendingGenerationId', args.pendingGenerationId)
|
|
||||||
)
|
|
||||||
.collect();
|
|
||||||
return images
|
|
||||||
.sort((a, b) => a.order - b.order)
|
|
||||||
.map((img) => ({ base64: img.base64, mediaType: img.mediaType }));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
import { v } from 'convex/values';
|
|
||||||
import { mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
const photoValidator = v.object({
|
|
||||||
base64: v.string(),
|
|
||||||
mediaType: v.string()
|
|
||||||
});
|
|
||||||
|
|
||||||
export const get = query({
|
|
||||||
args: { chatId: v.id('chats'), deviceId: v.string() },
|
|
||||||
returns: v.object({
|
|
||||||
photos: v.array(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('photoDrafts'),
|
|
||||||
mediaType: v.string()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const drafts = await ctx.db
|
|
||||||
.query('photoDrafts')
|
|
||||||
.withIndex('by_chat_id_and_device_id', (q) =>
|
|
||||||
q.eq('chatId', args.chatId).eq('deviceId', args.deviceId)
|
|
||||||
)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
return {
|
|
||||||
photos: drafts.map((d) => ({
|
|
||||||
_id: d._id,
|
|
||||||
mediaType: d.mediaType
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const addPhoto = mutation({
|
|
||||||
args: {
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string(),
|
|
||||||
photo: photoValidator
|
|
||||||
},
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.insert('photoDrafts', {
|
|
||||||
chatId: args.chatId,
|
|
||||||
deviceId: args.deviceId,
|
|
||||||
base64: args.photo.base64,
|
|
||||||
mediaType: args.photo.mediaType,
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const removePhoto = mutation({
|
|
||||||
args: {
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string(),
|
|
||||||
index: v.number()
|
|
||||||
},
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const drafts = await ctx.db
|
|
||||||
.query('photoDrafts')
|
|
||||||
.withIndex('by_chat_id_and_device_id', (q) =>
|
|
||||||
q.eq('chatId', args.chatId).eq('deviceId', args.deviceId)
|
|
||||||
)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if (drafts[args.index]) {
|
|
||||||
await ctx.db.delete(drafts[args.index]._id);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const clear = mutation({
|
|
||||||
args: { chatId: v.id('chats'), deviceId: v.string() },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const drafts = await ctx.db
|
|
||||||
.query('photoDrafts')
|
|
||||||
.withIndex('by_chat_id_and_device_id', (q) =>
|
|
||||||
q.eq('chatId', args.chatId).eq('deviceId', args.deviceId)
|
|
||||||
)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
for (const draft of drafts) {
|
|
||||||
await ctx.db.delete(draft._id);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,293 +0,0 @@
|
|||||||
import { v } from 'convex/values';
|
|
||||||
import { mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
const photoRequestValidator = v.object({
|
|
||||||
_id: v.id('photoRequests'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
requesterId: v.string(),
|
|
||||||
captureDeviceId: v.optional(v.string()),
|
|
||||||
status: v.union(
|
|
||||||
v.literal('pending'),
|
|
||||||
v.literal('countdown'),
|
|
||||||
v.literal('capture_now'),
|
|
||||||
v.literal('captured'),
|
|
||||||
v.literal('accepted'),
|
|
||||||
v.literal('rejected')
|
|
||||||
),
|
|
||||||
photoBase64: v.optional(v.string()),
|
|
||||||
photoMediaType: v.optional(v.string()),
|
|
||||||
thumbnailBase64: v.optional(v.string()),
|
|
||||||
createdAt: v.number()
|
|
||||||
});
|
|
||||||
|
|
||||||
const photoRequestLightValidator = v.object({
|
|
||||||
_id: v.id('photoRequests'),
|
|
||||||
status: v.union(
|
|
||||||
v.literal('pending'),
|
|
||||||
v.literal('countdown'),
|
|
||||||
v.literal('capture_now'),
|
|
||||||
v.literal('captured'),
|
|
||||||
v.literal('accepted'),
|
|
||||||
v.literal('rejected')
|
|
||||||
),
|
|
||||||
photoMediaType: v.optional(v.string()),
|
|
||||||
thumbnailBase64: v.optional(v.string())
|
|
||||||
});
|
|
||||||
|
|
||||||
export const create = mutation({
|
|
||||||
args: {
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
requesterId: v.string(),
|
|
||||||
captureDeviceId: v.string()
|
|
||||||
},
|
|
||||||
returns: v.id('photoRequests'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const oldRequests = await ctx.db
|
|
||||||
.query('photoRequests')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.take(20);
|
|
||||||
|
|
||||||
for (const req of oldRequests) {
|
|
||||||
if (req.status === 'pending' || req.status === 'countdown' || req.status === 'capture_now') {
|
|
||||||
await ctx.db.patch(req._id, { status: 'rejected' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return await ctx.db.insert('photoRequests', {
|
|
||||||
chatId: args.chatId,
|
|
||||||
requesterId: args.requesterId,
|
|
||||||
captureDeviceId: args.captureDeviceId,
|
|
||||||
status: 'countdown',
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const markCaptureNow = mutation({
|
|
||||||
args: { requestId: v.id('photoRequests') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.requestId, { status: 'capture_now' });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const submitPhoto = mutation({
|
|
||||||
args: {
|
|
||||||
requestId: v.id('photoRequests'),
|
|
||||||
photoBase64: v.string(),
|
|
||||||
photoMediaType: v.string(),
|
|
||||||
thumbnailBase64: v.optional(v.string())
|
|
||||||
},
|
|
||||||
returns: v.boolean(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const req = await ctx.db.get(args.requestId);
|
|
||||||
if (!req || req.status !== 'capture_now') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await ctx.db.patch(args.requestId, {
|
|
||||||
status: 'captured',
|
|
||||||
photoBase64: args.photoBase64,
|
|
||||||
photoMediaType: args.photoMediaType,
|
|
||||||
thumbnailBase64: args.thumbnailBase64
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const markAccepted = mutation({
|
|
||||||
args: { requestId: v.id('photoRequests') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.requestId, { status: 'accepted' });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const markRejected = mutation({
|
|
||||||
args: { requestId: v.id('photoRequests') },
|
|
||||||
returns: v.boolean(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const req = await ctx.db.get(args.requestId);
|
|
||||||
if (!req || req.status === 'accepted' || req.status === 'rejected') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
await ctx.db.patch(req._id, { status: 'rejected' });
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const captureNowLightValidator = v.object({
|
|
||||||
_id: v.id('photoRequests'),
|
|
||||||
status: v.literal('capture_now')
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getCaptureNowRequest = query({
|
|
||||||
args: { chatId: v.id('chats'), deviceId: v.optional(v.string()) },
|
|
||||||
returns: v.union(captureNowLightValidator, v.null()),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const now = Date.now();
|
|
||||||
const maxAge = 60 * 1000;
|
|
||||||
|
|
||||||
const requests = await ctx.db
|
|
||||||
.query('photoRequests')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.order('desc')
|
|
||||||
.take(50);
|
|
||||||
|
|
||||||
const found = requests.find((r) => r.status === 'capture_now' && now - r.createdAt < maxAge);
|
|
||||||
if (!found) return null;
|
|
||||||
|
|
||||||
return { _id: found._id, status: 'capture_now' as const };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getActiveForCapture = query({
|
|
||||||
args: { chatId: v.id('chats'), deviceId: v.optional(v.string()) },
|
|
||||||
returns: v.union(photoRequestValidator, v.null()),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const requests = await ctx.db
|
|
||||||
.query('photoRequests')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.order('desc')
|
|
||||||
.take(50);
|
|
||||||
|
|
||||||
return requests.find((r) => r.status === 'countdown' || r.status === 'capture_now') ?? null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getMyActiveRequest = query({
|
|
||||||
args: { chatId: v.id('chats'), deviceId: v.optional(v.string()) },
|
|
||||||
returns: v.union(photoRequestLightValidator, v.null()),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const requests = await ctx.db
|
|
||||||
.query('photoRequests')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.order('desc')
|
|
||||||
.take(100);
|
|
||||||
|
|
||||||
if (!args.deviceId) return null;
|
|
||||||
|
|
||||||
const found = requests.find(
|
|
||||||
(r) =>
|
|
||||||
r.requesterId === args.deviceId &&
|
|
||||||
(r.status === 'countdown' || r.status === 'capture_now' || r.status === 'captured')
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!found) return null;
|
|
||||||
|
|
||||||
return {
|
|
||||||
_id: found._id,
|
|
||||||
status: found.status,
|
|
||||||
photoMediaType: found.photoMediaType,
|
|
||||||
thumbnailBase64: found.thumbnailBase64
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getPhotoData = query({
|
|
||||||
args: { requestId: v.id('photoRequests') },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
photoBase64: v.string(),
|
|
||||||
photoMediaType: v.string(),
|
|
||||||
thumbnailBase64: v.optional(v.string())
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const req = await ctx.db.get(args.requestId);
|
|
||||||
if (!req || !req.photoBase64 || !req.photoMediaType) return null;
|
|
||||||
|
|
||||||
return {
|
|
||||||
photoBase64: req.photoBase64,
|
|
||||||
photoMediaType: req.photoMediaType,
|
|
||||||
thumbnailBase64: req.thumbnailBase64
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getPhotoPreview = query({
|
|
||||||
args: { requestId: v.id('photoRequests') },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
thumbnailBase64: v.string(),
|
|
||||||
photoMediaType: v.string()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const req = await ctx.db.get(args.requestId);
|
|
||||||
if (!req || !req.photoMediaType) return null;
|
|
||||||
|
|
||||||
return {
|
|
||||||
thumbnailBase64: req.thumbnailBase64 || req.photoBase64 || '',
|
|
||||||
photoMediaType: req.photoMediaType
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const acceptPhotoToDraft = mutation({
|
|
||||||
args: {
|
|
||||||
requestId: v.id('photoRequests'),
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string()
|
|
||||||
},
|
|
||||||
returns: v.id('photoDrafts'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const req = await ctx.db.get(args.requestId);
|
|
||||||
if (!req || !req.photoBase64 || !req.photoMediaType) {
|
|
||||||
throw new Error('Photo request not found or has no photo');
|
|
||||||
}
|
|
||||||
|
|
||||||
const draftId = await ctx.db.insert('photoDrafts', {
|
|
||||||
chatId: args.chatId,
|
|
||||||
deviceId: args.deviceId,
|
|
||||||
base64: req.photoBase64,
|
|
||||||
mediaType: req.photoMediaType,
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
|
|
||||||
await ctx.db.patch(args.requestId, { status: 'accepted' });
|
|
||||||
|
|
||||||
return draftId;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const cleanup = mutation({
|
|
||||||
args: { chatId: v.id('chats') },
|
|
||||||
returns: v.number(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const requests = await ctx.db
|
|
||||||
.query('photoRequests')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.take(20);
|
|
||||||
|
|
||||||
let deleted = 0;
|
|
||||||
for (const req of requests) {
|
|
||||||
await ctx.db.delete(req._id);
|
|
||||||
deleted++;
|
|
||||||
}
|
|
||||||
return deleted;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getCapturedForPhone = query({
|
|
||||||
args: { chatId: v.id('chats'), deviceId: v.optional(v.string()) },
|
|
||||||
returns: v.union(photoRequestValidator, v.null()),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const requests = await ctx.db
|
|
||||||
.query('photoRequests')
|
|
||||||
.withIndex('by_chat_id', (q) => q.eq('chatId', args.chatId))
|
|
||||||
.order('desc')
|
|
||||||
.take(50);
|
|
||||||
|
|
||||||
if (!args.deviceId) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
requests.find((r) => r.captureDeviceId === args.deviceId && r.status === 'captured') ?? null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,252 +0,0 @@
|
|||||||
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
||||||
import { RAG } from '@convex-dev/rag';
|
|
||||||
import { v } from 'convex/values';
|
|
||||||
import { api, components } from './_generated/api';
|
|
||||||
import { action, mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
function createRagInstance(apiKey: string) {
|
|
||||||
const google = createGoogleGenerativeAI({ apiKey });
|
|
||||||
return new RAG(components.rag, {
|
|
||||||
textEmbeddingModel: google.embedding('gemini-embedding-001'),
|
|
||||||
embeddingDimension: 768
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildNamespace(userId: string, dbName: string): string {
|
|
||||||
return `user_${userId}/${dbName}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const createDatabase = mutation({
|
|
||||||
args: { userId: v.id('users'), name: v.string() },
|
|
||||||
returns: v.id('ragDatabases'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const existing = await ctx.db
|
|
||||||
.query('ragDatabases')
|
|
||||||
.withIndex('by_user_id_and_name', (q) => q.eq('userId', args.userId).eq('name', args.name))
|
|
||||||
.unique();
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
return existing._id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await ctx.db.insert('ragDatabases', {
|
|
||||||
userId: args.userId,
|
|
||||||
name: args.name,
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getDatabase = query({
|
|
||||||
args: { userId: v.id('users'), name: v.string() },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('ragDatabases'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
name: v.string(),
|
|
||||||
createdAt: v.number()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db
|
|
||||||
.query('ragDatabases')
|
|
||||||
.withIndex('by_user_id_and_name', (q) => q.eq('userId', args.userId).eq('name', args.name))
|
|
||||||
.unique();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getDatabaseById = query({
|
|
||||||
args: { ragDatabaseId: v.id('ragDatabases') },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('ragDatabases'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
name: v.string(),
|
|
||||||
createdAt: v.number()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db.get(args.ragDatabaseId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const listDatabases = query({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.array(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('ragDatabases'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
name: v.string(),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db
|
|
||||||
.query('ragDatabases')
|
|
||||||
.withIndex('by_user_id', (q) => q.eq('userId', args.userId))
|
|
||||||
.collect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const deleteDatabase = action({
|
|
||||||
args: { userId: v.id('users'), name: v.string(), apiKey: v.string() },
|
|
||||||
returns: v.boolean(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const db = await ctx.runQuery(api.rag.getDatabase, {
|
|
||||||
userId: args.userId,
|
|
||||||
name: args.name
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!db) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const connections = await ctx.runQuery(api.ragConnections.getByRagDatabaseId, {
|
|
||||||
ragDatabaseId: db._id
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const conn of connections) {
|
|
||||||
await ctx.runMutation(api.ragConnections.deleteConnection, {
|
|
||||||
connectionId: conn._id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await ctx.runMutation(api.rag.deleteDatabaseRecord, {
|
|
||||||
ragDatabaseId: db._id
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const deleteDatabaseRecord = mutation({
|
|
||||||
args: { ragDatabaseId: v.id('ragDatabases') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.delete(args.ragDatabaseId);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const addContent = action({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
apiKey: v.string(),
|
|
||||||
text: v.string(),
|
|
||||||
key: v.optional(v.string())
|
|
||||||
},
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const db = await ctx.runQuery(api.rag.getDatabaseById, {
|
|
||||||
ragDatabaseId: args.ragDatabaseId
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!db) {
|
|
||||||
throw new Error('RAG database not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
const rag = createRagInstance(args.apiKey);
|
|
||||||
const namespace = buildNamespace(args.userId, db.name);
|
|
||||||
|
|
||||||
await rag.add(ctx, {
|
|
||||||
namespace,
|
|
||||||
text: args.text,
|
|
||||||
key: args.key
|
|
||||||
});
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const search = action({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
dbName: v.string(),
|
|
||||||
apiKey: v.string(),
|
|
||||||
query: v.string(),
|
|
||||||
limit: v.optional(v.number())
|
|
||||||
},
|
|
||||||
returns: v.object({
|
|
||||||
text: v.string(),
|
|
||||||
results: v.array(
|
|
||||||
v.object({
|
|
||||||
text: v.string(),
|
|
||||||
score: v.number()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const rag = createRagInstance(args.apiKey);
|
|
||||||
const namespace = buildNamespace(args.userId, args.dbName);
|
|
||||||
|
|
||||||
const { results, text } = await rag.search(ctx, {
|
|
||||||
namespace,
|
|
||||||
query: args.query,
|
|
||||||
limit: args.limit ?? 5
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
text: text ?? '',
|
|
||||||
results: results.map((r) => ({
|
|
||||||
text: r.content.map((c) => c.text).join('\n'),
|
|
||||||
score: r.score
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const searchMultiple = action({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
dbNames: v.array(v.string()),
|
|
||||||
apiKey: v.string(),
|
|
||||||
query: v.string(),
|
|
||||||
limit: v.optional(v.number())
|
|
||||||
},
|
|
||||||
returns: v.object({
|
|
||||||
text: v.string(),
|
|
||||||
results: v.array(
|
|
||||||
v.object({
|
|
||||||
text: v.string(),
|
|
||||||
score: v.number(),
|
|
||||||
dbName: v.string()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const rag = createRagInstance(args.apiKey);
|
|
||||||
const allResults: Array<{ text: string; score: number; dbName: string }> = [];
|
|
||||||
|
|
||||||
for (const dbName of args.dbNames) {
|
|
||||||
const namespace = buildNamespace(args.userId, dbName);
|
|
||||||
const { results } = await rag.search(ctx, {
|
|
||||||
namespace,
|
|
||||||
query: args.query,
|
|
||||||
limit: args.limit ?? 5
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const r of results) {
|
|
||||||
allResults.push({
|
|
||||||
text: r.content.map((c) => c.text).join('\n'),
|
|
||||||
score: r.score,
|
|
||||||
dbName
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
allResults.sort((a, b) => b.score - a.score);
|
|
||||||
const topResults = allResults.slice(0, args.limit ?? 5);
|
|
||||||
const combinedText = topResults.map((r) => r.text).join('\n\n---\n\n');
|
|
||||||
|
|
||||||
return {
|
|
||||||
text: combinedText,
|
|
||||||
results: topResults
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
import { v } from 'convex/values';
|
|
||||||
import { mutation, query } from './_generated/server';
|
|
||||||
|
|
||||||
export const connect = mutation({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
isGlobal: v.optional(v.boolean())
|
|
||||||
},
|
|
||||||
returns: v.id('ragConnections'),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const existing = await ctx.db
|
|
||||||
.query('ragConnections')
|
|
||||||
.withIndex('by_user_id_and_rag_database_id', (q) =>
|
|
||||||
q.eq('userId', args.userId).eq('ragDatabaseId', args.ragDatabaseId)
|
|
||||||
)
|
|
||||||
.unique();
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
return existing._id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await ctx.db.insert('ragConnections', {
|
|
||||||
userId: args.userId,
|
|
||||||
ragDatabaseId: args.ragDatabaseId,
|
|
||||||
isGlobal: args.isGlobal ?? true,
|
|
||||||
createdAt: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const disconnect = mutation({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
ragDatabaseId: v.id('ragDatabases')
|
|
||||||
},
|
|
||||||
returns: v.boolean(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const existing = await ctx.db
|
|
||||||
.query('ragConnections')
|
|
||||||
.withIndex('by_user_id_and_rag_database_id', (q) =>
|
|
||||||
q.eq('userId', args.userId).eq('ragDatabaseId', args.ragDatabaseId)
|
|
||||||
)
|
|
||||||
.unique();
|
|
||||||
|
|
||||||
if (!existing) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await ctx.db.delete(existing._id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getActiveForUser = query({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.array(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('ragConnections'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
isGlobal: v.boolean(),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db
|
|
||||||
.query('ragConnections')
|
|
||||||
.withIndex('by_user_id', (q) => q.eq('userId', args.userId))
|
|
||||||
.collect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getByRagDatabaseId = query({
|
|
||||||
args: { ragDatabaseId: v.id('ragDatabases') },
|
|
||||||
returns: v.array(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('ragConnections'),
|
|
||||||
_creationTime: v.number(),
|
|
||||||
userId: v.id('users'),
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
isGlobal: v.boolean(),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
return await ctx.db
|
|
||||||
.query('ragConnections')
|
|
||||||
.withIndex('by_rag_database_id', (q) => q.eq('ragDatabaseId', args.ragDatabaseId))
|
|
||||||
.collect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const deleteConnection = mutation({
|
|
||||||
args: { connectionId: v.id('ragConnections') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.delete(args.connectionId);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -10,28 +10,7 @@ export default defineSchema({
|
|||||||
followUpPrompt: v.optional(v.string()),
|
followUpPrompt: v.optional(v.string()),
|
||||||
model: v.string(),
|
model: v.string(),
|
||||||
followUpModel: v.optional(v.string()),
|
followUpModel: v.optional(v.string()),
|
||||||
activeChatId: v.optional(v.id('chats')),
|
activeChatId: v.optional(v.id('chats'))
|
||||||
ragCollectionMode: v.optional(
|
|
||||||
v.object({
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
injectCollectionMode: v.optional(
|
|
||||||
v.object({
|
|
||||||
injectDatabaseId: v.id('injectDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
collaborativeRoom: v.optional(
|
|
||||||
v.object({
|
|
||||||
pin: v.string(),
|
|
||||||
creatorToken: v.optional(v.string()),
|
|
||||||
joinedAt: v.number(),
|
|
||||||
lastSeenHistoryCount: v.optional(v.number()),
|
|
||||||
lastSeenSheetId: v.optional(v.number())
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}).index('by_telegram_id', ['telegramId']),
|
}).index('by_telegram_id', ['telegramId']),
|
||||||
|
|
||||||
chats: defineTable({
|
chats: defineTable({
|
||||||
@@ -47,13 +26,10 @@ export default defineSchema({
|
|||||||
imageBase64: v.optional(v.string()),
|
imageBase64: v.optional(v.string()),
|
||||||
imageMediaType: v.optional(v.string()),
|
imageMediaType: v.optional(v.string()),
|
||||||
imageStorageId: v.optional(v.id('_storage')),
|
imageStorageId: v.optional(v.id('_storage')),
|
||||||
imagesBase64: v.optional(v.array(v.string())),
|
|
||||||
imagesMediaTypes: v.optional(v.array(v.string())),
|
|
||||||
followUpOptions: v.optional(v.array(v.string())),
|
followUpOptions: v.optional(v.array(v.string())),
|
||||||
source: v.union(v.literal('telegram'), v.literal('web')),
|
source: v.union(v.literal('telegram'), v.literal('web')),
|
||||||
createdAt: v.number(),
|
createdAt: v.number(),
|
||||||
isStreaming: v.optional(v.boolean()),
|
isStreaming: v.optional(v.boolean())
|
||||||
telegramMessageId: v.optional(v.number())
|
|
||||||
})
|
})
|
||||||
.index('by_chat_id', ['chatId'])
|
.index('by_chat_id', ['chatId'])
|
||||||
.index('by_chat_id_and_created_at', ['chatId', 'createdAt']),
|
.index('by_chat_id_and_created_at', ['chatId', 'createdAt']),
|
||||||
@@ -62,153 +38,6 @@ export default defineSchema({
|
|||||||
userId: v.id('users'),
|
userId: v.id('users'),
|
||||||
chatId: v.id('chats'),
|
chatId: v.id('chats'),
|
||||||
userMessage: v.string(),
|
userMessage: v.string(),
|
||||||
imagesBase64: v.optional(v.array(v.string())),
|
|
||||||
imagesMediaTypes: v.optional(v.array(v.string())),
|
|
||||||
createdAt: v.number()
|
|
||||||
}).index('by_chat_id', ['chatId']),
|
|
||||||
|
|
||||||
pendingGenerationImages: defineTable({
|
|
||||||
pendingGenerationId: v.id('pendingGenerations'),
|
|
||||||
base64: v.string(),
|
|
||||||
mediaType: v.string(),
|
|
||||||
order: v.number()
|
|
||||||
}).index('by_pending_generation_id', ['pendingGenerationId']),
|
|
||||||
|
|
||||||
messageImages: defineTable({
|
|
||||||
messageId: v.id('messages'),
|
|
||||||
base64: v.string(),
|
|
||||||
mediaType: v.string(),
|
|
||||||
order: v.number()
|
|
||||||
}).index('by_message_id', ['messageId']),
|
|
||||||
|
|
||||||
devicePairings: defineTable({
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string(),
|
|
||||||
hasCamera: v.boolean(),
|
|
||||||
pairedWithDeviceId: v.optional(v.string()),
|
|
||||||
lastSeen: v.number()
|
|
||||||
}).index('by_chat_id', ['chatId']),
|
|
||||||
|
|
||||||
pairingRequests: defineTable({
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
fromDeviceId: v.string(),
|
|
||||||
status: v.union(v.literal('pending'), v.literal('accepted'), v.literal('rejected')),
|
|
||||||
createdAt: v.number()
|
|
||||||
}).index('by_chat_id', ['chatId']),
|
|
||||||
|
|
||||||
photoRequests: defineTable({
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
requesterId: v.string(),
|
|
||||||
captureDeviceId: v.optional(v.string()),
|
|
||||||
status: v.union(
|
|
||||||
v.literal('pending'),
|
|
||||||
v.literal('countdown'),
|
|
||||||
v.literal('capture_now'),
|
|
||||||
v.literal('captured'),
|
|
||||||
v.literal('accepted'),
|
|
||||||
v.literal('rejected')
|
|
||||||
),
|
|
||||||
photoBase64: v.optional(v.string()),
|
|
||||||
photoMediaType: v.optional(v.string()),
|
|
||||||
thumbnailBase64: v.optional(v.string()),
|
|
||||||
createdAt: v.number()
|
|
||||||
}).index('by_chat_id', ['chatId']),
|
|
||||||
|
|
||||||
photoDrafts: defineTable({
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
deviceId: v.string(),
|
|
||||||
base64: v.string(),
|
|
||||||
mediaType: v.string(),
|
|
||||||
createdAt: v.number()
|
|
||||||
}).index('by_chat_id_and_device_id', ['chatId', 'deviceId']),
|
|
||||||
|
|
||||||
ragDatabases: defineTable({
|
|
||||||
userId: v.id('users'),
|
|
||||||
name: v.string(),
|
|
||||||
createdAt: v.number()
|
createdAt: v.number()
|
||||||
})
|
})
|
||||||
.index('by_user_id', ['userId'])
|
|
||||||
.index('by_user_id_and_name', ['userId', 'name']),
|
|
||||||
|
|
||||||
ragConnections: defineTable({
|
|
||||||
userId: v.id('users'),
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
isGlobal: v.boolean(),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
.index('by_user_id', ['userId'])
|
|
||||||
.index('by_user_id_and_rag_database_id', ['userId', 'ragDatabaseId'])
|
|
||||||
.index('by_rag_database_id', ['ragDatabaseId']),
|
|
||||||
|
|
||||||
injectDatabases: defineTable({
|
|
||||||
userId: v.id('users'),
|
|
||||||
name: v.string(),
|
|
||||||
content: v.optional(v.string()),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
.index('by_user_id', ['userId'])
|
|
||||||
.index('by_user_id_and_name', ['userId', 'name']),
|
|
||||||
|
|
||||||
injectConnections: defineTable({
|
|
||||||
userId: v.id('users'),
|
|
||||||
injectDatabaseId: v.id('injectDatabases'),
|
|
||||||
isGlobal: v.boolean(),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
.index('by_user_id', ['userId'])
|
|
||||||
.index('by_user_id_and_inject_database_id', ['userId', 'injectDatabaseId'])
|
|
||||||
.index('by_inject_database_id', ['injectDatabaseId']),
|
|
||||||
|
|
||||||
pendingRoomUploads: defineTable({
|
|
||||||
userId: v.id('users'),
|
|
||||||
pin: v.string(),
|
|
||||||
imageBase64: v.string(),
|
|
||||||
mediaType: v.string(),
|
|
||||||
status: v.union(
|
|
||||||
v.literal('pending'),
|
|
||||||
v.literal('uploading'),
|
|
||||||
v.literal('done'),
|
|
||||||
v.literal('failed')
|
|
||||||
),
|
|
||||||
attempts: v.number(),
|
|
||||||
lastError: v.optional(v.string()),
|
|
||||||
createdAt: v.number(),
|
|
||||||
updatedAt: v.number()
|
|
||||||
})
|
|
||||||
.index('by_status_and_updated_at', ['status', 'updatedAt'])
|
|
||||||
.index('by_user_id', ['userId']),
|
|
||||||
|
|
||||||
incomingSolutions: defineTable({
|
|
||||||
userId: v.id('users'),
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
pin: v.string(),
|
|
||||||
conditionSnippet: v.string(),
|
|
||||||
problem: v.string(),
|
|
||||||
snippet: v.string(),
|
|
||||||
fullSolution: v.string(),
|
|
||||||
plain: v.string(),
|
|
||||||
status: v.union(v.literal('preview'), v.literal('accepted'), v.literal('dismissed')),
|
|
||||||
linkedMessageId: v.optional(v.id('messages')),
|
|
||||||
telegramMessageId: v.optional(v.number()),
|
|
||||||
acceptedAt: v.optional(v.number()),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
.index('by_chat_id_and_status', ['chatId', 'status'])
|
|
||||||
.index('by_status_and_telegram_message_id', ['status', 'telegramMessageId'])
|
|
||||||
.index('by_linked_message_id', ['linkedMessageId']),
|
|
||||||
|
|
||||||
incomingSheets: defineTable({
|
|
||||||
userId: v.id('users'),
|
|
||||||
chatId: v.id('chats'),
|
|
||||||
pin: v.string(),
|
|
||||||
sheetId: v.number(),
|
|
||||||
sheetCreatedAt: v.number(),
|
|
||||||
text: v.string(),
|
|
||||||
status: v.union(v.literal('preview'), v.literal('accepted'), v.literal('dismissed')),
|
|
||||||
linkedMessageId: v.optional(v.id('messages')),
|
|
||||||
acceptedAt: v.optional(v.number()),
|
|
||||||
createdAt: v.number()
|
|
||||||
})
|
|
||||||
.index('by_chat_id_and_status', ['chatId', 'status'])
|
|
||||||
.index('by_chat_id_and_sheet_id', ['chatId', 'sheetId'])
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { v } from 'convex/values';
|
import { v } from 'convex/values';
|
||||||
import { mutation, query } from './_generated/server';
|
import { mutation, query } from './_generated/server';
|
||||||
import type { Id } from './_generated/dataModel';
|
|
||||||
|
|
||||||
const DEFAULT_MODEL = 'gemini-3-pro-preview';
|
const DEFAULT_MODEL = 'gemini-3-pro-preview';
|
||||||
|
|
||||||
@@ -17,28 +16,7 @@ export const getById = query({
|
|||||||
followUpPrompt: v.optional(v.string()),
|
followUpPrompt: v.optional(v.string()),
|
||||||
model: v.string(),
|
model: v.string(),
|
||||||
followUpModel: v.optional(v.string()),
|
followUpModel: v.optional(v.string()),
|
||||||
activeChatId: v.optional(v.id('chats')),
|
activeChatId: v.optional(v.id('chats'))
|
||||||
ragCollectionMode: v.optional(
|
|
||||||
v.object({
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
injectCollectionMode: v.optional(
|
|
||||||
v.object({
|
|
||||||
injectDatabaseId: v.id('injectDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
collaborativeRoom: v.optional(
|
|
||||||
v.object({
|
|
||||||
pin: v.string(),
|
|
||||||
creatorToken: v.optional(v.string()),
|
|
||||||
joinedAt: v.number(),
|
|
||||||
lastSeenHistoryCount: v.optional(v.number()),
|
|
||||||
lastSeenSheetId: v.optional(v.number())
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}),
|
}),
|
||||||
v.null()
|
v.null()
|
||||||
),
|
),
|
||||||
@@ -60,28 +38,7 @@ export const getByTelegramId = query({
|
|||||||
followUpPrompt: v.optional(v.string()),
|
followUpPrompt: v.optional(v.string()),
|
||||||
model: v.string(),
|
model: v.string(),
|
||||||
followUpModel: v.optional(v.string()),
|
followUpModel: v.optional(v.string()),
|
||||||
activeChatId: v.optional(v.id('chats')),
|
activeChatId: v.optional(v.id('chats'))
|
||||||
ragCollectionMode: v.optional(
|
|
||||||
v.object({
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
injectCollectionMode: v.optional(
|
|
||||||
v.object({
|
|
||||||
injectDatabaseId: v.id('injectDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
collaborativeRoom: v.optional(
|
|
||||||
v.object({
|
|
||||||
pin: v.string(),
|
|
||||||
creatorToken: v.optional(v.string()),
|
|
||||||
joinedAt: v.number(),
|
|
||||||
lastSeenHistoryCount: v.optional(v.number()),
|
|
||||||
lastSeenSheetId: v.optional(v.number())
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}),
|
}),
|
||||||
v.null()
|
v.null()
|
||||||
),
|
),
|
||||||
@@ -170,147 +127,3 @@ export const setActiveChat = mutation({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const startRagCollectionMode = mutation({
|
|
||||||
args: { userId: v.id('users'), ragDatabaseId: v.id('ragDatabases') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.userId, {
|
|
||||||
ragCollectionMode: {
|
|
||||||
ragDatabaseId: args.ragDatabaseId,
|
|
||||||
activeSince: Date.now()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const stopRagCollectionMode = mutation({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.userId, { ragCollectionMode: undefined });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getRagCollectionMode = query({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
ragDatabaseId: v.id('ragDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const user = await ctx.db.get(args.userId);
|
|
||||||
return user?.ragCollectionMode ?? null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const startInjectCollectionMode = mutation({
|
|
||||||
args: { userId: v.id('users'), injectDatabaseId: v.id('injectDatabases') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.userId, {
|
|
||||||
injectCollectionMode: {
|
|
||||||
injectDatabaseId: args.injectDatabaseId,
|
|
||||||
activeSince: Date.now()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const stopInjectCollectionMode = mutation({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.userId, { injectCollectionMode: undefined });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getInjectCollectionMode = query({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.union(
|
|
||||||
v.object({
|
|
||||||
injectDatabaseId: v.id('injectDatabases'),
|
|
||||||
activeSince: v.number()
|
|
||||||
}),
|
|
||||||
v.null()
|
|
||||||
),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const user = await ctx.db.get(args.userId);
|
|
||||||
return user?.injectCollectionMode ?? null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const setCollaborativeRoom = mutation({
|
|
||||||
args: {
|
|
||||||
userId: v.id('users'),
|
|
||||||
pin: v.string(),
|
|
||||||
creatorToken: v.optional(v.string()),
|
|
||||||
lastSeenSheetId: v.optional(v.number())
|
|
||||||
},
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.userId, {
|
|
||||||
collaborativeRoom: {
|
|
||||||
pin: args.pin,
|
|
||||||
creatorToken: args.creatorToken,
|
|
||||||
joinedAt: Date.now(),
|
|
||||||
lastSeenSheetId: args.lastSeenSheetId ?? 0
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const clearCollaborativeRoom = mutation({
|
|
||||||
args: { userId: v.id('users') },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
await ctx.db.patch(args.userId, { collaborativeRoom: undefined });
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const setLastSeenSheetId = mutation({
|
|
||||||
args: { userId: v.id('users'), sheetId: v.number() },
|
|
||||||
returns: v.null(),
|
|
||||||
handler: async (ctx, args) => {
|
|
||||||
const user = await ctx.db.get(args.userId);
|
|
||||||
if (!user?.collaborativeRoom) return null;
|
|
||||||
await ctx.db.patch(args.userId, {
|
|
||||||
collaborativeRoom: { ...user.collaborativeRoom, lastSeenSheetId: args.sheetId }
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export const listActiveRoomUsers = query({
|
|
||||||
args: {},
|
|
||||||
returns: v.array(
|
|
||||||
v.object({
|
|
||||||
_id: v.id('users'),
|
|
||||||
pin: v.string(),
|
|
||||||
lastSeenSheetId: v.number()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
handler: async (ctx) => {
|
|
||||||
const users = await ctx.db.query('users').collect();
|
|
||||||
const result: Array<{ _id: Id<'users'>; pin: string; lastSeenSheetId: number }> = [];
|
|
||||||
for (const u of users) {
|
|
||||||
if (u.collaborativeRoom) {
|
|
||||||
result.push({
|
|
||||||
_id: u._id,
|
|
||||||
pin: u.collaborativeRoom.pin,
|
|
||||||
lastSeenSheetId: u.collaborativeRoom.lastSeenSheetId ?? 0
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
import { Marked } from 'marked';
|
|
||||||
|
|
||||||
const marked = new Marked({ breaks: true, gfm: true });
|
|
||||||
|
|
||||||
const CODE_OPEN = '';
|
|
||||||
const CODE_CLOSE = '';
|
|
||||||
|
|
||||||
export function processLatex(text: string): string {
|
|
||||||
const placeholders: string[] = [];
|
|
||||||
const stash = (match: string) => {
|
|
||||||
const token = `${CODE_OPEN}${placeholders.length}${CODE_CLOSE}`;
|
|
||||||
placeholders.push(match);
|
|
||||||
return token;
|
|
||||||
};
|
|
||||||
|
|
||||||
const protectedText = text.replace(/```[\s\S]*?```/g, stash).replace(/`[^`\n]*`/g, stash);
|
|
||||||
|
|
||||||
const rendered = protectedText
|
|
||||||
.replace(/\$\$(.*?)\$\$/gs, (_, tex) => {
|
|
||||||
const encoded = encodeURIComponent(tex.trim());
|
|
||||||
return `<img src="/service/latex?tex=${encoded}&display=1" alt="LaTeX" class="block my-1 max-h-12" />`;
|
|
||||||
})
|
|
||||||
.replace(/\$(.+?)\$/g, (_, tex) => {
|
|
||||||
const encoded = encodeURIComponent(tex.trim());
|
|
||||||
return `<img src="/service/latex?tex=${encoded}" alt="LaTeX" class="inline-block align-middle max-h-4" />`;
|
|
||||||
});
|
|
||||||
|
|
||||||
return rendered.replace(
|
|
||||||
new RegExp(`${CODE_OPEN}(\\d+)${CODE_CLOSE}`, 'g'),
|
|
||||||
(_, i) => placeholders[Number(i)]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function processContent(text: string): string {
|
|
||||||
return marked.parse(processLatex(text)) as string;
|
|
||||||
}
|
|
||||||
@@ -2,15 +2,13 @@
|
|||||||
import './layout.css';
|
import './layout.css';
|
||||||
import favicon from '$lib/assets/favicon.svg';
|
import favicon from '$lib/assets/favicon.svg';
|
||||||
import { PUBLIC_CONVEX_URL } from '$env/static/public';
|
import { PUBLIC_CONVEX_URL } from '$env/static/public';
|
||||||
import { env } from '$env/dynamic/public';
|
|
||||||
import { setupConvex } from 'convex-svelte';
|
import { setupConvex } from 'convex-svelte';
|
||||||
import { hasWebSocketSupport, setupPollingConvex } from '$lib/convex-polling.svelte';
|
import { hasWebSocketSupport, setupPollingConvex } from '$lib/convex-polling.svelte';
|
||||||
import { setContext } from 'svelte';
|
import { setContext } from 'svelte';
|
||||||
|
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
|
|
||||||
const fallbackEnabled = env.PUBLIC_FALLBACK === '1';
|
const usePolling = !hasWebSocketSupport();
|
||||||
const usePolling = fallbackEnabled && !hasWebSocketSupport();
|
|
||||||
setContext('convex-use-polling', usePolling);
|
setContext('convex-use-polling', usePolling);
|
||||||
|
|
||||||
if (usePolling) {
|
if (usePolling) {
|
||||||
|
|||||||
@@ -1,105 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
import { browser } from '$app/environment';
|
import { getContext } from 'svelte';
|
||||||
import { getContext, onMount } from 'svelte';
|
|
||||||
import { SvelteSet } from 'svelte/reactivity';
|
|
||||||
import { useQuery, useConvexClient } from 'convex-svelte';
|
import { useQuery, useConvexClient } from 'convex-svelte';
|
||||||
import {
|
import { usePollingQuery, usePollingMutation } from '$lib/convex-polling.svelte';
|
||||||
usePollingQuery,
|
|
||||||
usePollingMutation,
|
|
||||||
usePollingClient
|
|
||||||
} from '$lib/convex-polling.svelte';
|
|
||||||
import { api } from '$lib/convex/_generated/api';
|
import { api } from '$lib/convex/_generated/api';
|
||||||
import type { Id } from '$lib/convex/_generated/dataModel';
|
|
||||||
import ChatMessage from '$lib/components/ChatMessage.svelte';
|
import ChatMessage from '$lib/components/ChatMessage.svelte';
|
||||||
import PendingMessageBubble from '$lib/components/PendingMessageBubble.svelte';
|
|
||||||
import ChatInput from '$lib/components/ChatInput.svelte';
|
import ChatInput from '$lib/components/ChatInput.svelte';
|
||||||
import FollowUpButtons from '$lib/components/FollowUpButtons.svelte';
|
import FollowUpButtons from '$lib/components/FollowUpButtons.svelte';
|
||||||
import StealthOverlay from '$lib/components/StealthOverlay.svelte';
|
|
||||||
import CameraCapture from '$lib/components/CameraCapture.svelte';
|
|
||||||
import WatchCountdown from '$lib/components/WatchCountdown.svelte';
|
|
||||||
import PhotoPreview from '$lib/components/PhotoPreview.svelte';
|
|
||||||
import DraftBadge from '$lib/components/DraftBadge.svelte';
|
|
||||||
import SilentCapture from '$lib/components/SilentCapture.svelte';
|
|
||||||
import IncomingSheetsPanel from '$lib/components/IncomingSheetsPanel.svelte';
|
|
||||||
|
|
||||||
const usePolling = getContext<boolean>('convex-use-polling') ?? false;
|
const usePolling = getContext<boolean>('convex-use-polling') ?? false;
|
||||||
let mnemonic = $derived(page.params.mnemonic);
|
let mnemonic = $derived(page.params.mnemonic);
|
||||||
|
|
||||||
let lastMessageElement: HTMLDivElement | null = $state(null);
|
|
||||||
let showScrollButton = $state(false);
|
|
||||||
|
|
||||||
let deviceId = $state('');
|
|
||||||
let hasCamera = $state(false);
|
|
||||||
let showCamera = $state(false);
|
|
||||||
let showWatchCountdown = $state(false);
|
|
||||||
let activeRequestId: Id<'photoRequests'> | null = $state(null);
|
|
||||||
let previewPhoto: {
|
|
||||||
thumbnail: string;
|
|
||||||
mediaType: string;
|
|
||||||
requestId: Id<'photoRequests'>;
|
|
||||||
} | null = $state(null);
|
|
||||||
let shownPreviewIds = new SvelteSet<string>();
|
|
||||||
let silentCaptureRef: SilentCapture | null = $state(null);
|
|
||||||
let processedCaptureNowIds = new SvelteSet<string>();
|
|
||||||
|
|
||||||
function generateId(): string {
|
|
||||||
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
||||||
return crypto.randomUUID();
|
|
||||||
}
|
|
||||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
||||||
const r = (Math.random() * 16) | 0;
|
|
||||||
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
||||||
return v.toString(16);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getOrCreateDeviceId(): string {
|
|
||||||
if (!browser) return '';
|
|
||||||
let id = localStorage.getItem('stealth-device-id');
|
|
||||||
if (!id) {
|
|
||||||
id = generateId();
|
|
||||||
localStorage.setItem('stealth-device-id', id);
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function checkCamera(): Promise<boolean> {
|
|
||||||
if (!browser) return false;
|
|
||||||
if (!navigator.mediaDevices?.enumerateDevices) return false;
|
|
||||||
try {
|
|
||||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
||||||
return devices.some((d) => d.kind === 'videoinput');
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
deviceId = getOrCreateDeviceId();
|
|
||||||
checkCamera().then((has) => {
|
|
||||||
hasCamera = has;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if (!lastMessageElement) return;
|
|
||||||
|
|
||||||
const observer = new IntersectionObserver(
|
|
||||||
([entry]) => {
|
|
||||||
showScrollButton = !entry.isIntersecting;
|
|
||||||
},
|
|
||||||
{ threshold: 0, rootMargin: '0px 0px -90% 0px' }
|
|
||||||
);
|
|
||||||
|
|
||||||
observer.observe(lastMessageElement);
|
|
||||||
return () => observer.disconnect();
|
|
||||||
});
|
|
||||||
|
|
||||||
function scrollToLastMessage() {
|
|
||||||
lastMessageElement?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
||||||
}
|
|
||||||
|
|
||||||
const chatDataWs = usePolling
|
const chatDataWs = usePolling
|
||||||
? null
|
? null
|
||||||
: useQuery(api.chats.getWithUser, () => (mnemonic ? { mnemonic } : 'skip'));
|
: useQuery(api.chats.getWithUser, () => (mnemonic ? { mnemonic } : 'skip'));
|
||||||
@@ -108,26 +19,19 @@
|
|||||||
: null;
|
: null;
|
||||||
const chatData = $derived(usePolling ? chatDataPoll! : chatDataWs!);
|
const chatData = $derived(usePolling ? chatDataPoll! : chatDataWs!);
|
||||||
|
|
||||||
const chatId = $derived(chatData.data?.chat?._id);
|
|
||||||
|
|
||||||
const messagesQueryWs = usePolling
|
const messagesQueryWs = usePolling
|
||||||
? null
|
? null
|
||||||
: useQuery(api.messages.listByChat, () => (chatId ? { chatId } : 'skip'));
|
: useQuery(api.messages.listByChat, () =>
|
||||||
|
chatData.data?.chat?._id ? { chatId: chatData.data.chat._id } : 'skip'
|
||||||
|
);
|
||||||
const messagesQueryPoll = usePolling
|
const messagesQueryPoll = usePolling
|
||||||
? usePollingQuery(api.messages.listByChat, () => (chatId ? { chatId } : 'skip'))
|
? usePollingQuery(api.messages.listByChat, () =>
|
||||||
|
chatData.data?.chat?._id ? { chatId: chatData.data.chat._id } : 'skip'
|
||||||
|
)
|
||||||
: null;
|
: null;
|
||||||
const messagesQuery = $derived(usePolling ? messagesQueryPoll! : messagesQueryWs!);
|
const messagesQuery = $derived(usePolling ? messagesQueryPoll! : messagesQueryWs!);
|
||||||
|
|
||||||
const pendingQueryWs = usePolling
|
|
||||||
? null
|
|
||||||
: useQuery(api.pendingGenerations.listByChat, () => (chatId ? { chatId } : 'skip'));
|
|
||||||
const pendingQueryPoll = usePolling
|
|
||||||
? usePollingQuery(api.pendingGenerations.listByChat, () => (chatId ? { chatId } : 'skip'))
|
|
||||||
: null;
|
|
||||||
const pendingQuery = $derived(usePolling ? pendingQueryPoll! : pendingQueryWs!);
|
|
||||||
|
|
||||||
let messages = $derived(messagesQuery.data ?? []);
|
let messages = $derived(messagesQuery.data ?? []);
|
||||||
let pendingMessages = $derived(pendingQuery.data ?? []);
|
|
||||||
let lastMessage = $derived(messages[messages.length - 1]);
|
let lastMessage = $derived(messages[messages.length - 1]);
|
||||||
let followUpOptions = $derived(
|
let followUpOptions = $derived(
|
||||||
lastMessage?.role === 'assistant' && lastMessage.followUpOptions
|
lastMessage?.role === 'assistant' && lastMessage.followUpOptions
|
||||||
@@ -135,250 +39,56 @@
|
|||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|
||||||
const myDeviceWs = usePolling
|
|
||||||
? null
|
|
||||||
: useQuery(api.devicePairings.getMyDevice, () =>
|
|
||||||
chatId && deviceId ? { chatId, deviceId } : 'skip'
|
|
||||||
);
|
|
||||||
const myDevicePoll = usePolling
|
|
||||||
? usePollingQuery(api.devicePairings.getMyDevice, () =>
|
|
||||||
chatId && deviceId ? { chatId, deviceId } : 'skip'
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
const myDevice = $derived(usePolling ? myDevicePoll! : myDeviceWs!);
|
|
||||||
|
|
||||||
const pairedDeviceWs = usePolling
|
|
||||||
? null
|
|
||||||
: useQuery(api.devicePairings.getPairedDevice, () =>
|
|
||||||
chatId && deviceId ? { chatId, deviceId } : 'skip'
|
|
||||||
);
|
|
||||||
const pairedDevicePoll = usePolling
|
|
||||||
? usePollingQuery(api.devicePairings.getPairedDevice, () =>
|
|
||||||
chatId && deviceId ? { chatId, deviceId } : 'skip'
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
const pairedDevice = $derived(usePolling ? pairedDevicePoll! : pairedDeviceWs!);
|
|
||||||
|
|
||||||
const isPaired = $derived(!!myDevice.data?.pairedWithDeviceId && !!pairedDevice.data);
|
|
||||||
|
|
||||||
const pendingPairingWs = usePolling
|
|
||||||
? null
|
|
||||||
: useQuery(api.pairingRequests.getPending, () =>
|
|
||||||
chatId && deviceId ? { chatId, excludeDeviceId: deviceId } : 'skip'
|
|
||||||
);
|
|
||||||
const pendingPairingPoll = usePolling
|
|
||||||
? usePollingQuery(api.pairingRequests.getPending, () =>
|
|
||||||
chatId && deviceId ? { chatId, excludeDeviceId: deviceId } : 'skip'
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
const pendingPairing = $derived(usePolling ? pendingPairingPoll! : pendingPairingWs!);
|
|
||||||
|
|
||||||
const captureNowRequestWs = usePolling
|
|
||||||
? null
|
|
||||||
: useQuery(api.photoRequests.getCaptureNowRequest, () => (chatId ? { chatId } : 'skip'));
|
|
||||||
const captureNowRequestPoll = usePolling
|
|
||||||
? usePollingQuery(api.photoRequests.getCaptureNowRequest, () => (chatId ? { chatId } : 'skip'))
|
|
||||||
: null;
|
|
||||||
const captureNowRequest = $derived(usePolling ? captureNowRequestPoll! : captureNowRequestWs!);
|
|
||||||
|
|
||||||
const myActiveRequestWs = usePolling
|
|
||||||
? null
|
|
||||||
: useQuery(api.photoRequests.getMyActiveRequest, () =>
|
|
||||||
chatId && deviceId ? { chatId, deviceId } : 'skip'
|
|
||||||
);
|
|
||||||
const myActiveRequestPoll = usePolling
|
|
||||||
? usePollingQuery(api.photoRequests.getMyActiveRequest, () =>
|
|
||||||
chatId && deviceId ? { chatId, deviceId } : 'skip'
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
const myActiveRequest = $derived(usePolling ? myActiveRequestPoll! : myActiveRequestWs!);
|
|
||||||
|
|
||||||
const photoDraftWs = usePolling
|
|
||||||
? null
|
|
||||||
: useQuery(api.photoDrafts.get, () => (chatId && deviceId ? { chatId, deviceId } : 'skip'));
|
|
||||||
const photoDraftPoll = usePolling
|
|
||||||
? usePollingQuery(api.photoDrafts.get, () =>
|
|
||||||
chatId && deviceId ? { chatId, deviceId } : 'skip'
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
const photoDraft = $derived(usePolling ? photoDraftPoll! : photoDraftWs!);
|
|
||||||
const draftPhotos = $derived(photoDraft.data?.photos ?? []);
|
|
||||||
|
|
||||||
const incomingSheetsWs = usePolling
|
|
||||||
? null
|
|
||||||
: useQuery(api.incomingSheets.listForChat, () =>
|
|
||||||
chatId ? { chatId, status: 'preview' as const } : 'skip'
|
|
||||||
);
|
|
||||||
const incomingSheetsPoll = usePolling
|
|
||||||
? usePollingQuery(api.incomingSheets.listForChat, () =>
|
|
||||||
chatId ? { chatId, status: 'preview' as const } : 'skip'
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
const incomingSheetsQ = $derived(usePolling ? incomingSheetsPoll! : incomingSheetsWs!);
|
|
||||||
const incomingSheetItems = $derived(incomingSheetsQ.data ?? []);
|
|
||||||
|
|
||||||
const acceptSheetPoll = usePolling ? usePollingMutation(api.incomingSheets.accept) : null;
|
|
||||||
const dismissSheetPoll = usePolling ? usePollingMutation(api.incomingSheets.dismiss) : null;
|
|
||||||
|
|
||||||
function handleAcceptSheet(id: Id<'incomingSheets'>) {
|
|
||||||
if (usePolling && acceptSheetPoll) {
|
|
||||||
acceptSheetPoll({ id });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.incomingSheets.accept, { id });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleDismissSheet(id: Id<'incomingSheets'>) {
|
|
||||||
if (usePolling && dismissSheetPoll) {
|
|
||||||
dismissSheetPoll({ id });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.incomingSheets.dismiss, { id });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
const req = captureNowRequest.data;
|
|
||||||
if (req && hasCamera && !processedCaptureNowIds.has(req._id)) {
|
|
||||||
processedCaptureNowIds.add(req._id);
|
|
||||||
const tryCapture = () => {
|
|
||||||
const success = silentCaptureRef?.capture();
|
|
||||||
if (!success) {
|
|
||||||
setTimeout(tryCapture, 100);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
tryCapture();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
const req = myActiveRequest.data;
|
|
||||||
if (req?.status === 'captured' && req.photoMediaType) {
|
|
||||||
if (shownPreviewIds.has(req._id)) return;
|
|
||||||
shownPreviewIds.add(req._id);
|
|
||||||
|
|
||||||
const client = pollingClient ?? clientWs;
|
|
||||||
if (client) {
|
|
||||||
client.query(api.photoRequests.getPhotoPreview, { requestId: req._id }).then((data) => {
|
|
||||||
if (data) {
|
|
||||||
previewPhoto = {
|
|
||||||
thumbnail: data.thumbnailBase64,
|
|
||||||
mediaType: data.photoMediaType,
|
|
||||||
requestId: req._id
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let prevMessageCount = 0;
|
let prevMessageCount = 0;
|
||||||
let prevLastMessageId: string | undefined;
|
let prevLastMessageId: string | undefined;
|
||||||
let prevPendingCount = 0;
|
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const count = messages.length;
|
const count = messages.length;
|
||||||
const lastId = lastMessage?._id;
|
const lastId = lastMessage?._id;
|
||||||
const pendingCount = pendingMessages.length;
|
if (count > prevMessageCount || (lastId && lastId !== prevLastMessageId)) {
|
||||||
if (
|
|
||||||
count > prevMessageCount ||
|
|
||||||
pendingCount > prevPendingCount ||
|
|
||||||
(lastId && lastId !== prevLastMessageId)
|
|
||||||
) {
|
|
||||||
prevMessageCount = count;
|
prevMessageCount = count;
|
||||||
prevPendingCount = pendingCount;
|
|
||||||
prevLastMessageId = lastId;
|
prevLastMessageId = lastId;
|
||||||
window.scrollTo(0, document.body.scrollHeight);
|
window.scrollTo(0, document.body.scrollHeight);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const clientWs = usePolling ? null : useConvexClient();
|
const clientWs = usePolling ? null : useConvexClient();
|
||||||
const pollingClient = usePolling ? usePollingClient() : null;
|
|
||||||
const createMessagePoll = usePolling ? usePollingMutation(api.messages.create) : null;
|
const createMessagePoll = usePolling ? usePollingMutation(api.messages.create) : null;
|
||||||
const registerDevicePoll = usePolling ? usePollingMutation(api.devicePairings.register) : null;
|
|
||||||
const heartbeatPoll = usePolling ? usePollingMutation(api.devicePairings.heartbeat) : null;
|
|
||||||
const addPhotoPoll = usePolling ? usePollingMutation(api.photoDrafts.addPhoto) : null;
|
|
||||||
const removePhotoPoll = usePolling ? usePollingMutation(api.photoDrafts.removePhoto) : null;
|
|
||||||
const createPairingPoll = usePolling ? usePollingMutation(api.pairingRequests.create) : null;
|
|
||||||
const acceptPairingPoll = usePolling ? usePollingMutation(api.pairingRequests.accept) : null;
|
|
||||||
const rejectPairingPoll = usePolling ? usePollingMutation(api.pairingRequests.reject) : null;
|
|
||||||
const unpairPoll = usePolling ? usePollingMutation(api.pairingRequests.unpair) : null;
|
|
||||||
const createRequestPoll = usePolling ? usePollingMutation(api.photoRequests.create) : null;
|
|
||||||
const markCaptureNowPoll = usePolling
|
|
||||||
? usePollingMutation(api.photoRequests.markCaptureNow)
|
|
||||||
: null;
|
|
||||||
const submitPhotoPoll = usePolling ? usePollingMutation(api.photoRequests.submitPhoto) : null;
|
|
||||||
const markRejectedPoll = usePolling ? usePollingMutation(api.photoRequests.markRejected) : null;
|
|
||||||
const acceptPhotoToDraftPoll = usePolling
|
|
||||||
? usePollingMutation(api.photoRequests.acceptPhotoToDraft)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
$effect(() => {
|
async function sendMessage(content: string) {
|
||||||
if (!chatId || !deviceId) return;
|
|
||||||
|
|
||||||
if (usePolling && registerDevicePoll) {
|
|
||||||
registerDevicePoll({ chatId, deviceId, hasCamera });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.devicePairings.register, {
|
|
||||||
chatId,
|
|
||||||
deviceId,
|
|
||||||
hasCamera
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
if (usePolling && heartbeatPoll) {
|
|
||||||
heartbeatPoll({ chatId, deviceId });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.devicePairings.heartbeat, { chatId, deviceId });
|
|
||||||
}
|
|
||||||
}, 10000);
|
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
|
||||||
});
|
|
||||||
|
|
||||||
function sendMessage(content: string) {
|
|
||||||
const chat = chatData.data?.chat;
|
const chat = chatData.data?.chat;
|
||||||
if (!chat) return;
|
if (!chat) return;
|
||||||
|
|
||||||
const photos = draftPhotos;
|
|
||||||
const photoDraftIds = photos.length > 0 ? photos.map((p) => p._id) : undefined;
|
|
||||||
|
|
||||||
const messageContent =
|
|
||||||
content || (photos.length > 0 ? 'Process images according to your task' : '');
|
|
||||||
if (!messageContent) return;
|
|
||||||
|
|
||||||
if (usePolling && createMessagePoll) {
|
if (usePolling && createMessagePoll) {
|
||||||
createMessagePoll({
|
await createMessagePoll({
|
||||||
chatId: chat._id,
|
chatId: chat._id,
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: messageContent,
|
content,
|
||||||
source: 'web',
|
source: 'web'
|
||||||
photoDraftIds
|
|
||||||
});
|
});
|
||||||
} else if (clientWs) {
|
} else if (clientWs) {
|
||||||
clientWs.mutation(api.messages.create, {
|
await clientWs.mutation(api.messages.create, {
|
||||||
chatId: chat._id,
|
chatId: chat._id,
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: messageContent,
|
content,
|
||||||
source: 'web',
|
source: 'web'
|
||||||
photoDraftIds
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function summarize() {
|
async function summarize() {
|
||||||
const chat = chatData.data?.chat;
|
const chat = chatData.data?.chat;
|
||||||
if (!chat) return;
|
if (!chat) return;
|
||||||
|
|
||||||
if (usePolling && createMessagePoll) {
|
if (usePolling && createMessagePoll) {
|
||||||
createMessagePoll({
|
await createMessagePoll({
|
||||||
chatId: chat._id,
|
chatId: chat._id,
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: '/summarize',
|
content: '/summarize',
|
||||||
source: 'web'
|
source: 'web'
|
||||||
});
|
});
|
||||||
} else if (clientWs) {
|
} else if (clientWs) {
|
||||||
clientWs.mutation(api.messages.create, {
|
await clientWs.mutation(api.messages.create, {
|
||||||
chatId: chat._id,
|
chatId: chat._id,
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: '/summarize',
|
content: '/summarize',
|
||||||
@@ -386,191 +96,6 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleTakePhoto() {
|
|
||||||
showCamera = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleCameraCapture(base64: string, mediaType: string) {
|
|
||||||
showCamera = false;
|
|
||||||
if (!chatId) return;
|
|
||||||
if (usePolling && addPhotoPoll) {
|
|
||||||
addPhotoPoll({ chatId, deviceId, photo: { base64, mediaType } });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.photoDrafts.addPhoto, {
|
|
||||||
chatId,
|
|
||||||
deviceId,
|
|
||||||
photo: { base64, mediaType }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleCameraClose() {
|
|
||||||
showCamera = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handlePair() {
|
|
||||||
if (!chatId) return;
|
|
||||||
if (usePolling && createPairingPoll) {
|
|
||||||
createPairingPoll({ chatId, fromDeviceId: deviceId });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.pairingRequests.create, {
|
|
||||||
chatId,
|
|
||||||
fromDeviceId: deviceId
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleAcceptPairing() {
|
|
||||||
const req = pendingPairing.data;
|
|
||||||
if (!req) return;
|
|
||||||
if (usePolling && acceptPairingPoll) {
|
|
||||||
acceptPairingPoll({ requestId: req._id, acceptingDeviceId: deviceId });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.pairingRequests.accept, {
|
|
||||||
requestId: req._id,
|
|
||||||
acceptingDeviceId: deviceId
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleRejectPairing() {
|
|
||||||
const req = pendingPairing.data;
|
|
||||||
if (!req) return;
|
|
||||||
if (usePolling && rejectPairingPoll) {
|
|
||||||
rejectPairingPoll({ requestId: req._id });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.pairingRequests.reject, { requestId: req._id });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleUnpair() {
|
|
||||||
if (!chatId) return;
|
|
||||||
if (usePolling && unpairPoll) {
|
|
||||||
unpairPoll({ chatId, deviceId });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.pairingRequests.unpair, {
|
|
||||||
chatId,
|
|
||||||
deviceId
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleRequestPhoto() {
|
|
||||||
if (!chatId || !pairedDevice.data) return;
|
|
||||||
const captureDeviceId = pairedDevice.data.deviceId;
|
|
||||||
|
|
||||||
if (usePolling && createRequestPoll) {
|
|
||||||
createRequestPoll({ chatId, requesterId: deviceId, captureDeviceId }).then((id) => {
|
|
||||||
if (id) {
|
|
||||||
activeRequestId = id as Id<'photoRequests'>;
|
|
||||||
showWatchCountdown = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs
|
|
||||||
.mutation(api.photoRequests.create, {
|
|
||||||
chatId,
|
|
||||||
requesterId: deviceId,
|
|
||||||
captureDeviceId
|
|
||||||
})
|
|
||||||
.then((id) => {
|
|
||||||
activeRequestId = id;
|
|
||||||
showWatchCountdown = true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleWatchCountdownComplete() {
|
|
||||||
showWatchCountdown = false;
|
|
||||||
if (!activeRequestId) return;
|
|
||||||
const reqId = activeRequestId;
|
|
||||||
activeRequestId = null;
|
|
||||||
|
|
||||||
if (usePolling && markCaptureNowPoll) {
|
|
||||||
markCaptureNowPoll({ requestId: reqId });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.photoRequests.markCaptureNow, { requestId: reqId });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleWatchCountdownCancel() {
|
|
||||||
showWatchCountdown = false;
|
|
||||||
if (activeRequestId && markRejectedPoll) {
|
|
||||||
if (usePolling) {
|
|
||||||
markRejectedPoll({ requestId: activeRequestId });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.photoRequests.markRejected, { requestId: activeRequestId });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
activeRequestId = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleSilentCapture(base64: string, mediaType: string, thumbnailBase64: string) {
|
|
||||||
const req = captureNowRequest.data;
|
|
||||||
if (!req) return;
|
|
||||||
|
|
||||||
if (usePolling && submitPhotoPoll) {
|
|
||||||
submitPhotoPoll({
|
|
||||||
requestId: req._id,
|
|
||||||
photoBase64: base64,
|
|
||||||
photoMediaType: mediaType,
|
|
||||||
thumbnailBase64
|
|
||||||
});
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.photoRequests.submitPhoto, {
|
|
||||||
requestId: req._id,
|
|
||||||
photoBase64: base64,
|
|
||||||
photoMediaType: mediaType,
|
|
||||||
thumbnailBase64
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handlePreviewAccept() {
|
|
||||||
if (!previewPhoto || !chatId) return;
|
|
||||||
|
|
||||||
const reqId = previewPhoto.requestId;
|
|
||||||
previewPhoto = null;
|
|
||||||
|
|
||||||
if (usePolling && acceptPhotoToDraftPoll) {
|
|
||||||
acceptPhotoToDraftPoll({ requestId: reqId, chatId, deviceId });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.photoRequests.acceptPhotoToDraft, {
|
|
||||||
requestId: reqId,
|
|
||||||
chatId,
|
|
||||||
deviceId
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handlePreviewReject() {
|
|
||||||
if (!previewPhoto) return;
|
|
||||||
|
|
||||||
const reqId = previewPhoto.requestId;
|
|
||||||
previewPhoto = null;
|
|
||||||
|
|
||||||
if (usePolling && markRejectedPoll) {
|
|
||||||
markRejectedPoll({ requestId: reqId });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.photoRequests.markRejected, {
|
|
||||||
requestId: reqId
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleRemoveDraftPhoto(index: number) {
|
|
||||||
if (!chatId) return;
|
|
||||||
if (usePolling && removePhotoPoll) {
|
|
||||||
removePhotoPoll({ chatId, deviceId, index });
|
|
||||||
} else if (clientWs) {
|
|
||||||
clientWs.mutation(api.photoDrafts.removePhoto, {
|
|
||||||
chatId,
|
|
||||||
deviceId,
|
|
||||||
index
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -593,39 +118,12 @@
|
|||||||
<div class="py-4 text-center text-xs text-neutral-500">Not found</div>
|
<div class="py-4 text-center text-xs text-neutral-500">Not found</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
{#each messages as message, i (message._id)}
|
{#each messages as message (message._id)}
|
||||||
{#if i === messages.length - 1 && pendingMessages.length === 0}
|
<ChatMessage
|
||||||
<div bind:this={lastMessageElement}>
|
role={message.role}
|
||||||
<ChatMessage
|
content={message.content}
|
||||||
role={message.role}
|
isStreaming={message.isStreaming}
|
||||||
content={message.content}
|
/>
|
||||||
isStreaming={message.isStreaming}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<ChatMessage
|
|
||||||
role={message.role}
|
|
||||||
content={message.content}
|
|
||||||
isStreaming={message.isStreaming}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
{#each pendingMessages as p, i (p._id)}
|
|
||||||
{#if i === pendingMessages.length - 1}
|
|
||||||
<div bind:this={lastMessageElement}>
|
|
||||||
<PendingMessageBubble
|
|
||||||
content={p.userMessage}
|
|
||||||
images={p.imagesBase64 ?? []}
|
|
||||||
mediaTypes={p.imagesMediaTypes ?? []}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<PendingMessageBubble
|
|
||||||
content={p.userMessage}
|
|
||||||
images={p.imagesBase64 ?? []}
|
|
||||||
mediaTypes={p.imagesMediaTypes ?? []}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -635,122 +133,16 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="mt-3 space-y-2">
|
<div class="mt-2 flex gap-1">
|
||||||
<div class="flex gap-2">
|
<button
|
||||||
{#if hasCamera}
|
onclick={summarize}
|
||||||
<button
|
class="shrink-0 rounded bg-neutral-800 px-1.5 py-0.5 text-[8px] text-neutral-400"
|
||||||
onclick={handleTakePhoto}
|
>
|
||||||
class="flex-1 rounded bg-neutral-800 py-2 text-xs text-neutral-300"
|
/sum
|
||||||
>
|
</button>
|
||||||
+ photo
|
<div class="flex-1">
|
||||||
</button>
|
<ChatInput onsubmit={sendMessage} />
|
||||||
{/if}
|
|
||||||
{#if isPaired && pairedDevice.data?.hasCamera}
|
|
||||||
<button
|
|
||||||
onclick={handleRequestPhoto}
|
|
||||||
class="flex-1 rounded bg-neutral-800 py-2 text-xs text-neutral-300"
|
|
||||||
>
|
|
||||||
request
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
{#if isPaired}
|
|
||||||
<button
|
|
||||||
onclick={handleUnpair}
|
|
||||||
class="flex-1 rounded bg-red-900/50 py-2 text-xs text-red-300"
|
|
||||||
>
|
|
||||||
unpair
|
|
||||||
</button>
|
|
||||||
{:else}
|
|
||||||
<button
|
|
||||||
onclick={handlePair}
|
|
||||||
class="flex-1 rounded bg-neutral-800 py-2 text-xs text-neutral-300"
|
|
||||||
>
|
|
||||||
pair
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
<button
|
|
||||||
onclick={summarize}
|
|
||||||
class="flex-1 rounded bg-neutral-800 py-2 text-xs text-neutral-300"
|
|
||||||
>
|
|
||||||
/sum
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{#if draftPhotos.length > 0}
|
|
||||||
<DraftBadge photos={draftPhotos} onremove={handleRemoveDraftPhoto} />
|
|
||||||
{/if}
|
|
||||||
{#if incomingSheetItems.length > 0}
|
|
||||||
<IncomingSheetsPanel
|
|
||||||
sheets={incomingSheetItems}
|
|
||||||
onaccept={handleAcceptSheet}
|
|
||||||
ondismiss={handleDismissSheet}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
<ChatInput
|
|
||||||
onsubmit={sendMessage}
|
|
||||||
onpasteimage={handleCameraCapture}
|
|
||||||
allowEmpty={draftPhotos.length > 0}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if showScrollButton}
|
|
||||||
<button
|
|
||||||
onclick={scrollToLastMessage}
|
|
||||||
class="fixed right-3 bottom-12 z-50 flex h-8 w-8 animate-pulse items-center justify-center rounded-full bg-blue-600 text-white shadow-lg"
|
|
||||||
>
|
|
||||||
↓
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<StealthOverlay />
|
|
||||||
|
|
||||||
{#if showCamera}
|
|
||||||
<CameraCapture oncapture={handleCameraCapture} onclose={handleCameraClose} />
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if pendingPairing.data && !isPaired}
|
|
||||||
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/90" data-camera-ui>
|
|
||||||
<div class="rounded-lg bg-neutral-900 p-6 text-center">
|
|
||||||
<p class="mb-4 text-sm text-white">Accept pairing request?</p>
|
|
||||||
<div class="flex gap-3">
|
|
||||||
<button
|
|
||||||
onclick={handleAcceptPairing}
|
|
||||||
class="flex-1 rounded bg-blue-600 py-2 text-sm text-white"
|
|
||||||
>
|
|
||||||
Accept
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onclick={handleRejectPairing}
|
|
||||||
class="flex-1 rounded bg-neutral-700 py-2 text-sm text-white"
|
|
||||||
>
|
|
||||||
Reject
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if showWatchCountdown}
|
|
||||||
<WatchCountdown
|
|
||||||
oncomplete={handleWatchCountdownComplete}
|
|
||||||
oncancel={handleWatchCountdownCancel}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if previewPhoto}
|
|
||||||
<PhotoPreview
|
|
||||||
base64={previewPhoto.thumbnail}
|
|
||||||
mediaType={previewPhoto.mediaType}
|
|
||||||
onaccept={handlePreviewAccept}
|
|
||||||
onreject={handlePreviewReject}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if hasCamera && isPaired}
|
|
||||||
<SilentCapture
|
|
||||||
bind:this={silentCaptureRef}
|
|
||||||
oncapture={handleSilentCapture}
|
|
||||||
onunpair={handleUnpair}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,7 +2,4 @@ import tailwindcss from '@tailwindcss/vite';
|
|||||||
import { sveltekit } from '@sveltejs/kit/vite';
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({ plugins: [tailwindcss(), sveltekit()] });
|
||||||
plugins: [tailwindcss(), sveltekit()],
|
|
||||||
server: { allowedHosts: ['parameters-detection-adware-christ.trycloudflare.com'] }
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user