'use strict';

var chunkY4B2NZI4_cjs = require('../../chunk-Y4B2NZI4.cjs');
var chunkT5KH32UA_cjs = require('../../chunk-T5KH32UA.cjs');
var chunkGHD37MZU_cjs = require('../../chunk-GHD37MZU.cjs');
var chunkFOX2GBIB_cjs = require('../../chunk-FOX2GBIB.cjs');
var chunk7NRYKBNJ_cjs = require('../../chunk-7NRYKBNJ.cjs');
var chunkRCWQFAJC_cjs = require('../../chunk-RCWQFAJC.cjs');
var chunkXZPOPKJV_cjs = require('../../chunk-XZPOPKJV.cjs');
var chunk6B2LGUBB_cjs = require('../../chunk-6B2LGUBB.cjs');
var chunkHWQ6HAV5_cjs = require('../../chunk-HWQ6HAV5.cjs');
var chunk5CHFOOQN_cjs = require('../../chunk-5CHFOOQN.cjs');
var chunkYNYUGFB5_cjs = require('../../chunk-YNYUGFB5.cjs');
var chunkGPSD5CSR_cjs = require('../../chunk-GPSD5CSR.cjs');
var chunkKPDZYFEE_cjs = require('../../chunk-KPDZYFEE.cjs');
var chunkBMW56UXY_cjs = require('../../chunk-BMW56UXY.cjs');
var chunkTTU35R4T_cjs = require('../../chunk-TTU35R4T.cjs');
var chunkNGSJV5D6_cjs = require('../../chunk-NGSJV5D6.cjs');
var chunkEHHCBPKQ_cjs = require('../../chunk-EHHCBPKQ.cjs');
var chunk6JFPLO7G_cjs = require('../../chunk-6JFPLO7G.cjs');
var chunkCFW3KNV7_cjs = require('../../chunk-CFW3KNV7.cjs');
var chunk5LNN2GWK_cjs = require('../../chunk-5LNN2GWK.cjs');
var chunkUXMTV44Q_cjs = require('../../chunk-UXMTV44Q.cjs');
var chunkAV3VZ6S3_cjs = require('../../chunk-AV3VZ6S3.cjs');
var chunkAAHPYUEC_cjs = require('../../chunk-AAHPYUEC.cjs');
var chunkI2WBGTIX_cjs = require('../../chunk-I2WBGTIX.cjs');
var chunkO36HRJ75_cjs = require('../../chunk-O36HRJ75.cjs');
var chunkO6EQUWUC_cjs = require('../../chunk-O6EQUWUC.cjs');
var chunk6M4TAONR_cjs = require('../../chunk-6M4TAONR.cjs');
var chunkC2PXJYRT_cjs = require('../../chunk-C2PXJYRT.cjs');
var chunkJ5IJWZEA_cjs = require('../../chunk-J5IJWZEA.cjs');
var chunk4LVJBXI2_cjs = require('../../chunk-4LVJBXI2.cjs');
var requestContext = require('@mastra/core/request-context');
var server = require('@mastra/core/server');
var hono = require('hono');

// src/server/server-adapter/routes/a2a.ts
var A2A_ROUTES = [chunkI2WBGTIX_cjs.GET_AGENT_CARD_ROUTE, chunkI2WBGTIX_cjs.AGENT_EXECUTION_ROUTE];

// src/server/server-adapter/routes/agent-builder.ts
var AGENT_BUILDER_ROUTES = [
  chunkO36HRJ75_cjs.LIST_AGENT_BUILDER_ACTIONS_ROUTE,
  chunkO36HRJ75_cjs.GET_AGENT_BUILDER_ACTION_BY_ID_ROUTE,
  chunkO36HRJ75_cjs.LIST_AGENT_BUILDER_ACTION_RUNS_ROUTE,
  chunkO36HRJ75_cjs.GET_AGENT_BUILDER_ACTION_RUN_BY_ID_ROUTE,
  chunkO36HRJ75_cjs.CREATE_AGENT_BUILDER_ACTION_RUN_ROUTE,
  chunkO36HRJ75_cjs.STREAM_AGENT_BUILDER_ACTION_ROUTE,
  chunkO36HRJ75_cjs.START_ASYNC_AGENT_BUILDER_ACTION_ROUTE,
  chunkO36HRJ75_cjs.START_AGENT_BUILDER_ACTION_RUN_ROUTE,
  chunkO36HRJ75_cjs.OBSERVE_STREAM_AGENT_BUILDER_ACTION_ROUTE,
  chunkO36HRJ75_cjs.RESUME_ASYNC_AGENT_BUILDER_ACTION_ROUTE,
  chunkO36HRJ75_cjs.RESUME_AGENT_BUILDER_ACTION_ROUTE,
  chunkO36HRJ75_cjs.RESUME_STREAM_AGENT_BUILDER_ACTION_ROUTE,
  chunkO36HRJ75_cjs.CANCEL_AGENT_BUILDER_ACTION_RUN_ROUTE
];

