@iqai/adk 0.5.4 → 0.5.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iqai/adk
2
2
 
3
+ ## 0.5.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 05bb1b8: Fix state variable injection: serialize objects to JSON and parse nested properties
8
+
3
9
  ## 0.5.4
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -8731,17 +8731,27 @@ async function injectSessionState(template, readonlyContext) {
8731
8731
  throw error;
8732
8732
  }
8733
8733
  } else {
8734
- if (!isValidStateName(varName)) {
8734
+ const isNestedAccess = varName.includes(".") || varName.includes("[");
8735
+ const rootProperty = isNestedAccess ? varName.split(/[.[]/)[0] : varName;
8736
+ if (!isValidStateName(rootProperty)) {
8735
8737
  return match[0];
8736
8738
  }
8737
8739
  const sessionState = invocationContext.session.state;
8738
- if (varName in sessionState) {
8739
- return String(sessionState[varName]);
8740
- }
8741
- if (optional) {
8742
- return "";
8740
+ try {
8741
+ const value = isNestedAccess ? getNestedValue(sessionState, varName) : sessionState[varName];
8742
+ if (value === void 0) {
8743
+ if (optional) {
8744
+ return "";
8745
+ }
8746
+ throw new Error(`Context variable not found: \`${varName}\`.`);
8747
+ }
8748
+ return formatValue(value);
8749
+ } catch (error) {
8750
+ if (optional) {
8751
+ return "";
8752
+ }
8753
+ throw error;
8743
8754
  }
8744
- throw new Error(`Context variable not found: \`${varName}\`.`);
8745
8755
  }
8746
8756
  }
8747
8757
  return await asyncReplace(/{[^{}]*}/g, replaceMatch, template);
@@ -8764,6 +8774,66 @@ function isValidIdentifier(name) {
8764
8774
  const identifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
8765
8775
  return identifierRegex.test(name);
8766
8776
  }
8777
+ function getNestedValue(obj, path3) {
8778
+ const parts = [];
8779
+ let current = "";
8780
+ let inBrackets = false;
8781
+ let quote = "";
8782
+ for (let i = 0; i < path3.length; i++) {
8783
+ const char = path3[i];
8784
+ if (char === "[" && !quote) {
8785
+ if (current) {
8786
+ parts.push(current);
8787
+ current = "";
8788
+ }
8789
+ inBrackets = true;
8790
+ } else if (char === "]" && inBrackets && !quote) {
8791
+ if (current) {
8792
+ parts.push(current);
8793
+ current = "";
8794
+ }
8795
+ inBrackets = false;
8796
+ } else if ((char === '"' || char === "'") && inBrackets) {
8797
+ if (quote === char) {
8798
+ quote = "";
8799
+ } else if (!quote) {
8800
+ quote = char;
8801
+ } else {
8802
+ current += char;
8803
+ }
8804
+ } else if (char === "." && !inBrackets && !quote) {
8805
+ if (current) {
8806
+ parts.push(current);
8807
+ current = "";
8808
+ }
8809
+ } else {
8810
+ current += char;
8811
+ }
8812
+ }
8813
+ if (current) {
8814
+ parts.push(current);
8815
+ }
8816
+ let result = obj;
8817
+ for (const part of parts) {
8818
+ if (result === null || result === void 0) {
8819
+ return void 0;
8820
+ }
8821
+ result = result[part];
8822
+ }
8823
+ return result;
8824
+ }
8825
+ function formatValue(value) {
8826
+ if (value === null) {
8827
+ return "null";
8828
+ }
8829
+ if (value === void 0) {
8830
+ return "undefined";
8831
+ }
8832
+ if (typeof value === "object") {
8833
+ return JSON.stringify(value, null, 2);
8834
+ }
8835
+ return String(value);
8836
+ }
8767
8837
 
8768
8838
  // src/flows/llm-flows/instructions.ts
8769
8839
  var InstructionsLlmRequestProcessor = class extends BaseLlmRequestProcessor {
package/dist/index.mjs CHANGED
@@ -8731,17 +8731,27 @@ async function injectSessionState(template, readonlyContext) {
8731
8731
  throw error;
8732
8732
  }
8733
8733
  } else {
8734
- if (!isValidStateName(varName)) {
8734
+ const isNestedAccess = varName.includes(".") || varName.includes("[");
8735
+ const rootProperty = isNestedAccess ? varName.split(/[.[]/)[0] : varName;
8736
+ if (!isValidStateName(rootProperty)) {
8735
8737
  return match[0];
8736
8738
  }
8737
8739
  const sessionState = invocationContext.session.state;
8738
- if (varName in sessionState) {
8739
- return String(sessionState[varName]);
8740
- }
8741
- if (optional) {
8742
- return "";
8740
+ try {
8741
+ const value = isNestedAccess ? getNestedValue(sessionState, varName) : sessionState[varName];
8742
+ if (value === void 0) {
8743
+ if (optional) {
8744
+ return "";
8745
+ }
8746
+ throw new Error(`Context variable not found: \`${varName}\`.`);
8747
+ }
8748
+ return formatValue(value);
8749
+ } catch (error) {
8750
+ if (optional) {
8751
+ return "";
8752
+ }
8753
+ throw error;
8743
8754
  }
8744
- throw new Error(`Context variable not found: \`${varName}\`.`);
8745
8755
  }
8746
8756
  }
8747
8757
  return await asyncReplace(/{[^{}]*}/g, replaceMatch, template);
@@ -8764,6 +8774,66 @@ function isValidIdentifier(name) {
8764
8774
  const identifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
8765
8775
  return identifierRegex.test(name);
8766
8776
  }
8777
+ function getNestedValue(obj, path3) {
8778
+ const parts = [];
8779
+ let current = "";
8780
+ let inBrackets = false;
8781
+ let quote = "";
8782
+ for (let i = 0; i < path3.length; i++) {
8783
+ const char = path3[i];
8784
+ if (char === "[" && !quote) {
8785
+ if (current) {
8786
+ parts.push(current);
8787
+ current = "";
8788
+ }
8789
+ inBrackets = true;
8790
+ } else if (char === "]" && inBrackets && !quote) {
8791
+ if (current) {
8792
+ parts.push(current);
8793
+ current = "";
8794
+ }
8795
+ inBrackets = false;
8796
+ } else if ((char === '"' || char === "'") && inBrackets) {
8797
+ if (quote === char) {
8798
+ quote = "";
8799
+ } else if (!quote) {
8800
+ quote = char;
8801
+ } else {
8802
+ current += char;
8803
+ }
8804
+ } else if (char === "." && !inBrackets && !quote) {
8805
+ if (current) {
8806
+ parts.push(current);
8807
+ current = "";
8808
+ }
8809
+ } else {
8810
+ current += char;
8811
+ }
8812
+ }
8813
+ if (current) {
8814
+ parts.push(current);
8815
+ }
8816
+ let result = obj;
8817
+ for (const part of parts) {
8818
+ if (result === null || result === void 0) {
8819
+ return void 0;
8820
+ }
8821
+ result = result[part];
8822
+ }
8823
+ return result;
8824
+ }
8825
+ function formatValue(value) {
8826
+ if (value === null) {
8827
+ return "null";
8828
+ }
8829
+ if (value === void 0) {
8830
+ return "undefined";
8831
+ }
8832
+ if (typeof value === "object") {
8833
+ return JSON.stringify(value, null, 2);
8834
+ }
8835
+ return String(value);
8836
+ }
8767
8837
 
8768
8838
  // src/flows/llm-flows/instructions.ts
8769
8839
  var InstructionsLlmRequestProcessor = class extends BaseLlmRequestProcessor {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iqai/adk",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Agent Development Kit for TypeScript with multi-provider LLM support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",