@botonic/plugin-ai-agents 0.48.0 → 0.49.0-alpha.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 (160) hide show
  1. package/lib/cjs/agents/base-agent.d.ts +28 -0
  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/cjs/agents/router-agent.d.ts +25 -0
  8. package/lib/cjs/agents/router-agent.js +33 -0
  9. package/lib/cjs/agents/router-agent.js.map +1 -0
  10. package/lib/cjs/agents/worker-agent.d.ts +35 -0
  11. package/lib/cjs/{agent-builder.js → agents/worker-agent.js} +48 -49
  12. package/lib/cjs/agents/worker-agent.js.map +1 -0
  13. package/lib/cjs/bot-config-tools.js +3 -4
  14. package/lib/cjs/bot-config-tools.js.map +1 -1
  15. package/lib/cjs/debug-logger.d.ts +1 -1
  16. package/lib/cjs/debug-logger.js +4 -1
  17. package/lib/cjs/debug-logger.js.map +1 -1
  18. package/lib/cjs/guardrails/input.d.ts +1 -1
  19. package/lib/cjs/guardrails/input.js +25 -9
  20. package/lib/cjs/guardrails/input.js.map +1 -1
  21. package/lib/cjs/index.d.ts +4 -1
  22. package/lib/cjs/index.js +112 -51
  23. package/lib/cjs/index.js.map +1 -1
  24. package/lib/cjs/llm-config.d.ts +2 -1
  25. package/lib/cjs/llm-config.js +3 -0
  26. package/lib/cjs/llm-config.js.map +1 -1
  27. package/lib/cjs/runners/base-runner.d.ts +26 -0
  28. package/lib/cjs/runners/base-runner.js +114 -0
  29. package/lib/cjs/runners/base-runner.js.map +1 -0
  30. package/lib/cjs/runners/index.d.ts +2 -0
  31. package/lib/cjs/runners/index.js +8 -0
  32. package/lib/cjs/runners/index.js.map +1 -0
  33. package/lib/cjs/runners/router-runner.d.ts +6 -0
  34. package/lib/cjs/runners/router-runner.js +29 -0
  35. package/lib/cjs/runners/router-runner.js.map +1 -0
  36. package/lib/cjs/runners/worker-runner.d.ts +10 -0
  37. package/lib/cjs/runners/worker-runner.js +78 -0
  38. package/lib/cjs/runners/worker-runner.js.map +1 -0
  39. package/lib/cjs/structured-output/bot-executor.d.ts +6 -42
  40. package/lib/cjs/structured-output/bot-executor.js +9 -9
  41. package/lib/cjs/structured-output/bot-executor.js.map +1 -1
  42. package/lib/cjs/structured-output/carousel.d.ts +6 -78
  43. package/lib/cjs/structured-output/carousel.js +2 -1
  44. package/lib/cjs/structured-output/carousel.js.map +1 -1
  45. package/lib/cjs/structured-output/exit.d.ts +4 -8
  46. package/lib/cjs/structured-output/exit.js +4 -4
  47. package/lib/cjs/structured-output/exit.js.map +1 -1
  48. package/lib/cjs/structured-output/index.d.ts +48 -553
  49. package/lib/cjs/structured-output/index.js +15 -0
  50. package/lib/cjs/structured-output/index.js.map +1 -1
  51. package/lib/cjs/structured-output/text-with-buttons.d.ts +10 -49
  52. package/lib/cjs/structured-output/text-with-buttons.js +10 -10
  53. package/lib/cjs/structured-output/text-with-buttons.js.map +1 -1
  54. package/lib/cjs/structured-output/text.d.ts +4 -18
  55. package/lib/cjs/structured-output/text.js +2 -1
  56. package/lib/cjs/structured-output/text.js.map +1 -1
  57. package/lib/cjs/tools/index.d.ts +1 -1
  58. package/lib/cjs/tools/index.js +3 -2
  59. package/lib/cjs/tools/index.js.map +1 -1
  60. package/lib/cjs/tools/retrieve-knowledge.d.ts +3 -6
  61. package/lib/cjs/tools/retrieve-knowledge.js +7 -5
  62. package/lib/cjs/tools/retrieve-knowledge.js.map +1 -1
  63. package/lib/cjs/types.d.ts +2 -3
  64. package/lib/esm/agents/base-agent.d.ts +28 -0
  65. package/lib/esm/agents/base-agent.js +39 -0
  66. package/lib/esm/agents/base-agent.js.map +1 -0
  67. package/lib/esm/agents/index.d.ts +2 -0
  68. package/lib/esm/agents/index.js +8 -0
  69. package/lib/esm/agents/index.js.map +1 -0
  70. package/lib/esm/agents/router-agent.d.ts +25 -0
  71. package/lib/esm/agents/router-agent.js +33 -0
  72. package/lib/esm/agents/router-agent.js.map +1 -0
  73. package/lib/esm/agents/worker-agent.d.ts +35 -0
  74. package/lib/esm/{agent-builder.js → agents/worker-agent.js} +48 -49
  75. package/lib/esm/agents/worker-agent.js.map +1 -0
  76. package/lib/esm/bot-config-tools.js +3 -4
  77. package/lib/esm/bot-config-tools.js.map +1 -1
  78. package/lib/esm/debug-logger.d.ts +1 -1
  79. package/lib/esm/debug-logger.js +4 -1
  80. package/lib/esm/debug-logger.js.map +1 -1
  81. package/lib/esm/guardrails/input.d.ts +1 -1
  82. package/lib/esm/guardrails/input.js +25 -9
  83. package/lib/esm/guardrails/input.js.map +1 -1
  84. package/lib/esm/index.d.ts +4 -1
  85. package/lib/esm/index.js +112 -51
  86. package/lib/esm/index.js.map +1 -1
  87. package/lib/esm/llm-config.d.ts +2 -1
  88. package/lib/esm/llm-config.js +3 -0
  89. package/lib/esm/llm-config.js.map +1 -1
  90. package/lib/esm/runners/base-runner.d.ts +26 -0
  91. package/lib/esm/runners/base-runner.js +114 -0
  92. package/lib/esm/runners/base-runner.js.map +1 -0
  93. package/lib/esm/runners/index.d.ts +2 -0
  94. package/lib/esm/runners/index.js +8 -0
  95. package/lib/esm/runners/index.js.map +1 -0
  96. package/lib/esm/runners/router-runner.d.ts +6 -0
  97. package/lib/esm/runners/router-runner.js +29 -0
  98. package/lib/esm/runners/router-runner.js.map +1 -0
  99. package/lib/esm/runners/worker-runner.d.ts +10 -0
  100. package/lib/esm/runners/worker-runner.js +78 -0
  101. package/lib/esm/runners/worker-runner.js.map +1 -0
  102. package/lib/esm/structured-output/bot-executor.d.ts +6 -42
  103. package/lib/esm/structured-output/bot-executor.js +9 -9
  104. package/lib/esm/structured-output/bot-executor.js.map +1 -1
  105. package/lib/esm/structured-output/carousel.d.ts +6 -78
  106. package/lib/esm/structured-output/carousel.js +2 -1
  107. package/lib/esm/structured-output/carousel.js.map +1 -1
  108. package/lib/esm/structured-output/exit.d.ts +4 -8
  109. package/lib/esm/structured-output/exit.js +4 -4
  110. package/lib/esm/structured-output/exit.js.map +1 -1
  111. package/lib/esm/structured-output/index.d.ts +48 -553
  112. package/lib/esm/structured-output/index.js +15 -0
  113. package/lib/esm/structured-output/index.js.map +1 -1
  114. package/lib/esm/structured-output/text-with-buttons.d.ts +10 -49
  115. package/lib/esm/structured-output/text-with-buttons.js +10 -10
  116. package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
  117. package/lib/esm/structured-output/text.d.ts +4 -18
  118. package/lib/esm/structured-output/text.js +2 -1
  119. package/lib/esm/structured-output/text.js.map +1 -1
  120. package/lib/esm/tools/index.d.ts +1 -1
  121. package/lib/esm/tools/index.js +3 -2
  122. package/lib/esm/tools/index.js.map +1 -1
  123. package/lib/esm/tools/retrieve-knowledge.d.ts +3 -6
  124. package/lib/esm/tools/retrieve-knowledge.js +7 -5
  125. package/lib/esm/tools/retrieve-knowledge.js.map +1 -1
  126. package/lib/esm/types.d.ts +2 -3
  127. package/package.json +6 -7
  128. package/src/agents/base-agent.ts +75 -0
  129. package/src/agents/index.ts +2 -0
  130. package/src/agents/router-agent.ts +71 -0
  131. package/src/{agent-builder.ts → agents/worker-agent.ts} +75 -77
  132. package/src/bot-config-tools.ts +3 -4
  133. package/src/debug-logger.ts +10 -4
  134. package/src/guardrails/input.ts +35 -9
  135. package/src/index.ts +216 -82
  136. package/src/llm-config.ts +5 -0
  137. package/src/runners/base-runner.ts +190 -0
  138. package/src/runners/index.ts +2 -0
  139. package/src/runners/router-runner.ts +41 -0
  140. package/src/runners/worker-runner.ts +112 -0
  141. package/src/structured-output/bot-executor.ts +3 -3
  142. package/src/structured-output/carousel.ts +2 -2
  143. package/src/structured-output/exit.ts +3 -3
  144. package/src/structured-output/index.ts +15 -0
  145. package/src/structured-output/text-with-buttons.ts +3 -3
  146. package/src/structured-output/text.ts +2 -2
  147. package/src/tools/index.ts +4 -1
  148. package/src/tools/retrieve-knowledge.ts +32 -29
  149. package/src/types.ts +2 -3
  150. package/lib/cjs/agent-builder.d.ts +0 -37
  151. package/lib/cjs/agent-builder.js.map +0 -1
  152. package/lib/cjs/runner.d.ts +0 -18
  153. package/lib/cjs/runner.js +0 -180
  154. package/lib/cjs/runner.js.map +0 -1
  155. package/lib/esm/agent-builder.d.ts +0 -37
  156. package/lib/esm/agent-builder.js.map +0 -1
  157. package/lib/esm/runner.d.ts +0 -18
  158. package/lib/esm/runner.js +0 -180
  159. package/lib/esm/runner.js.map +0 -1
  160. package/src/runner.ts +0 -283
@@ -1,56 +1,17 @@
1
- import type { TextWithButtonsMessage } from '@botonic/core';
2
- import z from 'zod';
1
+ import { OutputMessageType, type TextWithButtonsMessage } from '@botonic/core';
2
+ import { z } from 'zod';
3
3
  export type { TextWithButtonsMessage };
4
4
  export declare const TextWithButtonsSchema: z.ZodObject<{
5
- type: z.ZodEnum<["textWithButtons"]>;
5
+ type: z.ZodLiteral<OutputMessageType.TextWithButtons>;
6
6
  content: z.ZodObject<{
7
7
  text: z.ZodString;
8
8
  buttons: z.ZodArray<z.ZodObject<{
9
9
  text: z.ZodString;
10
10
  url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
11
- target: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodEnum<["_blank", "_self"]>>>>;
12
- }, "strip", z.ZodTypeAny, {
13
- text: string;
14
- url?: string | null | undefined;
15
- target?: "_blank" | "_self" | null | undefined;
16
- }, {
17
- text: string;
18
- url?: string | null | undefined;
19
- target?: "_blank" | "_self" | null | undefined;
20
- }>, "many">;
21
- }, "strip", z.ZodTypeAny, {
22
- text: string;
23
- buttons: {
24
- text: string;
25
- url?: string | null | undefined;
26
- target?: "_blank" | "_self" | null | undefined;
27
- }[];
28
- }, {
29
- text: string;
30
- buttons: {
31
- text: string;
32
- url?: string | null | undefined;
33
- target?: "_blank" | "_self" | null | undefined;
34
- }[];
35
- }>;
36
- }, "strip", z.ZodTypeAny, {
37
- type: "textWithButtons";
38
- content: {
39
- text: string;
40
- buttons: {
41
- text: string;
42
- url?: string | null | undefined;
43
- target?: "_blank" | "_self" | null | undefined;
44
- }[];
45
- };
46
- }, {
47
- type: "textWithButtons";
48
- content: {
49
- text: string;
50
- buttons: {
51
- text: string;
52
- url?: string | null | undefined;
53
- target?: "_blank" | "_self" | null | undefined;
54
- }[];
55
- };
56
- }>;
11
+ target: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodEnum<{
12
+ _blank: "_blank";
13
+ _self: "_self";
14
+ }>>>>;
15
+ }, z.core.$strip>>;
16
+ }, z.core.$strip>;
17
+ }, z.core.$strip>;
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TextWithButtonsSchema = void 0;
4
- const tslib_1 = require("tslib");
5
- const zod_1 = tslib_1.__importDefault(require("zod"));
6
- exports.TextWithButtonsSchema = zod_1.default
4
+ const core_1 = require("@botonic/core");
5
+ const zod_1 = require("zod");
6
+ exports.TextWithButtonsSchema = zod_1.z
7
7
  .object({
8
- type: zod_1.default.enum(['textWithButtons']),
9
- content: zod_1.default.object({
10
- text: zod_1.default.string(),
11
- buttons: zod_1.default.array(zod_1.default.object({
12
- text: zod_1.default.string(),
13
- url: zod_1.default.string().nullable().optional(),
14
- target: zod_1.default
8
+ type: zod_1.z.literal(core_1.OutputMessageType.TextWithButtons),
9
+ content: zod_1.z.object({
10
+ text: zod_1.z.string(),
11
+ buttons: zod_1.z.array(zod_1.z.object({
12
+ text: zod_1.z.string(),
13
+ url: zod_1.z.string().nullable().optional(),
14
+ target: zod_1.z
15
15
  .enum(['_blank', '_self'])
16
16
  .default('_blank')
17
17
  .nullable()
@@ -1 +1 @@
1
- {"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":";;;;AACA,sDAAmB;AAIN,QAAA,qBAAqB,GAAG,aAAC;KACnC,MAAM,CAAC;IACN,IAAI,EAAE,aAAC,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACjC,OAAO,EAAE,aAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,aAAC,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,aAAC,CAAC,KAAK,CACd,aAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,aAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;YACrC,MAAM,EAAE,aAAC;iBACN,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;iBACzB,OAAO,CAAC,QAAQ,CAAC;iBACjB,QAAQ,EAAE;iBACV,QAAQ,EAAE;iBACV,QAAQ,CACP,0FAA0F,CAC3F;SACJ,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CACP,oEAAoE,CACrE,CAAA"}
1
+ {"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":";;;AAAA,wCAA8E;AAC9E,6BAAuB;AAIV,QAAA,qBAAqB,GAAG,OAAC;KACnC,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,wBAAiB,CAAC,eAAe,CAAC;IAClD,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,OAAC,CAAC,KAAK,CACd,OAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;YACrC,MAAM,EAAE,OAAC;iBACN,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;iBACzB,OAAO,CAAC,QAAQ,CAAC;iBACjB,QAAQ,EAAE;iBACV,QAAQ,EAAE;iBACV,QAAQ,CACP,0FAA0F,CAC3F;SACJ,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CACP,oEAAoE,CACrE,CAAA"}
@@ -1,23 +1,9 @@
1
- import type { TextMessage } from '@botonic/core';
1
+ import { OutputMessageType, type TextMessage } from '@botonic/core';
2
2
  import { z } from 'zod';
3
3
  export type { TextMessage };
4
4
  export declare const TextSchema: z.ZodObject<{
5
- type: z.ZodEnum<["text"]>;
5
+ type: z.ZodLiteral<OutputMessageType.Text>;
6
6
  content: z.ZodObject<{
7
7
  text: z.ZodString;
8
- }, "strip", z.ZodTypeAny, {
9
- text: string;
10
- }, {
11
- text: string;
12
- }>;
13
- }, "strip", z.ZodTypeAny, {
14
- type: "text";
15
- content: {
16
- text: string;
17
- };
18
- }, {
19
- type: "text";
20
- content: {
21
- text: string;
22
- };
23
- }>;
8
+ }, z.core.$strip>;
9
+ }, z.core.$strip>;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TextSchema = void 0;
4
+ const core_1 = require("@botonic/core");
4
5
  const zod_1 = require("zod");
5
6
  exports.TextSchema = zod_1.z
6
7
  .object({
7
- type: zod_1.z.enum(['text']),
8
+ type: zod_1.z.literal(core_1.OutputMessageType.Text),
8
9
  content: zod_1.z.object({
9
10
  text: zod_1.z.string(),
10
11
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/structured-output/text.ts"],"names":[],"mappings":";;;AACA,6BAAuB;AAIV,QAAA,UAAU,GAAG,OAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;KACjB,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,gBAAgB,CAAC,CAAA"}
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/structured-output/text.ts"],"names":[],"mappings":";;;AAAA,wCAAmE;AACnE,6BAAuB;AAIV,QAAA,UAAU,GAAG,OAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,wBAAiB,CAAC,IAAI,CAAC;IACvC,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;KACjB,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,gBAAgB,CAAC,CAAA"}
@@ -1,3 +1,3 @@
1
1
  import type { Tool } from '../types';
2
- export { retrieveKnowledge } from './retrieve-knowledge';
2
+ export { createRetrieveKnowledge, RETRIEVE_KNOWLEDGE_TOOL_NAME, } from './retrieve-knowledge';
3
3
  export declare const mandatoryTools: Tool[];
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mandatoryTools = exports.retrieveKnowledge = void 0;
3
+ exports.mandatoryTools = exports.RETRIEVE_KNOWLEDGE_TOOL_NAME = exports.createRetrieveKnowledge = void 0;
4
4
  var retrieve_knowledge_1 = require("./retrieve-knowledge");
5
- Object.defineProperty(exports, "retrieveKnowledge", { enumerable: true, get: function () { return retrieve_knowledge_1.retrieveKnowledge; } });
5
+ Object.defineProperty(exports, "createRetrieveKnowledge", { enumerable: true, get: function () { return retrieve_knowledge_1.createRetrieveKnowledge; } });
6
+ Object.defineProperty(exports, "RETRIEVE_KNOWLEDGE_TOOL_NAME", { enumerable: true, get: function () { return retrieve_knowledge_1.RETRIEVE_KNOWLEDGE_TOOL_NAME; } });
6
7
  exports.mandatoryTools = [];
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":";;;AAEA,2DAAwD;AAA/C,uHAAA,iBAAiB,OAAA;AAEb,QAAA,cAAc,GAAW,EAAE,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":";;;AAEA,2DAG6B;AAF3B,6HAAA,uBAAuB,OAAA;AACvB,kIAAA,4BAA4B,OAAA;AAGjB,QAAA,cAAc,GAAW,EAAE,CAAA"}
@@ -1,9 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import type { Context } from '../types';
3
- export declare const retrieveKnowledge: import("@openai/agents").FunctionTool<Context<import("@botonic/core").ResolvedPlugins, any>, z.ZodObject<{
3
+ export declare const RETRIEVE_KNOWLEDGE_TOOL_NAME = "retrieve_knowledge";
4
+ export declare const createRetrieveKnowledge: (sourceIds: string[]) => import("@openai/agents").FunctionTool<Context<import("@botonic/core").ResolvedPlugins, any>, z.ZodObject<{
4
5
  query: z.ZodString;
5
- }, "strip", z.ZodTypeAny, {
6
- query: string;
7
- }, {
8
- query: string;
9
- }>, string>;
6
+ }, z.core.$strip>, string>;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.retrieveKnowledge = void 0;
3
+ exports.createRetrieveKnowledge = exports.RETRIEVE_KNOWLEDGE_TOOL_NAME = void 0;
4
4
  const agents_1 = require("@openai/agents");
5
5
  const zod_1 = require("zod");
6
6
  const hubtype_api_client_1 = require("../services/hubtype-api-client");
7
- exports.retrieveKnowledge = (0, agents_1.tool)({
8
- name: 'retrieve_knowledge',
7
+ exports.RETRIEVE_KNOWLEDGE_TOOL_NAME = 'retrieve_knowledge';
8
+ const createRetrieveKnowledge = (sourceIds) => (0, agents_1.tool)({
9
+ name: exports.RETRIEVE_KNOWLEDGE_TOOL_NAME,
9
10
  description: 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
10
11
  parameters: zod_1.z.object({
11
12
  query: zod_1.z.string().describe('The query to search the knowledge base for'),
@@ -16,17 +17,18 @@ exports.retrieveKnowledge = (0, agents_1.tool)({
16
17
  if (!context) {
17
18
  throw new Error('Context is required');
18
19
  }
19
- const sourceIds = context.sourceIds;
20
20
  const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
21
21
  const chunks = await client.retrieveSimilarChunks(query, sourceIds);
22
+ const chunksIds = chunks.map(chunk => chunk.id);
22
23
  const chunkTexts = chunks.map(chunk => chunk.text);
23
24
  context.knowledgeUsed = {
24
25
  query,
25
26
  sourceIds,
26
- chunksIds: chunks.map(chunk => chunk.id),
27
+ chunksIds,
27
28
  chunkTexts,
28
29
  };
29
30
  return chunkTexts;
30
31
  },
31
32
  });
33
+ exports.createRetrieveKnowledge = createRetrieveKnowledge;
32
34
  //# sourceMappingURL=retrieve-knowledge.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AACtD,6BAAuB;AAEvB,uEAAiE;AAGpD,QAAA,iBAAiB,GAAG,IAAA,aAAI,EAAC;IACpC,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EACT,kIAAkI;IACpI,UAAU,EAAE,OAAC,CAAC,MAAM,CAAC;QACnB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;KACzE,CAAC;IACF,OAAO,EAAE,KAAK,EACZ,KAAwB,EACxB,UAAgC,EACb,EAAE;QACrB,MAAM,OAAO,GAAG,UAAU,EAAE,OAAO,CAAA;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QACxC,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QACnC,MAAM,MAAM,GAAG,IAAI,qCAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACtD,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SAAS,CAAC,CAAA;QACnE,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC/C,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAElD,OAAO,CAAC,aAAa,GAAG;YACtB,KAAK;YACL,SAAS;YACT,SAAS;YACT,UAAU;SACX,CAAA;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;CACF,CAAC,CAAA;AA/BS,QAAA,uBAAuB,2BA+BhC"}
@@ -1,10 +1,9 @@
1
1
  import { AgenticOutputMessage, AiAgentArgs, type BotContext, GuardrailRule, InferenceResponse, type ResolvedPlugins, RunResult } from '@botonic/core';
2
2
  import type { Agent, AgentInputItem, AgentOutputType, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
3
- import type { ZodSchema } from 'zod';
3
+ import type { ZodType } from 'zod';
4
4
  import type { OutputSchema } from './structured-output';
5
5
  export interface Context<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
6
6
  authToken: string;
7
- sourceIds: string[];
8
7
  knowledgeUsed: {
9
8
  query: string;
10
9
  sourceIds: string[];
@@ -17,7 +16,7 @@ export type RunContext<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtr
17
16
  export interface CustomTool<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
18
17
  name: string;
19
18
  description: string;
20
- schema: ZodSchema;
19
+ schema: ZodType;
21
20
  func: (input?: any, runContext?: RunContext<TPlugins, TExtraData>) => Promise<any>;
22
21
  }
23
22
  export interface Chunk {
@@ -0,0 +1,28 @@
1
+ import type { AgentOutputType, InputGuardrail, Model, ModelSettings } from '@openai/agents';
2
+ import type { z } from 'zod';
3
+ import type { GuardrailTrackingContext } from '../guardrails/input';
4
+ import type { LLMConfig } from '../llm-config';
5
+ import { type OutputSchema } from '../structured-output';
6
+ import type { GuardrailRule } from '../types';
7
+ export interface BaseAgentOptions {
8
+ name: string;
9
+ instructions: string;
10
+ llmConfig: LLMConfig;
11
+ inputGuardrailRules: GuardrailRule[];
12
+ outputMessagesSchemas?: z.ZodObject[];
13
+ guardrailTrackingContext: GuardrailTrackingContext;
14
+ }
15
+ export declare abstract class BaseAgent {
16
+ protected name: string;
17
+ protected instructions: string;
18
+ protected llmConfig: LLMConfig;
19
+ private inputGuardrailRules;
20
+ private outputMessagesSchemas;
21
+ private guardrailTrackingContext;
22
+ constructor(options: BaseAgentOptions);
23
+ protected getAgentModelSettings(): ModelSettings;
24
+ protected getInputGuardrails(): Promise<InputGuardrail[]>;
25
+ protected getOutputType(): AgentOutputType<typeof OutputSchema>;
26
+ protected addOutputInstructions(instructions: string): string;
27
+ protected getModel(): Promise<string | Model>;
28
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseAgent = void 0;
4
+ const guardrails_1 = require("../guardrails");
5
+ const structured_output_1 = require("../structured-output");
6
+ class BaseAgent {
7
+ constructor(options) {
8
+ this.name = options.name;
9
+ this.instructions = options.instructions;
10
+ this.llmConfig = options.llmConfig;
11
+ this.inputGuardrailRules = options.inputGuardrailRules;
12
+ this.outputMessagesSchemas = options.outputMessagesSchemas || [];
13
+ this.guardrailTrackingContext = options.guardrailTrackingContext;
14
+ }
15
+ getAgentModelSettings() {
16
+ const modelSettings = { ...this.llmConfig.modelSettings };
17
+ if (this.llmConfig.modelSettings.reasoning) {
18
+ modelSettings.reasoning = { ...this.llmConfig.modelSettings.reasoning };
19
+ }
20
+ if (this.llmConfig.modelSettings.text) {
21
+ modelSettings.text = { ...this.llmConfig.modelSettings.text };
22
+ }
23
+ return modelSettings;
24
+ }
25
+ async getInputGuardrails() {
26
+ return await (0, guardrails_1.createInputGuardrails)(this.inputGuardrailRules, this.llmConfig, this.guardrailTrackingContext);
27
+ }
28
+ getOutputType() {
29
+ return (0, structured_output_1.getOutputSchema)(this.outputMessagesSchemas);
30
+ }
31
+ addOutputInstructions(instructions) {
32
+ return `${instructions}\n\n${(0, structured_output_1.getOutputInstructions)()}`;
33
+ }
34
+ async getModel() {
35
+ return await this.llmConfig.getModel();
36
+ }
37
+ }
38
+ exports.BaseAgent = BaseAgent;
39
+ //# sourceMappingURL=base-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-agent.js","sourceRoot":"","sources":["../../../src/agents/base-agent.ts"],"names":[],"mappings":";;;AAQA,8CAAqD;AAGrD,4DAI6B;AAY7B,MAAsB,SAAS;IAQ7B,YAAY,OAAyB;QACnC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;QACxC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAA;QACtD,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,IAAI,EAAE,CAAA;QAChE,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAA;IAClE,CAAC;IAES,qBAAqB;QAC7B,MAAM,aAAa,GAAkB,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,CAAA;QACxE,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;YAC3C,aAAa,CAAC,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE,CAAA;QACzE,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YACtC,aAAa,CAAC,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,CAAA;QAC/D,CAAC;QACD,OAAO,aAAa,CAAA;IACtB,CAAC;IAES,KAAK,CAAC,kBAAkB;QAChC,OAAO,MAAM,IAAA,kCAAqB,EAChC,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,wBAAwB,CAC9B,CAAA;IACH,CAAC;IAES,aAAa;QACrB,OAAO,IAAA,mCAAe,EAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;IACpD,CAAC;IAES,qBAAqB,CAAC,YAAoB;QAClD,OAAO,GAAG,YAAY,OAAO,IAAA,yCAAqB,GAAE,EAAE,CAAA;IACxD,CAAC;IAES,KAAK,CAAC,QAAQ;QACtB,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAA;IACxC,CAAC;CACF;AA/CD,8BA+CC"}
@@ -0,0 +1,2 @@
1
+ export { RouterAgent } from './router-agent';
2
+ export { WorkerAgent } from './worker-agent';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkerAgent = exports.RouterAgent = void 0;
4
+ var router_agent_1 = require("./router-agent");
5
+ Object.defineProperty(exports, "RouterAgent", { enumerable: true, get: function () { return router_agent_1.RouterAgent; } });
6
+ var worker_agent_1 = require("./worker-agent");
7
+ Object.defineProperty(exports, "WorkerAgent", { enumerable: true, get: function () { return worker_agent_1.WorkerAgent; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agents/index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAAnC,2GAAA,WAAW,OAAA;AACpB,+CAA4C;AAAnC,2GAAA,WAAW,OAAA"}
@@ -0,0 +1,25 @@
1
+ import type { ResolvedPlugins } from '@botonic/core';
2
+ import { type AgentOutputType, type Handoff } from '@openai/agents';
3
+ import type { z } from 'zod';
4
+ import type { GuardrailTrackingContext } from '../guardrails/input';
5
+ import type { LLMConfig } from '../llm-config';
6
+ import type { OutputSchema } from '../structured-output';
7
+ import type { AIAgent, Context, GuardrailRule } from '../types';
8
+ import { BaseAgent } from './base-agent';
9
+ interface RouterAgentOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown> {
10
+ name: string;
11
+ instructions: string;
12
+ llmConfig: LLMConfig;
13
+ handoffs: Handoff<Context<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>[];
14
+ inputGuardrailRules: GuardrailRule[];
15
+ outputMessagesSchemas?: z.ZodObject[];
16
+ guardrailTrackingContext: GuardrailTrackingContext;
17
+ }
18
+ export declare class RouterAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown> extends BaseAgent {
19
+ private handoffs;
20
+ private agent;
21
+ private constructor();
22
+ static create<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown>(options: RouterAgentOptions<TPlugins, TExtraData>): Promise<RouterAgent<TPlugins, TExtraData>>;
23
+ getAgent(): AIAgent<TPlugins, TExtraData>;
24
+ }
25
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RouterAgent = void 0;
4
+ const agents_1 = require("@openai/agents");
5
+ const extensions_1 = require("@openai/agents-core/extensions");
6
+ const base_agent_1 = require("./base-agent");
7
+ class RouterAgent extends base_agent_1.BaseAgent {
8
+ constructor(options) {
9
+ super(options);
10
+ this.handoffs = options.handoffs;
11
+ }
12
+ static async create(options) {
13
+ const routerAgent = new RouterAgent(options);
14
+ const inputGuardrails = await routerAgent.getInputGuardrails();
15
+ // Agent.create is typed as Agent<UnknownContext>; we run with Context<TPlugins, TExtraData>.
16
+ const agent = agents_1.Agent.create({
17
+ name: routerAgent.name,
18
+ model: await routerAgent.getModel(),
19
+ modelSettings: routerAgent.getAgentModelSettings(),
20
+ instructions: routerAgent.addOutputInstructions(`${extensions_1.RECOMMENDED_PROMPT_PREFIX}${routerAgent.instructions}`),
21
+ handoffs: routerAgent.handoffs,
22
+ outputType: routerAgent.getOutputType(),
23
+ inputGuardrails,
24
+ });
25
+ routerAgent.agent = agent;
26
+ return routerAgent;
27
+ }
28
+ getAgent() {
29
+ return this.agent;
30
+ }
31
+ }
32
+ exports.RouterAgent = RouterAgent;
33
+ //# sourceMappingURL=router-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router-agent.js","sourceRoot":"","sources":["../../../src/agents/router-agent.ts"],"names":[],"mappings":";;;AACA,2CAA0E;AAC1E,+DAA0E;AAM1E,6CAAwC;AAkBxC,MAAa,WAGX,SAAQ,sBAAS;IAOjB,YAAoB,OAAiD;QACnE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;IAClC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAIjB,OAAiD;QAEjD,MAAM,WAAW,GAAG,IAAI,WAAW,CAAuB,OAAO,CAAC,CAAA;QAClE,MAAM,eAAe,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,CAAA;QAE9D,6FAA6F;QAC7F,MAAM,KAAK,GAAG,cAAK,CAAC,MAAM,CAAC;YACzB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,KAAK,EAAE,MAAM,WAAW,CAAC,QAAQ,EAAE;YACnC,aAAa,EAAE,WAAW,CAAC,qBAAqB,EAAE;YAClD,YAAY,EAAE,WAAW,CAAC,qBAAqB,CAC7C,GAAG,sCAAyB,GAAG,WAAW,CAAC,YAAY,EAAE,CAC1D;YACD,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,UAAU,EAAE,WAAW,CAAC,aAAa,EAAE;YACvC,eAAe;SAChB,CAAkC,CAAA;QAEnC,WAAW,CAAC,KAAK,GAAG,KAAK,CAAA;QACzB,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;CACF;AA5CD,kCA4CC"}
@@ -0,0 +1,35 @@
1
+ import type { CampaignV2, ContactInfo, ResolvedPlugins } from '@botonic/core';
2
+ import type { z } from 'zod';
3
+ import type { DebugLogger } from '../debug-logger';
4
+ import type { GuardrailTrackingContext } from '../guardrails/input';
5
+ import type { LLMConfig } from '../llm-config';
6
+ import type { AIAgent, GuardrailRule, Tool } from '../types';
7
+ import { BaseAgent } from './base-agent';
8
+ interface WorkerAgentOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown> {
9
+ name: string;
10
+ instructions: string;
11
+ tools: Tool<TPlugins, TExtraData>[];
12
+ campaignsContext?: CampaignV2[];
13
+ contactInfo: ContactInfo[];
14
+ inputGuardrailRules: GuardrailRule[];
15
+ sourceIds: string[];
16
+ outputMessagesSchemas?: z.ZodObject[];
17
+ llmConfig: LLMConfig;
18
+ logger: DebugLogger;
19
+ guardrailTrackingContext: GuardrailTrackingContext;
20
+ }
21
+ export declare class WorkerAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown> extends BaseAgent {
22
+ private tools;
23
+ private logger;
24
+ private agent;
25
+ private constructor();
26
+ static create<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = unknown>(options: WorkerAgentOptions<TPlugins, TExtraData>): Promise<WorkerAgent<TPlugins, TExtraData>>;
27
+ getAgent(): AIAgent<TPlugins, TExtraData>;
28
+ private getWorkerModelSettings;
29
+ private addExtraInstructions;
30
+ private getContactInfoInstructions;
31
+ private getMetadataInstructions;
32
+ private getCampaignInstructions;
33
+ private addHubtypeTools;
34
+ }
35
+ export {};
@@ -1,55 +1,68 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AIAgentBuilder = void 0;
3
+ exports.WorkerAgent = void 0;
4
4
  const agents_1 = require("@openai/agents");
5
- const constants_1 = require("./constants");
6
- const guardrails_1 = require("./guardrails");
7
- const structured_output_1 = require("./structured-output");
8
- const tools_1 = require("./tools");
9
- class AIAgentBuilder {
5
+ const constants_1 = require("../constants");
6
+ const tools_1 = require("../tools");
7
+ const base_agent_1 = require("./base-agent");
8
+ class WorkerAgent extends base_agent_1.BaseAgent {
10
9
  constructor(options) {
11
- this.name = options.name;
10
+ super({
11
+ name: options.name,
12
+ instructions: options.instructions,
13
+ llmConfig: options.llmConfig,
14
+ inputGuardrailRules: options.inputGuardrailRules,
15
+ outputMessagesSchemas: options.outputMessagesSchemas,
16
+ guardrailTrackingContext: options.guardrailTrackingContext,
17
+ });
12
18
  this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.campaignsContext);
13
19
  this.tools = this.addHubtypeTools(options.tools, options.sourceIds);
14
- this.externalOutputMessagesSchemas = options.outputMessagesSchemas || [];
15
- this.inputGuardrails = [];
16
- this.llmConfig = options.llmConfig;
17
20
  this.logger = options.logger;
18
- if (options.inputGuardrailRules.length > 0) {
19
- const inputGuardrail = (0, guardrails_1.createInputGuardrail)(options.inputGuardrailRules, options.llmConfig, options.guardrailTrackingContext);
20
- this.inputGuardrails.push(inputGuardrail);
21
- }
22
21
  }
23
- build() {
24
- // When using standard OpenAI API, we need to specify the model
25
- // Azure OpenAI uses deployment name instead
26
- const model = this.llmConfig.modelName;
27
- const hasRetrieveKnowledge = this.tools.includes(tools_1.retrieveKnowledge);
28
- this.logger.logModelSettings({
22
+ static async create(options) {
23
+ const workerAgent = new WorkerAgent(options);
24
+ const model = workerAgent.llmConfig.modelName;
25
+ const resolvedModel = await workerAgent.getModel();
26
+ const hasRetrieveKnowledge = workerAgent.tools.some(tool => tool.name === tools_1.RETRIEVE_KNOWLEDGE_TOOL_NAME);
27
+ const modelSettings = workerAgent.getWorkerModelSettings(hasRetrieveKnowledge);
28
+ const inputGuardrails = await workerAgent.getInputGuardrails();
29
+ workerAgent.logger.logModelSettings({
29
30
  provider: constants_1.OPENAI_PROVIDER,
30
31
  model,
31
- reasoning: this.llmConfig.modelSettings.reasoning,
32
- text: this.llmConfig.modelSettings.text,
33
- toolChoice: this.llmConfig.modelSettings.toolChoice,
32
+ reasoning: modelSettings.reasoning,
33
+ text: modelSettings.text,
34
+ toolChoice: modelSettings.toolChoice,
34
35
  hasRetrieveKnowledge,
35
36
  });
36
- return new agents_1.Agent({
37
- name: this.name,
38
- model,
39
- instructions: this.instructions,
40
- tools: this.tools,
41
- outputType: (0, structured_output_1.getOutputSchema)(this.externalOutputMessagesSchemas),
42
- inputGuardrails: this.inputGuardrails,
37
+ const agent = new agents_1.Agent({
38
+ name: workerAgent.name,
39
+ model: resolvedModel,
40
+ modelSettings,
41
+ instructions: workerAgent.instructions,
42
+ tools: workerAgent.tools,
43
+ outputType: workerAgent.getOutputType(),
44
+ inputGuardrails,
43
45
  outputGuardrails: [],
44
46
  });
47
+ workerAgent.agent = agent;
48
+ return workerAgent;
49
+ }
50
+ getAgent() {
51
+ return this.agent;
52
+ }
53
+ getWorkerModelSettings(hasRetrieveKnowledge) {
54
+ const modelSettings = this.getAgentModelSettings();
55
+ if (hasRetrieveKnowledge) {
56
+ modelSettings.toolChoice = tools_1.RETRIEVE_KNOWLEDGE_TOOL_NAME;
57
+ }
58
+ return modelSettings;
45
59
  }
46
60
  addExtraInstructions(initialInstructions, contactInfo, campaignsContext) {
47
61
  const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`;
48
62
  const metadataInstructions = this.getMetadataInstructions();
49
63
  const contactInfoInstructions = this.getContactInfoInstructions(contactInfo);
50
64
  const campaignInstructions = this.getCampaignInstructions(campaignsContext);
51
- const outputInstructions = this.getOutputInstructions();
52
- return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`;
65
+ return this.addOutputInstructions(`${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}`);
53
66
  }
54
67
  getContactInfoInstructions(contactInfo) {
55
68
  const structuredContactInfo = contactInfo
@@ -80,27 +93,13 @@ class AIAgentBuilder {
80
93
  .map((campaign, index) => `<campaign_context_${index + 1}>\n${campaign.agent_context}\n</campaign_context_${index + 1}>`)
81
94
  .join('\n');
82
95
  }
83
- getOutputInstructions() {
84
- const example = {
85
- messages: [
86
- {
87
- type: 'text',
88
- content: {
89
- text: 'Hello, how can I help you today?',
90
- },
91
- },
92
- ],
93
- };
94
- const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${JSON.stringify(example)}\n</example>`;
95
- return `<output>\n${output}\n</output>`;
96
- }
97
96
  addHubtypeTools(tools, sourceIds) {
98
97
  const hubtypeTools = [...tools_1.mandatoryTools];
99
98
  if (sourceIds.length > 0) {
100
- hubtypeTools.push(tools_1.retrieveKnowledge);
99
+ hubtypeTools.push((0, tools_1.createRetrieveKnowledge)(sourceIds));
101
100
  }
102
101
  return [...hubtypeTools, ...tools];
103
102
  }
104
103
  }
105
- exports.AIAgentBuilder = AIAgentBuilder;
106
- //# sourceMappingURL=agent-builder.js.map
104
+ exports.WorkerAgent = WorkerAgent;
105
+ //# sourceMappingURL=worker-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-agent.js","sourceRoot":"","sources":["../../../src/agents/worker-agent.ts"],"names":[],"mappings":";;;AACA,2CAAgF;AAEhF,4CAA8C;AAK9C,oCAIiB;AAEjB,6CAAwC;AAmBxC,MAAa,WAGX,SAAQ,sBAAS;IAKjB,YAAoB,OAAiD;QACnE,KAAK,CAAC;YACJ,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;YAChD,qBAAqB,EAAE,OAAO,CAAC,qBAAqB;YACpD,wBAAwB,EAAE,OAAO,CAAC,wBAAwB;SAC3D,CAAC,CAAA;QACF,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAC3C,OAAO,CAAC,YAAY,EACpB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,gBAAgB,CACzB,CAAA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CAAA;QAC5D,OAAO,eAAe,QAAQ,eAAe,CAAA;IAC/C,CAAC;IAEO,uBAAuB,CAAC,gBAA+B;QAC7D,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,OAAO,EAAE,CAAA;QACX,CAAC;QACD,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,MAAM,CAClD,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,aAAa,CACnC,CAAA;QACD,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtC,OAAO,EAAE,CAAA;QACX,CAAC;QACD,OAAO,oBAAoB;aACxB,GAAG,CACF,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAClB,qBAAqB,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,aAAa,wBAAwB,KAAK,GAAG,CAAC,GAAG,CACjG;aACA,IAAI,CAAC,IAAI,CAAC,CAAA;IACf,CAAC;IAEO,eAAe,CACrB,KAAmC,EACnC,SAAmB;QAEnB,MAAM,YAAY,GAAW,CAAC,GAAG,sBAAc,CAAC,CAAA;QAChD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,IAAA,+BAAuB,EAAC,SAAS,CAAC,CAAC,CAAA;QACvD,CAAC;QACD,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF;AAnJD,kCAmJC"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getToolsForBotConfig = getToolsForBotConfig;
4
- const zod_to_json_schema_1 = require("zod-to-json-schema");
4
+ const zod_1 = require("zod");
5
5
  /**
6
6
  * Maps custom AI agent tools to the format expected by bot config (e.g. for flow-builder).
7
7
  * Converts each tool's Zod schema to JSON Schema so it can be serialized in the config.
@@ -10,9 +10,8 @@ function getToolsForBotConfig(customTools) {
10
10
  return customTools.map(tool => ({
11
11
  name: tool.name,
12
12
  description: tool.description,
13
- // Cast to avoid TS "Type instantiation is excessively deep" with zodToJsonSchema + ZodSchema
14
- schema: (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema, {
15
- $refStrategy: 'none',
13
+ schema: zod_1.z.toJSONSchema(tool.schema, {
14
+ target: 'draft-07',
16
15
  }),
17
16
  }));
18
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bot-config-tools.js","sourceRoot":"","sources":["../../src/bot-config-tools.ts"],"names":[],"mappings":";;AASA,oDAWC;AAnBD,2DAAoD;AAIpD;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,WAAyB;IAEzB,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,6FAA6F;QAC7F,MAAM,EAAE,IAAA,oCAAe,EAAC,IAAI,CAAC,MAAe,EAAE;YAC5C,YAAY,EAAE,MAAM;SACrB,CAA6B;KAC/B,CAAC,CAAC,CAAA;AACL,CAAC"}
1
+ {"version":3,"file":"bot-config-tools.js","sourceRoot":"","sources":["../../src/bot-config-tools.ts"],"names":[],"mappings":";;AASA,oDAUC;AAlBD,6BAAuB;AAIvB;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,WAAyB;IAEzB,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,MAAM,EAAE,OAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE;YAClC,MAAM,EAAE,UAAU;SACnB,CAA6B;KAC/B,CAAC,CAAC,CAAA;AACL,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { AiAgentArgs, ToolExecution } from '@botonic/core';
1
+ import { type AiAgentArgs, type ToolExecution } from '@botonic/core';
2
2
  import type { ModelSettings } from '@openai/agents';
3
3
  import type { AgenticInputMessage, MemoryOptions, RunResult } from './types';
4
4
  export interface DebugLoggerConfig {