import { defineAction } from "../../../automation/actions" import { getGmailApi, toGmailLabel, } from "@automate.ax/integration-contracts/gmail" import { GMAIL_LABELS_READ_REQUIREMENT } from "../lib/scopes" import { LABEL_SCHEMA } from "@automate.ax/integration-contracts/gmail" /** Lists all Gmail system and user labels with available counts and colors. */ export const listGmailLabels = defineAction("List Gmail labels") .describe("Lists Gmail labels with visibility, count, and color metadata.") .account("google", GMAIL_LABELS_READ_REQUIREMENT) .output(LABEL_SCHEMA.array()) .retry({ replaySafety: "safe" }) .handler(async ({ account }) => { const { data } = await getGmailApi(account.secret).users.labels.list({ userId: "me", }) return (data.labels ?? []).map(toGmailLabel) })