@besales/mcp 0.1.0 → 0.11.1

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 (94) hide show
  1. package/README.md +272 -17
  2. package/dist/auth/connection-store.d.ts +58 -0
  3. package/dist/auth/connection-store.js +208 -0
  4. package/dist/auth/connection-store.js.map +1 -0
  5. package/dist/auth/oauth-client.d.ts +27 -2
  6. package/dist/auth/oauth-client.js +62 -11
  7. package/dist/auth/oauth-client.js.map +1 -1
  8. package/dist/auth/session-workspace.d.ts +2 -0
  9. package/dist/auth/session-workspace.js +20 -0
  10. package/dist/auth/session-workspace.js.map +1 -0
  11. package/dist/auth/token-storage.d.ts +19 -5
  12. package/dist/auth/token-storage.js +11 -6
  13. package/dist/auth/token-storage.js.map +1 -1
  14. package/dist/cli.d.ts +2 -7
  15. package/dist/cli.js +111 -33
  16. package/dist/cli.js.map +1 -1
  17. package/dist/http/api-client.d.ts +4 -13
  18. package/dist/http/api-client.js +18 -18
  19. package/dist/http/api-client.js.map +1 -1
  20. package/dist/index.d.ts +8 -6
  21. package/dist/index.js +3 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/instructions/server-instructions.d.ts +15 -0
  24. package/dist/instructions/server-instructions.js +243 -0
  25. package/dist/instructions/server-instructions.js.map +1 -0
  26. package/dist/package-metadata.js +7 -1
  27. package/dist/package-metadata.js.map +1 -1
  28. package/dist/resources/concepts/feedback-sheets.md +77 -0
  29. package/dist/resources/concepts/sandbox.md +13 -0
  30. package/dist/resources/concepts/workbook-classification.md +241 -0
  31. package/dist/resources/docs/agent-behavior.md +393 -0
  32. package/dist/resources/docs/crm-integration.md +535 -0
  33. package/dist/resources/docs/files-and-uploads.md +295 -0
  34. package/dist/resources/docs/knowledge-base.md +521 -0
  35. package/dist/resources/docs/pipeline-builder.md +221 -0
  36. package/dist/resources/docs/pipeline-settings-deep.md +221 -0
  37. package/dist/resources/docs/platforms.md +513 -0
  38. package/dist/resources/docs/prompt-anatomy.md +298 -0
  39. package/dist/resources/docs/prompt-principles.md +289 -0
  40. package/dist/resources/registry.js +34 -12
  41. package/dist/resources/registry.js.map +1 -1
  42. package/dist/resources/workflows/compare-models.md +46 -0
  43. package/dist/resources/workflows/connect-crm-from-scratch.md +89 -0
  44. package/dist/resources/workflows/connect-datasource-from-scratch.md +92 -0
  45. package/dist/resources/workflows/extract-from-document.md +36 -0
  46. package/dist/resources/workflows/iterate-with-sandbox.md +31 -0
  47. package/dist/resources/workflows/platform-setup-from-scratch.md +113 -0
  48. package/dist/resources/workflows/production-readiness-check.md +41 -0
  49. package/dist/schemas/mcp-tools.json +2636 -182
  50. package/dist/server.js +2 -0
  51. package/dist/server.js.map +1 -1
  52. package/dist/tools/definitions/agent-design.d.ts +215 -0
  53. package/dist/tools/definitions/agent-design.js +643 -0
  54. package/dist/tools/definitions/agent-design.js.map +1 -0
  55. package/dist/tools/definitions/crm-platform.d.ts +211 -0
  56. package/dist/tools/definitions/crm-platform.js +1070 -0
  57. package/dist/tools/definitions/crm-platform.js.map +1 -0
  58. package/dist/tools/definitions/datasource.d.ts +40 -0
  59. package/dist/tools/definitions/datasource.js +196 -0
  60. package/dist/tools/definitions/datasource.js.map +1 -0
  61. package/dist/tools/definitions/knowledge.d.ts +215 -0
  62. package/dist/tools/definitions/knowledge.js +782 -0
  63. package/dist/tools/definitions/knowledge.js.map +1 -0
  64. package/dist/tools/definitions/model-comparison.d.ts +25 -0
  65. package/dist/tools/definitions/model-comparison.js +101 -0
  66. package/dist/tools/definitions/model-comparison.js.map +1 -0
  67. package/dist/tools/definitions/platform-setup.d.ts +412 -0
  68. package/dist/tools/definitions/platform-setup.js +738 -0
  69. package/dist/tools/definitions/platform-setup.js.map +1 -0
  70. package/dist/tools/definitions/session.d.ts +11 -0
  71. package/dist/tools/definitions/session.js +86 -0
  72. package/dist/tools/definitions/session.js.map +1 -0
  73. package/dist/tools/definitions/shared.d.ts +742 -0
  74. package/dist/tools/definitions/shared.js +773 -0
  75. package/dist/tools/definitions/shared.js.map +1 -0
  76. package/dist/tools/definitions.d.ts +873 -88
  77. package/dist/tools/definitions.js +14 -856
  78. package/dist/tools/definitions.js.map +1 -1
  79. package/dist/tools/registry.d.ts +3 -1
  80. package/dist/tools/registry.js +90 -11
  81. package/dist/tools/registry.js.map +1 -1
  82. package/dist/tools/result.d.ts +1 -1
  83. package/dist/tools/result.js +12 -4
  84. package/dist/tools/result.js.map +1 -1
  85. package/dist/utils/logger.js +2 -1
  86. package/dist/utils/logger.js.map +1 -1
  87. package/docs/host-setup.md +34 -15
  88. package/package.json +2 -2
  89. package/scripts/install-claude-desktop.js +89 -11
  90. package/scripts/mock-api-server.js +1 -1
  91. package/scripts/mock-credentials.js +49 -6
  92. package/dist/types/api-contract.gen.d.ts +0 -6975
  93. package/dist/types/api-contract.gen.js +0 -6
  94. package/dist/types/api-contract.gen.js.map +0 -1
