index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // Zoho Tasks Plugin v2.2.0
  2. // EU data center: accounts.zoho.eu
  3. // Action-based tool surface, mirroring the ShadowMan C++ builtin style
  4. // (see manage_mcp, kb, skill, office etc. — one tool per resource, with
  5. // an `action` enum that picks a sub-operation).
  6. var auth = require('./lib/auth');
  7. var tasks = require('./lib/tasks');
  8. shadowman.log.info('Zoho Tasks plugin v2.2.0 loaded');
  9. function requireAuth() {
  10. var token = auth.getValidToken();
  11. if (!token) return { token: null, error: 'Not authenticated. Run zoho_auth action=setup with a grant token first.' };
  12. return { token: token };
  13. }
  14. function missing(field) { return { error: 'Missing ' + field + ' parameter' }; }
  15. // ────────────────────────────────────────────────────────────────────────
  16. // zoho_auth — actions: setup, status, resolve_portal
  17. // ────────────────────────────────────────────────────────────────────────
  18. shadowman.tools.register('zoho_auth', function(args, context) {
  19. var action = args.action;
  20. if (!action) return missing('action');
  21. if (action === 'setup') {
  22. if (!args.grant_token) return missing('grant_token');
  23. shadowman.storage.set('auth_conversation_id', context.conversationId);
  24. return auth.setupAuth(args.grant_token);
  25. }
  26. if (action === 'status') {
  27. return auth.getStatus();
  28. }
  29. if (action === 'resolve_portal') {
  30. var a = requireAuth(); if (a.error) return { error: a.error };
  31. return auth.resolvePortal(a.token, args);
  32. }
  33. return { error: 'Unknown action: ' + action };
  34. });
  35. // ────────────────────────────────────────────────────────────────────────
  36. // zoho_project — actions: list, get, users, statuses
  37. // ────────────────────────────────────────────────────────────────────────
  38. shadowman.tools.register('zoho_project', function(args) {
  39. var a = requireAuth(); if (a.error) return { error: a.error };
  40. var action = args.action;
  41. if (!action) return missing('action');
  42. if (action === 'list') {
  43. return tasks.listProjects(a.token, args.index || 1);
  44. }
  45. if (action === 'get') {
  46. if (!args.project_id) return missing('project_id');
  47. return tasks.getProject(a.token, args.project_id);
  48. }
  49. if (action === 'users') {
  50. return tasks.listUsers(a.token, args);
  51. }
  52. if (action === 'statuses') {
  53. if (!args.project_id) return missing('project_id');
  54. return tasks.listTaskStatuses(a.token, args.project_id);
  55. }
  56. return { error: 'Unknown action: ' + action };
  57. });
  58. // ────────────────────────────────────────────────────────────────────────
  59. // zoho_task — actions: list, get, create, update, delete, subtasks, my, search
  60. // ────────────────────────────────────────────────────────────────────────
  61. shadowman.tools.register('zoho_task', function(args) {
  62. var a = requireAuth(); if (a.error) return { error: a.error };
  63. var action = args.action;
  64. if (!action) return missing('action');
  65. if (action === 'my') {
  66. return tasks.getMyTasks(a.token, args);
  67. }
  68. if (action === 'search') {
  69. if (!args.query) return missing('query');
  70. return tasks.searchTasks(a.token, args);
  71. }
  72. if (!args.project_id) return missing('project_id');
  73. if (action === 'list') {
  74. return tasks.listTasks(a.token, args.project_id, args);
  75. }
  76. if (action === 'get') {
  77. if (!args.task_id) return missing('task_id');
  78. return tasks.getTask(a.token, args.project_id, args.task_id);
  79. }
  80. if (action === 'create') {
  81. if (!args.name) return missing('name');
  82. return tasks.createTask(a.token, args.project_id, args);
  83. }
  84. if (action === 'update') {
  85. if (!args.task_id) return missing('task_id');
  86. return tasks.updateTask(a.token, args.project_id, args.task_id, args);
  87. }
  88. if (action === 'delete') {
  89. if (!args.task_id) return missing('task_id');
  90. return tasks.deleteTask(a.token, args.project_id, args.task_id);
  91. }
  92. if (action === 'subtasks') {
  93. if (!args.task_id) return missing('task_id');
  94. return tasks.listSubtasks(a.token, args.project_id, args.task_id);
  95. }
  96. return { error: 'Unknown action: ' + action };
  97. });
  98. // ────────────────────────────────────────────────────────────────────────
  99. // zoho_comment — actions: list, add, update, delete
  100. // ────────────────────────────────────────────────────────────────────────
  101. shadowman.tools.register('zoho_comment', function(args) {
  102. var a = requireAuth(); if (a.error) return { error: a.error };
  103. var action = args.action;
  104. if (!action) return missing('action');
  105. if (!args.project_id) return missing('project_id');
  106. if (!args.task_id) return missing('task_id');
  107. if (action === 'list') {
  108. return tasks.listComments(a.token, args.project_id, args.task_id, args.index);
  109. }
  110. if (action === 'add') {
  111. if (!args.content) return missing('content');
  112. return tasks.addComment(a.token, args.project_id, args.task_id, args.content);
  113. }
  114. if (action === 'update') {
  115. if (!args.comment_id) return missing('comment_id');
  116. if (!args.content) return missing('content');
  117. return tasks.updateComment(a.token, args.project_id, args.task_id, args.comment_id, args.content);
  118. }
  119. if (action === 'delete') {
  120. if (!args.comment_id) return missing('comment_id');
  121. return tasks.deleteComment(a.token, args.project_id, args.task_id, args.comment_id);
  122. }
  123. return { error: 'Unknown action: ' + action };
  124. });
  125. // ────────────────────────────────────────────────────────────────────────
  126. // zoho_milestone — actions: list, create, update, delete
  127. // ────────────────────────────────────────────────────────────────────────
  128. shadowman.tools.register('zoho_milestone', function(args) {
  129. var a = requireAuth(); if (a.error) return { error: a.error };
  130. var action = args.action;
  131. if (!action) return missing('action');
  132. if (!args.project_id) return missing('project_id');
  133. if (action === 'list') {
  134. return tasks.listMilestones(a.token, args.project_id, args);
  135. }
  136. if (action === 'create') {
  137. if (!args.name) return missing('name');
  138. return tasks.createMilestone(a.token, args.project_id, args);
  139. }
  140. if (action === 'update') {
  141. if (!args.milestone_id) return missing('milestone_id');
  142. return tasks.updateMilestone(a.token, args.project_id, args.milestone_id, args);
  143. }
  144. if (action === 'delete') {
  145. if (!args.milestone_id) return missing('milestone_id');
  146. return tasks.deleteMilestone(a.token, args.project_id, args.milestone_id);
  147. }
  148. return { error: 'Unknown action: ' + action };
  149. });
  150. // ────────────────────────────────────────────────────────────────────────
  151. // zoho_tasklist — actions: list, get, create, update, delete
  152. // ────────────────────────────────────────────────────────────────────────
  153. shadowman.tools.register('zoho_tasklist', function(args) {
  154. var a = requireAuth(); if (a.error) return { error: a.error };
  155. var action = args.action;
  156. if (!action) return missing('action');
  157. if (action === 'list') {
  158. return tasks.listTasklists(a.token, args.project_id, args);
  159. }
  160. if (!args.project_id) return missing('project_id');
  161. if (action === 'get') {
  162. if (!args.tasklist_id) return missing('tasklist_id');
  163. return tasks.getTasklist(a.token, args.project_id, args.tasklist_id);
  164. }
  165. if (action === 'create') {
  166. if (!args.name) return missing('name');
  167. return tasks.createTasklist(a.token, args.project_id, args);
  168. }
  169. if (action === 'update') {
  170. if (!args.tasklist_id) return missing('tasklist_id');
  171. return tasks.updateTasklist(a.token, args.project_id, args.tasklist_id, args);
  172. }
  173. if (action === 'delete') {
  174. if (!args.tasklist_id) return missing('tasklist_id');
  175. return tasks.deleteTasklist(a.token, args.project_id, args.tasklist_id);
  176. }
  177. return { error: 'Unknown action: ' + action };
  178. });
  179. // ────────────────────────────────────────────────────────────────────────
  180. // zoho_timesheet — actions: list, create, update, delete
  181. // ────────────────────────────────────────────────────────────────────────
  182. shadowman.tools.register('zoho_timesheet', function(args) {
  183. var a = requireAuth(); if (a.error) return { error: a.error };
  184. var action = args.action;
  185. if (!action) return missing('action');
  186. if (!args.project_id) return missing('project_id');
  187. if (action === 'list') {
  188. return tasks.listTimesheets(a.token, args.project_id, args);
  189. }
  190. if (action === 'create') {
  191. if (!args.task_id) return missing('task_id');
  192. if (args.hours === undefined) return missing('hours');
  193. return tasks.logTime(a.token, args.project_id, args);
  194. }
  195. if (action === 'update') {
  196. if (!args.log_id) return missing('log_id');
  197. return tasks.updateTimesheet(a.token, args.project_id, args.log_id, args);
  198. }
  199. if (action === 'delete') {
  200. if (!args.log_id) return missing('log_id');
  201. return tasks.deleteTimesheet(a.token, args.project_id, args.log_id);
  202. }
  203. return { error: 'Unknown action: ' + action };
  204. });