symposium 1.2.9 → 1.2.11
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/Agent.js +32 -10
- package/Tool.js +4 -0
- package/package.json +1 -1
package/Agent.js
CHANGED
|
@@ -292,8 +292,9 @@ export default class Agent {
|
|
|
292
292
|
} catch (e) {
|
|
293
293
|
reject(e);
|
|
294
294
|
}
|
|
295
|
-
}).then(
|
|
295
|
+
}).then(value => {
|
|
296
296
|
emitter.emit('end', thread);
|
|
297
|
+
return value;
|
|
297
298
|
});
|
|
298
299
|
|
|
299
300
|
return this.type === 'chat' ? emitter : execution;
|
|
@@ -418,20 +419,25 @@ export default class Agent {
|
|
|
418
419
|
}
|
|
419
420
|
|
|
420
421
|
if (functions.length) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
return {type: 'response', value: this.afterHandle(thread, completion, f.arguments)};
|
|
422
|
+
if (this.utility && ['function', 'json'].includes(this.utility.type))
|
|
423
|
+
return {type: 'response', value: this.afterHandle(thread, completion, functions[0].arguments)};
|
|
424
424
|
|
|
425
|
-
|
|
425
|
+
const responses = await Promise.all(functions.map(async f => this.callFunction(thread, f, emitter)));
|
|
426
426
|
|
|
427
|
+
if (responses.some(r => r.type === 'tool_auth')) {
|
|
428
|
+
emitter.emit('tool_auth', responses.filter(r => r.type === 'tool_auth').map(r => ({tool: r.tool, arguments: r.arguments})));
|
|
429
|
+
return {type: 'void'};
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
for (let r of responses) {
|
|
427
433
|
thread.addMessage('tool', [
|
|
428
434
|
{
|
|
429
435
|
type: 'function_response',
|
|
430
|
-
content: {name: f.name, response:
|
|
436
|
+
content: {name: f.name, response: r, id: f.id || undefined},
|
|
431
437
|
},
|
|
432
438
|
], f.name);
|
|
433
439
|
|
|
434
|
-
await this.log('function_response',
|
|
440
|
+
await this.log('function_response', r);
|
|
435
441
|
}
|
|
436
442
|
|
|
437
443
|
await this.afterHandle(thread, completion);
|
|
@@ -480,19 +486,35 @@ export default class Agent {
|
|
|
480
486
|
throw new Error('Unrecognized function ' + function_call.name);
|
|
481
487
|
|
|
482
488
|
const func = functions.get(function_call.name);
|
|
483
|
-
await this.log('function_call', function_call);
|
|
484
489
|
|
|
490
|
+
await this.log('function_call', function_call);
|
|
485
491
|
emitter.emit('tool', function_call);
|
|
486
492
|
|
|
493
|
+
if (!func.tool.authorize(thread, function_call.name, function_call.arguments)) {
|
|
494
|
+
return {
|
|
495
|
+
type: 'tool_auth',
|
|
496
|
+
tool: function_call.name,
|
|
497
|
+
arguments: function_call.arguments,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
487
501
|
try {
|
|
488
502
|
const response = await func.tool.callFunction(thread, function_call.name, function_call.arguments);
|
|
489
503
|
if (emitter)
|
|
490
504
|
emitter.emit('tool_response', {name: func.tool.name, success: true, response});
|
|
491
|
-
|
|
505
|
+
|
|
506
|
+
return {
|
|
507
|
+
type: 'response',
|
|
508
|
+
response,
|
|
509
|
+
};
|
|
492
510
|
} catch (error) {
|
|
493
511
|
if (emitter)
|
|
494
512
|
emitter.emit('tool_response', {name: func.tool.name, success: false, error: error.message || error});
|
|
495
|
-
|
|
513
|
+
|
|
514
|
+
return {
|
|
515
|
+
type: 'error',
|
|
516
|
+
error,
|
|
517
|
+
};
|
|
496
518
|
}
|
|
497
519
|
}
|
|
498
520
|
|
package/Tool.js
CHANGED