All files / src/services/api/routers GenerationRouter.tsx

81.81% Statements 9/11
71.42% Branches 5/7
100% Functions 3/3
81.81% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                                            2209x     2209x 3x 3x 3x         2209x           6x       6x 6x          
import { GenerationRun } from "@/objects/History";
import { Dictionary } from "@/types/ext";
import { AxiosRequestConfig } from "axios";
import { APIRouter } from "../ApiRouter";
 
/**
 * Generative invocations — the "why does this exist?" read path.
 *
 * A history entry links a `generation_id`; this resolves it to the invocation
 * itself: the flow, the exact arguments the user gave, the model that
 * answered, and the resources that came out of it.
 *
 * Read-only by design — runs are written by the flows that perform them and
 * are never edited, so there is no create/update/delete here.
 */
export class GenerationRouter extends APIRouter {
  constructor(
    host: string,
    token: string | null = null,
    default_config: AxiosRequestConfig | null = null,
    headers: Dictionary<string> = {},
  ) {
    super("generations", host, token, default_config, headers);
  }
 
  get = async (id: string): Promise<GenerationRun | null> => {
    const res = await this.api.get<GenerationRun>(super.endpoint(id));
    Eif (super.validRes(res)) {
      return res.data;
    }
    return null;
  };
 
  list = async (params?: {
    flow?: string;
    status?: string;
    limit?: number;
    offset?: number;
  }): Promise<{ generations: GenerationRun[]; total: number } | null> => {
    const res = await this.api.get<{
      generations: GenerationRun[];
      total: number;
    }>(this.prefix, { params });
    Eif (super.validRes(res)) {
      return res.data;
    }
    return null;
  };
}