setup(frontend): rename frontend-react

This commit is contained in:
Nex Zhu
2025-11-20 09:41:20 +08:00
parent e40cdd1dee
commit 4fa5504697
195 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
import { api } from '@sttot/api-hooks';
import { IApiStepTask } from './generate-base-plan';
export interface IAgentSelectModifyInitRequest {
goal: string;
stepTask: IApiStepTask;
}
export interface IAgentSelectModifyAddRequest {
aspects: string[];
}
export interface IScoreItem {
reason: string;
score: number;
}
type IRawAgentSelectModifyInitResponse = Record<
string,
Record<string, { Reason: string; Score: number }>
>;
export const agentSelectModifyInitApi = api<
IAgentSelectModifyInitRequest,
Record<string, Record<string, IScoreItem>>
>(
({ goal, stepTask }) => ({
baseURL: 'api',
url: '/agentSelectModify_init',
method: 'POST',
data: {
'General Goal': goal,
stepTask: {
StepName: stepTask.name,
TaskContent: stepTask.content,
// eslint-disable-next-line @typescript-eslint/naming-convention
InputObject_List: stepTask.inputs,
OutputObject: stepTask.output,
},
},
}),
({ data }: { data: IRawAgentSelectModifyInitResponse }) =>
Object.fromEntries(
Object.entries(data).map(([agent, reasons]) => [
agent,
Object.fromEntries(
Object.entries(reasons).map(([reason, score]) => [
reason,
{
reason: score.Reason,
score: score.Score,
},
]),
),
]),
),
);
export const agentSelectModifyAddApi = api<
IAgentSelectModifyAddRequest,
Record<string, Record<string, IScoreItem>>
>(
data => ({
baseURL: 'api',
url: '/agentSelectModify_addAspect',
method: 'POST',
data: {
aspectList: data.aspects,
},
}),
({ data }: { data: IRawAgentSelectModifyInitResponse }) =>
Object.fromEntries(
Object.entries(data).map(([agent, reasons]) => [
agent,
Object.fromEntries(
Object.entries(reasons).map(([reason, score]) => [
reason,
{
reason: score.Reason,
score: score.Score,
},
]),
),
]),
),
);

View File

@@ -0,0 +1,144 @@
import { api } from '@sttot/api-hooks';
import type { IGeneratedPlan } from './generate-base-plan';
import { ActionType } from '@/storage/plan';
export interface IExecutePlanRequest {
plan: IGeneratedPlan;
stepsToRun: number;
rehearsalLog: IExecuteNode[];
}
export enum ExecuteNodeType {
Step = 'step',
Object = 'object',
}
type IExecuteRawResponse = {
LogNodeType: string;
NodeId: string;
// eslint-disable-next-line @typescript-eslint/naming-convention
InputName_List?: string[] | null;
OutputName?: string;
content?: string;
ActionHistory?: {
ID: string;
ActionType: string;
AgentName: string;
Description: string;
ImportantInput: string[];
// eslint-disable-next-line @typescript-eslint/naming-convention
Action_Result: string;
}[];
};
export interface IExecuteStepHistoryItem {
id: string;
type: ActionType;
agent: string;
description: string;
inputs: string[];
result: string;
}
export interface IExecuteStep {
type: ExecuteNodeType.Step;
id: string;
inputs: string[];
output: string;
history: IExecuteStepHistoryItem[];
}
export interface IExecuteObject {
type: ExecuteNodeType.Object;
id: string;
content: string;
}
export type IExecuteNode = IExecuteStep | IExecuteObject;
export const executePlanApi = api<IExecutePlanRequest, IExecuteNode[]>(
({ plan, stepsToRun, rehearsalLog }) => ({
baseURL: '/api',
url: '/executePlan',
method: 'POST',
timeout: Infinity,
data: {
// eslint-disable-next-line @typescript-eslint/naming-convention
num_StepToRun: Number.isFinite(stepsToRun)
? Math.max(stepsToRun, 1)
: null,
plan: {
'Initial Input Object': plan.inputs,
'General Goal': plan.goal,
'Collaboration Process': plan.process.map(step => ({
StepName: step.name,
TaskContent: step.content,
// eslint-disable-next-line @typescript-eslint/naming-convention
InputObject_List: step.inputs,
OutputObject: step.output,
AgentSelection: step.agents,
// eslint-disable-next-line @typescript-eslint/naming-convention
Collaboration_Brief_frontEnd: step.brief,
TaskProcess: step.process.map(action => ({
ActionType: action.type,
AgentName: action.agent,
Description: action.description,
ID: action.id,
ImportantInput: action.inputs,
})),
})),
},
RehearsalLog: rehearsalLog.map(h =>
h.type === ExecuteNodeType.Object
? {
LogNodeType: 'object',
NodeId: h.id,
content: h.content,
}
: {
LogNodeType: 'step',
NodeId: h.id,
// eslint-disable-next-line @typescript-eslint/naming-convention
InputName_List: h.inputs,
OutputName: h.output,
chatLog: [],
// eslint-disable-next-line @typescript-eslint/naming-convention
inputObject_Record: [],
ActionHistory: h.history.map(item => ({
ID: item.id,
ActionType: item.type,
AgentName: item.agent,
Description: item.description,
ImportantInput: item.inputs,
// eslint-disable-next-line @typescript-eslint/naming-convention
Action_Result: item.result,
})),
},
),
},
}),
({ data }) =>
data.map((raw: IExecuteRawResponse) =>
raw.LogNodeType === 'step'
? {
type: ExecuteNodeType.Step,
id: raw.NodeId,
inputs: raw.InputName_List || [],
output: raw.OutputName ?? '',
history:
raw.ActionHistory?.map(item => ({
id: item.ID,
type: item.ActionType,
agent: item.AgentName,
description: item.Description,
inputs: item.ImportantInput,
result: item.Action_Result,
})) || [],
}
: {
type: ExecuteNodeType.Object,
id: raw.NodeId,
content: raw.content || '',
},
),
);

