@ziggs-ai/agent-sdk 0.46.5 → 0.46.6

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/dist/Agent.d.ts CHANGED
@@ -295,7 +295,8 @@ export declare class Agent {
295
295
  private readonly wakeDestination;
296
296
  private readonly outboundMessages;
297
297
  private readonly confirmedPlanVersions;
298
- private grantProviderCache;
298
+ /** Live connection providers, per execution: what a grant lists depends on the party the wake acts for. */
299
+ private readonly grantProviderCache;
299
300
  /** The checkout box each lane holds while its wake runs. */
300
301
  private checkoutByLane;
301
302
  constructor(options?: AgentOptions);
package/dist/Agent.js CHANGED
@@ -249,7 +249,8 @@ export class Agent {
249
249
  wakeDestination = new AsyncLocalStorage();
250
250
  outboundMessages = new SeenMessages();
251
251
  confirmedPlanVersions = new SeenMessages();
252
- grantProviderCache = null;
252
+ /** Live connection providers, per execution: what a grant lists depends on the party the wake acts for. */
253
+ grantProviderCache = new Map();
253
254
  /** The checkout box each lane holds while its wake runs. */
254
255
  checkoutByLane = new Map();
255
256
  constructor(options = {}) {
@@ -905,8 +906,12 @@ export class Agent {
905
906
  return reported !== undefined && reported !== null && reported !== '';
906
907
  }
907
908
  /** Providers of this agent's live connection grants. Its own seam, so the gate below is testable without a backend. */
908
- async _listGrantProviders(operatorKey, agentId) {
909
- const groups = await new ConnectionsClient(operatorKey, agentId).listForHolder();
909
+ async _listGrantProviders(operatorKey, agentId, execution) {
910
+ // The server answers for the party this call acts for. Without the wake's
911
+ // execution it answers for the agent's own operator, so a grant a customer
912
+ // gave for a hire is never listed and every hired agent reads as unconnected.
913
+ const read = () => new ConnectionsClient(operatorKey, agentId).listForHolder();
914
+ const groups = execution ? await withWorkExecution(execution, read) : await read();
910
915
  return groups.filter((g) => (g.grants ?? []).length > 0).map((g) => g.provider);
911
916
  }
912
917
  /**
@@ -914,13 +919,18 @@ export class Agent {
914
919
  * several in seconds — but hire comes before grant, so a grant arriving
915
920
  * mid-engagement has to take effect without a restart.
916
921
  */
917
- async _grantProvidersCached(operatorKey, agentId) {
922
+ async _grantProvidersCached(operatorKey, agentId, execution) {
918
923
  const now = Date.now();
919
- if (this.grantProviderCache && now - this.grantProviderCache.at < 30_000) {
920
- return this.grantProviderCache.providers;
921
- }
922
- const providers = await this._listGrantProviders(operatorKey, agentId);
923
- this.grantProviderCache = { at: now, providers };
924
+ const key = execution?.contextId ?? '';
925
+ const cached = this.grantProviderCache.get(key);
926
+ if (cached && now - cached.at < 30_000)
927
+ return cached.providers;
928
+ const providers = await this._listGrantProviders(operatorKey, agentId, execution);
929
+ this.grantProviderCache.set(key, { at: now, providers });
930
+ // One entry per live execution is enough; drop the stale ones as they pass.
931
+ for (const [k, v] of this.grantProviderCache)
932
+ if (now - v.at >= 30_000)
933
+ this.grantProviderCache.delete(k);
924
934
  return providers;
925
935
  }
926
936
  /**
@@ -947,7 +957,10 @@ export class Agent {
947
957
  return false;
948
958
  let providers;
949
959
  try {
950
- providers = await this._grantProvidersCached(operatorKey, agentId);
960
+ // The grant a customer gave for a hire is listed to the wake that works that hire.
961
+ const execution = this.sessions?.get(_laneKey)?.executionContext ??
962
+ (_event?.executionContext);
963
+ providers = await this._grantProvidersCached(operatorKey, agentId, execution);
951
964
  }
952
965
  catch (err) {
953
966
  // A grants read that failed is not proof the grant is missing, and failing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.46.5",
3
+ "version": "0.46.6",
4
4
  "description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
5
5
  "homepage": "https://ziggsai.com/docs",
6
6
  "bugs": {