@botonic/plugin-ai-agents 0.57.0-rslib-esm.1 → 0.57.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/{agents → cjs/agents}/base-agent.d.ts +4 -4
- package/lib/cjs/agents/base-agent.js +39 -0
- package/lib/cjs/agents/base-agent.js.map +1 -0
- package/lib/cjs/agents/index.d.ts +2 -0
- package/lib/cjs/agents/index.js +8 -0
- package/lib/cjs/agents/index.js.map +1 -0
- package/lib/{agents → cjs/agents}/router-agent.d.ts +5 -5
- package/lib/cjs/agents/router-agent.js +33 -0
- package/lib/cjs/agents/router-agent.js.map +1 -0
- package/lib/{agents → cjs/agents}/specialist-agent.d.ts +5 -5
- package/lib/{agents → cjs/agents}/specialist-agent.js +45 -65
- package/lib/cjs/agents/specialist-agent.js.map +1 -0
- package/lib/{bot-config-tools.d.ts → cjs/bot-config-tools.d.ts} +1 -1
- package/lib/cjs/bot-config-tools.js +18 -0
- package/lib/cjs/bot-config-tools.js.map +1 -0
- package/lib/cjs/constants.js +25 -0
- package/lib/cjs/constants.js.map +1 -0
- package/lib/{debug-logger.d.ts → cjs/debug-logger.d.ts} +1 -1
- package/lib/{debug-logger.js → cjs/debug-logger.js} +9 -14
- package/lib/cjs/debug-logger.js.map +1 -0
- 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/{guardrails → cjs/guardrails}/input.d.ts +2 -2
- package/lib/cjs/guardrails/input.js +96 -0
- package/lib/cjs/guardrails/input.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +3 -3
- package/lib/{index.js → cjs/index.js} +75 -114
- package/lib/cjs/index.js.map +1 -0
- package/lib/{llm-config.d.ts → cjs/llm-config.d.ts} +1 -1
- package/lib/cjs/llm-config.js +121 -0
- package/lib/cjs/llm-config.js.map +1 -0
- package/lib/{runners → cjs/runners}/base-runner.d.ts +4 -4
- package/lib/{runners → cjs/runners}/base-runner.js +74 -81
- package/lib/cjs/runners/base-runner.js.map +1 -0
- package/lib/cjs/runners/index.d.ts +2 -0
- package/lib/cjs/runners/index.js +8 -0
- package/lib/cjs/runners/index.js.map +1 -0
- package/lib/{runners → cjs/runners}/router-runner.d.ts +2 -2
- package/lib/{runners → cjs/runners}/router-runner.js +14 -19
- package/lib/cjs/runners/router-runner.js.map +1 -0
- package/lib/{runners → cjs/runners}/specialist-runner.d.ts +1 -1
- package/lib/cjs/runners/specialist-runner.js +8 -0
- package/lib/cjs/runners/specialist-runner.js.map +1 -0
- package/lib/{services → cjs/services}/hubtype-api-client.d.ts +2 -2
- package/lib/cjs/services/hubtype-api-client.js +176 -0
- package/lib/cjs/services/hubtype-api-client.js.map +1 -0
- package/lib/{services → cjs/services}/types.d.ts +1 -1
- package/lib/cjs/services/types.js +13 -0
- package/lib/cjs/services/types.js.map +1 -0
- package/lib/cjs/structured-output/bot-executor.js +18 -0
- package/lib/cjs/structured-output/bot-executor.js.map +1 -0
- package/lib/cjs/structured-output/carousel.js +23 -0
- package/lib/cjs/structured-output/carousel.js.map +1 -0
- package/lib/cjs/structured-output/do-nothing.d.ts +6 -0
- package/lib/cjs/structured-output/do-nothing.js +11 -0
- package/lib/cjs/structured-output/do-nothing.js.map +1 -0
- package/lib/cjs/structured-output/exit.js +11 -0
- package/lib/cjs/structured-output/exit.js.map +1 -0
- package/lib/{structured-output → cjs/structured-output}/index.d.ts +14 -0
- package/lib/cjs/structured-output/index.js +47 -0
- package/lib/cjs/structured-output/index.js.map +1 -0
- package/lib/cjs/structured-output/request-contact-info.d.ts +9 -0
- package/lib/cjs/structured-output/request-contact-info.js +14 -0
- package/lib/cjs/structured-output/request-contact-info.js.map +1 -0
- package/lib/cjs/structured-output/text-with-buttons.js +24 -0
- package/lib/cjs/structured-output/text-with-buttons.js.map +1 -0
- package/lib/cjs/structured-output/text.js +14 -0
- package/lib/cjs/structured-output/text.js.map +1 -0
- package/lib/{tools → cjs/tools}/index.d.ts +2 -2
- package/lib/cjs/tools/index.js +8 -0
- package/lib/cjs/tools/index.js.map +1 -0
- package/lib/{tools → cjs/tools}/retrieve-knowledge.d.ts +2 -2
- package/lib/cjs/tools/retrieve-knowledge.js +34 -0
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -0
- package/lib/{types.d.ts → cjs/types.d.ts} +1 -1
- package/lib/cjs/types.js +3 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/esm/agents/base-agent.d.ts +28 -0
- package/lib/esm/agents/base-agent.js +39 -0
- package/lib/esm/agents/base-agent.js.map +1 -0
- package/lib/esm/agents/index.d.ts +2 -0
- package/lib/esm/agents/index.js +8 -0
- package/lib/esm/agents/index.js.map +1 -0
- package/lib/esm/agents/router-agent.d.ts +25 -0
- package/lib/esm/agents/router-agent.js +33 -0
- package/lib/esm/agents/router-agent.js.map +1 -0
- package/lib/esm/agents/specialist-agent.d.ts +39 -0
- package/lib/esm/agents/specialist-agent.js +108 -0
- package/lib/esm/agents/specialist-agent.js.map +1 -0
- package/lib/esm/bot-config-tools.d.ts +7 -0
- package/lib/esm/bot-config-tools.js +18 -0
- package/lib/esm/bot-config-tools.js.map +1 -0
- package/lib/esm/constants.d.ts +21 -0
- package/lib/esm/constants.js +25 -0
- package/lib/esm/constants.js.map +1 -0
- package/lib/esm/debug-logger.d.ts +33 -0
- package/lib/esm/debug-logger.js +116 -0
- package/lib/esm/debug-logger.js.map +1 -0
- package/lib/esm/guardrails/index.d.ts +1 -0
- package/lib/esm/guardrails/index.js +5 -0
- package/lib/esm/guardrails/index.js.map +1 -0
- package/lib/esm/guardrails/input.d.ts +10 -0
- package/lib/esm/guardrails/input.js +96 -0
- package/lib/esm/guardrails/input.js.map +1 -0
- package/lib/esm/index.d.ts +22 -0
- package/lib/esm/index.js +220 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/llm-config.d.ts +30 -0
- package/lib/esm/llm-config.js +121 -0
- package/lib/esm/llm-config.js.map +1 -0
- package/lib/esm/runners/base-runner.d.ts +31 -0
- package/lib/esm/runners/base-runner.js +194 -0
- package/lib/esm/runners/base-runner.js.map +1 -0
- package/lib/esm/runners/index.d.ts +2 -0
- package/lib/esm/runners/index.js +8 -0
- package/lib/esm/runners/index.js.map +1 -0
- package/lib/esm/runners/router-runner.d.ts +8 -0
- package/lib/esm/runners/router-runner.js +44 -0
- package/lib/esm/runners/router-runner.js.map +1 -0
- package/lib/esm/runners/specialist-runner.d.ts +4 -0
- package/lib/esm/runners/specialist-runner.js +8 -0
- package/lib/esm/runners/specialist-runner.js.map +1 -0
- package/lib/esm/services/hubtype-api-client.d.ts +13 -0
- package/lib/esm/services/hubtype-api-client.js +176 -0
- package/lib/esm/services/hubtype-api-client.js.map +1 -0
- package/lib/esm/services/types.d.ts +72 -0
- package/lib/esm/services/types.js +13 -0
- package/lib/esm/services/types.js.map +1 -0
- package/lib/esm/structured-output/bot-executor.d.ts +13 -0
- package/lib/esm/structured-output/bot-executor.js +18 -0
- package/lib/esm/structured-output/bot-executor.js.map +1 -0
- package/lib/esm/structured-output/carousel.d.ts +18 -0
- package/lib/esm/structured-output/carousel.js +23 -0
- package/lib/esm/structured-output/carousel.js.map +1 -0
- package/lib/esm/structured-output/do-nothing.d.ts +6 -0
- package/lib/esm/structured-output/do-nothing.js +11 -0
- package/lib/esm/structured-output/do-nothing.js.map +1 -0
- package/lib/esm/structured-output/exit.d.ts +6 -0
- package/lib/esm/structured-output/exit.js +11 -0
- package/lib/esm/structured-output/exit.js.map +1 -0
- package/lib/esm/structured-output/index.d.ts +112 -0
- package/lib/esm/structured-output/index.js +47 -0
- package/lib/esm/structured-output/index.js.map +1 -0
- package/lib/esm/structured-output/request-contact-info.d.ts +9 -0
- package/lib/esm/structured-output/request-contact-info.js +14 -0
- package/lib/esm/structured-output/request-contact-info.js.map +1 -0
- package/lib/esm/structured-output/text-with-buttons.d.ts +17 -0
- package/lib/esm/structured-output/text-with-buttons.js +24 -0
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -0
- package/lib/esm/structured-output/text.d.ts +9 -0
- package/lib/esm/structured-output/text.js +14 -0
- package/lib/esm/structured-output/text.js.map +1 -0
- package/lib/esm/tools/index.d.ts +3 -0
- package/lib/esm/tools/index.js +8 -0
- package/lib/esm/tools/index.js.map +1 -0
- package/lib/esm/tools/retrieve-knowledge.d.ts +6 -0
- package/lib/esm/tools/retrieve-knowledge.js +34 -0
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -0
- package/lib/esm/types.d.ts +53 -0
- package/lib/esm/types.js +3 -0
- package/lib/esm/types.js.map +1 -0
- package/package.json +9 -11
- package/src/index.ts +1 -0
- package/src/runners/base-runner.ts +20 -10
- package/src/structured-output/do-nothing.ts +12 -0
- package/src/structured-output/index.ts +4 -0
- package/src/structured-output/request-contact-info.ts +18 -0
- package/lib/agents/base-agent.js +0 -66
- package/lib/agents/base-agent.js.map +0 -1
- package/lib/agents/index.d.ts +0 -2
- package/lib/agents/index.js +0 -9
- package/lib/agents/index.js.map +0 -1
- package/lib/agents/router-agent.js +0 -50
- package/lib/agents/router-agent.js.map +0 -1
- package/lib/agents/specialist-agent.js.map +0 -1
- package/lib/bot-config-tools.js +0 -20
- package/lib/bot-config-tools.js.map +0 -1
- package/lib/constants.js +0 -26
- package/lib/constants.js.map +0 -1
- package/lib/debug-logger.js.map +0 -1
- package/lib/guardrails/index.d.ts +0 -1
- package/lib/guardrails/index.js +0 -6
- package/lib/guardrails/index.js.map +0 -1
- package/lib/guardrails/input.js +0 -119
- package/lib/guardrails/input.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/llm-config.js +0 -150
- package/lib/llm-config.js.map +0 -1
- package/lib/runners/base-runner.js.map +0 -1
- package/lib/runners/index.d.ts +0 -2
- package/lib/runners/index.js +0 -9
- package/lib/runners/index.js.map +0 -1
- package/lib/runners/router-runner.js.map +0 -1
- package/lib/runners/specialist-runner.js +0 -10
- package/lib/runners/specialist-runner.js.map +0 -1
- package/lib/services/hubtype-api-client.js +0 -191
- package/lib/services/hubtype-api-client.js.map +0 -1
- package/lib/services/types.js +0 -13
- package/lib/services/types.js.map +0 -1
- package/lib/structured-output/bot-executor.js +0 -21
- package/lib/structured-output/bot-executor.js.map +0 -1
- package/lib/structured-output/carousel.js +0 -26
- package/lib/structured-output/carousel.js.map +0 -1
- package/lib/structured-output/exit.js +0 -14
- package/lib/structured-output/exit.js.map +0 -1
- package/lib/structured-output/index.js +0 -55
- package/lib/structured-output/index.js.map +0 -1
- package/lib/structured-output/text-with-buttons.js +0 -25
- package/lib/structured-output/text-with-buttons.js.map +0 -1
- package/lib/structured-output/text.js +0 -17
- package/lib/structured-output/text.js.map +0 -1
- package/lib/tools/index.js +0 -8
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/retrieve-knowledge.js +0 -40
- package/lib/tools/retrieve-knowledge.js.map +0 -1
- package/lib/types.js +0 -5
- package/lib/types.js.map +0 -1
- /package/lib/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/lib/{structured-output → cjs/structured-output}/bot-executor.d.ts +0 -0
- /package/lib/{structured-output → cjs/structured-output}/carousel.d.ts +0 -0
- /package/lib/{structured-output → cjs/structured-output}/exit.d.ts +0 -0
- /package/lib/{structured-output → cjs/structured-output}/text-with-buttons.d.ts +0 -0
- /package/lib/{structured-output → cjs/structured-output}/text.d.ts +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OutputMessageType, type TextMessage } from '@botonic/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export type { TextMessage };
|
|
4
|
+
export declare const TextSchema: z.ZodObject<{
|
|
5
|
+
type: z.ZodLiteral<OutputMessageType.Text>;
|
|
6
|
+
content: z.ZodObject<{
|
|
7
|
+
text: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextSchema = void 0;
|
|
4
|
+
const core_1 = require("@botonic/core");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
exports.TextSchema = zod_1.z
|
|
7
|
+
.object({
|
|
8
|
+
type: zod_1.z.literal(core_1.OutputMessageType.Text),
|
|
9
|
+
content: zod_1.z.object({
|
|
10
|
+
text: zod_1.z.string(),
|
|
11
|
+
}),
|
|
12
|
+
})
|
|
13
|
+
.describe('A text message');
|
|
14
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/structured-output/text.ts"],"names":[],"mappings":";;;AAAA,wCAAmE;AACnE,6BAAuB;AAIV,QAAA,UAAU,GAAG,OAAC;KACxB,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,wBAAiB,CAAC,IAAI,CAAC;IACvC,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;KACjB,CAAC;CACH,CAAC;KACD,QAAQ,CAAC,gBAAgB,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mandatoryTools = exports.RETRIEVE_KNOWLEDGE_TOOL_NAME = exports.createRetrieveKnowledge = void 0;
|
|
4
|
+
var retrieve_knowledge_1 = require("./retrieve-knowledge");
|
|
5
|
+
Object.defineProperty(exports, "createRetrieveKnowledge", { enumerable: true, get: function () { return retrieve_knowledge_1.createRetrieveKnowledge; } });
|
|
6
|
+
Object.defineProperty(exports, "RETRIEVE_KNOWLEDGE_TOOL_NAME", { enumerable: true, get: function () { return retrieve_knowledge_1.RETRIEVE_KNOWLEDGE_TOOL_NAME; } });
|
|
7
|
+
exports.mandatoryTools = [];
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":";;;AAEA,2DAG6B;AAF3B,6HAAA,uBAAuB,OAAA;AACvB,kIAAA,4BAA4B,OAAA;AAGjB,QAAA,cAAc,GAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Context } from '../types';
|
|
3
|
+
export declare const RETRIEVE_KNOWLEDGE_TOOL_NAME = "retrieve_knowledge";
|
|
4
|
+
export declare const createRetrieveKnowledge: (sourceIds: string[]) => import("@openai/agents").FunctionTool<Context<import("@botonic/core").ResolvedPlugins, any>, z.ZodObject<{
|
|
5
|
+
query: z.ZodString;
|
|
6
|
+
}, z.core.$strip>, string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRetrieveKnowledge = exports.RETRIEVE_KNOWLEDGE_TOOL_NAME = void 0;
|
|
4
|
+
const agents_1 = require("@openai/agents");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const hubtype_api_client_1 = require("../services/hubtype-api-client");
|
|
7
|
+
exports.RETRIEVE_KNOWLEDGE_TOOL_NAME = 'retrieve_knowledge';
|
|
8
|
+
const createRetrieveKnowledge = (sourceIds) => (0, agents_1.tool)({
|
|
9
|
+
name: exports.RETRIEVE_KNOWLEDGE_TOOL_NAME,
|
|
10
|
+
description: 'Consult the knowledge base for information before answering. Use this tool to make sure the information you provide is faithful.',
|
|
11
|
+
parameters: zod_1.z.object({
|
|
12
|
+
query: zod_1.z.string().describe('The query to search the knowledge base for'),
|
|
13
|
+
}),
|
|
14
|
+
execute: async (input, runContext) => {
|
|
15
|
+
const context = runContext?.context;
|
|
16
|
+
const query = input.query;
|
|
17
|
+
if (!context) {
|
|
18
|
+
throw new Error('Context is required');
|
|
19
|
+
}
|
|
20
|
+
const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
|
|
21
|
+
const chunks = await client.retrieveSimilarChunks(query, sourceIds);
|
|
22
|
+
const chunksIds = chunks.map(chunk => chunk.id);
|
|
23
|
+
const chunkTexts = chunks.map(chunk => chunk.text);
|
|
24
|
+
context.knowledgeUsed = {
|
|
25
|
+
query,
|
|
26
|
+
sourceIds,
|
|
27
|
+
chunksIds,
|
|
28
|
+
chunkTexts,
|
|
29
|
+
};
|
|
30
|
+
return chunkTexts;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
exports.createRetrieveKnowledge = createRetrieveKnowledge;
|
|
34
|
+
//# sourceMappingURL=retrieve-knowledge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AACtD,6BAAuB;AAEvB,uEAAiE;AAGpD,QAAA,4BAA4B,GAAG,oBAAoB,CAAA;AAEzD,MAAM,uBAAuB,GAAG,CAAC,SAAmB,EAAE,EAAE,CAC7D,IAAA,aAAI,EAAC;IACH,IAAI,EAAE,oCAA4B;IAClC,WAAW,EACT,kIAAkI;IACpI,UAAU,EAAE,OAAC,CAAC,MAAM,CAAC;QACnB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;KACzE,CAAC;IACF,OAAO,EAAE,KAAK,EACZ,KAAwB,EACxB,UAAgC,EACb,EAAE;QACrB,MAAM,OAAO,GAAG,UAAU,EAAE,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,MAAM,GAAG,IAAI,qCAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACtD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QACnE,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC/C,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;YACT,UAAU;SACX,CAAA;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;CACF,CAAC,CAAA;AA/BS,QAAA,uBAAuB,2BA+BhC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AgenticOutputMessage, AiAgentArgs, BotContext, GuardrailRule, InferenceResponse, ResolvedPlugins, RunResult } from '@botonic/core';
|
|
2
|
+
import type { Agent, AgentInputItem, AgentOutputType, RunContext as OpenAIRunContext, Tool as OpenAITool } from '@openai/agents';
|
|
3
|
+
import type { ZodType } from 'zod';
|
|
4
|
+
import type { OutputSchema } from './structured-output';
|
|
5
|
+
export interface Context<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
6
|
+
authToken: string;
|
|
7
|
+
knowledgeUsed: {
|
|
8
|
+
query: string;
|
|
9
|
+
sourceIds: string[];
|
|
10
|
+
chunksIds: string[];
|
|
11
|
+
chunkTexts: string[];
|
|
12
|
+
};
|
|
13
|
+
request: BotContext<TPlugins, TExtraData>;
|
|
14
|
+
}
|
|
15
|
+
export type RunContext<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = OpenAIRunContext<Context<TPlugins, TExtraData>>;
|
|
16
|
+
export interface CustomTool<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
schema: ZodType;
|
|
20
|
+
func: (input?: any, runContext?: RunContext<TPlugins, TExtraData>) => Promise<any>;
|
|
21
|
+
}
|
|
22
|
+
export interface Chunk {
|
|
23
|
+
id: string;
|
|
24
|
+
text: string;
|
|
25
|
+
}
|
|
26
|
+
export type Tool<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = OpenAITool<Context<TPlugins, TExtraData>>;
|
|
27
|
+
export type AIAgent<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = Agent<Context<TPlugins, TExtraData>, AgentOutputType<typeof OutputSchema>>;
|
|
28
|
+
export interface MemoryOptions {
|
|
29
|
+
maxMessages: number;
|
|
30
|
+
includeToolCalls: boolean;
|
|
31
|
+
maxFullToolResults: number;
|
|
32
|
+
debugMode: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface PluginAiAgentOptions<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> {
|
|
35
|
+
authToken?: string;
|
|
36
|
+
customTools?: CustomTool<TPlugins, TExtraData>[];
|
|
37
|
+
maxRetries?: number;
|
|
38
|
+
timeout?: number;
|
|
39
|
+
memory?: Partial<MemoryOptions>;
|
|
40
|
+
/** Enable debug logging for AI agent configuration and execution details. */
|
|
41
|
+
enableDebug?: boolean;
|
|
42
|
+
/** Key for the local storage to to get messages in local development mode */
|
|
43
|
+
localStorageKey?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ResultRawResponse {
|
|
46
|
+
usage: {
|
|
47
|
+
inputTokens: number;
|
|
48
|
+
outputTokens: number;
|
|
49
|
+
};
|
|
50
|
+
providerData?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
export type AgenticInputMessage = AgentInputItem;
|
|
53
|
+
export type { AgenticOutputMessage, AiAgentArgs, GuardrailRule, InferenceResponse, RunResult, };
|
package/lib/esm/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"type": "module",
|
|
3
2
|
"name": "@botonic/plugin-ai-agents",
|
|
4
|
-
"version": "0.57.0
|
|
5
|
-
"main": "./lib/index.js",
|
|
6
|
-
"module": "./lib/index.js",
|
|
3
|
+
"version": "0.57.0",
|
|
4
|
+
"main": "./lib/cjs/index.js",
|
|
5
|
+
"module": "./lib/esm/index.js",
|
|
7
6
|
"description": "Use AI Agents to generate your contents",
|
|
8
7
|
"scripts": {
|
|
9
|
-
"build": "
|
|
10
|
-
"build:watch": "
|
|
8
|
+
"build": "rm -rf lib && ../../node_modules/.bin/tsc -p tsconfig.json && ../../node_modules/.bin/tsc -p tsconfig.esm.json",
|
|
9
|
+
"build:watch": "npm run build -- --watch",
|
|
11
10
|
"test": "../../node_modules/.bin/jest --coverage",
|
|
12
|
-
"prepublishOnly": "
|
|
11
|
+
"prepublishOnly": "rm -rf lib && npm i && npm run build",
|
|
13
12
|
"lint": "biome check --write src/ tests/",
|
|
14
13
|
"lint:check": "biome check src/ tests/",
|
|
15
14
|
"format": "biome format --write src/ tests/"
|
|
16
15
|
},
|
|
17
16
|
"dependencies": {
|
|
18
|
-
"@botonic/core": "0.57.0
|
|
17
|
+
"@botonic/core": "^0.57.0",
|
|
19
18
|
"@openai/agents": "^0.10.1",
|
|
20
19
|
"axios": "^1.18.1",
|
|
21
20
|
"openai": "^6.36.0",
|
|
@@ -31,7 +30,7 @@
|
|
|
31
30
|
"README.md"
|
|
32
31
|
],
|
|
33
32
|
"engines": {
|
|
34
|
-
"node": ">=22.
|
|
33
|
+
"node": ">=22.23.2",
|
|
35
34
|
"npm": ">=10.0.0"
|
|
36
35
|
},
|
|
37
36
|
"repository": {
|
|
@@ -46,6 +45,5 @@
|
|
|
46
45
|
"typescript",
|
|
47
46
|
"javascript"
|
|
48
47
|
],
|
|
49
|
-
"author": ""
|
|
50
|
-
"types": "./lib/index.d.ts"
|
|
48
|
+
"author": ""
|
|
51
49
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
OutputMessage,
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
type OutputMessage,
|
|
3
|
+
OutputMessageType,
|
|
4
|
+
type ResolvedPlugins,
|
|
5
|
+
type ToolExecution,
|
|
5
6
|
} from '@botonic/core'
|
|
6
7
|
import {
|
|
7
8
|
InputGuardrailTripwireTriggered,
|
|
@@ -214,22 +215,30 @@ export abstract class BaseRunner<
|
|
|
214
215
|
const outputMessages = result.finalOutput?.messages || []
|
|
215
216
|
const hasExit =
|
|
216
217
|
outputMessages.length === 0 ||
|
|
217
|
-
outputMessages.some(message => message.type ===
|
|
218
|
+
outputMessages.some(message => message.type === OutputMessageType.Exit)
|
|
219
|
+
|
|
220
|
+
const hasDoNothing = outputMessages.some(
|
|
221
|
+
message => message.type === OutputMessageType.DoNothing
|
|
222
|
+
)
|
|
218
223
|
|
|
219
224
|
return {
|
|
220
225
|
startingAgentName: '',
|
|
221
226
|
lastAgentName: '',
|
|
222
227
|
availableSpecialists: [],
|
|
223
228
|
isTransferredToSpecialist: false,
|
|
224
|
-
messages:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
+
messages:
|
|
230
|
+
hasExit || hasDoNothing
|
|
231
|
+
? []
|
|
232
|
+
: (outputMessages.filter(
|
|
233
|
+
message =>
|
|
234
|
+
message.type !== OutputMessageType.Exit &&
|
|
235
|
+
message.type !== OutputMessageType.DoNothing
|
|
236
|
+
) as AgenticOutputMessage[]),
|
|
229
237
|
toolsExecuted: this.getToolsExecuted(result, context),
|
|
230
238
|
exit: hasExit,
|
|
231
239
|
memoryLength,
|
|
232
240
|
error: false,
|
|
241
|
+
doNothing: hasDoNothing,
|
|
233
242
|
inputGuardrailsTriggered: [],
|
|
234
243
|
outputGuardrailsTriggered: [],
|
|
235
244
|
}
|
|
@@ -295,6 +304,7 @@ export abstract class BaseRunner<
|
|
|
295
304
|
toolsExecuted: [],
|
|
296
305
|
exit: true,
|
|
297
306
|
error: false,
|
|
307
|
+
doNothing: false,
|
|
298
308
|
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
299
309
|
outputGuardrailsTriggered: [],
|
|
300
310
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DoNothingMessage, OutputMessageType } from '@botonic/core'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
export type { DoNothingMessage }
|
|
5
|
+
|
|
6
|
+
export const DoNothingSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
type: z.literal(OutputMessageType.DoNothing),
|
|
9
|
+
})
|
|
10
|
+
.describe(
|
|
11
|
+
'A do nothing message is used to end the conversation without send a reply. Use it only when asked explicitly in the prompt.'
|
|
12
|
+
)
|
|
@@ -2,7 +2,9 @@ import type { OutputMessage } from '@botonic/core'
|
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
import { BotExecutorSchema } from './bot-executor'
|
|
4
4
|
import { CarouselSchema } from './carousel'
|
|
5
|
+
import { DoNothingSchema } from './do-nothing'
|
|
5
6
|
import { ExitSchema } from './exit'
|
|
7
|
+
import { RequestContactInfoSchema } from './request-contact-info'
|
|
6
8
|
import { TextSchema } from './text'
|
|
7
9
|
import { TextWithButtonsSchema } from './text-with-buttons'
|
|
8
10
|
|
|
@@ -14,8 +16,10 @@ const baseMessageSchemas = [
|
|
|
14
16
|
TextSchema,
|
|
15
17
|
TextWithButtonsSchema,
|
|
16
18
|
CarouselSchema,
|
|
19
|
+
DoNothingSchema,
|
|
17
20
|
ExitSchema,
|
|
18
21
|
BotExecutorSchema,
|
|
22
|
+
RequestContactInfoSchema,
|
|
19
23
|
] as const
|
|
20
24
|
export const OutputSchema = z
|
|
21
25
|
.object({
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OutputMessageType,
|
|
3
|
+
type RequestContactInfoMessage,
|
|
4
|
+
} from '@botonic/core'
|
|
5
|
+
import { z } from 'zod'
|
|
6
|
+
|
|
7
|
+
export type { RequestContactInfoMessage }
|
|
8
|
+
|
|
9
|
+
export const RequestContactInfoSchema = z
|
|
10
|
+
.object({
|
|
11
|
+
type: z.literal(OutputMessageType.RequestContactInfo),
|
|
12
|
+
content: z.object({
|
|
13
|
+
text: z.string().describe('The text of the message'),
|
|
14
|
+
}),
|
|
15
|
+
})
|
|
16
|
+
.describe(
|
|
17
|
+
'A message to request phone number from the user. Use it only when asked explicitly in the prompt.'
|
|
18
|
+
)
|
package/lib/agents/base-agent.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { createInputGuardrails } from "../guardrails/index.js";
|
|
2
|
-
import { getOutputInstructions, getOutputSchema } from "../structured-output/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function _define_property(obj, key, value) {
|
|
7
|
-
if (key in obj) {
|
|
8
|
-
Object.defineProperty(obj, key, {
|
|
9
|
-
value: value,
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true
|
|
13
|
-
});
|
|
14
|
-
} else obj[key] = value;
|
|
15
|
-
return obj;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class BaseAgent {
|
|
20
|
-
getAgentModelSettings() {
|
|
21
|
-
const modelSettings = {
|
|
22
|
-
...this.llmConfig.modelSettings
|
|
23
|
-
};
|
|
24
|
-
if (this.llmConfig.modelSettings.reasoning) {
|
|
25
|
-
modelSettings.reasoning = {
|
|
26
|
-
...this.llmConfig.modelSettings.reasoning
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
if (this.llmConfig.modelSettings.text) {
|
|
30
|
-
modelSettings.text = {
|
|
31
|
-
...this.llmConfig.modelSettings.text
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return modelSettings;
|
|
35
|
-
}
|
|
36
|
-
async getInputGuardrails() {
|
|
37
|
-
return await createInputGuardrails(this.inputGuardrailRules, this.llmConfig, this.guardrailTrackingContext);
|
|
38
|
-
}
|
|
39
|
-
getOutputType() {
|
|
40
|
-
return getOutputSchema(this.outputMessagesSchemas);
|
|
41
|
-
}
|
|
42
|
-
addOutputInstructions(instructions) {
|
|
43
|
-
return `${instructions}\n\n${getOutputInstructions()}`;
|
|
44
|
-
}
|
|
45
|
-
async getModel() {
|
|
46
|
-
return await this.llmConfig.getModel();
|
|
47
|
-
}
|
|
48
|
-
constructor(options){
|
|
49
|
-
_define_property(this, "name", void 0);
|
|
50
|
-
_define_property(this, "instructions", void 0);
|
|
51
|
-
_define_property(this, "llmConfig", void 0);
|
|
52
|
-
_define_property(this, "inputGuardrailRules", void 0);
|
|
53
|
-
_define_property(this, "outputMessagesSchemas", void 0);
|
|
54
|
-
_define_property(this, "guardrailTrackingContext", void 0);
|
|
55
|
-
this.name = options.name;
|
|
56
|
-
this.instructions = options.instructions;
|
|
57
|
-
this.llmConfig = options.llmConfig;
|
|
58
|
-
this.inputGuardrailRules = options.inputGuardrailRules;
|
|
59
|
-
this.outputMessagesSchemas = options.outputMessagesSchemas || [];
|
|
60
|
-
this.guardrailTrackingContext = options.guardrailTrackingContext;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { BaseAgent };
|
|
65
|
-
|
|
66
|
-
//# sourceMappingURL=base-agent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agents/base-agent.js","sources":["../../src/agents/base-agent.ts"],"sourcesContent":["import type {\n AgentOutputType,\n InputGuardrail,\n Model,\n ModelSettings,\n} from '@openai/agents'\nimport type { z } from 'zod'\n\nimport { createInputGuardrails } from '../guardrails'\nimport type { GuardrailTrackingContext } from '../guardrails/input'\nimport type { LLMConfig } from '../llm-config'\nimport {\n getOutputInstructions,\n getOutputSchema,\n type OutputSchema,\n} from '../structured-output'\nimport type { GuardrailRule } from '../types'\n\nexport interface BaseAgentOptions {\n name: string\n instructions: string\n llmConfig: LLMConfig\n inputGuardrailRules: GuardrailRule[]\n outputMessagesSchemas?: z.ZodObject[]\n guardrailTrackingContext: GuardrailTrackingContext\n}\n\nexport abstract class BaseAgent {\n protected name: string\n protected instructions: string\n protected llmConfig: LLMConfig\n private inputGuardrailRules: GuardrailRule[]\n private outputMessagesSchemas: z.ZodObject[]\n private guardrailTrackingContext: GuardrailTrackingContext\n\n constructor(options: BaseAgentOptions) {\n this.name = options.name\n this.instructions = options.instructions\n this.llmConfig = options.llmConfig\n this.inputGuardrailRules = options.inputGuardrailRules\n this.outputMessagesSchemas = options.outputMessagesSchemas || []\n this.guardrailTrackingContext = options.guardrailTrackingContext\n }\n\n protected getAgentModelSettings(): ModelSettings {\n const modelSettings: ModelSettings = { ...this.llmConfig.modelSettings }\n\n if (this.llmConfig.modelSettings.reasoning) {\n modelSettings.reasoning = { ...this.llmConfig.modelSettings.reasoning }\n }\n\n if (this.llmConfig.modelSettings.text) {\n modelSettings.text = { ...this.llmConfig.modelSettings.text }\n }\n\n return modelSettings\n }\n\n protected async getInputGuardrails(): Promise<InputGuardrail[]> {\n return await createInputGuardrails(\n this.inputGuardrailRules,\n this.llmConfig,\n this.guardrailTrackingContext\n )\n }\n\n protected getOutputType(): AgentOutputType<typeof OutputSchema> {\n return getOutputSchema(this.outputMessagesSchemas)\n }\n\n protected addOutputInstructions(instructions: string): string {\n return `${instructions}\\n\\n${getOutputInstructions()}`\n }\n\n protected async getModel(): Promise<string | Model> {\n return await this.llmConfig.getModel()\n }\n}\n"],"names":["createInputGuardrails","getOutputInstructions","getOutputSchema","BaseAgent","modelSettings","instructions","options"],"mappings":";;;;;;;;;;;;;;;;AAQqD;AAOxB;AAYtB,MAAeG,SAASA;IAiBnB,wBAAuC;QAC/C,MAAMC,gBAA+B;YAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa;QAAC;QAEvE,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE;YAC1CA,cAAc,SAAS,GAAG;gBAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS;YAAC;QACxE;QAEA,IAAI,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE;YACrCA,cAAc,IAAI,GAAG;gBAAE,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI;YAAC;QAC9D;QAEA,OAAOA;IACT;IAEA,MAAgB,qBAAgD;QAC9D,OAAO,MAAMJ,qBAAqBA,CAChC,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,wBAAwB;IAEjC;IAEU,gBAAsD;QAC9D,OAAOE,eAAeA,CAAC,IAAI,CAAC,qBAAqB;IACnD;IAEU,sBAAsBG,YAAoB,EAAU;QAC5D,OAAO,GAAGA,aAAa,IAAI,EAAEJ,qBAAqBA,IAAI;IACxD;IAEA,MAAgB,WAAoC;QAClD,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ;IACtC;IAzCA,YAAYK,OAAyB,CAAE;QAPvC,uBAAU,QAAV;QACA,uBAAU,gBAAV;QACA,uBAAU,aAAV;QACA,uBAAQ,uBAAR;QACA,uBAAQ,yBAAR;QACA,uBAAQ,4BAAR;QAGE,IAAI,CAAC,IAAI,GAAGA,QAAQ,IAAI;QACxB,IAAI,CAAC,YAAY,GAAGA,QAAQ,YAAY;QACxC,IAAI,CAAC,SAAS,GAAGA,QAAQ,SAAS;QAClC,IAAI,CAAC,mBAAmB,GAAGA,QAAQ,mBAAmB;QACtD,IAAI,CAAC,qBAAqB,GAAGA,QAAQ,qBAAqB,IAAI,EAAE;QAChE,IAAI,CAAC,wBAAwB,GAAGA,QAAQ,wBAAwB;IAClE;AAmCF"}
|
package/lib/agents/index.d.ts
DELETED
package/lib/agents/index.js
DELETED
package/lib/agents/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agents/index.js","sources":["../../src/agents/index.ts"],"sourcesContent":["export { RouterAgent } from './router-agent'\nexport { SpecialistAgent } from './specialist-agent'\n"],"names":["RouterAgent","SpecialistAgent"],"mappings":";;AAA4C;AACQ"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Agent } from "@openai/agents";
|
|
2
|
-
import { RECOMMENDED_PROMPT_PREFIX } from "@openai/agents-core/extensions";
|
|
3
|
-
import { BaseAgent } from "./base-agent.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function _define_property(obj, key, value) {
|
|
9
|
-
if (key in obj) {
|
|
10
|
-
Object.defineProperty(obj, key, {
|
|
11
|
-
value: value,
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true
|
|
15
|
-
});
|
|
16
|
-
} else obj[key] = value;
|
|
17
|
-
return obj;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class RouterAgent extends BaseAgent {
|
|
23
|
-
static async create(options) {
|
|
24
|
-
const routerAgent = new RouterAgent(options);
|
|
25
|
-
const inputGuardrails = await routerAgent.getInputGuardrails();
|
|
26
|
-
// Agent.create is typed as Agent<UnknownContext>; we run with Context<TPlugins, TExtraData>.
|
|
27
|
-
const agent = Agent.create({
|
|
28
|
-
name: routerAgent.name,
|
|
29
|
-
model: await routerAgent.getModel(),
|
|
30
|
-
modelSettings: routerAgent.getAgentModelSettings(),
|
|
31
|
-
instructions: routerAgent.addOutputInstructions(`${RECOMMENDED_PROMPT_PREFIX}${routerAgent.instructions}`),
|
|
32
|
-
handoffs: routerAgent.handoffs,
|
|
33
|
-
outputType: routerAgent.getOutputType(),
|
|
34
|
-
inputGuardrails
|
|
35
|
-
});
|
|
36
|
-
routerAgent.agent = agent;
|
|
37
|
-
return routerAgent;
|
|
38
|
-
}
|
|
39
|
-
getAgent() {
|
|
40
|
-
return this.agent;
|
|
41
|
-
}
|
|
42
|
-
constructor(options){
|
|
43
|
-
super(options), _define_property(this, "handoffs", void 0), _define_property(this, "agent", void 0);
|
|
44
|
-
this.handoffs = options.handoffs;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export { RouterAgent };
|
|
49
|
-
|
|
50
|
-
//# sourceMappingURL=router-agent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agents/router-agent.js","sources":["../../src/agents/router-agent.ts"],"sourcesContent":["import type { ResolvedPlugins } from '@botonic/core'\nimport { Agent, type AgentOutputType, type Handoff } from '@openai/agents'\nimport { RECOMMENDED_PROMPT_PREFIX } from '@openai/agents-core/extensions'\nimport type { z } from 'zod'\nimport type { GuardrailTrackingContext } from '../guardrails/input'\nimport type { LLMConfig } from '../llm-config'\nimport type { OutputSchema } from '../structured-output'\nimport type { AIAgent, Context, GuardrailRule } from '../types'\nimport { BaseAgent } from './base-agent'\n\ninterface RouterAgentOptions<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n> {\n name: string\n instructions: string\n llmConfig: LLMConfig\n handoffs: Handoff<\n Context<TPlugins, TExtraData>,\n AgentOutputType<typeof OutputSchema>\n >[]\n inputGuardrailRules: GuardrailRule[]\n outputMessagesSchemas?: z.ZodObject[]\n guardrailTrackingContext: GuardrailTrackingContext\n}\n\nexport class RouterAgent<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n> extends BaseAgent {\n private handoffs: Handoff<\n Context<TPlugins, TExtraData>,\n AgentOutputType<typeof OutputSchema>\n >[]\n private agent!: AIAgent<TPlugins, TExtraData>\n\n private constructor(options: RouterAgentOptions<TPlugins, TExtraData>) {\n super(options)\n this.handoffs = options.handoffs\n }\n\n static async create<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n >(\n options: RouterAgentOptions<TPlugins, TExtraData>\n ): Promise<RouterAgent<TPlugins, TExtraData>> {\n const routerAgent = new RouterAgent<TPlugins, TExtraData>(options)\n const inputGuardrails = await routerAgent.getInputGuardrails()\n\n // Agent.create is typed as Agent<UnknownContext>; we run with Context<TPlugins, TExtraData>.\n const agent = Agent.create({\n name: routerAgent.name,\n model: await routerAgent.getModel(),\n modelSettings: routerAgent.getAgentModelSettings(),\n instructions: routerAgent.addOutputInstructions(\n `${RECOMMENDED_PROMPT_PREFIX}${routerAgent.instructions}`\n ),\n handoffs: routerAgent.handoffs,\n outputType: routerAgent.getOutputType(),\n inputGuardrails,\n }) as AIAgent<TPlugins, TExtraData>\n\n routerAgent.agent = agent\n return routerAgent\n }\n\n getAgent(): AIAgent<TPlugins, TExtraData> {\n return this.agent\n }\n}\n"],"names":["Agent","RECOMMENDED_PROMPT_PREFIX","BaseAgent","RouterAgent","options","routerAgent","inputGuardrails","agent"],"mappings":";;;;;;;;;;;;;;;;;;AAC0E;AACA;AAMlC;AAkBjC,MAAMG,WAAWA,SAGdD,SAASA;IAYjB,aAAa,OAIXE,OAAiD,EACL;QAC5C,MAAMC,cAAc,IAAIF,WAAWA,CAAuBC;QAC1D,MAAME,kBAAkB,MAAMD,YAAY,kBAAkB;QAE5D,6FAA6F;QAC7F,MAAME,QAAQP,YAAY,CAAC;YACzB,MAAMK,YAAY,IAAI;YACtB,OAAO,MAAMA,YAAY,QAAQ;YACjC,eAAeA,YAAY,qBAAqB;YAChD,cAAcA,YAAY,qBAAqB,CAC7C,GAAGJ,yBAAyBA,GAAGI,YAAY,YAAY,EAAE;YAE3D,UAAUA,YAAY,QAAQ;YAC9B,YAAYA,YAAY,aAAa;YACrCC;QACF;QAEAD,YAAY,KAAK,GAAGE;QACpB,OAAOF;IACT;IAEA,WAA0C;QACxC,OAAO,IAAI,CAAC,KAAK;IACnB;IAjCA,YAAoBD,OAAiD,CAAE;QACrE,KAAK,CAACA,UAPR,uBAAQ,YAAR,SAIA,uBAAQ,SAAR;QAIE,IAAI,CAAC,QAAQ,GAAGA,QAAQ,QAAQ;IAClC;AA+BF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agents/specialist-agent.js","sources":["../../src/agents/specialist-agent.ts"],"sourcesContent":["import type { CampaignV2, ContactInfo, ResolvedPlugins } from '@botonic/core'\nimport { Agent, type AgentOutputType, type ModelSettings } from '@openai/agents'\nimport type { z } from 'zod'\nimport { LLM_PROVIDER } from '../constants'\nimport type { DebugLogger } from '../debug-logger'\nimport type { GuardrailTrackingContext } from '../guardrails/input'\nimport type { LLMConfig } from '../llm-config'\nimport type { OutputSchema } from '../structured-output'\nimport {\n createRetrieveKnowledge,\n mandatoryTools,\n RETRIEVE_KNOWLEDGE_TOOL_NAME,\n} from '../tools'\nimport type { AIAgent, Context, GuardrailRule, Tool } from '../types'\nimport { BaseAgent } from './base-agent'\n\ninterface SpecialistAgentOptions<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n> {\n name: string\n instructions: string\n tools: Tool<TPlugins, TExtraData>[]\n campaignsContext?: CampaignV2[]\n contactInfo: ContactInfo[]\n inputGuardrailRules: GuardrailRule[]\n sourceIds: string[]\n outputMessagesSchemas?: z.ZodObject[]\n llmConfig: LLMConfig\n logger: DebugLogger\n guardrailTrackingContext: GuardrailTrackingContext\n forceToolNameOverride?: string\n disableForceRetrieveKnowledge?: boolean\n}\n\nexport class SpecialistAgent<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n> extends BaseAgent {\n private tools: Tool<TPlugins, TExtraData>[]\n private logger: DebugLogger\n private agent!: AIAgent<TPlugins, TExtraData>\n private forceToolNameOverride?: string\n private disableForceRetrieveKnowledge?: boolean\n\n private constructor(options: SpecialistAgentOptions<TPlugins, TExtraData>) {\n super({\n name: options.name,\n instructions: options.instructions,\n llmConfig: options.llmConfig,\n inputGuardrailRules: options.inputGuardrailRules,\n outputMessagesSchemas: options.outputMessagesSchemas,\n guardrailTrackingContext: options.guardrailTrackingContext,\n })\n this.instructions = this.addExtraInstructions(\n options.instructions,\n options.contactInfo,\n options.campaignsContext\n )\n this.tools = this.addHubtypeTools(options.tools, options.sourceIds)\n this.logger = options.logger\n this.forceToolNameOverride = options.forceToolNameOverride\n this.disableForceRetrieveKnowledge = options.disableForceRetrieveKnowledge\n }\n\n static async create<\n TPlugins extends ResolvedPlugins = ResolvedPlugins,\n TExtraData = unknown,\n >(\n options: SpecialistAgentOptions<TPlugins, TExtraData>\n ): Promise<SpecialistAgent<TPlugins, TExtraData>> {\n const specialistAgent = new SpecialistAgent<TPlugins, TExtraData>(options)\n const model = specialistAgent.llmConfig.modelName\n const resolvedModel = await specialistAgent.getModel()\n const hasRetrieveKnowledge = specialistAgent.tools.some(\n tool => tool.name === RETRIEVE_KNOWLEDGE_TOOL_NAME\n )\n const modelSettings =\n specialistAgent.getSpecialistModelSettings(hasRetrieveKnowledge)\n const inputGuardrails = await specialistAgent.getInputGuardrails()\n\n specialistAgent.logger.logModelSettings({\n provider: LLM_PROVIDER,\n model,\n reasoning: modelSettings.reasoning as { effort: string } | undefined,\n text: modelSettings.text as { verbosity: string } | undefined,\n toolChoice: modelSettings.toolChoice,\n hasRetrieveKnowledge,\n })\n\n const agent = new Agent<\n Context<TPlugins, TExtraData>,\n AgentOutputType<typeof OutputSchema>\n >({\n name: specialistAgent.name,\n model: resolvedModel,\n modelSettings,\n instructions: specialistAgent.instructions,\n tools: specialistAgent.tools,\n outputType: specialistAgent.getOutputType(),\n inputGuardrails,\n outputGuardrails: [],\n })\n\n specialistAgent.agent = agent\n return specialistAgent\n }\n\n getAgent(): AIAgent<TPlugins, TExtraData> {\n return this.agent\n }\n\n private getSpecialistModelSettings(\n hasRetrieveKnowledge: boolean\n ): ModelSettings {\n const modelSettings = this.getAgentModelSettings()\n const forceRetrieveKnowledge =\n hasRetrieveKnowledge &&\n !this.forceToolNameOverride &&\n !this.disableForceRetrieveKnowledge\n\n if (forceRetrieveKnowledge) {\n modelSettings.toolChoice = RETRIEVE_KNOWLEDGE_TOOL_NAME\n }\n\n if (this.forceToolNameOverride) {\n modelSettings.toolChoice = this.forceToolNameOverride\n }\n\n return modelSettings\n }\n\n private addExtraInstructions(\n initialInstructions: string,\n contactInfo: ContactInfo[],\n campaignsContext?: CampaignV2[]\n ): string {\n const sections = [\n `<instructions>\\n${initialInstructions.trim()}\\n</instructions>`,\n this.getMetadataInstructions(),\n this.getContactInfoInstructions(contactInfo),\n this.getCampaignInstructions(campaignsContext),\n ].filter(section => section.length > 0)\n\n return this.addOutputInstructions(sections.join('\\n\\n'))\n }\n\n private getContactInfoInstructions(contactInfo: ContactInfo[]): string {\n return `<contact_info_fields>${JSON.stringify(\n contactInfo.map(info => ({\n name: info.name,\n value: info.value,\n })),\n null,\n 0\n )}</contact_info_fields>`\n }\n\n private getMetadataInstructions(): string {\n const metadata = `Current Date: ${new Date().toISOString()}`\n return `<metadata>\\n${metadata}\\n</metadata>`\n }\n\n private getCampaignInstructions(campaignsContext?: CampaignV2[]): string {\n if (!campaignsContext || campaignsContext.length === 0) {\n return ''\n }\n const campaignsWithContext = campaignsContext.filter(\n campaign => campaign.agent_context\n )\n if (campaignsWithContext.length === 0) {\n return ''\n }\n return campaignsWithContext\n .map(\n (campaign, index) =>\n `<campaign_context_${index + 1}>\\n${campaign.agent_context}\\n</campaign_context_${index + 1}>`\n )\n .join('\\n')\n }\n\n private addHubtypeTools(\n tools: Tool<TPlugins, TExtraData>[],\n sourceIds: string[]\n ): Tool<TPlugins, TExtraData>[] {\n const hubtypeTools: Tool[] = [...mandatoryTools]\n if (sourceIds.length > 0) {\n hubtypeTools.push(createRetrieveKnowledge(sourceIds))\n }\n return [...hubtypeTools, ...tools]\n }\n}\n"],"names":["Agent","LLM_PROVIDER","createRetrieveKnowledge","mandatoryTools","RETRIEVE_KNOWLEDGE_TOOL_NAME","BaseAgent","SpecialistAgent","options","specialistAgent","model","resolvedModel","hasRetrieveKnowledge","tool","modelSettings","inputGuardrails","agent","forceRetrieveKnowledge","initialInstructions","contactInfo","campaignsContext","sections","section","JSON","info","metadata","Date","campaigns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SAAC;QAChD,IAAI2B,UAAU,MAAM,GAAG,GAAG;YACxBC,aAAa,IAAI,CAAC7B,uBAAuBA,CAAC4B;QAC5C;QACA,OAAO;eAAIC;eAAiBF;SAAM;IACpC;IAjJA,YAAoBtB,OAAqD,CAAE;QACzE,KAAK,CAAC;YACJ,MAAMA,QAAQ,IAAI;YAClB,cAAcA,QAAQ,YAAY;YAClC,WAAWA,QAAQ,SAAS;YAC5B,qBAAqBA,QAAQ,mBAAmB;YAChD,uBAAuBA,QAAQ,qBAAqB;YACpD,0BAA0BA,QAAQ,wBAAwB;QAC5D,IAdF,uBAAQ,SAAR,SACA,uBAAQ,UAAR,SACA,uBAAQ,SAAR,SACA,uBAAQ,yBAAR,SACA,uBAAQ,iCAAR;QAWE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAC3CA,QAAQ,YAAY,EACpBA,QAAQ,WAAW,EACnBA,QAAQ,gBAAgB;QAE1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAACA,QAAQ,KAAK,EAAEA,QAAQ,SAAS;QAClE,IAAI,CAAC,MAAM,GAAGA,QAAQ,MAAM;QAC5B,IAAI,CAAC,qBAAqB,GAAGA,QAAQ,qBAAqB;QAC1D,IAAI,CAAC,6BAA6B,GAAGA,QAAQ,6BAA6B;IAC5E;AAgIF"}
|
package/lib/bot-config-tools.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Maps custom AI agent tools to the format expected by bot config (e.g. for flow-builder).
|
|
7
|
-
* Converts each tool's Zod schema to JSON Schema so it can be serialized in the config.
|
|
8
|
-
*/ function getToolsForBotConfig(customTools) {
|
|
9
|
-
return customTools.map((tool)=>({
|
|
10
|
-
name: tool.name,
|
|
11
|
-
description: tool.description,
|
|
12
|
-
schema: z.toJSONSchema(tool.schema, {
|
|
13
|
-
target: 'draft-07'
|
|
14
|
-
})
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { getToolsForBotConfig };
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=bot-config-tools.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bot-config-tools.js","sources":["../src/bot-config-tools.ts"],"sourcesContent":["import type { ToolConfigJSON } from '@botonic/core'\nimport { z } from 'zod'\n\nimport type { CustomTool } from './types'\n\n/**\n * Maps custom AI agent tools to the format expected by bot config (e.g. for flow-builder).\n * Converts each tool's Zod schema to JSON Schema so it can be serialized in the config.\n */\nexport function getToolsForBotConfig(\n customTools: CustomTool[]\n): ToolConfigJSON[] {\n return customTools.map(tool => ({\n name: tool.name,\n description: tool.description,\n schema: z.toJSONSchema(tool.schema, {\n target: 'draft-07',\n }) as ToolConfigJSON['schema'],\n }))\n}\n"],"names":["z","getToolsForBotConfig","customTools","tool"],"mappings":";;;AACuB;AAIvB;;;CAGC,GACM,SAASC,oBAAoBA,CAClCC,WAAyB;IAEzB,OAAOA,YAAY,GAAG,CAACC,CAAAA,OAAS;YAC9B,MAAMA,KAAK,IAAI;YACf,aAAaA,KAAK,WAAW;YAC7B,QAAQH,cAAc,CAACG,KAAK,MAAM,EAAE;gBAClC,QAAQ;YACV;QACF;AACF"}
|
package/lib/constants.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
|
|
2
|
-
// LLM Configuration (provider-agnostic; set LLM_PROVIDER=azure|openai)
|
|
3
|
-
const LLM_PROVIDERS = {
|
|
4
|
-
AZURE: 'azure',
|
|
5
|
-
OPENAI: 'openai',
|
|
6
|
-
LITELLM: 'litellm'
|
|
7
|
-
};
|
|
8
|
-
const LITELLM_TAG_KEYS = {
|
|
9
|
-
BOT_ID: 'bot_id',
|
|
10
|
-
ORG_ID: 'org_id',
|
|
11
|
-
SEPARATOR: ','
|
|
12
|
-
};
|
|
13
|
-
const LLM_PROVIDER = process.env.LLM_PROVIDER || LLM_PROVIDERS.AZURE;
|
|
14
|
-
const LLM_API_KEY = process.env.LLM_API_KEY // pragma: allowlist secret
|
|
15
|
-
;
|
|
16
|
-
const LLM_API_URL = process.env.LLM_API_URL;
|
|
17
|
-
const LLM_AZURE_API_VERSION = process.env.LLM_AZURE_API_VERSION || '2025-01-01-preview';
|
|
18
|
-
const LLM_OPENAI_MODEL = process.env.LLM_OPENAI_MODEL || 'gpt-4.1-mini';
|
|
19
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
20
|
-
const MAX_MEMORY_LENGTH = 25;
|
|
21
|
-
const DEFAULT_TIMEOUT_16_SECONDS = 16000;
|
|
22
|
-
const DEFAULT_MAX_RETRIES = 2;
|
|
23
|
-
|
|
24
|
-
export { DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_16_SECONDS, HUBTYPE_API_URL, LITELLM_TAG_KEYS, LLM_API_KEY, LLM_API_URL, LLM_AZURE_API_VERSION, LLM_OPENAI_MODEL, LLM_PROVIDER, LLM_PROVIDERS, MAX_MEMORY_LENGTH, isProd };
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=constants.js.map
|
package/lib/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const HUBTYPE_API_URL =\n process.env.HUBTYPE_API_URL || 'https://api.hubtype.com'\n\n// LLM Configuration (provider-agnostic; set LLM_PROVIDER=azure|openai)\nexport const LLM_PROVIDERS = {\n AZURE: 'azure',\n OPENAI: 'openai',\n LITELLM: 'litellm',\n} as const\n\nexport type LLMProviderType = (typeof LLM_PROVIDERS)[keyof typeof LLM_PROVIDERS]\n\nexport const LITELLM_TAG_KEYS = {\n BOT_ID: 'bot_id',\n ORG_ID: 'org_id',\n SEPARATOR: ',',\n} as const\n\nexport const LLM_PROVIDER: LLMProviderType =\n (process.env.LLM_PROVIDER as LLMProviderType) || LLM_PROVIDERS.AZURE\nexport const LLM_API_KEY = process.env.LLM_API_KEY // pragma: allowlist secret\nexport const LLM_API_URL = process.env.LLM_API_URL\nexport const LLM_AZURE_API_VERSION =\n process.env.LLM_AZURE_API_VERSION || '2025-01-01-preview'\nexport const LLM_OPENAI_MODEL = process.env.LLM_OPENAI_MODEL || 'gpt-4.1-mini'\n\nexport const isProd = process.env.NODE_ENV === 'production'\n\nexport const MAX_MEMORY_LENGTH = 25\n\nexport const DEFAULT_TIMEOUT_16_SECONDS = 16000\nexport const DEFAULT_MAX_RETRIES = 2\n"],"names":["HUBTYPE_API_URL","process","LLM_PROVIDERS","LITELLM_TAG_KEYS","LLM_PROVIDER","LLM_API_KEY","LLM_API_URL","LLM_AZURE_API_VERSION","LLM_OPENAI_MODEL","isProd","MAX_MEMORY_LENGTH","DEFAULT_TIMEOUT_16_SECONDS","DEFAULT_MAX_RETRIES"],"mappings":"AAAO,MAAMA,eAAeA,GAC1BC,QAAQ,GAAG,CAAC,eAAe,IAAI,0BAAyB;AAE1D,uEAAuE;AAChE,MAAMC,aAAaA,GAAG;IAC3B,OAAO;IACP,QAAQ;IACR,SAAS;AACX,EAAU;AAIH,MAAMC,gBAAgBA,GAAG;IAC9B,QAAQ;IACR,QAAQ;IACR,WAAW;AACb,EAAU;AAEH,MAAMC,YAAYA,GACtBH,QAAQ,GAAG,CAAC,YAAY,IAAwBC,aAAaA,CAAC,KAAK;AAC/D,MAAMG,WAAWA,GAAGJ,QAAQ,GAAG,CAAC,WAAW,CAAC,2BAA2B;CAA5B;AAC3C,MAAMK,WAAWA,GAAGL,QAAQ,GAAG,CAAC,WAAW;AAC3C,MAAMM,qBAAqBA,GAChCN,QAAQ,GAAG,CAAC,qBAAqB,IAAI,qBAAoB;AACpD,MAAMO,gBAAgBA,GAAGP,QAAQ,GAAG,CAAC,gBAAgB,IAAI,eAAc;AAEvE,MAAMQ,MAAMA,GAAGR,oBAAoB,KAAK,aAAY;AAEpD,MAAMS,iBAAiBA,GAAG,GAAE;AAE5B,MAAMC,0BAA0BA,GAAG,MAAK;AACxC,MAAMC,mBAAmBA,GAAG,EAAC"}
|
package/lib/debug-logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug-logger.js","sources":["../src/debug-logger.ts"],"sourcesContent":["import {\n type AiAgentArgs,\n AiAgentType,\n type ToolExecution,\n} from '@botonic/core'\nimport type { ModelSettings } from '@openai/agents'\nimport { LLM_PROVIDER } from './constants'\nimport type { AgenticInputMessage, MemoryOptions, RunResult } from './types'\n\nconst PREFIX = '[BotonicPluginAiAgents]'\n\nexport interface DebugLoggerConfig {\n messageHistoryApiVersion: string\n maxRetries: number\n timeout: number\n customToolNames: string[]\n memory: MemoryOptions\n}\n\nexport interface ModelSettingsInfo {\n provider: string\n model: string | undefined\n reasoning?: { effort: string }\n text?: { verbosity: string }\n toolChoice?: string\n hasRetrieveKnowledge: boolean\n}\n\nexport interface DebugLogger {\n logInitialConfig(config: DebugLoggerConfig): void\n logAgentDebugInfo(\n aiAgentArgs: AiAgentArgs,\n toolNames: string[],\n messages: AgenticInputMessage[]\n ): void\n logModelSettings(settings: ModelSettingsInfo): void\n logRunnerStart(\n model: string,\n modelSettings: ModelSettings,\n prompt: string\n ): void\n logRunResult(runResult: RunResult, startTime: number): void\n logGuardrailTriggered(): void\n logRunnerError(startTime: number, error: unknown): void\n logToolExecution(toolExecution: ToolExecution): void\n}\n\nclass EnabledDebugLogger implements DebugLogger {\n logInitialConfig(config: DebugLoggerConfig): void {\n console.log(`${PREFIX} === Plugin Initialization ===`)\n console.log(`${PREFIX} Provider: ${LLM_PROVIDER}`)\n console.log(\n `${PREFIX} Message History API Version: ${config.messageHistoryApiVersion}`\n )\n console.log(`${PREFIX} Max Retries: ${config.maxRetries}`)\n console.log(`${PREFIX} Timeout: ${config.timeout}ms`)\n console.log(\n `${PREFIX} Custom Tools Registered: ${config.customToolNames.join(', ') || 'none'}`\n )\n console.log(`${PREFIX} Memory Options:`, {\n maxMessages: config.memory.maxMessages,\n includeToolCalls: config.memory.includeToolCalls,\n maxFullToolResults: config.memory.maxFullToolResults,\n debugMode: config.memory.debugMode,\n })\n console.log(`${PREFIX} === End Plugin Initialization ===`)\n }\n\n logAgentDebugInfo(\n aiAgentArgs: AiAgentArgs,\n toolNames: string[],\n messages: AgenticInputMessage[]\n ): void {\n console.log(`${PREFIX} === AI Agent Debug Info ===`)\n console.log(`${PREFIX} Agent Name: ${aiAgentArgs.name}`)\n console.log(`${PREFIX} Active Tools: ${JSON.stringify(toolNames)}`)\n if (aiAgentArgs.type === AiAgentType.Specialist) {\n console.log(\n `${PREFIX} Source IDs: ${JSON.stringify(aiAgentArgs.sourceIds || [])}`\n )\n }\n console.log(`${PREFIX} Message History Count: ${messages.length}`)\n console.log(`${PREFIX} Messages: ${JSON.stringify(messages, null, 2)}`)\n console.log(\n `${PREFIX} Input Guardrail Rules: ${aiAgentArgs.inputGuardrailRules?.length || 0}`\n )\n console.log(`${PREFIX} === End Debug Info ===`)\n }\n\n logModelSettings(settings: ModelSettingsInfo): void {\n console.log(`${PREFIX} === Agent Model Settings ===`)\n console.log(\n `${PREFIX} Has Retrieve Knowledge Tool: ${settings.hasRetrieveKnowledge}`\n )\n if (settings.reasoning) {\n console.log(`${PREFIX} Reasoning Effort: ${settings.reasoning.effort}`)\n }\n if (settings.text) {\n console.log(`${PREFIX} Text Verbosity: ${settings.text.verbosity}`)\n }\n if (settings.toolChoice) {\n console.log(`${PREFIX} Tool Choice: ${settings.toolChoice}`)\n }\n console.log(`${PREFIX} === End Model Settings ===`)\n }\n\n logRunnerStart(\n model: string,\n modelSettings: ModelSettings,\n prompt: string\n ): void {\n console.log(`${PREFIX} === Runner Execution Start ===`)\n console.log(`${PREFIX} Model: ${model}`)\n console.log(`${PREFIX} Model Settings: ${JSON.stringify(modelSettings)}`)\n console.log(`${PREFIX} Prompt: ${prompt}`)\n }\n\n logRunResult(runResult: RunResult, startTime: number): void {\n const elapsedMs = Date.now() - startTime\n\n console.log(`${PREFIX} === Runner Execution Complete ===`)\n console.log(`${PREFIX} Execution Time: ${elapsedMs}ms`)\n console.log(`${PREFIX} Output Messages Count: ${runResult.messages.length}`)\n console.log(`${PREFIX} Exit: ${runResult.exit}`)\n console.log(`${PREFIX} Error: ${runResult.error}`)\n console.log(\n `${PREFIX} Tools Executed: ${JSON.stringify(runResult.toolsExecuted.map(t => t.toolName))}`\n )\n if (runResult.inputGuardrailsTriggered.length > 0) {\n console.log(\n `${PREFIX} Input Guardrails Triggered: ${runResult.inputGuardrailsTriggered.length}`\n )\n }\n if (runResult.outputGuardrailsTriggered.length > 0) {\n console.log(\n `${PREFIX} Output Guardrails Triggered: ${runResult.outputGuardrailsTriggered.length}`\n )\n }\n console.log(`${PREFIX} === End Runner Execution ===`)\n }\n\n logGuardrailTriggered(): void {\n console.log(`${PREFIX} Input guardrail triggered`)\n }\n\n logRunnerError(startTime: number, error: unknown): void {\n const elapsedMs = Date.now() - startTime\n console.log(`${PREFIX} Runner execution failed after ${elapsedMs}ms`)\n console.log(`${PREFIX} Error:`, error)\n }\n\n logToolExecution(toolExecution: ToolExecution): void {\n console.log(`${PREFIX} Tool Execution: ${toolExecution.toolName}`)\n console.log(\n `${PREFIX} Tool Arguments: ${JSON.stringify(toolExecution.toolArguments)}`\n )\n console.log(`${PREFIX} Tool Results: ${toolExecution.toolResults}`)\n console.log(\n `${PREFIX} Knowledgebase Sources IDs: ${JSON.stringify(toolExecution.knowledgebaseSourcesIds)}`\n )\n console.log(\n `${PREFIX} Knowledgebase Chunks IDs: ${JSON.stringify(toolExecution.knowledgebaseChunksIds)}`\n )\n }\n}\n\nclass DisabledDebugLogger implements DebugLogger {\n logInitialConfig(): void {\n return\n }\n logAgentDebugInfo(): void {\n return\n }\n logModelSettings(): void {\n return\n }\n logRunnerStart(\n _model: string,\n _modelSettings: ModelSettings,\n _prompt: string\n ): void {\n return\n }\n logRunResult(): void {\n return\n }\n logGuardrailTriggered(): void {\n return\n }\n logRunnerError(): void {\n return\n }\n logToolExecution(): void {\n return\n }\n}\n\nexport function createDebugLogger(enableDebug: boolean): DebugLogger {\n return enableDebug ? new EnabledDebugLogger() : new DisabledDebugLogger()\n}\n"],"names":["AiAgentType","LLM_PROVIDER","PREFIX","EnabledDebugLogger","config","console","aiAgentArgs","toolNames","messages","JSON","settings","model","modelSettings","prompt","runResult","startTime","elapsedMs","Date","t","error","toolExecution","DisabledDebugLogger","_model","_modelSettings","_prompt","createDebugLogger","enableDebug"],"mappings":";;;;;AAIsB;AAEoB;AAG1C,MAAME,MAAMA,GAAG;AAsCf,MAAMC,kBAAkBA;IACtB,iBAAiBC,MAAyB,EAAQ;QAChDC,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,8BAA8B,CAAC;QACrDG,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,WAAW,EAAED,YAAYA,EAAE;QACjDI,QAAQ,GAAG,CACT,GAAGH,MAAMA,CAAC,8BAA8B,EAAEE,OAAO,wBAAwB,EAAE;QAE7EC,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,cAAc,EAAEE,OAAO,UAAU,EAAE;QACzDC,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,UAAU,EAAEE,OAAO,OAAO,CAAC,EAAE,CAAC;QACpDC,QAAQ,GAAG,CACT,GAAGH,MAAMA,CAAC,0BAA0B,EAAEE,OAAO,eAAe,CAAC,IAAI,CAAC,SAAS,QAAQ;QAErFC,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,gBAAgB,CAAC,EAAE;YACvC,aAAaE,OAAO,MAAM,CAAC,WAAW;YACtC,kBAAkBA,OAAO,MAAM,CAAC,gBAAgB;YAChD,oBAAoBA,OAAO,MAAM,CAAC,kBAAkB;YACpD,WAAWA,OAAO,MAAM,CAAC,SAAS;QACpC;QACAC,QAAQ,GAAG,CAAC,GAAGH,MAAMA,CAAC,kCAAkC,CAAC;IAC3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e,EACT;QACN;IACF;IACA,eAAqB;QACnB;IACF;IACA,wBAA8B;QAC5B;IACF;IACA,iBAAuB;QACrB;IACF;IACA,mBAAyB;QACvB;IACF;AACF;AAEO,SAASC,iBAAiBA,CAACC,WAAoB;IACpD,OAAOA,cAAc,IAAIvB,kBAAkBA,KAAK,IAAIkB,mBAAmBA;AACzE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './input.js';
|
package/lib/guardrails/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guardrails/index.js","sources":["../../src/guardrails/index.ts"],"sourcesContent":["export * from './input'\n"],"names":[],"mappings":";AAAuB"}
|