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
| Column | Type | Notes |
|---|---|---|
| id | text PK | |
| organization_id | text | |
| source_type | text | web, cctv, social |
| session_id | text | nullable |
| data | text | Raw interaction data (JSON) |
| summary | text | nullable, AI-generated |
| confidence | real | nullable, 0.0-1.0 |
| tags | text | nullable, JSON array |
| product_ids | text | nullable, JSON array of matched product IDs |
| timestamp | timestamp | When the interaction occurred |
| created_at | timestamp |
Routes
| Method | Path | Description |
|---|---|---|
| GET | /api/v1/interactions/organization/{orgId} | List interactions (paginated, filterable by sourceType, searchable via q) |
| GET | /api/v1/interactions/organization/{orgId}/summary | Counts by source type (web, cctv, social, total) |
| POST | /api/v1/interactions/organization/{orgId}/analyze | AI-generated analysis (summary, insights, anomalies, recommendations) |
| POST | /api/v1/interactions/create-interaction | Queue an interaction for processing |
Environment Variables
| Variable | Example |
|---|---|
| ENVIRONMENT | dev |
| AUTH_SERVICE_URL | https://dev.internal.auth-api.crowai.dev |
| PRODUCT_SERVICE_URL | https://dev.internal.products.crowai.dev |
Secrets
| Secret | Purpose |
|---|---|
| SYSTEM_SECRET | System-level auth for internal operations |
| INTERNAL_GATEWAY_KEY | Gateway trust validation |
Bindings
| Binding | Type | Name |
|---|---|---|
| DB | D1 | crow-core-interaction-service-db |
| R2_BUCKET | R2 | crow-core-interaction-service-store |
| AI | Workers AI | LLM inference |
| INTERACTION_ANALYZER | Durable Object | InteractionAnalyzerContainer (Workers Container) |
| INTERACTION_QUEUE | Queue (producer + consumer) | crow-interaction-queue |
| CCTV_QUEUE | Queue (producer + consumer) | crow-cctv-batch-queue |
Queue Configuration
| Queue | Role | Batch Size | Timeout | Retries | Delay |
|---|---|---|---|---|---|
crow-interaction-queue | Producer + Consumer | 10 | 30s | 3 | 60s |
crow-cctv-batch-queue | Producer + Consumer | 5 | 60s | 3 | 120s |
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-IdagainstorgIdpath parameter - CCTV processing: Uses
@cf/meta/llama-3.3-70b-instruct-fp8-fastto 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