@botpress/runtime 1.2.4 → 1.3.0

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 (42) 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/definition.d.ts +1 -0
  8. package/dist/definition.d.ts.map +1 -1
  9. package/dist/definition.js +45914 -9
  10. package/dist/definition.js.map +4 -4
  11. package/dist/internal.d.ts +1 -0
  12. package/dist/internal.d.ts.map +1 -1
  13. package/dist/internal.js +277 -164
  14. package/dist/internal.js.map +4 -4
  15. package/dist/library.d.ts +5 -1
  16. package/dist/library.d.ts.map +1 -1
  17. package/dist/library.js +276 -164
  18. package/dist/library.js.map +4 -4
  19. package/dist/primitives/conversation-instance.d.ts +42 -0
  20. package/dist/primitives/conversation-instance.d.ts.map +1 -0
  21. package/dist/primitives/conversation.d.ts +30 -64
  22. package/dist/primitives/conversation.d.ts.map +1 -1
  23. package/dist/primitives/definition.d.ts +1 -1
  24. package/dist/primitives/definition.d.ts.map +1 -1
  25. package/dist/primitives/index.d.ts +3 -0
  26. package/dist/primitives/index.d.ts.map +1 -1
  27. package/dist/primitives/workflow-instance.d.ts +0 -2
  28. package/dist/primitives/workflow-instance.d.ts.map +1 -1
  29. package/dist/primitives/workflow.d.ts +1 -2
  30. package/dist/primitives/workflow.d.ts.map +1 -1
  31. package/dist/runtime/adk.d.ts +1 -1
  32. package/dist/runtime/adk.d.ts.map +1 -1
  33. package/dist/runtime/autonomous.d.ts.map +1 -1
  34. package/dist/runtime/handlers/conversation-matching.d.ts +17 -0
  35. package/dist/runtime/handlers/conversation-matching.d.ts.map +1 -0
  36. package/dist/runtime/handlers/conversation.d.ts.map +1 -1
  37. package/dist/runtime/handlers/event.d.ts.map +1 -1
  38. package/dist/runtime/tracked-state.d.ts +16 -5
  39. package/dist/runtime/tracked-state.d.ts.map +1 -1
  40. package/dist/runtime.js +311 -207
  41. package/dist/runtime.js.map +4 -4
  42. package/package.json +2 -2
@@ -9,6 +9,7 @@ export * from "./primitives";
9
9
  export * from "./errors";
10
10
  export * from "./telemetry/tracing";
11
11
  export { BuiltInWorkflows } from "./runtime/workflows";
12
+ export { BUILT_IN_STATES } from "./runtime/tracked-state";
12
13
  export { setAdkCommand } from "./environment";
13
14
  export { isAgentConfig } from "./define-config";
