@botonic/plugin-ai-agents 0.40.0-alpha.1 → 0.40.1-alpha.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 (55) hide show
  1. package/lib/cjs/agent-builder.d.ts +1 -1
  2. package/lib/cjs/agent-builder.js +13 -3
  3. package/lib/cjs/agent-builder.js.map +1 -1
  4. package/lib/cjs/hubtype-api-client.d.ts +1 -0
  5. package/lib/cjs/hubtype-api-client.js +19 -1
  6. package/lib/cjs/hubtype-api-client.js.map +1 -1
  7. package/lib/cjs/index.d.ts +2 -2
  8. package/lib/cjs/index.js +3 -1
  9. package/lib/cjs/index.js.map +1 -1
  10. package/lib/cjs/structured-output/carousel.d.ts +9 -9
  11. package/lib/cjs/structured-output/carousel.js +1 -1
  12. package/lib/cjs/structured-output/carousel.js.map +1 -1
  13. package/lib/cjs/structured-output/index.d.ts +36 -18
  14. package/lib/cjs/structured-output/text-with-buttons.d.ts +19 -5
  15. package/lib/cjs/structured-output/text-with-buttons.js +3 -1
  16. package/lib/cjs/structured-output/text-with-buttons.js.map +1 -1
  17. package/lib/cjs/tools/index.d.ts +1 -0
  18. package/lib/cjs/tools/index.js +3 -1
  19. package/lib/cjs/tools/index.js.map +1 -1
  20. package/lib/cjs/tools/retrieve-knowledge.d.ts +2 -0
  21. package/lib/cjs/tools/retrieve-knowledge.js +25 -0
  22. package/lib/cjs/tools/retrieve-knowledge.js.map +1 -0
  23. package/lib/cjs/types.d.ts +7 -17
  24. package/lib/esm/agent-builder.d.ts +1 -1
  25. package/lib/esm/agent-builder.js +14 -4
  26. package/lib/esm/agent-builder.js.map +1 -1
  27. package/lib/esm/hubtype-api-client.d.ts +1 -0
  28. package/lib/esm/hubtype-api-client.js +19 -1
  29. package/lib/esm/hubtype-api-client.js.map +1 -1
  30. package/lib/esm/index.d.ts +2 -2
  31. package/lib/esm/index.js +3 -1
  32. package/lib/esm/index.js.map +1 -1
  33. package/lib/esm/structured-output/carousel.d.ts +9 -9
  34. package/lib/esm/structured-output/carousel.js +1 -1
  35. package/lib/esm/structured-output/carousel.js.map +1 -1
  36. package/lib/esm/structured-output/index.d.ts +36 -18
  37. package/lib/esm/structured-output/text-with-buttons.d.ts +19 -5
  38. package/lib/esm/structured-output/text-with-buttons.js +3 -1
  39. package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
  40. package/lib/esm/tools/index.d.ts +1 -0
  41. package/lib/esm/tools/index.js +1 -0
  42. package/lib/esm/tools/index.js.map +1 -1
  43. package/lib/esm/tools/retrieve-knowledge.d.ts +2 -0
  44. package/lib/esm/tools/retrieve-knowledge.js +22 -0
  45. package/lib/esm/tools/retrieve-knowledge.js.map +1 -0
  46. package/lib/esm/types.d.ts +7 -17
  47. package/package.json +4 -4
  48. package/src/agent-builder.ts +23 -5
  49. package/src/hubtype-api-client.ts +22 -1
  50. package/src/index.ts +5 -3
  51. package/src/structured-output/carousel.ts +1 -1
  52. package/src/structured-output/text-with-buttons.ts +5 -1
  53. package/src/tools/index.ts +1 -0
  54. package/src/tools/retrieve-knowledge.ts +28 -0
  55. package/src/types.ts +25 -16
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BotContext, Plugin } from '@botonic/core'
1
+ import { AiAgentArgs, BotContext, Plugin } from '@botonic/core'
2
2
  import { tool } from '@openai/agents'
3
3
 
4
4
  import { AIAgentBuilder } from './agent-builder'
@@ -8,7 +8,6 @@ import { setUpOpenAI } from './openai'
8
8
  import { AIAgentRunner } from './runner'
