@peopl-health/nexus 1.6.4 → 1.6.5

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.
@@ -164,11 +164,21 @@ class OpenAIProvider {
164
164
  return this.client.beta.threads.runs.retrieve(this._ensureId(conversationId), this._ensureId(runId));
165
165
  }
166
166
 
167
- async listRuns({ conversationId, limit, order = 'desc' } = {}) {
168
- return this.client.beta.threads.runs.list(this._ensureId(conversationId), {
167
+ async listRuns({ conversationId, limit, order = 'desc', activeOnly = false } = {}) {
168
+ const runs = await this.client.beta.threads.runs.list(this._ensureId(conversationId), {
169
169
  limit,
170
170
  order,
171
171
  });
172
+
173
+ if (activeOnly) {
174
+ const activeStatuses = ['in_progress', 'queued', 'requires_action'];
175
+ return {
176
+ ...runs,
177
+ data: runs.data.filter(run => activeStatuses.includes(run.status))
178
+ };
179
+ }
180
+
181
+ return runs;
172
182
  }
173
183
 
174
184
  async submitToolOutputs({ conversationId, runId, toolOutputs }) {
@@ -362,12 +362,12 @@ const replyAssistant = async function (code, message_ = null, thread_ = null, ru
362
362
 
363
363
  const provider = llmConfig.requireOpenAIProvider();
364
364
 
365
- let activeRuns = await provider.listRuns({ conversationId: thread.thread_id });
365
+ let activeRuns = await provider.listRuns({ conversationId: thread.thread_id, activeOnly: true });
366
366
  let activeRunsCount = activeRuns?.data?.length || 0;
367
- console.log('ACTIVE RUNS:', activeRunsCount);
367
+ console.log('ACTIVE RUNS:', activeRunsCount, activeRuns?.data?.map(run => ({ id: run.id, status: run.status })));
368
368
  while (activeRunsCount > 0) {
369
- console.log(`ACTIVE RUNS ${thread.thread_id}`);
370
- activeRuns = await provider.listRuns({ conversationId: thread.thread_id });
369
+ console.log(`WAITING FOR ${activeRunsCount} ACTIVE RUNS TO COMPLETE - ${thread.thread_id}`);
370
+ activeRuns = await provider.listRuns({ conversationId: thread.thread_id, activeOnly: true });
371
371
  activeRunsCount = activeRuns?.data?.length || 0;
372
372
  await delay(5000);
373
373
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",