@backstage-community/plugin-copilot-backend 0.7.0 → 0.7.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/CHANGELOG.md
CHANGED
|
@@ -30,29 +30,29 @@ function filterIdeCompletionMetrics(metrics, type, team) {
|
|
|
30
30
|
}
|
|
31
31
|
function filterIdeCompletionLanguageMetrics(metrics, type, team) {
|
|
32
32
|
return metrics.flatMap(
|
|
33
|
-
(metric) => metric.copilot_ide_code_completions.languages
|
|
33
|
+
(metric) => metric.copilot_ide_code_completions.languages?.map((language) => ({
|
|
34
34
|
day: metric.date,
|
|
35
35
|
type,
|
|
36
36
|
team_name: team,
|
|
37
37
|
language: language.name,
|
|
38
38
|
total_engaged_users: language.total_engaged_users
|
|
39
|
-
}))
|
|
39
|
+
})) || []
|
|
40
40
|
).filter((language) => language.total_engaged_users > 0);
|
|
41
41
|
}
|
|
42
42
|
function filterIdeCompletionEditorMetrics(metrics, type, team) {
|
|
43
43
|
return metrics.flatMap(
|
|
44
|
-
(metric) => metric.copilot_ide_code_completions.editors
|
|
44
|
+
(metric) => metric.copilot_ide_code_completions.editors?.map((editor) => ({
|
|
45
45
|
day: metric.date,
|
|
46
46
|
type,
|
|
47
47
|
team_name: team,
|
|
48
48
|
editor: editor.name,
|
|
49
49
|
total_engaged_users: editor.total_engaged_users
|
|
50
|
-
}))
|
|
50
|
+
})) || []
|
|
51
51
|
).filter((editor) => editor.total_engaged_users > 0);
|
|
52
52
|
}
|
|
53
53
|
function filterIdeCompletionEditorModelMetrics(metrics, type, team) {
|
|
54
54
|
return metrics.flatMap(
|
|
55
|
-
(metric) => metric.copilot_ide_code_completions.editors
|
|
55
|
+
(metric) => metric.copilot_ide_code_completions.editors?.flatMap(
|
|
56
56
|
(editor) => editor.models.map((model) => ({
|
|
57
57
|
day: metric.date,
|
|
58
58
|
type,
|
|
@@ -61,12 +61,12 @@ function filterIdeCompletionEditorModelMetrics(metrics, type, team) {
|
|
|
61
61
|
model: model.name,
|
|
62
62
|
total_engaged_users: model.total_engaged_users
|
|
63
63
|
}))
|
|
64
|
-
)
|
|
64
|
+
) || []
|
|
65
65
|
).filter((model) => model.total_engaged_users > 0);
|
|
66
66
|
}
|
|
67
67
|
function filterIdeCompletionEditorModelLanguageMetrics(metrics, type, team) {
|
|
68
68
|
return metrics.flatMap(
|
|
69
|
-
(metric) => metric.copilot_ide_code_completions.editors
|
|
69
|
+
(metric) => metric.copilot_ide_code_completions.editors?.flatMap(
|
|
70
70
|
(editor) => editor.models.flatMap(
|
|
71
71
|
(model) => model.languages.map((language) => ({
|
|
72
72
|
day: metric.date,
|
|
@@ -82,7 +82,7 @@ function filterIdeCompletionEditorModelLanguageMetrics(metrics, type, team) {
|
|
|
82
82
|
total_code_lines_suggested: language.total_code_lines_suggested
|
|
83
83
|
}))
|
|
84
84
|
)
|
|
85
|
-
)
|
|
85
|
+
) || []
|
|
86
86
|
).filter((language) => language.total_engaged_users > 0);
|
|
87
87
|
}
|
|
88
88
|
function filterIdeChatMetrics(metrics, type, team) {
|
|
@@ -95,18 +95,18 @@ function filterIdeChatMetrics(metrics, type, team) {
|
|
|
95
95
|
}
|
|
96
96
|
function filterIdeEditorMetrics(metrics, type, team) {
|
|
97
97
|
return metrics.flatMap(
|
|
98
|
-
(metric) => metric.copilot_ide_chat.editors
|
|
98
|
+
(metric) => metric.copilot_ide_chat.editors?.map((editor) => ({
|
|
99
99
|
day: metric.date,
|
|
100
100
|
type,
|
|
101
101
|
team_name: team,
|
|
102
102
|
editor: editor.name,
|
|
103
103
|
total_engaged_users: editor.total_engaged_users
|
|
104
|
-
}))
|
|
104
|
+
})) || []
|
|
105
105
|
).filter((editor) => editor.total_engaged_users > 0);
|
|
106
106
|
}
|
|
107
107
|
function filterIdeChatEditorModelMetrics(metrics, type, team) {
|
|
108
108
|
return metrics.flatMap(
|
|
109
|
-
(metric) => metric.copilot_ide_chat.editors
|
|
109
|
+
(metric) => metric.copilot_ide_chat.editors?.flatMap(
|
|
110
110
|
(editor) => editor.models.map((model) => ({
|
|
111
111
|
day: metric.date,
|
|
112
112
|
type,
|
|
@@ -118,7 +118,7 @@ function filterIdeChatEditorModelMetrics(metrics, type, team) {
|
|
|
118
118
|
total_chats: model.total_chats,
|
|
119
119
|
total_chat_insertion_events: model.total_chat_insertion_events
|
|
120
120
|
}))
|
|
121
|
-
)
|
|
121
|
+
) || []
|
|
122
122
|
).filter((model) => model.total_engaged_users > 0);
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metricHelpers.cjs.js","sources":["../../src/utils/metricHelpers.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\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 */\nimport { DateTime } from 'luxon';\nimport {\n CopilotIdeChatsDb,\n CopilotIdeChatsEditorModelDb,\n CopilotIdeChatsEditorsDb,\n CopilotIdeCodeCompletionsDb,\n CopilotIdeCodeCompletionsEditorModelLanguagesDb,\n CopilotIdeCodeCompletionsEditorModelsDb,\n CopilotIdeCodeCompletionsEditorsDb,\n CopilotIdeCodeCompletionsLanguageDb,\n CopilotMetricsDb,\n MetricDbRow,\n} from '../db/DatabaseHandler';\nimport {\n Metric,\n MetricsType,\n CopilotMetrics,\n} from '@backstage-community/plugin-copilot-common';\n\nexport function filterNewMetricsV2(\n metrics: CopilotMetrics[],\n lastDay?: string,\n): CopilotMetrics[] {\n return metrics\n .sort(\n (a, b) =>\n DateTime.fromISO(a.date).toMillis() -\n DateTime.fromISO(b.date).toMillis(),\n )\n .filter(metric => {\n const metricDate = DateTime.fromISO(metric.date);\n\n const lastDayDate = lastDay\n ? DateTime.fromJSDate(new Date(lastDay))\n : null;\n\n return !lastDay || (lastDayDate?.isValid && metricDate > lastDayDate);\n });\n}\n\nexport function filterBaseMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotMetricsDb[] {\n return metrics\n .map(metric => ({\n day: metric.date,\n type: type,\n team_name: team,\n total_engaged_users: metric.total_engaged_users,\n total_active_users: metric.total_active_users,\n }))\n .filter(metric => metric.total_engaged_users > 0);\n}\n\nexport function filterIdeCompletionMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsDb[] {\n return metrics\n .map(metric => ({\n day: metric.date,\n type: type,\n team_name: team,\n total_engaged_users:\n metric.copilot_ide_code_completions.total_engaged_users,\n }))\n .filter(completion => completion.total_engaged_users > 0);\n}\n\nexport function filterIdeCompletionLanguageMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsLanguageDb[] {\n return metrics\n .flatMap((metric: CopilotMetrics) =>\n metric.copilot_ide_code_completions.languages.map(language => ({\n day: metric.date,\n type: type,\n team_name: team,\n language: language.name,\n total_engaged_users: language.total_engaged_users,\n })),\n )\n .filter(language => language.total_engaged_users > 0);\n}\nexport function filterIdeCompletionEditorMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsEditorsDb[] {\n return metrics\n .flatMap((metric: CopilotMetrics) =>\n metric.copilot_ide_code_completions.editors.map(editor => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n total_engaged_users: editor.total_engaged_users,\n })),\n )\n .filter(editor => editor.total_engaged_users > 0);\n}\n\nexport function filterIdeCompletionEditorModelMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsEditorModelsDb[] {\n return metrics\n .flatMap((metric: CopilotMetrics) =>\n metric.copilot_ide_code_completions.editors.flatMap(editor =>\n editor.models.map(model => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n model: model.name,\n total_engaged_users: model.total_engaged_users,\n })),\n ),\n )\n .filter(model => model.total_engaged_users > 0);\n}\nexport function filterIdeCompletionEditorModelLanguageMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsEditorModelLanguagesDb[] {\n return metrics\n .flatMap((metric: CopilotMetrics) =>\n metric.copilot_ide_code_completions.editors.flatMap(editor =>\n editor.models.flatMap(model =>\n model.languages.map(language => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n model: model.name,\n language: language.name,\n total_engaged_users: language.total_engaged_users,\n total_code_acceptances: language.total_code_acceptances,\n total_code_suggestions: language.total_code_suggestions,\n total_code_lines_accepted: language.total_code_lines_accepted,\n total_code_lines_suggested: language.total_code_lines_suggested,\n })),\n ),\n ),\n )\n .filter(language => language.total_engaged_users > 0);\n}\n\nexport function filterIdeChatMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeChatsDb[] {\n return metrics\n .map((metric: CopilotMetrics) => ({\n day: metric.date,\n type: type,\n team_name: team,\n total_engaged_users: metric.copilot_ide_chat.total_engaged_users,\n }))\n .filter(chat => chat.total_engaged_users > 0);\n}\n\nexport function filterIdeEditorMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeChatsEditorsDb[] {\n return metrics\n .flatMap((metric: CopilotMetrics) =>\n metric.copilot_ide_chat.editors.map(editor => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n total_engaged_users: editor.total_engaged_users,\n })),\n )\n .filter(editor => editor.total_engaged_users > 0);\n}\n\nexport function filterIdeChatEditorModelMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeChatsEditorModelDb[] {\n return metrics\n .flatMap((metric: CopilotMetrics) =>\n metric.copilot_ide_chat.editors.flatMap(editor =>\n editor.models.map(model => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n model: model.name,\n total_engaged_users: model.total_engaged_users,\n total_chat_copy_events: model.total_chat_copy_events,\n total_chats: model.total_chats,\n total_chat_insertion_events: model.total_chat_insertion_events,\n })),\n ),\n )\n .filter(model => model.total_engaged_users > 0);\n}\n\nexport function prepareMetricsForInsert(\n metrics: Metric[],\n type: MetricsType,\n team_name?: string,\n): MetricDbRow[] {\n return metrics.map(({ breakdown, ...rest }) => ({\n ...rest,\n type,\n team_name,\n breakdown: JSON.stringify(breakdown),\n })) as MetricDbRow[];\n}\n"],"names":["DateTime"],"mappings":";;;;AAkCgB,SAAA,kBAAA,CACd,SACA,OACkB,EAAA;AAClB,EAAA,OAAO,OACJ,CAAA,IAAA;AAAA,IACC,CAAC,CAAA,EAAG,CACF,KAAAA,cAAA,CAAS,QAAQ,CAAE,CAAA,IAAI,CAAE,CAAA,QAAA,KACzBA,cAAS,CAAA,OAAA,CAAQ,CAAE,CAAA,IAAI,EAAE,QAAS;AAAA,GACtC,CACC,OAAO,CAAU,MAAA,KAAA;AAChB,IAAA,MAAM,UAAa,GAAAA,cAAA,CAAS,OAAQ,CAAA,MAAA,CAAO,IAAI,CAAA;AAE/C,IAAM,MAAA,WAAA,GAAc,UAChBA,cAAS,CAAA,UAAA,CAAW,IAAI,IAAK,CAAA,OAAO,CAAC,CACrC,GAAA,IAAA;AAEJ,IAAA,OAAO,CAAC,OAAA,IAAY,WAAa,EAAA,OAAA,IAAW,UAAa,GAAA,WAAA;AAAA,GAC1D,CAAA;AACL;AAEgB,SAAA,iBAAA,CACd,OACA,EAAA,IAAA,EACA,IACoB,EAAA;AACpB,EAAO,OAAA,OAAA,CACJ,IAAI,CAAW,MAAA,MAAA;AAAA,IACd,KAAK,MAAO,CAAA,IAAA;AAAA,IACZ,IAAA;AAAA,IACA,SAAW,EAAA,IAAA;AAAA,IACX,qBAAqB,MAAO,CAAA,mBA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,MAAA,KAAA,MAAA,CAAO,MAAO,CAAA,GAAA,CAAI,CAAU,KAAA,MAAA;AAAA,QAC1B,KAAK,MAAO,CAAA,IAAA;AAAA,QACZ,IAAA;AAAA,QACA,SAAW,EAAA,IAAA;AAAA,QACX,QAAQ,MAAO,CAAA,IAAA;AAAA,QACf,OAAO,KAAM,CAAA,IAAA;AAAA,QACb,qBAAqB,KAAM,CAAA,mBAAA;AAAA,QAC3B,wBAAwB,KAAM,CAAA,sBAAA;AAAA,QAC9B,aAAa,KAAM,CAAA,WAAA;AAAA,QACnB,6BAA6B,KAAM,CAAA;AAAA,OACnC,CAAA;AAAA;AACJ,GAED,CAAA,MAAA,CAAO,CAAS,KAAA,KAAA,KAAA,CAAM,sBAAsB,CAAC,CAAA;AAClD;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"metricHelpers.cjs.js","sources":["../../src/utils/metricHelpers.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\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 */\nimport { DateTime } from 'luxon';\nimport {\n CopilotIdeChatsDb,\n CopilotIdeChatsEditorModelDb,\n CopilotIdeChatsEditorsDb,\n CopilotIdeCodeCompletionsDb,\n CopilotIdeCodeCompletionsEditorModelLanguagesDb,\n CopilotIdeCodeCompletionsEditorModelsDb,\n CopilotIdeCodeCompletionsEditorsDb,\n CopilotIdeCodeCompletionsLanguageDb,\n CopilotMetricsDb,\n MetricDbRow,\n} from '../db/DatabaseHandler';\nimport {\n Metric,\n MetricsType,\n CopilotMetrics,\n} from '@backstage-community/plugin-copilot-common';\n\nexport function filterNewMetricsV2(\n metrics: CopilotMetrics[],\n lastDay?: string,\n): CopilotMetrics[] {\n return metrics\n .sort(\n (a, b) =>\n DateTime.fromISO(a.date).toMillis() -\n DateTime.fromISO(b.date).toMillis(),\n )\n .filter(metric => {\n const metricDate = DateTime.fromISO(metric.date);\n\n const lastDayDate = lastDay\n ? DateTime.fromJSDate(new Date(lastDay))\n : null;\n\n return !lastDay || (lastDayDate?.isValid && metricDate > lastDayDate);\n });\n}\n\nexport function filterBaseMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotMetricsDb[] {\n return metrics\n .map(metric => ({\n day: metric.date,\n type: type,\n team_name: team,\n total_engaged_users: metric.total_engaged_users,\n total_active_users: metric.total_active_users,\n }))\n .filter(metric => metric.total_engaged_users > 0);\n}\n\nexport function filterIdeCompletionMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsDb[] {\n return metrics\n .map(metric => ({\n day: metric.date,\n type: type,\n team_name: team,\n total_engaged_users:\n metric.copilot_ide_code_completions.total_engaged_users,\n }))\n .filter(completion => completion.total_engaged_users > 0);\n}\n\nexport function filterIdeCompletionLanguageMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsLanguageDb[] {\n return metrics\n .flatMap(\n (metric: CopilotMetrics) =>\n metric.copilot_ide_code_completions.languages?.map(language => ({\n day: metric.date,\n type: type,\n team_name: team,\n language: language.name,\n total_engaged_users: language.total_engaged_users,\n })) || [],\n )\n .filter(language => language.total_engaged_users > 0);\n}\nexport function filterIdeCompletionEditorMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsEditorsDb[] {\n return metrics\n .flatMap(\n (metric: CopilotMetrics) =>\n metric.copilot_ide_code_completions.editors?.map(editor => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n total_engaged_users: editor.total_engaged_users,\n })) || [],\n )\n .filter(editor => editor.total_engaged_users > 0);\n}\n\nexport function filterIdeCompletionEditorModelMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsEditorModelsDb[] {\n return metrics\n .flatMap(\n (metric: CopilotMetrics) =>\n metric.copilot_ide_code_completions.editors?.flatMap(editor =>\n editor.models.map(model => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n model: model.name,\n total_engaged_users: model.total_engaged_users,\n })),\n ) || [],\n )\n .filter(model => model.total_engaged_users > 0);\n}\nexport function filterIdeCompletionEditorModelLanguageMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeCodeCompletionsEditorModelLanguagesDb[] {\n return metrics\n .flatMap(\n (metric: CopilotMetrics) =>\n metric.copilot_ide_code_completions.editors?.flatMap(editor =>\n editor.models.flatMap(model =>\n model.languages.map(language => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n model: model.name,\n language: language.name,\n total_engaged_users: language.total_engaged_users,\n total_code_acceptances: language.total_code_acceptances,\n total_code_suggestions: language.total_code_suggestions,\n total_code_lines_accepted: language.total_code_lines_accepted,\n total_code_lines_suggested: language.total_code_lines_suggested,\n })),\n ),\n ) || [],\n )\n .filter(language => language.total_engaged_users > 0);\n}\n\nexport function filterIdeChatMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeChatsDb[] {\n return metrics\n .map((metric: CopilotMetrics) => ({\n day: metric.date,\n type: type,\n team_name: team,\n total_engaged_users: metric.copilot_ide_chat.total_engaged_users,\n }))\n .filter(chat => chat.total_engaged_users > 0);\n}\n\nexport function filterIdeEditorMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeChatsEditorsDb[] {\n return metrics\n .flatMap(\n (metric: CopilotMetrics) =>\n metric.copilot_ide_chat.editors?.map(editor => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n total_engaged_users: editor.total_engaged_users,\n })) || [],\n )\n .filter(editor => editor.total_engaged_users > 0);\n}\n\nexport function filterIdeChatEditorModelMetrics(\n metrics: CopilotMetrics[],\n type: MetricsType,\n team?: string,\n): CopilotIdeChatsEditorModelDb[] {\n return metrics\n .flatMap(\n (metric: CopilotMetrics) =>\n metric.copilot_ide_chat.editors?.flatMap(editor =>\n editor.models.map(model => ({\n day: metric.date,\n type: type,\n team_name: team,\n editor: editor.name,\n model: model.name,\n total_engaged_users: model.total_engaged_users,\n total_chat_copy_events: model.total_chat_copy_events,\n total_chats: model.total_chats,\n total_chat_insertion_events: model.total_chat_insertion_events,\n })),\n ) || [],\n )\n .filter(model => model.total_engaged_users > 0);\n}\n\nexport function prepareMetricsForInsert(\n metrics: Metric[],\n type: MetricsType,\n team_name?: string,\n): MetricDbRow[] {\n return metrics.map(({ breakdown, ...rest }) => ({\n ...rest,\n type,\n team_name,\n breakdown: JSON.stringify(breakdown),\n })) as MetricDbRow[];\n}\n"],"names":["DateTime"],"mappings":";;;;AAkCgB,SAAA,kBAAA,CACd,SACA,OACkB,EAAA;AAClB,EAAA,OAAO,OACJ,CAAA,IAAA;AAAA,IACC,CAAC,CAAA,EAAG,CACF,KAAAA,cAAA,CAAS,QAAQ,CAAE,CAAA,IAAI,CAAE,CAAA,QAAA,KACzBA,cAAS,CAAA,OAAA,CAAQ,CAAE,CAAA,IAAI,EAAE,QAAS;AAAA,GACtC,CACC,OAAO,CAAU,MAAA,KAAA;AAChB,IAAA,MAAM,UAAa,GAAAA,cAAA,CAAS,OAAQ,CAAA,MAAA,CAAO,IAAI,CAAA;AAE/C,IAAM,MAAA,WAAA,GAAc,UAChBA,cAAS,CAAA,UAAA,CAAW,IAAI,IAAK,CAAA,OAAO,CAAC,CACrC,GAAA,IAAA;AAEJ,IAAA,OAAO,CAAC,OAAA,IAAY,WAAa,EAAA,OAAA,IAAW,UAAa,GAAA,WAAA;AAAA,GAC1D,CAAA;AACL;AAEgB,SAAA,iBAAA,CACd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