chore: 初始版本提交 - 简化架构 + 轮询改造
- 移除 Motia Streams 实时通信,改用 3 秒轮询 - 简化前端代码,移除冗余组件 - 简化后端架构,准备 FastAPI 重构 - 更新 pixi.toml 环境配置 - 保留 bttoxin_digger_v5_repro 作为参考文档 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
62
motia-backend/streams/taskLog.ts
Normal file
62
motia-backend/streams/taskLog.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* TaskLog Stream Definition
|
||||
*
|
||||
* Manages log entries for each task execution.
|
||||
* Uses sessionId as groupId for per-task log isolation.
|
||||
* Retains recent N entries for state recovery.
|
||||
*
|
||||
* @see Requirements 4.2, 4.6
|
||||
*/
|
||||
|
||||
import { defineStream } from '@motia/core'
|
||||
import { z } from 'zod'
|
||||
import type { StepId } from './taskState'
|
||||
|
||||
// Log level enum
|
||||
export const LogLevelSchema = z.enum(['INFO', 'WARN', 'ERROR'])
|
||||
export type LogLevel = z.infer<typeof LogLevelSchema>
|
||||
|
||||
// Task log entry schema
|
||||
export const TaskLogEntrySchema = z.object({
|
||||
sessionId: z.string(),
|
||||
stepId: z.string(), // StepId type
|
||||
ts: z.string(), // ISO timestamp
|
||||
level: LogLevelSchema,
|
||||
message: z.string(),
|
||||
seq: z.number(), // Log sequence number for ordering
|
||||
})
|
||||
export type TaskLogEntry = z.infer<typeof TaskLogEntrySchema>
|
||||
|
||||
// Maximum number of log entries to retain per task
|
||||
export const MAX_LOG_ENTRIES = 1000
|
||||
|
||||
/**
|
||||
* Create a new log entry
|
||||
*/
|
||||
export function createLogEntry(
|
||||
sessionId: string,
|
||||
stepId: StepId,
|
||||
level: LogLevel,
|
||||
message: string,
|
||||
seq: number
|
||||
): TaskLogEntry {
|
||||
return {
|
||||
sessionId,
|
||||
stepId,
|
||||
ts: new Date().toISOString(),
|
||||
level,
|
||||
message,
|
||||
seq,
|
||||
}
|
||||
}
|
||||
|
||||
// Define the taskLog stream
|
||||
export const taskLogStream = defineStream({
|
||||
name: 'taskLog',
|
||||
schema: TaskLogEntrySchema,
|
||||
persistence: {
|
||||
enabled: true,
|
||||
// Retain recent entries for state recovery
|
||||
maxEntries: MAX_LOG_ENTRIES,
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user