fix: restore microdao api functions and update types

This commit is contained in:
Apple
2025-11-28 10:25:03 -08:00
parent cbd5b2f731
commit 3f53038cf7
2 changed files with 58 additions and 0 deletions

View File

@@ -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<MicrodaoOption[]> {
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<void> {
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<void> {
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");
}
}

View File

@@ -112,6 +112,8 @@ export interface MicrodaoOption {
id: string;
slug: string;
name: string;
district?: string | null;
is_active?: boolean;
}
// =============================================================================