@spekra.in/agent-os 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Booker/README.md +41 -0
- package/Booker/package.json +11 -0
- package/Booker/src/agent.js +15 -0
- package/Booker/src/calendar-adapter.js +75 -0
- package/Booker/src/index.js +4 -0
- package/Booker/src/intake-parser.js +96 -0
- package/Booker/src/validation.js +34 -0
- package/Booker/test/booker.test.js +35 -0
- package/CashHound/README.md +181 -0
- package/CashHound/package.json +21 -0
- package/CashHound/src/agent.js +621 -0
- package/CashHound/src/bank-reconciler.js +66 -0
- package/CashHound/src/dunning.js +380 -0
- package/CashHound/src/index.js +32 -0
- package/CashHound/src/invoice.js +371 -0
- package/CashHound/src/mobile.js +35 -0
- package/CashHound/src/npv-optimizer.js +259 -0
- package/CashHound/test/advanced.test.js +44 -0
- package/CashHound/test/cashhound.test.js +530 -0
- package/CashHound/test/mobile.test.js +25 -0
- package/CashHound/test/security.test.js +35 -0
- package/Clerk/README.md +30 -0
- package/Clerk/package.json +11 -0
- package/Clerk/src/agent.js +18 -0
- package/Clerk/src/index.js +2 -0
- package/Clerk/src/reconciliation.js +52 -0
- package/Clerk/test/clerk.test.js +39 -0
- package/LocalRoar/README.md +37 -0
- package/LocalRoar/package.json +13 -0
- package/LocalRoar/src/agent.js +70 -0
- package/LocalRoar/src/booking-router.js +74 -0
- package/LocalRoar/src/feedback-interceptor.js +47 -0
- package/LocalRoar/src/index.js +7 -0
- package/LocalRoar/src/lead-engine.js +52 -0
- package/LocalRoar/src/mobile.js +23 -0
- package/LocalRoar/src/review-booster.js +24 -0
- package/LocalRoar/src/route-density.js +46 -0
- package/LocalRoar/test/advanced.test.js +41 -0
- package/LocalRoar/test/localroar.test.js +59 -0
- package/LocalRoar/test/mobile.test.js +12 -0
- package/OmniLife/README.md +39 -0
- package/OmniLife/package.json +13 -0
- package/OmniLife/src/agent.js +47 -0
- package/OmniLife/src/bill-negotiator.js +43 -0
- package/OmniLife/src/browser-cancel.js +28 -0
- package/OmniLife/src/conflict-engine.js +49 -0
- package/OmniLife/src/index.js +6 -0
- package/OmniLife/src/mobile.js +18 -0
- package/OmniLife/src/subscription-manager.js +66 -0
- package/OmniLife/test/advanced.test.js +29 -0
- package/OmniLife/test/mobile.test.js +12 -0
- package/OmniLife/test/omnilife.test.js +71 -0
- package/PulseMD/README.md +42 -0
- package/PulseMD/package.json +13 -0
- package/PulseMD/src/agent.js +67 -0
- package/PulseMD/src/ambient-scribe.js +46 -0
- package/PulseMD/src/auth.js +63 -0
- package/PulseMD/src/charting.js +54 -0
- package/PulseMD/src/index.js +7 -0
- package/PulseMD/src/mobile.js +18 -0
- package/PulseMD/src/prior-auth.js +39 -0
- package/PulseMD/src/safety-guard.js +88 -0
- package/PulseMD/test/advanced.test.js +50 -0
- package/PulseMD/test/mobile.test.js +12 -0
- package/PulseMD/test/pulsemd.test.js +71 -0
- package/README.md +203 -2
- package/ResolveX/README.md +274 -0
- package/ResolveX/package.json +20 -0
- package/ResolveX/src/agent.js +679 -0
- package/ResolveX/src/carrier-listener.js +405 -0
- package/ResolveX/src/diagnosis.js +315 -0
- package/ResolveX/src/index.js +36 -0
- package/ResolveX/src/mobile.js +31 -0
- package/ResolveX/src/policy.js +325 -0
- package/ResolveX/src/vision.js +384 -0
- package/ResolveX/test/advanced.test.js +445 -0
- package/ResolveX/test/mobile.test.js +15 -0
- package/ResolveX/test/resolvex.test.js +428 -0
- package/SentinelMesh/README.md +51 -0
- package/SentinelMesh/package.json +13 -0
- package/SentinelMesh/src/governor.js +61 -0
- package/SentinelMesh/src/index.js +4 -0
- package/SentinelMesh/src/mobile.js +19 -0
- package/SentinelMesh/src/policy.js +63 -0
- package/SentinelMesh/src/sandbox.js +152 -0
- package/SentinelMesh/test/mobile.test.js +12 -0
- package/SentinelMesh/test/sentinel.test.js +135 -0
- package/Sidekick/README.md +43 -0
- package/Sidekick/package.json +11 -0
- package/Sidekick/src/agent.js +15 -0
- package/Sidekick/src/evidence.js +45 -0
- package/Sidekick/src/index.js +3 -0
- package/Sidekick/src/validation.js +15 -0
- package/Sidekick/test/sidekick.test.js +33 -0
- package/agent-os-mobile/README.md +26 -0
- package/agent-os-mobile/src/api.js +97 -0
- package/agent-os-mobile/src/biometric.js +41 -0
- package/agent-os-mobile/src/components/ApprovalStack.js +207 -0
- package/agent-os-mobile/src/components/OutcomeCard.js +98 -0
- package/agent-os-mobile/src/memory-graph.js +114 -0
- package/agent-os-mobile/src/screens/CashHoundMobileScreen.js +111 -0
- package/agent-os-mobile/src/screens/LocalRoarMobileScreen.js +183 -0
- package/agent-os-mobile/src/screens/OmniLifeMobileScreen.js +111 -0
- package/agent-os-mobile/src/screens/PulseMDMobileScreen.js +55 -0
- package/agent-os-mobile/src/screens/ResolveXMobileScreen.js +96 -0
- package/agent-os-mobile/src/screens/SentinelMeshMobileScreen.js +199 -0
- package/agent-os-mobile/src/self-healer.js +104 -0
- package/agent-os-mobile/src/speculative-verifier.js +69 -0
- package/agent-os-mobile/src/spekra-bridge.js +216 -0
- package/agent-os-mobile/src/swarm.js +72 -0
- package/agent-os-mobile/src/voice.js +51 -0
- package/bin/agentos.js +260 -0
- package/package.json +51 -4
- package/src/index.js +91 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CashHound - Tiered Dunning Engine & Financial Settlement Calculator
|
|
3
|
+
* Generates polite-to-firm communications with fine-grained tone controls,
|
|
4
|
+
* installment plan schedules, and early settlement offers.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { CustomerTier } from './invoice.js';
|
|
8
|
+
|
|
9
|
+
export const DunningTier = Object.freeze({
|
|
10
|
+
TIER_1_COURTESY: 1, // 1-14 days: Gentle courtesy check-in
|
|
11
|
+
TIER_2_REMINDER: 2, // 15-30 days: Standard professional reminder
|
|
12
|
+
TIER_3_URGENT: 3, // 31-60 days: Firm notice with payment options
|
|
13
|
+
TIER_4_FINAL_DEMAND: 4, // 61+ days: Formal final demand / pre-collections
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const DunningTone = Object.freeze({
|
|
17
|
+
FRIENDLY: 'friendly',
|
|
18
|
+
PROFESSIONAL: 'professional',
|
|
19
|
+
URGENT: 'urgent',
|
|
20
|
+
FORMAL: 'formal',
|
|
21
|
+
EMPATHETIC: 'empathetic',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Calculates a structured installment payment plan for an outstanding balance.
|
|
26
|
+
*
|
|
27
|
+
* @param {number} balance - Current outstanding balance
|
|
28
|
+
* @param {Object} [options={}]
|
|
29
|
+
* @param {number} [options.numberOfInstallments=3] - Number of split payments (2-12)
|
|
30
|
+
* @param {string} [options.frequency='monthly'] - 'weekly' | 'biweekly' | 'monthly'
|
|
31
|
+
* @param {Date|string} [options.startDate=new Date()] - First payment date
|
|
32
|
+
* @param {number} [options.feePercentage=0] - Surcharge or convenience fee percent (if any)
|
|
33
|
+
* @returns {Object} Installment plan breakdown
|
|
34
|
+
*/
|
|
35
|
+
export function calculateInstallmentPlan(balance, options = {}) {
|
|
36
|
+
const {
|
|
37
|
+
numberOfInstallments = 3,
|
|
38
|
+
frequency = 'monthly',
|
|
39
|
+
startDate = new Date(),
|
|
40
|
+
feePercentage = 0,
|
|
41
|
+
} = options;
|
|
42
|
+
|
|
43
|
+
if (typeof balance !== 'number' || !Number.isFinite(balance) || balance <= 0) {
|
|
44
|
+
throw new Error('Balance must be a positive finite number to calculate an installment plan');
|
|
45
|
+
}
|
|
46
|
+
const installmentsCount = Math.max(2, Math.min(12, Math.round(numberOfInstallments)));
|
|
47
|
+
const feeMultiplier = 1 + (Math.max(0, feePercentage) / 100);
|
|
48
|
+
const totalPayable = Number((balance * feeMultiplier).toFixed(2));
|
|
49
|
+
const baseInstallment = Number((totalPayable / installmentsCount).toFixed(2));
|
|
50
|
+
|
|
51
|
+
const schedule = [];
|
|
52
|
+
let remaining = totalPayable;
|
|
53
|
+
let currentDate = new Date(startDate);
|
|
54
|
+
|
|
55
|
+
for (let i = 1; i <= installmentsCount; i++) {
|
|
56
|
+
// Determine the next payment date based on frequency
|
|
57
|
+
if (i > 1) {
|
|
58
|
+
currentDate = new Date(currentDate);
|
|
59
|
+
if (frequency === 'weekly') {
|
|
60
|
+
currentDate.setDate(currentDate.getDate() + 7);
|
|
61
|
+
} else if (frequency === 'biweekly') {
|
|
62
|
+
currentDate.setDate(currentDate.getDate() + 14);
|
|
63
|
+
} else {
|
|
64
|
+
// default monthly
|
|
65
|
+
currentDate.setMonth(currentDate.getMonth() + 1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Last installment absorbs any rounding cent differences
|
|
70
|
+
const amount = (i === installmentsCount)
|
|
71
|
+
? Number(remaining.toFixed(2))
|
|
72
|
+
: baseInstallment;
|
|
73
|
+
|
|
74
|
+
remaining = Number((remaining - amount).toFixed(2));
|
|
75
|
+
|
|
76
|
+
schedule.push({
|
|
77
|
+
installmentNumber: i,
|
|
78
|
+
dueDate: new Date(currentDate).toISOString().split('T')[0],
|
|
79
|
+
amount,
|
|
80
|
+
remainingBalanceAfter: Math.max(0, remaining),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
originalBalance: Number(balance.toFixed(2)),
|
|
86
|
+
totalPayable,
|
|
87
|
+
numberOfInstallments: installmentsCount,
|
|
88
|
+
frequency,
|
|
89
|
+
installmentAmount: baseInstallment,
|
|
90
|
+
feePercentage,
|
|
91
|
+
schedule,
|
|
92
|
+
summary: `${installmentsCount} payments of $${baseInstallment.toFixed(2)} (${frequency})`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Calculates a lump-sum settlement discount offer for immediate recovery.
|
|
98
|
+
*
|
|
99
|
+
* @param {number} balance - Current outstanding balance
|
|
100
|
+
* @param {Object} [options={}]
|
|
101
|
+
* @param {number} [options.discountPercentage=15] - Discount percent (e.g. 10% to 30%)
|
|
102
|
+
* @param {number} [options.validityDays=7] - Number of days the offer remains valid
|
|
103
|
+
* @param {Date|string} [options.asOfDate=new Date()] - Offer creation date
|
|
104
|
+
* @returns {Object} Settlement offer breakdown
|
|
105
|
+
*/
|
|
106
|
+
export function calculateSettlementOffer(balance, options = {}) {
|
|
107
|
+
const {
|
|
108
|
+
discountPercentage = 15,
|
|
109
|
+
validityDays = 7,
|
|
110
|
+
asOfDate = new Date(),
|
|
111
|
+
} = options;
|
|
112
|
+
|
|
113
|
+
if (balance <= 0) {
|
|
114
|
+
throw new Error('Balance must be greater than zero to calculate a settlement offer');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const validPercent = Math.max(5, Math.min(50, discountPercentage));
|
|
118
|
+
const discountAmount = Number(((balance * validPercent) / 100).toFixed(2));
|
|
119
|
+
const settlementAmount = Number((balance - discountAmount).toFixed(2));
|
|
120
|
+
|
|
121
|
+
const validUntil = new Date(asOfDate);
|
|
122
|
+
validUntil.setDate(validUntil.getDate() + validityDays);
|
|
123
|
+
|
|
124
|
+
const offerCode = `SETTLE-${Math.floor(balance)}-${Math.floor(Math.random() * 9000 + 1000)}`;
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
originalBalance: Number(balance.toFixed(2)),
|
|
128
|
+
settlementAmount,
|
|
129
|
+
discountAmount,
|
|
130
|
+
discountPercentage: validPercent,
|
|
131
|
+
validityDays,
|
|
132
|
+
validUntil: validUntil.toISOString().split('T')[0],
|
|
133
|
+
offerCode,
|
|
134
|
+
terms: `Pay $${settlementAmount.toFixed(2)} in full by ${validUntil.toISOString().split('T')[0]} to settle invoice in full (saves $${discountAmount.toFixed(2)}).`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Determines recommended dunning tier from days past due.
|
|
140
|
+
*
|
|
141
|
+
* @param {number} daysPastDue
|
|
142
|
+
* @returns {number} DunningTier
|
|
143
|
+
*/
|
|
144
|
+
export function getRecommendedTier(daysPastDue) {
|
|
145
|
+
if (daysPastDue <= 14) return DunningTier.TIER_1_COURTESY;
|
|
146
|
+
if (daysPastDue <= 30) return DunningTier.TIER_2_REMINDER;
|
|
147
|
+
if (daysPastDue <= 60) return DunningTier.TIER_3_URGENT;
|
|
148
|
+
return DunningTier.TIER_4_FINAL_DEMAND;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Generates an appropriate tone based on tier and customer tier.
|
|
153
|
+
*
|
|
154
|
+
* @param {number} tier
|
|
155
|
+
* @param {string} customerTier
|
|
156
|
+
* @returns {string} DunningTone
|
|
157
|
+
*/
|
|
158
|
+
export function resolveTone(tier, customerTier) {
|
|
159
|
+
if (customerTier === CustomerTier.VIP) {
|
|
160
|
+
// VIP customers are kept friendly or empathetic
|
|
161
|
+
if (tier === DunningTier.TIER_4_FINAL_DEMAND) return DunningTone.PROFESSIONAL;
|
|
162
|
+
return DunningTone.EMPATHETIC;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
switch (tier) {
|
|
166
|
+
case DunningTier.TIER_1_COURTESY:
|
|
167
|
+
return DunningTone.FRIENDLY;
|
|
168
|
+
case DunningTier.TIER_2_REMINDER:
|
|
169
|
+
return DunningTone.PROFESSIONAL;
|
|
170
|
+
case DunningTier.TIER_3_URGENT:
|
|
171
|
+
return DunningTone.URGENT;
|
|
172
|
+
case DunningTier.TIER_4_FINAL_DEMAND:
|
|
173
|
+
default:
|
|
174
|
+
return DunningTone.FORMAL;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Generates a tailored dunning follow-up message with tone controls,
|
|
180
|
+
* custom formatting, and embedded payment options.
|
|
181
|
+
*
|
|
182
|
+
* @param {import('./invoice.js').Invoice} invoice
|
|
183
|
+
* @param {Object} [options={}]
|
|
184
|
+
* @param {number} [options.tier] - Override default tier
|
|
185
|
+
* @param {string} [options.tone] - Override default tone
|
|
186
|
+
* @param {Date|string} [options.asOfDate=new Date()]
|
|
187
|
+
* @param {boolean} [options.includeInstallmentPlan=false]
|
|
188
|
+
* @param {boolean} [options.includeSettlementOffer=false]
|
|
189
|
+
* @param {string} [options.paymentPortalUrl='https://pay.cashhound.io']
|
|
190
|
+
* @returns {Object} Structured communication artifact
|
|
191
|
+
*/
|
|
192
|
+
export function generateDunningMessage(invoice, options = {}) {
|
|
193
|
+
const asOf = options.asOfDate ? new Date(options.asOfDate) : new Date();
|
|
194
|
+
const daysOverdue = invoice.getDaysPastDue(asOf);
|
|
195
|
+
const tier = options.tier || getRecommendedTier(daysOverdue);
|
|
196
|
+
const tone = options.tone || resolveTone(tier, invoice.customer.tier);
|
|
197
|
+
const portalBase = options.paymentPortalUrl || 'https://pay.cashhound.io';
|
|
198
|
+
// SEC-08: Enforce HTTPS scheme and encode URI parameters to prevent open redirects and parameter pollution
|
|
199
|
+
if (!portalBase.startsWith('https://')) {
|
|
200
|
+
throw new Error('Insecure payment portal URL scheme: HTTPS required');
|
|
201
|
+
}
|
|
202
|
+
const paymentLink = `${portalBase}/pay/${encodeURIComponent(invoice.id)}?amt=${encodeURIComponent(invoice.balance)}`;
|
|
203
|
+
|
|
204
|
+
const formattedBalance = `$${invoice.balance.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
|
|
205
|
+
const formattedDueDate = invoice.dueDate.toISOString().split('T')[0];
|
|
206
|
+
const customerName = invoice.customer.name;
|
|
207
|
+
const invoiceId = invoice.id;
|
|
208
|
+
|
|
209
|
+
let installmentPlan = null;
|
|
210
|
+
if (options.includeInstallmentPlan || (tier >= DunningTier.TIER_3_URGENT && invoice.balance >= 1000)) {
|
|
211
|
+
installmentPlan = calculateInstallmentPlan(invoice.balance, {
|
|
212
|
+
startDate: asOf,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let settlementOffer = null;
|
|
217
|
+
if (options.includeSettlementOffer || (tier === DunningTier.TIER_4_FINAL_DEMAND && invoice.balance >= 500)) {
|
|
218
|
+
settlementOffer = calculateSettlementOffer(invoice.balance, {
|
|
219
|
+
asOfDate: asOf,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let subject = '';
|
|
224
|
+
let bodyLines = [];
|
|
225
|
+
const suggestedActions = ['PAY_NOW'];
|
|
226
|
+
|
|
227
|
+
switch (tier) {
|
|
228
|
+
case DunningTier.TIER_1_COURTESY: {
|
|
229
|
+
if (tone === DunningTone.EMPATHETIC || tone === DunningTone.FRIENDLY) {
|
|
230
|
+
subject = `Friendly reminder: Invoice ${invoiceId} for ${customerName}`;
|
|
231
|
+
bodyLines = [
|
|
232
|
+
`Hi ${customerName},`,
|
|
233
|
+
'',
|
|
234
|
+
`We hope all is well! We wanted to quickly check in regarding Invoice ${invoiceId} for ${formattedBalance}, which was due on ${formattedDueDate}.`,
|
|
235
|
+
`We know days get busy, so if this already crossed in the mail or was scheduled, please feel free to disregard this note.`,
|
|
236
|
+
'',
|
|
237
|
+
`You can view and settle your invoice conveniently here:`,
|
|
238
|
+
`${paymentLink}`,
|
|
239
|
+
'',
|
|
240
|
+
`If you have any questions or need a copy of the original invoice, let us know!`,
|
|
241
|
+
'',
|
|
242
|
+
`Warm regards,`,
|
|
243
|
+
`Accounts Receivable Team`,
|
|
244
|
+
];
|
|
245
|
+
} else {
|
|
246
|
+
subject = `Notice: Invoice ${invoiceId} payment due`;
|
|
247
|
+
bodyLines = [
|
|
248
|
+
`Dear ${customerName},`,
|
|
249
|
+
'',
|
|
250
|
+
`This is a courtesy reminder that Invoice ${invoiceId} with a balance of ${formattedBalance} was due on ${formattedDueDate}.`,
|
|
251
|
+
`Please arrange for payment at your earliest convenience using our secure portal:`,
|
|
252
|
+
`${paymentLink}`,
|
|
253
|
+
'',
|
|
254
|
+
`Thank you for your prompt attention to this matter.`,
|
|
255
|
+
'',
|
|
256
|
+
`Sincerely,`,
|
|
257
|
+
`Finance Department`,
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
case DunningTier.TIER_2_REMINDER: {
|
|
264
|
+
suggestedActions.push('REQUEST_REVIEW');
|
|
265
|
+
if (tone === DunningTone.EMPATHETIC) {
|
|
266
|
+
subject = `Checking in regarding Invoice ${invoiceId} (${formattedBalance})`;
|
|
267
|
+
bodyLines = [
|
|
268
|
+
`Hello ${customerName},`,
|
|
269
|
+
'',
|
|
270
|
+
`We noticed that Invoice ${invoiceId} for ${formattedBalance} is now ${daysOverdue} days overdue (due date: ${formattedDueDate}).`,
|
|
271
|
+
`We value our partnership and want to make sure there are no questions or discrepancies holding up payment.`,
|
|
272
|
+
'',
|
|
273
|
+
`You can make a direct payment here:`,
|
|
274
|
+
`${paymentLink}`,
|
|
275
|
+
'',
|
|
276
|
+
`If anything is preventing payment, please reply directly so we can work together on a solution.`,
|
|
277
|
+
'',
|
|
278
|
+
`Best regards,`,
|
|
279
|
+
`Accounts Receivable`,
|
|
280
|
+
];
|
|
281
|
+
} else {
|
|
282
|
+
subject = `Follow-Up: Overdue Invoice ${invoiceId} - Action Required`;
|
|
283
|
+
bodyLines = [
|
|
284
|
+
`Dear ${customerName},`,
|
|
285
|
+
'',
|
|
286
|
+
`Our records indicate that Invoice ${invoiceId} for the amount of ${formattedBalance} remains outstanding. Payment was due on ${formattedDueDate} (${daysOverdue} days ago).`,
|
|
287
|
+
'',
|
|
288
|
+
`Please remit payment today via the following link:`,
|
|
289
|
+
`${paymentLink}`,
|
|
290
|
+
'',
|
|
291
|
+
`If payment has already been sent, please reply with the remittance details so we can update your account.`,
|
|
292
|
+
'',
|
|
293
|
+
`Sincerely,`,
|
|
294
|
+
`Accounts Receivable Team`,
|
|
295
|
+
];
|
|
296
|
+
}
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
case DunningTier.TIER_3_URGENT: {
|
|
301
|
+
suggestedActions.push('PAYMENT_PLAN_REQUEST');
|
|
302
|
+
subject = `Urgent: Overdue Account Alert for Invoice ${invoiceId}`;
|
|
303
|
+
bodyLines = [
|
|
304
|
+
`Dear ${customerName},`,
|
|
305
|
+
'',
|
|
306
|
+
`Invoice ${invoiceId} with an unpaid balance of ${formattedBalance} is critically past due (${daysOverdue} days overdue).`,
|
|
307
|
+
`To ensure continued uninterrupted service and avoid further escalation, please settle this balance immediately:`,
|
|
308
|
+
`${paymentLink}`,
|
|
309
|
+
];
|
|
310
|
+
|
|
311
|
+
if (installmentPlan) {
|
|
312
|
+
bodyLines.push(
|
|
313
|
+
'',
|
|
314
|
+
`Flexible Payment Plan Available:`,
|
|
315
|
+
`If you are experiencing temporary cash flow challenges, we have approved a flexible payment plan:`,
|
|
316
|
+
`- ${installmentPlan.summary}`,
|
|
317
|
+
`- Settle in installments via: ${paymentLink}&plan=installments`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
bodyLines.push(
|
|
322
|
+
'',
|
|
323
|
+
`Please contact us immediately if there are any unresolved disputes or questions regarding this charge.`,
|
|
324
|
+
'',
|
|
325
|
+
`Finance & Collections Operations`,
|
|
326
|
+
);
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
case DunningTier.TIER_4_FINAL_DEMAND:
|
|
331
|
+
default: {
|
|
332
|
+
suggestedActions.push('LEGAL_ESCALATION_WARNING');
|
|
333
|
+
subject = `FINAL DEMAND: Immediate Payment Required for Invoice ${invoiceId}`;
|
|
334
|
+
bodyLines = [
|
|
335
|
+
`ATTENTION: ${customerName}`,
|
|
336
|
+
'',
|
|
337
|
+
`Invoice ${invoiceId} is now ${daysOverdue} days delinquent, with a remaining unpaid balance of ${formattedBalance}.`,
|
|
338
|
+
`Despite multiple prior notices, this account remains unresolved. Continued non-payment will result in suspension of account privileges and referral to our legal recovery team or external collections.`,
|
|
339
|
+
'',
|
|
340
|
+
`IMMEDIATE RESOLUTION REQUIRED:`,
|
|
341
|
+
`Please remit the outstanding balance immediately:`,
|
|
342
|
+
`${paymentLink}`,
|
|
343
|
+
];
|
|
344
|
+
|
|
345
|
+
if (settlementOffer) {
|
|
346
|
+
suggestedActions.push('SETTLEMENT_OFFER');
|
|
347
|
+
bodyLines.push(
|
|
348
|
+
'',
|
|
349
|
+
`One-Time Settlement Option:`,
|
|
350
|
+
`${settlementOffer.terms}`,
|
|
351
|
+
`Redeem settlement offer online: ${paymentLink}&settle=${settlementOffer.offerCode}`
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
bodyLines.push(
|
|
356
|
+
'',
|
|
357
|
+
`Govern yourself accordingly.`,
|
|
358
|
+
'',
|
|
359
|
+
`Office of Credit and Legal Compliance`,
|
|
360
|
+
);
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return {
|
|
366
|
+
invoiceId,
|
|
367
|
+
tier,
|
|
368
|
+
tierName: Object.keys(DunningTier).find(key => DunningTier[key] === tier) || 'TIER_UNKNOWN',
|
|
369
|
+
tone,
|
|
370
|
+
daysOverdue,
|
|
371
|
+
balance: invoice.balance,
|
|
372
|
+
subject,
|
|
373
|
+
body: bodyLines.join('\n'),
|
|
374
|
+
paymentLink,
|
|
375
|
+
suggestedActions,
|
|
376
|
+
installmentPlan,
|
|
377
|
+
settlementOffer,
|
|
378
|
+
generatedAt: asOf.toISOString(),
|
|
379
|
+
};
|
|
380
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CashHound - Autonomous SMB Revenue Recovery Agent
|
|
3
|
+
* Primary module entry point.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
Invoice,
|
|
8
|
+
AgingBuckets,
|
|
9
|
+
InvoiceStatus,
|
|
10
|
+
CustomerTier,
|
|
11
|
+
PriorityLevel,
|
|
12
|
+
} from './invoice.js';
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
DunningTier,
|
|
16
|
+
DunningTone,
|
|
17
|
+
generateDunningMessage,
|
|
18
|
+
calculateInstallmentPlan,
|
|
19
|
+
calculateSettlementOffer,
|
|
20
|
+
getRecommendedTier,
|
|
21
|
+
resolveTone,
|
|
22
|
+
} from './dunning.js';
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
CashHoundAgent,
|
|
26
|
+
ActionStatus,
|
|
27
|
+
AgentDecisionType,
|
|
28
|
+
} from './agent.js';
|
|
29
|
+
|
|
30
|
+
export { CashHoundMobileAdapter } from './mobile.js';
|
|
31
|
+
export { SettlementNpvOptimizer, RECOVERY_PROBABILITIES } from './npv-optimizer.js';
|
|
32
|
+
export { BankFeedReconciler } from './bank-reconciler.js';
|