agent-swarm-kit 1.0.63 → 1.0.65
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/build/index.cjs +11 -2
- package/build/index.mjs +12 -3
- package/package.json +1 -1
- package/types.d.ts +108 -0
package/build/index.cjs
CHANGED
|
@@ -446,6 +446,8 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
446
446
|
clientId: this.clientId,
|
|
447
447
|
agentName: agentName,
|
|
448
448
|
});
|
|
449
|
+
this.callbacks.onPush &&
|
|
450
|
+
this.callbacks.onPush(value, this.clientId, agentName);
|
|
449
451
|
this._array.push(value);
|
|
450
452
|
this.callbacks.onChange &&
|
|
451
453
|
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
@@ -690,7 +692,7 @@ var HistoryUtils = /** @class */ (function () {
|
|
|
690
692
|
*/
|
|
691
693
|
this.useHistoryCallbacks = function (Callbacks) {
|
|
692
694
|
swarm.loggerService.log("HistoryUtils useHistoryCallbacks");
|
|
693
|
-
_this.HistoryCallbacks
|
|
695
|
+
Object.assign(_this.HistoryCallbacks, Callbacks);
|
|
694
696
|
};
|
|
695
697
|
/**
|
|
696
698
|
* Push a new message to the history.
|
|
@@ -908,7 +910,7 @@ var setConfig = function (config) {
|
|
|
908
910
|
Object.assign(GLOBAL_CONFIG, config);
|
|
909
911
|
};
|
|
910
912
|
|
|
911
|
-
var AGENT_CHANGE_SYMBOL = Symbol(
|
|
913
|
+
var AGENT_CHANGE_SYMBOL = Symbol("agent-change");
|
|
912
914
|
var getPlaceholder = function () {
|
|
913
915
|
return GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS[Math.floor(Math.random() * GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS.length)];
|
|
914
916
|
};
|
|
@@ -1295,6 +1297,13 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1295
1297
|
})
|
|
1296
1298
|
.catch(function (error) {
|
|
1297
1299
|
var _a, _b;
|
|
1300
|
+
console.error("agent-swarm tool call error functionName=".concat(tool.function.name, " error=").concat(functoolsKit.getErrorMessage(error)), {
|
|
1301
|
+
clientId: _this.params.clientId,
|
|
1302
|
+
agentName: _this.params.agentName,
|
|
1303
|
+
tool_call_id: tool.id,
|
|
1304
|
+
arguments: tool.function.arguments,
|
|
1305
|
+
error: functoolsKit.errorData(error),
|
|
1306
|
+
});
|
|
1298
1307
|
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onCallError) &&
|
|
1299
1308
|
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onCallError(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments, error));
|
|
1300
1309
|
_this._toolErrorSubject.next();
|
package/build/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { scoped } from 'di-scoped';
|
|
2
|
-
import { ToolRegistry, trycatch, singleshot, memoize, sleep, Subject, queued, not, randomString, createAwaiter, cancelable, CANCELED_PROMISE_SYMBOL, execpool, SortedArray, schedule, ttl, Source } from 'functools-kit';
|
|
2
|
+
import { ToolRegistry, trycatch, singleshot, memoize, sleep, Subject, queued, getErrorMessage, errorData, not, randomString, createAwaiter, cancelable, CANCELED_PROMISE_SYMBOL, execpool, SortedArray, schedule, ttl, Source } from 'functools-kit';
|
|
3
3
|
import { createActivator } from 'di-kit';
|
|
4
4
|
import { omit } from 'lodash-es';
|
|
5
5
|
import xml2js from 'xml2js';
|
|
@@ -444,6 +444,8 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
444
444
|
clientId: this.clientId,
|
|
445
445
|
agentName: agentName,
|
|
446
446
|
});
|
|
447
|
+
this.callbacks.onPush &&
|
|
448
|
+
this.callbacks.onPush(value, this.clientId, agentName);
|
|
447
449
|
this._array.push(value);
|
|
448
450
|
this.callbacks.onChange &&
|
|
449
451
|
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
@@ -688,7 +690,7 @@ var HistoryUtils = /** @class */ (function () {
|
|
|
688
690
|
*/
|
|
689
691
|
this.useHistoryCallbacks = function (Callbacks) {
|
|
690
692
|
swarm.loggerService.log("HistoryUtils useHistoryCallbacks");
|
|
691
|
-
_this.HistoryCallbacks
|
|
693
|
+
Object.assign(_this.HistoryCallbacks, Callbacks);
|
|
692
694
|
};
|
|
693
695
|
/**
|
|
694
696
|
* Push a new message to the history.
|
|
@@ -906,7 +908,7 @@ var setConfig = function (config) {
|
|
|
906
908
|
Object.assign(GLOBAL_CONFIG, config);
|
|
907
909
|
};
|
|
908
910
|
|
|
909
|
-
var AGENT_CHANGE_SYMBOL = Symbol(
|
|
911
|
+
var AGENT_CHANGE_SYMBOL = Symbol("agent-change");
|
|
910
912
|
var getPlaceholder = function () {
|
|
911
913
|
return GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS[Math.floor(Math.random() * GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS.length)];
|
|
912
914
|
};
|
|
@@ -1293,6 +1295,13 @@ var ClientAgent = /** @class */ (function () {
|
|
|
1293
1295
|
})
|
|
1294
1296
|
.catch(function (error) {
|
|
1295
1297
|
var _a, _b;
|
|
1298
|
+
console.error("agent-swarm tool call error functionName=".concat(tool.function.name, " error=").concat(getErrorMessage(error)), {
|
|
1299
|
+
clientId: _this.params.clientId,
|
|
1300
|
+
agentName: _this.params.agentName,
|
|
1301
|
+
tool_call_id: tool.id,
|
|
1302
|
+
arguments: tool.function.arguments,
|
|
1303
|
+
error: errorData(error),
|
|
1304
|
+
});
|
|
1296
1305
|
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onCallError) &&
|
|
1297
1306
|
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onCallError(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments, error));
|
|
1298
1307
|
_this._toolErrorSubject.next();
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -400,6 +400,13 @@ interface IHistoryInstanceCallbacks {
|
|
|
400
400
|
* @param agentName - The agent name.
|
|
401
401
|
*/
|
|
402
402
|
onChange: (data: IModelMessage[], clientId: string, agentName: AgentName) => void;
|
|
403
|
+
/**
|
|
404
|
+
* Callback for when the history get the new message
|
|
405
|
+
* @param data - The array of model messages.
|
|
406
|
+
* @param clientId - The client ID.
|
|
407
|
+
* @param agentName - The agent name.
|
|
408
|
+
*/
|
|
409
|
+
onPush: (data: IModelMessage, clientId: string, agentName: AgentName) => void;
|
|
403
410
|
/**
|
|
404
411
|
* Callback for when the history is read. Will be called for each message
|
|
405
412
|
* @param message - The model message.
|
|
@@ -726,35 +733,136 @@ interface IEmbeddingSchema {
|
|
|
726
733
|
type EmbeddingName = string;
|
|
727
734
|
|
|
728
735
|
type StorageId = string | number;
|
|
736
|
+
/**
|
|
737
|
+
* Interface representing the data stored in the storage.
|
|
738
|
+
*/
|
|
729
739
|
interface IStorageData {
|
|
730
740
|
id: StorageId;
|
|
731
741
|
}
|
|
742
|
+
/**
|
|
743
|
+
* Interface representing the schema of the storage.
|
|
744
|
+
* @template T - Type of the storage data.
|
|
745
|
+
*/
|
|
732
746
|
interface IStorageSchema<T extends IStorageData = IStorageData> {
|
|
747
|
+
/**
|
|
748
|
+
* Function to get data from the storage.
|
|
749
|
+
* @param clientId - The client ID.
|
|
750
|
+
* @param storageName - The name of the storage.
|
|
751
|
+
* @returns A promise that resolves to an array of storage data or an array of storage data.
|
|
752
|
+
*/
|
|
733
753
|
getData?: (clientId: string, storageName: StorageName) => Promise<T[]> | T[];
|
|
754
|
+
/**
|
|
755
|
+
* Function to create an index for an item.
|
|
756
|
+
* @param item - The item to index.
|
|
757
|
+
* @returns A promise that resolves to a string or a string.
|
|
758
|
+
*/
|
|
734
759
|
createIndex(item: T): Promise<string> | string;
|
|
760
|
+
/**
|
|
761
|
+
* The name of the embedding.
|
|
762
|
+
*/
|
|
735
763
|
embedding: EmbeddingName;
|
|
764
|
+
/**
|
|
765
|
+
* The name of the storage.
|
|
766
|
+
*/
|
|
736
767
|
storageName: StorageName;
|
|
768
|
+
/**
|
|
769
|
+
* Optional callbacks for storage events.
|
|
770
|
+
*/
|
|
737
771
|
callbacks?: Partial<IStorageCallbacks<T>>;
|
|
738
772
|
}
|
|
773
|
+
/**
|
|
774
|
+
* Interface representing the callbacks for storage events.
|
|
775
|
+
* @template T - Type of the storage data.
|
|
776
|
+
*/
|
|
739
777
|
interface IStorageCallbacks<T extends IStorageData = IStorageData> {
|
|
778
|
+
/**
|
|
779
|
+
* Callback function for update events.
|
|
780
|
+
* @param items - The updated items.
|
|
781
|
+
* @param clientId - The client ID.
|
|
782
|
+
* @param storageName - The name of the storage.
|
|
783
|
+
*/
|
|
740
784
|
onUpdate: (items: T[], clientId: string, storageName: StorageName) => void;
|
|
785
|
+
/**
|
|
786
|
+
* Callback function for search events.
|
|
787
|
+
* @param search - The search query.
|
|
788
|
+
* @param index - The sorted array of storage data.
|
|
789
|
+
* @param clientId - The client ID.
|
|
790
|
+
* @param storageName - The name of the storage.
|
|
791
|
+
*/
|
|
741
792
|
onSearch: (search: string, index: SortedArray<T>, clientId: string, storageName: StorageName) => void;
|
|
742
793
|
}
|
|
794
|
+
/**
|
|
795
|
+
* Interface representing the parameters for storage.
|
|
796
|
+
* @template T - Type of the storage data.
|
|
797
|
+
*/
|
|
743
798
|
interface IStorageParams<T extends IStorageData = IStorageData> extends IStorageSchema<T>, Partial<IEmbeddingCallbacks> {
|
|
799
|
+
/**
|
|
800
|
+
* The client ID.
|
|
801
|
+
*/
|
|
744
802
|
clientId: string;
|
|
803
|
+
/**
|
|
804
|
+
* Function to calculate similarity.
|
|
805
|
+
*/
|
|
745
806
|
calculateSimilarity: IEmbeddingSchema["calculateSimilarity"];
|
|
807
|
+
/**
|
|
808
|
+
* Function to create an embedding.
|
|
809
|
+
*/
|
|
746
810
|
createEmbedding: IEmbeddingSchema["createEmbedding"];
|
|
811
|
+
/**
|
|
812
|
+
* The name of the storage.
|
|
813
|
+
*/
|
|
747
814
|
storageName: StorageName;
|
|
815
|
+
/**
|
|
816
|
+
* Logger instance.
|
|
817
|
+
*/
|
|
748
818
|
logger: ILogger;
|
|
749
819
|
}
|
|
820
|
+
/**
|
|
821
|
+
* Interface representing the storage.
|
|
822
|
+
* @template T - Type of the storage data.
|
|
823
|
+
*/
|
|
750
824
|
interface IStorage<T extends IStorageData = IStorageData> {
|
|
825
|
+
/**
|
|
826
|
+
* Function to take items from the storage.
|
|
827
|
+
* @param search - The search query.
|
|
828
|
+
* @param total - The total number of items to take.
|
|
829
|
+
* @param score - Optional score parameter.
|
|
830
|
+
* @returns A promise that resolves to an array of storage data.
|
|
831
|
+
*/
|
|
751
832
|
take(search: string, total: number, score?: number): Promise<T[]>;
|
|
833
|
+
/**
|
|
834
|
+
* Function to upsert an item in the storage.
|
|
835
|
+
* @param item - The item to upsert.
|
|
836
|
+
* @returns A promise that resolves when the operation is complete.
|
|
837
|
+
*/
|
|
752
838
|
upsert(item: T): Promise<void>;
|
|
839
|
+
/**
|
|
840
|
+
* Function to remove an item from the storage.
|
|
841
|
+
* @param itemId - The ID of the item to remove.
|
|
842
|
+
* @returns A promise that resolves when the operation is complete.
|
|
843
|
+
*/
|
|
753
844
|
remove(itemId: IStorageData["id"]): Promise<void>;
|
|
845
|
+
/**
|
|
846
|
+
* Function to get an item from the storage.
|
|
847
|
+
* @param itemId - The ID of the item to get.
|
|
848
|
+
* @returns A promise that resolves to the item or null if not found.
|
|
849
|
+
*/
|
|
754
850
|
get(itemId: IStorageData["id"]): Promise<T | null>;
|
|
851
|
+
/**
|
|
852
|
+
* Function to list items from the storage.
|
|
853
|
+
* @param filter - Optional filter function.
|
|
854
|
+
* @returns A promise that resolves to an array of storage data.
|
|
855
|
+
*/
|
|
755
856
|
list(filter?: (item: T) => boolean): Promise<T[]>;
|
|
857
|
+
/**
|
|
858
|
+
* Function to clear the storage.
|
|
859
|
+
* @returns A promise that resolves when the operation is complete.
|
|
860
|
+
*/
|
|
756
861
|
clear(): Promise<void>;
|
|
757
862
|
}
|
|
863
|
+
/**
|
|
864
|
+
* Type representing the name of the storage.
|
|
865
|
+
*/
|
|
758
866
|
type StorageName = string;
|
|
759
867
|
|
|
760
868
|
/**
|