@n8n/n8n-nodes-langchain
Version:
48 lines • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildChatShellViewModel = buildChatShellViewModel;
exports.connectBarText = connectBarText;
const accountsLabel = (count) => (count === 1 ? 'account' : 'accounts');
function buildChatShellViewModel(credentials, visitorEmail) {
const initialOf = (name) => (name.trim().charAt(0) || '?').toUpperCase();
const rows = credentials.map((c) => ({
key: `${c.credentialId}::${c.resolverId ?? ''}`,
id: c.credentialId,
name: c.credentialName,
connected: c.status === 'configured',
initial: initialOf(c.credentialName),
iconUrl: c.iconUrl,
authorizationUrl: c.authorizationUrl,
revokeUrl: c.revokeUrl,
resolverId: c.resolverId,
account: c.status === 'configured' ? visitorEmail : undefined,
}));
const total = rows.length;
const connectedCount = rows.filter((r) => r.connected).length;
return {
credentials: rows,
total,
connectedCount,
useDialog: total >= 2,
footerText: `${connectedCount} of ${total} ${accountsLabel(total)} connected`,
};
}
function connectBarText(vm, testMode) {
const remaining = Math.max(vm.total - vm.connectedCount, 0);
if (remaining === 0) {
if (testMode) {
return "You're testing with your own connected accounts. Visitors will need to connect their own.";
}
return vm.total === 1
? 'Account connected \u00b7 ready to chat'
: `All ${vm.total} accounts connected \u00b7 ready to chat`;
}
if (vm.total === 1) {
return `Connect ${vm.credentials[0].name} to start this chat`;
}
if (vm.connectedCount === 0) {
return `${vm.total} ${accountsLabel(vm.total)} needed to start this chat`;
}
return `${remaining} more ${accountsLabel(remaining)} needed to start this chat`;
}
//# sourceMappingURL=connect-panel.js.map