@elizaos/core 1.0.0 → 1.0.2

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.
@@ -385,6 +385,12 @@ export declare abstract class DatabaseAdapter<DB = unknown> implements IDatabase
385
385
  * @returns A Promise that resolves to a boolean indicating success or failure of the deletion.
386
386
  */
387
387
  abstract deleteAgent(agentId: UUID): Promise<boolean>;
388
+ /**
389
+ * Ensures an agent exists in the database.
390
+ * @param agent The agent object to ensure exists.
391
+ * @returns A Promise that resolves when the agent has been ensured to exist.
392
+ */
393
+ abstract ensureAgentExists(agent: Partial<Agent>): Promise<Agent>;
388
394
  /**
389
395
  * Ensures an embedding dimension exists in the database.
390
396
  * @param dimension The dimension to ensure exists.
package/dist/index.js CHANGED
@@ -8251,7 +8251,9 @@ var AgentRuntime = class {
8251
8251
  try {
8252
8252
  await this.adapter.init();
8253
8253
  span.addEvent("adapter_initialized");
8254
- const existingAgent = await this.ensureAgentExists(this.character);
8254
+ const existingAgent = await this.adapter.ensureAgentExists(
8255
+ this.character
8256
+ );
8255
8257
  span.addEvent("agent_exists_verified");
8256
8258
  if (!existingAgent) {
8257
8259
  const errorMsg = `Agent ${this.character.name} does not exist in database after ensureAgentExists call`;
@@ -9299,35 +9301,7 @@ var AgentRuntime = class {
9299
9301
  return await this.adapter.deleteAgent(agentId);
9300
9302
  }
9301
9303
  async ensureAgentExists(agent) {
9302
- if (!agent.name) {
9303
- throw new Error("Agent name is required");
9304
- }
9305
- const agents = await this.adapter.getAgents();
9306
- const existingAgentId = agents.find((a) => a.name === agent.name)?.id;
9307
- if (existingAgentId) {
9308
- const updatedAgent = {
9309
- ...agent,
9310
- id: existingAgentId,
9311
- updatedAt: Date.now()
9312
- };
9313
- await this.adapter.updateAgent(existingAgentId, updatedAgent);
9314
- const existingAgent = await this.adapter.getAgent(existingAgentId);
9315
- if (!existingAgent) {
9316
- throw new Error(`Failed to retrieve agent after update: ${existingAgentId}`);
9317
- }
9318
- this.logger.debug(`Updated existing agent ${agent.name} on restart`);
9319
- return existingAgent;
9320
- }
9321
- const newAgent = {
9322
- ...agent,
9323
- id: stringToUuid(agent.name)
9324
- };
9325
- const created = await this.adapter.createAgent(newAgent);
9326
- if (!created) {
9327
- throw new Error(`Failed to create agent: ${agent.name}`);
9328
- }
9329
- this.logger.debug(`Created new agent ${agent.name}`);
9330
- return newAgent;
9304
+ return await this.adapter.ensureAgentExists(agent);
9331
9305
  }
9332
9306
  async getEntityById(entityId) {
9333
9307
  const entities = await this.adapter.getEntityByIds([entityId]);
package/dist/types.d.ts CHANGED
@@ -698,6 +698,7 @@ export interface IDatabaseAdapter {
698
698
  createAgent(agent: Partial<Agent>): Promise<boolean>;
699
699
  updateAgent(agentId: UUID, agent: Partial<Agent>): Promise<boolean>;
700
700
  deleteAgent(agentId: UUID): Promise<boolean>;
701
+ ensureAgentExists(agent: Partial<Agent>): Promise<Agent>;
701
702
  ensureEmbeddingDimension(dimension: number): Promise<void>;
702
703
  /** Get entity by IDs */
703
704
  getEntityByIds(entityIds: UUID[]): Promise<Entity[] | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -88,5 +88,5 @@
88
88
  "publishConfig": {
89
89
  "access": "public"
90
90
  },
91
- "gitHead": "b315ad294cec3ae8a0f5e9f2fa792523a67cbfe7"
91
+ "gitHead": "d72a82d998aab8202a1e8ae8e239c56ac7345e8a"
92
92
  }