@botonic/plugin-ai-agents 0.36.0-alpha.6 → 0.36.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/lib/cjs/constants.d.ts +1 -0
  2. package/lib/cjs/constants.js +2 -1
  3. package/lib/cjs/constants.js.map +1 -1
  4. package/lib/cjs/hubtype-api-client.d.ts +2 -0
  5. package/lib/cjs/hubtype-api-client.js +41 -2
  6. package/lib/cjs/hubtype-api-client.js.map +1 -1
  7. package/lib/cjs/index.d.ts +2 -2
  8. package/lib/cjs/index.js +22 -25
  9. package/lib/cjs/index.js.map +1 -1
  10. package/lib/cjs/runner.d.ts +10 -0
  11. package/lib/cjs/runner.js +75 -0
  12. package/lib/cjs/runner.js.map +1 -0
  13. package/lib/cjs/structured-output/carousel.d.ts +100 -0
  14. package/lib/cjs/structured-output/carousel.js +21 -0
  15. package/lib/cjs/structured-output/carousel.js.map +1 -0
  16. package/lib/cjs/structured-output/exit.d.ts +12 -0
  17. package/lib/cjs/structured-output/exit.js +11 -0
  18. package/lib/cjs/structured-output/exit.js.map +1 -0
  19. package/lib/cjs/structured-output/index.d.ts +198 -0
  20. package/lib/cjs/structured-output/index.js +14 -0
  21. package/lib/cjs/structured-output/index.js.map +1 -0
  22. package/lib/cjs/structured-output/shared.d.ts +3 -0
  23. package/lib/cjs/structured-output/shared.js +3 -0
  24. package/lib/cjs/structured-output/shared.js.map +1 -0
  25. package/lib/cjs/structured-output/text-with-buttons.d.ts +34 -0
  26. package/lib/cjs/structured-output/text-with-buttons.js +15 -0
  27. package/lib/cjs/structured-output/text-with-buttons.js.map +1 -0
  28. package/lib/cjs/structured-output/text.d.ts +28 -0
  29. package/lib/cjs/structured-output/text.js +13 -0
  30. package/lib/cjs/structured-output/text.js.map +1 -0
  31. package/lib/cjs/types.d.ts +6 -25
  32. package/lib/esm/constants.d.ts +1 -0
  33. package/lib/esm/constants.js +1 -0
  34. package/lib/esm/constants.js.map +1 -1
  35. package/lib/esm/hubtype-api-client.d.ts +2 -0
  36. package/lib/esm/hubtype-api-client.js +41 -2
  37. package/lib/esm/hubtype-api-client.js.map +1 -1
  38. package/lib/esm/index.d.ts +2 -2
  39. package/lib/esm/index.js +20 -23
  40. package/lib/esm/index.js.map +1 -1
  41. package/lib/esm/runner.d.ts +10 -0
  42. package/lib/esm/runner.js +71 -0
  43. package/lib/esm/runner.js.map +1 -0
  44. package/lib/esm/structured-output/carousel.d.ts +100 -0
  45. package/lib/esm/structured-output/carousel.js +18 -0
  46. package/lib/esm/structured-output/carousel.js.map +1 -0
  47. package/lib/esm/structured-output/exit.d.ts +12 -0
  48. package/lib/esm/structured-output/exit.js +7 -0
  49. package/lib/esm/structured-output/exit.js.map +1 -0
  50. package/lib/esm/structured-output/index.d.ts +198 -0
  51. package/lib/esm/structured-output/index.js +11 -0
  52. package/lib/esm/structured-output/index.js.map +1 -0
  53. package/lib/esm/structured-output/shared.d.ts +3 -0
  54. package/lib/esm/structured-output/shared.js +2 -0
  55. package/lib/esm/structured-output/shared.js.map +1 -0
  56. package/lib/esm/structured-output/text-with-buttons.d.ts +34 -0
  57. package/lib/esm/structured-output/text-with-buttons.js +11 -0
  58. package/lib/esm/structured-output/text-with-buttons.js.map +1 -0
  59. package/lib/esm/structured-output/text.d.ts +28 -0
  60. package/lib/esm/structured-output/text.js +10 -0
  61. package/lib/esm/structured-output/text.js.map +1 -0
  62. package/lib/esm/types.d.ts +6 -25
  63. package/package.json +3 -4
  64. package/src/constants.ts +2 -0
  65. package/src/hubtype-api-client.ts +55 -9
  66. package/src/index.ts +25 -32
  67. package/src/runner.ts +97 -0
  68. package/src/structured-output/carousel.ts +36 -0
  69. package/src/structured-output/exit.ts +15 -0
  70. package/src/structured-output/index.ts +27 -0
  71. package/src/structured-output/shared.ts +3 -0
  72. package/src/structured-output/text-with-buttons.ts +23 -0
  73. package/src/structured-output/text.ts +19 -0
  74. package/src/types.ts +7 -34
  75. package/lib/cjs/ai-agent-client.d.ts +0 -9
  76. package/lib/cjs/ai-agent-client.js +0 -49
  77. package/lib/cjs/ai-agent-client.js.map +0 -1
  78. package/lib/cjs/errors.d.ts +0 -3
  79. package/lib/cjs/errors.js +0 -11
  80. package/lib/cjs/errors.js.map +0 -1
  81. package/lib/cjs/tools/custom.d.ts +0 -3
  82. package/lib/cjs/tools/custom.js +0 -14
  83. package/lib/cjs/tools/custom.js.map +0 -1
  84. package/lib/cjs/tools/default.d.ts +0 -6
  85. package/lib/cjs/tools/default.js +0 -41
  86. package/lib/cjs/tools/default.js.map +0 -1
  87. package/lib/cjs/utils.d.ts +0 -5
  88. package/lib/cjs/utils.js +0 -26
  89. package/lib/cjs/utils.js.map +0 -1
  90. package/lib/esm/ai-agent-client.d.ts +0 -9
  91. package/lib/esm/ai-agent-client.js +0 -45
  92. package/lib/esm/ai-agent-client.js.map +0 -1
  93. package/lib/esm/errors.d.ts +0 -3
  94. package/lib/esm/errors.js +0 -7
  95. package/lib/esm/errors.js.map +0 -1
  96. package/lib/esm/tools/custom.d.ts +0 -3
  97. package/lib/esm/tools/custom.js +0 -10
  98. package/lib/esm/tools/custom.js.map +0 -1
  99. package/lib/esm/tools/default.d.ts +0 -6
  100. package/lib/esm/tools/default.js +0 -38
  101. package/lib/esm/tools/default.js.map +0 -1
  102. package/lib/esm/utils.d.ts +0 -5
  103. package/lib/esm/utils.js +0 -22
  104. package/lib/esm/utils.js.map +0 -1
  105. package/src/ai-agent-client.ts +0 -69
  106. package/src/errors.ts +0 -6
  107. package/src/tools/custom.ts +0 -14
  108. package/src/tools/default.ts +0 -52
  109. package/src/utils.ts +0 -28
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod'
2
+
3
+ import { BaseMessage } from './shared'
4
+
5
+ interface CarouselElement {
6
+ title: string
7
+ subtitle: string
8
+ image: string
9
+ button: { text: string; url: string }
10
+ }
11
+
12
+ export interface CarouselMessage extends BaseMessage {
13
+ type: 'carousel'
14
+ content: {
15
+ elements: CarouselElement[]
16
+ }
17
+ }
18
+
19
+ export const CarouselSchema = z
20
+ .object({
21
+ type: z.enum(['carousel']),
22
+ content: z.object({
23
+ elements: z.array(
24
+ z.object({
25
+ title: z.string(),
26
+ subtitle: z.string(),
27
+ image: z.string(),
28
+ button: z.object({
29
+ text: z.string(),
30
+ url: z.string(),
31
+ }),
32
+ })
33
+ ),
34
+ }),
35
+ })
36
+ .describe('A carousel message containing a list of elements')
@@ -0,0 +1,15 @@
1
+ import z from 'zod'
2
+
3
+ import { BaseMessage } from './shared'
4
+
5
+ export interface ExitMessage extends BaseMessage {
6
+ type: 'exit'
7
+ }
8
+
9
+ export const ExitSchema = z
10
+ .object({
11
+ type: z.enum(['exit']),
12
+ })
13
+ .describe(
14
+ 'An exit message. This message should only be used to exit the agent due to out of context or the user asking to exit the conversation'
15
+ )
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod'
2
+
3
+ import { CarouselMessage, CarouselSchema } from './carousel'
4
+ import { ExitMessage, ExitSchema } from './exit'
5
+ import { TextMessage, TextSchema } from './text'
6
+ import {
7
+ TextWithButtonsMessage,
8
+ TextWithButtonsSchema,
9
+ } from './text-with-buttons'
10
+
11
+ export type OutputMessage =
12
+ | TextMessage
13
+ | TextWithButtonsMessage
14
+ | CarouselMessage
15
+ | ExitMessage
16
+
17
+ export interface Output {
18
+ messages: OutputMessage[]
19
+ }
20
+
21
+ export const OutputSchema = z
22
+ .object({
23
+ messages: z.array(
24
+ z.union([TextSchema, TextWithButtonsSchema, CarouselSchema, ExitSchema])
25
+ ),
26
+ })
27
+ .describe('The messages to be sent to the user')
@@ -0,0 +1,3 @@
1
+ export interface BaseMessage {
2
+ type: 'text' | 'textWithButtons' | 'carousel' | 'exit'
3
+ }
@@ -0,0 +1,23 @@
1
+ import z from 'zod'
2
+
3
+ import { BaseMessage } from './shared'
4
+
5
+ export interface TextWithButtonsMessage extends BaseMessage {
6
+ type: 'textWithButtons'
7
+ content: {
8
+ text: string
9
+ buttons: string[]
10
+ }
11
+ }
12
+
13
+ export const TextWithButtonsSchema = z
14
+ .object({
15
+ type: z.enum(['textWithButtons']),
16
+ content: z.object({
17
+ text: z.string(),
18
+ buttons: z.array(z.string()),
19
+ }),
20
+ })
21
+ .describe(
22
+ 'A text message with buttons to allow the user to use quick replies'
23
+ )
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod'
2
+
3
+ import { BaseMessage } from './shared'
4
+
5
+ export interface TextMessage extends BaseMessage {
6
+ type: 'text'
7
+ content: {
8
+ text: string
9
+ }
10
+ }
11
+
12
+ export const TextSchema = z
13
+ .object({
14
+ type: z.enum(['text']),
15
+ content: z.object({
16
+ text: z.string(),
17
+ }),
18
+ })
19
+ .describe('A text message')
package/src/types.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { ZodSchema } from 'zod'
1
+ import { AgentInputItem } from '@openai/agents'
2
+ import { ZodObject } from 'zod'
3
+
4
+ import { OutputMessage } from './structured-output'
2
5
  export interface PluginAiAgentOptions {
3
6
  authToken?: string
4
7
  customTools?: CustomTool[]
@@ -7,8 +10,7 @@ export interface PluginAiAgentOptions {
7
10
  export interface CustomTool {
8
11
  name: string
9
12
  description: string
10
- schema: ZodSchema
11
- returnDirect?: boolean
13
+ schema: ZodObject<any>
12
14
  func: (input?: any) => Promise<any>
13
15
  }
14
16
 
@@ -18,34 +20,5 @@ export interface AiAgentArgs {
18
20
  activeTools?: { name: string }[]
19
21
  }
20
22
 
21
- export interface AgenticBaseMessage {
22
- role: 'assistant' | 'user' | 'tool' | 'exit'
23
- }
24
-
25
- export interface AssistantMessage extends AgenticBaseMessage {
26
- role: 'assistant'
27
- content: string
28
- }
29
-
30
- export interface UserMessage extends AgenticBaseMessage {
31
- role: 'user'
32
- content: string
33
- }
34
-
35
- export interface ToolMessage extends AgenticBaseMessage {
36
- role: 'tool'
37
- toolName: string
38
- toolOutput: string | null
39
- }
40
-
41
- export interface ExitMessage extends AgenticBaseMessage {
42
- role: 'exit'
43
- }
44
-
45
- export type AgenticInputMessage = AssistantMessage | UserMessage
46
- export type AgenticOutputMessage = AssistantMessage | ToolMessage | ExitMessage
47
- export type AgenticMessage =
48
- | AssistantMessage
49
- | UserMessage
50
- | ToolMessage
51
- | ExitMessage
23
+ export type AgenticInputMessage = AgentInputItem
24
+ export type AgenticOutputMessage = OutputMessage
@@ -1,9 +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
- agent: CompiledStateGraph<any, any>;
7
- constructor(aiAgentArgs: AiAgentArgs, chatModel: BaseChatModel, tools?: StructuredTool[]);
8
- runAgent(_messages: AgenticInputMessage[]): Promise<AgenticOutputMessage>;
9
- }
@@ -1,49 +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 default_1 = require("./tools/default");
8
- class AiAgentClient {
9
- constructor(aiAgentArgs, chatModel, tools = []) {
10
- this.agent = (0, prebuilt_1.createReactAgent)({
11
- name: aiAgentArgs.name,
12
- llm: chatModel,
13
- tools: tools,
14
- prompt: aiAgentArgs.instructions,
15
- });
16
- }
17
- runAgent(_messages) {
18
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
- const response = yield this.agent.invoke({
20
- messages: _messages.map((message) => ({
21
- role: message.role,
22
- content: message.content,
23
- })),
24
- });
25
- const lastMessage = response.messages.at(-1);
26
- if (lastMessage instanceof messages_1.ToolMessage) {
27
- if (lastMessage.name && default_1.EXIT_TOOLS.includes(lastMessage.name)) {
28
- return {
29
- role: 'exit',
30
- };
31
- }
32
- return {
33
- role: 'tool',
34
- toolName: lastMessage.name,
35
- toolOutput: lastMessage.content,
36
- };
37
- }
38
- if (lastMessage instanceof messages_1.AIMessage) {
39
- return {
40
- role: 'assistant',
41
- content: lastMessage.content,
42
- };
43
- }
44
- throw new Error('Last message is not a valid message');
45
- });
46
- }
47
- }
48
- exports.AiAgentClient = AiAgentClient;
49
- //# 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,6CAA4C;AAU5C,MAAa,aAAa;IAGxB,YACE,WAAwB,EACxB,SAAwB,EACxB,QAA0B,EAAE;QAE5B,IAAI,CAAC,KAAK,GAAG,IAAA,2BAAgB,EAAC;YAC5B,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,GAAG,EAAE,SAAS;YACd,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,WAAW,CAAC,YAAY;SACjC,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,oBAAU,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;AAjDD,sCAiDC"}
@@ -1,3 +0,0 @@
1
- export declare class AiAgentError extends Error {
2
- constructor(message: string);
3
- }
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
@@ -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,3 +0,0 @@
1
- import { DynamicStructuredTool } from '@langchain/core/tools';
2
- import { CustomTool } from '../types';
3
- export declare function createCustomTool(customTool: CustomTool): DynamicStructuredTool;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCustomTool = void 0;
4
- const tools_1 = require("@langchain/core/tools");
5
- function createCustomTool(customTool) {
6
- return (0, tools_1.tool)(customTool.func, {
7
- name: customTool.name,
8
- description: customTool.description,
9
- schema: customTool.schema,
10
- returnDirect: customTool.returnDirect || false,
11
- });
12
- }
13
- exports.createCustomTool = createCustomTool;
14
- //# sourceMappingURL=custom.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"custom.js","sourceRoot":"","sources":["../../../src/tools/custom.ts"],"names":[],"mappings":";;;AAAA,iDAAmE;AAInE,SAAgB,gBAAgB,CAC9B,UAAsB;IAEtB,OAAO,IAAA,YAAI,EAAC,UAAU,CAAC,IAAI,EAAE;QAC3B,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,YAAY,EAAE,UAAU,CAAC,YAAY,IAAI,KAAK;KAC/C,CAAC,CAAA;AACJ,CAAC;AATD,4CASC"}
@@ -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[];
@@ -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=default.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default.js","sourceRoot":"","sources":["../../../src/tools/default.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;AAEY,QAAA,UAAU,GAAG;IACxB,2BAAmB,CAAC,IAAI;IACxB,oBAAY,CAAC,IAAI;IACjB,0BAAkB,CAAC,IAAI;CACxB,CAAA"}
@@ -1,5 +0,0 @@
1
- import { AzureChatOpenAI } from '@langchain/openai';
2
- export declare enum AiProvider {
3
- AzureOpenAI = "azureOpenAI"
4
- }
5
- export declare function loadChatModel(provider: AiProvider): AzureChatOpenAI;
package/lib/cjs/utils.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadChatModel = exports.AiProvider = void 0;
4
- const openai_1 = require("@langchain/openai");
5
- const constants_1 = require("./constants");
6
- var AiProvider;
7
- (function (AiProvider) {
8
- AiProvider["AzureOpenAI"] = "azureOpenAI";
9
- })(AiProvider = exports.AiProvider || (exports.AiProvider = {}));
10
- function loadChatModel(provider) {
11
- switch (provider) {
12
- case AiProvider.AzureOpenAI:
13
- return new openai_1.AzureChatOpenAI({
14
- azureOpenAIApiVersion: constants_1.AZURE_OPENAI_API_VERSION,
15
- azureOpenAIApiKey: constants_1.AZURE_OPENAI_API_KEY,
16
- azureOpenAIApiDeploymentName: constants_1.AZURE_OPENAI_API_DEPLOYMENT_NAME,
17
- azureOpenAIEndpoint: constants_1.AZURE_OPENAI_API_BASE,
18
- temperature: 0,
19
- // other params...
20
- });
21
- default:
22
- throw new Error(`Provider ${provider} not supported`);
23
- }
24
- }
25
- exports.loadChatModel = loadChatModel;
26
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA,8CAAmD;AAEnD,2CAKoB;AAEpB,IAAY,UAEX;AAFD,WAAY,UAAU;IACpB,yCAA2B,CAAA;AAC7B,CAAC,EAFW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAErB;AAED,SAAgB,aAAa,CAAC,QAAoB;IAChD,QAAQ,QAAQ,EAAE;QAChB,KAAK,UAAU,CAAC,WAAW;YACzB,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,9 +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
- agent: CompiledStateGraph<any, any>;
7
- constructor(aiAgentArgs: AiAgentArgs, chatModel: BaseChatModel, tools?: StructuredTool[]);
8
- runAgent(_messages: AgenticInputMessage[]): Promise<AgenticOutputMessage>;
9
- }
@@ -1,45 +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/default';
5
- export class AiAgentClient {
6
- constructor(aiAgentArgs, chatModel, tools = []) {
7
- this.agent = createReactAgent({
8
- name: aiAgentArgs.name,
9
- llm: chatModel,
10
- tools: tools,
11
- prompt: aiAgentArgs.instructions,
12
- });
13
- }
14
- runAgent(_messages) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const response = yield this.agent.invoke({
17
- messages: _messages.map((message) => ({
18
- role: message.role,
19
- content: message.content,
20
- })),
21
- });
22
- const lastMessage = response.messages.at(-1);
23
- if (lastMessage instanceof LangchainToolMessage) {
24
- if (lastMessage.name && EXIT_TOOLS.includes(lastMessage.name)) {
25
- return {
26
- role: 'exit',
27
- };
28
- }
29
- return {
30
- role: 'tool',
31
- toolName: lastMessage.name,
32
- toolOutput: lastMessage.content,
33
- };
34
- }
35
- if (lastMessage instanceof LangchainAIMessage) {
36
- return {
37
- role: 'assistant',
38
- content: lastMessage.content,
39
- };
40
- }
41
- throw new Error('Last message is not a valid message');
42
- });
43
- }
44
- }
45
- //# 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,iBAAiB,CAAA;AAU5C,MAAM,OAAO,aAAa;IAGxB,YACE,WAAwB,EACxB,SAAwB,EACxB,QAA0B,EAAE;QAE5B,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAAC;YAC5B,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,GAAG,EAAE,SAAS;YACd,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,WAAW,CAAC,YAAY;SACjC,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"}
@@ -1,3 +0,0 @@
1
- export declare class AiAgentError extends Error {
2
- constructor(message: string);
3
- }
package/lib/esm/errors.js DELETED
@@ -1,7 +0,0 @@
1
- export class AiAgentError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = 'AiAgentError';
5
- }
6
- }
7
- //# sourceMappingURL=errors.js.map
@@ -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,3 +0,0 @@
1
- import { DynamicStructuredTool } from '@langchain/core/tools';
2
- import { CustomTool } from '../types';
3
- export declare function createCustomTool(customTool: CustomTool): DynamicStructuredTool;
@@ -1,10 +0,0 @@
1
- import { tool } from '@langchain/core/tools';
2
- export function createCustomTool(customTool) {
3
- return tool(customTool.func, {
4
- name: customTool.name,
5
- description: customTool.description,
6
- schema: customTool.schema,
7
- returnDirect: customTool.returnDirect || false,
8
- });
9
- }
10
- //# sourceMappingURL=custom.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"custom.js","sourceRoot":"","sources":["../../../src/tools/custom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAInE,MAAM,UAAU,gBAAgB,CAC9B,UAAsB;IAEtB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;QAC3B,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,YAAY,EAAE,UAAU,CAAC,YAAY,IAAI,KAAK;KAC/C,CAAC,CAAA;AACJ,CAAC"}
@@ -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[];
@@ -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=default.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default.js","sourceRoot":"","sources":["../../../src/tools/default.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;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,mBAAmB,CAAC,IAAI;IACxB,YAAY,CAAC,IAAI;IACjB,kBAAkB,CAAC,IAAI;CACxB,CAAA"}
@@ -1,5 +0,0 @@
1
- import { AzureChatOpenAI } from '@langchain/openai';
2
- export declare enum AiProvider {
3
- AzureOpenAI = "azureOpenAI"
4
- }
5
- export declare function loadChatModel(provider: AiProvider): AzureChatOpenAI;
package/lib/esm/utils.js DELETED
@@ -1,22 +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 var AiProvider;
4
- (function (AiProvider) {
5
- AiProvider["AzureOpenAI"] = "azureOpenAI";
6
- })(AiProvider || (AiProvider = {}));
7
- export function loadChatModel(provider) {
8
- switch (provider) {
9
- case AiProvider.AzureOpenAI:
10
- return new AzureChatOpenAI({
11
- azureOpenAIApiVersion: AZURE_OPENAI_API_VERSION,
12
- azureOpenAIApiKey: AZURE_OPENAI_API_KEY,
13
- azureOpenAIApiDeploymentName: AZURE_OPENAI_API_DEPLOYMENT_NAME,
14
- azureOpenAIEndpoint: AZURE_OPENAI_API_BASE,
15
- temperature: 0,
16
- // other params...
17
- });
18
- default:
19
- throw new Error(`Provider ${provider} not supported`);
20
- }
21
- }
22
- //# sourceMappingURL=utils.js.map
@@ -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,CAAN,IAAY,UAEX;AAFD,WAAY,UAAU;IACpB,yCAA2B,CAAA;AAC7B,CAAC,EAFW,UAAU,KAAV,UAAU,QAErB;AAED,MAAM,UAAU,aAAa,CAAC,QAAoB;IAChD,QAAQ,QAAQ,EAAE;QAChB,KAAK,UAAU,CAAC,WAAW;YACzB,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"}
@@ -1,69 +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/default'
11
- import {
12
- AgenticInputMessage,
13
- AgenticOutputMessage,
14
- AiAgentArgs,
15
- AssistantMessage,
16
- ExitMessage,
17
- ToolMessage,
18
- } from './types'
19
-
20
- export class AiAgentClient {
21
- public agent: CompiledStateGraph<any, any> // TODO: apply RunInput, RunOutput, etc.
22
-
23
- constructor(
24
- aiAgentArgs: AiAgentArgs,
25
- chatModel: BaseChatModel,
26
- tools: StructuredTool[] = []
27
- ) {
28
- this.agent = createReactAgent({
29
- name: aiAgentArgs.name,
30
- llm: chatModel,
31
- tools: tools,
32
- prompt: aiAgentArgs.instructions,
33
- })
34
- }
35
-
36
- async runAgent(
37
- _messages: AgenticInputMessage[]
38
- ): Promise<AgenticOutputMessage> {
39
- const response = await this.agent.invoke({
40
- messages: _messages.map((message: AgenticInputMessage) => ({
41
- role: message.role,
42
- content: message.content,
43
- })),
44
- })
45
- const lastMessage = response.messages.at(-1)
46
-
47
- if (lastMessage instanceof LangchainToolMessage) {
48
- if (lastMessage.name && EXIT_TOOLS.includes(lastMessage.name)) {
49
- return {
50
- role: 'exit',
51
- } as ExitMessage
52
- }
53
- return {
54
- role: 'tool',
55
- toolName: lastMessage.name,
56
- toolOutput: lastMessage.content,
57
- } as ToolMessage
58
- }
59
-
60
- if (lastMessage instanceof LangchainAIMessage) {
61
- return {
62
- role: 'assistant',
63
- content: lastMessage.content,
64
- } as AssistantMessage
65
- }
66
-
67
- throw new Error('Last message is not a valid message')
68
- }
69
- }