@botonic/plugin-ai-agents 0.43.0 → 0.44.0-alpha.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/lib/cjs/agent-builder.d.ts +1 -1
- package/lib/cjs/agent-builder.js +8 -7
- package/lib/cjs/agent-builder.js.map +1 -1
- package/lib/cjs/guardrails/input.js +4 -6
- package/lib/cjs/guardrails/input.js.map +1 -1
- package/lib/cjs/hubtype-api-client.js +94 -97
- package/lib/cjs/hubtype-api-client.js.map +1 -1
- package/lib/cjs/index.js +63 -70
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/openai.js +3 -4
- package/lib/cjs/openai.js.map +1 -1
- package/lib/cjs/runner.js +39 -41
- package/lib/cjs/runner.js.map +1 -1
- package/lib/cjs/tools/retrieve-knowledge.js +4 -5
- package/lib/cjs/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/agent-builder.d.ts +1 -1
- package/lib/esm/agent-builder.js +27 -22
- package/lib/esm/agent-builder.js.map +1 -1
- package/lib/esm/constants.js +13 -10
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/guardrails/index.js +4 -1
- package/lib/esm/guardrails/index.js.map +1 -1
- package/lib/esm/guardrails/input.js +11 -9
- package/lib/esm/guardrails/input.js.map +1 -1
- package/lib/esm/hubtype-api-client.js +102 -101
- package/lib/esm/hubtype-api-client.js.map +1 -1
- package/lib/esm/index.js +76 -80
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/openai.js +24 -20
- package/lib/esm/openai.js.map +1 -1
- package/lib/esm/runner.js +47 -45
- package/lib/esm/runner.js.map +1 -1
- package/lib/esm/structured-output/carousel.js +15 -12
- package/lib/esm/structured-output/carousel.js.map +1 -1
- package/lib/esm/structured-output/exit.js +7 -3
- package/lib/esm/structured-output/exit.js.map +1 -1
- package/lib/esm/structured-output/index.js +10 -7
- package/lib/esm/structured-output/index.js.map +1 -1
- package/lib/esm/structured-output/text-with-buttons.js +12 -8
- package/lib/esm/structured-output/text-with-buttons.js.map +1 -1
- package/lib/esm/structured-output/text.js +8 -5
- package/lib/esm/structured-output/text.js.map +1 -1
- package/lib/esm/tools/index.js +6 -2
- package/lib/esm/tools/index.js.map +1 -1
- package/lib/esm/tools/retrieve-knowledge.js +14 -12
- package/lib/esm/tools/retrieve-knowledge.js.map +1 -1
- package/lib/esm/types.js +2 -1
- package/package.json +5 -5
- package/src/agent-builder.ts +12 -8
- package/src/index.ts +2 -3
package/lib/cjs/runner.js
CHANGED
|
@@ -1,60 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AIAgentRunner = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const agents_1 = require("@openai/agents");
|
|
6
5
|
const tools_1 = require("./tools");
|
|
7
6
|
class AIAgentRunner {
|
|
8
7
|
constructor(agent) {
|
|
9
8
|
this.agent = agent;
|
|
10
9
|
}
|
|
11
|
-
run(messages, context) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
10
|
+
async run(messages, context) {
|
|
11
|
+
try {
|
|
12
|
+
const runner = new agents_1.Runner({
|
|
13
|
+
modelSettings: { temperature: 0 },
|
|
14
|
+
});
|
|
15
|
+
// Type assertion to bypass strict type checking - the actual return type from runner.run()
|
|
16
|
+
// doesn't perfectly match our interface, but the properties we access are compatible
|
|
17
|
+
const result = (await runner.run(this.agent, messages, {
|
|
18
|
+
context,
|
|
19
|
+
}));
|
|
20
|
+
const outputMessages = result.finalOutput?.messages || [];
|
|
21
|
+
const hasExit = outputMessages.length === 0 ||
|
|
22
|
+
outputMessages.some(message => message.type === 'exit');
|
|
23
|
+
const toolsExecuted = this.getToolsExecuted(result, context);
|
|
24
|
+
return {
|
|
25
|
+
messages: hasExit
|
|
26
|
+
? []
|
|
27
|
+
: outputMessages.filter(message => message.type !== 'exit'),
|
|
28
|
+
toolsExecuted,
|
|
29
|
+
exit: hasExit,
|
|
30
|
+
memoryLength: messages.length,
|
|
31
|
+
error: false,
|
|
32
|
+
inputGuardrailsTriggered: [],
|
|
33
|
+
outputGuardrailsTriggered: [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error instanceof agents_1.InputGuardrailTripwireTriggered) {
|
|
27
38
|
return {
|
|
28
|
-
messages:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
exit: hasExit,
|
|
33
|
-
memoryLength: messages.length,
|
|
39
|
+
messages: [],
|
|
40
|
+
memoryLength: 0,
|
|
41
|
+
toolsExecuted: [],
|
|
42
|
+
exit: true,
|
|
34
43
|
error: false,
|
|
35
|
-
inputGuardrailsTriggered:
|
|
44
|
+
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
36
45
|
outputGuardrailsTriggered: [],
|
|
37
46
|
};
|
|
38
47
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
messages: [],
|
|
43
|
-
memoryLength: 0,
|
|
44
|
-
toolsExecuted: [],
|
|
45
|
-
exit: true,
|
|
46
|
-
error: false,
|
|
47
|
-
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
48
|
-
outputGuardrailsTriggered: [],
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
54
50
|
}
|
|
55
51
|
getToolsExecuted(result, context) {
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
return (result.newItems
|
|
53
|
+
?.filter(item => item instanceof agents_1.RunToolCallItem)
|
|
54
|
+
.map((item) => this.getToolExecutionInfo(item, context))
|
|
55
|
+
.filter((toolExecution) => toolExecution.toolName !== '') || []);
|
|
58
56
|
}
|
|
59
57
|
getToolExecutionInfo(item, context) {
|
|
60
58
|
if (item.rawItem.type !== 'function_call') {
|
package/lib/cjs/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;AACA,2CAIuB;AAEvB,mCAA2C;AAkB3C,MAAa,aAAa;IAMxB,YAAY,KAAoC;QAC9C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,GAAG,CACP,QAA+B,EAC/B,OAAsC;QAEtC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;gBACxB,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE;aAClC,CAAC,CAAA;YACF,2FAA2F;YAC3F,qFAAqF;YACrF,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE;gBACrD,OAAO;aACR,CAAC,CAAwB,CAAA;YAE1B,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,EAAE,QAAQ,IAAI,EAAE,CAAA;YACzD,MAAM,OAAO,GACX,cAAc,CAAC,MAAM,KAAK,CAAC;gBAC3B,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAA;YACzD,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;YAE5D,OAAO;gBACL,QAAQ,EAAE,OAAO;oBACf,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAE,cAAc,CAAC,MAAM,CACpB,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK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,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QAEvE,IAAI,QAAQ,KAAK,yBAAiB,CAAC,IAAI,EAAE,CAAC;YACxC,OAAO;gBACL,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;AA9GD,sCA8GC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.retrieveKnowledge = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const agents_1 = require("@openai/agents");
|
|
6
5
|
const zod_1 = require("zod");
|
|
7
6
|
const hubtype_api_client_1 = require("../hubtype-api-client");
|
|
@@ -11,15 +10,15 @@ exports.retrieveKnowledge = (0, agents_1.tool)({
|
|
|
11
10
|
parameters: zod_1.z.object({
|
|
12
11
|
query: zod_1.z.string().describe('The query to search the knowledge base for'),
|
|
13
12
|
}),
|
|
14
|
-
execute: (input, runContext) =>
|
|
15
|
-
const context = runContext
|
|
13
|
+
execute: async (input, runContext) => {
|
|
14
|
+
const context = runContext?.context;
|
|
16
15
|
const query = input.query;
|
|
17
16
|
if (!context) {
|
|
18
17
|
throw new Error('Context is required');
|
|
19
18
|
}
|
|
20
19
|
const sourceIds = context.sourceIds;
|
|
21
20
|
const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
|
|
22
|
-
const chunks =
|
|
21
|
+
const chunks = await client.retrieveSimilarChunks(query, sourceIds);
|
|
23
22
|
const chunkTexts = chunks.map(chunk => chunk.text);
|
|
24
23
|
context.knowledgeUsed = {
|
|
25
24
|
query,
|
|
@@ -28,6 +27,6 @@ exports.retrieveKnowledge = (0, agents_1.tool)({
|
|
|
28
27
|
chunkTexts,
|
|
29
28
|
};
|
|
30
29
|
return chunkTexts;
|
|
31
|
-
}
|
|
30
|
+
},
|
|
32
31
|
});
|
|
33
32
|
//# sourceMappingURL=retrieve-knowledge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retrieve-knowledge.js","sourceRoot":"","sources":["../../../src/tools/retrieve-knowledge.ts"],"names":[],"mappings":";;;AAAA,2CAAiD;AACjD,6BAAuB;AAEvB,8DAAwD;AAG3C,QAAA,iBAAiB,GAAG,IAAA,aAAI,EAAC;IACpC,IAAI,EAAE,oBAAoB;IAC1B,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,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QACnC,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,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;CACF,CAAC,CAAA"}
|
|
@@ -4,7 +4,7 @@ interface AIAgentBuilderOptions<TPlugins extends ResolvedPlugins = ResolvedPlugi
|
|
|
4
4
|
name: string;
|
|
5
5
|
instructions: string;
|
|
6
6
|
tools: Tool<TPlugins, TExtraData>[];
|
|
7
|
-
|
|
7
|
+
campaignsContext?: CampaignV2[];
|
|
8
8
|
contactInfo: ContactInfo[];
|
|
9
9
|
inputGuardrailRules: GuardrailRule[];
|
|
10
10
|
sourceIds: string[];
|
package/lib/esm/agent-builder.js
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIAgentBuilder = void 0;
|
|
4
|
+
const agents_1 = require("@openai/agents");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const guardrails_1 = require("./guardrails");
|
|
7
|
+
const structured_output_1 = require("./structured-output");
|
|
8
|
+
const tools_1 = require("./tools");
|
|
9
|
+
class AIAgentBuilder {
|
|
7
10
|
constructor(options) {
|
|
8
11
|
this.name = options.name;
|
|
9
|
-
this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.
|
|
12
|
+
this.instructions = this.addExtraInstructions(options.instructions, options.contactInfo, options.campaignsContext);
|
|
10
13
|
this.tools = this.addHubtypeTools(options.tools, options.sourceIds);
|
|
11
14
|
this.inputGuardrails = [];
|
|
12
15
|
if (options.inputGuardrailRules.length > 0) {
|
|
13
|
-
const inputGuardrail = createInputGuardrail(options.inputGuardrailRules);
|
|
16
|
+
const inputGuardrail = (0, guardrails_1.createInputGuardrail)(options.inputGuardrailRules);
|
|
14
17
|
this.inputGuardrails.push(inputGuardrail);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
build() {
|
|
18
21
|
const modelSettings = {};
|
|
19
|
-
if (OPENAI_PROVIDER === 'openai') {
|
|
20
|
-
// @ts-expect-error - reasoning.effort is valid but we need to update openai and typescript dependencies
|
|
22
|
+
if (constants_1.OPENAI_PROVIDER === 'openai') {
|
|
21
23
|
modelSettings.reasoning = { effort: 'none' };
|
|
22
24
|
modelSettings.text = { verbosity: 'medium' };
|
|
23
25
|
}
|
|
24
|
-
if (this.tools.includes(retrieveKnowledge) && OPENAI_PROVIDER === 'azure') {
|
|
25
|
-
modelSettings.toolChoice = retrieveKnowledge.name;
|
|
26
|
+
if (this.tools.includes(tools_1.retrieveKnowledge) && constants_1.OPENAI_PROVIDER === 'azure') {
|
|
27
|
+
modelSettings.toolChoice = tools_1.retrieveKnowledge.name;
|
|
26
28
|
}
|
|
27
29
|
// When using standard OpenAI API, we need to specify the model
|
|
28
30
|
// Azure OpenAI uses deployment name instead
|
|
29
|
-
const model = OPENAI_PROVIDER === 'openai' ? OPENAI_MODEL : undefined;
|
|
31
|
+
const model = constants_1.OPENAI_PROVIDER === 'openai' ? constants_1.OPENAI_MODEL : undefined;
|
|
30
32
|
// TODO: Improve type safety - replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema>
|
|
31
33
|
// Currently using explicit type parameters to avoid type inference issues where Agent constructor
|
|
32
34
|
// infers ZodObject instead of AgentOutputType<typeof OutputSchema>. The explicit type parameters
|
|
@@ -34,22 +36,22 @@ export class AIAgentBuilder {
|
|
|
34
36
|
// 1. Update @openai/agents package to properly infer AgentOutputType from outputType parameter
|
|
35
37
|
// 2. Replace AgentOutputType<any> with AgentOutputType<typeof OutputSchema> once type system allows
|
|
36
38
|
// 3. Consider updating AIAgent type definition if @openai/agents types change significantly
|
|
37
|
-
return new Agent({
|
|
39
|
+
return new agents_1.Agent({
|
|
38
40
|
name: this.name,
|
|
39
41
|
model,
|
|
40
42
|
instructions: this.instructions,
|
|
41
43
|
tools: this.tools,
|
|
42
|
-
outputType: OutputSchema,
|
|
44
|
+
outputType: structured_output_1.OutputSchema,
|
|
43
45
|
inputGuardrails: this.inputGuardrails,
|
|
44
46
|
outputGuardrails: [],
|
|
45
47
|
modelSettings,
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
|
-
addExtraInstructions(initialInstructions, contactInfo,
|
|
50
|
+
addExtraInstructions(initialInstructions, contactInfo, campaignsContext) {
|
|
49
51
|
const instructions = `<instructions>\n${initialInstructions.trim()}\n</instructions>`;
|
|
50
52
|
const metadataInstructions = this.getMetadataInstructions();
|
|
51
53
|
const contactInfoInstructions = this.getContactInfoInstructions(contactInfo);
|
|
52
|
-
const campaignInstructions = this.getCampaignInstructions(
|
|
54
|
+
const campaignInstructions = this.getCampaignInstructions(campaignsContext);
|
|
53
55
|
const outputInstructions = this.getOutputInstructions();
|
|
54
56
|
return `${instructions}\n\n${metadataInstructions}\n\n${contactInfoInstructions}\n\n${campaignInstructions}\n\n${outputInstructions}`;
|
|
55
57
|
}
|
|
@@ -70,11 +72,13 @@ export class AIAgentBuilder {
|
|
|
70
72
|
const metadata = `Current Date: ${new Date().toISOString()}`;
|
|
71
73
|
return `<metadata>\n${metadata}\n</metadata>`;
|
|
72
74
|
}
|
|
73
|
-
getCampaignInstructions(
|
|
74
|
-
if (!
|
|
75
|
+
getCampaignInstructions(campaignsContext) {
|
|
76
|
+
if (!campaignsContext || campaignsContext.length === 0) {
|
|
75
77
|
return '';
|
|
76
78
|
}
|
|
77
|
-
return
|
|
79
|
+
return campaignsContext
|
|
80
|
+
.map((campaign, index) => `<campaign_context${index + 1}>\n${campaign.agent_context}\n</campaign_context${index + 1}>`)
|
|
81
|
+
.join('\n');
|
|
78
82
|
}
|
|
79
83
|
getOutputInstructions() {
|
|
80
84
|
const example = {
|
|
@@ -91,11 +95,12 @@ export class AIAgentBuilder {
|
|
|
91
95
|
return `<output>\n${output}\n</output>`;
|
|
92
96
|
}
|
|
93
97
|
addHubtypeTools(tools, sourceIds) {
|
|
94
|
-
const hubtypeTools = [...mandatoryTools];
|
|
98
|
+
const hubtypeTools = [...tools_1.mandatoryTools];
|
|
95
99
|
if (sourceIds.length > 0) {
|
|
96
|
-
hubtypeTools.push(retrieveKnowledge);
|
|
100
|
+
hubtypeTools.push(tools_1.retrieveKnowledge);
|
|
97
101
|
}
|
|
98
102
|
return [...hubtypeTools, ...tools];
|
|
99
103
|
}
|
|
100
104
|
}
|
|
105
|
+
exports.AIAgentBuilder = AIAgentBuilder;
|
|
101
106
|
//# sourceMappingURL=agent-builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"agent-builder.js","sourceRoot":"","sources":["../../src/agent-builder.ts"],"names":[],"mappings":";;;AACA,2CAKuB;AAEvB,2CAA2D;AAC3D,6CAAmD;AACnD,2DAAkD;AAClD,mCAA2D;AAgB3D,MAAa,cAAc;IASzB,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,e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AQ,CAAC,aAAa,uBAAuB,KAAK,GAAG,CAAC,GAAG,CAC/F;aACA,IAAI,CAAC,IAAI,CAAC,CAAA;IACf,CAAC;IAEO,qBAAqB;QAC3B,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,kCAAkC;qBACzC;iBACF;aACF;SACF,CAAA;QACD,MAAM,MAAM,GAAG,yIAAyI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAA;QAC7L,OAAO,aAAa,MAAM,aAAa,CAAA;IACzC,CAAC;IAEO,eAAe,CACrB,KAAmC,EACnC,SAAmB;QAEnB,MAAM,YAAY,GAAW,CAAC,GAAG,sBAAc,CAAC,CAAA;QAChD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,yBAAiB,CAAC,CAAA;QACtC,CAAC;QACD,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,KAAK,CAAC,CAAA;IACpC,CAAC;CACF;AApID,wCAoIC"}
|
package/lib/esm/constants.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_MEMORY_LENGTH = exports.isProd = exports.AZURE_OPENAI_API_VERSION = exports.AZURE_OPENAI_API_DEPLOYMENT_NAME = exports.AZURE_OPENAI_API_BASE = exports.AZURE_OPENAI_API_KEY = exports.OPENAI_PROVIDER = exports.OPENAI_MODEL = exports.OPENAI_API_KEY = exports.HUBTYPE_API_URL = void 0;
|
|
4
|
+
exports.HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
|
|
2
5
|
// OpenAI Provider Configuration
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
exports.OPENAI_API_KEY = process.env.OPENAI_API_KEY; // pragma: allowlist secret
|
|
7
|
+
exports.OPENAI_MODEL = process.env.OPENAI_MODEL || 'gpt-4.1-mini';
|
|
8
|
+
exports.OPENAI_PROVIDER = process.env.OPENAI_PROVIDER || 'azure';
|
|
6
9
|
// Azure OpenAI Configuration
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
exports.AZURE_OPENAI_API_KEY = process.env.AZURE_OPENAI_API_KEY; // pragma: allowlist secret
|
|
11
|
+
exports.AZURE_OPENAI_API_BASE = process.env.AZURE_OPENAI_API_BASE;
|
|
12
|
+
exports.AZURE_OPENAI_API_DEPLOYMENT_NAME = process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME || 'gpt-41-mini_p1';
|
|
13
|
+
exports.AZURE_OPENAI_API_VERSION = process.env.AZURE_OPENAI_API_VERSION || '2025-01-01-preview';
|
|
14
|
+
exports.isProd = process.env.NODE_ENV === 'production';
|
|
15
|
+
exports.MAX_MEMORY_LENGTH = 25;
|
|
13
16
|
//# sourceMappingURL=constants.js.map
|
package/lib/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAE1D,gCAAgC;AACnB,QAAA,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAA,CAAC,2BAA2B;AACvE,QAAA,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,cAAc,CAAA;AACzD,QAAA,eAAe,GACzB,OAAO,CAAC,GAAG,CAAC,eAAsC,IAAI,OAAO,CAAA;AAEhE,6BAA6B;AAChB,QAAA,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA,CAAC,2BAA2B;AACnF,QAAA,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAA;AACzD,QAAA,gCAAgC,GAC3C,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,gBAAgB,CAAA;AACrD,QAAA,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,oBAAoB,CAAA;AAEjD,QAAA,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAE9C,QAAA,iBAAiB,GAAG,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/guardrails/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/guardrails/index.ts"],"names":[],"mappings":";;;AAAA,kDAAuB"}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInputGuardrail = createInputGuardrail;
|
|
4
|
+
const agents_1 = require("@openai/agents");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
function createInputGuardrail(rules) {
|
|
7
|
+
const outputType = zod_1.z.object(Object.fromEntries(rules.map(rule => [rule.name, zod_1.z.boolean().describe(rule.description)])));
|
|
8
|
+
const agent = new agents_1.Agent({
|
|
7
9
|
name: 'InputGuardrail',
|
|
8
10
|
instructions: 'Check if the user triggers some of the following guardrails.',
|
|
9
11
|
outputType,
|
|
10
12
|
});
|
|
11
13
|
return {
|
|
12
14
|
name: 'InputGuardrail',
|
|
13
|
-
execute: ({ input, context }) =>
|
|
15
|
+
execute: async ({ input, context }) => {
|
|
14
16
|
const lastMessage = input[input.length - 1];
|
|
15
|
-
const result =
|
|
17
|
+
const result = await (0, agents_1.run)(agent, [lastMessage], { context });
|
|
16
18
|
const finalOutput = result.finalOutput;
|
|
17
19
|
if (finalOutput === undefined) {
|
|
18
20
|
throw new Error('Guardrail agent failed to produce output');
|
|
@@ -23,7 +25,7 @@ export function createInputGuardrail(rules) {
|
|
|
23
25
|
outputInfo: triggeredGuardrails,
|
|
24
26
|
tripwireTriggered: triggered,
|
|
25
27
|
};
|
|
26
|
-
}
|
|
28
|
+
},
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
//# sourceMappingURL=input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/guardrails/input.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/guardrails/input.ts"],"names":[],"mappings":";;AAKA,oDAiCC;AAtCD,2CAA4E;AAC5E,6BAAuB;AAIvB,SAAgB,oBAAoB,CAAC,KAAsB;IACzD,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,CACzB,MAAM,CAAC,WAAW,CAChB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CACvE,CACF,CAAA;IAED,MAAM,KAAK,GAAG,IAAI,cAAK,CAAC;QACtB,IAAI,EAAE,gBAAgB;QACtB,YAAY,EACV,8DAA8D;QAChE,UAAU;KACX,CAAC,CAAA;IAEF,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;YACpC,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAoB,CAAA;YAC9D,MAAM,MAAM,GAAG,MAAM,IAAA,YAAG,EAAC,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