agent-swarm-kit 1.0.189 → 1.0.191
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 +153 -0
- package/build/index.mjs +153 -1
- package/package.json +1 -1
- package/types.d.ts +65 -1
package/build/index.cjs
CHANGED
|
@@ -16625,6 +16625,92 @@ const listenPolicyEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
16625
16625
|
return swarm$1.busService.once(clientId, "policy-bus", filterFn, functoolsKit.queued(async (e) => await fn(e)));
|
|
16626
16626
|
});
|
|
16627
16627
|
|
|
16628
|
+
/** @private Constant for logging the call method in RoundRobin */
|
|
16629
|
+
const METHOD_NAME_CALL = "RoundRobin.call";
|
|
16630
|
+
/** @private Constant for logging the create method in RoundRobin */
|
|
16631
|
+
const METHOD_NAME_CREATE = "RoundRobin.create";
|
|
16632
|
+
/**
|
|
16633
|
+
* A generic RoundRobin implementation that distributes calls across a set of tokens
|
|
16634
|
+
* using a factory function to create instances.
|
|
16635
|
+
* @template T The type of instances created by the factory
|
|
16636
|
+
* @template Token The type of tokens to cycle through
|
|
16637
|
+
* @template A The type of arguments passed to the factory (extends any[])
|
|
16638
|
+
*/
|
|
16639
|
+
class RoundRobin {
|
|
16640
|
+
/**
|
|
16641
|
+
* Creates a new RoundRobin instance
|
|
16642
|
+
* @private
|
|
16643
|
+
* @param tokens - Array of tokens to cycle through
|
|
16644
|
+
* @param factory - Function that creates instances given a token and arguments
|
|
16645
|
+
* @throws {Error} If the tokens array is empty
|
|
16646
|
+
*/
|
|
16647
|
+
constructor(tokens, factory) {
|
|
16648
|
+
if (tokens.length === 0) {
|
|
16649
|
+
throw new Error("agent-swarm RoundRobin cannot be created with an empty tokens array");
|
|
16650
|
+
}
|
|
16651
|
+
this.tokens = tokens;
|
|
16652
|
+
this.factory = factory;
|
|
16653
|
+
this.instances = new Map();
|
|
16654
|
+
this.currentIndex = 0;
|
|
16655
|
+
}
|
|
16656
|
+
/**
|
|
16657
|
+
* Creates a RoundRobin function that cycles through tokens
|
|
16658
|
+
* @template T The type of instances created by the factory
|
|
16659
|
+
* @template Token The type of tokens to cycle through
|
|
16660
|
+
* @template A The type of arguments passed to the factory
|
|
16661
|
+
* @param tokens - Array of tokens to cycle through
|
|
16662
|
+
* @param factory - Function that creates instances given a token and arguments
|
|
16663
|
+
* @returns A function that returns the next instance in the rotation
|
|
16664
|
+
* @throws {Error} If the tokens array is empty
|
|
16665
|
+
* @example
|
|
16666
|
+
* const rr = RoundRobin.create(['a', 'b'], (token) => ({ id: token }));
|
|
16667
|
+
* const instance1 = rr(); // { id: 'a' }
|
|
16668
|
+
* const instance2 = rr(); // { id: 'b' }
|
|
16669
|
+
* @example
|
|
16670
|
+
* const rr2 = RoundRobin.create<number[]>([[1], [2]], (token) => token[0]);
|
|
16671
|
+
* const num1 = rr2(); // 1
|
|
16672
|
+
* const num2 = rr2(); // 2
|
|
16673
|
+
*/
|
|
16674
|
+
static create(tokens, factory) {
|
|
16675
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16676
|
+
swarm$1.loggerService.log(METHOD_NAME_CREATE, {
|
|
16677
|
+
tokenCount: tokens.length,
|
|
16678
|
+
});
|
|
16679
|
+
const roundRobin = new RoundRobin(tokens.filter((value) => !!value), factory);
|
|
16680
|
+
return (...args) => roundRobin.call(...args);
|
|
16681
|
+
}
|
|
16682
|
+
/**
|
|
16683
|
+
* Gets the next instance in the rotation, creating it if necessary
|
|
16684
|
+
* @private
|
|
16685
|
+
* @param args - Arguments to pass to the factory function
|
|
16686
|
+
* @returns The next instance in the rotation
|
|
16687
|
+
*/
|
|
16688
|
+
call(...args) {
|
|
16689
|
+
// Log the call
|
|
16690
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16691
|
+
swarm$1.loggerService.log(METHOD_NAME_CALL, {
|
|
16692
|
+
currentIndex: this.currentIndex,
|
|
16693
|
+
tokenCount: this.tokens.length,
|
|
16694
|
+
});
|
|
16695
|
+
// Get the current token
|
|
16696
|
+
const token = this.tokens[this.currentIndex];
|
|
16697
|
+
// Generate a map key (strings and symbols can be used directly, objects are stringified)
|
|
16698
|
+
const key = typeof token === "object" && token !== null
|
|
16699
|
+
? JSON.stringify(token)
|
|
16700
|
+
: token;
|
|
16701
|
+
// Create instance if it doesn't exist
|
|
16702
|
+
if (!this.instances.has(key)) {
|
|
16703
|
+
const instance = this.factory(token, ...args);
|
|
16704
|
+
this.instances.set(key, instance);
|
|
16705
|
+
}
|
|
16706
|
+
// Get the instance
|
|
16707
|
+
const instance = this.instances.get(key);
|
|
16708
|
+
// Update index for next call
|
|
16709
|
+
this.currentIndex = (this.currentIndex + 1) % this.tokens.length;
|
|
16710
|
+
return instance;
|
|
16711
|
+
}
|
|
16712
|
+
}
|
|
16713
|
+
|
|
16628
16714
|
/** @private Constant for logging the getState method in StateUtils */
|
|
16629
16715
|
const METHOD_NAME_GET$3 = "StateUtils.getState";
|
|
16630
16716
|
/** @private Constant for logging the setState method in StateUtils */
|
|
@@ -17317,6 +17403,72 @@ const RETRY_DELAY = 5000;
|
|
|
17317
17403
|
*/
|
|
17318
17404
|
class AdapterUtils {
|
|
17319
17405
|
constructor() {
|
|
17406
|
+
/**
|
|
17407
|
+
* Creates a function to interact with CohereClientV2 chat completions API.
|
|
17408
|
+
* @param {any} openai - The CohereClientV2 client instance.
|
|
17409
|
+
* @param {string} [model="gpt-3.5-turbo"] - The model to use for completions (defaults to "gpt-3.5-turbo").
|
|
17410
|
+
* @param {{ type: string }} [response_format] - Optional response format configuration (e.g., `{ type: "json_object" }`).
|
|
17411
|
+
* @returns {TCompleteFn} A function that processes completion arguments and returns a response from CohereClientV2.
|
|
17412
|
+
*/
|
|
17413
|
+
this.fromCohereClientV2 = (cohere, model = "command-r-08-2024") =>
|
|
17414
|
+
/**
|
|
17415
|
+
* Handles a completion request to CohereClientV2, transforming messages and tools into the required format.
|
|
17416
|
+
* Executes requests in a pool to limit concurrency.
|
|
17417
|
+
* @param {ICompletionArgs} args - The arguments for the completion request.
|
|
17418
|
+
* @param {string} args.agentName - The name of the agent making the request.
|
|
17419
|
+
* @param {IModelMessage[]} args.messages - The array of messages to send to CohereClientV2.
|
|
17420
|
+
* @param {string} args.mode - The mode of the completion (e.g., "user" or "tool").
|
|
17421
|
+
* @param {any[]} args.tools - The tools available for the completion, if any.
|
|
17422
|
+
* @param {string} args.clientId - The ID of the client making the request.
|
|
17423
|
+
* @returns {Promise<IModelMessage>} The response from CohereClientV2 in `agent-swarm-kit` format.
|
|
17424
|
+
*/
|
|
17425
|
+
functoolsKit.execpool(functoolsKit.retry(async ({ agentName, messages: rawMessages, mode, tools: rawTools, clientId, }) => {
|
|
17426
|
+
LoggerAdapter.logClient(clientId, "AdapterUtils fromCohereClientV2 completion", JSON.stringify(rawMessages));
|
|
17427
|
+
const messages = rawMessages.map(({ role, tool_call_id, tool_calls, content }) => ({
|
|
17428
|
+
role: role,
|
|
17429
|
+
toolCallId: tool_call_id,
|
|
17430
|
+
content,
|
|
17431
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
17432
|
+
...rest,
|
|
17433
|
+
function: {
|
|
17434
|
+
name: f.name,
|
|
17435
|
+
arguments: JSON.stringify(f.arguments),
|
|
17436
|
+
},
|
|
17437
|
+
})),
|
|
17438
|
+
}));
|
|
17439
|
+
const tools = rawTools?.map(({ type, function: f }) => ({
|
|
17440
|
+
type: type,
|
|
17441
|
+
function: {
|
|
17442
|
+
name: f.name,
|
|
17443
|
+
parameters: f.parameters,
|
|
17444
|
+
},
|
|
17445
|
+
}));
|
|
17446
|
+
const { message: { content, role, toolCalls }, } = await cohere.chat({
|
|
17447
|
+
model,
|
|
17448
|
+
messages,
|
|
17449
|
+
tools,
|
|
17450
|
+
seed: 0,
|
|
17451
|
+
temperature: 0,
|
|
17452
|
+
});
|
|
17453
|
+
return {
|
|
17454
|
+
content: content ? content[0].text : "",
|
|
17455
|
+
mode,
|
|
17456
|
+
agentName,
|
|
17457
|
+
role,
|
|
17458
|
+
tool_calls: toolCalls?.map(({ function: f, ...rest }) => ({
|
|
17459
|
+
...rest,
|
|
17460
|
+
id: rest.id,
|
|
17461
|
+
type: rest.type,
|
|
17462
|
+
function: {
|
|
17463
|
+
name: f?.name,
|
|
17464
|
+
arguments: JSON.parse(f?.arguments),
|
|
17465
|
+
},
|
|
17466
|
+
})),
|
|
17467
|
+
};
|
|
17468
|
+
}, RETRY_COUNT, RETRY_DELAY), {
|
|
17469
|
+
maxExec: EXECPOOL_SIZE,
|
|
17470
|
+
delay: EXECPOOL_WAIT,
|
|
17471
|
+
});
|
|
17320
17472
|
/**
|
|
17321
17473
|
* Creates a function to interact with OpenAI's chat completions API.
|
|
17322
17474
|
* @param {any} openai - The OpenAI client instance.
|
|
@@ -17531,6 +17683,7 @@ exports.PersistState = PersistState;
|
|
|
17531
17683
|
exports.PersistStorage = PersistStorage;
|
|
17532
17684
|
exports.PersistSwarm = PersistSwarm;
|
|
17533
17685
|
exports.Policy = Policy;
|
|
17686
|
+
exports.RoundRobin = RoundRobin;
|
|
17534
17687
|
exports.Schema = Schema;
|
|
17535
17688
|
exports.SharedState = SharedState;
|
|
17536
17689
|
exports.SharedStorage = SharedStorage;
|
package/build/index.mjs
CHANGED
|
@@ -16623,6 +16623,92 @@ const listenPolicyEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
16623
16623
|
return swarm$1.busService.once(clientId, "policy-bus", filterFn, queued(async (e) => await fn(e)));
|
|
16624
16624
|
});
|
|
16625
16625
|
|
|
16626
|
+
/** @private Constant for logging the call method in RoundRobin */
|
|
16627
|
+
const METHOD_NAME_CALL = "RoundRobin.call";
|
|
16628
|
+
/** @private Constant for logging the create method in RoundRobin */
|
|
16629
|
+
const METHOD_NAME_CREATE = "RoundRobin.create";
|
|
16630
|
+
/**
|
|
16631
|
+
* A generic RoundRobin implementation that distributes calls across a set of tokens
|
|
16632
|
+
* using a factory function to create instances.
|
|
16633
|
+
* @template T The type of instances created by the factory
|
|
16634
|
+
* @template Token The type of tokens to cycle through
|
|
16635
|
+
* @template A The type of arguments passed to the factory (extends any[])
|
|
16636
|
+
*/
|
|
16637
|
+
class RoundRobin {
|
|
16638
|
+
/**
|
|
16639
|
+
* Creates a new RoundRobin instance
|
|
16640
|
+
* @private
|
|
16641
|
+
* @param tokens - Array of tokens to cycle through
|
|
16642
|
+
* @param factory - Function that creates instances given a token and arguments
|
|
16643
|
+
* @throws {Error} If the tokens array is empty
|
|
16644
|
+
*/
|
|
16645
|
+
constructor(tokens, factory) {
|
|
16646
|
+
if (tokens.length === 0) {
|
|
16647
|
+
throw new Error("agent-swarm RoundRobin cannot be created with an empty tokens array");
|
|
16648
|
+
}
|
|
16649
|
+
this.tokens = tokens;
|
|
16650
|
+
this.factory = factory;
|
|
16651
|
+
this.instances = new Map();
|
|
16652
|
+
this.currentIndex = 0;
|
|
16653
|
+
}
|
|
16654
|
+
/**
|
|
16655
|
+
* Creates a RoundRobin function that cycles through tokens
|
|
16656
|
+
* @template T The type of instances created by the factory
|
|
16657
|
+
* @template Token The type of tokens to cycle through
|
|
16658
|
+
* @template A The type of arguments passed to the factory
|
|
16659
|
+
* @param tokens - Array of tokens to cycle through
|
|
16660
|
+
* @param factory - Function that creates instances given a token and arguments
|
|
16661
|
+
* @returns A function that returns the next instance in the rotation
|
|
16662
|
+
* @throws {Error} If the tokens array is empty
|
|
16663
|
+
* @example
|
|
16664
|
+
* const rr = RoundRobin.create(['a', 'b'], (token) => ({ id: token }));
|
|
16665
|
+
* const instance1 = rr(); // { id: 'a' }
|
|
16666
|
+
* const instance2 = rr(); // { id: 'b' }
|
|
16667
|
+
* @example
|
|
16668
|
+
* const rr2 = RoundRobin.create<number[]>([[1], [2]], (token) => token[0]);
|
|
16669
|
+
* const num1 = rr2(); // 1
|
|
16670
|
+
* const num2 = rr2(); // 2
|
|
16671
|
+
*/
|
|
16672
|
+
static create(tokens, factory) {
|
|
16673
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16674
|
+
swarm$1.loggerService.log(METHOD_NAME_CREATE, {
|
|
16675
|
+
tokenCount: tokens.length,
|
|
16676
|
+
});
|
|
16677
|
+
const roundRobin = new RoundRobin(tokens.filter((value) => !!value), factory);
|
|
16678
|
+
return (...args) => roundRobin.call(...args);
|
|
16679
|
+
}
|
|
16680
|
+
/**
|
|
16681
|
+
* Gets the next instance in the rotation, creating it if necessary
|
|
16682
|
+
* @private
|
|
16683
|
+
* @param args - Arguments to pass to the factory function
|
|
16684
|
+
* @returns The next instance in the rotation
|
|
16685
|
+
*/
|
|
16686
|
+
call(...args) {
|
|
16687
|
+
// Log the call
|
|
16688
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16689
|
+
swarm$1.loggerService.log(METHOD_NAME_CALL, {
|
|
16690
|
+
currentIndex: this.currentIndex,
|
|
16691
|
+
tokenCount: this.tokens.length,
|
|
16692
|
+
});
|
|
16693
|
+
// Get the current token
|
|
16694
|
+
const token = this.tokens[this.currentIndex];
|
|
16695
|
+
// Generate a map key (strings and symbols can be used directly, objects are stringified)
|
|
16696
|
+
const key = typeof token === "object" && token !== null
|
|
16697
|
+
? JSON.stringify(token)
|
|
16698
|
+
: token;
|
|
16699
|
+
// Create instance if it doesn't exist
|
|
16700
|
+
if (!this.instances.has(key)) {
|
|
16701
|
+
const instance = this.factory(token, ...args);
|
|
16702
|
+
this.instances.set(key, instance);
|
|
16703
|
+
}
|
|
16704
|
+
// Get the instance
|
|
16705
|
+
const instance = this.instances.get(key);
|
|
16706
|
+
// Update index for next call
|
|
16707
|
+
this.currentIndex = (this.currentIndex + 1) % this.tokens.length;
|
|
16708
|
+
return instance;
|
|
16709
|
+
}
|
|
16710
|
+
}
|
|
16711
|
+
|
|
16626
16712
|
/** @private Constant for logging the getState method in StateUtils */
|
|
16627
16713
|
const METHOD_NAME_GET$3 = "StateUtils.getState";
|
|
16628
16714
|
/** @private Constant for logging the setState method in StateUtils */
|
|
@@ -17315,6 +17401,72 @@ const RETRY_DELAY = 5000;
|
|
|
17315
17401
|
*/
|
|
17316
17402
|
class AdapterUtils {
|
|
17317
17403
|
constructor() {
|
|
17404
|
+
/**
|
|
17405
|
+
* Creates a function to interact with CohereClientV2 chat completions API.
|
|
17406
|
+
* @param {any} openai - The CohereClientV2 client instance.
|
|
17407
|
+
* @param {string} [model="gpt-3.5-turbo"] - The model to use for completions (defaults to "gpt-3.5-turbo").
|
|
17408
|
+
* @param {{ type: string }} [response_format] - Optional response format configuration (e.g., `{ type: "json_object" }`).
|
|
17409
|
+
* @returns {TCompleteFn} A function that processes completion arguments and returns a response from CohereClientV2.
|
|
17410
|
+
*/
|
|
17411
|
+
this.fromCohereClientV2 = (cohere, model = "command-r-08-2024") =>
|
|
17412
|
+
/**
|
|
17413
|
+
* Handles a completion request to CohereClientV2, transforming messages and tools into the required format.
|
|
17414
|
+
* Executes requests in a pool to limit concurrency.
|
|
17415
|
+
* @param {ICompletionArgs} args - The arguments for the completion request.
|
|
17416
|
+
* @param {string} args.agentName - The name of the agent making the request.
|
|
17417
|
+
* @param {IModelMessage[]} args.messages - The array of messages to send to CohereClientV2.
|
|
17418
|
+
* @param {string} args.mode - The mode of the completion (e.g., "user" or "tool").
|
|
17419
|
+
* @param {any[]} args.tools - The tools available for the completion, if any.
|
|
17420
|
+
* @param {string} args.clientId - The ID of the client making the request.
|
|
17421
|
+
* @returns {Promise<IModelMessage>} The response from CohereClientV2 in `agent-swarm-kit` format.
|
|
17422
|
+
*/
|
|
17423
|
+
execpool(retry(async ({ agentName, messages: rawMessages, mode, tools: rawTools, clientId, }) => {
|
|
17424
|
+
LoggerAdapter.logClient(clientId, "AdapterUtils fromCohereClientV2 completion", JSON.stringify(rawMessages));
|
|
17425
|
+
const messages = rawMessages.map(({ role, tool_call_id, tool_calls, content }) => ({
|
|
17426
|
+
role: role,
|
|
17427
|
+
toolCallId: tool_call_id,
|
|
17428
|
+
content,
|
|
17429
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
17430
|
+
...rest,
|
|
17431
|
+
function: {
|
|
17432
|
+
name: f.name,
|
|
17433
|
+
arguments: JSON.stringify(f.arguments),
|
|
17434
|
+
},
|
|
17435
|
+
})),
|
|
17436
|
+
}));
|
|
17437
|
+
const tools = rawTools?.map(({ type, function: f }) => ({
|
|
17438
|
+
type: type,
|
|
17439
|
+
function: {
|
|
17440
|
+
name: f.name,
|
|
17441
|
+
parameters: f.parameters,
|
|
17442
|
+
},
|
|
17443
|
+
}));
|
|
17444
|
+
const { message: { content, role, toolCalls }, } = await cohere.chat({
|
|
17445
|
+
model,
|
|
17446
|
+
messages,
|
|
17447
|
+
tools,
|
|
17448
|
+
seed: 0,
|
|
17449
|
+
temperature: 0,
|
|
17450
|
+
});
|
|
17451
|
+
return {
|
|
17452
|
+
content: content ? content[0].text : "",
|
|
17453
|
+
mode,
|
|
17454
|
+
agentName,
|
|
17455
|
+
role,
|
|
17456
|
+
tool_calls: toolCalls?.map(({ function: f, ...rest }) => ({
|
|
17457
|
+
...rest,
|
|
17458
|
+
id: rest.id,
|
|
17459
|
+
type: rest.type,
|
|
17460
|
+
function: {
|
|
17461
|
+
name: f?.name,
|
|
17462
|
+
arguments: JSON.parse(f?.arguments),
|
|
17463
|
+
},
|
|
17464
|
+
})),
|
|
17465
|
+
};
|
|
17466
|
+
}, RETRY_COUNT, RETRY_DELAY), {
|
|
17467
|
+
maxExec: EXECPOOL_SIZE,
|
|
17468
|
+
delay: EXECPOOL_WAIT,
|
|
17469
|
+
});
|
|
17318
17470
|
/**
|
|
17319
17471
|
* Creates a function to interact with OpenAI's chat completions API.
|
|
17320
17472
|
* @param {any} openai - The OpenAI client instance.
|
|
@@ -17510,4 +17662,4 @@ const Utils = {
|
|
|
17510
17662
|
PersistEmbeddingUtils,
|
|
17511
17663
|
};
|
|
17512
17664
|
|
|
17513
|
-
export { Adapter, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, Schema, SharedState, SharedStorage, State, Storage, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, 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, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
|
|
17665
|
+
export { Adapter, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, RoundRobin, Schema, SharedState, SharedStorage, State, Storage, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, 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, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -10256,6 +10256,62 @@ interface IGlobalConfig {
|
|
|
10256
10256
|
declare const GLOBAL_CONFIG: IGlobalConfig;
|
|
10257
10257
|
declare const setConfig: (config: Partial<IGlobalConfig>) => void;
|
|
10258
10258
|
|
|
10259
|
+
/**
|
|
10260
|
+
* A generic RoundRobin implementation that distributes calls across a set of tokens
|
|
10261
|
+
* using a factory function to create instances.
|
|
10262
|
+
* @template T The type of instances created by the factory
|
|
10263
|
+
* @template Token The type of tokens to cycle through
|
|
10264
|
+
* @template A The type of arguments passed to the factory (extends any[])
|
|
10265
|
+
*/
|
|
10266
|
+
declare class RoundRobin<T, Token = string | symbol | {
|
|
10267
|
+
[key: string]: any;
|
|
10268
|
+
}, A extends any[] = any[]> {
|
|
10269
|
+
/** @private Array of tokens to cycle through */
|
|
10270
|
+
private tokens;
|
|
10271
|
+
/** @private Factory function that creates instances from tokens and arguments */
|
|
10272
|
+
private factory;
|
|
10273
|
+
/** @private Map storing created instances with string or symbol keys */
|
|
10274
|
+
private instances;
|
|
10275
|
+
/** @private Current index position in the token rotation */
|
|
10276
|
+
private currentIndex;
|
|
10277
|
+
/**
|
|
10278
|
+
* Creates a new RoundRobin instance
|
|
10279
|
+
* @private
|
|
10280
|
+
* @param tokens - Array of tokens to cycle through
|
|
10281
|
+
* @param factory - Function that creates instances given a token and arguments
|
|
10282
|
+
* @throws {Error} If the tokens array is empty
|
|
10283
|
+
*/
|
|
10284
|
+
private constructor();
|
|
10285
|
+
/**
|
|
10286
|
+
* Creates a RoundRobin function that cycles through tokens
|
|
10287
|
+
* @template T The type of instances created by the factory
|
|
10288
|
+
* @template Token The type of tokens to cycle through
|
|
10289
|
+
* @template A The type of arguments passed to the factory
|
|
10290
|
+
* @param tokens - Array of tokens to cycle through
|
|
10291
|
+
* @param factory - Function that creates instances given a token and arguments
|
|
10292
|
+
* @returns A function that returns the next instance in the rotation
|
|
10293
|
+
* @throws {Error} If the tokens array is empty
|
|
10294
|
+
* @example
|
|
10295
|
+
* const rr = RoundRobin.create(['a', 'b'], (token) => ({ id: token }));
|
|
10296
|
+
* const instance1 = rr(); // { id: 'a' }
|
|
10297
|
+
* const instance2 = rr(); // { id: 'b' }
|
|
10298
|
+
* @example
|
|
10299
|
+
* const rr2 = RoundRobin.create<number[]>([[1], [2]], (token) => token[0]);
|
|
10300
|
+
* const num1 = rr2(); // 1
|
|
10301
|
+
* const num2 = rr2(); // 2
|
|
10302
|
+
*/
|
|
10303
|
+
static create<T, Token = string | symbol | {
|
|
10304
|
+
[key: string]: any;
|
|
10305
|
+
}, A extends any[] = any[]>(tokens: Token[], factory: (token: Token, ...args: A) => T): (...args: A) => T;
|
|
10306
|
+
/**
|
|
10307
|
+
* Gets the next instance in the rotation, creating it if necessary
|
|
10308
|
+
* @private
|
|
10309
|
+
* @param args - Arguments to pass to the factory function
|
|
10310
|
+
* @returns The next instance in the rotation
|
|
10311
|
+
*/
|
|
10312
|
+
private call;
|
|
10313
|
+
}
|
|
10314
|
+
|
|
10259
10315
|
/**
|
|
10260
10316
|
* Utility class providing methods to manage client bans within a swarm policy context.
|
|
10261
10317
|
* All methods validate inputs and execute within a context for logging and tracking.
|
|
@@ -10712,6 +10768,14 @@ type TCompleteFn = (args: ICompletionArgs) => Promise<IModelMessage>;
|
|
|
10712
10768
|
* Utility class providing adapter functions for interacting with various AI completion providers.
|
|
10713
10769
|
*/
|
|
10714
10770
|
declare class AdapterUtils {
|
|
10771
|
+
/**
|
|
10772
|
+
* Creates a function to interact with CohereClientV2 chat completions API.
|
|
10773
|
+
* @param {any} openai - The CohereClientV2 client instance.
|
|
10774
|
+
* @param {string} [model="gpt-3.5-turbo"] - The model to use for completions (defaults to "gpt-3.5-turbo").
|
|
10775
|
+
* @param {{ type: string }} [response_format] - Optional response format configuration (e.g., `{ type: "json_object" }`).
|
|
10776
|
+
* @returns {TCompleteFn} A function that processes completion arguments and returns a response from CohereClientV2.
|
|
10777
|
+
*/
|
|
10778
|
+
fromCohereClientV2: (cohere: any, model?: string) => TCompleteFn;
|
|
10715
10779
|
/**
|
|
10716
10780
|
* Creates a function to interact with OpenAI's chat completions API.
|
|
10717
10781
|
* @param {any} openai - The OpenAI client instance.
|
|
@@ -10796,4 +10860,4 @@ declare const Utils: {
|
|
|
10796
10860
|
PersistEmbeddingUtils: typeof PersistEmbeddingUtils;
|
|
10797
10861
|
};
|
|
10798
10862
|
|
|
10799
|
-
export { Adapter, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, 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, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, Schema, type SendMessageFn, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, 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, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
|
|
10863
|
+
export { Adapter, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, 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, Logger, LoggerInstance, MethodContextService, 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, Utils, addAgent, addCompletion, addEmbedding, addPolicy, addState, addStorage, addSwarm, addTool, 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, getPayload, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, runStateless, runStatelessForce, session, setConfig, swarm };
|