Skip to main content

Conversation Domain API

These explicit domain records are separate from the runtime executable transcript. Runtime applications read canonical history through client.messages; controlled manual runtime changes use guarded runtimeTranscript contracts with locks/expected revisions. Domain shares/snapshots still require current authority and retention checks.

Usage boundary​

Access the namespace on an explicitly configured root Cortex client. Host JWT and deployment-operator transports are distinct; validate current resource scope and do not infer authority from AuthContext metadata. See administrative operations.

Records, history and pagination​

create requires the selected memory space, conversation type and participants. conversationId may be supplied for an explicit import; otherwise it is generated. user-agent and agent-agent are supported types. addMessage accepts user/agent/system role and nonempty content, with an optional message ID, participant and metadata. Use these explicit operations for independent records. Runtime turns already write their one canonical transcript.

get returns null when absent; missing resources for mutations/history can raise CONVERSATION_NOT_FOUND. Tenant disagreement raises TENANT_SCOPE_MISMATCH. Bulk domain operations can stop with DOMAIN_SCOPE_AMBIGUOUS or DOMAIN_SELECTION_CHANGED; inspect partial outcomes rather than restarting the selection.

getHistory returns { messages, total, hasMore, conversationId }. Supply limit, offset, chronological sortOrder, role filters and optional since/until timestamps; since must not exceed until. list returns { conversations, total, limit, offset, hasMore }, with filters for owner, space, type, participant, metadata, time and message-count range. includeMessages controls expanded messages. Offset pages are rolling reads; concurrent edits can change page membership, so they are not an immutable export snapshot.

import type { Cortex } from '@cortexmemory/sdk';

export async function readHistoryPage(cortex: Cortex, conversationId: string,
tenantId: string, offset = 0) {
const page = await cortex.conversations.getHistory(conversationId, {
tenantId, limit: 50, offset, sortOrder: 'asc', roles: ['user', 'agent'],
});
return { messages: page.messages, total: page.total,
nextOffset: page.hasMore ? offset + page.messages.length : undefined };
}

Sharing and snapshots are explicit record features. A share's resource identity, permission/expiry and current revocation state control access; possession of a conversation ID is insufficient for protected runtime reads. Redaction and included-content options select what a snapshot retains. Snapshot/share APIs do not publish private asset storage URLs. See conversation history.

Parameter and result contracts​

These are reference definitions for the explicit server APIs. Optional fields use ?; timestamps are milliseconds since epoch unless an operation accepts a Date. Resource identifiers and participant metadata do not grant runtime authority.

CreateConversationInput​

export interface CreateConversationInput {
conversationId?: string;
memorySpaceId: string;
tenantId?: string;
participantId?: string;
type: ConversationType;
participants: {
userId?: string;
agentId?: string;
userIds?: string[];
participantId?: string;
memorySpaceIds?: string[];
};
metadata?: Record<string, unknown>;
visibility?: ConversationVisibility;
collaborativeSettings?: CollaborativeSettings;
}
FieldMeaning and defaults
visibilityVisibility for shareable chats. Defaults to 'private'.
collaborativeSettingsSettings for collaborative conversations (Phase 4)

AddMessageInput​

export interface AddMessageInput {
conversationId: string;
message: {
id?: string;
role: "user" | "agent" | "system";
content: string;
participantId?: string;
metadata?: Record<string, unknown>;
};
}

Message​

export interface Message {
id: string;
role: "user" | "agent" | "system";
content: string;
timestamp: number;
participantId?: string;
metadata?: Record<string, unknown>;
approvalStatus?: MessageApprovalStatus;
approvedBy?: string;
approvedAt?: number;
}
FieldMeaning and defaults
approvalStatusApproval status for collaborative conversations (Phase 4)
approvedByUserId who approved/rejected the message
approvedAtTimestamp of approval/rejection

Conversation​

export interface Conversation extends GraphCaptureMetadata {
_id: string;
conversationId: string;
memorySpaceId: string;
tenantId?: string;
participantId?: string;
type: ConversationType;
participants: {
userId?: string;
agentId?: string;
userIds?: string[];
participantId?: string;
memorySpaceIds?: string[];
};
messages: Message[];
messageCount: number;
metadata?: Record<string, unknown>;
createdAt: number;
updatedAt: number;
visibility?: ConversationVisibility;
collaborativeSettings?: CollaborativeSettings;
}
FieldMeaning and defaults
visibilityVisibility for shareable chats. Defaults to 'private' if undefined.
collaborativeSettingsSettings for collaborative conversations (Phase 4)

