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

Commit7ff7a14

Browse files
committed
Merge branch 'release/0.1.0'
2 parents53e2c70 +b4939b0 commit7ff7a14

File tree

5 files changed

+362
-2
lines changed

5 files changed

+362
-2
lines changed

‎.dockerignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dist/
6060
downloads/
6161
eggs/
6262
.eggs/
63-
lib/
63+
#lib/
6464
lib64/
6565
parts/
6666
sdist/

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dist/
1111
downloads/
1212
eggs/
1313
.eggs/
14-
lib/
14+
#lib/
1515
lib64/
1616
parts/
1717
sdist/

‎frontend/lib/env.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import{env}from'next-runtime-env';
2+
3+
exportconstgetEnv=(key:string,defaultValue?:string):string=>{
4+
try{
5+
constvalue=env(key);
6+
returnvalue||defaultValue||'';
7+
}catch(error){
8+
console.error(`Error getting environment variable${key}:`,error);
9+
returndefaultValue||'';
10+
}
11+
};
12+
13+
exportconstgetApiUrl=():string=>{
14+
returngetEnv('NEXT_PUBLIC_API_URL','https://api-evoai.evoapicloud.com');
15+
};

‎frontend/lib/file-utils.ts‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
┌──────────────────────────────────────────────────────────────────────────────┐
3+
│ @author: Davidson Gomes │
4+
│ @file: /lib/file-utils.ts │
5+
│ Developed by: Davidson Gomes │
6+
│ Creation date: August 24, 2025 │
7+
│ Contact: contato@evolution-api.com │
8+
├──────────────────────────────────────────────────────────────────────────────┤
9+
│ @copyright © Evolution API 2025. All rights reserved. │
10+
│ Licensed under the Apache License, Version 2.0 │
11+
│ │
12+
│ You may not use this file except in compliance with the License. │
13+
│ You may obtain a copy of the License at │
14+
│ │
15+
│ http://www.apache.org/licenses/LICENSE-2.0 │
16+
│ │
17+
│ Unless required by applicable law or agreed to in writing, software │
18+
│ distributed under the License is distributed on an "AS IS" BASIS, │
19+
│ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │
20+
│ See the License for the specific language governing permissions and │
21+
│ limitations under the License. │
22+
├──────────────────────────────────────────────────────────────────────────────┤
23+
│ @important │
24+
│ For any future changes to the code in this file, it is recommended to │
25+
│ include, together with the modification, the information of the developer │
26+
│ who changed it and the date of modification. │
27+
└──────────────────────────────────────────────────────────────────────────────┘
28+
*/
29+
30+
exportinterfaceFileData{
31+
filename:string;
32+
content_type:string;
33+
data:string;
34+
size:number;
35+
preview_url?:string;
36+
}
37+
38+
exportfunctionfileToBase64(file:File):Promise<string>{
39+
returnnewPromise((resolve,reject)=>{
40+
constreader=newFileReader();
41+
reader.readAsDataURL(file);
42+
reader.onload=()=>{
43+
constbase64=reader.resultasstring;
44+
constbase64Data=base64.split(',')[1];
45+
resolve(base64Data);
46+
};
47+
reader.onerror=error=>reject(error);
48+
});
49+
}
50+
51+
exportasyncfunctionfileToFileData(file:File):Promise<FileData>{
52+
constbase64Data=awaitfileToBase64(file);
53+
constpreviewUrl=URL.createObjectURL(file);
54+
55+
return{
56+
filename:file.name,
57+
content_type:file.type,
58+
data:base64Data,
59+
size:file.size,
60+
preview_url:previewUrl
61+
};
62+
}
63+
64+
exportfunctionformatFileSize(bytes:number):string{
65+
if(bytes===0){
66+
return'0 Bytes';
67+
}
68+
69+
constsizes=['Bytes','KB','MB','GB','TB'];
70+
consti=Math.floor(Math.log(bytes)/Math.log(1024));
71+
72+
returnparseFloat((bytes/Math.pow(1024,i)).toFixed(2))+' '+sizes[i];
73+
}
74+
75+
exportfunctionisImageFile(mimeType:string):boolean{
76+
returnmimeType.startsWith('image/');
77+
}
78+
79+
exportfunctionisPdfFile(mimeType:string):boolean{
80+
returnmimeType==='application/pdf';
81+
}
82+
83+
exportfunctiongetFileIcon(mimeType:string):string{
84+
if(isImageFile(mimeType)){
85+
return'image';
86+
}
87+
if(isPdfFile(mimeType)){
88+
return'file-text';
89+
}
90+
if(mimeType.includes('word')){
91+
return'file-text';
92+
}
93+
if(mimeType.includes('excel')||mimeType.includes('spreadsheet')){
94+
return'file-spreadsheet';
95+
}
96+
if(mimeType.includes('presentation')||mimeType.includes('powerpoint')){
97+
return'file-presentation';
98+
}
99+
if(mimeType.includes('text/')){
100+
return'file-text';
101+
}
102+
if(mimeType.includes('audio/')){
103+
return'file-audio';
104+
}
105+
if(mimeType.includes('video/')){
106+
return'file-video';
107+
}
108+
109+
return'file';
110+
}

