An open-source, faster Devin alternative
TypeScript
sdk: make managed surface 1:1 with the v3 public API (no gaps)
Igor Zalutskicd6d7fa6a83c
diff --git a/sdks/typescript/src/agents/destinations.ts b/sdks/typescript/src/agents/destinations.tsnew file mode 100644index 00000000..bfe6cace--- /dev/null+++ b/sdks/typescript/src/agents/destinations.ts@@ -0,0 +1,61 @@+import type { Http, Query } from "./http.js";+import type { Destination, Delivery, DeliveryStatus, Level } from "./types.js";++export interface CreateDestinationParams {+ url: string;+ /** Signing secret (write-only). */+ secret?: string;+ level?: Level;+ /** Event-type allow-list (exact or `prefix.*`); default all. */+ types?: string[];+ includeRaw?: boolean;+ enabled?: boolean;+}++export interface UpdateDestinationParams {+ enabled?: boolean;+ level?: Level;+ types?: string[];+ secret?: string;+}++/** Webhook destinations for one session. Management — needs the org key. */+export class Destinations {+ constructor(private readonly http: Http, private readonly sessionId: string) {}++ create(params: CreateDestinationParams): Promise<Destination> {+ return this.http.request("POST", `/sessions/${this.sessionId}/destinations`, { body: params });+ }+ async list(): Promise<Destination[]> {+ const r = await this.http.request<{ data?: Destination[] } | Destination[]>("GET", `/sessions/${this.sessionId}/destinations`);+ return Array.isArray(r) ? r : r.data ?? [];+ }+ get(id: string): Promise<Destination> {+ return this.http.request("GET", `/sessions/${this.sessionId}/destinations/${id}`);+ }+ update(id: string, params: UpdateDestinationParams): Promise<Destination> {+ return this.http.request("PATCH", `/sessions/${this.sessionId}/destinations/${id}`, { body: params });+ }+ delete(id: string): Promise<void> {+ return this.http.request("DELETE", `/sessions/${this.sessionId}/destinations/${id}`);+ }+}++/** Delivery records (the deliveries control surface) for one session. Needs the org key. */+export class Deliveries {+ constructor(private readonly http: Http, private readonly sessionId: string) {}++ async list(params: { destination?: string; status?: DeliveryStatus } = {}): Promise<Delivery[]> {+ const r = await this.http.request<{ data?: Delivery[] } | Delivery[]>(+ "GET", `/sessions/${this.sessionId}/deliveries`, { query: params as Query },+ );+ return Array.isArray(r) ? r : r.data ?? [];+ }+ get(id: string): Promise<Delivery> {+ return this.http.request("GET", `/sessions/${this.sessionId}/deliveries/${id}`);+ }+ /** Re-send any delivery (not just dead-lettered). */+ redeliver(id: string): Promise<void> {+ return this.http.request("POST", `/sessions/${this.sessionId}/deliveries/${id}/redeliver`);+ }+}diff --git a/sdks/typescript/src/agents/http.ts b/sdks/typescript/src/agents/http.tsindex 6cd9170e..dc6af024 100644--- a/sdks/typescript/src/agents/http.ts+++ b/sdks/typescript/src/agents/http.ts@@ -78,6 +78,13 @@ export class Http {if (!res.ok) throw errorFromResponse(res.status, (await safeJson(res))?.error, retryAfterSec(res));return res;}++ /** Raw GET (no JSON parse) — e.g. blob-backed event content. Returns the checked Response. */+ async raw(method: string, path: string, opts: { query?: Query; signal?: AbortSignal } = {}): Promise<Response> {+ const res = await this.doFetch(this.url(path, opts.query), { method, headers: this.headers(), signal: opts.signal });+ if (!res.ok) throw errorFromResponse(res.status, (await safeJson(res))?.error, retryAfterSec(res));+ return res;+ }}const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));diff --git a/sdks/typescript/src/agents/index.ts b/sdks/typescript/src/agents/index.tsindex 7b5064df..67e82933 100644--- a/sdks/typescript/src/agents/index.ts+++ b/sdks/typescript/src/agents/index.ts@@ -7,6 +7,8 @@ export { Agents } from "./agents.js";export type { CreateAgentParams, UpdateAgentParams, Page } from "./agents.js";export { Credentials } from "./credentials.js";export type { CreateCredentialParams } from "./credentials.js";+export { Destinations, Deliveries } from "./destinations.js";+export type { CreateDestinationParams, UpdateDestinationParams } from "./destinations.js";export * from "./types.js";export * from "./errors.js";diff --git a/sdks/typescript/src/agents/sessions.ts b/sdks/typescript/src/agents/sessions.tsindex 1e112815..881d8413 100644--- a/sdks/typescript/src/agents/sessions.ts+++ b/sdks/typescript/src/agents/sessions.ts@@ -1,6 +1,7 @@import type { Http, Query } from "./http.js";-import type { Event, Level, Limits, LastTurn, SessionData, SessionStatus } from "./types.js";+import type { Event, Level, Limits, LastTurn, SessionData, SessionStatus, Turn } from "./types.js";import { parseEventStream } from "./sse.js";+import { Destinations, Deliveries } from "./destinations.js";export type Envelope = { text?: string; [k: string]: unknown };@@ -51,11 +52,16 @@ export class Sessions {export class Session {/** Present after create / connectSession — safe to hand to a browser. */readonly clientToken?: string;+ /** Webhook destinations + delivery records for this session (management — need the org key). */+ readonly destinations: Destinations;+ readonly deliveries: Deliveries;private data: SessionData;constructor(private readonly http: Http, data: SessionData, clientToken?: string) {this.data = data;this.clientToken = clientToken;+ this.destinations = new Destinations(http, data.id);+ this.deliveries = new Deliveries(http, data.id);}get id(): string { return this.data.id; }@@ -107,6 +113,31 @@ export class Session {return this.http.request("GET", `/sessions/${this.id}/events`, { query: opts as Query });}+ /** Fetch a single event by id. */+ event(eventId: string): Promise<Event> {+ return this.http.request("GET", `/sessions/${this.id}/events/${eventId}`);+ }++ /** Fetch a blob-backed event body (large outputs) as text. */+ async eventContent(eventId: string): Promise<string> {+ return (await this.http.raw("GET", `/sessions/${this.id}/events/${eventId}/content`)).text();+ }++ /** User-message history (alias for level=user + type=*.message). */+ messages(opts: { after?: number; limit?: number } = {}): Promise<ListPage<Event>> {+ return this.http.request("GET", `/sessions/${this.id}/messages`, { query: opts as Query });+ }++ /** Per-turn history (timing + outcome). */+ turns(): Promise<Turn[]> {+ return this.http+ .request<{ data?: Turn[] } | Turn[]>("GET", `/sessions/${this.id}/turns`)+ .then((r) => (Array.isArray(r) ? r : r.data ?? []));+ }+ turn(turnId: string): Promise<Turn> {+ return this.http.request("GET", `/sessions/${this.id}/turns/${turnId}`);+ }+/** Send a message; wakes the session. */async steer(text: string, opts: { idempotencyKey?: string } = {}): Promise<{ id: string; seq: number }> {const r = await this.http.request<{ event: { id: string; seq: number } }>(diff --git a/sdks/typescript/src/agents/types.ts b/sdks/typescript/src/agents/types.tsindex 2971413e..b4ebd6a0 100644--- a/sdks/typescript/src/agents/types.ts+++ b/sdks/typescript/src/agents/types.ts@@ -38,6 +38,16 @@ export interface LastTurn {error?: unknown;}+export interface Turn {+ id: string;+ state?: "queued" | "running" | "ok" | "error";+ yieldReason?: YieldReason;+ resultEventId?: string;+ error?: unknown;+ startedAt?: string;+ completedAt?: string;+}+export interface SessionData {id: string;status: SessionStatus;@@ -59,6 +69,29 @@ export interface Credential {createdAt?: string;}+export interface Destination {+ id: string;+ url: string;+ level: Level;+ types?: string[];+ includeRaw: boolean;+ enabled: boolean;+ createdAt?: string;+}++export type DeliveryStatus = "pending" | "delivering" | "delivered" | "failed" | "dead_letter";++export interface Delivery {+ id: string;+ destinationId: string;+ eventId: string;+ status: DeliveryStatus;+ attempts: number;+ lastAttemptAt?: string;+ responseCode?: number;+ error?: string;+}+// ── Events ─────────────────────────────────────────────────────────────────────// Discriminated on `type`. Switch on it; don't parse prose. Unknown types fall through// the open member and still carry `body.text`/`summary`, so new types are non-breaking.