agent-swarm-kit 1.0.173 → 1.0.174
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 +103 -4
- package/build/index.mjs +103 -5
- package/package.json +1 -1
- package/types.d.ts +104 -2
package/build/index.cjs
CHANGED
|
@@ -495,6 +495,9 @@ const PERSIST_STORAGE_UTILS_METHOD_NAME_USE_PERSIST_STORAGE_ADAPTER = "PersistSt
|
|
|
495
495
|
const PERSIST_STORAGE_UTILS_METHOD_NAME_GET_DATA = "PersistStorageUtils.getData";
|
|
496
496
|
/** @private Constant for logging the setData method in PersistStorageUtils */
|
|
497
497
|
const PERSIST_STORAGE_UTILS_METHOD_NAME_SET_DATA = "PersistStorageUtils.setData";
|
|
498
|
+
const PERSIST_POLICY_UTILS_METHOD_NAME_USE_PERSIST_POLICY_ADAPTER = "PersistPolicyUtils.usePersistPolicyAdapter";
|
|
499
|
+
const PERSIST_POLICY_UTILS_METHOD_NAME_GET_BANNED_CLIENTS = "PersistPolicyUtils.getBannedClients";
|
|
500
|
+
const PERSIST_POLICY_UTILS_METHOD_NAME_SET_BANNED_CLIENTS = "PersistPolicyUtils.setBannedClients";
|
|
498
501
|
// Logging method names for private functions
|
|
499
502
|
/** @private Constant for logging the waitForInitFn function */
|
|
500
503
|
const BASE_WAIT_FOR_INIT_FN_METHOD_NAME = "PersistBase.waitForInitFn";
|
|
@@ -1551,6 +1554,87 @@ const PersistAliveAdapter = new PersistAliveUtils();
|
|
|
1551
1554
|
* @type {IPersistAliveControl}
|
|
1552
1555
|
*/
|
|
1553
1556
|
const PersistAlive = PersistAliveAdapter;
|
|
1557
|
+
/**
|
|
1558
|
+
* Utility class for managing policy data persistence in the swarm system.
|
|
1559
|
+
* Provides methods to get and set banned clients within a `SwarmName`, with a customizable adapter.
|
|
1560
|
+
* @implements {IPersistPolicyControl}
|
|
1561
|
+
*/
|
|
1562
|
+
class PersistPolicyUtils {
|
|
1563
|
+
constructor() {
|
|
1564
|
+
/** @private Default constructor for policy data persistence, defaults to `PersistBase` */
|
|
1565
|
+
this.PersistPolicyFactory = PersistBase;
|
|
1566
|
+
/**
|
|
1567
|
+
* Memoized function to create or retrieve storage for a specific policy data.
|
|
1568
|
+
* Ensures a single persistence instance per swarm, optimizing resource use.
|
|
1569
|
+
* @private
|
|
1570
|
+
* @param swarmName - The identifier of the swarm.
|
|
1571
|
+
* @returns A persistence instance for the policy data, rooted at `./logs/data/policy/`.
|
|
1572
|
+
*/
|
|
1573
|
+
this.getPolicyStorage = functoolsKit.memoize(([swarmName]) => `${swarmName}`, (swarmName) => Reflect.construct(this.PersistPolicyFactory, [
|
|
1574
|
+
swarmName,
|
|
1575
|
+
`./logs/data/policy/`,
|
|
1576
|
+
]));
|
|
1577
|
+
/**
|
|
1578
|
+
* Retrieves the list of banned clients for a specific policy, defaulting to an empty array if unset.
|
|
1579
|
+
* Used to check client ban status in swarm workflows.
|
|
1580
|
+
* @param policyName - The identifier of the policy to check.
|
|
1581
|
+
* @param swarmName - The identifier of the swarm.
|
|
1582
|
+
* @param defaultValue - Optional default value if no banned clients are found.
|
|
1583
|
+
* @returns A promise resolving to an array of banned client session IDs.
|
|
1584
|
+
* @throws {Error} If reading from storage fails (e.g., file corruption).
|
|
1585
|
+
*/
|
|
1586
|
+
this.getBannedClients = async (policyName, swarmName, defaultValue = []) => {
|
|
1587
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
1588
|
+
swarm$1.loggerService.log(PERSIST_POLICY_UTILS_METHOD_NAME_GET_BANNED_CLIENTS);
|
|
1589
|
+
const isInitial = this.getPolicyStorage.has(swarmName);
|
|
1590
|
+
const stateStorage = this.getPolicyStorage(swarmName);
|
|
1591
|
+
await stateStorage.waitForInit(isInitial);
|
|
1592
|
+
if (await stateStorage.hasValue(policyName)) {
|
|
1593
|
+
const { bannedClients } = await stateStorage.readValue(policyName);
|
|
1594
|
+
return bannedClients;
|
|
1595
|
+
}
|
|
1596
|
+
return defaultValue;
|
|
1597
|
+
};
|
|
1598
|
+
/**
|
|
1599
|
+
* Sets the list of banned clients for a specific policy, persisting the status for future retrieval.
|
|
1600
|
+
* Used to manage client bans in swarm operations.
|
|
1601
|
+
* @param bannedClients - Array of session IDs to be banned under this policy.
|
|
1602
|
+
* @param policyName - The identifier of the policy to update.
|
|
1603
|
+
* @param swarmName - The identifier of the swarm.
|
|
1604
|
+
* @returns A promise that resolves when the banned clients list is persisted.
|
|
1605
|
+
* @throws {Error} If writing to storage fails (e.g., permissions or disk space).
|
|
1606
|
+
*/
|
|
1607
|
+
this.setBannedClients = async (bannedClients, policyName, swarmName) => {
|
|
1608
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
1609
|
+
swarm$1.loggerService.log(PERSIST_POLICY_UTILS_METHOD_NAME_SET_BANNED_CLIENTS);
|
|
1610
|
+
const isInitial = this.getPolicyStorage.has(swarmName);
|
|
1611
|
+
const stateStorage = this.getPolicyStorage(swarmName);
|
|
1612
|
+
await stateStorage.waitForInit(isInitial);
|
|
1613
|
+
await stateStorage.writeValue(policyName, { bannedClients });
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Configures a custom constructor for policy data persistence, overriding the default `PersistBase`.
|
|
1618
|
+
* Enables advanced tracking (e.g., in-memory or database-backed persistence).
|
|
1619
|
+
* @param Ctor - The constructor to use for policy data storage, implementing `IPersistBase`.
|
|
1620
|
+
*/
|
|
1621
|
+
usePersistPolicyAdapter(Ctor) {
|
|
1622
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
1623
|
+
swarm$1.loggerService.log(PERSIST_POLICY_UTILS_METHOD_NAME_USE_PERSIST_POLICY_ADAPTER);
|
|
1624
|
+
this.PersistPolicyFactory = Ctor;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Singleton instance of `PersistPolicyUtils` for managing policy data persistence globally.
|
|
1629
|
+
* @type {PersistPolicyUtils}
|
|
1630
|
+
*/
|
|
1631
|
+
const PersistPolicyAdapter = new PersistPolicyUtils();
|
|
1632
|
+
/**
|
|
1633
|
+
* Exported singleton for policy persistence operations, cast as the control interface.
|
|
1634
|
+
* Provides a global point of access for managing client bans in the swarm.
|
|
1635
|
+
* @type {IPersistPolicyControl}
|
|
1636
|
+
*/
|
|
1637
|
+
const PersistPolicy = PersistPolicyAdapter;
|
|
1554
1638
|
|
|
1555
1639
|
var _a$1, _b$1, _c, _d;
|
|
1556
1640
|
/** @private Symbol for memoizing the waitForInit method in HistoryMemoryInstance */
|
|
@@ -2628,6 +2712,9 @@ const CC_LOGGER_ENABLE_CONSOLE = false;
|
|
|
2628
2712
|
let CC_RESQUE_STRATEGY;
|
|
2629
2713
|
const CC_DEFAULT_STATE_SET = () => Promise.resolve();
|
|
2630
2714
|
const CC_DEFAULT_STATE_GET = ({}, {}, defaultState) => Promise.resolve(defaultState);
|
|
2715
|
+
const CC_DEFAULT_POLICY_GET_BAN_CLIENTS = () => [];
|
|
2716
|
+
const CC_DEFAULT_POLICY_GET = () => [];
|
|
2717
|
+
const CC_DEFAULT_POLICY_SET = () => Promise.resolve();
|
|
2631
2718
|
const CC_DEFAULT_STORAGE_GET = ({}, {}, defaultValue) => Promise.resolve(defaultValue);
|
|
2632
2719
|
const CC_DEFAULT_STORAGE_SET = () => Promise.resolve();
|
|
2633
2720
|
const CC_NAME_TO_TITLE = nameToTitle;
|
|
@@ -2644,6 +2731,9 @@ const GLOBAL_CONFIG = {
|
|
|
2644
2731
|
CC_EMPTY_OUTPUT_PLACEHOLDERS,
|
|
2645
2732
|
CC_KEEP_MESSAGES,
|
|
2646
2733
|
CC_MAX_TOOL_CALLS,
|
|
2734
|
+
CC_DEFAULT_POLICY_GET_BAN_CLIENTS,
|
|
2735
|
+
CC_DEFAULT_POLICY_GET,
|
|
2736
|
+
CC_DEFAULT_POLICY_SET,
|
|
2647
2737
|
CC_AGENT_MAP_TOOLS,
|
|
2648
2738
|
CC_GET_AGENT_HISTORY_ADAPTER,
|
|
2649
2739
|
CC_GET_CLIENT_LOGGER_ADAPTER,
|
|
@@ -11898,8 +11988,9 @@ class PolicySchemaService {
|
|
|
11898
11988
|
if (typeof policySchema.policyName !== "string") {
|
|
11899
11989
|
throw new Error(`agent-swarm policy schema validation failed: missing policyName`);
|
|
11900
11990
|
}
|
|
11901
|
-
if (typeof policySchema.
|
|
11902
|
-
|
|
11991
|
+
if (typeof policySchema.validateInput !== "function" &&
|
|
11992
|
+
typeof policySchema.validateOutput !== "function") {
|
|
11993
|
+
throw new Error(`agent-swarm policy schema validation failed: the validateInput or validateOutput must be provided at least policyName=${policySchema.policyName}`);
|
|
11903
11994
|
}
|
|
11904
11995
|
};
|
|
11905
11996
|
/**
|
|
@@ -12505,12 +12596,18 @@ class PolicyConnectionService {
|
|
|
12505
12596
|
* @returns {ClientPolicy} The memoized ClientPolicy instance configured for the policy.
|
|
12506
12597
|
*/
|
|
12507
12598
|
this.getPolicy = functoolsKit.memoize(([policyName]) => `${policyName}`, (policyName) => {
|
|
12508
|
-
const { autoBan = GLOBAL_CONFIG.CC_AUTOBAN_ENABLED_BY_DEFAULT,
|
|
12599
|
+
const { autoBan = GLOBAL_CONFIG.CC_AUTOBAN_ENABLED_BY_DEFAULT, banMessage = GLOBAL_CONFIG.CC_BANHAMMER_PLACEHOLDER, persist = GLOBAL_CONFIG.CC_PERSIST_ENABLED_BY_DEFAULT, getBannedClients = persist
|
|
12600
|
+
? PersistPolicyAdapter.getBannedClients
|
|
12601
|
+
: GLOBAL_CONFIG.CC_DEFAULT_POLICY_GET, setBannedClients = persist
|
|
12602
|
+
? PersistPolicyAdapter.setBannedClients
|
|
12603
|
+
: GLOBAL_CONFIG.CC_DEFAULT_POLICY_SET, ...schema } = this.policySchemaService.get(policyName);
|
|
12509
12604
|
return new ClientPolicy({
|
|
12510
12605
|
policyName,
|
|
12511
12606
|
bus: this.busService,
|
|
12512
12607
|
logger: this.loggerService,
|
|
12513
|
-
autoBan,
|
|
12608
|
+
autoBan, getBannedClients,
|
|
12609
|
+
setBannedClients,
|
|
12610
|
+
banMessage,
|
|
12514
12611
|
...schema,
|
|
12515
12612
|
});
|
|
12516
12613
|
});
|
|
@@ -17159,6 +17256,7 @@ const Utils = {
|
|
|
17159
17256
|
PersistStorageUtils,
|
|
17160
17257
|
PersistMemoryUtils,
|
|
17161
17258
|
PersistAliveUtils,
|
|
17259
|
+
PersistPolicyUtils,
|
|
17162
17260
|
};
|
|
17163
17261
|
|
|
17164
17262
|
exports.Adapter = Adapter;
|
|
@@ -17174,6 +17272,7 @@ exports.PersistAlive = PersistAlive;
|
|
|
17174
17272
|
exports.PersistBase = PersistBase;
|
|
17175
17273
|
exports.PersistList = PersistList;
|
|
17176
17274
|
exports.PersistMemory = PersistMemory;
|
|
17275
|
+
exports.PersistPolicy = PersistPolicy;
|
|
17177
17276
|
exports.PersistState = PersistState;
|
|
17178
17277
|
exports.PersistStorage = PersistStorage;
|
|
17179
17278
|
exports.PersistSwarm = PersistSwarm;
|
package/build/index.mjs
CHANGED
|
@@ -493,6 +493,9 @@ const PERSIST_STORAGE_UTILS_METHOD_NAME_USE_PERSIST_STORAGE_ADAPTER = "PersistSt
|
|
|
493
493
|
const PERSIST_STORAGE_UTILS_METHOD_NAME_GET_DATA = "PersistStorageUtils.getData";
|
|
494
494
|
/** @private Constant for logging the setData method in PersistStorageUtils */
|
|
495
495
|
const PERSIST_STORAGE_UTILS_METHOD_NAME_SET_DATA = "PersistStorageUtils.setData";
|
|
496
|
+
const PERSIST_POLICY_UTILS_METHOD_NAME_USE_PERSIST_POLICY_ADAPTER = "PersistPolicyUtils.usePersistPolicyAdapter";
|
|
497
|
+
const PERSIST_POLICY_UTILS_METHOD_NAME_GET_BANNED_CLIENTS = "PersistPolicyUtils.getBannedClients";
|
|
498
|
+
const PERSIST_POLICY_UTILS_METHOD_NAME_SET_BANNED_CLIENTS = "PersistPolicyUtils.setBannedClients";
|
|
496
499
|
// Logging method names for private functions
|
|
497
500
|
/** @private Constant for logging the waitForInitFn function */
|
|
498
501
|
const BASE_WAIT_FOR_INIT_FN_METHOD_NAME = "PersistBase.waitForInitFn";
|
|
@@ -1549,6 +1552,87 @@ const PersistAliveAdapter = new PersistAliveUtils();
|
|
|
1549
1552
|
* @type {IPersistAliveControl}
|
|
1550
1553
|
*/
|
|
1551
1554
|
const PersistAlive = PersistAliveAdapter;
|
|
1555
|
+
/**
|
|
1556
|
+
* Utility class for managing policy data persistence in the swarm system.
|
|
1557
|
+
* Provides methods to get and set banned clients within a `SwarmName`, with a customizable adapter.
|
|
1558
|
+
* @implements {IPersistPolicyControl}
|
|
1559
|
+
*/
|
|
1560
|
+
class PersistPolicyUtils {
|
|
1561
|
+
constructor() {
|
|
1562
|
+
/** @private Default constructor for policy data persistence, defaults to `PersistBase` */
|
|
1563
|
+
this.PersistPolicyFactory = PersistBase;
|
|
1564
|
+
/**
|
|
1565
|
+
* Memoized function to create or retrieve storage for a specific policy data.
|
|
1566
|
+
* Ensures a single persistence instance per swarm, optimizing resource use.
|
|
1567
|
+
* @private
|
|
1568
|
+
* @param swarmName - The identifier of the swarm.
|
|
1569
|
+
* @returns A persistence instance for the policy data, rooted at `./logs/data/policy/`.
|
|
1570
|
+
*/
|
|
1571
|
+
this.getPolicyStorage = memoize(([swarmName]) => `${swarmName}`, (swarmName) => Reflect.construct(this.PersistPolicyFactory, [
|
|
1572
|
+
swarmName,
|
|
1573
|
+
`./logs/data/policy/`,
|
|
1574
|
+
]));
|
|
1575
|
+
/**
|
|
1576
|
+
* Retrieves the list of banned clients for a specific policy, defaulting to an empty array if unset.
|
|
1577
|
+
* Used to check client ban status in swarm workflows.
|
|
1578
|
+
* @param policyName - The identifier of the policy to check.
|
|
1579
|
+
* @param swarmName - The identifier of the swarm.
|
|
1580
|
+
* @param defaultValue - Optional default value if no banned clients are found.
|
|
1581
|
+
* @returns A promise resolving to an array of banned client session IDs.
|
|
1582
|
+
* @throws {Error} If reading from storage fails (e.g., file corruption).
|
|
1583
|
+
*/
|
|
1584
|
+
this.getBannedClients = async (policyName, swarmName, defaultValue = []) => {
|
|
1585
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
1586
|
+
swarm$1.loggerService.log(PERSIST_POLICY_UTILS_METHOD_NAME_GET_BANNED_CLIENTS);
|
|
1587
|
+
const isInitial = this.getPolicyStorage.has(swarmName);
|
|
1588
|
+
const stateStorage = this.getPolicyStorage(swarmName);
|
|
1589
|
+
await stateStorage.waitForInit(isInitial);
|
|
1590
|
+
if (await stateStorage.hasValue(policyName)) {
|
|
1591
|
+
const { bannedClients } = await stateStorage.readValue(policyName);
|
|
1592
|
+
return bannedClients;
|
|
1593
|
+
}
|
|
1594
|
+
return defaultValue;
|
|
1595
|
+
};
|
|
1596
|
+
/**
|
|
1597
|
+
* Sets the list of banned clients for a specific policy, persisting the status for future retrieval.
|
|
1598
|
+
* Used to manage client bans in swarm operations.
|
|
1599
|
+
* @param bannedClients - Array of session IDs to be banned under this policy.
|
|
1600
|
+
* @param policyName - The identifier of the policy to update.
|
|
1601
|
+
* @param swarmName - The identifier of the swarm.
|
|
1602
|
+
* @returns A promise that resolves when the banned clients list is persisted.
|
|
1603
|
+
* @throws {Error} If writing to storage fails (e.g., permissions or disk space).
|
|
1604
|
+
*/
|
|
1605
|
+
this.setBannedClients = async (bannedClients, policyName, swarmName) => {
|
|
1606
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
1607
|
+
swarm$1.loggerService.log(PERSIST_POLICY_UTILS_METHOD_NAME_SET_BANNED_CLIENTS);
|
|
1608
|
+
const isInitial = this.getPolicyStorage.has(swarmName);
|
|
1609
|
+
const stateStorage = this.getPolicyStorage(swarmName);
|
|
1610
|
+
await stateStorage.waitForInit(isInitial);
|
|
1611
|
+
await stateStorage.writeValue(policyName, { bannedClients });
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Configures a custom constructor for policy data persistence, overriding the default `PersistBase`.
|
|
1616
|
+
* Enables advanced tracking (e.g., in-memory or database-backed persistence).
|
|
1617
|
+
* @param Ctor - The constructor to use for policy data storage, implementing `IPersistBase`.
|
|
1618
|
+
*/
|
|
1619
|
+
usePersistPolicyAdapter(Ctor) {
|
|
1620
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
1621
|
+
swarm$1.loggerService.log(PERSIST_POLICY_UTILS_METHOD_NAME_USE_PERSIST_POLICY_ADAPTER);
|
|
1622
|
+
this.PersistPolicyFactory = Ctor;
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Singleton instance of `PersistPolicyUtils` for managing policy data persistence globally.
|
|
1627
|
+
* @type {PersistPolicyUtils}
|
|
1628
|
+
*/
|
|
1629
|
+
const PersistPolicyAdapter = new PersistPolicyUtils();
|
|
1630
|
+
/**
|
|
1631
|
+
* Exported singleton for policy persistence operations, cast as the control interface.
|
|
1632
|
+
* Provides a global point of access for managing client bans in the swarm.
|
|
1633
|
+
* @type {IPersistPolicyControl}
|
|
1634
|
+
*/
|
|
1635
|
+
const PersistPolicy = PersistPolicyAdapter;
|
|
1552
1636
|
|
|
1553
1637
|
var _a$1, _b$1, _c, _d;
|
|
1554
1638
|
/** @private Symbol for memoizing the waitForInit method in HistoryMemoryInstance */
|
|
@@ -2626,6 +2710,9 @@ const CC_LOGGER_ENABLE_CONSOLE = false;
|
|
|
2626
2710
|
let CC_RESQUE_STRATEGY;
|
|
2627
2711
|
const CC_DEFAULT_STATE_SET = () => Promise.resolve();
|
|
2628
2712
|
const CC_DEFAULT_STATE_GET = ({}, {}, defaultState) => Promise.resolve(defaultState);
|
|
2713
|
+
const CC_DEFAULT_POLICY_GET_BAN_CLIENTS = () => [];
|
|
2714
|
+
const CC_DEFAULT_POLICY_GET = () => [];
|
|
2715
|
+
const CC_DEFAULT_POLICY_SET = () => Promise.resolve();
|
|
2629
2716
|
const CC_DEFAULT_STORAGE_GET = ({}, {}, defaultValue) => Promise.resolve(defaultValue);
|
|
2630
2717
|
const CC_DEFAULT_STORAGE_SET = () => Promise.resolve();
|
|
2631
2718
|
const CC_NAME_TO_TITLE = nameToTitle;
|
|
@@ -2642,6 +2729,9 @@ const GLOBAL_CONFIG = {
|
|
|
2642
2729
|
CC_EMPTY_OUTPUT_PLACEHOLDERS,
|
|
2643
2730
|
CC_KEEP_MESSAGES,
|
|
2644
2731
|
CC_MAX_TOOL_CALLS,
|
|
2732
|
+
CC_DEFAULT_POLICY_GET_BAN_CLIENTS,
|
|
2733
|
+
CC_DEFAULT_POLICY_GET,
|
|
2734
|
+
CC_DEFAULT_POLICY_SET,
|
|
2645
2735
|
CC_AGENT_MAP_TOOLS,
|
|
2646
2736
|
CC_GET_AGENT_HISTORY_ADAPTER,
|
|
2647
2737
|
CC_GET_CLIENT_LOGGER_ADAPTER,
|
|
@@ -11896,8 +11986,9 @@ class PolicySchemaService {
|
|
|
11896
11986
|
if (typeof policySchema.policyName !== "string") {
|
|
11897
11987
|
throw new Error(`agent-swarm policy schema validation failed: missing policyName`);
|
|
11898
11988
|
}
|
|
11899
|
-
if (typeof policySchema.
|
|
11900
|
-
|
|
11989
|
+
if (typeof policySchema.validateInput !== "function" &&
|
|
11990
|
+
typeof policySchema.validateOutput !== "function") {
|
|
11991
|
+
throw new Error(`agent-swarm policy schema validation failed: the validateInput or validateOutput must be provided at least policyName=${policySchema.policyName}`);
|
|
11901
11992
|
}
|
|
11902
11993
|
};
|
|
11903
11994
|
/**
|
|
@@ -12503,12 +12594,18 @@ class PolicyConnectionService {
|
|
|
12503
12594
|
* @returns {ClientPolicy} The memoized ClientPolicy instance configured for the policy.
|
|
12504
12595
|
*/
|
|
12505
12596
|
this.getPolicy = memoize(([policyName]) => `${policyName}`, (policyName) => {
|
|
12506
|
-
const { autoBan = GLOBAL_CONFIG.CC_AUTOBAN_ENABLED_BY_DEFAULT,
|
|
12597
|
+
const { autoBan = GLOBAL_CONFIG.CC_AUTOBAN_ENABLED_BY_DEFAULT, banMessage = GLOBAL_CONFIG.CC_BANHAMMER_PLACEHOLDER, persist = GLOBAL_CONFIG.CC_PERSIST_ENABLED_BY_DEFAULT, getBannedClients = persist
|
|
12598
|
+
? PersistPolicyAdapter.getBannedClients
|
|
12599
|
+
: GLOBAL_CONFIG.CC_DEFAULT_POLICY_GET, setBannedClients = persist
|
|
12600
|
+
? PersistPolicyAdapter.setBannedClients
|
|
12601
|
+
: GLOBAL_CONFIG.CC_DEFAULT_POLICY_SET, ...schema } = this.policySchemaService.get(policyName);
|
|
12507
12602
|
return new ClientPolicy({
|
|
12508
12603
|
policyName,
|
|
12509
12604
|
bus: this.busService,
|
|
12510
12605
|
logger: this.loggerService,
|
|
12511
|
-
autoBan,
|
|
12606
|
+
autoBan, getBannedClients,
|
|
12607
|
+
setBannedClients,
|
|
12608
|
+
banMessage,
|
|
12512
12609
|
...schema,
|
|
12513
12610
|
});
|
|
12514
12611
|
});
|
|
@@ -17157,6 +17254,7 @@ const Utils = {
|
|
|
17157
17254
|
PersistStorageUtils,
|
|
17158
17255
|
PersistMemoryUtils,
|
|
17159
17256
|
PersistAliveUtils,
|
|
17257
|
+
PersistPolicyUtils,
|
|
17160
17258
|
};
|
|
17161
17259
|
|
|
17162
|
-
export { Adapter, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistList, PersistMemory, 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 };
|
|
17260
|
+
export { Adapter, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, 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 };
|
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 { PolicyName as PolicyName$1 } from 'src/interfaces/Policy.interface';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Interface defining the structure of execution context in the swarm system.
|
|
@@ -664,6 +665,8 @@ interface IPolicy {
|
|
|
664
665
|
* Defines how policies enforce rules and manage bans within the swarm.
|
|
665
666
|
*/
|
|
666
667
|
interface IPolicySchema {
|
|
668
|
+
/** Optional flag to enable serialization of banned clients to persistent storage (e.g., hard drive). */
|
|
669
|
+
persist?: boolean;
|
|
667
670
|
/** Optional description for documentation purposes, aiding in policy usage understanding. */
|
|
668
671
|
docDescription?: string;
|
|
669
672
|
/** The unique name of the policy within the swarm. */
|
|
@@ -687,7 +690,7 @@ interface IPolicySchema {
|
|
|
687
690
|
* @param {SwarmName} swarmName - The unique name of the swarm.
|
|
688
691
|
* @returns {SessionId[] | Promise<SessionId[]>} An array of banned session IDs, synchronously or asynchronously.
|
|
689
692
|
*/
|
|
690
|
-
getBannedClients
|
|
693
|
+
getBannedClients?: (policyName: PolicyName, swarmName: SwarmName) => SessionId[] | Promise<SessionId[]>;
|
|
691
694
|
/**
|
|
692
695
|
* Optional function to set the list of banned clients.
|
|
693
696
|
* Overrides default ban list management if provided.
|
|
@@ -2283,6 +2286,77 @@ declare class PersistAliveUtils implements IPersistAliveControl {
|
|
|
2283
2286
|
* @type {IPersistAliveControl}
|
|
2284
2287
|
*/
|
|
2285
2288
|
declare const PersistAlive: IPersistAliveControl;
|
|
2289
|
+
/**
|
|
2290
|
+
* Defines the structure for policy data persistence in the swarm system.
|
|
2291
|
+
* Tracks banned clients (`SessionId`) within a `SwarmName` under a specific policy.
|
|
2292
|
+
* @interface IPersistPolicyData
|
|
2293
|
+
*/
|
|
2294
|
+
interface IPersistPolicyData {
|
|
2295
|
+
/** Array of session IDs that are banned under this policy */
|
|
2296
|
+
bannedClients: SessionId[];
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Defines control methods for customizing policy persistence operations.
|
|
2300
|
+
* Allows injection of a custom persistence adapter for policy data tied to `SwarmName`.
|
|
2301
|
+
* @interface IPersistPolicyControl
|
|
2302
|
+
*/
|
|
2303
|
+
interface IPersistPolicyControl {
|
|
2304
|
+
/**
|
|
2305
|
+
* Sets a custom persistence adapter for policy data storage.
|
|
2306
|
+
* Overrides the default `PersistBase` implementation for specialized behavior (e.g., in-memory tracking for `SwarmName`).
|
|
2307
|
+
* @param {TPersistBaseCtor<SwarmName, IPersistPolicyData>} Ctor - The constructor for the policy data persistence adapter.
|
|
2308
|
+
*/
|
|
2309
|
+
usePersistPolicyAdapter(Ctor: TPersistBaseCtor<SwarmName, IPersistPolicyData>): void;
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* Utility class for managing policy data persistence in the swarm system.
|
|
2313
|
+
* Provides methods to get and set banned clients within a `SwarmName`, with a customizable adapter.
|
|
2314
|
+
* @implements {IPersistPolicyControl}
|
|
2315
|
+
*/
|
|
2316
|
+
declare class PersistPolicyUtils implements IPersistPolicyControl {
|
|
2317
|
+
/** @private Default constructor for policy data persistence, defaults to `PersistBase` */
|
|
2318
|
+
private PersistPolicyFactory;
|
|
2319
|
+
/**
|
|
2320
|
+
* Memoized function to create or retrieve storage for a specific policy data.
|
|
2321
|
+
* Ensures a single persistence instance per swarm, optimizing resource use.
|
|
2322
|
+
* @private
|
|
2323
|
+
* @param swarmName - The identifier of the swarm.
|
|
2324
|
+
* @returns A persistence instance for the policy data, rooted at `./logs/data/policy/`.
|
|
2325
|
+
*/
|
|
2326
|
+
private getPolicyStorage;
|
|
2327
|
+
/**
|
|
2328
|
+
* Configures a custom constructor for policy data persistence, overriding the default `PersistBase`.
|
|
2329
|
+
* Enables advanced tracking (e.g., in-memory or database-backed persistence).
|
|
2330
|
+
* @param Ctor - The constructor to use for policy data storage, implementing `IPersistBase`.
|
|
2331
|
+
*/
|
|
2332
|
+
usePersistPolicyAdapter(Ctor: TPersistBaseCtor<SwarmName, IPersistPolicyData>): void;
|
|
2333
|
+
/**
|
|
2334
|
+
* Retrieves the list of banned clients for a specific policy, defaulting to an empty array if unset.
|
|
2335
|
+
* Used to check client ban status in swarm workflows.
|
|
2336
|
+
* @param policyName - The identifier of the policy to check.
|
|
2337
|
+
* @param swarmName - The identifier of the swarm.
|
|
2338
|
+
* @param defaultValue - Optional default value if no banned clients are found.
|
|
2339
|
+
* @returns A promise resolving to an array of banned client session IDs.
|
|
2340
|
+
* @throws {Error} If reading from storage fails (e.g., file corruption).
|
|
2341
|
+
*/
|
|
2342
|
+
getBannedClients: (policyName: PolicyName$1, swarmName: SwarmName, defaultValue?: SessionId[]) => Promise<SessionId[]>;
|
|
2343
|
+
/**
|
|
2344
|
+
* Sets the list of banned clients for a specific policy, persisting the status for future retrieval.
|
|
2345
|
+
* Used to manage client bans in swarm operations.
|
|
2346
|
+
* @param bannedClients - Array of session IDs to be banned under this policy.
|
|
2347
|
+
* @param policyName - The identifier of the policy to update.
|
|
2348
|
+
* @param swarmName - The identifier of the swarm.
|
|
2349
|
+
* @returns A promise that resolves when the banned clients list is persisted.
|
|
2350
|
+
* @throws {Error} If writing to storage fails (e.g., permissions or disk space).
|
|
2351
|
+
*/
|
|
2352
|
+
setBannedClients: (bannedClients: SessionId[], policyName: PolicyName$1, swarmName: SwarmName) => Promise<void>;
|
|
2353
|
+
}
|
|
2354
|
+
/**
|
|
2355
|
+
* Exported singleton for policy persistence operations, cast as the control interface.
|
|
2356
|
+
* Provides a global point of access for managing client bans in the swarm.
|
|
2357
|
+
* @type {IPersistPolicyControl}
|
|
2358
|
+
*/
|
|
2359
|
+
declare const PersistPolicy: IPersistPolicyControl;
|
|
2286
2360
|
|
|
2287
2361
|
/**
|
|
2288
2362
|
* Callbacks for managing history instance lifecycle and message handling.
|
|
@@ -9920,6 +9994,33 @@ interface IGlobalConfig {
|
|
|
9920
9994
|
* });
|
|
9921
9995
|
*/
|
|
9922
9996
|
CC_DEFAULT_STATE_GET: <T = any>(clientId: string, stateName: StateName, defaultState: T) => Promise<T>;
|
|
9997
|
+
/**
|
|
9998
|
+
* Default function to get banned clients for the policy
|
|
9999
|
+
* @param {PolicyName} policyName - The policy identifier.
|
|
10000
|
+
* @param {SwarmName} swarmName - The swarm identifier.
|
|
10001
|
+
* @example
|
|
10002
|
+
* setConfig({
|
|
10003
|
+
* CC_DEFAULT_POLICY_GET_BAN_CLIENTS: async () => []
|
|
10004
|
+
* });
|
|
10005
|
+
*/
|
|
10006
|
+
CC_DEFAULT_POLICY_GET_BAN_CLIENTS: (policyName: PolicyName, swarmName: SwarmName) => Promise<SessionId[]> | SessionId[];
|
|
10007
|
+
/**
|
|
10008
|
+
* Retrieves the list of currently banned clients under this policy.
|
|
10009
|
+
* @param {PolicyName} policyName - The unique name of the policy.
|
|
10010
|
+
* @param {SwarmName} swarmName - The unique name of the swarm.
|
|
10011
|
+
* @returns {SessionId[] | Promise<SessionId[]>} An array of banned session IDs, synchronously or asynchronously.
|
|
10012
|
+
*/
|
|
10013
|
+
CC_DEFAULT_POLICY_GET?: (policyName: PolicyName, swarmName: SwarmName) => SessionId[] | Promise<SessionId[]>;
|
|
10014
|
+
/**
|
|
10015
|
+
* Optional function to set the list of banned clients.
|
|
10016
|
+
* Overrides default ban list management if provided.
|
|
10017
|
+
* @param {SessionId[]} clientIds - An array of session IDs to ban.
|
|
10018
|
+
* @param {PolicyName} policyName - The unique name of the policy.
|
|
10019
|
+
* @param {SwarmName} swarmName - The unique name of the swarm.
|
|
10020
|
+
* @returns {Promise<void> | void} A promise that resolves when the ban list is updated, or void if synchronous.
|
|
10021
|
+
* @throws {Error} If updating the ban list fails (e.g., due to persistence issues).
|
|
10022
|
+
*/
|
|
10023
|
+
CC_DEFAULT_POLICY_SET?: (clientIds: SessionId[], policyName: PolicyName, swarmName: SwarmName) => Promise<void> | void;
|
|
9923
10024
|
/**
|
|
9924
10025
|
* Default function to get storage data, used in `IStorage.take` for storage retrieval.
|
|
9925
10026
|
* Returns `defaultValue` by default, allowing storage retrieval to be customized via `setConfig`, though not directly in `ClientAgent`.
|
|
@@ -10503,6 +10604,7 @@ declare const Utils: {
|
|
|
10503
10604
|
PersistStorageUtils: typeof PersistStorageUtils;
|
|
10504
10605
|
PersistMemoryUtils: typeof PersistMemoryUtils;
|
|
10505
10606
|
PersistAliveUtils: typeof PersistAliveUtils;
|
|
10607
|
+
PersistPolicyUtils: typeof PersistPolicyUtils;
|
|
10506
10608
|
};
|
|
10507
10609
|
|
|
10508
|
-
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 IPersistBase, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, PersistList, PersistMemory, 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 };
|
|
10610
|
+
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 IPersistBase, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerInstance, MethodContextService, PayloadContextService, PersistAlive, PersistBase, 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 };
|