@anuma/sdk 6.33.0 → 6.33.1

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.
@@ -9151,7 +9151,13 @@ async function runToolLoop(options) {
9151
9151
  );
9152
9152
  const extra = results.flatMap((r) => Array.isArray(r) ? r : []);
9153
9153
  if (extra.length > 0) {
9154
- messages = [...messages, ...await redactBatch(extra)];
9154
+ let userIndex = messages.length - 1;
9155
+ while (userIndex > 0 && messages[userIndex].role !== "user") userIndex--;
9156
+ messages = [
9157
+ ...messages.slice(0, userIndex),
9158
+ ...await redactBatch(extra),
9159
+ ...messages.slice(userIndex)
9160
+ ];
9155
9161
  }
9156
9162
  }
9157
9163
  } catch (err) {
@@ -1401,7 +1401,7 @@ type PromptPreProcessorContext = {
1401
1401
  signal?: AbortSignal;
1402
1402
  };
1403
1403
  /**
1404
- * Returns messages to append to the conversation, or nothing to leave
1404
+ * Returns context messages to insert before the latest user message, or nothing to leave
1405
1405
  * the conversation unchanged. Thrown errors are caught by the tool loop
1406
1406
  * so a failing pre-processor does not abort the LLM request.
1407
1407
  */
@@ -1401,7 +1401,7 @@ type PromptPreProcessorContext = {
1401
1401
  signal?: AbortSignal;
1402
1402
  };
1403
1403
  /**
1404
- * Returns messages to append to the conversation, or nothing to leave
1404
+ * Returns context messages to insert before the latest user message, or nothing to leave
1405
1405
  * the conversation unchanged. Thrown errors are caught by the tool loop
1406
1406
  * so a failing pre-processor does not abort the LLM request.
1407
1407
  */
@@ -7500,7 +7500,13 @@ async function runToolLoop(options) {
7500
7500
  );
7501
7501
  const extra = results.flatMap((r) => Array.isArray(r) ? r : []);
7502
7502
  if (extra.length > 0) {
7503
- messages = [...messages, ...await redactBatch(extra)];
7503
+ let userIndex = messages.length - 1;
7504
+ while (userIndex > 0 && messages[userIndex].role !== "user") userIndex--;
7505
+ messages = [
7506
+ ...messages.slice(0, userIndex),
7507
+ ...await redactBatch(extra),
7508
+ ...messages.slice(userIndex)
7509
+ ];
7504
7510
  }
7505
7511
  }
7506
7512
  } catch (err) {
@@ -9589,7 +9589,13 @@ async function runToolLoop(options) {
9589
9589
  );
9590
9590
  const extra = results.flatMap((r) => Array.isArray(r) ? r : []);
9591
9591
  if (extra.length > 0) {
9592
- messages = [...messages, ...await redactBatch(extra)];
9592
+ let userIndex = messages.length - 1;
9593
+ while (userIndex > 0 && messages[userIndex].role !== "user") userIndex--;
9594
+ messages = [
9595
+ ...messages.slice(0, userIndex),
9596
+ ...await redactBatch(extra),
9597
+ ...messages.slice(userIndex)
9598
+ ];
9593
9599
  }
9594
9600
  }
9595
9601
  } catch (err) {
@@ -2062,7 +2062,7 @@ type PromptPreProcessorContext = {
2062
2062
  signal?: AbortSignal;
2063
2063
  };
2064
2064
  /**
2065
- * Returns messages to append to the conversation, or nothing to leave
2065
+ * Returns context messages to insert before the latest user message, or nothing to leave
2066
2066
  * the conversation unchanged. Thrown errors are caught by the tool loop
2067
2067
  * so a failing pre-processor does not abort the LLM request.
2068
2068
  */
@@ -2062,7 +2062,7 @@ type PromptPreProcessorContext = {
2062
2062
  signal?: AbortSignal;
2063
2063
  };
2064
2064
  /**
2065
- * Returns messages to append to the conversation, or nothing to leave
2065
+ * Returns context messages to insert before the latest user message, or nothing to leave
2066
2066
  * the conversation unchanged. Thrown errors are caught by the tool loop
2067
2067
  * so a failing pre-processor does not abort the LLM request.
2068
2068
  */
@@ -7677,7 +7677,13 @@ async function runToolLoop(options) {
7677
7677
  );
7678
7678
  const extra = results.flatMap((r) => Array.isArray(r) ? r : []);
7679
7679
  if (extra.length > 0) {
7680
- messages = [...messages, ...await redactBatch(extra)];
7680
+ let userIndex = messages.length - 1;
7681
+ while (userIndex > 0 && messages[userIndex].role !== "user") userIndex--;
7682
+ messages = [
7683
+ ...messages.slice(0, userIndex),
7684
+ ...await redactBatch(extra),
7685
+ ...messages.slice(userIndex)
7686
+ ];
7681
7687
  }
7682
7688
  }
