@newrelic/preflight 1.4.47 → 1.5.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 (60) hide show
  1. package/dist/dashboard/index.d.ts +1 -1
  2. package/dist/dashboard/index.d.ts.map +1 -1
  3. package/dist/dashboard/live-event-bus.d.ts +32 -0
  4. package/dist/dashboard/live-event-bus.d.ts.map +1 -1
  5. package/dist/dashboard/live-event-bus.js.map +1 -1
  6. package/dist/dashboard/routes/api-handler.d.ts +46 -0
  7. package/dist/dashboard/routes/api-handler.d.ts.map +1 -1
  8. package/dist/dashboard/routes/api-handler.js +188 -5
  9. package/dist/dashboard/routes/api-handler.js.map +1 -1
  10. package/dist/dashboard/subagent-timeline-store.d.ts +156 -0
  11. package/dist/dashboard/subagent-timeline-store.d.ts.map +1 -0
  12. package/dist/dashboard/subagent-timeline-store.js +674 -0
  13. package/dist/dashboard/subagent-timeline-store.js.map +1 -0
  14. package/dist/dashboard/workflow-store.d.ts +85 -0
  15. package/dist/dashboard/workflow-store.d.ts.map +1 -0
  16. package/dist/dashboard/workflow-store.js +330 -0
  17. package/dist/dashboard/workflow-store.js.map +1 -0
  18. package/dist/hooks/event-processor.d.ts +86 -1
  19. package/dist/hooks/event-processor.d.ts.map +1 -1
  20. package/dist/hooks/event-processor.js +182 -0
  21. package/dist/hooks/event-processor.js.map +1 -1
  22. package/dist/hooks/subagent-watcher.d.ts +182 -0
  23. package/dist/hooks/subagent-watcher.d.ts.map +1 -0
  24. package/dist/hooks/subagent-watcher.js +765 -0
  25. package/dist/hooks/subagent-watcher.js.map +1 -0
  26. package/dist/hooks/workflow-script-parser.d.ts +44 -0
  27. package/dist/hooks/workflow-script-parser.d.ts.map +1 -0
  28. package/dist/hooks/workflow-script-parser.js +255 -0
  29. package/dist/hooks/workflow-script-parser.js.map +1 -0
  30. package/dist/hooks/workflow-watcher.d.ts +65 -0
  31. package/dist/hooks/workflow-watcher.d.ts.map +1 -0
  32. package/dist/hooks/workflow-watcher.js +402 -0
  33. package/dist/hooks/workflow-watcher.js.map +1 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +315 -11
  36. package/dist/index.js.map +1 -1
  37. package/dist/metrics/cost-tracker.d.ts +113 -17
  38. package/dist/metrics/cost-tracker.d.ts.map +1 -1
  39. package/dist/metrics/cost-tracker.js +151 -8
  40. package/dist/metrics/cost-tracker.js.map +1 -1
  41. package/dist/metrics/workflow-run-tracker.d.ts +140 -0
  42. package/dist/metrics/workflow-run-tracker.d.ts.map +1 -0
  43. package/dist/metrics/workflow-run-tracker.js +306 -0
  44. package/dist/metrics/workflow-run-tracker.js.map +1 -0
  45. package/dist/storage/session-store.d.ts +8 -0
  46. package/dist/storage/session-store.d.ts.map +1 -1
  47. package/dist/storage/session-store.js +1 -1
  48. package/dist/storage/session-store.js.map +1 -1
  49. package/dist/storage/types.d.ts +40 -1
  50. package/dist/storage/types.d.ts.map +1 -1
  51. package/dist/transport/nr-ingest.d.ts +153 -2
  52. package/dist/transport/nr-ingest.d.ts.map +1 -1
  53. package/dist/transport/nr-ingest.js +276 -1
  54. package/dist/transport/nr-ingest.js.map +1 -1
  55. package/dist/web/assets/index-B4DkT4Go.css +2 -0
  56. package/dist/web/assets/index-CWwZdwYX.js +64 -0
  57. package/dist/web/index.html +2 -2
  58. package/package.json +1 -1
  59. package/dist/web/assets/index-CrBs4WEp.js +0 -64
  60. package/dist/web/assets/index-DwBQxRYb.css +0 -2
