apcore-js 0.21.1 → 0.23.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/README.md +37 -3
- package/dist/acl-handlers.d.ts.map +1 -1
- package/dist/acl-handlers.js +5 -0
- package/dist/acl-handlers.js.map +1 -1
- package/dist/async-task.d.ts +49 -14
- package/dist/async-task.d.ts.map +1 -1
- package/dist/async-task.js +134 -39
- package/dist/async-task.js.map +1 -1
- package/dist/bindings.d.ts +13 -1
- package/dist/bindings.d.ts.map +1 -1
- package/dist/bindings.js +21 -5
- package/dist/bindings.js.map +1 -1
- package/dist/browser/index.d.ts +2 -2
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/builtin-steps.d.ts +14 -12
- package/dist/builtin-steps.d.ts.map +1 -1
- package/dist/builtin-steps.js +99 -30
- package/dist/builtin-steps.js.map +1 -1
- package/dist/cancel.d.ts +23 -2
- package/dist/cancel.d.ts.map +1 -1
- package/dist/cancel.js +31 -6
- package/dist/cancel.js.map +1 -1
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7 -3
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +31 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +108 -14
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +36 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +111 -20
- package/dist/context.js.map +1 -1
- package/dist/errors.d.ts +74 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +158 -11
- package/dist/errors.js.map +1 -1
- package/dist/events/emitter.d.ts +54 -16
- package/dist/events/emitter.d.ts.map +1 -1
- package/dist/events/emitter.js +162 -73
- package/dist/events/emitter.js.map +1 -1
- package/dist/events/index.d.ts +2 -1
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +1 -1
- package/dist/events/index.js.map +1 -1
- package/dist/events/retry.d.ts +35 -0
- package/dist/events/retry.d.ts.map +1 -0
- package/dist/events/retry.js +52 -0
- package/dist/events/retry.js.map +1 -0
- package/dist/events/subscribers.d.ts +54 -9
- package/dist/events/subscribers.d.ts.map +1 -1
- package/dist/events/subscribers.js +109 -67
- package/dist/events/subscribers.js.map +1 -1
- package/dist/executor.d.ts +4 -1
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +157 -21
- package/dist/executor.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/middleware/circuit-breaker.d.ts +10 -4
- package/dist/middleware/circuit-breaker.d.ts.map +1 -1
- package/dist/middleware/circuit-breaker.js +49 -24
- package/dist/middleware/circuit-breaker.js.map +1 -1
- package/dist/middleware/index.d.ts +2 -2
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +2 -2
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/manager.d.ts +6 -2
- package/dist/middleware/manager.d.ts.map +1 -1
- package/dist/middleware/manager.js +36 -1
- package/dist/middleware/manager.js.map +1 -1
- package/dist/middleware/platform-notify.d.ts +2 -3
- package/dist/middleware/platform-notify.d.ts.map +1 -1
- package/dist/middleware/platform-notify.js +5 -6
- package/dist/middleware/platform-notify.js.map +1 -1
- package/dist/middleware/retry.d.ts +33 -15
- package/dist/middleware/retry.d.ts.map +1 -1
- package/dist/middleware/retry.js +48 -23
- package/dist/middleware/retry.js.map +1 -1
- package/dist/observability/context-logger.d.ts +15 -11
- package/dist/observability/context-logger.d.ts.map +1 -1
- package/dist/observability/context-logger.js +40 -14
- package/dist/observability/context-logger.js.map +1 -1
- package/dist/pipeline.d.ts +1 -1
- package/dist/pipeline.js +11 -11
- package/dist/pipeline.js.map +1 -1
- package/dist/registry/multi-class.js +6 -17
- package/dist/registry/multi-class.js.map +1 -1
- package/dist/registry/registry.d.ts +46 -2
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +276 -36
- package/dist/registry/registry.js.map +1 -1
- package/dist/registry/version.d.ts.map +1 -1
- package/dist/registry/version.js +9 -2
- package/dist/registry/version.js.map +1 -1
- package/dist/schema/ref-resolver.d.ts.map +1 -1
- package/dist/schema/ref-resolver.js +2 -2
- package/dist/schema/ref-resolver.js.map +1 -1
- package/dist/schema/strict.d.ts.map +1 -1
- package/dist/schema/strict.js +4 -1
- package/dist/schema/strict.js.map +1 -1
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +1 -1
- package/dist/schema/types.js.map +1 -1
- package/dist/schema/validator.d.ts.map +1 -1
- package/dist/schema/validator.js +11 -20
- package/dist/schema/validator.js.map +1 -1
- package/dist/streaming.d.ts +21 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +32 -0
- package/dist/streaming.js.map +1 -0
- package/dist/sys-modules/control.d.ts +7 -0
- package/dist/sys-modules/control.d.ts.map +1 -1
- package/dist/sys-modules/control.js +32 -7
- package/dist/sys-modules/control.js.map +1 -1
- package/dist/sys-modules/manifest.js +7 -0
- package/dist/sys-modules/manifest.js.map +1 -1
- package/dist/sys-modules/registration.d.ts.map +1 -1
- package/dist/sys-modules/registration.js +18 -8
- package/dist/sys-modules/registration.js.map +1 -1
- package/dist/trace-context.d.ts.map +1 -1
- package/dist/trace-context.js +14 -3
- package/dist/trace-context.js.map +1 -1
- package/package.json +8 -4
- package/dist/registry/index.d.ts +0 -15
- package/dist/registry/index.d.ts.map +0 -1
- package/dist/registry/index.js +0 -11
- package/dist/registry/index.js.map +0 -1
- package/dist/schema/index.d.ts +0 -11
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js +0 -9
- package/dist/schema/index.js.map +0 -1
package/dist/events/emitter.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Global event bus with fan-out delivery
|
|
2
|
+
* Global event bus with fan-out delivery, per-subscriber retry, and DLQ.
|
|
3
3
|
*/
|
|
4
|
+
import { resolveRetry, computeDelayMs, fnmatch } from './retry.js';
|
|
4
5
|
export function createEvent(eventType, moduleId, severity, data) {
|
|
5
6
|
return {
|
|
6
7
|
eventType,
|
|
@@ -10,35 +11,26 @@ export function createEvent(eventType, moduleId, severity, data) {
|
|
|
10
11
|
data,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* deprecation window. The legacy event payload is augmented with
|
|
16
|
-
* `deprecated: true` and `canonical_event: <canonicalType>` so subscribers
|
|
17
|
-
* still listening to the legacy name can migrate.
|
|
18
|
-
*
|
|
19
|
-
* The two emissions share an identical timestamp so they appear atomic to
|
|
20
|
-
* downstream consumers ordering by `timestamp`.
|
|
21
|
-
*/
|
|
22
|
-
export function emitWithLegacy(emitter, canonicalType, legacyType, moduleId, severity, data) {
|
|
23
|
-
const timestamp = new Date().toISOString();
|
|
24
|
-
emitter.emit({ eventType: canonicalType, moduleId, timestamp, severity, data });
|
|
25
|
-
emitter.emit({
|
|
26
|
-
eventType: legacyType,
|
|
27
|
-
moduleId,
|
|
28
|
-
timestamp,
|
|
29
|
-
severity,
|
|
30
|
-
data: { ...data, deprecated: true, canonical_event: canonicalType },
|
|
31
|
-
});
|
|
14
|
+
function sleep(ms) {
|
|
15
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
32
16
|
}
|
|
33
17
|
const DEFAULT_MAX_PENDING = 1000;
|
|
34
18
|
/**
|
|
35
|
-
* Global event bus with
|
|
36
|
-
*
|
|
19
|
+
* Global event bus with fan-out delivery, per-subscriber retry, and DLQ.
|
|
20
|
+
*
|
|
21
|
+
* Key behaviors:
|
|
22
|
+
* - All subscribers get exponential-backoff retries up to `maxAttempts`. A subscriber
|
|
23
|
+
* that omits `retry` receives the spec default policy (max_attempts=3); one that sets
|
|
24
|
+
* `maxAttempts: 1` disables retry (single attempt).
|
|
25
|
+
* - After retry exhaustion: DLQ event + optional `onFailure` callback.
|
|
26
|
+
* - `eventPattern` (glob) filters which events a subscriber receives.
|
|
27
|
+
* - `flush()` drains all in-flight async deliveries.
|
|
37
28
|
*/
|
|
38
29
|
export class EventEmitter {
|
|
39
30
|
_subscribers = [];
|
|
40
31
|
_pending = [];
|
|
41
32
|
_maxPending;
|
|
33
|
+
_shutdown = false;
|
|
42
34
|
constructor(maxPending = DEFAULT_MAX_PENDING) {
|
|
43
35
|
this._maxPending = maxPending;
|
|
44
36
|
}
|
|
@@ -51,72 +43,157 @@ export class EventEmitter {
|
|
|
51
43
|
this._subscribers.splice(idx, 1);
|
|
52
44
|
}
|
|
53
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Stop accepting new emits. After shutdown, {@link emit} is a no-op (A-D-028,
|
|
48
|
+
* cross-SDK canonical with Python/Rust which drop post-shutdown emits). Drains
|
|
49
|
+
* any in-flight deliveries via {@link flush}.
|
|
50
|
+
*/
|
|
51
|
+
async shutdown(timeoutMs = 5000) {
|
|
52
|
+
if (this._shutdown)
|
|
53
|
+
return;
|
|
54
|
+
this._shutdown = true;
|
|
55
|
+
await this.flush(timeoutMs);
|
|
56
|
+
}
|
|
54
57
|
emit(event) {
|
|
55
|
-
|
|
58
|
+
// A-D-028: silently drop emits after shutdown.
|
|
59
|
+
if (this._shutdown)
|
|
60
|
+
return;
|
|
61
|
+
const snapshot = this._getMatchingSubscribers(event.eventType);
|
|
56
62
|
for (const subscriber of snapshot) {
|
|
63
|
+
// Every subscriber — built-in and user-registered, with or without an explicit
|
|
64
|
+
// `retry` block — goes through the unified retry/backoff/DLQ delivery path.
|
|
65
|
+
// A subscriber that omits `retry` receives the spec default policy
|
|
66
|
+
// (max_attempts=3); one that explicitly sets maxAttempts:1 disables retry.
|
|
67
|
+
// (event-system.md §Per-Subscriber Retry Policy; sync finding A-D-005)
|
|
68
|
+
if (this._pending.length >= this._maxPending) {
|
|
69
|
+
// A-D-06: the pending buffer is full. The event was accepted by emit(),
|
|
70
|
+
// so it MUST NOT be silently discarded (event-system.md §Overflow). Route
|
|
71
|
+
// the affected delivery through the dead-letter path with
|
|
72
|
+
// reason: "pending_overflow" instead of a log-only drop. `maxPending`
|
|
73
|
+
// remains a legitimate memory bound — we just fail through the DLQ.
|
|
74
|
+
const overflowPromise = this._emitOverflowDLQ(subscriber, event);
|
|
75
|
+
const tracked = overflowPromise.catch(() => {
|
|
76
|
+
// DLQ subscriber errors handled inside _emitOverflowDLQ
|
|
77
|
+
});
|
|
78
|
+
this._pending.push(tracked);
|
|
79
|
+
tracked.then(() => {
|
|
80
|
+
const idx = this._pending.indexOf(tracked);
|
|
81
|
+
if (idx !== -1)
|
|
82
|
+
this._pending.splice(idx, 1);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const tracked = this._deliver(subscriber, event).catch(() => {
|
|
87
|
+
// errors handled inside _deliver
|
|
88
|
+
});
|
|
89
|
+
this._pending.push(tracked);
|
|
90
|
+
tracked.then(() => {
|
|
91
|
+
const idx = this._pending.indexOf(tracked);
|
|
92
|
+
if (idx !== -1)
|
|
93
|
+
this._pending.splice(idx, 1);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
_getMatchingSubscribers(eventType, isDlq = false) {
|
|
99
|
+
return this._subscribers.filter((sub) => {
|
|
100
|
+
// A-D-026: DLQ events (apcore.event.delivery_failed) are delivered ONLY
|
|
101
|
+
// to subscribers with an explicit, non-wildcard pattern. Catch-all
|
|
102
|
+
// subscribers (no pattern, or pattern '*') never receive DLQ events —
|
|
103
|
+
// this prevents cascading failures where a catch-all subscriber would
|
|
104
|
+
// recursively fail on the DLQ event about its own delivery failure.
|
|
105
|
+
const pattern = sub.eventPattern ?? '*';
|
|
106
|
+
if (isDlq && pattern === '*')
|
|
107
|
+
return false;
|
|
108
|
+
return fnmatch(eventType, pattern);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async _deliver(subscriber, event) {
|
|
112
|
+
const retry = resolveRetry(subscriber.retry);
|
|
113
|
+
let lastError = new Error('Unknown error');
|
|
114
|
+
for (let attempt = 0; attempt < retry.maxAttempts; attempt++) {
|
|
57
115
|
try {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const tracked = result.catch((err) => {
|
|
68
|
-
console.warn(`[apcore:events] Subscriber failed handling event ${event.eventType}:`, err);
|
|
69
|
-
});
|
|
70
|
-
this._pending.push(tracked);
|
|
71
|
-
// Auto-cleanup when resolved to prevent unbounded growth
|
|
72
|
-
tracked.then(() => {
|
|
73
|
-
const idx = this._pending.indexOf(tracked);
|
|
74
|
-
if (idx !== -1)
|
|
75
|
-
this._pending.splice(idx, 1);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
116
|
+
await subscriber.onEvent(event);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
lastError = e instanceof Error ? e : new Error(String(e));
|
|
121
|
+
if (attempt + 1 < retry.maxAttempts) {
|
|
122
|
+
await sleep(computeDelayMs(retry, attempt));
|
|
78
123
|
}
|
|
79
124
|
}
|
|
80
|
-
|
|
81
|
-
|
|
125
|
+
}
|
|
126
|
+
// All attempts exhausted — emit DLQ event and invoke onFailure callback
|
|
127
|
+
await this._emitDLQ(subscriber, event, lastError, retry.maxAttempts);
|
|
128
|
+
if (subscriber.onFailure) {
|
|
129
|
+
try {
|
|
130
|
+
await subscriber.onFailure(event, lastError, retry.maxAttempts);
|
|
131
|
+
}
|
|
132
|
+
catch (cbError) {
|
|
133
|
+
console.error('[apcore:events] onFailure callback raised:', cbError);
|
|
82
134
|
}
|
|
83
135
|
}
|
|
84
136
|
}
|
|
85
137
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
138
|
+
* Route an overflowed delivery through the dead-letter path (A-D-06).
|
|
139
|
+
*
|
|
140
|
+
* When the pending buffer is at capacity, the affected delivery cannot be
|
|
141
|
+
* tracked normally, so instead of dropping it we emit
|
|
142
|
+
* `apcore.event.delivery_failed` with `reason: "pending_overflow"`. This keeps
|
|
143
|
+
* the "accepted events are never silently lost" guarantee while preserving
|
|
144
|
+
* `maxPending` as a memory bound (event-system.md §Overflow, normative).
|
|
89
145
|
*/
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
146
|
+
async _emitOverflowDLQ(subscriber, originalEvent) {
|
|
147
|
+
const error = new Error(`pending buffer at capacity (${this._maxPending}) — delivery routed to dead-letter`);
|
|
148
|
+
await this._emitDLQ(subscriber, originalEvent, error, 0, 'pending_overflow');
|
|
149
|
+
}
|
|
150
|
+
async _emitDLQ(subscriber, originalEvent, error, attemptCount, reason) {
|
|
151
|
+
// A-D-029: prefer the declared `subscriberType` field; fall back to the
|
|
152
|
+
// constructor-name derivation only when it is absent.
|
|
153
|
+
const subscriberType = typeof subscriber.subscriberType === 'string'
|
|
154
|
+
? subscriber.subscriberType
|
|
155
|
+
: (subscriber.constructor?.name ?? 'unknown')
|
|
156
|
+
.replace('Subscriber', '')
|
|
157
|
+
.toLowerCase();
|
|
158
|
+
const subscriberId = subscriber.subscriberId ?? this._identifySubscriber(subscriber);
|
|
159
|
+
const dlqEvent = createEvent('apcore.event.delivery_failed', null, 'error', {
|
|
160
|
+
subscriber_type: subscriberType,
|
|
161
|
+
subscriber_id: subscriberId,
|
|
162
|
+
original_event: {
|
|
163
|
+
name: originalEvent.eventType,
|
|
164
|
+
payload: originalEvent.data,
|
|
165
|
+
metadata: {
|
|
166
|
+
module_id: originalEvent.moduleId,
|
|
167
|
+
timestamp: originalEvent.timestamp,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
error: { type: error.constructor?.name ?? 'Error', message: error.message },
|
|
171
|
+
attempt_count: attemptCount,
|
|
172
|
+
timestamp: new Date().toISOString(),
|
|
173
|
+
// A-D-06: present only on pending-buffer overflow ("pending_overflow").
|
|
174
|
+
...(reason !== undefined ? { reason } : {}),
|
|
95
175
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
176
|
+
// Deliver DLQ event with NO retry — single attempt only; DLQ subscriber errors are logged.
|
|
177
|
+
// isDlq=true excludes catch-all ('*'/no-pattern) subscribers (A-D-026).
|
|
178
|
+
const dlqSubscribers = this._getMatchingSubscribers(dlqEvent.eventType, true);
|
|
179
|
+
for (const dlqSub of dlqSubscribers) {
|
|
99
180
|
try {
|
|
100
|
-
const r =
|
|
101
|
-
// Intentionally do not track this Promise in _pending — at-cap by design.
|
|
102
|
-
// Async handlers swallow their own errors; attach a guard so unhandled
|
|
103
|
-
// rejections don't escape.
|
|
181
|
+
const r = dlqSub.onEvent(dlqEvent);
|
|
104
182
|
if (r instanceof Promise) {
|
|
105
|
-
r
|
|
106
|
-
console.warn(`[apcore:events] Subscriber failed handling delivery_dropped:`, err);
|
|
107
|
-
});
|
|
183
|
+
await r;
|
|
108
184
|
}
|
|
109
185
|
}
|
|
110
|
-
catch (
|
|
111
|
-
console.
|
|
186
|
+
catch (dlqErr) {
|
|
187
|
+
console.error('[apcore:events] DLQ subscriber raised:', dlqErr);
|
|
112
188
|
}
|
|
113
189
|
}
|
|
114
190
|
}
|
|
115
191
|
_identifySubscriber(sub) {
|
|
192
|
+
if (sub.subscriberId)
|
|
193
|
+
return sub.subscriberId;
|
|
116
194
|
const ctorName = sub.constructor?.name;
|
|
117
195
|
if (ctorName && ctorName !== 'Object')
|
|
118
196
|
return ctorName;
|
|
119
|
-
// Fall back to a stable hash-ish string based on identity.
|
|
120
197
|
return `subscriber@${this._subscribers.indexOf(sub)}`;
|
|
121
198
|
}
|
|
122
199
|
/**
|
|
@@ -128,13 +205,25 @@ export class EventEmitter {
|
|
|
128
205
|
* (sync finding A-D-503)
|
|
129
206
|
*/
|
|
130
207
|
async flush(timeoutMs = 5000) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
208
|
+
// A-D-027: per-pending semantics (Python canonical) — each pending delivery
|
|
209
|
+
// gets up to `timeoutMs` to settle, rather than sharing one total deadline.
|
|
210
|
+
// A delivery that exceeds its budget is abandoned (the next call to flush
|
|
211
|
+
// can re-await any that are still tracked).
|
|
212
|
+
const pending = [...this._pending];
|
|
213
|
+
this._pending = [];
|
|
214
|
+
for (const p of pending) {
|
|
215
|
+
if (timeoutMs > 0) {
|
|
216
|
+
let timer;
|
|
217
|
+
const timeout = new Promise((resolve) => {
|
|
218
|
+
timer = setTimeout(resolve, timeoutMs);
|
|
219
|
+
});
|
|
220
|
+
await Promise.race([p.catch(() => { }), timeout]);
|
|
221
|
+
if (timer !== undefined)
|
|
222
|
+
clearTimeout(timer);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
await p.catch(() => { });
|
|
226
|
+
}
|
|
138
227
|
}
|
|
139
228
|
}
|
|
140
229
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/events/emitter.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/events/emitter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAyCnE,MAAM,UAAU,WAAW,CACzB,SAAiB,EACjB,QAAuB,EACvB,QAAgB,EAChB,IAA6B;IAE7B,OAAO;QACL,SAAS;QACT,QAAQ;QACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,QAAQ;QACR,IAAI;KACL,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,C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;OAOG;IACH,KAAK,CAAC,KAAK,CAAC,YAAoB,IAAI;QAClC,4EAA4E;QAC5E,4EAA4E;QAC5E,0EAA0E;QAC1E,4CAA4C;QAC5C,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;gBAClB,IAAI,KAAgD,CAAC;gBACrD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;oBAC5C,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;gBACzC,CAAC,CAAC,CAAC;gBACH,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;gBACjD,IAAI,KAAK,KAAK,SAAS;oBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/events/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { EventEmitter, createEvent
|
|
1
|
+
export { EventEmitter, createEvent } from './emitter.js';
|
|
2
2
|
export type { ApCoreEvent, EventSubscriber } from './emitter.js';
|
|
3
3
|
export { WebhookSubscriber, A2ASubscriber, FileSubscriber, StdoutSubscriber, FilterSubscriber } from './subscribers.js';
|
|
4
4
|
export { CircuitBreakerWrapper, CircuitState } from './circuit-breaker.js';
|
|
5
5
|
export type { CircuitBreakerConfig } from './circuit-breaker.js';
|
|
6
|
+
export type { RetryConfig } from './retry.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC3E,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/events/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { EventEmitter, createEvent
|
|
1
|
+
export { EventEmitter, createEvent } from './emitter.js';
|
|
2
2
|
export { WebhookSubscriber, A2ASubscriber, FileSubscriber, StdoutSubscriber, FilterSubscriber } from './subscribers.js';
|
|
3
3
|
export { CircuitBreakerWrapper, CircuitState } from './circuit-breaker.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/events/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry configuration types and helpers for event delivery.
|
|
3
|
+
*/
|
|
4
|
+
export interface RetryConfig {
|
|
5
|
+
maxAttempts?: number;
|
|
6
|
+
initialBackoffMs?: number;
|
|
7
|
+
maxBackoffMs?: number;
|
|
8
|
+
backoffMultiplier?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ResolvedRetryConfig {
|
|
11
|
+
maxAttempts: number;
|
|
12
|
+
initialBackoffMs: number;
|
|
13
|
+
maxBackoffMs: number;
|
|
14
|
+
backoffMultiplier: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Spec default retry policy (event-system.md §Per-Subscriber Retry Policy).
|
|
18
|
+
* Applied when a subscriber omits the `retry` block entirely, and as the base
|
|
19
|
+
* for merging when individual fields are omitted. `max_attempts` default is 3 —
|
|
20
|
+
* uniform across Python/TypeScript/Rust SDKs.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEFAULT_RETRY: ResolvedRetryConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Merge caller-supplied retry config with the spec defaults.
|
|
25
|
+
* A subscriber that does NOT supply `retry` receives the full DEFAULT_RETRY
|
|
26
|
+
* policy (max_attempts=3), per event-system.md §Per-Subscriber Retry Policy —
|
|
27
|
+
* built-in and user-registered subscribers share the same default. A subscriber
|
|
28
|
+
* that explicitly sets `maxAttempts: 1` disables retry (single attempt).
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveRetry(config?: RetryConfig): ResolvedRetryConfig;
|
|
31
|
+
/** Glob pattern matching supporting * (any chars) and ? (single char). Cached per pattern. */
|
|
32
|
+
export declare function fnmatch(text: string, pattern: string): boolean;
|
|
33
|
+
/** Exponential-backoff delay for attempt `attempt` (0-based, clamped to ≥ 0). */
|
|
34
|
+
export declare function computeDelayMs(cfg: ResolvedRetryConfig, attempt: number): number;
|
|
35
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/events/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,mBAK3B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,mBAAmB,CAKtE;AAID,8FAA8F;AAC9F,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAc9D;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,GAAG,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKhF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry configuration types and helpers for event delivery.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Spec default retry policy (event-system.md §Per-Subscriber Retry Policy).
|
|
6
|
+
* Applied when a subscriber omits the `retry` block entirely, and as the base
|
|
7
|
+
* for merging when individual fields are omitted. `max_attempts` default is 3 —
|
|
8
|
+
* uniform across Python/TypeScript/Rust SDKs.
|
|
9
|
+
*/
|
|
10
|
+
export const DEFAULT_RETRY = {
|
|
11
|
+
maxAttempts: 3,
|
|
12
|
+
initialBackoffMs: 100,
|
|
13
|
+
maxBackoffMs: 30_000,
|
|
14
|
+
backoffMultiplier: 2.0,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Merge caller-supplied retry config with the spec defaults.
|
|
18
|
+
* A subscriber that does NOT supply `retry` receives the full DEFAULT_RETRY
|
|
19
|
+
* policy (max_attempts=3), per event-system.md §Per-Subscriber Retry Policy —
|
|
20
|
+
* built-in and user-registered subscribers share the same default. A subscriber
|
|
21
|
+
* that explicitly sets `maxAttempts: 1` disables retry (single attempt).
|
|
22
|
+
*/
|
|
23
|
+
export function resolveRetry(config) {
|
|
24
|
+
if (config === undefined) {
|
|
25
|
+
return { ...DEFAULT_RETRY };
|
|
26
|
+
}
|
|
27
|
+
return { ...DEFAULT_RETRY, ...config };
|
|
28
|
+
}
|
|
29
|
+
const _patternCache = new Map();
|
|
30
|
+
/** Glob pattern matching supporting * (any chars) and ? (single char). Cached per pattern. */
|
|
31
|
+
export function fnmatch(text, pattern) {
|
|
32
|
+
let regex = _patternCache.get(pattern);
|
|
33
|
+
if (regex === undefined) {
|
|
34
|
+
const regexStr = Array.from(pattern)
|
|
35
|
+
.map((c) => {
|
|
36
|
+
if (c === '*')
|
|
37
|
+
return '.*';
|
|
38
|
+
if (c === '?')
|
|
39
|
+
return '.';
|
|
40
|
+
return c.replace(/[$()*+.?[\]^{|}-]/g, '\\$&');
|
|
41
|
+
})
|
|
42
|
+
.join('');
|
|
43
|
+
regex = new RegExp(`^${regexStr}$`);
|
|
44
|
+
_patternCache.set(pattern, regex);
|
|
45
|
+
}
|
|
46
|
+
return regex.test(text);
|
|
47
|
+
}
|
|
48
|
+
/** Exponential-backoff delay for attempt `attempt` (0-based, clamped to ≥ 0). */
|
|
49
|
+
export function computeDelayMs(cfg, attempt) {
|
|
50
|
+
return Math.min(cfg.maxBackoffMs, Math.floor(cfg.initialBackoffMs * Math.pow(cfg.backoffMultiplier, Math.max(0, attempt))));
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/events/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgBH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAwB;IAChD,WAAW,EAAE,CAAC;IACd,gBAAgB,EAAE,GAAG;IACrB,YAAY,EAAE,MAAM;IACpB,iBAAiB,EAAE,GAAG;CACvB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAAoB;IAC/C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,GAAG,aAAa,EAAE,CAAC;IAC9B,CAAC;IACD,OAAO,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,EAAE,CAAC;AACzC,CAAC;AAED,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEhD,8FAA8F;AAC9F,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,OAAe;IACnD,IAAI,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;aACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,GAAG,CAAC;YAC1B,OAAO,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC,CAAC;aACD,IAAI,CAAC,EAAE,CAAC,CAAC;QACZ,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC;QACpC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,GAAwB,EAAE,OAAe;IACtE,OAAO,IAAI,CAAC,GAAG,CACb,GAAG,CAAC,YAAY,EAChB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CACzF,CAAC;AACJ,CAAC"}
|
|
@@ -2,47 +2,83 @@
|
|
|
2
2
|
* Event subscribers for webhook, A2A, file, stdout, and filter delivery.
|
|
3
3
|
*/
|
|
4
4
|
import type { ApCoreEvent, EventSubscriber } from './emitter.js';
|
|
5
|
+
import type { RetryConfig } from './retry.js';
|
|
5
6
|
/**
|
|
6
7
|
* Delivers events via HTTP POST to a webhook URL.
|
|
7
8
|
*
|
|
8
|
-
* Retries on 5xx and connection errors
|
|
9
|
-
*
|
|
9
|
+
* Retries on 5xx and connection errors. As of v0.22.0 finding A-D-EVT-001,
|
|
10
|
+
* the retry policy is unified across event subscribers: the subscriber MUST
|
|
11
|
+
* NOT loop internally. Instead, it rethrows on 5xx / network errors and the
|
|
12
|
+
* outer `EventEmitter._deliver` applies the spec retry policy declared via
|
|
13
|
+
* the `retry` field (defaults to `DEFAULT_RETRY` — 3 attempts, 100 ms initial
|
|
14
|
+
* backoff, 2× multiplier, 30 s cap). 4xx responses are treated as
|
|
15
|
+
* non-retryable: a warning is logged and the call returns normally.
|
|
10
16
|
*/
|
|
11
17
|
export declare class WebhookSubscriber implements EventSubscriber {
|
|
18
|
+
/** Declared subscriber kind for DLQ payloads (A-D-029). */
|
|
19
|
+
readonly subscriberType = "webhook";
|
|
20
|
+
readonly subscriberId: string;
|
|
21
|
+
readonly retry: RetryConfig;
|
|
12
22
|
private readonly _url;
|
|
13
23
|
private readonly _headers;
|
|
14
|
-
private readonly _retryCount;
|
|
15
24
|
private readonly _timeoutMs;
|
|
16
|
-
constructor(url: string, headers?: Record<string, string>,
|
|
25
|
+
constructor(url: string, headers?: Record<string, string>, timeoutMsOrOpts?: number | {
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
retry?: RetryConfig;
|
|
28
|
+
id?: string;
|
|
29
|
+
}, id?: string);
|
|
17
30
|
onEvent(event: ApCoreEvent): Promise<void>;
|
|
18
31
|
}
|
|
19
32
|
/**
|
|
20
33
|
* Delivers events via the A2A protocol to the platform.
|
|
21
34
|
*
|
|
22
35
|
* Sends a POST with `skillId="apevo.event_receiver"` and the
|
|
23
|
-
* serialized event in the payload.
|
|
36
|
+
* serialized event in the payload. As of v0.22.0 finding A-D-EVT-001 the
|
|
37
|
+
* subscriber no longer silently swallows errors. Mirroring
|
|
38
|
+
* `WebhookSubscriber`, it rethrows on 5xx / network errors so the unified
|
|
39
|
+
* `EventEmitter._deliver` retry policy applies (defaults to `DEFAULT_RETRY`
|
|
40
|
+
* — 3 attempts, 100 ms initial backoff, 2× multiplier, 30 s cap); after
|
|
41
|
+
* exhaustion the EventEmitter routes the failure through the DLQ +
|
|
42
|
+
* `onFailure` path. 4xx responses are treated as non-retryable: a warning
|
|
43
|
+
* is logged and the call returns normally (no retry, no DLQ).
|
|
24
44
|
*/
|
|
25
45
|
export declare class A2ASubscriber implements EventSubscriber {
|
|
46
|
+
/** Declared subscriber kind for DLQ payloads (A-D-029). */
|
|
47
|
+
readonly subscriberType = "a2a";
|
|
48
|
+
readonly subscriberId: string;
|
|
49
|
+
readonly retry: RetryConfig;
|
|
26
50
|
private readonly _platformUrl;
|
|
27
51
|
private readonly _auth;
|
|
28
52
|
private readonly _timeoutMs;
|
|
29
|
-
|
|
53
|
+
private readonly _skillId;
|
|
54
|
+
constructor(platformUrl: string, auth?: string | Record<string, string | unknown>, timeoutMsOrOpts?: number | {
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
retry?: RetryConfig;
|
|
57
|
+
id?: string;
|
|
58
|
+
skillId?: string;
|
|
59
|
+
}, id?: string, skillId?: string);
|
|
30
60
|
onEvent(event: ApCoreEvent): Promise<void>;
|
|
31
61
|
}
|
|
32
62
|
/** Writes events to a local file (built-in type: 'file'). */
|
|
33
63
|
export declare class FileSubscriber implements EventSubscriber {
|
|
64
|
+
/** Declared subscriber kind for DLQ payloads (A-D-029). */
|
|
65
|
+
readonly subscriberType = "file";
|
|
66
|
+
readonly subscriberId: string;
|
|
34
67
|
private readonly _path;
|
|
35
68
|
private readonly _append;
|
|
36
69
|
private readonly _format;
|
|
37
70
|
private readonly _rotateBytes;
|
|
38
|
-
constructor(path: string, append?: boolean, format?: string, rotateBytes?: number);
|
|
71
|
+
constructor(path: string, append?: boolean, format?: string, rotateBytes?: number, id?: string);
|
|
39
72
|
onEvent(event: ApCoreEvent): Promise<void>;
|
|
40
73
|
}
|
|
41
74
|
/** Writes events to stdout (built-in type: 'stdout'). */
|
|
42
75
|
export declare class StdoutSubscriber implements EventSubscriber {
|
|
76
|
+
/** Declared subscriber kind for DLQ payloads (A-D-029). */
|
|
77
|
+
readonly subscriberType = "stdout";
|
|
78
|
+
readonly subscriberId: string;
|
|
43
79
|
private readonly _format;
|
|
44
80
|
private readonly _levelFilter;
|
|
45
|
-
constructor(format?: string, levelFilter?: string);
|
|
81
|
+
constructor(format?: string, levelFilter?: string, id?: string);
|
|
46
82
|
onEvent(event: ApCoreEvent): Promise<void>;
|
|
47
83
|
}
|
|
48
84
|
/**
|
|
@@ -54,10 +90,19 @@ export declare class StdoutSubscriber implements EventSubscriber {
|
|
|
54
90
|
* 3. If neither is set, forward all events.
|
|
55
91
|
*/
|
|
56
92
|
export declare class FilterSubscriber implements EventSubscriber {
|
|
93
|
+
/** Declared subscriber kind for DLQ payloads (A-D-029). */
|
|
94
|
+
readonly subscriberType = "filter";
|
|
95
|
+
/** Stable identity for DLQ payloads and dedup (A-D-022). */
|
|
96
|
+
readonly subscriberId: string;
|
|
97
|
+
/** Retry policy applied by EventEmitter._deliver (A-D-022). */
|
|
98
|
+
readonly retry: RetryConfig;
|
|
57
99
|
private readonly _delegate;
|
|
58
100
|
private readonly _includeEvents;
|
|
59
101
|
private readonly _excludeEvents;
|
|
60
|
-
constructor(delegate: EventSubscriber, includeEvents?: string[], excludeEvents?: string[]
|
|
102
|
+
constructor(delegate: EventSubscriber, includeEvents?: string[], excludeEvents?: string[], opts?: {
|
|
103
|
+
id?: string;
|
|
104
|
+
retry?: RetryConfig;
|
|
105
|
+
});
|
|
61
106
|
onEvent(event: ApCoreEvent): Promise<void>;
|
|
62
107
|
private _matches;
|
|
63
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribers.d.ts","sourceRoot":"","sources":["../../src/events/subscribers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"subscribers.d.ts","sourceRoot":"","sources":["../../src/events/subscribers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAa9C;;;;;;;;;;GAUG;AACH,qBAAa,iBAAkB,YAAW,eAAe;IACvD,2DAA2D;IAC3D,QAAQ,CAAC,cAAc,aAAa;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAGlC,GAAG,EAAE,MA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