@besales/mcp 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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +127 -0
  3. package/bin/besales-mcp.js +10 -0
  4. package/dist/auth/oauth-client.d.ts +32 -0
  5. package/dist/auth/oauth-client.js +180 -0
  6. package/dist/auth/oauth-client.js.map +1 -0
  7. package/dist/auth/token-storage.d.ts +7 -0
  8. package/dist/auth/token-storage.js +17 -0
  9. package/dist/auth/token-storage.js.map +1 -0
  10. package/dist/cli.d.ts +22 -0
  11. package/dist/cli.js +70 -0
  12. package/dist/cli.js.map +1 -0
  13. package/dist/http/api-client.d.ts +51 -0
  14. package/dist/http/api-client.js +115 -0
  15. package/dist/http/api-client.js.map +1 -0
  16. package/dist/index.d.ts +16 -0
  17. package/dist/index.js +10 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/package-metadata.d.ts +1 -0
  20. package/dist/package-metadata.js +6 -0
  21. package/dist/package-metadata.js.map +1 -0
  22. package/dist/resources/concepts/external-execution.md +22 -0
  23. package/dist/resources/concepts/handoff.md +16 -0
  24. package/dist/resources/concepts/icp.md +16 -0
  25. package/dist/resources/concepts/sandbox.md +17 -0
  26. package/dist/resources/concepts/triggers.md +16 -0
  27. package/dist/resources/registry.d.ts +5 -0
  28. package/dist/resources/registry.js +33 -0
  29. package/dist/resources/registry.js.map +1 -0
  30. package/dist/schemas/mcp-tools.json +1192 -0
  31. package/dist/server.d.ts +20 -0
  32. package/dist/server.js +74 -0
  33. package/dist/server.js.map +1 -0
  34. package/dist/tools/contracts.d.ts +22 -0
  35. package/dist/tools/contracts.js +24 -0
  36. package/dist/tools/contracts.js.map +1 -0
  37. package/dist/tools/definitions.d.ts +307 -0
  38. package/dist/tools/definitions.js +859 -0
  39. package/dist/tools/definitions.js.map +1 -0
  40. package/dist/tools/registry.d.ts +11 -0
  41. package/dist/tools/registry.js +52 -0
  42. package/dist/tools/registry.js.map +1 -0
  43. package/dist/tools/result.d.ts +4 -0
  44. package/dist/tools/result.js +78 -0
  45. package/dist/tools/result.js.map +1 -0
  46. package/dist/types/api-contract.gen.d.ts +6975 -0
  47. package/dist/types/api-contract.gen.js +6 -0
  48. package/dist/types/api-contract.gen.js.map +1 -0
  49. package/dist/utils/logger.d.ts +2 -0
  50. package/dist/utils/logger.js +13 -0
  51. package/dist/utils/logger.js.map +1 -0
  52. package/dist/utils/mask.d.ts +1 -0
  53. package/dist/utils/mask.js +7 -0
  54. package/dist/utils/mask.js.map +1 -0
  55. package/docs/host-setup.md +256 -0
  56. package/package.json +81 -0
  57. package/scripts/install-claude-desktop.js +77 -0
  58. package/scripts/mock-api-server.js +56 -0
  59. package/scripts/mock-credentials.js +34 -0
