graph.d.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import type { RunnableInterface, RunnableIOSchema, Node, Edge } from "./types.js";
  2. export { Node, Edge };
  3. export declare class Graph {
  4. nodes: Record<string, Node>;
  5. edges: Edge[];
  6. constructor(params?: {
  7. nodes: Record<string, Node>;
  8. edges: Edge[];
  9. });
  10. toJSON(): Record<string, any>;
  11. addNode(data: RunnableInterface | RunnableIOSchema, id?: string, metadata?: Record<string, any>): Node;
  12. removeNode(node: Node): void;
  13. addEdge(source: Node, target: Node, data?: string, conditional?: boolean): Edge;
  14. firstNode(): Node | undefined;
  15. lastNode(): Node | undefined;
  16. /**
  17. * Add all nodes and edges from another graph.
  18. * Note this doesn't check for duplicates, nor does it connect the graphs.
  19. */
  20. extend(graph: Graph, prefix?: string): ({
  21. id: string;
  22. data: RunnableIOSchema | RunnableInterface<any, any, import("./types.js").RunnableConfig<Record<string, any>>>;
  23. } | undefined)[];
  24. trimFirstNode(): void;
  25. trimLastNode(): void;
  26. /**
  27. * Return a new graph with all nodes re-identified,
  28. * using their unique, readable names where possible.
  29. */
  30. reid(): Graph;
  31. drawMermaid(params?: {
  32. withStyles?: boolean;
  33. curveStyle?: string;
  34. nodeColors?: Record<string, string>;
  35. wrapLabelNWords?: number;
  36. }): string;
  37. drawMermaidPng(params?: {
  38. withStyles?: boolean;
  39. curveStyle?: string;
  40. nodeColors?: Record<string, string>;
  41. wrapLabelNWords?: number;
  42. backgroundColor?: string;
  43. }): Promise<Blob>;
  44. }