veryfront 0.0.5 → 0.0.6

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
@@ -35,8 +35,7 @@ function getEnvironmentVariable(name) {
35
35
  const value = globalThis.process?.env[name];
36
36
  return value === "" ? void 0 : value;
37
37
  }
38
- } catch (error) {
39
- console.debug(`Failed to get environment variable ${name}:`, error);
38
+ } catch {
40
39
  return void 0;
41
40
  }
42
41
  return void 0;
@@ -88,10 +87,10 @@ var ConsoleLogger = class {
88
87
  const end = performance.now();
89
88
  this.debug(`${label} completed in ${(end - start).toFixed(2)}ms`);
90
89
  return result;
91
- } catch (_error) {
90
+ } catch (error) {
92
91
  const end = performance.now();
93
- this.error(`${label} failed after ${(end - start).toFixed(2)}ms`, _error);
94
- throw _error;
92
+ this.error(`${label} failed after ${(end - start).toFixed(2)}ms`, error);
93
+ throw error;
95
94
  }
96
95
  }
97
96
  };
@@ -846,10 +845,69 @@ var GoogleProvider = class extends BaseProvider {
846
845
  };
847
846
 
848
847
  // src/ai/providers/factory.ts
848
+ function getEnv(name) {
849
+ if (typeof Deno !== "undefined" && Deno.env) {
850
+ return process.env(name);
851
+ }
852
+ const _global = globalThis;
853
+ if (typeof _global.process !== "undefined" && _global.process.env) {
854
+ return _global.process.env[name];
855
+ }
856
+ return void 0;
857
+ }
849
858
  var ProviderRegistry = class {
850
859
  constructor() {
851
860
  this.providers = /* @__PURE__ */ new Map();
852
861
  this.config = {};
862
+ this.autoInitialized = false;
863
+ }
864
+ /**
865
+ * Auto-initialize providers from environment variables
866
+ * This is called lazily when a provider is first requested
867
+ */
868
+ autoInitializeFromEnv() {
869
+ if (this.autoInitialized)
870
+ return;
871
+ this.autoInitialized = true;
872
+ const openaiKey = getEnv("OPENAI_API_KEY");
873
+ if (openaiKey && !this.providers.has("openai")) {
874
+ try {
875
+ const provider = new OpenAIProvider({
876
+ apiKey: openaiKey,
877
+ baseURL: getEnv("OPENAI_BASE_URL"),
878
+ organizationId: getEnv("OPENAI_ORGANIZATION_ID")
879
+ });
880
+ this.providers.set("openai", provider);
881
+ agentLogger.debug("Auto-initialized OpenAI provider from environment");
882
+ } catch (error) {
883
+ agentLogger.warn("Failed to auto-initialize OpenAI provider:", error);
884
+ }
885
+ }
886
+ const anthropicKey = getEnv("ANTHROPIC_API_KEY");
887
+ if (anthropicKey && !this.providers.has("anthropic")) {
888
+ try {
889
+ const provider = new AnthropicProvider({
890
+ apiKey: anthropicKey,
891
+ baseURL: getEnv("ANTHROPIC_BASE_URL")
892
+ });
893
+ this.providers.set("anthropic", provider);
894
+ agentLogger.debug("Auto-initialized Anthropic provider from environment");
895
+ } catch (error) {
896
+ agentLogger.warn("Failed to auto-initialize Anthropic provider:", error);
897
+ }
898
+ }
899
+ const googleKey = getEnv("GOOGLE_API_KEY") || getEnv("GOOGLE_GENERATIVE_AI_API_KEY");
900
+ if (googleKey && !this.providers.has("google")) {
901
+ try {
902
+ const provider = new GoogleProvider({
903
+ apiKey: googleKey
904
+ });
905
+ this.providers.set("google", provider);
906
+ agentLogger.debug("Auto-initialized Google provider from environment");
907
+ } catch (error) {
908
+ agentLogger.warn("Failed to auto-initialize Google provider:", error);
909
+ }
910
+ }
853
911
  }
854
912
  /**
855
913
  * Initialize providers from configuration
@@ -885,6 +943,7 @@ var ProviderRegistry = class {
885
943
  * Get a provider by name
886
944
  */
887
945
  getProvider(name) {
946
+ this.autoInitializeFromEnv();
888
947
  const provider = this.providers.get(name);
889
948
  if (!provider) {
890
949
  throw toError(createError({
@@ -927,12 +986,14 @@ var ProviderRegistry = class {
927
986
  * Check if a provider is available
928
987
  */
929
988
  hasProvider(name) {
989
+ this.autoInitializeFromEnv();
930
990
  return this.providers.has(name);
931
991
  }
932
992
  /**
933
993
  * Get all available provider names
934
994
  */
935
995
  getAvailableProviders() {
996
+ this.autoInitializeFromEnv();
936
997
  return Array.from(this.providers.keys());
937
998
  }
938
999
  /**
@@ -1553,15 +1614,15 @@ var SECONDS_PER_MINUTE = 60;
1553
1614
  var MINUTES_PER_HOUR = 60;
1554
1615
  var HOURS_PER_DAY = 24;
1555
1616
  var MS_PER_SECOND = 1e3;
1556
- var COMPONENT_LOADER_TTL_MS = 10 * MINUTES_PER_HOUR * MS_PER_SECOND;
1557
- var MDX_RENDERER_TTL_MS = 10 * MINUTES_PER_HOUR * MS_PER_SECOND;
1558
- var RENDERER_CORE_TTL_MS = 5 * MINUTES_PER_HOUR * MS_PER_SECOND;
1559
- var TSX_LAYOUT_TTL_MS = 10 * MINUTES_PER_HOUR * MS_PER_SECOND;
1560
- var DATA_FETCHING_TTL_MS = 10 * MINUTES_PER_HOUR * MS_PER_SECOND;
1617
+ var COMPONENT_LOADER_TTL_MS = 10 * SECONDS_PER_MINUTE * MS_PER_SECOND;
1618
+ var MDX_RENDERER_TTL_MS = 10 * SECONDS_PER_MINUTE * MS_PER_SECOND;
1619
+ var RENDERER_CORE_TTL_MS = 5 * SECONDS_PER_MINUTE * MS_PER_SECOND;
1620
+ var TSX_LAYOUT_TTL_MS = 10 * SECONDS_PER_MINUTE * MS_PER_SECOND;
1621
+ var DATA_FETCHING_TTL_MS = 10 * SECONDS_PER_MINUTE * MS_PER_SECOND;
1561
1622
  var MDX_CACHE_TTL_PRODUCTION_MS = HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE * MS_PER_SECOND;
1562
- var MDX_CACHE_TTL_DEVELOPMENT_MS = 5 * MINUTES_PER_HOUR * MS_PER_SECOND;
1623
+ var MDX_CACHE_TTL_DEVELOPMENT_MS = 5 * SECONDS_PER_MINUTE * MS_PER_SECOND;
1563
1624
  var BUNDLE_CACHE_TTL_PRODUCTION_MS = HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE * MS_PER_SECOND;
1564
- var BUNDLE_CACHE_TTL_DEVELOPMENT_MS = 5 * MINUTES_PER_HOUR * MS_PER_SECOND;
1625
+ var BUNDLE_CACHE_TTL_DEVELOPMENT_MS = 5 * SECONDS_PER_MINUTE * MS_PER_SECOND;
1565
1626
  var BUNDLE_MANIFEST_PROD_TTL_MS = 7 * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE * MS_PER_SECOND;
1566
1627
  var BUNDLE_MANIFEST_DEV_TTL_MS = MINUTES_PER_HOUR * SECONDS_PER_MINUTE * MS_PER_SECOND;
1567
1628
  var SERVER_ACTION_DEFAULT_TTL_SEC = MINUTES_PER_HOUR * SECONDS_PER_MINUTE;
@@ -1614,7 +1675,7 @@ var BYTES_PER_MB = 1024 * 1024;
1614
1675
  // deno.json
1615
1676
  var deno_default = {
1616
1677
  name: "veryfront",
1617
- version: "0.1.0",
1678
+ version: "0.0.6",
1618
1679
  nodeModulesDir: "auto",
1619
1680
  workspace: [
1620
1681
  "./examples/async-worker-redis",
@@ -2079,14 +2140,10 @@ var ContextPropagation = class {
2079
2140
  async withActiveSpan(span, fn) {
2080
2141
  if (!span)
2081
2142
  return await fn();
2082
- try {
2083
- return await this.api.context.with(
2084
- this.api.trace.setSpan(this.api.context.active(), span),
2085
- fn
2086
- );
2087
- } catch (error) {
2088
- throw error;
2089
- }
2143
+ return await this.api.context.with(
2144
+ this.api.trace.setSpan(this.api.context.active(), span),
2145
+ fn
2146
+ );
2090
2147
  }
2091
2148
  withSpan(name, fn, startSpan, endSpan) {
2092
2149
  const span = startSpan(name);
@@ -2366,7 +2423,6 @@ var AgentRuntime = class {
2366
2423
  role: "assistant",
2367
2424
  content: response.text,
2368
2425
  toolCalls: response.toolCalls,
2369
- // Include tool calls from response
2370
2426
  timestamp: Date.now()
2371
2427
  };
2372
2428
  currentMessages.push(assistantMessage);
@@ -2402,7 +2458,6 @@ var AgentRuntime = class {
2402
2458
  role: "tool",
2403
2459
  content: JSON.stringify(result),
2404
2460
  toolCallId: tc.id,
2405
- // Required by OpenAI API
2406
2461
  toolCall,
2407
2462
  timestamp: Date.now()
2408
2463
  };
@@ -2417,7 +2472,6 @@ var AgentRuntime = class {
2417
2472
  role: "tool",
2418
2473
  content: `Error: ${toolCall.error}`,
2419
2474
  toolCallId: tc.id,
2420
- // Required by OpenAI API
2421
2475
  toolCall,
2422
2476
  timestamp: Date.now()
2423
2477
  };
@@ -2558,7 +2612,7 @@ var AgentRuntime = class {
2558
2612
  try {
2559
2613
  const event = JSON.parse(line);
2560
2614
  handleEvent(event);
2561
- } catch (_e) {
2615
+ } catch {
2562
2616
  continue;
2563
2617
  }
2564
2618
  }
@@ -3049,9 +3103,6 @@ function agent(config) {
3049
3103
  const compatibility = validatePlatformCompatibility({
3050
3104
  maxSteps: config.maxSteps,
3051
3105
  streaming: config.streaming,
3052
- // Conservative defaults: filesystem and MCP requirements aren't auto-detected yet
3053
- // since Tool and AgentConfig types don't expose these flags. This ensures agents
3054
- // work across all platforms. Users can manually specify via edge config if needed.
3055
3106
  requiresFileSystem: false,
3056
3107
  requiresMCP: false
3057
3108
  }, platform);
@@ -3094,7 +3145,6 @@ ${compatibility.warnings.join("\n")}`
3094
3145
  }
3095
3146
  });
3096
3147
  },
3097
- // Memory management
3098
3148
  getMemory() {
3099
3149
  return runtime.getMemory();
3100
3150
  },
@@ -3573,9 +3623,7 @@ function createMockAdapter() {
3573
3623
  },
3574
3624
  fs: {
3575
3625
  files,
3576
- // Expose files Map for tests to populate
3577
3626
  directories,
3578
- // Expose directories Set for tests to track empty dirs
3579
3627
  readFile: (path) => {
3580
3628
  const content = files.get(path);
3581
3629
  if (!content) {
@@ -3599,12 +3647,7 @@ function createMockAdapter() {
3599
3647
  if (filePath.startsWith(path + "/"))
3600
3648
  return true;
3601
3649
  }
3602
- try {
3603
- await Deno.stat(path);
3604
- return true;
3605
- } catch {
3606
- return false;
3607
- }
3650
+ return false;
3608
3651
  },
3609
3652
  readDir: async function* (path) {
3610
3653
  const entries = /* @__PURE__ */ new Map();
@@ -3911,7 +3954,6 @@ async function getNodeDeps(context) {
3911
3954
  }
3912
3955
  if (context.fsAdapter) {
3913
3956
  context.nodeDeps = {
3914
- // Minimal shim using fsAdapter to satisfy types; not used when fsAdapter path is chosen
3915
3957
  fs: {},
3916
3958
  path: {}
3917
3959
  };
@@ -4659,6 +4701,7 @@ var LRUCache = class {
4659
4701
  var TTLCache = class {
4660
4702
  constructor(ttl = 3e5) {
4661
4703
  this.cache = /* @__PURE__ */ new Map();
4704
+ this.cleanupInterval = null;
4662
4705
  this.ttl = ttl;
4663
4706
  this.startCleanup();
4664
4707
  }
@@ -4703,8 +4746,15 @@ var TTLCache = class {
4703
4746
  size() {
4704
4747
  return this.cache.size;
4705
4748
  }
4749
+ destroy() {
4750
+ if (this.cleanupInterval) {
4751
+ clearInterval(this.cleanupInterval);
4752
+ this.cleanupInterval = null;
4753
+ }
4754
+ this.cache.clear();
4755
+ }
4706
4756
  startCleanup() {
4707
- setInterval(() => {
4757
+ this.cleanupInterval = setInterval(() => {
4708
4758
  const now = Date.now();
4709
4759
  for (const [key, entry] of this.cache.entries()) {
4710
4760
  if (entry.expiresAt && now >= entry.expiresAt) {
@@ -4811,6 +4861,7 @@ var CostTracker = class {
4811
4861
  this.monthlyTotal = 0;
4812
4862
  this.lastDayReset = Date.now();
4813
4863
  this.lastMonthReset = Date.now();
4864
+ this.resetInterval = null;
4814
4865
  this.config = config;
4815
4866
  this.startPeriodicReset();
4816
4867
  }
@@ -4930,11 +4981,8 @@ var CostTracker = class {
4930
4981
  }
4931
4982
  }
4932
4983
  }
4933
- /**
4934
- * Reset periodic totals
4935
- */
4936
4984
  startPeriodicReset() {
4937
- setInterval(() => {
4985
+ this.resetInterval = setInterval(() => {
4938
4986
  const now = Date.now();
4939
4987
  if (now - this.lastDayReset >= 24 * 60 * 60 * 1e3) {
4940
4988
  this.dailyTotal = 0;
@@ -4946,6 +4994,13 @@ var CostTracker = class {
4946
4994
  }
4947
4995
  }, 6e4);
4948
4996
  }
4997
+ destroy() {
4998
+ if (this.resetInterval) {
4999
+ clearInterval(this.resetInterval);
5000
+ this.resetInterval = null;
5001
+ }
5002
+ this.records = [];
5003
+ }
4949
5004
  /**
4950
5005
  * Create empty record
4951
5006
  */