- Updated README to include new features such as task-specific logs and messages, task creation with attachments, and task context preservation. - Introduced `stripAgentBlocks` function to remove agent-only blocks from text, improving message clarity. - Enhanced `lookupMessage` function to handle ambiguous messageId scenarios more effectively. - Added `sourceMessageId` and `sourceMessage` fields to capture original message details during task creation. - Updated tests to reflect changes in message handling and ensure robust functionality.
30 lines
845 B
JavaScript
30 lines
845 B
JavaScript
const AGENT_BLOCK_TAG = 'info_for_agent';
|
|
const AGENT_BLOCK_OPEN = `<${AGENT_BLOCK_TAG}>`;
|
|
const AGENT_BLOCK_CLOSE = `</${AGENT_BLOCK_TAG}>`;
|
|
const AGENT_BLOCK_RE = new RegExp(`<${AGENT_BLOCK_TAG}>[\\s\\S]*?</${AGENT_BLOCK_TAG}>`, 'g');
|
|
|
|
function wrapAgentBlock(text) {
|
|
const trimmed = typeof text === 'string' ? text.trim() : '';
|
|
if (!trimmed) {
|
|
return '';
|
|
}
|
|
return `${AGENT_BLOCK_OPEN}\n${trimmed}\n${AGENT_BLOCK_CLOSE}`;
|
|
}
|
|
|
|
/**
|
|
* Strip all agent-only blocks from text.
|
|
* Returns text with `<info_for_agent>...</info_for_agent>` blocks removed and trimmed.
|
|
*/
|
|
function stripAgentBlocks(text) {
|
|
if (typeof text !== 'string') return '';
|
|
return text.replace(AGENT_BLOCK_RE, '').trim();
|
|
}
|
|
|
|
module.exports = {
|
|
AGENT_BLOCK_TAG,
|
|
AGENT_BLOCK_OPEN,
|
|
AGENT_BLOCK_CLOSE,
|
|
AGENT_BLOCK_RE,
|
|
stripAgentBlocks,
|
|
wrapAgentBlock,
|
|
};
|