Skip to main content

路径

GET /thread/:threadId/current-task 公网入口 https://agentapi.kira.art/thread/:threadId/current-task 前端打开 / 刷新 thread 时调用:若有正在跑的 task,可直接续连其 GET /stream/:taskId

认证

eitherAuth()Authorization: Bearer <Supabase JWT>X-Internal-Key: <INTERNAL_KEY>。命中 task 后校验 task.userId === jwtPayload.sub,不匹配返 403

请求

无 body。threadId 走路径参数。

响应

agent:lock:{threadId} 锁值解析出现役 taskId,再 getTask
{
  task: {
    taskId: string,
    threadId: string,
    status: "running" | "completed" | "failed",
    startedAt: number,     // epoch ms
    userMessage: {         // run 期间用户消息未 upsert DB,刷新时前端拼回末尾
      id: string,
      role: string,
      parts: any[]
    }
  }
}
这是「查询当前状态」而非「取唯一资源」:没有 in-flight task 也是合法状态,返回 200 { task: null } 而不是 404。这样基于 status_code >= 4xx 的 alert 不会被污染。无锁、锁值无 taskId、或 task HASH 已 TTL 过期,三种情况都返 200 { task: null }

状态码

含义
200返回 { task: {...} }{ task: null }
401缺少有效 JWT / jwtPayload.sub
403命中的 task 属于其他用户

示例

curl https://agentapi.kira.art/thread/22222222-2222-2222-2222-222222222222/current-task \
  -H "Authorization: Bearer $SUPABASE_JWT"
# → 200 { "task": null }
# 或
# → 200 { "task": { "taskId": "...", "threadId": "...", "status": "running", "startedAt": 1759500000000, "userMessage": {...} } }

src/hono/agent/index.ts:435

相关