Also inherits GraphCaptureMetadata. See shared contracts.

GetHistoryOptions​

export interface GetHistoryOptions {
limit?: number;
offset?: number;
sortOrder?: "asc" | "desc";
since?: number;
until?: number;
roles?: ("user" | "agent" | "system")[];
}

GetConversationOptions​

export interface GetConversationOptions {
includeMessages?: boolean;
messageLimit?: number;
}

ListConversationsFilter​

export interface ListConversationsFilter {
type?: ConversationType;
userId?: string;
tenantId?: string;
memorySpaceId?: string;
participantId?: string;
createdBefore?: number;
createdAfter?: number;
updatedBefore?: number;
updatedAfter?: number;
lastMessageBefore?: number;
lastMessageAfter?: number;
messageCount?: number | { min?: number; max?: number };
metadata?: Record<string, unknown>;
limit?: number;
offset?: number;
sortBy?: "createdAt" | "updatedAt" | "lastMessageAt" | "messageCount";
sortOrder?: "asc" | "desc";
includeMessages?: boolean;
}

ListConversationsResult​

export interface ListConversationsResult {
conversations: Conversation[];
total: number;
limit: number;
offset: number;
hasMore: boolean;
}

SearchConversationsInput​

export interface SearchConversationsInput {
query: string;
filters?: {
type?: ConversationType;
userId?: string;
memorySpaceId?: string;
dateRange?: {
start?: number;
end?: number;
};
limit?: number;
};
options?: SearchConversationsOptions;
}

SearchConversationsOptions​

export interface SearchConversationsOptions {
searchIn?: "content" | "metadata" | "both";
matchMode?: "contains" | "exact" | "fuzzy";
}

ConversationSearchResult​

export interface ConversationSearchResult {
conversation: Conversation;
matchedMessages: Message[];
highlights: string[];
score: number;
}

ConversationDeletionResult​

export interface ConversationDeletionResult {
deleted: boolean;
conversationId: string;
messagesDeleted: number;
deletedAt: number;
restorable: boolean;
}

CreateShareInput​

export interface CreateShareInput {
conversationId: string;
grantType: ShareGrantType;
grantedTo?: string;
permissions?: Partial<SharePermissions>;
expiresAt?: number;
maxViews?: number;
redactBefore?: number;
redactSensitive?: boolean;
}

CreateShareResult​

export interface CreateShareResult {
shareId: string;
expiresAt?: number;
share: ConversationShare;
}

SnapshotRedaction​

export interface SnapshotRedaction {
piiRedacted: boolean;
messagesRedactedBefore?: number;
customRedactions?: CustomRedaction[];
}

SnapshotIncludedContent​

export interface SnapshotIncludedContent {
messages: boolean;
facts: boolean;
memories: boolean;
}

CreateSnapshotInput​

export interface CreateSnapshotInput {
conversationId: string;
redactPII?: boolean;
redactBefore?: number;
customRedactions?: CustomRedaction[];
includeFacts?: boolean;
includeMemories?: boolean;
}

CreateSnapshotResult​

export interface CreateSnapshotResult {
snapshotId: string;
snapshot: ConversationSnapshot;
}

Public methods​

The following signatures describe the TypeScript namespace. Parameter and result fields are defined on this page; the installed @cortexmemory/sdk declarations also provide their compile-time types. Signatures are reference notation, not application code to execute.

create​

Create a new conversation

cortex.conversations.create(input: CreateConversationInput, _options?: CreateConversationOptions): Promise<Conversation>

get​

Get a conversation by ID

cortex.conversations.get(conversationId: string, options?: GetConversationOptions & DomainReadOptions): Promise<Conversation | null>

addMessage​

Add a message to a conversation

cortex.conversations.addMessage(input: AddMessageInput, _options?: AddMessageOptions): Promise<Conversation>

list​

List conversations with optional filters and pagination

cortex.conversations.list(filter?: ListConversationsFilter): Promise<ListConversationsResult>

