runline 0.1.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 (230) hide show
  1. package/.pi/extensions/runline-context/index.ts +135 -0
  2. package/.pi/extensions/runline-context/package.json +17 -0
  3. package/README.md +273 -0
  4. package/dist/commands/actions.d.ts +3 -0
  5. package/dist/commands/actions.js +43 -0
  6. package/dist/commands/connection.d.ts +11 -0
  7. package/dist/commands/connection.js +56 -0
  8. package/dist/commands/exec.d.ts +5 -0
  9. package/dist/commands/exec.js +46 -0
  10. package/dist/commands/init.d.ts +4 -0
  11. package/dist/commands/init.js +26 -0
  12. package/dist/commands/plugin.d.ts +10 -0
  13. package/dist/commands/plugin.js +57 -0
  14. package/dist/config/index.d.ts +3 -0
  15. package/dist/config/index.js +2 -0
  16. package/dist/config/loader.d.ts +11 -0
  17. package/dist/config/loader.js +82 -0
  18. package/dist/config/types.d.ts +9 -0
  19. package/dist/config/types.js +5 -0
  20. package/dist/core/engine.d.ts +21 -0
  21. package/dist/core/engine.js +280 -0
  22. package/dist/index.d.ts +16 -0
  23. package/dist/index.js +9 -0
  24. package/dist/main.d.ts +2 -0
  25. package/dist/main.js +127 -0
  26. package/dist/plugin/api.d.ts +32 -0
  27. package/dist/plugin/api.js +68 -0
  28. package/dist/plugin/installer.d.ts +27 -0
  29. package/dist/plugin/installer.js +181 -0
  30. package/dist/plugin/loader.d.ts +13 -0
  31. package/dist/plugin/loader.js +164 -0
  32. package/dist/plugin/registry.d.ts +18 -0
  33. package/dist/plugin/registry.js +43 -0
  34. package/dist/plugin/types.d.ts +40 -0
  35. package/dist/plugin/types.js +1 -0
  36. package/dist/plugins/actionNetwork/src/index.js +353 -0
  37. package/dist/plugins/activeCampaign/src/index.js +711 -0
  38. package/dist/plugins/adalo/src/index.js +131 -0
  39. package/dist/plugins/affinity/src/index.js +279 -0
  40. package/dist/plugins/agileCrm/src/index.js +415 -0
  41. package/dist/plugins/airtable/src/index.js +280 -0
  42. package/dist/plugins/airtop/src/index.js +527 -0
  43. package/dist/plugins/apiTemplateIo/src/index.js +86 -0
  44. package/dist/plugins/asana/src/index.js +413 -0
  45. package/dist/plugins/autopilot/src/index.js +203 -0
  46. package/dist/plugins/bambooHr/src/index.js +252 -0
  47. package/dist/plugins/bannerbear/src/index.js +100 -0
  48. package/dist/plugins/baserow/src/index.js +180 -0
  49. package/dist/plugins/beeminder/src/index.js +298 -0
  50. package/dist/plugins/bitly/src/index.js +107 -0
  51. package/dist/plugins/bitwarden/src/index.js +383 -0
  52. package/dist/plugins/box/src/index.js +300 -0
  53. package/dist/plugins/brandfetch/src/index.js +80 -0
  54. package/dist/plugins/brevo/src/index.js +305 -0
  55. package/dist/plugins/bubble/src/index.js +181 -0
  56. package/dist/plugins/chargebee/src/index.js +126 -0
  57. package/dist/plugins/circleci/src/index.js +111 -0
  58. package/dist/plugins/ciscoWebex/src/index.js +245 -0
  59. package/dist/plugins/clearbit/src/index.js +103 -0
  60. package/dist/plugins/clickup/src/index.js +1043 -0
  61. package/dist/plugins/clockify/src/index.js +443 -0
  62. package/dist/plugins/cloudflare/src/index.js +93 -0
  63. package/dist/plugins/cockpit/src/index.js +131 -0
  64. package/dist/plugins/coda/src/index.js +327 -0
  65. package/dist/plugins/coingecko/src/index.js +244 -0
  66. package/dist/plugins/contentful/src/index.js +146 -0
  67. package/dist/plugins/convertkit/src/index.js +270 -0
  68. package/dist/plugins/copper/src/index.js +140 -0
  69. package/dist/plugins/cortex/src/index.js +147 -0
  70. package/dist/plugins/currents/src/index.js +405 -0
  71. package/dist/plugins/customerIo/src/index.js +184 -0
  72. package/dist/plugins/databricks/src/index.js +342 -0
  73. package/dist/plugins/deepl/src/index.js +87 -0
  74. package/dist/plugins/demio/src/index.js +111 -0
  75. package/dist/plugins/dhl/src/index.js +40 -0
  76. package/dist/plugins/discord/src/index.js +275 -0
  77. package/dist/plugins/discourse/src/index.js +273 -0
  78. package/dist/plugins/disqus/src/index.js +145 -0
  79. package/dist/plugins/docker/src/index.js +76 -0
  80. package/dist/plugins/drift/src/index.js +89 -0
  81. package/dist/plugins/dropbox/src/index.js +159 -0
  82. package/dist/plugins/dropcontact/src/index.js +59 -0
  83. package/dist/plugins/egoi/src/index.js +151 -0
  84. package/dist/plugins/elasticsearch/src/index.js +157 -0
  85. package/dist/plugins/emelia/src/index.js +174 -0
  86. package/dist/plugins/erpnext/src/index.js +121 -0
  87. package/dist/plugins/facebookGraph/src/index.js +57 -0
  88. package/dist/plugins/freshdesk/src/index.js +320 -0
  89. package/dist/plugins/freshservice/src/index.js +146 -0
  90. package/dist/plugins/freshworksCrm/src/index.js +149 -0
  91. package/dist/plugins/getresponse/src/index.js +140 -0
  92. package/dist/plugins/ghost/src/index.js +192 -0
  93. package/dist/plugins/github/src/index.js +630 -0
  94. package/dist/plugins/gitlab/src/index.js +358 -0
  95. package/dist/plugins/gong/src/index.js +126 -0
  96. package/dist/plugins/gotify/src/index.js +77 -0
  97. package/dist/plugins/gotowebinar/src/index.js +316 -0
  98. package/dist/plugins/grafana/src/index.js +250 -0
  99. package/dist/plugins/graphql/src/index.js +78 -0
  100. package/dist/plugins/grist/src/index.js +106 -0
  101. package/dist/plugins/hackernews/src/index.js +89 -0
  102. package/dist/plugins/halopsa/src/index.js +79 -0
  103. package/dist/plugins/harvest/src/index.js +163 -0
  104. package/dist/plugins/helpscout/src/index.js +176 -0
  105. package/dist/plugins/highlevel/src/index.js +172 -0
  106. package/dist/plugins/homeAssistant/src/index.js +148 -0
  107. package/dist/plugins/hubspot/src/index.js +176 -0
  108. package/dist/plugins/humanticAi/src/index.js +60 -0
  109. package/dist/plugins/hunter/src/index.js +59 -0
  110. package/dist/plugins/intercom/src/index.js +156 -0
  111. package/dist/plugins/iterable/src/index.js +139 -0
  112. package/dist/plugins/jenkins/src/index.js +132 -0
  113. package/dist/plugins/jira/src/index.js +229 -0
  114. package/dist/plugins/keap/src/index.js +502 -0
  115. package/dist/plugins/kobotoolbox/src/index.js +281 -0
  116. package/dist/plugins/lemlist/src/index.js +231 -0
  117. package/dist/plugins/linear/src/index.js +133 -0
  118. package/dist/plugins/lingvanex/src/index.js +31 -0
  119. package/dist/plugins/linkedin/src/index.js +80 -0
  120. package/dist/plugins/lonescale/src/index.js +119 -0
  121. package/dist/plugins/magento/src/index.js +300 -0
  122. package/dist/plugins/mailcheck/src/index.js +27 -0
  123. package/dist/plugins/mailchimp/src/index.js +321 -0
  124. package/dist/plugins/mailerlite/src/index.js +123 -0
  125. package/dist/plugins/mailgun/src/index.js +48 -0
  126. package/dist/plugins/mailjet/src/index.js +155 -0
  127. package/dist/plugins/mandrill/src/index.js +145 -0
  128. package/dist/plugins/marketstack/src/index.js +97 -0
  129. package/dist/plugins/matrix/src/index.js +194 -0
  130. package/dist/plugins/mattermost/src/index.js +331 -0
  131. package/dist/plugins/mautic/src/index.js +311 -0
  132. package/dist/plugins/medium/src/index.js +77 -0
  133. package/dist/plugins/messagebird/src/index.js +57 -0
  134. package/dist/plugins/metabase/src/index.js +130 -0
  135. package/dist/plugins/misp/src/index.js +476 -0
  136. package/dist/plugins/mocean/src/index.js +67 -0
  137. package/dist/plugins/monday/src/index.js +231 -0
  138. package/dist/plugins/monicaCrm/src/index.js +52 -0
  139. package/dist/plugins/msg91/src/index.js +31 -0
  140. package/dist/plugins/nasa/src/index.js +146 -0
  141. package/dist/plugins/netlify/src/index.js +151 -0
  142. package/dist/plugins/netscalerAdc/src/index.js +131 -0
  143. package/dist/plugins/nextcloud/src/index.js +263 -0
  144. package/dist/plugins/nocodb/src/index.js +130 -0
  145. package/dist/plugins/notion/src/index.js +112 -0
  146. package/dist/plugins/npm/src/index.js +104 -0
  147. package/dist/plugins/odoo/src/index.js +157 -0
  148. package/dist/plugins/okta/src/index.js +141 -0
  149. package/dist/plugins/oneSimpleApi/src/index.js +155 -0
  150. package/dist/plugins/onfleet/src/index.js +254 -0
  151. package/dist/plugins/openThesaurus/src/index.js +32 -0
  152. package/dist/plugins/openweathermap/src/index.js +60 -0
  153. package/dist/plugins/oura/src/index.js +62 -0
  154. package/dist/plugins/paddle/src/index.js +247 -0
  155. package/dist/plugins/pagerduty/src/index.js +201 -0
  156. package/dist/plugins/paypal/src/index.js +106 -0
  157. package/dist/plugins/peekalink/src/index.js +35 -0
  158. package/dist/plugins/phantombuster/src/index.js +94 -0
  159. package/dist/plugins/philipsHue/src/index.js +98 -0
  160. package/dist/plugins/pipedrive/src/index.js +169 -0
  161. package/dist/plugins/plivo/src/index.js +66 -0
  162. package/dist/plugins/postbin/src/index.js +93 -0
  163. package/dist/plugins/posthog/src/index.js +113 -0
  164. package/dist/plugins/profitwell/src/index.js +50 -0
  165. package/dist/plugins/pushbullet/src/index.js +102 -0
  166. package/dist/plugins/pushcut/src/index.js +39 -0
  167. package/dist/plugins/pushover/src/index.js +65 -0
  168. package/dist/plugins/quickbase/src/index.js +153 -0
  169. package/dist/plugins/quickbooks/src/index.js +73 -0
  170. package/dist/plugins/quickchart/src/index.js +36 -0
  171. package/dist/plugins/raindrop/src/index.js +209 -0
  172. package/dist/plugins/reddit/src/index.js +185 -0
  173. package/dist/plugins/rocketchat/src/index.js +53 -0
  174. package/dist/plugins/rundeck/src/index.js +62 -0
  175. package/dist/plugins/salesforce/src/index.js +94 -0
  176. package/dist/plugins/salesmate/src/index.js +83 -0
  177. package/dist/plugins/securityScorecard/src/index.js +200 -0
  178. package/dist/plugins/segment/src/index.js +125 -0
  179. package/dist/plugins/sendgrid/src/index.js +187 -0
  180. package/dist/plugins/sendy/src/index.js +138 -0
  181. package/dist/plugins/sentry/src/index.js +233 -0
  182. package/dist/plugins/servicenow/src/index.js +108 -0
  183. package/dist/plugins/shopify/src/index.js +222 -0
  184. package/dist/plugins/signl4/src/index.js +61 -0
  185. package/dist/plugins/slack/src/index.js +236 -0
  186. package/dist/plugins/sms77/src/index.js +63 -0
  187. package/dist/plugins/splunk/src/index.js +207 -0
  188. package/dist/plugins/spotify/src/index.js +188 -0
  189. package/dist/plugins/stackby/src/index.js +82 -0
  190. package/dist/plugins/storyblok/src/index.js +141 -0
  191. package/dist/plugins/strapi/src/index.js +152 -0
  192. package/dist/plugins/strava/src/index.js +137 -0
  193. package/dist/plugins/stripe/src/index.js +222 -0
  194. package/dist/plugins/supabase/src/index.js +121 -0
  195. package/dist/plugins/syncromsp/src/index.js +255 -0
  196. package/dist/plugins/tapfiliate/src/index.js +125 -0
  197. package/dist/plugins/telegram/src/index.js +233 -0
  198. package/dist/plugins/thehive/src/index.js +142 -0
  199. package/dist/plugins/thehiveProject/src/index.js +194 -0
  200. package/dist/plugins/todoist/src/index.js +244 -0
  201. package/dist/plugins/travisci/src/index.js +71 -0
  202. package/dist/plugins/trello/src/index.js +341 -0
  203. package/dist/plugins/twake/src/index.js +40 -0
  204. package/dist/plugins/twilio/src/index.js +75 -0
  205. package/dist/plugins/twist/src/index.js +90 -0
  206. package/dist/plugins/twitter/src/index.js +123 -0
  207. package/dist/plugins/unleashedSoftware/src/index.js +84 -0
  208. package/dist/plugins/uplead/src/index.js +59 -0
  209. package/dist/plugins/uproc/src/index.js +34 -0
  210. package/dist/plugins/uptimerobot/src/index.js +264 -0
  211. package/dist/plugins/urlscanio/src/index.js +64 -0
  212. package/dist/plugins/vero/src/index.js +80 -0
  213. package/dist/plugins/vonage/src/index.js +42 -0
  214. package/dist/plugins/wekan/src/index.js +91 -0
  215. package/dist/plugins/woocommerce/src/index.js +92 -0
  216. package/dist/plugins/wordpress/src/index.js +121 -0
  217. package/dist/plugins/xero/src/index.js +136 -0
  218. package/dist/plugins/yourls/src/index.js +56 -0
  219. package/dist/plugins/zammad/src/index.js +91 -0
  220. package/dist/plugins/zendesk/src/index.js +137 -0
  221. package/dist/plugins/zoho/src/index.js +85 -0
  222. package/dist/plugins/zoom/src/index.js +122 -0
  223. package/dist/plugins/zulip/src/index.js +170 -0
  224. package/dist/sdk.d.ts +38 -0
  225. package/dist/sdk.js +105 -0
  226. package/dist/utils/cli.d.ts +13 -0
  227. package/dist/utils/cli.js +32 -0
  228. package/dist/utils/output.d.ts +4 -0
  229. package/dist/utils/output.js +13 -0
  230. package/package.json +57 -0
