// src/server/constants.ts
var MASTRA_RESOURCE_ID_KEY = "mastra__resourceId";
var MASTRA_THREAD_ID_KEY = "mastra__threadId";
var MASTRA_AUTH_TOKEN_KEY = "mastra__authToken";
var MASTRA_IS_STUDIO_KEY = "mastra__isStudio";
var MASTRA_CLIENT_TYPE_HEADER = "x-mastra-client-type";
var MASTRA_STUDIO_CLIENT_TYPE = "studio";
var RESERVED_CONTEXT_KEYS = /* @__PURE__ */ new Set([
  MASTRA_RESOURCE_ID_KEY,
  MASTRA_THREAD_ID_KEY,
  MASTRA_AUTH_TOKEN_KEY,
  MASTRA_IS_STUDIO_KEY
]);
function isReservedRequestContextKey(key) {
  return RESERVED_CONTEXT_KEYS.has(key);
}
function isStudioClientTypeHeader(value) {
  return value?.toLowerCase() === MASTRA_STUDIO_CLIENT_TYPE;
}
var WORKSPACE_TOOLS_PREFIX = "mastra_workspace";
var WORKSPACE_TOOLS = {
  FILESYSTEM: {
    READ_FILE: `${WORKSPACE_TOOLS_PREFIX}_read_file`,
    WRITE_FILE: `${WORKSPACE_TOOLS_PREFIX}_write_file`,
    EDIT_FILE: `${WORKSPACE_TOOLS_PREFIX}_edit_file`,
    LIST_FILES: `${WORKSPACE_TOOLS_PREFIX}_list_files`,
    DELETE: `${WORKSPACE_TOOLS_PREFIX}_delete`,
    FILE_STAT: `${WORKSPACE_TOOLS_PREFIX}_file_stat`,
    MKDIR: `${WORKSPACE_TOOLS_PREFIX}_mkdir`,
    GREP: `${WORKSPACE_TOOLS_PREFIX}_grep`
  },
  SANDBOX: {
    EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command`
  },
  SEARCH: {
    SEARCH: `${WORKSPACE_TOOLS_PREFIX}_search`,
    INDEX: `${WORKSPACE_TOOLS_PREFIX}_index`
  }
};
async function resolveDynamicValue(value, context, safeDefault) {
  if (value === void 0) return safeDefault;
  if (typeof value === "boolean") return value;
  if (!context) return safeDefault;
  try {
    return await value(context);
  } catch (error) {
    console.warn("[Workspace Tools] Dynamic config function threw, using safe default:", error);
    return safeDefault;
  }
}
async function resolveToolConfig(toolsConfig, toolName, context) {
  let enabled = true;
  let requireApproval = false;
  let requireReadBeforeWrite;
  if (toolsConfig) {
    if (toolsConfig.enabled !== void 0) {
      enabled = toolsConfig.enabled;
    }
    if (toolsConfig.requireApproval !== void 0) {
      requireApproval = toolsConfig.requireApproval;
    }
    const perToolConfig = toolsConfig[toolName];
    if (perToolConfig) {
      if (perToolConfig.enabled !== void 0) {
        enabled = perToolConfig.enabled;
      }
      if (perToolConfig.requireApproval !== void 0) {
        requireApproval = perToolConfig.requireApproval;
      }
      if (perToolConfig.requireReadBeforeWrite !== void 0) {
        requireReadBeforeWrite = perToolConfig.requireReadBeforeWrite;
      }
    }
  }
  return {
    enabled: await resolveDynamicValue(enabled, context, false),
    requireApproval: await resolveDynamicValue(requireApproval, context, true),
    requireReadBeforeWrite: requireReadBeforeWrite !== void 0 ? await resolveDynamicValue(requireReadBeforeWrite, context, true) : void 0
  };
}

export { MASTRA_AUTH_TOKEN_KEY, MASTRA_CLIENT_TYPE_HEADER, MASTRA_IS_STUDIO_KEY, MASTRA_RESOURCE_ID_KEY, MASTRA_STUDIO_CLIENT_TYPE, MASTRA_THREAD_ID_KEY, WORKSPACE_TOOLS, isReservedRequestContextKey, isStudioClientTypeHeader, resolveToolConfig };
//# sourceMappingURL=chunk-YARY4I5U.js.map
//# sourceMappingURL=chunk-YARY4I5U.js.map