chore: sync from fn-registry agent
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import type { Board, Card, Column, HistoryEntry } from "./types";
|
||||
|
||||
const BASE = "/api";
|
||||
|
||||
async function fetchJSON<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const res = await fetch(`${BASE}${path}`, {
|
||||
...init,
|
||||
headers: { "Content-Type": "application/json", ...(init?.headers || {}) },
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({ Message: res.statusText }));
|
||||
throw new Error(err.Message || err.message || res.statusText);
|
||||
}
|
||||
if (res.status === 204) return undefined as T;
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export function getBoard(): Promise<Board> {
|
||||
return fetchJSON("/board");
|
||||
}
|
||||
|
||||
export function createColumn(name: string): Promise<Column> {
|
||||
return fetchJSON("/columns", { method: "POST", body: JSON.stringify({ name }) });
|
||||
}
|
||||
|
||||
export interface UpdateColumnInput {
|
||||
name?: string;
|
||||
position?: number;
|
||||
location?: "board" | "sidebar";
|
||||
width?: number;
|
||||
}
|
||||
|
||||
export function updateColumn(id: string, patch: UpdateColumnInput): Promise<void> {
|
||||
return fetchJSON(`/columns/${id}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(patch),
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteColumn(id: string): Promise<void> {
|
||||
return fetchJSON(`/columns/${id}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function reorderColumns(ids: string[]): Promise<void> {
|
||||
return fetchJSON("/columns/reorder", { method: "POST", body: JSON.stringify({ ids }) });
|
||||
}
|
||||
|
||||
export interface CreateCardInput {
|
||||
column_id: string;
|
||||
requester?: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export function createCard(input: CreateCardInput): Promise<Card> {
|
||||
return fetchJSON("/cards", { method: "POST", body: JSON.stringify(input) });
|
||||
}
|
||||
|
||||
export interface UpdateCardInput {
|
||||
requester?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
export function updateCard(id: string, patch: UpdateCardInput): Promise<void> {
|
||||
return fetchJSON(`/cards/${id}`, { method: "PATCH", body: JSON.stringify(patch) });
|
||||
}
|
||||
|
||||
export function deleteCard(id: string): Promise<void> {
|
||||
return fetchJSON(`/cards/${id}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function moveCard(id: string, column_id: string, ordered_ids: string[]): Promise<void> {
|
||||
return fetchJSON(`/cards/${id}/move`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ column_id, ordered_ids }),
|
||||
});
|
||||
}
|
||||
|
||||
export function cardHistory(id: string): Promise<HistoryEntry[]> {
|
||||
return fetchJSON(`/cards/${id}/history`);
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
role: "user" | "assistant";
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface ChatToolCall {
|
||||
tool: string;
|
||||
ok: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface ChatResponse {
|
||||
role: "assistant";
|
||||
content: string;
|
||||
board_changed: boolean;
|
||||
tool_calls?: ChatToolCall[];
|
||||
}
|
||||
|
||||
export function sendChat(messages: ChatMessage[]): Promise<ChatResponse> {
|
||||
return fetchJSON("/chat", { method: "POST", body: JSON.stringify({ messages }) });
|
||||
}
|
||||
Reference in New Issue
Block a user