Skip to content

Commit

Permalink
fix type error
Browse files Browse the repository at this point in the history
  • Loading branch information
isamu committed Jun 19, 2024
1 parent aeeeb04 commit 889d144
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default defineComponent({
const download = () => {
const data = graph.serialize();
console.log(data);

Check warning on line 77 in src/views/Home.vue

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
const json = JSON.stringify(graph.serialize(), null, 2);
// const json = JSON.stringify(graph.serialize(), null, 2);
liteGraph2GraphData(data, lite2agent);
};
Expand Down
33 changes: 22 additions & 11 deletions src/views/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ComputedNodeData } from "graphai";
import { LGraphNode, LiteGraph } from "litegraph.js";
import * as vanillaAgents from "@graphai/vanilla";

Expand Down Expand Up @@ -94,7 +95,7 @@ const initLiteGraph = () => {
LiteGraph.registerNodeType([agent.category, agent.name].join("/"), createAgentNode(agent));
});

const lite2agent = {};
const lite2agent: Record<string, any> = {};
Object.values(vanillaAgents).map((agent) => {
if (agent.category) {
agent.category.forEach((category) => {
Expand All @@ -117,18 +118,28 @@ const initLiteGraph = () => {
return { lite2agent };
};

const liteGraph2GraphData = (liteGraph, lite2agent) => {
const nodes = liteGraph.nodes.map((node) => {
const liteGraph2GraphData = (liteGraph: any, lite2agent: any) => {
// [link index, out node, out position, in node, in position]かな。
const linkObj = liteGraph.links.reduce((tmp: Record<string, string[]>, link: string[]) => {
if (tmp[link[3]] === undefined) {
tmp[link[3]] = [];
}
tmp[link[3]].push(link[1])
return tmp;
}, {});
// console.log(linkObj);

const nodes = liteGraph.nodes.reduce((tmp: Record<string, ComputedNodeData>, node: any) => {
// [link index, out node, out position, in node, in position]
// innode, inputs [out node]
const inputs = linkObj[node.id];
const agent = lite2agent[node.type];
if (agent) {
return {
agent: agent.name,
};
tmp[`node_${node.id}`] = {
agent: agent ? agent.name : node.type,
inputs: inputs ? inputs.map((id: string) => `node_${id}`) : undefined,
}
return {
agent: node.type,
};
});
return tmp;
}, {});
console.log(nodes);

Check warning on line 143 in src/views/nodes.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
console.log(liteGraph, lite2agent);

Check warning on line 144 in src/views/nodes.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
};
Expand Down

0 comments on commit 889d144

Please sign in to comment.