{"version":3,"file":"AgentContext.mjs","names":[],"sources":["../../../src/agent/context/AgentContext.ts"],"sourcesContent":["import { InjectionSymbols } from '../../constants'\nimport type { DependencyManager, InjectionToken } from '../../plugins'\nimport { AgentConfig } from '../AgentConfig'\nimport type { AgentContextProvider } from './AgentContextProvider'\n\nexport class AgentContext {\n  /**\n   * Dependency manager holds all dependencies for the current context. Possibly a child of a parent dependency manager,\n   * in which case all singleton dependencies from the parent context are also available to this context.\n   */\n  public readonly dependencyManager: DependencyManager\n\n  /**\n   * An identifier that allows to correlate this context across sessions. This identifier is created by the `AgentContextProvider`\n   * and should only be meaningful to the `AgentContextProvider`. The `contextCorrelationId` MUST uniquely identity the context and\n   * should be enough to start a new session.\n   *\n   * An example of the `contextCorrelationId` is for example the id of the `TenantRecord` that is associated with this context when using the tenant module.\n   * The `TenantAgentContextProvider` will set the `contextCorrelationId` to the `TenantRecord` id when creating the context, and will be able to create a context\n   * for a specific tenant using the `contextCorrelationId`.\n   */\n  public readonly contextCorrelationId: string\n\n  public readonly isRootAgentContext: boolean\n\n  public constructor({\n    dependencyManager,\n    contextCorrelationId,\n    isRootAgentContext = false,\n  }: {\n    dependencyManager: DependencyManager\n    contextCorrelationId: string\n    isRootAgentContext?: boolean\n  }) {\n    this.dependencyManager = dependencyManager\n    this.contextCorrelationId = contextCorrelationId\n    this.isRootAgentContext = isRootAgentContext\n  }\n\n  /**\n   * Convenience method to access the agent config for the current context.\n   */\n  public get config() {\n    return this.dependencyManager.resolve(AgentConfig)\n  }\n\n  /**\n   * End session the current agent context\n   */\n  public async endSession() {\n    // TODO: we need to create a custom agent context per sesion\n    // and then track if it has already been ended, because it's quite\n    // easy to mess up the session count at the moment\n    const agentContextProvider = this.dependencyManager.resolve<AgentContextProvider>(\n      InjectionSymbols.AgentContextProvider\n    )\n\n    await agentContextProvider.endSessionForAgentContext(this)\n  }\n\n  public toJSON() {\n    return {\n      contextCorrelationId: this.contextCorrelationId,\n    }\n  }\n\n  /**\n   * Resolve a dependency\n   */\n  public resolve<T>(token: InjectionToken<T>): T {\n    return this.dependencyManager.resolve(token)\n  }\n}\n"],"mappings":";;;;;;AAKA,IAAa,eAAb,MAA0B;CAoBxB,AAAO,YAAY,EACjB,mBACA,sBACA,qBAAqB,SAKpB;AACD,OAAK,oBAAoB;AACzB,OAAK,uBAAuB;AAC5B,OAAK,qBAAqB;;;;;CAM5B,IAAW,SAAS;AAClB,SAAO,KAAK,kBAAkB,QAAQ,YAAY;;;;;CAMpD,MAAa,aAAa;AAQxB,QAJ6B,KAAK,kBAAkB,QAClD,iBAAiB,qBAClB,CAE0B,0BAA0B,KAAK;;CAG5D,AAAO,SAAS;AACd,SAAO,EACL,sBAAsB,KAAK,sBAC5B;;;;;CAMH,AAAO,QAAW,OAA6B;AAC7C,SAAO,KAAK,kBAAkB,QAAQ,MAAM"}