@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/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.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
|
|
|
@@ -61,6 +61,124 @@ var init_asset = __esm({
|
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
// ../../node_modules/ms/index.js
|
|
65
|
+
var require_ms = __commonJS({
|
|
66
|
+
"../../node_modules/ms/index.js"(exports2, module) {
|
|
67
|
+
init_define_BUILD();
|
|
68
|
+
init_define_PACKAGE_VERSIONS();
|
|
69
|
+
var s = 1e3;
|
|
70
|
+
var m = s * 60;
|
|
71
|
+
var h = m * 60;
|
|
72
|
+
var d = h * 24;
|
|
73
|
+
var w = d * 7;
|
|
74
|
+
var y = d * 365.25;
|
|
75
|
+
module.exports = function(val, options) {
|
|
76
|
+
options = options || {};
|
|
77
|
+
var type = typeof val;
|
|
78
|
+
if (type === "string" && val.length > 0) {
|
|
79
|
+
return parse(val);
|
|
80
|
+
} else if (type === "number" && isFinite(val)) {
|
|
81
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
82
|
+
}
|
|
83
|
+
throw new Error(
|
|
84
|
+
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
function parse(str) {
|
|
88
|
+
str = String(str);
|
|
89
|
+
if (str.length > 100) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var match2 = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
93
|
+
str
|
|
94
|
+
);
|
|
95
|
+
if (!match2) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
var n = parseFloat(match2[1]);
|
|
99
|
+
var type = (match2[2] || "ms").toLowerCase();
|
|
100
|
+
switch (type) {
|
|
101
|
+
case "years":
|
|
102
|
+
case "year":
|
|
103
|
+
case "yrs":
|
|
104
|
+
case "yr":
|
|
105
|
+
case "y":
|
|
106
|
+
return n * y;
|
|
107
|
+
case "weeks":
|
|
108
|
+
case "week":
|
|
109
|
+
case "w":
|
|
110
|
+
return n * w;
|
|
111
|
+
case "days":
|
|
112
|
+
case "day":
|
|
113
|
+
case "d":
|
|
114
|
+
return n * d;
|
|
115
|
+
case "hours":
|
|
116
|
+
case "hour":
|
|
117
|
+
case "hrs":
|
|
118
|
+
case "hr":
|
|
119
|
+
case "h":
|
|
120
|
+
return n * h;
|
|
121
|
+
case "minutes":
|
|
122
|
+
case "minute":
|
|
123
|
+
case "mins":
|
|
124
|
+
case "min":
|
|
125
|
+
case "m":
|
|
126
|
+
return n * m;
|
|
127
|
+
case "seconds":
|
|
128
|
+
case "second":
|
|
129
|
+
case "secs":
|
|
130
|
+
case "sec":
|
|
131
|
+
case "s":
|
|
132
|
+
return n * s;
|
|
133
|
+
case "milliseconds":
|
|
134
|
+
case "millisecond":
|
|
135
|
+
case "msecs":
|
|
136
|
+
case "msec":
|
|
137
|
+
case "ms":
|
|
138
|
+
return n;
|
|
139
|
+
default:
|
|
140
|
+
return void 0;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function fmtShort(ms4) {
|
|
144
|
+
var msAbs = Math.abs(ms4);
|
|
145
|
+
if (msAbs >= d) {
|
|
146
|
+
return Math.round(ms4 / d) + "d";
|
|
147
|
+
}
|
|
148
|
+
if (msAbs >= h) {
|
|
149
|
+
return Math.round(ms4 / h) + "h";
|
|
150
|
+
}
|
|
151
|
+
if (msAbs >= m) {
|
|
152
|
+
return Math.round(ms4 / m) + "m";
|
|
153
|
+
}
|
|
154
|
+
if (msAbs >= s) {
|
|
155
|
+
return Math.round(ms4 / s) + "s";
|
|
156
|
+
}
|
|
157
|
+
return ms4 + "ms";
|
|
158
|
+
}
|
|
159
|
+
function fmtLong(ms4) {
|
|
160
|
+
var msAbs = Math.abs(ms4);
|
|
161
|
+
if (msAbs >= d) {
|
|
162
|
+
return plural(ms4, msAbs, d, "day");
|
|
163
|
+
}
|
|
164
|
+
if (msAbs >= h) {
|
|
165
|
+
return plural(ms4, msAbs, h, "hour");
|
|
166
|
+
}
|
|
167
|
+
if (msAbs >= m) {
|
|
168
|
+
return plural(ms4, msAbs, m, "minute");
|
|
169
|
+
}
|
|
170
|
+
if (msAbs >= s) {
|
|
171
|
+
return plural(ms4, msAbs, s, "second");
|
|
172
|
+
}
|
|
173
|
+
return ms4 + " ms";
|
|
174
|
+
}
|
|
175
|
+
function plural(ms4, msAbs, n, name) {
|
|
176
|
+
var isPlural = msAbs >= n * 1.5;
|
|
177
|
+
return Math.round(ms4 / n) + " " + name + (isPlural ? "s" : "");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
64
182
|
// src/errors.ts
|
|
65
183
|
import { z } from "@botpress/sdk";
|
|
66
184
|
var Errors;
|
|
@@ -26507,7 +26625,7 @@ var require_form_data = __commonJS({
|
|
|
26507
26625
|
var parseUrl = __require("url").parse;
|
|
26508
26626
|
var fs3 = __require("fs");
|
|
26509
26627
|
var Stream2 = __require("stream").Stream;
|
|
26510
|
-
var
|
|
26628
|
+
var crypto2 = __require("crypto");
|
|
26511
26629
|
var mime = require_mime_types();
|
|
26512
26630
|
var asynckit = require_asynckit();
|
|
26513
26631
|
var setToStringTag = require_es_set_tostringtag();
|
|
@@ -26713,7 +26831,7 @@ var require_form_data = __commonJS({
|
|
|
26713
26831
|
return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
|
|
26714
26832
|
};
|
|
26715
26833
|
FormData3.prototype._generateBoundary = function() {
|
|
26716
|
-
this._boundary = "--------------------------" +
|
|
26834
|
+
this._boundary = "--------------------------" + crypto2.randomBytes(12).toString("hex");
|
|
26717
26835
|
};
|
|
26718
26836
|
FormData3.prototype.getLengthSync = function() {
|
|
26719
26837
|
var knownLength = this._overheadLength + this._valueLength;
|
|
@@ -27909,124 +28027,6 @@ var require_proxy_from_env = __commonJS({
|
|
|
27909
28027
|
}
|
|
27910
28028
|
});
|
|
27911
28029
|
|
|
27912
|
-
// ../../node_modules/ms/index.js
|
|
27913
|
-
var require_ms = __commonJS({
|
|
27914
|
-
"../../node_modules/ms/index.js"(exports2, module) {
|
|
27915
|
-
init_define_BUILD();
|
|
27916
|
-
init_define_PACKAGE_VERSIONS();
|
|
27917
|
-
var s = 1e3;
|
|
27918
|
-
var m = s * 60;
|
|
27919
|
-
var h = m * 60;
|
|
27920
|
-
var d = h * 24;
|
|
27921
|
-
var w = d * 7;
|
|
27922
|
-
var y = d * 365.25;
|
|
27923
|
-
module.exports = function(val, options) {
|
|
27924
|
-
options = options || {};
|
|
27925
|
-
var type = typeof val;
|
|
27926
|
-
if (type === "string" && val.length > 0) {
|
|
27927
|
-
return parse(val);
|
|
27928
|
-
} else if (type === "number" && isFinite(val)) {
|
|
27929
|
-
return options.long ? fmtLong(val) : fmtShort(val);
|
|
27930
|
-
}
|
|
27931
|
-
throw new Error(
|
|
27932
|
-
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
|
|
27933
|
-
);
|
|
27934
|
-
};
|
|
27935
|
-
function parse(str) {
|
|
27936
|
-
str = String(str);
|
|
27937
|
-
if (str.length > 100) {
|
|
27938
|
-
return;
|
|
27939
|
-
}
|
|
27940
|
-
var match2 = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
27941
|
-
str
|
|
27942
|
-
);
|
|
27943
|
-
if (!match2) {
|
|
27944
|
-
return;
|
|
27945
|
-
}
|
|
27946
|
-
var n = parseFloat(match2[1]);
|
|
27947
|
-
var type = (match2[2] || "ms").toLowerCase();
|
|
27948
|
-
switch (type) {
|
|
27949
|
-
case "years":
|
|
27950
|
-
case "year":
|
|
27951
|
-
case "yrs":
|
|
27952
|
-
case "yr":
|
|
27953
|
-
case "y":
|
|
27954
|
-
return n * y;
|
|
27955
|
-
case "weeks":
|
|
27956
|
-
case "week":
|
|
27957
|
-
case "w":
|
|
27958
|
-
return n * w;
|
|
27959
|
-
case "days":
|
|
27960
|
-
case "day":
|
|
27961
|
-
case "d":
|
|
27962
|
-
return n * d;
|
|
27963
|
-
case "hours":
|
|
27964
|
-
case "hour":
|
|
27965
|
-
case "hrs":
|
|
27966
|
-
case "hr":
|
|
27967
|
-
case "h":
|
|
27968
|
-
return n * h;
|
|
27969
|
-
case "minutes":
|
|
27970
|
-
case "minute":
|
|
27971
|
-
case "mins":
|
|
27972
|
-
case "min":
|
|
27973
|
-
case "m":
|
|
27974
|
-
return n * m;
|
|
27975
|
-
case "seconds":
|
|
27976
|
-
case "second":
|
|
27977
|
-
case "secs":
|
|
27978
|
-
case "sec":
|
|
27979
|
-
case "s":
|
|
27980
|
-
return n * s;
|
|
27981
|
-
case "milliseconds":
|
|
27982
|
-
case "millisecond":
|
|
27983
|
-
case "msecs":
|
|
27984
|
-
case "msec":
|
|
27985
|
-
case "ms":
|
|
27986
|
-
return n;
|
|
27987
|
-
default:
|
|
27988
|
-
return void 0;
|
|
27989
|
-
}
|
|
27990
|
-
}
|
|
27991
|
-
function fmtShort(ms3) {
|
|
27992
|
-
var msAbs = Math.abs(ms3);
|
|
27993
|
-
if (msAbs >= d) {
|
|
27994
|
-
return Math.round(ms3 / d) + "d";
|
|
27995
|
-
}
|
|
27996
|
-
if (msAbs >= h) {
|
|
27997
|
-
return Math.round(ms3 / h) + "h";
|
|
27998
|
-
}
|
|
27999
|
-
if (msAbs >= m) {
|
|
28000
|
-
return Math.round(ms3 / m) + "m";
|
|
28001
|
-
}
|
|
28002
|
-
if (msAbs >= s) {
|
|
28003
|
-
return Math.round(ms3 / s) + "s";
|
|
28004
|
-
}
|
|
28005
|
-
return ms3 + "ms";
|
|
28006
|
-
}
|
|
28007
|
-
function fmtLong(ms3) {
|
|
28008
|
-
var msAbs = Math.abs(ms3);
|
|
28009
|
-
if (msAbs >= d) {
|
|
28010
|
-
return plural(ms3, msAbs, d, "day");
|
|
28011
|
-
}
|
|
28012
|
-
if (msAbs >= h) {
|
|
28013
|
-
return plural(ms3, msAbs, h, "hour");
|
|
28014
|
-
}
|
|
28015
|
-
if (msAbs >= m) {
|
|
28016
|
-
return plural(ms3, msAbs, m, "minute");
|
|
28017
|
-
}
|
|
28018
|
-
if (msAbs >= s) {
|
|
28019
|
-
return plural(ms3, msAbs, s, "second");
|
|
28020
|
-
}
|
|
28021
|
-
return ms3 + " ms";
|
|
28022
|
-
}
|
|
28023
|
-
function plural(ms3, msAbs, n, name) {
|
|
28024
|
-
var isPlural = msAbs >= n * 1.5;
|
|
28025
|
-
return Math.round(ms3 / n) + " " + name + (isPlural ? "s" : "");
|
|
28026
|
-
}
|
|
28027
|
-
}
|
|
28028
|
-
});
|
|
28029
|
-
|
|
28030
28030
|
// ../../node_modules/debug/src/common.js
|
|
28031
28031
|
var require_common = __commonJS({
|
|
28032
28032
|
"../../node_modules/debug/src/common.js"(exports2, module) {
|
|
@@ -28067,8 +28067,8 @@ var require_common = __commonJS({
|
|
|
28067
28067
|
}
|
|
28068
28068
|
const self2 = debug;
|
|
28069
28069
|
const curr = Number(/* @__PURE__ */ new Date());
|
|
28070
|
-
const
|
|
28071
|
-
self2.diff =
|
|
28070
|
+
const ms4 = curr - (prevTime || curr);
|
|
28071
|
+
self2.diff = ms4;
|
|
28072
28072
|
self2.prev = prevTime;
|
|
28073
28073
|
self2.curr = curr;
|
|
28074
28074
|
prevTime = curr;
|
|
@@ -34676,6 +34676,9 @@ Always prefer information from the knowledge bases over general knowledge when a
|
|
|
34676
34676
|
...props.hooks?.onBeforeTool && {
|
|
34677
34677
|
onBeforeTool: asyncResource.bind(props.hooks.onBeforeTool)
|
|
34678
34678
|
},
|
|
34679
|
+
...props.hooks?.onIterationStart && {
|
|
34680
|
+
onIterationStart: asyncResource.bind(props.hooks.onIterationStart)
|
|
34681
|
+
},
|
|
34679
34682
|
...props.hooks?.onAfterTool && {
|
|
34680
34683
|
onAfterTool: asyncResource.bind(props.hooks.onAfterTool)
|
|
34681
34684
|
},
|
|
@@ -35021,47 +35024,6 @@ var init_structured_logging = __esm({
|
|
|
35021
35024
|
}
|
|
35022
35025
|
});
|
|
35023
35026
|
|
|
35024
|
-
// src/utilities/trigger-tags.ts
|
|
35025
|
-
var trigger_tags_exports = {};
|
|
35026
|
-
__export(trigger_tags_exports, {
|
|
35027
|
-
getTriggerSubscriptionTags: () => getTriggerSubscriptionTags,
|
|
35028
|
-
getTriggerTagName: () => getTriggerTagName,
|
|
35029
|
-
getTriggerTagValue: () => getTriggerTagValue,
|
|
35030
|
-
isConversationSubscribedToTrigger: () => isConversationSubscribedToTrigger
|
|
35031
|
-
});
|
|
35032
|
-
import crypto2 from "crypto";
|
|
35033
|
-
var hashString, getTriggerTagName, getTriggerTagValue, getTriggerSubscriptionTags, isConversationSubscribedToTrigger;
|
|
35034
|
-
var init_trigger_tags = __esm({
|
|
35035
|
-
"src/utilities/trigger-tags.ts"() {
|
|
35036
|
-
"use strict";
|
|
35037
|
-
init_define_BUILD();
|
|
35038
|
-
init_define_PACKAGE_VERSIONS();
|
|
35039
|
-
hashString = (str) => {
|
|
35040
|
-
return crypto2.createHash("md5").update(str).digest("hex").substring(0, 5).toUpperCase();
|
|
35041
|
-
};
|
|
35042
|
-
getTriggerTagName = (triggerName) => {
|
|
35043
|
-
return `trigger${hashString(triggerName)}`;
|
|
35044
|
-
};
|
|
35045
|
-
getTriggerTagValue = (key) => {
|
|
35046
|
-
return key ?? "*";
|
|
35047
|
-
};
|
|
35048
|
-
getTriggerSubscriptionTags = (triggerName, key) => {
|
|
35049
|
-
return {
|
|
35050
|
-
name: getTriggerTagName(triggerName),
|
|
35051
|
-
value: getTriggerTagValue(key)
|
|
35052
|
-
};
|
|
35053
|
-
};
|
|
35054
|
-
isConversationSubscribedToTrigger = (conversationTags, triggerName, triggerKey) => {
|
|
35055
|
-
const tagName = getTriggerTagName(triggerName);
|
|
35056
|
-
const tagValue = conversationTags[tagName];
|
|
35057
|
-
if (!tagValue) {
|
|
35058
|
-
return false;
|
|
35059
|
-
}
|
|
35060
|
-
return tagValue === "*" || tagValue === triggerKey;
|
|
35061
|
-
};
|
|
35062
|
-
}
|
|
35063
|
-
});
|
|
35064
|
-
|
|
35065
35027
|
// src/types.ts
|
|
35066
35028
|
var init_types2 = __esm({
|
|
35067
35029
|
"src/types.ts"() {
|
|
@@ -35161,15 +35123,25 @@ var init_validate_tag_name = __esm({
|
|
|
35161
35123
|
}
|
|
35162
35124
|
});
|
|
35163
35125
|
|
|
35126
|
+
// src/utilities/validate-event-name.ts
|
|
35127
|
+
var init_validate_event_name = __esm({
|
|
35128
|
+
"src/utilities/validate-event-name.ts"() {
|
|
35129
|
+
"use strict";
|
|
35130
|
+
init_define_BUILD();
|
|
35131
|
+
init_define_PACKAGE_VERSIONS();
|
|
35132
|
+
}
|
|
35133
|
+
});
|
|
35134
|
+
|
|
35164
35135
|
// src/define-config.ts
|
|
35165
35136
|
import { z as z4 } from "@botpress/sdk";
|
|
35166
|
-
var zuiSchema, modelSchema, tagDefinitionSchema, configSchema, AGENT_CONFIG_BRAND, isAgentConfig;
|
|
35137
|
+
var zuiSchema, modelSchema, tagDefinitionSchema, eventDefinitionSchema, configSchema, AGENT_CONFIG_BRAND, isAgentConfig;
|
|
35167
35138
|
var init_define_config = __esm({
|
|
35168
35139
|
"src/define-config.ts"() {
|
|
35169
35140
|
"use strict";
|
|
35170
35141
|
init_define_BUILD();
|
|
35171
35142
|
init_define_PACKAGE_VERSIONS();
|
|
35172
35143
|
init_validate_tag_name();
|
|
35144
|
+
init_validate_event_name();
|
|
35173
35145
|
zuiSchema = z4.custom(
|
|
35174
35146
|
(val) => {
|
|
35175
35147
|
if (typeof val === "object" && val !== null && "parse" in val) {
|
|
@@ -35194,6 +35166,13 @@ var init_define_config = __esm({
|
|
|
35194
35166
|
description: z4.string().optional()
|
|
35195
35167
|
})
|
|
35196
35168
|
);
|
|
35169
|
+
eventDefinitionSchema = z4.record(
|
|
35170
|
+
z4.string(),
|
|
35171
|
+
z4.object({
|
|
35172
|
+
schema: zuiSchema.optional(),
|
|
35173
|
+
description: z4.string().optional()
|
|
35174
|
+
})
|
|
35175
|
+
);
|
|
35197
35176
|
configSchema = z4.object({
|
|
35198
35177
|
name: z4.string().optional(),
|
|
35199
35178
|
description: z4.string().optional(),
|
|
@@ -35234,7 +35213,8 @@ var init_define_config = __esm({
|
|
|
35234
35213
|
zai: val?.zai ?? "openai:gpt-4.1-2025-04-14",
|
|
35235
35214
|
autonomous: val?.autonomous ?? "openai:gpt-4.1-mini-2025-04-14"
|
|
35236
35215
|
})),
|
|
35237
|
-
dependencies: z4.custom()
|
|
35216
|
+
dependencies: z4.custom(),
|
|
35217
|
+
events: eventDefinitionSchema.optional()
|
|
35238
35218
|
});
|
|
35239
35219
|
AGENT_CONFIG_BRAND = Symbol.for("@botpress/runtime/AgentConfig");
|
|
35240
35220
|
isAgentConfig = (value) => {
|
|
@@ -35256,7 +35236,6 @@ var init_runtime = __esm({
|
|
|
35256
35236
|
init_structured_logging();
|
|
35257
35237
|
init_environment();
|
|
35258
35238
|
init_runtime2();
|
|
35259
|
-
init_trigger_tags();
|
|
35260
35239
|
init_types2();
|
|
35261
35240
|
init_errors();
|
|
35262
35241
|
init_state();
|
|
@@ -36377,6 +36356,259 @@ var init_tracked_state = __esm({
|
|
|
36377
36356
|
}
|
|
36378
36357
|
});
|
|
36379
36358
|
|
|
36359
|
+
// src/runtime/tracked-tags.ts
|
|
36360
|
+
var TrackedTags;
|
|
36361
|
+
var init_tracked_tags = __esm({
|
|
36362
|
+
"src/runtime/tracked-tags.ts"() {
|
|
36363
|
+
"use strict";
|
|
36364
|
+
init_define_BUILD();
|
|
36365
|
+
init_define_PACKAGE_VERSIONS();
|
|
36366
|
+
init_context();
|
|
36367
|
+
init_tracing();
|
|
36368
|
+
TrackedTags = class _TrackedTags {
|
|
36369
|
+
type;
|
|
36370
|
+
id;
|
|
36371
|
+
client;
|
|
36372
|
+
_tags = {};
|
|
36373
|
+
_initialTags = {};
|
|
36374
|
+
_loaded = false;
|
|
36375
|
+
_saving = false;
|
|
36376
|
+
_saveAgain = false;
|
|
36377
|
+
_saveAgainCount = 0;
|
|
36378
|
+
static _savingAll = false;
|
|
36379
|
+
static _saveAllAgain = false;
|
|
36380
|
+
static _saveAllCount = 0;
|
|
36381
|
+
constructor(props) {
|
|
36382
|
+
this.type = props.type;
|
|
36383
|
+
this.id = props.id;
|
|
36384
|
+
this.client = props.client;
|
|
36385
|
+
}
|
|
36386
|
+
static create(props) {
|
|
36387
|
+
const tags = context.get("tags", { optional: true });
|
|
36388
|
+
const executionFinished = context.get("executionFinished", { optional: true });
|
|
36389
|
+
if (executionFinished) {
|
|
36390
|
+
throw new Error(`Cannot create new TrackedTags "${props.type}/${props.id}" after execution has finished.`);
|
|
36391
|
+
}
|
|
36392
|
+
const match2 = tags?.find((x) => x.id === props.id && x.type === props.type);
|
|
36393
|
+
if (match2) {
|
|
36394
|
+
return match2;
|
|
36395
|
+
}
|
|
36396
|
+
const instance = new _TrackedTags(props);
|
|
36397
|
+
if (props.initialTags) {
|
|
36398
|
+
instance._tags = { ...props.initialTags };
|
|
36399
|
+
instance._initialTags = { ...props.initialTags };
|
|
36400
|
+
instance._loaded = true;
|
|
36401
|
+
}
|
|
36402
|
+
tags?.push(instance);
|
|
36403
|
+
return instance;
|
|
36404
|
+
}
|
|
36405
|
+
static async saveAllDirty() {
|
|
36406
|
+
if (this._savingAll) {
|
|
36407
|
+
this._saveAllAgain = true;
|
|
36408
|
+
return;
|
|
36409
|
+
}
|
|
36410
|
+
try {
|
|
36411
|
+
this._savingAll = true;
|
|
36412
|
+
const tags = context.get("tags", { optional: true });
|
|
36413
|
+
const dirtyTags = tags?.filter((t) => t.isDirty()) || [];
|
|
36414
|
+
if (!dirtyTags.length) {
|
|
36415
|
+
return;
|
|
36416
|
+
}
|
|
36417
|
+
await span(
|
|
36418
|
+
"tags.saveAllDirty",
|
|
36419
|
+
{
|
|
36420
|
+
tags_count: tags?.length || 0,
|
|
36421
|
+
tags: tags.map((t) => `${t.type}/${t.id}`)
|
|
36422
|
+
},
|
|
36423
|
+
() => Promise.allSettled(dirtyTags.map((t) => t.save()))
|
|
36424
|
+
);
|
|
36425
|
+
} finally {
|
|
36426
|
+
this._savingAll = false;
|
|
36427
|
+
if (this._saveAllAgain && this._saveAllCount++ <= 5) {
|
|
36428
|
+
this._saveAllAgain = false;
|
|
36429
|
+
await this.saveAllDirty();
|
|
36430
|
+
} else {
|
|
36431
|
+
this._saveAllCount = 0;
|
|
36432
|
+
}
|
|
36433
|
+
}
|
|
36434
|
+
}
|
|
36435
|
+
static async loadAll() {
|
|
36436
|
+
await span("tags.loadAll", {}, async () => {
|
|
36437
|
+
const client2 = context.get("client")._inner;
|
|
36438
|
+
const bot2 = context.get("bot", { optional: true });
|
|
36439
|
+
const user2 = context.get("user", { optional: true });
|
|
36440
|
+
const conversation = context.get("conversation", { optional: true });
|
|
36441
|
+
const workflow = context.get("workflow", { optional: true });
|
|
36442
|
+
if (bot2) {
|
|
36443
|
+
const botTags = bot2.tags;
|
|
36444
|
+
_TrackedTags.create({
|
|
36445
|
+
client: client2,
|
|
36446
|
+
type: "bot",
|
|
36447
|
+
id: bot2.id,
|
|
36448
|
+
...botTags && { initialTags: botTags }
|
|
36449
|
+
});
|
|
36450
|
+
}
|
|
36451
|
+
if (user2) {
|
|
36452
|
+
const userTags = user2.tags;
|
|
36453
|
+
_TrackedTags.create({
|
|
36454
|
+
client: client2,
|
|
36455
|
+
type: "user",
|
|
36456
|
+
id: user2.id,
|
|
36457
|
+
...userTags && { initialTags: userTags }
|
|
36458
|
+
});
|
|
36459
|
+
}
|
|
36460
|
+
if (conversation) {
|
|
36461
|
+
const conversationTags = conversation.tags;
|
|
36462
|
+
_TrackedTags.create({
|
|
36463
|
+
client: client2,
|
|
36464
|
+
type: "conversation",
|
|
36465
|
+
id: conversation.id,
|
|
36466
|
+
...conversationTags && { initialTags: conversationTags }
|
|
36467
|
+
});
|
|
36468
|
+
}
|
|
36469
|
+
if (workflow) {
|
|
36470
|
+
const workflowTags = workflow.tags;
|
|
36471
|
+
_TrackedTags.create({
|
|
36472
|
+
client: client2,
|
|
36473
|
+
type: "workflow",
|
|
36474
|
+
id: workflow.id,
|
|
36475
|
+
...workflowTags && { initialTags: workflowTags }
|
|
36476
|
+
});
|
|
36477
|
+
}
|
|
36478
|
+
const tags = context.get("tags", { optional: true });
|
|
36479
|
+
const unloadedTags = tags?.filter((tag) => !tag._loaded) ?? [];
|
|
36480
|
+
if (unloadedTags.length > 0) {
|
|
36481
|
+
await Promise.allSettled(unloadedTags.map((tag) => tag.load()));
|
|
36482
|
+
}
|
|
36483
|
+
});
|
|
36484
|
+
}
|
|
36485
|
+
static unloadAll() {
|
|
36486
|
+
context.get("tags", { optional: true })?.splice(0);
|
|
36487
|
+
}
|
|
36488
|
+
async load(force = false) {
|
|
36489
|
+
if (this._loaded && !force) {
|
|
36490
|
+
return;
|
|
36491
|
+
}
|
|
36492
|
+
await span(
|
|
36493
|
+
"tags.load",
|
|
36494
|
+
{
|
|
36495
|
+
type: this.type,
|
|
36496
|
+
id: this.id
|
|
36497
|
+
},
|
|
36498
|
+
async () => {
|
|
36499
|
+
const tags = await this.fetchTags();
|
|
36500
|
+
this._tags = { ...tags };
|
|
36501
|
+
this._initialTags = { ...tags };
|
|
36502
|
+
this._loaded = true;
|
|
36503
|
+
}
|
|
36504
|
+
);
|
|
36505
|
+
}
|
|
36506
|
+
async save() {
|
|
36507
|
+
if (this._saving) {
|
|
36508
|
+
this._saveAgain = true;
|
|
36509
|
+
return;
|
|
36510
|
+
}
|
|
36511
|
+
const executionFinished = context.get("executionFinished", { optional: true });
|
|
36512
|
+
if (executionFinished) {
|
|
36513
|
+
throw new Error(`Cannot save TrackedTags "${this.type}/${this.id}" after execution has finished.`);
|
|
36514
|
+
}
|
|
36515
|
+
try {
|
|
36516
|
+
this._saving = true;
|
|
36517
|
+
await span(
|
|
36518
|
+
"tags.save",
|
|
36519
|
+
{
|
|
36520
|
+
type: this.type,
|
|
36521
|
+
id: this.id
|
|
36522
|
+
},
|
|
36523
|
+
async () => {
|
|
36524
|
+
await this.persistTags(this._tags);
|
|
36525
|
+
this._initialTags = { ...this._tags };
|
|
36526
|
+
}
|
|
36527
|
+
);
|
|
36528
|
+
} finally {
|
|
36529
|
+
this._saving = false;
|
|
36530
|
+
if (this._saveAgain && this._saveAgainCount++ <= 5) {
|
|
36531
|
+
this._saveAgain = false;
|
|
36532
|
+
await this.save();
|
|
36533
|
+
} else {
|
|
36534
|
+
this._saveAgainCount = 0;
|
|
36535
|
+
}
|
|
36536
|
+
}
|
|
36537
|
+
}
|
|
36538
|
+
isDirty() {
|
|
36539
|
+
const currentKeys = Object.keys(this._tags).filter((k) => !k.includes(":")).sort();
|
|
36540
|
+
const initialKeys = Object.keys(this._initialTags).filter((k) => !k.includes(":")).sort();
|
|
36541
|
+
if (currentKeys.length !== initialKeys.length) {
|
|
36542
|
+
return true;
|
|
36543
|
+
}
|
|
36544
|
+
for (const key of currentKeys) {
|
|
36545
|
+
if (this._tags[key] !== this._initialTags[key]) {
|
|
36546
|
+
return true;
|
|
36547
|
+
}
|
|
36548
|
+
}
|
|
36549
|
+
return false;
|
|
36550
|
+
}
|
|
36551
|
+
get tags() {
|
|
36552
|
+
return new Proxy(this._tags, {
|
|
36553
|
+
set: (target, prop, value) => {
|
|
36554
|
+
target[prop] = value;
|
|
36555
|
+
return true;
|
|
36556
|
+
},
|
|
36557
|
+
deleteProperty: (target, prop) => {
|
|
36558
|
+
target[prop] = void 0;
|
|
36559
|
+
return true;
|
|
36560
|
+
}
|
|
36561
|
+
});
|
|
36562
|
+
}
|
|
36563
|
+
set tags(value) {
|
|
36564
|
+
this._tags = { ...value };
|
|
36565
|
+
}
|
|
36566
|
+
async fetchTags() {
|
|
36567
|
+
try {
|
|
36568
|
+
if (this.type === "bot") {
|
|
36569
|
+
const { bot: bot2 } = await this.client.getBot({ id: this.id });
|
|
36570
|
+
return bot2.tags || {};
|
|
36571
|
+
} else if (this.type === "user") {
|
|
36572
|
+
const { user: user2 } = await this.client.getUser({ id: this.id });
|
|
36573
|
+
return user2.tags || {};
|
|
36574
|
+
} else if (this.type === "conversation") {
|
|
36575
|
+
const { conversation } = await this.client.getConversation({ id: this.id });
|
|
36576
|
+
return conversation.tags || {};
|
|
36577
|
+
} else if (this.type === "workflow") {
|
|
36578
|
+
const { workflow } = await this.client.getWorkflow({ id: this.id });
|
|
36579
|
+
return workflow.tags || {};
|
|
36580
|
+
}
|
|
36581
|
+
} catch (err) {
|
|
36582
|
+
console.error(`Failed to fetch tags for ${this.type}/${this.id}:`, err);
|
|
36583
|
+
}
|
|
36584
|
+
return {};
|
|
36585
|
+
}
|
|
36586
|
+
async persistTags(tags) {
|
|
36587
|
+
const tagsForApi = {};
|
|
36588
|
+
for (const [key, value] of Object.entries(tags)) {
|
|
36589
|
+
if (value !== void 0 && !key.includes(":")) {
|
|
36590
|
+
tagsForApi[key] = value;
|
|
36591
|
+
}
|
|
36592
|
+
}
|
|
36593
|
+
try {
|
|
36594
|
+
if (this.type === "bot") {
|
|
36595
|
+
await this.client.updateBot({ id: this.id, tags: tagsForApi });
|
|
36596
|
+
} else if (this.type === "user") {
|
|
36597
|
+
await this.client.updateUser({ id: this.id, tags: tagsForApi });
|
|
36598
|
+
} else if (this.type === "conversation") {
|
|
36599
|
+
await this.client.updateConversation({ id: this.id, tags: tagsForApi });
|
|
36600
|
+
} else if (this.type === "workflow") {
|
|
36601
|
+
await this.client.updateWorkflow({ id: this.id, tags: tagsForApi });
|
|
36602
|
+
}
|
|
36603
|
+
} catch (err) {
|
|
36604
|
+
console.error(`Failed to persist tags for ${this.type}/${this.id}:`, err);
|
|
36605
|
+
throw err;
|
|
36606
|
+
}
|
|
36607
|
+
}
|
|
36608
|
+
};
|
|
36609
|
+
}
|
|
36610
|
+
});
|
|
36611
|
+
|
|
36380
36612
|
// src/runtime/context/inspector-handler.ts
|
|
36381
36613
|
var init_inspector_handler = __esm({
|
|
36382
36614
|
"src/runtime/context/inspector-handler.ts"() {
|
|
@@ -36458,6 +36690,7 @@ var init_handlers = __esm({
|
|
|
36458
36690
|
init_http();
|
|
36459
36691
|
init_agent_registry();
|
|
36460
36692
|
init_tracked_state();
|
|
36693
|
+
init_tracked_tags();
|
|
36461
36694
|
init_tracing();
|
|
36462
36695
|
init_heavy_imports();
|
|
36463
36696
|
init_environment();
|
|
@@ -37315,38 +37548,6 @@ var init_conversation_instance = __esm({
|
|
|
37315
37548
|
});
|
|
37316
37549
|
}
|
|
37317
37550
|
}
|
|
37318
|
-
/**
|
|
37319
|
-
* Subscribe to a trigger
|
|
37320
|
-
*/
|
|
37321
|
-
async subscribeToTrigger(triggerName, key) {
|
|
37322
|
-
const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
|
|
37323
|
-
if (isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
|
|
37324
|
-
return;
|
|
37325
|
-
}
|
|
37326
|
-
const { name, value } = getTriggerSubscriptionTags2(triggerName, key);
|
|
37327
|
-
await this.client.updateConversation({
|
|
37328
|
-
id: this.id,
|
|
37329
|
-
tags: {
|
|
37330
|
-
[name]: value
|
|
37331
|
-
}
|
|
37332
|
-
});
|
|
37333
|
-
}
|
|
37334
|
-
/**
|
|
37335
|
-
* Unsubscribe from a trigger
|
|
37336
|
-
*/
|
|
37337
|
-
async unsubscribeFromTrigger(triggerName, key) {
|
|
37338
|
-
const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
|
|
37339
|
-
if (!isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
|
|
37340
|
-
return;
|
|
37341
|
-
}
|
|
37342
|
-
const { name } = getTriggerSubscriptionTags2(triggerName, key);
|
|
37343
|
-
await this.client.updateConversation({
|
|
37344
|
-
id: this.id,
|
|
37345
|
-
tags: {
|
|
37346
|
-
[name]: ""
|
|
37347
|
-
}
|
|
37348
|
-
});
|
|
37349
|
-
}
|
|
37350
37551
|
};
|
|
37351
37552
|
}
|
|
37352
37553
|
});
|
|
@@ -37382,19 +37583,11 @@ var init_conversation = __esm({
|
|
|
37382
37583
|
/** @internal */
|
|
37383
37584
|
schema;
|
|
37384
37585
|
#handler;
|
|
37385
|
-
#startFromTrigger;
|
|
37386
37586
|
constructor(props) {
|
|
37387
37587
|
this.channel = props.channel;
|
|
37388
37588
|
this.events = props.events ?? [];
|
|
37389
37589
|
this.schema = props.state ?? z16.object({}).passthrough();
|
|
37390
37590
|
this.#handler = props.handler;
|
|
37391
|
-
if (props.startFromTrigger) {
|
|
37392
|
-
this.#startFromTrigger = props.startFromTrigger;
|
|
37393
|
-
}
|
|
37394
|
-
}
|
|
37395
|
-
/** @internal */
|
|
37396
|
-
get startFromTrigger() {
|
|
37397
|
-
return this.#startFromTrigger;
|
|
37398
37591
|
}
|
|
37399
37592
|
/** @internal */
|
|
37400
37593
|
getDefinition() {
|
|
@@ -37670,259 +37863,6 @@ var init_handlers2 = __esm({
|
|
|
37670
37863
|
}
|
|
37671
37864
|
});
|
|
37672
37865
|
|
|
37673
|
-
// src/runtime/tracked-tags.ts
|
|
37674
|
-
var TrackedTags;
|
|
37675
|
-
var init_tracked_tags = __esm({
|
|
37676
|
-
"src/runtime/tracked-tags.ts"() {
|
|
37677
|
-
"use strict";
|
|
37678
|
-
init_define_BUILD();
|
|
37679
|
-
init_define_PACKAGE_VERSIONS();
|
|
37680
|
-
init_context();
|
|
37681
|
-
init_tracing();
|
|
37682
|
-
TrackedTags = class _TrackedTags {
|
|
37683
|
-
type;
|
|
37684
|
-
id;
|
|
37685
|
-
client;
|
|
37686
|
-
_tags = {};
|
|
37687
|
-
_initialTags = {};
|
|
37688
|
-
_loaded = false;
|
|
37689
|
-
_saving = false;
|
|
37690
|
-
_saveAgain = false;
|
|
37691
|
-
_saveAgainCount = 0;
|
|
37692
|
-
static _savingAll = false;
|
|
37693
|
-
static _saveAllAgain = false;
|
|
37694
|
-
static _saveAllCount = 0;
|
|
37695
|
-
constructor(props) {
|
|
37696
|
-
this.type = props.type;
|
|
37697
|
-
this.id = props.id;
|
|
37698
|
-
this.client = props.client;
|
|
37699
|
-
}
|
|
37700
|
-
static create(props) {
|
|
37701
|
-
const tags = context.get("tags", { optional: true });
|
|
37702
|
-
const executionFinished = context.get("executionFinished", { optional: true });
|
|
37703
|
-
if (executionFinished) {
|
|
37704
|
-
throw new Error(`Cannot create new TrackedTags "${props.type}/${props.id}" after execution has finished.`);
|
|
37705
|
-
}
|
|
37706
|
-
const match2 = tags?.find((x) => x.id === props.id && x.type === props.type);
|
|
37707
|
-
if (match2) {
|
|
37708
|
-
return match2;
|
|
37709
|
-
}
|
|
37710
|
-
const instance = new _TrackedTags(props);
|
|
37711
|
-
if (props.initialTags) {
|
|
37712
|
-
instance._tags = { ...props.initialTags };
|
|
37713
|
-
instance._initialTags = { ...props.initialTags };
|
|
37714
|
-
instance._loaded = true;
|
|
37715
|
-
}
|
|
37716
|
-
tags?.push(instance);
|
|
37717
|
-
return instance;
|
|
37718
|
-
}
|
|
37719
|
-
static async saveAllDirty() {
|
|
37720
|
-
if (this._savingAll) {
|
|
37721
|
-
this._saveAllAgain = true;
|
|
37722
|
-
return;
|
|
37723
|
-
}
|
|
37724
|
-
try {
|
|
37725
|
-
this._savingAll = true;
|
|
37726
|
-
const tags = context.get("tags", { optional: true });
|
|
37727
|
-
const dirtyTags = tags?.filter((t) => t.isDirty()) || [];
|
|
37728
|
-
if (!dirtyTags.length) {
|
|
37729
|
-
return;
|
|
37730
|
-
}
|
|
37731
|
-
await span(
|
|
37732
|
-
"tags.saveAllDirty",
|
|
37733
|
-
{
|
|
37734
|
-
tags_count: tags?.length || 0,
|
|
37735
|
-
tags: tags.map((t) => `${t.type}/${t.id}`)
|
|
37736
|
-
},
|
|
37737
|
-
() => Promise.allSettled(dirtyTags.map((t) => t.save()))
|
|
37738
|
-
);
|
|
37739
|
-
} finally {
|
|
37740
|
-
this._savingAll = false;
|
|
37741
|
-
if (this._saveAllAgain && this._saveAllCount++ <= 5) {
|
|
37742
|
-
this._saveAllAgain = false;
|
|
37743
|
-
await this.saveAllDirty();
|
|
37744
|
-
} else {
|
|
37745
|
-
this._saveAllCount = 0;
|
|
37746
|
-
}
|
|
37747
|
-
}
|
|
37748
|
-
}
|
|
37749
|
-
static async loadAll() {
|
|
37750
|
-
await span("tags.loadAll", {}, async () => {
|
|
37751
|
-
const client2 = context.get("client")._inner;
|
|
37752
|
-
const bot2 = context.get("bot", { optional: true });
|
|
37753
|
-
const user2 = context.get("user", { optional: true });
|
|
37754
|
-
const conversation = context.get("conversation", { optional: true });
|
|
37755
|
-
const workflow = context.get("workflow", { optional: true });
|
|
37756
|
-
if (bot2) {
|
|
37757
|
-
const botTags = bot2.tags;
|
|
37758
|
-
_TrackedTags.create({
|
|
37759
|
-
client: client2,
|
|
37760
|
-
type: "bot",
|
|
37761
|
-
id: bot2.id,
|
|
37762
|
-
...botTags && { initialTags: botTags }
|
|
37763
|
-
});
|
|
37764
|
-
}
|
|
37765
|
-
if (user2) {
|
|
37766
|
-
const userTags = user2.tags;
|
|
37767
|
-
_TrackedTags.create({
|
|
37768
|
-
client: client2,
|
|
37769
|
-
type: "user",
|
|
37770
|
-
id: user2.id,
|
|
37771
|
-
...userTags && { initialTags: userTags }
|
|
37772
|
-
});
|
|
37773
|
-
}
|
|
37774
|
-
if (conversation) {
|
|
37775
|
-
const conversationTags = conversation.tags;
|
|
37776
|
-
_TrackedTags.create({
|
|
37777
|
-
client: client2,
|
|
37778
|
-
type: "conversation",
|
|
37779
|
-
id: conversation.id,
|
|
37780
|
-
...conversationTags && { initialTags: conversationTags }
|
|
37781
|
-
});
|
|
37782
|
-
}
|
|
37783
|
-
if (workflow) {
|
|
37784
|
-
const workflowTags = workflow.tags;
|
|
37785
|
-
_TrackedTags.create({
|
|
37786
|
-
client: client2,
|
|
37787
|
-
type: "workflow",
|
|
37788
|
-
id: workflow.id,
|
|
37789
|
-
...workflowTags && { initialTags: workflowTags }
|
|
37790
|
-
});
|
|
37791
|
-
}
|
|
37792
|
-
const tags = context.get("tags", { optional: true });
|
|
37793
|
-
const unloadedTags = tags?.filter((tag) => !tag._loaded) ?? [];
|
|
37794
|
-
if (unloadedTags.length > 0) {
|
|
37795
|
-
await Promise.allSettled(unloadedTags.map((tag) => tag.load()));
|
|
37796
|
-
}
|
|
37797
|
-
});
|
|
37798
|
-
}
|
|
37799
|
-
static unloadAll() {
|
|
37800
|
-
context.get("tags", { optional: true })?.splice(0);
|
|
37801
|
-
}
|
|
37802
|
-
async load(force = false) {
|
|
37803
|
-
if (this._loaded && !force) {
|
|
37804
|
-
return;
|
|
37805
|
-
}
|
|
37806
|
-
await span(
|
|
37807
|
-
"tags.load",
|
|
37808
|
-
{
|
|
37809
|
-
type: this.type,
|
|
37810
|
-
id: this.id
|
|
37811
|
-
},
|
|
37812
|
-
async () => {
|
|
37813
|
-
const tags = await this.fetchTags();
|
|
37814
|
-
this._tags = { ...tags };
|
|
37815
|
-
this._initialTags = { ...tags };
|
|
37816
|
-
this._loaded = true;
|
|
37817
|
-
}
|
|
37818
|
-
);
|
|
37819
|
-
}
|
|
37820
|
-
async save() {
|
|
37821
|
-
if (this._saving) {
|
|
37822
|
-
this._saveAgain = true;
|
|
37823
|
-
return;
|
|
37824
|
-
}
|
|
37825
|
-
const executionFinished = context.get("executionFinished", { optional: true });
|
|
37826
|
-
if (executionFinished) {
|
|
37827
|
-
throw new Error(`Cannot save TrackedTags "${this.type}/${this.id}" after execution has finished.`);
|
|
37828
|
-
}
|
|
37829
|
-
try {
|
|
37830
|
-
this._saving = true;
|
|
37831
|
-
await span(
|
|
37832
|
-
"tags.save",
|
|
37833
|
-
{
|
|
37834
|
-
type: this.type,
|
|
37835
|
-
id: this.id
|
|
37836
|
-
},
|
|
37837
|
-
async () => {
|
|
37838
|
-
await this.persistTags(this._tags);
|
|
37839
|
-
this._initialTags = { ...this._tags };
|
|
37840
|
-
}
|
|
37841
|
-
);
|
|
37842
|
-
} finally {
|
|
37843
|
-
this._saving = false;
|
|
37844
|
-
if (this._saveAgain && this._saveAgainCount++ <= 5) {
|
|
37845
|
-
this._saveAgain = false;
|
|
37846
|
-
await this.save();
|
|
37847
|
-
} else {
|
|
37848
|
-
this._saveAgainCount = 0;
|
|
37849
|
-
}
|
|
37850
|
-
}
|
|
37851
|
-
}
|
|
37852
|
-
isDirty() {
|
|
37853
|
-
const currentKeys = Object.keys(this._tags).sort();
|
|
37854
|
-
const initialKeys = Object.keys(this._initialTags).sort();
|
|
37855
|
-
if (currentKeys.length !== initialKeys.length) {
|
|
37856
|
-
return true;
|
|
37857
|
-
}
|
|
37858
|
-
for (const key of currentKeys) {
|
|
37859
|
-
if (this._tags[key] !== this._initialTags[key]) {
|
|
37860
|
-
return true;
|
|
37861
|
-
}
|
|
37862
|
-
}
|
|
37863
|
-
return false;
|
|
37864
|
-
}
|
|
37865
|
-
get tags() {
|
|
37866
|
-
return new Proxy(this._tags, {
|
|
37867
|
-
set: (target, prop, value) => {
|
|
37868
|
-
target[prop] = value;
|
|
37869
|
-
return true;
|
|
37870
|
-
},
|
|
37871
|
-
deleteProperty: (target, prop) => {
|
|
37872
|
-
target[prop] = void 0;
|
|
37873
|
-
return true;
|
|
37874
|
-
}
|
|
37875
|
-
});
|
|
37876
|
-
}
|
|
37877
|
-
set tags(value) {
|
|
37878
|
-
this._tags = { ...value };
|
|
37879
|
-
}
|
|
37880
|
-
async fetchTags() {
|
|
37881
|
-
try {
|
|
37882
|
-
if (this.type === "bot") {
|
|
37883
|
-
const { bot: bot2 } = await this.client.getBot({ id: this.id });
|
|
37884
|
-
return bot2.tags || {};
|
|
37885
|
-
} else if (this.type === "user") {
|
|
37886
|
-
const { user: user2 } = await this.client.getUser({ id: this.id });
|
|
37887
|
-
return user2.tags || {};
|
|
37888
|
-
} else if (this.type === "conversation") {
|
|
37889
|
-
const { conversation } = await this.client.getConversation({ id: this.id });
|
|
37890
|
-
return conversation.tags || {};
|
|
37891
|
-
} else if (this.type === "workflow") {
|
|
37892
|
-
const { workflow } = await this.client.getWorkflow({ id: this.id });
|
|
37893
|
-
return workflow.tags || {};
|
|
37894
|
-
}
|
|
37895
|
-
} catch (err) {
|
|
37896
|
-
console.error(`Failed to fetch tags for ${this.type}/${this.id}:`, err);
|
|
37897
|
-
}
|
|
37898
|
-
return {};
|
|
37899
|
-
}
|
|
37900
|
-
async persistTags(tags) {
|
|
37901
|
-
const tagsForApi = {};
|
|
37902
|
-
for (const [key, value] of Object.entries(tags)) {
|
|
37903
|
-
if (value !== void 0) {
|
|
37904
|
-
tagsForApi[key] = value;
|
|
37905
|
-
}
|
|
37906
|
-
}
|
|
37907
|
-
try {
|
|
37908
|
-
if (this.type === "bot") {
|
|
37909
|
-
await this.client.updateBot({ id: this.id, tags: tagsForApi });
|
|
37910
|
-
} else if (this.type === "user") {
|
|
37911
|
-
await this.client.updateUser({ id: this.id, tags: tagsForApi });
|
|
37912
|
-
} else if (this.type === "conversation") {
|
|
37913
|
-
await this.client.updateConversation({ id: this.id, tags: tagsForApi });
|
|
37914
|
-
} else if (this.type === "workflow") {
|
|
37915
|
-
await this.client.updateWorkflow({ id: this.id, tags: tagsForApi });
|
|
37916
|
-
}
|
|
37917
|
-
} catch (err) {
|
|
37918
|
-
console.error(`Failed to persist tags for ${this.type}/${this.id}:`, err);
|
|
37919
|
-
throw err;
|
|
37920
|
-
}
|
|
37921
|
-
}
|
|
37922
|
-
};
|
|
37923
|
-
}
|
|
37924
|
-
});
|
|
37925
|
-
|
|
37926
37866
|
// src/runtime/client.ts
|
|
37927
37867
|
import { Client as Client3 } from "@botpress/client";
|
|
37928
37868
|
function getStandaloneClient() {
|
|
@@ -38239,12 +38179,12 @@ var init_workflow_step = __esm({
|
|
|
38239
38179
|
workflowControlContext.abort();
|
|
38240
38180
|
throw createStepSignal();
|
|
38241
38181
|
};
|
|
38242
|
-
step.sleep = async (name,
|
|
38182
|
+
step.sleep = async (name, ms4) => {
|
|
38243
38183
|
await _step(
|
|
38244
38184
|
name,
|
|
38245
38185
|
async () => {
|
|
38246
38186
|
const remainingTime = context.get("runtime").getRemainingExecutionTimeInMs();
|
|
38247
|
-
if (remainingTime - MIN_STEP_REMAINING_TIME_MS <=
|
|
38187
|
+
if (remainingTime - MIN_STEP_REMAINING_TIME_MS <= ms4 || ms4 >= 1e4) {
|
|
38248
38188
|
const client2 = context.get("client");
|
|
38249
38189
|
const workflowControlContext = context.get("workflowControlContext");
|
|
38250
38190
|
await client2.createEvent({
|
|
@@ -38252,7 +38192,7 @@ var init_workflow_step = __esm({
|
|
|
38252
38192
|
payload: {},
|
|
38253
38193
|
workflowId: workflowControlContext.workflow.id,
|
|
38254
38194
|
schedule: {
|
|
38255
|
-
delay:
|
|
38195
|
+
delay: ms4
|
|
38256
38196
|
}
|
|
38257
38197
|
});
|
|
38258
38198
|
await updateWorkflow({
|
|
@@ -38261,7 +38201,7 @@ var init_workflow_step = __esm({
|
|
|
38261
38201
|
});
|
|
38262
38202
|
workflowControlContext.abort();
|
|
38263
38203
|
} else {
|
|
38264
|
-
await new Promise((resolve) => void setTimeout(resolve,
|
|
38204
|
+
await new Promise((resolve) => void setTimeout(resolve, ms4));
|
|
38265
38205
|
context.get("workflowControlContext").signal.throwIfAborted();
|
|
38266
38206
|
}
|
|
38267
38207
|
},
|
|
@@ -38272,8 +38212,8 @@ var init_workflow_step = __esm({
|
|
|
38272
38212
|
);
|
|
38273
38213
|
};
|
|
38274
38214
|
step.sleepUntil = async (name, date) => {
|
|
38275
|
-
const
|
|
38276
|
-
await step.sleep(name,
|
|
38215
|
+
const ms4 = Math.max(0, new Date(date).getTime() - Date.now() - MIN_STEP_REMAINING_TIME_MS);
|
|
38216
|
+
await step.sleep(name, ms4);
|
|
38277
38217
|
};
|
|
38278
38218
|
step.waitForWorkflow = async (name, workflowId) => {
|
|
38279
38219
|
const workflowControlContext = context.get("workflowControlContext");
|
|
@@ -38492,12 +38432,13 @@ function createWorkflowExecutionState(client2, workflowId) {
|
|
|
38492
38432
|
name: BUILT_IN_STATES.workflowSteps
|
|
38493
38433
|
});
|
|
38494
38434
|
}
|
|
38495
|
-
var workflowStepContextSchema, workflowExecutionContextSchema, StepSymbol, BaseWorkflowInstance;
|
|
38435
|
+
var import_ms3, workflowStepContextSchema, workflowExecutionContextSchema, StepSymbol, BaseWorkflowInstance;
|
|
38496
38436
|
var init_workflow_instance = __esm({
|
|
38497
38437
|
"src/primitives/workflow-instance.ts"() {
|
|
38498
38438
|
"use strict";
|
|
38499
38439
|
init_define_BUILD();
|
|
38500
38440
|
init_define_PACKAGE_VERSIONS();
|
|
38441
|
+
import_ms3 = __toESM(require_ms(), 1);
|
|
38501
38442
|
init_errors();
|
|
38502
38443
|
init_library();
|
|
38503
38444
|
init_autonomous();
|
|
@@ -38624,6 +38565,81 @@ var init_workflow_instance = __esm({
|
|
|
38624
38565
|
});
|
|
38625
38566
|
Object.assign(this.workflow, workflow);
|
|
38626
38567
|
}
|
|
38568
|
+
/**
|
|
38569
|
+
* Extend the workflow timeout by setting a new timeout.
|
|
38570
|
+
* This is useful for long-running workflows that need more time to complete.
|
|
38571
|
+
*
|
|
38572
|
+
* @param options - Either `{ in: string }` for relative duration or `{ at: string }` for absolute ISO timestamp
|
|
38573
|
+
* @returns A promise that resolves when the timeout is updated (can be awaited or not)
|
|
38574
|
+
* @example
|
|
38575
|
+
* // Relative timeout (duration from now):
|
|
38576
|
+
* workflow.setTimeout({ in: '30m' }) // Timeout in 30 minutes
|
|
38577
|
+
* workflow.setTimeout({ in: '6 hours' }) // Timeout in 6 hours
|
|
38578
|
+
*
|
|
38579
|
+
* // Absolute timeout (ISO timestamp):
|
|
38580
|
+
* workflow.setTimeout({ at: '2024-12-25T00:00:00Z' })
|
|
38581
|
+
*
|
|
38582
|
+
* // Optionally await if you need to ensure the update completes:
|
|
38583
|
+
* await workflow.setTimeout({ in: '1h' })
|
|
38584
|
+
*/
|
|
38585
|
+
setTimeout(options) {
|
|
38586
|
+
let newTimeoutAt;
|
|
38587
|
+
if ("in" in options) {
|
|
38588
|
+
const durationMs = (0, import_ms3.default)(options.in);
|
|
38589
|
+
if (!durationMs) {
|
|
38590
|
+
throw new Error(`Invalid duration format: "${options.in}". Use formats like "30m", "1h", "6 hours".`);
|
|
38591
|
+
}
|
|
38592
|
+
newTimeoutAt = new Date(Date.now() + durationMs).toISOString();
|
|
38593
|
+
} else {
|
|
38594
|
+
const date = new Date(options.at);
|
|
38595
|
+
if (isNaN(date.getTime())) {
|
|
38596
|
+
throw new Error(`Invalid ISO date format: "${options.at}".`);
|
|
38597
|
+
}
|
|
38598
|
+
newTimeoutAt = date.toISOString();
|
|
38599
|
+
}
|
|
38600
|
+
return updateWorkflow({
|
|
38601
|
+
id: this.id,
|
|
38602
|
+
timeoutAt: newTimeoutAt
|
|
38603
|
+
}).then(({ workflow }) => {
|
|
38604
|
+
Object.assign(this.workflow, workflow);
|
|
38605
|
+
});
|
|
38606
|
+
}
|
|
38607
|
+
/**
|
|
38608
|
+
* Fail the workflow with an error reason.
|
|
38609
|
+
* This immediately interrupts the workflow handler and marks the workflow as failed.
|
|
38610
|
+
* Can only be called from within a workflow handler.
|
|
38611
|
+
*
|
|
38612
|
+
* @param reason - The error reason for the failure
|
|
38613
|
+
* @throws Never returns - always throws to interrupt the handler
|
|
38614
|
+
* @example
|
|
38615
|
+
* workflow.fail('Invalid input data')
|
|
38616
|
+
*/
|
|
38617
|
+
fail(reason) {
|
|
38618
|
+
const controlContext = context.get("workflowControlContext", { optional: true });
|
|
38619
|
+
if (!controlContext || controlContext.workflow.id !== this.id) {
|
|
38620
|
+
throw new Error("workflow.fail() can only be called from within the workflow handler");
|
|
38621
|
+
}
|
|
38622
|
+
controlContext.fail(reason);
|
|
38623
|
+
throw createStepSignal();
|
|
38624
|
+
}
|
|
38625
|
+
/**
|
|
38626
|
+
* Complete the workflow early with the given output.
|
|
38627
|
+
* This immediately interrupts the workflow handler and marks the workflow as completed.
|
|
38628
|
+
* Can only be called from within a workflow handler.
|
|
38629
|
+
*
|
|
38630
|
+
* @param output - The workflow output (typed according to workflow definition)
|
|
38631
|
+
* @throws Never returns - always throws to interrupt the handler
|
|
38632
|
+
* @example
|
|
38633
|
+
* workflow.complete({ result: 'success', data: processedData })
|
|
38634
|
+
*/
|
|
38635
|
+
complete(output2) {
|
|
38636
|
+
const controlContext = context.get("workflowControlContext", { optional: true });
|
|
38637
|
+
if (!controlContext || controlContext.workflow.id !== this.id) {
|
|
38638
|
+
throw new Error("workflow.complete() can only be called from within the workflow handler");
|
|
38639
|
+
}
|
|
38640
|
+
controlContext.complete(output2);
|
|
38641
|
+
throw createStepSignal();
|
|
38642
|
+
}
|
|
38627
38643
|
/**
|
|
38628
38644
|
* Provide data in response to a workflow data request (instance method).
|
|
38629
38645
|
* Call this method from a conversation handler when you receive a WorkflowDataRequestEvent.
|
|
@@ -38674,6 +38690,7 @@ var init_workflow_instance = __esm({
|
|
|
38674
38690
|
workflow: this.workflow,
|
|
38675
38691
|
aborted: false,
|
|
38676
38692
|
failed: false,
|
|
38693
|
+
completed: false,
|
|
38677
38694
|
acked: false,
|
|
38678
38695
|
restarted: false,
|
|
38679
38696
|
signal: abortSignal,
|
|
@@ -38688,6 +38705,10 @@ var init_workflow_instance = __esm({
|
|
|
38688
38705
|
workflowControlContext.failed = true;
|
|
38689
38706
|
workflowControlContext.failedReason = reason;
|
|
38690
38707
|
},
|
|
38708
|
+
complete: (result) => {
|
|
38709
|
+
workflowControlContext.completed = true;
|
|
38710
|
+
workflowControlContext.completedResult = result;
|
|
38711
|
+
},
|
|
38691
38712
|
ack: async () => {
|
|
38692
38713
|
if (workflowControlContext.acked) {
|
|
38693
38714
|
return;
|
|
@@ -38741,7 +38762,8 @@ var init_workflow_instance = __esm({
|
|
|
38741
38762
|
step,
|
|
38742
38763
|
client: this.client,
|
|
38743
38764
|
execute: this.execute.bind(this),
|
|
38744
|
-
signal: abortSignal
|
|
38765
|
+
signal: abortSignal,
|
|
38766
|
+
workflow: this
|
|
38745
38767
|
});
|
|
38746
38768
|
return {
|
|
38747
38769
|
status: "done",
|
|
@@ -38752,6 +38774,12 @@ var init_workflow_instance = __esm({
|
|
|
38752
38774
|
}
|
|
38753
38775
|
} catch (err) {
|
|
38754
38776
|
if (isStepSignal(err)) {
|
|
38777
|
+
if (workflowControlContext.completed) {
|
|
38778
|
+
return {
|
|
38779
|
+
status: "done",
|
|
38780
|
+
result: workflowControlContext.completedResult
|
|
38781
|
+
};
|
|
38782
|
+
}
|
|
38755
38783
|
if (workflowControlContext.failed) {
|
|
38756
38784
|
return {
|
|
38757
38785
|
status: "error",
|
|
@@ -41035,7 +41063,7 @@ var init_source_website = __esm({
|
|
|
41035
41063
|
type: "website",
|
|
41036
41064
|
state: State,
|
|
41037
41065
|
async handler({ input, step: step2, state, client: client2 }) {
|
|
41038
|
-
const
|
|
41066
|
+
const crypto2 = await import("crypto");
|
|
41039
41067
|
console.log(
|
|
41040
41068
|
`Starting sync for WebsiteSource [${this.id}] in mode [${this.mode}, maxPages=${this.maxPages}, maxDepth=${this.maxDepth}, baseUrl=${this.baseUrl}, sitemapUrl=${this.sitemapUrl}]`
|
|
41041
41069
|
);
|
|
@@ -41117,7 +41145,7 @@ var init_source_website = __esm({
|
|
|
41117
41145
|
content,
|
|
41118
41146
|
metadata: fetchMetadata
|
|
41119
41147
|
} = await this.fetchUrl(sitemapUrl.loc);
|
|
41120
|
-
const hash =
|
|
41148
|
+
const hash = crypto2.createHash("sha256").update(content).digest("hex");
|
|
41121
41149
|
let contentType = fetchedContentType;
|
|
41122
41150
|
if (!contentType) {
|
|
41123
41151
|
contentType = content.includes("<html") ? "text/html" : "text/markdown";
|
|
@@ -48114,7 +48142,7 @@ var init_source_directory = __esm({
|
|
|
48114
48142
|
const glob2 = await Promise.resolve().then(() => (init_esm9(), esm_exports3));
|
|
48115
48143
|
const path5 = await import("path");
|
|
48116
48144
|
const fs3 = await import("fs/promises");
|
|
48117
|
-
const
|
|
48145
|
+
const crypto2 = await import("crypto");
|
|
48118
48146
|
const directory = path5.resolve(adk.environment.agent.directory, this.directoryPath);
|
|
48119
48147
|
const tags = {
|
|
48120
48148
|
[WellKnownTags.knowledge.KNOWLEDGE]: "knowledge-base",
|
|
@@ -48176,7 +48204,7 @@ var init_source_directory = __esm({
|
|
|
48176
48204
|
const upsertFile = async (local) => {
|
|
48177
48205
|
const key = `data_source://${this.type}/${this.id}/${local.rel}`;
|
|
48178
48206
|
const content = await fs3.readFile(local.abs);
|
|
48179
|
-
const hash =
|
|
48207
|
+
const hash = crypto2.createHash("sha256").update(content).digest("hex");
|
|
48180
48208
|
const { file } = await client2.getFile({ id: key }).catch(() => ({ file: null }));
|
|
48181
48209
|
if (!input.force && file?.metadata?.hash === hash) {
|
|
48182
48210
|
console.log(`Skipping unchanged file: ${local.rel}`);
|