agent-swarm-kit
Version:
A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems
1 lines • 517 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../node_modules/tslib/tslib.es6.js","../src/lib/services/context/MethodContextService.ts","../src/lib/core/di.ts","../src/lib/core/types.ts","../src/lib/services/context/ExecutionContextService.ts","../src/validation/validateNoEmptyResult.ts","../src/validation/validateNoToolCall.ts","../src/validation/validateDefault.ts","../src/classes/History.ts","../src/classes/Logger.ts","../src/config/params.ts","../src/utils/removeXmlTags.ts","../src/utils/nameToTitle.ts","../src/lib/services/base/LoggerService.ts","../src/lib/services/schema/AgentSchemaService.ts","../src/client/ClientAgent.ts","../src/lib/services/connection/AgentConnectionService.ts","../src/client/ClientHistory.ts","../src/lib/services/connection/HistoryConnectionService.ts","../src/lib/services/schema/ToolSchemaService.ts","../src/client/ClientSwarm.ts","../src/lib/services/connection/SwarmConnectionService.ts","../src/lib/services/schema/SwarmSchemaService.ts","../src/lib/services/schema/CompletionSchemaService.ts","../src/client/ClientSession.ts","../src/lib/services/connection/SessionConnectionService.ts","../src/lib/services/public/AgentPublicService.ts","../src/lib/services/public/HistoryPublicService.ts","../src/lib/services/public/SessionPublicService.ts","../src/lib/services/public/SwarmPublicService.ts","../src/lib/services/validation/AgentValidationService.ts","../src/lib/services/validation/CompletionValidationService.ts","../src/lib/services/validation/SessionValidationService.ts","../src/lib/services/validation/SwarmValidationService.ts","../src/lib/services/validation/ToolValidationService.ts","../src/lib/services/schema/EmbeddingSchemaService.ts","../src/lib/services/schema/StorageSchemaService.ts","../src/client/ClientStorage.ts","../src/lib/services/connection/StorageConnectionService.ts","../src/lib/services/public/StoragePublicService.ts","../src/lib/services/validation/StorageValidationService.ts","../src/lib/services/validation/EmbeddingValidationService.ts","../src/lib/services/schema/StateSchemaService.ts","../src/client/ClientState.ts","../src/lib/services/connection/StateConnectionService.ts","../src/lib/services/public/StatePublicService.ts","../src/lib/services/base/BusService.ts","../src/lib/core/provide.ts","../src/lib/index.ts","../src/functions/addAgent.ts","../src/functions/addCompletion.ts","../src/functions/addSwarm.ts","../src/functions/addTool.ts","../src/functions/addState.ts","../src/functions/addEmbeding.ts","../src/functions/addStorage.ts","../src/functions/commitUserMessage.ts","../src/functions/getAgentName.ts","../src/functions/makeConnection.ts","../src/functions/changeAgent.ts","../src/functions/disposeConnection.ts","../src/functions/complete.ts","../src/functions/session.ts","../src/functions/getRawHistory.ts","../src/functions/getAgentHistory.ts","../src/functions/getSessionMode.ts","../src/functions/commitToolOutput.ts","../src/functions/commitSystemMessage.ts","../src/functions/commitFlush.ts","../src/functions/execute.ts","../src/functions/emit.ts","../src/functions/commitToolOutputForce.ts","../src/functions/commitSystemMessageForce.ts","../src/functions/commitFlushForce.ts","../src/functions/commitUserMessageForce.ts","../src/functions/emitForce.ts","../src/functions/executeForce.ts","../src/functions/listenEvent.ts","../src/functions/listenEventOnce.ts","../src/functions/getLastUserMessage.ts","../src/functions/getUserHistory.ts","../src/functions/getAssistantHistory.ts","../src/functions/getLastAssistantMessage.ts","../src/functions/getLastSystemMessage.ts","../src/functions/makeAutoDispose.ts","../src/functions/event.ts","../src/functions/cancelOutput.ts","../src/functions/cancelOutputForce.ts","../src/events/listenAgentEvent.ts","../src/events/listenHistoryEvent.ts","../src/events/listenSessionEvent.ts","../src/events/listenStateEvent.ts","../src/events/listenStorageEvent.ts","../src/events/listenSwarmEvent.ts","../src/events/listenAgentEventOnce.ts","../src/events/listenHistoryEventOnce.ts","../src/events/listenSessionEventOnce.ts","../src/events/listenStateEventOnce.ts","../src/events/listenStorageEventOnce.ts","../src/events/listenSwarmEventOnce.ts","../src/classes/Storage.ts","../src/classes/State.ts","../src/utils/objectFlat.ts","../src/classes/Schema.ts"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol, Iterator */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === \"function\" ? Iterator : Object).prototype);\r\n return g.next = verb(0), g[\"throw\"] = verb(1), g[\"return\"] = verb(2), typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = Object.create((typeof AsyncIterator === \"function\" ? AsyncIterator : Object).prototype), verb(\"next\"), verb(\"throw\"), verb(\"return\", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }\r\n function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose, inner;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n if (async) inner = dispose;\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n var r, s = 0;\r\n function next() {\r\n while (r = env.stack.pop()) {\r\n try {\r\n if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);\r\n if (r.dispose) {\r\n var result = r.dispose.call(r.value);\r\n if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n else s |= 1;\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n","import { scoped } from \"di-scoped\";\r\nimport { AgentName } from \"../../../interfaces/Agent.interface\";\r\nimport { SwarmName } from \"../../../interfaces/Swarm.interface\";\r\nimport { StorageName } from \"../../../interfaces/Storage.interface\";\r\nimport { StateName } from \"../../../interfaces/State.interface\";\r\n\r\n/**\r\n * Interface representing the context.\r\n */\r\nexport interface IMethodContext {\r\n clientId: string;\r\n methodName: string;\r\n agentName: AgentName;\r\n swarmName: SwarmName;\r\n storageName: StorageName;\r\n stateName: StateName;\r\n}\r\n\r\n/**\r\n * Service providing method call context information.\r\n */\r\nexport const MethodContextService = scoped(\r\n class {\r\n /**\r\n * Creates an instance of MethodContextService.\r\n * @param {IMethodContext} context - The context object.\r\n */\r\n constructor(readonly context: IMethodContext) {}\r\n }\r\n);\r\n\r\n/**\r\n * Type representing an instance of MethodContextService.\r\n */\r\nexport type TMethodContextService = InstanceType<typeof MethodContextService>;\r\n\r\nexport default MethodContextService;\r\n","import { createActivator } from \"di-kit\";\r\n\r\nexport const { init, inject, provide } = createActivator(\"agent-swarm\");\r\n","const baseServices = {\r\n busService: Symbol('busService'),\r\n loggerService: Symbol('loggerService'),\r\n};\r\n\r\nconst contextServices = {\r\n methodContextService: Symbol('methodContextService'),\r\n executionContextService: Symbol('executionContextService'),\r\n};\r\n\r\nconst connectionServices = {\r\n agentConnectionService: Symbol('agentConnectionService'),\r\n historyConnectionService: Symbol('historyConnectionService'),\r\n swarmConnectionService: Symbol('swarmConnectionService'),\r\n sessionConnectionService: Symbol('sessionConnectionService'),\r\n storageConnectionService: Symbol('storageConnectionService'),\r\n stateConnectionService: Symbol('stateConnectionService'),\r\n};\r\n\r\nconst schemaServices = {\r\n completionSchemaService: Symbol('completionSchemaService'),\r\n agentSchemaService: Symbol('agentSchemaService'),\r\n swarmSchemaService: Symbol('swarmSchemaService'),\r\n toolSchemaService: Symbol('toolSchemaService'),\r\n embeddingSchemaService: Symbol('embeddingSchemaService'),\r\n storageSchemaService: Symbol('storageSchemaService'),\r\n stateSchemaService: Symbol('stateSchemaService'),\r\n};\r\n\r\nconst publicServices = {\r\n agentPublicService: Symbol('agentPublicService'),\r\n historyPublicService: Symbol('historyPublicService'),\r\n sessionPublicService: Symbol('sessionPublicService'),\r\n swarmPublicService: Symbol('swarmPublicService'),\r\n storagePublicService: Symbol('storagePublicService'),\r\n statePublicService: Symbol('statePublicService'),\r\n};\r\n\r\nconst validationServices = {\r\n agentValidationService: Symbol('agentValidationService'),\r\n toolValidationService: Symbol('toolValidationService'),\r\n sessionValidationService: Symbol('sessionValidationService'),\r\n swarmValidationService: Symbol('swarmValidationService'),\r\n completionValidationService: Symbol('completionValidationService'),\r\n embeddingValidationService: Symbol('embeddingValidationService'),\r\n storageValidationService: Symbol('storageValidationService'),\r\n};\r\n\r\nexport const TYPES = {\r\n ...baseServices,\r\n ...contextServices,\r\n ...schemaServices,\r\n ...connectionServices,\r\n ...publicServices,\r\n ...validationServices,\r\n}\r\n\r\nexport default TYPES;\r\n","import { scoped } from \"di-scoped\";\r\n\r\n/**\r\n * Interface representing the context.\r\n */\r\nexport interface IExecutionContext {\r\n clientId: string;\r\n executionId: string;\r\n}\r\n\r\n/**\r\n * Service providing execution context information.\r\n */\r\nexport const ExecutionContextService = scoped(\r\n class {\r\n /**\r\n * Creates an instance of ExecutionContextService.\r\n * @param {IExecutionContext} context - The context object.\r\n */\r\n constructor(readonly context: IExecutionContext) {}\r\n }\r\n);\r\n\r\n/**\r\n * Type representing an instance of ExecutionContextService.\r\n */\r\nexport type TExecutionContextService = InstanceType<typeof ExecutionContextService>;\r\n\r\nexport default ExecutionContextService;\r\n","/**\r\n * Validates that the given output string is not empty.\r\n * \r\n * @param {string} output - The output string to validate.\r\n * @returns {Promise<string | null>} - Returns a promise that resolves to \"Empty output\" if the string is empty, otherwise null.\r\n */\r\nexport const validateNoEmptyResult = async (output: string): Promise<string | null> => {\r\n if (!output.trim()) {\r\n return \"Empty output\";\r\n }\r\n return null;\r\n};\r\n\r\nexport default validateNoEmptyResult;\r\n","import { trycatch } from \"functools-kit\";\r\nimport { GLOBAL_CONFIG } from \"../config/params\";\r\nimport xml2js from \"xml2js\";\r\n\r\nconst toolParser = new xml2js.Parser();\r\n\r\n/**\r\n * Validates that the given output string does not contain any tool call entries or disallowed symbols.\r\n * @see https://github.com/ollama/ollama/issues/8287\r\n * \r\n * @param {string} output - The output string to validate.\r\n * @returns {Promise<string | null>} - A promise that resolves to a string indicating a tool call in the text output, or null if no tool call is found.\r\n * @throws {Error} - If an error occurs during XML parsing.\r\n */\r\nexport const validateNoToolCall: (output: string) => Promise<string | null> = trycatch(\r\n async (output: string) => {\r\n for (const symbol of GLOBAL_CONFIG.CC_AGENT_DISALLOWED_SYMBOLS) {\r\n if (output.includes(symbol)) {\r\n return \"Tool call in text output\";\r\n }\r\n }\r\n const result = await toolParser.parseStringPromise(output);\r\n for (const tag of GLOBAL_CONFIG.CC_AGENT_DISALLOWED_TAGS) {\r\n if (result[tag]) {\r\n return \"Tool call in text output\";\r\n }\r\n }\r\n return null;\r\n },\r\n {\r\n defaultValue: null,\r\n }\r\n);\r\n\r\nexport default validateNoToolCall;\r\n","import validateNoEmptyResult from \"./validateNoEmptyResult\";\r\nimport validateNoToolCall from \"./validateNoToolCall\";\r\n\r\n/**\r\n * Validates the given output string using a series of validation functions.\r\n * \r\n * @param {string} output - The output string to validate.\r\n * @returns {Promise<string | null>} - A promise that resolves to a validation error message if any validation fails, or null if all validations pass.\r\n */\r\nexport const validateDefault = async (output: string): Promise<string | null> => {\r\n let validation: string | null = null;\r\n if (validation = await validateNoEmptyResult(output)) {\r\n return validation;\r\n }\r\n if (validation = await validateNoToolCall(output)) {\r\n return validation;\r\n }\r\n return null;\r\n};\r\n\r\nexport default validateDefault;\r\n","import { memoize, singleshot } from \"functools-kit\";\r\nimport { AgentName } from \"../interfaces/Agent.interface\";\r\nimport { IModelMessage } from \"../model/ModelMessage.model\";\r\nimport swarm from \"../lib\";\r\nimport { GLOBAL_CONFIG } from \"../config/params\";\r\n\r\n/**\r\n * Interface for History Adapter Callbacks\r\n */\r\nexport interface IHistoryInstanceCallbacks {\r\n\r\n /**\r\n * Callback for compute of dynamic system prompt\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n * @returns An array of additional system prompt messages\r\n */\r\n getSystemPrompt?: (\r\n clientId: string,\r\n agentName: AgentName\r\n ) => Promise<string[]> | string[];\r\n\r\n /**\r\n * Filter condition for history messages.\r\n * @param message - The model message.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n * @returns A promise that resolves to a boolean indicating whether the message passes the filter.\r\n */\r\n filterCondition?: (\r\n message: IModelMessage,\r\n clientId: string,\r\n agentName: AgentName\r\n ) => Promise<boolean> | boolean;\r\n\r\n /**\r\n * Get data for the history.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n * @returns A promise that resolves to an array of model messages.\r\n */\r\n getData: (\r\n clientId: string,\r\n agentName: AgentName\r\n ) => Promise<IModelMessage[]> | IModelMessage[];\r\n\r\n /**\r\n * Callback for when the history changes.\r\n * @param data - The array of model messages.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n */\r\n onChange: (\r\n data: IModelMessage[],\r\n clientId: string,\r\n agentName: AgentName\r\n ) => void;\r\n\r\n /**\r\n * Callback for when the history get the new message\r\n * @param data - The array of model messages.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n */\r\n onPush: (data: IModelMessage, clientId: string, agentName: AgentName) => void;\r\n\r\n /**\r\n * Callback for when the history is read. Will be called for each message\r\n * @param message - The model message.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n */\r\n onRead: (\r\n message: IModelMessage,\r\n clientId: string,\r\n agentName: AgentName\r\n ) => void;\r\n\r\n /**\r\n * Callback for when the read is begin\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n */\r\n onReadBegin: (clientId: string, agentName: AgentName) => void;\r\n\r\n /**\r\n * Callback for when the read is end\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n */\r\n onReadEnd: (clientId: string, agentName: AgentName) => void;\r\n\r\n /**\r\n * Callback for when the history is disposed.\r\n * @param clientId - The client ID.\r\n */\r\n onDispose: (clientId: string) => void;\r\n\r\n /**\r\n * Callback for when the history is initialized.\r\n * @param clientId - The client ID.\r\n */\r\n onInit: (clientId: string) => void;\r\n\r\n /**\r\n * Callback to obtain history ref\r\n * @param clientId - The client ID.\r\n */\r\n onRef: (history: HistoryInstance) => void;\r\n}\r\n\r\n/**\r\n * Interface for History Adapter\r\n */\r\nexport interface IHistoryAdapter {\r\n /**\r\n * Iterate over the history messages.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n * @returns An async iterable iterator of model messages.\r\n */\r\n iterate(\r\n clientId: string,\r\n agentName: AgentName\r\n ): AsyncIterableIterator<IModelMessage>;\r\n\r\n /**\r\n * Push a new message to the history.\r\n * @param value - The model message to push.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n * @returns A promise that resolves when the message is pushed.\r\n */\r\n push: (\r\n value: IModelMessage,\r\n clientId: string,\r\n agentName: AgentName\r\n ) => Promise<void>;\r\n\r\n /**\r\n * Dispose of the history for a given client and agent.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name or null.\r\n * @returns A promise that resolves when the history is disposed.\r\n */\r\n dispose: (clientId: string, agentName: AgentName | null) => Promise<void>;\r\n}\r\n\r\n/**\r\n * Interface for History Control\r\n */\r\nexport interface IHistoryControl {\r\n /**\r\n * Use a custom history adapter.\r\n * @param Ctor - The constructor for the history instance.\r\n */\r\n useHistoryAdapter(Ctor: THistoryInstanceCtor): void;\r\n\r\n /**\r\n * Use history lifecycle callbacks.\r\n * @param Callbacks - The callbacks dictionary.\r\n */\r\n useHistoryCallbacks: (Callbacks: Partial<IHistoryInstanceCallbacks>) => void;\r\n}\r\n\r\n/**\r\n * Interface for History Instance\r\n */\r\nexport interface IHistoryInstance {\r\n /**\r\n * Iterate over the history messages for a given agent.\r\n * @param agentName - The agent name.\r\n * @returns An async iterable iterator of model messages.\r\n */\r\n iterate(agentName: AgentName): AsyncIterableIterator<IModelMessage>;\r\n\r\n /**\r\n * Wait for the history to initialize.\r\n * @param agentName - The agent name.\r\n * @param init - Whether the history is initializing.\r\n * @returns A promise that resolves when the history is initialized.\r\n */\r\n waitForInit(agentName: AgentName, init: boolean): Promise<void>;\r\n\r\n /**\r\n * Push a new message to the history for a given agent.\r\n * @param value - The model message to push.\r\n * @param agentName - The agent name.\r\n * @returns A promise that resolves when the message is pushed.\r\n */\r\n push(value: IModelMessage, agentName: AgentName): Promise<void>;\r\n\r\n /**\r\n * Dispose of the history for a given agent.\r\n * @param agentName - The agent name or null.\r\n * @returns A promise that resolves when the history is disposed.\r\n */\r\n dispose(agentName: AgentName | null): Promise<void>;\r\n}\r\n\r\n/**\r\n * Type for History Instance Constructor\r\n */\r\nexport type THistoryInstanceCtor = new (\r\n clientId: string,\r\n ...args: unknown[]\r\n) => IHistoryInstance;\r\n\r\nconst HISTORY_INSTANCE_WAIT_FOR_INIT = Symbol(\"wait-for-init\");\r\n\r\nconst INSTANCE_METHOD_NAME_WAIT_FOR_INIT = \"HistoryInstance.waitForInit\";\r\nconst INSTANCE_METHOD_NAME_CTOR = \"HistoryInstance.CTOR\";\r\nconst INSTANCE_METHOD_NAME_ITERATE_CONDITION =\r\n \"HistoryInstance.iterate condition\";\r\nconst INSTANCE_METHOD_NAME_ITERATE = \"HistoryInstance.iterate\";\r\nconst INSTANCE_METHOD_NAME_PUSH = \"HistoryInstance.push\";\r\nconst INSTANCE_METHOD_NAME_DISPOSE = \"HistoryInstance.dispose\";\r\n\r\nconst METHOD_NAME_USE_HISTORY_ADAPTER = \"HistoryUtils.useHistoryAdapter\";\r\nconst METHOD_NAME_USE_HISTORY_CALLBACKS = \"HistoryUtils.useHistoryCallbacks\";\r\nconst METHOD_NAME_ITERATE = \"HistoryUtils.iterate\";\r\nconst METHOD_NAME_PUSH = \"HistoryUtils.push\";\r\nconst METHOD_NAME_DISPOSE = \"HistoryUtils.dispose\";\r\n\r\n/**\r\n * Class representing a History Instance\r\n */\r\nexport class HistoryInstance implements IHistoryInstance {\r\n private _array: IModelMessage[] = [];\r\n\r\n /**\r\n * Makes the singleshot for initialization\r\n * @param agentName - The agent name.\r\n */\r\n private [HISTORY_INSTANCE_WAIT_FOR_INIT] = singleshot(\r\n async (agentName: AgentName) => {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&\r\n swarm.loggerService.debug(INSTANCE_METHOD_NAME_WAIT_FOR_INIT, {\r\n clientId: this.clientId,\r\n agentName,\r\n });\r\n if (this.callbacks.getData) {\r\n this._array = await this.callbacks.getData(this.clientId, agentName);\r\n }\r\n }\r\n );\r\n\r\n /**\r\n * Wait for the history to initialize.\r\n * @param agentName - The agent name.\r\n */\r\n public async waitForInit(agentName: AgentName): Promise<void> {\r\n return await this[HISTORY_INSTANCE_WAIT_FOR_INIT](agentName);\r\n }\r\n\r\n /**\r\n * Create a HistoryInstance.\r\n * @param clientId - The client ID.\r\n * @param callbacks - The callbacks for the history instance.\r\n */\r\n constructor(\r\n readonly clientId: string,\r\n readonly callbacks: Partial<IHistoryInstanceCallbacks>\r\n ) {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&\r\n swarm.loggerService.debug(INSTANCE_METHOD_NAME_CTOR, {\r\n clientId: this.clientId,\r\n });\r\n if (callbacks.onInit) {\r\n callbacks.onInit(clientId);\r\n }\r\n if (callbacks.onRef) {\r\n callbacks.onRef(this);\r\n }\r\n if (callbacks.filterCondition) {\r\n this.iterate = async function* (\r\n agentName: AgentName\r\n ): AsyncIterableIterator<IModelMessage> {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&\r\n swarm.loggerService.debug(INSTANCE_METHOD_NAME_ITERATE_CONDITION, {\r\n clientId: this.clientId,\r\n agentName,\r\n });\r\n if (this.callbacks.onRead) {\r\n this.callbacks.onReadBegin &&\r\n this.callbacks.onReadBegin(this.clientId, agentName);\r\n for (const item of this._array) {\r\n if (\r\n await this.callbacks.filterCondition(\r\n item,\r\n this.clientId,\r\n agentName\r\n )\r\n ) {\r\n this.callbacks.onRead(item, this.clientId, agentName);\r\n yield item;\r\n }\r\n }\r\n if (this.callbacks.getSystemPrompt) {\r\n for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {\r\n yield {\r\n role: \"system\",\r\n content,\r\n agentName,\r\n mode: \"tool\"\r\n }\r\n }\r\n }\r\n this.callbacks.onReadEnd &&\r\n this.callbacks.onReadEnd(this.clientId, agentName);\r\n return;\r\n }\r\n this.callbacks.onReadBegin &&\r\n this.callbacks.onReadBegin(this.clientId, agentName);\r\n for (const item of this._array) {\r\n if (\r\n await this.callbacks.filterCondition(item, this.clientId, agentName)\r\n ) {\r\n yield item;\r\n }\r\n }\r\n if (this.callbacks.getSystemPrompt) {\r\n for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {\r\n yield {\r\n role: \"system\",\r\n content,\r\n agentName,\r\n mode: \"tool\"\r\n }\r\n }\r\n }\r\n this.callbacks.onReadEnd &&\r\n this.callbacks.onReadEnd(this.clientId, agentName);\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Iterate over the history messages for a given agent.\r\n * @param agentName - The agent name.\r\n * @returns An async iterable iterator of model messages.\r\n */\r\n public async *iterate(\r\n agentName: AgentName\r\n ): AsyncIterableIterator<IModelMessage> {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&\r\n swarm.loggerService.debug(INSTANCE_METHOD_NAME_ITERATE, {\r\n clientId: this.clientId,\r\n agentName,\r\n });\r\n if (this.callbacks.onRead) {\r\n this.callbacks.onReadBegin &&\r\n this.callbacks.onReadBegin(this.clientId, agentName);\r\n for (const item of this._array) {\r\n this.callbacks.onRead(item, this.clientId, agentName);\r\n yield item;\r\n }\r\n this.callbacks.onReadEnd &&\r\n this.callbacks.onReadEnd(this.clientId, agentName);\r\n return;\r\n }\r\n this.callbacks.onReadBegin &&\r\n this.callbacks.onReadBegin(this.clientId, agentName);\r\n for (const item of this._array) {\r\n yield item;\r\n }\r\n if (this.callbacks.getSystemPrompt) {\r\n for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {\r\n yield {\r\n role: \"system\",\r\n content,\r\n agentName,\r\n mode: \"tool\"\r\n }\r\n }\r\n }\r\n this.callbacks.onReadEnd &&\r\n this.callbacks.onReadEnd(this.clientId, agentName);\r\n }\r\n\r\n /**\r\n * Push a new message to the history for a given agent.\r\n * @param value - The model message to push.\r\n * @param agentName - The agent name.\r\n * @returns A promise that resolves when the message is pushed.\r\n */\r\n public push(value: IModelMessage, agentName: AgentName) {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&\r\n swarm.loggerService.debug(INSTANCE_METHOD_NAME_PUSH, {\r\n clientId: this.clientId,\r\n agentName,\r\n });\r\n this.callbacks.onPush &&\r\n this.callbacks.onPush(value, this.clientId, agentName);\r\n this._array.push(value);\r\n this.callbacks.onChange &&\r\n this.callbacks.onChange(this._array, this.clientId, agentName);\r\n return Promise.resolve();\r\n }\r\n\r\n /**\r\n * Dispose of the history for a given agent.\r\n * @param agentName - The agent name or null.\r\n * @returns A promise that resolves when the history is disposed.\r\n */\r\n public dispose(agentName: AgentName | null) {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&\r\n swarm.loggerService.debug(INSTANCE_METHOD_NAME_DISPOSE, {\r\n clientId: this.clientId,\r\n agentName,\r\n });\r\n if (agentName === null) {\r\n this.callbacks.onDispose && this.callbacks.onDispose(this.clientId);\r\n this._array = [];\r\n }\r\n return Promise.resolve();\r\n }\r\n}\r\n\r\n/**\r\n * Class representing History Utilities\r\n */\r\nclass HistoryUtils implements IHistoryAdapter, IHistoryControl {\r\n private HistoryFactory: THistoryInstanceCtor = HistoryInstance;\r\n private HistoryCallbacks: Partial<IHistoryInstanceCallbacks> = {};\r\n\r\n private getHistory = memoize(\r\n ([clientId]) => clientId,\r\n (clientId: string) =>\r\n new this.HistoryFactory(clientId, this.HistoryCallbacks)\r\n );\r\n\r\n /**\r\n * Use a custom history adapter.\r\n * @param Ctor - The constructor for the history instance.\r\n */\r\n public useHistoryAdapter = (Ctor: THistoryInstanceCtor) => {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&\r\n swarm.loggerService.log(METHOD_NAME_USE_HISTORY_ADAPTER);\r\n this.HistoryFactory = Ctor;\r\n };\r\n\r\n /**\r\n * Use history lifecycle callbacks.\r\n * @param Callbacks - The callbacks dictionary.\r\n */\r\n public useHistoryCallbacks = (\r\n Callbacks: Partial<IHistoryInstanceCallbacks>\r\n ) => {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&\r\n swarm.loggerService.log(METHOD_NAME_USE_HISTORY_CALLBACKS);\r\n Object.assign(this.HistoryCallbacks, Callbacks);\r\n };\r\n\r\n /**\r\n * Iterate over the history messages.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n * @returns An async iterable iterator of model messages.\r\n */\r\n public async *iterate(\r\n clientId: string,\r\n agentName: AgentName\r\n ): AsyncIterableIterator<IModelMessage> {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&\r\n swarm.loggerService.log(METHOD_NAME_ITERATE, {\r\n clientId,\r\n agentName,\r\n });\r\n const isInitial = this.getHistory.has(clientId);\r\n const history = await this.getHistory(clientId);\r\n await history.waitForInit(agentName, isInitial);\r\n for await (const item of history.iterate(agentName)) {\r\n yield item;\r\n }\r\n }\r\n\r\n /**\r\n * Push a new message to the history.\r\n * @param value - The model message to push.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name.\r\n * @returns A promise that resolves when the message is pushed.\r\n */\r\n public push = async (\r\n value: IModelMessage,\r\n clientId: string,\r\n agentName: AgentName\r\n ) => {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&\r\n swarm.loggerService.log(METHOD_NAME_PUSH, {\r\n clientId,\r\n agentName,\r\n value,\r\n });\r\n const isInitial = this.getHistory.has(clientId);\r\n const history = await this.getHistory(clientId);\r\n await history.waitForInit(agentName, isInitial);\r\n return await history.push(value, agentName);\r\n };\r\n\r\n /**\r\n * Dispose of the history for a given client and agent.\r\n * @param clientId - The client ID.\r\n * @param agentName - The agent name or null.\r\n * @returns A promise that resolves when the history is disposed.\r\n */\r\n public dispose = async (clientId: string, agentName: AgentName | null) => {\r\n GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&\r\n swarm.loggerService.log(METHOD_NAME_DISPOSE, {\r\n clientId,\r\n agentName,\r\n });\r\n if (!this.getHistory.has(clientId)) {\r\n return;\r\n }\r\n const history = await this.getHistory(clientId);\r\n await history.waitForInit(agentName, false);\r\n await history.dispose(agentName);\r\n if (agentName === null) {\r\n this.getHistory.clear(clientId);\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Exported History Adapter instance\r\n */\r\nexport const HistoryAdapter = new HistoryUtils();\r\n\r\n/**\r\n * Exported History Control instance\r\n */\r\nexport const History = HistoryAdapter as IHistoryControl;\r\n\r\nexport default HistoryAdapter;\r\n","import { ILogger } from \"../interfaces/Logger.interface\";\r\nimport swarm, { MethodContextService } from \"../lib\";\r\nimport { GLOBAL_CONFIG } from \"../config/params\";\r\nimport { memoize, singleshot } from \"functools-kit\";\r\n\r\nconst LOGGER_INSTANCE_WAIT_FOR_INIT = Symbol(\"wait-for-init\");\r\n\r\n/**\r\n * @interface ILoggerInstanceCallbacks\r\n * @description Callbacks for logger instance events.\r\n */\r\nexport interface ILoggerInstanceCallbacks {\r\n onInit(clientId: string): void;\r\n onDispose(clientId: string): void;\r\n onLog(clientId: string, topic: string, ...args: any[]): void;\r\n onDebug(clientId: string, topic: string, ...args: any[]): void;\r\n onInfo(clientId: string, topic: string, ...args: any[]): void;\r\n}\r\n\r\n/**\r\n * @interface ILoggerInstance\r\n * @extends ILogger\r\n * @description Interface for logger instances.\r\n */\r\nexport interface ILoggerInstance extends ILogger {\r\n waitForInit(initial: boolean): Promise<void> | void;\r\n dispose(): Promise<void> | void;\r\n}\r\n\r\n/**\r\n * @interface ILoggerAdapter\r\n * @description Interface for logger adapter.\r\n */\r\nexport interface ILoggerAdapter {\r\n log(clientId: string, topic: string, ...args: any[]): Promise<void>;\r\n debug(clientId: string, topic: string, ...args: any[]): Promise<void>;\r\n info(clientId: string, topic: string, ...args: any[]): Promise<void>;\r\n dispose(clientId: string): Promise<void>;\r\n}\r\n\r\n/**\r\n * @interface ILoggerControl\r\n * @description Interface for logger control.\r\n */\r\ninterface ILoggerControl {\r\n useCommonAdapter(logger: ILogger): void;\r\n useClientCallbacks(Callbacks: Partial<ILoggerInstanceCallbacks>):