@botonic/plugin-flow-builder 0.57.0-rslib-esm.2 → 0.58.0-alpha-new-stack.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 (93) hide show
  1. package/lib/action/ai-agent-from-user-input.js +8 -0
  2. package/lib/action/ai-agent-from-user-input.js.map +1 -1
  3. package/lib/action/first-interaction.js +10 -0
  4. package/lib/action/first-interaction.js.map +1 -1
  5. package/lib/action/get-contents.js +5 -2
  6. package/lib/action/get-contents.js.map +1 -1
  7. package/lib/action/index.js +8 -1
  8. package/lib/action/index.js.map +1 -1
  9. package/lib/api.d.ts +8 -3
  10. package/lib/api.js +37 -13
  11. package/lib/api.js.map +1 -1
  12. package/lib/bot-context-manager.d.ts +17 -0
  13. package/lib/bot-context-manager.js +101 -0
  14. package/lib/bot-context-manager.js.map +1 -0
  15. package/lib/constants.d.ts +2 -1
  16. package/lib/constants.js +4 -3
  17. package/lib/constants.js.map +1 -1
  18. package/lib/content-fields/contact-reasons-conditional-matcher.d.ts +4 -0
  19. package/lib/content-fields/contact-reasons-conditional-matcher.js +10 -0
  20. package/lib/content-fields/contact-reasons-conditional-matcher.js.map +1 -0
  21. package/lib/content-fields/flow-ai-agent-base.js +1 -1
  22. package/lib/content-fields/flow-ai-agent-base.js.map +1 -1
  23. package/lib/content-fields/flow-ai-agent-router.js +2 -1
  24. package/lib/content-fields/flow-ai-agent-router.js.map +1 -1
  25. package/lib/content-fields/flow-ai-agent.js +2 -1
  26. package/lib/content-fields/flow-ai-agent.js.map +1 -1
  27. package/lib/content-fields/flow-contact-reasons-conditional.d.ts +14 -0
  28. package/lib/content-fields/flow-contact-reasons-conditional.js +68 -0
  29. package/lib/content-fields/flow-contact-reasons-conditional.js.map +1 -0
  30. package/lib/content-fields/flow-do-nothing.d.ts +9 -0
  31. package/lib/content-fields/flow-do-nothing.js +33 -0
  32. package/lib/content-fields/flow-do-nothing.js.map +1 -0
  33. package/lib/content-fields/flow-handoff.d.ts +7 -1
  34. package/lib/content-fields/flow-handoff.js +41 -3
  35. package/lib/content-fields/flow-handoff.js.map +1 -1
  36. package/lib/content-fields/flow-whatsapp-request-contact-info.js +1 -0
  37. package/lib/content-fields/flow-whatsapp-request-contact-info.js.map +1 -1
  38. package/lib/content-fields/hubtype-fields/contact-reasons-conditional.d.ts +16 -0
  39. package/lib/content-fields/hubtype-fields/contact-reasons-conditional.js +4 -0
  40. package/lib/content-fields/hubtype-fields/contact-reasons-conditional.js.map +1 -0
  41. package/lib/content-fields/hubtype-fields/do-nothing.d.ts +6 -0
  42. package/lib/content-fields/hubtype-fields/do-nothing.js +4 -0
  43. package/lib/content-fields/hubtype-fields/do-nothing.js.map +1 -0
  44. package/lib/content-fields/hubtype-fields/handoff.d.ts +11 -1
  45. package/lib/content-fields/hubtype-fields/handoff.js +7 -1
  46. package/lib/content-fields/hubtype-fields/handoff.js.map +1 -1
  47. package/lib/content-fields/hubtype-fields/index.d.ts +1 -0
  48. package/lib/content-fields/hubtype-fields/index.js +2 -0
  49. package/lib/content-fields/hubtype-fields/index.js.map +1 -1
  50. package/lib/content-fields/hubtype-fields/node-types.d.ts +3 -1
  51. package/lib/content-fields/hubtype-fields/node-types.js +2 -0
  52. package/lib/content-fields/hubtype-fields/node-types.js.map +1 -1
  53. package/lib/content-fields/hubtype-fields/nodes.d.ts +3 -1
  54. package/lib/content-fields/hubtype-fields/nodes.js.map +1 -1
  55. package/lib/content-fields/hubtype-fields/whatsapp-request-contact-info.d.ts +2 -0
  56. package/lib/content-fields/hubtype-fields/whatsapp-request-contact-info.js.map +1 -1
  57. package/lib/content-fields/index.d.ts +4 -2
  58. package/lib/content-fields/index.js +6 -0
  59. package/lib/content-fields/index.js.map +1 -1
  60. package/lib/flow-factory.js +5 -1
  61. package/lib/flow-factory.js.map +1 -1
  62. package/lib/index.d.ts +5 -8
  63. package/lib/index.js +17 -55
  64. package/lib/index.js.map +1 -1
  65. package/lib/types.d.ts +2 -2
  66. package/lib/types.js.map +1 -1
  67. package/package.json +3 -3
  68. package/src/action/ai-agent-from-user-input.ts +7 -0
  69. package/src/action/first-interaction.ts +6 -0
  70. package/src/action/get-contents.ts +17 -2
  71. package/src/action/index.tsx +7 -0
  72. package/src/api.ts +52 -15
  73. package/src/bot-context-manager.ts +153 -0
  74. package/src/constants.ts +2 -1
  75. package/src/content-fields/contact-reasons-conditional-matcher.ts +24 -0
  76. package/src/content-fields/flow-ai-agent-base.tsx +1 -1
  77. package/src/content-fields/flow-ai-agent-router.tsx +1 -0
  78. package/src/content-fields/flow-ai-agent.tsx +1 -0
  79. package/src/content-fields/flow-contact-reasons-conditional.tsx +90 -0
  80. package/src/content-fields/flow-do-nothing.tsx +29 -0
  81. package/src/content-fields/flow-handoff.tsx +54 -7
  82. package/src/content-fields/flow-whatsapp-request-contact-info.tsx +2 -0
  83. package/src/content-fields/hubtype-fields/contact-reasons-conditional.ts +18 -0
  84. package/src/content-fields/hubtype-fields/do-nothing.ts +7 -0
  85. package/src/content-fields/hubtype-fields/handoff.ts +17 -1
  86. package/src/content-fields/hubtype-fields/index.ts +1 -0
  87. package/src/content-fields/hubtype-fields/node-types.ts +2 -0
  88. package/src/content-fields/hubtype-fields/nodes.ts +4 -0
  89. package/src/content-fields/hubtype-fields/whatsapp-request-contact-info.ts +2 -0
  90. package/src/content-fields/index.ts +6 -0
  91. package/src/flow-factory.ts +11 -0
  92. package/src/index.ts +26 -88
  93. package/src/types.ts +1 -2
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const FLOW_BUILDER_API_URL_PROD =\n process.env.HUBTYPE_API_URL || 'https://api.hubtype.com'\nexport const SEPARATOR = '|'\nexport const SOURCE_INFO_SEPARATOR = `${SEPARATOR}source_`\nexport const EMPTY_PAYLOAD = 'fb-empty-payload'\nexport const VARIABLE_PATTERN_GLOBAL = /{([^{}]+)}/g\nexport const ACCESS_TOKEN_VARIABLE_KEY = '_access_token'\nexport const REG_EXP_PATTERN = /^\\/(.*)\\/([gimyus]*)$/\nexport const UUID_REGEXP =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\n/* ********** PAYLOADS ********** */\nexport const AGENT_RATING_PAYLOAD = 'agent-rating'\nexport const PUSH_FLOW_PAYLOAD = 'push-flow'\n\n/* ********** FLOW NAMES ********** */\nexport const MAIN_FLOW_NAME = 'Main'\nexport const AI_AGENTS_FLOW_NAME = 'AI Agents'\nexport const FALLBACK_FLOW_NAME = 'Fallback'\n"],"names":["FLOW_BUILDER_API_URL_PROD","process","SEPARATOR","SOURCE_INFO_SEPARATOR","EMPTY_PAYLOAD","VARIABLE_PATTERN_GLOBAL","ACCESS_TOKEN_VARIABLE_KEY","REG_EXP_PATTERN","UUID_REGEXP","AGENT_RATING_PAYLOAD","PUSH_FLOW_PAYLOAD","MAIN_FLOW_NAME","AI_AGENTS_FLOW_NAME","FALLBACK_FLOW_NAME"],"mappings":"AAAO,MAAMA,yBAAyBA,GACpCC,QAAQ,GAAG,CAAC,eAAe,IAAI,0BAAyB;AACnD,MAAMC,SAASA,GAAG,IAAG;AACrB,MAAMC,qBAAqBA,GAAG,GAAGD,SAASA,CAAC,OAAO,CAAC;AACnD,MAAME,aAAaA,GAAG,mBAAkB;AACxC,MAAMC,uBAAuBA,GAAG,cAAa;AAC7C,MAAMC,yBAAyBA,GAAG,gBAAe;AACjD,MAAMC,eAAeA,GAAG,wBAAuB;AAC/C,MAAMC,WAAWA,GACtB,kEAAiE;AAEnE,kCAAkC,GAC3B,MAAMC,oBAAoBA,GAAG,eAAc;AAC3C,MAAMC,iBAAiBA,GAAG,YAAW;AAE5C,oCAAoC,GAC7B,MAAMC,cAAcA,GAAG,OAAM;AAC7B,MAAMC,mBAAmBA,GAAG,YAAW;AACvC,MAAMC,kBAAkBA,GAAG,WAAU"}
1
+ {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const FLOW_BUILDER_API_URL_PROD =\n process.env.HUBTYPE_API_URL || 'https://api.hubtype.com'\nexport const SEPARATOR = '|'\nexport const SOURCE_INFO_SEPARATOR = `${SEPARATOR}source_`\nexport const VARIABLE_PATTERN_GLOBAL = /{([^{}]+)}/g\nexport const ACCESS_TOKEN_VARIABLE_KEY = '_access_token'\nexport const REG_EXP_PATTERN = /^\\/(.*)\\/([gimyus]*)$/\nexport const UUID_REGEXP =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\n/* ********** PAYLOADS ********** */\nexport const EMPTY_PAYLOAD = 'fb-empty-payload'\nexport const ON_CLOSE_HANDOFF_PAYLOAD = 'fb-on-close-handoff'\nexport const AGENT_RATING_PAYLOAD = 'agent-rating'\nexport const PUSH_FLOW_PAYLOAD = 'push-flow'\n\n/* ********** FLOW NAMES ********** */\nexport const MAIN_FLOW_NAME = 'Main'\nexport const AI_AGENTS_FLOW_NAME = 'AI Agents'\nexport const FALLBACK_FLOW_NAME = 'Fallback'\n"],"names":["FLOW_BUILDER_API_URL_PROD","process","SEPARATOR","SOURCE_INFO_SEPARATOR","VARIABLE_PATTERN_GLOBAL","ACCESS_TOKEN_VARIABLE_KEY","REG_EXP_PATTERN","UUID_REGEXP","EMPTY_PAYLOAD","ON_CLOSE_HANDOFF_PAYLOAD","AGENT_RATING_PAYLOAD","PUSH_FLOW_PAYLOAD","MAIN_FLOW_NAME","AI_AGENTS_FLOW_NAME","FALLBACK_FLOW_NAME"],"mappings":"AAAO,MAAMA,yBAAyBA,GACpCC,QAAQ,GAAG,CAAC,eAAe,IAAI,0BAAyB;AACnD,MAAMC,SAASA,GAAG,IAAG;AACrB,MAAMC,qBAAqBA,GAAG,GAAGD,SAASA,CAAC,OAAO,CAAC;AACnD,MAAME,uBAAuBA,GAAG,cAAa;AAC7C,MAAMC,yBAAyBA,GAAG,gBAAe;AACjD,MAAMC,eAAeA,GAAG,wBAAuB;AAC/C,MAAMC,WAAWA,GACtB,kEAAiE;AAEnE,kCAAkC,GAC3B,MAAMC,aAAaA,GAAG,mBAAkB;AACxC,MAAMC,wBAAwBA,GAAG,sBAAqB;AACtD,MAAMC,oBAAoBA,GAAG,eAAc;AAC3C,MAAMC,iBAAiBA,GAAG,YAAW;AAE5C,oCAAoC,GAC7B,MAAMC,cAAcA,GAAG,OAAM;AAC7B,MAAMC,mBAAmBA,GAAG,YAAW;AACvC,MAAMC,kBAAkBA,GAAG,WAAU"}
@@ -0,0 +1,4 @@
1
+ import type { HubtypeCaseContactReason } from '@botonic/core';
2
+ import type { HtContactReasonBranch } from './hubtype-fields/contact-reasons-conditional.js';
3
+ export declare function contactReasonMatchesBranch(sessionContactReason: HubtypeCaseContactReason, branch: HtContactReasonBranch): boolean;
4
+ export declare function findMatchingContactReasonBranch(sessionContactReasons: HubtypeCaseContactReason[], contactReasonBranches: HtContactReasonBranch[]): HtContactReasonBranch | undefined;
@@ -0,0 +1,10 @@
1
+ function contactReasonMatchesBranch(sessionContactReason, branch) {
2
+ return sessionContactReason.project_id === branch.project_id && sessionContactReason.name === branch.name;
3
+ }
4
+ function findMatchingContactReasonBranch(sessionContactReasons, contactReasonBranches) {
5
+ return contactReasonBranches.find((branch)=>sessionContactReasons.some((sessionContactReason)=>contactReasonMatchesBranch(sessionContactReason, branch)));
6
+ }
7
+
8
+ export { contactReasonMatchesBranch, findMatchingContactReasonBranch };
9
+
10
+ //# sourceMappingURL=contact-reasons-conditional-matcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-fields/contact-reasons-conditional-matcher.js","sources":["../../src/content-fields/contact-reasons-conditional-matcher.ts"],"sourcesContent":["import type { HubtypeCaseContactReason } from '@botonic/core'\n\nimport type { HtContactReasonBranch } from './hubtype-fields/contact-reasons-conditional'\n\nexport function contactReasonMatchesBranch(\n sessionContactReason: HubtypeCaseContactReason,\n branch: HtContactReasonBranch\n): boolean {\n return (\n sessionContactReason.project_id === branch.project_id &&\n sessionContactReason.name === branch.name\n )\n}\n\nexport function findMatchingContactReasonBranch(\n sessionContactReasons: HubtypeCaseContactReason[],\n contactReasonBranches: HtContactReasonBranch[]\n): HtContactReasonBranch | undefined {\n return contactReasonBranches.find(branch =>\n sessionContactReasons.some(sessionContactReason =>\n contactReasonMatchesBranch(sessionContactReason, branch)\n )\n )\n}\n"],"names":["contactReasonMatchesBranch","sessionContactReason","branch","findMatchingContactReasonBranch","sessionContactReasons","contactReasonBranches"],"mappings":"AAIO,SAASA,0BAA0BA,CACxCC,oBAA8C,EAC9CC,MAA6B;IAE7B,OACED,qBAAqB,UAAU,KAAKC,OAAO,UAAU,IACrDD,qBAAqB,IAAI,KAAKC,OAAO,IAAI;AAE7C;AAEO,SAASC,+BAA+BA,CAC7CC,qBAAiD,EACjDC,qBAA8C;IAE9C,OAAOA,sBAAsB,IAAI,CAACH,CAAAA,SAChCE,sBAAsB,IAAI,CAACH,CAAAA,uBACzBD,0BAA0BA,CAACC,sBAAsBC;AAGvD"}
@@ -68,7 +68,7 @@ class FlowAiAgentBase extends ContentFieldsBase {
68
68
  return;
69
69
  }
70
70
  async processContent(botContext, previousContents) {
71
- if (this.messages.length === 0) {
71
+ if (!this.aiAgentResponse) {
72
72
  await this.resolveAIAgentResponse(botContext, previousContents);
73
73
  }
74
74
  if (this.jsxElements.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"content-fields/flow-ai-agent-base.js","sources":["../../src/content-fields/flow-ai-agent-base.tsx"],"sourcesContent":["import {\n type AgenticOutputMessage,\n type BotContext,\n type GuardrailRule,\n type HubtypeAssistantMessage,\n type InferenceResponse,\n OutputMessageType,\n VerbosityLevel,\n} from '@botonic/core'\nimport {\n type FlowBuilderContentMessage,\n FlowBuilderOutputMessageType,\n} from '../structured-output/flow-builder-content'\nimport { getFlowBuilderPlugin } from '../utils/get-flow-builder-plugin'\nimport { HubtypeAssistantContent } from '../utils/hubtype-assistant-content'\nimport { ContentFieldsBase } from './content-fields-base'\nimport { FlowCarousel } from './flow-carousel'\nimport { FlowText } from './flow-text'\nimport { FlowWhatsappRequestContactInfoNode } from './flow-whatsapp-request-contact-info'\nimport type { HtInputGuardrailRule, HtNodeWithContent } from './hubtype-fields'\nimport type { FlowContent } from './index'\n\nexport abstract class FlowAiAgentBase extends ContentFieldsBase {\n public name: string = ''\n public instructions: string = ''\n public model: string = ''\n public verbosity: VerbosityLevel = VerbosityLevel.Medium\n public inputGuardrailRules: HtInputGuardrailRule[] = []\n\n public aiAgentResponse?: InferenceResponse<FlowBuilderContentMessage>\n public messages: AgenticOutputMessage<FlowBuilderContentMessage>[] = []\n public jsxElements: JSX.Element[] = []\n\n abstract getAIAgentResponse(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<InferenceResponse<FlowBuilderContentMessage> | undefined>\n\n abstract trackAiAgentResponse(botContext: BotContext): Promise<void>\n\n async resolveAIAgentResponse(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<InferenceResponse<FlowBuilderContentMessage> | undefined> {\n const aiAgentResponse = await this.getAIAgentResponse(\n botContext,\n previousContents\n )\n\n if (aiAgentResponse) {\n this.aiAgentResponse = aiAgentResponse\n await this.trackAiAgentResponse(botContext)\n this.messages = aiAgentResponse.messages\n }\n\n return aiAgentResponse\n }\n\n async trackFlow(_botContext: BotContext): Promise<void> {\n return\n }\n\n async getFlowContentsByContentId(\n botContext: BotContext,\n contentId: string\n ): Promise<FlowContent[]> {\n const flowBuilderPlugin = getFlowBuilderPlugin(botContext.plugins)\n const cmsApi = flowBuilderPlugin.cmsApi\n const node = cmsApi.getNodeByContentID(contentId)\n const flowContents = await flowBuilderPlugin.getContentsByNode(\n node as HtNodeWithContent\n )\n\n return flowContents\n }\n\n async messagesToBotonicJSXElements(botContext: BotContext): Promise<void> {\n for (const message of this.messages) {\n if (\n message.type === OutputMessageType.Text ||\n message.type === OutputMessageType.TextWithButtons ||\n message.type === OutputMessageType.BotExecutor\n ) {\n this.jsxElements.push(FlowText.fromAIAgent(this.id, message))\n }\n\n if (message.type === OutputMessageType.Carousel) {\n this.jsxElements.push(\n FlowCarousel.fromAIAgent(this.id, message, botContext)\n )\n }\n\n if (message.type === OutputMessageType.RequestContactInfo) {\n this.jsxElements.push(\n FlowWhatsappRequestContactInfoNode.fromAIAgent(\n this.id,\n message,\n botContext\n )\n )\n }\n\n if (message.type === FlowBuilderOutputMessageType.FlowBuilderContent) {\n const flowContents = await this.getFlowContentsByContentId(\n botContext,\n message.contentId\n )\n for (const content of flowContents) {\n await content.processContent(botContext)\n this.jsxElements.push(content.toBotonic(botContext))\n }\n }\n }\n return\n }\n\n async processContent(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<void> {\n if (this.messages.length === 0) {\n await this.resolveAIAgentResponse(botContext, previousContents)\n }\n if (this.jsxElements.length === 0) {\n await this.filterContent(botContext, this as unknown as FlowContent)\n await this.messagesToBotonicJSXElements(botContext)\n }\n return\n }\n\n toBotonic(): JSX.Element {\n return <>{this.jsxElements}</>\n }\n\n protected getPreviousHubtypeContents(\n previousContents?: FlowContent[]\n ): HubtypeAssistantMessage[] {\n return (\n previousContents?.map(content => {\n return {\n role: 'assistant',\n content: HubtypeAssistantContent.adapt(content),\n }\n }) || []\n )\n }\n\n protected getActiveInputGuardrailRules(\n inputGuardrailRules: HtInputGuardrailRule[]\n ): GuardrailRule[] {\n return (\n inputGuardrailRules\n ?.filter(rule => rule.is_active)\n ?.map(rule => ({\n name: rule.name,\n description: rule.description,\n })) || []\n )\n }\n}\n"],"names":["OutputMessageType","VerbosityLevel","FlowBuilderOutputMessageType","getFlowBuilderPlugin","HubtypeAssistantContent","ContentFieldsBase","FlowCarousel","FlowText","FlowWhatsappRequestContactInfoNode","FlowAiAgentBase","botContext","previousContents","aiAgentResponse","_botContext","contentId","flowBuilderPlugin","cmsApi","node","flowContents","message","content","inputGuardrailRules","rule"],"mappings":";;;;;;;;;;;;;;;;;;;;AAQsB;AAI4B;AACqB;AACK;AACnB;AACX;AACR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AKjB,+CAA+C,EAAE;gBACpE,MAAMgB,eAAe,MAAM,IAAI,CAAC,0BAA0B,CACxDR,YACAS,QAAQ,SAAS;gBAEnB,KAAK,MAAMC,WAAWF,aAAc;oBAClC,MAAME,QAAQ,cAAc,CAACV;oBAC7B,IAAI,CAAC,WAAW,CAAC,IAAI,CAACU,QAAQ,SAAS,CAACV;gBAC1C;YACF;QACF;QACA;IACF;IAEA,MAAM,eACJA,UAAsB,EACtBC,gBAAgC,EACjB;QACf,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG;YAC9B,MAAM,IAAI,CAAC,sBAAsB,CAACD,YAAYC;QAChD;QACA,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,GAAG;YACjC,MAAM,IAAI,CAAC,aAAa,CAACD,YAAY,IAAI;YACzC,MAAM,IAAI,CAAC,4BAA4B,CAACA;QAC1C;QACA;IACF;IAEA,YAAyB;QACvB,qBAAO;sBAAG,IAAI,CAAC,WAAW;;IAC5B;IAEU,2BACRC,gBAAgC,EACL;QAC3B,OACEA,kBAAkB,IAAIS,CAAAA;YACpB,OAAO;gBACL,MAAM;gBACN,SAAShB,6BAA6B,CAACgB;YACzC;QACF,MAAM,EAAE;IAEZ;IAEU,6BACRC,mBAA2C,EAC1B;QACjB,OACEA,qBACI,OAAOC,CAAAA,OAAQA,KAAK,SAAS,GAC7B,IAAIA,CAAAA,OAAS;gBACb,MAAMA,KAAK,IAAI;gBACf,aAAaA,KAAK,WAAW;YAC/B,OAAO,EAAE;IAEf;;QAxIK,qBACE,OAAe,SACf,eAAuB,SACvB,QAAgB,SAChB,YAA4BrB,qBAAqB,OACjD,sBAA8C,EAAE,OAGhD,WAA8D,EAAE,OAChE,cAA6B,EAAE;;AAgIxC"}
1
+ {"version":3,"file":"content-fields/flow-ai-agent-base.js","sources":["../../src/content-fields/flow-ai-agent-base.tsx"],"sourcesContent":["import {\n type AgenticOutputMessage,\n type BotContext,\n type GuardrailRule,\n type HubtypeAssistantMessage,\n type InferenceResponse,\n OutputMessageType,\n VerbosityLevel,\n} from '@botonic/core'\nimport {\n type FlowBuilderContentMessage,\n FlowBuilderOutputMessageType,\n} from '../structured-output/flow-builder-content'\nimport { getFlowBuilderPlugin } from '../utils/get-flow-builder-plugin'\nimport { HubtypeAssistantContent } from '../utils/hubtype-assistant-content'\nimport { ContentFieldsBase } from './content-fields-base'\nimport { FlowCarousel } from './flow-carousel'\nimport { FlowText } from './flow-text'\nimport { FlowWhatsappRequestContactInfoNode } from './flow-whatsapp-request-contact-info'\nimport type { HtInputGuardrailRule, HtNodeWithContent } from './hubtype-fields'\nimport type { FlowContent } from './index'\n\nexport abstract class FlowAiAgentBase extends ContentFieldsBase {\n public name: string = ''\n public instructions: string = ''\n public model: string = ''\n public verbosity: VerbosityLevel = VerbosityLevel.Medium\n public inputGuardrailRules: HtInputGuardrailRule[] = []\n\n public aiAgentResponse?: InferenceResponse<FlowBuilderContentMessage>\n public messages: AgenticOutputMessage<FlowBuilderContentMessage>[] = []\n public jsxElements: JSX.Element[] = []\n\n abstract getAIAgentResponse(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<InferenceResponse<FlowBuilderContentMessage> | undefined>\n\n abstract trackAiAgentResponse(botContext: BotContext): Promise<void>\n\n async resolveAIAgentResponse(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<InferenceResponse<FlowBuilderContentMessage> | undefined> {\n const aiAgentResponse = await this.getAIAgentResponse(\n botContext,\n previousContents\n )\n\n if (aiAgentResponse) {\n this.aiAgentResponse = aiAgentResponse\n await this.trackAiAgentResponse(botContext)\n this.messages = aiAgentResponse.messages\n }\n\n return aiAgentResponse\n }\n\n async trackFlow(_botContext: BotContext): Promise<void> {\n return\n }\n\n async getFlowContentsByContentId(\n botContext: BotContext,\n contentId: string\n ): Promise<FlowContent[]> {\n const flowBuilderPlugin = getFlowBuilderPlugin(botContext.plugins)\n const cmsApi = flowBuilderPlugin.cmsApi\n const node = cmsApi.getNodeByContentID(contentId)\n const flowContents = await flowBuilderPlugin.getContentsByNode(\n node as HtNodeWithContent\n )\n\n return flowContents\n }\n\n async messagesToBotonicJSXElements(botContext: BotContext): Promise<void> {\n for (const message of this.messages) {\n if (\n message.type === OutputMessageType.Text ||\n message.type === OutputMessageType.TextWithButtons ||\n message.type === OutputMessageType.BotExecutor\n ) {\n this.jsxElements.push(FlowText.fromAIAgent(this.id, message))\n }\n\n if (message.type === OutputMessageType.Carousel) {\n this.jsxElements.push(\n FlowCarousel.fromAIAgent(this.id, message, botContext)\n )\n }\n\n if (message.type === OutputMessageType.RequestContactInfo) {\n this.jsxElements.push(\n FlowWhatsappRequestContactInfoNode.fromAIAgent(\n this.id,\n message,\n botContext\n )\n )\n }\n\n if (message.type === FlowBuilderOutputMessageType.FlowBuilderContent) {\n const flowContents = await this.getFlowContentsByContentId(\n botContext,\n message.contentId\n )\n for (const content of flowContents) {\n await content.processContent(botContext)\n this.jsxElements.push(content.toBotonic(botContext))\n }\n }\n }\n return\n }\n\n async processContent(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<void> {\n if (!this.aiAgentResponse) {\n await this.resolveAIAgentResponse(botContext, previousContents)\n }\n if (this.jsxElements.length === 0) {\n await this.filterContent(botContext, this as unknown as FlowContent)\n await this.messagesToBotonicJSXElements(botContext)\n }\n return\n }\n\n toBotonic(): JSX.Element {\n return <>{this.jsxElements}</>\n }\n\n protected getPreviousHubtypeContents(\n previousContents?: FlowContent[]\n ): HubtypeAssistantMessage[] {\n return (\n previousContents?.map(content => {\n return {\n role: 'assistant',\n content: HubtypeAssistantContent.adapt(content),\n }\n }) || []\n )\n }\n\n protected getActiveInputGuardrailRules(\n inputGuardrailRules: HtInputGuardrailRule[]\n ): GuardrailRule[] {\n return (\n inputGuardrailRules\n ?.filter(rule => rule.is_active)\n ?.map(rule => ({\n name: rule.name,\n description: rule.description,\n })) || []\n )\n }\n}\n"],"names":["OutputMessageType","VerbosityLevel","FlowBuilderOutputMessageType","getFlowBuilderPlugin","HubtypeAssistantContent","ContentFieldsBase","FlowCarousel","FlowText","FlowWhatsappRequestContactInfoNode","FlowAiAgentBase","botContext","previousContents","aiAgentResponse","_botContext","contentId","flowBuilderPlugin","cmsApi","node","flowContents","message","content","inputGuardrailRules","rule"],"mappings":";;;;;;;;;;;;;;;;;;;;AAQsB;AAI4B;AACqB;AACK;AACnB;AACX;AACR;AACmD;AAIlF,MAAeS,eAAeA,SAASJ,iBAAiBA;IAkB7D,MAAM,uBACJK,UAAsB,EACtBC,gBAAgC,EACmC;QACnE,MAAMC,kBAAkB,MAAM,IAAI,CAAC,kBAAkB,CACnDF,YACAC;QAGF,IAAIC,iBAAiB;YACnB,IAAI,CAAC,eAAe,GAAGA;YACvB,MAAM,IAAI,CAAC,oBAAoB,CAACF;YAChC,IAAI,CAAC,QAAQ,GAAGE,gBAAgB,QAAQ;QAC1C;QAEA,OAAOA;IACT;IAEA,MAAM,UAAUC,WAAuB,EAAiB;QACtD;IACF;IAEA,MAAM,2BACJH,UAAsB,EACtBI,SAAiB,EACO;QACxB,MAAMC,oBAAoBZ,oBAAoBA,CAACO,WAAW,OAAO;QACjE,MAAMM,SAASD,kBAAkB,MAAM;QACvC,MAAME,OAAOD,OAAO,kBAAkB,CAACF;QACvC,MAAMI,eAAe,MAAMH,kBAAkB,iBAAiB,CAC5DE;QAGF,OAAOC;IACT;IAEA,MAAM,6BAA6BR,UAAsB,EAAiB;QACxE,KAAK,MAAMS,WAAW,IAAI,CAAC,QAAQ,CAAE;YACnC,IACEA,QAAQ,IAAI,KAAKnB,sBAAsB,IACvCmB,QAAQ,IAAI,KAAKnB,iCAAiC,IAClDmB,QAAQ,IAAI,KAAKnB,6BAA6B,EAC9C;gBACA,IAAI,CAAC,WAAW,CAAC,IAAI,CAACO,oBAAoB,CAAC,IAAI,CAAC,EAAE,EAAEY;YACtD;YAEA,IAAIA,QAAQ,IAAI,KAAKnB,0BAA0B,EAAE;gBAC/C,IAAI,CAAC,WAA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gB,SAChB,YAA4BrB,qBAAqB,OACjD,sBAA8C,EAAE,OAGhD,WAA8D,EAAE,OAChE,cAA6B,EAAE;;AAgIxC"}
@@ -121,7 +121,8 @@ class FlowAiAgentRouter extends FlowAiAgentBase {
121
121
  exit: this.aiAgentResponse?.exit ?? true,
122
122
  error: this.aiAgentResponse?.error ?? false,
123
123
  inputGuardrailsTriggered: [],
124
- outputGuardrailsTriggered: this.aiAgentResponse?.outputGuardrailsTriggered ?? []
124
+ outputGuardrailsTriggered: this.aiAgentResponse?.outputGuardrailsTriggered ?? [],
125
+ doNothing: this.aiAgentResponse?.doNothing ?? false
125
126
  };
126
127
  const { action, ...specialistEventArgs } = specialistEvent;
127
128
  await trackEvent(botContext, action, specialistEventArgs);
@@ -1 +1 @@
1
- {"version":3,"file":"content-fields/flow-ai-agent-router.js","sources":["../../src/content-fields/flow-ai-agent-router.tsx"],"sourcesContent":["import {\n AiAgentType,\n type BotContext,\n EventAction,\n type EventAiAgent,\n type EventAiAgentRouter,\n type InferenceResponse,\n} from '@botonic/core'\nimport {\n type FlowBuilderContentMessage,\n FlowBuilderContentSchema,\n} from '../structured-output/flow-builder-content'\nimport {\n getCommonFlowContentEventArgsForContentId,\n trackEvent,\n} from '../tracking'\nimport { getFlowBuilderPlugin } from '../utils/get-flow-builder-plugin'\nimport { FlowAiAgent } from './flow-ai-agent'\nimport { FlowAiAgentBase } from './flow-ai-agent-base'\nimport type { HtAiAgentNode, HtAiAgentRouterNode } from './hubtype-fields'\nimport type { FlowContent } from './index'\n\nexport interface AvailableSpecialists {\n agent: FlowAiAgent\n description: string\n name: string\n}\n\nexport class FlowAiAgentRouter extends FlowAiAgentBase {\n public availableSpecialists: AvailableSpecialists[] = []\n\n static fromHubtypeCMS(\n component: HtAiAgentRouterNode,\n botContext: BotContext\n ): FlowAiAgentRouter {\n const newAiAgentRouter = new FlowAiAgentRouter(component.id)\n newAiAgentRouter.code = component.code\n newAiAgentRouter.name = component.content.name\n newAiAgentRouter.instructions = newAiAgentRouter.replaceVariables(\n component.content.instructions,\n botContext\n )\n newAiAgentRouter.model = component.content.model\n newAiAgentRouter.verbosity = component.content.verbosity\n newAiAgentRouter.availableSpecialists =\n FlowAiAgentRouter.getAvailableSpecialistsFromHubtypeCMS(\n component,\n botContext\n )\n newAiAgentRouter.inputGuardrailRules =\n component.content.input_guardrail_rules || []\n return newAiAgentRouter\n }\n\n private static getAvailableSpecialistsFromHubtypeCMS(\n component: HtAiAgentRouterNode,\n botContext: BotContext\n ): AvailableSpecialists[] {\n const flowBuilderPlugin = getFlowBuilderPlugin(botContext.plugins)\n const cmsApi = flowBuilderPlugin.cmsApi\n\n return component.content.available_specialists.map((agentSlot, index) => {\n const aiAgentSpecialistNode = cmsApi.getNodeById<HtAiAgentNode>(\n agentSlot.target.id\n )\n const specialist = FlowAiAgent.fromHubtypeCMS(\n aiAgentSpecialistNode,\n botContext\n )\n const specialistName = FlowAiAgentRouter.specialistAgentBaseName(\n agentSlot.name,\n index\n )\n const specialistDescription = specialist.replaceVariables(\n agentSlot.description || `Transfer to ${specialistName}`,\n botContext\n )\n\n return {\n agent: specialist,\n description: specialistDescription,\n name: `transfer_to_${specialistName}`,\n }\n })\n }\n\n private static specialistAgentBaseName(\n name: string | undefined,\n index: number\n ): string {\n return name?.trim().toLowerCase().replace(/ /g, '_') || `ai_agent_${index}`\n }\n\n async getAIAgentResponse(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<InferenceResponse<FlowBuilderContentMessage> | undefined> {\n const flowBuilderPlugin = getFlowBuilderPlugin(botContext.plugins)\n const aiAgentResponse = await flowBuilderPlugin.getAiAgentResponse?.(\n botContext,\n {\n type: AiAgentType.Router,\n name: this.name,\n instructions: this.instructions,\n model: this.model,\n verbosity: this.verbosity,\n specialists: this.availableSpecialists.map(\n ({ agent, description, name }) => ({\n type: AiAgentType.Specialist,\n name,\n description,\n instructions: agent.instructions,\n model: agent.model,\n verbosity: agent.verbosity,\n activeTools: agent.activeTools ?? [],\n inputGuardrailRules: this.getActiveInputGuardrailRules(\n agent.inputGuardrailRules\n ),\n sourceIds: agent.sources?.map(s => s.id) ?? [],\n })\n ),\n inputGuardrailRules: this.getActiveInputGuardrailRules(\n this.inputGuardrailRules\n ),\n outputMessagesSchemas: [FlowBuilderContentSchema],\n previousHubtypeMessages:\n this.getPreviousHubtypeContents(previousContents),\n }\n )\n\n return aiAgentResponse\n }\n\n async trackAiAgentResponse(botContext: BotContext) {\n const isTransferredToSpecialist =\n this.aiAgentResponse?.isTransferredToSpecialist ?? false\n\n await this.trackAIAgentRouterEvent(botContext, isTransferredToSpecialist)\n\n if (isTransferredToSpecialist) {\n await this.trackAIAgentSpecialistEvent(botContext)\n }\n }\n\n private async trackAIAgentRouterEvent(\n botContext: BotContext,\n isTransferredToSpecialist: boolean\n ) {\n const { flowThreadId, flowId, flowName, flowNodeId } =\n getCommonFlowContentEventArgsForContentId(botContext, this.id)\n\n const routerEvent: EventAiAgentRouter = {\n action: EventAction.AiAgentRouter,\n flowThreadId,\n flowId,\n flowName,\n flowNodeId,\n flowNodeContentId: this.name,\n flowNodeIsMeaningful: true,\n memoryLength: this.aiAgentResponse?.memoryLength ?? 0,\n inputMessageId: botContext.input.message_id!,\n exit: this.aiAgentResponse?.exit ?? true,\n error: this.aiAgentResponse?.error ?? false,\n inputGuardrailsTriggered:\n this.aiAgentResponse?.inputGuardrailsTriggered ?? [],\n outputGuardrailsTriggered:\n this.aiAgentResponse?.outputGuardrailsTriggered ?? [],\n startingAgentName: this.aiAgentResponse?.startingAgentName || this.name,\n lastAgentName: this.aiAgentResponse?.lastAgentName || this.name,\n availableSpecialists: this.aiAgentResponse?.availableSpecialists ?? [],\n isTransferredToSpecialist,\n }\n const { action, ...routerEventArgs } = routerEvent\n await trackEvent(botContext, action, routerEventArgs)\n }\n\n private async trackAIAgentSpecialistEvent(botContext: BotContext) {\n const { flowThreadId, flowId, flowName, flowNodeId } =\n getCommonFlowContentEventArgsForContentId(botContext, this.id)\n\n const specialistEvent: EventAiAgent = {\n action: EventAction.AiAgent,\n flowThreadId,\n flowId,\n flowName,\n flowNodeId,\n flowNodeContentId: this.aiAgentResponse?.lastAgentName ?? '',\n flowNodeIsMeaningful: true,\n toolsExecuted: this.aiAgentResponse?.toolsExecuted ?? [],\n memoryLength: this.aiAgentResponse?.memoryLength ?? 0,\n inputMessageId: botContext.input.message_id!,\n exit: this.aiAgentResponse?.exit ?? true,\n error: this.aiAgentResponse?.error ?? false,\n inputGuardrailsTriggered: [],\n outputGuardrailsTriggered:\n this.aiAgentResponse?.outputGuardrailsTriggered ?? [],\n }\n const { action, ...specialistEventArgs } = specialistEvent\n await trackEvent(botContext, action, specialistEventArgs)\n }\n}\n"],"names":["AiAgentType","EventAction","FlowBuilderContentSchema","getCommonFlowContentEventArgsForContentId","trackEvent","getFlowBuilderPlugin","FlowAiAgent","FlowAiAgentBase","FlowAiAgentRouter","component","botContext","newAiAgentRouter","flowBuilderPlugin","cmsApi","agentSlot","index","aiAgentSpecialistNode","specialist","specialistName","specialistDescription","name","previousContents","aiAgentResponse","agent","description","s","isTransferredToSpecialist","flowThreadId","flowId","flowName","flowNodeId","routerEvent","action","routerEventArgs","specialistEvent","specialistEventArgs"],"mappings":";;;;;;;;;;;;;AAOsB;AAI4B;AAI9B;AACmD;AAC1B;AACS;AAU/C,MAAMQ,iBAAiBA,SAASD,eAAeA;IAGpD,OAAO,eACLE,SAA8B,EAC9BC,UAAsB,EACH;QACnB,MAAMC,mBAAmB,IAAIH,iBAAiBA,CAACC,UAAU,EAAE;QAC3DE,iBAAiB,IAAI,GAAGF,UAAU,IAAI;QACtCE,iBAAiB,IAAI,GAAGF,UAAU,OAAO,CAAC,IAAI;QAC9CE,iBAAiB,YAAY,GAAGA,iBAAiB,gBAAgB,CAC/DF,UAAU,OAAO,CAAC,YAAY,EAC9BC;QAEFC,iBAAiB,KAAK,GAAGF,UAAU,OAAO,CAAC,KAAK;QAChDE,iBAAiB,SAAS,GAAGF,UAAU,OAAO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,4BAA4B,EAAE;YACtD,2BACE,IAAI,CAAC,eAAe,EAAE,6BAA6B,EAAE;YACvD,mBAAmB,IAAI,CAAC,eAAe,EAAE,qBAAqB,IAAI,CAAC,IAAI;YACvE,eAAe,IAAI,CAAC,eAAe,EAAE,iBAAiB,IAAI,CAAC,IAAI;YAC/D,sBAAsB,IAAI,CAAC,eAAe,EAAE,wBAAwB,EAAE;YACtEgB;QACF;QACA,MAAM,EAAEM,MAAM,EAAE,GAAGC,iBAAiB,GAAGF;QACvC,MAAM3B,UAAUA,CAACM,YAAYsB,QAAQC;IACvC;IAEA,MAAc,4BAA4BvB,UAAsB,EAAE;QAChE,MAAM,EAAEiB,YAAY,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAClD3B,yCAAyCA,CAACO,YAAY,IAAI,CAAC,EAAE;QAE/D,MAAMwB,kBAAgC;YACpC,QAAQjC,mBAAmB;YAC3B0B;YACAC;YACAC;YACAC;YACA,mBAAmB,IAAI,CAAC,eAAe,EAAE,iBAAiB;YAC1D,sBAAsB;YACtB,eAAe,IAAI,CAAC,eAAe,EAAE,iBAAiB,EAAE;YACxD,cAAc,IAAI,CAAC,eAAe,EAAE,gBAAgB;YACpD,gBAAgBpB,WAAW,KAAK,CAAC,UAAU;YAC3C,MAAM,IAAI,CAAC,eAAe,EAAE,QAAQ;YACpC,OAAO,IAAI,CAAC,eAAe,EAAE,SAAS;YACtC,0BAA0B,EAAE;YAC5B,2BACE,IAAI,CAAC,eAAe,EAAE,6BAA6B,EAAE;QACzD;QACA,MAAM,EAAEsB,MAAM,EAAE,GAAGG,qBAAqB,GAAGD;QAC3C,MAAM9B,UAAUA,CAACM,YAAYsB,QAAQG;IACvC;;QA3KK,qBACE,uBAA+C,EAAE;;AA2K1D"}
1
+ {"version":3,"file":"content-fields/flow-ai-agent-router.js","sources":["../../src/content-fields/flow-ai-agent-router.tsx"],"sourcesContent":["import {\n AiAgentType,\n type BotContext,\n EventAction,\n type EventAiAgent,\n type EventAiAgentRouter,\n type InferenceResponse,\n} from '@botonic/core'\nimport {\n type FlowBuilderContentMessage,\n FlowBuilderContentSchema,\n} from '../structured-output/flow-builder-content'\nimport {\n getCommonFlowContentEventArgsForContentId,\n trackEvent,\n} from '../tracking'\nimport { getFlowBuilderPlugin } from '../utils/get-flow-builder-plugin'\nimport { FlowAiAgent } from './flow-ai-agent'\nimport { FlowAiAgentBase } from './flow-ai-agent-base'\nimport type { HtAiAgentNode, HtAiAgentRouterNode } from './hubtype-fields'\nimport type { FlowContent } from './index'\n\nexport interface AvailableSpecialists {\n agent: FlowAiAgent\n description: string\n name: string\n}\n\nexport class FlowAiAgentRouter extends FlowAiAgentBase {\n public availableSpecialists: AvailableSpecialists[] = []\n\n static fromHubtypeCMS(\n component: HtAiAgentRouterNode,\n botContext: BotContext\n ): FlowAiAgentRouter {\n const newAiAgentRouter = new FlowAiAgentRouter(component.id)\n newAiAgentRouter.code = component.code\n newAiAgentRouter.name = component.content.name\n newAiAgentRouter.instructions = newAiAgentRouter.replaceVariables(\n component.content.instructions,\n botContext\n )\n newAiAgentRouter.model = component.content.model\n newAiAgentRouter.verbosity = component.content.verbosity\n newAiAgentRouter.availableSpecialists =\n FlowAiAgentRouter.getAvailableSpecialistsFromHubtypeCMS(\n component,\n botContext\n )\n newAiAgentRouter.inputGuardrailRules =\n component.content.input_guardrail_rules || []\n return newAiAgentRouter\n }\n\n private static getAvailableSpecialistsFromHubtypeCMS(\n component: HtAiAgentRouterNode,\n botContext: BotContext\n ): AvailableSpecialists[] {\n const flowBuilderPlugin = getFlowBuilderPlugin(botContext.plugins)\n const cmsApi = flowBuilderPlugin.cmsApi\n\n return component.content.available_specialists.map((agentSlot, index) => {\n const aiAgentSpecialistNode = cmsApi.getNodeById<HtAiAgentNode>(\n agentSlot.target.id\n )\n const specialist = FlowAiAgent.fromHubtypeCMS(\n aiAgentSpecialistNode,\n botContext\n )\n const specialistName = FlowAiAgentRouter.specialistAgentBaseName(\n agentSlot.name,\n index\n )\n const specialistDescription = specialist.replaceVariables(\n agentSlot.description || `Transfer to ${specialistName}`,\n botContext\n )\n\n return {\n agent: specialist,\n description: specialistDescription,\n name: `transfer_to_${specialistName}`,\n }\n })\n }\n\n private static specialistAgentBaseName(\n name: string | undefined,\n index: number\n ): string {\n return name?.trim().toLowerCase().replace(/ /g, '_') || `ai_agent_${index}`\n }\n\n async getAIAgentResponse(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<InferenceResponse<FlowBuilderContentMessage> | undefined> {\n const flowBuilderPlugin = getFlowBuilderPlugin(botContext.plugins)\n const aiAgentResponse = await flowBuilderPlugin.getAiAgentResponse?.(\n botContext,\n {\n type: AiAgentType.Router,\n name: this.name,\n instructions: this.instructions,\n model: this.model,\n verbosity: this.verbosity,\n specialists: this.availableSpecialists.map(\n ({ agent, description, name }) => ({\n type: AiAgentType.Specialist,\n name,\n description,\n instructions: agent.instructions,\n model: agent.model,\n verbosity: agent.verbosity,\n activeTools: agent.activeTools ?? [],\n inputGuardrailRules: this.getActiveInputGuardrailRules(\n agent.inputGuardrailRules\n ),\n sourceIds: agent.sources?.map(s => s.id) ?? [],\n })\n ),\n inputGuardrailRules: this.getActiveInputGuardrailRules(\n this.inputGuardrailRules\n ),\n outputMessagesSchemas: [FlowBuilderContentSchema],\n previousHubtypeMessages:\n this.getPreviousHubtypeContents(previousContents),\n }\n )\n\n return aiAgentResponse\n }\n\n async trackAiAgentResponse(botContext: BotContext) {\n const isTransferredToSpecialist =\n this.aiAgentResponse?.isTransferredToSpecialist ?? false\n\n await this.trackAIAgentRouterEvent(botContext, isTransferredToSpecialist)\n\n if (isTransferredToSpecialist) {\n await this.trackAIAgentSpecialistEvent(botContext)\n }\n }\n\n private async trackAIAgentRouterEvent(\n botContext: BotContext,\n isTransferredToSpecialist: boolean\n ) {\n const { flowThreadId, flowId, flowName, flowNodeId } =\n getCommonFlowContentEventArgsForContentId(botContext, this.id)\n\n const routerEvent: EventAiAgentRouter = {\n action: EventAction.AiAgentRouter,\n flowThreadId,\n flowId,\n flowName,\n flowNodeId,\n flowNodeContentId: this.name,\n flowNodeIsMeaningful: true,\n memoryLength: this.aiAgentResponse?.memoryLength ?? 0,\n inputMessageId: botContext.input.message_id!,\n exit: this.aiAgentResponse?.exit ?? true,\n error: this.aiAgentResponse?.error ?? false,\n inputGuardrailsTriggered:\n this.aiAgentResponse?.inputGuardrailsTriggered ?? [],\n outputGuardrailsTriggered:\n this.aiAgentResponse?.outputGuardrailsTriggered ?? [],\n startingAgentName: this.aiAgentResponse?.startingAgentName || this.name,\n lastAgentName: this.aiAgentResponse?.lastAgentName || this.name,\n availableSpecialists: this.aiAgentResponse?.availableSpecialists ?? [],\n isTransferredToSpecialist,\n }\n const { action, ...routerEventArgs } = routerEvent\n await trackEvent(botContext, action, routerEventArgs)\n }\n\n private async trackAIAgentSpecialistEvent(botContext: BotContext) {\n const { flowThreadId, flowId, flowName, flowNodeId } =\n getCommonFlowContentEventArgsForContentId(botContext, this.id)\n\n const specialistEvent: EventAiAgent = {\n action: EventAction.AiAgent,\n flowThreadId,\n flowId,\n flowName,\n flowNodeId,\n flowNodeContentId: this.aiAgentResponse?.lastAgentName ?? '',\n flowNodeIsMeaningful: true,\n toolsExecuted: this.aiAgentResponse?.toolsExecuted ?? [],\n memoryLength: this.aiAgentResponse?.memoryLength ?? 0,\n inputMessageId: botContext.input.message_id!,\n exit: this.aiAgentResponse?.exit ?? true,\n error: this.aiAgentResponse?.error ?? false,\n inputGuardrailsTriggered: [],\n outputGuardrailsTriggered:\n this.aiAgentResponse?.outputGuardrailsTriggered ?? [],\n doNothing: this.aiAgentResponse?.doNothing ?? false,\n }\n const { action, ...specialistEventArgs } = specialistEvent\n await trackEvent(botContext, action, specialistEventArgs)\n }\n}\n"],"names":["AiAgentType","EventAction","FlowBuilderContentSchema","getCommonFlowContentEventArgsForContentId","trackEvent","getFlowBuilderPlugin","FlowAiAgent","FlowAiAgentBase","FlowAiAgentRouter","component","botContext","newAiAgentRouter","flowBuilderPlugin","cmsApi","agentSlot","index","aiAgentSpecialistNode","specialist","specialistName","specialistDescription","name","previousContents","aiAgentResponse","agent","description","s","isTransferredToSpecialist","flowThreadId","flowId","flowName","flowNodeId","routerEvent","action","routerEventArgs","specialistEvent","specialistEventArgs"],"mappings":";;;;;;;;;;;;;AAOsB;AAI4B;AAI9B;AACmD;AAC1B;AACS;AAU/C,MAAMQ,iBAAiBA,SAASD,eAAeA;IAGpD,OAAO,eACLE,SAA8B,EAC9BC,UAAsB,EACH;QACnB,MAAMC,mBAAmB,IAAIH,iBAAiBA,CAACC,UAAU,EAAE;QAC3DE,iBAAiB,IAAI,GAAGF,UAAU,IAAI;QACtCE,iBAAiB,IAAI,GAAGF,UAAU,OAAO,CAAC,IAAI;QAC9CE,iBAAiB,YAAY,GAAGA,iBAAiB,gBAAgB,CAC/DF,UAAU,OAAO,CAAC,YAAY,EAC9BC;QAEFC,iBAAiB,KAAK,GAAGF,UAAU,OAAO,CAAC,KAAK;QAChDE,iBAAiB,SAAS,GAAGF,UAAU,OAAO,CAAC,SAAS;QACxDE,iBAAiB,oBAAoB,GACnCH,iBAAiBA,CAAC,qCAAqC,CACrDC,WACAC;QAEJC,iBAAiB,mBAAmB,GAClCF,UAAU,OAAO,CAAC,qBAAqB,IAAI,EAAE;QAC/C,OAAOE;IACT;IAEA,OAAe,sCACbF,SAA8B,EAC9BC,UAAsB,EACE;QACxB,MAAME,oBAAoBP,oBAAoBA,CAACK,WAAW,OAAO;QACjE,MAAMG,SAASD,kBAAkB,MAAM;QAEvC,OAAOH,UAAU,OAAO,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAACK,WAAWC;YAC7D,MAAMC,wBAAwBH,OAAO,WAAW,CAC9CC,UAAU,MAAM,CAAC,EAAE;YAErB,MAAMG,aAAaX,0BAA0B,CAC3CU,uBACAN;YAEF,MAAMQ,iBAAiBV,iBAAiBA,CAAC,uBAAuB,CAC9DM,UAAU,IAAI,EACdC;YAEF,MAAMI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B0B;YACAC;YACAC;YACAC;YACA,mBAAmB,IAAI,CAAC,eAAe,EAAE,iBAAiB;YAC1D,sBAAsB;YACtB,eAAe,IAAI,CAAC,eAAe,EAAE,iBAAiB,EAAE;YACxD,cAAc,IAAI,CAAC,eAAe,EAAE,gBAAgB;YACpD,gBAAgBpB,WAAW,KAAK,CAAC,UAAU;YAC3C,MAAM,IAAI,CAAC,eAAe,EAAE,QAAQ;YACpC,OAAO,IAAI,CAAC,eAAe,EAAE,SAAS;YACtC,0BAA0B,EAAE;YAC5B,2BACE,IAAI,CAAC,eAAe,EAAE,6BAA6B,EAAE;YACvD,WAAW,IAAI,CAAC,eAAe,EAAE,aAAa;QAChD;QACA,MAAM,EAAEsB,MAAM,EAAE,GAAGG,qBAAqB,GAAGD;QAC3C,MAAM9B,UAAUA,CAACM,YAAYsB,QAAQG;IACvC;;QA5KK,qBACE,uBAA+C,EAAE;;AA4K1D"}
@@ -63,7 +63,8 @@ class FlowAiAgent extends FlowAiAgentBase {
63
63
  exit: this.aiAgentResponse?.exit ?? true,
64
64
  inputGuardrailsTriggered: this.aiAgentResponse?.inputGuardrailsTriggered ?? [],
65
65
  outputGuardrailsTriggered: [],
66
- error: this.aiAgentResponse?.error ?? false
66
+ error: this.aiAgentResponse?.error ?? false,
67
+ doNothing: this.aiAgentResponse?.doNothing ?? false
67
68
  };
68
69
  const { action, ...eventArgs } = event;
69
70
  await trackEvent(botContext, action, eventArgs);
@@ -1 +1 @@
1
- {"version":3,"file":"content-fields/flow-ai-agent.js","sources":["../../src/content-fields/flow-ai-agent.tsx"],"sourcesContent":["import {\n AiAgentType,\n type BotContext,\n EventAction,\n type EventAiAgent,\n type InferenceResponse,\n} from '@botonic/core'\nimport {\n type FlowBuilderContentMessage,\n FlowBuilderContentSchema,\n} from '../structured-output/flow-builder-content'\nimport {\n getCommonFlowContentEventArgsForContentId,\n trackEvent,\n} from '../tracking'\nimport { getFlowBuilderPlugin } from '../utils/get-flow-builder-plugin'\nimport { FlowAiAgentBase } from './flow-ai-agent-base'\nimport type { HtAiAgentNode } from './hubtype-fields/ai-agent'\nimport type { FlowContent } from './index'\n\nexport class FlowAiAgent extends FlowAiAgentBase {\n public activeTools?: { name: string }[]\n public sources?: { id: string; name: string }[]\n\n static fromHubtypeCMS(\n component: HtAiAgentNode,\n botContext: BotContext\n ): FlowAiAgent {\n const newAiAgent = new FlowAiAgent(component.id)\n newAiAgent.code = component.code\n newAiAgent.name = component.content.name\n newAiAgent.instructions = newAiAgent.replaceVariables(\n component.content.instructions,\n botContext\n )\n newAiAgent.model = component.content.model\n newAiAgent.verbosity = component.content.verbosity\n newAiAgent.activeTools = component.content.active_tools\n newAiAgent.inputGuardrailRules =\n component.content.input_guardrail_rules || []\n newAiAgent.sources = component.content.sources\n newAiAgent.followUp = component.follow_up\n\n return newAiAgent\n }\n\n async getAIAgentResponse(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<InferenceResponse<FlowBuilderContentMessage> | undefined> {\n const activeInputGuardrailRules = this.getActiveInputGuardrailRules(\n this.inputGuardrailRules\n )\n\n const flowBuilderPlugin = getFlowBuilderPlugin(botContext.plugins)\n\n const aiAgentResponse = await flowBuilderPlugin.getAiAgentResponse?.(\n botContext,\n {\n type: AiAgentType.Specialist,\n name: this.name,\n instructions: this.instructions,\n model: this.model,\n verbosity: this.verbosity,\n activeTools: this.activeTools ?? [],\n inputGuardrailRules: activeInputGuardrailRules,\n sourceIds: this.sources?.map(source => source.id) ?? [],\n outputMessagesSchemas: [FlowBuilderContentSchema],\n previousHubtypeMessages:\n this.getPreviousHubtypeContents(previousContents),\n }\n )\n\n return aiAgentResponse\n }\n\n async trackAiAgentResponse(botContext: BotContext) {\n const { flowThreadId, flowId, flowName, flowNodeId } =\n getCommonFlowContentEventArgsForContentId(botContext, this.id)\n\n const event: EventAiAgent = {\n action: EventAction.AiAgent,\n flowThreadId: flowThreadId,\n flowId: flowId,\n flowName: flowName,\n flowNodeId: flowNodeId,\n flowNodeContentId: this.name,\n flowNodeIsMeaningful: true,\n toolsExecuted: this.aiAgentResponse?.toolsExecuted ?? [],\n memoryLength: this.aiAgentResponse?.memoryLength ?? 0,\n inputMessageId: botContext.input.message_id!,\n exit: this.aiAgentResponse?.exit ?? true,\n inputGuardrailsTriggered:\n this.aiAgentResponse?.inputGuardrailsTriggered ?? [],\n outputGuardrailsTriggered: [], //aiAgentResponse.outputGuardrailsTriggered,\n error: this.aiAgentResponse?.error ?? false,\n }\n const { action, ...eventArgs } = event\n\n await trackEvent(botContext, action, eventArgs)\n }\n}\n"],"names":["AiAgentType","EventAction","FlowBuilderContentSchema","getCommonFlowContentEventArgsForContentId","trackEvent","getFlowBuilderPlugin","FlowAiAgentBase","FlowAiAgent","component","botContext","newAiAgent","previousContents","activeInputGuardrailRules","flowBuilderPlugin","aiAgentResponse","source","flowThreadId","flowId","flowName","flowNodeId","event","action","eventArgs"],"mappings":";;;;;;;;;;;AAMsB;AAI4B;AAI9B;AACmD;AACjB;AAI/C,MAAMO,WAAWA,SAASD,eAAeA;IAI9C,OAAO,eACLE,SAAwB,EACxBC,UAAsB,EACT;QACb,MAAMC,aAAa,IAAIH,WAAWA,CAACC,UAAU,EAAE;QAC/CE,WAAW,IAAI,GAAGF,UAAU,IAAI;QAChCE,WAAW,IAAI,GAAGF,UAAU,OAAO,CAAC,IAAI;QACxCE,WAAW,YAAY,GAAGA,WAAW,gBAAgB,CACnDF,UAAU,OAAO,CAAC,YAAY,EAC9BC;QAEFC,WAAW,KAAK,GAAGF,UAAU,OAAO,CAAC,KAAK;QAC1CE,WAAW,SAAS,GAAGF,UAAU,OAAO,CAAC,SAAS;QAClDE,WAAW,WAAW,GAAGF,UAAU,OAAO,CAAC,YAAY;QACvDE,WAAW,mBAAmB,GAC5BF,UAAU,OAAO,CAAC,qBAAqB,IAAI,EAAE;QAC/CE,WAAW,OAAO,GAAGF,UAAU,OAAO,CAAC,OAAO;QAC9CE,WAAW,QAAQ,GAAGF,UAAU,SAAS;QAEzC,O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AEY,MAAM,EAAE,GAAGC,WAAW,GAAGF;QAEjC,MAAMhB,UAAUA,CAACK,YAAYY,QAAQC;IACvC;AACF"}
1
+ {"version":3,"file":"content-fields/flow-ai-agent.js","sources":["../../src/content-fields/flow-ai-agent.tsx"],"sourcesContent":["import {\n AiAgentType,\n type BotContext,\n EventAction,\n type EventAiAgent,\n type InferenceResponse,\n} from '@botonic/core'\nimport {\n type FlowBuilderContentMessage,\n FlowBuilderContentSchema,\n} from '../structured-output/flow-builder-content'\nimport {\n getCommonFlowContentEventArgsForContentId,\n trackEvent,\n} from '../tracking'\nimport { getFlowBuilderPlugin } from '../utils/get-flow-builder-plugin'\nimport { FlowAiAgentBase } from './flow-ai-agent-base'\nimport type { HtAiAgentNode } from './hubtype-fields/ai-agent'\nimport type { FlowContent } from './index'\n\nexport class FlowAiAgent extends FlowAiAgentBase {\n public activeTools?: { name: string }[]\n public sources?: { id: string; name: string }[]\n\n static fromHubtypeCMS(\n component: HtAiAgentNode,\n botContext: BotContext\n ): FlowAiAgent {\n const newAiAgent = new FlowAiAgent(component.id)\n newAiAgent.code = component.code\n newAiAgent.name = component.content.name\n newAiAgent.instructions = newAiAgent.replaceVariables(\n component.content.instructions,\n botContext\n )\n newAiAgent.model = component.content.model\n newAiAgent.verbosity = component.content.verbosity\n newAiAgent.activeTools = component.content.active_tools\n newAiAgent.inputGuardrailRules =\n component.content.input_guardrail_rules || []\n newAiAgent.sources = component.content.sources\n newAiAgent.followUp = component.follow_up\n\n return newAiAgent\n }\n\n async getAIAgentResponse(\n botContext: BotContext,\n previousContents?: FlowContent[]\n ): Promise<InferenceResponse<FlowBuilderContentMessage> | undefined> {\n const activeInputGuardrailRules = this.getActiveInputGuardrailRules(\n this.inputGuardrailRules\n )\n\n const flowBuilderPlugin = getFlowBuilderPlugin(botContext.plugins)\n\n const aiAgentResponse = await flowBuilderPlugin.getAiAgentResponse?.(\n botContext,\n {\n type: AiAgentType.Specialist,\n name: this.name,\n instructions: this.instructions,\n model: this.model,\n verbosity: this.verbosity,\n activeTools: this.activeTools ?? [],\n inputGuardrailRules: activeInputGuardrailRules,\n sourceIds: this.sources?.map(source => source.id) ?? [],\n outputMessagesSchemas: [FlowBuilderContentSchema],\n previousHubtypeMessages:\n this.getPreviousHubtypeContents(previousContents),\n }\n )\n\n return aiAgentResponse\n }\n\n async trackAiAgentResponse(botContext: BotContext) {\n const { flowThreadId, flowId, flowName, flowNodeId } =\n getCommonFlowContentEventArgsForContentId(botContext, this.id)\n\n const event: EventAiAgent = {\n action: EventAction.AiAgent,\n flowThreadId: flowThreadId,\n flowId: flowId,\n flowName: flowName,\n flowNodeId: flowNodeId,\n flowNodeContentId: this.name,\n flowNodeIsMeaningful: true,\n toolsExecuted: this.aiAgentResponse?.toolsExecuted ?? [],\n memoryLength: this.aiAgentResponse?.memoryLength ?? 0,\n inputMessageId: botContext.input.message_id!,\n exit: this.aiAgentResponse?.exit ?? true,\n inputGuardrailsTriggered:\n this.aiAgentResponse?.inputGuardrailsTriggered ?? [],\n outputGuardrailsTriggered: [], //aiAgentResponse.outputGuardrailsTriggered,\n error: this.aiAgentResponse?.error ?? false,\n doNothing: this.aiAgentResponse?.doNothing ?? false,\n }\n const { action, ...eventArgs } = event\n\n await trackEvent(botContext, action, eventArgs)\n }\n}\n"],"names":["AiAgentType","EventAction","FlowBuilderContentSchema","getCommonFlowContentEventArgsForContentId","trackEvent","getFlowBuilderPlugin","FlowAiAgentBase","FlowAiAgent","component","botContext","newAiAgent","previousContents","activeInputGuardrailRules","flowBuilderPlugin","aiAgentResponse","source","flowThreadId","flowId","flowName","flowNodeId","event","action","eventArgs"],"mappings":";;;;;;;;;;;AAMsB;AAI4B;AAI9B;AACmD;AACjB;AAI/C,MAAMO,WAAWA,SAASD,eAAeA;IAI9C,OAAO,eACLE,SAAwB,EACxBC,UAAsB,EACT;QACb,MAAMC,aAAa,IAAIH,WAAWA,CAACC,UAAU,EAAE;QAC/CE,WAAW,IAAI,GAAGF,UAAU,IAAI;Q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/D,MAAMW,QAAsB;YAC1B,QAAQnB,mBAAmB;YAC3B,cAAce;YACd,QAAQC;YACR,UAAUC;YACV,YAAYC;YACZ,mBAAmB,IAAI,CAAC,IAAI;YAC5B,sBAAsB;YACtB,eAAe,IAAI,CAAC,eAAe,EAAE,iBAAiB,EAAE;YACxD,cAAc,IAAI,CAAC,eAAe,EAAE,gBAAgB;YACpD,gBAAgBV,WAAW,KAAK,CAAC,UAAU;YAC3C,MAAM,IAAI,CAAC,eAAe,EAAE,QAAQ;YACpC,0BACE,IAAI,CAAC,eAAe,EAAE,4BAA4B,EAAE;YACtD,2BAA2B,EAAE;YAC7B,OAAO,IAAI,CAAC,eAAe,EAAE,SAAS;YACtC,WAAW,IAAI,CAAC,eAAe,EAAE,aAAa;QAChD;QACA,MAAM,EAAEY,MAAM,EAAE,GAAGC,WAAW,GAAGF;QAEjC,MAAMhB,UAAUA,CAACK,YAAYY,QAAQC;IACvC;AACF"}
@@ -0,0 +1,14 @@
1
+ import { type BotContext } from '@botonic/core';
2
+ import { ContentFieldsBase } from './content-fields-base.js';
3
+ import type { HtNodeLink } from './hubtype-fields/common.js';
4
+ import type { HtContactReasonBranch, HtContactReasonsNode } from './hubtype-fields/contact-reasons-conditional.js';
5
+ export declare class FlowContactReasonsConditional extends ContentFieldsBase {
6
+ contactReasons: HtContactReasonBranch[];
7
+ conditionalResult: string;
8
+ defaultTarget: HtNodeLink;
9
+ static fromHubtypeCMS(component: HtContactReasonsNode, botContext: BotContext): FlowContactReasonsConditional;
10
+ private setFollowUp;
11
+ trackFlow(botContext: BotContext): Promise<void>;
12
+ processContent(botContext: BotContext): Promise<void>;
13
+ toBotonic(): import("react").JSX.Element;
14
+ }
@@ -0,0 +1,68 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { EventAction } from "@botonic/core";
3
+ import { getCommonFlowContentEventArgsForContentId, trackEvent } from "../tracking.js";
4
+ import { findMatchingContactReasonBranch } from "./contact-reasons-conditional-matcher.js";
5
+ import { ContentFieldsBase } from "./content-fields-base.js";
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ class FlowContactReasonsConditional extends ContentFieldsBase {
18
+ static fromHubtypeCMS(component, botContext) {
19
+ const newContactReasonsConditional = new FlowContactReasonsConditional(component.id);
20
+ newContactReasonsConditional.contactReasons = component.content.contact_reasons;
21
+ newContactReasonsConditional.defaultTarget = component.content.default_target;
22
+ newContactReasonsConditional.setFollowUp(botContext);
23
+ return newContactReasonsConditional;
24
+ }
25
+ setFollowUp(botContext) {
26
+ const sessionContactReasons = botContext.session._hubtype_case_contact_reasons;
27
+ const matchingBranch = sessionContactReasons ? findMatchingContactReasonBranch(sessionContactReasons, this.contactReasons) : undefined;
28
+ if (matchingBranch) {
29
+ this.conditionalResult = matchingBranch.name;
30
+ this.followUp = matchingBranch.target;
31
+ } else {
32
+ this.conditionalResult = 'default';
33
+ this.followUp = this.defaultTarget;
34
+ }
35
+ }
36
+ async trackFlow(botContext) {
37
+ const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = getCommonFlowContentEventArgsForContentId(botContext, this.id);
38
+ const eventContactReasonsConditional = {
39
+ action: EventAction.ConditionalContactReasons,
40
+ flowThreadId,
41
+ flowId,
42
+ flowName,
43
+ flowNodeId,
44
+ flowNodeContentId,
45
+ flowNodeIsMeaningful: false,
46
+ contactReasons: botContext.session._hubtype_case_contact_reasons?.map((contactReason)=>contactReason.name) || [],
47
+ result: this.conditionalResult
48
+ };
49
+ const { action, ...eventArgs } = eventContactReasonsConditional;
50
+ await trackEvent(botContext, action, eventArgs);
51
+ return;
52
+ }
53
+ async processContent(botContext) {
54
+ await this.filterContent(botContext, this);
55
+ await this.trackFlow(botContext);
56
+ return;
57
+ }
58
+ toBotonic() {
59
+ return /*#__PURE__*/ jsx(Fragment, {});
60
+ }
61
+ constructor(...args){
62
+ super(...args), this.contactReasons = [], this.conditionalResult = '';
63
+ }
64
+ }
65
+
66
+ export { FlowContactReasonsConditional };
67
+
68
+ //# sourceMappingURL=flow-contact-reasons-conditional.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-fields/flow-contact-reasons-conditional.js","sources":["../../src/content-fields/flow-contact-reasons-conditional.tsx"],"sourcesContent":["import {\n type BotContext,\n EventAction,\n type EventConditionalContactReasons,\n} from '@botonic/core'\n\nimport {\n getCommonFlowContentEventArgsForContentId,\n trackEvent,\n} from '../tracking'\nimport { findMatchingContactReasonBranch } from './contact-reasons-conditional-matcher'\nimport { ContentFieldsBase } from './content-fields-base'\nimport type { HtNodeLink } from './hubtype-fields/common'\nimport type {\n HtContactReasonBranch,\n HtContactReasonsNode,\n} from './hubtype-fields/contact-reasons-conditional'\n\nexport class FlowContactReasonsConditional extends ContentFieldsBase {\n public contactReasons: HtContactReasonBranch[] = []\n public conditionalResult: string = ''\n public defaultTarget: HtNodeLink\n\n static fromHubtypeCMS(\n component: HtContactReasonsNode,\n botContext: BotContext\n ): FlowContactReasonsConditional {\n const newContactReasonsConditional = new FlowContactReasonsConditional(\n component.id\n )\n newContactReasonsConditional.contactReasons =\n component.content.contact_reasons\n newContactReasonsConditional.defaultTarget =\n component.content.default_target\n newContactReasonsConditional.setFollowUp(botContext)\n return newContactReasonsConditional\n }\n\n private setFollowUp(botContext: BotContext): void {\n const sessionContactReasons =\n botContext.session._hubtype_case_contact_reasons\n\n const matchingBranch = sessionContactReasons\n ? findMatchingContactReasonBranch(\n sessionContactReasons,\n this.contactReasons\n )\n : undefined\n\n if (matchingBranch) {\n this.conditionalResult = matchingBranch.name\n this.followUp = matchingBranch.target\n } else {\n this.conditionalResult = 'default'\n this.followUp = this.defaultTarget\n }\n }\n\n async trackFlow(botContext: BotContext): Promise<void> {\n const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } =\n getCommonFlowContentEventArgsForContentId(botContext, this.id)\n const eventContactReasonsConditional: EventConditionalContactReasons = {\n action: EventAction.ConditionalContactReasons,\n flowThreadId,\n flowId,\n flowName,\n flowNodeId,\n flowNodeContentId,\n flowNodeIsMeaningful: false,\n contactReasons:\n botContext.session._hubtype_case_contact_reasons?.map(\n contactReason => contactReason.name\n ) || [],\n result: this.conditionalResult,\n }\n const { action, ...eventArgs } = eventContactReasonsConditional\n await trackEvent(botContext, action, eventArgs)\n return\n }\n\n async processContent(botContext: BotContext): Promise<void> {\n await this.filterContent(botContext, this)\n await this.trackFlow(botContext)\n return\n }\n\n toBotonic() {\n return <></>\n }\n}\n"],"names":["EventAction","getCommonFlowContentEventArgsForContentId","trackEvent","findMatchingContactReasonBranch","ContentFieldsBase","FlowContactReasonsConditional","component","botContext","newContactReasonsConditional","sessionContactReasons","matchingBranch","undefined","flowThreadId","flowId","flowName","flowNodeId","flowNodeContentId","eventContactReasonsConditional","contactReason","action","eventArgs"],"mappings":";;;;;;;;;;;;AAIsB;AAKF;AACmE;AAC9B;AAOlD,MAAMK,6BAA6BA,SAASD,iBAAiBA;IAKlE,OAAO,eACLE,SAA+B,EAC/BC,UAAsB,EACS;QAC/B,MAAMC,+BAA+B,IAAIH,6BAA6BA,CACpEC,UAAU,EAAE;QAEdE,6BAA6B,cAAc,GACzCF,UAAU,OAAO,CAAC,eAAe;QACnCE,6BAA6B,aAAa,GACxCF,UAAU,OAAO,CAAC,cAAc;QAClCE,6BAA6B,WAAW,CAACD;QACzC,OAAOC;IACT;IAEQ,YAAYD,UAAsB,EAAQ;QAChD,MAAME,wBACJF,WAAW,OAAO,CAAC,6BAA6B;QAElD,MAAMG,iBAAiBD,wBACnBN,+BAA+BA,CAC7BM,uBACA,IAAI,CAAC,cAAc,IAErBE;QAEJ,IAAID,gBAAgB;YAClB,IAAI,CAAC,iBAAiB,GAAGA,eAAe,IAAI;YAC5C,IAAI,CAAC,QAAQ,GAAGA,eAAe,MAAM;QACvC,OAAO;YACL,IAAI,CAAC,iBAAiB,GAAG;YACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa;QACpC;IACF;IAEA,MAAM,UAAUH,UAAsB,EAAiB;QACrD,MAAM,EAAEK,YAAY,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,iBAAiB,EAAE,GACrEf,yCAAyCA,CAACM,YAAY,IAAI,CAAC,EAAE;QAC/D,MAAMU,iCAAiE;YACrE,QAAQjB,qCAAqC;YAC7CY;YACAC;YACAC;YACAC;YACAC;YACA,sBAAsB;YACtB,gBACET,WAAW,OAAO,CAAC,6BAA6B,EAAE,IAChDW,CAAAA,gBAAiBA,cAAc,IAAI,KAChC,EAAE;YACT,QAAQ,IAAI,CAAC,iBAAiB;QAChC;QACA,MAAM,EAAEC,MAAM,EAAE,GAAGC,WAAW,GAAGH;QACjC,MAAMf,UAAUA,CAACK,YAAYY,QAAQC;QACrC;IACF;IAEA,MAAM,eAAeb,UAAsB,EAAiB;QAC1D,MAAM,IAAI,CAAC,aAAa,CAACA,YAAY,IAAI;QACzC,MAAM,IAAI,CAAC,SAAS,CAACA;QACrB;IACF;IAEA,YAAY;QACV,qBAAO;IACT;;QAtEK,qBACE,iBAA0C,EAAE,OAC5C,oBAA4B;;AAqErC"}
@@ -0,0 +1,9 @@
1
+ import type { BotContext } from '@botonic/core';
2
+ import { ContentFieldsBase } from './content-fields-base.js';
3
+ import type { HtDoNothingNode } from './hubtype-fields/index.js';
4
+ export declare class FlowDoNothing extends ContentFieldsBase {
5
+ static fromHubtypeCMS(cmsDoNothing: HtDoNothingNode): FlowDoNothing;
6
+ trackFlow(botContext: BotContext): Promise<void>;
7
+ processContent(botContext: BotContext): Promise<void>;
8
+ toBotonic(): JSX.Element;
9
+ }
@@ -0,0 +1,33 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { trackOneContent } from "../tracking.js";
3
+ import { ContentFieldsBase } from "./content-fields-base.js";
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ class FlowDoNothing extends ContentFieldsBase {
12
+ static fromHubtypeCMS(cmsDoNothing) {
13
+ const newDoNothing = new FlowDoNothing(cmsDoNothing.id);
14
+ newDoNothing.code = cmsDoNothing.code;
15
+ newDoNothing.followUp = cmsDoNothing.follow_up;
16
+ return newDoNothing;
17
+ }
18
+ async trackFlow(botContext) {
19
+ await trackOneContent(botContext, this);
20
+ }
21
+ async processContent(botContext) {
22
+ await this.filterContent(botContext, this);
23
+ await this.trackFlow(botContext);
24
+ return;
25
+ }
26
+ toBotonic() {
27
+ return /*#__PURE__*/ jsx(Fragment, {});
28
+ }
29
+ }
30
+
31
+ export { FlowDoNothing };
32
+
33
+ //# sourceMappingURL=flow-do-nothing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-fields/flow-do-nothing.js","sources":["../../src/content-fields/flow-do-nothing.tsx"],"sourcesContent":["import type { BotContext } from '@botonic/core'\n\nimport { trackOneContent } from '../tracking'\nimport { ContentFieldsBase } from './content-fields-base'\nimport type { HtDoNothingNode } from './hubtype-fields'\n\nexport class FlowDoNothing extends ContentFieldsBase {\n static fromHubtypeCMS(cmsDoNothing: HtDoNothingNode): FlowDoNothing {\n const newDoNothing = new FlowDoNothing(cmsDoNothing.id)\n newDoNothing.code = cmsDoNothing.code\n newDoNothing.followUp = cmsDoNothing.follow_up\n\n return newDoNothing\n }\n\n async trackFlow(botContext: BotContext): Promise<void> {\n await trackOneContent(botContext, this)\n }\n\n async processContent(botContext: BotContext): Promise<void> {\n await this.filterContent(botContext, this)\n await this.trackFlow(botContext)\n return\n }\n\n toBotonic(): JSX.Element {\n return <></>\n }\n}\n"],"names":["trackOneContent","ContentFieldsBase","FlowDoNothing","cmsDoNothing","newDoNothing","botContext"],"mappings":";;;;;;;;AAE6C;AACY;AAGlD,MAAME,aAAaA,SAASD,iBAAiBA;IAClD,OAAO,eAAeE,YAA6B,EAAiB;QAClE,MAAMC,eAAe,IAAIF,aAAaA,CAACC,aAAa,EAAE;QACtDC,aAAa,IAAI,GAAGD,aAAa,IAAI;QACrCC,aAAa,QAAQ,GAAGD,aAAa,SAAS;QAE9C,OAAOC;IACT;IAEA,MAAM,UAAUC,UAAsB,EAAiB;QACrD,MAAML,eAAeA,CAACK,YAAY,IAAI;IACxC;IAEA,MAAM,eAAeA,UAAsB,EAAiB;QAC1D,MAAM,IAAI,CAAC,aAAa,CAACA,YAAY,IAAI;QACzC,MAAM,IAAI,CAAC,SAAS,CAACA;QACrB;IACF;IAEA,YAAyB;QACvB,qBAAO;IACT;AACF"}
@@ -1,15 +1,21 @@
1
1
  import { type BotContext } from '@botonic/core';
2
2
  import type { FlowBuilderApi } from '../api.js';
3
3
  import { ContentFieldsBase } from './content-fields-base.js';
4
- import type { HtHandoffNode, HtQueueLocale } from './hubtype-fields/index.js';
4
+ import { type HtHandoffNode, type HtNodeLink, type HtQueueLocale } from './hubtype-fields/index.js';
5
5
  export declare class FlowHandoff extends ContentFieldsBase {
6
6
  queue?: HtQueueLocale;
7
7
  onFinishPayload?: string;
8
8
  handoffAutoAssign: boolean;
9
9
  hasQueuePositionChangedNotificationsEnabled: boolean;
10
+ hasDifferentiatedCloseTypes: boolean;
11
+ resolvedByAgent?: HtNodeLink;
12
+ discardedByAgent?: HtNodeLink;
13
+ discardedByUser?: HtNodeLink;
14
+ discardedBySystem?: HtNodeLink;
10
15
  isTestIntegration: boolean;
11
16
  static fromHubtypeCMS(cmsHandoff: HtHandoffNode, locale: string, cmsApi: FlowBuilderApi): FlowHandoff;
12
17
  private static getOnFinishPayload;
18
+ resolveOnClosePayload(botContext: BotContext): string;
13
19
  doHandoff(botContext: BotContext): Promise<void>;
14
20
  trackFlow(_botContext: BotContext): Promise<void>;
15
21
  processContent(botContext: BotContext): Promise<void>;
@@ -1,8 +1,14 @@
1
1
  import { Fragment, jsx } from "react/jsx-runtime";
2
2
  import { HandOffBuilder, HelpdeskEvent, isDev, isWebchat } from "@botonic/core";
3
3
  import { WebchatSettings } from "@botonic/react";
4
+ import { ON_CLOSE_HANDOFF_PAYLOAD, SEPARATOR } from "../constants.js";
4
5
  import { getCommonFlowContentEventArgsForContentId } from "../tracking.js";
5
6
  import { ContentFieldsBase } from "./content-fields-base.js";
7
+ import { DiscardType } from "./hubtype-fields/index.js";
8
+
9
+
10
+
11
+
6
12
 
7
13
 
8
14
 
@@ -19,18 +25,50 @@ class FlowHandoff extends ContentFieldsBase {
19
25
  const newHandoff = new FlowHandoff(cmsHandoff.id);
20
26
  newHandoff.code = cmsHandoff.code;
21
27
  newHandoff.queue = FlowHandoff.getQueueByLocale(locale, cmsHandoff.content.queue);
22
- newHandoff.onFinishPayload = FlowHandoff.getOnFinishPayload(cmsHandoff, cmsApi);
28
+ newHandoff.hasDifferentiatedCloseTypes = cmsHandoff.content.has_differentiated_close_types;
29
+ newHandoff.resolvedByAgent = cmsHandoff.content.resolved_by_agent;
30
+ newHandoff.discardedByAgent = cmsHandoff.content.discarded_by_agent;
31
+ newHandoff.discardedByUser = cmsHandoff.content.discarded_by_user;
32
+ newHandoff.discardedBySystem = cmsHandoff.content.discarded_by_system;
23
33
  newHandoff.handoffAutoAssign = cmsHandoff.content.has_auto_assign;
24
34
  newHandoff.hasQueuePositionChangedNotificationsEnabled = cmsHandoff.content.has_queue_position_changed_notifications_enabled;
25
- newHandoff.followUp = cmsHandoff.follow_up;
35
+ newHandoff.onFinishPayload = FlowHandoff.getOnFinishPayload(cmsHandoff, cmsApi);
36
+ newHandoff.followUp = undefined;
26
37
  return newHandoff;
27
38
  }
28
39
  static getOnFinishPayload(cmsHandoff, cmsApi) {
29
- if (cmsHandoff.target?.id) {
40
+ if (cmsHandoff.content.has_differentiated_close_types) {
41
+ return `${ON_CLOSE_HANDOFF_PAYLOAD}${SEPARATOR}${cmsHandoff.id}`;
42
+ } else if (cmsHandoff.target?.id) {
30
43
  return cmsApi.getPayload(cmsHandoff.target);
31
44
  }
32
45
  return undefined;
33
46
  }
47
+ resolveOnClosePayload(botContext) {
48
+ const contactReasons = botContext.session._hubtype_case_contact_reasons || [];
49
+ if (contactReasons.some((reason)=>reason.name === DiscardType.ByAgent)) {
50
+ if (this.discardedByAgent?.id) {
51
+ return this.discardedByAgent.id;
52
+ }
53
+ console.error('No discarded by agent target found');
54
+ }
55
+ if (contactReasons.some((reason)=>reason.name === DiscardType.ByUser)) {
56
+ if (this.discardedByUser?.id) {
57
+ return this.discardedByUser.id;
58
+ }
59
+ console.error('No discarded by user target found');
60
+ }
61
+ if (contactReasons.some((reason)=>reason.name === DiscardType.BySystem)) {
62
+ if (this.discardedBySystem?.id) {
63
+ return this.discardedBySystem.id;
64
+ }
65
+ console.error('No discarded by system target found');
66
+ }
67
+ if (this.resolvedByAgent?.id) {
68
+ return this.resolvedByAgent.id;
69
+ }
70
+ throw new Error('No resolved by agent target found');
71
+ }
34
72
  async doHandoff(botContext) {
35
73
  const handOffBuilder = new HandOffBuilder(botContext.session);
36
74
  handOffBuilder.withAutoAssignOnWaiting(this.handoffAutoAssign);
@@ -1 +1 @@
1
- {"version":3,"file":"content-fields/flow-handoff.js","sources":["../../src/content-fields/flow-handoff.tsx"],"sourcesContent":["import {\n type BotContext,\n HandOffBuilder,\n HelpdeskEvent,\n isDev,\n isWebchat,\n} from '@botonic/core'\nimport { WebchatSettings } from '@botonic/react'\n\nimport type { FlowBuilderApi } from '../api'\nimport { getCommonFlowContentEventArgsForContentId } from '../tracking'\nimport { ContentFieldsBase } from './content-fields-base'\nimport type { HtHandoffNode, HtQueueLocale } from './hubtype-fields'\n\nexport class FlowHandoff extends ContentFieldsBase {\n public queue?: HtQueueLocale\n public onFinishPayload?: string\n public handoffAutoAssign: boolean\n public hasQueuePositionChangedNotificationsEnabled: boolean\n public isTestIntegration: boolean\n\n static fromHubtypeCMS(\n cmsHandoff: HtHandoffNode,\n locale: string,\n cmsApi: FlowBuilderApi\n ): FlowHandoff {\n const newHandoff = new FlowHandoff(cmsHandoff.id)\n newHandoff.code = cmsHandoff.code\n newHandoff.queue = FlowHandoff.getQueueByLocale(\n locale,\n cmsHandoff.content.queue\n )\n newHandoff.onFinishPayload = FlowHandoff.getOnFinishPayload(\n cmsHandoff,\n cmsApi\n )\n newHandoff.handoffAutoAssign = cmsHandoff.content.has_auto_assign\n newHandoff.hasQueuePositionChangedNotificationsEnabled =\n cmsHandoff.content.has_queue_position_changed_notifications_enabled\n newHandoff.followUp = cmsHandoff.follow_up\n\n return newHandoff\n }\n\n private static getOnFinishPayload(\n cmsHandoff: HtHandoffNode,\n cmsApi: FlowBuilderApi\n ): string | undefined {\n if (cmsHandoff.target?.id) {\n return cmsApi.getPayload(cmsHandoff.target)\n }\n\n return undefined\n }\n\n async doHandoff(botContext: BotContext): Promise<void> {\n const handOffBuilder = new HandOffBuilder(botContext.session)\n handOffBuilder.withAutoAssignOnWaiting(this.handoffAutoAssign)\n\n if (this.hasQueuePositionChangedNotificationsEnabled) {\n handOffBuilder.withSubscribeHelpdeskEvents([\n HelpdeskEvent.QueuePositionChanged,\n ])\n }\n\n if (this.onFinishPayload) {\n handOffBuilder.withOnFinishPayload(this.onFinishPayload)\n }\n\n if (this.queue) {\n const language = botContext.getSystemLocale()\n\n handOffBuilder.withQueue(this.queue.id)\n\n const { flowId, flowName, flowNodeId, flowNodeContentId } =\n getCommonFlowContentEventArgsForContentId(botContext, this.id)\n\n handOffBuilder.withBotEvent({\n flowId,\n flowName,\n flowNodeId,\n flowNodeContentId,\n })\n\n handOffBuilder.withExtraData({\n language,\n })\n\n await handOffBuilder.handOff()\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async trackFlow(_botContext: BotContext): Promise<void> {\n // TODO: Not apply for this content because backend track handoff success event\n }\n\n async processContent(botContext: BotContext): Promise<void> {\n await this.filterContent(botContext, this)\n await this.doHandoff(botContext)\n return\n }\n\n toBotonic(botContext: BotContext): JSX.Element {\n return isDev(botContext.session) || isWebchat(botContext.session) ? (\n <WebchatSettings key={this.id} enableUserInput={true} />\n ) : (\n <></>\n )\n }\n}\n"],"names":["HandOffBuilder","HelpdeskEvent","isDev","isWebchat","WebchatSettings","getCommonFlowContentEventArgsForContentId","ContentFieldsBase","FlowHandoff","cmsHandoff","locale","cmsApi","newHandoff","undefined","botContext","handOffBuilder","language","flowId","flowName","flowNodeId","flowNodeContentId","_botContext"],"mappings":";;;;;;;;;;;;AAMsB;AAC0B;AAGuB;AACd;AAGlD,MAAMO,WAAWA,SAASD,iBAAiBA;IAOhD,OAAO,eACLE,UAAyB,EACzBC,MAAc,EACdC,MAAsB,EACT;QACb,MAAMC,aAAa,IAAIJ,WAAWA,CAACC,WAAW,EAAE;QAChDG,WAAW,IAAI,GAAGH,WAAW,IAAI;QACjCG,WAAW,KAAK,GAAGJ,WAAWA,CAAC,gBAAgB,CAC7CE,QACAD,WAAW,OAAO,CAAC,KAAK;QAE1BG,WAAW,eAAe,GAAGJ,WAAWA,CAAC,kBAAkB,CACzDC,YACAE;QAEFC,WAAW,iBAAiB,GAAGH,WAAW,OAAO,CAAC,eAAe;QACjEG,WAAW,2CAA2C,GACpDH,WAAW,OAAO,CAAC,gDAAgD;QACrEG,WAAW,QAAQ,GAAGH,WAAW,SAAS;QAE1C,OAAOG;IACT;IAEA,OAAe,mBACbH,UAAyB,EACzBE,MAAsB,EACF;QACpB,IAAIF,WAAW,MAAM,EAAE,IAAI;YACzB,OAAOE,OAAO,UAAU,CAACF,WAAW,MAAM;QAC5C;QAEA,OAAOI;IACT;IAEA,MAAM,UAAUC,UAAsB,EAAiB;QACrD,MAAMC,iBAAiB,IAAId,cAAcA,CAACa,WAAW,OAAO;QAC5DC,eAAe,uBAAuB,CAAC,IAAI,CAAC,iBAAiB;QAE7D,IAAI,IAAI,CAAC,2CAA2C,EAAE;YACpDA,eAAe,2BAA2B,CAAC;gBACzCb,kCAAkC;aACnC;QACH;QAEA,IAAI,IAAI,CAAC,eAAe,EAAE;YACxBa,eAAe,mBAAmB,CAAC,IAAI,CAAC,eAAe;QACzD;QAEA,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,MAAMC,WAAWF,WAAW,eAAe;YAE3CC,eAAe,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAEtC,MAAM,EAAEE,MAAM,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,iBAAiB,EAAE,GACvDd,yCAAyCA,CAACQ,YAAY,IAAI,CAAC,EAAE;YAE/DC,eAAe,YAAY,CAAC;gBAC1BE;gBACAC;gBACAC;gBACAC;YACF;YAEAL,eAAe,aAAa,CAAC;gBAC3BC;YACF;YAEA,MAAMD,eAAe,OAAO;QAC9B;IACF;IAEA,6DAA6D;IAC7D,MAAM,UAAUM,WAAuB,EAAiB;IACtD,+EAA+E;IACjF;IAEA,MAAM,eAAeP,UAAsB,EAAiB;QAC1D,MAAM,IAAI,CAAC,aAAa,CAACA,YAAY,IAAI;QACzC,MAAM,IAAI,CAAC,SAAS,CAACA;QACrB;IACF;IAEA,UAAUA,UAAsB,EAAe;QAC7C,OAAOX,KAAKA,CAACW,WAAW,OAAO,KAAKV,SAASA,CAACU,WAAW,OAAO,kBAC9D,IAACT,eAAeA;YAAe,iBAAiB;WAA1B,IAAI,CAAC,EAAE,kBAE7B;IAEJ;AACF"}
1
+ {"version":3,"file":"content-fields/flow-handoff.js","sources":["../../src/content-fields/flow-handoff.tsx"],"sourcesContent":["import {\n type BotContext,\n HandOffBuilder,\n HelpdeskEvent,\n isDev,\n isWebchat,\n} from '@botonic/core'\nimport { WebchatSettings } from '@botonic/react'\nimport type { FlowBuilderApi } from '../api'\nimport { ON_CLOSE_HANDOFF_PAYLOAD, SEPARATOR } from '../constants'\nimport { getCommonFlowContentEventArgsForContentId } from '../tracking'\nimport { ContentFieldsBase } from './content-fields-base'\nimport {\n DiscardType,\n type HtHandoffNode,\n type HtNodeLink,\n type HtQueueLocale,\n} from './hubtype-fields'\n\nexport class FlowHandoff extends ContentFieldsBase {\n public queue?: HtQueueLocale\n public onFinishPayload?: string\n public handoffAutoAssign: boolean\n public hasQueuePositionChangedNotificationsEnabled: boolean\n public hasDifferentiatedCloseTypes: boolean\n public resolvedByAgent?: HtNodeLink\n public discardedByAgent?: HtNodeLink\n public discardedByUser?: HtNodeLink\n public discardedBySystem?: HtNodeLink\n public isTestIntegration: boolean\n\n static fromHubtypeCMS(\n cmsHandoff: HtHandoffNode,\n locale: string,\n cmsApi: FlowBuilderApi\n ): FlowHandoff {\n const newHandoff = new FlowHandoff(cmsHandoff.id)\n newHandoff.code = cmsHandoff.code\n newHandoff.queue = FlowHandoff.getQueueByLocale(\n locale,\n cmsHandoff.content.queue\n )\n newHandoff.hasDifferentiatedCloseTypes =\n cmsHandoff.content.has_differentiated_close_types\n newHandoff.resolvedByAgent = cmsHandoff.content.resolved_by_agent\n newHandoff.discardedByAgent = cmsHandoff.content.discarded_by_agent\n newHandoff.discardedByUser = cmsHandoff.content.discarded_by_user\n newHandoff.discardedBySystem = cmsHandoff.content.discarded_by_system\n newHandoff.handoffAutoAssign = cmsHandoff.content.has_auto_assign\n newHandoff.hasQueuePositionChangedNotificationsEnabled =\n cmsHandoff.content.has_queue_position_changed_notifications_enabled\n\n newHandoff.onFinishPayload = FlowHandoff.getOnFinishPayload(\n cmsHandoff,\n cmsApi\n )\n newHandoff.followUp = undefined\n\n return newHandoff\n }\n\n private static getOnFinishPayload(\n cmsHandoff: HtHandoffNode,\n cmsApi: FlowBuilderApi\n ): string | undefined {\n if (cmsHandoff.content.has_differentiated_close_types) {\n return `${ON_CLOSE_HANDOFF_PAYLOAD}${SEPARATOR}${cmsHandoff.id}`\n } else if (cmsHandoff.target?.id) {\n return cmsApi.getPayload(cmsHandoff.target)\n }\n\n return undefined\n }\n\n resolveOnClosePayload(botContext: BotContext): string {\n const contactReasons =\n botContext.session._hubtype_case_contact_reasons || []\n\n if (contactReasons.some(reason => reason.name === DiscardType.ByAgent)) {\n if (this.discardedByAgent?.id) {\n return this.discardedByAgent.id\n }\n console.error('No discarded by agent target found')\n }\n if (contactReasons.some(reason => reason.name === DiscardType.ByUser)) {\n if (this.discardedByUser?.id) {\n return this.discardedByUser.id\n }\n console.error('No discarded by user target found')\n }\n if (contactReasons.some(reason => reason.name === DiscardType.BySystem)) {\n if (this.discardedBySystem?.id) {\n return this.discardedBySystem.id\n }\n console.error('No discarded by system target found')\n }\n if (this.resolvedByAgent?.id) {\n return this.resolvedByAgent.id\n }\n throw new Error('No resolved by agent target found')\n }\n\n async doHandoff(botContext: BotContext): Promise<void> {\n const handOffBuilder = new HandOffBuilder(botContext.session)\n handOffBuilder.withAutoAssignOnWaiting(this.handoffAutoAssign)\n\n if (this.hasQueuePositionChangedNotificationsEnabled) {\n handOffBuilder.withSubscribeHelpdeskEvents([\n HelpdeskEvent.QueuePositionChanged,\n ])\n }\n\n if (this.onFinishPayload) {\n handOffBuilder.withOnFinishPayload(this.onFinishPayload)\n }\n\n if (this.queue) {\n const language = botContext.getSystemLocale()\n\n handOffBuilder.withQueue(this.queue.id)\n\n const { flowId, flowName, flowNodeId, flowNodeContentId } =\n getCommonFlowContentEventArgsForContentId(botContext, this.id)\n\n handOffBuilder.withBotEvent({\n flowId,\n flowName,\n flowNodeId,\n flowNodeContentId,\n })\n\n handOffBuilder.withExtraData({\n language,\n })\n\n await handOffBuilder.handOff()\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async trackFlow(_botContext: BotContext): Promise<void> {\n // TODO: Not apply for this content because backend track handoff success event\n }\n\n async processContent(botContext: BotContext): Promise<void> {\n await this.filterContent(botContext, this)\n await this.doHandoff(botContext)\n return\n }\n\n toBotonic(botContext: BotContext): JSX.Element {\n return isDev(botContext.session) || isWebchat(botContext.session) ? (\n <WebchatSettings key={this.id} enableUserInput={true} />\n ) : (\n <></>\n )\n }\n}\n"],"names":["HandOffBuilder","HelpdeskEvent","isDev","isWebchat","WebchatSettings","ON_CLOSE_HANDOFF_PAYLOAD","SEPARATOR","getCommonFlowContentEventArgsForContentId","ContentFieldsBase","DiscardType","FlowHandoff","cmsHandoff","locale","cmsApi","newHandoff","undefined","botContext","contactReasons","reason","console","Error","handOffBuilder","language","flowId","flowName","flowNodeId","flowNodeContentId","_botContext"],"mappings":";;;;;;;;;;;;;;;;AAMsB;AAC0B;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,eAAe,YAAY,CAAC;gBAC1BE;gBACAC;gBACAC;gBACAC;YACF;YAEAL,eAAe,aAAa,CAAC;gBAC3BC;YACF;YAEA,MAAMD,eAAe,OAAO;QAC9B;IACF;IAEA,6DAA6D;IAC7D,MAAM,UAAUM,WAAuB,EAAiB;IACtD,+EAA+E;IACjF;IAEA,MAAM,eAAeX,UAAsB,EAAiB;QAC1D,MAAM,IAAI,CAAC,aAAa,CAACA,YAAY,IAAI;QACzC,MAAM,IAAI,CAAC,SAAS,CAACA;QACrB;IACF;IAEA,UAAUA,UAAsB,EAAe;QAC7C,OAAOd,KAAKA,CAACc,WAAW,OAAO,KAAKb,SAASA,CAACa,WAAW,OAAO,kBAC9D,IAACZ,eAAeA;YAAe,iBAAiB;WAA1B,IAAI,CAAC,EAAE,kBAE7B;IAEJ;AACF"}
@@ -23,6 +23,7 @@ class FlowWhatsappRequestContactInfoNode extends ContentFieldsBase {
23
23
  return requestContactInfo;
24
24
  }
25
25
  static fromAIAgent(id, message, botContext) {
26
+ botContext.session.whatsapp_request_contact = undefined;
26
27
  if (!isWhatsapp(botContext.session)) {
27
28
  return /*#__PURE__*/ jsx(Text, {
28
29
  children: message.content.text
@@ -1 +1 @@
1
- {"version":3,"file":"content-fields/flow-whatsapp-request-contact-info.js","sources":["../../src/content-fields/flow-whatsapp-request-contact-info.tsx"],"sourcesContent":["import {\n type BotContext,\n isWhatsapp,\n type RequestContactInfoMessage,\n} from '@botonic/core'\nimport { Text, WhatsappRequestContactInfo } from '@botonic/react'\n\nimport { trackOneContent } from '../tracking'\nimport { ContentFieldsBase } from './content-fields-base'\nimport type { HtWhatsappRequestContactInfoNode } from './hubtype-fields'\n\nexport class FlowWhatsappRequestContactInfoNode extends ContentFieldsBase {\n public text = ''\n\n static fromHubtypeCMS(\n component: HtWhatsappRequestContactInfoNode,\n locale: string\n ): FlowWhatsappRequestContactInfoNode {\n const requestContactInfo = new FlowWhatsappRequestContactInfoNode(\n component.id\n )\n requestContactInfo.code = component.code\n requestContactInfo.text =\n FlowWhatsappRequestContactInfoNode.getTextByLocale(\n locale,\n component.content.text\n )\n requestContactInfo.followUp = component.follow_up\n\n return requestContactInfo\n }\n\n static fromAIAgent(\n id: string,\n message: RequestContactInfoMessage,\n botContext: BotContext\n ): JSX.Element {\n if (!isWhatsapp(botContext.session)) {\n return <Text key={id}>{message.content.text}</Text>\n }\n\n return <WhatsappRequestContactInfo key={id} body={message.content.text} />\n }\n\n async trackFlow(botContext: BotContext): Promise<void> {\n await trackOneContent(botContext, this)\n }\n\n async processContent(botContext: BotContext): Promise<void> {\n await this.filterContent(botContext, this)\n await this.trackFlow(botContext)\n return\n }\n\n toBotonic(botContext: BotContext): JSX.Element {\n const replacedText = this.replaceVariables(this.text, botContext)\n\n if (!isWhatsapp(botContext.session)) {\n return <Text>{replacedText}</Text>\n }\n\n return <WhatsappRequestContactInfo key={this.id} body={replacedText} />\n }\n}\n"],"names":["isWhatsapp","Text","WhatsappRequestContactInfo","trackOneContent","ContentFieldsBase","FlowWhatsappRequestContactInfoNode","component","locale","requestContactInfo","id","message","botContext","replacedText"],"mappings":";;;;;;;;;;;;AAIsB;AAC2C;AAEpB;AACY;AAGlD,MAAMK,kCAAkCA,SAASD,iBAAiBA;IAGvE,OAAO,eACLE,SAA2C,EAC3CC,MAAc,EACsB;QACpC,MAAMC,qBAAqB,IAAIH,kCAAkCA,CAC/DC,UAAU,EAAE;QAEdE,mBAAmB,IAAI,GAAGF,UAAU,IAAI;QACxCE,mBAAmB,IAAI,GACrBH,kCAAkCA,CAAC,eAAe,CAChDE,QACAD,UAAU,OAAO,CAAC,IAAI;QAE1BE,mBAAmB,QAAQ,GAAGF,UAAU,SAAS;QAEjD,OAAOE;IACT;IAEA,OAAO,YACLC,EAAU,EACVC,OAAkC,EAClCC,UAAsB,EACT;QACb,IAAI,CAACX,UAAUA,CAACW,WAAW,OAAO,GAAG;YACnC,qBAAO,IAACV,IAAIA;0BAAWS,QAAQ,OAAO,CAAC,IAAI;eAAzBD;QACpB;QAEA,qBAAO,IAACP,0BAA0BA;YAAU,MAAMQ,QAAQ,OAAO,CAAC,IAAI;WAA9BD;IAC1C;IAEA,MAAM,UAAUE,UAAsB,EAAiB;QACrD,MAAMR,eAAeA,CAACQ,YAAY,IAAI;IACxC;IAEA,MAAM,eAAeA,UAAsB,EAAiB;QAC1D,MAAM,IAAI,CAAC,aAAa,CAACA,YAAY,IAAI;QACzC,MAAM,IAAI,CAAC,SAAS,CAACA;QACrB;IACF;IAEA,UAAUA,UAAsB,EAAe;QAC7C,MAAMC,eAAe,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAED;QAEtD,IAAI,CAACX,UAAUA,CAACW,WAAW,OAAO,GAAG;YACnC,qBAAO,IAACV,IAAIA;0BAAEW;;QAChB;QAEA,qBAAO,IAACV,0BAA0BA;YAAe,MAAMU;WAAf,IAAI,CAAC,EAAE;IACjD;;QAnDK,qBACE,OAAO;;AAmDhB"}
1
+ {"version":3,"file":"content-fields/flow-whatsapp-request-contact-info.js","sources":["../../src/content-fields/flow-whatsapp-request-contact-info.tsx"],"sourcesContent":["import {\n type BotContext,\n isWhatsapp,\n type RequestContactInfoMessage,\n} from '@botonic/core'\nimport { Text, WhatsappRequestContactInfo } from '@botonic/react'\n\nimport { trackOneContent } from '../tracking'\nimport { ContentFieldsBase } from './content-fields-base'\nimport type { HtWhatsappRequestContactInfoNode } from './hubtype-fields'\n\nexport class FlowWhatsappRequestContactInfoNode extends ContentFieldsBase {\n public text = ''\n\n static fromHubtypeCMS(\n component: HtWhatsappRequestContactInfoNode,\n locale: string\n ): FlowWhatsappRequestContactInfoNode {\n const requestContactInfo = new FlowWhatsappRequestContactInfoNode(\n component.id\n )\n requestContactInfo.code = component.code\n requestContactInfo.text =\n FlowWhatsappRequestContactInfoNode.getTextByLocale(\n locale,\n component.content.text\n )\n requestContactInfo.followUp = component.follow_up\n\n return requestContactInfo\n }\n\n static fromAIAgent(\n id: string,\n message: RequestContactInfoMessage,\n botContext: BotContext\n ): JSX.Element {\n botContext.session.whatsapp_request_contact = undefined\n\n if (!isWhatsapp(botContext.session)) {\n return <Text key={id}>{message.content.text}</Text>\n }\n\n return <WhatsappRequestContactInfo key={id} body={message.content.text} />\n }\n\n async trackFlow(botContext: BotContext): Promise<void> {\n await trackOneContent(botContext, this)\n }\n\n async processContent(botContext: BotContext): Promise<void> {\n await this.filterContent(botContext, this)\n await this.trackFlow(botContext)\n return\n }\n\n toBotonic(botContext: BotContext): JSX.Element {\n const replacedText = this.replaceVariables(this.text, botContext)\n\n if (!isWhatsapp(botContext.session)) {\n return <Text>{replacedText}</Text>\n }\n\n return <WhatsappRequestContactInfo key={this.id} body={replacedText} />\n }\n}\n"],"names":["isWhatsapp","Text","WhatsappRequestContactInfo","trackOneContent","ContentFieldsBase","FlowWhatsappRequestContactInfoNode","component","locale","requestContactInfo","id","message","botContext","undefined","replacedText"],"mappings":";;;;;;;;;;;;AAIsB;AAC2C;AAEpB;AACY;AAGlD,MAAMK,kCAAkCA,SAASD,iBAAiBA;IAGvE,OAAO,eACLE,SAA2C,EAC3CC,MAAc,EACsB;QACpC,MAAMC,qBAAqB,IAAIH,kCAAkCA,CAC/DC,UAAU,EAAE;QAEdE,mBAAmB,IAAI,GAAGF,UAAU,IAAI;QACxCE,mBAAmB,IAAI,GACrBH,kCAAkCA,CAAC,eAAe,CAChDE,QACAD,UAAU,OAAO,CAAC,IAAI;QAE1BE,mBAAmB,QAAQ,GAAGF,UAAU,SAAS;QAEjD,OAAOE;IACT;IAEA,OAAO,YACLC,EAAU,EACVC,OAAkC,EAClCC,UAAsB,EACT;QACbA,WAAW,OAAO,CAAC,wBAAwB,GAAGC;QAE9C,IAAI,CAACZ,UAAUA,CAACW,WAAW,OAAO,GAAG;YACnC,qBAAO,IAACV,IAAIA;0BAAWS,QAAQ,OAAO,CAAC,IAAI;eAAzBD;QACpB;QAEA,qBAAO,IAACP,0BAA0BA;YAAU,MAAMQ,QAAQ,OAAO,CAAC,IAAI;WAA9BD;IAC1C;IAEA,MAAM,UAAUE,UAAsB,EAAiB;QACrD,MAAMR,eAAeA,CAACQ,YAAY,IAAI;IACxC;IAEA,MAAM,eAAeA,UAAsB,EAAiB;QAC1D,MAAM,IAAI,CAAC,aAAa,CAACA,YAAY,IAAI;QACzC,MAAM,IAAI,CAAC,SAAS,CAACA;QACrB;IACF;IAEA,UAAUA,UAAsB,EAAe;QAC7C,MAAME,eAAe,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAEF;QAEtD,IAAI,CAACX,UAAUA,CAACW,WAAW,OAAO,GAAG;YACnC,qBAAO,IAACV,IAAIA;0BAAEY;;QAChB;QAEA,qBAAO,IAACX,0BAA0BA;YAAe,MAAMW;WAAf,IAAI,CAAC,EAAE;IACjD;;QArDK,qBACE,OAAO;;AAqDhB"}
@@ -0,0 +1,16 @@
1
+ import type { HtBaseNode, HtNodeLink } from './common.js';
2
+ import type { HtNodeWithContentType } from './node-types.js';
3
+ export interface HtContactReasonBranch {
4
+ id: string;
5
+ name: string;
6
+ project_id: string;
7
+ project_name: string;
8
+ target: HtNodeLink;
9
+ }
10
+ export interface HtContactReasonsNode extends HtBaseNode {
11
+ type: HtNodeWithContentType.CONTACT_REASONS_CONDITION;
12
+ content: {
13
+ contact_reasons: HtContactReasonBranch[];
14
+ default_target: HtNodeLink;
15
+ };
16
+ }
@@ -0,0 +1,4 @@
1
+
2
+
3
+
4
+ //# sourceMappingURL=contact-reasons-conditional.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-fields/hubtype-fields/contact-reasons-conditional.js","sources":["../../../src/content-fields/hubtype-fields/contact-reasons-conditional.ts"],"sourcesContent":["import type { HtBaseNode, HtNodeLink } from './common'\nimport type { HtNodeWithContentType } from './node-types'\n\nexport interface HtContactReasonBranch {\n id: string\n name: string\n project_id: string\n project_name: string\n target: HtNodeLink\n}\n\nexport interface HtContactReasonsNode extends HtBaseNode {\n type: HtNodeWithContentType.CONTACT_REASONS_CONDITION\n content: {\n contact_reasons: HtContactReasonBranch[]\n default_target: HtNodeLink\n }\n}\n"],"names":[],"mappings":"AAiBC"}
@@ -0,0 +1,6 @@
1
+ import type { HtBaseNode } from './common.js';
2
+ import type { HtNodeWithContentType } from './node-types.js';
3
+ export interface HtDoNothingNode extends HtBaseNode {
4
+ id: string;
5
+ type: HtNodeWithContentType.DO_NOTHING;
6
+ }
@@ -0,0 +1,4 @@
1
+
2
+
3
+
4
+ //# sourceMappingURL=do-nothing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-fields/hubtype-fields/do-nothing.js","sources":["../../../src/content-fields/hubtype-fields/do-nothing.ts"],"sourcesContent":["import type { HtBaseNode } from './common'\nimport type { HtNodeWithContentType } from './node-types'\n\nexport interface HtDoNothingNode extends HtBaseNode {\n id: string\n type: HtNodeWithContentType.DO_NOTHING\n}\n"],"names":[],"mappings":"AAMC"}
@@ -1,5 +1,10 @@
1
- import type { HtBaseNode, HtPayloadLocale, HtQueueLocale } from './common.js';
1
+ import type { HtBaseNode, HtNodeLink, HtPayloadLocale, HtQueueLocale } from './common.js';
2
2
  import type { HtNodeWithContentType } from './node-types.js';
3
+ export declare enum DiscardType {
4
+ ByAgent = "discarded",
5
+ ByUser = "discarded_by_user",
6
+ BySystem = "discarded_by_system"
7
+ }
3
8
  export interface HtHandoffNode extends HtBaseNode {
4
9
  type: HtNodeWithContentType.HANDOFF;
5
10
  content: {
@@ -7,5 +12,10 @@ export interface HtHandoffNode extends HtBaseNode {
7
12
  payload: HtPayloadLocale[];
8
13
  has_auto_assign: boolean;
9
14
  has_queue_position_changed_notifications_enabled: boolean;
15
+ has_differentiated_close_types: boolean;
16
+ resolved_by_agent?: HtNodeLink;
17
+ discarded_by_agent?: HtNodeLink;
18
+ discarded_by_user?: HtNodeLink;
19
+ discarded_by_system?: HtNodeLink;
10
20
  };
11
21
  }
@@ -1,4 +1,10 @@
1
+ var handoff_DiscardType = /*#__PURE__*/ function(DiscardType) {
2
+ DiscardType["ByAgent"] = "discarded";
3
+ DiscardType["ByUser"] = "discarded_by_user";
4
+ DiscardType["BySystem"] = "discarded_by_system";
5
+ return DiscardType;
6
+ }({});
1
7
 
2
-
8
+ export { handoff_DiscardType as DiscardType };
3
9
 
4
10
  //# sourceMappingURL=handoff.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"content-fields/hubtype-fields/handoff.js","sources":["../../../src/content-fields/hubtype-fields/handoff.ts"],"sourcesContent":["import type { HtBaseNode, HtPayloadLocale, HtQueueLocale } from './common'\nimport type { HtNodeWithContentType } from './node-types'\n\nexport interface HtHandoffNode extends HtBaseNode {\n type: HtNodeWithContentType.HANDOFF\n content: {\n queue: HtQueueLocale[]\n payload: HtPayloadLocale[]\n has_auto_assign: boolean\n has_queue_position_changed_notifications_enabled: boolean\n }\n}\n"],"names":[],"mappings":"AAWC"}
1
+ {"version":3,"file":"content-fields/hubtype-fields/handoff.js","sources":["../../../src/content-fields/hubtype-fields/handoff.ts"],"sourcesContent":["import type {\n HtBaseNode,\n HtNodeLink,\n HtPayloadLocale,\n HtQueueLocale,\n} from './common'\nimport type { HtNodeWithContentType } from './node-types'\n\nexport enum DiscardType {\n ByAgent = 'discarded',\n ByUser = 'discarded_by_user',\n BySystem = 'discarded_by_system',\n}\n\nexport interface HtHandoffNode extends HtBaseNode {\n type: HtNodeWithContentType.HANDOFF\n content: {\n queue: HtQueueLocale[]\n payload: HtPayloadLocale[]\n has_auto_assign: boolean\n has_queue_position_changed_notifications_enabled: boolean\n has_differentiated_close_types: boolean\n resolved_by_agent?: HtNodeLink\n discarded_by_agent?: HtNodeLink\n discarded_by_user?: HtNodeLink\n discarded_by_system?: HtNodeLink\n }\n}\n"],"names":["DiscardType"],"mappings":"AAQO,IAAKA,mBAAWA,0BAAXA;;;;WAAAA;MAIX"}
@@ -6,6 +6,7 @@ export * from './capture-user-input.js';
6
6
  export * from './carousel.js';
7
7
  export * from './common.js';
8
8
  export * from './custom-conditional-v2.js';
9
+ export * from './do-nothing.js';
9
10
  export * from './fallback.js';
10
11
  export * from './function.js';
11
12
  export * from './go-to-flow.js';