@@ -0,0 +1,415 @@
1
+ async function apiRequest(subdomain, email, apiKey, method, endpoint, body, qs) {
2
+ const url = new URL(`https://${subdomain}.agilecrm.com/dev/${endpoint}`);
3
+ if (qs) {
4
+ for (const [k, v] of Object.entries(qs)) {
5
+ if (v !== undefined)
6
+ url.searchParams.set(k, String(v));
7
+ }
8
+ }
9
+ const opts = {
10
+ method,
11
+ headers: {
12
+ Accept: "application/json",
13
+ "Content-Type": "application/json",
14
+ Authorization: `Basic ${btoa(`${email}:${apiKey}`)}`,
15
+ },
16
+ };
17
+ if (body && method !== "GET" && method !== "DELETE") {
18
+ opts.body = JSON.stringify(body);
19
+ }
20
+ const res = await fetch(url.toString(), opts);
21
+ if (!res.ok) {
22
+ const text = await res.text();
23
+ throw new Error(`Agile CRM API error ${res.status}: ${text}`);
24
+ }
25
+ if (res.status === 204 || res.headers.get("content-length") === "0")
26
+ return { success: true };
27
+ return res.json();
28
+ }
29
+ async function paginateAll(subdomain, email, apiKey, method, endpoint, body, qs, limit, sendCursorInBody) {
30
+ const results = [];
31
+ const _body = { ...body };
32
+ const _qs = { ...qs };
33
+ while (true) {
34
+ const data = (await apiRequest(subdomain, email, apiKey, method, endpoint, Object.keys(_body).length > 0 ? _body : undefined, Object.keys(_qs).length > 0 ? _qs : undefined));
35
+ if (!Array.isArray(data) || data.length === 0)
36
+ break;
37
+ results.push(...data);
38
+ if (limit && results.length >= limit)
39
+ return results.slice(0, limit);
40
+ const last = data[data.length - 1];
41
+ if (!last.cursor)
42
+ break;
43
+ if (sendCursorInBody) {
44
+ _body.cursor = last.cursor;
45
+ }
46
+ else {
47
+ _qs.cursor = last.cursor;
48
+ }
49
+ }
50
+ return results;
51
+ }
52
+ function getConn(ctx) {
53
+ return {
54
+ subdomain: ctx.connection.config.subdomain,
55
+ email: ctx.connection.config.email,
56
+ apiKey: ctx.connection.config.apiKey,
57
+ };
58
+ }
59
+ export default function agileCrm(rl) {
60
+ rl.setName("agileCrm");
61
+ rl.setVersion("0.1.0");
62
+ rl.setConnectionSchema({
63
+ subdomain: {
64
+ type: "string",
65
+ required: true,
66
+ description: "Agile CRM subdomain (e.g. 'mycompany' for mycompany.agilecrm.com)",
67
+ env: "AGILE_CRM_SUBDOMAIN",
68
+ },
69
+ email: {
70
+ type: "string",
71
+ required: true,
72
+ description: "Account email address",
73
+ env: "AGILE_CRM_EMAIL",
74
+ },
75
+ apiKey: {
76
+ type: "string",
77
+ required: true,
78
+ description: "Agile CRM REST API key",
79
+ env: "AGILE_CRM_API_KEY",
80
+ },
81
+ });
82
+ // ── Contact ─────────────────────────────────────────
83
+ rl.registerAction("contact.create", {
84
+ description: "Create a new contact",
85
+ inputSchema: {
86
+ firstName: { type: "string", required: false, description: "First name" },
87
+ lastName: { type: "string", required: false, description: "Last name" },
88
+ email: { type: "string", required: false, description: "Email address" },
89
+ company: { type: "string", required: false, description: "Company name" },
90
+ title: { type: "string", required: false, description: "Job title" },
91
+ phone: { type: "string", required: false, description: "Phone number" },
92
+ tags: { type: "array", required: false, description: "Array of tag strings" },
93
+ starValue: { type: "number", required: false, description: "Star rating (0-5)" },
94
+ },
95
+ async execute(input, ctx) {
96
+ const { firstName, lastName, email, company, title, phone, tags, starValue } = input;
97
+ const { subdomain, email: userEmail, apiKey } = getConn(ctx);
98
+ const properties = [];
99
+ if (firstName)
100
+ properties.push({ type: "SYSTEM", name: "first_name", value: firstName });
101
+ if (lastName)
102
+ properties.push({ type: "SYSTEM", name: "last_name", value: lastName });
103
+ if (email)
104
+ properties.push({ type: "SYSTEM", name: "email", value: email });
105
+ if (company)
106
+ properties.push({ type: "SYSTEM", name: "company", value: company });
107
+ if (title)
108
+ properties.push({ type: "SYSTEM", name: "title", value: title });
109
+ if (phone)
110
+ properties.push({ type: "SYSTEM", name: "phone", value: phone });
111
+ const body = { properties };
112
+ if (tags)
113
+ body.tags = tags;
114
+ if (starValue !== undefined)
115
+ body.star_value = starValue;
116
+ return apiRequest(subdomain, userEmail, apiKey, "POST", "api/contacts", body);
117
+ },
118
+ });
119
+ rl.registerAction("contact.get", {
120
+ description: "Get a contact by ID",
121
+ inputSchema: {
122
+ contactId: { type: "string", required: true, description: "Contact ID" },
123
+ },
124
+ async execute(input, ctx) {
125
+ const { contactId } = input;
126
+ const { subdomain, email, apiKey } = getConn(ctx);
127
+ return apiRequest(subdomain, email, apiKey, "GET", `api/contacts/${contactId}`);
128
+ },
129
+ });
130
+ rl.registerAction("contact.list", {
131
+ description: "List/filter contacts",
132
+ inputSchema: {
133
+ limit: { type: "number", required: false, description: "Max results to return" },
134
+ },
135
+ async execute(input, ctx) {
136
+ const { limit } = input ?? {};
137
+ const { subdomain, email, apiKey } = getConn(ctx);
138
+ const body = {
139
+ page_size: limit ?? 100,
140
+ filterJson: JSON.stringify({ contact_type: "PERSON" }),
141
+ };
142
+ return paginateAll(subdomain, email, apiKey, "POST", "api/filters/filter/dynamic-filter", body, undefined, limit, true);
143
+ },
144
+ });
145
+ rl.registerAction("contact.update", {
146
+ description: "Update a contact's properties",
147
+ inputSchema: {
148
+ contactId: { type: "string", required: true, description: "Contact ID" },
149
+ firstName: { type: "string", required: false, description: "First name" },
150
+ lastName: { type: "string", required: false, description: "Last name" },
151
+ email: { type: "string", required: false, description: "Email address" },
152
+ company: { type: "string", required: false, description: "Company name" },
153
+ tags: { type: "array", required: false, description: "Array of tag strings" },
154
+ starValue: { type: "number", required: false, description: "Star rating (0-5)" },
155
+ leadScore: { type: "number", required: false, description: "Lead score" },
156
+ },
157
+ async execute(input, ctx) {
158
+ const { contactId, firstName, lastName, email: contactEmail, company, tags, starValue, leadScore } = input;
159
+ const { subdomain, email, apiKey } = getConn(ctx);
160
+ const baseUri = `https://${subdomain}.agilecrm.com/dev/`;
161
+ const properties = [];
162
+ if (firstName)
163
+ properties.push({ type: "SYSTEM", name: "first_name", value: firstName });
164
+ if (lastName)
165
+ properties.push({ type: "SYSTEM", name: "last_name", value: lastName });
166
+ if (contactEmail)
167
+ properties.push({ type: "SYSTEM", name: "email", value: contactEmail });
168
+ if (company)
169
+ properties.push({ type: "SYSTEM", name: "company", value: company });
170
+ let result;
171
+ const auth = `Basic ${btoa(`${email}:${apiKey}`)}`;
172
+ const headers = { Accept: "application/json", "Content-Type": "application/json", Authorization: auth };
173
+ if (properties.length > 0) {
174
+ const res = await fetch(`${baseUri}api/contacts/edit-properties`, {
175
+ method: "PUT",
176
+ headers,
177
+ body: JSON.stringify({ id: contactId, properties }),
178
+ });
179
+ result = await res.json();
180
+ }
181
+ if (leadScore !== undefined) {
182
+ const res = await fetch(`${baseUri}api/contacts/edit/lead-score`, {
183
+ method: "PUT",
184
+ headers,
185
+ body: JSON.stringify({ id: contactId, lead_score: leadScore }),
186
+ });
187
+ result = await res.json();
188
+ }
189
+ if (tags) {
190
+ const res = await fetch(`${baseUri}api/contacts/edit/tags`, {
191
+ method: "PUT",
192
+ headers,
193
+ body: JSON.stringify({ id: contactId, tags }),
194
+ });
195
+ result = await res.json();
196
+ }
197
+ if (starValue !== undefined) {
198
+ const res = await fetch(`${baseUri}api/contacts/edit/add-star`, {
199
+ method: "PUT",
200
+ headers,
201
+ body: JSON.stringify({ id: contactId, star_value: starValue }),
202
+ });
203
+ result = await res.json();
204
+ }
205
+ return result ?? { success: true };
206
+ },
207
+ });
208
+ rl.registerAction("contact.delete", {
209
+ description: "Delete a contact",
210
+ inputSchema: {
211
+ contactId: { type: "string", required: true, description: "Contact ID" },
212
+ },
213
+ async execute(input, ctx) {
214
+ const { contactId } = input;
215
+ const { subdomain, email, apiKey } = getConn(ctx);
216
+ return apiRequest(subdomain, email, apiKey, "DELETE", `api/contacts/${contactId}`);
217
+ },
218
+ });
219
+ // ── Company ─────────────────────────────────────────
220
+ rl.registerAction("company.create", {
221
+ description: "Create a new company",
222
+ inputSchema: {
223
+ name: { type: "string", required: true, description: "Company name" },
224
+ email: { type: "string", required: false, description: "Company email" },
225
+ phone: { type: "string", required: false, description: "Phone number" },
226
+ tags: { type: "array", required: false, description: "Array of tag strings" },
227
+ },
228
+ async execute(input, ctx) {
229
+ const { name, email: companyEmail, phone, tags } = input;
230
+ const { subdomain, email, apiKey } = getConn(ctx);
231
+ const properties = [];
232
+ if (name)
233
+ properties.push({ type: "SYSTEM", name: "name", value: name });
234
+ if (companyEmail)
235
+ properties.push({ type: "SYSTEM", name: "email", value: companyEmail });
236
+ if (phone)
237
+ properties.push({ type: "SYSTEM", name: "phone", value: phone });
238
+ const body = { type: "COMPANY", properties };
239
+ if (tags)
240
+ body.tags = tags;
241
+ return apiRequest(subdomain, email, apiKey, "POST", "api/contacts", body);
242
+ },
243
+ });
244
+ rl.registerAction("company.get", {
245
+ description: "Get a company by ID",
246
+ inputSchema: {
247
+ companyId: { type: "string", required: true, description: "Company ID" },
248
+ },
249
+ async execute(input, ctx) {
250
+ const { companyId } = input;
251
+ const { subdomain, email, apiKey } = getConn(ctx);
252
+ return apiRequest(subdomain, email, apiKey, "GET", `api/contacts/${companyId}`);
253
+ },
254
+ });
255
+ rl.registerAction("company.list", {
256
+ description: "List/filter companies",
257
+ inputSchema: {
258
+ limit: { type: "number", required: false, description: "Max results to return" },
259
+ },
260
+ async execute(input, ctx) {
261
+ const { limit } = input ?? {};
262
+ const { subdomain, email, apiKey } = getConn(ctx);
263
+ const body = {
264
+ page_size: limit ?? 100,
265
+ filterJson: JSON.stringify({ contact_type: "COMPANY" }),
266
+ };
267
+ return paginateAll(subdomain, email, apiKey, "POST", "api/filters/filter/dynamic-filter", body, undefined, limit, true);
268
+ },
269
+ });
270
+ rl.registerAction("company.update", {
271
+ description: "Update a company's properties",
272
+ inputSchema: {
273
+ companyId: { type: "string", required: true, description: "Company ID" },
274
+ name: { type: "string", required: false, description: "Company name" },
275
+ email: { type: "string", required: false, description: "Company email" },
276
+ phone: { type: "string", required: false, description: "Phone number" },
277
+ tags: { type: "array", required: false, description: "Array of tag strings" },
278
+ starValue: { type: "number", required: false, description: "Star rating (0-5)" },
279
+ },
280
+ async execute(input, ctx) {
281
+ const { companyId, name, email: companyEmail, phone, tags, starValue } = input;
282
+ const { subdomain, email, apiKey } = getConn(ctx);
283
+ const baseUri = `https://${subdomain}.agilecrm.com/dev/`;
284
+ const properties = [];
285
+ if (name)
286
+ properties.push({ type: "SYSTEM", name: "name", value: name });
287
+ if (companyEmail)
288
+ properties.push({ type: "SYSTEM", name: "email", value: companyEmail });
289
+ if (phone)
290
+ properties.push({ type: "SYSTEM", name: "phone", value: phone });
291
+ let result;
292
+ const auth = `Basic ${btoa(`${email}:${apiKey}`)}`;
293
+ const headers = { Accept: "application/json", "Content-Type": "application/json", Authorization: auth };
294
+ if (properties.length > 0) {
295
+ const res = await fetch(`${baseUri}api/contacts/edit-properties`, {
296
+ method: "PUT",
297
+ headers,
298
+ body: JSON.stringify({ id: companyId, properties }),
299
+ });
300
+ result = await res.json();
301
+ }
302
+ if (tags) {
303
+ const res = await fetch(`${baseUri}api/contacts/edit/tags`, {
304
+ method: "PUT",
305
+ headers,
306
+ body: JSON.stringify({ id: companyId, tags }),
307
+ });
308
+ result = await res.json();
309
+ }
310
+ if (starValue !== undefined) {
311
+ const res = await fetch(`${baseUri}api/contacts/edit/add-star`, {
312
+ method: "PUT",
313
+ headers,
314
+ body: JSON.stringify({ id: companyId, star_value: starValue }),
315
+ });
316
+ result = await res.json();
317
+ }
318
+ return result ?? { success: true };
319
+ },
320
+ });
321
+ rl.registerAction("company.delete", {
322
+ description: "Delete a company",
323
+ inputSchema: {
324
+ companyId: { type: "string", required: true, description: "Company ID" },
325
+ },
326
+ async execute(input, ctx) {
327
+ const { companyId } = input;
328
+ const { subdomain, email, apiKey } = getConn(ctx);
329
+ return apiRequest(subdomain, email, apiKey, "DELETE", `api/contacts/${companyId}`);
330
+ },
331
+ });
332
+ // ── Deal ────────────────────────────────────────────
333
+ rl.registerAction("deal.create", {
334
+ description: "Create a new deal",
335
+ inputSchema: {
336
+ name: { type: "string", required: true, description: "Deal name" },
337
+ expectedValue: { type: "number", required: true, description: "Expected value" },
338
+ probability: { type: "number", required: true, description: "Probability (0-100)" },
339
+ milestone: { type: "string", required: true, description: "Milestone/stage name" },
340
+ closeDate: { type: "string", required: true, description: "Close date (ISO string)" },
341
+ contactIds: { type: "array", required: false, description: "Array of contact IDs" },
342
+ },
343
+ async execute(input, ctx) {
344
+ const { name, expectedValue, probability, milestone, closeDate, contactIds } = input;
345
+ const { subdomain, email, apiKey } = getConn(ctx);
346
+ const body = {
347
+ name,
348
+ expected_value: expectedValue,
349
+ probability,
350
+ milestone,
351
+ close_date: new Date(closeDate).getTime(),
352
+ };
353
+ if (contactIds)
354
+ body.contactIds = contactIds;
355
+ return apiRequest(subdomain, email, apiKey, "POST", "api/opportunity", body);
356
+ },
357
+ });
358
+ rl.registerAction("deal.get", {
359
+ description: "Get a deal by ID",
360
+ inputSchema: {
361
+ dealId: { type: "string", required: true, description: "Deal ID" },
362
+ },
363
+ async execute(input, ctx) {
364
+ const { dealId } = input;
365
+ const { subdomain, email, apiKey } = getConn(ctx);
366
+ return apiRequest(subdomain, email, apiKey, "GET", `api/opportunity/${dealId}`);
367
+ },
368
+ });
369
+ rl.registerAction("deal.list", {
370
+ description: "List all deals",
371
+ inputSchema: {
372
+ limit: { type: "number", required: false, description: "Max results to return" },
373
+ },
374
+ async execute(input, ctx) {
375
+ const { limit } = input ?? {};
376
+ const { subdomain, email, apiKey } = getConn(ctx);
377
+ return paginateAll(subdomain, email, apiKey, "GET", "api/opportunity", undefined, { page_size: limit ?? 100 }, limit);
378
+ },
379
+ });
380
+ rl.registerAction("deal.update", {
381
+ description: "Update a deal",
382
+ inputSchema: {
383
+ dealId: { type: "string", required: true, description: "Deal ID" },
384
+ name: { type: "string", required: false, description: "Deal name" },
385
+ expectedValue: { type: "number", required: false, description: "Expected value" },
386
+ probability: { type: "number", required: false, description: "Probability (0-100)" },
387
+ contactIds: { type: "array", required: false, description: "Array of contact IDs" },
388
+ },
389
+ async execute(input, ctx) {
390
+ const { dealId, name, expectedValue, probability, contactIds } = input;
391
+ const { subdomain, email, apiKey } = getConn(ctx);
392
+ const body = { id: dealId };
393
+ if (name)
394
+ body.name = name;
395
+ if (expectedValue !== undefined)
396
+ body.expected_value = expectedValue;
397
+ if (probability !== undefined)
398
+ body.probability = probability;
399
+ if (contactIds)
400
+ body.contactIds = contactIds;
401
+ return apiRequest(subdomain, email, apiKey, "PUT", "api/opportunity/partial-update", body);
402
+ },
403
+ });
404
+ rl.registerAction("deal.delete", {
405
+ description: "Delete a deal",
406
+ inputSchema: {
407
+ dealId: { type: "string", required: true, description: "Deal ID" },
408
+ },
409
+ async execute(input, ctx) {
410
+ const { dealId } = input;
411
+ const { subdomain, email, apiKey } = getConn(ctx);
412
+ return apiRequest(subdomain, email, apiKey, "DELETE", `api/opportunity/${dealId}`);
413
+ },
414
+ });
415
+ }