@lyriel/openclaw-plugin 0.4.0 → 0.4.3
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/dist/api.js +181 -0
- package/dist/api.js.map +1 -0
- package/dist/inbox.js +206 -0
- package/dist/inbox.js.map +1 -0
- package/dist/index.js +132 -0
- package/dist/index.js.map +1 -0
- package/dist/pending.js +106 -0
- package/dist/pending.js.map +1 -0
- package/dist/primer.js +27 -0
- package/dist/primer.js.map +1 -0
- package/dist/surfacing.js +100 -0
- package/dist/surfacing.js.map +1 -0
- package/dist/telegram.js +63 -0
- package/dist/telegram.js.map +1 -0
- package/dist/tools.js +463 -0
- package/dist/tools.js.map +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending.js","sourceRoot":"","sources":["../pending.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,qEAAqE;AACrE,EAAE;AACF,kEAAkE;AAClE,6EAA6E;AAC7E,8EAA8E;AAC9E,0EAA0E;AAC1E,2DAA2D;AAS3D,MAAM,WAAW,GAAG,IAAI,GAAG,EAA2B,CAAC;AACvD,MAAM,YAAY,GAAG,IAAI,GAAG,EAA2B,CAAC;AACxD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE/C,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,2EAA2E;AAC3E,uEAAuE;AACvE,gDAAgD;AAChD,MAAM,eAAe,GAAG,yBAAyB,CAAC;AAClD,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AACvD,MAAM,WAAW,GAAG,mCAAmC,CAAC;AACxD,MAAM,mBAAmB,GAAG,oCAAoC,CAAC;AAEjE,SAAS,kBAAkB,CAAC,CAAS;IACnC,OAAO,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,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AE;QACvB,WAAW,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC5C,aAAa,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChD,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;QACtB,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;KACrC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,KAAK,EAAE,CAAC;QACV,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,KAAsB;IAChE,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/primer.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// The canonical Lyriel substrate primer.
|
|
2
|
+
//
|
|
3
|
+
// Loaded into the LLM's bound-tool context via one of the Lyriel tool
|
|
4
|
+
// descriptions (lyriel_send_ask, by convention — it's the simplest
|
|
5
|
+
// and most likely first tool the LLM looks at). The LLM reads tool
|
|
6
|
+
// descriptions when tools are bound, so the primer enters context
|
|
7
|
+
// the moment the Lyriel plugin activates.
|
|
8
|
+
//
|
|
9
|
+
// This must stay in sync with clients/hermes-plugin/lyriel_hermes/primer.py.
|
|
10
|
+
// Any edit here gets mirrored there until we extract a single shared
|
|
11
|
+
// source (see TODO at bottom).
|
|
12
|
+
export const SUBSTRATE_PRIMER = `You are operating on Lyriel — the protocol layer for agent-to-agent communication on behalf of humans. You act for your user, not as them; other agents on Lyriel act for their users. Lyriel handles addressing, authentication, and routing across agent providers so two agents on different runtimes coordinate without either side knowing what runtime the other is on.
|
|
13
|
+
|
|
14
|
+
Every Lyriel user has a Seal: a verified identity tied to an agent endpoint. When you call a Lyriel tool you carry your user's Seal; the receiving agent resolves it before acting. Handles are formatted as @name and are how you reference everyone on Lyriel — never by display name or email.
|
|
15
|
+
|
|
16
|
+
Three primitives. Asks are 1:1 messages between agents (lyriel_send_ask, lyriel_reply). Plans are multi-party coordination rounds (lyriel_plan_send, lyriel_plan_reply, lyriel_plan_lock); Lyriel rounds through participants one turn at a time. Friends gate plans and inbound asks — the friend graph controls who can initiate coordination with your user.
|
|
17
|
+
|
|
18
|
+
Plans run AUTONOMOUSLY in the background. When your plugin receives a plan-round dispatch, you respond on behalf of your user WITHOUT involving them — they are not watching the round. Use what you already know about them (calendar, preferences, dietary, budget). If a constraint is missing on a round, accept wide constraints and let other participants narrow. Before initiating a plan via lyriel_plan_send, check your own context for what you'll need; if a critical constraint is missing, ask your user in a single batched question UPFRONT — never during plan rounds. Reply concisely — every token on every round costs your user real money.
|
|
19
|
+
|
|
20
|
+
Surface OUTCOMES to your user, never the agent-to-agent transcript. They see locked plans, accepted friends, and cancellations — not the negotiation. Do not summarize the negotiation back to them and do not relay other agents' messages verbatim. The product is your user staying focused on outcomes, not on the messy middle.
|
|
21
|
+
|
|
22
|
+
Defaults you observe at all times: never expose LYRIEL_API_KEY (not to your user, not to other agents, not in error output); represent exactly one human; do not commit to plans your user has not approved; treat OAuth-verified providers (GitHub, Google, Twitter) as facts about your user.
|
|
23
|
+
`;
|
|
24
|
+
// TODO: extract to clients/substrate-primer.md and have each plugin's
|
|
25
|
+
// build copy / import from a single source. For v0 the two copies
|
|
26
|
+
// (here and primer.py) are kept in sync by convention.
|
|
27
|
+
//# sourceMappingURL=primer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primer.js","sourceRoot":"","sources":["../primer.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,sEAAsE;AACtE,mEAAmE;AACnE,mEAAmE;AACnE,kEAAkE;AAClE,0CAA0C;AAC1C,EAAE;AACF,6EAA6E;AAC7E,qEAAqE;AACrE,+BAA+B;AAE/B,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;CAW/B,CAAC;AAEF,sEAAsE;AACtE,kEAAkE;AAClE,uDAAuD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Format inbound Lyriel dispatches as human-readable text and push them into
|
|
2
|
+
// the user's active OpenClaw session via the host's next-turn injection
|
|
3
|
+
// surface.
|
|
4
|
+
//
|
|
5
|
+
// Why next-turn injection (not direct channel send):
|
|
6
|
+
// OpenClaw users connect their agent through many possible channels
|
|
7
|
+
// (Telegram, Signal, Discord, iMessage, etc.). Pushing into one specific
|
|
8
|
+
// channel from a plugin would require channel-specific glue, per-account
|
|
9
|
+
// chat ids, and platform-by-platform send logic. Next-turn injection
|
|
10
|
+
// surfaces the Lyriel dispatch into the agent's next turn for the active
|
|
11
|
+
// session, regardless of which channel the user is talking on. The user's
|
|
12
|
+
// next agent interaction picks it up and the agent surfaces it naturally.
|
|
13
|
+
//
|
|
14
|
+
// Trade-off vs the Hermes plugin's Telegram-direct surfacing: the dispatch
|
|
15
|
+
// doesn't become a free-standing push notification — the user has to engage
|
|
16
|
+
// the agent for it to surface. That's acceptable at v0: AI-native users are
|
|
17
|
+
// already in their agent throughout the day. A truly proactive push path
|
|
18
|
+
// would need per-channel send glue and is deferred until design-partner
|
|
19
|
+
// feedback says it's load-bearing.
|
|
20
|
+
const RE_INITIATOR = /This message is NOT from your human — it is from\s+([\s\S]+?)'s agent/;
|
|
21
|
+
const RE_ASK_TEXT = /The ask:\s*"""\s*([\s\S]+?)\s*"""/;
|
|
22
|
+
const RE_RESPONSE_TEXT = /agent has responded:\s*"""\s*([\s\S]+?)\s*"""/;
|
|
23
|
+
const RE_ORIGINAL_PROMPT = /on behalf of your human \(@\S+\):\s*"""\s*([\s\S]+?)\s*"""/;
|
|
24
|
+
const RE_RECIPIENT_NAME = /([\s\S]+?)'s agent has responded/;
|
|
25
|
+
// Plan envelope parsers
|
|
26
|
+
const RE_PLAN_INITIATOR = /plan initiated by\s+([\s\S]+?)'s agent/;
|
|
27
|
+
const RE_PLAN_DESCRIPTION = /THE PLAN:\s*"""\s*([\s\S]+?)\s*"""/;
|
|
28
|
+
const RE_PLAN_PARTICIPANTS = /PARTICIPANTS \(\d+ agents[^)]*\):\s*\n([\s\S]+?)\n\n/;
|
|
29
|
+
const RE_PLAN_CONVERSATION = /CONVERSATION SO FAR:\s*\n+([\s\S]+?)\n+WHAT TO DO RIGHT NOW/;
|
|
30
|
+
const RE_PLAN_LOCKED_SUMMARY = /LOCKED OUTCOME:\s*"""\s*([\s\S]+?)\s*"""/;
|
|
31
|
+
const RE_PLAN_LOCKED_PROPOSER = /locked\. ([\s\S]+?)'s agent proposed it/;
|
|
32
|
+
function pick(prompt, re, fallback) {
|
|
33
|
+
const m = prompt.match(re);
|
|
34
|
+
return m ? m[1].trim() : fallback;
|
|
35
|
+
}
|
|
36
|
+
export function formatDispatch(d) {
|
|
37
|
+
const askId = d.ask_id ?? "?";
|
|
38
|
+
const planId = d.plan_id;
|
|
39
|
+
const prompt = d.prompt ?? "";
|
|
40
|
+
if (d.direction === "plan" && planId) {
|
|
41
|
+
return formatPlanDispatch(planId, prompt);
|
|
42
|
+
}
|
|
43
|
+
if (d.direction === "dispatch") {
|
|
44
|
+
const sender = pick(prompt, RE_INITIATOR, "someone");
|
|
45
|
+
const askText = pick(prompt, RE_ASK_TEXT, "<could not parse ask>");
|
|
46
|
+
return (`🪶 Lyriel ask from ${sender}:\n\n` +
|
|
47
|
+
`"${askText}"\n\n` +
|
|
48
|
+
`To reply, say something like: ` +
|
|
49
|
+
`reply to Lyriel ask ${askId} with <your response>`);
|
|
50
|
+
}
|
|
51
|
+
if (d.direction === "forward") {
|
|
52
|
+
const respText = pick(prompt, RE_RESPONSE_TEXT, "<could not parse response>");
|
|
53
|
+
const original = pick(prompt, RE_ORIGINAL_PROMPT, "<your earlier ask>");
|
|
54
|
+
const sender = pick(prompt, RE_RECIPIENT_NAME, "someone");
|
|
55
|
+
return (`🪶 Lyriel reply from ${sender}:\n\n` +
|
|
56
|
+
`(in reply to: "${original}")\n\n` +
|
|
57
|
+
respText);
|
|
58
|
+
}
|
|
59
|
+
return `🪶 Lyriel: ${d.direction}\n${prompt.slice(0, 500)}`;
|
|
60
|
+
}
|
|
61
|
+
function formatPlanDispatch(planId, prompt) {
|
|
62
|
+
// Permissive separator matching — server emits comma today, em-dash
|
|
63
|
+
// was the older form. Strict match-current-server caused the lock
|
|
64
|
+
// notification to silently drop on the Hermes side (cf. 0.6.3 fix).
|
|
65
|
+
const isLocked = prompt.includes("[Lyriel group plan, LOCKED]") ||
|
|
66
|
+
prompt.includes("[Lyriel group plan — LOCKED]");
|
|
67
|
+
const isInitial = prompt.includes("[Lyriel group plan, round 1") ||
|
|
68
|
+
prompt.includes("[Lyriel group plan — round 1");
|
|
69
|
+
const description = pick(prompt, RE_PLAN_DESCRIPTION, "<could not parse plan>");
|
|
70
|
+
const participants = pick(prompt, RE_PLAN_PARTICIPANTS, "<participants unknown>");
|
|
71
|
+
if (isLocked) {
|
|
72
|
+
const summary = pick(prompt, RE_PLAN_LOCKED_SUMMARY, "<could not parse outcome>");
|
|
73
|
+
const proposer = pick(prompt, RE_PLAN_LOCKED_PROPOSER, "someone");
|
|
74
|
+
return (`🪶 Lyriel group plan LOCKED (plan_id ${planId})\n\n` +
|
|
75
|
+
`Plan: "${description}"\n\n` +
|
|
76
|
+
`Outcome (proposed by ${proposer}):\n` +
|
|
77
|
+
` → ${summary}\n\n` +
|
|
78
|
+
`Participants: ${participants}\n\n` +
|
|
79
|
+
`This is final. No further responses needed.`);
|
|
80
|
+
}
|
|
81
|
+
if (isInitial) {
|
|
82
|
+
const initiator = pick(prompt, RE_PLAN_INITIATOR, "someone");
|
|
83
|
+
return (`🪶 Lyriel group plan from ${initiator} (plan_id ${planId})\n\n` +
|
|
84
|
+
`Plan: "${description}"\n\n` +
|
|
85
|
+
`Participants: ${participants}\n\n` +
|
|
86
|
+
`Round 1 — your agent is being asked to contribute. To reply, ` +
|
|
87
|
+
`say something like: 'reply to Lyriel plan ${planId} saying ` +
|
|
88
|
+
`<your thoughts/constraints>'. To skip this round, say: ` +
|
|
89
|
+
`'stay silent on plan ${planId}'.`);
|
|
90
|
+
}
|
|
91
|
+
// plan_message (refinement round)
|
|
92
|
+
const conversation = pick(prompt, RE_PLAN_CONVERSATION, "<conversation unavailable>");
|
|
93
|
+
return (`🪶 Lyriel plan update (plan_id ${planId})\n\n` +
|
|
94
|
+
`Plan: "${description}"\n\n` +
|
|
95
|
+
`Conversation so far:\n${conversation}\n\n` +
|
|
96
|
+
`Refinement round — respond if you have something new to add. ` +
|
|
97
|
+
`To reply: 'reply to Lyriel plan ${planId} saying <your update>'. ` +
|
|
98
|
+
`To pass: 'stay silent on plan ${planId}'.`);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=surfacing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfacing.js","sourceRoot":"","sources":["../surfacing.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wEAAwE;AACxE,WAAW;AACX,EAAE;AACF,qDAAqD;AACrD,oEAAoE;AACpE,yEAAyE;AACzE,yEAAyE;AACzE,qEAAqE;AACrE,yEAAyE;AACzE,0EAA0E;AAC1E,0EAA0E;AAC1E,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,yEAAyE;AACzE,wEAAwE;AACxE,mCAAmC;AAInC,MAAM,YAAY,GAChB,uEAAuE,CAAC;AAC1E,MAAM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QAClF,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,uBAAuB,EAAE,SAAS,CAAC,CAAC;QAClE,OAAO,CACL,wCAAwC,MAAM,OAAO;YACrD,UAAU,WAAW,OAAO;YAC5B,wBAAwB,QAAQ,MAAM;YACtC,OAAO,OAAO,MAAM;YACpB,iBAAiB,YAAY,MAAM;YACnC,6CAA6C,CAC9C,CAAC;IACJ,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,iBAAiB,EAAE,SAAS,CAAC,CAAC;QAC7D,OAAO,CACL,6BAA6B,SAAS,aAAa,MAAM,OAAO;YAChE,UAAU,WAAW,OAAO;YAC5B,iBAAiB,YAAY,MAAM;YACnC,+DAA+D;YAC/D,6CAA6C,MAAM,UAAU;YAC7D,yDAAyD;YACzD,wBAAwB,MAAM,IAAI,CACnC,CAAC;IACJ,CAAC;IAED,kCAAkC;IAClC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,4BAA4B,CAAC,CAAC;IACtF,OAAO,CACL,kCAAkC,MAAM,OAAO;QAC/C,UAAU,WAAW,OAAO;QAC5B,yBAAyB,YAAY,MAAM;QAC3C,+DAA+D;QAC/D,mCAAmC,MAAM,0BAA0B;QACnE,iCAAiC,MAAM,IAAI,CAC5C,CAAC;AACJ,CAAC"}
|
package/dist/telegram.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Direct Telegram Bot API push for proactive surfacing.
|
|
2
|
+
//
|
|
3
|
+
// OpenClaw's plugin-sdk doesn't expose a clean cross-channel "deliver this
|
|
4
|
+
// text to chat X right now" primitive for external plugins — channel-message
|
|
5
|
+
// helpers exist but require a turn context. For v0 we reuse the bot token
|
|
6
|
+
// the user has already configured under `channels.telegram.botToken` and POST
|
|
7
|
+
// directly to api.telegram.org/bot<token>/sendMessage. Matches the
|
|
8
|
+
// surfacing behavior of the standalone Telegram bridge and the Hermes plugin.
|
|
9
|
+
//
|
|
10
|
+
// Chat id resolution (in order):
|
|
11
|
+
// 1. `plugins.entries.lyriel.config.surfaceTelegramChatId` (explicit pin)
|
|
12
|
+
// 2. `channels.telegram.allowFrom[0]` (the first allowlisted user — common
|
|
13
|
+
// single-user setup)
|
|
14
|
+
// 3. `channels.telegram.groupAllowFrom[0]` (group fallback)
|
|
15
|
+
//
|
|
16
|
+
// Returns false and logs a single warning if no chat id can be resolved or
|
|
17
|
+
// the bot token is missing.
|
|
18
|
+
const TELEGRAM_API_BASE = "https://api.telegram.org";
|
|
19
|
+
export function resolveTelegramSurface(openclawConfig, surfaceTelegramChatId) {
|
|
20
|
+
const cfg = openclawConfig;
|
|
21
|
+
const telegram = cfg?.channels?.telegram;
|
|
22
|
+
const botToken = telegram && typeof telegram.botToken === "string" && telegram.botToken ? telegram.botToken : null;
|
|
23
|
+
if (surfaceTelegramChatId) {
|
|
24
|
+
return { botToken, chatId: surfaceTelegramChatId };
|
|
25
|
+
}
|
|
26
|
+
const allowFrom = Array.isArray(telegram?.allowFrom) ? telegram?.allowFrom : [];
|
|
27
|
+
const firstAllow = allowFrom[0];
|
|
28
|
+
if (firstAllow !== undefined && firstAllow !== null) {
|
|
29
|
+
return { botToken, chatId: String(firstAllow) };
|
|
30
|
+
}
|
|
31
|
+
const groupAllowFrom = Array.isArray(telegram?.groupAllowFrom) ? telegram?.groupAllowFrom : [];
|
|
32
|
+
const firstGroup = groupAllowFrom[0];
|
|
33
|
+
if (firstGroup !== undefined && firstGroup !== null) {
|
|
34
|
+
return { botToken, chatId: String(firstGroup) };
|
|
35
|
+
}
|
|
36
|
+
return { botToken, chatId: null };
|
|
37
|
+
}
|
|
38
|
+
export async function sendTelegramMessage(surface, text) {
|
|
39
|
+
if (!surface.botToken || !surface.chatId) {
|
|
40
|
+
return { ok: false, error: "no telegram bot token or chat id configured" };
|
|
41
|
+
}
|
|
42
|
+
const url = `${TELEGRAM_API_BASE}/bot${surface.botToken}/sendMessage`;
|
|
43
|
+
try {
|
|
44
|
+
const res = await fetch(url, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: { "content-type": "application/json" },
|
|
47
|
+
body: JSON.stringify({
|
|
48
|
+
chat_id: surface.chatId,
|
|
49
|
+
text,
|
|
50
|
+
disable_web_page_preview: true,
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
if (!res.ok) {
|
|
54
|
+
const body = await res.text();
|
|
55
|
+
return { ok: false, error: `telegram ${res.status}: ${body.slice(0, 200)}` };
|
|
56
|
+
}
|
|
57
|
+
return { ok: true };
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
return { ok: false, error: err.message };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=telegram.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram.js","sourceRoot":"","sources":["../telegram.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,0EAA0E;AAC1E,8EAA8E;AAC9E,mEAAmE;AACnE,8EAA8E;AAC9E,EAAE;AACF,iCAAiC;AACjC,4EAA4E;AAC5E,6EAA6E;AAC7E,0BAA0B;AAC1B,8DAA8D;AAC9D,EAAE;AACF,2EAA2E;AAC3E,4BAA4B;AAO5B,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAErD,MAAM,UAAU,sBAAsB,CACpC,cAAuB,EACvB,qBAAyC;IAEzC,MAAM,GAAG,GAAG,cAAiF,CAAC;IAC9F,MAAM,QAAQ,GAAG,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC;IACzC,MAAM,QAAQ,GACZ,QAAQ,IAAI,OAAO,QAAQ,CAAC,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpG,IAAI,qBAAqB,EAAE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