@hailer/mcp 0.0.1

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 (163) hide show
  1. package/.claude/commands/tool-builder.md +37 -0
  2. package/.claude/commands/ws-pull.md +44 -0
  3. package/.claude/settings.json +8 -0
  4. package/.claude/settings.local.json +49 -0
  5. package/.claude/skills/activity-api/SKILL.md +96 -0
  6. package/.claude/skills/activity-api/references/activity-endpoints.md +845 -0
  7. package/.claude/skills/add-app-member-skill/SKILL.md +977 -0
  8. package/.claude/skills/agent-building/SKILL.md +243 -0
  9. package/.claude/skills/agent-building/references/architecture-patterns.md +446 -0
  10. package/.claude/skills/agent-building/references/code-examples.md +587 -0
  11. package/.claude/skills/agent-building/references/implementation-guide.md +619 -0
  12. package/.claude/skills/app-api/SKILL.md +219 -0
  13. package/.claude/skills/app-api/references/app-endpoints.md +759 -0
  14. package/.claude/skills/building-hailer-apps-skill/SKILL.md +548 -0
  15. package/.claude/skills/create-app-skill/SKILL.md +1101 -0
  16. package/.claude/skills/create-insight-skill/SKILL.md +1317 -0
  17. package/.claude/skills/get-insight-data-skill/SKILL.md +1053 -0
  18. package/.claude/skills/hailer-api/SKILL.md +283 -0
  19. package/.claude/skills/hailer-api/references/activities.md +620 -0
  20. package/.claude/skills/hailer-api/references/authentication.md +216 -0
  21. package/.claude/skills/hailer-api/references/datasets.md +437 -0
  22. package/.claude/skills/hailer-api/references/files.md +301 -0
  23. package/.claude/skills/hailer-api/references/insights.md +469 -0
  24. package/.claude/skills/hailer-api/references/workflows.md +720 -0
  25. package/.claude/skills/hailer-api/references/workspaces-users.md +445 -0
  26. package/.claude/skills/insight-api/SKILL.md +185 -0
  27. package/.claude/skills/insight-api/references/insight-endpoints.md +514 -0
  28. package/.claude/skills/install-workflow-skill/SKILL.md +1056 -0
  29. package/.claude/skills/list-apps-skill/SKILL.md +1010 -0
  30. package/.claude/skills/list-workflows-minimal-skill/SKILL.md +992 -0
  31. package/.claude/skills/local-first-skill/SKILL.md +570 -0
  32. package/.claude/skills/mcp-tools/SKILL.md +419 -0
  33. package/.claude/skills/mcp-tools/references/api-endpoints.md +499 -0
  34. package/.claude/skills/mcp-tools/references/data-structures.md +554 -0
  35. package/.claude/skills/mcp-tools/references/implementation-patterns.md +717 -0
  36. package/.claude/skills/preview-insight-skill/SKILL.md +1290 -0
  37. package/.claude/skills/publish-hailer-app-skill/SKILL.md +453 -0
  38. package/.claude/skills/remove-app-member-skill/SKILL.md +671 -0
  39. package/.claude/skills/remove-app-skill/SKILL.md +985 -0
  40. package/.claude/skills/remove-insight-skill/SKILL.md +1011 -0
  41. package/.claude/skills/remove-workflow-skill/SKILL.md +920 -0
  42. package/.claude/skills/scaffold-hailer-app-skill/SKILL.md +1034 -0
  43. package/.claude/skills/skill-testing/README.md +137 -0
  44. package/.claude/skills/skill-testing/SKILL.md +348 -0
  45. package/.claude/skills/skill-testing/references/test-patterns.md +705 -0
  46. package/.claude/skills/skill-testing/references/testing-guide.md +603 -0
  47. package/.claude/skills/skill-testing/references/validation-checklist.md +537 -0
  48. package/.claude/skills/tool-builder/SKILL.md +328 -0
  49. package/.claude/skills/update-app-skill/SKILL.md +970 -0
  50. package/.claude/skills/update-workflow-field-skill/SKILL.md +1098 -0
  51. package/.env.example +81 -0
  52. package/.mcp.json +13 -0
  53. package/README.md +297 -0
  54. package/dist/app.d.ts +4 -0
  55. package/dist/app.js +74 -0
  56. package/dist/cli.d.ts +3 -0
  57. package/dist/cli.js +5 -0
  58. package/dist/client/adaptive-documentation-bot.d.ts +108 -0
  59. package/dist/client/adaptive-documentation-bot.js +475 -0
  60. package/dist/client/adaptive-documentation-types.d.ts +66 -0
  61. package/dist/client/adaptive-documentation-types.js +9 -0
  62. package/dist/client/agent-activity-bot.d.ts +51 -0
  63. package/dist/client/agent-activity-bot.js +166 -0
  64. package/dist/client/agent-tracker.d.ts +499 -0
  65. package/dist/client/agent-tracker.js +659 -0
  66. package/dist/client/description-updater.d.ts +56 -0
  67. package/dist/client/description-updater.js +259 -0
  68. package/dist/client/log-parser.d.ts +72 -0
  69. package/dist/client/log-parser.js +387 -0
  70. package/dist/client/mcp-client.d.ts +50 -0
  71. package/dist/client/mcp-client.js +532 -0
  72. package/dist/client/message-processor.d.ts +35 -0
  73. package/dist/client/message-processor.js +352 -0
  74. package/dist/client/multi-bot-manager.d.ts +24 -0
  75. package/dist/client/multi-bot-manager.js +74 -0
  76. package/dist/client/providers/anthropic-provider.d.ts +19 -0
  77. package/dist/client/providers/anthropic-provider.js +631 -0
  78. package/dist/client/providers/llm-provider.d.ts +47 -0
  79. package/dist/client/providers/llm-provider.js +367 -0
  80. package/dist/client/providers/openai-provider.d.ts +23 -0
  81. package/dist/client/providers/openai-provider.js +621 -0
  82. package/dist/client/simple-llm-caller.d.ts +19 -0
  83. package/dist/client/simple-llm-caller.js +100 -0
  84. package/dist/client/skill-generator.d.ts +81 -0
  85. package/dist/client/skill-generator.js +386 -0
  86. package/dist/client/test-adaptive-bot.d.ts +9 -0
  87. package/dist/client/test-adaptive-bot.js +82 -0
  88. package/dist/client/token-pricing.d.ts +38 -0
  89. package/dist/client/token-pricing.js +127 -0
  90. package/dist/client/token-tracker.d.ts +232 -0
  91. package/dist/client/token-tracker.js +457 -0
  92. package/dist/client/token-usage-bot.d.ts +53 -0
  93. package/dist/client/token-usage-bot.js +153 -0
  94. package/dist/client/tool-executor.d.ts +69 -0
  95. package/dist/client/tool-executor.js +159 -0
  96. package/dist/client/tool-schema-loader.d.ts +60 -0
  97. package/dist/client/tool-schema-loader.js +178 -0
  98. package/dist/client/types.d.ts +69 -0
  99. package/dist/client/types.js +7 -0
  100. package/dist/config.d.ts +162 -0
  101. package/dist/config.js +296 -0
  102. package/dist/core.d.ts +26 -0
  103. package/dist/core.js +147 -0
  104. package/dist/lib/context-manager.d.ts +111 -0
  105. package/dist/lib/context-manager.js +431 -0
  106. package/dist/lib/logger.d.ts +74 -0
  107. package/dist/lib/logger.js +277 -0
  108. package/dist/lib/materialize.d.ts +3 -0
  109. package/dist/lib/materialize.js +101 -0
  110. package/dist/lib/normalizedName.d.ts +7 -0
  111. package/dist/lib/normalizedName.js +48 -0
  112. package/dist/lib/prompt-length-manager.d.ts +81 -0
  113. package/dist/lib/prompt-length-manager.js +457 -0
  114. package/dist/lib/terminal-prompt.d.ts +9 -0
  115. package/dist/lib/terminal-prompt.js +108 -0
  116. package/dist/mcp/UserContextCache.d.ts +56 -0
  117. package/dist/mcp/UserContextCache.js +163 -0
  118. package/dist/mcp/auth.d.ts +2 -0
  119. package/dist/mcp/auth.js +29 -0
  120. package/dist/mcp/hailer-clients.d.ts +42 -0
  121. package/dist/mcp/hailer-clients.js +246 -0
  122. package/dist/mcp/signal-handler.d.ts +45 -0
  123. package/dist/mcp/signal-handler.js +317 -0
  124. package/dist/mcp/tool-registry.d.ts +100 -0
  125. package/dist/mcp/tool-registry.js +306 -0
  126. package/dist/mcp/tools/activity.d.ts +15 -0
  127. package/dist/mcp/tools/activity.js +955 -0
  128. package/dist/mcp/tools/app.d.ts +20 -0
  129. package/dist/mcp/tools/app.js +1488 -0
  130. package/dist/mcp/tools/discussion.d.ts +19 -0
  131. package/dist/mcp/tools/discussion.js +950 -0
  132. package/dist/mcp/tools/file.d.ts +15 -0
  133. package/dist/mcp/tools/file.js +119 -0
  134. package/dist/mcp/tools/insight.d.ts +17 -0
  135. package/dist/mcp/tools/insight.js +806 -0
  136. package/dist/mcp/tools/skill.d.ts +10 -0
  137. package/dist/mcp/tools/skill.js +279 -0
  138. package/dist/mcp/tools/user.d.ts +10 -0
  139. package/dist/mcp/tools/user.js +108 -0
  140. package/dist/mcp/tools/workflow-template.d.ts +19 -0
  141. package/dist/mcp/tools/workflow-template.js +822 -0
  142. package/dist/mcp/tools/workflow.d.ts +18 -0
  143. package/dist/mcp/tools/workflow.js +1362 -0
  144. package/dist/mcp/utils/api-errors.d.ts +45 -0
  145. package/dist/mcp/utils/api-errors.js +160 -0
  146. package/dist/mcp/utils/data-transformers.d.ts +102 -0
  147. package/dist/mcp/utils/data-transformers.js +194 -0
  148. package/dist/mcp/utils/file-upload.d.ts +33 -0
  149. package/dist/mcp/utils/file-upload.js +148 -0
  150. package/dist/mcp/utils/hailer-api-client.d.ts +120 -0
  151. package/dist/mcp/utils/hailer-api-client.js +323 -0
  152. package/dist/mcp/utils/index.d.ts +13 -0
  153. package/dist/mcp/utils/index.js +39 -0
  154. package/dist/mcp/utils/logger.d.ts +42 -0
  155. package/dist/mcp/utils/logger.js +103 -0
  156. package/dist/mcp/utils/types.d.ts +286 -0
  157. package/dist/mcp/utils/types.js +7 -0
  158. package/dist/mcp/workspace-cache.d.ts +42 -0
  159. package/dist/mcp/workspace-cache.js +97 -0
  160. package/dist/mcp-server.d.ts +42 -0
  161. package/dist/mcp-server.js +280 -0
  162. package/package.json +56 -0
  163. package/tsconfig.json +23 -0
@@ -0,0 +1,554 @@
1
+ # Data Structures Reference
2
+
3
+ Complete schemas for Hailer data types including workflows, activities, fields, and relationships.
4
+
5
+ ---
6
+
7
+ ## Workflow Structure
8
+
9
+ Workflows (called `processes` in API) define the schema and lifecycle for activities.
10
+
11
+ ### Complete Workflow Schema
12
+
13
+ ```javascript
14
+ {
15
+ "_id": "68446dc05b30685f67c6fcd4", // Workflow ID
16
+ "name": "Topics", // Display name
17
+ "defaultView": "kanban", // Default UI view (kanban, list, calendar)
18
+ "enableMessenger": true, // Enable discussion for activities
19
+ "createdActivities": 42, // Activity count
20
+
21
+ // Field definitions
22
+ "fields": {
23
+ "684d5e4568e9345040ad050e": {
24
+ "label": "Related to",
25
+ "type": "activitylink", // Field type
26
+ "key": "relatedTo", // Readable key for returnFlat mode
27
+ "required": false,
28
+ "editable": true,
29
+ "data": ["68446dc05b30685f67c6fcd4"] // For activitylink: target workflow IDs
30
+ },
31
+ "684d5e4568e9345040ad050f": {
32
+ "label": "Description",
33
+ "type": "textarea",
34
+ "key": "description",
35
+ "required": false
36
+ },
37
+ "684d5e4568e9345040ad0510": {
38
+ "label": "Priority",
39
+ "type": "text",
40
+ "key": "priority",
41
+ "required": false
42
+ }
43
+ },
44
+
45
+ // Field display order
46
+ "fieldsOrder": [
47
+ "684d5e4568e9345040ad050e",
48
+ "684d5e4568e9345040ad050f",
49
+ "684d5e4568e9345040ad0510"
50
+ ],
51
+
52
+ // Phase definitions (workflow stages)
53
+ "phases": {
54
+ "6901ebb64fd57ff171f43338": {
55
+ "name": "New",
56
+ "isInitial": true, // Default phase for new activities
57
+ "isEndpoint": false, // Is this a final phase?
58
+ "possibleNextPhase": [
59
+ "6901ebb64fd57ff171f43339"
60
+ ],
61
+ "fields": [ // Phase-specific required fields
62
+ "684d5e4568e9345040ad050e"
63
+ ]
64
+ },
65
+ "6901ebb64fd57ff171f43339": {
66
+ "name": "In Progress",
67
+ "isEndpoint": false,
68
+ "possibleNextPhase": [
69
+ "6901ebb64fd57ff171f4333a"
70
+ ]
71
+ },
72
+ "6901ebb64fd57ff171f4333a": {
73
+ "name": "Done",
74
+ "isEndpoint": true, // Final phase
75
+ "possibleNextPhase": []
76
+ }
77
+ },
78
+
79
+ // Phase display order
80
+ "phasesOrder": [
81
+ "6901ebb64fd57ff171f43338",
82
+ "6901ebb64fd57ff171f43339",
83
+ "6901ebb64fd57ff171f4333a"
84
+ ]
85
+ }
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Field Types
91
+
92
+ ### Common Field Types
93
+
94
+ | Type | Description | Example Use |
95
+ |------|-------------|-------------|
96
+ | `text` | Single-line text | Name, title, status |
97
+ | `textarea` | Multi-line text | Description, notes |
98
+ | `numeric` | Number | Count, amount |
99
+ | `date` | Date only | Due date, start date |
100
+ | `datetime` | Date and time | Created, updated |
101
+ | `activitylink` | Link to other activities | Related to, parent, dependencies |
102
+ | `user` | User reference | Assigned to, created by |
103
+ | `select` | Single selection | Priority, category |
104
+ | `multiselect` | Multiple selections | Tags, labels |
105
+
106
+ ### ActivityLink Field (Relationships)
107
+
108
+ The most important field type for building hierarchies and relationships.
109
+
110
+ ```javascript
111
+ {
112
+ "type": "activitylink",
113
+ "label": "Related to",
114
+ "key": "relatedTo", // Used with returnFlat
115
+ "data": [ // Target workflow IDs
116
+ "68446dc05b30685f67c6fcd4", // Can link to Project workflow
117
+ "69021153a27e596689bdf95d" // Can also link to Topic workflow
118
+ ],
119
+ "required": false,
120
+ "editable": true
121
+ }
122
+ ```
123
+
124
+ **Value Format**:
125
+ - Single link: `"activity-id"`
126
+ - Multiple links: `["activity-id-1", "activity-id-2"]`
127
+
128
+ **Example Hierarchy**:
129
+ ```
130
+ Projects (workflow 1)
131
+ ↑ linked via "project" field
132
+ Topics (workflow 2)
133
+ ↑ linked via "relatedTo" field
134
+ Tasks (workflow 3)
135
+ ```
136
+
137
+ ---
138
+
139
+ ## Activity Structure
140
+
141
+ Activities are instances of workflows, containing actual data.
142
+
143
+ ### Activity Without returnFlat
144
+
145
+ Default format with field IDs as keys:
146
+
147
+ ```javascript
148
+ {
149
+ "_id": "690300db68e9345040ad078b",
150
+ "name": "Task Title",
151
+ "processId": "68446dc05b30685f67c6fcd4", // Workflow ID
152
+ "phaseId": "6901ebb64fd57ff171f43338", // Current phase
153
+ "discussion": "684be83f68e9345040ad02a3", // Discussion ID
154
+ "created": "2025-10-30T09:00:00Z",
155
+ "updated": "2025-10-30T10:00:00Z",
156
+ "creator": "user-id",
157
+
158
+ "fields": {
159
+ "684d5e4568e9345040ad050e": { // Field ID as key
160
+ "value": "topic-activity-id" // Actual value
161
+ },
162
+ "684d5e4568e9345040ad050f": {
163
+ "value": "This is the description text"
164
+ },
165
+ "684d5e4568e9345040ad0510": {
166
+ "value": "high"
167
+ }
168
+ }
169
+ }
170
+ ```
171
+
172
+ ### Activity With returnFlat: true
173
+
174
+ Cleaner format using field keys instead of IDs:
175
+
176
+ ```javascript
177
+ {
178
+ "_id": "690300db68e9345040ad078b",
179
+ "name": "Task Title",
180
+ "processId": "68446dc05b30685f67c6fcd4",
181
+ "phaseId": "6901ebb64fd57ff171f43338",
182
+ "discussion": "684be83f68e9345040ad02a3",
183
+ "created": "2025-10-30T09:00:00Z",
184
+ "updated": "2025-10-30T10:00:00Z",
185
+
186
+ // Fields directly accessible by key
187
+ "relatedTo": "topic-activity-id", // Much cleaner!
188
+ "description": "This is the description text",
189
+ "priority": "high"
190
+ }
191
+ ```
192
+
193
+ **Always use returnFlat: true in new code** - it's much easier to work with.
194
+
195
+ ---
196
+
197
+ ## Activity Relationships Example
198
+
199
+ Real-world example showing how Projects → Topics → Tasks are linked.
200
+
201
+ ### Projects Workflow
202
+
203
+ ```javascript
204
+ {
205
+ "_id": "69021153a27e596689bdf95d",
206
+ "name": "Projects",
207
+ "fields": {
208
+ "company-field-id": {
209
+ "label": "Company",
210
+ "type": "activitylink",
211
+ "key": "company",
212
+ "data": ["69021153a27e596689bdf957"] // Links to Companies workflow
213
+ }
214
+ }
215
+ }
216
+ ```
217
+
218
+ ### Topics Workflow
219
+
220
+ ```javascript
221
+ {
222
+ "_id": "68446dc05b30685f67c6fcd4",
223
+ "name": "Topics",
224
+ "fields": {
225
+ "project-field-id": {
226
+ "label": "Project",
227
+ "type": "activitylink",
228
+ "key": "project",
229
+ "data": ["69021153a27e596689bdf95d"] // Links to Projects workflow
230
+ }
231
+ }
232
+ }
233
+ ```
234
+
235
+ ### Tasks Workflow
236
+
237
+ ```javascript
238
+ {
239
+ "_id": "69021153a27e596689bdf960",
240
+ "name": "Tasks",
241
+ "fields": {
242
+ "related-to-field-id": {
243
+ "label": "Related to",
244
+ "type": "activitylink",
245
+ "key": "relatedTo",
246
+ "data": ["68446dc05b30685f67c6fcd4"] // Links to Topics workflow
247
+ }
248
+ }
249
+ }
250
+ ```
251
+
252
+ ### Sample Activities (with returnFlat)
253
+
254
+ **Project Activity**:
255
+ ```javascript
256
+ {
257
+ "_id": "project-123",
258
+ "name": "Website Redesign",
259
+ "processId": "69021153a27e596689bdf95d",
260
+ "company": "company-456" // Links to company activity
261
+ }
262
+ ```
263
+
264
+ **Topic Activity**:
265
+ ```javascript
266
+ {
267
+ "_id": "topic-789",
268
+ "name": "Homepage Design",
269
+ "processId": "68446dc05b30685f67c6fcd4",
270
+ "project": "project-123" // Links to project above
271
+ }
272
+ ```
273
+
274
+ **Task Activity**:
275
+ ```javascript
276
+ {
277
+ "_id": "task-xyz",
278
+ "name": "Create hero section mockup",
279
+ "processId": "69021153a27e596689bdf960",
280
+ "relatedTo": "topic-789" // Links to topic above
281
+ }
282
+ ```
283
+
284
+ **Traversing the Hierarchy**:
285
+ ```typescript
286
+ // Get task
287
+ const task = await getActivity("task-xyz"); // relatedTo: "topic-789"
288
+
289
+ // Get parent topic
290
+ const topic = await getActivity(task.relatedTo); // project: "project-123"
291
+
292
+ // Get parent project
293
+ const project = await getActivity(topic.project); // company: "company-456"
294
+
295
+ // Get parent company
296
+ const company = await getActivity(project.company);
297
+
298
+ // Full path: company → project → topic → task
299
+ ```
300
+
301
+ ---
302
+
303
+ ## Discussion Structure
304
+
305
+ ### Discussion Object
306
+
307
+ ```javascript
308
+ {
309
+ "_id": "684be83f68e9345040ad02a3",
310
+ "activity": "activity-id", // Linked activity (if any)
311
+ "participants": [
312
+ {
313
+ "_id": "user-id",
314
+ "name": "User Name",
315
+ "email": "user@example.com"
316
+ }
317
+ ],
318
+ "unreadCount": 3
319
+ }
320
+ ```
321
+
322
+ ### Message Object
323
+
324
+ ```javascript
325
+ {
326
+ "_id": "message-id",
327
+ "msg": "Message text content",
328
+ "user": {
329
+ "_id": "user-id",
330
+ "name": "User Name"
331
+ },
332
+ "discussion": "discussion-id",
333
+ "created": "2025-10-30T10:00:00Z",
334
+ "replyTo": "parent-message-id", // If replying
335
+ "mentions": ["user-id-1", "user-id-2"], // @mentioned users
336
+ "edited": "2025-10-30T10:05:00Z" // If edited
337
+ }
338
+ ```
339
+
340
+ ---
341
+
342
+ ## User Structure
343
+
344
+ ```javascript
345
+ {
346
+ "_id": "user-id",
347
+ "name": "Johan Rekna",
348
+ "email": "johan@example.com",
349
+ "avatar": "https://...",
350
+ "role": "admin", // admin, member, guest
351
+ "networks": ["network-id-1"] // Workspaces user belongs to
352
+ }
353
+ ```
354
+
355
+ ---
356
+
357
+ ## Workspace (Network) Structure
358
+
359
+ ```javascript
360
+ {
361
+ "_id": "68446c045b30685f67c6fc8c",
362
+ "name": "My Workspace",
363
+ "owner": "user-id",
364
+ "members": [
365
+ {
366
+ "_id": "user-id",
367
+ "role": "admin"
368
+ }
369
+ ],
370
+ "processes": [ // Workflows in this workspace
371
+ {
372
+ "_id": "workflow-id",
373
+ "name": "Projects"
374
+ }
375
+ ]
376
+ }
377
+ ```
378
+
379
+ ---
380
+
381
+ ## Working with Field Keys
382
+
383
+ ### Setting Up Field Keys
384
+
385
+ When creating workflows, always define readable keys:
386
+
387
+ ```javascript
388
+ {
389
+ "label": "Due Date",
390
+ "type": "date",
391
+ "key": "dueDate" // Camel case, readable
392
+ }
393
+ ```
394
+
395
+ ### Benefits of returnFlat
396
+
397
+ **Without returnFlat**:
398
+ ```typescript
399
+ const priority = activity.fields["684d5e4568e9345040ad0510"].value;
400
+ const relatedId = activity.fields["684d5e4568e9345040ad050e"].value;
401
+ ```
402
+
403
+ **With returnFlat**:
404
+ ```typescript
405
+ const priority = activity.priority;
406
+ const relatedId = activity.relatedTo;
407
+ ```
408
+
409
+ Much cleaner and less error-prone!
410
+
411
+ ---
412
+
413
+ ## Field Validation
414
+
415
+ ### Required Fields
416
+
417
+ ```javascript
418
+ {
419
+ "type": "text",
420
+ "required": true // Must be provided when creating activity
421
+ }
422
+ ```
423
+
424
+ ### Phase-Specific Fields
425
+
426
+ ```javascript
427
+ "phases": {
428
+ "phase-id": {
429
+ "fields": ["field-id-1", "field-id-2"] // Required for this phase
430
+ }
431
+ }
432
+ ```
433
+
434
+ ### Field Constraints
435
+
436
+ ```javascript
437
+ {
438
+ "type": "numeric",
439
+ "min": 0,
440
+ "max": 100
441
+ }
442
+
443
+ {
444
+ "type": "text",
445
+ "maxLength": 255
446
+ }
447
+
448
+ {
449
+ "type": "select",
450
+ "options": ["low", "medium", "high"]
451
+ }
452
+ ```
453
+
454
+ ---
455
+
456
+ ## Type Definitions (TypeScript)
457
+
458
+ Useful TypeScript interfaces for type safety:
459
+
460
+ ```typescript
461
+ interface Workflow {
462
+ _id: string;
463
+ name: string;
464
+ fields: Record<string, WorkflowField>;
465
+ phases: Record<string, Phase>;
466
+ fieldsOrder: string[];
467
+ phasesOrder: string[];
468
+ }
469
+
470
+ interface WorkflowField {
471
+ label: string;
472
+ type: FieldType;
473
+ key?: string;
474
+ required?: boolean;
475
+ data?: string[]; // For activitylink: target workflow IDs
476
+ }
477
+
478
+ type FieldType =
479
+ | 'text'
480
+ | 'textarea'
481
+ | 'numeric'
482
+ | 'date'
483
+ | 'datetime'
484
+ | 'activitylink'
485
+ | 'user'
486
+ | 'select'
487
+ | 'multiselect';
488
+
489
+ interface Phase {
490
+ name: string;
491
+ isInitial?: boolean;
492
+ isEndpoint?: boolean;
493
+ possibleNextPhase: string[];
494
+ fields?: string[];
495
+ }
496
+
497
+ interface Activity {
498
+ _id: string;
499
+ name: string;
500
+ processId: string;
501
+ phaseId: string;
502
+ discussion?: string;
503
+ created: string;
504
+ updated: string;
505
+ [key: string]: any; // Field values with returnFlat
506
+ }
507
+ ```
508
+
509
+ ---
510
+
511
+ ## Common Patterns
512
+
513
+ ### Finding Field IDs from Keys
514
+
515
+ ```typescript
516
+ // Get field ID from key
517
+ function getFieldIdByKey(workflow: Workflow, key: string): string | null {
518
+ for (const [fieldId, field] of Object.entries(workflow.fields)) {
519
+ if (field.key === key) {
520
+ return fieldId;
521
+ }
522
+ }
523
+ return null;
524
+ }
525
+
526
+ // Usage
527
+ const priorityFieldId = getFieldIdByKey(workflow, 'priority');
528
+ ```
529
+
530
+ ### Building Activity Links
531
+
532
+ ```typescript
533
+ // Create activity with link to parent
534
+ await createActivity(workflowId, {
535
+ name: "Child Task",
536
+ fields: {
537
+ relatedTo: parentActivity._id // Link using returnFlat key
538
+ }
539
+ });
540
+ ```
541
+
542
+ ### Querying by Relationship
543
+
544
+ ```typescript
545
+ // Find all tasks for a specific topic
546
+ await listActivities(tasksWorkflowId, {
547
+ filters: {
548
+ and: [
549
+ { "relatedTo": { equalTo: topicActivityId } }
550
+ ]
551
+ },
552
+ returnFlat: true
553
+ });
554
+ ```