Skip to content

Commit 8698804

Browse files
feat: Add defineSpellGraph function for defining spell graphs, update test spell
1 parent 90a2ce2 commit 8698804

3 files changed

Lines changed: 19 additions & 59 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {
2+
type GraphJSON,
3+
type IRegistry,
4+
type GraphInstance,
5+
readGraphFromJSON,
6+
} from '@magickml/behave-graph'
7+
8+
export function defineSpellGraph(graphDefinition: GraphJSON): GraphInstance {
9+
// TODO: Get the real registry
10+
const registry = {} as IRegistry
11+
return readGraphFromJSON({ graphJson: graphDefinition, registry })
12+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './registry'
2-
export * from './spells'
2+
export * from './spells'
3+
export * from './define'
Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,7 @@
1-
import type { Spell } from '@magickml/spells/runtime/utils'
2-
// We should re-export these from behave-graph in our node/spell packages
3-
import {
4-
createNode,
5-
makeGraphApi,
6-
makeOrGenerateSockets,
7-
} from '@magickml/behave-graph'
8-
import { useRuntimeConfig } from 'nitro/runtime'
1+
import { defineSpellGraph } from '@magickml/spells/runtime/utils'
92

10-
const exampleSpell: Spell = {
11-
id: 'example-spell',
12-
name: 'Example Spell',
13-
description: 'A simple example spell',
14-
graph: {
15-
name: 'Example Graph',
16-
nodes: {},
17-
variables: {},
18-
customEvents: {},
19-
metadata: {},
20-
},
21-
}
22-
23-
// Add nodes to the graph
24-
const graph = makeGraphApi({
25-
...useRuntimeConfig().registry,
26-
variables: exampleSpell.graph.variables,
27-
customEvents: exampleSpell.graph.customEvents,
28-
})
29-
30-
// e we have our defineNode definers but these behave-graph utils are still useful
31-
// I feel like this createNode is better for programmatic use
32-
// where our defineNode is better for declarative use/conntected to the registry/editor
33-
34-
const startNode = createNode({
35-
id: 'start',
36-
graph,
37-
registry: useRuntimeConfig().registry, // replace this with useNodeSpec()
38-
nodeTypeName: 'lifecycle/onStart',
39-
})
40-
41-
const logNode = createNode({
42-
id: 'log',
43-
graph,
44-
registry: useRuntimeConfig().registry,
45-
nodeTypeName: 'debug/log',
46-
nodeConfiguration: {
47-
text: 'Hello from Example Spell!',
48-
},
3+
export default defineSpellGraph({
4+
name: 'Test Spell',
5+
nodes: [],
6+
variables: [],
497
})
50-
51-
exampleSpell.graph.nodes[startNode.id] = startNode
52-
exampleSpell.graph.nodes[logNode.id] = logNode
53-
54-
// implement sometihng like this to grab node config
55-
// const nodeConfig = useNodeSpec()
56-
57-
// we can store a node config in the nitro object
58-
// or generate on the fly
59-
60-
export default exampleSpell

0 commit comments

Comments
 (0)