veryfront 0.1.156 → 0.1.159
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/esm/cli/mcp/remote-file-tools.d.ts.map +1 -1
- package/esm/cli/mcp/remote-file-tools.js +16 -9
- package/esm/deno.js +1 -1
- package/esm/src/agent/human-input.d.ts +298 -0
- package/esm/src/agent/human-input.d.ts.map +1 -0
- package/esm/src/agent/human-input.js +112 -0
- package/esm/src/agent/index.d.ts +1 -0
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +1 -0
- package/esm/src/mcp/server.d.ts +2 -1
- package/esm/src/mcp/server.d.ts.map +1 -1
- package/esm/src/mcp/server.js +12 -5
- package/esm/src/proxy/handler.d.ts.map +1 -1
- package/esm/src/proxy/handler.js +6 -9
- package/esm/src/routing/api/module-loader/loader.d.ts +7 -0
- package/esm/src/routing/api/module-loader/loader.d.ts.map +1 -1
- package/esm/src/routing/api/module-loader/loader.js +104 -94
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
- package/src/cli/mcp/remote-file-tools.ts +24 -13
- package/src/deno.js +1 -1
- package/src/src/agent/human-input.ts +152 -0
- package/src/src/agent/index.ts +18 -0
- package/src/src/mcp/server.ts +14 -5
- package/src/src/proxy/handler.ts +6 -23
- package/src/src/routing/api/module-loader/loader.ts +127 -100
- package/src/src/utils/version-constant.ts +1 -1
package/src/src/proxy/handler.ts
CHANGED
|
@@ -392,36 +392,19 @@ export function createProxyHandler(options: ProxyHandlerOptions) {
|
|
|
392
392
|
return `https://veryfront.com/sign-in?from=${encodeURIComponent(returnPath)}`;
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
function makePreviewProjectNotFoundContext(
|
|
396
|
-
base: {
|
|
397
|
-
scope: TokenScope;
|
|
398
|
-
host: string;
|
|
399
|
-
parsedDomain: ParsedDomain;
|
|
400
|
-
},
|
|
401
|
-
token?: string,
|
|
402
|
-
): ProxyContext {
|
|
403
|
-
return makeErrorContext(
|
|
404
|
-
base,
|
|
405
|
-
404,
|
|
406
|
-
"Preview project not found",
|
|
407
|
-
token,
|
|
408
|
-
undefined,
|
|
409
|
-
"project-not-found",
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
395
|
function makeProjectNotFoundContext(
|
|
414
396
|
base: {
|
|
415
397
|
scope: TokenScope;
|
|
416
398
|
host: string;
|
|
417
399
|
parsedDomain: ParsedDomain;
|
|
418
400
|
},
|
|
401
|
+
message: "Preview project not found" | "Project not found",
|
|
419
402
|
token?: string,
|
|
420
403
|
): ProxyContext {
|
|
421
404
|
return makeErrorContext(
|
|
422
405
|
base,
|
|
423
406
|
404,
|
|
424
|
-
|
|
407
|
+
message,
|
|
425
408
|
token,
|
|
426
409
|
undefined,
|
|
427
410
|
"project-not-found",
|
|
@@ -630,11 +613,11 @@ export function createProxyHandler(options: ProxyHandlerOptions) {
|
|
|
630
613
|
if (status === 404) {
|
|
631
614
|
if (scope === "preview") {
|
|
632
615
|
logger?.info("Preview project not found", { projectSlug, host });
|
|
633
|
-
return
|
|
616
|
+
return makeProjectNotFoundContext(base, "Preview project not found");
|
|
634
617
|
}
|
|
635
618
|
|
|
636
619
|
logger?.info("Project not found", { projectSlug, host, scope });
|
|
637
|
-
return makeProjectNotFoundContext(base);
|
|
620
|
+
return makeProjectNotFoundContext(base, "Project not found");
|
|
638
621
|
}
|
|
639
622
|
|
|
640
623
|
const message = scope === "preview"
|
|
@@ -727,7 +710,7 @@ export function createProxyHandler(options: ProxyHandlerOptions) {
|
|
|
727
710
|
scope,
|
|
728
711
|
targetEnvName: parsedDomain.environment,
|
|
729
712
|
});
|
|
730
|
-
return makeProjectNotFoundContext(base, token);
|
|
713
|
+
return makeProjectNotFoundContext(base, "Project not found", token);
|
|
731
714
|
}
|
|
732
715
|
|
|
733
716
|
projectId = resolved.projectId;
|
|
@@ -765,7 +748,7 @@ export function createProxyHandler(options: ProxyHandlerOptions) {
|
|
|
765
748
|
|
|
766
749
|
if (!resolved.projectId) {
|
|
767
750
|
logger?.info("Preview project not found after lookup", { projectSlug, host });
|
|
768
|
-
return
|
|
751
|
+
return makeProjectNotFoundContext(base, "Preview project not found", token);
|
|
769
752
|
}
|
|
770
753
|
|
|
771
754
|
projectId = resolved.projectId;
|
|
@@ -661,129 +661,156 @@ async function loadModuleFromCode(
|
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
663
|
|
|
664
|
-
|
|
665
|
-
|
|
664
|
+
export function getNodeExternalPackagesToResolve(userDeps: Map<string, string>): string[] {
|
|
665
|
+
const externalPackagesToResolve = ["zod"];
|
|
666
|
+
|
|
667
|
+
for (const name of userDeps.keys()) {
|
|
668
|
+
if (!externalPackagesToResolve.includes(name)) {
|
|
669
|
+
externalPackagesToResolve.push(name);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return externalPackagesToResolve;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export async function resolveNodePackageToFileUrl(
|
|
666
677
|
projectDir: string,
|
|
678
|
+
packageName: string,
|
|
667
679
|
fs: FileSystem,
|
|
668
|
-
|
|
669
|
-
): Promise<string> {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
if (isNode) {
|
|
673
|
-
try {
|
|
674
|
-
const { pathToFileURL } = await import("node:url");
|
|
680
|
+
pathToFileURL: typeof import("node:url").pathToFileURL,
|
|
681
|
+
): Promise<string | null> {
|
|
682
|
+
const packagePath = pathHelper.join(projectDir, "node_modules", packageName);
|
|
683
|
+
const packageJsonPath = pathHelper.join(packagePath, "package.json");
|
|
675
684
|
|
|
676
|
-
|
|
685
|
+
try {
|
|
686
|
+
const pkgJson = JSON.parse(await fs.readTextFile(packageJsonPath));
|
|
687
|
+
let entryPoint: string | undefined;
|
|
677
688
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
689
|
+
if (pkgJson.exports) {
|
|
690
|
+
entryPoint = resolveExportEntry(pkgJson.exports["."]);
|
|
691
|
+
}
|
|
681
692
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
let entryPoint: string | undefined;
|
|
693
|
+
entryPoint ||= pkgJson.module || pkgJson.main || "index.js";
|
|
694
|
+
if (!entryPoint) return null;
|
|
685
695
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
696
|
+
return pathToFileURL(pathHelper.join(packagePath, entryPoint)).href;
|
|
697
|
+
} catch (_) {
|
|
698
|
+
/* expected: package.json may not exist or be invalid */
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
689
702
|
|
|
690
|
-
|
|
691
|
-
|
|
703
|
+
export async function loadVeryfrontExportsMap(
|
|
704
|
+
projectDir: string,
|
|
705
|
+
fs: FileSystem,
|
|
706
|
+
): Promise<Record<string, { import?: string }>> {
|
|
707
|
+
const vfPackagePath = pathHelper.join(projectDir, "node_modules", "veryfront");
|
|
708
|
+
const vfPackageJsonPath = pathHelper.join(vfPackagePath, "package.json");
|
|
692
709
|
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
710
|
+
try {
|
|
711
|
+
const pkgJson = JSON.parse(await fs.readTextFile(vfPackageJsonPath));
|
|
712
|
+
return pkgJson.exports || {};
|
|
713
|
+
} catch (_error) {
|
|
714
|
+
logger.debug("Could not read veryfront package.json");
|
|
715
|
+
return {};
|
|
716
|
+
}
|
|
717
|
+
}
|
|
699
718
|
|
|
700
|
-
|
|
719
|
+
export async function rewriteNodeExternalImports(
|
|
720
|
+
code: string,
|
|
721
|
+
projectDir: string,
|
|
722
|
+
fs: FileSystem,
|
|
723
|
+
userDeps: Map<string, string>,
|
|
724
|
+
): Promise<string> {
|
|
725
|
+
const { pathToFileURL } = await import("node:url");
|
|
726
|
+
let transformed = code;
|
|
701
727
|
|
|
702
|
-
|
|
703
|
-
if (!externalPackagesToResolve.includes(name)) {
|
|
704
|
-
externalPackagesToResolve.push(name);
|
|
705
|
-
}
|
|
706
|
-
}
|
|
728
|
+
logger.debug(`Rewriting external imports for Node.js, projectDir: ${projectDir}`);
|
|
707
729
|
|
|
708
|
-
|
|
709
|
-
|
|
730
|
+
for (const pkg of getNodeExternalPackagesToResolve(userDeps)) {
|
|
731
|
+
const escapedPkg = pkg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
710
732
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
);
|
|
733
|
+
const staticImportRegex = new RegExp(`from\\s*["']${escapedPkg}(/[^"']*)?["']`, "g");
|
|
734
|
+
const dynamicImportRegex = new RegExp(
|
|
735
|
+
`import\\s*\\(\\s*["']${escapedPkg}(/[^"']*)?["']\\s*\\)`,
|
|
736
|
+
"g",
|
|
737
|
+
);
|
|
717
738
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
}
|
|
734
|
-
if (!resolvedUrl) return `from "${pkg}"`;
|
|
735
|
-
logger.debug(`Resolved ${pkg} -> ${resolvedUrl}`);
|
|
736
|
-
return `from "${resolvedUrl}"`;
|
|
737
|
-
});
|
|
739
|
+
const needsStatic = staticImportRegex.test(transformed);
|
|
740
|
+
staticImportRegex.lastIndex = 0;
|
|
741
|
+
const needsDynamic = dynamicImportRegex.test(transformed);
|
|
742
|
+
dynamicImportRegex.lastIndex = 0;
|
|
743
|
+
if (!needsStatic && !needsDynamic) continue;
|
|
744
|
+
|
|
745
|
+
const packageDir = pathToFileURL(pathHelper.join(projectDir, "node_modules", pkg)).href;
|
|
746
|
+
const resolvedUrl = await resolveNodePackageToFileUrl(projectDir, pkg, fs, pathToFileURL);
|
|
747
|
+
|
|
748
|
+
if (needsStatic) {
|
|
749
|
+
transformed = transformed.replace(staticImportRegex, (_, subpath) => {
|
|
750
|
+
if (subpath) {
|
|
751
|
+
const subUrl = `${packageDir}${subpath}`;
|
|
752
|
+
logger.debug(`Resolved ${pkg}${subpath} -> ${subUrl}`);
|
|
753
|
+
return `from "${subUrl}"`;
|
|
738
754
|
}
|
|
755
|
+
if (!resolvedUrl) return `from "${pkg}"`;
|
|
756
|
+
logger.debug(`Resolved ${pkg} -> ${resolvedUrl}`);
|
|
757
|
+
return `from "${resolvedUrl}"`;
|
|
758
|
+
});
|
|
759
|
+
}
|
|
739
760
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
return `import("${subUrl}")`;
|
|
745
|
-
}
|
|
746
|
-
if (!resolvedUrl) return `import("${pkg}")`;
|
|
747
|
-
return `import("${resolvedUrl}")`;
|
|
748
|
-
});
|
|
761
|
+
if (needsDynamic) {
|
|
762
|
+
transformed = transformed.replace(dynamicImportRegex, (_, subpath) => {
|
|
763
|
+
if (subpath) {
|
|
764
|
+
return `import("${packageDir}${subpath}")`;
|
|
749
765
|
}
|
|
766
|
+
if (!resolvedUrl) return `import("${pkg}")`;
|
|
767
|
+
return `import("${resolvedUrl}")`;
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
const vfPackagePath = pathHelper.join(projectDir, "node_modules", "veryfront");
|
|
773
|
+
const exportsMap = await loadVeryfrontExportsMap(projectDir, fs);
|
|
774
|
+
|
|
775
|
+
transformed = transformed.replace(
|
|
776
|
+
/from\s+["'](veryfront\/[^"']+)["']/g,
|
|
777
|
+
(match, fullSpecifier: string) => {
|
|
778
|
+
const subpath = "./" + fullSpecifier.replace("veryfront/", "");
|
|
779
|
+
const exportEntry = exportsMap[subpath];
|
|
780
|
+
if (!exportEntry?.import) {
|
|
781
|
+
logger.warn(`No export found for ${subpath}`);
|
|
782
|
+
return match;
|
|
750
783
|
}
|
|
751
784
|
|
|
752
|
-
const
|
|
753
|
-
|
|
785
|
+
const resolvedPath = pathHelper.join(vfPackagePath, exportEntry.import);
|
|
786
|
+
logger.debug(`Resolved ${fullSpecifier} -> ${resolvedPath}`);
|
|
787
|
+
return `from "${pathToFileURL(resolvedPath).href}"`;
|
|
788
|
+
},
|
|
789
|
+
);
|
|
754
790
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
exportsMap = pkgJson.exports || {};
|
|
759
|
-
} catch (_error) {
|
|
760
|
-
logger.debug(`Could not read veryfront package.json: `);
|
|
761
|
-
}
|
|
791
|
+
transformed = transformed.replace(/from\s+["']veryfront["']/g, () => {
|
|
792
|
+
const exportEntry = exportsMap["."];
|
|
793
|
+
if (!exportEntry?.import) return 'from "veryfront"';
|
|
762
794
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
const exportEntry = exportsMap[subpath];
|
|
768
|
-
if (!exportEntry?.import) {
|
|
769
|
-
logger.warn(`No export found for ${subpath}`);
|
|
770
|
-
return match;
|
|
771
|
-
}
|
|
795
|
+
const resolvedPath = pathHelper.join(vfPackagePath, exportEntry.import);
|
|
796
|
+
logger.debug(`Resolved veryfront -> ${resolvedPath}`);
|
|
797
|
+
return `from "${pathToFileURL(resolvedPath).href}"`;
|
|
798
|
+
});
|
|
772
799
|
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
return `from "${pathToFileURL(resolvedPath).href}"`;
|
|
776
|
-
},
|
|
777
|
-
);
|
|
800
|
+
return transformed;
|
|
801
|
+
}
|
|
778
802
|
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
803
|
+
async function rewriteExternalImports(
|
|
804
|
+
code: string,
|
|
805
|
+
projectDir: string,
|
|
806
|
+
fs: FileSystem,
|
|
807
|
+
userDeps: Map<string, string> = new Map(),
|
|
808
|
+
): Promise<string> {
|
|
809
|
+
let transformed = code;
|
|
782
810
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
});
|
|
811
|
+
if (isNode) {
|
|
812
|
+
try {
|
|
813
|
+
transformed = await rewriteNodeExternalImports(transformed, projectDir, fs, userDeps);
|
|
787
814
|
} catch (e) {
|
|
788
815
|
logger.warn(`Failed to import node:module: ${e}`);
|
|
789
816
|
}
|