@botonic/plugin-ai-agents 0.40.0-alpha.1 → 0.40.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.
- package/lib/cjs/agent-builder.d.ts +1 -1
- package/lib/cjs/agent-builder.js +11 -3
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/hubtype-api-client.d.ts +1 -0
- package/lib/cjs/hubtype-api-client.js +19 -1
- package/lib/cjs/hubtype-api-client.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/structured-output/carousel.d.ts +9 -9
- package/lib/cjs/structured-output/carousel.js +1 -1
- package/lib/cjs/structured-output/carousel.js.map +1 -1
- package/lib/cjs/structured-output/index.d.ts +36 -18
- package/lib/cjs/structured-output/text-with-buttons.d.ts +19 -5
- package/lib/cjs/structured-output/text-with-buttons.js +3 -1
- package/lib/cjs/structured-output/text-with-buttons.js.map +1 -1
- package/lib/cjs/tools/index.d.ts +1 -0
- package/lib/cjs/tools/index.js +3 -1
- package/lib/cjs/tools/index.js.map +1 -1
- package/lib/cjs/tools/retrieve-knowledge.d.ts +2 -0
- package/lib/cjs/tools/retrieve-knowledge.js +25 -0
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -0
- package/lib/cjs/types.d.ts +3 -14
- package/lib/esm/agent-builder.d.ts +1 -1
- package/lib/esm/agent-builder.js +12 -4
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/hubtype-api-client.d.ts +1 -0
- package/lib/esm/hubtype-api-client.js +19 -1
- package/lib/esm/hubtype-api-client.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/structured-output/carousel.d.ts +9 -9
- package/lib/esm/structured-output/carousel.js +1 -1
- package/lib/esm/structured-output/carousel.js.map +1 -1
- package/lib/esm/structured-output/index.d.ts +36 -18
- package/lib/esm/structured-output/text-with-buttons.d.ts +19 -5
- package/lib/esm/structured-output/text-with-buttons.js +3 -1
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
- package/lib/esm/tools/index.d.ts +1 -0
- package/lib/esm/tools/index.js +1 -0
- package/lib/esm/tools/index.js.map +1 -1
- package/lib/esm/tools/retrieve-knowledge.d.ts +2 -0
- package/lib/esm/tools/retrieve-knowledge.js +22 -0
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -0
- package/lib/esm/types.d.ts +3 -14
- package/package.json +3 -3
- package/src/agent-builder.ts +16 -5
- package/src/hubtype-api-client.ts +22 -1
- package/src/index.ts +4 -3
- package/src/structured-output/carousel.ts +1 -1
- package/src/structured-output/text-with-buttons.ts +5 -1
- package/src/tools/index.ts +1 -0
- package/src/tools/retrieve-knowledge.ts +27 -0
- package/src/types.ts +10 -13
|
@@ -5,9 +5,27 @@ export class HubtypeApiClient {
|
|
|
5
5
|
constructor(authToken) {
|
|
6
6
|
this.authToken = authToken;
|
|
7
7
|
}
|
|
8
|
+
retrieveSimilarChunks(query, sources) {
|
|
9
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
const url = `${HUBTYPE_API_URL}/external/v1/ai/knowledge_base/similar_chunks/`;
|
|
11
|
+
const headers = {
|
|
12
|
+
'Content-Type': 'application/json',
|
|
13
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
14
|
+
};
|
|
15
|
+
const params = {
|
|
16
|
+
query,
|
|
17
|
+
source_ids: sources,
|
|
18
|
+
num_chunks: 5,
|
|
19
|
+
};
|
|
20
|
+
const response = yield axios.post(url, params, { headers });
|
|
21
|
+
return response.data.chunks.map((chunk) => chunk.text);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
8
24
|
getLocalMessages(maxMemoryLength) {
|
|
9
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10
|
-
const localBotonicState =
|
|
26
|
+
const localBotonicState = typeof globalThis !== 'undefined' && globalThis.localStorage
|
|
27
|
+
? globalThis.localStorage.getItem('botonicState')
|
|
28
|
+
: null;
|
|
11
29
|
const botonicState = JSON.parse(localBotonicState || '{}');
|
|
12
30
|
const messages = botonicState.messages;
|
|
13
31
|
const filteredMessages = messages
|
|
@@ -1 +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,CACpB,eAAuB;;YAEvB,MAAM,iBAAiB,
|
|
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,qBAAqB,CACzB,KAAa,EACb,OAAiB;;YAEjB,MAAM,GAAG,GAAG,GAAG,eAAe,gDAAgD,CAAA;YAC9E,MAAM,OAAO,GAAG;gBACd,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;aAC1C,CAAA;YACD,MAAM,MAAM,GAAG;gBACb,KAAK;gBACL,UAAU,EAAE,OAAO;gBACnB,UAAU,EAAE,CAAC;aACd,CAAA;YACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;YAC3D,OAAO,QAAQ,CAAC,IAAI,CAAC,MA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AAe;aAC9B,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"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BotContext, Plugin } from '@botonic/core';
|
|
2
|
-
import {
|
|
1
|
+
import { AiAgentArgs, BotContext, Plugin } from '@botonic/core';
|
|
2
|
+
import { CustomTool, InferenceResponse, PluginAiAgentOptions } from './types';
|
|
3
3
|
export default class BotonicPluginAiAgents implements Plugin {
|
|
4
4
|
private readonly authToken?;
|
|
5
5
|
toolDefinitions: CustomTool[];
|
package/lib/esm/index.js
CHANGED
|
@@ -24,10 +24,11 @@ export default class BotonicPluginAiAgents {
|
|
|
24
24
|
throw new Error('Auth token is required');
|
|
25
25
|
}
|
|
26
26
|
const tools = this.buildTools(((_a = aiAgentArgs.activeTools) === null || _a === void 0 ? void 0 : _a.map(tool => tool.name)) || []);
|
|
27
|
-
const agent = new AIAgentBuilder(aiAgentArgs.name, aiAgentArgs.instructions, tools, request.session.user.contact_info || {}, aiAgentArgs.inputGuardrailRules || []).build();
|
|
27
|
+
const agent = new AIAgentBuilder(aiAgentArgs.name, aiAgentArgs.instructions, tools, request.session.user.contact_info || {}, aiAgentArgs.inputGuardrailRules || [], aiAgentArgs.sourceIds || []).build();
|
|
28
28
|
const messages = yield this.getMessages(request, authToken, MAX_MEMORY_LENGTH);
|
|
29
29
|
const context = {
|
|
30
30
|
authToken,
|
|
31
|
+
sources: aiAgentArgs.sourceIds || [],
|
|
31
32
|
};
|
|
32
33
|
const runner = new AIAgentRunner(agent);
|
|
33
34
|
return yield runner.run(messages, context);
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAErC,OAAO,EAAE,cAAc,EAAE,MA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AC,GAAG,CAAC,cAAc,CAAC,EAAE;YACzC,OAAO,IAAI,CAAoB;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;AAED,cAAc,SAAS,CAAA"}
|
|
@@ -10,13 +10,13 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
10
10
|
image: z.ZodString;
|
|
11
11
|
button: z.ZodObject<{
|
|
12
12
|
text: z.ZodString;
|
|
13
|
-
url: z.ZodString
|
|
13
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
14
|
}, "strip", z.ZodTypeAny, {
|
|
15
15
|
text: string;
|
|
16
|
-
url
|
|
16
|
+
url?: string | null | undefined;
|
|
17
17
|
}, {
|
|
18
18
|
text: string;
|
|
19
|
-
url
|
|
19
|
+
url?: string | null | undefined;
|
|
20
20
|
}>;
|
|
21
21
|
}, "strip", z.ZodTypeAny, {
|
|
22
22
|
title: string;
|
|
@@ -24,7 +24,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
24
24
|
image: string;
|
|
25
25
|
button: {
|
|
26
26
|
text: string;
|
|
27
|
-
url
|
|
27
|
+
url?: string | null | undefined;
|
|
28
28
|
};
|
|
29
29
|
}, {
|
|
30
30
|
title: string;
|
|
@@ -32,7 +32,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
32
32
|
image: string;
|
|
33
33
|
button: {
|
|
34
34
|
text: string;
|
|
35
|
-
url
|
|
35
|
+
url?: string | null | undefined;
|
|
36
36
|
};
|
|
37
37
|
}>, "many">;
|
|
38
38
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -42,7 +42,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
42
42
|
image: string;
|
|
43
43
|
button: {
|
|
44
44
|
text: string;
|
|
45
|
-
url
|
|
45
|
+
url?: string | null | undefined;
|
|
46
46
|
};
|
|
47
47
|
}[];
|
|
48
48
|
}, {
|
|
@@ -52,7 +52,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
52
52
|
image: string;
|
|
53
53
|
button: {
|
|
54
54
|
text: string;
|
|
55
|
-
url
|
|
55
|
+
url?: string | null | undefined;
|
|
56
56
|
};
|
|
57
57
|
}[];
|
|
58
58
|
}>;
|
|
@@ -65,7 +65,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
65
65
|
image: string;
|
|
66
66
|
button: {
|
|
67
67
|
text: string;
|
|
68
|
-
url
|
|
68
|
+
url?: string | null | undefined;
|
|
69
69
|
};
|
|
70
70
|
}[];
|
|
71
71
|
};
|
|
@@ -78,7 +78,7 @@ export declare const CarouselSchema: z.ZodObject<{
|
|
|
78
78
|
image: string;
|
|
79
79
|
button: {
|
|
80
80
|
text: string;
|
|
81
|
-
url
|
|
81
|
+
url?: string | null | undefined;
|
|
82
82
|
};
|
|
83
83
|
}[];
|
|
84
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"carousel.js","sourceRoot":"","sources":["../../../src/structured-output/carousel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,QAAQ,EAAE,CAAC,CAAC,KAAK,CACf,CAAC,CAAC,MAAM,CAAC;YACP,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;YACjB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;YACpB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;gBACf,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;gBAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;
|
|
1
|
+
{"version":3,"file":"carousel.js","sourceRoot":"","sources":["../../../src/structured-output/carousel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,QAAQ,EAAE,CAAC,CAAC,KAAK,CACf,CAAC,CAAC,MAAM,CAAC;YACP,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;YACjB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;YACpB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;gBACf,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;gBAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;aACtC,CAAC;SACH,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,kDAAkD,CAAC,CAAA"}
|
|
@@ -27,25 +27,39 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
27
27
|
type: z.ZodEnum<["textWithButtons"]>;
|
|
28
28
|
content: z.ZodObject<{
|
|
29
29
|
text: z.ZodString;
|
|
30
|
-
buttons: z.ZodArray<z.
|
|
30
|
+
buttons: z.ZodArray<z.ZodObject<{
|
|
31
|
+
text: z.ZodString;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
text: string;
|
|
34
|
+
}, {
|
|
35
|
+
text: string;
|
|
36
|
+
}>, "many">;
|
|
31
37
|
}, "strip", z.ZodTypeAny, {
|
|
32
38
|
text: string;
|
|
33
|
-
buttons:
|
|
39
|
+
buttons: {
|
|
40
|
+
text: string;
|
|
41
|
+
}[];
|
|
34
42
|
}, {
|
|
35
43
|
text: string;
|
|
36
|
-
buttons:
|
|
44
|
+
buttons: {
|
|
45
|
+
text: string;
|
|
46
|
+
}[];
|
|
37
47
|
}>;
|
|
38
48
|
}, "strip", z.ZodTypeAny, {
|
|
39
49
|
type: "textWithButtons";
|
|
40
50
|
content: {
|
|
41
51
|
text: string;
|
|
42
|
-
buttons:
|
|
52
|
+
buttons: {
|
|
53
|
+
text: string;
|
|
54
|
+
}[];
|
|
43
55
|
};
|
|
44
56
|
}, {
|
|
45
57
|
type: "textWithButtons";
|
|
46
58
|
content: {
|
|
47
59
|
text: string;
|
|
48
|
-
buttons:
|
|
60
|
+
buttons: {
|
|
61
|
+
text: string;
|
|
62
|
+
}[];
|
|
49
63
|
};
|
|
50
64
|
}>, z.ZodObject<{
|
|
51
65
|
type: z.ZodEnum<["carousel"]>;
|
|
@@ -56,13 +70,13 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
56
70
|
image: z.ZodString;
|
|
57
71
|
button: z.ZodObject<{
|
|
58
72
|
text: z.ZodString;
|
|
59
|
-
url: z.ZodString
|
|
73
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
60
74
|
}, "strip", z.ZodTypeAny, {
|
|
61
75
|
text: string;
|
|
62
|
-
url
|
|
76
|
+
url?: string | null | undefined;
|
|
63
77
|
}, {
|
|
64
78
|
text: string;
|
|
65
|
-
url
|
|
79
|
+
url?: string | null | undefined;
|
|
66
80
|
}>;
|
|
67
81
|
}, "strip", z.ZodTypeAny, {
|
|
68
82
|
title: string;
|
|
@@ -70,7 +84,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
70
84
|
image: string;
|
|
71
85
|
button: {
|
|
72
86
|
text: string;
|
|
73
|
-
url
|
|
87
|
+
url?: string | null | undefined;
|
|
74
88
|
};
|
|
75
89
|
}, {
|
|
76
90
|
title: string;
|
|
@@ -78,7 +92,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
78
92
|
image: string;
|
|
79
93
|
button: {
|
|
80
94
|
text: string;
|
|
81
|
-
url
|
|
95
|
+
url?: string | null | undefined;
|
|
82
96
|
};
|
|
83
97
|
}>, "many">;
|
|
84
98
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -88,7 +102,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
88
102
|
image: string;
|
|
89
103
|
button: {
|
|
90
104
|
text: string;
|
|
91
|
-
url
|
|
105
|
+
url?: string | null | undefined;
|
|
92
106
|
};
|
|
93
107
|
}[];
|
|
94
108
|
}, {
|
|
@@ -98,7 +112,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
98
112
|
image: string;
|
|
99
113
|
button: {
|
|
100
114
|
text: string;
|
|
101
|
-
url
|
|
115
|
+
url?: string | null | undefined;
|
|
102
116
|
};
|
|
103
117
|
}[];
|
|
104
118
|
}>;
|
|
@@ -111,7 +125,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
111
125
|
image: string;
|
|
112
126
|
button: {
|
|
113
127
|
text: string;
|
|
114
|
-
url
|
|
128
|
+
url?: string | null | undefined;
|
|
115
129
|
};
|
|
116
130
|
}[];
|
|
117
131
|
};
|
|
@@ -124,7 +138,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
124
138
|
image: string;
|
|
125
139
|
button: {
|
|
126
140
|
text: string;
|
|
127
|
-
url
|
|
141
|
+
url?: string | null | undefined;
|
|
128
142
|
};
|
|
129
143
|
}[];
|
|
130
144
|
};
|
|
@@ -145,7 +159,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
145
159
|
image: string;
|
|
146
160
|
button: {
|
|
147
161
|
text: string;
|
|
148
|
-
url
|
|
162
|
+
url?: string | null | undefined;
|
|
149
163
|
};
|
|
150
164
|
}[];
|
|
151
165
|
};
|
|
@@ -160,7 +174,9 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
160
174
|
type: "textWithButtons";
|
|
161
175
|
content: {
|
|
162
176
|
text: string;
|
|
163
|
-
buttons:
|
|
177
|
+
buttons: {
|
|
178
|
+
text: string;
|
|
179
|
+
}[];
|
|
164
180
|
};
|
|
165
181
|
})[];
|
|
166
182
|
}, {
|
|
@@ -173,7 +189,7 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
173
189
|
image: string;
|
|
174
190
|
button: {
|
|
175
191
|
text: string;
|
|
176
|
-
url
|
|
192
|
+
url?: string | null | undefined;
|
|
177
193
|
};
|
|
178
194
|
}[];
|
|
179
195
|
};
|
|
@@ -188,7 +204,9 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
188
204
|
type: "textWithButtons";
|
|
189
205
|
content: {
|
|
190
206
|
text: string;
|
|
191
|
-
buttons:
|
|
207
|
+
buttons: {
|
|
208
|
+
text: string;
|
|
209
|
+
}[];
|
|
192
210
|
};
|
|
193
211
|
})[];
|
|
194
212
|
}>;
|
|
@@ -5,24 +5,38 @@ export declare const TextWithButtonsSchema: z.ZodObject<{
|
|
|
5
5
|
type: z.ZodEnum<["textWithButtons"]>;
|
|
6
6
|
content: z.ZodObject<{
|
|
7
7
|
text: z.ZodString;
|
|
8
|
-
buttons: z.ZodArray<z.
|
|
8
|
+
buttons: z.ZodArray<z.ZodObject<{
|
|
9
|
+
text: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
text: string;
|
|
12
|
+
}, {
|
|
13
|
+
text: string;
|
|
14
|
+
}>, "many">;
|
|
9
15
|
}, "strip", z.ZodTypeAny, {
|
|
10
16
|
text: string;
|
|
11
|
-
buttons:
|
|
17
|
+
buttons: {
|
|
18
|
+
text: string;
|
|
19
|
+
}[];
|
|
12
20
|
}, {
|
|
13
21
|
text: string;
|
|
14
|
-
buttons:
|
|
22
|
+
buttons: {
|
|
23
|
+
text: string;
|
|
24
|
+
}[];
|
|
15
25
|
}>;
|
|
16
26
|
}, "strip", z.ZodTypeAny, {
|
|
17
27
|
type: "textWithButtons";
|
|
18
28
|
content: {
|
|
19
29
|
text: string;
|
|
20
|
-
buttons:
|
|
30
|
+
buttons: {
|
|
31
|
+
text: string;
|
|
32
|
+
}[];
|
|
21
33
|
};
|
|
22
34
|
}, {
|
|
23
35
|
type: "textWithButtons";
|
|
24
36
|
content: {
|
|
25
37
|
text: string;
|
|
26
|
-
buttons:
|
|
38
|
+
buttons: {
|
|
39
|
+
text: string;
|
|
40
|
+
}[];
|
|
27
41
|
};
|
|
28
42
|
}>;
|
|
@@ -4,7 +4,9 @@ export const TextWithButtonsSchema = z
|
|
|
4
4
|
type: z.enum(['textWithButtons']),
|
|
5
5
|
content: z.object({
|
|
6
6
|
text: z.string(),
|
|
7
|
-
buttons: z.array(z.
|
|
7
|
+
buttons: z.array(z.object({
|
|
8
|
+
text: z.string(),
|
|
9
|
+
})),
|
|
8
10
|
}),
|
|
9
11
|
})
|
|
10
12
|
.describe('A text message with buttons to allow the user to use quick replies');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,KAAK,CAAA;AAInB,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;
|
|
1
|
+
{"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../src/structured-output/text-with-buttons.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,KAAK,CAAA;AAInB,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,CACd,CAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;SACjB,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CACP,oEAAoE,CACrE,CAAA"}
|
package/lib/esm/tools/index.d.ts
CHANGED
package/lib/esm/tools/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAExD,MAAM,CAAC,MAAM,cAAc,GAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { tool } from '@openai/agents';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { HubtypeApiClient } from '../hubtype-api-client';
|
|
5
|
+
export const retrieveKnowledge = tool({
|
|
6
|
+
name: 'retrieve_knowledge',
|
|
7
|
+
description: 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
|
|
8
|
+
parameters: z.object({
|
|
9
|
+
query: z.string().describe('The query to search the knowledge base for'),
|
|
10
|
+
}),
|
|
11
|
+
execute: ({ query }, runContext) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const context = runContext === null || runContext === void 0 ? void 0 : runContext.context;
|
|
13
|
+
if (!context) {
|
|
14
|
+
throw new Error('Context is required');
|
|
15
|
+
}
|
|
16
|
+
const sources = context.sources;
|
|
17
|
+
const client = new HubtypeApiClient(context.authToken);
|
|
18
|
+
const chunks = yield client.retrieveSimilarChunks(query, sources);
|
|
19
|
+
return chunks;
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=retrieve-knowledge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":";AAAA,OAAO,EAAc,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAoB;IACvD,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EACT,kIAAkI;IACpI,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC;QACnB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;KACzE,CAAC;IACF,OAAO,EAAE,CACP,EAAE,KAAK,EAAqB,EAC5B,UAAgC,EACb,EAAE;QACrB,MAAM,OAAO,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAA;QACnC,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;SACvC;QACD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC/B,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACtD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACjE,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;CACF,CAAC,CAAA"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AgenticOutputMessage, InferenceResponse, RunResult } from '@botonic/core';
|
|
1
|
+
import { AgenticOutputMessage, AiAgentArgs, GuardrailRule, InferenceResponse, RunResult } from '@botonic/core';
|
|
2
2
|
import { Agent, AgentInputItem, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
4
|
import { OutputSchema } from './structured-output';
|
|
5
5
|
export interface Context {
|
|
6
6
|
authToken: string;
|
|
7
|
+
sources: string[];
|
|
7
8
|
}
|
|
8
9
|
export type RunContext = OpenAIRunContext<Context>;
|
|
9
10
|
export interface CustomTool {
|
|
@@ -12,10 +13,6 @@ export interface CustomTool {
|
|
|
12
13
|
schema: ZodSchema;
|
|
13
14
|
func: (input?: any, runContext?: RunContext) => Promise<any>;
|
|
14
15
|
}
|
|
15
|
-
export interface GuardrailRule {
|
|
16
|
-
name: string;
|
|
17
|
-
description: string;
|
|
18
|
-
}
|
|
19
16
|
export type ContactInfo = Record<string, string>;
|
|
20
17
|
export type Tool = OpenAITool<Context>;
|
|
21
18
|
export type AIAgent = Agent<Context, typeof OutputSchema>;
|
|
@@ -23,13 +20,5 @@ export interface PluginAiAgentOptions {
|
|
|
23
20
|
authToken?: string;
|
|
24
21
|
customTools?: CustomTool[];
|
|
25
22
|
}
|
|
26
|
-
export interface AiAgentArgs {
|
|
27
|
-
name: string;
|
|
28
|
-
instructions: string;
|
|
29
|
-
activeTools?: {
|
|
30
|
-
name: string;
|
|
31
|
-
}[];
|
|
32
|
-
inputGuardrailRules?: GuardrailRule[];
|
|
33
|
-
}
|
|
34
23
|
export type AgenticInputMessage = AgentInputItem;
|
|
35
|
-
export
|
|
24
|
+
export { AgenticOutputMessage, AiAgentArgs, GuardrailRule, InferenceResponse, RunResult, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-ai-agents",
|
|
3
|
-
"version": "0.40.0
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use AI Agents to generate your contents",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@botonic/core": "0.40.0
|
|
16
|
+
"@botonic/core": "^0.40.0",
|
|
17
17
|
"@openai/agents": "^0.0.10",
|
|
18
18
|
"axios": "^1.10.0",
|
|
19
19
|
"openai": "^5.8.3",
|
|
@@ -45,4 +45,4 @@
|
|
|
45
45
|
"javascript"
|
|
46
46
|
],
|
|
47
47
|
"author": ""
|
|
48
|
-
}
|
|
48
|
+
}
|
package/src/agent-builder.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Agent, InputGuardrail } from '@openai/agents'
|
|
1
|
+
import { Agent, InputGuardrail, ModelSettings } from '@openai/agents'
|
|
2
2
|
|
|
3
3
|
import { createInputGuardrail } from './guardrails'
|
|
4
4
|
import { OutputSchema } from './structured-output'
|
|
5
|
-
import { mandatoryTools } from './tools'
|
|
5
|
+
import { mandatoryTools, retrieveKnowledge } from './tools'
|
|
6
6
|
import { AIAgent, ContactInfo, GuardrailRule, Tool } from './types'
|
|
7
7
|
|
|
8
8
|
export class AIAgentBuilder {
|
|
@@ -16,11 +16,12 @@ export class AIAgentBuilder {
|
|
|
16
16
|
instructions: string,
|
|
17
17
|
tools: Tool[],
|
|
18
18
|
contactInfo: ContactInfo,
|
|
19
|
-
inputGuardrailRules: GuardrailRule[]
|
|
19
|
+
inputGuardrailRules: GuardrailRule[],
|
|
20
|
+
sourceIds: string[]
|
|
20
21
|
) {
|
|
21
22
|
this.name = name
|
|
22
23
|
this.instructions = this.addExtraInstructions(instructions, contactInfo)
|
|
23
|
-
this.tools = this.addHubtypeTools(tools)
|
|
24
|
+
this.tools = this.addHubtypeTools(tools, sourceIds)
|
|
24
25
|
this.inputGuardrails = []
|
|
25
26
|
if (inputGuardrailRules.length > 0) {
|
|
26
27
|
const inputGuardrail = createInputGuardrail(inputGuardrailRules)
|
|
@@ -29,6 +30,12 @@ export class AIAgentBuilder {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
build(): AIAgent {
|
|
33
|
+
const modelSettings: ModelSettings = {}
|
|
34
|
+
|
|
35
|
+
if (this.tools.includes(retrieveKnowledge)) {
|
|
36
|
+
modelSettings.toolChoice = retrieveKnowledge.name
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
return new Agent({
|
|
33
40
|
name: this.name,
|
|
34
41
|
instructions: this.instructions,
|
|
@@ -36,6 +43,7 @@ export class AIAgentBuilder {
|
|
|
36
43
|
outputType: OutputSchema,
|
|
37
44
|
inputGuardrails: this.inputGuardrails,
|
|
38
45
|
outputGuardrails: [],
|
|
46
|
+
modelSettings,
|
|
39
47
|
})
|
|
40
48
|
}
|
|
41
49
|
|
|
@@ -77,8 +85,11 @@ export class AIAgentBuilder {
|
|
|
77
85
|
return `<output>\n${output}\n</output>`
|
|
78
86
|
}
|
|
79
87
|
|
|
80
|
-
private addHubtypeTools(tools: Tool[]): Tool[] {
|
|
88
|
+
private addHubtypeTools(tools: Tool[], sourceIds: string[]): Tool[] {
|
|
81
89
|
const hubtypeTools: Tool[] = [...mandatoryTools]
|
|
90
|
+
if (sourceIds.length > 0) {
|
|
91
|
+
hubtypeTools.push(retrieveKnowledge)
|
|
92
|
+
}
|
|
82
93
|
return [...hubtypeTools, ...tools]
|
|
83
94
|
}
|
|
84
95
|
}
|
|
@@ -24,10 +24,31 @@ export class HubtypeApiClient {
|
|
|
24
24
|
this.authToken = authToken
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
async retrieveSimilarChunks(
|
|
28
|
+
query: string,
|
|
29
|
+
sources: string[]
|
|
30
|
+
): Promise<string[]> {
|
|
31
|
+
const url = `${HUBTYPE_API_URL}/external/v1/ai/knowledge_base/similar_chunks/`
|
|
32
|
+
const headers = {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
35
|
+
}
|
|
36
|
+
const params = {
|
|
37
|
+
query,
|
|
38
|
+
source_ids: sources,
|
|
39
|
+
num_chunks: 5,
|
|
40
|
+
}
|
|
41
|
+
const response = await axios.post(url, params, { headers })
|
|
42
|
+
return response.data.chunks.map((chunk: any) => chunk.text)
|
|
43
|
+
}
|
|
44
|
+
|
|
27
45
|
async getLocalMessages(
|
|
28
46
|
maxMemoryLength: number
|
|
29
47
|
): Promise<AgenticInputMessage[]> {
|
|
30
|
-
const localBotonicState =
|
|
48
|
+
const localBotonicState =
|
|
49
|
+
typeof globalThis !== 'undefined' && globalThis.localStorage
|
|
50
|
+
? globalThis.localStorage.getItem('botonicState')
|
|
51
|
+
: null
|
|
31
52
|
const botonicState = JSON.parse(localBotonicState || '{}')
|
|
32
53
|
const messages = botonicState.messages
|
|
33
54
|
const filteredMessages = messages
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BotContext, Plugin } from '@botonic/core'
|
|
1
|
+
import { AiAgentArgs, BotContext, Plugin } from '@botonic/core'
|
|
2
2
|
import { tool } from '@openai/agents'
|
|
3
3
|
|
|
4
4
|
import { AIAgentBuilder } from './agent-builder'
|
|
@@ -8,7 +8,6 @@ import { setUpOpenAI } from './openai'
|
|
|
8
8
|
import { AIAgentRunner } from './runner'
|
|
9
9
|
import {
|
|
10
10
|
AgenticInputMessage,
|
|
11
|
-
AiAgentArgs,
|
|
12
11
|
Context,
|
|
13
12
|
CustomTool,
|
|
14
13
|
InferenceResponse,
|
|
@@ -48,7 +47,8 @@ export default class BotonicPluginAiAgents implements Plugin {
|
|
|
48
47
|
aiAgentArgs.instructions,
|
|
49
48
|
tools,
|
|
50
49
|
request.session.user.contact_info || {},
|
|
51
|
-
aiAgentArgs.inputGuardrailRules || []
|
|
50
|
+
aiAgentArgs.inputGuardrailRules || [],
|
|
51
|
+
aiAgentArgs.sourceIds || []
|
|
52
52
|
).build()
|
|
53
53
|
|
|
54
54
|
const messages = await this.getMessages(
|
|
@@ -58,6 +58,7 @@ export default class BotonicPluginAiAgents implements Plugin {
|
|
|
58
58
|
)
|
|
59
59
|
const context: Context = {
|
|
60
60
|
authToken,
|
|
61
|
+
sources: aiAgentArgs.sourceIds || [],
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
const runner = new AIAgentRunner(agent)
|
package/src/tools/index.ts
CHANGED