forked from longtao.wu/droboticflow
Replace plain-text replies with react-markdown and GFM tables, lists, code and safe links. Recognize complete topology fences, JSON fences and standalone graph data in source order without promoting ordinary JSON. Render escaped SVG elements with cycle-safe layouts, zoom, node details and accessible data tables; show incomplete graphs as recoverable errors. Preserve finish_reason=length, prevent truncated tool calls from executing, and give concise topology replies a 4096-token budget. Tighten the prompt to return bounded, closed diagrams rather than an exhaustive node dump. Add parser, model-completion and isolated browser regression coverage. Fix existing frontend type declarations exposed by the React types now provided with react-markdown, without changing workflow execution. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
122 lines
3.1 KiB
TypeScript
122 lines
3.1 KiB
TypeScript
import { apiRequest } from "./client";
|
|
import type { Edge, Node } from "reactflow";
|
|
import type {
|
|
HyperParam,
|
|
PortTransmission,
|
|
PortType,
|
|
ScanConfig,
|
|
WorkflowKind,
|
|
WorkflowSchedule,
|
|
WorkflowType,
|
|
} from "../../types";
|
|
|
|
export interface AIStatus {
|
|
enabled: boolean;
|
|
provider: string;
|
|
baseURL?: string;
|
|
model?: string;
|
|
reason?: string;
|
|
operatorGeneration?: {
|
|
enabled: boolean;
|
|
ready: boolean;
|
|
reason?: string;
|
|
missingFields?: string[];
|
|
};
|
|
}
|
|
|
|
export interface GeneratedWorkflow {
|
|
name: string;
|
|
description: string;
|
|
type?: WorkflowType;
|
|
kind?: WorkflowKind;
|
|
scanConfig?: ScanConfig;
|
|
hyperparams?: HyperParam[];
|
|
maxConcurrentRuns?: number;
|
|
nodeTimeoutSeconds?: number;
|
|
runTimeoutSeconds?: number;
|
|
maxRetryAttempts?: number;
|
|
retryBackoffSeconds?: number;
|
|
schedule?: WorkflowSchedule;
|
|
nodes: Node[];
|
|
edges: Edge[];
|
|
}
|
|
|
|
export interface GeneratedOperator {
|
|
name: string;
|
|
category: string;
|
|
description: string;
|
|
version?: string;
|
|
image?: string;
|
|
imageId?: string;
|
|
containerCommand?: string[];
|
|
containerArgs?: string[];
|
|
runtimeContract?: Record<string, unknown>;
|
|
resources?: {
|
|
cpuRequest?: string;
|
|
cpuLimit?: string;
|
|
memoryRequest?: string;
|
|
memoryLimit?: string;
|
|
gpuType?: string;
|
|
gpuLimit?: string;
|
|
sharedMemorySize?: string;
|
|
};
|
|
inputs: { name: string; type: PortType; transmission: PortTransmission; description?: string }[];
|
|
outputs: { name: string; type: PortType; transmission: PortTransmission; description?: string }[];
|
|
hyperparams: HyperParam[];
|
|
skillDefinition: string;
|
|
publicationStatus?: "draft" | "built" | "verified" | "published";
|
|
generationSource?: "manual" | "ai";
|
|
publicationEvidence?: {
|
|
repositoryUrl?: string;
|
|
repositoryCommit?: string;
|
|
image?: string;
|
|
imageId?: string;
|
|
fixtureChecksum?: string;
|
|
testCommand?: string;
|
|
acceptanceProjectId?: string;
|
|
acceptanceWorkflowId?: string;
|
|
acceptanceRunId?: string;
|
|
verifiedAt?: string;
|
|
verifiedBy?: string;
|
|
};
|
|
implementation?: {
|
|
repositoryPath: string;
|
|
repositoryName?: string;
|
|
repositoryURL?: string;
|
|
files: { path: string; description: string; content: string }[];
|
|
buildCommands: string[];
|
|
acceptanceChecklist: 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 }),
|
|
};
|