agent-swarm-kit 1.0.127 → 1.0.130
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 +81 -1
- package/build/index.mjs +81 -2
- package/package.json +1 -1
- package/types.d.ts +26 -1
package/build/index.cjs
CHANGED
|
@@ -1484,7 +1484,7 @@ var CC_AGENT_HISTORY_FILTER = function (agentName) {
|
|
|
1484
1484
|
};
|
|
1485
1485
|
};
|
|
1486
1486
|
var CC_AGENT_OUTPUT_TRANSFORM = removeXmlTags;
|
|
1487
|
-
var CC_KEEP_MESSAGES =
|
|
1487
|
+
var CC_KEEP_MESSAGES = 25;
|
|
1488
1488
|
var CC_GET_AGENT_HISTORY_ADAPTER = function () { return HistoryAdapter; };
|
|
1489
1489
|
var CC_GET_CLIENT_LOGGER_ADAPTER = function () { return LoggerAdapter; };
|
|
1490
1490
|
var CC_AGENT_OUTPUT_MAP = function (message) { return message; };
|
|
@@ -15596,6 +15596,86 @@ var SchemaUtils = /** @class */ (function () {
|
|
|
15596
15596
|
*/
|
|
15597
15597
|
var Schema = new SchemaUtils();
|
|
15598
15598
|
|
|
15599
|
+
var AdapterUtils = /** @class */ (function () {
|
|
15600
|
+
function AdapterUtils() {
|
|
15601
|
+
var _this = this;
|
|
15602
|
+
/**
|
|
15603
|
+
* Creates a function to interact with OpenAI's chat completions.
|
|
15604
|
+
*
|
|
15605
|
+
* @param {any} openai - The OpenAI instance.
|
|
15606
|
+
* @param {string} [model="gpt-3.5-turbo"] - The model to use for completions.
|
|
15607
|
+
* @returns {Function} - A function that takes completion arguments and returns a response from OpenAI.
|
|
15608
|
+
*/
|
|
15609
|
+
this.fromOpenAI = function (openai, model, response_format) {
|
|
15610
|
+
if (model === void 0) { model = "gpt-3.5-turbo"; }
|
|
15611
|
+
/**
|
|
15612
|
+
* Handles the completion request to OpenAI.
|
|
15613
|
+
*
|
|
15614
|
+
* @param {ICompletionArgs} args - The arguments for the completion request.
|
|
15615
|
+
* @param {string} args.agentName - The name of the agent.
|
|
15616
|
+
* @param {Array} args.messages - The messages to send to OpenAI.
|
|
15617
|
+
* @param {string} args.mode - The mode of the completion.
|
|
15618
|
+
* @param {Array} args.tools - The tools to use for the completion.
|
|
15619
|
+
* @param {string} args.clientId - The client ID.
|
|
15620
|
+
* @returns {Promise<Object>} - The response from OpenAI.
|
|
15621
|
+
*/
|
|
15622
|
+
return function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
15623
|
+
var messages, _c, _d, content, role, tool_calls;
|
|
15624
|
+
var agentName = _b.agentName, rawMessages = _b.messages, mode = _b.mode, tools = _b.tools, clientId = _b.clientId;
|
|
15625
|
+
return __generator(this, function (_e) {
|
|
15626
|
+
switch (_e.label) {
|
|
15627
|
+
case 0:
|
|
15628
|
+
LoggerAdapter.logClient(clientId, "AdapterUtils history", JSON.stringify(rawMessages));
|
|
15629
|
+
messages = rawMessages.map(function (_a) {
|
|
15630
|
+
var role = _a.role, tool_call_id = _a.tool_call_id, tool_calls = _a.tool_calls, content = _a.content;
|
|
15631
|
+
return ({
|
|
15632
|
+
role: role,
|
|
15633
|
+
tool_call_id: tool_call_id,
|
|
15634
|
+
content: content,
|
|
15635
|
+
tool_calls: tool_calls === null || tool_calls === void 0 ? void 0 : tool_calls.map(function (_a) {
|
|
15636
|
+
var f = _a.function, rest = __rest(_a, ["function"]);
|
|
15637
|
+
return (__assign(__assign({}, rest), { function: {
|
|
15638
|
+
name: f.name,
|
|
15639
|
+
arguments: JSON.stringify(f.arguments),
|
|
15640
|
+
} }));
|
|
15641
|
+
}),
|
|
15642
|
+
});
|
|
15643
|
+
});
|
|
15644
|
+
return [4 /*yield*/, openai.chat.completions.create({
|
|
15645
|
+
model: model,
|
|
15646
|
+
messages: messages,
|
|
15647
|
+
tools: tools,
|
|
15648
|
+
response_format: response_format,
|
|
15649
|
+
})];
|
|
15650
|
+
case 1:
|
|
15651
|
+
_c = __read.apply(void 0, [(_e.sent()).choices, 1]), _d = _c[0].message, content = _d.content, role = _d.role, tool_calls = _d.tool_calls;
|
|
15652
|
+
return [2 /*return*/, {
|
|
15653
|
+
content: content,
|
|
15654
|
+
mode: mode,
|
|
15655
|
+
agentName: agentName,
|
|
15656
|
+
role: role,
|
|
15657
|
+
tool_calls: tool_calls === null || tool_calls === void 0 ? void 0 : tool_calls.map(function (_a) {
|
|
15658
|
+
var f = _a.function, rest = __rest(_a, ["function"]);
|
|
15659
|
+
return (__assign(__assign({}, rest), { function: {
|
|
15660
|
+
name: f.name,
|
|
15661
|
+
arguments: JSON.parse(f.arguments),
|
|
15662
|
+
} }));
|
|
15663
|
+
}),
|
|
15664
|
+
}];
|
|
15665
|
+
}
|
|
15666
|
+
});
|
|
15667
|
+
}); };
|
|
15668
|
+
};
|
|
15669
|
+
}
|
|
15670
|
+
return AdapterUtils;
|
|
15671
|
+
}());
|
|
15672
|
+
/**
|
|
15673
|
+
* An instance of AdapterUtils.
|
|
15674
|
+
* @type {AdapterUtils}
|
|
15675
|
+
*/
|
|
15676
|
+
var Adapter = new AdapterUtils();
|
|
15677
|
+
|
|
15678
|
+
exports.Adapter = Adapter;
|
|
15599
15679
|
exports.ExecutionContextService = ExecutionContextService;
|
|
15600
15680
|
exports.History = History;
|
|
15601
15681
|
exports.HistoryAdapter = HistoryAdapter;
|
package/build/index.mjs
CHANGED
|
@@ -1482,7 +1482,7 @@ var CC_AGENT_HISTORY_FILTER = function (agentName) {
|
|
|
1482
1482
|
};
|
|
1483
1483
|
};
|
|
1484
1484
|
var CC_AGENT_OUTPUT_TRANSFORM = removeXmlTags;
|
|
1485
|
-
var CC_KEEP_MESSAGES =
|
|
1485
|
+
var CC_KEEP_MESSAGES = 25;
|
|
1486
1486
|
var CC_GET_AGENT_HISTORY_ADAPTER = function () { return HistoryAdapter; };
|
|
1487
1487
|
var CC_GET_CLIENT_LOGGER_ADAPTER = function () { return LoggerAdapter; };
|
|
1488
1488
|
var CC_AGENT_OUTPUT_MAP = function (message) { return message; };
|
|
@@ -15594,4 +15594,83 @@ var SchemaUtils = /** @class */ (function () {
|
|
|
15594
15594
|
*/
|
|
15595
15595
|
var Schema = new SchemaUtils();
|
|
15596
15596
|
|
|
15597
|
-
|
|
15597
|
+
var AdapterUtils = /** @class */ (function () {
|
|
15598
|
+
function AdapterUtils() {
|
|
15599
|
+
var _this = this;
|
|
15600
|
+
/**
|
|
15601
|
+
* Creates a function to interact with OpenAI's chat completions.
|
|
15602
|
+
*
|
|
15603
|
+
* @param {any} openai - The OpenAI instance.
|
|
15604
|
+
* @param {string} [model="gpt-3.5-turbo"] - The model to use for completions.
|
|
15605
|
+
* @returns {Function} - A function that takes completion arguments and returns a response from OpenAI.
|
|
15606
|
+
*/
|
|
15607
|
+
this.fromOpenAI = function (openai, model, response_format) {
|
|
15608
|
+
if (model === void 0) { model = "gpt-3.5-turbo"; }
|
|
15609
|
+
/**
|
|
15610
|
+
* Handles the completion request to OpenAI.
|
|
15611
|
+
*
|
|
15612
|
+
* @param {ICompletionArgs} args - The arguments for the completion request.
|
|
15613
|
+
* @param {string} args.agentName - The name of the agent.
|
|
15614
|
+
* @param {Array} args.messages - The messages to send to OpenAI.
|
|
15615
|
+
* @param {string} args.mode - The mode of the completion.
|
|
15616
|
+
* @param {Array} args.tools - The tools to use for the completion.
|
|
15617
|
+
* @param {string} args.clientId - The client ID.
|
|
15618
|
+
* @returns {Promise<Object>} - The response from OpenAI.
|
|
15619
|
+
*/
|
|
15620
|
+
return function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
15621
|
+
var messages, _c, _d, content, role, tool_calls;
|
|
15622
|
+
var agentName = _b.agentName, rawMessages = _b.messages, mode = _b.mode, tools = _b.tools, clientId = _b.clientId;
|
|
15623
|
+
return __generator(this, function (_e) {
|
|
15624
|
+
switch (_e.label) {
|
|
15625
|
+
case 0:
|
|
15626
|
+
LoggerAdapter.logClient(clientId, "AdapterUtils history", JSON.stringify(rawMessages));
|
|
15627
|
+
messages = rawMessages.map(function (_a) {
|
|
15628
|
+
var role = _a.role, tool_call_id = _a.tool_call_id, tool_calls = _a.tool_calls, content = _a.content;
|
|
15629
|
+
return ({
|
|
15630
|
+
role: role,
|
|
15631
|
+
tool_call_id: tool_call_id,
|
|
15632
|
+
content: content,
|
|
15633
|
+
tool_calls: tool_calls === null || tool_calls === void 0 ? void 0 : tool_calls.map(function (_a) {
|
|
15634
|
+
var f = _a.function, rest = __rest(_a, ["function"]);
|
|
15635
|
+
return (__assign(__assign({}, rest), { function: {
|
|
15636
|
+
name: f.name,
|
|
15637
|
+
arguments: JSON.stringify(f.arguments),
|
|
15638
|
+
} }));
|
|
15639
|
+
}),
|
|
15640
|
+
});
|
|
15641
|
+
});
|
|
15642
|
+
return [4 /*yield*/, openai.chat.completions.create({
|
|
15643
|
+
model: model,
|
|
15644
|
+
messages: messages,
|
|
15645
|
+
tools: tools,
|
|
15646
|
+
response_format: response_format,
|
|
15647
|
+
})];
|
|
15648
|
+
case 1:
|
|
15649
|
+
_c = __read.apply(void 0, [(_e.sent()).choices, 1]), _d = _c[0].message, content = _d.content, role = _d.role, tool_calls = _d.tool_calls;
|
|
15650
|
+
return [2 /*return*/, {
|
|
15651
|
+
content: content,
|
|
15652
|
+
mode: mode,
|
|
15653
|
+
agentName: agentName,
|
|
15654
|
+
role: role,
|
|
15655
|
+
tool_calls: tool_calls === null || tool_calls === void 0 ? void 0 : tool_calls.map(function (_a) {
|
|
15656
|
+
var f = _a.function, rest = __rest(_a, ["function"]);
|
|
15657
|
+
return (__assign(__assign({}, rest), { function: {
|
|
15658
|
+
name: f.name,
|
|
15659
|
+
arguments: JSON.parse(f.arguments),
|
|
15660
|
+
} }));
|
|
15661
|
+
}),
|
|
15662
|
+
}];
|
|
15663
|
+
}
|
|
15664
|
+
});
|
|
15665
|
+
}); };
|
|
15666
|
+
};
|
|
15667
|
+
}
|
|
15668
|
+
return AdapterUtils;
|
|
15669
|
+
}());
|
|
15670
|
+
/**
|
|
15671
|
+
* An instance of AdapterUtils.
|
|
15672
|
+
* @type {AdapterUtils}
|
|
15673
|
+
*/
|
|
15674
|
+
var Adapter = new AdapterUtils();
|
|
15675
|
+
|
|
15676
|
+
export { Adapter, ExecutionContextService, History, HistoryAdapter, HistoryInstance, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Policy, Schema, SharedState, SharedStorage, State, Storage, 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, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, runStateless, runStatelessForce, session, setConfig, swarm };
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as di_scoped from 'di-scoped';
|
|
2
2
|
import * as functools_kit from 'functools-kit';
|
|
3
3
|
import { SortedArray, Subject } from 'functools-kit';
|
|
4
|
+
import { ICompletionArgs as ICompletionArgs$1 } from 'src/interfaces/Completion.interface';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Interface representing the context.
|
|
@@ -5646,6 +5647,30 @@ declare class SchemaUtils {
|
|
|
5646
5647
|
*/
|
|
5647
5648
|
declare const Schema: SchemaUtils;
|
|
5648
5649
|
|
|
5650
|
+
declare class AdapterUtils {
|
|
5651
|
+
/**
|
|
5652
|
+
* Creates a function to interact with OpenAI's chat completions.
|
|
5653
|
+
*
|
|
5654
|
+
* @param {any} openai - The OpenAI instance.
|
|
5655
|
+
* @param {string} [model="gpt-3.5-turbo"] - The model to use for completions.
|
|
5656
|
+
* @returns {Function} - A function that takes completion arguments and returns a response from OpenAI.
|
|
5657
|
+
*/
|
|
5658
|
+
fromOpenAI: (openai: any, model?: string, response_format?: {
|
|
5659
|
+
type: string;
|
|
5660
|
+
}) => ({ agentName, messages: rawMessages, mode, tools, clientId, }: ICompletionArgs$1) => Promise<{
|
|
5661
|
+
content: any;
|
|
5662
|
+
mode: ExecutionMode;
|
|
5663
|
+
agentName: string;
|
|
5664
|
+
role: any;
|
|
5665
|
+
tool_calls: any;
|
|
5666
|
+
}>;
|
|
5667
|
+
}
|
|
5668
|
+
/**
|
|
5669
|
+
* An instance of AdapterUtils.
|
|
5670
|
+
* @type {AdapterUtils}
|
|
5671
|
+
*/
|
|
5672
|
+
declare const Adapter: AdapterUtils;
|
|
5673
|
+
|
|
5649
5674
|
/**
|
|
5650
5675
|
* A higher-order function that ensures execution outside of existing method and execution contexts.
|
|
5651
5676
|
*
|
|
@@ -5665,4 +5690,4 @@ declare const Schema: SchemaUtils;
|
|
|
5665
5690
|
*/
|
|
5666
5691
|
declare const beginContext: <T extends (...args: any[]) => any>(run: T) => ((...args: Parameters<T>) => ReturnType<T>);
|
|
5667
5692
|
|
|
5668
|
-
export { type EventSource, ExecutionContextService, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IHistoryAdapter, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Policy, type ReceiveMessageFn, Schema, type SendMessageFn$1 as SendMessageFn, SharedState, SharedStorage, State, Storage, 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, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, runStateless, runStatelessForce, session, setConfig, swarm };
|
|
5693
|
+
export { Adapter, type EventSource, ExecutionContextService, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IHistoryAdapter, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerAdapter, LoggerInstance, MethodContextService, Policy, type ReceiveMessageFn, Schema, type SendMessageFn$1 as SendMessageFn, SharedState, SharedStorage, State, Storage, 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, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, runStateless, runStatelessForce, session, setConfig, swarm };
|