@botonic/plugin-ai-agents 0.43.0 → 0.44.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/agent-builder.d.ts +1 -1
- package/lib/cjs/agent-builder.js +8 -7
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/guardrails/input.js +4 -6
- package/lib/cjs/guardrails/input.js.map +1 -1
- package/lib/cjs/hubtype-api-client.js +94 -97
- package/lib/cjs/hubtype-api-client.js.map +1 -1
- package/lib/cjs/index.js +63 -70
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/openai.js +3 -4
- package/lib/cjs/openai.js.map +1 -1
- package/lib/cjs/runner.js +39 -41
- package/lib/cjs/runner.js.map +1 -1
- package/lib/cjs/tools/retrieve-knowledge.js +4 -5
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/agent-builder.d.ts +1 -1
- package/lib/esm/agent-builder.js +27 -22
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/constants.js +13 -10
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/guardrails/index.js +4 -1
- package/lib/esm/guardrails/index.js.map +1 -1
- package/lib/esm/guardrails/input.js +11 -9
- package/lib/esm/guardrails/input.js.map +1 -1
- package/lib/esm/hubtype-api-client.js +102 -101
- package/lib/esm/hubtype-api-client.js.map +1 -1
- package/lib/esm/index.js +76 -80
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/openai.js +24 -20
- package/lib/esm/openai.js.map +1 -1
- package/lib/esm/runner.js +47 -45
- package/lib/esm/runner.js.map +1 -1
- package/lib/esm/structured-output/carousel.js +15 -12
- package/lib/esm/structured-output/carousel.js.map +1 -1
- package/lib/esm/structured-output/exit.js +7 -3
- package/lib/esm/structured-output/exit.js.map +1 -1
- package/lib/esm/structured-output/index.js +10 -7
- package/lib/esm/structured-output/index.js.map +1 -1
- package/lib/esm/structured-output/text-with-buttons.js +12 -8
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
- package/lib/esm/structured-output/text.js +8 -5
- package/lib/esm/structured-output/text.js.map +1 -1
- package/lib/esm/tools/index.js +6 -2
- package/lib/esm/tools/index.js.map +1 -1
- package/lib/esm/tools/retrieve-knowledge.js +14 -12
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/types.js +2 -1
- package/package.json +5 -5
- package/src/agent-builder.ts +12 -8
- package/src/index.ts +2 -3
|
@@ -4,7 +4,7 @@ interface AIAgentBuilderOptions<TPlugins extends ResolvedPlugins = ResolvedPlugi
|
|
|
4
4
|
name: string;
|
|
5
5
|
instructions: string;
|
|
6
6
|
tools: Tool<TPlugins, TExtraData>[];
|
|
7
|
-
|
|
7
|
+
campaignsContext?: CampaignV2[];
|
|
8
8
|
contactInfo: ContactInfo[];
|
|
9
9
|
inputGuardrailRules: GuardrailRule[];
|
|
10
10
|
sourceIds: string[];
|
package/lib/cjs/agent-builder.js
CHANGED
|
@@ -9,7 +9,7 @@ const tools_1 = require("./tools");
|
|
|
9
9
|
class AIAgentBuilder {
|
|
10
10
|
constructor(options) {
|
|
11
11
|
this.name = options.name;
|
|
12
|
-
this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.
|
|
12
|
+
this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.campaignsContext);
|
|
13
13
|
this.tools = this.addHubtypeTools(options.tools, options.sourceIds);
|
|
14
14
|
this.inputGuardrails = [];
|
|
15
15
|
if (options.inputGuardrailRules.length > 0) {
|
|
@@ -20,7 +20,6 @@ class AIAgentBuilder {
|
|
|
20
20
|
build() {
|
|
21
21
|
const modelSettings = {};
|
|
22
22
|
if (constants_1.OPENAI_PROVIDER === 'openai') {
|
|
23
|
-
// @ts-expect-error - reasoning.effort is valid but we need to update openai and typescript dependencies
|
|
24
23
|
modelSettings.reasoning = { effort: 'none' };
|
|
25
24
|
modelSettings.text = { verbosity: 'medium' };
|
|
26
25
|
}
|
|
@@ -48,11 +47,11 @@ class AIAgentBuilder {
|
|
|
48
47
|
modelSettings,
|
|
49
48
|
});
|
|
50
49
|
}
|
|
51
|
-
addExtraInstructions(initialInstructions, contactInfo,
|
|
50
|
+
addExtraInstructions(initialInstructions, contactInfo, campaignsContext) {
|
|
52
51
|
const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`;
|
|
53
52
|
const metadataInstructions = this.getMetadataInstructions();
|
|
54
53
|
const contactInfoInstructions = this.getContactInfoInstructions(contactInfo);
|
|
55
|
-
const campaignInstructions = this.getCampaignInstructions(
|
|
54
|
+
const campaignInstructions = this.getCampaignInstructions(campaignsContext);
|
|
56
55
|
const outputInstructions = this.getOutputInstructions();
|
|
57
56
|
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`;
|
|
58
57
|
}
|
|
@@ -73,11 +72,13 @@ class AIAgentBuilder {
|
|
|
73
72
|
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
74
73
|
return `<metadata>\n${metadata}\n</metadata>`;
|
|
75
74
|
}
|
|
76
|
-
getCampaignInstructions(
|
|
77
|
-
if (!
|
|
75
|
+
getCampaignInstructions(campaignsContext) {
|
|
76
|
+
if (!campaignsContext || campaignsContext.length === 0) {
|
|
78
77
|
return '';
|
|
79
78
|
}
|
|
80
|
-
return
|
|
79
|
+
return campaignsContext
|
|
80
|
+
.map((campaign, index) => `<campaign_context${index + 1}>\n${campaign.agent_context}\n</campaign_context${index + 1}>`)
|
|
81
|
+
.join('\n');
|
|
81
82
|
}
|
|
82
83
|
getOutputInstructions() {
|
|
83
84
|
const example = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAKuB;AAEvB,2CAA2D;AAC3D,6CAAmD;AACnD,2DAAkD;AAClD,mCAA2D;AAgB3D,MAAa,cAAc;IASzB,YAAY,OAAoD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;YACzB,YAAY,CAAC,IAAI,CAAC,yBAAiB,CAAC,CAAA;QACtC,CAAC;QACD,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF;AApID,wCAoIC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createInputGuardrail =
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
3
|
+
exports.createInputGuardrail = createInputGuardrail;
|
|
5
4
|
const agents_1 = require("@openai/agents");
|
|
6
5
|
const zod_1 = require("zod");
|
|
7
6
|
function createInputGuardrail(rules) {
|
|
@@ -13,9 +12,9 @@ function createInputGuardrail(rules) {
|
|
|
13
12
|
});
|
|
14
13
|
return {
|
|
15
14
|
name: 'InputGuardrail',
|
|
16
|
-
execute: ({ input, context }) =>
|
|
15
|
+
execute: async ({ input, context }) => {
|
|
17
16
|
const lastMessage = input[input.length - 1];
|
|
18
|
-
const result =
|
|
17
|
+
const result = await (0, agents_1.run)(agent, [lastMessage], { context });
|
|
19
18
|
const finalOutput = result.finalOutput;
|
|
20
19
|
if (finalOutput === undefined) {
|
|
21
20
|
throw new Error('Guardrail agent failed to produce output');
|
|
@@ -26,8 +25,7 @@ function createInputGuardrail(rules) {
|
|
|
26
25
|
outputInfo: triggeredGuardrails,
|
|
27
26
|
tripwireTriggered: triggered,
|
|
28
27
|
};
|
|
29
|
-
}
|
|
28
|
+
},
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
|
-
exports.createInputGuardrail = createInputGuardrail;
|
|
33
31
|
//# sourceMappingURL=input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/guardrails/input.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/guardrails/input.ts"],"names":[],"mappings":";;AAKA,oDAiCC;AAtCD,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AAE,SAAS;aAC7B,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -8,112 +8,109 @@ class HubtypeApiClient {
|
|
|
8
8
|
constructor(authToken) {
|
|
9
9
|
this.authToken = authToken;
|
|
10
10
|
}
|
|
11
|
-
retrieveSimilarChunks(query, sourceIds) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return chunks;
|
|
29
|
-
});
|
|
11
|
+
async retrieveSimilarChunks(query, sourceIds) {
|
|
12
|
+
const url = `${constants_1.HUBTYPE_API_URL}/external/v1/ai/knowledge_base/similar_chunks/`;
|
|
13
|
+
const headers = {
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
16
|
+
};
|
|
17
|
+
const params = {
|
|
18
|
+
query,
|
|
19
|
+
source_ids: sourceIds,
|
|
20
|
+
num_chunks: 5,
|
|
21
|
+
};
|
|
22
|
+
const response = await axios_1.default.post(url, params, { headers });
|
|
23
|
+
const chunks = response.data.chunks.map((chunk) => ({
|
|
24
|
+
id: chunk.id,
|
|
25
|
+
text: chunk.text,
|
|
26
|
+
}));
|
|
27
|
+
return chunks;
|
|
30
28
|
}
|
|
31
|
-
getLocalMessages(maxMemoryLength) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return filteredMessages.slice(-maxMemoryLength);
|
|
46
|
-
});
|
|
29
|
+
async getLocalMessages(maxMemoryLength) {
|
|
30
|
+
const localBotonicState = typeof globalThis !== 'undefined' && globalThis.localStorage
|
|
31
|
+
? globalThis.localStorage.getItem('botonicState')
|
|
32
|
+
: null;
|
|
33
|
+
const botonicState = JSON.parse(localBotonicState || '{}');
|
|
34
|
+
const messages = botonicState.messages;
|
|
35
|
+
const filteredMessages = messages
|
|
36
|
+
.filter(message => message.data.text)
|
|
37
|
+
.map(message => ({
|
|
38
|
+
role: message.sentBy === 'user' ? 'user' : 'assistant',
|
|
39
|
+
content: message.data.text,
|
|
40
|
+
}))
|
|
41
|
+
.map(message => this.formatMessage(message));
|
|
42
|
+
return filteredMessages.slice(-maxMemoryLength);
|
|
47
43
|
}
|
|
48
|
-
getMessages(request, maxMemoryLength) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
});
|
|
44
|
+
async getMessages(request, maxMemoryLength) {
|
|
45
|
+
const url = `${constants_1.HUBTYPE_API_URL}/external/v1/ai/agent/message_history/`;
|
|
46
|
+
const headers = {
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
49
|
+
};
|
|
50
|
+
const params = {
|
|
51
|
+
last_message_id: request.input.message_id,
|
|
52
|
+
num_messages: maxMemoryLength,
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
const response = await axios_1.default.get(url, {
|
|
56
|
+
headers,
|
|
57
|
+
params,
|
|
58
|
+
});
|
|
59
|
+
const messages = response.data.messages;
|
|
60
|
+
return messages.map(message => this.formatMessage(message));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error(error);
|
|
64
|
+
throw new Error('Failed to get messages from Hubtype');
|
|
65
|
+
}
|
|
72
66
|
}
|
|
73
|
-
getMessagesV2(request, options = {}) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
async getMessagesV2(request, options = {}) {
|
|
68
|
+
const url = `${constants_1.HUBTYPE_API_URL}/external/v2/ai/agent/message_history/`;
|
|
69
|
+
const headers = {
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
72
|
+
};
|
|
73
|
+
const params = {
|
|
74
|
+
last_message_id: request.input.message_id,
|
|
75
|
+
...(options.maxMessages !== undefined && {
|
|
81
76
|
max_messages: options.maxMessages,
|
|
82
|
-
})
|
|
77
|
+
}),
|
|
78
|
+
...(options.includeToolCalls !== undefined && {
|
|
83
79
|
include_tool_calls: options.includeToolCalls,
|
|
84
|
-
})
|
|
80
|
+
}),
|
|
81
|
+
...(options.maxFullToolResults !== undefined && {
|
|
85
82
|
max_full_tool_results: options.maxFullToolResults,
|
|
86
|
-
})
|
|
83
|
+
}),
|
|
84
|
+
...(options.debugMode !== undefined && {
|
|
87
85
|
debug_mode: options.debugMode,
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
86
|
+
}),
|
|
87
|
+
};
|
|
88
|
+
try {
|
|
89
|
+
const response = await axios_1.default.get(url, {
|
|
90
|
+
headers,
|
|
91
|
+
params,
|
|
92
|
+
});
|
|
93
|
+
const { messages, conversation_id, truncated } = response.data;
|
|
94
|
+
const formattedMessages = messages
|
|
95
|
+
.map(message => this.formatMessageV2(message))
|
|
96
|
+
.filter((message) => message !== null);
|
|
97
|
+
return {
|
|
98
|
+
messages: formattedMessages,
|
|
99
|
+
conversationId: conversation_id,
|
|
100
|
+
truncated,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error(error);
|
|
105
|
+
throw new Error('Failed to get messages from Hubtype V2 API');
|
|
106
|
+
}
|
|
109
107
|
}
|
|
110
108
|
formatMessageV2(message) {
|
|
111
|
-
var _a, _b, _c, _d, _e;
|
|
112
109
|
switch (message.role) {
|
|
113
110
|
case 'user':
|
|
114
111
|
return {
|
|
115
112
|
role: 'user',
|
|
116
|
-
content:
|
|
113
|
+
content: message.content ?? '',
|
|
117
114
|
};
|
|
118
115
|
case 'assistant': {
|
|
119
116
|
const assistantMessage = message;
|
|
@@ -124,7 +121,7 @@ class HubtypeApiClient {
|
|
|
124
121
|
assistantMessage.tool_calls.length > 0) {
|
|
125
122
|
return {
|
|
126
123
|
role: 'assistant',
|
|
127
|
-
content:
|
|
124
|
+
content: assistantMessage.content ?? '',
|
|
128
125
|
tool_calls: assistantMessage.tool_calls.map(tc => ({
|
|
129
126
|
id: tc.id,
|
|
130
127
|
type: tc.type,
|
|
@@ -141,7 +138,7 @@ class HubtypeApiClient {
|
|
|
141
138
|
content: [
|
|
142
139
|
{
|
|
143
140
|
type: 'output_text',
|
|
144
|
-
text:
|
|
141
|
+
text: assistantMessage.content ?? '',
|
|
145
142
|
},
|
|
146
143
|
],
|
|
147
144
|
status: 'completed',
|
|
@@ -155,13 +152,13 @@ class HubtypeApiClient {
|
|
|
155
152
|
return {
|
|
156
153
|
role: 'tool',
|
|
157
154
|
tool_call_id: toolMessage.tool_call_id,
|
|
158
|
-
content:
|
|
155
|
+
content: toolMessage.content ?? '',
|
|
159
156
|
};
|
|
160
157
|
}
|
|
161
158
|
case 'system':
|
|
162
159
|
return {
|
|
163
160
|
role: 'system',
|
|
164
|
-
content:
|
|
161
|
+
content: message.content ?? '',
|
|
165
162
|
};
|
|
166
163
|
default:
|
|
167
164
|
throw new Error(`Invalid message role: ${message.role}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-api-client.js","sourceRoot":"","sources":["../../src/hubtype-api-client.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AAEzB,2CAA6C;AAgF7C,MAAa,gBAAgB;IAG3B,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;
|
|
1
|
+
{"version":3,"file":"hubtype-api-client.js","sourceRoot":"","sources":["../../src/hubtype-api-client.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AAEzB,2CAA6C;AAgF7C,MAAa,gBAAgB;IAG3B,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAED,KAAK,CAAC,qBAAqB,CACzB,KAAa,EACb,SAAmB;QAEnB,MAAM,GAAG,GAAG,GAAG,2BAAe,gDAAgD,CAAA;QAC9E,MAAM,OAAO,GAAG;YACd,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;SAC1C,CAAA;QACD,MAAM,MAAM,GAAG;YACb,KAAK;YACL,UAAU,EAAE,SAAS;YACrB,UAAU,EAAE,CAAC;SACd,CAAA;QACD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;QAC3D,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC;YACzD,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC,CAAC,CAAA;QACH,OAAO,MAAM,CAAA;IACf,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,eAAuB;QAEvB,MAAM,iBAAiB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AI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;CACF;AA/MD,4CA+MC"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -9,87 +9,80 @@ const openai_1 = require("./openai");
|
|
|
9
9
|
const runner_1 = require("./runner");
|
|
10
10
|
class BotonicPluginAiAgents {
|
|
11
11
|
constructor(options) {
|
|
12
|
-
var _a, _b;
|
|
13
12
|
this.toolDefinitions = [];
|
|
14
|
-
(0, openai_1.setUpOpenAI)(options
|
|
15
|
-
if (
|
|
13
|
+
(0, openai_1.setUpOpenAI)(options?.maxRetries, options?.timeout);
|
|
14
|
+
if (options?.messageHistoryApiVersion === 'v1' && options?.memory) {
|
|
16
15
|
throw new Error('Cannot use memory when messageHistoryApiVersion is "v1". ' +
|
|
17
16
|
'Either set messageHistoryApiVersion to "v2" or remove memory.');
|
|
18
17
|
}
|
|
19
|
-
this.authToken = options
|
|
20
|
-
this.toolDefinitions =
|
|
21
|
-
this.messageHistoryApiVersion =
|
|
22
|
-
this.memory =
|
|
18
|
+
this.authToken = options?.authToken;
|
|
19
|
+
this.toolDefinitions = options?.customTools || [];
|
|
20
|
+
this.messageHistoryApiVersion = options?.messageHistoryApiVersion ?? 'v2';
|
|
21
|
+
this.memory = options?.memory ?? {};
|
|
23
22
|
}
|
|
24
23
|
pre() {
|
|
25
24
|
return;
|
|
26
25
|
}
|
|
27
|
-
getInference(request, aiAgentArgs) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!authToken) {
|
|
33
|
-
throw new Error('Auth token is required');
|
|
34
|
-
}
|
|
35
|
-
const tools = this.buildTools(((_a = aiAgentArgs.activeTools) === null || _a === void 0 ? void 0 : _a.map(tool => tool.name)) || []);
|
|
36
|
-
const agent = new agent_builder_1.AIAgentBuilder({
|
|
37
|
-
name: aiAgentArgs.name,
|
|
38
|
-
instructions: aiAgentArgs.instructions,
|
|
39
|
-
tools: tools,
|
|
40
|
-
contactInfo: request.session.user.contact_info || [],
|
|
41
|
-
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
42
|
-
sourceIds: aiAgentArgs.sourceIds || [],
|
|
43
|
-
campaignContext: (_b = request.input.context) === null || _b === void 0 ? void 0 : _b.campaign_v2,
|
|
44
|
-
}).build();
|
|
45
|
-
const messages = yield this.getMessages(request, authToken, constants_1.MAX_MEMORY_LENGTH);
|
|
46
|
-
const context = {
|
|
47
|
-
authToken,
|
|
48
|
-
sourceIds: aiAgentArgs.sourceIds || [],
|
|
49
|
-
knowledgeUsed: {
|
|
50
|
-
query: '',
|
|
51
|
-
sourceIds: [],
|
|
52
|
-
chunksIds: [],
|
|
53
|
-
chunkTexts: [],
|
|
54
|
-
},
|
|
55
|
-
request,
|
|
56
|
-
};
|
|
57
|
-
const runner = new runner_1.AIAgentRunner(agent);
|
|
58
|
-
return yield runner.run(messages, context);
|
|
26
|
+
async getInference(request, aiAgentArgs) {
|
|
27
|
+
try {
|
|
28
|
+
const authToken = constants_1.isProd ? request.session._access_token : this.authToken;
|
|
29
|
+
if (!authToken) {
|
|
30
|
+
throw new Error('Auth token is required');
|
|
59
31
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
32
|
+
const tools = this.buildTools(aiAgentArgs.activeTools?.map(tool => tool.name) || []);
|
|
33
|
+
const agent = new agent_builder_1.AIAgentBuilder({
|
|
34
|
+
name: aiAgentArgs.name,
|
|
35
|
+
instructions: aiAgentArgs.instructions,
|
|
36
|
+
tools: tools,
|
|
37
|
+
contactInfo: request.session.user.contact_info || [],
|
|
38
|
+
inputGuardrailRules: aiAgentArgs.inputGuardrailRules || [],
|
|
39
|
+
sourceIds: aiAgentArgs.sourceIds || [],
|
|
40
|
+
campaignsContext: request.input.context?.campaigns_v2,
|
|
41
|
+
}).build();
|
|
42
|
+
const messages = await this.getMessages(request, authToken, constants_1.MAX_MEMORY_LENGTH);
|
|
43
|
+
const context = {
|
|
44
|
+
authToken,
|
|
45
|
+
sourceIds: aiAgentArgs.sourceIds || [],
|
|
46
|
+
knowledgeUsed: {
|
|
47
|
+
query: '',
|
|
48
|
+
sourceIds: [],
|
|
49
|
+
chunksIds: [],
|
|
50
|
+
chunkTexts: [],
|
|
51
|
+
},
|
|
52
|
+
request,
|
|
53
|
+
};
|
|
54
|
+
const runner = new runner_1.AIAgentRunner(agent);
|
|
55
|
+
return await runner.run(messages, context);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('error plugin returns undefined', error);
|
|
59
|
+
return {
|
|
60
|
+
messages: [],
|
|
61
|
+
toolsExecuted: [],
|
|
62
|
+
memoryLength: 0,
|
|
63
|
+
exit: true,
|
|
64
|
+
error: true,
|
|
65
|
+
inputGuardrailsTriggered: [],
|
|
66
|
+
outputGuardrailsTriggered: [],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
73
69
|
}
|
|
74
|
-
getMessages(request, authToken, memoryLength) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
maxFullToolResults: (_c = this.memory.maxFullToolResults) !== null && _c !== void 0 ? _c : 1,
|
|
89
|
-
debugMode: (_d = this.memory.debugMode) !== null && _d !== void 0 ? _d : false,
|
|
90
|
-
});
|
|
91
|
-
return result.messages;
|
|
70
|
+
async getMessages(request, authToken, memoryLength) {
|
|
71
|
+
const hubtypeClient = new hubtype_api_client_1.HubtypeApiClient(authToken);
|
|
72
|
+
if (!constants_1.isProd) {
|
|
73
|
+
return await hubtypeClient.getLocalMessages(memoryLength);
|
|
74
|
+
}
|
|
75
|
+
if (this.messageHistoryApiVersion === 'v1') {
|
|
76
|
+
return await hubtypeClient.getMessages(request, memoryLength);
|
|
77
|
+
}
|
|
78
|
+
// Default to V2
|
|
79
|
+
const result = await hubtypeClient.getMessagesV2(request, {
|
|
80
|
+
maxMessages: this.memory.maxMessages ?? memoryLength,
|
|
81
|
+
includeToolCalls: this.memory.includeToolCalls ?? true,
|
|
82
|
+
maxFullToolResults: this.memory.maxFullToolResults ?? 1,
|
|
83
|
+
debugMode: this.memory.debugMode ?? false,
|
|
92
84
|
});
|
|
85
|
+
return result.messages;
|
|
93
86
|
}
|
|
94
87
|
buildTools(activeToolNames) {
|
|
95
88
|
const availableTools = this.toolDefinitions.filter(tool => activeToolNames.includes(tool.name));
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAuD;AACvD,6DAAuD;AACvD,qCAAsC;AACtC,qCAAwC;AAYxC,MAAqB,qBAAqB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,2CAAqC;AAErC,mDAAgD;AAChD,2CAAuD;AACvD,6DAAuD;AACvD,qCAAsC;AACtC,qCAAwC;AAYxC,MAAqB,qBAAqB;IASxC,YAAY,OAAoD;QAFzD,oBAAe,GAAuC,EAAE,CAAA;QAG7D,IAAA,oBAAW,EAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QAElD,IAAI,OAAO,EAAE,wBAAwB,KAAK,IAAI,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;YAClE,MAAM,IAAI,KAAK,CACb,2DAA2D;gBACzD,+DAA+D,CAClE,CAAA;QACH,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,CAAA;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,EAAE,W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B,EAAE,IAAI,CAAC,MAAM,CAAC,kBAAkB,IAAI,CAAC;YACvD,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK;SAC1C,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,QAAQ,CAAA;IACxB,CAAC;IAEO,UAAU,CAAC,eAAyB;QAC1C,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CACxD,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAA;QACD,OAAO,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;YACzC,OAAO,IAAA,aAAI,EAA0C;gBACnD,IAAI,EAAE,cAAc,CAAC,IAAI;gBACzB,WAAW,EAAE,cAAc,CAAC,WAAW;gBACvC,UAAU,EAAE,cAAc,CAAC,MAAM;gBACjC,OAAO,EAAE,cAAc,CAAC,IAAI;aAC7B,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AA3HD,wCA2HC;AAED,kDAAuB"}
|
package/lib/cjs/openai.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setUpOpenAI =
|
|
3
|
+
exports.setUpOpenAI = setUpOpenAI;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const agents_1 = require("@openai/agents");
|
|
6
6
|
const openai_1 = tslib_1.__importStar(require("openai"));
|
|
@@ -15,11 +15,10 @@ function setUpOpenAI(maxRetries, timeout) {
|
|
|
15
15
|
(0, agents_1.setOpenAIAPI)('chat_completions');
|
|
16
16
|
(0, agents_1.setTracingDisabled)(true);
|
|
17
17
|
}
|
|
18
|
-
exports.setUpOpenAI = setUpOpenAI;
|
|
19
18
|
function setOpenAIClient(maxRetries, timeout) {
|
|
20
19
|
const client = new openai_1.default({
|
|
21
20
|
apiKey: constants_1.OPENAI_API_KEY,
|
|
22
|
-
timeout: timeout || 16000,
|
|
21
|
+
timeout: timeout || 16000, // 16 seconds
|
|
23
22
|
maxRetries: maxRetries || 2,
|
|
24
23
|
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
25
24
|
});
|
|
@@ -31,7 +30,7 @@ function setAzureOpenAIClient(maxRetries, timeout) {
|
|
|
31
30
|
apiVersion: constants_1.AZURE_OPENAI_API_VERSION,
|
|
32
31
|
deployment: constants_1.AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
33
32
|
baseURL: constants_1.AZURE_OPENAI_API_BASE,
|
|
34
|
-
timeout: timeout || 16000,
|
|
33
|
+
timeout: timeout || 16000, // 16 seconds
|
|
35
34
|
maxRetries: maxRetries || 2,
|
|
36
35
|
dangerouslyAllowBrowser: !constants_1.isProd,
|
|
37
36
|
});
|
package/lib/cjs/openai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/openai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/openai.ts"],"names":[],"mappings":";;AAiBA,kCAQC;;AAzBD,2CAIuB;AACvB,yDAA4C;AAE5C,2CAQoB;AAEpB,SAAgB,WAAW,CAAC,UAAmB,EAAE,OAAgB;IAC/D,IAAI,2BAAe,KAAK,OAAO,EAAE,CAAC;QAChC,oBAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC;SAAM,CAAC;QACN,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC;IACD,IAAA,qBAAY,EAAC,kBAAkB,CAAC,CAAA;IAChC,IAAA,2BAAkB,EAAC,IAAI,CAAC,CAAA;AAC1B,CAAC;AAED,SAAS,eAAe,CAAC,UAAmB,EAAE,OAAgB;IAC5D,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC;QACxB,MAAM,EAAE,0BAAc;QACtB,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,aAAa;QACxC,UAAU,EAAE,UAAU,IAAI,CAAC;QAC3B,uBAAuB,EAAE,CAAC,kBAAM;KACjC,CAAC,CAAA;IACF,IAAA,+BAAsB,EAAC,MAAM,CAAC,CAAA;AAChC,CAAC;AAED,SAAS,oBAAoB,CAAC,UAAmB,EAAE,OAAgB;IACjE,MAAM,MAAM,GAAG,IAAI,oBAAW,CAAC;QAC7B,MAAM,EAAE,gCAAoB;QAC5B,UAAU,EAAE,oCAAwB;QACpC,UAAU,EAAE,4CAAgC;QAC5C,OAAO,EAAE,iCAAqB;QAC9B,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,aAAa;QACxC,UAAU,EAAE,UAAU,IAAI,CAAC;QAC3B,uBAAuB,EAAE,CAAC,kBAAM;KACjC,CAAC,CAAA;IACF,IAAA,+BAAsB,EAAC,MAAM,CAAC,CAAA;AAChC,CAAC"}
|