/**
 * Execution Engine - Contract-based workflow and agent system
 *
 * @module @repo/core/execution-engine
 */

// Note: ExecutionEngine class has been removed in favor of direct resource execution
// Resources (workflows, agents) now execute themselves with ExecutionContext

// Workflow exports (from workflow module)
export {
  Workflow,
  type WorkflowStep,
  type WorkflowStepDefinition,
  type StepHandler,
  type WorkflowConfig,
  type DescriptorBackedWorkflowConfig,
  type WorkflowDefinition,
  type NextConfig,
  type LinearNext,
  type ConditionalNext,
  StepType,
  // Workflow step helper types (browser-safe - types only)
  // NOTE: llmCall implementation is server-only - import from @repo/core/server
  type LLMCallOptions
} from './workflow'

// Workflow logger exports
export {
  type WorkflowLogContext,
  type WorkflowLogMessage,
  type WorkflowExecutionContext,
  type WorkflowFailureContext,
  type StepStartedContext,
  type StepCompletedContext,
  type StepFailedContext,
  type ConditionalRouteContext,
  type ExecutionPathContext,
  isWorkflowExecutionContext,
  isWorkflowFailureContext,
  isStepStartedContext,
  isStepCompletedContext,
  isStepFailedContext,
  isConditionalRouteContext,
  isExecutionPathContext,
  isStepContext,
  toWorkflowLogMessage,
  toWorkflowLogMessages
} from './workflow/logging'

// Workflow timeline types
export {
  type StepState,
  type WorkflowNodeVisualizerData,
  type WorkflowNodeVisualizerData as TimelineData,
  type StepExecutionData,
  type ExecutionPathState
} from './workflow/types'

// Agent exports (from agent module)
export {
  Agent,
  type AgentKind,
  type AgentConfig,
  type DescriptorBackedAgentConfig,
  type AgentConstraints,
  type AgentMemory,
  type AgentDefinition,
  type Tool,
  type ToolDefinition,
  // Memory types
  type MemoryEntry,
  type MemoryEntryType,
  // Memory utilities
  loadSessionMemory,
  addToolError,
  // Action types
  type AgentAction,
  type ToolCallAction,
  type CompleteAction,
  type MessageAction,
  type NavigateKnowledgeAction,
  // Knowledge map types
  type KnowledgeMap,
  type KnowledgeNode,
  type KnowledgeContent,
  type KnowledgeMapState,
  reloadKnowledgeMapTools,
  // LLM types (generic interface - browser-safe)
  type LLMAdapter,
  type LLMGenerateRequest,
  type LLMGenerateResponse,
  type LLMMessage,
  type LLMModel,
  // LLM adapter types (browser-safe - types only)
  // NOTE: OpenAIAdapter and createLLMAdapter implementations are server-only - import from @repo/core/server
  type OpenAIAdapterConfig,
  // LLM adapter factory (dependency injection for environment-agnostic agent execution)
  type LLMAdapterFactory
} from './agent'

// Agent prompt system
// Note: BASE_SYSTEM_PROMPT removed - now internal to modular prompt builder
// Agents should provide only their agent-specific prompt
// The runtime (buildReasoningRequest) handles system prompt composition automatically using modular sections

// Base error exports
export { ExecutionError as ExecutionError, UnknownExecutionError, type ExecutionErrorCategory } from './base/errors'

// LLM error exports
export {
  LLMError,
  InsufficientTokensError,
  TokenLimitExceededError,
  LLMInputBlockedError,
  ModelConfigError,
  validateModelConfig
} from './llm/errors'

// Input sanitizer exports
export { sanitizeUserInput, type SanitizationResult } from './llm/input-sanitizer'

// Tool error exports
export {
  ToolingError,
  type ToolingErrorType,
  type ToolExecutionOptions,
  // Factory functions
  serviceUnavailable,
  permissionDenied,
  adapterNotFound,
  methodNotFound,
  toolNotFound,
  credentialsMissing,
  credentialsInvalid,
  rateLimitExceeded,
  serverUnavailable,
  authError,
  apiError,
  validationError,
  networkError,
  timeoutError,
  unknownError
} from './tools/types'

// Circuit breaker error exports
export { CircuitBreakerOpenError } from './llm/adapters/circuit-breaker'

// Workflow error exports
export { WorkflowStepError, WorkflowValidationError } from './workflow/errors'

// Agent error exports
export {
  AgentInitializationError,
  AgentIterationError,
  AgentCancellationError,
  AgentCompletionError,
  AgentOutputValidationError,
  AgentMaxIterationsError,
  AgentTimeoutError,
  AgentStalledError
} from './agent/errors'

