@riotprompt/riotprompt 0.0.1 → 0.0.2
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/logger.js +4 -2
- package/dist/logger.js.map +1 -1
- package/dist/riotprompt.cjs +104 -102
- package/dist/riotprompt.cjs.map +1 -1
- package/package.json +16 -14
- package/vite.config.ts +2 -2
- package/dist/builder.cjs +0 -152
- package/dist/builder.cjs.map +0 -1
- package/dist/chat.cjs +0 -26
- package/dist/chat.cjs.map +0 -1
- package/dist/constants.cjs +0 -34
- package/dist/constants.cjs.map +0 -1
- package/dist/formatter.cjs +0 -139
- package/dist/formatter.cjs.map +0 -1
- package/dist/items/content.cjs +0 -14
- package/dist/items/content.cjs.map +0 -1
- package/dist/items/context.cjs +0 -13
- package/dist/items/context.cjs.map +0 -1
- package/dist/items/instruction.cjs +0 -13
- package/dist/items/instruction.cjs.map +0 -1
- package/dist/items/parameters.cjs +0 -53
- package/dist/items/parameters.cjs.map +0 -1
- package/dist/items/section.cjs +0 -120
- package/dist/items/section.cjs.map +0 -1
- package/dist/items/trait.cjs +0 -13
- package/dist/items/trait.cjs.map +0 -1
- package/dist/items/weighted.cjs +0 -27
- package/dist/items/weighted.cjs.map +0 -1
- package/dist/loader.cjs +0 -167
- package/dist/loader.cjs.map +0 -1
- package/dist/logger.cjs +0 -51
- package/dist/logger.cjs.map +0 -1
- package/dist/override.cjs +0 -109
- package/dist/override.cjs.map +0 -1
- package/dist/parse/markdown.cjs +0 -114
- package/dist/parse/markdown.cjs.map +0 -1
- package/dist/parse/text.cjs +0 -33
- package/dist/parse/text.cjs.map +0 -1
- package/dist/parser.cjs +0 -99
- package/dist/parser.cjs.map +0 -1
- package/dist/prompt.cjs +0 -15
- package/dist/prompt.cjs.map +0 -1
- package/dist/util/general.cjs +0 -52
- package/dist/util/general.cjs.map +0 -1
- package/dist/util/markdown.cjs +0 -115
- package/dist/util/markdown.cjs.map +0 -1
- package/dist/util/storage.cjs +0 -155
- package/dist/util/storage.cjs.map +0 -1
- package/dist/util/text.cjs +0 -42
- package/dist/util/text.cjs.map +0 -1
package/dist/util/storage.cjs
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const glob = require('glob');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const crypto = require('crypto');
|
|
9
|
-
|
|
10
|
-
function _interopNamespaceDefault(e) {
|
|
11
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
12
|
-
if (e) {
|
|
13
|
-
for (const k in e) {
|
|
14
|
-
if (k !== 'default') {
|
|
15
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: () => e[k]
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
n.default = e;
|
|
24
|
-
return Object.freeze(n);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line no-restricted-imports
|
|
30
|
-
const create = (params)=>{
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
|
-
const log = params.log || console.log;
|
|
33
|
-
const exists = async (path)=>{
|
|
34
|
-
try {
|
|
35
|
-
await fs__namespace.promises.stat(path);
|
|
36
|
-
return true;
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
38
|
-
} catch (error) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const isDirectory = async (path)=>{
|
|
43
|
-
const stats = await fs__namespace.promises.stat(path);
|
|
44
|
-
if (!stats.isDirectory()) {
|
|
45
|
-
log(`${path} is not a directory`);
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
};
|
|
50
|
-
const isFile = async (path)=>{
|
|
51
|
-
const stats = await fs__namespace.promises.stat(path);
|
|
52
|
-
if (!stats.isFile()) {
|
|
53
|
-
log(`${path} is not a file`);
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
};
|
|
58
|
-
const isReadable = async (path)=>{
|
|
59
|
-
try {
|
|
60
|
-
await fs__namespace.promises.access(path, fs__namespace.constants.R_OK);
|
|
61
|
-
} catch (error) {
|
|
62
|
-
log(`${path} is not readable: %s %s`, error.message, error.stack);
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
};
|
|
67
|
-
const isWritable = async (path)=>{
|
|
68
|
-
try {
|
|
69
|
-
await fs__namespace.promises.access(path, fs__namespace.constants.W_OK);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
log(`${path} is not writable: %s %s`, error.message, error.stack);
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
};
|
|
76
|
-
const isFileReadable = async (path)=>{
|
|
77
|
-
return await exists(path) && await isFile(path) && await isReadable(path);
|
|
78
|
-
};
|
|
79
|
-
const isDirectoryWritable = async (path)=>{
|
|
80
|
-
return await exists(path) && await isDirectory(path) && await isWritable(path);
|
|
81
|
-
};
|
|
82
|
-
const isDirectoryReadable = async (path)=>{
|
|
83
|
-
return await exists(path) && await isDirectory(path) && await isReadable(path);
|
|
84
|
-
};
|
|
85
|
-
const createDirectory = async (path)=>{
|
|
86
|
-
try {
|
|
87
|
-
await fs__namespace.promises.mkdir(path, {
|
|
88
|
-
recursive: true
|
|
89
|
-
});
|
|
90
|
-
} catch (mkdirError) {
|
|
91
|
-
throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const readFile = async (path, encoding)=>{
|
|
95
|
-
return await fs__namespace.promises.readFile(path, {
|
|
96
|
-
encoding: encoding
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
const writeFile = async (path, data, encoding)=>{
|
|
100
|
-
await fs__namespace.promises.writeFile(path, data, {
|
|
101
|
-
encoding: encoding
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
const forEachFileIn = async (directory, callback, options = {
|
|
105
|
-
pattern: '*.*'
|
|
106
|
-
})=>{
|
|
107
|
-
try {
|
|
108
|
-
let filesProcessed = 0;
|
|
109
|
-
const files = await glob.glob(options.pattern, {
|
|
110
|
-
cwd: directory,
|
|
111
|
-
nodir: true
|
|
112
|
-
});
|
|
113
|
-
for (const file of files){
|
|
114
|
-
await callback(path.join(directory, file));
|
|
115
|
-
filesProcessed++;
|
|
116
|
-
if (options.limit && filesProcessed >= options.limit) {
|
|
117
|
-
log(`Reached limit of ${options.limit} files, stopping`);
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
} catch (err) {
|
|
122
|
-
throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
const readStream = async (path)=>{
|
|
126
|
-
return fs__namespace.createReadStream(path);
|
|
127
|
-
};
|
|
128
|
-
const hashFile = async (path, length)=>{
|
|
129
|
-
const file = await readFile(path, 'utf8');
|
|
130
|
-
return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);
|
|
131
|
-
};
|
|
132
|
-
const listFiles = async (directory)=>{
|
|
133
|
-
return await fs__namespace.promises.readdir(directory);
|
|
134
|
-
};
|
|
135
|
-
return {
|
|
136
|
-
exists,
|
|
137
|
-
isDirectory,
|
|
138
|
-
isFile,
|
|
139
|
-
isReadable,
|
|
140
|
-
isWritable,
|
|
141
|
-
isFileReadable,
|
|
142
|
-
isDirectoryWritable,
|
|
143
|
-
isDirectoryReadable,
|
|
144
|
-
createDirectory,
|
|
145
|
-
readFile,
|
|
146
|
-
readStream,
|
|
147
|
-
writeFile,
|
|
148
|
-
forEachFileIn,
|
|
149
|
-
hashFile,
|
|
150
|
-
listFiles
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
exports.create = create;
|
|
155
|
-
//# sourceMappingURL=storage.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage.cjs","sources":["../../src/util/storage.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport * as fs from 'fs';\nimport { glob } from 'glob';\nimport path from 'path';\nimport crypto from 'crypto';\n/**\n * This module exists to isolate filesystem operations from the rest of the codebase.\n * This makes testing easier by avoiding direct fs mocking in jest configuration.\n * \n * Additionally, abstracting storage operations allows for future flexibility - \n * this export utility may need to work with storage systems other than the local filesystem\n * (e.g. S3, Google Cloud Storage, etc).\n */\n\nexport interface Utility {\n exists: (path: string) => Promise<boolean>;\n isDirectory: (path: string) => Promise<boolean>;\n isFile: (path: string) => Promise<boolean>;\n isReadable: (path: string) => Promise<boolean>;\n isWritable: (path: string) => Promise<boolean>;\n isFileReadable: (path: string) => Promise<boolean>;\n isDirectoryWritable: (path: string) => Promise<boolean>;\n isDirectoryReadable: (path: string) => Promise<boolean>;\n createDirectory: (path: string) => Promise<void>;\n readFile: (path: string, encoding: string) => Promise<string>;\n readStream: (path: string) => Promise<fs.ReadStream>;\n writeFile: (path: string, data: string | Buffer, encoding: string) => Promise<void>;\n forEachFileIn: (directory: string, callback: (path: string) => Promise<void>, options?: { pattern: string, limit?: number }) => Promise<void>;\n hashFile: (path: string, length: number) => Promise<string>;\n listFiles: (directory: string) => Promise<string[]>;\n}\n\nexport const create = (params: { log?: (message: string, ...args: any[]) => void }): Utility => {\n\n // eslint-disable-next-line no-console\n const log = params.log || console.log;\n\n const exists = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.stat(path);\n return true;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error: any) {\n return false;\n }\n }\n\n const isDirectory = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isDirectory()) {\n log(`${path} is not a directory`);\n return false;\n }\n return true;\n }\n\n const isFile = async (path: string): Promise<boolean> => {\n const stats = await fs.promises.stat(path);\n if (!stats.isFile()) {\n log(`${path} is not a file`);\n return false;\n }\n return true;\n }\n\n const isReadable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.R_OK);\n } catch (error: any) {\n log(`${path} is not readable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isWritable = async (path: string): Promise<boolean> => {\n try {\n await fs.promises.access(path, fs.constants.W_OK);\n } catch (error: any) {\n log(`${path} is not writable: %s %s`, error.message, error.stack);\n return false;\n }\n return true;\n }\n\n const isFileReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isFile(path) && await isReadable(path);\n }\n\n const isDirectoryWritable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isWritable(path);\n }\n\n const isDirectoryReadable = async (path: string): Promise<boolean> => {\n return await exists(path) && await isDirectory(path) && await isReadable(path);\n }\n\n const createDirectory = async (path: string): Promise<void> => {\n try {\n await fs.promises.mkdir(path, { recursive: true });\n } catch (mkdirError: any) {\n throw new Error(`Failed to create output directory ${path}: ${mkdirError.message} ${mkdirError.stack}`);\n }\n }\n\n const readFile = async (path: string, encoding: string): Promise<string> => {\n return await fs.promises.readFile(path, { encoding: encoding as BufferEncoding });\n }\n\n const writeFile = async (path: string, data: string | Buffer, encoding: string): Promise<void> => {\n await fs.promises.writeFile(path, data, { encoding: encoding as BufferEncoding });\n }\n\n const forEachFileIn = async (\n directory: string,\n callback: (file: string) => Promise<void>,\n options: { pattern: string | string[], limit?: number } = { pattern: '*.*' },\n ): Promise<void> => {\n try {\n let filesProcessed = 0;\n const files = await glob(options.pattern, { cwd: directory, nodir: true });\n for (const file of files) {\n await callback(path.join(directory, file));\n filesProcessed++;\n if (options.limit && filesProcessed >= options.limit) {\n log(`Reached limit of ${options.limit} files, stopping`);\n break;\n }\n }\n } catch (err: any) {\n throw new Error(`Failed to glob pattern ${options.pattern} in ${directory}: ${err.message}`);\n }\n }\n\n const readStream = async (path: string): Promise<fs.ReadStream> => {\n return fs.createReadStream(path);\n }\n\n const hashFile = async (path: string, length: number): Promise<string> => {\n const file = await readFile(path, 'utf8');\n return crypto.createHash('sha256').update(file).digest('hex').slice(0, length);\n }\n\n const listFiles = async (directory: string): Promise<string[]> => {\n return await fs.promises.readdir(directory);\n }\n\n return {\n exists,\n isDirectory,\n isFile,\n isReadable,\n isWritable,\n isFileReadable,\n isDirectoryWritable,\n isDirectoryReadable,\n createDirectory,\n readFile,\n readStream,\n writeFile,\n forEachFileIn,\n hashFile,\n listFiles,\n };\n}"],"names":["create","params","log","console","exists","path","fs","promises","stat","error","isDirectory","stats","isFile","isReadable","access","constants","R_OK","message","stack","isWritable","W_OK","isFileReadable","isDirectoryWritable","isDirectoryReadable","createDirectory","mkdir","recursive","mkdirError","Error","readFile","encoding","writeFile","data","forEachFileIn","directory","callback","options","pattern","filesProcessed","files","glob","cwd","nodir","file","join","limit","err","readStream","createReadStream","hashFile","length","crypto","createHash","update","digest","slice","listFiles","readdir"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAgCO,MAAMA,SAAS,CAACC,MAAAA,GAAAA;;AAGnB,IAAA,MAAMC,GAAMD,GAAAA,MAAAA,CAAOC,GAAG,IAAIC,QAAQD,GAAG;AAErC,IAAA,MAAME,SAAS,OAAOC,IAAAA,GAAAA;QAClB,IAAI;AACA,YAAA,MAAMC,aAAGC,CAAAA,QAAQ,CAACC,IAAI,CAACH,IAAAA,CAAAA;YACvB,OAAO,IAAA;;AAEX,SAAA,CAAE,OAAOI,KAAY,EAAA;YACjB,OAAO,KAAA;AACX;AACJ,KAAA;AAEA,IAAA,MAAMC,cAAc,OAAOL,IAAAA,GAAAA;AACvB,QAAA,M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C,IAAAA,CAAAA;AAC/B,KAAA;IAEA,MAAM4C,QAAAA,GAAW,OAAO5C,IAAc6C,EAAAA,MAAAA,GAAAA;QAClC,MAAMP,IAAAA,GAAO,MAAMd,QAAAA,CAASxB,IAAM,EAAA,MAAA,CAAA;AAClC,QAAA,OAAO8C,MAAOC,CAAAA,UAAU,CAAC,QAAA,CAAA,CAAUC,MAAM,CAACV,IAAMW,CAAAA,CAAAA,MAAM,CAAC,KAAA,CAAA,CAAOC,KAAK,CAAC,CAAGL,EAAAA,MAAAA,CAAAA;AAC3E,KAAA;AAEA,IAAA,MAAMM,YAAY,OAAOtB,SAAAA,GAAAA;AACrB,QAAA,OAAO,MAAM5B,aAAAA,CAAGC,QAAQ,CAACkD,OAAO,CAACvB,SAAAA,CAAAA;AACrC,KAAA;IAEA,OAAO;AACH9B,QAAAA,MAAAA;AACAM,QAAAA,WAAAA;AACAE,QAAAA,MAAAA;AACAC,QAAAA,UAAAA;AACAM,QAAAA,UAAAA;AACAE,QAAAA,cAAAA;AACAC,QAAAA,mBAAAA;AACAC,QAAAA,mBAAAA;AACAC,QAAAA,eAAAA;AACAK,QAAAA,QAAAA;AACAkB,QAAAA,UAAAA;AACAhB,QAAAA,SAAAA;AACAE,QAAAA,aAAAA;AACAgB,QAAAA,QAAAA;AACAO,QAAAA;AACJ,KAAA;AACJ;;;;"}
|
package/dist/util/text.cjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const constants = require('../constants.cjs');
|
|
6
|
-
|
|
7
|
-
// Returns true if the input is likely text, false if likely binary
|
|
8
|
-
function isText(input) {
|
|
9
|
-
let buf;
|
|
10
|
-
if (typeof input === 'string') {
|
|
11
|
-
buf = Buffer.from(input, constants.DEFAULT_CHARACTER_ENCODING);
|
|
12
|
-
} else {
|
|
13
|
-
buf = input;
|
|
14
|
-
}
|
|
15
|
-
// Empty buffers are considered text
|
|
16
|
-
if (buf.length === 0) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
// If the buffer contains null bytes, it's likely binary
|
|
20
|
-
if (buf.includes(0)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
// For UTF-8 encoded text (including emoji and international characters),
|
|
24
|
-
// convert to string first and check if there are non-printable characters
|
|
25
|
-
const str = buf.toString(constants.DEFAULT_CHARACTER_ENCODING);
|
|
26
|
-
// Count the number of non-printable ASCII characters (excluding common whitespace)
|
|
27
|
-
let nonPrintable = 0;
|
|
28
|
-
const len = Math.min(str.length, 512); // Only check the first 512 characters for performance
|
|
29
|
-
for(let i = 0; i < len; i++){
|
|
30
|
-
const charCode = str.charCodeAt(i);
|
|
31
|
-
// Allow: tab (9), line feed (10), carriage return (13), printable ASCII (32-126)
|
|
32
|
-
// Also allow all non-ASCII Unicode characters (charCode > 127)
|
|
33
|
-
if (charCode !== 9 && charCode !== 10 && charCode !== 13 && (charCode < 32 || charCode > 126 && charCode < 128)) {
|
|
34
|
-
nonPrintable++;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// If more than 10% of the checked characters are non-printable, consider it binary
|
|
38
|
-
return nonPrintable / len < 0.1;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
exports.isText = isText;
|
|
42
|
-
//# sourceMappingURL=text.cjs.map
|
package/dist/util/text.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.cjs","sources":["../../src/util/text.ts"],"sourcesContent":["import { DEFAULT_CHARACTER_ENCODING } from \"../constants\";\n\n// Returns true if the input is likely text, false if likely binary\nexport function isText(input: string | Buffer): boolean {\n let buf: Buffer;\n if (typeof input === 'string') {\n buf = Buffer.from(input, DEFAULT_CHARACTER_ENCODING);\n } else {\n buf = input;\n }\n\n // Empty buffers are considered text\n if (buf.length === 0) {\n return true;\n }\n\n // If the buffer contains null bytes, it's likely binary\n if (buf.includes(0)) {\n return false;\n }\n\n // For UTF-8 encoded text (including emoji and international characters),\n // convert to string first and check if there are non-printable characters\n const str = buf.toString(DEFAULT_CHARACTER_ENCODING);\n\n // Count the number of non-printable ASCII characters (excluding common whitespace)\n let nonPrintable = 0;\n const len = Math.min(str.length, 512); // Only check the first 512 characters for performance\n\n for (let i = 0; i < len; i++) {\n const charCode = str.charCodeAt(i);\n // Allow: tab (9), line feed (10), carriage return (13), printable ASCII (32-126)\n // Also allow all non-ASCII Unicode characters (charCode > 127)\n if (\n charCode !== 9 && charCode !== 10 && charCode !== 13 &&\n (charCode < 32 || (charCode > 126 && charCode < 128))\n ) {\n nonPrintable++;\n }\n }\n\n // If more than 10% of the checked characters are non-printable, consider it binary\n return nonPrintable / len < 0.1;\n}\n"],"names":["isText","input","buf","Buffer","from","DEFAULT_CHARACTER_ENCODING","length","includes","str","toString","nonPrintable","len","Math","min","i","charCode","charCodeAt"],"mappings":";;;;;;AAEA;AACO,SAASA,OAAOC,KAAsB,EAAA;IACzC,IAAIC,GAAAA;IACJ,IAAI,OAAOD,UAAU,QAAU,EAAA;QAC3BC,GAAMC,GAAAA,MAAAA,CAAOC,IAAI,CAACH,KAAOI,EAAAA,oCAAAA,CAAAA;KACtB,MAAA;QACHH,GAAMD,GAAAA,KAAAA;AACV;;IAGA,IAAIC,GAAAA,CAAII,MAAM,KAAK,CAAG,EAAA;QAClB,OAAO,IAAA;AACX;;IAGA,IAAIJ,GAAAA,CAAIK,QAAQ,CAAC,CAAI,CAAA,EAAA;QACjB,OAAO,KAAA;AACX;;;IAIA,MAAMC,GAAAA,GAAMN,GAAIO,CAAAA,QAAQ,CAACJ,oCAAAA,CAAAA;;AAGzB,IAAA,IAAIK,YAAe,GAAA,CAAA;IACnB,MAAMC,GAAAA,GAAMC,KAAKC,GAAG,CAACL,IAAIF,MAAM,EAAE;AAEjC,IAAA,IAAK,IAAIQ,CAAAA,GAAI,CAAGA,EAAAA,CAAAA,GAAIH,KAAKG,CAAK,EAAA,CAAA;QAC1B,MAAMC,QAAAA,GAAWP,GAAIQ,CAAAA,UAAU,CAACF,CAAAA,CAAAA;;;AAGhC,QAAA,IACIC,QAAa,KAAA,CAAA,IAAKA,QAAa,KAAA,EAAA,IAAMA,QAAa,KAAA,EAAA,KACjDA,QAAAA,GAAW,EAAOA,IAAAA,QAAAA,GAAW,GAAOA,IAAAA,QAAAA,GAAW,GAAG,CACrD,EAAA;AACEL,YAAAA,YAAAA,EAAAA;AACJ;AACJ;;AAGA,IAAA,OAAOA,eAAeC,GAAM,GAAA,GAAA;AAChC;;;;"}
|