@@ -0,0 +1,859 @@
1
+ import { z } from 'zod';
2
+ const uuidSchema = z.string().uuid();
3
+ const anyObjectSchema = z.object({}).passthrough();
4
+ const optionalAnyObjectSchema = anyObjectSchema.optional();
5
+ const outcomeSchema = z.enum(['won', 'lost', 'in_progress']);
6
+ const platformSetupConfirmationSchema = {
7
+ explicit_confirmation: z.boolean().optional(),
8
+ confirmation_reason: z.string().optional(),
9
+ };
10
+ const modelLaneSchema = z.enum(['CHEAP', 'STANDARD', 'DEEP']);
11
+ const routingStrategySchema = z.enum(['LEAD_STATUS', 'CUSTOM_VARIABLE']);
12
+ const triggerScopeSchema = z.enum(['ON_USER_MESSAGE']).optional();
13
+ const followUpSequenceTypeSchema = z.enum([
14
+ 'MEETING_REMINDER',
15
+ 'INACTIVE_USER_REACTIVATION',
16
+ 'LOST_CLIENTS',
17
+ ]);
18
+ const followUpTriggerSchema = z.enum([
19
+ 'USER_INACTIVITY',
20
+ 'DEAL_CLOSED',
21
+ 'BIRTHDAY_DATE',
22
+ 'MEETING_TIME',
23
+ 'CUSTOM_SCHEDULE',
24
+ 'LOST_CLIENTS',
25
+ ]);
26
+ const analysisModeSchema = z.enum([
27
+ 'grammar',
28
+ 'structure',
29
+ 'industry',
30
+ 'contradictions',
31
+ 'completeness',
32
+ ]);
33
+ const promptGenerationStageOutputSchema = z.object({
34
+ name: z.enum(['structure_builder', 'industry_validator', 'prompt_tester', 'finalizer']),
35
+ output: anyObjectSchema,
36
+ });
37
+ const promptIterationStageOutputSchema = z.object({
38
+ name: z.enum(['iteration_analysis', 'iteration_recommendation']),
39
+ output: anyObjectSchema,
40
+ });
41
+ const promptAnalysisStageOutputSchema = z.object({
42
+ name: z.enum(['grammar', 'industry', 'structure', 'aggregation']),
43
+ output: anyObjectSchema,
44
+ });
45
+ const icpAnalysisSegmentSchema = z.object({
46
+ id: uuidSchema.optional(),
47
+ name: z.string(),
48
+ description: z.string().optional(),
49
+ demographics: optionalAnyObjectSchema,
50
+ pains: z.array(z.unknown()).optional(),
51
+ motivations: z.array(z.unknown()).optional(),
52
+ language_style: optionalAnyObjectSchema,
53
+ });
54
+ const icpAnalysisPersonaSchema = z.object({
55
+ name: z.string(),
56
+ segment_id: uuidSchema,
57
+ description: z.string().optional(),
58
+ pain_points: z.array(z.unknown()).optional(),
59
+ goals: z.array(z.unknown()).optional(),
60
+ objections: optionalAnyObjectSchema,
61
+ messaging_hints: optionalAnyObjectSchema,
62
+ });
63
+ const feedbackSchema = z.object({
64
+ general_comments: z.string().optional(),
65
+ selections: z.array(anyObjectSchema).optional(),
66
+ });
67
+ const sandboxFindingSchema = z.object({
68
+ scenario_id: uuidSchema.optional(),
69
+ category: z.enum([
70
+ 'hallucination',
71
+ 'wrong_action',
72
+ 'missed_trigger',
73
+ 'wrong_pipeline_transition',
74
+ 'rag_miss',
75
+ 'bad_tone',
76
+ 'other',
77
+ ]),
78
+ severity: z.enum(['low', 'medium', 'critical']),
79
+ message: z.string(),
80
+ suggestion: z.string().optional(),
81
+ turn_index: z.number().int().optional(),
82
+ });
83
+ const simulationFindingSchema = z.object({
84
+ dialogue_id: uuidSchema.optional(),
85
+ category: z.enum([
86
+ 'hallucination',
87
+ 'wrong_action',
88
+ 'bad_tone',
89
+ 'missed_context',
90
+ 'contradiction',
91
+ 'off_topic',
92
+ 'other',
93
+ ]),
94
+ severity: z.enum(['low', 'medium', 'critical']),
95
+ message: z.string(),
96
+ suggestion: z.string().optional(),
97
+ reference_message_index: z.number().int().optional(),
98
+ });
99
+ const routingRuleLeadStatusSchema = z.object({
100
+ lead_status_name: z.string().nullable().optional(),
101
+ lead_status_pipeline_crm_id: z.string().nullable().optional(),
102
+ lead_status_pipeline_id: z.number().int().nullable().optional(),
103
+ lead_status_id: z.number().int().nullable().optional(),
104
+ });
105
+ const agentToolPatchSchema = z.object({
106
+ tool_id: z.string(),
107
+ priority: z.number().int().min(1).max(100).optional(),
108
+ is_enabled: z.boolean().optional(),
109
+ agent_specific_conditions: anyObjectSchema.nullable().optional(),
110
+ });
111
+ export const toolDefinitions = [
112
+ defineTool({
113
+ name: 'besales_icp_create',
114
+ requiredFields: ['name'],
115
+ defaultWorkspaceId: true,
116
+ schema: z.object({
117
+ workspace_id: uuidSchema.optional(),
118
+ name: z.string(),
119
+ description: z.string().optional(),
120
+ source: z
121
+ .enum(['from_dialogues', 'from_files', 'from_scratch', 'ai_generated'])
122
+ .default('from_scratch'),
123
+ }),
124
+ createRequest: (input) => ({
125
+ path: `/workspaces/${input.workspace_id}/icp`,
126
+ body: compactObject({
127
+ name: input.name,
128
+ description: input.description,
129
+ source: {
130
+ type: input.source === 'ai_generated' ? 'from_scratch' : input.source,
131
+ },
132
+ }),
133
+ }),
134
+ }),
135
+ defineTool({
136
+ name: 'besales_icp_import_dialogues',
137
+ requiredFields: ['icp_id', 'crm_connection_id', 'gdpr_confirmed'],
138
+ schema: z.object({
139
+ icp_id: uuidSchema,
140
+ crm_connection_id: uuidSchema,
141
+ outcome_filter: z.array(outcomeSchema).default(['won', 'lost']),
142
+ days_ago: z.number().int().min(1).max(730).default(180),
143
+ anonymize: z.boolean().default(true),
144
+ gdpr_confirmed: z.boolean(),
145
+ }),
146
+ createRequest: (input) => ({
147
+ path: `/icp/${input.icp_id}/samples/import-from-crm`,
148
+ body: {
149
+ crmConnectionId: input.crm_connection_id,
150
+ outcomeFilter: input.outcome_filter,
151
+ ageFilter: { daysAgo: input.days_ago },
152
+ anonymize: input.anonymize,
153
+ gdprConfirmed: input.gdpr_confirmed,
154
+ },
155
+ }),
156
+ }),
157
+ defineTool({
158
+ name: 'besales_icp_analysis_get_instructions',
159
+ requiredFields: ['icp_profile_id'],
160
+ defaultWorkspaceId: true,
161
+ schema: z.object({
162
+ workspace_id: uuidSchema.optional(),
163
+ icp_profile_id: uuidSchema,
164
+ business_context: optionalAnyObjectSchema,
165
+ }),
166
+ createRequest: (input) => ({
167
+ path: `/workspaces/${input.workspace_id}/icp/instructions`,
168
+ body: compactObject({
169
+ icpProfileId: input.icp_profile_id,
170
+ businessContext: input.business_context,
171
+ }),
172
+ }),
173
+ enhanceResponse: (response) => withInstructions(response, [
174
+ 'Выполни 3 stages ICP analysis локально: segment_clustering, classification, persona_generation.',
175
+ 'Используй returned schemas для structured output и не меняй operationId.',
176
+ 'Для каждого нового segment укажи валидный UUID id; persona.segment_id должен точно совпадать с существующим segment id или UUID из segments[].id.',
177
+ 'После всех stages вызови besales_icp_analysis_submit с segments и personas.',
178
+ ]),
179
+ }),
180
+ defineTool({
181
+ name: 'besales_icp_analysis_submit',
182
+ requiredFields: ['operation_id', 'icp_profile_id', 'segments', 'personas'],
183
+ defaultWorkspaceId: true,
184
+ schema: z.object({
185
+ workspace_id: uuidSchema.optional(),
186
+ operation_id: uuidSchema,
187
+ icp_profile_id: uuidSchema,
188
+ segments: z.array(icpAnalysisSegmentSchema),
189
+ personas: z.array(icpAnalysisPersonaSchema),
190
+ }),
191
+ createRequest: (input) => ({
192
+ path: `/workspaces/${input.workspace_id}/icp/external-submit`,
193
+ body: {
194
+ operationId: input.operation_id,
195
+ icpProfileId: input.icp_profile_id,
196
+ segments: input.segments.map((segment) => compactObject({
197
+ id: segment.id,
198
+ name: segment.name,
199
+ description: segment.description,
200
+ demographics: segment.demographics,
201
+ pains: segment.pains,
202
+ motivations: segment.motivations,
203
+ languageStyle: segment.language_style,
204
+ })),
205
+ personas: input.personas.map((persona) => compactObject({
206
+ name: persona.name,
207
+ segmentId: persona.segment_id,
208
+ description: persona.description,
209
+ painPoints: persona.pain_points,
210
+ goals: persona.goals,
211
+ objections: persona.objections,
212
+ messagingHints: persona.messaging_hints,
213
+ })),
214
+ },
215
+ }),
216
+ restartToolName: 'besales_icp_analysis_get_instructions',
217
+ }),
218
+ defineTool({
219
+ name: 'besales_prompt_generate_get_instructions',
220
+ requiredFields: ['agent_id'],
221
+ schema: z.object({
222
+ agent_id: uuidSchema,
223
+ icp_profile_id: uuidSchema.optional(),
224
+ business_context: optionalAnyObjectSchema,
225
+ style_hints: z
226
+ .object({
227
+ formality: z.enum(['formal', 'casual', 'friendly']).optional(),
228
+ verbosity: z.enum(['concise', 'balanced', 'detailed']).optional(),
229
+ language: z.string().default('ru'),
230
+ })
231
+ .optional(),
232
+ }),
233
+ createRequest: (input) => ({
234
+ path: `/agents/${input.agent_id}/prompt/generate/instructions`,
235
+ body: compactObject({
236
+ sourceType: input.icp_profile_id ? 'icp_full' : 'business_context_only',
237
+ icpProfileId: input.icp_profile_id,
238
+ businessContext: input.business_context,
239
+ styleHints: input.style_hints,
240
+ }),
241
+ }),
242
+ enhanceResponse: (response) => withInstructions(response, [
243
+ 'Выполни 4 stages prompt generation локально: structure_builder, industry_validator, prompt_tester, finalizer.',
244
+ 'Каждая stage должна вернуть JSON по своей schema. Финальный compiled prompt положи в final_content.',
245
+ 'После stages вызови besales_prompt_generate_submit с stages, final_content и metadata.',
246
+ ]),
247
+ }),
248
+ defineTool({
249
+ name: 'besales_prompt_generate_submit',
250
+ requiredFields: ['agent_id', 'operation_id', 'stages', 'final_content'],
251
+ schema: z.object({
252
+ agent_id: uuidSchema,
253
+ operation_id: uuidSchema,
254
+ stages: z.array(promptGenerationStageOutputSchema).min(4),
255
+ final_content: z.string(),
256
+ metadata: z
257
+ .object({
258
+ total_tokens: z.number().int().optional(),
259
+ models: z.record(z.string(), z.string()).optional(),
260
+ })
261
+ .optional(),
262
+ }),
263
+ createRequest: (input) => ({
264
+ path: `/agents/${input.agent_id}/prompt/generate/${input.operation_id}/submit`,
265
+ body: compactObject({
266
+ stages: input.stages,
267
+ finalContent: input.final_content,
268
+ metadata: input.metadata
269
+ ? compactObject({
270
+ totalTokens: input.metadata.total_tokens,
271
+ models: input.metadata.models,
272
+ })
273
+ : undefined,
274
+ }),
275
+ }),
276
+ restartToolName: 'besales_prompt_generate_get_instructions',
277
+ }),
278
+ defineTool({
279
+ name: 'besales_prompt_iterate_get_instructions',
280
+ requiredFields: ['agent_id', 'base_version_id', 'feedback'],
281
+ schema: z.object({
282
+ agent_id: uuidSchema,
283
+ base_version_id: uuidSchema,
284
+ feedback: feedbackSchema,
285
+ }),
286
+ createRequest: (input) => ({
287
+ path: `/agents/${input.agent_id}/prompt/iterate/instructions`,
288
+ body: {
289
+ baseVersionId: input.base_version_id,
290
+ feedback: compactObject({
291
+ generalComments: input.feedback.general_comments,
292
+ selections: input.feedback.selections,
293
+ }),
294
+ },
295
+ }),
296
+ enhanceResponse: (response) => withInstructions(response, [
297
+ 'Выполни 2 stages prompt iteration локально: iteration_analysis и iteration_recommendation.',
298
+ 'Сохрани связь с baseVersionId и верни proposed_changes плюс preview_content.',
299
+ 'После stages вызови besales_prompt_iterate_submit.',
300
+ ]),
301
+ }),
302
+ defineTool({
303
+ name: 'besales_prompt_iterate_submit',
304
+ requiredFields: ['agent_id', 'operation_id', 'stages', 'proposed_changes', 'preview_content'],
305
+ schema: z.object({
306
+ agent_id: uuidSchema,
307
+ operation_id: uuidSchema,
308
+ stages: z.array(promptIterationStageOutputSchema).min(2),
309
+ proposed_changes: z.array(anyObjectSchema),
310
+ preview_content: z.string(),
311
+ }),
312
+ createRequest: (input) => ({
313
+ path: `/agents/${input.agent_id}/prompt/iterate/${input.operation_id}/submit`,
314
+ body: {
315
+ stages: input.stages,
316
+ proposedChanges: input.proposed_changes,
317
+ previewContent: input.preview_content,
318
+ },
319
+ }),
320
+ restartToolName: 'besales_prompt_iterate_get_instructions',
321
+ }),
322
+ defineTool({
323
+ name: 'besales_prompt_analyze_get_instructions',
324
+ requiredFields: ['agent_id', 'version_id'],
325
+ schema: z.object({
326
+ agent_id: uuidSchema,
327
+ version_id: uuidSchema,
328
+ modes: z.array(analysisModeSchema).default(['grammar', 'structure', 'contradictions']),
329
+ }),
330
+ createRequest: (input) => ({
331
+ path: `/agents/${input.agent_id}/prompt/analyze/instructions`,
332
+ body: {
333
+ versionId: input.version_id,
334
+ modes: input.modes,
335
+ },
336
+ }),
337
+ enhanceResponse: (response) => withInstructions(response, [
338
+ 'Выполни static analysis stages локально: grammar, industry, structure, aggregation.',
339
+ 'Собери итоговый список issues без дублей и с severity.',
340
+ 'После анализа вызови besales_prompt_analyze_submit с aggregated_issues.',
341
+ ]),
342
+ }),
343
+ defineTool({
344
+ name: 'besales_prompt_analyze_submit',
345
+ requiredFields: ['agent_id', 'operation_id', 'stages', 'aggregated_issues'],
346
+ schema: z.object({
347
+ agent_id: uuidSchema,
348
+ operation_id: uuidSchema,
349
+ stages: z.array(promptAnalysisStageOutputSchema).min(4),
350
+ aggregated_issues: z.array(anyObjectSchema),
351
+ }),
352
+ createRequest: (input) => ({
353
+ path: `/agents/${input.agent_id}/prompt/analyze/${input.operation_id}/submit`,
354
+ body: {
355
+ stages: input.stages,
356
+ aggregatedIssues: input.aggregated_issues,
357
+ },
358
+ }),
359
+ restartToolName: 'besales_prompt_analyze_get_instructions',
360
+ }),
361
+ defineTool({
362
+ name: 'besales_prompt_finalize',
363
+ requiredFields: ['agent_id', 'draft_version_id'],
364
+ schema: z.object({
365
+ agent_id: uuidSchema,
366
+ draft_version_id: uuidSchema,
367
+ changelog_note: z.string().optional(),
368
+ }),
369
+ createRequest: (input) => ({
370
+ path: `/agents/${input.agent_id}/prompt/approve`,
371
+ body: compactObject({
372
+ draftVersionId: input.draft_version_id,
373
+ changelogNote: input.changelog_note,
374
+ }),
375
+ }),
376
+ }),
377
+ defineTool({
378
+ name: 'besales_sandbox_run_start',
379
+ requiredFields: ['agent_id'],
380
+ schema: z.object({
381
+ agent_id: uuidSchema,
382
+ scenario_ids: z.array(uuidSchema).optional(),
383
+ options: z
384
+ .object({
385
+ check_routing: z.boolean().default(false),
386
+ check_pipeline_transitions: z.boolean().default(false),
387
+ check_agent_actions: z.boolean().default(false),
388
+ run_rag_golden_tests: z.boolean().default(false),
389
+ turns_per_scenario: z.number().int().min(1).max(50).default(10),
390
+ })
391
+ .optional(),
392
+ }),
393
+ createRequest: (input) => ({
394
+ path: `/agents/${input.agent_id}/sandbox-runs`,
395
+ body: compactObject({
396
+ scenarioIds: input.scenario_ids,
397
+ options: input.options
398
+ ? {
399
+ checkRouting: input.options.check_routing,
400
+ checkPipelineTransitions: input.options.check_pipeline_transitions,
401
+ checkAgentActions: input.options.check_agent_actions,
402
+ runRagGoldenTests: input.options.run_rag_golden_tests,
403
+ turnsPerScenario: input.options.turns_per_scenario,
404
+ }
405
+ : undefined,
406
+ }),
407
+ }),
408
+ }),
409
+ defineTool({
410
+ name: 'besales_sandbox_findings_get_instructions',
411
+ requiredFields: ['agent_id', 'run_id'],
412
+ schema: z.object({
413
+ agent_id: uuidSchema,
414
+ run_id: uuidSchema,
415
+ }),
416
+ createRequest: (input) => ({
417
+ path: `/agents/${input.agent_id}/sandbox/runs/${input.run_id}/findings/instructions`,
418
+ }),
419
+ enhanceResponse: (response) => withInstructions(response, [
420
+ 'Проанализируй sandbox report локально и выдели structured findings.',
421
+ 'Сгруппируй проблемы по scenario/turn/category/severity и предложи actionable fix.',
422
+ 'После анализа вызови besales_sandbox_findings_submit.',
423
+ ]),
424
+ }),
425
+ defineTool({
426
+ name: 'besales_sandbox_findings_submit',
427
+ requiredFields: ['agent_id', 'run_id', 'operation_id', 'findings'],
428
+ schema: z.object({
429
+ agent_id: uuidSchema,
430
+ run_id: uuidSchema,
431
+ operation_id: uuidSchema,
432
+ findings: z.array(sandboxFindingSchema),
433
+ }),
434
+ createRequest: (input) => ({
435
+ path: `/agents/${input.agent_id}/sandbox/runs/${input.run_id}/findings/${input.operation_id}/submit`,
436
+ body: {
437
+ findings: input.findings.map((finding) => compactObject({
438
+ scenarioId: finding.scenario_id,
439
+ category: finding.category,
440
+ severity: finding.severity,
441
+ message: finding.message,
442
+ suggestion: finding.suggestion,
443
+ turnIndex: finding.turn_index,
444
+ })),
445
+ },
446
+ }),
447
+ restartToolName: 'besales_sandbox_findings_get_instructions',
448
+ }),
449
+ defineTool({
450
+ name: 'besales_simulation_findings_get_instructions',
451
+ requiredFields: ['agent_id', 'simulation_id'],
452
+ schema: z.object({
453
+ agent_id: uuidSchema,
454
+ simulation_id: uuidSchema,
455
+ }),
456
+ createRequest: (input) => ({
457
+ path: `/agents/${input.agent_id}/prompt/simulate-findings/instructions`,
458
+ body: {
459
+ simulationId: input.simulation_id,
460
+ },
461
+ }),
462
+ enhanceResponse: (response) => withInstructions(response, [
463
+ 'Проанализируй simulation dialogues локально и найди hallucination, tone, off-topic и action issues.',
464
+ 'Не отправляй raw simulation_id в submit body: он используется только для выбора route/context.',
465
+ 'После анализа вызови besales_simulation_findings_submit.',
466
+ ]),
467
+ }),
468
+ defineTool({
469
+ name: 'besales_simulation_findings_submit',
470
+ requiredFields: ['agent_id', 'simulation_id', 'operation_id', 'findings'],
471
+ schema: z.object({
472
+ agent_id: uuidSchema,
473
+ simulation_id: uuidSchema,
474
+ operation_id: uuidSchema,
475
+ findings: z.array(simulationFindingSchema),
476
+ }),
477
+ createRequest: (input) => ({
478
+ path: `/agents/${input.agent_id}/prompt/simulate-findings/${input.operation_id}/submit`,
479
+ body: {
480
+ findings: input.findings.map((finding) => compactObject({
481
+ dialogueId: finding.dialogue_id,
482
+ category: finding.category,
483
+ severity: finding.severity,
484
+ message: finding.message,
485
+ suggestion: finding.suggestion,
486
+ referenceMessageIndex: finding.reference_message_index,
487
+ })),
488
+ },
489
+ }),
490
+ restartToolName: 'besales_simulation_findings_get_instructions',
491
+ }),
492
+ defineTool({
493
+ name: 'besales_qa_generation_get_instructions',
494
+ requiredFields: ['agent_id'],
495
+ schema: z.object({
496
+ agent_id: uuidSchema,
497
+ namespace_context: z.string().optional(),
498
+ company_context: z.string().optional(),
499
+ icp_profile_id: uuidSchema.optional(),
500
+ target_count: z.number().int().min(5).max(100).default(30),
501
+ }),
502
+ createRequest: (input) => ({
503
+ path: `/agents/${input.agent_id}/knowledge/qa-generation/instructions`,
504
+ body: compactObject({
505
+ namespaceContext: input.namespace_context,
506
+ companyContext: input.company_context,
507
+ icpProfileId: input.icp_profile_id,
508
+ targetCount: input.target_count,
509
+ }),
510
+ }),
511
+ enhanceResponse: (response) => withInstructions(response, [
512
+ 'Сгенерируй Q&A pairs локально по returned schema и company/namespace context.',
513
+ 'Каждая пара должна быть пригодна для knowledge base: короткий вопрос, точный ответ, optional tags.',
514
+ 'После генерации вызови besales_qa_generation_submit с qa_pairs.',
515
+ ]),
516
+ }),
517
+ defineTool({
518
+ name: 'besales_qa_generation_submit',
519
+ requiredFields: ['agent_id', 'operation_id', 'qa_pairs'],
520
+ schema: z.object({
521
+ agent_id: uuidSchema,
522
+ operation_id: uuidSchema,
523
+ knowledge_space_id: uuidSchema.optional(),
524
+ qa_pairs: z.array(z.object({
525
+ question: z.string(),
526
+ answer: z.string(),
527
+ tags: z.array(z.string()).optional(),
528
+ })),
529
+ }),
530
+ createRequest: (input) => ({
531
+ path: `/agents/${input.agent_id}/knowledge/qa-generation/${input.operation_id}/submit`,
532
+ body: compactObject({
533
+ knowledgeSpaceId: input.knowledge_space_id,
534
+ qaPairs: input.qa_pairs,
535
+ }),
536
+ }),
537
+ restartToolName: 'besales_qa_generation_get_instructions',
538
+ }),
539
+ defineTool({
540
+ name: 'besales_platform_context_get',
541
+ requiredFields: ['platform_id'],
542
+ schema: z.object({
543
+ platform_id: uuidSchema,
544
+ }),
545
+ createRequest: (input) => ({
546
+ method: 'GET',
547
+ path: `/platforms/${input.platform_id}/setup/context`,
548
+ }),
549
+ enhanceResponse: (response) => withInstructions(response, [
550
+ 'Use this sanitized context first for Platform Setup Bridge flows.',
551
+ 'Read readiness flags, then call targeted mutation tools. Do not ask the user for workspace_id.',
552
+ 'Prompt content changes still go through besales_prompt_* tools and besales_prompt_finalize.',
553
+ ]),
554
+ }),
555
+ defineTool({
556
+ name: 'besales_agent_list',
557
+ requiredFields: ['platform_id'],
558
+ schema: z.object({
559
+ platform_id: uuidSchema,
560
+ }),
561
+ createRequest: (input) => ({
562
+ method: 'GET',
563
+ path: `/platforms/${input.platform_id}/agents`,
564
+ }),
565
+ }),
566
+ defineTool({
567
+ name: 'besales_agent_create',
568
+ requiredFields: ['platform_id', 'name', 'model_lane'],
569
+ schema: z.object({
570
+ platform_id: uuidSchema,
571
+ name: z.string(),
572
+ description: z.string().nullable().optional(),
573
+ model_lane: modelLaneSchema,
574
+ default_icp_profile_id: uuidSchema.optional(),
575
+ }),
576
+ createRequest: (input) => ({
577
+ path: `/platforms/${input.platform_id}/agents`,
578
+ body: compactObject({
579
+ name: input.name,
580
+ description: input.description,
581
+ modelLane: input.model_lane,
582
+ defaultIcpProfileId: input.default_icp_profile_id,
583
+ }),
584
+ }),
585
+ }),
586
+ defineTool({
587
+ name: 'besales_agent_update',
588
+ requiredFields: ['platform_id', 'agent_id'],
589
+ schema: z.object({
590
+ platform_id: uuidSchema,
591
+ agent_id: uuidSchema,
592
+ name: z.string().optional(),
593
+ description: z.string().nullable().optional(),
594
+ model_lane: modelLaneSchema.optional(),
595
+ default_icp_profile_id: uuidSchema.nullable().optional(),
596
+ use_global_history: z.boolean().optional(),
597
+ adapt_to_user_language: z.boolean().optional(),
598
+ }),
599
+ createRequest: (input) => ({
600
+ method: 'PATCH',
601
+ path: `/platforms/${input.platform_id}/agents/${input.agent_id}`,
602
+ body: compactObject({
603
+ name: input.name,
604
+ description: input.description,
605
+ modelLane: input.model_lane,
606
+ defaultIcpProfileId: input.default_icp_profile_id,
607
+ useGlobalHistory: input.use_global_history,
608
+ adaptToUserLanguage: input.adapt_to_user_language,
609
+ }),
610
+ }),
611
+ }),
612
+ defineTool({
613
+ name: 'besales_agent_tools_update',
614
+ requiredFields: ['platform_id', 'agent_id', 'tools'],
615
+ schema: z.object({
616
+ platform_id: uuidSchema,
617
+ agent_id: uuidSchema,
618
+ tools: z.array(agentToolPatchSchema).min(1),
619
+ }),
620
+ createRequest: (input) => ({
621
+ method: 'PATCH',
622
+ path: `/platforms/${input.platform_id}/agents/${input.agent_id}/tools`,
623
+ body: {
624
+ tools: input.tools.map((tool) => compactObject({
625
+ toolId: tool.tool_id,
626
+ priority: tool.priority,
627
+ isEnabled: tool.is_enabled,
628
+ agentSpecificConditions: tool.agent_specific_conditions,
629
+ })),
630
+ },
631
+ }),
632
+ }),
633
+ defineTool({
634
+ name: 'besales_router_update',
635
+ requiredFields: ['platform_id'],
636
+ schema: z.object({
637
+ platform_id: uuidSchema,
638
+ name: z.string().optional(),
639
+ model: z.string().optional(),
640
+ temperature: z.number().min(0).max(2).optional(),
641
+ max_tokens: z.number().int().min(1).nullable().optional(),
642
+ additional_prompt: z.string().nullable().optional(),
643
+ adapt_to_user_language: z.boolean().optional(),
644
+ skip_llm_routing: z.boolean().optional(),
645
+ direct_routing_agent_id: uuidSchema.nullable().optional(),
646
+ ...platformSetupConfirmationSchema,
647
+ }),
648
+ createRequest: (input) => ({
649
+ method: 'PATCH',
650
+ path: `/platforms/${input.platform_id}/router`,
651
+ body: compactObject({
652
+ name: input.name,
653
+ model: input.model,
654
+ temperature: input.temperature,
655
+ maxTokens: input.max_tokens,
656
+ additionalPrompt: input.additional_prompt,
657
+ adaptToUserLanguage: input.adapt_to_user_language,
658
+ skipLlmRouting: input.skip_llm_routing,
659
+ directRoutingAgentId: input.direct_routing_agent_id,
660
+ ...setupConfirmation(input),
661
+ }),
662
+ }),
663
+ }),
664
+ defineTool({
665
+ name: 'besales_routing_rule_upsert',
666
+ requiredFields: ['platform_id', 'routing_strategy', 'custom_router_prompt'],
667
+ schema: z.object({
668
+ platform_id: uuidSchema,
669
+ routing_rule_id: uuidSchema.optional(),
670
+ routing_strategy: routingStrategySchema,
671
+ deal_mode: z.string().nullable().optional(),
672
+ custom_variable_id: uuidSchema.nullable().optional(),
673
+ variable_value: z.string().nullable().optional(),
674
+ custom_router_prompt: z.string(),
675
+ is_enabled: z.boolean().optional(),
676
+ priority: z.number().int().min(0).optional(),
677
+ skip_llm: z.boolean().optional(),
678
+ direct_agent_id: uuidSchema.nullable().optional(),
679
+ lead_statuses: z.array(routingRuleLeadStatusSchema).optional(),
680
+ ...platformSetupConfirmationSchema,
681
+ }),
682
+ createRequest: (input) => ({
683
+ method: input.routing_rule_id ? 'PATCH' : 'POST',
684
+ path: `/platforms/${input.platform_id}/router/routing-rules`,
685
+ body: compactObject({
686
+ routingRuleId: input.routing_rule_id,
687
+ routingStrategy: input.routing_strategy,
688
+ dealMode: input.deal_mode,
689
+ customVariableId: input.custom_variable_id,
690
+ variableValue: input.variable_value,
691
+ customRouterPrompt: input.custom_router_prompt,
692
+ isEnabled: input.is_enabled,
693
+ priority: input.priority,
694
+ skipLlm: input.skip_llm,
695
+ directAgentId: input.direct_agent_id,
696
+ leadStatuses: input.lead_statuses?.map((status) => compactObject({
697
+ leadStatusName: status.lead_status_name,
698
+ leadStatusPipelineCrmId: status.lead_status_pipeline_crm_id,
699
+ leadStatusPipelineId: status.lead_status_pipeline_id,
700
+ leadStatusId: status.lead_status_id,
701
+ })),
702
+ ...setupConfirmation(input),
703
+ }),
704
+ }),
705
+ }),
706
+ defineTool({
707
+ name: 'besales_trigger_upsert',
708
+ requiredFields: ['platform_id', 'agent_id'],
709
+ schema: z.object({
710
+ platform_id: uuidSchema,
711
+ agent_id: uuidSchema,
712
+ trigger_id: uuidSchema.optional(),
713
+ name: z.string().optional(),
714
+ condition: z.string().optional(),
715
+ is_enabled: z.boolean().optional(),
716
+ priority: z.number().int().min(1).max(100).optional(),
717
+ stop_propagation: z.boolean().optional(),
718
+ scope: triggerScopeSchema,
719
+ metadata: anyObjectSchema.optional(),
720
+ actions: z.array(anyObjectSchema).optional(),
721
+ ...platformSetupConfirmationSchema,
722
+ }),
723
+ createRequest: (input) => ({
724
+ method: input.trigger_id ? 'PATCH' : 'POST',
725
+ path: input.trigger_id
726
+ ? `/platforms/${input.platform_id}/agents/${input.agent_id}/triggers/${input.trigger_id}`
727
+ : `/platforms/${input.platform_id}/agents/${input.agent_id}/triggers`,
728
+ body: compactObject({
729
+ name: input.name,
730
+ condition: input.condition,
731
+ isEnabled: input.is_enabled,
732
+ priority: input.priority,
733
+ stopPropagation: input.stop_propagation,
734
+ scope: input.scope,
735
+ metadata: input.metadata,
736
+ actions: input.actions,
737
+ ...setupConfirmation(input),
738
+ }),
739
+ }),
740
+ }),
741
+ defineTool({
742
+ name: 'besales_behavior_update',
743
+ requiredFields: ['platform_id', 'updates'],
744
+ schema: z.object({
745
+ platform_id: uuidSchema,
746
+ updates: anyObjectSchema,
747
+ ...platformSetupConfirmationSchema,
748
+ }),
749
+ createRequest: (input) => ({
750
+ method: 'PATCH',
751
+ path: `/platforms/${input.platform_id}/agent-behavior`,
752
+ body: {
753
+ updates: input.updates,
754
+ ...setupConfirmation(input),
755
+ },
756
+ }),
757
+ }),
758
+ defineTool({
759
+ name: 'besales_followup_sequence_upsert',
760
+ requiredFields: ['platform_id', 'name', 'type', 'trigger', 'config'],
761
+ schema: z.object({
762
+ platform_id: uuidSchema,
763
+ sequence_id: uuidSchema.optional(),
764
+ name: z.string(),
765
+ description: z.string().nullable().optional(),
766
+ type: followUpSequenceTypeSchema,
767
+ enabled: z.boolean().optional(),
768
+ trigger: followUpTriggerSchema,
769
+ config: anyObjectSchema,
770
+ ...platformSetupConfirmationSchema,
771
+ }),
772
+ createRequest: (input) => ({
773
+ method: input.sequence_id ? 'PATCH' : 'POST',
774
+ path: input.sequence_id
775
+ ? `/platforms/${input.platform_id}/follow-up/sequences/${input.sequence_id}`
776
+ : `/platforms/${input.platform_id}/follow-up/sequences`,
777
+ body: compactObject({
778
+ name: input.name,
779
+ description: input.description,
780
+ type: input.type,
781
+ enabled: input.enabled,
782
+ trigger: input.trigger,
783
+ config: input.config,
784
+ ...setupConfirmation(input),
785
+ }),
786
+ }),
787
+ }),
788
+ defineTool({
789
+ name: 'besales_pipeline_settings_update',
790
+ requiredFields: ['platform_id', 'updates'],
791
+ schema: z.object({
792
+ platform_id: uuidSchema,
793
+ updates: anyObjectSchema,
794
+ ...platformSetupConfirmationSchema,
795
+ }),
796
+ createRequest: (input) => ({
797
+ method: 'PATCH',
798
+ path: `/platforms/${input.platform_id}/pipeline-settings`,
799
+ body: {
800
+ updates: input.updates,
801
+ ...setupConfirmation(input),
802
+ },
803
+ }),
804
+ }),
805
+ defineTool({
806
+ name: 'besales_platform_settings_update',
807
+ requiredFields: ['platform_id', 'settings'],
808
+ schema: z.object({
809
+ platform_id: uuidSchema,
810
+ settings: anyObjectSchema,
811
+ ...platformSetupConfirmationSchema,
812
+ }),
813
+ createRequest: (input) => ({
814
+ method: 'PATCH',
815
+ path: `/platforms/${input.platform_id}/settings`,
816
+ body: {
817
+ ...input.settings,
818
+ ...setupConfirmation(input),
819
+ },
820
+ }),
821
+ }),
822
+ defineTool({
823
+ name: 'besales_audit_revert',
824
+ requiredFields: ['platform_id', 'audit_log_id'],
825
+ schema: z.object({
826
+ platform_id: uuidSchema,
827
+ audit_log_id: uuidSchema,
828
+ }),
829
+ createRequest: (input) => ({
830
+ path: `/platforms/${input.platform_id}/audit/${input.audit_log_id}/revert`,
831
+ }),
832
+ }),
833
+ ];
834
+ function defineTool(definition) {
835
+ return definition;
836
+ }
837
+ function compactObject(value) {
838
+ return Object.fromEntries(Object.entries(value).filter(([, entryValue]) => entryValue !== undefined));
839
+ }
840
+ function setupConfirmation(input) {
841
+ return compactObject({
842
+ explicitConfirmation: input.explicit_confirmation,
843
+ confirmationReason: input.confirmation_reason,
844
+ });
845
+ }
846
+ function withInstructions(response, instructions) {
847
+ const text = instructions.join('\n');
848
+ if (response && typeof response === 'object' && !Array.isArray(response)) {
849
+ return {
850
+ ...response,
851
+ instructions: text,
852
+ };
853
+ }
854
+ return {
855
+ result: response,
856
+ instructions: text,
857
+ };
858
+ }
859
+ //# sourceMappingURL=definitions.js.map