9
9
  import {
10
10
  AgenticInputMessage,
11
- AiAgentArgs,
12
11
  Context,
13
12
  CustomTool,
14
13
  InferenceResponse,
@@ -48,7 +47,8 @@ export default class BotonicPluginAiAgents implements Plugin {
48
47
  aiAgentArgs.instructions,
49
48
  tools,
50
49
  request.session.user.contact_info || {},
51
- aiAgentArgs.inputGuardrailRules || []
50
+ aiAgentArgs.inputGuardrailRules || [],
51
+ aiAgentArgs.sourceIds || []
52
52
  ).build()
53
53
 
54
54
  const messages = await this.getMessages(
@@ -58,6 +58,8 @@ export default class BotonicPluginAiAgents implements Plugin {
58
58
  )
59
59
  const context: Context = {
60
60
  authToken,
61
+ request,
62
+ sources: aiAgentArgs.sourceIds || [],
61
63
  }
62
64
 
63
65
  const runner = new AIAgentRunner(agent)
@@ -14,7 +14,7 @@ export const CarouselSchema = z
14
14
  image: z.string(),
15
15
  button: z.object({
16
16
  text: z.string(),
17
- url: z.string(),
17
+ url: z.string().nullable().optional(),
18
18
  }),
19
19
  })
20
20
  ),
@@ -8,7 +8,11 @@ export const TextWithButtonsSchema = z
8
8
  type: z.enum(['textWithButtons']),
9
9
  content: z.object({
10
10
  text: z.string(),
11
- buttons: z.array(z.string()),
11
+ buttons: z.array(
12
+ z.object({
13
+ text: z.string(),
14
+ })
15
+ ),
12
16
  }),
13
17
  })
14
18
  .describe(
@@ -1,3 +1,4 @@
1
1
  import { Tool } from '../types'
2
+ export { retrieveKnowledge } from './retrieve-knowledge'
2
3
 
3
4
  export const mandatoryTools: Tool[] = []
@@ -0,0 +1,28 @@
1
+ import { RunContext, tool } from '@openai/agents'
2
+ import { z } from 'zod'
3
+
4
+ import { HubtypeApiClient } from '../hubtype-api-client'
5
+ import { Context } from '../types'
6
+
7
+ export const retrieveKnowledge = tool<any, Context, any>({
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
+ { query }: { query: string },
16
+ runContext?: RunContext<Context>
17
+ ): Promise<string[]> => {
18
+ const context = runContext?.context
19
+ if (!context) {
20
+ throw new Error('Context is required')
21
+ }
22
+ const sources = context.sources
23
+ const client = new HubtypeApiClient(context.authToken)
24
+ const chunks = await client.retrieveSimilarChunks(query, sources)
25
+
26
+ return chunks
27
+ },
28
+ })
package/src/types.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import {
2
2
  AgenticOutputMessage,
3
+ AiAgentArgs,
4
+ BotContext,
5
+ GuardrailRule,
3
6
  InferenceResponse,
7
+ ResolvedPlugins,
4
8
  RunResult,
5
9
  } from '@botonic/core'
6
10
  import {
@@ -13,22 +17,28 @@ import { ZodSchema } from 'zod'
13
17
 
14
18
  import { OutputSchema } from './structured-output'
15
19
 
16
- export interface Context {
20
+ export interface Context<
21
+ TPlugins extends ResolvedPlugins = ResolvedPlugins,
22
+ TExtraData = any,
23
+ > {
17
24
  authToken: string
25
+ request: BotContext<TPlugins, TExtraData>
26
+ sources: string[]
18
27
  }
19
28
 
20
- export type RunContext = OpenAIRunContext<Context>
29
+ export type RunContext<
30
+ TPlugins extends ResolvedPlugins = ResolvedPlugins,
31
+ TExtraData = any,
32
+ > = OpenAIRunContext<Context<TPlugins, TExtraData>>
21
33
 
22
34
  export interface CustomTool {
23
35
  name: string
24
36
  description: string
25
37
  schema: ZodSchema
26
- func: (input?: any, runContext?: RunContext) => Promise<any>
27
- }
28
-
29
- export interface GuardrailRule {
30
- name: string
31
- description: string
38
+ func: <TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any>(
39
+ input?: any,
40
+ runContext?: RunContext<TPlugins, TExtraData>
41
+ ) => Promise<any>
32
42
  }
33
43
 
34
44
  export type ContactInfo = Record<string, string>
@@ -40,13 +50,12 @@ export interface PluginAiAgentOptions {
40
50
  customTools?: CustomTool[]
41
51
  }
42
52
 
43
- export interface AiAgentArgs {
44
- name: string
45
- instructions: string
46
- activeTools?: { name: string }[]
47
- inputGuardrailRules?: GuardrailRule[]
48
- }
49
-
50
53
  export type AgenticInputMessage = AgentInputItem
51
54
 
52
- export type { AgenticOutputMessage, InferenceResponse, RunResult }
55
+ export {
56
+ AgenticOutputMessage,
57
+ AiAgentArgs,
58
+ GuardrailRule,
59
+ InferenceResponse,
60
+ RunResult,
61
+ }