@botonic/plugin-ai-agents 0.56.0-alpha.0 → 0.57.0-rslib-esm.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/agents/base-agent.d.ts +4 -4
- package/lib/esm/agents/base-agent.js +47 -20
- package/lib/esm/agents/base-agent.js.map +1 -1
- package/lib/esm/agents/index.d.ts +2 -2
- package/lib/esm/agents/index.js +8 -7
- package/lib/esm/agents/index.js.map +1 -1
- package/lib/esm/agents/router-agent.d.ts +5 -5
- package/lib/esm/agents/router-agent.js +32 -15
- package/lib/esm/agents/router-agent.js.map +1 -1
- package/lib/esm/agents/specialist-agent.d.ts +5 -5
- package/lib/esm/agents/specialist-agent.js +65 -45
- package/lib/esm/agents/specialist-agent.js.map +1 -1
- package/lib/esm/bot-config-tools.d.ts +1 -1
- package/lib/esm/bot-config-tools.js +15 -13
- package/lib/esm/bot-config-tools.js.map +1 -1
- package/lib/esm/constants.js +18 -17
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/debug-logger.d.ts +1 -1
- package/lib/esm/debug-logger.js +14 -9
- package/lib/esm/debug-logger.js.map +1 -1
- package/lib/esm/guardrails/index.d.ts +1 -1
- package/lib/esm/guardrails/index.js +5 -4
- package/lib/esm/guardrails/index.js.map +1 -1
- package/lib/esm/guardrails/input.d.ts +2 -2
- package/lib/esm/guardrails/input.js +65 -42
- package/lib/esm/guardrails/input.js.map +1 -1
- package/lib/esm/index.d.ts +3 -3
- package/lib/esm/index.js +114 -74
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/llm-config.d.ts +1 -1
- package/lib/esm/llm-config.js +81 -52
- package/lib/esm/llm-config.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/runners/base-runner.d.ts +3 -3
- package/lib/esm/runners/base-runner.js +81 -69
- package/lib/esm/runners/base-runner.js.map +1 -1
- package/lib/esm/runners/index.d.ts +2 -2
- package/lib/esm/runners/index.js +8 -7
- package/lib/esm/runners/index.js.map +1 -1
- package/lib/esm/runners/router-runner.d.ts +2 -2
- package/lib/esm/runners/router-runner.js +19 -14
- package/lib/esm/runners/router-runner.js.map +1 -1
- package/lib/esm/runners/specialist-runner.d.ts +1 -1
- package/lib/esm/runners/specialist-runner.js +8 -6
- package/lib/esm/runners/specialist-runner.js.map +1 -1
- package/lib/esm/services/hubtype-api-client.d.ts +2 -2
- package/lib/esm/services/hubtype-api-client.js +110 -95
- package/lib/esm/services/hubtype-api-client.js.map +1 -1
- package/lib/esm/services/types.d.ts +1 -1
- package/lib/esm/services/types.js +9 -9
- package/lib/esm/services/types.js.map +1 -1
- package/lib/esm/structured-output/bot-executor.js +20 -17
- package/lib/esm/structured-output/bot-executor.js.map +1 -1
- package/lib/esm/structured-output/carousel.js +25 -22
- package/lib/esm/structured-output/carousel.js.map +1 -1
- package/lib/esm/structured-output/exit.js +13 -10
- package/lib/esm/structured-output/exit.js.map +1 -1
- package/lib/esm/structured-output/index.d.ts +0 -10
- package/lib/esm/structured-output/index.js +39 -29
- package/lib/esm/structured-output/index.js.map +1 -1
- package/lib/esm/structured-output/text-with-buttons.js +24 -23
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
- package/lib/esm/structured-output/text.js +16 -13
- package/lib/esm/structured-output/text.js.map +1 -1
- package/lib/esm/tools/index.d.ts +2 -2
- package/lib/esm/tools/index.js +7 -7
- package/lib/esm/tools/index.js.map +1 -1
- package/lib/esm/tools/retrieve-knowledge.d.ts +2 -2
- package/lib/esm/tools/retrieve-knowledge.js +38 -32
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/types.d.ts +3 -3
- package/lib/esm/types.js +4 -2
- package/lib/esm/types.js.map +1 -1
- package/package.json +8 -7
- package/src/structured-output/index.ts +0 -2
- package/src/types.ts +4 -4
- package/lib/cjs/agents/base-agent.d.ts +0 -28
- package/lib/cjs/agents/base-agent.js +0 -39
- package/lib/cjs/agents/base-agent.js.map +0 -1
- package/lib/cjs/agents/index.d.ts +0 -2
- package/lib/cjs/agents/index.js +0 -8
- package/lib/cjs/agents/index.js.map +0 -1
- package/lib/cjs/agents/router-agent.d.ts +0 -25
- package/lib/cjs/agents/router-agent.js +0 -33
- package/lib/cjs/agents/router-agent.js.map +0 -1
- package/lib/cjs/agents/specialist-agent.d.ts +0 -39
- package/lib/cjs/agents/specialist-agent.js +0 -108
- package/lib/cjs/agents/specialist-agent.js.map +0 -1
- package/lib/cjs/bot-config-tools.d.ts +0 -7
- package/lib/cjs/bot-config-tools.js +0 -18
- package/lib/cjs/bot-config-tools.js.map +0 -1
- package/lib/cjs/constants.d.ts +0 -21
- package/lib/cjs/constants.js +0 -25
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/debug-logger.d.ts +0 -33
- package/lib/cjs/debug-logger.js +0 -116
- package/lib/cjs/debug-logger.js.map +0 -1
- package/lib/cjs/guardrails/index.d.ts +0 -1
- package/lib/cjs/guardrails/index.js +0 -5
- package/lib/cjs/guardrails/index.js.map +0 -1
- package/lib/cjs/guardrails/input.d.ts +0 -10
- package/lib/cjs/guardrails/input.js +0 -96
- package/lib/cjs/guardrails/input.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -22
- package/lib/cjs/index.js +0 -219
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/llm-config.d.ts +0 -30
- package/lib/cjs/llm-config.js +0 -121
- package/lib/cjs/llm-config.js.map +0 -1
- package/lib/cjs/runners/base-runner.d.ts +0 -31
- package/lib/cjs/runners/base-runner.js +0 -189
- package/lib/cjs/runners/base-runner.js.map +0 -1
- package/lib/cjs/runners/index.d.ts +0 -2
- package/lib/cjs/runners/index.js +0 -8
- package/lib/cjs/runners/index.js.map +0 -1
- package/lib/cjs/runners/router-runner.d.ts +0 -8
- package/lib/cjs/runners/router-runner.js +0 -44
- package/lib/cjs/runners/router-runner.js.map +0 -1
- package/lib/cjs/runners/specialist-runner.d.ts +0 -4
- package/lib/cjs/runners/specialist-runner.js +0 -8
- package/lib/cjs/runners/specialist-runner.js.map +0 -1
- package/lib/cjs/services/hubtype-api-client.d.ts +0 -13
- package/lib/cjs/services/hubtype-api-client.js +0 -176
- package/lib/cjs/services/hubtype-api-client.js.map +0 -1
- package/lib/cjs/services/types.d.ts +0 -72
- package/lib/cjs/services/types.js +0 -13
- package/lib/cjs/services/types.js.map +0 -1
- package/lib/cjs/structured-output/bot-executor.d.ts +0 -13
- package/lib/cjs/structured-output/bot-executor.js +0 -18
- package/lib/cjs/structured-output/bot-executor.js.map +0 -1
- package/lib/cjs/structured-output/carousel.d.ts +0 -18
- package/lib/cjs/structured-output/carousel.js +0 -23
- package/lib/cjs/structured-output/carousel.js.map +0 -1
- package/lib/cjs/structured-output/exit.d.ts +0 -6
- package/lib/cjs/structured-output/exit.js +0 -11
- package/lib/cjs/structured-output/exit.js.map +0 -1
- package/lib/cjs/structured-output/index.d.ts +0 -108
- package/lib/cjs/structured-output/index.js +0 -45
- package/lib/cjs/structured-output/index.js.map +0 -1
- package/lib/cjs/structured-output/request-contact-info.d.ts +0 -9
- package/lib/cjs/structured-output/request-contact-info.js +0 -14
- package/lib/cjs/structured-output/request-contact-info.js.map +0 -1
- package/lib/cjs/structured-output/text-with-buttons.d.ts +0 -17
- package/lib/cjs/structured-output/text-with-buttons.js +0 -24
- package/lib/cjs/structured-output/text-with-buttons.js.map +0 -1
- package/lib/cjs/structured-output/text.d.ts +0 -9
- package/lib/cjs/structured-output/text.js +0 -14
- package/lib/cjs/structured-output/text.js.map +0 -1
- package/lib/cjs/tools/index.d.ts +0 -3
- package/lib/cjs/tools/index.js +0 -8
- package/lib/cjs/tools/index.js.map +0 -1
- package/lib/cjs/tools/retrieve-knowledge.d.ts +0 -6
- package/lib/cjs/tools/retrieve-knowledge.js +0 -34
- package/lib/cjs/tools/retrieve-knowledge.js.map +0 -1
- package/lib/cjs/types.d.ts +0 -53
- package/lib/cjs/types.js +0 -3
- package/lib/cjs/types.js.map +0 -1
- package/lib/esm/structured-output/request-contact-info.d.ts +0 -9
- package/lib/esm/structured-output/request-contact-info.js +0 -14
- package/lib/esm/structured-output/request-contact-info.js.map +0 -1
- package/src/structured-output/request-contact-info.ts +0 -18
|
@@ -1,134 +1,144 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { HUBTYPE_API_URL } from "../constants.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/* eslint-disable @typescript-eslint/naming-convention */ function _define_property(obj, key, value) {
|
|
7
|
+
if (key in obj) {
|
|
8
|
+
Object.defineProperty(obj, key, {
|
|
9
|
+
value: value,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true
|
|
13
|
+
});
|
|
14
|
+
} else obj[key] = value;
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
7
19
|
class HubtypeApiClient {
|
|
8
|
-
constructor(authToken) {
|
|
9
|
-
this.authToken = authToken;
|
|
10
|
-
}
|
|
11
20
|
async retrieveSimilarChunks(query, sourceIds) {
|
|
12
|
-
const url = `${
|
|
21
|
+
const url = `${HUBTYPE_API_URL}/external/v1/ai/knowledge_base/similar_chunks/`;
|
|
13
22
|
const headers = {
|
|
14
23
|
'Content-Type': 'application/json',
|
|
15
|
-
Authorization: `Bearer ${this.authToken}
|
|
24
|
+
Authorization: `Bearer ${this.authToken}`
|
|
16
25
|
};
|
|
17
26
|
const params = {
|
|
18
27
|
query,
|
|
19
28
|
source_ids: sourceIds,
|
|
20
|
-
num_chunks: 5
|
|
29
|
+
num_chunks: 5
|
|
21
30
|
};
|
|
22
|
-
const response = await
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
const response = await axios.post(url, params, {
|
|
32
|
+
headers
|
|
33
|
+
});
|
|
34
|
+
const chunks = response.data.chunks.map((chunk)=>({
|
|
35
|
+
id: chunk.id,
|
|
36
|
+
text: chunk.text
|
|
37
|
+
}));
|
|
27
38
|
return chunks;
|
|
28
39
|
}
|
|
29
40
|
async getLocalMessages(maxMemoryLength, previousHubtypeMessages, localStorageKey) {
|
|
30
|
-
const localBotonicState = typeof globalThis !== 'undefined' && globalThis.localStorage
|
|
31
|
-
? globalThis.localStorage.getItem(localStorageKey)
|
|
32
|
-
: null;
|
|
41
|
+
const localBotonicState = typeof globalThis !== 'undefined' && globalThis.localStorage ? globalThis.localStorage.getItem(localStorageKey) : null;
|
|
33
42
|
const botonicState = JSON.parse(localBotonicState || '{}');
|
|
34
43
|
const messages = botonicState.messages;
|
|
35
|
-
const filteredMessages = messages
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
const filteredMessages = messages.filter((message)=>message.data.text).map((message)=>({
|
|
45
|
+
role: message.sentBy === 'user' ? 'user' : 'assistant',
|
|
46
|
+
content: message.data.text
|
|
47
|
+
})).map((message)=>this.formatMessage(message));
|
|
48
|
+
const resultMessages = [
|
|
49
|
+
...filteredMessages,
|
|
50
|
+
...previousHubtypeMessages
|
|
51
|
+
];
|
|
43
52
|
return resultMessages.slice(-maxMemoryLength);
|
|
44
53
|
}
|
|
45
54
|
async getMessagesV2(botContext, options, previousHubtypeMessages) {
|
|
46
|
-
const url = `${
|
|
55
|
+
const url = `${HUBTYPE_API_URL}/external/v2/ai/agent/message_history/`;
|
|
47
56
|
const headers = {
|
|
48
57
|
'Content-Type': 'application/json',
|
|
49
|
-
Authorization: `Bearer ${this.authToken}
|
|
58
|
+
Authorization: `Bearer ${this.authToken}`
|
|
50
59
|
};
|
|
51
60
|
const params = {
|
|
52
61
|
last_message_id: botContext.input.message_id,
|
|
53
62
|
max_messages: options.maxMessages,
|
|
54
63
|
include_tool_calls: options.includeToolCalls,
|
|
55
64
|
max_full_tool_results: options.maxFullToolResults,
|
|
56
|
-
debug_mode: options.debugMode
|
|
65
|
+
debug_mode: options.debugMode
|
|
57
66
|
};
|
|
58
67
|
try {
|
|
59
|
-
const response = await
|
|
68
|
+
const response = await axios.get(url, {
|
|
60
69
|
headers,
|
|
61
|
-
params
|
|
70
|
+
params
|
|
62
71
|
});
|
|
63
72
|
const { messages, conversation_id, truncated } = response.data;
|
|
64
|
-
const formattedMessages = [
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
const formattedMessages = [
|
|
74
|
+
...messages,
|
|
75
|
+
...previousHubtypeMessages
|
|
76
|
+
].map((message)=>this.formatMessageV2(message)).filter((message)=>message !== null);
|
|
67
77
|
return {
|
|
68
78
|
messages: formattedMessages,
|
|
69
79
|
conversationId: conversation_id,
|
|
70
|
-
truncated
|
|
80
|
+
truncated
|
|
71
81
|
};
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
82
|
+
} catch (error) {
|
|
74
83
|
console.error(error);
|
|
75
84
|
throw new Error('Failed to get messages from Hubtype V2 API');
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
87
|
formatMessageV2(message) {
|
|
79
|
-
switch
|
|
88
|
+
switch(message.role){
|
|
80
89
|
case 'user':
|
|
81
90
|
return {
|
|
82
91
|
role: 'user',
|
|
83
|
-
content: message.content ?? ''
|
|
92
|
+
content: message.content ?? ''
|
|
84
93
|
};
|
|
85
|
-
case 'assistant':
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
assistantMessage.tool_calls.length > 0) {
|
|
94
|
+
case 'assistant':
|
|
95
|
+
{
|
|
96
|
+
const assistantMessage = message;
|
|
97
|
+
// If assistant message has tool_calls, include them for context
|
|
98
|
+
// Using double assertion as the OpenAI API supports this format,
|
|
99
|
+
// but the agents SDK types are more restrictive
|
|
100
|
+
if (assistantMessage.tool_calls && assistantMessage.tool_calls.length > 0) {
|
|
101
|
+
return {
|
|
102
|
+
role: 'assistant',
|
|
103
|
+
content: assistantMessage.content ?? '',
|
|
104
|
+
tool_calls: assistantMessage.tool_calls.map((tc)=>({
|
|
105
|
+
id: tc.id,
|
|
106
|
+
type: tc.type,
|
|
107
|
+
function: {
|
|
108
|
+
name: tc.function.name,
|
|
109
|
+
arguments: tc.function.arguments
|
|
110
|
+
}
|
|
111
|
+
}))
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// Regular assistant message without tool_calls
|
|
92
115
|
return {
|
|
93
116
|
role: 'assistant',
|
|
94
|
-
content:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
117
|
+
content: [
|
|
118
|
+
{
|
|
119
|
+
type: 'output_text',
|
|
120
|
+
text: assistantMessage.content ?? ''
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
status: 'completed'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
case 'tool':
|
|
127
|
+
{
|
|
128
|
+
// Tool messages provide context about previous tool executions
|
|
129
|
+
// Using double assertion as the OpenAI API supports this format,
|
|
130
|
+
// but the agents SDK types are more restrictive
|
|
131
|
+
const toolMessage = message;
|
|
132
|
+
return {
|
|
133
|
+
role: 'tool',
|
|
134
|
+
tool_call_id: toolMessage.tool_call_id,
|
|
135
|
+
content: toolMessage.content ?? ''
|
|
103
136
|
};
|
|
104
137
|
}
|
|
105
|
-
// Regular assistant message without tool_calls
|
|
106
|
-
return {
|
|
107
|
-
role: 'assistant',
|
|
108
|
-
content: [
|
|
109
|
-
{
|
|
110
|
-
type: 'output_text',
|
|
111
|
-
text: assistantMessage.content ?? '',
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
status: 'completed',
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
case 'tool': {
|
|
118
|
-
// Tool messages provide context about previous tool executions
|
|
119
|
-
// Using double assertion as the OpenAI API supports this format,
|
|
120
|
-
// but the agents SDK types are more restrictive
|
|
121
|
-
const toolMessage = message;
|
|
122
|
-
return {
|
|
123
|
-
role: 'tool',
|
|
124
|
-
tool_call_id: toolMessage.tool_call_id,
|
|
125
|
-
content: toolMessage.content ?? '',
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
138
|
case 'system':
|
|
129
139
|
return {
|
|
130
140
|
role: 'system',
|
|
131
|
-
content: message.content ?? ''
|
|
141
|
+
content: message.content ?? ''
|
|
132
142
|
};
|
|
133
143
|
default:
|
|
134
144
|
throw new Error(`Invalid message role: ${message.role}`);
|
|
@@ -137,14 +147,15 @@ class HubtypeApiClient {
|
|
|
137
147
|
async trackLlmRuns(botId, data) {
|
|
138
148
|
// Not stop the bot execution if the tracking fails, just log the error
|
|
139
149
|
try {
|
|
140
|
-
const url = `${
|
|
150
|
+
const url = `${HUBTYPE_API_URL}/external/v2/conversational_apps/${botId}/track_llm_runs/`;
|
|
141
151
|
const headers = {
|
|
142
152
|
'Content-Type': 'application/json',
|
|
143
|
-
Authorization: `Bearer ${this.authToken}
|
|
153
|
+
Authorization: `Bearer ${this.authToken}`
|
|
144
154
|
};
|
|
145
|
-
await
|
|
146
|
-
|
|
147
|
-
|
|
155
|
+
await axios.post(url, data, {
|
|
156
|
+
headers
|
|
157
|
+
});
|
|
158
|
+
} catch (error) {
|
|
148
159
|
console.error('Failed to track LLM runs:', error);
|
|
149
160
|
}
|
|
150
161
|
}
|
|
@@ -152,25 +163,29 @@ class HubtypeApiClient {
|
|
|
152
163
|
if (message.role === 'user') {
|
|
153
164
|
return {
|
|
154
165
|
content: message.content,
|
|
155
|
-
role: 'user'
|
|
166
|
+
role: 'user'
|
|
156
167
|
};
|
|
157
|
-
}
|
|
158
|
-
else if (message.role === 'assistant') {
|
|
168
|
+
} else if (message.role === 'assistant') {
|
|
159
169
|
return {
|
|
160
170
|
role: 'assistant',
|
|
161
171
|
content: [
|
|
162
172
|
{
|
|
163
173
|
type: 'output_text',
|
|
164
|
-
text: message.content
|
|
165
|
-
}
|
|
174
|
+
text: message.content
|
|
175
|
+
}
|
|
166
176
|
],
|
|
167
|
-
status: 'completed'
|
|
177
|
+
status: 'completed'
|
|
168
178
|
};
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
179
|
+
} else {
|
|
171
180
|
throw new Error('Invalid message role');
|
|
172
181
|
}
|
|
173
182
|
}
|
|
183
|
+
constructor(authToken){
|
|
184
|
+
_define_property(this, "authToken", void 0);
|
|
185
|
+
this.authToken = authToken;
|
|
186
|
+
}
|
|
174
187
|
}
|
|
175
|
-
|
|
188
|
+
|
|
189
|
+
export { HubtypeApiClient };
|
|
190
|
+
|
|
176
191
|
//# sourceMappingURL=hubtype-api-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-api-client.js","sourceRoot":"","sources":["../../../src/services/hubtype-api-client.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AAEzB,4CAA8C;AAa9C,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,KA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;QACL,CAAC;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAa,EAAE,IAAsB;QACtD,uEAAuE;QACvE,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,GAAG,2BAAe,oCAAoC,KAAK,kBAAkB,CAAA;YACzF,MAAM,OAAO,GAAG;gBACd,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;aAC1C,CAAA;YACD,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAEO,aAAa,CAAC,OAAuB;QAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,OAAO;gBACL,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,MAAM;aACb,CAAA;QACH,CAAC;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACxC,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,aAAa;wBACnB,IAAI,EAAE,OAAO,CAAC,OAAO;qBACtB;iBACF;gBACD,MAAM,EAAE,WAAW;aACpB,CAAA;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;CACF;AAhMD,4CAgMC"}
|
|
1
|
+
{"version":3,"file":"services/hubtype-api-client.js","sources":["../../../src/services/hubtype-api-client.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { BotContext, HubtypeAssistantMessage } from '@botonic/core'\nimport axios from 'axios'\n\nimport { HUBTYPE_API_URL } from '../constants'\nimport type { AgenticInputMessage, Chunk, MemoryOptions } from '../types'\nimport type {\n GetMessagesV2Result,\n HubtypeAssistantMessageV2,\n HubtypeMessage,\n HubtypeMessageV2,\n HubtypeToolMessageV2,\n MessageHistoryResponseV2,\n MessageHistoryV2Params,\n TrackLlmRunsData,\n} from './types'\n\nexport class HubtypeApiClient {\n private readonly authToken: string\n\n constructor(authToken: string) {\n this.authToken = authToken\n }\n\n async retrieveSimilarChunks(\n query: string,\n sourceIds: string[]\n ): Promise<Chunk[]> {\n const url = `${HUBTYPE_API_URL}/external/v1/ai/knowledge_base/similar_chunks/`\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.authToken}`,\n }\n const params = {\n query,\n source_ids: sourceIds,\n num_chunks: 5,\n }\n const response = await axios.post(url, params, { headers })\n const chunks = response.data.chunks.map((chunk: Chunk) => ({\n id: chunk.id,\n text: chunk.text,\n }))\n return chunks\n }\n\n async getLocalMessages(\n maxMemoryLength: number,\n previousHubtypeMessages: HubtypeAssistantMessage[],\n localStorageKey: string\n ): Promise<AgenticInputMessage[]> {\n const localBotonicState =\n typeof globalThis !== 'undefined' && globalThis.localStorage\n ? globalThis.localStorage.getItem(localStorageKey)\n : null\n const botonicState = JSON.parse(localBotonicState || '{}')\n const messages = botonicState.messages\n const filteredMessages = messages\n .filter(message => message.data.text)\n .map(message => ({\n role: message.sentBy === 'user' ? 'user' : 'assistant',\n content: message.data.text,\n }))\n .map(message => this.formatMessage(message))\n const resultMessages = [...filteredMessages, ...previousHubtypeMessages]\n\n return resultMessages.slice(-maxMemoryLength)\n }\n\n async getMessagesV2(\n botContext: BotContext,\n options: MemoryOptions,\n previousHubtypeMessages: HubtypeAssistantMessage[]\n ): Promise<GetMessagesV2Result> {\n const url = `${HUBTYPE_API_URL}/external/v2/ai/agent/message_history/`\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.authToken}`,\n }\n const params: MessageHistoryV2Params = {\n last_message_id: botContext.input.message_id,\n max_messages: options.maxMessages,\n include_tool_calls: options.includeToolCalls,\n max_full_tool_results: options.maxFullToolResults,\n debug_mode: options.debugMode,\n }\n\n try {\n const response = await axios.get<MessageHistoryResponseV2>(url, {\n headers,\n params,\n })\n const { messages, conversation_id, truncated } = response.data\n const formattedMessages = [...messages, ...previousHubtypeMessages]\n .map(message => this.formatMessageV2(message))\n .filter((message): message is AgenticInputMessage => message !== null)\n\n return {\n messages: formattedMessages,\n conversationId: conversation_id,\n truncated,\n }\n } catch (error) {\n console.error(error)\n throw new Error('Failed to get messages from Hubtype V2 API')\n }\n }\n\n private formatMessageV2(\n message: HubtypeMessageV2\n ): AgenticInputMessage | null {\n switch (message.role) {\n case 'user':\n return {\n role: 'user',\n content: message.content ?? '',\n }\n case 'assistant': {\n const assistantMessage = message as HubtypeAssistantMessageV2\n // If assistant message has tool_calls, include them for context\n // Using double assertion as the OpenAI API supports this format,\n // but the agents SDK types are more restrictive\n if (\n assistantMessage.tool_calls &&\n assistantMessage.tool_calls.length > 0\n ) {\n return {\n role: 'assistant',\n content: assistantMessage.content ?? '',\n tool_calls: assistantMessage.tool_calls.map(tc => ({\n id: tc.id,\n type: tc.type,\n function: {\n name: tc.function.name,\n arguments: tc.function.arguments,\n },\n })),\n } as unknown as AgenticInputMessage\n }\n // Regular assistant message without tool_calls\n return {\n role: 'assistant',\n content: [\n {\n type: 'output_text',\n text: assistantMessage.content ?? '',\n },\n ],\n status: 'completed',\n }\n }\n case 'tool': {\n // Tool messages provide context about previous tool executions\n // Using double assertion as the OpenAI API supports this format,\n // but the agents SDK types are more restrictive\n const toolMessage = message as HubtypeToolMessageV2\n return {\n role: 'tool',\n tool_call_id: toolMessage.tool_call_id,\n content: toolMessage.content ?? '',\n } as unknown as AgenticInputMessage\n }\n case 'system':\n return {\n role: 'system',\n content: message.content ?? '',\n }\n default:\n throw new Error(\n `Invalid message role: ${(message as HubtypeMessageV2).role}`\n )\n }\n }\n\n async trackLlmRuns(botId: string, data: TrackLlmRunsData): Promise<void> {\n // Not stop the bot execution if the tracking fails, just log the error\n try {\n const url = `${HUBTYPE_API_URL}/external/v2/conversational_apps/${botId}/track_llm_runs/`\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.authToken}`,\n }\n await axios.post(url, data, { headers })\n } catch (error) {\n console.error('Failed to track LLM runs:', error)\n }\n }\n\n private formatMessage(message: HubtypeMessage): AgenticInputMessage {\n if (message.role === 'user') {\n return {\n content: message.content,\n role: 'user',\n }\n } else if (message.role === 'assistant') {\n return {\n role: 'assistant',\n content: [\n {\n type: 'output_text',\n text: message.content,\n },\n ],\n status: 'completed',\n }\n } else {\n throw new Error('Invalid message role')\n }\n }\n}\n"],"names":["axios","HUBTYPE_API_URL","HubtypeApiClient","query","sourceIds","url","headers","params","response","chunks","chunk","maxMemoryLength","previousHubtypeMessages","localStorageKey","localBotonicState","globalThis","botonicState","JSON","messages","filteredMessages","message","resultMessages","botContext","options","conversation_id","truncated","formattedMessages","error","console","Error","assistantMessage","tc","toolMessage","botId","data","authToken"],"mappings":";;;;;AAAA,uDAAuD;;;;;;;;;;;AAE9B;AAEqB;AAavC,MAAME,gBAAgBA;IAO3B,MAAM,sBACJC,KAAa,EACbC,SAAmB,EACD;QAClB,MAAMC,MAAM,GAAGJ,eAAeA,CAAC,8CAA8C,CAAC;QAC9E,MAAMK,UAAU;YACd,gBAAgB;YAChB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE;QAC3C;QACA,MAAMC,SAAS;YACbJ;YACA,YAAYC;YACZ,YAAY;QACd;QACA,MAAMI,WAAW,MAAMR,UAAU,CAACK,KAAKE,QAAQ;YAAED;QAAQ;QACzD,MAAMG,SAASD,SAAS,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAACE,QAAkB;gBACzD,IAAIA,MAAM,EAAE;gBACZ,MAAMA,MAAM,IAAI;YAClB;QACA,OAAOD;IACT;IAEA,MAAM,iBACJE,eAAuB,EACvBC,uBAAkD,EAClDC,eAAuB,EACS;QAChC,MAAM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EAAuE;QACvE,IAAI;YACF,MAAM7B,MAAM,GAAGJ,eAAeA,CAAC,iCAAiC,EAAEgC,MAAM,gBAAgB,CAAC;YACzF,MAAM3B,UAAU;gBACd,gBAAgB;gBAChB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE;YAC3C;YACA,MAAMN,UAAU,CAACK,KAAK6B,MAAM;gBAAE5B;YAAQ;QACxC,EAAE,OAAOqB,OAAO;YACdC,QAAQ,KAAK,CAAC,6BAA6BD;QAC7C;IACF;IAEQ,cAAcP,OAAuB,EAAuB;QAClE,IAAIA,QAAQ,IAAI,KAAK,QAAQ;YAC3B,OAAO;gBACL,SAASA,QAAQ,OAAO;gBACxB,MAAM;YACR;QACF,OAAO,IAAIA,QAAQ,IAAI,KAAK,aAAa;YACvC,OAAO;gBACL,MAAM;gBACN,SAAS;oBACP;wBACE,MAAM;wBACN,MAAMA,QAAQ,OAAO;oBACvB;iBACD;gBACD,QAAQ;YACV;QACF,OAAO;YACL,MAAM,IAAIS,MAAM;QAClB;IACF;IA5LA,YAAYM,SAAiB,CAAE;QAF/B,uBAAiB,aAAjB;QAGE,IAAI,CAAC,SAAS,GAAGA;IACnB;AA2LF"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TrackFeature = exports.TrackProductName = void 0;
|
|
4
|
-
var TrackProductName;
|
|
5
|
-
(function (TrackProductName) {
|
|
1
|
+
var types_TrackProductName = /*#__PURE__*/ function(TrackProductName) {
|
|
6
2
|
TrackProductName["AI_AGENT"] = "ai_agent";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
return TrackProductName;
|
|
4
|
+
}({});
|
|
5
|
+
var types_TrackFeature = /*#__PURE__*/ function(TrackFeature) {
|
|
10
6
|
TrackFeature["AI_AGENT_RUN"] = "ai_agent_run";
|
|
11
7
|
TrackFeature["AI_AGENT_GUARDRAIL"] = "ai_agent_guardrail";
|
|
12
|
-
|
|
8
|
+
return TrackFeature;
|
|
9
|
+
}({});
|
|
10
|
+
|
|
11
|
+
export { types_TrackFeature as TrackFeature, types_TrackProductName as TrackProductName };
|
|
12
|
+
|
|
13
13
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","
|
|
1
|
+
{"version":3,"file":"services/types.js","sources":["../../../src/services/types.ts"],"sourcesContent":["import type { HubtypeAssistantMessage, HubtypeUserMessage } from '@botonic/core'\nimport type { AgenticInputMessage } from '../types'\n\nexport enum TrackProductName {\n AI_AGENT = 'ai_agent',\n}\n\nexport enum TrackFeature {\n AI_AGENT_RUN = 'ai_agent_run',\n AI_AGENT_GUARDRAIL = 'ai_agent_guardrail',\n}\n\nexport interface LlmRunData {\n inference_id: string\n is_test: boolean\n product_name: string\n deployment_name: string\n model_name: string\n feature: string\n api_version?: string\n num_prompt_tokens: number\n num_completion_tokens: number\n duration_in_milliseconds: number\n temperature: number\n error: string | null\n}\n\nexport interface TrackLlmRunsData {\n llm_runs: LlmRunData[]\n}\n\nexport type HubtypeMessage = HubtypeAssistantMessage | HubtypeUserMessage\n\n// V2 API Types\ninterface HubtypeToolCall {\n id: string\n type: 'function'\n function: {\n name: string\n arguments: string\n }\n}\n\ninterface HubtypeUserMessageV2 {\n role: 'user'\n content: string | null\n}\n\nexport interface HubtypeAssistantMessageV2 {\n role: 'assistant'\n content: string | null\n tool_calls?: HubtypeToolCall[] | null\n}\n\nexport interface HubtypeToolMessageV2 {\n role: 'tool'\n content: string | null\n tool_call_id: string\n}\n\ninterface HubtypeSystemMessageV2 {\n role: 'system'\n content: string | null\n}\n\nexport type HubtypeMessageV2 =\n | HubtypeUserMessageV2\n | HubtypeAssistantMessageV2\n | HubtypeToolMessageV2\n | HubtypeSystemMessageV2\n\nexport interface MessageHistoryResponseV2 {\n messages: HubtypeMessageV2[]\n conversation_id: string | null\n truncated: boolean\n}\n\nexport interface GetMessagesV2Result {\n messages: AgenticInputMessage[]\n conversationId: string | null\n truncated: boolean\n}\n\nexport interface MessageHistoryV2Params {\n last_message_id: string\n max_messages?: number\n include_tool_calls?: boolean\n max_full_tool_results?: number\n debug_mode?: boolean\n}\n"],"names":["TrackProductName","TrackFeature"],"mappings":"AAGO,IAAKA,sBAAgBA,0BAAhBA;;WAAAA;MAEX;AAEM,IAAKC,kBAAYA,0BAAZA;;;WAAAA;MAGX"}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
17
|
-
|
|
1
|
+
import { OutputMessageType } from "@botonic/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const BotExecutorSchema = z.object({
|
|
9
|
+
type: z.literal(OutputMessageType.BotExecutor),
|
|
10
|
+
content: z.object({
|
|
11
|
+
text: z.string(),
|
|
12
|
+
buttons: z.array(z.object({
|
|
13
|
+
text: z.string(),
|
|
14
|
+
payload: z.string()
|
|
15
|
+
}))
|
|
16
|
+
})
|
|
17
|
+
}).describe('A text message with buttons to allow the bot to execute a specific action. Use it only when asked explicitly in the prompt');
|
|
18
|
+
|
|
19
|
+
export { BotExecutorSchema };
|
|
20
|
+
|
|
18
21
|
//# sourceMappingURL=bot-executor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bot-executor.js","
|
|
1
|
+
{"version":3,"file":"structured-output/bot-executor.js","sources":["../../../src/structured-output/bot-executor.ts"],"sourcesContent":["import { type BotExecutorMessage, OutputMessageType } from '@botonic/core'\nimport { z } from 'zod'\n\nexport type { BotExecutorMessage }\n\nexport const BotExecutorSchema = z\n .object({\n type: z.literal(OutputMessageType.BotExecutor),\n content: z.object({\n text: z.string(),\n buttons: z.array(\n z.object({\n text: z.string(),\n payload: z.string(),\n })\n ),\n }),\n })\n .describe(\n 'A text message with buttons to allow the bot to execute a specific action. Use it only when asked explicitly in the prompt'\n )\n"],"names":["OutputMessageType","z","BotExecutorSchema"],"mappings":";;;;;AAA0E;AACnD;AAIhB,MAAME,iBAAiBA,GAAGD,QACxB,CAAC;IACN,MAAMA,SAAS,CAACD,6BAA6B;IAC7C,SAASC,QAAQ,CAAC;QAChB,MAAMA,QAAQ;QACd,SAASA,OAAO,CACdA,QAAQ,CAAC;YACP,MAAMA,QAAQ;YACd,SAASA,QAAQ;QACnB;IAEJ;AACF,GACC,QAAQ,CACP,8HACD"}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
|
|
1
|
+
import { OutputMessageType } from "@botonic/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const CarouselSchema = z.object({
|
|
9
|
+
type: z.literal(OutputMessageType.Carousel),
|
|
10
|
+
content: z.object({
|
|
11
|
+
text: z.string().nullable().optional(),
|
|
12
|
+
elements: z.array(z.object({
|
|
13
|
+
title: z.string(),
|
|
14
|
+
subtitle: z.string(),
|
|
15
|
+
image: z.string(),
|
|
16
|
+
button: z.object({
|
|
17
|
+
text: z.string(),
|
|
18
|
+
url: z.string().nullable().optional()
|
|
19
|
+
})
|
|
20
|
+
}))
|
|
21
|
+
})
|
|
22
|
+
}).describe('A carousel message containing a list of elements');
|
|
23
|
+
|
|
24
|
+
export { CarouselSchema };
|
|
25
|
+
|
|
23
26
|
//# sourceMappingURL=carousel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"carousel.js","
|
|
1
|
+
{"version":3,"file":"structured-output/carousel.js","sources":["../../../src/structured-output/carousel.ts"],"sourcesContent":["import { type CarouselMessage, OutputMessageType } from '@botonic/core'\nimport { z } from 'zod'\n\nexport type { CarouselMessage }\n\nexport const CarouselSchema = z\n .object({\n type: z.literal(OutputMessageType.Carousel),\n content: z.object({\n text: z.string().nullable().optional(),\n elements: z.array(\n z.object({\n title: z.string(),\n subtitle: z.string(),\n image: z.string(),\n button: z.object({\n text: z.string(),\n url: z.string().nullable().optional(),\n }),\n })\n ),\n }),\n })\n .describe('A carousel message containing a list of elements')\n"],"names":["OutputMessageType","z","CarouselSchema"],"mappings":";;;;;AAAuE;AAChD;AAIhB,MAAME,cAAcA,GAAGD,QACrB,CAAC;IACN,MAAMA,SAAS,CAACD,0BAA0B;IAC1C,SAASC,QAAQ,CAAC;QAChB,MAAMA,QAAQ,GAAG,QAAQ,GAAG,QAAQ;QACpC,UAAUA,OAAO,CACfA,QAAQ,CAAC;YACP,OAAOA,QAAQ;YACf,UAAUA,QAAQ;YAClB,OAAOA,QAAQ;YACf,QAAQA,QAAQ,CAAC;gBACf,MAAMA,QAAQ;gBACd,KAAKA,QAAQ,GAAG,QAAQ,GAAG,QAAQ;YACrC;QACF;IAEJ;AACF,GACC,QAAQ,CAAC,oDAAmD"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { OutputMessageType } from "@botonic/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const ExitSchema = z.object({
|
|
9
|
+
type: z.literal(OutputMessageType.Exit)
|
|
10
|
+
}).describe('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');
|
|
11
|
+
|
|
12
|
+
export { ExitSchema };
|
|
13
|
+
|
|
11
14
|
//# sourceMappingURL=exit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exit.js","
|
|
1
|
+
{"version":3,"file":"structured-output/exit.js","sources":["../../../src/structured-output/exit.ts"],"sourcesContent":["import { type ExitMessage, OutputMessageType } from '@botonic/core'\nimport { z } from 'zod'\n\nexport type { ExitMessage }\n\nexport const ExitSchema = z\n .object({\n type: z.literal(OutputMessageType.Exit),\n })\n .describe(\n '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'\n )\n"],"names":["OutputMessageType","z","ExitSchema"],"mappings":";;;;;AAAmE;AAC5C;AAIhB,MAAME,UAAUA,GAAGD,QACjB,CAAC;IACN,MAAMA,SAAS,CAACD,sBAAsB;AACxC,GACC,QAAQ,CACP,yIACD"}
|
|
@@ -47,11 +47,6 @@ export declare const OutputSchema: z.ZodObject<{
|
|
|
47
47
|
payload: z.ZodString;
|
|
48
48
|
}, z.core.$strip>>;
|
|
49
49
|
}, z.core.$strip>;
|
|
50
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
51
|
-
type: z.ZodLiteral<import("@botonic/core").OutputMessageType.RequestContactInfo>;
|
|
52
|
-
content: z.ZodObject<{
|
|
53
|
-
text: z.ZodString;
|
|
54
|
-
}, z.core.$strip>;
|
|
55
50
|
}, z.core.$strip>]>>;
|
|
56
51
|
}, z.core.$strip>;
|
|
57
52
|
export declare function getOutputSchema(externalOutputMessagesSchemas: z.ZodObject<any>[]): z.ZodObject<{
|
|
@@ -98,11 +93,6 @@ export declare function getOutputSchema(externalOutputMessagesSchemas: z.ZodObje
|
|
|
98
93
|
payload: z.ZodString;
|
|
99
94
|
}, z.core.$strip>>;
|
|
100
95
|
}, z.core.$strip>;
|
|
101
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
102
|
-
type: z.ZodLiteral<import("@botonic/core").OutputMessageType.RequestContactInfo>;
|
|
103
|
-
content: z.ZodObject<{
|
|
104
|
-
text: z.ZodString;
|
|
105
|
-
}, z.core.$strip>;
|
|
106
96
|
}, z.core.$strip>, ...z.ZodObject<any, z.core.$strip>[]]>>;
|
|
107
97
|
}, z.core.$strip>;
|
|
108
98
|
export declare function getOutputInstructions(): string;
|
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BotExecutorSchema } from "./bot-executor.js";
|
|
3
|
+
import { CarouselSchema } from "./carousel.js";
|
|
4
|
+
import { ExitSchema } from "./exit.js";
|
|
5
|
+
import { TextSchema } from "./text.js";
|
|
6
|
+
import { TextWithButtonsSchema } from "./text-with-buttons.js";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
13
20
|
const baseMessageSchemas = [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
request_contact_info_1.RequestContactInfoSchema,
|
|
21
|
+
TextSchema,
|
|
22
|
+
TextWithButtonsSchema,
|
|
23
|
+
CarouselSchema,
|
|
24
|
+
ExitSchema,
|
|
25
|
+
BotExecutorSchema
|
|
20
26
|
];
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
})
|
|
25
|
-
.describe('The messages to be sent to the user');
|
|
27
|
+
const OutputSchema = z.object({
|
|
28
|
+
messages: z.array(z.union(baseMessageSchemas))
|
|
29
|
+
}).describe('The messages to be sent to the user');
|
|
26
30
|
function getOutputSchema(externalOutputMessagesSchemas) {
|
|
27
|
-
return
|
|
28
|
-
messages:
|
|
31
|
+
return z.object({
|
|
32
|
+
messages: z.array(z.union([
|
|
33
|
+
...baseMessageSchemas,
|
|
34
|
+
...externalOutputMessagesSchemas
|
|
35
|
+
]))
|
|
29
36
|
});
|
|
30
37
|
}
|
|
31
38
|
function getOutputInstructions() {
|
|
@@ -34,12 +41,15 @@ function getOutputInstructions() {
|
|
|
34
41
|
{
|
|
35
42
|
type: 'text',
|
|
36
43
|
content: {
|
|
37
|
-
text: 'Hello, how can I help you today?'
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
]
|
|
44
|
+
text: 'Hello, how can I help you today?'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
41
48
|
};
|
|
42
49
|
const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\n<example>\n${JSON.stringify(example)}\n</example>`;
|
|
43
50
|
return `<output>\n${output}\n</output>`;
|
|
44
51
|
}
|
|
52
|
+
|
|
53
|
+
export { OutputSchema, getOutputInstructions, getOutputSchema };
|
|
54
|
+
|
|
45
55
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"structured-output/index.js","sources":["../../../src/structured-output/index.ts"],"sourcesContent":["import type { OutputMessage } from '@botonic/core'\nimport { z } from 'zod'\nimport { BotExecutorSchema } from './bot-executor'\nimport { CarouselSchema } from './carousel'\nimport { ExitSchema } from './exit'\nimport { TextSchema } from './text'\nimport { TextWithButtonsSchema } from './text-with-buttons'\n\nexport interface Output {\n messages: OutputMessage[]\n}\n\nconst baseMessageSchemas = [\n TextSchema,\n TextWithButtonsSchema,\n CarouselSchema,\n ExitSchema,\n BotExecutorSchema,\n] as const\nexport const OutputSchema = z\n .object({\n messages: z.array(z.union(baseMessageSchemas)),\n })\n .describe('The messages to be sent to the user')\n\nexport function getOutputSchema(\n externalOutputMessagesSchemas: z.ZodObject<any>[]\n) {\n return z.object({\n messages: z.array(\n z.union([...baseMessageSchemas, ...externalOutputMessagesSchemas])\n ),\n })\n}\n\nexport function getOutputInstructions(): string {\n const example = {\n messages: [\n {\n type: 'text',\n content: {\n text: 'Hello, how can I help you today?',\n },\n },\n ],\n }\n const output = `Return a JSON that follows the output schema provided. Never return multiple output schemas concatenated by a line break.\\n<example>\\n${JSON.stringify(example)}\\n</example>`\n return `<output>\\n${output}\\n</output>`\n}\n"],"names":["z","BotExecutorSchema","CarouselSchema","ExitSchema","TextSchema","TextWithButtonsSchema","baseMessageSchemas","OutputSchema","getOutputSchema","externalOutputMessagesSchemas","getOutputInstructions","example","output","JSON"],"mappings":";;;;;;;;;;;;;AACuB;AAC2B;AACP;AACR;AACA;AACwB;AAM3D,MAAMM,kBAAkBA,GAAG;IACzBF,UAAUA;IACVC,qBAAqBA;IACrBH,cAAcA;IACdC,UAAUA;IACVF,iBAAiBA;CAClB;AACM,MAAMM,YAAYA,GAAGP,QACnB,CAAC;IACN,UAAUA,OAAO,CAACA,OAAO,CAACM,kBAAkBA;AAC9C,GACC,QAAQ,CAAC,uCAAsC;AAE3C,SAASE,eAAeA,CAC7BC,6BAAiD;IAEjD,OAAOT,QAAQ,CAAC;QACd,UAAUA,OAAO,CACfA,OAAO,CAAC;eAAIM,kBAAkBA;eAAKG;SAA8B;IAErE;AACF;AAEO,SAASC,qBAAqBA;IACnC,MAAMC,UAAU;QACd,UAAU;YACR;gBACE,MAAM;gBACN,SAAS;oBACP,MAAM;gBACR;YACF;SACD;IACH;IACA,MAAMC,SAAS,CAAC,sIAAsI,EAAEC,KAAK,SAAS,CAACF,SAAS,YAAY,CAAC;IAC7L,OAAO,CAAC,UAAU,EAAEC,OAAO,WAAW,CAAC;AACzC"}
|