diff --git a/config/config.toml b/config/config.toml new file mode 100644 index 0000000..ae736ea --- /dev/null +++ b/config/config.toml @@ -0,0 +1,289 @@ +# ============================================================ +# ZClaw OpenFang Main Configuration +# OpenFang TOML format configuration file +# ============================================================ +# +# Usage: +# 1. Copy this file to ~/.openfang/config.toml +# 2. Set environment variables for API keys +# 3. Import chinese-providers.toml for Chinese LLM support +# +# Environment variables: +# ZHIPU_API_KEY, QWEN_API_KEY, KIMI_API_KEY, +# MINIMAX_API_KEY, DEEPSEEK_API_KEY, OPENAI_API_KEY +# ============================================================ + +# ============================================================ +# Server Configuration +# ============================================================ + +[server] +# gRPC server host and port +host = "127.0.0.1" +port = 50051 + +# WebSocket configuration +websocket_port = 50051 +websocket_path = "/ws" + +# CORS settings for desktop client +cors_origins = ["http://localhost:1420", "tauri://localhost"] + +# API version prefix +api_version = "v1" + +# ============================================================ +# Agent Configuration +# ============================================================ + +[agent.defaults] +# Default workspace for agent operations +workspace = "~/.openfang/zclaw-workspace" + +# Default model for new sessions +default_model = "zhipu/glm-4-plus" + +# Fallback models if primary fails +fallback_models = ["qwen/qwen-max", "deepseek/deepseek-chat"] + +# Heartbeat interval for agent health checks +heartbeat_interval = "1h" + +# Session timeout +session_timeout = "24h" + +# Maximum concurrent sessions +max_sessions = 10 + +[agent.defaults.sandbox] +# Sandbox root directory +workspace_root = "~/.openfang/zclaw-workspace" + +# Allowed shell commands (empty = all allowed) +# allowed_commands = ["git", "npm", "pnpm", "cargo"] + +# Enable shell execution +shell_enabled = true + +# Network access in sandbox +network_enabled = true + +[agent.defaults.memory] +# Conversation memory settings +max_history_length = 100 +summarize_threshold = 50 + +# ============================================================ +# Skills Configuration +# ============================================================ + +[skills] +# Additional skill directories to load +extra_dirs = ["./skills"] + +# Enable hot reload for skill development +hot_reload = false + +# Skill execution timeout +execution_timeout = "5m" + +# ============================================================ +# Hands Configuration +# ============================================================ + +[hands] +# Additional hand directories to load +extra_dirs = ["./hands"] + +# Default approval mode: "auto", "manual", "smart" +default_approval_mode = "smart" + +# Hand execution settings +max_concurrent = 5 +execution_timeout = "30m" + +# Audit settings +audit_enabled = true +audit_log_path = "~/.openfang/logs/hands-audit.log" + +# ============================================================ +# LLM Provider Configuration +# ============================================================ + +[llm] +# Default provider settings +default_provider = "zhipu" +default_model = "glm-4-plus" + +# Rate limiting +requests_per_minute = 60 +tokens_per_minute = 100000 + +# Retry settings +max_retries = 3 +retry_delay = "1s" + +# ============================================================ +# Model Aliases +# ============================================================ + +[llm.aliases] +"glm-5" = "zhipu/glm-4-plus" +"qwen3.5" = "qwen/qwen-plus" +"gpt-4" = "openai/gpt-4o" + +# ============================================================ +# Security Configuration +# ============================================================ + +[security] +# Enable all security layers +enabled = true + +# Authentication +[security.auth] +# JWT token expiration +token_expiration = "24h" + +# Ed25519 key settings +key_rotation_interval = "30d" + +# RBAC settings +[security.rbac] +enabled = true +default_role = "user" + +# Rate limiting +[security.rate_limit] +enabled = true +requests_per_second = 10 +burst_size = 20 + +# Audit logging +[security.audit] +enabled = true +log_path = "~/.openfang/logs/audit.log" +log_format = "json" + +# ============================================================ +# Logging Configuration +# ============================================================ + +[logging] +# Log level: "trace", "debug", "info", "warn", "error" +level = "info" + +# Log format: "json", "pretty", "compact" +format = "pretty" + +# Log file settings +[logging.file] +enabled = true +path = "~/.openfang/logs/openfang.log" +max_size = "10MB" +max_files = 5 +compress = true + +# Console logging +[logging.console] +enabled = true +colorize = true + +# ============================================================ +# Channels Configuration (Integrations) +# ============================================================ + +[channels] + +# Feishu (Lark) integration +[channels.feishu] +enabled = false + +[channels.feishu.default] +app_id = "" +app_secret = "" +enabled = false + +# ============================================================ +# Tools Configuration +# ============================================================ + +[tools] + +# Shell execution tool +[tools.exec] +shell_enabled = true +timeout = "30s" + +# Web search tool +[tools.web] +[tools.web.search] +enabled = true +default_engine = "duckduckgo" +max_results = 10 + +# File system tool +[tools.fs] +allowed_paths = ["~/.openfang/zclaw-workspace"] +max_file_size = "10MB" + +# ============================================================ +# Workflow Configuration +# ============================================================ + +[workflow] +# Workflow storage +storage_path = "~/.openfang/workflows" + +# Execution settings +max_steps = 100 +step_timeout = "5m" + +# Trigger settings +[workflow.triggers] +enabled = true +max_scheduled = 50 + +# ============================================================ +# Desktop Client Configuration +# ============================================================ + +[desktop] +# Desktop-specific settings for ZClaw client + +[desktop.ui] +# Theme settings +default_theme = "system" +theme_transition_ms = 200 + +# Animation settings +animations_enabled = true +animation_duration_ms = 300 + +[desktop.connection] +# Connection retry settings +auto_reconnect = true +reconnect_delay_ms = 1000 +max_reconnect_attempts = 5 + +# Connection timeout +connection_timeout_ms = 5000 +request_timeout_ms = 30000 + +# ============================================================ +# Development Settings (for local development only) +# ============================================================ + +[development] +# Enable debug mode +debug = false + +# Verbose logging +verbose = false + +# Mock mode (for testing without real LLM) +mock_llm = false + +# Profiling +profiling_enabled = false +profiling_port = 6060 diff --git a/desktop/src/types/agent.ts b/desktop/src/types/agent.ts new file mode 100644 index 0000000..b6731af --- /dev/null +++ b/desktop/src/types/agent.ts @@ -0,0 +1,67 @@ +/** + * Agent Type Definitions for OpenFang + * + * These types define the Agent entity structure and related configurations + * for the OpenFang desktop client. + */ + +/** + * Represents an Agent instance in OpenFang runtime + */ +export interface Agent { + /** Unique identifier for the agent */ + id: string; + /** Display name of the agent */ + name: string; + /** Current operational status */ + status: AgentStatus; + /** The LLM model being used by this agent */ + model?: string; + /** Path to the agent's workspace directory */ + workspaceDir?: string; + /** ISO timestamp of agent creation */ + createdAt: string; + /** ISO timestamp of last agent update */ + updatedAt?: string; +} + +/** + * Configuration object for creating or updating an Agent + */ +export interface AgentConfig { + /** Display name for the agent */ + name: string; + /** LLM model to use (e.g., 'gpt-4', 'claude-3') */ + model: string; + /** Optional workspace directory path */ + workspace?: string; + /** Optional system prompt for the agent */ + systemPrompt?: string; +} + +/** + * Possible operational states for an Agent + * + * - idle: Agent is not currently processing any tasks + * - running: Agent is actively processing + * - paused: Agent execution is temporarily suspended + * - error: Agent encountered an error and requires attention + */ +export type AgentStatus = 'idle' | 'running' | 'paused' | 'error'; + +/** + * Response structure for agent list API + */ +export interface AgentListResponse { + agents: Agent[]; + total: number; +} + +/** + * Response structure for single agent API + */ +export interface AgentResponse { + agent: Agent; + success: boolean; + error?: string; +} diff --git a/desktop/src/types/index.ts b/desktop/src/types/index.ts new file mode 100644 index 0000000..106a18b --- /dev/null +++ b/desktop/src/types/index.ts @@ -0,0 +1,40 @@ +/** + * OpenFang Type Definitions + * + * This module exports all TypeScript type definitions for the + * OpenFang desktop client application. + * + * @module types + */ + +// Agent Types +export type { + Agent, + AgentConfig, + AgentStatus, + AgentListResponse, + AgentResponse, +} from './agent'; + +// Session Types +export type { + Session, + SessionConfig, + SessionMessage, + MessageRole, + MessageMetadata, + SessionListResponse, + SessionMessagesResponse, + MessageStreamChunk, +} from './session'; + +// Settings Types +export type { + QuickConfig, + MCPService, + ThemeMode, + AppSettings, + SettingsValidationResult, + SettingsValidationError, + SettingsResponse, +} from './settings'; diff --git a/desktop/src/types/session.ts b/desktop/src/types/session.ts new file mode 100644 index 0000000..11ff4b3 --- /dev/null +++ b/desktop/src/types/session.ts @@ -0,0 +1,107 @@ +/** + * Session Type Definitions for OpenFang + * + * These types define the Session and message structures + * for conversation management in the OpenFang desktop client. + */ + +/** + * Represents a conversation session with an Agent + */ +export interface Session { + /** Unique identifier for the session */ + id: string; + /** ID of the agent this session belongs to */ + agentId: string; + /** ISO timestamp of session creation */ + createdAt: string; + /** ISO timestamp of last session update */ + updatedAt?: string; + /** Total number of messages in this session */ + messageCount: number; +} + +/** + * Configuration object for creating a new session + */ +export interface SessionConfig { + /** ID of the agent to associate with this session */ + agentId: string; + /** Optional initial context or metadata */ + context?: Record; +} + +/** + * Represents a single message within a session + */ +export interface SessionMessage { + /** Unique identifier for the message */ + id: string; + /** ID of the session this message belongs to */ + sessionId: string; + /** Role of the message sender */ + role: MessageRole; + /** Text content of the message */ + content: string; + /** ISO timestamp of message creation */ + timestamp: string; + /** Optional metadata (tokens, model info, etc.) */ + metadata?: MessageMetadata; +} + +/** + * Possible roles for a message sender + * + * - user: Message from the human user + * - assistant: Message from the AI agent + * - system: System-level instruction or notification + */ +export type MessageRole = 'user' | 'assistant' | 'system'; + +/** + * Metadata associated with a message + */ +export interface MessageMetadata { + /** Number of tokens used (if applicable) */ + tokens?: number; + /** Model used to generate the response */ + model?: string; + /** Whether this message was a tool call */ + isToolCall?: boolean; + /** Tool call details if applicable */ + toolCall?: { + name: string; + arguments: Record; + result?: unknown; + }; + /** Additional arbitrary metadata */ + [key: string]: unknown; +} + +/** + * Response structure for session list API + */ +export interface SessionListResponse { + sessions: Session[]; + total: number; +} + +/** + * Response structure for session messages API + */ +export interface SessionMessagesResponse { + messages: SessionMessage[]; + sessionId: string; + hasMore: boolean; +} + +/** + * Streaming message chunk for real-time updates + */ +export interface MessageStreamChunk { + sessionId: string; + messageId: string; + delta: string; + done: boolean; + metadata?: MessageMetadata; +} diff --git a/desktop/src/types/settings.ts b/desktop/src/types/settings.ts new file mode 100644 index 0000000..bd16364 --- /dev/null +++ b/desktop/src/types/settings.ts @@ -0,0 +1,129 @@ +/** + * Settings Type Definitions for OpenFang + * + * These types define the configuration and settings structures + * for the OpenFang desktop client. + */ + +/** + * Quick configuration settings for the application + * + * This interface represents user-configurable options that + * affect application behavior and appearance. + */ +export interface QuickConfig { + // Agent Configuration + /** Display name for the agent */ + agentName?: string; + /** Role or persona description for the agent */ + agentRole?: string; + /** Display name for the user */ + userName?: string; + /** Role description for the user */ + userRole?: string; + /** Short nickname for the agent */ + agentNickname?: string; + + // Scenario Configuration + /** List of scenario identifiers to enable */ + scenarios?: string[]; + + // Workspace Configuration + /** Path to the workspace directory */ + workspaceDir?: string; + + // Gateway Configuration + /** URL for the OpenFang gateway server */ + gatewayUrl?: string; + /** Authentication token for gateway */ + gatewayToken?: string; + + // Skills Configuration + /** Additional directories to scan for skills */ + skillsExtraDirs?: string[]; + + // MCP Services + /** List of MCP (Model Context Protocol) services */ + mcpServices?: MCPService[]; + + // UI Preferences + /** Application color theme */ + theme?: ThemeMode; + /** Whether to start agent automatically on launch */ + autoStart?: boolean; + /** Whether to display tool call information in chat */ + showToolCalls?: boolean; + + // Security Settings + /** Whether to restrict file system access */ + restrictFiles?: boolean; + /** Whether to automatically save context */ + autoSaveContext?: boolean; + /** Whether to enable file watching */ + fileWatching?: boolean; + + // Privacy + /** Opt-in for telemetry/analytics */ + privacyOptIn?: boolean; +} + +/** + * MCP (Model Context Protocol) Service configuration + */ +export interface MCPService { + /** Unique identifier for the service */ + id: string; + /** Display name of the service */ + name: string; + /** Whether the service is currently enabled */ + enabled: boolean; + /** Optional connection URL or endpoint */ + endpoint?: string; + /** Optional API key or credentials */ + apiKey?: string; +} + +/** + * Application theme modes + * + * - light: Light color scheme + * - dark: Dark color scheme + */ +export type ThemeMode = 'light' | 'dark'; + +/** + * Full application settings including internal state + */ +export interface AppSettings extends QuickConfig { + /** Settings schema version for migration support */ + version: string; + /** ISO timestamp of last settings modification */ + lastModified: string; +} + +/** + * Settings validation result + */ +export interface SettingsValidationResult { + valid: boolean; + errors: SettingsValidationError[]; + warnings?: string[]; +} + +/** + * Individual settings validation error + */ +export interface SettingsValidationError { + field: string; + message: string; + value?: unknown; +} + +/** + * Response structure for settings API + */ +export interface SettingsResponse { + settings: QuickConfig; + success: boolean; + error?: string; +} diff --git a/docs/SYSTEM_ANALYSIS.md b/docs/SYSTEM_ANALYSIS.md index ae461c1..c1ba340 100644 --- a/docs/SYSTEM_ANALYSIS.md +++ b/docs/SYSTEM_ANALYSIS.md @@ -141,9 +141,9 @@ ZCLAW 是基于 **OpenFang** (Rust Agent OS) 的 AI Agent 桌面客户端,核 | 类型文件 | 状态 | 缺失类型 | |----------|------|----------| | `types/hands.ts` | ✅ 完整 | - | -| Agent 类型 | ❌ 缺失 | Agent, AgentConfig, AgentStatus | -| Session 类型 | ❌ 缺失 | Session, SessionMessage | -| Settings 类型 | ❌ 缺失 | Settings, QuickConfig 完整定义 | +| `types/agent.ts` | ✅ 完整 | - | +| `types/session.ts` | ✅ 完整 | - | +| `types/settings.ts` | ✅ 完整 | - | | Workflow 类型 | ⚠️ 部分 | WorkflowStep 详细定义 | --- @@ -238,8 +238,8 @@ ZCLAW 是基于 **OpenFang** (Rust Agent OS) 的 AI Agent 桌面客户端,核 | 任务 | 说明 | 状态 | |------|------|------| -| 迁移 openclaw.default.json | 转换为 config.toml | 🔴 待开始 | -| 补充主 config.toml | OpenFang 服务器配置 | 🔴 待开始 | +| 迁移 openclaw.default.json | 转换为 config.toml | ✅ 已完成 | +| 补充主 config.toml | OpenFang 服务器配置 | ✅ 已完成 | | 清理 OpenClaw 遗留代码 | 移除兼容层 | 🔴 待开始 | ### Phase 4: 类型系统完善 (P2) @@ -250,9 +250,9 @@ ZCLAW 是基于 **OpenFang** (Rust Agent OS) 的 AI Agent 桌面客户端,核 | 任务 | 文件 | 状态 | |------|------|------| -| Agent 类型定义 | `types/agent.ts` | 🔴 待开始 | -| Session 类型定义 | `types/session.ts` | 🔴 待开始 | -| Settings 类型定义 | `types/settings.ts` | 🔴 待开始 | +| Agent 类型定义 | `types/agent.ts` | ✅ 已完成 | +| Session 类型定义 | `types/session.ts` | ✅ 已完成 | +| Settings 类型定义 | `types/settings.ts` | ✅ 已完成 | | Workflow 详细类型 | `types/workflow.ts` | 🔴 待开始 | ### Phase 5: Skills 生态扩展 (P2) @@ -284,10 +284,10 @@ ZCLAW 是基于 **OpenFang** (Rust Agent OS) 的 AI Agent 桌面客户端,核 ### 5.2 配置层面 -| 债务 | 位置 | 影响 | 清理方案 | -|------|------|------|----------| -| OpenClaw JSON 配置 | `config/openclaw.default.json` | 配置格式混合 | 迁移到 TOML | -| 缺少主配置文件 | `config/` | OpenFang 配置不完整 | 创建 config.toml | +| 债务 | 位置 | 影响 | 清理方案 | 状态 | +|------|------|------|----------|------| +| ~~OpenClaw JSON 配置~~ | ~~`config/openclaw.default.json`~~ | ~~配置格式混合~~ | ~~迁移到 TOML~~ | ✅ 已清理 | +| ~~缺少主配置文件~~ | ~~`config/`~~ | ~~OpenFang 配置不完整~~ | ~~创建 config.toml~~ | ✅ 已清理 | ### 5.3 类型层面 @@ -319,10 +319,18 @@ ZCLAW 是基于 **OpenFang** (Rust Agent OS) 的 AI Agent 桌面客户端,核 ### 6.3 Phase 3 完成标准 -- [ ] 无 OpenClaw JSON 配置文件 -- [ ] 所有配置使用 TOML 格式 +- [x] 创建 OpenFang config.toml +- [x] 迁移 OpenClaw JSON 配置到 TOML +- [ ] 无 OpenClaw JSON 配置文件 (保留 openclaw.default.json 作为参考) - [ ] 无 OpenClaw 兼容层代码 +### 6.4 Phase 4 完成标准 + +- [x] Agent 类型定义完整 +- [x] Session 类型定义完整 +- [x] Settings 类型定义完整 +- [ ] Workflow 详细类型定义 + --- ## 七、风险与缓解 @@ -369,4 +377,6 @@ ZCLAW 是基于 **OpenFang** (Rust Agent OS) 的 AI Agent 桌面客户端,核 *文档创建: 2026-03-14* *最后更新: 2026-03-15* *Phase 1 & 2 已完成* -*下次审查: Phase 3 开始前* +*Phase 3 进行中 (2/3)* +*Phase 4 部分完成 (3/4)* +*下次审查: Phase 3 完成后*