handoff-pushed-array-many.ts 699 B

12345678910111213
  1. // A const array literal that is later `push`ed is NOT a literal length: the analyzer must
  2. // give no cardinality (no ` count=` on the fan-out) and the family becomes one `many` card.
  3. // The second fan-out iterates an ask result — unknowable, also `many`.
  4. interface Draft {
  5. text: string;
  6. }
  7. const topics = ["sky", "sea"];
  8. topics.push("soil");
  9. const drafts = await Promise.all(topics.map((t) => agent(`writer-${t}`).ask<Draft>(`write about ${t}`)));
  10. const planner = agent("planner");
  11. const more = await planner.ask<string[]>(`more topics after ${drafts.length}`);
  12. const extra = await Promise.all(more.map((t) => agent(`writer-${t}`).ask<Draft>(`write about ${t}`)));
  13. return [...drafts, ...extra];