@framers/agentos-ext-ml-classifiers 0.1.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.
Files changed (62) hide show
  1. package/LICENSE +23 -0
  2. package/dist/ClassifierOrchestrator.d.ts +126 -0
  3. package/dist/ClassifierOrchestrator.d.ts.map +1 -0
  4. package/dist/ClassifierOrchestrator.js +239 -0
  5. package/dist/ClassifierOrchestrator.js.map +1 -0
  6. package/dist/IContentClassifier.d.ts +117 -0
  7. package/dist/IContentClassifier.d.ts.map +1 -0
  8. package/dist/IContentClassifier.js +22 -0
  9. package/dist/IContentClassifier.js.map +1 -0
  10. package/dist/MLClassifierGuardrail.d.ts +163 -0
  11. package/dist/MLClassifierGuardrail.d.ts.map +1 -0
  12. package/dist/MLClassifierGuardrail.js +335 -0
  13. package/dist/MLClassifierGuardrail.js.map +1 -0
  14. package/dist/SlidingWindowBuffer.d.ts +213 -0
  15. package/dist/SlidingWindowBuffer.d.ts.map +1 -0
  16. package/dist/SlidingWindowBuffer.js +246 -0
  17. package/dist/SlidingWindowBuffer.js.map +1 -0
  18. package/dist/classifiers/InjectionClassifier.d.ts +126 -0
  19. package/dist/classifiers/InjectionClassifier.d.ts.map +1 -0
  20. package/dist/classifiers/InjectionClassifier.js +210 -0
  21. package/dist/classifiers/InjectionClassifier.js.map +1 -0
  22. package/dist/classifiers/JailbreakClassifier.d.ts +124 -0
  23. package/dist/classifiers/JailbreakClassifier.d.ts.map +1 -0
  24. package/dist/classifiers/JailbreakClassifier.js +208 -0
  25. package/dist/classifiers/JailbreakClassifier.js.map +1 -0
  26. package/dist/classifiers/ToxicityClassifier.d.ts +125 -0
  27. package/dist/classifiers/ToxicityClassifier.d.ts.map +1 -0
  28. package/dist/classifiers/ToxicityClassifier.js +212 -0
  29. package/dist/classifiers/ToxicityClassifier.js.map +1 -0
  30. package/dist/classifiers/WorkerClassifierProxy.d.ts +158 -0
  31. package/dist/classifiers/WorkerClassifierProxy.d.ts.map +1 -0
  32. package/dist/classifiers/WorkerClassifierProxy.js +268 -0
  33. package/dist/classifiers/WorkerClassifierProxy.js.map +1 -0
  34. package/dist/index.d.ts +110 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +342 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/tools/ClassifyContentTool.d.ts +105 -0
  39. package/dist/tools/ClassifyContentTool.d.ts.map +1 -0
  40. package/dist/tools/ClassifyContentTool.js +149 -0
  41. package/dist/tools/ClassifyContentTool.js.map +1 -0
  42. package/dist/types.d.ts +319 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/types.js +62 -0
  45. package/dist/types.js.map +1 -0
  46. package/dist/worker/classifier-worker.d.ts +49 -0
  47. package/dist/worker/classifier-worker.d.ts.map +1 -0
  48. package/dist/worker/classifier-worker.js +180 -0
  49. package/dist/worker/classifier-worker.js.map +1 -0
  50. package/package.json +45 -0
  51. package/src/ClassifierOrchestrator.ts +290 -0
  52. package/src/IContentClassifier.ts +124 -0
  53. package/src/MLClassifierGuardrail.ts +419 -0
  54. package/src/SlidingWindowBuffer.ts +384 -0
  55. package/src/classifiers/InjectionClassifier.ts +261 -0
  56. package/src/classifiers/JailbreakClassifier.ts +259 -0
  57. package/src/classifiers/ToxicityClassifier.ts +263 -0
  58. package/src/classifiers/WorkerClassifierProxy.ts +366 -0
  59. package/src/index.ts +383 -0
  60. package/src/tools/ClassifyContentTool.ts +201 -0
  61. package/src/types.ts +391 -0
  62. package/src/worker/classifier-worker.ts +267 -0
