@n8n/n8n-nodes-langchain
Version:

32 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessageFormatter = void 0;
class MessageFormatter {
static formatToolResult(result) {
if (typeof result === 'object' && result !== null) {
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
}
if (typeof result === 'string') {
return { content: [{ type: 'text', text: result }] };
}
if (result === null || result === undefined) {
return { content: [{ type: 'text', text: String(result) }] };
}
if (typeof result === 'number' || typeof result === 'boolean' || typeof result === 'bigint') {
return { content: [{ type: 'text', text: result.toString() }] };
}
return {
content: [
{ type: 'text', text: String(result) },
],
};
}
static formatError(error) {
return {
isError: true,
content: [{ type: 'text', text: `${error.name}: ${error.message}` }],
};
}
}
exports.MessageFormatter = MessageFormatter;
//# sourceMappingURL=MessageFormatter.js.map