@botonic/plugin-ai-agents 0.36.0-alpha.1 → 0.36.0-alpha.10

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 (129) hide show
  1. package/README.md +14 -0
  2. package/lib/cjs/agent-builder.d.ts +10 -0
  3. package/lib/cjs/agent-builder.js +43 -0
  4. package/lib/cjs/agent-builder.js.map +1 -0
  5. package/lib/cjs/constants.d.ts +3 -2
  6. package/lib/cjs/constants.js +5 -4
  7. package/lib/cjs/constants.js.map +1 -1
  8. package/lib/{esm/hubtype-client.d.ts → cjs/hubtype-api-client.d.ts} +3 -1
  9. package/lib/cjs/hubtype-api-client.js +76 -0
  10. package/lib/cjs/hubtype-api-client.js.map +1 -0
  11. package/lib/cjs/index.d.ts +5 -2
  12. package/lib/cjs/index.js +40 -17
  13. package/lib/cjs/index.js.map +1 -1
  14. package/lib/cjs/openai.d.ts +1 -0
  15. package/lib/cjs/openai.js +23 -0
  16. package/lib/cjs/openai.js.map +1 -0
  17. package/lib/cjs/runner.d.ts +7 -0
  18. package/lib/cjs/runner.js +35 -0
  19. package/lib/cjs/runner.js.map +1 -0
  20. package/lib/cjs/structured-output/carousel.d.ts +100 -0
  21. package/lib/cjs/structured-output/carousel.js +21 -0
  22. package/lib/cjs/structured-output/carousel.js.map +1 -0
  23. package/lib/cjs/structured-output/exit.d.ts +12 -0
  24. package/lib/cjs/structured-output/exit.js +11 -0
  25. package/lib/cjs/structured-output/exit.js.map +1 -0
  26. package/lib/cjs/structured-output/index.d.ts +198 -0
  27. package/lib/cjs/structured-output/index.js +14 -0
  28. package/lib/cjs/structured-output/index.js.map +1 -0
  29. package/lib/cjs/structured-output/shared.d.ts +3 -0
  30. package/lib/cjs/structured-output/shared.js +3 -0
  31. package/lib/cjs/structured-output/shared.js.map +1 -0
  32. package/lib/cjs/structured-output/text-with-buttons.d.ts +34 -0
  33. package/lib/cjs/structured-output/text-with-buttons.js +15 -0
  34. package/lib/cjs/structured-output/text-with-buttons.js.map +1 -0
  35. package/lib/cjs/structured-output/text.d.ts +28 -0
  36. package/lib/cjs/structured-output/text.js +13 -0
  37. package/lib/cjs/structured-output/text.js.map +1 -0
  38. package/lib/cjs/tools/index.d.ts +2 -0
  39. package/lib/cjs/tools/index.js +5 -0
  40. package/lib/cjs/tools/index.js.map +1 -0
  41. package/lib/cjs/types.d.ts +20 -22
  42. package/lib/esm/agent-builder.d.ts +10 -0
  43. package/lib/esm/agent-builder.js +39 -0
  44. package/lib/esm/agent-builder.js.map +1 -0
  45. package/lib/esm/constants.d.ts +3 -2
  46. package/lib/esm/constants.js +4 -3
  47. package/lib/esm/constants.js.map +1 -1
  48. package/lib/{cjs/hubtype-client.d.ts → esm/hubtype-api-client.d.ts} +3 -1
  49. package/lib/esm/hubtype-api-client.js +72 -0
  50. package/lib/esm/hubtype-api-client.js.map +1 -0
  51. package/lib/esm/index.d.ts +5 -2
  52. package/lib/esm/index.js +39 -16
  53. package/lib/esm/index.js.map +1 -1
  54. package/lib/esm/openai.d.ts +1 -0
  55. package/lib/esm/openai.js +19 -0
  56. package/lib/esm/openai.js.map +1 -0
  57. package/lib/esm/runner.d.ts +7 -0
  58. package/lib/esm/runner.js +31 -0
  59. package/lib/esm/runner.js.map +1 -0
  60. package/lib/esm/structured-output/carousel.d.ts +100 -0
  61. package/lib/esm/structured-output/carousel.js +18 -0
  62. package/lib/esm/structured-output/carousel.js.map +1 -0
  63. package/lib/esm/structured-output/exit.d.ts +12 -0
  64. package/lib/esm/structured-output/exit.js +7 -0
  65. package/lib/esm/structured-output/exit.js.map +1 -0
  66. package/lib/esm/structured-output/index.d.ts +198 -0
  67. package/lib/esm/structured-output/index.js +11 -0
  68. package/lib/esm/structured-output/index.js.map +1 -0
  69. package/lib/esm/structured-output/shared.d.ts +3 -0
  70. package/lib/esm/structured-output/shared.js +2 -0
  71. package/lib/esm/structured-output/shared.js.map +1 -0
  72. package/lib/esm/structured-output/text-with-buttons.d.ts +34 -0
  73. package/lib/esm/structured-output/text-with-buttons.js +11 -0
  74. package/lib/esm/structured-output/text-with-buttons.js.map +1 -0
  75. package/lib/esm/structured-output/text.d.ts +28 -0
  76. package/lib/esm/structured-output/text.js +10 -0
  77. package/lib/esm/structured-output/text.js.map +1 -0
  78. package/lib/esm/tools/index.d.ts +2 -0
  79. package/lib/esm/tools/index.js +2 -0
  80. package/lib/esm/tools/index.js.map +1 -0
  81. package/lib/esm/types.d.ts +20 -22
  82. package/package.json +7 -7
  83. package/src/agent-builder.ts +48 -0
  84. package/src/constants.ts +7 -4
  85. package/src/hubtype-api-client.ts +89 -0
  86. package/src/index.ts +56 -19
  87. package/src/openai.ts +30 -0
  88. package/src/runner.ts +43 -0
  89. package/src/structured-output/carousel.ts +36 -0
  90. package/src/structured-output/exit.ts +15 -0
  91. package/src/structured-output/index.ts +27 -0
  92. package/src/structured-output/shared.ts +3 -0
  93. package/src/structured-output/text-with-buttons.ts +23 -0
  94. package/src/structured-output/text.ts +19 -0
  95. package/src/tools/index.ts +3 -0
  96. package/src/types.ts +27 -29
  97. package/lib/cjs/ai-agent-client.d.ts +0 -11
  98. package/lib/cjs/ai-agent-client.js +0 -50
  99. package/lib/cjs/ai-agent-client.js.map +0 -1
  100. package/lib/cjs/errors.d.ts +0 -3
  101. package/lib/cjs/errors.js +0 -11
  102. package/lib/cjs/errors.js.map +0 -1
  103. package/lib/cjs/hubtype-client.js +0 -36
  104. package/lib/cjs/hubtype-client.js.map +0 -1
  105. package/lib/cjs/tools.d.ts +0 -6
  106. package/lib/cjs/tools.js +0 -41
  107. package/lib/cjs/tools.js.map +0 -1
  108. package/lib/cjs/utils.d.ts +0 -2
  109. package/lib/cjs/utils.js +0 -22
  110. package/lib/cjs/utils.js.map +0 -1
  111. package/lib/esm/ai-agent-client.d.ts +0 -11
  112. package/lib/esm/ai-agent-client.js +0 -46
  113. package/lib/esm/ai-agent-client.js.map +0 -1
  114. package/lib/esm/errors.d.ts +0 -3
  115. package/lib/esm/errors.js +0 -7
  116. package/lib/esm/errors.js.map +0 -1
  117. package/lib/esm/hubtype-client.js +0 -32
  118. package/lib/esm/hubtype-client.js.map +0 -1
  119. package/lib/esm/tools.d.ts +0 -6
  120. package/lib/esm/tools.js +0 -38
  121. package/lib/esm/tools.js.map +0 -1
  122. package/lib/esm/utils.d.ts +0 -2
  123. package/lib/esm/utils.js +0 -18
  124. package/lib/esm/utils.js.map +0 -1
  125. package/src/ai-agent-client.ts +0 -73
  126. package/src/errors.ts +0 -6
  127. package/src/hubtype-client.ts +0 -43
  128. package/src/tools.ts +0 -51
  129. package/src/utils.ts +0 -24
