veryfront 0.0.57 → 0.0.59

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/ai/index.js CHANGED
@@ -1675,7 +1675,7 @@ var LRU_DEFAULT_MAX_SIZE_BYTES = 50 * 1024 * 1024;
1675
1675
  // deno.json
1676
1676
  var deno_default = {
1677
1677
  name: "veryfront",
1678
- version: "0.0.57",
1678
+ version: "0.0.59",
1679
1679
  exclude: [
1680
1680
  "npm/",
1681
1681
  "dist/",
@@ -4255,20 +4255,105 @@ function getPathMod() {
4255
4255
  var dirname = (path) => getPathMod().dirname(path);
4256
4256
  var join2 = (...paths) => getPathMod().join(...paths);
4257
4257
  var resolve = (...paths) => getPathMod().resolve(...paths);
4258
+ var extname = (path) => getPathMod().extname(path);
4258
4259
  var sep = nodePath.sep;
4259
4260
 
4260
4261
  // src/ai/utils/discovery.ts
4261
4262
  var transpileCache = /* @__PURE__ */ new Map();
4263
+ function createFsAdapterPlugin(fsAdapter) {
4264
+ const existsCache = /* @__PURE__ */ new Map();
4265
+ async function checkExists(filePath) {
4266
+ if (existsCache.has(filePath)) {
4267
+ return existsCache.get(filePath);
4268
+ }
4269
+ const exists = await fsAdapter.exists(filePath);
4270
+ existsCache.set(filePath, exists);
4271
+ return exists;
4272
+ }
4273
+ async function resolveWithExtensions(basePath) {
4274
+ if (/\.(ts|tsx|js|jsx|mjs|json)$/i.test(basePath)) {
4275
+ if (await checkExists(basePath)) {
4276
+ return basePath;
4277
+ }
4278
+ return null;
4279
+ }
4280
+ const extensions = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
4281
+ for (const ext of extensions) {
4282
+ const fullPath = basePath + ext;
4283
+ if (await checkExists(fullPath)) {
4284
+ return fullPath;
4285
+ }
4286
+ }
4287
+ for (const ext of extensions) {
4288
+ const indexPath = join2(basePath, `index${ext}`);
4289
+ if (await checkExists(indexPath)) {
4290
+ return indexPath;
4291
+ }
4292
+ }
4293
+ return null;
4294
+ }
4295
+ return {
4296
+ name: "veryfront-fsadapter",
4297
+ // deno-lint-ignore no-explicit-any
4298
+ setup(build) {
4299
+ build.onResolve(
4300
+ { filter: /^\.\.?\// },
4301
+ async (args) => {
4302
+ const importerDir = args.importer ? dirname(args.importer) : args.resolveDir;
4303
+ const basePath = resolve(importerDir, args.path);
4304
+ const resolvedPath = await resolveWithExtensions(basePath);
4305
+ if (resolvedPath) {
4306
+ return {
4307
+ path: resolvedPath,
4308
+ namespace: "fsadapter"
4309
+ };
4310
+ }
4311
+ return {
4312
+ errors: [{
4313
+ text: `Could not resolve "${args.path}" from "${importerDir}" via fsAdapter`
4314
+ }]
4315
+ };
4316
+ }
4317
+ );
4318
+ build.onLoad(
4319
+ { filter: /.*/, namespace: "fsadapter" },
4320
+ async (args) => {
4321
+ try {
4322
+ const content = await fsAdapter.readFile(args.path);
4323
+ const ext = extname(args.path).toLowerCase();
4324
+ const loader = ext === ".tsx" ? "tsx" : ext === ".jsx" ? "jsx" : ext === ".ts" ? "ts" : "js";
4325
+ return {
4326
+ contents: content,
4327
+ loader,
4328
+ // Set resolveDir for nested imports from this file
4329
+ resolveDir: dirname(args.path)
4330
+ };
4331
+ } catch (error) {
4332
+ return {
4333
+ errors: [{
4334
+ text: `Failed to load "${args.path}" from fsAdapter: ${error}`
4335
+ }]
4336
+ };
4337
+ }
4338
+ }
4339
+ );
4340
+ }
4341
+ };
4342
+ }
4262
4343
  async function importModule(file, context) {
4263
4344
  const cacheKey = file;
4264
4345
  if (transpileCache.has(cacheKey)) {
4265
4346
  return transpileCache.get(cacheKey);
4266
4347
  }
4267
- const fs2 = createFileSystem();
4268
4348
  const filePath = file.replace("file://", "");
4269
4349
  let source;
4270
4350
  try {
4271
- source = await fs2.readTextFile(filePath);
4351
+ if (context.fsAdapter) {
4352
+ source = await context.fsAdapter.readFile(filePath);
4353
+ } else {
4354
+ const fs2 = createFileSystem();
4355
+ source = await fs2.readTextFile(filePath);
4356
+ }
4272
4357
  } catch (error) {
4273
4358
  throw new Error(`Failed to read file ${filePath}: ${error}`);
4274
4359
  }
@@ -4277,14 +4362,18 @@ async function importModule(file, context) {
4277
4362
  const loader = isTsx ? "tsx" : isJsx ? "jsx" : filePath.endsWith(".ts") ? "ts" : "js";
4278
4363
  const { build } = await import("esbuild");
4279
4364
  const fileDir = dirname(filePath);
4280
- const relativeImportPattern = /from\s+["'](\.\.[^"']+)["']/g;
4281
4365
  const relativeImports = [];
4282
- let match;
4283
- while ((match = relativeImportPattern.exec(source)) !== null) {
4284
- if (match[1]) {
4285
- relativeImports.push(match[1]);
4366
+ if (isDeno) {
4367
+ const relativeImportPattern = /from\s+["'](\.\.[^"']+)["']/g;
4368
+ let match;
4369
+ while ((match = relativeImportPattern.exec(source)) !== null) {
4370
+ if (match[1]) {
4371
+ relativeImports.push(match[1]);
4372
+ }
4286
4373
  }
4287
4374
  }
4375
+ const usePlugin = !isDeno && !!context.fsAdapter;
4376
+ const plugins = usePlugin ? [createFsAdapterPlugin(context.fsAdapter)] : [];
4288
4377
  const result = await build({
4289
4378
  bundle: true,
4290
4379
  write: false,
@@ -4294,6 +4383,7 @@ async function importModule(file, context) {
4294
4383
  jsx: "automatic",
4295
4384
  jsxImportSource: "react",
4296
4385
  resolveExtensions: [".ts", ".tsx", ".js", ".jsx", ".mjs"],
4386
+ plugins,
4297
4387
  external: [
4298
4388
  "ai",
4299
4389
  "ai/*",
@@ -4304,7 +4394,7 @@ async function importModule(file, context) {
4304
4394
  "veryfront/*",
4305
4395
  "@opentelemetry/*",
4306
4396
  "path",
4307
- // Mark relative imports as external to avoid filesystem access issues
4397
+ // Only mark relative imports as external in Deno (plugin handles them in Node.js)
4308
4398
  ...relativeImports
4309
4399
  ],
4310
4400
  stdin: {
@@ -4319,21 +4409,22 @@ async function importModule(file, context) {
4319
4409
  throw new Error(`Failed to transpile ${filePath}: ${first}`);
4320
4410
  }
4321
4411
  const js = result.outputFiles?.[0]?.text ?? "export {}";
4322
- const tempDir = await fs2.makeTempDir({ prefix: "vf-discovery-" });
4412
+ const localFs = createFileSystem();
4413
+ const tempDir = await localFs.makeTempDir({ prefix: "vf-discovery-" });
4323
4414
  const tempFile = join2(tempDir, "module.mjs");
4324
4415
  let transformedCode;
4325
4416
  if (isDeno) {
4326
4417
  transformedCode = rewriteForDeno(js, fileDir);
4327
4418
  } else {
4328
- transformedCode = await rewriteDiscoveryImports(js, context.baseDir || ".", fs2, fileDir);
4419
+ transformedCode = await rewriteDiscoveryImports(js, context.baseDir || ".", localFs, fileDir);
4329
4420
  }
4330
- await fs2.writeTextFile(tempFile, transformedCode);
4421
+ await localFs.writeTextFile(tempFile, transformedCode);
4331
4422
  try {
4332
4423
  const module = await import(`file://${tempFile}?v=${Date.now()}`);
4333
4424
  transpileCache.set(cacheKey, module);
4334
4425
  return module;
4335
4426
  } finally {
4336
- await fs2.remove(tempDir, { recursive: true });
4427
+ await localFs.remove(tempDir, { recursive: true });
4337
4428
  }
4338
4429
  }
4339
4430
  function rewriteForDeno(code, fileDir) {