mcp-creatio 0.3.6

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 (370) hide show
  1. package/.dockerignore +12 -0
  2. package/.editorconfig +14 -0
  3. package/.eslintrc.cjs +18 -0
  4. package/.gitattributes +8 -0
  5. package/.github/workflows/docker-publish.yml +50 -0
  6. package/.prettierignore +3 -0
  7. package/.prettierrc +9 -0
  8. package/.vscode/launch.json +23 -0
  9. package/.vscode/mcp.json +13 -0
  10. package/.vscode/settings.json +16 -0
  11. package/Agent.md +187 -0
  12. package/Debug.md +32 -0
  13. package/Dockerfile +23 -0
  14. package/LICENSE +21 -0
  15. package/README.md +162 -0
  16. package/dist/cli.d.ts +3 -0
  17. package/dist/cli.d.ts.map +1 -0
  18. package/dist/cli.js +135 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/config-builder.d.ts +3 -0
  21. package/dist/config-builder.d.ts.map +1 -0
  22. package/dist/config-builder.js +66 -0
  23. package/dist/config-builder.js.map +1 -0
  24. package/dist/consts.d.ts +2 -0
  25. package/dist/consts.d.ts.map +1 -0
  26. package/dist/consts.js +6 -0
  27. package/dist/consts.js.map +1 -0
  28. package/dist/creatio/auth/auth-manager.d.ts +9 -0
  29. package/dist/creatio/auth/auth-manager.d.ts.map +1 -0
  30. package/dist/creatio/auth/auth-manager.js +29 -0
  31. package/dist/creatio/auth/auth-manager.js.map +1 -0
  32. package/dist/creatio/auth/auth.d.ts +16 -0
  33. package/dist/creatio/auth/auth.d.ts.map +1 -0
  34. package/dist/creatio/auth/auth.js +20 -0
  35. package/dist/creatio/auth/auth.js.map +1 -0
  36. package/dist/creatio/auth/index.d.ts +4 -0
  37. package/dist/creatio/auth/index.d.ts.map +1 -0
  38. package/dist/creatio/auth/index.js +21 -0
  39. package/dist/creatio/auth/index.js.map +1 -0
  40. package/dist/creatio/auth/providers/base-oauth2-provider.d.ts +17 -0
  41. package/dist/creatio/auth/providers/base-oauth2-provider.d.ts.map +1 -0
  42. package/dist/creatio/auth/providers/base-oauth2-provider.js +49 -0
  43. package/dist/creatio/auth/providers/base-oauth2-provider.js.map +1 -0
  44. package/dist/creatio/auth/providers/base-provider.d.ts +15 -0
  45. package/dist/creatio/auth/providers/base-provider.d.ts.map +1 -0
  46. package/dist/creatio/auth/providers/base-provider.js +32 -0
  47. package/dist/creatio/auth/providers/base-provider.js.map +1 -0
  48. package/dist/creatio/auth/providers/index.d.ts +5 -0
  49. package/dist/creatio/auth/providers/index.d.ts.map +1 -0
  50. package/dist/creatio/auth/providers/index.js +21 -0
  51. package/dist/creatio/auth/providers/index.js.map +1 -0
  52. package/dist/creatio/auth/providers/legacy-provider.d.ts +10 -0
  53. package/dist/creatio/auth/providers/legacy-provider.d.ts.map +1 -0
  54. package/dist/creatio/auth/providers/legacy-provider.js +73 -0
  55. package/dist/creatio/auth/providers/legacy-provider.js.map +1 -0
  56. package/dist/creatio/auth/providers/oauth2-code-provider.d.ts +18 -0
  57. package/dist/creatio/auth/providers/oauth2-code-provider.d.ts.map +1 -0
  58. package/dist/creatio/auth/providers/oauth2-code-provider.js +245 -0
  59. package/dist/creatio/auth/providers/oauth2-code-provider.js.map +1 -0
  60. package/dist/creatio/auth/providers/oauth2-provider.d.ts +9 -0
  61. package/dist/creatio/auth/providers/oauth2-provider.d.ts.map +1 -0
  62. package/dist/creatio/auth/providers/oauth2-provider.js +86 -0
  63. package/dist/creatio/auth/providers/oauth2-provider.js.map +1 -0
  64. package/dist/creatio/auth/providers/type.d.ts +6 -0
  65. package/dist/creatio/auth/providers/type.d.ts.map +1 -0
  66. package/dist/creatio/auth/providers/type.js +10 -0
  67. package/dist/creatio/auth/providers/type.js.map +1 -0
  68. package/dist/creatio/client-config.d.ts +29 -0
  69. package/dist/creatio/client-config.d.ts.map +1 -0
  70. package/dist/creatio/client-config.js +3 -0
  71. package/dist/creatio/client-config.js.map +1 -0
  72. package/dist/creatio/engines/crud/crud-engine.d.ts +15 -0
  73. package/dist/creatio/engines/crud/crud-engine.d.ts.map +1 -0
  74. package/dist/creatio/engines/crud/crud-engine.js +33 -0
  75. package/dist/creatio/engines/crud/crud-engine.js.map +1 -0
  76. package/dist/creatio/engines/engine-manager.d.ts +33 -0
  77. package/dist/creatio/engines/engine-manager.d.ts.map +1 -0
  78. package/dist/creatio/engines/engine-manager.js +54 -0
  79. package/dist/creatio/engines/engine-manager.js.map +1 -0
  80. package/dist/creatio/engines/engine-registry.d.ts +15 -0
  81. package/dist/creatio/engines/engine-registry.d.ts.map +1 -0
  82. package/dist/creatio/engines/engine-registry.js +35 -0
  83. package/dist/creatio/engines/engine-registry.js.map +1 -0
  84. package/dist/creatio/engines/engine.d.ts +4 -0
  85. package/dist/creatio/engines/engine.d.ts.map +1 -0
  86. package/dist/creatio/engines/engine.js +3 -0
  87. package/dist/creatio/engines/engine.js.map +1 -0
  88. package/dist/creatio/engines/index.d.ts +8 -0
  89. package/dist/creatio/engines/index.d.ts.map +1 -0
  90. package/dist/creatio/engines/index.js +24 -0
  91. package/dist/creatio/engines/index.js.map +1 -0
  92. package/dist/creatio/engines/process/process-engine.d.ts +10 -0
  93. package/dist/creatio/engines/process/process-engine.d.ts.map +1 -0
  94. package/dist/creatio/engines/process/process-engine.js +18 -0
  95. package/dist/creatio/engines/process/process-engine.js.map +1 -0
  96. package/dist/creatio/engines/sys-settings/sys-settings-engine.d.ts +13 -0
  97. package/dist/creatio/engines/sys-settings/sys-settings-engine.d.ts.map +1 -0
  98. package/dist/creatio/engines/sys-settings/sys-settings-engine.js +27 -0
  99. package/dist/creatio/engines/sys-settings/sys-settings-engine.js.map +1 -0
  100. package/dist/creatio/engines/user/user-engine.d.ts +10 -0
  101. package/dist/creatio/engines/user/user-engine.d.ts.map +1 -0
  102. package/dist/creatio/engines/user/user-engine.js +18 -0
  103. package/dist/creatio/engines/user/user-engine.js.map +1 -0
  104. package/dist/creatio/index.d.ts +7 -0
  105. package/dist/creatio/index.d.ts.map +1 -0
  106. package/dist/creatio/index.js +23 -0
  107. package/dist/creatio/index.js.map +1 -0
  108. package/dist/creatio/provider-context.d.ts +10 -0
  109. package/dist/creatio/provider-context.d.ts.map +1 -0
  110. package/dist/creatio/provider-context.js +3 -0
  111. package/dist/creatio/provider-context.js.map +1 -0
  112. package/dist/creatio/providers/crud-provider.d.ts +40 -0
  113. package/dist/creatio/providers/crud-provider.d.ts.map +1 -0
  114. package/dist/creatio/providers/crud-provider.js +3 -0
  115. package/dist/creatio/providers/crud-provider.js.map +1 -0
  116. package/dist/creatio/providers/index.d.ts +5 -0
  117. package/dist/creatio/providers/index.d.ts.map +1 -0
  118. package/dist/creatio/providers/index.js +21 -0
  119. package/dist/creatio/providers/index.js.map +1 -0
  120. package/dist/creatio/providers/process-provider.d.ts +14 -0
  121. package/dist/creatio/providers/process-provider.d.ts.map +1 -0
  122. package/dist/creatio/providers/process-provider.js +3 -0
  123. package/dist/creatio/providers/process-provider.js.map +1 -0
  124. package/dist/creatio/providers/sys-settings-provider.d.ts +58 -0
  125. package/dist/creatio/providers/sys-settings-provider.d.ts.map +1 -0
  126. package/dist/creatio/providers/sys-settings-provider.js +3 -0
  127. package/dist/creatio/providers/sys-settings-provider.js.map +1 -0
  128. package/dist/creatio/providers/user-provider.d.ts +12 -0
  129. package/dist/creatio/providers/user-provider.d.ts.map +1 -0
  130. package/dist/creatio/providers/user-provider.js +3 -0
  131. package/dist/creatio/providers/user-provider.js.map +1 -0
  132. package/dist/creatio/services/creatio-service-context.d.ts +17 -0
  133. package/dist/creatio/services/creatio-service-context.d.ts.map +1 -0
  134. package/dist/creatio/services/creatio-service-context.js +35 -0
  135. package/dist/creatio/services/creatio-service-context.js.map +1 -0
  136. package/dist/creatio/services/http-client.d.ts +29 -0
  137. package/dist/creatio/services/http-client.d.ts.map +1 -0
  138. package/dist/creatio/services/http-client.js +136 -0
  139. package/dist/creatio/services/http-client.js.map +1 -0
  140. package/dist/creatio/services/index.d.ts +8 -0
  141. package/dist/creatio/services/index.d.ts.map +1 -0
  142. package/dist/creatio/services/index.js +24 -0
  143. package/dist/creatio/services/index.js.map +1 -0
  144. package/dist/creatio/services/metadata-store.d.ts +20 -0
  145. package/dist/creatio/services/metadata-store.d.ts.map +1 -0
  146. package/dist/creatio/services/metadata-store.js +162 -0
  147. package/dist/creatio/services/metadata-store.js.map +1 -0
  148. package/dist/creatio/services/odata-crud-provider.d.ts +21 -0
  149. package/dist/creatio/services/odata-crud-provider.d.ts.map +1 -0
  150. package/dist/creatio/services/odata-crud-provider.js +145 -0
  151. package/dist/creatio/services/odata-crud-provider.js.map +1 -0
  152. package/dist/creatio/services/process-service-provider.d.ts +11 -0
  153. package/dist/creatio/services/process-service-provider.d.ts.map +1 -0
  154. package/dist/creatio/services/process-service-provider.js +52 -0
  155. package/dist/creatio/services/process-service-provider.js.map +1 -0
  156. package/dist/creatio/services/sys-settings-service-provider.d.ts +19 -0
  157. package/dist/creatio/services/sys-settings-service-provider.d.ts.map +1 -0
  158. package/dist/creatio/services/sys-settings-service-provider.js +107 -0
  159. package/dist/creatio/services/sys-settings-service-provider.js.map +1 -0
  160. package/dist/creatio/services/user-info-provider.d.ts +10 -0
  161. package/dist/creatio/services/user-info-provider.d.ts.map +1 -0
  162. package/dist/creatio/services/user-info-provider.js +26 -0
  163. package/dist/creatio/services/user-info-provider.js.map +1 -0
  164. package/dist/index.d.ts +2 -0
  165. package/dist/index.d.ts.map +1 -0
  166. package/dist/index.js +46 -0
  167. package/dist/index.js.map +1 -0
  168. package/dist/log.d.ts +51 -0
  169. package/dist/log.d.ts.map +1 -0
  170. package/dist/log.js +137 -0
  171. package/dist/log.js.map +1 -0
  172. package/dist/server/http/creatio-oauth-handlers.d.ts +14 -0
  173. package/dist/server/http/creatio-oauth-handlers.d.ts.map +1 -0
  174. package/dist/server/http/creatio-oauth-handlers.js +137 -0
  175. package/dist/server/http/creatio-oauth-handlers.js.map +1 -0
  176. package/dist/server/http/httpServer.d.ts +23 -0
  177. package/dist/server/http/httpServer.d.ts.map +1 -0
  178. package/dist/server/http/httpServer.js +131 -0
  179. package/dist/server/http/httpServer.js.map +1 -0
  180. package/dist/server/http/index.d.ts +6 -0
  181. package/dist/server/http/index.d.ts.map +1 -0
  182. package/dist/server/http/index.js +22 -0
  183. package/dist/server/http/index.js.map +1 -0
  184. package/dist/server/http/mcp-handlers.d.ts +10 -0
  185. package/dist/server/http/mcp-handlers.d.ts.map +1 -0
  186. package/dist/server/http/mcp-handlers.js +82 -0
  187. package/dist/server/http/mcp-handlers.js.map +1 -0
  188. package/dist/server/http/mcp-oauth-handlers.d.ts +11 -0
  189. package/dist/server/http/mcp-oauth-handlers.d.ts.map +1 -0
  190. package/dist/server/http/mcp-oauth-handlers.js +106 -0
  191. package/dist/server/http/mcp-oauth-handlers.js.map +1 -0
  192. package/dist/server/http/middleware.d.ts +11 -0
  193. package/dist/server/http/middleware.d.ts.map +1 -0
  194. package/dist/server/http/middleware.js +88 -0
  195. package/dist/server/http/middleware.js.map +1 -0
  196. package/dist/server/index.d.ts +3 -0
  197. package/dist/server/index.d.ts.map +1 -0
  198. package/dist/server/index.js +19 -0
  199. package/dist/server/index.js.map +1 -0
  200. package/dist/server/mcp/filters.d.ts +2 -0
  201. package/dist/server/mcp/filters.d.ts.map +1 -0
  202. package/dist/server/mcp/filters.js +94 -0
  203. package/dist/server/mcp/filters.js.map +1 -0
  204. package/dist/server/mcp/index.d.ts +2 -0
  205. package/dist/server/mcp/index.d.ts.map +1 -0
  206. package/dist/server/mcp/index.js +18 -0
  207. package/dist/server/mcp/index.js.map +1 -0
  208. package/dist/server/mcp/prompts-data.d.ts +147 -0
  209. package/dist/server/mcp/prompts-data.d.ts.map +1 -0
  210. package/dist/server/mcp/prompts-data.js +884 -0
  211. package/dist/server/mcp/prompts-data.js.map +1 -0
  212. package/dist/server/mcp/server.d.ts +25 -0
  213. package/dist/server/mcp/server.d.ts.map +1 -0
  214. package/dist/server/mcp/server.js +233 -0
  215. package/dist/server/mcp/server.js.map +1 -0
  216. package/dist/server/mcp/tools-data.d.ts +165 -0
  217. package/dist/server/mcp/tools-data.d.ts.map +1 -0
  218. package/dist/server/mcp/tools-data.js +466 -0
  219. package/dist/server/mcp/tools-data.js.map +1 -0
  220. package/dist/server/oauth/client-manager.d.ts +6 -0
  221. package/dist/server/oauth/client-manager.d.ts.map +1 -0
  222. package/dist/server/oauth/client-manager.js +52 -0
  223. package/dist/server/oauth/client-manager.js.map +1 -0
  224. package/dist/server/oauth/index.d.ts +7 -0
  225. package/dist/server/oauth/index.d.ts.map +1 -0
  226. package/dist/server/oauth/index.js +23 -0
  227. package/dist/server/oauth/index.js.map +1 -0
  228. package/dist/server/oauth/oauth-server.d.ts +21 -0
  229. package/dist/server/oauth/oauth-server.d.ts.map +1 -0
  230. package/dist/server/oauth/oauth-server.js +146 -0
  231. package/dist/server/oauth/oauth-server.js.map +1 -0
  232. package/dist/server/oauth/storage.d.ts +31 -0
  233. package/dist/server/oauth/storage.d.ts.map +1 -0
  234. package/dist/server/oauth/storage.js +73 -0
  235. package/dist/server/oauth/storage.js.map +1 -0
  236. package/dist/server/oauth/token-manager.d.ts +13 -0
  237. package/dist/server/oauth/token-manager.d.ts.map +1 -0
  238. package/dist/server/oauth/token-manager.js +69 -0
  239. package/dist/server/oauth/token-manager.js.map +1 -0
  240. package/dist/server/oauth/types.d.ts +51 -0
  241. package/dist/server/oauth/types.d.ts.map +1 -0
  242. package/dist/server/oauth/types.js +3 -0
  243. package/dist/server/oauth/types.js.map +1 -0
  244. package/dist/server/oauth/validators.d.ts +7 -0
  245. package/dist/server/oauth/validators.d.ts.map +1 -0
  246. package/dist/server/oauth/validators.js +51 -0
  247. package/dist/server/oauth/validators.js.map +1 -0
  248. package/dist/services/index.d.ts +3 -0
  249. package/dist/services/index.d.ts.map +1 -0
  250. package/dist/services/index.js +19 -0
  251. package/dist/services/index.js.map +1 -0
  252. package/dist/services/session-context.d.ts +57 -0
  253. package/dist/services/session-context.d.ts.map +1 -0
  254. package/dist/services/session-context.js +182 -0
  255. package/dist/services/session-context.js.map +1 -0
  256. package/dist/services/token-refresh-scheduler.d.ts +16 -0
  257. package/dist/services/token-refresh-scheduler.d.ts.map +1 -0
  258. package/dist/services/token-refresh-scheduler.js +66 -0
  259. package/dist/services/token-refresh-scheduler.js.map +1 -0
  260. package/dist/types/index.d.ts +2 -0
  261. package/dist/types/index.d.ts.map +1 -0
  262. package/dist/types/index.js +18 -0
  263. package/dist/types/index.js.map +1 -0
  264. package/dist/types/network.d.ts +7 -0
  265. package/dist/types/network.d.ts.map +1 -0
  266. package/dist/types/network.js +6 -0
  267. package/dist/types/network.js.map +1 -0
  268. package/dist/utils/context.d.ts +10 -0
  269. package/dist/utils/context.d.ts.map +1 -0
  270. package/dist/utils/context.js +44 -0
  271. package/dist/utils/context.js.map +1 -0
  272. package/dist/utils/env.d.ts +3 -0
  273. package/dist/utils/env.d.ts.map +1 -0
  274. package/dist/utils/env.js +16 -0
  275. package/dist/utils/env.js.map +1 -0
  276. package/dist/utils/index.d.ts +6 -0
  277. package/dist/utils/index.d.ts.map +1 -0
  278. package/dist/utils/index.js +22 -0
  279. package/dist/utils/index.js.map +1 -0
  280. package/dist/utils/mcp.d.ts +3 -0
  281. package/dist/utils/mcp.d.ts.map +1 -0
  282. package/dist/utils/mcp.js +7 -0
  283. package/dist/utils/mcp.js.map +1 -0
  284. package/dist/utils/network.d.ts +7 -0
  285. package/dist/utils/network.d.ts.map +1 -0
  286. package/dist/utils/network.js +63 -0
  287. package/dist/utils/network.js.map +1 -0
  288. package/dist/utils/pkce.d.ts +7 -0
  289. package/dist/utils/pkce.d.ts.map +1 -0
  290. package/dist/utils/pkce.js +43 -0
  291. package/dist/utils/pkce.js.map +1 -0
  292. package/dist/version.d.ts +3 -0
  293. package/dist/version.d.ts.map +1 -0
  294. package/dist/version.js +10 -0
  295. package/dist/version.js.map +1 -0
  296. package/docs/coding-style.md +30 -0
  297. package/ecosystem.config.json +17 -0
  298. package/eslint.config.cjs +95 -0
  299. package/package.json +54 -0
  300. package/src/cli.ts +158 -0
  301. package/src/config-builder.ts +76 -0
  302. package/src/consts.ts +3 -0
  303. package/src/creatio/auth/auth-manager.ts +27 -0
  304. package/src/creatio/auth/auth.ts +31 -0
  305. package/src/creatio/auth/index.ts +3 -0
  306. package/src/creatio/auth/providers/base-oauth2-provider.ts +62 -0
  307. package/src/creatio/auth/providers/base-provider.ts +42 -0
  308. package/src/creatio/auth/providers/index.ts +4 -0
  309. package/src/creatio/auth/providers/legacy-provider.ts +70 -0
  310. package/src/creatio/auth/providers/oauth2-code-provider.ts +252 -0
  311. package/src/creatio/auth/providers/oauth2-provider.ts +91 -0
  312. package/src/creatio/auth/providers/type.ts +5 -0
  313. package/src/creatio/client-config.ts +34 -0
  314. package/src/creatio/engines/crud/crud-engine.ts +47 -0
  315. package/src/creatio/engines/engine-manager.ts +102 -0
  316. package/src/creatio/engines/engine-registry.ts +36 -0
  317. package/src/creatio/engines/engine.ts +3 -0
  318. package/src/creatio/engines/index.ts +7 -0
  319. package/src/creatio/engines/process/process-engine.ts +20 -0
  320. package/src/creatio/engines/sys-settings/sys-settings-engine.ts +41 -0
  321. package/src/creatio/engines/user/user-engine.ts +20 -0
  322. package/src/creatio/index.ts +6 -0
  323. package/src/creatio/provider-context.ts +10 -0
  324. package/src/creatio/providers/crud-provider.ts +45 -0
  325. package/src/creatio/providers/index.ts +4 -0
  326. package/src/creatio/providers/process-provider.ts +15 -0
  327. package/src/creatio/providers/sys-settings-provider.ts +63 -0
  328. package/src/creatio/providers/user-provider.ts +12 -0
  329. package/src/creatio/services/creatio-service-context.ts +38 -0
  330. package/src/creatio/services/http-client.ts +174 -0
  331. package/src/creatio/services/index.ts +7 -0
  332. package/src/creatio/services/metadata-store.ts +181 -0
  333. package/src/creatio/services/odata-crud-provider.ts +210 -0
  334. package/src/creatio/services/process-service-provider.ts +76 -0
  335. package/src/creatio/services/sys-settings-service-provider.ts +192 -0
  336. package/src/creatio/services/user-info-provider.ts +41 -0
  337. package/src/index.ts +44 -0
  338. package/src/log.ts +141 -0
  339. package/src/server/http/creatio-oauth-handlers.ts +146 -0
  340. package/src/server/http/httpServer.ts +150 -0
  341. package/src/server/http/index.ts +5 -0
  342. package/src/server/http/mcp-handlers.ts +92 -0
  343. package/src/server/http/mcp-oauth-handlers.ts +108 -0
  344. package/src/server/http/middleware.ts +91 -0
  345. package/src/server/index.ts +2 -0
  346. package/src/server/mcp/filters.ts +97 -0
  347. package/src/server/mcp/index.ts +1 -0
  348. package/src/server/mcp/prompts-data.ts +896 -0
  349. package/src/server/mcp/server.ts +331 -0
  350. package/src/server/mcp/tools-data.ts +592 -0
  351. package/src/server/oauth/client-manager.ts +47 -0
  352. package/src/server/oauth/index.ts +6 -0
  353. package/src/server/oauth/oauth-server.ts +185 -0
  354. package/src/server/oauth/storage.ts +106 -0
  355. package/src/server/oauth/token-manager.ts +80 -0
  356. package/src/server/oauth/types.ts +55 -0
  357. package/src/server/oauth/validators.ts +56 -0
  358. package/src/services/index.ts +2 -0
  359. package/src/services/session-context.ts +232 -0
  360. package/src/services/token-refresh-scheduler.ts +68 -0
  361. package/src/types/index.ts +1 -0
  362. package/src/types/network.ts +7 -0
  363. package/src/utils/context.ts +49 -0
  364. package/src/utils/env.ts +12 -0
  365. package/src/utils/index.ts +5 -0
  366. package/src/utils/mcp.ts +8 -0
  367. package/src/utils/network.ts +65 -0
  368. package/src/utils/pkce.ts +39 -0
  369. package/src/version.ts +15 -0
  370. package/tsconfig.json +28 -0
