Skip to content

Core: Data Model, Types & Interfaces #2

@ggondim

Description

@ggondim

Summary

Define all core TypeScript types, the abstract storage interface, and the abstract channel adapter interface. These contracts are the foundation that every other package implements against.

Tasks

Data Model & Types

  • Define core types:
    • Channel — id, platform, credentials reference, metadata
    • Recipient — id, webhookUrl, apiKey, metadata
    • Thread — threadId (ot_thr_*), channelId, nativeThreadId (nullable), targetId, createdAt
    • Turn — turnId (ot_turn_*), threadId, direction (inbound/outbound), message, timestamp
    • Route — id, criteria (channel, group, DM, thread, mention, sender, content pattern), recipientId, priority
    • Envelope — threadId, turnId, replyTo, source, message (single object or array)
  • Define A2H intent types: INFORM, COLLECT, AUTHORIZE, ESCALATE, RESULT
  • Define message union type with duck-typing discriminator: presence of intent = A2H, otherwise = Chat SDK
  • ID generation utilities (ot_thr_*, ot_turn_*, ot_tk_*, ot_ch_sk_*)

Storage Interface

  • Define abstract StorageAdapter interface:
    • channels: CRUD
    • recipients: CRUD
    • threads: create, getById, getByNativeId, listByChannel
    • turns: create, listByThread
    • routes: CRUD, match(criteria) → Route[]
    • tokens: create (ephemeral), validate, revoke
  • Define StorageAdapterFactory pattern for pluggable instantiation

Channel Adapter Interface

  • Define abstract ChannelAdapter interface:
    • register(config) — set up webhook/subscription listeners
    • sendMessage(target, message) — send rendered message to channel
    • renderChatSDK(message, capabilities) — adapt Chat SDK message to platform
    • renderA2HInline(intent, capabilities) — render buttons/selects for A2H
    • captureResponse(thread, turn) — listen for response in thread/reply/DM
    • capabilities() — returns platform capability flags
  • Define ChannelCapabilities type: { threads, buttons, selectMenus, replyMessages, dms, fileUpload }
  • Integrate Vercel Chat SDK as the base adapter layer

Acceptance Criteria

  • All types exported from packages/core
  • Storage interface is fully abstract (no implementation)
  • Channel adapter interface is fully abstract (no implementation)
  • ID generation produces correctly prefixed, unique IDs
  • Duck-typing discriminator correctly classifies Chat SDK vs A2H messages
  • Unit tests for ID generation and message classification

Dependencies

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions