@botpress/runtime 1.2.3 → 1.2.5
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/_types/channels.d.ts +18 -0
- package/dist/_types/channels.d.ts.map +1 -0
- package/dist/_types/conversations.d.ts +9 -0
- package/dist/_types/conversations.d.ts.map +1 -0
- package/dist/_types/integrations.d.ts +13 -0
- package/dist/_types/integrations.d.ts.map +1 -0
- package/dist/consts.d.ts +1 -0
- package/dist/consts.d.ts.map +1 -1
- package/dist/definition.d.ts +1 -0
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +45914 -9
- package/dist/definition.js.map +4 -4
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +313 -202
- package/dist/internal.js.map +4 -4
- package/dist/library.d.ts +5 -1
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +290 -162
- package/dist/library.js.map +4 -4
- package/dist/primitives/conversation-instance.d.ts +42 -0
- package/dist/primitives/conversation-instance.d.ts.map +1 -0
- package/dist/primitives/conversation.d.ts +30 -64
- package/dist/primitives/conversation.d.ts.map +1 -1
- package/dist/primitives/definition.d.ts +1 -1
- package/dist/primitives/definition.d.ts.map +1 -1
- package/dist/primitives/index.d.ts +3 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/knowledge.d.ts.map +1 -1
- package/dist/primitives/workflow-instance.d.ts +0 -2
- package/dist/primitives/workflow-instance.d.ts.map +1 -1
- package/dist/primitives/workflow.d.ts +1 -2
- package/dist/primitives/workflow.d.ts.map +1 -1
- package/dist/runtime/adk.d.ts +1 -1
- package/dist/runtime/adk.d.ts.map +1 -1
- package/dist/runtime/autonomous.d.ts.map +1 -1
- package/dist/runtime/handlers/conversation-matching.d.ts +17 -0
- package/dist/runtime/handlers/conversation-matching.d.ts.map +1 -0
- package/dist/runtime/handlers/conversation.d.ts.map +1 -1
- package/dist/runtime/handlers/event.d.ts.map +1 -1
- package/dist/runtime/tracked-state.d.ts +16 -5
- package/dist/runtime/tracked-state.d.ts.map +1 -1
- package/dist/runtime.js +325 -205
- package/dist/runtime.js.map +4 -4
- package/dist/telemetry/structured-logging.d.ts.map +1 -1
- package/dist/workers/dev_worker.d.ts.map +1 -1
- package/dist/workers/worker_pool.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/internal.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.2.
|
|
51
|
+
define_PACKAGE_VERSIONS_default = { runtime: "1.2.5", adk: "not-installed", sdk: "4.16.0", llmz: "0.0.26", zai: "2.1.16", cognitive: "0.1.47" };
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -27463,6 +27463,47 @@ var require_indexv2 = __commonJS({
|
|
|
27463
27463
|
}
|
|
27464
27464
|
});
|
|
27465
27465
|
|
|
27466
|
+
// src/utilities/trigger-tags.ts
|
|
27467
|
+
var trigger_tags_exports = {};
|
|
27468
|
+
__export(trigger_tags_exports, {
|
|
27469
|
+
getTriggerSubscriptionTags: () => getTriggerSubscriptionTags,
|
|
27470
|
+
getTriggerTagName: () => getTriggerTagName,
|
|
27471
|
+
getTriggerTagValue: () => getTriggerTagValue,
|
|
27472
|
+
isConversationSubscribedToTrigger: () => isConversationSubscribedToTrigger
|
|
27473
|
+
});
|
|
27474
|
+
import crypto2 from "crypto";
|
|
27475
|
+
var hashString, getTriggerTagName, getTriggerTagValue, getTriggerSubscriptionTags, isConversationSubscribedToTrigger;
|
|
27476
|
+
var init_trigger_tags = __esm({
|
|
27477
|
+
"src/utilities/trigger-tags.ts"() {
|
|
27478
|
+
"use strict";
|
|
27479
|
+
init_define_BUILD();
|
|
27480
|
+
init_define_PACKAGE_VERSIONS();
|
|
27481
|
+
hashString = (str) => {
|
|
27482
|
+
return crypto2.createHash("md5").update(str).digest("hex").substring(0, 5).toUpperCase();
|
|
27483
|
+
};
|
|
27484
|
+
getTriggerTagName = (triggerName) => {
|
|
27485
|
+
return `trigger${hashString(triggerName)}`;
|
|
27486
|
+
};
|
|
27487
|
+
getTriggerTagValue = (key) => {
|
|
27488
|
+
return key ?? "*";
|
|
27489
|
+
};
|
|
27490
|
+
getTriggerSubscriptionTags = (triggerName, key) => {
|
|
27491
|
+
return {
|
|
27492
|
+
name: getTriggerTagName(triggerName),
|
|
27493
|
+
value: getTriggerTagValue(key)
|
|
27494
|
+
};
|
|
27495
|
+
};
|
|
27496
|
+
isConversationSubscribedToTrigger = (conversationTags, triggerName, triggerKey) => {
|
|
27497
|
+
const tagName = getTriggerTagName(triggerName);
|
|
27498
|
+
const tagValue = conversationTags[tagName];
|
|
27499
|
+
if (!tagValue) {
|
|
27500
|
+
return false;
|
|
27501
|
+
}
|
|
27502
|
+
return tagValue === "*" || tagValue === triggerKey;
|
|
27503
|
+
};
|
|
27504
|
+
}
|
|
27505
|
+
});
|
|
27506
|
+
|
|
27466
27507
|
// ../../node_modules/.bun/@isaacs+balanced-match@4.0.1/node_modules/@isaacs/balanced-match/dist/esm/index.js
|
|
27467
27508
|
var balanced, maybeMatch, range;
|
|
27468
27509
|
var init_esm3 = __esm({
|
|
@@ -36437,6 +36478,14 @@ init_define_PACKAGE_VERSIONS();
|
|
|
36437
36478
|
// src/consts.ts
|
|
36438
36479
|
init_define_BUILD();
|
|
36439
36480
|
init_define_PACKAGE_VERSIONS();
|
|
36481
|
+
var BOT_ID_HEADER = "x-bot-id";
|
|
36482
|
+
var BOT_USER_ID_HEADER = "x-bot-user-id";
|
|
36483
|
+
var WEBHOOK_ID_HEADER = "x-webhook-id";
|
|
36484
|
+
var CONFIGURATION_TYPE_HEADER = "x-bp-configuration-type";
|
|
36485
|
+
var CONFIGURATION_PAYLOAD_HEADER = "x-bp-configuration";
|
|
36486
|
+
var OPERATION_TYPE_HEADER = "x-bp-operation";
|
|
36487
|
+
var OPERATION_SUBTYPE_HEADER = "x-bp-type";
|
|
36488
|
+
var LOG_DELIMITER = "<|MESSAGE_END|>\n";
|
|
36440
36489
|
|
|
36441
36490
|
// src/runtime/context/handlers.ts
|
|
36442
36491
|
import { Client } from "@botpress/client";
|
|
@@ -40431,6 +40480,8 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
|
|
|
40431
40480
|
const { passages } = await client.searchFiles({
|
|
40432
40481
|
query,
|
|
40433
40482
|
withContext: true,
|
|
40483
|
+
includeBreadcrumb: true,
|
|
40484
|
+
contextDepth: 4,
|
|
40434
40485
|
tags: {
|
|
40435
40486
|
[WellKnownTags.knowledge.KNOWLEDGE]: "true",
|
|
40436
40487
|
[WellKnownTags.knowledge.KNOWLEDGE_BASE_NAME]: kbNames
|
|
@@ -40474,8 +40525,9 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
|
|
|
40474
40525
|
citationMetadata.sourceId = tags[WellKnownTags.knowledge.KNOWLEDGE_SOURCE_ID];
|
|
40475
40526
|
}
|
|
40476
40527
|
const { tag } = citations.registerSource(citationMetadata);
|
|
40477
|
-
message.push(
|
|
40478
|
-
|
|
40528
|
+
message.push(
|
|
40529
|
+
`<${tag} file="${p.file.key}" title="${citationMetadata.title || p.file.key}">`
|
|
40530
|
+
);
|
|
40479
40531
|
message.push(p.content);
|
|
40480
40532
|
message.push(`</${tag}>`);
|
|
40481
40533
|
}
|
|
@@ -40601,6 +40653,7 @@ Always prefer information from the knowledge bases over general knowledge when a
|
|
|
40601
40653
|
message: "ThinkSignal"
|
|
40602
40654
|
});
|
|
40603
40655
|
err[HandledErrorProp] = true;
|
|
40656
|
+
throw err;
|
|
40604
40657
|
} else {
|
|
40605
40658
|
s.setAttributes({
|
|
40606
40659
|
"autonomous.tool.status": "error",
|
|
@@ -40945,7 +40998,17 @@ function serializeArgs(...args) {
|
|
|
40945
40998
|
});
|
|
40946
40999
|
}
|
|
40947
41000
|
function writeStructuredLog(type, ...args) {
|
|
41001
|
+
const output2 = process.stdout;
|
|
40948
41002
|
const { spanId, traceId } = getTraceContext();
|
|
41003
|
+
let maybeArgObj = null;
|
|
41004
|
+
try {
|
|
41005
|
+
maybeArgObj = typeof args[0] === "string" ? JSON.parse(args[0]) : args[0];
|
|
41006
|
+
} catch {
|
|
41007
|
+
}
|
|
41008
|
+
if (maybeArgObj && typeof maybeArgObj === "object" && maybeArgObj.type === "worker_stats") {
|
|
41009
|
+
output2.write((0, import_fast_safe_stringify3.default)(maybeArgObj) + LOG_DELIMITER);
|
|
41010
|
+
return;
|
|
41011
|
+
}
|
|
40949
41012
|
const logEntry = {
|
|
40950
41013
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
40951
41014
|
type,
|
|
@@ -40957,8 +41020,7 @@ function writeStructuredLog(type, ...args) {
|
|
|
40957
41020
|
if (traceId) {
|
|
40958
41021
|
logEntry.traceId = traceId;
|
|
40959
41022
|
}
|
|
40960
|
-
|
|
40961
|
-
output2.write(JSON.stringify(logEntry) + "\n");
|
|
41023
|
+
output2.write((0, import_fast_safe_stringify3.default)(logEntry) + LOG_DELIMITER);
|
|
40962
41024
|
}
|
|
40963
41025
|
function installStructuredLogging() {
|
|
40964
41026
|
console.log = (...args) => {
|
|
@@ -40979,36 +41041,9 @@ function installStructuredLogging() {
|
|
|
40979
41041
|
}
|
|
40980
41042
|
|
|
40981
41043
|
// src/runtime.ts
|
|
41044
|
+
init_trigger_tags();
|
|
40982
41045
|
import { z as z4 } from "@botpress/sdk";
|
|
40983
41046
|
|
|
40984
|
-
// src/utilities/trigger-tags.ts
|
|
40985
|
-
init_define_BUILD();
|
|
40986
|
-
init_define_PACKAGE_VERSIONS();
|
|
40987
|
-
import crypto2 from "crypto";
|
|
40988
|
-
var hashString = (str) => {
|
|
40989
|
-
return crypto2.createHash("md5").update(str).digest("hex").substring(0, 5).toUpperCase();
|
|
40990
|
-
};
|
|
40991
|
-
var getTriggerTagName = (triggerName) => {
|
|
40992
|
-
return `trigger${hashString(triggerName)}`;
|
|
40993
|
-
};
|
|
40994
|
-
var getTriggerTagValue = (key) => {
|
|
40995
|
-
return key ?? "*";
|
|
40996
|
-
};
|
|
40997
|
-
var getTriggerSubscriptionTags = (triggerName, key) => {
|
|
40998
|
-
return {
|
|
40999
|
-
name: getTriggerTagName(triggerName),
|
|
41000
|
-
value: getTriggerTagValue(key)
|
|
41001
|
-
};
|
|
41002
|
-
};
|
|
41003
|
-
var isConversationSubscribedToTrigger = (conversationTags, triggerName, triggerKey) => {
|
|
41004
|
-
const tagName = getTriggerTagName(triggerName);
|
|
41005
|
-
const tagValue = conversationTags[tagName];
|
|
41006
|
-
if (!tagValue) {
|
|
41007
|
-
return false;
|
|
41008
|
-
}
|
|
41009
|
-
return tagValue === "*" || tagValue === triggerKey;
|
|
41010
|
-
};
|
|
41011
|
-
|
|
41012
41047
|
// src/types.ts
|
|
41013
41048
|
init_define_BUILD();
|
|
41014
41049
|
init_define_PACKAGE_VERSIONS();
|
|
@@ -41087,8 +41122,6 @@ var BaseWorkflow = class {
|
|
|
41087
41122
|
/** @internal */
|
|
41088
41123
|
schedule;
|
|
41089
41124
|
timeout = (0, import_ms.default)("5m");
|
|
41090
|
-
// Runtime state
|
|
41091
|
-
state;
|
|
41092
41125
|
constructor(props) {
|
|
41093
41126
|
this.name = props.name;
|
|
41094
41127
|
if (props.description !== void 0) {
|
|
@@ -41456,10 +41489,15 @@ var EMPTY_STATE = {
|
|
|
41456
41489
|
};
|
|
41457
41490
|
var MAX_SWAP_FILE_SIZE = import_bytes2.default.parse("100MB");
|
|
41458
41491
|
var BUILT_IN_STATES = {
|
|
41459
|
-
user
|
|
41492
|
+
/** Generic conversation-specific state (user-defined per conversation) */
|
|
41460
41493
|
conversation: "state",
|
|
41494
|
+
/** User-specific state (persists across conversations per user) */
|
|
41495
|
+
user: "userState",
|
|
41496
|
+
/** Bot-wide global state (persists across all conversations) */
|
|
41461
41497
|
bot: "botState",
|
|
41498
|
+
/** Workflow-specific state (persists across workflow executions) */
|
|
41462
41499
|
workflowState: "workflowState",
|
|
41500
|
+
/** Workflow cached steps executions */
|
|
41463
41501
|
workflowSteps: "workflowSteps"
|
|
41464
41502
|
};
|
|
41465
41503
|
var TrackedState = class _TrackedState {
|
|
@@ -41532,6 +41570,7 @@ var TrackedState = class _TrackedState {
|
|
|
41532
41570
|
const client = context.get("client")._inner;
|
|
41533
41571
|
const botId = context.get("botId", { optional: true });
|
|
41534
41572
|
const user2 = context.get("user", { optional: true });
|
|
41573
|
+
const conversation = context.get("conversation", { optional: true });
|
|
41535
41574
|
if (botId) {
|
|
41536
41575
|
_TrackedState.create({
|
|
41537
41576
|
client,
|
|
@@ -41550,6 +41589,23 @@ var TrackedState = class _TrackedState {
|
|
|
41550
41589
|
schema: adk.project.config.user?.state || z9.object({})
|
|
41551
41590
|
});
|
|
41552
41591
|
}
|
|
41592
|
+
if (conversation) {
|
|
41593
|
+
const definition = adk.project.conversations.find((c) => {
|
|
41594
|
+
const def = c.getDefinition();
|
|
41595
|
+
if (typeof def.channel === "string") {
|
|
41596
|
+
return def.channel === conversation.channel || def.channel === "*";
|
|
41597
|
+
} else {
|
|
41598
|
+
return def.channel.includes(conversation.channel);
|
|
41599
|
+
}
|
|
41600
|
+
});
|
|
41601
|
+
_TrackedState.create({
|
|
41602
|
+
client,
|
|
41603
|
+
name: BUILT_IN_STATES.conversation,
|
|
41604
|
+
type: "conversation",
|
|
41605
|
+
id: conversation.id,
|
|
41606
|
+
schema: definition?.schema || z9.object({})
|
|
41607
|
+
});
|
|
41608
|
+
}
|
|
41553
41609
|
const states = context.get("states", { optional: true });
|
|
41554
41610
|
const promises = Promise.allSettled(
|
|
41555
41611
|
states?.map((state) => state.load()) ?? []
|
|
@@ -41596,16 +41652,23 @@ var TrackedState = class _TrackedState {
|
|
|
41596
41652
|
} else {
|
|
41597
41653
|
this.value = value;
|
|
41598
41654
|
}
|
|
41599
|
-
if (
|
|
41600
|
-
|
|
41601
|
-
this.value = this.state.parse({});
|
|
41602
|
-
this._isDirty = true;
|
|
41603
|
-
} catch (error) {
|
|
41655
|
+
if (this.value == null || this.value === void 0) {
|
|
41656
|
+
if (this.state && "parse" in this.state) {
|
|
41604
41657
|
try {
|
|
41605
|
-
this.value = this.state.parse(
|
|
41658
|
+
this.value = this.state.parse({});
|
|
41606
41659
|
this._isDirty = true;
|
|
41607
|
-
} catch {
|
|
41660
|
+
} catch (error) {
|
|
41661
|
+
try {
|
|
41662
|
+
this.value = this.state.parse(void 0);
|
|
41663
|
+
this._isDirty = true;
|
|
41664
|
+
} catch {
|
|
41665
|
+
this.value = {};
|
|
41666
|
+
this._isDirty = true;
|
|
41667
|
+
}
|
|
41608
41668
|
}
|
|
41669
|
+
} else {
|
|
41670
|
+
this.value = {};
|
|
41671
|
+
this._isDirty = true;
|
|
41609
41672
|
}
|
|
41610
41673
|
}
|
|
41611
41674
|
try {
|
|
@@ -42215,24 +42278,145 @@ init_define_BUILD();
|
|
|
42215
42278
|
init_define_PACKAGE_VERSIONS();
|
|
42216
42279
|
import { z as z13 } from "@botpress/sdk";
|
|
42217
42280
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
42281
|
+
|
|
42282
|
+
// src/primitives/conversation-instance.ts
|
|
42283
|
+
init_define_BUILD();
|
|
42284
|
+
init_define_PACKAGE_VERSIONS();
|
|
42285
|
+
var BaseConversationInstance = class {
|
|
42286
|
+
id;
|
|
42287
|
+
channel;
|
|
42288
|
+
integration;
|
|
42289
|
+
tags;
|
|
42290
|
+
conversation;
|
|
42291
|
+
// @internal
|
|
42292
|
+
client;
|
|
42293
|
+
// @internal
|
|
42294
|
+
TrackedState;
|
|
42295
|
+
constructor(conversation, client) {
|
|
42296
|
+
this.id = conversation.id;
|
|
42297
|
+
this.channel = conversation.channel;
|
|
42298
|
+
this.integration = conversation.integration;
|
|
42299
|
+
this.tags = conversation.tags;
|
|
42300
|
+
this.conversation = conversation;
|
|
42301
|
+
this.client = client;
|
|
42302
|
+
const states = context.get("states", { optional: true });
|
|
42303
|
+
const existingState = states?.find(
|
|
42304
|
+
(s) => s.type === "conversation" && s.id === conversation.id && s.name === BUILT_IN_STATES.conversation
|
|
42305
|
+
);
|
|
42306
|
+
if (!existingState) {
|
|
42307
|
+
throw new Error(
|
|
42308
|
+
`Conversation state not found for conversation ${conversation.id}. Make sure TrackedState.loadAll() is called before creating conversation instances.`
|
|
42309
|
+
);
|
|
42310
|
+
}
|
|
42311
|
+
this.TrackedState = existingState;
|
|
42312
|
+
}
|
|
42313
|
+
/**
|
|
42314
|
+
* Send a message to this conversation
|
|
42315
|
+
*/
|
|
42316
|
+
async send(message) {
|
|
42317
|
+
try {
|
|
42318
|
+
const chat = context.get("chat");
|
|
42319
|
+
await trackPromise(
|
|
42320
|
+
chat.sendMessage({
|
|
42321
|
+
type: message.type,
|
|
42322
|
+
payload: message.payload
|
|
42323
|
+
})
|
|
42324
|
+
);
|
|
42325
|
+
} catch (err) {
|
|
42326
|
+
console.error("Error sending message in conversation:", err);
|
|
42327
|
+
}
|
|
42328
|
+
}
|
|
42329
|
+
/**
|
|
42330
|
+
* Start typing indicator
|
|
42331
|
+
*/
|
|
42332
|
+
async startTyping() {
|
|
42333
|
+
const mapping = InterfaceMappings.getIntegrationAction(
|
|
42334
|
+
"typingIndicator",
|
|
42335
|
+
"startTypingIndicator",
|
|
42336
|
+
this.integration
|
|
42337
|
+
);
|
|
42338
|
+
if (mapping) {
|
|
42339
|
+
const message = context.get("message", { optional: true });
|
|
42340
|
+
await this.client.callAction({
|
|
42341
|
+
type: mapping,
|
|
42342
|
+
input: {
|
|
42343
|
+
conversationId: this.id,
|
|
42344
|
+
messageId: message?.id
|
|
42345
|
+
}
|
|
42346
|
+
}).catch(() => {
|
|
42347
|
+
});
|
|
42348
|
+
}
|
|
42349
|
+
}
|
|
42350
|
+
/**
|
|
42351
|
+
* Stop typing indicator
|
|
42352
|
+
*/
|
|
42353
|
+
async stopTyping() {
|
|
42354
|
+
const mapping = InterfaceMappings.getIntegrationAction(
|
|
42355
|
+
"typingIndicator",
|
|
42356
|
+
"stopTypingIndicator",
|
|
42357
|
+
this.integration
|
|
42358
|
+
);
|
|
42359
|
+
if (mapping) {
|
|
42360
|
+
const message = context.get("message", { optional: true });
|
|
42361
|
+
await this.client.callAction({
|
|
42362
|
+
type: mapping,
|
|
42363
|
+
input: {
|
|
42364
|
+
conversationId: this.id,
|
|
42365
|
+
messageId: message?.id
|
|
42366
|
+
}
|
|
42367
|
+
}).catch(() => {
|
|
42368
|
+
});
|
|
42369
|
+
}
|
|
42370
|
+
}
|
|
42371
|
+
/**
|
|
42372
|
+
* Subscribe to a trigger
|
|
42373
|
+
*/
|
|
42374
|
+
async subscribeToTrigger(triggerName, key) {
|
|
42375
|
+
const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
|
|
42376
|
+
if (isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
|
|
42377
|
+
return;
|
|
42378
|
+
}
|
|
42379
|
+
const { name, value } = getTriggerSubscriptionTags2(triggerName, key);
|
|
42380
|
+
await this.client.updateConversation({
|
|
42381
|
+
id: this.id,
|
|
42382
|
+
tags: {
|
|
42383
|
+
[name]: value
|
|
42384
|
+
}
|
|
42385
|
+
});
|
|
42386
|
+
}
|
|
42387
|
+
/**
|
|
42388
|
+
* Unsubscribe from a trigger
|
|
42389
|
+
*/
|
|
42390
|
+
async unsubscribeFromTrigger(triggerName, key) {
|
|
42391
|
+
const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
|
|
42392
|
+
if (!isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
|
|
42393
|
+
return;
|
|
42394
|
+
}
|
|
42395
|
+
const { name } = getTriggerSubscriptionTags2(triggerName, key);
|
|
42396
|
+
await this.client.updateConversation({
|
|
42397
|
+
id: this.id,
|
|
42398
|
+
tags: {
|
|
42399
|
+
[name]: ""
|
|
42400
|
+
}
|
|
42401
|
+
});
|
|
42402
|
+
}
|
|
42403
|
+
};
|
|
42404
|
+
|
|
42405
|
+
// src/primitives/conversation.ts
|
|
42218
42406
|
var ConversationHandler = Symbol.for("conversation.handler");
|
|
42219
42407
|
var Typings3;
|
|
42220
42408
|
((Typings8) => {
|
|
42221
42409
|
Typings8.Primitive = "conversation";
|
|
42222
42410
|
})(Typings3 || (Typings3 = {}));
|
|
42223
42411
|
var BaseConversation = class {
|
|
42224
|
-
integration;
|
|
42225
42412
|
channel;
|
|
42226
42413
|
/** @internal */
|
|
42227
42414
|
schema;
|
|
42228
42415
|
#handler;
|
|
42229
|
-
#state;
|
|
42230
42416
|
#startFromTrigger;
|
|
42231
|
-
#interruptionSignal;
|
|
42232
42417
|
constructor(props) {
|
|
42233
42418
|
this.channel = props.channel;
|
|
42234
42419
|
this.schema = props.state ?? z13.object({}).passthrough();
|
|
42235
|
-
this.integration = props.channel.split(".")[0];
|
|
42236
42420
|
this.#handler = props.handler;
|
|
42237
42421
|
if (props.startFromTrigger) {
|
|
42238
42422
|
this.#startFromTrigger = props.startFromTrigger;
|
|
@@ -42244,31 +42428,34 @@ var BaseConversation = class {
|
|
|
42244
42428
|
}
|
|
42245
42429
|
/** @internal */
|
|
42246
42430
|
getDefinition() {
|
|
42247
|
-
|
|
42248
|
-
|
|
42249
|
-
|
|
42250
|
-
|
|
42251
|
-
|
|
42252
|
-
|
|
42253
|
-
|
|
42254
|
-
|
|
42255
|
-
|
|
42256
|
-
|
|
42257
|
-
|
|
42258
|
-
|
|
42259
|
-
|
|
42260
|
-
|
|
42261
|
-
|
|
42262
|
-
|
|
42431
|
+
if (this.channel === "*") {
|
|
42432
|
+
return {
|
|
42433
|
+
type: "conversation",
|
|
42434
|
+
channel: "*"
|
|
42435
|
+
};
|
|
42436
|
+
} else if (Array.isArray(this.channel)) {
|
|
42437
|
+
return {
|
|
42438
|
+
type: "conversation",
|
|
42439
|
+
channel: this.channel
|
|
42440
|
+
};
|
|
42441
|
+
} else {
|
|
42442
|
+
return {
|
|
42443
|
+
type: "conversation",
|
|
42444
|
+
channel: this.channel
|
|
42445
|
+
};
|
|
42446
|
+
}
|
|
42263
42447
|
}
|
|
42264
|
-
|
|
42265
|
-
// TODO: each execution should have its own instance to avoid state conflicts etc
|
|
42448
|
+
/** @internal */
|
|
42266
42449
|
async [ConversationHandler]() {
|
|
42267
42450
|
const message = context.get("message", { optional: true });
|
|
42268
42451
|
const event = context.get("event", { optional: true });
|
|
42269
42452
|
const chat = context.get("chat");
|
|
42270
42453
|
const client = context.get("client");
|
|
42271
|
-
const
|
|
42454
|
+
const botpressConversation = context.get("conversation");
|
|
42455
|
+
const conversationInstance = new BaseConversationInstance(
|
|
42456
|
+
botpressConversation,
|
|
42457
|
+
client
|
|
42458
|
+
);
|
|
42272
42459
|
let type;
|
|
42273
42460
|
let requestObject = void 0;
|
|
42274
42461
|
if (message) {
|
|
@@ -42293,11 +42480,10 @@ var BaseConversation = class {
|
|
|
42293
42480
|
type = "event";
|
|
42294
42481
|
}
|
|
42295
42482
|
const controller = new AbortController();
|
|
42296
|
-
this.#interruptionSignal = controller.signal;
|
|
42297
42483
|
void span(
|
|
42298
42484
|
"interruption.check",
|
|
42299
42485
|
{
|
|
42300
|
-
conversationId
|
|
42486
|
+
conversationId: conversationInstance.id
|
|
42301
42487
|
},
|
|
42302
42488
|
async (s) => {
|
|
42303
42489
|
async function checkNewUserMessage() {
|
|
@@ -42305,7 +42491,7 @@ var BaseConversation = class {
|
|
|
42305
42491
|
return;
|
|
42306
42492
|
}
|
|
42307
42493
|
const { events } = await client.listEvents({
|
|
42308
|
-
conversationId,
|
|
42494
|
+
conversationId: conversationInstance.id,
|
|
42309
42495
|
status: "pending"
|
|
42310
42496
|
});
|
|
42311
42497
|
const newEvents = events.filter(
|
|
@@ -42361,100 +42547,36 @@ var BaseConversation = class {
|
|
|
42361
42547
|
const execute = Autonomous.createExecute({
|
|
42362
42548
|
mode: "chat",
|
|
42363
42549
|
defaultModel: adk.project.config.defaultModels.autonomous,
|
|
42364
|
-
|
|
42365
|
-
|
|
42550
|
+
interruption: controller.signal
|
|
42551
|
+
});
|
|
42552
|
+
if (!conversationInstance.TrackedState.value) {
|
|
42553
|
+
conversationInstance.TrackedState.value = {};
|
|
42554
|
+
}
|
|
42555
|
+
const stateProxy = new Proxy(conversationInstance.TrackedState.value, {
|
|
42556
|
+
set(target, prop, value) {
|
|
42557
|
+
const result = Reflect.set(target, prop, value);
|
|
42558
|
+
conversationInstance.TrackedState.markDirty();
|
|
42559
|
+
return result;
|
|
42366
42560
|
}
|
|
42367
42561
|
});
|
|
42368
|
-
await this.#handler
|
|
42562
|
+
await this.#handler({
|
|
42369
42563
|
type,
|
|
42370
42564
|
message,
|
|
42371
42565
|
event,
|
|
42372
42566
|
request: requestObject,
|
|
42567
|
+
conversation: conversationInstance,
|
|
42568
|
+
state: stateProxy,
|
|
42569
|
+
client,
|
|
42373
42570
|
execute
|
|
42374
42571
|
});
|
|
42375
42572
|
controller.abort();
|
|
42376
42573
|
}
|
|
42377
|
-
async subscribeToTrigger(triggerName, key) {
|
|
42378
|
-
if (isConversationSubscribedToTrigger(this.tags, triggerName, key)) {
|
|
42379
|
-
return;
|
|
42380
|
-
}
|
|
42381
|
-
const conversation = context.get("conversation");
|
|
42382
|
-
const client = context.get("client");
|
|
42383
|
-
const { name, value } = getTriggerSubscriptionTags(triggerName, key);
|
|
42384
|
-
await client.updateConversation({
|
|
42385
|
-
id: conversation.id,
|
|
42386
|
-
tags: {
|
|
42387
|
-
[name]: value
|
|
42388
|
-
}
|
|
42389
|
-
});
|
|
42390
|
-
}
|
|
42391
|
-
async unsubscribeFromTrigger(triggerName, key) {
|
|
42392
|
-
if (!isConversationSubscribedToTrigger(this.tags, triggerName, key)) {
|
|
42393
|
-
return;
|
|
42394
|
-
}
|
|
42395
|
-
const conversation = context.get("conversation");
|
|
42396
|
-
const client = context.get("client");
|
|
42397
|
-
const { name } = getTriggerSubscriptionTags(triggerName, key);
|
|
42398
|
-
await client.updateConversation({
|
|
42399
|
-
id: conversation.id,
|
|
42400
|
-
tags: {
|
|
42401
|
-
[name]: ""
|
|
42402
|
-
}
|
|
42403
|
-
});
|
|
42404
|
-
}
|
|
42405
|
-
async startTyping() {
|
|
42406
|
-
const conversation = context.get("conversation", { optional: true });
|
|
42407
|
-
const message = context.get("message", { optional: true });
|
|
42408
|
-
const mapping = InterfaceMappings.getIntegrationAction(
|
|
42409
|
-
"typingIndicator",
|
|
42410
|
-
"startTypingIndicator",
|
|
42411
|
-
conversation?.integration
|
|
42412
|
-
);
|
|
42413
|
-
if (conversation && mapping) {
|
|
42414
|
-
await context.get("client").callAction({
|
|
42415
|
-
type: mapping,
|
|
42416
|
-
input: {
|
|
42417
|
-
conversationId: conversation.id,
|
|
42418
|
-
messageId: message?.id
|
|
42419
|
-
}
|
|
42420
|
-
}).catch(() => {
|
|
42421
|
-
});
|
|
42422
|
-
}
|
|
42423
|
-
}
|
|
42424
|
-
async stopTyping() {
|
|
42425
|
-
const conversation = context.get("conversation", { optional: true });
|
|
42426
|
-
const message = context.get("message", { optional: true });
|
|
42427
|
-
const mapping = InterfaceMappings.getIntegrationAction(
|
|
42428
|
-
"typingIndicator",
|
|
42429
|
-
"stopTypingIndicator",
|
|
42430
|
-
conversation?.integration
|
|
42431
|
-
);
|
|
42432
|
-
if (conversation && mapping) {
|
|
42433
|
-
await context.get("client").callAction({
|
|
42434
|
-
type: mapping,
|
|
42435
|
-
input: {
|
|
42436
|
-
conversationId: conversation.id,
|
|
42437
|
-
messageId: message?.id
|
|
42438
|
-
}
|
|
42439
|
-
}).catch(() => {
|
|
42440
|
-
});
|
|
42441
|
-
}
|
|
42442
|
-
}
|
|
42443
|
-
async send(message) {
|
|
42444
|
-
try {
|
|
42445
|
-
const chat = context.get("chat");
|
|
42446
|
-
await trackPromise(
|
|
42447
|
-
chat.sendMessage({
|
|
42448
|
-
type: message.type,
|
|
42449
|
-
payload: message.payload
|
|
42450
|
-
})
|
|
42451
|
-
);
|
|
42452
|
-
} catch (err) {
|
|
42453
|
-
console.error("Error getting context in conversation.send:", err);
|
|
42454
|
-
}
|
|
42455
|
-
}
|
|
42456
42574
|
};
|
|
42457
42575
|
|
|
42576
|
+
// src/runtime/handlers/conversation-matching.ts
|
|
42577
|
+
init_define_BUILD();
|
|
42578
|
+
init_define_PACKAGE_VERSIONS();
|
|
42579
|
+
|
|
42458
42580
|
// src/runtime/handlers/trigger.ts
|
|
42459
42581
|
init_define_BUILD();
|
|
42460
42582
|
init_define_PACKAGE_VERSIONS();
|
|
@@ -42944,12 +43066,6 @@ var BaseWorkflowInstance = class _BaseWorkflowInstance {
|
|
|
42944
43066
|
workflow;
|
|
42945
43067
|
// @internal
|
|
42946
43068
|
TrackedState;
|
|
42947
|
-
set state(state) {
|
|
42948
|
-
this.TrackedState.value = state;
|
|
42949
|
-
}
|
|
42950
|
-
get state() {
|
|
42951
|
-
return this.TrackedState.value;
|
|
42952
|
-
}
|
|
42953
43069
|
constructor(workflow, client) {
|
|
42954
43070
|
const definition = adk.project.workflows.find(
|
|
42955
43071
|
(w) => w.name === workflow.name
|
|
@@ -42959,7 +43075,7 @@ var BaseWorkflowInstance = class _BaseWorkflowInstance {
|
|
|
42959
43075
|
client: client._inner,
|
|
42960
43076
|
id: workflow.id,
|
|
42961
43077
|
schema: definition?.stateSchema,
|
|
42962
|
-
name:
|
|
43078
|
+
name: BUILT_IN_STATES.workflowState
|
|
42963
43079
|
});
|
|
42964
43080
|
this.id = workflow.id;
|
|
42965
43081
|
this.name = workflow.name;
|
|
@@ -43090,14 +43206,25 @@ var BaseWorkflowInstance = class _BaseWorkflowInstance {
|
|
|
43090
43206
|
"Workflow execution state is not loaded"
|
|
43091
43207
|
);
|
|
43092
43208
|
workflowExecutionState.value.executionCount++;
|
|
43209
|
+
if (!this.TrackedState.value) {
|
|
43210
|
+
this.TrackedState.value = {};
|
|
43211
|
+
}
|
|
43212
|
+
const trackedState = this.TrackedState;
|
|
43213
|
+
const stateProxy = new Proxy(this.TrackedState.value, {
|
|
43214
|
+
set(target, prop, value) {
|
|
43215
|
+
const result2 = Reflect.set(target, prop, value);
|
|
43216
|
+
trackedState.markDirty();
|
|
43217
|
+
return result2;
|
|
43218
|
+
}
|
|
43219
|
+
});
|
|
43093
43220
|
const result = await context.run(
|
|
43094
43221
|
{
|
|
43095
43222
|
...ctx,
|
|
43096
43223
|
workflowControlContext
|
|
43097
43224
|
},
|
|
43098
|
-
async () => handler
|
|
43225
|
+
async () => handler({
|
|
43099
43226
|
input: this.input,
|
|
43100
|
-
state:
|
|
43227
|
+
state: stateProxy,
|
|
43101
43228
|
step,
|
|
43102
43229
|
client: this.client,
|
|
43103
43230
|
execute: this.execute.bind(this)
|
|
@@ -43163,7 +43290,7 @@ function createWorkflowExecutionState(client, workflowId) {
|
|
|
43163
43290
|
client,
|
|
43164
43291
|
id: workflowId,
|
|
43165
43292
|
schema: workflowExecutionContextSchema,
|
|
43166
|
-
name:
|
|
43293
|
+
name: BUILT_IN_STATES.workflowSteps
|
|
43167
43294
|
});
|
|
43168
43295
|
}
|
|
43169
43296
|
|
|
@@ -43175,7 +43302,12 @@ var Definitions;
|
|
|
43175
43302
|
((Definitions2) => {
|
|
43176
43303
|
const conversationDefinitionSchema = z18.object({
|
|
43177
43304
|
type: z18.literal("conversation"),
|
|
43178
|
-
channel: z18.
|
|
43305
|
+
channel: z18.union([
|
|
43306
|
+
z18.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^(\*|[a-zA-Z0-9._-]+)$/, "Channel must be a valid identifier or glob '*'"),
|
|
43307
|
+
z18.array(
|
|
43308
|
+
z18.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^[a-zA-Z0-9._-]+$/, "Channel must be a valid identifier")
|
|
43309
|
+
)
|
|
43310
|
+
])
|
|
43179
43311
|
});
|
|
43180
43312
|
const workflowDefinitionSchema = z18.object({
|
|
43181
43313
|
type: z18.literal("workflow"),
|
|
@@ -45425,6 +45557,7 @@ var BaseKnowledge = class {
|
|
|
45425
45557
|
constructor(props) {
|
|
45426
45558
|
this.name = props.name;
|
|
45427
45559
|
this.sources = props.sources;
|
|
45560
|
+
this.description = props.description;
|
|
45428
45561
|
}
|
|
45429
45562
|
/** @internal */
|
|
45430
45563
|
getDefinition() {
|
|
@@ -45798,6 +45931,7 @@ var Primitives;
|
|
|
45798
45931
|
((Primitives2) => {
|
|
45799
45932
|
Primitives2.Definitions = Definitions;
|
|
45800
45933
|
Primitives2.BaseConversation = BaseConversation;
|
|
45934
|
+
Primitives2.BaseConversationInstance = BaseConversationInstance;
|
|
45801
45935
|
Primitives2.Conversation = Typings3;
|
|
45802
45936
|
Primitives2.BaseKnowledge = BaseKnowledge;
|
|
45803
45937
|
Primitives2.Knowledge = Typings4;
|
|
@@ -45871,20 +46005,14 @@ var WorkerPool = class {
|
|
|
45871
46005
|
};
|
|
45872
46006
|
constructor(workerScript) {
|
|
45873
46007
|
this.workerScript = workerScript || path4.join(process.cwd(), ".botpress/dist/index.cjs");
|
|
45874
|
-
debugLog(
|
|
45875
|
-
"[WorkerPool] Initializing...",
|
|
45876
|
-
this.workerScript,
|
|
45877
|
-
process.cwd()
|
|
45878
|
-
);
|
|
46008
|
+
debugLog("[WorkerPool] Initializing...", this.workerScript, process.cwd());
|
|
45879
46009
|
this.initialize();
|
|
45880
46010
|
}
|
|
45881
46011
|
/**
|
|
45882
46012
|
* Initialize the worker pool with the configured number of workers
|
|
45883
46013
|
*/
|
|
45884
46014
|
initialize() {
|
|
45885
|
-
debugLog(
|
|
45886
|
-
`[WorkerPool] Initializing pool with ${WORKER_POOL_SIZE} workers`
|
|
45887
|
-
);
|
|
46015
|
+
debugLog(`[WorkerPool] Initializing pool with ${WORKER_POOL_SIZE} workers`);
|
|
45888
46016
|
for (let i = 0; i < WORKER_POOL_SIZE; i++) {
|
|
45889
46017
|
this.createWorker();
|
|
45890
46018
|
}
|
|
@@ -45989,6 +46117,9 @@ var WorkerPool = class {
|
|
|
45989
46117
|
case "debug":
|
|
45990
46118
|
console.debug(prefix, ...args);
|
|
45991
46119
|
break;
|
|
46120
|
+
case "log":
|
|
46121
|
+
console.log(prefix, ...args);
|
|
46122
|
+
break;
|
|
45992
46123
|
default:
|
|
45993
46124
|
debugLog(prefix, ...args);
|
|
45994
46125
|
}
|
|
@@ -46437,7 +46568,7 @@ function initializeParentWorker(bot2) {
|
|
|
46437
46568
|
}
|
|
46438
46569
|
})
|
|
46439
46570
|
);
|
|
46440
|
-
},
|
|
46571
|
+
}, 500);
|
|
46441
46572
|
}
|
|
46442
46573
|
|
|
46443
46574
|
// src/workers/dev_worker.ts
|
|
@@ -46445,46 +46576,16 @@ init_define_BUILD();
|
|
|
46445
46576
|
init_define_PACKAGE_VERSIONS();
|
|
46446
46577
|
import { parentPort } from "worker_threads";
|
|
46447
46578
|
var DEBUG_ENABLED3 = process.env.BP_DEBUG === "true" || process.env.BP_DEBUG === "1";
|
|
46448
|
-
var originalLog = console.log;
|
|
46449
46579
|
function debugLog3(...args) {
|
|
46450
46580
|
if (DEBUG_ENABLED3) {
|
|
46451
|
-
|
|
46581
|
+
console.log(...args);
|
|
46452
46582
|
}
|
|
46453
46583
|
}
|
|
46454
|
-
function setupLogRelay() {
|
|
46455
|
-
if (!parentPort) return;
|
|
46456
|
-
const originalConsole = {
|
|
46457
|
-
log: console.log,
|
|
46458
|
-
info: console.info,
|
|
46459
|
-
warn: console.warn,
|
|
46460
|
-
error: console.error,
|
|
46461
|
-
debug: console.debug
|
|
46462
|
-
};
|
|
46463
|
-
originalLog = originalConsole.log;
|
|
46464
|
-
const createLogRelay = (level) => {
|
|
46465
|
-
return (...args) => {
|
|
46466
|
-
parentPort.postMessage({
|
|
46467
|
-
type: "log",
|
|
46468
|
-
level,
|
|
46469
|
-
args
|
|
46470
|
-
});
|
|
46471
|
-
if (DEBUG_ENABLED3) {
|
|
46472
|
-
originalConsole[level](...args);
|
|
46473
|
-
}
|
|
46474
|
-
};
|
|
46475
|
-
};
|
|
46476
|
-
console.log = createLogRelay("log");
|
|
46477
|
-
console.info = createLogRelay("info");
|
|
46478
|
-
console.warn = createLogRelay("warn");
|
|
46479
|
-
console.error = createLogRelay("error");
|
|
46480
|
-
console.debug = createLogRelay("debug");
|
|
46481
|
-
}
|
|
46482
46584
|
function runWorker(bot2) {
|
|
46483
46585
|
const expiryTime = process.env.WORKER_EXPIRY_TIME ? parseInt(process.env.WORKER_EXPIRY_TIME, 10) : Date.now() + 5 * 60 * 1e3;
|
|
46484
46586
|
if (!parentPort) {
|
|
46485
46587
|
throw new Error("This script must be run as a worker thread");
|
|
46486
46588
|
}
|
|
46487
|
-
setupLogRelay();
|
|
46488
46589
|
parentPort.on("message", async (message) => {
|
|
46489
46590
|
const { type, taskId, event } = message;
|
|
46490
46591
|
if (type !== "event" || !taskId) {
|
|
@@ -46545,15 +46646,25 @@ var isWorkerMode = () => {
|
|
|
46545
46646
|
};
|
|
46546
46647
|
export {
|
|
46547
46648
|
Action,
|
|
46649
|
+
BOT_ID_HEADER,
|
|
46650
|
+
BOT_USER_ID_HEADER,
|
|
46651
|
+
BUILT_IN_STATES,
|
|
46652
|
+
BaseConversationInstance,
|
|
46548
46653
|
BaseWorkflowInstance,
|
|
46549
46654
|
BuiltInWorkflows,
|
|
46655
|
+
CONFIGURATION_PAYLOAD_HEADER,
|
|
46656
|
+
CONFIGURATION_TYPE_HEADER,
|
|
46550
46657
|
BaseConversation as Conversation,
|
|
46551
46658
|
DataSource2 as DataSource,
|
|
46552
46659
|
Errors,
|
|
46553
46660
|
BaseKnowledge as Knowledge,
|
|
46661
|
+
LOG_DELIMITER,
|
|
46662
|
+
OPERATION_SUBTYPE_HEADER,
|
|
46663
|
+
OPERATION_TYPE_HEADER,
|
|
46554
46664
|
Primitives,
|
|
46555
46665
|
BaseTable as Table,
|
|
46556
46666
|
Trigger,
|
|
46667
|
+
WEBHOOK_ID_HEADER,
|
|
46557
46668
|
BaseWorkflow as Workflow,
|
|
46558
46669
|
contextManager,
|
|
46559
46670
|
createSpan,
|