src.index
session
Session Objects ↗ (opens in a new tab)
class Session()
The Session
class represents an interaction session with the AI engine API, managing messages and function executions within a function group.
Attributes
_apiBaseUrl
string - The base URL for the AI engine API._apiKey
string - The API key used for authentication.sessionId
string - The unique identifier for the session.functionGroup
string - The function group associated with the session._messages
ApiMessage[] - A list of messages associated with the session._messageIds
Set of string - A set to store unique message IDs to prevent duplication.
Methods:
Constructor ↗ (opens in a new tab)
constructor(apiBaseUrl: string, apiKey: string, sessionId: string, functionGroup: string)
Parameters:
apiBaseUrl
string - The base URL for the API.apiKey
string - The API key for authentication.sessionId
string - The unique identifier for the session.functionGroup
string - The function group associated with the session.
_submitMessage ↗ (opens in a new tab)
async _submitMessage(payload: ApiMessagePayload)
Submits a message to the API.
Parameters:
payload
ApiMessagePayload - The message payload to be submitted.
start ↗ (opens in a new tab)
async start(objective: string, context?: string)
Starts a new session by submitting an initial message.
Parameters:
objective
string - The primary objective of the session.context
string, optional - Additional context for the session.
submitTaskSelection ↗ (opens in a new tab)
async submitTaskSelection(selection: TaskSelectionMessage, options: TaskOption[])
Submits a message with the selected task.
Parameters:
selection
TaskSelectionMessage - The selected task message.options
TaskOption[] - List of selected tasks.
submitResponse ↗ (opens in a new tab)
async submitResponse(query: AgentMessage, response: string)
Sends a response to an agent's message.
Parameters:
query
AgentMessage - The agent's message being responded to.response
string - The user's response.
submitConfirmation ↗ (opens in a new tab)
async submitConfirmation(confirmation: ConfirmationMessage): Promise<void>
Submits a confirmation message.
Parameters:
confirmation
(ConfirmationMessage) - The confirmation message to be submitted.
rejectConfirmation ↗ (opens in a new tab)
async rejectConfirmation(confirmation: ConfirmationMessage, reason: string): Promise<void>
Rejects a confirmation with a reason.
Parameters:
confirmation
(ConfirmationMessage) - The confirmation message to be rejected.reason
(string) - The reason for rejection.
getMessages ↗ (opens in a new tab)
async getMessages(): Promise<Message[]>
Retrieves new messages from the chat session.
Returns:
Message[]
- A list of new messages.
delete ↗ (opens in a new tab)
async delete()
Deletes the session from the AI engine API.
execute_function ↗ (opens in a new tab)
async execute_function(functionIds: string[], objective: string, context: string): Promise<void>
Executes a set of functions within the AI engine.
Parameters:
functionIds
string[] - A list of function IDs to execute.objective
string - The objective or goal of executing these functions.context
string - Additional context for execution.
AiEngine Objects ↗ (opens in a new tab)
class AiEngine()
The AiEngine
class provides methods to interact with the AI engine API, such as retrieving function groups, credits, and models.
Methods:
Constructor ↗ (opens in a new tab)
constructor(apiKey: string, options?: { apiBaseUrl?: string })
Parameters:
apiKey
string - The API key for authentication.options.apiBaseUrl
string, optional - The base URL for the API (defaults tohttps://agentverse.ai
).
getFunctionGroups ↗ (opens in a new tab)
async getFunctionGroups(): Promise<FunctionGroup[]>
Retrieves a list of available function groups.
Returns:
FunctionGroup[]
- A list of function groups.
createSession ↗ (opens in a new tab)
async createSession(functionGroup: string, opts?: { email?: string; model?: KnownModelId | string }): Promise<Session>
Creates a new session.
Parameters:
functionGroup
string - The function group to use.opts.email
string, optional - User email.opts.model
KnownModelId | string, optional - The model identifier.
Returns:
Session
- The created session instance.
getCredits ↗ (opens in a new tab)
async getCredits(): Promise<CreditBalance>
Retrieves the credit balance information.
Returns:
CreditBalance
- The total, used, and available credits.
getModels ↗ (opens in a new tab)
async getModels(): Promise<Model[]>
Retrieves a list of models and their associated credits.
Returns:
Model[]
- A list of available models with their credit balance.
getModelCredits ↗ (opens in a new tab)
async getModelCredits(model: KnownModelId | CustomModel): Promise<number>
Retrieves the remaining token balance for a specific model.
Parameters:
model
(KnownModelId | CustomModel) - The model to retrieve credits for.
Returns:
number
- The remaining token balance for the model.