@elizaos/core 1.0.0-alpha.0 → 1.0.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,6 +4,10 @@ import * as pino from 'pino';
4
4
  /**
5
5
  * Represents a UUID string in the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
6
6
  */
7
+ /**
8
+ * Type definition for a Universally Unique Identifier (UUID) using a specific format.
9
+ * @typedef {`${string}-${string}-${string}-${string}-${string}`} UUID
10
+ */
7
11
  type UUID = `${string}-${string}-${string}-${string}-${string}`;
8
12
  /**
9
13
  * Represents the content of a message or communication
@@ -429,9 +433,10 @@ declare abstract class Service {
429
433
  static stop(_runtime: IAgentRuntime): Promise<unknown>;
430
434
  }
431
435
  type Route = {
432
- type: "GET" | "POST" | "PUT" | "DELETE";
436
+ type: "GET" | "POST" | "PUT" | "DELETE" | "STATIC";
433
437
  path: string;
434
- handler: (req: any, res: any, runtime: IAgentRuntime) => Promise<void>;
438
+ filePath?: string;
439
+ handler?: (req: any, res: any, runtime: IAgentRuntime) => Promise<void>;
435
440
  };
436
441
  /**
437
442
  * Plugin for extending agent functionality
@@ -453,7 +458,7 @@ interface Plugin {
453
458
  actions?: Action[];
454
459
  providers?: Provider[];
455
460
  evaluators?: Evaluator[];
456
- adapters?: IDatabaseAdapter[];
461
+ adapter?: IDatabaseAdapter;
457
462
  models?: {
458
463
  [key: string]: (...args: any[]) => Promise<any>;
459
464
  };
@@ -540,6 +545,8 @@ interface Agent extends Character {
540
545
  interface IDatabaseAdapter {
541
546
  /** Database instance */
542
547
  db: any;
548
+ /** Initialize database connection */
549
+ init(): Promise<void>;
543
550
  /** Close database connection */
544
551
  close(): Promise<void>;
545
552
  getAgent(agentId: UUID): Promise<Agent | null>;
@@ -759,7 +766,6 @@ interface IAgentRuntime {
759
766
  getAllServices(): Map<ServiceType, Service>;
760
767
  registerService(service: typeof Service): void;
761
768
  registerDatabaseAdapter(adapter: IDatabaseAdapter): void;
762
- getDatabaseAdapters(): IDatabaseAdapter[];
763
769
  getDatabaseAdapter(): IDatabaseAdapter | null;
764
770
  setSetting(key: string, value: string | boolean | null | any, secret: boolean): void;
765
771
  getSetting(key: string): string | boolean | null | any;
@@ -955,7 +961,7 @@ interface TaskWorker {
955
961
  name: string;
956
962
  execute: (runtime: IAgentRuntime, options: {
957
963
  [key: string]: unknown;
958
- }) => Promise<void>;
964
+ }, task: Task) => Promise<void>;
959
965
  validate?: (runtime: IAgentRuntime, message: Memory, state: State) => Promise<boolean>;
960
966
  }
