/** * The shared executor behind every write. * * Replaces the earlier executeAction, which hardcoded POST and the * `/v1/alerts/{id}/` prefix and so could express only four of the API's writes. * The invariant it existed to protect is unchanged: JSM applies alert actions * asynchronously and returns a receipt rather than the updated object, and one * executor is what guarantees every write reports that receipt identically and * points at jsm_get_request_status. A tool that renders its own response * teaches the model an inconsistent contract, and it starts believing writes * have landed when they have not. * * What is new is that asynchrony is now a parameter rather than an assumption. * Alert actions are asynchronous; note edits and every configuration write are * not. Telling the model to poll a request id that was never issued is its own * way of teaching a false contract, so `mode` has to be stated per tool. */ import { type JsmClient } from "../services/client.js"; import { type ToolResult } from "../services/format.js"; export type WriteMode = /** 202-style receipt: {result, requestId}, change applied out of band. */ "async" /** The response body is the updated object. */ | "sync" /** 204 with no body. */ | "deleted" /** * 204 with no body, on an endpoint that did not delete anything. * * Split from "deleted" because the structured payload is read by a model: * reporting `deleted: true` after reordering a routing rule is how a caller * ends up telling someone the rule was removed. The reorder endpoints are * the ones this exists for — they answer 204, and declaring the updated * object as their output made every call fail output validation with * "expected object, received string", which is what an empty body * deserialises to. */ | "confirmed"; export interface WriteOptions { /** Human label for the action, used in the receipt and in error messages. */ label: string; /** * GET is here for exactly one endpoint: the heartbeat ping, * GET /v1/teams/{teamId}/heartbeats/ping, which mutates state — it resets * the timer and clears a firing alert. It is a write however it is spelled, * and routing it through here is what keeps its annotations and its error * handling consistent with every other write. */ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; /** The full path below the cloud-id root, e.g. "/v1/alerts/{id}/snooze". */ path: string; body?: unknown; params?: Record | undefined; mode: WriteMode; /** * What was written: `key` names the field echoed into the structured payload, * `noun` is the word the receipt uses, `value` is the id. * e.g. { key: "alert_id", noun: "alert", value: id }. */ subject?: { key: string; value?: string | undefined; noun: string; }; /** Required for mode "sync": renders the object the API returned. */ render?: (data: T) => string; /** * Optional for mode "sync": builds the structured payload from the response. * The default spreads the response's own fields alongside the subject, which * suits a tool whose output schema names those fields. A tool that reports * the object under a single key — as the resource factory's create and update * do, to match its get — needs to say so, or the SDK rejects the result * against its own declared output schema. */ structured?: (data: T) => Record; } export declare function executeWrite(client: JsmClient, options: WriteOptions): Promise; //# sourceMappingURL=execute-write.d.ts.map