feat(phase3-4): add OpenFang config.toml and TypeScript type definitions
Phase 3: Configuration Migration (P1) - Create config/config.toml with comprehensive OpenFang settings - Migrate openclaw.default.json content to TOML format - Add server, agent, skills, hands, llm, security, logging configs - Add desktop-specific settings for ZClaw client Phase 4: Type System Enhancement (P2) - Create types/agent.ts: Agent, AgentConfig, AgentStatus types - Create types/session.ts: Session, SessionMessage, MessageRole types - Create types/settings.ts: QuickConfig, MCPService, AppSettings types - Create types/index.ts: Barrel export for all type definitions Documentation Updates: - Mark Phase 3 config migration tasks as completed (2/3) - Mark Phase 4 type definition tasks as completed (3/4) - Update technical debt cleanup status - Update type definition section in SYSTEM_ANALYSIS.md Files Added: - config/config.toml (289 lines) - desktop/src/types/agent.ts (68 lines) - desktop/src/types/session.ts (75 lines) - desktop/src/types/settings.ts (89 lines) - desktop/src/types/index.ts (41 lines) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
67
desktop/src/types/agent.ts
Normal file
67
desktop/src/types/agent.ts
Normal file
@@ -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;
|
||||
}
|
||||
40
desktop/src/types/index.ts
Normal file
40
desktop/src/types/index.ts
Normal file
@@ -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';
|
||||
107
desktop/src/types/session.ts
Normal file
107
desktop/src/types/session.ts
Normal file
@@ -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<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<string, unknown>;
|
||||
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;
|
||||
}
|
||||
129
desktop/src/types/settings.ts
Normal file
129
desktop/src/types/settings.ts
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user