@minded-ai/mindedjs 1.0.50 → 1.0.51

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minded-ai/mindedjs",
3
- "version": "1.0.50",
3
+ "version": "1.0.51",
4
4
  "description": "MindedJS is a TypeScript library for building agents.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/agent.ts CHANGED
@@ -335,13 +335,23 @@ export class Agent {
335
335
  triggerBody,
336
336
  sessionId,
337
337
  });
338
- const handlerResult = results.find((r) => r !== undefined);
339
- if (handlerResult) {
340
- memoryUpdate = handlerResult.memory || {};
341
- messages = handlerResult.messages ?? [];
342
- sessionId = handlerResult.sessionId ?? sessionId;
343
- } else if (appName) {
344
- messages = triggerTypeToDefaultMessage[appName]?.[triggerName]?.(triggerBody) ?? [];
338
+ if (results.length === 0) {
339
+ if (appName) {
340
+ messages = triggerTypeToDefaultMessage[appName]?.[triggerName]?.(triggerBody) ?? [new HumanMessage(JSON.stringify(triggerBody))];
341
+ } else {
342
+ messages = [new HumanMessage(JSON.stringify(triggerBody))];
343
+ }
344
+ } else {
345
+ const handlerResult = results.find((r) => r !== undefined);
346
+ if (handlerResult) {
347
+ if (!handlerResult.isQualified) {
348
+ console.log(`Trigger ${triggerName} was disqualified`);
349
+ return;
350
+ }
351
+ memoryUpdate = handlerResult.memory || {};
352
+ messages = handlerResult.messages ?? [];
353
+ sessionId = handlerResult.sessionId ?? sessionId;
354
+ }
345
355
  }
346
356
  }
347
357
  const triggerInvocation = { appName, triggerName, triggerBody };
@@ -21,5 +21,11 @@ export type AgentEventRequestPayloads<Memory> = {
21
21
 
22
22
  export type AgentEventResponsePayloads<Memory> = {
23
23
  [AgentEvents.AI_MESSAGE]: void;
24
- [AgentEvents.TRIGGER_EVENT]: { messages?: BaseMessage[]; memory?: Memory, history?: FlowHistory[], sessionId?: string } | false;
24
+ [AgentEvents.TRIGGER_EVENT]: {
25
+ isQualified: boolean;
26
+ messages?: BaseMessage[];
27
+ memory?: Memory;
28
+ history?: FlowHistory[];
29
+ sessionId?: string;
30
+ };
25
31
  };
@@ -1,9 +1,9 @@
1
- import { BaseMessage, HumanMessage } from "@langchain/core/messages";
1
+ import { BaseMessage, HumanMessage } from '@langchain/core/messages';
2
2
 
3
3
  const triggerTypeToDefaultMessage: Record<string, Record<string, (triggerBody: any) => Array<BaseMessage>>> = {
4
- ["Slack"]: {
5
- "New Direct Message (Instant)": (triggerBody: any) => [new HumanMessage({ content: triggerBody.text })],
6
- }
4
+ ['Slack']: {
5
+ 'New Direct Message (Instant)': (triggerBody: any) => [new HumanMessage({ content: triggerBody.text })],
6
+ },
7
7
  };
8
8
 
9
- export default triggerTypeToDefaultMessage;
9
+ export default triggerTypeToDefaultMessage;