UNPKG

@hotmeshio/hotmesh

Version:

Permanent-Memory Workflows & AI Agents

34 lines (33 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.entity = void 0; const common_1 = require("./common"); /** * Returns an entity session handle for interacting with the workflow's JSONB entity storage. * @returns {Promise<Entity>} An entity session for workflow data. * * @example * ```typescript * const entity = await workflow.entity(); * await entity.set({ user: { id: 123 } }); * await entity.merge({ user: { name: "John" } }); * const user = await entity.get("user"); * ``` */ async function entity() { const store = common_1.asyncLocalStorage.getStore(); const workflowId = store.get('workflowId'); const workflowDimension = store.get('workflowDimension') ?? ''; const workflowTopic = store.get('workflowTopic'); const connection = store.get('connection'); const namespace = store.get('namespace'); const COUNTER = store.get('counter'); const execIndex = COUNTER.counter = COUNTER.counter + 1; const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, { connection, namespace, }); const entitySessionId = `-entity${workflowDimension}-${execIndex}`; return new common_1.Entity(workflowId, hotMeshClient, entitySessionId); } exports.entity = entity;