@botpress/runtime 1.13.10 → 1.13.11

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/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.13.10", adk: "1.13.10", sdk: "5.0.2", llmz: "0.0.35", zai: "2.5.6", cognitive: "0.3.3" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.13.11", adk: "1.13.11", sdk: "5.0.2", llmz: "0.0.37", zai: "2.5.6", cognitive: "0.3.3" };
52
52
  }
53
53
  });
54
54
 
@@ -79,7 +79,7 @@ var init_singletons = __esm({
79
79
 
80
80
  // src/runtime/context/context.ts
81
81
  import { AsyncLocalStorage } from "async_hooks";
82
- var storage, context;
82
+ var storage, defaultContext, context;
83
83
  var init_context = __esm({
84
84
  "src/runtime/context/context.ts"() {
85
85
  "use strict";
@@ -87,6 +87,7 @@ var init_context = __esm({
87
87
  init_define_PACKAGE_VERSIONS();
88
88
  init_singletons();
89
89
  storage = getSingleton("__ADK_GLOBAL_CTX_STORAGE", () => new AsyncLocalStorage());
90
+ defaultContext = getSingleton("__ADK_GLOBAL_DEFAULT_CTX", () => ({ value: null }));
90
91
  context = {
91
92
  enterWith: (data) => {
92
93
  storage.enterWith(data);
@@ -105,7 +106,10 @@ var init_context = __esm({
105
106
  return store;
106
107
  },
107
108
  get: (key, opts) => {
108
- const store = storage.getStore();
109
+ let store = storage.getStore();
110
+ if (!store && defaultContext.value) {
111
+ store = defaultContext.value;
112
+ }
109
113
  if (store) {
110
114
  store.states ??= [];
111
115
  store.tags ??= [];
@@ -121,6 +125,28 @@ var init_context = __esm({
121
125
  const store = storage.getStore();
122
126
  if (!store) throw new Error("Cannot set context outside of `run`");
123
127
  store[key] = value;
128
+ },
129
+ /**
130
+ * Set a default context that will be used as a fallback when no AsyncLocalStorage context is active.
131
+ * This is useful for testing and script execution where code runs outside of request handlers.
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * context.setDefaultContext({
136
+ * botId: 'my-bot',
137
+ * integrations: agentRegistry.integrations,
138
+ * interfaces: agentRegistry.interfaces,
139
+ * })
140
+ * ```
141
+ */
142
+ setDefaultContext: (data) => {
143
+ defaultContext.value = data;
144
+ },
145
+ /**
146
+ * Clear the default context.
147
+ */
148
+ clearDefaultContext: () => {
149
+ defaultContext.value = null;
124
150
  }
125
151
  };
126
152
  }
@@ -34608,7 +34634,7 @@ var init_actions = __esm({
34608
34634
  }
34609
34635
  integrations ??= context.get("integrations", { optional: true });
34610
34636
  client2 ??= context.get("client", { optional: true });
34611
- const integration = integrations.find((i) => i.alias === integrationName);
34637
+ const integration = integrations?.find((i) => i.alias === integrationName);
34612
34638
  const actionDef = integration?.definition.actions?.[actionName];
34613
34639
  const handler = async (params) => {
34614
34640
  integrations ??= context.get("integrations", { optional: true });
@@ -37455,6 +37481,9 @@ var init_tracked_state = __esm({
37455
37481
  });
37456
37482
 
37457
37483
  // src/runtime/tracked-tags.ts
37484
+ function isSystemTag(key) {
37485
+ return key.includes(":");
37486
+ }
37458
37487
  var TrackedTags;
37459
37488
  var init_tracked_tags = __esm({
37460
37489
  "src/runtime/tracked-tags.ts"() {
@@ -37634,8 +37663,8 @@ var init_tracked_tags = __esm({
37634
37663
  }
37635
37664
  }
37636
37665
  isDirty() {
37637
- const currentKeys = Object.keys(this._tags).filter((k) => !k.includes(":")).sort();
37638
- const initialKeys = Object.keys(this._initialTags).filter((k) => !k.includes(":")).sort();
37666
+ const currentKeys = Object.keys(this._tags).filter((k) => !isSystemTag(k)).sort();
37667
+ const initialKeys = Object.keys(this._initialTags).filter((k) => !isSystemTag(k)).sort();
37639
37668
  if (currentKeys.length !== initialKeys.length) {
37640
37669
  return true;
37641
37670
  }
@@ -37649,10 +37678,16 @@ var init_tracked_tags = __esm({
37649
37678
  get tags() {
37650
37679
  return new Proxy(this._tags, {
37651
37680
  set: (target, prop, value) => {
37681
+ if (isSystemTag(prop)) {
37682
+ return true;
37683
+ }
37652
37684
  target[prop] = value;
37653
37685
  return true;
37654
37686
  },
37655
37687
  deleteProperty: (target, prop) => {
37688
+ if (isSystemTag(prop)) {
37689
+ return true;
37690
+ }
37656
37691
  target[prop] = void 0;
37657
37692
  return true;
37658
37693
  }
@@ -37684,7 +37719,7 @@ var init_tracked_tags = __esm({
37684
37719
  async persistTags(tags) {
37685
37720
  const tagsForApi = {};
37686
37721
  for (const [key, value] of Object.entries(tags)) {
37687
- if (value !== void 0 && !key.includes(":")) {
37722
+ if (value !== void 0 && !isSystemTag(key)) {
37688
37723
  tagsForApi[key] = value;
37689
37724
  }
37690
37725
  }