14
15
  export * from "./workers";
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
package/dist/internal.js CHANGED
@@ -48,7 +48,7 @@ var init_define_BUILD = __esm({
48
48
  var define_PACKAGE_VERSIONS_default;
49
49
  var init_define_PACKAGE_VERSIONS = __esm({
50
50
  "<define:__PACKAGE_VERSIONS__>"() {
51
- define_PACKAGE_VERSIONS_default = { runtime: "1.2.4", 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.3.0", adk: "not-installed", sdk: "4.17.0", llmz: "0.0.26", zai: "2.1.16", cognitive: "0.1.47" };
52
52
  }
53
53
  });
54
54
 
@@ -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({
@@ -40415,9 +40456,6 @@ var Autonomous;
40415
40456
  Autonomous2.DefaultExit = _DefaultExit;
40416
40457
  function createKnowledgeSearchTool(knowledgeBases) {
40417
40458
  const kbNames = knowledgeBases.map((kb) => kb.name);
40418
- for (const kb of knowledgeBases) {
40419
- console.log(kb.name, kb.description);
40420
- }
40421
40459
  const description = knowledgeBases.map((kb) => `- "${kb.name}": ${kb.description || "No description"}`).join("\n");
40422
40460
  return new LlmzTool({
40423
40461
  name: "search_knowledge",
@@ -40442,6 +40480,8 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
40442
40480
  const { passages } = await client.searchFiles({
40443
40481
  query,
40444
40482
  withContext: true,
40483
+ includeBreadcrumb: true,
40484
+ contextDepth: 4,
40445
40485
  tags: {
40446
40486
  [WellKnownTags.knowledge.KNOWLEDGE]: "true",
40447
40487
  [WellKnownTags.knowledge.KNOWLEDGE_BASE_NAME]: kbNames
@@ -40485,12 +40525,12 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
40485
40525
  citationMetadata.sourceId = tags[WellKnownTags.knowledge.KNOWLEDGE_SOURCE_ID];
40486
40526
  }
40487
40527
  const { tag } = citations.registerSource(citationMetadata);
40488
- message.push(`<${tag} file="${p.file.key}">`);
40489
- message.push(`**${citationMetadata.title || p.file.key}**`);
40528
+ message.push(
40529
+ `<${tag} file="${p.file.key}" title="${citationMetadata.title || p.file.key}">`
40530
+ );
40490
40531
  message.push(p.content);
40491
40532
  message.push(`</${tag}>`);
40492
40533
  }
40493
- console.log(message.join("\n").trim());
40494
40534
  throw new Autonomous2.ThinkSignal(
40495
40535
  `We got the search results. When answering the question, you MUST add inline the citations used (eg: "Yes, the price is $10${example} ...")`,
40496
40536
  message.join("\n").trim()
@@ -41001,36 +41041,9 @@ function installStructuredLogging() {
41001
41041
  }
41002
41042
 
41003
41043
  // src/runtime.ts
41044
+ init_trigger_tags();
41004
41045
  import { z as z4 } from "@botpress/sdk";
41005
41046
 
41006
- // src/utilities/trigger-tags.ts
41007
- init_define_BUILD();
41008
- init_define_PACKAGE_VERSIONS();
41009
- import crypto2 from "crypto";
41010
- var hashString = (str) => {
41011
- return crypto2.createHash("md5").update(str).digest("hex").substring(0, 5).toUpperCase();
41012
- };
41013
- var getTriggerTagName = (triggerName) => {
41014
- return `trigger${hashString(triggerName)}`;
41015
- };
41016
- var getTriggerTagValue = (key) => {
41017
- return key ?? "*";
41018
- };
41019
- var getTriggerSubscriptionTags = (triggerName, key) => {
41020
- return {
41021
- name: getTriggerTagName(triggerName),
41022
- value: getTriggerTagValue(key)
41023
- };
41024
- };
41025
- var isConversationSubscribedToTrigger = (conversationTags, triggerName, triggerKey) => {
41026
- const tagName = getTriggerTagName(triggerName);
41027
- const tagValue = conversationTags[tagName];
41028
- if (!tagValue) {
41029
- return false;
41030
- }
41031
- return tagValue === "*" || tagValue === triggerKey;
41032
- };
41033
-
41034
41047
  // src/types.ts
41035
41048
  init_define_BUILD();
41036
41049
  init_define_PACKAGE_VERSIONS();
@@ -41109,8 +41122,6 @@ var BaseWorkflow = class {
41109
41122
  /** @internal */
41110
41123
  schedule;
41111
41124
  timeout = (0, import_ms.default)("5m");
41112
- // Runtime state
41113
- state;
41114
41125
  constructor(props) {
41115
41126
  this.name = props.name;
41116
41127
  if (props.description !== void 0) {
@@ -41478,10 +41489,15 @@ var EMPTY_STATE = {
41478
41489
  };
41479
41490
  var MAX_SWAP_FILE_SIZE = import_bytes2.default.parse("100MB");
41480
41491
  var BUILT_IN_STATES = {
41481
- user: "userState",
41492
+ /** Generic conversation-specific state (user-defined per conversation) */
41482
41493
  conversation: "state",
41494
+ /** User-specific state (persists across conversations per user) */
41495
+ user: "userState",
41496
+ /** Bot-wide global state (persists across all conversations) */
41483
41497
  bot: "botState",
41498
+ /** Workflow-specific state (persists across workflow executions) */
41484
41499
  workflowState: "workflowState",
41500
+ /** Workflow cached steps executions */
41485
41501
  workflowSteps: "workflowSteps"
41486
41502
  };
41487
41503
  var TrackedState = class _TrackedState {
@@ -41554,6 +41570,7 @@ var TrackedState = class _TrackedState {
41554
41570
  const client = context.get("client")._inner;
41555
41571
  const botId = context.get("botId", { optional: true });
41556
41572
  const user2 = context.get("user", { optional: true });
41573
+ const conversation = context.get("conversation", { optional: true });
41557
41574
  if (botId) {
41558
41575
  _TrackedState.create({
41559
41576
  client,
@@ -41572,6 +41589,23 @@ var TrackedState = class _TrackedState {
41572
41589
  schema: adk.project.config.user?.state || z9.object({})
41573
41590
  });
41574
41591
  }
41592
+ if (conversation) {
41593
+ const definition = adk.project.conversations.find((c) => {
41594
+ const def = c.getDefinition();
41595
+ if (typeof def.channel === "string") {
41596
+ return def.channel === conversation.channel || def.channel === "*";
41597
+ } else {
41598
+ return def.channel.includes(conversation.channel);
41599
+ }
41600
+ });
41601
+ _TrackedState.create({
41602
+ client,
41603
+ name: BUILT_IN_STATES.conversation,
41604
+ type: "conversation",
41605
+ id: conversation.id,
41606
+ schema: definition?.schema || z9.object({})
41607
+ });
41608
+ }
41575
41609
  const states = context.get("states", { optional: true });
41576
41610
  const promises = Promise.allSettled(
41577
41611
  states?.map((state) => state.load()) ?? []
@@ -41618,16 +41652,23 @@ var TrackedState = class _TrackedState {
41618
41652
  } else {
41619
41653
  this.value = value;
41620
41654
  }
41621
- if ((this.value == null || this.value === void 0) && this.state && "parse" in this.state) {
41622
- try {
41623
- this.value = this.state.parse({});
41624
- this._isDirty = true;
41625
- } catch (error) {
41655
+ if (this.value == null || this.value === void 0) {
41656
+ if (this.state && "parse" in this.state) {
41626
41657
  try {
41627
- this.value = this.state.parse(void 0);
41658
+ this.value = this.state.parse({});
41628
41659
  this._isDirty = true;
41629
- } catch {
41660
+ } catch (error) {
41661
+ try {
41662
+ this.value = this.state.parse(void 0);
41663
+ this._isDirty = true;
41664
+ } catch {
41665
+ this.value = {};
41666
+ this._isDirty = true;
41667
+ }
41630
41668
  }
41669
+ } else {
41670
+ this.value = {};
41671
+ this._isDirty = true;
41631
41672
  }
41632
41673
  }
41633
41674
  try {
@@ -42237,24 +42278,145 @@ init_define_BUILD();
42237
42278
  init_define_PACKAGE_VERSIONS();
42238
42279
  import { z as z13 } from "@botpress/sdk";
42239
42280
  import { setTimeout as setTimeout2 } from "node:timers/promises";
42281
+
42282
+ // src/primitives/conversation-instance.ts
42283
+ init_define_BUILD();
42284
+ init_define_PACKAGE_VERSIONS();
42285
+ var BaseConversationInstance = class {
42286
+ id;
42287
+ channel;
42288
+ integration;
42289
+ tags;
42290
+ conversation;
42291
+ // @internal
42292
+ client;
42293
+ // @internal
42294
+ TrackedState;
42295
+ constructor(conversation, client) {
42296
+ this.id = conversation.id;
42297
+ this.channel = conversation.channel;
42298
+ this.integration = conversation.integration;
42299
+ this.tags = conversation.tags;
42300
+ this.conversation = conversation;
42301
+ this.client = client;
42302
+ const states = context.get("states", { optional: true });
42303
+ const existingState = states?.find(
42304
+ (s) => s.type === "conversation" && s.id === conversation.id && s.name === BUILT_IN_STATES.conversation
42305
+ );
42306
+ if (!existingState) {
42307
+ throw new Error(
42308
+ `Conversation state not found for conversation ${conversation.id}. Make sure TrackedState.loadAll() is called before creating conversation instances.`
42309
+ );
42310
+ }
42311
+ this.TrackedState = existingState;
42312
+ }
42313
+ /**
42314
+ * Send a message to this conversation
42315
+ */
42316
+ async send(message) {
42317
+ try {
42318
+ const chat = context.get("chat");
42319
+ await trackPromise(
42320
+ chat.sendMessage({
42321
+ type: message.type,
42322
+ payload: message.payload
42323
+ })
42324
+ );
42325
+ } catch (err) {
42326
+ console.error("Error sending message in conversation:", err);
42327
+ }
42328
+ }
42329
+ /**
42330
+ * Start typing indicator
42331
+ */
42332
+ async startTyping() {
42333
+ const mapping = InterfaceMappings.getIntegrationAction(
42334
+ "typingIndicator",
42335
+ "startTypingIndicator",
42336
+ this.integration
42337
+ );
42338
+ if (mapping) {
42339
+ const message = context.get("message", { optional: true });
42340
+ await this.client.callAction({
42341
+ type: mapping,
42342
+ input: {
42343
+ conversationId: this.id,
42344
+ messageId: message?.id
42345
+ }
42346
+ }).catch(() => {
42347
+ });
42348
+ }
42349
+ }
42350
+ /**
42351
+ * Stop typing indicator
42352
+ */
42353
+ async stopTyping() {
42354
+ const mapping = InterfaceMappings.getIntegrationAction(
42355
+ "typingIndicator",
42356
+ "stopTypingIndicator",
42357
+ this.integration
42358
+ );
42359
+ if (mapping) {
42360
+ const message = context.get("message", { optional: true });
42361
+ await this.client.callAction({
42362
+ type: mapping,
42363
+ input: {
42364
+ conversationId: this.id,
42365
+ messageId: message?.id
42366
+ }
42367
+ }).catch(() => {
42368
+ });
42369
+ }
42370
+ }
42371
+ /**
42372
+ * Subscribe to a trigger
42373
+ */
42374
+ async subscribeToTrigger(triggerName, key) {
42375
+ const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
42376
+ if (isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
42377
+ return;
42378
+ }
42379
+ const { name, value } = getTriggerSubscriptionTags2(triggerName, key);
42380
+ await this.client.updateConversation({
42381
+ id: this.id,
42382
+ tags: {
42383
+ [name]: value
42384
+ }
42385
+ });
42386
+ }
42387
+ /**
42388
+ * Unsubscribe from a trigger
42389
+ */
42390
+ async unsubscribeFromTrigger(triggerName, key) {
42391
+ const { getTriggerSubscriptionTags: getTriggerSubscriptionTags2, isConversationSubscribedToTrigger: isConversationSubscribedToTrigger2 } = await Promise.resolve().then(() => (init_trigger_tags(), trigger_tags_exports));
42392
+ if (!isConversationSubscribedToTrigger2(this.tags, triggerName, key)) {
42393
+ return;
42394
+ }
42395
+ const { name } = getTriggerSubscriptionTags2(triggerName, key);
42396
+ await this.client.updateConversation({
42397
+ id: this.id,
42398
+ tags: {
42399
+ [name]: ""
42400
+ }
42401
+ });
42402
+ }
42403
+ };
42404
+
42405
+ // src/primitives/conversation.ts
42240
42406
  var ConversationHandler = Symbol.for("conversation.handler");
42241
42407
  var Typings3;
42242
42408
  ((Typings8) => {
42243
42409
  Typings8.Primitive = "conversation";
42244
42410
  })(Typings3 || (Typings3 = {}));
42245
42411
  var BaseConversation = class {
42246
- integration;
42247
42412
  channel;
42248
42413
  /** @internal */
42249
42414
  schema;
42250
42415
  #handler;
42251
- #state;
42252
42416
  #startFromTrigger;
42253
- #interruptionSignal;
42254
42417
  constructor(props) {
42255
42418
  this.channel = props.channel;
42256
42419
  this.schema = props.state ?? z13.object({}).passthrough();
42257
- this.integration = props.channel.split(".")[0];
42258
42420
  this.#handler = props.handler;
42259
42421
  if (props.startFromTrigger) {
42260
42422
  this.#startFromTrigger = props.startFromTrigger;
@@ -42266,31 +42428,34 @@ var BaseConversation = class {
42266
42428
  }
42267
42429
  /** @internal */
42268
42430
  getDefinition() {
42269
- return {
42270
- type: "conversation",
42271
- channel: this.channel
42272
- };
42273
- }
42274
- set state(state) {
42275
- this.#state = state;
42276
- }
42277
- get state() {
42278
- return this.#state;
42279
- }
42280
- get id() {
42281
- return context.get("conversation").id;
42282
- }
42283
- get tags() {
42284
- return context.get("conversation").tags;
42431
+ if (this.channel === "*") {
42432
+ return {
42433
+ type: "conversation",
42434
+ channel: "*"
42435
+ };
42436
+ } else if (Array.isArray(this.channel)) {
42437
+ return {
42438
+ type: "conversation",
42439
+ channel: this.channel
42440
+ };
42441
+ } else {
42442
+ return {
42443
+ type: "conversation",
42444
+ channel: this.channel
42445
+ };
42446
+ }
42285
42447
  }
42286
- // TODO: separate the handler from the conversation definition
42287
- // TODO: each execution should have its own instance to avoid state conflicts etc
42448
+ /** @internal */
42288
42449
  async [ConversationHandler]() {
42289
42450
  const message = context.get("message", { optional: true });
42290
42451
  const event = context.get("event", { optional: true });
42291
42452
  const chat = context.get("chat");
42292
42453
  const client = context.get("client");
42293
- const conversationId = this.id;
42454
+ const botpressConversation = context.get("conversation");
42455
+ const conversationInstance = new BaseConversationInstance(
42456
+ botpressConversation,
42457
+ client
42458
+ );
42294
42459
  let type;
42295
42460
  let requestObject = void 0;
42296
42461
  if (message) {
@@ -42315,11 +42480,10 @@ var BaseConversation = class {
42315
42480
  type = "event";
42316
42481
  }
42317
42482
  const controller = new AbortController();
42318
- this.#interruptionSignal = controller.signal;
42319
42483
  void span(
42320
42484
  "interruption.check",
42321
42485
  {
42322
- conversationId
42486
+ conversationId: conversationInstance.id
42323
42487
  },
42324
42488
  async (s) => {
42325
42489
  async function checkNewUserMessage() {
@@ -42327,7 +42491,7 @@ var BaseConversation = class {
42327
42491
  return;
42328
42492
  }
42329
42493
  const { events } = await client.listEvents({
42330
- conversationId,
42494
+ conversationId: conversationInstance.id,
42331
42495
  status: "pending"
42332
42496
  });
42333
42497
  const newEvents = events.filter(
@@ -42383,100 +42547,36 @@ var BaseConversation = class {
42383
42547
  const execute = Autonomous.createExecute({
42384
42548
  mode: "chat",
42385
42549
  defaultModel: adk.project.config.defaultModels.autonomous,
42386
- ...this.#interruptionSignal && {
42387
- interruption: this.#interruptionSignal
42550
+ interruption: controller.signal
42551
+ });
42552
+ if (!conversationInstance.TrackedState.value) {
42553
+ conversationInstance.TrackedState.value = {};
42554
+ }
42555
+ const stateProxy = new Proxy(conversationInstance.TrackedState.value, {
42556
+ set(target, prop, value) {
42557
+ const result = Reflect.set(target, prop, value);
42558
+ conversationInstance.TrackedState.markDirty();
42559
+ return result;
42388
42560
  }
42389
42561
  });
42390
- await this.#handler.call(this, {
42562
+ await this.#handler({
42391
42563
  type,
42392
42564
  message,
42393
42565
  event,
42394
42566
  request: requestObject,
42567
+ conversation: conversationInstance,
42568
+ state: stateProxy,
42569
+ client,
42395
42570
  execute
42396
42571
  });
42397
42572
  controller.abort();
42398
42573
  }
42399
- async subscribeToTrigger(triggerName, key) {
42400
- if (isConversationSubscribedToTrigger(this.tags, triggerName, key)) {
42401
- return;
42402
- }
42403
- const conversation = context.get("conversation");
42404
- const client = context.get("client");
42405
- const { name, value } = getTriggerSubscriptionTags(triggerName, key);
42406
- await client.updateConversation({
42407
- id: conversation.id,
42408
- tags: {
42409
- [name]: value
42410
- }
42411
- });
42412
- }
42413
- async unsubscribeFromTrigger(triggerName, key) {
42414
- if (!isConversationSubscribedToTrigger(this.tags, triggerName, key)) {
42415
- return;
42416
- }
42417
- const conversation = context.get("conversation");
42418
- const client = context.get("client");
42419
- const { name } = getTriggerSubscriptionTags(triggerName, key);
42420
- await client.updateConversation({
42421
- id: conversation.id,
42422
- tags: {
42423
- [name]: ""
42424
- }
42425
- });
42426
- }
42427
- async startTyping() {
42428
- const conversation = context.get("conversation", { optional: true });
42429
- const message = context.get("message", { optional: true });
42430
- const mapping = InterfaceMappings.getIntegrationAction(
42431
- "typingIndicator",
42432
- "startTypingIndicator",
42433
- conversation?.integration
42434
- );
42435
- if (conversation && mapping) {
42436
- await context.get("client").callAction({
42437
- type: mapping,
42438
- input: {
42439
- conversationId: conversation.id,
42440
- messageId: message?.id
42441
- }
42442
- }).catch(() => {
42443
- });
42444
- }
42445
- }
42446
- async stopTyping() {
42447
- const conversation = context.get("conversation", { optional: true });
42448
- const message = context.get("message", { optional: true });
42449
- const mapping = InterfaceMappings.getIntegrationAction(
42450
- "typingIndicator",
42451
- "stopTypingIndicator",
42452
- conversation?.integration
42453
- );
42454
- if (conversation && mapping) {
42455
- await context.get("client").callAction({
42456
- type: mapping,
42457
- input: {
42458
- conversationId: conversation.id,
42459
- messageId: message?.id
42460
- }
42461
- }).catch(() => {
42462
- });
42463
- }
42464
- }
42465
- async send(message) {
42466
- try {
42467
- const chat = context.get("chat");
42468
- await trackPromise(
42469
- chat.sendMessage({
42470
- type: message.type,
42471
- payload: message.payload
42472
- })
42473
- );
42474
- } catch (err) {
42475
- console.error("Error getting context in conversation.send:", err);
42476
- }
42477
- }
42478
42574
  };
42479
42575
 
42576
+ // src/runtime/handlers/conversation-matching.ts
42577
+ init_define_BUILD();
42578
+ init_define_PACKAGE_VERSIONS();
42579
+
42480
42580
  // src/runtime/handlers/trigger.ts
42481
42581
  init_define_BUILD();
42482
42582
  init_define_PACKAGE_VERSIONS();
@@ -42966,12 +43066,6 @@ var BaseWorkflowInstance = class _BaseWorkflowInstance {
42966
43066
  workflow;
42967
43067
  // @internal
42968
43068
  TrackedState;
42969
- set state(state) {
42970
- this.TrackedState.value = state;
42971
- }
42972
- get state() {
42973
- return this.TrackedState.value;
42974
- }
42975
43069
  constructor(workflow, client) {
42976
43070
  const definition = adk.project.workflows.find(
42977
43071
  (w) => w.name === workflow.name
@@ -42981,7 +43075,7 @@ var BaseWorkflowInstance = class _BaseWorkflowInstance {
42981
43075
  client: client._inner,
42982
43076
  id: workflow.id,
42983
43077
  schema: definition?.stateSchema,
42984
- name: "workflowState"
43078
+ name: BUILT_IN_STATES.workflowState
42985
43079
  });
42986
43080
  this.id = workflow.id;
42987
43081
  this.name = workflow.name;
@@ -43112,14 +43206,25 @@ var BaseWorkflowInstance = class _BaseWorkflowInstance {
43112
43206
  "Workflow execution state is not loaded"
43113
43207
  );
43114
43208
  workflowExecutionState.value.executionCount++;
43209
+ if (!this.TrackedState.value) {
43210
+ this.TrackedState.value = {};
43211
+ }
43212
+ const trackedState = this.TrackedState;
43213
+ const stateProxy = new Proxy(this.TrackedState.value, {
43214
+ set(target, prop, value) {
43215
+ const result2 = Reflect.set(target, prop, value);
43216
+ trackedState.markDirty();
43217
+ return result2;
43218
+ }
43219
+ });
43115
43220
  const result = await context.run(
43116
43221
  {
43117
43222
  ...ctx,
43118
43223
  workflowControlContext
43119
43224
  },
43120
- async () => handler.call(this, {
43225
+ async () => handler({
43121
43226
  input: this.input,
43122
- state: this.state,
43227
+ state: stateProxy,
43123
43228
  step,
43124
43229
  client: this.client,
43125
43230
  execute: this.execute.bind(this)
@@ -43185,7 +43290,7 @@ function createWorkflowExecutionState(client, workflowId) {
43185
43290
  client,
43186
43291
  id: workflowId,
43187
43292
  schema: workflowExecutionContextSchema,
43188
- name: "workflowExecutionContext"
43293
+ name: BUILT_IN_STATES.workflowSteps
43189
43294
  });
43190
43295
  }
43191
43296
 
@@ -43197,7 +43302,12 @@ var Definitions;
43197
43302
  ((Definitions2) => {
43198
43303
  const conversationDefinitionSchema = z18.object({
43199
43304
  type: z18.literal("conversation"),
43200
- channel: z18.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^[a-zA-Z0-9._-]+$/, "Channel must be a valid identifier")
43305
+ channel: z18.union([
43306
+ z18.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^(\*|[a-zA-Z0-9._-]+)$/, "Channel must be a valid identifier or glob '*'"),
43307
+ z18.array(
43308
+ z18.string().min(1, "Channel must be a non-empty string").max(255, "Channel must be less than 255 characters").regex(/^[a-zA-Z0-9._-]+$/, "Channel must be a valid identifier")
43309
+ )
43310
+ ])
43201
43311
  });
43202
43312
  const workflowDefinitionSchema = z18.object({
43203
43313
  type: z18.literal("workflow"),
@@ -45821,6 +45931,7 @@ var Primitives;
45821
45931
  ((Primitives2) => {
45822
45932
  Primitives2.Definitions = Definitions;
45823
45933
  Primitives2.BaseConversation = BaseConversation;
45934
+ Primitives2.BaseConversationInstance = BaseConversationInstance;
45824
45935
  Primitives2.Conversation = Typings3;
45825
45936
  Primitives2.BaseKnowledge = BaseKnowledge;
45826
45937
  Primitives2.Knowledge = Typings4;
@@ -46537,6 +46648,8 @@ export {
46537
46648
  Action,
46538
46649
  BOT_ID_HEADER,
46539
46650
  BOT_USER_ID_HEADER,
46651
+ BUILT_IN_STATES,
46652
+ BaseConversationInstance,
46540
46653
  BaseWorkflowInstance,
46541
46654
  BuiltInWorkflows,
46542
46655
  CONFIGURATION_PAYLOAD_HEADER,