import { api, detachInflightGet } from "./client"; import type { MuseInvitation, MuseInvitationInput, MuseConnection, MusePairing, MusePairingInput, MuseVerifyInput, MuseVerifyResult, MuseRevokeInput, MuseDetectorCleanupAttestationInput, MuseAttestStopInput, } from "@paperclipai/shared"; const path = (companyId: string, agentId: string) => `/companies/${companyId}/agents/${agentId}/muse-binding`; function accountScopedRead(path: string, signal?: AbortSignal) { // Query keys carry the operator. Path-only GET coalescing must not join a // request issued under the previous account; React Query handles same-key reads. detachInflightGet(path); return api.get(path, { signal, cache: "no-store" }); } export const museInvitationsApi = { resume: (companyId: string, signal?: AbortSignal) => accountScopedRead(`/companies/${companyId}/muse-invitations`, signal), create: (companyId: string, input: MuseInvitationInput) => api.post(`/companies/${companyId}/muse-invitations`, input), connection: (companyId: string, agentId: string, signal?: AbortSignal) => accountScopedRead(path(companyId, agentId), signal), pair: (companyId: string, agentId: string, input: MusePairingInput) => api.post(path(companyId, agentId), input), verify: (companyId: string, agentId: string, input: MuseVerifyInput) => api.post(path(companyId, agentId) + "/verify", input), revoke: (companyId: string, agentId: string, input: MuseRevokeInput) => api.post(path(companyId, agentId) + "/revoke", input), attestDetectorCleanup: (companyId: string, agentId: string, input: MuseDetectorCleanupAttestationInput) => api.post(path(companyId, agentId) + "/attest-detector-cleanup", input), attestStop: (companyId: string, agentId: string, input: MuseAttestStopInput) => api.post(path(companyId, agentId) + "/attest-stop", input), };