feat: Oracle Canvas Component Schema and Qwen 3.6 integration (#31)

Co-authored-by: Sagnik <sagnik7896@gmail.com>
Reviewed-on: #31
This commit was merged in pull request #31.
This commit is contained in:
2026-04-20 01:43:39 +05:30
parent 57144e1bd3
commit e519339cc9
129 changed files with 625213 additions and 262 deletions

View File

@@ -22,6 +22,7 @@ from __future__ import annotations
import json
import logging
import os
from typing import Any, Optional
from fastapi import APIRouter, Depends, HTTPException, Query, Request, status
@@ -32,6 +33,7 @@ from backend.auth.dependencies import get_current_user
logger = logging.getLogger("velocity.oracle_templates")
router = APIRouter()
_DEFAULT_TENANT_ID = os.getenv("ORACLE_DEFAULT_TENANT_ID", "tenant_velocity")
# ── Helpers ───────────────────────────────────────────────────────────────────
@@ -43,6 +45,10 @@ def _pool(request: Request):
return pool
def _tenant_id() -> str:
return _DEFAULT_TENANT_ID
# ── Models ────────────────────────────────────────────────────────────────────
class ChapterCreate(BaseModel):
@@ -112,7 +118,7 @@ async def list_template_chapters(
GROUP BY ch.chapter_id
ORDER BY ch.sort_order ASC
""",
user.role,
_tenant_id(),
)
return {"chapters": [dict(r) for r in rows]}
@@ -132,7 +138,7 @@ async def create_template_chapter(
VALUES ($1,$2,$3,$4)
RETURNING chapter_id, created_at
""",
user.role, body.name, body.description, body.sort_order,
_tenant_id(), body.name, body.description, body.sort_order,
)
return {"chapter_id": str(row["chapter_id"]), "created_at": str(row["created_at"])}
@@ -149,7 +155,7 @@ async def list_template_subchapters(
pool = _pool(request)
async with pool.acquire() as conn:
where = "WHERE sub.tenant_id=$1"
params: list[Any] = [user.role]
params: list[Any] = [_tenant_id()]
idx = 2
if not include_inactive:
where += " AND sub.is_active=TRUE"
@@ -186,7 +192,7 @@ async def create_template_subchapter(
# Verify chapter exists and belongs to tenant
ch_exists = await conn.fetchval(
"SELECT 1 FROM oracle_template_chapters WHERE chapter_id=$1 AND tenant_id=$2",
body.chapter_id, user.role,
body.chapter_id, _tenant_id(),
)
if not ch_exists:
raise HTTPException(404, "Chapter not found")
@@ -198,7 +204,7 @@ async def create_template_subchapter(
VALUES ($1,$2,$3,$4,$5)
RETURNING subchapter_id, created_at
""",
body.chapter_id, user.role, body.name, body.description, body.sort_order,
body.chapter_id, _tenant_id(), body.name, body.description, body.sort_order,
)
return {"subchapter_id": str(row["subchapter_id"]), "created_at": str(row["created_at"])}
@@ -218,7 +224,7 @@ async def list_component_templates(
):
pool = _pool(request)
where = "WHERE t.tenant_id=$1"
params: list[Any] = [user.role]
params: list[Any] = [_tenant_id()]
idx = 2
if chapter_id:
@@ -270,7 +276,7 @@ async def create_component_template(
) VALUES ($1,$2,$3,$4,$5,$6,$7::jsonb,$8,$9,$10,'draft')
RETURNING template_id, created_at
""",
user.role, body.name, body.category, body.chapter_id, body.subchapter_id,
_tenant_id(), body.name, body.category, body.chapter_id, body.subchapter_id,
body.accepted_shapes,
json.dumps(body.json_template) if body.json_template else None,
body.description, body.origin, body.version,
@@ -294,7 +300,7 @@ async def get_component_template(
LEFT JOIN oracle_template_subchapters sub ON sub.subchapter_id = t.subchapter_id
WHERE t.template_id=$1 AND t.tenant_id=$2
""",
template_id, user.role,
template_id, _tenant_id(),
)
if not row:
raise HTTPException(404, "Template not found")
@@ -315,7 +321,7 @@ async def add_seed_example(
async with pool.acquire() as conn:
exists = await conn.fetchval(
"SELECT 1 FROM oracle_component_templates WHERE template_id=$1 AND tenant_id=$2",
template_id, user.role,
template_id, _tenant_id(),
)
if not exists:
raise HTTPException(404, "Template not found")
@@ -371,7 +377,7 @@ async def trigger_synthetic_job(
async with pool.acquire() as conn:
exists = await conn.fetchval(
"SELECT 1 FROM oracle_component_templates WHERE template_id=$1 AND tenant_id=$2",
body.template_id, user.role,
body.template_id, _tenant_id(),
)
if not exists:
raise HTTPException(404, "Template not found")
@@ -384,7 +390,7 @@ async def trigger_synthetic_job(
) VALUES ($1,$2,$3,$4,$5,$6,$7)
RETURNING job_id, status, created_at
""",
user.role, body.template_id, body.chapter_id, body.subchapter_id,
_tenant_id(), body.template_id, body.chapter_id, body.subchapter_id,
body.model, body.requested_count, user.user_id,
)
logger.info(