@rcrsr/rill 0.8.0 → 0.8.2
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/README.md +28 -0
- package/dist/error-registry.d.ts.map +1 -1
- package/dist/error-registry.js +164 -0
- package/dist/error-registry.js.map +1 -1
- package/dist/ext/crypto/index.d.ts +32 -0
- package/dist/ext/crypto/index.d.ts.map +1 -0
- package/dist/ext/crypto/index.js +143 -0
- package/dist/ext/crypto/index.js.map +1 -0
- package/dist/ext/exec/index.d.ts +45 -0
- package/dist/ext/exec/index.d.ts.map +1 -0
- package/dist/ext/exec/index.js +168 -0
- package/dist/ext/exec/index.js.map +1 -0
- package/dist/ext/exec/runner.d.ts +62 -0
- package/dist/ext/exec/runner.d.ts.map +1 -0
- package/dist/ext/exec/runner.js +168 -0
- package/dist/ext/exec/runner.js.map +1 -0
- package/dist/ext/fetch/index.d.ts +68 -0
- package/dist/ext/fetch/index.d.ts.map +1 -0
- package/dist/ext/fetch/index.js +259 -0
- package/dist/ext/fetch/index.js.map +1 -0
- package/dist/ext/fetch/request.d.ts +90 -0
- package/dist/ext/fetch/request.d.ts.map +1 -0
- package/dist/ext/fetch/request.js +413 -0
- package/dist/ext/fetch/request.js.map +1 -0
- package/dist/ext/fs/index.d.ts +39 -0
- package/dist/ext/fs/index.d.ts.map +1 -0
- package/dist/ext/fs/index.js +560 -0
- package/dist/ext/fs/index.js.map +1 -0
- package/dist/ext/fs/sandbox.d.ts +78 -0
- package/dist/ext/fs/sandbox.d.ts.map +1 -0
- package/dist/ext/fs/sandbox.js +208 -0
- package/dist/ext/fs/sandbox.js.map +1 -0
- package/dist/ext/kv/index.d.ts +46 -0
- package/dist/ext/kv/index.d.ts.map +1 -0
- package/dist/ext/kv/index.js +215 -0
- package/dist/ext/kv/index.js.map +1 -0
- package/dist/ext/kv/store.d.ts +46 -0
- package/dist/ext/kv/store.d.ts.map +1 -0
- package/dist/ext/kv/store.js +256 -0
- package/dist/ext/kv/store.js.map +1 -0
- package/dist/generated/version-data.d.ts +1 -1
- package/dist/generated/version-data.js +2 -2
- package/package.json +37 -11
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch Extension Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates host functions for HTTP requests based on endpoint configuration.
|
|
5
|
+
* Scripts call endpoints with positional args or single dict argument.
|
|
6
|
+
* All URLs are constructed from config - scripts cannot specify arbitrary URLs.
|
|
7
|
+
*/
|
|
8
|
+
import { RuntimeError } from '../../error-classes.js';
|
|
9
|
+
import { isDict, } from '../../runtime/core/callable.js';
|
|
10
|
+
import { buildRequest, executeRequest, createSemaphore, } from './request.js';
|
|
11
|
+
// ============================================================
|
|
12
|
+
// PARAMETER MAPPING
|
|
13
|
+
// ============================================================
|
|
14
|
+
/**
|
|
15
|
+
* Convert EndpointParam to EndpointArg for request module.
|
|
16
|
+
* Maps type-aware parameters to location-based arguments.
|
|
17
|
+
*
|
|
18
|
+
* @param param - Parameter definition with type information
|
|
19
|
+
* @returns Argument definition for request builder
|
|
20
|
+
*/
|
|
21
|
+
function mapParamToArg(param) {
|
|
22
|
+
return {
|
|
23
|
+
name: param.name,
|
|
24
|
+
location: param.location,
|
|
25
|
+
required: param.required ?? true, // Default to required per spec
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Convert EndpointConfig to InternalEndpointConfig for request module.
|
|
30
|
+
* Maps high-level endpoint config to request-compatible format.
|
|
31
|
+
*
|
|
32
|
+
* @param config - Public endpoint configuration
|
|
33
|
+
* @returns Request-compatible endpoint configuration
|
|
34
|
+
*/
|
|
35
|
+
function mapEndpointConfig(config) {
|
|
36
|
+
return {
|
|
37
|
+
method: config.method,
|
|
38
|
+
path: config.path,
|
|
39
|
+
args: config.params?.map(mapParamToArg),
|
|
40
|
+
headers: config.headers,
|
|
41
|
+
responseShape: config.responseShape ?? 'body',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// ============================================================
|
|
45
|
+
// ARGUMENT PROCESSING
|
|
46
|
+
// ============================================================
|
|
47
|
+
/**
|
|
48
|
+
* Process arguments from positional or dict form.
|
|
49
|
+
* Supports two calling conventions:
|
|
50
|
+
* 1. Positional: endpoint(arg1, arg2, arg3)
|
|
51
|
+
* 2. Dict: endpoint({name: value, ...})
|
|
52
|
+
*
|
|
53
|
+
* @param args - Raw arguments from call site
|
|
54
|
+
* @param params - Parameter definitions
|
|
55
|
+
* @param functionName - Function name for error messages
|
|
56
|
+
* @returns Dict of argument name to value
|
|
57
|
+
* @throws RuntimeError on missing required parameter (EC-8)
|
|
58
|
+
*/
|
|
59
|
+
function processArguments(args, params, functionName) {
|
|
60
|
+
const result = {};
|
|
61
|
+
// Case 1: Single dict argument - extract named parameters
|
|
62
|
+
const firstArg = args[0];
|
|
63
|
+
if (args.length === 1 && firstArg !== undefined && isDict(firstArg)) {
|
|
64
|
+
const argsDict = firstArg;
|
|
65
|
+
for (const param of params) {
|
|
66
|
+
const value = argsDict[param.name];
|
|
67
|
+
if (value === undefined) {
|
|
68
|
+
// Check if parameter has default value
|
|
69
|
+
if (param.defaultValue !== undefined) {
|
|
70
|
+
result[param.name] = param.defaultValue;
|
|
71
|
+
}
|
|
72
|
+
else if (param.required !== false) {
|
|
73
|
+
// EC-8: Missing required parameter
|
|
74
|
+
throw new RuntimeError('RILL-R001', `parameter "${param.name}" is required`, undefined, {
|
|
75
|
+
functionName,
|
|
76
|
+
paramName: param.name,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
result[param.name] = value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
// Case 2: Positional arguments - map by position
|
|
87
|
+
for (let i = 0; i < params.length; i++) {
|
|
88
|
+
const param = params[i];
|
|
89
|
+
if (param === undefined)
|
|
90
|
+
continue;
|
|
91
|
+
const value = args[i];
|
|
92
|
+
if (value === undefined) {
|
|
93
|
+
// Check if parameter has default value
|
|
94
|
+
if (param.defaultValue !== undefined) {
|
|
95
|
+
result[param.name] = param.defaultValue;
|
|
96
|
+
}
|
|
97
|
+
else if (param.required !== false) {
|
|
98
|
+
// EC-8: Missing required parameter
|
|
99
|
+
throw new RuntimeError('RILL-R001', `parameter "${param.name}" is required`, undefined, {
|
|
100
|
+
functionName,
|
|
101
|
+
paramName: param.name,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
result[param.name] = value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
// ============================================================
|
|
112
|
+
// FACTORY
|
|
113
|
+
// ============================================================
|
|
114
|
+
/**
|
|
115
|
+
* Create fetch extension with generated endpoint functions.
|
|
116
|
+
*
|
|
117
|
+
* Each endpoint in config becomes a host function.
|
|
118
|
+
* Scripts call endpoints with positional args or single dict.
|
|
119
|
+
* All URLs constructed from config - scripts cannot create arbitrary URLs.
|
|
120
|
+
*
|
|
121
|
+
* @param config - Fetch configuration with endpoints
|
|
122
|
+
* @returns ExtensionResult with endpoint functions and introspection
|
|
123
|
+
* @throws Error on invalid configuration
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const api = createFetchExtension({
|
|
128
|
+
* baseUrl: 'https://api.example.com',
|
|
129
|
+
* endpoints: {
|
|
130
|
+
* getUser: {
|
|
131
|
+
* method: 'GET',
|
|
132
|
+
* path: '/users/:id',
|
|
133
|
+
* params: [
|
|
134
|
+
* { name: 'id', type: 'string', location: 'path' }
|
|
135
|
+
* ]
|
|
136
|
+
* }
|
|
137
|
+
* }
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export function createFetchExtension(config) {
|
|
142
|
+
// Apply defaults
|
|
143
|
+
const timeout = config.timeout ?? 30000;
|
|
144
|
+
const retries = config.retries ?? 0;
|
|
145
|
+
const retryDelay = config.retryDelay ?? 1000;
|
|
146
|
+
const defaultResponseShape = config.responseShape ?? 'body';
|
|
147
|
+
// Create semaphore for concurrency control
|
|
148
|
+
const semaphore = createSemaphore(config.maxConcurrent);
|
|
149
|
+
// Track active requests for dispose()
|
|
150
|
+
const activeControllers = new Set();
|
|
151
|
+
// Convert config to request-compatible format
|
|
152
|
+
const requestConfig = {
|
|
153
|
+
baseUrl: config.baseUrl,
|
|
154
|
+
headers: config.headers,
|
|
155
|
+
timeout,
|
|
156
|
+
retryLimit: retries,
|
|
157
|
+
retryDelay,
|
|
158
|
+
maxConcurrent: config.maxConcurrent,
|
|
159
|
+
endpoints: Object.fromEntries(Object.entries(config.endpoints).map(([name, endpointConfig]) => [
|
|
160
|
+
name,
|
|
161
|
+
mapEndpointConfig(endpointConfig),
|
|
162
|
+
])),
|
|
163
|
+
};
|
|
164
|
+
// ============================================================
|
|
165
|
+
// ENDPOINT FUNCTIONS
|
|
166
|
+
// ============================================================
|
|
167
|
+
const functions = {};
|
|
168
|
+
for (const [endpointName, endpointConfig] of Object.entries(config.endpoints)) {
|
|
169
|
+
const params = endpointConfig.params ?? [];
|
|
170
|
+
// Generate function for this endpoint
|
|
171
|
+
const endpointFn = async (args) => {
|
|
172
|
+
// Process arguments (positional or dict)
|
|
173
|
+
const processedArgs = processArguments(args, params, endpointName);
|
|
174
|
+
// Build request
|
|
175
|
+
const { url, options, responseShape } = buildRequest(requestConfig, endpointName, processedArgs);
|
|
176
|
+
// Create abort controller for this request
|
|
177
|
+
const controller = new AbortController();
|
|
178
|
+
activeControllers.add(controller);
|
|
179
|
+
try {
|
|
180
|
+
// Execute request
|
|
181
|
+
const result = await executeRequest(url, { ...options, signal: controller.signal }, requestConfig, endpointName, responseShape, semaphore);
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
activeControllers.delete(controller);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
// Build parameter definitions for HostFunctionDefinition
|
|
189
|
+
const hostParams = params.map((param) => {
|
|
190
|
+
// Map EndpointParam type to HostFunctionParam type
|
|
191
|
+
const type = param.type === 'bool' ? 'bool' : param.type;
|
|
192
|
+
const hostParam = {
|
|
193
|
+
name: param.name,
|
|
194
|
+
type,
|
|
195
|
+
};
|
|
196
|
+
if (param.defaultValue !== undefined) {
|
|
197
|
+
hostParam.defaultValue = param.defaultValue;
|
|
198
|
+
}
|
|
199
|
+
return hostParam;
|
|
200
|
+
});
|
|
201
|
+
const returnType = (endpointConfig.responseShape ?? defaultResponseShape) === 'full'
|
|
202
|
+
? 'dict'
|
|
203
|
+
: 'any';
|
|
204
|
+
const hostFunctionDef = {
|
|
205
|
+
params: hostParams,
|
|
206
|
+
fn: endpointFn,
|
|
207
|
+
...(endpointConfig.description !== undefined
|
|
208
|
+
? { description: endpointConfig.description }
|
|
209
|
+
: {}),
|
|
210
|
+
returnType,
|
|
211
|
+
};
|
|
212
|
+
functions[endpointName] = hostFunctionDef;
|
|
213
|
+
}
|
|
214
|
+
// ============================================================
|
|
215
|
+
// INTROSPECTION FUNCTION
|
|
216
|
+
// ============================================================
|
|
217
|
+
/**
|
|
218
|
+
* List all configured endpoints.
|
|
219
|
+
* IR-13: Returns list with name, method, path, description.
|
|
220
|
+
*/
|
|
221
|
+
const endpoints = async () => {
|
|
222
|
+
const result = [];
|
|
223
|
+
for (const [name, endpointConfig] of Object.entries(config.endpoints)) {
|
|
224
|
+
result.push({
|
|
225
|
+
name,
|
|
226
|
+
method: endpointConfig.method,
|
|
227
|
+
path: endpointConfig.path,
|
|
228
|
+
description: endpointConfig.description ?? '',
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
};
|
|
233
|
+
functions['endpoints'] = {
|
|
234
|
+
params: [],
|
|
235
|
+
fn: endpoints,
|
|
236
|
+
description: 'List configured endpoints',
|
|
237
|
+
returnType: 'list',
|
|
238
|
+
};
|
|
239
|
+
// ============================================================
|
|
240
|
+
// DISPOSAL
|
|
241
|
+
// ============================================================
|
|
242
|
+
/**
|
|
243
|
+
* Abort all in-flight requests.
|
|
244
|
+
* AC-8: dispose() aborts in-flight requests.
|
|
245
|
+
*/
|
|
246
|
+
const dispose = () => {
|
|
247
|
+
for (const controller of activeControllers) {
|
|
248
|
+
controller.abort();
|
|
249
|
+
}
|
|
250
|
+
activeControllers.clear();
|
|
251
|
+
};
|
|
252
|
+
// ============================================================
|
|
253
|
+
// EXTENSION RESULT
|
|
254
|
+
// ============================================================
|
|
255
|
+
const result = functions;
|
|
256
|
+
result.dispose = dispose;
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ext/fetch/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,OAAO,EACL,MAAM,GAEP,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAIL,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAC;AA2CtB,+DAA+D;AAC/D,oBAAoB;AACpB,+DAA+D;AAE/D;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,KAAoB;IACzC,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,IAAI,EAAE,+BAA+B;KAClE,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,MAAsB;IAC/C,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,aAAa,CAAC;QACvC,OAAO,EAAE,MA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AAyB;IACzB,+DAA+D;IAE/D;;;OAGG;IACH,MAAM,SAAS,GAAG,KAAK,IAA0B,EAAE;QACjD,MAAM,MAAM,GAAgB,EAAE,CAAC;QAE/B,KAAK,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACtE,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI;gBACJ,MAAM,EAAE,cAAc,CAAC,MAAM;gBAC7B,IAAI,EAAE,cAAc,CAAC,IAAI;gBACzB,WAAW,EAAE,cAAc,CAAC,WAAW,IAAI,EAAE;aAC9C,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,SAAS,CAAC,WAAW,CAAC,GAAG;QACvB,MAAM,EAAE,EAAE;QACV,EAAE,EAAE,SAAS;QACb,WAAW,EAAE,2BAA2B;QACxC,UAAU,EAAE,MAAM;KACnB,CAAC;IAEF,+DAA+D;IAC/D,WAAW;IACX,+DAA+D;IAE/D;;;OAGG;IACH,MAAM,OAAO,GAAG,GAAS,EAAE;QACzB,KAAK,MAAM,UAAU,IAAI,iBAAiB,EAAE,CAAC;YAC3C,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;QACD,iBAAiB,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC,CAAC;IAEF,+DAA+D;IAC/D,mBAAmB;IACnB,+DAA+D;IAE/D,MAAM,MAAM,GAAoB,SAAS,CAAC;IAC1C,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch Request Module
|
|
3
|
+
* Handles URL building, retry logic, response parsing, and error handling
|
|
4
|
+
*/
|
|
5
|
+
/** Response shape configuration */
|
|
6
|
+
export type ResponseShape = 'body' | 'full';
|
|
7
|
+
/** Location of argument in request */
|
|
8
|
+
export type ArgLocation = 'path' | 'query' | 'header' | 'body';
|
|
9
|
+
/** Argument definition for endpoint */
|
|
10
|
+
export interface EndpointArg {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly location: ArgLocation;
|
|
13
|
+
readonly required?: boolean | undefined;
|
|
14
|
+
}
|
|
15
|
+
/** Internal endpoint configuration for request building */
|
|
16
|
+
export interface InternalEndpointConfig {
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly method: string;
|
|
19
|
+
readonly args?: EndpointArg[] | undefined;
|
|
20
|
+
readonly headers?: Record<string, string> | undefined;
|
|
21
|
+
readonly responseShape?: ResponseShape | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Extension configuration */
|
|
24
|
+
export interface FetchExtensionConfig {
|
|
25
|
+
readonly baseUrl: string;
|
|
26
|
+
readonly endpoints: Record<string, InternalEndpointConfig>;
|
|
27
|
+
readonly headers?: Record<string, string> | (() => Record<string, string>) | undefined;
|
|
28
|
+
readonly timeout?: number | undefined;
|
|
29
|
+
readonly retryLimit?: number | undefined;
|
|
30
|
+
readonly retryDelay?: number | undefined;
|
|
31
|
+
readonly maxConcurrent?: number | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** Full response shape */
|
|
34
|
+
export interface FullResponse {
|
|
35
|
+
readonly status: number;
|
|
36
|
+
readonly headers: Record<string, string>;
|
|
37
|
+
readonly body: unknown;
|
|
38
|
+
}
|
|
39
|
+
/** Fetch request options (compatible with fetch API) */
|
|
40
|
+
export interface FetchOptions {
|
|
41
|
+
readonly method: string;
|
|
42
|
+
readonly headers: Record<string, string>;
|
|
43
|
+
body?: string | undefined;
|
|
44
|
+
signal?: AbortSignal | undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Simple semaphore for limiting concurrent requests.
|
|
48
|
+
* Queues requests when limit is reached.
|
|
49
|
+
*/
|
|
50
|
+
declare class Semaphore {
|
|
51
|
+
private permits;
|
|
52
|
+
private readonly queue;
|
|
53
|
+
constructor(permits: number);
|
|
54
|
+
acquire(): Promise<void>;
|
|
55
|
+
release(): void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Execute HTTP request with retry logic.
|
|
59
|
+
* Handles timeouts, network errors, and retries.
|
|
60
|
+
*
|
|
61
|
+
* @param url - Request URL
|
|
62
|
+
* @param options - Fetch options
|
|
63
|
+
* @param config - Extension configuration
|
|
64
|
+
* @param namespace - Extension namespace for error messages
|
|
65
|
+
* @param semaphore - Concurrency semaphore (optional)
|
|
66
|
+
* @returns Response body or full response
|
|
67
|
+
*/
|
|
68
|
+
export declare function executeRequest(url: string, options: FetchOptions, config: FetchExtensionConfig, namespace: string, responseShape: ResponseShape, semaphore?: Semaphore | undefined): Promise<unknown>;
|
|
69
|
+
/**
|
|
70
|
+
* Create semaphore for concurrency control.
|
|
71
|
+
*
|
|
72
|
+
* @param maxConcurrent - Maximum concurrent requests
|
|
73
|
+
* @returns Semaphore instance or undefined if no limit
|
|
74
|
+
*/
|
|
75
|
+
export declare function createSemaphore(maxConcurrent: number | undefined): Semaphore | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Build request from endpoint config and arguments.
|
|
78
|
+
*
|
|
79
|
+
* @param config - Extension configuration
|
|
80
|
+
* @param endpointName - Endpoint name
|
|
81
|
+
* @param args - Request arguments
|
|
82
|
+
* @returns Request URL and options
|
|
83
|
+
*/
|
|
84
|
+
export declare function buildRequest(config: FetchExtensionConfig, endpointName: string, args: Record<string, unknown>): {
|
|
85
|
+
url: string;
|
|
86
|
+
options: FetchOptions;
|
|
87
|
+
responseShape: ResponseShape;
|
|
88
|
+
};
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/ext/fetch/request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,MAA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