File size: 4,006 Bytes
99caad5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Persistent organization and constrained executable skill catalog."""
from sqlalchemy import String, Integer, JSON, Text, ForeignKeyConstraint
from sqlalchemy.orm import Mapped, mapped_column
from KnowledgeService.models import Base

class Employee(Base):
    __tablename__='org_employee'
    tenant:Mapped[str]=mapped_column(String(80),primary_key=True)
    user_id:Mapped[str]=mapped_column(String(80),primary_key=True)
    name:Mapped[str]=mapped_column(String(120))
    status:Mapped[str]=mapped_column(String(24),default='enabled')

class Group(Base):
    __tablename__='org_group'
    tenant:Mapped[str]=mapped_column(String(80),primary_key=True)
    id:Mapped[str]=mapped_column(String(80),primary_key=True)
    name:Mapped[str]=mapped_column(String(120))
    description:Mapped[str]=mapped_column(Text,default='')
    revision:Mapped[int]=mapped_column(Integer,default=1)

class Membership(Base):
    __tablename__='org_membership'
    tenant:Mapped[str]=mapped_column(String(80),primary_key=True)
    group_id:Mapped[str]=mapped_column(String(80),primary_key=True)
    user_id:Mapped[str]=mapped_column(String(80),primary_key=True)
    role:Mapped[str]=mapped_column(String(24),default='member')
    __table_args__=(ForeignKeyConstraint(['tenant','group_id'],['org_group.tenant','org_group.id']),
                    ForeignKeyConstraint(['tenant','user_id'],['org_employee.tenant','org_employee.user_id']))

class GroupGrant(Base):
    __tablename__='org_group_kb_grant'
    tenant:Mapped[str]=mapped_column(String(80),primary_key=True)
    group_id:Mapped[str]=mapped_column(String(80),primary_key=True)
    base_id:Mapped[str]=mapped_column(String(80),primary_key=True)
    __table_args__=(ForeignKeyConstraint(['tenant','group_id'],['org_group.tenant','org_group.id']),
                    ForeignKeyConstraint(['tenant','base_id'],['kb_base.tenant','kb_base.id']))

class OrganizationAudit(Base):
    __tablename__='org_audit'
    id:Mapped[str]=mapped_column(String(80),primary_key=True)
    tenant:Mapped[str]=mapped_column(String(80),index=True)
    actor:Mapped[str]=mapped_column(String(80))
    group_id:Mapped[str]=mapped_column(String(80))
    action:Mapped[str]=mapped_column(String(40))
    detail:Mapped[dict]=mapped_column(JSON)
    created_at:Mapped[str]=mapped_column(String(40))

class Program(Base):
    __tablename__='skill_program'
    id:Mapped[str]=mapped_column(String(80),primary_key=True)
    tenant:Mapped[str]=mapped_column(String(80),index=True)
    owner:Mapped[str]=mapped_column(String(80),index=True)
    workspace:Mapped[str]=mapped_column(String(80),index=True)
    request_key:Mapped[str]=mapped_column(String(128))
    fingerprint:Mapped[str]=mapped_column(String(64))
    name:Mapped[str]=mapped_column(String(120))
    description:Mapped[str]=mapped_column(Text)
    code:Mapped[str]=mapped_column(Text)
    tests:Mapped[list]=mapped_column(JSON)
    report:Mapped[dict]=mapped_column(JSON)
    status:Mapped[str]=mapped_column(String(24),default='draft')
    revision:Mapped[int]=mapped_column(Integer,default=1)
    operation_id:Mapped[str|None]=mapped_column(String(80))
    created_at:Mapped[str]=mapped_column(String(40))

class PromptSkill(Base):
    __tablename__='skill_prompt'
    tenant:Mapped[str]=mapped_column(String(80),primary_key=True)
    id:Mapped[str]=mapped_column(String(80),primary_key=True)
    owner:Mapped[str]=mapped_column(String(80))
    revision:Mapped[int]=mapped_column(Integer)
    body:Mapped[dict]=mapped_column(JSON)

class PromptSkillVersion(Base):
    __tablename__='skill_prompt_version'
    tenant:Mapped[str]=mapped_column(String(80),primary_key=True)
    skill_id:Mapped[str]=mapped_column(String(80),primary_key=True)
    version:Mapped[int]=mapped_column(Integer,primary_key=True)
    body:Mapped[dict]=mapped_column(JSON)
    __table_args__=(ForeignKeyConstraint(['tenant','skill_id'],['skill_prompt.tenant','skill_prompt.id']),)