@minded-ai/mindedjs 1.0.141 → 1.0.142-beta-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.
@@ -141,12 +141,16 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
141
141
  };
142
142
  }
143
143
 
144
+ // Model text response
144
145
  state.goto = null;
145
- state.messages.push(result);
146
- let stateUpdate: any = { goto: null, messages: state.messages };
146
+ //update state so AI_MESSAGE will get the latest state
147
+ const stateForAIMessage = structuredClone(state);
148
+ stateForAIMessage.goto = null;
149
+ stateForAIMessage.messages.push(result);
150
+ let stateUpdate: any = { goto: null, messages: [result] };
147
151
  if (result.getType() === 'ai') {
148
152
  logger.info({ msg: `[Model] Response`, content: result.content });
149
- const results = await emit(AgentEvents.AI_MESSAGE, { message: result.content as string, state });
153
+ const results = await emit(AgentEvents.AI_MESSAGE, { message: result.content as string, state: stateForAIMessage });
150
154
  const handlerResult = results.find((r) => r !== undefined);
151
155
  if (handlerResult && handlerResult.state) {
152
156
  stateUpdate = { ...stateUpdate, ...handlerResult.state };