@autobe/ui 0.30.0-dev.20260315 → 0.30.0
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/LICENSE +661 -661
- package/lib/components/AutoBeChatMain.js +5 -5
- package/lib/components/AutoBeConfigModal.js +9 -9
- package/package.json +2 -2
- package/src/components/AutoBeAssistantMessageMovie.tsx +22 -22
- package/src/components/AutoBeChatMain.tsx +376 -376
- package/src/components/AutoBeChatSidebar.tsx +414 -414
- package/src/components/AutoBeConfigButton.tsx +83 -83
- package/src/components/AutoBeConfigModal.tsx +443 -443
- package/src/components/AutoBeStatusButton.tsx +75 -75
- package/src/components/AutoBeStatusModal.tsx +486 -486
- package/src/components/AutoBeUserMessageMovie.tsx +27 -27
- package/src/components/common/ActionButton.tsx +205 -205
- package/src/components/common/ActionButtonGroup.tsx +80 -80
- package/src/components/common/AutoBeConfigInput.tsx +185 -185
- package/src/components/common/ChatBubble.tsx +119 -119
- package/src/components/common/Collapsible.tsx +95 -95
- package/src/components/common/CompactSessionIndicator.tsx +73 -73
- package/src/components/common/CompactSessionList.tsx +82 -82
- package/src/components/common/index.ts +8 -8
- package/src/components/common/openai/OpenAIContent.tsx +53 -53
- package/src/components/common/openai/OpenAIUserAudioContent.tsx +70 -70
- package/src/components/common/openai/OpenAIUserFileContent.tsx +76 -76
- package/src/components/common/openai/OpenAIUserImageContent.tsx +34 -34
- package/src/components/common/openai/OpenAIUserTextContent.tsx +15 -15
- package/src/components/common/openai/index.ts +5 -5
- package/src/components/events/AutoBeCompleteEventMovie.tsx +402 -402
- package/src/components/events/AutoBeCorrectEventMovie.tsx +354 -354
- package/src/components/events/AutoBeEventGroupMovie.tsx +18 -18
- package/src/components/events/AutoBeEventMovie.tsx +158 -158
- package/src/components/events/AutoBeProgressEventMovie.tsx +217 -217
- package/src/components/events/AutoBeScenarioEventMovie.tsx +135 -135
- package/src/components/events/AutoBeStartEventMovie.tsx +82 -82
- package/src/components/events/AutoBeValidateEventMovie.tsx +249 -249
- package/src/components/events/README.md +300 -300
- package/src/components/events/common/CollapsibleEventGroup.tsx +211 -211
- package/src/components/events/common/EventCard.tsx +61 -61
- package/src/components/events/common/EventContent.tsx +31 -31
- package/src/components/events/common/EventHeader.tsx +85 -85
- package/src/components/events/common/EventIcon.tsx +82 -82
- package/src/components/events/common/ProgressBar.tsx +64 -64
- package/src/components/events/common/index.ts +13 -13
- package/src/components/events/groups/CorrectEventGroup.tsx +183 -183
- package/src/components/events/groups/ValidateEventGroup.tsx +143 -143
- package/src/components/events/groups/index.ts +8 -8
- package/src/components/events/index.ts +16 -16
- package/src/components/events/utils/eventGrouper.tsx +116 -116
- package/src/components/events/utils/index.ts +1 -1
- package/src/components/index.ts +13 -13
- package/src/components/upload/AutoBeChatUploadBox.tsx +425 -425
- package/src/components/upload/AutoBeChatUploadSendButton.tsx +66 -66
- package/src/components/upload/AutoBeFileUploadBox.tsx +123 -123
- package/src/components/upload/AutoBeUploadConfig.ts +5 -5
- package/src/components/upload/AutoBeVoiceRecoderButton.tsx +100 -100
- package/src/components/upload/index.ts +5 -5
- package/src/constant/color.ts +28 -28
- package/src/context/AutoBeAgentContext.tsx +245 -245
- package/src/context/AutoBeAgentSessionList.tsx +58 -58
- package/src/context/SearchParamsContext.tsx +49 -49
- package/src/hooks/index.ts +3 -3
- package/src/hooks/useEscapeKey.ts +24 -24
- package/src/hooks/useIsomorphicLayoutEffect.ts +8 -8
- package/src/hooks/useMediaQuery.ts +73 -73
- package/src/hooks/useSessionStorage.ts +10 -10
- package/src/icons/Receipt.tsx +74 -74
- package/src/index.ts +9 -9
- package/src/strategy/AutoBeAgentSessionStorageStrategy.ts +127 -127
- package/src/structure/AutoBeListener.ts +373 -373
- package/src/structure/AutoBeListenerState.ts +53 -53
- package/src/structure/IAutoBeAgentSessionStorageStrategy.ts +87 -87
- package/src/structure/IAutoBeEventGroup.ts +6 -6
- package/src/structure/index.ts +4 -4
- package/src/types/config.ts +44 -44
- package/src/types/index.ts +1 -1
- package/src/utils/AutoBeFileUploader.ts +279 -279
- package/src/utils/AutoBeVoiceRecorder.ts +95 -95
- package/src/utils/__tests__/crypto.test.ts +286 -286
- package/src/utils/__tests__/storage.test.ts +229 -229
- package/src/utils/crypto.ts +95 -95
- package/src/utils/index.ts +6 -6
- package/src/utils/number.ts +17 -17
- package/src/utils/storage.ts +96 -96
- package/src/utils/time.ts +14 -14
- package/tsconfig.json +9 -9
- package/vitest.config.ts +15 -15
- package/README.md +0 -261
|
@@ -1,373 +1,373 @@
|
|
|
1
|
-
import { AutoBeEvent, IAutoBeRpcListener } from "@autobe/interface";
|
|
2
|
-
import { List } from "tstl";
|
|
3
|
-
|
|
4
|
-
import { AutoBeListenerState } from "./AutoBeListenerState";
|
|
5
|
-
import { IAutoBeEventGroup } from "./IAutoBeEventGroup";
|
|
6
|
-
|
|
7
|
-
export class AutoBeListener {
|
|
8
|
-
private callback_: Set<(eventGroups: IAutoBeEventGroup[]) => Promise<void>>;
|
|
9
|
-
private onEnableCallback_: Set<(value: boolean) => Promise<void>>;
|
|
10
|
-
|
|
11
|
-
private listener_: Required<IAutoBeRpcListener>;
|
|
12
|
-
private events_: List<IAutoBeEventGroup> = new List();
|
|
13
|
-
private dict_: Map<AutoBeEvent.Type, List.Iterator<IAutoBeEventGroup>> =
|
|
14
|
-
new Map();
|
|
15
|
-
private enable_: boolean = false;
|
|
16
|
-
private readonly state_: AutoBeListenerState;
|
|
17
|
-
|
|
18
|
-
public constructor() {
|
|
19
|
-
this.callback_ = new Set();
|
|
20
|
-
this.onEnableCallback_ = new Set();
|
|
21
|
-
|
|
22
|
-
this.state_ = new AutoBeListenerState();
|
|
23
|
-
this.listener_ = {
|
|
24
|
-
enable: async (value) => {
|
|
25
|
-
this.enable_ = value;
|
|
26
|
-
this.onEnableCallback_.forEach((callback) =>
|
|
27
|
-
callback(value).catch(() => {}),
|
|
28
|
-
);
|
|
29
|
-
},
|
|
30
|
-
assistantMessage: async (event) => {
|
|
31
|
-
this.insert(event);
|
|
32
|
-
},
|
|
33
|
-
userMessage: async (event) => {
|
|
34
|
-
this.insert(event);
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
// DESCRIBE
|
|
38
|
-
imageDescribeStart: async (event) => {
|
|
39
|
-
this.dict_.delete("imageDescribeDraft");
|
|
40
|
-
this.insert(event);
|
|
41
|
-
},
|
|
42
|
-
imageDescribeDraft: async (event) => {
|
|
43
|
-
this.insert(event);
|
|
44
|
-
},
|
|
45
|
-
imageDescribeComplete: async (event) => {
|
|
46
|
-
this.dict_.delete("imageDescribeDraft");
|
|
47
|
-
this.insert(event);
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
// ANALYZE
|
|
51
|
-
analyzeStart: async (event) => {
|
|
52
|
-
this.dict_.delete("analyzeWriteModule");
|
|
53
|
-
this.dict_.delete("analyzeModuleReview");
|
|
54
|
-
this.dict_.delete("analyzeWriteUnit");
|
|
55
|
-
this.dict_.delete("analyzeUnitReview");
|
|
56
|
-
this.dict_.delete("analyzeWriteSection");
|
|
57
|
-
this.dict_.delete("analyzeSectionReview");
|
|
58
|
-
this.insert(event);
|
|
59
|
-
},
|
|
60
|
-
analyzeScenario: async (event) => {
|
|
61
|
-
this.accumulate(event);
|
|
62
|
-
},
|
|
63
|
-
analyzeWriteModule: async (event) => {
|
|
64
|
-
this.accumulate(event);
|
|
65
|
-
},
|
|
66
|
-
analyzeModuleReview: async (event) => {
|
|
67
|
-
this.accumulate(event);
|
|
68
|
-
},
|
|
69
|
-
analyzeWriteUnit: async (event) => {
|
|
70
|
-
this.accumulate(event);
|
|
71
|
-
},
|
|
72
|
-
analyzeUnitReview: async (event) => {
|
|
73
|
-
this.accumulate(event);
|
|
74
|
-
},
|
|
75
|
-
analyzeWriteSection: async (event) => {
|
|
76
|
-
this.accumulate(event);
|
|
77
|
-
},
|
|
78
|
-
analyzeSectionReview: async (event) => {
|
|
79
|
-
this.accumulate(event);
|
|
80
|
-
},
|
|
81
|
-
analyzeScenarioReview: async (event) => {
|
|
82
|
-
this.accumulate(event);
|
|
83
|
-
},
|
|
84
|
-
analyzeComplete: async (event) => {
|
|
85
|
-
this.dict_.delete("analyzeWriteModule");
|
|
86
|
-
this.dict_.delete("analyzeModuleReview");
|
|
87
|
-
this.dict_.delete("analyzeWriteUnit");
|
|
88
|
-
this.dict_.delete("analyzeUnitReview");
|
|
89
|
-
this.dict_.delete("analyzeWriteSection");
|
|
90
|
-
this.dict_.delete("analyzeSectionReview");
|
|
91
|
-
this.state_.setAnalyze(event);
|
|
92
|
-
this.insert(event);
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
// PRISMA
|
|
96
|
-
databaseStart: async (event) => {
|
|
97
|
-
this.dict_.delete("databaseAuthorizationReview");
|
|
98
|
-
this.dict_.delete("databaseComponent");
|
|
99
|
-
this.dict_.delete("databaseComponentReview");
|
|
100
|
-
this.dict_.delete("databaseSchema");
|
|
101
|
-
this.dict_.delete("databaseSchemaReview");
|
|
102
|
-
this.insert(event);
|
|
103
|
-
},
|
|
104
|
-
databaseGroup: async (event) => {
|
|
105
|
-
this.insert(event);
|
|
106
|
-
},
|
|
107
|
-
databaseGroupReview: async (event) => {
|
|
108
|
-
this.insert(event);
|
|
109
|
-
},
|
|
110
|
-
databaseAuthorization: async (event) => {
|
|
111
|
-
this.accumulate(event);
|
|
112
|
-
},
|
|
113
|
-
databaseAuthorizationReview: async (event) => {
|
|
114
|
-
this.accumulate(event);
|
|
115
|
-
},
|
|
116
|
-
databaseComponent: async (event) => {
|
|
117
|
-
this.accumulate(event);
|
|
118
|
-
},
|
|
119
|
-
databaseComponentReview: async (event) => {
|
|
120
|
-
this.accumulate(event);
|
|
121
|
-
},
|
|
122
|
-
databaseSchema: async (event) => {
|
|
123
|
-
this.accumulate(event);
|
|
124
|
-
},
|
|
125
|
-
databaseSchemaReview: async (event) => {
|
|
126
|
-
this.accumulate(event);
|
|
127
|
-
},
|
|
128
|
-
databaseValidate: async (event) => {
|
|
129
|
-
this.insert(event);
|
|
130
|
-
},
|
|
131
|
-
databaseCorrect: async (event) => {
|
|
132
|
-
this.insert(event);
|
|
133
|
-
},
|
|
134
|
-
databaseComplete: async (event) => {
|
|
135
|
-
this.dict_.delete("databaseAuthorizationReview");
|
|
136
|
-
this.dict_.delete("databaseComponent");
|
|
137
|
-
this.dict_.delete("databaseComponentReview");
|
|
138
|
-
this.dict_.delete("databaseSchema");
|
|
139
|
-
this.dict_.delete("databaseSchemaReview");
|
|
140
|
-
this.state_.setDatabase(event);
|
|
141
|
-
this.insert(event);
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
// INTERFACE
|
|
145
|
-
interfaceStart: async (event) => {
|
|
146
|
-
this.dict_.delete("interfaceAuthorization");
|
|
147
|
-
this.dict_.delete("interfaceEndpoint");
|
|
148
|
-
this.dict_.delete("interfaceOperation");
|
|
149
|
-
this.dict_.delete("interfaceOperationReview");
|
|
150
|
-
this.dict_.delete("interfaceSchema");
|
|
151
|
-
this.dict_.delete("interfaceSchemaCasting");
|
|
152
|
-
this.dict_.delete("interfaceSchemaRefine");
|
|
153
|
-
this.dict_.delete("interfaceSchemaReview");
|
|
154
|
-
this.dict_.delete("interfaceSchemaComplement");
|
|
155
|
-
this.dict_.delete("interfaceSchemaRename");
|
|
156
|
-
this.dict_.delete("interfacePrerequisite");
|
|
157
|
-
this.insert(event);
|
|
158
|
-
},
|
|
159
|
-
interfaceGroup: async (event) => {
|
|
160
|
-
this.insert(event);
|
|
161
|
-
},
|
|
162
|
-
interfaceEndpoint: async (event) => {
|
|
163
|
-
this.accumulate(event);
|
|
164
|
-
},
|
|
165
|
-
interfaceEndpointReview: async (event) => {
|
|
166
|
-
this.accumulate(event);
|
|
167
|
-
},
|
|
168
|
-
interfaceOperation: async (event) => {
|
|
169
|
-
this.accumulate(event);
|
|
170
|
-
},
|
|
171
|
-
interfaceOperationReview: async (event) => {
|
|
172
|
-
this.accumulate(event);
|
|
173
|
-
},
|
|
174
|
-
interfaceAuthorization: async (event) => {
|
|
175
|
-
this.accumulate(event);
|
|
176
|
-
},
|
|
177
|
-
interfaceSchema: async (event) => {
|
|
178
|
-
this.accumulate(event);
|
|
179
|
-
},
|
|
180
|
-
interfaceSchemaCasting: async (event) => {
|
|
181
|
-
this.accumulate(event);
|
|
182
|
-
},
|
|
183
|
-
interfaceSchemaRefine: async (event) => {
|
|
184
|
-
this.accumulate(event);
|
|
185
|
-
},
|
|
186
|
-
interfaceSchemaReview: async (event) => {
|
|
187
|
-
this.accumulate(event);
|
|
188
|
-
},
|
|
189
|
-
interfaceSchemaRename: async (event) => {
|
|
190
|
-
this.accumulate(event);
|
|
191
|
-
},
|
|
192
|
-
interfaceSchemaComplement: async (event) => {
|
|
193
|
-
this.accumulate(event);
|
|
194
|
-
},
|
|
195
|
-
interfacePrerequisite: async (event) => {
|
|
196
|
-
this.accumulate(event);
|
|
197
|
-
},
|
|
198
|
-
interfaceComplete: async (event) => {
|
|
199
|
-
this.dict_.delete("interfaceEndpoint");
|
|
200
|
-
this.dict_.delete("interfaceOperation");
|
|
201
|
-
this.dict_.delete("interfaceOperationReview");
|
|
202
|
-
this.dict_.delete("interfaceAuthorization");
|
|
203
|
-
this.dict_.delete("interfaceSchema");
|
|
204
|
-
this.dict_.delete("interfaceSchemaCasting");
|
|
205
|
-
this.dict_.delete("interfaceSchemaRefine");
|
|
206
|
-
this.dict_.delete("interfaceSchemaReview");
|
|
207
|
-
this.dict_.delete("interfaceSchemaRename");
|
|
208
|
-
this.dict_.delete("interfaceSchemaComplement");
|
|
209
|
-
this.dict_.delete("interfacePrerequisite");
|
|
210
|
-
this.state_.setInterface(event);
|
|
211
|
-
this.insert(event);
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
// TEST
|
|
215
|
-
testStart: async (event) => {
|
|
216
|
-
this.dict_.delete("testScenario");
|
|
217
|
-
this.dict_.delete("testWrite");
|
|
218
|
-
this.dict_.delete("testValidate");
|
|
219
|
-
this.dict_.delete("testCorrect");
|
|
220
|
-
this.insert(event);
|
|
221
|
-
},
|
|
222
|
-
testScenario: async (event) => {
|
|
223
|
-
this.accumulate(event);
|
|
224
|
-
},
|
|
225
|
-
testScenarioReview: async (event) => {
|
|
226
|
-
this.accumulate(event);
|
|
227
|
-
},
|
|
228
|
-
testWrite: async (event) => {
|
|
229
|
-
this.accumulate(event);
|
|
230
|
-
},
|
|
231
|
-
testValidate: async (event) => {
|
|
232
|
-
this.accumulate(event);
|
|
233
|
-
},
|
|
234
|
-
testCorrect: async (event) => {
|
|
235
|
-
this.accumulate(event);
|
|
236
|
-
},
|
|
237
|
-
testComplete: async (event) => {
|
|
238
|
-
this.dict_.delete("testScenario");
|
|
239
|
-
this.dict_.delete("testWrite");
|
|
240
|
-
this.dict_.delete("testValidate");
|
|
241
|
-
this.dict_.delete("testCorrect");
|
|
242
|
-
this.state_.setTest(event);
|
|
243
|
-
this.insert(event);
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
//----
|
|
247
|
-
// REALIZE
|
|
248
|
-
//----
|
|
249
|
-
// REALIZE-MAIN
|
|
250
|
-
realizeStart: async (event) => {
|
|
251
|
-
this.dict_.delete("realizePlan");
|
|
252
|
-
this.dict_.delete("realizeWrite");
|
|
253
|
-
this.dict_.delete("realizeValidate");
|
|
254
|
-
this.insert(event);
|
|
255
|
-
},
|
|
256
|
-
realizePlan: async (event) => {
|
|
257
|
-
this.accumulate(event);
|
|
258
|
-
},
|
|
259
|
-
realizeWrite: async (event) => {
|
|
260
|
-
this.accumulate(event);
|
|
261
|
-
},
|
|
262
|
-
realizeCorrect: async (event) => {
|
|
263
|
-
this.accumulate(event);
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
realizeValidate: async (event) => {
|
|
267
|
-
this.accumulate(event);
|
|
268
|
-
},
|
|
269
|
-
realizeComplete: async (event) => {
|
|
270
|
-
this.dict_.delete("realizePlan");
|
|
271
|
-
this.dict_.delete("realizeWrite");
|
|
272
|
-
this.dict_.delete("realizeValidate");
|
|
273
|
-
this.state_.setRealize(event);
|
|
274
|
-
this.insert(event);
|
|
275
|
-
},
|
|
276
|
-
// REALIZE-AUTHORIZATION
|
|
277
|
-
realizeAuthorizationStart: async (event) => {
|
|
278
|
-
this.dict_.delete("realizeAuthorizationWrite");
|
|
279
|
-
this.dict_.delete("realizeAuthorizationCorrect");
|
|
280
|
-
this.dict_.delete("realizeAuthorizationValidate");
|
|
281
|
-
this.insert(event);
|
|
282
|
-
},
|
|
283
|
-
realizeAuthorizationWrite: async (event) => {
|
|
284
|
-
this.accumulate(event);
|
|
285
|
-
},
|
|
286
|
-
realizeAuthorizationValidate: async (event) => {
|
|
287
|
-
this.accumulate(event);
|
|
288
|
-
},
|
|
289
|
-
realizeAuthorizationCorrect: async (event) => {
|
|
290
|
-
this.insert(event);
|
|
291
|
-
},
|
|
292
|
-
realizeAuthorizationComplete: async (event) => {
|
|
293
|
-
this.dict_.delete("realizeAuthorizationWrite");
|
|
294
|
-
this.dict_.delete("realizeAuthorizationCorrect");
|
|
295
|
-
this.dict_.delete("realizeAuthorizationValidate");
|
|
296
|
-
this.insert(event);
|
|
297
|
-
},
|
|
298
|
-
// REALILZE-TEST
|
|
299
|
-
realizeTestStart: async (event) => {
|
|
300
|
-
this.dict_.delete("realizeTestOperation");
|
|
301
|
-
this.insert(event);
|
|
302
|
-
},
|
|
303
|
-
realizeTestReset: async (event) => {
|
|
304
|
-
this.insert(event);
|
|
305
|
-
},
|
|
306
|
-
realizeTestOperation: async (event) => {
|
|
307
|
-
this.accumulate(event);
|
|
308
|
-
},
|
|
309
|
-
realizeTestComplete: async (event) => {
|
|
310
|
-
this.dict_.delete("realizeTestOperation");
|
|
311
|
-
this.insert(event);
|
|
312
|
-
},
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
public on(callback: (eventGroups: IAutoBeEventGroup[]) => Promise<void>) {
|
|
317
|
-
this.callback_.add(callback);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
public off(callback: (eventGroups: IAutoBeEventGroup[]) => Promise<void>) {
|
|
321
|
-
this.callback_.delete(callback);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
public getListener(): Required<IAutoBeRpcListener> {
|
|
325
|
-
return this.listener_;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
public getState(): AutoBeListenerState {
|
|
329
|
-
return this.state_;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
public getEnable(): boolean {
|
|
333
|
-
return this.enable_;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
public onEnable(callback: (value: boolean) => Promise<void>) {
|
|
337
|
-
this.onEnableCallback_.add(callback);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
public offEnable(callback: (value: boolean) => Promise<void>) {
|
|
341
|
-
this.onEnableCallback_.delete(callback);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
private accumulate(event: AutoBeEvent) {
|
|
345
|
-
const it: List.Iterator<IAutoBeEventGroup> | undefined = this.dict_.get(
|
|
346
|
-
event.type,
|
|
347
|
-
);
|
|
348
|
-
if (it === undefined)
|
|
349
|
-
this.dict_.set(
|
|
350
|
-
event.type,
|
|
351
|
-
this.events_.insert(this.events_.end(), {
|
|
352
|
-
type: event.type,
|
|
353
|
-
events: [event],
|
|
354
|
-
}),
|
|
355
|
-
);
|
|
356
|
-
else it.value.events.push(event);
|
|
357
|
-
this.dispatch();
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
private insert(event: AutoBeEvent) {
|
|
361
|
-
this.events_.push_back({
|
|
362
|
-
type: event.type,
|
|
363
|
-
events: [event],
|
|
364
|
-
});
|
|
365
|
-
this.dispatch();
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
private dispatch() {
|
|
369
|
-
this.callback_.forEach((callback) =>
|
|
370
|
-
callback(this.events_.toJSON()).catch(() => {}),
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
1
|
+
import { AutoBeEvent, IAutoBeRpcListener } from "@autobe/interface";
|
|
2
|
+
import { List } from "tstl";
|
|
3
|
+
|
|
4
|
+
import { AutoBeListenerState } from "./AutoBeListenerState";
|
|
5
|
+
import { IAutoBeEventGroup } from "./IAutoBeEventGroup";
|
|
6
|
+
|
|
7
|
+
export class AutoBeListener {
|
|
8
|
+
private callback_: Set<(eventGroups: IAutoBeEventGroup[]) => Promise<void>>;
|
|
9
|
+
private onEnableCallback_: Set<(value: boolean) => Promise<void>>;
|
|
10
|
+
|
|
11
|
+
private listener_: Required<IAutoBeRpcListener>;
|
|
12
|
+
private events_: List<IAutoBeEventGroup> = new List();
|
|
13
|
+
private dict_: Map<AutoBeEvent.Type, List.Iterator<IAutoBeEventGroup>> =
|
|
14
|
+
new Map();
|
|
15
|
+
private enable_: boolean = false;
|
|
16
|
+
private readonly state_: AutoBeListenerState;
|
|
17
|
+
|
|
18
|
+
public constructor() {
|
|
19
|
+
this.callback_ = new Set();
|
|
20
|
+
this.onEnableCallback_ = new Set();
|
|
21
|
+
|
|
22
|
+
this.state_ = new AutoBeListenerState();
|
|
23
|
+
this.listener_ = {
|
|
24
|
+
enable: async (value) => {
|
|
25
|
+
this.enable_ = value;
|
|
26
|
+
this.onEnableCallback_.forEach((callback) =>
|
|
27
|
+
callback(value).catch(() => {}),
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
assistantMessage: async (event) => {
|
|
31
|
+
this.insert(event);
|
|
32
|
+
},
|
|
33
|
+
userMessage: async (event) => {
|
|
34
|
+
this.insert(event);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
// DESCRIBE
|
|
38
|
+
imageDescribeStart: async (event) => {
|
|
39
|
+
this.dict_.delete("imageDescribeDraft");
|
|
40
|
+
this.insert(event);
|
|
41
|
+
},
|
|
42
|
+
imageDescribeDraft: async (event) => {
|
|
43
|
+
this.insert(event);
|
|
44
|
+
},
|
|
45
|
+
imageDescribeComplete: async (event) => {
|
|
46
|
+
this.dict_.delete("imageDescribeDraft");
|
|
47
|
+
this.insert(event);
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// ANALYZE
|
|
51
|
+
analyzeStart: async (event) => {
|
|
52
|
+
this.dict_.delete("analyzeWriteModule");
|
|
53
|
+
this.dict_.delete("analyzeModuleReview");
|
|
54
|
+
this.dict_.delete("analyzeWriteUnit");
|
|
55
|
+
this.dict_.delete("analyzeUnitReview");
|
|
56
|
+
this.dict_.delete("analyzeWriteSection");
|
|
57
|
+
this.dict_.delete("analyzeSectionReview");
|
|
58
|
+
this.insert(event);
|
|
59
|
+
},
|
|
60
|
+
analyzeScenario: async (event) => {
|
|
61
|
+
this.accumulate(event);
|
|
62
|
+
},
|
|
63
|
+
analyzeWriteModule: async (event) => {
|
|
64
|
+
this.accumulate(event);
|
|
65
|
+
},
|
|
66
|
+
analyzeModuleReview: async (event) => {
|
|
67
|
+
this.accumulate(event);
|
|
68
|
+
},
|
|
69
|
+
analyzeWriteUnit: async (event) => {
|
|
70
|
+
this.accumulate(event);
|
|
71
|
+
},
|
|
72
|
+
analyzeUnitReview: async (event) => {
|
|
73
|
+
this.accumulate(event);
|
|
74
|
+
},
|
|
75
|
+
analyzeWriteSection: async (event) => {
|
|
76
|
+
this.accumulate(event);
|
|
77
|
+
},
|
|
78
|
+
analyzeSectionReview: async (event) => {
|
|
79
|
+
this.accumulate(event);
|
|
80
|
+
},
|
|
81
|
+
analyzeScenarioReview: async (event) => {
|
|
82
|
+
this.accumulate(event);
|
|
83
|
+
},
|
|
84
|
+
analyzeComplete: async (event) => {
|
|
85
|
+
this.dict_.delete("analyzeWriteModule");
|
|
86
|
+
this.dict_.delete("analyzeModuleReview");
|
|
87
|
+
this.dict_.delete("analyzeWriteUnit");
|
|
88
|
+
this.dict_.delete("analyzeUnitReview");
|
|
89
|
+
this.dict_.delete("analyzeWriteSection");
|
|
90
|
+
this.dict_.delete("analyzeSectionReview");
|
|
91
|
+
this.state_.setAnalyze(event);
|
|
92
|
+
this.insert(event);
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
// PRISMA
|
|
96
|
+
databaseStart: async (event) => {
|
|
97
|
+
this.dict_.delete("databaseAuthorizationReview");
|
|
98
|
+
this.dict_.delete("databaseComponent");
|
|
99
|
+
this.dict_.delete("databaseComponentReview");
|
|
100
|
+
this.dict_.delete("databaseSchema");
|
|
101
|
+
this.dict_.delete("databaseSchemaReview");
|
|
102
|
+
this.insert(event);
|
|
103
|
+
},
|
|
104
|
+
databaseGroup: async (event) => {
|
|
105
|
+
this.insert(event);
|
|
106
|
+
},
|
|
107
|
+
databaseGroupReview: async (event) => {
|
|
108
|
+
this.insert(event);
|
|
109
|
+
},
|
|
110
|
+
databaseAuthorization: async (event) => {
|
|
111
|
+
this.accumulate(event);
|
|
112
|
+
},
|
|
113
|
+
databaseAuthorizationReview: async (event) => {
|
|
114
|
+
this.accumulate(event);
|
|
115
|
+
},
|
|
116
|
+
databaseComponent: async (event) => {
|
|
117
|
+
this.accumulate(event);
|
|
118
|
+
},
|
|
119
|
+
databaseComponentReview: async (event) => {
|
|
120
|
+
this.accumulate(event);
|
|
121
|
+
},
|
|
122
|
+
databaseSchema: async (event) => {
|
|
123
|
+
this.accumulate(event);
|
|
124
|
+
},
|
|
125
|
+
databaseSchemaReview: async (event) => {
|
|
126
|
+
this.accumulate(event);
|
|
127
|
+
},
|
|
128
|
+
databaseValidate: async (event) => {
|
|
129
|
+
this.insert(event);
|
|
130
|
+
},
|
|
131
|
+
databaseCorrect: async (event) => {
|
|
132
|
+
this.insert(event);
|
|
133
|
+
},
|
|
134
|
+
databaseComplete: async (event) => {
|
|
135
|
+
this.dict_.delete("databaseAuthorizationReview");
|
|
136
|
+
this.dict_.delete("databaseComponent");
|
|
137
|
+
this.dict_.delete("databaseComponentReview");
|
|
138
|
+
this.dict_.delete("databaseSchema");
|
|
139
|
+
this.dict_.delete("databaseSchemaReview");
|
|
140
|
+
this.state_.setDatabase(event);
|
|
141
|
+
this.insert(event);
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
// INTERFACE
|
|
145
|
+
interfaceStart: async (event) => {
|
|
146
|
+
this.dict_.delete("interfaceAuthorization");
|
|
147
|
+
this.dict_.delete("interfaceEndpoint");
|
|
148
|
+
this.dict_.delete("interfaceOperation");
|
|
149
|
+
this.dict_.delete("interfaceOperationReview");
|
|
150
|
+
this.dict_.delete("interfaceSchema");
|
|
151
|
+
this.dict_.delete("interfaceSchemaCasting");
|
|
152
|
+
this.dict_.delete("interfaceSchemaRefine");
|
|
153
|
+
this.dict_.delete("interfaceSchemaReview");
|
|
154
|
+
this.dict_.delete("interfaceSchemaComplement");
|
|
155
|
+
this.dict_.delete("interfaceSchemaRename");
|
|
156
|
+
this.dict_.delete("interfacePrerequisite");
|
|
157
|
+
this.insert(event);
|
|
158
|
+
},
|
|
159
|
+
interfaceGroup: async (event) => {
|
|
160
|
+
this.insert(event);
|
|
161
|
+
},
|
|
162
|
+
interfaceEndpoint: async (event) => {
|
|
163
|
+
this.accumulate(event);
|
|
164
|
+
},
|
|
165
|
+
interfaceEndpointReview: async (event) => {
|
|
166
|
+
this.accumulate(event);
|
|
167
|
+
},
|
|
168
|
+
interfaceOperation: async (event) => {
|
|
169
|
+
this.accumulate(event);
|
|
170
|
+
},
|
|
171
|
+
interfaceOperationReview: async (event) => {
|
|
172
|
+
this.accumulate(event);
|
|
173
|
+
},
|
|
174
|
+
interfaceAuthorization: async (event) => {
|
|
175
|
+
this.accumulate(event);
|
|
176
|
+
},
|
|
177
|
+
interfaceSchema: async (event) => {
|
|
178
|
+
this.accumulate(event);
|
|
179
|
+
},
|
|
180
|
+
interfaceSchemaCasting: async (event) => {
|
|
181
|
+
this.accumulate(event);
|
|
182
|
+
},
|
|
183
|
+
interfaceSchemaRefine: async (event) => {
|
|
184
|
+
this.accumulate(event);
|
|
185
|
+
},
|
|
186
|
+
interfaceSchemaReview: async (event) => {
|
|
187
|
+
this.accumulate(event);
|
|
188
|
+
},
|
|
189
|
+
interfaceSchemaRename: async (event) => {
|
|
190
|
+
this.accumulate(event);
|
|
191
|
+
},
|
|
192
|
+
interfaceSchemaComplement: async (event) => {
|
|
193
|
+
this.accumulate(event);
|
|
194
|
+
},
|
|
195
|
+
interfacePrerequisite: async (event) => {
|
|
196
|
+
this.accumulate(event);
|
|
197
|
+
},
|
|
198
|
+
interfaceComplete: async (event) => {
|
|
199
|
+
this.dict_.delete("interfaceEndpoint");
|
|
200
|
+
this.dict_.delete("interfaceOperation");
|
|
201
|
+
this.dict_.delete("interfaceOperationReview");
|
|
202
|
+
this.dict_.delete("interfaceAuthorization");
|
|
203
|
+
this.dict_.delete("interfaceSchema");
|
|
204
|
+
this.dict_.delete("interfaceSchemaCasting");
|
|
205
|
+
this.dict_.delete("interfaceSchemaRefine");
|
|
206
|
+
this.dict_.delete("interfaceSchemaReview");
|
|
207
|
+
this.dict_.delete("interfaceSchemaRename");
|
|
208
|
+
this.dict_.delete("interfaceSchemaComplement");
|
|
209
|
+
this.dict_.delete("interfacePrerequisite");
|
|
210
|
+
this.state_.setInterface(event);
|
|
211
|
+
this.insert(event);
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
// TEST
|
|
215
|
+
testStart: async (event) => {
|
|
216
|
+
this.dict_.delete("testScenario");
|
|
217
|
+
this.dict_.delete("testWrite");
|
|
218
|
+
this.dict_.delete("testValidate");
|
|
219
|
+
this.dict_.delete("testCorrect");
|
|
220
|
+
this.insert(event);
|
|
221
|
+
},
|
|
222
|
+
testScenario: async (event) => {
|
|
223
|
+
this.accumulate(event);
|
|
224
|
+
},
|
|
225
|
+
testScenarioReview: async (event) => {
|
|
226
|
+
this.accumulate(event);
|
|
227
|
+
},
|
|
228
|
+
testWrite: async (event) => {
|
|
229
|
+
this.accumulate(event);
|
|
230
|
+
},
|
|
231
|
+
testValidate: async (event) => {
|
|
232
|
+
this.accumulate(event);
|
|
233
|
+
},
|
|
234
|
+
testCorrect: async (event) => {
|
|
235
|
+
this.accumulate(event);
|
|
236
|
+
},
|
|
237
|
+
testComplete: async (event) => {
|
|
238
|
+
this.dict_.delete("testScenario");
|
|
239
|
+
this.dict_.delete("testWrite");
|
|
240
|
+
this.dict_.delete("testValidate");
|
|
241
|
+
this.dict_.delete("testCorrect");
|
|
242
|
+
this.state_.setTest(event);
|
|
243
|
+
this.insert(event);
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
//----
|
|
247
|
+
// REALIZE
|
|
248
|
+
//----
|
|
249
|
+
// REALIZE-MAIN
|
|
250
|
+
realizeStart: async (event) => {
|
|
251
|
+
this.dict_.delete("realizePlan");
|
|
252
|
+
this.dict_.delete("realizeWrite");
|
|
253
|
+
this.dict_.delete("realizeValidate");
|
|
254
|
+
this.insert(event);
|
|
255
|
+
},
|
|
256
|
+
realizePlan: async (event) => {
|
|
257
|
+
this.accumulate(event);
|
|
258
|
+
},
|
|
259
|
+
realizeWrite: async (event) => {
|
|
260
|
+
this.accumulate(event);
|
|
261
|
+
},
|
|
262
|
+
realizeCorrect: async (event) => {
|
|
263
|
+
this.accumulate(event);
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
realizeValidate: async (event) => {
|
|
267
|
+
this.accumulate(event);
|
|
268
|
+
},
|
|
269
|
+
realizeComplete: async (event) => {
|
|
270
|
+
this.dict_.delete("realizePlan");
|
|
271
|
+
this.dict_.delete("realizeWrite");
|
|
272
|
+
this.dict_.delete("realizeValidate");
|
|
273
|
+
this.state_.setRealize(event);
|
|
274
|
+
this.insert(event);
|
|
275
|
+
},
|
|
276
|
+
// REALIZE-AUTHORIZATION
|
|
277
|
+
realizeAuthorizationStart: async (event) => {
|
|
278
|
+
this.dict_.delete("realizeAuthorizationWrite");
|
|
279
|
+
this.dict_.delete("realizeAuthorizationCorrect");
|
|
280
|
+
this.dict_.delete("realizeAuthorizationValidate");
|
|
281
|
+
this.insert(event);
|
|
282
|
+
},
|
|
283
|
+
realizeAuthorizationWrite: async (event) => {
|
|
284
|
+
this.accumulate(event);
|
|
285
|
+
},
|
|
286
|
+
realizeAuthorizationValidate: async (event) => {
|
|
287
|
+
this.accumulate(event);
|
|
288
|
+
},
|
|
289
|
+
realizeAuthorizationCorrect: async (event) => {
|
|
290
|
+
this.insert(event);
|
|
291
|
+
},
|
|
292
|
+
realizeAuthorizationComplete: async (event) => {
|
|
293
|
+
this.dict_.delete("realizeAuthorizationWrite");
|
|
294
|
+
this.dict_.delete("realizeAuthorizationCorrect");
|
|
295
|
+
this.dict_.delete("realizeAuthorizationValidate");
|
|
296
|
+
this.insert(event);
|
|
297
|
+
},
|
|
298
|
+
// REALILZE-TEST
|
|
299
|
+
realizeTestStart: async (event) => {
|
|
300
|
+
this.dict_.delete("realizeTestOperation");
|
|
301
|
+
this.insert(event);
|
|
302
|
+
},
|
|
303
|
+
realizeTestReset: async (event) => {
|
|
304
|
+
this.insert(event);
|
|
305
|
+
},
|
|
306
|
+
realizeTestOperation: async (event) => {
|
|
307
|
+
this.accumulate(event);
|
|
308
|
+
},
|
|
309
|
+
realizeTestComplete: async (event) => {
|
|
310
|
+
this.dict_.delete("realizeTestOperation");
|
|
311
|
+
this.insert(event);
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
public on(callback: (eventGroups: IAutoBeEventGroup[]) => Promise<void>) {
|
|
317
|
+
this.callback_.add(callback);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public off(callback: (eventGroups: IAutoBeEventGroup[]) => Promise<void>) {
|
|
321
|
+
this.callback_.delete(callback);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
public getListener(): Required<IAutoBeRpcListener> {
|
|
325
|
+
return this.listener_;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
public getState(): AutoBeListenerState {
|
|
329
|
+
return this.state_;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
public getEnable(): boolean {
|
|
333
|
+
return this.enable_;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
public onEnable(callback: (value: boolean) => Promise<void>) {
|
|
337
|
+
this.onEnableCallback_.add(callback);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
public offEnable(callback: (value: boolean) => Promise<void>) {
|
|
341
|
+
this.onEnableCallback_.delete(callback);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
private accumulate(event: AutoBeEvent) {
|
|
345
|
+
const it: List.Iterator<IAutoBeEventGroup> | undefined = this.dict_.get(
|
|
346
|
+
event.type,
|
|
347
|
+
);
|
|
348
|
+
if (it === undefined)
|
|
349
|
+
this.dict_.set(
|
|
350
|
+
event.type,
|
|
351
|
+
this.events_.insert(this.events_.end(), {
|
|
352
|
+
type: event.type,
|
|
353
|
+
events: [event],
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
356
|
+
else it.value.events.push(event);
|
|
357
|
+
this.dispatch();
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
private insert(event: AutoBeEvent) {
|
|
361
|
+
this.events_.push_back({
|
|
362
|
+
type: event.type,
|
|
363
|
+
events: [event],
|
|
364
|
+
});
|
|
365
|
+
this.dispatch();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private dispatch() {
|
|
369
|
+
this.callback_.forEach((callback) =>
|
|
370
|
+
callback(this.events_.toJSON()).catch(() => {}),
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
}
|