@botonic/plugin-ai-agents 0.40.0-alpha.0 → 0.40.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 +11 -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 +2 -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 +3 -14
  24. package/lib/esm/agent-builder.d.ts +1 -1
  25. package/lib/esm/agent-builder.js +12 -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 +2 -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 +3 -14
  47. package/package.json +3 -3
  48. package/src/agent-builder.ts +16 -5
  49. package/src/hubtype-api-client.ts +22 -1
  50. package/src/index.ts +4 -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 +27 -0
  55. package/src/types.ts +10 -13
@@ -0,0 +1,27 @@
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
+ return chunks
26
+ },
27
+ })
package/src/types.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import {
2
2
  AgenticOutputMessage,
3
+ AiAgentArgs,
4
+ GuardrailRule,
3
5
  InferenceResponse,
4
6
  RunResult,
5
7
  } from '@botonic/core'
@@ -15,6 +17,7 @@ import { OutputSchema } from './structured-output'
15
17
 
16
18
  export interface Context {
17
19
  authToken: string
20
+ sources: string[]
18
21
  }
19
22
 
20
23
  export type RunContext = OpenAIRunContext<Context>
@@ -26,11 +29,6 @@ export interface CustomTool {
26
29
  func: (input?: any, runContext?: RunContext) => Promise<any>
27
30
  }
28
31
 
29
- export interface GuardrailRule {
30
- name: string
31
- description: string
32
- }
33
-
34
32
  export type ContactInfo = Record<string, string>
35
33
 
36
34
  export type Tool = OpenAITool<Context>
@@ -40,13 +38,12 @@ export interface PluginAiAgentOptions {
40
38
  customTools?: CustomTool[]
41
39
  }
42
40
 
43
- export interface AiAgentArgs {
44
- name: string
45
- instructions: string
46
- activeTools?: { name: string }[]
47
- inputGuardrailRules?: GuardrailRule[]
48
- }
49
-
50
41
  export type AgenticInputMessage = AgentInputItem
51
42
 
52
- export type { AgenticOutputMessage, InferenceResponse, RunResult }
43
+ export {
44
+ AgenticOutputMessage,
45
+ AiAgentArgs,
46
+ GuardrailRule,
47
+ InferenceResponse,
48
+ RunResult,
49
+ }