View File

@@ -0,0 +1,61 @@
import { api } from '@sttot/api-hooks';
import { IApiStepTask, vec2Hsl, IRawStepTask } from './generate-base-plan';
export interface IFillAgentSelectionRequest {
goal: string;
stepTask: IApiStepTask;
agents: string[];
}
export const fillAgentSelectionApi = api<
IFillAgentSelectionRequest,
IApiStepTask
>(
({ goal, stepTask, agents }) => ({
baseURL: 'api',
url: '/fill_stepTask_TaskProcess',
method: 'POST',
data: {
'General Goal': goal,
// eslint-disable-next-line @typescript-eslint/naming-convention
stepTask_lackTaskProcess: {
StepName: stepTask.name,
TaskContent: stepTask.content,
// eslint-disable-next-line @typescript-eslint/naming-convention
InputObject_List: stepTask.inputs,
OutputObject: stepTask.output,
AgentSelection: agents,
},
},
}),
({ data }: { data: IRawStepTask }) => ({
name: data.StepName ?? '',
content: data.TaskContent ?? '',
inputs: data.InputObject_List ?? [],
output: data.OutputObject ?? '',
agents: data.AgentSelection ?? [],
brief: {
template: data.Collaboration_Brief_FrontEnd?.template ?? '',
data: Object.fromEntries(
Object.entries(data.Collaboration_Brief_FrontEnd?.data ?? {}).map(
([key, value]) => [
key,
{
text: value.text,
style: {
background: vec2Hsl(value.color),
},
},
],
),
),
},
process: data.TaskProcess.map(process => ({
id: process.ID,
type: process.ActionType,
agent: process.AgentName,
description: process.Description,
inputs: process.ImportantInput,
})),
}),
);

View File

@@ -0,0 +1,55 @@
import { api } from '@sttot/api-hooks';
import { IApiStepTask, IRawStepTask, vec2Hsl } from './generate-base-plan';
export interface IFillStepTaskRequest {
goal: string;
stepTask: IApiStepTask;
}
export const fillStepTaskApi = api<IFillStepTaskRequest, IApiStepTask>(
({ goal, stepTask }) => ({
baseURL: 'api',
url: '/fill_stepTask',
method: 'POST',
data: {
'General Goal': goal,
stepTask: {
StepName: stepTask.name,
TaskContent: stepTask.content,
// eslint-disable-next-line @typescript-eslint/naming-convention
InputObject_List: stepTask.inputs,
OutputObject: stepTask.output,
},
},
}),
({ data }: { data: IRawStepTask }) => ({
name: data.StepName ?? '',
content: data.TaskContent ?? '',
inputs: data.InputObject_List ?? [],
output: data.OutputObject ?? '',
agents: data.AgentSelection ?? [],
brief: {
template: data.Collaboration_Brief_FrontEnd?.template ?? '',
data: Object.fromEntries(
Object.entries(data.Collaboration_Brief_FrontEnd?.data ?? {}).map(
([key, value]) => [
key,
{
text: value.text,
style: {
background: vec2Hsl(value.color),
},
},
],
),
),
},
process: data.TaskProcess.map(process => ({
id: process.ID,
type: process.ActionType,
agent: process.AgentName,
description: process.Description,
inputs: process.ImportantInput,
})),
}),
);

View File

@@ -0,0 +1,119 @@
import { api } from '@sttot/api-hooks';
import { SxProps } from '@mui/material';
export const vec2Hsl = (vec: HslColorVector): string =>
`hsl(${vec[0]},${vec[1]}%,${vec[2]}%)`;
export interface IPlanGeneratingRequest {
goal: string;
inputs: string[];
}
export interface IRichText {
template: string;
data: Record<string, { text: string; style: SxProps }>;
}
export interface IApiAgentAction {
id: string;
type: string;
agent: string;
description: string;
inputs: string[];
}
export interface IApiStepTask {
name: string;
content: string;
inputs: string[];
output: string;
agents: string[];
brief: IRichText;
process: IApiAgentAction[];
}
export interface IGeneratedPlan {
inputs: string[];
goal: string;
process: IApiStepTask[];
}
type HslColorVector = [number, number, number];
export interface IRawStepTask {
StepName?: string;
TaskContent?: string;
// eslint-disable-next-line @typescript-eslint/naming-convention
InputObject_List?: string[];
OutputObject?: string;
AgentSelection?: string[];
// eslint-disable-next-line @typescript-eslint/naming-convention
Collaboration_Brief_FrontEnd: {
template: string;
data: Record<string, { text: string; color: HslColorVector }>;
};
TaskProcess: {
ActionType: string;
AgentName: string;
Description: string;
ID: string;
ImportantInput: string[];
}[];
}
export interface IRawPlanResponse {
'Initial Input Object'?: string[] | string;
'General Goal'?: string;
'Collaboration Process'?: IRawStepTask[];
}
export const genBasePlanApi = api<IPlanGeneratingRequest, IGeneratedPlan>(
data => ({
baseURL: '/api',
url: '/generate_basePlan',
method: 'POST',
data: {
'General Goal': data.goal,
'Initial Input Object': data.inputs,
},
timeout: Infinity,
}),
({ data }: { data: IRawPlanResponse }) => ({
inputs:
(typeof data['Initial Input Object'] === 'string'
? [data['Initial Input Object']]
: data['Initial Input Object']) || [],
goal: data['General Goal'] || '',
process:
data['Collaboration Process']?.map(step => ({
name: step.StepName || '',
content: step.TaskContent || '',
inputs: step.InputObject_List || [],
output: step.OutputObject || '',
agents: step.AgentSelection || [],
brief: {
template: step.Collaboration_Brief_FrontEnd.template,
data: Object.fromEntries(
Object.entries(step.Collaboration_Brief_FrontEnd.data).map(
([key, value]) => [
key,
{
text: value.text,
style: {
background: vec2Hsl(value.color),
},
},
],
),
),
},
process: step.TaskProcess.map(process => ({
id: process.ID,
type: process.ActionType,
agent: process.AgentName,
description: process.Description,
inputs: process.ImportantInput,
})),
})) ?? [],
}),
);

View File

@@ -0,0 +1,33 @@
import { api } from '@sttot/api-hooks';
import { IconName, IconMap } from '@/components/AgentIcon';
interface IRawAgent {
Name: string;
Profile: string;
Icon: string;
}
export interface IAgent {
name: string;
profile: string;
icon: IconName;
}
export const getAgentsApi = api<void, IAgent[]>(
() => ({
baseURL: '/api',
url: '/getAgent',
method: 'POST',
timeout: Infinity,
}),
({ data }) => {
const data_ = data as IRawAgent[];
return data_.map(agent => ({
name: agent.Name,
profile: agent.Profile,
icon: IconMap[agent.Icon.replace(/\.png$/, '')],
}));
},
);
export const useAgents = getAgentsApi.createMemoHook();

