types.ts 812 B

1234567891011121314151617181920212223242526272829303132333435
  1. export interface LLMUsage {
  2. used: number;
  3. total: number;
  4. available: boolean;
  5. }
  6. export interface LLMModel {
  7. name: string;
  8. available: boolean;
  9. }
  10. export const ROLES = ["system", "user", "assistant"] as const;
  11. export type MessageRole = (typeof ROLES)[number];
  12. export interface RequestMessage {
  13. role: MessageRole;
  14. content: string;
  15. }
  16. export interface ChatOptions {
  17. messages: RequestMessage[];
  18. shouldSummarize?: boolean;
  19. onUpdate?: (message: string, chunk: string) => void;
  20. onFinish: (message: string) => void;
  21. onError?: (err: Error) => void;
  22. onController?: (controller: AbortController) => void;
  23. }
  24. export type LLMClient = {
  25. chat(options: ChatOptions): Promise<void>;
  26. chatStream(options: ChatOptions): Promise<void>;
  27. usage(): Promise<LLMUsage>;
  28. models(): Promise<LLMModel[]>;
  29. };