@agenticprimitives/orchestration 0.0.0-alpha.1 → 0.0.0-alpha.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.
Files changed (61) hide show
  1. package/dist/admission.d.ts +87 -0
  2. package/dist/admission.d.ts.map +1 -0
  3. package/dist/admission.js +193 -0
  4. package/dist/admission.js.map +1 -0
  5. package/dist/artifacts.d.ts +137 -0
  6. package/dist/artifacts.d.ts.map +1 -0
  7. package/dist/artifacts.js +232 -0
  8. package/dist/artifacts.js.map +1 -0
  9. package/dist/authority.d.ts +431 -0
  10. package/dist/authority.d.ts.map +1 -0
  11. package/dist/authority.js +2 -0
  12. package/dist/authority.js.map +1 -0
  13. package/dist/durable.d.ts +44 -0
  14. package/dist/durable.d.ts.map +1 -0
  15. package/dist/durable.js +15 -0
  16. package/dist/durable.js.map +1 -0
  17. package/dist/flow-trace.d.ts +105 -0
  18. package/dist/flow-trace.d.ts.map +1 -0
  19. package/dist/flow-trace.js +60 -0
  20. package/dist/flow-trace.js.map +1 -0
  21. package/dist/index.d.ts +20 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +21 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/input.d.ts +165 -0
  26. package/dist/input.d.ts.map +1 -0
  27. package/dist/input.js +33 -0
  28. package/dist/input.js.map +1 -0
  29. package/dist/loop.d.ts +115 -3
  30. package/dist/loop.d.ts.map +1 -1
  31. package/dist/loop.js +656 -30
  32. package/dist/loop.js.map +1 -1
  33. package/dist/metrics.d.ts +35 -0
  34. package/dist/metrics.d.ts.map +1 -0
  35. package/dist/metrics.js +98 -0
  36. package/dist/metrics.js.map +1 -0
  37. package/dist/planner-wire.d.ts +11 -0
  38. package/dist/planner-wire.d.ts.map +1 -0
  39. package/dist/planner-wire.js +53 -0
  40. package/dist/planner-wire.js.map +1 -0
  41. package/dist/planner.d.ts +33 -0
  42. package/dist/planner.d.ts.map +1 -1
  43. package/dist/planner.js.map +1 -1
  44. package/dist/record.d.ts +151 -0
  45. package/dist/record.d.ts.map +1 -0
  46. package/dist/record.js +72 -0
  47. package/dist/record.js.map +1 -0
  48. package/dist/spans.d.ts +200 -0
  49. package/dist/spans.d.ts.map +1 -0
  50. package/dist/spans.js +522 -0
  51. package/dist/spans.js.map +1 -0
  52. package/dist/tool-invoker.d.ts +7 -0
  53. package/dist/tool-invoker.d.ts.map +1 -1
  54. package/dist/trace-context.d.ts +26 -0
  55. package/dist/trace-context.d.ts.map +1 -0
  56. package/dist/trace-context.js +59 -0
  57. package/dist/trace-context.js.map +1 -0
  58. package/dist/types.d.ts +180 -3
  59. package/dist/types.d.ts.map +1 -1
  60. package/dist/types.js.map +1 -1
  61. package/package.json +4 -1
