layerbase 0.2.0 → 0.3.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/dist/cli.js +1 -1
- package/dist/commands/interactive.js +76 -69
- package/dist/commands/interactive.js.map +1 -1
- package/dist/lib/commands.js +76 -0
- package/dist/lib/commands.js.map +1 -0
- package/dist/ui/prompt.js +59 -0
- package/dist/ui/prompt.js.map +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ const cli = meow(`
|
|
|
23
23
|
spindb [args...] Run the local spindb CLI (passes args through)
|
|
24
24
|
alias Set up the short lb command (only if it is free)
|
|
25
25
|
|
|
26
|
-
Run with no command for
|
|
26
|
+
Run with no command for the interactive prompt (type /commands). Also lbase.
|
|
27
27
|
|
|
28
28
|
Options
|
|
29
29
|
--print With connect: show connection info, do not exec
|
|
@@ -1,55 +1,45 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { render, Box, Text } from 'ink';
|
|
3
|
+
import { Prompt } from '../ui/prompt.js';
|
|
3
4
|
import { Menu } from '../ui/menu.js';
|
|
4
|
-
import { Header } from '../ui/brand.js';
|
|
5
5
|
import { Connecting } from '../ui/connecting.js';
|
|
6
|
-
import { PressEnter } from '../ui/press-enter.js';
|
|
7
6
|
import { loadCredentials } from '../lib/config.js';
|
|
8
7
|
import { decodeTokenClaims } from '../lib/token.js';
|
|
8
|
+
import { resolveInput, availableCommands } from '../lib/commands.js';
|
|
9
9
|
import { listDatabases } from '../lib/cloud-api.js';
|
|
10
10
|
import { runSpindb } from '../lib/run-spindb.js';
|
|
11
11
|
import { connectToDatabase } from '../commands/connect.js';
|
|
12
|
-
import { lbStatus } from '../lib/alias.js';
|
|
13
12
|
import { App } from '../ui/app.js';
|
|
13
|
+
const ACCENT_ANSI = '\x1b[38;2;124;156;255m';
|
|
14
|
+
const DIM = '\x1b[2m';
|
|
15
|
+
const RESET = '\x1b[0m';
|
|
14
16
|
const BACK = '__back__';
|
|
15
|
-
function
|
|
16
|
-
// Clear the visible screen and home the cursor (scrollback is preserved).
|
|
17
|
-
process.stdout.write('[2J[H');
|
|
18
|
-
}
|
|
19
|
-
function accountLine(creds) {
|
|
17
|
+
function accountText(creds) {
|
|
20
18
|
if (!creds)
|
|
21
|
-
return
|
|
19
|
+
return 'Not signed in';
|
|
22
20
|
const email = decodeTokenClaims(creds.token)?.email;
|
|
23
|
-
return
|
|
21
|
+
return email ? `Signed in as ${email}` : 'Signed in';
|
|
24
22
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
items.push({ label: 'List cloud databases', value: 'ls' });
|
|
29
|
-
items.push({ label: 'Connect to a database', value: 'connect' });
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
items.push({ label: 'Log in', value: 'login', hint: 'browser sign-in' });
|
|
33
|
-
}
|
|
34
|
-
items.push({ label: 'Run spindb', value: 'spindb', hint: 'local databases' });
|
|
35
|
-
if (loggedIn)
|
|
36
|
-
items.push({ label: 'Log out', value: 'logout' });
|
|
37
|
-
if (lbAvailable) {
|
|
38
|
-
items.push({ label: 'Enable the lb shortcut', value: 'alias' });
|
|
39
|
-
}
|
|
40
|
-
items.push({ label: 'Quit', value: 'quit' });
|
|
41
|
-
return items;
|
|
23
|
+
function printBanner(creds) {
|
|
24
|
+
process.stdout.write(`\n${ACCENT_ANSI}◆ Layerbase${RESET} ${DIM}cloud + local databases${RESET}\n` +
|
|
25
|
+
`${DIM}${accountText(creds)} · type /help to see commands${RESET}\n\n`);
|
|
42
26
|
}
|
|
43
|
-
function
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
function printCommands(loggedIn) {
|
|
28
|
+
const lines = availableCommands(loggedIn).map((c) => ` ${DIM}/${RESET}${c.name.padEnd(11)}${DIM}${c.summary}${RESET}`);
|
|
29
|
+
process.stdout.write(`Commands:\n${lines.join('\n')}\n\n`);
|
|
30
|
+
}
|
|
31
|
+
function promptOnce(creds) {
|
|
32
|
+
// Surface aliases (e.g. /menu for spindb) as their own palette entries so
|
|
33
|
+
// they are discoverable while typing.
|
|
34
|
+
const commands = availableCommands(Boolean(creds)).flatMap((c) => [
|
|
35
|
+
{ name: c.name, summary: c.summary },
|
|
36
|
+
...(c.aliases ?? []).map((alias) => ({ name: alias, summary: c.summary })),
|
|
37
|
+
]);
|
|
48
38
|
return new Promise((resolve) => {
|
|
49
|
-
const app = render(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
const app = render(_jsx(Prompt, { commands: commands, onSubmit: (raw) => {
|
|
40
|
+
app.unmount();
|
|
41
|
+
resolve(raw);
|
|
42
|
+
} }));
|
|
53
43
|
});
|
|
54
44
|
}
|
|
55
45
|
function pickDatabase(databases) {
|
|
@@ -60,15 +50,17 @@ function pickDatabase(databases) {
|
|
|
60
50
|
}));
|
|
61
51
|
items.push({ label: 'Back', value: BACK });
|
|
62
52
|
return new Promise((resolve) => {
|
|
63
|
-
const app = render(_jsxs(Box, { flexDirection: "column",
|
|
53
|
+
const app = render(_jsxs(Box, { flexDirection: "column", paddingY: 1, children: [_jsx(Text, { bold: true, children: "Pick a database to connect to" }), _jsx(Box, { marginTop: 1, children: _jsx(Menu, { items: items, onSelect: (v) => {
|
|
64
54
|
app.unmount();
|
|
65
|
-
resolve(
|
|
55
|
+
resolve(v === BACK ? null : v);
|
|
66
56
|
} }) })] }));
|
|
67
57
|
});
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
async function runConnectFlow(dbRef) {
|
|
60
|
+
if (dbRef) {
|
|
61
|
+
await connectToDatabase({ dbRef, command: 'connect' });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
72
64
|
const spinner = render(_jsx(Connecting, { label: "Loading your databases..." }));
|
|
73
65
|
let databases;
|
|
74
66
|
try {
|
|
@@ -84,42 +76,57 @@ async function runConnectFlow() {
|
|
|
84
76
|
process.stdout.write('No databases yet. Create one at https://layerbase.com.\n');
|
|
85
77
|
return;
|
|
86
78
|
}
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
await connectToDatabase({ dbRef, command: 'connect' });
|
|
79
|
+
const picked = await pickDatabase(databases);
|
|
80
|
+
if (picked)
|
|
81
|
+
await connectToDatabase({ dbRef: picked, command: 'connect' });
|
|
91
82
|
}
|
|
92
|
-
async function
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
async function dispatch(name, args, creds, flags) {
|
|
84
|
+
switch (name) {
|
|
85
|
+
case 'quit':
|
|
86
|
+
return 'quit';
|
|
87
|
+
case 'help':
|
|
88
|
+
printCommands(Boolean(creds));
|
|
89
|
+
return 'continue';
|
|
90
|
+
case 'spindb':
|
|
91
|
+
await runSpindb(args);
|
|
92
|
+
return 'continue';
|
|
93
|
+
case 'connect':
|
|
94
|
+
await runConnectFlow(args[0]);
|
|
95
|
+
return 'continue';
|
|
96
|
+
default: {
|
|
97
|
+
const instance = render(_jsx(App, { command: name, args: args, flags: flags }));
|
|
98
|
+
await instance.waitUntilExit();
|
|
99
|
+
process.stdout.write('\n');
|
|
100
|
+
return 'continue';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
95
103
|
}
|
|
96
|
-
// The
|
|
97
|
-
//
|
|
98
|
-
//
|
|
104
|
+
// The interactive harness: a Claude-Code-style prompt loop. Type /commands (or
|
|
105
|
+
// browse the palette); /spindb (alias /menu) hands off to local spindb. Bare
|
|
106
|
+
// text is the future AI-chat path (stubbed for now). The command set lives in
|
|
107
|
+
// @/lib/commands.
|
|
99
108
|
export async function runInteractive(flags) {
|
|
109
|
+
printBanner(await loadCredentials());
|
|
100
110
|
for (;;) {
|
|
101
|
-
clearScreen();
|
|
102
111
|
const creds = await loadCredentials();
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
const raw = await promptOnce(creds);
|
|
113
|
+
const res = resolveInput(raw, { loggedIn: Boolean(creds) });
|
|
114
|
+
if (res.type === 'empty')
|
|
115
|
+
continue;
|
|
116
|
+
if (res.type === 'unknown') {
|
|
117
|
+
process.stdout.write(`Unknown command: /${res.token}. Type /help to see the commands.\n\n`);
|
|
118
|
+
continue;
|
|
108
119
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
if (res.type === 'ai') {
|
|
121
|
+
process.stdout.write('We do not yet support AI chat, please check back soon.\n\n');
|
|
122
|
+
printCommands(Boolean(creds));
|
|
123
|
+
continue;
|
|
112
124
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// login / logout / ls / alias run through the same Ink dispatcher as
|
|
118
|
-
// typed commands; wait for the action to finish.
|
|
119
|
-
const instance = render(_jsx(App, { command: choice, args: [], flags: flags }));
|
|
120
|
-
await instance.waitUntilExit();
|
|
125
|
+
const result = await dispatch(res.name, res.args, creds, flags);
|
|
126
|
+
if (result === 'quit') {
|
|
127
|
+
process.stdout.write('Bye.\n');
|
|
128
|
+
return;
|
|
121
129
|
}
|
|
122
|
-
await waitForEnter();
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
132
|
//# sourceMappingURL=interactive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/commands/interactive.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AACvC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/commands/interactive.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE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Ae,EAAE,CAAC,CAAA;IAEpC,SAAS,CAAC;QACR,MAAM,KAAK,GAAG,MAAM,eAAe,EAAE,CAAA;QACrC,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,CAAA;QACnC,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAE3D,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;YAAE,SAAQ;QAClC,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,qBAAqB,GAAG,CAAC,KAAK,uCAAuC,CACtE,CAAA;YACD,SAAQ;QACV,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,4DAA4D,CAC7D,CAAA;YACD,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;YAC7B,SAAQ;QACV,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;QAC/D,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;YAC9B,OAAM;QACR,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// The command registry: the single source of truth for the interactive harness.
|
|
2
|
+
// Adding a command here makes it show up in the prompt palette, the /menu, and
|
|
3
|
+
// /help automatically. This is the seam future AI chat plugs into (a default
|
|
4
|
+
// handler for non-command input).
|
|
5
|
+
// When true (the pre-AI state), a bare single word that matches a command runs
|
|
6
|
+
// it, so `login` behaves like `/login`. Once AI chat is wired in, flip this to
|
|
7
|
+
// false so bare text is sent to the model instead of being treated as a command.
|
|
8
|
+
// Deliberately an in-code constant, not an env var: it encodes a code-evolution
|
|
9
|
+
// stage, not a runtime/operator decision.
|
|
10
|
+
export const ALLOW_FORWARD_SLASH_OMISSION = true;
|
|
11
|
+
export const COMMANDS = [
|
|
12
|
+
{ name: 'login', summary: 'Sign in via your browser', hideWhenAuthed: true },
|
|
13
|
+
{
|
|
14
|
+
name: 'logout',
|
|
15
|
+
summary: 'Sign out and remove the stored token',
|
|
16
|
+
requiresAuth: true,
|
|
17
|
+
},
|
|
18
|
+
{ name: 'whoami', summary: 'Show the signed-in account', requiresAuth: true },
|
|
19
|
+
{ name: 'ls', summary: 'List your cloud databases', requiresAuth: true },
|
|
20
|
+
{
|
|
21
|
+
name: 'connect',
|
|
22
|
+
summary: 'Connect to a cloud database',
|
|
23
|
+
requiresAuth: true,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'spindb',
|
|
27
|
+
summary: 'Open the local spindb manager (also /menu)',
|
|
28
|
+
aliases: ['menu'],
|
|
29
|
+
},
|
|
30
|
+
{ name: 'help', summary: 'List the available commands' },
|
|
31
|
+
{ name: 'quit', summary: 'Exit', aliases: ['exit'] },
|
|
32
|
+
];
|
|
33
|
+
export function findCommand(token) {
|
|
34
|
+
const t = token.toLowerCase();
|
|
35
|
+
return COMMANDS.find((c) => c.name === t || c.aliases?.includes(t));
|
|
36
|
+
}
|
|
37
|
+
export function availableCommands(loggedIn) {
|
|
38
|
+
return COMMANDS.filter((c) => {
|
|
39
|
+
if (c.requiresAuth && !loggedIn)
|
|
40
|
+
return false;
|
|
41
|
+
if (c.hideWhenAuthed && loggedIn)
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// Parse a line of prompt input into an action. Slash commands always resolve as
|
|
47
|
+
// commands; bare input resolves to a command only when it is a single word that
|
|
48
|
+
// matches AND ALLOW_FORWARD_SLASH_OMISSION is on; everything else is 'ai' (the
|
|
49
|
+
// future AI-chat path, stubbed for now).
|
|
50
|
+
export function resolveInput(raw, options) {
|
|
51
|
+
void options;
|
|
52
|
+
const input = raw.trim();
|
|
53
|
+
if (!input)
|
|
54
|
+
return { type: 'empty' };
|
|
55
|
+
if (input.startsWith('/')) {
|
|
56
|
+
const parts = input.slice(1).trim().split(/\s+/);
|
|
57
|
+
const token = parts[0];
|
|
58
|
+
if (!token)
|
|
59
|
+
return { type: 'empty' };
|
|
60
|
+
const cmd = findCommand(token);
|
|
61
|
+
return cmd
|
|
62
|
+
? { type: 'command', name: cmd.name, args: parts.slice(1) }
|
|
63
|
+
: { type: 'unknown', token };
|
|
64
|
+
}
|
|
65
|
+
if (ALLOW_FORWARD_SLASH_OMISSION) {
|
|
66
|
+
const words = input.split(/\s+/);
|
|
67
|
+
const only = words[0];
|
|
68
|
+
if (words.length === 1 && only) {
|
|
69
|
+
const cmd = findCommand(only);
|
|
70
|
+
if (cmd)
|
|
71
|
+
return { type: 'command', name: cmd.name, args: [] };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { type: 'ai', input };
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/lib/commands.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,+EAA+E;AAC/E,6EAA6E;AAC7E,kCAAkC;AAElC,+EAA+E;AAC/E,+EAA+E;AAC/E,iFAAiF;AACjF,gFAAgF;AAChF,0CAA0C;AAC1C,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAA;AAahD,MAAM,CAAC,MAAM,QAAQ,GAAkB;IACrC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,IAAI,EAAE;IAC5E;QACE,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,sCAAsC;QAC/C,YAAY,EAAE,IAAI;KAC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0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Box, Text, useInput } from 'ink';
|
|
4
|
+
import { ACCENT } from '../ui/brand.js';
|
|
5
|
+
// A Claude-Code-style input line: type a /command (with a live palette you can
|
|
6
|
+
// arrow through and Tab-complete), or type free text. Enter submits. The palette
|
|
7
|
+
// shows only while typing a bare slash token (it hides once you add arguments).
|
|
8
|
+
export function Prompt({ commands, onSubmit, }) {
|
|
9
|
+
const [value, setValue] = useState('');
|
|
10
|
+
const [index, setIndex] = useState(0);
|
|
11
|
+
const showPalette = /^\/[a-z-]*$/i.test(value);
|
|
12
|
+
const query = showPalette ? value.slice(1).toLowerCase() : '';
|
|
13
|
+
const matches = showPalette
|
|
14
|
+
? commands.filter((c) => c.name.startsWith(query))
|
|
15
|
+
: [];
|
|
16
|
+
const active = matches.length ? Math.min(index, matches.length - 1) : 0;
|
|
17
|
+
useInput((input, key) => {
|
|
18
|
+
if (key.return) {
|
|
19
|
+
const chosen = matches[active];
|
|
20
|
+
if (showPalette && chosen)
|
|
21
|
+
onSubmit(`/${chosen.name}`);
|
|
22
|
+
else
|
|
23
|
+
onSubmit(value);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (key.upArrow) {
|
|
27
|
+
if (matches.length)
|
|
28
|
+
setIndex((i) => (i <= 0 ? matches.length - 1 : i - 1));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (key.downArrow) {
|
|
32
|
+
if (matches.length)
|
|
33
|
+
setIndex((i) => (i >= matches.length - 1 ? 0 : i + 1));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (key.tab) {
|
|
37
|
+
const chosen = matches[active];
|
|
38
|
+
if (chosen) {
|
|
39
|
+
setValue(`/${chosen.name}`);
|
|
40
|
+
setIndex(0);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (key.backspace || key.delete) {
|
|
45
|
+
setValue((v) => v.slice(0, -1));
|
|
46
|
+
setIndex(0);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (input && !key.ctrl && !key.meta) {
|
|
50
|
+
setValue((v) => v + input);
|
|
51
|
+
setIndex(0);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: ACCENT, children: '❯ ' }), _jsx(Text, { children: value }), _jsx(Text, { inverse: true, children: " " })] }), showPalette ? (_jsx(Box, { flexDirection: "column", marginTop: 1, children: matches.length === 0 ? (_jsx(Text, { dimColor: true, children: " no matching command" })) : (matches.map((c, i) => {
|
|
55
|
+
const on = i === active;
|
|
56
|
+
return (_jsxs(Box, { children: [_jsxs(Text, { color: on ? ACCENT : undefined, bold: on, children: [on ? '❯ ' : ' ', `/${c.name}`.padEnd(12)] }), _jsx(Text, { dimColor: true, children: c.summary })] }, c.name));
|
|
57
|
+
})) })) : (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["Type a /command (or / to browse) ", '·', " Enter to run ", '·', " Ctrl+C to quit"] }) }))] }));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/ui/prompt.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAInC,+EAA+E;AAC/E,iFAAiF;AACjF,gFAAgF;AAChF,MAAM,UAAU,MAAM,CAAC,EACrB,QAAQ,EACR,QAAQ,GAIT;IACC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAA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