diff --git a/apps/web/src/lib/api/microdao.ts b/apps/web/src/lib/api/microdao.ts index 667a6de5..feb01e90 100644 --- a/apps/web/src/lib/api/microdao.ts +++ b/apps/web/src/lib/api/microdao.ts @@ -2,6 +2,8 @@ * MicroDAO API Client (Task 029) */ +import { MicrodaoOption } from "@/lib/types/microdao"; + // ============================================================================= // Types // ============================================================================= @@ -19,6 +21,12 @@ export interface MicrodaoVisibilityResponse { is_platform: boolean; } +export interface AssignAgentPayload { + microdao_id: string; + role?: string; + is_core?: boolean; +} + // ============================================================================= // API Functions // ============================================================================= @@ -44,3 +52,51 @@ export async function updateMicrodaoVisibility( return json; } + +/** + * Fetch available MicroDAO options for dropdown + */ +export async function fetchMicrodaoOptions(): Promise { + const res = await fetch("/api/microdao/options"); + if (!res.ok) { + throw new Error("Failed to load MicroDAO options"); + } + return res.json(); +} + +/** + * Assign agent to MicroDAO + */ +export async function assignAgentToMicrodao( + agentId: string, + payload: AssignAgentPayload +): Promise { + const res = await fetch(`/api/agents/${encodeURIComponent(agentId)}/microdao-membership`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(payload), + }); + + if (!res.ok) { + const error = await res.json().catch(() => ({})); + throw new Error(error.detail || error.error || "Failed to assign MicroDAO"); + } +} + +/** + * Remove agent from MicroDAO + */ +export async function removeAgentFromMicrodao( + agentId: string, + microdaoId: string +): Promise { + const res = await fetch( + `/api/agents/${encodeURIComponent(agentId)}/microdao-membership/${encodeURIComponent(microdaoId)}`, + { method: "DELETE" } + ); + + if (!res.ok) { + const error = await res.json().catch(() => ({})); + throw new Error(error.detail || error.error || "Failed to remove MicroDAO membership"); + } +} diff --git a/apps/web/src/lib/types/microdao.ts b/apps/web/src/lib/types/microdao.ts index 00d0c22f..045a5df4 100644 --- a/apps/web/src/lib/types/microdao.ts +++ b/apps/web/src/lib/types/microdao.ts @@ -112,6 +112,8 @@ export interface MicrodaoOption { id: string; slug: string; name: string; + district?: string | null; + is_active?: boolean; } // =============================================================================