@botpress/runtime 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/_types/channels.d.ts +18 -0
  2. package/dist/_types/channels.d.ts.map +1 -0
  3. package/dist/_types/conversations.d.ts +9 -0
  4. package/dist/_types/conversations.d.ts.map +1 -0
  5. package/dist/_types/integrations.d.ts +13 -0
  6. package/dist/_types/integrations.d.ts.map +1 -0
  7. package/dist/consts.d.ts +1 -0
  8. package/dist/consts.d.ts.map +1 -1
  9. package/dist/definition.d.ts +1 -0
  10. package/dist/definition.d.ts.map +1 -1
  11. package/dist/definition.js +45914 -9
  12. package/dist/definition.js.map +4 -4
  13. package/dist/internal.d.ts +2 -0
  14. package/dist/internal.d.ts.map +1 -1
  15. package/dist/internal.js +313 -202
  16. package/dist/internal.js.map +4 -4
  17. package/dist/library.d.ts +5 -1
  18. package/dist/library.d.ts.map +1 -1
  19. package/dist/library.js +290 -162
  20. package/dist/library.js.map +4 -4
  21. package/dist/primitives/conversation-instance.d.ts +42 -0
  22. package/dist/primitives/conversation-instance.d.ts.map +1 -0
  23. package/dist/primitives/conversation.d.ts +30 -64
  24. package/dist/primitives/conversation.d.ts.map +1 -1
  25. package/dist/primitives/definition.d.ts +1 -1
  26. package/dist/primitives/definition.d.ts.map +1 -1
  27. package/dist/primitives/index.d.ts +3 -0
  28. package/dist/primitives/index.d.ts.map +1 -1
  29. package/dist/primitives/knowledge.d.ts.map +1 -1
  30. package/dist/primitives/workflow-instance.d.ts +0 -2
  31. package/dist/primitives/workflow-instance.d.ts.map +1 -1
  32. package/dist/primitives/workflow.d.ts +1 -2
  33. package/dist/primitives/workflow.d.ts.map +1 -1
  34. package/dist/runtime/adk.d.ts +1 -1
  35. package/dist/runtime/adk.d.ts.map +1 -1
  36. package/dist/runtime/autonomous.d.ts.map +1 -1
  37. package/dist/runtime/handlers/conversation-matching.d.ts +17 -0
  38. package/dist/runtime/handlers/conversation-matching.d.ts.map +1 -0
  39. package/dist/runtime/handlers/conversation.d.ts.map +1 -1
  40. package/dist/runtime/handlers/event.d.ts.map +1 -1
  41. package/dist/runtime/tracked-state.d.ts +16 -5
  42. package/dist/runtime/tracked-state.d.ts.map +1 -1
  43. package/dist/runtime.js +325 -205
  44. package/dist/runtime.js.map +4 -4
  45. package/dist/telemetry/structured-logging.d.ts.map +1 -1
  46. package/dist/workers/dev_worker.d.ts.map +1 -1
  47. package/dist/workers/worker_pool.d.ts.map +1 -1
  48. package/package.json +1 -1
