An open-source, faster Devin alternative
TypeScript
Document session creation by agent reference and replay on the original deployment
Igor Zalutskiba34bee61144
diff --git a/docs/agents/api.mdx b/docs/agents/api.mdxindex 520bbd59..59366841 100644--- a/docs/agents/api.mdx+++ b/docs/agents/api.mdx@@ -78,8 +78,8 @@ curl -X POST 'https://app.opencomputer.dev/api/managed-agents/sessions' \| Field | Meaning || --- | --- |-| `agentId` | `<agent-id>@development` or `<agent-id>@production`. The alias selects the environment and the deployment active in it. A bare agent ID means `production`. |-| `deploymentId` | Pin one deployment instead of resolving an alias. Send `environment` with it; it may be omitted only when the deployment is promoted to exactly one environment. |+| `agentId` | `<agent-id>@development` or `<agent-id>@production`. The alias selects the environment and the deployment active in it. A bare agent ID means `production`. This is how applications address an agent; which deployment runs the session is the platform's choice, recorded on the session. |+| `deploymentId` | Advanced: pin one deployment instead of resolving an alias, for reproducibility or testing. Send `environment` with it; it may be omitted only when the deployment is promoted to exactly one environment. || `environment` | `development` or `production`. Optional with `agentId`; it must agree with the alias. || `memory` | Bindings keyed by resource ID, at most eight. Needs a deployed agent and an environment. Shapes on [Document memory](/agents/document-memory#session-bindings). || `source` | `api` (default), `playground`, `channel` or `webhook`. The dashboard groups sessions by it. |@@ -91,12 +91,22 @@ The session starts without a turn; send one with the turns route.`Idempotency-Key` (at most 256 characters) makes a retry safe. The keyidentifies the session within your organization:-- The same key with the same agent, deployment, environment and memory- bindings returns the existing session with `200`.-- Anything else under that key is `409 idempotency_conflict`. The deployment- is part of the identity, so after a redeploy the same key conflicts:- a session pins its deployment, and new code needs a new session under a- new key.+- The same key with the same request, meaning the same `agentId` (or the+ same pinned `deploymentId`), environment and memory bindings, returns the+ existing session with `200`, together with the deployment it pinned when+ it was first created. That holds after a redeploy or a rollback: the+ session keeps the deployment it started with, and your retry does not+ need to know which one that was. A new session under a new key gets the+ deployment active at that time.+- Anything else under that key is `409 idempotency_conflict`: another+ agent, environment or pinned deployment, or different memory bindings.+ Pinning the deployment the session already holds counts as the same+ request.+- Two identical requests under one key that arrive together create one+ session; both answers name it, one with `201` and the other with `200`.+- Sessions created before this rule was recorded keep the earlier one: a+ replay through an alias succeeds only while the alias still resolves to+ the deployment the session pinned.- `503 memory_admission_unconfirmed` means the memory grants were notconfirmed in time. Retry with the same key; the retry resumes the wait.- `503 session_publication_unconfirmed` means the session exists but itsdiff --git a/sdks/typescript/package-lock.json b/sdks/typescript/package-lock.jsonindex 850a6af3..667f80a1 100644--- a/sdks/typescript/package-lock.json+++ b/sdks/typescript/package-lock.json@@ -1,12 +1,12 @@{"name": "@opencomputer/sdk",- "version": "2.1.0",+ "version": "2.1.1","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@opencomputer/sdk",- "version": "2.1.0",+ "version": "2.1.1","license": "MIT","dependencies": {"undici": "^6.0.0 || ^7.0.0"diff --git a/sdks/typescript/package.json b/sdks/typescript/package.jsonindex d7f85ce0..b9c986d0 100644--- a/sdks/typescript/package.json+++ b/sdks/typescript/package.json@@ -1,6 +1,6 @@{"name": "@opencomputer/sdk",- "version": "2.1.0",+ "version": "2.1.1","description": "TypeScript SDK for OpenComputer - cloud sandboxes and the Serverless Agents management API","type": "module","main": "dist/index.js",diff --git a/sdks/typescript/src/agents/types.ts b/sdks/typescript/src/agents/types.tsindex 4fe53a32..0824eae7 100644--- a/sdks/typescript/src/agents/types.ts+++ b/sdks/typescript/src/agents/types.ts@@ -107,7 +107,7 @@ export interface Session {/** What `POST /sessions` returns. */export interface SessionCreated {session: Pick<Session, "id" | "status" | "createdAt"> & Partial<Session>;- /** The deployment the session pinned. */+ /** The deployment the session pinned when it was first created; on a replay, that one, not the alias's current one. */deployment?: Deployment;/*** `true` when this call created the session (`201`); `false` when the@@ -117,9 +117,15 @@ export interface SessionCreated {}export interface CreateSessionParams {- /** `<agent-id>@development` or `<agent-id>@production`; a bare id means `production`. */+ /**+ * `<agent-id>@development` or `<agent-id>@production`; a bare id means+ * `production`. This is how an application addresses an agent: the+ * platform chooses the deployment, records it on the session, and a+ * replay of the same `idempotencyKey` returns that session and that+ * deployment even after a redeploy.+ */agentId?: string;- /** Pin one deployment instead of resolving an alias. Send `environment` with it. */+ /** Advanced: pin one deployment instead of resolving an alias. Send `environment` with it. */deploymentId?: string;environment?: Environment;/** Bindings keyed by resource id, at most eight. */