Skip to main content

Platform Service Patterns

Use these patterns when choosing how an app, eai-gofer, or terminal automation should call EAI platform capabilities.

Boundary Rules

  • Browser code calls the app BFF at /api/eai/....
  • Browser streaming calls use /api/eai/stream/....
  • App code should prefer template hooks before hand-written fetches.
  • CLI automation may call platform services through authenticated eai commands.
  • Use eai publicapi only for authorized PublicAPI V4 routes that do not yet have named SDK or CLI support.
  • Do not generate direct downstream database, blob, search, model provider, or platform secrets.

Service Selection Matrix

NeedApp PatternCLI PatternNotes
Frontend compositionsrc/eai.config layout slots plus src/eai.blocks.tsx registryeai gofer refresh installs guidanceKeep config data-only; callbacks belong in overrides.
Data modelObject Types in src/eai.config/object-types.tseai types validate, eai types seed, eai types diffObject Types define ResourceAPI contracts.
Structured resourcesuseResources(type) or client.resourceseai resources list/get/create/update/delete/queryDefault for tenant business data.
Resource actionsclient.resources.executeAction(type, id, action)named resources command if available; otherwise eai publicapi post /v4/data/resources/...Actions enforce Object Type rules.
Resource searchhelper around PublicAPI resource search if SDK support is absenteai resources search "<query>" --mode hybridSearch is a projection over canonical data.
Resource fileshelper around resource file routeseai resources file upload/get/deleteUse for file fields on ResourceAPI objects.
DocumentsuseDocuments().upload/classify/ragIndexeai docs upload, eai docs classify, eai docs indexUse for platform document processing and RAG.
ChatuseChat(workflowId, stage).send/streameai chat send, eai chat streamUse message, conversation_id, and params.
Advanced PublicAPIBFF or server helpereai publicapi <method> /v4/...Use only when named support is missing.

Storage Backend Rules

  • postgresql: canonical structured resource storage.
  • documentdb: document-model persistence when the data genuinely needs it.
  • blob: large files or file-like resources behind API-mediated access.
  • search: derived full-text, vector, or hybrid projection, not the sole system of record for runtime writes.

Document RAG indexing is a documents service pattern (useDocuments().ragIndex or eai docs index), not a reason to create a search-only Object Type.

Chat Payload Pattern

await client.chat.send({
workflowId,
stage: "chat",
message: "Summarise this application",
conversationId,
params: {},
runtime_context: { applicationId },
});

The platform expects message, conversation_id, and params. Do not generate legacy payloads such as chat_input for new apps.

Resource Payload Pattern

const { list, create, update, executeAction } = useResources<ApplicationData>(
"Application",
tenantId,
);

const applications = await list({ limit: 20, sort: "-created_at" });
const created = await create({ applicantName: "Jane", status: "draft" });
await update(created.id, { status: "submitted" }, created.version);
await executeAction(created.id, "submit");

Updates require the current version for optimistic locking.

Document Pattern

const { upload, classify, ragIndex } = useDocuments(tenantId);

const uploaded = await upload(file, {
category: "supporting-document",
application_id: applicationId,
});
const documentId = uploaded.documentId;

await classify([file]);
await ragIndex(documentId);

Use ResourceAPI file routes when the file is a property of a ResourceAPI object. Use document upload, classification, and RAG routes when the platform should process the document content.