‎frontend/lib/utils.ts‎

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
/*
2+
┌──────────────────────────────────────────────────────────────────────────────┐
3+
│ @author: Davidson Gomes │
4+
│ @file: /lib/utils.ts │
5+
│ Developed by: Davidson Gomes │
6+
│ Creation date: May 13, 2025 │
7+
│ Contact: contato@evolution-api.com │
8+
├──────────────────────────────────────────────────────────────────────────────┤
9+
│ @copyright © Evolution API 2025. All rights reserved. │
10+
│ Licensed under the Apache License, Version 2.0 │
11+
│ │
12+
│ You may not use this file except in compliance with the License. │
13+
│ You may obtain a copy of the License at │
14+
│ │
15+
│ http://www.apache.org/licenses/LICENSE-2.0 │
16+
│ │
17+
│ Unless required by applicable law or agreed to in writing, software │
18+
│ distributed under the License is distributed on an "AS IS" BASIS, │
19+
│ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │
20+
│ See the License for the specific language governing permissions and │
21+
│ limitations under the License. │
22+
├──────────────────────────────────────────────────────────────────────────────┤
23+
│ @important │
24+
│ For any future changes to the code in this file, it is recommended to │
25+
│ include, together with the modification, the information of the developer │
26+
│ who changed it and the date of modification. │
27+
└──────────────────────────────────────────────────────────────────────────────┘
28+
*/
29+
import{clsx,typeClassValue}from"clsx";
30+
import{twMerge}from"tailwind-merge";
31+
32+
exportfunctioncn(...inputs:ClassValue[]){
33+
returntwMerge(clsx(inputs));
34+
}
35+
36+
exportfunctiongetAccessTokenFromCookie(){
37+
if(typeofdocument==="undefined")return"";
38+
constmatch=document.cookie.match(/(?:^|;)access_token=([^;]*)/);
39+
returnmatch ?decodeURIComponent(match[1]) :"";
40+
}
41+
42+
/**
43+
* Obtém um parâmetro específico da URL atual
44+
*/
45+
exportfunctiongetQueryParam(param:string):string|null{
46+
if(typeofwindow==="undefined")returnnull;
47+
consturlParams=newURLSearchParams(window.location.search);
48+
returnurlParams.get(param);
49+
}
50+
51+
/**
52+
* Sanitizes the agent name by removing accents,
53+
* replacing spaces with underscores and removing special characters
54+
*/
55+
exportfunctionsanitizeAgentName(name:string):string{
56+
// Remove accents (normalize to basic form without combined characters)
57+
constwithoutAccents=name.normalize("NFD").replace(/[\u0300-\u036f]/g,"");
58+
59+
// Replace spaces with underscores and remove special characters
60+
returnwithoutAccents
61+
.replace(/\s+/g,"_")// Spaces to underscores
62+
.replace(/[^a-zA-Z0-9_]/g,"");// Remove everything that is not alphanumeric or underscore
63+
}
64+
65+
/**
66+
* Escapes braces in instruction prompts to avoid interpretation errors
67+
* as context variables in Python. Uses a more robust approach to ensure
68+
* Python doesn't interpret any brace patterns as variables.
69+
*/
70+
exportfunctionescapePromptBraces(text:string):string{
71+
if(!text)returntext;
72+
73+
// replace { per [ and } per ]
74+
returntext.replace(/\{/g,"[").replace(/\}/g,"]");
75+
}
76+
77+
/**
78+
* Exports any data as a JSON file for download
79+
*@param data The data to export
80+
*@param filename The name of the file to download (without .json extension)
81+
*@param pretty Whether to pretty-print the JSON (default: true)
82+
*@param allAgents Optional array of all agents to resolve references
83+
*@returns boolean indicating success
84+
*/
85+
exportfunctionexportAsJson(
86+
data:any,
87+
filename:string,
88+
pretty:boolean=true,
89+
allAgents?:any[]
90+
):boolean{
91+
try{
92+
// Create a copy of the data
93+
letexportData=JSON.parse(JSON.stringify(data));
94+
95+
// If we have all agents available, use them to resolve references
96+
constagentsMap=newMap();
97+
if(allAgents&&Array.isArray(allAgents)){
98+
allAgents.forEach(agent=>{
99+
if(agent&&agent.id){
100+
agentsMap.set(agent.id,{ ...agent});
101+
}
102+
});
103+
}elseif(exportData.agents&&Array.isArray(exportData.agents)){
104+
// If we're exporting a collection, build a map from that
105+
exportData.agents.forEach((agent:any)=>{
106+
if(agent&&agent.id){
107+
agentsMap.set(agent.id,{ ...agent});
108+
}
109+
});
110+
}
111+
112+
// Process each agent to replace IDs with full objects and remove sensitive fields
113+
constprocessAgent=(agent:any,depth=0)=>{
114+
if(!agent||depth>2)returnagent;// Limit recursion depth to avoid circular references
115+
116+
// Process agent_tools - replace IDs with full agent objects
117+
if(agent.config&&agent.config.agent_tools&&Array.isArray(agent.config.agent_tools)){
118+
agent.config.agent_tools=agent.config.agent_tools.map((toolId:string)=>{
119+
if(typeoftoolId==='string'&&agentsMap.has(toolId)){
120+
// Create a simplified version of the agent
121+
consttoolAgent={ ...agentsMap.get(toolId)};
122+
returnprocessAgent(toolAgent,depth+1);
123+
}
124+
returntoolId;
125+
});
126+
}
127+
128+
// Process sub_agents - replace IDs with full agent objects
129+
if(agent.config&&agent.config.sub_agents&&Array.isArray(agent.config.sub_agents)){
130+
agent.config.sub_agents=agent.config.sub_agents.map((agentId:string)=>{
131+
if(typeofagentId==='string'&&agentsMap.has(agentId)){
132+
// Create a simplified version of the agent
133+
constsubAgent={ ...agentsMap.get(agentId)};
134+
returnprocessAgent(subAgent,depth+1);
135+
}
136+
returnagentId;
137+
});
138+
}
139+
140+
// Process task agents - extract tasks and create full agent objects
141+
if(agent.type==='task'&&agent.config?.tasks&&Array.isArray(agent.config.tasks)){
142+
agent.config.tasks=agent.config.tasks.map((task:any)=>{
143+
if(task.agent_id&&agentsMap.has(task.agent_id)){
144+
// Add the corresponding agent to the task
145+
task.agent=processAgent({...agentsMap.get(task.agent_id)},depth+1);
146+
}
147+
returntask;
148+
});
149+
}
150+
151+
// Process workflow nodes - recursively process any agent objects in agent-nodes
152+
if(agent.type==='workflow'&&agent.config?.workflow?.nodes&&Array.isArray(agent.config.workflow.nodes)){
153+
agent.config.workflow.nodes=agent.config.workflow.nodes.map((node:any)=>{
154+
if(node.type==='agent-node'&&node.data?.agent){
155+
// Process the embedded agent object
156+
node.data.agent=processAgent(node.data.agent,depth+1);
157+
158+
// If this is a task agent, also process its tasks
159+
if(node.data.agent.type==='task'&&node.data.agent.config?.tasks&&Array.isArray(node.data.agent.config.tasks)){
160+
node.data.agent.config.tasks=node.data.agent.config.tasks.map((task:any)=>{
161+
if(task.agent_id&&agentsMap.has(task.agent_id)){
162+
task.agent=processAgent({...agentsMap.get(task.agent_id)},depth+1);
163+
}
164+
returntask;
165+
});
166+
}
167+
}
168+
returnnode;
169+
});
170+
}
171+
172+
// Remove sensitive fields
173+
constfieldsToRemove=[
174+
'api_key_id',
175+
'agent_card_url',
176+
'folder_id',
177+
'client_id',
178+
'created_at',
179+
'updated_at'
180+
];
181+
182+
// Remove top-level fields
183+
fieldsToRemove.forEach(field=>{
184+
if(agent[field]!==undefined){
185+
deleteagent[field];
186+
}
187+
});
188+
189+
// Remove nested fields
190+
if(agent.config&&agent.config.api_key!==undefined){
191+
deleteagent.config.api_key;
192+
}
193+
194+
returnagent;
195+
};
196+
197+
// Apply processing for single agent or array of agents
198+
if(exportData.agents&&Array.isArray(exportData.agents)){
199+
// For collections of agents
200+
exportData.agents=exportData.agents.map((agent:any)=>processAgent(agent));
201+
}elseif(exportData.id&&(exportData.type||exportData.name)){
202+
// For a single agent
203+
exportData=processAgent(exportData);
204+
}
205+
206+
// Create JSON string
207+
constjsonString=pretty ?JSON.stringify(exportData,null,2) :JSON.stringify(exportData);
208+
209+
// Create a Blob with the content
210+
constblob=newBlob([jsonString],{type:"application/json"});
211+
212+
// Create URL for the blob
213+
consturl=URL.createObjectURL(blob);
214+
215+
// Create a temporary <a> element for download
216+
constlink=document.createElement("a");
217+
link.href=url;
218+
link.download=filename.endsWith(".json") ?filename :`${filename}.json`;
219+
220+
// Append to document, click, and remove
221+
document.body.appendChild(link);
222+
link.click();
223+
224+
// Clean up
225+
setTimeout(()=>{
226+
document.body.removeChild(link);
227+
URL.revokeObjectURL(url);
228+
},100);
229+
230+
returntrue;
231+
}catch(error){
232+
console.error("Error exporting JSON:",error);
233+
returnfalse;
234+
}
235+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp