agent-swarm-kit 1.0.235 → 1.0.237
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 +26 -5
- package/build/index.mjs +26 -5
- package/package.json +1 -1
- package/types.d.ts +16 -1
package/build/index.cjs
CHANGED
|
@@ -2763,6 +2763,8 @@ const Logger = LoggerAdapter;
|
|
|
2763
2763
|
const OPERATOR_INSTANCE_METHOD_NAME_CTOR = "OperatorInstance.CTOR";
|
|
2764
2764
|
/** @private Constant for logging the connectAnswer method in OperatorInstance */
|
|
2765
2765
|
const OPERATOR_INSTANCE_METHOD_NAME_CONNECT_ANSWER = "OperatorInstance.connectAnswer";
|
|
2766
|
+
/** @private Constant for logging the init method in OperatorInstance */
|
|
2767
|
+
const OPERATOR_INSTANCE_METHOD_NAME_INIT = "OperatorInstance.init";
|
|
2766
2768
|
/** @private Constant for logging the notify method in OperatorInstance */
|
|
2767
2769
|
const OPERATOR_INSTANCE_METHOD_NAME_NOTIFY = "OperatorInstance.notify";
|
|
2768
2770
|
/** @private Constant for logging the answer method in OperatorInstance */
|
|
@@ -2806,9 +2808,6 @@ const OperatorInstance = functoolsKit.makeExtendable(class {
|
|
|
2806
2808
|
clientId: this.clientId,
|
|
2807
2809
|
agentName,
|
|
2808
2810
|
});
|
|
2809
|
-
if (this.callbacks.onInit) {
|
|
2810
|
-
this.callbacks.onInit(clientId, agentName);
|
|
2811
|
-
}
|
|
2812
2811
|
}
|
|
2813
2812
|
/**
|
|
2814
2813
|
* Connects an answer subscription
|
|
@@ -2823,6 +2822,20 @@ const OperatorInstance = functoolsKit.makeExtendable(class {
|
|
|
2823
2822
|
this._answerSubject.unsubscribeAll();
|
|
2824
2823
|
this._answerSubject.subscribe(next);
|
|
2825
2824
|
}
|
|
2825
|
+
/**
|
|
2826
|
+
* Init the operator connection
|
|
2827
|
+
* @returns {Promise<void>}
|
|
2828
|
+
*/
|
|
2829
|
+
async init() {
|
|
2830
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2831
|
+
swarm$1.loggerService.debug(OPERATOR_INSTANCE_METHOD_NAME_INIT, {
|
|
2832
|
+
clientId: this.clientId,
|
|
2833
|
+
agentName: this.agentName,
|
|
2834
|
+
});
|
|
2835
|
+
if (this.callbacks.onInit) {
|
|
2836
|
+
this.callbacks.onInit(this.clientId, this.agentName);
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2826
2839
|
/**
|
|
2827
2840
|
* Sends a notification
|
|
2828
2841
|
* @param {string} content - Notification content
|
|
@@ -2945,7 +2958,9 @@ class OperatorUtils {
|
|
|
2945
2958
|
clientId,
|
|
2946
2959
|
agentName,
|
|
2947
2960
|
});
|
|
2961
|
+
const isInitial = this.getOperator.has(`${clientId}-${agentName}`);
|
|
2948
2962
|
const operator = this.getOperator(clientId, agentName);
|
|
2963
|
+
isInitial && operator.init();
|
|
2949
2964
|
return (message, next) => {
|
|
2950
2965
|
operator.connectAnswer(next);
|
|
2951
2966
|
operator.recieveMessage(message);
|
|
@@ -3059,6 +3074,10 @@ const CC_DEFAULT_WRITE_EMBEDDING_CACHE = (embeddings, embeddingName, stringHash)
|
|
|
3059
3074
|
* @returns {(message: string, next: (answer: string) => void) => DisposeFn}
|
|
3060
3075
|
*/
|
|
3061
3076
|
const CC_DEFAULT_CONNECT_OPERATOR = (clientId, agentName) => OperatorAdapter.connectOperator(clientId, agentName);
|
|
3077
|
+
/**
|
|
3078
|
+
* Flag to enable operator timeout, used in `ClientOperator` for message processing.
|
|
3079
|
+
*/
|
|
3080
|
+
const CC_ENABLE_OPERATOR_TIMEOUT = false;
|
|
3062
3081
|
const GLOBAL_CONFIG = {
|
|
3063
3082
|
CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
|
|
3064
3083
|
CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
|
|
@@ -3108,6 +3127,7 @@ const GLOBAL_CONFIG = {
|
|
|
3108
3127
|
CC_DEFAULT_AGENT_TOOL_VALIDATE,
|
|
3109
3128
|
CC_THROW_WHEN_NAVIGATION_RECURSION,
|
|
3110
3129
|
CC_DEFAULT_CONNECT_OPERATOR,
|
|
3130
|
+
CC_ENABLE_OPERATOR_TIMEOUT,
|
|
3111
3131
|
};
|
|
3112
3132
|
GLOBAL_CONFIG.CC_RESQUE_STRATEGY = "flush";
|
|
3113
3133
|
/**
|
|
@@ -4418,6 +4438,9 @@ class ClientOperator {
|
|
|
4418
4438
|
async waitForOutput() {
|
|
4419
4439
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4420
4440
|
this.params.logger.debug(`ClientOperator agentName=${this.params.agentName} clientId=${this.params.clientId} waitForOutput begin`);
|
|
4441
|
+
if (!GLOBAL_CONFIG.CC_ENABLE_OPERATOR_TIMEOUT) {
|
|
4442
|
+
return await this._outgoingSubject.toPromise();
|
|
4443
|
+
}
|
|
4421
4444
|
const result = await Promise.race([
|
|
4422
4445
|
this._outgoingSubject.toPromise(),
|
|
4423
4446
|
functoolsKit.sleep(OPERATOR_SIGNAL_TIMEOUT).then(() => OPERATOR_SIGNAL_SYMBOL),
|
|
@@ -4428,8 +4451,6 @@ class ClientOperator {
|
|
|
4428
4451
|
await this._operatorSignal.dispose();
|
|
4429
4452
|
return "";
|
|
4430
4453
|
}
|
|
4431
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4432
|
-
this.params.logger.debug(`ClientOperator agentName=${this.params.agentName} clientId=${this.params.clientId} waitForOutput end`, { result });
|
|
4433
4454
|
return result;
|
|
4434
4455
|
}
|
|
4435
4456
|
/**
|
package/build/index.mjs
CHANGED
|
@@ -2761,6 +2761,8 @@ const Logger = LoggerAdapter;
|
|
|
2761
2761
|
const OPERATOR_INSTANCE_METHOD_NAME_CTOR = "OperatorInstance.CTOR";
|
|
2762
2762
|
/** @private Constant for logging the connectAnswer method in OperatorInstance */
|
|
2763
2763
|
const OPERATOR_INSTANCE_METHOD_NAME_CONNECT_ANSWER = "OperatorInstance.connectAnswer";
|
|
2764
|
+
/** @private Constant for logging the init method in OperatorInstance */
|
|
2765
|
+
const OPERATOR_INSTANCE_METHOD_NAME_INIT = "OperatorInstance.init";
|
|
2764
2766
|
/** @private Constant for logging the notify method in OperatorInstance */
|
|
2765
2767
|
const OPERATOR_INSTANCE_METHOD_NAME_NOTIFY = "OperatorInstance.notify";
|
|
2766
2768
|
/** @private Constant for logging the answer method in OperatorInstance */
|
|
@@ -2804,9 +2806,6 @@ const OperatorInstance = makeExtendable(class {
|
|
|
2804
2806
|
clientId: this.clientId,
|
|
2805
2807
|
agentName,
|
|
2806
2808
|
});
|
|
2807
|
-
if (this.callbacks.onInit) {
|
|
2808
|
-
this.callbacks.onInit(clientId, agentName);
|
|
2809
|
-
}
|
|
2810
2809
|
}
|
|
2811
2810
|
/**
|
|
2812
2811
|
* Connects an answer subscription
|
|
@@ -2821,6 +2820,20 @@ const OperatorInstance = makeExtendable(class {
|
|
|
2821
2820
|
this._answerSubject.unsubscribeAll();
|
|
2822
2821
|
this._answerSubject.subscribe(next);
|
|
2823
2822
|
}
|
|
2823
|
+
/**
|
|
2824
|
+
* Init the operator connection
|
|
2825
|
+
* @returns {Promise<void>}
|
|
2826
|
+
*/
|
|
2827
|
+
async init() {
|
|
2828
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2829
|
+
swarm$1.loggerService.debug(OPERATOR_INSTANCE_METHOD_NAME_INIT, {
|
|
2830
|
+
clientId: this.clientId,
|
|
2831
|
+
agentName: this.agentName,
|
|
2832
|
+
});
|
|
2833
|
+
if (this.callbacks.onInit) {
|
|
2834
|
+
this.callbacks.onInit(this.clientId, this.agentName);
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2824
2837
|
/**
|
|
2825
2838
|
* Sends a notification
|
|
2826
2839
|
* @param {string} content - Notification content
|
|
@@ -2943,7 +2956,9 @@ class OperatorUtils {
|
|
|
2943
2956
|
clientId,
|
|
2944
2957
|
agentName,
|
|
2945
2958
|
});
|
|
2959
|
+
const isInitial = this.getOperator.has(`${clientId}-${agentName}`);
|
|
2946
2960
|
const operator = this.getOperator(clientId, agentName);
|
|
2961
|
+
isInitial && operator.init();
|
|
2947
2962
|
return (message, next) => {
|
|
2948
2963
|
operator.connectAnswer(next);
|
|
2949
2964
|
operator.recieveMessage(message);
|
|
@@ -3057,6 +3072,10 @@ const CC_DEFAULT_WRITE_EMBEDDING_CACHE = (embeddings, embeddingName, stringHash)
|
|
|
3057
3072
|
* @returns {(message: string, next: (answer: string) => void) => DisposeFn}
|
|
3058
3073
|
*/
|
|
3059
3074
|
const CC_DEFAULT_CONNECT_OPERATOR = (clientId, agentName) => OperatorAdapter.connectOperator(clientId, agentName);
|
|
3075
|
+
/**
|
|
3076
|
+
* Flag to enable operator timeout, used in `ClientOperator` for message processing.
|
|
3077
|
+
*/
|
|
3078
|
+
const CC_ENABLE_OPERATOR_TIMEOUT = false;
|
|
3060
3079
|
const GLOBAL_CONFIG = {
|
|
3061
3080
|
CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
|
|
3062
3081
|
CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
|
|
@@ -3106,6 +3125,7 @@ const GLOBAL_CONFIG = {
|
|
|
3106
3125
|
CC_DEFAULT_AGENT_TOOL_VALIDATE,
|
|
3107
3126
|
CC_THROW_WHEN_NAVIGATION_RECURSION,
|
|
3108
3127
|
CC_DEFAULT_CONNECT_OPERATOR,
|
|
3128
|
+
CC_ENABLE_OPERATOR_TIMEOUT,
|
|
3109
3129
|
};
|
|
3110
3130
|
GLOBAL_CONFIG.CC_RESQUE_STRATEGY = "flush";
|
|
3111
3131
|
/**
|
|
@@ -4416,6 +4436,9 @@ class ClientOperator {
|
|
|
4416
4436
|
async waitForOutput() {
|
|
4417
4437
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4418
4438
|
this.params.logger.debug(`ClientOperator agentName=${this.params.agentName} clientId=${this.params.clientId} waitForOutput begin`);
|
|
4439
|
+
if (!GLOBAL_CONFIG.CC_ENABLE_OPERATOR_TIMEOUT) {
|
|
4440
|
+
return await this._outgoingSubject.toPromise();
|
|
4441
|
+
}
|
|
4419
4442
|
const result = await Promise.race([
|
|
4420
4443
|
this._outgoingSubject.toPromise(),
|
|
4421
4444
|
sleep(OPERATOR_SIGNAL_TIMEOUT).then(() => OPERATOR_SIGNAL_SYMBOL),
|
|
@@ -4426,8 +4449,6 @@ class ClientOperator {
|
|
|
4426
4449
|
await this._operatorSignal.dispose();
|
|
4427
4450
|
return "";
|
|
4428
4451
|
}
|
|
4429
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4430
|
-
this.params.logger.debug(`ClientOperator agentName=${this.params.agentName} clientId=${this.params.clientId} waitForOutput end`, { result });
|
|
4431
4452
|
return result;
|
|
4432
4453
|
}
|
|
4433
4454
|
/**
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -11008,6 +11008,10 @@ interface IGlobalConfig {
|
|
|
11008
11008
|
* and answers to be received via a callback mechanism.
|
|
11009
11009
|
*/
|
|
11010
11010
|
CC_DEFAULT_CONNECT_OPERATOR: (clientId: string, agentName: AgentName) => (message: string, next: (answer: string) => void) => DisposeFn$1;
|
|
11011
|
+
/**
|
|
11012
|
+
* Flag to enable operator timeout, used in `ClientOperator` for message processing.
|
|
11013
|
+
*/
|
|
11014
|
+
CC_ENABLE_OPERATOR_TIMEOUT: boolean;
|
|
11011
11015
|
}
|
|
11012
11016
|
|
|
11013
11017
|
declare const GLOBAL_CONFIG: IGlobalConfig;
|
|
@@ -11045,6 +11049,8 @@ interface IOperatorInstance {
|
|
|
11045
11049
|
connectAnswer(next: (answer: string) => void): void;
|
|
11046
11050
|
/** Sends an answer */
|
|
11047
11051
|
answer(content: string): Promise<void>;
|
|
11052
|
+
/** Init the connection */
|
|
11053
|
+
init(): Promise<void>;
|
|
11048
11054
|
/** Sends a notification */
|
|
11049
11055
|
notify(content: string): Promise<void>;
|
|
11050
11056
|
/** Receives a message */
|
|
@@ -11078,6 +11084,11 @@ declare const OperatorInstance: {
|
|
|
11078
11084
|
* @param {(answer: string) => void} next - Answer handler callback
|
|
11079
11085
|
*/
|
|
11080
11086
|
connectAnswer(next: (answer: string) => void): void;
|
|
11087
|
+
/**
|
|
11088
|
+
* Init the operator connection
|
|
11089
|
+
* @returns {Promise<void>}
|
|
11090
|
+
*/
|
|
11091
|
+
init(): Promise<void>;
|
|
11081
11092
|
/**
|
|
11082
11093
|
* Sends a notification
|
|
11083
11094
|
* @param {string} content - Notification content
|
|
@@ -11103,6 +11114,10 @@ declare const OperatorInstance: {
|
|
|
11103
11114
|
dispose(): Promise<void>;
|
|
11104
11115
|
};
|
|
11105
11116
|
};
|
|
11117
|
+
/**
|
|
11118
|
+
* Type alias for an instance of OperatorInstance.
|
|
11119
|
+
*/
|
|
11120
|
+
type TOperatorInstance = InstanceType<typeof OperatorInstance>;
|
|
11106
11121
|
/**
|
|
11107
11122
|
* Operator control interface
|
|
11108
11123
|
* @interface IOperatorControl
|
|
@@ -11882,4 +11897,4 @@ declare const Utils: {
|
|
|
11882
11897
|
PersistEmbeddingUtils: typeof PersistEmbeddingUtils;
|
|
11883
11898
|
};
|
|
11884
11899
|
|
|
11885
|
-
export { Adapter, Chat, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type IChatArgs, type IChatInstance, type IChatInstanceCallbacks, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, type IWikiSchema, Logger, LoggerInstance, MethodContextService, Operator, OperatorInstance, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, type SendMessageFn, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, type ToolValue, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, addWiki, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getNavigationRoute, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, hasNavigation, hasSession, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, notify, notifyForce, question, questionForce, runStateless, runStatelessForce, session, setConfig, swarm };
|
|
11900
|
+
export { Adapter, Chat, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type IChatArgs, type IChatInstance, type IChatInstanceCallbacks, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, type IWikiSchema, Logger, LoggerInstance, MethodContextService, Operator, OperatorInstance, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, type SendMessageFn, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TOperatorInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, type ToolValue, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, addWiki, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getNavigationRoute, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, hasNavigation, hasSession, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, notify, notifyForce, question, questionForce, runStateless, runStatelessForce, session, setConfig, swarm };
|