// ── SDK v2 — AgentDraftsClient ──────────────────────────────────────────────── // // Covers: // POST /v2/agents/drafts // GET /v2/agents/drafts // GET /v2/agents/drafts/:id // PATCH /v2/agents/drafts/:id // DELETE /v2/agents/drafts/:id // POST /v2/agents/drafts/:id/publish import type { Fetcher } from "../http/fetcher"; import type { RequestOptions } from "../http/types"; import type { AgentDraft, AgentDraftCreate, AgentDraftUpdate, AgentDraftPublishBody, Agent, ListParams, Paginated, } from "../types/index"; export class AgentDraftsClient { constructor(private readonly fetcher: Fetcher) {} /** * Lists agent drafts with cursor pagination and optional DSL filtering. * * @example * ```ts * const page = await client.agentDrafts.list({ q: "status.eq:pending" }); * ``` */ list(params?: ListParams, opts?: RequestOptions): Promise> { return this.fetcher.list("/agents/drafts", params, opts); } /** * Creates a new agent draft. * * @example * ```ts * const draft = await client.agentDrafts.create({ * team_id: "team-abc", * name: "Baggage Agent v2", * kind: "task", * }); * ``` */ create(data: AgentDraftCreate, opts?: RequestOptions): Promise { return this.fetcher.post("/agents/drafts", data, opts); } /** * Gets a single agent draft by ID. * * @throws {NotFoundError} when no draft with `id` exists. */ get(id: string, opts?: RequestOptions): Promise { return this.fetcher.get(`/agents/drafts/${id}`, undefined, opts); } /** * Partially updates an agent draft. * * @throws {NotFoundError} when no draft with `id` exists. */ update(id: string, data: AgentDraftUpdate, opts?: RequestOptions): Promise { return this.fetcher.patch(`/agents/drafts/${id}`, data, opts); } /** * Deletes an agent draft. * * @throws {NotFoundError} when no draft with `id` exists. */ delete(id: string, opts?: RequestOptions): Promise { return this.fetcher.delete(`/agents/drafts/${id}`, opts); } /** * Publishes an agent draft — creates or updates the live `Agent` record. * Returns the resulting `Agent` after publish. * * @example * ```ts * const agent = await client.agentDrafts.publish(draftId, { * team_id: "team-abc", * }); * console.log("Live agent:", agent.id); * ``` * * @throws {NotFoundError} when no draft with `id` exists. */ publish(id: string, data: AgentDraftPublishBody, opts?: RequestOptions): Promise { return this.fetcher.post(`/agents/drafts/${id}/publish`, data, opts); } }