@casual-simulation/aux-common 2.0.32 → 3.0.0-alpha.1826142686

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.
@@ -260,7 +260,8 @@ declare type AsyncActions =
260
260
  | GetVoicesAction
261
261
  | GetGeolocationAction
262
262
  | ARSupportedAction
263
- | VRSupportedAction;
263
+ | VRSupportedAction
264
+ | OpenImageClassifierAction;
264
265
 
265
266
  /**
266
267
  * Defines an interface for actions that represent asynchronous tasks.
@@ -872,6 +873,45 @@ declare interface ShowBarcodeAction extends Action {
872
873
  format: BarcodeFormat;
873
874
  }
874
875
 
876
+ /**
877
+ * An event that is used to show or hide an image classifier on screen.
878
+ */
879
+ export interface OpenImageClassifierAction extends AsyncAction {
880
+ type: 'show_image_classifier';
881
+
882
+ /**
883
+ * Whether the image classifier should be visible.
884
+ */
885
+ open: boolean;
886
+
887
+ /**
888
+ * The URL that the model should be loaded from.
889
+ */
890
+ modelUrl?: string;
891
+
892
+ /**
893
+ * The URL that the model JSON should be loaded from.
894
+ * Not required. Can be used if you are storing the model JSON in a custom location.
895
+ */
896
+ modelJsonUrl?: string;
897
+
898
+ /**
899
+ * The URL that the model metadata should be loaded from.
900
+ * Not required. Can be used if you are storing the model metadata in a custom location.
901
+ */
902
+ modelMetadataUrl?: string;
903
+
904
+ /**
905
+ * The camera that should be used for the image classifier.
906
+ */
907
+ cameraType?: CameraType;
908
+ }
909
+
910
+ export type ImageClassifierOptions = Pick<
911
+ OpenImageClassifierAction,
912
+ 'modelUrl' | 'modelJsonUrl' | 'modelMetadataUrl' | 'cameraType'
913
+ >;
914
+
875
915
  /**
876
916
  * An event that is used to load a simulation.
877
917
  */
@@ -2965,6 +3005,27 @@ export interface GetDataFailure {
2965
3005
  errorMessage: string;
2966
3006
  }
2967
3007
 
3008
+
3009
+ export type ListDataResult = ListDataSuccess | ListDataFailure;
3010
+
3011
+ export interface ListDataSuccess {
3012
+ success: true;
3013
+ recordName: string;
3014
+ items: {
3015
+ data: any;
3016
+ address: string;
3017
+ }[];
3018
+ }
3019
+
3020
+ export interface ListDataFailure {
3021
+ success: false;
3022
+ errorCode:
3023
+ | ServerError
3024
+ | NotSupportedError;
3025
+ errorMessage: string;
3026
+ }
3027
+
3028
+
2968
3029
  export type EraseDataResult = EraseDataSuccess | EraseDataFailure;
2969
3030
 
