hytopia 0.1.77 → 0.1.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/docs/server.entity.despawn.md +1 -1
  2. package/docs/server.entity.md +44 -2
  3. package/docs/server.entity.parent.md +13 -0
  4. package/docs/server.entity.parentnodename.md +13 -0
  5. package/docs/server.entity.spawn.md +19 -3
  6. package/docs/server.entitymanager.getentitychildren.md +55 -0
  7. package/docs/server.entitymanager.md +14 -0
  8. package/docs/server.entityoptions.md +38 -0
  9. package/docs/server.entityoptions.parent.md +13 -0
  10. package/docs/server.entityoptions.parentnodename.md +13 -0
  11. package/docs/server.gameserver.md +2 -2
  12. package/docs/{server.gameserver.modelmanager.md → server.gameserver.modelregistry.md} +3 -3
  13. package/docs/server.md +1 -1
  14. package/docs/{server.modelmanager.getboundingbox.md → server.modelregistry.getboundingbox.md} +2 -2
  15. package/docs/server.modelregistry.getnodenames.md +55 -0
  16. package/docs/server.modelregistry.instance.md +13 -0
  17. package/docs/server.modelregistry.md +139 -0
  18. package/docs/server.modelregistry.modelhasnode.md +71 -0
  19. package/examples/ai-agents/README.md +47 -0
  20. package/examples/ai-agents/assets/map.json +25828 -0
  21. package/examples/ai-agents/assets/ui/index.html +215 -0
  22. package/examples/ai-agents/index.ts +350 -0
  23. package/examples/ai-agents/package.json +16 -0
  24. package/examples/ai-agents/src/BaseAgent.ts +482 -0
  25. package/examples/ai-agents/src/behaviors/FishingBehavior.ts +181 -0
  26. package/examples/ai-agents/src/behaviors/FollowBehavior.ts +171 -0
  27. package/examples/ai-agents/src/behaviors/MiningBehavior.ts +226 -0
  28. package/examples/ai-agents/src/behaviors/PathfindingBehavior.ts +435 -0
  29. package/examples/ai-agents/src/behaviors/SpeakBehavior.ts +50 -0
  30. package/examples/ai-agents/src/behaviors/TradeBehavior.ts +254 -0
  31. package/examples/entity-controller/MyEntityController.ts +1 -1
  32. package/package.json +1 -1
  33. package/server.api.json +324 -21
  34. package/server.d.ts +47 -22
  35. package/server.js +83 -83
  36. package/docs/server.modelmanager.instance.md +0 -13
  37. package/docs/server.modelmanager.md +0 -111
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## Entity.despawn() method
6
6
 
7
- Despawns the entity from the world.
7
+ Despawns the entity and all children from the world.
8
8
 
9
9
  **Signature:**
10
10
 
@@ -528,6 +528,48 @@ number \| undefined
528
528
  The opacity of the entity between 0 and 1. 0 is fully transparent, 1 is fully opaque.
529
529
 
530
530
 
531
+ </td></tr>
532
+ <tr><td>
533
+
534
+ [parent](./server.entity.parent.md)
535
+
536
+
537
+ </td><td>
538
+
539
+ `readonly`
540
+
541
+
542
+ </td><td>
543
+
544
+ [Entity](./server.entity.md) \| undefined
545
+
546
+
547
+ </td><td>
548
+
549
+ The parent entity of the entity.
550
+
551
+
552
+ </td></tr>
553
+ <tr><td>
554
+
555
+ [parentNodeName](./server.entity.parentnodename.md)
556
+
557
+
558
+ </td><td>
559
+
560
+ `readonly`
561
+
562
+
563
+ </td><td>
564
+
565
+ string \| undefined
566
+
567
+
568
+ </td><td>
569
+
570
+ The name of the parent's node (if parent is a model entity) this entity is attached to when spawned.
571
+
572
+
531
573
  </td></tr>
532
574
  <tr><td>
533
575
 
@@ -622,7 +664,7 @@ Description
622
664
 
623
665
  </td><td>
624
666
 
625
- Despawns the entity from the world.
667
+ Despawns the entity and all children from the world.
626
668
 
627
669
 
628
670
  </td></tr>
@@ -698,7 +740,7 @@ Sets the tint color of the entity.
698
740
  </td></tr>
699
741
  <tr><td>
700
742
 