package/dist/record.js ADDED
@@ -0,0 +1,72 @@
1
+ import { runIntent } from './loop.js';
2
+ export function recordOf(input) {
3
+ const stepRefOf = (o, i) => o.stepRef ?? o.step.id ?? `s${i}`;
4
+ return {
5
+ type: 'ap.run-record.v1',
6
+ runRef: input.runRef,
7
+ at: input.now ?? Date.now(),
8
+ intent: input.intent,
9
+ plan: input.result.plan,
10
+ steps: input.result.steps.map((o, i) => ({
11
+ stepRef: stepRefOf(o, i), toolId: o.step.toolId, args: o.step.args, ok: o.ok,
12
+ ...(o.result !== undefined ? { result: o.result } : {}), ...(o.error ? { error: o.error } : {}),
13
+ ...(o.skipped ? { skipped: true } : {}), ...(o.replayed ? { replayed: true } : {}),
14
+ })),
15
+ receipts: [...input.result.receipts],
16
+ events: [...input.events],
17
+ outcome: input.result.outcome,
18
+ ...(input.traceContext ? { traceContext: input.traceContext } : {}),
19
+ ...(input.planner ? { planner: input.planner } : {}),
20
+ ...(typeof input.receivedAt === 'number' && input.receivedAt > 0 ? { receivedAt: input.receivedAt } : {}),
21
+ ...(input.offloaded?.length ? { offloaded: input.offloaded } : {}),
22
+ ...(input.bill ? { bill: input.bill } : {}),
23
+ ...(input.presented?.length ? { presented: [...input.presented] } : {}),
24
+ };
25
+ }
26
+ /** An invoker that answers each step from the record and runs nothing. A step the record does not hold
27
+ * is refused, never executed: a replay may not do new work under an old name. */
28
+ export function replayingInvoker(record) {
29
+ const byRef = new Map(record.steps.map((s) => [s.stepRef, s]));
30
+ return async (toolId, _args, ctx) => {
31
+ const stepRef = ctx.step.id ?? `s${ctx.index}`;
32
+ const rec = byRef.get(stepRef);
33
+ if (!rec || rec.toolId !== toolId)
34
+ throw new Error(`replay: step ${stepRef} (${toolId}) was not recorded — nothing runs on a replay`);
35
+ if (!rec.ok)
36
+ throw new Error(rec.error ?? `replay: step ${stepRef} failed when recorded`);
37
+ return rec.result;
38
+ };
39
+ }
40
+ function verdictOf(r) {
41
+ return r?.authority?.decision.decision ?? null;
42
+ }
43
+ /**
44
+ * Replay a record: the SAME plan (the planner is not asked), the SAME observations (the tools are not
45
+ * run), and a FRESH pass through every gate the caller provides. Compare per step what was decided then
46
+ * with what is decided now. `opts` carries the live ports, tools and — when the caller can present them —
47
+ * the record's own mandates (a replay presenting nothing reports authority-required for every act, which
48
+ * is also a true statement about now).
49
+ */
50
+ export async function replayRun(record, opts) {
51
+ const result = await runIntent(record.intent, {
52
+ ...opts,
53
+ planner: { plan: async () => ({ steps: record.plan.steps.map((s) => ({ ...s })), rationale: `replay of ${record.runRef}` }) },
54
+ invoke: replayingInvoker(record),
55
+ runRef: `${record.runRef}:replay`,
56
+ onMissingMandate: 'report',
57
+ presented: opts.presented ?? record.presented ?? null,
58
+ });
59
+ const recordedBy = new Map(record.receipts.filter((r) => !r.stepRef.endsWith(':compensate')).map((r) => [r.stepRef, r]));
60
+ const replayedBy = new Map(result.receipts.map((r) => [r.stepRef, r]));
61
+ const refs = [...new Set([...recordedBy.keys(), ...replayedBy.keys()])];
62
+ const verdicts = refs.map((stepRef) => {
63
+ const rec = recordedBy.get(stepRef);
64
+ const rep = replayedBy.get(stepRef);
65
+ const recorded = verdictOf(rec);
66
+ const replayed = verdictOf(rep);
67
+ const because = rep?.authority?.decision.decision === 'deny' ? rep.authority.decision.reasons.map((x) => `${x.code}: ${x.message}`).join('; ') : rep?.status === 'authority-required' ? 'no mandate presented on the replay' : undefined;
68
+ return { stepRef, toolId: rec?.toolId ?? rep?.toolId ?? '', recorded, replayed, changed: recorded !== replayed, ...(because ? { because } : {}) };
69
+ });
70
+ return { runRef: record.runRef, outcome: result.outcome, recordedOutcome: record.outcome, verdicts, result };
71
+ }
72
+ //# sourceMappingURL=record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAsB,MAAM,WAAW,CAAC;AA0E1D,MAAM,UAAU,QAAQ,CAAC,KAA0S;IACjU,MAAM,SAAS,GAAG,CAAC,CAAkB,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC;IACvF,OAAO;QACL,IAAI,EAAE,kBAAkB;QACxB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,EAAE,EAAE,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE;QAC3B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI;QACvB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YACvC,OAAO,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE;YAC5E,GAAG,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CA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,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAAC,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAAC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QACjE,MAAM,OAAO,GAAG,GAAG,EAAE,SAAS,EAAE,QAAQ,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,oBAAoB,CAAC,CAAC,CAAC,oCAAoC,CAAC,CAAC,CAAC,SAAS,CAAC;QACzO,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,IAAI,GAAG,EAAE,MAAM,IAAI,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,KAAK,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACpJ,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC/G,CAAC"}
@@ -0,0 +1,200 @@
1
+ import type { RunRecordV1 } from './record.js';
2
+ import type { StepReceipt } from './authority.js';
3
+ /** One span, vendor-neutral. Ids are W3C trace-context sized (16-byte trace, 8-byte span), derived from the
4
+ * run and step references so a re-export of the same record is the same trace. */
5
+ export interface SpanV1 {
6
+ traceId: string;
7
+ spanId: string;
8
+ parentSpanId?: string;
9
+ name: string;
10
+ kind: 'INTERNAL' | 'CLIENT' | 'SERVER';
11
+ /** Milliseconds since the epoch. */
12
+ startMs: number;
13
+ endMs: number;
14
+ status: 'OK' | 'ERROR' | 'UNSET';
15
+ attributes: Record<string, string | number | boolean>;
16
+ /** Spec 381 W2 — a causal link to a span of ANOTHER run in the same trace: the child run a step was handed
17
+ * to. Ids only; the link carries no more than the span does. */
18
+ links?: Array<{
19
+ traceId: string;
20
+ spanId: string;
21
+ attributes?: Record<string, string>;
22
+ }>;
23
+ /** Spec 390 W4 — the run's events on the span they belong to (a verdict, an approval, a receipt), as OTel span
24
+ * events: the event's name, when, and names-and-classes attributes through the same allowlist. */
25
+ events?: Array<{
26
+ name: string;
27
+ timeMs: number;
28
+ attributes?: Record<string, string | number | boolean>;
29
+ }>;
30
+ }
31
+ /** The attribute names a span MAY carry — the firewall's allowlist. Anything else is refused at export. */
32
+ export declare const SPAN_ATTRIBUTE_ALLOWLIST: ReadonlySet<string>;
33
+ /** Spec 390 — the PROV ids a span names, derived exactly as `provenance.harnessIds` derives them (the two
34
+ * packages cannot import each other; `run-export.test.ts` asserts they agree). */
35
+ export declare const PROV_ID_BASE = "urn:ap:prov:";
36
+ export declare const provIds: {
37
+ run: (runRef: string) => string;
38
+ step: (runRef: string, stepRef: string) => string;
39
+ bundle: (runRef: string) => string;
40
+ plan: (runRef: string) => string;
41
+ planStep: (runRef: string, stepRef: string) => string;
42
+ };
43
+ /** The digest of a receipt as recorded — the one thing a span carries that names an act. */
44
+ export declare function receiptDigest(r: StepReceipt): Promise<string>;
45
+ /** W3C-sized ids derived from references: 16-byte trace, 8-byte span. Correlation, never trust (spec 390). */
46
+ export declare const traceIdOf: (runRef: string) => Promise<string>;
47
+ export declare const spanIdOf: (runRef: string, stepRef: string | null) => Promise<string>;
48
+ /** Spec 390 W2 — THE TRACE A RUN BELONGS TO, and what its root span is parented to. The wire wins: a
49
+ * `traceparent` the request arrived with names the caller's trace and span. Absent that, a routed or
50
+ * handed-off run derives the sender's trace from the run it answers (381 W2); a fresh run derives its own.
51
+ * One rule, used by the spans and by the provenance view, so the graph and the trace name the same trace. */
52
+ export declare function traceIdFor(record: RunRecordV1): Promise<{
53
+ traceId: string;
54
+ parentSpanId?: string;
55
+ origin?: {
56
+ runRef: string;
57
+ stepRef?: string;
58
+ };
59
+ }>;
60
+ /** The run as spans. Pure; the same record always yields the same trace. */
61
+ export declare function spansOf(record: RunRecordV1): Promise<SpanV1[]>;
62
+ /**
63
+ * Spec 390 W3 — THE AUTHORITY STAGES, THE MODEL CALLS AND THE OUTCOME AS SPANS, projected from the record's
64
+ * stamped events (`RunEvent.at`) and its planner summary. Nothing is instrumented inline: the same record
65
+ * yields the same tree, and the firewall stays the whole surface.
66
+ *
67
+ * invoke_agent
68
+ * ├── receive_request the request's arrival → RunStarted: admission and preparation (session, standing, playbook), un-itemised
69
+ * ├── identify_principal instant, at run start — the standing this hop ran under (383 W2), the anchors as digests
70
+ * ├── plan [model] RunStarted → the first PlanCreated; `chat` on the model that planned, with the route's reason
71
+ * ├── execute_tool <tool> the step (381), and UNDER it:
72
+ * │ ├── verify_mandate StepProposed → MandateChecked (and again after an approval)
73
+ * │ ├── await_approval ApprovalRequested → ApprovalDischarged, when both landed in this record
74
+ * │ └── perform_action instant at the step's end when it left a chain transaction or effects
75
+ * └── issue_outcome RunCompleted → the record's time; `chat` on the model that composed
76
+ *
77
+ * A stage whose two stamps are not both on the record is not emitted — a record written before events
78
+ * were stamped simply has no stage spans, never guessed ones. `resolve_delegation` (the chain walk) is not
79
+ * a separate span: the verifier walks the chain inside `verify_mandate`, whose attributes carry the chain
80
+ * (depth, digest) — one span, said honestly. `retrieval` waits for a tool to DECLARE itself one.
81
+ */
82
+ export declare function stageSpansOf(record: RunRecordV1, ctx: {
83
+ traceId: string;
84
+ rootId: string;
85
+ stepIds: Map<string, string>;
86
+ }): Promise<SpanV1[]>;
87
+ /**
88
+ * THE FIREWALL, re-read. Every attribute must be allowlisted, and no value may carry an address, the
89
+ * intent's words, or any step's argument values. Throws naming the span and attribute, so a leak is a
90
+ * build failure and a test failure, never a quiet export.
91
+ */
92
+ export declare function assertFirewalled(spans: readonly SpanV1[], record: RunRecordV1): void;
93
+ /** Spec 390 W4 — the same firewall over a run's metric attributes: allowlisted names, no address, no words. */
94
+ export declare function assertMetricsFirewalled(points: ReadonlyArray<{
95
+ attributes: Record<string, string | number | boolean>;
96
+ }>, record: RunRecordV1): void;
97
+ /** The OTLP/HTTP JSON body for these spans (`ExportTraceServiceRequest`), for a collector's `/v1/traces`.
98
+ * Pure: the caller posts it. `resource` names the exporting service (its attributes go through the same
99
+ * allowlist as a span's would not — they name the SERVICE, never the run, so `service.name` is the one). */
100
+ export declare function otlpTracesOf(spans: readonly SpanV1[], resource: {
101
+ serviceName: string;
102
+ version?: string;
103
+ }): unknown;
104
+ /** What the vault keeps of a run (spec 381 §2): the PROV-O A-box in record form — one activity per step,
105
+ * what it used (the authority), what it generated (the receipt, by digest), how it ended. Never the
106
+ * arguments, results or words; those are the DO's rebuildable copy and the person's own memory. */
107
+ export interface RunProvenanceV1 {
108
+ type: 'ap.run-provenance.v1';
109
+ runRef: string;
110
+ /** ISO time the run ended. */
111
+ endedAt: string;
112
+ /** The agent the run ran at — whose authority was spent, whose vault this is. */
113
+ agent: string;
114
+ /** Who asked — an address the record's intent carried, or absent for an unattended run. */
115
+ asker?: string;
116
+ intentDigest?: string;
117
+ outcome: RunRecordV1['outcome'];
118
+ /** The playbook the run followed, when one did (the commitment is the definition digest). */
119
+ playbook?: {
120
+ skillId: string;
121
+ version: string;
122
+ commitment: string;
123
+ };
124
+ /** Spec 389 — the request this run answered (a routed or handed-off run, 367 §8): the sender's agent, run
125
+ * and step, so the run's provenance bundle can say which bundle it `wasInformedBy`. */
126
+ inResponseTo?: {
127
+ agent: string;
128
+ runRef: string;
129
+ stepRef?: string;
130
+ };
131
+ /** Spec 390 — the trace the run's spans belong to and the run's root span, so the graph names the trace. */
132
+ traceId: string;
133
+ spanId: string;
134
+ steps: Array<{
135
+ stepRef: string;
136
+ /** Spec 390 — the span this step's activity is. */
137
+ spanId: string;
138
+ toolId: string;
139
+ capability?: {
140
+ id: string;
141
+ action: string;
142
+ };
143
+ risk?: string;
144
+ status: string;
145
+ startedAt?: string;
146
+ endedAt?: string;
147
+ authority?: {
148
+ presentedRef: string | null;
149
+ decision: string;
150
+ afterApproval: boolean;
151
+ /** Spec 383 — the verified chain: every grant by reference, the accountability root, the acting agent. */
152
+ chain?: {
153
+ accountabilityRoot: string;
154
+ actingAgent: string;
155
+ depth: number;
156
+ chainDigest: string;
157
+ links: Array<{
158
+ ref: string;
159
+ delegator: string;
160
+ delegate: string;
161
+ parentRef: string | null;
162
+ }>;
163
+ };
164
+ };
165
+ /** Spec 383 — who acted for whom in this hop. */
166
+ actor?: {
167
+ rootPrincipal?: string;
168
+ originatingAgent?: string;
169
+ actingAgent: string;
170
+ };
171
+ receiptDigest?: string;
172
+ inputDigest?: string;
173
+ outputDigest?: string;
174
+ /** A chain transaction the step left, when its result named one — the one public fact a step can cite. */
175
+ txHash?: string;
176
+ delegatedTo?: string;
177
+ /** Spec 389 — the child run a hand-off step's work ran as (its bundle is what the step `wasInformedBy`). */
178
+ delegatedToRun?: string;
179
+ /** Spec 391 — the step's raw result was offloaded to the acting agent's vault. */
180
+ artifact?: {
181
+ recordType: string;
182
+ digest: string;
183
+ bytes: number;
184
+ };
185
+ effects?: Array<{
186
+ produces: string;
187
+ ok: boolean;
188
+ }>;
189
+ decisions?: Array<{
190
+ point: string;
191
+ ruleId: string;
192
+ }>;
193
+ errorClass?: string;
194
+ }>;
195
+ }
196
+ export declare function provenanceOf(record: RunRecordV1, agent: string): Promise<RunProvenanceV1>;
197
+ /** The vault record key a run's provenance lives under, in the acting agent's vault. */
198
+ export declare const RUN_PROVENANCE_RECORD_PREFIX: "run.provenance:";
199
+ export declare const runProvenanceRecordKey: (runRef: string) => string;
200
+ //# sourceMappingURL=spans.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spans.d.ts","sourceRoot":"","sources":["../src/spans.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;mFACmF;AACnF,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACvC,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IACtD;qEACiE;IACjE,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;IACxF;uGACmG;IACnG,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CAC1G;AAED,2GAA2G;AAC3G,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,MAAM,CA6BvD,CAAC;AAEH;mFACmF;AACnF,eAAO,MAAM,YAAY,iBAAiB,CAA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