@elevasis/core 0.15.1 → 0.17.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 (72) hide show
  1. package/dist/index.d.ts +1662 -23
  2. package/dist/index.js +171 -24
  3. package/dist/knowledge/index.d.ts +1340 -0
  4. package/dist/knowledge/index.js +138 -0
  5. package/dist/organization-model/index.d.ts +1662 -23
  6. package/dist/organization-model/index.js +171 -24
  7. package/dist/test-utils/index.d.ts +711 -10
  8. package/dist/test-utils/index.js +159 -16
  9. package/package.json +7 -3
  10. package/src/__tests__/publish.test.ts +14 -13
  11. package/src/__tests__/template-core-compatibility.test.ts +4 -4
  12. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +1265 -1154
  13. package/src/auth/multi-tenancy/index.ts +3 -0
  14. package/src/auth/multi-tenancy/theme-presets.ts +45 -0
  15. package/src/auth/multi-tenancy/types.ts +57 -83
  16. package/src/auth/multi-tenancy/users/api-schemas.ts +165 -194
  17. package/src/business/acquisition/activity-events.ts +1 -1
  18. package/src/business/acquisition/api-schemas.ts +1196 -1177
  19. package/src/business/acquisition/crm-state-actions.test.ts +139 -139
  20. package/src/business/acquisition/types.ts +381 -390
  21. package/src/business/crm/api-schemas.ts +40 -0
  22. package/src/business/crm/index.ts +1 -0
  23. package/src/business/deals/api-schemas.ts +79 -0
  24. package/src/business/deals/index.ts +1 -0
  25. package/src/business/projects/types.ts +124 -88
  26. package/src/execution/core/runner-types.ts +61 -80
  27. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-tools.ts +105 -104
  28. package/src/execution/engine/tools/integration/server/adapters/instantly/instantly-tools.ts +1474 -1473
  29. package/src/execution/engine/tools/integration/server/adapters/millionverifier/millionverifier-tools.ts +103 -102
  30. package/src/execution/engine/tools/integration/server/adapters/signature-api/signature-api-tools.ts +182 -179
  31. package/src/execution/engine/tools/integration/server/adapters/stripe/stripe-tools.ts +310 -309
  32. package/src/execution/engine/tools/integration/tool.ts +255 -253
  33. package/src/execution/engine/tools/lead-service-types.ts +895 -894
  34. package/src/execution/engine/tools/messages.ts +43 -0
  35. package/src/execution/engine/tools/platform/acquisition/types.ts +2 -1
  36. package/src/execution/engine/tools/platform/email/types.ts +97 -96
  37. package/src/execution/engine/tools/types.ts +234 -233
  38. package/src/execution/engine/workflow/types.ts +195 -193
  39. package/src/execution/external/api-schemas.ts +40 -0
  40. package/src/execution/external/index.ts +1 -0
  41. package/src/knowledge/README.md +32 -0
  42. package/src/knowledge/__tests__/queries.test.ts +504 -0
  43. package/src/knowledge/format.ts +99 -0
  44. package/src/knowledge/index.ts +5 -0
  45. package/src/knowledge/published.ts +5 -0
  46. package/src/knowledge/queries.ts +256 -0
  47. package/src/organization-model/__tests__/defaults.test.ts +172 -172
  48. package/src/organization-model/__tests__/foundation.test.ts +7 -7
  49. package/src/organization-model/__tests__/icons.test.ts +27 -0
  50. package/src/organization-model/__tests__/knowledge.test.ts +214 -0
  51. package/src/organization-model/contracts.ts +17 -15
  52. package/src/organization-model/defaults.ts +74 -19
  53. package/src/organization-model/domains/knowledge.ts +53 -0
  54. package/src/organization-model/domains/navigation.ts +416 -399
  55. package/src/organization-model/domains/shared.ts +6 -5
  56. package/src/organization-model/foundation.ts +10 -6
  57. package/src/organization-model/graph/build.ts +209 -182
  58. package/src/organization-model/graph/schema.ts +37 -34
  59. package/src/organization-model/graph/types.ts +47 -31
  60. package/src/organization-model/icons.ts +81 -0
  61. package/src/organization-model/index.ts +8 -3
  62. package/src/organization-model/organization-model.mdx +1 -1
  63. package/src/organization-model/published.ts +103 -86
  64. package/src/organization-model/schema.ts +90 -85
  65. package/src/organization-model/types.ts +40 -33
  66. package/src/platform/index.ts +23 -27
  67. package/src/platform/registry/index.ts +0 -4
  68. package/src/platform/registry/resource-registry.ts +0 -77
  69. package/src/platform/registry/serialized-types.ts +148 -219
  70. package/src/platform/registry/stats-types.ts +60 -60
  71. package/src/reference/_generated/contracts.md +1265 -1154
  72. package/src/platform/registry/__tests__/resource-registry.list-executable.test.ts +0 -393