701
- [spawn(world, coordinate)](./server.entity.spawn.md)
743
+ [spawn(world, position, rotation)](./server.entity.spawn.md)
702
744
 
703
745
 
704
746
  </td><td>
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [Entity](./server.entity.md) &gt; [parent](./server.entity.parent.md)
4
+
5
+ ## Entity.parent property
6
+
7
+ The parent entity of the entity.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ get parent(): Entity | undefined;
13
+ ```
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [Entity](./server.entity.md) &gt; [parentNodeName](./server.entity.parentnodename.md)
4
+
5
+ ## Entity.parentNodeName property
6
+
7
+ The name of the parent's node (if parent is a model entity) this entity is attached to when spawned.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ get parentNodeName(): string | undefined;
13
+ ```
@@ -9,7 +9,7 @@ Spawns the entity in the world.
9
9
  **Signature:**
10
10
 
11
11
  ```typescript
12
- spawn(world: World, coordinate: Vector3Like): void;
12
+ spawn(world: World, position: Vector3Like, rotation?: QuaternionLike): void;
13
13
  ```
14
14
 
15
15
  ## Parameters
@@ -48,7 +48,7 @@ The world to spawn the entity in.
48
48
  </td></tr>
49
49
  <tr><td>
50
50
 
51
- coordinate
51
+ position
52
52
 
53
53
 
54
54
  </td><td>
@@ -58,7 +58,23 @@ coordinate
58
58
 
59
59
  </td><td>
60
60
 
61
- The coordinate to spawn the entity at.
61
+ The position to spawn the entity at.
62
+
63
+
64
+ </td></tr>
65
+ <tr><td>
66
+
67
+ rotation
68
+
69
+
70
+ </td><td>
71
+
72
+ [QuaternionLike](./server.quaternionlike.md)
73
+
74
+
75
+ </td><td>
76
+
77
+ _(Optional)_ The optional rotation to spawn the entity with.
62
78
 
63
79
 
64
80
  </td></tr>
@@ -0,0 +1,55 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [EntityManager](./server.entitymanager.md) &gt; [getEntityChildren](./server.entitymanager.getentitychildren.md)
4
+
5
+ ## EntityManager.getEntityChildren() method
6
+
7
+ Gets all child entities of an entity.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ getEntityChildren(entity: Entity): Entity[];
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ <table><thead><tr><th>
18
+
19
+ Parameter
20
+
21
+
22
+ </th><th>
23
+
24
+ Type
25
+
26
+
27
+ </th><th>
28
+
29
+ Description
30
+
31
+
32
+ </th></tr></thead>
33
+ <tbody><tr><td>
34
+
35
+ entity
36
+
37
+
38
+ </td><td>
39
+
40
+ [Entity](./server.entity.md)
41
+
42
+
43
+ </td><td>
44
+
45
+ The entity to get the children for.
46
+
47
+
48
+ </td></tr>
49
+ </tbody></table>
50
+ **Returns:**
51
+
52
+ [Entity](./server.entity.md)<!-- -->\[\]
53
+
54
+ All child entities of the entity.
55
+
@@ -160,6 +160,20 @@ Gets all spawned entities in the world with a tag that includes a specific subst
160
160
  Gets a spawned entity in the world by its id.
161
161
 
162
162
 
163
+ </td></tr>
164
+ <tr><td>
165
+
166
+ [getEntityChildren(entity)](./server.entitymanager.getentitychildren.md)
167
+
168
+
169
+ </td><td>
170
+
171
+
172
+ </td><td>
173
+
174
+ Gets all child entities of an entity.
175
+
176
+
163
177
  </td></tr>
164
178
  <tr><td>
165
179
 
@@ -224,6 +224,44 @@ number
224
224
  _(Optional)_ The opacity of the entity between 0 and 1. 0 is fully transparent, 1 is fully opaque.
225
225
 
226
226
 
227
+ </td></tr>
228
+ <tr><td>
229
+
230
+ [parent?](./server.entityoptions.parent.md)
231
+
232
+
233
+ </td><td>
234
+
235
+
236
+ </td><td>
237
+
238
+ [Entity](./server.entity.md)
239
+
240
+
241
+ </td><td>
242
+
243
+ _(Optional)_ The parent entity of the entity, entities with a parent will ignore creating their own colliders.
244
+
245
+
246
+ </td></tr>
247
+ <tr><td>
248
+
249
+ [parentNodeName?](./server.entityoptions.parentnodename.md)
250
+
251
+
252
+ </td><td>
253
+
254
+
255
+ </td><td>
256
+
257
+ string
258
+
259
+
260
+ </td><td>
261
+
262
+ _(Optional)_ The name of the parent's node (if parent is a model entity) to attach the entity to.
263
+
264
+
227
265
  </td></tr>
