fix: extract text from plannerResponse field for Discord relay
This commit is contained in:
@@ -1806,13 +1806,48 @@ function setupMonitor() {
|
|||||||
const s = steps[ri];
|
const s = steps[ri];
|
||||||
const sType = s?.type || '';
|
const sType = s?.type || '';
|
||||||
if (sType.includes('PLANNER_RESPONSE') || sType.includes('MESSAGE')) {
|
if (sType.includes('PLANNER_RESPONSE') || sType.includes('MESSAGE')) {
|
||||||
const parts = s?.content?.parts || s?.parts || [];
|
|
||||||
let textContent = '';
|
let textContent = '';
|
||||||
|
// Extract from plannerResponse field
|
||||||
|
const pr = s?.plannerResponse;
|
||||||
|
if (pr) {
|
||||||
|
if (typeof pr === 'string')
|
||||||
|
textContent = pr;
|
||||||
|
else if (pr.rawText)
|
||||||
|
textContent = pr.rawText;
|
||||||
|
else if (pr.message)
|
||||||
|
textContent = typeof pr.message === 'string' ? pr.message : JSON.stringify(pr.message);
|
||||||
|
else if (pr.content?.parts) {
|
||||||
|
for (const p of pr.content.parts) {
|
||||||
|
if (p?.text)
|
||||||
|
textContent += p.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pr.parts) {
|
||||||
|
for (const p of pr.parts) {
|
||||||
|
if (p?.text)
|
||||||
|
textContent += p.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!textContent)
|
||||||
|
textContent = JSON.stringify(pr).substring(0, 500);
|
||||||
|
}
|
||||||
|
// Extract from ephemeralMessage field
|
||||||
|
const em = s?.ephemeralMessage;
|
||||||
|
if (!textContent && em) {
|
||||||
|
if (typeof em === 'string')
|
||||||
|
textContent = em;
|
||||||
|
else if (em.message)
|
||||||
|
textContent = em.message;
|
||||||
|
else if (em.content)
|
||||||
|
textContent = typeof em.content === 'string' ? em.content : JSON.stringify(em.content);
|
||||||
|
}
|
||||||
|
// Fallback: metadata, content, rawOutput
|
||||||
|
if (!textContent) {
|
||||||
|
const parts = s?.content?.parts || s?.parts || [];
|
||||||
for (const p of parts) {
|
for (const p of parts) {
|
||||||
if (p?.text)
|
if (p?.text)
|
||||||
textContent += p.text;
|
textContent += p.text;
|
||||||
else if (typeof p === 'string')
|
}
|
||||||
textContent += p;
|
|
||||||
}
|
}
|
||||||
if (!textContent && s?.metadata?.text)
|
if (!textContent && s?.metadata?.text)
|
||||||
textContent = s.metadata.text;
|
textContent = s.metadata.text;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1774,11 +1774,38 @@ function setupMonitor() {
|
|||||||
const s = steps[ri];
|
const s = steps[ri];
|
||||||
const sType = s?.type || '';
|
const sType = s?.type || '';
|
||||||
if (sType.includes('PLANNER_RESPONSE') || sType.includes('MESSAGE')) {
|
if (sType.includes('PLANNER_RESPONSE') || sType.includes('MESSAGE')) {
|
||||||
const parts = s?.content?.parts || s?.parts || [];
|
|
||||||
let textContent = '';
|
let textContent = '';
|
||||||
|
// Extract from plannerResponse field
|
||||||
|
const pr = s?.plannerResponse;
|
||||||
|
if (pr) {
|
||||||
|
if (typeof pr === 'string') textContent = pr;
|
||||||
|
else if (pr.rawText) textContent = pr.rawText;
|
||||||
|
else if (pr.message) textContent = typeof pr.message === 'string' ? pr.message : JSON.stringify(pr.message);
|
||||||
|
else if (pr.content?.parts) {
|
||||||
|
for (const p of pr.content.parts) {
|
||||||
|
if (p?.text) textContent += p.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pr.parts) {
|
||||||
|
for (const p of pr.parts) {
|
||||||
|
if (p?.text) textContent += p.text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!textContent) textContent = JSON.stringify(pr).substring(0, 500);
|
||||||
|
}
|
||||||
|
// Extract from ephemeralMessage field
|
||||||
|
const em = s?.ephemeralMessage;
|
||||||
|
if (!textContent && em) {
|
||||||
|
if (typeof em === 'string') textContent = em;
|
||||||
|
else if (em.message) textContent = em.message;
|
||||||
|
else if (em.content) textContent = typeof em.content === 'string' ? em.content : JSON.stringify(em.content);
|
||||||
|
}
|
||||||
|
// Fallback: metadata, content, rawOutput
|
||||||
|
if (!textContent) {
|
||||||
|
const parts = s?.content?.parts || s?.parts || [];
|
||||||
for (const p of parts) {
|
for (const p of parts) {
|
||||||
if (p?.text) textContent += p.text;
|
if (p?.text) textContent += p.text;
|
||||||
else if (typeof p === 'string') textContent += p;
|
}
|
||||||
}
|
}
|
||||||
if (!textContent && s?.metadata?.text) textContent = s.metadata.text;
|
if (!textContent && s?.metadata?.text) textContent = s.metadata.text;
|
||||||
if (!textContent && s?.rawOutput) textContent = typeof s.rawOutput === 'string' ? s.rawOutput : JSON.stringify(s.rawOutput);
|
if (!textContent && s?.rawOutput) textContent = typeof s.rawOutput === 'string' ? s.rawOutput : JSON.stringify(s.rawOutput);
|
||||||
|
|||||||
Reference in New Issue
Block a user