@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.
- package/lib/cjs/agent-builder.d.ts +1 -1
- package/lib/cjs/agent-builder.js +13 -3
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/hubtype-api-client.d.ts +1 -0
- package/lib/cjs/hubtype-api-client.js +19 -1
- package/lib/cjs/hubtype-api-client.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/structured-output/carousel.d.ts +9 -9
- package/lib/cjs/structured-output/carousel.js +1 -1
- package/lib/cjs/structured-output/carousel.js.map +1 -1
- package/lib/cjs/structured-output/index.d.ts +36 -18
- package/lib/cjs/structured-output/text-with-buttons.d.ts +19 -5
- package/lib/cjs/structured-output/text-with-buttons.js +3 -1
- package/lib/cjs/structured-output/text-with-buttons.js.map +1 -1
- package/lib/cjs/tools/index.d.ts +1 -0
- package/lib/cjs/tools/index.js +3 -1
- package/lib/cjs/tools/index.js.map +1 -1
- package/lib/cjs/tools/retrieve-knowledge.d.ts +2 -0
- package/lib/cjs/tools/retrieve-knowledge.js +25 -0
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -0
- package/lib/cjs/types.d.ts +7 -17
- package/lib/esm/agent-builder.d.ts +1 -1
- package/lib/esm/agent-builder.js +14 -4
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/hubtype-api-client.d.ts +1 -0
- package/lib/esm/hubtype-api-client.js +19 -1
- package/lib/esm/hubtype-api-client.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +3 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/structured-output/carousel.d.ts +9 -9
- package/lib/esm/structured-output/carousel.js +1 -1
- package/lib/esm/structured-output/carousel.js.map +1 -1
- package/lib/esm/structured-output/index.d.ts +36 -18
- package/lib/esm/structured-output/text-with-buttons.d.ts +19 -5
- package/lib/esm/structured-output/text-with-buttons.js +3 -1
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
- package/lib/esm/tools/index.d.ts +1 -0
- package/lib/esm/tools/index.js +1 -0
- package/lib/esm/tools/index.js.map +1 -1
- package/lib/esm/tools/retrieve-knowledge.d.ts +2 -0
- package/lib/esm/tools/retrieve-knowledge.js +22 -0
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -0
- package/lib/esm/types.d.ts +7 -17
- package/package.json +4 -4
- package/src/agent-builder.ts +23 -5
- package/src/hubtype-api-client.ts +22 -1
- package/src/index.ts +5 -3
- package/src/structured-output/carousel.ts +1 -1
- package/src/structured-output/text-with-buttons.ts +5 -1
- package/src/tools/index.ts +1 -0
- package/src/tools/retrieve-knowledge.ts +28 -0
- 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)
|
package/src/tools/index.ts
CHANGED
|
@@ -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
|
|
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:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
55
|
+
export {
|
|
56
|
+
AgenticOutputMessage,
|
|
57
|
+
AiAgentArgs,
|
|
58
|
+
GuardrailRule,
|
|
59
|
+
InferenceResponse,
|
|
60
|
+
RunResult,
|
|
61
|
+
}
|