feat: KB Accelerator — convert KB articles into interactive flows
Full-stack implementation of the KB Accelerator feature that converts static MSP knowledge base articles into interactive troubleshooting and procedural flows using AI. Backend: - Migrations 054/055: kb_imports, kb_import_nodes tables + plan_limits KB columns - SQLAlchemy models with relationships and self-referential node hierarchy - Text extraction service (txt, paste, docx with structural metadata) - AI conversion service with MSP-specialist prompts for both flow types - 8 API endpoints: upload, get, list, convert, edit node, commit, delete, quota - Tier-gated access via plan_limits (free: 3 lifetime, pro/team: unlimited) - 8 integration tests covering upload, get/list, quota, commit, delete Frontend: - TypeScript types and API client for all KB Accelerator endpoints - Multi-step wizard page: upload → processing → review → success - Upload screen with paste/file tabs, drag-drop, target type selector - Two-panel review screen with source highlighting and node cards - Per-node actions: approve, edit, regenerate, insert, delete - Confidence color indicators (green/amber/red) - Sidebar navigation with Sparkles icon - Code-split lazy-loaded route at /kb-accelerator Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
79
backend/alembic/versions/054_add_kb_imports.py
Normal file
79
backend/alembic/versions/054_add_kb_imports.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""add kb_imports and kb_import_nodes tables
|
||||
|
||||
Revision ID: 054
|
||||
Revises: 053
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
||||
|
||||
revision = "054"
|
||||
down_revision = "053"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
"kb_imports",
|
||||
sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
||||
sa.Column("account_id", UUID(as_uuid=True), sa.ForeignKey("accounts.id", ondelete="CASCADE"), nullable=False, index=True),
|
||||
sa.Column("created_by", UUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True),
|
||||
sa.Column("source_filename", sa.String(500), nullable=True),
|
||||
sa.Column("source_format", sa.String(20), nullable=False),
|
||||
sa.Column("source_text", sa.Text, nullable=False),
|
||||
sa.Column("source_metadata", JSONB, nullable=True),
|
||||
sa.Column("target_type", sa.String(20), nullable=False),
|
||||
sa.Column("status", sa.String(20), nullable=False, server_default="processing"),
|
||||
sa.Column("confidence_avg", sa.Float, nullable=True),
|
||||
sa.Column("error_message", sa.Text, nullable=True),
|
||||
sa.Column("processing_time_ms", sa.Integer, nullable=True),
|
||||
sa.Column("ai_tokens_input", sa.Integer, nullable=True),
|
||||
sa.Column("ai_tokens_output", sa.Integer, nullable=True),
|
||||
sa.Column("tree_id", UUID(as_uuid=True), sa.ForeignKey("trees.id", ondelete="SET NULL"), nullable=True),
|
||||
sa.Column("batch_id", UUID(as_uuid=True), nullable=True, index=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
sa.CheckConstraint(
|
||||
"source_format IN ('txt', 'paste', 'docx', 'pdf', 'html', 'md')",
|
||||
name="ck_kb_imports_source_format",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"target_type IN ('troubleshooting', 'procedural')",
|
||||
name="ck_kb_imports_target_type",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"status IN ('processing', 'ready', 'committed', 'failed')",
|
||||
name="ck_kb_imports_status",
|
||||
),
|
||||
)
|
||||
|
||||
op.create_index("ix_kb_imports_status", "kb_imports", ["status"])
|
||||
op.create_index("ix_kb_imports_created_at_desc", "kb_imports", [sa.text("created_at DESC")])
|
||||
|
||||
op.create_table(
|
||||
"kb_import_nodes",
|
||||
sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
||||
sa.Column("kb_import_id", UUID(as_uuid=True), sa.ForeignKey("kb_imports.id", ondelete="CASCADE"), nullable=False, index=True),
|
||||
sa.Column("node_order", sa.Integer, nullable=False),
|
||||
sa.Column("node_type", sa.String(20), nullable=False),
|
||||
sa.Column("content", JSONB, nullable=False),
|
||||
sa.Column("parent_node_id", UUID(as_uuid=True), sa.ForeignKey("kb_import_nodes.id", ondelete="SET NULL"), nullable=True),
|
||||
sa.Column("source_excerpt", sa.Text, nullable=True),
|
||||
sa.Column("confidence_score", sa.Float, nullable=False),
|
||||
sa.Column("user_edited", sa.Boolean, nullable=False, server_default=sa.text("false")),
|
||||
sa.Column("user_approved", sa.Boolean, nullable=False, server_default=sa.text("false")),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
sa.CheckConstraint(
|
||||
"node_type IN ('question', 'resolution', 'step', 'section_header', 'warning', 'action')",
|
||||
name="ck_kb_import_nodes_node_type",
|
||||
),
|
||||
)
|
||||
|
||||
op.create_index("ix_kb_import_nodes_confidence", "kb_import_nodes", ["confidence_score"])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table("kb_import_nodes")
|
||||
op.drop_table("kb_imports")
|
||||
76
backend/alembic/versions/055_add_kb_plan_limits.py
Normal file
76
backend/alembic/versions/055_add_kb_plan_limits.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""add KB Accelerator columns to plan_limits
|
||||
|
||||
Revision ID: 055
|
||||
Revises: 054
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
revision = "055"
|
||||
down_revision = "054"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# Add KB Accelerator columns to plan_limits
|
||||
op.add_column("plan_limits", sa.Column("kb_accelerator_enabled", sa.Boolean, nullable=False, server_default=sa.text("false")))
|
||||
op.add_column("plan_limits", sa.Column("kb_max_lifetime_conversions", sa.Integer, nullable=True))
|
||||
op.add_column("plan_limits", sa.Column("kb_batch_max_size", sa.Integer, nullable=True))
|
||||
op.add_column("plan_limits", sa.Column("kb_allowed_formats", JSONB, nullable=False, server_default=sa.text("'[\"txt\",\"paste\"]'::jsonb")))
|
||||
op.add_column("plan_limits", sa.Column("kb_detailed_analysis", sa.Boolean, nullable=False, server_default=sa.text("false")))
|
||||
op.add_column("plan_limits", sa.Column("kb_conversational_refinement", sa.Boolean, nullable=False, server_default=sa.text("false")))
|
||||
op.add_column("plan_limits", sa.Column("kb_step_library_matching", sa.Boolean, nullable=False, server_default=sa.text("false")))
|
||||
op.add_column("plan_limits", sa.Column("kb_history_limit", sa.Integer, nullable=True))
|
||||
|
||||
# Seed defaults for each plan tier
|
||||
op.execute("""
|
||||
UPDATE plan_limits SET
|
||||
kb_accelerator_enabled = true,
|
||||
kb_max_lifetime_conversions = 3,
|
||||
kb_batch_max_size = NULL,
|
||||
kb_allowed_formats = '["txt","paste"]'::jsonb,
|
||||
kb_detailed_analysis = false,
|
||||
kb_conversational_refinement = false,
|
||||
kb_step_library_matching = false,
|
||||
kb_history_limit = 3
|
||||
WHERE plan = 'free'
|
||||
""")
|
||||
|
||||
op.execute("""
|
||||
UPDATE plan_limits SET
|
||||
kb_accelerator_enabled = true,
|
||||
kb_max_lifetime_conversions = NULL,
|
||||
kb_batch_max_size = 5,
|
||||
kb_allowed_formats = '["txt","paste","docx","pdf","html","md"]'::jsonb,
|
||||
kb_detailed_analysis = true,
|
||||
kb_conversational_refinement = true,
|
||||
kb_step_library_matching = true,
|
||||
kb_history_limit = NULL
|
||||
WHERE plan = 'pro'
|
||||
""")
|
||||
|
||||
op.execute("""
|
||||
UPDATE plan_limits SET
|
||||
kb_accelerator_enabled = true,
|
||||
kb_max_lifetime_conversions = NULL,
|
||||
kb_batch_max_size = 10,
|
||||
kb_allowed_formats = '["txt","paste","docx","pdf","html","md"]'::jsonb,
|
||||
kb_detailed_analysis = true,
|
||||
kb_conversational_refinement = true,
|
||||
kb_step_library_matching = true,
|
||||
kb_history_limit = NULL
|
||||
WHERE plan = 'team'
|
||||
""")
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column("plan_limits", "kb_history_limit")
|
||||
op.drop_column("plan_limits", "kb_step_library_matching")
|
||||
op.drop_column("plan_limits", "kb_conversational_refinement")
|
||||
op.drop_column("plan_limits", "kb_detailed_analysis")
|
||||
op.drop_column("plan_limits", "kb_allowed_formats")
|
||||
op.drop_column("plan_limits", "kb_batch_max_size")
|
||||
op.drop_column("plan_limits", "kb_max_lifetime_conversions")
|
||||
op.drop_column("plan_limits", "kb_accelerator_enabled")
|
||||
Reference in New Issue
Block a user