961
967
  interface Task {
@@ -1011,6 +1017,13 @@ interface OnboardingConfig {
1011
1017
  * @param count - The number of examples to generate.
1012
1018
  * @returns A string containing formatted examples of conversations.
1013
1019
  */
1020
+ /**
1021
+ * Compose a specified number of random action examples from the given actionsData.
1022
+ *
1023
+ * @param {Action[]} actionsData - The list of actions to generate examples from.
1024
+ * @param {number} count - The number of examples to compose.
1025
+ * @returns {string} The formatted action examples.
1026
+ */
1014
1027
  declare const composeActionExamples: (actionsData: Action[], count: number) => string;
1015
1028
  /**
1016
1029
  * Formats the names of the provided actions into a comma-separated string.
@@ -1029,11 +1042,23 @@ declare function formatActions(actions: Action[]): string;
1029
1042
  * An abstract class representing a database adapter for managing various entities
1030
1043
  * like entities, memories, entities, goals, and rooms.
1031
1044
  */
1045
+ /**
1046
+ * Database adapter class to be extended by individual database adapters.
1047
+ *
1048
+ * @template DB - The type of the database instance.
1049
+ * @abstract
1050
+ * @implements {IDatabaseAdapter}
1051
+ */
1032
1052
  declare abstract class DatabaseAdapter<DB = unknown> implements IDatabaseAdapter {
1033
1053
  /**
1034
1054
  * The database instance.
1035
1055
  */
1036
1056
  db: DB;
1057
+ /**
1058
+ * Initialize the database adapter.
1059
+ * @returns A Promise that resolves when initialization is complete.
1060
+ */
1061
+ abstract init(): Promise<void>;
1037
1062
  /**
1038
1063
  * Optional close method for the database adapter.
1039
1064
  * @returns A Promise that resolves when closing is complete.
@@ -1476,16 +1501,42 @@ declare abstract class DatabaseAdapter<DB = unknown> implements IDatabaseAdapter
1476
1501
  abstract deleteTask(id: UUID): Promise<void>;
1477
1502
  }
1478
1503
 
1504
+ /**
1505
+ * Finds an entity by name in the given runtime environment.
1506
+ *
1507
+ * @param {IAgentRuntime} runtime - The agent runtime environment.
1508
+ * @param {Memory} message - The memory message containing relevant information.
1509
+ * @param {State} state - The current state of the system.
1510
+ * @returns {Promise<Entity | null>} A promise that resolves to the found entity or null if not found.
1511
+ */
1479
1512
  declare function findEntityByName(runtime: IAgentRuntime, message: Memory, state: State): Promise<Entity | null>;
1513
+ /**
1514
+ * Function to create a unique UUID based on the runtime and base user ID.
1515
+ *
1516
+ * @param {RuntimeContext} runtime - The runtime context object.
1517
+ * @param {UUID|string} baseUserId - The base user ID to use in generating the UUID.
1518
+ * @returns {UUID} - The unique UUID generated based on the runtime and base user ID.
1519
+ */
1480
1520
  declare const createUniqueUuid: (runtime: any, baseUserId: UUID | string) => UUID;
1481
1521
  /**
1482
1522
  * Get details for a list of entities.
1483
1523
  */
1524
+ /**
1525
+ * Retrieves entity details for a specific room from the database.
1526
+ *
1527
+ * @param {Object} params - The input parameters
1528
+ * @param {IAgentRuntime} params.runtime - The Agent Runtime instance
1529
+ * @param {UUID} params.roomId - The ID of the room to retrieve entity details for
1530
+ * @returns {Promise<Array>} - A promise that resolves to an array of unique entity details
1531
+ */
1484
1532
  declare function getEntityDetails({ runtime, roomId, }: {
1485
1533
  runtime: IAgentRuntime;
1486
1534
  roomId: UUID;
1487
1535
  }): Promise<any[]>;
1488
1536
 
1537
+ /**
1538
+ * Interface for settings object with key-value pairs.
1539
+ */
1489
1540
  interface Settings {
1490
1541
  [key: string]: string | undefined;
1491
1542
  }
@@ -1887,6 +1938,12 @@ declare function validateCharacterConfig(json: unknown): CharacterConfig;
1887
1938
 
1888
1939
  declare const dynamicImport: (specifier: string) => Promise<any>;
1889
1940
  declare const registerDynamicImport: (specifier: string, module: any) => void;
1941
+ /**
1942
+ * Handles importing of plugins asynchronously.
1943
+ *
1944
+ * @param {string[]} plugins - An array of strings representing the plugins to import.
1945
+ * @returns {Promise<Function[]>} - A Promise that resolves to an array of imported plugins functions.
1946
+ */
1890
1947
  declare function handlePluginImporting(plugins: string[]): Promise<any[]>;
1891
1948
 
1892
1949
  declare const logger: pino.Logger<string, boolean>;
@@ -1895,6 +1952,9 @@ declare const elizaLogger: pino.Logger<string, boolean>;
1895
1952
  /**
1896
1953
  * Manage memories in the database.
1897
1954
  */
1955
+ /**
1956
+ * The AgentRuntime instance associated with this manager.
1957
+ */
1898
1958
  declare class MemoryManager implements IMemoryManager {
1899
1959
  /**
1900
1960
  * The AgentRuntime instance associated with this manager.
@@ -2031,6 +2091,14 @@ declare class MemoryManager implements IMemoryManager {
2031
2091
  * };
2032
2092
  * const contextSimple = composePrompt({ state, template });
2033
2093
  */
2094
+ /**
2095
+ * Function to compose a prompt using a provided template and state.
2096
+ *
2097
+ * @param {Object} options - Object containing state and template information.
2098
+ * @param {State} options.state - The state object containing values to fill the template.
2099
+ * @param {TemplateType} options.template - The template to be used for composing the prompt.
2100
+ * @returns {string} The composed prompt output.
2101
+ */
2034
2102
  declare const composePrompt: ({ state, template, }: {
2035
2103
  state: State;
2036
2104
  template: TemplateType;
@@ -2093,7 +2161,7 @@ declare const formatMessages: ({ messages, entities, }: {
2093
2161
  entities: Entity[];
2094
2162
  }) => string;
2095
2163
  declare const formatTimestamp: (messageDate: number) => string;
2096
- declare const shouldRespondTemplate = "# Task: Decide on behalf of {{agentName}} whether they should respond to the message, ignore it or stop the conversation.\n{{providers}}\n# Instructions: Decide if {{agentName}} should respond to or interact with the conversation.\nIf the message is directed at or relevant to {{agentName}}, respond with RESPOND action.\nIf a user asks {{agentName}} to be quiet, respond with STOP action.\nIf {{agentName}} should ignore the message, respond with IGNORE action.\nIf responding with the RESPOND action, include a list of optional providers that could be relevant to the response.\nResponse format should be formatted in a valid JSON block like this:\n```json\n{\n \"name\": \"{{agentName}}\",\n \"action\": \"RESPOND\" | \"IGNORE\" | \"STOP\",\n \"providers\": [\"<string>\", \"<string>\", ...]\n}\n```\nYour response should include the valid JSON block and nothing else.";
2164
+ declare const shouldRespondTemplate = "# Task: Decide on behalf of {{agentName}} whether they should respond to the message, ignore it or stop the conversation.\n{{providers}}\n# Instructions: Decide if {{agentName}} should respond to or interact with the conversation.\nIf the message is directed at or relevant to {{agentName}}, respond with RESPOND action.\nIf a user asks {{agentName}} to be quiet, respond with STOP action.\nIf {{agentName}} should ignore the message, respond with IGNORE action.\nIf responding with the RESPOND action, include a list of optional providers that could be relevant to the response.\nResponse format should be formatted in a valid JSON block like this:\n```json\n{\n \"name\": \"{{agentName}}\",\n\t\"reasoning\": \"<string>\",\n \"action\": \"RESPOND\" | \"IGNORE\" | \"STOP\",\n \"providers\": [\"<string>\", \"<string>\", ...]\n}\n```\nYour response should include the valid JSON block and nothing else.";
2097
2165
  declare const messageHandlerTemplate = "# Task: Generate dialog and actions for the character {{agentName}}.\n{{providers}}\n# Instructions: Write a thought and plan for {{agentName}} and decide what actions to take. Also include the providers that {{agentName}} will use to have the right context for responding and acting, if any.\nFirst, think about what you want to do next and plan your actions. Then, write the next message and include the actions you plan to take.\n\"thought\" should be a short description of what the agent is thinking about and planning.\n\"actions\" should be an array of the actions {{agentName}} plans to take based on the thought (if none, use IGNORE, if simply responding with text, use REPLY)\n\"providers\" should be an optional array of the providers that {{agentName}} will use to have the right context for responding and acting\n\"evaluators\" should be an optional array of the evaluators that {{agentName}} will use to evaluate the conversation after responding\n\"plan\" should be explanation of the message you plan to send, the actions you plan to take, and the data providers you plan to use.\nThese are the available valid actions: {{actionNames}}\n\nResponse format should be formatted in a valid JSON block like this:\n```json\n{\n \"thought\": \"<string>\",\n \"plan\": \"<string>\",\n \"actions\": [\"<string>\", \"<string>\", ...],\n \"providers\": [\"<string>\", \"<string>\", ...]\n}\n```\n\nYour response should include the valid JSON block and nothing else.";
2098
2166
  declare const booleanFooter = "Respond with only a YES or a NO.";
2099
2167
  /**
@@ -2180,6 +2248,9 @@ declare function splitChunks(content: string, chunkSize?: number, bleed?: number
2180
2248
  */
2181
2249
  declare function trimTokens(prompt: string, maxTokens: number, runtime: IAgentRuntime): Promise<any>;
2182
2250
 
2251
+ /**
2252
+ * Represents the state of server ownership, including a mapping of server IDs to their respective World objects.
2253
+ */
2183
2254
  interface ServerOwnershipState {
2184
2255
  servers: {
2185
2256
  [serverId: string]: World;
@@ -2188,6 +2259,14 @@ interface ServerOwnershipState {
2188
2259
  /**
2189
2260
  * Gets a user's role from world metadata
2190
2261
  */
2262
+ /**
2263
+ * Retrieve the server role of a specified user entity within a given server.
2264
+ *
2265
+ * @param {IAgentRuntime} runtime - The runtime object containing necessary configurations and services.
2266
+ * @param {string} entityId - The unique identifier of the user entity.
2267
+ * @param {string} serverId - The unique identifier of the server.
2268
+ * @returns {Promise<Role>} The role of the user entity within the server, resolved as a Promise.
2269
+ */
2191
2270
  declare function getUserServerRole(runtime: IAgentRuntime, entityId: string, serverId: string): Promise<Role>;
2192
2271
  /**
2193
2272
  * Finds a server where the given user is the owner
@@ -2198,6 +2277,19 @@ declare function findWorldForOwner(runtime: IAgentRuntime, entityId: string): Pr
2198
2277
  * Represents the runtime environment for an agent, handling message processing,
2199
2278
  * action registration, and interaction with external services like OpenAI and Supabase.
2200
2279
  */
2280
+ /**
2281
+ * Represents the runtime environment for an agent.
2282
+ * @class
2283
+ * @implements { IAgentRuntime }
2284
+ * @property { number } #conversationLength - The maximum length of a conversation.
2285
+ * @property { UUID } agentId - The unique identifier for the agent.
2286
+ * @property { Character } character - The character associated with the agent.
2287
+ * @property { IDatabaseAdapter } databaseAdapter - The adapter for interacting with the database.
2288
+ * @property {Action[]} actions - The list of actions available to the agent.
2289
+ * @property {Evaluator[]} evaluators - The list of evaluators for decision making.
2290
+ * @property {Provider[]} providers - The list of providers for external services.
2291
+ * @property {Plugin[]} plugins - The list of plugins to extend functionality.
2292
+ */
2201
2293
  declare class AgentRuntime implements IAgentRuntime {
2202
2294
  #private;
2203
2295
  readonly agentId: UUID;
@@ -2219,7 +2311,7 @@ declare class AgentRuntime implements IAgentRuntime {
2219
2311
  }>;
2220
2312
  readonly fetch: typeof fetch;
2221
2313
  services: Map<ServiceType, Service>;
2222
- adapters: IDatabaseAdapter[];
2314
+ adapter: IDatabaseAdapter;
2223
2315
  private readonly knowledgeRoot;
2224
2316
  models: Map<string, ((params: any) => Promise<any>)[]>;
2225
2317
  routes: Route[];
@@ -2231,7 +2323,7 @@ declare class AgentRuntime implements IAgentRuntime {
2231
2323
  plugins?: Plugin[];
2232
2324
  fetch?: typeof fetch;
2233
2325
  databaseAdapter?: IDatabaseAdapter;
2234
- adapters?: IDatabaseAdapter[];
2326
+ adapter?: IDatabaseAdapter;
2235
2327
  events?: {
2236
2328
  [key: string]: ((params: any) => void)[];
2237
2329
  };
@@ -2262,7 +2354,6 @@ declare class AgentRuntime implements IAgentRuntime {
2262
2354
  */
2263
2355
  getConversationLength(): number;
2264
2356
  registerDatabaseAdapter(adapter: IDatabaseAdapter): void;
2265
- getDatabaseAdapters(): IDatabaseAdapter[];
2266
2357
  getDatabaseAdapter(): IDatabaseAdapter;
2267
2358
  /**
2268
2359
  * Register a provider for the agent to use.
@@ -2362,7 +2453,20 @@ declare function getWorldSettings(runtime: IAgentRuntime, serverId: string): Pro
2362
2453
  declare function initializeOnboarding(runtime: IAgentRuntime, world: World, config: OnboardingConfig): Promise<WorldSettings | null>;
2363
2454
 
2364
2455
  declare const uuidSchema: z.ZodType<UUID>;
2456
+ /**
2457
+ * Validates a UUID value.
2458
+ *
2459
+ * @param {unknown} value - The value to validate.
2460
+ * @returns {UUID | null} Returns the validated UUID value or null if validation fails.
2461
+ */
2365
2462
  declare function validateUuid(value: unknown): UUID | null;
2463
+ /**
2464
+ * Converts a string or number to a UUID.
2465
+ *
2466
+ * @param {string | number} target - The string or number to convert to a UUID.
2467
+ * @returns {UUID} The UUID generated from the input target.
2468
+ * @throws {TypeError} Throws an error if the input target is not a string.
2469
+ */
2366
2470
  declare function stringToUuid(target: string | number): UUID;
2367
2471
 
2368
2472
  export { type Action, type ActionExample, type Agent, AgentRuntime, type BaseMetadata, CacheKeyPrefix, type CacheOptions, ChannelType, type Character, type CharacterConfig, CharacterSchema, type ChunkRow, type Component, type Content, type ConversationExample, type CustomMetadata, DatabaseAdapter, type DeriveKeyAttestationData, type DescriptionMetadata, type DetokenizeTextParams, type DirectoryItem, type DocumentMetadata, type Entity, type EvaluationExample, type Evaluator, type FragmentMetadata, type GenerateTextParams, type Goal, GoalStatus, type Handler, type HandlerCallback, type IAgentRuntime, type IBrowserService, type IDatabaseAdapter, type IFileService, type IMemoryManager, type IPdfService, type ITeeLogService, type IVideoService, type KnowledgeItem, KnowledgeScope, type Media, type Memory, MemoryManager, type MemoryMetadata, MemoryType, type MemoryTypeAlias, type MessageExample, MessageExampleSchema, type MessageMetadata, type ModelConfiguration, type ModelType, ModelTypes, type Objective, type OnboardingConfig, type Participant, type Plugin, PluginSchema, type Project, type ProjectAgent, type Provider, type ProviderResult, type Relationship, type RemoteAttestationMessage, type RemoteAttestationQuote, Role, type Room, type Route, type ServerOwnershipState, Service, type ServiceType, ServiceTypes, type Setting, type SgxAttestation, type State, TEEMode, type Task, type TaskWorker, type TeeAgent, type TeeLog, TeeLogDAO, type TeeLogQuery, type TeePageQuery, type TeePluginConfig, TeeType, type TeeVendorConfig, type TemplateType, type TestCase, type TestSuite, type TokenizeTextParams, type UUID, type Validator, type World, type WorldSettings, addHeader, booleanFooter, cleanJsonResponse, composeActionExamples, composePrompt, composeRandomUser, configureSettings, createUniqueUuid, dynamicImport, elizaLogger, extractAttributes, findEntityByName, findNearestEnvFile, findWorldForOwner, formatActionNames, formatActions, formatMessages, formatPosts, formatTimestamp, getEntityDetails, getEnvVariable, getUserServerRole, getWorldSettings, handlePluginImporting, hasEnvVariable, initializeOnboarding, loadEnvConfig, logger, messageHandlerTemplate, normalizeJsonString, parseActionResponseFromText, parseBooleanFromText, parseJSONObjectFromText, parseJsonArrayFromText, postActionResponseFooter, registerDynamicImport, settings, shouldRespondTemplate, splitChunks, stringArrayFooter, stringToUuid, trimTokens, truncateToCompleteSentence, updateWorldSettings, uuidSchema, validateCharacterConfig, validateUuid };