@elevasis/core 0.15.0 → 0.16.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 (88) hide show
  1. package/dist/index.d.ts +1718 -19
  2. package/dist/index.js +369 -25
  3. package/dist/organization-model/index.d.ts +1718 -19
  4. package/dist/organization-model/index.js +369 -25
  5. package/dist/test-utils/index.d.ts +1108 -371
  6. package/dist/test-utils/index.js +357 -17
  7. package/package.json +5 -1
  8. package/src/__tests__/publish.test.ts +14 -13
  9. package/src/__tests__/template-core-compatibility.test.ts +4 -4
  10. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +1109 -882
  11. package/src/auth/multi-tenancy/index.ts +3 -0
  12. package/src/auth/multi-tenancy/theme-presets.ts +45 -0
  13. package/src/auth/multi-tenancy/types.ts +57 -83
  14. package/src/auth/multi-tenancy/users/api-schemas.ts +165 -194
  15. package/src/business/acquisition/activity-events.ts +13 -4
  16. package/src/business/acquisition/api-schemas.test.ts +315 -4
  17. package/src/business/acquisition/api-schemas.ts +122 -8
  18. package/src/business/acquisition/build-templates.ts +44 -0
  19. package/src/business/acquisition/crm-next-action.test.ts +262 -0
  20. package/src/business/acquisition/crm-next-action.ts +220 -0
  21. package/src/business/acquisition/crm-priority.test.ts +216 -0
  22. package/src/business/acquisition/crm-priority.ts +349 -0
  23. package/src/business/acquisition/crm-state-actions.test.ts +151 -160
  24. package/src/business/acquisition/deal-ownership.test.ts +351 -0
  25. package/src/business/acquisition/deal-ownership.ts +120 -0
  26. package/src/business/acquisition/derive-actions.test.ts +101 -37
  27. package/src/business/acquisition/derive-actions.ts +102 -87
  28. package/src/business/acquisition/index.ts +10 -0
  29. package/src/business/acquisition/types.ts +400 -366
  30. package/src/business/crm/api-schemas.ts +40 -0
  31. package/src/business/crm/index.ts +1 -0
  32. package/src/business/deals/api-schemas.ts +79 -0
  33. package/src/business/deals/index.ts +1 -0
  34. package/src/business/projects/types.ts +124 -88
  35. package/src/execution/core/runner-types.ts +61 -80
  36. package/src/execution/engine/index.ts +4 -3
  37. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-tools.ts +105 -104
  38. package/src/execution/engine/tools/integration/server/adapters/instantly/instantly-tools.ts +1474 -1473
  39. package/src/execution/engine/tools/integration/server/adapters/millionverifier/millionverifier-tools.ts +103 -102
  40. package/src/execution/engine/tools/integration/server/adapters/signature-api/signature-api-tools.ts +182 -179
  41. package/src/execution/engine/tools/integration/server/adapters/stripe/stripe-tools.ts +310 -309
  42. package/src/execution/engine/tools/integration/tool.ts +255 -253
  43. package/src/execution/engine/tools/lead-service-types.ts +939 -924
  44. package/src/execution/engine/tools/messages.ts +43 -0
  45. package/src/execution/engine/tools/platform/acquisition/list-tools.ts +6 -5
  46. package/src/execution/engine/tools/platform/acquisition/types.ts +5 -2
  47. package/src/execution/engine/tools/platform/email/types.ts +97 -96
  48. package/src/execution/engine/tools/registry.ts +4 -3
  49. package/src/execution/engine/tools/tool-maps.ts +3 -1
  50. package/src/execution/engine/tools/types.ts +234 -233
  51. package/src/execution/engine/workflow/types.ts +195 -193
  52. package/src/execution/external/api-schemas.ts +40 -0
  53. package/src/execution/external/index.ts +1 -0
  54. package/src/knowledge/README.md +32 -0
  55. package/src/knowledge/__tests__/queries.test.ts +504 -0
  56. package/src/knowledge/format.ts +99 -0
  57. package/src/knowledge/index.ts +5 -0
  58. package/src/knowledge/queries.ts +256 -0
  59. package/src/organization-model/__tests__/defaults.test.ts +172 -172
  60. package/src/organization-model/__tests__/foundation.test.ts +7 -7
  61. package/src/organization-model/__tests__/icons.test.ts +27 -0
  62. package/src/organization-model/__tests__/knowledge.test.ts +214 -0
  63. package/src/organization-model/contracts.ts +17 -15
  64. package/src/organization-model/defaults.ts +74 -19
  65. package/src/organization-model/domains/knowledge.ts +53 -0
  66. package/src/organization-model/domains/navigation.ts +416 -399
  67. package/src/organization-model/domains/prospecting.ts +204 -1
  68. package/src/organization-model/domains/sales.test.ts +29 -0
  69. package/src/organization-model/domains/sales.ts +102 -0
  70. package/src/organization-model/domains/shared.ts +6 -5
  71. package/src/organization-model/foundation.ts +10 -6
  72. package/src/organization-model/graph/build.ts +209 -182
  73. package/src/organization-model/graph/schema.ts +37 -34
  74. package/src/organization-model/graph/types.ts +47 -31
  75. package/src/organization-model/icons.ts +81 -0
  76. package/src/organization-model/index.ts +8 -3
  77. package/src/organization-model/organization-model.mdx +1 -1
  78. package/src/organization-model/published.ts +103 -86
  79. package/src/organization-model/schema.ts +90 -85
  80. package/src/organization-model/types.ts +42 -35
  81. package/src/platform/constants/versions.ts +1 -1
  82. package/src/platform/index.ts +23 -27
  83. package/src/platform/registry/index.ts +0 -4
  84. package/src/platform/registry/resource-registry.ts +0 -77
  85. package/src/platform/registry/serialized-types.ts +148 -219
  86. package/src/platform/registry/stats-types.ts +60 -60
  87. package/src/reference/_generated/contracts.md +829 -595
  88. package/src/supabase/database.types.ts +2978 -2958
