diff --git a/agent/routes/workspace/keep.ts b/agent/routes/workspace/keep.ts index 8ff5a88..4f8cf4f 100644 --- a/agent/routes/workspace/keep.ts +++ b/agent/routes/workspace/keep.ts @@ -30,21 +30,20 @@ app.route({ ctx.throw(401, 'CNB_COOKIE 环境变量无效或已过期,请重新登录获取新的cookie'); } const res = await cnb.workspace.getWorkspaceCookie(repo, pipelineId); - let wsUrl = `wss://${pipelineId}.cnb.space:443?skipWebSocketFrames=false`; - let cookie = ''; - if (res.code === 200) { - cookie = res.data.value; - console.log(`启动保持工作空间 ${wsUrl} 存活的任务`); - } else { - ctx.throw(500, `获取工作空间访问cookie失败: ${res.message}`); + if (res.code !== 200 || !res.data?.cookie) { + ctx.throw(500, `获取工作空间 Cookie 失败: ${res.message}`); } - console.log(`启动保持工作空间 ${wsUrl} 存活的任务`); + // 添加保活数据 + const liveData = createLiveData({ + repo, + pipelineId, + cookie: res.data.cookie + }); + addKeepAliveData(liveData); + console.log('已添加 keep-alive 数据'); - const config: KeepAliveData = createLiveData({ cookie, repo, pipelineId }); - addKeepAliveData(config); - - ctx.body = { content: `已启动保持工作空间 ${wsUrl} 存活的任务`, data: config }; + ctx.body = { content: `已启动保持工作空间 ${repo}/${pipelineId} 存活的任务`, data: liveData }; }).addTo(app); // 停止保持工作空间存活技能 diff --git a/package.json b/package.json index 2e1baae..53b3bda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cnb", - "version": "0.0.36", + "version": "0.0.37", "description": "", "main": "index.js", "scripts": {