@botonic/plugin-ai-agents 0.46.1 → 2.23.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/CHANGELOG.md +209 -0
- 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/esm → 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/README.md +0 -156
- 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 +0 -97
- 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.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
package/lib/cjs/runner.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AIAgentRunner = void 0;
|
|
4
|
-
const agents_1 = require("@openai/agents");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
const hubtype_api_client_1 = require("./services/hubtype-api-client");
|
|
7
|
-
const types_1 = require("./services/types");
|
|
8
|
-
const tools_1 = require("./tools");
|
|
9
|
-
class AIAgentRunner {
|
|
10
|
-
constructor(agent, openAiClient, inferenceId, logger) {
|
|
11
|
-
this.agent = agent;
|
|
12
|
-
this.llmConfig = openAiClient;
|
|
13
|
-
this.inferenceId = inferenceId;
|
|
14
|
-
this.logger = logger;
|
|
15
|
-
}
|
|
16
|
-
async run(messages, context) {
|
|
17
|
-
const startTime = Date.now();
|
|
18
|
-
this.logger.logRunnerStart(this.llmConfig.modelName, this.llmConfig.modelSettings);
|
|
19
|
-
try {
|
|
20
|
-
const modelProvider = this.llmConfig.modelProvider;
|
|
21
|
-
const modelSettings = this.llmConfig.modelSettings;
|
|
22
|
-
const hasRetrieveKnowledge = this.agent.tools.includes(tools_1.retrieveKnowledge);
|
|
23
|
-
if (hasRetrieveKnowledge && constants_1.OPENAI_PROVIDER === 'azure') {
|
|
24
|
-
modelSettings.toolChoice = tools_1.retrieveKnowledge.name;
|
|
25
|
-
}
|
|
26
|
-
const runner = new agents_1.Runner({
|
|
27
|
-
modelSettings,
|
|
28
|
-
modelProvider,
|
|
29
|
-
tracingDisabled: true,
|
|
30
|
-
});
|
|
31
|
-
// Type assertion to bypass strict type checking - the actual return type from runner.run()
|
|
32
|
-
// doesn't perfectly match our interface, but the properties we access are compatible
|
|
33
|
-
const result = (await runner.run(this.agent, messages, {
|
|
34
|
-
context,
|
|
35
|
-
}));
|
|
36
|
-
const endTime = Date.now();
|
|
37
|
-
void this.sendLlmRunTracking(result, context, startTime, endTime);
|
|
38
|
-
const { _context, ...restResult } = result.state;
|
|
39
|
-
console.log('Runner result:', restResult);
|
|
40
|
-
const outputMessages = result.finalOutput?.messages || [];
|
|
41
|
-
const hasExit = outputMessages.length === 0 ||
|
|
42
|
-
outputMessages.some(message => message.type === 'exit');
|
|
43
|
-
const toolsExecuted = this.getToolsExecuted(result, context);
|
|
44
|
-
const runResult = {
|
|
45
|
-
messages: hasExit
|
|
46
|
-
? []
|
|
47
|
-
: outputMessages.filter(message => message.type !== 'exit'),
|
|
48
|
-
toolsExecuted,
|
|
49
|
-
exit: hasExit,
|
|
50
|
-
memoryLength: messages.length,
|
|
51
|
-
error: false,
|
|
52
|
-
inputGuardrailsTriggered: [],
|
|
53
|
-
outputGuardrailsTriggered: [],
|
|
54
|
-
};
|
|
55
|
-
this.logger.logRunResult(runResult, startTime);
|
|
56
|
-
return runResult;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
if (error instanceof agents_1.InputGuardrailTripwireTriggered) {
|
|
60
|
-
const runResult = {
|
|
61
|
-
messages: [],
|
|
62
|
-
memoryLength: 0,
|
|
63
|
-
toolsExecuted: [],
|
|
64
|
-
exit: true,
|
|
65
|
-
error: false,
|
|
66
|
-
inputGuardrailsTriggered: error.result.output.outputInfo,
|
|
67
|
-
outputGuardrailsTriggered: [],
|
|
68
|
-
};
|
|
69
|
-
this.logger.logGuardrailTriggered();
|
|
70
|
-
this.logger.logRunResult(runResult, startTime);
|
|
71
|
-
return runResult;
|
|
72
|
-
}
|
|
73
|
-
this.logger.logRunnerError(startTime, error);
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async sendLlmRunTracking(result, context, startTime, endTime) {
|
|
78
|
-
if (!constants_1.isProd) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const rawResponses = result.rawResponses ?? [];
|
|
82
|
-
if (rawResponses.length === 0) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const botId = context.request.session.bot.id;
|
|
86
|
-
const isTest = context.request.session.is_test_integration;
|
|
87
|
-
const totalDuration = endTime - startTime;
|
|
88
|
-
const durationPerCall = Math.round(totalDuration / rawResponses.length);
|
|
89
|
-
const temperature = this.llmConfig.modelSettings.temperature ?? 0;
|
|
90
|
-
const apiVersion = constants_1.OPENAI_PROVIDER === 'azure' ? constants_1.AZURE_OPENAI_API_VERSION : '';
|
|
91
|
-
const llmRuns = rawResponses.map(response => ({
|
|
92
|
-
inference_id: this.inferenceId,
|
|
93
|
-
is_test: isTest,
|
|
94
|
-
product_name: types_1.TrackProductName.AI_AGENT,
|
|
95
|
-
deployment_name: this.llmConfig.modelName,
|
|
96
|
-
model_name: response.providerData?.['model'] ??
|
|
97
|
-
this.llmConfig.modelName,
|
|
98
|
-
feature: types_1.TrackFeature.AI_AGENT_RUN,
|
|
99
|
-
api_version: apiVersion,
|
|
100
|
-
num_prompt_tokens: response.usage.inputTokens,
|
|
101
|
-
num_completion_tokens: response.usage.outputTokens,
|
|
102
|
-
duration_in_milliseconds: durationPerCall,
|
|
103
|
-
temperature,
|
|
104
|
-
error: null,
|
|
105
|
-
}));
|
|
106
|
-
const client = new hubtype_api_client_1.HubtypeApiClient(context.authToken);
|
|
107
|
-
await client.trackLlmRuns(botId, {
|
|
108
|
-
llm_runs: llmRuns,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
getToolsExecuted(result, context) {
|
|
112
|
-
const toolResultsByCallId = this.getToolResultsByCallId(result.newItems);
|
|
113
|
-
return (result.newItems
|
|
114
|
-
?.filter(item => item instanceof agents_1.RunToolCallItem)
|
|
115
|
-
.map((item) => this.getToolExecutionInfo(item, context, toolResultsByCallId))
|
|
116
|
-
.filter((toolExecution) => toolExecution.toolName !== '') || []);
|
|
117
|
-
}
|
|
118
|
-
getToolResultsByCallId(newItems) {
|
|
119
|
-
const map = new Map();
|
|
120
|
-
for (const item of newItems || []) {
|
|
121
|
-
if (!(item instanceof agents_1.RunToolCallOutputItem)) {
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
const rawItem = item.rawItem;
|
|
125
|
-
const callId = rawItem?.callId;
|
|
126
|
-
const output = rawItem?.output;
|
|
127
|
-
if (callId == null || output == null) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
const text = this.extractToolResult(output);
|
|
131
|
-
if (text != null) {
|
|
132
|
-
map.set(callId, text);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return map;
|
|
136
|
-
}
|
|
137
|
-
extractToolResult(output) {
|
|
138
|
-
if (typeof output === 'string') {
|
|
139
|
-
return output;
|
|
140
|
-
}
|
|
141
|
-
return output?.type === 'text' && typeof output?.text === 'string'
|
|
142
|
-
? output.text
|
|
143
|
-
: undefined;
|
|
144
|
-
}
|
|
145
|
-
getToolExecutionInfo(item, context, toolResultsByCallId) {
|
|
146
|
-
if (item.rawItem.type !== 'function_call') {
|
|
147
|
-
return {
|
|
148
|
-
toolName: '',
|
|
149
|
-
toolArguments: {},
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
const toolName = item.rawItem.name;
|
|
153
|
-
const toolArguments = this.getSafeToolArguments(item.rawItem.arguments);
|
|
154
|
-
const toolResults = item.rawItem.callId
|
|
155
|
-
? toolResultsByCallId.get(item.rawItem.callId)
|
|
156
|
-
: undefined;
|
|
157
|
-
const toolExecution = {
|
|
158
|
-
toolName,
|
|
159
|
-
toolArguments,
|
|
160
|
-
toolResults,
|
|
161
|
-
};
|
|
162
|
-
if (toolName === tools_1.retrieveKnowledge.name) {
|
|
163
|
-
return {
|
|
164
|
-
...toolExecution,
|
|
165
|
-
knowledgebaseSourcesIds: context.knowledgeUsed.sourceIds,
|
|
166
|
-
knowledgebaseChunksIds: context.knowledgeUsed.chunksIds,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
return toolExecution;
|
|
170
|
-
}
|
|
171
|
-
getSafeToolArguments(rawToolArguments) {
|
|
172
|
-
try {
|
|
173
|
-
return JSON.parse(rawToolArguments);
|
|
174
|
-
}
|
|
175
|
-
catch (_error) {
|
|
176
|
-
return {};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
exports.AIAgentRunner = AIAgentRunner;
|
|
181
|
-
//# sourceMappingURL=runner.js.map
|
package/lib/cjs/runner.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":";;;AAKA,2CAKuB;AACvB,2CAA+E;AAG/E,sEAAgE;AAChE,4CAAiE;AACjE,mCAA2C;AAsB3C,MAAa,aAAa;IASxB,YACE,KAAoC,EACpC,YAAuB,EACvB,WAAmB,EACnB,MAAmB;QAEnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,SAAS,GAAG,YAAY,CAAA;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,GAAG,CACP,QAA+B,EAC/B,OAAsC;QAEtC,MAAM,SAAS,GAAG,IAAI,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,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;aACxD,CAAA;QACH,CAAC;QAED,OAAO,aAAa,CAAA;IACtB,CAAC;IAEO,oBAAoB,CAAC,gBAAwB;QACnD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;QACrC,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YAChB,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;CACF;AAxPD,sCAwPC"}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HubtypeApiClient = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
-
const constants_1 = require("../constants");
|
|
7
|
-
class HubtypeApiClient {
|
|
8
|
-
constructor(authToken) {
|
|
9
|
-
this.authToken = authToken;
|
|
10
|
-
}
|
|
11
|
-
async retrieveSimilarChunks(query, sourceIds) {
|
|
12
|
-
const url = `${constants_1.HUBTYPE_API_URL}/external/v1/ai/knowledge_base/similar_chunks/`;
|
|
13
|
-
const headers = {
|
|
14
|
-
'Content-Type': 'application/json',
|
|
15
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
16
|
-
};
|
|
17
|
-
const params = {
|
|
18
|
-
query,
|
|
19
|
-
source_ids: sourceIds,
|
|
20
|
-
num_chunks: 5,
|
|
21
|
-
};
|
|
22
|
-
const response = await axios_1.default.post(url, params, { headers });
|
|
23
|
-
const chunks = response.data.chunks.map((chunk) => ({
|
|
24
|
-
id: chunk.id,
|
|
25
|
-
text: chunk.text,
|
|
26
|
-
}));
|
|
27
|
-
return chunks;
|
|
28
|
-
}
|
|
29
|
-
async getLocalMessages(maxMemoryLength) {
|
|
30
|
-
const localBotonicState = typeof globalThis !== 'undefined' && globalThis.localStorage
|
|
31
|
-
? globalThis.localStorage.getItem('botonicState')
|
|
32
|
-
: null;
|
|
33
|
-
const botonicState = JSON.parse(localBotonicState || '{}');
|
|
34
|
-
const messages = botonicState.messages;
|
|
35
|
-
const filteredMessages = messages
|
|
36
|
-
.filter(message => message.data.text)
|
|
37
|
-
.map(message => ({
|
|
38
|
-
role: message.sentBy === 'user' ? 'user' : 'assistant',
|
|
39
|
-
content: message.data.text,
|
|
40
|
-
}))
|
|
41
|
-
.map(message => this.formatMessage(message));
|
|
42
|
-
return filteredMessages.slice(-maxMemoryLength);
|
|
43
|
-
}
|
|
44
|
-
async getMessages(botContext, maxMemoryLength) {
|
|
45
|
-
const url = `${constants_1.HUBTYPE_API_URL}/external/v1/ai/agent/message_history/`;
|
|
46
|
-
const headers = {
|
|
47
|
-
'Content-Type': 'application/json',
|
|
48
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
49
|
-
};
|
|
50
|
-
const params = {
|
|
51
|
-
last_message_id: botContext.input.message_id,
|
|
52
|
-
num_messages: maxMemoryLength,
|
|
53
|
-
};
|
|
54
|
-
try {
|
|
55
|
-
const response = await axios_1.default.get(url, {
|
|
56
|
-
headers,
|
|
57
|
-
params,
|
|
58
|
-
});
|
|
59
|
-
const messages = response.data.messages;
|
|
60
|
-
return messages.map(message => this.formatMessage(message));
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
console.error(error);
|
|
64
|
-
throw new Error('Failed to get messages from Hubtype');
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async getMessagesV2(botContext, options = {}) {
|
|
68
|
-
const url = `${constants_1.HUBTYPE_API_URL}/external/v2/ai/agent/message_history/`;
|
|
69
|
-
const headers = {
|
|
70
|
-
'Content-Type': 'application/json',
|
|
71
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
72
|
-
};
|
|
73
|
-
const params = {
|
|
74
|
-
last_message_id: botContext.input.message_id,
|
|
75
|
-
...(options.maxMessages !== undefined && {
|
|
76
|
-
max_messages: options.maxMessages,
|
|
77
|
-
}),
|
|
78
|
-
...(options.includeToolCalls !== undefined && {
|
|
79
|
-
include_tool_calls: options.includeToolCalls,
|
|
80
|
-
}),
|
|
81
|
-
...(options.maxFullToolResults !== undefined && {
|
|
82
|
-
max_full_tool_results: options.maxFullToolResults,
|
|
83
|
-
}),
|
|
84
|
-
...(options.debugMode !== undefined && {
|
|
85
|
-
debug_mode: options.debugMode,
|
|
86
|
-
}),
|
|
87
|
-
};
|
|
88
|
-
try {
|
|
89
|
-
const response = await axios_1.default.get(url, {
|
|
90
|
-
headers,
|
|
91
|
-
params,
|
|
92
|
-
});
|
|
93
|
-
const { messages, conversation_id, truncated } = response.data;
|
|
94
|
-
const formattedMessages = messages
|
|
95
|
-
.map(message => this.formatMessageV2(message))
|
|
96
|
-
.filter((message) => message !== null);
|
|
97
|
-
return {
|
|
98
|
-
messages: formattedMessages,
|
|
99
|
-
conversationId: conversation_id,
|
|
100
|
-
truncated,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
console.error(error);
|
|
105
|
-
throw new Error('Failed to get messages from Hubtype V2 API');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
formatMessageV2(message) {
|
|
109
|
-
switch (message.role) {
|
|
110
|
-
case 'user':
|
|
111
|
-
return {
|
|
112
|
-
role: 'user',
|
|
113
|
-
content: message.content ?? '',
|
|
114
|
-
};
|
|
115
|
-
case 'assistant': {
|
|
116
|
-
const assistantMessage = message;
|
|
117
|
-
// If assistant message has tool_calls, include them for context
|
|
118
|
-
// Using double assertion as the OpenAI API supports this format,
|
|
119
|
-
// but the agents SDK types are more restrictive
|
|
120
|
-
if (assistantMessage.tool_calls &&
|
|
121
|
-
assistantMessage.tool_calls.length > 0) {
|
|
122
|
-
return {
|
|
123
|
-
role: 'assistant',
|
|
124
|
-
content: assistantMessage.content ?? '',
|
|
125
|
-
tool_calls: assistantMessage.tool_calls.map(tc => ({
|
|
126
|
-
id: tc.id,
|
|
127
|
-
type: tc.type,
|
|
128
|
-
function: {
|
|
129
|
-
name: tc.function.name,
|
|
130
|
-
arguments: tc.function.arguments,
|
|
131
|
-
},
|
|
132
|
-
})),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
// Regular assistant message without tool_calls
|
|
136
|
-
return {
|
|
137
|
-
role: 'assistant',
|
|
138
|
-
content: [
|
|
139
|
-
{
|
|
140
|
-
type: 'output_text',
|
|
141
|
-
text: assistantMessage.content ?? '',
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
status: 'completed',
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
case 'tool': {
|
|
148
|
-
// Tool messages provide context about previous tool executions
|
|
149
|
-
// Using double assertion as the OpenAI API supports this format,
|
|
150
|
-
// but the agents SDK types are more restrictive
|
|
151
|
-
const toolMessage = message;
|
|
152
|
-
return {
|
|
153
|
-
role: 'tool',
|
|
154
|
-
tool_call_id: toolMessage.tool_call_id,
|
|
155
|
-
content: toolMessage.content ?? '',
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
case 'system':
|
|
159
|
-
return {
|
|
160
|
-
role: 'system',
|
|
161
|
-
content: message.content ?? '',
|
|
162
|
-
};
|
|
163
|
-
default:
|
|
164
|
-
throw new Error(`Invalid message role: ${message.role}`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
async trackLlmRuns(botId, data) {
|
|
168
|
-
// Not stop the bot execution if the tracking fails, just log the error
|
|
169
|
-
try {
|
|
170
|
-
const url = `${constants_1.HUBTYPE_API_URL}/external/v2/conversational_apps/${botId}/track_llm_runs/`;
|
|
171
|
-
const headers = {
|
|
172
|
-
'Content-Type': 'application/json',
|
|
173
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
174
|
-
};
|
|
175
|
-
await axios_1.default.post(url, data, { headers });
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
console.error('Failed to track LLM runs:', error);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
formatMessage(message) {
|
|
182
|
-
if (message.role === 'user') {
|
|
183
|
-
return {
|
|
184
|
-
content: message.content,
|
|
185
|
-
role: 'user',
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
else if (message.role === 'assistant') {
|
|
189
|
-
return {
|
|
190
|
-
role: 'assistant',
|
|
191
|
-
content: [
|
|
192
|
-
{
|
|
193
|
-
type: 'output_text',
|
|
194
|
-
text: message.content,
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
status: 'completed',
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
throw new Error('Invalid message role');
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
exports.HubtypeApiClient = HubtypeApiClient;
|
|
206
|
-
//# sourceMappingURL=hubtype-api-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-api-client.js","sourceRoot":"","sources":["../../../src/services/hubtype-api-client.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AAEzB,4CAA8C;AAc9C,MAAa,gBAAgB;IAG3B,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAED,KAAK,CAAC,qBAAqB,CACzB,KAAa,EACb,SAAmB;QAEnB,MAAM,GAAG,GAAG,GAAG,2BAAe,gDAAgD,CAAA;QAC9E,MAAM,OAAO,GAAG;YACd,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;SAC1C,CAAA;QACD,MAAM,MAAM,GAAG;YACb,KAAK;YACL,UAAU,EAAE,SAAS;YACrB,UAAU,EAAE,CAAC;SACd,CAAA;QACD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;QAC3D,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAA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aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,EAAE;aAC1C,CAAA;YACD,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAEO,aAAa,CAAC,OAAuB;QAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,OAAO;gBACL,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,MAAM;aACb,CAAA;QACH,CAAC;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACxC,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,aAAa;wBACnB,IAAI,EAAE,OAAO,CAAC,OAAO;qBACtB;iBACF;gBACD,MAAM,EAAE,WAAW;aACpB,CAAA;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;CACF;AA7ND,4CA6NC"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { AgenticInputMessage } from '../types';
|
|
2
|
-
export declare enum TrackProductName {
|
|
3
|
-
AI_AGENT = "ai_agent"
|
|
4
|
-
}
|
|
5
|
-
export declare enum TrackFeature {
|
|
6
|
-
AI_AGENT_RUN = "ai_agent_run",
|
|
7
|
-
AI_AGENT_GUARDRAIL = "ai_agent_guardrail"
|
|
8
|
-
}
|
|
9
|
-
export interface LlmRunData {
|
|
10
|
-
inference_id: string;
|
|
11
|
-
is_test: boolean;
|
|
12
|
-
product_name: string;
|
|
13
|
-
deployment_name: string;
|
|
14
|
-
model_name: string;
|
|
15
|
-
feature: string;
|
|
16
|
-
api_version: string;
|
|
17
|
-
num_prompt_tokens: number;
|
|
18
|
-
num_completion_tokens: number;
|
|
19
|
-
duration_in_milliseconds: number;
|
|
20
|
-
temperature: number;
|
|
21
|
-
error: string | null;
|
|
22
|
-
}
|
|
23
|
-
export interface TrackLlmRunsData {
|
|
24
|
-
llm_runs: LlmRunData[];
|
|
25
|
-
}
|
|
26
|
-
interface HubtypeAssistantMessage {
|
|
27
|
-
role: 'assistant';
|
|
28
|
-
content: string;
|
|
29
|
-
}
|
|
30
|
-
interface HubtypeUserMessage {
|
|
31
|
-
role: 'user';
|
|
32
|
-
content: string;
|
|
33
|
-
}
|
|
34
|
-
export type HubtypeMessage = HubtypeAssistantMessage | HubtypeUserMessage;
|
|
35
|
-
interface HubtypeToolCall {
|
|
36
|
-
id: string;
|
|
37
|
-
type: 'function';
|
|
38
|
-
function: {
|
|
39
|
-
name: string;
|
|
40
|
-
arguments: string;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
interface HubtypeUserMessageV2 {
|
|
44
|
-
role: 'user';
|
|
45
|
-
content: string | null;
|
|
46
|
-
}
|
|
47
|
-
export interface HubtypeAssistantMessageV2 {
|
|
48
|
-
role: 'assistant';
|
|
49
|
-
content: string | null;
|
|
50
|
-
tool_calls?: HubtypeToolCall[] | null;
|
|
51
|
-
}
|
|
52
|
-
export interface HubtypeToolMessageV2 {
|
|
53
|
-
role: 'tool';
|
|
54
|
-
content: string | null;
|
|
55
|
-
tool_call_id: string;
|
|
56
|
-
}
|
|
57
|
-
interface HubtypeSystemMessageV2 {
|
|
58
|
-
role: 'system';
|
|
59
|
-
content: string | null;
|
|
60
|
-
}
|
|
61
|
-
export type HubtypeMessageV2 = HubtypeUserMessageV2 | HubtypeAssistantMessageV2 | HubtypeToolMessageV2 | HubtypeSystemMessageV2;
|
|
62
|
-
export interface MessageHistoryResponseV2 {
|
|
63
|
-
messages: HubtypeMessageV2[];
|
|
64
|
-
conversation_id: string | null;
|
|
65
|
-
truncated: boolean;
|
|
66
|
-
}
|
|
67
|
-
export interface GetMessagesV2Options {
|
|
68
|
-
maxMessages?: number;
|
|
69
|
-
includeToolCalls?: boolean;
|
|
70
|
-
maxFullToolResults?: number;
|
|
71
|
-
debugMode?: boolean;
|
|
72
|
-
}
|
|
73
|
-
export interface GetMessagesV2Result {
|
|
74
|
-
messages: AgenticInputMessage[];
|
|
75
|
-
conversationId: string | null;
|
|
76
|
-
truncated: boolean;
|
|
77
|
-
}
|
|
78
|
-
export interface MessageHistoryV2Params {
|
|
79
|
-
last_message_id: string;
|
|
80
|
-
max_messages?: number;
|
|
81
|
-
include_tool_calls?: boolean;
|
|
82
|
-
max_full_tool_results?: number;
|
|
83
|
-
debug_mode?: boolean;
|
|
84
|
-
}
|
|
85
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TrackFeature = exports.TrackProductName = void 0;
|
|
4
|
-
var TrackProductName;
|
|
5
|
-
(function (TrackProductName) {
|
|
6
|
-
TrackProductName["AI_AGENT"] = "ai_agent";
|
|
7
|
-
})(TrackProductName || (exports.TrackProductName = TrackProductName = {}));
|
|
8
|
-
var TrackFeature;
|
|
9
|
-
(function (TrackFeature) {
|
|
10
|
-
TrackFeature["AI_AGENT_RUN"] = "ai_agent_run";
|
|
11
|
-
TrackFeature["AI_AGENT_GUARDRAIL"] = "ai_agent_guardrail";
|
|
12
|
-
})(TrackFeature || (exports.TrackFeature = TrackFeature = {}));
|
|
13
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/services/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,gBAEX;AAFD,WAAY,gBAAgB;IAC1B,yCAAqB,CAAA;AACvB,CAAC,EAFW,gBAAgB,gCAAhB,gBAAgB,QAE3B;AAED,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,6CAA6B,CAAA;IAC7B,yDAAyC,CAAA;AAC3C,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { BotExecutorMessage } from '@botonic/core';
|
|
2
|
-
import z from 'zod';
|
|
3
|
-
export type { BotExecutorMessage };
|
|
4
|
-
export declare const BotExecutorSchema: z.ZodObject<{
|
|
5
|
-
type: z.ZodEnum<["botExecutor"]>;
|
|
6
|
-
content: z.ZodObject<{
|
|
7
|
-
text: z.ZodString;
|
|
8
|
-
buttons: z.ZodArray<z.ZodObject<{
|
|
9
|
-
text: z.ZodString;
|
|
10
|
-
payload: z.ZodString;
|
|
11
|
-
}, "strip", z.ZodTypeAny, {
|
|
12
|
-
text: string;
|
|
13
|
-
payload: string;
|
|
14
|
-
}, {
|
|
15
|
-
text: string;
|
|
16
|
-
payload: string;
|
|
17
|
-
}>, "many">;
|
|
18
|
-
}, "strip", z.ZodTypeAny, {
|
|
19
|
-
text: string;
|
|
20
|
-
buttons: {
|
|
21
|
-
text: string;
|
|
22
|
-
payload: string;
|
|
23
|
-
}[];
|
|
24
|
-
}, {
|
|
25
|
-
text: string;
|
|
26
|
-
buttons: {
|
|
27
|
-
text: string;
|
|
28
|
-
payload: string;
|
|
29
|
-
}[];
|
|
30
|
-
}>;
|
|
31
|
-
}, "strip", z.ZodTypeAny, {
|
|
32
|
-
type: "botExecutor";
|
|
33
|
-
content: {
|
|
34
|
-
text: string;
|
|
35
|
-
buttons: {
|
|
36
|
-
text: string;
|
|
37
|
-
payload: string;
|
|
38
|
-
}[];
|
|
39
|
-
};
|
|
40
|
-
}, {
|
|
41
|
-
type: "botExecutor";
|
|
42
|
-
content: {
|
|
43
|
-
text: string;
|
|
44
|
-
buttons: {
|
|
45
|
-
text: string;
|
|
46
|
-
payload: string;
|
|
47
|
-
}[];
|
|
48
|
-
};
|
|
49
|
-
}>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BotExecutorSchema = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const zod_1 = tslib_1.__importDefault(require("zod"));
|
|
6
|
-
exports.BotExecutorSchema = zod_1.default
|
|
7
|
-
.object({
|
|
8
|
-
type: zod_1.default.enum(['botExecutor']),
|
|
9
|
-
content: zod_1.default.object({
|
|
10
|
-
text: zod_1.default.string(),
|
|
11
|
-
buttons: zod_1.default.array(zod_1.default.object({
|
|
12
|
-
text: zod_1.default.string(),
|
|
13
|
-
payload: zod_1.default.string(),
|
|
14
|
-
})),
|
|
15
|
-
}),
|
|
16
|
-
})
|
|
17
|
-
.describe('A text message with buttons to allow the bot to execute a specific action. Use it only when asked explicitly in the prompt');
|
|
18
|
-
//# sourceMappingURL=bot-executor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bot-executor.js","sourceRoot":"","sources":["../../../src/structured-output/bot-executor.ts"],"names":[],"mappings":";;;;AACA,sDAAmB;AAIN,QAAA,iBAAiB,GAAG,aAAC;KAC/B,MAAM,CAAC;IACN,IAAI,EAAE,aAAC,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC;IAC7B,OAAO,EAAE,aAAC,CAAC,MAAM,CAAC;QAChB,IAAI,EAAE,aAAC,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,aAAC,CAAC,KAAK,CACd,aAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,aAAC,CAAC,MAAM,EAAE;YAChB,OAAO,EAAE,aAAC,CAAC,MAAM,EAAE;SACpB,CAAC,CACH;KACF,CAAC;CACH,CAAC;KACD,QAAQ,CACP,4HAA4H,CAC7H,CAAA"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import type { CarouselMessage } from '@botonic/core';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
export type { CarouselMessage };
|
|
4
|
-
export declare const CarouselSchema: z.ZodObject<{
|
|
5
|
-
type: z.ZodEnum<["carousel"]>;
|
|
6
|
-
content: z.ZodObject<{
|
|
7
|
-
text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
8
|
-
elements: z.ZodArray<z.ZodObject<{
|
|
9
|
-
title: z.ZodString;
|
|
10
|
-
subtitle: z.ZodString;
|
|
11
|
-
image: z.ZodString;
|
|
12
|
-
button: z.ZodObject<{
|
|
13
|
-
text: z.ZodString;
|
|
14
|
-
url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
15
|
-
}, "strip", z.ZodTypeAny, {
|
|
16
|
-
text: string;
|
|
17
|
-
url?: string | null | undefined;
|
|
18
|
-
}, {
|
|
19
|
-
text: string;
|
|
20
|
-
url?: string | null | undefined;
|
|
21
|
-
}>;
|
|
22
|
-
}, "strip", z.ZodTypeAny, {
|
|
23
|
-
title: string;
|
|
24
|
-
subtitle: string;
|
|
25
|
-
image: string;
|
|
26
|
-
button: {
|
|
27
|
-
text: string;
|
|
28
|
-
url?: string | null | undefined;
|
|
29
|
-
};
|
|
30
|
-
}, {
|
|
31
|
-
title: string;
|
|
32
|
-
subtitle: string;
|
|
33
|
-
image: string;
|
|
34
|
-
button: {
|
|
35
|
-
text: string;
|
|
36
|
-
url?: string | null | undefined;
|
|
37
|
-
};
|
|
38
|
-
}>, "many">;
|
|
39
|
-
}, "strip", z.ZodTypeAny, {
|
|
40
|
-
elements: {
|
|
41
|
-
title: string;
|
|
42
|
-
subtitle: string;
|
|
43
|
-
image: string;
|
|
44
|
-
button: {
|
|
45
|
-
text: string;
|
|
46
|
-
url?: string | null | undefined;
|
|
47
|
-
};
|
|
48
|
-
}[];
|
|
49
|
-
text?: string | null | undefined;
|
|
50
|
-
}, {
|
|
51
|
-
elements: {
|
|
52
|
-
title: string;
|
|
53
|
-
subtitle: string;
|
|
54
|
-
image: string;
|
|
55
|
-
button: {
|
|
56
|
-
text: string;
|
|
57
|
-
url?: string | null | undefined;
|
|
58
|
-
};
|
|
59
|
-
}[];
|
|
60
|
-
text?: string | null | undefined;
|
|
61
|
-
}>;
|
|
62
|
-
}, "strip", z.ZodTypeAny, {
|
|
63
|
-
type: "carousel";
|
|
64
|
-
content: {
|
|
65
|
-
elements: {
|
|
66
|
-
title: string;
|
|
67
|
-
subtitle: string;
|
|
68
|
-
image: string;
|
|
69
|
-
button: {
|
|
70
|
-
text: string;
|
|
71
|
-
url?: string | null | undefined;
|
|
72
|
-
};
|
|
73
|
-
}[];
|
|
74
|
-
text?: string | null | undefined;
|
|
75
|
-
};
|
|
76
|
-
}, {
|
|
77
|
-
type: "carousel";
|
|
78
|
-
content: {
|
|
79
|
-
elements: {
|
|
80
|
-
title: string;
|
|
81
|
-
subtitle: string;
|
|
82
|
-
image: string;
|
|
83
|
-
button: {
|
|
84
|
-
text: string;
|
|
85
|
-
url?: string | null | undefined;
|
|
86
|
-
};
|
|
87
|
-
}[];
|
|
88
|
-
text?: string | null | undefined;
|
|
89
|
-
};
|
|
90
|
-
}>;
|