7683
7689
  } catch (err) {
@@ -38007,7 +38007,13 @@ async function runToolLoop(options) {
38007
38007
  );
38008
38008
  const extra = results.flatMap((r) => Array.isArray(r) ? r : []);
38009
38009
  if (extra.length > 0) {
38010
- messages = [...messages, ...await redactBatch(extra)];
38010
+ let userIndex = messages.length - 1;
38011
+ while (userIndex > 0 && messages[userIndex].role !== "user") userIndex--;
38012
+ messages = [
38013
+ ...messages.slice(0, userIndex),
38014
+ ...await redactBatch(extra),
38015
+ ...messages.slice(userIndex)
38016
+ ];
38011
38017
  }
38012
38018
  }
38013
38019
  } catch (err) {
@@ -1697,7 +1697,7 @@ type PromptPreProcessorContext = {
1697
1697
  signal?: AbortSignal;
1698
1698
  };
1699
1699
  /**
1700
- * Returns messages to append to the conversation, or nothing to leave
1700
+ * Returns context messages to insert before the latest user message, or nothing to leave
1701
1701
  * the conversation unchanged. Thrown errors are caught by the tool loop
1702
1702
  * so a failing pre-processor does not abort the LLM request.
1703
1703
  */
@@ -2458,7 +2458,7 @@ type RunToolLoopOptions = {
2458
2458
  * the first LLM request. Each pre-processor receives the prompt text
2459
2459
  * and a shared embedding (computed once per request) and may return
2460
2460
  * additional messages to enrich the conversation. Messages returned by
2461
- * each pre-processor are appended in array order to `messages` for the
2461
+ * each pre-processor are inserted in array order before the latest user message for the
2462
2462
  * initial LLM call and all subsequent tool-loop rounds.
2463
2463
  *
2464
2464
  * Pre-processors run in parallel; a failure in one is logged and does
@@ -1697,7 +1697,7 @@ type PromptPreProcessorContext = {
1697
1697
  signal?: AbortSignal;
1698
1698
  };
1699
1699
  /**
1700
- * Returns messages to append to the conversation, or nothing to leave
1700
+ * Returns context messages to insert before the latest user message, or nothing to leave
1701
1701
  * the conversation unchanged. Thrown errors are caught by the tool loop
1702
1702
  * so a failing pre-processor does not abort the LLM request.
1703
1703
  */
@@ -2458,7 +2458,7 @@ type RunToolLoopOptions = {
2458
2458
  * the first LLM request. Each pre-processor receives the prompt text
2459
2459
  * and a shared embedding (computed once per request) and may return
2460
2460
  * additional messages to enrich the conversation. Messages returned by
2461
- * each pre-processor are appended in array order to `messages` for the
2461
+ * each pre-processor are inserted in array order before the latest user message for the
2462
2462
  * initial LLM call and all subsequent tool-loop rounds.
2463
2463
  *
2464
2464
  * Pre-processors run in parallel; a failure in one is logged and does
@@ -36207,7 +36207,13 @@ async function runToolLoop(options) {
36207
36207
  );
36208
36208
  const extra = results.flatMap((r) => Array.isArray(r) ? r : []);
36209
36209
  if (extra.length > 0) {
36210
- messages = [...messages, ...await redactBatch(extra)];
36210
+ let userIndex = messages.length - 1;
36211
+ while (userIndex > 0 && messages[userIndex].role !== "user") userIndex--;
36212
+ messages = [
36213
+ ...messages.slice(0, userIndex),
36214
+ ...await redactBatch(extra),
36215
+ ...messages.slice(userIndex)
36216
+ ];
36211
36217
  }
36212
36218
  }
36213
36219
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "6.33.0",
3
+ "version": "6.33.1",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",