praetom 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +82 -0
  2. package/dist/_esm-loader.d.ts +49 -0
  3. package/dist/_esm-loader.d.ts.map +1 -0
  4. package/dist/_esm-loader.js +131 -0
  5. package/dist/_esm-loader.js.map +1 -0
  6. package/dist/_internal.d.ts +63 -0
  7. package/dist/_internal.d.ts.map +1 -0
  8. package/dist/_internal.js +357 -0
  9. package/dist/_internal.js.map +1 -0
  10. package/dist/browser.d.ts +90 -0
  11. package/dist/browser.d.ts.map +1 -0
  12. package/dist/browser.js +357 -0
  13. package/dist/browser.js.map +1 -0
  14. package/dist/cli/cli.d.ts +3 -0
  15. package/dist/cli/cli.d.ts.map +1 -0
  16. package/dist/cli/cli.js +97 -0
  17. package/dist/cli/cli.js.map +1 -0
  18. package/dist/cli/commands/discover.d.ts +3 -0
  19. package/dist/cli/commands/discover.d.ts.map +1 -0
  20. package/dist/cli/commands/discover.js +15 -0
  21. package/dist/cli/commands/discover.js.map +1 -0
  22. package/dist/cli/commands/features.d.ts +5 -0
  23. package/dist/cli/commands/features.d.ts.map +1 -0
  24. package/dist/cli/commands/features.js +83 -0
  25. package/dist/cli/commands/features.js.map +1 -0
  26. package/dist/cli/commands/init.d.ts +3 -0
  27. package/dist/cli/commands/init.d.ts.map +1 -0
  28. package/dist/cli/commands/init.js +52 -0
  29. package/dist/cli/commands/init.js.map +1 -0
  30. package/dist/cli/commands/login.d.ts +20 -0
  31. package/dist/cli/commands/login.d.ts.map +1 -0
  32. package/dist/cli/commands/login.js +138 -0
  33. package/dist/cli/commands/login.js.map +1 -0
  34. package/dist/cli/commands/logout.d.ts +3 -0
  35. package/dist/cli/commands/logout.d.ts.map +1 -0
  36. package/dist/cli/commands/logout.js +15 -0
  37. package/dist/cli/commands/logout.js.map +1 -0
  38. package/dist/cli/commands/rotate.d.ts +3 -0
  39. package/dist/cli/commands/rotate.d.ts.map +1 -0
  40. package/dist/cli/commands/rotate.js +33 -0
  41. package/dist/cli/commands/rotate.js.map +1 -0
  42. package/dist/cli/commands/status.d.ts +3 -0
  43. package/dist/cli/commands/status.d.ts.map +1 -0
  44. package/dist/cli/commands/status.js +54 -0
  45. package/dist/cli/commands/status.js.map +1 -0
  46. package/dist/cli/commands/uninstall.d.ts +3 -0
  47. package/dist/cli/commands/uninstall.d.ts.map +1 -0
  48. package/dist/cli/commands/uninstall.js +63 -0
  49. package/dist/cli/commands/uninstall.js.map +1 -0
  50. package/dist/cli/commands/usage.d.ts +3 -0
  51. package/dist/cli/commands/usage.d.ts.map +1 -0
  52. package/dist/cli/commands/usage.js +19 -0
  53. package/dist/cli/commands/usage.js.map +1 -0
  54. package/dist/cli/commands/whoami.d.ts +3 -0
  55. package/dist/cli/commands/whoami.d.ts.map +1 -0
  56. package/dist/cli/commands/whoami.js +37 -0
  57. package/dist/cli/commands/whoami.js.map +1 -0
  58. package/dist/cli/util/agent-env.d.ts +13 -0
  59. package/dist/cli/util/agent-env.d.ts.map +1 -0
  60. package/dist/cli/util/agent-env.js +28 -0
  61. package/dist/cli/util/agent-env.js.map +1 -0
  62. package/dist/cli/util/api.d.ts +36 -0
  63. package/dist/cli/util/api.d.ts.map +1 -0
  64. package/dist/cli/util/api.js +84 -0
  65. package/dist/cli/util/api.js.map +1 -0
  66. package/dist/cli/util/auth-file.d.ts +25 -0
  67. package/dist/cli/util/auth-file.d.ts.map +1 -0
  68. package/dist/cli/util/auth-file.js +74 -0
  69. package/dist/cli/util/auth-file.js.map +1 -0
  70. package/dist/cli/util/git.d.ts +28 -0
  71. package/dist/cli/util/git.d.ts.map +1 -0
  72. package/dist/cli/util/git.js +103 -0
  73. package/dist/cli/util/git.js.map +1 -0
  74. package/dist/cli/util/run.d.ts +26 -0
  75. package/dist/cli/util/run.d.ts.map +1 -0
  76. package/dist/cli/util/run.js +31 -0
  77. package/dist/cli/util/run.js.map +1 -0
  78. package/dist/edge.d.ts +34 -0
  79. package/dist/edge.d.ts.map +1 -0
  80. package/dist/edge.js +127 -0
  81. package/dist/edge.js.map +1 -0
  82. package/dist/server.d.ts +69 -0
  83. package/dist/server.d.ts.map +1 -0
  84. package/dist/server.js +193 -0
  85. package/dist/server.js.map +1 -0
  86. package/dist/vite/index.d.ts +48 -0
  87. package/dist/vite/index.d.ts.map +1 -0
  88. package/dist/vite/index.js +138 -0
  89. package/dist/vite/index.js.map +1 -0
  90. package/dist/webpack/index.d.ts +64 -0
  91. package/dist/webpack/index.d.ts.map +1 -0
  92. package/dist/webpack/index.js +106 -0
  93. package/dist/webpack/index.js.map +1 -0
  94. package/dist/webpack/loader.d.ts +27 -0
  95. package/dist/webpack/loader.d.ts.map +1 -0
  96. package/dist/webpack/loader.js +54 -0
  97. package/dist/webpack/loader.js.map +1 -0
  98. package/dist/webpack/shared.d.ts +25 -0
  99. package/dist/webpack/shared.d.ts.map +1 -0
  100. package/dist/webpack/shared.js +63 -0
  101. package/dist/webpack/shared.js.map +1 -0
  102. package/package.json +79 -0
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # praetom
2
+
3
+ Production intelligence for AI-generated code. One `register()` call wires up feature-shaped tracing across your server, browser, and edge runtimes — praetom's backend decides what gets instrumented; your source stays clean.
4
+
5
+ → [praetom.com](https://praetom.com) for the dashboard, docs, and account.
6
+
7
+ ---
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install praetom
13
+ # or
14
+ pnpm add praetom
15
+ ```
16
+
17
+ ---
18
+
19
+ ## Quickstart
20
+
21
+ **Server** (Next.js `instrumentation.ts`, Express `app.ts`, anywhere that runs once at process start):
22
+
23
+ ```ts
24
+ import { register } from "praetom";
25
+
26
+ await register();
27
+ ```
28
+
29
+ Identity is auto-detected from your deploy provider (Vercel, Railway, Render, Fly, GitHub Actions). To override, set `PRAETOM_INGEST_ID` or pass it explicitly:
30
+
31
+ ```ts
32
+ await register({ ingestId: process.env.PRAETOM_INGEST_ID });
33
+ ```
34
+
35
+ **Browser** (root layout, `_app.tsx`, SPA entry):
36
+
37
+ ```ts
38
+ import { register } from "praetom";
39
+
40
+ register({ ingestId: "praetom_..." });
41
+ ```
42
+
43
+ The ingest ID is DSN-style — public-safe to bake into your client bundle.
44
+
45
+ **Edge** (Vercel Edge, Cloudflare Workers): same import, same `register()`. Conditional exports route to the right implementation.
46
+
47
+ ---
48
+
49
+ ## What it does
50
+
51
+ - **One trace per user action.** A button click in the browser, the resulting API call, and downstream database writes all share one `trace_id` — visible as a single waterfall in your praetom dashboard.
52
+ - **Features, not services.** Spans are tagged with the feature they belong to (`checkout`, `onboarding`, `search`). Ask "is checkout healthy?" instead of grepping a service-shaped span table.
53
+ - **No source-level coupling.** Feature names, paths, and entry points live in praetom's backend. Your code calls `register()` and `emit()`; everything else is decided server-side and pushed to the SDK at runtime.
54
+
55
+ ## Emitting events
56
+
57
+ `register()` covers auto-wrapped feature spans. For point-in-time events inside a feature, drop an `emit()`:
58
+
59
+ ```ts
60
+ import { emit } from "praetom";
61
+
62
+ emit("checkout:stripe-charged", { amount });
63
+ emit("checkout:order-created", { orderId });
64
+ ```
65
+
66
+ Events attach to the active feature span. Failed spans capture errors automatically — no try/catch needed.
67
+
68
+ ## Configuration
69
+
70
+ | Env var | Purpose |
71
+ |---|---|
72
+ | `PRAETOM_INGEST_ID` | Override auto-detected workspace identity (server only). |
73
+ | `PRAETOM_REPO` | Override auto-detected repo when deploy-provider env vars are missing. |
74
+ | `PRAETOM_OTLP_ENDPOINT` | Override the default span ingestion endpoint. Defaults to `https://praetom.com`. |
75
+
76
+ ## Get a praetom workspace
77
+
78
+ You'll need one before this package does anything useful: [praetom.com](https://praetom.com) → sign in with email → connect your GitHub repo → praetom proposes feature contracts from your code → save the ones that ring true → `register()` and ship.
79
+
80
+ ## License
81
+
82
+ UNLICENSED — see [praetom.com](https://praetom.com) for terms.
@@ -0,0 +1,49 @@
1
+ /**
2
+ * ESM loader hook for the praetom runtime SDK. Companion to the CJS
3
+ * `Module._load` hook in `server.ts` — covers ESM-native servers
4
+ * (Express/Fastify/Hono/Nest with `.mjs`/`.ts`), Bun, and pre-bundle
5
+ * dev mode for several frameworks.
6
+ *
7
+ * Registered via `module.register('./dist/_esm-loader.js', import.meta.url,
8
+ * { data: { featureMap: [...] } })` from server.ts's installEsmLoader().
9
+ *
10
+ * Strategy: regex-level source rewriting on files matching a feature
11
+ * path. Detects common named-function export shapes, renames the
12
+ * underlying function, and appends a wrapped re-export that calls
13
+ * `__praetomWrapEntryPoint`. Falls back to no-op (with a `[praetom]`
14
+ * warning) for shapes that don't match.
15
+ *
16
+ * Handles:
17
+ * export async function NAME(...)
18
+ * export function NAME(...)
19
+ * export const NAME = async (...)
20
+ * export const NAME = (...)
21
+ *
22
+ * Does NOT handle (yet):
23
+ * export default ...
24
+ * export { NAME }
25
+ * export { NAME as default }
26
+ * class exports
27
+ *
28
+ * The bundler plugins (Vite/Webpack) cover the cases this loader skips
29
+ * — bundled apps go through the plugin, not this loader.
30
+ */
31
+ interface FeatureMapEntry {
32
+ slug: string;
33
+ entrySymbol?: string;
34
+ }
35
+ interface InitData {
36
+ featureMap: Array<[string, FeatureMapEntry]>;
37
+ }
38
+ interface LoadResult {
39
+ format: string;
40
+ source?: string | ArrayBuffer | ArrayBufferView;
41
+ shortCircuit?: boolean;
42
+ }
43
+ type NextLoad = (url: string, context: unknown) => Promise<LoadResult>;
44
+ export declare function initialize(data: InitData): void;
45
+ export declare function load(url: string, context: {
46
+ format?: string;
47
+ } & Record<string, unknown>, nextLoad: NextLoad): Promise<LoadResult>;
48
+ export {};
49
+ //# sourceMappingURL=_esm-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_esm-loader.d.ts","sourceRoot":"","sources":["../src/_esm-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,QAAQ;IAChB,UAAU,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CAC9C;AAED,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,eAAe,CAAC;IAChD,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,KAAK,QAAQ,GAAG,CACd,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,UAAU,CAAC,CAAC;AAKzB,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAG/C;AAED,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtD,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,UAAU,CAAC,CAoCrB"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * ESM loader hook for the praetom runtime SDK. Companion to the CJS
3
+ * `Module._load` hook in `server.ts` — covers ESM-native servers
4
+ * (Express/Fastify/Hono/Nest with `.mjs`/`.ts`), Bun, and pre-bundle
5
+ * dev mode for several frameworks.
6
+ *
7
+ * Registered via `module.register('./dist/_esm-loader.js', import.meta.url,
8
+ * { data: { featureMap: [...] } })` from server.ts's installEsmLoader().
9
+ *
10
+ * Strategy: regex-level source rewriting on files matching a feature
11
+ * path. Detects common named-function export shapes, renames the
12
+ * underlying function, and appends a wrapped re-export that calls
13
+ * `__praetomWrapEntryPoint`. Falls back to no-op (with a `[praetom]`
14
+ * warning) for shapes that don't match.
15
+ *
16
+ * Handles:
17
+ * export async function NAME(...)
18
+ * export function NAME(...)
19
+ * export const NAME = async (...)
20
+ * export const NAME = (...)
21
+ *
22
+ * Does NOT handle (yet):
23
+ * export default ...
24
+ * export { NAME }
25
+ * export { NAME as default }
26
+ * class exports
27
+ *
28
+ * The bundler plugins (Vite/Webpack) cover the cases this loader skips
29
+ * — bundled apps go through the plugin, not this loader.
30
+ */
31
+ let _featureMap = new Map();
32
+ let _initialized = false;
33
+ export function initialize(data) {
34
+ _featureMap = new Map(data.featureMap);
35
+ _initialized = true;
36
+ }
37
+ export async function load(url, context, nextLoad) {
38
+ const result = await nextLoad(url, context);
39
+ if (!_initialized)
40
+ return result;
41
+ if (result.format !== "module")
42
+ return result;
43
+ if (!url.startsWith("file://"))
44
+ return result;
45
+ let filePath;
46
+ try {
47
+ filePath = decodeURIComponent(new URL(url).pathname);
48
+ }
49
+ catch {
50
+ return result;
51
+ }
52
+ const match = matchFeature(filePath);
53
+ if (!match)
54
+ return result;
55
+ const source = typeof result.source === "string"
56
+ ? result.source
57
+ : result.source
58
+ ? new TextDecoder().decode(result.source instanceof ArrayBuffer
59
+ ? new Uint8Array(result.source)
60
+ : result.source)
61
+ : "";
62
+ const wrapped = wrapModuleSource(source, match.slug, match.entrySymbol);
63
+ if (!wrapped) {
64
+ // eslint-disable-next-line no-console
65
+ console.warn(`[praetom] could not wrap ${filePath} (export shape not recognized; falling back to no-op)`);
66
+ return result;
67
+ }
68
+ return { ...result, source: wrapped };
69
+ }
70
+ function matchFeature(absPath) {
71
+ const normalized = absPath.replace(/\\/g, "/");
72
+ for (const [featurePath, info] of _featureMap) {
73
+ if (normalized === featurePath ||
74
+ normalized.endsWith(`/${featurePath}`)) {
75
+ return info;
76
+ }
77
+ }
78
+ return null;
79
+ }
80
+ const PRAETOM_IMPORT_MARKER = "__praetom_wrap_import__";
81
+ const HTTP_METHODS = new Set([
82
+ "GET",
83
+ "POST",
84
+ "PUT",
85
+ "PATCH",
86
+ "DELETE",
87
+ "OPTIONS",
88
+ "HEAD",
89
+ ]);
90
+ function wrapModuleSource(source, slug, entrySymbol) {
91
+ if (source.includes(PRAETOM_IMPORT_MARKER)) {
92
+ // Already wrapped (shouldn't happen with nextLoad short-circuit but
93
+ // belt + suspenders).
94
+ return null;
95
+ }
96
+ // Pattern A: `export (async )?function NAME(` — rewrite the export
97
+ // keyword off, rename the function to __praetom_orig_NAME, and
98
+ // append an `export const NAME = __wrap(...)`.
99
+ // Pattern B: `export const NAME = ` (function value) — same shape.
100
+ const targets = new Set();
101
+ let rewritten = source.replace(/^export\s+(async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(/gm, (_match, asyncKw, name) => {
102
+ targets.add(name);
103
+ return `${asyncKw ?? ""}function __praetom_orig_${name}(`;
104
+ });
105
+ rewritten = rewritten.replace(/^export\s+const\s+([A-Za-z_$][\w$]*)\s*=/gm, (_match, name) => {
106
+ // Only wrap if the entry name is the requested entrySymbol (when
107
+ // specified) or an HTTP method (Next.js App Router convention).
108
+ // Otherwise leave alone — `export const foo = "bar"` shouldn't
109
+ // become `wrapEntryPoint(..., "bar")`.
110
+ if (!shouldWrap(name, entrySymbol))
111
+ return `export const ${name} =`;
112
+ targets.add(name);
113
+ return `const __praetom_orig_${name} =`;
114
+ });
115
+ if (targets.size === 0)
116
+ return null;
117
+ const filtered = [...targets].filter((n) => shouldWrap(n, entrySymbol));
118
+ if (filtered.length === 0)
119
+ return null;
120
+ const importLine = `import { __praetomWrapEntryPoint as ${PRAETOM_IMPORT_MARKER} } from "praetom";\n`;
121
+ const wraps = filtered
122
+ .map((name) => `export const ${name} = ${PRAETOM_IMPORT_MARKER}(${JSON.stringify(slug)}, ${JSON.stringify(name)}, __praetom_orig_${name});`)
123
+ .join("\n");
124
+ return `${importLine}${rewritten}\n${wraps}\n`;
125
+ }
126
+ function shouldWrap(name, entrySymbol) {
127
+ if (entrySymbol)
128
+ return name === entrySymbol;
129
+ return HTTP_METHODS.has(name) || name === "handler" || name === "default";
130
+ }
131
+ //# sourceMappingURL=_esm-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_esm-loader.js","sourceRoot":"","sources":["../src/_esm-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;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AS,UAAU,CAAC,IAAY,EAAE,WAA+B;IAC/D,IAAI,WAAW;QAAE,OAAO,IAAI,KAAK,WAAW,CAAC;IAC7C,OAAO,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Internal runtime primitives. NOT part of the public package surface —
3
+ * customers should import from `praetom` or
4
+ * `praetom`, which together expose only `register` and
5
+ * `emit`.
6
+ *
7
+ * Everything else (`feature`, `featureSync`, `continueTrace`, `init`,
8
+ * `flush`, `shutdown`, the buffer, the fetch patch) lives here and is
9
+ * called by `register()` + the autowrap hook + the bundler plugin's
10
+ * generated code. We don't ship a manual-wrap API.
11
+ */
12
+ export interface FeatureContext {
13
+ traceId: string;
14
+ spanId: string;
15
+ slug: string;
16
+ }
17
+ export declare function init(opts: {
18
+ token: string;
19
+ endpoint?: string;
20
+ serviceName?: string;
21
+ }): void;
22
+ /**
23
+ * Wrap an async function as a feature entry point. Called by the
24
+ * autowrap hook in `server.ts` and the bundler plugin's generated
25
+ * browser-side code — NOT a customer-facing API.
26
+ */
27
+ export declare function feature<T>(slug: string, fn: () => Promise<T>, attributes?: Record<string, string>): Promise<T>;
28
+ export declare function featureSync<T>(slug: string, fn: () => T): T;
29
+ /**
30
+ * Continue a trace from an incoming HTTP request. Called by the
31
+ * autowrap hook when wrapping HTTP handlers — reads `traceparent` and
32
+ * stitches the local span under the upstream span.
33
+ */
34
+ export declare function continueTrace<T>(headers: Headers | Record<string, string | undefined> | {
35
+ get(key: string): string | null;
36
+ }, slug: string, fn: () => Promise<T>, attributes?: Record<string, string>): Promise<T>;
37
+ export declare function currentFeatureContext(): FeatureContext | undefined;
38
+ /**
39
+ * Internal wrap-as-entry-point helper. Shared by the CJS Module._load
40
+ * hook, the ESM loader hook, and the bundler plugin's injected code.
41
+ *
42
+ * If `entryName` is an HTTP method (`GET`, `POST`, ...), the wrap reads
43
+ * `traceparent` from the first arg's `headers` to continue an upstream
44
+ * trace. Otherwise it opens a fresh feature span.
45
+ *
46
+ * NOT a public customer API — exported under `__praetom*` only so the
47
+ * bundler-plugin-injected code can call it; customers should never
48
+ * import it directly.
49
+ */
50
+ export declare function wrapEntryPoint(slug: string, entryName: string, original: (...args: unknown[]) => unknown): (...args: unknown[]) => unknown;
51
+ /**
52
+ * Public primitive — fire a point-in-time event tagged with the current
53
+ * feature context if one exists. Use inside business logic to mark
54
+ * latency splits, business events, or error context that the entry-
55
+ * point wrap doesn't capture by itself.
56
+ *
57
+ * Outside a feature context the span still emits, but with no parent —
58
+ * use sparingly for top-level signals.
59
+ */
60
+ export declare function emit(eventName: string, payload?: Record<string, unknown>): void;
61
+ export declare function flush(): Promise<void>;
62
+ export declare function shutdown(): Promise<void>;
63
+ //# sourceMappingURL=_internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_internal.d.ts","sourceRoot":"","sources":["../src/_internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA6BH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AA4BD,wBAAgB,IAAI,CAAC,IAAI,EAAE;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,IAAI,CAOP;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,CAAC,CAAC,CAOZ;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAA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