feat: relay AG-side user messages to Discord via chat_snapshots
This commit is contained in:
@@ -1878,7 +1878,41 @@ function setupMonitor() {
|
|||||||
const userInputIdx = bestSession.lastUserInputStepIndex ?? -1;
|
const userInputIdx = bestSession.lastUserInputStepIndex ?? -1;
|
||||||
if (userInputIdx > lastUserInputStepIdx) {
|
if (userInputIdx > lastUserInputStepIdx) {
|
||||||
lastUserInputStepIdx = userInputIdx;
|
lastUserInputStepIdx = userInputIdx;
|
||||||
logToFile(`[RESPONSE-CAPTURE] user input detected at step ${userInputIdx}`);
|
logToFile(`[USER-MSG] user input detected at step ${userInputIdx}, capturing...`);
|
||||||
|
// Fetch user message content and relay to Discord
|
||||||
|
try {
|
||||||
|
const umResp = await sdk.ls.rawRPC('GetCascadeTrajectorySteps', {
|
||||||
|
cascadeId: bestSessionId,
|
||||||
|
stepOffset: userInputIdx,
|
||||||
|
verbosity: 1,
|
||||||
|
});
|
||||||
|
if (umResp?.steps?.length > 0) {
|
||||||
|
const umStep = umResp.steps[0];
|
||||||
|
// User message text can be in various fields
|
||||||
|
const umText = umStep?.userMessage?.text
|
||||||
|
|| umStep?.userMessage?.rawText
|
||||||
|
|| umStep?.plannerResponse?.rawText
|
||||||
|
|| umStep?.metadata?.toolCall?.argumentsJson
|
||||||
|
|| '';
|
||||||
|
if (umText.length > 2) {
|
||||||
|
const truncated = umText.length > 800
|
||||||
|
? umText.substring(0, 800) + '\n\n_(이하 생략)_'
|
||||||
|
: umText;
|
||||||
|
writeChatSnapshot(`👤 **사용자 (AG 직접 입력)**\n\n${truncated}`);
|
||||||
|
logToFile(`[USER-MSG] relayed ${umText.length} chars from step ${userInputIdx}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Fallback: just notify that user sent input
|
||||||
|
writeChatSnapshot(`👤 **사용자 (AG 직접 입력)** — _(내용 추출 불가)_`);
|
||||||
|
logToFile(`[USER-MSG] step ${userInputIdx} text empty, sent fallback`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (umErr) {
|
||||||
|
logToFile(`[USER-MSG] capture error: ${umErr.message?.substring(0, 100)}`);
|
||||||
|
// Still notify discord about user input even without content
|
||||||
|
writeChatSnapshot(`👤 **사용자 (AG 직접 입력)** — _(캡처 실패)_`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (wasRunning && !isRunning && currentCount > lastResponseCaptureStep) {
|
if (wasRunning && !isRunning && currentCount > lastResponseCaptureStep) {
|
||||||
logToFile(`[RESPONSE-CAPTURE] RUNNING→IDLE, steps=${currentCount}, capturing response...`);
|
logToFile(`[RESPONSE-CAPTURE] RUNNING→IDLE, steps=${currentCount}, capturing response...`);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1843,7 +1843,39 @@ function setupMonitor() {
|
|||||||
const userInputIdx = bestSession.lastUserInputStepIndex ?? -1;
|
const userInputIdx = bestSession.lastUserInputStepIndex ?? -1;
|
||||||
if (userInputIdx > lastUserInputStepIdx) {
|
if (userInputIdx > lastUserInputStepIdx) {
|
||||||
lastUserInputStepIdx = userInputIdx;
|
lastUserInputStepIdx = userInputIdx;
|
||||||
logToFile(`[RESPONSE-CAPTURE] user input detected at step ${userInputIdx}`);
|
logToFile(`[USER-MSG] user input detected at step ${userInputIdx}, capturing...`);
|
||||||
|
// Fetch user message content and relay to Discord
|
||||||
|
try {
|
||||||
|
const umResp = await sdk.ls.rawRPC('GetCascadeTrajectorySteps', {
|
||||||
|
cascadeId: bestSessionId,
|
||||||
|
stepOffset: userInputIdx,
|
||||||
|
verbosity: 1,
|
||||||
|
});
|
||||||
|
if (umResp?.steps?.length > 0) {
|
||||||
|
const umStep = umResp.steps[0];
|
||||||
|
// User message text can be in various fields
|
||||||
|
const umText = umStep?.userMessage?.text
|
||||||
|
|| umStep?.userMessage?.rawText
|
||||||
|
|| umStep?.plannerResponse?.rawText
|
||||||
|
|| umStep?.metadata?.toolCall?.argumentsJson
|
||||||
|
|| '';
|
||||||
|
if (umText.length > 2) {
|
||||||
|
const truncated = umText.length > 800
|
||||||
|
? umText.substring(0, 800) + '\n\n_(이하 생략)_'
|
||||||
|
: umText;
|
||||||
|
writeChatSnapshot(`👤 **사용자 (AG 직접 입력)**\n\n${truncated}`);
|
||||||
|
logToFile(`[USER-MSG] relayed ${umText.length} chars from step ${userInputIdx}`);
|
||||||
|
} else {
|
||||||
|
// Fallback: just notify that user sent input
|
||||||
|
writeChatSnapshot(`👤 **사용자 (AG 직접 입력)** — _(내용 추출 불가)_`);
|
||||||
|
logToFile(`[USER-MSG] step ${userInputIdx} text empty, sent fallback`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (umErr: any) {
|
||||||
|
logToFile(`[USER-MSG] capture error: ${umErr.message?.substring(0, 100)}`);
|
||||||
|
// Still notify discord about user input even without content
|
||||||
|
writeChatSnapshot(`👤 **사용자 (AG 직접 입력)** — _(캡처 실패)_`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasRunning && !isRunning && currentCount > lastResponseCaptureStep) {
|
if (wasRunning && !isRunning && currentCount > lastResponseCaptureStep) {
|
||||||
|
|||||||
Reference in New Issue
Block a user