This repository has been archived on 2026-08-04. You can view files and clone it, but cannot push or open issues or pull requests.
seahaven-slack-bot/lib/constructs/conversation-log.ts

32 lines
1.3 KiB
TypeScript
Raw Normal View History

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
export class ConversationLogConstruct extends Construct {
public readonly table: dynamodb.Table;
constructor(scope: Construct, id: string) {
super(scope, id);
this.table = new dynamodb.Table(this, 'Table', {
tableName: 'seahaven-conversations',
// PK: Slack user ID (e.g. U0123456789)
partitionKey: { name: 'userId', type: dynamodb.AttributeType.STRING },
// SK: ISO-8601 timestamp — enables range queries for session lookup
sortKey: { name: 'timestamp', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: cdk.RemovalPolicy.RETAIN,
pointInTimeRecoverySpecification: { pointInTimeRecoveryEnabled: true },
// TTL attribute — records are automatically expired after 90 days
timeToLiveAttribute: 'ttl',
});
// GSI for looking up all turns in a given Bedrock session (for context retrieval)
this.table.addGlobalSecondaryIndex({
indexName: 'sessionId-index',
partitionKey: { name: 'sessionId', type: dynamodb.AttributeType.STRING },
sortKey: { name: 'timestamp', type: dynamodb.AttributeType.STRING },
});
}
}