MCPcopy
hub / github.com/rohitg00/agentmemory / FallbackChainProvider

Class FallbackChainProvider

src/providers/fallback-chain.ts:3–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import type { MemoryProvider } from "../types.js";
2
3export class FallbackChainProvider implements MemoryProvider {
4 name: string;
5
6 constructor(private providers: MemoryProvider[]) {
7 this.name = `fallback(${providers.map((p) => p.name).join(" -> ")})`;
8 }
9
10 async compress(systemPrompt: string, userPrompt: string): Promise<string> {
11 return this.tryAll((p) => p.compress(systemPrompt, userPrompt));
12 }
13
14 async summarize(systemPrompt: string, userPrompt: string): Promise<string> {
15 return this.tryAll((p) => p.summarize(systemPrompt, userPrompt));
16 }
17
18 private async tryAll(
19 fn: (p: MemoryProvider) => Promise<string>,
20 ): Promise<string> {
21 let lastError: Error | null = null;
22 for (const provider of this.providers) {
23 try {
24 return await fn(provider);
25 } catch (err) {
26 lastError = err instanceof Error ? err : new Error(String(err));
27 }
28 }
29 throw lastError || new Error("No providers available");
30 }
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected