skill.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. from typing import TYPE_CHECKING
  2. from pydantic import BaseModel, Field
  3. from core_domain import (
  4. SkillDefinitionContract,
  5. SkillInstallationContract,
  6. SkillInstallStatus,
  7. SkillRunContract,
  8. SkillStatus,
  9. SkillVersionContract,
  10. SkillVersionStatus,
  11. )
  12. from core_shared import JSONValue
  13. if TYPE_CHECKING:
  14. from app.db.models import SkillDefinition, SkillInstallation, SkillRun, SkillVersion
  15. class SkillCreateRequest(BaseModel):
  16. tenant_id: str
  17. code: str
  18. name: str
  19. skill_type: str = "template"
  20. description: str | None = None
  21. owner_user_id: str | None = None
  22. metadata_json: dict[str, JSONValue] = Field(default_factory=dict)
  23. class SkillStatusUpdateRequest(BaseModel):
  24. tenant_id: str
  25. status: SkillStatus
  26. class SkillResponse(SkillDefinitionContract):
  27. @classmethod
  28. def from_entity(cls, entity: "SkillDefinition") -> "SkillResponse":
  29. return cls.model_validate(entity, from_attributes=True)
  30. class SkillVersionCreateRequest(BaseModel):
  31. tenant_id: str
  32. skill_id: str
  33. status: SkillVersionStatus = "draft"
  34. runtime_type: str = "template"
  35. entrypoint: str | None = None
  36. parameter_schema_json: dict[str, JSONValue] = Field(default_factory=dict)
  37. output_schema_json: dict[str, JSONValue] = Field(default_factory=dict)
  38. implementation_json: dict[str, JSONValue] = Field(default_factory=dict)
  39. class SkillVersionResponse(SkillVersionContract):
  40. @classmethod
  41. def from_entity(cls, entity: "SkillVersion") -> "SkillVersionResponse":
  42. return cls.model_validate(entity, from_attributes=True)
  43. class SkillInstallRequest(BaseModel):
  44. tenant_id: str
  45. skill_id: str
  46. skill_version_id: str | None = None
  47. install_scope: str = "tenant"
  48. scope_id: str
  49. config_json: dict[str, JSONValue] = Field(default_factory=dict)
  50. installed_by: str | None = None
  51. class SkillInstallationStatusUpdateRequest(BaseModel):
  52. tenant_id: str
  53. status: SkillInstallStatus
  54. class SkillInstallationResponse(SkillInstallationContract):
  55. @classmethod
  56. def from_entity(cls, entity: "SkillInstallation") -> "SkillInstallationResponse":
  57. return cls.model_validate(entity, from_attributes=True)
  58. class SkillRunCreateRequest(BaseModel):
  59. tenant_id: str
  60. skill_id: str
  61. skill_version_id: str | None = None
  62. installation_id: str | None = None
  63. input_json: dict[str, JSONValue] = Field(default_factory=dict)
  64. class SkillRunExecuteRequest(BaseModel):
  65. tenant_id: str
  66. worker_key: str | None = None
  67. class SkillRunResponse(SkillRunContract):
  68. @classmethod
  69. def from_entity(cls, entity: "SkillRun") -> "SkillRunResponse":
  70. return cls.model_validate(entity, from_attributes=True)