@shadow-garden/bapbong-mcp 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.
@@ -0,0 +1,144 @@
1
+ /**
2
+ * The host-agnostic contract between MCP tools and a document host.
3
+ *
4
+ * Tools (packages/mcp/src/lib/server.ts) are written once against
5
+ * {@link DocumentSession}; hosts implement it for their document store:
6
+ * the desktop app binds the live editor (WebView), a server binds a headless
7
+ * ProseMirror EditorState ({@link ../headless-session}). Anything here must
8
+ * therefore stay meaningful for BOTH — no DOM, no desktop-isms.
9
+ *
10
+ * Anchoring semantics (the part language-agnostic hosts must reproduce):
11
+ * - Text anchors match within a single block (paragraph/cell paragraph);
12
+ * matches never span blocks or inline atoms (images/fields).
13
+ * - A mutation anchor must match exactly once, or the caller must pass
14
+ * `occurrence` (1-based, in document order). Ambiguity is an error that
15
+ * lists the occurrence count — the model retries with `occurrence`.
16
+ * - `docVersion` is an opaque string that changes whenever the document
17
+ * changes. Mutations MAY pass `expectedVersion`; a mismatch raises
18
+ * {@link VersionConflictError} and the caller re-reads before retrying.
19
+ */
20
+ /** An inline image (bitmap picture or drawn shape) inside a block —
21
+ * addressable as (block index, image index) by updateImage. */
22
+ export interface DocImage {
23
+ /** 0-based among the block's images, in block order. */
24
+ index: number;
25
+ alt: string;
26
+ /** CSS px. */
27
+ width: number;
28
+ height: number;
29
+ /** Clockwise degrees around the image center (0 when unrotated). */
30
+ rotation: number;
31
+ /** Drawn vector shape (rect/ellipse/…) vs a bitmap picture. */
32
+ kind: 'bitmap' | 'shape';
33
+ }
34
+ /** One addressable block in reading order (table-cell paragraphs included). */
35
+ export interface DocBlock {
36
+ /** Stable only within one docVersion — re-read after any change. */
37
+ index: number;
38
+ /** 'paragraph' | 'heading1'..'heading6' | future kinds. */
39
+ type: string;
40
+ text: string;
41
+ /** The block's inline images, when it has any. */
42
+ images?: DocImage[];
43
+ }
44
+ export interface DocSnapshot {
45
+ docVersion: string;
46
+ blocks: DocBlock[];
47
+ /** Host metadata (file name, dirty state…) — informational only. */
48
+ meta: {
49
+ name?: string;
50
+ dirty?: boolean;
51
+ };
52
+ }
53
+ export interface FindMatch {
54
+ blockIndex: number;
55
+ /** 1-based occurrence of the query across the whole document. */
56
+ occurrence: number;
57
+ /** The match with surrounding text — enough to disambiguate. */
58
+ context: string;
59
+ }
60
+ /** Where insertContent puts new blocks. */
61
+ export type InsertAnchor = {
62
+ position: 'before' | 'after';
63
+ text: string;
64
+ occurrence?: number;
65
+ } | {
66
+ position: 'document_end';
67
+ };
68
+ /** Character marks are tri-state: true = apply, false = remove, absent = keep. */
69
+ export interface Formatting {
70
+ bold?: boolean;
71
+ italic?: boolean;
72
+ underline?: boolean;
73
+ strike?: boolean;
74
+ /** Paragraph alignment of the block(s) containing the target text. */
75
+ align?: 'left' | 'center' | 'right' | 'justify';
76
+ }
77
+ /** Partial image update — absent fields keep their current value. */
78
+ export interface ImageChanges {
79
+ /** CSS px (rounded; must be positive). */
80
+ width?: number;
81
+ /** CSS px (rounded; must be positive). */
82
+ height?: number;
83
+ /** Clockwise degrees around the center — normalized to [0, 360). */
84
+ rotation?: number;
85
+ }
86
+ export interface MutationResult {
87
+ docVersion: string;
88
+ /** The affected range (PM positions) — informational; hosts use it to
89
+ * surface the edit (the desktop selects + scrolls to it). Positions are
90
+ * only stable within the returned docVersion. */
91
+ range?: {
92
+ from: number;
93
+ to: number;
94
+ };
95
+ }
96
+ export interface MutationOptions {
97
+ expectedVersion?: string;
98
+ /** 1-based pick when the anchor text matches more than once. */
99
+ occurrence?: number;
100
+ }
101
+ /** What a host supports; tools that need a missing capability aren't offered. */
102
+ export interface SessionCapabilities {
103
+ /** A live user selection exists (desktop editor) — enables get_selection. */
104
+ selection: boolean;
105
+ }
106
+ /** The port every document host implements. */
107
+ export interface DocumentSession {
108
+ readonly capabilities: SessionCapabilities;
109
+ snapshot(): Promise<DocSnapshot>;
110
+ find(query: string): Promise<FindMatch[]>;
111
+ replaceText(oldText: string, newText: string, opts?: MutationOptions): Promise<MutationResult>;
112
+ /** `content`: plain text; each line becomes one paragraph. */
113
+ insertContent(content: string, anchor: InsertAnchor, opts?: MutationOptions): Promise<MutationResult>;
114
+ applyFormatting(target: string, format: Formatting, opts?: MutationOptions): Promise<MutationResult>;
115
+ /** Resize/rotate one image, addressed as (blockIndex, imageIndex) from the
116
+ * latest snapshot. One transaction — a single undo step in a live editor. */
117
+ updateImage(blockIndex: number, imageIndex: number, changes: ImageChanges, opts?: MutationOptions): Promise<MutationResult>;
118
+ /** Only when capabilities.selection — the user's current selection. */
119
+ getSelection?(): Promise<{
120
+ text: string;
121
+ blockIndex: number;
122
+ } | null>;
123
+ /** Persist to the host's backing store (file, DB…). */
124
+ save(): Promise<void>;
125
+ close(): Promise<void>;
126
+ }
127
+ /** Resolves the session a tool call operates on. Desktop: `documentId`
128
+ * omitted = the open document. Server: id is required (tenancy). */
129
+ export interface SessionProvider {
130
+ get(documentId?: string): Promise<DocumentSession | null>;
131
+ }
132
+ /** The document changed since `expectedVersion` — re-read, then retry. */
133
+ export declare class VersionConflictError extends Error {
134
+ constructor(current: string, expected: string);
135
+ }
136
+ /** Anchor text not found, or ambiguous without `occurrence`. */
137
+ export declare class AnchorError extends Error {
138
+ constructor(message: string);
139
+ }
140
+ /** The host has no document to operate on (desktop: nothing open yet). */
141
+ export declare class NoDocumentError extends Error {
142
+ constructor(message?: string);
143
+ }
144
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/lib/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;gEACgE;AAChE,MAAM,WAAW,QAAQ;IACvB,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,oEAAoE;IAC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AI,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC5H,uEAAuE;IACvE,YAAY,CAAC,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IACtE,uDAAuD;IACvD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;qEACqE;AACrE,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;CAC3D;AAED,0EAA0E;AAC1E,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAO9C;AAED,gEAAgE;AAChE,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B;AAED,0EAA0E;AAC1E,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,SAAgE;CAIpF"}
@@ -0,0 +1,27 @@
1
+ import type { DocSnapshot, DocumentSession, FindMatch, Formatting, ImageChanges, InsertAnchor, MutationOptions, MutationResult, SessionCapabilities } from './contract.js';
2
+ export interface HeadlessSessionOptions {
3
+ /** Where save() writes the exported bytes (file, DB, test sink…). */
4
+ onSave?: (bytes: Uint8Array) => void | Promise<void>;
5
+ name?: string;
6
+ }
7
+ export declare class HeadlessSession implements DocumentSession {
8
+ private readonly raw;
9
+ private readonly opts;
10
+ readonly capabilities: SessionCapabilities;
11
+ private state;
12
+ private version;
13
+ private dirty;
14
+ private readonly inner;
15
+ private constructor();
16
+ static open(bytes: ArrayBuffer | Uint8Array, opts?: HeadlessSessionOptions): Promise<HeadlessSession>;
17
+ get docVersion(): string;
18
+ snapshot(): Promise<DocSnapshot>;
19
+ find(query: string): Promise<FindMatch[]>;
20
+ replaceText(oldText: string, newText: string, opts?: MutationOptions): Promise<MutationResult>;
21
+ insertContent(content: string, anchor: InsertAnchor, opts?: MutationOptions): Promise<MutationResult>;
22
+ applyFormatting(target: string, format: Formatting, opts?: MutationOptions): Promise<MutationResult>;
23
+ updateImage(blockIndex: number, imageIndex: number, changes: ImageChanges, opts?: MutationOptions): Promise<MutationResult>;
24
+ save(): Promise<void>;
25
+ close(): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=headless-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headless-session.d.ts","sourceRoot":"","sources":["../../src/lib/headless-session.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,SAAS,EACT,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,cAAc,EACd,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAGvB,MAAM,WAAW,sBAAsB;IACrC,qEAAqE;IACrE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,eAAgB,YAAW,eAAe;IAUnD,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAVvB,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAwB;IAElE,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IAErC,OAAO;WAyBM,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,EAAE,IAAI,GAAE,sBAA2B,GAAG,OAAO,CAAC,eAAe,CAAC;IAK/G,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC;IAGhC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAGzC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAG9F,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAGrG,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAGpG,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAG3H,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAGrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvB"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The shared DocumentSession semantics over ANY ProseMirror editor state —
3
+ * anchoring (atom-safe text hits → PM positions), unique-match rules,
4
+ * optimistic locking, mutations as transactions.
5
+ *
6
+ * Hosts provide the state and the dispatch:
7
+ * - HeadlessSession owns an EditorState (server / tests);
8
+ * - the desktop WebView wraps its live editor (state + dispatch) so AI edits
9
+ * ride the normal transaction pipeline (undo, autosave, journal).
10
+ * Keeping ALL semantics here means both hosts behave identically — tested
11
+ * once, headlessly.
12
+ */
13
+ import type { EditorState, Transaction } from 'prosemirror-state';
14
+ import { type DocSnapshot, type DocumentSession, type FindMatch, type Formatting, type ImageChanges, type InsertAnchor, type MutationOptions, type MutationResult, type SessionCapabilities } from './contract.js';
15
+ /** What a PmDocSession needs from its host. */
16
+ export interface PmSessionHost {
17
+ getState(): EditorState;
18
+ /** Dispatch a transaction (live editor) / apply it (headless state). */
19
+ apply(tr: Transaction): void;
20
+ /** Opaque, changes on every doc change — INCLUDING user edits. */
21
+ getVersion(): string;
22
+ meta(): {
23
+ name?: string;
24
+ dirty?: boolean;
25
+ };
26
+ save(): Promise<void>;
27
+ /** Current user selection, when the host has one (desktop editor). */
28
+ selection?(): {
29
+ from: number;
30
+ to: number;
31
+ } | null;
32
+ }
33
+ export declare class PmDocSession implements DocumentSession {
34
+ private readonly host;
35
+ readonly capabilities: SessionCapabilities;
36
+ constructor(host: PmSessionHost);
37
+ snapshot(): Promise<DocSnapshot>;
38
+ find(query: string): Promise<FindMatch[]>;
39
+ getSelection(): Promise<{
40
+ text: string;
41
+ blockIndex: number;
42
+ } | null>;
43
+ replaceText(oldText: string, newText: string, opts?: MutationOptions): Promise<MutationResult>;
44
+ insertContent(content: string, anchor: InsertAnchor, opts?: MutationOptions): Promise<MutationResult>;
45
+ applyFormatting(target: string, format: Formatting, opts?: MutationOptions): Promise<MutationResult>;
46
+ updateImage(blockIndex: number, imageIndex: number, changes: ImageChanges, opts?: MutationOptions): Promise<MutationResult>;
47
+ save(): Promise<void>;
48
+ close(): Promise<void>;
49
+ private checkVersion;
50
+ /** All textblocks (paragraphs, incl. inside table cells) in reading order. */
51
+ private textblocks;
52
+ /** Every occurrence of `query`, atom-safe (matches never span images/fields
53
+ * or block boundaries), in document order with absolute PM positions. */
54
+ private hits;
55
+ private uniqueHit;
56
+ }
57
+ //# sourceMappingURL=pm-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pm-session.d.ts","sourceRoot":"","sources":["../../src/lib/pm-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAElE,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB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O,CAAC,cAAc,CAAC;IAyBxG,WAAW,CACf,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,YAAY,EACrB,IAAI,GAAE,eAAoB,GACzB,OAAO,CAAC,cAAc,CAAC;IA+BpB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B,OAAO,CAAC,YAAY;IAOpB,8EAA8E;IAC9E,OAAO,CAAC,UAAU;IAYlB;8EAC0E;IAC1E,OAAO,CAAC,IAAI;IAsCZ,OAAO,CAAC,SAAS;CAuBlB"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The MCP server over a {@link SessionProvider} — the host-agnostic half of
3
+ * M15. Hosts supply sessions (desktop: the live editor; server: headless
4
+ * EditorStates) and a transport (loopback Bun.serve, TLS gateway, stdio…);
5
+ * everything the agent sees — tool names, schemas, anchoring/versioning
6
+ * semantics, error texts that teach the retry — is defined once, here.
7
+ */
8
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
+ import { type SessionProvider } from './contract.js';
10
+ export interface CreateMcpServerOptions {
11
+ name?: string;
12
+ version?: string;
13
+ /** Offer get_selection (hosts with a live user selection — the desktop). */
14
+ selection?: boolean;
15
+ }
16
+ export declare function createMcpServer(provider: SessionProvider, opts?: CreateMcpServerOptions): McpServer;
17
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/lib/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAA4E,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAE/H,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA4BD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,GAAE,sBAA2B,GAAG,SAAS,CAsMvG"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The wire protocol between a DocumentSession host process and the process
3
+ * where the document actually lives, when they are not the same — on desktop,
4
+ * the Bun process hosts the MCP server while the document lives in the
5
+ * WebView editor.
6
+ *
7
+ * Bun side: {@link RemoteSession} — a DocumentSession whose every method
8
+ * serializes into one {@link SessionOpRequest} (pushed over the app's SSE
9
+ * command channel) and awaits the matching {@link SessionOpResponse}.
10
+ * WebView side: {@link executeOp} — runs the request against the local
11
+ * session and produces the response, round-tripping contract errors by name
12
+ * so optimistic-locking / anchoring semantics survive the process hop.
13
+ */
14
+ import { type DocumentSession, type Formatting, type ImageChanges, type InsertAnchor, type MutationOptions, type SessionCapabilities } from './contract.js';
15
+ export type SessionOpName = 'snapshot' | 'find' | 'replaceText' | 'insertContent' | 'applyFormatting' | 'updateImage' | 'getSelection' | 'save' | 'consent';
16
+ export interface SessionOpRequest {
17
+ id: string;
18
+ op: SessionOpName;
19
+ args: unknown[];
20
+ }
21
+ export type SessionOpResponse = {
22
+ id: string;
23
+ ok: true;
24
+ value: unknown;
25
+ } | {
26
+ id: string;
27
+ ok: false;
28
+ error: {
29
+ name: string;
30
+ message: string;
31
+ };
32
+ };
33
+ /** Run one wire op against a local session ('consent' is host-level and is
34
+ * handled by the caller before this). Never throws — errors are encoded. */
35
+ export declare function executeOp(session: DocumentSession | null, request: SessionOpRequest): Promise<SessionOpResponse>;
36
+ /** Rebuild a contract error from its wire form so upstream catch-by-class
37
+ * (createMcpServer's teaching errors) keeps working across the hop. */
38
+ export declare function reviveError(error: {
39
+ name: string;
40
+ message: string;
41
+ }): Error;
42
+ /** DocumentSession proxy: forwards every call over `send` (the transport is
43
+ * the host's business — desktop uses its SSE command channel + POST-back). */
44
+ export declare class RemoteSession implements DocumentSession {
45
+ private readonly send;
46
+ readonly capabilities: SessionCapabilities;
47
+ constructor(send: (op: SessionOpName, args: unknown[]) => Promise<unknown>, capabilities: SessionCapabilities);
48
+ private call;
49
+ snapshot(): Promise<import("./contract.js").DocSnapshot>;
50
+ find(query: string): Promise<import("./contract.js").FindMatch[]>;
51
+ replaceText(oldText: string, newText: string, opts?: MutationOptions): Promise<import("./contract.js").MutationResult>;
52
+ insertContent(content: string, anchor: InsertAnchor, opts?: MutationOptions): Promise<import("./contract.js").MutationResult>;
53
+ applyFormatting(target: string, format: Formatting, opts?: MutationOptions): Promise<import("./contract.js").MutationResult>;
54
+ updateImage(blockIndex: number, imageIndex: number, changes: ImageChanges, opts?: MutationOptions): Promise<import("./contract.js").MutationResult>;
55
+ getSelection(): Promise<{
56
+ text: string;
57
+ blockIndex: number;
58
+ } | null>;
59
+ save(): Promise<void>;
60
+ close(): Promise<void>;
61
+ }
62
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../src/lib/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACzB,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,aAAa,GACrB,UAAU,GACV,MAAM,GACN,aAAa,GACb,eAAe,GACf,iBAAiB,GACjB,aAAa,GACb,cAAc,GACd,MAAM,GACN,SAAS,CAAC;AAEd,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,aAAa,CAAC;IAClB,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AAED,MAAM,MAAM,iBAAiB,GACzB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACxC;IAA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