@botonic/plugin-ai-agents 0.46.0 → 2.23.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.
Files changed (181) hide show
  1. package/CHANGELOG.md +209 -0
  2. package/package.json +23 -41
  3. package/src/index.d.ts +2 -0
  4. package/src/index.js +3 -0
  5. package/src/index.js.map +1 -0
  6. package/{lib/cjs → src/lib}/agent-builder.d.ts +5 -10
  7. package/{lib/cjs → src/lib}/agent-builder.js +31 -25
  8. package/src/lib/agent-builder.js.map +1 -0
  9. package/{lib/cjs → src/lib}/constants.d.ts +1 -3
  10. package/src/lib/constants.js +13 -0
  11. package/src/lib/constants.js.map +1 -0
  12. package/{lib/esm → src/lib}/debug-logger.d.ts +3 -5
  13. package/{lib/esm → src/lib}/debug-logger.js +44 -29
  14. package/src/lib/debug-logger.js.map +1 -0
  15. package/src/lib/guardrails/index.js +2 -0
  16. package/src/lib/guardrails/index.js.map +1 -0
  17. package/src/lib/guardrails/input.d.ts +3 -0
  18. package/src/lib/guardrails/input.js +29 -0
  19. package/src/lib/guardrails/input.js.map +1 -0
  20. package/{lib/cjs/services → src/lib}/hubtype-api-client.d.ts +13 -5
  21. package/src/lib/hubtype-api-client.js +206 -0
  22. package/src/lib/hubtype-api-client.js.map +1 -0
  23. package/{lib/cjs → src/lib}/index.d.ts +2 -7
  24. package/src/lib/index.js +111 -0
  25. package/src/lib/index.js.map +1 -0
  26. package/src/lib/openai.d.ts +1 -0
  27. package/src/lib/openai.js +21 -0
  28. package/src/lib/openai.js.map +1 -0
  29. package/src/lib/runner.d.ts +12 -0
  30. package/src/lib/runner.js +96 -0
  31. package/src/lib/runner.js.map +1 -0
  32. package/{lib/esm → src/lib}/structured-output/carousel.d.ts +1 -1
  33. package/src/lib/structured-output/carousel.js +19 -0
  34. package/src/lib/structured-output/carousel.js.map +1 -0
  35. package/{lib/cjs → src/lib}/structured-output/exit.d.ts +1 -1
  36. package/src/lib/structured-output/exit.js +7 -0
  37. package/src/lib/structured-output/exit.js.map +1 -0
  38. package/{lib/cjs → src/lib}/structured-output/index.d.ts +10 -73
  39. package/src/lib/structured-output/index.js +11 -0
  40. package/src/lib/structured-output/index.js.map +1 -0
  41. package/{lib/esm → src/lib}/structured-output/text-with-buttons.d.ts +8 -8
  42. package/src/lib/structured-output/text-with-buttons.js +14 -0
  43. package/src/lib/structured-output/text-with-buttons.js.map +1 -0
  44. package/{lib/esm → src/lib}/structured-output/text.d.ts +1 -1
  45. package/src/lib/structured-output/text.js +10 -0
  46. package/src/lib/structured-output/text.js.map +1 -0
  47. package/{lib/esm → src/lib}/tools/index.d.ts +1 -1
  48. package/src/lib/tools/index.js +3 -0
  49. package/src/lib/tools/index.js.map +1 -0
  50. package/{lib/cjs → src/lib}/tools/retrieve-knowledge.d.ts +2 -2
  51. package/src/lib/tools/retrieve-knowledge.js +30 -0
  52. package/src/lib/tools/retrieve-knowledge.js.map +1 -0
  53. package/{lib/esm → src/lib}/types.d.ts +11 -21
  54. package/src/lib/types.js +2 -0
  55. package/src/lib/types.js.map +1 -0
  56. package/README.md +0 -156
  57. package/lib/cjs/agent-builder.js.map +0 -1
  58. package/lib/cjs/bot-config-tools.d.ts +0 -7
  59. package/lib/cjs/bot-config-tools.js +0 -19
  60. package/lib/cjs/bot-config-tools.js.map +0 -1
  61. package/lib/cjs/constants.js +0 -17
  62. package/lib/cjs/constants.js.map +0 -1
  63. package/lib/cjs/debug-logger.d.ts +0 -33
  64. package/lib/cjs/debug-logger.js +0 -97
  65. package/lib/cjs/debug-logger.js.map +0 -1
  66. package/lib/cjs/guardrails/index.js +0 -5
  67. package/lib/cjs/guardrails/index.js.map +0 -1
  68. package/lib/cjs/guardrails/input.d.ts +0 -10
  69. package/lib/cjs/guardrails/input.js +0 -77
  70. package/lib/cjs/guardrails/input.js.map +0 -1
  71. package/lib/cjs/index.js +0 -133
  72. package/lib/cjs/index.js.map +0 -1
  73. package/lib/cjs/llm-config.d.ts +0 -15
  74. package/lib/cjs/llm-config.js +0 -66
  75. package/lib/cjs/llm-config.js.map +0 -1
  76. package/lib/cjs/runner.d.ts +0 -18
  77. package/lib/cjs/runner.js +0 -181
  78. package/lib/cjs/runner.js.map +0 -1
  79. package/lib/cjs/services/hubtype-api-client.js +0 -206
  80. package/lib/cjs/services/hubtype-api-client.js.map +0 -1
  81. package/lib/cjs/services/types.d.ts +0 -85
  82. package/lib/cjs/services/types.js +0 -13
  83. package/lib/cjs/services/types.js.map +0 -1
  84. package/lib/cjs/structured-output/bot-executor.d.ts +0 -49
  85. package/lib/cjs/structured-output/bot-executor.js +0 -18
  86. package/lib/cjs/structured-output/bot-executor.js.map +0 -1
  87. package/lib/cjs/structured-output/carousel.d.ts +0 -90
  88. package/lib/cjs/structured-output/carousel.js +0 -22
  89. package/lib/cjs/structured-output/carousel.js.map +0 -1
  90. package/lib/cjs/structured-output/exit.js +0 -11
  91. package/lib/cjs/structured-output/exit.js.map +0 -1
  92. package/lib/cjs/structured-output/index.js +0 -21
  93. package/lib/cjs/structured-output/index.js.map +0 -1
  94. package/lib/cjs/structured-output/text-with-buttons.d.ts +0 -49
  95. package/lib/cjs/structured-output/text-with-buttons.js +0 -18
  96. package/lib/cjs/structured-output/text-with-buttons.js.map +0 -1
  97. package/lib/cjs/structured-output/text.d.ts +0 -23
  98. package/lib/cjs/structured-output/text.js +0 -13
  99. package/lib/cjs/structured-output/text.js.map +0 -1
  100. package/lib/cjs/tools/index.d.ts +0 -3
  101. package/lib/cjs/tools/index.js +0 -7
  102. package/lib/cjs/tools/index.js.map +0 -1
  103. package/lib/cjs/tools/retrieve-knowledge.js +0 -32
  104. package/lib/cjs/tools/retrieve-knowledge.js.map +0 -1
  105. package/lib/cjs/types.d.ts +0 -56
  106. package/lib/cjs/types.js +0 -3
  107. package/lib/cjs/types.js.map +0 -1
  108. package/lib/esm/agent-builder.d.ts +0 -34
  109. package/lib/esm/agent-builder.js +0 -105
  110. package/lib/esm/agent-builder.js.map +0 -1
  111. package/lib/esm/bot-config-tools.d.ts +0 -7
  112. package/lib/esm/bot-config-tools.js +0 -19
  113. package/lib/esm/bot-config-tools.js.map +0 -1
  114. package/lib/esm/constants.d.ts +0 -11
  115. package/lib/esm/constants.js +0 -17
  116. package/lib/esm/constants.js.map +0 -1
  117. package/lib/esm/debug-logger.js.map +0 -1
  118. package/lib/esm/guardrails/index.d.ts +0 -1
  119. package/lib/esm/guardrails/index.js +0 -5
  120. package/lib/esm/guardrails/index.js.map +0 -1
  121. package/lib/esm/guardrails/input.d.ts +0 -10
  122. package/lib/esm/guardrails/input.js +0 -77
  123. package/lib/esm/guardrails/input.js.map +0 -1
  124. package/lib/esm/index.d.ts +0 -18
  125. package/lib/esm/index.js +0 -133
  126. package/lib/esm/index.js.map +0 -1
  127. package/lib/esm/llm-config.d.ts +0 -15
  128. package/lib/esm/llm-config.js +0 -66
  129. package/lib/esm/llm-config.js.map +0 -1
  130. package/lib/esm/runner.d.ts +0 -18
  131. package/lib/esm/runner.js +0 -181
  132. package/lib/esm/runner.js.map +0 -1
  133. package/lib/esm/services/hubtype-api-client.d.ts +0 -14
  134. package/lib/esm/services/hubtype-api-client.js +0 -206
  135. package/lib/esm/services/hubtype-api-client.js.map +0 -1
  136. package/lib/esm/services/types.d.ts +0 -85
  137. package/lib/esm/services/types.js +0 -13
  138. package/lib/esm/services/types.js.map +0 -1
  139. package/lib/esm/structured-output/bot-executor.d.ts +0 -49
  140. package/lib/esm/structured-output/bot-executor.js +0 -18
  141. package/lib/esm/structured-output/bot-executor.js.map +0 -1
  142. package/lib/esm/structured-output/carousel.js +0 -22
  143. package/lib/esm/structured-output/carousel.js.map +0 -1
  144. package/lib/esm/structured-output/exit.d.ts +0 -10
  145. package/lib/esm/structured-output/exit.js +0 -11
  146. package/lib/esm/structured-output/exit.js.map +0 -1
  147. package/lib/esm/structured-output/index.d.ts +0 -291
  148. package/lib/esm/structured-output/index.js +0 -21
  149. package/lib/esm/structured-output/index.js.map +0 -1
  150. package/lib/esm/structured-output/text-with-buttons.js +0 -18
  151. package/lib/esm/structured-output/text-with-buttons.js.map +0 -1
  152. package/lib/esm/structured-output/text.js +0 -13
  153. package/lib/esm/structured-output/text.js.map +0 -1
  154. package/lib/esm/tools/index.js +0 -7
  155. package/lib/esm/tools/index.js.map +0 -1
  156. package/lib/esm/tools/retrieve-knowledge.d.ts +0 -9
  157. package/lib/esm/tools/retrieve-knowledge.js +0 -32
  158. package/lib/esm/tools/retrieve-knowledge.js.map +0 -1
  159. package/lib/esm/types.js +0 -3
  160. package/lib/esm/types.js.map +0 -1
  161. package/src/agent-builder.ts +0 -179
  162. package/src/bot-config-tools.ts +0 -21
  163. package/src/constants.ts +0 -21
  164. package/src/debug-logger.ts +0 -166
  165. package/src/guardrails/index.ts +0 -1
  166. package/src/guardrails/input.ts +0 -122
  167. package/src/index.ts +0 -209
  168. package/src/llm-config.ts +0 -96
  169. package/src/runner.ts +0 -287
  170. package/src/services/hubtype-api-client.ts +0 -240
  171. package/src/services/types.ts +0 -106
  172. package/src/structured-output/bot-executor.ts +0 -21
  173. package/src/structured-output/carousel.ts +0 -24
  174. package/src/structured-output/exit.ts +0 -12
  175. package/src/structured-output/index.ts +0 -25
  176. package/src/structured-output/text-with-buttons.ts +0 -21
  177. package/src/structured-output/text.ts +0 -13
  178. package/src/tools/index.ts +0 -5
  179. package/src/tools/retrieve-knowledge.ts +0 -37
  180. package/src/types.ts +0 -110
  181. /package/{lib/cjs → src/lib}/guardrails/index.d.ts +0 -0
