@botonic/plugin-ai-agents 0.36.0-alpha.6 → 0.36.0-alpha.7
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.
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/hubtype-api-client.d.ts +2 -0
- package/lib/cjs/hubtype-api-client.js +41 -2
- package/lib/cjs/hubtype-api-client.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +22 -25
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/runner.d.ts +9 -0
- package/lib/cjs/runner.js +58 -0
- package/lib/cjs/runner.js.map +1 -0
- package/lib/cjs/structured-output/carousel.d.ts +100 -0
- package/lib/cjs/structured-output/carousel.js +21 -0
- package/lib/cjs/structured-output/carousel.js.map +1 -0
- package/lib/cjs/structured-output/exit.d.ts +12 -0
- package/lib/cjs/structured-output/exit.js +11 -0
- package/lib/cjs/structured-output/exit.js.map +1 -0
- package/lib/cjs/structured-output/index.d.ts +198 -0
- package/lib/cjs/structured-output/index.js +14 -0
- package/lib/cjs/structured-output/index.js.map +1 -0
- package/lib/cjs/structured-output/shared.d.ts +3 -0
- package/lib/cjs/structured-output/shared.js +3 -0
- package/lib/cjs/structured-output/shared.js.map +1 -0
- package/lib/cjs/structured-output/text-with-buttons.d.ts +34 -0
- package/lib/cjs/structured-output/text-with-buttons.js +15 -0
- package/lib/cjs/structured-output/text-with-buttons.js.map +1 -0
- package/lib/cjs/structured-output/text.d.ts +28 -0
- package/lib/cjs/structured-output/text.js +13 -0
- package/lib/cjs/structured-output/text.js.map +1 -0
- package/lib/cjs/types.d.ts +6 -25
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/hubtype-api-client.d.ts +2 -0
- package/lib/esm/hubtype-api-client.js +41 -2
- package/lib/esm/hubtype-api-client.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +20 -23
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/runner.d.ts +9 -0
- package/lib/esm/runner.js +54 -0
- package/lib/esm/runner.js.map +1 -0
- package/lib/esm/structured-output/carousel.d.ts +100 -0
- package/lib/esm/structured-output/carousel.js +18 -0
- package/lib/esm/structured-output/carousel.js.map +1 -0
- package/lib/esm/structured-output/exit.d.ts +12 -0
- package/lib/esm/structured-output/exit.js +7 -0
- package/lib/esm/structured-output/exit.js.map +1 -0
- package/lib/esm/structured-output/index.d.ts +198 -0
- package/lib/esm/structured-output/index.js +11 -0
- package/lib/esm/structured-output/index.js.map +1 -0
- package/lib/esm/structured-output/shared.d.ts +3 -0
- package/lib/esm/structured-output/shared.js +2 -0
- package/lib/esm/structured-output/shared.js.map +1 -0
- package/lib/esm/structured-output/text-with-buttons.d.ts +34 -0
- package/lib/esm/structured-output/text-with-buttons.js +11 -0
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -0
- package/lib/esm/structured-output/text.d.ts +28 -0
- package/lib/esm/structured-output/text.js +10 -0
- package/lib/esm/structured-output/text.js.map +1 -0
- package/lib/esm/types.d.ts +6 -25
- package/package.json +3 -4
- package/src/constants.ts +2 -0
- package/src/hubtype-api-client.ts +55 -9
- package/src/index.ts +25 -32
- package/src/runner.ts +74 -0
- package/src/structured-output/carousel.ts +36 -0
- package/src/structured-output/exit.ts +15 -0
- package/src/structured-output/index.ts +27 -0
- package/src/structured-output/shared.ts +3 -0
- package/src/structured-output/text-with-buttons.ts +23 -0
- package/src/structured-output/text.ts +19 -0
- package/src/types.ts +7 -34
- package/lib/cjs/ai-agent-client.d.ts +0 -9
- package/lib/cjs/ai-agent-client.js +0 -49
- package/lib/cjs/ai-agent-client.js.map +0 -1
- package/lib/cjs/errors.d.ts +0 -3
- package/lib/cjs/errors.js +0 -11
- package/lib/cjs/errors.js.map +0 -1
- package/lib/cjs/tools/custom.d.ts +0 -3
- package/lib/cjs/tools/custom.js +0 -14
- package/lib/cjs/tools/custom.js.map +0 -1
- package/lib/cjs/tools/default.d.ts +0 -6
- package/lib/cjs/tools/default.js +0 -41
- package/lib/cjs/tools/default.js.map +0 -1
- package/lib/cjs/utils.d.ts +0 -5
- package/lib/cjs/utils.js +0 -26
- package/lib/cjs/utils.js.map +0 -1
- package/lib/esm/ai-agent-client.d.ts +0 -9
- package/lib/esm/ai-agent-client.js +0 -45
- package/lib/esm/ai-agent-client.js.map +0 -1
- package/lib/esm/errors.d.ts +0 -3
- package/lib/esm/errors.js +0 -7
- package/lib/esm/errors.js.map +0 -1
- package/lib/esm/tools/custom.d.ts +0 -3
- package/lib/esm/tools/custom.js +0 -10
- package/lib/esm/tools/custom.js.map +0 -1
- package/lib/esm/tools/default.d.ts +0 -6
- package/lib/esm/tools/default.js +0 -38
- package/lib/esm/tools/default.js.map +0 -1
- package/lib/esm/utils.d.ts +0 -5
- package/lib/esm/utils.js +0 -22
- package/lib/esm/utils.js.map +0 -1
- package/src/ai-agent-client.ts +0 -69
- package/src/errors.ts +0 -6
- package/src/tools/custom.ts +0 -14
- package/src/tools/default.ts +0 -52
- package/src/utils.ts +0 -28
|
@@ -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,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CarouselSchema } from './carousel';
|
|
3
|
+
import { ExitSchema } from './exit';
|
|
4
|
+
import { TextSchema } from './text';
|
|
5
|
+
import { TextWithButtonsSchema, } from './text-with-buttons';
|
|
6
|
+
export const OutputSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
messages: z.array(z.union([TextSchema, TextWithButtonsSchema, CarouselSchema, ExitSchema])),
|
|
9
|
+
})
|
|
10
|
+
.describe('The messages to be sent to the user');
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structured-output/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAmB,cAAc,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAe,UAAU,EAAE,MAAM,QAAQ,CAAA;AAChD,OAAO,EAAe,UAAU,EAAE,MAAM,QAAQ,CAAA;AAChD,OAAO,EAEL,qBAAqB,GACtB,MAAM,qBAAqB,CAAA;AAY5B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC,CAAC,KAAK,CACf,CAAC,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,qBAAqB,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC,CACzE;CACF,CAAC;KACD,QAAQ,CAAC,qCAAqC,CAAC,CAAA"}
|
|
@@ -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,11 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export const TextWithButtonsSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
type: z.enum(['textWithButtons']),
|
|
5
|
+
content: z.object({
|
|
6
|
+
text: z.string(),
|
|
7
|
+
buttons: z.array(z.string()),
|
|
8
|
+
}),
|
|
9
|
+
})
|
|
10
|
+
.describe('A text message with buttons to allow the user to use quick replies');
|
|
11
|
+
//# 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,OAAO,CAAC,MAAM,KAAK,CAAA;AAYnB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC;KACnC,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACjC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,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 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/structured-output/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAWvB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;KACjB,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,gBAAgB,CAAC,CAAA"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentInputItem } from '@openai/agents';
|
|
2
|
+
import { ZodObject } from 'zod';
|
|
3
|
+
import { OutputMessage } from './structured-output';
|
|
2
4
|
export interface PluginAiAgentOptions {
|
|
3
5
|
authToken?: string;
|
|
4
6
|
customTools?: CustomTool[];
|
|
@@ -6,8 +8,7 @@ export interface PluginAiAgentOptions {
|
|
|
6
8
|
export interface CustomTool {
|
|
7
9
|
name: string;
|
|
8
10
|
description: string;
|
|
9
|
-
schema:
|
|
10
|
-
returnDirect?: boolean;
|
|
11
|
+
schema: ZodObject<any>;
|
|
11
12
|
func: (input?: any) => Promise<any>;
|
|
12
13
|
}
|
|
13
14
|
export interface AiAgentArgs {
|
|
@@ -17,25 +18,5 @@ export interface AiAgentArgs {
|
|
|
17
18
|
name: string;
|
|
18
19
|
}[];
|
|
19
20
|
}
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
export interface AssistantMessage extends AgenticBaseMessage {
|
|
24
|
-
role: 'assistant';
|
|
25
|
-
content: string;
|
|
26
|
-
}
|
|
27
|
-
export interface UserMessage extends AgenticBaseMessage {
|
|
28
|
-
role: 'user';
|
|
29
|
-
content: string;
|
|
30
|
-
}
|
|
31
|
-
export interface ToolMessage extends AgenticBaseMessage {
|
|
32
|
-
role: 'tool';
|
|
33
|
-
toolName: string;
|
|
34
|
-
toolOutput: string | null;
|
|
35
|
-
}
|
|
36
|
-
export interface ExitMessage extends AgenticBaseMessage {
|
|
37
|
-
role: 'exit';
|
|
38
|
-
}
|
|
39
|
-
export type AgenticInputMessage = AssistantMessage | UserMessage;
|
|
40
|
-
export type AgenticOutputMessage = AssistantMessage | ToolMessage | ExitMessage;
|
|
41
|
-
export type AgenticMessage = AssistantMessage | UserMessage | ToolMessage | ExitMessage;
|
|
21
|
+
export type AgenticInputMessage = AgentInputItem;
|
|
22
|
+
export type AgenticOutputMessage = OutputMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-ai-agents",
|
|
3
|
-
"version": "0.36.0-alpha.
|
|
3
|
+
"version": "0.36.0-alpha.7",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use AI Agents to generate your contents",
|
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@botonic/core": "^0.36.0",
|
|
17
|
-
"@
|
|
18
|
-
"@langchain/langgraph": "^0.3.0",
|
|
19
|
-
"@langchain/openai": "^0.5.12",
|
|
17
|
+
"@openai/agents": "^0.0.10",
|
|
20
18
|
"axios": "^1.10.0",
|
|
19
|
+
"openai": "^5.8.3",
|
|
21
20
|
"uuid": "^10.0.0",
|
|
22
21
|
"zod": "^3.25.57"
|
|
23
22
|
},
|
package/src/constants.ts
CHANGED
|
@@ -7,3 +7,5 @@ export const AZURE_OPENAI_API_DEPLOYMENT_NAME =
|
|
|
7
7
|
process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME || 'gpt-4o-mini_p1'
|
|
8
8
|
export const AZURE_OPENAI_API_VERSION =
|
|
9
9
|
process.env.AZURE_OPENAI_API_VERSION || '2024-12-01-preview'
|
|
10
|
+
|
|
11
|
+
export const isProd = process.env.NODE_ENV === 'production'
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1
2
|
import { BotContext } from '@botonic/core'
|
|
2
3
|
import axios from 'axios'
|
|
3
4
|
|
|
4
5
|
import { HUBTYPE_API_URL } from './constants'
|
|
5
6
|
import { AgenticInputMessage } from './types'
|
|
6
7
|
|
|
8
|
+
interface HubtypeAssistantMessage {
|
|
9
|
+
role: 'assistant'
|
|
10
|
+
content: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface HubtypeUserMessage {
|
|
14
|
+
role: 'user'
|
|
15
|
+
content: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type HubtypeMessage = HubtypeAssistantMessage | HubtypeUserMessage
|
|
19
|
+
|
|
7
20
|
export class HubtypeApiClient {
|
|
8
21
|
private readonly authToken: string
|
|
9
22
|
|
|
@@ -11,6 +24,20 @@ export class HubtypeApiClient {
|
|
|
11
24
|
this.authToken = authToken
|
|
12
25
|
}
|
|
13
26
|
|
|
27
|
+
async getLocalMessages(memoryLength: number): Promise<AgenticInputMessage[]> {
|
|
28
|
+
const localBotonicState = localStorage.getItem('botonicState')
|
|
29
|
+
const botonicState = JSON.parse(localBotonicState || '{}')
|
|
30
|
+
const messages = botonicState.messages
|
|
31
|
+
const filteredMessages = messages
|
|
32
|
+
.filter(message => message.data.text)
|
|
33
|
+
.map(message => ({
|
|
34
|
+
role: message.sentBy === 'user' ? 'user' : 'assistant',
|
|
35
|
+
content: message.data.text,
|
|
36
|
+
}))
|
|
37
|
+
.map(message => this.formatMessage(message))
|
|
38
|
+
return filteredMessages.slice(-memoryLength)
|
|
39
|
+
}
|
|
40
|
+
|
|
14
41
|
async getMessages(
|
|
15
42
|
request: BotContext,
|
|
16
43
|
memoryLength: number
|
|
@@ -26,18 +53,37 @@ export class HubtypeApiClient {
|
|
|
26
53
|
}
|
|
27
54
|
|
|
28
55
|
try {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
return messages.data.messages
|
|
56
|
+
const response = await axios.get<{ messages: HubtypeMessage[] }>(url, {
|
|
57
|
+
headers,
|
|
58
|
+
params,
|
|
59
|
+
})
|
|
60
|
+
const messages = response.data.messages
|
|
61
|
+
return messages.map(message => this.formatMessage(message))
|
|
38
62
|
} catch (error) {
|
|
39
63
|
console.error(error)
|
|
40
64
|
throw new Error('Failed to get messages from Hubtype')
|
|
41
65
|
}
|
|
42
66
|
}
|
|
67
|
+
|
|
68
|
+
private formatMessage(message: HubtypeMessage): AgenticInputMessage {
|
|
69
|
+
if (message.role === 'user') {
|
|
70
|
+
return {
|
|
71
|
+
content: message.content,
|
|
72
|
+
role: 'user',
|
|
73
|
+
}
|
|
74
|
+
} else if (message.role === 'assistant') {
|
|
75
|
+
return {
|
|
76
|
+
role: 'assistant',
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: 'output_text',
|
|
80
|
+
text: message.content,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
status: 'completed',
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
throw new Error('Invalid message role')
|
|
87
|
+
}
|
|
88
|
+
}
|
|
43
89
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BotContext, Plugin } from '@botonic/core'
|
|
2
|
+
import { tool } from '@openai/agents'
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import { isProd } from './constants'
|
|
4
5
|
import { HubtypeApiClient } from './hubtype-api-client'
|
|
5
|
-
import {
|
|
6
|
-
import { MANDATORY_TOOLS } from './tools/default'
|
|
6
|
+
import { AIAgentRunner } from './runner'
|
|
7
7
|
import {
|
|
8
8
|
AgenticInputMessage,
|
|
9
9
|
AgenticOutputMessage,
|
|
@@ -11,9 +11,6 @@ import {
|
|
|
11
11
|
CustomTool,
|
|
12
12
|
PluginAiAgentOptions,
|
|
13
13
|
} from './types'
|
|
14
|
-
import { AiProvider, loadChatModel } from './utils'
|
|
15
|
-
|
|
16
|
-
const isProd = process.env.NODE_ENV === 'production'
|
|
17
14
|
|
|
18
15
|
export default class BotonicPluginAiAgents implements Plugin {
|
|
19
16
|
private readonly authToken?: string
|
|
@@ -31,7 +28,7 @@ export default class BotonicPluginAiAgents implements Plugin {
|
|
|
31
28
|
async getInference(
|
|
32
29
|
request: BotContext,
|
|
33
30
|
aiAgentArgs: AiAgentArgs
|
|
34
|
-
): Promise<AgenticOutputMessage | undefined> {
|
|
31
|
+
): Promise<AgenticOutputMessage[] | undefined> {
|
|
35
32
|
try {
|
|
36
33
|
const authToken = isProd ? request.session._access_token : this.authToken
|
|
37
34
|
if (!authToken) {
|
|
@@ -39,20 +36,20 @@ export default class BotonicPluginAiAgents implements Plugin {
|
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
const messages = await this.getMessages(request, authToken, 10)
|
|
42
|
-
|
|
43
|
-
const customTools = this.customTools.map(customTool =>
|
|
44
|
-
createCustomTool(customTool)
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
const customActiveTools = customTools.filter(tool =>
|
|
39
|
+
const availableTools = this.customTools.filter(tool =>
|
|
48
40
|
aiAgentArgs.activeTools?.map(tool => tool.name).includes(tool.name)
|
|
49
41
|
)
|
|
50
|
-
const tools =
|
|
42
|
+
const tools = this.createTools(availableTools)
|
|
51
43
|
|
|
52
|
-
const
|
|
53
|
-
|
|
44
|
+
const runner = new AIAgentRunner(
|
|
45
|
+
aiAgentArgs.name,
|
|
46
|
+
aiAgentArgs.instructions,
|
|
47
|
+
tools
|
|
48
|
+
)
|
|
49
|
+
const output = await runner.run(messages)
|
|
50
|
+
console.log('\n\nOutput:', output)
|
|
54
51
|
|
|
55
|
-
return
|
|
52
|
+
return output
|
|
56
53
|
} catch (error) {
|
|
57
54
|
console.error('error plugin returns undefined', error)
|
|
58
55
|
return undefined
|
|
@@ -68,23 +65,19 @@ export default class BotonicPluginAiAgents implements Plugin {
|
|
|
68
65
|
const hubtypeClient = new HubtypeApiClient(authToken)
|
|
69
66
|
return await hubtypeClient.getMessages(request, memoryLength)
|
|
70
67
|
}
|
|
71
|
-
|
|
68
|
+
const hubtypeClient = new HubtypeApiClient(authToken)
|
|
69
|
+
return await hubtypeClient.getLocalMessages(memoryLength)
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
private
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
role: message.sentBy === 'user' ? 'user' : 'assistant',
|
|
84
|
-
content: message.data.text,
|
|
85
|
-
}))
|
|
86
|
-
|
|
87
|
-
return filteredMessages.slice(-memoryLength)
|
|
72
|
+
private createTools(customTools: CustomTool[]) {
|
|
73
|
+
return customTools.map(customTool => {
|
|
74
|
+
return tool({
|
|
75
|
+
name: customTool.name,
|
|
76
|
+
description: customTool.description,
|
|
77
|
+
parameters: customTool.schema,
|
|
78
|
+
execute: customTool.func,
|
|
79
|
+
})
|
|
80
|
+
})
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
83
|
|
package/src/runner.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Agent,
|
|
3
|
+
Runner,
|
|
4
|
+
setDefaultOpenAIClient,
|
|
5
|
+
setOpenAIAPI,
|
|
6
|
+
setTracingDisabled,
|
|
7
|
+
Tool,
|
|
8
|
+
} from '@openai/agents'
|
|
9
|
+
import { AzureOpenAI } from 'openai'
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
AZURE_OPENAI_API_BASE,
|
|
13
|
+
AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
14
|
+
AZURE_OPENAI_API_KEY,
|
|
15
|
+
AZURE_OPENAI_API_VERSION,
|
|
16
|
+
isProd,
|
|
17
|
+
} from './constants'
|
|
18
|
+
import { OutputMessage, OutputSchema } from './structured-output'
|
|
19
|
+
import { AgenticInputMessage } from './types'
|
|
20
|
+
|
|
21
|
+
export class AIAgentRunner {
|
|
22
|
+
private agent: Agent<any, typeof OutputSchema>
|
|
23
|
+
|
|
24
|
+
constructor(name: string, instructions: string, tools: Tool[]) {
|
|
25
|
+
if (AZURE_OPENAI_API_KEY) {
|
|
26
|
+
const client = new AzureOpenAI({
|
|
27
|
+
apiKey: AZURE_OPENAI_API_KEY,
|
|
28
|
+
apiVersion: AZURE_OPENAI_API_VERSION,
|
|
29
|
+
deployment: AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
30
|
+
baseURL: AZURE_OPENAI_API_BASE,
|
|
31
|
+
dangerouslyAllowBrowser: !isProd,
|
|
32
|
+
})
|
|
33
|
+
setDefaultOpenAIClient(client as any)
|
|
34
|
+
setOpenAIAPI('chat_completions')
|
|
35
|
+
setTracingDisabled(true)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this.agent = new Agent({
|
|
39
|
+
name: name,
|
|
40
|
+
instructions: this.addExtraInstructions(instructions),
|
|
41
|
+
tools: tools,
|
|
42
|
+
outputType: OutputSchema,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async run(messages: AgenticInputMessage[]): Promise<OutputMessage[]> {
|
|
47
|
+
const runner = new Runner({
|
|
48
|
+
modelSettings: { temperature: 0 },
|
|
49
|
+
})
|
|
50
|
+
const result = await runner.run(this.agent, messages)
|
|
51
|
+
const finalOutput = result.finalOutput
|
|
52
|
+
|
|
53
|
+
return finalOutput?.messages || []
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private addExtraInstructions(instructions: string): string {
|
|
57
|
+
const metadata = `Current Date: ${new Date().toISOString()}`
|
|
58
|
+
|
|
59
|
+
const outputExample = JSON.stringify({
|
|
60
|
+
messages: [
|
|
61
|
+
{
|
|
62
|
+
type: 'text',
|
|
63
|
+
content: {
|
|
64
|
+
text: 'Hello, how can I help you today?',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
numMessages: 1,
|
|
69
|
+
})
|
|
70
|
+
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${outputExample}\n</example>`
|
|
71
|
+
|
|
72
|
+
return `<instructions>\n${instructions}\n</instructions>\n\n<metadata>\n${metadata}\n</metadata>\n\n<output>\n${output}\n</output>`
|
|
73
|
+
}
|
|
74
|
+
}
|