From 4628395cd022be33007c82d24e8e5f277b4d6f0a Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 22 Aug 2026 19:03:33 +0200 Subject: [PATCH] Extend holdings table with activities count --- apps/api/src/app/endpoints/ai/ai.service.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/api/src/app/endpoints/ai/ai.service.ts b/apps/api/src/app/endpoints/ai/ai.service.ts index 4e35ff5ef..653e4423a 100644 --- a/apps/api/src/app/endpoints/ai/ai.service.ts +++ b/apps/api/src/app/endpoints/ai/ai.service.ts @@ -19,6 +19,7 @@ import type { ColumnDescriptor } from 'tablemark'; export class AiService { private static readonly HOLDINGS_TABLE_COLUMN_DEFINITIONS: ({ key: + | 'ACTIVITIES_COUNT' | 'ALLOCATION_PERCENTAGE' | 'ASSET_CLASS' | 'ASSET_SUB_CLASS' @@ -33,6 +34,7 @@ export class AiService { { key: 'ASSET_CLASS', name: 'Asset Class' }, { key: 'ASSET_SUB_CLASS', name: 'Asset Sub Class' }, { key: 'DATE_OF_FIRST_ACTIVITY', name: 'Date of First Activity' }, + { align: 'right', key: 'ACTIVITIES_COUNT', name: 'Activities Count' }, { align: 'right', key: 'ALLOCATION_PERCENTAGE', @@ -101,6 +103,7 @@ export class AiService { }) .map( ({ + activitiesCount, allocationInPercentage, assetProfile: { assetClass, @@ -114,6 +117,10 @@ export class AiService { return AiService.HOLDINGS_TABLE_COLUMN_DEFINITIONS.reduce( (row, { key, name }) => { switch (key) { + case 'ACTIVITIES_COUNT': + row[name] = activitiesCount.toString(); + break; + case 'ALLOCATION_PERCENTAGE': row[name] = `${(allocationInPercentage * 100).toFixed(3)}%`; break; @@ -163,17 +170,21 @@ export class AiService { ) => Promise; const { tablemark } = await dynamicImport('tablemark'); - const holdingsTableString = tablemark(holdingsTableRows, { - columns: holdingsTableColumns - }); + const holdingsSection = [ + '## Holdings', + '', + tablemark(holdingsTableRows, { + columns: holdingsTableColumns + }) + ].join('\n'); if (mode === 'portfolio') { - return holdingsTableString; + return holdingsSection; } return [ `You are a neutral financial assistant. Please analyze the following investment portfolio (base currency being ${userCurrency}) in simple words.`, - holdingsTableString, + holdingsSection, 'Structure your answer with these sections:', 'Overview: Briefly summarize the portfolio’s composition and allocation rationale.', 'Risk Assessment: Identify potential risks, including market volatility, concentration, and sectoral imbalances.',