import { z } from "zod" import { defineAction } from "../../../automation/actions" import { getGoogleMeetApi, getGoogleMeetSpaceConfigUpdateMask, GOOGLE_MEET_SPACE_CONFIG_SCHEMA, GOOGLE_MEET_SPACE_REFERENCE_SCHEMA, GOOGLE_MEET_SPACE_SCHEMA, normalizeGoogleMeetSpace, normalizeGoogleMeetSpaceName, toGoogleMeetSpaceConfig, } from "@automate.ax/integration-contracts/google-meet" import { GOOGLE_MEET_CREATE_REQUIREMENT, GOOGLE_MEET_SPACE_READ_REQUIREMENT, GOOGLE_MEET_SPACE_WRITE_REQUIREMENT, } from "../lib/scopes" /** Creates a reusable Google Meet meeting space. */ export const createGoogleMeetSpace = defineAction("Create Google Meet space") .describe( "Creates a meeting space with optional access and artifact settings.", ) .account("google", GOOGLE_MEET_CREATE_REQUIREMENT) .input( z.object({ /** Access, moderation, attendance, and automatic artifact settings. */ config: GOOGLE_MEET_SPACE_CONFIG_SCHEMA.optional(), }), ) .output(GOOGLE_MEET_SPACE_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => { const { data } = await getGoogleMeetApi(account.secret).spaces.create({ requestBody: { config: input.config ? toGoogleMeetSpaceConfig(input.config) : undefined, }, }) return normalizeGoogleMeetSpace(data) }) /** Retrieves one meeting space by resource name, code, ID, or Meet URL. */ export const getGoogleMeetSpace = defineAction("Get Google Meet space") .describe("Gets current access details, configuration, and join methods.") .account("google", GOOGLE_MEET_SPACE_READ_REQUIREMENT) .input( z.object({ /** Space resource name, meeting code, opaque space ID, or Meet URL. */ space: GOOGLE_MEET_SPACE_REFERENCE_SCHEMA, }), ) .output(GOOGLE_MEET_SPACE_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => { const { data } = await getGoogleMeetApi(account.secret).spaces.get({ name: normalizeGoogleMeetSpaceName(input.space), }) return normalizeGoogleMeetSpace(data) }) /** Updates selected settings on an existing meeting space. */ export const updateGoogleMeetSpace = defineAction("Update Google Meet space") .describe("Patches selected access, moderation, and artifact settings.") .account("google", GOOGLE_MEET_SPACE_WRITE_REQUIREMENT) .input( z.object({ /** Settings to patch. Omitted settings remain unchanged. */ config: GOOGLE_MEET_SPACE_CONFIG_SCHEMA, /** Stable space resource name or opaque space ID. */ space: GOOGLE_MEET_SPACE_REFERENCE_SCHEMA, }), ) .output(GOOGLE_MEET_SPACE_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => { const name = normalizeGoogleMeetSpaceName(input.space) const updateMask = getGoogleMeetSpaceConfigUpdateMask(input.config) if (!updateMask) throw new Error("Provide at least one Google Meet setting.") const { data } = await getGoogleMeetApi(account.secret).spaces.patch({ name, requestBody: { config: toGoogleMeetSpaceConfig(input.config), name }, updateMask, }) return normalizeGoogleMeetSpace(data) }) /** Ends the active conference in a space, if one is running. */ export const endGoogleMeetConference = defineAction( "End Google Meet conference", ) .describe("Ends the active call in an app-created meeting space.") .account("google", GOOGLE_MEET_CREATE_REQUIREMENT) .input( z.object({ /** Stable space resource name or opaque space ID. */ space: GOOGLE_MEET_SPACE_REFERENCE_SCHEMA, }), ) .output(z.object({ space: z.string() })) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => { const space = normalizeGoogleMeetSpaceName(input.space) await getGoogleMeetApi(account.secret).spaces.endActiveConference({ name: space, }) return { space } })