@@ -7,8 +7,10 @@
7
7
  *
8
8
  * Cost calculation delegates to `calculateCost()` from the shared package.
9
9
  */
10
- import { calculateCost } from '../shared/index.js';
10
+ import { calculateCost, createLogger } from '../shared/index.js';
11
11
  import { localDateKey } from '../lib/date.js';
12
+ const logger = createLogger('cost-tracker');
13
+ const LATE_ARRIVAL_REJECTION_MS = 48 * 60 * 60 * 1000;
12
14
  // ---------------------------------------------------------------------------
13
15
  // CostTracker
14
16
  // ---------------------------------------------------------------------------
@@ -33,16 +35,39 @@ export class CostTracker {
33
35
  // including tokens spent before midnight.
34
36
  costByDayUsd = new Map();
35
37
  firstActivityMsByDay = new Map();
38
+ /**
39
+ * Per-workflow-run cost attribution split by local-day so a run that crosses
40
+ * midnight contributes to each day's bucket independently. Two-level map:
41
+ * `costByWorkflowRunId.get(runId).get(dayKey) → usd`. Restart-resets to empty
42
+ * (intentional: per-day totals remain correct even if run-level attribution
43
+ * is lost across restarts).
44
+ */
45
+ costByWorkflowRunId = new Map();
46
+ /** Per-day mutation counter so dashboards can invalidate cached day cards. */
47
+ lastMutationMsByDay = new Map();
48
+ /**
49
+ * Subagent-attributed spend: accumulated when `ctx.agentId` is set.
50
+ * Parent spend covers all other token reports.
51
+ */
52
+ subagentCostUsd = 0;
53
+ /** Subagent-attributed spend per local-day key, for a today-scoped KPI. */
54
+ subagentCostByDayUsd = new Map();
55
+ parentCostUsd = 0;
36
56
  totalLinesChanged = 0;
37
57
  constructor(sessionTracker) {
38
58
  this.sessionTracker = sessionTracker ?? null;
39
59
  }
40
60
  /**
41
61
  * Primary path: record exact token usage from self-reporting.
62
+ *
63
+ * The optional `ctx` argument lets the subagent watcher attribute tokens
64
+ * to the actual JSONL `timestamp` (rather than `Date.now()`) so a run
65
+ * that crosses midnight is bucketed correctly, AND to a `workflowRunId` /
66
+ * `agentId` for per-run and subagent/parent cost attribution.
42
67
  */
43
- recordTokenUsage(usage, model) {
68
+ recordTokenUsage(usage, model, ctx) {
44
69
  this.reportCount++;
45
- return this.accumulateTokens(usage, model);
70
+ return this.accumulateTokens(usage, model, ctx);
46
71
  }
47
72
  /**
48
73
  * Fallback path: estimate tokens from character counts.
@@ -62,8 +87,40 @@ export class CostTracker {
62
87
  this.estimationCount++;
63
88
  return this.accumulateTokens(usage, model);
64
89
  }
65
- accumulateTokens(usage, model) {
90
+ accumulateTokens(usage, model, ctx) {
66
91
  const breakdown = calculateCost(model, usage);
92
+ const wallNowMs = Date.now();
93
+ // Late-arrival rejection: a `ctx.timestampMs` more than 48h before now is
94
+ // dropped from day buckets to bound retroactive mutation. Session-level
95
+ // totals (totalCostUsd, subagentCostUsd, etc.) still accumulate because
96
+ // they are session-scoped and the cost is real.
97
+ const tsMs = ctx?.timestampMs ?? wallNowMs;
98
+ const isLate = ctx?.timestampMs !== undefined && wallNowMs - ctx.timestampMs > LATE_ARRIVAL_REJECTION_MS;
99
+ if (isLate) {
100
+ logger.warn('Late-arrival token event dropped from day bucket', {
101
+ timestampMs: ctx?.timestampMs,
102
+ deltaMs: wallNowMs - (ctx?.timestampMs ?? wallNowMs),
103
+ });
104
+ // Still accumulate session-level totals, but skip day bucketing and
105
+ // workflow-run maps.
106
+ this.totalCostUsd += breakdown.totalUsd;
107
+ this.totalInputTokens += usage.inputTokens;
108
+ this.totalOutputTokens += usage.outputTokens;
109
+ this.totalThinkingTokens += usage.thinkingTokens;
110
+ this.totalCacheReadTokens += usage.cacheReadTokens;
111
+ this.totalCacheCreationTokens += usage.cacheCreationTokens;
112
+ this.currentModel = model;
113
+ this.latestCostBreakdown = breakdown;
114
+ this.costByModel.set(model, (this.costByModel.get(model) ?? 0) + breakdown.totalUsd);
115
+ this.totalCacheSavingsUsd += breakdown.savingsFromCacheUsd;
116
+ if (ctx?.agentId !== undefined) {
117
+ this.subagentCostUsd += breakdown.totalUsd;
118
+ }
119
+ else {
120
+ this.parentCostUsd += breakdown.totalUsd;
121
+ }
122
+ return breakdown;
123
+ }
67
124
  this.totalCostUsd += breakdown.totalUsd;
68
125
  this.totalInputTokens += usage.inputTokens;
69
126
  this.totalOutputTokens += usage.outputTokens;
@@ -74,11 +131,31 @@ export class CostTracker {
74
131
  this.latestCostBreakdown = breakdown;
75
132
  this.costByModel.set(model, (this.costByModel.get(model) ?? 0) + breakdown.totalUsd);
76
133
  this.totalCacheSavingsUsd += breakdown.savingsFromCacheUsd;
77
- const nowMs = Date.now();
78
- const dayKey = localDateKey(nowMs);
134
+ // Subagent vs parent split
135
+ if (ctx?.agentId !== undefined) {
136
+ this.subagentCostUsd += breakdown.totalUsd;
137
+ }
138
+ else {
139
+ this.parentCostUsd += breakdown.totalUsd;
140
+ }
141
+ // Day bucketing
142
+ const dayKey = localDateKey(tsMs);
79
143
  this.costByDayUsd.set(dayKey, (this.costByDayUsd.get(dayKey) ?? 0) + breakdown.totalUsd);
80
- if (!this.firstActivityMsByDay.has(dayKey)) {
81
- this.firstActivityMsByDay.set(dayKey, nowMs);
144
+ if (ctx?.agentId !== undefined) {
145
+ this.subagentCostByDayUsd.set(dayKey, (this.subagentCostByDayUsd.get(dayKey) ?? 0) + breakdown.totalUsd);
146
+ }
147
+ this.lastMutationMsByDay.set(dayKey, wallNowMs);
148
+ const existingFirst = this.firstActivityMsByDay.get(dayKey);
149
+ if (existingFirst === undefined || tsMs < existingFirst) {
150
+ // Use earliest event timestamp for the day so cross-midnight burn-rate
151
+ // denominators stay correct (NOT wall-clock arrival time).
152
+ this.firstActivityMsByDay.set(dayKey, tsMs);
153
+ }
154
+ // Per-workflow-run day bucketing
155
+ if (ctx?.workflowRunId) {
156
+ const runMap = this.costByWorkflowRunId.get(ctx.workflowRunId) ?? new Map();
157
+ runMap.set(dayKey, (runMap.get(dayKey) ?? 0) + breakdown.totalUsd);
158
+ this.costByWorkflowRunId.set(ctx.workflowRunId, runMap);
82
159
  }
83
160
  return breakdown;
84
161
  }
@@ -99,6 +176,15 @@ export class CostTracker {
99
176
  getCostForDay(dayKey) {
100
177
  return this.costByDayUsd.get(dayKey) ?? 0;
101
178
  }
179
+ /**
180
+ * Subagent-attributed cost during a specific local-time day. Today-scoped
181
+ * counterpart to getSubagentMetrics().subagentUsd (which is session-
182
+ * cumulative) so the "subagent spend" KPI lines up with the day-bucketed
183
+ * "spend today" total.
184
+ */
185
+ getSubagentCostForDay(dayKey) {
186
+ return this.subagentCostByDayUsd.get(dayKey) ?? 0;
187
+ }
102
188
  /**
103
189
  * Epoch ms of the first token event recorded today (local time), or null
104
190
  * if no spend has been booked today. The forecast burn-rate denominator
@@ -109,6 +195,48 @@ export class CostTracker {
109
195
  getFirstActivityMsForDay(dayKey) {
110
196
  return this.firstActivityMsByDay.get(dayKey) ?? null;
111
197
  }
198
+ /** Most recent wall-clock ms a per-day bucket was mutated (cache-key seed). */
199
+ getLastMutationMsForDay(dayKey) {
200
+ return this.lastMutationMsByDay.get(dayKey) ?? null;
201
+ }
202
+ /**
203
+ * Per-workflow-run total spend, summed across all day-keys this run
204
+ * touched. Returns 0 for unknown runIds.
205
+ */
206
+ getCostForWorkflowRun(runId) {
207
+ const m = this.costByWorkflowRunId.get(runId);
208
+ if (!m)
209
+ return 0;
210
+ let total = 0;
211
+ for (const v of m.values())
212
+ total += v;
213
+ return total;
214
+ }
215
+ /** Iterable view of every (runId, dayKey, usd) tuple — for dashboard joins. */
216
+ *iterCostByWorkflowRun() {
217
+ for (const [runId, m] of this.costByWorkflowRunId) {
218
+ for (const [dayKey, usd] of m) {
219
+ yield { runId, dayKey, usd };
220
+ }
221
+ }
222
+ }
223
+ /**
224
+ * Subagent / parent cost split for the current session.
225
+ *
226
+ * `reconciliationDeltaPct` is a Phase 3 placeholder: it will compare the
227
+ * total tokens reported by WorkflowRunEvent against the sum of per-subagent
228
+ * cost to detect attribution gaps. Returns null until that data is available.
229
+ */
230
+ getSubagentMetrics() {
231
+ const total = this.subagentCostUsd + this.parentCostUsd;
232
+ const subagentSharePct = total > 0 ? (this.subagentCostUsd / total) * 100 : 0;
233
+ return {
234
+ subagentUsd: this.subagentCostUsd,
235
+ parentUsd: this.parentCostUsd,
236
+ subagentSharePct,
237
+ reconciliationDeltaPct: null,
238
+ };
239
+ }
112
240
  /**
113
241
  * Record lines of code changed (from Edit/Write tool data).
114
242
  */
@@ -120,6 +248,11 @@ export class CostTracker {
120
248
  const uniqueFilesWritten = this.sessionTracker
121
249
  ? this.sessionTracker.getMetrics().uniqueFilesWritten
122
250
  : 0;
251
+ // Serialise the two-level Map into a plain Record for JSON compatibility.
252
+ const costByWorkflowRunId = {};
253
+ for (const [runId, dayMap] of this.costByWorkflowRunId) {
254
+ costByWorkflowRunId[runId] = Object.fromEntries(dayMap);
255
+ }
123
256
  return {
124
257
  sessionTotalCostUsd: hasData ? this.totalCostUsd : null,
125
258
  costByTask: null,
@@ -137,6 +270,9 @@ export class CostTracker {
137
270
  reportCount: this.reportCount,
138
271
  estimationCount: this.estimationCount,
139
272
  latestCostBreakdown: this.latestCostBreakdown,
273
+ subagentCostUsd: this.subagentCostUsd,
274
+ parentCostUsd: this.parentCostUsd,
275
+ costByWorkflowRunId,
140
276
  };
141
277
  }
142
278
  emitMetrics(aggregator) {
@@ -162,6 +298,8 @@ export class CostTracker {
162
298
  }
163
299
  aggregator.record('ai.cost.report_count', this.reportCount, attrs);
164
300
  aggregator.record('ai.cost.estimation_count', this.estimationCount, attrs);
301
+ aggregator.record('ai.cost.subagent_usd', this.subagentCostUsd, attrs);
302
+ aggregator.record('ai.cost.parent_usd', this.parentCostUsd, attrs);
165
303
  }
166
304
  reset() {
167
305
  this.totalCostUsd = 0;
@@ -177,7 +315,12 @@ export class CostTracker {
177
315
  this.latestCostBreakdown = null;
178
316
  this.costByModel = new Map();
179
317
  this.costByDayUsd = new Map();
318
+ this.subagentCostByDayUsd = new Map();
180
319
  this.firstActivityMsByDay = new Map();
320
+ this.costByWorkflowRunId = new Map();
321
+ this.lastMutationMsByDay = new Map();
322
+ this.subagentCostUsd = 0;
323
+ this.parentCostUsd = 0;
181
324
  this.totalLinesChanged = 0;
182
325
  }
183
326
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cost-tracker.js","sourceRoot":"","sources":["../../src/metrics/cost-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA0B9C,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,MAAM,OAAO,WAAW;IACd,cAAc,CAAwB;IAEtC,YAAY,G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IAC7B,CAAC;CACF"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * WorkflowRunTracker — captures one record per detected workflow run.
3
+ *
4
+ * Two input sources (identifier-space discriminator):
5
+ * 1. run_source: 'agent_tool' — from PreToolUse/PostToolUse hook pairs on
6
+ * the 'Agent' tool. workflow_run_id = toolUseId (toolu_*).
7
+ * Entry points: recordAgentToolCall(record) or recordToolCall(record).
8
+ *
9
+ * 2. run_source: 'script' — from wf_*.json WorkflowWatcher events.
10
+ * workflow_run_id = wf_<hex>-<hex>.
11
+ * Entry point: recordScriptRun(event).
12
+ *
13
+ * For agent_tool runs, non-Agent tool calls that fall within a run's
14
+ * [started_at, started_at + duration_ms] window are attributed to it via
15
+ * tool_call_count and child_agent_count heuristics (best-effort, because hook
16
+ * payloads do not distinguish inner-subagent calls from parent calls).
17
+ */
18
+ import type { ToolCallRecord } from '../storage/types.js';
19
+ export type WorkflowRunStatus = 'completed' | 'errored' | 'in_progress';
20
+ /** Event shape produced by the WorkflowWatcher from wf_*.json files. */
21
+ export interface WorkflowRunEvent {
22
+ readonly mode: 'workflow_run';
23
+ readonly timestamp: number;
24
+ readonly workflowRunId: string;
25
+ readonly status: string;
26
+ readonly durationMs: number | null;
27
+ readonly totalTokens: number;
28
+ readonly agentCount: number;
29
+ readonly workflowName: string;
30
+ readonly phases: readonly string[];
31
+ readonly workflowProgress: ReadonlyArray<{
32
+ readonly type?: string;
33
+ readonly state?: string;
34
+ readonly agentId?: string;
35
+ }>;
36
+ readonly parentSessionId: string;
37
+ }
38
+ /**
39
+ * One row per completed workflow run.
40
+ *
41
+ * Fields marked "agent_tool only" are null when run_source === 'script'.
42
+ * Fields marked "script only" are null/0 when run_source === 'agent_tool'.
43
+ */
44
+ export interface WorkflowRunMetrics {
45
+ readonly workflow_run_id: string;
46
+ readonly run_source: 'agent_tool' | 'script';
47
+ readonly session_id: string;
48
+ readonly workflow_name: string;
49
+ readonly status: string;
50
+ readonly started_at: number;
51
+ readonly duration_ms: number;
52
+ readonly agent_count: number;
53
+ readonly total_tokens: number;
54
+ readonly declared_phases: number | null;
55
+ readonly observed_phases: number;
56
+ readonly incomplete: boolean;
57
+ readonly subagent_type: string | null;
58
+ readonly agent_name: string | null;
59
+ readonly agent_model: string | null;
60
+ readonly agent_description: string | null;
61
+ readonly run_in_background: boolean | null;
62
+ readonly exit_error: string | null;
63
+ readonly tool_call_count: number;
64
+ readonly child_agent_count: number;
65
+ }
66
+ export interface WorkflowRunTrackerOptions {
67
+ /** Max characters of agent_description retained on the metrics row. */
68
+ readonly descriptionMaxLength?: number;
69
+ /** Hard cap on simultaneously-tracked open runs to prevent unbounded growth. */
70
+ readonly maxOpenRuns?: number;
71
+ /** Hard cap on drainable completed runs awaiting consumption. */
72
+ readonly maxCompletedRuns?: number;
73
+ }
74
+ export declare class WorkflowRunTracker {
75
+ private readonly descriptionMaxLength;
76
+ private readonly maxOpenRuns;
77
+ private readonly maxCompletedRuns;
78
+ /** Open runs keyed by workflow_run_id. Insertion order = arrival order. */
79
+ private readonly openRuns;
80
+ /** Completed (drainable) runs in arrival order. */
81
+ private readonly completed;
82
+ constructor(options?: WorkflowRunTrackerOptions);
83
+ /**
84
+ * Record a ToolCallRecord from the hook event processor.
85
+ * Only Agent tool calls are recorded as workflow runs; other tool calls are
86
+ * attributed to the enclosing run as child calls.
87
+ *
88
+ * Kept for backward compatibility — delegates to recordAgentToolCall or
89
+ * the attribution heuristic as appropriate.
90
+ */
91
+ recordToolCall(record: ToolCallRecord): void;
92
+ /**
93
+ * Record a completed Agent tool call hook pair.
94
+ * Only processes records where toolName === 'Agent'.
95
+ */
96
+ recordAgentToolCall(record: ToolCallRecord): void;
97
+ /**
98
+ * Record a workflow run event from a wf_*.json WorkflowWatcher file.
99
+ *
100
+ * NOTE: currently unused in production wiring. `src/index.ts` feeds only
101
+ * `run_source='agent_tool'` runs into the tracker (via `onWorkflowAgent` →
102
+ * `recordToolCall`); script workflow runs are surfaced to the dashboard by
103
+ * WorkflowStore reading wf_*.json directly, not through this tracker. This
104
+ * method is retained (and covered by tests) for a future buffer path that
105
+ * routes WorkflowWatcher events through the processor — do not delete.
106
+ */
107
+ recordScriptRun(event: WorkflowRunEvent): void;
108
+ /**
109
+ * Returns and clears all completed (drainable) runs in arrival order.
110
+ * Open (in-progress) runs are not returned.
111
+ * Each run is returned exactly once.
112
+ */
113
+ drainCompleted(): WorkflowRunMetrics[];
114
+ /**
115
+ * Snapshot of all currently-tracked runs (open + completed-but-not-drained),
116
+ * primarily for tests and MCP tool inspection. Does not clear the buffer.
117
+ *
118
+ * A completed agent_tool run is kept in BOTH `openRuns` (for attribution
119
+ * lookups by late-arriving child tool calls) and `completed` (until
120
+ * drained) — dedupe by workflow_run_id so it isn't double-counted here.
121
+ */
122
+ getMetrics(): readonly WorkflowRunMetrics[];
123
+ /**
124
+ * Clears all state for a new session. The sessionId parameter is accepted
125
+ * for interface consistency with other trackers.
126
+ */
127
+ reset(_sessionId: string): void;
128
+ private attributeChildToolCall;
129
+ private incrementParentChildAgentCount;
130
+ /**
131
+ * Find the most-recently-started run in the same session whose
132
+ * [started_at, started_at + duration_ms] window encloses `timestamp`.
133
+ * Falls back to the most recent run that started before `timestamp` when
134
+ * no window encloses it (best-effort attribution).
135
+ */
136
+ private findEnclosingRun;
137
+ private pushCompleted;
138
+ private enforceOpenRunsCap;
139
+ }
140
+ //# sourceMappingURL=workflow-run-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-run-tracker.d.ts","sourceRoot":"","sources":["../../src/metrics/workflow-run-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQ1D,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,SAAS,GAAG,aAAa,CAAC;AAExE,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B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