@ignite-ember/extension-bridge 0.0.0-stage → 0.2.1
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +364 -2
- package/dist/bridge.d.ts +37 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +96 -0
- package/dist/bridge.js.map +1 -0
- package/dist/channel.d.ts +26 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +36 -0
- package/dist/channel.js.map +1 -0
- package/dist/contract.d.ts +137 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +9 -0
- package/dist/contract.js.map +1 -0
- package/dist/correlator.d.ts +37 -0
- package/dist/correlator.d.ts.map +1 -0
- package/dist/correlator.js +75 -0
- package/dist/correlator.js.map +1 -0
- package/dist/guestBridge.d.ts +63 -0
- package/dist/guestBridge.d.ts.map +1 -0
- package/dist/guestBridge.js +156 -0
- package/dist/guestBridge.js.map +1 -0
- package/dist/hostModel.d.ts +159 -0
- package/dist/hostModel.d.ts.map +1 -0
- package/dist/hostModel.generated.d.ts +2373 -0
- package/dist/hostModel.generated.d.ts.map +1 -0
- package/dist/hostModel.generated.js +1746 -0
- package/dist/hostModel.generated.js.map +1 -0
- package/dist/hostModel.js +172 -0
- package/dist/hostModel.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +348 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +145 -0
- package/dist/protocol.js.map +1 -0
- package/dist/service.d.ts +168 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +196 -0
- package/dist/service.js.map +1 -0
- package/dist/signals.d.ts +21 -0
- package/dist/signals.d.ts.map +1 -0
- package/dist/signals.js +52 -0
- package/dist/signals.js.map +1 -0
- package/dist/tokens.d.ts +101 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +164 -0
- package/dist/tokens.js.map +1 -0
- package/dist/watchers.d.ts +12 -0
- package/dist/watchers.d.ts.map +1 -0
- package/dist/watchers.js +18 -0
- package/dist/watchers.js.map +1 -0
- package/package.json +53 -4
- package/src/bridge.ts +116 -0
- package/src/channel.ts +48 -0
- package/src/contract.ts +157 -0
- package/src/correlator.ts +88 -0
- package/src/guestBridge.ts +261 -0
- package/src/hostModel.generated.ts +3155 -0
- package/src/hostModel.ts +213 -0
- package/src/index.ts +11 -0
- package/src/protocol.ts +485 -0
- package/src/service.ts +278 -0
- package/src/signals.ts +65 -0
- package/src/tokens.ts +171 -0
- package/src/watchers.ts +18 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge an extension's page holds once the host has said hello.
|
|
3
|
+
*
|
|
4
|
+
* It owns everything the page learned from the host — params, theme,
|
|
5
|
+
* tokens — and the three kinds of request it can be waiting on, each
|
|
6
|
+
* with its own {@link Correlator}. Messages from the host are routed by
|
|
7
|
+
* kind through one table, {@link GuestBridge.handlers}.
|
|
8
|
+
*/
|
|
9
|
+
import { Correlator } from "./correlator.js";
|
|
10
|
+
import { HostError } from "./hostModel.js";
|
|
11
|
+
import { Host } from "./hostModel.generated.js";
|
|
12
|
+
import { ServiceError, ServiceLink } from "./service.js";
|
|
13
|
+
import { SignalSubscriptions } from "./signals.js";
|
|
14
|
+
import { applyThemeTokens } from "./tokens.js";
|
|
15
|
+
import { Watchers } from "./watchers.js";
|
|
16
|
+
/** How long a request waits before giving up. The host has its own. */
|
|
17
|
+
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
18
|
+
/** Members whose answer is the person's, so no timeout applies to them. */
|
|
19
|
+
const WAITS_ON_THE_PERSON = new Set(["ui.show_dialog"]);
|
|
20
|
+
export class GuestBridge {
|
|
21
|
+
channel;
|
|
22
|
+
extensionId;
|
|
23
|
+
settings;
|
|
24
|
+
host;
|
|
25
|
+
service;
|
|
26
|
+
currentParams;
|
|
27
|
+
currentTheme;
|
|
28
|
+
currentTokens;
|
|
29
|
+
themeWatchers = new Watchers();
|
|
30
|
+
paramWatchers = new Watchers();
|
|
31
|
+
/** One numbering for every request, whatever its kind. */
|
|
32
|
+
requestCount = 0;
|
|
33
|
+
nextRequest = () => ++this.requestCount;
|
|
34
|
+
calls = new Correlator("", this.nextRequest);
|
|
35
|
+
hostRequests = new Correlator("h", this.nextRequest);
|
|
36
|
+
tokenRequests = new Correlator("s", this.nextRequest);
|
|
37
|
+
signals = new SignalSubscriptions((op, signal) => this.hostRequest({ op, path: "", signals: [signal] }));
|
|
38
|
+
handlers = {
|
|
39
|
+
// Connecting already consumed the greeting; a repeat changes nothing.
|
|
40
|
+
hello: () => { },
|
|
41
|
+
theme: (message) => this.applyTheme(message),
|
|
42
|
+
params: (message) => this.applyParams(message),
|
|
43
|
+
signal: (message) => this.signals.deliver(message),
|
|
44
|
+
"host-reply": (message) => this.settleHostRequest(message),
|
|
45
|
+
"service-token-reply": (message) => this.settleTokenRequest(message),
|
|
46
|
+
result: (message) => this.settleCall(message),
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* `params` and `settings` are the extension's to name (`P`, `S`): the
|
|
50
|
+
* host sends what the extension's own links and manifest put there.
|
|
51
|
+
*/
|
|
52
|
+
constructor(channel, hello) {
|
|
53
|
+
this.channel = channel;
|
|
54
|
+
this.extensionId = hello.extensionId;
|
|
55
|
+
this.settings = (hello.settings ?? {});
|
|
56
|
+
this.currentParams = hello.params;
|
|
57
|
+
this.currentTheme = hello.theme;
|
|
58
|
+
this.currentTokens = hello.tokens;
|
|
59
|
+
const link = {
|
|
60
|
+
request: (op, path, options) => this.hostRequest({
|
|
61
|
+
op,
|
|
62
|
+
path,
|
|
63
|
+
window: options.window ?? null,
|
|
64
|
+
...(options.session ? { session: options.session } : {}),
|
|
65
|
+
...(options.params !== undefined ? { params: options.params } : {}),
|
|
66
|
+
...(op === "set" ? { value: options.value } : {}),
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
this.host = new Host(link);
|
|
70
|
+
this.service = new ServiceLink(hello.serviceUrl ?? null, () => this.askForToken());
|
|
71
|
+
// Applied before the page renders anything, so an extension never
|
|
72
|
+
// paints once in the fallback palette and again in the real one.
|
|
73
|
+
applyThemeTokens(this.currentTokens, document.documentElement);
|
|
74
|
+
}
|
|
75
|
+
get params() {
|
|
76
|
+
return this.currentParams;
|
|
77
|
+
}
|
|
78
|
+
get theme() {
|
|
79
|
+
return this.currentTheme;
|
|
80
|
+
}
|
|
81
|
+
get tokens() {
|
|
82
|
+
return this.currentTokens;
|
|
83
|
+
}
|
|
84
|
+
/** Act on one message the host sent. */
|
|
85
|
+
receive(message) {
|
|
86
|
+
// The table is keyed by kind, so this handler takes this message;
|
|
87
|
+
// TypeScript cannot follow that correlation through an index.
|
|
88
|
+
const handle = this.handlers[message.kind];
|
|
89
|
+
handle(message);
|
|
90
|
+
}
|
|
91
|
+
rpc(method, args = {}, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
92
|
+
// `Number`, not `timeoutMs` as it is: null means "no limit" to a
|
|
93
|
+
// correlator, but an untyped caller's null (or "500") reaches a
|
|
94
|
+
// call's timer the way `setTimeout` always read it — as 0 (or 500).
|
|
95
|
+
return this.calls.send(Number(timeoutMs), () => new Error(`igni bridge: ${method} timed out after ${timeoutMs}ms`), (id) => this.channel.post({ kind: "call", id, method, args }));
|
|
96
|
+
}
|
|
97
|
+
navigate(to) {
|
|
98
|
+
this.channel.post({ kind: "navigate", to });
|
|
99
|
+
}
|
|
100
|
+
close() {
|
|
101
|
+
this.channel.post({ kind: "close" });
|
|
102
|
+
}
|
|
103
|
+
onTheme(fn) {
|
|
104
|
+
return this.themeWatchers.add(fn);
|
|
105
|
+
}
|
|
106
|
+
onParams(fn) {
|
|
107
|
+
return this.paramWatchers.add(fn);
|
|
108
|
+
}
|
|
109
|
+
setLocation(state) {
|
|
110
|
+
this.channel.post({ kind: "location", state });
|
|
111
|
+
}
|
|
112
|
+
on(signal, fn, onRefused) {
|
|
113
|
+
return this.signals.on(signal, fn, onRefused);
|
|
114
|
+
}
|
|
115
|
+
applyTheme(message) {
|
|
116
|
+
this.currentTheme = message.theme;
|
|
117
|
+
this.currentTokens = message.tokens;
|
|
118
|
+
applyThemeTokens(this.currentTokens, document.documentElement);
|
|
119
|
+
this.themeWatchers.emit(this.currentTheme);
|
|
120
|
+
}
|
|
121
|
+
applyParams(message) {
|
|
122
|
+
this.currentParams = message.params;
|
|
123
|
+
this.paramWatchers.emit(this.currentParams);
|
|
124
|
+
}
|
|
125
|
+
hostRequest(body) {
|
|
126
|
+
// A dialog waits on the person, for as long as they take.
|
|
127
|
+
const waits = WAITS_ON_THE_PERSON.has(body.path);
|
|
128
|
+
return this.hostRequests.send(waits ? null : DEFAULT_TIMEOUT_MS, () => new HostError("failed", `igni bridge: host.${body.path || body.op} timed out after ${DEFAULT_TIMEOUT_MS}ms`), (id) => this.channel.post({ kind: "host", id, ...body }));
|
|
129
|
+
}
|
|
130
|
+
/** One token request to the host, which asks igni as this extension. */
|
|
131
|
+
askForToken() {
|
|
132
|
+
return this.tokenRequests.send(DEFAULT_TIMEOUT_MS, () => new ServiceError("failed", `igni bridge: no service token within ${DEFAULT_TIMEOUT_MS}ms`), (id) => this.channel.post({ kind: "service-token", id }));
|
|
133
|
+
}
|
|
134
|
+
settleCall(reply) {
|
|
135
|
+
if (reply.ok)
|
|
136
|
+
this.calls.resolve(reply.id, reply.value);
|
|
137
|
+
else
|
|
138
|
+
this.calls.reject(reply.id, new Error(reply.error || "the host refused the call without saying why"));
|
|
139
|
+
}
|
|
140
|
+
settleHostRequest(reply) {
|
|
141
|
+
if (reply.ok)
|
|
142
|
+
this.hostRequests.resolve(reply.id, reply.result);
|
|
143
|
+
else
|
|
144
|
+
this.hostRequests.reject(reply.id, new HostError(reply.error?.code ?? "failed", reply.error?.message ?? "the host refused without saying why"));
|
|
145
|
+
}
|
|
146
|
+
settleTokenRequest(reply) {
|
|
147
|
+
if (reply.ok && typeof reply.token === "string")
|
|
148
|
+
this.tokenRequests.resolve(reply.id, {
|
|
149
|
+
token: reply.token,
|
|
150
|
+
expiresIn: reply.expiresIn ?? 0,
|
|
151
|
+
});
|
|
152
|
+
else
|
|
153
|
+
this.tokenRequests.reject(reply.id, new ServiceError("refused", reply.error || "igni gave no token for this extension's service"));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=guestBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guestBridge.js","sourceRoot":"","sources":["../src/guestBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAA8B,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAehD,OAAO,EAAoB,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAoB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,uEAAuE;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC,2EAA2E;AAC3E,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAexD,MAAM,OAAO,WAAW;IAwCH;IApCV,WAAW,CAAS;IACpB,QAAQ,CAAI;IACZ,IAAI,CAAO;IACX,OAAO,CAAc;IAEtB,aAAa,CAAI;IACjB,YAAY,CAAS;IACrB,aAAa,CAAc;IAClB,aAAa,GAAG,IAAI,QAAQ,EAAU,CAAC;IACvC,aAAa,GAAG,IAAI,QAAQ,EAAK,CAAC;IACnD,0DAA0D;IACl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AAK;gBAClB,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,CAAC;aAChC,CAAC,CAAC;;YAEH,IAAI,CAAC,aAAa,CAAC,MAAM,CACvB,KAAK,CAAC,EAAE,EACR,IAAI,YAAY,CACd,SAAS,EACT,KAAK,CAAC,KAAK,IAAI,iDAAiD,CACjE,CACF,CAAC;IACN,CAAC;CACF"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pieces `bridge.host` is built from: objects, properties, signals,
|
|
3
|
+
* calls. `hostModel.generated.ts` is generated from igni's host schema
|
|
4
|
+
* and is made of these.
|
|
5
|
+
*
|
|
6
|
+
* await bridge.host.chat.processing.get(); // read a property
|
|
7
|
+
* await bridge.host.sessions.current.set(id); // write one
|
|
8
|
+
* await bridge.host.chat.post("Done."); // call a method
|
|
9
|
+
* bridge.on(bridge.host.chat.run_completed, (run) => { … });
|
|
10
|
+
*
|
|
11
|
+
* How a request reaches igni is the `HostLink`'s business — the bridge
|
|
12
|
+
* forwards it to the window this page is framed in, which forwards it to
|
|
13
|
+
* the host. Names are the schema's, snake_case, in both SDKs.
|
|
14
|
+
*/
|
|
15
|
+
/** Any JSON value: the host's report of something not yet typed. */
|
|
16
|
+
export type JsonValue = unknown;
|
|
17
|
+
/** Why the host refused or failed — the same codes the Python SDK raises. */
|
|
18
|
+
export type HostErrorCode = "not_granted" | "not_found" | "invalid" | "read_only" | "stage_2" | "refused" | "unavailable" | "failed";
|
|
19
|
+
/** The host said no, or it went wrong there. `code` is for code; the message, for people. */
|
|
20
|
+
export declare class HostError extends Error {
|
|
21
|
+
/** Why it failed: one of the {@link HostErrorCode}s, or the host's own. */
|
|
22
|
+
readonly code: HostErrorCode | string;
|
|
23
|
+
/**
|
|
24
|
+
* The failure, as the host reported it.
|
|
25
|
+
*
|
|
26
|
+
* @param code — why it failed: one of the {@link HostErrorCode}s, or
|
|
27
|
+
* whatever the host said.
|
|
28
|
+
* @param message — a sentence for a person to read.
|
|
29
|
+
*/
|
|
30
|
+
constructor(
|
|
31
|
+
/** Why it failed: one of the {@link HostErrorCode}s, or the host's own. */
|
|
32
|
+
code: HostErrorCode | string, message: string);
|
|
33
|
+
}
|
|
34
|
+
/** How requests reach the igni host. */
|
|
35
|
+
export interface HostLink {
|
|
36
|
+
/**
|
|
37
|
+
* Send one request to the host.
|
|
38
|
+
*
|
|
39
|
+
* @param op — what to do: read a property, write one, or call a method.
|
|
40
|
+
* @param path — where in the model, as `chat.processing`: the path without the leading `host.`.
|
|
41
|
+
* @param options — the window or session it is about, the arguments
|
|
42
|
+
* of a call, and the value of a write.
|
|
43
|
+
* @returns — whatever the host answered with.
|
|
44
|
+
*/
|
|
45
|
+
request(op: "get" | "set" | "call", path: string, options: {
|
|
46
|
+
/** The window to ask about, when it is not this page's own. */
|
|
47
|
+
window?: string | null;
|
|
48
|
+
/** The session to ask about, when it is not the one on screen. */
|
|
49
|
+
session?: string | null;
|
|
50
|
+
/** The arguments of a call, by name. */
|
|
51
|
+
params?: Record<string, unknown>;
|
|
52
|
+
/** The value of a write. */
|
|
53
|
+
value?: unknown;
|
|
54
|
+
}): Promise<unknown>;
|
|
55
|
+
}
|
|
56
|
+
/** One object of the host model: `host.chat`, `host.windows.ui(id)`, `host.sessions.chat(id)`. */
|
|
57
|
+
export declare class HostObject {
|
|
58
|
+
/** How requests reach the host. */
|
|
59
|
+
protected readonly link: HostLink;
|
|
60
|
+
/** Where in the model this object sits: `chat`, without the leading `host.`. */
|
|
61
|
+
readonly path: string;
|
|
62
|
+
/** The window it belongs to, when it belongs to one. */
|
|
63
|
+
protected readonly window: string | null;
|
|
64
|
+
/** The session it belongs to, when it belongs to one. */
|
|
65
|
+
protected readonly session: string | null;
|
|
66
|
+
/**
|
|
67
|
+
* One object of the model, bound to a host.
|
|
68
|
+
*
|
|
69
|
+
* A page never builds one: `bridge.host` is already the right one,
|
|
70
|
+
* and a second would be a second conversation.
|
|
71
|
+
*
|
|
72
|
+
* @param link — how requests reach the host.
|
|
73
|
+
* @param path — where in the model this object sits.
|
|
74
|
+
* @param window — the window it belongs to, when it belongs to one.
|
|
75
|
+
* @param session — the session it belongs to, when it belongs to one.
|
|
76
|
+
*/
|
|
77
|
+
constructor(
|
|
78
|
+
/** How requests reach the host. */
|
|
79
|
+
link: HostLink,
|
|
80
|
+
/** Where in the model this object sits: `chat`, without the leading `host.`. */
|
|
81
|
+
path: string,
|
|
82
|
+
/** The window it belongs to, when it belongs to one. */
|
|
83
|
+
window?: string | null,
|
|
84
|
+
/** The session it belongs to, when it belongs to one. */
|
|
85
|
+
session?: string | null);
|
|
86
|
+
/** @internal */
|
|
87
|
+
memberPath(name: string): string;
|
|
88
|
+
/** @internal — for `Property`. */
|
|
89
|
+
hostLink(): HostLink;
|
|
90
|
+
/** @internal — for `Property`. */
|
|
91
|
+
windowId(): string | null;
|
|
92
|
+
/** @internal — for `Property`. */
|
|
93
|
+
sessionId(): string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Call a method on the host.
|
|
96
|
+
*
|
|
97
|
+
* @param name — the method's name, as the schema spells it.
|
|
98
|
+
* @param params — its arguments, by name.
|
|
99
|
+
* @returns — whatever the host answered with.
|
|
100
|
+
*/
|
|
101
|
+
protected call<T>(name: string, params: Record<string, unknown>): Promise<T>;
|
|
102
|
+
}
|
|
103
|
+
/** A value of a host object: `get()` reads it, `set()` writes it. */
|
|
104
|
+
export declare class Property<T> {
|
|
105
|
+
/** The object it belongs to. */
|
|
106
|
+
private readonly owner;
|
|
107
|
+
/** Its name, as the schema spells it. */
|
|
108
|
+
readonly name: string;
|
|
109
|
+
/** Whether it may be written. */
|
|
110
|
+
readonly writable: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* One value of one host object.
|
|
113
|
+
*
|
|
114
|
+
* @param owner — the object it belongs to.
|
|
115
|
+
* @param name — its name, as the schema spells it.
|
|
116
|
+
* @param writable — whether it may be written.
|
|
117
|
+
*/
|
|
118
|
+
constructor(
|
|
119
|
+
/** The object it belongs to. */
|
|
120
|
+
owner: HostObject,
|
|
121
|
+
/** Its name, as the schema spells it. */
|
|
122
|
+
name: string,
|
|
123
|
+
/** Whether it may be written. */
|
|
124
|
+
writable: boolean);
|
|
125
|
+
/** Where in the model this value sits: `chat.processing`, without the leading `host.`. */
|
|
126
|
+
get path(): string;
|
|
127
|
+
/**
|
|
128
|
+
* Read it.
|
|
129
|
+
*
|
|
130
|
+
* @returns — the value the host holds right now.
|
|
131
|
+
*/
|
|
132
|
+
get(): Promise<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Write it, as the person's UI would. Refused where theirs would be.
|
|
135
|
+
*
|
|
136
|
+
* @param value — what the host should hold for it from now on.
|
|
137
|
+
*/
|
|
138
|
+
set(value: T): Promise<void>;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* One signal of one host object; `T` is what it carries. `name` is its
|
|
142
|
+
* wire name — `chat.run_completed`, or for the four events that predate
|
|
143
|
+
* the model their topic strings (`session.switched`, …).
|
|
144
|
+
*/
|
|
145
|
+
export declare class Signal<T> {
|
|
146
|
+
/** Its wire name, as the host sends it: `chat.run_completed`. */
|
|
147
|
+
readonly name: string;
|
|
148
|
+
/** Only for the type parameter; never set. */
|
|
149
|
+
readonly carries?: T;
|
|
150
|
+
/**
|
|
151
|
+
* One signal of one host object.
|
|
152
|
+
*
|
|
153
|
+
* @param name — its wire name, as the host sends it.
|
|
154
|
+
*/
|
|
155
|
+
constructor(
|
|
156
|
+
/** Its wire name, as the host sends it: `chat.run_completed`. */
|
|
157
|
+
name: string);
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=hostModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostModel.d.ts","sourceRoot":"","sources":["../src/hostModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,oEAAoE;AACpE,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC;AAEhC,6EAA6E;AAC7E,MAAM,MAAM,a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