@morphllm/morphsdk 0.2.192 → 0.2.194
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-OXVH7KJ7.js → chunk-2JKIWBME.js} +2 -2
- package/dist/{chunk-X57U7AHA.js → chunk-2THF6MNE.js} +2 -2
- package/dist/{chunk-4E2HKWUQ.js → chunk-33WVJLIT.js} +2 -2
- package/dist/{chunk-RAWFZX7R.js → chunk-74LJOCDW.js} +2 -2
- package/dist/{chunk-XT75CKB2.js → chunk-7KAW6EUG.js} +21 -21
- package/dist/{chunk-3RIS4CS2.js → chunk-A2SC5ZOG.js} +2 -2
- package/dist/{chunk-3RIS4CS2.js.map → chunk-A2SC5ZOG.js.map} +1 -1
- package/dist/{chunk-45HXBGGH.js → chunk-C225GOV2.js} +2 -2
- package/dist/{chunk-DRM3ETEL.js → chunk-CKSINYRF.js} +2 -2
- package/dist/{chunk-4BALDMIZ.js → chunk-DL4EUMBV.js} +2 -2
- package/dist/{chunk-NDUHOFAN.js → chunk-EM7BMNSS.js} +2 -2
- package/dist/{chunk-CKN2RJPD.js → chunk-FM2L35XC.js} +2 -2
- package/dist/{chunk-F4L7PCXV.js → chunk-GRYLQ2HM.js} +2 -2
- package/dist/{chunk-EABWHIAS.js → chunk-GWXMT3S2.js} +13 -4
- package/dist/chunk-GWXMT3S2.js.map +1 -0
- package/dist/{chunk-EUZCZNK4.js → chunk-JIHDKRQW.js} +2 -2
- package/dist/chunk-KGHHK42W.js +399 -0
- package/dist/chunk-KGHHK42W.js.map +1 -0
- package/dist/{chunk-UCDN6SER.js → chunk-MFAIFUFK.js} +2 -2
- package/dist/{chunk-VLZ6PNAD.js → chunk-OPNTDMHH.js} +4 -4
- package/dist/{chunk-4EZ7L6FJ.js → chunk-PDSLRLYI.js} +3 -3
- package/dist/{chunk-2W54UBCR.js → chunk-POUBLP4R.js} +4 -4
- package/dist/{chunk-OZDNWR3I.js → chunk-PPNJY7P3.js} +3 -3
- package/dist/{chunk-24ID7P4E.js → chunk-PUTYJ2ET.js} +4 -4
- package/dist/{chunk-A777CPSD.js → chunk-QJSGHJ7D.js} +2 -2
- package/dist/{chunk-G5J5ZHCG.js → chunk-S3V22W7M.js} +2 -2
- package/dist/{chunk-QJQORGE3.js → chunk-SU5FOI4R.js} +2 -2
- package/dist/{chunk-TP625ZYJ.js → chunk-TAQLWNIF.js} +2 -2
- package/dist/{chunk-IY5WUAFH.js → chunk-TT37PYOQ.js} +2 -2
- package/dist/{chunk-FL4XLVK2.js → chunk-U74U4ZFN.js} +2 -2
- package/dist/{chunk-KKVV5RQZ.js → chunk-UDZBOMRA.js} +3 -3
- package/dist/{chunk-GS4QVZ75.js → chunk-VYDKGM7F.js} +9 -9
- package/dist/{chunk-AKPE7Z23.js → chunk-WP44GN6A.js} +2 -2
- package/dist/{chunk-HHSBWOAP.js → chunk-WXUMJSGG.js} +2 -2
- package/dist/{chunk-DDM6B66N.js → chunk-XQR2U3LP.js} +3 -3
- package/dist/client.cjs +284 -21
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +29 -29
- package/dist/core/client.cjs +1 -1
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.js +4 -4
- package/dist/core/error.cjs +1 -1
- package/dist/core/error.cjs.map +1 -1
- package/dist/core/error.js +3 -3
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +4 -4
- package/dist/edge.cjs +269 -18
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +11 -7
- package/dist/git/client.cjs +1 -1
- package/dist/git/client.cjs.map +1 -1
- package/dist/git/client.js +5 -5
- package/dist/git/index.cjs +1 -1
- package/dist/git/index.cjs.map +1 -1
- package/dist/git/index.js +5 -5
- package/dist/index.cjs +288 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +35 -31
- package/dist/modelrouter/core.cjs +1 -1
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +5 -5
- package/dist/modelrouter/index.cjs +1 -1
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +5 -5
- package/dist/subagents/anthropic.cjs +1 -1
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.js +10 -10
- package/dist/subagents/vercel.cjs +1 -1
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.js +10 -10
- package/dist/tools/browser/anthropic.cjs +1 -1
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +7 -7
- package/dist/tools/browser/core.cjs +1 -1
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +6 -6
- package/dist/tools/browser/index.cjs +1 -1
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +9 -9
- package/dist/tools/browser/openai.cjs +1 -1
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +7 -7
- package/dist/tools/browser/profiles/core.cjs +1 -1
- package/dist/tools/browser/profiles/core.cjs.map +1 -1
- package/dist/tools/browser/profiles/core.js +3 -3
- package/dist/tools/browser/profiles/index.cjs +1 -1
- package/dist/tools/browser/profiles/index.cjs.map +1 -1
- package/dist/tools/browser/profiles/index.js +3 -3
- package/dist/tools/browser/vercel.cjs +1 -1
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +7 -7
- package/dist/tools/codebase_search/anthropic.cjs +1 -1
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +6 -6
- package/dist/tools/codebase_search/core.cjs +1 -1
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.js +5 -5
- package/dist/tools/codebase_search/index.cjs +1 -1
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.js +8 -8
- package/dist/tools/codebase_search/openai.cjs +1 -1
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +6 -6
- package/dist/tools/codebase_search/vercel.cjs +1 -1
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +6 -6
- package/dist/tools/compact/core.cjs +1 -1
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.js +5 -5
- package/dist/tools/compact/index.cjs +1 -1
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.js +6 -6
- package/dist/tools/fastapply/anthropic.cjs +284 -21
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +7 -7
- package/dist/tools/fastapply/apply.cjs +269 -18
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.d.ts +13 -1
- package/dist/tools/fastapply/apply.js +6 -2
- package/dist/tools/fastapply/core.cjs +288 -21
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.d.ts +1 -1
- package/dist/tools/fastapply/core.js +10 -6
- package/dist/tools/fastapply/index.cjs +288 -21
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.d.ts +1 -1
- package/dist/tools/fastapply/index.js +13 -9
- package/dist/tools/fastapply/openai.cjs +284 -21
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +7 -7
- package/dist/tools/fastapply/types.cjs.map +1 -1
- package/dist/tools/fastapply/types.d.ts +14 -2
- package/dist/tools/fastapply/vercel.cjs +284 -21
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +7 -7
- package/dist/tools/index.cjs +288 -21
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +13 -9
- package/dist/tools/reflex/core.cjs +1 -1
- package/dist/tools/reflex/core.cjs.map +1 -1
- package/dist/tools/reflex/core.js +5 -5
- package/dist/tools/reflex/index.cjs +1 -1
- package/dist/tools/reflex/index.cjs.map +1 -1
- package/dist/tools/reflex/index.js +5 -5
- package/dist/tools/utils/resilience.cjs +1 -1
- package/dist/tools/utils/resilience.cjs.map +1 -1
- package/dist/tools/utils/resilience.js +2 -2
- package/dist/tools/warp_grep/agent/runner.cjs +1 -1
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -2
- package/dist/tools/warp_grep/anthropic.cjs +1 -1
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +10 -10
- package/dist/tools/warp_grep/client.cjs +1 -1
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +9 -9
- package/dist/tools/warp_grep/gemini.cjs +1 -1
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +9 -9
- package/dist/tools/warp_grep/harness.js +2 -2
- package/dist/tools/warp_grep/index.cjs +1 -1
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +14 -14
- package/dist/tools/warp_grep/openai.cjs +1 -1
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +10 -10
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/vercel.cjs +1 -1
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +10 -10
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-EABWHIAS.js.map +0 -1
- package/dist/chunk-SM27L5SF.js +0 -148
- package/dist/chunk-SM27L5SF.js.map +0 -1
- /package/dist/{chunk-OXVH7KJ7.js.map → chunk-2JKIWBME.js.map} +0 -0
- /package/dist/{chunk-X57U7AHA.js.map → chunk-2THF6MNE.js.map} +0 -0
- /package/dist/{chunk-4E2HKWUQ.js.map → chunk-33WVJLIT.js.map} +0 -0
- /package/dist/{chunk-RAWFZX7R.js.map → chunk-74LJOCDW.js.map} +0 -0
- /package/dist/{chunk-XT75CKB2.js.map → chunk-7KAW6EUG.js.map} +0 -0
- /package/dist/{chunk-45HXBGGH.js.map → chunk-C225GOV2.js.map} +0 -0
- /package/dist/{chunk-DRM3ETEL.js.map → chunk-CKSINYRF.js.map} +0 -0
- /package/dist/{chunk-4BALDMIZ.js.map → chunk-DL4EUMBV.js.map} +0 -0
- /package/dist/{chunk-NDUHOFAN.js.map → chunk-EM7BMNSS.js.map} +0 -0
- /package/dist/{chunk-CKN2RJPD.js.map → chunk-FM2L35XC.js.map} +0 -0
- /package/dist/{chunk-F4L7PCXV.js.map → chunk-GRYLQ2HM.js.map} +0 -0
- /package/dist/{chunk-EUZCZNK4.js.map → chunk-JIHDKRQW.js.map} +0 -0
- /package/dist/{chunk-UCDN6SER.js.map → chunk-MFAIFUFK.js.map} +0 -0
- /package/dist/{chunk-VLZ6PNAD.js.map → chunk-OPNTDMHH.js.map} +0 -0
- /package/dist/{chunk-4EZ7L6FJ.js.map → chunk-PDSLRLYI.js.map} +0 -0
- /package/dist/{chunk-2W54UBCR.js.map → chunk-POUBLP4R.js.map} +0 -0
- /package/dist/{chunk-OZDNWR3I.js.map → chunk-PPNJY7P3.js.map} +0 -0
- /package/dist/{chunk-24ID7P4E.js.map → chunk-PUTYJ2ET.js.map} +0 -0
- /package/dist/{chunk-A777CPSD.js.map → chunk-QJSGHJ7D.js.map} +0 -0
- /package/dist/{chunk-G5J5ZHCG.js.map → chunk-S3V22W7M.js.map} +0 -0
- /package/dist/{chunk-QJQORGE3.js.map → chunk-SU5FOI4R.js.map} +0 -0
- /package/dist/{chunk-TP625ZYJ.js.map → chunk-TAQLWNIF.js.map} +0 -0
- /package/dist/{chunk-IY5WUAFH.js.map → chunk-TT37PYOQ.js.map} +0 -0
- /package/dist/{chunk-FL4XLVK2.js.map → chunk-U74U4ZFN.js.map} +0 -0
- /package/dist/{chunk-KKVV5RQZ.js.map → chunk-UDZBOMRA.js.map} +0 -0
- /package/dist/{chunk-GS4QVZ75.js.map → chunk-VYDKGM7F.js.map} +0 -0
- /package/dist/{chunk-AKPE7Z23.js.map → chunk-WP44GN6A.js.map} +0 -0
- /package/dist/{chunk-HHSBWOAP.js.map → chunk-WXUMJSGG.js.map} +0 -0
- /package/dist/{chunk-DDM6B66N.js.map → chunk-XQR2U3LP.js.map} +0 -0
|
@@ -89,7 +89,7 @@ var init_package = __esm({
|
|
|
89
89
|
"package.json"() {
|
|
90
90
|
package_default = {
|
|
91
91
|
name: "@morphllm/morphsdk",
|
|
92
|
-
version: "0.2.
|
|
92
|
+
version: "0.2.194",
|
|
93
93
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
94
94
|
type: "module",
|
|
95
95
|
main: "./dist/index.cjs",
|
|
@@ -366,14 +366,219 @@ var init_version = __esm({
|
|
|
366
366
|
}
|
|
367
367
|
});
|
|
368
368
|
|
|
369
|
+
// tools/fastapply/anchors.ts
|
|
370
|
+
function escapeRegExp(value) {
|
|
371
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
372
|
+
}
|
|
373
|
+
function findNamespace(values) {
|
|
374
|
+
for (let namespace = 0; namespace < Number.MAX_SAFE_INTEGER; namespace++) {
|
|
375
|
+
const prefix = `\u27EAM${namespace}:`;
|
|
376
|
+
if (values.every((value) => !value.includes(prefix))) {
|
|
377
|
+
return namespace;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
throw new Error("Unable to allocate a Fast Apply anchor namespace");
|
|
381
|
+
}
|
|
382
|
+
function htmlLabel(token) {
|
|
383
|
+
if (!token.startsWith("<")) return "text";
|
|
384
|
+
const match = token.match(/^<\s*(!doctype|\/?[a-zA-Z][\w:-]*)/);
|
|
385
|
+
return (match?.[1] ?? "tag").toLowerCase();
|
|
386
|
+
}
|
|
387
|
+
function htmlTokenUnits(value, visibleTags = /* @__PURE__ */ new Set()) {
|
|
388
|
+
return (value.match(/<[^>]*>|[^<]+/g) ?? [value]).map((token) => ({
|
|
389
|
+
value: token,
|
|
390
|
+
label: htmlLabel(token),
|
|
391
|
+
anchorable: token.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH && !visibleTags.has(htmlLabel(token).replace(/^\//, ""))
|
|
392
|
+
}));
|
|
393
|
+
}
|
|
394
|
+
function sourceUnits(originalCode, editContext) {
|
|
395
|
+
const trimmed = originalCode.trimStart().toLowerCase();
|
|
396
|
+
const looksLikeHtml = (trimmed.startsWith("<!doctype") || trimmed.startsWith("<html")) && /<\/html\s*>/i.test(originalCode);
|
|
397
|
+
if (looksLikeHtml) {
|
|
398
|
+
const contextWords = new Set(
|
|
399
|
+
editContext.join(" ").toLowerCase().match(/[a-z][\w:-]*/g) ?? []
|
|
400
|
+
);
|
|
401
|
+
return htmlTokenUnits(originalCode, contextWords);
|
|
402
|
+
}
|
|
403
|
+
const parts = originalCode.split(/(\r\n|\n|\r)/);
|
|
404
|
+
const units = [];
|
|
405
|
+
for (let index = 0; index < parts.length; index += 2) {
|
|
406
|
+
const line = parts[index] ?? "";
|
|
407
|
+
const lineEnding = parts[index + 1] ?? "";
|
|
408
|
+
units.push({
|
|
409
|
+
value: line,
|
|
410
|
+
label: "line",
|
|
411
|
+
anchorable: line.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH
|
|
412
|
+
});
|
|
413
|
+
if (lineEnding) {
|
|
414
|
+
units.push({ value: lineEnding, anchorable: false });
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return units;
|
|
418
|
+
}
|
|
419
|
+
function copyCount(value) {
|
|
420
|
+
const words = {
|
|
421
|
+
one: 1,
|
|
422
|
+
two: 2,
|
|
423
|
+
three: 3,
|
|
424
|
+
four: 4,
|
|
425
|
+
five: 5,
|
|
426
|
+
six: 6,
|
|
427
|
+
seven: 7,
|
|
428
|
+
eight: 8,
|
|
429
|
+
nine: 9,
|
|
430
|
+
ten: 10
|
|
431
|
+
};
|
|
432
|
+
return /^\d+$/.test(value) ? Number(value) : words[value.toLowerCase()];
|
|
433
|
+
}
|
|
434
|
+
function structuralExpectation(originalCode, editContext) {
|
|
435
|
+
const context = editContext.join(" ");
|
|
436
|
+
const match = context.match(
|
|
437
|
+
/(?: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
|
|
438
|
+
);
|
|
439
|
+
if (!match) return void 0;
|
|
440
|
+
const tag = match[1].toLowerCase();
|
|
441
|
+
const addedCopies = copyCount(match[2]);
|
|
442
|
+
if (addedCopies === void 0) return void 0;
|
|
443
|
+
const tagPattern = new RegExp(`<${escapeRegExp(tag)}(?:\\s|>)`, "gi");
|
|
444
|
+
const originalCount = originalCode.match(tagPattern)?.length ?? 0;
|
|
445
|
+
if (originalCount === 0) return void 0;
|
|
446
|
+
return { tag, expectedCount: originalCount * (addedCopies + 1) };
|
|
447
|
+
}
|
|
448
|
+
function createAnchorCompactionPlan(originalCode, collisionValues = []) {
|
|
449
|
+
const namespace = findNamespace([originalCode, ...collisionValues]);
|
|
450
|
+
const expectation = structuralExpectation(originalCode, collisionValues);
|
|
451
|
+
const markerPrefix = `\u27EAM${namespace}:`;
|
|
452
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
453
|
+
const values = [];
|
|
454
|
+
const markers = [];
|
|
455
|
+
let anchorCount = 0;
|
|
456
|
+
let skeleton = "";
|
|
457
|
+
for (const unit of sourceUnits(originalCode, collisionValues)) {
|
|
458
|
+
if (!unit.anchorable) {
|
|
459
|
+
skeleton += unit.value;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
let id = definitions.get(unit.value);
|
|
463
|
+
if (id === void 0) {
|
|
464
|
+
id = values.length;
|
|
465
|
+
definitions.set(unit.value, id);
|
|
466
|
+
values.push(unit.value);
|
|
467
|
+
markers.push(`${markerPrefix}${id}:${unit.label ?? "unit"}\u27EB`);
|
|
468
|
+
}
|
|
469
|
+
skeleton += markers[id];
|
|
470
|
+
anchorCount++;
|
|
471
|
+
}
|
|
472
|
+
if (anchorCount === 0 || skeleton.length >= originalCode.length) {
|
|
473
|
+
return void 0;
|
|
474
|
+
}
|
|
475
|
+
const definitionsBegin = `\u27EAMORPH_DEFINITIONS_BEGIN_${namespace}\u27EB`;
|
|
476
|
+
const definitionsEnd = `\u27EAMORPH_DEFINITIONS_END_${namespace}\u27EB`;
|
|
477
|
+
const codeBegin = `\u27EAMORPH_CODE_BEGIN_${namespace}\u27EB`;
|
|
478
|
+
const serializedDefinitions = values.map((value, id) => `${markers[id]}=${JSON.stringify(value)}`).join("\n");
|
|
479
|
+
const code = [
|
|
480
|
+
definitionsBegin,
|
|
481
|
+
serializedDefinitions,
|
|
482
|
+
definitionsEnd,
|
|
483
|
+
codeBegin,
|
|
484
|
+
skeleton
|
|
485
|
+
].join("\n");
|
|
486
|
+
const instructionSuffix = `
|
|
487
|
+
|
|
488
|
+
LARGE-FILE ANCHOR PROTOCOL:
|
|
489
|
+
The <code> block starts with an exact anchor definition table, then ${codeBegin}, then the source skeleton.
|
|
490
|
+
Each ${markerPrefix}N:kind\u27EB placeholder represents the exact source fragment in its matching JSON-string definition. The kind suffix describes its HTML tag, text, or source line.
|
|
491
|
+
Return only the updated source skeleton after ${codeBegin}; never return the definition table or protocol delimiters.
|
|
492
|
+
Copy a placeholder exactly when its source fragment is unchanged. You may repeat, reorder, or remove placeholders when the requested edit requires it.
|
|
493
|
+
To modify an anchored fragment, output the modified source instead of its placeholder.
|
|
494
|
+
Do not invent or alter placeholder IDs.`;
|
|
495
|
+
const markerPattern = new RegExp(`${escapeRegExp(markerPrefix)}(\\d+):[^\u27EB]+\u27EB`, "g");
|
|
496
|
+
return {
|
|
497
|
+
code,
|
|
498
|
+
instructionSuffix,
|
|
499
|
+
anchorCount,
|
|
500
|
+
uniqueAnchorCount: values.length,
|
|
501
|
+
hasStructuralValidation: expectation !== void 0,
|
|
502
|
+
expand(content) {
|
|
503
|
+
const codeBeginIndex = content.lastIndexOf(codeBegin);
|
|
504
|
+
const skeletonContent = codeBeginIndex >= 0 ? content.slice(codeBeginIndex + codeBegin.length).replace(/^\r?\n/, "") : content;
|
|
505
|
+
const expanded = skeletonContent.replace(markerPattern, (marker, idText) => {
|
|
506
|
+
const id = Number(idText);
|
|
507
|
+
const value = values[id];
|
|
508
|
+
return value === void 0 || markers[id] !== marker ? marker : value;
|
|
509
|
+
});
|
|
510
|
+
if (expanded.includes(markerPrefix)) {
|
|
511
|
+
throw new FastApplyAnchorIntegrityError();
|
|
512
|
+
}
|
|
513
|
+
if (expectation) {
|
|
514
|
+
const tagPattern = new RegExp(`<${escapeRegExp(expectation.tag)}(?:\\s|>)`, "gi");
|
|
515
|
+
const actualCount = expanded.match(tagPattern)?.length ?? 0;
|
|
516
|
+
if (actualCount !== expectation.expectedCount) {
|
|
517
|
+
throw new FastApplyAnchorIntegrityError();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return expanded;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
var DEFAULT_MIN_ANCHOR_LINE_LENGTH, DEFAULT_ANCHOR_COMPACTION_THRESHOLD, FastApplyAnchorIntegrityError;
|
|
525
|
+
var init_anchors = __esm({
|
|
526
|
+
"tools/fastapply/anchors.ts"() {
|
|
527
|
+
"use strict";
|
|
528
|
+
DEFAULT_MIN_ANCHOR_LINE_LENGTH = 24;
|
|
529
|
+
DEFAULT_ANCHOR_COMPACTION_THRESHOLD = 128 * 1024;
|
|
530
|
+
FastApplyAnchorIntegrityError = class extends Error {
|
|
531
|
+
code = "anchor_integrity_failed";
|
|
532
|
+
completionId;
|
|
533
|
+
constructor(completionId) {
|
|
534
|
+
super(
|
|
535
|
+
"Fast Apply failed large-file anchor integrity checks. The partial result was discarded safely."
|
|
536
|
+
);
|
|
537
|
+
this.name = "FastApplyAnchorIntegrityError";
|
|
538
|
+
this.completionId = completionId;
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
|
|
369
544
|
// tools/fastapply/apply.ts
|
|
370
545
|
var apply_exports = {};
|
|
371
546
|
__export(apply_exports, {
|
|
547
|
+
FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
|
|
548
|
+
FastApplyContextLengthError: () => FastApplyContextLengthError,
|
|
372
549
|
applyEdit: () => applyEdit,
|
|
373
550
|
callMorphAPI: () => callMorphAPI,
|
|
374
551
|
countChanges: () => countChanges,
|
|
375
552
|
generateUdiff: () => generateUdiff
|
|
376
553
|
});
|
|
554
|
+
function isAsyncIterable(value) {
|
|
555
|
+
return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
|
|
556
|
+
}
|
|
557
|
+
async function collectCompletion(response) {
|
|
558
|
+
if (!isAsyncIterable(response)) {
|
|
559
|
+
const completion = response;
|
|
560
|
+
return {
|
|
561
|
+
content: completion.choices?.[0]?.message?.content ?? "",
|
|
562
|
+
completionId: completion.id,
|
|
563
|
+
finishReason: completion.choices?.[0]?.finish_reason
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
const content = [];
|
|
567
|
+
let completionId;
|
|
568
|
+
let finishReason;
|
|
569
|
+
for await (const chunk of response) {
|
|
570
|
+
completionId = chunk.id ?? completionId;
|
|
571
|
+
for (const choice of chunk.choices ?? []) {
|
|
572
|
+
if (choice.delta?.content) {
|
|
573
|
+
content.push(choice.delta.content);
|
|
574
|
+
}
|
|
575
|
+
if (choice.finish_reason !== void 0 && choice.finish_reason !== null) {
|
|
576
|
+
finishReason = choice.finish_reason;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return { content: content.join(""), completionId, finishReason };
|
|
581
|
+
}
|
|
377
582
|
function generateUdiff(original, modified, filepath) {
|
|
378
583
|
return (0, import_diff.createTwoFilesPatch)(
|
|
379
584
|
filepath,
|
|
@@ -408,15 +613,19 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
|
|
|
408
613
|
const apiUrl = config.morphApiUrl || DEFAULT_API_URL;
|
|
409
614
|
const useLarge = config.large ?? (typeof process !== "undefined" ? process.env?.MORPH_LARGE_APPLY !== "false" : true);
|
|
410
615
|
const model = useLarge ? "morph-v3-large" : "morph-v3-fast";
|
|
411
|
-
const timeout = config.timeout
|
|
616
|
+
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
412
617
|
const debug = config.debug || false;
|
|
413
618
|
if (!apiKey) {
|
|
414
619
|
throw new Error(
|
|
415
620
|
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
416
621
|
);
|
|
417
622
|
}
|
|
418
|
-
const
|
|
419
|
-
|
|
623
|
+
const anchorThreshold = config.anchorCompactionThreshold ?? DEFAULT_ANCHOR_COMPACTION_THRESHOLD;
|
|
624
|
+
const anchorPlan = config.anchorCompaction !== false && originalCode.length >= anchorThreshold ? createAnchorCompactionPlan(originalCode, [codeEdit, instructions]) : void 0;
|
|
625
|
+
const requestCode = anchorPlan?.code ?? originalCode;
|
|
626
|
+
const requestInstructions = anchorPlan ? instructions + anchorPlan.instructionSuffix : instructions;
|
|
627
|
+
const message = `<instruction>${requestInstructions}</instruction>
|
|
628
|
+
<code>${requestCode}</code>
|
|
420
629
|
<update>${codeEdit}</update>`;
|
|
421
630
|
logger.debug("FastApply", "http_request", {
|
|
422
631
|
url: `${apiUrl}/v1/chat/completions`,
|
|
@@ -424,7 +633,10 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
|
|
|
424
633
|
filepath,
|
|
425
634
|
instruction_len: instructions.length,
|
|
426
635
|
original_len: originalCode.length,
|
|
427
|
-
|
|
636
|
+
request_code_len: requestCode.length,
|
|
637
|
+
code_edit_len: codeEdit.length,
|
|
638
|
+
anchor_count: anchorPlan?.anchorCount ?? 0,
|
|
639
|
+
unique_anchor_count: anchorPlan?.uniqueAnchorCount ?? 0
|
|
428
640
|
});
|
|
429
641
|
const startTime = Date.now();
|
|
430
642
|
const client = new import_openai.default({
|
|
@@ -432,20 +644,49 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
|
|
|
432
644
|
baseURL: `${apiUrl}/v1`,
|
|
433
645
|
timeout,
|
|
434
646
|
maxRetries: config.retryConfig?.maxRetries ?? 3,
|
|
435
|
-
defaultHeaders: {
|
|
647
|
+
defaultHeaders: {
|
|
648
|
+
"X-Morph-SDK-Version": SDK_VERSION,
|
|
649
|
+
...anchorPlan ? { "X-Morph-Apply-Context": "extralong" } : {}
|
|
650
|
+
}
|
|
436
651
|
});
|
|
437
652
|
try {
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
653
|
+
const maxAttempts = anchorPlan?.hasStructuralValidation ? 2 : 1;
|
|
654
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
655
|
+
const response = await client.chat.completions.create({
|
|
656
|
+
model,
|
|
657
|
+
messages: [{ role: "user", content: message }],
|
|
658
|
+
stream: true
|
|
659
|
+
});
|
|
660
|
+
const completion = await collectCompletion(response);
|
|
661
|
+
if (completion.finishReason === "length") {
|
|
662
|
+
throw new FastApplyContextLengthError(completion.completionId);
|
|
663
|
+
}
|
|
664
|
+
let content = completion.content;
|
|
665
|
+
if (!content) {
|
|
666
|
+
throw new Error("Morph API returned empty response");
|
|
667
|
+
}
|
|
668
|
+
if (anchorPlan) {
|
|
669
|
+
try {
|
|
670
|
+
content = anchorPlan.expand(content);
|
|
671
|
+
} catch (error) {
|
|
672
|
+
if (error instanceof FastApplyAnchorIntegrityError) {
|
|
673
|
+
if (attempt < maxAttempts) {
|
|
674
|
+
logger.warn("FastApply", "anchor_validation_retry", {
|
|
675
|
+
attempt,
|
|
676
|
+
completion_id: completion.completionId
|
|
677
|
+
});
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
throw new FastApplyAnchorIntegrityError(completion.completionId);
|
|
681
|
+
}
|
|
682
|
+
throw error;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const elapsed = Date.now() - startTime;
|
|
686
|
+
logger.debug("FastApply", "http_response", { status: 200, completion_id: completion.completionId, content_len: content.length, latency_ms: elapsed });
|
|
687
|
+
return { content, completionId: completion.completionId };
|
|
445
688
|
}
|
|
446
|
-
|
|
447
|
-
logger.debug("FastApply", "http_response", { status: 200, completion_id: completion.id, content_len: content.length, latency_ms: elapsed });
|
|
448
|
-
return { content, completionId: completion.id };
|
|
689
|
+
throw new FastApplyAnchorIntegrityError();
|
|
449
690
|
} catch (error) {
|
|
450
691
|
const elapsed = Date.now() - startTime;
|
|
451
692
|
const status = error?.status || error?.response?.status;
|
|
@@ -495,14 +736,17 @@ async function applyEdit(input, config = {}) {
|
|
|
495
736
|
} catch (error) {
|
|
496
737
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
497
738
|
logger.error("FastApply", "apply_edit_error", { error: errorMessage });
|
|
739
|
+
const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
|
|
498
740
|
return {
|
|
499
741
|
success: false,
|
|
500
742
|
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
501
|
-
error: errorMessage
|
|
743
|
+
error: errorMessage,
|
|
744
|
+
errorCode: structuredError?.code,
|
|
745
|
+
completionId: structuredError?.completionId
|
|
502
746
|
};
|
|
503
747
|
}
|
|
504
748
|
}
|
|
505
|
-
var import_diff, import_openai, DEFAULT_API_URL, DEFAULT_TIMEOUT;
|
|
749
|
+
var import_diff, import_openai, DEFAULT_API_URL, DEFAULT_TIMEOUT, FastApplyContextLengthError;
|
|
506
750
|
var init_apply = __esm({
|
|
507
751
|
"tools/fastapply/apply.ts"() {
|
|
508
752
|
"use strict";
|
|
@@ -510,8 +754,21 @@ var init_apply = __esm({
|
|
|
510
754
|
import_openai = __toESM(require("openai"), 1);
|
|
511
755
|
init_version();
|
|
512
756
|
init_logger();
|
|
757
|
+
init_anchors();
|
|
758
|
+
init_anchors();
|
|
513
759
|
DEFAULT_API_URL = "https://api.morphllm.com";
|
|
514
|
-
DEFAULT_TIMEOUT =
|
|
760
|
+
DEFAULT_TIMEOUT = 6e5;
|
|
761
|
+
FastApplyContextLengthError = class extends Error {
|
|
762
|
+
code = "context_length_exceeded";
|
|
763
|
+
completionId;
|
|
764
|
+
constructor(completionId) {
|
|
765
|
+
super(
|
|
766
|
+
"Fast Apply exhausted its context window before producing the complete file. Retry with a smaller input/update or use sparse anchors for unchanged code."
|
|
767
|
+
);
|
|
768
|
+
this.name = "FastApplyContextLengthError";
|
|
769
|
+
this.completionId = completionId;
|
|
770
|
+
}
|
|
771
|
+
};
|
|
515
772
|
}
|
|
516
773
|
});
|
|
517
774
|
|
|
@@ -520,6 +777,8 @@ var fastapply_exports = {};
|
|
|
520
777
|
__export(fastapply_exports, {
|
|
521
778
|
EDIT_FILE_SYSTEM_PROMPT: () => EDIT_FILE_SYSTEM_PROMPT,
|
|
522
779
|
EDIT_FILE_TOOL_DESCRIPTION: () => EDIT_FILE_TOOL_DESCRIPTION,
|
|
780
|
+
FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
|
|
781
|
+
FastApplyContextLengthError: () => FastApplyContextLengthError,
|
|
523
782
|
anthropic: () => anthropic_exports,
|
|
524
783
|
applyEdit: () => applyEdit,
|
|
525
784
|
countChanges: () => countChanges,
|
|
@@ -543,12 +802,15 @@ init_version();
|
|
|
543
802
|
|
|
544
803
|
// tools/fastapply/core.ts
|
|
545
804
|
init_apply();
|
|
805
|
+
init_apply();
|
|
546
806
|
var DEFAULT_CONFIG = {
|
|
547
807
|
morphApiUrl: "https://api.morphllm.com",
|
|
548
808
|
baseDir: process.cwd(),
|
|
549
809
|
generateUdiff: true,
|
|
550
810
|
autoWrite: true,
|
|
551
|
-
timeout:
|
|
811
|
+
timeout: 6e5,
|
|
812
|
+
anchorCompaction: true,
|
|
813
|
+
anchorCompactionThreshold: 128 * 1024,
|
|
552
814
|
debug: false
|
|
553
815
|
};
|
|
554
816
|
async function executeEditFile(input, config = {}) {
|
|
@@ -601,12 +863,15 @@ async function executeEditFile(input, config = {}) {
|
|
|
601
863
|
};
|
|
602
864
|
} catch (error) {
|
|
603
865
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
866
|
+
const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
|
|
604
867
|
logger.error("FastApply", "execute_error", { error: errorMessage, target_filepath: input.target_filepath, stack: error instanceof Error ? error.stack : void 0 });
|
|
605
868
|
return {
|
|
606
869
|
success: false,
|
|
607
870
|
filepath: input.target_filepath,
|
|
608
871
|
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
609
|
-
error: errorMessage
|
|
872
|
+
error: errorMessage,
|
|
873
|
+
errorCode: structuredError?.code,
|
|
874
|
+
completionId: structuredError?.completionId
|
|
610
875
|
};
|
|
611
876
|
}
|
|
612
877
|
}
|
|
@@ -857,6 +1122,8 @@ var vercel_default = editFileTool3;
|
|
|
857
1122
|
0 && (module.exports = {
|
|
858
1123
|
EDIT_FILE_SYSTEM_PROMPT,
|
|
859
1124
|
EDIT_FILE_TOOL_DESCRIPTION,
|
|
1125
|
+
FastApplyAnchorIntegrityError,
|
|
1126
|
+
FastApplyContextLengthError,
|
|
860
1127
|
anthropic,
|
|
861
1128
|
applyEdit,
|
|
862
1129
|
countChanges,
|