n8n
Version:
n8n Workflow Automation Tool
50 lines • 3.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AGENT_PREVIEW_CONTEXT_CLOSE_TAG = exports.AGENT_PREVIEW_CONTEXT_OPEN_TAG = exports.CREDENTIAL_CONTEXT_CLOSE_TAG = exports.CREDENTIAL_CONTEXT_OPEN_TAG = exports.EDITOR_CONTEXT_CLOSE_TAG = exports.EDITOR_CONTEXT_OPEN_TAG = exports.AUTO_FOLLOW_UP_MESSAGE = void 0;
exports.withCurrentDateTime = withCurrentDateTime;
exports.cleanStoredUserMessage = cleanStoredUserMessage;
exports.extractEditorContextResourceAttachments = extractEditorContextResourceAttachments;
exports.extractAgentPreviewHandoffContext = extractAgentPreviewHandoffContext;
const api_types_1 = require("@n8n/api-types");
const n8n_workflow_1 = require("n8n-workflow");
const zod_1 = require("zod");
exports.AUTO_FOLLOW_UP_MESSAGE = '(continue)';
exports.EDITOR_CONTEXT_OPEN_TAG = '<editor-context>';
exports.EDITOR_CONTEXT_CLOSE_TAG = '</editor-context>';
exports.CREDENTIAL_CONTEXT_OPEN_TAG = '<credential-context>';
exports.CREDENTIAL_CONTEXT_CLOSE_TAG = '</credential-context>';
exports.AGENT_PREVIEW_CONTEXT_OPEN_TAG = '<agent-preview-context>';
exports.AGENT_PREVIEW_CONTEXT_CLOSE_TAG = '</agent-preview-context>';
const TASK_CONTEXT_BLOCK = /^(?:<running-tasks>\n[\s\S]*?\n<\/running-tasks>|<planned-task-follow-up[\s\S]*?\n<\/planned-task-follow-up>|<planning-blueprint>\n[\s\S]*?\n<\/planning-blueprint>|<background-task-completed>\n[\s\S]*?\n<\/background-task-completed>|<workflow-verification-follow-up>\n[\s\S]*?\n<\/workflow-verification-follow-up>|<workflow-setup-required>\n[\s\S]*?\n<\/workflow-setup-required>|<editor-context>\n[\s\S]*?\n<\/editor-context>|<credential-context>\n[\s\S]*?\n<\/credential-context>|<agent-preview-context>\n[\s\S]*?\n<\/agent-preview-context>)(?:\n\n|$)/;
const EDITOR_CONTEXT_JSON = /^<editor-context>\n(\[[\s\S]*?\])\n/;
const AGENT_PREVIEW_CONTEXT_JSON = /^<agent-preview-context>\n(\{[\s\S]*?\})\n/;
const CURRENT_DATE_TIME_BLOCK = /\n*<current-date-time>[\s\S]*?<\/current-date-time>\s*$/;
function withCurrentDateTime(message, dateTimeSection) {
return `${message}\n\n<current-date-time>${dateTimeSection}\n</current-date-time>`;
}
function cleanStoredUserMessage(stored) {
let text = stored.replace(CURRENT_DATE_TIME_BLOCK, '');
let previous;
do {
previous = text;
text = text.replace(TASK_CONTEXT_BLOCK, '');
} while (text !== previous);
return text === exports.AUTO_FOLLOW_UP_MESSAGE ? null : text;
}
function extractEditorContextResourceAttachments(stored) {
const match = EDITOR_CONTEXT_JSON.exec(stored);
if (!match)
return [];
const parsed = zod_1.z
.array(api_types_1.instanceAiResourceAttachmentSchema)
.safeParse((0, n8n_workflow_1.jsonParse)(match[1], { fallbackValue: undefined }));
return parsed.success ? parsed.data : [];
}
function extractAgentPreviewHandoffContext(stored) {
const match = AGENT_PREVIEW_CONTEXT_JSON.exec(stored);
if (!match)
return undefined;
const parsed = api_types_1.instanceAiAgentPreviewHandoffContextSchema.safeParse((0, n8n_workflow_1.jsonParse)(match[1], { fallbackValue: undefined }));
return parsed.success ? parsed.data : undefined;
}
//# sourceMappingURL=internal-messages.js.map