@@ -0,0 +1,896 @@
1
+ const DEFAULT_ACTIVITY_IDS = {
2
+ TYPE_TASK: 'fbe0acdc-cfc0-df11-b00f-001d60e938c6',
3
+ CATEGORY_TODO: 'f2c0ce0e-cfc1-df11-b00f-001d60e938c6',
4
+ STATUS_NOT_STARTED: '384d4b84-58e6-df11-971b-001d60e938c6',
5
+ PRIORITY_MEDIUM: 'ab96fa02-7fe6-df11-971b-001d60e938c6',
6
+ } as const;
7
+
8
+ const ACTIVITY_TYPE_TABLE = `
9
+ | User says / intent | TypeId → Type (fixed) | Category (set via ActivityCategoryId) |
10
+ |--------------------|-----------------------|---------------------------------------|
11
+ | task / todo (default) | Task | To do |
12
+ | meeting / meet / sync | Task | Meeting |
13
+ | call / phone | Task | Call |
14
+ | email / mail | Task | Email |
15
+
16
+ 💡 We deliberately keep Type always = Task for speed. Change only if user explicitly insists: "Use real meeting type".
17
+ `.trim();
18
+
19
+ const CREATE_ACTIVITY_WORKFLOW = `
20
+ # 🆕 Create Activity in Creatio (Optimized 99% Case)
21
+
22
+ ⚠️⚠️⚠️ FIRST STEP - ALWAYS CALL get-current-user-info FIRST! ⚠️⚠️⚠️
23
+
24
+ Before creating ANY activity, you MUST:
25
+ 1. Call 'get-current-user-info' tool (no parameters)
26
+ 2. Extract contactId from response
27
+ 3. Store contactId in memory
28
+ 4. Use contactId as OwnerId and AuthorId in the activity
29
+
30
+ DO NOT skip this step! Activities require valid OwnerId and AuthorId (both = contactId).
31
+
32
+ ## Why Simplified?
33
+ Business usage: almost all activities should just appear in calendar quickly. So we hardcode **Type = Task** and only adjust the **Category** to reflect intent (meeting / call / email / todo). This minimizes API calls and cognitive load.
34
+
35
+ If user explicitly insists: "Use real meeting type" / "Set actual Call type" → THEN switch to extended lookup mode (ActivityType + ActivityCategory must match). Otherwise stay in fast mode.
36
+
37
+ ⚠️ ABSOLUTE RULE:
38
+ Always set **TypeId = Task** for intents like "meeting", "meet", "sync", "call", "phone", "email", "mail", "todo", "task" UNLESS (and only unless) the user explicitly demands a non-Task type using phrases such as:
39
+ "real meeting type", "actual meeting type", "true call type", "use real ActivityType", "not a task", "change the Type itself", "use Visit type", "use Call type id".
40
+
41
+ Plain requests like "create a meeting", "schedule a call", "create email follow-up" DO *NOT* justify changing Type. Treat them as Category changes only.
42
+
43
+ 🚫 NEVER perform ActivityType lookups for Meeting/Call/Email unless escalation trigger is present. Doing so wastes calls and breaks the 99% optimization goal.
44
+
45
+ ❌ WRONG (for ordinary meeting request): Query ActivityType 'Visit' then set TypeId=Visit.
46
+ ✅ RIGHT: Keep TypeId=Task; lookup only ActivityCategory 'Meeting'.
47
+
48
+ ---
49
+ ## 📋 STEP 1: Parse Intent → Decide Category (Type fixed = Task)
50
+
51
+ Ask (if unclear): "What kind of activity? (task / meeting / call / email)". Default = task.
52
+
53
+ ${ACTIVITY_TYPE_TABLE}
54
+
55
+ GUIDs we already have (hardcoded):
56
+ - TypeId (Task): ${DEFAULT_ACTIVITY_IDS.TYPE_TASK}
57
+ - Default Category (To do): ${DEFAULT_ACTIVITY_IDS.CATEGORY_TODO}
58
+ - Default Status (Not started): ${DEFAULT_ACTIVITY_IDS.STATUS_NOT_STARTED}
59
+ - Default Priority (Medium): ${DEFAULT_ACTIVITY_IDS.PRIORITY_MEDIUM}
60
+
61
+ If category ≠ To do (e.g. Meeting / Call / Email) and you don't have its GUID cached:
62
+ 1. Query ActivityCategory by Name (e.g. filter: "Name eq 'Meeting'") select Id top 1
63
+ 2. Use returned Id as ActivityCategoryId
64
+
65
+ Do NOT query ActivityType unless user demands non-Task type explicitly.
66
+
67
+ ---
68
+ ## 👤 STEP 2: Resolve ContactId (Owner/Author) - USE get-current-user-info!
69
+
70
+ 🎯 **DEFAULT BEHAVIOR: Activities are ALWAYS created for the current user!**
71
+
72
+ Unless the user **explicitly** requests to create an activity for someone else (e.g., "create a task for John", "schedule meeting for Anna"),
73
+ **ALWAYS** use the current user's ContactId as both OwnerId and AuthorId.
74
+
75
+ ### Get Current User ContactId:
76
+
77
+ **MANDATORY FIRST CALL:** Use \`get-current-user-info\` tool:
78
+
79
+ STEP 1: Call \`get-current-user-info\` (no parameters) ← DO THIS NOW if not done yet!
80
+ STEP 2: Extract \`contactId\` from response
81
+ STEP 3: Use contactId for OwnerId & AuthorId
82
+
83
+ **Alternative (Legacy):** Query SysAdminUnit once for ContactId (NOT Id!). Store and reuse.
84
+
85
+ ⚠️ CRITICAL:
86
+ - Never use SysAdminUnit.Id for Owner/Author fields. Always use ContactId!
87
+ - By default, OwnerId = AuthorId = current user's ContactId
88
+ - Only change if user explicitly says "for [other person]"
89
+
90
+ See /contactid-guide prompt for detailed explanation.
91
+
92
+ ---
93
+ ## ⏰ STEP 3: Timezone Handling
94
+
95
+ Always confirm timezone → convert to UTC → ISO 8601 with Z. See /datetime-guide for full details.
96
+
97
+ ---
98
+ ## 🔨 STEP 4: Construct Payload
99
+
100
+ Base payload:
101
+ \`\`\`json
102
+ {
103
+ "entity": "Activity",
104
+ "data": {
105
+ "Title": "<title>",
106
+ "TypeId": "${DEFAULT_ACTIVITY_IDS.TYPE_TASK}",
107
+ "ActivityCategoryId": "<category-guid>",
108
+ "StartDate": "<utc-start>",
109
+ "DueDate": "<utc-due>",
110
+ "StatusId": "${DEFAULT_ACTIVITY_IDS.STATUS_NOT_STARTED}",
111
+ "OwnerId": "<contactId>",
112
+ "AuthorId": "<contactId>",
113
+ "PriorityId": "${DEFAULT_ACTIVITY_IDS.PRIORITY_MEDIUM}",
114
+ "ShowInScheduler": true
115
+ }
116
+ }
117
+ \`\`\`
118
+
119
+ **CRITICAL:** Always set \`"ShowInScheduler": true\` for meetings/calls/events so they appear in the calendar!
120
+ Only set to false if user explicitly requests the activity to be hidden from calendar.
121
+
122
+ If user supplies duration only (e.g. 30m) → compute DueDate = StartDate + duration.
123
+
124
+ ---
125
+ ## 👥 STEP 5: Add Participants (Optional)
126
+
127
+ If user requests to add participants to a meeting/call/activity:
128
+ - User says: "add John to the meeting", "invite Anna", "add participant [Name]"
129
+
130
+ ### How to Add Participants:
131
+
132
+ 1. **Find the Contact:** Query Contact entity by Name to get ContactId
133
+ \`\`\`json
134
+ {
135
+ "entity": "Contact",
136
+ "filter": "contains(Name, 'John')",
137
+ "select": ["Id", "Name"],
138
+ "top": 1
139
+ }
140
+ \`\`\`
141
+
142
+ 2. **Create ActivityParticipant record:**
143
+ \`\`\`json
144
+ {
145
+ "entity": "ActivityParticipant",
146
+ "data": {
147
+ "ActivityId": "<activity-guid>",
148
+ "ParticipantId": "<contact-guid>"
149
+ }
150
+ }
151
+ \`\`\`
152
+
153
+ ⚠️ **IMPORTANT:**
154
+ - ActivityId = GUID of the Activity (meeting/call/task)
155
+ - ParticipantId = ContactId of the person to add
156
+ - **NO other fields needed!** Just these two fields are sufficient.
157
+ - You can add multiple participants by creating multiple ActivityParticipant records
158
+
159
+ ### Example:
160
+ User: "Add John and Mary to tomorrow's meeting"
161
+ 1. Create Activity → get activityId
162
+ 2. Find Contact "John" → get johnContactId
163
+ 3. Create ActivityParticipant { ActivityId: activityId, ParticipantId: johnContactId }
164
+ 4. Find Contact "Mary" → get maryContactId
165
+ 5. Create ActivityParticipant { ActivityId: activityId, ParticipantId: maryContactId }
166
+
167
+ ---
168
+ ## ✅ Example (Meeting intent, fast mode)
169
+
170
+ User: "Schedule meeting tomorrow 14:00" → ask timezone → user: "UTC+2" → 14:00 UTC+2 = 12:00Z.
171
+ 1. Resolve ContactId (SysAdminUnit query once)
172
+ 2. Lookup ActivityCategory 'Meeting' (if not cached)
173
+ 3. Create with Type=Task, Category=Meeting
174
+
175
+ ---
176
+ ## 🔁 Escalation to Extended Mode (Rare)
177
+ Trigger only if user supplies explicit escalation phrase (contains one of: "real", "actual", "true", "non-task", "not a task", "use real type", "use Visit type", "use Call type", "change the TypeId"). Simple intent words (meeting/call/email) are NOT escalation.
178
+ If triggered:
179
+ 1. Query ActivityType by Name (Call / Email / Visit)
180
+ 2. Query matching ActivityCategory
181
+ 3. Replace TypeId with looked up Id. (Ensure combination is valid.)
182
+
183
+ ---
184
+ ## 🚨 Common Mistakes
185
+ ❌ Unnecessary lookups for Meeting/Call when fast mode sufficient
186
+ ❌ Using SysAdminUnit.Id instead of ContactId
187
+ ❌ Skipping timezone confirmation
188
+ ❌ Forgetting Z suffix
189
+ ❌ Mismatching explicit non-Task request (ignore only if user accepts fast mode)
190
+ ❌ Adding extra fields to ActivityParticipant (only ActivityId + ParticipantId needed!)
191
+ ❌ Forgetting to create ActivityParticipant records when user asks to add participants
192
+
193
+ ---
194
+ ## 🧠 Decision Heuristics
195
+ If user is vague: default Category = To do.
196
+ If keywords: "meeting", "meet", "sync" → Meeting category.
197
+ "call", "phone" → Call category.
198
+ "email", "mail" → Email category.
199
+ Explicit: "task" / nothing → To do.
200
+
201
+ Return the minimal number of read calls (cache category GUIDs when first resolved in session).
202
+ `.trim();
203
+
204
+ const DATETIME_GUIDE = `
205
+ # ⏰ DateTime and Timezone Guide for Creatio
206
+
207
+ ## The Problem
208
+ You do NOT automatically know the user's timezone!
209
+ Dates in Creatio must be stored in UTC with ISO 8601 format.
210
+
211
+ ---
212
+
213
+ ## ✅ The Solution: Always Ask!
214
+
215
+ ### Step 1: Identify Date/Time from User
216
+ User says: "Create meeting tomorrow at 2pm"
217
+ - Tomorrow = calculate date
218
+ - 2pm = time in **user's local timezone**
219
+
220
+ ### Step 2: Ask for Timezone
221
+ **You:** "What timezone are you in?"
222
+
223
+ **User might say:**
224
+ - "UTC+3" or "GMT+3"
225
+ - "Europe/Kiev" or "Europe/Warsaw"
226
+ - "EST" or "PST"
227
+ - "My local time is 2pm now" (calculate offset)
228
+
229
+ ### Step 3: Convert to UTC
230
+ Formula: **UTC = Local Time - Offset**
231
+
232
+ Examples:
233
+ - 2pm UTC+3 → 2pm - 3h = **11am UTC**
234
+ - 9am UTC-5 (EST) → 9am - (-5h) = 9am + 5h = **2pm UTC**
235
+ - 10pm UTC+0 → **10pm UTC** (no conversion)
236
+
237
+ ### Step 4: Format as ISO 8601 with Z suffix
238
+ Format: \`YYYY-MM-DDTHH:mm:ss**Z**\`
239
+
240
+ Examples:
241
+ - \`2024-01-16T11:00:00Z\`
242
+ - \`2024-12-25T14:30:00Z\`
243
+ - \`2025-03-01T00:00:00Z\`
244
+
245
+ **The Z suffix means UTC!** Never omit it.
246
+
247
+ ---
248
+
249
+ ## 📋 Common Timezone Reference
250
+
251
+ | Timezone | Offset | Example: 2pm local → UTC |
252
+ |-------------------|---------|--------------------------|
253
+ | UTC+0 (London) | +0 | 2pm → 2pm UTC |
254
+ | UTC+1 (Paris) | +1 | 2pm → 1pm UTC |
255
+ | UTC+2 (Kyiv) | +2 | 2pm → 12pm UTC |
256
+ | UTC+3 (Moscow) | +3 | 2pm → 11am UTC |
257
+ | UTC-5 (EST/NY) | -5 | 2pm → 7pm UTC |
258
+ | UTC-8 (PST/LA) | -8 | 2pm → 10pm UTC |
259
+
260
+ ---
261
+
262
+ ## 💡 Conversation Examples
263
+
264
+ ### Example 1: Clear timezone
265
+ **User:** "Create task tomorrow at 9am EST"
266
+ **You:** *(recognize EST = UTC-5)*
267
+ - Tomorrow = 2024-01-16
268
+ - 9am EST = 9am + 5h = 2pm UTC
269
+ - Store: \`"StartDate": "2024-01-16T14:00:00Z"\`
270
+
271
+ ### Example 2: Ask for clarification
272
+ **User:** "Meeting at 3pm"
273
+ **You:** "What timezone are you in?"
274
+ **User:** "UTC+3"
275
+ **You:** *(calculate)*
276
+ - 3pm UTC+3 = 3pm - 3h = 12pm UTC
277
+ - Store: \`"StartDate": "2024-01-16T12:00:00Z"\`
278
+
279
+ ### Example 3: Relative time
280
+ **User:** "Create task in 2 hours"
281
+ **You:** "What timezone?"
282
+ **User:** "It's 4pm here, UTC+2"
283
+ **You:** *(calculate)*
284
+ - Now: 4pm UTC+2 = 2pm UTC
285
+ - In 2 hours: 2pm + 2h = 4pm UTC
286
+ - Store: \`"StartDate": "2024-01-16T16:00:00Z"\`
287
+
288
+ ---
289
+
290
+ ## 🚨 Critical Rules
291
+
292
+ 1. ⚠️ **ALWAYS ask timezone** - never assume!
293
+ 2. ⚠️ **ALWAYS use Z suffix** - indicates UTC
294
+ 3. ⚠️ **Subtract offset for east** (UTC+) - e.g., UTC+3 → subtract 3
295
+ 4. ⚠️ **Add offset for west** (UTC-) - e.g., UTC-5 → add 5
296
+ 5. ⚠️ **Store in UTC** - Creatio expects UTC, not local time
297
+
298
+ ---
299
+
300
+ ## 🎯 Quick Checklist
301
+
302
+ Before storing ANY date in Creatio:
303
+ - [ ] Asked user for timezone?
304
+ - [ ] Converted local time to UTC?
305
+ - [ ] Used ISO 8601 format?
306
+ - [ ] Added Z suffix?
307
+ - [ ] Double-checked offset direction?
308
+
309
+ If all ✅ → Good to go!
310
+ `.trim();
311
+
312
+ const CONTACTID_GUIDE = `
313
+ # 👤 ContactId Rule - UNIVERSAL for ALL Creatio Entities
314
+
315
+ ## 🚨 CRITICAL RULE (Read This First!)
316
+
317
+ In Creatio, there are TWO types of IDs:
318
+
319
+ 1. **SysAdminUnit.Id** = User account ID (for login/permissions)
320
+ 2. **SysAdminUnit.ContactId** = Contact ID (for CRM records)
321
+
322
+ ### For CRM fields, ALWAYS use ContactId!
323
+
324
+ This applies to **ALL entities**, not just Activity:
325
+ - Activity.OwnerId = ContactId ✅
326
+ - Activity.AuthorId = ContactId ✅
327
+ - Lead.OwnerId = ContactId ✅
328
+ - Opportunity.OwnerId = ContactId ✅
329
+ - Case.OwnerId = ContactId ✅
330
+ - Account.OwnerId = ContactId ✅
331
+
332
+ ---
333
+
334
+ ## 🎯 The Workflow (RECOMMENDED!)
335
+
336
+ ### 🔑 DEFAULT RULE: Current User by Default!
337
+
338
+ **ALWAYS assume activities/tasks/leads/opportunities are for the CURRENT USER unless explicitly told otherwise!**
339
+
340
+ Examples:
341
+ - ❌ "Create task" → DO NOT ask "for whom?" → Create for current user!
342
+ - ❌ "Schedule meeting tomorrow" → DO NOT ask "whose meeting?" → Current user's meeting!
343
+ - ✅ "Create task for John" → Only THEN create for someone else
344
+ - ✅ "Schedule meeting with Anna as owner" → Only THEN change owner
345
+
346
+ **This is the expected behavior! Don't annoy users by asking obvious questions.**
347
+
348
+ ### Step 1: Use get-current-user-info Tool (BEST METHOD!)
349
+
350
+ **RECOMMENDED:** Use the dedicated tool to get user information:
351
+
352
+ Call \`get-current-user-info\` tool (no parameters needed)
353
+
354
+ **Returns:**
355
+ \`\`\`json
356
+ {
357
+ "userId": "410006e1-ca4e-4502-a9ec-e54d922d2c00",
358
+ "contactId": "76929f8c-7e15-4c64-bdb0-adc62d383727", // ← USE THIS!
359
+ "userName": "Current User",
360
+ "cultureName": "en-US"
361
+ }
362
+ \`\`\`
363
+
364
+ **Why this is better:**
365
+ - ✅ Single call, all info
366
+ - ✅ No need to know username
367
+ - ✅ Gets ContactId directly
368
+ - ✅ More reliable
369
+ - ✅ Use contactId for ALL Owner/Author fields by default
370
+
371
+ ### Alternative: Query SysAdminUnit (Legacy Method)
372
+
373
+ If you need to query manually:
374
+
375
+ \`\`\`json
376
+ {
377
+ "entity": "SysAdminUnit",
378
+ "filter": "Name eq '<your_username>'",
379
+ "select": ["ContactId"],
380
+ "top": 1
381
+ }
382
+ \`\`\`
383
+
384
+ **Returns:**
385
+ \`\`\`json
386
+ [{
387
+ "ContactId": "76929f8c-7e15-4c64-bfb1-40c705d25fcd"
388
+ }]
389
+ \`\`\`
390
+
391
+ ### Step 2: Store ContactId in Memory
392
+
393
+ Remember the ContactId for the entire conversation:
394
+
395
+ \`\`\`typescript
396
+ const currentUserContactId = "76929f8c-7e15-4c64-bfb1-40c705d25fcd";
397
+ \`\`\`
398
+
399
+ ### Step 3: Use This ContactId EVERYWHERE
400
+
401
+ For **ANY** entity that has owner/author/creator fields:
402
+
403
+ \`\`\`json
404
+ {
405
+ "entity": "Activity",
406
+ "data": {
407
+ "OwnerId": currentUserContactId, // ← ContactId
408
+ "AuthorId": currentUserContactId // ← ContactId
409
+ }
410
+ }
411
+ \`\`\`
412
+
413
+ \`\`\`json
414
+ {
415
+ "entity": "Lead",
416
+ "data": {
417
+ "OwnerId": currentUserContactId // ← ContactId
418
+ }
419
+ }
420
+ \`\`\`
421
+
422
+ \`\`\`json
423
+ {
424
+ "entity": "Opportunity",
425
+ "data": {
426
+ "OwnerId": currentUserContactId // ← ContactId
427
+ }
428
+ }
429
+ \`\`\`
430
+
431
+ ---
432
+
433
+ ## ❌ Common Mistake
434
+
435
+ ### WRONG (using SysAdminUnit.Id):
436
+ \`\`\`json
437
+ // Step 1: Query SysAdminUnit
438
+ read("SysAdminUnit", "Name eq '<your_username>'", ["Id"], 1)
439
+ // → Returns: [{ "Id": "410006e1-ca4e-4502-a9ec-e54d922d2c00" }]
440
+
441
+ // Step 2: Use .Id (WRONG!)
442
+ create("Activity", {
443
+ "OwnerId": "410006e1-ca4e-4502-a9ec-e54d922d2c00" // ❌ This is user ID!
444
+ })
445
+ // → ERROR: Invalid reference or constraint violation!
446
+ \`\`\`
447
+
448
+ ### ✅ CORRECT (using ContactId):
449
+ \`\`\`json
450
+ // Step 1: Query SysAdminUnit
451
+ read("SysAdminUnit", "Name eq '<your_username>'", ["ContactId"], 1)
452
+ // → Returns: [{ "ContactId": "76929f8c-7e15-4c64-bfb1-40c705d25fcd" }]
453
+
454
+ // Step 2: Use .ContactId (CORRECT!)
455
+ create("Activity", {
456
+ "OwnerId": "76929f8c-7e15-4c64-bfb1-40c705d25fcd" // ✅ This is contact ID!
457
+ })
458
+ // → SUCCESS!
459
+ \`\`\`
460
+
461
+ ---
462
+
463
+ ## 🔍 Visual Explanation
464
+
465
+ \`\`\`
466
+ SysAdminUnit "<your_username>":
467
+ ├─ Id: "410006e1..." ← USER account (for system/permissions)
468
+ │ └─ Used for: Login, roles, access rights
469
+
470
+ └─ ContactId: "76929f8c..." ← CONTACT record (for CRM)
471
+ └─ Used for: Activities, Leads, Opportunities, Owners, Authors
472
+
473
+ Contact "John Doe":
474
+ └─ Id: "76929f8c..." ← Same as SysAdminUnit.ContactId!
475
+ └─ This is the CRM person record
476
+ \`\`\`
477
+
478
+ ---
479
+
480
+ ## 📋 When to Use Each ID
481
+
482
+ | Field Type | Use This | Example Entity |
483
+ |-------------------------------|-----------------|------------------------|
484
+ | OwnerId | **ContactId** | Activity, Lead, Case |
485
+ | AuthorId | **ContactId** | Activity |
486
+ | CreatedById | **ContactId** | Any entity |
487
+ | ModifiedById | **ContactId** | Any entity |
488
+ | ContactId (in Activity) | **ContactId** | Activity |
489
+ | ParticipantId | **ContactId** | ActivityParticipant |
490
+ | ResponsibleId | **ContactId** | Lead, Opportunity |
491
+ | System permissions/roles | **Id** | SysAdminUnit relations |
492
+
493
+ **Rule of thumb:** If it's a CRM field → **ContactId**. Always.
494
+
495
+ ---
496
+
497
+ ## 🎯 Best Practice
498
+
499
+ At the **start of any workflow** that needs user identity:
500
+
501
+ 1. Query \`SysAdminUnit\` once
502
+ 2. Select \`["ContactId"]\`
503
+ 3. Store in variable
504
+ 4. Use everywhere
505
+
506
+ **Don't query multiple times!** One query per session is enough.
507
+
508
+ ---
509
+
510
+ ## ⚠️ What If I Used Wrong ID?
511
+
512
+ You'll see errors like:
513
+ - "Foreign key constraint violation"
514
+ - "Invalid reference"
515
+ - "Record not found"
516
+ - Owner field is empty or points to wrong person
517
+
518
+ **Solution:** Go back and use ContactId instead of Id!
519
+
520
+ ---
521
+
522
+ ## 💡 Summary
523
+
524
+ - **SysAdminUnit.Id** = User account (system)
525
+ - **SysAdminUnit.ContactId** = Contact person (CRM)
526
+ - **For CRM fields** → ALWAYS use ContactId
527
+ - **Query once** → Use everywhere
528
+ - **This rule applies** → ALL entities in Creatio
529
+
530
+ Remember: **ContactId, not Id!** 🎯
531
+ `.trim();
532
+
533
+ const TAGGING_GUIDE = `
534
+ # 🏷️ Tagging Records in Creatio
535
+
536
+ ## 🚨 CRITICAL DECISION: Which Tag System?
537
+
538
+ Creatio has TWO tagging systems that may coexist:
539
+
540
+ ### 1️⃣ LEGACY System (Entity-Specific) - **DEFAULT & RECOMMENDED**
541
+ - Uses: \`<Entity>Tag\` and \`<Entity>InTag\` tables
542
+ - Examples: \`ActivityTag\` + \`ActivityInTag\`, \`AccountTag\` + \`AccountInTag\`
543
+ - Fields: \`TagId\` (from <Entity>Tag), \`EntityId\` (record GUID)
544
+ - **Use this by DEFAULT unless user explicitly asks for universal tags!**
545
+
546
+ ### 2️⃣ NEW System (Universal)
547
+ - Uses: \`Tag\` and \`TagInRecord\` tables
548
+ - Fields: \`TagId\`, \`RecordId\`, \`RecordSchemaName\`
549
+ - Only use if user specifically says "use universal tags" or "use new tag system"
550
+
551
+ ---
552
+
553
+ ## ⚡ Quick Decision Flow
554
+
555
+ **MANDATORY behavior:**
556
+ 1. Check if \`<Entity>Tag\` exists (e.g., \`ActivityTag\`)
557
+ 2. If BOTH systems exist (Legacy AND Universal):
558
+ → **ALWAYS ASK USER**: "Which tagging system should I use: legacy (ActivityTag/ActivityInTag) or universal (Tag/TagInRecord)?"
559
+ → Wait for explicit user response - NO DEFAULT!
560
+ → User must choose: "legacy" or "universal"
561
+ 3. If ONLY legacy exists → Use legacy (no question needed)
562
+ 4. If ONLY universal exists → Use universal (no question needed)
563
+
564
+ **CRITICAL:** Never auto-choose when both systems are available! Always ask and wait for clear answer!
565
+
566
+ ---
567
+
568
+ ## 📋 STEP-BY-STEP WORKFLOW
569
+
570
+ ### Step 1: Identify Target Entity & Record
571
+ - Extract entity name (Activity, Contact, Account, etc.)
572
+ - Get record GUID (from context or ask user)
573
+ - Store as: \`entityName\`, \`recordId\`
574
+
575
+ ### Step 2: Choose System (MANDATORY CHECK!)
576
+
577
+ **Always perform this check:**
578
+
579
+ 1. Try describe-entity on \`<Entity>Tag\` (e.g., "ActivityTag")
580
+ 2. Try describe-entity on \`Tag\`
581
+ 3. Determine availability:
582
+ - BOTH exist → **ASK USER MANDATORY**: "I found both tagging systems. Which one should I use: legacy (<Entity>Tag) or universal (Tag)?"
583
+ - ONLY legacy exists → Use legacy automatically
584
+ - ONLY universal exists → Use universal automatically
585
+ - NEITHER exists → Error (cannot tag)
586
+
587
+ **User response handling:**
588
+ - "legacy" / "old" / "entity-specific" / "<Entity>Tag" → useLegacy = true
589
+ - "universal" / "new" / "Tag" / "TagInRecord" → useLegacy = false
590
+ - If unclear response → Ask again for clarification
591
+
592
+ **NEVER skip the question when both systems are present!**
593
+ **NEVER assume a default - wait for explicit user choice!**
594
+
595
+ ### Step 3: Resolve or Create Tag
596
+
597
+ **Tag name can be ANY value provided by user** (e.g., "VIP", "Urgent", "Follow-up", "Important", etc.)
598
+
599
+ **For LEGACY system:**
600
+ 1. Try to find existing tag: read <Entity>Tag where Name eq '<TagName>' select Id top 1
601
+ 2. If not found, create it: create <Entity>Tag with Name: "<TagName>"
602
+ 3. Returns tag Id (GUID)
603
+
604
+ **For UNIVERSAL system:**
605
+ 1. Try to find existing tag: read Tag where Name eq '<TagName>' and EntitySchemaName eq '<Entity>' select Id top 1
606
+ 2. If not found, create it: create Tag with Name: "<TagName>", EntitySchemaName: "<Entity>"
607
+ 3. Returns tag Id (GUID)
608
+
609
+ ### Step 4: Check if Already Tagged
610
+ Avoid duplicate links!
611
+
612
+ **LEGACY:**
613
+ - read <Entity>InTag where TagId eq <tag-guid> and EntityId eq <record-guid> select Id top 1
614
+
615
+ **UNIVERSAL:**
616
+ - read TagInRecord where TagId eq <tag-guid> and RecordId eq <record-guid> select Id top 1
617
+
618
+ ### Step 5: Create Link (if not exists)
619
+
620
+ **LEGACY:**
621
+ - create <Entity>InTag with TagId: <tag-guid>, EntityId: <record-guid>
622
+
623
+ **UNIVERSAL:**
624
+ - create TagInRecord with TagId: <tag-guid>, RecordId: <record-guid>, RecordSchemaName: "<Entity>"
625
+
626
+ ---
627
+
628
+ ## 💡 Examples
629
+
630
+ ### Example 1: Add "VIP" tag to Activity (Standard Request)
631
+
632
+ User: "Add tag VIP to this meeting"
633
+
634
+ LLM Actions:
635
+ 1. Detect: Entity = Activity, recordId from context
636
+ 2. Check: ActivityTag exists? YES. Tag exists? YES (BOTH found!)
637
+ 3. ASK USER: "Which tagging system should I use: legacy (ActivityTag) or universal (Tag)?"
638
+ 4. User: "legacy"
639
+ 5. Query: ActivityTag where Name='VIP' (found: "9dd32c9f...")
640
+ 6. Check: ActivityInTag link exists? NO
641
+ 7. Create: ActivityInTag with TagId: "9dd32c9f...", EntityId: "meeting-id"
642
+ 8. Report: "Added VIP tag to meeting using legacy system"
643
+
644
+ ### Example 2: User explicitly wants universal system
645
+
646
+ User: "Add tag Important using the new universal tag system"
647
+
648
+ LLM Actions:
649
+ 1. User specified "new universal" (useLegacy = false, skip question!)
650
+ 2. Query: Tag where Name='Important' and EntitySchemaName='Activity'
651
+ 3. If not found: Create Tag with Name: "Important", EntitySchemaName: "Activity"
652
+ 4. Create: TagInRecord with TagId, RecordId, RecordSchemaName: "Activity"
653
+ 5. Report: "Added Important tag using universal system"
654
+
655
+ ### Example 3: Legacy system doesn't exist
656
+
657
+ User: "Add tag to CustomEntity"
658
+
659
+ LLM Actions:
660
+ 1. Check: CustomEntityTag exists? NO
661
+ 2. Auto-fallback: Use universal system
662
+ 3. Query/Create in Tag table
663
+ 4. Link via TagInRecord
664
+
665
+ ---
666
+
667
+ ## 🚨 Common Mistakes to Avoid
668
+
669
+ ❌ **WRONG:** Auto-choosing system when both exist
670
+ ✅ **RIGHT:** ALWAYS ask user when both legacy and universal are available
671
+
672
+ ❌ **WRONG:** Creating duplicate tags without checking
673
+ ✅ **RIGHT:** Always check existence first
674
+
675
+ ❌ **WRONG:** Not checking if link already exists
676
+ ✅ **RIGHT:** Query <Entity>InTag or TagInRecord before creating
677
+
678
+ ❌ **WRONG:** Skipping the mandatory question
679
+ ✅ **RIGHT:** If both systems exist, MUST ask user which one to use
680
+
681
+ ---
682
+
683
+ ## 📊 Quick Reference Table
684
+
685
+ | Entity | Tag Table | Link Table | Tag Field | Record Field |
686
+ |-----------|----------------|-------------------|-----------|--------------|
687
+ | Activity | ActivityTag | ActivityInTag | TagId | EntityId |
688
+ | Account | AccountTag | AccountInTag | TagId | EntityId |
689
+ | Contact | ContactTag | ContactInTag | TagId | EntityId |
690
+ | Lead | LeadTag | LeadInTag | TagId | EntityId |
691
+ | Case | CaseTag | CaseInTag | TagId | EntityId |
692
+ | *Universal* | Tag | TagInRecord | TagId | RecordId |
693
+
694
+ ---
695
+
696
+ ## ✅ Final Checklist
697
+
698
+ Before creating a tag link:
699
+ - [ ] Entity and record GUID identified
700
+ - [ ] System auto-detected (legacy preferred)
701
+ - [ ] Tag resolved or created in correct table
702
+ - [ ] Existing link checked (no duplicates)
703
+ - [ ] Link created in correct table
704
+ - [ ] User notified of success
705
+
706
+ ---
707
+
708
+ ## 🎯 Remember
709
+
710
+ **The Golden Rule:** When BOTH systems exist - ALWAYS ASK USER (no defaults!)
711
+
712
+ Question format: "I found both tagging systems for <Entity>. Which should I use: legacy (<Entity>Tag) or universal (Tag)?"
713
+
714
+ **Wait for explicit answer!** Do not proceed until user chooses.
715
+
716
+ Only skip question if:
717
+ - ONLY legacy exists → Use legacy automatically
718
+ - ONLY universal exists → Use universal automatically
719
+ - User already specified in original request (e.g., "use new tag system")
720
+
721
+ **Tag names:** Can be ANY value user provides (VIP, Urgent, Important, Follow-up, etc.)
722
+
723
+ **DO NOT assume or auto-choose when both are present!**
724
+ `.trim();
725
+
726
+ const SYS_SETTINGS_VALUE_TYPES_TABLE = `
727
+ | valueTypeName | Display label |
728
+ | ------------- | ----------------------- |
729
+ | Binary | BLOB |
730
+ | Boolean | Boolean |
731
+ | DateTime | Date/Time |
732
+ | Date | Date |
733
+ | Time | Time |
734
+ | Integer | Integer |
735
+ | Money | Currency (0.01) |
736
+ | Float | Decimal |
737
+ | Lookup | Lookup |
738
+ | ShortText | Text (50 characters) |
739
+ | MediumText | Text (250 characters) |
740
+ | LongText | Text (500 characters) |
741
+ | Text | Text |
742
+ | MaxSizeText | Unlimited length text |
743
+ | SecureText | Encrypted string |
744
+ `.trim();
745
+
746
+ const SYS_SETTINGS_GUIDE = `
747
+ # ⚙️ Creating Creatio System Settings
748
+
749
+ ## Supported valueTypeName values
750
+ Always use the **value** column (not the display label) when filling \`definition.valueTypeName\`.
751
+
752
+ ${SYS_SETTINGS_VALUE_TYPES_TABLE}
753
+
754
+ ## Discovering existing system settings
755
+ To inspect what system settings already exist (names, codes, value types, cache flags, etc.), query the
756
+ \`VwSysSetting\` view via the standard \`read\` tool. Example:
757
+
758
+ \`\`\`json
759
+ {
760
+ "entity": "VwSysSetting",
761
+ "select": [
762
+ "Id",
763
+ "Name",
764
+ "Code",
765
+ "Description",
766
+ "ValueTypeName",
767
+ "IsPersonal",
768
+ "IsCacheable"
769
+ ],
770
+ "top": 50
771
+ }
772
+ \`\`\`
773
+
774
+ Filter by \`Code\` or \`Name\` to narrow results (e.g., \`"filters":{"all":[{"field":"Code","op":"contains","value":"Product"}]}\`).
775
+ This is the fastest way to learn which settings already exist before inserting new ones.
776
+
777
+ ## Lookup referenceSchemaUId
778
+ - Required only when \`valueTypeName = "Lookup"\`.
779
+ - Set \`definition.referenceSchemaUId\` to the EntitySchema UId of the lookup target.
780
+ - Fetch the UId from \`VwWorkspaceObjects\` by filtering on the schema name.
781
+
782
+ ### Example MCP read request
783
+ \`\`\`json
784
+ {
785
+ "entity": "VwWorkspaceObjects",
786
+ "filters": {
787
+ "all": [
788
+ { "field": "Name", "op": "eq", "value": "Account" }
789
+ ]
790
+ },
791
+ "select": ["UId", "Name", "Caption"]
792
+ }
793
+ \`\`\`
794
+
795
+ Use the returned \`UId\` as \`referenceSchemaUId\` inside the \`create-sys-setting\` tool payload.
796
+
797
+ ## Quick workflow reminder
798
+ 1. Insert sys setting metadata via \`create-sys-setting\`.
799
+ 2. Optionally include \`initialValue\` to write the first value immediately.
800
+ 3. For additional updates later, call \`set-sys-settings-value\`.
801
+ `.trim();
802
+
803
+ export const CREATE_ACTIVITY_PROMPT = {
804
+ name: 'create-activity-guide',
805
+ title: 'Create Activity in Creatio',
806
+ description:
807
+ 'Complete step-by-step guide for creating Activities (tasks/meetings/calls) in Creatio',
808
+ argsSchema: {},
809
+ callback: () => ({
810
+ messages: [
811
+ {
812
+ role: 'user' as const,
813
+ content: {
814
+ type: 'text' as const,
815
+ text: CREATE_ACTIVITY_WORKFLOW,
816
+ },
817
+ },
818
+ ],
819
+ }),
820
+ };
821
+ export const DATETIME_PROMPT = {
822
+ name: 'datetime-guide',
823
+ title: 'DateTime and Timezone Guide',
824
+ description: 'How to ask users for timezone and convert to UTC for Creatio',
825
+ argsSchema: {},
826
+ callback: () => ({
827
+ messages: [
828
+ {
829
+ role: 'user' as const,
830
+ content: {
831
+ type: 'text' as const,
832
+ text: DATETIME_GUIDE,
833
+ },
834
+ },
835
+ ],
836
+ }),
837
+ };
838
+
839
+ export const CONTACTID_PROMPT = {
840
+ name: 'contactid-guide',
841
+ title: 'ContactId Rule for All Entities',
842
+ description:
843
+ 'CRITICAL: Always use SysAdminUnit.ContactId (not .Id!) for all CRM fields across all entities',
844
+ argsSchema: {},
845
+ callback: () => ({
846
+ messages: [
847
+ {
848
+ role: 'user' as const,
849
+ content: {
850
+ type: 'text' as const,
851
+ text: CONTACTID_GUIDE,
852
+ },
853
+ },
854
+ ],
855
+ }),
856
+ };
857
+
858
+ export const TAGGING_PROMPT = {
859
+ name: 'tagging-guide',
860
+ title: 'Tagging Records (New & Legacy Systems)',
861
+ description:
862
+ 'Guide for adding tags to records using Tag/TagInRecord or legacy <Entity>Tag / <Entity>InTag tables',
863
+ argsSchema: {},
864
+ callback: () => ({
865
+ messages: [
866
+ {
867
+ role: 'user' as const,
868
+ content: { type: 'text' as const, text: TAGGING_GUIDE },
869
+ },
870
+ ],
871
+ }),
872
+ };
873
+
874
+ export const SYS_SETTINGS_PROMPT = {
875
+ name: 'sys-settings-guide',
876
+ title: 'Creatio System Settings Guide',
877
+ description:
878
+ 'Value type options and lookup reference instructions for create-sys-setting / set-sys-settings-value workflows',
879
+ argsSchema: {},
880
+ callback: () => ({
881
+ messages: [
882
+ {
883
+ role: 'user' as const,
884
+ content: { type: 'text' as const, text: SYS_SETTINGS_GUIDE },
885
+ },
886
+ ],
887
+ }),
888
+ };
889
+
890
+ export const ALL_PROMPTS = [
891
+ CREATE_ACTIVITY_PROMPT,
892
+ DATETIME_PROMPT,
893
+ CONTACTID_PROMPT,
894
+ TAGGING_PROMPT,
895
+ SYS_SETTINGS_PROMPT,
896
+ ] as const;