56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { apiRequest } from "./client";
|
|
|
|
export interface AIStatus {
|
|
enabled: boolean;
|
|
provider: string;
|
|
baseURL?: string;
|
|
model?: string;
|
|
reason?: string;
|
|
}
|
|
|
|
export interface GeneratedWorkflow {
|
|
name: string;
|
|
description: string;
|
|
nodes: any[];
|
|
edges: any[];
|
|
}
|
|
|
|
export interface GeneratedOperator {
|
|
name: string;
|
|
category: string;
|
|
description: string;
|
|
inputs: { name: string; type: string; transmission: string; description?: string }[];
|
|
outputs: { name: string; type: string; transmission: string; description?: string }[];
|
|
hyperparams: { key: string; value: string; description?: string; type?: string }[];
|
|
skillDefinition: string;
|
|
}
|
|
|
|
let statusCache: AIStatus | null = null;
|
|
let statusPromise: Promise<AIStatus> | null = null;
|
|
|
|
async function loadStatus(force = false) {
|
|
if (!force && statusCache) {
|
|
return statusCache;
|
|
}
|
|
if (!force && statusPromise) {
|
|
return statusPromise;
|
|
}
|
|
statusPromise = apiRequest<AIStatus>("/api/ai/status").then((status) => {
|
|
statusCache = status;
|
|
statusPromise = null;
|
|
return status;
|
|
}).catch((error) => {
|
|
statusPromise = null;
|
|
throw error;
|
|
});
|
|
return statusPromise;
|
|
}
|
|
|
|
export const aiApi = {
|
|
status: (force = false) => loadStatus(force),
|
|
generateWorkflow: (description: string) =>
|
|
apiRequest<GeneratedWorkflow>("/api/ai/workflows/generate", { method: "POST" }, { description }),
|
|
generateOperator: (description: string) =>
|
|
apiRequest<GeneratedOperator>("/api/ai/operators/generate", { method: "POST" }, { description }),
|
|
};
|