The FunctionMap class in the Delphi framework is a specialized map used to
store and manage functions callable by an agent. Below is a detailed API
reference for this class.
FunctionMapA map for storing AgentFunction instances with additional capabilities to
enable or disable functions.
constructor(functions?: IterableIterator<AgentFunction<any, any>>, enable = false)
Initializes a new instance of FunctionMap.
| Parameter | Type | Description |
|---|---|---|
functions |
Iterable<AgentFunction<any, any>> |
An optional iterable of AgentFunction instances. |
enabled: Returns a readonly array of the names of enabled functions.addFunctionAdds a function to the map.
addFunction(fn: AgentFunction<any, any>): void
| Parameter | Type | Description |
|---|---|---|
fn |
AgentFunction<any, any> |
The function to add. |
Throws: Error if the function already exists in the map.
addFunctionsAdds multiple functions to the map.
addFunctions(...fns: (AgentFunction<any, any> | { fn: AgentFunction<any, any>, enabled?: boolean })[]): void
| Parameter | Type | Description |
|---|---|---|
fns |
(AgentFunction<any, any> \| { fn: AgentFunction<any, any>, enabled?: boolean })[] |
An array of AgentFunction instances or objects containing a function and an optional flag. |
Throws: Error if any of the functions already exist in the map.
enableEnables a function in the map by its name or function instance.
enable(name: string): void
enable(fn: AgentFunction<any, any>): void
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name of the function. |
fn |
AgentFunction<any, any> |
The function to enable. |
Throws: Error if the function does not exist.
enableAllEnables all functions in the map.
enableAll(): void
disableDisables a function in the map by its name.
disable(name: string): void
disable(fn: AgentFunction<any, any>): void
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name of the function. |
fn |
AgentFunction<any, any> |
The function to disable. |
Throws: Error if the function does not exist.
disableAllDisables all functions in the map.
disableAll(): void
buildBuilds and returns an array of FunctionDefinition objects based on the enabled
functions.
build(): FunctionDefinition[]
Returns: FunctionDefinition[] - An array of function definitions for the
enabled functions.
const functionMap = new FunctionMap();
// Adding functions
const myFunction = new AgentFunction(/* ... */);
functionMap.addFunction(myFunction);
// Enabling and disabling functions
functionMap.enable(myFunction);
functionMap.disable("anotherFunctionName");
// Building function definitions for use
const functionDefinitions = functionMap.build();
In this example, functionMap is an instance of FunctionMap where a custom
function is added and then enabled. The build method is used to prepare
function definitions based on the enabled functions.
The FunctionMap class provides a convenient way to manage the functions your
Delphi agent can call, with the flexibility to enable or disable functions as
needed. This class is integral to the modular and dynamic nature of the Delphi
framework.