View File

@@ -0,0 +1,66 @@
import { api } from '@sttot/api-hooks';
import { IApiStepTask, IApiAgentAction } from './generate-base-plan';
export interface INewActionBranchRequest {
goal: string;
batch?: number;
requirement: string;
stepTask: IApiStepTask;
base: IApiAgentAction[];
existing: IApiAgentAction[];
}
export type INewActionBranchResponse = IApiAgentAction[][];
export const newActionBranchApi = api<
INewActionBranchRequest,
INewActionBranchResponse
>(
data => ({
baseURL: '/api',
url: '/branch_TaskProcess',
method: 'POST',
timeout: Infinity,
data: {
// eslint-disable-next-line @typescript-eslint/naming-convention
branch_Number: data.batch ?? 1,
// eslint-disable-next-line @typescript-eslint/naming-convention
Modification_Requirement: data.requirement,
// eslint-disable-next-line @typescript-eslint/naming-convention
Baseline_Completion: data.base.map(s => ({
ID: s.id,
ActionType: s.type,
AgentName: s.agent,
Description: s.description,
ImportantInput: s.inputs,
})),
// eslint-disable-next-line @typescript-eslint/naming-convention
Existing_Steps: data.existing.map(s => ({
ID: s.id,
ActionType: s.type,
AgentName: s.agent,
Description: s.description,
ImportantInput: s.inputs,
})),
'General Goal': data.goal,
stepTaskExisting: {
StepName: data.stepTask.name,
TaskContent: data.stepTask.content,
// eslint-disable-next-line @typescript-eslint/naming-convention
InputObject_List: data.stepTask.inputs,
OutputObject: data.stepTask.output,
AgentSelection: data.stepTask.agents,
},
},
}),
({ data }) =>
data.map((s: any) =>
s.map((s: any) => ({
id: s.ID,
type: s.ActionType,
agent: s.AgentName,
description: s.Description,
inputs: s.ImportantInput,
})),
),
);

View File

@@ -0,0 +1,57 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { api } from '@sttot/api-hooks';
import { IApiStepTask } from './generate-base-plan';
export interface INewPlanBranchRequest {
goal: string;
inputs: string[];
batch?: number;
requirement: string;
base: IApiStepTask[];
existing: IApiStepTask[];
}
export type INewPlanBranchResponse = IApiStepTask[][];
export const newPlanBranchApi = api<
INewPlanBranchRequest,
INewPlanBranchResponse
>(
data => ({
baseURL: '/api',
url: '/branch_PlanOutline',
method: 'POST',
timeout: Infinity,
data: {
branch_Number: data.batch ?? 1,
Modification_Requirement: data.requirement,
Baseline_Completion: data.base.map(s => ({
StepName: s.name,
TaskContent: s.content,
InputObject_List: s.inputs,
OutputObject: s.output,
})),
Existing_Steps: data.existing.map(s => ({
StepName: s.name,
TaskContent: s.content,
InputObject_List: s.inputs,
OutputObject: s.output,
})),
'General Goal': data.goal,
'Initial Input Object': data.inputs,
},
}),
({ data }) =>
data.map((s: any) =>
s.map((s: any) => ({
name: s.StepName,
content: s.TaskContent,
inputs: s.InputObject_List,
output: s.OutputObject,
agents: [],
brief: { template: '', data: {} },
process: [],
})),
),
);
/* eslint-enable @typescript-eslint/naming-convention */

View File

@@ -0,0 +1,32 @@
import { api } from '@sttot/api-hooks';
import { IconName } from '@/components/AgentIcon';
export interface IAgent {
name: string;
profile: string;
icon: IconName;
}
export const setAgentsApi = api<IAgent[], any>(
agents => ({
baseURL: '/api',
url: '/setAgents',
method: 'POST',
data: agents.map(agent => ({
Name: agent.name,
Profile: agent.profile,
})),
timeout: Infinity,
}),
({ data }) => {
// const data_ = data as IRawAgent[];
// return data_.map(agent => ({
// name: agent.Name,
// profile: agent.Profile,
// icon: IconMap[agent.Icon.replace(/\.png$/, '')],
// }));
return data;
},
);
export const setagents = setAgentsApi.createMemoHook();