{"version":3,"sources":["../../../tools/fastapply/apply.ts","../../../package.json","../../../version.ts","../../../logger.ts","../../../tools/fastapply/anchors.ts"],"sourcesContent":["/**\n * Edge-compatible code application API\n *\n * This module works on:\n * - Node.js\n * - Cloudflare Workers\n * - Vercel Edge Functions\n * - Deno Deploy\n * - Browser environments\n *\n * For file-based operations, use executeEditFile from core.ts\n */\n\nimport { createTwoFilesPatch } from 'diff';\nimport OpenAI from 'openai';\nimport { SDK_VERSION } from '../../version.js';\nimport { logger } from '../../logger.js';\nimport {\n  createAnchorCompactionPlan,\n  DEFAULT_ANCHOR_COMPACTION_THRESHOLD,\n  FastApplyAnchorIntegrityError,\n} from './anchors.js';\nimport type {\n  EditChanges,\n  ApplyEditInput,\n  ApplyEditResult,\n  ApplyEditConfig,\n} from './types.js';\n\nconst DEFAULT_API_URL = 'https://api.morphllm.com';\nconst DEFAULT_TIMEOUT = 600000;\n\ntype CompletionChunk = {\n  id?: string;\n  choices?: Array<{\n    delta?: { content?: string | null };\n    finish_reason?: string | null;\n  }>;\n};\n\ntype CompletionResponse = {\n  id?: string;\n  choices?: Array<{\n    message?: { content?: string | null };\n    finish_reason?: string | null;\n  }>;\n};\n\nexport class FastApplyContextLengthError extends Error {\n  readonly code = 'context_length_exceeded';\n  readonly completionId?: string;\n\n  constructor(completionId?: string) {\n    super(\n      'Fast Apply exhausted its context window before producing the complete file. ' +\n      'Retry with a smaller input/update or use sparse anchors for unchanged code.'\n    );\n    this.name = 'FastApplyContextLengthError';\n    this.completionId = completionId;\n  }\n}\n\nexport { FastApplyAnchorIntegrityError } from './anchors.js';\n\nfunction isAsyncIterable(value: unknown): value is AsyncIterable<CompletionChunk> {\n  return typeof value === 'object' && value !== null && Symbol.asyncIterator in value;\n}\n\nasync function collectCompletion(\n  response: unknown\n): Promise<{ content: string; completionId?: string; finishReason?: string | null }> {\n  if (!isAsyncIterable(response)) {\n    const completion = response as CompletionResponse;\n    return {\n      content: completion.choices?.[0]?.message?.content ?? '',\n      completionId: completion.id,\n      finishReason: completion.choices?.[0]?.finish_reason,\n    };\n  }\n\n  const content: string[] = [];\n  let completionId: string | undefined;\n  let finishReason: string | null | undefined;\n\n  for await (const chunk of response) {\n    completionId = chunk.id ?? completionId;\n    for (const choice of chunk.choices ?? []) {\n      if (choice.delta?.content) {\n        content.push(choice.delta.content);\n      }\n      if (choice.finish_reason !== undefined && choice.finish_reason !== null) {\n        finishReason = choice.finish_reason;\n      }\n    }\n  }\n\n  return { content: content.join(''), completionId, finishReason };\n}\n\n/**\n * Generate a unified diff between two strings\n */\nexport function generateUdiff(\n  original: string,\n  modified: string,\n  filepath: string\n): string {\n  return createTwoFilesPatch(\n    filepath,\n    filepath,\n    original,\n    modified,\n    'Original',\n    'Modified'\n  );\n}\n\n/**\n * Count changes from a unified diff\n */\nexport function countChanges(original: string, modified: string): EditChanges {\n  const diff = generateUdiff(original, modified, 'file');\n  const lines = diff.split('\\n');\n\n  let linesAdded = 0;\n  let linesRemoved = 0;\n\n  for (const line of lines) {\n    if (line.startsWith('+') && !line.startsWith('+++')) {\n      linesAdded++;\n    } else if (line.startsWith('-') && !line.startsWith('---')) {\n      linesRemoved++;\n    }\n  }\n\n  const linesModified = Math.min(linesAdded, linesRemoved);\n\n  return {\n    linesAdded: linesAdded - linesModified,\n    linesRemoved: linesRemoved - linesModified,\n    linesModified,\n  };\n}\n\n/**\n * Call Morph Apply API to merge code edits\n * Uses OpenAI SDK for reliable connection handling, retries, and timeouts\n */\nexport async function callMorphAPI(\n  originalCode: string,\n  codeEdit: string,\n  instructions: string,\n  filepath: string,\n  config: ApplyEditConfig\n): Promise<{ content: string; completionId?: string }> {\n  const apiKey = config.morphApiKey || (typeof process !== 'undefined' ? process.env?.MORPH_API_KEY : undefined);\n  const apiUrl = config.morphApiUrl || DEFAULT_API_URL;\n  const useLarge = config.large ?? (typeof process !== 'undefined' ? process.env?.MORPH_LARGE_APPLY !== 'false' : true);\n  const model = useLarge ? 'morph-v3-large' : 'morph-v3-fast';\n  const timeout = config.timeout ?? DEFAULT_TIMEOUT;\n  const debug = config.debug || false;\n\n  if (!apiKey) {\n    throw new Error(\n      'Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config.'\n    );\n  }\n\n  const anchorThreshold = config.anchorCompactionThreshold\n    ?? DEFAULT_ANCHOR_COMPACTION_THRESHOLD;\n  const anchorPlan = config.anchorCompaction !== false\n    && originalCode.length >= anchorThreshold\n    ? createAnchorCompactionPlan(originalCode, [codeEdit, instructions])\n    : undefined;\n  const requestCode = anchorPlan?.code ?? originalCode;\n  const requestInstructions = anchorPlan\n    ? instructions + anchorPlan.instructionSuffix\n    : instructions;\n\n  // Format message with XML tags as per Morph Fast Apply spec\n  const message = `<instruction>${requestInstructions}</instruction>\\n<code>${requestCode}</code>\\n<update>${codeEdit}</update>`;\n\n  logger.debug('FastApply', 'http_request', {\n    url: `${apiUrl}/v1/chat/completions`,\n    model,\n    filepath,\n    instruction_len: instructions.length,\n    original_len: originalCode.length,\n    request_code_len: requestCode.length,\n    code_edit_len: codeEdit.length,\n    anchor_count: anchorPlan?.anchorCount ?? 0,\n    unique_anchor_count: anchorPlan?.uniqueAnchorCount ?? 0,\n  });\n\n  const startTime = Date.now();\n\n  const client = new OpenAI({\n    apiKey,\n    baseURL: `${apiUrl}/v1`,\n    timeout,\n    maxRetries: config.retryConfig?.maxRetries ?? 3,\n    defaultHeaders: {\n      'X-Morph-SDK-Version': SDK_VERSION,\n      ...(anchorPlan ? { 'X-Morph-Apply-Context': 'extralong' } : {}),\n    },\n  });\n\n  try {\n    const maxAttempts = anchorPlan?.hasStructuralValidation ? 2 : 1;\n    for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n      const response = await client.chat.completions.create({\n        model,\n        messages: [{ role: 'user', content: message }],\n        stream: true,\n      });\n      const completion = await collectCompletion(response);\n\n      if (completion.finishReason === 'length') {\n        throw new FastApplyContextLengthError(completion.completionId);\n      }\n\n      let content = completion.content;\n      if (!content) {\n        throw new Error('Morph API returned empty response');\n      }\n\n      if (anchorPlan) {\n        try {\n          content = anchorPlan.expand(content);\n        } catch (error) {\n          if (error instanceof FastApplyAnchorIntegrityError) {\n            if (attempt < maxAttempts) {\n              logger.warn('FastApply', 'anchor_validation_retry', {\n                attempt,\n                completion_id: completion.completionId,\n              });\n              continue;\n            }\n            throw new FastApplyAnchorIntegrityError(completion.completionId);\n          }\n          throw error;\n        }\n      }\n\n      const elapsed = Date.now() - startTime;\n      logger.debug('FastApply', 'http_response', { status: 200, completion_id: completion.completionId, content_len: content.length, latency_ms: elapsed });\n\n      return { content, completionId: completion.completionId };\n    }\n\n    throw new FastApplyAnchorIntegrityError();\n  } catch (error: any) {\n    const elapsed = Date.now() - startTime;\n    const status = error?.status || error?.response?.status;\n    logger.error('FastApply', 'http_error', {\n      status,\n      error: error?.message,\n      latency_ms: elapsed,\n    });\n\n    if (status === 401) {\n      const err = new Error(\n        'Authentication failed: Your Morph API key is invalid or has been revoked. ' +\n        'Please visit https://morphllm.com to get a valid API key, then update your MCP configuration.'\n      );\n      (err as any).status = 401;\n      throw err;\n    }\n\n    if (status === 429) {\n      const err = new Error(\n        'Rate limited: You\\'ve exceeded your Morph API usage limits. ' +\n        'Please visit https://morphllm.com to check your plan and purchase additional credits.'\n      );\n      (err as any).status = 429;\n      throw err;\n    }\n\n    throw error;\n  }\n}\n\n/**\n * Apply an edit to code directly without file I/O\n *\n * This is the edge-compatible code-in/code-out API that accepts code content directly\n * and returns the merged result without reading or writing any files.\n *\n * Works on Cloudflare Workers, Vercel Edge Functions, Deno, and browsers.\n *\n * @param input - Code and edit parameters\n * @param config - Optional configuration\n * @returns Result with merged code\n *\n * @example\n * ```typescript\n * import { applyEdit } from '@morphllm/morphsdk';\n *\n * const result = await applyEdit({\n *   originalCode: fs.readFileSync('file.ts', 'utf-8'),\n *   codeEdit: '// ... existing code ...\\nconst newVar = 42;\\n// ... existing code ...',\n *   instructions: 'Add a new variable',\n *   // filepath is accepted but does nothing\n * });\n *\n * if (result.success) {\n *   fs.writeFileSync('file.ts', result.mergedCode);\n * }\n * ```\n */\nexport async function applyEdit(\n  input: ApplyEditInput,\n  config: ApplyEditConfig = {}\n): Promise<ApplyEditResult> {\n  const filepath = input.filepath || 'file';\n\n  try {\n    logger.debug('FastApply', 'apply_edit_start', { original_len: input.originalCode.length, code_edit_len: input.codeEdit.length });\n\n    const instruction = input.instruction ?? input.instructions ?? '';\n    const { content: mergedCode, completionId } = await callMorphAPI(\n      input.originalCode,\n      input.codeEdit,\n      instruction,\n      filepath,\n      config\n    );\n\n    const udiff = config.generateUdiff !== false\n      ? generateUdiff(input.originalCode, mergedCode, filepath)\n      : undefined;\n\n    const changes = countChanges(input.originalCode, mergedCode);\n\n    return {\n      success: true,\n      mergedCode,\n      udiff,\n      changes,\n      completionId,\n    };\n  } catch (error) {\n    const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';\n    logger.error('FastApply', 'apply_edit_error', { error: errorMessage });\n    const structuredError = error instanceof FastApplyContextLengthError\n      || error instanceof FastApplyAnchorIntegrityError\n      ? error\n      : undefined;\n\n    return {\n      success: false,\n      changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },\n      error: errorMessage,\n      errorCode: structuredError?.code,\n      completionId: structuredError?.completionId,\n    };\n  }\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 * 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","const DEFAULT_MIN_ANCHOR_LINE_LENGTH = 24;\n\nexport const DEFAULT_ANCHOR_COMPACTION_THRESHOLD = 128 * 1024;\n\nexport interface AnchorCompactionPlan {\n  code: string;\n  instructionSuffix: string;\n  anchorCount: number;\n  uniqueAnchorCount: number;\n  hasStructuralValidation: boolean;\n  expand: (content: string) => string;\n}\n\nexport class FastApplyAnchorIntegrityError extends Error {\n  readonly code = 'anchor_integrity_failed';\n  readonly completionId?: string;\n\n  constructor(completionId?: string) {\n    super(\n      'Fast Apply failed large-file anchor integrity checks. The partial result was discarded safely.'\n    );\n    this.name = 'FastApplyAnchorIntegrityError';\n    this.completionId = completionId;\n  }\n}\n\nfunction escapeRegExp(value: string): string {\n  return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction findNamespace(values: string[]): number {\n  for (let namespace = 0; namespace < Number.MAX_SAFE_INTEGER; namespace++) {\n    const prefix = `⟪M${namespace}:`;\n    if (values.every((value) => !value.includes(prefix))) {\n      return namespace;\n    }\n  }\n\n  throw new Error('Unable to allocate a Fast Apply anchor namespace');\n}\n\ninterface SourceUnit {\n  value: string;\n  label?: string;\n  anchorable: boolean;\n}\n\nfunction htmlLabel(token: string): string {\n  if (!token.startsWith('<')) return 'text';\n  const match = token.match(/^<\\s*(!doctype|\\/?[a-zA-Z][\\w:-]*)/);\n  return (match?.[1] ?? 'tag').toLowerCase();\n}\n\nfunction htmlTokenUnits(value: string, visibleTags = new Set<string>()): SourceUnit[] {\n  return (value.match(/<[^>]*>|[^<]+/g) ?? [value]).map((token) => ({\n    value: token,\n    label: htmlLabel(token),\n    anchorable: token.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH\n      && !visibleTags.has(htmlLabel(token).replace(/^\\//, '')),\n  }));\n}\n\nfunction sourceUnits(originalCode: string, editContext: string[]): SourceUnit[] {\n  const trimmed = originalCode.trimStart().toLowerCase();\n  const looksLikeHtml = (trimmed.startsWith('<!doctype') || trimmed.startsWith('<html'))\n    && /<\\/html\\s*>/i.test(originalCode);\n\n  if (looksLikeHtml) {\n    const contextWords = new Set(\n      editContext.join(' ').toLowerCase().match(/[a-z][\\w:-]*/g) ?? []\n    );\n    return htmlTokenUnits(originalCode, contextWords);\n  }\n\n  const parts = originalCode.split(/(\\r\\n|\\n|\\r)/);\n  const units: SourceUnit[] = [];\n  for (let index = 0; index < parts.length; index += 2) {\n    const line = parts[index] ?? '';\n    const lineEnding = parts[index + 1] ?? '';\n    units.push({\n      value: line,\n      label: 'line',\n      anchorable: line.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH,\n    });\n    if (lineEnding) {\n      units.push({ value: lineEnding, anchorable: false });\n    }\n  }\n  return units;\n}\n\nfunction copyCount(value: string): number | undefined {\n  const words: Record<string, number> = {\n    one: 1,\n    two: 2,\n    three: 3,\n    four: 4,\n    five: 5,\n    six: 6,\n    seven: 7,\n    eight: 8,\n    nine: 9,\n    ten: 10,\n  };\n  return /^\\d+$/.test(value) ? Number(value) : words[value.toLowerCase()];\n}\n\nfunction structuralExpectation(originalCode: string, editContext: string[]) {\n  const context = editContext.join(' ');\n  const match = context.match(\n    /(?:for every|for each|each)\\s+([a-z][\\w:-]*)[\\s\\S]{0,120}?add\\s+(one|two|three|four|five|six|seven|eight|nine|ten|\\d+)\\s+identical cop(?:y|ies)/i\n  );\n  if (!match) return undefined;\n\n  const tag = match[1]!.toLowerCase();\n  const addedCopies = copyCount(match[2]!);\n  if (addedCopies === undefined) return undefined;\n\n  const tagPattern = new RegExp(`<${escapeRegExp(tag)}(?:\\\\s|>)`, 'gi');\n  const originalCount = originalCode.match(tagPattern)?.length ?? 0;\n  if (originalCount === 0) return undefined;\n\n  return { tag, expectedCount: originalCount * (addedCopies + 1) };\n}\n\n/**\n * Replace long source fragments with lossless placeholders. Definitions are sent once,\n * while the model can emit a small skeleton containing repeated/moved placeholders.\n */\nexport function createAnchorCompactionPlan(\n  originalCode: string,\n  collisionValues: string[] = []\n): AnchorCompactionPlan | undefined {\n  const namespace = findNamespace([originalCode, ...collisionValues]);\n  const expectation = structuralExpectation(originalCode, collisionValues);\n  const markerPrefix = `⟪M${namespace}:`;\n  const definitions = new Map<string, number>();\n  const values: string[] = [];\n  const markers: string[] = [];\n  let anchorCount = 0;\n  let skeleton = '';\n\n  for (const unit of sourceUnits(originalCode, collisionValues)) {\n    if (!unit.anchorable) {\n      skeleton += unit.value;\n      continue;\n    }\n\n    let id = definitions.get(unit.value);\n    if (id === undefined) {\n      id = values.length;\n      definitions.set(unit.value, id);\n      values.push(unit.value);\n      markers.push(`${markerPrefix}${id}:${unit.label ?? 'unit'}⟫`);\n    }\n\n    skeleton += markers[id];\n    anchorCount++;\n  }\n\n  if (anchorCount === 0 || skeleton.length >= originalCode.length) {\n    return undefined;\n  }\n\n  const definitionsBegin = `⟪MORPH_DEFINITIONS_BEGIN_${namespace}⟫`;\n  const definitionsEnd = `⟪MORPH_DEFINITIONS_END_${namespace}⟫`;\n  const codeBegin = `⟪MORPH_CODE_BEGIN_${namespace}⟫`;\n  const serializedDefinitions = values\n    .map((value, id) => `${markers[id]}=${JSON.stringify(value)}`)\n    .join('\\n');\n\n  const code = [\n    definitionsBegin,\n    serializedDefinitions,\n    definitionsEnd,\n    codeBegin,\n    skeleton,\n  ].join('\\n');\n\n  const instructionSuffix = `\n\nLARGE-FILE ANCHOR PROTOCOL:\nThe <code> block starts with an exact anchor definition table, then ${codeBegin}, then the source skeleton.\nEach ${markerPrefix}N:kind⟫ placeholder represents the exact source fragment in its matching JSON-string definition. The kind suffix describes its HTML tag, text, or source line.\nReturn only the updated source skeleton after ${codeBegin}; never return the definition table or protocol delimiters.\nCopy a placeholder exactly when its source fragment is unchanged. You may repeat, reorder, or remove placeholders when the requested edit requires it.\nTo modify an anchored fragment, output the modified source instead of its placeholder.\nDo not invent or alter placeholder IDs.`;\n\n  const markerPattern = new RegExp(`${escapeRegExp(markerPrefix)}(\\\\d+):[^⟫]+⟫`, 'g');\n\n  return {\n    code,\n    instructionSuffix,\n    anchorCount,\n    uniqueAnchorCount: values.length,\n    hasStructuralValidation: expectation !== undefined,\n    expand(content: string): string {\n      const codeBeginIndex = content.lastIndexOf(codeBegin);\n      const skeletonContent = codeBeginIndex >= 0\n        ? content.slice(codeBeginIndex + codeBegin.length).replace(/^\\r?\\n/, '')\n        : content;\n\n      const expanded = skeletonContent.replace(markerPattern, (marker, idText: string) => {\n        const id = Number(idText);\n        const value = values[id];\n        return value === undefined || markers[id] !== marker ? marker : value;\n      });\n\n      if (expanded.includes(markerPrefix)) {\n        throw new FastApplyAnchorIntegrityError();\n      }\n\n      if (expectation) {\n        const tagPattern = new RegExp(`<${escapeRegExp(expectation.tag)}(?:\\\\s|>)`, 'gi');\n        const actualCount = expanded.match(tagPattern)?.length ?? 0;\n        if (actualCount !== expectation.expectedCount) {\n          throw new FastApplyAnchorIntegrityError();\n        }\n      }\n\n      return expanded;\n    },\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,kBAAoC;AACpC,oBAAmB;;;ACdnB;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,MAC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