Member Junction
    Preparing search index...

    Manages payload access control for agent hierarchies.

    This class handles extracting specific paths from payloads when sending data downstream to sub-agents, and merging results back upstream while respecting write permissions.

    Path syntax supports:

    • Exact paths: "customer.name"
    • Wildcards: "customer.*" (all properties under customer)
    • Array indices: "items[0].price" or "items[*].price"
    • Deep wildcards: "**.id" (all id fields at any depth)
    • Root wildcard: "*" (entire payload)
    Index

    Constructors

    Methods

    • Applies an AgentPayloadChangeRequest to a payload

      Type Parameters

      • P = any

      Parameters

      • originalPayload: P

        The original payload to apply changes to

      • changeRequest: AgentPayloadChangeRequest<any>

        The change request from the AI agent

      • Optionaloptions: {
            agentName?: string;
            allowedPaths?: string[];
            analyzeChanges?: boolean;
            generateDiff?: boolean;
            ignoreStrayKeys?: boolean;
            logChanges?: boolean;
            validateChanges?: boolean;
            verbose?: boolean;
        }

        Configuration options for the operation

      Returns PayloadManagerResult<P>

      Result object with the modified payload, operation counts, and any warnings

    • Applies a payload scope transformation to extract only the scoped portion.

      Type Parameters

      • P = any

      Parameters

      • payload: P

        The full payload to scope

      • scopePath: string

        The scope path (e.g., "/functionalRequirements" or "/PropA/SubProp1")

      Returns any

      The scoped portion of the payload

      const payload = { functionalRequirements: { feature1: "..." }, technicalDesign: { ... } };
      const scoped = applyPayloadScope(payload, "/functionalRequirements");
      // Returns: { feature1: "..." }
    • Apply a change request to a sub-agent payload with upstream guardrails

      This method first applies the change request, then enforces upstream path restrictions to ensure the sub-agent only modifies allowed paths.

      Type Parameters

      • P = any

      Parameters

      Returns PayloadManagerResult<P> & { blocked: number }

    • Detects and auto-corrects stray keys in a payloadChangeRequest. LLMs sometimes place payload properties as siblings of updateElements/newElements instead of nesting them inside. This method moves those stray keys into the appropriate bucket (updateElements if the key exists on the payload, newElements if not).

      Only keys starting with a letter (a-z, A-Z) are considered — keys starting with underscore, dollar sign, or other non-letter characters are left alone as they may be internal markers.

      Type Parameters

      • P = any

      Parameters

      Returns void

    • Deep merges two objects, with source overriding destination.

      This method preserves existing nested properties in the destination while adding or updating properties from the source. It handles nested objects recursively, ensuring that partial updates don't wipe out existing data.

      Type Parameters

      • T = any

      Parameters

      • destination: T

        The target object to merge into

      • source: Partial<T>

        The source object to merge from

      Returns T

      A new merged object with all properties from both objects

      const dest = { decision: { Y: 4, Z: 2 } };
      const src = { decision: { x: "string" } };
      const result = deepMerge(dest, src);
      // Returns: { decision: { x: "string", Y: 4, Z: 2 } }
    • Extracts only the allowed paths from a payload for downstream transmission.

      Type Parameters

      • P = any

      Parameters

      • subAgentName: string
      • fullPayload: P

        The complete payload object

      • downstreamPaths: string[]

        Array of path patterns defining what to extract

      Returns Partial<P>

      A new object containing only the allowed paths

      const payload = { customer: { id: 1, name: 'John', secret: 'xxx' }, order: { id: 2 } };
      const paths = ['customer.id', 'customer.name', 'order.*'];
      const result = extractDownstreamPayload(payload, paths);
      // Returns: { customer: { id: 1, name: 'John' }, order: { id: 2 } }
    • Merges sub-agent results back into the parent payload, respecting write permissions.

      Type Parameters

      • P = any

      Parameters

      • subAgentName: string
      • parentPayload: P

        The original parent payload

      • subAgentPayload: Partial<P>

        The payload returned by the sub-agent

      • upstreamPaths: string[]

        Array of path patterns the sub-agent is allowed to write

      • Optionalverbose: boolean

      Returns PayloadManagerResult<P>

      A new merged payload object

      const parent = { customer: { id: 1 }, analysis: { sentiment: null } };
      const subResult = { customer: { id: 2 }, analysis: { sentiment: 'positive', score: 0.9 } };
      const writePaths = ['analysis.*'];
      const merged = mergeUpstreamPayload(parent, subResult, writePaths);
      // Returns: { customer: { id: 1 }, analysis: { sentiment: 'positive', score: 0.9 } }
    • Reverses a payload scope transformation by wrapping the scoped content back into the full structure.

      Type Parameters

      • P = any

      Parameters

      • scopedPayload: unknown

        The scoped payload to wrap

      • scopePath: string

        The scope path used for extraction

      Returns P

      A full payload structure with the scoped content at the correct path

      const scoped = { feature1: "updated" };
      const full = reversePayloadScope(scoped, "/functionalRequirements");
      // Returns: { functionalRequirements: { feature1: "updated" } }
    • Transforms paths in a change request to account for payload scoping. Prepends the scope path to all paths in the change request.

      Type Parameters

      • P = any

      Parameters

      • changeRequest: AgentPayloadChangeRequest<P>

        The change request with paths relative to the scoped view

      • scopePath: string

        The scope path to prepend

      Returns AgentPayloadChangeRequest<P>

      A new change request with transformed paths

      const request = { updateElements: { "field1": "value" } };
      const transformed = transformChangeRequestPaths(request, "/functionalRequirements");
      // Returns: { updateElements: { "functionalRequirements.field1": "value" } }