// LLM model info and configuration exports
export {
  getModelInfo,
  type ModelInfo,
  type ModelConfig,
  type ModelSpecificOptions,
  type GPT5Options,
  type MockOptions,
  GPT5ConfigSchema,
  MockConfigSchema,
  MODEL_INFO,
  calculateCost
} from './llm/model-info'

// Agent logger exports (2-event model)
export {
  type AgentLogContext,
  type AgentLogMessage,
  type AgentLifecycle,
  type LifecycleStage,
  type IterationEventType,
  type AgentLifecycleEvent,
  type AgentIterationEvent,
  type AgentToolCallEvent,
  type ActionPlaceholderData,
  isLifecycleEvent,
  isIterationEvent,
  isReasoningEvent,
  isActionEvent,
  isToolCallEvent,
  isInitialization,
  isIteration,
  isCompletion,
  isToolUseAction,
  isIterationContext
} from './agent/observability/logging'

// Agent timeline types
export {
  type SubActivity,
  type AgentIteration,
  type AgentLifecycleNode,
  type AgentIterationData
} from './agent/observability/types'

// Base type exports
export type {
  ExecutionContext,
  ExecutionMetadata,
  MessageEvent,
  AssistantAction,
  Contract,
  ResourceType,
  ResourceStatus,
  ExecutableResourceType,
  AIResourceDefinition
} from './base/types'

// Base color exports
export { ResourceStatusColors } from './base/types'

// Utility exports
export {
  type ExecutionLogLevel,
  type ExecutionLoggerConfig,
  type ExecutionLogMessage,
  type LogContext,
  type IExecutionLogger
} from './base/logging'

// Structure utility exports
// Removed deprecated structure-utils exports - use serializeDefinition() directly

// Serialization utility exports
export { serializeDefinition, type SerializationOptions } from './base/serialization'

// Tool Services Registry (server-side only)
export {
  toolServicesRegistry,
  getToolServices,
  type ToolServices,
  type ICommandQueueService,
  type ITaskSchedulerService,
  type INotificationsService,
  type ICredentialsService,
  type IIntegrationService,
  type ICrmService,
  type IProjectsService,
  // Email Service types
  type IEmailService,
  type SendPlatformEmailParams,
  type EmailResult,
  // Storage Service types
  type IStorageService,
  type StorageUploadParams,
  type StorageDownloadParams,
  type StorageSignedUrlParams,
  type StorageUploadResult,
  type StorageSignedUrlResult,
  // Lead Service types
  type ILeadService,
  type AcqList,
  type AcqCompany,
  type AcqContact,
  // Note: PaginationParams already exported from @repo/core (platform/utils/validation)
  type PaginatedResult,
  type CreateListParams,
  type UpdateListParams,
  type CreateCompanyParams,
  type UpdateCompanyParams,
  type UpsertCompanyParams,
  type CompanyFilters,
  type CreateContactParams,
  type UpdateContactParams,
  type UpsertContactParams,
  type ContactFilters,
  type AddContactsToListParams,
  type AddContactsToListResult,
  type BulkImportParams,
  type BulkImportResult,
  type BulkImportCompanyEntry,
  type BulkImportCompaniesParams,
  type BulkImportCompaniesResult,
  type DeactivateContactsByCompanyParams,
  type DeactivateContactsByCompanyResult,
  // Deal types (acq_deals table)
  type UpsertDealParams,
  type AcqDeal,
  type DealActivityEntry,
  // Deal analytics types
  type DealStageSummary,
  type StaleDeal,
  type DealPipelineAnalytics,
  type DealAnalyticsParams,
  // Deal-sync param types
  type UpdateDiscoveryDataParams,
  type UpdateProposalDataParams,
  type MarkProposalSentParams,
  type MarkProposalReviewedParams,
  type UpdateCloseLostReasonParams,
  type UpdateFeesParams,
  type CacheInstantlyThreadIdsParams,
  type TransitionItemParams,
  type SetContactNurtureParams,
  type CancelSchedulesAndHitlByEmailParams,
  type CancelHitlByDealIdParams,
  type ClearDealFieldsParams,
  type DeleteDealParams,
  // Deal note types
  type AcqDealNote,
  type CreateDealNoteParams,
  type ListDealNotesParams,
  // Deal task types
  type CreateDealTaskParams,
  type ListDealTasksParams,
  type ListDealTasksDueParams,
  type CompleteDealTaskParams,
  type RecordDealActivityParams,
  type GetDealByIdParams,
  type GetContactByIdParams,
  type GetCompanyByIdParams,
  // CRM workflow helper param types
  type TransitionDealParams,
  type LoadDealParams,
  // List-oriented lead gen params (Step 3 of list-oriented migration)
  type UpdateListConfigParams,
  type UpdateCompanyStageParams,
  type UpdateContactStageParams,
  type ClearCompanyStagesParams,
  type ClearContactStagesParams,
  type ListPendingCompanyIdsParams,
  type ListPendingContactIdsParams,
  type AddCompaniesToListParams,
  type AddCompaniesToListResult,
  type RemoveCompaniesFromListParams,
  type RemoveCompaniesFromListResult,
  type RecordListExecutionParams,
  type ListExecutionSummary
} from './tools/registry'