228
266
  <tr><td>
229
267
 
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [EntityOptions](./server.entityoptions.md) &gt; [parent](./server.entityoptions.parent.md)
4
+
5
+ ## EntityOptions.parent property
6
+
7
+ The parent entity of the entity, entities with a parent will ignore creating their own colliders.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ parent?: Entity;
13
+ ```
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [EntityOptions](./server.entityoptions.md) &gt; [parentNodeName](./server.entityoptions.parentnodename.md)
4
+
5
+ ## EntityOptions.parentNodeName property
6
+
7
+ The name of the parent's node (if parent is a model entity) to attach the entity to.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ parentNodeName?: string;
13
+ ```
@@ -66,7 +66,7 @@ The singleton instance of the game server.
66
66
  </td></tr>
67
67
  <tr><td>
68
68
 
69
- [modelManager](./server.gameserver.modelmanager.md)
69
+ [modelRegistry](./server.gameserver.modelregistry.md)
70
70
 
71
71
 
72
72
  </td><td>
@@ -76,7 +76,7 @@ The singleton instance of the game server.
76
76
 
77
77
  </td><td>
78
78
 
79
- [ModelManager](./server.modelmanager.md)
79
+ [ModelRegistry](./server.modelregistry.md)
80
80
 
81
81
 
82
82
  </td><td>
@@ -1,13 +1,13 @@
1
1
  <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
2
 
3
- [Home](./index.md) &gt; [server](./server.md) &gt; [GameServer](./server.gameserver.md) &gt; [modelManager](./server.gameserver.modelmanager.md)
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [GameServer](./server.gameserver.md) &gt; [modelRegistry](./server.gameserver.modelregistry.md)
4
4
 
5
- ## GameServer.modelManager property
5
+ ## GameServer.modelRegistry property
6
6
 
7
7
  The model manager for the game server.
8
8
 
9
9
  **Signature:**
10
10
 
11
11
  ```typescript
12
- get modelManager(): ModelManager;
12
+ get modelRegistry(): ModelRegistry;
13
13
  ```
package/docs/server.md CHANGED
@@ -195,7 +195,7 @@ Manages Light instances in a world.
195
195
  </td></tr>
196
196
  <tr><td>
197
197
 
198
- [ModelManager](./server.modelmanager.md)
198
+ [ModelRegistry](./server.modelregistry.md)
199
199
 
200
200
 
201
201
  </td><td>
@@ -1,8 +1,8 @@
1
1
  <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
2
 
3
- [Home](./index.md) &gt; [server](./server.md) &gt; [ModelManager](./server.modelmanager.md) &gt; [getBoundingBox](./server.modelmanager.getboundingbox.md)
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [ModelRegistry](./server.modelregistry.md) &gt; [getBoundingBox](./server.modelregistry.getboundingbox.md)
4
4
 
5
- ## ModelManager.getBoundingBox() method
5
+ ## ModelRegistry.getBoundingBox() method
6
6
 
7
7
  Retrieves the bounding box of a model.
8
8
 