// src/server/server-adapter/routes/agents.ts
var AGENTS_ROUTES = [
  // ============================================================================
  // Agent Core Routes
  // ============================================================================
  chunkC2PXJYRT_cjs.LIST_AGENTS_ROUTE,
  chunkC2PXJYRT_cjs.GET_PROVIDERS_ROUTE,
  chunkC2PXJYRT_cjs.GET_AGENT_BY_ID_ROUTE,
  chunkC2PXJYRT_cjs.CLONE_AGENT_ROUTE,
  // ============================================================================
  // Voice Routes
  // ============================================================================
  chunkBMW56UXY_cjs.GET_SPEAKERS_ROUTE,
  chunkBMW56UXY_cjs.GET_SPEAKERS_DEPRECATED_ROUTE,
  // ============================================================================
  // Agent Execution Routes
  // ============================================================================
  chunkC2PXJYRT_cjs.GENERATE_AGENT_ROUTE,
  chunkC2PXJYRT_cjs.GENERATE_AGENT_VNEXT_ROUTE,
  chunkC2PXJYRT_cjs.STREAM_GENERATE_ROUTE,
  chunkC2PXJYRT_cjs.STREAM_GENERATE_VNEXT_DEPRECATED_ROUTE,
  // ============================================================================
  // Tool Routes
  // ============================================================================
  chunkNGSJV5D6_cjs.EXECUTE_AGENT_TOOL_ROUTE,
  chunkC2PXJYRT_cjs.APPROVE_TOOL_CALL_ROUTE,
  chunkC2PXJYRT_cjs.DECLINE_TOOL_CALL_ROUTE,
  chunkC2PXJYRT_cjs.APPROVE_TOOL_CALL_GENERATE_ROUTE,
  chunkC2PXJYRT_cjs.DECLINE_TOOL_CALL_GENERATE_ROUTE,
  chunkC2PXJYRT_cjs.APPROVE_NETWORK_TOOL_CALL_ROUTE,
  chunkC2PXJYRT_cjs.DECLINE_NETWORK_TOOL_CALL_ROUTE,
  // ============================================================================
  // Network Routes
  // ============================================================================
  chunkC2PXJYRT_cjs.STREAM_NETWORK_ROUTE,
  // ============================================================================
  // Model Management Routes
  // ============================================================================
  chunkC2PXJYRT_cjs.UPDATE_AGENT_MODEL_ROUTE,
  chunkC2PXJYRT_cjs.RESET_AGENT_MODEL_ROUTE,
  chunkC2PXJYRT_cjs.REORDER_AGENT_MODEL_LIST_ROUTE,
  chunkC2PXJYRT_cjs.UPDATE_AGENT_MODEL_IN_MODEL_LIST_ROUTE,
  // ============================================================================
  // Instruction Enhancement Routes
  // ============================================================================
  chunkC2PXJYRT_cjs.ENHANCE_INSTRUCTIONS_ROUTE,
  // ============================================================================
  // Agent Tool Routes
  // ============================================================================
  chunkNGSJV5D6_cjs.GET_AGENT_TOOL_ROUTE,
  // ============================================================================
  // Agent Skill Routes
  // ============================================================================
  chunkC2PXJYRT_cjs.GET_AGENT_SKILL_ROUTE,
  // ============================================================================
  // Voice/Speech Routes
  // ============================================================================
  chunkBMW56UXY_cjs.GENERATE_SPEECH_ROUTE,
  chunkBMW56UXY_cjs.GENERATE_SPEECH_DEPRECATED_ROUTE,
  chunkBMW56UXY_cjs.TRANSCRIBE_SPEECH_ROUTE,
  chunkBMW56UXY_cjs.TRANSCRIBE_SPEECH_DEPRECATED_ROUTE,
  chunkBMW56UXY_cjs.GET_LISTENER_ROUTE,
  // ============================================================================
  // Deprecated Routes
  // ============================================================================
  chunkC2PXJYRT_cjs.STREAM_VNEXT_DEPRECATED_ROUTE,
  chunkC2PXJYRT_cjs.STREAM_UI_MESSAGE_VNEXT_DEPRECATED_ROUTE,
  chunkC2PXJYRT_cjs.STREAM_UI_MESSAGE_DEPRECATED_ROUTE
];

// src/server/server-adapter/routes/datasets.ts
var DATASETS_ROUTES = [
  // Dataset CRUD
  chunkYNYUGFB5_cjs.LIST_DATASETS_ROUTE,
  chunkYNYUGFB5_cjs.CREATE_DATASET_ROUTE,
  chunkYNYUGFB5_cjs.GET_DATASET_ROUTE,
  chunkYNYUGFB5_cjs.UPDATE_DATASET_ROUTE,
  chunkYNYUGFB5_cjs.DELETE_DATASET_ROUTE,
  // Item list and add
  chunkYNYUGFB5_cjs.LIST_ITEMS_ROUTE,
  chunkYNYUGFB5_cjs.ADD_ITEM_ROUTE,
  // Batch operations - MUST come before item-specific routes to avoid /items/batch matching /items/:itemId
  chunkYNYUGFB5_cjs.BATCH_INSERT_ITEMS_ROUTE,
  chunkYNYUGFB5_cjs.BATCH_DELETE_ITEMS_ROUTE,
  // Item-specific CRUD (uses :itemId param)
  chunkYNYUGFB5_cjs.GET_ITEM_ROUTE,
  chunkYNYUGFB5_cjs.UPDATE_ITEM_ROUTE,
  chunkYNYUGFB5_cjs.DELETE_ITEM_ROUTE,
  // Version operations
  chunkYNYUGFB5_cjs.LIST_DATASET_VERSIONS_ROUTE,
  chunkYNYUGFB5_cjs.LIST_ITEM_VERSIONS_ROUTE,
  chunkYNYUGFB5_cjs.GET_ITEM_VERSION_ROUTE,
  // Experiment operations
  chunkYNYUGFB5_cjs.LIST_EXPERIMENTS_ROUTE,
  chunkYNYUGFB5_cjs.TRIGGER_EXPERIMENT_ROUTE,
  chunkYNYUGFB5_cjs.GET_EXPERIMENT_ROUTE,
  chunkYNYUGFB5_cjs.LIST_EXPERIMENT_RESULTS_ROUTE,
  // Analytics
  chunkYNYUGFB5_cjs.COMPARE_EXPERIMENTS_ROUTE
];

// src/server/server-adapter/routes/legacy.ts
var LEGACY_ROUTES = [
  // ============================================================================
  // Legacy Agent Routes
  // ============================================================================
  chunkC2PXJYRT_cjs.GENERATE_LEGACY_ROUTE,
  chunkC2PXJYRT_cjs.STREAM_GENERATE_LEGACY_ROUTE,
  // ============================================================================
  // Legacy Workflow Routes
  // ============================================================================
  chunkO6EQUWUC_cjs.STREAM_LEGACY_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE,
  // ============================================================================
  // Legacy Agent Builder Routes
  // ============================================================================
  chunkO36HRJ75_cjs.STREAM_LEGACY_AGENT_BUILDER_ACTION_ROUTE,
  chunkO36HRJ75_cjs.OBSERVE_STREAM_LEGACY_AGENT_BUILDER_ACTION_ROUTE
];

