/** * Shared response shaping: markdown rendering, truncation, and the * text+structuredContent envelope every tool returns. */ import { type Directory } from "./directory.js"; import { ResponseFormat } from "../schemas/common.js"; import type { Alert, AlertAttachment, AlertLog, AlertNote, AsyncActionResponse, OnCallData, OnCallParticipant, PaginationMeta, ResolvedIdentity, Schedule } from "../types.js"; /** * NOTE: a type alias, not an interface. The SDK's CallToolResult carries an * index signature, and TypeScript only grants an implicit one to type * aliases — declaring this as an interface makes every registerTool callback * fail to typecheck. */ export type ToolResult = { content: Array<{ type: "text"; text: string; }>; structuredContent?: Record; isError?: boolean; }; /** Success envelope: text for the model to read, structured data for the client. */ export declare function ok(text: string, structured?: Record): ToolResult; /** Error envelope. Reported in-result (not as a protocol error) per MCP guidance. */ export declare function fail(text: string): ToolResult; /** * Guards against dumping a huge payload into the context window. Trims the * item list in half until it fits, and says how to get the rest. */ export declare function withCharacterLimit(items: T[], render: (items: T[]) => string, hint: string): { text: string; truncated: boolean; kept: number; }; export interface PaginationInput { /** Records actually included in the response, after any truncation. */ returned: number; /** Records the API returned for this page, before truncation. */ fetched: number; limit: number; offset?: number | undefined; totalCount?: number | undefined; nextCursor?: string | undefined; /** * The `links.next` the API returned for this page, if any. Authoritative: * the API knows whether more records exist and we do not. */ nextLink?: string | undefined; /** * True when the endpoint accepts no paging parameters, so there is no later * page to fetch however full this one looks. */ unpaged?: boolean | undefined; } /** * Pulls one query parameter out of an API `links.next` value. * * The API returns a whole relative URL there — "/v1/alerts/{id}/notes?after=149…" * — not a bare cursor. Handing that straight back as `next_cursor` invites the * caller to send the entire URL as their `after` parameter, so extract the part * that is actually re-sendable. */ export declare function extractLinkParam(link: string | undefined, name: string): string | undefined; /** * Builds the standard pagination block returned by every list tool. * * Takes `returned` and `fetched` separately on purpose. Reporting the fetched * count while shipping the truncated list would make `next_offset` skip past * every record that truncation dropped, losing them silently — so `count` and * `next_offset` are both derived from what the caller actually received. */ export declare function buildPagination({ returned, fetched, limit, offset, totalCount, nextCursor, nextLink, unpaged, }: PaginationInput): PaginationMeta; /** * Result envelope for a list tool that found nothing. * * Exists because `ok(text)` alone is a trap: every list tool declares an * outputSchema, and the SDK rejects a non-error result that carries no * structuredContent. An empty page is an ordinary answer, not an error, so it * has to ship a valid — but empty — structured payload. */ export declare function emptyResult(text: string, key: string, limit: number, offset?: number): ToolResult; /** * Result envelope for a write that removed something and got 204 back. * * Exists for the same reason emptyResult does: the tool declares an * outputSchema, so `ok(text)` with no structuredContent is rejected outright by * the SDK. A body-less success still has to ship a structured payload. */ export declare function renderDeleted(label: string, subject?: { key: string; value?: string | undefined; noun: string; }): ToolResult; /** * Confirms a 204 that changed something without removing it. * * Deliberately not renderDeleted with a different word: the structured payload * carries `confirmed`, not `deleted`, because a model reading `deleted: true` * after a reorder will say the thing was deleted. */ export declare function renderConfirmed(label: string, subject?: { key: string; value?: string | undefined; noun: string; }): ToolResult; /** One-line summary used in list views. */ export declare function renderAlertLine(alert: Alert): string; /** Full detail view used by jsm_get_alert. */ export declare function renderAlertDetail(alert: Alert, directory?: Directory): string; export declare function renderNotes(notes: AlertNote[]): string; /** Single-note view, used after an edit so the caller sees what the note now says. */ export declare function renderNote(note: AlertNote): string; export declare function renderAttachments(attachments: AlertAttachment[]): string; export declare function renderLogs(logs: AlertLog[]): string; export declare function renderSchedules(schedules: Schedule[], teams?: Map): string; /** * Walks the nested participant tree into a flat list of {id, type}. * * `noone` is the API's sentinel for an unfilled slot in a rotation — it is a * real enum value, not a responder, and rendering it would put a uuid where a * person should be. */ export declare function flattenParticipants(participants: OnCallParticipant[]): Responder[]; /** * Pulls the responders out of an on-call response, whichever shape it arrived in. * * `flat=true` returns bare ids under `onCallUsers`/`nextOnCallUsers`; * `flat=false` returns the participant tree. The `*Recipients` fallbacks are * the Opsgenie names — reading ONLY those is what made this tool report * "Nobody is on-call" for a schedule that had someone on it, so the documented * name is read first and the legacy one is a fallback, never the reverse. */ export declare function extractOnCall(data: OnCallData, next: boolean): Responder[]; /** * One responder as the API described it, before any directory lookup. * * `name` is only ever populated by a legacy Opsgenie-shaped response; JSM * Operations sends ids alone, which is why resolution exists. */ export interface Responder { id: string; type?: string; name?: string; /** * Set when this person is listed because they forwarded their shift. Kept * separate from `type` so the responder is still a *user* for lookup * purposes — overloading `type` with "forwarded" meant the forwarding * person was the one name on the page that never got resolved. */ forwarded?: boolean; } /** * Merges what the API said about a responder with what the directory lookup * found, so the markdown and the structured payload cannot disagree. * * A name the API itself supplied is used when the lookup found nothing — * dropping it would be a regression for any tenant still on the legacy shape. */ export declare function identifyResponders(responders: Responder[], directory?: Directory): ResolvedIdentity[]; export interface OnCallRenderOptions { /** What to call the schedule in the heading. The API returns no name here. */ scheduleLabel: string; /** Resolved responder names, where the directory lookup found any. */ directory?: Directory; /** * The shift these responders are covering. Its absence is why the on-call * tools could not answer "when does this end?" before. */ shift?: ShiftSummary; /** Anything the reader needs to know about what could not be determined. */ notes?: string[]; /** Opsgenie's `exactNextOnCallTime`, when a tenant still sends it. */ legacyShiftStart?: string | undefined; } /** The boundary information a shift contributes to an answer. */ export interface ShiftSummary { start?: string; end?: string; rotationName?: string; type?: string; forwardedFrom?: { id?: string; }; } /** * Renders a shift's boundaries. * * Both ends are stated explicitly rather than as a duration: "until 09:00 UTC * tomorrow" is what a handover message needs, and a relative figure goes stale * the moment it is written down. */ export declare function renderShift(shift: ShiftSummary, next: boolean): string[]; /** * Renders an on-call answer. * * Takes the responders rather than the raw payload on purpose: they may have * come from the timeline rather than the on-call endpoint, and re-deriving them * here from a payload the caller might not have used would quietly disagree * with the structured output sitting beside it. */ export declare function renderOnCall(responders: Responder[], next: boolean, options: OnCallRenderOptions): string; export interface TimelineRenderOptions { scheduleLabel: string; directory?: Directory; } /** One period of a rotation, as the timeline tool renders it. */ export interface RenderableShift extends ShiftSummary { responders: Array<{ id?: string; type?: string; }>; } export declare function renderTimeline(shifts: RenderableShift[], options: TimelineRenderOptions): string; /** * Mutating endpoints return an async receipt rather than the updated alert. * Every write tool renders it the same way so the agent learns the pattern. */ export declare function renderAsyncReceipt(action: string, subject: { noun: string; id?: string | undefined; }, response: AsyncActionResponse): string; export declare function renderFormat(format: ResponseFormat, markdown: string, structured: Record): ToolResult; //# sourceMappingURL=format.d.ts.map