@@ -0,0 +1,773 @@
1
+ // Schemas, helpers, snake→camel mappers and the ToolDefinition contract
2
+ // shared by all definition modules. Split out of the former monolithic
3
+ // definitions.ts to keep each file under the 1200-line project limit.
4
+ import { z } from 'zod';
5
+ export const uuidSchema = z.string().uuid();
6
+ export const anyObjectSchema = z.object({}).passthrough();
7
+ export const optionalAnyObjectSchema = anyObjectSchema.optional();
8
+ export const outcomeSchema = z.enum(['won', 'lost', 'in_progress']);
9
+ export const platformSetupConfirmationSchema = {
10
+ explicit_confirmation: z.boolean().optional(),
11
+ confirmation_reason: z.string().optional(),
12
+ };
13
+ export const modelLaneSchema = z.enum(['CHEAP', 'STANDARD', 'DEEP']);
14
+ // v1.5 Increment 5a — file upload (Setup URL pattern)
15
+ export const MAX_FILE_UPLOAD_BYTES = 40 * 1024 * 1024;
16
+ export const storedFileTypeSchema = z.enum([
17
+ 'IMAGE',
18
+ 'DOCUMENT',
19
+ 'VIDEO',
20
+ 'AUDIO',
21
+ 'VOICE',
22
+ 'VIDEO_NOTE',
23
+ 'OTHER',
24
+ ]);
25
+ export const mcpFileSourceSchema = z.enum([
26
+ 'USER_UPLOAD',
27
+ 'AGENT_GREETING',
28
+ 'CAMPAIGN',
29
+ 'CRM_IMPORT',
30
+ 'OTHER',
31
+ ]);
32
+ // v1.5 Increment 5b — platform provisioning (API-key каналы; OAuth Instagram/Avito → Phase 2)
33
+ export const apiKeyPlatformTypeSchema = z.enum([
34
+ 'TelegramBot',
35
+ 'Wazzup',
36
+ 'Salebot',
37
+ 'SmsGorod',
38
+ 'VKon',
39
+ 'GetCourse',
40
+ 'WebWidget',
41
+ 'Bitrix24Bot',
42
+ ]);
43
+ // v1.5 Increment 5b Phase 2 — OAuth-каналы (авторизация в браузере, код мимо LLM).
44
+ export const oauthPlatformTypeSchema = z.enum(['Instagram', 'Avito']);
45
+ // v1.5 Increment 5c — CRM provisioning через Setup URL pattern (секреты в браузере).
46
+ // GETCOURSE/TELEGRAM — API-key; AMOCRM/BITRIX24 — вставка credentials (5c Phase 2, не OAuth-redirect).
47
+ export const provisionableCrmTypeSchema = z.enum(['GETCOURSE', 'TELEGRAM', 'AMOCRM', 'BITRIX24']);
48
+ export const fieldSpecialPurposeSchema = z.enum([
49
+ 'phone',
50
+ 'telegramId',
51
+ 'username',
52
+ 'avitoId',
53
+ 'instagramId',
54
+ 'vkonId',
55
+ ]);
56
+ export const crmFieldMappingItemSchema = z
57
+ .object({
58
+ crm_field_id: z.string().min(1),
59
+ crm_field_name: z.string().optional(),
60
+ save_as: z.string().min(1),
61
+ enabled: z.boolean(),
62
+ special_purpose: fieldSpecialPurposeSchema.optional(),
63
+ category: z.string().optional(),
64
+ })
65
+ .strict();
66
+ export const routingStrategySchema = z.enum(['LEAD_STATUS', 'CUSTOM_VARIABLE']);
67
+ export const triggerScopeSchema = z.enum(['ON_USER_MESSAGE']).optional();
68
+ export const followUpSequenceTypeSchema = z.enum([
69
+ 'MEETING_REMINDER',
70
+ 'INACTIVE_USER_REACTIVATION',
71
+ 'LOST_CLIENTS',
72
+ ]);
73
+ export const followUpTriggerSchema = z.enum([
74
+ 'USER_INACTIVITY',
75
+ 'DEAL_CLOSED',
76
+ 'BIRTHDAY_DATE',
77
+ 'MEETING_TIME',
78
+ 'CUSTOM_SCHEDULE',
79
+ 'LOST_CLIENTS',
80
+ ]);
81
+ export const analysisModeSchema = z.enum([
82
+ 'grammar',
83
+ 'structure',
84
+ 'industry',
85
+ 'contradictions',
86
+ 'completeness',
87
+ ]);
88
+ export const promptGenerationStageOutputSchema = z.object({
89
+ name: z.enum(['structure_builder', 'industry_validator', 'prompt_tester', 'finalizer']),
90
+ output: anyObjectSchema,
91
+ });
92
+ export const promptAnalysisStageOutputSchema = z.object({
93
+ name: z.enum(['grammar', 'industry', 'structure', 'aggregation']),
94
+ output: anyObjectSchema,
95
+ });
96
+ export const icpAnalysisSegmentSchema = z.object({
97
+ id: uuidSchema.optional(),
98
+ name: z.string(),
99
+ description: z.string().optional(),
100
+ demographics: optionalAnyObjectSchema,
101
+ pains: z.array(z.unknown()).optional(),
102
+ motivations: z.array(z.unknown()).optional(),
103
+ language_style: optionalAnyObjectSchema,
104
+ });
105
+ export const icpAnalysisPersonaSchema = z.object({
106
+ name: z.string(),
107
+ segment_id: uuidSchema,
108
+ description: z.string().optional(),
109
+ pain_points: z.array(z.unknown()).optional(),
110
+ goals: z.array(z.unknown()).optional(),
111
+ objections: optionalAnyObjectSchema,
112
+ messaging_hints: optionalAnyObjectSchema,
113
+ });
114
+ export const scenarioSituationSchema = z.object({
115
+ role: z.enum(['client', 'agent']),
116
+ text: z.string().min(1).max(4000),
117
+ });
118
+ export const generatedScenarioSchema = z
119
+ .object({
120
+ name: z.string().min(1).max(200),
121
+ description: z.string().max(1000).optional(),
122
+ // Accept both snake_case (MCP-native) и camelCase (JSON Schema от backend instructions)
123
+ // — Claude следует returned schema и часто использует camelCase.
124
+ segment_ids: z.array(uuidSchema).optional(),
125
+ segmentIds: z.array(uuidSchema).optional(),
126
+ situations: z.array(scenarioSituationSchema).min(1),
127
+ })
128
+ .transform(({ segment_ids, segmentIds, ...rest }) => ({
129
+ ...rest,
130
+ segment_ids: segment_ids ?? segmentIds,
131
+ }));
132
+ export const sandboxFindingSchema = z.object({
133
+ scenario_id: uuidSchema.optional(),
134
+ category: z.enum([
135
+ 'hallucination',
136
+ 'wrong_action',
137
+ 'wrong_routing',
138
+ 'missed_trigger',
139
+ 'wrong_pipeline_transition',
140
+ 'rag_miss',
141
+ 'bad_tone',
142
+ 'other',
143
+ ]),
144
+ severity: z.enum(['low', 'medium', 'critical']),
145
+ message: z.string(),
146
+ suggestion: z.string().optional(),
147
+ turn_index: z.number().int().optional(),
148
+ });
149
+ export const simulationFindingSchema = z.object({
150
+ dialogue_id: uuidSchema.optional(),
151
+ category: z.enum([
152
+ 'hallucination',
153
+ 'wrong_action',
154
+ 'bad_tone',
155
+ 'missed_context',
156
+ 'contradiction',
157
+ 'off_topic',
158
+ 'other',
159
+ ]),
160
+ severity: z.enum(['low', 'medium', 'critical']),
161
+ message: z.string(),
162
+ suggestion: z.string().optional(),
163
+ reference_message_index: z.number().int().optional(),
164
+ });
165
+ export const routingRuleLeadStatusSchema = z.object({
166
+ lead_status_name: z.string().nullable().optional(),
167
+ lead_status_pipeline_crm_id: z.string().nullable().optional(),
168
+ lead_status_pipeline_id: z.number().int().nullable().optional(),
169
+ lead_status_id: z.number().int().nullable().optional(),
170
+ });
171
+ export const agentToolPatchSchema = z.object({
172
+ tool_id: z.string(),
173
+ priority: z.number().int().min(1).max(100).optional(),
174
+ is_enabled: z.boolean().optional(),
175
+ agent_specific_conditions: anyObjectSchema.nullable().optional(),
176
+ });
177
+ export const feedbackSheetRowSchema = z.object({
178
+ row_number: z.number().int().min(2),
179
+ row_hash: z.string(),
180
+ status: z.enum(['done', 'in_progress', 'wont_fix', 'needs_clarification']),
181
+ comment: z.string().optional(),
182
+ });
183
+ // ============================================================
184
+ // v1.5 Increment 3 — typed schemas (Group B + C + A.5)
185
+ // ============================================================
186
+ export const agentRuntimeConfigSchema = z.object({
187
+ temperature: z.number().min(0).max(2).optional(),
188
+ max_tokens: z.number().int().min(1).optional(),
189
+ memory_history_size: z.number().int().min(1).optional(),
190
+ rag_top_k: z.number().int().min(1).max(50).optional(),
191
+ rag_min_score: z.number().min(0).max(1).optional(),
192
+ qa_min_score: z.number().min(0).max(1).optional(),
193
+ qa_context_limit: z.number().int().min(1).max(10).optional(),
194
+ max_response_symbols: z.number().int().min(1).optional(),
195
+ reasoning_effort: z.enum(['minimal', 'low', 'medium', 'high', 'max']).optional(),
196
+ verbosity: z.enum(['low', 'medium', 'high']).optional(),
197
+ enable_thinking: z.boolean().optional(),
198
+ timezone: z.string().optional(),
199
+ language_code: z.string().optional(),
200
+ summarize_every: z.number().int().min(1).optional(),
201
+ summary_max_size: z.number().int().min(1).optional(),
202
+ use_summary: z.boolean().optional(),
203
+ include_crm_fields_in_memory: z.boolean().optional(),
204
+ include_trigger_context: z.boolean().optional(),
205
+ });
206
+ export const agentButtonGeneratorSchema = z.object({
207
+ enabled: z.boolean().optional(),
208
+ max_buttons: z.number().int().min(1).max(10).optional(),
209
+ keyboard_type: z.enum(['INLINE', 'REPLY']).optional(),
210
+ dynamic: z.boolean().optional(),
211
+ });
212
+ export const agentOutputConfigSchema = z.object({
213
+ display_name: z.string().optional(),
214
+ button_generator: agentButtonGeneratorSchema.optional(),
215
+ });
216
+ export const agentScopeSchema = z.enum([
217
+ 'sale',
218
+ 'reactivation',
219
+ 'support',
220
+ 'onboarding',
221
+ 'faq',
222
+ 'qualification',
223
+ 'complaint',
224
+ 'other',
225
+ ]);
226
+ // Behavior typed sections (Group C.1)
227
+ export const behaviorGreetingButtonSchema = z.object({
228
+ id: z.string(),
229
+ label: z.string(),
230
+ text: z.string(),
231
+ order: z.number().int(),
232
+ });
233
+ export const behaviorGreetingSchema = z.object({
234
+ bot_greeting: z.string().optional(),
235
+ greeting_file_id: uuidSchema.nullable().optional(),
236
+ greeting_buttons: z.array(behaviorGreetingButtonSchema).optional(),
237
+ greeting_buttons_keyboard_type: z.enum(['INLINE', 'REPLY']).optional(),
238
+ popup_delay_seconds: z.number().int().min(0).optional(),
239
+ });
240
+ export const behaviorMediaHandlerSchema = z.object({
241
+ behavior: z.enum(['SILENT', 'PROCESS_WITH_LLM', 'FIXED_RESPONSE']),
242
+ fixed_response_text: z.string().optional(),
243
+ call_operator: z.boolean().optional(),
244
+ operator_comment: z.string().optional(),
245
+ });
246
+ export const behaviorMediaHandlingSchema = z.object({
247
+ image: behaviorMediaHandlerSchema.optional(),
248
+ video: behaviorMediaHandlerSchema.optional(),
249
+ audio: behaviorMediaHandlerSchema.optional(),
250
+ document: behaviorMediaHandlerSchema.optional(),
251
+ });
252
+ export const behaviorUrlHandlingSchema = z.object({
253
+ behavior: z.enum(['PASS_THROUGH', 'SILENT', 'FIXED_RESPONSE', 'PROCESS_WITH_CRAWLER']),
254
+ fixed_response_text: z.string().optional(),
255
+ call_operator: z.boolean().optional(),
256
+ operator_comment: z.string().optional(),
257
+ });
258
+ export const behaviorErrorHandlingSchema = z.object({
259
+ ai_error_behavior: z.enum(['SILENT', 'SEND_ERROR_MESSAGE']).optional(),
260
+ ai_error_custom_message: z.string().optional(),
261
+ call_operator_with_error: z.boolean().optional(),
262
+ ai_error_target_stage_id: z.number().int().nullable().optional(),
263
+ });
264
+ export const behaviorDayAvailabilitySchema = z.object({
265
+ active: z.boolean(),
266
+ start_time: z.string().optional(),
267
+ end_time: z.string().optional(),
268
+ });
269
+ export const behaviorWeekAvailabilitySchema = z.object({
270
+ monday: behaviorDayAvailabilitySchema.optional(),
271
+ tuesday: behaviorDayAvailabilitySchema.optional(),
272
+ wednesday: behaviorDayAvailabilitySchema.optional(),
273
+ thursday: behaviorDayAvailabilitySchema.optional(),
274
+ friday: behaviorDayAvailabilitySchema.optional(),
275
+ saturday: behaviorDayAvailabilitySchema.optional(),
276
+ sunday: behaviorDayAvailabilitySchema.optional(),
277
+ });
278
+ export const behaviorOperatorScheduleSchema = z.object({
279
+ enabled: z.boolean().optional(),
280
+ availability: behaviorWeekAvailabilitySchema.optional(),
281
+ unavailable_message: z.string().optional(),
282
+ bot_waiting_return_hours: z.union([
283
+ z.literal(0),
284
+ z.literal(1),
285
+ z.literal(3),
286
+ z.literal(6),
287
+ z.literal(12),
288
+ z.literal(24),
289
+ ]).optional(),
290
+ follow_up_waiting_return_hours: z.number().int().optional(),
291
+ skip_task_creation_on_call_operator: z.boolean().optional(),
292
+ });
293
+ export const behaviorTypingBehaviorSchema = z.object({
294
+ waiting_answer_time: z.number().int().min(0).optional(),
295
+ can_interrupt: z.boolean().optional(),
296
+ message_devide: z.boolean().optional(),
297
+ typing_speed: z.enum(['slow', 'medium', 'fast']).optional(),
298
+ fake_delay: z.number().int().min(0).optional(),
299
+ message_open_delay: z.number().int().min(0).optional(),
300
+ go_offline: z.string().optional(),
301
+ });
302
+ export const behaviorMessageFilterSchema = z.object({
303
+ id: z.string(),
304
+ source: z.string(),
305
+ target: z.string(),
306
+ enabled: z.boolean(),
307
+ order: z.number().int(),
308
+ });
309
+ export const behaviorMessageSplittingSchema = z.object({
310
+ message_chunk_separator: z.string().optional(),
311
+ });
312
+ export const behaviorPrivacySchema = z.object({
313
+ anonymization_enabled: z.boolean().optional(),
314
+ // Типы PII, выключенные из анонимизации (отдаются в LLM как есть).
315
+ // Например ["FIRST_NAME"] оставляет имя для склонения моделью.
316
+ anonymization_disabled_types: z
317
+ .array(z.enum([
318
+ 'FIRST_NAME',
319
+ 'LAST_NAME',
320
+ 'PATRONYMIC',
321
+ 'PERSON',
322
+ 'PHONE',
323
+ 'EMAIL',
324
+ 'INN',
325
+ 'PASSPORT',
326
+ 'CARD',
327
+ 'DATE_OF_BIRTH',
328
+ 'ACCOUNT',
329
+ 'SNILS',
330
+ 'OGRN',
331
+ 'OGRNIP',
332
+ 'SOCIAL_ID',
333
+ ]))
334
+ .optional(),
335
+ });
336
+ // Pipeline settings typed sections (Group C.3)
337
+ export const pipelineCrmBehaviorSchema = z.object({
338
+ active_pipeline_ids: z.array(z.string()).optional(),
339
+ filter_enabled: z.boolean().optional(),
340
+ status_movement: anyObjectSchema.optional(),
341
+ create_defaults: anyObjectSchema.optional(),
342
+ global: anyObjectSchema.optional(),
343
+ });
344
+ export const pipelineAutoFinishSchema = z.object({
345
+ finish_auto_noanswer: z.boolean().optional(),
346
+ finish_auto_timeout: z.boolean().optional(),
347
+ finish_auto_days: z.number().int().min(1).optional(),
348
+ send_finish_auto_note_to_crm: z.boolean().optional(),
349
+ finish_auto_note_template: z.string().nullable().optional(),
350
+ });
351
+ // Platform settings typed sections (Group C.2 + Increment 4c per-channel)
352
+ export const platformAccessControlSchema = z
353
+ .object({
354
+ is_active: z.boolean().optional(),
355
+ is_ai_enabled: z.boolean().optional(),
356
+ is_user_filter_enabled: z.boolean().optional(),
357
+ filtered_user_ids: z.array(z.string()).optional(),
358
+ // v1.5 Increment 4c — TelegramBot only (hard 400 на других)
359
+ enable_cleanup_commands: z.boolean().optional(),
360
+ })
361
+ .strict();
362
+ export const platformVariablesConfigSchema = z
363
+ .object({
364
+ enable_dynamic_variables: z.boolean().optional(),
365
+ clear_dynamic_vars_on_history_clear: z.boolean().optional(),
366
+ })
367
+ .strict();
368
+ export const platformCrmBehaviorSchema = z
369
+ .object({
370
+ send_to_crm: z.boolean().optional(),
371
+ use_cross_platform_history: z.boolean().optional(),
372
+ responsible_assignee_strategy: z
373
+ .enum(['ROUND_ROBIN', 'LEAST_BUSY', 'RANDOM', 'FIXED', 'OPERATOR_SPECIFIC'])
374
+ .optional(),
375
+ fixed_responsible_id: z.string().nullable().optional(),
376
+ send_start_note_to_crm: z.boolean().optional(),
377
+ start_note_template: z.string().nullable().optional(),
378
+ send_failed_note_to_crm: z.boolean().optional(),
379
+ failed_note_template: z.string().nullable().optional(),
380
+ send_operator_takeover_note_to_crm: z.boolean().optional(),
381
+ operator_takeover_note_template: z.string().nullable().optional(),
382
+ // v1.5 Increment 4c — deal marker (любой CRM-aware channel)
383
+ deal_marker_type: z.enum(['NONE', 'TAG', 'CUSTOM_FIELD']).optional(),
384
+ deal_marker_value: z.string().nullable().optional(),
385
+ deal_marker_field_id: z.string().nullable().optional(),
386
+ })
387
+ .strict();
388
+ export const platformWidgetMarketingSchema = z
389
+ .object({
390
+ web_widget_allowed_origins: anyObjectSchema.nullable().optional(),
391
+ web_widget_show_page_info: z.boolean().optional(),
392
+ web_widget_rate_limit_per_minute: z.number().int().min(1).max(600).optional(),
393
+ web_widget_customization: anyObjectSchema.nullable().optional(),
394
+ web_widget_marketing_field_mappings: anyObjectSchema.nullable().optional(),
395
+ web_widget_entry_url_variable_mapping: anyObjectSchema.nullable().optional(),
396
+ })
397
+ .strict();
398
+ export const platformInstagramCommentSchema = z
399
+ .object({
400
+ reply_to_instagram_comments: z.boolean().optional(),
401
+ instagram_comment_handling_mode: z.string().nullable().optional(),
402
+ instagram_comment_reply_method: z.string().nullable().optional(),
403
+ instagram_comment_keywords: anyObjectSchema.nullable().optional(),
404
+ reply_to_story_mentions: z.boolean().optional(),
405
+ })
406
+ .strict();
407
+ // v1.5 Increment 4c — per-channel typed sections
408
+ export const platformGeneralSettingsSchema = z
409
+ .object({
410
+ name: z.string().nullable().optional(),
411
+ off_message: z.string().nullable().optional(),
412
+ timezone: z.string().optional(),
413
+ is_active: z.boolean().optional(),
414
+ })
415
+ .strict();
416
+ export const platformSalebotSettingsSchema = z
417
+ .object({
418
+ project_id: z.string().nullable().optional(),
419
+ group_id: z.string().nullable().optional(),
420
+ })
421
+ .strict();
422
+ export const platformSmsgorodSettingsSchema = z
423
+ .object({
424
+ channel: z.enum(['DIGIT', 'CHAR']).optional(),
425
+ sender: z.string().nullable().optional(),
426
+ })
427
+ .strict();
428
+ export const platformBitrix24BotSettingsSchema = z
429
+ .object({
430
+ bot_id: z.number().int().nullable().optional(),
431
+ bot_code: z.string().nullable().optional(),
432
+ bot_name: z.string().optional(),
433
+ open_line_id: z.string().nullable().optional(),
434
+ })
435
+ .strict();
436
+ export const getcourseTransportEnum = z.enum([
437
+ 'Site',
438
+ 'Email',
439
+ 'SMS',
440
+ 'Telegram',
441
+ 'Facebook',
442
+ 'VK',
443
+ 'Chatium',
444
+ 'WhatsApp',
445
+ 'Viber',
446
+ ]);
447
+ export const platformGetcourseDepartmentSchema = z
448
+ .object({
449
+ id: z.string(),
450
+ label: z.string(),
451
+ })
452
+ .strict();
453
+ export const platformGetcourseSettingsSchema = z
454
+ .object({
455
+ account_domain: z.string().nullable().optional(),
456
+ employee_user_id: z.number().int().nullable().optional(),
457
+ available_transports: z.array(getcourseTransportEnum).optional(),
458
+ default_transport: getcourseTransportEnum.nullable().optional(),
459
+ departments: z.array(platformGetcourseDepartmentSchema).nullable().optional(),
460
+ template_user_id: z.number().int().nullable().optional(),
461
+ template_deal_id: z.number().int().nullable().optional(),
462
+ })
463
+ .strict();
464
+ // Knowledge tables (Group A.5)
465
+ export const knowledgeTableSourceSchema = z.object({
466
+ kind: z.enum(['GOOGLE_SHEETS', 'NATIVE']),
467
+ spreadsheet_url: z.string().optional(),
468
+ table_schema: anyObjectSchema.optional(),
469
+ });
470
+ export function defineTool(definition) {
471
+ return definition;
472
+ }
473
+ export function compactObject(value) {
474
+ return Object.fromEntries(Object.entries(value).filter(([, entryValue]) => entryValue !== undefined));
475
+ }
476
+ export function compactMetadata(metadata) {
477
+ if (!metadata) {
478
+ return undefined;
479
+ }
480
+ const compacted = compactObject({
481
+ totalTokens: metadata.total_tokens,
482
+ models: metadata.models,
483
+ });
484
+ return Object.keys(compacted).length === 0 ? undefined : compacted;
485
+ }
486
+ export function setupConfirmation(input) {
487
+ return compactObject({
488
+ explicitConfirmation: input.explicit_confirmation,
489
+ confirmationReason: input.confirmation_reason,
490
+ });
491
+ }
492
+ export function withInstructions(response, instructions) {
493
+ const text = instructions.join('\n');
494
+ if (response && typeof response === 'object' && !Array.isArray(response)) {
495
+ return {
496
+ ...response,
497
+ instructions: text,
498
+ };
499
+ }
500
+ return {
501
+ result: response,
502
+ instructions: text,
503
+ };
504
+ }
505
+ export function buildKnowledgeSpaceListQuery(scopeType, channelId) {
506
+ const params = new URLSearchParams();
507
+ if (scopeType)
508
+ params.set('scope_type', scopeType);
509
+ if (channelId)
510
+ params.set('channel_id', channelId);
511
+ const query = params.toString();
512
+ return query.length > 0 ? `?${query}` : '';
513
+ }
514
+ export function buildListQuery(params) {
515
+ const search = new URLSearchParams();
516
+ for (const [key, value] of Object.entries(params)) {
517
+ if (value !== undefined) {
518
+ search.set(key, String(value));
519
+ }
520
+ }
521
+ const query = search.toString();
522
+ return query.length > 0 ? `?${query}` : '';
523
+ }
524
+ export function buildVariableListQuery(scope, platformId, filter) {
525
+ const params = new URLSearchParams();
526
+ params.set('scope', scope);
527
+ if (platformId) {
528
+ params.set('platformId', platformId);
529
+ }
530
+ if (filter) {
531
+ params.set('filter', filter);
532
+ }
533
+ const queryString = params.toString();
534
+ return queryString ? `?${queryString}` : '';
535
+ }
536
+ export function buildVariableScopeQuery(scope, platformId) {
537
+ const params = new URLSearchParams();
538
+ params.set('scope', scope);
539
+ if (platformId) {
540
+ params.set('platformId', platformId);
541
+ }
542
+ return `?${params.toString()}`;
543
+ }
544
+ export function buildFileListQuery(input) {
545
+ const params = new URLSearchParams();
546
+ if (input.file_type)
547
+ params.set('file_type', input.file_type);
548
+ if (input.source)
549
+ params.set('source', input.source);
550
+ if (input.section_id !== undefined)
551
+ params.set('section_id', input.section_id);
552
+ if (input.limit !== undefined)
553
+ params.set('limit', String(input.limit));
554
+ if (input.offset !== undefined)
555
+ params.set('offset', String(input.offset));
556
+ const queryString = params.toString();
557
+ return queryString ? `?${queryString}` : '';
558
+ }
559
+ // ============================================================
560
+ // v1.5 Increment 3 — snake_case → camelCase input mappers
561
+ // ============================================================
562
+ export function mapRuntimeConfigInput(input) {
563
+ return compactObject({
564
+ temperature: input.temperature,
565
+ maxTokens: input.max_tokens,
566
+ memoryHistorySize: input.memory_history_size,
567
+ ragTopK: input.rag_top_k,
568
+ ragMinScore: input.rag_min_score,
569
+ qaMinScore: input.qa_min_score,
570
+ qaContextLimit: input.qa_context_limit,
571
+ maxResponseSymbols: input.max_response_symbols,
572
+ reasoningEffort: input.reasoning_effort,
573
+ verbosity: input.verbosity,
574
+ enableThinking: input.enable_thinking,
575
+ timezone: input.timezone,
576
+ languageCode: input.language_code,
577
+ summarizeEvery: input.summarize_every,
578
+ summaryMaxSize: input.summary_max_size,
579
+ useSummary: input.use_summary,
580
+ includeCrmFieldsInMemory: input.include_crm_fields_in_memory,
581
+ includeTriggerContext: input.include_trigger_context,
582
+ });
583
+ }
584
+ export function mapOutputConfigInput(input) {
585
+ const buttonGenerator = input.button_generator;
586
+ return compactObject({
587
+ displayName: input.display_name,
588
+ buttonGenerator: buttonGenerator
589
+ ? compactObject({
590
+ enabled: buttonGenerator.enabled,
591
+ maxButtons: buttonGenerator.max_buttons,
592
+ keyboardType: buttonGenerator.keyboard_type,
593
+ dynamic: buttonGenerator.dynamic,
594
+ })
595
+ : undefined,
596
+ });
597
+ }
598
+ export function mapBehaviorGreetingInput(input) {
599
+ return compactObject({
600
+ botGreeting: input.bot_greeting,
601
+ greetingFileId: input.greeting_file_id,
602
+ greetingButtons: input.greeting_buttons,
603
+ greetingButtonsKeyboardType: input.greeting_buttons_keyboard_type,
604
+ popupDelaySeconds: input.popup_delay_seconds,
605
+ });
606
+ }
607
+ export function mapMediaHandlerInput(input) {
608
+ if (!input)
609
+ return undefined;
610
+ return compactObject({
611
+ behavior: input.behavior,
612
+ fixedResponseText: input.fixed_response_text,
613
+ callOperator: input.call_operator,
614
+ operatorComment: input.operator_comment,
615
+ });
616
+ }
617
+ export function mapBehaviorMediaHandlingInput(input) {
618
+ return compactObject({
619
+ image: mapMediaHandlerInput(input.image),
620
+ video: mapMediaHandlerInput(input.video),
621
+ audio: mapMediaHandlerInput(input.audio),
622
+ document: mapMediaHandlerInput(input.document),
623
+ });
624
+ }
625
+ export function mapBehaviorUrlHandlingInput(input) {
626
+ return compactObject({
627
+ behavior: input.behavior,
628
+ fixedResponseText: input.fixed_response_text,
629
+ callOperator: input.call_operator,
630
+ operatorComment: input.operator_comment,
631
+ });
632
+ }
633
+ export function mapBehaviorErrorHandlingInput(input) {
634
+ return compactObject({
635
+ aiErrorBehavior: input.ai_error_behavior,
636
+ aiErrorCustomMessage: input.ai_error_custom_message,
637
+ callOperatorWithError: input.call_operator_with_error,
638
+ aiErrorTargetStageId: input.ai_error_target_stage_id,
639
+ });
640
+ }
641
+ export function mapBehaviorOperatorScheduleInput(input) {
642
+ return compactObject({
643
+ enabled: input.enabled,
644
+ availability: input.availability,
645
+ unavailableMessage: input.unavailable_message,
646
+ botWaitingReturnHours: input.bot_waiting_return_hours,
647
+ followUpWaitingReturnHours: input.follow_up_waiting_return_hours,
648
+ skipTaskCreationOnCallOperator: input.skip_task_creation_on_call_operator,
649
+ });
650
+ }
651
+ export function mapBehaviorTypingInput(input) {
652
+ return compactObject({
653
+ waitingAnswerTime: input.waiting_answer_time,
654
+ canInterrupt: input.can_interrupt,
655
+ messageDevide: input.message_devide,
656
+ typingSpeed: input.typing_speed,
657
+ fakeDelay: input.fake_delay,
658
+ messageOpenDelay: input.message_open_delay,
659
+ goOffline: input.go_offline,
660
+ });
661
+ }
662
+ export function mapPipelineCrmBehaviorInput(input) {
663
+ return compactObject({
664
+ activePipelineIds: input.active_pipeline_ids,
665
+ filterEnabled: input.filter_enabled,
666
+ statusMovement: input.status_movement,
667
+ createDefaults: input.create_defaults,
668
+ global: input.global,
669
+ });
670
+ }
671
+ export function mapPipelineAutoFinishInput(input) {
672
+ return compactObject({
673
+ finishAutoNoanswer: input.finish_auto_noanswer,
674
+ finishAutoTimeout: input.finish_auto_timeout,
675
+ finishAutoDays: input.finish_auto_days,
676
+ sendFinishAutoNoteToCrm: input.send_finish_auto_note_to_crm,
677
+ finishAutoNoteTemplate: input.finish_auto_note_template,
678
+ });
679
+ }
680
+ export function mapPlatformAccessControlInput(input) {
681
+ return compactObject({
682
+ isActive: input.is_active,
683
+ isAiEnabled: input.is_ai_enabled,
684
+ isUserFilterEnabled: input.is_user_filter_enabled,
685
+ filteredUserIds: input.filtered_user_ids,
686
+ // v1.5 Increment 4c
687
+ enableCleanupCommands: input.enable_cleanup_commands,
688
+ });
689
+ }
690
+ export function mapPlatformVariablesConfigInput(input) {
691
+ return compactObject({
692
+ enableDynamicVariables: input.enable_dynamic_variables,
693
+ clearDynamicVarsOnHistoryClear: input.clear_dynamic_vars_on_history_clear,
694
+ });
695
+ }
696
+ export function mapPlatformCrmBehaviorInput(input) {
697
+ return compactObject({
698
+ sendToCrm: input.send_to_crm,
699
+ useCrossPlatformHistory: input.use_cross_platform_history,
700
+ responsibleAssigneeStrategy: input.responsible_assignee_strategy,
701
+ fixedResponsibleId: input.fixed_responsible_id,
702
+ sendStartNoteToCrm: input.send_start_note_to_crm,
703
+ startNoteTemplate: input.start_note_template,
704
+ sendFailedNoteToCrm: input.send_failed_note_to_crm,
705
+ failedNoteTemplate: input.failed_note_template,
706
+ sendOperatorTakeoverNoteToCrm: input.send_operator_takeover_note_to_crm,
707
+ operatorTakeoverNoteTemplate: input.operator_takeover_note_template,
708
+ // v1.5 Increment 4c — deal marker
709
+ dealMarkerType: input.deal_marker_type,
710
+ dealMarkerValue: input.deal_marker_value,
711
+ dealMarkerFieldId: input.deal_marker_field_id,
712
+ });
713
+ }
714
+ export function mapPlatformWidgetMarketingInput(input) {
715
+ return compactObject({
716
+ webWidgetAllowedOrigins: input.web_widget_allowed_origins,
717
+ webWidgetShowPageInfo: input.web_widget_show_page_info,
718
+ webWidgetRateLimitPerMinute: input.web_widget_rate_limit_per_minute,
719
+ webWidgetCustomization: input.web_widget_customization,
720
+ webWidgetMarketingFieldMappings: input.web_widget_marketing_field_mappings,
721
+ webWidgetEntryUrlVariableMapping: input.web_widget_entry_url_variable_mapping,
722
+ });
723
+ }
724
+ export function mapPlatformInstagramCommentInput(input) {
725
+ return compactObject({
726
+ replyToInstagramComments: input.reply_to_instagram_comments,
727
+ instagramCommentHandlingMode: input.instagram_comment_handling_mode,
728
+ instagramCommentReplyMethod: input.instagram_comment_reply_method,
729
+ instagramCommentKeywords: input.instagram_comment_keywords,
730
+ replyToStoryMentions: input.reply_to_story_mentions,
731
+ });
732
+ }
733
+ // v1.5 Increment 4c — per-channel typed section mappers
734
+ export function mapPlatformGeneralSettingsInput(input) {
735
+ return compactObject({
736
+ name: input.name,
737
+ offMessage: input.off_message,
738
+ timezone: input.timezone,
739
+ isActive: input.is_active,
740
+ });
741
+ }
742
+ export function mapPlatformSalebotSettingsInput(input) {
743
+ return compactObject({
744
+ projectId: input.project_id,
745
+ groupId: input.group_id,
746
+ });
747
+ }
748
+ export function mapPlatformSmsgorodSettingsInput(input) {
749
+ return compactObject({
750
+ channel: input.channel,
751
+ sender: input.sender,
752
+ });
753
+ }
754
+ export function mapPlatformBitrix24BotSettingsInput(input) {
755
+ return compactObject({
756
+ botId: input.bot_id,
757
+ botCode: input.bot_code,
758
+ botName: input.bot_name,
759
+ openLineId: input.open_line_id,
760
+ });
761
+ }
762
+ export function mapPlatformGetcourseSettingsInput(input) {
763
+ return compactObject({
764
+ accountDomain: input.account_domain,
765
+ employeeUserId: input.employee_user_id,
766
+ availableTransports: input.available_transports,
767
+ defaultTransport: input.default_transport,
768
+ departments: input.departments,
769
+ templateUserId: input.template_user_id,
770
+ templateDealId: input.template_deal_id,
771
+ });
772
+ }
773
+ //# sourceMappingURL=shared.js.map