- 移除 Motia Streams 实时通信,改用 3 秒轮询 - 简化前端代码,移除冗余组件 - 简化后端架构,准备 FastAPI 重构 - 更新 pixi.toml 环境配置 - 保留 bttoxin_digger_v5_repro 作为参考文档 Co-Authored-By: Claude <noreply@anthropic.com>
63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
/**
|
|
* 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,
|
|
},
|
|
})
|