/**
 * Create a child invocation state with the current agent appended to parentChain.
 *
 * This function is called by SupervisorAgent and RouterAgent when delegating
 * to sub-agents. It ensures the full agent hierarchy is tracked for debugging,
 * logging, and tenant isolation validation.
 *
 * When `parent` is undefined (top-level agent), a minimal root context is
 * required so `tenantId` can be seeded — see {@link DeriveChildStateRoot}.
 * `InvocationState.tenantId` is required in 0.2.0 (§12.1).
 *
 * @param parent The parent invocation state, or a root seed carrying `tenantId`.
 * @param currentAgentId The ID of the agent making the delegation
 * @returns A new InvocationState with currentAgentId appended to parentChain
 */
export function deriveChildState(parent, currentAgentId) {
    const existingChain = 'parentChain' in parent ? parent.parentChain : undefined;
    const parentChain = existingChain ? [...existingChain, currentAgentId] : [currentAgentId];
    return {
        tenantId: parent.tenantId,
        metadata: 'metadata' in parent ? parent.metadata : undefined,
        services: 'services' in parent ? parent.services : undefined,
        parentChain,
    };
}
//# sourceMappingURL=index.js.map