Browse Source

chore: backup

SudoUserReal 1 month ago
parent
commit
44f3730417

+ 14 - 0
ecosystem/semi-mcp/.gitignore

@@ -0,0 +1,14 @@
+# Local
+.DS_Store
+*.local
+*.log*
+
+# Dist
+node_modules
+dist/
+storybook-static
+
+# IDE
+.vscode/*
+!.vscode/extensions.json
+.idea

+ 20 - 0
ecosystem/semi-mcp/AGENTS.md

@@ -0,0 +1,20 @@
+# AGENTS.md
+
+You are an expert in JavaScript, Rspack, Rsbuild, Rslib, and library development. You write maintainable, performant, and accessible code.
+
+## Commands
+
+- `npm run build` - Build the library for production
+- `npm run dev` - Turn on watch mode, watch for changes and rebuild the library
+
+## Docs
+
+- Rslib: https://rslib.rs/llms.txt
+- Rsbuild: https://rsbuild.rs/llms.txt
+- Rspack: https://rspack.rs/llms.txt
+
+## Tools
+
+### Rstest
+
+- Run `npm run test` to test your code

+ 59 - 0
ecosystem/semi-mcp/README.md

@@ -0,0 +1,59 @@
+# Semi MCP Server
+
+基于 Model Context Protocol (MCP) SDK 实现的 MCP 服务器,使用 stdio 作为传输层。
+
+## 安装
+
+```bash
+npm install
+```
+
+## 构建
+
+构建项目:
+
+```bash
+npm run build
+```
+
+开发模式(监听文件变化):
+
+```bash
+npm run dev
+```
+
+## 运行
+
+构建完成后运行服务器:
+
+```bash
+npm start
+```
+
+或者直接运行构建后的文件:
+
+```bash
+node dist/index.js
+```
+
+## 功能
+
+当前实现的功能包括:
+
+- **工具 (Tools)**
+  - `semi_component_info`: 获取 Semi Design 组件信息
+
+- **资源 (Resources)**
+  - `semi://components`: Semi Design 组件列表资源
+
+## 使用方式
+
+MCP 服务器通过 stdio(标准输入/输出)进行通信,适用于与支持 MCP 协议的客户端集成。
+
+## 开发
+
+项目使用 TypeScript 和 Rslib 构建工具。
+
+- `npm run build` - 构建生产版本
+- `npm run dev` - 开发模式,监听文件变化并自动重建
+- `npm run test` - 运行测试

+ 31 - 0
ecosystem/semi-mcp/package.json

@@ -0,0 +1,31 @@
+{
+  "name": "semi-mcp",
+  "version": "0.0.0",
+  "type": "module",
+  "exports": {
+    ".": {
+      "types": "./dist/index.d.ts",
+      "import": "./dist/index.js"
+    }
+  },
+  "types": "./dist/index.d.ts",
+  "files": [
+    "dist"
+  ],
+  "scripts": {
+    "build": "rslib build",
+    "dev": "rslib build --watch",
+    "test": "rstest",
+    "start": "node dist/index.js"
+  },
+  "dependencies": {
+    "@modelcontextprotocol/sdk": "^1.0.4"
+  },
+  "devDependencies": {
+    "@rslib/core": "^0.18.5",
+    "@rstest/core": "^0.7.2",
+    "@types/node": "^24.10.4",
+    "tsx": "^4.19.2",
+    "typescript": "^5.9.3"
+  }
+}

+ 11 - 0
ecosystem/semi-mcp/rslib.config.ts

@@ -0,0 +1,11 @@
+import { defineConfig } from '@rslib/core';
+
+export default defineConfig({
+  lib: [
+    {
+      format: 'esm',
+      syntax: ['node 18'],
+      dts: true,
+    },
+  ],
+});

+ 3 - 0
ecosystem/semi-mcp/rstest.config.ts

@@ -0,0 +1,3 @@
+import { defineConfig } from '@rstest/core';
+
+export default defineConfig({});

+ 105 - 0
ecosystem/semi-mcp/src/index.ts

@@ -0,0 +1,105 @@
+#!/usr/bin/env node
+
+import { Server } from '@modelcontextprotocol/sdk/server/index.js';
+import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
+import {
+  CallToolRequestSchema,
+  ListToolsRequestSchema,
+  ListResourcesRequestSchema,
+  ReadResourceRequestSchema,
+} from '@modelcontextprotocol/sdk/types.js';
+import { tools, toolHandlers } from './tools/index.js';
+
+/**
+ * Semi MCP Server
+ * 基于 Model Context Protocol SDK 实现的 MCP 服务器
+ * 使用 stdio 作为传输层
+ */
+async function main() {
+  // 创建 MCP 服务器实例
+  const server = new Server(
+    {
+      name: 'semi-mcp',
+      version: '0.0.0',
+    },
+    {
+      capabilities: {
+        tools: {},
+        resources: {},
+      },
+    }
+  );
+
+  // 注册工具列表处理器
+  server.setRequestHandler(ListToolsRequestSchema, async () => {
+    return {
+      tools,
+    };
+  });
+
+  // 注册工具调用处理器
+  server.setRequestHandler(CallToolRequestSchema, async (request) => {
+    const { name, arguments: args } = request.params;
+
+    const handler = toolHandlers[name];
+    if (!handler) {
+      throw new Error(`未知的工具: ${name}`);
+    }
+
+    return handler(args || {});
+  });
+
+  // 注册资源列表处理器
+  server.setRequestHandler(ListResourcesRequestSchema, async () => {
+    return {
+      resources: [
+        {
+          uri: 'semi://components',
+          name: 'Semi Components',
+          description: 'Semi Design 组件列表',
+          mimeType: 'application/json',
+        },
+      ],
+    };
+  });
+
+  // 注册资源读取处理器
+  server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
+    const { uri } = request.params;
+
+    if (uri === 'semi://components') {
+      return {
+        contents: [
+          {
+            uri,
+            mimeType: 'application/json',
+            text: JSON.stringify(
+              {
+                components: ['Button', 'Input', 'Select', 'Table', 'Form'],
+                description: 'Semi Design 组件列表',
+              },
+              null,
+              2
+            ),
+          },
+        ],
+      };
+    }
+
+    throw new Error(`未知的资源 URI: ${uri}`);
+  });
+
+  // 创建 stdio 传输层
+  const transport = new StdioServerTransport();
+
+  // 连接服务器到传输层
+  await server.connect(transport);
+
+  console.error('Semi MCP Server 已启动,使用 stdio 传输');
+}
+
+// 启动服务器
+main().catch((error) => {
+  console.error('服务器启动失败:', error);
+  process.exit(1);
+});