// src/server/server-adapter/routes/logs.ts
var LOGS_ROUTES = [
  chunkCFW3KNV7_cjs.LIST_LOG_TRANSPORTS_ROUTE,
  chunkCFW3KNV7_cjs.LIST_LOGS_ROUTE,
  chunkCFW3KNV7_cjs.LIST_LOGS_BY_RUN_ID_ROUTE
];

// src/server/server-adapter/routes/mcp.ts
var MCP_ROUTES = [
  // ============================================================================
  // MCP Server Registry Routes
  // ============================================================================
  chunk5LNN2GWK_cjs.LIST_MCP_SERVERS_ROUTE,
  chunk5LNN2GWK_cjs.GET_MCP_SERVER_DETAIL_ROUTE,
  // ============================================================================
  // MCP Server Tool Routes
  // ============================================================================
  chunk5LNN2GWK_cjs.LIST_MCP_SERVER_TOOLS_ROUTE,
  chunk5LNN2GWK_cjs.GET_MCP_SERVER_TOOL_DETAIL_ROUTE,
  chunk5LNN2GWK_cjs.EXECUTE_MCP_SERVER_TOOL_ROUTE,
  // ============================================================================
  // MCP Transport Routes (handled by adapters)
  // ============================================================================
  chunk5LNN2GWK_cjs.MCP_HTTP_TRANSPORT_ROUTE,
  chunk5LNN2GWK_cjs.MCP_SSE_TRANSPORT_ROUTE,
  chunk5LNN2GWK_cjs.MCP_SSE_MESSAGES_ROUTE
];

// src/server/server-adapter/routes/memory.ts
var MEMORY_ROUTES = [
  chunkUXMTV44Q_cjs.GET_MEMORY_STATUS_ROUTE,
  chunkUXMTV44Q_cjs.GET_MEMORY_CONFIG_ROUTE,
  chunkUXMTV44Q_cjs.GET_OBSERVATIONAL_MEMORY_ROUTE,
  chunkUXMTV44Q_cjs.AWAIT_BUFFER_STATUS_ROUTE,
  chunkUXMTV44Q_cjs.LIST_THREADS_ROUTE,
  chunkUXMTV44Q_cjs.GET_THREAD_BY_ID_ROUTE,
  chunkUXMTV44Q_cjs.LIST_MESSAGES_ROUTE,
  chunkUXMTV44Q_cjs.GET_WORKING_MEMORY_ROUTE,
  chunkUXMTV44Q_cjs.SAVE_MESSAGES_ROUTE,
  chunkUXMTV44Q_cjs.CREATE_THREAD_ROUTE,
  chunkUXMTV44Q_cjs.UPDATE_THREAD_ROUTE,
  chunkUXMTV44Q_cjs.DELETE_THREAD_ROUTE,
  chunkUXMTV44Q_cjs.CLONE_THREAD_ROUTE,
  chunkUXMTV44Q_cjs.UPDATE_WORKING_MEMORY_ROUTE,
  chunkUXMTV44Q_cjs.DELETE_MESSAGES_ROUTE,
  chunkUXMTV44Q_cjs.SEARCH_MEMORY_ROUTE,
  chunkUXMTV44Q_cjs.GET_MEMORY_STATUS_NETWORK_ROUTE,
  chunkUXMTV44Q_cjs.LIST_THREADS_NETWORK_ROUTE,
  chunkUXMTV44Q_cjs.GET_THREAD_BY_ID_NETWORK_ROUTE,
  chunkUXMTV44Q_cjs.LIST_MESSAGES_NETWORK_ROUTE,
  chunkUXMTV44Q_cjs.SAVE_MESSAGES_NETWORK_ROUTE,
  chunkUXMTV44Q_cjs.CREATE_THREAD_NETWORK_ROUTE,
  chunkUXMTV44Q_cjs.UPDATE_THREAD_NETWORK_ROUTE,
  chunkUXMTV44Q_cjs.DELETE_THREAD_NETWORK_ROUTE,
  chunkUXMTV44Q_cjs.DELETE_MESSAGES_NETWORK_ROUTE
];

// src/server/server-adapter/routes/observability.ts
var OBSERVABILITY_ROUTES = [
  chunkAV3VZ6S3_cjs.LIST_TRACES_ROUTE,
  chunkAV3VZ6S3_cjs.GET_TRACE_ROUTE,
  chunkAV3VZ6S3_cjs.SCORE_TRACES_ROUTE,
  chunkAV3VZ6S3_cjs.LIST_SCORES_BY_SPAN_ROUTE
];

// src/server/server-adapter/routes/processors.ts
var PROCESSORS_ROUTES = [
  chunkKPDZYFEE_cjs.LIST_PROCESSORS_ROUTE,
  chunkKPDZYFEE_cjs.GET_PROCESSOR_BY_ID_ROUTE,
  chunkKPDZYFEE_cjs.EXECUTE_PROCESSOR_ROUTE
];

// src/server/server-adapter/routes/scorers.ts
var SCORES_ROUTES = [
  chunk6JFPLO7G_cjs.LIST_SCORERS_ROUTE,
  chunk6JFPLO7G_cjs.GET_SCORER_ROUTE,
  chunk6JFPLO7G_cjs.LIST_SCORES_BY_RUN_ID_ROUTE,
  chunk6JFPLO7G_cjs.LIST_SCORES_BY_SCORER_ID_ROUTE,
  chunk6JFPLO7G_cjs.LIST_SCORES_BY_ENTITY_ID_ROUTE,
  chunk6JFPLO7G_cjs.SAVE_SCORE_ROUTE
];

