agent-service.ts


Overview

agent-service.ts is a TypeScript module that acts as a centralized service layer for interacting with various backend API endpoints related to "canvas" entities, agents, templates, logs, and related resources within an application. It abstracts HTTP request details by defining a collection of API methods and then registering them with a server utility (registerNextServer). This file primarily serves as an API client wrapper that simplifies calling backend services by defining consistent method signatures and URLs.

Key responsibilities:


Classes, Functions, and Methods

This file does not define any classes but exports a collection of service functions and an agentService object.

1. methods (constant object)

Example entry:

fetchCanvas: {
  url: fetchCanvas,   // imported URL string
  method: 'get',
}

2. agentService

import agentService from './agent-service';

// Fetch canvas by ID
agentService.fetchCanvas({ id: 'canvas123' }).then(response => {
  console.log(response.data);
});

(Note: Actual parameters depend on how registerNextServer constructs method signatures.)


3. fetchTrace

fetchTrace(data: { canvas_id: string; message_id: string }): Promise<any>
fetchTrace({ canvas_id: 'canvas123', message_id: 'msg456' })
  .then(response => {
    console.log('Trace data:', response.data);
  });

4. fetchAgentLogsByCanvasId

fetchAgentLogsByCanvasId(canvasId: string, params: IAgentLogsRequest): Promise<any>
fetchAgentLogsByCanvasId('canvas123', { limit: 10, offset: 0 })
  .then(response => {
    console.log('Agent logs:', response.data);
  });

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class agentService {
        +fetchCanvas()
        +getCanvasSSE()
        +setCanvas()
        +fetchVersionList()
        +fetchVersion()
        +listCanvas()
        +resetCanvas()
        +removeCanvas()
        +runCanvas()
        +listTemplates()
        +testDbConnect()
        +getInputElements()
        +debugSingle()
        +listCanvasTeam()
        +settingCanvas()
        +uploadCanvasFile()
        +trace()
        +inputForm()
        +fetchAgentAvatar()
        +fetchAgentLogs()
        +fetchExternalAgentInputs()
        +fetchPrompt()
    }
    class fetchTrace {
        +fetchTrace(data: {canvas_id:string, message_id:string})
    }
    class fetchAgentLogsByCanvasId {
        +fetchAgentLogsByCanvasId(canvasId:string, params: IAgentLogsRequest)
    }
    agentService ..> methods : uses
    fetchTrace ..> methods.trace : calls
    fetchAgentLogsByCanvasId ..> methods.fetchAgentLogs : calls

Summary

agent-service.ts is a dedicated API client module for managing agent and canvas-related backend interactions. It cleanly abstracts HTTP details behind a set of well-organized methods, supports dynamic URL generation, and exports useful helper functions for fetching trace data and logs. It is a vital part of the frontend's data layer, enabling consistent and type-safe communication with the backend services.


End of Documentation for agent-service.ts