diff --git a/client/package.json b/client/package.json index 3e8ff36d5..588d72324 100644 --- a/client/package.json +++ b/client/package.json @@ -46,6 +46,7 @@ "react-simple-code-editor": "^0.11.0", "rebass": "^4.0.7", "regenerator-runtime": "^0.13.9", + "rete-connection-reroute-plugin": "^0.4.0", "rete-context-menu-plugin": "^0.6.0-rc.1", "rete-react-render-plugin": "^0.2.1", "rxdb": "^9.21.0", diff --git a/client/scripts/engine.ts b/client/scripts/engine.ts index aac657f5b..e50e6c4f0 100644 --- a/client/scripts/engine.ts +++ b/client/scripts/engine.ts @@ -1,32 +1,14 @@ -// import spell from "./spell"; +import thothCore from '@latitudegames/thoth-core/dist/server' -import { TenseTransformer } from "@latitudegames/thoth-core/components/TenseTransformer"; -import { ModuleInput } from "@latitudegames/thoth-core/components/ModuleInput"; -import { ModuleOutput } from "@latitudegames/thoth-core/components/ModuleOutput"; -import { ModuleTriggerOut } from "@latitudegames/thoth-core/components/ModuleTriggerOut"; -import { ModuleTriggerIn } from "@latitudegames/thoth-core/components/ModuleTriggerIn"; -// import { InputComponent } from "@latitudegames/thoth-core/components/Input"; -// import { JoinListComponent } from "@latitudegames/thoth-core/components/JoinList"; -// import { RunInputComponent } from "@latitudegames/thoth-core/components/RunInput"; -// import { ActionTypeComponent } from "@latitudegames/thoth-core/components/ActionType"; -// import { ItemTypeComponent } from "@latitudegames/thoth-core/components/ItemDetector"; -// import { DifficultyDetectorComponent } from "@latitudegames/thoth-core/components/DifficultyDetector"; -// import { EntityDetector } from "@latitudegames/thoth-core/components/EntityDetector"; -// import { SafetyVerifier } from "@latitudegames/thoth-core/components/SafetyVerifier"; -// import { BooleanGate } from "@latitudegames/thoth-core/components/BooleanGate"; -// import { TimeDetectorComponent } from "@latitudegames/thoth-core/components/TimeDetector"; -// import { Alert } from "@latitudegames/thoth-core/components/AlertMessage"; -// import { SwitchGate } from "@latitudegames/thoth-core/components/SwitchGate"; -// import { PlaytestPrint } from "@latitudegames/thoth-core/components/PlaytestPrint"; -// import { PlaytestInput } from "@latitudegames/thoth-core/components/PlaytestInput"; -// import { StateWrite } from "@latitudegames/thoth-core/components/StateWrite"; -// import { StateRead } from "@latitudegames/thoth-core/components/StateRead"; -// import { StringProcessor } from "@latitudegames/thoth-core/components/StringProcessor"; -// import { ForEach } from "@latitudegames/thoth-core/components/ForEach"; -// import { EnkiTask } from "@latitudegames/thoth-core/components/EnkiTask"; -// import { Generator } from "@latitudegames/thoth-core/components/Generator"; -// import { Code } from "@latitudegames/thoth-core/components/Code"; -// import { ModuleComponent } from "@latitudegames/thoth-core/components/Module"; +const { + components: { + moduleInput, + moduleOutput, + moduleTriggerIn, + moduleTriggerOut, + tenseTransformer, + }, +} = thothCore export const components = [ // new ActionTypeComponent(), @@ -42,10 +24,10 @@ export const components = [ // new ItemTypeComponent(), // new JoinListComponent(), // new ModuleComponent(), - new ModuleInput(), - new ModuleOutput(), - new ModuleTriggerOut(), - new ModuleTriggerIn(), + moduleInput(), + moduleOutput(), + moduleTriggerOut(), + moduleTriggerIn(), // new PlaytestPrint(), // new PlaytestInput(), // new RunInputComponent(), @@ -54,8 +36,6 @@ export const components = [ // new StateRead(), // new StringProcessor(), // new SwitchGate(), - new TenseTransformer(), + tenseTransformer(), // new TimeDetectorComponent(), -]; - -export let modules = []; +] diff --git a/client/scripts/runSpell.ts b/client/scripts/runSpell.ts deleted file mode 100644 index 555d40394..000000000 --- a/client/scripts/runSpell.ts +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env ts-node -import "regenerator-runtime/runtime"; -import { Component } from "rete"; -import spell from "./spell"; -import { Module } from "./module"; -import { EngineContext } from "@latitudegames/thoth-core/engine"; -import { modules, components } from "./engine"; -import { initSharedEngine } from "@latitudegames/thoth-core/engine"; -interface ModuleComponent extends Component { - run: Function; -} - -// this parses through all the nodes in the data and finds the nodes associated with the given map -function extractNodes(nodes, map) { - const names = Array.from(map.keys()); - - return Object.keys(nodes) - .filter((k) => names.includes(nodes[k].name)) - .map((k) => nodes[k]) - .sort((n1, n2) => n1.position[1] - n2.position[1]); -} - -// This will get the node that was triggered given a socketKey associated with that node. -function getTriggeredNode(data, socketKey, map) { - return extractNodes(data.nodes, map).find( - (node) => node.data.socketKey === socketKey - ); -} - -// this will be the interface that we use to mirror any functionality from the client -// on the server. This completion function should make an actual openAI call. -const thoth: EngineContext = { - completion: (body) => { - return new Promise((resolve, reject) => { - resolve("Joe looks around"); - }); - }, - getCurrentGameState: () => { - return {}; - }, - updateCurrentGameState: () => { - return {}; - }, - huggingface: () => { - return new Promise((resolve) => { - resolve({ string: {} as unknown, error: {} as unknown } as { - [key: string]: unknown; - error: unknown; - }); - }); - }, - enkiCompletion: () => { - return new Promise((resolve) => {}); - }, -}; - -const main = async () => { - // only setting this as 'any' until we create a proper engine interface with the proper methods types on it. - const engine = initSharedEngine( - "demo@0.1.0", - modules, - components, - true - ) as any; - - // The module is an interface that the module system uses to write data to - // used internally by the module plugin, and we make use of it here too. - // we definitely want to watch out when we run nested modules to ensure nothing funky happens - // when child modules overwrite this with their own. - const module = new Module(); - - // these map to the names of the module inputs that the user defined in their chains. - // we would likely expect them to know what to use based on what they defined. - // how can we type these? Can we parse the spell chain for this information? - const inputs = { - text: "look around", - name: "Joe", - }; - - // this will have the eventual outputs written to it - const outputs = {}; - - // this attaches inputs to the module, which is passed in when the engine runs. - // you can see this at work in the 'workerInputs' function of module-manager - module.read(inputs); - - // this is the context object which is passed down into the engine and is used by workers. - const context = { - module, - thoth, - silent: true, - }; - - // processing here with the engine will just set up the tasks and prime the system for the first 'run' command. - // note that the thid - await engine?.process(spell, null, context); - - // we grab all the "trigger ins" that the module manager has gathered for us. - const triggerIns = engine.moduleManager.triggerIns; - - // We want to get a specific node that contains the socket we want to trigger to start our "run" - // this could eventually be defined by a user as a param in their request body - const triggeredNode = getTriggeredNode( - spell, - "1a819a65-e1e2-4f77-9a42-9f99f546f7c4", - triggerIns - ); - - // Here we get the component that we want to start the run sequence from, since it is the component which has the run function on it. - const component = engine?.components.get( - "Module Trigger In" - ) as ModuleComponent; - - // when we run the component, we need to pass to it WHICH node we are running from all the nodes that were built from it. - await component?.run(triggeredNode); - - // when this is done, we write all the data that was output by the module run to an object - module.write(outputs); - - console.log("Outputs", outputs); -}; - -main(); diff --git a/core/src/editor.ts b/core/src/editor.ts index 3e5095993..90eb8a23f 100644 --- a/core/src/editor.ts +++ b/core/src/editor.ts @@ -1,6 +1,6 @@ import { NodeEditor } from 'rete' import ConnectionPlugin from 'rete-connection-plugin' -// import ConnectionReroutePlugin from 'rete-connection-reroute-plugin' +import ConnectionReroutePlugin from 'rete-connection-reroute-plugin' import ContextMenuPlugin from 'rete-context-menu-plugin' import ReactRenderPlugin from 'rete-react-render-plugin' import { Data } from 'rete/types/core/data' @@ -75,7 +75,7 @@ export const initEditor = async function ({ // connection plugin is used to render conections between nodes editor.use(ConnectionPlugin) // @seang: temporarily disabling because dependencies of ConnectionReroutePlugin are failing validation on server import of thoth-core - // editor.use(ConnectionReroutePlugin) + editor.use(ConnectionReroutePlugin) // React rendering for the editor editor.use(ReactRenderPlugin, { @@ -123,7 +123,7 @@ export const initEditor = async function ({ }, {} as Record) // The engine is used to process/run the rete graph - const engine = initSharedEngine('demo@0.1.0', modules, components) + const engine = initSharedEngine('demo@0.1.0', components, false, modules) // @seang TODO: update types for editor.use rather than casting as unknown here, we may want to bring our custom rete directly into the monorepo at this point // WARNING: ModulePlugin needs to be initialized before TaskPlugin during engine setup diff --git a/core/src/engine.ts b/core/src/engine.ts index d831fc42c..92677c2ec 100644 --- a/core/src/engine.ts +++ b/core/src/engine.ts @@ -52,12 +52,12 @@ export type EngineContext = { onUpdateModule?: Function sendToPlaytest?: Function } - +// @seang TODO: update this to not use positional arguments export const initSharedEngine = ( name: string, - modules: Record, components: any[], - server = false + server = false, + modules: Record = {} ) => { const engine = new Rete.Engine(name) diff --git a/yarn.lock b/yarn.lock index 1172f9da9..616c44803 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1476,6 +1476,23 @@ "@types/yargs" "^16.0.0" chalk "^4.0.0" +"@latitudegames/thoth-core@^0.0.47": + version "0.0.47" + resolved "https://npm.pkg.github.com/download/@latitudegames/thoth-core/0.0.47/debf55884ea59db1d621e76a32e686b46b6efb7818a382339b54f53a0fb7c330#ec6feaf9c36988ab9b7ea2b8f53dad15926932ae" + integrity sha512-seAbSeF2p32eCImjDB4Z0BVniuOXiL25numaJGaTMSvCooIgoh6QNX2n8IxGQ8jDT0MTxZF3JvNpF9wHjq3Ihg== + dependencies: + deep-equal "^2.0.5" + handlebars "^4.7.7" + path "^0.12.7" + react "^17.0.2" + rete "https://github.com/latitudegames/rete.git#master" + rete-area-plugin "^0.2.1" + rete-connection-plugin "^0.9.0" + rete-context-menu-plugin "^0.6.0-rc.1" + rete-module-plugin "^0.4.1" + rete-react-render-plugin "^0.2.1" + uuid "^8.3.2" + "@lerna/add@4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@lerna/add/-/add-4.0.0.tgz#c36f57d132502a57b9e7058d1548b7a565ef183f" @@ -5568,6 +5585,18 @@ cyclist@^1.0.1: resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk= +d3-path@1: + version "1.0.9" + resolved "https://registry.yarnpkg.com/d3-path/-/d3-path-1.0.9.tgz#48c050bb1fe8c262493a8caf5524e3e9591701cf" + integrity sha512-VLaYcn81dtHVTjEHd8B+pbe9yHWpXKZUC87PzoFmsFrJqgFwDe/qxfp5MlfsfM1V5E/iVt0MmEbWQ7FVIXh/bg== + +d3-shape@^1.3.5: + version "1.3.7" + resolved "https://registry.yarnpkg.com/d3-shape/-/d3-shape-1.3.7.tgz#df63801be07bc986bc54f63789b4fe502992b5d7" + integrity sha512-EUkvKjqPFUAZyOlhY5gzCxCeI0Aep04LwIRpsZ/mLFelJiUfnK56jo5JMDSE7yyP2kLSb6LtF+S5chMk7uqPqw== + dependencies: + d3-path "1" + dargs@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/dargs/-/dargs-7.0.0.tgz#04015c41de0bcb69ec84050f3d9be0caf8d6d5cc" @@ -12200,6 +12229,14 @@ rete-connection-plugin@^0.9.0: resolved "https://registry.yarnpkg.com/rete-connection-plugin/-/rete-connection-plugin-0.9.0.tgz#3a6df36f55493a5c2ea021ae3147a0f0a6ada6ed" integrity sha512-D+H1yAONBBFYXeMkz0sdpDm76XiqcF2N3FduaqMUqcoThocMaFB2O8TX3nJc76ksuYaLYqo/+OLXTxNa+5HQYQ== +rete-connection-reroute-plugin@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/rete-connection-reroute-plugin/-/rete-connection-reroute-plugin-0.4.0.tgz#30fb8f8e2d5d32a379f8c8bd743145a326a42e08" + integrity sha512-DWZrK/qk9kt83o2cELjKpabD0YIJ6rhzp7rnTqEV4IHpSJxhruNSBKG2V7hxXq4wMy7T0zVFh9f0TIRJ5qvTqQ== + dependencies: + d3-shape "^1.3.5" + vue "2.6.10" + rete-context-menu-plugin@^0.6.0-rc.1: version "0.6.0-rc.1" resolved "https://registry.yarnpkg.com/rete-context-menu-plugin/-/rete-context-menu-plugin-0.6.0-rc.1.tgz#0e5ba94057952ec9c07c0efd0d2ab27e9cc683a1" @@ -13976,6 +14013,11 @@ vm-browserify@^1.0.1: resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0" integrity sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ== +vue@2.6.10: + version "2.6.10" + resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637" + integrity sha512-ImThpeNU9HbdZL3utgMCq0oiMzAkt1mcgy3/E6zWC/G6AaQoeuFdsl9nDhTDU3X1R6FK7nsIUuRACVcjI+A2GQ== + vue@^2.5.17: version "2.6.14" resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.14.tgz#e51aa5250250d569a3fbad3a8a5a687d6036e235"