// src/server/server-adapter/routes/stored-agents.ts
var STORED_AGENTS_ROUTES = [
  // ============================================================================
  // Stored Agents CRUD Routes
  // IMPORTANT: Routes with literal paths (e.g., /preview-instructions) must come
  // BEFORE routes with path parameters (e.g., /:storedAgentId) to ensure correct matching.
  // ============================================================================
  chunkRCWQFAJC_cjs.LIST_STORED_AGENTS_ROUTE,
  chunkRCWQFAJC_cjs.PREVIEW_INSTRUCTIONS_ROUTE,
  // Must be before GET_STORED_AGENT_ROUTE
  chunkRCWQFAJC_cjs.GET_STORED_AGENT_ROUTE,
  chunkRCWQFAJC_cjs.CREATE_STORED_AGENT_ROUTE,
  chunkRCWQFAJC_cjs.UPDATE_STORED_AGENT_ROUTE,
  chunkRCWQFAJC_cjs.DELETE_STORED_AGENT_ROUTE,
  // ============================================================================
  // Agent Versions Routes
  // IMPORTANT: Routes with literal paths (e.g., /compare) must come BEFORE
  // routes with path parameters (e.g., /:versionId) to ensure correct matching.
  // ============================================================================
  chunk6M4TAONR_cjs.LIST_AGENT_VERSIONS_ROUTE,
  chunk6M4TAONR_cjs.CREATE_AGENT_VERSION_ROUTE,
  chunk6M4TAONR_cjs.COMPARE_AGENT_VERSIONS_ROUTE,
  // Must be before GET_AGENT_VERSION_ROUTE
  chunk6M4TAONR_cjs.GET_AGENT_VERSION_ROUTE,
  chunk6M4TAONR_cjs.ACTIVATE_AGENT_VERSION_ROUTE,
  chunk6M4TAONR_cjs.RESTORE_AGENT_VERSION_ROUTE,
  chunk6M4TAONR_cjs.DELETE_AGENT_VERSION_ROUTE
];

// src/server/server-adapter/routes/stored-mcp-clients.ts
var STORED_MCP_CLIENTS_ROUTES = [
  // Stored MCP Clients CRUD Routes
  chunkXZPOPKJV_cjs.LIST_STORED_MCP_CLIENTS_ROUTE,
  chunkXZPOPKJV_cjs.GET_STORED_MCP_CLIENT_ROUTE,
  chunkXZPOPKJV_cjs.CREATE_STORED_MCP_CLIENT_ROUTE,
  chunkXZPOPKJV_cjs.UPDATE_STORED_MCP_CLIENT_ROUTE,
  chunkXZPOPKJV_cjs.DELETE_STORED_MCP_CLIENT_ROUTE,
  // MCP Client Versions Routes
  // IMPORTANT: Routes with literal paths (e.g., /compare) must come BEFORE
  // routes with path parameters (e.g., /:versionId) to ensure correct matching.
  chunkGPSD5CSR_cjs.LIST_MCP_CLIENT_VERSIONS_ROUTE,
  chunkGPSD5CSR_cjs.CREATE_MCP_CLIENT_VERSION_ROUTE,
  chunkGPSD5CSR_cjs.COMPARE_MCP_CLIENT_VERSIONS_ROUTE,
  chunkGPSD5CSR_cjs.GET_MCP_CLIENT_VERSION_ROUTE,
  chunkGPSD5CSR_cjs.ACTIVATE_MCP_CLIENT_VERSION_ROUTE,
  chunkGPSD5CSR_cjs.RESTORE_MCP_CLIENT_VERSION_ROUTE,
  chunkGPSD5CSR_cjs.DELETE_MCP_CLIENT_VERSION_ROUTE
];

// src/server/server-adapter/routes/stored-prompt-blocks.ts
var STORED_PROMPT_BLOCKS_ROUTES = [
  // Stored Prompt Blocks CRUD Routes
  chunk6B2LGUBB_cjs.LIST_STORED_PROMPT_BLOCKS_ROUTE,
  chunk6B2LGUBB_cjs.GET_STORED_PROMPT_BLOCK_ROUTE,
  chunk6B2LGUBB_cjs.CREATE_STORED_PROMPT_BLOCK_ROUTE,
  chunk6B2LGUBB_cjs.UPDATE_STORED_PROMPT_BLOCK_ROUTE,
  chunk6B2LGUBB_cjs.DELETE_STORED_PROMPT_BLOCK_ROUTE,
  // Prompt Block Versions Routes
  // IMPORTANT: Routes with literal paths (e.g., /compare) must come BEFORE
  // routes with path parameters (e.g., /:versionId) to ensure correct matching.
  chunkFOX2GBIB_cjs.LIST_PROMPT_BLOCK_VERSIONS_ROUTE,
  chunkFOX2GBIB_cjs.CREATE_PROMPT_BLOCK_VERSION_ROUTE,
  chunkFOX2GBIB_cjs.COMPARE_PROMPT_BLOCK_VERSIONS_ROUTE,
  chunkFOX2GBIB_cjs.GET_PROMPT_BLOCK_VERSION_ROUTE,
  chunkFOX2GBIB_cjs.ACTIVATE_PROMPT_BLOCK_VERSION_ROUTE,
  chunkFOX2GBIB_cjs.RESTORE_PROMPT_BLOCK_VERSION_ROUTE,
  chunkFOX2GBIB_cjs.DELETE_PROMPT_BLOCK_VERSION_ROUTE
];

// src/server/server-adapter/routes/stored-scorers.ts
var STORED_SCORERS_ROUTES = [
  // Stored Scorers CRUD Routes
  chunkHWQ6HAV5_cjs.LIST_STORED_SCORERS_ROUTE,
  chunkHWQ6HAV5_cjs.GET_STORED_SCORER_ROUTE,
  chunkHWQ6HAV5_cjs.CREATE_STORED_SCORER_ROUTE,
  chunkHWQ6HAV5_cjs.UPDATE_STORED_SCORER_ROUTE,
  chunkHWQ6HAV5_cjs.DELETE_STORED_SCORER_ROUTE,
  // Scorer Versions Routes
  // IMPORTANT: Routes with literal paths (e.g., /compare) must come BEFORE
  // routes with path parameters (e.g., /:versionId) to ensure correct matching.
  chunk7NRYKBNJ_cjs.LIST_SCORER_VERSIONS_ROUTE,
  chunk7NRYKBNJ_cjs.CREATE_SCORER_VERSION_ROUTE,
  chunk7NRYKBNJ_cjs.COMPARE_SCORER_VERSIONS_ROUTE,
  chunk7NRYKBNJ_cjs.GET_SCORER_VERSION_ROUTE,
  chunk7NRYKBNJ_cjs.ACTIVATE_SCORER_VERSION_ROUTE,
  chunk7NRYKBNJ_cjs.RESTORE_SCORER_VERSION_ROUTE,
  chunk7NRYKBNJ_cjs.DELETE_SCORER_VERSION_ROUTE
];

// src/server/server-adapter/routes/stored-skills.ts
var STORED_SKILLS_ROUTES = [
  // Stored Skills CRUD Routes
  chunk5CHFOOQN_cjs.LIST_STORED_SKILLS_ROUTE,
  chunk5CHFOOQN_cjs.GET_STORED_SKILL_ROUTE,
  chunk5CHFOOQN_cjs.CREATE_STORED_SKILL_ROUTE,
  chunk5CHFOOQN_cjs.UPDATE_STORED_SKILL_ROUTE,
  chunk5CHFOOQN_cjs.DELETE_STORED_SKILL_ROUTE,
  // Publish
  chunk5CHFOOQN_cjs.PUBLISH_STORED_SKILL_ROUTE
];

// src/server/server-adapter/routes/stored-workspaces.ts
var STORED_WORKSPACES_ROUTES = [
  // Stored Workspaces CRUD Routes
  chunkY4B2NZI4_cjs.LIST_STORED_WORKSPACES_ROUTE,
  chunkY4B2NZI4_cjs.GET_STORED_WORKSPACE_ROUTE,
  chunkY4B2NZI4_cjs.CREATE_STORED_WORKSPACE_ROUTE,
  chunkY4B2NZI4_cjs.UPDATE_STORED_WORKSPACE_ROUTE,
  chunkY4B2NZI4_cjs.DELETE_STORED_WORKSPACE_ROUTE
];

// src/server/server-adapter/routes/system.ts
var SYSTEM_ROUTES = [chunkT5KH32UA_cjs.GET_SYSTEM_PACKAGES_ROUTE];

// src/server/server-adapter/routes/tool-providers.ts
var TOOL_PROVIDER_ROUTES = [
  chunkGHD37MZU_cjs.LIST_TOOL_PROVIDERS_ROUTE,
  chunkGHD37MZU_cjs.LIST_TOOL_PROVIDER_TOOLKITS_ROUTE,
  chunkGHD37MZU_cjs.LIST_TOOL_PROVIDER_TOOLS_ROUTE,
  chunkGHD37MZU_cjs.GET_TOOL_PROVIDER_TOOL_SCHEMA_ROUTE
];

// src/server/server-adapter/routes/tools.ts
var TOOLS_ROUTES = [chunkNGSJV5D6_cjs.LIST_TOOLS_ROUTE, chunkNGSJV5D6_cjs.GET_TOOL_BY_ID_ROUTE, chunkNGSJV5D6_cjs.EXECUTE_TOOL_ROUTE];

// src/server/server-adapter/routes/vectors.ts
var VECTORS_ROUTES = [
  chunkEHHCBPKQ_cjs.UPSERT_VECTORS_ROUTE,
  chunkEHHCBPKQ_cjs.CREATE_INDEX_ROUTE,
  chunkEHHCBPKQ_cjs.QUERY_VECTORS_ROUTE,
  chunkEHHCBPKQ_cjs.LIST_INDEXES_ROUTE,
  chunkEHHCBPKQ_cjs.DESCRIBE_INDEX_ROUTE,
  chunkEHHCBPKQ_cjs.DELETE_INDEX_ROUTE,
  chunkEHHCBPKQ_cjs.LIST_VECTORS_ROUTE,
  chunkEHHCBPKQ_cjs.LIST_EMBEDDERS_ROUTE
];

// src/server/server-adapter/routes/workflows.ts
var WORKFLOWS_ROUTES = [
  chunkO6EQUWUC_cjs.LIST_WORKFLOWS_ROUTE,
  chunkO6EQUWUC_cjs.GET_WORKFLOW_BY_ID_ROUTE,
  chunkO6EQUWUC_cjs.LIST_WORKFLOW_RUNS_ROUTE,
  chunkO6EQUWUC_cjs.GET_WORKFLOW_RUN_BY_ID_ROUTE,
  chunkO6EQUWUC_cjs.DELETE_WORKFLOW_RUN_BY_ID_ROUTE,
  chunkO6EQUWUC_cjs.CREATE_WORKFLOW_RUN_ROUTE,
  chunkO6EQUWUC_cjs.STREAM_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.RESUME_STREAM_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.START_ASYNC_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.START_WORKFLOW_RUN_ROUTE,
  chunkO6EQUWUC_cjs.OBSERVE_STREAM_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.RESUME_ASYNC_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.RESUME_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.CANCEL_WORKFLOW_RUN_ROUTE,
  chunkO6EQUWUC_cjs.TIME_TRAVEL_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.TIME_TRAVEL_STREAM_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.RESTART_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.RESTART_ASYNC_WORKFLOW_ROUTE,
  chunkO6EQUWUC_cjs.RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE,
  chunkO6EQUWUC_cjs.RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE
];

// src/server/server-adapter/routes/workspace.ts
var WORKSPACE_ROUTES = [
  // List all workspaces route (at /api/workspaces)
  chunkTTU35R4T_cjs.LIST_WORKSPACES_ROUTE,
  // Get workspace route (at /api/workspaces/:workspaceId)
  chunkTTU35R4T_cjs.GET_WORKSPACE_ROUTE,
  // Filesystem routes (at /api/workspaces/:workspaceId/fs/*)
  ...chunkTTU35R4T_cjs.WORKSPACE_FS_ROUTES,
  // Search routes (at /api/workspaces/:workspaceId/search, /api/workspaces/:workspaceId/index)
  ...chunkTTU35R4T_cjs.WORKSPACE_SEARCH_ROUTES,
  // Skills routes (search must come before parameterized routes)
  ...chunkTTU35R4T_cjs.WORKSPACE_SKILLS_ROUTES,
  // skills.sh proxy routes (at /api/workspaces/:workspaceId/skills-sh/*)
  ...chunkTTU35R4T_cjs.WORKSPACE_SKILLS_SH_ROUTES
];

// src/server/server-adapter/routes/index.ts
var SERVER_ROUTES = [
  ...AGENTS_ROUTES,
  ...WORKFLOWS_ROUTES,
  ...TOOLS_ROUTES,
  ...PROCESSORS_ROUTES,
  ...MEMORY_ROUTES,
  ...SCORES_ROUTES,
  ...OBSERVABILITY_ROUTES,
  ...LOGS_ROUTES,
  ...VECTORS_ROUTES,
  ...A2A_ROUTES,
  ...AGENT_BUILDER_ROUTES,
  ...WORKSPACE_ROUTES,
  ...LEGACY_ROUTES,
  ...MCP_ROUTES,
  ...STORED_AGENTS_ROUTES,
  ...STORED_MCP_CLIENTS_ROUTES,
  ...STORED_PROMPT_BLOCKS_ROUTES,
  ...STORED_SCORERS_ROUTES,
  ...STORED_WORKSPACES_ROUTES,
  ...STORED_SKILLS_ROUTES,
  ...TOOL_PROVIDER_ROUTES,
  ...SYSTEM_ROUTES,
  ...DATASETS_ROUTES
];

// src/server/server-adapter/redact.ts
function redactV2Payload(payload) {
  const redactedPayload = { ...payload };
  if (redactedPayload.metadata && typeof redactedPayload.metadata === "object") {
    const { request, ...metadataRest } = redactedPayload.metadata;
    redactedPayload.metadata = metadataRest;
  }
  if (redactedPayload.output && typeof redactedPayload.output === "object") {
    const output = { ...redactedPayload.output };
    if (Array.isArray(output.steps)) {
      output.steps = output.steps.map((step) => {
        if (step && typeof step === "object") {
          const { request, ...stepRest } = step;
          return stepRest;
        }
        return step;
      });
    }
    redactedPayload.output = output;
  }
  return redactedPayload;
}
function redactStreamChunk(chunk) {
  if (!chunk || typeof chunk !== "object") {
    return chunk;
  }
  const typedChunk = chunk;
  switch (chunk.type) {
    case "step-start": {
      if ("payload" in typedChunk && typedChunk.payload && typeof typedChunk.payload === "object") {
        const { payload, ...rest } = typedChunk;
        const { request, ...payloadRest } = payload;
        return {
          ...rest,
          type: "step-start",
          payload: {
            ...payloadRest,
            // Keep an empty request object to maintain structure but remove body
            request: {}
          }
        };
      } else if ("request" in typedChunk) {
        const { request, ...rest } = typedChunk;
        return {
          ...rest,
          type: "step-start",
          // Keep an empty request object to maintain structure
          request: {}
        };
      }
      return chunk;
    }
    case "step-finish": {
      if ("payload" in typedChunk && typedChunk.payload && typeof typedChunk.payload === "object") {
        const { payload, ...rest } = typedChunk;
        return {
          ...rest,
          type: "step-finish",
          payload: redactV2Payload(payload)
        };
      } else if ("request" in typedChunk) {
        const { request, ...rest } = typedChunk;
        return {
          ...rest,
          type: "step-finish"
        };
      }
      return chunk;
    }
    case "finish": {
      if ("payload" in typedChunk && typedChunk.payload && typeof typedChunk.payload === "object") {
        const { payload, ...rest } = typedChunk;
        return {
          ...rest,
          type: "finish",
          payload: redactV2Payload(payload)
        };
      } else if ("request" in typedChunk) {
        const { request, ...rest } = typedChunk;
        return {
          ...rest,
          type: "finish"
        };
      }
      return chunk;
    }
    default:
      return chunk;
  }
}

// src/server/server-adapter/index.ts
function normalizeQueryParams(rawQuery) {
  const queryParams = {};
  const bracketGroups = {};
  for (const [key, value] of Object.entries(rawQuery)) {
    const bracketMatch = key.match(/^([^[]+)\[([^\]]+)\]$/);
    if (bracketMatch) {
      const parent = bracketMatch[1];
      const child = bracketMatch[2];
      const strValue = Array.isArray(value) ? value.filter((v) => typeof v === "string")[0] : typeof value === "string" ? value : void 0;
      if (strValue !== void 0) {
        if (!bracketGroups[parent]) {
          bracketGroups[parent] = {};
        }
        bracketGroups[parent][child] = strValue;
      }
    } else if (typeof value === "string") {
      queryParams[key] = value;
    } else if (Array.isArray(value)) {
      const stringValues = value.filter((v) => typeof v === "string");
      queryParams[key] = stringValues.length === 1 ? stringValues[0] : stringValues;
    }
  }
  for (const [parent, children] of Object.entries(bracketGroups)) {
    if (!(parent in queryParams)) {
      queryParams[parent] = JSON.stringify(children);
    }
  }
  return queryParams;
}
var MastraServer = class extends server.MastraServerBase {
  mastra;
  bodyLimitOptions;
  tools;
  prefix;
  openapiPath;
  taskStore;
  customRouteAuthConfig;
  streamOptions;
  customApiRoutes;
  mcpOptions;
  customRouteHandler = null;
  constructor({
    app,
    mastra,
    bodyLimitOptions,
    tools,
    prefix = "/api",
    openapiPath = "",
    taskStore,
    customRouteAuthConfig,
    streamOptions,
    customApiRoutes,
    mcpOptions
  }) {
    super({ app, name: "MastraServer" });
    this.mastra = mastra;
    this.bodyLimitOptions = bodyLimitOptions;
    this.tools = tools;
    this.prefix = chunkJ5IJWZEA_cjs.normalizeRoutePath(prefix);
    this.openapiPath = openapiPath;
    this.taskStore = taskStore;
    this.customRouteAuthConfig = customRouteAuthConfig;
    this.streamOptions = { redact: true, ...streamOptions };
    this.customApiRoutes = customApiRoutes;
    this.mcpOptions = mcpOptions;
    mastra.setMastraServer(this);
  }
  mergeRequestContext({
    paramsRequestContext,
    bodyRequestContext
  }) {
    const requestContext$1 = new requestContext.RequestContext();
    if (bodyRequestContext) {
      for (const [key, value] of Object.entries(bodyRequestContext)) {
        requestContext$1.set(key, value);
      }
    }
    if (paramsRequestContext) {
      for (const [key, value] of Object.entries(paramsRequestContext)) {
        requestContext$1.set(key, value);
      }
    }
    return requestContext$1;
  }
  /**
   * Check if the current request should be authenticated/authorized.
   * Returns null if auth passes, or an error response if it fails.
   *
   * This method encapsulates the complete auth flow:
   * 1. Check if route requires auth (route.requiresAuth)
   * 2. Check if it's a dev playground request
   * 3. Check if path is publicly accessible
   * 4. Perform authentication (verify token)
   * 5. Perform authorization (check rules, authorizeUser, authorize)
   */
  async checkRouteAuth(route, context) {
    const authConfig = this.mastra.getServer()?.auth;
    if (!authConfig) {
      return null;
    }
    if (route.requiresAuth === false) {
      return null;
    }
    if (chunkAAHPYUEC_cjs.isDevPlaygroundRequest(context.path, context.method, context.getHeader, authConfig)) {
      return null;
    }
    if (chunkAAHPYUEC_cjs.canAccessPublicly(context.path, context.method, authConfig)) {
      return null;
    }
    const authHeader = context.getHeader("authorization");
    let token = authHeader ? authHeader.replace("Bearer ", "") : null;
    if (!token) {
      token = context.getQuery("apiKey") || null;
    }
    if (!token) {
      return { status: 401, error: "Authentication required" };
    }
    let user;
    try {
      if (typeof authConfig.authenticateToken === "function") {
        user = await authConfig.authenticateToken(token, null);
      } else {
        return { status: 401, error: "No token verification method configured" };
      }
      if (!user) {
        return { status: 401, error: "Invalid or expired token" };
      }
      context.requestContext.set("user", user);
    } catch (err) {
      this.mastra.getLogger()?.error("Authentication error", {
        error: err instanceof Error ? { message: err.message, stack: err.stack } : err
      });
      return { status: 401, error: "Invalid or expired token" };
    }
    if ("authorizeUser" in authConfig && typeof authConfig.authorizeUser === "function") {
      try {
        const isAuthorized = await authConfig.authorizeUser(user, null);
        if (!isAuthorized) {
          return { status: 403, error: "Access denied" };
        }
        return null;
      } catch (err) {
        this.mastra.getLogger()?.error("Authorization error in authorizeUser", {
          error: err instanceof Error ? { message: err.message, stack: err.stack } : err
        });
        return { status: 500, error: "Authorization error" };
      }
    }
    if ("authorize" in authConfig && typeof authConfig.authorize === "function") {
      try {
        const isAuthorized = await authConfig.authorize(context.path, context.method, user, null);
        if (!isAuthorized) {
          return { status: 403, error: "Access denied" };
        }
        return null;
      } catch (err) {
        this.mastra.getLogger()?.error("Authorization error in authorize", {
          error: err instanceof Error ? { message: err.message, stack: err.stack } : err,
          path: context.path,
          method: context.method
        });
        return { status: 500, error: "Authorization error" };
      }
    }
    if ("rules" in authConfig && authConfig.rules && authConfig.rules.length > 0) {
      const isAuthorized = await chunkAAHPYUEC_cjs.checkRules(authConfig.rules, context.path, context.method, user);
      if (isAuthorized) {
        return null;
      }
      return { status: 403, error: "Access denied" };
    }
    if (chunkAAHPYUEC_cjs.defaultAuthConfig.rules && chunkAAHPYUEC_cjs.defaultAuthConfig.rules.length > 0) {
      const isAuthorized = await chunkAAHPYUEC_cjs.checkRules(chunkAAHPYUEC_cjs.defaultAuthConfig.rules, context.path, context.method, user);
      if (isAuthorized) {
        return null;
      }
    }
    return { status: 403, error: "Access denied" };
  }
  async init() {
    this.registerContextMiddleware();
    this.registerAuthMiddleware();
    await this.registerCustomApiRoutes();
    await this.registerRoutes();
  }
  /**
   * Override in adapters to register custom API routes defined via registerApiRoute().
   * Called by init() between registerAuthMiddleware() and registerRoutes().
   */
  async registerCustomApiRoutes() {
  }
  /**
   * Creates an internal Hono sub-app with all custom API routes registered.
   * Stores the handler on this instance for use by handleCustomRouteRequest().
   * Returns true if custom routes were found and registered.
   */
  async buildCustomRouteHandler() {
    const routes = this.customApiRoutes ?? this.mastra.getServer()?.apiRoutes;
    if (!routes || routes.length === 0) return false;
    const NOT_FOUND_HEADER = "x-mastra-custom-route-not-found";
    const mastra = this.mastra;
    const app = new hono.Hono();
    app.use("*", async (c, next) => {
      c.set("mastra", mastra);
      c.set("requestContext", c.env?.requestContext ?? new requestContext.RequestContext());
      await next();
    });
    for (const route of routes) {
      const handler = "handler" in route && route.handler ? route.handler : "createHandler" in route ? await route.createHandler({ mastra }) : void 0;
      if (!handler) continue;
      const middlewares = [];
      if (route.middleware) {
        middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
      }
      const allHandlers = [...middlewares, handler];
      if (route.method === "ALL") {
        app.all(route.path, allHandlers[0], ...allHandlers.slice(1));
      } else {
        app.on(route.method, route.path, allHandlers[0], ...allHandlers.slice(1));
      }
    }
    app.notFound(() => new Response(null, { status: 404, headers: { [NOT_FOUND_HEADER]: "true" } }));
    this.customRouteHandler = async (request, env) => app.fetch(request, env);
    return true;
  }
  /**
   * Forwards a request to the internal custom route handler.
   * Returns the Response if a custom route matched, or null to fall through.
   * Used by non-Hono adapter bridges.
   */
  async handleCustomRouteRequest(url, method, headers, body, requestContext) {
    if (!this.customRouteHandler) return null;
    const fetchHeaders = new Headers();
    for (const [key, value] of Object.entries(headers)) {
      if (typeof value === "string") fetchHeaders.set(key, value);
      else if (Array.isArray(value))
        value.forEach((v) => {
          fetchHeaders.append(key, v);
        });
    }
    const init = { method, headers: fetchHeaders };
    if (["POST", "PUT", "PATCH"].includes(method) && body !== void 0) {
      const contentType = (typeof headers["content-type"] === "string" ? headers["content-type"] : "") || "";
      if (contentType.includes("application/json")) {
        init.body = JSON.stringify(body);
      } else if (typeof body === "string") {
        init.body = body;
      } else if (body instanceof ArrayBuffer || body instanceof Uint8Array || body instanceof ReadableStream) {
        init.body = body;
      }
    }
    const request = new globalThis.Request(url, init);
    const response = await this.customRouteHandler(request, { requestContext });
    if (response.headers.get("x-mastra-custom-route-not-found") === "true") return null;
    return response;
  }
  /**
   * Pipes a custom route Response to a Node.js ServerResponse (http.ServerResponse).
   * Works with Koa (ctx.res), Express (res), and Fastify (reply.raw).
   */
  async writeCustomRouteResponse(response, nodeRes) {
    const headers = {};
    response.headers.forEach((value, key) => {
      if (key.toLowerCase() !== "set-cookie") {
        headers[key] = value;
      }
    });
    const setCookies = response.headers.getSetCookie?.();
    if (setCookies && setCookies.length > 0) {
      headers["set-cookie"] = setCookies;
    }
    nodeRes.writeHead(response.status, headers);
    if (response.body) {
      const reader = response.body.getReader();
      try {
        while (true) {
          const { done, value } = await reader.read();
          if (done) break;
          nodeRes.write(value);
        }
      } finally {
        nodeRes.end();
      }
    } else {
      nodeRes.end(await response.text());
    }
  }
  async registerOpenAPIRoute(app, config = {}, { prefix }) {
    const {
      title = "Mastra API",
      version = "1.0.0",
      description = "Mastra Server API",
      path = "/openapi.json"
    } = config;
    const openApiSpec = chunk4LVJBXI2_cjs.generateOpenAPIDocument(SERVER_ROUTES, {
      title,
      version,
      description
    });
    if (prefix) {
      openApiSpec.servers = [{ url: prefix }];
    }
    if (this.customApiRoutes && this.customApiRoutes.length > 0) {
      const customPaths = chunk4LVJBXI2_cjs.convertCustomRoutesToOpenAPIPaths(this.customApiRoutes);
      openApiSpec.paths = { ...openApiSpec.paths, ...customPaths };
    }
    const openApiRoute = {
      method: "GET",
      path,
      responseType: "json",
      handler: async () => openApiSpec
    };
    await this.registerRoute(app, openApiRoute, { prefix });
  }
  async registerRoutes() {
    for (const route of SERVER_ROUTES) {
      await this.registerRoute(this.app, route, { prefix: this.prefix });
    }
    if (this.openapiPath) {
      await this.registerOpenAPIRoute(
        this.app,
        {
          title: "Mastra API",
          version: "1.0.0",
          description: "Mastra Server API",
          path: this.openapiPath
        },
        { prefix: this.prefix }
      );
    }
  }
  async parsePathParams(route, params) {
    const pathParamSchema = route.pathParamSchema;
    if (!pathParamSchema) {
      return params;
    }
    return pathParamSchema.parseAsync(params);
  }
  async parseQueryParams(route, params) {
    const queryParamSchema = route.queryParamSchema;
    if (!queryParamSchema) {
      return params;
    }
    return queryParamSchema.parseAsync(params);
  }
  async parseBody(route, body) {
    const bodySchema = route.bodySchema;
    if (!bodySchema) {
      return body;
    }
    return bodySchema.parseAsync(body);
  }
};

