Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.9 kB ยท 89 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import { z } from "zod";
import { listPrivateLocations } from "../private-location";import type { AgentTool } from "./types";
const PER_PAGE_DEFAULT = 50;const PER_PAGE_MAX = 100;
const ListPrivateLocationsInputShape = z.object({ page: z .number() .int() .min(1) .default(1) .describe("1-indexed page number (default 1)."), perPage: z .number() .int() .min(1) .max(PER_PAGE_MAX) .default(PER_PAGE_DEFAULT) .describe( `Items per page (default ${PER_PAGE_DEFAULT}, max ${PER_PAGE_MAX}).`, ),});
// `token` is omitted โ it's the agent's bearer credential, and possession of it// grants access to monitor configs including secret request headers.const ListPrivateLocationsOutput = z.object({ items: z.array( z.object({ id: z.number().int(), name: z.string(), status: z.enum(["active", "error"]), metadata: z.record(z.string(), z.string()).nullable(), monitorIds: z.array(z.number().int()), lastSeenAt: z.string().nullable(), createdAt: z.string().nullable(), updatedAt: z.string().nullable(), }), ), pagination: z.object({ page: z.number().int(), perPage: z.number().int(), totalSize: z.number().int(), totalPages: z.number().int(), }),});
export const listPrivateLocationsTool: AgentTool< z.infer<typeof ListPrivateLocationsInputShape>, z.infer<typeof ListPrivateLocationsOutput>> = { name: "list_private_locations", description: 'List private locations (self-hosted checker agents) in this workspace, with the monitors each one runs and when it last reported in. Read-only โ agent tokens are NOT exposed. `status: "error"` means the agent is not currently healthy (it may not have reported yet or may have a stale heartbeat); use `lastSeenAt` to tell whether an agent is still alive before blaming a monitor for missing checks. `metadata` holds user-defined key/value labels.', scope: "read", destructive: false, inputSchema: ListPrivateLocationsInputShape, outputSchema: ListPrivateLocationsOutput, async run({ ctx, input }) { const { page, perPage } = input; const result = await listPrivateLocations({ ctx, input: { limit: perPage, offset: (page - 1) * perPage, }, }); return { items: result.items.map((location) => ({ id: location.id, name: location.name, status: location.status, metadata: location.metadata ?? null, monitorIds: location.monitors.map((m) => m.id), lastSeenAt: location.lastSeenAt?.toISOString() ?? null, createdAt: location.createdAt?.toISOString() ?? null, updatedAt: location.updatedAt?.toISOString() ?? null, })), pagination: { page, perPage, totalSize: result.totalSize, totalPages: Math.max(1, Math.ceil(result.totalSize / perPage)), }, }; },};