agent.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // src/types/agent.ts
  2. export interface ToolStep {
  3. tool: string;
  4. arguments: Record<string, any>;
  5. call_id?: string;
  6. result?: any;
  7. is_error?: boolean;
  8. status: 'running' | 'completed' | 'failed';
  9. startedAt?: number;
  10. completedAt?: number;
  11. }
  12. export interface AgentToolFunction {
  13. name: string;
  14. description: string;
  15. parameters?: Record<string, any>;
  16. }
  17. export interface AgentToolMetadata {
  18. name: string;
  19. description: string;
  20. is_dangerous?: boolean;
  21. schema?: {
  22. type?: string;
  23. function?: AgentToolFunction;
  24. };
  25. }
  26. export interface AgentDangerousAction {
  27. tool: string;
  28. arguments: Record<string, any>;
  29. call_id?: string;
  30. description?: string;
  31. confirmed?: boolean;
  32. cancelled?: boolean;
  33. }
  34. export interface AgentMessage {
  35. id: string;
  36. role: 'user' | 'assistant' | 'system';
  37. content: string;
  38. timestamp: number;
  39. steps?: ToolStep[];
  40. thinking?: {
  41. status: 'started' | 'planning' | 'executing' | 'idle';
  42. step?: number;
  43. };
  44. isStreaming?: boolean;
  45. error?: string;
  46. dangerousAction?: AgentDangerousAction;
  47. }
  48. export interface AgentSession {
  49. id: string;
  50. title: string;
  51. createdAt: number;
  52. updatedAt: number;
  53. messageCount: number;
  54. lastMessageSnippet?: string;
  55. }
  56. export interface AgentChatParams {
  57. message: string;
  58. session_id?: string;
  59. stream?: boolean;
  60. max_steps?: number;
  61. model?: string;
  62. }
  63. export interface SSEStreamHandlers {
  64. onThink?: (step: number, status?: string) => void;
  65. onToolStart?: (tool: string, args: Record<string, any>, callId?: string) => void;
  66. onToolEnd?: (tool: string, result: any, isError: boolean, callId?: string) => void;
  67. onMessage?: (delta: string, full: string) => void;
  68. onFinish?: (finalAnswer: string, stepsCount: number, sessionId?: string) => void;
  69. onError?: (err: any) => void;
  70. }