@vertesia/client 0.66.0 → 0.68.0

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.
@@ -31,6 +31,11 @@ export class WorkflowsApi extends ApiTopic {
31
31
  return this.post(`/runs`, { payload: { documentId, eventName, ruleId } });
32
32
  }
33
33
 
34
+ /** List conversations the users has access to */
35
+ listConversations(): Promise<ListWorkflowRunsResponse> {
36
+ return this.get(`/conversations`);
37
+ }
38
+
34
39
  searchRuns(payload: ListWorkflowRunsPayload): Promise<ListWorkflowRunsResponse> {
35
40
  return this.post(`/runs`, { payload: payload });
36
41
  }
@@ -70,14 +75,14 @@ export class WorkflowsApi extends ApiTopic {
70
75
  return this.post(`/runs/${runId}/updates`, { payload: msg });
71
76
  }
72
77
 
73
- retrieveMessages(runId: string, since?: number): Promise<AgentMessage[]> {
78
+ retrieveMessages(workflowId: string, runId: string, since?: number): Promise<AgentMessage[]> {
74
79
  const query = {
75
80
  since,
76
81
  };
77
- return this.get(`/runs/${runId}/updates`, { query });
82
+ return this.get(`/runs/${workflowId}/${runId}/updates`, { query });
78
83
  }
79
84
 
80
- async streamMessages(runId: string, onMessage?: (message: AgentMessage, exitFn?: (payload: unknown) => void) => void, since?: number): Promise<unknown> {
85
+ async streamMessages(workflowId: string, runId: string, onMessage?: (message: AgentMessage, exitFn?: (payload: unknown) => void) => void, since?: number): Promise<unknown> {
81
86
  return new Promise<unknown>((resolve, reject) => {
82
87
  let reconnectAttempts = 0;
83
88
  let lastMessageTimestamp = since || 0;
@@ -121,7 +126,7 @@ export class WorkflowsApi extends ApiTopic {
121
126
  try {
122
127
  const EventSourceImpl = await EventSourceProvider();
123
128
  const client = this.client as VertesiaClient;
124
- const streamUrl = new URL(client.workflows.baseUrl + "/runs/" + runId + "/stream");
129
+ const streamUrl = new URL(client.workflows.baseUrl + `/runs/${workflowId}/${runId}/stream`);
125
130
 
126
131
  // Use the timestamp of the last received message for reconnection
127
132
  if (lastMessageTimestamp > 0) {
@@ -171,8 +176,12 @@ export class WorkflowsApi extends ApiTopic {
171
176
 
172
177
  if (onMessage) onMessage(message, exit);
173
178
 
174
- // Only close the stream when the main workstream completes
175
- if (message.type === AgentMessageType.COMPLETE && (!message.workstream_id || message.workstream_id === 'main')) {
179
+ const streamIsOver = message.type === AgentMessageType.TERMINATED ||
180
+ (message.type === AgentMessageType.COMPLETE &&
181
+ (!message.workstream_id || message.workstream_id === 'main'));
182
+
183
+ // Only close the stream when the main workstream completes or terminates
184
+ if (streamIsOver) {
176
185
  console.log("Closing stream due to COMPLETE message from main workstream");
177
186
  if (!isClosed) {
178
187
  isClosed = true;