2970
3031
  export interface EraseDataSuccess {
@@ -3035,6 +3096,59 @@ export interface EraseFileFailure {
3035
3096
  errorMessage: string;
3036
3097
  }
3037
3098
 
3099
+
3100
+ export type AddCountResult = AddCountSuccess | AddCountFailure;
3101
+
3102
+ export interface AddCountSuccess {
3103
+ success: true;
3104
+ recordName: string;
3105
+ eventName: string;
3106
+ countAdded: number;
3107
+ }
3108
+
3109
+ export interface AddCountFailure {
3110
+ success: false;
3111
+ errorCode:
3112
+ | ServerError
3113
+ | NotLoggedInError
3114
+ | InvalidRecordKey
3115
+ | RecordNotFoundError
3116
+ | NotSupportedError
3117
+ errorMessage: string;
3118
+ }
3119
+
3120
+ export type GetCountResult = GetCountSuccess | GetCountFailure;
3121
+
3122
+ /**
3123
+ * Defines an interface that represents a successful "get data" result.
3124
+ */
3125
+ export interface GetCountSuccess {
3126
+ success: true;
3127
+
3128
+ /**
3129
+ * The total count of events.
3130
+ */
3131
+ count: number;
3132
+
3133
+ /**
3134
+ * The name of the record.
3135
+ */
3136
+ recordName: string;
3137
+
3138
+ /**
3139
+ * The name of the event.
3140
+ */
3141
+ eventName: string;
3142
+ }
3143
+
3144
+ export interface GetCountFailure {
3145
+ success: false;
3146
+ errorCode:
3147
+ | ServerError
3148
+ | NotSupportedError;
3149
+ errorMessage: string;
3150
+ }
3151
+
3038
3152
  export interface AudioRecordingOptions {
3039
3153
  /**
3040
3154
  * Whether to stream the audio recording.
@@ -4728,6 +4842,12 @@ interface Os {
4728
4842
  */
4729
4843
  isCollaborative(): boolean;
4730
4844
 
4845
+ /**
4846
+ * Gets media permission for the device.
4847
+ * Promise will resolve if permission was granted, otherwise an error will be thrown.
4848
+ */
4849
+ getMediaPermission(options: { audio?: boolean, video?: boolean }): Promise<void>;
4850
+
4731
4851
  /**
4732
4852
  * Gets the URL that AB1 should be bootstrapped from.
4733
4853
  */
@@ -5013,6 +5133,19 @@ interface Os {
5013
5133
  */
5014
5134
  hideBarcode(): ShowBarcodeAction;
5015
5135
 
5136
+ /**
5137
+ * Shows an image classifier for the given ML Model.
5138
+ * Returns a promise that resolves when the image classifier has been opened.
5139
+ * @param options The options for the classifier.
5140
+ */
5141
+ openImageClassifier(options: ImageClassifierOptions): Promise<void>;
5142
+
5143
+ /**
5144
+ * Closes the image classifier.
5145
+ * Returns a promise that resolves when the image classifier has been closed.
5146
+ */
5147
+ closeImageClassifier(): Promise<void>;
5148
+
5016
5149
  /**
5017
5150
  * Shows the chat bar.
5018
5151
  */
@@ -5313,6 +5446,13 @@ interface Os {
5313
5446
  address: string
5314
5447
  ): Promise<GetDataResult>;
5315
5448
 
5449
+ /**
5450
+ * Lists the data stored in the given record starting with the given address.
5451
+ * @param recordKeyOrName The record that the data should be retrieved from.
5452
+ * @param startingAddress The address that the list should start with.
5453
+ */
5454
+ listData(recordKeyOrName: string, startingAddress?: string): Promise<ListDataResult>;
5455
+
5316
5456
  /**
5317
5457
  * Erases the data stored in the given record at the given address.
5318
5458
  * @param recordKey The key that should be used to access the record.
@@ -5402,6 +5542,20 @@ interface Os {
5402
5542
  */
5403
5543
  eraseFile(recordKey: string, fileUrlOrRecordFileResult: string | RecordFileSuccess): Promise<EraseFileResult>;
5404
5544
 
5545
+ /**
5546
+ * Records that the given event occurred.
5547
+ * @param recordKey The key that should be used to record the event.
5548
+ * @param eventName The name of the event.
5549
+ */
5550
+ recordEvent(recordKey: string, eventName: string): Promise<AddCountResult>;
5551
+
5552
+ /**
5553
+ * Gets the number of times that the given event has been recorded.
5554
+ * @param recordNameOrKey The record that the event count should be retrieved from.
5555
+ * @param eventName The name of the event.
5556
+ */
5557
+ countEvents(recordNameOrKey: string, eventName: string): Promise<GetCountResult>;
5558
+
5405
5559
  /**
5406
5560
  * Converts the given geolocation to a what3words (https://what3words.com/) address.
5407
5561
  * @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.