Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

959 B
Raw Blame
import debug from 'debug';
import type { Context } from 'hono';

import { runHeartbeatTick } from '@/server/services/taskRunner/heartbeatTick';

const log = debug('lobe-server:workflows:task:heartbeat-tick');

export interface HeartbeatTickPayload {
  taskId: string;
  tickToken?: string;
  userId: string;
}

export async function heartbeatTick(c: Context) {
  try {
    const body = (await c.req.json()) as HeartbeatTickPayload;
    const { taskId, tickToken, userId } = body;
    if (!taskId || !userId) {
      return c.json({ error: 'Missing required fields: taskId, userId' }, 400);
    }

    log('Received tick: taskId=%s userId=%s', taskId, userId);
    const outcome = await runHeartbeatTick(taskId, userId, tickToken);
    return c.json({ success: true, ...outcome });
  } catch (error) {
    console.error('[task/heartbeat-tick] Error:', error);
    return c.json({ error: error instanceof Error ? error.message : 'Internal error' }, 500);
  }
}