@botonic/plugin-ai-agents 0.37.0 → 0.37.2-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/README.md +148 -6
- package/lib/cjs/agent-builder.d.ts +6 -2
- package/lib/cjs/agent-builder.js +28 -5
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/guardrails/index.d.ts +1 -0
- package/lib/cjs/guardrails/index.js +5 -0
- package/lib/cjs/guardrails/index.js.map +1 -0
- package/lib/cjs/guardrails/input.d.ts +3 -0
- package/lib/cjs/guardrails/input.js +33 -0
- package/lib/cjs/guardrails/input.js.map +1 -0
- 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/runner.d.ts +3 -2
- package/lib/cjs/runner.js +31 -1
- package/lib/cjs/runner.js.map +1 -1
- package/lib/cjs/structured-output/carousel.d.ts +2 -17
- package/lib/cjs/structured-output/carousel.js.map +1 -1
- package/lib/cjs/structured-output/exit.d.ts +2 -4
- package/lib/cjs/structured-output/exit.js.map +1 -1
- package/lib/cjs/structured-output/index.d.ts +1 -5
- package/lib/cjs/structured-output/index.js.map +1 -1
- package/lib/cjs/structured-output/text-with-buttons.d.ts +2 -8
- package/lib/cjs/structured-output/text-with-buttons.js.map +1 -1
- package/lib/cjs/structured-output/text.d.ts +2 -7
- package/lib/cjs/structured-output/text.js.map +1 -1
- package/lib/cjs/types.d.ts +12 -4
- package/lib/esm/agent-builder.d.ts +6 -2
- package/lib/esm/agent-builder.js +28 -5
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/guardrails/index.d.ts +1 -0
- package/lib/esm/guardrails/index.js +2 -0
- package/lib/esm/guardrails/index.js.map +1 -0
- package/lib/esm/guardrails/input.d.ts +3 -0
- package/lib/esm/guardrails/input.js +29 -0
- package/lib/esm/guardrails/input.js.map +1 -0
- 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/runner.d.ts +3 -2
- package/lib/esm/runner.js +32 -2
- package/lib/esm/runner.js.map +1 -1
- package/lib/esm/structured-output/carousel.d.ts +2 -17
- package/lib/esm/structured-output/carousel.js.map +1 -1
- package/lib/esm/structured-output/exit.d.ts +2 -4
- package/lib/esm/structured-output/exit.js.map +1 -1
- package/lib/esm/structured-output/index.d.ts +1 -5
- package/lib/esm/structured-output/index.js +1 -1
- package/lib/esm/structured-output/index.js.map +1 -1
- package/lib/esm/structured-output/text-with-buttons.d.ts +2 -8
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
- package/lib/esm/structured-output/text.d.ts +2 -7
- package/lib/esm/structured-output/text.js.map +1 -1
- package/lib/esm/types.d.ts +12 -4
- package/package.json +3 -3
- package/src/agent-builder.ts +43 -7
- package/src/guardrails/index.ts +1 -0
- package/src/guardrails/input.ts +39 -0
- package/src/index.ts +7 -3
- package/src/runner.ts +49 -4
- package/src/structured-output/carousel.ts +2 -15
- package/src/structured-output/exit.ts +2 -5
- package/src/structured-output/index.ts +5 -13
- package/src/structured-output/text-with-buttons.ts +2 -9
- package/src/structured-output/text.ts +2 -8
- package/src/types.ts +20 -5
- package/lib/cjs/structured-output/shared.d.ts +0 -3
- package/lib/cjs/structured-output/shared.js +0 -3
- package/lib/cjs/structured-output/shared.js.map +0 -1
- package/lib/esm/structured-output/shared.d.ts +0 -3
- package/lib/esm/structured-output/shared.js +0 -2
- package/lib/esm/structured-output/shared.js.map +0 -1
- package/src/structured-output/shared.ts +0 -3
package/src/runner.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
InputGuardrailTripwireTriggered,
|
|
3
|
+
Runner,
|
|
4
|
+
RunToolCallItem,
|
|
5
|
+
} from '@openai/agents'
|
|
2
6
|
|
|
3
7
|
import {
|
|
4
8
|
AgenticInputMessage,
|
|
5
9
|
AgenticOutputMessage,
|
|
6
10
|
AIAgent,
|
|
7
11
|
Context,
|
|
12
|
+
RunResult,
|
|
8
13
|
} from './types'
|
|
9
14
|
|
|
10
15
|
export class AIAgentRunner {
|
|
@@ -18,7 +23,7 @@ export class AIAgentRunner {
|
|
|
18
23
|
messages: AgenticInputMessage[],
|
|
19
24
|
context: Context,
|
|
20
25
|
maxRetries: number = 1
|
|
21
|
-
): Promise<
|
|
26
|
+
): Promise<RunResult> {
|
|
22
27
|
return this.runWithRetry(messages, context, maxRetries, 1)
|
|
23
28
|
}
|
|
24
29
|
|
|
@@ -27,18 +32,58 @@ export class AIAgentRunner {
|
|
|
27
32
|
context: Context,
|
|
28
33
|
maxRetries: number,
|
|
29
34
|
attempt: number
|
|
30
|
-
): Promise<
|
|
35
|
+
): Promise<RunResult> {
|
|
31
36
|
try {
|
|
32
37
|
const runner = new Runner({
|
|
33
38
|
modelSettings: { temperature: 0 },
|
|
34
39
|
})
|
|
35
40
|
const result = await runner.run(this.agent, messages, { context })
|
|
36
|
-
|
|
41
|
+
|
|
42
|
+
const outputMessages = result.finalOutput?.messages || []
|
|
43
|
+
const hasExit =
|
|
44
|
+
outputMessages.length === 0 ||
|
|
45
|
+
outputMessages.some(message => message.type === 'exit')
|
|
46
|
+
const toolsExecuted = this.getExecutedNameTools(result)
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
messages: hasExit
|
|
50
|
+
? []
|
|
51
|
+
: (outputMessages.filter(
|
|
52
|
+
message => message.type !== 'exit'
|
|
53
|
+
) as AgenticOutputMessage[]),
|
|
54
|
+
toolsExecuted,
|
|
55
|
+
exit: hasExit,
|
|
56
|
+
inputGuardrailTriggered: [],
|
|
57
|
+
outputGuardrailTriggered: [],
|
|
58
|
+
}
|
|
37
59
|
} catch (error) {
|
|
60
|
+
if (error instanceof InputGuardrailTripwireTriggered) {
|
|
61
|
+
return {
|
|
62
|
+
messages: [],
|
|
63
|
+
toolsExecuted: [],
|
|
64
|
+
exit: true,
|
|
65
|
+
inputGuardrailTriggered: error.result.output.outputInfo,
|
|
66
|
+
outputGuardrailTriggered: [],
|
|
67
|
+
}
|
|
68
|
+
}
|
|
38
69
|
if (attempt > maxRetries) {
|
|
39
70
|
throw error
|
|
40
71
|
}
|
|
41
72
|
return this.runWithRetry(messages, context, maxRetries, attempt + 1)
|
|
42
73
|
}
|
|
43
74
|
}
|
|
75
|
+
|
|
76
|
+
private getExecutedNameTools(result) {
|
|
77
|
+
return (
|
|
78
|
+
result.newItems
|
|
79
|
+
?.filter(item => item instanceof RunToolCallItem)
|
|
80
|
+
.map((item: RunToolCallItem) => {
|
|
81
|
+
if (item.rawItem.type === 'function_call') {
|
|
82
|
+
return item.rawItem.name
|
|
83
|
+
}
|
|
84
|
+
return ''
|
|
85
|
+
})
|
|
86
|
+
.filter((toolName: string) => toolName !== '') || []
|
|
87
|
+
)
|
|
88
|
+
}
|
|
44
89
|
}
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
+
import { CarouselMessage } from '@botonic/core'
|
|
1
2
|
import { z } from 'zod'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
interface CarouselElement {
|
|
6
|
-
title: string
|
|
7
|
-
subtitle: string
|
|
8
|
-
image: string
|
|
9
|
-
button: { text: string; url: string }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface CarouselMessage extends BaseMessage {
|
|
13
|
-
type: 'carousel'
|
|
14
|
-
content: {
|
|
15
|
-
elements: CarouselElement[]
|
|
16
|
-
}
|
|
17
|
-
}
|
|
4
|
+
export type { CarouselMessage }
|
|
18
5
|
|
|
19
6
|
export const CarouselSchema = z
|
|
20
7
|
.object({
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
+
import { ExitMessage } from '@botonic/core'
|
|
1
2
|
import z from 'zod'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface ExitMessage extends BaseMessage {
|
|
6
|
-
type: 'exit'
|
|
7
|
-
}
|
|
4
|
+
export type { ExitMessage }
|
|
8
5
|
|
|
9
6
|
export const ExitSchema = z
|
|
10
7
|
.object({
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
+
import { OutputMessage } from '@botonic/core'
|
|
1
2
|
import { z } from 'zod'
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
TextWithButtonsMessage,
|
|
8
|
-
TextWithButtonsSchema,
|
|
9
|
-
} from './text-with-buttons'
|
|
10
|
-
|
|
11
|
-
export type OutputMessage =
|
|
12
|
-
| TextMessage
|
|
13
|
-
| TextWithButtonsMessage
|
|
14
|
-
| CarouselMessage
|
|
15
|
-
| ExitMessage
|
|
4
|
+
import { CarouselSchema } from './carousel'
|
|
5
|
+
import { ExitSchema } from './exit'
|
|
6
|
+
import { TextSchema } from './text'
|
|
7
|
+
import { TextWithButtonsSchema } from './text-with-buttons'
|
|
16
8
|
|
|
17
9
|
export interface Output {
|
|
18
10
|
messages: OutputMessage[]
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
+
import { TextWithButtonsMessage } from '@botonic/core'
|
|
1
2
|
import z from 'zod'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface TextWithButtonsMessage extends BaseMessage {
|
|
6
|
-
type: 'textWithButtons'
|
|
7
|
-
content: {
|
|
8
|
-
text: string
|
|
9
|
-
buttons: string[]
|
|
10
|
-
}
|
|
11
|
-
}
|
|
4
|
+
export type { TextWithButtonsMessage }
|
|
12
5
|
|
|
13
6
|
export const TextWithButtonsSchema = z
|
|
14
7
|
.object({
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
+
import { TextMessage } from '@botonic/core'
|
|
1
2
|
import { z } from 'zod'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface TextMessage extends BaseMessage {
|
|
6
|
-
type: 'text'
|
|
7
|
-
content: {
|
|
8
|
-
text: string
|
|
9
|
-
}
|
|
10
|
-
}
|
|
4
|
+
export type { TextMessage }
|
|
11
5
|
|
|
12
6
|
export const TextSchema = z
|
|
13
7
|
.object({
|
package/src/types.ts
CHANGED
|
@@ -1,27 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgenticOutputMessage,
|
|
3
|
+
InferenceResponse,
|
|
4
|
+
RunResult,
|
|
5
|
+
} from '@botonic/core'
|
|
1
6
|
import {
|
|
2
7
|
Agent,
|
|
3
8
|
AgentInputItem,
|
|
4
|
-
RunContext,
|
|
9
|
+
RunContext as OpenAIRunContext,
|
|
5
10
|
Tool as OpenAITool,
|
|
6
11
|
} from '@openai/agents'
|
|
7
12
|
import { ZodSchema } from 'zod'
|
|
8
13
|
|
|
9
|
-
import {
|
|
14
|
+
import { OutputSchema } from './structured-output'
|
|
10
15
|
|
|
11
16
|
export interface Context {
|
|
12
17
|
authToken: string
|
|
13
18
|
}
|
|
14
19
|
|
|
20
|
+
export type RunContext = OpenAIRunContext<Context>
|
|
21
|
+
|
|
15
22
|
export interface CustomTool {
|
|
16
23
|
name: string
|
|
17
24
|
description: string
|
|
18
25
|
schema: ZodSchema
|
|
19
|
-
func: (input?: any, runContext?: RunContext
|
|
26
|
+
func: (input?: any, runContext?: RunContext) => Promise<any>
|
|
20
27
|
}
|
|
21
28
|
|
|
29
|
+
export interface GuardrailRule {
|
|
30
|
+
name: string
|
|
31
|
+
description: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type ContactInfo = Record<string, string>
|
|
35
|
+
|
|
22
36
|
export type Tool = OpenAITool<Context>
|
|
23
37
|
export type AIAgent = Agent<Context, typeof OutputSchema>
|
|
24
|
-
|
|
25
38
|
export interface PluginAiAgentOptions {
|
|
26
39
|
authToken?: string
|
|
27
40
|
customTools?: CustomTool[]
|
|
@@ -31,7 +44,9 @@ export interface AiAgentArgs {
|
|
|
31
44
|
name: string
|
|
32
45
|
instructions: string
|
|
33
46
|
activeTools?: { name: string }[]
|
|
47
|
+
inputGuardrailRules?: GuardrailRule[]
|
|
34
48
|
}
|
|
35
49
|
|
|
36
50
|
export type AgenticInputMessage = AgentInputItem
|
|
37
|
-
|
|
51
|
+
|
|
52
|
+
export type { AgenticOutputMessage, InferenceResponse, RunResult }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/structured-output/shared.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/structured-output/shared.ts"],"names":[],"mappings":""}
|