# LambdaCLI **Repository Path**: hrx-open-platform/lambda-cli ## Basic Information - **Project Name**: LambdaCLI - **Description**: A CLI tool with MCP (Model Context Protocol) server integration, designed to be called by AI Agents and to remotely invoke REST APIs. - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2026-04-14 - **Last Updated**: 2026-04-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OmniCLI v0.5.0 - 完整功能文档 > **版本**: 0.5.0 > **日期**: 2026-04-14 --- ## 目录 - [功能概览](#功能概览) - [CLI 命令清单](#cli-命令清单) - [核心模块](#核心模块) - [编程接口](#编程接口) - [MCP 服务器 API](#mcp-服务器-api) - [配置文件](#配置文件) - [安装和使用](#安装和使用) --- ## 功能概览 OmniCLI 是一个功能完整的 **AI 智能支配平台**,从 API 桥接工具演进而来: | 版本 | 阶段 | 核心功能 | |------|------|----------| | v0.2.0 | Phase 1A | 基础巩固 - 配置管理、Auth、MCP | | v0.3.0 | Phase 1B-2 | MVP + 智能化 - 测试、文档、历史、智能建议 | | v0.4.0 | Phase 3 | 生态系统 - 插件、模板、CI/CD、知识库 | | v0.5.0 | Phase 4 | AI 深度集成 - 监控、工作流、LLM | --- ## CLI 命令清单 ### 1. API 管理 (api) | 命令 | 描述 | 示例 | |------|------|------| | `api:list` | 列出所有配置的端点 | `omni api list` | | `api:call` | 调用 API 端点 | `omni api call --endpoint jsonplaceholder --method GET --path /posts/1` | **参数**: - `--endpoint, -e` - 端点 ID (必需) - `--method, -m` - HTTP 方法 (GET/POST/PUT/DELETE) - `--path, -p` - API 路径 (必需) - `--data, -d` - JSON 请求体 --- ### 2. 认证 (auth) | 命令 | 描述 | 示例 | |------|------|------| | `auth:login` | 存储 API Token | `omni auth login --endpoint-id myapi --token your-secret-token` | | `auth:logout` | 删除 Token | `omni auth logout --endpoint-id myapi` | --- ### 3. 配置管理 (config) | 命令 | 描述 | 示例 | |------|------|------| | `config:add-endpoint` | 添加新端点 | `omni config add-endpoint --id myapi --name "My API" --url https://api.example.com --auth-type api-key` | | `config:list` | 列出所有端点 | `omni config list` | --- ### 4. MCP 服务器 (mcp) | 命令 | 描述 | 示例 | |------|------|------| | `mcp:start` | 启动 MCP 服务器 | `omni mcp start` 或 `omni mcp start --port 3001` | **参数**: - `--port` - 服务器端口 (默认: 3000) --- ### 5. OpenAPI 导入 (import) | 命令 | 描述 | 示例 | |------|------|------| | `import:openapi` | 导入 OpenAPI 3.0 规范 | `omni import openapi ./openapi.json` 或 `omni import openapi https://api.example.com/openapi.json --name "My API"` | --- ### 6. Mock 服务器 (mock) | 命令 | 描述 | 示例 | |------|------|------| | `mock:start` | 启动 Mock 服务器 | `omni mock start --spec ./openapi.json --port 8080` | **参数**: - `--spec` - OpenAPI 规范文件或 URL (必需) - `--port` - 端口 (默认: 8080) --- ### 7. 请求历史 (history) | 命令 | 描述 | 示例 | |------|------|------| | `history:list` | 列出历史记录 | `omni history list --limit 10 --endpoint jsonplaceholder` | | `history:show` | 显示历史详情 | `omni history show ` | | `history:replay` | 重放历史请求 | `omni history replay ` | | `history:search` | 搜索历史 | `omni history search "error" --status 5xx` | | `history:stats` | 使用统计 | `omni history stats --endpoint myapi` | **参数**: - `--limit` - 限制数量 - `--endpoint` - 按端点筛选 - `--method` - 按方法筛选 - `--status` - 按状态码筛选 (如 200, 4xx, 5xx) - `--path` - 按路径筛选 - `--verbose` - 显示完整响应体 --- ### 8. 测试套件 (test) | 命令 | 描述 | 示例 | |------|------|------| | `test:init` | 从 OpenAPI 初始化测试套件 | `omni test init ./openapi.json` | | `test:generate` | 为端点生成测试 | `omni test generate get-users` | | `test:run` | 运行所有测试 | `omni test run` | --- ### 9. 文档生成 (doc) | 命令 | 描述 | 示例 | |------|------|------| | `doc:generate` | 生成 Markdown API 文档 | `omni doc generate --spec ./openapi.json --output ./api-docs.md` | **参数**: - `--spec, -s` - OpenAPI 规范 (必需) - `--output, -o` - 输出文件 (默认: ./api-docs.md) --- ### 10. 配置模板 (template) | 命令 | 描述 | 示例 | |------|------|------| | `template:list` | 列出可用模板 | `omni template list` | | `template:apply` | 应用模板 | `omni template apply rest-api --name MyAPI` | **内置模板**: - `minimal` - 最小配置 - `rest-api` - 标准 REST API - `oauth2-api` - OAuth2 保护 API - `full-stack` - 多环境 --- ### 11. CI/CD 集成 (cicd) | 命令 | 描述 | 示例 | |------|------|------| | `cicd:generate` | 生成 GitHub Actions 工作流 | `omni cicd generate --workflow test --project-name MyProject --test-command "npm test" --secrets SECRET1,SECRET2 --deploy` | **参数**: - `--workflow` - 工作流类型 (test) - `--project-name` - 项目名称 - `--test-command` - 测试命令 - `--node-version` - Node 版本 (默认: 18.x) - `--secrets` - 密钥列表 - `--deploy` - 包含部署步骤 --- ### 12. 知识库 (kb) | 命令 | 描述 | 示例 | |------|------|------| | `kb:list` | 列出知识条目 | `omni kb list` 或 `omni kb list --category auth` | | `kb:search` | 搜索知识库 | `omni kb search OAuth2` | | `kb:show` | 显示条目详情 | `omni kb show kb-oauth2-setup` | **内置类别**: auth, testing, performance, security, debugging, workflow --- ### 13. 工作流 (workflow) | 命令 | 描述 | 示例 | |------|------|------| | `workflow:list` | 列出工作流 | `omni workflow list` | | `workflow:run` | 运行工作流 | `omni workflow run --input key=value` | --- ### 14. AI/LLM 集成 (ai) | 命令 | 描述 | 示例 | |------|------|------| | `ai:config` | 配置 LLM Provider | `omni ai config --provider openai --api-key --model gpt-4` | | `ai:chat` | 交互式聊天 | `omni ai chat "Hello, how can you help?"` | **Provider**: openai, anthropic, local, custom --- ### 15. 监控 (monitor) | 命令 | 描述 | 示例 | |------|------|------| | `monitor:health` | 端点健康检查 | `omni monitor health --endpoint myapi` | | `monitor:metrics` | 查看指标 | `omni monitor metrics --endpoint myapi` | | `monitor:sla` | SLA 追踪 | `omni monitor sla --endpoint myapi` | --- ### 16. 其他 | 命令 | 描述 | 示例 | |------|------|------| | `suggest` | 智能操作建议 | `omni suggest` | | `hello` | 测试命令 | `omni hello` | --- ## 核心模块 ### src/api/client.ts ```typescript // API 客户端 - 发起 REST 请求 export class APIClient { constructor(endpoint: EndPoint, token?: string) get(path: string): Promise post(path: string, data?: unknown): Promise put(path: string, data?: unknown): Promise delete(path: string): Promise updateToken(token: string): void } ``` ### src/config/index.ts ```typescript // 配置管理器 - 持久化配置 export class ConfigManager { constructor(configPath?: string) addEndpoint(endpoint: EndPoint): void getEndpoint(id: string): EndPoint | undefined listEndpoints(): EndPoint[] removeEndpoint(id: string): void setToken(endpointId: string, token: string): void getToken(endpointId: string): string | undefined removeToken(endpointId: string): void } ``` ### src/history/store.ts ```typescript // 历史存储 - JSONL 持久化 export class HistoryStore { record(entry: Omit): HistoryEntry list(query?: HistoryQuery): HistoryEntry[] get(id: string): HistoryEntry | undefined clear(): void } ``` ### src/mcp/server.ts ```typescript // MCP 服务器 - JSON-RPC 2.0 export class MCPServer { constructor(options?: { port?: number; host?: string }) start(): Promise stop(): Promise } ``` ### src/openapi/parser.ts ```typescript // OpenAPI 解析器 export function loadSpec(source: string): Promise export function parseOpenAPISpec(jsonString: string): ParsedSpec ``` ### src/testing/runner.ts ```typescript // 测试运行器 export async function runTests( cases: TestCase[], configManager: ConfigManager ): Promise ``` ### src/doc/generator.ts ```typescript // 文档生成器 export function generateMarkdown(spec: ParsedSpec): string export async function generateAndSave(specSource: string, outputPath: string): Promise ``` ### src/templates/manager.ts ```typescript // 模板管理器 export class TemplateManager { list(): ConfigTemplate[] get(id: string): ConfigTemplate | undefined apply(id: string, options?: ApplyOptions): Promise } ``` ### src/workflow/engine.ts ```typescript // 工作流引擎 export function listWorkflows(): Workflow[] export async function runWorkflow(id: string, inputs?: Record): Promise ``` ### src/ai/providers.ts ```typescript // LLM Provider 工厂 export function createProvider(config: LLMConfig): LLMProvider // Provider 类 class OpenAIProvider extends LLMProvider { ... } class AnthropicProvider extends LLMProvider { ... } class LocalProvider extends LLMProvider { ... } ``` --- ## MCP 服务器 API MCP 服务器提供 JSON-RPC 2.0 接口供 AI Agent 调用。 ### 端点 - **URL**: `http://localhost:3000` (默认) - **Content-Type**: `application/json` ### 方法 | 方法 | 描述 | 参数 | |------|------|------| | `initialize` | 初始化 MCP 连接 | `protocolVersion`, `capabilities`, `clientInfo` | | `ping` | 健康检查 | - | | `callEndpoint` | 调用 API 端点 | `endpoint`, `method`, `payload` | | `listEndpoints` | 列出端点 | - | | `setToken` | 存储 Token | `token`, `endpointId?` | | `getToken` | 获取 Token | `endpointId?` | ### 示例请求 ```bash # Ping curl -X POST http://localhost:3000 \ -H "Content-Type: application/json" \ -d '{"jsonrpc": "2.0", "id": 1, "method": "ping"}' # Call Endpoint curl -X POST http://localhost:3000 \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 2, "method": "callEndpoint", "params": { "endpoint": "jsonplaceholder", "method": "GET", "payload": { "path": "/posts/1" } } }' ``` --- ## 配置文件 ### 位置 - **Windows**: `C:\Users\\.omni\omni.config.json` - **Linux/macOS**: `~/.omni/omni.config.json` ### 格式 ```json { "version": "0.5.0", "endpoints": [ { "id": "jsonplaceholder", "name": "JSONPlaceholder API", "baseURL": "https://jsonplaceholder.typicode.com", "authType": "api-key" } ], "auth": { "tokens": { "jsonplaceholder": "stored-token" } }, "mcp": { "enabled": true, "port": 3000 } } ``` --- ## 安装和使用 ### 从源码构建 ```bash # 克隆仓库 git clone cd OmniCLI # 安装依赖 npm install # 构建 npm run build # 开发模式 npm run dev # 测试 npm run test # 列出所有命令 omni --help ``` ### 快速开始 ```bash # 1. 添加端点 omni config add-endpoint --id jsonplaceholder --name "JSONPlaceholder" --url https://jsonplaceholder.typicode.com --auth-type api-key # 2. 列出端点 omni api list # 3. 调用 API omni api call --endpoint jsonplaceholder --method GET --path /posts/1 # 4. 查看历史 omni history list # 5. 启动 MCP 服务器 omni mcp start ``` --- ## 版本历史 | 版本 | 日期 | 变更 | |------|------|------| | v0.2.0 | 2026-04-14 | 初始版本 - 基础功能 | | v0.3.0 | 2026-04-14 | 测试套件、文档生成、历史、智能建议 | | v0.4.0 | 2026-04-14 | 插件、模板、CI/CD、知识库 | | v0.5.0 | 2026-04-14 | 监控、工作流、AI/LLM 集成 | --- ## 许可证 MIT