default
chainalign-backend / services/AIManager / default
Class: default
Defined in: services/AIManager.js:27
Manages AI-driven functionalities for the ChainAlign application. This class provides methods for processing user input, generating dynamic content, and integrating with various AI and data services.
Constructors
Constructor
new default(
sessionId?):AIManager
Defined in: services/AIManager.js:32
Creates an instance of AIManager.
Parameters
sessionId?
string = "default-sop-session"
The session ID for conversation history persistence (e.g., with Zep).
Returns
AIManager
Properties
dataSchema
dataSchema:
object
Defined in: services/AIManager.js:33
dimensions
dimensions:
object[]
measures
measures:
object[]
sessionId
sessionId:
string
Defined in: services/AIManager.js:35
Methods
addMessageToZep()
addMessageToZep(
content,role):Promise<void>
Defined in: services/AIManager.js:246
Adds a message to the Zep session.
Parameters
content
string
The message content.
role
string
The role of the sender (e.g., "user", "ai").
Returns
Promise<void>
constructAugmentedPrompt()
constructAugmentedPrompt(
transcript,relevantDocuments,insightContext):string
Defined in: services/AIManager.js:266
Constructs the detailed, context-aware prompt for the Gemini LLM.
Parameters
transcript
string
The user's current request.
relevantDocuments
string[]
An array of relevant document snippets from the general vector DB.
insightContext
string
Formatted string of relevant S&OP insights from the knowledge base.
Returns
string
- The full prompt to be sent to the LLM.
initZepSession()
initZepSession():
Promise<void>
Defined in: services/AIManager.js:168
Initializes a Zep session for conversation history persistence. This method is called fire-and-forget during AIManager instantiation. It handles cases where the session already exists gracefully.
Returns
Promise<void>
A promise that resolves when the Zep session is initialized or confirmed to exist.
processTranscript()
processTranscript(
transcript,tenantId,userId):Promise<any>
Defined in: services/AIManager.js:197
Processes a transcribed utterance to generate a structured chart query.
Parameters
transcript
string
The user's transcribed speech.
tenantId
string
The ID of the tenant.
userId
string
The ID of the user.
Returns
Promise<any>
- A structured JSON object for the charting engine.
enrichNewsArticle()
staticenrichNewsArticle(rawArticle,tenantId,userId):Promise<EnrichedNewsArticle>
Defined in: services/AIManager.js:534
Enriches a raw news article with AI-derived insights using Google Gemini. It extracts country information, fetches relevant World Bank data, and constructs a prompt for Gemini to analyze the article and provide structured S&OP impact assessments.
Parameters
rawArticle
any
The raw article object from NewsAPI.
tenantId
string
The ID of the tenant for auditing.
userId
string
The ID of the user for auditing.
Returns
Promise<EnrichedNewsArticle>
- The enriched article object.
generateAlertPage()
staticgenerateAlertPage(tenantId,userId):Promise<any>
Defined in: services/AIManager.js:61
Generates a dynamic UI page JSON based on a detected alert.
It fetches alert data from a backend endpoint and uses Gemini to construct a structured JSON
object that describes the layout and components of an alert page.
The backendApiToken is retrieved from GCP Secret Manager (or local .env for development)
and is used for internal service-to-service authentication as per docs/website/docs/developer/security-guidelines.md.
Parameters
tenantId
string
The ID of the tenant.
userId
string
The ID of the user.
Returns
Promise<any>
A JSON object representing the dynamic page layout, or null if no alert is detected or an error occurs.
generateDynamicPageFromContext()
staticgenerateDynamicPageFromContext(unstructuredContext,structuredContext,tenantId,userId):Promise<any>
Defined in: services/AIManager.js:363
Generates a dynamic UI page JSON based on unstructured and structured context. This method first checks for active alerts and, if none, constructs a prompt for Gemini to generate a structured JSON object for dynamic UI rendering, typically for insights display.
Parameters
unstructuredContext
any
Unstructured context from sources like uploaded documents.
structuredContext
any
Structured context from databases.
tenantId
string
The ID of the tenant.
userId
string
The ID of the user.
Returns
Promise<any>
A JSON object representing the dynamic page layout.
Throws
If the LLM output does not conform to the expected page layout schema.
getTranscriptions()
staticgetTranscriptions():Promise<any[]>
Defined in: services/AIManager.js:489
Retrieves all stored transcriptions from Firestore, ordered by timestamp.
Returns
Promise<any[]>
A promise that resolves with an array of transcription objects.
Throws
If an error occurs during retrieval.
handleNLPRequest()
statichandleNLPRequest(text):Promise<any>
Defined in: services/AIManager.js:506
Handles a Natural Language Processing (NLP) request by processing text and generating a structured query.
It uses processTranscript internally and optionally stores the result in Firestore.
Parameters
text
string
The input text for NLP processing.
Returns
Promise<any>
A promise that resolves with the structured query object.
Throws
If an error occurs during NLP processing.
handleTranscriptionRequest()
statichandleTranscriptionRequest(audioBytes,encoding,sampleRateHertz,languageCode):Promise<string>
Defined in: services/AIManager.js:469
Handles a transcription request by transcribing audio and storing it in Firestore.
Parameters
audioBytes
Buffer<ArrayBufferLike>
The audio data in bytes.
encoding
string
The audio encoding (e.g., 'LINEAR16').
sampleRateHertz
number
The sample rate of the audio.
languageCode
string
The language code (e.g., 'en-US').
Returns
Promise<string>
A promise that resolves with the transcribed text.
Throws
If an error occurs during transcription or storage.