@minded-ai/mindedjs 1.0.92 → 1.0.93-beta.2

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.
Files changed (82) hide show
  1. package/README.md +1 -1
  2. package/dist/agent.d.ts +5 -10
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +39 -70
  5. package/dist/agent.js.map +1 -1
  6. package/dist/checkpointer/checkpointSaverFactory.d.ts +1 -3
  7. package/dist/checkpointer/checkpointSaverFactory.d.ts.map +1 -1
  8. package/dist/checkpointer/checkpointSaverFactory.js +38 -5
  9. package/dist/checkpointer/checkpointSaverFactory.js.map +1 -1
  10. package/dist/cli/index.js +0 -0
  11. package/dist/events/AgentEvents.d.ts +1 -8
  12. package/dist/events/AgentEvents.d.ts.map +1 -1
  13. package/dist/events/AgentEvents.js +0 -1
  14. package/dist/events/AgentEvents.js.map +1 -1
  15. package/dist/guidelines/guidelinesManager.d.ts +37 -0
  16. package/dist/guidelines/guidelinesManager.d.ts.map +1 -0
  17. package/dist/guidelines/guidelinesManager.js +172 -0
  18. package/dist/guidelines/guidelinesManager.js.map +1 -0
  19. package/dist/index.d.ts +3 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +7 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/interfaces/zendesk.d.ts.map +1 -1
  24. package/dist/interfaces/zendesk.js +70 -48
  25. package/dist/interfaces/zendesk.js.map +1 -1
  26. package/dist/internalTools/appActionRunnerTool.d.ts +1 -2
  27. package/dist/internalTools/appActionRunnerTool.d.ts.map +1 -1
  28. package/dist/internalTools/appActionRunnerTool.js +36 -2
  29. package/dist/internalTools/appActionRunnerTool.js.map +1 -1
  30. package/dist/internalTools/sendPlaceholderMessage.d.ts +14 -0
  31. package/dist/internalTools/sendPlaceholderMessage.d.ts.map +1 -0
  32. package/dist/internalTools/sendPlaceholderMessage.js +61 -0
  33. package/dist/internalTools/sendPlaceholderMessage.js.map +1 -0
  34. package/dist/internalTools/timer.d.ts +93 -0
  35. package/dist/internalTools/timer.d.ts.map +1 -0
  36. package/dist/internalTools/timer.js +152 -0
  37. package/dist/internalTools/timer.js.map +1 -0
  38. package/dist/platform/mindedCheckpointSaver.d.ts +1 -3
  39. package/dist/platform/mindedCheckpointSaver.d.ts.map +1 -1
  40. package/dist/platform/mindedCheckpointSaver.js +43 -10
  41. package/dist/platform/mindedCheckpointSaver.js.map +1 -1
  42. package/dist/platform/mindedConnection.d.ts +14 -14
  43. package/dist/platform/mindedConnection.d.ts.map +1 -1
  44. package/dist/platform/mindedConnection.js +152 -131
  45. package/dist/platform/mindedConnection.js.map +1 -1
  46. package/dist/platform/mindedConnectionTypes.d.ts +47 -38
  47. package/dist/platform/mindedConnectionTypes.d.ts.map +1 -1
  48. package/dist/platform/mindedConnectionTypes.js +25 -24
  49. package/dist/platform/mindedConnectionTypes.js.map +1 -1
  50. package/dist/platform/piiGateway/gateway.d.ts +1 -3
  51. package/dist/platform/piiGateway/gateway.d.ts.map +1 -1
  52. package/dist/platform/piiGateway/gateway.js +39 -6
  53. package/dist/platform/piiGateway/gateway.js.map +1 -1
  54. package/dist/playbooks/playbooks.d.ts +1 -2
  55. package/dist/playbooks/playbooks.d.ts.map +1 -1
  56. package/dist/playbooks/playbooks.js +4 -3
  57. package/dist/playbooks/playbooks.js.map +1 -1
  58. package/dist/utils/extractToolMemoryResponse.d.ts +4 -0
  59. package/dist/utils/extractToolMemoryResponse.d.ts.map +1 -0
  60. package/dist/utils/extractToolMemoryResponse.js +16 -0
  61. package/dist/utils/extractToolMemoryResponse.js.map +1 -0
  62. package/dist/voice/voiceSession.d.ts.map +1 -1
  63. package/dist/voice/voiceSession.js +39 -5
  64. package/dist/voice/voiceSession.js.map +1 -1
  65. package/docs/SUMMARY.md +4 -0
  66. package/docs/tooling/timers.md +61 -0
  67. package/package.json +3 -4
  68. package/src/agent.ts +56 -87
  69. package/src/checkpointer/checkpointSaverFactory.ts +5 -6
  70. package/src/events/AgentEvents.ts +1 -8
  71. package/src/index.ts +3 -1
  72. package/src/interfaces/zendesk.ts +38 -37
  73. package/src/internalTools/appActionRunnerTool.ts +4 -4
  74. package/src/internalTools/sendPlaceholderMessage.ts +27 -0
  75. package/src/internalTools/timer.ts +137 -0
  76. package/src/platform/mindedCheckpointSaver.ts +27 -27
  77. package/src/platform/mindedConnection.ts +176 -147
  78. package/src/platform/mindedConnectionTypes.ts +49 -38
  79. package/src/platform/piiGateway/gateway.ts +8 -10
  80. package/src/playbooks/playbooks.ts +5 -5
  81. package/src/voice/voiceSession.ts +6 -5
  82. package/docs-structure.md +0 -141
