@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.
- package/README.md +14 -0
- package/lib/cjs/agent-builder.d.ts +10 -0
- package/lib/cjs/agent-builder.js +43 -0
- package/lib/cjs/agent-builder.js.map +1 -0
- package/lib/cjs/constants.d.ts +3 -2
- package/lib/cjs/constants.js +5 -4
- package/lib/cjs/constants.js.map +1 -1
- package/lib/{esm/hubtype-client.d.ts → cjs/hubtype-api-client.d.ts} +3 -1
- package/lib/cjs/hubtype-api-client.js +76 -0
- package/lib/cjs/hubtype-api-client.js.map +1 -0
- package/lib/cjs/index.d.ts +5 -2
- package/lib/cjs/index.js +40 -17
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/openai.d.ts +1 -0
- package/lib/cjs/openai.js +23 -0
- package/lib/cjs/openai.js.map +1 -0
- package/lib/cjs/runner.d.ts +7 -0
- package/lib/cjs/runner.js +35 -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/tools/index.d.ts +2 -0
- package/lib/cjs/tools/index.js +5 -0
- package/lib/cjs/tools/index.js.map +1 -0
- package/lib/cjs/types.d.ts +20 -22
- package/lib/esm/agent-builder.d.ts +10 -0
- package/lib/esm/agent-builder.js +39 -0
- package/lib/esm/agent-builder.js.map +1 -0
- package/lib/esm/constants.d.ts +3 -2
- package/lib/esm/constants.js +4 -3
- package/lib/esm/constants.js.map +1 -1
- package/lib/{cjs/hubtype-client.d.ts → esm/hubtype-api-client.d.ts} +3 -1
- package/lib/esm/hubtype-api-client.js +72 -0
- package/lib/esm/hubtype-api-client.js.map +1 -0
- package/lib/esm/index.d.ts +5 -2
- package/lib/esm/index.js +39 -16
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/openai.d.ts +1 -0
- package/lib/esm/openai.js +19 -0
- package/lib/esm/openai.js.map +1 -0
- package/lib/esm/runner.d.ts +7 -0
- package/lib/esm/runner.js +31 -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/tools/index.d.ts +2 -0
- package/lib/esm/tools/index.js +2 -0
- package/lib/esm/tools/index.js.map +1 -0
- package/lib/esm/types.d.ts +20 -22
- package/package.json +7 -7
- package/src/agent-builder.ts +48 -0
- package/src/constants.ts +7 -4
- package/src/hubtype-api-client.ts +89 -0
- package/src/index.ts +56 -19
- package/src/openai.ts +30 -0
- package/src/runner.ts +43 -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/tools/index.ts +3 -0
- package/src/types.ts +27 -29
- package/lib/cjs/ai-agent-client.d.ts +0 -11
- package/lib/cjs/ai-agent-client.js +0 -50
- 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/hubtype-client.js +0 -36
- package/lib/cjs/hubtype-client.js.map +0 -1
- package/lib/cjs/tools.d.ts +0 -6
- package/lib/cjs/tools.js +0 -41
- package/lib/cjs/tools.js.map +0 -1
- package/lib/cjs/utils.d.ts +0 -2
- package/lib/cjs/utils.js +0 -22
- package/lib/cjs/utils.js.map +0 -1
- package/lib/esm/ai-agent-client.d.ts +0 -11
- package/lib/esm/ai-agent-client.js +0 -46
- 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/hubtype-client.js +0 -32
- package/lib/esm/hubtype-client.js.map +0 -1
- package/lib/esm/tools.d.ts +0 -6
- package/lib/esm/tools.js +0 -38
- package/lib/esm/tools.js.map +0 -1
- package/lib/esm/utils.d.ts +0 -2
- package/lib/esm/utils.js +0 -18
- package/lib/esm/utils.js.map +0 -1
- package/src/ai-agent-client.ts +0 -73
- package/src/errors.ts +0 -6
- package/src/hubtype-client.ts +0 -43
- package/src/tools.ts +0 -51
- package/src/utils.ts +0 -24
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AiAgentClient = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const messages_1 = require("@langchain/core/messages");
|
|
6
|
-
const prebuilt_1 = require("@langchain/langgraph/prebuilt");
|
|
7
|
-
const tools_1 = require("./tools");
|
|
8
|
-
class AiAgentClient {
|
|
9
|
-
constructor(aiAgentArgs, chatModel, tools = []) {
|
|
10
|
-
this.name = aiAgentArgs.name;
|
|
11
|
-
this.instructions = aiAgentArgs.instructions;
|
|
12
|
-
this.agent = (0, prebuilt_1.createReactAgent)({
|
|
13
|
-
llm: chatModel,
|
|
14
|
-
tools: tools,
|
|
15
|
-
prompt: this.instructions,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
runAgent(_messages) {
|
|
19
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const response = yield this.agent.invoke({
|
|
21
|
-
messages: _messages.map((message) => ({
|
|
22
|
-
role: message.role,
|
|
23
|
-
content: message.content,
|
|
24
|
-
})),
|
|
25
|
-
});
|
|
26
|
-
const lastMessage = response.messages.at(-1);
|
|
27
|
-
if (lastMessage instanceof messages_1.ToolMessage) {
|
|
28
|
-
if (lastMessage.name && tools_1.EXIT_TOOLS.includes(lastMessage.name)) {
|
|
29
|
-
return {
|
|
30
|
-
role: 'exit',
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
role: 'tool',
|
|
35
|
-
toolName: lastMessage.name,
|
|
36
|
-
toolOutput: lastMessage.content,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (lastMessage instanceof messages_1.AIMessage) {
|
|
40
|
-
return {
|
|
41
|
-
role: 'assistant',
|
|
42
|
-
content: lastMessage.content,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
throw new Error('Last message is not a valid message');
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.AiAgentClient = AiAgentClient;
|
|
50
|
-
//# sourceMappingURL=ai-agent-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ai-agent-client.js","sourceRoot":"","sources":["../../src/ai-agent-client.ts"],"names":[],"mappings":";;;;AACA,uDAGiC;AAGjC,4DAAgE;AAEhE,mCAAoC;AAUpC,MAAa,aAAa;IAKxB,YACE,WAAwB,EACxB,SAAwB,EACxB,QAA0B,EAAE;QAE5B,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAA;QAC5B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC,YAAY,CAAA;QAE5C,IAAI,CAAC,KAAK,GAAG,IAAA,2BAAgB,EAAC;YAC5B,GAAG,EAAE,SAAS;YACd,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,IAAI,CAAC,YAAY;SAC1B,CAAC,CAAA;IACJ,CAAC;IAEK,QAAQ,CACZ,SAAgC;;YAEhC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;gBACvC,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,OAA4B,EAAE,EAAE,CAAC,CAAC;oBACzD,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,OAAO,EAAE,OAAO,CAAC,OAAO;iBACzB,CAAC,CAAC;aACJ,CAAC,CAAA;YACF,MAAM,WAAW,GAAG,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;YAE5C,IAAI,WAAW,YAAY,sBAAoB,EAAE;gBAC/C,IAAI,WAAW,CAAC,IAAI,IAAI,kBAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;oBAC7D,OAAO;wBACL,IAAI,EAAE,MAAM;qBACE,CAAA;iBACjB;gBACD,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,WAAW,CAAC,IAAI;oBAC1B,UAAU,EAAE,WAAW,CAAC,OAAO;iBACjB,CAAA;aACjB;YAED,IAAI,WAAW,YAAY,oBAAkB,EAAE;gBAC7C,OAAO;oBACL,IAAI,EAAE,WAAW;oBACjB,OAAO,EAAE,WAAW,CAAC,OAAO;iBACT,CAAA;aACtB;YAED,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;KAAA;CACF;AArDD,sCAqDC"}
|
package/lib/cjs/errors.d.ts
DELETED
package/lib/cjs/errors.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
package/lib/cjs/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HubtypeClient = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
-
const constants_1 = require("./constants");
|
|
7
|
-
class HubtypeClient {
|
|
8
|
-
constructor(authToken) {
|
|
9
|
-
this.authToken = authToken;
|
|
10
|
-
}
|
|
11
|
-
getMessages(request, memoryLength) {
|
|
12
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
const url = `${constants_1.HUBTYPE_API_URL}/external/v1/ai/agent/message_history/`;
|
|
14
|
-
const data = {
|
|
15
|
-
last_message_id: request.input.message_id,
|
|
16
|
-
num_messages: memoryLength,
|
|
17
|
-
};
|
|
18
|
-
const config = {
|
|
19
|
-
headers: {
|
|
20
|
-
'Content-Type': 'application/json',
|
|
21
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
try {
|
|
25
|
-
const messages = yield axios_1.default.post(url, data, config);
|
|
26
|
-
return messages.data.messages;
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error(error);
|
|
30
|
-
throw new Error('Failed to get messages from Hubtype');
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.HubtypeClient = HubtypeClient;
|
|
36
|
-
//# sourceMappingURL=hubtype-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-client.js","sourceRoot":"","sources":["../../src/hubtype-client.ts"],"names":[],"mappings":";;;;AACA,0DAAyB;AAEzB,2CAA6C;AAG7C,MAAa,aAAa;IAGxB,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAEK,WAAW,CACf,OAAmB,EACnB,YAAoB;;YAEpB,MAAM,GAAG,GAAG,GAAG,2BAAe,wCAAwC,CAAA;YACtE,MAAM,IAAI,GAAG;gBACX,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;gBACzC,YAAY,EAAE,YAAY;aAC3B,CAAA;YACD,MAAM,MAAM,GAAG;gBACb,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;iBAC1C;aACF,CAAA;YAED,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,GAAG,EACH,IAAI,EACJ,MAAM,CACP,CAAA;gBAED,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAA;aAC9B;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;gBACpB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;aACvD;QACH,CAAC;KAAA;CACF;AApCD,sCAoCC"}
|
package/lib/cjs/tools.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export declare const handoffToHumanAgent: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {}, {}, null>;
|
|
3
|
-
export declare const outOfContext: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {}, {}, null>;
|
|
4
|
-
export declare const finishConversation: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {}, {}, null>;
|
|
5
|
-
export declare const MANDATORY_TOOLS: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {}, {}, null>[];
|
|
6
|
-
export declare const EXIT_TOOLS: string[];
|
package/lib/cjs/tools.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EXIT_TOOLS = exports.MANDATORY_TOOLS = exports.finishConversation = exports.outOfContext = exports.handoffToHumanAgent = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const tools_1 = require("@langchain/core/tools");
|
|
6
|
-
const zod_1 = require("zod");
|
|
7
|
-
exports.handoffToHumanAgent = (0, tools_1.tool)(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
return null;
|
|
9
|
-
}), {
|
|
10
|
-
name: 'handoffToHumanAgent',
|
|
11
|
-
schema: zod_1.z.object({}),
|
|
12
|
-
description: 'Use this tool strictly when the user wants to talk with a human agent.',
|
|
13
|
-
returnDirect: true,
|
|
14
|
-
});
|
|
15
|
-
exports.outOfContext = (0, tools_1.tool)(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
return null;
|
|
17
|
-
}), {
|
|
18
|
-
name: 'outOfContext',
|
|
19
|
-
schema: zod_1.z.object({}),
|
|
20
|
-
description: 'Use this when the user talks about something that is clearly out of your context. Example: "I want to buy a car" when you are a travel agent.',
|
|
21
|
-
returnDirect: true,
|
|
22
|
-
});
|
|
23
|
-
exports.finishConversation = (0, tools_1.tool)(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
return null;
|
|
25
|
-
}), {
|
|
26
|
-
name: 'finishConversation',
|
|
27
|
-
schema: zod_1.z.object({}),
|
|
28
|
-
description: 'Use this when the user wants to end the conversation.',
|
|
29
|
-
returnDirect: true,
|
|
30
|
-
});
|
|
31
|
-
exports.MANDATORY_TOOLS = [
|
|
32
|
-
exports.handoffToHumanAgent,
|
|
33
|
-
exports.outOfContext,
|
|
34
|
-
exports.finishConversation,
|
|
35
|
-
];
|
|
36
|
-
exports.EXIT_TOOLS = [
|
|
37
|
-
exports.handoffToHumanAgent.name,
|
|
38
|
-
exports.outOfContext.name,
|
|
39
|
-
exports.finishConversation.name,
|
|
40
|
-
];
|
|
41
|
-
//# sourceMappingURL=tools.js.map
|
package/lib/cjs/tools.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/tools.ts"],"names":[],"mappings":";;;;AAAA,iDAA4C;AAC5C,6BAAuB;AAEV,QAAA,mBAAmB,GAAG,IAAA,YAAI,EACrC,GAAS,EAAE;IACT,OAAO,IAAI,CAAA;AACb,CAAC,CAAA,EACD;IACE,IAAI,EAAE,qBAAqB;IAC3B,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACpB,WAAW,EACT,wEAAwE;IAC1E,YAAY,EAAE,IAAI;CACnB,CACF,CAAA;AAEY,QAAA,YAAY,GAAG,IAAA,YAAI,EAC9B,GAAS,EAAE;IACT,OAAO,IAAI,CAAA;AACb,CAAC,CAAA,EACD;IACE,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACpB,WAAW,EACT,+IAA+I;IACjJ,YAAY,EAAE,IAAI;CACnB,CACF,CAAA;AAEY,QAAA,kBAAkB,GAAG,IAAA,YAAI,EACpC,GAAS,EAAE;IACT,OAAO,IAAI,CAAA;AACb,CAAC,CAAA,EACD;IACE,IAAI,EAAE,oBAAoB;IAC1B,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACpB,WAAW,EAAE,uDAAuD;IACpE,YAAY,EAAE,IAAI;CACnB,CACF,CAAA;AAEY,QAAA,eAAe,GAAG;IAC7B,2BAAmB;IACnB,oBAAY;IACZ,0BAAkB;CACnB,CAAA;AACY,QAAA,UAAU,GAAG;IACxB,2BAAmB,CAAC,IAAI;IACxB,oBAAY,CAAC,IAAI;IACjB,0BAAkB,CAAC,IAAI;CACxB,CAAA"}
|
package/lib/cjs/utils.d.ts
DELETED
package/lib/cjs/utils.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadChatModel = void 0;
|
|
4
|
-
const openai_1 = require("@langchain/openai");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
function loadChatModel(provider) {
|
|
7
|
-
switch (provider) {
|
|
8
|
-
case 'azureOpenAI':
|
|
9
|
-
return new openai_1.AzureChatOpenAI({
|
|
10
|
-
azureOpenAIApiVersion: constants_1.AZURE_OPENAI_API_VERSION,
|
|
11
|
-
azureOpenAIApiKey: constants_1.AZURE_OPENAI_API_KEY,
|
|
12
|
-
azureOpenAIApiDeploymentName: constants_1.AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
13
|
-
azureOpenAIEndpoint: constants_1.AZURE_OPENAI_API_BASE,
|
|
14
|
-
temperature: 0,
|
|
15
|
-
// other params...
|
|
16
|
-
});
|
|
17
|
-
default:
|
|
18
|
-
throw new Error(`Provider ${provider} not supported`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.loadChatModel = loadChatModel;
|
|
22
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/cjs/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA,8CAAmD;AAEnD,2CAKoB;AAEpB,SAAgB,aAAa,CAAC,QAAuB;IACnD,QAAQ,QAAQ,EAAE;QAChB,KAAK,aAAa;YAChB,OAAO,IAAI,wBAAe,CAAC;gBACzB,qBAAqB,EAAE,oCAAwB;gBAC/C,iBAAiB,EAAE,gCAAoB;gBACvC,4BAA4B,EAAE,4CAAgC;gBAC9D,mBAAmB,EAAE,iCAAqB;gBAC1C,WAAW,EAAE,CAAC;gBACd,kBAAkB;aACnB,CAAC,CAAA;QACJ;YACE,MAAM,IAAI,KAAK,CAAC,YAAY,QAAQ,gBAAgB,CAAC,CAAA;KACxD;AACH,CAAC;AAdD,sCAcC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
-
import { StructuredTool } from '@langchain/core/tools';
|
|
3
|
-
import { CompiledStateGraph } from '@langchain/langgraph';
|
|
4
|
-
import { AgenticInputMessage, AgenticOutputMessage, AiAgentArgs } from './types';
|
|
5
|
-
export declare class AiAgentClient {
|
|
6
|
-
name: string;
|
|
7
|
-
instructions: string;
|
|
8
|
-
agent: CompiledStateGraph<any, any>;
|
|
9
|
-
constructor(aiAgentArgs: AiAgentArgs, chatModel: BaseChatModel, tools?: StructuredTool[]);
|
|
10
|
-
runAgent(_messages: AgenticInputMessage[]): Promise<AgenticOutputMessage>;
|
|
11
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { AIMessage as LangchainAIMessage, ToolMessage as LangchainToolMessage, } from '@langchain/core/messages';
|
|
3
|
-
import { createReactAgent } from '@langchain/langgraph/prebuilt';
|
|
4
|
-
import { EXIT_TOOLS } from './tools';
|
|
5
|
-
export class AiAgentClient {
|
|
6
|
-
constructor(aiAgentArgs, chatModel, tools = []) {
|
|
7
|
-
this.name = aiAgentArgs.name;
|
|
8
|
-
this.instructions = aiAgentArgs.instructions;
|
|
9
|
-
this.agent = createReactAgent({
|
|
10
|
-
llm: chatModel,
|
|
11
|
-
tools: tools,
|
|
12
|
-
prompt: this.instructions,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
runAgent(_messages) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const response = yield this.agent.invoke({
|
|
18
|
-
messages: _messages.map((message) => ({
|
|
19
|
-
role: message.role,
|
|
20
|
-
content: message.content,
|
|
21
|
-
})),
|
|
22
|
-
});
|
|
23
|
-
const lastMessage = response.messages.at(-1);
|
|
24
|
-
if (lastMessage instanceof LangchainToolMessage) {
|
|
25
|
-
if (lastMessage.name && EXIT_TOOLS.includes(lastMessage.name)) {
|
|
26
|
-
return {
|
|
27
|
-
role: 'exit',
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
role: 'tool',
|
|
32
|
-
toolName: lastMessage.name,
|
|
33
|
-
toolOutput: lastMessage.content,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (lastMessage instanceof LangchainAIMessage) {
|
|
37
|
-
return {
|
|
38
|
-
role: 'assistant',
|
|
39
|
-
content: lastMessage.content,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
throw new Error('Last message is not a valid message');
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=ai-agent-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ai-agent-client.js","sourceRoot":"","sources":["../../src/ai-agent-client.ts"],"names":[],"mappings":";AACA,OAAO,EACL,SAAS,IAAI,kBAAkB,EAC/B,WAAW,IAAI,oBAAoB,GACpC,MAAM,0BAA0B,CAAA;AAGjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAUpC,MAAM,OAAO,aAAa;IAKxB,YACE,WAAwB,EACxB,SAAwB,EACxB,QAA0B,EAAE;QAE5B,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAA;QAC5B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC,YAAY,CAAA;QAE5C,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC;YAC5B,GAAG,EAAE,SAAS;YACd,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,IAAI,CAAC,YAAY;SAC1B,CAAC,CAAA;IACJ,CAAC;IAEK,QAAQ,CACZ,SAAgC;;YAEhC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;gBACvC,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,OAA4B,EAAE,EAAE,CAAC,CAAC;oBACzD,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,OAAO,EAAE,OAAO,CAAC,OAAO;iBACzB,CAAC,CAAC;aACJ,CAAC,CAAA;YACF,MAAM,WAAW,GAAG,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;YAE5C,IAAI,WAAW,YAAY,oBAAoB,EAAE;gBAC/C,IAAI,WAAW,CAAC,IAAI,IAAI,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;oBAC7D,OAAO;wBACL,IAAI,EAAE,MAAM;qBACE,CAAA;iBACjB;gBACD,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,WAAW,CAAC,IAAI;oBAC1B,UAAU,EAAE,WAAW,CAAC,OAAO;iBACjB,CAAA;aACjB;YAED,IAAI,WAAW,YAAY,kBAAkB,EAAE;gBAC7C,OAAO;oBACL,IAAI,EAAE,WAAW;oBACjB,OAAO,EAAE,WAAW,CAAC,OAAO;iBACT,CAAA;aACtB;YAED,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACxD,CAAC;KAAA;CACF"}
|
package/lib/esm/errors.d.ts
DELETED
package/lib/esm/errors.js
DELETED
package/lib/esm/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import { HUBTYPE_API_URL } from './constants';
|
|
4
|
-
export class HubtypeClient {
|
|
5
|
-
constructor(authToken) {
|
|
6
|
-
this.authToken = authToken;
|
|
7
|
-
}
|
|
8
|
-
getMessages(request, memoryLength) {
|
|
9
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
10
|
-
const url = `${HUBTYPE_API_URL}/external/v1/ai/agent/message_history/`;
|
|
11
|
-
const data = {
|
|
12
|
-
last_message_id: request.input.message_id,
|
|
13
|
-
num_messages: memoryLength,
|
|
14
|
-
};
|
|
15
|
-
const config = {
|
|
16
|
-
headers: {
|
|
17
|
-
'Content-Type': 'application/json',
|
|
18
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
try {
|
|
22
|
-
const messages = yield axios.post(url, data, config);
|
|
23
|
-
return messages.data.messages;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
console.error(error);
|
|
27
|
-
throw new Error('Failed to get messages from Hubtype');
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=hubtype-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-client.js","sourceRoot":"","sources":["../../src/hubtype-client.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7C,MAAM,OAAO,aAAa;IAGxB,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAEK,WAAW,CACf,OAAmB,EACnB,YAAoB;;YAEpB,MAAM,GAAG,GAAG,GAAG,eAAe,wCAAwC,CAAA;YACtE,MAAM,IAAI,GAAG;gBACX,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU;gBACzC,YAAY,EAAE,YAAY;aAC3B,CAAA;YACD,MAAM,MAAM,GAAG;gBACb,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;iBAC1C;aACF,CAAA;YAED,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAC/B,GAAG,EACH,IAAI,EACJ,MAAM,CACP,CAAA;gBAED,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAA;aAC9B;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;gBACpB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;aACvD;QACH,CAAC;KAAA;CACF"}
|
package/lib/esm/tools.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export declare const handoffToHumanAgent: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {}, {}, null>;
|
|
3
|
-
export declare const outOfContext: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {}, {}, null>;
|
|
4
|
-
export declare const finishConversation: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {}, {}, null>;
|
|
5
|
-
export declare const MANDATORY_TOOLS: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {}, {}, null>[];
|
|
6
|
-
export declare const EXIT_TOOLS: string[];
|
package/lib/esm/tools.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { tool } from '@langchain/core/tools';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
export const handoffToHumanAgent = tool(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
5
|
-
return null;
|
|
6
|
-
}), {
|
|
7
|
-
name: 'handoffToHumanAgent',
|
|
8
|
-
schema: z.object({}),
|
|
9
|
-
description: 'Use this tool strictly when the user wants to talk with a human agent.',
|
|
10
|
-
returnDirect: true,
|
|
11
|
-
});
|
|
12
|
-
export const outOfContext = tool(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
return null;
|
|
14
|
-
}), {
|
|
15
|
-
name: 'outOfContext',
|
|
16
|
-
schema: z.object({}),
|
|
17
|
-
description: 'Use this when the user talks about something that is clearly out of your context. Example: "I want to buy a car" when you are a travel agent.',
|
|
18
|
-
returnDirect: true,
|
|
19
|
-
});
|
|
20
|
-
export const finishConversation = tool(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
return null;
|
|
22
|
-
}), {
|
|
23
|
-
name: 'finishConversation',
|
|
24
|
-
schema: z.object({}),
|
|
25
|
-
description: 'Use this when the user wants to end the conversation.',
|
|
26
|
-
returnDirect: true,
|
|
27
|
-
});
|
|
28
|
-
export const MANDATORY_TOOLS = [
|
|
29
|
-
handoffToHumanAgent,
|
|
30
|
-
outOfContext,
|
|
31
|
-
finishConversation,
|
|
32
|
-
];
|
|
33
|
-
export const EXIT_TOOLS = [
|
|
34
|
-
handoffToHumanAgent.name,
|
|
35
|
-
outOfContext.name,
|
|
36
|
-
finishConversation.name,
|
|
37
|
-
];
|
|
38
|
-
//# sourceMappingURL=tools.js.map
|
package/lib/esm/tools.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/tools.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CACrC,GAAS,EAAE;IACT,OAAO,IAAI,CAAA;AACb,CAAC,CAAA,EACD;IACE,IAAI,EAAE,qBAAqB;IAC3B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACpB,WAAW,EACT,wEAAwE;IAC1E,YAAY,EAAE,IAAI;CACnB,CACF,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAC9B,GAAS,EAAE;IACT,OAAO,IAAI,CAAA;AACb,CAAC,CAAA,EACD;IACE,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACpB,WAAW,EACT,+IAA+I;IACjJ,YAAY,EAAE,IAAI;CACnB,CACF,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CACpC,GAAS,EAAE;IACT,OAAO,IAAI,CAAA;AACb,CAAC,CAAA,EACD;IACE,IAAI,EAAE,oBAAoB;IAC1B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACpB,WAAW,EAAE,uDAAuD;IACpE,YAAY,EAAE,IAAI;CACnB,CACF,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,mBAAmB;IACnB,YAAY;IACZ,kBAAkB;CACnB,CAAA;AACD,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,mBAAmB,CAAC,IAAI;IACxB,YAAY,CAAC,IAAI;IACjB,kBAAkB,CAAC,IAAI;CACxB,CAAA"}
|
package/lib/esm/utils.d.ts
DELETED
package/lib/esm/utils.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AzureChatOpenAI } from '@langchain/openai';
|
|
2
|
-
import { AZURE_OPENAI_API_BASE, AZURE_OPENAI_API_DEPLOYMENT_NAME, AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_VERSION, } from './constants';
|
|
3
|
-
export function loadChatModel(provider) {
|
|
4
|
-
switch (provider) {
|
|
5
|
-
case 'azureOpenAI':
|
|
6
|
-
return new AzureChatOpenAI({
|
|
7
|
-
azureOpenAIApiVersion: AZURE_OPENAI_API_VERSION,
|
|
8
|
-
azureOpenAIApiKey: AZURE_OPENAI_API_KEY,
|
|
9
|
-
azureOpenAIApiDeploymentName: AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
10
|
-
azureOpenAIEndpoint: AZURE_OPENAI_API_BASE,
|
|
11
|
-
temperature: 0,
|
|
12
|
-
// other params...
|
|
13
|
-
});
|
|
14
|
-
default:
|
|
15
|
-
throw new Error(`Provider ${provider} not supported`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/esm/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,aAAa,CAAA;AAEpB,MAAM,UAAU,aAAa,CAAC,QAAuB;IACnD,QAAQ,QAAQ,EAAE;QAChB,KAAK,aAAa;YAChB,OAAO,IAAI,eAAe,CAAC;gBACzB,qBAAqB,EAAE,wBAAwB;gBAC/C,iBAAiB,EAAE,oBAAoB;gBACvC,4BAA4B,EAAE,gCAAgC;gBAC9D,mBAAmB,EAAE,qBAAqB;gBAC1C,WAAW,EAAE,CAAC;gBACd,kBAAkB;aACnB,CAAC,CAAA;QACJ;YACE,MAAM,IAAI,KAAK,CAAC,YAAY,QAAQ,gBAAgB,CAAC,CAAA;KACxD;AACH,CAAC"}
|
package/src/ai-agent-client.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { BaseChatModel } from '@langchain/core/language_models/chat_models'
|
|
2
|
-
import {
|
|
3
|
-
AIMessage as LangchainAIMessage,
|
|
4
|
-
ToolMessage as LangchainToolMessage,
|
|
5
|
-
} from '@langchain/core/messages'
|
|
6
|
-
import { StructuredTool } from '@langchain/core/tools'
|
|
7
|
-
import { CompiledStateGraph } from '@langchain/langgraph'
|
|
8
|
-
import { createReactAgent } from '@langchain/langgraph/prebuilt'
|
|
9
|
-
|
|
10
|
-
import { EXIT_TOOLS } from './tools'
|
|
11
|
-
import {
|
|
12
|
-
AgenticInputMessage,
|
|
13
|
-
AgenticOutputMessage,
|
|
14
|
-
AiAgentArgs,
|
|
15
|
-
AssistantMessage,
|
|
16
|
-
ExitMessage,
|
|
17
|
-
ToolMessage,
|
|
18
|
-
} from './types'
|
|
19
|
-
|
|
20
|
-
export class AiAgentClient {
|
|
21
|
-
public name: string
|
|
22
|
-
public instructions: string
|
|
23
|
-
public agent: CompiledStateGraph<any, any> // TODO: apply RunInput, RunOutput, etc.
|
|
24
|
-
|
|
25
|
-
constructor(
|
|
26
|
-
aiAgentArgs: AiAgentArgs,
|
|
27
|
-
chatModel: BaseChatModel,
|
|
28
|
-
tools: StructuredTool[] = []
|
|
29
|
-
) {
|
|
30
|
-
this.name = aiAgentArgs.name
|
|
31
|
-
this.instructions = aiAgentArgs.instructions
|
|
32
|
-
|
|
33
|
-
this.agent = createReactAgent({
|
|
34
|
-
llm: chatModel,
|
|
35
|
-
tools: tools,
|
|
36
|
-
prompt: this.instructions,
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async runAgent(
|
|
41
|
-
_messages: AgenticInputMessage[]
|
|
42
|
-
): Promise<AgenticOutputMessage> {
|
|
43
|
-
const response = await this.agent.invoke({
|
|
44
|
-
messages: _messages.map((message: AgenticInputMessage) => ({
|
|
45
|
-
role: message.role,
|
|
46
|
-
content: message.content,
|
|
47
|
-
})),
|
|
48
|
-
})
|
|
49
|
-
const lastMessage = response.messages.at(-1)
|
|
50
|
-
|
|
51
|
-
if (lastMessage instanceof LangchainToolMessage) {
|
|
52
|
-
if (lastMessage.name && EXIT_TOOLS.includes(lastMessage.name)) {
|
|
53
|
-
return {
|
|
54
|
-
role: 'exit',
|
|
55
|
-
} as ExitMessage
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
role: 'tool',
|
|
59
|
-
toolName: lastMessage.name,
|
|
60
|
-
toolOutput: lastMessage.content,
|
|
61
|
-
} as ToolMessage
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (lastMessage instanceof LangchainAIMessage) {
|
|
65
|
-
return {
|
|
66
|
-
role: 'assistant',
|
|
67
|
-
content: lastMessage.content,
|
|
68
|
-
} as AssistantMessage
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
throw new Error('Last message is not a valid message')
|
|
72
|
-
}
|
|
73
|
-
}
|
package/src/errors.ts
DELETED
package/src/hubtype-client.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { BotContext } from '@botonic/core'
|
|
2
|
-
import axios from 'axios'
|
|
3
|
-
|
|
4
|
-
import { HUBTYPE_API_URL } from './constants'
|
|
5
|
-
import { AgenticInputMessage } from './types'
|
|
6
|
-
|
|
7
|
-
export class HubtypeClient {
|
|
8
|
-
private readonly authToken: string
|
|
9
|
-
|
|
10
|
-
constructor(authToken: string) {
|
|
11
|
-
this.authToken = authToken
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async getMessages(
|
|
15
|
-
request: BotContext,
|
|
16
|
-
memoryLength: number
|
|
17
|
-
): Promise<AgenticInputMessage[]> {
|
|
18
|
-
const url = `${HUBTYPE_API_URL}/external/v1/ai/agent/message_history/`
|
|
19
|
-
const data = {
|
|
20
|
-
last_message_id: request.input.message_id,
|
|
21
|
-
num_messages: memoryLength,
|
|
22
|
-
}
|
|
23
|
-
const config = {
|
|
24
|
-
headers: {
|
|
25
|
-
'Content-Type': 'application/json',
|
|
26
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
const messages = await axios.post<{ messages: AgenticInputMessage[] }>(
|
|
32
|
-
url,
|
|
33
|
-
data,
|
|
34
|
-
config
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
return messages.data.messages
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.error(error)
|
|
40
|
-
throw new Error('Failed to get messages from Hubtype')
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/tools.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { tool } from '@langchain/core/tools'
|
|
2
|
-
import { z } from 'zod'
|
|
3
|
-
|
|
4
|
-
export const handoffToHumanAgent = tool(
|
|
5
|
-
async () => {
|
|
6
|
-
return null
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
name: 'handoffToHumanAgent',
|
|
10
|
-
schema: z.object({}),
|
|
11
|
-
description:
|
|
12
|
-
'Use this tool strictly when the user wants to talk with a human agent.',
|
|
13
|
-
returnDirect: true,
|
|
14
|
-
}
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
export const outOfContext = tool(
|
|
18
|
-
async () => {
|
|
19
|
-
return null
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
name: 'outOfContext',
|
|
23
|
-
schema: z.object({}),
|
|
24
|
-
description:
|
|
25
|
-
'Use this when the user talks about something that is clearly out of your context. Example: "I want to buy a car" when you are a travel agent.',
|
|
26
|
-
returnDirect: true,
|
|
27
|
-
}
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
export const finishConversation = tool(
|
|
31
|
-
async () => {
|
|
32
|
-
return null
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: 'finishConversation',
|
|
36
|
-
schema: z.object({}),
|
|
37
|
-
description: 'Use this when the user wants to end the conversation.',
|
|
38
|
-
returnDirect: true,
|
|
39
|
-
}
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
export const MANDATORY_TOOLS = [
|
|
43
|
-
handoffToHumanAgent,
|
|
44
|
-
outOfContext,
|
|
45
|
-
finishConversation,
|
|
46
|
-
]
|
|
47
|
-
export const EXIT_TOOLS = [
|
|
48
|
-
handoffToHumanAgent.name,
|
|
49
|
-
outOfContext.name,
|
|
50
|
-
finishConversation.name,
|
|
51
|
-
]
|
package/src/utils.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { AzureChatOpenAI } from '@langchain/openai'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
AZURE_OPENAI_API_BASE,
|
|
5
|
-
AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
6
|
-
AZURE_OPENAI_API_KEY,
|
|
7
|
-
AZURE_OPENAI_API_VERSION,
|
|
8
|
-
} from './constants'
|
|
9
|
-
|
|
10
|
-
export function loadChatModel(provider: 'azureOpenAI') {
|
|
11
|
-
switch (provider) {
|
|
12
|
-
case 'azureOpenAI':
|
|
13
|
-
return new AzureChatOpenAI({
|
|
14
|
-
azureOpenAIApiVersion: AZURE_OPENAI_API_VERSION,
|
|
15
|
-
azureOpenAIApiKey: AZURE_OPENAI_API_KEY,
|
|
16
|
-
azureOpenAIApiDeploymentName: AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
17
|
-
azureOpenAIEndpoint: AZURE_OPENAI_API_BASE,
|
|
18
|
-
temperature: 0,
|
|
19
|
-
// other params...
|
|
20
|
-
})
|
|
21
|
-
default:
|
|
22
|
-
throw new Error(`Provider ${provider} not supported`)
|
|
23
|
-
}
|
|
24
|
-
}
|