package/dist/library.js CHANGED
@@ -48,7 +48,7 @@ var init_define_BUILD = __esm({
48
48
  var define_PACKAGE_VERSIONS_default;
49
49
  var init_define_PACKAGE_VERSIONS = __esm({
50
50
  "<define:__PACKAGE_VERSIONS__>"() {
51
- define_PACKAGE_VERSIONS_default = { runtime: "1.2.3", adk: "not-installed", sdk: "4.16.0", llmz: "0.0.26", zai: "2.1.16", cognitive: "0.1.47" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.2.5", adk: "not-installed", sdk: "4.16.0", llmz: "0.0.26", zai: "2.1.16", cognitive: "0.1.47" };
52
52
  }
53
53
  });
54
54
 
@@ -27463,6 +27463,47 @@ var require_indexv2 = __commonJS({
27463
27463
  }
27464
27464
  });
27465
27465
 
27466
+ // src/utilities/trigger-tags.ts
27467
+ var trigger_tags_exports = {};
27468
+ __export(trigger_tags_exports, {
27469
+ getTriggerSubscriptionTags: () => getTriggerSubscriptionTags,
27470
+ getTriggerTagName: () => getTriggerTagName,
27471
+ getTriggerTagValue: () => getTriggerTagValue,
27472
+ isConversationSubscribedToTrigger: () => isConversationSubscribedToTrigger
27473
+ });
27474
+ import crypto2 from "crypto";
27475
+ var hashString, getTriggerTagName, getTriggerTagValue, getTriggerSubscriptionTags, isConversationSubscribedToTrigger;
27476
+ var init_trigger_tags = __esm({
27477
+ "src/utilities/trigger-tags.ts"() {
27478
+ "use strict";
27479
+ init_define_BUILD();
27480
+ init_define_PACKAGE_VERSIONS();
27481
+ hashString = (str) => {
27482
+ return crypto2.createHash("md5").update(str).digest("hex").substring(0, 5).toUpperCase();
27483
+ };
27484
+ getTriggerTagName = (triggerName) => {
27485
+ return `trigger${hashString(triggerName)}`;
27486
+ };
27487
+ getTriggerTagValue = (key) => {
27488
+ return key ?? "*";
27489
+ };
27490
+ getTriggerSubscriptionTags = (triggerName, key) => {
27491
+ return {
27492
+ name: getTriggerTagName(triggerName),
27493
+ value: getTriggerTagValue(key)
27494
+ };
27495
+ };
27496
+ isConversationSubscribedToTrigger = (conversationTags, triggerName, triggerKey) => {
27497
+ const tagName = getTriggerTagName(triggerName);
27498
+ const tagValue = conversationTags[tagName];
27499
+ if (!tagValue) {
27500
+ return false;
27501
+ }
27502
+ return tagValue === "*" || tagValue === triggerKey;
27503
+ };
27504
+ }
27505
+ });
27506
+
27466
27507
  // ../../node_modules/.bun/@isaacs+balanced-match@4.0.1/node_modules/@isaacs/balanced-match/dist/esm/index.js
27467
27508
  var balanced, maybeMatch, range;
27468
27509
  var init_esm3 = __esm({
@@ -36247,6 +36288,7 @@ init_define_PACKAGE_VERSIONS();
36247
36288
  // src/consts.ts
36248
36289
  init_define_BUILD();
36249
36290
  init_define_PACKAGE_VERSIONS();
36291
+ var LOG_DELIMITER = "<|MESSAGE_END|>\n";
36250
36292
 
36251
36293
  // src/runtime/context/handlers.ts
36252
36294
  import { Client } from "@botpress/client";
@@ -40241,6 +40283,8 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
40241
40283
  const { passages } = await client.searchFiles({
40242
40284
  query,
40243
40285
  withContext: true,
40286
+ includeBreadcrumb: true,
40287
+ contextDepth: 4,
40244
40288
  tags: {
40245
40289
  [WellKnownTags.knowledge.KNOWLEDGE]: "true",
40246
40290
  [WellKnownTags.knowledge.KNOWLEDGE_BASE_NAME]: kbNames
@@ -40284,8 +40328,9 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
40284
40328
  citationMetadata.sourceId = tags[WellKnownTags.knowledge.KNOWLEDGE_SOURCE_ID];
40285
40329
  }
40286
40330
  const { tag } = citations.registerSource(citationMetadata);
40287
- message.push(`<${tag} file="${p.file.key}">`);
40288
- message.push(`**${citationMetadata.title || p.file.key}**`);
40331
+ message.push(
40332
+ `<${tag} file="${p.file.key}" title="${citationMetadata.title || p.file.key}">`
40333
+ );
40289
40334
  message.push(p.content);
40290
40335
  message.push(`</${tag}>`);
40291
40336
  }
@@ -40411,6 +40456,7 @@ Always prefer information from the knowledge bases over general knowledge when a
40411
40456
  message: "ThinkSignal"
40412
40457
  });
40413
40458
  err[HandledErrorProp] = true;
40459
+ throw err;
40414
40460
  } else {
40415
40461
  s.setAttributes({
40416
40462
  "autonomous.tool.status": "error",
@@ -40941,7 +40987,17 @@ function serializeArgs(...args) {
40941
40987
  });
40942
40988
  }
40943
40989
  function writeStructuredLog(type, ...args) {
40990
+ const output2 = process.stdout;
40944
40991
  const { spanId, traceId } = getTraceContext();
40992
+ let maybeArgObj = null;
40993
+ try {
40994
+ maybeArgObj = typeof args[0] === "string" ? JSON.parse(args[0]) : args[0];
40995
+ } catch {
40996
+ }
40997
+ if (maybeArgObj && typeof maybeArgObj === "object" && maybeArgObj.type === "worker_stats") {
40998
+ output2.write((0, import_fast_safe_stringify3.default)(maybeArgObj) + LOG_DELIMITER);
40999
+ return;
41000
+ }
40945
41001
  const logEntry = {
40946
41002
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
40947
41003
  type,
@@ -40953,8 +41009,7 @@ function writeStructuredLog(type, ...args) {
40953
41009
  if (traceId) {
40954
41010
  logEntry.traceId = traceId;
40955
41011
  }
40956
- const output2 = process.stdout;
40957
- output2.write(JSON.stringify(logEntry) + "\n");
41012
+ output2.write((0, import_fast_safe_stringify3.default)(logEntry) + LOG_DELIMITER);
40958
41013
  }
40959
41014
  function installStructuredLogging() {
40960
41015
  console.log = (...args) => {
@@ -40975,36 +41030,9 @@ function installStructuredLogging() {
40975
41030
  }
40976
41031
 
40977
41032
  // src/runtime.ts
41033
+ init_trigger_tags();
40978
41034
  import { z as z4 } from "@botpress/sdk";
40979
41035
 
40980
- // src/utilities/trigger-tags.ts
40981
- init_define_BUILD();
40982
- init_define_PACKAGE_VERSIONS();
40983
- import crypto2 from "crypto";
40984
- var hashString = (str) => {
40985
- return crypto2.createHash("md5").update(str).digest("hex").substring(0, 5).toUpperCase();
40986
- };
40987
- var getTriggerTagName = (triggerName) => {
40988
- return `trigger${hashString(triggerName)}`;
40989
- };
40990
- var getTriggerTagValue = (key) => {
40991
- return key ?? "*";
40992
- };
40993
- var getTriggerSubscriptionTags = (triggerName, key) => {
40994
- return {
40995
- name: getTriggerTagName(triggerName),
40996
- value: getTriggerTagValue(key)
40997
- };
40998
- };
40999
- var isConversationSubscribedToTrigger = (conversationTags, triggerName, triggerKey) => {
41000
- const tagName = getTriggerTagName(triggerName);
41001
- const tagValue = conversationTags[tagName];
41002
- if (!tagValue) {
41003
- return false;
41004
- }
41005
- return tagValue === "*" || tagValue === triggerKey;
41006
- };
41007
-
41008
41036
  // src/types.ts
41009
41037
  init_define_BUILD();
41010
41038
  init_define_PACKAGE_VERSIONS();
@@ -41606,12 +41634,6 @@ var BaseWorkflowInstance = class _BaseWorkflowInstance {
41606
41634
  workflow;
41607
41635
  // @internal
41608
41636
  TrackedState;
41609
- set state(state) {
41610
- this.TrackedState.value = state;
41611
- }
41612
- get state() {
41613
- return this.TrackedState.value;
41614
- }
41615
41637
  constructor(workflow, client) {
41616
41638
  const definition = adk.project.workflows.find(
41617
41639
  (w) => w.name === workflow.name
@@ -41621,7 +41643,7 @@ var BaseWorkflowInstance = class _BaseWorkflowInstance {
41621
41643
  client: client._inner,
41622
41644
  id: workflow.id,
41623
41645
  schema: definition?.stateSchema,
41624
- name: "workflowState"
41646
+ name: BUILT_IN_STATES.workflowState
41625
41647
  });
41626
41648
  this.id = workflow.id;
41627
41649
  this.name = workflow.name;
@@ -41752,14 +41774,25 @@ var BaseWorkflowInstance = class _BaseWorkflowInstance {
41752
41774
  "Workflow execution state is not loaded"
41753
41775
  );
41754
41776
  workflowExecutionState.value.executionCount++;
41777
+ if (!this.TrackedState.value) {
41778
+ this.TrackedState.value = {};
41779
+ }
41780
+ const trackedState = this.TrackedState;
41781
+ const stateProxy = new Proxy(this.TrackedState.value, {
41782
+ set(target, prop, value) {
41783
+ const result2 = Reflect.set(target, prop, value);
41784
+ trackedState.markDirty();
41785
+ return result2;
41786
+ }
41787
+ });
41755
41788
  const result = await context.run(
41756
41789
  {
41757
41790
  ...ctx,
41758
41791
  workflowControlContext
41759
41792
  },
41760
- async () => handler.call(this, {
41793
+ async () => handler({
41761
41794
  input: this.input,
41762
- state: this.state,
41795
+ state: stateProxy,
41763
41796
  step,
41764
41797
  client: this.client,
41765
41798
  execute: this.execute.bind(this)
@@ -41825,7 +41858,7 @@ function createWorkflowExecutionState(client, workflowId) {
41825
41858
  client,
41826
41859
  id: workflowId,
41827
41860
  schema: workflowExecutionContextSchema,
41828
- name: "workflowExecutionContext"
41861
+ name: BUILT_IN_STATES.workflowSteps
41829
41862
  });
41830
41863
  }
41831
41864
 
@@ -41852,8 +41885,6 @@ var BaseWorkflow = class {
41852
41885
  /** @internal */
41853
41886
  schedule;
41854
41887
  timeout = (0, import_ms.default)("5m");
41855
- // Runtime state
41856
- state;
41857
41888
  constructor(props) {
41858
41889
  this.name = props.name;
41859
41890
  if (props.description !== void 0) {
@@ -42216,10 +42247,15 @@ var EMPTY_STATE = {
42216
42247
  };
42217
42248
  var MAX_SWAP_FILE_SIZE = import_bytes2.default.parse("100MB");
42218
42249
  var BUILT_IN_STATES = {
42219
- user: "userState",
42250
+ /** Generic conversation-specific state (user-defined per conversation) */
42220
42251
  conversation: "state",
42252
+ /** User-specific state (persists across conversations per user) */
42253
+ user: "userState",
42254
+ /** Bot-wide global state (persists across all conversations) */
42221
42255
  bot: "botState",
42256
+ /** Workflow-specific state (persists across workflow executions) */
42222
42257
  workflowState: "workflowState",
42258
+ /** Workflow cached steps executions */
42223
42259
  workflowSteps: "workflowSteps"
42224
42260
  };
42225
42261
  var TrackedState = class _TrackedState {
@@ -42292,6 +42328,7 @@ var TrackedState = class _TrackedState {
42292
42328
  const client = context.get("client")._inner;
42293
42329
  const botId = context.get("botId", { optional: true });
42294
42330
  const user2 = context.get("user", { optional: true });
42331
+ const conversation = context.get("conversation", { optional: true });
42295
42332
  if (botId) {
42296
42333
  _TrackedState.create({
42297
42334
  client,
@@ -42310,6 +42347,23 @@ var TrackedState = class _TrackedState {
42310
42347
  schema: adk.project.config.user?.state || z12.object({})
42311
42348
  });
42312
42349
  }
42350
+ if (conversation) {
42351
+ const definition = adk.project.conversations.find((c) => {
42352
+ const def = c.getDefinition();
42353
+ if (typeof def.channel === "string") {
42354
+ return def.channel === conversation.channel || def.channel === "*";
42355
+ } else {
42356
+ return def.channel.includes(conversation.channel);
42357
+ }
42358
+ });
42359
+ _TrackedState.create({
42360
+ client,
42361
+ name: BUILT_IN_STATES.conversation,
42362
+ type: "conversation",
42363
+ id: conversation.id,
42364
+ schema: definition?.schema || z12.object({})
42365
+ });
42366
+ }
42313
42367
  const states = context.get("states", { optional: true });
42314
42368
  const promises = Promise.allSettled(
42315
42369
  states?.map((state) => state.load()) ?? []
@@ -42356,16 +42410,23 @@ var TrackedState = class _TrackedState {
42356
42410
  } else {
42357
42411
  this.value = value;
42358
42412
  }
42359
- if ((this.value == null || this.value === void 0) && this.state && "parse" in this.state) {
42360
- try {
42361
- this.value = this.state.parse({});
42362
- this._isDirty = true;
42363
- } catch (error) {
42413
+ if (this.value == null || this.value === void 0) {
42414
+ if (this.state && "parse" in this.state) {
42364
42415
  try {
42365
- this.value = this.state.parse(void 0);
42416
+ this.value = this.state.parse({});
42366
42417
  this._isDirty = true;
42367
- } catch {
42418
+ } catch (error) {
42419
+ try {
42420
+ this.value = this.state.parse(void 0);
42421
+ this._isDirty = true;
42422
+ } catch {
42423
+ this.value = {};
42424
+ this._isDirty = true;
42425
+ }
42368
42426
  }
42427
+ } else {
42428
+ this.value = {};
42429
+ this._isDirty = true;
42369
42430
  }
42370
42431
  }
42371
42432
  try {
@@ -42961,24 +43022,145 @@ init_define_BUILD();
42961
43022
  init_define_PACKAGE_VERSIONS();
42962
43023
  import { z as z16 } from "@botpress/sdk";
42963
43024
  import { setTimeout as setTimeout2 } from "node:timers/promises";
43025
+
43026
+ // src/primitives/conversation-instance.ts
43027
+ init_define_BUILD();
43028
+ init_define_PACKAGE_VERSIONS();
43029
+ var BaseConversationInstance = class {
43030
+ id;
43031
+ channel;
43032
+ integration;
43033
+ tags;
43034
+ conversation;
43035
+ // @internal
43036
+ client;
43037
+ // @internal
43038
+ TrackedState;
43039
+ constructor(conversation, client) {
43040
+ this.id = conversation.id;
43041
+ this.channel = conversation.channel;
43042
+ this.integration = conversation.integration;
43043
+ this.tags = conversation.tags;
43044
+ this.conversation = conversation;
43045
+ this.client = client;
43046
+ const states = context.get("states", { optional: true });
43047
+ const existingState = states?.find(
43048
+ (s) => s.type === "conversation" && s.id === conversation.id && s.name === BUILT_IN_STATES.conversation
43049
+ );
43050
+ if (!existingState) {
43051
+ throw new Error(
43052
+ `Conversation state not found for conversation ${conversation.id}. Make sure TrackedState.loadAll() is called before creating conversation instances.`
43053
+ );
43054
+ }
43055
+ this.TrackedState = existingState;
43056
+ }
43057
+ /**
43058
+ * Send a message to this conversation
43059
+ */
43060
+ async send(message) {
43061
+ try {
43062
+ const chat = context.get("chat");
43063
+ await trackPromise(
43064
+ chat.sendMessage({
43065
+ type: message.type,
43066
+ payload: message.payload
43067
+ })
43068
+ );
43069
+ } catch (err) {
43070
+ console.error("Error sending message in conversation:", err);
43071
+ }
43072
+ }
43073
+ /**
43074
+ * Start typing indicator
43075
+ */
43076
+ async startTyping() {
43077
+ const mapping = InterfaceMappings.getIntegrationAction(
43078
+ "typingIndicator",
43079
+ "startTypingIndicator",
43080
+ this.integration
43081
+ );
43082
+ if (mapping) {
43083
+ const message = context.get("message", { optional: true });
43084
+ await this.client.callAction({
43085
+ type: mapping,
43086
+ input: {
43087
+ conversationId: this.id,
43088
+ messageId: message?.id
43089
+ }
43090
+ }).catch(() => {
43091
+ });
43092
+ }
43093
+ }
43094
+ /**
43095
+ * Stop typing indicator
43096
+ */
43097
+ async stopTyping() {
43098
+ const mapping = InterfaceMappings.getIntegrationAction(
43099
+ "typingIndicator",
43100
+ "stopTypingIndicator",
43101
+ this.integration
43102
+ );
43103
+ if (mapping) {
43104
+ const message = context.get("message", { optional: true });
43105
+ await this.client.callAction({
43106
+ type: mapping,
43107
+ input: {
43108
+ conversationId: this.id,
43109
+ messageId: message?.id
43110
+ }
43111
+ }).catch(() => {
43112
+ });
43113
+ }
43114
+ }
43115
+ /**
43116
+ * Subscribe to a trigger
43117
+ */
43118
+ async subscribeToTrigger(triggerName, key) {
43119
+ const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
43120
+ if (isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
43121
+ return;
43122
+ }
43123
+ const { name, value } = getTriggerSubscriptionTags2(triggerName, key);
43124
+ await this.client.updateConversation({
43125
+ id: this.id,
43126
+ tags: {
43127
+ [name]: value
43128
+ }
43129
+ });
43130
+ }
43131
+ /**
43132
+ * Unsubscribe from a trigger
43133
+ */
43134
+ async unsubscribeFromTrigger(triggerName, key) {
43135
+ const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
43136
+ if (!isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
43137
+ return;
43138
+ }
43139
+ const { name } = getTriggerSubscriptionTags2(triggerName, key);
43140
+ await this.client.updateConversation({
43141
+ id: this.id,
43142
+ tags: {
43143
+ [name]: ""
43144
+ }
43145
+ });
43146
+ }
43147
+ };
43148
+
43149
+ // src/primitives/conversation.ts
42964
43150
  var ConversationHandler = Symbol.for("conversation.handler");
42965
43151
  var Typings3;
42966
43152
  ((Typings8) => {
42967
43153
  Typings8.Primitive = "conversation";
42968
43154
  })(Typings3 || (Typings3 = {}));
42969
43155
  var BaseConversation = class {
42970
- integration;
42971
43156
  channel;
42972
43157
  /** @internal */
42973
43158
  schema;
42974
43159
  #handler;
42975
- #state;
42976
43160
  #startFromTrigger;
42977
- #interruptionSignal;
42978
43161
  constructor(props) {
42979
43162
  this.channel = props.channel;
42980
43163
  this.schema = props.state ?? z16.object({}).passthrough();
42981
- this.integration = props.channel.split(".")[0];
42982
43164
  this.#handler = props.handler;
42983
43165
  if (props.startFromTrigger) {
42984
43166
  this.#startFromTrigger = props.startFromTrigger;
@@ -42990,31 +43172,34 @@ var BaseConversation = class {
42990
43172
  }
42991
43173
  /** @internal */
42992
43174
  getDefinition() {
42993
- return {
42994
- type: "conversation",
42995
- channel: this.channel
42996
- };
42997
- }
42998
- set state(state) {
42999
- this.#state = state;
43000
- }
43001
- get state() {
43002
- return this.#state;
43003
- }
43004
- get id() {
43005
- return context.get("conversation").id;
43006
- }
43007
- get tags() {
43008
- return context.get("conversation").tags;
43175
+ if (this.channel === "*") {
43176
+ return {
43177
+ type: "conversation",
43178
+ channel: "*"
43179
+ };
43180
+ } else if (Array.isArray(this.channel)) {
43181
+ return {
43182
+ type: "conversation",
43183
+ channel: this.channel
43184
+ };
43185
+ } else {
43186
+ return {
43187
+ type: "conversation",
43188
+ channel: this.channel
43189
+ };
43190
+ }
43009
43191
  }
43010
- // TODO: separate the handler from the conversation definition
43011
- // TODO: each execution should have its own instance to avoid state conflicts etc
43192
+ /** @internal */
43012
43193
  async [ConversationHandler]() {
43013
43194
  const message = context.get("message", { optional: true });
43014
43195
  const event = context.get("event", { optional: true });
43015
43196
  const chat = context.get("chat");
43016
43197
  const client = context.get("client");
43017
- const conversationId = this.id;
43198
+ const botpressConversation = context.get("conversation");
43199
+ const conversationInstance = new BaseConversationInstance(
43200
+ botpressConversation,
43201
+ client
43202
+ );
43018
43203
  let type;
43019
43204
  let requestObject = void 0;
43020
43205
  if (message) {
@@ -43039,11 +43224,10 @@ var BaseConversation = class {
43039
43224
  type = "event";
43040
43225
  }
43041
43226
  const controller = new AbortController();
43042
- this.#interruptionSignal = controller.signal;
43043
43227
  void span(
43044
43228
  "interruption.check",
43045
43229
  {
43046
- conversationId
43230
+ conversationId: conversationInstance.id
43047
43231
  },
43048
43232
  async (s) => {
43049
43233
  async function checkNewUserMessage() {
@@ -43051,7 +43235,7 @@ var BaseConversation = class {
43051
43235
  return;
43052
43236
  }
43053
43237
  const { events } = await client.listEvents({
43054
- conversationId,
43238
+ conversationId: conversationInstance.id,
43055
43239
  status: "pending"
43056
43240
  });
43057
43241
  const newEvents = events.filter(
@@ -43107,100 +43291,36 @@ var BaseConversation = class {
43107
43291
  const execute = Autonomous.createExecute({
43108
43292
  mode: "chat",
43109
43293
  defaultModel: adk.project.config.defaultModels.autonomous,
43110
- ...this.#interruptionSignal && {
43111
- interruption: this.#interruptionSignal
43294
+ interruption: controller.signal
43295
+ });
43296
+ if (!conversationInstance.TrackedState.value) {
43297
+ conversationInstance.TrackedState.value = {};
43298
+ }
43299
+ const stateProxy = new Proxy(conversationInstance.TrackedState.value, {
43300
+ set(target, prop, value) {
43301
+ const result = Reflect.set(target, prop, value);
43302
+ conversationInstance.TrackedState.markDirty();
43303
+ return result;
43112
43304
  }
43113
43305
  });
43114
- await this.#handler.call(this, {
43306
+ await this.#handler({
43115
43307
  type,
43116
43308
  message,
43117
43309
  event,
43118
43310
  request: requestObject,
43311
+ conversation: conversationInstance,
43312
+ state: stateProxy,
43313
+ client,
43119
43314
  execute
43120
43315
  });
43121
43316
  controller.abort();
43122
43317
  }
43123
- async subscribeToTrigger(triggerName, key) {
43124
- if (isConversationSubscribedToTrigger(this.tags, triggerName, key)) {
43125
- return;
43126
- }
43127
- const conversation = context.get("conversation");
43128
- const client = context.get("client");
43129
- const { name, value } = getTriggerSubscriptionTags(triggerName, key);
43130
- await client.updateConversation({
43131
- id: conversation.id,
43132
- tags: {
43133
- [name]: value
43134
- }
43135
- });
43136
- }
43137
- async unsubscribeFromTrigger(triggerName, key) {
43138
- if (!isConversationSubscribedToTrigger(this.tags, triggerName, key)) {
43139
- return;
43140
- }
43141
- const conversation = context.get("conversation");
43142
- const client = context.get("client");
43143
- const { name } = getTriggerSubscriptionTags(triggerName, key);
43144
- await client.updateConversation({
43145
- id: conversation.id,
43146
- tags: {
43147
- [name]: ""
43148
- }
43149
- });
43150
- }
43151
- async startTyping() {
43152
- const conversation = context.get("conversation", { optional: true });
43153
- const message = context.get("message", { optional: true });
43154
- const mapping = InterfaceMappings.getIntegrationAction(
43155
- "typingIndicator",
43156
- "startTypingIndicator",
43157
- conversation?.integration
43158
- );
43159
- if (conversation && mapping) {
43160
- await context.get("client").callAction({
43161
- type: mapping,
43162
- input: {
43163
- conversationId: conversation.id,
43164
- messageId: message?.id
43165
- }
43166
- }).catch(() => {
43167
- });
43168
- }
43169
- }
43170
- async stopTyping() {
43171
- const conversation = context.get("conversation", { optional: true });
43172
- const message = context.get("message", { optional: true });
43173
- const mapping = InterfaceMappings.getIntegrationAction(
43174
- "typingIndicator",
43175
- "stopTypingIndicator",
43176
- conversation?.integration
43177
- );
43178
- if (conversation && mapping) {
43179
- await context.get("client").callAction({
43180
- type: mapping,
43181
- input: {
43182
- conversationId: conversation.id,
43183
- messageId: message?.id
43184
- }
43185
- }).catch(() => {
43186
- });
43187
- }
43188
- }
43189
- async send(message) {
43190
- try {
43191
- const chat = context.get("chat");
43192
- await trackPromise(
43193
- chat.sendMessage({
43194
- type: message.type,
43195
- payload: message.payload
43196
- })
43197
- );
43198
- } catch (err) {
43199
- console.error("Error getting context in conversation.send:", err);
43200
- }
43201
- }
43202
43318
  };
43203
43319
 
43320
+ // src/runtime/handlers/conversation-matching.ts
43321
+ init_define_BUILD();
43322
+ init_define_PACKAGE_VERSIONS();
43323
+
43204
43324
  // src/runtime/handlers/trigger.ts
43205
43325
  init_define_BUILD();
43206
43326
  init_define_PACKAGE_VERSIONS();
@@ -43225,7 +43345,12 @@ var Definitions;
43225
43345
  ((Definitions2) => {
43226
43346
  const conversationDefinitionSchema = z17.object({
43227
43347
  type: z17.literal("conversation"),
43228
- channel: z17.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^[a-zA-Z0-9._-]+$/, "Channel must be a valid identifier")
43348
+ channel: z17.union([
43349
+ z17.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^(\*|[a-zA-Z0-9._-]+)$/, "Channel must be a valid identifier or glob '*'"),
43350
+ z17.array(
43351
+ z17.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^[a-zA-Z0-9._-]+$/, "Channel must be a valid identifier")
43352
+ )
43353
+ ])
43229
43354
  });
43230
43355
  const workflowDefinitionSchema = z17.object({
43231
43356
  type: z17.literal("workflow"),
@@ -45475,6 +45600,7 @@ var BaseKnowledge = class {
45475
45600
  constructor(props) {
45476
45601
  this.name = props.name;
45477
45602
  this.sources = props.sources;
45603
+ this.description = props.description;
45478
45604
  }
45479
45605
  /** @internal */
45480
45606
  getDefinition() {
@@ -45848,6 +45974,7 @@ var Primitives;
45848
45974
  ((Primitives2) => {
45849
45975
  Primitives2.Definitions = Definitions;
45850
45976
  Primitives2.BaseConversation = BaseConversation;
45977
+ Primitives2.BaseConversationInstance = BaseConversationInstance;
45851
45978
  Primitives2.Conversation = Typings3;
45852
45979
  Primitives2.BaseKnowledge = BaseKnowledge;
45853
45980
  Primitives2.Knowledge = Typings4;
@@ -45876,6 +46003,7 @@ init_define_PACKAGE_VERSIONS();
45876
46003
  export {
45877
46004
  Action,
45878
46005
  Autonomous,
46006
+ BaseConversationInstance,
45879
46007
  BaseConversation as Conversation,
45880
46008
  DataSource2 as DataSource,
45881
46009
  Errors,