83 lines
2.6 KiB
Protocol Buffer
83 lines
2.6 KiB
Protocol Buffer
syntax = "proto3";
|
||
|
||
package next_edu_cloud.events.v1;
|
||
|
||
// Cross-service event contracts published by CoreEdu via the transactional
|
||
// outbox pattern and consumed by downstream services (notifications, analytics,
|
||
// audit, etc.). Topics follow the convention edu.{domain}.events.
|
||
//
|
||
// Event routing (TOPIC_MAP in outbox.publisher.ts):
|
||
// edu.exam.events <- exam.created / exam.updated / exam.deleted
|
||
// edu.homework.events <- homework.assigned / homework.submitted / homework.graded
|
||
// edu.grade.events <- grade.recorded / grade.updated
|
||
// edu.class.events <- class.transferred
|
||
|
||
message ClassEvent {
|
||
string event_id = 1;
|
||
string aggregate_id = 2;
|
||
string event_type = 3;
|
||
int64 occurred_at = 4;
|
||
string class_id = 5;
|
||
string name = 6;
|
||
string action = 7;
|
||
map<string, string> metadata = 8;
|
||
}
|
||
|
||
message ExamEvent {
|
||
string event_id = 1;
|
||
string aggregate_id = 2;
|
||
string event_type = 3;
|
||
int64 occurred_at = 4;
|
||
string exam_id = 5;
|
||
string class_id = 6;
|
||
string title = 7;
|
||
string action = 8;
|
||
map<string, string> metadata = 9;
|
||
}
|
||
|
||
message HomeworkEvent {
|
||
string event_id = 1;
|
||
string aggregate_id = 2;
|
||
string event_type = 3;
|
||
int64 occurred_at = 4;
|
||
string homework_id = 5;
|
||
string class_id = 6;
|
||
string title = 7;
|
||
string action = 8;
|
||
map<string, string> metadata = 9;
|
||
}
|
||
|
||
message GradeEvent {
|
||
string event_id = 1;
|
||
string aggregate_id = 2;
|
||
string event_type = 3;
|
||
int64 occurred_at = 4;
|
||
string grade_id = 5;
|
||
string student_id = 6;
|
||
string score = 7;
|
||
string action = 8;
|
||
map<string, string> metadata = 9;
|
||
}
|
||
|
||
// AI 用量计费事件(ai 服务发布,data-ana 消费落 ClickHouse)
|
||
// 派生数据,豁免 Outbox(004 §12.2);topic: edu.ai.usage(matrix.md §4 + ISSUE-02 裁决)
|
||
message AIUsageEvent {
|
||
string event_id = 1; // UUID,幂等去重
|
||
string aggregate_id = 2; // workflow_id 或 request_id
|
||
string event_type = 3; // 固定 "AIUsageRecorded"
|
||
int64 occurred_at = 4; // Unix 毫秒时间戳
|
||
string user_id = 5;
|
||
string school_id = 6; // 用于多租户配额
|
||
string request_id = 7; // 链路追踪 ID
|
||
string provider = 8; // openai/anthropic/baichuan/local_ollama
|
||
string model = 9; // gpt-4o-mini/claude-3-haiku/...
|
||
string operation = 10; // chat/generate_question/optimize_expression/lesson_preparation
|
||
uint32 prompt_tokens = 11;
|
||
uint32 completion_tokens = 12;
|
||
uint32 total_tokens = 13;
|
||
uint32 latency_ms = 14;
|
||
bool success = 15;
|
||
bool degraded = 16; // 是否降级(LLM 不可用时)
|
||
map<string, string> metadata = 17; // 额外上下文(subject/grade/difficulty 等)
|
||
}
|