@forumviriumhelsinki/podio-mcp 2.3.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.
Files changed (197) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +491 -0
  3. package/build/__tests__/integration/setup.integration.d.ts +104 -0
  4. package/build/__tests__/integration/setup.integration.d.ts.map +1 -0
  5. package/build/__tests__/integration/setup.integration.js +233 -0
  6. package/build/__tests__/integration/setup.integration.js.map +1 -0
  7. package/build/__tests__/mock-data/items-mock-data.d.ts +168 -0
  8. package/build/__tests__/mock-data/items-mock-data.d.ts.map +1 -0
  9. package/build/__tests__/mock-data/items-mock-data.js +370 -0
  10. package/build/__tests__/mock-data/items-mock-data.js.map +1 -0
  11. package/build/__tests__/mock-data/notification-mock-data.d.ts +55 -0
  12. package/build/__tests__/mock-data/notification-mock-data.d.ts.map +1 -0
  13. package/build/__tests__/mock-data/notification-mock-data.js +190 -0
  14. package/build/__tests__/mock-data/notification-mock-data.js.map +1 -0
  15. package/build/__tests__/mock-data/project-epic-mock-data.d.ts +45 -0
  16. package/build/__tests__/mock-data/project-epic-mock-data.d.ts.map +1 -0
  17. package/build/__tests__/mock-data/project-epic-mock-data.js +85 -0
  18. package/build/__tests__/mock-data/project-epic-mock-data.js.map +1 -0
  19. package/build/__tests__/mock-data/tasks-mock-data.d.ts +27 -0
  20. package/build/__tests__/mock-data/tasks-mock-data.d.ts.map +1 -0
  21. package/build/__tests__/mock-data/tasks-mock-data.js +104 -0
  22. package/build/__tests__/mock-data/tasks-mock-data.js.map +1 -0
  23. package/build/__tests__/mock-data/utility-mock-data.d.ts +19 -0
  24. package/build/__tests__/mock-data/utility-mock-data.d.ts.map +1 -0
  25. package/build/__tests__/mock-data/utility-mock-data.js +165 -0
  26. package/build/__tests__/mock-data/utility-mock-data.js.map +1 -0
  27. package/build/__tests__/setup.d.ts +8 -0
  28. package/build/__tests__/setup.d.ts.map +1 -0
  29. package/build/__tests__/setup.js +31 -0
  30. package/build/__tests__/setup.js.map +1 -0
  31. package/build/__tests__/utils/test-helpers.d.ts +110 -0
  32. package/build/__tests__/utils/test-helpers.d.ts.map +1 -0
  33. package/build/__tests__/utils/test-helpers.js +222 -0
  34. package/build/__tests__/utils/test-helpers.js.map +1 -0
  35. package/build/api/podio-api-client.d.ts +364 -0
  36. package/build/api/podio-api-client.d.ts.map +1 -0
  37. package/build/api/podio-api-client.js +696 -0
  38. package/build/api/podio-api-client.js.map +1 -0
  39. package/build/cache/app-cache.d.ts +77 -0
  40. package/build/cache/app-cache.d.ts.map +1 -0
  41. package/build/cache/app-cache.js +230 -0
  42. package/build/cache/app-cache.js.map +1 -0
  43. package/build/cache/base-cache-manager.d.ts +149 -0
  44. package/build/cache/base-cache-manager.d.ts.map +1 -0
  45. package/build/cache/base-cache-manager.js +312 -0
  46. package/build/cache/base-cache-manager.js.map +1 -0
  47. package/build/cache/cache-manager.d.ts +230 -0
  48. package/build/cache/cache-manager.d.ts.map +1 -0
  49. package/build/cache/cache-manager.js +362 -0
  50. package/build/cache/cache-manager.js.map +1 -0
  51. package/build/cache/cache-test.d.ts +9 -0
  52. package/build/cache/cache-test.d.ts.map +1 -0
  53. package/build/cache/cache-test.js +169 -0
  54. package/build/cache/cache-test.js.map +1 -0
  55. package/build/cache/index.d.ts +18 -0
  56. package/build/cache/index.d.ts.map +1 -0
  57. package/build/cache/index.js +20 -0
  58. package/build/cache/index.js.map +1 -0
  59. package/build/cache/migration-helper.d.ts +44 -0
  60. package/build/cache/migration-helper.d.ts.map +1 -0
  61. package/build/cache/migration-helper.js +235 -0
  62. package/build/cache/migration-helper.js.map +1 -0
  63. package/build/cache/project-epic-cache.d.ts +108 -0
  64. package/build/cache/project-epic-cache.d.ts.map +1 -0
  65. package/build/cache/project-epic-cache.js +278 -0
  66. package/build/cache/project-epic-cache.js.map +1 -0
  67. package/build/cache/space-members-cache.d.ts +99 -0
  68. package/build/cache/space-members-cache.d.ts.map +1 -0
  69. package/build/cache/space-members-cache.js +305 -0
  70. package/build/cache/space-members-cache.js.map +1 -0
  71. package/build/cache/storage-adapters.d.ts +100 -0
  72. package/build/cache/storage-adapters.d.ts.map +1 -0
  73. package/build/cache/storage-adapters.js +297 -0
  74. package/build/cache/storage-adapters.js.map +1 -0
  75. package/build/errors/api-errors.d.ts +52 -0
  76. package/build/errors/api-errors.d.ts.map +1 -0
  77. package/build/errors/api-errors.js +86 -0
  78. package/build/errors/api-errors.js.map +1 -0
  79. package/build/errors/auth-errors.d.ts +67 -0
  80. package/build/errors/auth-errors.d.ts.map +1 -0
  81. package/build/errors/auth-errors.js +114 -0
  82. package/build/errors/auth-errors.js.map +1 -0
  83. package/build/errors/base.d.ts +102 -0
  84. package/build/errors/base.d.ts.map +1 -0
  85. package/build/errors/base.js +131 -0
  86. package/build/errors/base.js.map +1 -0
  87. package/build/errors/cache-errors.d.ts +53 -0
  88. package/build/errors/cache-errors.d.ts.map +1 -0
  89. package/build/errors/cache-errors.js +83 -0
  90. package/build/errors/cache-errors.js.map +1 -0
  91. package/build/errors/config-errors.d.ts +58 -0
  92. package/build/errors/config-errors.d.ts.map +1 -0
  93. package/build/errors/config-errors.js +96 -0
  94. package/build/errors/config-errors.js.map +1 -0
  95. package/build/errors/index.d.ts +101 -0
  96. package/build/errors/index.d.ts.map +1 -0
  97. package/build/errors/index.js +135 -0
  98. package/build/errors/index.js.map +1 -0
  99. package/build/errors/structure-errors.d.ts +89 -0
  100. package/build/errors/structure-errors.d.ts.map +1 -0
  101. package/build/errors/structure-errors.js +182 -0
  102. package/build/errors/structure-errors.js.map +1 -0
  103. package/build/errors/validation-errors.d.ts +81 -0
  104. package/build/errors/validation-errors.d.ts.map +1 -0
  105. package/build/errors/validation-errors.js +169 -0
  106. package/build/errors/validation-errors.js.map +1 -0
  107. package/build/fields/field-mapper.d.ts +245 -0
  108. package/build/fields/field-mapper.d.ts.map +1 -0
  109. package/build/fields/field-mapper.js +404 -0
  110. package/build/fields/field-mapper.js.map +1 -0
  111. package/build/index.d.ts +550 -0
  112. package/build/index.d.ts.map +1 -0
  113. package/build/index.js +1527 -0
  114. package/build/index.js.map +1 -0
  115. package/build/oauth-helper.d.ts +189 -0
  116. package/build/oauth-helper.d.ts.map +1 -0
  117. package/build/oauth-helper.js +422 -0
  118. package/build/oauth-helper.js.map +1 -0
  119. package/build/services/app-structure-service.d.ts +49 -0
  120. package/build/services/app-structure-service.d.ts.map +1 -0
  121. package/build/services/app-structure-service.js +122 -0
  122. package/build/services/app-structure-service.js.map +1 -0
  123. package/build/services/code-execution-service.d.ts +88 -0
  124. package/build/services/code-execution-service.d.ts.map +1 -0
  125. package/build/services/code-execution-service.js +342 -0
  126. package/build/services/code-execution-service.js.map +1 -0
  127. package/build/services/comment-service.d.ts +66 -0
  128. package/build/services/comment-service.d.ts.map +1 -0
  129. package/build/services/comment-service.js +139 -0
  130. package/build/services/comment-service.js.map +1 -0
  131. package/build/services/index.d.ts +16 -0
  132. package/build/services/index.d.ts.map +1 -0
  133. package/build/services/index.js +15 -0
  134. package/build/services/index.js.map +1 -0
  135. package/build/services/item-service.d.ts +104 -0
  136. package/build/services/item-service.d.ts.map +1 -0
  137. package/build/services/item-service.js +368 -0
  138. package/build/services/item-service.js.map +1 -0
  139. package/build/services/notification-service.d.ts +125 -0
  140. package/build/services/notification-service.d.ts.map +1 -0
  141. package/build/services/notification-service.js +321 -0
  142. package/build/services/notification-service.js.map +1 -0
  143. package/build/services/project-epic-service.d.ts +73 -0
  144. package/build/services/project-epic-service.d.ts.map +1 -0
  145. package/build/services/project-epic-service.js +248 -0
  146. package/build/services/project-epic-service.js.map +1 -0
  147. package/build/services/response-formatter.d.ts +190 -0
  148. package/build/services/response-formatter.d.ts.map +1 -0
  149. package/build/services/response-formatter.js +1221 -0
  150. package/build/services/response-formatter.js.map +1 -0
  151. package/build/services/search-service.d.ts +103 -0
  152. package/build/services/search-service.d.ts.map +1 -0
  153. package/build/services/search-service.js +273 -0
  154. package/build/services/search-service.js.map +1 -0
  155. package/build/services/task-service.d.ts +70 -0
  156. package/build/services/task-service.d.ts.map +1 -0
  157. package/build/services/task-service.js +156 -0
  158. package/build/services/task-service.js.map +1 -0
  159. package/build/tools/index.d.ts +8 -0
  160. package/build/tools/index.d.ts.map +1 -0
  161. package/build/tools/index.js +8 -0
  162. package/build/tools/index.js.map +1 -0
  163. package/build/tools/tool-definitions.d.ts +89 -0
  164. package/build/tools/tool-definitions.d.ts.map +1 -0
  165. package/build/tools/tool-definitions.js +1167 -0
  166. package/build/tools/tool-definitions.js.map +1 -0
  167. package/build/types/api-types.d.ts +106 -0
  168. package/build/types/api-types.d.ts.map +1 -0
  169. package/build/types/api-types.js +11 -0
  170. package/build/types/api-types.js.map +1 -0
  171. package/build/types/cache-types.d.ts +52 -0
  172. package/build/types/cache-types.d.ts.map +1 -0
  173. package/build/types/cache-types.js +12 -0
  174. package/build/types/cache-types.js.map +1 -0
  175. package/build/types/index.d.ts +31 -0
  176. package/build/types/index.d.ts.map +1 -0
  177. package/build/types/index.js +25 -0
  178. package/build/types/index.js.map +1 -0
  179. package/build/types/notification-types.d.ts +154 -0
  180. package/build/types/notification-types.d.ts.map +1 -0
  181. package/build/types/notification-types.js +7 -0
  182. package/build/types/notification-types.js.map +1 -0
  183. package/build/types/podio-types.d.ts +250 -0
  184. package/build/types/podio-types.d.ts.map +1 -0
  185. package/build/types/podio-types.js +11 -0
  186. package/build/types/podio-types.js.map +1 -0
  187. package/build/types/search-types.d.ts +188 -0
  188. package/build/types/search-types.d.ts.map +1 -0
  189. package/build/types/search-types.js +43 -0
  190. package/build/types/search-types.js.map +1 -0
  191. package/build/utils/debug.d.ts +58 -0
  192. package/build/utils/debug.d.ts.map +1 -0
  193. package/build/utils/debug.js +147 -0
  194. package/build/utils/debug.js.map +1 -0
  195. package/examples/claude-config-example.json +13 -0
  196. package/package.json +87 -0
  197. package/scripts/generate-claude-config.js +107 -0