@@ -0,0 +1,268 @@
1
+ /**
2
+ * @fileoverview WorkerClassifierProxy — wraps an IContentClassifier to run
3
+ * inference inside a Web Worker, with automatic main-thread fallback.
4
+ *
5
+ * ## Why a proxy?
6
+ * ML inference (even quantized ONNX / WASM pipelines) can block the main
7
+ * thread for 50–500 ms per classification. Moving classification into a
8
+ * Web Worker keeps the UI responsive. This proxy makes the switch
9
+ * transparent to callers: they still call `classify(text)` and receive a
10
+ * `ClassificationResult`; the underlying transport (Worker vs. direct call)
11
+ * is an implementation detail.
12
+ *
13
+ * ## Fallback policy
14
+ * The proxy falls back to direct (main-thread) delegation whenever:
15
+ * - The global `Worker` constructor is undefined (Node.js, older browsers).
16
+ * - `browserConfig.useWebWorker` is explicitly `false`.
17
+ * - Worker creation throws (e.g. strict CSP that blocks `blob:` URLs).
18
+ *
19
+ * Once a fallback has been triggered by a Worker creation error the proxy
20
+ * sets `workerFailed = true` and remains in fallback mode for all subsequent
21
+ * calls.
22
+ *
23
+ * ## IContentClassifier contract
24
+ * The proxy forwards all identity fields (`id`, `displayName`, `description`,
25
+ * `modelId`) and the `isLoaded` state directly from the wrapped classifier so
26
+ * it is completely transparent to the orchestrator.
27
+ *
28
+ * @module agentos/extensions/packs/ml-classifiers/classifiers/WorkerClassifierProxy
29
+ */
30
+ // ---------------------------------------------------------------------------
31
+ // WorkerClassifierProxy
32
+ // ---------------------------------------------------------------------------
33
+ /**
34
+ * Transparent proxy around an {@link IContentClassifier} that offloads
35
+ * `classify()` calls to a Web Worker when the browser environment supports it.
36
+ *
37
+ * In all other environments (Node.js, strict CSP, explicit opt-out) the proxy
38
+ * delegates calls directly to the wrapped classifier on the main thread.
39
+ *
40
+ * @implements {IContentClassifier}
41
+ *
42
+ * @example Browser context — Web Worker path
43
+ * ```typescript
44
+ * const toxicity = new ToxicityClassifier(serviceRegistry);
45
+ * const proxy = new WorkerClassifierProxy(toxicity, { useWebWorker: true });
46
+ * const result = await proxy.classify('some text');
47
+ * ```
48
+ *
49
+ * @example Node.js / forced fallback path
50
+ * ```typescript
51
+ * const proxy = new WorkerClassifierProxy(toxicity, { useWebWorker: false });
52
+ * // Delegates directly to toxicity.classify() on the same thread.
53
+ * ```
54
+ */
55
+ export class WorkerClassifierProxy {
56
+ wrapped;
57
+ browserConfig;
58
+ // -------------------------------------------------------------------------
59
+ // IContentClassifier identity — delegated from wrapped classifier
60
+ // -------------------------------------------------------------------------
61
+ /**
62
+ * {@inheritDoc IContentClassifier.id}
63
+ * Delegated from the wrapped classifier so this proxy is transparent in
64
+ * the orchestrator's service-ID lookups.
65
+ */
66
+ get id() {
67
+ return this.wrapped.id;
68
+ }
69
+ /**
70
+ * {@inheritDoc IContentClassifier.displayName}
71
+ * Returns the wrapped classifier's display name with a `(Worker)` suffix
72
+ * when the Web Worker path is active, so logs clearly indicate the mode.
73
+ */
74
+ get displayName() {
75
+ return this.wrapped.displayName;
76
+ }
77
+ /**
78
+ * {@inheritDoc IContentClassifier.description}
79
+ * Delegated directly from the wrapped classifier.
80
+ */
81
+ get description() {
82
+ return this.wrapped.description;
83
+ }
84
+ /**
85
+ * {@inheritDoc IContentClassifier.modelId}
86
+ * Delegated directly from the wrapped classifier.
87
+ */
88
+ get modelId() {
89
+ return this.wrapped.modelId;
90
+ }
91
+ /**
92
+ * {@inheritDoc IContentClassifier.isLoaded}
93
+ *
94
+ * Reflects the wrapped classifier's `isLoaded` state. The wrapped
95
+ * instance is the authoritative source because it owns the model weights
96
+ * (whether they live in the Worker or on the main thread).
97
+ */
98
+ get isLoaded() {
99
+ return this.wrapped.isLoaded;
100
+ }
101
+ /**
102
+ * IContentClassifier requires `isLoaded` to be settable via the interface
103
+ * contract (`isLoaded: boolean`). We store the value through the wrapped
104
+ * classifier so the authoritative state lives in one place.
105
+ */
106
+ set isLoaded(value) {
107
+ this.wrapped.isLoaded = value;
108
+ }
109
+ // -------------------------------------------------------------------------
110
+ // Internal state
111
+ // -------------------------------------------------------------------------
112
+ /**
113
+ * Set to `true` after a Worker creation failure. Once set, all subsequent
114
+ * `classify()` calls are routed directly to the wrapped classifier without
115
+ * attempting to re-create the Worker.
116
+ */
117
+ workerFailed = false;
118
+ // -------------------------------------------------------------------------
119
+ // Constructor
120
+ // -------------------------------------------------------------------------
121
+ /**
122
+ * Create a WorkerClassifierProxy.
123
+ *
124
+ * @param wrapped - The real classifier to delegate to. In Worker
125
+ * mode this classifier is still responsible for
126
+ * model loading and inference; the proxy just
127
+ * changes the thread on which it executes.
128
+ * @param browserConfig - Optional browser-side configuration. Controls
129
+ * whether Worker mode is attempted
130
+ * (`useWebWorker`, default `true`).
131
+ */
132
+ constructor(wrapped, browserConfig) {
133
+ this.wrapped = wrapped;
134
+ this.browserConfig = browserConfig;
135
+ }
136
+ // -------------------------------------------------------------------------
137
+ // classify
138
+ // -------------------------------------------------------------------------
139
+ /**
140
+ * Classify the provided text, routing to a Web Worker when available.
141
+ *
142
+ * ### Routing decision (evaluated once per call)
143
+ * 1. `typeof Worker === 'undefined'` → fallback (Node.js / no Worker API).
144
+ * 2. `browserConfig.useWebWorker === false` → fallback (explicit opt-out).
145
+ * 3. `workerFailed === true` → fallback (previous Worker creation error).
146
+ * 4. Otherwise → attempt to run in a Web Worker.
147
+ *
148
+ * If the Worker is created but fails to post a result within the
149
+ * classification request, the error is propagated as a rejected promise
150
+ * (not silently swallowed) so the orchestrator can log and fall back at
151
+ * a higher level.
152
+ *
153
+ * @param text - The text to classify. Must not be empty.
154
+ * @returns A promise that resolves with the classification result.
155
+ */
156
+ async classify(text) {
157
+ // Determine whether to use a Web Worker.
158
+ const shouldUseWorker = this.shouldUseWebWorker();
159
+ if (!shouldUseWorker) {
160
+ // Fallback: delegate directly to the wrapped classifier on this thread.
161
+ return this.wrapped.classify(text);
162
+ }
163
+ // Attempt to classify in a Worker.
164
+ return this.classifyInWorker(text);
165
+ }
166
+ // -------------------------------------------------------------------------
167
+ // dispose (optional IContentClassifier lifecycle hook)
168
+ // -------------------------------------------------------------------------
169
+ /**
170
+ * Release resources held by the wrapped classifier.
171
+ *
172
+ * Delegates to `wrapped.dispose()` if it exists. Idempotent.
173
+ */
174
+ async dispose() {
175
+ if (this.wrapped.dispose) {
176
+ await this.wrapped.dispose();
177
+ }
178
+ }
179
+ // -------------------------------------------------------------------------
180
+ // Private helpers
181
+ // -------------------------------------------------------------------------
182
+ /**
183
+ * Determine whether the current environment and configuration support
184
+ * running inference in a Web Worker.
185
+ *
186
+ * @returns `true` when Web Worker mode should be attempted.
187
+ */
188
+ shouldUseWebWorker() {
189
+ // Worker API is not available (Node.js, JSDOM without worker support, etc.)
190
+ if (typeof Worker === 'undefined') {
191
+ return false;
192
+ }
193
+ // Caller explicitly opted out of Web Worker mode.
194
+ if (this.browserConfig?.useWebWorker === false) {
195
+ return false;
196
+ }
197
+ // A previous Worker creation attempt failed — stay on main thread.
198
+ if (this.workerFailed) {
199
+ return false;
200
+ }
201
+ return true;
202
+ }
203
+ /**
204
+ * Run `classify(text)` inside a transient Web Worker.
205
+ *
206
+ * Each call creates a new Worker, sends a single `classify` message,
207
+ * awaits the `result` or `error` response, then terminates the Worker.
208
+ *
209
+ * If Worker creation itself throws (e.g. CSP violation), `workerFailed`
210
+ * is set to `true` and the call falls back to the wrapped classifier on
211
+ * the main thread.
212
+ *
213
+ * @param text - The text to classify inside the Worker.
214
+ * @returns A promise resolving with the {@link ClassificationResult}.
215
+ */
216
+ async classifyInWorker(text) {
217
+ let worker;
218
+ try {
219
+ // Resolve the Worker script URL. We use the sibling classifier-worker
220
+ // module. In a bundled environment this will be a blob URL or a
221
+ // `new URL(...)` import; here we use a relative path that bundlers
222
+ // understand via the standard Worker constructor pattern.
223
+ worker = new Worker(new URL('../worker/classifier-worker.ts', import.meta.url), {
224
+ type: 'module',
225
+ });
226
+ }
227
+ catch (err) {
228
+ // Worker could not be created (CSP, missing support, etc.).
229
+ // Mark as failed and fall back to the main thread.
230
+ this.workerFailed = true;
231
+ console.warn(`[WorkerClassifierProxy] Worker creation failed for "${this.wrapped.id}"; ` +
232
+ `falling back to main-thread classification. Reason: ${err}`);
233
+ return this.wrapped.classify(text);
234
+ }
235
+ // Build the request message.
236
+ const request = {
237
+ type: 'classify',
238
+ text,
239
+ modelId: this.wrapped.modelId,
240
+ // Default to non-quantized; the wrapped classifier's config owns this,
241
+ // but the Worker needs it to load the right model variant.
242
+ quantized: false,
243
+ taskType: 'text-classification',
244
+ };
245
+ return new Promise((resolve, reject) => {
246
+ // Handle the single response message from the Worker.
247
+ worker.onmessage = (event) => {
248
+ const message = event.data;
249
+ if (message.type === 'result') {
250
+ resolve(message.result);
251
+ }
252
+ else {
253
+ reject(new Error(`Worker classification error: ${message.error}`));
254
+ }
255
+ // Terminate the Worker after receiving its response to free resources.
256
+ worker.terminate();
257
+ };
258
+ // Handle any uncaught errors thrown inside the Worker.
259
+ worker.onerror = (errorEvent) => {
260
+ reject(new Error(`Worker runtime error in "${this.wrapped.id}": ${errorEvent.message}`));
261
+ worker.terminate();
262
+ };
263
+ // Send the classify request to the Worker.
264
+ worker.postMessage(request);
265
+ });
266
+ }
267
+ }
268
+ //# sourceMappingURL=WorkerClassifierProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkerClassifierProxy.js","sourceRoot":"","sources":["../../src/classifiers/WorkerClassifierProxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAoEH,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,qBAAqB;IAsFb;IACA;IAtFnB,4EAA4E;IAC5E,kEAAkE;IAClE,4EAA4E;IAE5E;;;;OAIG;IACH,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACH,IAAI,QAAQ,CAA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CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAC1B,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,KAAK,CAAC,gCAAgC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBACrE,CAAC;gBAED,uEAAuE;gBACvE,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,CAAC,CAAC;YAEF,uDAAuD;YACvD,MAAM,CAAC,OAAO,GAAG,CAAC,UAAsB,EAAE,EAAE;gBAC1C,MAAM,CACJ,IAAI,KAAK,CACP,4BAA4B,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CACtE,CACF,CAAC;gBACF,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,CAAC,CAAC;YAEF,2CAA2C;YAC3C,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @fileoverview Pack factory for the ML Classifier Guardrail Extension Pack.
3
+ *
4
+ * Exports the main `createMLClassifierPack()` factory that assembles the
5
+ * ML classifier guardrail and the `classify_content` tool into a single
6
+ * {@link ExtensionPack} ready for registration with the AgentOS extension
7
+ * manager.
8
+ *
9
+ * Also exports a `createExtensionPack()` bridge function that conforms to
10
+ * the AgentOS manifest factory convention, delegating to
11
+ * `createMLClassifierPack()` with options extracted from the
12
+ * {@link ExtensionPackContext}.
13
+ *
14
+ * ### Default behaviour (zero-config)
15
+ * When called without arguments, all three built-in classifiers (toxicity,
16
+ * prompt-injection, jailbreak) are active using their default model IDs and
17
+ * the default threshold set:
18
+ * - block at 0.90 confidence
19
+ * - flag at 0.70 confidence
20
+ * - warn (sanitize) at 0.40 confidence
21
+ *
22
+ * ### Activation lifecycle
23
+ * Components are built eagerly at pack creation time for direct programmatic
24
+ * use. When the extension manager activates the pack, `onActivate` rebuilds
25
+ * all components with the manager's shared service registry so heavyweight
26
+ * resources (ONNX/WASM model pipelines) are shared across the agent.
27
+ *
28
+ * ### Disabling classifiers
29
+ * Individual classifiers can be disabled by omitting them from the
30
+ * `options.classifiers` array. An empty array or `undefined` activates all
31
+ * three built-in classifiers.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { createMLClassifierPack } from './ml-classifiers';
36
+ *
37
+ * // All built-in classifiers at default thresholds:
38
+ * const pack = createMLClassifierPack();
39
+ *
40
+ * // Toxicity only with custom block threshold:
41
+ * const strictPack = createMLClassifierPack({
42
+ * classifiers: ['toxicity'],
43
+ * thresholds: { blockThreshold: 0.85 },
44
+ * streamingMode: true,
45
+ * guardrailScope: 'both',
46
+ * });
47
+ * ```
48
+ *
49
+ * @module agentos/extensions/packs/ml-classifiers
50
+ */
51
+ import type { ExtensionPack, ExtensionPackContext } from '@framers/agentos';
52
+ import type { MLClassifierPackOptions } from './types';
53
+ /**
54
+ * Re-export all types from the ML classifier type definitions so consumers
55
+ * can import everything from a single entry point:
56
+ * ```ts
57
+ * import { createMLClassifierPack, DEFAULT_THRESHOLDS } from './ml-classifiers';
58
+ * ```
59
+ */
60
+ export * from './types';
61
+ /**
62
+ * Create an {@link ExtensionPack} that bundles:
63
+ * - The {@link MLClassifierGuardrail} guardrail (evaluates input & output).
64
+ * - The {@link ClassifyContentTool} `classify_content` tool (on-demand analysis).
65
+ *
66
+ * The built-in classifiers that are instantiated depend on `options.classifiers`:
67
+ * - `'toxicity'` → {@link ToxicityClassifier} (`unitary/toxic-bert`)
68
+ * - `'injection'` → {@link InjectionClassifier} (`protectai/deberta-v3-small-prompt-injection-v2`)
69
+ * - `'jailbreak'` → {@link JailbreakClassifier} (`meta-llama/PromptGuard-86M`)
70
+ *
71
+ * When `options.classifiers` is `undefined` or empty, **all three** are active.
72
+ *
73
+ * Additional classifiers supplied via `options.customClassifiers` are appended
74
+ * to the active list and run in parallel alongside the built-in ones.
75
+ *
76
+ * @param options - Optional pack-level configuration. All properties have
77
+ * sensible defaults; see {@link MLClassifierPackOptions}.
78
+ * @returns A fully-configured {@link ExtensionPack} with one guardrail
79
+ * descriptor and one tool descriptor.
80
+ */
81
+ export declare function createMLClassifierPack(options?: MLClassifierPackOptions): ExtensionPack;
82
+ /**
83
+ * AgentOS manifest factory function.
84
+ *
85
+ * Conforms to the convention expected by the extension loader when resolving
86
+ * packs from manifests. Extracts `options` from the {@link ExtensionPackContext}
87
+ * and delegates to {@link createMLClassifierPack}.
88
+ *
89
+ * @param context - Manifest context containing optional pack options, secret
90
+ * resolver, and shared service registry.
91
+ * @returns A fully-configured {@link ExtensionPack}.
92
+ *
93
+ * @example Manifest entry:
94
+ * ```json
95
+ * {
96
+ * "packs": [
97
+ * {
98
+ * "module": "./ml-classifiers",
99
+ * "options": {
100
+ * "classifiers": ["toxicity", "jailbreak"],
101
+ * "thresholds": { "blockThreshold": 0.95 },
102
+ * "streamingMode": true
103
+ * }
104
+ * }
105
+ * ]
106
+ * }
107
+ * ```
108
+ */
109
+ export declare function createExtensionPack(context: ExtensionPackContext): ExtensionPack;
110
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG5E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAevD;;;;;;GAMG;AACH,cAAc,SAAS,CAAC;AAMxB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,aAAa,CAmPvF;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAEhF"}