@botpress/runtime 1.13.8 → 1.13.10
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/define-config.d.ts +23 -1
- package/dist/define-config.d.ts.map +1 -1
- package/dist/definition.js +406 -378
- package/dist/definition.js.map +4 -4
- package/dist/internal.js +500 -472
- package/dist/internal.js.map +4 -4
- package/dist/library.d.ts +4 -2
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +433 -372
- package/dist/library.js.map +4 -4
- package/dist/primitives/conversation-instance.d.ts +0 -8
- package/dist/primitives/conversation-instance.d.ts.map +1 -1
- package/dist/primitives/conversation.d.ts +24 -13
- package/dist/primitives/conversation.d.ts.map +1 -1
- package/dist/primitives/data-sources/source-base.d.ts +1 -1
- package/dist/primitives/data-sources/source-base.d.ts.map +1 -1
- package/dist/primitives/index.d.ts +1 -1
- package/dist/primitives/workflow-instance.d.ts +45 -1
- package/dist/primitives/workflow-instance.d.ts.map +1 -1
- package/dist/primitives/workflow.d.ts +3 -2
- package/dist/primitives/workflow.d.ts.map +1 -1
- package/dist/runtime/autonomous.d.ts +1 -0
- package/dist/runtime/autonomous.d.ts.map +1 -1
- package/dist/runtime/context/context.d.ts +3 -0
- package/dist/runtime/context/context.d.ts.map +1 -1
- package/dist/runtime/context/handlers.d.ts.map +1 -1
- package/dist/runtime/handlers/event.d.ts.map +1 -1
- package/dist/runtime/handlers/workflow.d.ts.map +1 -1
- package/dist/runtime/tracked-tags.d.ts.map +1 -1
- package/dist/runtime.d.ts +0 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +457 -394
- package/dist/runtime.js.map +4 -4
- package/dist/utilities/events.d.ts +28 -0
- package/dist/utilities/events.d.ts.map +1 -1
- package/dist/utilities/validate-event-name.d.ts +20 -0
- package/dist/utilities/validate-event-name.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/utilities/trigger-tags.d.ts +0 -31
- package/dist/utilities/trigger-tags.d.ts.map +0 -1
package/dist/definition.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.13.
|
|
51
|
+
define_PACKAGE_VERSIONS_default = { runtime: "1.13.10", adk: "1.13.10", sdk: "5.0.2", llmz: "0.0.35", zai: "2.5.6", cognitive: "0.3.3" };
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -10657,7 +10657,7 @@ var require_form_data = __commonJS({
|
|
|
10657
10657
|
var parseUrl = __require("url").parse;
|
|
10658
10658
|
var fs3 = __require("fs");
|
|
10659
10659
|
var Stream2 = __require("stream").Stream;
|
|
10660
|
-
var
|
|
10660
|
+
var crypto2 = __require("crypto");
|
|
10661
10661
|
var mime = require_mime_types();
|
|
10662
10662
|
var asynckit = require_asynckit();
|
|
10663
10663
|
var setToStringTag = require_es_set_tostringtag();
|
|
@@ -10863,7 +10863,7 @@ var require_form_data = __commonJS({
|
|
|
10863
10863
|
return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
|
|
10864
10864
|
};
|
|
10865
10865
|
FormData3.prototype._generateBoundary = function() {
|
|
10866
|
-
this._boundary = "--------------------------" +
|
|
10866
|
+
this._boundary = "--------------------------" + crypto2.randomBytes(12).toString("hex");
|
|
10867
10867
|
};
|
|
10868
10868
|
FormData3.prototype.getLengthSync = function() {
|
|
10869
10869
|
var knownLength = this._overheadLength + this._valueLength;
|
|
@@ -12138,41 +12138,41 @@ var require_ms = __commonJS({
|
|
|
12138
12138
|
return void 0;
|
|
12139
12139
|
}
|
|
12140
12140
|
}
|
|
12141
|
-
function fmtShort(
|
|
12142
|
-
var msAbs = Math.abs(
|
|
12141
|
+
function fmtShort(ms4) {
|
|
12142
|
+
var msAbs = Math.abs(ms4);
|
|
12143
12143
|
if (msAbs >= d) {
|
|
12144
|
-
return Math.round(
|
|
12144
|
+
return Math.round(ms4 / d) + "d";
|
|
12145
12145
|
}
|
|
12146
12146
|
if (msAbs >= h) {
|
|
12147
|
-
return Math.round(
|
|
12147
|
+
return Math.round(ms4 / h) + "h";
|
|
12148
12148
|
}
|
|
12149
12149
|
if (msAbs >= m) {
|
|
12150
|
-
return Math.round(
|
|
12150
|
+
return Math.round(ms4 / m) + "m";
|
|
12151
12151
|
}
|
|
12152
12152
|
if (msAbs >= s) {
|
|
12153
|
-
return Math.round(
|
|
12153
|
+
return Math.round(ms4 / s) + "s";
|
|
12154
12154
|
}
|
|
12155
|
-
return
|
|
12155
|
+
return ms4 + "ms";
|
|
12156
12156
|
}
|
|
12157
|
-
function fmtLong(
|
|
12158
|
-
var msAbs = Math.abs(
|
|
12157
|
+
function fmtLong(ms4) {
|
|
12158
|
+
var msAbs = Math.abs(ms4);
|
|
12159
12159
|
if (msAbs >= d) {
|
|
12160
|
-
return plural(
|
|
12160
|
+
return plural(ms4, msAbs, d, "day");
|
|
12161
12161
|
}
|
|
12162
12162
|
if (msAbs >= h) {
|
|
12163
|
-
return plural(
|
|
12163
|
+
return plural(ms4, msAbs, h, "hour");
|
|
12164
12164
|
}
|
|
12165
12165
|
if (msAbs >= m) {
|
|
12166
|
-
return plural(
|
|
12166
|
+
return plural(ms4, msAbs, m, "minute");
|
|
12167
12167
|
}
|
|
12168
12168
|
if (msAbs >= s) {
|
|
12169
|
-
return plural(
|
|
12169
|
+
return plural(ms4, msAbs, s, "second");
|
|
12170
12170
|
}
|
|
12171
|
-
return
|
|
12171
|
+
return ms4 + " ms";
|
|
12172
12172
|
}
|
|
12173
|
-
function plural(
|
|
12173
|
+
function plural(ms4, msAbs, n, name) {
|
|
12174
12174
|
var isPlural = msAbs >= n * 1.5;
|
|
12175
|
-
return Math.round(
|
|
12175
|
+
return Math.round(ms4 / n) + " " + name + (isPlural ? "s" : "");
|
|
12176
12176
|
}
|
|
12177
12177
|
}
|
|
12178
12178
|
});
|
|
@@ -12217,8 +12217,8 @@ var require_common = __commonJS({
|
|
|
12217
12217
|
}
|
|
12218
12218
|
const self2 = debug;
|
|
12219
12219
|
const curr = Number(/* @__PURE__ */ new Date());
|
|
12220
|
-
const
|
|
12221
|
-
self2.diff =
|
|
12220
|
+
const ms4 = curr - (prevTime || curr);
|
|
12221
|
+
self2.diff = ms4;
|
|
12222
12222
|
self2.prev = prevTime;
|
|
12223
12223
|
self2.curr = curr;
|
|
12224
12224
|
prevTime = curr;
|
|
@@ -32944,6 +32944,259 @@ var init_agent_registry = __esm({
|
|
|
32944
32944
|
}
|
|
32945
32945
|
});
|
|
32946
32946
|
|
|
32947
|
+
// src/runtime/tracked-tags.ts
|
|
32948
|
+
var TrackedTags;
|
|
32949
|
+
var init_tracked_tags = __esm({
|
|
32950
|
+
"src/runtime/tracked-tags.ts"() {
|
|
32951
|
+
"use strict";
|
|
32952
|
+
init_define_BUILD();
|
|
32953
|
+
init_define_PACKAGE_VERSIONS();
|
|
32954
|
+
init_context3();
|
|
32955
|
+
init_tracing();
|
|
32956
|
+
TrackedTags = class _TrackedTags {
|
|
32957
|
+
type;
|
|
32958
|
+
id;
|
|
32959
|
+
client;
|
|
32960
|
+
_tags = {};
|
|
32961
|
+
_initialTags = {};
|
|
32962
|
+
_loaded = false;
|
|
32963
|
+
_saving = false;
|
|
32964
|
+
_saveAgain = false;
|
|
32965
|
+
_saveAgainCount = 0;
|
|
32966
|
+
static _savingAll = false;
|
|
32967
|
+
static _saveAllAgain = false;
|
|
32968
|
+
static _saveAllCount = 0;
|
|
32969
|
+
constructor(props) {
|
|
32970
|
+
this.type = props.type;
|
|
32971
|
+
this.id = props.id;
|
|
32972
|
+
this.client = props.client;
|
|
32973
|
+
}
|
|
32974
|
+
static create(props) {
|
|
32975
|
+
const tags = context2.get("tags", { optional: true });
|
|
32976
|
+
const executionFinished = context2.get("executionFinished", { optional: true });
|
|
32977
|
+
if (executionFinished) {
|
|
32978
|
+
throw new Error(`Cannot create new TrackedTags "${props.type}/${props.id}" after execution has finished.`);
|
|
32979
|
+
}
|
|
32980
|
+
const match2 = tags?.find((x) => x.id === props.id && x.type === props.type);
|
|
32981
|
+
if (match2) {
|
|
32982
|
+
return match2;
|
|
32983
|
+
}
|
|
32984
|
+
const instance = new _TrackedTags(props);
|
|
32985
|
+
if (props.initialTags) {
|
|
32986
|
+
instance._tags = { ...props.initialTags };
|
|
32987
|
+
instance._initialTags = { ...props.initialTags };
|
|
32988
|
+
instance._loaded = true;
|
|
32989
|
+
}
|
|
32990
|
+
tags?.push(instance);
|
|
32991
|
+
return instance;
|
|
32992
|
+
}
|
|
32993
|
+
static async saveAllDirty() {
|
|
32994
|
+
if (this._savingAll) {
|
|
32995
|
+
this._saveAllAgain = true;
|
|
32996
|
+
return;
|
|
32997
|
+
}
|
|
32998
|
+
try {
|
|
32999
|
+
this._savingAll = true;
|
|
33000
|
+
const tags = context2.get("tags", { optional: true });
|
|
33001
|
+
const dirtyTags = tags?.filter((t) => t.isDirty()) || [];
|
|
33002
|
+
if (!dirtyTags.length) {
|
|
33003
|
+
return;
|
|
33004
|
+
}
|
|
33005
|
+
await span(
|
|
33006
|
+
"tags.saveAllDirty",
|
|
33007
|
+
{
|
|
33008
|
+
tags_count: tags?.length || 0,
|
|
33009
|
+
tags: tags.map((t) => `${t.type}/${t.id}`)
|
|
33010
|
+
},
|
|
33011
|
+
() => Promise.allSettled(dirtyTags.map((t) => t.save()))
|
|
33012
|
+
);
|
|
33013
|
+
} finally {
|
|
33014
|
+
this._savingAll = false;
|
|
33015
|
+
if (this._saveAllAgain && this._saveAllCount++ <= 5) {
|
|
33016
|
+
this._saveAllAgain = false;
|
|
33017
|
+
await this.saveAllDirty();
|
|
33018
|
+
} else {
|
|
33019
|
+
this._saveAllCount = 0;
|
|
33020
|
+
}
|
|
33021
|
+
}
|
|
33022
|
+
}
|
|
33023
|
+
static async loadAll() {
|
|
33024
|
+
await span("tags.loadAll", {}, async () => {
|
|
33025
|
+
const client2 = context2.get("client")._inner;
|
|
33026
|
+
const bot2 = context2.get("bot", { optional: true });
|
|
33027
|
+
const user2 = context2.get("user", { optional: true });
|
|
33028
|
+
const conversation = context2.get("conversation", { optional: true });
|
|
33029
|
+
const workflow = context2.get("workflow", { optional: true });
|
|
33030
|
+
if (bot2) {
|
|
33031
|
+
const botTags = bot2.tags;
|
|
33032
|
+
_TrackedTags.create({
|
|
33033
|
+
client: client2,
|
|
33034
|
+
type: "bot",
|
|
33035
|
+
id: bot2.id,
|
|
33036
|
+
...botTags && { initialTags: botTags }
|
|
33037
|
+
});
|
|
33038
|
+
}
|
|
33039
|
+
if (user2) {
|
|
33040
|
+
const userTags = user2.tags;
|
|
33041
|
+
_TrackedTags.create({
|
|
33042
|
+
client: client2,
|
|
33043
|
+
type: "user",
|
|
33044
|
+
id: user2.id,
|
|
33045
|
+
...userTags && { initialTags: userTags }
|
|
33046
|
+
});
|
|
33047
|
+
}
|
|
33048
|
+
if (conversation) {
|
|
33049
|
+
const conversationTags = conversation.tags;
|
|
33050
|
+
_TrackedTags.create({
|
|
33051
|
+
client: client2,
|
|
33052
|
+
type: "conversation",
|
|
33053
|
+
id: conversation.id,
|
|
33054
|
+
...conversationTags && { initialTags: conversationTags }
|
|
33055
|
+
});
|
|
33056
|
+
}
|
|
33057
|
+
if (workflow) {
|
|
33058
|
+
const workflowTags = workflow.tags;
|
|
33059
|
+
_TrackedTags.create({
|
|
33060
|
+
client: client2,
|
|
33061
|
+
type: "workflow",
|
|
33062
|
+
id: workflow.id,
|
|
33063
|
+
...workflowTags && { initialTags: workflowTags }
|
|
33064
|
+
});
|
|
33065
|
+
}
|
|
33066
|
+
const tags = context2.get("tags", { optional: true });
|
|
33067
|
+
const unloadedTags = tags?.filter((tag) => !tag._loaded) ?? [];
|
|
33068
|
+
if (unloadedTags.length > 0) {
|
|
33069
|
+
await Promise.allSettled(unloadedTags.map((tag) => tag.load()));
|
|
33070
|
+
}
|
|
33071
|
+
});
|
|
33072
|
+
}
|
|
33073
|
+
static unloadAll() {
|
|
33074
|
+
context2.get("tags", { optional: true })?.splice(0);
|
|
33075
|
+
}
|
|
33076
|
+
async load(force = false) {
|
|
33077
|
+
if (this._loaded && !force) {
|
|
33078
|
+
return;
|
|
33079
|
+
}
|
|
33080
|
+
await span(
|
|
33081
|
+
"tags.load",
|
|
33082
|
+
{
|
|
33083
|
+
type: this.type,
|
|
33084
|
+
id: this.id
|
|
33085
|
+
},
|
|
33086
|
+
async () => {
|
|
33087
|
+
const tags = await this.fetchTags();
|
|
33088
|
+
this._tags = { ...tags };
|
|
33089
|
+
this._initialTags = { ...tags };
|
|
33090
|
+
this._loaded = true;
|
|
33091
|
+
}
|
|
33092
|
+
);
|
|
33093
|
+
}
|
|
33094
|
+
async save() {
|
|
33095
|
+
if (this._saving) {
|
|
33096
|
+
this._saveAgain = true;
|
|
33097
|
+
return;
|
|
33098
|
+
}
|
|
33099
|
+
const executionFinished = context2.get("executionFinished", { optional: true });
|
|
33100
|
+
if (executionFinished) {
|
|
33101
|
+
throw new Error(`Cannot save TrackedTags "${this.type}/${this.id}" after execution has finished.`);
|
|
33102
|
+
}
|
|
33103
|
+
try {
|
|
33104
|
+
this._saving = true;
|
|
33105
|
+
await span(
|
|
33106
|
+
"tags.save",
|
|
33107
|
+
{
|
|
33108
|
+
type: this.type,
|
|
33109
|
+
id: this.id
|
|
33110
|
+
},
|
|
33111
|
+
async () => {
|
|
33112
|
+
await this.persistTags(this._tags);
|
|
33113
|
+
this._initialTags = { ...this._tags };
|
|
33114
|
+
}
|
|
33115
|
+
);
|
|
33116
|
+
} finally {
|
|
33117
|
+
this._saving = false;
|
|
33118
|
+
if (this._saveAgain && this._saveAgainCount++ <= 5) {
|
|
33119
|
+
this._saveAgain = false;
|
|
33120
|
+
await this.save();
|
|
33121
|
+
} else {
|
|
33122
|
+
this._saveAgainCount = 0;
|
|
33123
|
+
}
|
|
33124
|
+
}
|
|
33125
|
+
}
|
|
33126
|
+
isDirty() {
|
|
33127
|
+
const currentKeys = Object.keys(this._tags).filter((k) => !k.includes(":")).sort();
|
|
33128
|
+
const initialKeys = Object.keys(this._initialTags).filter((k) => !k.includes(":")).sort();
|
|
33129
|
+
if (currentKeys.length !== initialKeys.length) {
|
|
33130
|
+
return true;
|
|
33131
|
+
}
|
|
33132
|
+
for (const key of currentKeys) {
|
|
33133
|
+
if (this._tags[key] !== this._initialTags[key]) {
|
|
33134
|
+
return true;
|
|
33135
|
+
}
|
|
33136
|
+
}
|
|
33137
|
+
return false;
|
|
33138
|
+
}
|
|
33139
|
+
get tags() {
|
|
33140
|
+
return new Proxy(this._tags, {
|
|
33141
|
+
set: (target, prop, value) => {
|
|
33142
|
+
target[prop] = value;
|
|
33143
|
+
return true;
|
|
33144
|
+
},
|
|
33145
|
+
deleteProperty: (target, prop) => {
|
|
33146
|
+
target[prop] = void 0;
|
|
33147
|
+
return true;
|
|
33148
|
+
}
|
|
33149
|
+
});
|
|
33150
|
+
}
|
|
33151
|
+
set tags(value) {
|
|
33152
|
+
this._tags = { ...value };
|
|
33153
|
+
}
|
|
33154
|
+
async fetchTags() {
|
|
33155
|
+
try {
|
|
33156
|
+
if (this.type === "bot") {
|
|
33157
|
+
const { bot: bot2 } = await this.client.getBot({ id: this.id });
|
|
33158
|
+
return bot2.tags || {};
|
|
33159
|
+
} else if (this.type === "user") {
|
|
33160
|
+
const { user: user2 } = await this.client.getUser({ id: this.id });
|
|
33161
|
+
return user2.tags || {};
|
|
33162
|
+
} else if (this.type === "conversation") {
|
|
33163
|
+
const { conversation } = await this.client.getConversation({ id: this.id });
|
|
33164
|
+
return conversation.tags || {};
|
|
33165
|
+
} else if (this.type === "workflow") {
|
|
33166
|
+
const { workflow } = await this.client.getWorkflow({ id: this.id });
|
|
33167
|
+
return workflow.tags || {};
|
|
33168
|
+
}
|
|
33169
|
+
} catch (err) {
|
|
33170
|
+
console.error(`Failed to fetch tags for ${this.type}/${this.id}:`, err);
|
|
33171
|
+
}
|
|
33172
|
+
return {};
|
|
33173
|
+
}
|
|
33174
|
+
async persistTags(tags) {
|
|
33175
|
+
const tagsForApi = {};
|
|
33176
|
+
for (const [key, value] of Object.entries(tags)) {
|
|
33177
|
+
if (value !== void 0 && !key.includes(":")) {
|
|
33178
|
+
tagsForApi[key] = value;
|
|
33179
|
+
}
|
|
33180
|
+
}
|
|
33181
|
+
try {
|
|
33182
|
+
if (this.type === "bot") {
|
|
33183
|
+
await this.client.updateBot({ id: this.id, tags: tagsForApi });
|
|
33184
|
+
} else if (this.type === "user") {
|
|
33185
|
+
await this.client.updateUser({ id: this.id, tags: tagsForApi });
|
|
33186
|
+
} else if (this.type === "conversation") {
|
|
33187
|
+
await this.client.updateConversation({ id: this.id, tags: tagsForApi });
|
|
33188
|
+
} else if (this.type === "workflow") {
|
|
33189
|
+
await this.client.updateWorkflow({ id: this.id, tags: tagsForApi });
|
|
33190
|
+
}
|
|
33191
|
+
} catch (err) {
|
|
33192
|
+
console.error(`Failed to persist tags for ${this.type}/${this.id}:`, err);
|
|
33193
|
+
throw err;
|
|
33194
|
+
}
|
|
33195
|
+
}
|
|
33196
|
+
};
|
|
33197
|
+
}
|
|
33198
|
+
});
|
|
33199
|
+
|
|
32947
33200
|
// src/runtime/heavy-imports.ts
|
|
32948
33201
|
var HEAVY_IMPORTS, clearScheduledHeavyImports, importScheduledHeavyImports;
|
|
32949
33202
|
var init_heavy_imports = __esm({
|
|
@@ -33058,6 +33311,7 @@ var init_handlers = __esm({
|
|
|
33058
33311
|
init_http2();
|
|
33059
33312
|
init_agent_registry();
|
|
33060
33313
|
init_tracked_state();
|
|
33314
|
+
init_tracked_tags();
|
|
33061
33315
|
init_tracing();
|
|
33062
33316
|
init_heavy_imports();
|
|
33063
33317
|
init_environment();
|
|
@@ -33854,6 +34108,9 @@ Always prefer information from the knowledge bases over general knowledge when a
|
|
|
33854
34108
|
...props.hooks?.onBeforeTool && {
|
|
33855
34109
|
onBeforeTool: asyncResource.bind(props.hooks.onBeforeTool)
|
|
33856
34110
|
},
|
|
34111
|
+
...props.hooks?.onIterationStart && {
|
|
34112
|
+
onIterationStart: asyncResource.bind(props.hooks.onIterationStart)
|
|
34113
|
+
},
|
|
33857
34114
|
...props.hooks?.onAfterTool && {
|
|
33858
34115
|
onAfterTool: asyncResource.bind(props.hooks.onAfterTool)
|
|
33859
34116
|
},
|
|
@@ -34318,47 +34575,6 @@ var init_asset = __esm({
|
|
|
34318
34575
|
}
|
|
34319
34576
|
});
|
|
34320
34577
|
|
|
34321
|
-
// src/utilities/trigger-tags.ts
|
|
34322
|
-
var trigger_tags_exports = {};
|
|
34323
|
-
__export(trigger_tags_exports, {
|
|
34324
|
-
getTriggerSubscriptionTags: () => getTriggerSubscriptionTags,
|
|
34325
|
-
getTriggerTagName: () => getTriggerTagName,
|
|
34326
|
-
getTriggerTagValue: () => getTriggerTagValue,
|
|
34327
|
-
isConversationSubscribedToTrigger: () => isConversationSubscribedToTrigger
|
|
34328
|
-
});
|
|
34329
|
-
import crypto2 from "crypto";
|
|
34330
|
-
var hashString, getTriggerTagName, getTriggerTagValue, getTriggerSubscriptionTags, isConversationSubscribedToTrigger;
|
|
34331
|
-
var init_trigger_tags = __esm({
|
|
34332
|
-
"src/utilities/trigger-tags.ts"() {
|
|
34333
|
-
"use strict";
|
|
34334
|
-
init_define_BUILD();
|
|
34335
|
-
init_define_PACKAGE_VERSIONS();
|
|
34336
|
-
hashString = (str) => {
|
|
34337
|
-
return crypto2.createHash("md5").update(str).digest("hex").substring(0, 5).toUpperCase();
|
|
34338
|
-
};
|
|
34339
|
-
getTriggerTagName = (triggerName) => {
|
|
34340
|
-
return `trigger${hashString(triggerName)}`;
|
|
34341
|
-
};
|
|
34342
|
-
getTriggerTagValue = (key) => {
|
|
34343
|
-
return key ?? "*";
|
|
34344
|
-
};
|
|
34345
|
-
getTriggerSubscriptionTags = (triggerName, key) => {
|
|
34346
|
-
return {
|
|
34347
|
-
name: getTriggerTagName(triggerName),
|
|
34348
|
-
value: getTriggerTagValue(key)
|
|
34349
|
-
};
|
|
34350
|
-
};
|
|
34351
|
-
isConversationSubscribedToTrigger = (conversationTags, triggerName, triggerKey) => {
|
|
34352
|
-
const tagName = getTriggerTagName(triggerName);
|
|
34353
|
-
const tagValue = conversationTags[tagName];
|
|
34354
|
-
if (!tagValue) {
|
|
34355
|
-
return false;
|
|
34356
|
-
}
|
|
34357
|
-
return tagValue === "*" || tagValue === triggerKey;
|
|
34358
|
-
};
|
|
34359
|
-
}
|
|
34360
|
-
});
|
|
34361
|
-
|
|
34362
34578
|
// src/primitives/conversation-instance.ts
|
|
34363
34579
|
var BaseConversationInstance;
|
|
34364
34580
|
var init_conversation_instance = __esm({
|
|
@@ -34473,38 +34689,6 @@ var init_conversation_instance = __esm({
|
|
|
34473
34689
|
});
|
|
34474
34690
|
}
|
|
34475
34691
|
}
|
|
34476
|
-
/**
|
|
34477
|
-
* Subscribe to a trigger
|
|
34478
|
-
*/
|
|
34479
|
-
async subscribeToTrigger(triggerName, key) {
|
|
34480
|
-
const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
|
|
34481
|
-
if (isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
|
|
34482
|
-
return;
|
|
34483
|
-
}
|
|
34484
|
-
const { name, value } = getTriggerSubscriptionTags2(triggerName, key);
|
|
34485
|
-
await this.client.updateConversation({
|
|
34486
|
-
id: this.id,
|
|
34487
|
-
tags: {
|
|
34488
|
-
[name]: value
|
|
34489
|
-
}
|
|
34490
|
-
});
|
|
34491
|
-
}
|
|
34492
|
-
/**
|
|
34493
|
-
* Unsubscribe from a trigger
|
|
34494
|
-
*/
|
|
34495
|
-
async unsubscribeFromTrigger(triggerName, key) {
|
|
34496
|
-
const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
|
|
34497
|
-
if (!isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
|
|
34498
|
-
return;
|
|
34499
|
-
}
|
|
34500
|
-
const { name } = getTriggerSubscriptionTags2(triggerName, key);
|
|
34501
|
-
await this.client.updateConversation({
|
|
34502
|
-
id: this.id,
|
|
34503
|
-
tags: {
|
|
34504
|
-
[name]: ""
|
|
34505
|
-
}
|
|
34506
|
-
});
|
|
34507
|
-
}
|
|
34508
34692
|
};
|
|
34509
34693
|
}
|
|
34510
34694
|
});
|
|
@@ -36811,7 +36995,7 @@ var init_source_website = __esm({
|
|
|
36811
36995
|
type: "website",
|
|
36812
36996
|
state: State,
|
|
36813
36997
|
async handler({ input, step: step2, state, client: client2 }) {
|
|
36814
|
-
const
|
|
36998
|
+
const crypto2 = await import("crypto");
|
|
36815
36999
|
console.log(
|
|
36816
37000
|
`Starting sync for WebsiteSource [${this.id}] in mode [${this.mode}, maxPages=${this.maxPages}, maxDepth=${this.maxDepth}, baseUrl=${this.baseUrl}, sitemapUrl=${this.sitemapUrl}]`
|
|
36817
37001
|
);
|
|
@@ -36893,7 +37077,7 @@ var init_source_website = __esm({
|
|
|
36893
37077
|
content,
|
|
36894
37078
|
metadata: fetchMetadata
|
|
36895
37079
|
} = await this.fetchUrl(sitemapUrl.loc);
|
|
36896
|
-
const hash =
|
|
37080
|
+
const hash = crypto2.createHash("sha256").update(content).digest("hex");
|
|
36897
37081
|
let contentType = fetchedContentType;
|
|
36898
37082
|
if (!contentType) {
|
|
36899
37083
|
contentType = content.includes("<html") ? "text/html" : "text/markdown";
|
|
@@ -43890,7 +44074,7 @@ var init_source_directory = __esm({
|
|
|
43890
44074
|
const glob2 = await Promise.resolve().then(() => (init_esm9(), esm_exports3));
|
|
43891
44075
|
const path4 = await import("path");
|
|
43892
44076
|
const fs3 = await import("fs/promises");
|
|
43893
|
-
const
|
|
44077
|
+
const crypto2 = await import("crypto");
|
|
43894
44078
|
const directory = path4.resolve(adk.environment.agent.directory, this.directoryPath);
|
|
43895
44079
|
const tags = {
|
|
43896
44080
|
[WellKnownTags.knowledge.KNOWLEDGE]: "knowledge-base",
|
|
@@ -43952,7 +44136,7 @@ var init_source_directory = __esm({
|
|
|
43952
44136
|
const upsertFile = async (local) => {
|
|
43953
44137
|
const key = `data_source://${this.type}/${this.id}/${local.rel}`;
|
|
43954
44138
|
const content = await fs3.readFile(local.abs);
|
|
43955
|
-
const hash =
|
|
44139
|
+
const hash = crypto2.createHash("sha256").update(content).digest("hex");
|
|
43956
44140
|
const { file } = await client2.getFile({ id: key }).catch(() => ({ file: null }));
|
|
43957
44141
|
if (!input.force && file?.metadata?.hash === hash) {
|
|
43958
44142
|
console.log(`Skipping unchanged file: ${local.rel}`);
|
|
@@ -44070,19 +44254,11 @@ var init_conversation = __esm({
|
|
|
44070
44254
|
/** @internal */
|
|
44071
44255
|
schema;
|
|
44072
44256
|
#handler;
|
|
44073
|
-
#startFromTrigger;
|
|
44074
44257
|
constructor(props) {
|
|
44075
44258
|
this.channel = props.channel;
|
|
44076
44259
|
this.events = props.events ?? [];
|
|
44077
44260
|
this.schema = props.state ?? z13.object({}).passthrough();
|
|
44078
44261
|
this.#handler = props.handler;
|
|
44079
|
-
if (props.startFromTrigger) {
|
|
44080
|
-
this.#startFromTrigger = props.startFromTrigger;
|
|
44081
|
-
}
|
|
44082
|
-
}
|
|
44083
|
-
/** @internal */
|
|
44084
|
-
get startFromTrigger() {
|
|
44085
|
-
return this.#startFromTrigger;
|
|
44086
44262
|
}
|
|
44087
44263
|
/** @internal */
|
|
44088
44264
|
getDefinition() {
|
|
@@ -44434,15 +44610,25 @@ var init_validate_tag_name = __esm({
|
|
|
44434
44610
|
}
|
|
44435
44611
|
});
|
|
44436
44612
|
|
|
44613
|
+
// src/utilities/validate-event-name.ts
|
|
44614
|
+
var init_validate_event_name = __esm({
|
|
44615
|
+
"src/utilities/validate-event-name.ts"() {
|
|
44616
|
+
"use strict";
|
|
44617
|
+
init_define_BUILD();
|
|
44618
|
+
init_define_PACKAGE_VERSIONS();
|
|
44619
|
+
}
|
|
44620
|
+
});
|
|
44621
|
+
|
|
44437
44622
|
// src/define-config.ts
|
|
44438
44623
|
import { z as z14 } from "@botpress/sdk";
|
|
44439
|
-
var zuiSchema, modelSchema, tagDefinitionSchema, configSchema, AGENT_CONFIG_BRAND;
|
|
44624
|
+
var zuiSchema, modelSchema, tagDefinitionSchema, eventDefinitionSchema, configSchema, AGENT_CONFIG_BRAND;
|
|
44440
44625
|
var init_define_config = __esm({
|
|
44441
44626
|
"src/define-config.ts"() {
|
|
44442
44627
|
"use strict";
|
|
44443
44628
|
init_define_BUILD();
|
|
44444
44629
|
init_define_PACKAGE_VERSIONS();
|
|
44445
44630
|
init_validate_tag_name();
|
|
44631
|
+
init_validate_event_name();
|
|
44446
44632
|
zuiSchema = z14.custom(
|
|
44447
44633
|
(val) => {
|
|
44448
44634
|
if (typeof val === "object" && val !== null && "parse" in val) {
|
|
@@ -44467,6 +44653,13 @@ var init_define_config = __esm({
|
|
|
44467
44653
|
description: z14.string().optional()
|
|
44468
44654
|
})
|
|
44469
44655
|
);
|
|
44656
|
+
eventDefinitionSchema = z14.record(
|
|
44657
|
+
z14.string(),
|
|
44658
|
+
z14.object({
|
|
44659
|
+
schema: zuiSchema.optional(),
|
|
44660
|
+
description: z14.string().optional()
|
|
44661
|
+
})
|
|
44662
|
+
);
|
|
44470
44663
|
configSchema = z14.object({
|
|
44471
44664
|
name: z14.string().optional(),
|
|
44472
44665
|
description: z14.string().optional(),
|
|
@@ -44507,7 +44700,8 @@ var init_define_config = __esm({
|
|
|
44507
44700
|
zai: val?.zai ?? "openai:gpt-4.1-2025-04-14",
|
|
44508
44701
|
autonomous: val?.autonomous ?? "openai:gpt-4.1-mini-2025-04-14"
|
|
44509
44702
|
})),
|
|
44510
|
-
dependencies: z14.custom()
|
|
44703
|
+
dependencies: z14.custom(),
|
|
44704
|
+
events: eventDefinitionSchema.optional()
|
|
44511
44705
|
});
|
|
44512
44706
|
AGENT_CONFIG_BRAND = Symbol.for("@botpress/runtime/AgentConfig");
|
|
44513
44707
|
}
|
|
@@ -44526,7 +44720,6 @@ var init_runtime = __esm({
|
|
|
44526
44720
|
init_structured_logging();
|
|
44527
44721
|
init_environment();
|
|
44528
44722
|
init_runtime2();
|
|
44529
|
-
init_trigger_tags();
|
|
44530
44723
|
init_types2();
|
|
44531
44724
|
init_errors();
|
|
44532
44725
|
init_state();
|
|
@@ -44999,12 +45192,12 @@ var init_workflow_step = __esm({
|
|
|
44999
45192
|
workflowControlContext.abort();
|
|
45000
45193
|
throw createStepSignal();
|
|
45001
45194
|
};
|
|
45002
|
-
step.sleep = async (name,
|
|
45195
|
+
step.sleep = async (name, ms4) => {
|
|
45003
45196
|
await _step(
|
|
45004
45197
|
name,
|
|
45005
45198
|
async () => {
|
|
45006
45199
|
const remainingTime = context2.get("runtime").getRemainingExecutionTimeInMs();
|
|
45007
|
-
if (remainingTime - MIN_STEP_REMAINING_TIME_MS <=
|
|
45200
|
+
if (remainingTime - MIN_STEP_REMAINING_TIME_MS <= ms4 || ms4 >= 1e4) {
|
|
45008
45201
|
const client2 = context2.get("client");
|
|
45009
45202
|
const workflowControlContext = context2.get("workflowControlContext");
|
|
45010
45203
|
await client2.createEvent({
|
|
@@ -45012,7 +45205,7 @@ var init_workflow_step = __esm({
|
|
|
45012
45205
|
payload: {},
|
|
45013
45206
|
workflowId: workflowControlContext.workflow.id,
|
|
45014
45207
|
schedule: {
|
|
45015
|
-
delay:
|
|
45208
|
+
delay: ms4
|
|
45016
45209
|
}
|
|
45017
45210
|
});
|
|
45018
45211
|
await updateWorkflow({
|
|
@@ -45021,7 +45214,7 @@ var init_workflow_step = __esm({
|
|
|
45021
45214
|
});
|
|
45022
45215
|
workflowControlContext.abort();
|
|
45023
45216
|
} else {
|
|
45024
|
-
await new Promise((resolve) => void setTimeout(resolve,
|
|
45217
|
+
await new Promise((resolve) => void setTimeout(resolve, ms4));
|
|
45025
45218
|
context2.get("workflowControlContext").signal.throwIfAborted();
|
|
45026
45219
|
}
|
|
45027
45220
|
},
|
|
@@ -45032,8 +45225,8 @@ var init_workflow_step = __esm({
|
|
|
45032
45225
|
);
|
|
45033
45226
|
};
|
|
45034
45227
|
step.sleepUntil = async (name, date) => {
|
|
45035
|
-
const
|
|
45036
|
-
await step.sleep(name,
|
|
45228
|
+
const ms4 = Math.max(0, new Date(date).getTime() - Date.now() - MIN_STEP_REMAINING_TIME_MS);
|
|
45229
|
+
await step.sleep(name, ms4);
|
|
45037
45230
|
};
|
|
45038
45231
|
step.waitForWorkflow = async (name, workflowId) => {
|
|
45039
45232
|
const workflowControlContext = context2.get("workflowControlContext");
|
|
@@ -45252,12 +45445,13 @@ function createWorkflowExecutionState(client2, workflowId) {
|
|
|
45252
45445
|
name: BUILT_IN_STATES.workflowSteps
|
|
45253
45446
|
});
|
|
45254
45447
|
}
|
|
45255
|
-
var workflowStepContextSchema, workflowExecutionContextSchema, StepSymbol, BaseWorkflowInstance;
|
|
45448
|
+
var import_ms, workflowStepContextSchema, workflowExecutionContextSchema, StepSymbol, BaseWorkflowInstance;
|
|
45256
45449
|
var init_workflow_instance = __esm({
|
|
45257
45450
|
"src/primitives/workflow-instance.ts"() {
|
|
45258
45451
|
"use strict";
|
|
45259
45452
|
init_define_BUILD();
|
|
45260
45453
|
init_define_PACKAGE_VERSIONS();
|
|
45454
|
+
import_ms = __toESM(require_ms(), 1);
|
|
45261
45455
|
init_errors();
|
|
45262
45456
|
init_library();
|
|
45263
45457
|
init_autonomous();
|
|
@@ -45384,6 +45578,81 @@ var init_workflow_instance = __esm({
|
|
|
45384
45578
|
});
|
|
45385
45579
|
Object.assign(this.workflow, workflow);
|
|
45386
45580
|
}
|
|
45581
|
+
/**
|
|
45582
|
+
* Extend the workflow timeout by setting a new timeout.
|
|
45583
|
+
* This is useful for long-running workflows that need more time to complete.
|
|
45584
|
+
*
|
|
45585
|
+
* @param options - Either `{ in: string }` for relative duration or `{ at: string }` for absolute ISO timestamp
|
|
45586
|
+
* @returns A promise that resolves when the timeout is updated (can be awaited or not)
|
|
45587
|
+
* @example
|
|
45588
|
+
* // Relative timeout (duration from now):
|
|
45589
|
+
* workflow.setTimeout({ in: '30m' }) // Timeout in 30 minutes
|
|
45590
|
+
* workflow.setTimeout({ in: '6 hours' }) // Timeout in 6 hours
|
|
45591
|
+
*
|
|
45592
|
+
* // Absolute timeout (ISO timestamp):
|
|
45593
|
+
* workflow.setTimeout({ at: '2024-12-25T00:00:00Z' })
|
|
45594
|
+
*
|
|
45595
|
+
* // Optionally await if you need to ensure the update completes:
|
|
45596
|
+
* await workflow.setTimeout({ in: '1h' })
|
|
45597
|
+
*/
|
|
45598
|
+
setTimeout(options) {
|
|
45599
|
+
let newTimeoutAt;
|
|
45600
|
+
if ("in" in options) {
|
|
45601
|
+
const durationMs = (0, import_ms.default)(options.in);
|
|
45602
|
+
if (!durationMs) {
|
|
45603
|
+
throw new Error(`Invalid duration format: "${options.in}". Use formats like "30m", "1h", "6 hours".`);
|
|
45604
|
+
}
|
|
45605
|
+
newTimeoutAt = new Date(Date.now() + durationMs).toISOString();
|
|
45606
|
+
} else {
|
|
45607
|
+
const date = new Date(options.at);
|
|
45608
|
+
if (isNaN(date.getTime())) {
|
|
45609
|
+
throw new Error(`Invalid ISO date format: "${options.at}".`);
|
|
45610
|
+
}
|
|
45611
|
+
newTimeoutAt = date.toISOString();
|
|
45612
|
+
}
|
|
45613
|
+
return updateWorkflow({
|
|
45614
|
+
id: this.id,
|
|
45615
|
+
timeoutAt: newTimeoutAt
|
|
45616
|
+
}).then(({ workflow }) => {
|
|
45617
|
+
Object.assign(this.workflow, workflow);
|
|
45618
|
+
});
|
|
45619
|
+
}
|
|
45620
|
+
/**
|
|
45621
|
+
* Fail the workflow with an error reason.
|
|
45622
|
+
* This immediately interrupts the workflow handler and marks the workflow as failed.
|
|
45623
|
+
* Can only be called from within a workflow handler.
|
|
45624
|
+
*
|
|
45625
|
+
* @param reason - The error reason for the failure
|
|
45626
|
+
* @throws Never returns - always throws to interrupt the handler
|
|
45627
|
+
* @example
|
|
45628
|
+
* workflow.fail('Invalid input data')
|
|
45629
|
+
*/
|
|
45630
|
+
fail(reason) {
|
|
45631
|
+
const controlContext = context2.get("workflowControlContext", { optional: true });
|
|
45632
|
+
if (!controlContext || controlContext.workflow.id !== this.id) {
|
|
45633
|
+
throw new Error("workflow.fail() can only be called from within the workflow handler");
|
|
45634
|
+
}
|
|
45635
|
+
controlContext.fail(reason);
|
|
45636
|
+
throw createStepSignal();
|
|
45637
|
+
}
|
|
45638
|
+
/**
|
|
45639
|
+
* Complete the workflow early with the given output.
|
|
45640
|
+
* This immediately interrupts the workflow handler and marks the workflow as completed.
|
|
45641
|
+
* Can only be called from within a workflow handler.
|
|
45642
|
+
*
|
|
45643
|
+
* @param output - The workflow output (typed according to workflow definition)
|
|
45644
|
+
* @throws Never returns - always throws to interrupt the handler
|
|
45645
|
+
* @example
|
|
45646
|
+
* workflow.complete({ result: 'success', data: processedData })
|
|
45647
|
+
*/
|
|
45648
|
+
complete(output2) {
|
|
45649
|
+
const controlContext = context2.get("workflowControlContext", { optional: true });
|
|
45650
|
+
if (!controlContext || controlContext.workflow.id !== this.id) {
|
|
45651
|
+
throw new Error("workflow.complete() can only be called from within the workflow handler");
|
|
45652
|
+
}
|
|
45653
|
+
controlContext.complete(output2);
|
|
45654
|
+
throw createStepSignal();
|
|
45655
|
+
}
|
|
45387
45656
|
/**
|
|
45388
45657
|
* Provide data in response to a workflow data request (instance method).
|
|
45389
45658
|
* Call this method from a conversation handler when you receive a WorkflowDataRequestEvent.
|
|
@@ -45434,6 +45703,7 @@ var init_workflow_instance = __esm({
|
|
|
45434
45703
|
workflow: this.workflow,
|
|
45435
45704
|
aborted: false,
|
|
45436
45705
|
failed: false,
|
|
45706
|
+
completed: false,
|
|
45437
45707
|
acked: false,
|
|
45438
45708
|
restarted: false,
|
|
45439
45709
|
signal: abortSignal,
|
|
@@ -45448,6 +45718,10 @@ var init_workflow_instance = __esm({
|
|
|
45448
45718
|
workflowControlContext.failed = true;
|
|
45449
45719
|
workflowControlContext.failedReason = reason;
|
|
45450
45720
|
},
|
|
45721
|
+
complete: (result) => {
|
|
45722
|
+
workflowControlContext.completed = true;
|
|
45723
|
+
workflowControlContext.completedResult = result;
|
|
45724
|
+
},
|
|
45451
45725
|
ack: async () => {
|
|
45452
45726
|
if (workflowControlContext.acked) {
|
|
45453
45727
|
return;
|
|
@@ -45501,7 +45775,8 @@ var init_workflow_instance = __esm({
|
|
|
45501
45775
|
step,
|
|
45502
45776
|
client: this.client,
|
|
45503
45777
|
execute: this.execute.bind(this),
|
|
45504
|
-
signal: abortSignal
|
|
45778
|
+
signal: abortSignal,
|
|
45779
|
+
workflow: this
|
|
45505
45780
|
});
|
|
45506
45781
|
return {
|
|
45507
45782
|
status: "done",
|
|
@@ -45512,6 +45787,12 @@ var init_workflow_instance = __esm({
|
|
|
45512
45787
|
}
|
|
45513
45788
|
} catch (err) {
|
|
45514
45789
|
if (isStepSignal(err)) {
|
|
45790
|
+
if (workflowControlContext.completed) {
|
|
45791
|
+
return {
|
|
45792
|
+
status: "done",
|
|
45793
|
+
result: workflowControlContext.completedResult
|
|
45794
|
+
};
|
|
45795
|
+
}
|
|
45515
45796
|
if (workflowControlContext.failed) {
|
|
45516
45797
|
return {
|
|
45517
45798
|
status: "error",
|
|
@@ -45566,7 +45847,7 @@ var init_workflow_instance = __esm({
|
|
|
45566
45847
|
|
|
45567
45848
|
// src/primitives/workflow.ts
|
|
45568
45849
|
import { z as z23 } from "@botpress/sdk";
|
|
45569
|
-
var
|
|
45850
|
+
var import_ms2, WorkflowHandler, Typings7, BaseWorkflow;
|
|
45570
45851
|
var init_workflow = __esm({
|
|
45571
45852
|
"src/primitives/workflow.ts"() {
|
|
45572
45853
|
"use strict";
|
|
@@ -45574,7 +45855,7 @@ var init_workflow = __esm({
|
|
|
45574
45855
|
init_define_PACKAGE_VERSIONS();
|
|
45575
45856
|
init_workflow_instance();
|
|
45576
45857
|
init_context3();
|
|
45577
|
-
|
|
45858
|
+
import_ms2 = __toESM(require_ms(), 1);
|
|
45578
45859
|
init_autonomous();
|
|
45579
45860
|
init_runtime();
|
|
45580
45861
|
WorkflowHandler = Symbol.for("workflow.handler");
|
|
@@ -45596,7 +45877,7 @@ var init_workflow = __esm({
|
|
|
45596
45877
|
_handler;
|
|
45597
45878
|
/** @internal */
|
|
45598
45879
|
schedule;
|
|
45599
|
-
timeout = (0,
|
|
45880
|
+
timeout = (0, import_ms2.default)("5m");
|
|
45600
45881
|
constructor(props) {
|
|
45601
45882
|
this.name = props.name;
|
|
45602
45883
|
if (props.description !== void 0) {
|
|
@@ -45609,7 +45890,7 @@ var init_workflow = __esm({
|
|
|
45609
45890
|
this._handler = props.handler;
|
|
45610
45891
|
this.schedule = props.schedule;
|
|
45611
45892
|
if (props.timeout) {
|
|
45612
|
-
this.timeout = (0,
|
|
45893
|
+
this.timeout = (0, import_ms2.default)(props.timeout);
|
|
45613
45894
|
}
|
|
45614
45895
|
}
|
|
45615
45896
|
// @internal
|
|
@@ -45665,7 +45946,7 @@ var init_workflow = __esm({
|
|
|
45665
45946
|
tags,
|
|
45666
45947
|
conversationId: context2.get("conversation", { optional: true })?.id,
|
|
45667
45948
|
parentWorkflowId: context2.get("workflow", { optional: true })?.id,
|
|
45668
|
-
timeoutAt: new Date(Date.now() + (this.timeout ?? (0,
|
|
45949
|
+
timeoutAt: new Date(Date.now() + (this.timeout ?? (0, import_ms2.default)("5m"))).toISOString(),
|
|
45669
45950
|
...discriminator && { discriminateBy: { tags: discriminator } }
|
|
45670
45951
|
};
|
|
45671
45952
|
let { workflow } = await client2._inner.getOrCreateWorkflow(createArgs);
|
|
@@ -45728,7 +46009,7 @@ var init_workflow = __esm({
|
|
|
45728
46009
|
input: validatedInput,
|
|
45729
46010
|
parentWorkflowId: workflow?.id,
|
|
45730
46011
|
conversationId: context2.get("conversation", { optional: true })?.id,
|
|
45731
|
-
timeoutAt: new Date(Date.now() + (this.timeout ?? (0,
|
|
46012
|
+
timeoutAt: new Date(Date.now() + (this.timeout ?? (0, import_ms2.default)("5m"))).toISOString()
|
|
45732
46013
|
});
|
|
45733
46014
|
return await BaseWorkflowInstance.load({
|
|
45734
46015
|
id: res.workflow.id,
|
|
@@ -46543,7 +46824,7 @@ var init_trigger2 = __esm({
|
|
|
46543
46824
|
});
|
|
46544
46825
|
|
|
46545
46826
|
// src/runtime/handlers/workflow.ts
|
|
46546
|
-
var
|
|
46827
|
+
var import_ms3;
|
|
46547
46828
|
var init_workflow2 = __esm({
|
|
46548
46829
|
"src/runtime/handlers/workflow.ts"() {
|
|
46549
46830
|
"use strict";
|
|
@@ -46555,7 +46836,7 @@ var init_workflow2 = __esm({
|
|
|
46555
46836
|
init_tracing();
|
|
46556
46837
|
init_adk();
|
|
46557
46838
|
init_workflow_utils();
|
|
46558
|
-
|
|
46839
|
+
import_ms3 = __toESM(require_ms(), 1);
|
|
46559
46840
|
}
|
|
46560
46841
|
});
|
|
46561
46842
|
|
|
@@ -46599,259 +46880,6 @@ var init_handlers2 = __esm({
|
|
|
46599
46880
|
}
|
|
46600
46881
|
});
|
|
46601
46882
|
|
|
46602
|
-
// src/runtime/tracked-tags.ts
|
|
46603
|
-
var TrackedTags;
|
|
46604
|
-
var init_tracked_tags = __esm({
|
|
46605
|
-
"src/runtime/tracked-tags.ts"() {
|
|
46606
|
-
"use strict";
|
|
46607
|
-
init_define_BUILD();
|
|
46608
|
-
init_define_PACKAGE_VERSIONS();
|
|
46609
|
-
init_context3();
|
|
46610
|
-
init_tracing();
|
|
46611
|
-
TrackedTags = class _TrackedTags {
|
|
46612
|
-
type;
|
|
46613
|
-
id;
|
|
46614
|
-
client;
|
|
46615
|
-
_tags = {};
|
|
46616
|
-
_initialTags = {};
|
|
46617
|
-
_loaded = false;
|
|
46618
|
-
_saving = false;
|
|
46619
|
-
_saveAgain = false;
|
|
46620
|
-
_saveAgainCount = 0;
|
|
46621
|
-
static _savingAll = false;
|
|
46622
|
-
static _saveAllAgain = false;
|
|
46623
|
-
static _saveAllCount = 0;
|
|
46624
|
-
constructor(props) {
|
|
46625
|
-
this.type = props.type;
|
|
46626
|
-
this.id = props.id;
|
|
46627
|
-
this.client = props.client;
|
|
46628
|
-
}
|
|
46629
|
-
static create(props) {
|
|
46630
|
-
const tags = context2.get("tags", { optional: true });
|
|
46631
|
-
const executionFinished = context2.get("executionFinished", { optional: true });
|
|
46632
|
-
if (executionFinished) {
|
|
46633
|
-
throw new Error(`Cannot create new TrackedTags "${props.type}/${props.id}" after execution has finished.`);
|
|
46634
|
-
}
|
|
46635
|
-
const match2 = tags?.find((x) => x.id === props.id && x.type === props.type);
|
|
46636
|
-
if (match2) {
|
|
46637
|
-
return match2;
|
|
46638
|
-
}
|
|
46639
|
-
const instance = new _TrackedTags(props);
|
|
46640
|
-
if (props.initialTags) {
|
|
46641
|
-
instance._tags = { ...props.initialTags };
|
|
46642
|
-
instance._initialTags = { ...props.initialTags };
|
|
46643
|
-
instance._loaded = true;
|
|
46644
|
-
}
|
|
46645
|
-
tags?.push(instance);
|
|
46646
|
-
return instance;
|
|
46647
|
-
}
|
|
46648
|
-
static async saveAllDirty() {
|
|
46649
|
-
if (this._savingAll) {
|
|
46650
|
-
this._saveAllAgain = true;
|
|
46651
|
-
return;
|
|
46652
|
-
}
|
|
46653
|
-
try {
|
|
46654
|
-
this._savingAll = true;
|
|
46655
|
-
const tags = context2.get("tags", { optional: true });
|
|
46656
|
-
const dirtyTags = tags?.filter((t) => t.isDirty()) || [];
|
|
46657
|
-
if (!dirtyTags.length) {
|
|
46658
|
-
return;
|
|
46659
|
-
}
|
|
46660
|
-
await span(
|
|
46661
|
-
"tags.saveAllDirty",
|
|
46662
|
-
{
|
|
46663
|
-
tags_count: tags?.length || 0,
|
|
46664
|
-
tags: tags.map((t) => `${t.type}/${t.id}`)
|
|
46665
|
-
},
|
|
46666
|
-
() => Promise.allSettled(dirtyTags.map((t) => t.save()))
|
|
46667
|
-
);
|
|
46668
|
-
} finally {
|
|
46669
|
-
this._savingAll = false;
|
|
46670
|
-
if (this._saveAllAgain && this._saveAllCount++ <= 5) {
|
|
46671
|
-
this._saveAllAgain = false;
|
|
46672
|
-
await this.saveAllDirty();
|
|
46673
|
-
} else {
|
|
46674
|
-
this._saveAllCount = 0;
|
|
46675
|
-
}
|
|
46676
|
-
}
|
|
46677
|
-
}
|
|
46678
|
-
static async loadAll() {
|
|
46679
|
-
await span("tags.loadAll", {}, async () => {
|
|
46680
|
-
const client2 = context2.get("client")._inner;
|
|
46681
|
-
const bot2 = context2.get("bot", { optional: true });
|
|
46682
|
-
const user2 = context2.get("user", { optional: true });
|
|
46683
|
-
const conversation = context2.get("conversation", { optional: true });
|
|
46684
|
-
const workflow = context2.get("workflow", { optional: true });
|
|
46685
|
-
if (bot2) {
|
|
46686
|
-
const botTags = bot2.tags;
|
|
46687
|
-
_TrackedTags.create({
|
|
46688
|
-
client: client2,
|
|
46689
|
-
type: "bot",
|
|
46690
|
-
id: bot2.id,
|
|
46691
|
-
...botTags && { initialTags: botTags }
|
|
46692
|
-
});
|
|
46693
|
-
}
|
|
46694
|
-
if (user2) {
|
|
46695
|
-
const userTags = user2.tags;
|
|
46696
|
-
_TrackedTags.create({
|
|
46697
|
-
client: client2,
|
|
46698
|
-
type: "user",
|
|
46699
|
-
id: user2.id,
|
|
46700
|
-
...userTags && { initialTags: userTags }
|
|
46701
|
-
});
|
|
46702
|
-
}
|
|
46703
|
-
if (conversation) {
|
|
46704
|
-
const conversationTags = conversation.tags;
|
|
46705
|
-
_TrackedTags.create({
|
|
46706
|
-
client: client2,
|
|
46707
|
-
type: "conversation",
|
|
46708
|
-
id: conversation.id,
|
|
46709
|
-
...conversationTags && { initialTags: conversationTags }
|
|
46710
|
-
});
|
|
46711
|
-
}
|
|
46712
|
-
if (workflow) {
|
|
46713
|
-
const workflowTags = workflow.tags;
|
|
46714
|
-
_TrackedTags.create({
|
|
46715
|
-
client: client2,
|
|
46716
|
-
type: "workflow",
|
|
46717
|
-
id: workflow.id,
|
|
46718
|
-
...workflowTags && { initialTags: workflowTags }
|
|
46719
|
-
});
|
|
46720
|
-
}
|
|
46721
|
-
const tags = context2.get("tags", { optional: true });
|
|
46722
|
-
const unloadedTags = tags?.filter((tag) => !tag._loaded) ?? [];
|
|
46723
|
-
if (unloadedTags.length > 0) {
|
|
46724
|
-
await Promise.allSettled(unloadedTags.map((tag) => tag.load()));
|
|
46725
|
-
}
|
|
46726
|
-
});
|
|
46727
|
-
}
|
|
46728
|
-
static unloadAll() {
|
|
46729
|
-
context2.get("tags", { optional: true })?.splice(0);
|
|
46730
|
-
}
|
|
46731
|
-
async load(force = false) {
|
|
46732
|
-
if (this._loaded && !force) {
|
|
46733
|
-
return;
|
|
46734
|
-
}
|
|
46735
|
-
await span(
|
|
46736
|
-
"tags.load",
|
|
46737
|
-
{
|
|
46738
|
-
type: this.type,
|
|
46739
|
-
id: this.id
|
|
46740
|
-
},
|
|
46741
|
-
async () => {
|
|
46742
|
-
const tags = await this.fetchTags();
|
|
46743
|
-
this._tags = { ...tags };
|
|
46744
|
-
this._initialTags = { ...tags };
|
|
46745
|
-
this._loaded = true;
|
|
46746
|
-
}
|
|
46747
|
-
);
|
|
46748
|
-
}
|
|
46749
|
-
async save() {
|
|
46750
|
-
if (this._saving) {
|
|
46751
|
-
this._saveAgain = true;
|
|
46752
|
-
return;
|
|
46753
|
-
}
|
|
46754
|
-
const executionFinished = context2.get("executionFinished", { optional: true });
|
|
46755
|
-
if (executionFinished) {
|
|
46756
|
-
throw new Error(`Cannot save TrackedTags "${this.type}/${this.id}" after execution has finished.`);
|
|
46757
|
-
}
|
|
46758
|
-
try {
|
|
46759
|
-
this._saving = true;
|
|
46760
|
-
await span(
|
|
46761
|
-
"tags.save",
|
|
46762
|
-
{
|
|
46763
|
-
type: this.type,
|
|
46764
|
-
id: this.id
|
|
46765
|
-
},
|
|
46766
|
-
async () => {
|
|
46767
|
-
await this.persistTags(this._tags);
|
|
46768
|
-
this._initialTags = { ...this._tags };
|
|
46769
|
-
}
|
|
46770
|
-
);
|
|
46771
|
-
} finally {
|
|
46772
|
-
this._saving = false;
|
|
46773
|
-
if (this._saveAgain && this._saveAgainCount++ <= 5) {
|
|
46774
|
-
this._saveAgain = false;
|
|
46775
|
-
await this.save();
|
|
46776
|
-
} else {
|
|
46777
|
-
this._saveAgainCount = 0;
|
|
46778
|
-
}
|
|
46779
|
-
}
|
|
46780
|
-
}
|
|
46781
|
-
isDirty() {
|
|
46782
|
-
const currentKeys = Object.keys(this._tags).sort();
|
|
46783
|
-
const initialKeys = Object.keys(this._initialTags).sort();
|
|
46784
|
-
if (currentKeys.length !== initialKeys.length) {
|
|
46785
|
-
return true;
|
|
46786
|
-
}
|
|
46787
|
-
for (const key of currentKeys) {
|
|
46788
|
-
if (this._tags[key] !== this._initialTags[key]) {
|
|
46789
|
-
return true;
|
|
46790
|
-
}
|
|
46791
|
-
}
|
|
46792
|
-
return false;
|
|
46793
|
-
}
|
|
46794
|
-
get tags() {
|
|
46795
|
-
return new Proxy(this._tags, {
|
|
46796
|
-
set: (target, prop, value) => {
|
|
46797
|
-
target[prop] = value;
|
|
46798
|
-
return true;
|
|
46799
|
-
},
|
|
46800
|
-
deleteProperty: (target, prop) => {
|
|
46801
|
-
target[prop] = void 0;
|
|
46802
|
-
return true;
|
|
46803
|
-
}
|
|
46804
|
-
});
|
|
46805
|
-
}
|
|
46806
|
-
set tags(value) {
|
|
46807
|
-
this._tags = { ...value };
|
|
46808
|
-
}
|
|
46809
|
-
async fetchTags() {
|
|
46810
|
-
try {
|
|
46811
|
-
if (this.type === "bot") {
|
|
46812
|
-
const { bot: bot2 } = await this.client.getBot({ id: this.id });
|
|
46813
|
-
return bot2.tags || {};
|
|
46814
|
-
} else if (this.type === "user") {
|
|
46815
|
-
const { user: user2 } = await this.client.getUser({ id: this.id });
|
|
46816
|
-
return user2.tags || {};
|
|
46817
|
-
} else if (this.type === "conversation") {
|
|
46818
|
-
const { conversation } = await this.client.getConversation({ id: this.id });
|
|
46819
|
-
return conversation.tags || {};
|
|
46820
|
-
} else if (this.type === "workflow") {
|
|
46821
|
-
const { workflow } = await this.client.getWorkflow({ id: this.id });
|
|
46822
|
-
return workflow.tags || {};
|
|
46823
|
-
}
|
|
46824
|
-
} catch (err) {
|
|
46825
|
-
console.error(`Failed to fetch tags for ${this.type}/${this.id}:`, err);
|
|
46826
|
-
}
|
|
46827
|
-
return {};
|
|
46828
|
-
}
|
|
46829
|
-
async persistTags(tags) {
|
|
46830
|
-
const tagsForApi = {};
|
|
46831
|
-
for (const [key, value] of Object.entries(tags)) {
|
|
46832
|
-
if (value !== void 0) {
|
|
46833
|
-
tagsForApi[key] = value;
|
|
46834
|
-
}
|
|
46835
|
-
}
|
|
46836
|
-
try {
|
|
46837
|
-
if (this.type === "bot") {
|
|
46838
|
-
await this.client.updateBot({ id: this.id, tags: tagsForApi });
|
|
46839
|
-
} else if (this.type === "user") {
|
|
46840
|
-
await this.client.updateUser({ id: this.id, tags: tagsForApi });
|
|
46841
|
-
} else if (this.type === "conversation") {
|
|
46842
|
-
await this.client.updateConversation({ id: this.id, tags: tagsForApi });
|
|
46843
|
-
} else if (this.type === "workflow") {
|
|
46844
|
-
await this.client.updateWorkflow({ id: this.id, tags: tagsForApi });
|
|
46845
|
-
}
|
|
46846
|
-
} catch (err) {
|
|
46847
|
-
console.error(`Failed to persist tags for ${this.type}/${this.id}:`, err);
|
|
46848
|
-
throw err;
|
|
46849
|
-
}
|
|
46850
|
-
}
|
|
46851
|
-
};
|
|
46852
|
-
}
|
|
46853
|
-
});
|
|
46854
|
-
|
|
46855
46883
|
// src/runtime/index.ts
|
|
46856
46884
|
var init_runtime2 = __esm({
|
|
46857
46885
|
"src/runtime/index.ts"() {
|