@botonic/plugin-ai-agents 0.36.0-alpha.0 → 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.
Files changed (110) hide show
  1. package/README.md +14 -0
  2. package/lib/cjs/agent-builder.d.ts +10 -0
  3. package/lib/cjs/agent-builder.js +43 -0
  4. package/lib/cjs/agent-builder.js.map +1 -0
  5. package/lib/cjs/constants.d.ts +5 -0
  6. package/lib/cjs/constants.js +6 -1
  7. package/lib/cjs/constants.js.map +1 -1
  8. package/lib/cjs/hubtype-api-client.d.ts +9 -0
  9. package/lib/cjs/hubtype-api-client.js +76 -0
  10. package/lib/cjs/hubtype-api-client.js.map +1 -0
  11. package/lib/cjs/index.d.ts +8 -5
  12. package/lib/cjs/index.js +52 -4
  13. package/lib/cjs/index.js.map +1 -1
  14. package/lib/cjs/openai.d.ts +1 -0
  15. package/lib/cjs/openai.js +23 -0
  16. package/lib/cjs/openai.js.map +1 -0
  17. package/lib/cjs/runner.d.ts +7 -0
  18. package/lib/cjs/runner.js +35 -0
  19. package/lib/cjs/runner.js.map +1 -0
  20. package/lib/cjs/structured-output/carousel.d.ts +100 -0
  21. package/lib/cjs/structured-output/carousel.js +21 -0
  22. package/lib/cjs/structured-output/carousel.js.map +1 -0
  23. package/lib/cjs/structured-output/exit.d.ts +12 -0
  24. package/lib/cjs/structured-output/exit.js +11 -0
  25. package/lib/cjs/structured-output/exit.js.map +1 -0
  26. package/lib/cjs/structured-output/index.d.ts +198 -0
  27. package/lib/cjs/structured-output/index.js +14 -0
  28. package/lib/cjs/structured-output/index.js.map +1 -0
  29. package/lib/cjs/structured-output/shared.d.ts +3 -0
  30. package/lib/cjs/structured-output/shared.js +3 -0
  31. package/lib/cjs/structured-output/shared.js.map +1 -0
  32. package/lib/cjs/structured-output/text-with-buttons.d.ts +34 -0
  33. package/lib/cjs/structured-output/text-with-buttons.js +15 -0
  34. package/lib/cjs/structured-output/text-with-buttons.js.map +1 -0
  35. package/lib/cjs/structured-output/text.d.ts +28 -0
  36. package/lib/cjs/structured-output/text.js +13 -0
  37. package/lib/cjs/structured-output/text.js.map +1 -0
  38. package/lib/cjs/tools/index.d.ts +2 -0
  39. package/lib/cjs/tools/index.js +5 -0
  40. package/lib/cjs/tools/index.js.map +1 -0
  41. package/lib/cjs/types.d.ts +21 -25
  42. package/lib/esm/agent-builder.d.ts +10 -0
  43. package/lib/esm/agent-builder.js +39 -0
  44. package/lib/esm/agent-builder.js.map +1 -0
  45. package/lib/esm/constants.d.ts +5 -0
  46. package/lib/esm/constants.js +5 -0
  47. package/lib/esm/constants.js.map +1 -1
  48. package/lib/esm/hubtype-api-client.d.ts +9 -0
  49. package/lib/esm/hubtype-api-client.js +72 -0
  50. package/lib/esm/hubtype-api-client.js.map +1 -0
  51. package/lib/esm/index.d.ts +8 -5
  52. package/lib/esm/index.js +52 -4
  53. package/lib/esm/index.js.map +1 -1
  54. package/lib/esm/openai.d.ts +1 -0
  55. package/lib/esm/openai.js +19 -0
  56. package/lib/esm/openai.js.map +1 -0
  57. package/lib/esm/runner.d.ts +7 -0
  58. package/lib/esm/runner.js +31 -0
  59. package/lib/esm/runner.js.map +1 -0
  60. package/lib/esm/structured-output/carousel.d.ts +100 -0
  61. package/lib/esm/structured-output/carousel.js +18 -0
  62. package/lib/esm/structured-output/carousel.js.map +1 -0
  63. package/lib/esm/structured-output/exit.d.ts +12 -0
  64. package/lib/esm/structured-output/exit.js +7 -0
  65. package/lib/esm/structured-output/exit.js.map +1 -0
  66. package/lib/esm/structured-output/index.d.ts +198 -0
  67. package/lib/esm/structured-output/index.js +11 -0
  68. package/lib/esm/structured-output/index.js.map +1 -0
  69. package/lib/esm/structured-output/shared.d.ts +3 -0
  70. package/lib/esm/structured-output/shared.js +2 -0
  71. package/lib/esm/structured-output/shared.js.map +1 -0
  72. package/lib/esm/structured-output/text-with-buttons.d.ts +34 -0
  73. package/lib/esm/structured-output/text-with-buttons.js +11 -0
  74. package/lib/esm/structured-output/text-with-buttons.js.map +1 -0
  75. package/lib/esm/structured-output/text.d.ts +28 -0
  76. package/lib/esm/structured-output/text.js +10 -0
  77. package/lib/esm/structured-output/text.js.map +1 -0
  78. package/lib/esm/tools/index.d.ts +2 -0
  79. package/lib/esm/tools/index.js +2 -0
  80. package/lib/esm/tools/index.js.map +1 -0
  81. package/lib/esm/types.d.ts +21 -25
  82. package/package.json +7 -4
  83. package/src/agent-builder.ts +48 -0
  84. package/src/constants.ts +9 -0
  85. package/src/hubtype-api-client.ts +89 -0
  86. package/src/index.ts +77 -7
  87. package/src/openai.ts +30 -0
  88. package/src/runner.ts +43 -0
  89. package/src/structured-output/carousel.ts +36 -0
  90. package/src/structured-output/exit.ts +15 -0
  91. package/src/structured-output/index.ts +27 -0
  92. package/src/structured-output/shared.ts +3 -0
  93. package/src/structured-output/text-with-buttons.ts +23 -0
  94. package/src/structured-output/text.ts +19 -0
  95. package/src/tools/index.ts +3 -0
  96. package/src/types.ts +27 -23
  97. package/lib/cjs/ai-agent-client.d.ts +0 -12
  98. package/lib/cjs/ai-agent-client.js +0 -78
  99. package/lib/cjs/ai-agent-client.js.map +0 -1
  100. package/lib/cjs/errors.d.ts +0 -3
  101. package/lib/cjs/errors.js +0 -11
  102. package/lib/cjs/errors.js.map +0 -1
  103. package/lib/esm/ai-agent-client.d.ts +0 -12
  104. package/lib/esm/ai-agent-client.js +0 -74
  105. package/lib/esm/ai-agent-client.js.map +0 -1
  106. package/lib/esm/errors.d.ts +0 -3
  107. package/lib/esm/errors.js +0 -7
  108. package/lib/esm/errors.js.map +0 -1
  109. package/src/ai-agent-client.ts +0 -112
  110. package/src/errors.ts +0 -6
@@ -1,74 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai-agent-client.js","sourceRoot":"","sources":["../../src/ai-agent-client.ts"],"names":[],"mappings":";AAAA,y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,CAAC,IAAI,CAAA;QACtB,CAAC;KAAA;IAEO,SAAS,CAAC,OAAmB;QACnC,OAAO;YACL,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,OAAO,CAAC,OAAO,CAAC,aAAa,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"}
@@ -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,112 +0,0 @@
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
- }
package/src/errors.ts DELETED
@@ -1,6 +0,0 @@
1
- export class AiAgentError extends Error {
2
- constructor(message: string) {
3
- super(message)
4
- this.name = 'AiAgentError'
5
- }
6
- }