-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rysweet typescript doc comments (#5678)
adding doc comments into my typescript branch
- Loading branch information
Showing
12 changed files
with
298 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
/** | ||
* Represents metadata associated with an agent, including its type, unique key, and description. | ||
*/ | ||
export interface AgentMetadata { | ||
/** | ||
* An identifier that associates an agent with a specific factory function. | ||
* Strings may only be composed of alphanumeric letters (a-z, 0-9), or underscores (_). | ||
*/ | ||
type: string; | ||
|
||
/** | ||
* A unique key identifying the agent instance. | ||
* Strings may only be composed of alphanumeric letters (a-z, 0-9), or underscores (_). | ||
*/ | ||
key: string; | ||
|
||
/** | ||
* A brief description of the agent's purpose or functionality. | ||
*/ | ||
description?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
/** | ||
* Represents the type of an agent as a string. | ||
* This is a strongly-typed wrapper around a string, ensuring type safety when working with agent types. | ||
*/ | ||
export type AgentType = string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
import { AgentId } from "./IAgentRuntime"; | ||
|
||
/** | ||
* Represents an agent within the runtime that can process messages, maintain state, | ||
* and be closed when no longer needed. | ||
*/ | ||
export interface IAgent { | ||
/** | ||
* Gets the unique identifier of the agent. | ||
*/ | ||
readonly id: AgentId; | ||
|
||
/** | ||
* Handles an incoming message for the agent. | ||
* This should only be called by the runtime, not by other agents. | ||
* @param message The received message. The type should match one of the expected subscription types. | ||
* @param context The context of the message, providing additional metadata. | ||
* @returns A promise resolving to a response to the message. Can be null if no reply is necessary. | ||
* @throws {CantHandleException} If the agent cannot handle the message. | ||
* @throws {OperationCanceledException} If the message was cancelled. | ||
*/ | ||
onMessageAsync(message: unknown, context: unknown): Promise<unknown>; | ||
|
||
/** | ||
* Saves the state of the agent. The result must be JSON serializable. | ||
* @returns A promise resolving to a dictionary containing the saved state. | ||
*/ | ||
saveStateAsync(): Promise<unknown>; | ||
|
||
/** | ||
* Loads the saved state into the agent. | ||
* @param state The state to restore. | ||
* @returns A promise that completes when the state has been loaded. | ||
*/ | ||
loadStateAsync(state: unknown): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import { MessageContext } from "./MessageContext"; | ||
|
||
// Generic interface for message handlers | ||
/** | ||
* Defines a handler interface for processing items of type TMessage. | ||
* @template TMessage The type of message to be handled. | ||
*/ | ||
export interface IHandle<TMessage> { | ||
/** | ||
* Handles the specified message asynchronously. | ||
* @param message The message to be handled. | ||
* @param context The context information for the message being handled. | ||
* @returns A promise that resolves to the result of handling the message. | ||
*/ | ||
handleAsync(message: TMessage, context: MessageContext): Promise<unknown>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
/** | ||
* Defines a contract for saving and loading the state of an object. | ||
* The state must be JSON serializable. | ||
*/ | ||
export interface ISaveState { | ||
/** | ||
* Saves the current state of the object. | ||
* @returns A promise that resolves to the saved state. The structure of the state | ||
* is implementation-defined but must be JSON serializable. | ||
*/ | ||
saveStateAsync(): Promise<unknown>; | ||
|
||
/** | ||
* Loads a previously saved state into the object. | ||
* @param state A state object representing the saved state. The structure of the state | ||
* is implementation-defined but must be JSON serializable. | ||
* @returns A promise that completes when the state has been loaded. | ||
*/ | ||
loadStateAsync(state: unknown): Promise<void>; | ||
// Interface for saving/loading agent state | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
import { AgentId, TopicId } from "./IAgentRuntime"; | ||
|
||
/** | ||
* Defines a subscription that matches topics and maps them to agents. | ||
*/ | ||
export interface ISubscriptionDefinition { | ||
/** | ||
* Gets the unique identifier of the subscription. | ||
*/ | ||
id: string; | ||
|
||
/** | ||
* Checks if a given TopicId matches the subscription. | ||
* @param topic The topic to check | ||
* @returns true if the topic matches the subscription; otherwise, false | ||
*/ | ||
matches(topic: TopicId): boolean; | ||
|
||
/** | ||
* Maps a TopicId to an AgentId. | ||
* Should only be called if matches() returns true. | ||
* @param topic The topic to map | ||
* @returns The AgentId that should handle the topic | ||
*/ | ||
mapToAgent(topic: TopicId): AgentId; | ||
} |
Oops, something went wrong.