@@ -1,253 +1,255 @@
1
- import type { z } from 'zod'
2
- import type { Tool, ToolExecutionOptions } from '../types'
3
- import { ToolingError } from '../types'
4
- import { getToolServices } from '../registry'
5
-
6
- /**
7
- * Supported integration types
8
- *
9
- * These represent the available integration adapters that can be used with tools.
10
- * Each integration type corresponds to an adapter implementation.
11
- *
12
- * Note: Concrete adapter implementations are deferred until needed.
13
- * This type provides compile-time safety and auto-completion for tool definitions.
14
- */
15
- export type IntegrationType =
16
- | 'gmail' // Google Gmail API
17
- | 'google-sheets' // Google Sheets API
18
- | 'slack' // Slack API
19
- | 'github' // GitHub API
20
- | 'linear' // Linear API
21
- | 'attio' // Attio CRM API
22
- | 'airtable' // Airtable API
23
- | 'salesforce' // Salesforce API
24
- | 'hubspot' // HubSpot API
25
- | 'stripe' // Stripe API
26
- | 'twilio' // Twilio API
27
- | 'sendgrid' // SendGrid API
28
- | 'mailgun' // Mailgun API
29
- | 'zapier' // Zapier Webhooks
30
- | 'webhook' // Generic webhook
31
- | 'apify' // Apify actor automation
32
- | 'instantly' // Instantly.ai email automation
33
- | 'resend' // Resend transactional email API
34
- | 'signature-api' // SignatureAPI eSignature service
35
- | 'dropbox' // Dropbox file storage API
36
- | 'anymailfinder' // Anymailfinder email finder API
37
- | 'tomba' // Tomba email discovery API
38
- | 'millionverifier' // MillionVerifier email verification API
39
-
40
- /**
41
- * Type-safe method names for each integration
42
- * Provides compile-time validation and IDE auto-completion
43
- */
44
- export type GmailMethod = 'sendEmail' | 'searchEmails' | 'readEmail' | 'createDraft' | 'addLabel'
45
- export type SlackMethod = 'postMessage' | 'listChannels' | 'createChannel' | 'uploadFile' | 'addReaction'
46
- export type GithubMethod = 'createIssue' | 'createPR' | 'addComment' | 'listIssues'
47
- export type LinearMethod = 'createIssue' | 'updateIssue' | 'listIssues'
48
- export type AttioMethod =
49
- | 'createRecord'
50
- | 'updateRecord'
51
- | 'listRecords'
52
- | 'getRecord'
53
- | 'deleteRecord'
54
- | 'createTask'
55
- | 'createNote'
56
- | 'listNotes'
57
- | 'deleteNote'
58
- | 'listObjects'
59
- | 'listAttributes'
60
- | 'createAttribute'
61
- | 'updateAttribute'
62
- export type AirtableMethod = 'listRecords' | 'createRecord' | 'updateRecord' | 'deleteRecord'
63
- export type SalesforceMethod = 'query' | 'create' | 'update' | 'delete'
64
- export type HubspotMethod = 'createContact' | 'updateContact' | 'listContacts'
65
- export type StripeMethod =
66
- | 'createPaymentLink'
67
- | 'getPaymentLink'
68
- | 'updatePaymentLink'
69
- | 'listPaymentLinks'
70
- | 'createCheckoutSession'
71
- | 'createAutoPaymentLink'
72
- export type TwilioMethod = 'sendSMS' | 'sendWhatsApp' | 'makeCall'
73
- export type SendgridMethod = 'sendEmail' | 'addToList'
74
- export type MailgunMethod = 'sendEmail' | 'validateEmail'
75
- export type ZapierMethod = 'trigger'
76
- export type WebhookMethod = 'call'
77
- export type GoogleSheetsMethod =
78
- | 'readSheet'
79
- | 'writeSheet'
80
- | 'appendRows'
81
- | 'clearRange'
82
- | 'getSpreadsheetMetadata'
83
- | 'batchUpdate'
84
- | 'getHeaders'
85
- | 'getLastRow'
86
- | 'getRowByValue'
87
- | 'updateRowByValue'
88
- | 'upsertRow'
89
- | 'filterRows'
90
- | 'deleteRowByValue'
91
- export type ApifyMethod = 'runActor' | 'getDatasetItems' | 'startActor'
92
- export type InstantlyMethod =
93
- | 'sendReply'
94
- | 'updateInterestStatus'
95
- | 'removeFromSubsequence'
96
- | 'deleteLead'
97
- | 'moveLead'
98
- | 'getEmails'
99
- | 'addToCampaign'
100
- | 'listCampaigns'
101
- | 'getCampaign'
102
- | 'updateCampaign'
103
- | 'pauseCampaign'
104
- | 'activateCampaign'
105
- | 'getCampaignAnalytics'
106
- | 'getStepAnalytics'
107
- | 'bulkAddLeads'
108
- | 'getAccountHealth'
109
- | 'createInboxTest'
110
- | 'createCampaign'
111
- | 'getDailyCampaignAnalytics'
112
- | 'listLeads'
113
- | 'bulkDeleteLeads'
114
- | 'deleteCampaign'
115
- export type ResendMethod = 'sendEmail' | 'getEmail'
116
- export type SignatureApiMethod = 'createEnvelope' | 'voidEnvelope' | 'downloadDocument' | 'getEnvelope'
117
- export type DropboxMethod = 'uploadFile' | 'createFolder'
118
- export type AnymailfinderMethod = 'findCompanyEmail' | 'findPersonEmail' | 'findDecisionMakerEmail' | 'verifyEmail'
119
- export type TombaMethod = 'emailFinder' | 'domainSearch' | 'emailVerifier'
120
- export type MillionVerifierMethod = 'verifyEmail' | 'checkCredits'
121
-
122
- /**
123
- * Map integration types to their method types
124
- */
125
- export type IntegrationMethodMap = {
126
- gmail: GmailMethod
127
- 'google-sheets': GoogleSheetsMethod
128
- slack: SlackMethod
129
- github: GithubMethod
130
- linear: LinearMethod
131
- attio: AttioMethod
132
- airtable: AirtableMethod
133
- salesforce: SalesforceMethod
134
- hubspot: HubspotMethod
135
- stripe: StripeMethod
136
- twilio: TwilioMethod
137
- sendgrid: SendgridMethod
138
- mailgun: MailgunMethod
139
- zapier: ZapierMethod
140
- webhook: WebhookMethod
141
- apify: ApifyMethod
142
- instantly: InstantlyMethod
143
- resend: ResendMethod
144
- 'signature-api': SignatureApiMethod
145
- dropbox: DropboxMethod
146
- anymailfinder: AnymailfinderMethod
147
- tomba: TombaMethod
148
- millionverifier: MillionVerifierMethod
149
- }
150
-
151
- /**
152
- * Configuration for creating an integration tool.
153
- * Integration tools call external APIs (Gmail, Slack, etc.) using organization credentials.
154
- *
155
- * @template T - Integration type (e.g., 'gmail', 'slack')
156
- */
157
- export interface IntegrationToolConfig<T extends IntegrationType = IntegrationType> {
158
- /** Unique name for the tool (e.g., 'gmail_sendEmail', 'slack_postMessage') */
159
- name: string
160
- /** Description of what the tool does (shown to LLM) */
161
- description: string
162
- /** Zod schema for validating input */
163
- inputSchema: z.ZodSchema
164
- /** Zod schema for validating output */
165
- outputSchema: z.ZodSchema
166
- /** Integration adapter type (e.g., 'gmail', 'slack') */
167
- integration: T
168
- /** Method to call on the integration adapter (type-safe based on integration) */
169
- method: T extends keyof IntegrationMethodMap ? IntegrationMethodMap[T] : string
170
- /** Credential name to use from credentials table (e.g., 'support-gmail', 'sales-gmail') */
171
- credentialName: string
172
- /** Optional callback executed after successful tool execution (e.g., cache updates) - receives full options including iterationContext for memory management */
173
- onSuccess?: (result: unknown, options: ToolExecutionOptions) => void | Promise<void>
174
- }
175
-
176
- /**
177
- * Create an integration tool that calls external APIs using organization credentials
178
- *
179
- * Integration tools enable agents to interact with external services (Gmail, Slack, etc.)
180
- * using encrypted credentials stored in the credentials table. Each tool
181
- * specifies which credential name to use, allowing multiple credentials per integration type.
182
- *
183
- * @param config - Configuration for the integration tool
184
- * @returns Tool that calls the integration adapter with credentials
185
- *
186
- * @example
187
- * // Create tool for sending email via support Gmail account
188
- * const sendSupportEmail = createIntegrationTool({
189
- * name: 'send_support_email',
190
- * description: 'Send email from support@company.com',
191
- * inputSchema: z.object({
192
- * to: z.string().email(),
193
- * subject: z.string(),
194
- * body: z.string()
195
- * }),
196
- * outputSchema: z.object({ messageId: z.string() }),
197
- * integration: 'gmail',
198
- * method: 'sendEmail',
199
- * credentialName: 'support-gmail'
200
- * })
201
- *
202
- * @example
203
- * // Create tool for sending email via sales Gmail account
204
- * const sendSalesEmail = createIntegrationTool({
205
- * name: 'send_sales_email',
206
- * description: 'Send email from sales@company.com',
207
- * inputSchema: z.object({
208
- * to: z.string().email(),
209
- * subject: z.string(),
210
- * body: z.string()
211
- * }),
212
- * outputSchema: z.object({ messageId: z.string() }),
213
- * integration: 'gmail',
214
- * method: 'sendEmail',
215
- * credentialName: 'sales-gmail' // Different credential, same integration
216
- * })
217
- */
218
- export function createIntegrationTool(config: IntegrationToolConfig): Tool {
219
- return {
220
- name: config.name,
221
- description: config.description,
222
- inputSchema: config.inputSchema,
223
- outputSchema: config.outputSchema,
224
-
225
- async execute(options: ToolExecutionOptions): Promise<unknown> {
226
- // Get integration service from global registry
227
- const { integrationService } = getToolServices()
228
- if (!integrationService) {
229
- throw new ToolingError(
230
- 'service_unavailable',
231
- 'IntegrationService not initialized. Ensure toolServicesRegistry.initialize() was called in apps/api/src/main.ts',
232
- { integration: config.integration, method: config.method }
233
- )
234
- }
235
-
236
- // Call integration service
237
- const result = await integrationService.call(
238
- config.integration,
239
- config.method,
240
- options.input,
241
- config.credentialName,
242
- options.executionContext
243
- )
244
-
245
- // Execute onSuccess hook if provided (e.g., for cache updates)
246
- if (config.onSuccess) {
247
- await config.onSuccess(result, options)
248
- }
249
-
250
- return result
251
- }
252
- }
253
- }
1
+ import type { z } from 'zod'
2
+ import type { Tool, ToolExecutionOptions } from '../types'
3
+ import { ToolingError } from '../types'
4
+ import { getToolServices } from '../registry'
5
+
6
+ /**
7
+ * Supported integration types
8
+ *
9
+ * These represent the available integration adapters that can be used with tools.
10
+ * Each integration type corresponds to an adapter implementation.
11
+ *
12
+ * Note: Concrete adapter implementations are deferred until needed.
13
+ * This type provides compile-time safety and auto-completion for tool definitions.
14
+ */
15
+ export type IntegrationType =
16
+ | 'gmail' // Google Gmail API
17
+ | 'google-sheets' // Google Sheets API
18
+ | 'slack' // Slack API
19
+ | 'github' // GitHub API
20
+ | 'linear' // Linear API
21
+ | 'attio' // Attio CRM API
22
+ | 'airtable' // Airtable API
23
+ | 'salesforce' // Salesforce API
24
+ | 'hubspot' // HubSpot API
25
+ | 'stripe' // Stripe API
26
+ | 'twilio' // Twilio API
27
+ | 'sendgrid' // SendGrid API
28
+ | 'mailgun' // Mailgun API
29
+ | 'zapier' // Zapier Webhooks
30
+ | 'webhook' // Generic webhook
31
+ | 'apify' // Apify actor automation
32
+ | 'instantly' // Instantly.ai email automation
33
+ | 'resend' // Resend transactional email API
34
+ | 'signature-api' // SignatureAPI eSignature service
35
+ | 'dropbox' // Dropbox file storage API
36
+ | 'anymailfinder' // Anymailfinder email finder API
37
+ | 'tomba' // Tomba email discovery API
38
+ | 'millionverifier' // MillionVerifier email verification API
39
+
40
+ /**
41
+ * Type-safe method names for each integration
42
+ * Provides compile-time validation and IDE auto-completion
43
+ */
44
+ export type GmailMethod = 'sendEmail' | 'searchEmails' | 'readEmail' | 'createDraft' | 'addLabel'
45
+ export type SlackMethod = 'postMessage' | 'listChannels' | 'createChannel' | 'uploadFile' | 'addReaction'
46
+ export type GithubMethod = 'createIssue' | 'createPR' | 'addComment' | 'listIssues'
47
+ export type LinearMethod = 'createIssue' | 'updateIssue' | 'listIssues'
48
+ export type AttioMethod =
49
+ | 'createRecord'
50
+ | 'updateRecord'
51
+ | 'listRecords'
52
+ | 'getRecord'
53
+ | 'deleteRecord'
54
+ | 'createTask'
55
+ | 'createNote'
56
+ | 'listNotes'
57
+ | 'deleteNote'
58
+ | 'listObjects'
59
+ | 'listAttributes'
60
+ | 'createAttribute'
61
+ | 'updateAttribute'
62
+ export type AirtableMethod = 'listRecords' | 'createRecord' | 'updateRecord' | 'deleteRecord'
63
+ export type SalesforceMethod = 'query' | 'create' | 'update' | 'delete'
64
+ export type HubspotMethod = 'createContact' | 'updateContact' | 'listContacts'
65
+ export type StripeMethod =
66
+ | 'createPaymentLink'
67
+ | 'getPaymentLink'
68
+ | 'updatePaymentLink'
69
+ | 'listPaymentLinks'
70
+ | 'createCheckoutSession'
71
+ | 'createAutoPaymentLink'
72
+ export type TwilioMethod = 'sendSMS' | 'sendWhatsApp' | 'makeCall'
73
+ export type SendgridMethod = 'sendEmail' | 'addToList'
74
+ export type MailgunMethod = 'sendEmail' | 'validateEmail'
75
+ export type ZapierMethod = 'trigger'
76
+ export type WebhookMethod = 'call'
77
+ export type GoogleSheetsMethod =
78
+ | 'readSheet'
79
+ | 'writeSheet'
80
+ | 'appendRows'
81
+ | 'clearRange'
82
+ | 'getSpreadsheetMetadata'
83
+ | 'batchUpdate'
84
+ | 'getHeaders'
85
+ | 'getLastRow'
86
+ | 'getRowByValue'
87
+ | 'updateRowByValue'
88
+ | 'upsertRow'
89
+ | 'filterRows'
90
+ | 'deleteRowByValue'
91
+ export type ApifyMethod = 'runActor' | 'getDatasetItems' | 'startActor'
92
+ export type InstantlyMethod =
93
+ | 'sendReply'
94
+ | 'updateInterestStatus'
95
+ | 'removeFromSubsequence'
96
+ | 'deleteLead'
97
+ | 'moveLead'
98
+ | 'getEmails'
99
+ | 'addToCampaign'
100
+ | 'listCampaigns'
101
+ | 'getCampaign'
102
+ | 'updateCampaign'
103
+ | 'pauseCampaign'
104
+ | 'activateCampaign'
105
+ | 'getCampaignAnalytics'
106
+ | 'getStepAnalytics'
107
+ | 'bulkAddLeads'
108
+ | 'getAccountHealth'
109
+ | 'createInboxTest'
110
+ | 'createCampaign'
111
+ | 'getDailyCampaignAnalytics'
112
+ | 'listLeads'
113
+ | 'bulkDeleteLeads'
114
+ | 'deleteCampaign'
115
+ export type ResendMethod = 'sendEmail' | 'getEmail'
116
+ export type SignatureApiMethod = 'createEnvelope' | 'voidEnvelope' | 'downloadDocument' | 'getEnvelope'
117
+ export type DropboxMethod = 'uploadFile' | 'createFolder'
118
+ export type AnymailfinderMethod = 'findCompanyEmail' | 'findPersonEmail' | 'findDecisionMakerEmail' | 'verifyEmail'
119
+ export type TombaMethod = 'emailFinder' | 'domainSearch' | 'emailVerifier'
120
+ export type MillionVerifierMethod = 'verifyEmail' | 'checkCredits'
121
+
122
+ /**
123
+ * Map integration types to their method types
124
+ */
125
+ export type IntegrationMethodMap = {
126
+ gmail: GmailMethod
127
+ 'google-sheets': GoogleSheetsMethod
128
+ slack: SlackMethod
129
+ github: GithubMethod
130
+ linear: LinearMethod
131
+ attio: AttioMethod
132
+ airtable: AirtableMethod
133
+ salesforce: SalesforceMethod
134
+ hubspot: HubspotMethod
135
+ stripe: StripeMethod
136
+ twilio: TwilioMethod
137
+ sendgrid: SendgridMethod
138
+ mailgun: MailgunMethod
139
+ zapier: ZapierMethod
140
+ webhook: WebhookMethod
141
+ apify: ApifyMethod
142
+ instantly: InstantlyMethod
143
+ resend: ResendMethod
144
+ 'signature-api': SignatureApiMethod
145
+ dropbox: DropboxMethod
146
+ anymailfinder: AnymailfinderMethod
147
+ tomba: TombaMethod
148
+ millionverifier: MillionVerifierMethod
149
+ }
150
+
151
+ /**
152
+ * Configuration for creating an integration tool.
153
+ * Integration tools call external APIs (Gmail, Slack, etc.) using organization credentials.
154
+ *
155
+ * @template T - Integration type (e.g., 'gmail', 'slack')
156
+ */
157
+ export interface IntegrationToolConfig<T extends IntegrationType = IntegrationType> {
158
+ /** Unique name for the tool (e.g., 'gmail_sendEmail', 'slack_postMessage') */
159
+ name: string
160
+ /** Description of what the tool does (shown to LLM) */
161
+ description: string
162
+ /** Zod schema for validating input */
163
+ inputSchema: z.ZodSchema
164
+ /** Zod schema for validating output */
165
+ outputSchema: z.ZodSchema
166
+ /** Integration adapter type (e.g., 'gmail', 'slack') */
167
+ integration: T
168
+ /** Method to call on the integration adapter (type-safe based on integration) */
169
+ method: T extends keyof IntegrationMethodMap ? IntegrationMethodMap[T] : string
170
+ /** Credential name to use from credentials table (e.g., 'support-gmail', 'sales-gmail') */
171
+ credentialName: string
172
+ /** Optional callback executed after successful tool execution (e.g., cache updates) - receives full options including iterationContext for memory management */
173
+ onSuccess?: (result: unknown, options: ToolExecutionOptions) => void | Promise<void>
174
+ }
175
+
176
+ /**
177
+ * Create an integration tool that calls external APIs using organization credentials
178
+ *
179
+ * Integration tools enable agents to interact with external services (Gmail, Slack, etc.)
180
+ * using encrypted credentials stored in the credentials table. Each tool
181
+ * specifies which credential name to use, allowing multiple credentials per integration type.
182
+ *
183
+ * @param config - Configuration for the integration tool
184
+ * @returns Tool that calls the integration adapter with credentials
185
+ *
186
+ * @example
187
+ * // Create tool for sending email via support Gmail account
188
+ * import { EmailSchema } from '@repo/core'
189
+ * const sendSupportEmail = createIntegrationTool({
190
+ * name: 'send_support_email',
191
+ * description: 'Send email from support@company.com',
192
+ * inputSchema: z.object({
193
+ * to: EmailSchema,
194
+ * subject: z.string(),
195
+ * body: z.string()
196
+ * }),
197
+ * outputSchema: z.object({ messageId: z.string() }),
198
+ * integration: 'gmail',
199
+ * method: 'sendEmail',
200
+ * credentialName: 'support-gmail'
201
+ * })
202
+ *
203
+ * @example
204
+ * // Create tool for sending email via sales Gmail account
205
+ * import { EmailSchema } from '@repo/core'
206
+ * const sendSalesEmail = createIntegrationTool({
207
+ * name: 'send_sales_email',
208
+ * description: 'Send email from sales@company.com',
209
+ * inputSchema: z.object({
210
+ * to: EmailSchema,
211
+ * subject: z.string(),
212
+ * body: z.string()
213
+ * }),
214
+ * outputSchema: z.object({ messageId: z.string() }),
215
+ * integration: 'gmail',
216
+ * method: 'sendEmail',
217
+ * credentialName: 'sales-gmail' // Different credential, same integration
218
+ * })
219
+ */
220
+ export function createIntegrationTool(config: IntegrationToolConfig): Tool {
221
+ return {
222
+ name: config.name,
223
+ description: config.description,
224
+ inputSchema: config.inputSchema,
225
+ outputSchema: config.outputSchema,
226
+
227
+ async execute(options: ToolExecutionOptions): Promise<unknown> {
228
+ // Get integration service from global registry
229
+ const { integrationService } = getToolServices()
230
+ if (!integrationService) {
231
+ throw new ToolingError(
232
+ 'service_unavailable',
233
+ 'IntegrationService not initialized. Ensure toolServicesRegistry.initialize() was called in apps/api/src/main.ts',
234
+ { integration: config.integration, method: config.method }
235
+ )
236
+ }
237
+
238
+ // Call integration service
239
+ const result = await integrationService.call(
240
+ config.integration,
241
+ config.method,
242
+ options.input,
243
+ config.credentialName,
244
+ options.executionContext
245
+ )
246
+
247
+ // Execute onSuccess hook if provided (e.g., for cache updates)
248
+ if (config.onSuccess) {
249
+ await config.onSuccess(result, options)
250
+ }
251
+
252
+ return result
253
+ }
254
+ }
255
+ }