Object.defineProperty(exports, "WorkflowRegistry", {
  enumerable: true,
  get: function () { return chunkJ5IJWZEA_cjs.WorkflowRegistry; }
});
Object.defineProperty(exports, "normalizeRoutePath", {
  enumerable: true,
  get: function () { return chunkJ5IJWZEA_cjs.normalizeRoutePath; }
});
Object.defineProperty(exports, "createRoute", {
  enumerable: true,
  get: function () { return chunk4LVJBXI2_cjs.createRoute; }
});
Object.defineProperty(exports, "generateOpenAPIDocument", {
  enumerable: true,
  get: function () { return chunk4LVJBXI2_cjs.generateOpenAPIDocument; }
});
Object.defineProperty(exports, "jsonQueryParam", {
  enumerable: true,
  get: function () { return chunk4LVJBXI2_cjs.jsonQueryParam; }
});
Object.defineProperty(exports, "pickParams", {
  enumerable: true,
  get: function () { return chunk4LVJBXI2_cjs.pickParams; }
});
Object.defineProperty(exports, "wrapSchemaForQueryParams", {
  enumerable: true,
  get: function () { return chunk4LVJBXI2_cjs.wrapSchemaForQueryParams; }
});
exports.MastraServer = MastraServer;
exports.SERVER_ROUTES = SERVER_ROUTES;
exports.normalizeQueryParams = normalizeQueryParams;
exports.redactStreamChunk = redactStreamChunk;
//# sourceMappingURL=index.cjs.map
//# sourceMappingURL=index.cjs.map