@@ -0,0 +1,55 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [ModelRegistry](./server.modelregistry.md) &gt; [getNodeNames](./server.modelregistry.getnodenames.md)
4
+
5
+ ## ModelRegistry.getNodeNames() method
6
+
7
+ Retrieves the names of all nodes in a model.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ getNodeNames(modelUri: string): string[];
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ <table><thead><tr><th>
18
+
19
+ Parameter
20
+
21
+
22
+ </th><th>
23
+
24
+ Type
25
+
26
+
27
+ </th><th>
28
+
29
+ Description
30
+
31
+
32
+ </th></tr></thead>
33
+ <tbody><tr><td>
34
+
35
+ modelUri
36
+
37
+
38
+ </td><td>
39
+
40
+ string
41
+
42
+
43
+ </td><td>
44
+
45
+ The URI of the model to retrieve the node names for.
46
+
47
+
48
+ </td></tr>
49
+ </tbody></table>
50
+ **Returns:**
51
+
52
+ string\[\]
53
+
54
+ The names of all nodes in the model.
55
+
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [ModelRegistry](./server.modelregistry.md) &gt; [instance](./server.modelregistry.instance.md)
4
+
5
+ ## ModelRegistry.instance property
6
+
7
+ The global ModelRegistry instance as a singleton.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ static readonly instance: ModelRegistry;
13
+ ```
@@ -0,0 +1,139 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [ModelRegistry](./server.modelregistry.md)
4
+
5
+ ## ModelRegistry class
6
+
7
+ Manages model data for all known models of the game.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ export default class ModelRegistry
13
+ ```
14
+
15
+ ## Remarks
16
+
17
+ The ModelRegistry is created internally as a global singletone accessible with the static property `ModelRegistry.instance`<!-- -->.
18
+
19
+ The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `ModelRegistry` class.
20
+
21
+ ## Example
22
+
23
+
24
+ ```typescript
25
+ import { ModelRegistry } from 'hytopia';
26
+
27
+ const modelRegistry = ModelRegistry.instance;
28
+ const boundingBox = modelRegistry.getBoundingBox('models/player.gltf');
29
+ ```
30
+
31
+ ## Properties
32
+
33
+ <table><thead><tr><th>
34
+
35
+ Property
36
+
37
+
38
+ </th><th>
39
+
40
+ Modifiers
41
+
42
+
43
+ </th><th>
44
+
45
+ Type
46
+
47
+
48
+ </th><th>
49
+
50
+ Description
51
+
52
+
53
+ </th></tr></thead>
54
+ <tbody><tr><td>
55
+
56
+ [instance](./server.modelregistry.instance.md)
57
+
58
+
59
+ </td><td>
60
+
61
+ `static`
62
+
63
+ `readonly`
64
+
65
+
66
+ </td><td>
67
+
68
+ [ModelRegistry](./server.modelregistry.md)
69
+
70
+
71
+ </td><td>
72
+
73
+ The global ModelRegistry instance as a singleton.
74
+
75
+
76
+ </td></tr>
77
+ </tbody></table>
78
+
79
+ ## Methods
80
+
81
+ <table><thead><tr><th>
82
+
83
+ Method
84
+
85
+
86
+ </th><th>
87
+
88
+ Modifiers
89
+
90
+
91
+ </th><th>
92
+
93
+ Description
94
+
95
+
96
+ </th></tr></thead>
97
+ <tbody><tr><td>
98
+
99
+ [getBoundingBox(modelUri)](./server.modelregistry.getboundingbox.md)
100
+
101
+
102
+ </td><td>
103
+
104
+
105
+ </td><td>
106
+
107
+ Retrieves the bounding box of a model.
108
+
109
+
110
+ </td></tr>
111
+ <tr><td>
112
+
113
+ [getNodeNames(modelUri)](./server.modelregistry.getnodenames.md)
114
+
115
+
116
+ </td><td>
117
+
118
+
119
+ </td><td>
120
+
121
+ Retrieves the names of all nodes in a model.
122
+
123
+
124
+ </td></tr>
125
+ <tr><td>
126
+
127
+ [modelHasNode(modelUri, nodeName)](./server.modelregistry.modelhasnode.md)
128
+
129
+
130
+ </td><td>
131
+
132
+
133
+ </td><td>
134
+
135
+ Checks if a model has a node with the given name.
136
+
137
+
138
+ </td></tr>
139
+ </tbody></table>
@@ -0,0 +1,71 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [ModelRegistry](./server.modelregistry.md) &gt; [modelHasNode](./server.modelregistry.modelhasnode.md)
4
+
5
+ ## ModelRegistry.modelHasNode() method
6
+
7
+ Checks if a model has a node with the given name.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ modelHasNode(modelUri: string, nodeName: string): boolean;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ <table><thead><tr><th>
18
+
19
+ Parameter
20
+
21
+
22
+ </th><th>
23
+
24
+ Type
25
+
26
+
27
+ </th><th>
28
+
29
+ Description
30
+
31
+
32
+ </th></tr></thead>
33
+ <tbody><tr><td>
34
+
35
+ modelUri
36
+
37
+
38
+ </td><td>
39
+
40
+ string
41
+
42
+
43
+ </td><td>
44
+
45
+ The URI of the model to check.
46
+
47
+
48
+ </td></tr>
49
+ <tr><td>
50
+
51
+ nodeName
52
+
53
+
54
+ </td><td>
55
+
56
+ string
57
+
58
+
59
+ </td><td>
60
+
61
+ The name of the node to check for.
62
+
63
+
64
+ </td></tr>
65
+ </tbody></table>
66
+ **Returns:**
67
+
68
+ boolean
69
+
70
+ Whether the model has a node with the given name.
71
+
@@ -0,0 +1,47 @@
1
+ # Hytopia Multi Agent Demo
2
+
3
+ This demo codebase provides an example for building multi Agent AI systems in Hytopia. The server has the following features:
4
+ - Multiple AI agents with unique pathfinding, behaviour and capabilities
5
+ - Chat bubbles for agent speech
6
+ - Side bar UI for viewing Agent actions
7
+
8
+ ## How do Agents work in Hytopia?
9
+ Game Agents are driven by a combination of game-specific action logic, world state representation, and Large Language Models.
10
+
11
+ At a high level, to integrate agents into your game, you need to think about these three pieces.
12
+
13
+ ### World State Representation
14
+ Your Agents need to know what is going on in the game. Where are they? What is around them? etc..
15
+ In this demo, the following data is available in the Agent's personal state:
16
+ - Their location
17
+ - Entities around them
18
+ - The status of any ongoing actions ("Behaviors")
19
+ - Items in their inventory
20
+
21
+ For more information on this, see the [`getCurrentState()`](src/BaseAgent.ts#L205) function in BaseAgent. Each behavior returns their Agent-specific state as a string, which we group together into an object and stringify it for the Agent's prompt.
22
+ States are prepended to each prompt to the agent.
23
+
24
+ ### Actions
25
+ Actions are things that people and agents do in your game. In this simple demo, the things people do are simple: they go places, they say things, and some of them do profession-specific tasks like Fishing and Mining.
26
+
27
+ Going places means going to specific locations (by coordinates), or going to a person or thing (by name). This means Bob can go to Jim, without knowing where Jim is. Bob might also decide to go to the Pier, since Jim is a Fisherman and one would expect the town fisherman to be at the pier.
28
+
29
+ Saying things is simple, but the weeds of what that means is also game specific. In this demo, when agents speak, other agents can hear them in close proximity, but for the sake of the demo we also show their messages globally in chat. Speaking also spawns a chat bubble UI template. See the [`agent-chat template`](assets/ui/index.html#L178) for more info on this.
30
+
31
+ Actions also interact with LLMs. Since actions are called by the LLM, we need to show the LLM how to call them.
32
+ Some agent frameworks use tool calling/function calling, which is very popular with OpenAI.
33
+ You can do this if you want, but I prefer XML. XML takes less output tokens, is very natural for LLMs to write (billions of html pages parsed). Most importantly, valid XML can be easily regexed out of any text, intermingled with other thoughts from the LLM. Many benchmarks show creativity in language models decreasing as output format is increasingly restricted.
34
+
35
+ In this demo, an action can be called by an LLM simply by outputting text like this:
36
+ `<action type="speak">...</action>`
37
+
38
+ Another benefit of this approach is that models with very little infrastructure around their APIs can all output valid XML, so you can easily use whatever model or provider you want.
39
+
40
+ ### Large Language Models
41
+ LLM's act as a router and brain for the agent, converting state representations and inputs into a sequence of actions.
42
+ LLM's need to be prompted. You will not get a spontaneous output without an input. In a game, this means you need to decide when Agent's make decisions. In this demo I show two common techniques:
43
+ - Response Triggers: when a Player speaks to an Agent, they will respond immediately. This lets players have some immediate control over influencing agent behaviours, and makes it easy to test your prompts with quick feedback. This is best for smaller player counts.
44
+ - Game Steps: as you can imagine, the above response triggers will not work at scale. Imagine 100 players in an area all talking to the same agent. You would not want it to respond outloud to everyone in the area. Instead, you can take a page out of the playbook of turn-based strategy games. Divide your game time into turns (a step could be every 5 seconds, 10 seconds, whatever you want), and each turn, you trigger each agent with the new state since their last turn. Players don't need to be limited by turns, but this makes your agents a bit simpler to manage. You can see an example of how this works in the idle detection of the agents in this repo. If an agent has not been triggered by a player in the last 30 seconds, they wake up and can decide what to do next.
45
+
46
+ ## What's next?
47
+ We want to continue to make AI Agents accessible for developers of Hytopia games. This means more game-specific demos, more tooling, and a standardized Agent implementation that you can import as a plugin into your games. More on this soon :)