Files
cnb/agent/routes/cnb-env/vscode.ts
2026-01-29 13:59:18 +08:00

96 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { createSkill, tool } from '@kevisual/router';
import { app, cnb } from '../../app.ts';
import { CNB_ENV } from "@/common/cnb-env.ts";
// 执行技能 get-cnb-port-uri端口为4096
// 执行技能 get-cnb-port-uri端口为51515
// TODO 获取仓库的
app.route({
path: 'cnb',
key: 'get-cnb-port-uri',
description: '获取当前cnb工作空间的port代理uri',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'get-cnb-port-uri',
title: '获取当前cnb工作空间的port代理uri',
summary: '获取当前cnb工作空间的port代理uri用于端口转发',
args: {
port: tool.schema.number().optional().describe('端口号默认为4096'),
}
})
}
}).define(async (ctx) => {
const port = ctx.query?.port || 4096;
const uri = CNB_ENV?.CNB_VSCODE_PROXY_URI as string || '';
const finalUri = uri.replace('{{port}}', port.toString());
let content = `
cnb工作空间的访问uri为${finalUri}
`
ctx.body = { content };
}).addTo(app);
// 获取当前cnb工作空间的vscode代理uri执行技能 get-cnb-vscode-uri
// 包括 web 访问urivscode 访问uricodebuddy 访问uricursor 访问urissh 连接字符串
app.route({
path: 'cnb',
key: 'get-cnb-vscode-uri',
description: '获取当前cnb工作空间的vscode代理uri, 包括多种访问方式, 如web、vscode、codebuddy、cursor、ssh',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'get-cnb-vscode-uri',
title: '获取当前cnb工作空间的编辑器访问地址',
summary: '获取当前cnb工作空间的vscode代理uri用于在浏览器中访问vscode包含多种访问方式如web、vscode、codebuddy、cursor、ssh',
args: {
web: tool.schema.boolean().optional().describe('是否获取vscode web的访问uri默认为false'),
vscode: tool.schema.boolean().optional().describe('是否获取vscode的代理uri默认为true'),
codebuddy: tool.schema.boolean().optional().describe('是否获取codebuddy的代理uri默认为false'),
cursor: tool.schema.boolean().optional().describe('是否获取cursor的代理uri默认为false'),
// trae: tool.schema.boolean().optional().describe('是否获取trae的代理uri默认为false'),
ssh: tool.schema.boolean().optional().describe('是否获取vscode remote ssh的连接字符串默认为false'),
}
})
}
}).define(async (ctx) => {
const web = ctx.query?.web ?? false;
const vscode = ctx.query?.vscode ?? true; // 默认true
const codebuddy = ctx.query?.codebuddy ?? false;
const cursor = ctx.query?.cursor ?? false;
// const trae = ctx.query?.trae ?? false;
const ssh = ctx.query?.ssh ?? false;
const webUri = CNB_ENV?.CNB_VSCODE_WEB_URL as string || '';
const vscodeSchma = CNB_ENV?.CNB_VSCODE_REMOTE_SSH_SCHEMA as string || '';
let content = `
当前的cnb 仓库为:${CNB_ENV?.CNB_REPO_SLUG}
`
if (web) {
content += `VS Code Web 访问 URI${webUri}\n\n`;
}
if (vscode) {
content += `VS Code 访问 URI${vscodeSchma}\n\n`;
}
if (codebuddy) {
const codebuddyUri = vscodeSchma.replace('vscode://vscode-remote/ssh-remote+', 'codebuddycn://vscode-remote/codebuddy-remote');
content += `CodeBuddy 访问 URI${codebuddyUri}\n\n`;
}
if (cursor) {
const cursorUri = vscodeSchma.replace('vscode://', 'cursor://');
content += `Cursor 访问 URI${cursorUri}\n\n`;
}
// if (trae) {
// const traeUri = vscodeSchma.replace('vscode://vscode-remote/ssh-remote+', 'traecn://ssh-remote+');
// content += `Trae 访问 URI${traeUri}\n\n`;
// }
if (ssh) {
content += `VS Code Remote SSH 连接字符串ssh ${CNB_ENV.CNB_PIPELINE_ID}.${CNB_ENV.CNB_VSCODE_SSH_TOKEN}@cnb.space`;
}
ctx.body = { content };
}).addTo(app);