{"version":3,"sources":["../../../tools/codebase_search/core.ts","../../../package.json","../../../version.ts","../../../tools/utils/resilience.ts","../../../logger.ts","../../../core/error.ts","../../../core/client.ts","../../../core/resource.ts"],"sourcesContent":["/**\n * Core implementation for codebase search.\n * Calls the Morph rerank service for two-stage semantic search over the\n * code-storage host, through the shared `MorphAPIClient` transport.\n */\nimport { MorphAPIClient } from '../../core/client.js';\nimport { APIResource } from '../../core/resource.js';\nimport { MorphError } from '../utils/resilience.js';\nimport { logger } from '../../logger.js';\nimport type { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './types.js';\n\nconst DEFAULT_TIMEOUT = 30000;\n\nconst emptyStats = { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 };\n\n/**\n * Run a search against `/v1/codebase_search` on the repos host. HTTP failures\n * are returned in-band as `{ success: false, error }` (never thrown), matching\n * the long-standing contract callers rely on.\n */\nasync function runSearch(\n  client: MorphAPIClient,\n  input: CodebaseSearchInput,\n  repoId: string,\n  timeout: number,\n  baseURL?: string,\n): Promise<CodebaseSearchResult> {\n  const startTime = Date.now();\n  logger.debug('CodebaseSearch', 'request', { query: input.query.slice(0, 100), repo_id: repoId });\n\n  try {\n    const data = await client.post<{ results?: unknown[]; stats?: CodebaseSearchResult['stats'] }>(\n      '/v1/codebase_search',\n      {\n        baseURL: baseURL ?? client.reposURL,\n        timeout,\n        body: {\n          query: input.query,\n          repoId,\n          targetDirectories: input.target_directories || [],\n          limit: input.limit || 10,\n          candidateLimit: 50,\n        },\n      },\n    );\n\n    const elapsed = Date.now() - startTime;\n    logger.debug('CodebaseSearch', 'response', { results_count: data.results?.length || 0, latency_ms: elapsed });\n    return {\n      success: true,\n      results: (data.results as CodebaseSearchResult['results']) || [],\n      stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed },\n    };\n  } catch (error) {\n    const message =\n      error instanceof MorphError && error.statusCode\n        ? `Search failed (${error.statusCode}): ${error.message}`\n        : error instanceof Error\n          ? error.message\n          : 'Unknown error';\n    logger.error('CodebaseSearch', 'error', { error: message, latency_ms: Date.now() - startTime });\n    return { success: false, results: [], stats: { ...emptyStats }, error: message };\n  }\n}\n\n/**\n * CodebaseSearch client for programmatic semantic search\n *\n * @deprecated Prefer the unified `MorphClient` (`new MorphClient({ apiKey }).codebaseSearch`).\n * Standalone clients remain only for backwards compatibility and may be removed in a future\n * major version — do not use them in new code.\n */\nexport class CodebaseSearchClient extends APIResource {\n  private readonly timeout: number;\n\n  constructor(\n    clientOrConfig: MorphAPIClient | { apiKey?: string; debug?: boolean; timeout?: number; retryConfig?: any } = {},\n  ) {\n    super(\n      clientOrConfig instanceof MorphAPIClient\n        ? clientOrConfig\n        : new MorphAPIClient({\n            apiKey: clientOrConfig.apiKey,\n            timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,\n            retryConfig: clientOrConfig.retryConfig,\n            debug: clientOrConfig.debug,\n          }),\n    );\n    this.timeout = (clientOrConfig instanceof MorphAPIClient ? undefined : clientOrConfig.timeout) ?? DEFAULT_TIMEOUT;\n  }\n\n  /**\n   * Execute a semantic code search\n   *\n   * @param input - Search parameters including query, repoId, and target directories\n   * @param overrides - Optional config overrides for this operation\n   * @returns Search results with ranked code matches\n   */\n  async search(\n    input: { query: string; repoId: string; target_directories?: string[]; explanation?: string; limit?: number },\n    overrides?: { searchUrl?: string; timeout?: number },\n  ): Promise<CodebaseSearchResult> {\n    return runSearch(\n      this._client,\n      { query: input.query, target_directories: input.target_directories, explanation: input.explanation, limit: input.limit },\n      input.repoId,\n      overrides?.timeout ?? this.timeout,\n      overrides?.searchUrl,\n    );\n  }\n}\n\n/**\n * Execute semantic code search (standalone — builds its own transport).\n * Throws on a missing API key; returns `{ success: false, error }` on HTTP failure.\n */\nexport async function executeCodebaseSearch(\n  input: CodebaseSearchInput,\n  config: CodebaseSearchConfig,\n): Promise<CodebaseSearchResult> {\n  const apiKey = config.apiKey || process.env.MORPH_API_KEY;\n  if (!apiKey) {\n    throw new Error('MORPH_API_KEY not found. Set environment variable or pass in config');\n  }\n\n  const client = new MorphAPIClient({\n    apiKey,\n    reposURL: config.searchUrl,\n    timeout: config.timeout ?? DEFAULT_TIMEOUT,\n    retryConfig: config.retryConfig,\n    debug: config.debug,\n  });\n\n  return runSearch(client, input, config.repoId, config.timeout ?? DEFAULT_TIMEOUT, config.searchUrl);\n}\n","{\n  \"name\": \"@morphllm/morphsdk\",\n  \"version\": \"0.2.194\",\n  \"description\": \"TypeScript SDK and CLI for Morph Fast Apply integration\",\n  \"type\": \"module\",\n  \"main\": \"./dist/index.cjs\",\n  \"module\": \"./dist/index.js\",\n  \"types\": \"./dist/index.d.ts\",\n  \"exports\": {\n    \".\": {\n      \"types\": \"./dist/index.d.ts\",\n      \"import\": \"./dist/index.js\",\n      \"require\": \"./dist/index.cjs\"\n    },\n    \"./logger\": {\n      \"types\": \"./dist/logger.d.ts\",\n      \"import\": \"./dist/logger.js\",\n      \"require\": \"./dist/logger.cjs\"\n    },\n    \"./edge\": {\n      \"types\": \"./dist/edge.d.ts\",\n      \"import\": \"./dist/edge.js\",\n      \"require\": \"./dist/edge.cjs\"\n    },\n    \"./tools/warp-grep\": {\n      \"types\": \"./dist/tools/warp_grep/index.d.ts\",\n      \"import\": \"./dist/tools/warp_grep/index.js\",\n      \"require\": \"./dist/tools/warp_grep/index.cjs\"\n    },\n    \"./tools/warp-grep/openai\": {\n      \"types\": \"./dist/tools/warp_grep/openai.d.ts\",\n      \"import\": \"./dist/tools/warp_grep/openai.js\",\n      \"require\": \"./dist/tools/warp_grep/openai.cjs\"\n    },\n    \"./tools/warp-grep/anthropic\": {\n      \"types\": \"./dist/tools/warp_grep/anthropic.d.ts\",\n      \"import\": \"./dist/tools/warp_grep/anthropic.js\",\n      \"require\": \"./dist/tools/warp_grep/anthropic.cjs\"\n    },\n    \"./tools/warp-grep/vercel\": {\n      \"types\": \"./dist/tools/warp_grep/vercel.d.ts\",\n      \"import\": \"./dist/tools/warp_grep/vercel.js\",\n      \"require\": \"./dist/tools/warp_grep/vercel.cjs\"\n    },\n    \"./tools/warp-grep/client\": {\n      \"types\": \"./dist/tools/warp_grep/client.d.ts\",\n      \"import\": \"./dist/tools/warp_grep/client.js\",\n      \"require\": \"./dist/tools/warp_grep/client.cjs\"\n    },\n    \"./tools/warp-grep/gemini\": {\n      \"types\": \"./dist/tools/warp_grep/gemini.d.ts\",\n      \"import\": \"./dist/tools/warp_grep/gemini.js\",\n      \"require\": \"./dist/tools/warp_grep/gemini.cjs\"\n    },\n    \"./tools/warp-grep/harness\": {\n      \"types\": \"./dist/tools/warp_grep/harness.d.ts\",\n      \"import\": \"./dist/tools/warp_grep/harness.js\",\n      \"require\": \"./dist/tools/warp_grep/harness.cjs\"\n    },\n    \"./tracing\": {\n      \"types\": \"./dist/tracing/index.d.ts\",\n      \"import\": \"./dist/tracing/index.js\",\n      \"require\": \"./dist/tracing/index.cjs\"\n    },\n    \"./tracing/otel\": {\n      \"types\": \"./dist/tracing/otel.d.ts\",\n      \"import\": \"./dist/tracing/otel.js\",\n      \"require\": \"./dist/tracing/otel.cjs\"\n    },\n    \"./tools/fastapply\": {\n      \"types\": \"./dist/tools/fastapply/index.d.ts\",\n      \"import\": \"./dist/tools/fastapply/index.js\",\n      \"require\": \"./dist/tools/fastapply/index.cjs\"\n    },\n    \"./tools/fastapply/anthropic\": {\n      \"types\": \"./dist/tools/fastapply/anthropic.d.ts\",\n      \"import\": \"./dist/tools/fastapply/anthropic.js\",\n      \"require\": \"./dist/tools/fastapply/anthropic.cjs\"\n    },\n    \"./tools/fastapply/openai\": {\n      \"types\": \"./dist/tools/fastapply/openai.d.ts\",\n      \"import\": \"./dist/tools/fastapply/openai.js\",\n      \"require\": \"./dist/tools/fastapply/openai.cjs\"\n    },\n    \"./tools/fastapply/vercel\": {\n      \"types\": \"./dist/tools/fastapply/vercel.d.ts\",\n      \"import\": \"./dist/tools/fastapply/vercel.js\",\n      \"require\": \"./dist/tools/fastapply/vercel.cjs\"\n    },\n    \"./tools/codebase-search\": {\n      \"types\": \"./dist/tools/codebase_search/index.d.ts\",\n      \"import\": \"./dist/tools/codebase_search/index.js\",\n      \"require\": \"./dist/tools/codebase_search/index.cjs\"\n    },\n    \"./tools/codebase-search/anthropic\": {\n      \"types\": \"./dist/tools/codebase_search/anthropic.d.ts\",\n      \"import\": \"./dist/tools/codebase_search/anthropic.js\",\n      \"require\": \"./dist/tools/codebase_search/anthropic.cjs\"\n    },\n    \"./tools/codebase-search/openai\": {\n      \"types\": \"./dist/tools/codebase_search/openai.d.ts\",\n      \"import\": \"./dist/tools/codebase_search/openai.js\",\n      \"require\": \"./dist/tools/codebase_search/openai.cjs\"\n    },\n    \"./tools/codebase-search/vercel\": {\n      \"types\": \"./dist/tools/codebase_search/vercel.d.ts\",\n      \"import\": \"./dist/tools/codebase_search/vercel.js\",\n      \"require\": \"./dist/tools/codebase_search/vercel.cjs\"\n    },\n    \"./tools/git\": {\n      \"types\": \"./dist/git/index.d.ts\",\n      \"import\": \"./dist/git/index.js\",\n      \"require\": \"./dist/git/index.cjs\"\n    },\n    \"./tools/browser\": {\n      \"types\": \"./dist/tools/browser/index.d.ts\",\n      \"import\": \"./dist/tools/browser/index.js\",\n      \"require\": \"./dist/tools/browser/index.cjs\"\n    },\n    \"./tools/browser/anthropic\": {\n      \"types\": \"./dist/tools/browser/anthropic.d.ts\",\n      \"import\": \"./dist/tools/browser/anthropic.js\",\n      \"require\": \"./dist/tools/browser/anthropic.cjs\"\n    },\n    \"./tools/browser/openai\": {\n      \"types\": \"./dist/tools/browser/openai.d.ts\",\n      \"import\": \"./dist/tools/browser/openai.js\",\n      \"require\": \"./dist/tools/browser/openai.cjs\"\n    },\n    \"./tools/browser/vercel\": {\n      \"types\": \"./dist/tools/browser/vercel.d.ts\",\n      \"import\": \"./dist/tools/browser/vercel.js\",\n      \"require\": \"./dist/tools/browser/vercel.cjs\"\n    },\n    \"./tools/browser/profiles\": {\n      \"types\": \"./dist/tools/browser/profiles/index.d.ts\",\n      \"import\": \"./dist/tools/browser/profiles/index.js\",\n      \"require\": \"./dist/tools/browser/profiles/index.cjs\"\n    },\n    \"./modelrouter\": {\n      \"types\": \"./dist/modelrouter/index.d.ts\",\n      \"import\": \"./dist/modelrouter/index.js\",\n      \"require\": \"./dist/modelrouter/index.cjs\"\n    },\n    \"./tools/compact\": {\n      \"types\": \"./dist/tools/compact/index.d.ts\",\n      \"import\": \"./dist/tools/compact/index.js\",\n      \"require\": \"./dist/tools/compact/index.cjs\"\n    },\n    \"./tools/reflex\": {\n      \"types\": \"./dist/tools/reflex/index.d.ts\",\n      \"import\": \"./dist/tools/reflex/index.js\",\n      \"require\": \"./dist/tools/reflex/index.cjs\"\n    },\n    \"./tools/traces\": {\n      \"types\": \"./dist/tools/traces/index.d.ts\",\n      \"import\": \"./dist/tools/traces/index.js\",\n      \"require\": \"./dist/tools/traces/index.cjs\"\n    },\n    \"./subagents\": {\n      \"types\": \"./dist/subagents/index.d.ts\",\n      \"import\": \"./dist/subagents/index.js\",\n      \"require\": \"./dist/subagents/index.cjs\"\n    },\n    \"./subagents/vercel\": {\n      \"types\": \"./dist/subagents/vercel.d.ts\",\n      \"import\": \"./dist/subagents/vercel.js\",\n      \"require\": \"./dist/subagents/vercel.cjs\"\n    },\n    \"./subagents/anthropic\": {\n      \"types\": \"./dist/subagents/anthropic.d.ts\",\n      \"import\": \"./dist/subagents/anthropic.js\",\n      \"require\": \"./dist/subagents/anthropic.cjs\"\n    }\n  },\n  \"files\": [\n    \"dist/**/*.js\",\n    \"dist/**/*.cjs\",\n    \"dist/**/*.d.ts\",\n    \"dist/**/*.map\",\n    \"!dist/**/__tests__/**\",\n    \"!dist/**/*.test.*\"\n  ],\n  \"scripts\": {\n    \"build\": \"tsup version.ts index.ts edge.ts client.ts core/index.ts core/client.ts core/resource.ts core/error.ts tools/index.ts tools/fastapply/index.ts tools/fastapply/core.ts tools/fastapply/apply.ts tools/fastapply/types.ts tools/fastapply/prompts.ts tools/fastapply/anthropic.ts tools/fastapply/openai.ts tools/fastapply/vercel.ts tools/codebase_search/index.ts tools/codebase_search/core.ts tools/codebase_search/types.ts tools/codebase_search/prompts.ts tools/codebase_search/anthropic.ts tools/codebase_search/openai.ts tools/codebase_search/vercel.ts tools/warp_grep/index.ts tools/warp_grep/client.ts tools/warp_grep/openai.ts tools/warp_grep/anthropic.ts tools/warp_grep/vercel.ts tools/warp_grep/gemini.ts tools/warp_grep/harness.ts tools/warp_grep/agent/config.ts tools/warp_grep/agent/parser.ts tools/warp_grep/agent/runner.ts tools/warp_grep/agent/types.ts tools/warp_grep/agent/formatter.ts tools/warp_grep/providers/types.ts tools/warp_grep/providers/local.ts tools/warp_grep/providers/remote.ts tools/warp_grep/providers/code_storage_http.ts tools/warp_grep/tools/grep.ts tools/warp_grep/tools/analyse.ts tools/warp_grep/tools/read.ts tools/warp_grep/tools/finish.ts tools/warp_grep/utils/paths.ts tools/warp_grep/utils/github.ts tools/warp_grep/utils/ripgrep.ts tools/warp_grep/utils/format.ts tools/warp_grep/utils/files.ts git/index.ts git/client.ts git/config.ts git/types.ts tools/browser/index.ts tools/browser/core.ts tools/browser/types.ts tools/browser/prompts.ts tools/browser/anthropic.ts tools/browser/openai.ts tools/browser/vercel.ts tools/browser/live.ts tools/browser/errors.ts tools/browser/profiles/index.ts tools/browser/profiles/core.ts tools/browser/profiles/types.ts modelrouter/index.ts modelrouter/core.ts modelrouter/types.ts tools/compact/index.ts tools/compact/core.ts tools/compact/types.ts tools/reflex/index.ts tools/reflex/core.ts tools/reflex/types.ts tools/traces/index.ts tools/traces/core.ts tools/traces/types.ts tools/utils/resilience.ts subagents/index.ts subagents/types.ts subagents/prompts.ts subagents/vercel.ts subagents/anthropic.ts tracing/index.ts tracing/core.ts tracing/interaction.ts tracing/otel.ts tracing/types.ts --format esm,cjs --sourcemap --clean --dts --dts-resolve\",\n    \"prepare\": \"npm run build\",\n    \"typecheck\": \"tsc --noEmit\",\n    \"lint\": \"eslint .\",\n    \"test\": \"vitest run\",\n    \"test:watch\": \"vitest watch\",\n    \"test:anthropic\": \"vitest run anthropic\",\n    \"test:openai\": \"vitest run openai\",\n    \"test:vercel\": \"vitest run vercel\",\n    \"test:git\": \"vitest run git\",\n    \"test:browser\": \"vitest run browser\",\n    \"test:agent\": \"npx tsx tests/fullAgentTest.ts\",\n    \"test:integration\": \"npx tsx tests/fullIntegrationTest.ts\",\n    \"test:e2e\": \"vitest run --config vitest.e2e.config.ts\",\n    \"release:patch\": \"npm version patch && npm publish\",\n    \"release:minor\": \"npm version minor && npm publish\",\n    \"release:major\": \"npm version major && npm publish\"\n  },\n  \"keywords\": [\n    \"morph\",\n    \"fast-apply\",\n    \"cli\",\n    \"sdk\",\n    \"edit-file\"\n  ],\n  \"engines\": {\n    \"node\": \">=18\"\n  },\n  \"license\": \"MIT\",\n  \"dependencies\": {\n    \"@opentelemetry/api\": \"^1.9.0\",\n    \"@opentelemetry/exporter-trace-otlp-http\": \"^0.203.0\",\n    \"@opentelemetry/sdk-trace-base\": \"^2.7.1\",\n    \"@traceloop/node-server-sdk\": \"^0.27.0\",\n    \"@vscode/ripgrep\": \"^1.17.0\",\n    \"ai\": \">=5.0.0\",\n    \"diff\": \"^7.0.0\",\n    \"isomorphic-git\": \"^1.25.10\",\n    \"openai\": \"^4.52.7\",\n    \"zod\": \">=3.23.0\"\n  },\n  \"devDependencies\": {\n    \"@ai-sdk/anthropic\": \"^2.0.70\",\n    \"@ai-sdk/openai\": \"^2.0.35\",\n    \"@anthropic-ai/sdk\": \"^0.30.1\",\n    \"@google/generative-ai\": \"^0.24.1\",\n    \"@types/diff\": \"^7.0.2\",\n    \"@types/node\": \"^20.14.10\",\n    \"@typescript-eslint/eslint-plugin\": \"^7.18.0\",\n    \"@typescript-eslint/parser\": \"^7.18.0\",\n    \"dotenv\": \"^16.4.5\",\n    \"eslint\": \"^8.57.0\",\n    \"shx\": \"^0.3.4\",\n    \"tsup\": \"^8.5.0\",\n    \"tsx\": \"^4.16.2\",\n    \"typescript\": \"^5.5.4\",\n    \"vitest\": \"^2.1.6\"\n  },\n  \"peerDependencies\": {\n    \"@anthropic-ai/sdk\": \">=0.25.0\",\n    \"@google/generative-ai\": \">=0.21.0\",\n    \"ai\": \">=5.0.0\",\n    \"zod\": \">=3.23.0\"\n  },\n  \"peerDependenciesMeta\": {\n    \"@anthropic-ai/sdk\": {\n      \"optional\": true\n    },\n    \"@google/generative-ai\": {\n      \"optional\": true\n    },\n    \"ai\": {\n      \"optional\": true\n    },\n    \"zod\": {\n      \"optional\": true\n    }\n  },\n  \"publishConfig\": {\n    \"access\": \"public\"\n  }\n}\n","import pkg from './package.json' with { type: 'json' };\nexport const SDK_VERSION: string = pkg.version;\n","/**\n * Resilience utilities for retry logic and timeout handling\n */\n\nimport { SDK_VERSION } from '../../version.js';\n\nexport interface RetryConfig {\n  maxRetries?: number;        // Default: 3\n  initialDelay?: number;      // Default: 1000ms\n  maxDelay?: number;          // Default: 30000ms\n  backoffMultiplier?: number; // Default: 2\n  retryableErrors?: string[]; // Default: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND']\n  onRetry?: (attempt: number, error: Error) => void;\n}\n\nconst DEFAULT_RETRY_CONFIG: Required<Omit<RetryConfig, 'onRetry'>> = {\n  maxRetries: 3,\n  initialDelay: 1000,\n  maxDelay: 30000,\n  backoffMultiplier: 2,\n  retryableErrors: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND'],\n};\n\n/**\n * Retry a fetch request with exponential backoff\n * \n * @param url - Request URL\n * @param options - Fetch options\n * @param retryConfig - Retry configuration\n * @returns Response from fetch\n * \n * @example\n * ```typescript\n * const response = await fetchWithRetry(\n *   'https://api.example.com/data',\n *   { method: 'POST', body: JSON.stringify(data) },\n *   { maxRetries: 5, initialDelay: 500 }\n * );\n * ```\n */\nexport async function fetchWithRetry(\n  url: string,\n  options: RequestInit,\n  retryConfig: RetryConfig = {}\n): Promise<Response> {\n  const {\n    maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,\n    initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,\n    maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,\n    backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,\n    retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,\n    onRetry,\n  } = retryConfig;\n\n  let lastError: Error | null = null;\n  let delay = initialDelay;\n\n  // Inject SDK version header (caller-provided headers can override)\n  options = { ...options, headers: { 'X-Morph-SDK-Version': SDK_VERSION, ...options.headers } };\n\n  for (let attempt = 0; attempt <= maxRetries; attempt++) {\n    try {\n      const response = await fetch(url, options);\n      \n      // Retry on 429 (rate limit) or 503 (service unavailable)\n      if (response.status === 429 || response.status === 503) {\n        if (attempt < maxRetries) {\n          // Check for Retry-After header\n          const retryAfter = response.headers.get('Retry-After');\n          const waitTime = retryAfter \n            ? parseInt(retryAfter) * 1000 \n            : Math.min(delay, maxDelay);\n          \n          const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);\n          if (onRetry) {\n            onRetry(attempt + 1, error);\n          }\n          \n          await sleep(waitTime);\n          delay *= backoffMultiplier;\n          continue;\n        }\n      }\n\n      return response;\n    } catch (error) {\n      lastError = error as Error;\n      \n      // Check if error is retryable\n      const isRetryable = retryableErrors.some(errType => \n        lastError?.message?.includes(errType)\n      );\n\n      if (!isRetryable || attempt === maxRetries) {\n        throw lastError;\n      }\n\n      // Exponential backoff\n      const waitTime = Math.min(delay, maxDelay);\n      if (onRetry) {\n        onRetry(attempt + 1, lastError);\n      }\n      \n      await sleep(waitTime);\n      delay *= backoffMultiplier;\n    }\n  }\n\n  throw lastError || new Error('Max retries exceeded');\n}\n\n/**\n * Add timeout to any promise\n * \n * @param promise - Promise to wrap with timeout\n * @param timeoutMs - Timeout in milliseconds\n * @param errorMessage - Optional custom error message\n * @returns Promise that rejects if timeout is reached\n * \n * @example\n * ```typescript\n * const result = await withTimeout(\n *   fetchData(),\n *   5000,\n *   'Data fetch timed out'\n * );\n * ```\n */\nexport async function withTimeout<T>(\n  promise: Promise<T>,\n  timeoutMs: number,\n  errorMessage?: string\n): Promise<T> {\n  let timeoutId: NodeJS.Timeout | number;\n  \n  const timeoutPromise = new Promise<never>((_, reject) => {\n    timeoutId = setTimeout(() => {\n      reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));\n    }, timeoutMs);\n  });\n\n  try {\n    const result = await Promise.race([promise, timeoutPromise]);\n    clearTimeout(timeoutId!);\n    return result;\n  } catch (error) {\n    clearTimeout(timeoutId!);\n    throw error;\n  }\n}\n\n/**\n * Sleep for specified milliseconds\n */\nfunction sleep(ms: number): Promise<void> {\n  return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Unified error type for all tools\n */\nexport class MorphError extends Error {\n  constructor(\n    message: string,\n    public code: string,\n    public statusCode?: number,\n    public retryable: boolean = false\n  ) {\n    super(message);\n    this.name = 'MorphError';\n  }\n}\n\n\n","/**\n * Edge-safe logger.\n *\n * This module is imported transitively by the edge entrypoint\n * (`@morphllm/morphsdk/edge`) via fastapply, modelrouter, etc.\n * Edge runtimes (Vercel Edge Functions, Cloudflare Workers, Deno Deploy)\n * run on V8 isolates — not Node.js — so Node built-ins like fs don't\n * exist. A top-level static import of fs would crash at module-load time,\n * even if createWriteStream is only called conditionally.\n *\n * Fix: we use a dynamic import() behind a runtime check. In Node the\n * import resolves and file logging works normally. In edge runtimes the\n * import rejects and we silently fall back to console-only logging.\n */\n\ntype LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\ninterface WriteStream {\n  write(chunk: string): boolean;\n}\n\nclass MorphLogger {\n  private enabled: boolean;\n  private fileStream: WriteStream | null;\n  /** Resolves once the file stream is initialized (or immediately if no file logging). */\n  readonly ready: Promise<void>;\n\n  constructor() {\n    this.enabled = typeof process !== 'undefined' &&\n      (process.env.MORPH_DEBUG === '1' || !!process.env.MORPH_LOG_FILE);\n    this.fileStream = null;\n\n    const f = typeof process !== 'undefined' ? process.env.MORPH_LOG_FILE : undefined;\n    if (f) {\n      // Dynamic import — never evaluated at parse time, so edge runtimes\n      // don't blow up with \"Module 'fs' not found\".\n      this.ready = import('fs')\n        .then((fs) => {\n          this.fileStream = fs.createWriteStream(f, { flags: 'a' });\n        })\n        .catch(() => {\n          // Edge runtime — fs unavailable, silently skip file logging\n        });\n    } else {\n      this.ready = Promise.resolve();\n    }\n  }\n\n  debug(component: string, msg: string, data?: Record<string, unknown>) { this._log('debug', component, msg, data); }\n  info(component: string, msg: string, data?: Record<string, unknown>) { this._log('info', component, msg, data); }\n  warn(component: string, msg: string, data?: Record<string, unknown>) { this._log('warn', component, msg, data); }\n  error(component: string, msg: string, data?: Record<string, unknown>) { this._log('error', component, msg, data); }\n\n  enable() { this.enabled = true; }\n  get isEnabled() { return this.enabled; }\n\n  private _log(level: LogLevel, component: string, msg: string, data?: Record<string, unknown>) {\n    if (level !== 'error' && !this.enabled) return;\n    const ts = new Date().toISOString();\n    const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;\n    console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);\n    this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...(data && { data }) }) + '\\n');\n  }\n}\n\nexport const logger = new MorphLogger();\n","/**\n * Single error mapper for the SDK transport.\n *\n * Consolidates the per-tool error handling that used to live in every client\n * (compact, reflex, github, …) into one place, preserving the actionable\n * 401/429 messaging. Reuses the existing `MorphError` type so callers that\n * `instanceof MorphError` keep working.\n */\nimport { MorphError } from '../tools/utils/resilience.js';\n\ninterface ApiErrorBody {\n  error?: { message?: string; code?: string; type?: string };\n  message?: string;\n}\n\n/**\n * Turn a non-OK `Response` into a `MorphError`, extracting the API's error\n * message when present and marking 429/503 as retryable.\n */\nexport async function toMorphError(response: Response): Promise<MorphError> {\n  let message = `Morph API request failed (${response.status})`;\n  let code = 'api_error';\n\n  try {\n    const body = (await response.json()) as ApiErrorBody;\n    message = body.error?.message ?? body.message ?? message;\n    code = body.error?.code ?? body.error?.type ?? code;\n  } catch {\n    // Non-JSON body — keep the status-based default message.\n  }\n\n  if (response.status === 401) code = 'authentication_error';\n  if (response.status === 429) code = 'rate_limit_exceeded';\n\n  const retryable = response.status === 429 || response.status === 503;\n  return new MorphError(message, code, response.status, retryable);\n}\n","/**\n * MorphAPIClient — the SDK transport.\n *\n * One place owns authentication, the Morph service hosts, default headers,\n * retries, timeouts, and error mapping. Every resource (FastApply, Compact,\n * Reflex, …) holds a reference to this client and delegates HTTP to it via\n * `get`/`post`/`delete`/`request`, exactly like the OpenAI SDK.\n *\n * This module is intentionally free of tool imports and Node built-ins so it\n * stays edge-safe (it is reachable from `@morphllm/morphsdk/edge` through the\n * Compact and model-router resources).\n */\nimport { fetchWithRetry, withTimeout, MorphError, type RetryConfig } from '../tools/utils/resilience.js';\nimport { logger } from '../logger.js';\nimport { SDK_VERSION } from '../version.js';\nimport { toMorphError } from './error.js';\n\n/** The Morph services the SDK talks to. */\nconst DEFAULT_BASE_URL = 'https://api.morphllm.com';\nconst DEFAULT_REPOS_URL = 'https://repos.morphllm.com';\nconst DEFAULT_BROWSER_URL = 'https://browser.morphllm.com';\nconst DEFAULT_TIMEOUT = 60_000;\n\nconst env = (name: string): string | undefined =>\n  typeof process !== 'undefined' ? process.env?.[name] : undefined;\n\nconst stripTrailingSlash = (url: string): string => url.replace(/\\/+$/, '');\n\nexport interface MorphAPIClientOptions {\n  /** Morph API key. Resolved against `MORPH_API_KEY` at request time if omitted. */\n  apiKey?: string;\n  /** Primary API host (default `https://api.morphllm.com`). */\n  baseURL?: string;\n  /** Code-storage host for codebase search and git (default `https://repos.morphllm.com`). */\n  reposURL?: string;\n  /** Browser-automation host (default `https://browser.morphllm.com`). */\n  browserURL?: string;\n  /** Default per-request timeout in ms (default 60s). Resources may override per call. */\n  timeout?: number;\n  /** Retry policy for transient failures. */\n  retryConfig?: RetryConfig;\n  /** Enable debug logging. */\n  debug?: boolean;\n}\n\n/** Per-request options accepted by `request`/`get`/`post`/`delete`. */\nexport interface RequestOptions {\n  /** JSON body; serialized with `JSON.stringify`. */\n  body?: unknown;\n  /** Query parameters; `undefined`/`null` values are dropped. */\n  query?: Record<string, string | number | boolean | undefined | null>;\n  /** Extra headers, merged over (and able to override) the defaults. */\n  headers?: Record<string, string>;\n  /** Override the timeout for this call. */\n  timeout?: number;\n  /** Hit a different host than the default (e.g. `this._client.reposURL`). */\n  baseURL?: string;\n  /** Return the raw `Response` of a successful (2xx) request instead of parsed JSON (for streaming). */\n  stream?: boolean;\n  /**\n   * Return the raw `Response` without throwing on non-2xx and without parsing.\n   * For resources that map errors into their own taxonomy (e.g. GitHub).\n   */\n  raw?: boolean;\n  /** Caller-supplied abort signal. */\n  signal?: AbortSignal;\n}\n\nexport class MorphAPIClient {\n  /** Explicit key as provided; resolved against env at request time. */\n  apiKey?: string;\n  baseURL: string;\n  reposURL: string;\n  browserURL: string;\n  /** Explicit default timeout (ms), if set. The request default is applied lazily so\n   * resources can read an undefined value and supply their own fallback. */\n  timeout?: number;\n  retryConfig?: RetryConfig;\n  debug: boolean;\n\n  constructor(options: MorphAPIClientOptions = {}) {\n    this.apiKey = options.apiKey;\n    this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);\n    this.reposURL = stripTrailingSlash(options.reposURL ?? env('MORPH_SEARCH_URL') ?? DEFAULT_REPOS_URL);\n    this.browserURL = stripTrailingSlash(\n      options.browserURL ?? (env('MORPH_ENVIRONMENT') === 'DEV' ? 'http://localhost:8000' : DEFAULT_BROWSER_URL),\n    );\n    this.timeout = options.timeout;\n    this.retryConfig = options.retryConfig;\n    this.debug = options.debug ?? false;\n    if (this.debug) logger.enable();\n  }\n\n  /** The key actually used for requests: explicit, else `MORPH_API_KEY`. */\n  resolveApiKey(): string | undefined {\n    return this.apiKey ?? env('MORPH_API_KEY');\n  }\n\n  /** Headers shared with tools that bring their own HTTP client (FastApply/WarpGrep via the `openai` package). */\n  defaultHeaders(): Record<string, string> {\n    return { 'X-Morph-SDK-Version': SDK_VERSION };\n  }\n\n  buildURL(path: string, baseURL?: string): string {\n    if (/^https?:\\/\\//i.test(path)) return path;\n    const base = stripTrailingSlash(baseURL ?? this.baseURL);\n    return `${base}${path.startsWith('/') ? '' : '/'}${path}`;\n  }\n\n  private buildHeaders(apiKey: string, extra?: Record<string, string>): Record<string, string> {\n    return {\n      'Content-Type': 'application/json',\n      'X-Morph-SDK-Version': SDK_VERSION,\n      Authorization: `Bearer ${apiKey}`,\n      ...extra,\n    };\n  }\n\n  private applyQuery(url: string, query?: RequestOptions['query']): string {\n    if (!query) return url;\n    const params = new URLSearchParams();\n    for (const [key, value] of Object.entries(query)) {\n      if (value !== undefined && value !== null) params.set(key, String(value));\n    }\n    const qs = params.toString();\n    return qs ? `${url}${url.includes('?') ? '&' : '?'}${qs}` : url;\n  }\n\n  async request<T>(method: string, path: string, opts: RequestOptions = {}): Promise<T> {\n    const apiKey = this.resolveApiKey();\n    if (!apiKey) {\n      throw new MorphError(\n        'Morph API key not found. Set the MORPH_API_KEY environment variable or pass apiKey in config.',\n        'missing_api_key',\n        401,\n      );\n    }\n\n    const url = this.applyQuery(this.buildURL(path, opts.baseURL), opts.query);\n    const timeout = opts.timeout ?? this.timeout ?? DEFAULT_TIMEOUT;\n\n    const init: RequestInit = {\n      method,\n      headers: this.buildHeaders(apiKey, opts.headers),\n      ...(opts.body !== undefined ? { body: JSON.stringify(opts.body) } : {}),\n      ...(opts.signal ? { signal: opts.signal } : {}),\n    };\n\n    logger.debug('MorphAPIClient', 'request', { method, url });\n\n    const response = await withTimeout(\n      fetchWithRetry(url, init, this.retryConfig ?? {}),\n      timeout,\n      `Morph request to ${url} timed out after ${timeout}ms`,\n    );\n\n    if (opts.raw) return response as unknown as T;\n    if (!response.ok) throw await toMorphError(response);\n    if (opts.stream) return response as unknown as T;\n    if (response.status === 204) return undefined as T;\n\n    const text = await response.text();\n    return (text ? JSON.parse(text) : undefined) as T;\n  }\n\n  get<T>(path: string, opts?: RequestOptions): Promise<T> {\n    return this.request<T>('GET', path, opts);\n  }\n\n  post<T>(path: string, opts?: RequestOptions): Promise<T> {\n    return this.request<T>('POST', path, opts);\n  }\n\n  delete<T>(path: string, opts?: RequestOptions): Promise<T> {\n    return this.request<T>('DELETE', path, opts);\n  }\n}\n","/**\n * Base class for every API resource (FastApply, Compact, Reflex, …).\n *\n * Mirrors the OpenAI SDK's `APIResource`: a resource holds nothing but a\n * reference to the transport (`MorphAPIClient`) and delegates all HTTP to it.\n * Sub-resources receive the same client by reference, so configuration and the\n * fetch/retry/auth machinery live in exactly one place.\n */\nimport type { MorphAPIClient } from './client.js';\n\nexport abstract class APIResource {\n  protected _client: MorphAPIClient;\n\n  constructor(client: MorphAPIClient) {\n    this._client = client;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,MAAQ;AAAA,EACR,QAAU;AAAA,EACV,OAAS;AAAA,EACT,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACb;AAAA,IACA,YAAY;AAAA,MACV,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACb;AAAA,IACA,UAAU;AAAA,MACR,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACb;AAAA,IACA,qBAAqB;AAAA,MACnB,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACb;AAAA,IACA,4BAA4B;AAAA,MAC1B,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACb;AAAA,IACA,+BAA+B;AAAA,MAC7B,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACb;AAAA,IACA,4BAA4B;AAAA,MAC1B,OAAS;AAAA,MACT,Q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