@casual-simulation/aux-common 2.0.31 → 2.0.36
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.
- package/bots/Bot.d.ts +28 -0
- package/bots/Bot.js +39 -0
- package/bots/Bot.js.map +1 -1
- package/bots/BotEvents.d.ts +130 -2
- package/bots/BotEvents.js +84 -0
- package/bots/BotEvents.js.map +1 -1
- package/package.json +3 -3
- package/runtime/AuxLibrary.d.ts +9 -2
- package/runtime/AuxLibrary.js +102 -2
- package/runtime/AuxLibrary.js.map +1 -1
- package/runtime/AuxLibraryDefinitions.def +155 -4
- package/runtime/README.md +0 -144
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
type MaskFunc<Func extends ((...args: any[]) => any)> = {
|
|
3
2
|
(...args: Parameters<Func>): ReturnType<Func>;
|
|
4
3
|
|
|
@@ -233,7 +232,8 @@ declare type ExtraActions =
|
|
|
233
232
|
| AddDropSnapTargetsAction
|
|
234
233
|
| EnableCustomDraggingAction
|
|
235
234
|
| EnablePOVAction
|
|
236
|
-
| SetAppOutputAction
|
|
235
|
+
| SetAppOutputAction
|
|
236
|
+
| MeetCommandAction;
|
|
237
237
|
|
|
238
238
|
/**
|
|
239
239
|
* Defines a set of possible async action types.
|
|
@@ -258,7 +258,9 @@ declare type AsyncActions =
|
|
|
258
258
|
| EndRecordingAction
|
|
259
259
|
| SpeakTextAction
|
|
260
260
|
| GetVoicesAction
|
|
261
|
-
| GetGeolocationAction
|
|
261
|
+
| GetGeolocationAction
|
|
262
|
+
| ARSupportedAction
|
|
263
|
+
| VRSupportedAction;
|
|
262
264
|
|
|
263
265
|
/**
|
|
264
266
|
* Defines an interface for actions that represent asynchronous tasks.
|
|
@@ -1754,10 +1756,24 @@ declare interface EnableVRAction {
|
|
|
1754
1756
|
enabled: boolean;
|
|
1755
1757
|
}
|
|
1756
1758
|
|
|
1759
|
+
/**
|
|
1760
|
+
* Defines an event that checks for AR support on the device.
|
|
1761
|
+
*/
|
|
1762
|
+
declare interface ARSupportedAction extends AsyncAction {
|
|
1763
|
+
type: 'ar_supported';
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
/**
|
|
1767
|
+
* Defines an event that checks for VR support on the device.
|
|
1768
|
+
*/
|
|
1769
|
+
declare interface VRSupportedAction extends AsyncAction {
|
|
1770
|
+
type: 'vr_supported';
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1757
1773
|
/**
|
|
1758
1774
|
* Defines an event that enables POV on the device.
|
|
1759
1775
|
*/
|
|
1760
|
-
|
|
1776
|
+
declare interface EnablePOVAction {
|
|
1761
1777
|
type: 'enable_pov';
|
|
1762
1778
|
|
|
1763
1779
|
/**
|
|
@@ -1771,6 +1787,23 @@ declare interface EnableVRAction {
|
|
|
1771
1787
|
center?: { x: number, y: number, z: number };
|
|
1772
1788
|
}
|
|
1773
1789
|
|
|
1790
|
+
/**
|
|
1791
|
+
* An event that is used to send a command to the Jitsi Meet API.
|
|
1792
|
+
*/
|
|
1793
|
+
declare interface MeetCommandAction{
|
|
1794
|
+
type: 'meet_command',
|
|
1795
|
+
|
|
1796
|
+
/**
|
|
1797
|
+
* The name of the command to execute.
|
|
1798
|
+
*/
|
|
1799
|
+
command: string;
|
|
1800
|
+
|
|
1801
|
+
/**
|
|
1802
|
+
* The arguments for the command (if any).
|
|
1803
|
+
*/
|
|
1804
|
+
args?: any[];
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1774
1807
|
/**
|
|
1775
1808
|
* Defines an event that shows a QR code that is a link to a inst & dimension.
|
|
1776
1809
|
*/
|
|
@@ -2932,6 +2965,27 @@ export interface GetDataFailure {
|
|
|
2932
2965
|
errorMessage: string;
|
|
2933
2966
|
}
|
|
2934
2967
|
|
|
2968
|
+
|
|
2969
|
+
export type ListDataResult = ListDataSuccess | ListDataFailure;
|
|
2970
|
+
|
|
2971
|
+
export interface ListDataSuccess {
|
|
2972
|
+
success: true;
|
|
2973
|
+
recordName: string;
|
|
2974
|
+
items: {
|
|
2975
|
+
data: any;
|
|
2976
|
+
address: string;
|
|
2977
|
+
}[];
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
export interface ListDataFailure {
|
|
2981
|
+
success: false;
|
|
2982
|
+
errorCode:
|
|
2983
|
+
| ServerError
|
|
2984
|
+
| NotSupportedError;
|
|
2985
|
+
errorMessage: string;
|
|
2986
|
+
}
|
|
2987
|
+
|
|
2988
|
+
|
|
2935
2989
|
export type EraseDataResult = EraseDataSuccess | EraseDataFailure;
|
|
2936
2990
|
|
|
2937
2991
|
export interface EraseDataSuccess {
|
|
@@ -3002,6 +3056,59 @@ export interface EraseFileFailure {
|
|
|
3002
3056
|
errorMessage: string;
|
|
3003
3057
|
}
|
|
3004
3058
|
|
|
3059
|
+
|
|
3060
|
+
export type AddCountResult = AddCountSuccess | AddCountFailure;
|
|
3061
|
+
|
|
3062
|
+
export interface AddCountSuccess {
|
|
3063
|
+
success: true;
|
|
3064
|
+
recordName: string;
|
|
3065
|
+
eventName: string;
|
|
3066
|
+
countAdded: number;
|
|
3067
|
+
}
|
|
3068
|
+
|
|
3069
|
+
export interface AddCountFailure {
|
|
3070
|
+
success: false;
|
|
3071
|
+
errorCode:
|
|
3072
|
+
| ServerError
|
|
3073
|
+
| NotLoggedInError
|
|
3074
|
+
| InvalidRecordKey
|
|
3075
|
+
| RecordNotFoundError
|
|
3076
|
+
| NotSupportedError
|
|
3077
|
+
errorMessage: string;
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
export type GetCountResult = GetCountSuccess | GetCountFailure;
|
|
3081
|
+
|
|
3082
|
+
/**
|
|
3083
|
+
* Defines an interface that represents a successful "get data" result.
|
|
3084
|
+
*/
|
|
3085
|
+
export interface GetCountSuccess {
|
|
3086
|
+
success: true;
|
|
3087
|
+
|
|
3088
|
+
/**
|
|
3089
|
+
* The total count of events.
|
|
3090
|
+
*/
|
|
3091
|
+
count: number;
|
|
3092
|
+
|
|
3093
|
+
/**
|
|
3094
|
+
* The name of the record.
|
|
3095
|
+
*/
|
|
3096
|
+
recordName: string;
|
|
3097
|
+
|
|
3098
|
+
/**
|
|
3099
|
+
* The name of the event.
|
|
3100
|
+
*/
|
|
3101
|
+
eventName: string;
|
|
3102
|
+
}
|
|
3103
|
+
|
|
3104
|
+
export interface GetCountFailure {
|
|
3105
|
+
success: false;
|
|
3106
|
+
errorCode:
|
|
3107
|
+
| ServerError
|
|
3108
|
+
| NotSupportedError;
|
|
3109
|
+
errorMessage: string;
|
|
3110
|
+
}
|
|
3111
|
+
|
|
3005
3112
|
export interface AudioRecordingOptions {
|
|
3006
3113
|
/**
|
|
3007
3114
|
* Whether to stream the audio recording.
|
|
@@ -4651,6 +4758,16 @@ interface Os {
|
|
|
4651
4758
|
*/
|
|
4652
4759
|
disableVR(): EnableVRAction;
|
|
4653
4760
|
|
|
4761
|
+
/**
|
|
4762
|
+
* Promise that returns wether or not AR is supported on the device.
|
|
4763
|
+
*/
|
|
4764
|
+
arSupported(): Promise<boolean>;
|
|
4765
|
+
|
|
4766
|
+
/**
|
|
4767
|
+
* Promise that returns wether or not VR is supported on the device.
|
|
4768
|
+
*/
|
|
4769
|
+
vrSupported(): Promise<boolean>;
|
|
4770
|
+
|
|
4654
4771
|
/**
|
|
4655
4772
|
* Enables Point-of-View mode.
|
|
4656
4773
|
* @param center The position that the camera should be placed at. Defaults to (0,0,0)
|
|
@@ -4685,6 +4802,12 @@ interface Os {
|
|
|
4685
4802
|
*/
|
|
4686
4803
|
isCollaborative(): boolean;
|
|
4687
4804
|
|
|
4805
|
+
/**
|
|
4806
|
+
* Gets media permission for the device.
|
|
4807
|
+
* Promise will resolve if permission was granted, otherwise an error will be thrown.
|
|
4808
|
+
*/
|
|
4809
|
+
getMediaPermission(options: { audio?: boolean, video?: boolean }): Promise<void>;
|
|
4810
|
+
|
|
4688
4811
|
/**
|
|
4689
4812
|
* Gets the URL that AB1 should be bootstrapped from.
|
|
4690
4813
|
*/
|
|
@@ -4825,6 +4948,13 @@ interface Os {
|
|
|
4825
4948
|
*/
|
|
4826
4949
|
endAudioRecording(): Promise<Blob>;
|
|
4827
4950
|
|
|
4951
|
+
/**
|
|
4952
|
+
* Sends a command to the Jitsi Meet API.
|
|
4953
|
+
* @param command The name of the command to execute.
|
|
4954
|
+
* @param args The arguments for the command (if any).
|
|
4955
|
+
*/
|
|
4956
|
+
meetCommand(command: string, ...args: any[]): MeetCommandAction;
|
|
4957
|
+
|
|
4828
4958
|
/**
|
|
4829
4959
|
* Shows a QR Code that contains a link to a inst and dimension.
|
|
4830
4960
|
* @param inst The inst that should be joined. Defaults to the current inst.
|
|
@@ -5263,6 +5393,13 @@ interface Os {
|
|
|
5263
5393
|
address: string
|
|
5264
5394
|
): Promise<GetDataResult>;
|
|
5265
5395
|
|
|
5396
|
+
/**
|
|
5397
|
+
* Lists the data stored in the given record starting with the given address.
|
|
5398
|
+
* @param recordKeyOrName The record that the data should be retrieved from.
|
|
5399
|
+
* @param startingAddress The address that the list should start with.
|
|
5400
|
+
*/
|
|
5401
|
+
listData(recordKeyOrName: string, startingAddress?: string): Promise<ListDataResult>;
|
|
5402
|
+
|
|
5266
5403
|
/**
|
|
5267
5404
|
* Erases the data stored in the given record at the given address.
|
|
5268
5405
|
* @param recordKey The key that should be used to access the record.
|
|
@@ -5352,6 +5489,20 @@ interface Os {
|
|
|
5352
5489
|
*/
|
|
5353
5490
|
eraseFile(recordKey: string, fileUrlOrRecordFileResult: string | RecordFileSuccess): Promise<EraseFileResult>;
|
|
5354
5491
|
|
|
5492
|
+
/**
|
|
5493
|
+
* Records that the given event occurred.
|
|
5494
|
+
* @param recordKey The key that should be used to record the event.
|
|
5495
|
+
* @param eventName The name of the event.
|
|
5496
|
+
*/
|
|
5497
|
+
recordEvent(recordKey: string, eventName: string): Promise<AddCountResult>;
|
|
5498
|
+
|
|
5499
|
+
/**
|
|
5500
|
+
* Gets the number of times that the given event has been recorded.
|
|
5501
|
+
* @param recordNameOrKey The record that the event count should be retrieved from.
|
|
5502
|
+
* @param eventName The name of the event.
|
|
5503
|
+
*/
|
|
5504
|
+
countEvents(recordNameOrKey: string, eventName: string): Promise<GetCountResult>;
|
|
5505
|
+
|
|
5355
5506
|
/**
|
|
5356
5507
|
* Converts the given geolocation to a what3words (https://what3words.com/) address.
|
|
5357
5508
|
* @param location The latitude and longitude that should be converted to a 3 word address.
|
package/runtime/README.md
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
# AUX Runtime
|
|
2
|
-
|
|
3
|
-
The runtime of AUX is a set of services and utilities that make it possible to execute user scripts in a performant manner.
|
|
4
|
-
|
|
5
|
-
## Goals
|
|
6
|
-
|
|
7
|
-
### 1. Full JavaScript support.
|
|
8
|
-
|
|
9
|
-
The runtime should support all of the JavaScript features that the underlying browser supports and should encourage traditional JavaScript syntax and semantics instead of custom tricks.
|
|
10
|
-
|
|
11
|
-
The runtime may provide polyfills for unsupported features and may also insert additional code for the sake of debugging, tracing, error handling, or "performance management". "performance management" in this case means doing things like adding infinite loop detection and handling other common scenarios that can cause a user script to lock up the rest of the system. (See #2)
|
|
12
|
-
|
|
13
|
-
### 2. Doesn't lock up the system
|
|
14
|
-
|
|
15
|
-
The runtime should be able to supervise user scripts so that a bad behaving script can be caught and stopped to prevent the system from getting locked up. This is important since a script that locks up the system can prevent the processing of bot update events which can cause the issue to be unfixable.
|
|
16
|
-
|
|
17
|
-
### 3. Rich APIs
|
|
18
|
-
|
|
19
|
-
The runtime should be able to provide a rich set of APIs to user scripts. This means dispatching actions, synchronous queries, asynchronous queries, updating bots, and more.
|
|
20
|
-
|
|
21
|
-
Some specific needs:
|
|
22
|
-
|
|
23
|
-
- Some APIs need to know which bot is calling into it.
|
|
24
|
-
- APIs need to be able to edit bots such that the edits are immediately available to scripts.
|
|
25
|
-
- APIs need to be able to query current bot data.
|
|
26
|
-
- APIs need to enqueue actions.
|
|
27
|
-
- Some APIs need to know how to get the current player bot.
|
|
28
|
-
- Some APIs need to know the current energy state of the system.
|
|
29
|
-
|
|
30
|
-
See the [current API documentation](https://docs.casualsimulation.com/docs/actions) for examples.
|
|
31
|
-
|
|
32
|
-
### 4. Low Overhead
|
|
33
|
-
|
|
34
|
-
The runtime should pre-compile as much user-code as possible to reduce latency and general overhead. Sending a shout into the runtime should be as simple as looping through bots and calling the compiled function.
|
|
35
|
-
|
|
36
|
-
In the old system, sending a shout involves building the correct state, finding the bots with listeners, sorting the resulting bots, setting up the variables, and evaluating it. Most of the performance hit occurs due to lots of data copying and the deepening of the stack trace. Each shout adds about 10 extra stack frames which can compound over time.
|
|
37
|
-
|
|
38
|
-
### 5. Great developer experience
|
|
39
|
-
|
|
40
|
-
The runtime should enable a great developer experience by exposing metadata to assist with common operations like error handling and logging. Error stack traces should be walkable and traceable back to the original source. APIs should have type definitions so that code editing is a breeze.
|
|
41
|
-
|
|
42
|
-
## Constraints
|
|
43
|
-
|
|
44
|
-
The AUX Runtime has a couple of weird edge cases that it needs to work with. In particular, it needs to handle the following:
|
|
45
|
-
|
|
46
|
-
### Modifying unchangable bots
|
|
47
|
-
|
|
48
|
-
Bots can have any number of rules accociated with how they can be modified. Most bots allow all modifications and their storage spaces have robust rules for handling those modifications. However, some bot spaces have specialized rules.
|
|
49
|
-
|
|
50
|
-
For example:
|
|
51
|
-
|
|
52
|
-
- The `history` partition prevents all edits. Bot in the partition cannot be added, removed or updated.
|
|
53
|
-
- The `error` partition only allows creating bots. Once a bot is created, it cannot be updated or removed.
|
|
54
|
-
|
|
55
|
-
This causes a weird challenge with a persistent runtime environment. In the previous system the runtime environment would be created and subsequently destroyed when finished executing. This allowed edits to restricted bots to be made but the changes would be reverted once the runtime environment was re-created. With the new system, we need to track changes and whether they have been successful or not so that they can be reverted to prevent the system from deviating too far from the actual result.
|
|
56
|
-
|
|
57
|
-
The question is whether to use an optimistic model, a pessimistic model, or a synchronous model.
|
|
58
|
-
Basically, the pessimistic model assumes every write will fail while the optimistic model assumes every write will succeed. This is in contrast to the synchronous one which will validate each write with the partition as it is made.
|
|
59
|
-
|
|
60
|
-
The current system is pessimistic since it clears all changes after submitting them for persistence. This ensures that the data is always as close as possible to what is stored but can cause some weird anomalies. For example, two immediate shouts into the system can see very different data.
|
|
61
|
-
|
|
62
|
-
On the other hand, an optimistic model will preserve edits during persistence but then relies on additional communication to ensure that the runtime does not deviate too much.
|
|
63
|
-
If a write fails, then that failure needs to be communicated to the runtime so it can revert the changes. Due to the nature of storage, networking, and persistence,
|
|
64
|
-
it is often impossible to predict whether a particular write will pass or fail.
|
|
65
|
-
This fact makes handling failures more challenging than the pessimistic model.
|
|
66
|
-
|
|
67
|
-
Finally, the synchronous model will check each edit once it occurs to see if it is valid.
|
|
68
|
-
This may be appealing at first but there are a couple of obvious issues. Most notably, some partitions are split between threads and so cannot be run synchronosuly without greatly complicating their architecture. Additionally, the performance cost of checking each individual edit is likely quite high. Finally, data producing functions would need to be modified to surface these errors otherwise we risk users running into difficult to debug issues. (e.g. `create()` succeeds but no bot was actually created. Subsequent code likely depends on the bot actually existing after the function call.)
|
|
69
|
-
|
|
70
|
-
Let's go over some pros and cons:
|
|
71
|
-
|
|
72
|
-
#### Pessimistic Model
|
|
73
|
-
|
|
74
|
-
Assumes that changes will be denied by the partition.
|
|
75
|
-
|
|
76
|
-
_Pros:_
|
|
77
|
-
|
|
78
|
-
- Simple to implement.
|
|
79
|
-
- Ensures that the data never drifts too far from the actual.
|
|
80
|
-
|
|
81
|
-
_Cons:_
|
|
82
|
-
|
|
83
|
-
- Subsequent calls can see very different data even if the changes were valid.
|
|
84
|
-
- This makes properly handling async basically impossible.
|
|
85
|
-
- Also is more likely to happen in larger simulations since partitions run asynchronously.
|
|
86
|
-
- Scripts may see invalid data.
|
|
87
|
-
- This can happen because edits are accepted in-memory before being submitted to the partitions.
|
|
88
|
-
|
|
89
|
-
#### Optimistic model
|
|
90
|
-
|
|
91
|
-
Assumes that changes will be accepted by the partition.
|
|
92
|
-
|
|
93
|
-
_Pros:_
|
|
94
|
-
|
|
95
|
-
- Subsequent calls will see the same data.
|
|
96
|
-
- Async works out of the box without tons of edge cases.
|
|
97
|
-
|
|
98
|
-
_Cons:_
|
|
99
|
-
|
|
100
|
-
- Scripts may see invalid data.
|
|
101
|
-
- This can happen because edits are accepted in-memory before being submitted to the partitions.
|
|
102
|
-
- Difficult to implement.
|
|
103
|
-
- Rejected changes need to be sent back to the runtime so it can be updated.
|
|
104
|
-
- Runtime may drift from the actual over time due to communication issues.
|
|
105
|
-
|
|
106
|
-
#### Synchronous model
|
|
107
|
-
|
|
108
|
-
Checks each edit against a partition's storage rules.
|
|
109
|
-
|
|
110
|
-
_Pros:_
|
|
111
|
-
|
|
112
|
-
- Subsequent calls will see the same data.
|
|
113
|
-
- Async works out of the box.
|
|
114
|
-
- Scripts never see invalid data.
|
|
115
|
-
|
|
116
|
-
_Cons:_
|
|
117
|
-
|
|
118
|
-
- Difficult to implement.
|
|
119
|
-
- Requires additional changes to the runtime interface.
|
|
120
|
-
- All edits need to be checked.
|
|
121
|
-
- May be impossible depending on the implementation strategy.
|
|
122
|
-
|
|
123
|
-
#### Partitions
|
|
124
|
-
|
|
125
|
-
Let's talk about partitions. They seem to be an important factor in deciding which strategy to use. Partitions are persistent storage mechanisms for bots. When a bot is added to a universe, it is stored in a partition. Just like a normal file system, partitions are separate from each other and show up as different spaces. Unlinke a normal file system, partitions define the rules for how the data is stored. Normally, that honor goes to the actual storage device. (HDD, SSD, Flash Memory, Network, etc.)
|
|
126
|
-
In our case, partitions handle both. Additionally, partitions are expected to provide certain guarentees. In particular:
|
|
127
|
-
|
|
128
|
-
- All partition operations are expected to succeed.
|
|
129
|
-
- Basically, it must not error and must automatically resolve conflicts with concurrent edits.
|
|
130
|
-
- Partitions may decide to drop edits for any reason.
|
|
131
|
-
- Partitions must emit events representing changes to its data.
|
|
132
|
-
- Partitions must provide a snapshot of their current state.
|
|
133
|
-
|
|
134
|
-
These rules are pretty simple but predicting the result of an operation can be difficult when a partition can drop an edit due to bullet point 2. Note that in order to predict the result of an edit we need to know 2 things:
|
|
135
|
-
|
|
136
|
-
- Which partition the edit is for.
|
|
137
|
-
- Whether the partition supports/accepts the edit.
|
|
138
|
-
|
|
139
|
-
If we change bullet point 2 to be more restrictive, then we can support the synchronous model. So instead of allowing dropped edits for any reason, we should change it to allow dropped edits for a _specific set of reasons_. In particular, a partition must support a particular realtime edit strategy. Here are the three strategies:
|
|
140
|
-
|
|
141
|
-
- `immediate` - Realtime edits are supported and will produce update events once processed.
|
|
142
|
-
- `delayed` - Realtime edits are not supported. Edits may be used to update some non-local state. Update events may be produced at some point in the future. (supports history and error partitions)
|
|
143
|
-
|
|
144
|
-
Using these rules, we can decide whether an edit should update the bot's runtime data or if it should simply send the events to the partition.
|