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

88.88% Statements 8/9
88.88% Branches 8/9
100% Functions 3/3
88.88% Lines 8/9

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                                2209x       2209x             71x           71x 71x             2209x 5x 5x      
import type { RunningTurn } from "@/objects/Turn";
import { Dictionary } from "@/types/ext";
import { AxiosRequestConfig } from "axios";
import { APIRouter } from "../ApiRouter";
 
/**
 * The caller's running chat turns (svc-core `/app/turns`): what a chat page
 * opened mid-answer shows, and Stop for a turn another page started.
 */
export class TurnRouter extends APIRouter {
  constructor(
    host: string,
    token: string | null = null,
    default_config: AxiosRequestConfig | null = null,
    headers: Dictionary<string> = {},
  ) {
    super("turns", host, token, default_config, headers);
  }
 
  /** The caller's running turns with an agent or a model, oldest first. */
  list = async ({
    agentId,
    modelId,
  }: {
    agentId?: string;
    modelId?: string;
  }): Promise<RunningTurn[] | null> => {
    const res = await this.api.get<RunningTurn[]>(
      super.endpoint("", {
        ...(agentId ? { agent_id: agentId } : {}),
        ...(modelId ? { model_id: modelId } : {}),
      }),
    );
    Eif (super.validRes(res)) {
      return res.data;
    }
    return null;
  };
 
  /** Stop one of the caller's turns: svc-ai's run ends, and the turn is
   *  stored with what it had written. False when it is no longer running. */
  stop = async (id: string): Promise<boolean> => {
    const res = await this.api.post(super.endpoint(`${id}/stop`), {});
    return super.validRes(res);
  };
}