Update Detect Log By AI

This commit is contained in:
nguyentrungthat 2026-05-06 13:57:02 +07:00
parent 1ae7550d77
commit dd6d4047e0
5 changed files with 74 additions and 73 deletions

View File

@ -11,15 +11,9 @@ export default class PromptAi extends BaseModel {
@column() @column()
declare content: string declare content: string
@column()
declare description: string | null
@column() @column()
declare type: string declare type: string
@column()
declare is_active: boolean
@column.dateTime({ autoCreate: true }) @column.dateTime({ autoCreate: true })
declare createdAt: DateTime declare createdAt: DateTime

View File

@ -606,7 +606,7 @@ export default class LineConnection {
lineNumber: this.config.lineNumber, lineNumber: this.config.lineNumber,
inventory: this.config.inventory, inventory: this.config.inventory,
latestScenario: { latestScenario: {
detectAI: detectLog, detectAI: { issue: detectLog, summary: '', status: [] },
}, },
data, data,
}) })
@ -629,7 +629,10 @@ export default class LineConnection {
// } // }
if (this.config.latestScenario) if (this.config.latestScenario)
this.config.latestScenario = { ...this.config.latestScenario, detectAI: detectLog } this.config.latestScenario = {
...this.config.latestScenario,
detectAI: { issue: detectLog, summary: '', status: [] },
}
// if (result.sn) { // if (result.sn) {
// this.updateNote(result.sn, result) // this.updateNote(result.sn, result)
// } // }
@ -896,7 +899,11 @@ export default class LineConnection {
messages: [ messages: [
{ {
role: 'user', role: 'user',
content: promptRecord + "\n Here's the log:\n" + log, content: `${promptRecord.content}
Return ONLY a valid JSON array of strings.
Here is the log:
${log}`,
}, },
], ],
} }
@ -1283,7 +1290,7 @@ Ports Missing/Down: ${missing.length}\n\n`
await this.sleep(3000) await this.sleep(3000)
this.writeCommand(' show interfaces status\r\n') this.writeCommand(' show interfaces status\r\n')
this.writeCommand(' \r\n') this.writeCommand(' \r\n')
await this.sleep(4000) await this.sleep(6000)
const statusOutput = this.outputPhysicalTest const statusOutput = this.outputPhysicalTest
this.outputPhysicalTest = '' this.outputPhysicalTest = ''
const lines = statusOutput.split('\n') const lines = statusOutput.split('\n')
@ -1332,7 +1339,7 @@ Ports Missing/Down: ${missing.length}\n\n`
${reason}` ${reason}`
: '' : ''
await sendMessageToMail( await sendMessageToMail(
`[ATC] - [${this.config.stationName} - Line: ${this.config.lineNumber}] - Physical Ports Test`, `[ATC] - [${this.config.stationName} - Line: ${this.config.lineNumber}] - [${this.config.inventory?.pid}] - [${this.config.inventory?.sn}] - Physical Ports Test`,
formReport + reasonSkipPhysical formReport + reasonSkipPhysical
) )
} }
@ -1708,7 +1715,11 @@ Ports Missing/Down: ${missing.length}\n\n`
messages: [ messages: [
{ {
role: 'user', role: 'user',
content: promptRecord + "\n Here's the log:\n" + log, content: `${promptRecord.content}
Return ONLY a valid JSON array of strings.
Here is the log:
${log}`,
}, },
], ],
} }
@ -1844,8 +1855,7 @@ Ports Missing/Down: ${missing.length}\n\n`
?.join(', ') ?.join(', ')
: '' : ''
}</b><br/> }</b><br/>
Summary: <b style="color: ${!summary?.includes('No hardware issues found') ? '#ff0000' : ''};">${summary}</b><br/> Detect from AI: <b style="color: 'black';">${issue?.length ? `<br>- ` + issue.join(`<br>`) : 'No issues detected.'}</b><br/>
Issues: <b style="color: ${issue.filter((el) => !el.includes('No issues detected')).length ? '#ff0000' : 'black'};">${issue?.length ? `<br>- ` + issue.join(`<br>- `) : 'No issues detected.'}</b><br/>
</td> </td>
<td> <td>
Total Ports: ${portPhysical?.length}<br/> Total Ports: ${portPhysical?.length}<br/>
@ -1875,7 +1885,7 @@ Ports Missing/Down: ${missing.length}\n\n`
this.updateNote(config?.inventory?.sn, this.dataDPELP as DataDPELP) this.updateNote(config?.inventory?.sn, this.dataDPELP as DataDPELP)
await sendMessageToMail( await sendMessageToMail(
`[ATC] - [${config.stationName} - Line: ${config.lineNumber}] - Summary of Testing Results`, `[ATC] - [${config.stationName} - Line: ${config.lineNumber}] - [${this.config.inventory?.pid}] - [${this.config.inventory?.sn}] - Summary of Testing Results`,
body body
) )
this.socketIO.emit('summary_tested', { this.socketIO.emit('summary_tested', {

View File

@ -11,13 +11,13 @@ import ConfigRam from '#models/config_ram'
import Keyword from '#models/keywords' import Keyword from '#models/keywords'
const mailTo = 'andrew.ng@apactech.io' const mailTo = 'andrew.ng@apactech.io'
const mailCC = [ // const mailCC = [
'ips@ipsupply.com.au', // 'ips@ipsupply.com.au',
'kay@ipsupply.com.au', // 'kay@ipsupply.com.au',
'joseph@apactech.io', // 'joseph@apactech.io',
'kiet.phan@apactech.io', // 'kiet.phan@apactech.io',
] // ]
// const mailCC = '' const mailCC = ''
type DetectAI = { type DetectAI = {
status: string[] status: string[]
@ -225,11 +225,8 @@ export function mapToLineFormat(input: InputData) {
// const mode = dataPlatform && !dataPlatform.output?.includes('Incomplete') ? 'DPELP' : 'DPEL' // const mode = dataPlatform && !dataPlatform.output?.includes('Incomplete') ? 'DPELP' : 'DPEL'
// Issues // Issues
const issues = Array.isArray(input.latestScenario?.detectAI?.issue) const issues = Array.isArray(input.latestScenario?.detectAI) ? input.latestScenario?.detectAI : []
? input.latestScenario.detectAI.issue
: input.latestScenario?.detectAI?.issue
? [input.latestScenario.detectAI.issue]
: []
// Issues // Issues
const summary = input.latestScenario?.detectAI?.summary || '' const summary = input.latestScenario?.detectAI?.summary || ''

View File

@ -668,10 +668,10 @@ export class WebSocketIo {
const linkWiki = const linkWiki =
process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test' process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test'
try { try {
await axios.post(linkWiki, { // await axios.post(linkWiki, {
data: tableHTML, // data: tableHTML,
titleAuto: `[${scenarioName || 'DPELP'}] - ${stationName} - ` + dataFormat, // titleAuto: `[${scenarioName || 'DPELP'}] - ${stationName} - ` + dataFormat,
}) // })
} catch (error) { } catch (error) {
console.error('Error sending wiki message:', error) console.error('Error sending wiki message:', error)
} }
@ -684,16 +684,16 @@ export class WebSocketIo {
console.error('Error sending mail:', error) console.error('Error sending mail:', error)
} }
try { try {
const contentZulip = // const contentZulip =
`\n\n---\n**[${scenarioName || 'DPELP'}] - ${stationName} - ${dataFormat}**\n\n` + // `\n\n---\n**[${scenarioName || 'DPELP'}] - ${stationName} - ${dataFormat}**\n\n` +
zulipMess // zulipMess
await sendMessageToZulip( // await sendMessageToZulip(
'stream', // 'stream',
streamZulip || 'ATC_Report', // streamZulip || 'ATC_Report',
topicZulip, // topicZulip,
contentZulip // contentZulip
) // )
await sendMessageToZulip('stream', 'ATC_Report', station.name, contentZulip) // await sendMessageToZulip('stream', 'ATC_Report', station.name, contentZulip)
} catch (error) { } catch (error) {
console.error('Error sending zulip message:', error) console.error('Error sending zulip message:', error)
} }

View File

@ -177,7 +177,7 @@ const ModalTerminal = ({
const data = const data =
line?.latestScenario?.detectAI?.issue && line?.latestScenario?.detectAI?.issue &&
Array.isArray(line?.latestScenario?.detectAI?.issue) Array.isArray(line?.latestScenario?.detectAI?.issue)
? "- " + line?.latestScenario?.detectAI?.issue?.join("\n- ") ? line?.latestScenario?.detectAI?.issue?.join("\n")
: ""; : "";
setValueIssue(data); setValueIssue(data);
} else { } else {
@ -221,8 +221,8 @@ const ModalTerminal = ({
data?.history && data?.id data?.history && data?.id
? JSON.parse(data?.history) ? JSON.parse(data?.history)
: latest?.length > 0 : latest?.length > 0
? [latest[0], latest[latest?.length - 1]] ? [latest[0], latest[latest?.length - 1]]
: []; : [];
return ( return (
<div> <div>
{list.reverse().map((item: THistoryTicket, index: number) => ( {list.reverse().map((item: THistoryTicket, index: number) => (
@ -241,10 +241,10 @@ const ModalTerminal = ({
index === 0 index === 0
? "#30d100" ? "#30d100"
: item?.status === "closed" : item?.status === "closed"
? "red" ? "red"
: item?.status === "issue" : item?.status === "issue"
? "#fab005" ? "#fab005"
: "inherit", : "inherit",
}} }}
> >
<Text style={{ fontSize: "14px", fontWeight: "bold" }} fw={600}> <Text style={{ fontSize: "14px", fontWeight: "bold" }} fw={600}>
@ -259,10 +259,10 @@ const ModalTerminal = ({
index === 0 index === 0
? "#30d100" ? "#30d100"
: item?.status === "closed" : item?.status === "closed"
? "red" ? "red"
: item?.status === "issue" : item?.status === "issue"
? "#fab005" ? "#fab005"
: "dimmed" : "dimmed"
} }
fw={400} fw={400}
> >
@ -351,8 +351,8 @@ const ModalTerminal = ({
description: dataTicket.description.trim() description: dataTicket.description.trim()
? dataTicket.description.trim() ? dataTicket.description.trim()
: status === "closed" : status === "closed"
? "Closed" ? "Closed"
: "", : "",
model: dataTicket.model.trim(), model: dataTicket.model.trim(),
sn: dataTicket.sn.trim(), sn: dataTicket.sn.trim(),
station_id: Number(stationItem?.id), station_id: Number(stationItem?.id),
@ -365,7 +365,7 @@ const ModalTerminal = ({
try { try {
const res = await axios.post( const res = await axios.post(
`${apiUrl + "api/ticket/update" + "/" + dataTicket.id}`, `${apiUrl + "api/ticket/update" + "/" + dataTicket.id}`,
payload payload,
); );
if (res.status) { if (res.status) {
// if (res?.data?.status !== "closed") // if (res?.data?.status !== "closed")
@ -389,7 +389,7 @@ const ModalTerminal = ({
socket?.emit("update_ticket", { socket?.emit("update_ticket", {
lineId: Number(line?.id), lineId: Number(line?.id),
data: line?.tickets?.map((el) => data: line?.tickets?.map((el) =>
el.id === dataTicket.id ? res.data.data : el el.id === dataTicket.id ? res.data.data : el,
), ),
stationId: Number(stationItem?.id), stationId: Number(stationItem?.id),
}); });
@ -470,7 +470,7 @@ const ModalTerminal = ({
const findSwitchPort = (portName: string): SwitchPortsProps | null => { const findSwitchPort = (portName: string): SwitchPortsProps | null => {
if (listPorts?.length > 0) { if (listPorts?.length > 0) {
const port = listPorts.find( const port = listPorts.find(
(el) => normalizePortName(el.name) === normalizePortName(portName) (el) => normalizePortName(el.name) === normalizePortName(portName),
); );
if (port) return port; if (port) return port;
} }
@ -503,7 +503,7 @@ const ModalTerminal = ({
const showVersion = dataTextfsm?.find( const showVersion = dataTextfsm?.find(
(d) => (d) =>
d.command?.trim()?.includes("show ver") || d.command?.trim()?.includes("show ver") ||
d.command?.trim()?.includes("sh ver") d.command?.trim()?.includes("sh ver"),
); );
return showVersion?.textfsm && showVersion?.textfsm?.[0] return showVersion?.textfsm && showVersion?.textfsm?.[0]
? showVersion?.textfsm?.[0] ? showVersion?.textfsm?.[0]
@ -514,7 +514,7 @@ const ModalTerminal = ({
const showLicense = dataTextfsm?.find( const showLicense = dataTextfsm?.find(
(d) => (d) =>
d.command?.trim()?.includes("show lic") || d.command?.trim()?.includes("show lic") ||
d.command?.trim()?.includes("sh lic") d.command?.trim()?.includes("sh lic"),
); );
return showLicense?.textfsm && Array.isArray(showLicense?.textfsm) return showLicense?.textfsm && Array.isArray(showLicense?.textfsm)
? showLicense?.textfsm ? showLicense?.textfsm
@ -525,15 +525,15 @@ const ModalTerminal = ({
const showEnv = dataTextfsm?.find( const showEnv = dataTextfsm?.find(
(d) => (d) =>
d.command?.trim()?.includes("show env") || d.command?.trim()?.includes("show env") ||
d.command?.trim()?.includes("sh env") d.command?.trim()?.includes("sh env"),
); );
return showEnv?.dataAI && return showEnv?.dataAI &&
Array.isArray(showEnv?.dataAI) && Array.isArray(showEnv?.dataAI) &&
showEnv?.dataAI?.length > 0 showEnv?.dataAI?.length > 0
? showEnv?.dataAI ? showEnv?.dataAI
: showEnv?.textfsm && Array.isArray(showEnv?.textfsm) : showEnv?.textfsm && Array.isArray(showEnv?.textfsm)
? showEnv?.textfsm ? showEnv?.textfsm
: null; : null;
}; };
return ( return (
@ -648,7 +648,7 @@ const ModalTerminal = ({
if (!line) return; if (!line) return;
if (step === 0 && !isDisable) { if (step === 0 && !isDisable) {
const dpelp = scenarios?.find( const dpelp = scenarios?.find(
(el) => el.title.toUpperCase() === "DPELP" (el) => el.title.toUpperCase() === "DPELP",
); );
socket?.emit( socket?.emit(
"run_scenario", "run_scenario",
@ -662,7 +662,7 @@ const ModalTerminal = ({
timeout: 360000, timeout: 360000,
body: JSON.stringify(bodyDPELP), body: JSON.stringify(bodyDPELP),
}, },
}) }),
); );
socket?.emit("run_all_dpelp", { socket?.emit("run_all_dpelp", {
lineIds: [line?.id], lineIds: [line?.id],
@ -895,7 +895,7 @@ const ModalTerminal = ({
e.stopPropagation(); e.stopPropagation();
if (!line?.inventory?.pid) return; if (!line?.inventory?.pid) return;
navigator.clipboard.writeText( navigator.clipboard.writeText(
line.inventory?.pid || "" line.inventory?.pid || "",
); );
}} }}
> >
@ -999,8 +999,8 @@ const ModalTerminal = ({
? findDataShowLicense() ? findDataShowLicense()
?.filter((el: TextTSMLicense) => ?.filter((el: TextTSMLicense) =>
el.LICENSE_TYPE?.toLowerCase()?.includes( el.LICENSE_TYPE?.toLowerCase()?.includes(
"permanent" "permanent",
) ),
) )
?.map((v: TextTSMLicense) => v.FEATURE) ?.map((v: TextTSMLicense) => v.FEATURE)
?.join(", ") ?.join(", ")
@ -1020,7 +1020,7 @@ const ModalTerminal = ({
<Text fz={"14.5px"} key={i}> <Text fz={"14.5px"} key={i}>
- {v} - {v}
</Text> </Text>
) ),
) )
: ""} : ""}
</Box> </Box>
@ -1034,7 +1034,7 @@ const ModalTerminal = ({
{findDataShowVersion() && {findDataShowVersion() &&
findDataShowVersion()?.MEMORY findDataShowVersion()?.MEMORY
? convertFromKilobytesString( ? convertFromKilobytesString(
findDataShowVersion()?.MEMORY findDataShowVersion()?.MEMORY,
) )
: ""} : ""}
</Text> </Text>
@ -1047,7 +1047,7 @@ const ModalTerminal = ({
{findDataShowVersion() && {findDataShowVersion() &&
findDataShowVersion()?.USB_FLASH findDataShowVersion()?.USB_FLASH
? convertFromKilobytesString( ? convertFromKilobytesString(
findDataShowVersion()?.USB_FLASH findDataShowVersion()?.USB_FLASH,
) )
: ""} : ""}
</Text> </Text>
@ -1077,8 +1077,8 @@ const ModalTerminal = ({
? findDataShowLicense() ? findDataShowLicense()
?.filter((el: TextTSMLicense) => ?.filter((el: TextTSMLicense) =>
el.LICENSE_TYPE?.toLowerCase()?.includes( el.LICENSE_TYPE?.toLowerCase()?.includes(
"permanent" "permanent",
) ),
) )
?.map((v: TextTSMLicense) => v.FEATURE) ?.map((v: TextTSMLicense) => v.FEATURE)
: [], : [],
@ -1488,7 +1488,7 @@ const ModalTerminal = ({
}, 10000); }, 10000);
}} }}
dataDPELP={scenarios?.find( dataDPELP={scenarios?.find(
(el) => el.title.toUpperCase() === "DPELP" (el) => el.title.toUpperCase() === "DPELP",
)} )}
/> />
<Button <Button