@aglyn/plugins-ai 1.6.0 → 1.7.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.
- package/README.md +2 -2
- package/package.json +17 -17
- package/src/lib/components/ai-insight-dialog.component.js +14 -0
- package/src/lib/components/ai-insight-dialog.component.js.map +1 -1
- package/src/lib/insights/ai-figure-readers.d.ts +13 -0
- package/src/lib/insights/ai-figure-readers.js +158 -11
- package/src/lib/insights/ai-figure-readers.js.map +1 -1
- package/src/lib/insights/ai-figure-summaries.js +4 -2
- package/src/lib/insights/ai-figure-summaries.js.map +1 -1
- package/src/lib/insights/ai-insight-digest.d.ts +27 -17
- package/src/lib/insights/ai-insight-digest.js +96 -107
- package/src/lib/insights/ai-insight-digest.js.map +1 -1
- package/src/lib/jobs/ai-job-insight-budget.d.ts +19 -3
- package/src/lib/jobs/ai-job-insight-budget.js +18 -4
- package/src/lib/jobs/ai-job-insight-budget.js.map +1 -1
- package/src/lib/jobs/ai-job-insight-step.d.ts +2 -2
- package/src/lib/jobs/ai-job-insight-step.js +17 -7
- package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
- package/src/lib/model/ai-insight.d.ts +23 -3
- package/src/lib/model/ai-insight.js +17 -3
- package/src/lib/model/ai-insight.js.map +1 -1
- package/src/lib/providers/routing.js +3 -1
- package/src/lib/providers/routing.js.map +1 -1
- package/src/lib/runtime/ai-insight-check.d.ts +7 -0
- package/src/lib/runtime/ai-insight-check.js +111 -27
- package/src/lib/runtime/ai-insight-check.js.map +1 -1
- package/src/lib/tools/ai-insight-tool.js +45 -2
- package/src/lib/tools/ai-insight-tool.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/tools/ai-insight-tool.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AI_INSIGHT_GAP_MAX_CHARS,\n AI_INSIGHT_HEADLINE_MAX_CHARS,\n AI_INSIGHT_MAX_CHARS,\n AI_INSIGHT_MAX_CITED_ROWS,\n AI_INSIGHT_MAX_CITES,\n AI_INSIGHT_MAX_INSIGHTS,\n AI_INSIGHT_MAX_READS,\n type AiInsightAnswer,\n} from '../model/ai-insight'\nimport type { AiTool } from '../providers/contract'\n\n/**\n * The two strict tools an insight job answers through (AGL-2915).\n *\n * `read_figures` names readers — an id, a window and the reader's own\n * parameters — and nothing else: the model never writes a query, a field\n * path or a filter of its own, only a choice among the readers the request\n * lists. `submit_insights` is the answer, each insight citing the table rows\n * its figures come from. Lengths and counts are stated in the descriptions,\n * as the platform's other strict tools state them; the step holds every one.\n */\n\nexport const AI_INSIGHT_READ_TOOL_NAME = 'read_figures'\nexport const AI_INSIGHT_ANSWER_TOOL_NAME = 'submit_insights'\n\nexport function aiInsightReadTool(): AiTool {\n return {\n name: AI_INSIGHT_READ_TOOL_NAME,\n description:\n `Choose the readers whose tables answer the question: at most ${AI_INSIGHT_MAX_READS}, ` +\n 'each from the list the request gives. Every field is required.',\n strict: true,\n inputSchema: {\n type: 'object',\n properties: {\n reads: {\n type: 'array',\n description: `The readers to read, most useful first; at most ${AI_INSIGHT_MAX_READS}.`,\n items: {\n type: 'object',\n properties: {\n reader: { type: 'string', description: 'A reader id from the list, exactly as written.' },\n days: {\n type: 'integer',\n description: 'One of the windows that reader lists, in days; 0 for a reader that lists none.',\n },\n params: {\n type: 'array',\n description: 'The parameters that reader lists, by name; empty when it lists none.',\n items: {\n type: 'object',\n properties: {\n name: { type: 'string' },\n value: { type: 'string' },\n },\n required: ['name', 'value'],\n additionalProperties: false,\n },\n },\n },\n required: ['reader', 'days', 'params'],\n additionalProperties: false,\n },\n },\n },\n required: ['reads'],\n additionalProperties: false,\n },\n }\n}\n\nexport function aiInsightAnswerTool(): AiTool {\n return {\n name: AI_INSIGHT_ANSWER_TOOL_NAME,\n description:\n `Answer with at most ${AI_INSIGHT_MAX_INSIGHTS} insights, each citing the table rows its figures come from. ` +\n 'Every field is required.',\n strict: true,\n inputSchema: {\n type: 'object',\n properties: {\n insights: {\n type: 'array',\n description: `Most useful first; at most ${AI_INSIGHT_MAX_INSIGHTS}.`,\n items: {\n type: 'object',\n properties: {\n headline: {\n type: 'string',\n description: `What happened, in a few words, with no full stop; at most ${AI_INSIGHT_HEADLINE_MAX_CHARS} characters.`,\n },\n text: {\n type: 'string',\n description: `Why it matters, in one or two plain sentences that do not repeat the headline; at most ${AI_INSIGHT_MAX_CHARS} characters.`,\n },\n cites: {\n type: 'array',\n description: `The tables and rows its figures come from; at most ${AI_INSIGHT_MAX_CITES} tables.`,\n items: {\n type: 'object',\n properties: {\n table: { type: 'string', description: 'The table handle: t1, t2, …' },\n rows: {\n type: 'array',\n description: `Row numbers as the table numbers them, from 0; at most ${AI_INSIGHT_MAX_CITED_ROWS}.`,\n items: { type: 'integer' },\n },\n },\n required: ['table', 'rows'],\n additionalProperties: false,\n },\n },\n },\n required: ['headline', 'text', 'cites'],\n additionalProperties: false,\n },\n },\n gap: {\n anyOf: [{ type: 'string' }, { type: 'null' }],\n description: `What the tables cannot answer, in one sentence without numbers; at most ${AI_INSIGHT_GAP_MAX_CHARS} characters. null when nothing.`,\n },\n },\n required: ['insights', 'gap'],\n additionalProperties: false,\n },\n }\n}\n\n/** One reader the model asked for, as it asked. */\nexport interface AiInsightReadRequest {\n reader: string\n days: number\n params: Record<string, string>\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/** The reads a `read_figures` call names, shape-checked and bounded; the step decides which are real. */\nexport function parseAiInsightReads(input: unknown): AiInsightReadRequest[] {\n const reads = isRecord(input) && Array.isArray(input['reads']) ? input['reads'] : []\n const parsed: AiInsightReadRequest[] = []\n for (const raw of reads) {\n if (parsed.length === AI_INSIGHT_MAX_READS) break\n if (!isRecord(raw) || typeof raw['reader'] !== 'string') continue\n const params: Record<string, string> = {}\n for (const pair of Array.isArray(raw['params']) ? raw['params'] : []) {\n if (isRecord(pair) && typeof pair['name'] === 'string' && typeof pair['value'] === 'string') {\n params[pair['name']] = pair['value']\n }\n }\n const days = Number(raw['days'])\n parsed.push({\n reader: raw['reader'].trim(),\n days: Number.isInteger(days) && days >= 0 ? days : 0,\n params,\n })\n }\n return parsed\n}\n\n/**\n * A `submit_insights` call as the trace reads it, or `null` when the call is\n * not an answer at all. Values keep the types the model wrote, so the trace\n * — not this reader — decides what an unreadable citation costs.\n */\nexport function parseAiInsightAnswer(input: unknown): AiInsightAnswer | null {\n if (!isRecord(input) || !Array.isArray(input['insights'])) return null\n const insights = input['insights']\n .filter(isRecord)\n .map((raw) => ({\n ...(typeof raw['headline'] === 'string' ? { headline: raw['headline'] } : {}),\n text: typeof raw['text'] === 'string' ? raw['text'] : '',\n cites: (Array.isArray(raw['cites']) ? raw['cites'] : []).filter(isRecord).map((cite) => ({\n table: typeof cite['table'] === 'string' ? cite['table'] : '',\n rows: (Array.isArray(cite['rows']) ? cite['rows'] : []) as number[],\n })),\n }))\n const gap = typeof input['gap'] === 'string' ? input['gap'] : null\n return { insights, gap }\n}\n"],"names":["AI_INSIGHT_GAP_MAX_CHARS","AI_INSIGHT_HEADLINE_MAX_CHARS","AI_INSIGHT_MAX_CHARS","AI_INSIGHT_MAX_CITED_ROWS","AI_INSIGHT_MAX_CITES","AI_INSIGHT_MAX_INSIGHTS","AI_INSIGHT_MAX_READS","AI_INSIGHT_READ_TOOL_NAME","AI_INSIGHT_ANSWER_TOOL_NAME","aiInsightReadTool","name","description","strict","inputSchema","type","properties","reads","items","reader","days","params","value","required","additionalProperties","aiInsightAnswerTool","insights","headline","text","cites","table","rows","gap","anyOf","isRecord","Array","isArray","parseAiInsightReads","input","parsed","raw","length","pair","Number","push","trim","isInteger","parseAiInsightAnswer","filter","map","cite"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,6BAA6B,EAC7BC,oBAAoB,EACpBC,yBAAyB,EACzBC,oBAAoB,EACpBC,uBAAuB,EACvBC,oBAAoB,QAEf,yBAAqB;AAG5B;;;;;;;;;CASC,GAED,OAAO,MAAMC,4BAA4B,eAAc;AACvD,OAAO,MAAMC,8BAA8B,kBAAiB;AAE5D,OAAO,SAASC;IACd,OAAO;QACLC,MAAMH;QACNI,aACE,CAAC,6DAA6D,EAAEL,qBAAqB,EAAE,CAAC,GACxF;QACFM,QAAQ;QACRC,aAAa;YACXC,MAAM;YACNC,YAAY;gBACVC,OAAO;oBACLF,MAAM;oBACNH,aAAa,CAAC,gDAAgD,EAAEL,qBAAqB,CAAC,CAAC;oBACvFW,OAAO;wBACLH,MAAM;wBACNC,YAAY;4BACVG,QAAQ;gCAAEJ,MAAM;gCAAUH,aAAa;4BAAiD;4BACxFQ,MAAM;gCACJL,MAAM;gCACNH,aAAa;4BACf;4BACAS,QAAQ;gCACNN,MAAM;gCACNH,aAAa;gCACbM,OAAO;oCACLH,MAAM;oCACNC,YAAY;wCACVL,MAAM;4CAAEI,MAAM;wCAAS;wCACvBO,OAAO;4CAAEP,MAAM;wCAAS;oCAC1B;oCACAQ,UAAU;wCAAC;wCAAQ;qCAAQ;oCAC3BC,sBAAsB;gCACxB;4BACF;wBACF;wBACAD,UAAU;4BAAC;4BAAU;4BAAQ;yBAAS;wBACtCC,sBAAsB;oBACxB;gBACF;YACF;YACAD,UAAU;gBAAC;aAAQ;YACnBC,sBAAsB;QACxB;IACF;AACF;AAEA,OAAO,SAASC;IACd,OAAO;QACLd,MAAMF;QACNG,aACE,CAAC,oBAAoB,EAAEN,wBAAwB,6DAA6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OAAO,CAACI,GAAG,CAAC,QAAQ,IAAIA,GAAG,CAAC,QAAQ,GAAG,EAAE,AAAD,EAAGQ,MAAM,CAACd,UAAUe,GAAG,CAAC,CAACC,OAAU,CAAA;oBACvFpB,OAAO,OAAOoB,IAAI,CAAC,QAAQ,KAAK,WAAWA,IAAI,CAAC,QAAQ,GAAG;oBAC3DnB,MAAOI,MAAMC,OAAO,CAACc,IAAI,CAAC,OAAO,IAAIA,IAAI,CAAC,OAAO,GAAG,EAAE;gBACxD,CAAA;;IAEJ,MAAMlB,MAAM,OAAOM,KAAK,CAAC,MAAM,KAAK,WAAWA,KAAK,CAAC,MAAM,GAAG;IAC9D,OAAO;QAAEZ;QAAUM;IAAI;AACzB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/tools/ai-insight-tool.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AI_INSIGHT_GAP_MAX_CHARS,\n AI_INSIGHT_HEADLINE_MAX_CHARS,\n AI_INSIGHT_NEXT_MAX_CHARS,\n AI_INSIGHT_OVERVIEW_MAX_CHARS,\n AI_INSIGHT_WHY_MAX_CHARS,\n AI_INSIGHT_MAX_CHARS,\n AI_INSIGHT_MAX_CITED_ROWS,\n AI_INSIGHT_MAX_CITES,\n AI_INSIGHT_MAX_INSIGHTS,\n AI_INSIGHT_MAX_READS,\n type AiInsightAnswer,\n} from '../model/ai-insight'\nimport type { AiTool } from '../providers/contract'\n\n/**\n * The two strict tools an insight job answers through (AGL-2915).\n *\n * `read_figures` names readers — an id, a window and the reader's own\n * parameters — and nothing else: the model never writes a query, a field\n * path or a filter of its own, only a choice among the readers the request\n * lists. `submit_insights` is the answer, each insight citing the table rows\n * its figures come from. Lengths and counts are stated in the descriptions,\n * as the platform's other strict tools state them; the step holds every one.\n */\n\nexport const AI_INSIGHT_READ_TOOL_NAME = 'read_figures'\nexport const AI_INSIGHT_ANSWER_TOOL_NAME = 'submit_insights'\n\nexport function aiInsightReadTool(): AiTool {\n return {\n name: AI_INSIGHT_READ_TOOL_NAME,\n description:\n `Choose the readers whose tables answer the question: at most ${AI_INSIGHT_MAX_READS}, ` +\n 'each from the list the request gives. Every field is required.',\n strict: true,\n inputSchema: {\n type: 'object',\n properties: {\n reads: {\n type: 'array',\n description: `The readers to read, most useful first; at most ${AI_INSIGHT_MAX_READS}.`,\n items: {\n type: 'object',\n properties: {\n reader: { type: 'string', description: 'A reader id from the list, exactly as written.' },\n days: {\n type: 'integer',\n description: 'One of the windows that reader lists, in days; 0 for a reader that lists none.',\n },\n params: {\n type: 'array',\n description: 'The parameters that reader lists, by name; empty when it lists none.',\n items: {\n type: 'object',\n properties: {\n name: { type: 'string' },\n value: { type: 'string' },\n },\n required: ['name', 'value'],\n additionalProperties: false,\n },\n },\n },\n required: ['reader', 'days', 'params'],\n additionalProperties: false,\n },\n },\n },\n required: ['reads'],\n additionalProperties: false,\n },\n }\n}\n\nexport function aiInsightAnswerTool(): AiTool {\n return {\n name: AI_INSIGHT_ANSWER_TOOL_NAME,\n description:\n `Answer with at most ${AI_INSIGHT_MAX_INSIGHTS} insights, each citing the table rows its figures come from. ` +\n 'Every field is required.',\n strict: true,\n inputSchema: {\n type: 'object',\n properties: {\n overview: {\n anyOf: [{ type: 'string' }, { type: 'null' }],\n description: `A weekly digest only: what the week meant, in two or three sentences of your own; at most ${AI_INSIGHT_OVERVIEW_MAX_CHARS} characters. null on a question.`,\n },\n insights: {\n type: 'array',\n description: `Most useful first; at most ${AI_INSIGHT_MAX_INSIGHTS}.`,\n items: {\n type: 'object',\n properties: {\n headline: {\n type: 'string',\n description: `What happened, in a few words, with no full stop; at most ${AI_INSIGHT_HEADLINE_MAX_CHARS} characters.`,\n },\n text: {\n type: 'string',\n description: `Why it matters, in one or two plain sentences that do not repeat the headline; at most ${AI_INSIGHT_MAX_CHARS} characters.`,\n },\n why: {\n anyOf: [{ type: 'string' }, { type: 'null' }],\n description: `What most likely drove it, resting on a row you cite from the changes, sources or campaigns table; at most ${AI_INSIGHT_WHY_MAX_CHARS} characters. null when nothing there explains it.`,\n },\n next: {\n anyOf: [{ type: 'string' }, { type: 'null' }],\n description: `One concrete step the owner can take; at most ${AI_INSIGHT_NEXT_MAX_CHARS} characters. null when none fits.`,\n },\n cites: {\n type: 'array',\n description: `The tables and rows its figures come from; at most ${AI_INSIGHT_MAX_CITES} tables.`,\n items: {\n type: 'object',\n properties: {\n table: { type: 'string', description: 'The table handle: t1, t2, …' },\n rows: {\n type: 'array',\n description: `Row numbers as the table numbers them, from 0; at most ${AI_INSIGHT_MAX_CITED_ROWS}.`,\n items: { type: 'integer' },\n },\n },\n required: ['table', 'rows'],\n additionalProperties: false,\n },\n },\n },\n required: ['headline', 'text', 'why', 'next', 'cites'],\n additionalProperties: false,\n },\n },\n gap: {\n anyOf: [{ type: 'string' }, { type: 'null' }],\n description: `What the tables cannot answer, in one sentence without numbers; at most ${AI_INSIGHT_GAP_MAX_CHARS} characters. null when nothing.`,\n },\n },\n required: ['overview', 'insights', 'gap'],\n additionalProperties: false,\n },\n }\n}\n\n/** One reader the model asked for, as it asked. */\nexport interface AiInsightReadRequest {\n reader: string\n days: number\n params: Record<string, string>\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/** The reads a `read_figures` call names, shape-checked and bounded; the step decides which are real. */\nexport function parseAiInsightReads(input: unknown): AiInsightReadRequest[] {\n const reads = isRecord(input) && Array.isArray(input['reads']) ? input['reads'] : []\n const parsed: AiInsightReadRequest[] = []\n for (const raw of reads) {\n if (parsed.length === AI_INSIGHT_MAX_READS) break\n if (!isRecord(raw) || typeof raw['reader'] !== 'string') continue\n const params: Record<string, string> = {}\n for (const pair of Array.isArray(raw['params']) ? raw['params'] : []) {\n if (isRecord(pair) && typeof pair['name'] === 'string' && typeof pair['value'] === 'string') {\n params[pair['name']] = pair['value']\n }\n }\n const days = Number(raw['days'])\n parsed.push({\n reader: raw['reader'].trim(),\n days: Number.isInteger(days) && days >= 0 ? days : 0,\n params,\n })\n }\n return parsed\n}\n\n/**\n * A `submit_insights` call as the trace reads it, or `null` when the call is\n * not an answer at all. Values keep the types the model wrote, so the trace\n * — not this reader — decides what an unreadable citation costs.\n */\nexport function parseAiInsightAnswer(input: unknown): AiInsightAnswer | null {\n if (!isRecord(input) || !Array.isArray(input['insights'])) return null\n const insights = input['insights']\n .filter(isRecord)\n .map((raw) => ({\n ...(typeof raw['headline'] === 'string' ? { headline: raw['headline'] } : {}),\n text: typeof raw['text'] === 'string' ? raw['text'] : '',\n ...(typeof raw['why'] === 'string' ? { why: raw['why'] } : {}),\n ...(typeof raw['next'] === 'string' ? { next: raw['next'] } : {}),\n cites: (Array.isArray(raw['cites']) ? raw['cites'] : []).filter(isRecord).map((cite) => ({\n table: typeof cite['table'] === 'string' ? cite['table'] : '',\n rows: (Array.isArray(cite['rows']) ? cite['rows'] : []) as number[],\n })),\n }))\n const gap = typeof input['gap'] === 'string' ? input['gap'] : null\n const overview = typeof input['overview'] === 'string' ? input['overview'] : null\n return { overview, insights, gap }\n}\n"],"names":["AI_INSIGHT_GAP_MAX_CHARS","AI_INSIGHT_HEADLINE_MAX_CHARS","AI_INSIGHT_NEXT_MAX_CHARS","AI_INSIGHT_OVERVIEW_MAX_CHARS","AI_INSIGHT_WHY_MAX_CHARS","AI_INSIGHT_MAX_CHARS","AI_INSIGHT_MAX_CITED_ROWS","AI_INSIGHT_MAX_CITES","AI_INSIGHT_MAX_INSIGHTS","AI_INSIGHT_MAX_READS","AI_INSIGHT_READ_TOOL_NAME","AI_INSIGHT_ANSWER_TOOL_NAME","aiInsightReadTool","name","description","strict","inputSchema","type","properties","reads","items","reader","days","params","value","required","additionalProperties","aiInsightAnswerTool","overview","anyOf","insights","headline","text","why","next","cites","table","rows","gap","isRecord","Array","isArray","parseAiInsightReads","input","parsed","raw","length","pair","Number","push","trim","isInteger","parseAiInsightAnswer","filter","map","cite"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,6BAA6B,EAC7BC,yBAAyB,EACzBC,6BAA6B,EAC7BC,wBAAwB,EACxBC,oBAAoB,EACpBC,yBAAyB,EACzBC,oBAAoB,EACpBC,uBAAuB,EACvBC,oBAAoB,QAEf,yBAAqB;AAG5B;;;;;;;;;CASC,GAED,OAAO,MAAMC,4BAA4B,eAAc;AACvD,OAAO,MAAMC,8BAA8B,kBAAiB;AAE5D,OAAO,SAASC;IACd,OAAO;QACLC,MAAMH;QACNI,aACE,CAAC,6DAA6D,EAAEL,qBAAqB,EAAE,CAAC,GACxF;QACFM,QAAQ;QACRC,aAAa;YACXC,MAAM;YACNC,YAAY;gBACVC,OAAO;oBACLF,MAAM;oBACNH,aAAa,CAAC,gDAAgD,EAAEL,qBAAqB,CAAC,CAAC;oBACvFW,OAAO;wBACLH,MAAM;wBACNC,YAAY;4BACVG,QAAQ;gCAAEJ,MAAM;gCAAUH,aAAa;4BAAiD;4BACxFQ,MAAM;gCACJL,MAAM;gCACNH,aAAa;4BACf;4BACAS,QAAQ;gCACNN,MAAM;gCACNH,aAAa;gCACbM,OAAO;oCACLH,MAAM;oCACNC,YAAY;wCACVL,MAAM;4CAAEI,MAAM;wCAAS;wCACvBO,OAAO;4CAAEP,MAAM;wCAAS;oCAC1B;oCACAQ,UAAU;wCAAC;wCAAQ;qCAAQ;oCAC3BC,sBAAsB;gCACxB;4BACF;wBACF;wBACAD,UAAU;4BAAC;4BAAU;4BAAQ;yBAAS;wBACtCC,sBAAsB;oBACxB;gBACF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