Skip to main content

core-interaction-service

Processes incoming interaction data from all channels (web, CCTV, social). Stores structured interaction records with AI-generated summaries, product associations, and confidence scores. Uses Workers Containers with Durable Objects for CCTV batch analysis.

Worker name: crow-core-interaction-service Domain (prod): internal.interactions.crowai.dev Domain (dev): dev.internal.interactions.crowai.dev

Schema

interaction

ColumnTypeNotes
idtext PK
organization_idtext
source_typetextweb, cctv, social
session_idtextnullable
datatextRaw interaction data (JSON)
summarytextnullable, AI-generated
confidencerealnullable, 0.0-1.0
tagstextnullable, JSON array
product_idstextnullable, JSON array of matched product IDs
timestamptimestampWhen the interaction occurred
created_attimestamp

Routes

MethodPathDescription
GET/api/v1/interactions/organization/{orgId}List interactions (paginated, filterable by sourceType, searchable via q)
GET/api/v1/interactions/organization/{orgId}/summaryCounts by source type (web, cctv, social, total)
POST/api/v1/interactions/organization/{orgId}/analyzeAI-generated analysis (summary, insights, anomalies, recommendations)
POST/api/v1/interactions/create-interactionQueue an interaction for processing

Environment Variables

VariableExample
ENVIRONMENTdev
AUTH_SERVICE_URLhttps://dev.internal.auth-api.crowai.dev
PRODUCT_SERVICE_URLhttps://dev.internal.products.crowai.dev

Secrets

SecretPurpose
SYSTEM_SECRETSystem-level auth for internal operations
INTERNAL_GATEWAY_KEYGateway trust validation

Bindings

BindingTypeName
DBD1crow-core-interaction-service-db
R2_BUCKETR2crow-core-interaction-service-store
AIWorkers AILLM inference
INTERACTION_ANALYZERDurable ObjectInteractionAnalyzerContainer (Workers Container)
INTERACTION_QUEUEQueue (producer + consumer)crow-interaction-queue
CCTV_QUEUEQueue (producer + consumer)crow-cctv-batch-queue

Queue Configuration

QueueRoleBatch SizeTimeoutRetriesDelay
crow-interaction-queueProducer + Consumer1030s360s
crow-cctv-batch-queueProducer + Consumer560s3120s

Workers Container

The InteractionAnalyzerContainer is a Durable Object-backed Workers Container:

  • Image: ./Dockerfile
  • Max instances: 2
  • Purpose: Runs longer AI analysis tasks that exceed Worker CPU time limits

Message Types

InteractionMessage (INTERACTION_QUEUE)

{
organizationId: string
sourceType: 'web' | 'cctv' | 'social'
sessionId?: string
data: string
summary?: string
timestamp: number
}

CctvBatchQueueMessage (CCTV_QUEUE)

{
organizationId: string
sourceType: 'cctv'
sessionId: string
cameraId: string
batchIndex: number
frameAnalyses: Array<{
frameIndex: number
timestamp: number
description: string
}>
batchStartTimestamp: number
batchEndTimestamp: number
}

Dependencies

  • Inbound: web-ingest service (via queue), cctv-ingest service (via queue), gateway (CRUD), chat service (data access), pattern service (data access)
  • Outbound: product service (catalog lookup for product matching), auth service (JWT verification)

Key Behaviors

  • BOLA: All org-scoped routes check X-Organization-Id against orgId path parameter
  • CCTV processing: Uses @cf/meta/llama-3.3-70b-instruct-fp8-fast to match CCTV frame descriptions against the product catalog
  • INTERNAL_GATEWAY_KEY guard: Rejects requests without the shared internal key
  • ZodError sanitization: Validation errors return sanitized messages without leaking schema details