@botonic/plugin-ai-agents 0.57.0-rslib-esm.2 → 0.57.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 (225) hide show
  1. package/lib/{agents → cjs/agents}/base-agent.d.ts +4 -4
  2. package/lib/cjs/agents/base-agent.js +39 -0
  3. package/lib/cjs/agents/base-agent.js.map +1 -0
  4. package/lib/cjs/agents/index.d.ts +2 -0
  5. package/lib/cjs/agents/index.js +8 -0
  6. package/lib/cjs/agents/index.js.map +1 -0
  7. package/lib/{agents → cjs/agents}/router-agent.d.ts +5 -5
  8. package/lib/cjs/agents/router-agent.js +33 -0
  9. package/lib/cjs/agents/router-agent.js.map +1 -0
  10. package/lib/{agents → cjs/agents}/specialist-agent.d.ts +5 -5
  11. package/lib/{agents → cjs/agents}/specialist-agent.js +45 -65
  12. package/lib/cjs/agents/specialist-agent.js.map +1 -0
  13. package/lib/{bot-config-tools.d.ts → cjs/bot-config-tools.d.ts} +1 -1
  14. package/lib/cjs/bot-config-tools.js +18 -0
  15. package/lib/cjs/bot-config-tools.js.map +1 -0
  16. package/lib/cjs/constants.js +25 -0
  17. package/lib/cjs/constants.js.map +1 -0
  18. package/lib/{debug-logger.d.ts → cjs/debug-logger.d.ts} +1 -1
  19. package/lib/{debug-logger.js → cjs/debug-logger.js} +9 -14
  20. package/lib/cjs/debug-logger.js.map +1 -0
  21. package/lib/cjs/guardrails/index.d.ts +1 -0
  22. package/lib/cjs/guardrails/index.js +5 -0
  23. package/lib/cjs/guardrails/index.js.map +1 -0
  24. package/lib/{guardrails → cjs/guardrails}/input.d.ts +2 -2
  25. package/lib/cjs/guardrails/input.js +96 -0
  26. package/lib/cjs/guardrails/input.js.map +1 -0
  27. package/lib/{index.d.ts → cjs/index.d.ts} +3 -3
  28. package/lib/{index.js → cjs/index.js} +75 -114
  29. package/lib/cjs/index.js.map +1 -0
  30. package/lib/{llm-config.d.ts → cjs/llm-config.d.ts} +1 -1
  31. package/lib/cjs/llm-config.js +121 -0
  32. package/lib/cjs/llm-config.js.map +1 -0
  33. package/lib/{runners → cjs/runners}/base-runner.d.ts +4 -4
  34. package/lib/{runners → cjs/runners}/base-runner.js +74 -81
  35. package/lib/cjs/runners/base-runner.js.map +1 -0
  36. package/lib/cjs/runners/index.d.ts +2 -0
  37. package/lib/cjs/runners/index.js +8 -0
  38. package/lib/cjs/runners/index.js.map +1 -0
  39. package/lib/{runners → cjs/runners}/router-runner.d.ts +2 -2
  40. package/lib/{runners → cjs/runners}/router-runner.js +14 -19
  41. package/lib/cjs/runners/router-runner.js.map +1 -0
  42. package/lib/{runners → cjs/runners}/specialist-runner.d.ts +1 -1
  43. package/lib/cjs/runners/specialist-runner.js +8 -0
  44. package/lib/cjs/runners/specialist-runner.js.map +1 -0
  45. package/lib/{services → cjs/services}/hubtype-api-client.d.ts +2 -2
  46. package/lib/cjs/services/hubtype-api-client.js +176 -0
  47. package/lib/cjs/services/hubtype-api-client.js.map +1 -0
  48. package/lib/{services → cjs/services}/types.d.ts +1 -1
  49. package/lib/cjs/services/types.js +13 -0
  50. package/lib/cjs/services/types.js.map +1 -0
  51. package/lib/cjs/structured-output/bot-executor.js +18 -0
  52. package/lib/cjs/structured-output/bot-executor.js.map +1 -0
  53. package/lib/cjs/structured-output/carousel.js +23 -0
  54. package/lib/cjs/structured-output/carousel.js.map +1 -0
  55. package/lib/cjs/structured-output/do-nothing.d.ts +6 -0
  56. package/lib/cjs/structured-output/do-nothing.js +11 -0
  57. package/lib/cjs/structured-output/do-nothing.js.map +1 -0
  58. package/lib/cjs/structured-output/exit.js +11 -0
  59. package/lib/cjs/structured-output/exit.js.map +1 -0
  60. package/lib/{structured-output → cjs/structured-output}/index.d.ts +4 -0
  61. package/lib/cjs/structured-output/index.js +47 -0
  62. package/lib/cjs/structured-output/index.js.map +1 -0
  63. package/lib/cjs/structured-output/request-contact-info.js +14 -0
  64. package/lib/cjs/structured-output/request-contact-info.js.map +1 -0
  65. package/lib/cjs/structured-output/text-with-buttons.js +24 -0
  66. package/lib/cjs/structured-output/text-with-buttons.js.map +1 -0
  67. package/lib/cjs/structured-output/text.js +14 -0
  68. package/lib/cjs/structured-output/text.js.map +1 -0
  69. package/lib/{tools → cjs/tools}/index.d.ts +2 -2
  70. package/lib/cjs/tools/index.js +8 -0
  71. package/lib/cjs/tools/index.js.map +1 -0
  72. package/lib/{tools → cjs/tools}/retrieve-knowledge.d.ts +2 -2
  73. package/lib/cjs/tools/retrieve-knowledge.js +34 -0
  74. package/lib/cjs/tools/retrieve-knowledge.js.map +1 -0
  75. package/lib/{types.d.ts → cjs/types.d.ts} +1 -1
  76. package/lib/cjs/types.js +3 -0
  77. package/lib/cjs/types.js.map +1 -0
  78. package/lib/esm/agents/base-agent.d.ts +28 -0
  79. package/lib/esm/agents/base-agent.js +39 -0
  80. package/lib/esm/agents/base-agent.js.map +1 -0
  81. package/lib/esm/agents/index.d.ts +2 -0
  82. package/lib/esm/agents/index.js +8 -0
  83. package/lib/esm/agents/index.js.map +1 -0
  84. package/lib/esm/agents/router-agent.d.ts +25 -0
  85. package/lib/esm/agents/router-agent.js +33 -0
  86. package/lib/esm/agents/router-agent.js.map +1 -0
  87. package/lib/esm/agents/specialist-agent.d.ts +39 -0
  88. package/lib/esm/agents/specialist-agent.js +108 -0
  89. package/lib/esm/agents/specialist-agent.js.map +1 -0
  90. package/lib/esm/bot-config-tools.d.ts +7 -0
  91. package/lib/esm/bot-config-tools.js +18 -0
  92. package/lib/esm/bot-config-tools.js.map +1 -0
  93. package/lib/esm/constants.d.ts +21 -0
  94. package/lib/esm/constants.js +25 -0
  95. package/lib/esm/constants.js.map +1 -0
  96. package/lib/esm/debug-logger.d.ts +33 -0
  97. package/lib/esm/debug-logger.js +116 -0
  98. package/lib/esm/debug-logger.js.map +1 -0
  99. package/lib/esm/guardrails/index.d.ts +1 -0
  100. package/lib/esm/guardrails/index.js +5 -0
  101. package/lib/esm/guardrails/index.js.map +1 -0
  102. package/lib/esm/guardrails/input.d.ts +10 -0
  103. package/lib/esm/guardrails/input.js +96 -0
  104. package/lib/esm/guardrails/input.js.map +1 -0
  105. package/lib/esm/index.d.ts +22 -0
  106. package/lib/esm/index.js +220 -0
  107. package/lib/esm/index.js.map +1 -0
  108. package/lib/esm/llm-config.d.ts +30 -0
  109. package/lib/esm/llm-config.js +121 -0
  110. package/lib/esm/llm-config.js.map +1 -0
  111. package/lib/esm/runners/base-runner.d.ts +31 -0
  112. package/lib/esm/runners/base-runner.js +194 -0
  113. package/lib/esm/runners/base-runner.js.map +1 -0
  114. package/lib/esm/runners/index.d.ts +2 -0
  115. package/lib/esm/runners/index.js +8 -0
  116. package/lib/esm/runners/index.js.map +1 -0
  117. package/lib/esm/runners/router-runner.d.ts +8 -0
  118. package/lib/esm/runners/router-runner.js +44 -0
  119. package/lib/esm/runners/router-runner.js.map +1 -0
  120. package/lib/esm/runners/specialist-runner.d.ts +4 -0
  121. package/lib/esm/runners/specialist-runner.js +8 -0
  122. package/lib/esm/runners/specialist-runner.js.map +1 -0
  123. package/lib/esm/services/hubtype-api-client.d.ts +13 -0
  124. package/lib/esm/services/hubtype-api-client.js +176 -0
  125. package/lib/esm/services/hubtype-api-client.js.map +1 -0
  126. package/lib/esm/services/types.d.ts +72 -0
  127. package/lib/esm/services/types.js +13 -0
  128. package/lib/esm/services/types.js.map +1 -0
  129. package/lib/esm/structured-output/bot-executor.d.ts +13 -0
  130. package/lib/esm/structured-output/bot-executor.js +18 -0
  131. package/lib/esm/structured-output/bot-executor.js.map +1 -0
  132. package/lib/esm/structured-output/carousel.d.ts +18 -0
  133. package/lib/esm/structured-output/carousel.js +23 -0
  134. package/lib/esm/structured-output/carousel.js.map +1 -0
  135. package/lib/esm/structured-output/do-nothing.d.ts +6 -0
  136. package/lib/esm/structured-output/do-nothing.js +11 -0
  137. package/lib/esm/structured-output/do-nothing.js.map +1 -0
  138. package/lib/esm/structured-output/exit.d.ts +6 -0
  139. package/lib/esm/structured-output/exit.js +11 -0
  140. package/lib/esm/structured-output/exit.js.map +1 -0
  141. package/lib/esm/structured-output/index.d.ts +112 -0
  142. package/lib/esm/structured-output/index.js +47 -0
  143. package/lib/esm/structured-output/index.js.map +1 -0
  144. package/lib/esm/structured-output/request-contact-info.d.ts +9 -0
  145. package/lib/esm/structured-output/request-contact-info.js +14 -0
  146. package/lib/esm/structured-output/request-contact-info.js.map +1 -0
  147. package/lib/esm/structured-output/text-with-buttons.d.ts +17 -0
  148. package/lib/esm/structured-output/text-with-buttons.js +24 -0
  149. package/lib/esm/structured-output/text-with-buttons.js.map +1 -0
  150. package/lib/esm/structured-output/text.d.ts +9 -0
  151. package/lib/esm/structured-output/text.js +14 -0
  152. package/lib/esm/structured-output/text.js.map +1 -0
  153. package/lib/esm/tools/index.d.ts +3 -0
  154. package/lib/esm/tools/index.js +8 -0
  155. package/lib/esm/tools/index.js.map +1 -0
  156. package/lib/esm/tools/retrieve-knowledge.d.ts +6 -0
  157. package/lib/esm/tools/retrieve-knowledge.js +34 -0
  158. package/lib/esm/tools/retrieve-knowledge.js.map +1 -0
  159. package/lib/esm/types.d.ts +53 -0
  160. package/lib/esm/types.js +3 -0
  161. package/lib/esm/types.js.map +1 -0
  162. package/package.json +10 -12
  163. package/src/index.ts +1 -0
  164. package/src/runners/base-runner.ts +20 -10
  165. package/src/structured-output/do-nothing.ts +12 -0
  166. package/src/structured-output/index.ts +2 -0
  167. package/lib/agents/base-agent.js +0 -66
  168. package/lib/agents/base-agent.js.map +0 -1
  169. package/lib/agents/index.d.ts +0 -2
  170. package/lib/agents/index.js +0 -9
  171. package/lib/agents/index.js.map +0 -1
  172. package/lib/agents/router-agent.js +0 -50
  173. package/lib/agents/router-agent.js.map +0 -1
  174. package/lib/agents/specialist-agent.js.map +0 -1
  175. package/lib/bot-config-tools.js +0 -20
  176. package/lib/bot-config-tools.js.map +0 -1
  177. package/lib/constants.js +0 -26
  178. package/lib/constants.js.map +0 -1
  179. package/lib/debug-logger.js.map +0 -1
  180. package/lib/guardrails/index.d.ts +0 -1
  181. package/lib/guardrails/index.js +0 -6
  182. package/lib/guardrails/index.js.map +0 -1
  183. package/lib/guardrails/input.js +0 -119
  184. package/lib/guardrails/input.js.map +0 -1
  185. package/lib/index.js.map +0 -1
  186. package/lib/llm-config.js +0 -150
  187. package/lib/llm-config.js.map +0 -1
  188. package/lib/runners/base-runner.js.map +0 -1
  189. package/lib/runners/index.d.ts +0 -2
  190. package/lib/runners/index.js +0 -9
  191. package/lib/runners/index.js.map +0 -1
  192. package/lib/runners/router-runner.js.map +0 -1
  193. package/lib/runners/specialist-runner.js +0 -10
  194. package/lib/runners/specialist-runner.js.map +0 -1
  195. package/lib/services/hubtype-api-client.js +0 -191
  196. package/lib/services/hubtype-api-client.js.map +0 -1
  197. package/lib/services/types.js +0 -13
  198. package/lib/services/types.js.map +0 -1
  199. package/lib/structured-output/bot-executor.js +0 -21
  200. package/lib/structured-output/bot-executor.js.map +0 -1
  201. package/lib/structured-output/carousel.js +0 -26
  202. package/lib/structured-output/carousel.js.map +0 -1
  203. package/lib/structured-output/exit.js +0 -14
  204. package/lib/structured-output/exit.js.map +0 -1
  205. package/lib/structured-output/index.js +0 -59
  206. package/lib/structured-output/index.js.map +0 -1
  207. package/lib/structured-output/request-contact-info.js +0 -17
  208. package/lib/structured-output/request-contact-info.js.map +0 -1
  209. package/lib/structured-output/text-with-buttons.js +0 -25
  210. package/lib/structured-output/text-with-buttons.js.map +0 -1
  211. package/lib/structured-output/text.js +0 -17
  212. package/lib/structured-output/text.js.map +0 -1
  213. package/lib/tools/index.js +0 -8
  214. package/lib/tools/index.js.map +0 -1
  215. package/lib/tools/retrieve-knowledge.js +0 -40
  216. package/lib/tools/retrieve-knowledge.js.map +0 -1
  217. package/lib/types.js +0 -5
  218. package/lib/types.js.map +0 -1
  219. /package/lib/{constants.d.ts → cjs/constants.d.ts} +0 -0
  220. /package/lib/{structured-output → cjs/structured-output}/bot-executor.d.ts +0 -0
  221. /package/lib/{structured-output → cjs/structured-output}/carousel.d.ts +0 -0
  222. /package/lib/{structured-output → cjs/structured-output}/exit.d.ts +0 -0
  223. /package/lib/{structured-output → cjs/structured-output}/request-contact-info.d.ts +0 -0
  224. /package/lib/{structured-output → cjs/structured-output}/text-with-buttons.d.ts +0 -0
  225. /package/lib/{structured-output → cjs/structured-output}/text.d.ts +0 -0
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
- "type": "module",
3
2
  "name": "@botonic/plugin-ai-agents",