@@ -1,240 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import type { BotContext } from '@botonic/core'
3
- import axios from 'axios'
4
-
5
- import { HUBTYPE_API_URL } from '../constants'
6
- import type { AgenticInputMessage, Chunk } from '../types'
7
- import type {
8
- GetMessagesV2Options,
9
- GetMessagesV2Result,
10
- HubtypeAssistantMessageV2,
11
- HubtypeMessage,
12
- HubtypeMessageV2,
13
- HubtypeToolMessageV2,
14
- MessageHistoryResponseV2,
15
- MessageHistoryV2Params,
16
- TrackLlmRunsData,
17
- } from './types'
18
-
19
- export class HubtypeApiClient {
20
- private readonly authToken: string
21
-
22
- constructor(authToken: string) {
23
- this.authToken = authToken
24
- }
25
-
26
- async retrieveSimilarChunks(
27
- query: string,
28
- sourceIds: string[]
29
- ): Promise<Chunk[]> {
30
- const url = `${HUBTYPE_API_URL}/external/v1/ai/knowledge_base/similar_chunks/`
31
- const headers = {
32
- 'Content-Type': 'application/json',
33
- Authorization: `Bearer ${this.authToken}`,
34
- }
35
- const params = {
36
- query,
37
- source_ids: sourceIds,
38
- num_chunks: 5,
39
- }
40
- const response = await axios.post(url, params, { headers })
41
- const chunks = response.data.chunks.map((chunk: Chunk) => ({
42
- id: chunk.id,
43
- text: chunk.text,
44
- }))
45
- return chunks
46
- }
47
-
48
- async getLocalMessages(
49
- maxMemoryLength: number
50
- ): Promise<AgenticInputMessage[]> {
51
- const localBotonicState =
52
- typeof globalThis !== 'undefined' && globalThis.localStorage
53
- ? globalThis.localStorage.getItem('botonicState')
54
- : null
55
- const botonicState = JSON.parse(localBotonicState || '{}')
56
- const messages = botonicState.messages
57
- const filteredMessages = messages
58
- .filter(message => message.data.text)
59
- .map(message => ({
60
- role: message.sentBy === 'user' ? 'user' : 'assistant',
61
- content: message.data.text,
62
- }))
63
- .map(message => this.formatMessage(message))
64
- return filteredMessages.slice(-maxMemoryLength)
65
- }
66
-
67
- async getMessages(
68
- botContext: BotContext,
69
- maxMemoryLength: number
70
- ): Promise<AgenticInputMessage[]> {
71
- const url = `${HUBTYPE_API_URL}/external/v1/ai/agent/message_history/`
72
- const headers = {
73
- 'Content-Type': 'application/json',
74
- Authorization: `Bearer ${this.authToken}`,
75
- }
76
- const params = {
77
- last_message_id: botContext.input.message_id,
78
- num_messages: maxMemoryLength,
79
- }
80
-
81
- try {
82
- const response = await axios.get<{ messages: HubtypeMessage[] }>(url, {
83
- headers,
84
- params,
85
- })
86
- const messages = response.data.messages
87
- return messages.map(message => this.formatMessage(message))
88
- } catch (error) {
89
- console.error(error)
90
- throw new Error('Failed to get messages from Hubtype')
91
- }
92
- }
93
-
94
- async getMessagesV2(
95
- botContext: BotContext,
96
- options: GetMessagesV2Options = {}
97
- ): Promise<GetMessagesV2Result> {
98
- const url = `${HUBTYPE_API_URL}/external/v2/ai/agent/message_history/`
99
- const headers = {
100
- 'Content-Type': 'application/json',
101
- Authorization: `Bearer ${this.authToken}`,
102
- }
103
- const params: MessageHistoryV2Params = {
104
- last_message_id: botContext.input.message_id,
105
- ...(options.maxMessages !== undefined && {
106
- max_messages: options.maxMessages,
107
- }),
108
- ...(options.includeToolCalls !== undefined && {
109
- include_tool_calls: options.includeToolCalls,
110
- }),
111
- ...(options.maxFullToolResults !== undefined && {
112
- max_full_tool_results: options.maxFullToolResults,
113
- }),
114
- ...(options.debugMode !== undefined && {
115
- debug_mode: options.debugMode,
116
- }),
117
- }
118
-
119
- try {
120
- const response = await axios.get<MessageHistoryResponseV2>(url, {
121
- headers,
122
- params,
123
- })
124
- const { messages, conversation_id, truncated } = response.data
125
- const formattedMessages = messages
126
- .map(message => this.formatMessageV2(message))
127
- .filter((message): message is AgenticInputMessage => message !== null)
128
- return {
129
- messages: formattedMessages,
130
- conversationId: conversation_id,
131
- truncated,
132
- }
133
- } catch (error) {
134
- console.error(error)
135
- throw new Error('Failed to get messages from Hubtype V2 API')
136
- }
137
- }
138
-
139
- private formatMessageV2(
140
- message: HubtypeMessageV2
141
- ): AgenticInputMessage | null {
142
- switch (message.role) {
143
- case 'user':
144
- return {
145
- role: 'user',
146
- content: message.content ?? '',
147
- }
148
- case 'assistant': {
149
- const assistantMessage = message as HubtypeAssistantMessageV2
150
- // If assistant message has tool_calls, include them for context
151
- // Using double assertion as the OpenAI API supports this format,
152
- // but the agents SDK types are more restrictive
153
- if (
154
- assistantMessage.tool_calls &&
155
- assistantMessage.tool_calls.length > 0
156
- ) {
157
- return {
158
- role: 'assistant',
159
- content: assistantMessage.content ?? '',
160
- tool_calls: assistantMessage.tool_calls.map(tc => ({
161
- id: tc.id,
162
- type: tc.type,
163
- function: {
164
- name: tc.function.name,
165
- arguments: tc.function.arguments,
166
- },
167
- })),
168
- } as unknown as AgenticInputMessage
169
- }
170
- // Regular assistant message without tool_calls
171
- return {
172
- role: 'assistant',
173
- content: [
174
- {
175
- type: 'output_text',
176
- text: assistantMessage.content ?? '',
177
- },
178
- ],
179
- status: 'completed',
180
- }
181
- }
182
- case 'tool': {
183
- // Tool messages provide context about previous tool executions
184
- // Using double assertion as the OpenAI API supports this format,
185
- // but the agents SDK types are more restrictive
186
- const toolMessage = message as HubtypeToolMessageV2
187
- return {
188
- role: 'tool',
189
- tool_call_id: toolMessage.tool_call_id,
190
- content: toolMessage.content ?? '',
191
- } as unknown as AgenticInputMessage
192
- }
193
- case 'system':
194
- return {
195
- role: 'system',
196
- content: message.content ?? '',
197
- }
198
- default:
199
- throw new Error(
200
- `Invalid message role: ${(message as HubtypeMessageV2).role}`
201
- )
202
- }
203
- }
204
-
205
- async trackLlmRuns(botId: string, data: TrackLlmRunsData): Promise<void> {
206
- // Not stop the bot execution if the tracking fails, just log the error
207
- try {
208
- const url = `${HUBTYPE_API_URL}/external/v2/conversational_apps/${botId}/track_llm_runs/`
209
- const headers = {
210
- 'Content-Type': 'application/json',
211
- Authorization: `Bearer ${this.authToken}`,
212
- }
213
- await axios.post(url, data, { headers })
214
- } catch (error) {
215
- console.error('Failed to track LLM runs:', error)
216
- }
217
- }
218
-
219
- private formatMessage(message: HubtypeMessage): AgenticInputMessage {
220
- if (message.role === 'user') {
221
- return {
222
- content: message.content,
223
- role: 'user',
224
- }
225
- } else if (message.role === 'assistant') {
226
- return {
227
- role: 'assistant',
228
- content: [
229
- {
230
- type: 'output_text',
231
- text: message.content,
232
- },
233
- ],
234
- status: 'completed',
235
- }
236
- } else {
237
- throw new Error('Invalid message role')
238
- }
239
- }
240
- }
@@ -1,106 +0,0 @@
1
- import type { AgenticInputMessage } from '../types'
2
-
3
- export enum TrackProductName {
4
- AI_AGENT = 'ai_agent',
5
- }
6
-
7
- export enum TrackFeature {
8
- AI_AGENT_RUN = 'ai_agent_run',
9
- AI_AGENT_GUARDRAIL = 'ai_agent_guardrail',
10
- }
11
-
12
- export interface LlmRunData {
13
- inference_id: string
14
- is_test: boolean
15
- product_name: string
16
- deployment_name: string
17
- model_name: string
18
- feature: string
19
- api_version: string
20
- num_prompt_tokens: number
21
- num_completion_tokens: number
22
- duration_in_milliseconds: number
23
- temperature: number
24
- error: string | null
25
- }
26
-
27
- export interface TrackLlmRunsData {
28
- llm_runs: LlmRunData[]
29
- }
30
-
31
- interface HubtypeAssistantMessage {
32
- role: 'assistant'
33
- content: string
34
- }
35
-
36
- interface HubtypeUserMessage {
37
- role: 'user'
38
- content: string
39
- }
40
-
41
- export type HubtypeMessage = HubtypeAssistantMessage | HubtypeUserMessage
42
-
43
- // V2 API Types
44
- interface HubtypeToolCall {
45
- id: string
46
- type: 'function'
47
- function: {
48
- name: string
49
- arguments: string
50
- }
51
- }
52
-
53
- interface HubtypeUserMessageV2 {
54
- role: 'user'
55
- content: string | null
56
- }
57
-
58
- export interface HubtypeAssistantMessageV2 {
59
- role: 'assistant'
60
- content: string | null
61
- tool_calls?: HubtypeToolCall[] | null
62
- }
63
-
64
- export interface HubtypeToolMessageV2 {
65
- role: 'tool'
66
- content: string | null
67
- tool_call_id: string
68
- }
69
-
70
- interface HubtypeSystemMessageV2 {
71
- role: 'system'
72
- content: string | null
73
- }
74
-
75
- export type HubtypeMessageV2 =
76
- | HubtypeUserMessageV2
77
- | HubtypeAssistantMessageV2
78
- | HubtypeToolMessageV2
79
- | HubtypeSystemMessageV2
80
-
81
- export interface MessageHistoryResponseV2 {
82
- messages: HubtypeMessageV2[]
83
- conversation_id: string | null
84
- truncated: boolean
85
- }
86
-
87
- export interface GetMessagesV2Options {
88
- maxMessages?: number
89
- includeToolCalls?: boolean
90
- maxFullToolResults?: number
91
- debugMode?: boolean
92
- }
93
-
94
- export interface GetMessagesV2Result {
95
- messages: AgenticInputMessage[]
96
- conversationId: string | null
97
- truncated: boolean
98
- }
99
-
100
- export interface MessageHistoryV2Params {
101
- last_message_id: string
102
- max_messages?: number
103
- include_tool_calls?: boolean
104
- max_full_tool_results?: number
105
- debug_mode?: boolean
106
- }
@@ -1,21 +0,0 @@
1
- import type { BotExecutorMessage } from '@botonic/core'
2
- import z from 'zod'
3
-
4
- export type { BotExecutorMessage }
5
-
6
- export const BotExecutorSchema = z
7
- .object({
8
- type: z.enum(['botExecutor']),
9
- content: z.object({
10
- text: z.string(),
11
- buttons: z.array(
12
- z.object({
13
- text: z.string(),
14
- payload: z.string(),
15
- })
16
- ),
17
- }),
18
- })
19
- .describe(
20
- 'A text message with buttons to allow the bot to execute a specific action. Use it only when asked explicitly in the prompt'
21
- )
@@ -1,24 +0,0 @@
1
- import type { CarouselMessage } from '@botonic/core'
2
- import { z } from 'zod'
3
-
4
- export type { CarouselMessage }
5
-
6
- export const CarouselSchema = z
7
- .object({
8
- type: z.enum(['carousel']),
9
- content: z.object({
10
- text: z.string().nullable().optional(),
11
- elements: z.array(
12
- 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
- }),
23
- })
24
- .describe('A carousel message containing a list of elements')
@@ -1,12 +0,0 @@
1
- import type { ExitMessage } from '@botonic/core'
2
- import z from 'zod'
3
-
4
- export type { ExitMessage }
5
-
6
- export const ExitSchema = z
7
- .object({
8
- type: z.enum(['exit']),
9
- })
10
- .describe(
11
- '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'
12
- )
@@ -1,25 +0,0 @@
1
- import type { OutputMessage } from '@botonic/core'
2
- import { z } from 'zod'
3
- import { BotExecutorSchema } from './bot-executor'
4
- import { CarouselSchema } from './carousel'
5
- import { ExitSchema } from './exit'
6
- import { TextSchema } from './text'
7
- import { TextWithButtonsSchema } from './text-with-buttons'
8
-
9
- export interface Output {
10
- messages: OutputMessage[]
11
- }
12
-
13
- export const OutputSchema = z
14
- .object({
15
- messages: z.array(
16
- z.union([
17
- TextSchema,
18
- TextWithButtonsSchema,
19
- CarouselSchema,
20
- ExitSchema,
21
- BotExecutorSchema,
22
- ])
23
- ),
24
- })
25
- .describe('The messages to be sent to the user')
@@ -1,21 +0,0 @@
1
- import type { TextWithButtonsMessage } from '@botonic/core'
2
- import z from 'zod'
3
-
4
- export type { TextWithButtonsMessage }
5
-
6
- export const TextWithButtonsSchema = z
7
- .object({
8
- type: z.enum(['textWithButtons']),
9
- content: z.object({
10
- text: z.string(),
11
- buttons: z.array(
12
- z.object({
13
- text: z.string(),
14
- url: z.string().nullable().optional(),
15
- })
16
- ),
17
- }),
18
- })
19
- .describe(
20
- 'A text message with buttons to allow the user to use quick replies'
21
- )
@@ -1,13 +0,0 @@
1
- import type { TextMessage } from '@botonic/core'
2
- import { z } from 'zod'
3
-
4
- export type { TextMessage }
5
-
6
- export const TextSchema = z
7
- .object({
8
- type: z.enum(['text']),
9
- content: z.object({
10
- text: z.string(),
11
- }),
12
- })
13
- .describe('A text message')
@@ -1,5 +0,0 @@
1
- import type { Tool } from '../types'
2
-
3
- export { retrieveKnowledge } from './retrieve-knowledge'
4
-
5
- export const mandatoryTools: Tool[] = []
@@ -1,37 +0,0 @@
1
- import { type RunContext, tool } from '@openai/agents'
2
- import { z } from 'zod'
3
-
4
- import { HubtypeApiClient } from '../services/hubtype-api-client'
5
- import type { Context } from '../types'
6
-
7
- export const retrieveKnowledge = tool({
8
- name: 'retrieve_knowledge',
9
- description:
10
- 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
11
- parameters: z.object({
12
- query: z.string().describe('The query to search the knowledge base for'),
13
- }),
14
- execute: async (
15
- input: { query: string },
16
- runContext?: RunContext<Context>
17
- ): Promise<string[]> => {
18
- const context = runContext?.context
19
- const query = input.query
20
- if (!context) {
21
- throw new Error('Context is required')
22
- }
23
- const sourceIds = context.sourceIds
24
- const client = new HubtypeApiClient(context.authToken)
25
- const chunks = await client.retrieveSimilarChunks(query, sourceIds)
26
- const chunkTexts = chunks.map(chunk => chunk.text)
27
-
28
- context.knowledgeUsed = {
29
- query,
30
- sourceIds,
31
- chunksIds: chunks.map(chunk => chunk.id),
32
- chunkTexts,
33
- }
34
-
35
- return chunkTexts
36
- },
37
- })
package/src/types.ts DELETED
@@ -1,110 +0,0 @@
1
- import {
2
- AgenticOutputMessage,
3
- AiAgentArgs,
4
- type BotContext,
5
- GuardrailRule,
6
- InferenceResponse,
7
- type ResolvedPlugins,
8
- RunResult,
9
- } from '@botonic/core'
10
- import type {
11
- Agent,
12
- AgentInputItem,
13
- AgentOutputType,
14
- RunContext as OpenAIRunContext,
15
- Tool as OpenAITool,
16
- } from '@openai/agents'
17
- import type { ZodSchema } from 'zod'
18
-
19
- import type { OutputSchema } from './structured-output'
20
-
21
- export interface Context<
22
- TPlugins extends ResolvedPlugins = ResolvedPlugins,
23
- TExtraData = any,
24
- > {
25
- authToken: string
26
- sourceIds: string[]
27
- knowledgeUsed: {
28
- query: string
29
- sourceIds: string[]
30
- chunksIds: string[]
31
- chunkTexts: string[]
32
- }
33
- request: BotContext<TPlugins, TExtraData>
34
- }
35
-
36
- export type RunContext<
37
- TPlugins extends ResolvedPlugins = ResolvedPlugins,
38
- TExtraData = any,
39
- > = OpenAIRunContext<Context<TPlugins, TExtraData>>
40
-
41
- export interface CustomTool<
42
- TPlugins extends ResolvedPlugins = ResolvedPlugins,
43
- TExtraData = any,
44
- > {
45
- name: string
46
- description: string
47
- schema: ZodSchema
48
- func: (
49
- input?: any,
50
- runContext?: RunContext<TPlugins, TExtraData>
51
- ) => Promise<any>
52
- }
53
-
54
- export interface Chunk {
55
- id: string
56
- text: string
57
- }
58
-
59
- export type Tool<
60
- TPlugins extends ResolvedPlugins = ResolvedPlugins,
61
- TExtraData = any,
62
- > = OpenAITool<Context<TPlugins, TExtraData>>
63
-
64
- export type AIAgent<
65
- TPlugins extends ResolvedPlugins = ResolvedPlugins,
66
- TExtraData = any,
67
- > = Agent<Context<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>
68
-
69
- export type MessageHistoryApiVersion = 'v1' | 'v2'
70
-
71
- export interface MemoryOptions {
72
- maxMessages?: number
73
- includeToolCalls?: boolean
74
- maxFullToolResults?: number
75
- debugMode?: boolean
76
- }
77
-
78
- export interface PluginAiAgentOptions<
79
- TPlugins extends ResolvedPlugins = ResolvedPlugins,
80
- TExtraData = any,
81
- > {
82
- authToken?: string
83
- customTools?: CustomTool<TPlugins, TExtraData>[]
84
- maxRetries?: number
85
- timeout?: number
86
- /** API version for message history endpoint. Defaults to 'v2'. */
87
- messageHistoryApiVersion?: MessageHistoryApiVersion
88
- /** Options for V2 message history API. Only used when messageHistoryApiVersion is 'v2'. */
89
- memory?: MemoryOptions
90
- /** Enable debug logging for AI agent configuration and execution details. */
91
- enableDebug?: boolean
92
- }
93
-
94
- export interface ResultRawResponse {
95
- usage: {
96
- inputTokens: number
97
- outputTokens: number
98
- }
99
- providerData?: Record<string, unknown>
100
- }
101
-
102
- export type AgenticInputMessage = AgentInputItem
103
-
104
- export {
105
- AgenticOutputMessage,
106
- AiAgentArgs,
107
- GuardrailRule,
108
- InferenceResponse,
109
- RunResult,
110
- }
File without changes