@@ -0,0 +1,198 @@
1
+ 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
+ export interface Output {
8
+ messages: OutputMessage[];
9
+ }
10
+ export declare const OutputSchema: z.ZodObject<{
11
+ messages: z.ZodArray<z.ZodUnion<[z.ZodObject<{
12
+ type: z.ZodEnum<["text"]>;
13
+ content: z.ZodObject<{
14
+ text: z.ZodString;
15
+ }, "strip", z.ZodTypeAny, {
16
+ text: string;
17
+ }, {
18
+ text: string;
19
+ }>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ type: "text";
22
+ content: {
23
+ text: string;
24
+ };
25
+ }, {
26
+ type: "text";
27
+ content: {
28
+ text: string;
29
+ };
30
+ }>, z.ZodObject<{
31
+ type: z.ZodEnum<["textWithButtons"]>;
32
+ content: z.ZodObject<{
33
+ text: z.ZodString;
34
+ buttons: z.ZodArray<z.ZodString, "many">;
35
+ }, "strip", z.ZodTypeAny, {
36
+ text: string;
37
+ buttons: string[];
38
+ }, {
39
+ text: string;
40
+ buttons: string[];
41
+ }>;
42
+ }, "strip", z.ZodTypeAny, {
43
+ type: "textWithButtons";
44
+ content: {
45
+ text: string;
46
+ buttons: string[];
47
+ };
48
+ }, {
49
+ type: "textWithButtons";
50
+ content: {
51
+ text: string;
52
+ buttons: string[];
53
+ };
54
+ }>, z.ZodObject<{
55
+ type: z.ZodEnum<["carousel"]>;
56
+ content: z.ZodObject<{
57
+ elements: z.ZodArray<z.ZodObject<{
58
+ title: z.ZodString;
59
+ subtitle: z.ZodString;
60
+ image: z.ZodString;
61
+ button: z.ZodObject<{
62
+ text: z.ZodString;
63
+ url: z.ZodString;
64
+ }, "strip", z.ZodTypeAny, {
65
+ text: string;
66
+ url: string;
67
+ }, {
68
+ text: string;
69
+ url: string;
70
+ }>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ title: string;
73
+ subtitle: string;
74
+ image: string;
75
+ button: {
76
+ text: string;
77
+ url: string;
78
+ };
79
+ }, {
80
+ title: string;
81
+ subtitle: string;
82
+ image: string;
83
+ button: {
84
+ text: string;
85
+ url: string;
86
+ };
87
+ }>, "many">;
88
+ }, "strip", z.ZodTypeAny, {
89
+ elements: {
90
+ title: string;
91
+ subtitle: string;
92
+ image: string;
93
+ button: {
94
+ text: string;
95
+ url: string;
96
+ };
97
+ }[];
98
+ }, {
99
+ elements: {
100
+ title: string;
101
+ subtitle: string;
102
+ image: string;
103
+ button: {
104
+ text: string;
105
+ url: string;
106
+ };
107
+ }[];
108
+ }>;
109
+ }, "strip", z.ZodTypeAny, {
110
+ type: "carousel";
111
+ content: {
112
+ elements: {
113
+ title: string;
114
+ subtitle: string;
115
+ image: string;
116
+ button: {
117
+ text: string;
118
+ url: string;
119
+ };
120
+ }[];
121
+ };
122
+ }, {
123
+ type: "carousel";
124
+ content: {
125
+ elements: {
126
+ title: string;
127
+ subtitle: string;
128
+ image: string;
129
+ button: {
130
+ text: string;
131
+ url: string;
132
+ };
133
+ }[];
134
+ };
135
+ }>, z.ZodObject<{
136
+ type: z.ZodEnum<["exit"]>;
137
+ }, "strip", z.ZodTypeAny, {
138
+ type: "exit";
139
+ }, {
140
+ type: "exit";
141
+ }>]>, "many">;
142
+ }, "strip", z.ZodTypeAny, {
143
+ messages: ({
144
+ type: "carousel";
145
+ content: {
146
+ elements: {
147
+ title: string;
148
+ subtitle: string;
149
+ image: string;
150
+ button: {
151
+ text: string;
152
+ url: string;
153
+ };
154
+ }[];
155
+ };
156
+ } | {
157
+ type: "exit";
158
+ } | {
159
+ type: "text";
160
+ content: {
161
+ text: string;
162
+ };
163
+ } | {
164
+ type: "textWithButtons";
165
+ content: {
166
+ text: string;
167
+ buttons: string[];
168
+ };
169
+ })[];
170
+ }, {
171
+ messages: ({
172
+ type: "carousel";
173
+ content: {
174
+ elements: {
175
+ title: string;
176
+ subtitle: string;
177
+ image: string;
178
+ button: {
179
+ text: string;
180
+ url: string;
181
+ };
182
+ }[];
183
+ };
184
+ } | {
185
+ type: "exit";
186
+ } | {
187
+ type: "text";
188
+ content: {
189
+ text: string;
190
+ };
191
+ } | {
192
+ type: "textWithButtons";
193
+ content: {
194
+ text: string;
195
+ buttons: string[];
196
+ };
197
+ })[];
198
+ }>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OutputSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const carousel_1 = require("./carousel");
6
+ const exit_1 = require("./exit");
7
+ const text_1 = require("./text");
8
+ const text_with_buttons_1 = require("./text-with-buttons");
9
+ exports.OutputSchema = zod_1.z
10
+ .object({
11
+ messages: zod_1.z.array(zod_1.z.union([text_1.TextSchema, text_with_buttons_1.TextWithButtonsSchema, carousel_1.CarouselSchema, exit_1.ExitSchema])),
12
+ })
13
+ .describe('The messages to be sent to the user');
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ export interface BaseMessage {
2
+ type: 'text' | 'textWithButtons' | 'carousel' | 'exit';
3
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/structured-output/shared.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ 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
+ }
10
+ export declare const TextWithButtonsSchema: z.ZodObject<{
11
+ type: z.ZodEnum<["textWithButtons"]>;
12
+ content: z.ZodObject<{
13
+ text: z.ZodString;
14
+ buttons: z.ZodArray<z.ZodString, "many">;
15
+ }, "strip", z.ZodTypeAny, {
16
+ text: string;
17
+ buttons: string[];
18
+ }, {
19
+ text: string;
20
+ buttons: string[];
21
+ }>;
22
+ }, "strip", z.ZodTypeAny, {
23
+ type: "textWithButtons";
24
+ content: {
25
+ text: string;
26
+ buttons: string[];
27
+ };
28
+ }, {
29
+ type: "textWithButtons";
30
+ content: {
31
+ text: string;
32
+ buttons: string[];
33
+ };
34
+ }>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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
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.string()),
12
+ }),
13
+ })
14
+ .describe('A text message with buttons to allow the user to use quick replies');
15
+ //# sourceMappingURL=text-with-buttons.js.map
@@ -0,0 +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"}
@@ -0,0 +1,28 @@
1
+ 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
+ }
9
+ export declare const TextSchema: z.ZodObject<{
10
+ type: z.ZodEnum<["text"]>;
11
+ content: z.ZodObject<{
12
+ text: z.ZodString;
13
+ }, "strip", z.ZodTypeAny, {
14
+ text: string;
15
+ }, {
16
+ text: string;
17
+ }>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ type: "text";
20
+ content: {
21
+ text: string;
22
+ };
23
+ }, {
24
+ type: "text";
25
+ content: {
26
+ text: string;
27
+ };
28
+ }>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.TextSchema = zod_1.z
6
+ .object({
7
+ type: zod_1.z.enum(['text']),
8
+ content: zod_1.z.object({
9
+ text: zod_1.z.string(),
10
+ }),
11
+ })
12
+ .describe('A text message');
13
+ //# sourceMappingURL=text.js.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ import { Tool } from '../types';
2
+ export declare const mandatoryTools: Tool[];
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mandatoryTools = void 0;
4
+ exports.mandatoryTools = [];
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":";;;AAEa,QAAA,cAAc,GAAW,EAAE,CAAA"}
@@ -1,29 +1,27 @@
1
+ import { Agent, AgentInputItem, RunContext, Tool as OpenAITool } from '@openai/agents';
2
+ import { ZodSchema } from 'zod';
3
+ import { OutputMessage, OutputSchema } from './structured-output';
4
+ export interface Context {
5
+ authToken: string;
6
+ }
7
+ export interface CustomTool {
8
+ name: string;
9
+ description: string;
10
+ schema: ZodSchema;
11
+ func: (input?: any, runContext?: RunContext<Context>) => Promise<any>;
12
+ }
13
+ export type Tool = OpenAITool<Context>;
14
+ export type AIAgent = Agent<Context, typeof OutputSchema>;
1
15
  export interface PluginAiAgentOptions {
2
16
  authToken?: string;
17
+ customTools?: CustomTool[];
3
18
  }