4
- "version": "0.57.0-rslib-esm.2",
5
- "main": "./lib/index.js",
6
- "module": "./lib/index.js",
3
+ "version": "0.57.0",
4
+ "main": "./lib/cjs/index.js",
5
+ "module": "./lib/esm/index.js",
7
6
  "description": "Use AI Agents to generate your contents",
8
7
  "scripts": {
9
- "build": "rslib build --no-env",
10
- "build:watch": "rslib build --watch --no-env",
11
- "test": "vitest run --coverage",
12
- "prepublishOnly": "npm run build && npm run test && npm run lint",
8
+ "build": "rm -rf lib && ../../node_modules/.bin/tsc -p tsconfig.json && ../../node_modules/.bin/tsc -p tsconfig.esm.json",
9
+ "build:watch": "npm run build -- --watch",
10
+ "test": "../../node_modules/.bin/jest --coverage",
11
+ "prepublishOnly": "rm -rf lib && npm i && npm run build",
13
12
  "lint": "biome check --write src/ tests/",
14
13
  "lint:check": "biome check src/ tests/",
15
14
  "format": "biome format --write src/ tests/"
16
15
  },
17
16
  "dependencies": {
18
- "@botonic/core": "0.57.0-rslib-esm.2",
17
+ "@botonic/core": "^0.57.0",
19
18
  "@openai/agents": "^0.10.1",
20
19
  "axios": "^1.18.1",
21
20
  "openai": "^6.36.0",
@@ -31,7 +30,7 @@
31
30
  "README.md"
32
31
  ],
33
32
  "engines": {
34
- "node": ">=22.19.0",
33
+ "node": ">=22.23.2",
35
34
  "npm": ">=10.0.0"
36
35
  },
37
36
  "repository": {
@@ -46,6 +45,5 @@
46
45
  "typescript",
47
46
  "javascript"
48
47
  ],
49
- "author": "",
50
- "types": "./lib/index.d.ts"
48
+ "author": ""
51
49
  }
package/src/index.ts CHANGED
@@ -116,6 +116,7 @@ export default class BotonicPluginAiAgents<
116
116
  memoryLength: 0,
117
117
  exit: true,
118
118
  error: true,
119
+ doNothing: false,
119
120
  inputGuardrailsTriggered: [],
120
121
  outputGuardrailsTriggered: [],
121
122
  startingAgentName: '',
@@ -1,7 +1,8 @@
1
- import type {
2
- OutputMessage,
3
- ResolvedPlugins,
4
- ToolExecution,
1
+ import {
2
+ type OutputMessage,
3
+ OutputMessageType,
4
+ type ResolvedPlugins,
5
+ type ToolExecution,
5
6
  } from '@botonic/core'
6
7
  import {
7
8
  InputGuardrailTripwireTriggered,
@@ -214,22 +215,30 @@ export abstract class BaseRunner<
214
215
  const outputMessages = result.finalOutput?.messages || []
215
216
  const hasExit =
216
217
  outputMessages.length === 0 ||
217
- outputMessages.some(message => message.type === 'exit')
218
+ outputMessages.some(message => message.type === OutputMessageType.Exit)
219
+
220
+ const hasDoNothing = outputMessages.some(
221
+ message => message.type === OutputMessageType.DoNothing
222
+ )
218
223
 
219
224
  return {
220
225
  startingAgentName: '',
221
226
  lastAgentName: '',
222
227
  availableSpecialists: [],
223
228
  isTransferredToSpecialist: false,
224
- messages: hasExit
225
- ? []
226
- : (outputMessages.filter(
227
- message => message.type !== 'exit'
228
- ) as AgenticOutputMessage[]),
229
+ messages:
230
+ hasExit || hasDoNothing
231
+ ? []
232
+ : (outputMessages.filter(
233
+ message =>
234
+ message.type !== OutputMessageType.Exit &&
235
+ message.type !== OutputMessageType.DoNothing
236
+ ) as AgenticOutputMessage[]),
229
237
  toolsExecuted: this.getToolsExecuted(result, context),
230
238
  exit: hasExit,
231
239
  memoryLength,
232
240
  error: false,
241
+ doNothing: hasDoNothing,
233
242
  inputGuardrailsTriggered: [],
234
243
  outputGuardrailsTriggered: [],
235
244
  }
@@ -295,6 +304,7 @@ export abstract class BaseRunner<
295
304
  toolsExecuted: [],
296
305
  exit: true,
297
306
  error: false,
307
+ doNothing: false,
298
308
  inputGuardrailsTriggered: error.result.output.outputInfo,
299
309
  outputGuardrailsTriggered: [],
300
310
  }
@@ -0,0 +1,12 @@
1
+ import { type DoNothingMessage, OutputMessageType } from '@botonic/core'
2
+ import { z } from 'zod'
3
+
4
+ export type { DoNothingMessage }
5
+
6
+ export const DoNothingSchema = z
7
+ .object({
8
+ type: z.literal(OutputMessageType.DoNothing),
9
+ })
10
+ .describe(
11
+ 'A do nothing message is used to end the conversation without send a reply. Use it only when asked explicitly in the prompt.'
12
+ )
@@ -2,6 +2,7 @@ import type { OutputMessage } from '@botonic/core'
2
2
  import { z } from 'zod'
3
3
  import { BotExecutorSchema } from './bot-executor'
4
4
  import { CarouselSchema } from './carousel'
5
+ import { DoNothingSchema } from './do-nothing'
5
6
  import { ExitSchema } from './exit'
6
7
  import { RequestContactInfoSchema } from './request-contact-info'
7
8
  import { TextSchema } from './text'
@@ -15,6 +16,7 @@ const baseMessageSchemas = [
15
16
  TextSchema,
16
17
  TextWithButtonsSchema,
17
18
  CarouselSchema,
19
+ DoNothingSchema,
18
20
  ExitSchema,
19
21
  BotExecutorSchema,
20
22
  RequestContactInfoSchema,
@@ -1,66 +0,0 @@
1
- import { createInputGuardrails } from "../guardrails/index.js";
2
- import { getOutputInstructions, getOutputSchema } from "../structured-output/index.js";
3
-
4
-
5
-
6
- function _define_property(obj, key, value) {
7
- if (key in obj) {
8
- Object.defineProperty(obj, key, {
9
- value: value,
10
- enumerable: true,
11
- configurable: true,
12
- writable: true
13
- });
14
- } else obj[key] = value;
15
- return obj;
16
- }
17
-
18
-
19
- class BaseAgent {
20
- getAgentModelSettings() {
21
- const modelSettings = {
22
- ...this.llmConfig.modelSettings
23
- };
24
- if (this.llmConfig.modelSettings.reasoning) {
25
- modelSettings.reasoning = {
26
- ...this.llmConfig.modelSettings.reasoning
27
- };
28
- }
29
- if (this.llmConfig.modelSettings.text) {
30
- modelSettings.text = {
31
- ...this.llmConfig.modelSettings.text
32
- };
33
- }
34
- return modelSettings;
35
- }
36
- async getInputGuardrails() {
37
- return await createInputGuardrails(this.inputGuardrailRules, this.llmConfig, this.guardrailTrackingContext);
38
- }
39
- getOutputType() {
40
- return getOutputSchema(this.outputMessagesSchemas);
41
- }
42
- addOutputInstructions(instructions) {
43
- return `${instructions}\n\n${getOutputInstructions()}`;
44
- }
45
- async getModel() {
46
- return await this.llmConfig.getModel();
47
- }
48
- constructor(options){
49
- _define_property(this, "name", void 0);
50
- _define_property(this, "instructions", void 0);
51
- _define_property(this, "llmConfig", void 0);
52
- _define_property(this, "inputGuardrailRules", void 0);
53
- _define_property(this, "outputMessagesSchemas", void 0);
54
- _define_property(this, "guardrailTrackingContext", void 0);
55
- this.name = options.name;
56
- this.instructions = options.instructions;
57
- this.llmConfig = options.llmConfig;
58
- this.inputGuardrailRules = options.inputGuardrailRules;
59
- this.outputMessagesSchemas = options.outputMessagesSchemas || [];
60
- this.guardrailTrackingContext = options.guardrailTrackingContext;
61
- }
62
- }
63
-
64
- export { BaseAgent };
65
-
66
- //# sourceMappingURL=base-agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agents/base-agent.js","sources":["../../src/agents/base-agent.ts"],"sourcesContent":["import type {\n AgentOutputType,\n InputGuardrail,\n Model,\n ModelSettings,\n} from '@openai/agents'\nimport type { z } from 'zod'\n\nimport { createInputGuardrails } from '../guardrails'\nimport type { GuardrailTrackingContext } from '../guardrails/input'\nimport type { LLMConfig } from '../llm-config'\nimport {\n getOutputInstructions,\n getOutputSchema,\n type OutputSchema,\n} from '../structured-output'\nimport type { GuardrailRule } from '../types'\n\nexport interface BaseAgentOptions {\n name: string\n instructions: string\n llmConfig: LLMConfig\n inputGuardrailRules: GuardrailRule[]\n outputMessagesSchemas?: z.ZodObject[]\n guardrailTrackingContext: GuardrailTrackingContext\n}\n\nexport abstract class BaseAgent {\n protected name: string\n protected instructions: string\n protected llmConfig: LLMConfig\n private inputGuardrailRules: GuardrailRule[]\n private outputMessagesSchemas: z.ZodObject[]\n private guardrailTrackingContext: GuardrailTrackingContext\n\n constructor(options: BaseAgentOptions) {\n this.name = options.name\n this.instructions = options.instructions\n this.llmConfig = options.llmConfig\n this.inputGuardrailRules = options.inputGuardrailRules\n this.outputMessagesSchemas = options.outputMessagesSchemas || []\n this.guardrailTrackingContext = options.guardrailTrackingContext\n }\n\n protected getAgentModelSettings(): ModelSettings {\n const modelSettings: ModelSettings = { ...this.llmConfig.modelSettings }\n\n if (this.llmConfig.modelSettings.reasoning) {\n modelSettings.reasoning = { ...this.llmConfig.modelSettings.reasoning }\n }\n\n if (this.llmConfig.modelSettings.text) {\n modelSettings.text = { ...this.llmConfig.modelSettings.text }\n }\n\n return modelSettings\n }\n\n protected async getInputGuardrails(): Promise<InputGuardrail[]> {\n return await createInputGuardrails(\n this.inputGuardrailRules,\n this.llmConfig,\n this.guardrailTrackingContext\n )\n }\n\n protected getOutputType(): AgentOutputType<typeof OutputSchema> {\n return getOutputSchema(this.outputMessagesSchemas)\n }\n\n protected addOutputInstructions(instructions: string): string {\n return `${instructions}\\n\\n${getOutputInstructions()}`\n }\n\n protected async getModel(): Promise<string | Model> {\n return await this.llmConfig.getModel()\n }\n}\n"],"names":["createInputGuardrails","getOutputInstructions","getOutputSchema","BaseAgent","modelSettings","instructions","options"],"mappings":";;;;;;;;;;;;;;;;AAQqD;AAOxB;AAYtB,MAAeG,SAASA;IAiBnB,wBAAuC;QAC/C,MAAMC,gBAA+B;YAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa;QAAC;QAEvE,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE;YAC1CA,cAAc,SAAS,GAAG;gBAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS;YAAC;QACxE;QAEA,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE;YACrCA,cAAc,IAAI,GAAG;gBAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI;YAAC;QAC9D;QAEA,OAAOA;IACT;IAEA,MAAgB,qBAAgD;QAC9D,OAAO,MAAMJ,qBAAqBA,CAChC,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,wBAAwB;IAEjC;IAEU,gBAAsD;QAC9D,OAAOE,eAAeA,CAAC,IAAI,CAAC,qBAAqB;IACnD;IAEU,sBAAsBG,YAAoB,EAAU;QAC5D,OAAO,GAAGA,aAAa,IAAI,EAAEJ,qBAAqBA,IAAI;IACxD;IAEA,MAAgB,WAAoC;QAClD,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ;IACtC;IAzCA,YAAYK,OAAyB,CAAE;QAPvC,uBAAU,QAAV;QACA,uBAAU,gBAAV;QACA,uBAAU,aAAV;QACA,uBAAQ,uBAAR;QACA,uBAAQ,yBAAR;QACA,uBAAQ,4BAAR;QAGE,IAAI,CAAC,IAAI,GAAGA,QAAQ,IAAI;QACxB,IAAI,CAAC,YAAY,GAAGA,QAAQ,YAAY;QACxC,IAAI,CAAC,SAAS,GAAGA,QAAQ,SAAS;QAClC,IAAI,CAAC,mBAAmB,GAAGA,QAAQ,mBAAmB;QACtD,IAAI,CAAC,qBAAqB,GAAGA,QAAQ,qBAAqB,IAAI,EAAE;QAChE,IAAI,CAAC,wBAAwB,GAAGA,QAAQ,wBAAwB;IAClE;AAmCF"}
@@ -1,2 +0,0 @@
1
- export { RouterAgent } from './router-agent.js';
2
- export { SpecialistAgent } from './specialist-agent.js';
@@ -1,9 +0,0 @@
1
-
2
-
3
-
4
-
5
-
6
- export { RouterAgent } from "./router-agent.js";
7
- export { SpecialistAgent } from "./specialist-agent.js";
8
-
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agents/index.js","sources":["../../src/agents/index.ts"],"sourcesContent":["export { RouterAgent } from './router-agent'\nexport { SpecialistAgent } from './specialist-agent'\n"],"names":["RouterAgent","SpecialistAgent"],"mappings":";;AAA4C;AACQ"}
@@ -1,50 +0,0 @@
1
- import { Agent } from "@openai/agents";
2
- import { RECOMMENDED_PROMPT_PREFIX } from "@openai/agents-core/extensions";
3
- import { BaseAgent } from "./base-agent.js";
4
-
5
-
6
-
7
-
8
- function _define_property(obj, key, value) {
9
- if (key in obj) {
10
- Object.defineProperty(obj, key, {
11
- value: value,
12
- enumerable: true,
13
- configurable: true,
14
- writable: true
15
- });
16
- } else obj[key] = value;
17
- return obj;
18
- }
19
-
20
-
21
-
22
- class RouterAgent extends BaseAgent {
23
- static async create(options) {
24
- const routerAgent = new RouterAgent(options);
25
- const inputGuardrails = await routerAgent.getInputGuardrails();
26
- // Agent.create is typed as Agent<UnknownContext>; we run with Context<TPlugins, TExtraData>.
27
- const agent = Agent.create({
28
- name: routerAgent.name,
29
- model: await routerAgent.getModel(),
30
- modelSettings: routerAgent.getAgentModelSettings(),
31
- instructions: routerAgent.addOutputInstructions(`${RECOMMENDED_PROMPT_PREFIX}${routerAgent.instructions}`),
32
- handoffs: routerAgent.handoffs,
33
- outputType: routerAgent.getOutputType(),
34
- inputGuardrails
35
- });
36
- routerAgent.agent = agent;
37
- return routerAgent;
38
- }
39
- getAgent() {
40
- return this.agent;
41
- }
42
- constructor(options){
43
- super(options), _define_property(this, "handoffs", void 0), _define_property(this, "agent", void 0);
44
- this.handoffs = options.handoffs;
45
- }
46
- }
47
-
48
- export { RouterAgent };
49
-
50
- //# sourceMappingURL=router-agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agents/router-agent.js","sources":["../../src/agents/router-agent.ts"],"sourcesContent":["import type { ResolvedPlugins } from '@botonic/core'\nimport { Agent, type AgentOutputType, type Handoff } from '@openai/agents'\nimport { RECOMMENDED_PROMPT_PREFIX } from '@openai/agents-core/extensions'\nimport type { z } from 'zod'\nimport type { GuardrailTrackingContext } from '../guardrails/input'\nimport type { LLMConfig } from '../llm-config'\nimport type { OutputSchema } from '../structured-output'\nimport type { AIAgent, Context, GuardrailRule } from '../types'\nimport { BaseAgent } from './base-agent'\n\ninterface RouterAgentOptions<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n> {\n name: string\n instructions: string\n llmConfig: LLMConfig\n handoffs: Handoff<\n Context<TPlugins, TExtraData>,\n AgentOutputType<typeof OutputSchema>\n >[]\n inputGuardrailRules: GuardrailRule[]\n outputMessagesSchemas?: z.ZodObject[]\n guardrailTrackingContext: GuardrailTrackingContext\n}\n\nexport class RouterAgent<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n> extends BaseAgent {\n private handoffs: Handoff<\n Context<TPlugins, TExtraData>,\n AgentOutputType<typeof OutputSchema>\n >[]\n private agent!: AIAgent<TPlugins, TExtraData>\n\n private constructor(options: RouterAgentOptions<TPlugins, TExtraData>) {\n super(options)\n this.handoffs = options.handoffs\n }\n\n static async create<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n >(\n options: RouterAgentOptions<TPlugins, TExtraData>\n ): Promise<RouterAgent<TPlugins, TExtraData>> {\n const routerAgent = new RouterAgent<TPlugins, TExtraData>(options)\n const inputGuardrails = await routerAgent.getInputGuardrails()\n\n // Agent.create is typed as Agent<UnknownContext>; we run with Context<TPlugins, TExtraData>.\n const agent = Agent.create({\n name: routerAgent.name,\n model: await routerAgent.getModel(),\n modelSettings: routerAgent.getAgentModelSettings(),\n instructions: routerAgent.addOutputInstructions(\n `${RECOMMENDED_PROMPT_PREFIX}${routerAgent.instructions}`\n ),\n handoffs: routerAgent.handoffs,\n outputType: routerAgent.getOutputType(),\n inputGuardrails,\n }) as AIAgent<TPlugins, TExtraData>\n\n routerAgent.agent = agent\n return routerAgent\n }\n\n getAgent(): AIAgent<TPlugins, TExtraData> {\n return this.agent\n }\n}\n"],"names":["Agent","RECOMMENDED_PROMPT_PREFIX","BaseAgent","RouterAgent","options","routerAgent","inputGuardrails","agent"],"mappings":";;;;;;;;;;;;;;;;;;AAC0E;AACA;AAMlC;AAkBjC,MAAMG,WAAWA,SAGdD,SAASA;IAYjB,aAAa,OAIXE,OAAiD,EACL;QAC5C,MAAMC,cAAc,IAAIF,WAAWA,CAAuBC;QAC1D,MAAME,kBAAkB,MAAMD,YAAY,kBAAkB;QAE5D,6FAA6F;QAC7F,MAAME,QAAQP,YAAY,CAAC;YACzB,MAAMK,YAAY,IAAI;YACtB,OAAO,MAAMA,YAAY,QAAQ;YACjC,eAAeA,YAAY,qBAAqB;YAChD,cAAcA,YAAY,qBAAqB,CAC7C,GAAGJ,yBAAyBA,GAAGI,YAAY,YAAY,EAAE;YAE3D,UAAUA,YAAY,QAAQ;YAC9B,YAAYA,YAAY,aAAa;YACrCC;QACF;QAEAD,YAAY,KAAK,GAAGE;QACpB,OAAOF;IACT;IAEA,WAA0C;QACxC,OAAO,IAAI,CAAC,KAAK;IACnB;IAjCA,YAAoBD,OAAiD,CAAE;QACrE,KAAK,CAACA,UAPR,uBAAQ,YAAR,SAIA,uBAAQ,SAAR;QAIE,IAAI,CAAC,QAAQ,GAAGA,QAAQ,QAAQ;IAClC;AA+BF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"agents/specialist-agent.js","sources":["../../src/agents/specialist-agent.ts"],"sourcesContent":["import type { CampaignV2, ContactInfo, ResolvedPlugins } from '@botonic/core'\nimport { Agent, type AgentOutputType, type ModelSettings } from '@openai/agents'\nimport type { z } from 'zod'\nimport { LLM_PROVIDER } from '../constants'\nimport type { DebugLogger } from '../debug-logger'\nimport type { GuardrailTrackingContext } from '../guardrails/input'\nimport type { LLMConfig } from '../llm-config'\nimport type { OutputSchema } from '../structured-output'\nimport {\n createRetrieveKnowledge,\n mandatoryTools,\n RETRIEVE_KNOWLEDGE_TOOL_NAME,\n} from '../tools'\nimport type { AIAgent, Context, GuardrailRule, Tool } from '../types'\nimport { BaseAgent } from './base-agent'\n\ninterface SpecialistAgentOptions<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n> {\n name: string\n instructions: string\n tools: Tool<TPlugins, TExtraData>[]\n campaignsContext?: CampaignV2[]\n contactInfo: ContactInfo[]\n inputGuardrailRules: GuardrailRule[]\n sourceIds: string[]\n outputMessagesSchemas?: z.ZodObject[]\n llmConfig: LLMConfig\n logger: DebugLogger\n guardrailTrackingContext: GuardrailTrackingContext\n forceToolNameOverride?: string\n disableForceRetrieveKnowledge?: boolean\n}\n\nexport class SpecialistAgent<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n> extends BaseAgent {\n private tools: Tool<TPlugins, TExtraData>[]\n private logger: DebugLogger\n private agent!: AIAgent<TPlugins, TExtraData>\n private forceToolNameOverride?: string\n private disableForceRetrieveKnowledge?: boolean\n\n private constructor(options: SpecialistAgentOptions<TPlugins, TExtraData>) {\n super({\n name: options.name,\n instructions: options.instructions,\n llmConfig: options.llmConfig,\n inputGuardrailRules: options.inputGuardrailRules,\n outputMessagesSchemas: options.outputMessagesSchemas,\n guardrailTrackingContext: options.guardrailTrackingContext,\n })\n this.instructions = this.addExtraInstructions(\n options.instructions,\n options.contactInfo,\n options.campaignsContext\n )\n this.tools = this.addHubtypeTools(options.tools, options.sourceIds)\n this.logger = options.logger\n this.forceToolNameOverride = options.forceToolNameOverride\n this.disableForceRetrieveKnowledge = options.disableForceRetrieveKnowledge\n }\n\n static async create<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n >(\n options: SpecialistAgentOptions<TPlugins, TExtraData>\n ): Promise<SpecialistAgent<TPlugins, TExtraData>> {\n const specialistAgent = new SpecialistAgent<TPlugins, TExtraData>(options)\n const model = specialistAgent.llmConfig.modelName\n const resolvedModel = await specialistAgent.getModel()\n const hasRetrieveKnowledge = specialistAgent.tools.some(\n tool => tool.name === RETRIEVE_KNOWLEDGE_TOOL_NAME\n )\n const modelSettings =\n specialistAgent.getSpecialistModelSettings(hasRetrieveKnowledge)\n const inputGuardrails = await specialistAgent.getInputGuardrails()\n\n specialistAgent.logger.logModelSettings({\n provider: LLM_PROVIDER,\n model,\n reasoning: modelSettings.reasoning as { effort: string } | undefined,\n text: modelSettings.text as { verbosity: string } | undefined,\n toolChoice: modelSettings.toolChoice,\n hasRetrieveKnowledge,\n })\n\n const agent = new Agent<\n Context<TPlugins, TExtraData>,\n AgentOutputType<typeof OutputSchema>\n >({\n name: specialistAgent.name,\n model: resolvedModel,\n modelSettings,\n instructions: specialistAgent.instructions,\n tools: specialistAgent.tools,\n outputType: specialistAgent.getOutputType(),\n inputGuardrails,\n outputGuardrails: [],\n })\n\n specialistAgent.agent = agent\n return specialistAgent\n }\n\n getAgent(): AIAgent<TPlugins, TExtraData> {\n return this.agent\n }\n\n private getSpecialistModelSettings(\n hasRetrieveKnowledge: boolean\n ): ModelSettings {\n const modelSettings = this.getAgentModelSettings()\n const forceRetrieveKnowledge =\n hasRetrieveKnowledge &&\n !this.forceToolNameOverride &&\n !this.disableForceRetrieveKnowledge\n\n if (forceRetrieveKnowledge) {\n modelSettings.toolChoice = RETRIEVE_KNOWLEDGE_TOOL_NAME\n }\n\n if (this.forceToolNameOverride) {\n modelSettings.toolChoice = this.forceToolNameOverride\n }\n\n return modelSettings\n }\n\n private addExtraInstructions(\n initialInstructions: string,\n contactInfo: ContactInfo[],\n campaignsContext?: CampaignV2[]\n ): string {\n const sections = [\n `<instructions>\\n${initialInstructions.trim()}\\n</instructions>`,\n this.getMetadataInstructions(),\n this.getContactInfoInstructions(contactInfo),\n this.getCampaignInstructions(campaignsContext),\n ].filter(section => section.length > 0)\n\n return this.addOutputInstructions(sections.join('\\n\\n'))\n }\n\n private getContactInfoInstructions(contactInfo: ContactInfo[]): string {\n return `<contact_info_fields>${JSON.stringify(\n contactInfo.map(info => ({\n name: info.name,\n value: info.value,\n })),\n null,\n 0\n )}</contact_info_fields>`\n }\n\n private getMetadataInstructions(): string {\n const metadata = `Current Date: ${new Date().toISOString()}`\n return `<metadata>\\n${metadata}\\n</metadata>`\n }\n\n private getCampaignInstructions(campaignsContext?: CampaignV2[]): string {\n if (!campaignsContext || campaignsContext.length === 0) {\n return ''\n }\n const campaignsWithContext = campaignsContext.filter(\n campaign => campaign.agent_context\n )\n if (campaignsWithContext.length === 0) {\n return ''\n }\n return campaignsWithContext\n .map(\n (campaign, index) =>\n `<campaign_context_${index + 1}>\\n${campaign.agent_context}\\n</campaign_context_${index + 1}>`\n )\n .join('\\n')\n }\n\n private addHubtypeTools(\n tools: Tool<TPlugins, TExtraData>[],\n sourceIds: string[]\n ): Tool<TPlugins, TExtraData>[] {\n const hubtypeTools: Tool[] = [...mandatoryTools]\n if (sourceIds.length > 0) {\n hubtypeTools.push(createRetrieveKnowledge(sourceIds))\n }\n return [...hubtypeTools, ...tools]\n }\n}\n"],"names":["Agent","LLM_PROVIDER","createRetrieveKnowledge","mandatoryTools","RETRIEVE_KNOWLEDGE_TOOL_NAME","BaseAgent","SpecialistAgent","options","specialistAgent","model","resolvedModel","hasRetrieveKnowledge","tool","modelSettings","inputGuardrails","agent","forceRetrieveKnowledge","initialInstructions","contactInfo","campaignsContext","sections","section","JSON","info","metadata","Date","campaignsWithContext","campaign","index","tools","sourceIds","hubtypeTools"],"mappings":";;;;;;;;;;;;;;;;;;;;AACgF;AAErC;AAS1B;AAEuB;AAqBjC,MAAMM,eAAeA,SAGlBD,SAASA;IA2BjB,aAAa,OAIXE,OAAqD,EACL;QAChD,MAAMC,kBAAkB,IAAIF,eAAeA,CAAuBC;QAClE,MAAME,QAAQD,gBAAgB,SAAS,CAAC,SAAS;QACjD,MAAME,gBAAgB,MAAMF,gBAAgB,QAAQ;QACpD,MAAMG,uBAAuBH,gBAAgB,KAAK,CAAC,IAAI,CACrDI,CAAAA,OAAQA,KAAK,IAAI,KAAKR,4BAA4BA;QAEpD,MAAMS,gBACJL,gBAAgB,0BAA0B,CAACG;QAC7C,MAAMG,kBAAkB,MAAMN,gBAAgB,kBAAkB;QAEhEA,gBAAgB,MAAM,CAAC,gBAAgB,CAAC;YACtC,UAAUP,YAAYA;YACtBQ;YACA,WAAWI,cAAc,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gB;QAE1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAACA,QAAQ,KAAK,EAAEA,QAAQ,SAAS;QAClE,IAAI,CAAC,MAAM,GAAGA,QAAQ,MAAM;QAC5B,IAAI,CAAC,qBAAqB,GAAGA,QAAQ,qBAAqB;QAC1D,IAAI,CAAC,6BAA6B,GAAGA,QAAQ,6BAA6B;IAC5E;AAgIF"}
@@ -1,20 +0,0 @@
1
- import { z } from "zod";
2
-
3
-
4
-
5
- /**
6
- * Maps custom AI agent tools to the format expected by bot config (e.g. for flow-builder).
7
- * Converts each tool's Zod schema to JSON Schema so it can be serialized in the config.
8
- */ function getToolsForBotConfig(customTools) {
9
- return customTools.map((tool)=>({
10
- name: tool.name,
11
- description: tool.description,
12
- schema: z.toJSONSchema(tool.schema, {
13
- target: 'draft-07'
14
- })
15
- }));
16
- }
17
-
18
- export { getToolsForBotConfig };
19
-
20
- //# sourceMappingURL=bot-config-tools.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bot-config-tools.js","sources":["../src/bot-config-tools.ts"],"sourcesContent":["import type { ToolConfigJSON } from '@botonic/core'\nimport { z } from 'zod'\n\nimport type { CustomTool } from './types'\n\n/**\n * Maps custom AI agent tools to the format expected by bot config (e.g. for flow-builder).\n * Converts each tool's Zod schema to JSON Schema so it can be serialized in the config.\n */\nexport function getToolsForBotConfig(\n customTools: CustomTool[]\n): ToolConfigJSON[] {\n return customTools.map(tool => ({\n name: tool.name,\n description: tool.description,\n schema: z.toJSONSchema(tool.schema, {\n target: 'draft-07',\n }) as ToolConfigJSON['schema'],\n }))\n}\n"],"names":["z","getToolsForBotConfig","customTools","tool"],"mappings":";;;AACuB;AAIvB;;;CAGC,GACM,SAASC,oBAAoBA,CAClCC,WAAyB;IAEzB,OAAOA,YAAY,GAAG,CAACC,CAAAA,OAAS;YAC9B,MAAMA,KAAK,IAAI;YACf,aAAaA,KAAK,WAAW;YAC7B,QAAQH,cAAc,CAACG,KAAK,MAAM,EAAE;gBAClC,QAAQ;YACV;QACF;AACF"}
package/lib/constants.js DELETED
@@ -1,26 +0,0 @@
1
- const HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
2
- // LLM Configuration (provider-agnostic; set LLM_PROVIDER=azure|openai)
3
- const LLM_PROVIDERS = {
4
- AZURE: 'azure',
5
- OPENAI: 'openai',
6
- LITELLM: 'litellm'
7
- };
8
- const LITELLM_TAG_KEYS = {
9
- BOT_ID: 'bot_id',
10
- ORG_ID: 'org_id',
11
- SEPARATOR: ','
12
- };
13
- const LLM_PROVIDER = process.env.LLM_PROVIDER || LLM_PROVIDERS.AZURE;
14
- const LLM_API_KEY = process.env.LLM_API_KEY // pragma: allowlist secret
15
- ;
16
- const LLM_API_URL = process.env.LLM_API_URL;
17
- const LLM_AZURE_API_VERSION = process.env.LLM_AZURE_API_VERSION || '2025-01-01-preview';
18
- const LLM_OPENAI_MODEL = process.env.LLM_OPENAI_MODEL || 'gpt-4.1-mini';
19
- const isProd = process.env.NODE_ENV === 'production';
20
- const MAX_MEMORY_LENGTH = 25;
21
- const DEFAULT_TIMEOUT_16_SECONDS = 16000;
22
- const DEFAULT_MAX_RETRIES = 2;
23
-
24
- export { DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_16_SECONDS, HUBTYPE_API_URL, LITELLM_TAG_KEYS, LLM_API_KEY, LLM_API_URL, LLM_AZURE_API_VERSION, LLM_OPENAI_MODEL, LLM_PROVIDER, LLM_PROVIDERS, MAX_MEMORY_LENGTH, isProd };
25
-
26
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const HUBTYPE_API_URL =\n process.env.HUBTYPE_API_URL || 'https://api.hubtype.com'\n\n// LLM Configuration (provider-agnostic; set LLM_PROVIDER=azure|openai)\nexport const LLM_PROVIDERS = {\n AZURE: 'azure',\n OPENAI: 'openai',\n LITELLM: 'litellm',\n} as const\n\nexport type LLMProviderType = (typeof LLM_PROVIDERS)[keyof typeof LLM_PROVIDERS]\n\nexport const LITELLM_TAG_KEYS = {\n BOT_ID: 'bot_id',\n ORG_ID: 'org_id',\n SEPARATOR: ',',\n} as const\n\nexport const LLM_PROVIDER: LLMProviderType =\n (process.env.LLM_PROVIDER as LLMProviderType) || LLM_PROVIDERS.AZURE\nexport const LLM_API_KEY = process.env.LLM_API_KEY // pragma: allowlist secret\nexport const LLM_API_URL = process.env.LLM_API_URL\nexport const LLM_AZURE_API_VERSION =\n process.env.LLM_AZURE_API_VERSION || '2025-01-01-preview'\nexport const LLM_OPENAI_MODEL = process.env.LLM_OPENAI_MODEL || 'gpt-4.1-mini'\n\nexport const isProd = process.env.NODE_ENV === 'production'\n\nexport const MAX_MEMORY_LENGTH = 25\n\nexport const DEFAULT_TIMEOUT_16_SECONDS = 16000\nexport const DEFAULT_MAX_RETRIES = 2\n"],"names":["HUBTYPE_API_URL","process","LLM_PROVIDERS","LITELLM_TAG_KEYS","LLM_PROVIDER","LLM_API_KEY","LLM_API_URL","LLM_AZURE_API_VERSION","LLM_OPENAI_MODEL","isProd","MAX_MEMORY_LENGTH","DEFAULT_TIMEOUT_16_SECONDS","DEFAULT_MAX_RETRIES"],"mappings":"AAAO,MAAMA,eAAeA,GAC1BC,QAAQ,GAAG,CAAC,eAAe,IAAI,0BAAyB;AAE1D,uEAAuE;AAChE,MAAMC,aAAaA,GAAG;IAC3B,OAAO;IACP,QAAQ;IACR,SAAS;AACX,EAAU;AAIH,MAAMC,gBAAgBA,GAAG;IAC9B,QAAQ;IACR,QAAQ;IACR,WAAW;AACb,EAAU;AAEH,MAAMC,YAAYA,GACtBH,QAAQ,GAAG,CAAC,YAAY,IAAwBC,aAAaA,CAAC,KAAK;AAC/D,MAAMG,WAAWA,GAAGJ,QAAQ,GAAG,CAAC,WAAW,CAAC,2BAA2B;CAA5B;AAC3C,MAAMK,WAAWA,GAAGL,QAAQ,GAAG,CAAC,WAAW;AAC3C,MAAMM,qBAAqBA,GAChCN,QAAQ,GAAG,CAAC,qBAAqB,IAAI,qBAAoB;AACpD,MAAMO,gBAAgBA,GAAGP,QAAQ,GAAG,CAAC,gBAAgB,IAAI,eAAc;AAEvE,MAAMQ,MAAMA,GAAGR,oBAAoB,KAAK,aAAY;AAEpD,MAAMS,iBAAiBA,GAAG,GAAE;AAE5B,MAAMC,0BAA0BA,GAAG,MAAK;AACxC,MAAMC,mBAAmBA,GAAG,EAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug-logger.js","sources":["../src/debug-logger.ts"],"sourcesContent":["import {\n type AiAgentArgs,\n AiAgentType,\n type ToolExecution,\n} from '@botonic/core'\nimport type { ModelSettings } from '@openai/agents'\nimport { LLM_PROVIDER } from './constants'\nimport type { AgenticInputMessage, MemoryOptions, RunResult } from './types'\n\nconst PREFIX = '[BotonicPluginAiAgents]'\n\nexport interface DebugLoggerConfig {\n messageHistoryApiVersion: string\n maxRetries: number\n timeout: number\n customToolNames: string[]\n memory: MemoryOptions\n}\n\nexport interface ModelSettingsInfo {\n provider: string\n model: string | undefined\n reasoning?: { effort: string }\n text?: { verbosity: string }\n toolChoice?: string\n hasRetrieveKnowledge: boolean\n}\n\nexport interface DebugLogger {\n logInitialConfig(config: DebugLoggerConfig): void\n logAgentDebugInfo(\n aiAgentArgs: AiAgentArgs,\n toolNames: string[],\n messages: AgenticInputMessage[]\n ): void\n logModelSettings(settings: ModelSettingsInfo): void\n logRunnerStart(\n model: string,\n modelSettings: ModelSettings,\n prompt: string\n ): void\n logRunResult(runResult: RunResult, startTime: number): void\n logGuardrailTriggered(): void\n logRunnerError(startTime: number, error: unknown): void\n logToolExecution(toolExecution: ToolExecution): void\n}\n\nclass EnabledDebugLogger implements DebugLogger {\n logInitialConfig(config: DebugLoggerConfig): void {\n console.log(`${PREFIX} === Plugin Initialization ===`)\n console.log(`${PREFIX} Provider: ${LLM_PROVIDER}`)\n console.log(\n `${PREFIX} Message History API Version: ${config.messageHistoryApiVersion}`\n )\n console.log(`${PREFIX} Max Retries: ${config.maxRetries}`)\n console.log(`${PREFIX} Timeout: ${config.timeout}ms`)\n console.log(\n `${PREFIX} Custom Tools Registered: ${config.customToolNames.join(', ') || 'none'}`\n )\n console.log(`${PREFIX} Memory Options:`, {\n maxMessages: config.memory.maxMessages,\n includeToolCalls: config.memory.includeToolCalls,\n maxFullToolResults: config.memory.maxFullToolResults,\n debugMode: config.memory.debugMode,\n })\n console.log(`${PREFIX} === End Plugin Initialization ===`)\n }\n\n logAgentDebugInfo(\n aiAgentArgs: AiAgentArgs,\n toolNames: string[],\n messages: AgenticInputMessage[]\n ): void {\n console.log(`${PREFIX} === AI Agent Debug Info ===`)\n console.log(`${PREFIX} Agent Name: ${aiAgentArgs.name}`)\n console.log(`${PREFIX} Active Tools: ${JSON.stringify(toolNames)}`)\n if (aiAgentArgs.type === AiAgentType.Specialist) {\n console.log(\n `${PREFIX} Source IDs: ${JSON.stringify(aiAgentArgs.sourceIds || [])}`\n )\n }\n console.log(`${PREFIX} Message History Count: ${messages.length}`)\n console.log(`${PREFIX} Messages: ${JSON.stringify(messages, null, 2)}`)\n console.log(\n `${PREFIX} Input Guardrail Rules: ${aiAgentArgs.inputGuardrailRules?.length || 0}`\n )\n console.log(`${PREFIX} === End Debug Info ===`)\n }\n\n logModelSettings(settings: ModelSettingsInfo): void {\n console.log(`${PREFIX} === Agent Model Settings ===`)\n console.log(\n `${PREFIX} Has Retrieve Knowledge Tool: ${settings.hasRetrieveKnowledge}`\n )\n if (settings.reasoning) {\n console.log(`${PREFIX} Reasoning Effort: ${settings.reasoning.effort}`)\n }\n if (settings.text) {\n console.log(`${PREFIX} Text Verbosity: ${settings.text.verbosity}`)\n }\n if (settings.toolChoice) {\n console.log(`${PREFIX} Tool Choice: ${settings.toolChoice}`)\n }\n console.log(`${PREFIX} === End Model Settings ===`)\n }\n\n logRunnerStart(\n model: string,\n modelSettings: ModelSettings,\n prompt: string\n ): void {\n console.log(`${PREFIX} === Runner Execution Start ===`)\n console.log(`${PREFIX} Model: ${model}`)\n console.log(`${PREFIX} Model Settings: ${JSON.stringify(modelSettings)}`)\n console.log(`${PREFIX} Prompt: ${prompt}`)\n }\n\n logRunResult(runResult: RunResult, startTime: number): void {\n const elapsedMs = Date.now() - startTime\n\n console.log(`${PREFIX} === Runner Execution Complete ===`)\n console.log(`${PREFIX} Execution Time: ${elapsedMs}ms`)\n console.log(`${PREFIX} Output Messages Count: ${runResult.messages.length}`)\n console.log(`${PREFIX} Exit: ${runResult.exit}`)\n console.log(`${PREFIX} Error: ${runResult.error}`)\n console.log(\n `${PREFIX} Tools Executed: ${JSON.stringify(runResult.toolsExecuted.map(t => t.toolName))}`\n )\n if (runResult.inputGuardrailsTriggered.length > 0) {\n console.log(\n `${PREFIX} Input Guardrails Triggered: ${runResult.inputGuardrailsTriggered.length}`\n )\n }\n if (runResult.outputGuardrailsTriggered.length > 0) {\n console.log(\n `${PREFIX} Output Guardrails Triggered: ${runResult.outputGuardrailsTriggered.length}`\n )\n }\n console.log(`${PREFIX} === End Runner Execution ===`)\n }\n\n logGuardrailTriggered(): void {\n console.log(`${PREFIX} Input guardrail triggered`)\n }\n\n logRunnerError(startTime: number, error: unknown): void {\n const elapsedMs = Date.now() - startTime\n console.log(`${PREFIX} Runner execution failed after ${elapsedMs}ms`)\n console.log(`${PREFIX} Error:`, error)\n }\n\n logToolExecution(toolExecution: ToolExecution): void {\n console.log(`${PREFIX} Tool Execution: ${toolExecution.toolName}`)\n console.log(\n `${PREFIX} Tool Arguments: ${JSON.stringify(toolExecution.toolArguments)}`\n )\n console.log(`${PREFIX} Tool Results: ${toolExecution.toolResults}`)\n console.log(\n `${PREFIX} Knowledgebase Sources IDs: ${JSON.stringify(toolExecution.knowledgebaseSourcesIds)}`\n )\n console.log(\n `${PREFIX} Knowledgebase Chunks IDs: ${JSON.stringify(toolExecution.knowledgebaseChunksIds)}`\n )\n }\n}\n\nclass DisabledDebugLogger implements DebugLogger {\n logInitialConfig(): void {\n return\n }\n logAgentDebugInfo(): void {\n return\n }\n logModelSettings(): void {\n return\n }\n logRunnerStart(\n _model: string,\n _modelSettings: ModelSettings,\n _prompt: string\n ): void {\n return\n }\n logRunResult(): void {\n return\n }\n logGuardrailTriggered(): void {\n return\n }\n logRunnerError(): void {\n return\n }\n logToolExecution(): void {\n return\n }\n}\n\nexport function createDebugLogger(enableDebug: boolean): DebugLogger {\n return enableDebug ? new EnabledDebugLogger() : new DisabledDebugLogger()\n}\n"],"names":["AiAgentType","LLM_PROVIDER","PREFIX","EnabledDebugLogger","config","console","aiAgentArgs","toolNames","messages","JSON","settings","model","modelSettings","prompt","runResult","startTime","elapsedMs","Date","t","error","toolExecution","DisabledDebugLogger","_model","_modelSettings","_prompt","createDebugLogger","enableDebug"],"mappings":";;;;;AAIsB;AAEoB;AAG1C,MAAME,MAAMA,GAAG;AAsCf,MAAMC,kBAAkBA;IACtB,iBAAiBC,MAAyB,EAAQ;QAChDC,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,8BAA8B,CAAC;QACrDG,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,WAAW,EAAED,YAAYA,EAAE;QACjDI,QAAQ,GAAG,CACT,GAAGH,MAAMA,CAAC,8BAA8B,EAAEE,OAAO,wBAAwB,EAAE;QAE7EC,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,cAAc,EAAEE,OAAO,UAAU,EAAE;QACzDC,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,UAAU,EAAEE,OAAO,OAAO,CAAC,EAAE,CAAC;QACpDC,QAAQ,GAAG,CACT,GAAGH,MAAMA,CAAC,0BAA0B,EAAEE,OAAO,eAAe,CAAC,IAAI,CAAC,SAAS,QAAQ;QAErFC,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,gBAAgB,CAAC,EAAE;YACvC,aAAaE,OAAO,MAAM,CAAC,WAAW;YACtC,kBAAkBA,OAAO,MAAM,CAAC,gBAAgB;YAChD,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;AACF;AAEA,MAAMC,mBAAmBA;IACvB,mBAAyB;QACvB;IACF;IACA,oBAA0B;QACxB;IACF;IACA,mBAAyB;QACvB;IACF;IACA,eACEC,MAAc,EACdC,cAA6B,EAC7BC,OAAe,EACT;QACN;IACF;IACA,eAAqB;QACnB;IACF;IACA,wBAA8B;QAC5B;IACF;IACA,iBAAuB;QACrB;IACF;IACA,mBAAyB;QACvB;IACF;AACF;AAEO,SAASC,iBAAiBA,CAACC,WAAoB;IACpD,OAAOA,cAAc,IAAIvB,kBAAkBA,KAAK,IAAIkB,mBAAmBA;AACzE"}
@@ -1 +0,0 @@
1
- export * from './input.js';
@@ -1,6 +0,0 @@
1
- export * from "./input.js";
2
-
3
-
4
- export {};
5
-
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"guardrails/index.js","sources":["../../src/guardrails/index.ts"],"sourcesContent":["export * from './input'\n"],"names":[],"mappings":";AAAuB"}
@@ -1,119 +0,0 @@
1
- import { Agent, Runner } from "@openai/agents";
2
- import { z } from "zod";
3
- import { LLM_PROVIDERS, isProd } from "../constants.js";
4
- import { HubtypeApiClient } from "../services/hubtype-api-client.js";
5
- import { TrackFeature, TrackProductName } from "../services/types.js";
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
- async function createInputGuardrails(rules, llmConfig, trackingContext) {
18
- if (rules.length === 0) {
19
- return [];
20
- }
21
- return [
22
- await buildInputGuardrail(rules, llmConfig, trackingContext)
23
- ];
24
- }
25
- async function buildInputGuardrail(rules, llmConfig, trackingContext) {
26
- const outputType = z.object(Object.fromEntries(rules.map((rule)=>[
27
- rule.name,
28
- z.boolean().describe(rule.description)
29
- ])));
30
- const modelSettings = createInputGuardrailModelSettings(llmConfig);
31
- const agent = new Agent({
32
- name: 'InputGuardrail',
33
- model: await llmConfig.getModel(),
34
- modelSettings,
35
- instructions: 'Check if the user triggers some of the following guardrails.',
36
- outputType
37
- });
38
- return {
39
- name: 'InputGuardrail',
40
- execute: async ({ input, context })=>{
41
- const lastMessage = input[input.length - 1];
42
- const runner = new Runner({
43
- tracingDisabled: true
44
- });
45
- const startTime = Date.now();
46
- const result = await runner.run(agent, [
47
- lastMessage
48
- ], {
49
- context
50
- });
51
- const endTime = Date.now();
52
- await sendGuardrailLlmRunTracking(result, trackingContext, llmConfig, startTime, endTime);
53
- const finalOutput = result.finalOutput;
54
- if (finalOutput === undefined) {
55
- throw new Error('Guardrail agent failed to produce output');
56
- }
57
- const triggered = Object.values(finalOutput).some((value)=>value === true);
58
- const triggeredGuardrails = Object.keys(finalOutput).filter((key)=>finalOutput[key] === true);
59
- return {
60
- outputInfo: triggeredGuardrails,
61
- tripwireTriggered: triggered
62
- };
63
- }
64
- };
65
- }
66
- function createInputGuardrailModelSettings(llmConfig) {
67
- const modelSettings = {
68
- ...llmConfig.modelSettings,
69
- toolChoice: undefined
70
- };
71
- if (llmConfig.modelSettings.reasoning) {
72
- modelSettings.reasoning = {
73
- ...llmConfig.modelSettings.reasoning
74
- };
75
- }
76
- if (llmConfig.modelSettings.text) {
77
- modelSettings.text = {
78
- ...llmConfig.modelSettings.text
79
- };
80
- }
81
- return modelSettings;
82
- }
83
- async function sendGuardrailLlmRunTracking(result, trackingContext, llmConfig, startTime, endTime) {
84
- if (!isProd) {
85
- return;
86
- }
87
- if (llmConfig.getProviderName() === LLM_PROVIDERS.LITELLM) {
88
- return;
89
- }
90
- const rawResponses = result.rawResponses ?? [];
91
- if (rawResponses.length === 0) {
92
- return;
93
- }
94
- const totalDuration = endTime - startTime;
95
- const durationPerCall = Math.round(totalDuration / rawResponses.length);
96
- const temperature = llmConfig.modelSettings.temperature ?? 0;
97
- const llmRuns = rawResponses.map((response)=>({
98
- inference_id: trackingContext.inferenceId,
99
- is_test: trackingContext.isTest,
100
- product_name: TrackProductName.AI_AGENT,
101
- deployment_name: llmConfig.modelName,
102
- model_name: response.providerData?.model ?? llmConfig.modelName,
103
- feature: TrackFeature.AI_AGENT_GUARDRAIL,
104
- api_version: llmConfig.getApiVersion(),
105
- num_prompt_tokens: response.usage.inputTokens,
106
- num_completion_tokens: response.usage.outputTokens,
107
- duration_in_milliseconds: durationPerCall,
108
- temperature,
109
- error: null
110
- }));
111
- const client = new HubtypeApiClient(trackingContext.authToken);
112
- await client.trackLlmRuns(trackingContext.botId, {
113
- llm_runs: llmRuns
114
- });
115
- }
116
-
117
- export { createInputGuardrails };
118
-
119
- //# sourceMappingURL=input.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"guardrails/input.js","sources":["../../src/guardrails/input.ts"],"sourcesContent":["import {\n Agent,\n type InputGuardrail,\n type ModelSettings,\n Runner,\n type UserMessageItem,\n} from '@openai/agents'\nimport { z } from 'zod'\nimport { isProd, LLM_PROVIDERS } from '../constants'\nimport type { LLMConfig } from '../llm-config'\nimport { HubtypeApiClient } from '../services/hubtype-api-client'\nimport { TrackFeature, TrackProductName } from '../services/types'\nimport type { GuardrailRule, ResultRawResponse } from '../types'\n\nexport interface GuardrailTrackingContext {\n botId: string\n isTest: boolean\n authToken: string\n inferenceId: string\n}\n\nexport async function createInputGuardrails(\n rules: GuardrailRule[],\n llmConfig: LLMConfig,\n trackingContext: GuardrailTrackingContext\n): Promise<InputGuardrail[]> {\n if (rules.length === 0) {\n return []\n }\n\n return [await buildInputGuardrail(rules, llmConfig, trackingContext)]\n}\n\nasync function buildInputGuardrail(\n rules: GuardrailRule[],\n llmConfig: LLMConfig,\n trackingContext: GuardrailTrackingContext\n): Promise<InputGuardrail> {\n const outputType = z.object(\n Object.fromEntries(\n rules.map(rule => [rule.name, z.boolean().describe(rule.description)])\n )\n )\n const modelSettings = createInputGuardrailModelSettings(llmConfig)\n\n const agent = new Agent({\n name: 'InputGuardrail',\n model: await llmConfig.getModel(),\n modelSettings,\n instructions:\n 'Check if the user triggers some of the following guardrails.',\n outputType,\n })\n\n return {\n name: 'InputGuardrail',\n execute: async ({ input, context }) => {\n const lastMessage = input[input.length - 1] as UserMessageItem\n const runner = new Runner({\n tracingDisabled: true,\n })\n const startTime = Date.now()\n const result = await runner.run(agent, [lastMessage], { context })\n const endTime = Date.now()\n\n await sendGuardrailLlmRunTracking(\n result,\n trackingContext,\n llmConfig,\n startTime,\n endTime\n )\n\n const finalOutput = result.finalOutput as Record<string, boolean>\n if (finalOutput === undefined) {\n throw new Error('Guardrail agent failed to produce output')\n }\n const triggered = Object.values(finalOutput).some(value => value === true)\n const triggeredGuardrails = Object.keys(finalOutput).filter(\n key => finalOutput[key] === true\n )\n return {\n outputInfo: triggeredGuardrails,\n tripwireTriggered: triggered,\n }\n },\n }\n}\n\nfunction createInputGuardrailModelSettings(\n llmConfig: LLMConfig\n): ModelSettings {\n const modelSettings: ModelSettings = {\n ...llmConfig.modelSettings,\n toolChoice: undefined,\n }\n if (llmConfig.modelSettings.reasoning) {\n modelSettings.reasoning = { ...llmConfig.modelSettings.reasoning }\n }\n if (llmConfig.modelSettings.text) {\n modelSettings.text = { ...llmConfig.modelSettings.text }\n }\n return modelSettings\n}\n\nasync function sendGuardrailLlmRunTracking(\n result: {\n rawResponses?: ResultRawResponse[]\n },\n trackingContext: GuardrailTrackingContext,\n llmConfig: LLMConfig,\n startTime: number,\n endTime: number\n): Promise<void> {\n if (!isProd) {\n return\n }\n if (llmConfig.getProviderName() === LLM_PROVIDERS.LITELLM) {\n return\n }\n const rawResponses = result.rawResponses ?? []\n if (rawResponses.length === 0) {\n return\n }\n const totalDuration = endTime - startTime\n const durationPerCall = Math.round(totalDuration / rawResponses.length)\n const temperature =\n (llmConfig.modelSettings.temperature as number | undefined) ?? 0\n const llmRuns = rawResponses.map(response => ({\n inference_id: trackingContext.inferenceId,\n is_test: trackingContext.isTest,\n product_name: TrackProductName.AI_AGENT,\n deployment_name: llmConfig.modelName,\n model_name:\n (response.providerData?.model as string | undefined) ??\n llmConfig.modelName,\n feature: TrackFeature.AI_AGENT_GUARDRAIL,\n api_version: llmConfig.getApiVersion(),\n num_prompt_tokens: response.usage.inputTokens,\n num_completion_tokens: response.usage.outputTokens,\n duration_in_milliseconds: durationPerCall,\n temperature,\n error: null,\n }))\n\n const client = new HubtypeApiClient(trackingContext.authToken)\n await client.trackLlmRuns(trackingContext.botId, {\n llm_runs: llmRuns,\n })\n}\n"],"names":["Agent","Runner","z","isProd","LLM_PROVIDERS","HubtypeApiClient","TrackFeature","TrackProductName","createInputGuardrails","rules","llmConfig","trackingContext","buildInputGuardrail","outputType","Object","rule","modelSettings","createInputGuardrailModelSettings","agent","input","context","lastMessage","runner","startTime","Date","result","endTime","sendGuardrailLlmRunTracking","finalOutput","undefined","Error","triggered","value","triggeredGuardrails","key","rawResponses","totalDuration","durationPerCall","Math","temperature","llmRuns","response","client"],"mappings":";;;;;;;;;;;AAMuB;AACA;AAC6B;AAEa;AACC;AAU3D,eAAeQ,qBAAqBA,CACzCC,KAAsB,EACtBC,SAAoB,EACpBC,eAAyC;IAEzC,IAAIF,MAAM,MAAM,KAAK,GAAG;QACtB,OAAO,EAAE;IACX;IAEA,OAAO;QAAC,MAAMG,mBAAmBA,CAACH,OAAOC,WAAWC;KAAiB;AACvE;AAEA,eAAeC,mBAAmBA,CAChCH,KAAsB,EACtBC,SAAoB,EACpBC,eAAyC;IAEzC,MAAME,aAAaX,QAAQ,CACzBY,OAAO,WAAW,CAChBL,MAAM,GAAG,CAACM,CAAAA,OAAQ;YAACA,KAAK,IAAI;YAAEb,SAAS,GAAG,QAAQ,CAACa,KAAK,WAAW;SAAE;IAGzE,MAAMC,gBAAgBC,iCAAiCA,CAACP;IAExD,MAAMQ,QAAQ,IAAIlB,KAAKA,CAAC;QACtB,MAAM;QACN,OAAO,MAAMU,UAAU,QAAQ;QAC/BM;QACA,cACE;QACFH;IACF;IAEA,OAAO;QACL,MAAM;QACN,SAAS,OAAO,EAAEM,KAAK,EAAEC,OAAO,EAAE;YAChC,MAAMC,cAAcF,KAAK,CAACA,MAAM,MAAM,GAAG,EAAE;YAC3C,MAAMG,SAAS,IAAIrB,MAAMA,CA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;IAChC,MAAMc,kBAAkBC,KAAK,KAAK,CAACF,gBAAgBD,aAAa,MAAM;IACtE,MAAMI,cACH7B,UAAU,aAAa,CAAC,WAAW,IAA2B;IACjE,MAAM8B,UAAUL,aAAa,GAAG,CAACM,CAAAA,WAAa;YAC5C,cAAc9B,gBAAgB,WAAW;YACzC,SAASA,gBAAgB,MAAM;YAC/B,cAAcJ,yBAAyB;YACvC,iBAAiBG,UAAU,SAAS;YACpC,YACG+B,SAAS,YAAY,EAAE,SACxB/B,UAAU,SAAS;YACrB,SAASJ,+BAA+B;YACxC,aAAaI,UAAU,aAAa;YACpC,mBAAmB+B,SAAS,KAAK,CAAC,WAAW;YAC7C,uBAAuBA,SAAS,KAAK,CAAC,YAAY;YAClD,0BAA0BJ;YAC1BE;YACA,OAAO;QACT;IAEA,MAAMG,SAAS,IAAIrC,gBAAgBA,CAACM,gBAAgB,SAAS;IAC7D,MAAM+B,OAAO,YAAY,CAAC/B,gBAAgB,KAAK,EAAE;QAC/C,UAAU6B;IACZ;AACF"}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import {\n type AIAgentRouterArgs,\n type AiAgentArgs,\n type AiAgentSpecialistArgs,\n AiAgentType,\n type BotContext,\n type HubtypeAssistantMessage,\n type Plugin,\n type ResolvedPlugins,\n} from '@botonic/core'\nimport { handoff, setTracingDisabled, tool } from '@openai/agents'\nimport { v7 as uuidv7 } from 'uuid'\nimport type { ZodObject } from 'zod'\nimport { RouterAgent, SpecialistAgent } from './agents'\nimport {\n DEFAULT_MAX_RETRIES,\n DEFAULT_TIMEOUT_16_SECONDS,\n isProd,\n MAX_MEMORY_LENGTH,\n} from './constants'\nimport { createDebugLogger, type DebugLogger } from './debug-logger'\nimport { LLMConfig } from './llm-config'\nimport { RouterRunner, SpecialistRunner } from './runners'\nimport { HubtypeApiClient } from './services/hubtype-api-client'\nimport type {\n AgenticInputMessage,\n Context,\n CustomTool,\n InferenceResponse,\n MemoryOptions,\n PluginAiAgentOptions,\n Tool,\n} from './types'\n\nexport default class BotonicPluginAiAgents<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = any,\n> implements Plugin\n{\n private readonly authToken?: string\n private readonly memory: MemoryOptions\n private readonly logger: DebugLogger\n private readonly timeout: number\n private readonly maxRetries: number\n public toolDefinitions: CustomTool<TPlugins, TExtraData>[] = []\n private readonly localStorageKey: string\n\n constructor(options?: PluginAiAgentOptions<TPlugins, TExtraData>) {\n this.authToken = options?.authToken\n this.toolDefinitions = options?.customTools || []\n this.memory = this.getMemoryOptions(options?.memory)\n this.timeout = options?.timeout ?? DEFAULT_TIMEOUT_16_SECONDS\n this.maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES\n this.logger = createDebugLogger(options?.enableDebug ?? false)\n this.localStorageKey = options?.localStorageKey ?? 'botonicState'\n setTracingDisabled(true)\n\n this.logger.logInitialConfig({\n messageHistoryApiVersion: 'v2',\n maxRetries: options?.maxRetries ?? DEFAULT_MAX_RETRIES,\n timeout: options?.timeout ?? DEFAULT_TIMEOUT_16_SECONDS,\n customToolNames: this.toolDefinitions.map(t => t.name),\n memory: this.memory,\n })\n }\n\n private getMemoryOptions(memory?: Partial<MemoryOptions>): MemoryOptions {\n return {\n maxMessages: memory?.maxMessages ?? MAX_MEMORY_LENGTH,\n includeToolCalls: memory?.includeToolCalls ?? true,\n maxFullToolResults: memory?.maxFullToolResults ?? 1,\n debugMode: memory?.debugMode ?? false,\n }\n }\n\n pre(): void {\n return\n }\n\n async getInference(\n botContext: BotContext<TPlugins, TExtraData>,\n aiAgentArgs: AiAgentArgs\n ): Promise<InferenceResponse> {\n const authToken = isProd ? botContext.session._access_token : this.authToken\n if (!authToken) {\n throw new Error('Auth token is required')\n }\n\n const inferenceId = uuidv7()\n\n try {\n if (aiAgentArgs.type === AiAgentType.Specialist) {\n return await this.executeSpecialistAIAgent(\n botContext,\n aiAgentArgs,\n authToken,\n inferenceId\n )\n }\n\n if (aiAgentArgs.type === AiAgentType.Router) {\n return await this.executeRouterAIAgent(\n botContext,\n aiAgentArgs,\n authToken,\n inferenceId\n )\n }\n\n throw new Error('Invalid agent type')\n } catch (error) {\n console.error('error plugin returns undefined', error)\n return {\n messages: [],\n toolsExecuted: [],\n memoryLength: 0,\n exit: true,\n error: true,\n inputGuardrailsTriggered: [],\n outputGuardrailsTriggered: [],\n startingAgentName: '',\n lastAgentName: '',\n availableSpecialists: [],\n isTransferredToSpecialist: false,\n }\n }\n }\n\n private async executeSpecialistAIAgent(\n botContext: BotContext<TPlugins, TExtraData>,\n aiAgentArgs: AiAgentSpecialistArgs,\n authToken: string,\n inferenceId: string\n ) {\n const llmConfig = new LLMConfig({\n maxRetries: this.maxRetries,\n timeout: this.timeout,\n modelName: aiAgentArgs.model,\n verbosity: aiAgentArgs.verbosity,\n botContext,\n reasoningEffort: aiAgentArgs.reasoningEffort,\n })\n\n // Get LLM config, tools and agent\n const { tools, agent } = await this.getSpecialistAgentAndTools(\n botContext,\n aiAgentArgs,\n aiAgentArgs.outputMessagesSchemas || [],\n authToken,\n inferenceId,\n llmConfig\n )\n\n // Get messages\n const messages = await this.getMessages(\n botContext,\n authToken,\n aiAgentArgs.previousHubtypeMessages || []\n )\n\n // Build context\n const context: Context<TPlugins, TExtraData> = {\n authToken,\n knowledgeUsed: {\n query: '',\n sourceIds: [],\n chunksIds: [],\n chunkTexts: [],\n },\n request: botContext,\n }\n\n // Log agent debug info\n this.logger.logAgentDebugInfo(\n aiAgentArgs,\n tools.map(t => t.name),\n messages\n )\n\n // Run agent\n const runner = new SpecialistRunner<TPlugins, TExtraData>(\n agent,\n llmConfig,\n inferenceId,\n this.logger\n )\n return await runner.run(messages, context)\n }\n\n private async executeRouterAIAgent(\n botContext: BotContext<TPlugins, TExtraData>,\n aiAgentArgs: AIAgentRouterArgs,\n authToken: string,\n inferenceId: string\n ) {\n const { specialists, name, instructions } = aiAgentArgs\n\n const llmConfig = new LLMConfig({\n maxRetries: this.maxRetries,\n timeout: this.timeout,\n modelName: aiAgentArgs.model,\n verbosity: aiAgentArgs.verbosity,\n botContext,\n reasoningEffort: aiAgentArgs.reasoningEffort,\n })\n\n const specialistsAgents = await Promise.all(\n specialists.map(async specialistData => {\n // If the forceToolNameOverride is set, we force this override for all specialists\n const forceToolNameOverride = aiAgentArgs.forceToolNameOverride\n const reasoningEffort = aiAgentArgs.reasoningEffort\n const disableForceRetrieveKnowledge =\n aiAgentArgs.disableForceRetrieveKnowledge\n\n // Create AiAgentArgs for the specialist, with values from AIAgentRouterArgs\n const aiAgentSpecialistArgs: AiAgentArgs = {\n ...specialistData,\n forceToolNameOverride,\n reasoningEffort,\n disableForceRetrieveKnowledge,\n }\n\n const { agent } = await this.getSpecialistAgentAndTools(\n botContext,\n aiAgentSpecialistArgs,\n aiAgentArgs.outputMessagesSchemas || [],\n authToken,\n inferenceId,\n llmConfig\n )\n\n return handoff(agent, {\n toolNameOverride: specialistData.name,\n toolDescriptionOverride: specialistData.description,\n })\n })\n )\n\n const router = await RouterAgent.create<TPlugins, TExtraData>({\n name,\n instructions,\n llmConfig,\n handoffs: specialistsAgents,\n inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],\n outputMessagesSchemas: aiAgentArgs.outputMessagesSchemas || [],\n guardrailTrackingContext: {\n botId: botContext.session.bot.id,\n isTest: botContext.session.is_test_integration,\n authToken,\n inferenceId,\n },\n })\n\n // Get messages\n const messages = await this.getMessages(\n botContext,\n authToken,\n aiAgentArgs.previousHubtypeMessages || []\n )\n\n // Build context\n const context: Context<TPlugins, TExtraData> = {\n authToken,\n knowledgeUsed: {\n query: '',\n sourceIds: [],\n chunksIds: [],\n chunkTexts: [],\n },\n request: botContext,\n }\n\n // Run agent\n const routerAgent = router.getAgent()\n const runner = new RouterRunner<TPlugins, TExtraData>(\n routerAgent,\n llmConfig,\n inferenceId,\n this.logger\n )\n\n return await runner.run(messages, context)\n }\n\n private async getSpecialistAgentAndTools(\n botContext: BotContext,\n aiAgentArgs: AiAgentArgs,\n outputMessagesSchemas: ZodObject<any>[],\n authToken: string,\n inferenceId: string,\n llmConfig: LLMConfig\n ) {\n // Build tools\n const tools = this.buildTools(aiAgentArgs)\n\n // Build agent\n const sourceIds =\n aiAgentArgs.type === AiAgentType.Specialist ? aiAgentArgs.sourceIds : []\n\n const specialist = await SpecialistAgent.create<TPlugins, TExtraData>({\n name: aiAgentArgs.name,\n instructions: aiAgentArgs.instructions,\n tools: tools,\n contactInfo: botContext.session.user.contact_info || [],\n inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],\n sourceIds,\n outputMessagesSchemas: outputMessagesSchemas || [],\n campaignsContext: botContext.input.context?.campaigns_v2,\n logger: this.logger,\n llmConfig,\n guardrailTrackingContext: {\n botId: botContext.session.bot.id,\n isTest: botContext.session.is_test_integration,\n authToken,\n inferenceId,\n },\n forceToolNameOverride: aiAgentArgs.forceToolNameOverride,\n disableForceRetrieveKnowledge: aiAgentArgs.disableForceRetrieveKnowledge,\n })\n const specialistAgent = specialist.getAgent()\n\n return { agent: specialistAgent, tools }\n }\n\n private async getMessages(\n botContext: BotContext,\n authToken: string,\n previousHubtypeMessages: HubtypeAssistantMessage[]\n ): Promise<AgenticInputMessage[]> {\n const hubtypeClient = new HubtypeApiClient(authToken)\n if (!isProd) {\n return await hubtypeClient.getLocalMessages(\n MAX_MEMORY_LENGTH,\n previousHubtypeMessages,\n this.localStorageKey\n )\n }\n\n // Default to V2\n const result = await hubtypeClient.getMessagesV2(\n botContext,\n this.memory,\n previousHubtypeMessages\n )\n return result.messages\n }\n\n private buildTools(aiAgentArgs: AiAgentArgs): Tool<TPlugins, TExtraData>[] {\n const activeTools =\n aiAgentArgs.type === AiAgentType.Router ? [] : aiAgentArgs.activeTools\n const activeToolNames = activeTools.map(tool => tool.name)\n const availableTools = this.toolDefinitions.filter(tool =>\n activeToolNames.includes(tool.name)\n )\n return availableTools.map(toolDefinition => {\n return tool<any, Context<TPlugins, TExtraData>, any>({\n name: toolDefinition.name,\n description: toolDefinition.description,\n parameters: toolDefinition.schema,\n execute: toolDefinition.func,\n })\n })\n }\n}\n\nexport * from './bot-config-tools'\nexport * from './types'\n"],"names":["AiAgentType","handoff","setTracingDisabled","tool","v7","uuidv7","RouterAgent","SpecialistAgent","DEFAULT_MAX_RETRIES","DEFAULT_TIMEOUT_16_SECONDS","isProd","MAX_MEMORY_LENGTH","createDebugLogger","LLMConfig","RouterRunner","SpecialistRunner","HubtypeApiClient","BotonicPluginAiAgents","memory","botContext","aiAgentArgs","authToken","Error","inferenceId","error","console","llmConfig","tools","agent","messages","context","t","runner","specialists","name","instructions","specialistsAgents","Promise","specialistData","forceToolNameOverride","reasoningEffort","disableForceRetrieveKnowledge","aiAgentSpecialistArgs","router","routerAgent","outputMessagesSchemas","sourceIds","specialist","specialistAgent","previousHubtypeMessages","hubtypeClient","result","activeTools","activeToolNames","availableTools","toolDefinition","options"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASsB;AAC4C;AAC/B;AAEoB;AAMnC;AACgD;AAC5B;AACkB;AACM;AAWjD,MAAMiB,qBAAqBA;IAgChC,iBAAiBC,MAA+B,EAAiB;QACvE,OAAO;YACL,aAAaA,QAAQ,eAAeP,iBAAiBA;YACrD,kBAAkBO,QAAQ,oBAAoB;YAC9C,oBAAoBA,QAAQ,sBAAsB;YAClD,WAAWA,QAAQ,aAAa;QAClC;IACF;IAEA,MAAY;QACV;IACF;IAEA,MAAM,aACJC,UAA4C,EAC5CC,WAAwB,EACI;QAC5B,MAAMC,YAAYX,MAAMA,GAAGS,WAAW,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,SAAS;QAC5E,IAAI,CAACE,WAAW;YACd,MAAM,IAAIC,MAAM;QAClB;QAEA,MAAMC,cAAclB,EAAMA;QAE1B,IAAI;YACF,IAAIe,YAAY,IAAI,KAAKpB,sBAAsB,EAAE;gBAC/C,OAAO,MAAM,IAAI,CAAC,wBAAwB,CACxCm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