+ 18 - 0
ecosystem/semi-mcp/src/tools/index.ts

@@ -0,0 +1,18 @@
+import { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
+import { semiComponentInfoTool, handleSemiComponentInfo } from './semi-component-info.js';
+
+/**
+ * 所有工具的定义
+ */
+export const tools: Tool[] = [semiComponentInfoTool];
+
+/**
+ * 工具名称到处理器的映射
+ */
+export const toolHandlers: Record<
+  string,
+  (args: Record<string, unknown>) => Promise<CallToolResult>
+> = {
+  [semiComponentInfoTool.name]: handleSemiComponentInfo,
+};
+

+ 44 - 0
ecosystem/semi-mcp/src/tools/semi-component-info.ts

@@ -0,0 +1,44 @@
+import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
+
+import { Tool } from '@modelcontextprotocol/sdk/types.js';
+
+/**
+ * 工具定义:获取 Semi Design 组件信息
+ */
+export const semiComponentInfoTool: Tool = {
+  name: 'semi_component_info',
+  description: '获取 Semi Design 组件信息',
+  inputSchema: {
+    type: 'object',
+    properties: {
+      componentName: {
+        type: 'string',
+        description: '组件名称,例如 Button、Input 等',
+      },
+    },
+    required: ['componentName'],
+  },
+};
+
+/**
+ * 工具处理器:处理 semi_component_info 工具调用
+ */
+export async function handleSemiComponentInfo(
+  args: Record<string, unknown>
+): Promise<CallToolResult> {
+  const componentName = args?.componentName as string;
+
+  if (!componentName) {
+    throw new Error('组件名称是必需的');
+  }
+
+  return {
+    content: [
+      {
+        type: 'text',
+        text: `Semi Design 组件 "${componentName}" 的信息已获取。这是一个示例实现,你可以根据需要扩展功能。`,
+      },
+    ],
+  };
+}
+

+ 39 - 0
ecosystem/semi-mcp/tests/semi-component-info.test.ts

@@ -0,0 +1,39 @@
+import { expect, test } from '@rstest/core';
+import { handleSemiComponentInfo } from '../src/tools/semi-component-info.js';
+
+test('semi_component_info: 正常获取 Button 组件信息', async () => {
+  const result = await handleSemiComponentInfo({
+    componentName: 'Button',
+  });
+
+  expect(result).toBeDefined();
+  expect(result.content).toBeDefined();
+  expect(result.content.length).toBeGreaterThan(0);
+  expect(result.content[0].type).toBe('text');
+  expect(result.content[0].text).toContain('Button');
+});
+
+test('semi_component_info: 正常获取 Input 组件信息', async () => {
+  const result = await handleSemiComponentInfo({
+    componentName: 'Input',
+  });
+
+  expect(result).toBeDefined();
+  expect(result.content).toBeDefined();
+  expect(result.content.length).toBeGreaterThan(0);
+  expect(result.content[0].type).toBe('text');
+  expect(result.content[0].text).toContain('Input');
+});
+
+test('semi_component_info: 缺少 componentName 参数应该抛出错误', async () => {
+  await expect(handleSemiComponentInfo({})).rejects.toThrow('组件名称是必需的');
+});
+
+test('semi_component_info: 空字符串 componentName 应该抛出错误', async () => {
+  await expect(
+    handleSemiComponentInfo({
+      componentName: '',
+    })
+  ).rejects.toThrow('组件名称是必需的');
+});
+

+ 15 - 0
ecosystem/semi-mcp/tsconfig.json

@@ -0,0 +1,15 @@
+{
+  "compilerOptions": {
+    "lib": ["ES2022"],
+    "module": "ESNext",
+    "noEmit": true,
+    "strict": true,
+    "skipLibCheck": true,
+    "isolatedModules": true,
+    "resolveJsonModule": true,
+    "moduleResolution": "bundler",
+    "useDefineForClassFields": true,
+    "allowImportingTsExtensions": true
+  },
+  "include": ["src"]
+}

+ 0 - 1
packages/semi-foundation/aiChatInput/aiChatInput.scss

@@ -523,7 +523,6 @@ $module: #{$prefix}-aiChatInput;
     
             .input-slot {
                 display: inline-block;
-                box-sizing: content-box;
                 background-color: $color-aiChatInput_rich_text-input_slot-bg;
                 border-radius: $radius-aiChatInput_rich_text-input_slot;
                 padding: $spacing-aiChatInput_rich_text-input_slot-paddingY $spacing-aiChatInput_rich_text-input_slot-paddingX;