# Temporal Continuity: AI Coding Integration Guide

This guide is intended for developers using an AI coding assistant to integrate the **Temporal Continuity** hosted service into an application.

## What to install

Use the supported TypeScript SDK, **not** an MCP adapter:

```bash
npm install temporal-continuity
```

Requirements: a Node.js application with a server-side runtime, a Temporal Continuity developer account, an API key, and the organization, project, and environment identifiers from the developer console.

## Server-side configuration

Configure these values in the application's server environment (for local development, use a git-ignored environment file):

```dotenv
TEMPORAL_CONTINUITY_API_KEY=your_api_key
TEMPORAL_CONTINUITY_BASE_URL=https://api.rscapex.com
TEMPORAL_CONTINUITY_ORGANIZATION_ID=your_organization_id
TEMPORAL_CONTINUITY_PROJECT_ID=your_project_id
TEMPORAL_CONTINUITY_ENVIRONMENT_ID=your_environment_id
```

Never expose the API key in browser bundles, client components, logs, or a repository.

## Initialize the SDK

```ts
import { RMS } from "temporal-continuity";

export const rms = new RMS({
  apiKey: process.env.TEMPORAL_CONTINUITY_API_KEY,
  baseUrl: process.env.TEMPORAL_CONTINUITY_BASE_URL,
  organizationId: process.env.TEMPORAL_CONTINUITY_ORGANIZATION_ID,
  projectId: process.env.TEMPORAL_CONTINUITY_PROJECT_ID,
  environmentId: process.env.TEMPORAL_CONTINUITY_ENVIRONMENT_ID,
});
```

Run this code only on the server.

## Integrate the conversation lifecycle

Temporal continuity must be part of the application's **deterministic request lifecycle**, not an optional model-selected tool call.

1. Authenticate the application's user and resolve their authorized, stable relationship identity. Do not create a new relationship on every turn.
2. Before cognition, load the relationship's authorized context with the SDK or use the supported provider-neutral composition pathway.
3. Supply the retrieved context to the chosen cognition provider in a controlled, auditable way.
4. Record the interaction through the supported contribution/composition pathway. Confirm persistence and capture its receipt before treating the turn as committed.
5. Handle retries using stable idempotency keys. Reuse a key only for a retry of the same operation.
6. Test session clearing, process restart, returning users, provider changes, duplicate requests, and failed commits. Do not silently claim a turn was persisted when the commit failed.

For a managed user, the SDK supports provider-neutral composition with an application-supplied cognition callback:

```ts
await rms.compose({
  userId,
  content: "Remember that I prefer concise answers.",
  idempotencyKey: crypto.randomUUID(),
  cognition: async projection => invokeRegisteredCognition(projection),
});
```

`userId` must be the stable, provisioned application user identifier; `invokeRegisteredCognition` is **your application's** provider integration, not a function supplied by the SDK. Adapt the callback to the actual provider and SDK response contracts.

## Instructions to give your AI coding assistant

> Integrate the `temporal-continuity` TypeScript SDK into my application's server-side conversation lifecycle. First inspect my existing authentication, user identity, conversation handler, and cognition provider integration. Reuse authorized relationship identities. Hydrate context before cognition and ensure contribution persistence is confirmed after each turn, using supported SDK operations and idempotency. Keep credentials server-side. Do not introduce an MCP integration or model-optional memory tool calls. Show the files changed, the error-handling behavior, and tests proving continuity across sessions, retries, and provider changes. Do not invent SDK methods; consult the current SDK reference.

## References

- [TypeScript SDK quickstart](/developers/typescript)
- [SDK methods and API routes](/developers/reference)
- [Developer console](/console/enroll)

**Scope:** This guide describes application integration. Installing the SDK alone does not automatically intercept model turns or guarantee retrieval quality. The application must enforce the lifecycle and test its outcomes.
