refactor(config): extract shared config primitives

Create shared.ts with common configuration types that can be used
across agent-core and zee gateway:

- Session primitives: SessionScope, ReplyMode, TypingMode, ReplyToMode
- Policy types: DmPolicy, GroupPolicy
- Logging: LogLevel, ConsoleStyle, LoggingConfig
- Network: RetryConfig, BindMode
- Model/Provider: ModelApi, ModelDefinition, ProviderDefinition
- Processing: ThinkingLevel, QueueMode, QueueDropPolicy

Update types.ts to use shared primitives:
- GeneralSettings.logLevel now uses shared LogLevel
- WhatsAppConfig extended with dmPolicy, groupPolicy, allowFrom, retry
- TelegramConfig extended with dmPolicy, groupPolicy, allowFrom, retry

This is the first step toward config consolidation between agent-core
and zee gateway, enabling type-safe sharing of common configuration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Artur Do Lago
2026-01-10 23:20:45 +01:00
parent a9a2b256bf
commit bb250deb3a
3 changed files with 204 additions and 19 deletions
+6
View File
@@ -34,6 +34,12 @@
* ```
*/
// ============================================================================
// Shared Primitives (cross-project compatibility)
// ============================================================================
export * from "./shared";
// ============================================================================
// Legacy Types (backward compatibility)
// ============================================================================
+170
View File
@@ -0,0 +1,170 @@
/**
* Shared Configuration Primitives
*
* Types shared between agent-core and zee gateway.
* These are the canonical definitions - both projects should use these.
*/
// =============================================================================
// Session Primitives
// =============================================================================
/** How sessions are scoped */
export type SessionScope = "per-sender" | "global";
/** Reply behavior mode */
export type ReplyMode = "text" | "command";
/** When to show typing indicator */
export type TypingMode = "never" | "instant" | "thinking" | "message";
/** Reply-to threading behavior */
export type ReplyToMode = "off" | "first" | "all";
// =============================================================================
// Access Policy Primitives
// =============================================================================
/** Direct message access policy */
export type DmPolicy = "pairing" | "allowlist" | "open" | "disabled";
/** Group message access policy */
export type GroupPolicy = "open" | "disabled" | "allowlist";
// =============================================================================
// Logging Primitives
// =============================================================================
/** Log levels (compatible with pino/tslog) */
export type LogLevel =
| "silent"
| "fatal"
| "error"
| "warn"
| "info"
| "debug"
| "trace";
/** Console output style */
export type ConsoleStyle = "pretty" | "compact" | "json";
/** Base logging configuration */
export interface LoggingConfig {
/** Log level threshold */
level?: LogLevel;
/** Log file path */
file?: string;
/** Console-specific log level */
consoleLevel?: LogLevel;
/** Console output format */
consoleStyle?: ConsoleStyle;
}
// =============================================================================
// Retry Configuration
// =============================================================================
/** Outbound request retry configuration */
export interface RetryConfig {
/** Max retry attempts (default: 3) */
attempts?: number;
/** Minimum retry delay in ms */
minDelayMs?: number;
/** Maximum retry delay cap in ms */
maxDelayMs?: number;
/** Jitter factor (0-1) applied to delays */
jitter?: number;
}
// =============================================================================
// Model/Provider Primitives
// =============================================================================
/** API type for model providers */
export type ModelApi =
| "anthropic-messages"
| "openai-chat"
| "openai-responses"
| "google-genai"
| "bedrock-converse";
/** Model input modalities */
export type ModelInputModality = "text" | "image" | "audio" | "video" | "file";
/** Token cost structure */
export interface TokenCost {
input: number;
output: number;
cacheRead?: number;
cacheWrite?: number;
}
/** Model definition */
export interface ModelDefinition {
/** Model identifier */
id: string;
/** Display name */
name?: string;
/** Supports extended thinking */
reasoning?: boolean;
/** Supported input types */
input?: ModelInputModality[];
/** Token costs per million */
cost?: TokenCost;
/** Context window size in tokens */
contextWindow?: number;
/** Max output tokens */
maxTokens?: number;
/** Custom headers for this model */
headers?: Record<string, string>;
}
/** Provider configuration */
export interface ProviderDefinition {
/** API base URL */
baseUrl: string;
/** API key (or env var reference) */
apiKey?: string;
/** API type */
api?: ModelApi;
/** Custom headers */
headers?: Record<string, string>;
/** Available models */
models?: ModelDefinition[];
}
// =============================================================================
// Thinking Configuration
// =============================================================================
/** Thinking/reasoning level */
export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high";
// =============================================================================
// Queue/Processing Configuration
// =============================================================================
/** Queue processing mode */
export type QueueMode = "fifo" | "lifo" | "priority" | "debounce";
/** Queue drop policy when full */
export type QueueDropPolicy = "oldest" | "newest" | "none";
// =============================================================================
// Bind/Network Configuration
// =============================================================================
/** Network bind mode */
export type BindMode = "auto" | "lan" | "tailnet" | "loopback";
// =============================================================================
// Re-exports for convenience
// =============================================================================
export type {
SessionScope as SessionScopeType,
DmPolicy as DmPolicyType,
GroupPolicy as GroupPolicyType,
LogLevel as LogLevelType,
ThinkingLevel as ThinkingLevelType,
};
+28 -19
View File
@@ -14,6 +14,7 @@ import type { AgentConfig, AgentPersona } from "../agent/types";
import type { McpServerConfig as MCPConfig } from "../mcp/types";
import type { MemoryConfig } from "../memory/types";
import type { SurfaceType } from "../surface/types";
import type { LogLevel, DmPolicy, GroupPolicy, RetryConfig } from "./shared";
// =============================================================================
// Main Configuration
@@ -150,7 +151,6 @@ export interface SurfaceConfigs {
api?: APIConfig;
whatsapp?: WhatsAppConfig;
telegram?: TelegramConfig;
discord?: DiscordConfig;
}
/** CLI/TUI configuration */
@@ -213,6 +213,18 @@ export interface WhatsAppConfig {
/** Session data path */
sessionPath?: string;
/** Direct message access policy (shared with zee) */
dmPolicy?: DmPolicy;
/** Group message access policy (shared with zee) */
groupPolicy?: GroupPolicy;
/** Allowlist for direct chats (E.164 format) */
allowFrom?: string[];
/** Retry configuration for outbound messages */
retry?: RetryConfig;
/** Auto-reply settings */
autoReply?: {
/** Enable auto-reply */
@@ -241,36 +253,33 @@ export interface TelegramConfig {
/** Bot token */
botToken?: string;
/** Allowed user IDs (empty = all) */
/** Direct message access policy (shared with zee) */
dmPolicy?: DmPolicy;
/** Group message access policy (shared with zee) */
groupPolicy?: GroupPolicy;
/** Allowlist for direct chats (user IDs or usernames) */
allowFrom?: Array<string | number>;
/** Retry configuration for outbound messages */
retry?: RetryConfig;
/** Allowed user IDs (empty = all) - legacy, prefer allowFrom */
allowedUsers?: string[];
/** Webhook URL (if using webhooks) */
webhookUrl?: string;
}
/** Discord configuration */
export interface DiscordConfig {
/** Bot token */
botToken?: string;
/** Application ID */
applicationId?: string;
/** Allowed server IDs */
allowedServers?: string[];
/** Allowed channel IDs */
allowedChannels?: string[];
}
// =============================================================================
// General Settings
// =============================================================================
/** General application settings */
export interface GeneralSettings {
/** Log level */
logLevel?: "debug" | "info" | "warn" | "error";
/** Log level (uses shared LogLevel type) */
logLevel?: LogLevel;
/** Data directory for storage */
dataDir?: string;