@@ -1,102 +1,103 @@
1
- import { z } from 'zod'
2
- import type { Tool } from '../../../../types'
3
- import { createIntegrationTool } from '../../../tool'
4
-
5
- /**
6
- * Create a tool that verifies email addresses via MillionVerifier
7
- *
8
- * @param credentialName - Name of the MillionVerifier credential to use
9
- * @returns Tool instance
10
- *
11
- * @example
12
- * ```typescript
13
- * const tool = createMillionVerifierVerifyEmailTool('elevasis-millionverifier')
14
- * const result = await tool.execute({
15
- * email: 'john@example.com'
16
- * }, context)
17
- * // result.result: 'ok' | 'catch_all' | 'unknown' | 'error' | 'disposable' | 'invalid'
18
- * // result.quality: 'good' | 'bad' | 'risky' | ''
19
- * ```
20
- */
21
- export function createMillionVerifierVerifyEmailTool(credentialName: string): Tool {
22
- return createIntegrationTool({
23
- name: 'millionverifier_verify_email',
24
- description: `Verify email address deliverability using MillionVerifier.
25
-
26
- Use this tool to validate if an email address is real and can receive emails before
27
- adding it to a campaign. MillionVerifier is highly accurate and fast (160 req/s).
28
-
29
- Result codes:
30
- - ok (1): Email is valid and deliverable
31
- - catch_all (2): Domain accepts all email (cannot confirm individual mailbox) - FREE
32
- - unknown (3): Result could not be determined - FREE
33
- - error (4): Verification error
34
- - disposable (5): Disposable/temporary email address
35
- - invalid (6): Email address is invalid
36
-
37
- Quality signals:
38
- - good: Safe to send
39
- - risky: May bounce or flag spam filter
40
- - bad: Do not send
41
-
42
- Credits are only deducted for ok, invalid, and disposable results.
43
-
44
- Returns full verification details including free/role detection and suggested correction.`,
45
- inputSchema: z.object({
46
- email: z.string().email().describe('Email address to verify')
47
- }),
48
- outputSchema: z.object({
49
- email: z.string().describe('Verified email address'),
50
- quality: z.enum(['', 'good', 'bad', 'risky']).describe('Quality signal for sending decision'),
51
- result: z.enum(['ok', 'catch_all', 'unknown', 'error', 'disposable', 'invalid']).describe('Verification result'),
52
- resultCode: z
53
- .number()
54
- .describe('Numeric result code (1=ok, 2=catch_all, 3=unknown, 4=error, 5=disposable, 6=invalid)'),
55
- subresult: z.string().describe('Detailed sub-result (e.g., ok, no_mailbox, dns_no_mx)'),
56
- free: z.boolean().describe('Whether this is a free email provider (Gmail, Yahoo, etc.)'),
57
- role: z.boolean().describe('Whether this is a role-based address (info@, support@, etc.)'),
58
- didYouMean: z.string().describe('Suggested correction if email looks like a typo (empty if none)'),
59
- credits: z.number().describe('Remaining credits after this verification'),
60
- executionTime: z.number().describe('Time taken to verify in milliseconds'),
61
- error: z.string().describe('Error message when result is error (empty otherwise)'),
62
- liveMode: z.boolean().describe('Whether the verification was performed in live mode')
63
- }),
64
- integration: 'millionverifier' as const,
65
- method: 'verifyEmail' as const,
66
- credentialName
67
- })
68
- }
69
-
70
- /**
71
- * Create a tool that checks remaining MillionVerifier credits
72
- *
73
- * @param credentialName - Name of the MillionVerifier credential to use
74
- * @returns Tool instance
75
- *
76
- * @example
77
- * ```typescript
78
- * const tool = createMillionVerifierCheckCreditsTool('elevasis-millionverifier')
79
- * const result = await tool.execute({}, context)
80
- * // result.credits: 5000
81
- * ```
82
- */
83
- export function createMillionVerifierCheckCreditsTool(credentialName: string): Tool {
84
- return createIntegrationTool({
85
- name: 'millionverifier_check_credits',
86
- description: `Check remaining MillionVerifier verification credits.
87
-
88
- Use this tool to monitor credit balance before running large verification batches.
89
-
90
- Returns current credits, bulk credits, renewing credits, and plan tier.`,
91
- inputSchema: z.object({}),
92
- outputSchema: z.object({
93
- credits: z.number().describe('Remaining single-verification credits'),
94
- bulkCredits: z.number().describe('Remaining bulk verification credits'),
95
- renewingCredits: z.number().describe('Credits that will renew on next billing cycle'),
96
- plan: z.number().describe('Current plan tier')
97
- }),
98
- integration: 'millionverifier' as const,
99
- method: 'checkCredits' as const,
100
- credentialName
101
- })
102
- }
1
+ import { z } from 'zod'
2
+ import type { Tool } from '../../../../types'
3
+ import { createIntegrationTool } from '../../../tool'
4
+ import { EmailSchema } from '../../../../../../../platform/utils/validation'
5
+
6
+ /**
7
+ * Create a tool that verifies email addresses via MillionVerifier
8
+ *
9
+ * @param credentialName - Name of the MillionVerifier credential to use
10
+ * @returns Tool instance
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const tool = createMillionVerifierVerifyEmailTool('elevasis-millionverifier')
15
+ * const result = await tool.execute({
16
+ * email: 'john@example.com'
17
+ * }, context)
18
+ * // result.result: 'ok' | 'catch_all' | 'unknown' | 'error' | 'disposable' | 'invalid'
19
+ * // result.quality: 'good' | 'bad' | 'risky' | ''
20
+ * ```
21
+ */
22
+ export function createMillionVerifierVerifyEmailTool(credentialName: string): Tool {
23
+ return createIntegrationTool({
24
+ name: 'millionverifier_verify_email',
25
+ description: `Verify email address deliverability using MillionVerifier.
26
+
27
+ Use this tool to validate if an email address is real and can receive emails before
28
+ adding it to a campaign. MillionVerifier is highly accurate and fast (160 req/s).
29
+
30
+ Result codes:
31
+ - ok (1): Email is valid and deliverable
32
+ - catch_all (2): Domain accepts all email (cannot confirm individual mailbox) - FREE
33
+ - unknown (3): Result could not be determined - FREE
34
+ - error (4): Verification error
35
+ - disposable (5): Disposable/temporary email address
36
+ - invalid (6): Email address is invalid
37
+
38
+ Quality signals:
39
+ - good: Safe to send
40
+ - risky: May bounce or flag spam filter
41
+ - bad: Do not send
42
+
43
+ Credits are only deducted for ok, invalid, and disposable results.
44
+
45
+ Returns full verification details including free/role detection and suggested correction.`,
46
+ inputSchema: z.object({
47
+ email: EmailSchema.describe('Email address to verify')
48
+ }),
49
+ outputSchema: z.object({
50
+ email: z.string().describe('Verified email address'),
51
+ quality: z.enum(['', 'good', 'bad', 'risky']).describe('Quality signal for sending decision'),
52
+ result: z.enum(['ok', 'catch_all', 'unknown', 'error', 'disposable', 'invalid']).describe('Verification result'),
53
+ resultCode: z
54
+ .number()
55
+ .describe('Numeric result code (1=ok, 2=catch_all, 3=unknown, 4=error, 5=disposable, 6=invalid)'),
56
+ subresult: z.string().describe('Detailed sub-result (e.g., ok, no_mailbox, dns_no_mx)'),
57
+ free: z.boolean().describe('Whether this is a free email provider (Gmail, Yahoo, etc.)'),
58
+ role: z.boolean().describe('Whether this is a role-based address (info@, support@, etc.)'),
59
+ didYouMean: z.string().describe('Suggested correction if email looks like a typo (empty if none)'),
60
+ credits: z.number().describe('Remaining credits after this verification'),
61
+ executionTime: z.number().describe('Time taken to verify in milliseconds'),
62
+ error: z.string().describe('Error message when result is error (empty otherwise)'),
63
+ liveMode: z.boolean().describe('Whether the verification was performed in live mode')
64
+ }),
65
+ integration: 'millionverifier' as const,
66
+ method: 'verifyEmail' as const,
67
+ credentialName
68
+ })
69
+ }
70
+
71
+ /**
72
+ * Create a tool that checks remaining MillionVerifier credits
73
+ *
74
+ * @param credentialName - Name of the MillionVerifier credential to use
75
+ * @returns Tool instance
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const tool = createMillionVerifierCheckCreditsTool('elevasis-millionverifier')
80
+ * const result = await tool.execute({}, context)
81
+ * // result.credits: 5000
82
+ * ```
83
+ */
84
+ export function createMillionVerifierCheckCreditsTool(credentialName: string): Tool {
85
+ return createIntegrationTool({
86
+ name: 'millionverifier_check_credits',
87
+ description: `Check remaining MillionVerifier verification credits.
88
+
89
+ Use this tool to monitor credit balance before running large verification batches.
90
+
91
+ Returns current credits, bulk credits, renewing credits, and plan tier.`,
92
+ inputSchema: z.object({}),
93
+ outputSchema: z.object({
94
+ credits: z.number().describe('Remaining single-verification credits'),
95
+ bulkCredits: z.number().describe('Remaining bulk verification credits'),
96
+ renewingCredits: z.number().describe('Credits that will renew on next billing cycle'),
97
+ plan: z.number().describe('Current plan tier')
98
+ }),
99
+ integration: 'millionverifier' as const,
100
+ method: 'checkCredits' as const,
101
+ credentialName
102
+ })
103
+ }
@@ -1,179 +1,182 @@
1
- import { z } from 'zod'
2
- import type { Tool } from '../../../../types'
3
- import { createIntegrationTool } from '../../../tool'
4
-
5
- /**
6
- * Create a tool that creates SignatureAPI envelopes for electronic signatures
7
- *
8
- * @param credentialName - Name of the SignatureAPI credential to use
9
- * @returns Tool instance
10
- *
11
- * @example
12
- * ```typescript
13
- * const tool = createSignatureApiCreateEnvelopeTool('signatureapi-prod')
14
- * const result = await tool.execute({
15
- * input: {
16
- * title: 'Elevasis Proposal - Acme Corp',
17
- * documents: [{ name: 'proposal.pdf', url: 'https://...', places: [...] }],
18
- * recipients: [{ key: 'signer1', type: 'signer', name: 'John', email: 'john@acme.com' }]
19
- * },
20
- * executionContext: context
21
- * })
22
- * // result: { id: 'env_xxx', status: 'processing', signingUrl: 'https://...' }
23
- * ```
24
- */
25
- export function createSignatureApiCreateEnvelopeTool(credentialName: string): Tool {
26
- return createIntegrationTool({
27
- name: 'signatureapi_create_envelope',
28
- description: `Create a SignatureAPI envelope for electronic signatures.
29
-
30
- Use this tool to send documents for signing. An envelope is a container
31
- that holds documents and manages the signing process.
32
-
33
- Examples:
34
- - Create proposal envelope: title, documents with PDF URLs, recipients with signers
35
- - Include signature fields: specify page, x, y positions for signature placement
36
- - Use 'date' for auto-populated signing date (maps to recipient_completed_date)
37
-
38
- The envelope will be sent to recipients via email with a signing link.`,
39
- inputSchema: z.object({
40
- title: z.string().describe('Envelope title (shown in emails)'),
41
- message: z.string().optional().describe('Custom message for recipient emails'),
42
- documents: z
43
- .array(
44
- z.object({
45
- name: z.string().describe('Document filename'),
46
- url: z.string().url().describe('Publicly accessible URL to PDF document'),
47
- places: z
48
- .array(
49
- z.object({
50
- recipientKey: z.string().describe('Links to recipient key'),
51
- type: z.enum(['signature', 'date', 'text', 'initials']).describe('Field type (date maps to recipient_completed_date)'),
52
- page: z.number().describe('Page number (1-indexed, -1 for last)'),
53
- x: z.number().describe('X position in points'),
54
- y: z.number().describe('Y position in points'),
55
- width: z.number().optional(),
56
- height: z.number().optional()
57
- })
58
- )
59
- .optional()
60
- .describe('Signature field placements')
61
- })
62
- )
63
- .describe('Documents to sign'),
64
- recipients: z
65
- .array(
66
- z.object({
67
- key: z.string().describe('Unique identifier for this recipient'),
68
- type: z.enum(['signer', 'viewer', 'approver']),
69
- name: z.string().describe('Recipient full name'),
70
- email: z.string().email().describe('Recipient email'),
71
- language: z.string().optional().describe('Language code (en, es, fr)')
72
- })
73
- )
74
- .describe('Recipients/signers'),
75
- metadata: z.record(z.string(), z.string()).optional().describe('Custom metadata (e.g., deal_id)'),
76
- webhookUrl: z.string().url().optional().describe('Override default webhook URL'),
77
- routing: z.enum(['parallel', 'sequential']).optional().describe('How to route to multiple recipients')
78
- }),
79
- outputSchema: z.object({
80
- id: z.string().describe('Envelope ID (env_xxx)'),
81
- status: z.string().describe('Envelope status'),
82
- signingUrl: z.string().optional().describe('URL for first signer')
83
- }),
84
- integration: 'signature-api' as const,
85
- method: 'createEnvelope' as const,
86
- credentialName
87
- })
88
- }
89
-
90
- /**
91
- * Create a tool that voids/cancels SignatureAPI envelopes
92
- *
93
- * @param credentialName - Name of the SignatureAPI credential to use
94
- * @returns Tool instance
95
- *
96
- * @example
97
- * ```typescript
98
- * const tool = createSignatureApiVoidEnvelopeTool('signatureapi-prod')
99
- * const result = await tool.execute({
100
- * input: {
101
- * envelopeId: 'env_xxx',
102
- * reason: 'Revision requested by recipient'
103
- * },
104
- * executionContext: context
105
- * })
106
- * // result: { id: 'env_xxx', status: 'voided' }
107
- * ```
108
- */
109
- export function createSignatureApiVoidEnvelopeTool(credentialName: string): Tool {
110
- return createIntegrationTool({
111
- name: 'signatureapi_void_envelope',
112
- description: `Void/cancel a pending SignatureAPI envelope.
113
-
114
- Use this tool to cancel an envelope that hasn't been completed yet.
115
- Voided envelopes cannot be signed.
116
-
117
- Common reasons:
118
- - Revision requested by recipient
119
- - Error in document content
120
- - Deal cancelled`,
121
- inputSchema: z.object({
122
- envelopeId: z.string().describe('Envelope ID to void (env_xxx)'),
123
- reason: z.string().optional().describe('Reason for voiding')
124
- }),
125
- outputSchema: z.object({
126
- id: z.string().describe('Envelope ID'),
127
- status: z.literal('voided').describe('Status after voiding')
128
- }),
129
- integration: 'signature-api' as const,
130
- method: 'voidEnvelope' as const,
131
- credentialName
132
- })
133
- }
134
-
135
- /**
136
- * Create a tool that downloads signed documents from SignatureAPI
137
- *
138
- * @param credentialName - Name of the SignatureAPI credential to use
139
- * @returns Tool instance
140
- *
141
- * @example
142
- * ```typescript
143
- * const tool = createSignatureApiDownloadDocumentTool('signatureapi-prod')
144
- * const result = await tool.execute({
145
- * input: {
146
- * envelopeId: 'env_xxx',
147
- * documentType: 'combined'
148
- * },
149
- * executionContext: context
150
- * })
151
- * // result: { content: Buffer, contentType: 'application/pdf', filename: 'env_xxx-signed.pdf' }
152
- * ```
153
- */
154
- export function createSignatureApiDownloadDocumentTool(credentialName: string): Tool {
155
- return createIntegrationTool({
156
- name: 'signatureapi_download_document',
157
- description: `Download signed document from a completed envelope.
158
-
159
- Use this tool to retrieve the signed PDF after all recipients have signed.
160
- The combined document includes all documents and an audit trail.
161
-
162
- Document types:
163
- - combined: All documents merged with audit trail (default)
164
- - original: Original unsigned documents
165
- - audit: Audit trail only`,
166
- inputSchema: z.object({
167
- envelopeId: z.string().describe('Envelope ID (env_xxx)'),
168
- documentType: z.enum(['combined', 'original', 'audit']).optional().describe('Type of document to download')
169
- }),
170
- outputSchema: z.object({
171
- content: z.instanceof(Buffer).describe('PDF content as Buffer'),
172
- contentType: z.string().describe('MIME type'),
173
- filename: z.string().describe('Suggested filename')
174
- }),
175
- integration: 'signature-api' as const,
176
- method: 'downloadDocument' as const,
177
- credentialName
178
- })
179
- }
1
+ import { z } from 'zod'
2
+ import type { Tool } from '../../../../types'
3
+ import { createIntegrationTool } from '../../../tool'
4
+ import { EmailSchema } from '../../../../../../../platform/utils/validation'
5
+
6
+ /**
7
+ * Create a tool that creates SignatureAPI envelopes for electronic signatures
8
+ *
9
+ * @param credentialName - Name of the SignatureAPI credential to use
10
+ * @returns Tool instance
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const tool = createSignatureApiCreateEnvelopeTool('signatureapi-prod')
15
+ * const result = await tool.execute({
16
+ * input: {
17
+ * title: 'Elevasis Proposal - Acme Corp',
18
+ * documents: [{ name: 'proposal.pdf', url: 'https://...', places: [...] }],
19
+ * recipients: [{ key: 'signer1', type: 'signer', name: 'John', email: 'john@acme.com' }]
20
+ * },
21
+ * executionContext: context
22
+ * })
23
+ * // result: { id: 'env_xxx', status: 'processing', signingUrl: 'https://...' }
24
+ * ```
25
+ */
26
+ export function createSignatureApiCreateEnvelopeTool(credentialName: string): Tool {
27
+ return createIntegrationTool({
28
+ name: 'signatureapi_create_envelope',
29
+ description: `Create a SignatureAPI envelope for electronic signatures.
30
+
31
+ Use this tool to send documents for signing. An envelope is a container
32
+ that holds documents and manages the signing process.
33
+
34
+ Examples:
35
+ - Create proposal envelope: title, documents with PDF URLs, recipients with signers
36
+ - Include signature fields: specify page, x, y positions for signature placement
37
+ - Use 'date' for auto-populated signing date (maps to recipient_completed_date)
38
+
39
+ The envelope will be sent to recipients via email with a signing link.`,
40
+ inputSchema: z.object({
41
+ title: z.string().describe('Envelope title (shown in emails)'),
42
+ message: z.string().optional().describe('Custom message for recipient emails'),
43
+ documents: z
44
+ .array(
45
+ z.object({
46
+ name: z.string().describe('Document filename'),
47
+ url: z.string().url().describe('Publicly accessible URL to PDF document'),
48
+ places: z
49
+ .array(
50
+ z.object({
51
+ recipientKey: z.string().describe('Links to recipient key'),
52
+ type: z
53
+ .enum(['signature', 'date', 'text', 'initials'])
54
+ .describe('Field type (date maps to recipient_completed_date)'),
55
+ page: z.number().describe('Page number (1-indexed, -1 for last)'),
56
+ x: z.number().describe('X position in points'),
57
+ y: z.number().describe('Y position in points'),
58
+ width: z.number().optional(),
59
+ height: z.number().optional()
60
+ })
61
+ )
62
+ .optional()
63
+ .describe('Signature field placements')
64
+ })
65
+ )
66
+ .describe('Documents to sign'),
67
+ recipients: z
68
+ .array(
69
+ z.object({
70
+ key: z.string().describe('Unique identifier for this recipient'),
71
+ type: z.enum(['signer', 'viewer', 'approver']),
72
+ name: z.string().describe('Recipient full name'),
73
+ email: EmailSchema.describe('Recipient email'),
74
+ language: z.string().optional().describe('Language code (en, es, fr)')
75
+ })
76
+ )
77
+ .describe('Recipients/signers'),
78
+ metadata: z.record(z.string(), z.string()).optional().describe('Custom metadata (e.g., deal_id)'),
79
+ webhookUrl: z.string().url().optional().describe('Override default webhook URL'),
80
+ routing: z.enum(['parallel', 'sequential']).optional().describe('How to route to multiple recipients')
81
+ }),
82
+ outputSchema: z.object({
83
+ id: z.string().describe('Envelope ID (env_xxx)'),
84
+ status: z.string().describe('Envelope status'),
85
+ signingUrl: z.string().optional().describe('URL for first signer')
86
+ }),
87
+ integration: 'signature-api' as const,
88
+ method: 'createEnvelope' as const,
89
+ credentialName
90
+ })
91
+ }
92
+
93
+ /**
94
+ * Create a tool that voids/cancels SignatureAPI envelopes
95
+ *
96
+ * @param credentialName - Name of the SignatureAPI credential to use
97
+ * @returns Tool instance
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const tool = createSignatureApiVoidEnvelopeTool('signatureapi-prod')
102
+ * const result = await tool.execute({
103
+ * input: {
104
+ * envelopeId: 'env_xxx',
105
+ * reason: 'Revision requested by recipient'
106
+ * },
107
+ * executionContext: context
108
+ * })
109
+ * // result: { id: 'env_xxx', status: 'voided' }
110
+ * ```
111
+ */
112
+ export function createSignatureApiVoidEnvelopeTool(credentialName: string): Tool {
113
+ return createIntegrationTool({
114
+ name: 'signatureapi_void_envelope',
115
+ description: `Void/cancel a pending SignatureAPI envelope.
116
+
117
+ Use this tool to cancel an envelope that hasn't been completed yet.
118
+ Voided envelopes cannot be signed.
119
+
120
+ Common reasons:
121
+ - Revision requested by recipient
122
+ - Error in document content
123
+ - Deal cancelled`,
124
+ inputSchema: z.object({
125
+ envelopeId: z.string().describe('Envelope ID to void (env_xxx)'),
126
+ reason: z.string().optional().describe('Reason for voiding')
127
+ }),
128
+ outputSchema: z.object({
129
+ id: z.string().describe('Envelope ID'),
130
+ status: z.literal('voided').describe('Status after voiding')
131
+ }),
132
+ integration: 'signature-api' as const,
133
+ method: 'voidEnvelope' as const,
134
+ credentialName
135
+ })
136
+ }
137
+
138
+ /**
139
+ * Create a tool that downloads signed documents from SignatureAPI
140
+ *
141
+ * @param credentialName - Name of the SignatureAPI credential to use
142
+ * @returns Tool instance
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const tool = createSignatureApiDownloadDocumentTool('signatureapi-prod')
147
+ * const result = await tool.execute({
148
+ * input: {
149
+ * envelopeId: 'env_xxx',
150
+ * documentType: 'combined'
151
+ * },
152
+ * executionContext: context
153
+ * })
154
+ * // result: { content: Buffer, contentType: 'application/pdf', filename: 'env_xxx-signed.pdf' }
155
+ * ```
156
+ */
157
+ export function createSignatureApiDownloadDocumentTool(credentialName: string): Tool {
158
+ return createIntegrationTool({
159
+ name: 'signatureapi_download_document',
160
+ description: `Download signed document from a completed envelope.
161
+
162
+ Use this tool to retrieve the signed PDF after all recipients have signed.
163
+ The combined document includes all documents and an audit trail.
164
+
165
+ Document types:
166
+ - combined: All documents merged with audit trail (default)
167
+ - original: Original unsigned documents
168
+ - audit: Audit trail only`,
169
+ inputSchema: z.object({
170
+ envelopeId: z.string().describe('Envelope ID (env_xxx)'),
171
+ documentType: z.enum(['combined', 'original', 'audit']).optional().describe('Type of document to download')
172
+ }),
173
+ outputSchema: z.object({
174
+ content: z.instanceof(Buffer).describe('PDF content as Buffer'),
175
+ contentType: z.string().describe('MIME type'),
176
+ filename: z.string().describe('Suggested filename')
177
+ }),
178
+ integration: 'signature-api' as const,
179
+ method: 'downloadDocument' as const,
180
+ credentialName
181
+ })
182
+ }