Skip to content

Commit 13b8940

Browse files
committed
feat(interactive): add empty state for environment selection with create environment button 🚀
1 parent e1cda29 commit 13b8940

3 files changed

Lines changed: 90 additions & 11 deletions

File tree

mcp/src/interactive-server.ts

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,58 @@ export class InteractiveServer {
715715
font-size: 14px;
716716
}
717717
718+
.empty-state {
719+
display: flex;
720+
flex-direction: column;
721+
align-items: center;
722+
justify-content: center;
723+
padding: 60px 20px;
724+
text-align: center;
725+
animation: fadeIn 0.8s ease-out;
726+
}
727+
728+
.empty-icon {
729+
margin-bottom: 24px;
730+
color: var(--text-secondary);
731+
opacity: 0.6;
732+
}
733+
734+
.empty-title {
735+
font-size: 20px;
736+
font-weight: 600;
737+
color: var(--text-primary);
738+
margin-bottom: 12px;
739+
}
740+
741+
.empty-message {
742+
font-size: 14px;
743+
color: var(--text-secondary);
744+
line-height: 1.6;
745+
margin-bottom: 32px;
746+
max-width: 400px;
747+
}
748+
749+
.create-env-btn {
750+
padding: 14px 24px;
751+
font-size: 15px;
752+
background: var(--primary-color);
753+
color: var(--text-primary);
754+
border: 1px solid var(--border-color);
755+
border-radius: 8px;
756+
cursor: pointer;
757+
transition: all 0.3s ease;
758+
display: flex;
759+
align-items: center;
760+
gap: 8px;
761+
font-weight: 600;
762+
}
763+
764+
.create-env-btn:hover {
765+
background: var(--primary-hover);
766+
transform: translateY(-2px);
767+
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
768+
}
769+
718770
.actions {
719771
display: flex;
720772
gap: 12px;
@@ -891,17 +943,37 @@ export class InteractiveServer {
891943
<p class="content-subtitle">请选择您要使用的云开发环境</p>
892944
893945
<div class="env-list" id="envList">
894-
${(envs || []).map((env, index) => `
895-
<div class="env-item" onclick="selectEnv('${env.EnvId}', this)" style="animation-delay: ${index * 0.1}s;">
896-
<svg class="env-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
897-
<path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>
898-
</svg>
899-
<div class="env-info">
900-
<div class="env-name">${env.EnvId}</div>
901-
<div class="env-alias">${env.Alias || '无别名'}</div>
946+
${(envs || []).length > 0 ?
947+
(envs || []).map((env, index) => `
948+
<div class="env-item" onclick="selectEnv('${env.EnvId}', this)" style="animation-delay: ${index * 0.1}s;">
949+
<svg class="env-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
950+
<path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>
951+
</svg>
952+
<div class="env-info">
953+
<div class="env-name">${env.EnvId}</div>
954+
<div class="env-alias">${env.Alias || '无别名'}</div>
955+
</div>
956+
</div>
957+
`).join('') :
958+
`
959+
<div class="empty-state">
960+
<div class="empty-icon">
961+
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
962+
<path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>
963+
<path d="M20 6L9 17l-5-5"/>
964+
</svg>
902965
</div>
966+
<h3 class="empty-title">暂无云开发环境</h3>
967+
<p class="empty-message">当前没有可用的云开发 CloudBase 环境,请新建后重新在 AI 对话中重试</p>
968+
<button class="btn btn-primary create-env-btn" onclick="createNewEnv()">
969+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
970+
<path d="M12 5v14M5 12h14"/>
971+
</svg>
972+
新建环境
973+
</button>
903974
</div>
904-
`).join('')}
975+
`
976+
}
905977
</div>
906978
907979
<div class="actions">
@@ -1033,6 +1105,13 @@ export class InteractiveServer {
10331105
});
10341106
}
10351107
1108+
function createNewEnv() {
1109+
const integrationIde = '${process.env.INTEGRATION_IDE || "AI Toolkit"}';
1110+
const url = \`http://tcb.cloud.tencent.com/dev?from=\${encodeURIComponent(integrationIde)}\`;
1111+
console.log('🚀 打开新建环境页面:', url);
1112+
window.open(url, '_blank');
1113+
}
1114+
10361115
function cancel() {
10371116
fetch('/api/cancel', {
10381117
method: 'POST',

mcp/src/tools/interactive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export async function _promptAndSetEnvironmentId(autoSelectSingle: boolean, serv
119119
const cloudbase = await getCloudBaseManager({requireEnvId: false});
120120
const envResult = await cloudbase.env.listEnvs();
121121
debug('envResult', envResult);
122-
if (!envResult || !envResult.EnvList || envResult.EnvList.length === 0) {
122+
if (!envResult || !envResult.EnvList) {
123123
return { selectedEnvId: null, cancelled: false, noEnvs: true };
124124
}
125125

mcp/src/utils/tool-wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function createWrappedHandler(name: string, handler: any, server: ExtendedMcpSer
122122
});
123123

124124
// 生成 GitHub Issue 创建链接
125-
const issueLink = await generateGitHubIssueLink(name, errorMessage, args, cloudBaseOptions);
125+
const issueLink = await generateGitHubIssueLink(name, errorMessage, args, server.cloudBaseOptions);
126126

127127
// 创建增强的错误消息,包含 GitHub Issue 链接
128128
const enhancedErrorMessage = `${errorMessage}\n\n🔗 遇到问题?请复制以下链接到浏览器打开\n即可自动携带错误详情快速创建 GitHub Issue:\n${issueLink}`;

0 commit comments

Comments
 (0)