@cloudbase/agent-agents 0.0.2 → 0.0.6

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/index.mjs CHANGED
@@ -1791,13 +1791,14 @@ init_events();
1791
1791
  import { randomUUID as randomUUID3 } from "crypto";
1792
1792
  import { z as z2 } from "zod/v4";
1793
1793
  var AgentExecutor = class {
1794
- constructor(config, modelProvider, toolExecutionHandler, messageBuilder, getBusinessState, addMessages) {
1794
+ constructor(config, modelProvider, toolExecutionHandler, messageBuilder, getBusinessState, addMessages, syncState) {
1795
1795
  this.config = config;
1796
1796
  this.modelProvider = modelProvider;
1797
1797
  this.toolExecutionHandler = toolExecutionHandler;
1798
1798
  this.messageBuilder = messageBuilder;
1799
1799
  this.getBusinessState = getBusinessState;
1800
1800
  this.addMessages = addMessages;
1801
+ this.syncState = syncState;
1801
1802
  }
1802
1803
  /**
1803
1804
  * Execute the agent core loop
@@ -2124,6 +2125,10 @@ var AgentExecutor = class {
2124
2125
  [result.messageToSave],
2125
2126
  this.getBusinessState()
2126
2127
  );
2128
+ if (this.syncState && result.messageToSave.metadata?.state) {
2129
+ const updatedState = result.messageToSave.metadata.state;
2130
+ this.syncState(updatedState);
2131
+ }
2127
2132
  }
2128
2133
  if (!result.success) {
2129
2134
  allToolsHandled = false;
@@ -2137,10 +2142,17 @@ var AgentExecutor = class {
2137
2142
  async checkControlFlow(customHandler, context, eventEmitter, startTime, allMessages, totalTokenUsage) {
2138
2143
  if (!customHandler) return null;
2139
2144
  try {
2145
+ const latestUserMessage = allMessages.filter((m) => m.role === "user").pop()?.content || "";
2146
+ const state = this.getBusinessState();
2147
+ const userMessage = state?.userResponse || latestUserMessage;
2140
2148
  const controlDecision = await customHandler.handleNextStep(
2141
2149
  context,
2142
- this.getBusinessState()
2150
+ state,
2151
+ userMessage
2143
2152
  );
2153
+ if (this.syncState) {
2154
+ this.syncState(state);
2155
+ }
2144
2156
  switch (controlDecision.action) {
2145
2157
  case "continue":
2146
2158
  return null;
@@ -4016,7 +4028,15 @@ var Agent = class {
4016
4028
  this.toolExecutionHandler,
4017
4029
  this.messageBuilder,
4018
4030
  () => this.state.businessState,
4019
- (conversationId, messages, state) => this.addMessages(conversationId, messages, state)
4031
+ (conversationId, messages, state) => this.addMessages(conversationId, messages, state),
4032
+ // State sync callback: merge updated state into businessState
4033
+ (updatedState) => {
4034
+ if (this.state.businessState && typeof this.state.businessState === "object" && typeof updatedState === "object") {
4035
+ Object.assign(this.state.businessState, updatedState);
4036
+ } else {
4037
+ this.state.businessState = updatedState;
4038
+ }
4039
+ }
4020
4040
  );
4021
4041
  }
4022
4042
  /**