@botpress/runtime 1.3.5 → 1.3.6
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/dist/definition.js +20 -25
- package/dist/definition.js.map +3 -3
- package/dist/internal.js +16 -21
- package/dist/internal.js.map +3 -3
- package/dist/library.js +2 -7
- package/dist/library.js.map +2 -2
- package/dist/runtime/chat/chat.d.ts +161 -3
- package/dist/runtime/chat/chat.d.ts.map +1 -1
- package/dist/runtime/chat/components.d.ts +487 -0
- package/dist/runtime/chat/components.d.ts.map +1 -0
- package/dist/runtime.js +56 -71
- package/dist/runtime.js.map +3 -3
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -48,7 +48,7 @@ var init_define_BUILD = __esm({
|
|
|
48
48
|
var define_PACKAGE_VERSIONS_default;
|
|
49
49
|
var init_define_PACKAGE_VERSIONS = __esm({
|
|
50
50
|
"<define:__PACKAGE_VERSIONS__>"() {
|
|
51
|
-
define_PACKAGE_VERSIONS_default = { runtime: "1.3.
|
|
51
|
+
define_PACKAGE_VERSIONS_default = { runtime: "1.3.6", adk: "not-installed", sdk: "4.17.0", llmz: "0.0.26", zai: "2.1.16", cognitive: "0.1.47" };
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -45404,6 +45404,7 @@ init_define_BUILD();
|
|
|
45404
45404
|
init_define_PACKAGE_VERSIONS();
|
|
45405
45405
|
import {
|
|
45406
45406
|
Chat,
|
|
45407
|
+
DefaultComponents,
|
|
45407
45408
|
isAnyComponent as isAnyComponent2
|
|
45408
45409
|
} from "llmz";
|
|
45409
45410
|
|
|
@@ -45733,9 +45734,6 @@ ${openTag}${inner}${closeTag}
|
|
|
45733
45734
|
\`\`\``;
|
|
45734
45735
|
}
|
|
45735
45736
|
|
|
45736
|
-
// src/runtime/chat/chat.ts
|
|
45737
|
-
import { DefaultComponents } from "llmz";
|
|
45738
|
-
|
|
45739
45737
|
// ../../node_modules/.bun/dedent@1.7.0/node_modules/dedent/dist/dedent.mjs
|
|
45740
45738
|
init_define_BUILD();
|
|
45741
45739
|
init_define_PACKAGE_VERSIONS();
|
|
@@ -45873,45 +45871,10 @@ var Config = {
|
|
|
45873
45871
|
Analysis
|
|
45874
45872
|
};
|
|
45875
45873
|
|
|
45876
|
-
// src/runtime/chat/citations.ts
|
|
45877
|
-
init_define_BUILD();
|
|
45878
|
-
init_define_PACKAGE_VERSIONS();
|
|
45879
|
-
function expandCitationsInObject(obj, citationsManager) {
|
|
45880
|
-
if (typeof obj === "string" && obj.trim().length > 0) {
|
|
45881
|
-
let footer = "";
|
|
45882
|
-
const { cleaned } = citationsManager.extractCitations(obj, (citation) => {
|
|
45883
|
-
footer += `${JSON.stringify(citation.source)}
|
|
45884
|
-
`;
|
|
45885
|
-
return "";
|
|
45886
|
-
}) ?? { cleaned: obj };
|
|
45887
|
-
if (footer) {
|
|
45888
|
-
return `${cleaned}
|
|
45889
|
-
|
|
45890
|
-
${footer}`.trim();
|
|
45891
|
-
}
|
|
45892
|
-
return cleaned.trim();
|
|
45893
|
-
}
|
|
45894
|
-
if (Array.isArray(obj)) {
|
|
45895
|
-
return obj.map(
|
|
45896
|
-
(item) => expandCitationsInObject(item, citationsManager)
|
|
45897
|
-
);
|
|
45898
|
-
}
|
|
45899
|
-
if (obj && typeof obj === "object") {
|
|
45900
|
-
const result = {};
|
|
45901
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
45902
|
-
result[key] = expandCitationsInObject(value, citationsManager);
|
|
45903
|
-
}
|
|
45904
|
-
return result;
|
|
45905
|
-
}
|
|
45906
|
-
return obj;
|
|
45907
|
-
}
|
|
45908
|
-
|
|
45909
45874
|
// src/runtime/chat/chat.ts
|
|
45910
|
-
var OutgoingMessages = Object.values(DefaultComponents);
|
|
45911
45875
|
var BotpressChat = class extends Chat {
|
|
45912
45876
|
_transcript;
|
|
45913
45877
|
client;
|
|
45914
|
-
cognitive;
|
|
45915
45878
|
conversation;
|
|
45916
45879
|
botId;
|
|
45917
45880
|
logger;
|
|
@@ -45923,14 +45886,20 @@ var BotpressChat = class extends Chat {
|
|
|
45923
45886
|
handler: async (message) => this.handle(message)
|
|
45924
45887
|
});
|
|
45925
45888
|
this.client = context3.client;
|
|
45926
|
-
this.cognitive = context3.cognitive;
|
|
45927
45889
|
this.conversation = context3.conversation;
|
|
45928
45890
|
this.botId = context3.botId;
|
|
45929
45891
|
this.logger = context3.logger;
|
|
45930
45892
|
this.citations = context3.citations;
|
|
45931
45893
|
}
|
|
45932
45894
|
async getComponents() {
|
|
45933
|
-
return
|
|
45895
|
+
return [
|
|
45896
|
+
DefaultComponents.Text,
|
|
45897
|
+
DefaultComponents.Image,
|
|
45898
|
+
DefaultComponents.File,
|
|
45899
|
+
DefaultComponents.Audio,
|
|
45900
|
+
DefaultComponents.Video,
|
|
45901
|
+
DefaultComponents.Card
|
|
45902
|
+
];
|
|
45934
45903
|
}
|
|
45935
45904
|
async clearTranscript() {
|
|
45936
45905
|
this._transcript = [];
|
|
@@ -46049,12 +46018,18 @@ var BotpressChat = class extends Chat {
|
|
|
46049
46018
|
"message.type": message.type
|
|
46050
46019
|
},
|
|
46051
46020
|
async (s) => {
|
|
46021
|
+
const [payload, citations] = this.citations.removeCitationsFromObject(
|
|
46022
|
+
message.payload
|
|
46023
|
+
);
|
|
46052
46024
|
const { message: created } = await this.client.createMessage({
|
|
46053
46025
|
conversationId: this.conversation.id,
|
|
46054
46026
|
tags: message.tags || {},
|
|
46055
46027
|
userId: this.botId,
|
|
46056
|
-
type: message.type,
|
|
46057
|
-
payload:
|
|
46028
|
+
type: message.type.toLowerCase(),
|
|
46029
|
+
payload: {
|
|
46030
|
+
...payload,
|
|
46031
|
+
metadata: { citations }
|
|
46032
|
+
}
|
|
46058
46033
|
});
|
|
46059
46034
|
s.setAttribute("messageId", created.id);
|
|
46060
46035
|
this._transcript?.push({
|
|
@@ -46088,20 +46063,9 @@ var BotpressChat = class extends Chat {
|
|
|
46088
46063
|
if (isAnyComponent2(msg)) {
|
|
46089
46064
|
await this.handle(msg);
|
|
46090
46065
|
} else if (typeof msg === "string" && msg.trim().length) {
|
|
46091
|
-
|
|
46092
|
-
conversationId: this.conversation.id,
|
|
46093
|
-
tags: {},
|
|
46094
|
-
userId: this.botId,
|
|
46066
|
+
await this.sendMessage({
|
|
46095
46067
|
type: "text",
|
|
46096
|
-
payload: {
|
|
46097
|
-
text: expandCitationsInObject(msg, this.citations)
|
|
46098
|
-
}
|
|
46099
|
-
});
|
|
46100
|
-
this._transcript?.push({
|
|
46101
|
-
id: message2.id,
|
|
46102
|
-
role: "assistant",
|
|
46103
|
-
content: msg.trim(),
|
|
46104
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
46068
|
+
payload: { text: msg }
|
|
46105
46069
|
});
|
|
46106
46070
|
}
|
|
46107
46071
|
}
|
|
@@ -46109,28 +46073,16 @@ var BotpressChat = class extends Chat {
|
|
|
46109
46073
|
}
|
|
46110
46074
|
const components = await this.getComponents();
|
|
46111
46075
|
const component = components.find(
|
|
46112
|
-
(c) => c.definition.name.toLowerCase() === message.type.toLowerCase()
|
|
46076
|
+
(c) => c.definition.name.toLowerCase() === message.type.toLowerCase() || c.definition.aliases?.map((x) => x.toLowerCase()).includes(message.type.toLowerCase())
|
|
46113
46077
|
);
|
|
46114
46078
|
if (!component) {
|
|
46115
46079
|
throw new Error(
|
|
46116
46080
|
`Could not find component for message type "${message.type}"`
|
|
46117
46081
|
);
|
|
46118
46082
|
}
|
|
46119
|
-
|
|
46120
|
-
conversationId: this.conversation.id,
|
|
46121
|
-
tags: {},
|
|
46122
|
-
userId: this.botId,
|
|
46083
|
+
await this.sendMessage({
|
|
46123
46084
|
type: component.definition.name,
|
|
46124
|
-
payload:
|
|
46125
|
-
message.props,
|
|
46126
|
-
this.citations
|
|
46127
|
-
)
|
|
46128
|
-
});
|
|
46129
|
-
this._transcript?.push({
|
|
46130
|
-
id: created.id,
|
|
46131
|
-
role: "assistant",
|
|
46132
|
-
content: JSON.stringify(message, null, 2),
|
|
46133
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
46085
|
+
payload: message.props
|
|
46134
46086
|
});
|
|
46135
46087
|
}
|
|
46136
46088
|
);
|
|
@@ -46209,6 +46161,39 @@ var BotpressChat = class extends Chat {
|
|
|
46209
46161
|
}
|
|
46210
46162
|
};
|
|
46211
46163
|
|
|
46164
|
+
// src/runtime/chat/citations.ts
|
|
46165
|
+
init_define_BUILD();
|
|
46166
|
+
init_define_PACKAGE_VERSIONS();
|
|
46167
|
+
function expandCitationsInObject(obj, citationsManager) {
|
|
46168
|
+
if (typeof obj === "string" && obj.trim().length > 0) {
|
|
46169
|
+
let footer = "";
|
|
46170
|
+
const { cleaned } = citationsManager.extractCitations(obj, (citation) => {
|
|
46171
|
+
footer += `${JSON.stringify(citation.source)}
|
|
46172
|
+
`;
|
|
46173
|
+
return "";
|
|
46174
|
+
}) ?? { cleaned: obj };
|
|
46175
|
+
if (footer) {
|
|
46176
|
+
return `${cleaned}
|
|
46177
|
+
|
|
46178
|
+
${footer}`.trim();
|
|
46179
|
+
}
|
|
46180
|
+
return cleaned.trim();
|
|
46181
|
+
}
|
|
46182
|
+
if (Array.isArray(obj)) {
|
|
46183
|
+
return obj.map(
|
|
46184
|
+
(item) => expandCitationsInObject(item, citationsManager)
|
|
46185
|
+
);
|
|
46186
|
+
}
|
|
46187
|
+
if (obj && typeof obj === "object") {
|
|
46188
|
+
const result = {};
|
|
46189
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
46190
|
+
result[key] = expandCitationsInObject(value, citationsManager);
|
|
46191
|
+
}
|
|
46192
|
+
return result;
|
|
46193
|
+
}
|
|
46194
|
+
return obj;
|
|
46195
|
+
}
|
|
46196
|
+
|
|
46212
46197
|
// src/runtime/chat/transcript.ts
|
|
46213
46198
|
init_define_BUILD();
|
|
46214
46199
|
init_define_PACKAGE_VERSIONS();
|