@@ -0,0 +1,1221 @@
1
+ /**
2
+ * @fileoverview Response Formatter Service
3
+ *
4
+ * This service handles formatting of all MCP tool responses to ensure consistency
5
+ * across all tools and reduce duplication in the main server class.
6
+ */
7
+ import { SearchType, } from '../types/search-types.js';
8
+ import { debug } from '../utils/debug.js';
9
+ /**
10
+ * Response formatting service for MCP tools.
11
+ *
12
+ * This service centralizes all response formatting logic to ensure consistency
13
+ * and reduce code duplication throughout the server.
14
+ */
15
+ export class ResponseFormatter {
16
+ // ===============================
17
+ // APP STRUCTURE RESPONSES
18
+ // ===============================
19
+ /**
20
+ * Format app structure response
21
+ */
22
+ static formatAppStructure(appStructure, coordinates, cachedApp, fieldMapper) {
23
+ const appName = coordinates?.app_label || 'Unknown App';
24
+ let result = `✅ Successfully loaded app structure for ${appName}!\n\n`;
25
+ result += `**App ID:** ${appStructure.app_id}\n`;
26
+ if (coordinates) {
27
+ result += `**Organization:** ${coordinates.org_label}\n`;
28
+ result += `**Space:** ${coordinates.space_label}\n`;
29
+ result += `**App:** ${coordinates.app_label}\n`;
30
+ }
31
+ if (cachedApp) {
32
+ result += `**Cached:** ${cachedApp.cached_at}\n`;
33
+ }
34
+ result += `**Fields:** ${appStructure.fields.length} fields available\n`;
35
+ // Show field summary
36
+ if (fieldMapper) {
37
+ const fieldTypes = fieldMapper.getFieldStats();
38
+ result += `**Field Types:** ${Object.entries(fieldTypes.fieldTypes)
39
+ .map(([type, count]) => `${type} (${count})`)
40
+ .join(', ')}\n\n`;
41
+ }
42
+ result +=
43
+ 'The app structure has been cached for subsequent operations. You can now list items, create items, etc.';
44
+ return {
45
+ content: [
46
+ {
47
+ type: 'text',
48
+ text: result,
49
+ },
50
+ ],
51
+ };
52
+ }
53
+ /**
54
+ * Format cached apps list response
55
+ * Supports both the old format (array of CachedApp) and new multi-app format
56
+ */
57
+ static formatCachedAppsList(data) {
58
+ // Handle new multi-app format
59
+ if (data && typeof data === 'object' && !Array.isArray(data)) {
60
+ const { loadedInMemory, cachedInStorage, activeApp } = data;
61
+ let result = '🗂️ **App Structure Status**\n\n';
62
+ // Show loaded apps in memory
63
+ if (loadedInMemory && loadedInMemory.length > 0) {
64
+ result += `## Currently Loaded in Memory (${loadedInMemory.length})\n\n`;
65
+ loadedInMemory.forEach((app) => {
66
+ const isActive = app.isActive ? ' ⭐ **[ACTIVE]**' : '';
67
+ result += `📱 **${app.appName}**${isActive}\n`;
68
+ result += ` ID: ${app.appId}\n`;
69
+ result += ` Coordinates: ${app.coordinates}\n`;
70
+ result += ` Fields: ${app.fieldsCount}\n\n`;
71
+ });
72
+ }
73
+ else {
74
+ result += '## Currently Loaded in Memory\n\nNo apps loaded in memory.\n\n';
75
+ }
76
+ // Show cached apps in storage
77
+ if (cachedInStorage && cachedInStorage.length > 0) {
78
+ result += `## Cached in Storage (${cachedInStorage.length})\n\n`;
79
+ cachedInStorage.forEach((app) => {
80
+ result += `💾 **${app.name}** (ID: ${app.app_id})\n`;
81
+ result += ` Organization: ${app.coordinates.org_label}\n`;
82
+ result += ` Space: ${app.coordinates.space_label}\n`;
83
+ result += ` App: ${app.coordinates.app_label}\n`;
84
+ result += ` Cached: ${new Date(app.cached_at).toLocaleString()}\n`;
85
+ result += ` Fields: ${app.structure.fields.length}\n\n`;
86
+ });
87
+ }
88
+ else {
89
+ result += '## Cached in Storage\n\nNo apps cached in storage.\n\n';
90
+ }
91
+ result += '---\n';
92
+ result += '💡 **Tips:**\n';
93
+ result += '• Use `get_app_structure` to load an app into memory\n';
94
+ result += '• Use `set_active_app` to switch between loaded apps\n';
95
+ result += '• Use `clear_app_cache` to remove apps from cache\n';
96
+ return {
97
+ content: [
98
+ {
99
+ type: 'text',
100
+ text: result,
101
+ },
102
+ ],
103
+ };
104
+ }
105
+ // Handle legacy format (backward compatibility)
106
+ const cachedApps = data;
107
+ if (cachedApps.length === 0) {
108
+ return {
109
+ content: [
110
+ {
111
+ type: 'text',
112
+ text: 'No cached apps found. Use get_app_structure or cache_app_structure to cache apps.',
113
+ },
114
+ ],
115
+ };
116
+ }
117
+ let result = `Found ${cachedApps.length} cached apps:\n\n`;
118
+ cachedApps.forEach((app) => {
119
+ result += `📱 **${app.name}** (ID: ${app.app_id})\n`;
120
+ result += ` Organization: ${app.coordinates.org_label}\n`;
121
+ result += ` Space: ${app.coordinates.space_label}\n`;
122
+ result += ` App: ${app.coordinates.app_label}\n`;
123
+ result += ` Cached: ${new Date(app.cached_at).toLocaleString()}\n`;
124
+ result += ` Fields: ${app.structure.fields.length}\n\n`;
125
+ });
126
+ return {
127
+ content: [
128
+ {
129
+ type: 'text',
130
+ text: result,
131
+ },
132
+ ],
133
+ };
134
+ }
135
+ // ===============================
136
+ // ITEM RESPONSES
137
+ // ===============================
138
+ /**
139
+ * Format items list response
140
+ */
141
+ static formatItemsList(items, filteredItems, fieldMapper, responsibleFilter) {
142
+ const resultCount = responsibleFilter ? filteredItems.length : items.length;
143
+ const filterText = responsibleFilter
144
+ ? ` matching responsible filter "${responsibleFilter}"`
145
+ : '';
146
+ let result = `Found ${resultCount} items${filterText}:\n\n`;
147
+ filteredItems.forEach((item) => {
148
+ const title = fieldMapper.extractTitle(item);
149
+ const status = fieldMapper.extractCategoryText(item, 'Status');
150
+ const responsible = fieldMapper.extractContactProperty(item, 'Responsible', 'name');
151
+ // Show both app_item_id (ticket number) and global item_id
152
+ const ticketNum = item.app_item_id || item.app_item_id_formatted;
153
+ result += `📋 **${title}** (Ticket #${ticketNum}, ID: ${item.item_id})\n`;
154
+ result += ` Status: ${status}\n`;
155
+ result += ` Responsible: ${responsible}\n`;
156
+ result += ` Link: ${item.link}\n\n`;
157
+ });
158
+ return {
159
+ content: [
160
+ {
161
+ type: 'text',
162
+ text: result,
163
+ },
164
+ ],
165
+ };
166
+ }
167
+ /**
168
+ * Format item creation success response
169
+ */
170
+ static formatItemCreated(item, fieldMapper) {
171
+ const ticketNum = item.app_item_id || item.app_item_id_formatted;
172
+ return {
173
+ content: [
174
+ {
175
+ type: 'text',
176
+ text: `✅ Successfully created item!\n\n` +
177
+ `Title: ${fieldMapper.extractTitle(item)}\n` +
178
+ `Ticket Number: #${ticketNum}\n` +
179
+ `Global ID: ${item.item_id}\n` +
180
+ `Link: ${item.link}`,
181
+ },
182
+ ],
183
+ };
184
+ }
185
+ /**
186
+ * Format item details response
187
+ */
188
+ static formatItemDetails(item, fieldMapper) {
189
+ const title = fieldMapper.extractTitle(item);
190
+ const status = fieldMapper.extractCategoryText(item, 'Status');
191
+ const responsible = fieldMapper.extractContactProperty(item, 'Responsible', 'name');
192
+ const description = fieldMapper.extractTextValue(item, 'Description');
193
+ const project = fieldMapper.extractAppReferenceTitle(item, 'Project');
194
+ const epic = fieldMapper.extractAppReferenceTitle(item, 'Epic');
195
+ // Show both IDs prominently
196
+ const ticketNum = item.app_item_id || item.app_item_id_formatted;
197
+ let result = `📋 **${title}**\n\n`;
198
+ result += `**Ticket Number:** #${ticketNum} (App Item ID)\n`;
199
+ result += `**Global ID:** ${item.item_id}\n`;
200
+ result += `**Status:** ${status}\n`;
201
+ result += `**Responsible:** ${responsible}\n`;
202
+ result += `**Project:** ${project}\n`;
203
+ result += `**Epic:** ${epic}\n`;
204
+ result += `**Created:** ${item.created_on}\n`;
205
+ result += `**Link:** ${item.link}\n\n`;
206
+ if (description && description !== 'N/A') {
207
+ result += `**Description:**\n${ResponseFormatter.cleanHtmlContent(description)}\n\n`;
208
+ }
209
+ return {
210
+ content: [
211
+ {
212
+ type: 'text',
213
+ text: result,
214
+ },
215
+ ],
216
+ };
217
+ }
218
+ // ===============================
219
+ // TASK RESPONSES
220
+ // ===============================
221
+ /**
222
+ * Format tasks list response
223
+ */
224
+ static formatTasksList(tasks) {
225
+ let result = `Found ${tasks.length} tasks:\n\n`;
226
+ tasks.forEach((task) => {
227
+ result += `📝 **${task.text}** (ID: ${task.task_id})\n`;
228
+ result += ` Status: ${task.status}\n`;
229
+ result += ` Due: ${task.due_date || 'No due date'}\n`;
230
+ result += ` Link: ${task.link}\n\n`;
231
+ });
232
+ return {
233
+ content: [
234
+ {
235
+ type: 'text',
236
+ text: result,
237
+ },
238
+ ],
239
+ };
240
+ }
241
+ /**
242
+ * Format task creation success response
243
+ */
244
+ static formatTaskCreated(task, itemId) {
245
+ const text = itemId
246
+ ? `✅ Successfully created task for item ${itemId}!\n\n`
247
+ : `✅ Successfully created task!\n\n`;
248
+ return {
249
+ content: [
250
+ {
251
+ type: 'text',
252
+ text: text + `Title: ${task.text}\n` + `Task ID: ${task.task_id}\n` + `Link: ${task.link}`,
253
+ },
254
+ ],
255
+ };
256
+ }
257
+ /**
258
+ * Format task update success response
259
+ */
260
+ static formatTaskUpdated(task) {
261
+ return {
262
+ content: [
263
+ {
264
+ type: 'text',
265
+ text: `✅ Successfully updated task ${task.task_id}!\n` +
266
+ `Title: ${task.text}\n` +
267
+ `Status: ${task.status}`,
268
+ },
269
+ ],
270
+ };
271
+ }
272
+ /**
273
+ * Format task details response
274
+ */
275
+ static formatTaskDetails(task) {
276
+ let result = `📋 **${task.text}** (ID: ${task.task_id})\n\n`;
277
+ result += `**Status:** ${task.status}\n`;
278
+ result += `**Due Date:** ${task.due_date || 'No due date'}\n`;
279
+ result += `**Created:** ${task.created_on}\n`;
280
+ result += `**Link:** ${task.link}\n\n`;
281
+ if (task.description && task.description.trim()) {
282
+ result += `**Description:**\n${task.description}\n\n`;
283
+ }
284
+ if (task.responsible) {
285
+ result += `**Responsible:** ${JSON.stringify(task.responsible)}\n`;
286
+ }
287
+ return {
288
+ content: [
289
+ {
290
+ type: 'text',
291
+ text: result,
292
+ },
293
+ ],
294
+ };
295
+ }
296
+ // ===============================
297
+ // PROJECT/EPIC RESPONSES
298
+ // ===============================
299
+ /**
300
+ * Format project/epic list response
301
+ */
302
+ static formatProjectEpicList(items, type) {
303
+ if (items.length === 0) {
304
+ const itemType = type.toLowerCase().slice(0, -1); // Remove 's' from plural
305
+ return {
306
+ content: [
307
+ {
308
+ type: 'text',
309
+ text: `No ${type.toLowerCase()} found.\n\n` +
310
+ `**Possible causes:**\n` +
311
+ `• The ${itemType} field is not configured in this app\n` +
312
+ `• The ${itemType} field doesn't reference any app\n` +
313
+ `• The referenced app has no items\n` +
314
+ `• Permission issues accessing the referenced app\n\n` +
315
+ `**Troubleshooting steps:**\n` +
316
+ `1. Use \`inspect_field_structure field_name="${itemType}"\` to check field configuration\n` +
317
+ `2. Verify the ${itemType} field type is "app" (relationship field)\n` +
318
+ `3. Check that the referenced app has items: navigate to it in Podio\n` +
319
+ `4. Ensure you have permissions to access the referenced app\n` +
320
+ `5. Try refreshing the cache: \`cache_app_structure refresh=true\`\n\n` +
321
+ `**Need more help?**\n` +
322
+ `• ${debug.isEnabled() ? 'Check the console logs above for detailed diagnostic information' : 'Enable debug logging with `PODIO_DEBUG=true` for diagnostic information'}\n` +
323
+ `• See documentation: https://github.com/ForumViriumHelsinki/podio-mcp/blob/main/docs/troubleshooting.md`,
324
+ },
325
+ ],
326
+ };
327
+ }
328
+ let result = `Found ${items.length} ${type.toLowerCase()}:\n\n`;
329
+ items.forEach((item) => {
330
+ result += `• **${item.title}** (ID: ${item.item_id})\n`;
331
+ });
332
+ return {
333
+ content: [
334
+ {
335
+ type: 'text',
336
+ text: result,
337
+ },
338
+ ],
339
+ };
340
+ }
341
+ /**
342
+ * Format project/epic suggestions response
343
+ */
344
+ static formatProjectEpicSuggestions(title, projects, epics) {
345
+ let result = `Based on "${title}", here are suggested projects and epics:\n\n`;
346
+ if (projects.length > 0) {
347
+ result += `**Suggested Projects:**\n`;
348
+ projects.slice(0, 3).forEach((project) => {
349
+ result += `• ${project.title} (Score: ${project.score.toFixed(2)})\n`;
350
+ });
351
+ result += '\n';
352
+ }
353
+ if (epics.length > 0) {
354
+ result += `**Suggested Epics:**\n`;
355
+ epics.slice(0, 3).forEach((epic) => {
356
+ result += `• ${epic.title} (Score: ${epic.score.toFixed(2)})\n`;
357
+ });
358
+ result += '\n';
359
+ }
360
+ if (projects.length === 0 && epics.length === 0) {
361
+ result +=
362
+ 'No specific suggestions found. You may want to check available projects and epics using list_projects and list_epics tools.';
363
+ }
364
+ return {
365
+ content: [
366
+ {
367
+ type: 'text',
368
+ text: result,
369
+ },
370
+ ],
371
+ };
372
+ }
373
+ // ===============================
374
+ // UTILITY RESPONSES
375
+ // ===============================
376
+ /**
377
+ * Format field structure inspection response
378
+ */
379
+ static formatFieldStructure(appStructure, fieldMapper, fieldName) {
380
+ if (fieldName) {
381
+ // Inspect specific field
382
+ const field = fieldMapper.findField(fieldName);
383
+ if (!field) {
384
+ return {
385
+ content: [
386
+ {
387
+ type: 'text',
388
+ text: `Field "${fieldName}" not found. Use this tool without field_name to see all available fields.`,
389
+ },
390
+ ],
391
+ };
392
+ }
393
+ let result = `**Field: ${field.label}**\n\n`;
394
+ result += `Type: ${field.type}\n`;
395
+ result += `ID: ${field.field_id}\n`;
396
+ result += `External ID: ${field.external_id || 'None'}\n`;
397
+ result += `Required: ${field.config.required ? 'Yes' : 'No'}\n\n`;
398
+ result += `Configuration:\n${JSON.stringify(field.config, null, 2)}`;
399
+ return {
400
+ content: [
401
+ {
402
+ type: 'text',
403
+ text: result,
404
+ },
405
+ ],
406
+ };
407
+ }
408
+ else {
409
+ // List all fields
410
+ const stats = fieldMapper.getFieldStats();
411
+ let result = `**App Field Structure**\n\n`;
412
+ result += `Total Fields: ${stats.totalFields}\n`;
413
+ result += `Fields with External ID: ${stats.fieldsWithExternalId}\n\n`;
414
+ result += `**Field Types:**\n`;
415
+ Object.entries(stats.fieldTypes).forEach(([type, count]) => {
416
+ result += `• ${type}: ${count}\n`;
417
+ });
418
+ result += '\n';
419
+ result += `**All Fields:**\n`;
420
+ appStructure.fields.forEach((field) => {
421
+ result += `• ${field.label} (${field.type}) - ID: ${field.field_id}`;
422
+ if (field.external_id) {
423
+ result += ` - External: ${field.external_id}`;
424
+ }
425
+ result += '\n';
426
+ });
427
+ return {
428
+ content: [
429
+ {
430
+ type: 'text',
431
+ text: result,
432
+ },
433
+ ],
434
+ };
435
+ }
436
+ }
437
+ /**
438
+ * Format space members list response
439
+ */
440
+ static formatSpaceMembersList(members) {
441
+ if (members.length === 0) {
442
+ return {
443
+ content: [
444
+ {
445
+ type: 'text',
446
+ text: 'No space members found.',
447
+ },
448
+ ],
449
+ };
450
+ }
451
+ let result = `Found ${members.length} space members:\n\n`;
452
+ members.forEach((member) => {
453
+ result += `👤 **${member.user.name}** (ID: ${member.user.user_id})\n`;
454
+ if (member.user.mail) {
455
+ result += ` Email: ${member.user.mail}\n`;
456
+ }
457
+ result += ` Role: ${member.role || 'Member'}\n\n`;
458
+ });
459
+ return {
460
+ content: [
461
+ {
462
+ type: 'text',
463
+ text: result,
464
+ },
465
+ ],
466
+ };
467
+ }
468
+ // ===============================
469
+ // GENERIC SUCCESS RESPONSES
470
+ // ===============================
471
+ /**
472
+ * Format generic success message
473
+ */
474
+ static formatSuccess(message) {
475
+ return {
476
+ content: [
477
+ {
478
+ type: 'text',
479
+ text: `✅ ${message}`,
480
+ },
481
+ ],
482
+ };
483
+ }
484
+ /**
485
+ * Format generic error message
486
+ */
487
+ static formatError(message) {
488
+ return {
489
+ content: [
490
+ {
491
+ type: 'text',
492
+ text: `❌ ${message}`,
493
+ },
494
+ ],
495
+ };
496
+ }
497
+ // ===============================
498
+ // NOTIFICATION RESPONSES
499
+ // ===============================
500
+ /**
501
+ * Helper method to safely format notification dates
502
+ * Handles various date formats from Podio API and provides fallbacks
503
+ */
504
+ static formatNotificationDate(dateString) {
505
+ if (!dateString || typeof dateString !== 'string') {
506
+ return { date: 'Unknown date', time: '' };
507
+ }
508
+ try {
509
+ // Try parsing the date string directly
510
+ let parsedDate = new Date(dateString);
511
+ // If the first attempt fails, try common format variations
512
+ if (isNaN(parsedDate.getTime())) {
513
+ // Try different format variations that might come from Podio API
514
+ const formats = [
515
+ // ISO format variations
516
+ dateString.replace(' ', 'T') + 'Z', // "2024-01-15 10:30:00" -> "2024-01-15T10:30:00Z"
517
+ dateString + 'Z', // "2024-01-15T10:30:00" -> "2024-01-15T10:30:00Z"
518
+ dateString.replace(' ', 'T'), // "2024-01-15 10:30:00" -> "2024-01-15T10:30:00"
519
+ // European date formats
520
+ dateString.replace(/(\d{2})\/(\d{2})\/(\d{4})/, '$3-$2-$1'), // DD/MM/YYYY to YYYY-MM-DD
521
+ dateString.replace(/(\d{1,2})\/(\d{1,2})\/(\d{4})/, '$3-$1-$2'), // M/D/YYYY to YYYY-M-D
522
+ // Other common formats
523
+ dateString.replace(/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/, '$1-$2-$3T$4:$5:$6'),
524
+ ];
525
+ for (const format of formats) {
526
+ try {
527
+ parsedDate = new Date(format);
528
+ if (!isNaN(parsedDate.getTime())) {
529
+ break;
530
+ }
531
+ }
532
+ catch { }
533
+ }
534
+ }
535
+ // If we still can't parse it, return a fallback
536
+ if (isNaN(parsedDate.getTime())) {
537
+ return { date: 'Unable to parse date', time: '' };
538
+ }
539
+ // Validate the parsed date is reasonable (not too far in past/future)
540
+ const now = new Date();
541
+ const hundredYearsAgo = new Date(now.getFullYear() - 100, 0, 1);
542
+ const hundredYearsFromNow = new Date(now.getFullYear() + 100, 0, 1);
543
+ if (parsedDate < hundredYearsAgo || parsedDate > hundredYearsFromNow) {
544
+ // Date is outside reasonable range, but we'll still show it
545
+ }
546
+ return {
547
+ date: parsedDate.toLocaleDateString(),
548
+ time: parsedDate.toLocaleTimeString(),
549
+ };
550
+ }
551
+ catch (error) {
552
+ return { date: 'Unable to parse date', time: '' };
553
+ }
554
+ }
555
+ /**
556
+ * Helper method to safely format notification type
557
+ * Provides meaningful fallbacks for null/undefined/empty types
558
+ */
559
+ static formatNotificationType(type) {
560
+ if (!type || type.trim() === '') {
561
+ return 'UNKNOWN';
562
+ }
563
+ return type.toUpperCase();
564
+ }
565
+ /**
566
+ * Helper method to safely format notification ID
567
+ * Provides meaningful fallbacks for null/undefined IDs
568
+ */
569
+ static formatNotificationId(id) {
570
+ if (id === null || id === undefined) {
571
+ return 'UNKNOWN-ID';
572
+ }
573
+ return id.toString();
574
+ }
575
+ /**
576
+ * Format notifications list response
577
+ */
578
+ static formatNotificationsList(notifications, filteredNotifications, totalCount, showUnreadOnly) {
579
+ const displayNotifications = filteredNotifications || notifications;
580
+ const filterText = showUnreadOnly ? ' (unread only)' : '';
581
+ if (displayNotifications.length === 0) {
582
+ return {
583
+ content: [
584
+ {
585
+ type: 'text',
586
+ text: `📬 No notifications found${filterText}.`,
587
+ },
588
+ ],
589
+ };
590
+ }
591
+ let result = `📬 **Notifications${filterText}** (${displayNotifications.length}`;
592
+ if (totalCount && totalCount !== displayNotifications.length) {
593
+ result += ` of ${totalCount}`;
594
+ }
595
+ result += ')\n\n';
596
+ displayNotifications.forEach((notification, index) => {
597
+ const viewedIcon = notification.viewed ? '👁️' : '🔴';
598
+ const { date, time } = ResponseFormatter.formatNotificationDate(notification.created_on);
599
+ const type = ResponseFormatter.formatNotificationType(notification.type);
600
+ const id = ResponseFormatter.formatNotificationId(notification.notification_id);
601
+ result += `${index + 1}. ${viewedIcon} **${type}** (#${id})
602
+ `;
603
+ result += ` ${ResponseFormatter.cleanHtmlContent(notification.text)}\n`;
604
+ result += ` 📅 ${date}${time ? ` ${time}` : ''}`;
605
+ if (notification.created_by?.name) {
606
+ result += ` | 👤 ${notification.created_by.name}`;
607
+ }
608
+ if (notification.context?.title) {
609
+ result += ` | 🔗 ${notification.context.title}`;
610
+ }
611
+ if (notification.space?.name) {
612
+ result += ` | 🏢 ${notification.space.name}`;
613
+ }
614
+ result += `\n\n`;
615
+ });
616
+ if (displayNotifications.length < totalCount) {
617
+ result += `_Showing first ${displayNotifications.length} notifications. Use limit/offset parameters to see more._`;
618
+ }
619
+ return {
620
+ content: [
621
+ {
622
+ type: 'text',
623
+ text: result.trim(),
624
+ },
625
+ ],
626
+ };
627
+ }
628
+ /**
629
+ * Format single notification details response
630
+ */
631
+ static formatNotificationDetails(notification) {
632
+ const viewedIcon = notification.viewed ? '👁️' : '🔴';
633
+ const date = new Date(notification.created_on).toLocaleDateString();
634
+ const time = new Date(notification.created_on).toLocaleTimeString();
635
+ let result = `📬 **Notification Details** ${viewedIcon}\n\n`;
636
+ result += `**ID:** ${notification.notification_id}\n`;
637
+ result += `**Type:** ${(notification.type || 'UNTYPED').toUpperCase()}\n`;
638
+ result += `**Status:** ${notification.status}\n`;
639
+ result += `**Created:** ${date} ${time}\n`;
640
+ result += `**Viewed:** ${notification.viewed ? 'Yes' : 'No'}\n\n`;
641
+ result += `**Message:**\n${ResponseFormatter.cleanHtmlContent(notification.text)}\n\n`;
642
+ if (notification.created_by) {
643
+ result += `**Created By:** ${notification.created_by.name}`;
644
+ if (notification.created_by.mail) {
645
+ result += ` (${notification.created_by.mail})`;
646
+ }
647
+ result += '\n\n';
648
+ }
649
+ if (notification.context) {
650
+ result += `**Context:**\n`;
651
+ result += `- Type: ${notification.context.type}\n`;
652
+ result += `- ID: ${notification.context.id}\n`;
653
+ if (notification.context.title) {
654
+ result += `- Title: ${notification.context.title}\n`;
655
+ }
656
+ if (notification.context.link) {
657
+ result += `- Link: ${notification.context.link}\n`;
658
+ }
659
+ result += '\n';
660
+ }
661
+ if (notification.space) {
662
+ result += `**Space:** ${notification.space.name} (ID: ${notification.space.space_id})\n`;
663
+ }
664
+ if (notification.app) {
665
+ result += `**App:** ${notification.app.name} (ID: ${notification.app.app_id})\n`;
666
+ }
667
+ if (notification.data && Object.keys(notification.data).length > 0) {
668
+ result += `\n**Additional Data:**\n`;
669
+ Object.entries(notification.data).forEach(([key, value]) => {
670
+ result += `- ${key}: ${JSON.stringify(value)}\n`;
671
+ });
672
+ }
673
+ return {
674
+ content: [
675
+ {
676
+ type: 'text',
677
+ text: result.trim(),
678
+ },
679
+ ],
680
+ };
681
+ }
682
+ /**
683
+ * Format unread notifications count response
684
+ */
685
+ static formatUnreadCount(count) {
686
+ let result = `📬 **Unread Notifications**\n\n`;
687
+ result += `🔴 **New:** ${count.new}\n`;
688
+ if (count.total !== undefined) {
689
+ result += `📋 **Total:** ${count.total}\n`;
690
+ }
691
+ if (count.new === 0) {
692
+ result += `\n✅ You're all caught up!`;
693
+ }
694
+ else {
695
+ result += `\n💡 Use \`list_notifications\` with viewed=false to see unread notifications.`;
696
+ }
697
+ return {
698
+ content: [
699
+ {
700
+ type: 'text',
701
+ text: result,
702
+ },
703
+ ],
704
+ };
705
+ }
706
+ /**
707
+ * Format notification settings response
708
+ */
709
+ static formatNotificationSettings(settings) {
710
+ let result = `⚙️ **Notification Settings**\n\n`;
711
+ result += `**Notifications:** ${settings.enabled ? '✅ Enabled' : '❌ Disabled'}\n\n`;
712
+ if (settings.email) {
713
+ result += `**Email Notifications:**\n`;
714
+ result += `- Enabled: ${settings.email.enabled ? '✅ Yes' : '❌ No'}\n`;
715
+ if (settings.email.frequency) {
716
+ result += `- Frequency: ${settings.email.frequency}\n`;
717
+ }
718
+ result += '\n';
719
+ }
720
+ if (settings.push) {
721
+ result += `**Push Notifications:**\n`;
722
+ result += `- Enabled: ${settings.push.enabled ? '✅ Yes' : '❌ No'}\n\n`;
723
+ }
724
+ if (settings.types && Object.keys(settings.types).length > 0) {
725
+ result += `**Notification Type Settings:**\n`;
726
+ Object.entries(settings.types).forEach(([type, config]) => {
727
+ result += `- **${type}**: ${config.enabled ? '✅' : '❌'}`;
728
+ const details = [];
729
+ if (config.email)
730
+ details.push('📧 Email');
731
+ if (config.push)
732
+ details.push('📱 Push');
733
+ if (details.length > 0) {
734
+ result += ` (${details.join(', ')})`;
735
+ }
736
+ result += '\n';
737
+ });
738
+ }
739
+ return {
740
+ content: [
741
+ {
742
+ type: 'text',
743
+ text: result.trim(),
744
+ },
745
+ ],
746
+ };
747
+ }
748
+ // ===============================
749
+ // SEARCH RESPONSES
750
+ // ===============================
751
+ /**
752
+ * Format search results response
753
+ */
754
+ static formatSearchResults(searchResponse) {
755
+ const { results, total, count, query, scope, search_time } = searchResponse;
756
+ let result = `🔍 **Search Results for "${query}"**\n\n`;
757
+ result += `**Scope:** ${scope.charAt(0).toUpperCase() + scope.slice(1)}\n`;
758
+ result += `**Found:** ${total} total results (showing ${count})\n`;
759
+ if (search_time) {
760
+ result += `**Search Time:** ${search_time}ms\n`;
761
+ }
762
+ result += '\n';
763
+ if (results.length === 0) {
764
+ result += '❌ No results found for your search query.\n\n';
765
+ result += '**Suggestions:**\n';
766
+ result += '- Try using different keywords\n';
767
+ result += '- Check spelling and try broader terms\n';
768
+ result += '- Use different search scope (global, space, app)\n';
769
+ result += '- Remove filters to expand search\n';
770
+ }
771
+ else {
772
+ // Group results by type for better organization
773
+ const groupedResults = ResponseFormatter.groupResultsByType(results);
774
+ Object.entries(groupedResults).forEach(([type, typeResults]) => {
775
+ if (typeResults.length > 0) {
776
+ result += `## ${ResponseFormatter.getTypeDisplayName(type)} (${typeResults.length})\n\n`;
777
+ typeResults.forEach((searchResult, index) => {
778
+ result += ResponseFormatter.formatSingleSearchResult(searchResult, index + 1);
779
+ result += '\n';
780
+ });
781
+ }
782
+ });
783
+ }
784
+ return {
785
+ content: [
786
+ {
787
+ type: 'text',
788
+ text: result.trim(),
789
+ },
790
+ ],
791
+ };
792
+ }
793
+ /**
794
+ * Format grouped search results response
795
+ */
796
+ static formatGroupedSearchResults(groupedResults) {
797
+ const { groups, totals, query, scope, search_time } = groupedResults;
798
+ let result = `🔍 **Grouped Search Results for "${query}"**\n\n`;
799
+ result += `**Scope:** ${scope.charAt(0).toUpperCase() + scope.slice(1)}\n`;
800
+ result += `**Total Results:** ${totals.all_results} (showing ${totals.returned_results})\n`;
801
+ if (search_time) {
802
+ result += `**Search Time:** ${search_time}ms\n`;
803
+ }
804
+ result += '\n';
805
+ // Show summary of results by type
806
+ result += '**Results by Type:**\n';
807
+ Object.entries(groups).forEach(([type, group]) => {
808
+ result += `- **${ResponseFormatter.getTypeDisplayName(type)}:** ${group.count} results\n`;
809
+ });
810
+ result += '\n';
811
+ if (totals.all_results === 0) {
812
+ result += '❌ No results found for your search query.\n';
813
+ }
814
+ else {
815
+ // Display each group
816
+ Object.entries(groups).forEach(([type, group]) => {
817
+ if (group.results.length > 0) {
818
+ result += `## ${ResponseFormatter.getTypeDisplayName(type)}\n\n`;
819
+ group.results.forEach((searchResult, index) => {
820
+ result += ResponseFormatter.formatSingleSearchResult(searchResult, index + 1);
821
+ result += '\n';
822
+ });
823
+ }
824
+ });
825
+ }
826
+ return {
827
+ content: [
828
+ {
829
+ type: 'text',
830
+ text: result.trim(),
831
+ },
832
+ ],
833
+ };
834
+ }
835
+ /**
836
+ * Format search history response
837
+ */
838
+ static formatSearchHistory(searches) {
839
+ let result = '📚 **Recent Search History**\n\n';
840
+ if (searches.length === 0) {
841
+ result += 'No recent searches found.\n';
842
+ }
843
+ else {
844
+ result += `Found ${searches.length} recent searches:\n\n`;
845
+ searches.forEach((search, index) => {
846
+ result += `${index + 1}. "${search}"\n`;
847
+ });
848
+ }
849
+ return {
850
+ content: [
851
+ {
852
+ type: 'text',
853
+ text: result.trim(),
854
+ },
855
+ ],
856
+ };
857
+ }
858
+ /**
859
+ * Format single search result for display
860
+ *
861
+ * @private
862
+ */
863
+ static formatSingleSearchResult(result, index) {
864
+ const typeIcon = ResponseFormatter.getTypeIcon(result.type);
865
+ let formatted = `### ${index}. ${typeIcon} ${result.title}\n`;
866
+ if (result.description) {
867
+ const cleanDescription = ResponseFormatter.cleanHtmlContent(result.description);
868
+ const truncatedDescription = cleanDescription.length > 150
869
+ ? cleanDescription.substring(0, 150) + '...'
870
+ : cleanDescription;
871
+ formatted += `${truncatedDescription}\n`;
872
+ }
873
+ // Add context information
874
+ const contextInfo = [];
875
+ if (result.app) {
876
+ contextInfo.push(`App: ${result.app.name}`);
877
+ }
878
+ if (result.space) {
879
+ contextInfo.push(`Space: ${result.space.name}`);
880
+ }
881
+ if (result.user) {
882
+ contextInfo.push(`User: ${result.user.name}`);
883
+ }
884
+ if (result.file) {
885
+ contextInfo.push(`File: ${result.file.name} (${ResponseFormatter.formatFileSize(result.file.size)})`);
886
+ }
887
+ if (contextInfo.length > 0) {
888
+ formatted += `*${contextInfo.join(' • ')}*\n`;
889
+ }
890
+ // Add timestamps
891
+ if (result.created_on) {
892
+ const createdDate = new Date(result.created_on).toLocaleDateString();
893
+ formatted += `📅 Created: ${createdDate}`;
894
+ if (result.last_event_on && result.last_event_on !== result.created_on) {
895
+ const updatedDate = new Date(result.last_event_on).toLocaleDateString();
896
+ formatted += ` • Updated: ${updatedDate}`;
897
+ }
898
+ formatted += '\n';
899
+ }
900
+ // Add highlights if available
901
+ if (result.highlights && result.highlights.length > 0) {
902
+ formatted += `💡 Matches: ${result.highlights.slice(0, 2).join(' ... ')}\n`;
903
+ }
904
+ if (result.link) {
905
+ formatted += `🔗 [View in Podio](${result.link})\n`;
906
+ }
907
+ formatted += `**ID:** ${result.id}\n`;
908
+ return formatted;
909
+ }
910
+ /**
911
+ * Group search results by type
912
+ *
913
+ * @private
914
+ */
915
+ static groupResultsByType(results) {
916
+ const grouped = {};
917
+ results.forEach((result) => {
918
+ if (!grouped[result.type]) {
919
+ grouped[result.type] = [];
920
+ }
921
+ grouped[result.type].push(result);
922
+ });
923
+ return grouped;
924
+ }
925
+ /**
926
+ * Get display name for search result type
927
+ *
928
+ * @private
929
+ */
930
+ static getTypeDisplayName(type) {
931
+ const displayNames = {
932
+ [SearchType.ITEM]: 'Items',
933
+ [SearchType.TASK]: 'Tasks',
934
+ [SearchType.STATUS]: 'Status Updates',
935
+ [SearchType.FILE]: 'Files',
936
+ [SearchType.CONVERSATION]: 'Conversations',
937
+ [SearchType.PROFILE]: 'Profiles',
938
+ [SearchType.APP]: 'Apps',
939
+ [SearchType.SPACE]: 'Spaces',
940
+ };
941
+ return displayNames[type] || type.charAt(0).toUpperCase() + type.slice(1);
942
+ }
943
+ /**
944
+ * Get icon for search result type
945
+ *
946
+ * @private
947
+ */
948
+ static getTypeIcon(type) {
949
+ const icons = {
950
+ [SearchType.ITEM]: '📝',
951
+ [SearchType.TASK]: '✅',
952
+ [SearchType.STATUS]: '📢',
953
+ [SearchType.FILE]: '📎',
954
+ [SearchType.CONVERSATION]: '💬',
955
+ [SearchType.PROFILE]: '👤',
956
+ [SearchType.APP]: '📱',
957
+ [SearchType.SPACE]: '🏢',
958
+ };
959
+ return icons[type] || '📄';
960
+ }
961
+ /**
962
+ * Format file size for display
963
+ *
964
+ * @private
965
+ */
966
+ static formatFileSize(bytes) {
967
+ if (bytes === 0)
968
+ return '0 B';
969
+ const k = 1024;
970
+ const sizes = ['B', 'KB', 'MB', 'GB'];
971
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
972
+ return parseFloat((bytes / k ** i).toFixed(1)) + ' ' + sizes[i];
973
+ }
974
+ // ===============================
975
+ // COMMENT & ACTIVITY RESPONSES
976
+ // ===============================
977
+ /**
978
+ * Format list of comments for an item
979
+ */
980
+ static formatItemCommentsList(comments) {
981
+ if (!comments || comments.length === 0) {
982
+ return {
983
+ content: [
984
+ {
985
+ type: 'text',
986
+ text: '📝 No comments found for this item.',
987
+ },
988
+ ],
989
+ };
990
+ }
991
+ let result = `📝 **Comments (${comments.length})**\n\n`;
992
+ comments.forEach((comment, index) => {
993
+ const createdDate = new Date(comment.created_on).toLocaleString();
994
+ const authorName = comment.created_by?.name || 'Unknown User';
995
+ result += `**Comment ${index + 1}** (ID: ${comment.comment_id})\n`;
996
+ result += `**Author:** ${authorName}\n`;
997
+ result += `**Created:** ${createdDate}\n`;
998
+ result += `**Text:** ${ResponseFormatter.cleanHtmlContent(comment.text)}\n`;
999
+ if (comment.link) {
1000
+ result += `**Link:** ${comment.link}\n`;
1001
+ }
1002
+ result += '\n';
1003
+ });
1004
+ return {
1005
+ content: [
1006
+ {
1007
+ type: 'text',
1008
+ text: result.trim(),
1009
+ },
1010
+ ],
1011
+ };
1012
+ }
1013
+ /**
1014
+ * Format a newly created comment
1015
+ */
1016
+ static formatCommentCreated(comment) {
1017
+ const createdDate = new Date(comment.created_on).toLocaleString();
1018
+ const authorName = comment.created_by?.name || 'Unknown User';
1019
+ let result = `✅ **Comment Created Successfully!**\n\n`;
1020
+ result += `**Comment ID:** ${comment.comment_id}\n`;
1021
+ result += `**Author:** ${authorName}\n`;
1022
+ result += `**Created:** ${createdDate}\n`;
1023
+ result += `**Text:** ${ResponseFormatter.cleanHtmlContent(comment.text)}\n`;
1024
+ if (comment.link) {
1025
+ result += `**Link:** ${comment.link}\n`;
1026
+ }
1027
+ return {
1028
+ content: [
1029
+ {
1030
+ type: 'text',
1031
+ text: result,
1032
+ },
1033
+ ],
1034
+ };
1035
+ }
1036
+ /**
1037
+ * Format comment details
1038
+ */
1039
+ static formatCommentDetails(comment) {
1040
+ const createdDate = new Date(comment.created_on).toLocaleString();
1041
+ const authorName = comment.created_by?.name || 'Unknown User';
1042
+ const authorEmail = comment.created_by?.mail || '';
1043
+ let result = `📝 **Comment Details**\n\n`;
1044
+ result += `**Comment ID:** ${comment.comment_id}\n`;
1045
+ result += `**Author:** ${authorName}`;
1046
+ if (authorEmail) {
1047
+ result += ` (${authorEmail})`;
1048
+ }
1049
+ result += '\n';
1050
+ result += `**Created:** ${createdDate}\n`;
1051
+ result += `**Object Type:** ${comment.ref_type}\n`;
1052
+ result += `**Object ID:** ${comment.ref_id}\n`;
1053
+ result += `**Text:** ${ResponseFormatter.cleanHtmlContent(comment.text)}\n`;
1054
+ if (comment.link) {
1055
+ result += `**Link:** ${comment.link}\n`;
1056
+ }
1057
+ if (comment.files && comment.files.length > 0) {
1058
+ result += `**Attachments:** ${comment.files.length} file(s)\n`;
1059
+ }
1060
+ return {
1061
+ content: [
1062
+ {
1063
+ type: 'text',
1064
+ text: result,
1065
+ },
1066
+ ],
1067
+ };
1068
+ }
1069
+ /**
1070
+ * Format item activity (revisions)
1071
+ */
1072
+ static formatItemActivity(revisions) {
1073
+ if (!revisions || revisions.length === 0) {
1074
+ return {
1075
+ content: [
1076
+ {
1077
+ type: 'text',
1078
+ text: '📈 No activity found for this item.',
1079
+ },
1080
+ ],
1081
+ };
1082
+ }
1083
+ let result = `📈 **Item Activity (${revisions.length} revisions)**\n\n`;
1084
+ // Sort revisions by revision number (newest first)
1085
+ const sortedRevisions = [...revisions].sort((a, b) => b.revision - a.revision);
1086
+ sortedRevisions.forEach((revision, index) => {
1087
+ const createdDate = new Date(revision.created_on).toLocaleString();
1088
+ const authorName = revision.created_by?.name || 'Unknown User';
1089
+ result += `**Revision ${revision.revision}**\n`;
1090
+ result += `**Type:** ${revision.type}\n`;
1091
+ result += `**Author:** ${authorName}\n`;
1092
+ result += `**Date:** ${createdDate}\n`;
1093
+ if (revision.message) {
1094
+ result += `**Message:** ${revision.message}\n`;
1095
+ }
1096
+ if (revision.changes && revision.changes.length > 0) {
1097
+ result += `**Changes:** ${revision.changes.length} field(s) modified\n`;
1098
+ revision.changes.forEach((change) => {
1099
+ result += ` - ${change.label} (${change.type})\n`;
1100
+ });
1101
+ }
1102
+ if (revision.link) {
1103
+ result += `**Link:** ${revision.link}\n`;
1104
+ }
1105
+ result += '\n';
1106
+ });
1107
+ return {
1108
+ content: [
1109
+ {
1110
+ type: 'text',
1111
+ text: result.trim(),
1112
+ },
1113
+ ],
1114
+ };
1115
+ }
1116
+ /**
1117
+ * Format item revision details
1118
+ */
1119
+ static formatItemRevisionDetails(revision) {
1120
+ const createdDate = new Date(revision.created_on).toLocaleString();
1121
+ const authorName = revision.created_by?.name || 'Unknown User';
1122
+ const authorEmail = revision.created_by?.mail || '';
1123
+ let result = `📄 **Revision ${revision.revision} Details**\n\n`;
1124
+ result += `**Type:** ${revision.type}\n`;
1125
+ result += `**Author:** ${authorName}`;
1126
+ if (authorEmail) {
1127
+ result += ` (${authorEmail})`;
1128
+ }
1129
+ result += '\n';
1130
+ result += `**Date:** ${createdDate}\n`;
1131
+ if (revision.message) {
1132
+ result += `**Message:** ${revision.message}\n`;
1133
+ }
1134
+ if (revision.changes && revision.changes.length > 0) {
1135
+ result += `\n**Changes (${revision.changes.length}):**\n`;
1136
+ revision.changes.forEach((change) => {
1137
+ result += `\n**${change.label}** (${change.type})\n`;
1138
+ if (change.operation) {
1139
+ result += ` Operation: ${change.operation}\n`;
1140
+ }
1141
+ if (change.from !== undefined) {
1142
+ result += ` From: ${JSON.stringify(change.from)}\n`;
1143
+ }
1144
+ if (change.to !== undefined) {
1145
+ result += ` To: ${JSON.stringify(change.to)}\n`;
1146
+ }
1147
+ });
1148
+ }
1149
+ if (revision.link) {
1150
+ result += `\n**Link:** ${revision.link}\n`;
1151
+ }
1152
+ return {
1153
+ content: [
1154
+ {
1155
+ type: 'text',
1156
+ text: result,
1157
+ },
1158
+ ],
1159
+ };
1160
+ }
1161
+ /**
1162
+ * Format item revision diff
1163
+ */
1164
+ static formatItemRevisionDiff(diff) {
1165
+ let result = `🔍 **Revision Diff: ${diff.from_revision} → ${diff.to_revision}**\n\n`;
1166
+ if (diff.summary) {
1167
+ result += `**Summary:** ${diff.summary}\n\n`;
1168
+ }
1169
+ if (!diff.changes || diff.changes.length === 0) {
1170
+ result += 'No changes detected between these revisions.';
1171
+ }
1172
+ else {
1173
+ result += `**Changes (${diff.changes.length}):**\n\n`;
1174
+ diff.changes.forEach((change, index) => {
1175
+ result += `**${index + 1}. ${change.label}** (${change.type})\n`;
1176
+ if (change.operation) {
1177
+ result += ` Operation: ${change.operation}\n`;
1178
+ }
1179
+ if (change.from !== undefined && change.to !== undefined) {
1180
+ result += ` Changed from: ${JSON.stringify(change.from)}\n`;
1181
+ result += ` Changed to: ${JSON.stringify(change.to)}\n`;
1182
+ }
1183
+ else if (change.to !== undefined) {
1184
+ result += ` New value: ${JSON.stringify(change.to)}\n`;
1185
+ }
1186
+ else if (change.from !== undefined) {
1187
+ result += ` Removed value: ${JSON.stringify(change.from)}\n`;
1188
+ }
1189
+ result += '\n';
1190
+ });
1191
+ }
1192
+ return {
1193
+ content: [
1194
+ {
1195
+ type: 'text',
1196
+ text: result.trim(),
1197
+ },
1198
+ ],
1199
+ };
1200
+ }
1201
+ // ===============================
1202
+ // HELPER METHODS
1203
+ // ===============================
1204
+ /**
1205
+ * Clean HTML content for display
1206
+ */
1207
+ static cleanHtmlContent(content) {
1208
+ if (!content)
1209
+ return '';
1210
+ return content
1211
+ .replace(/<[^>]*>/g, '') // Remove HTML tags
1212
+ .replace(/&nbsp;/g, ' ') // Replace non-breaking spaces
1213
+ .replace(/&amp;/g, '&') // Replace HTML entities
1214
+ .replace(/&lt;/g, '<')
1215
+ .replace(/&gt;/g, '>')
1216
+ .replace(/&quot;/g, '"')
1217
+ .replace(/&#39;/g, "'")
1218
+ .trim();
1219
+ }
1220
+ }
1221
+ //# sourceMappingURL=response-formatter.js.map