package/src/agent.ts CHANGED
@@ -10,13 +10,10 @@ import { CompiledGraph, PreCompiledGraph, stateAnnotation } from './types/LangGr
10
10
  import { edgeFactory } from './edges/edgeFactory';
11
11
  import { AgentEventRequestPayloads, AgentEventResponsePayloads, AgentEvents } from './events/AgentEvents';
12
12
  import { z } from 'zod';
13
- import { MindedConnection } from './platform/mindedConnection';
13
+ import * as mindedConnection from './platform/mindedConnection';
14
14
  import {
15
15
  InvokeMessage,
16
- MindedConnectionSocketMessageType,
17
- TimerCancelResponse,
18
- TimerResetResponse,
19
- TimerTriggerRequest,
16
+ mindedConnectionSocketMessageType,
20
17
  } from './platform/mindedConnectionTypes';
21
18
  import * as fs from 'fs';
22
19
  import * as path from 'path';
@@ -41,6 +38,7 @@ import { PIIGateway, PIIGatewayInstance } from './platform/piiGateway';
41
38
  import { logger } from './utils/logger';
42
39
  import { loadPlaybooks, Playbook } from './playbooks/playbooks';
43
40
  import { createHistoryStep } from './utils/history';
41
+ import { timerHandlers } from './internalTools/timer';
44
42
 
