@crewdle/mist-connector-openai 1.0.1 → 1.0.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.
@@ -101,21 +101,55 @@ export class OpenAIGenerativeAIWorkerConnector {
101
101
  if (!message.tool_calls) {
102
102
  break;
103
103
  }
104
- messages.push(message);
105
- const toolCall = message.tool_calls[0];
106
- if (toolCall?.function) {
107
- try {
108
- const result = await parameters.functions.get(toolCall.function.name)?.callback(JSON.parse(toolCall.function.arguments));
109
- messages.push({
110
- role: 'tool',
111
- tool_call_id: toolCall.id,
112
- content: result ?? '',
113
- });
114
- }
115
- catch (error) {
116
- console.error('Error processing tool call', error);
104
+ messages.push({
105
+ role: 'assistant',
106
+ content: null,
107
+ tool_calls: message.tool_calls,
108
+ refusal: null,
109
+ });
110
+ const promises = [];
111
+ for (const toolCall of message.tool_calls) {
112
+ if (toolCall?.function && parameters.functions) {
113
+ try {
114
+ const func = parameters.functions.get(toolCall.function.name);
115
+ if (func) {
116
+ const result = func.callback(JSON.parse(toolCall.function.arguments));
117
+ if (result instanceof Promise) {
118
+ promises.push(result.then((res) => {
119
+ messages.push({
120
+ role: 'tool',
121
+ tool_call_id: toolCall.id,
122
+ content: res ?? 'Tool does not exist',
123
+ });
124
+ }));
125
+ }
126
+ else {
127
+ messages.push({
128
+ role: 'tool',
129
+ tool_call_id: toolCall.id,
130
+ content: result ?? 'Tool does not exist',
131
+ });
132
+ }
133
+ }
134
+ else {
135
+ messages.push({
136
+ role: 'tool',
137
+ tool_call_id: toolCall.id,
138
+ content: 'Tool does not exist',
139
+ });
140
+ }
141
+ }
142
+ catch (error) {
143
+ console.error('Error processing tool call', error);
144
+ messages.push({
145
+ role: 'tool',
146
+ tool_call_id: toolCall.id,
147
+ content: 'Error processing tool call',
148
+ });
149
+ }
117
150
  }
118
151
  }
152
+ await Promise.all(promises);
119
153
  }
120
154
  }
121
155
  messageReducer(previous, item) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewdle/mist-connector-openai",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",