INNER CODE UNIT · TypeScript

orderedAdapters

harvard-edge/cs249r_book · interviews/staffml/worker/src/index.ts:245

function orderedAdapters(env: Env): Adapter[] {
  const priority = (env.PROVIDER_PRIORITY ?? "groq,openai,anthropic,gemini,openrouter,cf-workers-ai")
    .split(",")
    .map((s) => s.trim())
    .filter(Boolean);
  const byName = new Map(ADAPTERS.map((a) => [a.name, a]));
  const ordered: Adapter[] = [];
  for (const name of priority) {
    const a = byName.get(name);
    if (a && isAvailable(a, env)) ordered.push(a);
  }
  // Always append cf-workers-ai as the floor if not already in the list
  const floor = byName.get("cf-workers-ai");
  if (floor && !ordered.includes(floor) && isAvailable(floor, env)) {
    ordered.push(floor);
  }
  return ordered;
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…