An open-source, faster Devin alternative
TypeScript
sdk: contract-review fixes (stream type filter, webhook normalize, isDefault)
Igor Zalutskia47a66c16920
diff --git a/sdks/typescript/src/agents/credentials.ts b/sdks/typescript/src/agents/credentials.tsindex 5887e76d..cb04a7e4 100644--- a/sdks/typescript/src/agents/credentials.ts+++ b/sdks/typescript/src/agents/credentials.ts@@ -7,6 +7,8 @@ export interface CreateCredentialParams {/** Write-only — never returned by the API. */key: string;name?: string;+ /** Make this the org default for its provider (sent as `is_default`). */+ isDefault?: boolean;}/** Provider keys (e.g. Anthropic, OpenAI), stored in the secret store; sessions run on them. */diff --git a/sdks/typescript/src/agents/sessions.ts b/sdks/typescript/src/agents/sessions.tsindex 4f127193..55b34f51 100644--- a/sdks/typescript/src/agents/sessions.ts+++ b/sdks/typescript/src/agents/sessions.ts@@ -32,7 +32,7 @@ export interface CreateSessionParams {export interface StreamOptions {/** Visibility threshold; default `internal` (the full build trace). */level?: Level;- /** Filter by event type (exact or `prefix.*`). */+ /** Filter by event type (exact or `prefix.*`). Applied client-side as the stream arrives. */type?: string;/** Resume from this seq (default 0 — replays the whole log). */after?: number;@@ -89,7 +89,9 @@ export class ClientSession {}try {for await (const ev of parseEventStream(res)) {- after = ev.seq;+ after = ev.seq; // advance the cursor on every event, even filtered-out ones+ // The SSE endpoint streams by level+seq; apply the type filter here (exact or `prefix.*`).+ if (opts.type && !(opts.type.endsWith(".*") ? ev.type.startsWith(opts.type.slice(0, -1)) : ev.type === opts.type)) continue;yield ev;}} catch {diff --git a/sdks/typescript/src/agents/webhooks.test.ts b/sdks/typescript/src/agents/webhooks.test.tsindex d279f50f..fc222d6b 100644--- a/sdks/typescript/src/agents/webhooks.test.ts+++ b/sdks/typescript/src/agents/webhooks.test.ts@@ -30,7 +30,7 @@ describe("verifyWebhook", () => {const ts = 1_700_000_000;const body = JSON.stringify({type: "turn.completed", sessionId: "ses_1", eventId: "msg_1",- metadata: { pull_number: 7 }, event: { id: "evt_1", type: "turn.completed" },+ metadata: { pull_number: 7 }, event: { id: "evt_1", type: "turn.completed", turn_id: "trn_1" },});const hdr = (sig: string) => ({ "webhook-id": id, "webhook-timestamp": String(ts), "webhook-signature": sig });@@ -38,7 +38,8 @@ describe("verifyWebhook", () => {const delivery = await verifyWebhook(body, hdr(await sign(id, ts, body, SECRET)), SECRET, { nowSeconds: ts });expect(delivery.type).toBe("turn.completed");expect(delivery.eventId).toBe("msg_1");- expect(delivery.metadata).toEqual({ pull_number: 7 });+ expect(delivery.metadata).toEqual({ pull_number: 7 }); // opaque — verbatim+ expect((delivery.event as { turnId?: string }).turnId).toBe("trn_1"); // wire turn_id → camelCase});it("rejects a tampered body", async () => {diff --git a/sdks/typescript/src/agents/webhooks.ts b/sdks/typescript/src/agents/webhooks.tsindex e4c3e5c8..229c0a59 100644--- a/sdks/typescript/src/agents/webhooks.ts+++ b/sdks/typescript/src/agents/webhooks.ts@@ -11,6 +11,7 @@// request body, BEFORE JSON-parsing it.import type { Event } from "./types.js";+import { normalize } from "./normalize.js";/** The envelope OpenComputer POSTs to a destination (see the Webhooks docs). */export interface WebhookDelivery<E = Event> {@@ -138,7 +139,9 @@ export async function verifyWebhook<E = Event>(if (!matched) throw new WebhookVerificationError("no matching webhook signature");try {- return JSON.parse(rawBody) as WebhookDelivery<E>;+ // Normalize so the returned envelope + nested event match the SDK's camelCase types+ // (the wire event is snake-cased, e.g. `turn_id`); `metadata` stays verbatim (opaque).+ return normalize(JSON.parse(rawBody)) as WebhookDelivery<E>;} catch {throw new WebhookVerificationError("signature valid but body is not JSON");}