Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd6cea0c

Browse files
workflow integration
1 parent734b320 commitd6cea0c

File tree

4 files changed

+105
-25
lines changed

4 files changed

+105
-25
lines changed

‎client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx‎

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
importReact,{useState}from"react";
1+
importReact,{useContext,useState,useRef,useEffect}from"react";
22
import{
33
useExternalStoreRuntime,
44
ThreadMessageLike,
@@ -17,6 +17,9 @@ import {
1717
}from"./context/ChatContext";
1818
importstyledfrom"styled-components";
1919
import{ChatCompProps}from"../chatCompTypes";
20+
import{message}from"antd";
21+
import{EditorContext}from"@lowcoder-ee/comps/editorState";
22+
import{addComponentAction}from"../../preLoadComp/actions/componentManagement";
2023

2124
constChatContainer=styled.div<{$autoHeight?:boolean}>`
2225
display: flex;
@@ -54,26 +57,44 @@ const callYourAPI = async (params: {
5457
text:string,
5558
modelHost:string,
5659
modelType:string,
60+
sessionId:string,
5761
})=>{
58-
const{ text, modelHost, modelType}=params;
62+
const{ text, modelHost, modelType, sessionId}=params;
5963

6064
leturl=modelHost;
6165
if(modelType==="direct-llm"){
6266
url=`${modelHost}/api/chat/completions`;
6367
}
6468

69+
constresponse=awaitfetch(`${url}`,{
70+
method:"POST",
71+
body:JSON.stringify({
72+
text,
73+
sessionId,
74+
}),
75+
});
76+
77+
returnresponse.json();
6578
// Simulate API delay
66-
awaitnewPromise(resolve=>setTimeout(resolve,1500));
79+
//await new Promise(resolve => setTimeout(resolve, 1500));
6780

6881
// Simple responses
69-
return{
70-
content:"This is a mock response from your backend. You typed: "+text
71-
};
82+
//return {
83+
// content: "This is a mock response from your backend. You typed: " + text
84+
//};
7285
};
7386

7487
exportfunctionChatMain(props:ChatCompProps){
7588
const{ state, actions}=useChatContext();
7689
const[isRunning,setIsRunning]=useState(false);
90+
consteditorState=useContext(EditorContext);
91+
consteditorStateRef=useRef(editorState);
92+
93+
// Keep the ref updated with the latest editorState
94+
useEffect(()=>{
95+
console.log("EDITOR STATE CHANGE ---> ",editorState);
96+
editorStateRef.current=editorState;
97+
},[editorState]);
7798

7899
console.log("STATE",state);
79100

@@ -88,6 +109,36 @@ export function ChatMain(props: ChatCompProps) {
88109
createdAt:newDate(message.timestamp),
89110
});
90111

112+
constperformAction=async(actions:any[])=>{
113+
constcomp=editorStateRef.current.getUIComp().children.comp;
114+
if(!comp){
115+
console.error("No comp found");
116+
return;
117+
}
118+
// const layout = comp.children.layout.getView();
119+
// console.log("LAYOUT", layout);
120+
121+
for(constactionofactions){
122+
const{ action_name, action_parameters, action_payload}=action;
123+
124+
switch(action_name){
125+
case"place_component":
126+
awaitaddComponentAction.execute({
127+
actionKey:action_name,
128+
actionValue:"",
129+
actionPayload:action_payload,
130+
selectedComponent:action_parameters,
131+
selectedEditorComponent:null,
132+
editorState:editorStateRef.current
133+
});
134+
break;
135+
default:
136+
break;
137+
}
138+
awaitnewPromise(resolve=>setTimeout(resolve,1000));
139+
}
140+
};
141+
91142
constonNew=async(message:AppendMessage)=>{
92143
// Extract text from AppendMessage content array
93144
if(message.content.length!==1||message.content[0]?.type!=="text"){
@@ -112,12 +163,15 @@ export function ChatMain(props: ChatCompProps) {
112163
text:userMessage.text,
113164
modelHost:props.modelHost!,
114165
modelType:props.modelType!,
166+
sessionId:state.currentThreadId,
115167
});
116-
168+
const{reply,actions:editorActions}=JSON.parse(response?.output);
169+
performAction(editorActions);
170+
117171
constassistantMessage:MyMessage={
118172
id:generateId(),
119173
role:"assistant",
120-
text:response.content,
174+
text:reply,
121175
timestamp:Date.now(),
122176
};
123177

@@ -170,12 +224,16 @@ export function ChatMain(props: ChatCompProps) {
170224
text:editedMessage.text,
171225
modelHost:props.modelHost!,
172226
modelType:props.modelType!,
227+
sessionId:state.currentThreadId,
173228
});
174-
229+
230+
const{reply,actions:editorActions}=JSON.parse(response?.output);
231+
performAction(editorActions);
232+
175233
constassistantMessage:MyMessage={
176234
id:generateId(),
177235
role:"assistant",
178-
text:response.content,
236+
text:reply,
179237
timestamp:Date.now(),
180238
};
181239

‎client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts‎

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
deleteCompAction
1414
}from"lowcoder-core";
1515
import{getEditorComponentInfo}from"../utils";
16+
import{getPromiseAfterDispatch}from"@lowcoder-ee/util/promiseUtils";
1617

1718
exportconstaddComponentAction:ActionConfig={
1819
key:'add-components',
@@ -21,8 +22,9 @@ export const addComponentAction: ActionConfig = {
2122
requiresComponentSelection:true,
2223
requiresInput:false,
2324
execute:async(params:ActionExecuteParams)=>{
24-
const{ selectedComponent, editorState}=params;
25-
25+
const{ selectedComponent, editorState, actionPayload}=params;
26+
const{ name, layout, ...otherProps}=actionPayload;
27+
2628
if(!selectedComponent||!editorState){
2729
message.error('Component and editor state are required');
2830
return;
@@ -43,31 +45,33 @@ export const addComponentAction: ActionConfig = {
4345
return;
4446
}
4547

48+
letcompName=name;
4649
constnameGenerator=editorState.getNameGenerator();
4750
constcompInfo=parseCompType(selectedComponent);
48-
constcompName=nameGenerator.genItemName(compInfo.compName);
51+
if(!compName){
52+
compName=nameGenerator.genItemName(compInfo.compName);
53+
}
4954
constkey=genRandomKey();
5055

5156
constmanifest=uiCompRegistry[selectedComponent];
5257
letdefaultDataFn=undefined;
5358

54-
if(manifest?.lazyLoad){
55-
const{ defaultDataFnName, defaultDataFnPath}=manifest;
56-
if(defaultDataFnName&&defaultDataFnPath){
57-
constmodule=awaitimport(`../../../${defaultDataFnPath}.tsx`);
58-
defaultDataFn=module[defaultDataFnName];
59-
}
60-
}elseif(!compInfo.isRemote){
59+
if(!compInfo.isRemote){
6160
defaultDataFn=manifest?.defaultDataFn;
6261
}
6362

63+
letcompDefaultValue=defaultDataFn ?defaultDataFn(compName,nameGenerator,editorState) :undefined;
64+
constcompInitialValue={
65+
...(compDefaultValueasany||{}),
66+
...otherProps,
67+
}
6468
constwidgetValue:GridItemDataType={
6569
compType:selectedComponent,
6670
name:compName,
67-
comp:defaultDataFn ?defaultDataFn(compName,nameGenerator,editorState) :undefined,
71+
comp:compInitialValue,
6872
};
6973

70-
constcurrentLayout=simpleContainer.children.layout.getView();
74+
constcurrentLayout=uiComp.children.comp.children.layout.getView();
7175
constlayoutInfo=manifest?.layoutInfo||defaultLayout(selectedComponentasUICompType);
7276

7377
letitemPos=0;
@@ -83,9 +87,11 @@ export const addComponentAction: ActionConfig = {
8387
h:layoutInfo.h||5,
8488
pos:itemPos,
8589
isDragging:false,
90+
...(layout||{}),
8691
};
8792

88-
simpleContainer.dispatch(
93+
awaitgetPromiseAfterDispatch(
94+
uiComp.children.comp.dispatch,
8995
wrapActionExtraInfo(
9096
multiChangeAction({
9197
layout:changeValueAction({
@@ -95,8 +101,23 @@ export const addComponentAction: ActionConfig = {
95101
items:addMapChildAction(key,widgetValue),
96102
}),
97103
{compInfos:[{compName:compName,compType:selectedComponent,type:"add"}]}
98-
)
104+
),
105+
{
106+
autoHandleAfterReduce:true,
107+
}
99108
);
109+
// simpleContainer.dispatch(
110+
// wrapActionExtraInfo(
111+
// multiChangeAction({
112+
// layout: changeValueAction({
113+
// ...currentLayout,
114+
// [key]: layoutItem,
115+
// }, true),
116+
// items: addMapChildAction(key, widgetValue),
117+
// }),
118+
// { compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }]}
119+
// )
120+
// );
100121

101122
editorState.setSelectedCompNames(newSet([compName]),"addComp");
102123

‎client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface ActionConfig {
4444
exportinterfaceActionExecuteParams{
4545
actionKey:string;
4646
actionValue:string;
47+
actionPayload?:any;
4748
selectedComponent:string|null;
4849
selectedEditorComponent:string|null;
4950
selectedNestComponent:string|null;

‎client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function Bottom(props: any) {
125125
// systemPrompt="You are a helpful assistant."
126126
// agent={true}
127127
// maxInteractions={10}
128-
modelHost="http://localhost:5678/webhook-test/9a363e76-d3a5-46d1-98c3-4359f7106d33"
128+
modelHost="http://192.168.100.49:5678/webhook/9a363e76-d3a5-46d1-98c3-4359f7106d33"
129129
/>
130130
</Flex>
131131
)}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp