@dvina/agents 0.3.0 → 0.3.2

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/index.cjs CHANGED
@@ -12838,7 +12838,9 @@ var require_out4 = __commonJS({
12838
12838
  // src/index.ts
12839
12839
  var index_exports = {};
12840
12840
  __export(index_exports, {
12841
+ InMemoryToolCache: () => InMemoryToolCache,
12841
12842
  LangchainAgentFactory: () => LangchainAgentFactory,
12843
+ RedisToolCache: () => RedisToolCache,
12842
12844
  ToolRegistry: () => ToolRegistry
12843
12845
  });
12844
12846
  module.exports = __toCommonJS(index_exports);
@@ -21708,20 +21710,14 @@ var ToolRegistry = class {
21708
21710
  }
21709
21711
  invalidate(toolKit) {
21710
21712
  const entry = this.entries.get(toolKit);
21711
- if (entry && entry.type === "provider") {
21712
- void this.toolSpecCache?.del?.(this.toolSpecsCacheKey(toolKit));
21713
- }
21714
- }
21715
- toolSpecsCacheKey(toolKit) {
21716
- return `tool-specs:v1:${toolKit}`;
21713
+ if (entry && entry.type === "provider") this.toolSpecCache?.del(toolKit);
21717
21714
  }
21718
21715
  async getToolKitSpecs(toolKit, provider, context) {
21719
- const cacheKey = this.toolSpecsCacheKey(toolKit);
21720
21716
  const cache = this.toolSpecCache;
21721
21717
  if (cache) {
21722
21718
  try {
21723
- const cached = await Promise.resolve(cache.get(cacheKey));
21724
- if (cached) return JSON.parse(cached);
21719
+ const cached = await cache.get(toolKit);
21720
+ if (cached) return cached;
21725
21721
  } catch (e) {
21726
21722
  console.error("Something went wrong when hitting the cache", e);
21727
21723
  }
@@ -21729,7 +21725,7 @@ var ToolRegistry = class {
21729
21725
  const specs = await provider.listToolKitSpecs(toolKit, context) ?? [];
21730
21726
  if (cache) {
21731
21727
  try {
21732
- await Promise.resolve(cache.set(cacheKey, JSON.stringify(specs)));
21728
+ await cache.set(toolKit, specs);
21733
21729
  } catch (e) {
21734
21730
  console.error("Something went wrong when setting the cache", e);
21735
21731
  }
@@ -21737,9 +21733,58 @@ var ToolRegistry = class {
21737
21733
  return specs;
21738
21734
  }
21739
21735
  };
21736
+
21737
+ // src/core/tools/tool-cache.ts
21738
+ var import_ioredis = __toESM(require("ioredis"), 1);
21739
+ var import_zod2 = require("zod");
21740
+ var RedisToolCache = class {
21741
+ redis;
21742
+ constructor(connectionString) {
21743
+ this.redis = new import_ioredis.default(connectionString);
21744
+ }
21745
+ async get(toolKit) {
21746
+ const data = await this.redis.get(`tool-cache:${toolKit}`);
21747
+ if (!data) return null;
21748
+ try {
21749
+ const parsed = JSON.parse(data);
21750
+ if (!Array.isArray(parsed)) return null;
21751
+ return parsed.map((spec) => ({
21752
+ ...spec,
21753
+ inputSchema: import_zod2.z.fromJSONSchema(spec.inputSchema)
21754
+ }));
21755
+ } catch (e) {
21756
+ console.error("Failed to parse cached tools", e);
21757
+ return null;
21758
+ }
21759
+ }
21760
+ async set(toolKit, specs) {
21761
+ const serialized = specs.map((spec) => ({
21762
+ ...spec,
21763
+ inputSchema: spec.inputSchema.toJSONSchema()
21764
+ }));
21765
+ await this.redis.set(`tool-cache:${toolKit}`, JSON.stringify(serialized));
21766
+ }
21767
+ async del(toolKit) {
21768
+ await this.redis.del(`tool-cache:${toolKit}`);
21769
+ }
21770
+ };
21771
+ var InMemoryToolCache = class {
21772
+ cache = /* @__PURE__ */ new Map();
21773
+ get(toolKit) {
21774
+ return this.cache.get(`tool-cache:${toolKit}`) ?? null;
21775
+ }
21776
+ async set(toolKit, specs) {
21777
+ this.cache.set(`tool-cache:${toolKit}`, specs);
21778
+ }
21779
+ async del(toolKit) {
21780
+ this.cache.delete(`tool-cache:${toolKit}`);
21781
+ }
21782
+ };
21740
21783
  // Annotate the CommonJS export names for ESM import in node:
21741
21784
  0 && (module.exports = {
21785
+ InMemoryToolCache,
21742
21786
  LangchainAgentFactory,
21787
+ RedisToolCache,
21743
21788
  ToolRegistry
21744
21789
  });
21745
21790
  /*! Bundled license information: