@botonic/plugin-ai-agents 0.37.0 → 0.37.2-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 (73) hide show
  1. package/README.md +148 -6
  2. package/lib/cjs/agent-builder.d.ts +6 -2
  3. package/lib/cjs/agent-builder.js +28 -5
  4. package/lib/cjs/agent-builder.js.map +1 -1
  5. package/lib/cjs/guardrails/index.d.ts +1 -0
  6. package/lib/cjs/guardrails/index.js +5 -0
  7. package/lib/cjs/guardrails/index.js.map +1 -0
  8. package/lib/cjs/guardrails/input.d.ts +3 -0
  9. package/lib/cjs/guardrails/input.js +33 -0
  10. package/lib/cjs/guardrails/input.js.map +1 -0
  11. package/lib/cjs/index.d.ts +2 -2
  12. package/lib/cjs/index.js +3 -1
  13. package/lib/cjs/index.js.map +1 -1
  14. package/lib/cjs/runner.d.ts +3 -2
  15. package/lib/cjs/runner.js +31 -1
  16. package/lib/cjs/runner.js.map +1 -1
  17. package/lib/cjs/structured-output/carousel.d.ts +2 -17
  18. package/lib/cjs/structured-output/carousel.js.map +1 -1
  19. package/lib/cjs/structured-output/exit.d.ts +2 -4
  20. package/lib/cjs/structured-output/exit.js.map +1 -1
  21. package/lib/cjs/structured-output/index.d.ts +1 -5
  22. package/lib/cjs/structured-output/index.js.map +1 -1
  23. package/lib/cjs/structured-output/text-with-buttons.d.ts +2 -8
  24. package/lib/cjs/structured-output/text-with-buttons.js.map +1 -1
  25. package/lib/cjs/structured-output/text.d.ts +2 -7
  26. package/lib/cjs/structured-output/text.js.map +1 -1
  27. package/lib/cjs/types.d.ts +12 -4
  28. package/lib/esm/agent-builder.d.ts +6 -2
  29. package/lib/esm/agent-builder.js +28 -5
  30. package/lib/esm/agent-builder.js.map +1 -1
  31. package/lib/esm/guardrails/index.d.ts +1 -0
  32. package/lib/esm/guardrails/index.js +2 -0
  33. package/lib/esm/guardrails/index.js.map +1 -0
  34. package/lib/esm/guardrails/input.d.ts +3 -0
  35. package/lib/esm/guardrails/input.js +29 -0
  36. package/lib/esm/guardrails/input.js.map +1 -0
  37. package/lib/esm/index.d.ts +2 -2
  38. package/lib/esm/index.js +3 -1
  39. package/lib/esm/index.js.map +1 -1
  40. package/lib/esm/runner.d.ts +3 -2
  41. package/lib/esm/runner.js +32 -2
  42. package/lib/esm/runner.js.map +1 -1
  43. package/lib/esm/structured-output/carousel.d.ts +2 -17
  44. package/lib/esm/structured-output/carousel.js.map +1 -1
  45. package/lib/esm/structured-output/exit.d.ts +2 -4
  46. package/lib/esm/structured-output/exit.js.map +1 -1
  47. package/lib/esm/structured-output/index.d.ts +1 -5
  48. package/lib/esm/structured-output/index.js +1 -1
  49. package/lib/esm/structured-output/index.js.map +1 -1
  50. package/lib/esm/structured-output/text-with-buttons.d.ts +2 -8
  51. package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
  52. package/lib/esm/structured-output/text.d.ts +2 -7
  53. package/lib/esm/structured-output/text.js.map +1 -1
  54. package/lib/esm/types.d.ts +12 -4
  55. package/package.json +3 -3
  56. package/src/agent-builder.ts +43 -7
  57. package/src/guardrails/index.ts +1 -0
  58. package/src/guardrails/input.ts +39 -0
  59. package/src/index.ts +7 -3
  60. package/src/runner.ts +49 -4
  61. package/src/structured-output/carousel.ts +2 -15
  62. package/src/structured-output/exit.ts +2 -5
  63. package/src/structured-output/index.ts +5 -13
  64. package/src/structured-output/text-with-buttons.ts +2 -9
  65. package/src/structured-output/text.ts +2 -8
  66. package/src/types.ts +20 -5
  67. package/lib/cjs/structured-output/shared.d.ts +0 -3
  68. package/lib/cjs/structured-output/shared.js +0 -3
  69. package/lib/cjs/structured-output/shared.js.map +0 -1
  70. package/lib/esm/structured-output/shared.d.ts +0 -3
  71. package/lib/esm/structured-output/shared.js +0 -2
  72. package/lib/esm/structured-output/shared.js.map +0 -1
  73. package/src/structured-output/shared.ts +0 -3
package/README.md CHANGED
@@ -2,13 +2,155 @@
2
2
 
3
3
  ## env variables
4
4
 
5
- You need this env variables when deploy a bot that use this plugin
5
+ - It is necessary to add the following variables to an `.env` file:
6
+ - `AZURE_OPENAI_API_KEY`
7
+ - `AZURE_OPENAI_API_BASE`
8
+ - `AZURE_OPENAI_API_DEPLOYMENT_NAME`
9
+ - `AZURE_OPENAI_API_VERSION`
10
+ - Add these env variables to build using rspack, for target NODE and DEV.
6
11
 
7
- .env
12
+ ```ts
13
+ ...
14
+ import { config } from 'dotenv'
15
+ config()
16
+ ...
17
+ const plugins = [
18
+ new rspack.EnvironmentPlugin({
19
+ NODE_ENV: process.env.NODE_ENV,
20
+ HUBTYPE_API_URL: process.env.HUBTYPE_API_URL || HUBTYPE_DEFAULTS.API_URL,
21
+ BOTONIC_TARGET: BotonicTarget.NODE,
22
+ WEBCHAT_PUSHER_KEY:
23
+ process.env.WEBCHAT_PUSHER_KEY || HUBTYPE_DEFAULTS.WEBCHAT_PUSHER_KEY,
24
+ ENVIRONMENT: process.env.ENVIRONMENT,
25
+ AZURE_OPENAI_API_KEY: isNodeOrDev
26
+ ? process.env.AZURE_OPENAI_API_KEY
27
+ : undefined,
28
+ AZURE_OPENAI_API_DEPLOYMENT_NAME: isNodeOrDev
29
+ ? process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME
30
+ : undefined,
31
+ AZURE_OPENAI_API_VERSION: isNodeOrDev
32
+ ? process.env.AZURE_OPENAI_API_VERSION
33
+ : undefined,
34
+ AZURE_OPENAI_API_BASE: isNodeOrDev
35
+ ? process.env.AZURE_OPENAI_API_BASE
36
+ : undefined,
37
+ }),
38
+ new rspack.ProgressPlugin(),
39
+ ]
40
+ ```
41
+
42
+ ## Custom Tools
43
+
44
+ - It is possible to add tools from the bot code. To do this:
45
+ - Add the `zod` dependency.
46
+ - Create and export the definition of the tools in a file, for example: `src/server/tools.ts`.
8
47
 
48
+ ```ts
49
+ import { CustomTool } from '@botonic/plugin-ai-agents'
50
+ import axios from 'axios'
51
+ import z from 'zod'
52
+
53
+ export const customTools: CustomTool[] = [
54
+ {
55
+ name: 'get_current_weather',
56
+ description: 'Get current weather for a city',
57
+ schema: z.object({
58
+ cityName: z.string(),
59
+ }),
60
+ func: async (input: { cityName: string }) => {
61
+ const baseURL = 'http://api.weatherapi.com/v1'
62
+ const response = await axios.get(`${baseURL}/forecast.json`, {
63
+ params: {
64
+ key: 'WEATHER_API_TOKEN',
65
+ q: input.cityName,
66
+ },
67
+ })
68
+ const data = response.data
69
+ console.log('get_current_weather', { data })
70
+ return data
71
+ },
72
+ },
73
+ ...
74
+ ]
9
75
  ```
10
- AZURE_OPENAI_API_KEY='FAKE_API_KEY' // pragma: allowlist secret
11
- AZURE_OPENAI_API_BASE='FAKE_API_URL_BASE'
12
- AZURE_OPENAI_API_DEPLOYMENT_NAME='gpt-4o-mini_p1'
13
- AZURE_OPENAI_API_VERSION='2024-12-01-preview'
76
+
77
+ - Add these tools to:
78
+ - Update the `BotonicPluginFlowBuilderOptions`, as we did with the knowledge base, and add the `customTools`.
79
+
80
+ src/server/config.ts
81
+
82
+ ```ts
83
+ import { PluginAiAgentOptions } from '@botonic/plugin-ai-agents'
84
+ import { customTools } from './tools'
85
+
86
+ ...
87
+ function getFlowBuilderConfig(
88
+ env: ENVIRONMENT
89
+ ): BotonicPluginFlowBuilderOptions<BotPlugins, UserData> {
90
+ return {
91
+ ...
92
+ getAiAgentResponse: async (
93
+ request: BotRequest,
94
+ aiAgentArgs: {
95
+ name: string
96
+ instructions: string
97
+ }
98
+ ) => {
99
+ const aiAgentPlugin = request.plugins.aiAgents
100
+ return await aiAgentPlugin.getInference(request, aiAgentArgs)
101
+ },
102
+ ...
103
+ }
104
+
105
+ function getAiAgentsConfig(): PluginAiAgentOptions {
106
+ return {
107
+ authToken: 'AUTH_TOKEN', // Used locally
108
+ customTools: customTools,
109
+ }
110
+ }
111
+ ...
112
+
113
+ interface Config {
114
+ // Use any for infer type for TPlugins and TExtraData
115
+ // to avoid type errors with circular dependencies
116
+ flowBuilder: BotonicPluginFlowBuilderOptions<any, any>
117
+ aiAgents: PluginAiAgentOptions
118
+ knowledgeBases: PluginKnowledgeBaseOptions
119
+ }
120
+
121
+ export const CONFIG: Record<ENVIRONMENT, Config> = {
122
+ [ENVIRONMENT.LOCAL]: {
123
+ flowBuilder: getFlowBuilderConfig(ENVIRONMENT.LOCAL),
124
+ aiAgents: getAiAgentsConfig(),
125
+ knowledgeBases: getKnowledgeBasesConfig(),
126
+ },
127
+ ...
128
+ }
129
+ ```
130
+
131
+ ## Share customTools with flow builder frontend
132
+
133
+ - Create new `src/bot-config.ts` file and add customTools. This file is used so that every time a bot is deployed, the Flow Builder frontend can know which tools are in the deployed bot and enable or disable tools for each AI Agent node.
134
+
135
+ src/bot-config.ts
136
+
137
+ ```ts
138
+ import { BotConfigJSON } from '@botonic/core'
139
+
140
+ import { customTools } from './server/tools'
141
+
142
+ const aiAgentTools =
143
+ customTools?.map(customTool => ({
144
+ name: customTool.name,
145
+ description: customTool.description,
146
+ })) || []
147
+
148
+ /**
149
+ * This is the configuration is shared with flow-builder-frontend.
150
+ */
151
+ export const botConfig: BotConfigJSON = {
152
+ tools: aiAgentTools,
153
+ payloads: [],
154
+ webviews: [],
155
+ }
14
156
  ```
@@ -1,10 +1,14 @@
1
- import { AIAgent, Tool } from './types';
1
+ import { AIAgent, ContactInfo, GuardrailRule, Tool } from './types';
2
2
  export declare class AIAgentBuilder {
3
3
  private name;
4
4
  private instructions;
5
5
  private tools;
6
- constructor(name: string, instructions: string, tools: Tool[]);
6
+ private inputGuardrails;
7
+ constructor(name: string, instructions: string, tools: Tool[], contactInfo: ContactInfo, inputGuardrailRules: GuardrailRule[]);
7
8
  build(): AIAgent;
8
9
  private addExtraInstructions;
10
+ private getContactInfoInstructions;
11
+ private getMetadataInstructions;
12
+ private getOutputInstructions;
9
13
  private addHubtypeTools;
10
14
  }
@@ -2,13 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AIAgentBuilder = void 0;
4
4
  const agents_1 = require("@openai/agents");
5
+ const guardrails_1 = require("./guardrails");
5
6
  const structured_output_1 = require("./structured-output");
6
7
  const tools_1 = require("./tools");
7
8
  class AIAgentBuilder {
8
- constructor(name, instructions, tools) {
9
+ constructor(name, instructions, tools, contactInfo, inputGuardrailRules) {
9
10
  this.name = name;
10
- this.instructions = this.addExtraInstructions(instructions);
11
+ this.instructions = this.addExtraInstructions(instructions, contactInfo);
11
12
  this.tools = this.addHubtypeTools(tools);
13
+ this.inputGuardrails = [];
14
+ if (inputGuardrailRules.length > 0) {
15
+ const inputGuardrail = (0, guardrails_1.createInputGuardrail)(inputGuardrailRules);
16
+ this.inputGuardrails.push(inputGuardrail);
17
+ }
12
18
  }
13
19
  build() {
14
20
  return new agents_1.Agent({
@@ -16,10 +22,28 @@ class AIAgentBuilder {
16
22
  instructions: this.instructions,
17
23
  tools: this.tools,
18
24
  outputType: structured_output_1.OutputSchema,
25
+ inputGuardrails: this.inputGuardrails,
26
+ outputGuardrails: [],
19
27
  });
20
28
  }
21
- addExtraInstructions(instructions) {
29
+ addExtraInstructions(initialInstructions, contactInfo) {
30
+ const instructions = `<instructions>\n${initialInstructions}\n</instructions>`;
31
+ const metadataInstructions = this.getMetadataInstructions();
32
+ const contactInfoInstructions = this.getContactInfoInstructions(contactInfo);
33
+ const outputInstructions = this.getOutputInstructions();
34
+ return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${outputInstructions}`;
35
+ }
36
+ getContactInfoInstructions(contactInfo) {
37
+ const structuredContactInfo = Object.entries(contactInfo)
38
+ .map(([key, value]) => `${key}: ${value}`)
39
+ .join('\n');
40
+ return `<contact_info>\n${structuredContactInfo}\n</contact_info>`;
41
+ }
42
+ getMetadataInstructions() {
22
43
  const metadata = `Current Date: ${new Date().toISOString()}`;
44
+ return `<metadata>\n${metadata}\n</metadata>`;
45
+ }
46
+ getOutputInstructions() {
23
47
  const example = {
24
48
  messages: [
25
49
  {
@@ -29,10 +53,9 @@ class AIAgentBuilder {
29
53
  },
30
54
  },
31
55
  ],
32
- numMessages: 1,
33
56
  };
34
57
  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>`;
35
- return `<instructions>\n${instructions}\n</instructions>\n\n<metadata>\n${metadata}\n</metadata>\n\n<output>\n${output}\n</output>`;
58
+ return `<output>\n${output}\n</output>`;
36
59
  }
37
60
  addHubtypeTools(tools) {
38
61
  const hubtypeTools = [...tools_1.mandatoryTools];
@@ -1 +1 @@
1
- {"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;AAEtC,2DAAkD;AAClD,mCAAwC;AAGxC,MAAa,cAAc;IAKzB,YAAY,IAAY,EAAE,YAAoB,EAAE,KAAa;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAA;QAC3D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC;IAED,KAAK;QACH,OAAO,IAAI,cAAK,CAAC;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,gCAAY;SACzB,CAAC,CAAA;IACJ,CAAC;IAEO,oBAAoB,CAAC,YAAoB;QAC/C,MAAM,QAAQ,GAAG,iBAAiB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAA;QAC5D,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,kCAAkC;qBACzC;iBACF;aACF;YACD,WAAW,EAAE,CAAC;SACf,CAAA;QACD,MAAM,MAAM,GAAG,yIAAyI,IAAI,CAAC,SAAS,CAA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pC,CAAC;CACF;AA5ED,wCA4EC"}
@@ -0,0 +1 @@
1
+ export * from './input';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./input"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/guardrails/index.ts"],"names":[],"mappings":";;;AAAA,kDAAuB"}
@@ -0,0 +1,3 @@
1
+ import { InputGuardrail } from '@openai/agents';
2
+ import { GuardrailRule } from '../types';
3
+ export declare function createInputGuardrail(rules: GuardrailRule[]): InputGuardrail;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createInputGuardrail = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const agents_1 = require("@openai/agents");
6
+ const zod_1 = require("zod");
7
+ function createInputGuardrail(rules) {
8
+ const outputType = zod_1.z.object(Object.fromEntries(rules.map(rule => [rule.name, zod_1.z.boolean().describe(rule.description)])));
9
+ const agent = new agents_1.Agent({
10
+ name: 'InputGuardrail',
11
+ instructions: 'Check if the user triggers some of the following guardrails.',
12
+ outputType,
13
+ });
14
+ return {
15
+ name: 'InputGuardrail',
16
+ execute: ({ input, context }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
17
+ const lastMessage = input[input.length - 1];
18
+ const result = yield (0, agents_1.run)(agent, [lastMessage], { context });
19
+ const finalOutput = result.finalOutput;
20
+ if (finalOutput === undefined) {
21
+ throw new Error('Guardrail agent failed to produce output');
22
+ }
23
+ const triggered = Object.values(finalOutput).some(value => value === true);
24
+ const triggeredGuardrails = Object.keys(finalOutput).filter(key => finalOutput[key] === true);
25
+ return {
26
+ outputInfo: triggeredGuardrails,
27
+ tripwireTriggered: triggered,
28
+ };
29
+ }),
30
+ };
31
+ }
32
+ exports.createInputGuardrail = createInputGuardrail;
33
+ //# sourceM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AAG,CAAC,KAAK,IAAI,CACjC,CAAA;YACD,OAAO;gBACL,UAAU,EAAE,mBAAmB;gBAC/B,iBAAiB,EAAE,SAAS;aAC7B,CAAA;QACH,CAAC,CAAA;KACF,CAAA;AACH,CAAC;AAjCD,oDAiCC"}
@@ -1,11 +1,11 @@
1
1
  import { BotContext, Plugin } from '@botonic/core';
2
- import { AgenticOutputMessage, AiAgentArgs, CustomTool, PluginAiAgentOptions } from './types';
2
+ import { AiAgentArgs, CustomTool, InferenceResponse, PluginAiAgentOptions } from './types';
3
3
  export default class BotonicPluginAiAgents implements Plugin {
4
4
  private readonly authToken?;
5
5
  toolDefinitions: CustomTool[];
6
6
  constructor(options?: PluginAiAgentOptions);
7
7
  pre(): void;
8
- getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<AgenticOutputMessage[] | undefined>;
8
+ getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<InferenceResponse>;
9
9
  private getMessages;
10
10
  private buildTools;
11
11
  }
package/lib/cjs/index.js CHANGED
@@ -26,7 +26,7 @@ class BotonicPluginAiAgents {
26
26
  throw new Error('Auth token is required');
27
27
  }
28
28
  const tools = this.buildTools(((_a = aiAgentArgs.activeTools) === null || _a === void 0 ? void 0 : _a.map(tool => tool.name)) || []);
29
- const agent = new agent_builder_1.AIAgentBuilder(aiAgentArgs.name, aiAgentArgs.instructions, tools).build();
29
+ const agent = new agent_builder_1.AIAgentBuilder(aiAgentArgs.name, aiAgentArgs.instructions, tools, request.session.user.contact_info || {}, aiAgentArgs.inputGuardrailRules || []).build();
30
30
  const messages = yield this.getMessages(request, authToken, 25);
31
31
  const context = {
32
32
  authToken,
@@ -36,6 +36,8 @@ class BotonicPluginAiAgents {
36
36
  }
37
37
  catch (error) {
38
38
  console.error('error plugin returns undefined', error);
39
+ // Here we can return a InferenceResponse as a exit
40
+ // but indicate that the inference failed
39
41
  return undefined;
40
42
  }
41
43
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot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EAAE,OAAO,CAAC,CAAA;aAC3C;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAA;gBACtD,mDAAmD;gBACnD,yCAAyC;gBACzC,OAAO,SAAS,CAAA;aACjB;;KACF;IAEa,WAAW,CACvB,OAAmB,EACnB,SAAiB,EACjB,YAAoB;;YAEpB,IAAI,kBAAM,EAAE;gBACV,MAAM,aAAa,GAAG,IAAI,qCAAgB,CAAC,SAAS,CAAC,CAAA;gBACrD,OAAO,MAAM,aAAa,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;aAC9D;YACD,MAAM,aAAa,GAAG,IAAI,qCAAgB,CAAC,SAAS,CAAC,CAAA;YACrD,OAAO,MAAM,aAAa,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAA;QAC3D,CAAC;KAAA;IAEO,UAAU,CAAC,eAAyB;QAC1C,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CACxD,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAA;QACD,OAAO,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;YACzC,OAAO,IAAA,aAAI,EAAoB;gBAC7B,IAAI,EAAE,cAAc,CAAC,IAAI;gBACzB,WAAW,EAAE,cAAc,CAAC,WAAW;gBACvC,UAAU,EAAE,cAAc,CAAC,MAAM;gBACjC,OAAO,EAAE,cAAc,CAAC,IAAI;aAC7B,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AA5ED,wCA4EC;AAED,kDAAuB"}
@@ -1,7 +1,8 @@
1
- import { AgenticInputMessage, AgenticOutputMessage, AIAgent, Context } from './types';
1
+ import { AgenticInputMessage, AIAgent, Context, RunResult } from './types';
2
2
  export declare class AIAgentRunner {
3
3
  private agent;
4
4
  constructor(agent: AIAgent);
5
- run(messages: AgenticInputMessage[], context: Context, maxRetries?: number): Promise<AgenticOutputMessage[]>;
5
+ run(messages: AgenticInputMessage[], context: Context, maxRetries?: number): Promise<RunResult>;
6
6
  private runWithRetry;
7
+ private getExecutedNameTools;
7
8
  }
package/lib/cjs/runner.js CHANGED
@@ -20,9 +20,30 @@ class AIAgentRunner {
20
20
  modelSettings: { temperature: 0 },
21
21
  });
22
22
  const result = yield runner.run(this.agent, messages, { context });
23
- return ((_a = result.finalOutput) === null || _a === void 0 ? void 0 : _a.messages) || [];
23
+ const outputMessages = ((_a = result.finalOutput) === null || _a === void 0 ? void 0 : _a.messages) || [];
24
+ const hasExit = outputMessages.length === 0 ||
25
+ outputMessages.some(message => message.type === 'exit');
26
+ const toolsExecuted = this.getExecutedNameTools(result);
27
+ return {
28
+ messages: hasExit
29
+ ? []
30
+ : outputMessages.filter(message => message.type !== 'exit'),
31
+ toolsExecuted,
32
+ exit: hasExit,
33
+ inputGuardrailTriggered: [],
34
+ outputGuardrailTriggered: [],
35
+ };
24
36
  }
25
37
  catch (error) {
38
+ if (error instanceof agents_1.InputGuardrailTripwireTriggered) {
39
+ return {
40
+ messages: [],
41
+ toolsExecuted: [],
42
+ exit: true,
43
+ inputGuardrailTriggered: error.result.output.outputInfo,
44
+ outputGuardrailTriggered: [],
45
+ };
46
+ }
26
47
  if (attempt > maxRetries) {
27
48
  throw error;
28
49
  }
@@ -30,6 +51,15 @@ class AIAgentRunner {
30
51
  }
31
52
  });
32
53
  }
54
+ getExecutedNameTools(result) {
55
+ var _a;
56
+ return (((_a = result.newItems) === null || _a === void 0 ? void 0 : _a.filter(item => item instanceof agents_1.RunToolCallItem).map((item) => {
57
+ if (item.rawItem.type === 'function_call') {
58
+ return item.rawItem.name;
59
+ }
60
+ return '';
61
+ }).filter((toolName) => toolName !== '')) || []);
62
+ }
33
63
  }
34
64
  exports.AIAgentRunner = AIAgentRunner;
35
65
  //# sourceMappingURL=runner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;;AAAA,2CAAuC;AASvC,MAAa,aAAa;IAGxB,YAAY,KAAc;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAEK,GAAG,CACP,QAA+B,EAC/B,OAAgB,EAChB,aAAqB,CAAC;;YAEtB,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;QAC5D,CAAC;KAAA;IAEa,YAAY,CACxB,QAA+B,EAC/B,OAAgB,EAChB,UAAkB,EAClB,OAAe;;;YAEf,IAAI;gBACF,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;oBACxB,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE;iBAClC,CAAC,CAAA;gBACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;gBAClE,OAAO,CAAA,MAAA,MAAM,CAAC,WAAW,0CAAE,QAAQ,KAAI,EAAE,CAAA;aAC1C;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,OAAO,GAAG,UAAU,EAAE;oBACxB,MAAM,KAAK,CAAA;iBACZ;gBACD,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,GAAG,CAAC,CAAC,CAAA;aACrE;;KACF;CACF;AAlCD,sCAkCC"}
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;;AAAA,2CAIuB;AAUvB,MAAa,aAAa;IAGxB,YAAY,KAAc;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAEK,GAAG,CACP,QAA+B,EAC/B,OAAgB,EAChB,aAAqB,CAAC;;YAEtB,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,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AI,OAAO,GAAG,UAAU,EAAE;oBACxB,MAAM,KAAK,CAAA;iBACZ;gBACD,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,GAAG,CAAC,CAAC,CAAA;aACrE;;KACF;IAEO,oBAAoB,CAAC,MAAM;;QACjC,OAAO,CACL,CAAA,MAAA,MAAM,CAAC,QAAQ,0CACX,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,YAAY,wBAAe,EAC/C,GAAG,CAAC,CAAC,IAAqB,EAAE,EAAE;YAC7B,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,eAAe,EAAE;gBACzC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;aACzB;YACD,OAAO,EAAE,CAAA;QACX,CAAC,EACA,MAAM,CAAC,CAAC,QAAgB,EAAE,EAAE,CAAC,QAAQ,KAAK,EAAE,CAAC,KAAI,EAAE,CACvD,CAAA;IACH,CAAC;CACF;AA1ED,sCA0EC"}
@@ -1,20 +1,6 @@
1
+ import { CarouselMessage } from '@botonic/core';
1
2
  import { z } from 'zod';
2
- import { BaseMessage } from './shared';
3
- interface CarouselElement {
4
- title: string;
5
- subtitle: string;
6
- image: string;
7
- button: {
8
- text: string;
9
- url: string;
10
- };
11
- }
12
- export interface CarouselMessage extends BaseMessage {
13
- type: 'carousel';
14
- content: {
15
- elements: CarouselElement[];
16
- };
17
- }
3
+ export type { CarouselMessage };
18
4
  export declare const CarouselSchema: z.ZodObject<{
19
5
  type: z.ZodEnum<["carousel"]>;
20
6
  content: z.ZodObject<{
@@ -97,4 +83,3 @@ export declare const CarouselSchema: z.ZodObject<{
97
83
  }[];
98
84
  };
99
85
  }>;
100
- export {};
@@ -1 +1 @@
1
- {"version":3,"file":"carousel.js","sourceRoot":"","sources":["../../../src/structured-output/carousel.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAkBV,QAAA,cAAc,GAAG,OAAC;KAC5B,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC;IAC1B,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,QAAQ,EAAE,OAAC,CAAC,KAAK,CACf,OAAC,CAAC,MAAM,CAAC;YACP,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;YACpB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;gBACf,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;gBAChB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;aAChB,CAAC;SACH,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,kDAAkD,CAAC,CAAA"}
1
+ {"version":3,"file":"carousel.js","sourceRoot":"","sources":["../../../src/structured-output/carousel.ts"],"names":[],"mappings":";;;AACA,6BAAuB;AAIV,QAAA,cAAc,GAAG,OAAC;KAC5B,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC;IAC1B,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,QAAQ,EAAE,OAAC,CAAC,KAAK,CACf,OAAC,CAAC,MAAM,CAAC;YACP,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;YACpB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;gBACf,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;gBAChB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;aAChB,CAAC;SACH,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,kDAAkD,CAAC,CAAA"}
@@ -1,8 +1,6 @@
1
+ import { ExitMessage } from '@botonic/core';
1
2
  import z from 'zod';
2
- import { BaseMessage } from './shared';
3
- export interface ExitMessage extends BaseMessage {
4
- type: 'exit';
5
- }
3
+ export type { ExitMessage };
6
4
  export declare const ExitSchema: z.ZodObject<{
7
5
  type: z.ZodEnum<["exit"]>;
8
6
  }, "strip", z.ZodTypeAny, {
@@ -1 +1 @@
1
- {"version":3,"file":"exit.js","sourceRoot":"","sources":["../../../src/structured-output/exit.ts"],"names":[],"mappings":";;;;AAAA,sDAAmB;AAQN,QAAA,UAAU,GAAG,aAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,aAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC;KACD,QAAQ,CACP,uIAAuI,CACxI,CAAA"}
1
+ {"version":3,"file":"exit.js","sourceRoot":"","sources":["../../../src/structured-output/exit.ts"],"names":[],"mappings":";;;;AACA,sDAAmB;AAIN,QAAA,UAAU,GAAG,aAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,aAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC;KACD,QAAQ,CACP,uIAAuI,CACxI,CAAA"}
@@ -1,9 +1,5 @@
1
+ import { OutputMessage } from '@botonic/core';
1
2
  import { z } from 'zod';
2
- import { CarouselMessage } from './carousel';
3
- import { ExitMessage } from './exit';
4
- import { TextMessage } from './text';
5
- import { TextWithButtonsMessage } from './text-with-buttons';
6
- export type OutputMessage = TextMessage | TextWithButtonsMessage | CarouselMessage | ExitMessage;
7
3
  export interface Output {
8
4
  messages: OutputMessage[];
9
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structured-output/index.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEvB,yCAA4D;AAC5D,iCAAgD;AAChD,iCAAgD;AAChD,2DAG4B;AAYf,QAAA,YAAY,GAAG,OAAC;KAC1B,MAAM,CAAC;IACN,QAAQ,EAAE,OAAC,CAAC,KAAK,CACf,OAAC,CAAC,KAAK,CAAC,CAAC,iBAAU,EAAE,yCAAqB,EAAE,yBAAc,EAAE,iBAAU,CAAC,CAAC,CACzE;CACF,CAAC;KACD,QAAQ,CAAC,qCAAqC,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structured-output/index.ts"],"names":[],"mappings":";;;AACA,6BAAuB;AAEvB,yCAA2C;AAC3C,iCAAmC;AACnC,iCAAmC;AACnC,2DAA2D;AAM9C,QAAA,YAAY,GAAG,OAAC;KAC1B,MAAM,CAAC;IACN,QAAQ,EAAE,OAAC,CAAC,KAAK,CACf,OAAC,CAAC,KAAK,CAAC,CAAC,iBAAU,EAAE,yCAAqB,EAAE,yBAAc,EAAE,iBAAU,CAAC,CAAC,CACzE;CACF,CAAC;KACD,QAAQ,CAAC,qCAAqC,CAAC,CAAA"}
@@ -1,12 +1,6 @@
1
+ import { TextWithButtonsMessage } from '@botonic/core';
1
2
  import z from 'zod';
2
- import { BaseMessage } from './shared';
3
- export interface TextWithButtonsMessage extends BaseMessage {
4
- type: 'textWithButtons';
5
- content: {
6
- text: string;
7
- buttons: string[];
8
- };
9
- }
3
+ export type { TextWithButtonsMessage };
10
4
  export declare const TextWithButtonsSchema: z.ZodObject<{
11
5
  type: z.ZodEnum<["textWithButtons"]>;
12
6
  content: z.ZodObject<{
@@ -1 +1 @@
1
- {"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":";;;;AAAA,sDAAmB;AAYN,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,CAAC,aAAC,CAAC,MAAM,EAAE,CAAC;KAC7B,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":";;;;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,CAAC,aAAC,CAAC,MAAM,EAAE,CAAC;KAC7B,CAAC;CACH,CAAC;KACD,QAAQ,CACP,oEAAoE,CACrE,CAAA"}
@@ -1,11 +1,6 @@
1
+ import { TextMessage } from '@botonic/core';
1
2
  import { z } from 'zod';
2
- import { BaseMessage } from './shared';
3
- export interface TextMessage extends BaseMessage {
4
- type: 'text';
5
- content: {
6
- text: string;
7
- };
8
- }
3
+ export type { TextMessage };
9
4
  export declare const TextSchema: z.ZodObject<{
10
5
  type: z.ZodEnum<["text"]>;
11
6
  content: z.ZodObject<{
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/structured-output/text.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAWV,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":";;;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,15 +1,22 @@
1
- import { Agent, AgentInputItem, RunContext, Tool as OpenAITool } from '@openai/agents';
1
+ import { AgenticOutputMessage, InferenceResponse, RunResult } from '@botonic/core';
2
+ import { Agent, AgentInputItem, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
2
3
  import { ZodSchema } from 'zod';
3
- import { OutputMessage, OutputSchema } from './structured-output';
4
+ import { OutputSchema } from './structured-output';
4
5
  export interface Context {
5
6
  authToken: string;
6
7
  }
8
+ export type RunContext = OpenAIRunContext<Context>;
7
9
  export interface CustomTool {
8
10
  name: string;
9
11
  description: string;
10
12
  schema: ZodSchema;
11
- func: (input?: any, runContext?: RunContext<Context>) => Promise<any>;
13
+ func: (input?: any, runContext?: RunContext) => Promise<any>;
12
14
  }
15
+ export interface GuardrailRule {
16
+ name: string;
17
+ description: string;
18
+ }
19
+ export type ContactInfo = Record<string, string>;
13
20
  export type Tool = OpenAITool<Context>;
14
21
  export type AIAgent = Agent<Context, typeof OutputSchema>;
15
22
  export interface PluginAiAgentOptions {
@@ -22,6 +29,7 @@ export interface AiAgentArgs {
22
29
  activeTools?: {
23
30
  name: string;
24
31
  }[];
32
+ inputGuardrailRules?: GuardrailRule[];
25
33
  }
26
34
  export type AgenticInputMessage = AgentInputItem;
27
- export type AgenticOutputMessage = OutputMessage;
35
+ export type { AgenticOutputMessage, InferenceResponse, RunResult };
@@ -1,10 +1,14 @@
1
- import { AIAgent, Tool } from './types';
1
+ import { AIAgent, ContactInfo, GuardrailRule, Tool } from './types';
2
2
  export declare class AIAgentBuilder {
3
3
  private name;
4
4
  private instructions;
5
5
  private tools;
6
- constructor(name: string, instructions: string, tools: Tool[]);
6
+ private inputGuardrails;
7
+ constructor(name: string, instructions: string, tools: Tool[], contactInfo: ContactInfo, inputGuardrailRules: GuardrailRule[]);
7
8
  build(): AIAgent;
8
9
  private addExtraInstructions;
10
+ private getContactInfoInstructions;
11
+ private getMetadataInstructions;
12
+ private getOutputInstructions;
9
13
  private addHubtypeTools;
10
14
  }