count​

Count conversations

cortex.conversations.count(filter?: CountConversationsFilter): Promise<number>

delete​

Delete a conversation (for GDPR/cleanup)

cortex.conversations.delete(conversationId: string, options?: DeleteConversationOptions & DomainReadOptions): Promise<ConversationDeletionResult & {partial?: DomainPartial}>

deleteMany​

Delete many conversations matching filters

cortex.conversations.deleteMany(filter: {tenantId?: string; userId?: string; memorySpaceId?: string; type?: "user-agent" | "agent-agent"}, options?: DeleteManyConversationsOptions & DomainReadOptions): Promise<DeleteManyConversationsResult & {partial?: DomainPartial}>

getMessage​

Get a specific message by ID

cortex.conversations.getMessage(conversationId: string, messageId: string): Promise<Message | null>

getMessagesByIds​

Get multiple messages by their IDs

cortex.conversations.getMessagesByIds(conversationId: string, messageIds: string[]): Promise<Message[]>

findConversation​

Find an existing conversation by participants

cortex.conversations.findConversation(params: { memorySpaceId: string; type: "user-agent" | "agent-agent"; userId?: string; memorySpaceIds?: string[]; }): Promise<Conversation | null>

getOrCreate​

Get or create a conversation (atomic)

cortex.conversations.getOrCreate(input: CreateConversationInput): Promise<Conversation>

getHistory​

Get paginated message history from a conversation

cortex.conversations.getHistory(conversationId: string, options?: GetHistoryOptions & DomainReadOptions): Promise<{ messages: Message[]; total: number; hasMore: boolean; conversationId: string; }>

Search conversations by text query

cortex.conversations.search(input: SearchConversationsInput): Promise<ConversationSearchResult[]>

export​

Export conversations to JSON or CSV

cortex.conversations.export(options: ExportConversationsOptions & DomainReadOptions): Promise<ExportResult>

checkAccess​

Check if a user has access to a conversation based on visibility

cortex.conversations.checkAccess(input: CheckAccessInput): Promise<CheckAccessResult>

setVisibility​

Set the visibility of a conversation

cortex.conversations.setVisibility(input: SetVisibilityInput): Promise<Conversation>

share​

Create a share for a conversation

cortex.conversations.share(input: CreateShareInput): Promise<CreateShareResult>

revokeShare​

Revoke an existing share

cortex.conversations.revokeShare(shareId: string): Promise<RevokeShareResult>

listShares​

List shares for a conversation

cortex.conversations.listShares(conversationId: string, filter?: { status?: ShareStatus }): Promise<ConversationShare[]>

getShare​

Get a share by its ID

cortex.conversations.getShare(shareId: string): Promise<ConversationShare | null>

checkShareAccess​

Check if a user/space has access to a conversation via share

cortex.conversations.checkShareAccess(input: { conversationId: string; userId?: string; memorySpaceId?: string; emailDomain?: string; }): Promise<CheckShareAccessResult>

snapshot​

Create a snapshot of a conversation

cortex.conversations.snapshot(input: CreateSnapshotInput): Promise<CreateSnapshotResult>

getSnapshot​

Get a snapshot by ID

cortex.conversations.getSnapshot(snapshotId: string): Promise<ConversationSnapshot | null>

listSnapshots​

List snapshots for a conversation

cortex.conversations.listSnapshots(conversationId: string, options?: { includeArchived?: boolean }): Promise<ConversationSnapshot[]>

deleteSnapshot​

Delete a snapshot

cortex.conversations.deleteSnapshot(snapshotId: string): Promise<{ deleted: boolean }>

approveMessage​

Approve a pending message in a collaborative conversation

cortex.conversations.approveMessage(input: ApproveMessageInput): Promise<Conversation>

rejectMessage​

Reject a pending message in a collaborative conversation

cortex.conversations.rejectMessage(input: ApproveMessageInput): Promise<Conversation>

Errors and lifecycle​

Validation, missing capability, authorization, stale version and partial/unknown committed outcomes are explicit. Inspect operation/write/deletion receipts before recovery; do not repeat an external effect under a new identity after uncertainty. Close owned clients and graph resources at the end of the server workflow.

See runtime client for ordinary app execution and error handling for recovery boundaries.