// Platform Tools (server-side only)
// Retained internal/compatibility surface. Deployed SDK workers use platform.call() -> dispatcher.
export {
  // Storage Tools
  createStorageUploadTool,
  createStorageSignedUrlTool,
  createStorageDownloadTool,
  createStorageDeleteTool,
  createStorageListTool,
  type StorageUploadInput,
  type StorageUploadOutput,
  type StorageSignedUrlInput,
  type StorageSignedUrlOutput,
  type StorageDownloadInput,
  type StorageDownloadOutput,
  type StorageDeleteInput,
  type StorageDeleteOutput,
  type StorageListInput,
  type StorageListOutput,
  type StorageToolConfig,
  StorageUploadInputSchema,
  StorageUploadOutputSchema,
  StorageSignedUrlInputSchema,
  StorageSignedUrlOutputSchema,
  StorageDownloadInputSchema,
  StorageDownloadOutputSchema,
  StorageDeleteInputSchema,
  StorageDeleteOutputSchema,
  StorageListInputSchema,
  StorageListOutputSchema,
  // Schedule Management Tools
  createScheduleListTool,
  createScheduleCancelByMetadataTool,
  createScheduleCancelByKeyTool,
  createScheduleDeleteByKeyTool,
  type ListSchedulesInput,
  type ListSchedulesOutput,
  type CancelSchedulesByMetadataInput,
  type CancelSchedulesByMetadataOutput,
  type CancelScheduleByKeyInput,
  type CancelScheduleByKeyOutput,
  type DeleteScheduleByKeyInput,
  type DeleteScheduleByKeyOutput,
  ListSchedulesInputSchema,
  ListSchedulesOutputSchema,
  CancelSchedulesByMetadataInputSchema,
  CancelSchedulesByMetadataOutputSchema,
  CancelScheduleByKeyInputSchema,
  CancelScheduleByKeyOutputSchema,
  DeleteScheduleByKeyInputSchema,
  DeleteScheduleByKeyOutputSchema,
  type HitlCancelByMetadataInput,
  type HitlCancelByMetadataOutput,
  HitlCancelByMetadataInputSchema,
  HitlCancelByMetadataOutputSchema
} from './tools/platform'

// Integration Tools
// NOTE: createIntegrationTool and types are browser-safe (can be used for type definitions)
// Tool factory functions (createGmailSendEmailTool, etc.) are server-only - import from @repo/core/server
// ALL adapters (mock or production) are server-only exports from @repo/core/server
export { createIntegrationTool, type IntegrationToolConfig, type IntegrationType } from './tools/integration'

// LLM Tools (for agent tool use - types only, browser-safe)
// NOTE: createLLMCallTool implementation is server-only - import from @repo/core/server
export { type LLMCallToolConfig } from './tools/llm'

// Integration Tools (exports from integration module)
export { IntegrationService } from './tools/integration'

// Tool Method Maps (SDK adapter type maps - browser-safe)
export type {
  MethodEntry,
  ToolMethodMap,
  AttioToolMap,
  StripeToolMap,
  GoogleSheetsToolMap,
  ResendToolMap,
  ApifyToolMap,
  GmailToolMap,
  DropboxToolMap,
  SignatureApiToolMap,
  InstantlyToolMap,
  AnymailfinderToolMap,
  TombaToolMap,
  MillionVerifierToolMap,
  ClickUpToolMap,
  SchedulerToolMap,
  StorageToolMap,
  NotificationToolMap,
  NotificationSDKInput,
  ProjectsToolMap,
  CrmToolMap,
  LeadToolMap,
  ListToolMap,
  PdfToolMap,
  ApprovalToolMap,
  ExecutionToolMap,
  EmailToolMap
} from './tools/tool-maps'

// Execution Interface (UI configuration for resource execution)
export { type ExecutionInterface, type ExecutionFormSchema, type ScheduleConfig, type WebhookConfig } from './interface'
