@botonic/plugin-ai-agents 0.36.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ import { BotContext } from '@botonic/core';
2
+ import { AiAgentArgs, AiAgentResponse } from './types';
3
+ export declare class AiAgentClient {
4
+ private url;
5
+ constructor();
6
+ getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<AiAgentResponse>;
7
+ private agentTestInference;
8
+ private agentInference;
9
+ private getConfig;
10
+ private getData;
11
+ private getDataTest;
12
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AiAgentClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /* eslint-disable @typescript-eslint/naming-convention */
6
+ const core_1 = require("@botonic/core");
7
+ const axios_1 = tslib_1.__importDefault(require("axios"));
8
+ const constants_1 = require("./constants");
9
+ const errors_1 = require("./errors");
10
+ class AiAgentClient {
11
+ constructor() {
12
+ this.url = `${constants_1.HUBTYPE_API_URL}/external/v1/ai/agent`;
13
+ }
14
+ getInference(request, aiAgentArgs) {
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ if ((0, core_1.isDev)(request.session)) {
17
+ return this.agentTestInference(request, aiAgentArgs);
18
+ }
19
+ return this.agentInference(request, aiAgentArgs);
20
+ });
21
+ }
22
+ agentTestInference(request, aiAgentArgs) {
23
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
24
+ const config = this.getConfig(request);
25
+ const data = this.getDataTest(request, aiAgentArgs);
26
+ const response = yield axios_1.default.post(`${this.url}/test/`, data, config);
27
+ return response.data;
28
+ });
29
+ }
30
+ agentInference(request, aiAgentArgs) {
31
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
32
+ const config = this.getConfig(request);
33
+ const data = this.getData(request, aiAgentArgs);
34
+ const response = yield axios_1.default.post(`${this.url}/run/`, data, config);
35
+ return response.data;
36
+ });
37
+ }
38
+ getConfig(request) {
39
+ return {
40
+ headers: {
41
+ Authorization: `Bearer ${request.session._access_token}`,
42
+ 'Content-Type': 'application/json',
43
+ },
44
+ };
45
+ }
46
+ getData(request, aiAgentArgs) {
47
+ if (!request.input.data) {
48
+ throw new errors_1.AiAgentError('No input data provided');
49
+ }
50
+ return {
51
+ message: request.input.message_id,
52
+ memory_length: 10,
53
+ name: aiAgentArgs.name,
54
+ instructions: aiAgentArgs.instructions,
55
+ };
56
+ }
57
+ getDataTest(request, aiAgentArgs) {
58
+ if (!request.input.data) {
59
+ throw new errors_1.AiAgentError('No input data provided');
60
+ }
61
+ // TODO: We can get messages from localStorage in Dev mode and transform them to the correct format {role: MessageRole, content: string}
62
+ // if (isDev(request.session)) {
63
+ // const messages = localStorage.getItem('botonicState').
64
+ // }
65
+ return {
66
+ messages: [
67
+ {
68
+ role: 'user',
69
+ content: request.input.data,
70
+ },
71
+ ],
72
+ name: aiAgentArgs.name,
73
+ instructions: aiAgentArgs.instructions,
74
+ };
75
+ }
76
+ }
77
+ exports.AiAgentClient = AiAgentClient;
78
+ //# sourceMappingURL=ai-agent-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-agent-client.js","sourceRoot":"","sources":["../../src/ai-agent-client.ts"],"names":[],"mappings":";;;;AAAA,yDAAyD;AACzD,wCAAiD;AACjD,0DAAyB;AAEzB,2CAA6C;AAC7C,qCAAuC;AASvC,MAAa,aAAa;IAGxB;QACE,IAAI,CAAC,GAAG,GAAG,GAAG,2BAAe,uBAAuB,CAAA;IACtD,CAAC;IAEK,YAAY,CAChB,OAAmB,EACnB,WAAwB;;YAExB,IAAI,IAAA,YAAK,EAAC,OAAO,CAAC,OAAO,CAAC,EAAE;gBAC1B,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;aACrD;YAED,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAClD,C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;IAEO,WAAW,CACjB,OAAmB,EACnB,WAAwB;QAExB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE;YACvB,MAAM,IAAI,qBAAY,CAAC,wBAAwB,CAAC,CAAA;SACjD;QAED,wIAAwI;QACxI,gCAAgC;QAChC,2DAA2D;QAC3D,IAAI;QAEJ,OAAO;YACL,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;iBAC5B;aACF;YACD,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,YAAY,EAAE,WAAW,CAAC,YAAY;SACvC,CAAA;IACH,CAAC;CACF;AAjGD,sCAiGC"}
@@ -0,0 +1 @@
1
+ export declare const HUBTYPE_API_URL: string;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HUBTYPE_API_URL = void 0;
4
+ exports.HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare class AiAgentError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AiAgentError = void 0;
4
+ class AiAgentError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'AiAgentError';
8
+ }
9
+ }
10
+ exports.AiAgentError = AiAgentError;
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;IAC5B,CAAC;CACF;AALD,oCAKC"}
@@ -0,0 +1,9 @@
1
+ import { BotContext, Plugin } from '@botonic/core';
2
+ import { AiAgentClient } from './ai-agent-client';
3
+ import { AiAgentArgs, AiAgentResponse } from './types';
4
+ export default class BotonicPluginAiAgents implements Plugin {
5
+ aiAgentClient: AiAgentClient;
6
+ constructor();
7
+ pre(): void;
8
+ getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<AiAgentResponse>;
9
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const ai_agent_client_1 = require("./ai-agent-client");
5
+ class BotonicPluginAiAgents {
6
+ constructor() {
7
+ this.aiAgentClient = new ai_agent_client_1.AiAgentClient();
8
+ }
9
+ pre() {
10
+ return;
11
+ }
12
+ getInference(request, aiAgentArgs) {
13
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
+ return this.aiAgentClient.getInference(request, aiAgentArgs);
15
+ });
16
+ }
17
+ }
18
+ exports.default = BotonicPluginAiAgents;
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAEA,uDAAiD;AAGjD,MAAqB,qBAAqB;IAGxC;QACE,IAAI,CAAC,aAAa,GAAG,IAAI,+BAAa,EAAE,CAAA;IAC1C,CAAC;IAED,GAAG;QACD,OAAM;IACR,CAAC;IAEK,YAAY,CAChB,OAAmB,EACnB,WAAwB;;YAExB,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAC9D,CAAC;KAAA;CACF;AAjBD,wCAiBC"}
@@ -0,0 +1,31 @@
1
+ export interface AiAgentArgs {
2
+ name: string;
3
+ instructions: string;
4
+ }
5
+ export interface Config {
6
+ headers: {
7
+ Authorization: string;
8
+ 'Content-Type': string;
9
+ };
10
+ }
11
+ export interface AiAgentRequestDataTest {
12
+ messages: {
13
+ role: MessageRole;
14
+ content: string;
15
+ }[];
16
+ name: string;
17
+ instructions: string;
18
+ }
19
+ export type MessageRole = 'user' | 'assistant';
20
+ export interface AiAgentRequestData {
21
+ message: string;
22
+ memory_length: number;
23
+ name: string;
24
+ instructions: string;
25
+ }
26
+ export interface AiAgentResponse {
27
+ message: {
28
+ role: string;
29
+ content: string;
30
+ };
31
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import { BotContext } from '@botonic/core';
2
+ import { AiAgentArgs, AiAgentResponse } from './types';
3
+ export declare class AiAgentClient {
4
+ private url;
5
+ constructor();
6
+ getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<AiAgentResponse>;
7
+ private agentTestInference;
8
+ private agentInference;
9
+ private getConfig;
10
+ private getData;
11
+ private getDataTest;
12
+ }
@@ -0,0 +1,74 @@
1
+ import { __awaiter } from "tslib";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ import { isDev } from '@botonic/core';
4
+ import axios from 'axios';
5
+ import { HUBTYPE_API_URL } from './constants';
6
+ import { AiAgentError } from './errors';
7
+ export class AiAgentClient {
8
+ constructor() {
9
+ this.url = `${HUBTYPE_API_URL}/external/v1/ai/agent`;
10
+ }
11
+ getInference(request, aiAgentArgs) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ if (isDev(request.session)) {
14
+ return this.agentTestInference(request, aiAgentArgs);
15
+ }
16
+ return this.agentInference(request, aiAgentArgs);
17
+ });
18
+ }
19
+ agentTestInference(request, aiAgentArgs) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const config = this.getConfig(request);
22
+ const data = this.getDataTest(request, aiAgentArgs);
23
+ const response = yield axios.post(`${this.url}/test/`, data, config);
24
+ return response.data;
25
+ });
26
+ }
27
+ agentInference(request, aiAgentArgs) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const config = this.getConfig(request);
30
+ const data = this.getData(request, aiAgentArgs);
31
+ const response = yield axios.post(`${this.url}/run/`, data, config);
32
+ return response.data;
33
+ });
34
+ }
35
+ getConfig(request) {
36
+ return {
37
+ headers: {
38
+ Authorization: `Bearer ${request.session._access_token}`,
39
+ 'Content-Type': 'application/json',
40
+ },
41
+ };
42
+ }
43
+ getData(request, aiAgentArgs) {
44
+ if (!request.input.data) {
45
+ throw new AiAgentError('No input data provided');
46
+ }
47
+ return {
48
+ message: request.input.message_id,
49
+ memory_length: 10,
50
+ name: aiAgentArgs.name,
51
+ instructions: aiAgentArgs.instructions,
52
+ };
53
+ }
54
+ getDataTest(request, aiAgentArgs) {
55
+ if (!request.input.data) {
56
+ throw new AiAgentError('No input data provided');
57
+ }
58
+ // TODO: We can get messages from localStorage in Dev mode and transform them to the correct format {role: MessageRole, content: string}
59
+ // if (isDev(request.session)) {
60
+ // const messages = localStorage.getItem('botonicState').
61
+ // }
62
+ return {
63
+ messages: [
64
+ {
65
+ role: 'user',
66
+ content: request.input.data,
67
+ },
68
+ ],
69
+ name: aiAgentArgs.name,
70
+ instructions: aiAgentArgs.instructions,
71
+ };
72
+ }
73
+ }
74
+ //# sourceMappingURL=ai-agent-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-agent-client.js","sourceRoot":"","sources":["../../src/ai-agent-client.ts"],"names":[],"mappings":";AAAA,yDAAyD;AACzD,OAAO,EAAc,KAAK,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA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a,EAAE;gBACxD,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAA;IACH,CAAC;IAEO,OAAO,CACb,OAAmB,EACnB,WAAwB;QAExB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE;YACvB,MAAM,IAAI,YAAY,CAAC,wBAAwB,CAAC,CAAA;SACjD;QAED,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;YACjC,aAAa,EAAE,EAAE;YACjB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,YAAY,EAAE,WAAW,CAAC,YAAY;SACvC,CAAA;IACH,CAAC;IAEO,WAAW,CACjB,OAAmB,EACnB,WAAwB;QAExB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE;YACvB,MAAM,IAAI,YAAY,CAAC,wBAAwB,CAAC,CAAA;SACjD;QAED,wIAAwI;QACxI,gCAAgC;QAChC,2DAA2D;QAC3D,IAAI;QAEJ,OAAO;YACL,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;iBAC5B;aACF;YACD,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,YAAY,EAAE,WAAW,CAAC,YAAY;SACvC,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1 @@
1
+ export declare const HUBTYPE_API_URL: string;
@@ -0,0 +1,2 @@
1
+ export const HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
2
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ export declare class AiAgentError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,7 @@
1
+ export class AiAgentError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = 'AiAgentError';
5
+ }
6
+ }
7
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;IAC5B,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { BotContext, Plugin } from '@botonic/core';
2
+ import { AiAgentClient } from './ai-agent-client';
3
+ import { AiAgentArgs, AiAgentResponse } from './types';
4
+ export default class BotonicPluginAiAgents implements Plugin {
5
+ aiAgentClient: AiAgentClient;
6
+ constructor();
7
+ pre(): void;
8
+ getInference(request: BotContext, aiAgentArgs: AiAgentArgs): Promise<AiAgentResponse>;
9
+ }
@@ -0,0 +1,16 @@
1
+ import { __awaiter } from "tslib";
2
+ import { AiAgentClient } from './ai-agent-client';
3
+ export default class BotonicPluginAiAgents {
4
+ constructor() {
5
+ this.aiAgentClient = new AiAgentClient();
6
+ }
7
+ pre() {
8
+ return;
9
+ }
10
+ getInference(request, aiAgentArgs) {
11
+ return __awaiter(this, void 0, void 0, function* () {
12
+ return this.aiAgentClient.getInference(request, aiAgentArgs);
13
+ });
14
+ }
15
+ }
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,MAAM,CAAC,OAAO,OAAO,qBAAqB;IAGxC;QACE,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;IAC1C,CAAC;IAED,GAAG;QACD,OAAM;IACR,CAAC;IAEK,YAAY,CAChB,OAAmB,EACnB,WAAwB;;YAExB,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAC9D,CAAC;KAAA;CACF"}
@@ -0,0 +1,31 @@
1
+ export interface AiAgentArgs {
2
+ name: string;
3
+ instructions: string;
4
+ }
5
+ export interface Config {
6
+ headers: {
7
+ Authorization: string;
8
+ 'Content-Type': string;
9
+ };
10
+ }
11
+ export interface AiAgentRequestDataTest {
12
+ messages: {
13
+ role: MessageRole;
14
+ content: string;
15
+ }[];
16
+ name: string;
17
+ instructions: string;
18
+ }
19
+ export type MessageRole = 'user' | 'assistant';
20
+ export interface AiAgentRequestData {
21
+ message: string;
22
+ memory_length: number;
23
+ name: string;
24
+ instructions: string;
25
+ }
26
+ export interface AiAgentResponse {
27
+ message: {
28
+ role: string;
29
+ content: string;
30
+ };
31
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@botonic/plugin-ai-agents",
3
+ "version": "0.36.0-alpha.0",
4
+ "main": "./lib/cjs/index.js",
5
+ "module": "./lib/esm/index.js",
6
+ "description": "Use AI Agents to generate your contents",
7
+ "scripts": {
8
+ "build": "rm -rf lib && ../../node_modules/.bin/tsc -p tsconfig.json && ../../node_modules/.bin/tsc -p tsconfig.esm.json",
9
+ "build:watch": "npm run build -- --watch",
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "prepublishOnly": "rm -rf lib && npm i && npm run build",
12
+ "lint": "npm run lint_core -- --fix",
13
+ "lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
14
+ },
15
+ "dependencies": {
16
+ "@botonic/core": "^0.35.0",
17
+ "axios": "^1.9.0",
18
+ "uuid": "^10.0.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/uuid": "^10.0.0"
22
+ },
23
+ "files": [
24
+ "lib/**",
25
+ "src/**",
26
+ "README.md"
27
+ ],
28
+ "engines": {
29
+ "node": ">=20.0.0",
30
+ "npm": ">=10.0.0"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/hubtype/botonic.git"
35
+ },
36
+ "keywords": [
37
+ "bot-framework",
38
+ "chatbot",
39
+ "ai-agents",
40
+ "conversational-app",
41
+ "typescript",
42
+ "javascript"
43
+ ],
44
+ "author": ""
45
+ }
@@ -0,0 +1,112 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { BotContext, isDev } from '@botonic/core'
3
+ import axios from 'axios'
4
+
5
+ import { HUBTYPE_API_URL } from './constants'
6
+ import { AiAgentError } from './errors'
7
+ import {
8
+ AiAgentArgs,
9
+ AiAgentRequestData,
10
+ AiAgentRequestDataTest,
11
+ AiAgentResponse,
12
+ Config,
13
+ } from './types'
14
+
15
+ export class AiAgentClient {
16
+ private url: string
17
+
18
+ constructor() {
19
+ this.url = `${HUBTYPE_API_URL}/external/v1/ai/agent`
20
+ }
21
+
22
+ async getInference(
23
+ request: BotContext,
24
+ aiAgentArgs: AiAgentArgs
25
+ ): Promise<AiAgentResponse> {
26
+ if (isDev(request.session)) {
27
+ return this.agentTestInference(request, aiAgentArgs)
28
+ }
29
+
30
+ return this.agentInference(request, aiAgentArgs)
31
+ }
32
+
33
+ private async agentTestInference(
34
+ request: BotContext,
35
+ aiAgentArgs: AiAgentArgs
36
+ ): Promise<AiAgentResponse> {
37
+ const config = this.getConfig(request)
38
+ const data = this.getDataTest(request, aiAgentArgs)
39
+ const response = await axios.post<AiAgentResponse>(
40
+ `${this.url}/test/`,
41
+ data,
42
+ config
43
+ )
44
+
45
+ return response.data
46
+ }
47
+
48
+ private async agentInference(
49
+ request: BotContext,
50
+ aiAgentArgs: AiAgentArgs
51
+ ): Promise<AiAgentResponse> {
52
+ const config = this.getConfig(request)
53
+ const data = this.getData(request, aiAgentArgs)
54
+ const response = await axios.post<AiAgentResponse>(
55
+ `${this.url}/run/`,
56
+ data,
57
+ config
58
+ )
59
+
60
+ return response.data
61
+ }
62
+
63
+ private getConfig(request: BotContext): Config {
64
+ return {
65
+ headers: {
66
+ Authorization: `Bearer ${request.session._access_token}`,
67
+ 'Content-Type': 'application/json',
68
+ },
69
+ }
70
+ }
71
+
72
+ private getData(
73
+ request: BotContext,
74
+ aiAgentArgs: AiAgentArgs
75
+ ): AiAgentRequestData {
76
+ if (!request.input.data) {
77
+ throw new AiAgentError('No input data provided')
78
+ }
79
+
80
+ return {
81
+ message: request.input.message_id,
82
+ memory_length: 10,
83
+ name: aiAgentArgs.name,
84
+ instructions: aiAgentArgs.instructions,
85
+ }
86
+ }
87
+
88
+ private getDataTest(
89
+ request: BotContext,
90
+ aiAgentArgs: AiAgentArgs
91
+ ): AiAgentRequestDataTest {
92
+ if (!request.input.data) {
93
+ throw new AiAgentError('No input data provided')
94
+ }
95
+
96
+ // TODO: We can get messages from localStorage in Dev mode and transform them to the correct format {role: MessageRole, content: string}
97
+ // if (isDev(request.session)) {
98
+ // const messages = localStorage.getItem('botonicState').
99
+ // }
100
+
101
+ return {
102
+ messages: [
103
+ {
104
+ role: 'user',
105
+ content: request.input.data,
106
+ },
107
+ ],
108
+ name: aiAgentArgs.name,
109
+ instructions: aiAgentArgs.instructions,
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,2 @@
1
+ export const HUBTYPE_API_URL =
2
+ process.env.HUBTYPE_API_URL || 'https://api.hubtype.com'
package/src/errors.ts ADDED
@@ -0,0 +1,6 @@
1
+ export class AiAgentError extends Error {
2
+ constructor(message: string) {
3
+ super(message)
4
+ this.name = 'AiAgentError'
5
+ }
6
+ }
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { BotContext, Plugin } from '@botonic/core'
2
+
3
+ import { AiAgentClient } from './ai-agent-client'
4
+ import { AiAgentArgs, AiAgentResponse } from './types'
5
+
6
+ export default class BotonicPluginAiAgents implements Plugin {
7
+ public aiAgentClient: AiAgentClient
8
+
9
+ constructor() {
10
+ this.aiAgentClient = new AiAgentClient()
11
+ }
12
+
13
+ pre(): void {
14
+ return
15
+ }
16
+
17
+ async getInference(
18
+ request: BotContext,
19
+ aiAgentArgs: AiAgentArgs
20
+ ): Promise<AiAgentResponse> {
21
+ return this.aiAgentClient.getInference(request, aiAgentArgs)
22
+ }
23
+ }
package/src/types.ts ADDED
@@ -0,0 +1,33 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ export interface AiAgentArgs {
3
+ name: string
4
+ instructions: string
5
+ }
6
+ export interface Config {
7
+ headers: {
8
+ Authorization: string
9
+ 'Content-Type': string
10
+ }
11
+ }
12
+
13
+ export interface AiAgentRequestDataTest {
14
+ messages: {
15
+ role: MessageRole
16
+ content: string
17
+ }[]
18
+ name: string
19
+ instructions: string
20
+ }
21
+
22
+ export type MessageRole = 'user' | 'assistant'
23
+
24
+ export interface AiAgentRequestData {
25
+ message: string
26
+ memory_length: number
27
+ name: string
28
+ instructions: string
29
+ }
30
+
31
+ export interface AiAgentResponse {
32
+ message: { role: string; content: string }
33
+ }