45
43
  type CreateAgentParams<Memory> = {
46
44
  memorySchema: z.ZodSchema;
@@ -72,8 +70,12 @@ export class Agent {
72
70
  private memorySchema: z.ZodSchema;
73
71
  private flows!: Flow[];
74
72
  public tools!: Tool<any, any>[];
73
+ /**
74
+ * Internal tools
75
+ */
75
76
  public llm!: BaseLanguageModel;
76
- public mindedConnection: MindedConnection | null = null;
77
+ // Remove the mindedConnection property since it's now a singleton module
78
+
77
79
  // Langgraph memory saver. In memory for local development, Custom for Platform
78
80
  private checkpointer!: BaseCheckpointSaver;
79
81
  // Langgraph compiled graph
@@ -86,10 +88,10 @@ export class Agent {
86
88
  private _piiGateway: PIIGatewayInstance | null = null;
87
89
  public playbooks: Playbook[] = [];
88
90
 
89
- // PII gateway instance getter
91
+ // Getter for PII Gateway that ensures it's available
90
92
  public get piiGateway(): PIIGatewayInstance {
91
93
  if (!this._piiGateway) {
92
- throw new Error('Minded connection is not established when trying to get PII gateway');
94
+ throw new Error('PII Gateway is not initialized. Make sure the agent is connected to the Minded platform.');
93
95
  }
94
96
  return this._piiGateway;
95
97
  }
@@ -149,12 +151,12 @@ export class Agent {
149
151
  const { config, tools, memorySaver } = params;
150
152
  const { runLocally } = getConfig();
151
153
  if (!runLocally) {
152
- this.mindedConnection = new MindedConnection();
153
- await this.mindedConnection.start();
154
+ await mindedConnection.start();
154
155
 
155
156
  // Initialize PII gateway
156
- this._piiGateway = new PIIGateway(this.mindedConnection);
157
- this.mindedConnection.on(MindedConnectionSocketMessageType.INVOKE, async (message, callback) => {
157
+ this._piiGateway = new PIIGateway();
158
+
159
+ mindedConnection.on(mindedConnectionSocketMessageType.INVOKE, async (message, callback) => {
158
160
  const invokeMessage = message as InvokeMessage;
159
161
  const result = await this.invoke({
160
162
  triggerBody: invokeMessage.triggerBody,
@@ -164,20 +166,18 @@ export class Agent {
164
166
  });
165
167
  callback(result);
166
168
  });
167
- this.mindedConnection.on(MindedConnectionSocketMessageType.TIMER_TRIGGER, async (message) => {
168
- const timerTriggerMessage = message as TimerTriggerRequest;
169
- await this.emit(AgentEvents.TIMER_TRIGGER, {
170
- sessionId: timerTriggerMessage.sessionId,
171
- timerName: timerTriggerMessage.timerName,
172
- eventArgs: timerTriggerMessage.eventArgs,
173
- });
169
+
170
+ mindedConnection.on(mindedConnectionSocketMessageType.RESTORE_CHECKPOINT, async (restoreCheckpointMessage, callback) => {
171
+ const langraphConfig = this.getLangraphConfig(restoreCheckpointMessage.sessionId, restoreCheckpointMessage.checkpointId);
172
+ this.compiledGraph.invoke({}, langraphConfig);
173
+ callback({ success: true });
174
174
  });
175
175
  }
176
176
 
177
177
  const [, flows, playbooks] = await Promise.all([
178
178
  this.loadSecrets(),
179
179
  this.loadFlows(config.flows),
180
- loadPlaybooks(this.mindedConnection, config.playbooks),
180
+ loadPlaybooks(config.playbooks),
181
181
  ]);
182
182
 
183
183
  this.playbooks = playbooks;
@@ -185,7 +185,7 @@ export class Agent {
185
185
  this.validate();
186
186
  const appActionsRunnerTools = this.initAppActionsRunnerTools();
187
187
  this.tools = [...tools, ...appActionsRunnerTools];
188
- this.checkpointer = memorySaver || createCheckpointSaver(this.mindedConnection);
188
+ this.checkpointer = memorySaver || createCheckpointSaver();
189
189
 
190
190
  // call here methods that needs environment variables to be loaded
191
191
  this.llm = createLlmInstance(config.llm);
@@ -207,8 +207,8 @@ export class Agent {
207
207
  private async loadFlows(flowsDirectories: string[]) {
208
208
  const { env, isDeployed } = getConfig();
209
209
  if (['sandbox-staging', 'sandbox'].includes(env) && isDeployed) {
210
- const response = await this.mindedConnection?.awaitEmit<object, { flows: Record<string, Flow> }>(
211
- MindedConnectionSocketMessageType.GET_FLOWS,
210
+ const response = await mindedConnection.awaitEmit<object, { flows: Record<string, Flow> }>(
211
+ mindedConnectionSocketMessageType.GET_FLOWS,
212
212
  {},
213
213
  );
214
214
  if (!response?.flows) {
@@ -376,14 +376,14 @@ export class Agent {
376
376
 
377
377
  return appName
378
378
  ? createHistoryStep<AppTriggerHistoryStep>(currentHistory, {
379
- ...baseStep,
380
- type: NodeType.TRIGGER,
381
- appName,
382
- })
379
+ ...baseStep,
380
+ type: NodeType.TRIGGER,
381
+ appName,
382
+ })
383
383
  : createHistoryStep<TriggerHistoryStep>(currentHistory, {
384
- ...baseStep,
385
- type: NodeType.TRIGGER,
386
- });
384
+ ...baseStep,
385
+ type: NodeType.TRIGGER,
386
+ });
387
387
  }
388
388
 
389
389
  /**
@@ -690,32 +690,7 @@ export class Agent {
690
690
  (this.eventHandlers[event] as Array<typeof handler>).push(handler);
691
691
  }
692
692
 
693
- public async resetTimer(
694
- sessionId: string,
695
- seconds: number,
696
- timerName: string,
697
- eventArgs: Record<string, any>,
698
- ): Promise<TimerResetResponse> {
699
- if (!this.mindedConnection) {
700
- throw new Error('Minded connection is not established when trying to reset timer');
701
- }
702
- return await this.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.TIMER_RESET, {
703
- sessionId,
704
- seconds,
705
- timerName,
706
- eventArgs,
707
- });
708
- }
709
693
 
710
- public async cancelTimer(sessionId: string, timerName: string): Promise<TimerCancelResponse> {
711
- if (!this.mindedConnection) {
712
- throw new Error('Minded connection is not established when trying to cancel timer');
713
- }
714
- return await this.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.TIMER_CANCEL, {
715
- sessionId,
716
- timerName,
717
- });
718
- }
719
694
 
720
695
  // Internal method to emit events to the registered listeners
721
696
  private async emit<E extends keyof AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>>(
@@ -731,12 +706,12 @@ export class Agent {
731
706
 
732
707
  private initAppActionsRunnerTools() {
733
708
  const { runLocally } = getConfig();
734
- if (!runLocally && !this.mindedConnection && process.env.NODE_ENV !== 'test') {
709
+ if (!runLocally && !mindedConnection.isConnected() && process.env.NODE_ENV !== 'test') {
735
710
  throw new Error('Minded connection is mandatory to use run app action tools');
736
711
  }
737
712
  return this.flows
738
713
  .flatMap((flow) => flow.nodes.filter((node) => node.type === NodeType.APP_TOOL))
739
- .map((node) => appActionRunnerToolCreator(node.metadata.schema, node.displayName!, this.mindedConnection as MindedConnection));
714
+ .map((node) => appActionRunnerToolCreator(node.metadata.schema, node.displayName!));
740
715
  }
741
716
 
742
717
  // Private method to get secrets from the backend service and load them into environment variables
@@ -747,7 +722,7 @@ export class Agent {
747
722
  logger.info('Running locally - skipping secret loading');
748
723
  return {};
749
724
  }
750
- if (!this.mindedConnection?.isConnected) {
725
+ if (!mindedConnection.isConnected()) {
751
726
  throw new Error('Minded connection is not established when trying to get secrets');
752
727
  }
753
728
 
@@ -758,12 +733,12 @@ export class Agent {
758
733
 
759
734
  try {
760
735
  // Check if mindedConnection is available
761
- if (!this.mindedConnection) {
736
+ if (!mindedConnection.isConnected()) {
762
737
  throw new Error('Platform is not available');
763
738
  }
764
739
 
765
- const response = await this.mindedConnection.awaitEmit<object, { secrets: Record<string, string> }>(
766
- MindedConnectionSocketMessageType.GET_SECRETS,
740
+ const response = await mindedConnection.awaitEmit<object, { secrets: Record<string, string> }>(
741
+ mindedConnectionSocketMessageType.GET_SECRETS,
767
742
  {},
768
743
  );
769
744
 
@@ -785,28 +760,28 @@ export class Agent {
785
760
  }
786
761
  }
787
762
 
788
- public getLangraphConfig(sessionId: string): { configurable: { thread_id: string; recursionLimit: number } } {
789
- return { configurable: { thread_id: sessionId, recursionLimit: 3 } };
763
+ public getLangraphConfig(sessionId: string, checkpointId?: string) {
764
+ return { configurable: { thread_id: sessionId, recursionLimit: 3, checkpoint_id: checkpointId } };
790
765
  }
791
766
 
792
767
  private setupVoice(): void {
793
768
  logger.info('Setting up voice');
794
- if (!this.mindedConnection) {
769
+ if (!mindedConnection.isConnected()) {
795
770
  throw new Error('Minded connection is required');
796
771
  }
797
772
 
798
- const connection = this.mindedConnection;
773
+ const connection = mindedConnection;
799
774
  const { dashboardConnected } = getConfig();
800
775
 
801
776
  if (dashboardConnected) {
802
777
  // Listen for voice session start
803
- connection.on(MindedConnectionSocketMessageType.DASHBOARD_VOICE_SESSION_START, async (message) => {
778
+ connection.on(mindedConnectionSocketMessageType.DASHBOARD_VOICE_SESSION_START, async (message) => {
804
779
  const sessionStart = message as BaseVoiceMessage;
805
780
  await this.startVoiceSession({ sessionId: sessionStart.sessionId });
806
781
  });
807
782
 
808
783
  // Listen for incoming audio from the platform
809
- connection.on(MindedConnectionSocketMessageType.DASHBOARD_VOICE_USER_AUDIO, (message) => {
784
+ connection.on(mindedConnectionSocketMessageType.DASHBOARD_VOICE_USER_AUDIO, (message) => {
810
785
  const audioMessage = message as OnVoiceAudioOut;
811
786
  const voiceSession = this.voiceSessions.get(audioMessage.sessionId);
812
787
  if (voiceSession) {
@@ -821,7 +796,7 @@ export class Agent {
821
796
  });
822
797
 
823
798
  // Hangup / end session handler
824
- connection.on(MindedConnectionSocketMessageType.DASHBOARD_VOICE_SESSION_END, (message) => {
799
+ connection.on(mindedConnectionSocketMessageType.DASHBOARD_VOICE_SESSION_END, (message) => {
825
800
  const hangup = message as BaseVoiceMessage;
826
801
  logger.debug({ message: 'Dashboard eneded voice session', sessionId: hangup.sessionId });
827
802
  const voiceSession = this.voiceSessions.get(hangup.sessionId);
@@ -838,19 +813,9 @@ export class Agent {
838
813
  }
839
814
  }
840
815
 
841
- public async sendPlaceholderMessage({ sessionId, message }: { sessionId: string; message: string }): Promise<void> {
842
- if (!this.mindedConnection) {
843
- throw new Error('Minded connection is not established when trying to send placeholder message');
844
- }
845
- const connection = this.mindedConnection;
846
- connection.emit(MindedConnectionSocketMessageType.DASHBOARD_VOICE_PLACEHOLDER_MESSAGES, {
847
- sessionId,
848
- message,
849
- timestamp: Date.now(),
850
- type: MindedConnectionSocketMessageType.DASHBOARD_VOICE_PLACEHOLDER_MESSAGES,
851
- });
852
- }
853
-
816
+ /*
817
+ To be used by the Lambda wrapper to start voice sessions
818
+ */
854
819
  public async startVoiceSession(params: { sessionId: string }): Promise<VoiceSession> {
855
820
  await this.waitForInitialization();
856
821
  const voiceTrigger = this.flows
@@ -877,12 +842,16 @@ export class Agent {
877
842
  return voiceSession;
878
843
  }
879
844
 
845
+ /*
846
+ To be used by the Lambda wrapper to trigger timers
847
+ */
880
848
  public async timerTrigger(params: { sessionId: string; timerName: string; eventArgs: Record<string, any> }): Promise<void> {
881
- console.log('timerTrigger fired from lambda', params);
882
- await this.emit(AgentEvents.TIMER_TRIGGER, {
883
- sessionId: params.sessionId,
884
- timerName: params.timerName,
885
- eventArgs: params.eventArgs,
886
- });
849
+ const handlers = timerHandlers.get(params.timerName) || [];
850
+ for (const { handler } of handlers) {
851
+ await handler({
852
+ sessionId: params.sessionId,
853
+ payload: params.eventArgs,
854
+ });
855
+ }
887
856
  }
888
857
  }
@@ -1,19 +1,18 @@
1
1
  import { BaseCheckpointSaver, MemorySaver } from '@langchain/langgraph';
2
2
  import { MindedCheckpointSaver } from '../platform/mindedCheckpointSaver';
3
- import { MindedConnection } from '../platform/mindedConnection';
3
+ import * as mindedConnection from '../platform/mindedConnection';
4
4
  import { logger } from '../utils/logger';
5
5
 
6
6
  /**
7
7
  * Factory function to create the appropriate checkpoint saver based on environment variables.
8
- * @param platformToken - Optional platform token for remote checkpoint saving
9
8
  * @returns BaseCheckpointSaver instance (either MemorySaver or MindedCheckpointSaver)
10
9
  */
11
- export function createCheckpointSaver(mindedConnection: MindedConnection | null): BaseCheckpointSaver {
12
- if (!mindedConnection) {
13
- logger.warn('mindedConnection not set, falling back to in-memory checkpoint saver');
10
+ export function createCheckpointSaver(): BaseCheckpointSaver {
11
+ if (!mindedConnection.isConnected()) {
12
+ logger.warn('mindedConnection not connected, falling back to in-memory checkpoint saver');
14
13
  return new MemorySaver();
15
14
  }
16
15
 
17
16
  logger.debug('Using remote checkpoint saver');
18
- return new MindedCheckpointSaver(mindedConnection);
17
+ return new MindedCheckpointSaver();
19
18
  }
@@ -7,8 +7,7 @@ export enum AgentEvents {
7
7
  AI_MESSAGE = 'AI_MESSAGE',
8
8
  TRIGGER_EVENT = 'TRIGGER_EVENT',
9
9
  VOICE_SESSION_START = 'VOICE_SESSION_START',
10
- ERROR = 'ERROR',
11
- TIMER_TRIGGER = 'TIMER_TRIGGER',
10
+ ERROR = 'ERROR'
12
11
  }
13
12
 
14
13
  export type AgentEventRequestPayloads<Memory> = {
@@ -31,11 +30,6 @@ export type AgentEventRequestPayloads<Memory> = {
31
30
  error: Error;
32
31
  state?: State<Memory>;
33
32
  };
34
- [AgentEvents.TIMER_TRIGGER]: {
35
- sessionId: string;
36
- timerName: string;
37
- eventArgs: Record<string, any>;
38
- };
39
33
  };
40
34
 
41
35
  export type AgentEventResponsePayloads<Memory> = {
@@ -50,5 +44,4 @@ export type AgentEventResponsePayloads<Memory> = {
50
44
  };
51
45
  [AgentEvents.VOICE_SESSION_START]: void;
52
46
  [AgentEvents.ERROR]: void;
53
- [AgentEvents.TIMER_TRIGGER]: void;
54
47
  };
package/src/index.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { Agent } from './agent';
2
2
  import events from './events';
3
3
  import { logger } from './utils/logger';
4
+ import { sendPlaceholderMessage } from './internalTools/sendPlaceholderMessage';
5
+ import { resetTimer, cancelTimer, onTimer } from './internalTools/timer';
4
6
 
5
7
  export type { ElevenLabsContext } from './types/Voice.types';
6
- export { Agent, events, logger };
8
+ export { Agent, events, logger, sendPlaceholderMessage, resetTimer, cancelTimer, onTimer };
7
9
 
8
10
  // HTTP module for PII masking - only public API
9
11
  export type { PIIGatewayInstance, HttpRequestConfig, HttpResponse } from './platform/piiGateway';
@@ -1,5 +1,6 @@
1
1
  import { Agent } from '../agent';
2
- import { MindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
2
+ import * as mindedConnection from '../platform/mindedConnection';
3
+ import { mindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
3
4
 
4
5
  export const zendesk = {
5
6
  agent: null as Agent | null,
@@ -8,9 +9,9 @@ export const zendesk = {
8
9
  },
9
10
 
10
11
  sendMessage: async (sessionId: string, message: string) => {
11
- if (!zendesk.agent?.mindedConnection) return;
12
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
13
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
12
+ if (!mindedConnection.isConnected()) return;
13
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
14
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
14
15
  interfaceName: 'zendesk',
15
16
  sessionId,
16
17
  functionName: 'sendMessage',
@@ -19,9 +20,9 @@ export const zendesk = {
19
20
  },
20
21
 
21
22
  sendComment: async (sessionId: string, comment: string) => {
22
- if (!zendesk.agent?.mindedConnection) return;
23
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
24
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
23
+ if (!mindedConnection.isConnected()) return;
24
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
25
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
25
26
  interfaceName: 'zendesk',
26
27
  sessionId,
27
28
  functionName: 'sendComment',
@@ -30,9 +31,9 @@ export const zendesk = {
30
31
  },
31
32
 
32
33
  sendPublicComment: async (sessionId: string, comment: string) => {
33
- if (!zendesk.agent?.mindedConnection) return;
34
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
35
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
34
+ if (!mindedConnection.isConnected()) return;
35
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
36
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
36
37
  interfaceName: 'zendesk',
37
38
  sessionId,
38
39
  functionName: 'sendPublicComment',
@@ -41,9 +42,9 @@ export const zendesk = {
41
42
  },
42
43
 
43
44
  getConversation: async (sessionId: string) => {
44
- if (!zendesk.agent?.mindedConnection) return;
45
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
46
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
45
+ if (!mindedConnection.isConnected()) return;
46
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
47
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
47
48
  interfaceName: 'zendesk',
48
49
  sessionId,
49
50
  functionName: 'getConversation',
@@ -52,9 +53,9 @@ export const zendesk = {
52
53
  },
53
54
 
54
55
  getConversationMessages: async (sessionId: string) => {
55
- if (!zendesk.agent?.mindedConnection) return;
56
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
57
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
56
+ if (!mindedConnection.isConnected()) return;
57
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
58
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
58
59
  interfaceName: 'zendesk',
59
60
  sessionId,
60
61
  functionName: 'getConversationMessages',
@@ -63,9 +64,9 @@ export const zendesk = {
63
64
  },
64
65
 
65
66
  addTag: async (sessionId: string, tag: string) => {
66
- if (!zendesk.agent?.mindedConnection) return;
67
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
68
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
67
+ if (!mindedConnection.isConnected()) return;
68
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
69
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
69
70
  interfaceName: 'zendesk',
70
71
  sessionId,
71
72
  functionName: 'addTag',
@@ -74,9 +75,9 @@ export const zendesk = {
74
75
  },
75
76
 
76
77
  getTicket: async (sessionId: string) => {
77
- if (!zendesk.agent?.mindedConnection) return;
78
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
79
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
78
+ if (!mindedConnection.isConnected()) return;
79
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
80
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
80
81
  interfaceName: 'zendesk',
81
82
  sessionId,
82
83
  functionName: 'getTicket',
@@ -101,9 +102,9 @@ export const zendesk = {
101
102
  tags: string[];
102
103
  customFields: any[];
103
104
  }) => {
104
- if (!zendesk.agent?.mindedConnection) return;
105
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
106
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
105
+ if (!mindedConnection.isConnected()) return;
106
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
107
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
107
108
  interfaceName: 'zendesk',
108
109
  sessionId,
109
110
  functionName: 'createTicket',
@@ -111,9 +112,9 @@ export const zendesk = {
111
112
  });
112
113
  },
113
114
  markTicketAsSolved: async ({ sessionId }: { sessionId: string }) => {
114
- if (!zendesk.agent?.mindedConnection) return;
115
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
116
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
115
+ if (!mindedConnection.isConnected()) return;
116
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
117
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
117
118
  interfaceName: 'zendesk',
118
119
  sessionId,
119
120
  functionName: 'markTicketAsSolved',
@@ -122,9 +123,9 @@ export const zendesk = {
122
123
  },
123
124
 
124
125
  markTicketAsOpen: async ({ sessionId }: { sessionId: string }) => {
125
- if (!zendesk.agent?.mindedConnection) return;
126
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
127
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
126
+ if (!mindedConnection.isConnected()) return;
127
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
128
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
128
129
  interfaceName: 'zendesk',
129
130
  sessionId,
130
131
  functionName: 'markTicketAsOpen',
@@ -133,9 +134,9 @@ export const zendesk = {
133
134
  },
134
135
 
135
136
  setCustomFields: async ({ sessionId, fields }: { sessionId: string; fields: any[] }) => {
136
- if (!zendesk.agent?.mindedConnection) return;
137
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
138
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
137
+ if (!mindedConnection.isConnected()) return;
138
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
139
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
139
140
  interfaceName: 'zendesk',
140
141
  sessionId,
141
142
  functionName: 'setCustomFields',
@@ -144,9 +145,9 @@ export const zendesk = {
144
145
  },
145
146
 
146
147
  search: async ({ sessionId, query }: { sessionId: string; query: string }) => {
147
- if (!zendesk.agent?.mindedConnection) return;
148
- return await zendesk.agent.mindedConnection.awaitEmit(MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
149
- type: MindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
148
+ if (!mindedConnection.isConnected()) return;
149
+ return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
150
+ type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
150
151
  interfaceName: 'zendesk',
151
152
  sessionId,
152
153
  functionName: 'search',
@@ -1,5 +1,5 @@
1
- import { MindedConnection } from '../platform/mindedConnection';
2
- import { MindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
1
+ import * as mindedConnection from '../platform/mindedConnection';
2
+ import { mindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
3
3
  import { ActionInputParam } from '../types/Flows.types';
4
4
  import { Tool, ToolExecuteInput } from '../types/Tools.types';
5
5
  import { z } from 'zod';
@@ -24,7 +24,7 @@ const convertToZodSchema = (schema: Record<string, { type: string; example?: any
24
24
 
25
25
  const createdTools: Record<string, Tool<any, any>> = {};
26
26
 
27
- const appActionRunnerToolCreator = (schema: ActionInputParam[], nodeTitle: string, mindedConnection: MindedConnection): Tool<any, any> => {
27
+ const appActionRunnerToolCreator = (schema: ActionInputParam[], nodeTitle: string): Tool<any, any> => {
28
28
  const zodSchema = convertToZodSchema(
29
29
  schema.reduce((acc, param) => {
30
30
  if (param.required) {
@@ -51,7 +51,7 @@ const appActionRunnerToolCreator = (schema: ActionInputParam[], nodeTitle: strin
51
51
  input: zodSchema,
52
52
  execute: async ({ input, state }: ToolExecuteInput<typeof zodSchema>) => {
53
53
  const response = await mindedConnection.awaitEmit(
54
- MindedConnectionSocketMessageType.OnAppAction,
54
+ mindedConnectionSocketMessageType.OnAppAction,
55
55
  {
56
56
  nodeTitle,
57
57
  actionInput: input,
@@ -0,0 +1,27 @@
1
+ import * as mindedConnection from '../platform/mindedConnection';
2
+ import { mindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
3
+
4
+ /**
5
+ * Send a placeholder message to the dashboard voice session.
6
+ * This is typically used for voice sessions to provide immediate feedback to users.
7
+ *
8
+ * @param params - The parameters for sending the placeholder message
9
+ * @param params.sessionId - The session ID of the voice session
10
+ * @param params.message - The placeholder message to send
11
+ * @throws {Error} When the Minded connection is not established
12
+ */
13
+ export async function sendPlaceholderMessage(params: { sessionId: string; message: string }): Promise<void> {
14
+ const { sessionId, message } = params;
15
+
16
+ if (!mindedConnection.isConnected()) {
17
+ throw new Error('Minded connection is not established when trying to send placeholder message');
18
+ }
19
+
20
+ const connection = mindedConnection;
21
+ connection.emit(mindedConnectionSocketMessageType.DASHBOARD_VOICE_PLACEHOLDER_MESSAGES, {
22
+ sessionId,
23
+ message,
24
+ timestamp: Date.now(),
25
+ type: mindedConnectionSocketMessageType.DASHBOARD_VOICE_PLACEHOLDER_MESSAGES,
26
+ });
27
+ }