Skip to content

An open-source, faster Devin alternative

TypeScript

docs+sdk: review round 2 — turn schema, metadata round-trip, normalize test

Igor Zalutski6d5dd0dc70b7
diff --git a/docs/agent-sessions/custom-runtimes.mdx b/docs/agent-sessions/custom-runtimes.mdx
index e0101c9b..cda2aa03 100644
--- a/docs/agent-sessions/custom-runtimes.mdx
+++ b/docs/agent-sessions/custom-runtimes.mdx
@@ -54,9 +54,10 @@ Content-Type: application/json
"model": "anthropic/claude-opus-4-8",
"system_prompt": "Run tests and explain risks.",
"mcp_endpoint": "http://127.0.0.1:8765/mcp",
- "state_dir": "/home/sandbox/.oc/runtime-state"
- },
- "deadline_s": 600
+ "state_dir": "/home/sandbox/.oc/runtime-state",
+ "resume": false,
+ "max_turns": 24
+ }
}
```
diff --git a/sdks/typescript/package-lock.json b/sdks/typescript/package-lock.json
index 7c6a9970..e1610781 100644
--- a/sdks/typescript/package-lock.json
+++ b/sdks/typescript/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@opencomputer/sdk",
- "version": "0.7.4",
+ "version": "0.7.5",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@opencomputer/sdk",
- "version": "0.7.4",
+ "version": "0.7.5",
"license": "MIT",
"devDependencies": {
"@types/node": "^25.3.0",
diff --git a/sdks/typescript/package.json b/sdks/typescript/package.json
index 78605dbc..0a507428 100644
--- a/sdks/typescript/package.json
+++ b/sdks/typescript/package.json
@@ -1,6 +1,6 @@
{
"name": "@opencomputer/sdk",
- "version": "0.7.4",
+ "version": "0.7.5",
"description": "TypeScript SDK for OpenComputer - cloud sandbox platform",
"type": "module",
"main": "dist/index.js",
diff --git a/sdks/typescript/src/agents/normalize.test.ts b/sdks/typescript/src/agents/normalize.test.ts
new file mode 100644
index 00000000..96e48d98
--- /dev/null
+++ b/sdks/typescript/src/agents/normalize.test.ts
@@ -0,0 +1,35 @@
+import { describe, it, expect } from "vitest";
+import { normalize, serialize } from "./normalize.js";
+
+describe("normalize (API response → idiomatic TS)", () => {
+ it("camelCases nested keys — last_turn → lastTurn, and the field is `id`", () => {
+ const out = normalize<{ lastTurn?: { id?: string; yieldReason?: string; resultEventId?: string } }>({
+ last_turn: { id: "trn_1", yield_reason: "completed", result_event_id: "evt_9" },
+ });
+ expect(out.lastTurn?.id).toBe("trn_1");
+ expect(out.lastTurn?.yieldReason).toBe("completed");
+ expect(out.lastTurn?.resultEventId).toBe("evt_9");
+ });
+
+ it("coerces known stringified-bigint numerics", () => {
+ const out = normalize<{ seq?: number; head?: number }>({ seq: "12", head: "3" });
+ expect(out.seq).toBe(12);
+ expect(out.head).toBe(3);
+ });
+
+ it("passes `metadata` through verbatim — opaque, inner keys untouched", () => {
+ const out = normalize<{ metadata?: Record<string, unknown> }>({
+ metadata: { pull_number: 42, owner_repo: "acme/widgets", nested: { keep_me: true } },
+ });
+ // Caller's routing JSON must round-trip exactly as set (no snake→camel mangling).
+ expect(out.metadata).toEqual({ pull_number: 42, owner_repo: "acme/widgets", nested: { keep_me: true } });
+ });
+});
+
+describe("serialize (request body → snake_case)", () => {
+ it("snake_cases keys but leaves metadata opaque", () => {
+ const out = serialize({ idempotencyKey: "k1", metadata: { pullNumber: 42 } }) as Record<string, unknown>;
+ expect(out.idempotency_key).toBe("k1");
+ expect(out.metadata).toEqual({ pullNumber: 42 }); // verbatim
+ });
+});
diff --git a/sdks/typescript/src/agents/normalize.ts b/sdks/typescript/src/agents/normalize.ts
index 296d1938..7a8a1edf 100644
--- a/sdks/typescript/src/agents/normalize.ts
+++ b/sdks/typescript/src/agents/normalize.ts
@@ -1,6 +1,7 @@
// Normalize API responses to idiomatic TS: snake_case keys → camelCase, and a known set
-// of numeric fields that the API serializes as strings (bigints) → numbers. Leaves the
-// opaque `raw` payload (source-specific adapter data) untouched.
+// of numeric fields that the API serializes as strings (bigints) → numbers. Opaque
+// subtrees are passed through untouched: `raw` (source-specific adapter data) and
+// `metadata` (the caller's own routing JSON — must round-trip verbatim, keys included).
const NUMERIC = new Set([
"seq", "head", "inputCursor", "inputFromSeq", "inputToSeq", "exitCode", "bytes", "port",
@@ -16,7 +17,7 @@ export function normalize<T = any>(value: unknown): T {
const out: Record<string, unknown> = {};
for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
const ck = camel(k);
- if (ck === "raw") { out[ck] = v; continue; }
+ if (ck === "raw" || ck === "metadata") { out[ck] = v; continue; } // opaque: verbatim, keys untouched
let nv: unknown = normalize(v);
if (NUMERIC.has(ck) && typeof nv === "string" && nv !== "" && !Number.isNaN(Number(nv))) {
nv = Number(nv);