4
19
  export interface AiAgentArgs {
5
20
  name: string;
6
21
  instructions: string;
22
+ activeTools?: {
23
+ name: string;
24
+ }[];
7
25
  }
8
- export interface AgenticBaseMessage {
9
- role: 'assistant' | 'user' | 'tool' | 'exit';
10
- }
11
- export interface AssistantMessage extends AgenticBaseMessage {
12
- role: 'assistant';
13
- content: string;
14
- }
15
- export interface UserMessage extends AgenticBaseMessage {
16
- role: 'user';
17
- content: string;
18
- }
19
- export interface ToolMessage extends AgenticBaseMessage {
20
- role: 'tool';
21
- toolName: string;
22
- toolOutput: string | null;
23
- }
24
- export interface ExitMessage extends AgenticBaseMessage {
25
- role: 'exit';
26
- }
27
- export type AgenticInputMessage = AssistantMessage | UserMessage;
28
- export type AgenticOutputMessage = AssistantMessage | ToolMessage | ExitMessage;
29
- export type AgenticMessage = AssistantMessage | UserMessage | ToolMessage | ExitMessage;
26
+ export type AgenticInputMessage = AgentInputItem;
27
+ export type AgenticOutputMessage = OutputMessage;
@@ -0,0 +1,10 @@
1
+ import { AIAgent, Tool } from './types';
2
+ export declare class AIAgentBuilder {
3
+ private name;
4
+ private instructions;
5
+ private tools;
6
+ constructor(name: string, instructions: string, tools: Tool[]);
7
+ build(): AIAgent;
8
+ private addExtraInstructions;
9
+ private addHubtypeTools;
10
+ }
@@ -0,0 +1,39 @@
1
+ import { Agent } from '@openai/agents';
2
+ import { OutputSchema } from './structured-output';
3
+ import { mandatoryTools } from './tools';
4
+ export class AIAgentBuilder {
5
+ constructor(name, instructions, tools) {
6
+ this.name = name;
7
+ this.instructions = this.addExtraInstructions(instructions);
8
+ this.tools = this.addHubtypeTools(tools);
9
+ }
10
+ build() {
11
+ return new Agent({
12
+ name: this.name,
13
+ instructions: this.instructions,
14
+ tools: this.tools,
15
+ outputType: OutputSchema,
16
+ });
17
+ }
18
+ addExtraInstructions(instructions) {
19
+ const metadata = `Current Date: ${new Date().toISOString()}`;
20
+ const example = {
21
+ messages: [
22
+ {
23
+ type: 'text',
24
+ content: {
25
+ text: 'Hello, how can I help you today?',
26
+ },
27
+ },
28
+ ],
29
+ numMessages: 1,
30
+ };
31
+ 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>`;
32
+ return `<instructions>\n${instructions}\n</instructions>\n\n<metadata>\n${metadata}\n</metadata>\n\n<output>\n${output}\n</output>`;
33
+ }
34
+ addHubtypeTools(tools) {
35
+ const hubtypeTools = [...mandatoryTools];
36
+ return [...hubtypeTools, ...tools];
37
+ }
38
+ }
39
+ //# sourceMappingURL=agent-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAGxC,MAAM,OAAO,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,KAAK,CAAC;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,YAAY;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,CAAC,OAAO,CAAC,cAAc,CAAA;QAC7L,OAAO,mBAAmB,YAAY,oCAAoC,QAAQ,8BAA8B,MAAM,aAAa,CAAA;IACrI,CAAC;IAEO,eAAe,CAAC,KAAa;QACnC,MAAM,YAAY,GAAW,CAAC,GAAG,cAAc,CAAC,CAAA;QAChD,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF"}
@@ -1,5 +1,6 @@
1
1
  export declare const HUBTYPE_API_URL: string;
2
2
  export declare const AZURE_OPENAI_API_KEY: string | undefined;
3
- export declare const AZURE_OPENAI_API_DEPLOYMENT_NAME: string | undefined;
4
- export declare const AZURE_OPENAI_API_VERSION: string | undefined;
5
3
  export declare const AZURE_OPENAI_API_BASE: string | undefined;
4
+ export declare const AZURE_OPENAI_API_DEPLOYMENT_NAME: string;
5
+ export declare const AZURE_OPENAI_API_VERSION: string;
6
+ export declare const isProd: boolean;
@@ -1,6 +1,7 @@
1
1
  export const HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
2
- export const AZURE_OPENAI_API_KEY = process.env.AZURE_OPENAI_API_KEY;
3
- export const AZURE_OPENAI_API_DEPLOYMENT_NAME = process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME;
4
- export const AZURE_OPENAI_API_VERSION = process.env.AZURE_OPENAI_API_VERSION;
2
+ export const AZURE_OPENAI_API_KEY = process.env.AZURE_OPENAI_API_KEY; // pragma: allowlist secret
5
3
  export const AZURE_OPENAI_API_BASE = process.env.AZURE_OPENAI_API_BASE;
4
+ export const AZURE_OPENAI_API_DEPLOYMENT_NAME = process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME || 'gpt-4o-mini_p1';
5
+ export const AZURE_OPENAI_API_VERSION = process.env.AZURE_OPENAI_API_VERSION || '2024-12-01-preview';
6
+ export const isProd = process.env.NODE_ENV === 'production';
6
7
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAE1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA;AACpE,MAAM,CAAC,MAAM,gCAAgC,GAC3C,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAA;AAC9C,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAA;AAC5E,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAA"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAE1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA,CAAC,2BAA2B;AAChG,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAA;AACtE,MAAM,CAAC,MAAM,gCAAgC,GAC3C,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,gBAAgB,CAAA;AAClE,MAAM,CAAC,MAAM,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,oBAAoB,CAAA;AAE9D,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA"}
@@ -1,7 +1,9 @@
1
1
  import { BotContext } from '@botonic/core';
2
2
  import { AgenticInputMessage } from './types';
3
- export declare class HubtypeClient {
3
+ export declare class HubtypeApiClient {
4
4
  private readonly authToken;
5
5
  constructor(authToken: string);
6
+ getLocalMessages(memoryLength: number): Promise<AgenticInputMessage[]>;
6
7
  getMessages(request: BotContext, memoryLength: number): Promise<AgenticInputMessage[]>;
8
+ private formatMessage;
7
9
  }
@@ -0,0 +1,72 @@
1
+ import { __awaiter } from "tslib";
2
+ import axios from 'axios';
3
+ import { HUBTYPE_API_URL } from './constants';
4
+ export class HubtypeApiClient {
5
+ constructor(authToken) {
6
+ this.authToken = authToken;
7
+ }
8
+ getLocalMessages(memoryLength) {
9
+ return __awaiter(this, void 0, void 0, function* () {
10
+ const localBotonicState = localStorage.getItem('botonicState');
11
+ const botonicState = JSON.parse(localBotonicState || '{}');
12
+ const messages = botonicState.messages;
13
+ const filteredMessages = messages
14
+ .filter(message => message.data.text)
15
+ .map(message => ({
16
+ role: message.sentBy === 'user' ? 'user' : 'assistant',
17
+ content: message.data.text,
18
+ }))
19
+ .map(message => this.formatMessage(message));
20
+ return filteredMessages.slice(-memoryLength);
21
+ });
22
+ }
23
+ getMessages(request, memoryLength) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const url = `${HUBTYPE_API_URL}/external/v1/ai/agent/message_history/`;
26
+ const headers = {
27
+ 'Content-Type': 'application/json',
28
+ Authorization: `Bearer ${this.authToken}`,
29
+ };
30
+ const params = {
31
+ last_message_id: request.input.message_id,
32
+ num_messages: memoryLength,
33
+ };
34
+ try {
35
+ const response = yield axios.get(url, {
36
+ headers,
37
+ params,
38
+ });
39
+ const messages = response.data.messages;
40
+ return messages.map(message => this.formatMessage(message));
41
+ }
42
+ catch (error) {
43
+ console.error(error);
44
+ throw new Error('Failed to get messages from Hubtype');
45
+ }
46
+ });
47
+ }
48
+ formatMessage(message) {
49
+ if (message.role === 'user') {
50
+ return {
51
+ content: message.content,
52
+ role: 'user',
53
+ };
54
+ }
55
+ else if (message.role === 'assistant') {
56
+ return {
57
+ role: 'assistant',
58
+ content: [
59
+ {
60
+ type: 'output_text',
61
+ text: message.content,
62
+ },
63
+ ],
64
+ status: 'completed',
65
+ };
66
+ }
67
+ else {
68
+ throw new Error('Invalid message role');
69
+ }
70
+ }
71
+ }
72
+ //# sourceMappingURL=hubtype-api-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hubtype-api-client.js","sourceRoot":"","sources":["../../src/hubtype-api-client.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAe7C,MAAM,OAAO,gBAAgB;IAG3B,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAEK,gBAAgB,CAAC,YAAoB;;YACzC,MAAM,iBAAiB,GAAG,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;YAC9D,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,IAAI,IAAI,CAAC,CAAA;YAC1D,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAA;YACtC,MAAM,gBAAgB,GAAG,QAAQ;iBAC9B,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;iBACpC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACf,IAAI,EAAE,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW;gBACtD,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI;aAC3B,CAAC,CAAC;iBACF,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;YAC9C,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAA;QAC9C,CAAC;KAAA;IAEK,WAAW,CACf,OAAmB,EACnB,YAAoB;;YAEpB,MAAM,GAAG,GAAG,GAAG,eAAe,wCAAwC,CAAA;YACtE,MAAM,OAAO,GAAG;gBACd,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;aAC1C,CAAA;YACD,MAAM,MAAM,GAAG;gBACb,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;gBACzC,YAAY,EAAE,YAAY;aAC3B,CAAA;YAED,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAiC,GAAG,EAAE;oBACpE,OAAO;oBACP,MAAM;iBACP,CAAC,CAAA;gBACF,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAA;gBACvC,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;aAC5D;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;gBACpB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;aACvD;QACH,CAAC;KAAA;IAEO,aAAa,CAAC,OAAuB;QAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;YAC3B,OAAO;gBACL,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,MAAM;aACb,CAAA;SACF;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,EAAE;YACvC,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,aAAa;wBACnB,IAAI,EAAE,OAAO,CAAC,OAAO;qBACtB;iBACF;gBACD,MAAM,EAAE,WAAW;aACpB,CAAA;SACF;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;SACxC;IACH,CAAC;CACF"}
@@ -1,9 +1,12 @@
1
1
  import { BotContext, Plugin } from '@botonic/core';
2
- import { AgenticOutputMessage, AiAgentArgs, PluginAiAgentOptions } from './types';
2
+ import { AgenticOutputMessage, AiAgentArgs, CustomTool, PluginAiAgentOptions } from './types';
3
3
  export default class BotonicPluginAiAgents implements Plugin {
4
4
  private readonly authToken?;
5
+ toolDefinitions: CustomTool[];
5
6
  constructor(options?: PluginAiAgentOptions);
6
7
  pre(): void;
7
- getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<AgenticOutputMessage | undefined>;
8
+ getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<AgenticOutputMessage[] | undefined>;
9
+ private getMessages;
10
+ private buildTools;
8
11
  }
9
12
  export * from './types';