@botonic/plugin-ai-agents 0.46.1 → 2.23.1
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/CHANGELOG.md +209 -0
- package/README.md +13 -149
- package/package.json +23 -41
- package/src/index.d.ts +2 -0
- package/src/index.js +3 -0
- package/src/index.js.map +1 -0
- package/{lib/cjs → src/lib}/agent-builder.d.ts +5 -13
- package/{lib/cjs → src/lib}/agent-builder.js +31 -26
- package/src/lib/agent-builder.js.map +1 -0
- package/{lib/cjs → src/lib}/constants.d.ts +1 -3
- package/src/lib/constants.js +13 -0
- package/src/lib/constants.js.map +1 -0
- package/{lib/esm → src/lib}/debug-logger.d.ts +3 -5
- package/{lib/cjs → src/lib}/debug-logger.js +44 -29
- package/src/lib/debug-logger.js.map +1 -0
- package/src/lib/guardrails/index.js +2 -0
- package/src/lib/guardrails/index.js.map +1 -0
- package/src/lib/guardrails/input.d.ts +3 -0
- package/src/lib/guardrails/input.js +29 -0
- package/src/lib/guardrails/input.js.map +1 -0
- package/{lib/cjs/services → src/lib}/hubtype-api-client.d.ts +13 -5
- package/src/lib/hubtype-api-client.js +206 -0
- package/src/lib/hubtype-api-client.js.map +1 -0
- package/{lib/esm → src/lib}/index.d.ts +2 -7
- package/src/lib/index.js +111 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/openai.d.ts +1 -0
- package/src/lib/openai.js +21 -0
- package/src/lib/openai.js.map +1 -0
- package/src/lib/runner.d.ts +12 -0
- package/src/lib/runner.js +96 -0
- package/src/lib/runner.js.map +1 -0
- package/{lib/esm → src/lib}/structured-output/carousel.d.ts +1 -1
- package/src/lib/structured-output/carousel.js +19 -0
- package/src/lib/structured-output/carousel.js.map +1 -0
- package/{lib/cjs → src/lib}/structured-output/exit.d.ts +1 -1
- package/src/lib/structured-output/exit.js +7 -0
- package/src/lib/structured-output/exit.js.map +1 -0
- package/src/lib/structured-output/index.d.ts +228 -0
- package/src/lib/structured-output/index.js +11 -0
- package/src/lib/structured-output/index.js.map +1 -0
- package/{lib/esm/structured-output/bot-executor.d.ts → src/lib/structured-output/text-with-buttons.d.ts} +13 -13
- package/src/lib/structured-output/text-with-buttons.js +14 -0
- package/src/lib/structured-output/text-with-buttons.js.map +1 -0
- package/{lib/esm → src/lib}/structured-output/text.d.ts +1 -1
- package/src/lib/structured-output/text.js +10 -0
- package/src/lib/structured-output/text.js.map +1 -0
- package/{lib/esm → src/lib}/tools/index.d.ts +1 -1
- package/src/lib/tools/index.js +3 -0
- package/src/lib/tools/index.js.map +1 -0
- package/{lib/cjs → src/lib}/tools/retrieve-knowledge.d.ts +2 -2
- package/src/lib/tools/retrieve-knowledge.js +30 -0
- package/src/lib/tools/retrieve-knowledge.js.map +1 -0
- package/{lib/esm → src/lib}/types.d.ts +11 -21
- package/src/lib/types.js +2 -0
- package/src/lib/types.js.map +1 -0
- package/lib/cjs/agent-builder.js.map +0 -1
- package/lib/cjs/bot-config-tools.d.ts +0 -7
- package/lib/cjs/bot-config-tools.js +0 -19
- package/lib/cjs/bot-config-tools.js.map +0 -1
- package/lib/cjs/constants.js +0 -17
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/debug-logger.d.ts +0 -33
- package/lib/cjs/debug-logger.js.map +0 -1
- package/lib/cjs/guardrails/index.js +0 -5
- package/lib/cjs/guardrails/index.js.map +0 -1
- package/lib/cjs/guardrails/input.d.ts +0 -10
- package/lib/cjs/guardrails/input.js +0 -77
- package/lib/cjs/guardrails/input.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -18
- package/lib/cjs/index.js +0 -134
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/llm-config.d.ts +0 -15
- package/lib/cjs/llm-config.js +0 -66
- package/lib/cjs/llm-config.js.map +0 -1
- package/lib/cjs/runner.d.ts +0 -18
- package/lib/cjs/runner.js +0 -181
- package/lib/cjs/runner.js.map +0 -1
- package/lib/cjs/services/hubtype-api-client.js +0 -206
- package/lib/cjs/services/hubtype-api-client.js.map +0 -1
- package/lib/cjs/services/types.d.ts +0 -85
- package/lib/cjs/services/types.js +0 -13
- package/lib/cjs/services/types.js.map +0 -1
- package/lib/cjs/structured-output/bot-executor.d.ts +0 -49
- package/lib/cjs/structured-output/bot-executor.js +0 -18
- package/lib/cjs/structured-output/bot-executor.js.map +0 -1
- package/lib/cjs/structured-output/carousel.d.ts +0 -90
- package/lib/cjs/structured-output/carousel.js +0 -22
- package/lib/cjs/structured-output/carousel.js.map +0 -1
- package/lib/cjs/structured-output/exit.js +0 -11
- package/lib/cjs/structured-output/exit.js.map +0 -1
- package/lib/cjs/structured-output/index.d.ts +0 -603
- package/lib/cjs/structured-output/index.js +0 -28
- package/lib/cjs/structured-output/index.js.map +0 -1
- package/lib/cjs/structured-output/text-with-buttons.d.ts +0 -56
- package/lib/cjs/structured-output/text-with-buttons.js +0 -24
- package/lib/cjs/structured-output/text-with-buttons.js.map +0 -1
- package/lib/cjs/structured-output/text.d.ts +0 -23
- package/lib/cjs/structured-output/text.js +0 -13
- package/lib/cjs/structured-output/text.js.map +0 -1
- package/lib/cjs/tools/index.d.ts +0 -3
- package/lib/cjs/tools/index.js +0 -7
- package/lib/cjs/tools/index.js.map +0 -1
- package/lib/cjs/tools/retrieve-knowledge.js +0 -32
- package/lib/cjs/tools/retrieve-knowledge.js.map +0 -1
- package/lib/cjs/types.d.ts +0 -56
- package/lib/cjs/types.js +0 -3
- package/lib/cjs/types.js.map +0 -1
- package/lib/esm/agent-builder.d.ts +0 -37
- package/lib/esm/agent-builder.js +0 -106
- package/lib/esm/agent-builder.js.map +0 -1
- package/lib/esm/bot-config-tools.d.ts +0 -7
- package/lib/esm/bot-config-tools.js +0 -19
- package/lib/esm/bot-config-tools.js.map +0 -1
- package/lib/esm/constants.d.ts +0 -11
- package/lib/esm/constants.js +0 -17
- package/lib/esm/constants.js.map +0 -1
- package/lib/esm/debug-logger.js +0 -97
- package/lib/esm/debug-logger.js.map +0 -1
- package/lib/esm/guardrails/index.d.ts +0 -1
- package/lib/esm/guardrails/index.js +0 -5
- package/lib/esm/guardrails/index.js.map +0 -1
- package/lib/esm/guardrails/input.d.ts +0 -10
- package/lib/esm/guardrails/input.js +0 -77
- package/lib/esm/guardrails/input.js.map +0 -1
- package/lib/esm/index.js +0 -134
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/llm-config.d.ts +0 -15
- package/lib/esm/llm-config.js +0 -66
- package/lib/esm/llm-config.js.map +0 -1
- package/lib/esm/runner.d.ts +0 -18
- package/lib/esm/runner.js +0 -181
- package/lib/esm/runner.js.map +0 -1
- package/lib/esm/services/hubtype-api-client.d.ts +0 -14
- package/lib/esm/services/hubtype-api-client.js +0 -206
- package/lib/esm/services/hubtype-api-client.js.map +0 -1
- package/lib/esm/services/types.d.ts +0 -85
- package/lib/esm/services/types.js +0 -13
- package/lib/esm/services/types.js.map +0 -1
- package/lib/esm/structured-output/bot-executor.js +0 -18
- package/lib/esm/structured-output/bot-executor.js.map +0 -1
- package/lib/esm/structured-output/carousel.js +0 -22
- package/lib/esm/structured-output/carousel.js.map +0 -1
- package/lib/esm/structured-output/exit.d.ts +0 -10
- package/lib/esm/structured-output/exit.js +0 -11
- package/lib/esm/structured-output/exit.js.map +0 -1
- package/lib/esm/structured-output/index.d.ts +0 -603
- package/lib/esm/structured-output/index.js +0 -28
- package/lib/esm/structured-output/index.js.map +0 -1
- package/lib/esm/structured-output/text-with-buttons.d.ts +0 -56
- package/lib/esm/structured-output/text-with-buttons.js +0 -24
- package/lib/esm/structured-output/text-with-buttons.js.map +0 -1
- package/lib/esm/structured-output/text.js +0 -13
- package/lib/esm/structured-output/text.js.map +0 -1
- package/lib/esm/tools/index.js +0 -7
- package/lib/esm/tools/index.js.map +0 -1
- package/lib/esm/tools/retrieve-knowledge.d.ts +0 -9
- package/lib/esm/tools/retrieve-knowledge.js +0 -32
- package/lib/esm/tools/retrieve-knowledge.js.map +0 -1
- package/lib/esm/types.js +0 -3
- package/lib/esm/types.js.map +0 -1
- package/src/agent-builder.ts +0 -183
- package/src/bot-config-tools.ts +0 -21
- package/src/constants.ts +0 -21
- package/src/debug-logger.ts +0 -166
- package/src/guardrails/index.ts +0 -1
- package/src/guardrails/input.ts +0 -122
- package/src/index.ts +0 -210
- package/src/llm-config.ts +0 -96
- package/src/runner.ts +0 -287
- package/src/services/hubtype-api-client.ts +0 -240
- package/src/services/types.ts +0 -106
- package/src/structured-output/bot-executor.ts +0 -21
- package/src/structured-output/carousel.ts +0 -24
- package/src/structured-output/exit.ts +0 -12
- package/src/structured-output/index.ts +0 -34
- package/src/structured-output/text-with-buttons.ts +0 -29
- package/src/structured-output/text.ts +0 -13
- package/src/tools/index.ts +0 -5
- package/src/tools/retrieve-knowledge.ts +0 -37
- package/src/types.ts +0 -110
- /package/{lib/cjs → src/lib}/guardrails/index.d.ts +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { InputGuardrailTripwireTriggered, Runner, RunToolCallItem, } from '@openai/agents';
|
|
3
|
+
import { retrieveKnowledge } from './tools';
|
|
4
|
+
export class AIAgentRunner {
|
|
5
|
+
constructor(agent, logger) {
|
|
6
|
+
this.agent = agent;
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
}
|
|
9
|
+
run(messages, context) {
|
|
10
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
var _a;
|
|
12
|
+
const startTime = Date.now();
|
|
13
|
+
this.logger.logRunnerStart();
|
|
14
|
+
try {
|
|
15
|
+
const runner = new Runner({
|
|
16
|
+
modelSettings: { temperature: 0 },
|
|
17
|
+
});
|
|
18
|
+
// Type assertion to bypass strict type checking - the actual return type from runner.run()
|
|
19
|
+
// doesn't perfectly match our interface, but the properties we access are compatible
|
|
20
|
+
const result = (yield runner.run(this.agent, messages, {
|
|
21
|
+
context,
|
|
22
|
+
}));
|
|
23
|
+
const outputMessages = ((_a = result.finalOutput) === null || _a === void 0 ? void 0 : _a.messages) || [];
|
|
24
|
+
const hasExit = outputMessages.length === 0 ||
|
|
25
|
+
outputMessages.some(message => message.type === 'exit');
|
|
26
|
+
const toolsExecuted = this.getToolsExecuted(result, context);
|
|
27
|
+
const runResult = {
|
|
28
|
+
messages: hasExit
|
|
29
|
+
? []
|
|
30
|
+
: outputMessages.filter(message => message.type !== 'exit'),
|
|
31
|
+
toolsExecuted,
|
|
32
|
+
exit: hasExit,
|
|
33
|
+
memoryLength: messages.length,
|
|
34
|
+
error: false,
|
|
35
|
+
inputGuardrailsTriggered: [],
|
|
36
|
+
outputGuardrailsTriggered: [],
|
|
37
|
+
};
|
|
38
|
+
this.logger.logRunResult(runResult, startTime);
|
|
39
|
+
return runResult;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof InputGuardrailTripwireTriggered) {
|
|
43
|
+
const runResult = {
|
|
44
|
+
messages: [],
|
|
45
|
+
memoryLength: 0,
|
|
46
|
+
toolsExecuted: [],
|
|
47
|
+
exit: true,
|
|
48
|
+
error: false,
|
|
49
|
+
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
50
|
+
outputGuardrailsTriggered: [],
|
|
51
|
+
};
|
|
52
|
+
this.logger.logGuardrailTriggered();
|
|
53
|
+
this.logger.logRunResult(runResult, startTime);
|
|
54
|
+
return runResult;
|
|
55
|
+
}
|
|
56
|
+
this.logger.logRunnerError(startTime, error);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
getToolsExecuted(result, context) {
|
|
62
|
+
var _a;
|
|
63
|
+
return (((_a = result.newItems) === null || _a === void 0 ? void 0 : _a.filter((item) => item instanceof RunToolCallItem).map((item) => this.getToolExecutionInfo(item, context)).filter((toolExecution) => toolExecution.toolName !== '')) || []);
|
|
64
|
+
}
|
|
65
|
+
getToolExecutionInfo(item, context) {
|
|
66
|
+
if (item.rawItem.type !== 'function_call') {
|
|
67
|
+
return {
|
|
68
|
+
toolName: '',
|
|
69
|
+
toolArguments: {},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const toolName = item.rawItem.name;
|
|
73
|
+
const toolArguments = this.getSafeToolArguments(item.rawItem.arguments);
|
|
74
|
+
if (toolName === retrieveKnowledge.name) {
|
|
75
|
+
return {
|
|
76
|
+
toolName,
|
|
77
|
+
toolArguments,
|
|
78
|
+
knowledgebaseSourcesIds: context.knowledgeUsed.sourceIds,
|
|
79
|
+
knowledgebaseChunksIds: context.knowledgeUsed.chunksIds,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
toolName,
|
|
84
|
+
toolArguments,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
getSafeToolArguments(rawToolArguments) {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(rawToolArguments);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../../../libs/botonic/plugin-ai-agents/src/lib/runner.ts"],"names":[],"mappings":";AAMA,OAAO,EACL,+BAA+B,EAE/B,MAAM,EACN,eAAe,GAChB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAkB3C,MAAM,OAAO,aAAa;IAOxB,YAAY,KAAoC,EAAE,MAAmB;QACnE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEK,GAAG,CACP,QAA+B,EAC/B,OAA6C;;;YAE7C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YAE5B,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAA;YAC5B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,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BACL,QAAQ;gBACR,aAAa;gBACb,uBAAuB,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;gBACxD,sBAAsB,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;aACxD,CAAA;QACH,CAAC;QAED,OAAO;YACL,QAAQ;YACR,aAAa;SACd,CAAA;IACH,CAAC;IAEO,oBAAoB,CAAC,gBAAwB;QACnD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const CarouselSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
type: z.enum(['carousel']),
|
|
5
|
+
content: z.object({
|
|
6
|
+
text: z.string().nullable().optional(),
|
|
7
|
+
elements: z.array(z.object({
|
|
8
|
+
title: z.string(),
|
|
9
|
+
subtitle: z.string(),
|
|
10
|
+
image: z.string(),
|
|
11
|
+
button: z.object({
|
|
12
|
+
text: z.string(),
|
|
13
|
+
url: z.string().nullable().optional(),
|
|
14
|
+
}),
|
|
15
|
+
})),
|
|
16
|
+
}),
|
|
17
|
+
})
|
|
18
|
+
.describe('A carousel message containing a list of elements');
|
|
19
|
+
//# sourceMappingURL=carousel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carousel.js","sourceRoot":"","sources":["../../../../../../../libs/botonic/plugin-ai-agents/src/lib/structured-output/carousel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;QACtC,QAAQ,EAAE,CAAC,CAAC,KAAK,CACf,CAAC,CAAC,MAAM,CAAC;YACP,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;YACjB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;YACpB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;YACjB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;gBACf,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;gBAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;aACtC,CAAC;SACH,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,kDAAkD,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export const ExitSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
type: z.enum(['exit']),
|
|
5
|
+
})
|
|
6
|
+
.describe('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');
|
|
7
|
+
//# sourceMappingURL=exit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit.js","sourceRoot":"","sources":["../../../../../../../libs/botonic/plugin-ai-agents/src/lib/structured-output/exit.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,KAAK,CAAA;AAInB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC;KACD,QAAQ,CACP,uIAAuI,CACxI,CAAA"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { OutputMessage } from '@botonic/shared';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export interface Output {
|
|
4
|
+
messages: OutputMessage[];
|
|
5
|
+
}
|
|
6
|
+
export declare const OutputSchema: z.ZodObject<{
|
|
7
|
+
messages: z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
8
|
+
type: z.ZodEnum<["text"]>;
|
|
9
|
+
content: z.ZodObject<{
|
|
10
|
+
text: z.ZodString;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
text: string;
|
|
13
|
+
}, {
|
|
14
|
+
text: string;
|
|
15
|
+
}>;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
type: "text";
|
|
18
|
+
content: {
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
}, {
|
|
22
|
+
type: "text";
|
|
23
|
+
content: {
|
|
24
|
+
text: string;
|
|
25
|
+
};
|
|
26
|
+
}>, z.ZodObject<{
|
|
27
|
+
type: z.ZodEnum<["textWithButtons"]>;
|
|
28
|
+
content: z.ZodObject<{
|
|
29
|
+
text: z.ZodString;
|
|
30
|
+
buttons: z.ZodArray<z.ZodObject<{
|
|
31
|
+
text: z.ZodString;
|
|
32
|
+
url: z.ZodOptional<z.ZodString>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
text: string;
|
|
35
|
+
url?: string | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
text: string;
|
|
38
|
+
url?: string | undefined;
|
|
39
|
+
}>, "many">;
|
|
40
|
+
}, "strip", z.ZodTypeAny, {
|
|
41
|
+
text: string;
|
|
42
|
+
buttons: {
|
|
43
|
+
text: string;
|
|
44
|
+
url?: string | undefined;
|
|
45
|
+
}[];
|
|
46
|
+
}, {
|
|
47
|
+
text: string;
|
|
48
|
+
buttons: {
|
|
49
|
+
text: string;
|
|
50
|
+
url?: string | undefined;
|
|
51
|
+
}[];
|
|
52
|
+
}>;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
type: "textWithButtons";
|
|
55
|
+
content: {
|
|
56
|
+
text: string;
|
|
57
|
+
buttons: {
|
|
58
|
+
text: string;
|
|
59
|
+
url?: string | undefined;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
}, {
|
|
63
|
+
type: "textWithButtons";
|
|
64
|
+
content: {
|
|
65
|
+
text: string;
|
|
66
|
+
buttons: {
|
|
67
|
+
text: string;
|
|
68
|
+
url?: string | undefined;
|
|
69
|
+
}[];
|
|
70
|
+
};
|
|
71
|
+
}>, z.ZodObject<{
|
|
72
|
+
type: z.ZodEnum<["carousel"]>;
|
|
73
|
+
content: z.ZodObject<{
|
|
74
|
+
text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
75
|
+
elements: z.ZodArray<z.ZodObject<{
|
|
76
|
+
title: z.ZodString;
|
|
77
|
+
subtitle: z.ZodString;
|
|
78
|
+
image: z.ZodString;
|
|
79
|
+
button: z.ZodObject<{
|
|
80
|
+
text: z.ZodString;
|
|
81
|
+
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
text: string;
|
|
84
|
+
url?: string | null | undefined;
|
|
85
|
+
}, {
|
|
86
|
+
text: string;
|
|
87
|
+
url?: string | null | undefined;
|
|
88
|
+
}>;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
title: string;
|
|
91
|
+
subtitle: string;
|
|
92
|
+
image: string;
|
|
93
|
+
button: {
|
|
94
|
+
text: string;
|
|
95
|
+
url?: string | null | undefined;
|
|
96
|
+
};
|
|
97
|
+
}, {
|
|
98
|
+
title: string;
|
|
99
|
+
subtitle: string;
|
|
100
|
+
image: string;
|
|
101
|
+
button: {
|
|
102
|
+
text: string;
|
|
103
|
+
url?: string | null | undefined;
|
|
104
|
+
};
|
|
105
|
+
}>, "many">;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
elements: {
|
|
108
|
+
title: string;
|
|
109
|
+
subtitle: string;
|
|
110
|
+
image: string;
|
|
111
|
+
button: {
|
|
112
|
+
text: string;
|
|
113
|
+
url?: string | null | undefined;
|
|
114
|
+
};
|
|
115
|
+
}[];
|
|
116
|
+
text?: string | null | undefined;
|
|
117
|
+
}, {
|
|
118
|
+
elements: {
|
|
119
|
+
title: string;
|
|
120
|
+
subtitle: string;
|
|
121
|
+
image: string;
|
|
122
|
+
button: {
|
|
123
|
+
text: string;
|
|
124
|
+
url?: string | null | undefined;
|
|
125
|
+
};
|
|
126
|
+
}[];
|
|
127
|
+
text?: string | null | undefined;
|
|
128
|
+
}>;
|
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
|
130
|
+
type: "carousel";
|
|
131
|
+
content: {
|
|
132
|
+
elements: {
|
|
133
|
+
title: string;
|
|
134
|
+
subtitle: string;
|
|
135
|
+
image: string;
|
|
136
|
+
button: {
|
|
137
|
+
text: string;
|
|
138
|
+
url?: string | null | undefined;
|
|
139
|
+
};
|
|
140
|
+
}[];
|
|
141
|
+
text?: string | null | undefined;
|
|
142
|
+
};
|
|
143
|
+
}, {
|
|
144
|
+
type: "carousel";
|
|
145
|
+
content: {
|
|
146
|
+
elements: {
|
|
147
|
+
title: string;
|
|
148
|
+
subtitle: string;
|
|
149
|
+
image: string;
|
|
150
|
+
button: {
|
|
151
|
+
text: string;
|
|
152
|
+
url?: string | null | undefined;
|
|
153
|
+
};
|
|
154
|
+
}[];
|
|
155
|
+
text?: string | null | undefined;
|
|
156
|
+
};
|
|
157
|
+
}>, z.ZodObject<{
|
|
158
|
+
type: z.ZodEnum<["exit"]>;
|
|
159
|
+
}, "strip", z.ZodTypeAny, {
|
|
160
|
+
type: "exit";
|
|
161
|
+
}, {
|
|
162
|
+
type: "exit";
|
|
163
|
+
}>]>, "many">;
|
|
164
|
+
}, "strip", z.ZodTypeAny, {
|
|
165
|
+
messages: ({
|
|
166
|
+
type: "carousel";
|
|
167
|
+
content: {
|
|
168
|
+
elements: {
|
|
169
|
+
title: string;
|
|
170
|
+
subtitle: string;
|
|
171
|
+
image: string;
|
|
172
|
+
button: {
|
|
173
|
+
text: string;
|
|
174
|
+
url?: string | null | undefined;
|
|
175
|
+
};
|
|
176
|
+
}[];
|
|
177
|
+
text?: string | null | undefined;
|
|
178
|
+
};
|
|
179
|
+
} | {
|
|
180
|
+
type: "exit";
|
|
181
|
+
} | {
|
|
182
|
+
type: "text";
|
|
183
|
+
content: {
|
|
184
|
+
text: string;
|
|
185
|
+
};
|
|
186
|
+
} | {
|
|
187
|
+
type: "textWithButtons";
|
|
188
|
+
content: {
|
|
189
|
+
text: string;
|
|
190
|
+
buttons: {
|
|
191
|
+
text: string;
|
|
192
|
+
url?: string | undefined;
|
|
193
|
+
}[];
|
|
194
|
+
};
|
|
195
|
+
})[];
|
|
196
|
+
}, {
|
|
197
|
+
messages: ({
|
|
198
|
+
type: "carousel";
|
|
199
|
+
content: {
|
|
200
|
+
elements: {
|
|
201
|
+
title: string;
|
|
202
|
+
subtitle: string;
|
|
203
|
+
image: string;
|
|
204
|
+
button: {
|
|
205
|
+
text: string;
|
|
206
|
+
url?: string | null | undefined;
|
|
207
|
+
};
|
|
208
|
+
}[];
|
|
209
|
+
text?: string | null | undefined;
|
|
210
|
+
};
|
|
211
|
+
} | {
|
|
212
|
+
type: "exit";
|
|
213
|
+
} | {
|
|
214
|
+
type: "text";
|
|
215
|
+
content: {
|
|
216
|
+
text: string;
|
|
217
|
+
};
|
|
218
|
+
} | {
|
|
219
|
+
type: "textWithButtons";
|
|
220
|
+
content: {
|
|
221
|
+
text: string;
|
|
222
|
+
buttons: {
|
|
223
|
+
text: string;
|
|
224
|
+
url?: string | undefined;
|
|
225
|
+
}[];
|
|
226
|
+
};
|
|
227
|
+
})[];
|
|
228
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CarouselSchema } from './carousel';
|
|
3
|
+
import { ExitSchema } from './exit';
|
|
4
|
+
import { TextSchema } from './text';
|
|
5
|
+
import { TextWithButtonsSchema } from './text-with-buttons';
|
|
6
|
+
export const OutputSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
messages: z.array(z.union([TextSchema, TextWithButtonsSchema, CarouselSchema, ExitSchema])),
|
|
9
|
+
})
|
|
10
|
+
.describe('The messages to be sent to the user');
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/botonic/plugin-ai-agents/src/lib/structured-output/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAM3D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC,CAAC,KAAK,CACf,CAAC,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,qBAAqB,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC,CACzE;CACF,CAAC;KACD,QAAQ,CAAC,qCAAqC,CAAC,CAAA"}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TextWithButtonsMessage } from '@botonic/shared';
|
|
2
2
|
import z from 'zod';
|
|
3
|
-
export type {
|
|
4
|
-
export declare const
|
|
5
|
-
type: z.ZodEnum<["
|
|
3
|
+
export type { TextWithButtonsMessage };
|
|
4
|
+
export declare const TextWithButtonsSchema: z.ZodObject<{
|
|
5
|
+
type: z.ZodEnum<["textWithButtons"]>;
|
|
6
6
|
content: z.ZodObject<{
|
|
7
7
|
text: z.ZodString;
|
|
8
8
|
buttons: z.ZodArray<z.ZodObject<{
|
|
9
9
|
text: z.ZodString;
|
|
10
|
-
|
|
10
|
+
url: z.ZodOptional<z.ZodString>;
|
|
11
11
|
}, "strip", z.ZodTypeAny, {
|
|
12
12
|
text: string;
|
|
13
|
-
|
|
13
|
+
url?: string | undefined;
|
|
14
14
|
}, {
|
|
15
15
|
text: string;
|
|
16
|
-
|
|
16
|
+
url?: string | undefined;
|
|
17
17
|
}>, "many">;
|
|
18
18
|
}, "strip", z.ZodTypeAny, {
|
|
19
19
|
text: string;
|
|
20
20
|
buttons: {
|
|
21
21
|
text: string;
|
|
22
|
-
|
|
22
|
+
url?: string | undefined;
|
|
23
23
|
}[];
|
|
24
24
|
}, {
|
|
25
25
|
text: string;
|
|
26
26
|
buttons: {
|
|
27
27
|
text: string;
|
|
28
|
-
|
|
28
|
+
url?: string | undefined;
|
|
29
29
|
}[];
|
|
30
30
|
}>;
|
|
31
31
|
}, "strip", z.ZodTypeAny, {
|
|
32
|
-
type: "
|
|
32
|
+
type: "textWithButtons";
|
|
33
33
|
content: {
|
|
34
34
|
text: string;
|
|
35
35
|
buttons: {
|
|
36
36
|
text: string;
|
|
37
|
-
|
|
37
|
+
url?: string | undefined;
|
|
38
38
|
}[];
|
|
39
39
|
};
|
|
40
40
|
}, {
|
|
41
|
-
type: "
|
|
41
|
+
type: "textWithButtons";
|
|
42
42
|
content: {
|
|
43
43
|
text: string;
|
|
44
44
|
buttons: {
|
|
45
45
|
text: string;
|
|
46
|
-
|
|
46
|
+
url?: string | undefined;
|
|
47
47
|
}[];
|
|
48
48
|
};
|
|
49
49
|
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export const TextWithButtonsSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
type: z.enum(['textWithButtons']),
|
|
5
|
+
content: z.object({
|
|
6
|
+
text: z.string(),
|
|
7
|
+
buttons: z.array(z.object({
|
|
8
|
+
text: z.string(),
|
|
9
|
+
url: z.string().optional(),
|
|
10
|
+
})),
|
|
11
|
+
}),
|
|
12
|
+
})
|
|
13
|
+
.describe('A text message with buttons to allow the user to use quick replies');
|
|
14
|
+
//# sourceMappingURL=text-with-buttons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-with-buttons.js","sourceRoot":"","sources":["../../../../../../../libs/botonic/plugin-ai-agents/src/lib/structured-output/text-with-buttons.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,KAAK,CAAA;AAInB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC;KACnC,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACjC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,CAAC,CAAC,KAAK,CACd,CAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SAC3B,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CACP,oEAAoE,CACrE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../../../../libs/botonic/plugin-ai-agents/src/lib/structured-output/text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;KACjB,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,gBAAgB,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/botonic/plugin-ai-agents/src/lib/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAExD,MAAM,CAAC,MAAM,cAAc,GAAW,EAAE,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import
|
|
3
|
-
export declare const retrieveKnowledge: import("@openai/agents").FunctionTool<
|
|
2
|
+
import { AiAgentContext } from '../types';
|
|
3
|
+
export declare const retrieveKnowledge: import("@openai/agents").FunctionTool<AiAgentContext<import("dist/libs/botonic/shared/src").ResolvedPlugins, import("dist/libs/botonic/shared/src").UserExtraData>, z.ZodObject<{
|
|
4
4
|
query: z.ZodString;
|
|
5
5
|
}, "strip", z.ZodTypeAny, {
|
|
6
6
|
query: string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { tool } from '@openai/agents';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { HubtypeApiClient } from '../hubtype-api-client';
|
|
5
|
+
export const retrieveKnowledge = tool({
|
|
6
|
+
name: 'retrieve_knowledge',
|
|
7
|
+
description: 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
|
|
8
|
+
parameters: z.object({
|
|
9
|
+
query: z.string().describe('The query to search the knowledge base for'),
|
|
10
|
+
}),
|
|
11
|
+
execute: (input, runContext) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const context = runContext === null || runContext === void 0 ? void 0 : runContext.context;
|
|
13
|
+
const query = input.query;
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error('Context is required');
|
|
16
|
+
}
|
|
17
|
+
const sourceIds = context.sourceIds;
|
|
18
|
+
const client = new HubtypeApiClient(context.authToken);
|
|
19
|
+
const chunks = yield client.retrieveSimilarChunks(query, sourceIds);
|
|
20
|
+
const chunkTexts = chunks.map(chunk => chunk.text);
|
|
21
|
+
context.knowledgeUsed = {
|
|
22
|
+
query,
|
|
23
|
+
sourceIds,
|
|
24
|
+
chunksIds: chunks.map(chunk => chunk.id),
|
|
25
|
+
chunkTexts,
|
|
26
|
+
};
|
|
27
|
+
return chunkTexts;
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=retrieve-knowledge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../../../../../libs/botonic/plugin-ai-agents/src/lib/tools/retrieve-knowledge.ts"],"names":[],"mappings":";AAAA,OAAO,EAAc,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;IACpC,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EACT,kIAAkI;IACpI,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC;QACnB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;KACzE,CAAC;IACF,OAAO,EAAE,CACP,KAAwB,EACxB,UAAuC,EACpB,EAAE;QACrB,MAAM,OAAO,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAA;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QACxC,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QACnC,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACtD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QACnE,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAElD,OAAO,CAAC,aAAa,GAAG;YACtB,KAAK;YACL,SAAS;YACT,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YACxC,UAAU;SACX,CAAA;QAED,OAAO,UAAU,CAAA;IACnB,CAAC,CAAA;CACF,CAAC,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AgenticOutputMessage, AiAgentArgs,
|
|
1
|
+
import type { AgenticOutputMessage, AiAgentArgs, BotContext, GuardrailRule, InferenceResponse, ResolvedPlugins, RunResult, UserExtraData } from '@botonic/shared';
|
|
2
2
|
import type { Agent, AgentInputItem, AgentOutputType, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
|
|
3
3
|
import type { ZodSchema } from 'zod';
|
|
4
4
|
import type { OutputSchema } from './structured-output';
|
|
5
|
-
export interface
|
|
5
|
+
export interface AiAgentContext<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData extends UserExtraData = UserExtraData> {
|
|
6
6
|
authToken: string;
|
|
7
7
|
sourceIds: string[];
|
|
8
8
|
knowledgeUsed: {
|
|
@@ -11,10 +11,10 @@ export interface Context<TPlugins extends ResolvedPlugins = ResolvedPlugins, TEx
|
|
|
11
11
|
chunksIds: string[];
|
|
12
12
|
chunkTexts: string[];
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
botonicContext: BotContext<TPlugins, TExtraData>;
|
|
15
15
|
}
|
|
16
|
-
export type RunContext<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData =
|
|
17
|
-
export interface CustomTool<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData =
|
|
16
|
+
export type RunContext<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData extends UserExtraData = UserExtraData> = OpenAIRunContext<AiAgentContext<TPlugins, TExtraData>>;
|
|
17
|
+
export interface CustomTool<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData extends UserExtraData = UserExtraData> {
|
|
18
18
|
name: string;
|
|
19
19
|
description: string;
|
|
20
20
|
schema: ZodSchema;
|
|
@@ -24,8 +24,9 @@ export interface Chunk {
|
|
|
24
24
|
id: string;
|
|
25
25
|
text: string;
|
|
26
26
|
}
|
|
27
|
-
export type
|
|
28
|
-
export type
|
|
27
|
+
export type ContactInfo = Record<string, string>;
|
|
28
|
+
export type Tool<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData extends UserExtraData = UserExtraData> = OpenAITool<AiAgentContext<TPlugins, TExtraData>>;
|
|
29
|
+
export type AIAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData extends UserExtraData = UserExtraData> = Agent<AiAgentContext<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>;
|
|
29
30
|
export type MessageHistoryApiVersion = 'v1' | 'v2';
|
|
30
31
|
export interface MemoryOptions {
|
|
31
32
|
maxMessages?: number;
|
|
@@ -33,24 +34,13 @@ export interface MemoryOptions {
|
|
|
33
34
|
maxFullToolResults?: number;
|
|
34
35
|
debugMode?: boolean;
|
|
35
36
|
}
|
|
36
|
-
export interface PluginAiAgentOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData =
|
|
37
|
-
authToken?: string;
|
|
37
|
+
export interface PluginAiAgentOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData extends UserExtraData = UserExtraData> {
|
|
38
38
|
customTools?: CustomTool<TPlugins, TExtraData>[];
|
|
39
|
-
maxRetries?: number;
|
|
40
39
|
timeout?: number;
|
|
41
|
-
|
|
40
|
+
maxRetries?: number;
|
|
42
41
|
messageHistoryApiVersion?: MessageHistoryApiVersion;
|
|
43
|
-
/** Options for V2 message history API. Only used when messageHistoryApiVersion is 'v2'. */
|
|
44
42
|
memory?: MemoryOptions;
|
|
45
|
-
/** Enable debug logging for AI agent configuration and execution details. */
|
|
46
43
|
enableDebug?: boolean;
|
|
47
44
|
}
|
|
48
|
-
export interface ResultRawResponse {
|
|
49
|
-
usage: {
|
|
50
|
-
inputTokens: number;
|
|
51
|
-
outputTokens: number;
|
|
52
|
-
};
|
|
53
|
-
providerData?: Record<string, unknown>;
|
|
54
|
-
}
|
|
55
45
|
export type AgenticInputMessage = AgentInputItem;
|
|
56
|
-
export { AgenticOutputMessage, AiAgentArgs, GuardrailRule, InferenceResponse, RunResult, };
|
|
46
|
+
export type { AgenticOutputMessage, AiAgentArgs, GuardrailRule, InferenceResponse, RunResult, };
|
package/src/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../libs/botonic/plugin-ai-agents/src/lib/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAIuB;AAGvB,2CAA6C;AAE7C,6CAAmD;AAGnD,2DAAwE;AACxE,mCAA2D;AAoB3D,MAAa,cAAc;IAYzB,YAAY,OAAoD;QAC9D,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAC3C,OAAO,CAAC,YAAY,EACpB,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,gBAAgB,CACzB,CAAA;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;QACnE,IAAI,CAAC,6BAA6B,GAAG,OAAO,CAAC,qBAAqB,IAAI,EAAE,CAAA;QACxE,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,MAAM,GAAG,O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