@egain/ai-agent-sdk API Reference - v0.1.1 / Transcript
Class: Transcript
Transcript storage class for managing conversation history.
The Transcript class provides a complete record of all messages exchanged during a conversation. It supports filtering, JSON export, and real-time updates.
Example
const transcript = new Transcript();
// Add a message
transcript.add(message, 'sent', sessionId, agentId);
// Get all entries
const entries = transcript.getEntries();
// Get as JSON for storage
const json = transcript.getEntriesAsJSON();
// Get entry count
console.log(`${transcript.size()} messages`);
// Clear all entries
transcript.clear();Example
const transcript = new Transcript({
enabled: true,
excludeRoles: ['heartbeat'], // Don't record heartbeats
});Example
// Get only agent responses
const agentResponses = transcript.getEntries({
direction: 'received',
persona: 'agent'
});
// Get messages from the last 5 minutes
const recentMessages = transcript.getEntries({
fromTimestamp: Date.now() - 300000
});Table of contents
Constructors
Methods
Constructors
constructor
• new Transcript(config?): Transcript
Create a new Transcript instance
Parameters
| Name | Type | Description |
|---|---|---|
config | TranscriptConfig | Optional configuration for filtering |
Returns
Defined in
core/message/Transcript.ts:279
Methods
add
▸ add(message, direction, sessionId?, agentId?): void
Add a message to the transcript.
Messages are automatically filtered based on configuration. If the transcript is disabled or the message matches an exclude filter, it will not be recorded.
Parameters
| Name | Type | Description |
|---|---|---|
message | Message | The message to add |
direction | "sent" | "received" | Whether the message was 'sent' or 'received' |
sessionId? | string | number | Optional session ID for context |
agentId? | string | number | Optional agent ID for context |
Returns
void
Example
transcript.add(
new Message('customer', 'human', 'Hello!'),
'sent',
'session-123',
'agent-456'
);Defined in
core/message/Transcript.ts:310
getEntries
▸ getEntries(options?): TranscriptEntry[]
Get transcript entries, optionally filtered.
Parameters
| Name | Type | Description |
|---|---|---|
options? | TranscriptOptions | Optional filtering options |
Returns
Array of transcript entries matching the filter
Example
// Get all entries
const all = transcript.getEntries();
// Get only sent messages
const sent = transcript.getEntries({ direction: 'sent' });
// Get messages from last hour
const recent = transcript.getEntries({
fromTimestamp: Date.now() - 3600000
});Defined in
core/message/Transcript.ts:356
getEntriesAsJSON
▸ getEntriesAsJSON(options?): any[]
Get transcript entries as plain JSON-serializable objects.
Useful for storing transcripts in databases, sending to APIs, or displaying in UI components.
Parameters
| Name | Type | Description |
|---|---|---|
options? | TranscriptOptions | Optional filtering options |
Returns
any[]
Array of plain objects representing transcript entries
Example
const json = transcript.getEntriesAsJSON();
// Each entry includes:
// {
// messageId, persona, role, content, messageData,
// timestamp, from, to, agentId, sessionId,
// direction, entryTimestamp
// }
// Save to database
await db.saveTranscript(json);Defined in
core/message/Transcript.ts:411
size
▸ size(): number
Get the number of entries in the transcript.
Returns
number
Number of recorded messages
Defined in
core/message/Transcript.ts:433
clear
▸ clear(): void
Clear all transcript entries.
This removes all recorded messages. Use with caution as this action cannot be undone.
Returns
void
Defined in
core/message/Transcript.ts:443
updateConfig
▸ updateConfig(config): void
Update transcript configuration at runtime.
Parameters
| Name | Type | Description |
|---|---|---|
config | Partial<TranscriptConfig> | New configuration options (partial update) |
Returns
void
Example
// Disable transcript temporarily
transcript.updateConfig({ enabled: false });
// Re-enable with new exclusions
transcript.updateConfig({
enabled: true,
excludeRoles: ['heartbeat', 'token']
});